foobara 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/projects/builtin_types/src/builtin_types.rb +3 -1
  4. data/projects/callback/src/registry/chained_conditioned.rb +7 -1
  5. data/projects/callback/src/registry/chained_multiple_action.rb +7 -1
  6. data/projects/callback/src/registry/joined_conditioned.rb +7 -1
  7. data/projects/command/src/command_pattern_implementation/concerns/errors.rb +3 -1
  8. data/projects/command/src/command_pattern_implementation/concerns/inputs_type.rb +3 -1
  9. data/projects/command/src/command_pattern_implementation/concerns/result_type.rb +3 -1
  10. data/projects/command_connectors/src/command_connector/commands/describe.rb +3 -1
  11. data/projects/command_connectors/src/command_connector.rb +3 -25
  12. data/projects/command_connectors/src/transformed_command.rb +28 -13
  13. data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +1 -0
  14. data/projects/common/src/outcome.rb +9 -5
  15. data/projects/detached_entity/src/concerns/associations.rb +3 -5
  16. data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/to_type_transformer.rb +1 -0
  17. data/projects/entity/src/concerns/callbacks.rb +10 -2
  18. data/projects/entity/src/extensions/builtin_types/entity/validators/model_instance_is_valid.rb +1 -1
  19. data/projects/entity/src/sensitive_type_removers/entity.rb +3 -0
  20. data/projects/entity/src/sensitive_value_removers/entity.rb +6 -7
  21. data/projects/manifest/src/foobara/manifest/organization.rb +4 -0
  22. data/projects/manifest/src/foobara/manifest/root_manifest.rb +4 -0
  23. data/projects/manifest/src/foobara/manifest/type.rb +1 -1
  24. data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +5 -1
  25. data/projects/persistence/src/entity_base/transaction.rb +3 -1
  26. data/projects/types/src/type.rb +6 -0
  27. data/version.rb +6 -0
  28. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ff971dedd276b649d7ceb9b184734a47074357ab20b517b01a377bf7dfedfaa
4
- data.tar.gz: a1b07c225fdddebd6dd859650db155a7e20aca66fe0647211d5daede966b305f
3
+ metadata.gz: c106dcffef98c13b230ca60f3433638583db9c1d6a9779995baa073cc1ddff00
4
+ data.tar.gz: 4159835c178cf602fd7fdedd20d5ed030f37dfb5721b6806847f12dbaa7379cd
5
5
  SHA512:
6
- metadata.gz: 1d797ddc6c22d97617ffe9c1c951d66257f305dceedccaa5df80f0da3283a902a3c7acfd086dd4603957e3efa2a9f2b06a0851bb6cc420884839f79f19c70816
7
- data.tar.gz: f57df9169e0da18ffc23d57e9fd8b2c5d218714938e4b37f1d4de1b19344774756915702d152b19ace97302b481df9bf6b9e4467db590b34f606cae2861cf44f
6
+ metadata.gz: d352b2e66aa89e993a741da14506decbc13bcde49a71d23225349b409f8871aaf9216c4a6ec38e325adace318ef01a90b078b596bed15df39cc3422fd2b59dbf
7
+ data.tar.gz: 3bf9fd820cddfaf432c704df09797ce100084507b450df4de8d2bcc4c0294ca77f5009ba51d750a7fb66161108e953a323fa7482ef35b56e6139e1acc8d90948
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # [0.1.7] - 2025-08-25
2
+
3
+ - Go back to using :detached_entity for entities that have had sensitive types removed to
4
+ avoid casting problems with multiple entities with the same name
5
+ - Remove private attributes as if they were sensitive attributes when exposing models
6
+
7
+ # [0.1.6] - 2025-08-25
8
+
9
+ - Allow constructing a thunk-like record when removing sensitive values from a thunk
10
+ - Undo automatically converting connected entities to detached entities
11
+ - Honor imported builtin types in manifest
12
+ - Add Foobara version to manifest metadata
13
+ - Add RootManifest#detached_entities
14
+ - Remove some items from the manifest that should be safe to remove
15
+ - Let's use GlobalDomain in the manifest for objects scoped to Foobara::Value
16
+
1
17
  # [0.1.4] - 2025-08-24
