lutaml-model 0.8.201 → 0.8.202

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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/downstream-performance.yml +1 -22
  4. data/.github/workflows/performance.yml +1 -33
  5. data/.github/workflows/rake.yml +2 -6
  6. data/.rubocop.yml +0 -10
  7. data/.rubocop_todo.yml +0 -4
  8. data/Gemfile +0 -23
  9. data/README.adoc +25 -86
  10. data/Rakefile +2 -167
  11. data/docs/_guides/advanced-mapping.adoc +6 -6
  12. data/docs/_guides/character-encoding.adoc +0 -3
  13. data/docs/_guides/gem-integration.adoc +1 -1
  14. data/docs/_guides/index.adoc +0 -4
  15. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  16. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  17. data/docs/_guides/xml-namespaces.adoc +2 -3
  18. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  19. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  20. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  21. data/docs/_pages/comparison-with-shale.adoc +1 -1
  22. data/docs/_pages/configuration.adoc +6 -40
  23. data/docs/_pages/index.adoc +0 -1
  24. data/docs/_pages/serialization_adapters.adoc +4 -16
  25. data/docs/_references/architecture.adoc +1 -1
  26. data/docs/_references/lutaml-namespace-planning.md +1 -1
  27. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  28. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  29. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  30. data/docs/architecture.md +7 -11
  31. data/docs/conversion_caching.adoc +1 -1
  32. data/docs/index.adoc +0 -1
  33. data/docs/key_value_data_model.adoc +1 -1
  34. data/docs/namespace-management.adoc +4 -10
  35. data/lib/lutaml/json/format.rb +0 -1
  36. data/lib/lutaml/json/generator_options.rb +0 -1
  37. data/lib/lutaml/key_value/transform.rb +9 -16
  38. data/lib/lutaml/lml/document_builder.rb +2 -2
  39. data/lib/lutaml/lml/entity_types.rb +2 -2
  40. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  41. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  42. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  43. data/lib/lutaml/model/global_context.rb +3 -5
  44. data/lib/lutaml/model/instrumentation.rb +0 -3
  45. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  46. data/lib/lutaml/model/register.rb +20 -31
  47. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  48. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  49. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  50. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  51. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  52. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  53. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  54. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  55. data/lib/lutaml/model/store.rb +10 -17
  56. data/lib/lutaml/model/toml.rb +0 -2
  57. data/lib/lutaml/model/transformation_registry.rb +3 -7
  58. data/lib/lutaml/model/version.rb +1 -1
  59. data/lib/lutaml/model.rb +3 -19
  60. data/lib/lutaml/toml/format.rb +4 -8
  61. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  62. data/lib/lutaml/xml/adapter.rb +0 -4
  63. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  64. data/lib/lutaml/xml/builder/base.rb +0 -3
  65. data/lib/lutaml/xml/builder.rb +0 -8
  66. data/lib/lutaml/xml/data_model.rb +1 -1
  67. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  68. data/lib/lutaml/xml/format.rb +22 -74
  69. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  70. data/lib/lutaml/xml/model_transform.rb +14 -24
  71. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  72. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  73. data/lib/lutaml/xml/schema/builder.rb +6 -9
  74. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  75. data/lib/lutaml/xml/xml_element.rb +3 -2
  76. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  77. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  78. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  79. data/lib/tasks/performance_comparator.rb +1 -1
  80. data/lutaml-model.gemspec +3 -8
  81. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  82. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  83. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  84. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  85. data/spec/lutaml/model/cdata_spec.rb +2 -15
  86. data/spec/lutaml/model/encoding_spec.rb +0 -9
  87. data/spec/lutaml/model/except_spec.rb +0 -7
  88. data/spec/lutaml/model/json_spec.rb +0 -14
  89. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  90. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  91. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  92. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  93. data/spec/lutaml/model/serializable_spec.rb +0 -2
  94. data/spec/lutaml/model/toml_spec.rb +0 -23
  95. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  96. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  97. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  98. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  99. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  100. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  101. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  102. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  103. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  104. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  105. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  106. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  107. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  108. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  109. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  110. data/spec/lutaml/xml/xml_spec.rb +2 -88
  111. data/spec/spec_helper.rb +5 -24
  112. data/spec/support/test_adapter_config.rb +6 -6
  113. metadata +1 -32
  114. data/.github/workflows/js-pr-check.yml +0 -106
  115. data/.github/workflows/js-sync.yml +0 -55
  116. data/.github/workflows/opal.yml +0 -65
  117. data/.gitmodules +0 -6
  118. data/.rspec-opal +0 -5
  119. data/docs/_guides/opal.adoc +0 -232
  120. data/lib/compat/opal/generate_boot.rb +0 -137
  121. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  122. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  123. data/lib/compat/opal/monitor.rb +0 -31
  124. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  125. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  126. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  127. data/lib/compat/opal/moxml_boot.rb +0 -68
  128. data/lib/compat/opal/objectspace_shim.rb +0 -23
  129. data/lib/compat/opal/rexml/namespace.rb +0 -59
  130. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  131. data/lib/compat/opal/rexml/source.rb +0 -214
  132. data/lib/compat/opal/rexml/text.rb +0 -426
  133. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  134. data/lib/compat/opal/rexml_compat.rb +0 -85
  135. data/lib/compat/opal/yaml_compat.rb +0 -32
  136. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  137. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  138. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  139. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  140. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  141. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  142. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  143. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  144. data/spec/support/opal.rb +0 -9
