forest_admin_agent 1.0.0.pre.beta.23 → 1.0.0.pre.beta.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c342682e272a5886928f4c48de0e35dbd6bcf013c4f888aa56bac238cca695da
4
- data.tar.gz: 300d73bdac310e91c2aa4a044d095b782bd362a0fb3c6309871fad0b1fff2930
3
+ metadata.gz: 99124b74e8108992635d7c4932b1e1a3e670cdef851df6af0174b1b13434845e
4
+ data.tar.gz: a4fb88fed216fd288ff7a2d89e13216ed21f576482f450b08300dc22ed805579
5
5
  SHA512:
6
- metadata.gz: 50d05943fa75c8559e127bd181f91bb36dc64352237126381d4bd1fd769fa0e51389b74051e1f7cdc55f7c6747fbdb2c91259cf135c6e2e7e7665c5cef8cefcd
7
- data.tar.gz: be53569ca0ad92511dc33b118693445e5a2a522faa98fd24e4d3662bf70eaa3ac7f9614cc1dccc6db444f8fe204d39db43eca1709f8efe4e528f7fef2b200ebf
6
+ metadata.gz: ef8333542d36d50484ede07d6bee4923e777eba881b6c49678e803387c271b8b4487ebf9b9f37697f8e23381c07e6a05af1a4eee07b8ead80277904fda28baf4
7
+ data.tar.gz: c32a53f151d3135e98349148e214f5ef90f9134a5cdf74fe3ac6bb072c241d7aef7a99a9cd3d8f8295d8acfa517bcae54567bf8b389ce533dfc1b3fe4c295f1f
@@ -14,26 +14,31 @@ module ForestAdminAgent
14
14
  def setup(options)
15
15
  @options = options
16
16
  @has_env_secret = options.to_h.key?(:env_secret)
17
- @customizer = ForestAdminDatasourceToolkit::Datasource.new
17
+ @customizer = ForestAdminDatasourceCustomizer::DatasourceCustomizer.new
18
18
  build_container
19
19
  build_cache
20
20
  build_logger
21
21
  end
22
22
 
23
- def add_datasource(datasource)
24
- datasource.collections.each_value { |collection| @customizer.add_collection(collection) }
23
+ def add_datasource(datasource, options = {})
24
+ @customizer.add_datasource(datasource, options)
25
+
25
26
  self
26
27
  end
27
28
 
29
+ def customize_collection(name, handle)
30
+ @customizer.customize_collection(name, handle)
31
+ end
32
+
28
33
  def build
29
- @container.register(:datasource, @customizer)
34
+ @container.register(:datasource, @customizer.datasource)
30
35
  send_schema
31
36
  end
32
37
 
33
38
  def send_schema(force: false)
34
39
  return unless @has_env_secret
35
40
 
36
- schema = ForestAdminAgent::Utils::Schema::SchemaEmitter.get_serialized_schema(@customizer)
41
+ schema = ForestAdminAgent::Utils::Schema::SchemaEmitter.get_serialized_schema(@customizer.datasource)
37
42
  schema_is_know = @container.key?(:schema_file_hash) &&
38
43
  @container.resolve(:schema_file_hash).get('value') == schema[:meta][:schemaFileHash]
39
44
 
@@ -14,7 +14,7 @@ module ForestAdminAgent
14
14
  record = args[:params][:data][:attributes]
15
15
 
16
16
  args[:params][:data][:relationships]&.map do |field, value|
17
- schema = @collection.fields[field]
17
+ schema = @collection.schema[:fields][field]
18
18
 
19
19
  record[schema.foreign_key] = value['data'][schema.foreign_key_target] if schema.type == 'ManyToOne'
20
20
  end
@@ -4,8 +4,8 @@ module ForestAdminAgent
4
4
  def build(args = {})
5
5
  super
6
6
 
7
- relation = @collection.fields[args[:params]['relation_name']]
8
- @child_collection = @datasource.collection(relation.foreign_collection)
7
+ relation = @collection.schema[:fields][args[:params]['relation_name']]
8
+ @child_collection = @datasource.get_collection(relation.foreign_collection)
9
9
  end
