lutaml-model 0.8.201 → 0.8.203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/dependent-tests.yml +59 -2
  4. data/.github/workflows/downstream-performance.yml +1 -22
  5. data/.github/workflows/performance.yml +1 -33
  6. data/.github/workflows/rake.yml +2 -6
  7. data/.rubocop.yml +0 -10
  8. data/.rubocop_todo.yml +0 -4
  9. data/Gemfile +0 -23
  10. data/README.adoc +25 -86
  11. data/Rakefile +2 -167
  12. data/docs/_guides/advanced-mapping.adoc +6 -6
  13. data/docs/_guides/character-encoding.adoc +0 -3
  14. data/docs/_guides/gem-integration.adoc +1 -1
  15. data/docs/_guides/index.adoc +0 -4
  16. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  17. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  18. data/docs/_guides/xml-namespaces.adoc +2 -3
  19. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  20. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  21. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  22. data/docs/_pages/comparison-with-shale.adoc +1 -1
  23. data/docs/_pages/configuration.adoc +6 -40
  24. data/docs/_pages/index.adoc +0 -1
  25. data/docs/_pages/serialization_adapters.adoc +4 -16
  26. data/docs/_references/architecture.adoc +1 -1
  27. data/docs/_references/lutaml-namespace-planning.md +1 -1
  28. data/docs/_references/plan-schema-spec.adoc +45 -18
  29. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  30. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  31. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  32. data/docs/architecture.md +7 -11
  33. data/docs/conversion_caching.adoc +1 -1
  34. data/docs/index.adoc +0 -1
  35. data/docs/key_value_data_model.adoc +1 -1
  36. data/docs/namespace-management.adoc +4 -10
  37. data/lib/lutaml/json/format.rb +0 -1
  38. data/lib/lutaml/json/generator_options.rb +0 -1
  39. data/lib/lutaml/key_value/transform.rb +149 -37
  40. data/lib/lutaml/lml/document_builder.rb +2 -2
  41. data/lib/lutaml/lml/entity_types.rb +2 -2
  42. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  43. data/lib/lutaml/model/attribute.rb +11 -6
  44. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  45. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  46. data/lib/lutaml/model/global_context.rb +3 -5
  47. data/lib/lutaml/model/instrumentation.rb +0 -3
  48. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  49. data/lib/lutaml/model/register.rb +20 -31
  50. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  51. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  52. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  53. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  54. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  55. data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
  56. data/lib/lutaml/model/serialize/initialization.rb +19 -9
  57. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  58. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  59. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  60. data/lib/lutaml/model/store.rb +10 -17
  61. data/lib/lutaml/model/toml.rb +0 -2
  62. data/lib/lutaml/model/transformation_registry.rb +3 -7
  63. data/lib/lutaml/model/version.rb +1 -1
  64. data/lib/lutaml/model.rb +3 -19
  65. data/lib/lutaml/toml/format.rb +4 -8
  66. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  67. data/lib/lutaml/xml/adapter.rb +0 -4
  68. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  69. data/lib/lutaml/xml/builder/base.rb +0 -3
  70. data/lib/lutaml/xml/builder.rb +0 -8
  71. data/lib/lutaml/xml/data_model.rb +1 -1
  72. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  73. data/lib/lutaml/xml/format.rb +22 -74
  74. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  75. data/lib/lutaml/xml/model_transform.rb +14 -24
  76. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  77. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  78. data/lib/lutaml/xml/schema/builder.rb +6 -9
  79. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  80. data/lib/lutaml/xml/xml_element.rb +3 -2
  81. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  82. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  83. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  84. data/lib/tasks/performance_comparator.rb +1 -1
  85. data/lutaml-model.gemspec +3 -8
  86. data/spec/address_person_spec.rb +8 -0
  87. data/spec/address_spec.rb +4 -0
  88. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  89. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  90. data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
  91. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  92. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  93. data/spec/lutaml/model/cdata_spec.rb +2 -15
  94. data/spec/lutaml/model/encoding_spec.rb +0 -9
  95. data/spec/lutaml/model/except_spec.rb +0 -7
  96. data/spec/lutaml/model/json_spec.rb +0 -14
  97. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  98. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  99. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  100. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  101. data/spec/lutaml/model/serializable_spec.rb +0 -2
  102. data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
  103. data/spec/lutaml/model/toml_spec.rb +0 -23
  104. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  105. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  106. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  107. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  108. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  109. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  110. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  111. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  112. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  113. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  114. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  115. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  116. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  117. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  118. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  119. data/spec/lutaml/xml/xml_spec.rb +2 -88
  120. data/spec/spec_helper.rb +8 -28
  121. data/spec/support/test_adapter_config.rb +6 -6
  122. metadata +2 -32
  123. data/.github/workflows/js-pr-check.yml +0 -106
  124. data/.github/workflows/js-sync.yml +0 -55
  125. data/.github/workflows/opal.yml +0 -65
  126. data/.gitmodules +0 -6
  127. data/.rspec-opal +0 -5
  128. data/docs/_guides/opal.adoc +0 -232
  129. data/lib/compat/opal/generate_boot.rb +0 -137
  130. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  131. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  132. data/lib/compat/opal/monitor.rb +0 -31
  133. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  134. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  135. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  136. data/lib/compat/opal/moxml_boot.rb +0 -68
  137. data/lib/compat/opal/objectspace_shim.rb +0 -23
  138. data/lib/compat/opal/rexml/namespace.rb +0 -59
  139. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  140. data/lib/compat/opal/rexml/source.rb +0 -214
  141. data/lib/compat/opal/rexml/text.rb +0 -426
  142. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  143. data/lib/compat/opal/rexml_compat.rb +0 -85
  144. data/lib/compat/opal/yaml_compat.rb +0 -32
  145. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  146. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  147. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  148. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  149. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  150. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  151. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  152. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  153. data/spec/support/opal.rb +0 -9