2
18
 
3
19
  - Fix TransformedCommand#foobara_manifest bug that failed to overwrite transformed possible_errors
@@ -5,7 +5,9 @@ module Foobara
5
5
 
6
6
  module BuiltinTypes
7
7
  class << self
8
- foobara_delegate :global_type_declaration_handler_registry, to: TypeDeclarations
8
+ def global_type_declaration_handler_registry
9
+ TypeDeclarations.global_type_declaration_handler_registry
10
+ end
9
11
 
10
12
  # TODO: break this up
11
13
  # TODO: much of this behavior is helpful to non-builtin types as well.
@@ -6,7 +6,13 @@ module Foobara
6
6
  class ChainedConditioned < Conditioned
7
7
  attr_accessor :other_conditions_registry
8
8
 
9
- foobara_delegate :possible_conditions, :possible_condition_keys, to: :other_conditions_registry
9
+ def possible_conditions
10
+ other_conditions_registry.possible_conditions
11
+ end
12
+
13
+ def possible_condition_keys
14
+ other_conditions_registry.possible_condition_keys
15
+ end
10
16
 
11
17
  def initialize(other_conditions_registry)
12
18
  self.other_conditions_registry = other_conditions_registry
@@ -8,7 +8,13 @@ module Foobara
8
8
 
9
9
  class InvalidConditions < StandardError; end
10
10
 
11
- foobara_delegate :possible_actions, :allowed_types, to: :other_multiple_actions_registry
11
+ def possible_actions
12
+ other_multiple_actions_registry.possible_actions
13
+ end
14
+
15
+ def allowed_types
16
+ other_multiple_actions_registry.allowed_types
17
+ end
12
18
 
13
19
  def initialize(other_multiple_actions_registry)
14
20
  self.other_multiple_actions_registry = other_multiple_actions_registry
@@ -6,7 +6,13 @@ module Foobara
6
6
  class JoinedConditioned < Conditioned
7
7
  attr_accessor :first, :second
8
8
 
9
- foobara_delegate :possible_conditions, :possible_condition_keys, to: :first
9
+ def possible_conditions
10
+ first.possible_conditions
11
+ end
12
+
13
+ def possible_condition_keys
14
+ first.possible_condition_keys
15
+ end
10
16
 
11
17
  def initialize(first, second)
12
18
  self.first = first
@@ -53,7 +53,9 @@ module Foobara
53
53
  super
54
54
  end
55
55
 
56
- foobara_delegate :has_errors?, to: :error_collection
56
+ def has_errors?
57
+ error_collection.has_errors?
58
+ end
57
59
 
58
60
  private
59
61
 
@@ -61,7 +61,9 @@ module Foobara
61
61
  end
62
62
  end
63
63
 
64
- foobara_delegate :inputs_type, to: :class
64
+ def inputs_type
65
+ self.class.inputs_type
66
+ end
65
67
  end
66
68
  end
67
69
  end
@@ -18,7 +18,9 @@ module Foobara
18
18
  end
19
19
  end
20
20
 
21
- foobara_delegate :result_type, :raw_result_type_declaration, to: :class
21
+ def result_type
22
+ self.class.result_type
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -1,3 +1,5 @@
1
+ require_relative "../../../../../version"
2
+
1
3
  module Foobara
2
4
  class CommandConnector
3
5
  module Commands
@@ -20,7 +22,7 @@ module Foobara
20
22
  end
21
23
 
22
24
  def stamp_request_metadata
23
- manifest[:metadata] = { when: Time.now }
25
+ manifest[:metadata] = { when: Time.now, foobara_version: Foobara::Version::VERSION }
24
26
  end
25
27
  end
26
28
  end
@@ -352,7 +352,9 @@ module Foobara
352
352
  args = args[1..]
353
353
  connected = []
354
354
 