@@ -1,106 +0,0 @@
1
- name: js-pr-check
2
-
3
- # On PRs that touch lib/, Gemfile, Rakefile, or .gitmodules, fire a
4
- # repository_dispatch at lutaml-model-js so it builds a test artifact
5
- # and runs the JS smoke tests against the PR head. Does NOT publish.
6
- # Catches JS regressions before the Ruby PR merges.
7
- #
8
- # PAT token: LUTAML_CI_PAT_TOKEN must have `repo` scope on
9
- # lutaml/lutaml-model-js. Note that PRs from forks of lutaml/lutaml-model
10
- # will not have access to the PAT (GitHub masks secrets on fork PRs);
11
- # those builds will be skipped — contributors from forks should run
12
- # `gh workflow run js-pr-check` manually after pushing to a branch on
13
- # the origin repo.
14
-
15
- on:
16
- pull_request:
17
- paths:
18
- - 'lib/**'
19
- - 'Gemfile'
20
- - 'gemspec'
21
- - 'Rakefile'
22
- - '.gitmodules'
23
- - '.github/workflows/js-pr-check.yml'
24
- workflow_dispatch:
25
- inputs:
26
- pr_number:
27
- description: PR number to test (for manual reruns).
28
- required: true
29
-
30
- permissions:
31
- contents: read
32
- pull-requests: write
33
-
34
- concurrency:
35
- group: js-pr-check-${{ github.ref }}
36
- cancel-in-progress: true
37
-
38
- jobs:
39
- trigger:
40
- runs-on: ubuntu-latest
41
- if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'lutaml/lutaml-model' }}
42
- steps:
43
- - uses: actions/checkout@v6
44
- with:
45
- # Need the PR head, not the merge commit, so the SHA the JS
46
- # build pulls matches what reviewers see.
47
- ref: ${{ github.event.pull_request.head.sha || github.sha }}
48
- fetch-depth: 0
49
-
50
- - name: Resolve PR inputs
51
- id: pr
52
- uses: actions/github-script@v7
53
- with:
54
- script: |
55
- const prNumber = context.payload.inputs?.pr_number
56
- ? parseInt(context.payload.inputs.pr_number, 10)
57
- : context.payload.pull_request?.number;
58
- if (!prNumber) {
59
- core.setFailed("No PR number available");
60
- return;
61
- }
62
- const { data: pr } = await github.rest.pulls.get({
63
- owner: context.repo.owner,
64
- repo: context.repo.repo,
65
- pull_number: prNumber,
66
- });
67
- core.setOutput("number", String(prNumber));
68
- core.setOutput("sha", pr.head.sha);
69
- core.setOutput("ref", pr.head.ref);
70
- core.setOutput("repo", pr.head.repo.full_name);
71
-
72
- - name: Notify lutaml-model-js
73
- uses: peter-evans/repository-dispatch@v3
74
- with:
75
- token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
76
- repository: lutaml/lutaml-model-js
77
- event-type: js-pr-check
78
- client-payload: |-
79
- {
80
- "pr_number": ${{ steps.pr.outputs.number }},
81
- "sha": "${{ steps.pr.outputs.sha }}",
82
- "ref": "${{ steps.pr.outputs.ref }}",
83
- "repo": "${{ steps.pr.outputs.repo }}"
84
- }
85
-
86
- - name: Annotate PR with build link
87
- if: ${{ github.event_name == 'pull_request' }}
88
- uses: actions/github-script@v7
89
- with:
90
- script: |
91
- const body = [
92
- "### JS build check",
93
- "",
94
- "Triggered [`js-pr-check`]",
95
- `(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)`,
96
- "against this PR's head (`" + context.payload.pull_request.head.sha.substring(0, 7) + "`).",
97
- "",
98
- "The result will appear as a `lutaml-model-js / pr-check` status check",
99
- "on this PR once the workflow run completes.",
100
- ].join("\n");
101
- await github.rest.issues.createComment({
102
- owner: context.repo.owner,
103
- repo: context.repo.repo,
104
- issue_number: context.payload.pull_request.number,
105
- body,
106
- });
@@ -1,55 +0,0 @@
1
- name: js-sync
2
-
3
- # On every push to main, fire a repository_dispatch at lutaml-model-js
4
- # so it rebuilds and publishes under the npm `next` dist-tag. This
5
- # closes the dev-build gap: JS consumers can track Ruby main without
6
- # waiting for a stable gem release.
7
- #
8
- # PAT token: LUTAML_CI_PAT_TOKEN must have `repo` scope on
9
- # lutaml/lutaml-model-js. Same token already used by release.yml.
10
-
11
- on:
12
- push:
13
- branches: [main]
14
- workflow_dispatch:
15
- inputs:
16
- sha:
17
- description: Specific SHA to build from (defaults to HEAD on main).
18
- required: false
19
-
20
- permissions:
21
- contents: read
22
-
23
- concurrency:
24
- group: js-sync-${{ github.ref }}
25
- cancel-in-progress: true
26
-
27
- jobs:
28
- trigger:
29
- runs-on: ubuntu-latest
30
- steps:
31
- - uses: actions/checkout@v6
32
- with:
33
- fetch-depth: 0
34
-
35
- - name: Resolve SHA
36
- id: sha
37
- run: |
38
- if [ -n "${{ github.event.inputs.sha }}" ]; then
39
- echo "sha=${{ github.event.inputs.sha }}" >> "$GITHUB_OUTPUT"
40
- else
41
- echo "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
42
- fi
43
-
44
- - name: Notify lutaml-model-js
45
- uses: peter-evans/repository-dispatch@v3
46
- with:
47
- token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
48
- repository: lutaml/lutaml-model-js
49
- event-type: js-sync-main
50
- client-payload: |-
51
- {
52
- "sha": "${{ steps.sha.outputs.sha }}",
53
- "ref": "${{ github.ref }}",
54
- "ruby_ref": "main"
55
- }
@@ -1,65 +0,0 @@
1
- # DEPRECATED: the Opal lane is on the deprecation path (the moxml-ts
2
- # wasm binding is the JavaScript endgame). The lane stays green — the
3
- # boot repair chain lives in lib/compat/opal — but it is
4
- # maintenance-only and non-gating; removal is planned for a future
5
- # release.
6
- name: opal
7
-
8
- on:
9
- push:
10
- branches: [main]
11
- tags: [ v* ]
12
- pull_request:
13
-
14
- permissions:
15
- contents: read
16
-
17
- concurrency:
18
- group: opal-${{ github.ref }}
19
- cancel-in-progress: true
20
-
21
- jobs:
22
- test:
23
- runs-on: ubuntu-latest
24
- env:
25
- # The Opal leg is the ONLY consumer of the vendored
26
- # Opal-compatibility forks (#835 step 2): MRI legs run released
27
- # oga/ruby-ll.
28
- LUTAML_OPAL_FORKS: "1"
29
- steps:
30
- - uses: actions/checkout@v6
31
- with:
32
- submodules: "recursive"
33
-
34
- - name: Set up Ruby
35
- uses: ruby/setup-ruby@v1
36
- with:
37
- ruby-version: "3.4"
38
- # bundler-cache disabled: the path-source oga and ruby-ll forks
39
- # need ragel + ruby-ll outputs generated (rake vendor:prepare)
40
- # before their C extensions can compile.
41
- bundler-cache: false
42
-
43
- - name: Set up Node.js
44
- uses: actions/setup-node@v4
45
- with:
46
- node-version: "18"
47
-
48
- - name: Install ragel
49
- run: sudo apt-get update && sudo apt-get install -y ragel
50
-
51
- - name: Install ruby-ll (for rake vendor:prepare)
52
- run: gem install ruby-ll --no-document
53
-
54
- - name: Generate ragel / ruby-ll outputs in vendored forks
55
- # Run before bundle install: the path-source oga/ruby-ll forks
56
- # gitignore their generated .rb/.c files. bundle install compiles
57
- # the C extensions via each fork's extconf.rb, which needs
58
- # ext/c/lexer.c to exist.
59
- run: rake vendor:prepare
60
-
61
- - name: Install dependencies
62
- run: bundle install
63
-
64
- - name: Run Opal tests
65
- run: bundle exec rake spec:opal
data/.gitmodules DELETED
@@ -1,6 +0,0 @@
1
- [submodule "vendor/opal-oga"]
2
- path = vendor/opal-oga
3
- url = https://github.com/lutaml/opal-oga.git
4
- [submodule "vendor/opal-ruby-ll"]
5
- path = vendor/opal-ruby-ll
6
- url = https://github.com/lutaml/opal-ruby-ll.git
data/.rspec-opal DELETED
@@ -1,5 +0,0 @@
1
- --default-path=spec
2
- --pattern='spec/lutaml/model/opal_smoke_spec.rb,spec/lutaml/xml/opal_xml_spec.rb'
3
- -I lib
4
- --require=spec_helper
5
- --require=support/opal
@@ -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"