lutaml-model 0.8.187 → 0.8.189

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 (310) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-repos-tools-informational.json +8 -0
  3. data/.github/workflows/dependent-repos-tools.json +1 -5
  4. data/.github/workflows/dependent-tests.yml +26 -2
  5. data/Gemfile +2 -0
  6. data/Rakefile +6 -0
  7. data/exe/lutaml-lml-lsp +11 -0
  8. data/lib/compat/opal/generate_boot.rb +12 -5
  9. data/lib/compat/opal/lutaml_model_boot.rb +96 -4
  10. data/lib/lutaml/key_value/adapter/hash/standard_adapter.rb +12 -0
  11. data/lib/lutaml/lml/association_label_resolver.rb +52 -0
  12. data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
  13. data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
  14. data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
  15. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
  16. data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
  17. data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
  18. data/lib/lutaml/lml/data_processor.rb +66 -0
  19. data/lib/lutaml/lml/diagnostic.rb +149 -0
  20. data/lib/lutaml/lml/document_builder.rb +486 -0
  21. data/lib/lutaml/lml/entity_types.rb +31 -0
  22. data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
  23. data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
  24. data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
  25. data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
  26. data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
  27. data/lib/lutaml/lml/executor.rb +96 -0
  28. data/lib/lutaml/lml/format/adapter/document.rb +11 -0
  29. data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
  30. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
  31. data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
  32. data/lib/lutaml/lml/format.rb +34 -0
  33. data/lib/lutaml/lml/formatter/base.rb +81 -0
  34. data/lib/lutaml/lml/formatter/canonical.rb +738 -0
  35. data/lib/lutaml/lml/formatter.rb +11 -0
  36. data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
  37. data/lib/lutaml/lml/grammar/lml.parg +389 -0
  38. data/lib/lutaml/lml/grammar.rb +60 -0
  39. data/lib/lutaml/lml/has_attributes.rb +14 -0
  40. data/lib/lutaml/lml/import_resolver.rb +96 -0
  41. data/lib/lutaml/lml/layout/engine.rb +17 -0
  42. data/lib/lutaml/lml/layout.rb +9 -0
  43. data/lib/lutaml/lml/literal_value.rb +32 -0
  44. data/lib/lutaml/lml/lsp/conversions.rb +78 -0
  45. data/lib/lutaml/lml/lsp/keywords.rb +43 -0
  46. data/lib/lutaml/lml/lsp/server.rb +380 -0
  47. data/lib/lutaml/lml/lsp/store.rb +68 -0
  48. data/lib/lutaml/lml/lsp/transport.rb +53 -0
  49. data/lib/lutaml/lml/lsp.rb +16 -0
  50. data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
  51. data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
  52. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
  53. data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
  54. data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
  55. data/lib/lutaml/lml/model_compiler.rb +329 -0
  56. data/lib/lutaml/lml/models/action.rb +10 -0
  57. data/lib/lutaml/lml/models/association.rb +31 -0
  58. data/lib/lutaml/lml/models/cardinality.rb +10 -0
  59. data/lib/lutaml/lml/models/collection.rb +11 -0
  60. data/lib/lutaml/lml/models/constraint.rb +25 -0
  61. data/lib/lutaml/lml/models/data_type.rb +43 -0
  62. data/lib/lutaml/lml/models/derived_field.rb +14 -0
  63. data/lib/lutaml/lml/models/diagram.rb +22 -0
  64. data/lib/lutaml/lml/models/document.rb +86 -0
  65. data/lib/lutaml/lml/models/enum.rb +40 -0
  66. data/lib/lutaml/lml/models/fidelity.rb +10 -0
  67. data/lib/lutaml/lml/models/group.rb +11 -0
  68. data/lib/lutaml/lml/models/instance.rb +28 -0
  69. data/lib/lutaml/lml/models/instance_collection.rb +18 -0
  70. data/lib/lutaml/lml/models/instances_export.rb +10 -0
  71. data/lib/lutaml/lml/models/instances_import.rb +11 -0
  72. data/lib/lutaml/lml/models/mapping.rb +15 -0
  73. data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
  74. data/lib/lutaml/lml/models/member_field.rb +16 -0
  75. data/lib/lutaml/lml/models/namespace.rb +18 -0
  76. data/lib/lutaml/lml/models/operation.rb +28 -0
  77. data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
  78. data/lib/lutaml/lml/models/package.rb +28 -0
  79. data/lib/lutaml/lml/models/primitive_type.rb +35 -0
  80. data/lib/lutaml/lml/models/reference.rb +23 -0
  81. data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
  82. data/lib/lutaml/lml/models/string_format.rb +16 -0
  83. data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
  84. data/lib/lutaml/lml/models/uml_class.rb +87 -0
  85. data/lib/lutaml/lml/models/value.rb +17 -0
  86. data/lib/lutaml/lml/models/view_filter.rb +11 -0
  87. data/lib/lutaml/lml/models/view_import.rb +11 -0
  88. data/lib/lutaml/lml/parser.rb +19 -0
  89. data/lib/lutaml/lml/pipeline.rb +73 -0
  90. data/lib/lutaml/lml/positioned.rb +13 -0
  91. data/lib/lutaml/lml/preprocessor.rb +132 -0
  92. data/lib/lutaml/lml/quoting.rb +60 -0
  93. data/lib/lutaml/lml/source.rb +49 -0
  94. data/lib/lutaml/lml/source_position.rb +20 -0
  95. data/lib/lutaml/lml/symbol_index.rb +202 -0
  96. data/lib/lutaml/lml/transform.rb +119 -0
  97. data/lib/lutaml/lml/types/text_type.rb +28 -0
  98. data/lib/lutaml/lml/types.rb +10 -0
  99. data/lib/lutaml/lml/validator.rb +460 -0
  100. data/lib/lutaml/lml/view_resolution.rb +32 -0
  101. data/lib/lutaml/lml/view_resolver.rb +48 -0
  102. data/lib/lutaml/lml/yaml_parser.rb +17 -0
  103. data/lib/lutaml/lml.rb +130 -0
  104. data/lib/lutaml/model/adapter_resolver.rb +21 -2
  105. data/lib/lutaml/model/attribute.rb +72 -0
  106. data/lib/lutaml/model/config.rb +22 -0
  107. data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
  108. data/lib/lutaml/model/services/rule_value_extractor.rb +19 -1
  109. data/lib/lutaml/model/version.rb +1 -1
  110. data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
  111. data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
  112. data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
  113. data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
  114. data/lib/lutaml/xml/adapter.rb +5 -0
  115. data/lib/lutaml/xml/adapter_loader.rb +5 -0
  116. data/lib/lutaml/xml/format.rb +23 -2
  117. data/lib/lutaml/xml/leptris/native_emission.rb +31 -4
  118. data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
  119. data/lib/lutaml/xml/parse_session.rb +8 -1
  120. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  121. data/lib/lutaml/xml/schema/builder.rb +1 -1
  122. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  123. data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
  124. data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
  125. data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
  126. data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
  127. data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
  128. data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
  129. data/lib/lutaml/xml/schema/xsd.rb +1 -0
  130. data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
  131. data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
  132. data/lib/lutaml/xml/xsd_validator.rb +1 -1
  133. data/lutaml-model.gemspec +2 -0
  134. data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
  135. data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
  136. data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
  137. data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
  138. data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
  139. data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
  140. data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
  141. data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
  142. data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
  143. data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
  144. data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
  145. data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
  146. data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
  147. data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
  148. data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
  149. data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
  150. data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
  151. data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
  152. data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
  153. data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
  154. data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
  155. data/spec/lml/fixtures/generated_dot/document.dot +28 -0
  156. data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
  157. data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
  158. data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
  159. data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
  160. data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
  161. data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
  162. data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
  163. data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
  164. data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
  165. data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
  166. data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
  167. data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
  168. data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
  169. data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
  170. data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
  171. data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
  172. data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
  173. data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
  174. data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
  175. data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
  176. data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
  177. data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
  178. data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
  179. data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
  180. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
  181. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
  182. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
  183. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
  184. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
  185. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
  186. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
  187. data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
  188. data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
  189. data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
  190. data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
  191. data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
  192. data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
  193. data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
  194. data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
  195. data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
  196. data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
  197. data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
  198. data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
  199. data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
  200. data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
  201. data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
  202. data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
  203. data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
  204. data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
  205. data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
  206. data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
  207. data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
  208. data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
  209. data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
  210. data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
  211. data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
  212. data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
  213. data/spec/lml/fixtures/test.lutaml +20 -0
  214. data/spec/lml/fixtures/test_data/components.csv +4 -0
  215. data/spec/lml/fixtures/test_data/products.xml +18 -0
  216. data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
  217. data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
  218. data/spec/lml/fixtures/uml/association.yml +11 -0
  219. data/spec/lml/fixtures/uml/class.yml +28 -0
  220. data/spec/lml/fixtures/uml/data_type.yml +30 -0
  221. data/spec/lml/fixtures/uml/diagram.yml +7 -0
  222. data/spec/lml/fixtures/uml/document.yml +44 -0
  223. data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
  224. data/spec/lml/fixtures/uml/enum.yml +14 -0
  225. data/spec/lml/fixtures/uml/operation.yml +8 -0
  226. data/spec/lml/fixtures/uml/package.yml +10 -0
  227. data/spec/lml/fixtures/uml/top_element.yml +11 -0
  228. data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
  229. data/spec/lml/fixtures/uml/trigger.yml +12 -0
  230. data/spec/lml/fixtures/uml/value.yml +8 -0
  231. data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
  232. data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
  233. data/spec/lml/fixtures/view/import_model.lutaml +3 -0
  234. data/spec/lml/fixtures/view/import_view.lutaml +3 -0
  235. data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
  236. data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
  237. data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
  238. data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
  239. data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
  240. data/spec/lml/integration/instance_import_export_spec.rb +102 -0
  241. data/spec/lml/lml_spec_setup.rb +25 -0
  242. data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
  243. data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
  244. data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
  245. data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
  246. data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
  247. data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
  248. data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
  249. data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
  250. data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
  251. data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
  252. data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
  253. data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
  254. data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
  255. data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
  256. data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
  257. data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
  258. data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
  259. data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
  260. data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
  261. data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
  262. data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
  263. data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
  264. data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
  265. data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
  266. data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
  267. data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
  268. data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
  269. data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
  270. data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
  271. data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
  272. data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
  273. data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
  274. data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
  275. data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
  276. data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
  277. data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
  278. data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
  279. data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
  280. data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
  281. data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
  282. data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
  283. data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
  284. data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
  285. data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
  286. data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
  287. data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
  288. data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
  289. data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
  290. data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
  291. data/spec/lml/lutaml/lml/source_spec.rb +62 -0
  292. data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
  293. data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
  294. data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
  295. data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
  296. data/spec/lml/lutaml/lml/view_spec.rb +112 -0
  297. data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
  298. data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
  299. data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
  300. data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
  301. data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
  302. data/spec/lutaml/model/from_json_scalar_cast_spec.rb +40 -12
  303. data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
  304. data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
  305. data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
  306. data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
  307. data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
  308. data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
  309. data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +43 -0
  310. metadata +286 -2
