@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,534 @@
1
+ /**
2
+ * Two versions of a model compared by element: which concepts were added,
3
+ * removed or changed, and how — not a list of triples. What a review reads: a
4
+ * branch against main, a Git commit against the one before it, a checkpoint
5
+ * against the model now (the History tab), and — from the same code — what CI
6
+ * posts on a merge request.
7
+ *
8
+ * Both versions are snapshots ({@link snapshotOf}). Every line added or removed
9
+ * is put under the concept it is about:
10
+ *
11
+ * - a concept's own lines (its subject's), under it;
12
+ * - a relationship's unqualified triple — the one its `rdf:reifies` names — and
13
+ * the qualified predicate leading to it from its source, under the
14
+ * relationship: they change with its ends, which already say so;
15
+ * - a diagram's shapes — its nodes and links, with their route cells, points
16
+ * and label nodes — under the view they are drawn in, as shapes placed,
17
+ * removed, moved, resized, rerouted or reconnected;
18
+ * - `X arch:inView V`, under the view, as what it shows — only where no shape
19
+ * placed or removed already says so.
20
+ *
21
+ * A property that takes one value (or one per language: `single-valued.ts`, as
22
+ * the merge and the room read them) is shown as its old value and its new; a
23
+ * changed type too. Any other property as values added and removed — but not a
24
+ * relationship's `rdf:reifies`, which changes with its ends.
25
+ *
26
+ * The provenance of edits is not a change of its own (Req 9.16): a concept's
27
+ * `dcterms:created` and `dcterms:modified`, every PROV statement, and the
28
+ * activities, users and tools PROV types change with every edit, and say only
29
+ * when and by whom. They are left out here — the changes by element are what
30
+ * changed — and stay in the triples added and removed (`lines`). What they say
31
+ * is given with the change instead ({@link ConceptChange.edit}): who made it,
32
+ * when, with what — where the later version records an edit the earlier does
33
+ * not, so a change made where nothing records it names nobody.
34
+ */
35
+
36
+ import { SingleValued } from '../rdf-engine/single-valued.js';
37
+ import { diffSnapshots, type SnapshotDiff } from './version-history.js';
38
+ import { BOUNDS_PREDICATES, IRI, localName } from './vocabulary.js';
39
+ import { iriOf, literalValue, parseLine, predicateOf, subjectOf, type Line } from './snapshot-lines.js';
40
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
41
+
42
+ const PROV_TERM = `<${NAMESPACES.prov}`;
43
+ const STAMPS = new Set([IRI.dctermsCreated, IRI.dctermsModified]);
44
+ const PROV = {
45
+ generatedBy: NAMESPACES.prov + 'wasGeneratedBy',
46
+ at: NAMESPACES.prov + 'generatedAtTime',
47
+ associated: NAMESPACES.prov + 'wasAssociatedWith',
48
+ person: NAMESPACES.prov + 'Person',
49
+ software: NAMESPACES.prov + 'SoftwareAgent',
50
+ };
51
+ const SCHEMA = {
52
+ name: new Set([NAMESPACES.schema + 'name']),
53
+ alternateName: new Set([NAMESPACES.schema + 'alternateName']),
54
+ email: new Set([NAMESPACES.schema + 'email']),
55
+ sameAs: new Set([NAMESPACES.schema + 'sameAs']),
56
+ softwareVersion: new Set([NAMESPACES.schema + 'softwareVersion']),
57
+ };
58
+
59
+ /** What records an edit rather than makes one: a date stamp, a PROV statement, a resource PROV types. */
60
+ function provenanceFilter(...versions: ReadonlyArray<readonly string[]>): (line: string) => boolean {
61
+ const recorded = new Set<string>();
62
+ for (const lines of versions) {
63
+ for (const line of lines) {
64
+ if (predicateOf(line) === IRI.rdfType && line.includes(PROV_TERM, line.indexOf('> <') + 3)) {
65
+ const o = parseLine(line).o;
66
+ if (o.startsWith(PROV_TERM)) recorded.add(subjectOf(line));
67
+ }
68
+ }
69
+ }
70
+ return (line) => {
71
+ const p = predicateOf(line);
72
+ return STAMPS.has(p) || p.startsWith(NAMESPACES.prov) || recorded.has(subjectOf(line));
73
+ };
74
+ }
75
+
76
+ /** What a concept is, as the diff groups it. */
77
+ export type ConceptKind = 'model' | 'element' | 'relationship' | 'view' | 'folder' | 'other';
78
+
79
+ /** Whether a concept, or a shape, is new, gone or changed. */
80
+ export type ChangeStatus = 'added' | 'removed' | 'changed';
81
+
82
+ /**
83
+ * A property that takes one value (or one per language): what it was and what
84
+ * it is now, as N-Triples terms — empty where there was none, or is none.
85
+ */
86
+ export interface ValueChange {
87
+ predicate: string;
88
+ /** A property that takes one value per language: which (`''` for none). */
89
+ language?: string;
90
+ from: string[];
91
+ to: string[];
92
+ }
93
+
94
+ /** A value of a property that takes several, added or removed. */
95
+ export interface PropertyValue {
96
+ predicate: string;
97
+ /** As an N-Triples term. */
98
+ object: string;
99
+ }
100
+
101
+ /** A node's position and size. */
102
+ export interface Bounds {
103
+ x: number;
104
+ y: number;
105
+ w: number;
106
+ h: number;
107
+ }
108
+
109
+ /** A node or a link in a view, placed, removed or changed. */
110
+ export interface ShapeChange {
111
+ /** The node or link (an IRI, or `_:label`). */
112
+ shape: string;
113
+ kind: 'node' | 'link';
114
+ /** What it shows: the element or the relationship. */
115
+ shows?: string;
116
+ status: ChangeStatus;
117
+ /** A changed one: what changed. */
118
+ moved?: boolean;
119
+ resized?: boolean;
120
+ rerouted?: boolean;
121
+ reconnected?: boolean;
122
+ /** Anything else about it: its style, its label's place. */
123
+ restyled?: boolean;
124
+ bounds?: { from?: Bounds; to?: Bounds };
125
+ }
126
+
127
+ /** Who made a concept's change, when and with what, as the later version records its last edit (Req 9.16). */
128
+ export interface EditRecord {
129
+ /** When: its `prov:generatedAtTime`, ISO 8601. */
130
+ at?: string;
131
+ /** Who: the user's name, else their username, else their address. */
132
+ by?: string;
133
+ /** Their Git account's page. */
134
+ account?: string;
135
+ /** With what: the tool's name and version. */
136
+ tool?: string;
137
+ }
138
+
139
+ /** One concept's changes. */
140
+ export interface ConceptChange {
141
+ /** The concept (an IRI, or `_:label`). */
142
+ subject: string;
143
+ kind: ConceptKind;
144
+ status: ChangeStatus;
145
+ /** Single values, old → new; for a concept added, each with nothing before. */
146
+ values: ValueChange[];
147
+ /** Values added, of properties that take several (its types and `arch:inModel` left out for a concept added or removed). */
148
+ added: PropertyValue[];
149
+ removed: PropertyValue[];
150
+ /** A relationship's ends, in the version it is in (the later, in both). */
151
+ ends?: { source?: string; target?: string };
152
+ /** A view's shapes. */
153
+ shapes: ShapeChange[];
154
+ /** What a view shows, by `arch:inView`, that no shape placed or removed accounts for. */
155
+ shows: { added: string[]; removed: string[] };
156
+ /** Who made the change, when, with what — where the later version records an edit of it the earlier does not. */
157
+ edit?: EditRecord;
158
+ /** Every line put under it. */
159
+ lines: SnapshotDiff;
160
+ }
161
+
162
+ /** What is known of a concept or value named in the diff, from the versions compared. */
163
+ export interface Described {
164
+ /** Its name, in the later version that has one. */
165
+ name?: string;
166
+ /** Its types, in the later version that has it. */
167
+ types: string[];
168
+ }
169
+
170
+ /** Two versions compared by element. */
171
+ export interface ModelDiff {
172
+ /** By kind (model, elements, relationships, views, folders, the rest), then name. */
173
+ changes: ConceptChange[];
174
+ /** How many concepts were added, removed and changed. */
175
+ counts: Record<ChangeStatus, number>;
176
+ /** Every concept, shape and value IRI the changes name: its name and types. */
177
+ about: Record<string, Described>;
178
+ /** Every line added and removed. */
179
+ lines: SnapshotDiff;
180
+ }
181
+
182
+ /** Options for {@link diffByElement}. */
183
+ export interface DiffOptions {
184
+ /** Which properties take one value; the built-in rules when absent. */
185
+ singleValued?: SingleValued;
186
+ /** The language a name is preferred in (`en` when absent). */
187
+ language?: string;
188
+ }
189
+
190
+ const KIND_ORDER: readonly ConceptKind[] = ['model', 'element', 'relationship', 'view', 'folder', 'other'];
191
+ const STATUS_ORDER: readonly ChangeStatus[] = ['added', 'changed', 'removed'];
192
+ /** Where a name is read from, in this order. */
193
+ const NAME_PREDICATES = [IRI.prefLabel, 'https://schema.org/name', 'http://schema.org/name', IRI.rdfsLabel, IRI.dctermsTitle];
194
+ /** What a subject names with one of these is part of it: a link's route cells and label, a cell's point and next cell. */
195
+ const OWNS = new Set<string>([IRI.points, IRI.rdfFirst, IRI.rdfRest, IRI.visLabel]);
196
+ const SOURCES = new Set<string>([IRI.source, IRI.legacyRelSource]);
197
+ const RELATIONSHIP_MARKS = new Set<string>([IRI.source, IRI.target, IRI.reifies, IRI.legacyRelSource, IRI.legacyRelTarget]);
198
+ const VIEW_TYPES = new Set<string>([IRI.View, IRI.Diagram, IRI.Catalog, IRI.Matrix]);
199
+ const SHAPE_TYPES = new Set<string>([IRI.ArchNode, IRI.Link, IRI.Point, IRI.LabelNode, IRI.ViewReferenceNode]);
200
+ const BOUNDS = new Set<string>(BOUNDS_PREDICATES);
201
+ const LINK_ENDS = new Set<string>([IRI.visSource, IRI.visTarget]);
202
+ const SHOWS = new Set<string>([IRI.archElement, IRI.archRelationship]);
203
+ /** Left out of a concept added or removed: its types are given apart, its membership of the model goes without saying. */
204
+ const WHOLE_LEFT_OUT = new Set<string>([IRI.rdfType, IRI.inModel]);
205
+ /** Left out always: the triple a relationship reifies changes with its ends, which say so. */
206
+ const LEFT_OUT = new Set<string>([IRI.reifies]);
207
+
208
+ /** Compare `from` with `to`, both snapshots, by element. */
209
+ export function diffByElement(from: readonly string[], to: readonly string[], options: DiffOptions = {}): ModelDiff {
210
+ const lines = diffSnapshots(from, to);
211
+ const counts: Record<ChangeStatus, number> = { added: 0, removed: 0, changed: 0 };
212
+ if (lines.added.length + lines.removed.length === 0) return { changes: [], counts, about: {}, lines };
213
+ const rules = options.singleValued ?? SingleValued.builtIn();
214
+ const before = new Version(from);
215
+ const after = new Version(to);
216
+ const versions: Record<'added' | 'removed', Version> = { added: after, removed: before };
217
+ const recordsAnEdit = provenanceFilter(from, to);
218
+ // A concept whose record of its last edit is new: it was edited where an edit is recorded.
219
+ const recorded = new Set(lines.added.filter((l) => predicateOf(l) === PROV.generatedBy).map(subjectOf));
220
+
221
+ // ── Each line under its concept ──
222
+ const groups = new Map<string, Group>();
223
+ const group = (term: string): Group => {
224
+ let g = groups.get(term);
225
+ if (!g) {
226
+ g = { own: { added: [], removed: [] }, lines: { added: [], removed: [] }, shapes: new Map(), shows: { added: new Set(), removed: new Set() } };
227
+ groups.set(term, g);
228
+ }
229
+ return g;
230
+ };
231
+ for (const side of ['added', 'removed'] as const) {
232
+ const version = versions[side];
233
+ for (const line of lines[side]) {
234
+ if (recordsAnEdit(line)) continue;
235
+ const parsed = parseLine(line);
236
+ let owner: string;
237
+ if (parsed.p === IRI.inView && parsed.refs.length === 1) {
238
+ owner = parsed.o;
239
+ group(owner).shows[side].add(parsed.s);
240
+ } else if (version.reifier.has(line)) {
241
+ owner = version.reifier.get(line)!;
242
+ } else if (parsed.refs.length === 1 && version.sourceOf.get(parsed.o) === parsed.s && isQualifiedPointer(parsed.p)) {
243
+ owner = parsed.o;
244
+ } else {
245
+ const shape = version.shapeOf(parsed.s);
246
+ if (shape !== undefined) {
247
+ owner = version.viewOf.get(shape)!;
248
+ const shapes = group(owner).shapes;
249
+ const changed = shapes.get(shape) ?? { added: [], removed: [] };
250
+ changed[side].push(parsed);
251
+ shapes.set(shape, changed);
252
+ } else {
253
+ owner = parsed.s;
254
+ group(owner).own[side].push(parsed);
255
+ }
256
+ }
257
+ group(owner).lines[side].push(line);
258
+ }
259
+ }
260
+
261
+ // ── Each concept's change ──
262
+ const named = new Set<string>();
263
+ const changes: ConceptChange[] = [];
264
+ for (const [term, g] of groups) {
265
+ const status: ChangeStatus = before.has(term) ? (after.has(term) ? 'changed' : 'removed') : after.has(term) ? 'added' : 'changed';
266
+ const version = status === 'removed' ? before : after;
267
+ const types = version.types(term).length > 0 ? version.types(term) : before.types(term);
268
+ const change: ConceptChange = {
269
+ subject: iriOf(term),
270
+ kind: kindOf(term, types, before, after),
271
+ status,
272
+ values: [],
273
+ added: [],
274
+ removed: [],
275
+ shapes: [],
276
+ shows: { added: [], removed: [] },
277
+ lines: g.lines,
278
+ };
279
+ const edit = status !== 'removed' && recorded.has(term) ? after.edit(term) : undefined;
280
+ if (edit) change.edit = edit;
281
+ named.add(term);
282
+
283
+ // Its own lines: single values paired, the rest as values added and removed.
284
+ const whole = status !== 'changed';
285
+ const values = new Map<string, ValueChange>();
286
+ const retyped = !whole && g.own.added.some((l) => l.p === IRI.rdfType) && g.own.removed.some((l) => l.p === IRI.rdfType);
287
+ for (const side of ['removed', 'added'] as const) {
288
+ for (const line of g.own[side]) {
289
+ if (LEFT_OUT.has(line.p) || (whole && WHOLE_LEFT_OUT.has(line.p))) continue;
290
+ const limit = line.p === IRI.rdfType ? (retyped ? 'one' : undefined) : rules.mayLimit(line.p) ? rules.limitOf(line.p, () => types) : undefined;
291
+ for (const ref of line.refs) named.add(ref);
292
+ if (limit === undefined) {
293
+ change[side].push({ predicate: line.p, object: line.o });
294
+ continue;
295
+ }
296
+ const perLanguage = limit === 'one-per-language';
297
+ const key = perLanguage ? `${line.p}@${line.lang}` : line.p;
298
+ let value = values.get(key);
299
+ if (!value) {
300
+ value = { predicate: line.p, ...(perLanguage ? { language: line.lang } : {}), from: [], to: [] };
301
+ values.set(key, value);
302
+ }
303
+ (side === 'removed' ? value.from : value.to).push(line.o);
304
+ }
305
+ }
306
+ change.values = [...values.values()].sort(byPredicate);
307
+ change.added.sort(byPredicate);
308
+ change.removed.sort(byPredicate);
309
+
310
+ if (change.kind === 'relationship') {
311
+ const source = version.objectOf(term, SOURCES) ?? before.objectOf(term, SOURCES);
312
+ const target = version.objectOf(term, new Set([IRI.target, IRI.legacyRelTarget])) ?? before.objectOf(term, new Set([IRI.target, IRI.legacyRelTarget]));
313
+ change.ends = { ...(source ? { source: iriOf(source) } : {}), ...(target ? { target: iriOf(target) } : {}) };
314
+ if (source) named.add(source);
315
+ if (target) named.add(target);
316
+ }
317
+
318
+ // A view's shapes, and what it shows that they do not account for.
319
+ for (const [shape, changed] of g.shapes) change.shapes.push(shapeChange(shape, changed, before, after));
320
+ change.shapes.sort((a, b) => STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status) || compare(a.shape, b.shape));
321
+ for (const s of change.shapes) if (s.shows) named.add(`<${s.shows}>`);
322
+ for (const side of ['added', 'removed'] as const) {
323
+ const placed = new Set(change.shapes.filter((s) => s.status === side && s.shows).map((s) => `<${s.shows}>`));
324
+ change.shows[side] = [...g.shows[side]].filter((c) => !placed.has(c)).sort().map(iriOf);
325
+ for (const c of g.shows[side]) named.add(c);
326
+ }
327
+ counts[status]++;
328
+ changes.push(change);
329
+ }
330
+
331
+ // ── What the changes name ──
332
+ const about: Record<string, Described> = {};
333
+ const language = (options.language ?? 'en').toLowerCase();
334
+ for (const term of named) {
335
+ if (!term.startsWith('<') && !term.startsWith('_:')) continue;
336
+ const name = after.name(term, language) ?? before.name(term, language);
337
+ const types = after.types(term).length > 0 ? after.types(term) : before.types(term);
338
+ about[iriOf(term)] = { ...(name !== undefined ? { name } : {}), types };
339
+ }
340
+ const nameOf = (c: ConceptChange) => about[c.subject]?.name ?? '';
341
+ changes.sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || compare(nameOf(a).toLowerCase(), nameOf(b).toLowerCase()) || compare(a.subject, b.subject));
342
+ return { changes, counts, about, lines };
343
+ }
344
+
345
+ /** Lines under one concept, as they come. */
346
+ interface Group {
347
+ own: Record<'added' | 'removed', Line[]>;
348
+ lines: SnapshotDiff;
349
+ shapes: Map<string, Record<'added' | 'removed', Line[]>>;
350
+ shows: Record<'added' | 'removed', Set<string>>;
351
+ }
352
+
353
+ /** One version: its lines by subject, and the structure the diff needs to put a line under its concept. */
354
+ class Version {
355
+ private bySubject?: Map<string, string[]>;
356
+ /** A route cell, point or label node → what it is part of. */
357
+ private readonly ownerOf = new Map<string, string>();
358
+ /** A shape → its view. */
359
+ readonly viewOf = new Map<string, string>();
360
+ /** A reified triple's line → the relationship reifying it. */
361
+ readonly reifier = new Map<string, string>();
362
+ /** A relationship → its source. */
363
+ readonly sourceOf = new Map<string, string>();
364
+ readonly relationships = new Set<string>();
365
+
366
+ constructor(private readonly lines: readonly string[]) {
367
+ for (const line of lines) {
368
+ const p = predicateOf(line);
369
+ if (OWNS.has(p)) {
370
+ const { s, refs } = parseLine(line);
371
+ for (const ref of refs) if (!this.ownerOf.has(ref)) this.ownerOf.set(ref, s);
372
+ } else if (p === IRI.visView) {
373
+ const { s, o } = parseLine(line);
374
+ this.viewOf.set(s, o);
375
+ } else if (RELATIONSHIP_MARKS.has(p)) {
376
+ const { s, o, refs } = parseLine(line);
377
+ this.relationships.add(s);
378
+ if (SOURCES.has(p)) this.sourceOf.set(s, o);
379
+ if (p === IRI.reifies && refs.length === 3) this.reifier.set(`${refs[0]} ${refs[1]} ${refs[2]} .`, s);
380
+ }
381
+ }
382
+ }
383
+
384
+ has(subject: string): boolean {
385
+ return this.index().has(subject);
386
+ }
387
+
388
+ of(subject: string): readonly string[] {
389
+ return this.index().get(subject) ?? [];
390
+ }
391
+
392
+ /** The shape a subject is, or is part of; `undefined` for anything else. */
393
+ shapeOf(subject: string): string | undefined {
394
+ const seen = new Set<string>();
395
+ for (let at: string | undefined = subject; at !== undefined && !seen.has(at); at = this.ownerOf.get(at)) {
396
+ if (this.viewOf.has(at)) return at;
397
+ seen.add(at);
398
+ }
399
+ return undefined;
400
+ }
401
+
402
+ /** Its types' IRIs. */
403
+ types(subject: string): string[] {
404
+ return this.of(subject)
405
+ .filter((l) => predicateOf(l) === IRI.rdfType)
406
+ .map((l) => iriOf(parseLine(l).o));
407
+ }
408
+
409
+ /** The object of its first line with one of `predicates`. */
410
+ objectOf(subject: string, predicates: ReadonlySet<string>): string | undefined {
411
+ const line = this.of(subject).find((l) => predicates.has(predicateOf(l)));
412
+ return line === undefined ? undefined : parseLine(line).o;
413
+ }
414
+
415
+ /** Its last edit, as recorded: the activity that generated it, the user and the tool that activity is associated with. */
416
+ edit(subject: string): EditRecord | undefined {
417
+ const activity = this.objectOf(subject, new Set([PROV.generatedBy]));
418
+ if (!activity?.startsWith('<')) return undefined;
419
+ const text = (term: string, predicates: ReadonlySet<string>) => {
420
+ const o = this.objectOf(term, predicates);
421
+ return o === undefined ? undefined : o.startsWith('<') ? iriOf(o) : literalValue(o);
422
+ };
423
+ const record: EditRecord = {};
424
+ const at = text(subject, new Set([PROV.at]));
425
+ if (at) record.at = at;
426
+ for (const line of this.of(activity)) {
427
+ if (predicateOf(line) !== PROV.associated) continue;
428
+ const agent = parseLine(line).o;
429
+ const types = this.types(agent);
430
+ if (types.includes(PROV.software)) {
431
+ record.tool = [text(agent, SCHEMA.name) ?? iriOf(agent), text(agent, SCHEMA.softwareVersion)].filter(Boolean).join(' ');
432
+ } else if (types.includes(PROV.person)) {
433
+ const by = text(agent, SCHEMA.name) ?? text(agent, SCHEMA.alternateName) ?? text(agent, SCHEMA.email);
434
+ const account = text(agent, SCHEMA.sameAs);
435
+ if (by) record.by = by;
436
+ if (account) record.account = account;
437
+ }
438
+ }
439
+ return Object.keys(record).length > 0 ? record : undefined;
440
+ }
441
+
442
+ /** Its name: the first property of {@link NAME_PREDICATES} it has, in `language`, else without one, else the first. */
443
+ name(subject: string, language: string): string | undefined {
444
+ const own = this.of(subject);
445
+ for (const predicate of NAME_PREDICATES) {
446
+ const names = own.map(parseLine).filter((l) => l.p === predicate && l.o.startsWith('"'));
447
+ if (names.length === 0) continue;
448
+ const pick = names.find((l) => l.lang === language) ?? names.find((l) => l.lang === '') ?? names[0]!;
449
+ return literalValue(pick.o);
450
+ }
451
+ return undefined;
452
+ }
453
+
454
+ private index(): Map<string, string[]> {
455
+ if (!this.bySubject) {
456
+ this.bySubject = new Map();
457
+ for (const line of this.lines) {
458
+ const s = subjectOf(line);
459
+ const list = this.bySubject.get(s);
460
+ if (list) list.push(line);
461
+ else this.bySubject.set(s, [line]);
462
+ }
463
+ }
464
+ return this.bySubject;
465
+ }
466
+ }
467
+
468
+ function kindOf(term: string, types: readonly string[], before: Version, after: Version): ConceptKind {
469
+ if (types.includes(IRI.Model)) return 'model';
470
+ if (types.includes(IRI.Folder)) return 'folder';
471
+ if (types.some((t) => VIEW_TYPES.has(t))) return 'view';
472
+ if (before.relationships.has(term) || after.relationships.has(term)) return 'relationship';
473
+ if (types.length > 0 && !types.some((t) => SHAPE_TYPES.has(t))) return 'element';
474
+ return 'other';
475
+ }
476
+
477
+ /** A shape's change, from its lines added and removed. */
478
+ function shapeChange(shape: string, changed: Record<'added' | 'removed', Line[]>, before: Version, after: Version): ShapeChange {
479
+ const status: ChangeStatus = before.has(shape) ? (after.has(shape) ? 'changed' : 'removed') : 'added';
480
+ const version = status === 'removed' ? before : after;
481
+ const own = version.of(shape).map(parseLine);
482
+ const shows = own.find((l) => SHOWS.has(l.p))?.o;
483
+ const link = own.some((l) => l.p === IRI.archRelationship || (l.p === IRI.rdfType && iriOf(l.o) === IRI.Link));
484
+ const result: ShapeChange = {
485
+ shape: iriOf(shape),
486
+ kind: link ? 'link' : 'node',
487
+ ...(shows ? { shows: iriOf(shows) } : {}),
488
+ status,
489
+ };
490
+ if (status !== 'changed') return result;
491
+ for (const line of [...changed.added, ...changed.removed]) {
492
+ if (line.s !== shape) {
493
+ if (link) result.rerouted = true;
494
+ else result.restyled = true;
495
+ } else if (BOUNDS.has(line.p)) {
496
+ // Said below, from the bounds before and after.
497
+ } else if (line.p === IRI.points) result.rerouted = true;
498
+ else if (LINK_ENDS.has(line.p)) result.reconnected = true;
499
+ else result.restyled = true;
500
+ }
501
+ const from = boundsOf(before, shape);
502
+ const to = boundsOf(after, shape);
503
+ if (from || to) {
504
+ if (from?.x !== to?.x || from?.y !== to?.y) result.moved = true;
505
+ if (from?.w !== to?.w || from?.h !== to?.h) result.resized = true;
506
+ if (result.moved || result.resized) result.bounds = { ...(from ? { from } : {}), ...(to ? { to } : {}) };
507
+ }
508
+ return result;
509
+ }
510
+
511
+ function boundsOf(version: Version, shape: string): Bounds | undefined {
512
+ const values: Record<string, number> = {};
513
+ for (const line of version.of(shape)) {
514
+ const p = predicateOf(line);
515
+ if (BOUNDS.has(p)) values[p] = Number(literalValue(parseLine(line).o));
516
+ }
517
+ const [x, y, w, h] = BOUNDS_PREDICATES.map((p) => values[p]);
518
+ return x === undefined && y === undefined && w === undefined && h === undefined
519
+ ? undefined
520
+ : { x: x ?? 0, y: y ?? 0, w: w ?? 0, h: h ?? 0 };
521
+ }
522
+
523
+ /** Whether a predicate leads from a relationship's source to it: a notation's `qualified…`, or core's fallback. */
524
+ function isQualifiedPointer(predicate: string): boolean {
525
+ return predicate === IRI.hasQualifiedRelationship || localName(predicate).startsWith('qualified');
526
+ }
527
+
528
+ function byPredicate(a: { predicate: string; language?: string }, b: { predicate: string; language?: string }): number {
529
+ return compare(a.predicate, b.predicate) || compare(a.language ?? '', b.language ?? '');
530
+ }
531
+
532
+ function compare(a: string, b: string): number {
533
+ return a < b ? -1 : a > b ? 1 : 0;
534
+ }