@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,203 @@
1
+ /**
2
+ * The orders a language proposes its relationships in, when two elements are
3
+ * connected: the ordered collections of relationship classes its metamodel
4
+ * names with `arch:relationshipProposalOrder` (core; the rule is that
5
+ * property's definition).
6
+ *
7
+ * ```turtle
8
+ * am4mm:ArchiMate4 arch:relationshipProposalOrder am4tax:ProposalOrder , am4tax:BehaviorProposalOrder .
9
+ *
10
+ * am4tax:ProposalOrder a skos:OrderedCollection ;
11
+ * skos:memberList ( am4:Composition am4:Aggregation … am4:Association ) .
12
+ *
13
+ * am4tax:BehaviorProposalOrder a skos:OrderedCollection ;
14
+ * arch:domainIncludes am4:BehaviorElement ;
15
+ * arch:rangeIncludes am4:BehaviorElement ;
16
+ * skos:memberList ( am4:Triggering am4:Flow am4:Composition … ) .
17
+ * ```
18
+ *
19
+ * An order with no `arch:domainIncludes` or `arch:rangeIncludes` is the
20
+ * general order, which applies to every pair. One with either applies where
21
+ * the source, the target, or both are of a class it names or of a subclass.
22
+ * A relationship takes the place the most specific order that lists it gives
23
+ * it: one naming both ends before one naming one, before the general order;
24
+ * between two naming the same ends, the one whose classes are subclasses of the
25
+ * other's — measured here by the size of each matched class's `rdfs:subClassOf*`
26
+ * closure, which agrees with "subclass of" wherever one order's classes are
27
+ * subclasses of the other's. Where an order lists a relationship's superclass
28
+ * rather than the class itself — a read access under Access — the
29
+ * superclass's place is the class's.
30
+ *
31
+ * The pointer is read from the metamodel's own document — a quad in a named
32
+ * graph — never from the model's default graph, so a model file cannot add an
33
+ * order; the collections themselves are in the language's taxonomy.
34
+ */
35
+
36
+ import type { NamedNode, Term } from '@rdfjs/types';
37
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
38
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
39
+ import { nn } from './vocabulary.js';
40
+
41
+ const RDF_FIRST = nn(NAMESPACES.rdf + 'first');
42
+ const RDF_REST = nn(NAMESPACES.rdf + 'rest');
43
+ const RDF_NIL = NAMESPACES.rdf + 'nil';
44
+ const SUBCLASS_OF = nn(NAMESPACES.rdfs + 'subClassOf');
45
+ /** `arch:relationshipProposalOrder`: from a metamodel to an order it publishes. */
46
+ export const RELATIONSHIP_PROPOSAL_ORDER = NAMESPACES.arch + 'relationshipProposalOrder';
47
+ const MEMBER_LIST = nn(NAMESPACES.skos + 'memberList');
48
+ const DOMAIN_INCLUDES = nn(NAMESPACES.arch + 'domainIncludes');
49
+ const RANGE_INCLUDES = nn(NAMESPACES.arch + 'rangeIncludes');
50
+
51
+ /** One proposal order: its relationship classes in order, and the elements it applies to. */
52
+ interface Order {
53
+ members: string[];
54
+ /** `arch:domainIncludes`, each with the size of its `rdfs:subClassOf*` closure: empty for the general order. */
55
+ sources: ReadonlyMap<string, number>;
56
+ /** `arch:rangeIncludes`, likewise. */
57
+ targets: ReadonlyMap<string, number>;
58
+ }
59
+
60
+ /**
61
+ * Where a relationship stands in a language's proposal orders, for one pair:
62
+ * how specifically the order that places it applies — `ends`, how many of the
63
+ * two elements it names (0 for the general order), then `depth`, the closure
64
+ * sizes of the classes it matches them by — and `position`, its place in that
65
+ * order, first 0. A greater `ends`, then a greater `depth`, then a smaller
66
+ * `position` ranks first (`compareProposals`).
67
+ */
68
+ export interface Proposal {
69
+ ends: number;
70
+ depth: number;
71
+ position: number;
72
+ }
73
+
74
+ /** No order lists the relationship. */
75
+ export const NO_PROPOSAL: Proposal = { ends: -1, depth: 0, position: Number.POSITIVE_INFINITY };
76
+
77
+ /** Negative when `a` ranks before `b`. */
78
+ export function compareProposals(a: Proposal, b: Proposal): number {
79
+ return b.ends - a.ends || b.depth - a.depth || (a.position === b.position ? 0 : a.position < b.position ? -1 : 1);
80
+ }
81
+
82
+ /** Whether an order lists the relationship for the pair. */
83
+ export function isProposed(proposal: Proposal): boolean {
84
+ return proposal.ends >= 0;
85
+ }
86
+
87
+ /** The proposal orders of the loaded metamodels. */
88
+ export class ProposalOrders {
89
+ constructor(private readonly orders: readonly Order[]) {}
90
+
91
+ /** How many orders were read. */
92
+ get size(): number {
93
+ return this.orders.length;
94
+ }
95
+
96
+ /**
97
+ * The place the most specific order that lists a relationship class gives it
98
+ * between two elements, given the `rdfs:subClassOf*` closures of all three
99
+ * (each including itself).
100
+ */
101
+ proposal(
102
+ relationshipIri: string,
103
+ relationshipClosure: readonly string[],
104
+ sourceClosure: readonly string[],
105
+ targetClosure: readonly string[],
106
+ ): Proposal {
107
+ let best = NO_PROPOSAL;
108
+ for (const order of this.orders) {
109
+ const position = positionIn(order.members, relationshipIri, relationshipClosure);
110
+ if (position < 0) continue;
111
+ const fit = fitOf(order, sourceClosure, targetClosure);
112
+ if (!fit) continue;
113
+ const candidate = { ...fit, position };
114
+ if (compareProposals(candidate, best) < 0) best = candidate;
115
+ }
116
+ return best;
117
+ }
118
+ }
119
+
120
+ /** No proposal orders loaded. */
121
+ export const NO_PROPOSAL_ORDERS = new ProposalOrders([]);
122
+
123
+ /** The class's own place in the order, else the earliest place of a superclass it lists. */
124
+ function positionIn(members: readonly string[], relationshipIri: string, closure: readonly string[]): number {
125
+ const own = members.indexOf(relationshipIri);
126
+ if (own >= 0) return own;
127
+ const inherited = members.map((member, i) => (closure.includes(member) ? i : -1)).filter((i) => i >= 0);
128
+ return inherited.length > 0 ? Math.min(...inherited) : -1;
129
+ }
130
+
131
+ /**
132
+ * How specifically an order applies to a pair, or `undefined` when it does not:
133
+ * the ends it names, and the closure sizes of the most specific classes it names
134
+ * that each end is of.
135
+ */
136
+ function fitOf(order: Order, sourceClosure: readonly string[], targetClosure: readonly string[]): Omit<Proposal, 'position'> | undefined {
137
+ let ends = 0;
138
+ let depth = 0;
139
+ for (const [named, closure] of [[order.sources, sourceClosure], [order.targets, targetClosure]] as const) {
140
+ if (named.size === 0) continue;
141
+ let matched = -1;
142
+ for (const [iri, size] of named) if (closure.includes(iri) && size > matched) matched = size;
143
+ if (matched < 0) return undefined;
144
+ ends += 1;
145
+ depth += matched;
146
+ }
147
+ return { ends, depth };
148
+ }
149
+
150
+ /** The members of an RDF list, in order. Bounded, so a malformed list that loops cannot hang. */
151
+ function listMembers(store: RdfStore, head: Term): string[] {
152
+ const members: string[] = [];
153
+ let node: Term | undefined = head;
154
+ const seen = new Set<string>();
155
+ while (node && node.value !== RDF_NIL && !seen.has(node.value)) {
156
+ seen.add(node.value);
157
+ const first = store.getQuads(node as NamedNode, RDF_FIRST)[0]?.object;
158
+ if (first?.termType === 'NamedNode') members.push(first.value);
159
+ node = store.getQuads(node as NamedNode, RDF_REST)[0]?.object;
160
+ }
161
+ return members;
162
+ }
163
+
164
+ /** The size of a class's `rdfs:subClassOf*` closure, itself included, across every loaded graph. */
165
+ function closureSize(store: RdfStore, classIri: string): number {
166
+ const seen = new Set<string>([classIri]);
167
+ const queue = [classIri];
168
+ while (queue.length > 0) {
169
+ const next = queue.shift()!;
170
+ for (const quad of store.getQuads(nn(next), SUBCLASS_OF)) {
171
+ if (quad.object.termType === 'NamedNode' && !seen.has(quad.object.value)) {
172
+ seen.add(quad.object.value);
173
+ queue.push(quad.object.value);
174
+ }
175
+ }
176
+ }
177
+ return seen.size;
178
+ }
179
+
180
+ /** The orders the loaded metamodels name with `arch:relationshipProposalOrder`, in their own documents. */
181
+ export function readProposalOrders(store: RdfStore): ProposalOrders {
182
+ const seen = new Set<string>();
183
+ const orders: Order[] = [];
184
+ const named = (order: NamedNode, predicate: NamedNode) =>
185
+ new Map(
186
+ store
187
+ .getQuads(order, predicate)
188
+ .map((q) => q.object)
189
+ .filter((o) => o.termType === 'NamedNode')
190
+ .map((o) => [o.value, closureSize(store, o.value)] as const),
191
+ );
192
+ for (const pointer of store.getQuads(null, nn(RELATIONSHIP_PROPOSAL_ORDER))) {
193
+ // A metamodel's document is a named graph; the model is the default graph.
194
+ if (pointer.graph.termType === 'DefaultGraph' || pointer.object.termType !== 'NamedNode') continue;
195
+ const order = pointer.object;
196
+ if (seen.has(order.value)) continue;
197
+ seen.add(order.value);
198
+ const head = store.getQuads(order, MEMBER_LIST)[0]?.object;
199
+ if (!head) continue;
200
+ orders.push({ members: listMembers(store, head), sources: named(order, DOMAIN_INCLUDES), targets: named(order, RANGE_INCLUDES) });
201
+ }
202
+ return new ProposalOrders(orders);
203
+ }
@@ -0,0 +1,396 @@
1
+ /**
2
+ * The provenance of edits (meta's DD-27, *What a modeller records of its edits*; Req 9.16): who changed a
3
+ * concept, when, and with which application. Stamps are written inside the edit, so undo takes them back
4
+ * with the change.
5
+ *
6
+ * - **On the concept** (the model, an element, a relationship, a view): `dcterms:created` when it is made,
7
+ * `dcterms:modified` at every change to it. A change to a shape, a style, a route or a name is a change to
8
+ * the view or the element it is part of; every change is one to the model too. A value set by hand in the
9
+ * same edit stays.
10
+ * - **In the provenance graph** (`{ns}graph/provenance` when saved): the concept's `prov:wasGeneratedBy`, the
11
+ * editing activity that last changed it, and `prov:generatedAtTime`; the activity — one user's edits in
12
+ * one la-gram, from the first change after the model is opened or saved to the next save — with its start
13
+ * and end, `prov:wasAssociatedWith` la-gram at its version and the user; la-gram, a
14
+ * `prov:SoftwareAgent`; the user, a `prov:Person` with their name, email address and Git account
15
+ * (`schema:sameAs` its page, `schema:alternateName` its username) as far as la-gram knows them.
16
+ *
17
+ * Minimal on purpose: four statements a concept, five an activity, la-gram and each user once. An activity
18
+ * no concept names any more is removed in the edit that leaves it unnamed, and so is a user or a la-gram
19
+ * version no activity names. What exactly changed in a concept is what checkpoints and Git compare.
20
+ *
21
+ * The activities and the users are named in the model's namespace, `{ns}provenance/edit-{id}` and
22
+ * `{ns}provenance/user-{id}` (meta's *IRI Minting*, *Provenance of edits*): the word is for a person reading
23
+ * the Turtle, the id is opaque — an activity's a random UUID, a user's the digest of their Git account's page,
24
+ * else of their email address, else of their name, so that the IRI carries nothing personal and one user is
25
+ * one resource on every machine. la-gram at a version is an IRI of its own, the same in every model:
26
+ * {@link modellerIri}, the page of that version.
27
+ *
28
+ * What is not an edit is not stamped: opening, importing, merging, restoring a version, moving the model to
29
+ * another namespace, undo and redo, a collaborator's changes (`ObservableRdfStore.withoutStamps`, origins).
30
+ */
31
+
32
+ import { DataFactory, Store as N3Store } from 'n3';
33
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
34
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
35
+ import type { RdfDiff } from '../rdf-engine/observable-store.js';
36
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
37
+ import { dateTimeLiteral, IRI } from './vocabulary.js';
38
+ import { keyDigest } from './short-hash.js';
39
+ import { uuid } from '../rdf-engine/iri.js';
40
+
41
+ const PROV = NAMESPACES.prov;
42
+ const SCHEMA = NAMESPACES.schema;
43
+ const { namedNode, literal, quad, defaultGraph } = DataFactory;
44
+ const MODEL = defaultGraph() as unknown as NamedNode;
45
+ const nn = (iri: string) => namedNode(iri) as unknown as NamedNode;
46
+
47
+ /** la-gram's home: the web app, its documentation, and a page for each version. */
48
+ export const LA_GRAM_HOME = 'https://app.linked.archi/la-gram/';
49
+
50
+ /** la-gram at `version`, as the agent of its edits: that version's page; a development build's own. */
51
+ export function modellerIri(version: string): string {
52
+ return version ? `${LA_GRAM_HOME}v${version}` : `${LA_GRAM_HOME}development`;
53
+ }
54
+
55
+ export const PROVENANCE_TERMS = {
56
+ activity: PROV + 'Activity',
57
+ person: PROV + 'Person',
58
+ softwareAgent: PROV + 'SoftwareAgent',
59
+ wasGeneratedBy: PROV + 'wasGeneratedBy',
60
+ generatedAtTime: PROV + 'generatedAtTime',
61
+ startedAtTime: PROV + 'startedAtTime',
62
+ endedAtTime: PROV + 'endedAtTime',
63
+ wasAssociatedWith: PROV + 'wasAssociatedWith',
64
+ softwareApplication: SCHEMA + 'SoftwareApplication',
65
+ name: SCHEMA + 'name',
66
+ email: SCHEMA + 'email',
67
+ sameAs: SCHEMA + 'sameAs',
68
+ alternateName: SCHEMA + 'alternateName',
69
+ softwareVersion: SCHEMA + 'softwareVersion',
70
+ } as const;
71
+ const P = PROVENANCE_TERMS;
72
+
73
+ /** What la-gram itself writes as it stamps: a change to these alone is no edit. */
74
+ const STAMPS = new Set([IRI.dctermsModified, IRI.dctermsCreated, P.wasGeneratedBy, P.generatedAtTime]);
75
+
76
+ /** Links from a resource to what it is part of in a folder, never to a part of its own. */
77
+ const NOT_PART_OF = new Set([
78
+ NAMESPACES.dcterms + 'isPartOf',
79
+ SCHEMA + 'item',
80
+ SCHEMA + 'itemListElement',
81
+ ]);
82
+
83
+ /** A Git account, as its host reports it (`GitHostProvider.currentAccount`). */
84
+ export interface GitAccount {
85
+ /** The account's page: `https://gitlab.com/ada`. */
86
+ url: string;
87
+ /** Its username: `ada`. */
88
+ username?: string;
89
+ /** The name it shows. */
90
+ name?: string;
91
+ /** The email address it shows, where it shows one. */
92
+ email?: string;
93
+ }
94
+
95
+ /** A Git account as la-gram shows it (*Settings › You*, *Model settings*): `ada · https://gitlab.com/ada`. */
96
+ export function accountText(account: GitAccount): string {
97
+ return [account.username, account.url].filter(Boolean).join(' · ');
98
+ }
99
+
100
+ /** Who is editing: the name, email address and Git account recorded with the edits, where known. */
101
+ export interface Editor {
102
+ name?: string;
103
+ email?: string;
104
+ /** Their account on the Git host the model is kept on: its page and username. */
105
+ account?: Pick<GitAccount, 'url' | 'username'>;
106
+ }
107
+
108
+ /** What names a user, most lasting first: their account's page, else their address, lower-cased, else their name. */
109
+ export function editorKey(editor: Editor | undefined): string | undefined {
110
+ return editor?.account?.url?.trim() || editor?.email?.trim().toLowerCase() || editor?.name?.trim() || undefined;
111
+ }
112
+
113
+ export interface EditProvenanceOptions {
114
+ /** Actual calling application (KReq 8.3). */
115
+ software: { iri: string; name: string; version?: string };
116
+ /** An application can retire its unreferenced agents for earlier versions under this IRI prefix. */
117
+ softwareIriPrefix?: string;
118
+ /** The open model's IRI. */
119
+ modelIri(): string | undefined;
120
+ /** The open model's namespace, which activities and users are named in. */
121
+ namespace(): string | undefined;
122
+ /** Who is editing now. When unknown, record the application agent. */
123
+ editor(): Editor | undefined;
124
+ /** The clock (tests). */
125
+ now?(): Date;
126
+ /** A random id (tests). */
127
+ uuid?(): string;
128
+ }
129
+
130
+ /** Whether a statement is provenance: a PROV property, or about a resource PROV types (an activity, an agent…). */
131
+ export function isProvenanceStatement(q: Quad, provenanceSubjects: ReadonlySet<string>): boolean {
132
+ return q.predicate.value.startsWith(PROV) || provenanceSubjects.has(q.subject.value);
133
+ }
134
+
135
+ /** The resources among `quads` that a PROV class types: activities, agents, entities, bundles, associations. */
136
+ export function provenanceSubjects(quads: Iterable<Quad>): Set<string> {
137
+ const subjects = new Set<string>();
138
+ for (const q of quads) {
139
+ if (q.predicate.value === IRI.rdfType && q.object.value.startsWith(PROV)) subjects.add(q.subject.value);
140
+ }
141
+ return subjects;
142
+ }
143
+
144
+ /** Records the provenance of local edits as they are made (see the module's comment). */
145
+ export class EditProvenance {
146
+ private activity: string | undefined;
147
+ private readonly now: () => Date;
148
+ private readonly uuid: () => string;
149
+
150
+ constructor(
151
+ private readonly store: RdfStore,
152
+ private readonly options: EditProvenanceOptions,
153
+ ) {
154
+ this.now = options.now ?? (() => new Date());
155
+ this.uuid = options.uuid ?? uuid;
156
+ }
157
+
158
+ /** The application's IRI as this build records it. */
159
+ get agent(): string {
160
+ return this.options.software.iri;
161
+ }
162
+
163
+ /** The editing activity edits go into now, if one has started. */
164
+ get currentActivity(): string | undefined {
165
+ return this.activity;
166
+ }
167
+
168
+ /** The activity ends: the model was saved, or another opened. The next edit starts another. */
169
+ endActivity(): void {
170
+ this.activity = undefined;
171
+ }
172
+
173
+ /** Stamp what `diff`, a local edit, changed. Called inside the edit, so the stamps are part of it. */
174
+ stamp(diff: RdfDiff): void {
175
+ const modelIri = this.options.modelIri();
176
+ const namespace = this.options.namespace();
177
+ if (!modelIri || !namespace) return;
178
+ const removed = new N3Store(diff.removed as never);
179
+ const concepts = new Set<string>();
180
+ const created = new Set<string>();
181
+ const setByHand = new Set<string>();
182
+ const formerActivities = new Set<string>();
183
+ const resolved = new Map<string, string | null>();
184
+
185
+ for (const q of diff.removed) if (q.predicate.value === P.wasGeneratedBy) formerActivities.add(q.object.value);
186
+ for (const q of [...diff.added, ...diff.removed]) {
187
+ if (q.graph.termType !== 'DefaultGraph') continue;
188
+ if (STAMPS.has(q.predicate.value)) continue;
189
+ if (this.isProvenanceNode(q.subject, removed)) continue;
190
+ const concept = this.ownerOf(q.subject, removed, resolved);
191
+ if (concept) concepts.add(concept);
192
+ }
193
+ for (const q of diff.added) {
194
+ if (q.predicate.value === IRI.dctermsModified) setByHand.add(q.subject.value);
195
+ if (q.predicate.value === IRI.inModel && q.object.value === modelIri) created.add(q.subject.value);
196
+ }
197
+ if (concepts.size === 0) return;
198
+ // Only what is in the model after the edit: a deleted concept took its stamps with it. The model changed
199
+ // whatever did.
200
+ const stamped = [...concepts].filter((c) => c === modelIri || this.has(nn(c), IRI.inModel));
201
+ if (!stamped.includes(modelIri) && this.has(nn(modelIri), IRI.rdfType)) stamped.push(modelIri);
202
+ if (stamped.length === 0) return;
203
+
204
+ const when = dateTimeLiteral(this.now()) as unknown as Term;
205
+ const activity = this.activityIn(namespace, when);
206
+ const add: Quad[] = [];
207
+ const remove: Quad[] = [];
208
+ const replace = (subject: string, predicate: string, object: Term) => {
209
+ remove.push(...this.get(nn(subject), predicate));
210
+ add.push(quad(nn(subject), nn(predicate), object as never) as unknown as Quad);
211
+ };
212
+
213
+ for (const concept of stamped) {
214
+ if (!setByHand.has(concept)) replace(concept, IRI.dctermsModified, when);
215
+ if (created.has(concept) && !this.has(nn(concept), IRI.dctermsCreated)) {
216
+ add.push(quad(nn(concept), nn(IRI.dctermsCreated), when as never) as unknown as Quad);
217
+ }
218
+ for (const q of this.get(nn(concept), P.wasGeneratedBy)) formerActivities.add(q.object.value);
219
+ replace(concept, P.wasGeneratedBy, nn(activity));
220
+ replace(concept, P.generatedAtTime, when);
221
+ }
222
+ replace(activity, P.endedAtTime, when);
223
+ this.write(remove, add);
224
+ formerActivities.delete(activity);
225
+ this.dropUnnamed(formerActivities, namespace);
226
+ }
227
+
228
+ /** The activity edits go into, started now — with la-gram and the user — when none is going. */
229
+ private activityIn(namespace: string, when: Term): string {
230
+ // The one going, while it is in this model: another model opened since starts another.
231
+ if (this.activity?.startsWith(`${namespace}provenance/`) && this.has(nn(this.activity), IRI.rdfType)) return this.activity;
232
+ const activity = `${namespace}provenance/edit-${this.uuid()}`;
233
+ const t = (s: string, p: string, o: Term) => quad(nn(s), nn(p), o as never) as unknown as Quad;
234
+ const remove: Quad[] = [];
235
+ const add: Quad[] = [
236
+ t(activity, IRI.rdfType, nn(P.activity)),
237
+ t(activity, P.startedAtTime, when),
238
+ t(activity, P.wasAssociatedWith, nn(this.agent)),
239
+ ];
240
+ if (!this.has(nn(this.agent), IRI.rdfType)) {
241
+ const { name, version } = this.options.software;
242
+ add.push(
243
+ t(this.agent, IRI.rdfType, nn(P.softwareAgent)),
244
+ t(this.agent, IRI.rdfType, nn(P.softwareApplication)),
245
+ t(this.agent, P.name, literal(name) as unknown as Term),
246
+ ...(version ? [t(this.agent, P.softwareVersion, literal(version) as unknown as Term)] : []),
247
+ );
248
+ }
249
+ const editor = this.options.editor();
250
+ const key = editorKey(editor);
251
+ if (key) {
252
+ const user = `${namespace}provenance/user-${keyDigest(key)}`;
253
+ const name = editor?.name?.trim();
254
+ const email = editor?.email?.trim();
255
+ const account = editor?.account;
256
+ add.push(t(activity, P.wasAssociatedWith, nn(user)), t(user, IRI.rdfType, nn(P.person)));
257
+ // What is known of the user now replaces what was: a name corrected, an address or an account added.
258
+ for (const p of [P.name, P.email, P.sameAs, P.alternateName]) remove.push(...this.get(nn(user), p));
259
+ if (name) add.push(t(user, P.name, literal(name) as unknown as Term));
260
+ if (email) add.push(t(user, P.email, literal(email) as unknown as Term));
261
+ if (account?.url) add.push(t(user, P.sameAs, nn(account.url)));
262
+ if (account?.username) add.push(t(user, P.alternateName, literal(account.username) as unknown as Term));
263
+ }
264
+ this.write(remove, add);
265
+ this.activity = activity;
266
+ return activity;
267
+ }
268
+
269
+ /**
270
+ * Remove la-gram's activities among `activities` that no concept names any more, and then the users and
271
+ * the la-gram versions no activity names. A converter's run and agent are not la-gram's to remove.
272
+ */
273
+ private dropUnnamed(activities: Set<string>, namespace: string): void {
274
+ const prefix = this.options.softwareIriPrefix;
275
+ const own = (iri: string) => iri.startsWith(`${namespace}provenance/`) || iri === this.agent || (!!prefix && iri.startsWith(prefix));
276
+ const agents = new Set<string>();
277
+ const remove: Quad[] = [];
278
+ for (const activity of activities) {
279
+ if (!own(activity) || this.get(null, P.wasGeneratedBy, nn(activity)).length > 0) continue;
280
+ const quads = this.get(nn(activity));
281
+ for (const q of quads) if (q.predicate.value === P.wasAssociatedWith) agents.add(q.object.value);
282
+ remove.push(...quads);
283
+ }
284
+ if (remove.length === 0) return;
285
+ this.store.removeQuads(remove);
286
+ const unnamed = [...agents].filter((a) => own(a) && this.get(null, P.wasAssociatedWith, nn(a)).length === 0);
287
+ const agentQuads = unnamed.flatMap((a) => this.get(nn(a)));
288
+ if (agentQuads.length > 0) this.store.removeQuads(agentQuads);
289
+ }
290
+
291
+ /**
292
+ * The concept a changed statement is about: the subject itself when it is the model or a member of it
293
+ * (`arch:inModel`); the view of a shape (`arch-vis:view`); else what it is a part of — a style, a route's
294
+ * cell, a name, a picture — by the link that leads to it, up to a concept or a shape. Before or after the
295
+ * edit: a removed statement is read from what the edit removed.
296
+ */
297
+ private ownerOf(subject: Quad['subject'], removed: N3Store, resolved: Map<string, string | null>): string | undefined {
298
+ const seen = new Set<string>();
299
+ const walk = (term: Quad['subject']): string | undefined => {
300
+ const key = term.value;
301
+ if (resolved.has(key)) return resolved.get(key) ?? undefined;
302
+ if (seen.has(key) || seen.size > 256) return undefined;
303
+ seen.add(key);
304
+ const either = (p: string, o: Term | null = null) => [
305
+ ...this.get(term as NamedNode, p, o),
306
+ ...(removed.getQuads(term as never, nn(p) as never, o as never, null) as unknown as Quad[]),
307
+ ];
308
+ let owner: string | undefined;
309
+ if (either(IRI.inModel).length > 0 || either(IRI.rdfType, nn(IRI.Model)).length > 0) owner = key;
310
+ else {
311
+ const view = either(NAMESPACES['arch-vis'] + 'view')[0];
312
+ if (view) owner = view.object.value;
313
+ else {
314
+ const incoming = [
315
+ ...this.get(null, null, term as Term),
316
+ ...(removed.getQuads(null, null, term as never, null) as unknown as Quad[]),
317
+ ];
318
+ for (const link of incoming) {
319
+ if (link.subject.value === key || NOT_PART_OF.has(link.predicate.value)) continue;
320
+ owner = walk(link.subject);
321
+ if (owner) break;
322
+ }
323
+ }
324
+ }
325
+ resolved.set(key, owner ?? null);
326
+ return owner;
327
+ };
328
+ return walk(subject);
329
+ }
330
+
331
+ /** Whether `subject` is provenance itself — an activity, an agent: its own statements are not an edit. */
332
+ private isProvenanceNode(subject: Quad['subject'], removed: N3Store): boolean {
333
+ const types = [
334
+ ...this.get(subject as NamedNode, IRI.rdfType),
335
+ ...(removed.getQuads(subject as never, nn(IRI.rdfType) as never, null, null) as unknown as Quad[]),
336
+ ];
337
+ return types.some((q) => q.object.value.startsWith(PROV));
338
+ }
339
+
340
+ private has(subject: NamedNode, predicate: string): boolean {
341
+ return this.get(subject, predicate).length > 0;
342
+ }
343
+
344
+ /** The model's statements matching a pattern — the default graph, which the store reads from its copy. */
345
+ private get(subject: NamedNode | null, predicate?: string | null, object?: Term | null): Quad[] {
346
+ return this.store.getQuads(subject, predicate ? nn(predicate) : null, (object ?? null) as NamedNode | null, MODEL);
347
+ }
348
+
349
+ private write(remove: Quad[], add: Quad[]): void {
350
+ const keys = new Set(add.map(key));
351
+ const stale = remove.filter((q) => !keys.has(key(q)));
352
+ const fresh = add.filter((q) => !remove.some((r) => key(r) === key(q)));
353
+ if (stale.length > 0) this.store.removeQuads(stale);
354
+ if (fresh.length > 0) this.store.addQuads(fresh);
355
+ }
356
+ }
357
+
358
+ function key(q: Quad): string {
359
+ return `${q.subject.value} ${q.predicate.value} ${q.object.termType}:${q.object.value}`;
360
+ }
361
+
362
+ /** What the panel shows of a concept's provenance, read-only (Req 9.16). */
363
+ export interface ConceptProvenance {
364
+ /** The last edit: when, by whom — and their account's page — with which tool, from the activity that generated it. */
365
+ changed?: { at: string; by?: string; account?: string; tool?: string };
366
+ /** Its other PROV statements — a converter's `prov:wasDerivedFrom` its source — as predicate and value. */
367
+ other: Array<{ predicate: string; value: string }>;
368
+ }
369
+
370
+ /** A concept's provenance as the model records it: its last edit, and its other PROV statements. */
371
+ export function provenanceOf(store: RdfStore, iri: string): ConceptProvenance {
372
+ const get = (s: string, p: string) => store.getQuads(nn(s), nn(p), null, MODEL);
373
+ const first = (s: string, p: string) => get(s, p)[0]?.object.value;
374
+ const statements = store.getQuads(nn(iri), null, null, MODEL).filter((q) => q.predicate.value.startsWith(PROV));
375
+ const other = statements
376
+ .filter((q) => q.predicate.value !== P.wasGeneratedBy && q.predicate.value !== P.generatedAtTime)
377
+ .map((q) => ({ predicate: q.predicate.value, value: q.object.value }));
378
+ const activity = first(iri, P.wasGeneratedBy);
379
+ const at = first(iri, P.generatedAtTime) ?? (activity ? first(activity, P.endedAtTime) : undefined);
380
+ if (!activity || !at) return { other };
381
+ let by: string | undefined;
382
+ let account: string | undefined;
383
+ let tool: string | undefined;
384
+ for (const agent of get(activity, P.wasAssociatedWith).map((q) => q.object.value)) {
385
+ const types = get(agent, IRI.rdfType).map((q) => q.object.value);
386
+ const name = first(agent, P.name);
387
+ if (types.includes(P.softwareAgent)) {
388
+ const version = first(agent, P.softwareVersion);
389
+ tool = [name ?? agent, version].filter(Boolean).join(' ');
390
+ } else if (types.includes(P.person)) {
391
+ by = name ?? first(agent, P.alternateName) ?? first(agent, P.email);
392
+ account = first(agent, P.sameAs);
393
+ }
394
+ }
395
+ return { changed: { at, ...(by ? { by } : {}), ...(account ? { account } : {}), ...(tool ? { tool } : {}) }, other };
396
+ }