lutaml-model 0.8.203 → 0.8.205
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.
- checksums.yaml +4 -4
- data/.gitattributes +5 -0
- data/.github/workflows/lml-conformance.yml +71 -0
- data/.gitignore +7 -0
- data/README.adoc +1 -0
- data/docs/_guides/lml-cross-language.adoc +128 -0
- data/docs/_guides/native-engines.adoc +10 -0
- data/docs/_references/lml-conformance.adoc +78 -0
- data/docs/_references/lml-contract.adoc +290 -0
- data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
- data/lib/lutaml/model/lml/bundle.rb +171 -0
- data/lib/lutaml/model/lml/document.rb +46 -10
- data/lib/lutaml/model/lml/document_validator.rb +840 -0
- data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
- data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
- data/lib/lutaml/model/lml/exporter.rb +223 -87
- data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
- data/lib/lutaml/model/lml/importer.rb +180 -0
- data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
- data/lib/lutaml/model/lml/materialization.rb +257 -0
- data/lib/lutaml/model/lml/ordered_content.rb +577 -0
- data/lib/lutaml/model/lml/portable_json.rb +385 -0
- data/lib/lutaml/model/lml/rejected_error.rb +64 -15
- data/lib/lutaml/model/lml/round_trip.rb +86 -0
- data/lib/lutaml/model/lml/value_declarations.rb +84 -0
- data/lib/lutaml/model/lml.rb +61 -0
- data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
- data/lib/lutaml/model/schema/registry_generator.rb +1 -1
- data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
- data/lib/lutaml/model/sequence.rb +7 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +22 -8
- data/lib/lutaml/model/serialize/initialization.rb +2 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +85 -3
- data/lib/lutaml/xml/leptris/plan_compiler.rb +190 -45
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +209 -56
- data/lib/lutaml/xml/leptris/plan_serializer.rb +533 -102
- data/lib/lutaml/xml/leptris/plan_walk.rb +1 -0
- data/lib/lutaml/xml/schema/builder/moxml.rb +7 -3
- data/lib/lutaml/xml/transformation/order_reconciler.rb +4 -0
- data/lib/lutaml/xml/transformation/ordered_applier.rb +8 -7
- data/schema/lml/document.schema.json +179 -0
- data/scripts/lml/export_choices.rb +57 -0
- data/scripts/lml/export_conformance.rb +23 -0
- data/scripts/lml/export_mml.rb +253 -0
- data/scripts/lml/export_preservation.rb +421 -0
- data/scripts/lml/verify_artifacts.rb +31 -0
- data/spec/fixtures/lml_artifacts/model.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
- data/spec/fixtures/lml_conformance/core/index.json +1 -0
- data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
- data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
- data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
- data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
- data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
- data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
- data/spec/fixtures/lml_contract/bundle.json +81 -0
- data/spec/fixtures/lml_contract/manifest.json +30 -0
- data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v1_unit.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.json +32 -0
- data/spec/fixtures/lml_mml/inventory.json +1 -0
- data/spec/fixtures/lml_mml/manifest.json +1 -0
- data/spec/fixtures/lml_mml/oracle.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
- data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
- data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
- data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
- data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
- data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
- data/spec/lutaml/model/lml_document_spec.rb +279 -0
- data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
- data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
- data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
- data/spec/lutaml/model/lml_importer_spec.rb +290 -0
- data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
- data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
- data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
- data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
- data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
- data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
- data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
- data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
- data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
- data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
- data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
- data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
- data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
- data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
- data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
- data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
- data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
- data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
- data/spec/lutaml/model/sequence_spec.rb +48 -0
- data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
- data/spec/lutaml/xml/production_lane_parity_spec.rb +632 -0
- data/spec/support/lml_any_attribute_fixtures.rb +26 -0
- data/spec/support/lml_conformance.rb +292 -0
- data/spec/support/lml_corpus.rb +75 -0
- data/spec/support/lml_export_fixtures.rb +190 -0
- data/spec/support/lml_graph_fixtures.rb +108 -0
- data/spec/support/lml_import_fixtures.rb +52 -0
- data/spec/support/lml_mapping_fixtures.rb +170 -0
- data/spec/support/lml_materialization_fixtures.rb +53 -0
- data/spec/support/lml_model_choices_fixtures.rb +150 -0
- data/spec/support/lml_order_fixtures.rb +151 -0
- metadata +94 -3
- data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
data/lib/lutaml/model/lml.rb
CHANGED
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
module Lutaml
|
|
4
4
|
module Model
|
|
5
5
|
module Lml
|
|
6
|
+
autoload :ArtifactVerifier, "#{__dir__}/lml/artifact_verifier"
|
|
7
|
+
autoload :Bundle, "#{__dir__}/lml/bundle"
|
|
6
8
|
autoload :Document, "#{__dir__}/lml/document"
|
|
9
|
+
autoload :DocumentValidator, "#{__dir__}/lml/document_validator"
|
|
7
10
|
autoload :Exporter, "#{__dir__}/lml/exporter"
|
|
11
|
+
autoload :GraphExporter, "#{__dir__}/lml/graph_exporter"
|
|
12
|
+
autoload :Importer, "#{__dir__}/lml/importer"
|
|
13
|
+
autoload :MappingCompiler, "#{__dir__}/lml/mapping_compiler"
|
|
14
|
+
autoload :Materialization, "#{__dir__}/lml/materialization"
|
|
15
|
+
autoload :OrderedContent, "#{__dir__}/lml/ordered_content"
|
|
16
|
+
autoload :PortableJson, "#{__dir__}/lml/portable_json"
|
|
8
17
|
autoload :RejectedError, "#{__dir__}/lml/rejected_error"
|
|
18
|
+
autoload :ValueDeclarations, "#{__dir__}/lml/value_declarations"
|
|
9
19
|
autoload :RoundTrip, "#{__dir__}/lml/round_trip"
|
|
10
20
|
|
|
11
21
|
module_function
|
|
@@ -35,6 +45,57 @@ module Lutaml
|
|
|
35
45
|
def verify(document, register: nil)
|
|
36
46
|
RoundTrip.verify(document, register: register)
|
|
37
47
|
end
|
|
48
|
+
|
|
49
|
+
# Export the closed graph of models reachable from +roots+ as an
|
|
50
|
+
# immutable neutral Bundle of v2 documents keyed by "Model@register".
|
|
51
|
+
#
|
|
52
|
+
# @param roots [Class, Array<Class, Array(Class, String)>] classes,
|
|
53
|
+
# or [class, register] pairs
|
|
54
|
+
# @param register [Symbol, String, nil] default register for roots
|
|
55
|
+
# without one; nil resolves through the model's own default
|
|
56
|
+
# @param provenance [Hash, nil] recorded but excluded from the checksum
|
|
57
|
+
# @param value_declarations [ValueDeclarations, nil] trusted scalar declarations
|
|
58
|
+
# @return [Lml::Bundle]
|
|
59
|
+
def export_bundle(roots, register: nil, provenance: nil, value_declarations: nil)
|
|
60
|
+
GraphExporter.export(
|
|
61
|
+
roots,
|
|
62
|
+
projector: Exporter.graph_projector(value_declarations: value_declarations),
|
|
63
|
+
register: register, provenance: provenance, check_root_registers: true
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Write a model instance as `portable-exact-json-v1` text, the JSON
|
|
68
|
+
# profile the TS and Rust codecs read (integers, decimals and floats
|
|
69
|
+
# as strings). `to_json` keeps writing `ruby-native-v1`.
|
|
70
|
+
#
|
|
71
|
+
# @param instance [Lutaml::Model::Serializable]
|
|
72
|
+
# @param pretty [Boolean]
|
|
73
|
+
# @return [String]
|
|
74
|
+
# @raise [Lml::RejectedError] for a value or mapping with no portable
|
|
75
|
+
# spelling (NaN/Infinity, custom methods, unions, ...)
|
|
76
|
+
def portable_json(instance, pretty: false)
|
|
77
|
+
PortableJson.generate(instance, pretty: pretty)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Build fresh Ruby classes (attributes and xml/json/yaml mappings)
|
|
81
|
+
# from a bundle, without the source constants.
|
|
82
|
+
#
|
|
83
|
+
# @param bundle [Lml::Bundle, Hash, String] bundle, Hash or JSON text
|
|
84
|
+
# @param namespace [Module, nil] named holder for generated
|
|
85
|
+
# constants (required when the bundle declares polymorphism)
|
|
86
|
+
# @param type_bindings [Hash{String=>Class}] trusted value types
|
|
87
|
+
# @return [Hash{String=>Class}] model id => generated class
|
|
88
|
+
def import_bundle(bundle, namespace: nil, type_bindings: {})
|
|
89
|
+
Importer.import(bundle, namespace: namespace, type_bindings: type_bindings)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# The reconstruction gate: import the bundle, export the generated
|
|
93
|
+
# classes and require identical declarations and checksum.
|
|
94
|
+
# @return [Lml::Bundle] the re-exported bundle
|
|
95
|
+
# @raise [Lml::RejectedError] :round_trip_mismatch on drift
|
|
96
|
+
def verify_materialization(bundle, namespace: nil, type_bindings: {})
|
|
97
|
+
RoundTrip.verify_materialization(bundle, namespace: namespace, type_bindings: type_bindings)
|
|
98
|
+
end
|
|
38
99
|
end
|
|
39
100
|
end
|
|
40
101
|
end
|
|
@@ -8,12 +8,13 @@ module Lutaml
|
|
|
8
8
|
class Attribute
|
|
9
9
|
attr_accessor :name, :type, :xml_name, :kind, :collection,
|
|
10
10
|
:default, :documentation, :initialize_empty,
|
|
11
|
-
:render_default, :render_empty
|
|
11
|
+
:render_default, :render_empty, :required
|
|
12
12
|
|
|
13
13
|
def initialize(name:, type:, xml_name:, kind:,
|
|
14
14
|
collection: false, default: nil,
|
|
15
15
|
documentation: nil, initialize_empty: false,
|
|
16
|
-
render_default: false, render_empty: false
|
|
16
|
+
render_default: false, render_empty: false,
|
|
17
|
+
required: false)
|
|
17
18
|
@name = name
|
|
18
19
|
@type = type
|
|
19
20
|
@xml_name = xml_name
|
|
@@ -24,6 +25,7 @@ module Lutaml
|
|
|
24
25
|
@initialize_empty = initialize_empty
|
|
25
26
|
@render_default = render_default
|
|
26
27
|
@render_empty = render_empty
|
|
28
|
+
@required = required
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -75,7 +75,7 @@ module Lutaml
|
|
|
75
75
|
# in their `namespace ...` mapping declarations).
|
|
76
76
|
def autoload_declarations
|
|
77
77
|
indent = " " * module_depth
|
|
78
|
-
module_subdir = @module_namespace.split("::").
|
|
78
|
+
module_subdir = @module_namespace.split("::").map(&:downcase).join("/")
|
|
79
79
|
(@classes + @namespaces).map do |entry|
|
|
80
80
|
class_name = Utils.camel_case(entry.name)
|
|
81
81
|
file_name = Utils.snake_case(entry.name)
|
|
@@ -75,6 +75,7 @@ module Lutaml
|
|
|
75
75
|
opts << collection_option(attr.collection) if attr.collection
|
|
76
76
|
opts << "default: -> { #{attr.default.inspect} }" if attr.default
|
|
77
77
|
opts << "initialize_empty: true" if attr.initialize_empty
|
|
78
|
+
opts << "required: true" if attr.required
|
|
78
79
|
opts.empty? ? "" : ", #{opts.join(', ')}"
|
|
79
80
|
end
|
|
80
81
|
|
|
@@ -31,6 +31,7 @@ module Lutaml
|
|
|
31
31
|
xml_name: attr.name,
|
|
32
32
|
kind: :attribute,
|
|
33
33
|
default: attr.default,
|
|
34
|
+
required: attribute_required?(attr),
|
|
34
35
|
)
|
|
35
36
|
end
|
|
36
37
|
|
|
@@ -43,9 +44,17 @@ module Lutaml
|
|
|
43
44
|
type: build_type_ref(type_str || "string"),
|
|
44
45
|
xml_name: item.name.to_s,
|
|
45
46
|
kind: kind,
|
|
47
|
+
required: attribute_required?(item),
|
|
46
48
|
)
|
|
47
49
|
end
|
|
48
50
|
|
|
51
|
+
# An attribute a document must supply: `use="required"`. The
|
|
52
|
+
# default is optional, so only the explicit requirement binds.
|
|
53
|
+
def attribute_required?(attr)
|
|
54
|
+
attr.is_a?(Lutaml::Xml::Schema::Xsd::Attribute) &&
|
|
55
|
+
attr.use == "required"
|
|
56
|
+
end
|
|
57
|
+
|
|
49
58
|
# ----- Elements --------------------------------------------------
|
|
50
59
|
|
|
51
60
|
def build_element(element)
|
|
@@ -138,6 +147,7 @@ module Lutaml
|
|
|
138
147
|
xml_name: target.xml_name,
|
|
139
148
|
kind: :attribute,
|
|
140
149
|
default: target.default,
|
|
150
|
+
required: target.required || attribute_required?(attr),
|
|
141
151
|
)
|
|
142
152
|
end
|
|
143
153
|
|
|
@@ -162,10 +162,17 @@ choices, register = nil)
|
|
|
162
162
|
end
|
|
163
163
|
return eo_index + occurrences if occurrences&.positive?
|
|
164
164
|
return eo_index + 1 if element_order[eo_index] == element
|
|
165
|
+
return eo_index if optional_absent?(element_order, element, klass_attr)
|
|
165
166
|
|
|
166
167
|
raise_incorrect_sequence_error!(element, element_order[eo_index])
|
|
167
168
|
end
|
|
168
169
|
|
|
170
|
+
def optional_absent?(element_order, element, klass_attr)
|
|
171
|
+
return false if klass_attr.collection? || klass_attr.options[:required]
|
|
172
|
+
|
|
173
|
+
!element_order.include?(element)
|
|
174
|
+
end
|
|
175
|
+
|
|
169
176
|
def process_choice(element_order, eo_index, element, klass_attr, choices,
|
|
170
177
|
register = nil)
|
|
171
178
|
return eo_index if choices[klass_attr.choice] || element_order[eo_index] != element
|
|
@@ -116,15 +116,21 @@ module Lutaml
|
|
|
116
116
|
def from(format, data, options = {})
|
|
117
117
|
resolve_serialization_mapping_option(format, options)
|
|
118
118
|
|
|
119
|
-
if format == :xml && Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
120
|
-
fast = xml_plan_fast_path(data, options)
|
|
121
|
-
return fast if fast
|
|
122
|
-
end
|
|
123
|
-
|
|
124
119
|
# The rescue sits on the parse block, not the method, so cache
|
|
125
120
|
# store failures propagate instead of becoming InvalidFormatError.
|
|
121
|
+
#
|
|
122
|
+
# The XML plan fast path runs INSIDE the cache block and leaves it
|
|
123
|
+
# with `next`: ahead of the block it skipped the lookup, and a
|
|
124
|
+
# method-level `return` skips the store write after the yield —
|
|
125
|
+
# on the production leptris lane the conversion cache was never
|
|
126
|
+
# consulted in either direction.
|
|
126
127
|
with_conversion_cache(:from, format, data, options) do
|
|
127
128
|
Instrumentation.instrument(:from, model: name, format: format) do
|
|
129
|
+
if format == :xml && Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
130
|
+
fast = xml_plan_fast_path(data, options)
|
|
131
|
+
next fast if fast
|
|
132
|
+
end
|
|
133
|
+
|
|
128
134
|
adapter = resolve_adapter(format, options.delete(:adapter))
|
|
129
135
|
|
|
130
136
|
raise Lutaml::Model::FormatAdapterNotSpecifiedError.new(format) if adapter.nil?
|
|
@@ -164,7 +170,7 @@ module Lutaml
|
|
|
164
170
|
return nil unless defined?(::Leptris::XML::Document)
|
|
165
171
|
return nil if options.key?(:only) || options.key?(:except) ||
|
|
166
172
|
options.key?(:mappings) || options.key?(:adapter) ||
|
|
167
|
-
options.key?(:_adapter_override) ||
|
|
173
|
+
options.key?(:_adapter_override) || options.key?(:encoding) ||
|
|
168
174
|
options.key?(:indent) || options.key?(:xml_declaration) ||
|
|
169
175
|
options.key?(:declaration) || options.key?(:doctype) ||
|
|
170
176
|
# prefix requests ride the interpretive writer's use_prefix
|
|
@@ -188,7 +194,9 @@ module Lutaml
|
|
|
188
194
|
# (the #847 xmlns drop is fixed in PlanSerializer); any
|
|
189
195
|
# unspellable shape answers nil there and falls back
|
|
190
196
|
# interpretively.
|
|
191
|
-
Lutaml::Xml::Leptris::PlanSerializer.call(
|
|
197
|
+
Lutaml::Xml::Leptris::PlanSerializer.call(
|
|
198
|
+
instance, plan, nil, pretty: options[:pretty] ? true : false
|
|
199
|
+
)
|
|
192
200
|
end
|
|
193
201
|
|
|
194
202
|
# Whole-document native materialization (Phase 5): compile the
|
|
@@ -213,6 +221,11 @@ module Lutaml
|
|
|
213
221
|
return nil unless adapter&.engine_name == :leptris
|
|
214
222
|
|
|
215
223
|
register = extract_register_id(nil)
|
|
224
|
+
# A type-only model's own error (validate_document) precedes
|
|
225
|
+
# parsing on the interpretive path; the strict parse below
|
|
226
|
+
# would answer a format error first.
|
|
227
|
+
return nil unless root?(register)
|
|
228
|
+
|
|
216
229
|
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(self, register)
|
|
217
230
|
return nil unless plan
|
|
218
231
|
|
|
@@ -225,6 +238,7 @@ module Lutaml
|
|
|
225
238
|
root = ::Leptris::XML.parse(data.to_s, **leptris_strict_kwargs).root
|
|
226
239
|
return nil if root.nil?
|
|
227
240
|
return nil unless root.name == plan[:tree][:name]
|
|
241
|
+
return nil if Lutaml::Xml::Leptris::PlanHydrator.xsi_nil_below_root?(root)
|
|
228
242
|
|
|
229
243
|
Lutaml::Xml::Leptris::PlanHydrator.call(self, plan,
|
|
230
244
|
plan[:descriptor].walk(root),
|
|
@@ -378,7 +392,7 @@ module Lutaml
|
|
|
378
392
|
options[:_adapter_override] = true if adapter_override
|
|
379
393
|
if format == :xml && Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
380
394
|
fast = xml_plan_fast_serialize(instance, options)
|
|
381
|
-
|
|
395
|
+
next fast if fast
|
|
382
396
|
end
|
|
383
397
|
value = public_send(:"as_#{format}", instance, options)
|
|
384
398
|
adapter = resolve_adapter(format, adapter_override)
|
|
@@ -381,6 +381,8 @@ module Lutaml
|
|
|
381
381
|
# Clear centralized mapping and transformation caches
|
|
382
382
|
# (Single Source of Truth - no longer uses instance variables)
|
|
383
383
|
TransformationRegistry.instance.clear
|
|
384
|
+
Lutaml::Xml::Leptris::PlanCompiler.invalidate!(self) if
|
|
385
|
+
defined?(Lutaml::Xml::Leptris::PlanCompiler)
|
|
384
386
|
|
|
385
387
|
# Clear Transform cache (uses class identity as key)
|
|
386
388
|
Transform.invalidate_for(self, register_id)
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -37,6 +37,9 @@ module Lutaml
|
|
|
37
37
|
DEFERRED_ROW_KINDS = %i[raw ordered_deferred].freeze
|
|
38
38
|
PLANNED_ROW_KINDS = %i[nested ordered_deferred].freeze
|
|
39
39
|
NESTED_ROW_KINDS = %i[nested ordered_deferred].freeze
|
|
40
|
+
# Element rows whose text the DOM lane spells through a type's
|
|
41
|
+
# own to_xml hook.
|
|
42
|
+
TEXT_ROW_KINDS = %i[scalar collection_native collection_cb].freeze
|
|
40
43
|
NS_EMITTABLE_ROW_KINDS = %i[scalar collection nested
|
|
41
44
|
collection_native
|
|
42
45
|
ordered_deferred].freeze
|
|
@@ -60,6 +63,15 @@ module Lutaml
|
|
|
60
63
|
return false if namespaced_tree?(plan[:tree]) &&
|
|
61
64
|
!engine_ns_prefix_safe?
|
|
62
65
|
return false unless ordered_ns_emittable?(plan, instance)
|
|
66
|
+
# A prefixed-parsed root pins the root's prefix form (format
|
|
67
|
+
# preservation, priority 1), and the ops spelling inherits
|
|
68
|
+
# that prefix down the tree — including over rows the
|
|
69
|
+
# elementFormDefault contract spells :unqualified. The DOM
|
|
70
|
+
# lane spells those bare; the ops lane cannot, so a prefixed
|
|
71
|
+
# source carrying an unqualified element row stays off it.
|
|
72
|
+
return false if instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
73
|
+
prefixed_source?(instance) &&
|
|
74
|
+
unqualified_element_row?(plan[:tree])
|
|
63
75
|
return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
64
76
|
instance.element_order.nil?
|
|
65
77
|
# An UNORDERED instance (no parse-captured element_order)
|
|
@@ -80,6 +92,20 @@ module Lutaml
|
|
|
80
92
|
subtree_gate_ok?(plan, instance, register)
|
|
81
93
|
end
|
|
82
94
|
|
|
95
|
+
# Whether any named element row in the emission graph is spelled
|
|
96
|
+
# :unqualified — a child row, or one inside a nested plan.
|
|
97
|
+
def unqualified_element_row?(tree)
|
|
98
|
+
return false unless tree.is_a?(::Hash)
|
|
99
|
+
|
|
100
|
+
(tree[:children] || []).any? do |r|
|
|
101
|
+
next false unless NS_EMITTABLE_ROW_KINDS.include?(r[:kind])
|
|
102
|
+
next true if r[:ns] == :unqualified
|
|
103
|
+
|
|
104
|
+
r[:plan] && PLANNED_ROW_KINDS.include?(r[:kind]) &&
|
|
105
|
+
unqualified_element_row?(r[:plan])
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
83
109
|
# Whether the tree's EXACT-ns rows (tree, attribute rows,
|
|
84
110
|
# child rows, recursively through nested plans) carry more
|
|
85
111
|
# than one distinct namespace URI.
|
|
@@ -221,14 +247,37 @@ module Lutaml
|
|
|
221
247
|
gate_row_kind?(row, register)
|
|
222
248
|
end
|
|
223
249
|
return false if content_cdata?(plan)
|
|
250
|
+
# Element rows with cdata: true have no native text-op spelling
|
|
251
|
+
# (the engine walk emits plain text); the plan serializer mints
|
|
252
|
+
# the CDATA node for them.
|
|
253
|
+
return false if plan.dig(:tree, :flags)&.include?(:cdata)
|
|
224
254
|
|
|
225
255
|
if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize)
|
|
226
256
|
return false if instance.element_order.nil?
|
|
227
257
|
return false if instance.mutated_after_parse?
|
|
228
258
|
return false unless instance.element_order.all? do |o|
|
|
229
|
-
(o
|
|
230
|
-
(o.type == "
|
|
259
|
+
PlanSerializer.order_entry?(o) &&
|
|
260
|
+
((o.type == "Element") ||
|
|
261
|
+
(o.type == "Text" && o.node_type != :cdata))
|
|
231
262
|
end
|
|
263
|
+
|
|
264
|
+
# A pristine order can still leave a value unemitted —
|
|
265
|
+
# in-place collection growth never trips the mutation
|
|
266
|
+
# flag. Reconciliation is the DOM lane's; the gate pays
|
|
267
|
+
# the coverage pre-check the DOM walk would run.
|
|
268
|
+
ns_index = PlanSerializer.ns_index_for(plan)
|
|
269
|
+
rows_by_name, name_keys =
|
|
270
|
+
PlanSerializer.ordered_layout_for(plan, nil, ns_index, register)
|
|
271
|
+
return false if PlanSerializer.order_uncovered?(
|
|
272
|
+
instance, plan, rows_by_name, name_keys,
|
|
273
|
+
instance.element_order, register
|
|
274
|
+
)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Attribute values spelling through a type's own to_xml hook
|
|
278
|
+
# are written by the DOM lane's text path.
|
|
279
|
+
plan[:attr_rows].each do |(_rule, attr, _name)|
|
|
280
|
+
return false if PlanSerializer.custom_xml_type?(attr.type(register))
|
|
232
281
|
end
|
|
233
282
|
|
|
234
283
|
return true unless instance.is_a?(::Lutaml::Model::Serialize)
|
|
@@ -236,6 +285,21 @@ module Lutaml
|
|
|
236
285
|
plan[:rows].each do |(rule, attr, kind, _sp, delegate, _type)|
|
|
237
286
|
next unless rule.name
|
|
238
287
|
|
|
288
|
+
# A type hooking the XML format through its own to_xml is
|
|
289
|
+
# spelled by the DOM lane's own text path.
|
|
290
|
+
if TEXT_ROW_KINDS.include?(kind) &&
|
|
291
|
+
PlanSerializer.custom_xml_type?(attr.type(register))
|
|
292
|
+
return false
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# A nil/empty value rendering a policy leaf (xsi:nil,
|
|
296
|
+
# blank) has no ops spelling: the DOM lane mints it.
|
|
297
|
+
if PlanSerializer::PLACEHOLDER_KINDS.include?(kind)
|
|
298
|
+
value = value_of(instance, attr, delegate)
|
|
299
|
+
return false if PlanSerializer.render_value?(rule, value, instance) &&
|
|
300
|
+
PlanSerializer.placeholder_for(rule, value)
|
|
301
|
+
end
|
|
302
|
+
|
|
239
303
|
if kind == :child_deferred
|
|
240
304
|
# A VALUED cycle-point row keeps the DOM lane: the
|
|
241
305
|
# native ordered replay has no ops spelling for it —
|
|
@@ -250,10 +314,18 @@ module Lutaml
|
|
|
250
314
|
end
|
|
251
315
|
next unless NESTED_ROW_KINDS.include?(kind)
|
|
252
316
|
|
|
317
|
+
declared_type = _type || attr.type(register)
|
|
253
318
|
value = value_of(instance, attr, delegate)
|
|
254
319
|
Array(value).each do |item|
|
|
255
320
|
next unless item
|
|
256
321
|
|
|
322
|
+
# A value of another class than the row's declared type
|
|
323
|
+
# serializes through its own mapping (the interpretive
|
|
324
|
+
# dispatch on value.class); the emission graph is built
|
|
325
|
+
# from the declared type's plan — the DOM lane compiles
|
|
326
|
+
# the item's own.
|
|
327
|
+
return false unless item.instance_of?(declared_type)
|
|
328
|
+
|
|
257
329
|
# leptris#1966: the emit compiles the ITEM CLASS's
|
|
258
330
|
# plan (nested_plans[[item.class, name]]) — the gate
|
|
259
331
|
# must gate exactly what emit emits. Unknown classes
|
|
@@ -328,6 +400,13 @@ module Lutaml
|
|
|
328
400
|
# ops spelling matches it, inherited down the tree.
|
|
329
401
|
def ns_emittable?(ns_form, prefixed_source = nil)
|
|
330
402
|
return true if ns_form.nil? || ns_form == :unqualified
|
|
403
|
+
# A :blank row (a local element of a form-not-set parent —
|
|
404
|
+
# in no namespace) follows the enclosing namespace's format:
|
|
405
|
+
# under a prefix-preserved root the ops spelling inherits
|
|
406
|
+
# the prefix, like the DOM lane; under the default-namespace
|
|
407
|
+
# one it must opt out with xmlns="" — the DOM lane's.
|
|
408
|
+
return prefixed_source ? true : false if ns_form == :blank
|
|
409
|
+
|
|
331
410
|
return false unless ns_form.is_a?(Hash) && ns_form[:prefix] &&
|
|
332
411
|
!ns_form[:prefix].empty?
|
|
333
412
|
|
|
@@ -477,7 +556,10 @@ module Lutaml
|
|
|
477
556
|
next
|
|
478
557
|
end
|
|
479
558
|
name = rule.name ? rule.name.to_s : ""
|
|
480
|
-
|
|
559
|
+
# :blank has no row form: the ops spelling inherits the
|
|
560
|
+
# plan's, exactly as a form-less row did.
|
|
561
|
+
form = ns_index[name]
|
|
562
|
+
ns = form.nil? || form == :blank ? {} : { ns: form }
|
|
481
563
|
case kind
|
|
482
564
|
when :scalar
|
|
483
565
|
out << { name: name, kind: :scalar, **ns }
|