@linked.archi/kernel 0.0.0-stage → 0.1.6

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 (366) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +102 -2
  4. package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
  5. package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
  6. package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
  7. package/assets/arch-decision/arch-decision-tax.ttl +129 -0
  8. package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
  9. package/assets/arch-processes/arch-processes-tax.ttl +136 -0
  10. package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
  11. package/assets/arch-processes/archProcesses.ttl +953 -0
  12. package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
  13. package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
  14. package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
  15. package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
  16. package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
  17. package/assets/archimate3/archimate3.2-principle-shapes.ttl +917 -0
  18. package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
  19. package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
  20. package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
  21. package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
  22. package/assets/archimate3/archimate3.2-tax.ttl +724 -0
  23. package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
  24. package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
  25. package/assets/archimate3/icons/and-junction.svg +3 -0
  26. package/assets/archimate3/icons/application-collaboration.svg +22 -0
  27. package/assets/archimate3/icons/application-component.svg +18 -0
  28. package/assets/archimate3/icons/application-event.svg +15 -0
  29. package/assets/archimate3/icons/application-function.svg +14 -0
  30. package/assets/archimate3/icons/application-interaction.svg +17 -0
  31. package/assets/archimate3/icons/application-interface.svg +16 -0
  32. package/assets/archimate3/icons/application-process.svg +14 -0
  33. package/assets/archimate3/icons/application-service.svg +14 -0
  34. package/assets/archimate3/icons/artifact.svg +16 -0
  35. package/assets/archimate3/icons/assessment.svg +17 -0
  36. package/assets/archimate3/icons/business-actor.svg +22 -0
  37. package/assets/archimate3/icons/business-collaboration.svg +21 -0
  38. package/assets/archimate3/icons/business-event.svg +15 -0
  39. package/assets/archimate3/icons/business-function.svg +14 -0
  40. package/assets/archimate3/icons/business-interaction.svg +18 -0
  41. package/assets/archimate3/icons/business-interface.svg +16 -0
  42. package/assets/archimate3/icons/business-object.svg +14 -0
  43. package/assets/archimate3/icons/business-process.svg +15 -0
  44. package/assets/archimate3/icons/business-role.svg +16 -0
  45. package/assets/archimate3/icons/business-service.svg +14 -0
  46. package/assets/archimate3/icons/capability.svg +40 -0
  47. package/assets/archimate3/icons/communication-network.svg +18 -0
  48. package/assets/archimate3/icons/constraint.svg +18 -0
  49. package/assets/archimate3/icons/contract.svg +13 -0
  50. package/assets/archimate3/icons/course-of-action.svg +20 -0
  51. package/assets/archimate3/icons/data-object.svg +14 -0
  52. package/assets/archimate3/icons/deliverable.svg +11 -0
  53. package/assets/archimate3/icons/device.svg +18 -0
  54. package/assets/archimate3/icons/distribution-network.svg +19 -0
  55. package/assets/archimate3/icons/driver.svg +24 -0
  56. package/assets/archimate3/icons/equipment.svg +31 -0
  57. package/assets/archimate3/icons/facility.svg +16 -0
  58. package/assets/archimate3/icons/gap.svg +22 -0
  59. package/assets/archimate3/icons/glyphs/activity.svg +3 -0
  60. package/assets/archimate3/icons/glyphs/actor.svg +14 -0
  61. package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
  62. package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
  63. package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
  64. package/assets/archimate3/icons/glyphs/capability.svg +32 -0
  65. package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
  66. package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
  67. package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
  68. package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
  69. package/assets/archimate3/icons/glyphs/contract.svg +5 -0
  70. package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
  71. package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
  72. package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
  73. package/assets/archimate3/icons/glyphs/device.svg +10 -0
  74. package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
  75. package/assets/archimate3/icons/glyphs/driver.svg +16 -0
  76. package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
  77. package/assets/archimate3/icons/glyphs/event.svg +6 -0
  78. package/assets/archimate3/icons/glyphs/facility.svg +7 -0
  79. package/assets/archimate3/icons/glyphs/function.svg +6 -0
  80. package/assets/archimate3/icons/glyphs/gap.svg +14 -0
  81. package/assets/archimate3/icons/glyphs/goal.svg +10 -0
  82. package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
  83. package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
  84. package/assets/archimate3/icons/glyphs/interface.svg +8 -0
  85. package/assets/archimate3/icons/glyphs/location.svg +6 -0
  86. package/assets/archimate3/icons/glyphs/material.svg +12 -0
  87. package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
  88. package/assets/archimate3/icons/glyphs/node.svg +8 -0
  89. package/assets/archimate3/icons/glyphs/object.svg +4 -0
  90. package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
  91. package/assets/archimate3/icons/glyphs/path.svg +10 -0
  92. package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
  93. package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
  94. package/assets/archimate3/icons/glyphs/principle.svg +12 -0
  95. package/assets/archimate3/icons/glyphs/process.svg +6 -0
  96. package/assets/archimate3/icons/glyphs/product.svg +4 -0
  97. package/assets/archimate3/icons/glyphs/representation.svg +4 -0
  98. package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
  99. package/assets/archimate3/icons/glyphs/resource.svg +14 -0
  100. package/assets/archimate3/icons/glyphs/role.svg +6 -0
  101. package/assets/archimate3/icons/glyphs/service.svg +6 -0
  102. package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
  103. package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
  104. package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
  105. package/assets/archimate3/icons/glyphs/value.svg +3 -0
  106. package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
  107. package/assets/archimate3/icons/goal.svg +18 -0
  108. package/assets/archimate3/icons/grouping.svg +12 -0
  109. package/assets/archimate3/icons/implementation-event.svg +15 -0
  110. package/assets/archimate3/icons/location.svg +14 -0
  111. package/assets/archimate3/icons/material.svg +21 -0
  112. package/assets/archimate3/icons/meaning.svg +11 -0
  113. package/assets/archimate3/icons/node.svg +14 -0
  114. package/assets/archimate3/icons/or-junction.svg +3 -0
  115. package/assets/archimate3/icons/outcome.svg +25 -0
  116. package/assets/archimate3/icons/path.svg +18 -0
  117. package/assets/archimate3/icons/plateau.svg +16 -0
  118. package/assets/archimate3/icons/principle.svg +21 -0
  119. package/assets/archimate3/icons/product.svg +12 -0
  120. package/assets/archimate3/icons/representation.svg +12 -0
  121. package/assets/archimate3/icons/requirement.svg +14 -0
  122. package/assets/archimate3/icons/resource.svg +23 -0
  123. package/assets/archimate3/icons/stakeholder.svg +15 -0
  124. package/assets/archimate3/icons/system-software.svg +22 -0
  125. package/assets/archimate3/icons/technology-collaboration.svg +22 -0
  126. package/assets/archimate3/icons/technology-event.svg +15 -0
  127. package/assets/archimate3/icons/technology-function.svg +14 -0
  128. package/assets/archimate3/icons/technology-interaction.svg +18 -0
  129. package/assets/archimate3/icons/technology-interface.svg +16 -0
  130. package/assets/archimate3/icons/technology-process.svg +14 -0
  131. package/assets/archimate3/icons/technology-service.svg +14 -0
  132. package/assets/archimate3/icons/value-stream.svg +11 -0
  133. package/assets/archimate3/icons/value.svg +11 -0
  134. package/assets/archimate3/icons/work-package.svg +12 -0
  135. package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
  136. package/assets/archimate4/archimate4-metamodel.ttl +179 -0
  137. package/assets/archimate4/archimate4-notation.ttl +1147 -0
  138. package/assets/archimate4/archimate4-onto.ttl +1559 -0
  139. package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
  140. package/assets/archimate4/archimate4-principle-shapes.ttl +895 -0
  141. package/assets/archimate4/archimate4-questions.ttl +1224 -0
  142. package/assets/archimate4/archimate4-reference-data.ttl +56 -0
  143. package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
  144. package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
  145. package/assets/archimate4/archimate4-tax.ttl +749 -0
  146. package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
  147. package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
  148. package/assets/archimate4/icons/and-junction.svg +3 -0
  149. package/assets/archimate4/icons/application-component.svg +18 -0
  150. package/assets/archimate4/icons/application-interface.svg +16 -0
  151. package/assets/archimate4/icons/artifact.svg +16 -0
  152. package/assets/archimate4/icons/assessment.svg +17 -0
  153. package/assets/archimate4/icons/business-actor.svg +22 -0
  154. package/assets/archimate4/icons/business-interface.svg +16 -0
  155. package/assets/archimate4/icons/business-object.svg +14 -0
  156. package/assets/archimate4/icons/capability.svg +40 -0
  157. package/assets/archimate4/icons/collaboration.svg +21 -0
  158. package/assets/archimate4/icons/communication-network.svg +18 -0
  159. package/assets/archimate4/icons/course-of-action.svg +20 -0
  160. package/assets/archimate4/icons/data-object.svg +14 -0
  161. package/assets/archimate4/icons/deliverable.svg +11 -0
  162. package/assets/archimate4/icons/device.svg +18 -0
  163. package/assets/archimate4/icons/distribution-network.svg +19 -0
  164. package/assets/archimate4/icons/driver.svg +24 -0
  165. package/assets/archimate4/icons/equipment.svg +31 -0
  166. package/assets/archimate4/icons/event.svg +15 -0
  167. package/assets/archimate4/icons/facility.svg +16 -0
  168. package/assets/archimate4/icons/function.svg +13 -0
  169. package/assets/archimate4/icons/glyphs/activity.svg +3 -0
  170. package/assets/archimate4/icons/glyphs/actor.svg +14 -0
  171. package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
  172. package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
  173. package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
  174. package/assets/archimate4/icons/glyphs/capability.svg +32 -0
  175. package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
  176. package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
  177. package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
  178. package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
  179. package/assets/archimate4/icons/glyphs/contract.svg +5 -0
  180. package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
  181. package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
  182. package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
  183. package/assets/archimate4/icons/glyphs/device.svg +10 -0
  184. package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
  185. package/assets/archimate4/icons/glyphs/driver.svg +16 -0
  186. package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
  187. package/assets/archimate4/icons/glyphs/event.svg +6 -0
  188. package/assets/archimate4/icons/glyphs/facility.svg +7 -0
  189. package/assets/archimate4/icons/glyphs/function.svg +6 -0
  190. package/assets/archimate4/icons/glyphs/gap.svg +14 -0
  191. package/assets/archimate4/icons/glyphs/goal.svg +10 -0
  192. package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
  193. package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
  194. package/assets/archimate4/icons/glyphs/interface.svg +8 -0
  195. package/assets/archimate4/icons/glyphs/location.svg +6 -0
  196. package/assets/archimate4/icons/glyphs/material.svg +12 -0
  197. package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
  198. package/assets/archimate4/icons/glyphs/node.svg +8 -0
  199. package/assets/archimate4/icons/glyphs/object.svg +4 -0
  200. package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
  201. package/assets/archimate4/icons/glyphs/path.svg +10 -0
  202. package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
  203. package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
  204. package/assets/archimate4/icons/glyphs/principle.svg +12 -0
  205. package/assets/archimate4/icons/glyphs/process.svg +6 -0
  206. package/assets/archimate4/icons/glyphs/product.svg +4 -0
  207. package/assets/archimate4/icons/glyphs/representation.svg +4 -0
  208. package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
  209. package/assets/archimate4/icons/glyphs/resource.svg +14 -0
  210. package/assets/archimate4/icons/glyphs/role.svg +6 -0
  211. package/assets/archimate4/icons/glyphs/service.svg +6 -0
  212. package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
  213. package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
  214. package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
  215. package/assets/archimate4/icons/glyphs/value.svg +3 -0
  216. package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
  217. package/assets/archimate4/icons/goal.svg +18 -0
  218. package/assets/archimate4/icons/grouping.svg +12 -0
  219. package/assets/archimate4/icons/location.svg +14 -0
  220. package/assets/archimate4/icons/material.svg +21 -0
  221. package/assets/archimate4/icons/meaning.svg +11 -0
  222. package/assets/archimate4/icons/node.svg +14 -0
  223. package/assets/archimate4/icons/or-junction.svg +3 -0
  224. package/assets/archimate4/icons/outcome.svg +25 -0
  225. package/assets/archimate4/icons/path.svg +18 -0
  226. package/assets/archimate4/icons/plateau.svg +16 -0
  227. package/assets/archimate4/icons/principle.svg +21 -0
  228. package/assets/archimate4/icons/process.svg +15 -0
  229. package/assets/archimate4/icons/product.svg +12 -0
  230. package/assets/archimate4/icons/requirement.svg +14 -0
  231. package/assets/archimate4/icons/resource.svg +23 -0
  232. package/assets/archimate4/icons/role.svg +16 -0
  233. package/assets/archimate4/icons/service.svg +13 -0
  234. package/assets/archimate4/icons/stakeholder.svg +15 -0
  235. package/assets/archimate4/icons/system-software.svg +22 -0
  236. package/assets/archimate4/icons/technology-interface.svg +16 -0
  237. package/assets/archimate4/icons/value-stream.svg +11 -0
  238. package/assets/archimate4/icons/value.svg +11 -0
  239. package/assets/archimate4/icons/work-package.svg +12 -0
  240. package/assets/basic/basic-metamodel.ttl +100 -0
  241. package/assets/basic/basic-notation-bubble.ttl +175 -0
  242. package/assets/basic/basic-notation.ttl +172 -0
  243. package/assets/basic/basic-onto.ttl +171 -0
  244. package/assets/basic/basic-presentation-contexts.ttl +70 -0
  245. package/assets/basic/basic-tax.ttl +130 -0
  246. package/assets/basic/icons/aggregation.svg +7 -0
  247. package/assets/basic/icons/association.svg +6 -0
  248. package/assets/basic/icons/element.svg +5 -0
  249. package/assets/basic/icons/glyphs/aggregation.svg +6 -0
  250. package/assets/basic/icons/glyphs/association.svg +5 -0
  251. package/assets/basic/icons/glyphs/element.svg +5 -0
  252. package/assets/basic/icons/glyphs/relationship.svg +5 -0
  253. package/assets/basic/icons/relationship.svg +7 -0
  254. package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
  255. package/assets/basic/notation-bubble/icons/association.svg +6 -0
  256. package/assets/basic/notation-bubble/icons/element.svg +5 -0
  257. package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
  258. package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
  259. package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
  260. package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
  261. package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
  262. package/assets/catalog.ttl +7406 -0
  263. package/assets/core/core-notation.ttl +131 -0
  264. package/assets/core/core-onto.ttl +2811 -0
  265. package/assets/core/core-questions.ttl +957 -0
  266. package/assets/core/core-shapes.ttl +915 -0
  267. package/assets/core/core-vis-onto.ttl +1408 -0
  268. package/assets/core/core-vis-shapes.ttl +851 -0
  269. package/assets/core-vis/markers/circle-dot.svg +3 -0
  270. package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
  271. package/assets/core-vis/markers/filled-diamond.svg +3 -0
  272. package/assets/core-vis/markers/half-arrowhead.svg +3 -0
  273. package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
  274. package/assets/core-vis/markers/hollow-diamond.svg +3 -0
  275. package/assets/core-vis/markers/open-arrowhead.svg +3 -0
  276. package/fixtures/interoperability/archimate4-demo.trig +259 -0
  277. package/fixtures/interoperability/expected-findings.json +26 -0
  278. package/fixtures/interoperability/shop-seed.ttl +225 -0
  279. package/package.json +136 -4
  280. package/scripts/sync-assets.mjs +252 -0
  281. package/src/conformance.ts +66 -0
  282. package/src/import-export/model-io.ts +426 -0
  283. package/src/index.ts +11 -0
  284. package/src/metamodel-manager/asset-sources.ts +754 -0
  285. package/src/metamodel-manager/bundled-assets.ts +599 -0
  286. package/src/metamodel-manager/catalogue.ts +114 -0
  287. package/src/metamodel-manager/class-hierarchy.ts +155 -0
  288. package/src/metamodel-manager/index.ts +65 -0
  289. package/src/metamodel-manager/interfaces.ts +422 -0
  290. package/src/metamodel-manager/metamodel-completeness.ts +162 -0
  291. package/src/metamodel-manager/metamodel-loader.ts +864 -0
  292. package/src/metamodel-manager/notation-resolver.ts +284 -0
  293. package/src/metamodel-manager/notation.ts +659 -0
  294. package/src/metamodel-manager/palette-generator.ts +882 -0
  295. package/src/metamodel-manager/property-shapes.ts +290 -0
  296. package/src/metamodel-manager/taxonomy.ts +904 -0
  297. package/src/metamodel-manager/type-guide.ts +241 -0
  298. package/src/metamodel-manager/viewpoint-manager.ts +147 -0
  299. package/src/model-manager/appearance.ts +389 -0
  300. package/src/model-manager/cascade.ts +246 -0
  301. package/src/model-manager/clipboard.ts +566 -0
  302. package/src/model-manager/context-names.ts +108 -0
  303. package/src/model-manager/custom-properties.ts +549 -0
  304. package/src/model-manager/derivations.ts +166 -0
  305. package/src/model-manager/direct-permissions.ts +182 -0
  306. package/src/model-manager/drawing-order.ts +119 -0
  307. package/src/model-manager/element-manager.ts +69 -0
  308. package/src/model-manager/element-pictures.ts +118 -0
  309. package/src/model-manager/field-names.ts +42 -0
  310. package/src/model-manager/folders.ts +354 -0
  311. package/src/model-manager/grid.ts +6 -0
  312. package/src/model-manager/index.ts +43 -0
  313. package/src/model-manager/interfaces.ts +417 -0
  314. package/src/model-manager/iri-conformance.ts +183 -0
  315. package/src/model-manager/label-expression.ts +233 -0
  316. package/src/model-manager/legacy-migration.ts +200 -0
  317. package/src/model-manager/missing-references.ts +86 -0
  318. package/src/model-manager/model-diff-text.ts +150 -0
  319. package/src/model-manager/model-diff.ts +534 -0
  320. package/src/model-manager/model-merge.ts +1160 -0
  321. package/src/model-manager/model-namespace.ts +199 -0
  322. package/src/model-manager/model-operations.ts +132 -0
  323. package/src/model-manager/model-queries.ts +616 -0
  324. package/src/model-manager/model-session.ts +759 -0
  325. package/src/model-manager/multiplicity.ts +74 -0
  326. package/src/model-manager/nested-resources.ts +145 -0
  327. package/src/model-manager/own-metamodel.ts +157 -0
  328. package/src/model-manager/placement-copy.ts +116 -0
  329. package/src/model-manager/property-catalog.ts +787 -0
  330. package/src/model-manager/proposal-order.ts +203 -0
  331. package/src/model-manager/provenance.ts +396 -0
  332. package/src/model-manager/questions.ts +475 -0
  333. package/src/model-manager/rdf-scope.ts +97 -0
  334. package/src/model-manager/relationship-graph.ts +462 -0
  335. package/src/model-manager/relationship-manager.ts +962 -0
  336. package/src/model-manager/relationship-table.ts +189 -0
  337. package/src/model-manager/relationship-validity.ts +261 -0
  338. package/src/model-manager/resource-edits.ts +28 -0
  339. package/src/model-manager/short-hash.ts +104 -0
  340. package/src/model-manager/snapshot-lines.ts +88 -0
  341. package/src/model-manager/version-history.ts +205 -0
  342. package/src/model-manager/view-from-results.ts +81 -0
  343. package/src/model-manager/view-manager.ts +1410 -0
  344. package/src/model-manager/vocabulary.ts +279 -0
  345. package/src/rdf-engine/finding-shape.ts +23 -0
  346. package/src/rdf-engine/graph-scope.ts +163 -0
  347. package/src/rdf-engine/index.ts +7 -0
  348. package/src/rdf-engine/interfaces.ts +144 -0
  349. package/src/rdf-engine/iri.ts +203 -0
  350. package/src/rdf-engine/localized-text.ts +13 -0
  351. package/src/rdf-engine/namespaces.ts +41 -0
  352. package/src/rdf-engine/native-load.ts +37 -0
  353. package/src/rdf-engine/observable-store.ts +609 -0
  354. package/src/rdf-engine/rdf-store.ts +520 -0
  355. package/src/rdf-engine/shacl-validator.ts +602 -0
  356. package/src/rdf-engine/shape-reach.ts +140 -0
  357. package/src/rdf-engine/shape-switches.ts +165 -0
  358. package/src/rdf-engine/single-valued.ts +219 -0
  359. package/src/rdf-engine/sparql-constraints.ts +349 -0
  360. package/src/rdf-engine/term-codec.ts +51 -0
  361. package/src/rdf-engine/ttl-parser.ts +51 -0
  362. package/src/rdf-engine/ttl-serializer.ts +79 -0
  363. package/src/rdf-engine/turtle-writer.ts +284 -0
  364. package/src/rdf-engine/validation-engine.ts +747 -0
  365. package/src/rdf-engine/validation-service.ts +186 -0
  366. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,759 @@
