@linked.archi/kernel 0.0.0-stage → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +102 -2
  4. package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
  5. package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
  6. package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
  7. package/assets/arch-decision/arch-decision-tax.ttl +129 -0
  8. package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
  9. package/assets/arch-processes/arch-processes-tax.ttl +136 -0
  10. package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
  11. package/assets/arch-processes/archProcesses.ttl +953 -0
  12. package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
  13. package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
  14. package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
  15. package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
  16. package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
  17. package/assets/archimate3/archimate3.2-principle-shapes.ttl +917 -0
  18. package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
  19. package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
  20. package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
  21. package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
  22. package/assets/archimate3/archimate3.2-tax.ttl +724 -0
  23. package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
  24. package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
  25. package/assets/archimate3/icons/and-junction.svg +3 -0
  26. package/assets/archimate3/icons/application-collaboration.svg +22 -0
  27. package/assets/archimate3/icons/application-component.svg +18 -0
  28. package/assets/archimate3/icons/application-event.svg +15 -0
  29. package/assets/archimate3/icons/application-function.svg +14 -0
  30. package/assets/archimate3/icons/application-interaction.svg +17 -0
  31. package/assets/archimate3/icons/application-interface.svg +16 -0
  32. package/assets/archimate3/icons/application-process.svg +14 -0
  33. package/assets/archimate3/icons/application-service.svg +14 -0
  34. package/assets/archimate3/icons/artifact.svg +16 -0
  35. package/assets/archimate3/icons/assessment.svg +17 -0
  36. package/assets/archimate3/icons/business-actor.svg +22 -0
  37. package/assets/archimate3/icons/business-collaboration.svg +21 -0
  38. package/assets/archimate3/icons/business-event.svg +15 -0
  39. package/assets/archimate3/icons/business-function.svg +14 -0
  40. package/assets/archimate3/icons/business-interaction.svg +18 -0
  41. package/assets/archimate3/icons/business-interface.svg +16 -0
  42. package/assets/archimate3/icons/business-object.svg +14 -0
  43. package/assets/archimate3/icons/business-process.svg +15 -0
  44. package/assets/archimate3/icons/business-role.svg +16 -0
  45. package/assets/archimate3/icons/business-service.svg +14 -0
  46. package/assets/archimate3/icons/capability.svg +40 -0
  47. package/assets/archimate3/icons/communication-network.svg +18 -0
  48. package/assets/archimate3/icons/constraint.svg +18 -0
  49. package/assets/archimate3/icons/contract.svg +13 -0
  50. package/assets/archimate3/icons/course-of-action.svg +20 -0
  51. package/assets/archimate3/icons/data-object.svg +14 -0
  52. package/assets/archimate3/icons/deliverable.svg +11 -0
  53. package/assets/archimate3/icons/device.svg +18 -0
  54. package/assets/archimate3/icons/distribution-network.svg +19 -0
  55. package/assets/archimate3/icons/driver.svg +24 -0
  56. package/assets/archimate3/icons/equipment.svg +31 -0
  57. package/assets/archimate3/icons/facility.svg +16 -0
  58. package/assets/archimate3/icons/gap.svg +22 -0
  59. package/assets/archimate3/icons/glyphs/activity.svg +3 -0
  60. package/assets/archimate3/icons/glyphs/actor.svg +14 -0
  61. package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
  62. package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
  63. package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
  64. package/assets/archimate3/icons/glyphs/capability.svg +32 -0
  65. package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
  66. package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
  67. package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
  68. package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
  69. package/assets/archimate3/icons/glyphs/contract.svg +5 -0
  70. package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
  71. package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
  72. package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
  73. package/assets/archimate3/icons/glyphs/device.svg +10 -0
  74. package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
  75. package/assets/archimate3/icons/glyphs/driver.svg +16 -0
  76. package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
  77. package/assets/archimate3/icons/glyphs/event.svg +6 -0
  78. package/assets/archimate3/icons/glyphs/facility.svg +7 -0
  79. package/assets/archimate3/icons/glyphs/function.svg +6 -0
  80. package/assets/archimate3/icons/glyphs/gap.svg +14 -0
  81. package/assets/archimate3/icons/glyphs/goal.svg +10 -0
  82. package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
  83. package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
  84. package/assets/archimate3/icons/glyphs/interface.svg +8 -0
  85. package/assets/archimate3/icons/glyphs/location.svg +6 -0
  86. package/assets/archimate3/icons/glyphs/material.svg +12 -0
  87. package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
  88. package/assets/archimate3/icons/glyphs/node.svg +8 -0
  89. package/assets/archimate3/icons/glyphs/object.svg +4 -0
  90. package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
  91. package/assets/archimate3/icons/glyphs/path.svg +10 -0
  92. package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
  93. package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
  94. package/assets/archimate3/icons/glyphs/principle.svg +12 -0
  95. package/assets/archimate3/icons/glyphs/process.svg +6 -0
  96. package/assets/archimate3/icons/glyphs/product.svg +4 -0
  97. package/assets/archimate3/icons/glyphs/representation.svg +4 -0
  98. package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
  99. package/assets/archimate3/icons/glyphs/resource.svg +14 -0
  100. package/assets/archimate3/icons/glyphs/role.svg +6 -0
  101. package/assets/archimate3/icons/glyphs/service.svg +6 -0
  102. package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
  103. package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
  104. package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
  105. package/assets/archimate3/icons/glyphs/value.svg +3 -0
  106. package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
  107. package/assets/archimate3/icons/goal.svg +18 -0
  108. package/assets/archimate3/icons/grouping.svg +12 -0
  109. package/assets/archimate3/icons/implementation-event.svg +15 -0
  110. package/assets/archimate3/icons/location.svg +14 -0
  111. package/assets/archimate3/icons/material.svg +21 -0
  112. package/assets/archimate3/icons/meaning.svg +11 -0
  113. package/assets/archimate3/icons/node.svg +14 -0
  114. package/assets/archimate3/icons/or-junction.svg +3 -0
  115. package/assets/archimate3/icons/outcome.svg +25 -0
  116. package/assets/archimate3/icons/path.svg +18 -0
  117. package/assets/archimate3/icons/plateau.svg +16 -0
  118. package/assets/archimate3/icons/principle.svg +21 -0
  119. package/assets/archimate3/icons/product.svg +12 -0
  120. package/assets/archimate3/icons/representation.svg +12 -0
  121. package/assets/archimate3/icons/requirement.svg +14 -0
  122. package/assets/archimate3/icons/resource.svg +23 -0
  123. package/assets/archimate3/icons/stakeholder.svg +15 -0
  124. package/assets/archimate3/icons/system-software.svg +22 -0
  125. package/assets/archimate3/icons/technology-collaboration.svg +22 -0
  126. package/assets/archimate3/icons/technology-event.svg +15 -0
  127. package/assets/archimate3/icons/technology-function.svg +14 -0
  128. package/assets/archimate3/icons/technology-interaction.svg +18 -0
  129. package/assets/archimate3/icons/technology-interface.svg +16 -0
  130. package/assets/archimate3/icons/technology-process.svg +14 -0
  131. package/assets/archimate3/icons/technology-service.svg +14 -0
  132. package/assets/archimate3/icons/value-stream.svg +11 -0
  133. package/assets/archimate3/icons/value.svg +11 -0
  134. package/assets/archimate3/icons/work-package.svg +12 -0
  135. package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
  136. package/assets/archimate4/archimate4-metamodel.ttl +179 -0
  137. package/assets/archimate4/archimate4-notation.ttl +1147 -0
  138. package/assets/archimate4/archimate4-onto.ttl +1559 -0
  139. package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
  140. package/assets/archimate4/archimate4-principle-shapes.ttl +895 -0
  141. package/assets/archimate4/archimate4-questions.ttl +1224 -0
  142. package/assets/archimate4/archimate4-reference-data.ttl +56 -0
  143. package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
  144. package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
  145. package/assets/archimate4/archimate4-tax.ttl +749 -0
  146. package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
  147. package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
  148. package/assets/archimate4/icons/and-junction.svg +3 -0
  149. package/assets/archimate4/icons/application-component.svg +18 -0
  150. package/assets/archimate4/icons/application-interface.svg +16 -0
  151. package/assets/archimate4/icons/artifact.svg +16 -0
  152. package/assets/archimate4/icons/assessment.svg +17 -0
  153. package/assets/archimate4/icons/business-actor.svg +22 -0
  154. package/assets/archimate4/icons/business-interface.svg +16 -0
  155. package/assets/archimate4/icons/business-object.svg +14 -0
  156. package/assets/archimate4/icons/capability.svg +40 -0
  157. package/assets/archimate4/icons/collaboration.svg +21 -0
  158. package/assets/archimate4/icons/communication-network.svg +18 -0
  159. package/assets/archimate4/icons/course-of-action.svg +20 -0
  160. package/assets/archimate4/icons/data-object.svg +14 -0
  161. package/assets/archimate4/icons/deliverable.svg +11 -0
  162. package/assets/archimate4/icons/device.svg +18 -0
  163. package/assets/archimate4/icons/distribution-network.svg +19 -0
  164. package/assets/archimate4/icons/driver.svg +24 -0
  165. package/assets/archimate4/icons/equipment.svg +31 -0
  166. package/assets/archimate4/icons/event.svg +15 -0
  167. package/assets/archimate4/icons/facility.svg +16 -0
  168. package/assets/archimate4/icons/function.svg +13 -0
  169. package/assets/archimate4/icons/glyphs/activity.svg +3 -0
  170. package/assets/archimate4/icons/glyphs/actor.svg +14 -0
  171. package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
  172. package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
  173. package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
  174. package/assets/archimate4/icons/glyphs/capability.svg +32 -0
  175. package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
  176. package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
  177. package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
  178. package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
  179. package/assets/archimate4/icons/glyphs/contract.svg +5 -0
  180. package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
  181. package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
  182. package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
  183. package/assets/archimate4/icons/glyphs/device.svg +10 -0
  184. package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
  185. package/assets/archimate4/icons/glyphs/driver.svg +16 -0
  186. package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
  187. package/assets/archimate4/icons/glyphs/event.svg +6 -0
  188. package/assets/archimate4/icons/glyphs/facility.svg +7 -0
  189. package/assets/archimate4/icons/glyphs/function.svg +6 -0
  190. package/assets/archimate4/icons/glyphs/gap.svg +14 -0
  191. package/assets/archimate4/icons/glyphs/goal.svg +10 -0
  192. package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
  193. package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
  194. package/assets/archimate4/icons/glyphs/interface.svg +8 -0
  195. package/assets/archimate4/icons/glyphs/location.svg +6 -0
  196. package/assets/archimate4/icons/glyphs/material.svg +12 -0
  197. package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
  198. package/assets/archimate4/icons/glyphs/node.svg +8 -0
  199. package/assets/archimate4/icons/glyphs/object.svg +4 -0
  200. package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
  201. package/assets/archimate4/icons/glyphs/path.svg +10 -0
  202. package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
  203. package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
  204. package/assets/archimate4/icons/glyphs/principle.svg +12 -0
  205. package/assets/archimate4/icons/glyphs/process.svg +6 -0
  206. package/assets/archimate4/icons/glyphs/product.svg +4 -0
  207. package/assets/archimate4/icons/glyphs/representation.svg +4 -0
  208. package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
  209. package/assets/archimate4/icons/glyphs/resource.svg +14 -0
  210. package/assets/archimate4/icons/glyphs/role.svg +6 -0
  211. package/assets/archimate4/icons/glyphs/service.svg +6 -0
  212. package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
  213. package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
  214. package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
  215. package/assets/archimate4/icons/glyphs/value.svg +3 -0
  216. package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
  217. package/assets/archimate4/icons/goal.svg +18 -0
  218. package/assets/archimate4/icons/grouping.svg +12 -0
  219. package/assets/archimate4/icons/location.svg +14 -0
  220. package/assets/archimate4/icons/material.svg +21 -0
  221. package/assets/archimate4/icons/meaning.svg +11 -0
  222. package/assets/archimate4/icons/node.svg +14 -0
  223. package/assets/archimate4/icons/or-junction.svg +3 -0
  224. package/assets/archimate4/icons/outcome.svg +25 -0
  225. package/assets/archimate4/icons/path.svg +18 -0
  226. package/assets/archimate4/icons/plateau.svg +16 -0
  227. package/assets/archimate4/icons/principle.svg +21 -0
  228. package/assets/archimate4/icons/process.svg +15 -0
  229. package/assets/archimate4/icons/product.svg +12 -0
  230. package/assets/archimate4/icons/requirement.svg +14 -0
  231. package/assets/archimate4/icons/resource.svg +23 -0
  232. package/assets/archimate4/icons/role.svg +16 -0
  233. package/assets/archimate4/icons/service.svg +13 -0
  234. package/assets/archimate4/icons/stakeholder.svg +15 -0
  235. package/assets/archimate4/icons/system-software.svg +22 -0
  236. package/assets/archimate4/icons/technology-interface.svg +16 -0
  237. package/assets/archimate4/icons/value-stream.svg +11 -0
  238. package/assets/archimate4/icons/value.svg +11 -0
  239. package/assets/archimate4/icons/work-package.svg +12 -0
  240. package/assets/basic/basic-metamodel.ttl +100 -0
  241. package/assets/basic/basic-notation-bubble.ttl +175 -0
  242. package/assets/basic/basic-notation.ttl +172 -0
  243. package/assets/basic/basic-onto.ttl +171 -0
  244. package/assets/basic/basic-presentation-contexts.ttl +70 -0
  245. package/assets/basic/basic-tax.ttl +130 -0
  246. package/assets/basic/icons/aggregation.svg +7 -0
  247. package/assets/basic/icons/association.svg +6 -0
  248. package/assets/basic/icons/element.svg +5 -0
  249. package/assets/basic/icons/glyphs/aggregation.svg +6 -0
  250. package/assets/basic/icons/glyphs/association.svg +5 -0
  251. package/assets/basic/icons/glyphs/element.svg +5 -0
  252. package/assets/basic/icons/glyphs/relationship.svg +5 -0
  253. package/assets/basic/icons/relationship.svg +7 -0
  254. package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
  255. package/assets/basic/notation-bubble/icons/association.svg +6 -0
  256. package/assets/basic/notation-bubble/icons/element.svg +5 -0
  257. package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
  258. package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
  259. package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
  260. package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
  261. package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
  262. package/assets/catalog.ttl +7406 -0
  263. package/assets/core/core-notation.ttl +131 -0
  264. package/assets/core/core-onto.ttl +2811 -0
  265. package/assets/core/core-questions.ttl +957 -0
  266. package/assets/core/core-shapes.ttl +915 -0
  267. package/assets/core/core-vis-onto.ttl +1408 -0
  268. package/assets/core/core-vis-shapes.ttl +851 -0
  269. package/assets/core-vis/markers/circle-dot.svg +3 -0
  270. package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
  271. package/assets/core-vis/markers/filled-diamond.svg +3 -0
  272. package/assets/core-vis/markers/half-arrowhead.svg +3 -0
  273. package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
  274. package/assets/core-vis/markers/hollow-diamond.svg +3 -0
  275. package/assets/core-vis/markers/open-arrowhead.svg +3 -0
  276. package/fixtures/interoperability/archimate4-demo.trig +259 -0
  277. package/fixtures/interoperability/expected-findings.json +26 -0
  278. package/fixtures/interoperability/shop-seed.ttl +225 -0
  279. package/package.json +136 -4
  280. package/scripts/sync-assets.mjs +252 -0
  281. package/src/conformance.ts +66 -0
  282. package/src/import-export/model-io.ts +426 -0
  283. package/src/index.ts +11 -0
  284. package/src/metamodel-manager/asset-sources.ts +754 -0
  285. package/src/metamodel-manager/bundled-assets.ts +599 -0
  286. package/src/metamodel-manager/catalogue.ts +114 -0
  287. package/src/metamodel-manager/class-hierarchy.ts +155 -0
  288. package/src/metamodel-manager/index.ts +65 -0
  289. package/src/metamodel-manager/interfaces.ts +422 -0
  290. package/src/metamodel-manager/metamodel-completeness.ts +162 -0
  291. package/src/metamodel-manager/metamodel-loader.ts +864 -0
  292. package/src/metamodel-manager/notation-resolver.ts +284 -0
  293. package/src/metamodel-manager/notation.ts +659 -0
  294. package/src/metamodel-manager/palette-generator.ts +882 -0
  295. package/src/metamodel-manager/property-shapes.ts +290 -0
  296. package/src/metamodel-manager/taxonomy.ts +904 -0
  297. package/src/metamodel-manager/type-guide.ts +241 -0
  298. package/src/metamodel-manager/viewpoint-manager.ts +147 -0
  299. package/src/model-manager/appearance.ts +389 -0
  300. package/src/model-manager/cascade.ts +246 -0
  301. package/src/model-manager/clipboard.ts +566 -0
  302. package/src/model-manager/context-names.ts +108 -0
  303. package/src/model-manager/custom-properties.ts +549 -0
  304. package/src/model-manager/derivations.ts +166 -0
  305. package/src/model-manager/direct-permissions.ts +182 -0
  306. package/src/model-manager/drawing-order.ts +119 -0
  307. package/src/model-manager/element-manager.ts +69 -0
  308. package/src/model-manager/element-pictures.ts +118 -0
  309. package/src/model-manager/field-names.ts +42 -0
  310. package/src/model-manager/folders.ts +354 -0
  311. package/src/model-manager/grid.ts +6 -0
  312. package/src/model-manager/index.ts +43 -0
  313. package/src/model-manager/interfaces.ts +417 -0
  314. package/src/model-manager/iri-conformance.ts +183 -0
  315. package/src/model-manager/label-expression.ts +233 -0
  316. package/src/model-manager/legacy-migration.ts +200 -0
  317. package/src/model-manager/missing-references.ts +86 -0
  318. package/src/model-manager/model-diff-text.ts +150 -0
  319. package/src/model-manager/model-diff.ts +534 -0
  320. package/src/model-manager/model-merge.ts +1160 -0
  321. package/src/model-manager/model-namespace.ts +199 -0
  322. package/src/model-manager/model-operations.ts +132 -0
  323. package/src/model-manager/model-queries.ts +616 -0
  324. package/src/model-manager/model-session.ts +759 -0
  325. package/src/model-manager/multiplicity.ts +74 -0
  326. package/src/model-manager/nested-resources.ts +145 -0
  327. package/src/model-manager/own-metamodel.ts +157 -0
  328. package/src/model-manager/placement-copy.ts +116 -0
  329. package/src/model-manager/property-catalog.ts +787 -0
  330. package/src/model-manager/proposal-order.ts +203 -0
  331. package/src/model-manager/provenance.ts +396 -0
  332. package/src/model-manager/questions.ts +475 -0
  333. package/src/model-manager/rdf-scope.ts +97 -0
  334. package/src/model-manager/relationship-graph.ts +462 -0
  335. package/src/model-manager/relationship-manager.ts +962 -0
  336. package/src/model-manager/relationship-table.ts +189 -0
  337. package/src/model-manager/relationship-validity.ts +261 -0
  338. package/src/model-manager/resource-edits.ts +28 -0
  339. package/src/model-manager/short-hash.ts +104 -0
  340. package/src/model-manager/snapshot-lines.ts +88 -0
  341. package/src/model-manager/version-history.ts +205 -0
  342. package/src/model-manager/view-from-results.ts +81 -0
  343. package/src/model-manager/view-manager.ts +1410 -0
  344. package/src/model-manager/vocabulary.ts +279 -0
  345. package/src/rdf-engine/finding-shape.ts +23 -0
  346. package/src/rdf-engine/graph-scope.ts +163 -0
  347. package/src/rdf-engine/index.ts +7 -0
  348. package/src/rdf-engine/interfaces.ts +144 -0
  349. package/src/rdf-engine/iri.ts +203 -0
  350. package/src/rdf-engine/localized-text.ts +13 -0
  351. package/src/rdf-engine/namespaces.ts +41 -0
  352. package/src/rdf-engine/native-load.ts +37 -0
  353. package/src/rdf-engine/observable-store.ts +609 -0
  354. package/src/rdf-engine/rdf-store.ts +520 -0
  355. package/src/rdf-engine/shacl-validator.ts +602 -0
  356. package/src/rdf-engine/shape-reach.ts +140 -0
  357. package/src/rdf-engine/shape-switches.ts +165 -0
  358. package/src/rdf-engine/single-valued.ts +219 -0
  359. package/src/rdf-engine/sparql-constraints.ts +349 -0
  360. package/src/rdf-engine/term-codec.ts +51 -0
  361. package/src/rdf-engine/ttl-parser.ts +51 -0
  362. package/src/rdf-engine/ttl-serializer.ts +79 -0
  363. package/src/rdf-engine/turtle-writer.ts +284 -0
  364. package/src/rdf-engine/validation-engine.ts +747 -0
  365. package/src/rdf-engine/validation-service.ts +186 -0
  366. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,189 @@
