lutaml-model 0.8.201 → 0.8.203

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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/dependent-tests.yml +59 -2
  4. data/.github/workflows/downstream-performance.yml +1 -22
  5. data/.github/workflows/performance.yml +1 -33
  6. data/.github/workflows/rake.yml +2 -6
  7. data/.rubocop.yml +0 -10
  8. data/.rubocop_todo.yml +0 -4
  9. data/Gemfile +0 -23
  10. data/README.adoc +25 -86
  11. data/Rakefile +2 -167
  12. data/docs/_guides/advanced-mapping.adoc +6 -6
  13. data/docs/_guides/character-encoding.adoc +0 -3
  14. data/docs/_guides/gem-integration.adoc +1 -1
  15. data/docs/_guides/index.adoc +0 -4
  16. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  17. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  18. data/docs/_guides/xml-namespaces.adoc +2 -3
  19. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  20. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  21. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  22. data/docs/_pages/comparison-with-shale.adoc +1 -1
  23. data/docs/_pages/configuration.adoc +6 -40
  24. data/docs/_pages/index.adoc +0 -1
  25. data/docs/_pages/serialization_adapters.adoc +4 -16
  26. data/docs/_references/architecture.adoc +1 -1
  27. data/docs/_references/lutaml-namespace-planning.md +1 -1
  28. data/docs/_references/plan-schema-spec.adoc +45 -18
  29. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  30. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  31. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  32. data/docs/architecture.md +7 -11
  33. data/docs/conversion_caching.adoc +1 -1
  34. data/docs/index.adoc +0 -1
  35. data/docs/key_value_data_model.adoc +1 -1
  36. data/docs/namespace-management.adoc +4 -10
  37. data/lib/lutaml/json/format.rb +0 -1
  38. data/lib/lutaml/json/generator_options.rb +0 -1
  39. data/lib/lutaml/key_value/transform.rb +149 -37
  40. data/lib/lutaml/lml/document_builder.rb +2 -2
  41. data/lib/lutaml/lml/entity_types.rb +2 -2
  42. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  43. data/lib/lutaml/model/attribute.rb +11 -6
  44. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  45. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  46. data/lib/lutaml/model/global_context.rb +3 -5
  47. data/lib/lutaml/model/instrumentation.rb +0 -3
  48. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  49. data/lib/lutaml/model/register.rb +20 -31
  50. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  51. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  52. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  53. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  54. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  55. data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
  56. data/lib/lutaml/model/serialize/initialization.rb +19 -9
  57. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  58. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  59. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  60. data/lib/lutaml/model/store.rb +10 -17
  61. data/lib/lutaml/model/toml.rb +0 -2
  62. data/lib/lutaml/model/transformation_registry.rb +3 -7
  63. data/lib/lutaml/model/version.rb +1 -1
  64. data/lib/lutaml/model.rb +3 -19
  65. data/lib/lutaml/toml/format.rb +4 -8
  66. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  67. data/lib/lutaml/xml/adapter.rb +0 -4
  68. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  69. data/lib/lutaml/xml/builder/base.rb +0 -3
  70. data/lib/lutaml/xml/builder.rb +0 -8
  71. data/lib/lutaml/xml/data_model.rb +1 -1
  72. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  73. data/lib/lutaml/xml/format.rb +22 -74
  74. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  75. data/lib/lutaml/xml/model_transform.rb +14 -24
  76. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  77. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  78. data/lib/lutaml/xml/schema/builder.rb +6 -9
  79. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  80. data/lib/lutaml/xml/xml_element.rb +3 -2
  81. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  82. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  83. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  84. data/lib/tasks/performance_comparator.rb +1 -1
  85. data/lutaml-model.gemspec +3 -8
  86. data/spec/address_person_spec.rb +8 -0
  87. data/spec/address_spec.rb +4 -0
  88. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  89. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  90. data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
  91. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  92. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  93. data/spec/lutaml/model/cdata_spec.rb +2 -15
  94. data/spec/lutaml/model/encoding_spec.rb +0 -9
  95. data/spec/lutaml/model/except_spec.rb +0 -7
  96. data/spec/lutaml/model/json_spec.rb +0 -14
  97. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  98. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  99. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  100. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  101. data/spec/lutaml/model/serializable_spec.rb +0 -2
  102. data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
  103. data/spec/lutaml/model/toml_spec.rb +0 -23
  104. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  105. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  106. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  107. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  108. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  109. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  110. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  111. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  112. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  113. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  114. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  115. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  116. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  117. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  118. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  119. data/spec/lutaml/xml/xml_spec.rb +2 -88
  120. data/spec/spec_helper.rb +8 -28
  121. data/spec/support/test_adapter_config.rb +6 -6
  122. metadata +2 -32
  123. data/.github/workflows/js-pr-check.yml +0 -106
  124. data/.github/workflows/js-sync.yml +0 -55
  125. data/.github/workflows/opal.yml +0 -65
  126. data/.gitmodules +0 -6
  127. data/.rspec-opal +0 -5
  128. data/docs/_guides/opal.adoc +0 -232
  129. data/lib/compat/opal/generate_boot.rb +0 -137
  130. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  131. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  132. data/lib/compat/opal/monitor.rb +0 -31
  133. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  134. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  135. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  136. data/lib/compat/opal/moxml_boot.rb +0 -68
  137. data/lib/compat/opal/objectspace_shim.rb +0 -23
  138. data/lib/compat/opal/rexml/namespace.rb +0 -59
  139. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  140. data/lib/compat/opal/rexml/source.rb +0 -214
  141. data/lib/compat/opal/rexml/text.rb +0 -426
  142. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  143. data/lib/compat/opal/rexml_compat.rb +0 -85
  144. data/lib/compat/opal/yaml_compat.rb +0 -32
  145. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  146. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  147. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  148. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  149. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  150. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  151. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  152. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  153. data/spec/support/opal.rb +0 -9