355
- registerable.foobara_each_command(mode: Namespace::LookupMode::DIRECT) do |command_class|
355
+ registerable = registerable.foobara_all_command(mode: Namespace::LookupMode::DIRECT)
356
+
357
+ registerable.each do |command_class|
356
358
  unless command_class.abstract?
357
359
  connected << connect(command_class, *args, **opts)
358
360
  end
@@ -567,29 +569,6 @@ module Foobara
567
569
  additional_to_include << exposed_organization
568
570
  end
569
571
  end
570
-
571
- if o.extends_type?(BuiltinTypes[:entity])
572
- declaration_data = o.declaration_data
573
-
574
- if declaration_data.is_a?(::Hash) && declaration_data[:type] == :entity
575
- if o.foobara_root_namespace != command_registry.foobara_root_namespace
576
- # Let's swap it out with a detached type
577
- detached_entity = command_registry.foobara_lookup_type(o.scoped_full_name, mode:)
578
-
579
- unless detached_entity
580
- declaration_data = o.declaration_data.merge(
581
- type: :detached_entity,
582
- model_base_class: "Foobara::DetachedEntity"
583
- )
584
-
585
- detached_entity = exposed_domain.foobara_type_from_declaration(declaration_data)
586
- end
587
-
588
- additional_to_include << detached_entity
589
- next
590
- end
591
- end
592
- end
593
572
  end
594
573
  end
595
574
 
@@ -637,7 +616,6 @@ module Foobara
637
616
  end
638
617
 
639
618
  h = normalize_manifest(h)
640
-
641
619
  patch_up_broken_parents_for_errors_with_missing_command_parents(h)
642
620
  end
643
621
 
@@ -61,10 +61,11 @@ module Foobara
61
61
  end
62
62
  end
63
63
 
64
- foobara_delegate :description,
65
- :domain,
66
- :organization,
67
- to: :command_class
64
+ foobara_delegate :domain, :organization, to: :command_class
65
+
66
+ def description
67
+ command_class.description
68
+ end
68
69
 
69
70
  def result_transformers
70
71
  return @result_transformers if @considered_sensitive_value_remover
@@ -350,7 +351,7 @@ module Foobara
350
351
  response_mutators = processors_to_manifest_symbols(self.response_mutators)
351
352
  request_mutators = processors_to_manifest_symbols(self.request_mutators)
352
353
 
353
- authenticator_details = if authenticator
354
+ authenticator_details = if requires_authentication && authenticator
354
355
  {
355
356
  symbol: authenticator.symbol,
356
357
  explanation: authenticator.explanation
@@ -395,16 +396,30 @@ module Foobara
395
396
 
396
397
  manifest = manifest.dup
397
398
 
399
+ # TODO: we should remove all blank valued keys but keeping many for now for stability
400
+ safe_to_remove = [
401
+ :pre_commit_transformers,
402
+ :response_mutators,
403
+ :request_mutators,
404
+ :capture_unknown_error,
405
+ :inputs_transformers,
406
+ :result_transformers,
407
+ :errors_transformers,
408
+ :requires_authentication,
409
+ :authenticator
410
+ ]
411
+
398
412
  to_merge.each_pair do |key, value|
399
413
  # TODO: we could probably remove empty strings and nils, too, and from the whole hash
400
- # if (value.is_a?(::Hash) || value.is_a?(::Array)) && value.empty?
401
- # manifest.delete(key)
402
- # else
403
- # manifest[key] = value
404
- # end
405
- # TODO: for now, just including everything for stability
406
- # But we should remove all empty values in a future version
407
- manifest[key] = value
414
+ if value.nil? || ((value.is_a?(::Hash) || value.is_a?(::Array)) && value.empty?)
415
+ if safe_to_remove.include?(key)
416
+ manifest.delete(key)
417
+ else
418
+ manifest[key] = value
419
+ end
420
+ else
421
+ manifest[key] = value
422
+ end
408
423
  end
409
424
 
410
425
  manifest
@@ -54,6 +54,7 @@ module Foobara
54
54
 
55
55
  description = "#{to_type.target_class.model_name} #{to_type.target_class.primary_key_attribute}"
56
56
 
57
+ # TODO: doesn't everything that extends :entity also extend :detached_entity?
57
58
  unless to_type.extends_directly?(Foobara::BuiltinTypes[:detached_entity]) ||
58
59
  to_type.extends_directly?(Foobara::BuiltinTypes[:entity])
59
60
 
@@ -55,11 +55,15 @@ module Foobara
55
55
  end
56
56
  end
57
57
 
58
- foobara_delegate :has_errors?,
59
- :has_error?,
60
- :add_error,
61
- :add_errors,
62
- to: :error_collection
58
+ foobara_delegate :has_error, :add_errors, to: :error_collection
59
+
60
+ def has_errors?
61
+ error_collection.has_errors?
62
+ end
63
+
64
+ def add_errors(...)
65
+ error_collection.add_errors(...)
66
+ end
63
67
 
64
68
  def errors
65
69
  error_collection
@@ -157,13 +157,11 @@ module Foobara
157
157
  result = {},
158
158
  initial: true
159
159
  )