10
10
  end
11
11
  end
@@ -8,7 +8,7 @@ module ForestAdminAgent
8
8
 
9
9
  def build(args)
10
10
  @datasource = ForestAdminAgent::Facades::Container.datasource
11
- @collection = @datasource.collection(args[:params]['collection_name'])
11
+ @collection = @datasource.get_collection(args[:params]['collection_name'])
12
12
  end
13
13
 
14
14
  def routes
@@ -141,7 +141,7 @@ module ForestAdminAgent
141
141
  end
142
142
 
143
143
  def make_leaderboard
144
- field = @collection.fields[@args[:params][:relationshipFieldName]]
144
+ field = @collection.schema[:fields][@args[:params][:relationshipFieldName]]
145
145
 
146
146
  if field && field.type == 'OneToMany'
147
147
  inverse = ForestAdminDatasourceToolkit::Utils::Collection.get_inverse_relation(
@@ -180,7 +180,7 @@ module ForestAdminAgent
180
180
  end
181
181
 
182
182
  if collection && filter && aggregation
183
- rows = @datasource.collection(collection).aggregate(
183
+ rows = @datasource.get_collection(collection).aggregate(
184
184
  @caller,
185
185
  filter,
186
186
  aggregation,
@@ -26,7 +26,7 @@ module ForestAdminAgent
26
26
  return {
27
27
  name: args[:params]['collection_name'],
28
28
  content: {
29
- count: result[0][:value]
29
+ count: result.empty? ? 0 : result[0][:value]
30
30
  }
31
31
  }
32
32
  end
@@ -62,7 +62,7 @@ module ForestAdminAgent
62
62
  origin_value = Collection.get_value(@collection, @caller, parent_id, id)
63
63
  record = { relation.origin_key => origin_value, relation.foreign_key => foreign_value }
64
64
 
65
- through_collection = @datasource.collection(relation.through_collection)
65
+ through_collection = @datasource.get_collection(relation.through_collection)
66
66
  through_collection.create(@caller, record)
67
67
  end
68
68
  end
@@ -52,7 +52,7 @@ module ForestAdminAgent
52
52
  end
53
53
 
54
54
  def dissociate_or_delete_many_to_many(relation, relation_name, parent_id, is_delete_mode, filter)
55
- through_collection = @datasource.collection(relation.through_collection)
55
+ through_collection = @datasource.get_collection(relation.through_collection)
56
56
 
57
57
  if is_delete_mode
58
58
  # Generate filters _BEFORE_ deleting stuff, otherwise things break.
@@ -23,7 +23,7 @@ module ForestAdminAgent
23
23
  build(args)
24
24
  @permissions.can?(:edit, @collection)
25
25
 
26
- relation = @collection.fields[args[:params]['relation_name']]
26
+ relation = @collection.schema[:fields][args[:params]['relation_name']]
27
27
  parent_id = Utils::Id.unpack_id(@collection, args[:params]['id'])
28
28
 
29
29
  linked_id = if (id = args.dig(:params, :data, :id))
@@ -32,11 +32,11 @@ module ForestAdminAgent
32
32
 
33
33
  def link_one_to_one_relations(args, record)
34
34
  args[:params][:data][:relationships]&.map do |field, value|
35
- schema = @collection.fields[field]
35
+ schema = @collection.schema[:fields][field]
36
36
  next unless schema.type == 'OneToOne'
37
37
 
38
38
  id = Utils::Id.unpack_id(@collection, value['data']['id'], with_key: true)
39
- foreign_collection = @datasource.collection(schema.foreign_collection)
39
+ foreign_collection = @datasource.get_collection(schema.foreign_collection)
40
40
  # Load the value that will be used as origin_key
41
41
  origin_value = record[schema.origin_key_target]
42
42
 
@@ -41,8 +41,8 @@ module ForestAdminAgent
41
41
  end
42
42
 
43
43
  def attributes
44
- forest_collection = ForestAdminAgent::Facades::Container.datasource.collection(object.class.name.demodulize.underscore)
45
- fields = forest_collection.fields.select { |_field_name, field| field.type == 'Column' }
44
+ forest_collection = ForestAdminAgent::Facades::Container.datasource.get_collection(object.class.name.demodulize.underscore)
45
+ fields = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'Column' }
46
46
  fields.each { |field_name, _field| add_attribute(field_name) }
47
47
  return {} if attributes_map.nil?
48
48
  attributes = {}
@@ -104,9 +104,9 @@ module ForestAdminAgent
104
104
  end
105
105
 
106
106
  def relationships
107
- forest_collection = ForestAdminAgent::Facades::Container.datasource.collection(object.class.name.demodulize.underscore)
108
- relations_to_many = forest_collection.fields.select { |_field_name, field| field.type == 'OneToMany' || field.type == 'ManyToMany' }
109
- relations_to_one = forest_collection.fields.select { |_field_name, field| field.type == 'OneToOne' || field.type == 'ManyToOne' }
107
+ forest_collection = ForestAdminAgent::Facades::Container.datasource.get_collection(object.class.name.demodulize.underscore)
108
+ relations_to_many = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'OneToMany' || field.type == 'ManyToMany' }
109
+ relations_to_one = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'OneToOne' || field.type == 'ManyToOne' }
110
110
 