@@ -332,7 +332,7 @@ The `DeclarationPlanner` creates optimal xmlns declaration strategies:
332
332
 
333
333
  Applies the plan during XML generation.
334
334
 
335
- All XML adapters (Nokogiri, Oga, Ox) use the three-phase architecture:
335
+ All XML adapters (Nokogiri, Ox) use the three-phase architecture:
336
336
 
337
337
  * `build_element_with_plan` - Core element building with namespace plan
338
338
  * `build_ordered_element_with_plan` - Ordered content support
@@ -439,7 +439,6 @@ an optimal declaration strategy:
439
439
  All XML adapters have been updated to use the three-phase architecture:
440
440
 
441
441
  **NokogiriAdapter** (`lib/lutaml/model/xml/nokogiri_adapter.rb`)
442
- **OgaAdapter** (`lib/lutaml/model/xml/oga_adapter.rb`)
443
442
  **OxAdapter** (`lib/lutaml/model/xml/ox_adapter.rb`)
444
443
 
445
444
  Each adapter implements:
@@ -60,14 +60,9 @@ both element declaration and type definition
60
60
 
61
61
  == Adapter support
62
62
 
63
- XSD generation uses SchemaBuilder adapters:
64
-
65
- * `Nokogiri`: Default,
66
- full XSD 1.0 support
67
- * `Oga`: Pure Ruby, feature
68
- complete
69
-
70
- Both adapters produce identical, standards-compliant XSD output.
63
+ XSD generation uses the SchemaBuilder adapters: the Nokogiri wrapper for
64
+ byte-identical emission, and the moxml layer for every other configured
65
+ engine. Both produce identical, standards-compliant XSD output.
71
66
 
72
67
  == Complete example
73
68
 
@@ -239,7 +239,7 @@ This document provides a comprehensive architectural overview of LutaML::Model's
239
239
  ▼
240
240
  ┌──────────────────────────┐
241
241
  │ XML Parser │
242
- │ (Nokogiri/Oga/Ox) │
242
+ │ (Nokogiri/Ox) │
243
243
  └──────┬───────────────────┘
244
244
  │
245
245
  ▼