160
- if initial && type.extends?(BuiltinTypes[:detached_entity])
161
- return construct_associations(type.element_types, path, result, initial: false)
162
- end
163
-
164
160
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?
165
161
 
166
- if type.extends?(BuiltinTypes[:entity])
162
+ if initial && type.extends?(BuiltinTypes[:detached_entity])
163
+ construct_associations(type.target_class.foobara_attributes_type, path, result, initial: false)
164
+ elsif type.extends?(BuiltinTypes[:entity])
167
165
  result[path.to_s] = type
168
166
  elsif type.extends?(BuiltinTypes[:tuple])
169
167
  element_types = type.element_types
@@ -3,6 +3,7 @@ module Foobara
3
3
  module Handlers
4
4
  class ExtendDetachedEntityTypeDeclaration < ExtendModelTypeDeclaration
5
5
  class ToTypeTransformer < ExtendModelTypeDeclaration::ToTypeTransformer
6
+ # TODO: use constants for these arrays for performance reasons
6
7
  def non_processor_keys
7
8
  [:primary_key, *super]
8
9
  end
@@ -35,7 +35,9 @@ module Foobara
35
35
  end
36
36
  end
37
37
 
38
- foobara_delegate :register_callback, to: :callback_registry
38
+ def register_callback(...)
39
+ callback_registry.register_callback(...)
40
+ end
39
41
 
40
42
  module ClassMethods
41
43
  def class_callback_registry
@@ -68,7 +70,13 @@ module Foobara
68
70
  end
69
71
  end
70
72
 
71
- foobara_delegate :register_callback, :possible_actions, to: :class_callback_registry
73
+ def register_callback(...)
74
+ class_callback_registry.register_callback(...)
75
+ end
76
+
77
+ def possible_actions
78
+ class_callback_registry.possible_actions
79
+ end
72
80
  end
73
81
 
74
82
  on_include do
@@ -4,7 +4,7 @@ module Foobara
4
4
  module Validators
5
5
  class ModelInstanceIsValid < DetachedEntity::Validators::ModelInstanceIsValid
6
6
  def applicable?(record)
7
- record && (record.created? || record.built?)
7
+ record && (record.created? || record.built?) && !record.skip_validations
8
8
  end
9
9
 
10
10
  def expected_type_symbol
@@ -7,6 +7,9 @@ module Foobara
7
7
 
8
8
  if strict_type_declaration != new_type_declaration
9
9
  if new_type_declaration[:type] == :entity
10
+ # It's important that we don't create another entity with different attributes
11
+ # or various things like crud drivers or type transformers can become confused.
12
+ # So we will create it as a detached_entity instead.
10
13
  new_type_declaration[:type] = :detached_entity
11
14
 
12
15
  if new_type_declaration[:model_base_class] == "Foobara::Entity"
@@ -8,11 +8,10 @@ module Foobara
8
8
  elsif record.persisted?