111
111
  relations_to_one.each { |field_name, _field| add_to_one_association(field_name) }
112
112
 
@@ -11,7 +11,7 @@ module ForestAdminAgent
11
11
  end
12
12
 
13
13
  result = primary_keys.map.with_index do |pk_name, index|
14
- field = collection.fields[pk_name]
14
+ field = collection.schema[:fields][pk_name]
15
15
  value = primary_key_values[index]
16
16
  casted_value = field.column_type == 'Number' ? value.to_i : value
17
17
  # TODO: call FieldValidator::validateValue($value, $field, $castedValue);
@@ -57,7 +57,7 @@ module ForestAdminAgent
57
57
  return ProjectionFactory.all(collection) unless fields != '' && !fields.nil?
58
58
 
59
59
  fields = fields.split(',').map do |field_name|
60
- column = collection.fields[field_name.strip]
60
+ column = collection.schema[:fields][field_name.strip]
61
61
  column.type == 'Column' ? field_name.strip : "#{field_name.strip}:#{args[:params][:fields][field_name.strip]}"
62
62
  end
63
63
 
@@ -10,7 +10,7 @@ module ForestAdminAgent
10
10
  fields: build_fields(collection),
11
11
  icon: nil,
12
12
  integration: nil,
13
- isReadOnly: collection.fields.all? { |_k, field| field.type != 'Column' || field.is_read_only },
13
+ isReadOnly: collection.schema[:fields].all? { |_k, field| field.type != 'Column' || field.is_read_only },
14
14
  isSearchable: true,
15
15
  isVirtual: false,
16
16
  name: collection.name,
@@ -21,7 +21,7 @@ module ForestAdminAgent
21
21
  end
22
22
 
23
23
  def self.build_fields(collection)
24
- fields = collection.fields.select do |name, _field|
24
+ fields = collection.schema[:fields].select do |name, _field|
25
25
  !ForestAdminDatasourceToolkit::Utils::Schema.foreign_key?(collection, name) ||
26
26
  ForestAdminDatasourceToolkit::Utils::Schema.primary_key?(collection, name)
27
27
  end
@@ -10,7 +10,7 @@ module ForestAdminAgent
10
10
  }.freeze
11
11
 
12
12
  def self.build_schema(collection, name)
13
- type = collection.fields[name].type
13
+ type = collection.schema[:fields][name].type
14
14
 
15
15
  case type
16
16
  when 'Column'
@@ -26,7 +26,7 @@ module ForestAdminAgent
26
26
  private
27
27
 
28
28
  def build_column_schema(collection, name)
