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.
- checksums.yaml +4 -4
- data/.github/scripts/test_installed_gem.rb +1 -13
- data/.github/workflows/dependent-tests.yml +59 -2
- data/.github/workflows/downstream-performance.yml +1 -22
- data/.github/workflows/performance.yml +1 -33
- data/.github/workflows/rake.yml +2 -6
- data/.rubocop.yml +0 -10
- data/.rubocop_todo.yml +0 -4
- data/Gemfile +0 -23
- data/README.adoc +25 -86
- data/Rakefile +2 -167
- data/docs/_guides/advanced-mapping.adoc +6 -6
- data/docs/_guides/character-encoding.adoc +0 -3
- data/docs/_guides/gem-integration.adoc +1 -1
- data/docs/_guides/index.adoc +0 -4
- data/docs/_guides/xml/type-namespaces.adoc +1 -1
- data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
- data/docs/_guides/xml-namespaces.adoc +2 -3
- data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
- data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
- data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
- data/docs/_pages/comparison-with-shale.adoc +1 -1
- data/docs/_pages/configuration.adoc +6 -40
- data/docs/_pages/index.adoc +0 -1
- data/docs/_pages/serialization_adapters.adoc +4 -16
- data/docs/_references/architecture.adoc +1 -1
- data/docs/_references/lutaml-namespace-planning.md +1 -1
- data/docs/_references/plan-schema-spec.adoc +45 -18
- data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
- data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
- data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
- data/docs/architecture.md +7 -11
- data/docs/conversion_caching.adoc +1 -1
- data/docs/index.adoc +0 -1
- data/docs/key_value_data_model.adoc +1 -1
- data/docs/namespace-management.adoc +4 -10
- data/lib/lutaml/json/format.rb +0 -1
- data/lib/lutaml/json/generator_options.rb +0 -1
- data/lib/lutaml/key_value/transform.rb +149 -37
- data/lib/lutaml/lml/document_builder.rb +2 -2
- data/lib/lutaml/lml/entity_types.rb +2 -2
- data/lib/lutaml/model/adapter_resolver.rb +5 -15
- data/lib/lutaml/model/attribute.rb +11 -6
- data/lib/lutaml/model/cached_type_resolver.rb +1 -7
- data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
- data/lib/lutaml/model/global_context.rb +3 -5
- data/lib/lutaml/model/instrumentation.rb +0 -3
- data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
- data/lib/lutaml/model/register.rb +20 -31
- data/lib/lutaml/model/runtime_compatibility.rb +0 -92
- data/lib/lutaml/model/schema/class_loader.rb +2 -4
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
- data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
- data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
- data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
- data/lib/lutaml/model/serialize/initialization.rb +19 -9
- data/lib/lutaml/model/serialize/model_import.rb +0 -5
- data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
- data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
- data/lib/lutaml/model/store.rb +10 -17
- data/lib/lutaml/model/toml.rb +0 -2
- data/lib/lutaml/model/transformation_registry.rb +3 -7
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model.rb +3 -19
- data/lib/lutaml/toml/format.rb +4 -8
- data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
- data/lib/lutaml/xml/adapter.rb +0 -4
- data/lib/lutaml/xml/adapter_loader.rb +1 -6
- data/lib/lutaml/xml/builder/base.rb +0 -3
- data/lib/lutaml/xml/builder.rb +0 -8
- data/lib/lutaml/xml/data_model.rb +1 -1
- data/lib/lutaml/xml/doctype_extractor.rb +3 -3
- data/lib/lutaml/xml/format.rb +22 -74
- data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
- data/lib/lutaml/xml/model_transform.rb +14 -24
- data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
- data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
- data/lib/lutaml/xml/schema/builder.rb +6 -9
- data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
- data/lib/lutaml/xml/xml_element.rb +3 -2
- data/lib/lutaml/xml/xsd_validator.rb +4 -11
- data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
- data/lib/lutaml/yamls/adapter_loader.rb +1 -5
- data/lib/tasks/performance_comparator.rb +1 -1
- data/lutaml-model.gemspec +3 -8
- data/spec/address_person_spec.rb +8 -0
- data/spec/address_spec.rb +4 -0
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
- data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
- data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
- data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
- data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
- data/spec/lutaml/model/cdata_spec.rb +2 -15
- data/spec/lutaml/model/encoding_spec.rb +0 -9
- data/spec/lutaml/model/except_spec.rb +0 -7
- data/spec/lutaml/model/json_spec.rb +0 -14
- data/spec/lutaml/model/mixed_content_spec.rb +6 -46
- data/spec/lutaml/model/ordered_content_spec.rb +0 -7
- data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
- data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
- data/spec/lutaml/model/serializable_spec.rb +0 -2
- data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
- data/spec/lutaml/model/toml_spec.rb +0 -23
- data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
- data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
- data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
- data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
- data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
- data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
- data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
- data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
- data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
- data/spec/lutaml/xml/mapping_spec.rb +8 -15
- data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
- data/spec/lutaml/xml/namespace_spec.rb +0 -13
- data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
- data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
- data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
- data/spec/lutaml/xml/xml_spec.rb +2 -88
- data/spec/spec_helper.rb +8 -28
- data/spec/support/test_adapter_config.rb +6 -6
- metadata +2 -32
- data/.github/workflows/js-pr-check.yml +0 -106
- data/.github/workflows/js-sync.yml +0 -55
- data/.github/workflows/opal.yml +0 -65
- data/.gitmodules +0 -6
- data/.rspec-opal +0 -5
- data/docs/_guides/opal.adoc +0 -232
- data/lib/compat/opal/generate_boot.rb +0 -137
- data/lib/compat/opal/js_bundle_entry.rb +0 -42
- data/lib/compat/opal/lutaml_model_boot.rb +0 -638
- data/lib/compat/opal/monitor.rb +0 -31
- data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
- data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
- data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
- data/lib/compat/opal/moxml_boot.rb +0 -68
- data/lib/compat/opal/objectspace_shim.rb +0 -23
- data/lib/compat/opal/rexml/namespace.rb +0 -59
- data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
- data/lib/compat/opal/rexml/source.rb +0 -214
- data/lib/compat/opal/rexml/text.rb +0 -426
- data/lib/compat/opal/rexml/xmltokens.rb +0 -45
- data/lib/compat/opal/rexml_compat.rb +0 -85
- data/lib/compat/opal/yaml_compat.rb +0 -32
- data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
- data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
- data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
- data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
- data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
- data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
- data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
- data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
- data/spec/support/opal.rb +0 -9
data/lib/lutaml/model/store.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
|
|
3
|
+
# The index holds WeakRef entries, so the instances they point at go
|
|
4
|
+
# out of scope with the GC rather than with the store.
|
|
5
|
+
require "weakref"
|
|
5
6
|
|
|
6
7
|
module Lutaml
|
|
7
8
|
module Model
|
|
@@ -15,18 +16,12 @@ module Lutaml
|
|
|
15
16
|
# cumulatively for the class).
|
|
16
17
|
COMPACTION_INTERVAL = 1000
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# allocation per insert and no per-object finalizer — the WeakRef
|
|
25
|
-
# approach allocated one finalizer-registering object per
|
|
26
|
-
# instance (lutaml-model#695) and dominated GC cycles on
|
|
27
|
-
# instance-heavy parses.
|
|
28
|
-
::ObjectSpace::WeakMap
|
|
29
|
-
end
|
|
19
|
+
# WeakMap holds keys weakly with zero Ruby-level allocation per
|
|
20
|
+
# insert and no per-object finalizer — the WeakRef approach
|
|
21
|
+
# allocated one finalizer-registering object per instance
|
|
22
|
+
# (lutaml-model#695) and dominated GC cycles on instance-heavy
|
|
23
|
+
# parses.
|
|
24
|
+
WeakBucket = ::ObjectSpace::WeakMap
|
|
30
25
|
|
|
31
26
|
class << self
|
|
32
27
|
def instance
|
|
@@ -210,9 +205,7 @@ module Lutaml
|
|
|
210
205
|
|
|
211
206
|
def live_objects_for(bucket)
|
|
212
207
|
# WeakMap#each_key requires a block on CRuby; WeakMap#each
|
|
213
|
-
# yields key/value pairs
|
|
214
|
-
# way (value is `true` for WeakMap, the object for the Opal
|
|
215
|
-
# fallback keyed by object identity).
|
|
208
|
+
# yields key/value pairs (value is `true` for WeakMap).
|
|
216
209
|
bucket.map { |key, _value| key }
|
|
217
210
|
end
|
|
218
211
|
|
data/lib/lutaml/model/toml.rb
CHANGED
|
@@ -17,8 +17,6 @@ module Lutaml
|
|
|
17
17
|
Transform = ::Lutaml::Toml::Adapter::Transform
|
|
18
18
|
|
|
19
19
|
def self.detect_toml_adapter
|
|
20
|
-
return nil if Lutaml::Model.opal?
|
|
21
|
-
|
|
22
20
|
# teptris 0.2.12+ parses ~3x and dumps ~8x faster than tomlib
|
|
23
21
|
# and ships prebuilts for every platform (mingw-ucrt restored
|
|
24
22
|
# in 0.2.4+) — native TOML on Windows retires the tomlib
|
|
@@ -94,11 +94,7 @@ module Lutaml
|
|
|
94
94
|
# add minutes to process boot
|
|
95
95
|
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
96
96
|
@transformations = {} # Cache for transformation instances (mutex-protected for cycle detection)
|
|
97
|
-
@mappings =
|
|
98
|
-
{}
|
|
99
|
-
else
|
|
100
|
-
Concurrent::Map.new
|
|
101
|
-
end
|
|
97
|
+
@mappings = Concurrent::Map.new
|
|
102
98
|
@mutex = Mutex.new
|
|
103
99
|
@building_threads = {} # Track which thread is building each transformation
|
|
104
100
|
@condition = ConditionVariable.new
|
|
@@ -199,10 +195,10 @@ module Lutaml
|
|
|
199
195
|
end
|
|
200
196
|
|
|
201
197
|
# Inner cache level container matching the outer map's engine
|
|
202
|
-
# (Concurrent::Map under GVL-threaded MRI
|
|
198
|
+
# (Concurrent::Map under GVL-threaded MRI).
|
|
203
199
|
def new_inner_map
|
|
204
200
|
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
205
|
-
|
|
201
|
+
::Concurrent::Map.new
|
|
206
202
|
end
|
|
207
203
|
|
|
208
204
|
# Clear all cached data (transformations and mappings).
|
data/lib/lutaml/model/version.rb
CHANGED
data/lib/lutaml/model.rb
CHANGED
|
@@ -263,18 +263,9 @@ module Lutaml
|
|
|
263
263
|
@configuration = nil
|
|
264
264
|
end
|
|
265
265
|
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
# instead of the long `Lutaml::Model::RuntimeCompatibility.opal?`.
|
|
270
|
-
def self.opal?
|
|
271
|
-
RuntimeCompatibility.opal?
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def self.native?
|
|
275
|
-
RuntimeCompatibility.native?
|
|
276
|
-
end
|
|
277
|
-
|
|
266
|
+
# Platform detection, delegated to RuntimeCompatibility so call sites
|
|
267
|
+
# can write `Lutaml::Model.windows?` (or `Model.windows?` inside the
|
|
268
|
+
# namespace).
|
|
278
269
|
def self.windows?
|
|
279
270
|
RuntimeCompatibility.windows?
|
|
280
271
|
end
|
|
@@ -300,10 +291,3 @@ require "#{__dir__}/xml/format"
|
|
|
300
291
|
# Builder must be prepended AFTER XML so its initialize runs first
|
|
301
292
|
# (Builder -> XML InstanceMethods -> Serialize)
|
|
302
293
|
Lutaml::Model::Serialize.prepend(Lutaml::Model::Serialize::Builder)
|
|
303
|
-
|
|
304
|
-
# Opal does not propagate a module prepended into an already-included
|
|
305
|
-
# module to classes that included it earlier (see lib/lutaml/xml/format.rb).
|
|
306
|
-
# Serializable included Serialize at boot, so Builder goes onto it directly.
|
|
307
|
-
if Lutaml::Model.opal?
|
|
308
|
-
Lutaml::Model::Serializable.prepend(Lutaml::Model::Serialize::Builder)
|
|
309
|
-
end
|
data/lib/lutaml/toml/format.rb
CHANGED
|
@@ -31,14 +31,10 @@ Lutaml::Model::FormatRegistry.register(
|
|
|
31
31
|
adapter_class: nil,
|
|
32
32
|
transformer: Lutaml::Toml::Adapter::Transform,
|
|
33
33
|
key_value: true,
|
|
34
|
-
adapter_options:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
available: %i[teptris tomlib toml_rb],
|
|
39
|
-
default: Lutaml::Model::RuntimeCompatibility.windows? ? :toml_rb : :tomlib,
|
|
40
|
-
}
|
|
41
|
-
end,
|
|
34
|
+
adapter_options: {
|
|
35
|
+
available: %i[teptris tomlib toml_rb],
|
|
36
|
+
default: Lutaml::Model::RuntimeCompatibility.windows? ? :toml_rb : :tomlib,
|
|
37
|
+
},
|
|
42
38
|
)
|
|
43
39
|
|
|
44
40
|
require_relative "type/serializers"
|
|
@@ -26,8 +26,7 @@ module Lutaml
|
|
|
26
26
|
class MoxmlAdapter < BaseAdapter
|
|
27
27
|
class << self
|
|
28
28
|
# Engine registry: the lazy requires keep this file free of
|
|
29
|
-
#
|
|
30
|
-
# requires this file unconditionally). `parse_error` is the
|
|
29
|
+
# engine-only dependencies at load time. `parse_error` is the
|
|
31
30
|
# engine error class the parse boundary rescues into a
|
|
32
31
|
# format error (nil = ride moxml's own error surface); the
|
|
33
32
|
# rexml entry carries the historical empty-document error
|
|
@@ -43,11 +42,6 @@ module Lutaml
|
|
|
43
42
|
moxml_adapter: "Moxml::Adapter::Leptris",
|
|
44
43
|
parse_error: "Moxml::ParseError",
|
|
45
44
|
},
|
|
46
|
-
oga: {
|
|
47
|
-
requires: ["oga", "moxml/adapter/oga"],
|
|
48
|
-
moxml_adapter: "Moxml::Adapter::Oga",
|
|
49
|
-
parse_error: nil,
|
|
50
|
-
},
|
|
51
45
|
ox: {
|
|
52
46
|
requires: ["moxml/adapter/ox"],
|
|
53
47
|
moxml_adapter: "Moxml::Adapter::Ox",
|
data/lib/lutaml/xml/adapter.rb
CHANGED
|
@@ -12,10 +12,6 @@ module Lutaml
|
|
|
12
12
|
autoload :PlanBasedBuilder, "#{__dir__}/adapter/plan_based_builder"
|
|
13
13
|
autoload :NamespaceUriCollector,
|
|
14
14
|
"#{__dir__}/adapter/namespace_uri_collector"
|
|
15
|
-
# Plain autoload (in addition to the native table): the Opal boot
|
|
16
|
-
# generator harvests `autoload :Name, "path"` declarations only,
|
|
17
|
-
# so the facade must appear here to ride the sequential boot.
|
|
18
|
-
autoload :MoxmlAdapter, "#{__dir__}/adapter/moxml_adapter"
|
|
19
15
|
Lutaml::Model::RuntimeCompatibility.autoload_native(
|
|
20
16
|
self,
|
|
21
17
|
MoxmlAdapter: "#{__dir__}/adapter/moxml_adapter",
|
|
@@ -20,12 +20,7 @@ module Lutaml
|
|
|
20
20
|
# "nokogiri_adapter") — informational; all types share the
|
|
21
21
|
# one adapter file
|
|
22
22
|
def self.load_adapter_file(_adapter, _type)
|
|
23
|
-
adapter_path =
|
|
24
|
-
"lutaml/xml/adapter/#{ADAPTER_FILE}"
|
|
25
|
-
else
|
|
26
|
-
File.join(File.dirname(__FILE__), "adapter",
|
|
27
|
-
ADAPTER_FILE)
|
|
28
|
-
end
|
|
23
|
+
adapter_path = File.join(File.dirname(__FILE__), "adapter", ADAPTER_FILE)
|
|
29
24
|
require adapter_path
|
|
30
25
|
rescue LoadError => e
|
|
31
26
|
raise Lutaml::Model::UnknownAdapterTypeError.new("xml", ADAPTER_FILE),
|
|
@@ -18,9 +18,6 @@ module Lutaml
|
|
|
18
18
|
def self.build(options = {})
|
|
19
19
|
engine = options.delete(:engine) || Lutaml::Xml.moxml_engine
|
|
20
20
|
context = Moxml.new(engine)
|
|
21
|
-
if Lutaml::Model.opal?
|
|
22
|
-
context.config.namespace_validation_mode = :lenient
|
|
23
|
-
end
|
|
24
21
|
|
|
25
22
|
encoding_value = options.delete(:encoding)
|
|
26
23
|
context.config.default_indent = options.delete(:indent) if options.key?(:indent)
|
data/lib/lutaml/xml/builder.rb
CHANGED
|
@@ -5,14 +5,6 @@ module Lutaml
|
|
|
5
5
|
# Builder module for XML generation
|
|
6
6
|
module Builder
|
|
7
7
|
autoload :Base, "#{__dir__}/builder/base"
|
|
8
|
-
autoload :Oga, "#{__dir__}/builder/oga"
|
|
9
|
-
autoload :Rexml, "#{__dir__}/builder/rexml"
|
|
10
|
-
Lutaml::Model::RuntimeCompatibility.autoload_native(
|
|
11
|
-
self,
|
|
12
|
-
Nokogiri: "#{__dir__}/builder/nokogiri",
|
|
13
|
-
Ox: "#{__dir__}/builder/ox",
|
|
14
|
-
Leptris: "#{__dir__}/builder/leptris",
|
|
15
|
-
)
|
|
16
8
|
end
|
|
17
9
|
end
|
|
18
10
|
end
|
|
@@ -6,7 +6,7 @@ module Lutaml
|
|
|
6
6
|
#
|
|
7
7
|
# These classes represent XML structure without serialization logic,
|
|
8
8
|
# allowing transformation to produce XML data that can be serialized
|
|
9
|
-
# by different adapters (Nokogiri, Ox
|
|
9
|
+
# by different adapters (Nokogiri, Ox).
|
|
10
10
|
module DataModel
|
|
11
11
|
# Represents an XML element with namespace, attributes, and children.
|
|
12
12
|
class XmlElement
|
|
@@ -6,13 +6,13 @@ module Lutaml
|
|
|
6
6
|
#
|
|
7
7
|
# This module provides a shared method to extract DOCTYPE declarations
|
|
8
8
|
# from raw XML strings when the XML library doesn't directly expose this
|
|
9
|
-
# information (as is the case with Moxml
|
|
9
|
+
# information (as is the case with Moxml and Ox).
|
|
10
10
|
#
|
|
11
11
|
# Nokogiri provides native access to DOCTYPE via `parsed.internal_subset`,
|
|
12
12
|
# so it doesn't need this extraction method.
|
|
13
13
|
#
|
|
14
|
-
# This logic is
|
|
15
|
-
#
|
|
14
|
+
# This logic is shared by the Ox path and has been extracted here
|
|
15
|
+
# to maintain DRY principles.
|
|
16
16
|
module DocTypeExtractor
|
|
17
17
|
# Extract DOCTYPE information from raw XML string
|
|
18
18
|
#
|
data/lib/lutaml/xml/format.rb
CHANGED
|
@@ -10,15 +10,6 @@
|
|
|
10
10
|
# XML requires moxml for parsing
|
|
11
11
|
require "moxml"
|
|
12
12
|
|
|
13
|
-
# Under Opal, moxml's autoloads don't fire (Opal ignores autoload).
|
|
14
|
-
# Pull in the eager-load boot that ships at lib/compat/opal/moxml_boot.rb
|
|
15
|
-
# so Moxml::Adapter::{Oga,Rexml} etc. are actually defined. Without
|
|
16
|
-
# this, `Config.adapter = :oga` later fails with
|
|
17
|
-
# `NameError: uninitialized constant Moxml::Adapter::Oga`.
|
|
18
|
-
if Lutaml::Model.opal?
|
|
19
|
-
require "moxml_boot"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
13
|
module Lutaml
|
|
23
14
|
module Xml
|
|
24
15
|
autoload :HtmlEntities, "#{__dir__}/html_entities"
|
|
@@ -195,32 +186,20 @@ Lutaml::Model::FormatRegistry.register(
|
|
|
195
186
|
Ox::ParseError
|
|
196
187
|
REXML::ParseException
|
|
197
188
|
],
|
|
198
|
-
adapter_options:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# explicit configuration and moxml runtime detection
|
|
213
|
-
# answer first. When resolution falls this far, prefer
|
|
214
|
-
# leptris, consistent with moxml's runtime preference
|
|
215
|
-
# (leptris whenever present); bundles without it
|
|
216
|
-
# resolve through auto-detection long before here.
|
|
217
|
-
# #1224: the metadata default is the DEFERRED lane -
|
|
218
|
-
# resolution defers the engine to moxml at parse
|
|
219
|
-
# time (the facade lane), so a consumer selecting the
|
|
220
|
-
# default never hard-codes an engine name.
|
|
221
|
-
default: :moxml,
|
|
222
|
-
}
|
|
223
|
-
end,
|
|
189
|
+
adapter_options: {
|
|
190
|
+
available: %i[nokogiri ox rexml leptris moxml],
|
|
191
|
+
# #908: the metadata default is the LAST resort —
|
|
192
|
+
# explicit configuration and moxml runtime detection
|
|
193
|
+
# answer first. When resolution falls this far, prefer
|
|
194
|
+
# leptris, consistent with moxml's runtime preference
|
|
195
|
+
# (leptris whenever present); bundles without it
|
|
196
|
+
# resolve through auto-detection long before here.
|
|
197
|
+
# #1224: the metadata default is the DEFERRED lane -
|
|
198
|
+
# resolution defers the engine to moxml at parse
|
|
199
|
+
# time (the facade lane), so a consumer selecting the
|
|
200
|
+
# default never hard-codes an engine name.
|
|
201
|
+
default: :moxml,
|
|
202
|
+
},
|
|
224
203
|
)
|
|
225
204
|
|
|
226
205
|
# Register XML transformation builder
|
|
@@ -248,18 +227,18 @@ Lutaml::Model::Serialize.prepend(
|
|
|
248
227
|
Lutaml::Xml::Serialization::InstanceMethods,
|
|
249
228
|
)
|
|
250
229
|
|
|
251
|
-
#
|
|
252
|
-
# to classes that included it before the prepend. Serializable
|
|
253
|
-
# Serialize during model boot, so
|
|
254
|
-
# concrete base class as well.
|
|
230
|
+
# TruffleRuby does not propagate methods prepended into an already-included
|
|
231
|
+
# module to classes that included it before the prepend. Serializable
|
|
232
|
+
# includes Serialize during model boot, so the XML instance API is made
|
|
233
|
+
# available on the concrete base class as well.
|
|
255
234
|
#
|
|
256
235
|
# Anonymous model classes (Class.new { include Serialize }) extend
|
|
257
236
|
# Serialize::ClassMethods rather than inheriting from Serializable, so the
|
|
258
237
|
# ModelImportExt override (root?) must land on ClassMethods too.
|
|
259
238
|
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
239
|
+
# The ClassMethods.prepend(FormatConversion) above does not reach
|
|
240
|
+
# Serializable's singleton chain, which extended ClassMethods before it
|
|
241
|
+
# ran, so it is prepended onto that singleton directly.
|
|
263
242
|
#
|
|
264
243
|
# TruffleRuby (34.0.1) has the same propagation gap, on both the include
|
|
265
244
|
# side and the extend/singleton side — a module prepended into an
|
|
@@ -274,7 +253,7 @@ Lutaml::Model::Serialize.prepend(
|
|
|
274
253
|
# mixed, doctype, xml_declaration, raw_schema_location), so
|
|
275
254
|
# ModelTransform#apply_xml_mapping dies at `instance.encoding = ...` —
|
|
276
255
|
# e.g. every relaton ItemData parse via Relaton::Cli.parse_xml.
|
|
277
|
-
if
|
|
256
|
+
if RUBY_ENGINE == "truffleruby"
|
|
278
257
|
Lutaml::Model::Serializable.singleton_class.prepend(
|
|
279
258
|
Lutaml::Xml::Serialization::ModelImportExt,
|
|
280
259
|
)
|
|
@@ -308,30 +287,14 @@ Lutaml::Xml::Type::Serializers.register_all!
|
|
|
308
287
|
|
|
309
288
|
# Register XML schema methods
|
|
310
289
|
Lutaml::Model::Schema.register_method(:to_xsd) do |klass, options = {}|
|
|
311
|
-
if Lutaml::Model.opal?
|
|
312
|
-
raise NotImplementedError,
|
|
313
|
-
"XSD schema generation is not available under Opal."
|
|
314
|
-
end
|
|
315
|
-
|
|
316
290
|
Lutaml::Xml::Schema::XsdSchema.generate(klass, options)
|
|
317
291
|
end
|
|
318
292
|
|
|
319
293
|
Lutaml::Model::Schema.register_method(:to_relaxng) do |klass, options = {}|
|
|
320
|
-
if Lutaml::Model.opal?
|
|
321
|
-
raise NotImplementedError,
|
|
322
|
-
"RELAX NG schema generation requires Nokogiri, " \
|
|
323
|
-
"which is not available under Opal."
|
|
324
|
-
end
|
|
325
|
-
|
|
326
294
|
Lutaml::Xml::Schema::RelaxngSchema.generate(klass, options)
|
|
327
295
|
end
|
|
328
296
|
|
|
329
297
|
Lutaml::Model::Schema.register_method(:from_xml) do |xml, options = {}|
|
|
330
|
-
if Lutaml::Model.opal?
|
|
331
|
-
raise NotImplementedError,
|
|
332
|
-
"XML schema compilation is not available under Opal."
|
|
333
|
-
end
|
|
334
|
-
|
|
335
298
|
Lutaml::Model::Schema::XmlCompiler.to_models(xml, options)
|
|
336
299
|
end
|
|
337
300
|
|
|
@@ -341,31 +304,16 @@ end
|
|
|
341
304
|
# it; see #1204). Rides Xsd.parse so the metaschema registration
|
|
342
305
|
# preamble runs before the parse resolves attribute types.
|
|
343
306
|
Lutaml::Model::Schema.register_method(:target_namespace) do |xml|
|
|
344
|
-
if Lutaml::Model.opal?
|
|
345
|
-
raise NotImplementedError,
|
|
346
|
-
"XML schema compilation is not available under Opal."
|
|
347
|
-
end
|
|
348
|
-
|
|
349
307
|
parsed = Lutaml::Xml::Schema::Xsd.parse(xml, validate_schema: false)
|
|
350
308
|
schema = parsed.is_a?(Array) ? parsed.first : parsed
|
|
351
309
|
schema&.target_namespace
|
|
352
310
|
end
|
|
353
311
|
|
|
354
312
|
Lutaml::Model::Schema.register_method(:from_relaxng) do |rng, options = {}|
|
|
355
|
-
if Lutaml::Model::RuntimeCompatibility.opal?
|
|
356
|
-
raise NotImplementedError,
|
|
357
|
-
"RELAX NG schema compilation is not available under Opal."
|
|
358
|
-
end
|
|
359
|
-
|
|
360
313
|
Lutaml::Model::Schema::RngCompiler.to_models(rng, options)
|
|
361
314
|
end
|
|
362
315
|
|
|
363
316
|
Lutaml::Model::Schema.register_method(:from_rnc) do |rnc, options = {}|
|
|
364
|
-
if Lutaml::Model::RuntimeCompatibility.opal?
|
|
365
|
-
raise NotImplementedError,
|
|
366
|
-
"RNC schema compilation is not available under Opal."
|
|
367
|
-
end
|
|
368
|
-
|
|
369
317
|
Lutaml::Model::Schema::RncCompiler.to_models(rnc, options)
|
|
370
318
|
end
|
|
371
319
|
|
|
@@ -388,8 +388,7 @@ module Lutaml
|
|
|
388
388
|
# on the theme docx). The tree is complete here; freeze
|
|
389
389
|
# now.
|
|
390
390
|
begin
|
|
391
|
-
# Lazy: the
|
|
392
|
-
# native gem there — the require only belongs on the
|
|
391
|
+
# Lazy: the leptris require only belongs on the
|
|
393
392
|
# engines-enabled path.
|
|
394
393
|
require "leptris/xml/descriptor"
|
|
395
394
|
descriptor = ::Leptris::XML::Descriptor.build(**tree)
|
|
@@ -16,40 +16,31 @@ module Lutaml
|
|
|
16
16
|
# rules — attribute, derived/valid flags, and #765 group-skip —
|
|
17
17
|
# keyed on the mapping's finalize version so late changes rebuild.
|
|
18
18
|
# The loop body used to re-derive these per parsed instance.
|
|
19
|
-
# Concurrent::Map
|
|
20
|
-
# (Concurrent is unavailable there); class identity keys either.
|
|
19
|
+
# Concurrent::Map; class identity keys.
|
|
21
20
|
# Concurrent is required here (not at boot) so its first load never
|
|
22
21
|
# happens inside RubyGems' unresolved-tree resolution (see
|
|
23
22
|
# TransformationRegistry#initialize).
|
|
24
|
-
RULE_RECORDS =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.require_native("concurrent")
|
|
29
|
-
Concurrent::Map.new # rubocop:disable Lint/HashCompareByIdentity
|
|
30
|
-
end
|
|
23
|
+
RULE_RECORDS = begin
|
|
24
|
+
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
25
|
+
Concurrent::Map.new # rubocop:disable Lint/HashCompareByIdentity
|
|
26
|
+
end
|
|
31
27
|
|
|
32
28
|
# Namespaced rule name -> [local_name, rule_uri]. Pure string
|
|
33
29
|
# splitting, deterministic per spelling, shared across parses.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
39
|
-
Concurrent::Map.new
|
|
40
|
-
end
|
|
30
|
+
NAMESPACED_NAME_PARTS = begin
|
|
31
|
+
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
32
|
+
Concurrent::Map.new
|
|
33
|
+
end
|
|
41
34
|
|
|
42
35
|
# Rule name -> its local suffix after the last colon. The
|
|
43
36
|
# cross-namespace fallback probes this suffix per rule name per
|
|
44
37
|
# child per element (11M substring mints on a 2M-node parse);
|
|
45
38
|
# the suffix is static per spelling, so it is shared here with
|
|
46
39
|
# the same backing as NAMESPACED_NAME_PARTS.
|
|
47
|
-
RULE_LOCAL_NAMES =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
Concurrent::Map.new
|
|
52
|
-
end
|
|
40
|
+
RULE_LOCAL_NAMES = begin
|
|
41
|
+
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
42
|
+
Concurrent::Map.new
|
|
43
|
+
end
|
|
53
44
|
include NestedCollectionAttribute
|
|
54
45
|
|
|
55
46
|
# Performance: Frozen empty hash to reduce allocations
|
|
@@ -955,7 +946,6 @@ _effective_register)
|
|
|
955
946
|
def decode_html_entities_value(value, enabled)
|
|
956
947
|
return value if value.nil? || !value.is_a?(String)
|
|
957
948
|
return value unless enabled
|
|
958
|
-
return value if Lutaml::Model.opal?
|
|
959
949
|
|
|
960
950
|
Lutaml::Xml::HtmlEntities.decode(value)
|
|
961
951
|
end
|
|
@@ -971,7 +961,7 @@ _effective_register)
|
|
|
971
961
|
version = mapping&.rule_records_version.to_i
|
|
972
962
|
per_class = RULE_RECORDS[model_class.object_id] # rubocop:disable Lint/HashCompareByIdentity
|
|
973
963
|
unless per_class
|
|
974
|
-
per_class =
|
|
964
|
+
per_class = Concurrent::Map.new
|
|
975
965
|
RULE_RECORDS[model_class.object_id] = per_class # rubocop:disable Lint/HashCompareByIdentity
|
|
976
966
|
end
|
|
977
967
|
cached = per_class[register]
|
|
@@ -13,7 +13,7 @@ module Lutaml
|
|
|
13
13
|
# `polymorphic_class: true`, indicating it's part of a polymorphic
|
|
14
14
|
# inheritance tree
|
|
15
15
|
#
|
|
16
|
-
# This logic is identical across all XML adapters (Nokogiri,
|
|
16
|
+
# This logic is identical across all XML adapters (Nokogiri, Ox)
|
|
17
17
|
# and has been extracted here to maintain DRY principles.
|
|
18
18
|
module PolymorphicValueHandler
|
|
19
19
|
# Determine if a value should be treated as polymorphic
|
|
@@ -13,7 +13,7 @@ module Lutaml
|
|
|
13
13
|
# Moxml (the closed #1183 leak).
|
|
14
14
|
#
|
|
15
15
|
# The block receives the Moxml::Builder and drives it with
|
|
16
|
-
# the same method_missing tag DSL the Nokogiri
|
|
16
|
+
# the same method_missing tag DSL the Nokogiri wrapper
|
|
17
17
|
# expose: tag(attrs) { ... } closures, symbol or string
|
|
18
18
|
# attribute keys, xmlns handled as a namespace declaration.
|
|
19
19
|
class Moxml
|
|
@@ -4,22 +4,21 @@ module Lutaml
|
|
|
4
4
|
module Xml
|
|
5
5
|
module Schema
|
|
6
6
|
# SchemaBuilder provides an adapter-agnostic interface for XSD schema generation
|
|
7
|
-
# It wraps XML builders (Nokogiri,
|
|
7
|
+
# It wraps XML builders (Nokogiri, or the moxml layer) to generate XSD documents
|
|
8
8
|
#
|
|
9
9
|
# NOTE: Schema generation is separate from XML parsing. While the XML parsing
|
|
10
|
-
# adapters (Nokogiri,
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
10
|
+
# adapters (Nokogiri, Ox, REXML) handle reading/writing XML documents, schema
|
|
11
|
+
# generation requires an XML builder API: the Nokogiri wrapper keeps
|
|
12
|
+
# byte-identical emission, and every other configured engine generates
|
|
13
|
+
# through the moxml layer.
|
|
14
14
|
class Builder
|
|
15
15
|
autoload :Nokogiri, "#{__dir__}/builder/nokogiri"
|
|
16
|
-
autoload :Oga, "#{__dir__}/builder/oga"
|
|
17
16
|
autoload :Moxml, "#{__dir__}/builder/moxml"
|
|
18
17
|
|
|
19
18
|
attr_reader :builder, :adapter_type
|
|
20
19
|
|
|
21
20
|
# Supported schema builders (separate from XML parsing adapters)
|
|
22
|
-
SUPPORTED_BUILDERS = %i[nokogiri
|
|
21
|
+
SUPPORTED_BUILDERS = %i[nokogiri].freeze
|
|
23
22
|
|
|
24
23
|
def initialize(adapter_type: nil, options: {}, &block)
|
|
25
24
|
# Use specified adapter, or configured XML adapter, or default to Nokogiri
|
|
@@ -48,8 +47,6 @@ module Lutaml
|
|
|
48
47
|
case @adapter_type
|
|
49
48
|
when :nokogiri
|
|
50
49
|
Nokogiri.new(@options, &block)
|
|
51
|
-
when :oga
|
|
52
|
-
Oga.new(@options, &block)
|
|
53
50
|
else
|
|
54
51
|
Moxml.new(@options, &block)
|
|
55
52
|
end
|
|
@@ -8,7 +8,7 @@ module Lutaml
|
|
|
8
8
|
# Generates RELAX NG schemas from LutaML model classes. The
|
|
9
9
|
# emission rides the configured engine through the moxml layer
|
|
10
10
|
# (#1184); an explicit adapter option keeps the dedicated
|
|
11
|
-
# Nokogiri
|
|
11
|
+
# Nokogiri wrapper available.
|
|
12
12
|
class RelaxngSchema
|
|
13
13
|
extend Lutaml::Model::Schema::SharedMethods
|
|
14
14
|
|
|
@@ -203,8 +203,9 @@ module Lutaml
|
|
|
203
203
|
# This supports the new namespace_definitions approach where each element only
|
|
204
204
|
# stores its own declarations, and child elements inherit from parent
|
|
205
205
|
#
|
|
206
|
-
# NOTE: Not cached here because
|
|
207
|
-
# super() sets @parent_document, which would cache an
|
|
206
|
+
# NOTE: Not cached here because an engine element's initialize calls
|
|
207
|
+
# this before super() sets @parent_document, which would cache an
|
|
208
|
+
# incorrect empty result.
|
|
208
209
|
# The hot path (namespaced_name) is cached separately.
|
|
209
210
|
if @namespaces&.any?
|
|
210
211
|
@namespaces
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "concurrent"
|
|
3
|
+
require "concurrent"
|
|
4
4
|
|
|
5
5
|
module Lutaml
|
|
6
6
|
module Xml
|
|
@@ -9,7 +9,7 @@ module Lutaml
|
|
|
9
9
|
# Backs the `validate_xml_with` class macro (issue #264). Routing is
|
|
10
10
|
# engine-agnostic through moxml (#1184): schemas compile and validate
|
|
11
11
|
# on the CONFIGURED engine — `Moxml::XSD.supported?` answers without
|
|
12
|
-
# raising, and engines without a validator (ox,
|
|
12
|
+
# raising, and engines without a validator (ox, rexml) fall back
|
|
13
13
|
# to the historical Nokogiri path, keeping its requirement error when
|
|
14
14
|
# the gem is absent. The leptris engine carries a validator.
|
|
15
15
|
#
|
|
@@ -24,8 +24,8 @@ module Lutaml
|
|
|
24
24
|
# Not to be confused with Schema::Xsd::SchemaValidator, which checks
|
|
25
25
|
# that an XSD document itself is well-formed XSD.
|
|
26
26
|
module XsdValidator
|
|
27
|
-
@schemas = ::Concurrent::Map.new
|
|
28
|
-
@nokogiri_schemas = ::Concurrent::Map.new
|
|
27
|
+
@schemas = ::Concurrent::Map.new
|
|
28
|
+
@nokogiri_schemas = ::Concurrent::Map.new
|
|
29
29
|
|
|
30
30
|
# @param xml [String] an XML document
|
|
31
31
|
# @param schema_paths [Array<String>] paths to XSD schema files
|
|
@@ -34,13 +34,6 @@ module Lutaml
|
|
|
34
34
|
paths = Array(schema_paths)
|
|
35
35
|
return [] if paths.empty?
|
|
36
36
|
|
|
37
|
-
if RUBY_ENGINE == "opal"
|
|
38
|
-
raise NotImplementedError,
|
|
39
|
-
"XSD schema validation (validate_xml_with) requires an " \
|
|
40
|
-
"XML engine with schema validation, which is not " \
|
|
41
|
-
"available under Opal."
|
|
42
|
-
end
|
|
43
|
-
|
|
44
37
|
if engine_supports_xsd?
|
|
45
38
|
document = context.parse(xml, strict: true)
|
|
46
39
|
paths.flat_map do |path|
|
|
@@ -77,8 +77,8 @@ module Lutaml
|
|
|
77
77
|
# format_error_types conversion to InvalidFormatError) hold on
|
|
78
78
|
# every adapter. The C parser reports the position inside the
|
|
79
79
|
# error message ("... at line L, column C"); lift it into the
|
|
80
|
-
# structured fields. Without psych
|
|
81
|
-
#
|
|
80
|
+
# structured fields. Without psych the engine error propagates
|
|
81
|
+
# unchanged.
|
|
82
82
|
def self.syntax_error(error)
|
|
83
83
|
return error unless defined?(::Psych::SyntaxError)
|
|
84
84
|
|
|
@@ -13,11 +13,7 @@ module Lutaml
|
|
|
13
13
|
# @param _adapter [String] the adapter format name ("yamls")
|
|
14
14
|
# @param type [String] the normalized type name (e.g., "yeptris_adapter")
|
|
15
15
|
def self.load_adapter_file(_adapter, type)
|
|
16
|
-
adapter_path =
|
|
17
|
-
"lutaml/yamls/adapter/#{type}"
|
|
18
|
-
else
|
|
19
|
-
File.join(File.dirname(__FILE__), "adapter", type)
|
|
20
|
-
end
|
|
16
|
+
adapter_path = File.join(File.dirname(__FILE__), "adapter", type)
|
|
21
17
|
require adapter_path
|
|
22
18
|
rescue LoadError => e
|
|
23
19
|
raise Lutaml::Model::UnknownAdapterTypeError.new("yamls", type),
|