9
9
  # We will assume that we do not need to clean up the primary key itself as
10
10
  # we will assume we don't allow sensitive primary keys for now.
11
- # We use .new because the target_class should be a detached entity
12
- to_type.target_class.new(
13
- { record.class.primary_key_attribute => record.primary_key },
14
- { mutable: false, skip_validations: true }
15
- )
11
+ thunkish = to_type.target_class.send(build_method, record.class.primary_key_attribute => record.primary_key)
12
+ thunkish.skip_validations = true
13
+ thunkish.mutable = false
14
+ thunkish
16
15
  else
17
16
  # :nocov:
18
17
  raise "Not sure what to do with a record that isn't loaded, created, or persisted"
@@ -21,8 +20,8 @@ module Foobara
21
20
  end
22
21
 
23
22
  def build_method
24
- if to_type.extends_type?(BuiltinTypes[:entity])
25
- # TODO: test this code path
23
+ if to_type.extends?(BuiltinTypes[:entity])
24
+ # TODO: figure out a way to test this path
26
25
  # :nocov:
27
26
  :build
28
27
  # :nocov:
@@ -21,6 +21,10 @@ module Foobara
21
21
  domains.map(&:types).flatten
22
22
  end
23
23
 
24
+ def detached_entities
25
+ domains.map(&:detached_entities).flatten
26
+ end
27
+
24
28
  def entities
25
29
  domains.map(&:entities).flatten
26
30
  end
@@ -31,6 +31,10 @@ module Foobara
31
31
  end
32
32
  end
33
33
 
34
+ def detached_entities
35
+ organizations.map(&:detached_entities).flatten
36
+ end
37
+
34
38
  def entities
35
39
  organizations.map(&:entities).flatten
36
40
  end
@@ -72,7 +72,7 @@ module Foobara
72
72
 
73
73
  # TODO: replace this with primitive?
74
74
  def builtin?
75
- BuiltinTypes.builtin_reference?(reference)
75
+ BuiltinTypes.builtin_reference?(reference) || self[:builtin]
76
76
  end
77
77
 
78
78
  def primitive?
@@ -7,7 +7,11 @@ module Foobara
7
7
 
8
8
  module Concerns
9
9
  module StateTransitions
10
- foobara_delegate :close!, :currently_open?, to: :state_machine
10
+ foobara_delegate :close, to: :state_machine
11
+
12
+ def currently_open?
13
+ state_machine.currently_open?
14
+ end
11
15
 
12
16
  def open!
13
17
  state_machine.open! do
@@ -14,7 +14,9 @@ module Foobara
14
14
  self.tables = {}
15
15
  end
16
16
 
17
- foobara_delegate :entity_attributes_crud_driver, to: :entity_base
17
+ def entity_attributes_crud_driver
18
+ entity_base.entity_attributes_crud_driver
19
+ end
18
20
 
19
21
  def create(entity_class, attributes = {})
20
22
  Persistence.to_base(entity_class).transaction(existing_transaction: self) do
@@ -116,6 +116,12 @@ module Foobara
116
116
  def has_sensitive_types?
117
117
  return true if sensitive?
118
118
 
119
+ # TODO: this is a hack... come up with a better/separate way to detect types with private attributes
120
+ if declaration_data.is_a?(::Hash)
121
+ private = declaration_data[:private]
122
+ return true if private.is_a?(::Array) && !private.empty?
123
+ end
124
+
119
125
  if element_type
120
126
  return true if element_type.has_sensitive_types?
121
127
  end
data/version.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Foobara
2
+ module Version
3
+ VERSION = "0.1.7".freeze
4
+ MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -491,6 +491,7 @@ files:
491
491
  - projects/value/src/validator.rb
492
492
  - projects/weak_object_set/lib/foobara/weak_object_set.rb
493
493
  - projects/weak_object_set/src/weak_object_set.rb
494
+ - version.rb
494
495
  homepage: https://foobara.com
495
496
  licenses:
496
497
  - MPL-2.0