lutaml-model 0.8.187 → 0.8.188

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 (306) 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/lml/association_label_resolver.rb +52 -0
  11. data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
  12. data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
  13. data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
  14. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
  15. data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
  16. data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
  17. data/lib/lutaml/lml/data_processor.rb +66 -0
  18. data/lib/lutaml/lml/diagnostic.rb +149 -0
  19. data/lib/lutaml/lml/document_builder.rb +486 -0
  20. data/lib/lutaml/lml/entity_types.rb +31 -0
  21. data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
  22. data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
  23. data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
  24. data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
  25. data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
  26. data/lib/lutaml/lml/executor.rb +96 -0
  27. data/lib/lutaml/lml/format/adapter/document.rb +11 -0
  28. data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
  29. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
  30. data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
  31. data/lib/lutaml/lml/format.rb +34 -0
  32. data/lib/lutaml/lml/formatter/base.rb +81 -0
  33. data/lib/lutaml/lml/formatter/canonical.rb +738 -0
  34. data/lib/lutaml/lml/formatter.rb +11 -0
  35. data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
  36. data/lib/lutaml/lml/grammar/lml.parg +389 -0
  37. data/lib/lutaml/lml/grammar.rb +60 -0
  38. data/lib/lutaml/lml/has_attributes.rb +14 -0
  39. data/lib/lutaml/lml/import_resolver.rb +96 -0
  40. data/lib/lutaml/lml/layout/engine.rb +17 -0
  41. data/lib/lutaml/lml/layout.rb +9 -0
  42. data/lib/lutaml/lml/literal_value.rb +32 -0
  43. data/lib/lutaml/lml/lsp/conversions.rb +78 -0
  44. data/lib/lutaml/lml/lsp/keywords.rb +43 -0
  45. data/lib/lutaml/lml/lsp/server.rb +380 -0
  46. data/lib/lutaml/lml/lsp/store.rb +68 -0
  47. data/lib/lutaml/lml/lsp/transport.rb +53 -0
  48. data/lib/lutaml/lml/lsp.rb +16 -0
  49. data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
  50. data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
  51. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
  52. data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
  53. data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
  54. data/lib/lutaml/lml/model_compiler.rb +329 -0
  55. data/lib/lutaml/lml/models/action.rb +10 -0
  56. data/lib/lutaml/lml/models/association.rb +31 -0
  57. data/lib/lutaml/lml/models/cardinality.rb +10 -0
  58. data/lib/lutaml/lml/models/collection.rb +11 -0
  59. data/lib/lutaml/lml/models/constraint.rb +25 -0
  60. data/lib/lutaml/lml/models/data_type.rb +43 -0
  61. data/lib/lutaml/lml/models/derived_field.rb +14 -0
  62. data/lib/lutaml/lml/models/diagram.rb +22 -0
  63. data/lib/lutaml/lml/models/document.rb +86 -0
  64. data/lib/lutaml/lml/models/enum.rb +40 -0
  65. data/lib/lutaml/lml/models/fidelity.rb +10 -0
  66. data/lib/lutaml/lml/models/group.rb +11 -0
  67. data/lib/lutaml/lml/models/instance.rb +28 -0
  68. data/lib/lutaml/lml/models/instance_collection.rb +18 -0
  69. data/lib/lutaml/lml/models/instances_export.rb +10 -0
  70. data/lib/lutaml/lml/models/instances_import.rb +11 -0
  71. data/lib/lutaml/lml/models/mapping.rb +15 -0
  72. data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
  73. data/lib/lutaml/lml/models/member_field.rb +16 -0
  74. data/lib/lutaml/lml/models/namespace.rb +18 -0
  75. data/lib/lutaml/lml/models/operation.rb +28 -0
  76. data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
  77. data/lib/lutaml/lml/models/package.rb +28 -0
  78. data/lib/lutaml/lml/models/primitive_type.rb +35 -0
  79. data/lib/lutaml/lml/models/reference.rb +23 -0
  80. data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
  81. data/lib/lutaml/lml/models/string_format.rb +16 -0
  82. data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
  83. data/lib/lutaml/lml/models/uml_class.rb +87 -0
  84. data/lib/lutaml/lml/models/value.rb +17 -0
  85. data/lib/lutaml/lml/models/view_filter.rb +11 -0
  86. data/lib/lutaml/lml/models/view_import.rb +11 -0
  87. data/lib/lutaml/lml/parser.rb +19 -0
  88. data/lib/lutaml/lml/pipeline.rb +73 -0
  89. data/lib/lutaml/lml/positioned.rb +13 -0
  90. data/lib/lutaml/lml/preprocessor.rb +132 -0
  91. data/lib/lutaml/lml/quoting.rb +60 -0
  92. data/lib/lutaml/lml/source.rb +49 -0
  93. data/lib/lutaml/lml/source_position.rb +20 -0
  94. data/lib/lutaml/lml/symbol_index.rb +202 -0
  95. data/lib/lutaml/lml/transform.rb +119 -0
  96. data/lib/lutaml/lml/types/text_type.rb +28 -0
  97. data/lib/lutaml/lml/types.rb +10 -0
  98. data/lib/lutaml/lml/validator.rb +460 -0
  99. data/lib/lutaml/lml/view_resolution.rb +32 -0
  100. data/lib/lutaml/lml/view_resolver.rb +48 -0
  101. data/lib/lutaml/lml/yaml_parser.rb +17 -0
  102. data/lib/lutaml/lml.rb +130 -0
  103. data/lib/lutaml/model/adapter_resolver.rb +21 -2
  104. data/lib/lutaml/model/config.rb +22 -0
  105. data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
  106. data/lib/lutaml/model/version.rb +1 -1
  107. data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
  108. data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
  109. data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
  110. data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
  111. data/lib/lutaml/xml/adapter.rb +5 -0
  112. data/lib/lutaml/xml/adapter_loader.rb +5 -0
  113. data/lib/lutaml/xml/format.rb +23 -2
  114. data/lib/lutaml/xml/leptris/native_emission.rb +6 -1
  115. data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
  116. data/lib/lutaml/xml/parse_session.rb +8 -1
  117. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  118. data/lib/lutaml/xml/schema/builder.rb +1 -1
  119. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  120. data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
  121. data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
  122. data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
  123. data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
  124. data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
  125. data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
  126. data/lib/lutaml/xml/schema/xsd.rb +1 -0
  127. data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
  128. data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
  129. data/lib/lutaml/xml/xsd_validator.rb +1 -1
  130. data/lutaml-model.gemspec +2 -0
  131. data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
  132. data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
  133. data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
  134. data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
  135. data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
  136. data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
  137. data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
  138. data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
  139. data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
  140. data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
  141. data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
  142. data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
  143. data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
  144. data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
  145. data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
  146. data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
  147. data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
  148. data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
  149. data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
  150. data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
  151. data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
  152. data/spec/lml/fixtures/generated_dot/document.dot +28 -0
  153. data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
  154. data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
  155. data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
  156. data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
  157. data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
  158. data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
  159. data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
  160. data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
  161. data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
  162. data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
  163. data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
  164. data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
  165. data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
  166. data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
  167. data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
  168. data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
  169. data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
  170. data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
  171. data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
  172. data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
  173. data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
  174. data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
  175. data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
  176. data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
  177. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
  178. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
  179. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
  180. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
  181. data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
  182. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
  183. data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
  184. data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
  185. data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
  186. data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
  187. data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
  188. data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
  189. data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
  190. data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
  191. data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
  192. data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
  193. data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
  194. data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
  195. data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
  196. data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
  197. data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
  198. data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
  199. data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
  200. data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
  201. data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
  202. data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
  203. data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
  204. data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
  205. data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
  206. data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
  207. data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
  208. data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
  209. data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
  210. data/spec/lml/fixtures/test.lutaml +20 -0
  211. data/spec/lml/fixtures/test_data/components.csv +4 -0
  212. data/spec/lml/fixtures/test_data/products.xml +18 -0
  213. data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
  214. data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
  215. data/spec/lml/fixtures/uml/association.yml +11 -0
  216. data/spec/lml/fixtures/uml/class.yml +28 -0
  217. data/spec/lml/fixtures/uml/data_type.yml +30 -0
  218. data/spec/lml/fixtures/uml/diagram.yml +7 -0
  219. data/spec/lml/fixtures/uml/document.yml +44 -0
  220. data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
  221. data/spec/lml/fixtures/uml/enum.yml +14 -0
  222. data/spec/lml/fixtures/uml/operation.yml +8 -0
  223. data/spec/lml/fixtures/uml/package.yml +10 -0
  224. data/spec/lml/fixtures/uml/top_element.yml +11 -0
  225. data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
  226. data/spec/lml/fixtures/uml/trigger.yml +12 -0
  227. data/spec/lml/fixtures/uml/value.yml +8 -0
  228. data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
  229. data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
  230. data/spec/lml/fixtures/view/import_model.lutaml +3 -0
  231. data/spec/lml/fixtures/view/import_view.lutaml +3 -0
  232. data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
  233. data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
  234. data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
  235. data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
  236. data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
  237. data/spec/lml/integration/instance_import_export_spec.rb +102 -0
  238. data/spec/lml/lml_spec_setup.rb +25 -0
  239. data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
  240. data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
  241. data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
  242. data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
  243. data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
  244. data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
  245. data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
  246. data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
  247. data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
  248. data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
  249. data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
  250. data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
  251. data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
  252. data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
  253. data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
  254. data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
  255. data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
  256. data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
  257. data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
  258. data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
  259. data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
  260. data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
  261. data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
  262. data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
  263. data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
  264. data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
  265. data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
  266. data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
  267. data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
  268. data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
  269. data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
  270. data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
  271. data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
  272. data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
  273. data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
  274. data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
  275. data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
  276. data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
  277. data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
  278. data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
  279. data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
  280. data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
  281. data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
  282. data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
  283. data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
  284. data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
  285. data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
  286. data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
  287. data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
  288. data/spec/lml/lutaml/lml/source_spec.rb +62 -0
  289. data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
  290. data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
  291. data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
  292. data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
  293. data/spec/lml/lutaml/lml/view_spec.rb +112 -0
  294. data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
  295. data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
  296. data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
  297. data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
  298. data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
  299. data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
  300. data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
  301. data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
  302. data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
  303. data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
  304. data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
  305. data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +43 -0
  306. metadata +286 -2
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ class Executor
6
+ # Evaluates collection validation conditions against instance data.
7
+ #
8
+ # Conditions are simple DSL strings like "count >= 3" or
9
+ # "all? { |i| i.components.count > 0 }". The evaluator parses a safe
10
+ # subset of forms — it never calls `eval` on arbitrary Ruby.
11
+ #
12
+ # Supported condition forms:
13
+ # "count >= N" — collection size comparison
14
+ # "count == N", "count <= N", etc.
15
+ # "all? { |i| i.path OP literal }" — every instance matches
16
+ # "any? { |i| i.path OP literal }" — at least one instance matches
17
+ #
18
+ # The block predicate supports a single comparison of an instance
19
+ # attribute path (e.g. `i.components.count`, `i.name`) against a
20
+ # literal (number, quoted string, true/false/nil) using one of
21
+ # `>, >=, <, <=, ==, !=`.
22
+ #
23
+ class ConditionEvaluator
24
+ class ConditionError < StandardError
25
+ end
26
+
27
+ BLOCK_PREFIX = /\A\s*(all|any)\?/
28
+ BLOCK_VAR = /\A\s*\|(\w+)\|/
29
+
30
+ # Operator list in longest-first order so ">=" never splits as
31
+ # ">" plus a stray "="; the LHS is a plain path and the RHS a
32
+ # literal, so the first occurring operator is the separator.
33
+ COMPARISON_OPERATORS = %w[>= <= == != > <].freeze
34
+
35
+ # Evaluate all validation conditions against a collection of instances.
36
+ # Returns an array of error strings (empty if all pass).
37
+ def self.evaluate(collection, instances)
38
+ return [] unless collection.is_a?(Collection)
39
+ return [] unless collection.validations&.any?
40
+
41
+ new(instances).evaluate_all(collection.validations)
42
+ end
43
+
44
+ def initialize(instances)
45
+ @instances = instances
46
+ end
47
+
48
+ def evaluate_all(conditions)
49
+ conditions.filter_map do |condition|
50
+ evaluate(condition)
51
+ rescue ConditionError => e
52
+ "Validation failed: #{e.message}"
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def evaluate(condition)
59
+ return evaluate_block(condition) if condition.match?(/\A\s*(all|any)\?\s*\{/)
60
+ return evaluate_count(condition) if condition.match?(/\bcount\s*[<>=]+/)
61
+
62
+ raise ConditionError, "Unsupported condition: #{condition}"
63
+ end
64
+
65
+ def evaluate_count(condition)
66
+ match = condition.match(/\bcount\s*(>=|<=|==|>|<)\s*(\d+)/)
67
+ raise ConditionError, "Invalid count condition: #{condition}" unless match
68
+
69
+ operator = match[1]
70
+ expected = match[2].to_i
71
+ actual = @instances.length
72
+
73
+ compare?(actual, operator, expected) ||
74
+ raise(ConditionError, "#{condition} (got #{actual})")
75
+ nil
76
+ end
77
+
78
+ def evaluate_block(condition)
79
+ quantifier, predicate = parse_block(condition)
80
+ raise ConditionError, "Invalid block condition: #{condition}" if quantifier.nil?
81
+
82
+ comparator = build_predicate(predicate)
83
+ satisfied = @instances.public_send("#{quantifier}?") do |instance|
84
+ comparator.call(instance)
85
+ end
86
+
87
+ return nil if satisfied
88
+
89
+ raise ConditionError, "#{condition} (failed for #{quantifier == 'all' ? 'at least one' : 'all'} instance)"
90
+ end
91
+
92
+ def parse_block(condition)
93
+ stripped = condition.strip
94
+ prefix = stripped.match(BLOCK_PREFIX)
95
+ return [nil, nil] unless prefix
96
+
97
+ open_idx = stripped.index("{")
98
+ close_idx = stripped.rindex("}")
99
+ return [nil, nil] unless open_idx && close_idx && close_idx > open_idx
100
+
101
+ body = stripped[(open_idx + 1)...close_idx].strip
102
+ var_match = body.match(BLOCK_VAR)
103
+ return [nil, nil] unless var_match
104
+
105
+ predicate = body[var_match[0].length..].strip
106
+ [prefix[1], predicate]
107
+ end
108
+
109
+ # Parses a single comparison predicate "i.path OP literal" into a
110
+ # callable that, given an instance, returns true/false. Split by
111
+ # operator scan rather than a lazy-capture regex: the condition
112
+ # string is document-controlled, and the capture form is
113
+ # polynomial on non-matching input (CodeQL rb/redos family).
114
+ def build_predicate(predicate)
115
+ stripped = predicate.strip
116
+ operator = COMPARISON_OPERATORS.find { |op| stripped.include?(op) }
117
+ lhs, rhs = stripped.split(operator, 2) if operator
118
+ raise ConditionError, "Unsupported predicate: #{predicate}" unless operator && lhs && rhs
119
+
120
+ getter = attribute_getter(lhs.strip)
121
+ expected = parse_literal(rhs.strip)
122
+
123
+ lambda do |instance|
124
+ actual = getter.call(instance)
125
+ compare?(actual, operator, expected)
126
+ rescue NoMethodError
127
+ false
128
+ end
129
+ end
130
+
131
+ # Parses "i.attr.subattr..." into a callable on an instance.
132
+ def attribute_getter(path)
133
+ parts = path.strip.split(".")
134
+ raise ConditionError, "Invalid attribute path: #{path}" if parts.empty?
135
+
136
+ unless parts.first == "i"
137
+ raise ConditionError, "Block predicate must reference i: #{path}"
138
+ end
139
+
140
+ chain = parts.drop(1)
141
+ lambda do |instance|
142
+ chain.reduce(instance) { |receiver, method| receiver.public_send(method) }
143
+ end
144
+ end
145
+
146
+ # Parses a single literal value from the predicate RHS.
147
+ def parse_literal(token)
148
+ stripped = token.strip
149
+ case stripped
150
+ when /\A-?\d+\z/ then stripped.to_i
151
+ when /\A-?\d+\.\d+\z/ then stripped.to_f
152
+ when /\A".*"\z/, /\A'.*'\z/ then stripped[1..-2]
153
+ when "true" then true
154
+ when "false" then false
155
+ when "nil", "null" then nil
156
+ else
157
+ raise ConditionError, "Unsupported literal: #{token}"
158
+ end
159
+ end
160
+
161
+ def compare?(actual, operator, expected)
162
+ case operator
163
+ when ">=" then actual.to_f >= expected.to_f
164
+ when "<=" then actual.to_f <= expected.to_f
165
+ when "==" then actual == expected
166
+ when "!=" then actual != expected
167
+ when ">" then actual.to_f > expected.to_f
168
+ when "<" then actual.to_f < expected.to_f
169
+ else false
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+
5
+ module Lutaml
6
+ module Lml
7
+ class Executor
8
+ # CSV format adapter. Reads CSV files and maps rows to hydrated
9
+ # compiled-class instances using column mappings from the import
10
+ # definition. Exports instances back to CSV.
11
+ #
12
+ # Registered for format "csv" via FormatAdapter::BUILTIN_ADAPTERS.
13
+ class CsvAdapter
14
+ extend AdapterHelpers
15
+
16
+ # Read a CSV file and map rows to compiled-class instances.
17
+ # Returns an array of hydrated objects.
18
+ #
19
+ # The import definition's attributes provide column mappings:
20
+ # attribute name = "csv_column_header"
21
+ def self.import(imp, compiled:)
22
+ return [] unless imp.file
23
+ return [] unless imp.attributes&.any?
24
+
25
+ mappings = build_column_mappings(imp.attributes)
26
+ target_class = resolve_target_class(imp.attributes, compiled)
27
+ return [] unless target_class
28
+
29
+ path = imp.file
30
+ return [] unless File.exist?(path)
31
+
32
+ rows = CSV.read(path, headers: true)
33
+ rows.map { |row| build_instance(row, mappings, target_class) }
34
+ end
35
+
36
+ # Write instances to a CSV file.
37
+ def self.export(exp, instances, compiled:)
38
+ return if instances.empty?
39
+
40
+ path = attribute_value(exp.attributes, "file")
41
+ return unless path && !path.empty?
42
+
43
+ first_instance = instances.first
44
+ _, target_class = find_class_for_instance(first_instance, compiled)
45
+ return unless target_class
46
+
47
+ fields = target_class.attributes.keys
48
+ rows = instances.map do |inst|
49
+ fields.map { |f| extract_attribute_value(inst, f) }
50
+ end
51
+
52
+ File.write(path, generate_csv(fields, rows))
53
+ end
54
+
55
+ class << self
56
+ private
57
+
58
+ def build_column_mappings(attributes)
59
+ Array(attributes).each_with_object({}) do |attr, map|
60
+ next if attr.name == "map_to"
61
+
62
+ map[attr.name.to_sym] = attr.value.to_s
63
+ end
64
+ end
65
+
66
+ def build_instance(row, mappings, target_class)
67
+ attrs = mappings.each_with_object({}) do |(attr_name, col_name), hash|
68
+ hash[attr_name] = row[col_name]
69
+ end
70
+ target_class.new(**attrs)
71
+ end
72
+
73
+ def extract_attribute_value(instance, field_name)
74
+ instance.public_send(field_name)
75
+ rescue NoMethodError
76
+ nil
77
+ end
78
+
79
+ def generate_csv(headers, rows)
80
+ CSV.generate do |csv|
81
+ csv << headers
82
+ rows.each { |row| csv << row }
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ class Executor
6
+ # Pluggable format adapter registry. Adapters handle the actual
7
+ # I/O for a given format (CSV, XML, etc.).
8
+ #
9
+ # Each adapter must implement:
10
+ # .import(imp, compiled:) — read external data, return array of instances
11
+ # .export(exp, instances, compiled:) — write instances to external format
12
+ #
13
+ module FormatAdapter
14
+ class AdapterNotFoundError < StandardError; end
15
+
16
+ @adapters = {}
17
+
18
+ # Built-in adapters resolved by referencing the constant under
19
+ # Executor, which triggers autoload on first access. External
20
+ # adapters can still register via `register`.
21
+ BUILTIN_ADAPTERS = {
22
+ "csv" => :CsvAdapter,
23
+ "xml" => :XmlAdapter,
24
+ }.freeze
25
+
26
+ # Register an adapter for a format name.
27
+ def self.register(format_name, adapter)
28
+ @adapters[format_name.to_s] = adapter
29
+ end
30
+
31
+ # Look up the adapter for a format name.
32
+ def self.resolve(format_name)
33
+ key = format_name.to_s
34
+ return @adapters[key] if @adapters.key?(key)
35
+
36
+ builtin = BUILTIN_ADAPTERS[key]
37
+ if builtin
38
+ adapter = Executor.const_get(builtin)
39
+ register(key, adapter)
40
+ return adapter
41
+ end
42
+
43
+ raise(AdapterNotFoundError,
44
+ "No adapter registered for format '#{format_name}'")
45
+ end
46
+
47
+ # Returns all registered format names.
48
+ def self.registered_formats
49
+ @adapters.keys
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "moxml"
4
+
5
+ module Lutaml
6
+ module Lml
7
+ class Executor
8
+ # XML format adapter. Reads XML files and maps elements to hydrated
9
+ # compiled-class instances, and writes instances back to XML.
10
+ #
11
+ # Registered for format "xml" via FormatAdapter::BUILTIN_ADAPTERS.
12
+ #
13
+ # Element-to-attribute mapping is provided by the lutaml-model XML
14
+ # mapping generated on each compiled class by ModelCompiler. This
15
+ # adapter only selects which XML elements correspond to records
16
+ # (via the `where` XPath from the import definition) and hands
17
+ # each one to `target_class.from_xml` for deserialization.
18
+ #
19
+ # Import shape (from LML `import { xml "..." { map_to X; where "/y" } }`):
20
+ # - imp.file = path to XML file
21
+ # - imp.attributes = TopElementAttribute list including:
22
+ # map_to: TargetClass (compiled-class key)
23
+ # where: XPath selector for each record element
24
+ #
25
+ # Export shape (from LML `export { format xml { file "..."; root "X" } }`):
26
+ # - exp.attributes = TopElementAttribute list including:
27
+ # file: output path
28
+ # root: root tag name (defaults to compiled class name)
29
+ # indent: "true" / "false" (default true)
30
+ # encoding: encoding string (default UTF-8)
31
+ class XmlAdapter
32
+ extend AdapterHelpers
33
+
34
+ DEFAULT_ENCODING = "UTF-8"
35
+ DEFAULT_SELECTOR = "/*/*"
36
+ DEFAULT_ROOT_SUFFIX = "s"
37
+
38
+ class << self
39
+ # Read an XML file and map elements to compiled-class instances.
40
+ # Returns an array of hydrated objects.
41
+ def import(imp, compiled:)
42
+ return [] unless imp.file
43
+ return [] unless imp.attributes&.any?
44
+
45
+ target_class = resolve_target_class(imp.attributes, compiled)
46
+ return [] unless target_class
47
+
48
+ path = imp.file
49
+ return [] unless File.exist?(path)
50
+
51
+ doc = Moxml.parse(File.read(path))
52
+ selector = attribute_value(imp.attributes, "where") || DEFAULT_SELECTOR
53
+
54
+ doc.xpath(selector).map do |element|
55
+ target_class.from_xml(element.to_xml)
56
+ end
57
+ end
58
+
59
+ # Write instances to an XML file.
60
+ def export(exp, instances, compiled:)
61
+ return if instances.empty?
62
+
63
+ path = attribute_value(exp.attributes, "file")
64
+ return unless path && !path.empty?
65
+
66
+ class_name, target_class = find_class_for_instance(instances.first, compiled)
67
+ return unless target_class
68
+
69
+ options = export_options(exp, class_name)
70
+ File.write(path, build_export_xml(instances, options))
71
+ end
72
+
73
+ private
74
+
75
+ def export_options(exp, class_name)
76
+ {
77
+ root: attribute_value(exp.attributes, "root") || "#{class_name}#{DEFAULT_ROOT_SUFFIX}",
78
+ indent: attribute_value(exp.attributes, "indent") != "false",
79
+ encoding: attribute_value(exp.attributes, "encoding") || DEFAULT_ENCODING,
80
+ }
81
+ end
82
+
83
+ # Builds the export XML by parsing each instance's `to_xml`
84
+ # output, then grafting its root element under a single
85
+ # configurable root. lutaml-model handles per-record
86
+ # serialization via the generated XML mapping.
87
+ def build_export_xml(instances, options)
88
+ doc = Moxml.parse("<#{options[:root]}/>")
89
+ root = doc.root
90
+
91
+ instances.each do |inst|
92
+ record_doc = Moxml.parse(inst.to_xml)
93
+ root.add_child(record_doc.root)
94
+ end
95
+
96
+ doc.to_xml(indent: options[:indent] ? 2 : 0)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module Lutaml
6
+ module Lml
7
+ # Orchestrates instance data I/O: import external data, validate
8
+ # collections, and export to external formats.
9
+ #
10
+ # Format-specific I/O is delegated to registered adapters via the
11
+ # FormatAdapter registry. The core executor only handles the
12
+ # orchestration — it knows *what* to do, adapters know *how*.
13
+ #
14
+ # Usage:
15
+ # compiled = ModelCompiler.new.compile(models_file)
16
+ # doc = Lutaml::Lml.parse_document(instances_file)
17
+ # result = Executor.run(doc, compiled: compiled)
18
+ # result.instances # array of hydrated instance objects
19
+ # result.errors # array of validation error strings
20
+ #
21
+ class Executor
22
+ autoload :FormatAdapter, "lutaml/lml/executor/format_adapter"
23
+ autoload :AdapterHelpers, "lutaml/lml/executor/adapter_helpers"
24
+ autoload :CsvAdapter, "lutaml/lml/executor/csv_adapter"
25
+ autoload :XmlAdapter, "lutaml/lml/executor/xml_adapter"
26
+ autoload :ConditionEvaluator, "lutaml/lml/executor/condition_evaluator"
27
+
28
+ # Result of running the executor: hydrated instances plus any
29
+ # validation errors collected along the way. Delegates array-like
30
+ # methods to instances so existing callers that treated the run
31
+ # return value as an array continue to work.
32
+ Result = Struct.new(:instances, :errors) do
33
+ extend Forwardable
34
+
35
+ def_delegators :instances, :length, :each, :map, :[], :empty?
36
+ end
37
+
38
+ attr_reader :compiled
39
+
40
+ def initialize(compiled:)
41
+ @compiled = compiled
42
+ end
43
+
44
+ # Run the full import/validate/export cycle on a parsed document.
45
+ # Returns a Result with hydrated instances and validation errors.
46
+ def self.run(doc, compiled:)
47
+ new(compiled: compiled).run(doc)
48
+ end
49
+
50
+ def run(doc)
51
+ instances = run_imports(doc)
52
+ errors = validate_collections(doc, instances)
53
+ run_exports(doc, instances)
54
+ Result.new(instances, errors)
55
+ end
56
+
57
+ private
58
+
59
+ # --- Import ---
60
+
61
+ def run_imports(doc)
62
+ return [] unless doc.instances&.imports&.any?
63
+
64
+ doc.instances.imports.flat_map { |imp| import_one(imp) }
65
+ end
66
+
67
+ def import_one(imp)
68
+ FormatAdapter.resolve(imp.format_type).import(imp, compiled: @compiled)
69
+ end
70
+
71
+ # --- Collection validation ---
72
+
73
+ def validate_collections(doc, instances)
74
+ return [] unless doc.instances&.collections
75
+
76
+ Array(doc.instances.collections).flat_map do |collection|
77
+ ConditionEvaluator.evaluate(collection, instances)
78
+ end
79
+ end
80
+
81
+ # --- Export ---
82
+
83
+ def run_exports(doc, instances)
84
+ return unless doc.instances&.exports&.any?
85
+
86
+ doc.instances.exports.each do |exp|
87
+ export_one(exp, instances)
88
+ end
89
+ end
90
+
91
+ def export_one(exp, instances)
92
+ FormatAdapter.resolve(exp.format_type).export(exp, instances, compiled: @compiled)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ module Format
6
+ module Adapter
7
+ class Document < Lutaml::KeyValue::Document; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Lml
5
+ module Format
6
+ module Adapter
7
+ class Mapping < Lutaml::KeyValue::Mapping
8
+ def initialize
9
+ super(:lml)
10
+ end
11
+
12
+ def dup_instance
13
+ self.class.new
14
+ end
15
+
16
+ # RS 3001 §String values: a present value — including a
17
+ # zero-length string — is distinct from an absent one, so the
18
+ # lml format emits empty values. Nil stays omitted: absence is
19
+ # the unassigned line, not a rendered null.
20
+ def map(name = nil, to: nil, render_empty: true, **options, &block)
21
+ super
22
+ end
23
+ # The parent's `alias map_element map` binds the alias to the
24
+ # parent method at definition time, so it bypasses the map
25
+ # override above; default_mappings goes through map_element.
26
+ alias map_element map
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end