1
+ /**
2
+ * The model being edited, and which of its views is open.
3
+ *
4
+ * The store can hold only one model's data at a time (its default graph — see
5
+ * `model-queries.ts`), and exactly one view is on the canvas. This class owns
6
+ * those two facts and the operations that change them: starting a new model,
7
+ * adopting one that was just loaded, and creating, opening, renaming and
8
+ * deleting views. It emits the events the UI re-renders from, and nothing
9
+ * here touches the canvas directly.
10
+ *
11
+ * ```turtle
12
+ * m:model a arch:Model ;
13
+ * skos:prefLabel "Order Platform"@en ;
14
+ * vann:preferredNamespacePrefix "m" ;
15
+ * vann:preferredNamespaceUri "https://example.org/archimate/3f2c…/" ;
16
+ * arch:modelConformsToMetamodel am4mm:ArchiMate4 ;
17
+ * dcterms:created "2026-09-25T…"^^xsd:dateTime .
18
+ * ```
19
+ *
20
+ * The namespace is where every IRI of the model is minted (see
21
+ * `model-namespace.ts`); a new model gets one under the configured base,
22
+ * `https://example.org/` by default.
23
+ */
24
+
25
+ import type { Quad } from '@rdfjs/types';
26
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
27
+ import { DEFAULT_MODEL_BASE, ensureNamespace, mintModelNamespace, modelIriIn, notationSlug } from '../rdf-engine/iri.js';
28
+ import type { Bounds, ElementManager, Point, RelationshipManager, ViewKind, ViewManager } from './interfaces.js';
29
+ import { migrateLegacyModel, type MigrationReport } from './legacy-migration.js';
30
+ import { addRelationshipsToView } from './view-manager.js';
31
+ import { classify, findModelIri, labelOf, modelQuads, typeClosure } from './model-queries.js';
32
+ import {
33
+ DEFAULT_MODEL_PREFIX,
34
+ declaredNamespaceQuads,
35
+ namespaceQuads,
36
+ planNamespaceChange,
37
+ readModelNamespace,
38
+ type ModelNamespace,
39
+ } from './model-namespace.js';
40
+ import { IRI, T, dateTimeLiteral, langLiteral, nn, triple, tripleTerm } from './vocabulary.js';
41
+ import type { NamedNode } from '@rdfjs/types';
42
+
43
+ /** The default graph: the model. */
44
+ const MODEL_GRAPH = { termType: 'DefaultGraph', value: '' } as unknown as NamedNode;
45
+ import { isQualifiedPredicate, qualifiedFormOf, relationshipClassOf, unqualifiedFormOf } from './cascade.js';
46
+ import { certaintyNamed, isCertaintyPredicate, isLedTo } from './derivations.js';
47
+ import { AUTO_LAYOUT } from './grid.js';
48
+ import { keyDigest } from './short-hash.js';
49
+
50
+ /** The slice of the event bus the session needs; structural so it stays UI-free. */
51
+ export interface SessionEvents {
52
+ emit(type: string, detail?: Record<string, unknown>): void;
53
+ }
54
+
55
+ /** Name given to the view every new model starts with. */
56
+ export const DEFAULT_VIEW_LABEL = 'Default View';
57
+
58
+
59
+ /** Result of {@link ModelSession.adopt}. */
60
+ export interface AdoptResult {
61
+ modelIri: string;
62
+ viewIri: string;
63
+ migration: MigrationReport;
64
+ /** Elements placed by the automatic layout (0 when the model had geometry). */
65
+ autoPlaced: number;
66
+ /** Relationships the model stated only as a direct triple, now each a resource (see `ensureRelationshipResources`). */
67
+ qualified: number;
68
+ }
69
+
70
+ export class ModelSession {
71
+ private currentModel: string | undefined;
72
+ private currentView: string | undefined;
73
+ /** The model's namespace when it was last looked at — kept to follow a remote rename. */
74
+ private currentNamespace: string | undefined;
75
+
76
+ constructor(
77
+ private readonly store: RdfStore,
78
+ private readonly elements: ElementManager,
79
+ private readonly views: ViewManager,
80
+ private readonly events?: SessionEvents,
81
+ private readonly options: { base?: string; relationships?: RelationshipManager } = {},
82
+ ) {}
83
+
84
+ /** Base new models are minted under; `https://example.org/` unless configured. */
85
+ get base(): string {
86
+ return this.options.base ?? DEFAULT_MODEL_BASE;
87
+ }
88
+
89
+ /** IRI of the `arch:Model` being edited. */
90
+ get modelIri(): string | undefined {
91
+ return this.currentModel;
92
+ }
93
+
94
+ /** IRI of the view on the canvas. */
95
+ get activeViewIri(): string | undefined {
96
+ return this.currentView;
97
+ }
98
+
99
+ /** The model's label, or a placeholder. */
100
+ modelLabel(): string {
101
+ return this.currentModel ? labelOf(this.store, this.currentModel) : 'Untitled model';
102
+ }
103
+
104
+ /** The model's namespace and prefix (what `m:` stands for). */
105
+ namespace(): ModelNamespace | undefined {
106
+ return this.currentModel ? readModelNamespace(this.store, this.currentModel) : undefined;
107
+ }
108
+
109
+ /** The metamodels the model declares conformance to. */
110
+ metamodelIris(): string[] {
111
+ if (!this.currentModel) return [];
112
+ return this.store.getQuads(nn(this.currentModel), T.modelConformsToMetamodel).map((q) => q.object.value);
113
+ }
114
+
115
+ // ── Model lifecycle ────────────────────────────────────────────────────
116
+
117
+ /** Remove every quad of the model data. Metamodel graphs are untouched. */
118
+ clearModelData(): void {
119
+ const quads = modelQuads(this.store);
120
+ if (quads.length > 0) this.store.removeQuads(quads);
121
+ this.currentModel = undefined;
122
+ this.currentView = undefined;
123
+ this.currentNamespace = undefined;
124
+ }
125
+
126
+ /**
127
+ * Start a fresh model with one empty diagram view.
128
+ *
129
+ * @param options.metamodelIris Conformance statements to write.
130
+ * @param options.namespace The model's namespace; minted under `base` when omitted.
131
+ * @param options.base Base to mint the namespace under; the session's otherwise.
132
+ * @param options.prefix Prefix for the namespace, `m` by default.
133
+ */
134
+ newModel(
135
+ options: { label?: string; metamodelIris?: string[]; base?: string; namespace?: string; prefix?: string } = {},
136
+ ): {
137
+ modelIri: string;
138
+ viewIri: string;
139
+ } {
140
+ this.clearModelData();
141
+ const metamodels = options.metamodelIris ?? [];
142
+ const namespace = options.namespace?.trim()
143
+ ? ensureNamespace(options.namespace)
144
+ : mintModelNamespace(options.base ?? this.base, notationSlug(metamodels[0]));
145
+ const modelIri = modelIriIn(namespace);
146
+ const model = nn(modelIri);
147
+ const quads: Quad[] = [
148
+ triple(model, T.rdfType, T.Model),
149
+ triple(model, T.prefLabel, langLiteral(options.label?.trim() || 'Untitled model')),
150
+ ...namespaceQuads(modelIri, namespace, options.prefix?.trim() || DEFAULT_MODEL_PREFIX),
151
+ triple(model, nn(IRI.dctermsCreated), dateTimeLiteral()),
152
+ ...metamodels.map((mm) => triple(model, T.modelConformsToMetamodel, nn(mm))),
153
+ ];
154
+ this.store.addQuads(quads);
155
+ this.currentModel = modelIri;
156
+ this.currentNamespace = namespace;
157
+ const viewIri = this.views.createView('Diagram', undefined, { label: DEFAULT_VIEW_LABEL, modelIri }).value;
158
+ this.currentView = viewIri;
159
+ this.events?.emit('model-loaded', { modelIri, viewIri, fresh: true });
160
+ this.events?.emit('view-opened', { viewIri });
161
+ return { modelIri, viewIri };
162
+ }
163
+
164
+ /**
165
+ * Take ownership of model data that was just put into the store (a file, an
166
+ * import, a collaboration room).
167
+ *
168
+ * Migrates retired vocabulary, makes sure there is an `arch:Model` and that
169
+ * every concept names it, makes sure there is a view to open, and — when the
170
+ * data carries no geometry at all — lays the elements out in a grid so the
171
+ * model is not an empty canvas.
172
+ */
173
+ adopt(options: { fallbackLabel?: string; metamodelIris?: string[]; emit?: boolean } = {}): AdoptResult {
174
+ let modelIri = findModelIri(this.store);
175
+ let defaultView: string | undefined;
176
+ const ensureDefaultView = (): string => {
177
+ if (!defaultView) {
178
+ defaultView =
179
+ this.views.getViews().find((v) => v.type === 'Diagram')?.iri ??
180
+ this.views.createView('Diagram', undefined, {
181
+ label: DEFAULT_VIEW_LABEL,
182
+ ...(modelIri ? { modelIri } : {}),
183
+ }).value;
184
+ }
185
+ return defaultView;
186
+ };
187
+
188
+ if (!modelIri) {
189
+ const namespace = mintModelNamespace(this.base, notationSlug(options.metamodelIris?.[0]));
190
+ modelIri = modelIriIn(namespace);
191
+ const model = nn(modelIri);
192
+ this.store.addQuads([
193
+ triple(model, T.rdfType, T.Model),
194
+ triple(model, T.prefLabel, langLiteral(options.fallbackLabel?.trim() || 'Imported model')),
195
+ ...namespaceQuads(modelIri, namespace),
196
+ ...(options.metamodelIris ?? []).map((mm) => triple(model, T.modelConformsToMetamodel, nn(mm))),
197
+ ]);
198
+ }
199
+ this.currentModel = modelIri;
200
+ this.currentNamespace = readModelNamespace(this.store, modelIri).namespace;
201
+
202
+ const migration = migrateLegacyModel(this.store, { viewManager: this.views, defaultView: ensureDefaultView });
203
+ // Before the repairs: the `rdf:reifies` they give an older relationship does not make it one.
204
+ const unstated = this.unstated();
205
+ this.ensureMembership(modelIri, unstated);
206
+ this.ensureReifies();
207
+ const qualified = this.ensureRelationshipResources(modelIri);
208
+ this.ensureQualifiedPointers(unstated);
209
+
210
+ // A view to open: the first diagram, else a new one.
211
+ const viewIri = ensureDefaultView();
212
+ const autoPlaced = this.autoLayoutIfNoGeometry(viewIri);
213
+
214
+ this.currentView = viewIri;
215
+ if (options.emit !== false) {
216
+ this.events?.emit('model-loaded', { modelIri, viewIri });
217
+ this.events?.emit('view-opened', { viewIri });
218
+ }
219
+ return { modelIri, viewIri, migration, autoPlaced, qualified };
220
+ }
221
+
222
+ /** Rename the model. */
223
+ renameModel(label: string): void {
224
+ if (!this.currentModel || !label.trim()) return;
225
+ const model = nn(this.currentModel);
226
+ const stale = this.store.getQuads(model, T.prefLabel);
227
+ if (stale.length > 0) this.store.removeQuads(stale);
228
+ this.store.addQuads([triple(model, T.prefLabel, langLiteral(label.trim()))]);
229
+ this.touch();
230
+ this.events?.emit('model-changed', { renamed: true });
231
+ }
232
+
233
+ /**
234
+ * Set the model's namespace (and prefix).
235
+ *
236
+ * With `rename` (the default) the model's existing IRIs move into the new
237
+ * namespace — see {@link planNamespaceChange} — and the canvas re-opens the
238
+ * same view under its new IRI. Without it only IRIs minted from now on use
239
+ * the new namespace. Either way it is one store change, so collaborators
240
+ * receive it as one update and follow it ({@link resync}).
241
+ *
242
+ * @returns The IRIs that changed, old → new.
243
+ */
244
+ setNamespace(namespace: string, options: { prefix?: string; rename?: boolean } = {}): Map<string, string> {
245
+ const modelIri = this.currentModel;
246
+ if (!modelIri) return new Map();
247
+ const current = readModelNamespace(this.store, modelIri);
248
+ const target = ensureNamespace(namespace);
249
+ const prefix = options.prefix?.trim() || current.prefix;
250
+ const plan =
251
+ options.rename === false
252
+ ? { mapping: new Map<string, string>(), remove: [], add: [] }
253
+ : planNamespaceChange(this.store, modelIri, current.namespace, target);
254
+ const nextModel = plan.mapping.get(modelIri) ?? modelIri;
255
+ const stale = declaredNamespaceQuads(this.store, modelIri);
256
+ const unchanged = plan.mapping.size === 0 && current.declared && current.namespace === target && current.prefix === prefix;
257
+ if (unchanged) return plan.mapping;
258
+
259
+ this.batch(() => {
260
+ const removed = [...stale, ...plan.remove];
261
+ if (removed.length > 0) this.store.removeQuads(removed);
262
+ this.store.addQuads([...plan.add, ...namespaceQuads(nextModel, target, prefix)]);
263
+ this.currentModel = nextModel;
264
+ this.touch();
265
+ });
266
+ this.currentNamespace = target;
267
+ const nextView = this.currentView ? plan.mapping.get(this.currentView) : undefined;
268
+ if (nextView) this.currentView = nextView;
269
+
270
+ if (plan.mapping.size > 0) {
271
+ // Every IRI on the canvas may have changed: re-open the view. The model's old IRI goes
272
+ // with it, for what is kept by it (the Git module's binding to a file).
273
+ this.events?.emit('model-loaded', {
274
+ modelIri: nextModel,
275
+ viewIri: this.currentView,
276
+ renamed: true,
277
+ ...(nextModel !== modelIri ? { previousModelIri: modelIri } : {}),
278
+ });
279
+ }
280
+ this.events?.emit('model-changed', { namespace: target });
281
+ return plan.mapping;
282
+ }
283
+
284
+ /**
285
+ * Follow a change that replaced the model resource in the store — a namespace
286
+ * change, or a new model — made elsewhere: by a collaborator, or (`moved`) by
287
+ * a merge or a version from Git that has the model under another IRI.
288
+ * Re-points the session at the model now in the store and at the same view
289
+ * under its new IRI when there is one, then emits `model-loaded`.
290
+ *
291
+ * The event carries the IRI the model had, `previousModelIri`, when it is the
292
+ * same model moved: for a collaborator's change when its view is there under
293
+ * the same local part, and always for a `moved` one — the merge or the
294
+ * version is of the same file, which the model stays bound to (DD-41).
295
+ *
296
+ * @returns Whether anything was re-pointed.
297
+ */
298
+ resync(options: { moved?: boolean } = {}): boolean {
299
+ const modelIri = this.currentModel;
300
+ if (!modelIri) return false;
301
+ const stillThere = this.store
302
+ .getQuads(nn(modelIri), T.rdfType, T.Model)
303
+ .some((q) => q.graph.termType === 'DefaultGraph');
304
+ if (stillThere) return false;
305
+ const next = findModelIri(this.store);
306
+ if (!next) return false;
307
+
308
+ const namespace = readModelNamespace(this.store, next).namespace;
309
+ const previous = this.currentNamespace;
310
+ let view: string | undefined;
311
+ if (this.currentView && previous && this.currentView.startsWith(previous)) {
312
+ // A move keeps the local part (DD-41).
313
+ const moved = `${namespace}${this.currentView.slice(previous.length)}`;
314
+ if (this.views.getView(moved)) view = moved;
315
+ }
316
+ this.currentModel = next;
317
+ this.currentNamespace = namespace;
318
+ this.currentView = view ?? this.views.getViews().find((v) => v.type === 'Diagram')?.iri ?? this.views.getViews()[0]?.iri;
319
+ this.events?.emit('model-loaded', {
320
+ modelIri: next,
321
+ viewIri: this.currentView,
322
+ ...(options.moved ? { renamed: true } : { remote: true }),
323
+ // The same model moved, its view there under the same local part — not another model started in the room.
324
+ ...(view || options.moved ? { previousModelIri: modelIri } : {}),
325
+ });
326
+ return true;
327
+ }
328
+
329
+ /**
330
+ * Replace the model's metamodel conformance statements — while the model is
331
+ * there: a file being opened has replaced it already, and the metamodels the
332
+ * file declares are loaded before it is adopted, so writing them for the
333
+ * model being left would put a statement about it among the file's triples,
334
+ * saved with them.
335
+ */
336
+ setMetamodels(metamodelIris: string[]): void {
337
+ if (!this.currentModel) return;
338
+ const model = nn(this.currentModel);
339
+ if (this.store.getQuads(model, T.rdfType, T.Model).length === 0) return;
340
+ const stale = this.store.getQuads(model, T.modelConformsToMetamodel);
341
+ if (stale.length > 0) this.store.removeQuads(stale);
342
+ this.store.addQuads(metamodelIris.map((mm) => triple(model, T.modelConformsToMetamodel, nn(mm))));
343
+ }
344
+
345
+ // ── Views ──────────────────────────────────────────────────────────────
346
+
347
+ /** Put a view on the canvas. */
348
+ openView(viewIri: string): void {
349
+ if (!this.views.getView(viewIri)) return;
350
+ this.currentView = viewIri;
351
+ this.events?.emit('view-opened', { viewIri });
352
+ }
353
+
354
+ /** The open view, or the first diagram, or a new one — always something. */
355
+ ensureView(): string {
356
+ if (this.currentView && this.views.getView(this.currentView)) return this.currentView;
357
+ const first = this.views.getViews().find((v) => v.type === 'Diagram');
358
+ const viewIri =
359
+ first?.iri ??
360
+ this.views.createView('Diagram', undefined, {
361
+ label: DEFAULT_VIEW_LABEL,
362
+ ...(this.currentModel ? { modelIri: this.currentModel } : {}),
363
+ }).value;
364
+ this.currentView = viewIri;
365
+ return viewIri;
366
+ }
367
+
368
+ createView(kind: ViewKind, options: { label?: string; viewpointIri?: string; open?: boolean; folderIri?: string } = {}): string {
369
+ let viewIri = '';
370
+ // Made and filed in its folder (Req 10.16) as one change, which collaborators receive as one update.
371
+ this.batch(() => {
372
+ viewIri = this.views.createView(kind, options.viewpointIri, {
373
+ label: options.label?.trim() || `New ${kind.toLowerCase()}`,
374
+ ...(this.currentModel ? { modelIri: this.currentModel } : {}),
375
+ }).value;
376
+ if (options.folderIri) this.store.addQuads([triple(nn(viewIri), T.dctermsIsPartOf, nn(options.folderIri))]);
377
+ });
378
+ this.events?.emit('views-changed', { viewIri });
379
+ if (options.open !== false) this.openView(viewIri);
380
+ return viewIri;
381
+ }
382
+
383
+ /**
384
+ * A new diagram showing these elements, where given, and the relationships
385
+ * among them, following `viewpointIri` when given — one change for
386
+ * collaborators; opened unless `open` is false.
387
+ */
388
+ createViewWith(
389
+ label: string,
390
+ nodes: ReadonlyArray<{ iri: string; bounds: Bounds }>,
391
+ relationships: readonly string[],
392
+ options: { open?: boolean; viewpointIri?: string; routes?: ReadonlyMap<string, Point[]> } = {},
393
+ ): string {
394
+ let viewIri = '';
395
+ this.batch(() => {
396
+ viewIri = this.views.createView('Diagram', options.viewpointIri, {
397
+ label: label.trim() || 'New diagram',
398
+ ...(this.currentModel ? { modelIri: this.currentModel } : {}),
399
+ }).value;
400
+ for (const node of nodes) this.views.addElementToView(viewIri, node.iri, node.bounds);
401
+ addRelationshipsToView(this.views, viewIri, relationships);
402
+ // Routed by the layout (ELK task, R10): by relationship, its line in this view.
403
+ for (const [relationshipIri, route] of options.routes ?? []) this.views.updateLinkWaypoints(viewIri, relationshipIri, route);
404
+ this.touch();
405
+ });
406
+ this.events?.emit('views-changed', { viewIri });
407
+ if (options.open !== false) this.openView(viewIri);
408
+ return viewIri;
409
+ }
410
+
411
+ renameView(viewIri: string, label: string): void {
412
+ this.views.renameView(viewIri, label);
413
+ this.events?.emit('views-changed', { viewIri });
414
+ }
415
+
416
+ setViewpoint(viewIri: string, viewpointIri: string | undefined): void {
417
+ this.views.setViewpoint(viewIri, viewpointIri);
418
+ this.events?.emit('views-changed', { viewIri });
419
+ }
420
+
421
+ duplicateView(viewIri: string): string {
422
+ const copy = this.views.duplicateView(viewIri).value;
423
+ this.events?.emit('views-changed', { viewIri: copy });
424
+ return copy;
425
+ }
426
+
427
+ /** Delete a view; its concepts stay in the model. Opens another if it was open. */
428
+ deleteView(viewIri: string): void {
429
+ this.views.deleteView(viewIri);
430
+ this.events?.emit('views-changed', { viewIri });
431
+ if (this.currentView === viewIri) {
432
+ this.currentView = undefined;
433
+ this.openView(this.ensureView());
434
+ }
435
+ }
436
+
437
+ // ── Internals ──────────────────────────────────────────────────────────
438
+
439
+ /** Stamp `dcterms:modified`. */
440
+ /** One change notification for `fn`'s edits, when the store can batch. */
441
+ private batch(fn: () => void): void {
442
+ const batching = this.store as RdfStore & { batch?: <R>(f: () => R) => R };
443
+ if (typeof batching.batch === 'function') batching.batch(fn);
444
+ else fn();
445
+ }
446
+
447
+ private touch(): void {
448
+ if (!this.currentModel) return;
449
+ const model = nn(this.currentModel);
450
+ const stale = this.store.getQuads(model, nn(IRI.dctermsModified));
451
+ if (stale.length > 0) this.store.removeQuads(stale);
452
+ this.store.addQuads([triple(model, nn(IRI.dctermsModified), dateTimeLiteral())]);
453
+ }
454
+
455
+ /**
456
+ * The resources that are propositions, not relationships of the model (core's
457
+ * `arch:QualifiedRelationship`): each reifies a triple the model does not
458
+ * assert, with no qualified predicate leading to it — a potential derivation,
459
+ * until a modeller confirms it. Loading leaves them as they are: a qualified
460
+ * predicate leading to one is half of confirming it.
461
+ */
462
+ private propositions(): Set<string> {
463
+ const found = new Set<string>();
464
+ const model = MODEL_GRAPH;
465
+ for (const q of this.store.getQuads(null, T.reifies, null, model)) {
466
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'Quad') continue;
467
+ const { subject, predicate, object } = q.object as unknown as Quad;
468
+ if (this.store.getQuads(subject as NamedNode, predicate as NamedNode, object as NamedNode, model).length > 0) continue;
469
+ const incoming = this.store.getQuads(null, null, nn(q.subject.value), model);
470
+ if (incoming.some((p) => isQualifiedPredicate(this.store, p.predicate.value))) continue;
471
+ found.add(q.subject.value);
472
+ }
473
+ return found;
474
+ }
475
+
476
+ /**
477
+ * The resources that are not relationships the model states: its
478
+ * propositions; its valid derivations, which hold but which nobody stated; and
479
+ * its potential derivations no qualified predicate leads to, though another
480
+ * derivation of the same triple was confirmed (`derivations.ts`). A potential
481
+ * derivation a modeller confirmed is stated.
482
+ */
483
+ private unstated(): Set<string> {
484
+ const found = this.propositions();
485
+ for (const q of this.store.getQuads(null, null, null, MODEL_GRAPH)) {
486
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode' || !isCertaintyPredicate(q.predicate.value)) continue;
487
+ const certainty = certaintyNamed(q.object.value);
488
+ if (certainty === 'valid' || (certainty === 'potential' && !isLedTo(this.store, q.subject.value))) found.add(q.subject.value);
489
+ }
490
+ return found;
491
+ }
492
+
493
+ /**
494
+ * Every element, relationship and view names its model (DD-15: membership is
495
+ * asserted, not implied by the graph). Data from another tool often omits it.
496
+ * A derivation the model does not state gets none: it is not part of what was
497
+ * modelled.
498
+ */
499
+ private ensureMembership(modelIri: string, unstated: ReadonlySet<string>): void {
500
+ const closure = typeClosure(this.store);
501
+ const typesOf = new Map<string, string[]>();
502
+ const members = new Set<string>();
503
+ for (const q of modelQuads(this.store)) {
504
+ if (q.subject.termType !== 'NamedNode') continue;
505
+ if (q.predicate.value === IRI.rdfType) {
506
+ const list = typesOf.get(q.subject.value) ?? [];
507
+ list.push(q.object.value);
508
+ typesOf.set(q.subject.value, list);
509
+ } else if (q.predicate.value === IRI.inModel) {
510
+ members.add(q.subject.value);
511
+ }
512
+ }
513
+ const add: Quad[] = [];
514
+ const model = nn(modelIri);
515
+ for (const [iri, types] of typesOf) {
516
+ if (members.has(iri) || unstated.has(iri)) continue;
517
+ const kind = classify(types, closure, false);
518
+ if (kind === 'element' || kind === 'relationship' || kind === 'view' || kind === 'unclassified') {
519
+ add.push(triple(nn(iri), T.inModel, model));
520
+ }
521
+ }
522
+ if (add.length > 0) this.store.addQuads(add);
523
+ }
524
+
525
+ /**
526
+ * Give every qualified relationship the `rdf:reifies` of the unqualified
527
+ * triple its class maps to (the core's pattern, RDF 1.2), where it has none —
528
+ * a model saved before la-gram wrote it, or made by another tool. A
529
+ * relationship whose class has no `arch:unqualifiedForm` stands for no triple
530
+ * and gets none.
531
+ *
532
+ * And one whose triple term names other ends than the relationship's own
533
+ * `arch:source` and `arch:target` is made to name them again, its predicate
534
+ * kept: a namespace change before it rewrote triple terms moved every IRI of
535
+ * the model but those, leaving the relationship reifying a triple of IRIs the
536
+ * model no longer has.
537
+ */
538
+ private ensureReifies(): void {
539
+ const add: Quad[] = [];
540
+ const remove: Quad[] = [];
541
+ // The model's relationships, by index in the model graph (Task 22).
542
+ const model = MODEL_GRAPH;
543
+ for (const q of this.store.getQuads(null, T.source, null, model)) {
544
+ if (q.subject.termType !== 'NamedNode') continue;
545
+ const rel = q.subject.value;
546
+ const target = this.store.getQuads(nn(rel), T.target, null, model)[0]?.object;
547
+ const ends = q.object.termType === 'NamedNode' && target?.termType === 'NamedNode';
548
+ const reifies = this.store.getQuads(nn(rel), T.reifies, null, model);
549
+ if (reifies.length > 0) {
550
+ for (const r of reifies) {
551
+ if (!ends || r.object.termType !== 'Quad') continue;
552
+ const term = r.object as unknown as Quad;
553
+ if (term.subject.value === q.object.value && term.object.value === target!.value) continue;
554
+ remove.push(r);
555
+ add.push(triple(nn(rel), T.reifies, tripleTerm(nn(q.object.value), term.predicate, nn(target!.value))));
556
+ }
557
+ continue;
558
+ }
559
+ const classIri = relationshipClassOf(this.store, rel);
560
+ const predicate = classIri ? unqualifiedFormOf(this.store, classIri) : undefined;
561
+ if (!ends || !predicate) continue;
562
+ add.push(triple(nn(rel), T.reifies, tripleTerm(nn(q.object.value), nn(predicate), nn(target!.value))));
563
+ }
564
+ if (remove.length > 0) this.store.removeQuads(remove);
565
+ if (add.length > 0) this.store.addQuads(add);
566
+ }
567
+
568
+ /**
569
+ * Make a relationship resource for every relationship the model states only as a direct triple — a file
570
+ * written by a tool or by hand, `?option ad:modifiesConcept ?component`, or an ArchiMate file of bare
571
+ * `am4:serves` — so that it is listed, drawn and given properties as any other is (decision D6 of
572
+ * linked-archi-meta's `decision-modelling-layer` task).
573
+ *
574
+ * A triple qualifies when a loaded relationship class names its predicate as its `arch:unqualifiedForm`,
575
+ * both ends are concepts of the model, and no resource reifies it. The resource is what meta's rules make of
576
+ * it (the ArchiMate derivation rules' `:QualifyRelationships`): the most general class of that form (a bare
577
+ * triple says no more than that), `arch:source` and `arch:target`, `rdf:reifies` the triple, and the IRI
578
+ * `{ns}relationship/{digest}` of "s p o" in the model's namespace (DD-41; {@link keyDigest}). So two windows
579
+ * opening the same file in one collaboration room, or a run of the rules, make the same resource, not two. It
580
+ * gets `arch:inModel`, and {@link ensureQualifiedPointers}, after it, the qualified predicate from its source.
581
+ * One made before, named `relationship-{sha1}`, keeps its name: a tool never renames.
582
+ *
583
+ * A triple of a predicate declared the `owl:inverseOf` of a drawn one (`?task ap:taskOfActivity ?activity`,
584
+ * of `ap:hasTask`) is the same link read the other way: the resource is made for the drawn direction, and
585
+ * that direction's triple is stated beside the one the file has, as a drawn link states it.
586
+ *
587
+ * A predicate two unrelated classes name as their form is left as a triple: which of them it is, the
588
+ * triple does not say.
589
+ *
590
+ * @returns How many resources were made.
591
+ */
592
+ private ensureRelationshipResources(modelIri: string): number {
593
+ const closure = typeClosure(this.store);
594
+ const candidates = new Map<string, Set<string>>();
595
+ for (const q of this.store.getQuads(null, T.unqualifiedForm, null)) {
596
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
597
+ if (!closure(q.subject.value).includes(IRI.QualifiedRelationship)) continue;
598
+ const set = candidates.get(q.object.value) ?? new Set<string>();
599
+ set.add(q.subject.value);
600
+ candidates.set(q.object.value, set);
601
+ }
602
+ const classOf = new Map<string, string>();
603
+ for (const [predicate, classes] of candidates) {
604
+ const general = [...classes].filter((c) => !closure(c).some((parent) => parent !== c && classes.has(parent)));
605
+ if (general.length === 1) classOf.set(predicate, general[0]!);
606
+ }
607
+ if (classOf.size === 0) return 0;
608
+ // A predicate read the other way: its inverse is drawn.
609
+ const reversedOf = new Map<string, string>();
610
+ for (const q of this.store.getQuads(null, T.inverseOf, null)) {
611
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
612
+ const [x, y] = [q.subject.value, q.object.value];
613
+ if (classOf.has(y) && !classOf.has(x)) reversedOf.set(x, y);
614
+ if (classOf.has(x) && !classOf.has(y)) reversedOf.set(y, x);
615
+ }
616
+
617
+ const model = MODEL_GRAPH;
618
+ const reified = new Set<string>();
619
+ for (const q of this.store.getQuads(null, T.reifies, null, model)) {
620
+ if (q.object.termType !== 'Quad') continue;
621
+ const term = q.object as unknown as Quad;
622
+ reified.add(`${term.subject.value} ${term.predicate.value} ${term.object.value}`);
623
+ }
624
+ const typesOf = new Map<string, string[]>();
625
+ for (const q of this.store.getQuads(null, T.rdfType, null, model)) {
626
+ if (q.subject.termType !== 'NamedNode') continue;
627
+ const list = typesOf.get(q.subject.value) ?? [];
628
+ list.push(q.object.value);
629
+ typesOf.set(q.subject.value, list);
630
+ }
631
+ const isConcept = (iri: string): boolean => {
632
+ const types = typesOf.get(iri);
633
+ if (!types) return false;
634
+ const kind = classify(types, closure, true);
635
+ return kind === 'element' || kind === 'relationship' || kind === 'unclassified';
636
+ };
637
+
638
+ const namespace = ensureNamespace(this.currentNamespace ?? readModelNamespace(this.store, modelIri).namespace);
639
+ const add: Quad[] = [];
640
+ let made = 0;
641
+ const qualify = (source: string, predicate: string, target: string, stated: boolean): void => {
642
+ const key = `${source} ${predicate} ${target}`;
643
+ if (reified.has(key) || !isConcept(source) || !isConcept(target)) return;
644
+ reified.add(key);
645
+ made += 1;
646
+ const rel = nn(`${namespace}relationship/${keyDigest(key)}`);
647
+ add.push(
648
+ triple(rel, T.rdfType, nn(classOf.get(predicate)!)),
649
+ triple(rel, T.source, nn(source)),
650
+ triple(rel, T.target, nn(target)),
651
+ triple(rel, T.reifies, tripleTerm(nn(source), nn(predicate), nn(target))),
652
+ triple(rel, T.inModel, nn(modelIri)),
653
+ );
654
+ if (!stated) add.push(triple(nn(source), nn(predicate), nn(target)));
655
+ };
656
+ for (const predicate of classOf.keys()) {
657
+ for (const q of this.store.getQuads(null, nn(predicate), null, model)) {
658
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
659
+ qualify(q.subject.value, predicate, q.object.value, true);
660
+ }
661
+ }
662
+ for (const [inverse, predicate] of reversedOf) {
663
+ for (const q of this.store.getQuads(null, nn(inverse), null, model)) {
664
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
665
+ const stated = this.store.getQuads(nn(q.object.value), nn(predicate), nn(q.subject.value), model).length > 0;
666
+ qualify(q.object.value, predicate, q.subject.value, stated);
667
+ }
668
+ }
669
+ if (add.length > 0) this.store.addQuads(add);
670
+ return made;
671
+ }
672
+
673
+ /**
674
+ * Give every qualified relationship the qualified predicate leading to it
675
+ * from its source (`am4:qualifiedServing`, else core's
676
+ * `arch:hasQualifiedRelationship`), where it has none — a model saved before
677
+ * la-gram wrote it, or made by another tool. One it has, of whichever
678
+ * predicate, is kept. A derivation the model does not state gets none: for a
679
+ * potential one, that would be half of confirming it.
680
+ */
681
+ private ensureQualifiedPointers(unstated: ReadonlySet<string>): void {
682
+ const add: Quad[] = [];
683
+ const formOf = new Map<string, string>();
684
+ const qualified = new Map<string, boolean>();
685
+ const isQualified = (predicate: string): boolean => {
686
+ if (!qualified.has(predicate)) qualified.set(predicate, isQualifiedPredicate(this.store, predicate));
687
+ return qualified.get(predicate)!;
688
+ };
689
+ // The model's relationships, by index in the model graph (Task 22).
690
+ const model = MODEL_GRAPH;
691
+ for (const q of this.store.getQuads(null, T.source, null, model)) {
692
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
693
+ const rel = q.subject.value;
694
+ if (unstated.has(rel)) continue;
695
+ if (this.store.getQuads(nn(q.object.value), null, nn(rel), model).some((p) => isQualified(p.predicate.value))) continue;
696
+ const classIri = relationshipClassOf(this.store, rel) ?? IRI.QualifiedRelationship;
697
+ if (!formOf.has(classIri)) formOf.set(classIri, qualifiedFormOf(this.store, classIri));
698
+ add.push(triple(nn(q.object.value), nn(formOf.get(classIri)!), nn(rel)));
699
+ }
700
+ if (add.length > 0) this.store.addQuads(add);
701
+ }
702
+
703
+ /**
704
+ * When no view in the model has any geometry, place every element in a grid
705
+ * in `viewIri` (grouped by type), and draw every relationship between them.
706
+ */
707
+ private autoLayoutIfNoGeometry(viewIri: string): number {
708
+ const anyGeometry =
709
+ this.store.getQuads(null, T.rdfType, T.ArchNode).some((q) => q.graph.termType === 'DefaultGraph');
710
+ if (anyGeometry) return 0;
711
+
712
+ const closure = typeClosure(this.store);
713
+ const elements: Array<{ iri: string; type: string }> = [];
714
+ const typesOf = new Map<string, string[]>();
715
+ for (const q of modelQuads(this.store)) {
716
+ if (q.predicate.value !== IRI.rdfType || q.subject.termType !== 'NamedNode') continue;
717
+ const list = typesOf.get(q.subject.value) ?? [];
718
+ list.push(q.object.value);
719
+ typesOf.set(q.subject.value, list);
720
+ }
721
+ for (const [iri, types] of typesOf) {
722
+ const kind = classify(types, closure, true);
723
+ if (kind === 'element' || kind === 'unclassified') elements.push({ iri, type: types[0] });
724
+ }
725
+ elements.sort((a, b) => a.type.localeCompare(b.type) || labelOf(this.store, a.iri).localeCompare(labelOf(this.store, b.iri)));
726
+
727
+ elements.forEach(({ iri }, i) => {
728
+ const col = i % AUTO_LAYOUT.columns;
729
+ const row = Math.floor(i / AUTO_LAYOUT.columns);
730
+ this.views.addElementToView(viewIri, iri, {
731
+ x: AUTO_LAYOUT.x0 + col * AUTO_LAYOUT.dx,
732
+ y: AUTO_LAYOUT.y0 + row * AUTO_LAYOUT.dy,
733
+ width: AUTO_LAYOUT.width,
734
+ height: AUTO_LAYOUT.height,
735
+ });
736
+ });
737
+ if (elements.length > 0) this.linkAllPlaced(viewIri);
738
+ return elements.length;
739
+ }
740
+
741
+ /**
742
+ * Draw every relationship the model states whose two ends are placed in the
743
+ * view. A derivation it does not state is drawn only when asked for.
744
+ */
745
+ linkAllPlaced(viewIri: string): number {
746
+ const unstated = this.unstated();
747
+ const stated = this.store
748
+ .getQuads(null, T.source, null)
749
+ .filter((q) => q.graph.termType === 'DefaultGraph' && !unstated.has(q.subject.value))
750
+ .map((q) => q.subject.value);
751
+ // In passes: a relationship ending on another is drawn once that one is.
752
+ return addRelationshipsToView(this.views, viewIri, stated);
753
+ }
754
+
755
+ /** The element manager, for callers that received the session only. */
756
+ get elementManager(): ElementManager {
757
+ return this.elements;
758
+ }
759
+ }