@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,233 @@
1
+ /**
2
+ * What a label says, as an expression (core-vis 0.7's `arch-vis:LabelExpression`):
3
+ * text drawn as it is but for its placeholders between braces —
4
+ *
5
+ * - `{name}`: the concept's name;
6
+ * - `{type}`: the name of its type;
7
+ * - `{prefix:local}` or `{<iri>}`: the values of that property of the concept,
8
+ * a literal as it is, a resource by its name, several joined by ", ";
9
+ * - a path: properties joined by `/`, each followed on from the values before
10
+ * it, `^` before one to follow it backwards (`{^arch:target/arch:source}`);
11
+ * - `{{` and `}}`: a brace.
12
+ *
13
+ * Its lines are the label's lines. A line whose placeholders all come to
14
+ * nothing is left out, so a line can be there only when the concept has what
15
+ * it shows. A placeholder that cannot be read — an unknown prefix, an empty
16
+ * path — is drawn as it was written, so that the mistake shows, and is listed
17
+ * in {@link ParsedLabelExpression.errors}.
18
+ */
19
+
20
+ import type { PrefixMap } from '../rdf-engine/interfaces.js';
21
+
22
+ /** A value as the expression reads it: a literal, or a resource. */
23
+ export type LabelValue = { literal: string; language?: string } | { iri: string };
24
+
25
+ /** Where an expression reads what it shows. */
26
+ export interface LabelSource {
27
+ /** The values of `predicate` on `subject`. */
28
+ values(subject: string, predicate: string): LabelValue[];
29
+ /** What has `object` as a value of `predicate`. */
30
+ subjectsOf(object: string, predicate: string): string[];
31
+ /** A resource's name for the presentation context shown: its name for that audience, else its canonical name. */
32
+ nameOf(iri: string): string | undefined;
33
+ /** Its name for the presentation context shown alone (a SKOS-XL name) — `undefined` when it has none, or none is shown. */
34
+ nameForContext?(iri: string): string | undefined;
35
+ /** Its picture for the presentation context shown — else its picture for every audience (core 0.5.0). Not for expressions: for drawing. */
36
+ pictureFor?(iri: string): string | undefined;
37
+ /** The name of a concept's type. */
38
+ typeOf(iri: string): string | undefined;
39
+ /** The prefixes a prefixed name may use: the vocabularies' in use and the model's own. */
40
+ prefixes: PrefixMap;
41
+ }
42
+
43
+ interface Step {
44
+ iri: string;
45
+ inverse: boolean;
46
+ }
47
+
48
+ type Part = { text: string } | { name: true } | { type: true } | { path: Step[] } | { error: string; source: string };
49
+
50
+ export interface ParsedLabelExpression {
51
+ lines: Part[][];
52
+ /** What could not be read, each with the placeholder as written. */
53
+ errors: string[];
54
+ }
55
+
56
+ /** At most this many values of one placeholder are shown; the rest as "…". */
57
+ const MAX_VALUES = 20;
58
+
59
+ /** Read an expression: its lines, each its text and placeholders. */
60
+ export function parseLabelExpression(expression: string, prefixes: PrefixMap): ParsedLabelExpression {
61
+ const errors: string[] = [];
62
+ const lines = expression.replace(/\r\n?/g, '\n').split('\n').map((line) => parseLine(line, prefixes, errors));
63
+ return { lines, errors };
64
+ }
65
+
66
+ function parseLine(line: string, prefixes: PrefixMap, errors: string[]): Part[] {
67
+ const parts: Part[] = [];
68
+ let text = '';
69
+ let i = 0;
70
+ while (i < line.length) {
71
+ const c = line[i]!;
72
+ if (c === '{' && line[i + 1] === '{') {
73
+ text += '{';
74
+ i += 2;
75
+ continue;
76
+ }
77
+ if (c === '}' && line[i + 1] === '}') {
78
+ text += '}';
79
+ i += 2;
80
+ continue;
81
+ }
82
+ if (c === '{') {
83
+ const end = closingBrace(line, i + 1);
84
+ if (end < 0) {
85
+ // Never closed: text, as written.
86
+ text += line.slice(i);
87
+ break;
88
+ }
89
+ if (text) parts.push({ text });
90
+ text = '';
91
+ const source = line.slice(i, end + 1);
92
+ const placeholder = parsePlaceholder(line.slice(i + 1, end).trim(), prefixes);
93
+ if ('error' in placeholder) {
94
+ errors.push(`${source}: ${placeholder.error}`);
95
+ parts.push({ error: placeholder.error, source });
96
+ } else parts.push(placeholder);
97
+ i = end + 1;
98
+ continue;
99
+ }
100
+ text += c;
101
+ i += 1;
102
+ }
103
+ if (text) parts.push({ text });
104
+ return parts;
105
+ }
106
+
107
+ /** Where the placeholder opened before `from` closes: past any `<…>` IRI, which may hold a brace. */
108
+ function closingBrace(line: string, from: number): number {
109
+ let inIri = false;
110
+ for (let i = from; i < line.length; i += 1) {
111
+ const c = line[i];
112
+ if (c === '<') inIri = true;
113
+ else if (c === '>') inIri = false;
114
+ else if (c === '}' && !inIri) return i;
115
+ }
116
+ return -1;
117
+ }
118
+
119
+ function parsePlaceholder(content: string, prefixes: PrefixMap): Part | { error: string } {
120
+ if (content === 'name') return { name: true };
121
+ if (content === 'type') return { type: true };
122
+ if (content === '') return { error: 'nothing between the braces' };
123
+ const steps: Step[] = [];
124
+ let rest = content;
125
+ while (rest.length > 0) {
126
+ let inverse = false;
127
+ if (rest.startsWith('^')) {
128
+ inverse = true;
129
+ rest = rest.slice(1).trimStart();
130
+ }
131
+ let token: string;
132
+ if (rest.startsWith('<')) {
133
+ const end = rest.indexOf('>');
134
+ if (end < 0) return { error: 'an IRI not closed with >' };
135
+ token = rest.slice(0, end + 1);
136
+ rest = rest.slice(end + 1).trimStart();
137
+ } else {
138
+ const slash = rest.indexOf('/');
139
+ token = (slash < 0 ? rest : rest.slice(0, slash)).trim();
140
+ rest = slash < 0 ? '' : rest.slice(slash);
141
+ }
142
+ const iri = resolve(token, prefixes);
143
+ if ('error' in iri) return iri;
144
+ steps.push({ iri: iri.iri, inverse });
145
+ if (rest.startsWith('/')) {
146
+ rest = rest.slice(1).trimStart();
147
+ if (rest === '') return { error: 'a path ending with /' };
148
+ } else if (rest !== '') return { error: `"${rest}" after ${token}` };
149
+ }
150
+ return { path: steps };
151
+ }
152
+
153
+ function resolve(token: string, prefixes: PrefixMap): { iri: string } | { error: string } {
154
+ if (token.startsWith('<') && token.endsWith('>')) {
155
+ const iri = token.slice(1, -1).trim();
156
+ return /^[a-z][\w+.-]*:\S+$/i.test(iri) ? { iri } : { error: `${token} is not an IRI` };
157
+ }
158
+ if (token === 'name' || token === 'type') return { error: `${token} stands alone, not in a path` };
159
+ const colon = token.indexOf(':');
160
+ if (colon < 0) return { error: `${token || 'a step'} is neither name, type, a prefixed name nor an <IRI>` };
161
+ const prefix = token.slice(0, colon);
162
+ const local = token.slice(colon + 1);
163
+ const namespace = prefixes[prefix];
164
+ if (namespace === undefined) return { error: `no prefix ${prefix}: is known` };
165
+ if (!/^[^\s<>"{}|^`\\/]*$/.test(local)) return { error: `${token} is not a prefixed name` };
166
+ return { iri: namespace + local };
167
+ }
168
+
169
+ /** What an expression says for `subject`: its lines, those whose placeholders all come to nothing left out. */
170
+ export function evaluateLabelExpression(
171
+ parsed: ParsedLabelExpression,
172
+ subject: string,
173
+ source: LabelSource,
174
+ language = 'en',
175
+ ): string {
176
+ const kept: string[] = [];
177
+ for (const line of parsed.lines) {
178
+ let text = '';
179
+ let placeholders = 0;
180
+ let filled = 0;
181
+ for (const part of line) {
182
+ if ('text' in part) {
183
+ text += part.text;
184
+ continue;
185
+ }
186
+ if ('error' in part) {
187
+ // Drawn as written, so the mistake shows.
188
+ text += part.source;
189
+ continue;
190
+ }
191
+ placeholders += 1;
192
+ const value = 'name' in part ? (source.nameOf(subject) ?? '') : 'type' in part ? (source.typeOf(subject) ?? '') : pathValues(part.path, subject, source, language);
193
+ if (value) filled += 1;
194
+ text += value;
195
+ }
196
+ if (placeholders > 0 && filled === 0) continue;
197
+ kept.push(text);
198
+ }
199
+ return kept.join('\n').trim();
200
+ }
201
+
202
+ /** Read and evaluate in one: what `expression` says for `subject`. */
203
+ export function labelFromExpression(expression: string, subject: string, source: LabelSource, language?: string): string {
204
+ return evaluateLabelExpression(parseLabelExpression(expression, source.prefixes), subject, source, language);
205
+ }
206
+
207
+ function pathValues(path: Step[], subject: string, source: LabelSource, language: string): string {
208
+ let frontier: LabelValue[] = [{ iri: subject }];
209
+ for (const step of path) {
210
+ const next: LabelValue[] = [];
211
+ for (const value of frontier) {
212
+ // A literal has no properties to follow.
213
+ if (!('iri' in value)) continue;
214
+ if (step.inverse) next.push(...source.subjectsOf(value.iri, step.iri).map((iri) => ({ iri })));
215
+ else next.push(...source.values(value.iri, step.iri));
216
+ }
217
+ frontier = next;
218
+ }
219
+ // A literal in the language shown, or with none — any, when it has neither.
220
+ const literals = frontier.filter((v): v is { literal: string; language?: string } => 'literal' in v);
221
+ const preferred = literals.filter((v) => !v.language || v.language === language);
222
+ const shownLiterals = preferred.length > 0 ? preferred : literals;
223
+ const shown = [
224
+ ...frontier.filter((v): v is { iri: string } => 'iri' in v).map((v) => source.nameOf(v.iri) ?? localName(v.iri)),
225
+ ...shownLiterals.map((v) => v.literal),
226
+ ].filter((v) => v !== '');
227
+ const unique = [...new Set(shown)];
228
+ return unique.length > MAX_VALUES ? `${unique.slice(0, MAX_VALUES).join(', ')}, …` : unique.join(', ');
229
+ }
230
+
231
+ function localName(iri: string): string {
232
+ return iri.split(/[#/]/).pop() || iri;
233
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Bring a loaded model up to the current vocabulary.
3
+ *
4
+ * Models in the wild predate `core` 0.4.0 and the view layer this tool now
5
+ * writes. Rather than reason over old terms forever, loading rewrites them once,
6
+ * in the default graph only (metamodel graphs are never touched):
7
+ *
8
+ * | Old | Current |
9
+ * |---------------------------------------|-------------------------------------------|
10
+ * | `arch:partOfModel` | `arch:inModel` (DD-30) |
11
+ * | `arch:exposedInView` | `arch:inView` (DD-30) |
12
+ * | `<model> arch:contains <view>` | `<view> arch:inModel <model>` (DD-30) |
13
+ * | `arch:conformsToMetamodel` | `arch:modelConformsToMetamodel` |
14
+ * | `<view> arch:viewpoint <vp>` | `<view> arch:viewConformsToViewpoint <vp>`|
15
+ * | `arch:relSource` / `relTarget` | `arch:source` / `arch:target` |
16
+ * | `arch:relPredicate <p>` | `rdf:type` the class mapped to `p`, plus the unqualified triple |
17
+ * | bounds on the element itself (la-gram ≤ 0.1) | an `arch-vis:ArchNode` in a view |
18
+ * | `<element> arch-vis:view <view>` (la-gram ≤ 0.1) | a node in that view |
19
+ *
20
+ * `arch:contains` is not declared a sub- or inverse property of anything in
21
+ * 0.4.0 (DD-30 explains why no sound mapping exists in general), so it is only
22
+ * rewritten in the one shape a model-to-view link can take.
23
+ */
24
+
25
+ import type { NamedNode, Quad } from '@rdfjs/types';
26
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
27
+ import type { Bounds, ViewManager } from './interfaces.js';
28
+ import { typeClosure } from './model-queries.js';
29
+
30
+ /** The default graph: the model. */
31
+ const MODEL_GRAPH = { termType: 'DefaultGraph', value: '' } as unknown as NamedNode;
32
+ import { IRI, T, nn, numberOf, triple } from './vocabulary.js';
33
+
34
+ /** What a migration changed. */
35
+ export interface MigrationReport {
36
+ /** Triples rewritten from a retired predicate to its replacement. */
37
+ renamed: number;
38
+ /** Qualified relationships moved to `arch:source` / `arch:target`. */
39
+ relationships: number;
40
+ /** Element-level bounds turned into view nodes. */
41
+ placements: number;
42
+ /** Things the migration could not do, for the user. */
43
+ notes: string[];
44
+ }
45
+
46
+ /** Straight predicate renames: old → new. */
47
+ const RENAMES: ReadonlyArray<[string, string]> = [
48
+ [IRI.legacyPartOfModel, IRI.inModel],
49
+ [IRI.legacyExposedInView, IRI.inView],
50
+ [IRI.legacyConformsToMetamodel, IRI.modelConformsToMetamodel],
51
+ [IRI.legacyRelSource, IRI.source],
52
+ [IRI.legacyRelTarget, IRI.target],
53
+ ];
54
+
55
+ /**
56
+ * Rewrite retired vocabulary in the model data.
57
+ *
58
+ * @param options.viewManager Used to create nodes for element-level bounds.
59
+ * @param options.defaultView Returns the view such bounds go into, creating it
60
+ * if need be. Called at most once.
61
+ */
62
+ export function migrateLegacyModel(
63
+ store: RdfStore,
64
+ options: { viewManager?: ViewManager; defaultView?: () => string } = {},
65
+ ): MigrationReport {
66
+ const report: MigrationReport = { renamed: 0, relationships: 0, placements: 0, notes: [] };
67
+ const add: Quad[] = [];
68
+ const remove: Quad[] = [];
69
+ // The model's statements with a predicate, by index — not the model scanned
70
+ // for each kind, on every opening (Task 22).
71
+ const withPredicate = (predicate: string) => store.getQuads(null, nn(predicate), null, MODEL_GRAPH);
72
+
73
+ // 1. Straight renames.
74
+ for (const [from, to] of RENAMES) {
75
+ for (const q of withPredicate(from)) {
76
+ remove.push(q);
77
+ add.push(triple(q.subject, nn(to), q.object));
78
+ report.renamed += 1;
79
+ }
80
+ }
81
+
82
+ // 2. Views: `arch:viewpoint` and container-first `arch:contains`.
83
+ const legacyViewpoints = withPredicate(IRI.legacyViewpoint);
84
+ const legacyContains = withPredicate(IRI.legacyContains);
85
+ const views = new Set(
86
+ legacyViewpoints.length + legacyContains.length > 0
87
+ ? store.getQuads(null, T.rdfType, T.View, MODEL_GRAPH).map((q) => q.subject.value)
88
+ : [],
89
+ );
90
+ for (const q of legacyViewpoints) {
91
+ if (!views.has(q.subject.value)) continue;
92
+ remove.push(q);
93
+ add.push(triple(q.subject, T.viewConformsToViewpoint, q.object));
94
+ report.renamed += 1;
95
+ }
96
+ for (const q of legacyContains) {
97
+ if (!views.has(q.object.value)) continue;
98
+ remove.push(q);
99
+ add.push(triple(q.object, T.inModel, q.subject));
100
+ report.renamed += 1;
101
+ }
102
+
103
+ // 3. `arch:relPredicate` → a class type plus the unqualified triple.
104
+ const relPredicates = withPredicate(IRI.legacyRelPredicate);
105
+ const closure = relPredicates.length > 0 ? typeClosure(store) : () => [];
106
+ for (const q of relPredicates) {
107
+ remove.push(q);
108
+ report.relationships += 1;
109
+ const rel = q.subject;
110
+ const predicateIri = q.object.value;
111
+ const isClass = closure(predicateIri).includes(IRI.QualifiedRelationship);
112
+ // Several resources may name the predicate as their unqualified form —
113
+ // ArchiMate 4.0 also maps the qualified *property* `am4:qualifiedServing` to
114
+ // `am4:serves` — so only a relationship class qualifies; and subclasses
115
+ // share their class's (`am4:ReadAccess` is `am4:accesses` too), so the most
116
+ // general one, which says no more than the predicate does.
117
+ const candidates = isClass
118
+ ? []
119
+ : store
120
+ .getQuads(null, T.unqualifiedForm, nn(predicateIri))
121
+ .map((m) => m.subject.value)
122
+ .filter((candidate) => closure(candidate).includes(IRI.QualifiedRelationship));
123
+ const classIri = isClass
124
+ ? predicateIri
125
+ : candidates.find((candidate) =>
126
+ closure(candidate).every((superClass) => superClass === candidate || !candidates.includes(superClass)),
127
+ );
128
+ if (classIri) {
129
+ add.push(triple(rel, T.rdfType, nn(classIri)));
130
+ } else {
131
+ report.notes.push(
132
+ `Relationship <${rel.value}> names <${predicateIri}>, which no loaded metamodel defines; it stays a generic arch:QualifiedRelationship.`,
133
+ );
134
+ }
135
+ const unqualified = isClass
136
+ ? store.getQuads(nn(predicateIri), T.unqualifiedForm)[0]?.object.value
137
+ : classIri
138
+ ? predicateIri
139
+ : undefined;
140
+ const end = (legacy: string, current: string) =>
141
+ store.getQuads(rel as NamedNode, nn(legacy), null, MODEL_GRAPH)[0] ?? store.getQuads(rel as NamedNode, nn(current), null, MODEL_GRAPH)[0];
142
+ const source = end(IRI.legacyRelSource, IRI.source);
143
+ const target = end(IRI.legacyRelTarget, IRI.target);
144
+ if (unqualified && source && target) add.push(triple(source.object, nn(unqualified), target.object));
145
+ }
146
+
147
+ if (remove.length > 0) store.removeQuads(remove);
148
+ if (add.length > 0) store.addQuads(add);
149
+
150
+ // 4. Element-level geometry (la-gram ≤ 0.1) → nodes.
151
+ if (options.viewManager) migrateElementGeometry(store, options.viewManager, options.defaultView, report);
152
+
153
+ return report;
154
+ }
155
+
156
+ /** Move bounds and `arch-vis:view` off elements into proper view nodes. */
157
+ function migrateElementGeometry(
158
+ store: RdfStore,
159
+ viewManager: ViewManager,
160
+ defaultView: (() => string) | undefined,
161
+ report: MigrationReport,
162
+ ): void {
163
+ const isDiagramElement = (subject: Quad['subject']) =>
164
+ store.getQuads(subject as NamedNode, T.rdfType, null, MODEL_GRAPH).some((q) => q.object.value.startsWith('https://meta.linked.archi/core-vis#'));
165
+
166
+ // Elements carrying bounds or an arch-vis:view of their own.
167
+ const carriers = new Set<string>();
168
+ for (const predicate of [IRI.boundsX, IRI.visView]) {
169
+ for (const q of store.getQuads(null, nn(predicate), null, MODEL_GRAPH)) {
170
+ if (!carriers.has(q.subject.value) && !isDiagramElement(q.subject)) carriers.add(q.subject.value);
171
+ }
172
+ }
173
+ if (carriers.size === 0) return;
174
+
175
+ let fallbackView: string | undefined;
176
+ for (const elementIri of carriers) {
177
+ const element = nn(elementIri);
178
+ const read = (predicate: string) => numberOf(store.getQuads(element, nn(predicate))[0]?.object);
179
+ const bounds: Bounds = {
180
+ x: read(IRI.boundsX) ?? 0,
181
+ y: read(IRI.boundsY) ?? 0,
182
+ width: read(IRI.boundsW) ?? 120,
183
+ height: read(IRI.boundsH) ?? 55,
184
+ };
185
+ const ownViews = store.getQuads(element, T.visView).map((q) => q.object.value);
186
+ const targets =
187
+ ownViews.length > 0 ? ownViews : [(fallbackView ??= defaultView?.() ?? viewManager.getViews()[0]?.iri ?? '')];
188
+ for (const viewIri of targets.filter(Boolean)) {
189
+ viewManager.addElementToView(viewIri, elementIri, bounds);
190
+ report.placements += 1;
191
+ }
192
+ const stale = [
193
+ ...store.getQuads(element, T.visView),
194
+ ...[IRI.boundsX, IRI.boundsY, IRI.boundsW, IRI.boundsH].flatMap((p) =>
195
+ store.getQuads(element, nn(p) as NamedNode),
196
+ ),
197
+ ];
198
+ if (stale.length > 0) store.removeQuads(stale);
199
+ }
200
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * References to something the model does not have: a relationship's end, a
3
+ * view node's element, a link's relationship or end shapes, a shape's view, a
4
+ * route's cells, `arch:inView`, `arch:inModel`, a folder entry. la-gram never
5
+ * leaves one — deleting a concept deletes what hangs on it — but a file merged
6
+ * as text on a Git host, edited by hand or written by another tool can: one
7
+ * branch deletes CRM, another relates something to it, and both merge cleanly
8
+ * line by line. Phase 3 of the Git collaboration plan: found by the validation
9
+ * engine, so the editor's Validation tab and CI report them alike.
10
+ *
11
+ * "Not in the model" is "nothing is said about it": no triple has it as its
12
+ * subject. Each finding is a violation about the node that refers, its path the
13
+ * property; it has no shape — no vocabulary is made up for it — so the
14
+ * Validation tab shows no shape line.
15
+ */
16
+
17
+ import type { Quad, Term } from '@rdfjs/types';
18
+ import type { ValidationResult } from '../rdf-engine/interfaces.js';
19
+ import { IRI } from './vocabulary.js';
20
+
21
+ /** What a reference by each property must name, in words. */
22
+ const MUST_NAME: ReadonlyMap<string, string> = new Map([
23
+ [IRI.source, 'Its source'],
24
+ [IRI.target, 'Its target'],
25
+ [IRI.legacyRelSource, 'Its source'],
26
+ [IRI.legacyRelTarget, 'Its target'],
27
+ [IRI.archElement, 'The element it shows'],
28
+ [IRI.archRelationship, 'The relationship it shows'],
29
+ [IRI.visSource, 'The shape it starts at'],
30
+ [IRI.visTarget, 'The shape it ends at'],
31
+ [IRI.visView, 'Its view'],
32
+ [IRI.inNode, 'The shape it is inside'],
33
+ [IRI.visLabel, 'Its label'],
34
+ [IRI.points, 'Its route'],
35
+ [IRI.rdfFirst, 'A point of its route'],
36
+ [IRI.rdfRest, 'The rest of its route'],
37
+ [IRI.inView, 'A view it is in'],
38
+ [IRI.inModel, 'Its model'],
39
+ [IRI.dctermsIsPartOf, 'The folder it is in'],
40
+ ['https://schema.org/itemListElement', 'An entry of the folder'],
41
+ ['http://schema.org/itemListElement', 'An entry of the folder'],
42
+ ['https://schema.org/item', 'What the folder entry holds'],
43
+ ['http://schema.org/item', 'What the folder entry holds'],
44
+ ]);
45
+
46
+ /** The predicates the check reads: a change to a triple by another is none of its business (the kernel's KD-21). */
47
+ export const REFERENCE_PREDICATES: ReadonlySet<string> = new Set(MUST_NAME.keys());
48
+
49
+ /** The store the check reads: the model's triples by pattern. */
50
+ export interface ReferenceSource {
51
+ getQuads(subject: Term | null, predicate: Term | null, object: Term | null, graph: Term | null): Quad[];
52
+ }
53
+
54
+ /**
55
+ * The references in `data` to what it does not have — of every node, or of the
56
+ * `focus` nodes only (their own triples).
57
+ */
58
+ export function missingReferences(data: ReferenceSource, focus?: readonly Term[]): ValidationResult[] {
59
+ const quads = focus ? focus.flatMap((node) => data.getQuads(node, null, null, null)) : data.getQuads(null, null, null, null);
60
+ const known = new Map<string, boolean>();
61
+ const exists = (node: Term): boolean => {
62
+ const key = `${node.termType}:${node.value}`;
63
+ let found = known.get(key);
64
+ if (found === undefined) {
65
+ found = data.getQuads(node, null, null, null).length > 0;
66
+ known.set(key, found);
67
+ }
68
+ return found;
69
+ };
70
+ const results: ValidationResult[] = [];
71
+ for (const q of quads) {
72
+ const what = MUST_NAME.get(q.predicate.value);
73
+ const o = q.object as Term;
74
+ if (!what || (o.termType !== 'NamedNode' && o.termType !== 'BlankNode')) continue;
75
+ if (o.termType === 'NamedNode' && o.value === IRI.rdfNil) continue;
76
+ if (exists(o)) continue;
77
+ results.push({
78
+ focusNode: q.subject as ValidationResult['focusNode'],
79
+ resultPath: q.predicate as ValidationResult['resultPath'],
80
+ sourceShape: { termType: 'NamedNode', value: '' } as ValidationResult['sourceShape'],
81
+ message: `${what} is not in the model: ${o.termType === 'BlankNode' ? `_:${o.value}` : o.value}`,
82
+ severity: 'Violation',
83
+ });
84
+ }
85
+ return results;
86
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * The diff by element (`model-diff.ts`) in words: a concept's name and type, a
3
+ * value, a shape's change — one wording for the History tab, a merge request's
4
+ * description, and what CI posts on one.
5
+ *
6
+ * Names come from the versions compared ({@link ModelDiff.about}), so a concept
7
+ * removed is still named; types and properties are named by the caller, who has
8
+ * the metamodels.
9
+ */
10
+
11
+ import type { ConceptChange, ModelDiff, ShapeChange, ValueChange } from './model-diff.js';
12
+ import { literalValue } from './snapshot-lines.js';
13
+ import { localName } from './vocabulary.js';
14
+
15
+ /** What the words need from the metamodels. */
16
+ export interface DiffWords {
17
+ /** A class's name: `Application Component`. */
18
+ typeName(iri: string): string;
19
+ /** A property's name: `Name`, `Target`. */
20
+ propertyName(iri: string): string;
21
+ }
22
+
23
+ const CORE = 'https://meta.linked.archi/core#';
24
+ const NUMBER_TYPES = new Set(['double', 'decimal', 'float', 'integer', 'int', 'long', 'short', 'boolean'].map((t) => `http://www.w3.org/2001/XMLSchema#${t}`));
25
+
26
+ /** The type a concept is shown with: its first outside the core vocabulary, else its first. */
27
+ export function shownType(diff: ModelDiff, iri: string): string | undefined {
28
+ const types = diff.about[iri]?.types ?? [];
29
+ return types.find((t) => !t.startsWith(CORE)) ?? types[0];
30
+ }
31
+
32
+ /** A concept's name; one without — a relationship, mostly — by its type; else its IRI's last part. */
33
+ export function conceptName(diff: ModelDiff, iri: string, words: DiffWords): string {
34
+ const name = diff.about[iri]?.name;
35
+ if (name) return name;
36
+ const type = shownType(diff, iri);
37
+ return type ? words.typeName(type) : localName(iri) || iri;
38
+ }
39
+
40
+ /** A value: a concept by its name, text in quotes with its language (unless `language` is false), a number as it is. */
41
+ export function termLabel(diff: ModelDiff, term: string, words: DiffWords, language = true): string {
42
+ if (term.startsWith('<<')) return term;
43
+ if (term.startsWith('<')) return conceptName(diff, term.slice(1, -1), words);
44
+ if (term.startsWith('_:')) return term;
45
+ const text = literalValue(term) ?? term;
46
+ const tail = term.slice(term.lastIndexOf('"') + 1);
47
+ if (tail.startsWith('@')) return language ? `“${text}” (${tail.slice(1)})` : `“${text}”`;
48
+ if (tail.startsWith('^^<') && NUMBER_TYPES.has(tail.slice(3, -1))) return text;
49
+ return `“${text}”`;
50
+ }
51
+
52
+ /** A relationship's ends: `Billing → ERP`. */
53
+ export function endsText(diff: ModelDiff, change: ConceptChange, words: DiffWords): string | undefined {
54
+ if (!change.ends) return undefined;
55
+ const end = (iri: string | undefined) => (iri ? conceptName(diff, iri, words) : '?');
56
+ return `${end(change.ends.source)} → ${end(change.ends.target)}`;
57
+ }
58
+
59
+ /** A single value's change: `Name (en): “Billing” → “Invoicing”`; for a concept added, its value only. */
60
+ export function valueText(diff: ModelDiff, value: ValueChange, words: DiffWords, added = false): string {
61
+ const name = `${words.propertyName(value.predicate)}${value.language ? ` (${value.language})` : ''}`;
62
+ // A value per language: its language is said once, with the property.
63
+ const side = (terms: string[]) =>
64
+ terms.length === 0 ? '—' : terms.map((t) => termLabel(diff, t, words, value.language === undefined)).join(', ');
65
+ return added && value.from.length === 0 ? `${name}: ${side(value.to)}` : `${name}: ${side(value.from)} → ${side(value.to)}`;
66
+ }
67
+
68
+ /** A shape's change: `placed ERP`, `moved and resized Billing`, `removed CRM`. */
69
+ export function shapeText(diff: ModelDiff, shape: ShapeChange, words: DiffWords): string {
70
+ const what = shape.shows ? conceptName(diff, shape.shows, words) : shape.kind === 'link' ? 'a line' : 'a shape';
71
+ if (shape.status === 'added') return `${shape.kind === 'link' ? 'drew' : 'placed'} ${what}`;
72
+ if (shape.status === 'removed') return `removed ${what}`;
73
+ const verbs = [
74
+ shape.moved && 'moved',
75
+ shape.resized && 'resized',
76
+ shape.rerouted && 'rerouted',
77
+ shape.reconnected && 'reconnected',
78
+ shape.restyled && 'restyled',
79
+ ].filter((v): v is string => Boolean(v));
80
+ return `${joined(verbs.length > 0 ? verbs : ['changed'])} ${what}`;
81
+ }
82
+
83
+ /** What a concept changed, a line each: values, values added and removed, a view's shapes and what it shows. */
84
+ export function detailLines(diff: ModelDiff, change: ConceptChange, words: DiffWords): Array<{ kind: 'value' | 'added' | 'removed' | 'shape'; text: string }> {
85
+ if (change.status === 'removed') return [];
86
+ const added = change.status === 'added';
87
+ const value = (v: { predicate: string; object: string }) => `${words.propertyName(v.predicate)}: ${termLabel(diff, v.object, words)}`;
88
+ return [
89
+ ...change.values.map((v) => ({ kind: 'value' as const, text: valueText(diff, v, words, added) })),
90
+ ...change.added.map((v) => ({ kind: 'added' as const, text: value(v) })),
91
+ ...change.removed.map((v) => ({ kind: 'removed' as const, text: value(v) })),
92
+ ...change.shapes.map((s) => ({ kind: 'shape' as const, text: shapeText(diff, s, words) })),
93
+ ...change.shows.added.map((iri) => ({ kind: 'added' as const, text: `shows ${conceptName(diff, iri, words)}` })),
94
+ ...change.shows.removed.map((iri) => ({ kind: 'removed' as const, text: `no longer shows ${conceptName(diff, iri, words)}` })),
95
+ ];
96
+ }
97
+
98
+ /** A time as the Markdown gives it, the same wherever it is written: `2026-11-20 16:40 UTC`. */
99
+ export function utcMinute(iso: string): string {
100
+ const date = new Date(iso);
101
+ return Number.isNaN(date.getTime()) ? iso : `${date.toISOString().slice(0, 16).replace('T', ' ')} UTC`;
102
+ }
103
+
104
+ /** Who made a change and when, as the later version records it: `by Ada Lovelace, 2026-11-20 16:40 UTC`. */
105
+ export function editText(change: ConceptChange, when: (iso: string) => string = utcMinute): string | undefined {
106
+ const edit = change.edit;
107
+ if (!edit?.by && !edit?.at) return undefined;
108
+ return [edit.by ? `by ${edit.by}` : '', edit.at ? when(edit.at) : ''].filter(Boolean).join(', ');
109
+ }
110
+
111
+ /** `1 added · 1 removed · 5 changed`, leaving out the noughts; `No changes` for none. */
112
+ export function countsText(diff: ModelDiff): string {
113
+ const parts = (['added', 'removed', 'changed'] as const).filter((s) => diff.counts[s] > 0).map((s) => `${diff.counts[s]} ${s}`);
114
+ return parts.length > 0 ? parts.join(' · ') : 'No changes';
115
+ }
116
+
117
+ /**
118
+ * The diff as Markdown: the counts, then a line per concept with what changed
119
+ * under it — at most `limit` concepts, the rest counted.
120
+ */
121
+ export function markdownOfDiff(diff: ModelDiff, words: DiffWords, limit = 100): string {
122
+ if (diff.changes.length === 0) return '_No changes to the model._';
123
+ const out = [`**Changes by element:** ${countsText(diff)}`, ''];
124
+ const sign = { added: '➕', removed: '➖', changed: '✏️' } as const;
125
+ const escape = (text: string) => text.replace(/([\\`*_[\]<>|])/g, '\\$1');
126
+ for (const change of diff.changes.slice(0, limit)) {
127
+ const type = shownType(diff, change.subject);
128
+ const ends = endsText(diff, change, words);
129
+ const edit = editText(change);
130
+ const head = [
131
+ `${sign[change.status]} **${escape(conceptName(diff, change.subject, words))}**`,
132
+ type && diff.about[change.subject]?.name ? ` _${escape(words.typeName(type))}_` : '',
133
+ ends ? ` ${escape(ends)}` : '',
134
+ change.status === 'changed' ? (edit ? ' — changed' : '') : ` — ${change.status}`,
135
+ edit ? ` ${escape(edit)}` : '',
136
+ ].join('');
137
+ out.push(`- ${head}`);
138
+ for (const line of detailLines(diff, change, words)) {
139
+ const mark = line.kind === 'added' ? '+ ' : line.kind === 'removed' ? '− ' : '';
140
+ out.push(` - ${mark}${escape(line.text)}`);
141
+ }
142
+ }
143
+ const more = diff.changes.length - limit;
144
+ if (more > 0) out.push('', `_… and ${more} more._`);
145
+ return out.join('\n');
146
+ }
147
+
148
+ function joined(words: string[]): string {
149
+ return words.length <= 1 ? (words[0] ?? '') : `${words.slice(0, -1).join(', ')} and ${words.at(-1)}`;
150
+ }