lutaml-model 0.8.169 → 0.8.171
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/bench/baselines/main_mml.json +30 -0
- data/bench/baselines/main_niso.json +23 -0
- data/bench/baselines/main_sts.json +30 -0
- data/bench/baselines/main_unitsml.json +9 -0
- data/bench/baselines/main_xmi.json +30 -0
- data/docs/namespace-management.adoc +27 -0
- data/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/model/adapter_resolver.rb +16 -46
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/decisions/decision_engine.rb +1 -0
- data/lib/lutaml/xml/decisions/rules/attribute_qualified_prefix_rule.rb +57 -0
- data/lib/lutaml/xml/decisions/rules.rb +2 -0
- data/lib/lutaml/xml/declaration_planner.rb +22 -2
- data/lib/lutaml/xml/leptris/native_emission.rb +36 -0
- data/lib/lutaml/xml/leptris/plan_serializer.rb +26 -0
- data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +88 -21
- data/spec/lutaml/model/yeptris_error_parity_spec.rb +22 -5
- data/spec/lutaml/model/yeptris_native_detection_spec.rb +4 -6
- data/spec/lutaml/xml/constructed_namespace_prefix_spec.rb +110 -0
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad87ede1dc1046dc1129810d396b384572f654bab3f426b303c2a26c46d30507
|
|
4
|
+
data.tar.gz: f0a37ec49e92932743c014ba0f8ef5f8de44dcc21fd7f0b7119090308d6089ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54efd8912a0ede8e60e9c2215a2819d10d7f9cd6298460bccd3bcbd2b2b0005f8ec2fe60093ee5e5a399f17460b15a352bc381858fc3d252b17ac336bb8e905b
|
|
7
|
+
data.tar.gz: 7816771d96e7d0751b627769bde1a609c735e9a9442f6922f07d687fe2bd614b7cd76c3599078edcc8ab1df7e7e7db0083b02a751aeb45675d668c880194a03f
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"complex1-46KB": {
|
|
3
|
+
"avg_time": 0.058778864333329274,
|
|
4
|
+
"min_time": 0.05830439700000056,
|
|
5
|
+
"max_time": 0.05932801200000881,
|
|
6
|
+
"allocations": 51133,
|
|
7
|
+
"ips": 17.012918016399507
|
|
8
|
+
},
|
|
9
|
+
"complex4-50KB": {
|
|
10
|
+
"avg_time": 0.07925129733333354,
|
|
11
|
+
"min_time": 0.07819793400000208,
|
|
12
|
+
"max_time": 0.08018583899999498,
|
|
13
|
+
"allocations": 71910,
|
|
14
|
+
"ips": 12.61808997011074
|
|
15
|
+
},
|
|
16
|
+
"size1000-245KB": {
|
|
17
|
+
"avg_time": 0.4650558216666667,
|
|
18
|
+
"min_time": 0.4527184709999972,
|
|
19
|
+
"max_time": 0.4820626730000015,
|
|
20
|
+
"allocations": 406451,
|
|
21
|
+
"ips": 2.150279500676286
|
|
22
|
+
},
|
|
23
|
+
"complex3-567KB": {
|
|
24
|
+
"avg_time": 0.63353054833334,
|
|
25
|
+
"min_time": 0.6305890920000081,
|
|
26
|
+
"max_time": 0.6364362909999954,
|
|
27
|
+
"allocations": 587536,
|
|
28
|
+
"ips": 1.5784558497309233
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metrology-4KB": {
|
|
3
|
+
"avg_time": 0.01583877299999396,
|
|
4
|
+
"min_time": 0.01537591099999247,
|
|
5
|
+
"max_time": 0.01672697600000106,
|
|
6
|
+
"allocations": 7544,
|
|
7
|
+
"ips": 63.136203795608495
|
|
8
|
+
},
|
|
9
|
+
"bmj-49KB": {
|
|
10
|
+
"avg_time": 0.14416509699999835,
|
|
11
|
+
"min_time": 0.14264834999998754,
|
|
12
|
+
"max_time": 0.145113625999997,
|
|
13
|
+
"allocations": 72378,
|
|
14
|
+
"ips": 6.936491708530612
|
|
15
|
+
},
|
|
16
|
+
"pnas-152KB": {
|
|
17
|
+
"avg_time": 0.6785376123333341,
|
|
18
|
+
"min_time": 0.6706088810000068,
|
|
19
|
+
"max_time": 0.6903751819999968,
|
|
20
|
+
"allocations": 259437,
|
|
21
|
+
"ips": 1.4737576544375057
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"feature-doc-23KB": {
|
|
3
|
+
"avg_time": 0.07073791833333114,
|
|
4
|
+
"min_time": 0.06960952800000086,
|
|
5
|
+
"max_time": 0.07274033499999177,
|
|
6
|
+
"allocations": 32998,
|
|
7
|
+
"ips": 14.13668967876325
|
|
8
|
+
},
|
|
9
|
+
"tbx-nisosts-101KB": {
|
|
10
|
+
"avg_time": 0.2049442063333231,
|
|
11
|
+
"min_time": 0.20431456800000092,
|
|
12
|
+
"max_time": 0.20608122899997738,
|
|
13
|
+
"allocations": 134786,
|
|
14
|
+
"ips": 4.879376772298657
|
|
15
|
+
},
|
|
16
|
+
"iso-13849-1MB": {
|
|
17
|
+
"avg_time": 8.094979964666683,
|
|
18
|
+
"min_time": 8.011807766000004,
|
|
19
|
+
"max_time": 8.253521833999997,
|
|
20
|
+
"allocations": 1733464,
|
|
21
|
+
"ips": 0.1235333508377838
|
|
22
|
+
},
|
|
23
|
+
"din-iso-1.1MB": {
|
|
24
|
+
"avg_time": 0.823126560000001,
|
|
25
|
+
"min_time": 0.8167314490000024,
|
|
26
|
+
"max_time": 0.8273381509999922,
|
|
27
|
+
"allocations": 883501,
|
|
28
|
+
"ips": 1.2148800058158722
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ea251": {
|
|
3
|
+
"avg_time": 0.3043722769999988,
|
|
4
|
+
"min_time": 0.2995728340000028,
|
|
5
|
+
"max_time": 0.3132120479999969,
|
|
6
|
+
"allocations": 183151,
|
|
7
|
+
"ips": 3.285450336858386
|
|
8
|
+
},
|
|
9
|
+
"medium": {
|
|
10
|
+
"avg_time": 0.7569878543333269,
|
|
11
|
+
"min_time": 0.7486214030000156,
|
|
12
|
+
"max_time": 0.7709131660000139,
|
|
13
|
+
"allocations": 474403,
|
|
14
|
+
"ips": 1.3210251581654398
|
|
15
|
+
},
|
|
16
|
+
"citygml": {
|
|
17
|
+
"avg_time": 0.8518815016666679,
|
|
18
|
+
"min_time": 0.8465627909999967,
|
|
19
|
+
"max_time": 0.8623405149999996,
|
|
20
|
+
"allocations": 586804,
|
|
21
|
+
"ips": 1.1738721853257112
|
|
22
|
+
},
|
|
23
|
+
"large": {
|
|
24
|
+
"avg_time": 7.076599947333325,
|
|
25
|
+
"min_time": 6.997333662999978,
|
|
26
|
+
"max_time": 7.230798198000002,
|
|
27
|
+
"allocations": 4531263,
|
|
28
|
+
"ips": 0.14131080002294463
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -73,6 +73,33 @@ When using namespaces with `uri_aliases`, the system maintains a mapping between
|
|
|
73
73
|
When round-tripping, the original URI (alias or canonical) is preserved regardless of the `prefix:` option.
|
|
74
74
|
====
|
|
75
75
|
|
|
76
|
+
==== Constructed-Model Wire Form
|
|
77
|
+
|
|
78
|
+
Models built programmatically (never parsed) choose their root spelling from the namespace declaration itself. A namespace that declares `attribute_form_default :qualified` serializes in prefix form — W3C attributes never inherit the default namespace, so a document whose attributes are namespace-qualified is inherently a prefixed document, and the root carries its `prefix_default` accordingly. Namespaces with unqualified attributes (the W3C default) serialize in default-namespace form.
|
|
79
|
+
|
|
80
|
+
[source,ruby]
|
|
81
|
+
----
|
|
82
|
+
class WordNamespace < Lutaml::Xml::Namespace
|
|
83
|
+
uri "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
|
84
|
+
prefix_default "w"
|
|
85
|
+
element_form_default :qualified
|
|
86
|
+
attribute_form_default :qualified # every attribute carries w:
|
|
87
|
+
end
|
|
88
|
+
# Constructed serialization: <w:document xmlns:w="..."> - the same
|
|
89
|
+
# form the parsed-and-reserialized output keeps.
|
|
90
|
+
|
|
91
|
+
class CustomPropsNamespace < Lutaml::Xml::Namespace
|
|
92
|
+
uri "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
|
|
93
|
+
prefix_default "custprops"
|
|
94
|
+
element_form_default :qualified # attributes stay unqualified (W3C default)
|
|
95
|
+
end
|
|
96
|
+
# Constructed serialization: <Properties xmlns="..."> - the
|
|
97
|
+
# default-xmlns document style; foreign-namespace children keep their
|
|
98
|
+
# declared prefixes.
|
|
99
|
+
----
|
|
100
|
+
|
|
101
|
+
The `prefix:` serialization options above still override this choice: `prefix: false` forces the default form, `prefix: true` and prefix strings force prefix form.
|
|
102
|
+
|
|
76
103
|
==== Examples
|
|
77
104
|
|
|
78
105
|
[source,ruby]
|
|
@@ -521,6 +521,7 @@ require "lutaml/model/schema/xml_compiler/registry_generator"
|
|
|
521
521
|
require "lutaml/model/schema/xml_compiler/spec_builder"
|
|
522
522
|
require "lutaml/model/schema/xml_compiler/supported_data_types"
|
|
523
523
|
require "lutaml/model/services/type/validator"
|
|
524
|
+
require "lutaml/xml/decisions/rules/attribute_qualified_prefix_rule"
|
|
524
525
|
require "lutaml/xml/decisions/rules/attribute_usage_rule"
|
|
525
526
|
require "lutaml/xml/decisions/rules/default_preference_rule"
|
|
526
527
|
require "lutaml/xml/decisions/rules/element_form_default_rule"
|
|
@@ -416,60 +416,30 @@ module Lutaml
|
|
|
416
416
|
end
|
|
417
417
|
|
|
418
418
|
# Native key-value engine preference: yeptris (libyeptris C11)
|
|
419
|
-
#
|
|
420
|
-
#
|
|
421
|
-
#
|
|
422
|
-
#
|
|
423
|
-
#
|
|
424
|
-
#
|
|
425
|
-
#
|
|
426
|
-
#
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
#
|
|
430
|
-
#
|
|
431
|
-
#
|
|
432
|
-
#
|
|
433
|
-
#
|
|
434
|
-
#
|
|
419
|
+
# is preferred whenever the engine answers a probe, matching
|
|
420
|
+
# the XML lane's prefer-if-available contract — the parity
|
|
421
|
+
# fixes for the platform scalar materialization landed in
|
|
422
|
+
# yeptris 0.6.57+ (leptris/yeptris#863), lifting the reason
|
|
423
|
+
# bundle-presence selection was unsafe. Adapter choice is
|
|
424
|
+
# centralized: a host that wants a different engine configures
|
|
425
|
+
# it through Config (yaml_adapter_type= / json_adapter_type=),
|
|
426
|
+
# which pins the adapter and bypasses detection entirely; no
|
|
427
|
+
# environment variables are consulted here (the former
|
|
428
|
+
# LUTAML_YAML / FONTIST_YAML spellings are not read anymore).
|
|
429
|
+
# The probe matters because a half-initialized Yeptris constant
|
|
430
|
+
# (the poison-process state the gem documents) passes
|
|
431
|
+
# const_defined? and require while every parse fails; without
|
|
432
|
+
# it the lane selection flips with process load order and the
|
|
433
|
+
# failure surfaces as a native parse error on valid input
|
|
434
|
+
# instead of a clean standard-lane parse (#978).
|
|
435
435
|
def detect_yeptris_kv_adapter(format)
|
|
436
436
|
default = metadata.dig(format, :default)
|
|
437
437
|
return default if Lutaml::Model.opal?
|
|
438
|
-
|
|
439
|
-
unless yeptris_opted_in?
|
|
440
|
-
warn_yeptris_present_once(format)
|
|
441
|
-
return default
|
|
442
|
-
end
|
|
443
438
|
return default unless Utils.safe_load("yeptris", :Yeptris)
|
|
444
439
|
|
|
445
440
|
load_adapter(format, :yeptris).available? ? :yeptris : default
|
|
446
441
|
end
|
|
447
442
|
|
|
448
|
-
# The consumer-neutral opt-in; FONTIST_YAML=yeptris stays honored
|
|
449
|
-
# as the legacy spelling fontist and lutaml-store already ship
|
|
450
|
-
# (#1115: glossarist is not fontist — the switch must not carry
|
|
451
|
-
# one consumer's namespace).
|
|
452
|
-
def yeptris_opted_in?
|
|
453
|
-
%w[LUTAML_YAML FONTIST_YAML].any? { |k| ENV[k] == "yeptris" }
|
|
454
|
-
end
|
|
455
|
-
|
|
456
|
-
# Make the gated engine visible (#1115 ask 3): a process whose
|
|
457
|
-
# bundle merely contains yeptris used to get it auto-selected;
|
|
458
|
-
# the gate keeps that from happening silently, but the presence
|
|
459
|
-
# of an unused native engine is exactly the kind of fact an
|
|
460
|
-
# upgrading consumer needs to see once.
|
|
461
|
-
def warn_yeptris_present_once(_format)
|
|
462
|
-
return if Lutaml::Model.opal?
|
|
463
|
-
return if @yeptris_presence_warned
|
|
464
|
-
return unless Utils.safe_load("yeptris", :Yeptris)
|
|
465
|
-
|
|
466
|
-
@yeptris_presence_warned = true
|
|
467
|
-
warn "[Lutaml::Model] yeptris is present in this bundle but the " \
|
|
468
|
-
"native YAML engine is not enabled (its parity fixes are " \
|
|
469
|
-
"still landing, leptris/yeptris#863); the standard adapter " \
|
|
470
|
-
"serves YAML. Enable explicitly with LUTAML_YAML=yeptris."
|
|
471
|
-
end
|
|
472
|
-
|
|
473
443
|
# Detect available XML adapter.
|
|
474
444
|
#
|
|
475
445
|
# Delegates to moxml which is the authority on XML adapter
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -56,6 +56,7 @@ module Lutaml
|
|
|
56
56
|
Rules::ExplicitOptionRule.new,
|
|
57
57
|
Rules::NamespaceScopeRule.new,
|
|
58
58
|
Rules::AttributeUsageRule.new,
|
|
59
|
+
Rules::AttributeQualifiedPrefixRule.new,
|
|
59
60
|
Rules::ElementFormDefaultRule.new,
|
|
60
61
|
Rules::DefaultPreferenceRule.new, # Must be last (catch-all)
|
|
61
62
|
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Decisions
|
|
6
|
+
module Rules
|
|
7
|
+
# Priority 4.4: attribute-qualifying namespaces spell prefixed.
|
|
8
|
+
#
|
|
9
|
+
# A namespace that declares attribute_form_default :qualified
|
|
10
|
+
# produces an inherently prefixed document: W3C attributes never
|
|
11
|
+
# inherit the default namespace, so every attribute already
|
|
12
|
+
# carries the prefix, and the coherent spelling prefixes the
|
|
13
|
+
# root too. Namespaces with unqualified attributes (the W3C
|
|
14
|
+
# default) keep the default-xmlns document style.
|
|
15
|
+
#
|
|
16
|
+
# This is the constructed-model counterpart of the parsed path's
|
|
17
|
+
# Priority 1 format preservation: a WordprocessingML-style part
|
|
18
|
+
# (w:document with w:val attributes) serializes prefixed whether
|
|
19
|
+
# it was parsed or built, while a custom-properties-style part
|
|
20
|
+
# (bare fmtid/pid/name attributes) serializes in default-xmlns
|
|
21
|
+
# form in both lanes (lutaml-model#1124).
|
|
22
|
+
#
|
|
23
|
+
# IMPORTANT: This rule does NOT override input format preservation
|
|
24
|
+
# (Priority 1). It only applies when no input format exists
|
|
25
|
+
# (programmatically created models).
|
|
26
|
+
class AttributeQualifiedPrefixRule < DecisionRule
|
|
27
|
+
def priority
|
|
28
|
+
4.4
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def applies?(context)
|
|
32
|
+
return false unless context.has_namespace?
|
|
33
|
+
|
|
34
|
+
ns_class = context.namespace_class
|
|
35
|
+
return false unless ns_class
|
|
36
|
+
return false if ns_class.prefix_default.to_s.empty?
|
|
37
|
+
return false unless ns_class.attribute_form_default == :qualified
|
|
38
|
+
|
|
39
|
+
# If input format exists, FormatPreservationRule (Priority 1)
|
|
40
|
+
# handles it
|
|
41
|
+
context.preserved_input_format.nil?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def decide(context)
|
|
45
|
+
ns_class = context.namespace_class
|
|
46
|
+
Decision.prefix(
|
|
47
|
+
prefix: ns_class.prefix_default,
|
|
48
|
+
namespace_class: ns_class,
|
|
49
|
+
reason: "Priority 4.4: attribute_form_default :qualified - " \
|
|
50
|
+
"inherently prefixed document, root spells prefixed",
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -27,6 +27,8 @@ module Lutaml
|
|
|
27
27
|
autoload :AttributeUsageRule, "#{__dir__}/rules/attribute_usage_rule"
|
|
28
28
|
autoload :ElementFormDefaultRule,
|
|
29
29
|
"#{__dir__}/rules/element_form_default_rule"
|
|
30
|
+
autoload :AttributeQualifiedPrefixRule,
|
|
31
|
+
"#{__dir__}/rules/attribute_qualified_prefix_rule"
|
|
30
32
|
autoload :DefaultPreferenceRule,
|
|
31
33
|
"#{__dir__}/rules/default_preference_rule"
|
|
32
34
|
autoload :InheritParentPrefixRule,
|
|
@@ -110,6 +110,18 @@ module Lutaml
|
|
|
110
110
|
# CRITICAL: Only applies when explicitly set, not when defaulted to :unqualified.
|
|
111
111
|
prefix = element_namespace.prefix_default || "ns#{hoisted.keys.length}"
|
|
112
112
|
hoisted[prefix] = element_namespace.uri
|
|
113
|
+
elsif element_namespace.attribute_form_default == :qualified &&
|
|
114
|
+
element_namespace.prefix_default
|
|
115
|
+
# A namespace that qualifies its ATTRIBUTES produces an
|
|
116
|
+
# inherently prefixed document: W3C attributes never
|
|
117
|
+
# inherit the default namespace, so every attribute
|
|
118
|
+
# already carries the prefix, and the coherent spelling
|
|
119
|
+
# prefixes the root too. Namespaces with unqualified
|
|
120
|
+
# attributes (the W3C default) keep the default-xmlns
|
|
121
|
+
# document style (lutaml-model#1124: w: document.xml vs
|
|
122
|
+
# default-form custom.xml).
|
|
123
|
+
hoisted[element_namespace.prefix_default] =
|
|
124
|
+
element_namespace.uri
|
|
113
125
|
else
|
|
114
126
|
# Default: prefer default format (cleaner)
|
|
115
127
|
hoisted[nil] = element_namespace.uri
|
|
@@ -182,8 +194,16 @@ module Lutaml
|
|
|
182
194
|
scope_config = needs.scope_config_for(ns_class)
|
|
183
195
|
next if scope_config
|
|
184
196
|
|
|
185
|
-
# Add remaining namespace (default format preferred
|
|
186
|
-
|
|
197
|
+
# Add remaining namespace (default format preferred;
|
|
198
|
+
# attribute-qualifying namespaces keep their declared
|
|
199
|
+
# prefix so foreign-namespace children stay qualified —
|
|
200
|
+
# lutaml-model#1124)
|
|
201
|
+
if ns_class.prefix_default &&
|
|
202
|
+
ns_class.attribute_form_default == :qualified
|
|
203
|
+
hoisted[ns_class.prefix_default] = ns_class.uri
|
|
204
|
+
else
|
|
205
|
+
hoisted[nil] = ns_class.uri
|
|
206
|
+
end
|
|
187
207
|
end
|
|
188
208
|
|
|
189
209
|
root_node = DeclarationPlan::ElementNode.new(
|
|
@@ -62,10 +62,46 @@ module Lutaml
|
|
|
62
62
|
return false unless ordered_ns_emittable?(plan, instance)
|
|
63
63
|
return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
64
64
|
instance.element_order.nil?
|
|
65
|
+
# An UNORDERED instance (no parse-captured element_order)
|
|
66
|
+
# over a MULTI-NAMESPACE EXACT tree spells through the
|
|
67
|
+
# flat emission layout, whose slot numbering diverges from
|
|
68
|
+
# the engine descriptor for nested rows across namespaces
|
|
69
|
+
# — the ops address the wrong plan and grandchildren
|
|
70
|
+
# render with the grandparent's name and prefix (a
|
|
71
|
+
# constructed prefixed w:-root with an m:-namespace child
|
|
72
|
+
# spelled the child's t row as w:r). Single-namespace
|
|
73
|
+
# unordered trees spell faithfully (the clrScheme shape);
|
|
74
|
+
# the DOM lane serves the rest until the flat emission
|
|
75
|
+
# numbering matches the descriptor walk.
|
|
76
|
+
return false if multi_exact_ns_tree?(plan[:tree]) &&
|
|
77
|
+
instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
78
|
+
instance.element_order.nil?
|
|
65
79
|
|
|
66
80
|
subtree_gate_ok?(plan, instance, register)
|
|
67
81
|
end
|
|
68
82
|
|
|
83
|
+
# Whether the tree's EXACT-ns rows (tree, attribute rows,
|
|
84
|
+
# child rows, recursively through nested plans) carry more
|
|
85
|
+
# than one distinct namespace URI.
|
|
86
|
+
def multi_exact_ns_tree?(tree, uris = ::Set.new)
|
|
87
|
+
return false unless tree.is_a?(::Hash)
|
|
88
|
+
|
|
89
|
+
ns = tree[:ns]
|
|
90
|
+
uris << ns[:exact] if ns.is_a?(::Hash) && ns[:exact]
|
|
91
|
+
(tree[:attributes] || []).each do |a|
|
|
92
|
+
ans = a[:ns]
|
|
93
|
+
uris << ans[:exact] if ans.is_a?(::Hash) && ans[:exact]
|
|
94
|
+
end
|
|
95
|
+
(tree[:children] || []).each do |r|
|
|
96
|
+
rns = r[:ns]
|
|
97
|
+
uris << rns[:exact] if rns.is_a?(::Hash) && rns[:exact]
|
|
98
|
+
if r[:plan] && PLANNED_ROW_KINDS.include?(r[:kind])
|
|
99
|
+
multi_exact_ns_tree?(r[:plan], uris)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
uris.length > 1
|
|
103
|
+
end
|
|
104
|
+
|
|
69
105
|
# The engine's attr-row ns_prefix deep-copy fix rides
|
|
70
106
|
# 1.9.407.0 (leptris#1967, fixed by leptris#1968): earlier
|
|
71
107
|
# engines keep the binding's freed FFI anchor pointer in the
|
|
@@ -119,6 +119,7 @@ module Lutaml
|
|
|
119
119
|
attr_reader :unspellable
|
|
120
120
|
|
|
121
121
|
def initialize(instance, plan, register)
|
|
122
|
+
@model_prefix = nil
|
|
122
123
|
@forms = {}
|
|
123
124
|
@hoisted = {}
|
|
124
125
|
@declared = {}
|
|
@@ -185,6 +186,23 @@ module Lutaml
|
|
|
185
186
|
end
|
|
186
187
|
end
|
|
187
188
|
collect(plan[:tree])
|
|
189
|
+
# #1124: under the attribute-qualified wire-form doctrine,
|
|
190
|
+
# a CONSTRUCTED instance (no parse provenance - no
|
|
191
|
+
# element_order AND no stored input declaration plan)
|
|
192
|
+
# whose namespace qualifies its attributes spells the
|
|
193
|
+
# whole document prefixed; rows compiled without an ns
|
|
194
|
+
# form (own-namespace children under element_form_default
|
|
195
|
+
# :qualified) take the model prefix instead of falling
|
|
196
|
+
# into no namespace.
|
|
197
|
+
ns_class = mapping.namespace_class
|
|
198
|
+
if instance.element_order.nil? &&
|
|
199
|
+
!instance.import_declaration_plan.is_a?(
|
|
200
|
+
Lutaml::Xml::DeclarationPlan,
|
|
201
|
+
) && ns_class &&
|
|
202
|
+
ns_class.attribute_form_default == :qualified &&
|
|
203
|
+
!ns_class.prefix_default.to_s.empty?
|
|
204
|
+
@model_prefix = ns_class.prefix_default.to_s
|
|
205
|
+
end
|
|
188
206
|
end
|
|
189
207
|
|
|
190
208
|
def unspellable?
|
|
@@ -219,6 +237,14 @@ module Lutaml
|
|
|
219
237
|
# planner's hoisted prefix for the URI, or unprefixed when
|
|
220
238
|
# hoisted as the default namespace.
|
|
221
239
|
def spell(local, ns_form = nil)
|
|
240
|
+
if ns_form.nil?
|
|
241
|
+
# No row ns: the element belongs to the model's own
|
|
242
|
+
# namespace (element_form_default :qualified) - under
|
|
243
|
+
# the attribute-qualified doctrine it spells with the
|
|
244
|
+
# model's declared prefix (#1124).
|
|
245
|
+
return @model_prefix ? "#{@model_prefix}:#{local}" : local
|
|
246
|
+
end
|
|
247
|
+
|
|
222
248
|
uri = if ns_form.is_a?(Hash)
|
|
223
249
|
ns_form[:exact]
|
|
224
250
|
else
|
|
@@ -2,39 +2,106 @@
|
|
|
2
2
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
|
|
5
|
+
# The yeptris YAML engine is preferred whenever it answers a probe,
|
|
6
|
+
# matching the XML lane's prefer-if-available contract: the platform
|
|
7
|
+
# parity fixes for plain-scalar materialization landed in yeptris
|
|
8
|
+
# 0.6.57+ (leptris/yeptris#863). Adapter choice is centralized in
|
|
9
|
+
# Config (yaml_adapter_type= / json_adapter_type=) — a host that wants
|
|
10
|
+
# a different engine pins it there, and the detection path consults no
|
|
11
|
+
# environment variables.
|
|
12
|
+
RSpec.describe "yeptris engine preference" do
|
|
13
|
+
# Reset only the key-value resolution entries: the explicit pins, the
|
|
14
|
+
# lazy detection cache, and the resolved-class cache. The resolver-wide
|
|
15
|
+
# reset! would also wipe the adapters other specs configured (the XML
|
|
16
|
+
# lane in particular), silently re-detecting a different runtime for
|
|
17
|
+
# the rest of the process.
|
|
18
|
+
def with_fresh_kv_resolution
|
|
19
|
+
resolver = Lutaml::Model::AdapterResolver
|
|
20
|
+
types = resolver.__send__(:configured_types)
|
|
21
|
+
detected = resolver.__send__(:detected_types)
|
|
22
|
+
detected_flags = resolver.__send__(:detected_formats)
|
|
23
|
+
resolved = resolver.__send__(:resolved)
|
|
24
|
+
saved = types.slice(:yaml, :json)
|
|
25
|
+
saved_detected = detected.slice(:yaml, :json)
|
|
26
|
+
saved_resolved = resolved.slice(:yaml, :json)
|
|
27
|
+
%i[yaml json].each do |format|
|
|
28
|
+
types.delete(format)
|
|
29
|
+
detected.delete(format)
|
|
30
|
+
detected_flags.delete(format)
|
|
31
|
+
resolved.delete(format)
|
|
32
|
+
end
|
|
33
|
+
yield
|
|
34
|
+
ensure
|
|
35
|
+
%i[yaml json].each do |format|
|
|
36
|
+
types.delete(format)
|
|
37
|
+
detected.delete(format)
|
|
38
|
+
detected_flags.delete(format)
|
|
39
|
+
resolved.delete(format)
|
|
40
|
+
end
|
|
41
|
+
saved.each { |format, type| types[format] = type }
|
|
42
|
+
saved_detected.each { |format, type| detected[format] = type }
|
|
43
|
+
saved_resolved.each { |format, klass| resolved[format] = klass }
|
|
44
|
+
%i[yaml json].each { |format| detected_flags.delete(format) }
|
|
45
|
+
end
|
|
46
|
+
|
|
10
47
|
around do |example|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
example.run
|
|
15
|
-
old.each { |k, v| ENV[k] = v }
|
|
48
|
+
with_fresh_kv_resolution do
|
|
49
|
+
example.run
|
|
50
|
+
end
|
|
16
51
|
end
|
|
17
52
|
|
|
18
|
-
|
|
53
|
+
def yeptris_engine_available?
|
|
54
|
+
return false if RUBY_ENGINE == "opal"
|
|
55
|
+
|
|
56
|
+
Lutaml::Model::Utils.safe_load("yeptris", :Yeptris)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "prefers yeptris by default when the engine is available" do
|
|
19
60
|
skip "yeptris engine not available on this platform" unless
|
|
20
|
-
|
|
61
|
+
yeptris_engine_available?
|
|
21
62
|
|
|
22
63
|
expect(Lutaml::Model::Config.adapter_for(:yaml))
|
|
23
64
|
.to be(Lutaml::Yaml::Adapter::YeptrisAdapter)
|
|
24
65
|
end
|
|
25
66
|
|
|
26
|
-
it "
|
|
27
|
-
|
|
67
|
+
it "keeps a centrally configured adapter ahead of detection" do
|
|
68
|
+
skip "yeptris engine not available on this platform" unless
|
|
69
|
+
yeptris_engine_available?
|
|
70
|
+
|
|
71
|
+
Lutaml::Model::AdapterResolver.set_adapter_type(:yaml, :standard)
|
|
28
72
|
|
|
29
|
-
|
|
30
|
-
|
|
73
|
+
expect(Lutaml::Model::Config.adapter_for(:yaml))
|
|
74
|
+
.not_to be(Lutaml::Yaml::Adapter::YeptrisAdapter)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "does not consult environment variables for engine choice" do
|
|
78
|
+
ENV["LUTAML_YAML"] = "standard"
|
|
79
|
+
ENV["FONTIST_YAML"] = "standard"
|
|
80
|
+
|
|
81
|
+
if yeptris_engine_available?
|
|
82
|
+
expect(Lutaml::Model::Config.adapter_for(:yaml))
|
|
83
|
+
.to be(Lutaml::Yaml::Adapter::YeptrisAdapter)
|
|
84
|
+
else
|
|
85
|
+
expect(Lutaml::Model::Config.adapter_for(:yaml))
|
|
86
|
+
.not_to be(Lutaml::Yaml::Adapter::YeptrisAdapter)
|
|
87
|
+
end
|
|
31
88
|
end
|
|
32
89
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
90
|
+
# leptris/yeptris#863: plain string scalars must materialize as
|
|
91
|
+
# strings on every platform build; the 0.6.53 linux build turned
|
|
92
|
+
# them into single-element Arrays, corrupting checksum consumers.
|
|
93
|
+
it "parses plain string scalars as strings through the engine" do
|
|
94
|
+
skip "yeptris engine not available on this platform" unless
|
|
95
|
+
yeptris_engine_available?
|
|
96
|
+
|
|
97
|
+
parsed = Lutaml::Yaml::Adapter::YeptrisAdapter.parse(<<~YAML)
|
|
98
|
+
resources:
|
|
99
|
+
andale32.exe:
|
|
100
|
+
sha256: 0524fe42951adc3a7eb870e32f0920313c71f170c859b5f770d82b4ee111e970
|
|
101
|
+
YAML
|
|
36
102
|
|
|
37
|
-
|
|
38
|
-
|
|
103
|
+
expect(
|
|
104
|
+
parsed["resources"]["andale32.exe"]["sha256"],
|
|
105
|
+
).to be_a(String)
|
|
39
106
|
end
|
|
40
107
|
end
|
|
@@ -24,7 +24,7 @@ RSpec.describe "yeptris adapter error parity" do
|
|
|
24
24
|
nil
|
|
25
25
|
end
|
|
26
26
|
args = libs.flat_map { |l| ["-I", l] } + ["-e", probe]
|
|
27
|
-
Open3.capture2e(
|
|
27
|
+
Open3.capture2e(Gem.ruby, *args).first
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def yeptris_installed?
|
|
@@ -73,11 +73,28 @@ RSpec.describe "yeptris adapter error parity" do
|
|
|
73
73
|
# Installed is not enough: a binding/native desync (yeptris
|
|
74
74
|
# 0.6.34.2 x64-mingw-ucrt) leaves the gem resolvable while every
|
|
75
75
|
# parse raises. The parity contract only holds when the engines
|
|
76
|
-
# actually answer a probe — detection then selects them.
|
|
76
|
+
# actually answer a probe — detection then selects them. The probe
|
|
77
|
+
# runs in a subprocess: the suite deliberately never loads the
|
|
78
|
+
# optional yeptris engine in-process, so the adapter classes are
|
|
79
|
+
# not referenced here.
|
|
77
80
|
def yeptris_usable?
|
|
78
|
-
yeptris_installed? &&
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
yeptris_installed? && yeptris_native_available?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def yeptris_native_available?
|
|
85
|
+
libs = %w[lutaml-model yeptris moxml leptris].filter_map do |g|
|
|
86
|
+
"#{Gem::Specification.find_by_name(g).gem_dir}/lib"
|
|
87
|
+
rescue Gem::LoadError
|
|
88
|
+
nil
|
|
89
|
+
end
|
|
90
|
+
probe = <<~RUBY
|
|
91
|
+
require "lutaml/json/adapter/yeptris_adapter"
|
|
92
|
+
require "lutaml/yaml/adapter/yeptris_adapter"
|
|
93
|
+
exit(Lutaml::Json::Adapter::YeptrisAdapter.available? &&
|
|
94
|
+
Lutaml::Yaml::Adapter::YeptrisAdapter.available? ? 0 : 1)
|
|
95
|
+
RUBY
|
|
96
|
+
args = libs.flat_map { |l| ["-I", l] } + ["-e", probe]
|
|
97
|
+
Open3.capture2e(Gem.ruby, *args).last.success?
|
|
81
98
|
end
|
|
82
99
|
|
|
83
100
|
before { skip "yeptris is not usable on this platform" unless yeptris_usable? }
|
|
@@ -47,9 +47,8 @@ RSpec.describe Lutaml::Model::AdapterResolver, ".adapter_for yeptris native dete
|
|
|
47
47
|
it "resolves the yeptris lane when the native engine answers a probe" do
|
|
48
48
|
skip "optional yeptris engine not resolvable outside the bundle" unless subprocess_yeptris_capable?
|
|
49
49
|
|
|
50
|
-
stdout, stderr, status = Open3.capture3(
|
|
51
|
-
|
|
52
|
-
parse_probe)
|
|
50
|
+
stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-I", "lib",
|
|
51
|
+
"-e", parse_probe)
|
|
53
52
|
expect(status).to be_success, stderr
|
|
54
53
|
expect(stdout).to include("ADAPTER=YeptrisAdapter")
|
|
55
54
|
expect(stdout).to include("PARSED=scalar")
|
|
@@ -71,9 +70,8 @@ RSpec.describe Lutaml::Model::AdapterResolver, ".adapter_for yeptris native dete
|
|
|
71
70
|
#{parse_probe}
|
|
72
71
|
RUBY
|
|
73
72
|
|
|
74
|
-
stdout, stderr, status = Open3.capture3(
|
|
75
|
-
|
|
76
|
-
poison)
|
|
73
|
+
stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-I", "lib",
|
|
74
|
+
"-e", poison)
|
|
77
75
|
expect(status).to be_success, stderr
|
|
78
76
|
expect(stdout).to include("ADAPTER=StandardAdapter")
|
|
79
77
|
expect(stdout).to include("PARSED=scalar")
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module ConstructedNs1124
|
|
6
|
+
class WNs < Lutaml::Xml::Namespace
|
|
7
|
+
uri "http://example.com/wordprocessingml"
|
|
8
|
+
prefix_default "w"
|
|
9
|
+
element_form_default :qualified
|
|
10
|
+
attribute_form_default :qualified
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class MNs < Lutaml::Xml::Namespace
|
|
14
|
+
uri "http://example.com/mathml"
|
|
15
|
+
prefix_default "m"
|
|
16
|
+
element_form_default :qualified
|
|
17
|
+
attribute_form_default :qualified
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class MathRun < Lutaml::Model::Serializable
|
|
21
|
+
attribute :text, :string
|
|
22
|
+
|
|
23
|
+
xml do
|
|
24
|
+
element "r"
|
|
25
|
+
namespace MNs
|
|
26
|
+
map_element "t", to: :text
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class Para < Lutaml::Model::Serializable
|
|
31
|
+
attribute :runs, MathRun, collection: true
|
|
32
|
+
|
|
33
|
+
xml do
|
|
34
|
+
element "p"
|
|
35
|
+
namespace WNs
|
|
36
|
+
map_element "r", to: :runs
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Body < Lutaml::Model::Serializable
|
|
41
|
+
attribute :paras, Para, collection: true
|
|
42
|
+
|
|
43
|
+
xml do
|
|
44
|
+
element "body"
|
|
45
|
+
namespace WNs
|
|
46
|
+
map_element "p", to: :paras
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
RSpec.describe "constructed models serialize foreign namespaces prefixed" do
|
|
52
|
+
# lutaml-model#1124: a constructed (never-parsed) model must serialize
|
|
53
|
+
# child elements in foreign namespaces with their declared prefix,
|
|
54
|
+
# matching the parsed-and-reserialized form — not the default-namespace
|
|
55
|
+
# form. The wire-form signal is attribute qualification: namespaces
|
|
56
|
+
# with attribute_form_default :qualified produce inherently prefixed
|
|
57
|
+
# documents (w: attributes demand the prefix everywhere, root
|
|
58
|
+
# included), so both the w: root and the m: children spell prefixed
|
|
59
|
+
# on the constructed lane exactly as WordprocessingML parts do.
|
|
60
|
+
|
|
61
|
+
let(:register) { Lutaml::Model::Config.default_register }
|
|
62
|
+
|
|
63
|
+
around do |example|
|
|
64
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def build_body
|
|
68
|
+
ConstructedNs1124::Body.new(
|
|
69
|
+
paras: [ConstructedNs1124::Para.new(
|
|
70
|
+
runs: [ConstructedNs1124::MathRun.new(text: "x")],
|
|
71
|
+
)],
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "serializes the constructed model fully prefixed" do
|
|
76
|
+
xml = build_body.to_xml
|
|
77
|
+
|
|
78
|
+
expect(xml).to include("<w:body")
|
|
79
|
+
expect(xml).to include("<w:p>")
|
|
80
|
+
expect(xml).to include("<m:r")
|
|
81
|
+
expect(xml).not_to include("<body")
|
|
82
|
+
expect(xml).not_to include("<r>")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "round-trips constructed output to the identical form" do
|
|
86
|
+
xml = build_body.to_xml
|
|
87
|
+
reparsed = ConstructedNs1124::Body.from_xml(xml)
|
|
88
|
+
|
|
89
|
+
expect(reparsed.to_xml).to eq(xml)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "keeps the foreign-namespace child out of the parent's default form" do
|
|
93
|
+
xml = build_body.to_xml
|
|
94
|
+
|
|
95
|
+
expect(xml).not_to include('xmlns="http://example.com/mathml"')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "routes the multi-namespace unordered emission to the DOM lane" do
|
|
99
|
+
instance = build_body
|
|
100
|
+
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
101
|
+
ConstructedNs1124::Body, register
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
Lutaml::Xml::Leptris::NativeEmission.compatible?(
|
|
106
|
+
plan, instance, register
|
|
107
|
+
),
|
|
108
|
+
).to be(false)
|
|
109
|
+
end
|
|
110
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.171
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -181,6 +181,11 @@ files:
|
|
|
181
181
|
- RELEASE_NOTES.adoc
|
|
182
182
|
- Rakefile
|
|
183
183
|
- bench/baselines/.gitkeep
|
|
184
|
+
- bench/baselines/main_mml.json
|
|
185
|
+
- bench/baselines/main_niso.json
|
|
186
|
+
- bench/baselines/main_sts.json
|
|
187
|
+
- bench/baselines/main_unitsml.json
|
|
188
|
+
- bench/baselines/main_xmi.json
|
|
184
189
|
- bench/bench_all.rb
|
|
185
190
|
- bench/bench_alloc_audit.rb
|
|
186
191
|
- bench/bench_common.rb
|
|
@@ -786,6 +791,7 @@ files:
|
|
|
786
791
|
- lib/lutaml/xml/decisions/decision_rule.rb
|
|
787
792
|
- lib/lutaml/xml/decisions/element_prefix_resolver.rb
|
|
788
793
|
- lib/lutaml/xml/decisions/rules.rb
|
|
794
|
+
- lib/lutaml/xml/decisions/rules/attribute_qualified_prefix_rule.rb
|
|
789
795
|
- lib/lutaml/xml/decisions/rules/attribute_usage_rule.rb
|
|
790
796
|
- lib/lutaml/xml/decisions/rules/default_preference_rule.rb
|
|
791
797
|
- lib/lutaml/xml/decisions/rules/element_form_default_rule.rb
|
|
@@ -1995,6 +2001,7 @@ files:
|
|
|
1995
2001
|
- spec/lutaml/xml/compiled_rule_namespace_spec.rb
|
|
1996
2002
|
- spec/lutaml/xml/conformance/xml_namespaces_spec.rb
|
|
1997
2003
|
- spec/lutaml/xml/conformance/xml_schema_instance_spec.rb
|
|
2004
|
+
- spec/lutaml/xml/constructed_namespace_prefix_spec.rb
|
|
1998
2005
|
- spec/lutaml/xml/content_model_validation_spec.rb
|
|
1999
2006
|
- spec/lutaml/xml/cross_class_dispatch_spec.rb
|
|
2000
2007
|
- spec/lutaml/xml/cross_register_plan_spec.rb
|