@linked.archi/kernel 0.0.0-stage → 0.1.5

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 (365) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +96 -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 +923 -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 +893 -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 +7302 -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 +840 -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 +470 -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/observable-store.ts +631 -0
  353. package/src/rdf-engine/rdf-store.ts +508 -0
  354. package/src/rdf-engine/shacl-validator.ts +602 -0
  355. package/src/rdf-engine/shape-reach.ts +140 -0
  356. package/src/rdf-engine/shape-switches.ts +165 -0
  357. package/src/rdf-engine/single-valued.ts +219 -0
  358. package/src/rdf-engine/sparql-constraints.ts +334 -0
  359. package/src/rdf-engine/term-codec.ts +51 -0
  360. package/src/rdf-engine/ttl-parser.ts +51 -0
  361. package/src/rdf-engine/ttl-serializer.ts +79 -0
  362. package/src/rdf-engine/turtle-writer.ts +284 -0
  363. package/src/rdf-engine/validation-engine.ts +682 -0
  364. package/src/rdf-engine/validation-service.ts +184 -0
  365. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Model Manager layer interfaces.
3
+ *
4
+ * CRUD operations on architecture model elements, relationships, views and the
5
+ * diagram geometry inside views. All mutations go through this layer to keep
6
+ * the RDF store consistent; the store (not the canvas) is the model of record.
7
+ */
8
+
9
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
10
+ import type { RelationshipTypeInfo } from '../metamodel-manager/interfaces.js';
11
+ import type { Appearance, AppearanceChanges } from './appearance.js';
12
+
13
+ export type { Appearance, AppearanceChanges } from './appearance.js';
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Shared types
17
+ // ---------------------------------------------------------------------------
18
+
19
+ /** Position and size of a diagram element. */
20
+ export interface Bounds {
21
+ x: number;
22
+ y: number;
23
+ width: number;
24
+ height: number;
25
+ }
26
+
27
+ /** A waypoint on a link's route. */
28
+ export interface Point {
29
+ x: number;
30
+ y: number;
31
+ }
32
+
33
+ /** The three kinds of `arch:View`. */
34
+ export type ViewKind = 'Diagram' | 'Catalog' | 'Matrix';
35
+
36
+ /** Metadata about a view resource. */
37
+ export interface ViewInfo {
38
+ /** IRI of the view resource. */
39
+ iri: string;
40
+ /** Display label (`skos:prefLabel`). */
41
+ label: string;
42
+ /** View type: Diagram, Catalog, or Matrix. */
43
+ type: ViewKind;
44
+ /** Viewpoint the view conforms to (`arch:viewConformsToViewpoint`). */
45
+ viewpointIri?: string;
46
+ /** Model the view belongs to (`arch:inModel`). */
47
+ modelIri?: string;
48
+ }
49
+
50
+ /** One element's placement in a diagram view (`arch-vis:ArchNode`) — or a figure's. */
51
+ /** A placement's own label expression: its text, and the presentation context it is for — every context when absent. */
52
+ export interface LabelExpressionInfo {
53
+ context?: string;
54
+ expression: string;
55
+ }
56
+
57
+ export interface NodeInfo {
58
+ /** How it looks in each presentation context it has a style for (core-vis 0.7), over {@link appearance}. */
59
+ contextAppearances?: Record<string, Appearance>;
60
+ /** What its label says, as its own style gives it: one expression a presentation context, one for every context. */
61
+ labelExpressions?: LabelExpressionInfo[];
62
+ nodeIri: string;
63
+ /** The element the node draws; for a figure, which stands for none, the node itself. */
64
+ elementIri: string;
65
+ bounds: Bounds;
66
+ /** The element — or figure — whose node this one is drawn inside (`arch-vis:inNode`), if any. */
67
+ parentElementIri?: string;
68
+ /** The node it is drawn inside — which of that element's placements, when it has several. */
69
+ parentNodeIri?: string;
70
+ /**
71
+ * Its drawing order among the nodes drawn in the same place (`arch-vis:zOrder`, core-vis 0.10): above those with a
72
+ * lower one; absent, 0 — `drawing-order.ts`.
73
+ */
74
+ zOrder?: number;
75
+ /** Set when the node stands for no model element. */
76
+ figure?: FigureInfo;
77
+ /** How an element's placement looks, from its own style; a figure's is in its {@link figure}. */
78
+ appearance?: Appearance;
79
+ }
80
+
81
+ /**
82
+ * What a figure is: no model element behind it.
83
+ *
84
+ * - `group` — a box holding others, its name at the top (`arch-vis:ContainerNode`);
85
+ * - `shape` — a core-vis shape type (`arch-vis:ContainerNode` whose `arch-vis:style`
86
+ * gives `arch-vis:shapeType`), which may hold others too;
87
+ * - `note` — a sticky note: free-standing text (`arch-vis:LabelNode` no element's
88
+ * `arch-vis:label` points at);
89
+ * - `reference` — another view, which it opens (`arch-vis:ViewReferenceNode`, core-vis
90
+ * 0.9). It stands for that view, its {@link FigureInfo.view},
91
+ * which is presented in this one (`arch:inView`), and holds nothing.
92
+ *
93
+ * Its text is its `skos:prefLabel`.
94
+ */
95
+ export type FigureKind = 'group' | 'shape' | 'note' | 'reference';
96
+
97
+ export interface FigureInfo extends Appearance {
98
+ kind: FigureKind;
99
+ /** The core-vis shape type of a `shape`. */
100
+ shapeType?: string;
101
+ /** The view a `reference` opens (`arch-vis:referencesView`). */
102
+ view?: string;
103
+ text?: string;
104
+ }
105
+
106
+ /** A reference to a view (an `arch-vis:ViewReferenceNode` naming it by `arch-vis:referencesView`), and its holder. */
107
+ export interface ViewReferenceInfo {
108
+ /** The reference's node. */
109
+ nodeIri: string;
110
+ /** The view it is drawn in (`arch-vis:view`): its holder. */
111
+ holderIri: string;
112
+ }
113
+
114
+ /** A figure's colours (`#rrggbb`), on its own core-vis style; absent, the figure's default. */
115
+ export interface FigureColours {
116
+ fillColor?: string;
117
+ lineColor?: string;
118
+ fontColor?: string;
119
+ }
120
+
121
+ /** One relationship drawn in a diagram view (`arch-vis:Link`). */
122
+ export interface LinkInfo {
123
+ /** How the line looks in each presentation context it has a style for (core-vis 0.7), over {@link appearance}. */
124
+ contextAppearances?: Record<string, Appearance>;
125
+ linkIri: string;
126
+ relationshipIri: string;
127
+ /** What the link starts at: a node, or the link of the relationship it starts at. */
128
+ sourceNodeIri: string;
129
+ /** What the link ends at: a node, or the link of the relationship it ends at. */
130
+ targetNodeIri: string;
131
+ /** The concept it starts at: an element, or a relationship. */
132
+ sourceElementIri: string;
133
+ /** The concept it ends at: an element, or a relationship. */
134
+ targetElementIri: string;
135
+ /** Persisted route, empty when the layouter should compute one. */
136
+ waypoints: Point[];
137
+ /**
138
+ * A line standing for no relationship — a core-vis `arch-vis:Link` with no
139
+ * `arch-vis:archRelationship`, drawn from a note or another figure to what it
140
+ * points at. Its `relationshipIri` is then the link's own IRI, and its ends'
141
+ * `…ElementIri` a figure's node where the end is a figure.
142
+ */
143
+ connector?: boolean;
144
+ /** A connector's text (`skos:prefLabel`): what a line from a note says. */
145
+ text?: string;
146
+ /**
147
+ * Where the relationship's name was moved to: its `arch-vis:LabelNode`'s
148
+ * bounds, in the diagram's coordinates. Absent, the name is at the middle of
149
+ * the route.
150
+ */
151
+ label?: Bounds;
152
+ /** How the line looks, from its own style. */
153
+ appearance?: Appearance;
154
+ }
155
+
156
+ /** A qualified relationship as read from the store. */
157
+ export interface RelationshipInfo {
158
+ iri: string;
159
+ /** The `arch:QualifiedRelationship` subclass (e.g. `am4:Serving`). */
160
+ classIri: string;
161
+ /** The unqualified predicate (e.g. `am4:serves`), when the metamodel maps one. */
162
+ predicateIri?: string;
163
+ sourceIri: string;
164
+ targetIri: string;
165
+ label?: string;
166
+ }
167
+
168
+ // ---------------------------------------------------------------------------
169
+ // Element Manager
170
+ // ---------------------------------------------------------------------------
171
+
172
+ /** Options for {@link ElementManager.createElement}. */
173
+ export interface CreateElementOptions {
174
+ /** `skos:prefLabel`, written language-tagged. Omit for none. */
175
+ label?: string;
176
+ /** Use this IRI instead of minting one (redo, import, collaboration). */
177
+ iri?: string;
178
+ /** Language of the label; `en` by default. */
179
+ language?: string;
180
+ }
181
+
182
+ /** Manages architecture model elements in the RDF store. */
183
+ export interface ElementManager {
184
+ /**
185
+ * Create an element: `rdf:type`, `arch:inModel` and (optionally) a label.
186
+ * Placing it in a view is the view manager's job.
187
+ */
188
+ createElement(typeIri: string, modelIri: string, options?: CreateElementOptions): NamedNode;
189
+ updateProperty(elementIri: string, property: string, value: Term): void;
190
+ /** Delete the element from the *model*: every view, every relationship. */
191
+ deleteElement(elementIri: string): void;
192
+ /** The quads {@link deleteElement} would remove — for undo snapshots. */
193
+ collectElementQuads?(elementIri: string): Quad[];
194
+ /**
195
+ * Legacy layout sink for a canvas that has no view manager (an embedded
196
+ * diagram with nowhere to put an `arch-vis:ArchNode`). The Oxigraph manager
197
+ * does not implement it: layout belongs to views.
198
+ */
199
+ updateLayout?(elementIri: string, bounds: Bounds): void;
200
+ }
201
+
202
+ // ---------------------------------------------------------------------------
203
+ // Relationship Manager
204
+ // ---------------------------------------------------------------------------
205
+
206
+ /** Request for {@link RelationshipManager.createQualifiedRelationship}. */
207
+ export interface CreateRelationshipRequest {
208
+ /** Relationship class (`am4:Serving`) or its unqualified predicate (`am4:serves`). */
209
+ typeIri: string;
210
+ /** The unqualified predicate, when the caller already knows it. */
211
+ predicateIri?: string;
212
+ sourceIri: string;
213
+ targetIri: string;
214
+ modelIri?: string;
215
+ label?: string;
216
+ /** Use this IRI instead of minting one. */
217
+ iri?: string;
218
+ }
219
+
220
+ /** Manages relationships between architecture elements. */
221
+ export interface RelationshipManager {
222
+ getValidRelationships(sourceTypeIri: string, targetTypeIri: string): RelationshipTypeInfo[];
223
+ /**
224
+ * Legacy form: a direct triple (returns `null`) or a bare qualified resource.
225
+ * New code uses {@link createQualifiedRelationship}.
226
+ */
227
+ createRelationship(
228
+ typeIri: string,
229
+ sourceIri: string,
230
+ targetIri: string,
231
+ qualified?: boolean,
232
+ ): NamedNode | null;
233
+ /**
234
+ * Create a relationship the way the Linked.Archi pattern prescribes: a
235
+ * qualified resource typed with its class, *and* the unqualified triple.
236
+ */
237
+ createQualifiedRelationship?(request: CreateRelationshipRequest): RelationshipInfo;
238
+ /** Delete a qualified relationship from the model, with its triple and links. */
239
+ deleteRelationship(relationshipIri: string): void;
240
+ /** The quads {@link deleteRelationship} would remove — for undo snapshots. */
241
+ collectRelationshipQuads?(relationshipIri: string): Quad[];
242
+ /** Read one qualified relationship. */
243
+ getRelationship?(relationshipIri: string): RelationshipInfo | undefined;
244
+ /** Every qualified relationship with the element at either end. */
245
+ getRelationshipsOf?(elementIri: string): RelationshipInfo[];
246
+ /**
247
+ * Change a relationship's kind in place: same IRI, same properties, new class
248
+ * type and unqualified triple.
249
+ */
250
+ retypeRelationship?(relationshipIri: string, typeIri: string): RelationshipInfo | undefined;
251
+ /**
252
+ * Move a relationship's ends to other elements (a connection reattached on
253
+ * the canvas): `arch:source`/`arch:target` and the unqualified triple follow.
254
+ */
255
+ reconnectRelationship?(relationshipIri: string, sourceIri: string, targetIri: string): RelationshipInfo | undefined;
256
+ }
257
+
258
+ // ---------------------------------------------------------------------------
259
+ // View Manager
260
+ // ---------------------------------------------------------------------------
261
+
262
+ /** Manages architecture views (Diagram, Catalog, Matrix) and their geometry. */
263
+ export interface ViewManager {
264
+ createView(
265
+ type: ViewKind,
266
+ viewpointIri?: string,
267
+ options?: { label?: string; modelIri?: string; iri?: string },
268
+ ): NamedNode;
269
+ getViews(modelIri?: string): ViewInfo[];
270
+ getView(viewIri: string): ViewInfo | undefined;
271
+ renameView(viewIri: string, label: string): void;
272
+ setViewpoint(viewIri: string, viewpointIri: string | undefined): void;
273
+ /** Delete the view, its geometry and its placements' and lines' own styles; the concepts it showed stay in the model. */
274
+ deleteView(viewIri: string): void;
275
+ collectViewQuads(viewIri: string): Quad[];
276
+ duplicateView(viewIri: string, label?: string): NamedNode;
277
+
278
+ /**
279
+ * Place an element: idempotent per view — the node it has — unless `another`
280
+ * asks for one more placement of it. Returns the node IRI.
281
+ *
282
+ * Wherever an element's IRI keys a node (`getNode`, `updateNodeBounds`,
283
+ * `setNodeParent`, `removeElementFromView`, `collectNodeQuads`), a node's IRI
284
+ * does too, and names that one placement.
285
+ */
286
+ /**
287
+ * Place an element in a view. `another` places it again beside a placement it has; `iri` names the node,
288
+ * where an import keeps its source's names — otherwise it is minted in the view's IRI, `{view}#node-{uuid}`.
289
+ */
290
+ addElementToView(viewIri: string, elementIri: string, bounds?: Bounds, options?: { another?: boolean; iri?: string }): string;
291
+ /**
292
+ * Remove the element's nodes, their links, and its `arch:inView` for this
293
+ * view — or, given a node, that placement alone (`arch:inView` with its last).
294
+ */
295
+ removeElementFromView(viewIri: string, elementIri: string): void;
296
+ /**
297
+ * Draw an element's node inside another's in the view (`arch-vis:inNode`), or
298
+ * — `undefined` — inside nothing. Bounds are not changed.
299
+ */
300
+ setNodeParent?(viewIri: string, elementIri: string, parentElementIri: string | undefined): void;
301
+ /**
302
+ * Draw a figure in a diagram view — a group, a shape, a note — standing for
303
+ * no model element; `parentIri` names the element or figure it is drawn
304
+ * inside. Returns the node's IRI, which is the figure's key wherever an
305
+ * element's IRI keys a node (`getNode`, `updateNodeBounds`, `setNodeParent`,
306
+ * `removeElementFromView`).
307
+ */
308
+ addFigure?(viewIri: string, figure: FigureInfo & { bounds: Bounds; parentIri?: string }, iri?: string): string;
309
+ /** A figure's text (`skos:prefLabel`), or none. */
310
+ setFigureText?(viewIri: string, nodeIri: string, text: string | undefined): void;
311
+ /** A node's drawing order (`arch-vis:zOrder`, core-vis 0.10), by node IRI; 0 or `undefined` writes none. */
312
+ setNodeZOrder?(viewIri: string, nodeIri: string, zOrder: number | undefined): void;
313
+ /**
314
+ * The references to a view — the nodes that open it (`arch-vis:referencesView`) — in every view, each with the
315
+ * view it is drawn in; by holder, then by node. A reference is its view's placement: wherever a concept's IRI keys
316
+ * its nodes (`getNode`, `removeElementFromView`, a link's ends), a view's IRI keys its references in that view.
317
+ */
318
+ referencesTo?(viewIri: string): ViewReferenceInfo[];
319
+ /**
320
+ * Point a reference drawn in `holderIri` at another view (`arch-vis:referencesView`). The view it opened leaves
321
+ * the holder (`arch:inView`) with its last reference there, and `viewIri` is presented there unless it is the
322
+ * holder — the rule {@link addFigure} and {@link collectNodeQuads} follow. Its text of its own stays. Nothing
323
+ * changes for a node that is not a reference of the holder, or a `viewIri` that is not a view.
324
+ */
325
+ setReferenceView?(holderIri: string, nodeIri: string, viewIri: string): void;
326
+ /** The quads {@link setReferenceView} removes and adds, read before anything changes. */
327
+ setReferenceViewQuads?(holderIri: string, nodeIri: string, viewIri: string): { removed: Quad[]; added: Quad[] };
328
+ /**
329
+ * The views that refine a concept — `V arch:refines X`, or `X arch:refinedInto V` — by name: what zooming in
330
+ * from it opens.
331
+ */
332
+ viewsRefining?(conceptIri: string): ViewInfo[];
333
+ /** A connector's text (its `skos:prefLabel`); none removes it. */
334
+ setConnectorText?(viewIri: string, linkIri: string, text: string | undefined): void;
335
+ /** Set a figure's colours on its own style — `null` takes one back to the default. */
336
+ setFigureColours?(viewIri: string, nodeIri: string, colours: { [K in keyof FigureColours]?: string | null }): void;
337
+ /**
338
+ * Set how one thing drawn in the view looks, on its own style: a node (an
339
+ * element's placement, a figure) or a link (a relationship's line, a line
340
+ * from a note), by its IRI. `null` takes a value back to the default. A
341
+ * style it shares, or one another tool wrote as a blank node, is copied to
342
+ * its own first, so the change is to it alone.
343
+ */
344
+ setAppearance?(viewIri: string, iri: string, changes: AppearanceChanges, context?: string): void;
345
+ /**
346
+ * What a placement's label says (core-vis 0.7's `arch-vis:labelExpression`):
347
+ * its expression for one presentation context (core's
348
+ * `arch:inPresentationContext`), or — `context` absent — for every context;
349
+ * `null` or empty takes it away. On the node's own style.
350
+ */
351
+ setLabelExpression?(viewIri: string, nodeIri: string, context: string | undefined, expression: string | null): void;
352
+ /** Every picture (`arch-vis:image`) any style of the model draws, once each, in order: to pick one again. */
353
+ usedImages?(): string[];
354
+ /**
355
+ * Draw a line standing for no relationship between two nodes of a diagram
356
+ * view (placements or figures; an element's IRI names its first placement)
357
+ * — a note pointing at what it is about.
358
+ * Returns the link's IRI, its key wherever a relationship's IRI keys a link
359
+ * (`updateLinkWaypoints`, `setLinkLabel`, `removeRelationshipFromView`), or
360
+ * `undefined` when an end is not a node of the view.
361
+ */
362
+ addConnector?(
363
+ viewIri: string,
364
+ ends: { sourceNodeIri: string; targetNodeIri: string },
365
+ waypoints?: Point[],
366
+ iri?: string,
367
+ ): string | undefined;
368
+ /** Re-point such a line's ends at other nodes of its view. */
369
+ reconnectConnector?(viewIri: string, linkIri: string, ends: { sourceNodeIri: string; targetNodeIri: string }): void;
370
+ collectNodeQuads(viewIri: string, elementIri: string): Quad[];
371
+ getNodes(viewIri: string): NodeInfo[];
372
+ getNode(viewIri: string, elementIri: string): NodeInfo | undefined;
373
+ updateNodeBounds(viewIri: string, elementIri: string, bounds: Bounds): void;
374
+
375
+ /**
376
+ * Draw a relationship between its two ends: placed elements, or — for an end
377
+ * that is a relationship — that relationship's link. `ends` names the
378
+ * placements, when an element has several (its first otherwise). Idempotent
379
+ * per view — the link it has — unless `another` asks for one more line of it.
380
+ * `undefined` if an end is not drawn in the view.
381
+ *
382
+ * Wherever a relationship's IRI keys a link (`updateLinkWaypoints`,
383
+ * `setLinkLabel`, `removeRelationshipFromView`, `collectLinkQuads`), a link's
384
+ * IRI does too, and names that one line.
385
+ */
386
+ addRelationshipToView(
387
+ viewIri: string,
388
+ relationshipIri: string,
389
+ waypoints?: Point[],
390
+ ends?: { sourceNodeIri?: string; targetNodeIri?: string },
391
+ options?: { another?: boolean; iri?: string },
392
+ ): string | undefined;
393
+ removeRelationshipFromView(viewIri: string, relationshipIri: string): void;
394
+ collectLinkQuads(viewIri: string, relationshipIri: string): Quad[];
395
+ getLinks(viewIri: string): LinkInfo[];
396
+ updateLinkWaypoints(viewIri: string, relationshipIri: string, waypoints: Point[]): void;
397
+ /**
398
+ * Keep where a relationship's name is drawn in a view — an
399
+ * `arch-vis:LabelNode` hung on its link with `arch-vis:label` — or, with no
400
+ * bounds, drop it: the name goes back to the middle of the route.
401
+ */
402
+ setLinkLabel?(viewIri: string, relationshipIri: string, bounds: Bounds | undefined): void;
403
+
404
+ /** Views presenting a concept (by `arch:inView` or by geometry). */
405
+ viewsContaining(conceptIri: string): string[];
406
+ /** The concepts a view presents (`arch:inView`). */
407
+ getMembers?(viewIri: string): string[];
408
+ /** Present a concept in a catalog or matrix: `arch:inView` alone (idempotent). */
409
+ addMember?(viewIri: string, conceptIri: string): void;
410
+ /** Stop presenting it there: its `arch:inView`. */
411
+ removeMember?(viewIri: string, conceptIri: string): void;
412
+ /**
413
+ * After a relationship's ends changed: re-point its links at the nodes of
414
+ * the new ends in every view, and remove the link where an end is not placed.
415
+ */
416
+ refreshLinksOf?(relationshipIri: string): void;
417
+ }
@@ -0,0 +1,183 @@
1
+ /**
2
+ * A model's IRIs against the layout every Linked.Archi tool mints (DD-41, the
3
+ * IRI minting guide's *Conformance check*): what `la-gram-git check` reports.
4
+ * It reports and never fails, so a repository's models do not start failing
5
+ * for names given before the layout; those are counted as legacy.
6
+ *
7
+ * Read from the triples, as the guide says to: the model is the `arch:Model`, a
8
+ * shape what has an `arch-vis:view`, a part what one of a part's properties
9
+ * names from its one owner. Each IRI of the model's namespace — and the model's
10
+ * own — goes into the first of these that applies:
11
+ *
12
+ * | Category | The IRI |
13
+ * |--------------|---------|
14
+ * | `characters` | holds a character a path segment cannot, such as a space |
15
+ * | `hashes` | holds more than one `#` |
16
+ * | `shape` | is a shape not named `{view}#node-{id}` or `{view}#link-{id}`, for the view its `arch-vis:view` names |
17
+ * | `part` | is a part not named under its owner, `{owner}/…`, or `{owner}-…` when its owner is a shape |
18
+ * | `outside` | is none of these, and its local part is not `model`, `graph/…` or `{kind}/{id}` |
19
+ *
20
+ * — unless it is named as before the layout, which makes it `legacy` instead:
21
+ * la-gram's `{kind}-{id}` and `{owner}-{part}`, a converter's
22
+ * `{ns}view/{v}/node/{id}`, meta's derivation rules' `{ns}derivation-{sha1}`
23
+ * and `{ns}derivation-activity-{sha1}[-association]`.
24
+ */
25
+
26
+ import type { Quad, Term } from '@rdfjs/types';
27
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
28
+ import { ensureNamespace, isPathNamespace } from '../rdf-engine/iri.js';
29
+ import { derivedNamespace } from './model-namespace.js';
30
+ import { SCHEMA_ITEM_LIST_ELEMENT } from './model-queries.js';
31
+ import { IRI } from './vocabulary.js';
32
+
33
+ /** What can be wrong with an IRI, in the order it is looked for; `legacy` is not wrong. */
34
+ export const LAYOUT_CATEGORIES = ['characters', 'hashes', 'shape', 'part', 'outside', 'legacy'] as const;
35
+ export type LayoutCategory = (typeof LAYOUT_CATEGORIES)[number];
36
+
37
+ /** A model's IRIs against the layout. */
38
+ export interface LayoutReport {
39
+ /** The `arch:Model`. */
40
+ model: string;
41
+ /** Its namespace: stated, or derived from its IRI. */
42
+ namespace: string;
43
+ /** Whether the model states it, with `vann:preferredNamespaceUri`. */
44
+ declared: boolean;
45
+ /** What breaks DD-41's rule for the namespace, said of it (`holds a # or a ?`); absent when nothing does. */
46
+ namespaceProblem?: string;
47
+ /** The IRIs of each category, sorted. */
48
+ iris: Record<LayoutCategory, string[]>;
49
+ }
50
+
51
+ /** The kinds of resource with an identity of their own: `{ns}{kind}/{id}` (the guide's kinds table). */
52
+ const KINDS = 'element|relationship|view|folder|decision|documentation|stakeholder|provenance';
53
+ const IN_LAYOUT = new RegExp(`^(?:model(?:/.*)?|graph/[^/#]+|(?:${KINDS})/[^/#].*)$`);
54
+ /**
55
+ * What la-gram minted before DD-41: `{ns}element-{uuid}`, `{ns}node-{uuid}`, and their parts, `{node}-style`;
56
+ * and meta's ArchiMate derivation rules: `{ns}relationship-{sha1}` for a triple they qualified,
57
+ * `{ns}derivation-{sha1}` for a derivation, `{ns}derivation-activity-{sha1}` and its `-association`.
58
+ */
59
+ const LEGACY = /^(?:element|relationship|view|folder|node|link|derivation)-./;
60
+ /** A converter's shapes before DD-41: `{ns}view/{v}/node/{id}`. */
61
+ const LEGACY_SHAPE = /^view\/[^/#]+\/(?:node|link|connection)\/[^/#]+$/;
62
+ /** A path's characters (RFC 3987 `ipchar` and `/`), and a fragment's (`?` too, and `#`, which `hashes` counts). */
63
+ const PATH = /^(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/]|%[0-9A-Fa-f]{2}|[^\x00-\x7F])*$/;
64
+ const FRAGMENT = /^(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/?#]|%[0-9A-Fa-f]{2}|[^\x00-\x7F])*$/;
65
+
66
+ const VANN_URI = NAMESPACES.vann + 'preferredNamespaceUri';
67
+ /** What names a part from its owner (DD-41's table): `{shape}-style`, `{shape}-label`, `{concept}/name/…`, `{folder}/item/…`. */
68
+ const PART_OF = new Set<string>([
69
+ IRI.visStyle,
70
+ IRI.visLabel,
71
+ IRI.labelExpression,
72
+ IRI.skosxlAltLabel,
73
+ IRI.prefVisNotation,
74
+ IRI.altVisNotation,
75
+ ...SCHEMA_ITEM_LIST_ELEMENT.map((t) => t.value),
76
+ ]);
77
+ const NODE_TYPES = new Set<string>([IRI.ArchNode, IRI.ContainerNode, IRI.LabelNode, IRI.ViewReferenceNode]);
78
+ /** A shape's fragment in its view: a line's `link-{id}`, a node's `node-{id}`, either for a shape of no known type. */
79
+ const SHAPE_NAME = { link: /^link-[^/#]+$/, node: /^node-[^/#]+$/, either: /^(?:node|link)-[^/#]+$/ };
80
+
81
+ /** The layout report of a model's triples; `undefined` when they have no `arch:Model`. */
82
+ export function layoutReport(quads: readonly Quad[]): LayoutReport | undefined {
83
+ const models = [
84
+ ...new Set(quads.filter((q) => q.subject.termType === 'NamedNode' && q.predicate.value === IRI.rdfType && q.object.value === IRI.Model).map((q) => q.subject.value)),
85
+ ].sort();
86
+ const model = models[0];
87
+ if (!model) return undefined;
88
+ const stated = quads.find((q) => q.subject.value === model && q.predicate.value === VANN_URI && q.object.termType === 'Literal')?.object.value.trim();
89
+ const namespace = stated ? ensureNamespace(stated) : derivedNamespace(model);
90
+ const problem = namespaceFault(stated ?? namespace);
91
+
92
+ // What the triples say a name is: a shape in a view, a part of an owner, a route's cells and points.
93
+ const views = new Map<string, string>();
94
+ const types = new Map<string, Set<string>>();
95
+ const owners = new Map<string, Set<string>>();
96
+ const labels = new Set<string>();
97
+ const firsts = new Map<string, string>();
98
+ const rests = new Map<string, string>();
99
+ const routes: Array<[string, string]> = [];
100
+ const iris = new Set<string>();
101
+ const collect = (term: Term) => {
102
+ if (term.termType === 'NamedNode') iris.add(term.value);
103
+ else if (term.termType === 'Quad') {
104
+ const inner = term as unknown as Quad;
105
+ [inner.subject, inner.predicate, inner.object].forEach(collect);
106
+ }
107
+ };
108
+ for (const q of quads) {
109
+ [q.subject, q.predicate, q.object, q.graph].forEach(collect);
110
+ if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
111
+ const [s, p, o] = [q.subject.value, q.predicate.value, q.object.value];
112
+ if (p === IRI.visView) views.set(s, o);
113
+ else if (p === IRI.rdfType) add(types, s, o);
114
+ else if (p === IRI.points) routes.push([s, o]);
115
+ else if (p === IRI.rdfFirst) firsts.set(s, o);
116
+ else if (p === IRI.rdfRest) rests.set(s, o);
117
+ if (PART_OF.has(p)) add(owners, o, s);
118
+ if (p === IRI.visLabel) labels.add(o);
119
+ }
120
+ // A route's cells and points are the line's.
121
+ for (const [link, first] of routes) {
122
+ const seen = new Set<string>();
123
+ for (let cell: string | undefined = first; cell && cell !== IRI.rdfNil && !seen.has(cell); cell = rests.get(cell)) {
124
+ seen.add(cell);
125
+ add(owners, cell, link);
126
+ const point = firsts.get(cell);
127
+ if (point) add(owners, point, link);
128
+ }
129
+ }
130
+
131
+ /** Where an IRI of the namespace goes, or the model's; `undefined` when it is in the layout. */
132
+ const categoryOf = (iri: string): LayoutCategory | undefined => {
133
+ // The model, not `{ns}model`.
134
+ if (!iri.startsWith(namespace)) return 'outside';
135
+ const local = iri.slice(namespace.length);
136
+ const hash = local.indexOf('#');
137
+ if (!PATH.test(hash < 0 ? local : local.slice(0, hash)) || (hash >= 0 && !FRAGMENT.test(local.slice(hash + 1)))) return 'characters';
138
+ if (iri.split('#').length > 2) return 'hashes';
139
+ const view = views.get(iri);
140
+ if (view && !labels.has(iri)) {
141
+ const kinds = types.get(iri) ?? new Set<string>();
142
+ const name = kinds.has(IRI.Link) ? SHAPE_NAME.link : [...kinds].some((t) => NODE_TYPES.has(t)) ? SHAPE_NAME.node : SHAPE_NAME.either;
143
+ if (iri.startsWith(`${view}#`) && name.test(iri.slice(view.length + 1))) return undefined;
144
+ return LEGACY.test(local) || LEGACY_SHAPE.test(local) ? 'legacy' : 'shape';
145
+ }
146
+ const owner = owners.get(iri);
147
+ if (owner?.size === 1) {
148
+ const [of] = [...owner];
149
+ // After a `#` a part is joined to its owner with `-`, elsewhere with `/`; joined the other way, it is legacy.
150
+ const [joined, other] = of.includes('#') ? ['-', '/'] : ['/', '-'];
151
+ if (iri.startsWith(`${of}${joined}`)) return undefined;
152
+ return iri.startsWith(`${of}${other}`) ? 'legacy' : 'part';
153
+ }
154
+ if (IN_LAYOUT.test(local)) return undefined;
155
+ return LEGACY.test(local) ? 'legacy' : 'outside';
156
+ };
157
+
158
+ const found = Object.fromEntries(LAYOUT_CATEGORIES.map((c) => [c, [] as string[]])) as Record<LayoutCategory, string[]>;
159
+ for (const iri of [...iris].sort()) {
160
+ if (iri !== model && (!iri.startsWith(namespace) || iri.length === namespace.length)) continue;
161
+ const category = categoryOf(iri);
162
+ if (category) found[category].push(iri);
163
+ }
164
+ return { model, namespace, declared: stated !== undefined, ...(problem ? { namespaceProblem: problem } : {}), iris: found };
165
+ }
166
+
167
+ /**
168
+ * What breaks DD-41's rule for a model's namespace — an `https:` or `http:` IRI
169
+ * that ends in `/`, with no `#` or `?` — said of it: `holds a # or a ?`.
170
+ */
171
+ function namespaceFault(namespace: string): string | undefined {
172
+ if (/[\s<>"{}|\\^`]/.test(namespace)) return 'holds characters an IRI cannot';
173
+ if (/[#?]/.test(namespace)) return 'holds a # or a ?';
174
+ if (!/^https?:\/\//i.test(namespace)) return 'is not an https: or http: IRI';
175
+ if (!namespace.endsWith('/')) return 'does not end in /';
176
+ return isPathNamespace(namespace) ? undefined : 'is not an https: or http: IRI ending in /';
177
+ }
178
+
179
+ function add(map: Map<string, Set<string>>, key: string, value: string): void {
180
+ const set = map.get(key);
181
+ if (set) set.add(value);
182
+ else map.set(key, new Set([value]));
183
+ }