@@ -1,232 +0,0 @@
1
- ---
2
- title: Opal Usage Guide
3
- parent: Guides
4
- nav_order: 99
5
- ---
6
-
7
- = Opal Usage Guide
8
-
9
- :toc:
10
- :toclevels: 3
11
-
12
- == Overview
13
-
14
- [IMPORTANT]
15
- ====
16
- Opal support in lutaml-model is **deprecated**. The Opal boot lane, its
17
- compat shims, and the vendored Opal forks remain functional in the 0.8
18
- line but receive maintenance-only attention, and removal is planned for
19
- a future release. New JavaScript-targeted work is directed at the
20
- moxml-ts wasm binding instead.
21
- ====
22
-
23
-
24
-
25
- https://opalrb.com[Opal] is a Ruby-to-JavaScript compiler that allows Ruby code to run in the browser. Lutaml::Model supports running under Opal, enabling XML/JSON/YAML serialization in client-side applications.
26
-
27
- The XML parsing layer is provided by the https://github.com/lutaml/moxml[moxml] gem (v0.2+), which detects the Opal runtime and uses the REXML adapter automatically.
28
-
29
- == How it works
30
-
31
- Opal compiles Ruby source code to JavaScript. Under Opal:
32
-
33
- . `RUBY_ENGINE` equals `"opal"`
34
- . `Lutaml::Model::RuntimeCompatibility.opal?` returns `true`
35
- . Adapter selection is adjusted automatically
36
- . Gems with C extensions (Nokogiri, Ox, Oj, tomlib) are not available
37
- . REXML is used for XML because Opal reimplements `strscan` and `stringio` in its stdlib, enabling REXML (pure Ruby) to compile cleanly to JavaScript
38
-
39
- No configuration is needed -- the runtime is detected and adapters are selected automatically.
40
-
41
- == Supported features
42
-
43
- === Fully supported
44
-
45
- * Model definition with `attribute`, types, collections, defaults
46
- * XML serialization/deserialization (via REXML adapter)
47
- ** Element and attribute mapping
48
- ** Nested elements and collections
49
- ** Mixed content
50
- ** Namespaces (parsing and serialization)
51
- ** CDATA sections
52
- ** Processing instructions
53
- ** Comments
54
- ** Entity references
55
- ** XML declarations and doctypes
56
- * JSON serialization/deserialization (via standard adapter)
57
- * YAML serialization/deserialization (via standard adapter)
58
- * Hash transformation
59
- * Custom types
60
- * Model import (`import_model`)
61
- * Value transformations
62
-
63
- === Not available
64
-
65
- [cols="1,3",options="header"]
66
- |===
67
- | Feature | Reason
68
- | XSD schema generation | Requires Nokogiri
69
- | RELAX NG generation | Requires Nokogiri
70
- | XML schema compilation | Requires Nokogiri + native parsing
71
- | TOML serialization | Both tomlib and toml-rb require native extensions
72
- | Oj / MultiJson adapters | Require native extensions
73
- | Ox / Nokogiri / Oga adapters | Require native extensions or C extensions
74
- | XPath queries | REXML XPath requires features not yet in Opal's stdlib
75
- | Liquid templating | Uses file-system-based template loading (Phase 1: skipped)
76
- | Canon XML equivalence | Uses Nokogiri for XML parsing
77
- |===
78
-
79
- == Setup
80
-
81
- === Gemfile
82
-
83
- Add Opal gems to your Gemfile:
84
-
85
- [source,ruby]
86
- ----
87
- gem "lutaml-model"
88
-
89
- group :opal do
90
- gem "opal", "~> 1.8"
91
- gem "opal-rspec", "~> 1.0"
92
- gem "opal-sprockets"
93
- end
94
- ----
95
-
96
- === Rake task
97
-
98
- Add an Opal RSpec task to your Rakefile:
99
-
100
- [source,ruby]
101
- ----
102
- begin
103
- require "opal/rspec/rake_task"
104
- rescue LoadError
105
- # Opal not available
106
- end
107
-
108
- namespace :spec do
109
- if defined?(Opal::RSpec::RakeTask)
110
- desc "Run Opal (JavaScript) tests"
111
- Opal::RSpec::RakeTask.new(:opal) do |server, runner|
112
- server.append_path "lib"
113
- runner.default_path = "spec"
114
- runner.pattern = "spec/**/*_spec.{rb,opal}"
115
- end
116
- end
117
- end
118
- ----
119
-
120
- === Test configuration
121
-
122
- Create `spec/support/opal.rb` for Opal-specific test patches:
123
-
124
- [source,ruby]
125
- ----
126
- # frozen_string_literal: true
127
-
128
- if RUBY_ENGINE == "opal"
129
- Lutaml::Model::Config.xml_adapter_type = :rexml
130
- end
131
- ----
132
-
133
- Create `.rspec-opal`:
134
-
135
- ----
136
- --default-path=spec
137
- --pattern='spec/**/*_spec.{rb,opal}'
138
- -I lib
139
- --opal-opt=-g,lutaml-model
140
- -I spec
141
- --require=spec_helper
142
- --require=support/opal
143
- ----
144
-
145
- === CI workflow
146
-
147
- Add `.github/workflows/opal.yml`:
148
-
149
- [source,yaml]
150
- ----
151
- name: opal
152
- on:
153
- push:
154
- branches: [main]
155
- pull_request:
156
-
157
- jobs:
158
- test:
159
- runs-on: ubuntu-latest
160
- steps:
161
- - uses: actions/checkout@v4
162
- with:
163
- submodules: "recursive"
164
- - uses: ruby/setup-ruby@v1
165
- with:
166
- ruby-version: "3.3"
167
- bundler-cache: true
168
- - uses: actions/setup-node@v4
169
- with:
170
- node-version: "18"
171
- - name: Run Opal tests
172
- run: bundle exec rake spec:opal
173
- ----
174
-
175
- == Example: XML round-trip in the browser
176
-
177
- [source,ruby]
178
- ----
179
- class Person
180
- include Lutaml::Model::Serialize
181
-
182
- attribute :name, :string
183
- attribute :age, :integer
184
-
185
- xml do
186
- element "person"
187
- map_element "name", to: :name
188
- map_element "age", to: :age
189
- end
190
- end
191
-
192
- # Parse XML
193
- person = Person.from_xml('<person><name>Alice</name><age>30</age></person>')
194
- person.name # => "Alice"
195
- person.age # => 30
196
-
197
- # Serialize to XML
198
- person.to_xml # => "<person><name>Alice</name><age>30</age></person>"
199
-
200
- # JSON and YAML also work
201
- person.to_json # => '{"name":"Alice","age":30}'
202
- person.to_yaml # => "---\nname: Alice\nage: 30\n"
203
- ----
204
-
205
- == Architecture
206
-
207
- Under Opal, the library uses a JRuby-like pattern for dependency management:
208
-
209
- . *Dependencies stay in the gemspec.* Gems like Nokogiri, Ox, and Oga remain listed as dependencies -- they are simply not loadable under Opal.
210
- . *Requires are guarded with `RUBY_ENGINE`.* Code that depends on native gems uses `RUBY_ENGINE == "opal"` checks instead of silent `rescue LoadError`.
211
- . *No gem splitting.* The same gem works on both MRI and Opal.
212
-
213
- Key components:
214
- * `Lutaml::Model::RuntimeCompatibility` -- detects the runtime (opal, windows, native)
215
- * `Lutaml::Model::AdapterResolver` -- selects adapters based on runtime capabilities
216
- * `Moxml::Config::OPAL_DEFAULT_ADAPTER` -- set to `:rexml`
217
- * `Moxml::Adapter::OPAL_AVAILABLE_ADAPTERS` -- set to `%i[rexml]`
218
-
219
- == Dependencies
220
-
221
- The following gems in the lutaml ecosystem support Opal:
222
-
223
- * **lutaml-model** -- Core model library (this gem)
224
- * **moxml** (v0.2+) -- XML parsing abstraction with REXML adapter for Opal
225
- * **canon** -- XML comparison (uses moxml under Opal; comparison features work but Nokogiri-specific features do not)
226
-
227
- == Limitations
228
-
229
- * **No XPath** -- REXML's XPath module has dependencies not yet reimplemented in Opal's stdlib.
230
- * **No schema generation** -- XSD, RELAX NG generation, and schema compilation require Nokogiri.
231
- * **No TOML** -- Both TOML adapters (tomlib, toml-rb) require native extensions.
232
- * **No Liquid** -- Template rendering via Liquid is skipped in Opal (file-system dependency). May be addressed in a future phase using liquidjs via Opal's JavaScript bridge.
@@ -1,137 +0,0 @@
1
- # frozen_string: true
2
-
3
- # One-shot generator for lib/compat/opal/lutaml_model_boot.rb.
4
- #
5
- # Walks lib/lutaml/**/*.rb and extracts every `autoload :Name, "path"`
6
- # declaration (single-line or multi-line), resolving the standard
7
- # `"#{__dir__}/..."` and `"#{File.dirname(__FILE__)}/..."` interpolation
8
- # patterns relative to the declaring file's directory.
9
- #
10
- # Opal treats autoload as a no-op, so every autoload target must appear
11
- # here as an explicit `require` for nested constants to resolve at runtime.
12
- #
13
- # Run after adding/removing any autoload in lib/lutaml/:
14
- # ruby lib/compat/opal/generate_boot.rb
15
-
16
- require "pathname"
17
-
18
- REPO_ROOT = Pathname.new(File.expand_path("../../..", __dir__))
19
- LIB = REPO_ROOT.join("lib")
20
-
21
- # Patterns excluded under Opal because they pull in native-only deps
22
- # (Nokogiri/Ox C extensions, Thor CLI, etc.). The one XML adapter
23
- # (moxml_adapter) resolves engine classes through LAZY requires, so it
24
- # is boot-safe. REXML is pure Ruby and ships in the bundled gem +
25
- # moxml's lib/compat/opal/rexml/* shadows, so it is NOT excluded — it
26
- # is a fully working second Opal adapter.
27
- NATIVE_ONLY_PATTERNS = [
28
- %r{/schema/(relaxng|xsd)\b},
29
- %r{/schema_builder/(nokogiri|oga)\b},
30
- %r{/schema/builder/(nokogiri|oga)\b},
31
- %r{\Alutaml/model/cli\z},
32
- # leptris is an FFI wrapper over a native library — Opal::Builder dies
33
- # on its requires (and FFI itself does not exist under Opal); the
34
- # adapter probe degrades to moxml at runtime (#1008).
35
- %r{\Alutaml/xml/leptris},
36
- # The CSV adapter pulls the csv bundled stdlib gem, which has no Opal
37
- # build; CSV instance import/export is not part of the Opal surface
38
- # (Executor's CsvAdapter autoload never fires under Opal either).
39
- %r{\Alutaml/lml/executor/csv_adapter\z},
40
- ].freeze
41
-
42
- # Match `autoload :Name, "...anything..."` where the string argument may
43
- # span multiple physical lines (whitespace after the comma).
44
- DECL_RE = /autoload\s+:[A-Za-z0-9_]+\s*,\s*"([^"]+)"/
45
-
46
- # Stitches multi-line autoload declarations into a single logical line so
47
- # DECL_RE can match. We only merge when the line ends right after the
48
- # comma that follows `autoload :Name`.
49
- def join_multiline_autoloads(src)
50
- src.gsub(/(autoload\s+:[A-Za-z0-9_]+\s*,)\s*\n\s*/) do
51
- "#{Regexp.last_match(1)} "
52
- end
53
- end
54
-
55
- # Resolve an autoload's raw string argument to a require path relative to
56
- # LIB. Both common interpolation shapes resolve relative to the declaring
57
- # file's directory, which is what MRI does for them.
58
- def resolve_path(raw, declaring_file)
59
- declaring_dir = Pathname.new(declaring_file).dirname
60
-
61
- if raw.start_with?("\#{__dir__}/")
62
- subdir = raw.sub("\#{__dir__}/", "").delete_suffix(".rb")
63
- (declaring_dir + subdir).relative_path_from(LIB).to_s.delete_suffix(".rb")
64
- elsif raw.start_with?("\#{File.dirname(__FILE__)}/")
65
- subdir = raw.sub("\#{File.dirname(__FILE__)}/", "").delete_suffix(".rb")
66
- (declaring_dir + subdir).relative_path_from(LIB).to_s.delete_suffix(".rb")
67
- elsif raw.start_with?("lutaml/")
68
- raw.delete_suffix(".rb")
69
- else
70
- raw.delete_suffix(".rb")
71
- end
72
- end
73
-
74
- paths = []
75
- Dir.glob("#{LIB}/lutaml/**/*.rb").each do |file|
76
- src = File.read(file)
77
- # Strip full-line and trailing comments so commented-out autoload
78
- # examples (e.g. in type_registry.rb) don't end up in the boot file.
79
- src = src.lines.reject { |line| line.lstrip.start_with?("#") }.join
80
- join_multiline_autoloads(src).scan(DECL_RE).each do |(raw)|
81
- paths << resolve_path(raw, file)
82
- end
83
- end
84
-
85
- paths = paths.uniq.sort
86
- native_only = paths.select { |p| NATIVE_ONLY_PATTERNS.any? { |re| p =~ re } }
87
- opal_paths = paths - native_only
88
-
89
- # Order matters: namespace-defining entry files must load before any of
90
- # their nested files. lutaml/model.rb declares the Lutaml::Model module
91
- # (referenced by every other file); lutaml/xml.rb declares Lutaml::Xml.
92
- # After the entry files, load by depth-then-name so a parent file (e.g.
93
- # lutaml/hash_format.rb) is required before its children (e.g.
94
- # lutaml/hash_format/adapter/document.rb).
95
- #
96
- # ENTRY_FILES are added unconditionally: they are top-level entry points
97
- # that nothing else autoloads (because they ARE the entry points users
98
- # require directly), so they would otherwise be missing from the list.
99
- # lutaml/lml defines Lutaml::Lml and its error hierarchy — the lutaml/lml/*
100
- # files open the namespace, but the entry file itself is only ever
101
- # user-required, so it must be pinned here.
102
- ENTRY_FILES = %w[lutaml/model lutaml/xml lutaml/lml].freeze
103
- remaining = (opal_paths - ENTRY_FILES).sort_by { |p| [p.count("/"), p] }
104
- ordered = ENTRY_FILES + remaining
105
-
106
- out = []
107
- out << "# frozen_string_literal: true"
108
- out << ""
109
- out << "# DO NOT EDIT — regenerate with:"
110
- out << "# ruby lib/compat/opal/generate_boot.rb"
111
- out << "#"
112
- out << "# Opal does not support Ruby autoload (it is a no-op at parse time)."
113
- out << "# This file explicitly requires every autoload target in lib/lutaml/**"
114
- out << "# so that nested constants resolve at runtime under Opal."
115
- out << "#"
116
- out << "# Native-only paths excluded under Opal:"
117
- out << "# - nokogiri/ox/rexml adapters (C extensions unavailable)"
118
- out << "# - XSD / RELAX NG schema generators (require Nokogiri)"
119
- out << "# - lutaml/model/cli (thor-based, runtime-irrelevant under Opal)"
120
- out << "#"
121
- out << "# Ordering: lutaml/model, lutaml/xml and lutaml/lml define the"
122
- out << "# Lutaml::Model, Lutaml::Xml and Lutaml::Lml namespaces, so they load"
123
- out << "# first. Remaining paths are ordered by depth (shallower first) so"
124
- out << "# parent files declare their child namespaces before children load."
125
- out << "#"
126
- out << "# Loaded by the Opal Rakefile before spec_helper."
127
- out << ""
128
- ordered.each { |p| out << %(require "#{p}") }
129
- out << ""
130
-
131
- # OPAL_BOOT_OUTPUT lets the in-sync guard spec regenerate to a temp path
132
- # without clobbering the committed manifest; unset, it writes canonically.
133
- target = ENV.fetch("OPAL_BOOT_OUTPUT") do
134
- File.expand_path("lutaml_model_boot.rb", __dir__)
135
- end
136
- File.write(target, out.join("\n"))
137
- warn "Generated #{ordered.size} requires (excluded #{native_only.size} native-only paths) -> #{target}"
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # JS bundle entry point. Pulls in the Opal-only compat shims and boot
4
- # files BEFORE lutaml/model so that moxml's adapter constants, the
5
- # String/Encoding/YAML/Array#pack patches, and the eager-loaded
6
- # Moxml::* / Lutaml::* constants are all in place by the time
7
- # lib/lutaml/model.rb runs.
8
- #
9
- # Used by scripts/build.rb as the bundle ENTRY (instead of
10
- # "lutaml/model" directly) so the JS bundle mirrors the load order
11
- # that lutaml-model's Rakefile applies for `rake spec:opal`.
12
-
13
- if RUBY_ENGINE == "opal"
14
- # 0. runtime_compatibility first: it stubs Mutex/ConditionVariable/
15
- # Thread/WeakRef and patches Module#prepend for Opal. Oga's LRU
16
- # and other gems reference Mutex at file-load time, so this must
17
- # run before any gem that touches thread-safety primitives.
18
- require "lutaml/model/runtime_compatibility"
19
-
20
- # 0a. Opal's stdlib StringIO < IO loads here so moxml's
21
- # `class StringIO` (bare, no parent) in rexml_compat.rb re-opens
22
- # the existing class instead of conflicting with `< ::IO`.
23
- # Without this, the bare-class definition runs first and Opal's
24
- # `< IO` definition later raises "superclass mismatch".
25
- require "stringio"
26
-
27
- # 1. stdlib shims: String/Encoding/StringIO + Array#pack + nodejs/yaml
28
- require "rexml_compat"
29
- require "yaml_compat"
30
-
31
- # 2. forks' Opal-aware conditionals select the pure-Ruby lexer
32
- require "oga"
33
- require "ll/setup"
34
-
35
- # 3. eager-load boots (Opal ignores autoload)
36
- require "moxml_boot"
37
- require "lutaml_model_boot"
38
- end
39
-
40
- # 4. the actual entry point
41
- require "lutaml/model"
42
- require "lutaml/xml"