Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def schema_hash_matches?(provided_hash)

private

def rpc_collection?(name)
@rpc_collections.any? do |pattern|
pattern.is_a?(Regexp) ? pattern.match?(name) : pattern == name
end
end

def should_skip_schema_update?
ForestAdminRpcAgent::Facades::Container.cache(:skip_schema_update) == true
end
Expand Down Expand Up @@ -84,19 +90,19 @@ def build_rpc_schema_from_datasource(datasource)
datasource.collections.each_value do |collection|
relations = {}

if @rpc_collections.include?(collection.name)
if rpc_collection?(collection.name)
# RPC collection → extract relations to non-RPC collections
collection.schema[:fields].each do |field_name, field|
next if field.type == 'Column'
next if @rpc_collections.include?(field.foreign_collection)
next if rpc_collection?(field.foreign_collection)

relations[field_name] = field
end
else
fields = {}

collection.schema[:fields].each do |field_name, field|
if field.type != 'Column' && @rpc_collections.include?(field.foreign_collection)
if field.type != 'Column' && rpc_collection?(field.foreign_collection)
relations[field_name] = field
else
if field.type == 'Column'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ module ForestAdminRpcAgent
expect(instance.rpc_collections).to include('users', 'orders')
end

it 'accepts regex patterns' do
instance.mark_collections_as_rpc(/^rpc_/, /.*_private$/)

expect(instance.rpc_collections).to include(/^rpc_/, /.*_private$/)
end

it 'accepts mixed strings and regex patterns' do
instance.mark_collections_as_rpc('users', /^admin_/)

expect(instance.rpc_collections).to include('users', /^admin_/)
end

it 'returns self for method chaining' do
result = instance.mark_collections_as_rpc('products')

Expand Down Expand Up @@ -268,6 +280,31 @@ module ForestAdminRpcAgent
expect(collection_names).not_to include('RpcCollection')
end

it 'excludes collections matching regex patterns from schema collections' do
rpc_collection1 = instance_double(ForestAdminDatasourceToolkit::Collection)
rpc_collection2 = instance_double(ForestAdminDatasourceToolkit::Collection)
normal_collection = instance_double(ForestAdminDatasourceToolkit::Collection)

allow(rpc_collection1).to receive_messages(name: 'rpc_users', schema: { fields: {} })
allow(rpc_collection2).to receive_messages(name: 'rpc_orders', schema: { fields: {} })
allow(normal_collection).to receive_messages(name: 'products', schema: { fields: {} })
allow(datasource).to receive_messages(
collections: {
'rpc_users' => rpc_collection1,
'rpc_orders' => rpc_collection2,
'products' => normal_collection
},
live_query_connections: {}
)

instance.mark_collections_as_rpc(/^rpc_/)
instance.send_schema

collection_names = instance.cached_schema[:collections].map { |c| c[:name] }
expect(collection_names).to include('products')
expect(collection_names).not_to include('rpc_users', 'rpc_orders')
end

it 'extracts relations from RPC collections to non-RPC collections into rpc_relations' do
rpc_collection = instance_double(ForestAdminDatasourceToolkit::Collection)
normal_collection = instance_double(ForestAdminDatasourceToolkit::Collection)
Expand Down
Loading