@@ -0,0 +1,486 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ # Builds domain model objects from processed parse hashes, applying
6
+ # source positions as non-serialized metadata.
7
+ class DocumentBuilder
8
+ # Default registry: builder keys → LML model classes. Built lazily
9
+ # (method, not load-time constant): the model classes live in the
10
+ # boot's later sections, and eager evaluation breaks Opal's
11
+ # sequential require order.
12
+ def self.default_registry
13
+ @default_registry ||= {
14
+ document: ::Lutaml::Lml::Document,
15
+ package: ::Lutaml::Lml::Package,
16
+ class: ::Lutaml::Lml::UmlClass,
17
+ enum: ::Lutaml::Lml::Enum,
18
+ data_type: ::Lutaml::Lml::DataType,
19
+ diagram: ::Lutaml::Lml::Diagram,
20
+ attribute: ::Lutaml::Lml::TopElementAttribute,
21
+ cardinality: ::Lutaml::Lml::Cardinality,
22
+ association: ::Lutaml::Lml::Association,
23
+ operation: ::Lutaml::Lml::Operation,
24
+ constraint: ::Lutaml::Lml::Constraint,
25
+ value: ::Lutaml::Lml::Value,
26
+ instance: ::Lutaml::Lml::Instance,
27
+ instance_collection: ::Lutaml::Lml::InstanceCollection,
28
+ view_import: ::Lutaml::Lml::ViewImport,
29
+ view_filter: ::Lutaml::Lml::ViewFilter,
30
+ mapping: ::Lutaml::Lml::Mapping,
31
+ string_format: ::Lutaml::Lml::StringFormat,
32
+ derived_field: ::Lutaml::Lml::DerivedField,
33
+ member_field: ::Lutaml::Lml::MemberField,
34
+ namespace: ::Lutaml::Lml::Namespace,
35
+ serialization_mapping: ::Lutaml::Lml::SerializationMapping,
36
+ }.freeze
37
+ end
38
+
39
+ attr_reader :registry
40
+
41
+ def initialize(registry = DocumentBuilder.default_registry)
42
+ @registry = registry
43
+ end
44
+
45
+ FACTORY_KEYS = %i[
46
+ document package class enum data_type diagram view_import view_filter
47
+ attribute association operation constraint value cardinality mapping
48
+ string_format derived_field namespace serialization_mapping
49
+ instance instance_collection
50
+ ].freeze
51
+
52
+ MEMBER_KEY_MAP = {
53
+ packages: :package,
54
+ classes: :class,
55
+ enums: :enum,
56
+ data_types: :data_type,
57
+ diagrams: :diagram,
58
+ view_imports: :view_import,
59
+ attributes: :attribute,
60
+ associations: :association,
61
+ operations: :operation,
62
+ constraints: :constraint,
63
+ values: :value,
64
+ mappings: :mapping,
65
+ member_fields: :member_field,
66
+ namespaces: :namespace,
67
+ serialization_mappings: :serialization_mapping,
68
+ instances: :instance,
69
+ }.freeze
70
+
71
+ MAPPING_KINDS = %w[element attribute map].freeze
72
+
73
+ FACTORY_KEYS.each do |key|
74
+ define_method(:"build_#{key}") { |hash| build(key, hash) }
75
+ end
76
+
77
+ def build(key, hash)
78
+ @registry.fetch(key).new.tap { |model| set_model(model, hash) }
79
+ end
80
+
81
+ private
82
+
83
+ def set_model(model, hash)
84
+ hash = build_members(model, hash)
85
+ apply_collection_members(model, hash)
86
+ set_model_attributes(model, hash)
87
+ expand_class_specializer(model, hash)
88
+ end
89
+
90
+ # The prefix specializer (`abstract class Foo`) expands to the
91
+ # canonical `abstract true` declaration (RS 3001 par. Declaration
92
+ # modifiers); the class-level modifier capture is not a block member.
93
+ def expand_class_specializer(model, hash)
94
+ return unless hash[:modifier].to_s == "abstract" && model.class.attributes.key?(:is_abstract)
95
+
96
+ model.is_abstract = true
97
+ end
98
+
99
+ def set_model_attributes(model, hash)
100
+ hash.each do |key, value|
101
+ if key == :position
102
+ attach_position(model, value)
103
+ next
104
+ end
105
+
106
+ apply_attribute(model, key, value)
107
+ end
108
+ end
109
+
110
+ def attach_position(model, value)
111
+ return unless model.is_a?(Positioned) && value.is_a?(Hash)
112
+
113
+ model.source_position = SourcePosition.new(**value)
114
+ end
115
+
116
+ def build_members(model, hash)
117
+ members = hash.delete(:members)
118
+ members.to_a.each do |member_hash|
119
+ record_model_version(model, member_hash)
120
+ add_members(model, member_hash)
121
+ set_model_attributes(model, member_hash)
122
+ end
123
+ hash
124
+ end
125
+
126
+ # A `models <Name> version "x.y.z"` header travels with the block's
127
+ # member hash; the block itself flattens into the document, so the
128
+ # version is recorded on the document before the name is dropped.
129
+ def record_model_version(model, hash)
130
+ return unless model.class.attributes.key?(:model_versions)
131
+ return unless hash.key?(:version)
132
+
133
+ name = hash[:name].to_s
134
+ model.model_versions[name] = unquote(hash.delete(:version)).to_s
135
+ end
136
+
137
+ def apply_attribute(model, key, value)
138
+ return unless model.class.attributes.key?(key.to_sym)
139
+
140
+ if model.class.attributes[key.to_sym].options[:collection]
141
+ append_collection(model, key, value)
142
+ else
143
+ model.public_send("#{key}=", value)
144
+ end
145
+ end
146
+
147
+ def append_collection(model, key, value)
148
+ values = model.public_send(key).to_a
149
+ value.is_a?(Array) ? values.concat(value) : values << value
150
+ model.public_send("#{key}=", values)
151
+ end
152
+
153
+ def add_members(model, hash)
154
+ expand_declared_members(model, hash)
155
+ normalize_namespace_declaration(hash)
156
+ normalize_serialization_mapping(hash)
157
+ expand_instances_collection_name(hash)
158
+ expand_nested_members(model, hash)
159
+ apply_collection_members(model, hash)
160
+
161
+ remap_filter_keys(hash, model)
162
+ end
163
+
164
+ # Builds collection-shaped keys through the registry rather than
165
+ # letting lutaml-model cast raw hashes, so nested entities keep
166
+ # their non-serialized source metadata (positions).
167
+ def apply_collection_members(model, hash)
168
+ model.instances = build(:instance_collection, hash.delete(:instances)) if model.is_a?(Document) && hash.key?(:instances)
169
+
170
+ MEMBER_KEY_MAP.each do |plural_key, singular_key|
171
+ data = hash.delete(plural_key)
172
+ next if data.nil?
173
+
174
+ entries = data.is_a?(Array) ? data : [data]
175
+ entries.each do |entry|
176
+ ensure_collection(model, plural_key) << build(singular_key, entry)
177
+ end
178
+ end
179
+ end
180
+
181
+ # RS 3001 §Enums: an enum-level `values { v1, v2 }` shorthand
182
+ # expands into plain members.
183
+ def expand_value_set_declaration(model, hash)
184
+ decl = hash.delete(:value_set_decl) or return
185
+ Array(decl[:items]).each do |item|
186
+ name = unquote(item[:item])
187
+ model.attributes << TopElementAttribute.new(name: name)
188
+ end
189
+ end
190
+
191
+ # RS 3001 §Value: the canonical `value` construct normalizes into
192
+ # the same member shape the bare-identifier shortcut produces.
193
+ def expand_value_declaration(model, hash)
194
+ decl = hash.delete(:value_decl) or return
195
+ inner = decl.fetch(:attributes)
196
+
197
+ # Route the value block's members onto the entry: descriptions
198
+ # and payload pairs ride the nested attributes, instance bodies
199
+ # become the entry's instances (RS 3001 §Enums values carrying
200
+ # instances).
201
+ entry = { name: inner[:name] }
202
+ entry[:position] = inner[:position] if inner[:position]
203
+ entry[:attributes] = inner[:attributes] if inner[:attributes]
204
+ if inner[:properties]
205
+ entry[:properties] = Array(inner[:properties]).flat_map do |pair|
206
+ pair.is_a?(Hash) ? [pair] : Array(pair)
207
+ end
208
+ end
209
+ entry[:instances] = inner[:instances] if inner[:instances]
210
+ append_collection(model, :attributes, build(:attribute, entry))
211
+ end
212
+
213
+ # Namespace declaration bodies arrive as keyword-line members
214
+ # ({uri: …}, {prefix: …}); flatten them onto the namespace hash.
215
+ def normalize_namespace_declaration(hash)
216
+ ns = hash[:namespaces] or return
217
+ Array(ns.delete(:members)).each do |pair|
218
+ pair.each { |key, value| ns[key] = unquote(value) }
219
+ end
220
+ end
221
+
222
+ # Serialization mapping rules arrive keyed by their line construct
223
+ # ({map_element: {wire:, field:}}); normalize into plain MappingRule
224
+ # hashes so the model cast lands typed rules.
225
+ def normalize_serialization_mapping(hash)
226
+ mapping = hash[:serialization_mappings] or return
227
+ rules = Array(mapping[:rules])
228
+ return if rules.any? && rules.all? { |e| e.is_a?(Hash) && e.key?(:kind) }
229
+
230
+ rules = rules.filter_map do |entry|
231
+ next nil unless entry.is_a?(Hash)
232
+
233
+ next { kind: "map", wire: unquote(entry[:wire]), field: unquote(entry[:to]) } if entry[:wire] && entry[:to]
234
+
235
+ first_key = entry.keys.first
236
+ kind = first_key.to_s
237
+ body = entry[first_key] || {}
238
+ unless body.is_a?(Hash)
239
+ kind_n = normalize_mapping_kind(kind)
240
+ next nil if body.to_s.empty?
241
+
242
+ term = unquote(body)
243
+ next { kind: kind_n, wire: term, field: term } if MAPPING_KINDS.include?(kind_n)
244
+
245
+ if kind_n == "namespace"
246
+ mapping[:namespace_ref] = term
247
+ next nil
248
+ end
249
+
250
+ next { kind: kind_n, field: term }
251
+ end
252
+ if kind == "element_name"
253
+ mapping[:element_name] = unquote(body[:element_name])
254
+ next nil
255
+ end
256
+ if kind == "map_namespace"
257
+ mapping[:namespace_ref] = unquote(body[:namespace_ref])
258
+ next nil
259
+ end
260
+ normalized = { kind: normalize_mapping_kind(kind) }
261
+ wire = body[:wire] || body[:element_wire]
262
+ normalized[:wire] = unquote(wire) if wire
263
+ field = body[:field] || body[:to_field] || body[:element_field] ||
264
+ body[:attribute_field] || body[:to]
265
+ normalized[:field] = unquote(field) if field
266
+ normalized[:mode] = body[:mode] if body[:mode]
267
+ normalized[:namespace_ref] = unquote(body[:namespace_ref]) if body[:namespace_ref]
268
+ normalized
269
+ end
270
+ mapping[:rules] = rules
271
+ end
272
+
273
+ def normalize_mapping_kind(kind)
274
+ {
275
+ "map_element" => "element", "map_attribute" => "attribute",
276
+ "map_content" => "content", "map_namespace" => "namespace",
277
+ "map_key" => "key", "map_value" => "value", "map" => "map",
278
+ "legacy_map" => "map"
279
+ }.fetch(kind, kind)
280
+ end
281
+
282
+ # A named instances collection (`instances "Glazes" { ... }`) arrives
283
+ # with its name as a sibling of the collection body; move it inside
284
+ # so the InstanceCollection carries it.
285
+ def expand_instances_collection_name(hash)
286
+ return unless hash.key?(:instances) && hash.key?(:name)
287
+
288
+ name = unquote(hash.delete(:name))
289
+ body = hash[:instances].is_a?(Hash) ? hash[:instances] : {}
290
+ body[:name] = name unless body.key?(:name)
291
+ end
292
+
293
+ # The document root is a repetition of top-level constructs (RS 3001:
294
+ # documents interleave declarations), so models/packages blocks nest
295
+ # their members one level down; recurse into them.
296
+ def expand_nested_members(model, hash)
297
+ return unless hash.key?(:members)
298
+
299
+ members = hash.delete(:members)
300
+ members.to_a.each do |nested|
301
+ add_members(model, nested)
302
+ set_model_attributes(model, nested)
303
+ end
304
+ end
305
+
306
+ # Declaration-level member hooks: single-line definitions, canonical
307
+ # `value` members, mapping sections, class declarations, enum
308
+ # member_fields and from_table all arrive as bare member hashes.
309
+ def expand_declared_members(model, hash)
310
+ expand_abstract_declaration(model, hash)
311
+ expand_definition_text(model, hash)
312
+ expand_value_declaration(model, hash)
313
+ expand_value_set_declaration(model, hash)
314
+ expand_mapping_section(model, hash)
315
+ expand_class_declarations(model, hash)
316
+ expand_enum_member_fields(model, hash)
317
+ expand_from_table(model, hash)
318
+ expand_operation_members(model, hash)
319
+ end
320
+
321
+ # Operation members arrive with grammar capture names
322
+ # (`visibility_modifier`, `param_default`) and per-iteration
323
+ # stereotype hashes; normalize to the model's field names.
324
+ def expand_operation_members(model, hash)
325
+ ops = hash.delete(:operations)
326
+ return unless ops && model.class.attributes.key?(:operations)
327
+
328
+ Array(ops.is_a?(Hash) ? [ops] : ops).each do |op|
329
+ model.operations << build(:operation, normalize_operation_hash(op))
330
+ end
331
+ end
332
+
333
+ def normalize_operation_hash(operation)
334
+ operation = operation.dup
335
+ if (vis = operation.delete(:visibility_modifier))
336
+ operation[:visibility] = Transform::VISIBILITY_MAP.fetch(vis.to_s, "public")
337
+ end
338
+ stereo = operation[:stereotype]
339
+ if stereo
340
+ items = stereo.is_a?(Array) ? stereo : [stereo]
341
+ operation[:stereotype] = items.map { |x| x.is_a?(Hash) ? x[:stereotype].to_s : x.to_s }
342
+ end
343
+ params = operation[:owned_parameter]
344
+ if params
345
+ list = params.is_a?(Array) ? params : [params]
346
+ operation[:owned_parameter] = list.map { |param| normalize_operation_param(param) }
347
+ end
348
+ operation
349
+ end
350
+
351
+ def normalize_operation_param(param)
352
+ param = param.dup
353
+ if (default = param.delete(:param_default))
354
+ param[:default] = default.is_a?(Hash) ? default[:string].to_s : default.to_s
355
+ end
356
+ param
357
+ end
358
+
359
+ # RS 3001 §Definition single-line form (`definition "text"`) arrives
360
+ # as a quoted-string capture; unwrap it for the entity's definition.
361
+ # RS 3001 declaration modifiers: `abstract true` maps onto the
362
+ # is_abstract field (the visibility declaration flows through the
363
+ # generic attribute path).
364
+ def expand_abstract_declaration(model, hash)
365
+ value = hash.delete(:abstract)
366
+ model.is_abstract = true if value.to_s == "true" && model.class.attributes.key?(:is_abstract)
367
+ end
368
+
369
+ def expand_definition_text(model, hash)
370
+ return unless hash.key?(:definition) && model.class.attributes.key?(:definition)
371
+
372
+ model.definition = unquote(hash.delete(:definition))
373
+ end
374
+
375
+ # A mapping section arrives as a bare member hash
376
+ # { format:, maps: [{ wire:, to: }] }; expand to one Mapping entry
377
+ # per map line, each carrying the format, and strip the section keys
378
+ def expand_mapping_section(model, hash)
379
+ section = mapping_section_from(hash)
380
+ return unless section
381
+
382
+ section[:maps].to_a.each do |line|
383
+ model.wire_mappings << build(:mapping,
384
+ format: section[:format],
385
+ wire: unquote(line[:wire]),
386
+ to: unquote(line[:to]))
387
+ end
388
+ end
389
+
390
+ def mapping_section_from(hash)
391
+ return { format: unquote(hash[:format]), maps: hash.delete(:maps) } if hash.key?(:maps)
392
+
393
+ hash.delete(:mappings)
394
+ end
395
+
396
+ # quoted_string captures nest their value under :string
397
+ def unquote(value)
398
+ value.is_a?(Hash) && value.key?(:string) ? value[:string] : value
399
+ end
400
+
401
+ # L5/L7 declaration members: string_format sections (class- or
402
+ # models-level), derive lines, and enum member_fields blocks
403
+ def expand_class_declarations(model, hash)
404
+ if (section = hash.delete(:string_format))
405
+ model.string_formats << build_string_format(section)
406
+ end
407
+ if (section = hash.delete(:default_string_formats))
408
+ model.default_string_formats << build_string_format(section)
409
+ end
410
+ expand_class_namespace(model, hash)
411
+ return unless (derived = hash.delete(:derived_field))
412
+
413
+ model.derived_fields << build(:derived_field,
414
+ name: derived[:name],
415
+ type: unquote(derived[:type]))
416
+ end
417
+
418
+ # Issue #49: an in-class `namespace "uri" [prefix "p"]` line
419
+ def expand_class_namespace(model, hash)
420
+ decl = hash.delete(:class_namespace) or return
421
+
422
+ model.xml_namespace = build(:namespace,
423
+ uri: unquote(decl[:uri]),
424
+ prefix: unquote(decl[:prefix]))
425
+ end
426
+
427
+ # L7a: from_table declares the enum's members as an artifact table
428
+ # { from_table_name:, from_table_artifact? } — expansion happens at
429
+ # compile time (deterministic materialization, no runtime data dep)
430
+ def expand_from_table(model, hash)
431
+ decl = hash.delete(:from_table_decl)
432
+ return unless decl && model.is_a?(Enum)
433
+
434
+ # the members repetition splits the declaration across iteration
435
+ # hashes (name part, artifact part) — merge the parts
436
+ parts = decl.is_a?(Array) ? decl : [decl]
437
+ decl = parts.each_with_object({}) do |part, acc|
438
+ acc.merge!(part) { |_key, _old, new_val| new_val }
439
+ end
440
+ model.from_table_name = unquote(decl[:from_table_name])
441
+ model.from_table_artifact = unquote(decl[:artifact_table]) if decl[:artifact_table]
442
+ end
443
+
444
+ def expand_enum_member_fields(model, hash)
445
+ decl = hash.delete(:member_fields_decl)
446
+ return unless decl && model.is_a?(Enum)
447
+
448
+ decl[:member_fields].to_a.each do |field|
449
+ model.member_fields << build(:member_field,
450
+ name: field[:name],
451
+ type: unquote(field[:member_field_type]))
452
+ end
453
+ end
454
+
455
+ def build_string_format(section)
456
+ items = section[:items].to_a.to_h do |item|
457
+ [item[:key].to_sym, unquote(item[:value])]
458
+ end
459
+ build(:string_format,
460
+ format: unquote(section[:format]),
461
+ artifact: items[:artifact],
462
+ root: items[:root])
463
+ end
464
+
465
+ def ensure_collection(model, key)
466
+ model.public_send(key) || begin
467
+ model.public_send("#{key}=", [])
468
+ model.public_send(key)
469
+ end
470
+ end
471
+
472
+ def remap_filter_keys(hash, model)
473
+ return unless model.is_a?(Document)
474
+
475
+ hash[:show_filter] = build_view_filter(hash.delete(:show_list)) if hash.key?(:show_list)
476
+ return unless hash.key?(:hide_list)
477
+
478
+ hash[:hide_filter] = build_view_filter(hash.delete(:hide_list))
479
+ end
480
+
481
+ def build_view_filter(entity_names)
482
+ ViewFilter.new(entity_names: Array(entity_names).map(&:to_s))
483
+ end
484
+ end
485
+ end
486
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ # Single source of truth for entity types held on a Document. Each
6
+ # entity model declares self.entity_type (the Document collection
7
+ # name); consumers iterate this registry instead of hardcoding the
8
+ # type list in four places.
9
+ module EntityTypes
10
+ # Registry built lazily (method, not load-time constant): the entity
11
+ # model classes load later in the boot, and eager evaluation breaks
12
+ # Opal's sequential require order.
13
+ def self.all
14
+ @all ||= [UmlClass, Enum, DataType, PrimitiveType].freeze
15
+ end
16
+
17
+ def self.by_symbol
18
+ @by_symbol ||= all.to_h { |klass| [klass.entity_type, klass] }
19
+ end
20
+
21
+ def self.symbols
22
+ by_symbol.keys
23
+ end
24
+
25
+ # Entities that can own attributes/associations (excludes enums).
26
+ def self.classifiable
27
+ all.select(&:classifiable?)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ class Executor
6
+ # Shared helpers for the I/O adapters. Both CsvAdapter and XmlAdapter
7
+ # need to:
8
+ #
9
+ # - resolve a `map_to` reference to a compiled class
10
+ # - look up attribute values by name in an import/export definition
11
+ # - find the compiled class that an instance belongs to (for export)
12
+ #
13
+ # This module owns those three concerns so each adapter can stay
14
+ # focused on its format-specific I/O.
15
+ module AdapterHelpers
16
+ # Returns the compiled class referenced by the `map_to` attribute,
17
+ # or nil if no such attribute or no such compiled class.
18
+ def resolve_target_class(attributes, compiled)
19
+ attr = find_attribute(attributes, "map_to")
20
+ return nil unless attr
21
+
22
+ compiled[attr.value.to_s]
23
+ end
24
+
25
+ # Returns the string value of the named attribute, or nil.
26
+ def attribute_value(attributes, name)
27
+ attr = find_attribute(attributes, name)
28
+ attr ? attr.value.to_s : nil
29
+ end
30
+
31
+ # Walks an attributes collection looking for an entry whose
32
+ # `.name` matches `name`. Returns the attribute, or nil.
33
+ def find_attribute(attributes, name)
34
+ Array(attributes).find { |a| a.name == name }
35
+ end
36
+
37
+ # Returns [class_name, klass] for the first compiled class whose
38
+ # instances include `first_instance`, or nil if no match.
39
+ def find_class_for_instance(first_instance, compiled)
40
+ compiled.find { |_name, klass| first_instance.is_a?(klass) }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end