@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,549 @@
1
+ /**
2
+ * Custom properties: a name and a value that no vocabulary declares, kept as the Linked.Archi converters keep one
3
+ * (KReq 4.10, KD-12). The concept has a `schema:PropertyValue` through `schema:additionalProperty`, with a
4
+ * `schema:name` and a `schema:value`, both plain text:
5
+ *
6
+ * ```turtle
7
+ * m:web-shop schema:additionalProperty <…/web-shop/property/{digest}> .
8
+ * <…/web-shop/property/{digest}> a schema:PropertyValue ;
9
+ * schema:name "Cost center" ;
10
+ * schema:value "4711" .
11
+ * ```
12
+ *
13
+ * The pair is a part of its concept and is named as the converters' `PartIri.propertyValue` names it:
14
+ * `{concept}/property/{digest}`. The digest is DD-41's ({@link keyDigest}) of the concept, `property`, and what the
15
+ * pair says — its `schema:propertyID`, name, value and description — each written as its length, `:`, itself and `;`,
16
+ * and an absent one as `-;`. So a pair added for a name and a value is the resource a converter writes for them on
17
+ * the same concept. An edited value, or a new name, keeps the pair's IRI, as a part is never renamed. A new pair whose
18
+ * IRI an edited one already holds is named by a UUID instead.
19
+ *
20
+ * A custom property can be made a property of its own — `dcterms:creator`, or `m:costCenter` — and a property's values
21
+ * custom properties again, on one concept or across the model (KReq 4.12, KD-15): {@link customPropertyConversion},
22
+ * {@link customPropertyFromProperty}.
23
+ */
24
+
25
+ import { DataFactory } from 'n3';
26
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
27
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
28
+ import { partIri, uuid } from '../rdf-engine/iri.js';
29
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
30
+ import { keyDigest, partKey } from './short-hash.js';
31
+ import { T, nn, triple } from './vocabulary.js';
32
+
33
+ /** The predicate a concept has its custom properties through. */
34
+ export const CUSTOM_PROPERTY = NAMESPACES.schema + 'additionalProperty';
35
+ /** The class of a custom property's pair. */
36
+ export const PROPERTY_VALUE = NAMESPACES.schema + 'PropertyValue';
37
+ /** A pair's name, its value and the source's identifier for its property. */
38
+ export const PAIR_NAME = NAMESPACES.schema + 'name';
39
+ export const PAIR_VALUE = NAMESPACES.schema + 'value';
40
+ export const PAIR_PROPERTY_ID = NAMESPACES.schema + 'propertyID';
41
+
42
+ const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
43
+ const XSD_STRING = NAMESPACES.xsd + 'string';
44
+
45
+ /** A custom property of a concept. */
46
+ export interface CustomProperty {
47
+ /** The pair's IRI. */
48
+ iri: string;
49
+ /** Its `schema:name`; empty when it has none. */
50
+ name: string;
51
+ /** Its `schema:value` as text; empty when it has none. */
52
+ value: string;
53
+ /** The value's language, when it has one. */
54
+ language?: string;
55
+ /** The value's datatype, when it is not a plain string. */
56
+ datatype?: string;
57
+ /** Its `schema:propertyID`, when the source gave one. */
58
+ propertyId?: string;
59
+ }
60
+
61
+ /**
62
+ * The IRI the converters give a pair on `owner` that says these things: `{owner}/property/{digest}`
63
+ * (`PartIri.propertyValue`).
64
+ */
65
+ export function customPropertyIri(owner: string, name?: string, value?: string, propertyId?: string, description?: string): string {
66
+ return partIri(owner, 'property', keyDigest(partKey(owner, 'property', propertyId, name, value, description)));
67
+ }
68
+
69
+ function modelObjects(store: RdfStore, subject: string, predicate: string): Term[] {
70
+ return store.getQuads(nn(subject), nn(predicate), null, MODEL_GRAPH).map((q) => q.object);
71
+ }
72
+
73
+ /** A concept's custom properties, by name and then by value. */
74
+ export function customPropertiesOf(store: RdfStore, owner: string): CustomProperty[] {
75
+ const found: CustomProperty[] = [];
76
+ for (const pair of modelObjects(store, owner, CUSTOM_PROPERTY)) {
77
+ // Model data has no blank nodes (KReq 4.5), and a literal is no pair.
78
+ if (pair.termType !== 'NamedNode') continue;
79
+ const name = modelObjects(store, pair.value, PAIR_NAME)[0];
80
+ const value = modelObjects(store, pair.value, PAIR_VALUE)[0];
81
+ const id = modelObjects(store, pair.value, PAIR_PROPERTY_ID)[0];
82
+ const language = value?.termType === 'Literal' ? (value as { language?: string }).language || undefined : undefined;
83
+ const written = value?.termType === 'Literal' && !language ? (value as { datatype?: { value: string } }).datatype?.value : undefined;
84
+ found.push({
85
+ iri: pair.value,
86
+ name: name?.value ?? '',
87
+ value: value?.value ?? '',
88
+ ...(language ? { language } : {}),
89
+ ...(written && written !== XSD_STRING ? { datatype: written } : {}),
90
+ ...(id ? { propertyId: id.value } : {}),
91
+ });
92
+ }
93
+ return found.sort((a, b) => a.name.localeCompare(b.name) || a.value.localeCompare(b.value));
94
+ }
95
+
96
+ /**
97
+ * The quads that give `owner` the custom property `name` with `value`, as plain text — and, from a source that
98
+ * identifies its properties (an ArchiMate exchange file's `propertyDefinitionRef`), its `schema:propertyID`: none
99
+ * when it has that pair already. A name or a value the source lacks is left out, as the converters leave it out. Its
100
+ * IRI is the converters' ({@link customPropertyIri}), unless that names another pair now — an edited one — when it is
101
+ * `{owner}/property/{uuid}`.
102
+ */
103
+ export function customPropertyQuads(
104
+ store: RdfStore,
105
+ owner: string,
106
+ name: string | undefined,
107
+ value: string | undefined,
108
+ propertyId?: string,
109
+ ): Quad[] {
110
+ let iri = customPropertyIri(owner, name, value, propertyId);
111
+ if (store.getQuads(nn(iri), null, null, MODEL_GRAPH).length > 0) {
112
+ const says = (predicate: string, text: string | undefined) => {
113
+ const objects = modelObjects(store, iri, predicate);
114
+ return text === undefined ? objects.length === 0 : objects.some((o) => o.value === text);
115
+ };
116
+ const same = says(PAIR_NAME, name) && says(PAIR_VALUE, value) && says(PAIR_PROPERTY_ID, propertyId);
117
+ const linked = modelObjects(store, owner, CUSTOM_PROPERTY).some((p) => p.value === iri);
118
+ if (same) return linked ? [] : [triple(nn(owner), nn(CUSTOM_PROPERTY), nn(iri))];
119
+ iri = partIri(owner, 'property', uuid());
120
+ }
121
+ const pair = nn(iri);
122
+ const text = (predicate: string, literal: string | undefined) =>
123
+ literal === undefined ? [] : [triple(pair, nn(predicate), DataFactory.literal(literal) as unknown as Term)];
124
+ return [
125
+ triple(nn(owner), nn(CUSTOM_PROPERTY), pair),
126
+ triple(pair, T.rdfType, nn(PROPERTY_VALUE)),
127
+ ...text(PAIR_PROPERTY_ID, propertyId),
128
+ ...text(PAIR_NAME, name),
129
+ ...text(PAIR_VALUE, value),
130
+ ];
131
+ }
132
+
133
+ /** Give `owner` the custom property `name` with `value` ({@link customPropertyQuads}); the pair's IRI. */
134
+ export function addCustomProperty(store: RdfStore, owner: string, name: string | undefined, value: string | undefined, propertyId?: string): string {
135
+ const quads = customPropertyQuads(store, owner, name, value, propertyId);
136
+ store.addQuads(quads);
137
+ return quads[0]?.object.value ?? customPropertyIri(owner, name, value, propertyId);
138
+ }
139
+
140
+ /** Replace a pair's value with `value`, as plain text; its IRI stays. */
141
+ export function setCustomPropertyValue(store: RdfStore, pairIri: string, value: string): void {
142
+ const stale = store.getQuads(nn(pairIri), nn(PAIR_VALUE), null, MODEL_GRAPH);
143
+ if (stale.length > 0) store.removeQuads(stale);
144
+ store.addQuads([triple(nn(pairIri), nn(PAIR_VALUE), DataFactory.literal(value) as unknown as Term)]);
145
+ }
146
+
147
+ /** The quads a rename takes away and adds ({@link customPropertyRename}). */
148
+ export interface CustomPropertyRename {
149
+ removed: Quad[];
150
+ added: Quad[];
151
+ }
152
+
153
+ /**
154
+ * The change that renames `owner`'s custom property `name` — each of its pairs by that name, `''` for those without
155
+ * one — `to`, as plain text (KReq 4.11, KD-12): a pair's `schema:name` replaced and its IRI kept, as a value edited
156
+ * keeps it. A pair something else links to as well stays as it is for that, and `owner` has a copy of it by the new
157
+ * name instead, named as {@link customPropertyQuads} names a pair. A pair that would then say what another of
158
+ * `owner`'s says — the same name and the same value — is taken away: the concept has it once. Nothing when `to`,
159
+ * trimmed, is empty or is `name`.
160
+ */
161
+ export function customPropertyRename(store: RdfStore, owner: string, name: string, to: string): CustomPropertyRename {
162
+ return renameChange(store, [owner], name, to);
163
+ }
164
+
165
+ /** Rename `owner`'s custom property `name` `to` ({@link customPropertyRename}). */
166
+ export function renameCustomProperty(store: RdfStore, owner: string, name: string, to: string): void {
167
+ apply(store, customPropertyRename(store, owner, name, to));
168
+ }
169
+
170
+ /**
171
+ * Everything in the model with a custom property `name` (`''`, a pair without a name): its elements, relationships
172
+ * and views, and the model itself, sorted by IRI.
173
+ */
174
+ export function customPropertyOwners(store: RdfStore, name: string): string[] {
175
+ const owners = new Set<string>();
176
+ for (const link of store.getQuads(null, nn(CUSTOM_PROPERTY), null, MODEL_GRAPH)) {
177
+ if (link.object.termType !== 'NamedNode') continue;
178
+ if ((modelObjects(store, link.object.value, PAIR_NAME)[0]?.value ?? '') === name) owners.add(link.subject.value);
179
+ }
180
+ return [...owners].sort();
181
+ }
182
+
183
+ /**
184
+ * The change that renames the custom property `name` `to` across the model (KReq 4.11): on everything that has it
185
+ * ({@link customPropertyOwners}), as {@link customPropertyRename} renames it on one. A pair several of them share is
186
+ * renamed once, for all of them; only something outside them that links to it — not as a custom property — keeps it
187
+ * as it is.
188
+ */
189
+ export function customPropertyRenameInModel(store: RdfStore, name: string, to: string): CustomPropertyRename {
190
+ return renameChange(store, customPropertyOwners(store, name), name, to);
191
+ }
192
+
193
+ /** Rename the custom property `name` `to` across the model ({@link customPropertyRenameInModel}). */
194
+ export function renameCustomPropertyInModel(store: RdfStore, name: string, to: string): void {
195
+ apply(store, customPropertyRenameInModel(store, name, to));
196
+ }
197
+
198
+ function apply(store: RdfStore, { removed, added }: CustomPropertyRename): void {
199
+ if (removed.length > 0) store.removeQuads(removed);
200
+ if (added.length > 0) store.addQuads(added);
201
+ }
202
+
203
+ /**
204
+ * What a property takes, for a custom property's values written as its own (KReq 4.12, KD-15): as a consumer reads it
205
+ * from the property's shape for the concept's type, else from its vocabulary.
206
+ */
207
+ export interface ConversionTarget {
208
+ /** Its values are resources: a value that is an absolute IRI (`https://…`, `urn:…`) is written as one. */
209
+ links?: boolean;
210
+ /** Its datatype (`xsd:decimal`): a value is written of it when it is one of the datatype's ({@link fitsDatatype}). */
211
+ datatype?: string;
212
+ /** The values it takes one of (`sh:in`): a value is the one it is, or names — by value or label, in any case. */
213
+ choices?: ReadonlyArray<{ value: string; label?: string; isIri?: boolean }>;
214
+ /** The language text with none is written in (documentation text in English); none, plain text. */
215
+ language?: string;
216
+ }
217
+
218
+ /** A conversion of a custom property ({@link customPropertyConversion}): the change, and the values it leaves. */
219
+ export interface CustomPropertyConversion extends CustomPropertyRename {
220
+ /**
221
+ * The values that stay custom properties, as the property does not take them — `abc` for a number, a value not in its
222
+ * list, a pair without a value — each by its concept and its pair.
223
+ */
224
+ kept: Array<{ owner: string; pair: string; value: string }>;
225
+ }
226
+
227
+ /**
228
+ * The change that makes `owner`'s custom property `name` — each of its pairs by that name — the property `predicate`
229
+ * (KReq 4.12, KD-15): each value written as `predicate`'s, as `target` says it takes one, and the pair taken away —
230
+ * unless something else links to it, when only the concept's link goes. A value it does not take stays a custom
231
+ * property (`kept`). A value the concept has by `predicate` already is not added twice. Nothing for
232
+ * `schema:additionalProperty` or RDF's own.
233
+ */
234
+ export function customPropertyConversion(
235
+ store: RdfStore,
236
+ owner: string,
237
+ name: string,
238
+ predicate: string,
239
+ target: ConversionTarget = {},
240
+ ): CustomPropertyConversion {
241
+ return conversionChange(store, [owner], name, predicate, target);
242
+ }
243
+
244
+ /** The same across the model: on everything that has the custom property `name` ({@link customPropertyOwners}). */
245
+ export function customPropertyConversionInModel(
246
+ store: RdfStore,
247
+ name: string,
248
+ predicate: string,
249
+ target: ConversionTarget = {},
250
+ ): CustomPropertyConversion {
251
+ return conversionChange(store, customPropertyOwners(store, name), name, predicate, target);
252
+ }
253
+
254
+ /** Make `owner`'s custom property `name` the property `predicate` ({@link customPropertyConversion}); the values kept. */
255
+ export function convertCustomProperty(
256
+ store: RdfStore,
257
+ owner: string,
258
+ name: string,
259
+ predicate: string,
260
+ target: ConversionTarget = {},
261
+ ): CustomPropertyConversion['kept'] {
262
+ const change = customPropertyConversion(store, owner, name, predicate, target);
263
+ apply(store, change);
264
+ return change.kept;
265
+ }
266
+
267
+ /** Make the custom property `name` the property `predicate` across the model ({@link customPropertyConversionInModel}). */
268
+ export function convertCustomPropertyInModel(
269
+ store: RdfStore,
270
+ name: string,
271
+ predicate: string,
272
+ target: ConversionTarget = {},
273
+ ): CustomPropertyConversion['kept'] {
274
+ const change = customPropertyConversionInModel(store, name, predicate, target);
275
+ apply(store, change);
276
+ return change.kept;
277
+ }
278
+
279
+ /**
280
+ * Everything in the model with a value of `predicate`: its elements, relationships and views, and the model itself,
281
+ * sorted by IRI — not a custom property's pair, a provenance record (`prov:` types) or a part of a diagram
282
+ * (`arch-vis:` types), whose statements are no concept's properties.
283
+ */
284
+ export function propertyOwners(store: RdfStore, predicate: string): string[] {
285
+ const owners = new Set<string>();
286
+ for (const q of store.getQuads(null, nn(predicate), null, MODEL_GRAPH)) {
287
+ if (q.subject.termType === 'NamedNode' && isConcept(store, q.subject.value)) owners.add(q.subject.value);
288
+ }
289
+ return [...owners].sort();
290
+ }
291
+
292
+ /**
293
+ * The change that makes `owner`'s values of `predicate` its custom property `name` (KReq 4.12, KD-15): each value a pair,
294
+ * named as {@link customPropertyQuads} names one, the value as written — text with its language or datatype, and a
295
+ * link its address, as text — and the statement taken away. A value the concept has by that name already is not had
296
+ * twice. Nothing when `name`, trimmed, is empty, or for `schema:additionalProperty` or RDF's own.
297
+ */
298
+ export function customPropertyFromProperty(store: RdfStore, owner: string, predicate: string, name: string): CustomPropertyRename {
299
+ return fromPropertyChange(store, [owner], predicate, name);
300
+ }
301
+
302
+ /** The same across the model: on everything that has a value of `predicate` ({@link propertyOwners}). */
303
+ export function customPropertyFromPropertyInModel(store: RdfStore, predicate: string, name: string): CustomPropertyRename {
304
+ return fromPropertyChange(store, propertyOwners(store, predicate), predicate, name);
305
+ }
306
+
307
+ /** Make `owner`'s values of `predicate` its custom property `name` ({@link customPropertyFromProperty}). */
308
+ export function makeCustomProperty(store: RdfStore, owner: string, predicate: string, name: string): void {
309
+ apply(store, customPropertyFromProperty(store, owner, predicate, name));
310
+ }
311
+
312
+ /** Make the values of `predicate` the custom property `name` across the model ({@link customPropertyFromPropertyInModel}). */
313
+ export function makeCustomPropertyInModel(store: RdfStore, predicate: string, name: string): void {
314
+ apply(store, customPropertyFromPropertyInModel(store, predicate, name));
315
+ }
316
+
317
+ /** Whether a property can be converted to or from: not the custom properties' own link, nor RDF's (`rdf:type`). */
318
+ function convertible(predicate: string): boolean {
319
+ return Boolean(predicate) && predicate !== CUSTOM_PROPERTY && !predicate.startsWith(NAMESPACES.rdf);
320
+ }
321
+
322
+ /** Whether `iri` is a concept of the model — typed, and no pair, provenance record or diagram part. */
323
+ function isConcept(store: RdfStore, iri: string): boolean {
324
+ const types = modelObjects(store, iri, T.rdfType.value);
325
+ const notConcepts = [NAMESPACES.prov, NAMESPACES['arch-vis']];
326
+ return types.length > 0 && !types.some((t) => t.value === PROPERTY_VALUE || notConcepts.some((ns) => t.value.startsWith(ns)));
327
+ }
328
+
329
+ /** What a value says, as a pair has it: its text, its language, its datatype unless a plain string. */
330
+ function saysOf(value: string, language?: string, datatype?: string): string {
331
+ return JSON.stringify([value, language ?? '', datatype && datatype !== XSD_STRING ? datatype : '']);
332
+ }
333
+
334
+ /** Whether two terms are the same: kind, text, language and datatype. */
335
+ function sameTerm(a: Term, b: Term): boolean {
336
+ const lit = (t: Term) => (t.termType === 'Literal' ? `${(t as { language?: string }).language ?? ''}^${(t as { datatype?: { value: string } }).datatype?.value ?? ''}` : '');
337
+ return a.termType === b.termType && a.value === b.value && lit(a) === lit(b);
338
+ }
339
+
340
+ const RDF_LANG_STRING = NAMESPACES.rdf + 'langString';
341
+ /** An absolute IRI as typed: a scheme and `//`, or a URN. */
342
+ const ABSOLUTE_IRI = /^(?:[A-Za-z][A-Za-z0-9+.-]*:\/\/\S+|urn:\S+:\S+)$/i;
343
+
344
+ /** A custom property's value as the property `target` describes takes it; `undefined`, one it does not take. */
345
+ function convertedTerm(p: CustomProperty, target: ConversionTarget): Term | undefined {
346
+ const text = p.value;
347
+ if (text === '') return undefined;
348
+ const typed = (value: string, datatype?: string) =>
349
+ (datatype ? DataFactory.literal(value, DataFactory.namedNode(datatype)) : DataFactory.literal(value)) as unknown as Term;
350
+ const datatype = target.datatype && target.datatype !== XSD_STRING && target.datatype !== RDF_LANG_STRING ? target.datatype : undefined;
351
+ if (target.choices) {
352
+ const wanted = text.trim().toLowerCase();
353
+ const choice = target.choices.find((c) => c.value.toLowerCase() === wanted || c.label?.trim().toLowerCase() === wanted);
354
+ if (!choice) return undefined;
355
+ return choice.isIri ? nn(choice.value) : typed(choice.value, datatype);
356
+ }
357
+ if (target.links && !p.language && !p.datatype && ABSOLUTE_IRI.test(text.trim())) return nn(text.trim());
358
+ if (datatype) return fitsDatatype(text.trim(), datatype) ? typed(text.trim(), datatype) : undefined;
359
+ // Text: in its own language, else of its own datatype, else in the language given — text in a language needs one.
360
+ const language = p.language ?? (p.datatype ? undefined : target.language || undefined);
361
+ if (language) return DataFactory.literal(text, language) as unknown as Term;
362
+ if (target.datatype === RDF_LANG_STRING) return undefined;
363
+ return typed(text, p.datatype);
364
+ }
365
+
366
+ /** The conversion of `name` on `owners` to `predicate`, each pair once ({@link customPropertyConversion}). */
367
+ function conversionChange(
368
+ store: RdfStore,
369
+ owners: readonly string[],
370
+ name: string,
371
+ predicate: string,
372
+ target: ConversionTarget,
373
+ ): CustomPropertyConversion {
374
+ const change: CustomPropertyConversion = { removed: [], added: [], kept: [] };
375
+ if (!convertible(predicate)) return change;
376
+ const converted = new Set(owners);
377
+ const gone = new Set<string>();
378
+ const added: Array<{ owner: string; term: Term }> = [];
379
+ for (const owner of owners) {
380
+ const has = store.getQuads(nn(owner), nn(predicate), null, MODEL_GRAPH).map((q) => q.object);
381
+ for (const p of customPropertiesOf(store, owner).filter((p) => p.name === name)) {
382
+ const term = convertedTerm(p, target);
383
+ if (!term) {
384
+ change.kept.push({ owner, pair: p.iri, value: p.value });
385
+ continue;
386
+ }
387
+ const pair = nn(p.iri);
388
+ change.removed.push(...store.getQuads(nn(owner), nn(CUSTOM_PROPERTY), pair, MODEL_GRAPH));
389
+ if (!has.some((o) => sameTerm(o, term)) && !added.some((a) => a.owner === owner && sameTerm(a.term, term))) {
390
+ added.push({ owner, term });
391
+ change.added.push(triple(nn(owner), nn(predicate), term));
392
+ }
393
+ // The pair goes once — unless something besides the concepts converted links to it.
394
+ const elsewhere = store.getQuads(null, null, pair, MODEL_GRAPH).some((q) => !converted.has(q.subject.value));
395
+ if (!elsewhere && !gone.has(p.iri)) {
396
+ gone.add(p.iri);
397
+ change.removed.push(...store.getQuads(pair, null, null, MODEL_GRAPH));
398
+ }
399
+ }
400
+ }
401
+ return change;
402
+ }
403
+
404
+ /** The custom property `name` made of `predicate`'s values on `owners` ({@link customPropertyFromProperty}). */
405
+ function fromPropertyChange(store: RdfStore, owners: readonly string[], predicate: string, name: string): CustomPropertyRename {
406
+ const target = name.trim();
407
+ const change: CustomPropertyRename = { removed: [], added: [] };
408
+ if (!target || !convertible(predicate)) return change;
409
+ const minted = new Set<string>();
410
+ for (const owner of owners) {
411
+ const held = new Set(customPropertiesOf(store, owner).filter((p) => p.name === target).map((p) => saysOf(p.value, p.language, p.datatype)));
412
+ for (const q of store.getQuads(nn(owner), nn(predicate), null, MODEL_GRAPH)) {
413
+ if (q.object.termType !== 'NamedNode' && q.object.termType !== 'Literal') continue;
414
+ change.removed.push(q);
415
+ // A link's address, as text; a literal as written.
416
+ const value = q.object.termType === 'NamedNode' ? (DataFactory.literal(q.object.value) as unknown as Term) : q.object;
417
+ const language = (value as { language?: string }).language || undefined;
418
+ const datatype = language ? undefined : (value as { datatype?: { value: string } }).datatype?.value;
419
+ const says = saysOf(value.value, language, datatype);
420
+ if (held.has(says)) continue;
421
+ held.add(says);
422
+ let iri = customPropertyIri(owner, target, value.value);
423
+ if (minted.has(iri) || store.getQuads(nn(iri), null, null, MODEL_GRAPH).length > 0) iri = partIri(owner, 'property', uuid());
424
+ minted.add(iri);
425
+ const pair = nn(iri);
426
+ change.added.push(
427
+ triple(nn(owner), nn(CUSTOM_PROPERTY), pair),
428
+ triple(pair, T.rdfType, nn(PROPERTY_VALUE)),
429
+ triple(pair, nn(PAIR_NAME), DataFactory.literal(target) as unknown as Term),
430
+ triple(pair, nn(PAIR_VALUE), value),
431
+ );
432
+ }
433
+ }
434
+ return change;
435
+ }
436
+
437
+ const INTEGER = /^[+-]?\d+$/;
438
+ const ZONE = '(?:Z|[+-]\\d{2}:\\d{2})?';
439
+ /** The lexical forms of the XSD datatypes la-gram's fields write, and those like them. */
440
+ const LEXICAL: Record<string, RegExp> = {
441
+ integer: INTEGER,
442
+ long: INTEGER,
443
+ int: INTEGER,
444
+ short: INTEGER,
445
+ byte: INTEGER,
446
+ nonNegativeInteger: /^\+?\d+$|^-0+$/,
447
+ unsignedLong: /^\+?\d+$/,
448
+ unsignedInt: /^\+?\d+$/,
449
+ unsignedShort: /^\+?\d+$/,
450
+ unsignedByte: /^\+?\d+$/,
451
+ positiveInteger: /^\+?0*[1-9]\d*$/,
452
+ nonPositiveInteger: /^-\d+$|^[+-]?0+$/,
453
+ negativeInteger: /^-0*[1-9]\d*$/,
454
+ decimal: /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/,
455
+ double: /^(?:[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|[+-]?INF|NaN)$/,
456
+ float: /^(?:[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|[+-]?INF|NaN)$/,
457
+ boolean: /^(?:true|false|1|0)$/,
458
+ date: new RegExp(`^-?\\d{4,}-\\d{2}-\\d{2}${ZONE}$`),
459
+ dateTime: new RegExp(`^-?\\d{4,}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?${ZONE}$`),
460
+ time: new RegExp(`^\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?${ZONE}$`),
461
+ gYear: new RegExp(`^-?\\d{4,}${ZONE}$`),
462
+ gYearMonth: new RegExp(`^-?\\d{4,}-\\d{2}${ZONE}$`),
463
+ anyURI: /^\S*$/,
464
+ };
465
+
466
+ /**
467
+ * Whether `text` is written as a value of the XSD `datatype` is (`300` an `xsd:decimal`, `2026-11-29` an `xsd:date`):
468
+ * by its lexical form, not its range — `300` is taken as an `xsd:byte` too. A datatype other than these is taken as
469
+ * fitting, to be judged by validation.
470
+ */
471
+ export function fitsDatatype(text: string, datatype: string): boolean {
472
+ if (!datatype.startsWith(NAMESPACES.xsd)) return true;
473
+ const form = LEXICAL[datatype.slice(NAMESPACES.xsd.length)];
474
+ return form ? form.test(text) : true;
475
+ }
476
+
477
+ /**
478
+ * The rename of `name` `to` on `owners`, each pair once: for each owner, its pairs by the name are kept — renamed — or,
479
+ * saying what one it has by the new name says, dropped. A pair kept is renamed where it is unless something other
480
+ * than the owners links to it, when each owner keeping it has a copy instead; a pair every owner drops goes, unless
481
+ * something else links to it, when only the owners' links go.
482
+ */
483
+ function renameChange(store: RdfStore, owners: readonly string[], name: string, to: string): CustomPropertyRename {
484
+ const target = to.trim();
485
+ const change: CustomPropertyRename = { removed: [], added: [] };
486
+ if (!target || target === name) return change;
487
+ // What a pair says, besides its name: its value, as written.
488
+ const says = (p: CustomProperty) => JSON.stringify([p.value, p.language ?? '', p.datatype ?? '']);
489
+ const pairs = new Map<string, { property: CustomProperty; keep: string[]; drop: string[] }>();
490
+ for (const owner of owners) {
491
+ const own = customPropertiesOf(store, owner);
492
+ const held = new Set(own.filter((p) => p.name === target).map(says));
493
+ for (const p of own.filter((p) => p.name === name)) {
494
+ const entry = pairs.get(p.iri) ?? { property: p, keep: [], drop: [] };
495
+ pairs.set(p.iri, entry);
496
+ if (held.has(says(p))) entry.drop.push(owner);
497
+ else {
498
+ held.add(says(p));
499
+ entry.keep.push(owner);
500
+ }
501
+ }
502
+ }
503
+ const renamed = new Set(owners);
504
+ const named = (pair: NamedNode) => triple(pair, nn(PAIR_NAME), DataFactory.literal(target) as unknown as Term);
505
+ const links = (owner: string, pair: NamedNode) => store.getQuads(nn(owner), nn(CUSTOM_PROPERTY), pair, MODEL_GRAPH);
506
+ for (const [iri, { property: p, keep, drop }] of pairs) {
507
+ const pair = nn(iri);
508
+ const elsewhere = store.getQuads(null, null, pair, MODEL_GRAPH).some((q) => !renamed.has(q.subject.value));
509
+ for (const owner of drop) change.removed.push(...links(owner, pair));
510
+ if (keep.length === 0) {
511
+ if (!elsewhere) change.removed.push(...store.getQuads(pair, null, null, MODEL_GRAPH));
512
+ continue;
513
+ }
514
+ if (!elsewhere) {
515
+ change.removed.push(...store.getQuads(pair, nn(PAIR_NAME), null, MODEL_GRAPH));
516
+ change.added.push(named(pair));
517
+ continue;
518
+ }
519
+ for (const owner of keep) {
520
+ let copy = customPropertyIri(owner, target, p.value, p.propertyId);
521
+ if (store.getQuads(nn(copy), null, null, MODEL_GRAPH).length > 0) copy = partIri(owner, 'property', uuid());
522
+ change.removed.push(...links(owner, pair));
523
+ change.added.push(triple(nn(owner), nn(CUSTOM_PROPERTY), nn(copy)));
524
+ for (const q of store.getQuads(pair, null, null, MODEL_GRAPH)) {
525
+ if (q.predicate.value !== PAIR_NAME) change.added.push(triple(nn(copy), q.predicate, q.object));
526
+ }
527
+ change.added.push(named(nn(copy)));
528
+ }
529
+ }
530
+ return change;
531
+ }
532
+
533
+ /**
534
+ * Exactly the quads {@link removeCustomProperty} removes: `owner`'s link to the pair, and the pair itself unless
535
+ * something else links to it as well.
536
+ */
537
+ export function collectCustomProperty(store: RdfStore, owner: string, pairIri: string): Quad[] {
538
+ const pair = nn(pairIri);
539
+ const links = store.getQuads(nn(owner), nn(CUSTOM_PROPERTY), pair, MODEL_GRAPH);
540
+ if (links.length === 0) return [];
541
+ const shared = store.getQuads(null, null, pair, MODEL_GRAPH).some((q) => q.subject.value !== owner);
542
+ return shared ? links : [...links, ...store.getQuads(pair, null, null, MODEL_GRAPH)];
543
+ }
544
+
545
+ /** Take a custom property from `owner` ({@link collectCustomProperty}). */
546
+ export function removeCustomProperty(store: RdfStore, owner: string, pairIri: string): void {
547
+ const quads = collectCustomProperty(store, owner, pairIri);
548
+ if (quads.length > 0) store.removeQuads(quads);
549
+ }