@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,166 @@
1
+ /**
2
+ * Derived relationships: what a derivation rule concluded, not what a modeller
3
+ * stated (D29–D32; meta's DD-27 and DD-28).
4
+ *
5
+ * A rule writes a resource with the relationship's class and ends, its
6
+ * certainty (`…/derivation#derivationCertainty`: `Valid` or `Potential`), its
7
+ * premises (`prov:wasDerivedFrom`) and the derivation activity that generated
8
+ * it, whose association names the rule as its plan. A valid derivation also
9
+ * asserts the direct triple and the qualified predicate leading to it: it holds,
10
+ * though nobody stated it. A potential one asserts neither — a proposition —
11
+ * until a modeller confirms it by asserting both ({@link confirmationQuads});
12
+ * it then is a relationship of the model, its certainty kept as the record of
13
+ * the rule that proposed it.
14
+ *
15
+ * la-gram does not run the rules (they need a server-side engine); it shows
16
+ * what a model's file brings, and confirms.
17
+ */
18
+
19
+ import { DataFactory } from 'n3';
20
+ import type { NamedNode, Quad } from '@rdfjs/types';
21
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
22
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
23
+ import { isQualifiedPredicate, qualifiedFormOf, relationshipClassOf, unqualifiedFormOf } from './cascade.js';
24
+ import { IRI, T, localName, nn, triple } from './vocabulary.js';
25
+
26
+ /** The default graph: the model. */
27
+ const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
28
+
29
+ const PROV = NAMESPACES.prov;
30
+
31
+ /** How sure a rule is of what it derived (Appendix B of ArchiMate: valid or potential). */
32
+ export type DerivationCertainty = 'valid' | 'potential';
33
+
34
+ /** Whether a resource is derived, how surely, and whether a modeller has confirmed it. */
35
+ export interface DerivationStatus {
36
+ certainty: DerivationCertainty;
37
+ /**
38
+ * A potential derivation a qualified predicate leads to. Its triple alone does
39
+ * not say so: another derivation of the same triple, confirmed, asserts it too.
40
+ */
41
+ confirmed: boolean;
42
+ }
43
+
44
+ /** A derivation, with the rule that made it and what it was derived from. */
45
+ export interface DerivationDetails extends DerivationStatus {
46
+ /** The rule: the plan of the activity that generated the derivation. */
47
+ rule?: string;
48
+ /** The relationships it was derived from. */
49
+ premises: string[];
50
+ }
51
+
52
+ /**
53
+ * Whether a predicate is a notation's derivation certainty. Each notation's
54
+ * rules declare their own (`am4deriv:derivationCertainty`,
55
+ * `amderiv:derivationCertainty`), so it is recognised by its local name.
56
+ */
57
+ export function isCertaintyPredicate(predicateIri: string): boolean {
58
+ return predicateIri.endsWith('#derivationCertainty') || predicateIri.endsWith('/derivationCertainty');
59
+ }
60
+
61
+ /** The certainty a value of it names: its local name, `Valid` or `Potential`. */
62
+ export function certaintyNamed(valueIri: string): DerivationCertainty | undefined {
63
+ const name = localName(valueIri);
64
+ return name === 'Valid' ? 'valid' : name === 'Potential' ? 'potential' : undefined;
65
+ }
66
+
67
+ /** A resource's derivation certainty, when it is a derivation. */
68
+ export function certaintyOf(store: RdfStore, iri: string): DerivationCertainty | undefined {
69
+ for (const q of store.getQuads(nn(iri), null, null, MODEL_GRAPH)) {
70
+ if (isCertaintyPredicate(q.predicate.value) && q.object.termType === 'NamedNode') {
71
+ const certainty = certaintyNamed(q.object.value);
72
+ if (certainty) return certainty;
73
+ }
74
+ }
75
+ return undefined;
76
+ }
77
+
78
+ /**
79
+ * Whether a resource is a proposition, not a relationship of the model (core's
80
+ * `arch:QualifiedRelationship`): it reifies a triple the model does not assert,
81
+ * and no qualified predicate leads to it — a potential derivation, until a
82
+ * modeller confirms it.
83
+ */
84
+ export function isProposition(store: RdfStore, iri: string): boolean {
85
+ const reified = store.getQuads(nn(iri), T.reifies, null, MODEL_GRAPH).map((q) => q.object);
86
+ if (!reified.some((term) => term.termType === 'Quad')) return false;
87
+ for (const term of reified) {
88
+ if (term.termType !== 'Quad') continue;
89
+ const { subject, predicate, object } = term as unknown as Quad;
90
+ if (store.getQuads(subject as NamedNode, predicate as NamedNode, object as NamedNode, MODEL_GRAPH).length > 0) return false;
91
+ }
92
+ return !store.getQuads(null, null, nn(iri), MODEL_GRAPH).some((q) => isQualifiedPredicate(store, q.predicate.value));
93
+ }
94
+
95
+ /** Whether a qualified predicate leads to a resource: a relationship of the model, not a proposition about one. */
96
+ export function isLedTo(store: RdfStore, iri: string): boolean {
97
+ return store.getQuads(null, null, nn(iri), MODEL_GRAPH).some((q) => isQualifiedPredicate(store, q.predicate.value));
98
+ }
99
+
100
+ /** Whether a resource is derived, how surely, and whether it was confirmed; `undefined` when it is not derived. */
101
+ export function derivationStatus(store: RdfStore, iri: string): DerivationStatus | undefined {
102
+ const certainty = certaintyOf(store, iri);
103
+ if (!certainty) return undefined;
104
+ return { certainty, confirmed: certainty === 'potential' && isLedTo(store, iri) };
105
+ }
106
+
107
+ /**
108
+ * A derivation that is not a relationship the model states: a valid one, or a
109
+ * potential one not confirmed. What the model's membership, its auto-layout and
110
+ * the explorer's Relationships leave out.
111
+ */
112
+ export function isUnstatedDerivation(store: RdfStore, iri: string): boolean {
113
+ const status = derivationStatus(store, iri);
114
+ return status !== undefined && !status.confirmed;
115
+ }
116
+
117
+ /** The rule that derived a resource: the plan of the activity that generated it (D30). */
118
+ export function ruleOf(store: RdfStore, iri: string): string | undefined {
119
+ for (const generated of store.getQuads(nn(iri), nn(PROV + 'wasGeneratedBy'), null, MODEL_GRAPH)) {
120
+ if (generated.object.termType !== 'NamedNode') continue;
121
+ for (const association of store.getQuads(generated.object, nn(PROV + 'qualifiedAssociation'), null, MODEL_GRAPH)) {
122
+ if (association.object.termType !== 'NamedNode') continue;
123
+ const plan = store.getQuads(association.object, nn(PROV + 'hadPlan'), null, MODEL_GRAPH)[0]?.object.value;
124
+ if (plan) return plan;
125
+ }
126
+ }
127
+ return undefined;
128
+ }
129
+
130
+ /** A derivation with its rule and premises; `undefined` when the resource is not derived. */
131
+ export function derivationDetails(store: RdfStore, iri: string): DerivationDetails | undefined {
132
+ const status = derivationStatus(store, iri);
133
+ if (!status) return undefined;
134
+ const rule = ruleOf(store, iri);
135
+ const premises = store
136
+ .getQuads(nn(iri), nn(PROV + 'wasDerivedFrom'), null, MODEL_GRAPH)
137
+ .map((q) => q.object.value)
138
+ .sort();
139
+ return { ...status, ...(rule ? { rule } : {}), premises };
140
+ }
141
+
142
+ /**
143
+ * What confirming a potential derivation asserts: its direct triple, the
144
+ * qualified predicate leading to it from its source, and its membership of the
145
+ * model — each only where the model does not have it yet. Nothing for a
146
+ * resource that is not an unconfirmed potential derivation.
147
+ */
148
+ export function confirmationQuads(store: RdfStore, iri: string, modelIri?: string): Quad[] {
149
+ const status = derivationStatus(store, iri);
150
+ if (status?.certainty !== 'potential' || status.confirmed) return [];
151
+ const rel = nn(iri);
152
+ const source = store.getQuads(rel, T.source, null, MODEL_GRAPH)[0]?.object;
153
+ const target = store.getQuads(rel, T.target, null, MODEL_GRAPH)[0]?.object;
154
+ if (source?.termType !== 'NamedNode' || target?.termType !== 'NamedNode') return [];
155
+ const classIri = relationshipClassOf(store, iri) ?? IRI.QualifiedRelationship;
156
+ // The triple it reifies, else the one its class stands for.
157
+ const reified = store.getQuads(rel, T.reifies, null, MODEL_GRAPH).map((q) => q.object).find((t) => t.termType === 'Quad') as
158
+ | Quad
159
+ | undefined;
160
+ const predicate = reified?.predicate.value ?? unqualifiedFormOf(store, classIri);
161
+ const add: Quad[] = [];
162
+ if (predicate && store.getQuads(source, nn(predicate), target, MODEL_GRAPH).length === 0) add.push(triple(source, nn(predicate), target));
163
+ add.push(triple(source, nn(qualifiedFormOf(store, classIri)), rel));
164
+ if (modelIri && store.getQuads(rel, T.inModel, null, MODEL_GRAPH).length === 0) add.push(triple(rel, T.inModel, nn(modelIri)));
165
+ return add;
166
+ }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Which relationships a modeller may draw directly, and which the language's
3
+ * metamodel figures draw, from a metamodel's relationship tables.
4
+ *
5
+ * ## Direct, or only by derivation
6
+ *
7
+ * ArchiMate's relationship tables print a relationship in upper case when the
8
+ * metamodel permits it directly, and in lower case when it is permitted only as
9
+ * the conclusion of a derivation: an artifact may realize a business object, but
10
+ * only by derivation. The relationship shapes (`relationship-table.ts`) do not
11
+ * keep the difference — they validate, and a derived relationship is a valid one.
12
+ * The relationship tables meta publishes beside them do, as lookups:
13
+ *
14
+ * ```turtle
15
+ * am4:realizes am4rt:permittedDirectlyBy am4rt:permitsDirectRealization .
16
+ * am4:Artifact am4rt:permitsDirectRealization am4:DataObject , am4:SystemSoftware , … .
17
+ * ```
18
+ *
19
+ * ## Read by pattern, not by namespace
20
+ *
21
+ * The annotation that maps a relationship predicate to its direct permissions is
22
+ * found by its declaration — an `owl:AnnotationProperty` named
23
+ * `permittedDirectlyBy` — in whatever namespace a language's tables use
24
+ * (`am4rt:` for ArchiMate 4.0, `amrt:` for 3.2), so another language's tables in
25
+ * the same pattern need nothing here. Looking it up through its type keeps the
26
+ * read to indexed quad lookups.
27
+ *
28
+ * ## Drawn in the metamodel figures
29
+ *
30
+ * The same tables say which relationships the specification's metamodel figures
31
+ * draw between two element types — the relationship a tool proposes first for
32
+ * the pair — in the same pattern, under `drawnBy`:
33
+ *
34
+ * ```turtle
35
+ * am4:assignedTo am4rt:drawnBy am4rt:drawsAssignment .
36
+ * am4:ApplicationComponent am4rt:drawsAssignment am4:DataObject , am4:Role .
37
+ * ```
38
+ *
39
+ * ## What the tables do not cover is unknown, not forbidden
40
+ *
41
+ * A relationship whose predicate has no such annotation, or an end type the
42
+ * tables never mention (a junction: the tables list element types only), is
43
+ * neither direct nor derived as far as they say: {@link TablePermissions.holds}
44
+ * answers `undefined`, and the caller ranks as before.
45
+ */
46
+
47
+ import type { NamedNode } from '@rdfjs/types';
48
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
49
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
50
+ import { nn } from './vocabulary.js';
51
+
52
+ const RDF_TYPE = nn(NAMESPACES.rdf + 'type');
53
+ const OWL_ANNOTATION_PROPERTY = nn(NAMESPACES.owl + 'AnnotationProperty');
54
+ /** The annotations that map a relationship predicate to its permissions of each kind. */
55
+ const DIRECT_ANNOTATION = 'permittedDirectlyBy';
56
+ const DRAWN_ANNOTATION = 'drawnBy';
57
+ /** Everything the tables permit, direct or only by derivation. */
58
+ const PERMITTED_ANNOTATION = 'permittedBy';
59
+ /** The tables' wildcards: every element type, and every element and relationship. */
60
+ const WILDCARDS = new Set([NAMESPACES.arch + 'Element', NAMESPACES.arch + 'ModelConcept']);
61
+
62
+ /** For one relationship predicate: each source type and the types it may reach directly. */
63
+ type DirectTargets = ReadonlyMap<string, ReadonlySet<string>>;
64
+
65
+ /** {@link TablePermissions} as plain data. */
66
+ export interface PlainTablePermissions {
67
+ byPredicate: ReadonlyMap<string, DirectTargets>;
68
+ mentioned: ReadonlySet<string>;
69
+ }
70
+
71
+ /** One kind of permission of the loaded relationship tables: direct, or drawn. */
72
+ export class TablePermissions {
73
+ constructor(
74
+ private readonly byPredicate: ReadonlyMap<string, DirectTargets>,
75
+ /** Every type the tables name, as a source or as a target (wildcards aside). */
76
+ private readonly mentioned: ReadonlySet<string>,
77
+ ) {}
78
+
79
+ /** Relationship predicates the tables give direct permissions for. */
80
+ get size(): number {
81
+ return this.byPredicate.size;
82
+ }
83
+
84
+ /** As plain data (maps and sets clone into a worker; the class does not). */
85
+ toPlain(): PlainTablePermissions {
86
+ return { byPredicate: this.byPredicate, mentioned: this.mentioned };
87
+ }
88
+
89
+ /** The permissions back from {@link toPlain}'s data. */
90
+ static fromPlain(plain: PlainTablePermissions): TablePermissions {
91
+ return new TablePermissions(plain.byPredicate, plain.mentioned);
92
+ }
93
+
94
+ /** Whether the tables give permissions of this kind for the predicate. */
95
+ covers(predicateIri: string): boolean {
96
+ return this.byPredicate.has(predicateIri);
97
+ }
98
+
99
+ /** Whether the tables name the type, as a source or a target (wildcards aside). */
100
+ mentions(typeIri: string): boolean {
101
+ return this.mentioned.has(typeIri);
102
+ }
103
+
104
+ /**
105
+ * Whether the tables give this kind of permission for a relationship with this
106
+ * predicate from the source to the target, given the types' `rdfs:subClassOf*`
107
+ * closures (each including the type itself) — for direct permissions, `true`
108
+ * when the tables print it in upper case and `false` when they permit it only
109
+ * by derivation. `undefined` when they do not say: no permissions of this kind
110
+ * for the predicate, or an end type they never mention.
111
+ */
112
+ holds(predicateIri: string, sourceClosure: readonly string[], targetClosure: readonly string[]): boolean | undefined {
113
+ const bySource = this.byPredicate.get(predicateIri);
114
+ if (!bySource) return undefined;
115
+ if (!sourceClosure.some((c) => this.mentioned.has(c)) || !targetClosure.some((c) => this.mentioned.has(c))) {
116
+ return undefined;
117
+ }
118
+ return sourceClosure.some((source) => {
119
+ const targets = bySource.get(source);
120
+ if (!targets) return false;
121
+ // A wildcard lists every element type (and with arch:ModelConcept, every relationship too).
122
+ for (const target of targets) if (WILDCARDS.has(target) || targetClosure.includes(target)) return true;
123
+ return false;
124
+ });
125
+ }
126
+ }
127
+
128
+ /** No relationship tables loaded: nothing is known to be direct, derived or drawn. */
129
+ export const NO_TABLE_PERMISSIONS = new TablePermissions(new Map(), new Set());
130
+
131
+ /** The local name of an IRI: after the last `#` or `/`. */
132
+ function localName(iri: string): string {
133
+ return iri.slice(Math.max(iri.lastIndexOf('#'), iri.lastIndexOf('/')) + 1);
134
+ }
135
+
136
+ /** Read the direct permissions of every relationship table in the store (all graphs). */
137
+ export function readDirectPermissions(store: RdfStore): TablePermissions {
138
+ return readPermissions(store, DIRECT_ANNOTATION);
139
+ }
140
+
141
+ /**
142
+ * Read everything the relationship tables permit — directly, or as the
143
+ * conclusion of a derivation: what a relationship may be at all, which
144
+ * validation checks (`relationship-validity.ts`).
145
+ */
146
+ export function readPermittedPermissions(store: RdfStore): TablePermissions {
147
+ return readPermissions(store, PERMITTED_ANNOTATION);
148
+ }
149
+
150
+ /** Read the relationships the metamodel figures draw, from every relationship table in the store. */
151
+ export function readDrawnPermissions(store: RdfStore): TablePermissions {
152
+ return readPermissions(store, DRAWN_ANNOTATION);
153
+ }
154
+
155
+ /** The permissions mapped by the annotation of this local name, in any namespace. */
156
+ function readPermissions(store: RdfStore, annotationName: string): TablePermissions {
157
+ const byPredicate = new Map<string, Map<string, Set<string>>>();
158
+ const mentioned = new Set<string>();
159
+ const annotations = store
160
+ .getQuads(null, RDF_TYPE, OWL_ANNOTATION_PROPERTY)
161
+ .map((q) => q.subject)
162
+ .filter((s) => s.termType === 'NamedNode' && localName(s.value) === annotationName);
163
+
164
+ for (const annotation of annotations) {
165
+ for (const mapping of store.getQuads(null, annotation as NamedNode)) {
166
+ const predicate = mapping.subject.value;
167
+ const permits = mapping.object as NamedNode;
168
+ let bySource = byPredicate.get(predicate);
169
+ if (!bySource) byPredicate.set(predicate, (bySource = new Map()));
170
+ for (const permission of store.getQuads(null, permits)) {
171
+ const source = permission.subject.value;
172
+ const target = permission.object.value;
173
+ let targets = bySource.get(source);
174
+ if (!targets) bySource.set(source, (targets = new Set()));
175
+ targets.add(target);
176
+ mentioned.add(source);
177
+ if (!WILDCARDS.has(target)) mentioned.add(target);
178
+ }
179
+ }
180
+ }
181
+ return new TablePermissions(byPredicate, mentioned);
182
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Which node is drawn above which (core-vis 0.10, `arch-vis:zOrder`; linked-archi-meta's DD-45): among the nodes drawn
3
+ * in the same place — a view's top level, or the inside of one container — the higher zOrder above the lower; absent,
4
+ * 0; the same, by IRI in code point order, the later above. A nested node is drawn above its container whatever
5
+ * either's zOrder, so only nodes in the same place are compared.
6
+ *
7
+ * {@link reorder} brings nodes to the front or the back, or one step forward or backward. Drawing order matters only
8
+ * between nodes that overlap, so a step goes past the next node a node overlaps, and keeps its order with every other
9
+ * node it overlaps. It changes as few zOrders as it can: the moving nodes', and — where the numbers leave no room
10
+ * between two nodes — the smaller of the two groups of nodes beside it, all by the same amount, so their order among
11
+ * themselves stays.
12
+ */
13
+
14
+ import type { Bounds } from './interfaces.js';
15
+
16
+ /** A node as its drawing order reads it. */
17
+ export interface OrderedNode {
18
+ nodeIri: string;
19
+ /** `arch-vis:zOrder`; absent, 0. */
20
+ zOrder?: number;
21
+ bounds: Bounds;
22
+ }
23
+
24
+ /** To the front, to the back, one step forward, one step backward. */
25
+ export type DrawingOrderChange = 'front' | 'back' | 'forward' | 'backward';
26
+
27
+ const codePoints = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
28
+
29
+ /** The drawing order of two nodes in the same place: negative when `a` is drawn below `b`. */
30
+ export function compareDrawingOrder(a: { nodeIri: string; zOrder?: number }, b: { nodeIri: string; zOrder?: number }): number {
31
+ return (a.zOrder ?? 0) - (b.zOrder ?? 0) || codePoints(a.nodeIri, b.nodeIri);
32
+ }
33
+
34
+ /** The nodes, the lowest first, as they are drawn. */
35
+ export function sortByDrawingOrder<T extends { nodeIri: string; zOrder?: number }>(nodes: readonly T[]): T[] {
36
+ return [...nodes].sort(compareDrawingOrder);
37
+ }
38
+
39
+ /** Whether two nodes cover some of the same area: touching edges do not. */
40
+ function overlaps(a: Bounds, b: Bounds): boolean {
41
+ return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
42
+ }
43
+
44
+ /**
45
+ * The zOrders that move the `moving` nodes among `siblings` — the nodes drawn in the same place, the moving ones among
46
+ * them — by node IRI: only those that change, 0 meaning none is to be written. Front and back keep the moving nodes'
47
+ * order among themselves. A step moves each moving node past the next node it overlaps that is not moving, if there is
48
+ * one — the topmost first going forward, the lowest first going backward — and nothing else changes place among the
49
+ * nodes it overlaps.
50
+ */
51
+ export function reorder(siblings: readonly OrderedNode[], moving: ReadonlySet<string>, change: DrawingOrderChange): Map<string, number> {
52
+ const z = new Map(siblings.map((n) => [n.nodeIri, n.zOrder ?? 0]));
53
+ const sorted = () => [...siblings].sort((a, b) => compareDrawingOrder({ nodeIri: a.nodeIri, zOrder: z.get(a.nodeIri) }, { nodeIri: b.nodeIri, zOrder: z.get(b.nodeIri) }));
54
+ const shift = (nodes: readonly OrderedNode[], by: number) => {
55
+ for (const n of nodes) z.set(n.nodeIri, z.get(n.nodeIri)! + by);
56
+ };
57
+
58
+ if (change === 'front' || change === 'back') {
59
+ const order = sorted();
60
+ const moved = order.filter((n) => moving.has(n.nodeIri));
61
+ const others = order.filter((n) => !moving.has(n.nodeIri));
62
+ if (moved.length > 0 && others.length > 0) {
63
+ const index = (n: OrderedNode) => order.indexOf(n);
64
+ // Already there: above every other, or below.
65
+ const there =
66
+ change === 'front'
67
+ ? Math.min(...moved.map(index)) > Math.max(...others.map(index))
68
+ : Math.max(...moved.map(index)) < Math.min(...others.map(index));
69
+ if (!there) {
70
+ const values = others.map((n) => z.get(n.nodeIri)!);
71
+ moved.forEach((n, i) =>
72
+ z.set(n.nodeIri, change === 'front' ? Math.max(...values) + 1 + i : Math.min(...values) - moved.length + i),
73
+ );
74
+ }
75
+ }
76
+ } else {
77
+ const forward = change === 'forward';
78
+ const order = sorted().filter((n) => moving.has(n.nodeIri));
79
+ for (const node of forward ? order.reverse() : order) {
80
+ const now = sorted();
81
+ const at = now.indexOf(node);
82
+ const over = (n: OrderedNode) => n !== node && overlaps(n.bounds, node.bounds);
83
+ // The node to step past, and the next the node overlaps beyond it, which it must stay this side of.
84
+ const ahead = forward ? now.slice(at + 1) : now.slice(0, at).reverse();
85
+ const t = ahead.findIndex((n) => over(n) && !moving.has(n.nodeIri));
86
+ if (t < 0) continue;
87
+ const target = ahead[t];
88
+ const beyond = ahead.slice(t + 1).find(over);
89
+ const zt = z.get(target.nodeIri)!;
90
+ const step = forward ? 1 : -1;
91
+ const wanted = { nodeIri: node.nodeIri, zOrder: zt + step };
92
+ const fits = !beyond || compareDrawingOrder(wanted, { nodeIri: beyond.nodeIri, zOrder: z.get(beyond.nodeIri) }) * step < 0;
93
+ if (fits) {
94
+ z.set(node.nodeIri, zt + step);
95
+ continue;
96
+ }
97
+ // No room between the target and the next beyond it: the target and what is on its side moved away from the
98
+ // node, or what is beyond moved further — whichever group is smaller — two apart, the node between.
99
+ const targetAt = now.indexOf(target);
100
+ const beyondAt = now.indexOf(beyond);
101
+ const behind = (forward ? now.slice(0, targetAt + 1) : now.slice(targetAt)).filter((n) => n !== node);
102
+ const past = (forward ? now.slice(beyondAt) : now.slice(0, beyondAt + 1)).filter((n) => n !== node);
103
+ if (past.length <= behind.length) {
104
+ shift(past, 2 * step);
105
+ z.set(node.nodeIri, zt + step);
106
+ } else {
107
+ shift(behind, -2 * step);
108
+ z.set(node.nodeIri, zt - step);
109
+ }
110
+ }
111
+ }
112
+
113
+ const changes = new Map<string, number>();
114
+ for (const n of siblings) {
115
+ const value = z.get(n.nodeIri)!;
116
+ if (value !== (n.zOrder ?? 0)) changes.set(n.nodeIri, value);
117
+ }
118
+ return changes;
119
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Element Manager — CRUD operations for architecture model elements.
3
+ *
4
+ * An element is a model concept, not a shape: creating one writes its type, its
5
+ * model membership and its label, and nothing about where it is drawn. Placing
6
+ * it on a diagram is {@link ViewManager.addElementToView}'s job, so the same
7
+ * element can appear in any number of views — or in none — and still be one
8
+ * RDF resource.
9
+ *
10
+ * ```turtle
11
+ * m:element-3f2c… a am4:ApplicationComponent ;
12
+ * arch:inModel m:model ;
13
+ * skos:prefLabel "Order Service"@en .
14
+ * ```
15
+ *
16
+ * Labels are language-tagged: the Linked.Archi element shapes reject a plain
17
+ * string `skos:prefLabel`.
18
+ *
19
+ * Deletion here is deletion from the *model* — every view, every relationship.
20
+ * See `cascade.ts` for exactly what goes.
21
+ */
22
+
23
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
24
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
25
+ import { mintIri } from '../rdf-engine/iri.js';
26
+ import { collectElementQuads } from './cascade.js';
27
+ import { modelNamespace } from './model-namespace.js';
28
+ import type { CreateElementOptions, ElementManager } from './interfaces.js';
29
+ import { T, langLiteral, nn, triple } from './vocabulary.js';
30
+
31
+ /**
32
+ * Kept for source compatibility with callers that reset the old counter in
33
+ * test setup. IRIs are UUID-based now, so there is nothing to reset.
34
+ */
35
+ export function resetElementCounter(): void {
36
+ /* no-op: IRIs are random, not counted */
37
+ }
38
+
39
+ /** Concrete {@link ElementManager} over an {@link RdfStore}. */
40
+ export class OxigraphElementManager implements ElementManager {
41
+ constructor(private readonly store: RdfStore) {}
42
+
43
+ createElement(typeIri: string, modelIri: string, options: CreateElementOptions = {}): NamedNode {
44
+ const element = nn(options.iri ?? mintIri(modelNamespace(this.store, modelIri || undefined), 'element'));
45
+ const quads: Quad[] = [triple(element, T.rdfType, nn(typeIri))];
46
+ if (modelIri) quads.push(triple(element, T.inModel, nn(modelIri)));
47
+ const label = options.label?.trim();
48
+ if (label) quads.push(triple(element, T.prefLabel, langLiteral(label, options.language)));
49
+ this.store.addQuads(quads);
50
+ return element;
51
+ }
52
+
53
+ updateProperty(elementIri: string, property: string, value: Term): void {
54
+ const subject = nn(elementIri);
55
+ const predicate = nn(property);
56
+ const existing = this.store.getQuads(subject, predicate);
57
+ if (existing.length > 0) this.store.removeQuads(existing);
58
+ this.store.addQuads([triple(subject, predicate, value)]);
59
+ }
60
+
61
+ deleteElement(elementIri: string): void {
62
+ const quads = this.collectElementQuads(elementIri);
63
+ if (quads.length > 0) this.store.removeQuads(quads);
64
+ }
65
+
66
+ collectElementQuads(elementIri: string): Quad[] {
67
+ return collectElementQuads(this.store, elementIri);
68
+ }
69
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * An element's pictures (core 0.5.0): its picture for every audience,
3
+ * `arch:prefVisNotation`, and one for an audience, an `arch:altVisNotation`
4
+ * whose value is a `schema:ImageObject` with its `schema:contentUrl` and
5
+ * `arch:inPresentationContext` — as a name for an audience is a SKOS-XL label
6
+ * (`context-names.ts`).
7
+ *
8
+ * A value may also be the image's own IRI, as published notations write
9
+ * `arch:prefVisNotation`: read as its own address. la-gram writes an
10
+ * ImageObject named after the element — `{element}/picture` for every
11
+ * audience, `{element}/picture/{hash}` for one (DD-41) — its address an
12
+ * `xsd:anyURI` literal (an http(s) URL, or a `data:image/…` URI for a picture
13
+ * kept in the model), so that a merge can match it. One per audience. One named
14
+ * as la-gram named it before (`{element}-picture`, `-picture-{hash}`) keeps its
15
+ * name when the picture changes.
16
+ */
17
+
18
+ import { DataFactory } from 'n3';
19
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
20
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
21
+ import { isPartNamed, partIri } from '../rdf-engine/iri.js';
22
+ import { imageUri } from './appearance.js';
23
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
24
+ import { shortHash } from './short-hash.js';
25
+ import { T, netChange } from './vocabulary.js';
26
+
27
+ const { namedNode, literal, quad } = DataFactory;
28
+
29
+ /** One picture an element has: for every audience (no `context`), or for one. */
30
+ export interface ElementPicture {
31
+ context?: string;
32
+ /** Its address, as drawn. */
33
+ url: string;
34
+ /** What holds it: an ImageObject, or the image's own IRI. */
35
+ node: string;
36
+ }
37
+
38
+ /** The address a picture value gives: its `schema:contentUrl`, else — an image's own IRI — itself. */
39
+ function urlOf(store: RdfStore, value: Term): string | undefined {
40
+ if (value.termType === 'Literal') return imageUri(value.value);
41
+ const content = store.getQuads(value as never, T.contentUrl as never)[0]?.object;
42
+ if (content) return imageUri(content.value);
43
+ return value.termType === 'NamedNode' ? imageUri(value.value) : undefined;
44
+ }
45
+
46
+ /** Every picture `iri` has: its `arch:prefVisNotation`, and each `arch:altVisNotation` (with its context, if it has one). */
47
+ export function picturesOf(store: RdfStore, iri: string): ElementPicture[] {
48
+ const pictures: ElementPicture[] = [];
49
+ for (const [predicate, scoped] of [
50
+ [T.prefVisNotation, false],
51
+ [T.altVisNotation, true],
52
+ ] as const) {
53
+ for (const q of store.getQuads(namedNode(iri) as never, predicate as never)) {
54
+ const url = urlOf(store, q.object);
55
+ if (!url) continue;
56
+ const context = scoped && q.object.termType !== 'Literal' ? store.getQuads(q.object as never, T.inPresentationContext as never)[0]?.object.value : undefined;
57
+ pictures.push({ url, node: q.object.value, ...(context ? { context } : {}) });
58
+ }
59
+ }
60
+ return pictures;
61
+ }
62
+
63
+ /** `iri`'s picture for `context`: its picture for that audience, else the one for every audience — `undefined` with neither. */
64
+ export function pictureOf(store: RdfStore, iri: string, context: string | undefined): string | undefined {
65
+ const pictures = picturesOf(store, iri);
66
+ return (
67
+ (context ? pictures.find((p) => p.context === context)?.url : undefined) ??
68
+ store
69
+ .getQuads(namedNode(iri) as never, T.prefVisNotation as never)
70
+ .map((q) => urlOf(store, q.object))
71
+ .find((url) => url !== undefined)
72
+ );
73
+ }
74
+
75
+ /** The IRI of `iri`'s picture for `context` — for every audience when absent: `{iri}/picture`, `{iri}/picture/{hash}`. */
76
+ export function pictureIri(iri: string, context: string | undefined): string {
77
+ return context ? partIri(iri, 'picture', shortHash(context)) : partIri(iri, 'picture');
78
+ }
79
+
80
+ /**
81
+ * What changes to give `iri` the picture at `url` for `context` — for every
82
+ * audience when `context` is absent — or, `null` or empty, to take it away:
83
+ * the one it has for that scope goes, with what holds it when nothing else
84
+ * points at it.
85
+ */
86
+ export function pictureChange(
87
+ store: RdfStore,
88
+ iri: string,
89
+ context: string | undefined,
90
+ url: string | null,
91
+ ): { remove: Quad[]; add: Quad[] } {
92
+ const element = namedNode(iri);
93
+ const predicate = (context ? T.altVisNotation : T.prefVisNotation) as NamedNode;
94
+ const address = imageUri(url ?? undefined);
95
+ // An address that is none changes nothing — it does not take the picture away either.
96
+ if (url?.trim() && !address) return { remove: [], add: [] };
97
+ const remove: Quad[] = [];
98
+ // The ImageObject it replaces keeps its name when it is the element's own, either way it was named.
99
+ let kept: string | undefined;
100
+ for (const q of store.getQuads(element as never, predicate as never) as Quad[]) {
101
+ const scope = q.object.termType === 'Literal' ? undefined : store.getQuads(q.object as never, T.inPresentationContext as never)[0]?.object.value;
102
+ if (scope !== context) continue;
103
+ remove.push(q);
104
+ const shared = store.getQuads(null, null, q.object as never).length > 1;
105
+ if (!shared && q.object.termType !== 'Literal') remove.push(...(store.getQuads(q.object as never) as Quad[]));
106
+ if (!shared && q.object.termType === 'NamedNode' && isPartNamed(iri, q.object.value, 'picture', /[0-9a-f]{8}/)) kept = q.object.value;
107
+ }
108
+ if (!address) return { remove, add: [] };
109
+ const picture = namedNode(kept ?? pictureIri(iri, context));
110
+ const add: Quad[] = [
111
+ quad(element, predicate, picture) as Quad,
112
+ quad(picture, T.rdfType as NamedNode, T.ImageObject as NamedNode) as Quad,
113
+ quad(picture, T.contentUrl as NamedNode, literal(address, namedNode(NAMESPACES.xsd + 'anyURI'))) as Quad,
114
+ ...(context ? [quad(picture, T.inPresentationContext as NamedNode, namedNode(context)) as Quad] : []),
115
+ ];
116
+ // A picture that keeps its name changes only in what differs.
117
+ return netChange({ remove, add });
118
+ }