@@ -942,12 +942,6 @@ xml_string = adapter.build_xml(
942
942
  # - apply_prefix(element_name, prefix)
943
943
  ```
944
944
 
945
- **OgaAdapter** (`oga_adapter.rb`):
946
- ```ruby
947
- # Same interface as NokogiriAdapter
948
- # Uses Oga XML library
949
- ```
950
-
951
945
  **OxAdapter** (`ox_adapter.rb`):
952
946
  ```ruby
953
947
  # Same interface as NokogiriAdapter
@@ -1271,7 +1265,7 @@ ns = register.namespace_for_prefix("po") # => PoNamespace
1271
1265
  ```ruby
1272
1266
  # Configure adapter
1273
1267
  Lutaml::Model::Config.configure do |config|
1274
- config.xml_adapter = :nokogiri # or :oga, :ox
1268
+ config.xml_adapter = :nokogiri # or :ox
1275
1269
  end
1276
1270
 
1277
1271
  # Used at runtime
data/docs/architecture.md CHANGED
@@ -116,25 +116,21 @@ cached_resolver.resolve(:string, context) # Resolves and caches
116
116
  cached_resolver.resolve(:string, context) # Returns cached value
117
117
  ```
118
118
 
119
- **Cache backend**: Uses `ConcurrentMapCache` on native Ruby (lock-free via Concurrent::Map) or `MutexHashCache` on Opal (Mutex + Hash). The backend is selected automatically and can be overridden per-instance.
119
+ **Cache backend**: Uses `ConcurrentMapCache` (lock-free via Concurrent::Map). The backend can be overridden per-instance.
120
120
 
121
121
  ### RuntimeCompatibility
122
122
 
123
- **Responsibility**: Abstracts runtime differences between native Ruby and Opal.
123
+ **Responsibility**: The platform helpers the load-time wiring uses.
124
124
 
125
125
  ```ruby
126
- Lutaml::Model::RuntimeCompatibility.opal? #=> false (native) / true (Opal)
127
- Lutaml::Model::RuntimeCompatibility.native? #=> true (native) / false (Opal)
128
-
129
- # Conditional autoload — only registers on native Ruby
126
+ # Registers each constant's autoload on the namespace
130
127
  RuntimeCompatibility.autoload_native(self, OjAdapter: "path/to/oj_adapter")
131
128
 
132
- # Conditional require — skips on Opal
133
- RuntimeCompatibility.require_native("nokogiri", "ox")
134
- ```
129
+ # Requires each path
130
+ RuntimeCompatibility.require_native("concurrent")
135
131
 
136
- On Opal, provides shim classes (`Mutex`, `ConditionVariable`, `Thread`) so
137
- code that references these compiles without errors.
132
+ RuntimeCompatibility.windows? #=> true on Windows
133
+ ```
138
134
 
139
135
  ### TypeSubstitution
140
136
 
@@ -131,7 +131,7 @@ lives elsewhere); non-`Hash` options (e.g. the generator state objects Ruby's
131
131
  JSON/YAML protocols pass); instance graphs `Marshal` cannot digest — notably,
132
132
  instances parsed from XML retain native parser nodes for round-trip fidelity
133
133
  and therefore skip serialization caching (programmatically built instances
134
- cache fully); and any environment without native `Marshal`/`Digest` (Opal).
134
+ cache fully); and any environment without native `Marshal`/`Digest`.
135
135
 
136
136
  Invalidation:: Entirely the store's concern — TTL, eviction, persistence, and
137
137
  clearing belong to the backend you configured. If you mutate a register's
data/docs/index.adoc CHANGED
@@ -19,7 +19,6 @@ Lutaml::Model is a Ruby library for creating information models with attributes
19
19
  * **Multi-format serialization** - XML, JSON, YAML, TOML, JSON-LD, Turtle, Hash, YAML Stream
20
20
  * **XML namespace support** - Full W3C namespace implementation
21
21
  * **Linked Data support** - RDF namespaces, JSON-LD, and Turtle serialization
22
- * **Opal support** - Run in the browser via Opal (Ruby to JavaScript) with REXML adapter
23
22
  * **Validation** - Built-in validation with custom rules
24
23
  * **Schema generation** - Generate XSD, JSON Schema, YAML Schema
25
24
  * **Polymorphism** - Handle multiple types elegantly
@@ -89,7 +89,7 @@ KeyValueDataModel mirrors the proven XmlDataModel architecture:
89
89
  | `KeyValueDataModel::KeyValueElement`
90
90
 
91
91
  | **Adapters**
92
- | Nokogiri, Ox, Oga
92
+ | Nokogiri, Ox
93
93
  | StandardJson, MultiJson, Oj, StandardYaml, TomlRb, Tomlib
94
94
 
95
95
  | **Output**
@@ -1021,44 +1021,38 @@ This follows W3C XML Namespaces 1.0 §6.2 which states that child elements inher
1021
1021
 
1022
1022
  == Adapter Compatibility
1023
1023
 
1024
- All four XML adapters (Nokogiri, Ox, Oga, REXML) now support the same namespace features:
1024
+ All XML adapters (Nokogiri, Ox, REXML) support the same namespace features:
1025
1025
 
1026
- [cols="1,1,1,1,1"]
1027
- |===
1028
- | Feature | Nokogiri | Ox | Oga | REXML
1026
+ [cols="1,1,1,1"]|===
1027
+ | Feature | Nokogiri | Ox | REXML
1029
1028
 
1030
1029
  | Default namespace format
1031
1030
  | ✓
1032
1031
  | ✓
1033
1032
  | ✓
1034
- | ✓
1035
1033
 
1036
1034
  | Prefixed namespace format
1037
1035
  | ✓
1038
1036
  | ✓
1039
1037
  | ✓
1040
- | ✓
1041
1038
 
1042
1039
  | Namespace inheritance
1043
1040
  | ✓
1044
1041
  | ✓
1045
1042
  | ✓
1046
- | ✓
1047
1043
 
1048
1044
  | Custom prefix strings (`prefix: "custom"`)
1049
1045
  | ✓
1050
1046
  | ✓
1051
1047
  | ✓
1052
- | ✓
1053
1048
 
1054
1049
  | Round-trip namespace preservation
1055
1050
  | ✓
1056
1051
  | ✓
1057
1052
  | ✓
1058
- | ✓
1059
1053
  |===
1060
1054
 
1061
- NOTE: All adapters now produce identical namespace output. The Oga adapter namespace issues that existed in earlier versions have been resolved.
1055
+ NOTE: All adapters now produce identical namespace output.
1062
1056
 
1063
1057
  == Related Documentation
1064
1058
 
@@ -35,7 +35,6 @@ module Lutaml
35
35
 
36
36
  # Detect available JSON adapters
37
37
  def self.detect_adapter
38
- return :standard if defined?(::JSON) && Lutaml::Model.opal?
39
38
  return :oj if defined?(::Oj)
40
39
  return :multi_json if defined?(::MultiJson)
41
40
  return :standard if defined?(::JSON)
@@ -32,7 +32,6 @@ module Lutaml
32
32
  ].freeze
33
33
 
34
34
  # Additive, so a json release that adds an option needs no change here.
35
- # Opal's JSON shim has no State class, hence the guard.
36
35
  DERIVED_PERMITTED =
37
36
  if defined?(::JSON::State)
38
37
  accessors = ::JSON::State.instance_methods(false).grep(/\A[a-z_][a-z0-9_]*=\z/)
@@ -42,8 +42,15 @@ module Lutaml
42
42
  # lutaml-model#88: nil unless the mapping partitions a wire key
43
43
  # with when_attribute rules — the common case pays one scan.
44
44
  partition = kv_partition(rules)
45
+ # #1311 lever 3: parent/root are the same for every rule of one
46
+ # node, so one cast-options hash serves the whole rule walk and
47
+ # carries the memoized propagated child options across its
48
+ # child-valued attributes.
49
+ cast_options = { lutaml_parent: instance,
50
+ lutaml_root: instance.lutaml_root || instance }
45
51
  rules.each do |rule|
46
- process_mapping_rule(data, instance, format, rule, options, partition)
52
+ process_mapping_rule(data, instance, format, rule, options,
53
+ partition, cast_options)
47
54
  end
48
55
  collect_unmapped_keys(data, instance, mappings, rules)
49
56
 
@@ -156,17 +163,13 @@ module Lutaml
156
163
  # :scalar, :model, :child_map or :unmapped; child_rows is the child
157
164
  # model's own row set. A recursive model graph compiles as a
158
165
  # self-referential plan: child_rows may be the plan itself.
159
- # Concurrent::Map under threaded MRI, plain Hash under Opal
160
- # (Concurrent is unavailable there) — the RULE_RECORDS pattern.
166
+ # Concurrent::Map — the RULE_RECORDS pattern.
161
167
  # Writes are idempotent (the same deterministic plan is computed),
162
168
  # so a lost race costs a duplicate build, never a wrong value.
163
- KV_GROUP_PLANS = if Lutaml::Model.opal?
164
- {}
165
- else
166
- Lutaml::Model::RuntimeCompatibility
167
- .require_native("concurrent")
168
- Concurrent::Map.new
169
- end
169
+ KV_GROUP_PLANS = begin
170
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
171
+ Concurrent::Map.new
172
+ end
170
173
 
171
174
  # [model class, register, format, generation] -> { rule => plan }.
172
175
  # Class-level, generation-retired: the whole dispatch table for a
@@ -176,13 +179,10 @@ module Lutaml
176
179
  # node (~12 predicate calls plus a key array per rule per node;
177
180
  # 154k+154k allocations per heroku.json parse). Same
178
181
  # idempotent-write pattern as KV_GROUP_PLANS.
179
- KV_WALK_PLANS = if Lutaml::Model.opal?
180
- {}
181
- else
182
- Lutaml::Model::RuntimeCompatibility
183
- .require_native("concurrent")
184
- Concurrent::Map.new
185
- end
182
+ KV_WALK_PLANS = begin
183
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
184
+ Concurrent::Map.new
185
+ end
186
186
 
187
187
  def self.kv_group_plan(model_class, format, register)
188
188
  # Context generation: specs (and apps) reset registers between
@@ -271,10 +271,18 @@ module Lutaml
271
271
  # dispatch and registered type substitutions own their cast
272
272
  # (the per-rule walk threads them through cast options).
273
273
  return false if attr.collection? && attr.collection.is_a?(Range)
274
- return false if attr.polymorphic? || attr.union? ||
275
- attr.custom_collection?
274
+ return false if attr.union? || attr.custom_collection?
276
275
 
277
276
  type = attr.type(register)
277
+ # A polymorphic VALUE attribute (a model-typed attribute whose
278
+ # concrete class the walk resolves) owns its cast on the walk.
279
+ # A polymorphic_class flag on a SCALAR attribute marks the
280
+ # class's discriminator (`_class`): it is a plain scalar here —
281
+ # with or without the map on this rule, exactly as the walk
282
+ # reads it — and the concrete child class comes from each
283
+ # document at build time (kv_group_child_class).
284
+ return false if attr.polymorphic? &&
285
+ !(type.is_a?(Class) && type < Lutaml::Model::Type::Value)
278
286
  return false if Lutaml::Model::GlobalContext.context(register)
279
287
  .substitution_for(type).any?
280
288
 
@@ -291,7 +299,8 @@ module Lutaml
291
299
  rule.hash_mappings)
292
300
  return false unless child_plan
293
301
 
294
- rows << [rule, attr, :child_map, child_plan, nil, nil]
302
+ rows << [rule, attr, :child_map, child_plan, nil, nil, nil,
303
+ kv_absent_action(attr, :child_map)]
295
304
  next
296
305
  end
297
306
 
@@ -303,12 +312,18 @@ module Lutaml
303
312
 
304
313
  # child_register rides the row: the plan was BUILT under it,
305
314
  # and rebuilding the resolution per model row per document
306
- # cost a Concurrent::Map hop each time (TODO.perf 14).
307
- rows << [rule, attr, :model, type, child_rows, child_register]
315
+ # cost a Concurrent::Map hop each time (TODO.perf 14). The
316
+ # seventh slot is the child's class-level discriminator rule
317
+ # (polymorphic_map:), if any: the concrete class comes from
318
+ # each document, so these rows serve the fallthrough case.
319
+ poly = type.mappings_for(format, child_register)&.polymorphic_mapping
320
+ rows << [rule, attr, :model, type, child_rows, child_register, poly,
321
+ kv_absent_action(attr, :model)]
308
322
  elsif type.is_a?(Class) && type < Lutaml::Model::Type::Value &&
309
323
  !attr.value_policy.whole_value?(type) &&
310
324
  !Lutaml::Model::Attribute.custom_from_probe?(type)
311
- rows << [rule, attr, :scalar, nil, nil, nil]
325
+ rows << [rule, attr, :scalar, nil, nil, nil, nil,
326
+ kv_absent_action(attr, :scalar)]
312
327
  else
313
328
  return false
314
329
  end
@@ -319,12 +334,59 @@ module Lutaml
319
334
  Array(rule.name).each { |name| claimed[name.to_s] = true } if rule.name
320
335
  end
321
336
  claimed.freeze
322
- rows << [nil, nil, :unmapped, unmapped_target, claimed, nil]
337
+ rows << [nil, nil, :unmapped, unmapped_target, claimed, nil, nil, nil]
323
338
  end
324
339
  # No eligible rows at all (empty mapping) — nothing to gain.
325
340
  rows.empty? ? nil : rows
326
341
  end
327
342
 
343
+ # The absent-key outcome of a plan row, compiled once (#1311):
344
+ # the walk assigns the attribute's default through its writer —
345
+ # nil when the attribute has none — except for a child-map rule
346
+ # with no default, where it returns before assigning. The implicit
347
+ # empty-collection default is the one proc default whose value is
348
+ # provably the collection itself, so the writer sees the same
349
+ # argument either way. Explicit defaults on model-valued and
350
+ # child-map rules keep the walk: whether a proc default materializes
351
+ # a document the rule must translate is not a per-class constant.
352
+ def self.kv_absent_action(attr, kind)
353
+ case kind
354
+ when :scalar
355
+ :set
356
+ when :model, :child_map
357
+ return :set if attr.default_kind == :none
358
+ return :set if attr.lazy_collection_default?
359
+
360
+ :walk
361
+ else
362
+ :walk
363
+ end
364
+ end
365
+
366
+ # The concrete class behind a :model row whose declared type carries
367
+ # a class-level discriminator (polymorphic_map:), read from one
368
+ # document the way resolve_polymorphic reads it — the discriminator
369
+ # key, the map entry, Object.const_get — with an entry that resolves
370
+ # to the declared type itself falling through to the row's own rows.
371
+ # Returns [class, rows, register]: the concrete class hydrates through
372
+ # its own cached plan; nil when that plan is ineligible, so the node
373
+ # takes the walk (which owns the error for a missing discriminator).
374
+ def self.kv_group_child_class(type, rows, poly, doc, format, register)
375
+ key = doc[poly.name]
376
+ klass_name = key && poly.polymorphic_map[key]
377
+ return nil unless klass_name
378
+
379
+ klass = Object.const_get(klass_name)
380
+ return [type, rows, register] if klass == type
381
+
382
+ klass_register = Lutaml::Model::Register.resolve_for_child(klass,
383
+ register)
384
+ klass_rows = kv_group_plan(klass, format, klass_register)
385
+ return nil unless klass_rows
386
+
387
+ [klass, klass_rows, klass_register]
388
+ end
389
+
328
390
  # Class-level twin of the walk's child-map compile: the registry
329
391
  # lookups (child rules, per-attribute wire names, path casts)
330
392
  # resolve once per plan instead of once per node per child. nil
@@ -504,7 +566,7 @@ child_mappings)
504
566
  # the separate string_or_symbol_key? probe goes away.
505
567
  v = Lutaml::Model::Utils.fetch_str_or_sym(frame.doc, rule.name, MISSING)
506
568
  if v.equal?(MISSING)
507
- (frame.absent ||= []) << rule
569
+ (frame.absent ||= []) << row
508
570
  i += 1
509
571
  next
510
572
  end
@@ -554,11 +616,26 @@ child_mappings)
554
616
  private
555
617
 
556
618
  # :child when the frame's pending row has a document the plan
557
- # covers, :fallback otherwise.
619
+ # covers, :fallback otherwise. A :model row whose declared type
620
+ # carries a class-level discriminator (polymorphic_map:, the seventh
621
+ # slot) resolves the concrete class from EACH document, so the
622
+ # frame's request follows the document, not the row.
558
623
  def request_child(frame)
559
624
  document = frame.next_child_document
560
625
  return :fallback unless document
561
626
 
627
+ row = frame.rows[frame.pending_index]
628
+ if (poly = row[6])
629
+ resolved = self.class.kv_group_child_class(row[3], row[4], poly,
630
+ document, frame.format,
631
+ row[5])
632
+ return :fallback unless resolved
633
+
634
+ frame.request_transform = self.class.cached_transform(resolved[0],
635
+ resolved[2])
636
+ frame.request_rows = resolved[1]
637
+ frame.request_register = resolved[2]
638
+ end
562
639
  frame.request_doc = document
563
640
  :child
564
641
  end
@@ -594,9 +671,7 @@ child_mappings)
594
671
 
595
672
  instance.public_send(row[0].kv_setter, v)
596
673
  end
597
- frame.absent&.each do |rule|
598
- process_mapping_rule(frame.doc, instance, frame.format, rule, frame.options, nil)
599
- end
674
+ kv_apply_absent(frame, instance)
600
675
  frame.children&.each do |child|
601
676
  child.lutaml_parent = instance
602
677
  child.lutaml_root ||= instance.lutaml_root || instance
@@ -618,6 +693,35 @@ child_mappings)
618
693
  instance
619
694
  end
620
695
 
696
+ # Absent keys through the compiled per-row action (#1311) instead
697
+ # of the per-rule walk: on the expressir corpus the absent walks
698
+ # were ~three quarters of the lane's samples. A :set row assigns
699
+ # the attribute's default exactly as the walk would — the
700
+ # DEFAULT_VALUE_MAP sends the omitted sentinel to nil, and the
701
+ # writer casts and marks the value set; :skip leaves the constructor
702
+ # seed (child-map rules with no default). Runtime value-map
703
+ # overrides keep the walk: their outcome is not a per-class
704
+ # constant.
705
+ def kv_apply_absent(frame, instance)
706
+ return unless frame.absent
707
+
708
+ overrides = frame.options[:nil] || frame.options[:empty] ||
709
+ frame.options[:omitted]
710
+ frame.absent.each do |row|
711
+ rule = row[0]
712
+ action = overrides ? :walk : row[7]
713
+ case action
714
+ when :set
715
+ value = row[1].default_value(frame.register, instance)
716
+ value = nil if Lutaml::Model::Utils.uninitialized?(value)
717
+ instance.public_send(rule.kv_setter, value)
718
+ when :walk
719
+ process_mapping_rule(frame.doc, instance, frame.format, rule,
720
+ frame.options, nil)
721
+ end
722
+ end
723
+ end
724
+
621
725
  def process_rule!(instance, rule, hash, format, _mappings, options)
622
726
  return handle_delegate(instance, rule, hash, format) if rule.delegate
623
727
 
@@ -985,7 +1089,7 @@ child_mappings)
985
1089
  end
986
1090
 
987
1091
  def process_mapping_rule(doc, instance, format, rule, options = {},
988
- partition = nil)
1092
+ partition = nil, cast_options = nil)
989
1093
  plans = walk_plans_for(format)
990
1094
  plan = plans[rule] ||= build_walk_plan(format, rule)
991
1095
  kind = plan.kind
@@ -1042,7 +1146,7 @@ partition = nil)
1042
1146
  end
1043
1147
  unless kind == :hash_map
1044
1148
  value = cast_value(value, attr, format, rule,
1045
- instance)
1149
+ instance, cast_options)
1046
1150
  end
1047
1151
 
1048
1152
  # Range errors stay eager here. The over-count error only fires when the
@@ -1279,12 +1383,20 @@ partition = nil)
1279
1383
  end
1280
1384
  end
1281
1385
 
1282
- def cast_value(value, attr, format, rule, instance)
1283
- cast_options = rule.polymorphic ? { polymorphic: rule.polymorphic } : {}
1284
- cast_options[:lutaml_parent] = instance if instance
1285
- if instance
1286
- cast_options[:lutaml_root] =
1287
- (instance.lutaml_root || instance)
1386
+ def cast_value(value, attr, format, rule, instance, cast_options = nil)
1387
+ # #1311 lever 3: the node's shared cast-options hash replaces the
1388
+ # per-rule allocation; the rule's polymorphic list must not leak
1389
+ # into siblings, so it rides a copy.
1390
+ unless cast_options
1391
+ cast_options = {}
1392
+ cast_options[:lutaml_parent] = instance if instance
1393
+ if instance
1394
+ cast_options[:lutaml_root] =
1395
+ (instance.lutaml_root || instance)
1396
+ end
1397
+ end
1398
+ if rule.polymorphic
1399
+ cast_options = cast_options.merge(polymorphic: rule.polymorphic)
1288
1400
  end
1289
1401
  attr.cast(value, format, lutaml_register, cast_options)
1290
1402
  end
@@ -7,8 +7,8 @@ module Lutaml
7
7
  class DocumentBuilder
8
8
  # Default registry: builder keys → LML model classes. Built lazily
9
9
  # (method, not load-time constant): the model classes live in the
10
- # boot's later sections, and eager evaluation breaks Opal's
11
- # sequential require order.
10
+ # boot's later sections, and eager evaluation would load them
11
+ # before they are defined.
12
12
  def self.default_registry
13
13
  @default_registry ||= {
14
14
  document: ::Lutaml::Lml::Document,
@@ -8,8 +8,8 @@ module Lutaml
8
8
  # type list in four places.
9
9
  module EntityTypes
10
10
  # Registry built lazily (method, not load-time constant): the entity
11
- # model classes load later in the boot, and eager evaluation breaks
12
- # Opal's sequential require order.
11
+ # model classes load later in the boot, and eager evaluation would
12
+ # reference them before they are defined.
13
13
  def self.all
14
14
  @all ||= [UmlClass, Enum, DataType, PrimitiveType].freeze
15
15
  end
@@ -32,16 +32,13 @@ module Lutaml
32
32
  # Adapters on the deprecation path. moxml is the only supported
33
33
  # XML facade going forward, and its default engine (Nokogiri,
34
34
  # with the leptris native engine preferred when present) is the
35
- # supported lane; the pure-Ruby REXML and Oga engines remain
36
- # loadable but select for the last time in the 0.8 line.
35
+ # supported lane; the pure-Ruby REXML engine remains loadable
36
+ # but selects for the last time in the 0.8 line.
37
37
  DEPRECATED_ADAPTERS = {
38
38
  %i[xml rexml] => "the REXML engine is deprecated; moxml's " \
39
39
  "default engine (Nokogiri, or the leptris " \
40
40
  "native engine when present) is the supported " \
41
41
  "XML lane",
42
- %i[xml oga] => "the Oga engine is deprecated; moxml's default " \
43
- "engine (Nokogiri, or the leptris native engine " \
44
- "when present) is the supported XML lane",
45
42
  }.freeze
46
43
 
47
44
  # --- Resolution ---
@@ -294,12 +291,8 @@ module Lutaml
294
291
  end
295
292
 
296
293
  # Default key-value adapter loading
297
- adapter_path = if Lutaml::Model.opal?
298
- "lutaml/key_value/adapter/#{adapter}/#{type}"
299
- else
300
- File.join(File.dirname(__FILE__), "../key_value/adapter",
301
- adapter, type)
302
- end
294
+ adapter_path = File.join(File.dirname(__FILE__), "../key_value/adapter",
295
+ adapter, type)
303
296
  require adapter_path
304
297
  rescue LoadError => e
305
298
  # Chain the cause so a missing engine gem is named, not masked.
@@ -452,7 +445,6 @@ module Lutaml
452
445
  # instead of a clean standard-lane parse (#978).
453
446
  def detect_yeptris_kv_adapter(format)
454
447
  default = metadata.dig(format, :default)
455
- return default if Lutaml::Model.opal?
456
448
  return default unless Utils.safe_load("yeptris", :Yeptris)
457
449
 
458
450
  load_adapter(format, :yeptris).available? ? :yeptris : default
@@ -461,7 +453,7 @@ module Lutaml
461
453
  # Detect available XML adapter.
462
454
  #
463
455
  # Delegates to moxml which is the authority on XML adapter
464
- # availability and platform constraints (Opal, MRI, etc.).
456
+ # availability and platform constraints.
465
457
  #
466
458
  # @return [Symbol] adapter type name
467
459
  def detect_xml_adapter
@@ -472,8 +464,6 @@ module Lutaml
472
464
  #
473
465
  # @return [Symbol, nil] :teptris, :tomlib, :toml_rb, or nil
474
466
  def detect_toml_adapter
475
- return nil if Lutaml::Model.opal?
476
-
477
467
  # teptris 0.2.12+ parses ~3x and dumps ~8x faster than
478
468
  # tomlib and ships prebuilts for every platform (mingw-ucrt
479
469
  # restored in 0.2.4+) — native TOML on Windows retires the
@@ -1261,17 +1261,22 @@ instance_object = nil)
1261
1261
  )
1262
1262
  end
1263
1263
 
1264
- propagated = Serialize::DeserializationContext.propagate(options)
1264
+ # #1311 lever 3: the child options are a per-node constant,
1265
+ # memoized on this node's cast-options hash instead of being
1266
+ # rebuilt (slice + merge) per attribute with a child value.
1267
+ child_options = Serialize::DeserializationContext.child_options(
1268
+ options, register
1269
+ )
1265
1270
  return klass.apply_mappings(
1266
- { content_attr => value }, format,
1267
- propagated.merge(register: register)
1271
+ { content_attr => value }, format, child_options
1268
1272
  )
1269
1273
  end
1270
1274
 
1271
1275
  if can_serialize?(klass, value, format, options)
1272
- propagated = Serialize::DeserializationContext.propagate(options)
1273
- klass.apply_mappings(value, format,
1274
- propagated.merge(register: register))
1276
+ child_options = Serialize::DeserializationContext.child_options(
1277
+ options, register
1278
+ )
1279
+ klass.apply_mappings(value, format, child_options)
1275
1280
  elsif needs_conversion?(klass, value)
1276
1281
  klass.public_send(:"from_#{format}", value)
1277
1282
  else
@@ -29,18 +29,12 @@ module Lutaml
29
29
  self,
30
30
  ConcurrentMapCache: "#{__dir__}/cached_type_resolver/concurrent_map_cache",
31
31
  )
32
- autoload :MutexHashCache,
33
- "#{__dir__}/cached_type_resolver/mutex_hash_cache"
34
32
 
35
33
  # @return [Object] The delegate resolver (typically TypeResolver)
36
34
  attr_reader :delegate, :cache_backend
37
35
 
38
36
  def self.default_cache_backend
39
- if Lutaml::Model.opal?
40
- MutexHashCache.new
41
- else
42
- ConcurrentMapCache.new
43
- end
37
+ ConcurrentMapCache.new
44
38
  end
45
39
 
46
40
  # Create a new CachedTypeResolver.
@@ -3,7 +3,7 @@ module Lutaml
3
3
  class UnknownAdapterTypeError < Error
4
4
  # Available adapters by format
5
5
  AVAILABLE_ADAPTERS = {
6
- xml: %w[nokogiri ox oga rexml leptris],
6
+ xml: %w[nokogiri ox rexml leptris],
7
7
  json: %w[standard multi_json oj yeptris],
8
8
  yaml: %w[standard yeptris],
9
9
  toml: %w[teptris tomlib toml_rb],
@@ -344,11 +344,9 @@ context_id = nil)
344
344
  end
345
345
 
346
346
  class << self
347
- # Block form: avoids Opal's runtime string parsing requirement
348
- # (MRI's class_eval(string) needs `require 'opal-parser'` at
349
- # runtime under Opal, which isn't bundled). Closures are
350
- # allocated once at file load, not per call, so the perf cost
351
- # over the previous string form is negligible.
347
+ # Block form (no String class_eval). Closures are allocated
348
+ # once at file load, not per call, so the perf cost over a
349
+ # string form is negligible.
352
350
 
353
351
  class_eval do
354
352
  def registry