29
- column = collection.fields[name]
29
+ column = collection.schema[:fields][name]
30
30
  is_foreign_key = ForestAdminDatasourceToolkit::Utils::Schema.foreign_key?(collection, name)
31
31
 
32
32
  {
@@ -74,10 +74,10 @@ module ForestAdminAgent
74
74
 
75
75
  def build_many_to_many_schema(relation, collection, foreign_collection, base_schema)
76
76
  target_name = relation.foreign_key_target
77
- target_field = foreign_collection.fields[target_name]
78
- through_schema = collection.datasource.collection(relation.through_collection)
79
- foreign_schema = through_schema.fields[relation.foreign_key]
80
- origin_key = through_schema.fields[relation.origin_key]
77
+ target_field = foreign_collection.schema[:fields][target_name]
78
+ through_schema = collection.datasource.get_collection(relation.through_collection)
79
+ foreign_schema = through_schema.schema[:fields][relation.foreign_key]
80
+ origin_key = through_schema.schema[:fields][relation.origin_key]
81
81
 
82
82
  base_schema.merge(
83
83
  {
@@ -96,8 +96,8 @@ module ForestAdminAgent
96
96
 
97
97
  def build_one_to_many_schema(relation, collection, foreign_collection, base_schema)
98
98
  target_name = relation.origin_key_target
99
- target_field = collection.fields[target_name]
100
- origin_key = foreign_collection.fields[relation.origin_key]
99
+ target_field = collection.schema[:fields][target_name]
100
+ origin_key = foreign_collection.schema[:fields][relation.origin_key]
101
101
 
102
102
  base_schema.merge(
103
103
  {
@@ -115,8 +115,8 @@ module ForestAdminAgent
115
115
  end
116
116
 
117
117
  def build_one_to_one_schema(relation, collection, foreign_collection, base_schema)
118
- target_field = collection.fields[relation.origin_key_target]
119
- key_field = foreign_collection.fields[relation.origin_key]
118
+ target_field = collection.schema[:fields][relation.origin_key_target]
119
+ key_field = foreign_collection.schema[:fields][relation.origin_key]
120
120
 
121
121
  base_schema.merge(
122
122
  {
@@ -134,7 +134,7 @@ module ForestAdminAgent
134
134
  end
135
135
 
136
136
  def build_many_to_one_schema(relation, collection, foreign_collection, base_schema)
137
- key_field = collection.fields[relation.foreign_key]
137
+ key_field = collection.schema[:fields][relation.foreign_key]
138
138
 
139
139
  base_schema.merge(
140
140
  {
@@ -152,8 +152,8 @@ module ForestAdminAgent
152
152
  end
153
153
 
154
154
  def build_relation_schema(collection, name)
155
- relation = collection.fields[name]
156
- foreign_collection = collection.datasource.collection(relation.foreign_collection)
155
+ relation = collection.schema[:fields][name]
156
+ foreign_collection = collection.datasource.get_collection(relation.foreign_collection)
157
157
 
158
158
  relation_schema = {
159
159
  field: name,
@@ -7,7 +7,7 @@ module ForestAdminAgent
7
7
  class SchemaEmitter
8
8
  LIANA_NAME = "forest-rails"
9
9
 
10
- LIANA_VERSION = "1.0.0-beta.23"
10
+ LIANA_VERSION = "1.0.0-beta.25"
11
11
 
12
12
  def self.get_serialized_schema(datasource)
13
13
  schema_path = Facades::Container.cache(:schema_path)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminAgent
2
- VERSION = "1.0.0-beta.23"
2
+ VERSION = "1.0.0-beta.25"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.23
4
+ version: 1.0.0.pre.beta.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-12-13 00:00:00.000000000 Z
12
+ date: 2023-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -218,7 +218,6 @@ extensions: []
218
218
  extra_rdoc_files: []
219
219
  files:
220
220
  - ".rspec"
221
- - CHANGELOG.md
222
221
  - README.md
223
222
  - Rakefile
224
223
  - forest_admin
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2023-08-28
4
-
5
- - Initial release