1
+ /**
2
+ * The relationship table a metamodel's SHACL shapes encode — which source and
3
+ * target classes each qualified relationship class admits.
4
+ *
5
+ * ## Why not `arch:domainIncludes` / `arch:rangeIncludes`
6
+ *
7
+ * Those are hints, declared on abstract superclasses: ArchiMate 4.0's Serving
8
+ * says "from an active structure element, to …", which admits far more pairs
9
+ * than the language allows. Deciding validity from them offered relationships
10
+ * the shapes then reported as violations. The normative answer is the
11
+ * relationship shapes: ArchiMate 4.0's and 3.2's are generated from the
12
+ * specification's relationship matrix, one node shape per qualified relationship
13
+ * class whose `sh:or` lists every permitted (source class, target classes) pair:
14
+ *
15
+ * ```turtle
16
+ * :AccessShape sh:targetClass am4:Access ;
17
+ * sh:or (
18
+ * [ sh:and (
19
+ * [ sh:property [ sh:path arch:source ; sh:class am4:ApplicationComponent ] ]
20
+ * [ sh:property [ sh:path arch:target ; sh:or ( [ sh:class am4:Artifact ] … ) ] ]
21
+ * ) ]
22
+ * …
23
+ * ) .
24
+ * ```
25
+ *
26
+ * This module reads that pattern into a lookup. `sh:class` matches instances of
27
+ * the class and its subclasses, so a pair admits a concrete type whose
28
+ * `rdfs:subClassOf*` closure contains the listed class.
29
+ *
30
+ * Shapes reach subclasses too: `sh:targetClass am4:Aggregation` also targets
31
+ * every `am4:Composition` (a subclass — "allowed in exactly the same cases").
32
+ * So a relationship class is judged by the rows of every class in its
33
+ * `rdfs:subClassOf*` closure, and must satisfy all of them, as validation would.
34
+ *
35
+ * C4's and Backstage's relationship shapes list their pairs in the same form,
36
+ * and are read the same way.
37
+ *
38
+ * A relationship class that neither it nor a superclass has rows for is left to
39
+ * the hints: a metamodel without relationship shapes in this form (BPMN, Basic,
40
+ * EDGY, …) behaves as before.
41
+ */
42
+
43
+ import type { NamedNode, Term } from '@rdfjs/types';
44
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
45
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
46
+ import { nn } from './vocabulary.js';
47
+
48
+ /** One permitted row: a source class and the target classes it may reach. */
49
+ interface PermittedRow {
50
+ source: string;
51
+ targets: Set<string>;
52
+ }
53
+
54
+ /** Which (source, target) pairs each constrained relationship class admits. */
55
+ export class RelationshipTable {
56
+ constructor(private readonly rows: ReadonlyMap<string, readonly PermittedRow[]>) {}
57
+
58
+ /** Relationship classes the shapes constrain. */
59
+ get size(): number {
60
+ return this.rows.size;
61
+ }
62
+
63
+ /**
64
+ * Whether the shapes constrain a relationship class, given its
65
+ * `rdfs:subClassOf*` closure (a shape on a superclass counts).
66
+ */
67
+ covers(relationshipClosure: readonly string[]): boolean {
68
+ return relationshipClosure.some((c) => this.rows.has(c));
69
+ }
70
+
71
+ /**
72
+ * Whether a relationship may go from a source to a target, given the
73
+ * `rdfs:subClassOf*` closures of the relationship class, the source type and
74
+ * the target type (each including the class itself). Every constrained class
75
+ * in the relationship's closure must admit the pair. `true` when none is
76
+ * constrained.
77
+ */
78
+ allows(relationshipClosure: readonly string[], sourceClosure: readonly string[], targetClosure: readonly string[]): boolean {
79
+ return relationshipClosure.every((c) => {
80
+ const rows = this.rows.get(c);
81
+ return !rows || rows.some((row) => sourceClosure.includes(row.source) && targetClosure.some((t) => row.targets.has(t)));
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Whether the shapes let a relationship start at a source at all (to some
87
+ * target) — the cheap question a UI prefilter asks. `true` when unconstrained.
88
+ */
89
+ allowsSource(relationshipClosure: readonly string[], sourceClosure: readonly string[]): boolean {
90
+ return relationshipClosure.every((c) => {
91
+ const rows = this.rows.get(c);
92
+ return !rows || rows.some((row) => sourceClosure.includes(row.source));
93
+ });
94
+ }
95
+
96
+ /** Whether the shapes let a relationship end at a target at all. `true` when unconstrained. */
97
+ allowsTarget(relationshipClosure: readonly string[], targetClosure: readonly string[]): boolean {
98
+ return relationshipClosure.every((c) => {
99
+ const rows = this.rows.get(c);
100
+ return !rows || rows.some((row) => targetClosure.some((t) => row.targets.has(t)));
101
+ });
102
+ }
103
+
104
+ /** The target classes the shapes list for a source class (for tests and diagnostics). */
105
+ targetsOf(relationshipClassIri: string, sourceClassIri: string): string[] {
106
+ const rows = this.rows.get(relationshipClassIri) ?? [];
107
+ return [...new Set(rows.filter((r) => r.source === sourceClassIri).flatMap((r) => [...r.targets]))].sort();
108
+ }
109
+ }
110
+
111
+ /** An empty table: everything is left to the hints. */
112
+ export const EMPTY_RELATIONSHIP_TABLE = new RelationshipTable(new Map());
113
+
114
+ const SH_TARGET_CLASS = nn(NAMESPACES.sh + 'targetClass');
115
+ const SH_OR = nn(NAMESPACES.sh + 'or');
116
+ const SH_AND = nn(NAMESPACES.sh + 'and');
117
+ const SH_PROPERTY = nn(NAMESPACES.sh + 'property');
118
+ const SH_PATH = nn(NAMESPACES.sh + 'path');
119
+ const SH_CLASS = nn(NAMESPACES.sh + 'class');
120
+ const RDF_FIRST = nn(NAMESPACES.rdf + 'first');
121
+ const RDF_REST = nn(NAMESPACES.rdf + 'rest');
122
+ const RDF_NIL = NAMESPACES.rdf + 'nil';
123
+ const ARCH_SOURCE = NAMESPACES.arch + 'source';
124
+ const ARCH_TARGET = NAMESPACES.arch + 'target';
125
+
126
+ /**
127
+ * Read the relationship table from every relationship shape in the store (all
128
+ * graphs).
129
+ *
130
+ * Walks the shapes' RDF lists with indexed quad lookups. The same walk as one
131
+ * SPARQL query with `rdf:rest*` paths took ~50 s over the merged metamodel
132
+ * graphs; this takes a fraction of a second.
133
+ */
134
+ export function readRelationshipTable(store: RdfStore): RelationshipTable {
135
+ const objects = (subject: Term, predicate: NamedNode): Term[] =>
136
+ store.getQuads(subject as NamedNode, predicate).map((q) => q.object);
137
+ const items = (head: Term): Term[] => {
138
+ const out: Term[] = [];
139
+ const seen = new Set<string>();
140
+ let cell: Term | undefined = head;
141
+ while (cell && cell.value !== RDF_NIL && !seen.has(cell.value)) {
142
+ seen.add(cell.value);
143
+ out.push(...objects(cell, RDF_FIRST));
144
+ cell = objects(cell, RDF_REST)[0];
145
+ }
146
+ return out;
147
+ };
148
+ const classesOf = (node: Term): string[] => [
149
+ ...objects(node, SH_CLASS).map((t) => t.value),
150
+ ...objects(node, SH_OR).flatMap((list) => items(list).flatMap((alt) => objects(alt, SH_CLASS).map((t) => t.value))),
151
+ ];
152
+
153
+ const rows = new Map<string, Map<string, Set<string>>>();
154
+ for (const target of store.getQuads(null, SH_TARGET_CLASS)) {
155
+ const rel = target.object.value;
156
+ for (const alternatives of objects(target.subject, SH_OR)) {
157
+ for (const alternative of items(alternatives)) {
158
+ for (const conjunction of objects(alternative, SH_AND)) {
159
+ const sources: string[] = [];
160
+ const targets: string[] = [];
161
+ for (const part of items(conjunction)) {
162
+ for (const property of objects(part, SH_PROPERTY)) {
163
+ const path = objects(property, SH_PATH)[0]?.value;
164
+ if (path === ARCH_SOURCE) sources.push(...classesOf(property));
165
+ else if (path === ARCH_TARGET) targets.push(...classesOf(property));
166
+ }
167
+ }
168
+ if (sources.length === 0 || targets.length === 0) continue;
169
+ let bySource = rows.get(rel);
170
+ if (!bySource) rows.set(rel, (bySource = new Map()));
171
+ for (const source of sources) {
172
+ let set = bySource.get(source);
173
+ if (!set) bySource.set(source, (set = new Set()));
174
+ for (const t of targets) set.add(t);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ const table = new Map<string, PermittedRow[]>();
182
+ for (const [rel, bySource] of rows) {
183
+ table.set(
184
+ rel,
185
+ [...bySource].map(([source, targets]) => ({ source, targets })),
186
+ );
187
+ }
188
+ return new RelationshipTable(table);
189
+ }
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Whether each relationship is one the language permits, checked against its
3
+ * relationship tables — in place of the relationship shapes generated from the
4
+ * same tables (Task 22).
5
+ *
6
+ * ## Why not the shapes
7
+ *
8
+ * The shapes a language's relationship matrix generates check a relationship
9
+ * against an `sh:or` of every source–target pair it permits. A SHACL engine
10
+ * tries the pairs in turn, and rdf-validate-shacl builds a full result for each
11
+ * one that fails — copying part of the shapes graph into it — before throwing
12
+ * it away: on a model of 34 000 triples, 12 of the 14 seconds validation took,
13
+ * after every edit. The relationship tables (`direct-permissions.ts`) say the
14
+ * same as lookups: here, a few map lookups per relationship.
15
+ *
16
+ * ## Which shapes, and how the check stays theirs
17
+ *
18
+ * {@link splitTableShapes} takes out of the shapes graph only what the tables
19
+ * cover, recognised by its form, in any language whose tables follow the
20
+ * pattern:
21
+ *
22
+ * - **qualified** — a node shape whose `sh:targetClass` is a relationship class
23
+ * whose `arch:unqualifiedForm` the tables cover, made of an `sh:or` (its
24
+ * permitted pairs) and nothing else;
25
+ * - **unqualified** — a node shape whose property shapes all have a covered
26
+ * predicate as `sh:path`, each an `sh:or` of classes or `sh:maxCount 0`.
27
+ *
28
+ * Every other shape stays — an attribute shape on a relationship class, the
29
+ * element, viewpoint and principle shapes. {@link checkRelationshipsByTables}
30
+ * then reports what the replaced shapes would: a qualified relationship whose
31
+ * source and target the tables do not permit, and a direct triple whose subject
32
+ * a replaced shape targets and whose object the tables do not permit — under
33
+ * the replaced shape's IRI and its `sh:message`.
34
+ *
35
+ * Junctions: the shapes let a junction be either end of any relationship; the
36
+ * tables do not name them. They are read from the replaced shapes — a class the
37
+ * shapes accept that the tables never name and that is not a relationship class.
38
+ */
39
+ import { DataFactory, Store as N3Store } from 'n3';
40
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
41
+ import type { ValidationResult } from '../rdf-engine/interfaces.js';
42
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
43
+ import type { TablePermissions } from './direct-permissions.js';
44
+ import type { TypeClosure } from './model-queries.js';
45
+
46
+ const { namedNode } = DataFactory;
47
+
48
+ const SH = NAMESPACES.sh;
49
+ const RDF_TYPE = NAMESPACES.rdf + 'type';
50
+ const ARCH_SOURCE = NAMESPACES.arch + 'source';
51
+ const ARCH_TARGET = NAMESPACES.arch + 'target';
52
+ const WILDCARDS = new Set([NAMESPACES.arch + 'Element', NAMESPACES.arch + 'ModelConcept']);
53
+ /** What a node shape may say besides its constraint and still be a generated one. */
54
+ const DESCRIPTIVE = new Set([
55
+ RDF_TYPE,
56
+ SH + 'targetClass',
57
+ SH + 'message',
58
+ SH + 'severity',
59
+ SH + 'name',
60
+ SH + 'description',
61
+ NAMESPACES.rdfs + 'label',
62
+ NAMESPACES.rdfs + 'comment',
63
+ NAMESPACES.skos + 'prefLabel',
64
+ NAMESPACES.skos + 'definition',
65
+ ]);
66
+ const PROPERTY_SHAPE_KEYS = new Set([SH + 'path', SH + 'or', SH + 'maxCount', SH + 'message', SH + 'severity']);
67
+
68
+ /** A replaced shape, as its results name it. */
69
+ interface Replaced {
70
+ shape: string;
71
+ message: string;
72
+ }
73
+
74
+ /** The shapes graph, split: what SHACL still checks, and what the tables check instead. */
75
+ export interface TableShapes {
76
+ /** The shapes graph without the replaced shapes. */
77
+ kept: Quad[];
78
+ /** Quads taken out. */
79
+ replacedQuads: number;
80
+ /** Relationship class → the qualified shape replaced, and the predicate the tables check it by. */
81
+ qualified: ReadonlyMap<string, Replaced & { predicate: string }>;
82
+ /** Subject class → predicate → the unqualified shape replaced (its property's message). */
83
+ unqualified: ReadonlyMap<string, ReadonlyMap<string, Replaced>>;
84
+ /** The junction classes: either end of any relationship. */
85
+ junctions: ReadonlySet<string>;
86
+ }
87
+
88
+ /** Nothing replaced: no tables loaded, or no shape in their form. */
89
+ export function noTableShapes(shapes: Quad[]): TableShapes {
90
+ return { kept: shapes, replacedQuads: 0, qualified: new Map(), unqualified: new Map(), junctions: new Set() };
91
+ }
92
+
93
+ /**
94
+ * Split a shapes graph into what SHACL keeps checking and what the tables
95
+ * check instead.
96
+ *
97
+ * @param formOf A relationship class's `arch:unqualifiedForm`.
98
+ * @param isRelationshipClass Whether a class is a relationship class (`arch:QualifiedRelationship` or under it).
99
+ */
100
+ export function splitTableShapes(
101
+ shapes: Quad[],
102
+ tables: TablePermissions,
103
+ formOf: ReadonlyMap<string, string>,
104
+ isRelationshipClass: (classIri: string) => boolean,
105
+ ): TableShapes {
106
+ if (tables.size === 0) return noTableShapes(shapes);
107
+ const index = new N3Store(shapes as never);
108
+ const subjectQuads = (s: Term) => index.getQuads(s as never, null, null, null) as unknown as Quad[];
109
+ const objects = (s: Term, p: string) => index.getObjects(s as never, namedNode(p), null) as unknown as Term[];
110
+ const literal = (s: Term, p: string) => objects(s, p).find((o) => o.termType === 'Literal')?.value ?? '';
111
+
112
+ const qualified = new Map<string, Replaced & { predicate: string }>();
113
+ const unqualified = new Map<string, Map<string, Replaced>>();
114
+ const dropped: Term[] = [];
115
+
116
+ for (const shape of index.getSubjects(namedNode(RDF_TYPE), namedNode(SH + 'NodeShape'), null) as unknown as Term[]) {
117
+ if (shape.termType !== 'NamedNode') continue;
118
+ const keys = new Set(subjectQuads(shape).map((q) => q.predicate.value));
119
+ const targets = objects(shape, SH + 'targetClass').map((t) => t.value);
120
+ if (targets.length === 0) continue;
121
+ const others = [...keys].filter((k) => !DESCRIPTIVE.has(k));
122
+
123
+ // Qualified: an sh:or of permitted pairs, on relationship classes the tables cover.
124
+ if (others.length === 1 && others[0] === SH + 'or') {
125
+ const forms = targets.map((t) => formOf.get(t));
126
+ if (forms.every((p): p is string => !!p && tables.covers(p))) {
127
+ targets.forEach((t, i) => qualified.set(t, { shape: shape.value, message: literal(shape, SH + 'message'), predicate: forms[i] as string }));
128
+ dropped.push(shape);
129
+ }
130
+ continue;
131
+ }
132
+
133
+ // Unqualified: property shapes only, each on a covered predicate, an sh:or or sh:maxCount 0.
134
+ if (others.length === 1 && others[0] === SH + 'property') {
135
+ const properties = objects(shape, SH + 'property');
136
+ const byPredicate = new Map<string, Replaced>();
137
+ const generated = properties.every((property) => {
138
+ const pkeys = subjectQuads(property).map((q) => q.predicate.value);
139
+ if (!pkeys.every((k) => PROPERTY_SHAPE_KEYS.has(k))) return false;
140
+ const path = objects(property, SH + 'path')[0];
141
+ if (!path || path.termType !== 'NamedNode' || !tables.covers(path.value)) return false;
142
+ const max = objects(property, SH + 'maxCount')[0];
143
+ if (max && max.value !== '0') return false;
144
+ if (!max && !pkeys.includes(SH + 'or')) return false;
145
+ byPredicate.set(path.value, { shape: shape.value, message: literal(property, SH + 'message') });
146
+ return true;
147
+ });
148
+ if (generated && byPredicate.size > 0) {
149
+ for (const target of targets) {
150
+ const forSource = unqualified.get(target) ?? new Map<string, Replaced>();
151
+ for (const [p, r] of byPredicate) forSource.set(p, r);
152
+ unqualified.set(target, forSource);
153
+ }
154
+ dropped.push(shape);
155
+ }
156
+ }
157
+ }
158
+
159
+ // The dropped shapes and every blank node reachable from them.
160
+ const gone = new Set<string>();
161
+ const key = (t: Term) => `${t.termType}:${t.value}`;
162
+ const stack = [...dropped];
163
+ const accepted = new Set<string>();
164
+ while (stack.length > 0) {
165
+ const node = stack.pop() as Term;
166
+ if (gone.has(key(node))) continue;
167
+ gone.add(key(node));
168
+ for (const q of subjectQuads(node)) {
169
+ if (q.predicate.value === SH + 'class' && q.object.termType === 'NamedNode') accepted.add(q.object.value);
170
+ if (q.object.termType === 'BlankNode') stack.push(q.object);
171
+ }
172
+ }
173
+ const kept = shapes.filter((q) => !gone.has(key(q.subject)));
174
+ const junctions = new Set(
175
+ [...accepted].filter((c) => !WILDCARDS.has(c) && !tables.mentions(c) && !isRelationshipClass(c)),
176
+ );
177
+ return { kept, replacedQuads: shapes.length - kept.length, qualified, unqualified, junctions };
178
+ }
179
+
180
+ /**
181
+ * The violations the replaced shapes would report for `data` (the model, with
182
+ * the class hierarchy — an array, or a store), found by the tables.
183
+ */
184
+ export function checkRelationshipsByTables(
185
+ data: Iterable<Quad>,
186
+ split: TableShapes,
187
+ tables: TablePermissions,
188
+ closure: TypeClosure,
189
+ ): ValidationResult[] {
190
+ if (split.qualified.size === 0 && split.unqualified.size === 0) return [];
191
+ const id = (t: Term) => (t.termType === 'BlankNode' ? `_:${t.value}` : t.value);
192
+ const types = new Map<string, string[]>();
193
+ const sources = new Map<string, Term>();
194
+ const targets = new Map<string, Term>();
195
+ const direct: Quad[] = [];
196
+ for (const q of data) {
197
+ const s = id(q.subject);
198
+ const p = q.predicate.value;
199
+ if (p === RDF_TYPE && q.object.termType === 'NamedNode') {
200
+ const list = types.get(s);
201
+ if (list) list.push(q.object.value);
202
+ else types.set(s, [q.object.value]);
203
+ } else if (p === ARCH_SOURCE) sources.set(s, q.object);
204
+ else if (p === ARCH_TARGET) targets.set(s, q.object);
205
+ else if (tables.covers(p)) direct.push(q);
206
+ }
207
+ const closures = new Map<string, string[]>();
208
+ const closureOf = (t: Term): string[] => {
209
+ const k = id(t);
210
+ let c = closures.get(k);
211
+ if (!c) {
212
+ const set = new Set<string>();
213
+ for (const type of types.get(k) ?? []) for (const sup of closure(type)) set.add(sup);
214
+ c = [...set];
215
+ closures.set(k, c);
216
+ }
217
+ return c;
218
+ };
219
+ const junction = (t: Term) => closureOf(t).some((c) => split.junctions.has(c));
220
+ const permitted = (predicate: string, source: Term, target: Term) =>
221
+ junction(source) || junction(target) || tables.holds(predicate, closureOf(source), closureOf(target)) === true;
222
+
223
+ const results: ValidationResult[] = [];
224
+ const result = (focus: Term, path: string, replaced: Replaced, component: string): ValidationResult => ({
225
+ focusNode: namedNode(focus.value) as unknown as NamedNode,
226
+ resultPath: namedNode(path) as unknown as NamedNode,
227
+ sourceShape: namedNode(replaced.shape) as unknown as NamedNode,
228
+ message: replaced.message,
229
+ severity: 'Violation',
230
+ sourceConstraintComponent: namedNode(SH + component) as unknown as NamedNode,
231
+ });
232
+
233
+ // Qualified relationships: their class (or a superclass) has a replaced shape.
234
+ for (const [s, ownTypes] of types) {
235
+ const shapes = new Map<string, Replaced & { predicate: string }>();
236
+ for (const type of ownTypes) for (const c of closure(type)) {
237
+ const q = split.qualified.get(c);
238
+ if (q) shapes.set(q.shape, q);
239
+ }
240
+ if (shapes.size === 0) continue;
241
+ const source = sources.get(s);
242
+ const target = targets.get(s);
243
+ if (!source || !target) continue; // the shape's pairs pass vacuously without one
244
+ const focus = s.startsWith('_:') ? DataFactory.blankNode(s.slice(2)) : namedNode(s);
245
+ for (const replaced of shapes.values()) {
246
+ if (!permitted(replaced.predicate, source, target)) results.push(result(focus, '', replaced, 'OrConstraintComponent'));
247
+ }
248
+ }
249
+
250
+ // Direct triples: the subject's class (or a superclass) has a replaced shape for the predicate.
251
+ for (const q of direct) {
252
+ const replaced = closureOf(q.subject)
253
+ .map((c) => split.unqualified.get(c)?.get(q.predicate.value))
254
+ .find((r): r is Replaced => !!r);
255
+ if (!replaced) continue;
256
+ if (!permitted(q.predicate.value, q.subject, q.object)) {
257
+ results.push(result(q.subject, q.predicate.value, replaced, 'OrConstraintComponent'));
258
+ }
259
+ }
260
+ return results;
261
+ }
@@ -0,0 +1,28 @@
1
+ /** Tool-neutral RDF mutations. Callers supply command/history policy (KReq 4–5). */
2
+ import {DataFactory,Writer} from 'n3';
3
+ import type {Term,NamedNode} from '@rdfjs/types';
4
+ import type {RdfStore} from '../rdf-engine/interfaces.js';
5
+ import {IRI,nn,triple} from './vocabulary.js';
6
+ import {quadsOf} from './version-history.js';
7
+
8
+ /** Replace this default-graph property with the complete supplied values; other properties and contexts stay. */
9
+ export function replacePropertyValues(store:RdfStore,subject:string,path:string,values:readonly Term[]):void {
10
+ const graph=DataFactory.defaultGraph() as unknown as NamedNode;
11
+ store.removeQuads(store.getQuads(nn(subject),nn(path),null,graph));
12
+ store.addQuads(values.map(value=>triple(nn(subject),nn(path),value)));
13
+ }
14
+
15
+ /** Replace one asserted class without erasing additional types, relationships or placements. */
16
+ export function replaceResourceType(store:RdfStore,subject:string,previous:string,next:string):void {
17
+ store.removeQuads(store.getQuads(nn(subject),nn(IRI.rdfType),nn(previous),DataFactory.defaultGraph() as unknown as NamedNode));
18
+ store.addQuads([triple(nn(subject),nn(IRI.rdfType),nn(next))]);
19
+ }
20
+
21
+ /** Serialize a model diff as the added/removed graph pair; no application identity or submission policy. */
22
+ export function serializeChangeSet(diff:{added:string[];removed:string[]},id:string):string {
23
+ const writer=new Writer({format:'application/trig'});
24
+ for(const [name,lines] of [['added',diff.added],['removed',diff.removed]] as const) {
25
+ for(const q of quadsOf(lines))writer.addQuad(DataFactory.quad(q.subject as never,q.predicate as never,q.object as never,DataFactory.namedNode(`${id}#${name}`)));
26
+ }
27
+ let text='';writer.end((error,result)=>{if(error)throw error;text=result??'';});return text;
28
+ }
@@ -0,0 +1,104 @@
1
+ /** A short, steady name for a string — an IRI in a resource's own IRI: FNV-1a, 32 bits, in hex. */
2
+ export function shortHash(text: string): string {
3
+ let hash = 0x811c9dc5;
4
+ for (let i = 0; i < text.length; i += 1) {
5
+ hash ^= text.charCodeAt(i);
6
+ hash = Math.imul(hash, 0x01000193) >>> 0;
7
+ }
8
+ return hash.toString(16).padStart(8, '0');
9
+ }
10
+
11
+ /**
12
+ * DD-41's digest of a key: the first 20 hex characters of the SHA-256 of its UTF-8 bytes, as the
13
+ * converters' `IriSegment.digest` gives it, and SPARQL's `SUBSTR(SHA256(key), 1, 20)` in meta's derivation
14
+ * rules. So the IRI la-gram mints from a key is the one the rules mint from it: `relationship/` + the digest
15
+ * of "s p o" for a direct triple (`:QualifyRelationships`).
16
+ */
17
+ export function keyDigest(key: string): string {
18
+ return sha256Hex(key).slice(0, 20);
19
+ }
20
+
21
+ /**
22
+ * A part's key as the converters write it before they digest it (`PartIri.encode`): each part as its length, `:`,
23
+ * itself and `;`, and an absent one as `-;`. So no two different keys give one text — `("ab", "c")` and
24
+ * `("a", "bc")`, or a missing value and an empty one.
25
+ */
26
+ export function partKey(...parts: Array<string | undefined>): string {
27
+ return parts.map((p) => (p === undefined ? '-;' : `${p.length}:${p};`)).join('');
28
+ }
29
+
30
+ /** SHA-256's round constants: the first 32 bits of the fractional parts of the cube roots of the first 64 primes. */
31
+ const SHA256_K = new Uint32Array([
32
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
33
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
34
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
35
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
36
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
37
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
38
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
39
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
40
+ ]);
41
+
42
+ /**
43
+ * SHA-256 of a string's UTF-8 bytes, in lower-case hex. A view's Turtle prefix is named by the first 8
44
+ * characters of its IRI's (DD-41), the hash the converters name it by too, and a key's digest by the first
45
+ * 20 ({@link keyDigest}). Synchronous, unlike Web Crypto's, because a save does not wait, nor do the model's
46
+ * repairs on opening.
47
+ */
48
+ export function sha256Hex(text: string): string {
49
+ const bytes = new TextEncoder().encode(text);
50
+ const bitLength = bytes.length * 8;
51
+ const blocks = Math.ceil((bytes.length + 9) / 64);
52
+ const message = new Uint8Array(blocks * 64);
53
+ message.set(bytes);
54
+ message[bytes.length] = 0x80;
55
+ const view = new DataView(message.buffer);
56
+ view.setUint32(message.length - 8, Math.floor(bitLength / 0x100000000));
57
+ view.setUint32(message.length - 4, bitLength >>> 0);
58
+ const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
59
+ const w = new Uint32Array(64);
60
+ const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));
61
+ for (let block = 0; block < blocks; block += 1) {
62
+ for (let i = 0; i < 16; i += 1) w[i] = view.getUint32(block * 64 + i * 4);
63
+ for (let i = 16; i < 64; i += 1) {
64
+ const w15 = w[i - 15]!;
65
+ const w2 = w[i - 2]!;
66
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);
67
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);
68
+ w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) >>> 0;
69
+ }
70
+ let a = h[0]!;
71
+ let b = h[1]!;
72
+ let c = h[2]!;
73
+ let d = h[3]!;
74
+ let e = h[4]!;
75
+ let f = h[5]!;
76
+ let g = h[6]!;
77
+ let hh = h[7]!;
78
+ for (let i = 0; i < 64; i += 1) {
79
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
80
+ const ch = (e & f) ^ (~e & g);
81
+ const temp1 = (hh + s1 + ch + SHA256_K[i]! + w[i]!) >>> 0;
82
+ const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
83
+ const maj = (a & b) ^ (a & c) ^ (b & c);
84
+ const temp2 = (s0 + maj) >>> 0;
85
+ hh = g;
86
+ g = f;
87
+ f = e;
88
+ e = (d + temp1) >>> 0;
89
+ d = c;
90
+ c = b;
91
+ b = a;
92
+ a = (temp1 + temp2) >>> 0;
93
+ }
94
+ h[0] = h[0]! + a;
95
+ h[1] = h[1]! + b;
96
+ h[2] = h[2]! + c;
97
+ h[3] = h[3]! + d;
98
+ h[4] = h[4]! + e;
99
+ h[5] = h[5]! + f;
100
+ h[6] = h[6]! + g;
101
+ h[7] = h[7]! + hh;
102
+ }
103
+ return Array.from(h, (x) => x.toString(16).padStart(8, '0')).join('');
104
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Snapshot lines taken apart: the canonical N-Triples lines {@link snapshotOf}
3
+ * writes (`<s> <p> o .`), read without a parser — the merge (`model-merge.ts`)
4
+ * and the diff by element (`model-diff.ts`) read hundreds of thousands of them.
5
+ *
6
+ * Terms stay as N-Triples text (`<iri>`, `_:b`, a literal with its quotes), so
7
+ * they compare as the lines do; a predicate comes back as its IRI.
8
+ */
9
+
10
+ /** A line taken apart. */
11
+ export interface Line {
12
+ s: string;
13
+ /** The predicate's IRI. */
14
+ p: string;
15
+ o: string;
16
+ /** A literal's language, lower case; `''` for none. */
17
+ lang: string;
18
+ /** The IRIs and blank nodes the object names — itself, or those inside a triple term. */
19
+ refs: readonly string[];
20
+ }
21
+
22
+ /** Take an N-Triples line apart (as `snapshotOf` writes them: `<s> <p> o .`). */
23
+ export function parseLine(line: string): Line {
24
+ const i1 = line.indexOf(' ');
25
+ const i2 = line.indexOf(' ', i1 + 1);
26
+ const s = line.slice(0, i1);
27
+ const p = line.slice(i1 + 2, i2 - 1);
28
+ const o = line.slice(i2 + 1, line.endsWith(' .') ? line.length - 2 : line.length);
29
+ if (o.startsWith('"')) {
30
+ const tail = o.slice(o.lastIndexOf('"') + 1);
31
+ return { s, p, o, lang: tail.startsWith('@') ? tail.slice(1).toLowerCase() : '', refs: [] };
32
+ }
33
+ return { s, p, o, lang: '', refs: o.startsWith('<<') ? nodesIn(o) : [o] };
34
+ }
35
+
36
+ /** The IRIs and blank nodes in a triple term, its literals' contents and datatypes skipped. */
37
+ export function nodesIn(text: string): string[] {
38
+ const out: string[] = [];
39
+ for (let i = 0; i < text.length; i++) {
40
+ if (text.startsWith('<<(', i)) {
41
+ i += 2;
42
+ } else if (text[i] === '"') {
43
+ for (i++; i < text.length && text[i] !== '"'; i++) if (text[i] === '\\') i++;
44
+ if (text.startsWith('^^<', i + 1)) i = text.indexOf('>', i + 3);
45
+ } else if (text[i] === '<') {
46
+ const end = text.indexOf('>', i);
47
+ out.push(text.slice(i, end + 1));
48
+ i = end;
49
+ } else if (text.startsWith('_:', i)) {
50
+ let end = i + 2;
51
+ while (end < text.length && !/[\s)]/.test(text[end])) end++;
52
+ out.push(text.slice(i, end));
53
+ i = end - 1;
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+
59
+ /** A line's subject, as N-Triples. */
60
+ export function subjectOf(line: string): string {
61
+ return line.slice(0, line.indexOf(' '));
62
+ }
63
+
64
+ /** A line's predicate, as an IRI. */
65
+ export function predicateOf(line: string): string {
66
+ const i1 = line.indexOf(' ');
67
+ return line.slice(i1 + 2, line.indexOf(' ', i1 + 1) - 1);
68
+ }
69
+
70
+ /** `<iri>` → the IRI; a blank node stays `_:label`. */
71
+ export function iriOf(term: string): string {
72
+ return term.startsWith('<') ? term.slice(1, -1) : term;
73
+ }
74
+
75
+ /** An IRI (or `_:label`) as an N-Triples term. */
76
+ export function termText(iriOrBlank: string): string {
77
+ return iriOrBlank.startsWith('_:') ? iriOrBlank : `<${iriOrBlank}>`;
78
+ }
79
+
80
+ /** A literal's text, unescaped; `undefined` for a term that is not a literal. */
81
+ export function literalValue(term: string): string | undefined {
82
+ if (!term.startsWith('"')) return undefined;
83
+ const body = term.slice(1, term.lastIndexOf('"'));
84
+ return body.replace(/\\(u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)/g, (_m, c: string) => {
85
+ if (c.length > 1) return String.fromCodePoint(parseInt(c.slice(1), 16));
86
+ return ({ n: '\n', r: '\r', t: '\t', b: '\b', f: '\f' } as Record<string, string>)[c] ?? c;
87
+ });
88
+ }