@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.
- package/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +102 -2
- package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
- package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
- package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
- package/assets/arch-decision/arch-decision-tax.ttl +129 -0
- package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
- package/assets/arch-processes/arch-processes-tax.ttl +136 -0
- package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
- package/assets/arch-processes/archProcesses.ttl +953 -0
- package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
- package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
- package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
- package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
- package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
- package/assets/archimate3/archimate3.2-principle-shapes.ttl +917 -0
- package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
- package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
- package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
- package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
- package/assets/archimate3/archimate3.2-tax.ttl +724 -0
- package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
- package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
- package/assets/archimate3/icons/and-junction.svg +3 -0
- package/assets/archimate3/icons/application-collaboration.svg +22 -0
- package/assets/archimate3/icons/application-component.svg +18 -0
- package/assets/archimate3/icons/application-event.svg +15 -0
- package/assets/archimate3/icons/application-function.svg +14 -0
- package/assets/archimate3/icons/application-interaction.svg +17 -0
- package/assets/archimate3/icons/application-interface.svg +16 -0
- package/assets/archimate3/icons/application-process.svg +14 -0
- package/assets/archimate3/icons/application-service.svg +14 -0
- package/assets/archimate3/icons/artifact.svg +16 -0
- package/assets/archimate3/icons/assessment.svg +17 -0
- package/assets/archimate3/icons/business-actor.svg +22 -0
- package/assets/archimate3/icons/business-collaboration.svg +21 -0
- package/assets/archimate3/icons/business-event.svg +15 -0
- package/assets/archimate3/icons/business-function.svg +14 -0
- package/assets/archimate3/icons/business-interaction.svg +18 -0
- package/assets/archimate3/icons/business-interface.svg +16 -0
- package/assets/archimate3/icons/business-object.svg +14 -0
- package/assets/archimate3/icons/business-process.svg +15 -0
- package/assets/archimate3/icons/business-role.svg +16 -0
- package/assets/archimate3/icons/business-service.svg +14 -0
- package/assets/archimate3/icons/capability.svg +40 -0
- package/assets/archimate3/icons/communication-network.svg +18 -0
- package/assets/archimate3/icons/constraint.svg +18 -0
- package/assets/archimate3/icons/contract.svg +13 -0
- package/assets/archimate3/icons/course-of-action.svg +20 -0
- package/assets/archimate3/icons/data-object.svg +14 -0
- package/assets/archimate3/icons/deliverable.svg +11 -0
- package/assets/archimate3/icons/device.svg +18 -0
- package/assets/archimate3/icons/distribution-network.svg +19 -0
- package/assets/archimate3/icons/driver.svg +24 -0
- package/assets/archimate3/icons/equipment.svg +31 -0
- package/assets/archimate3/icons/facility.svg +16 -0
- package/assets/archimate3/icons/gap.svg +22 -0
- package/assets/archimate3/icons/glyphs/activity.svg +3 -0
- package/assets/archimate3/icons/glyphs/actor.svg +14 -0
- package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate3/icons/glyphs/capability.svg +32 -0
- package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate3/icons/glyphs/contract.svg +5 -0
- package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate3/icons/glyphs/device.svg +10 -0
- package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate3/icons/glyphs/driver.svg +16 -0
- package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate3/icons/glyphs/event.svg +6 -0
- package/assets/archimate3/icons/glyphs/facility.svg +7 -0
- package/assets/archimate3/icons/glyphs/function.svg +6 -0
- package/assets/archimate3/icons/glyphs/gap.svg +14 -0
- package/assets/archimate3/icons/glyphs/goal.svg +10 -0
- package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate3/icons/glyphs/interface.svg +8 -0
- package/assets/archimate3/icons/glyphs/location.svg +6 -0
- package/assets/archimate3/icons/glyphs/material.svg +12 -0
- package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate3/icons/glyphs/node.svg +8 -0
- package/assets/archimate3/icons/glyphs/object.svg +4 -0
- package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate3/icons/glyphs/path.svg +10 -0
- package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate3/icons/glyphs/principle.svg +12 -0
- package/assets/archimate3/icons/glyphs/process.svg +6 -0
- package/assets/archimate3/icons/glyphs/product.svg +4 -0
- package/assets/archimate3/icons/glyphs/representation.svg +4 -0
- package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate3/icons/glyphs/resource.svg +14 -0
- package/assets/archimate3/icons/glyphs/role.svg +6 -0
- package/assets/archimate3/icons/glyphs/service.svg +6 -0
- package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate3/icons/glyphs/value.svg +3 -0
- package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate3/icons/goal.svg +18 -0
- package/assets/archimate3/icons/grouping.svg +12 -0
- package/assets/archimate3/icons/implementation-event.svg +15 -0
- package/assets/archimate3/icons/location.svg +14 -0
- package/assets/archimate3/icons/material.svg +21 -0
- package/assets/archimate3/icons/meaning.svg +11 -0
- package/assets/archimate3/icons/node.svg +14 -0
- package/assets/archimate3/icons/or-junction.svg +3 -0
- package/assets/archimate3/icons/outcome.svg +25 -0
- package/assets/archimate3/icons/path.svg +18 -0
- package/assets/archimate3/icons/plateau.svg +16 -0
- package/assets/archimate3/icons/principle.svg +21 -0
- package/assets/archimate3/icons/product.svg +12 -0
- package/assets/archimate3/icons/representation.svg +12 -0
- package/assets/archimate3/icons/requirement.svg +14 -0
- package/assets/archimate3/icons/resource.svg +23 -0
- package/assets/archimate3/icons/stakeholder.svg +15 -0
- package/assets/archimate3/icons/system-software.svg +22 -0
- package/assets/archimate3/icons/technology-collaboration.svg +22 -0
- package/assets/archimate3/icons/technology-event.svg +15 -0
- package/assets/archimate3/icons/technology-function.svg +14 -0
- package/assets/archimate3/icons/technology-interaction.svg +18 -0
- package/assets/archimate3/icons/technology-interface.svg +16 -0
- package/assets/archimate3/icons/technology-process.svg +14 -0
- package/assets/archimate3/icons/technology-service.svg +14 -0
- package/assets/archimate3/icons/value-stream.svg +11 -0
- package/assets/archimate3/icons/value.svg +11 -0
- package/assets/archimate3/icons/work-package.svg +12 -0
- package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
- package/assets/archimate4/archimate4-metamodel.ttl +179 -0
- package/assets/archimate4/archimate4-notation.ttl +1147 -0
- package/assets/archimate4/archimate4-onto.ttl +1559 -0
- package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
- package/assets/archimate4/archimate4-principle-shapes.ttl +895 -0
- package/assets/archimate4/archimate4-questions.ttl +1224 -0
- package/assets/archimate4/archimate4-reference-data.ttl +56 -0
- package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
- package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
- package/assets/archimate4/archimate4-tax.ttl +749 -0
- package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
- package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
- package/assets/archimate4/icons/and-junction.svg +3 -0
- package/assets/archimate4/icons/application-component.svg +18 -0
- package/assets/archimate4/icons/application-interface.svg +16 -0
- package/assets/archimate4/icons/artifact.svg +16 -0
- package/assets/archimate4/icons/assessment.svg +17 -0
- package/assets/archimate4/icons/business-actor.svg +22 -0
- package/assets/archimate4/icons/business-interface.svg +16 -0
- package/assets/archimate4/icons/business-object.svg +14 -0
- package/assets/archimate4/icons/capability.svg +40 -0
- package/assets/archimate4/icons/collaboration.svg +21 -0
- package/assets/archimate4/icons/communication-network.svg +18 -0
- package/assets/archimate4/icons/course-of-action.svg +20 -0
- package/assets/archimate4/icons/data-object.svg +14 -0
- package/assets/archimate4/icons/deliverable.svg +11 -0
- package/assets/archimate4/icons/device.svg +18 -0
- package/assets/archimate4/icons/distribution-network.svg +19 -0
- package/assets/archimate4/icons/driver.svg +24 -0
- package/assets/archimate4/icons/equipment.svg +31 -0
- package/assets/archimate4/icons/event.svg +15 -0
- package/assets/archimate4/icons/facility.svg +16 -0
- package/assets/archimate4/icons/function.svg +13 -0
- package/assets/archimate4/icons/glyphs/activity.svg +3 -0
- package/assets/archimate4/icons/glyphs/actor.svg +14 -0
- package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate4/icons/glyphs/capability.svg +32 -0
- package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate4/icons/glyphs/contract.svg +5 -0
- package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate4/icons/glyphs/device.svg +10 -0
- package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate4/icons/glyphs/driver.svg +16 -0
- package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate4/icons/glyphs/event.svg +6 -0
- package/assets/archimate4/icons/glyphs/facility.svg +7 -0
- package/assets/archimate4/icons/glyphs/function.svg +6 -0
- package/assets/archimate4/icons/glyphs/gap.svg +14 -0
- package/assets/archimate4/icons/glyphs/goal.svg +10 -0
- package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate4/icons/glyphs/interface.svg +8 -0
- package/assets/archimate4/icons/glyphs/location.svg +6 -0
- package/assets/archimate4/icons/glyphs/material.svg +12 -0
- package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate4/icons/glyphs/node.svg +8 -0
- package/assets/archimate4/icons/glyphs/object.svg +4 -0
- package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate4/icons/glyphs/path.svg +10 -0
- package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate4/icons/glyphs/principle.svg +12 -0
- package/assets/archimate4/icons/glyphs/process.svg +6 -0
- package/assets/archimate4/icons/glyphs/product.svg +4 -0
- package/assets/archimate4/icons/glyphs/representation.svg +4 -0
- package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate4/icons/glyphs/resource.svg +14 -0
- package/assets/archimate4/icons/glyphs/role.svg +6 -0
- package/assets/archimate4/icons/glyphs/service.svg +6 -0
- package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate4/icons/glyphs/value.svg +3 -0
- package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate4/icons/goal.svg +18 -0
- package/assets/archimate4/icons/grouping.svg +12 -0
- package/assets/archimate4/icons/location.svg +14 -0
- package/assets/archimate4/icons/material.svg +21 -0
- package/assets/archimate4/icons/meaning.svg +11 -0
- package/assets/archimate4/icons/node.svg +14 -0
- package/assets/archimate4/icons/or-junction.svg +3 -0
- package/assets/archimate4/icons/outcome.svg +25 -0
- package/assets/archimate4/icons/path.svg +18 -0
- package/assets/archimate4/icons/plateau.svg +16 -0
- package/assets/archimate4/icons/principle.svg +21 -0
- package/assets/archimate4/icons/process.svg +15 -0
- package/assets/archimate4/icons/product.svg +12 -0
- package/assets/archimate4/icons/requirement.svg +14 -0
- package/assets/archimate4/icons/resource.svg +23 -0
- package/assets/archimate4/icons/role.svg +16 -0
- package/assets/archimate4/icons/service.svg +13 -0
- package/assets/archimate4/icons/stakeholder.svg +15 -0
- package/assets/archimate4/icons/system-software.svg +22 -0
- package/assets/archimate4/icons/technology-interface.svg +16 -0
- package/assets/archimate4/icons/value-stream.svg +11 -0
- package/assets/archimate4/icons/value.svg +11 -0
- package/assets/archimate4/icons/work-package.svg +12 -0
- package/assets/basic/basic-metamodel.ttl +100 -0
- package/assets/basic/basic-notation-bubble.ttl +175 -0
- package/assets/basic/basic-notation.ttl +172 -0
- package/assets/basic/basic-onto.ttl +171 -0
- package/assets/basic/basic-presentation-contexts.ttl +70 -0
- package/assets/basic/basic-tax.ttl +130 -0
- package/assets/basic/icons/aggregation.svg +7 -0
- package/assets/basic/icons/association.svg +6 -0
- package/assets/basic/icons/element.svg +5 -0
- package/assets/basic/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/icons/glyphs/association.svg +5 -0
- package/assets/basic/icons/glyphs/element.svg +5 -0
- package/assets/basic/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/icons/relationship.svg +7 -0
- package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
- package/assets/basic/notation-bubble/icons/association.svg +6 -0
- package/assets/basic/notation-bubble/icons/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
- package/assets/catalog.ttl +7406 -0
- package/assets/core/core-notation.ttl +131 -0
- package/assets/core/core-onto.ttl +2811 -0
- package/assets/core/core-questions.ttl +957 -0
- package/assets/core/core-shapes.ttl +915 -0
- package/assets/core/core-vis-onto.ttl +1408 -0
- package/assets/core/core-vis-shapes.ttl +851 -0
- package/assets/core-vis/markers/circle-dot.svg +3 -0
- package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
- package/assets/core-vis/markers/filled-diamond.svg +3 -0
- package/assets/core-vis/markers/half-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-diamond.svg +3 -0
- package/assets/core-vis/markers/open-arrowhead.svg +3 -0
- package/fixtures/interoperability/archimate4-demo.trig +259 -0
- package/fixtures/interoperability/expected-findings.json +26 -0
- package/fixtures/interoperability/shop-seed.ttl +225 -0
- package/package.json +136 -4
- package/scripts/sync-assets.mjs +252 -0
- package/src/conformance.ts +66 -0
- package/src/import-export/model-io.ts +426 -0
- package/src/index.ts +11 -0
- package/src/metamodel-manager/asset-sources.ts +754 -0
- package/src/metamodel-manager/bundled-assets.ts +599 -0
- package/src/metamodel-manager/catalogue.ts +114 -0
- package/src/metamodel-manager/class-hierarchy.ts +155 -0
- package/src/metamodel-manager/index.ts +65 -0
- package/src/metamodel-manager/interfaces.ts +422 -0
- package/src/metamodel-manager/metamodel-completeness.ts +162 -0
- package/src/metamodel-manager/metamodel-loader.ts +864 -0
- package/src/metamodel-manager/notation-resolver.ts +284 -0
- package/src/metamodel-manager/notation.ts +659 -0
- package/src/metamodel-manager/palette-generator.ts +882 -0
- package/src/metamodel-manager/property-shapes.ts +290 -0
- package/src/metamodel-manager/taxonomy.ts +904 -0
- package/src/metamodel-manager/type-guide.ts +241 -0
- package/src/metamodel-manager/viewpoint-manager.ts +147 -0
- package/src/model-manager/appearance.ts +389 -0
- package/src/model-manager/cascade.ts +246 -0
- package/src/model-manager/clipboard.ts +566 -0
- package/src/model-manager/context-names.ts +108 -0
- package/src/model-manager/custom-properties.ts +549 -0
- package/src/model-manager/derivations.ts +166 -0
- package/src/model-manager/direct-permissions.ts +182 -0
- package/src/model-manager/drawing-order.ts +119 -0
- package/src/model-manager/element-manager.ts +69 -0
- package/src/model-manager/element-pictures.ts +118 -0
- package/src/model-manager/field-names.ts +42 -0
- package/src/model-manager/folders.ts +354 -0
- package/src/model-manager/grid.ts +6 -0
- package/src/model-manager/index.ts +43 -0
- package/src/model-manager/interfaces.ts +417 -0
- package/src/model-manager/iri-conformance.ts +183 -0
- package/src/model-manager/label-expression.ts +233 -0
- package/src/model-manager/legacy-migration.ts +200 -0
- package/src/model-manager/missing-references.ts +86 -0
- package/src/model-manager/model-diff-text.ts +150 -0
- package/src/model-manager/model-diff.ts +534 -0
- package/src/model-manager/model-merge.ts +1160 -0
- package/src/model-manager/model-namespace.ts +199 -0
- package/src/model-manager/model-operations.ts +132 -0
- package/src/model-manager/model-queries.ts +616 -0
- package/src/model-manager/model-session.ts +759 -0
- package/src/model-manager/multiplicity.ts +74 -0
- package/src/model-manager/nested-resources.ts +145 -0
- package/src/model-manager/own-metamodel.ts +157 -0
- package/src/model-manager/placement-copy.ts +116 -0
- package/src/model-manager/property-catalog.ts +787 -0
- package/src/model-manager/proposal-order.ts +203 -0
- package/src/model-manager/provenance.ts +396 -0
- package/src/model-manager/questions.ts +475 -0
- package/src/model-manager/rdf-scope.ts +97 -0
- package/src/model-manager/relationship-graph.ts +462 -0
- package/src/model-manager/relationship-manager.ts +962 -0
- package/src/model-manager/relationship-table.ts +189 -0
- package/src/model-manager/relationship-validity.ts +261 -0
- package/src/model-manager/resource-edits.ts +28 -0
- package/src/model-manager/short-hash.ts +104 -0
- package/src/model-manager/snapshot-lines.ts +88 -0
- package/src/model-manager/version-history.ts +205 -0
- package/src/model-manager/view-from-results.ts +81 -0
- package/src/model-manager/view-manager.ts +1410 -0
- package/src/model-manager/vocabulary.ts +279 -0
- package/src/rdf-engine/finding-shape.ts +23 -0
- package/src/rdf-engine/graph-scope.ts +163 -0
- package/src/rdf-engine/index.ts +7 -0
- package/src/rdf-engine/interfaces.ts +144 -0
- package/src/rdf-engine/iri.ts +203 -0
- package/src/rdf-engine/localized-text.ts +13 -0
- package/src/rdf-engine/namespaces.ts +41 -0
- package/src/rdf-engine/native-load.ts +37 -0
- package/src/rdf-engine/observable-store.ts +609 -0
- package/src/rdf-engine/rdf-store.ts +520 -0
- package/src/rdf-engine/shacl-validator.ts +602 -0
- package/src/rdf-engine/shape-reach.ts +140 -0
- package/src/rdf-engine/shape-switches.ts +165 -0
- package/src/rdf-engine/single-valued.ts +219 -0
- package/src/rdf-engine/sparql-constraints.ts +349 -0
- package/src/rdf-engine/term-codec.ts +51 -0
- package/src/rdf-engine/ttl-parser.ts +51 -0
- package/src/rdf-engine/ttl-serializer.ts +79 -0
- package/src/rdf-engine/turtle-writer.ts +284 -0
- package/src/rdf-engine/validation-engine.ts +747 -0
- package/src/rdf-engine/validation-service.ts +186 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An {@link RdfStore} that reports, and can record, every change to the model.
|
|
3
|
+
*
|
|
4
|
+
* Two things in the application need to know exactly which triples an
|
|
5
|
+
* operation changed:
|
|
6
|
+
*
|
|
7
|
+
* - **Undo/redo.** A canvas command runs a model operation once, records the
|
|
8
|
+
* quads it actually added and removed, and from then on undo applies the
|
|
9
|
+
* inverse and redo re-applies the same diff — never re-running the operation,
|
|
10
|
+
* which would mint new IRIs and break everything that points at the old ones.
|
|
11
|
+
* - **Collaboration.** The CRDT binding forwards each local change to the
|
|
12
|
+
* shared document and applies remote changes with a different origin, so it
|
|
13
|
+
* does not echo them back.
|
|
14
|
+
*
|
|
15
|
+
* Only the default graph — the model — is observed. Metamodel graphs are loaded
|
|
16
|
+
* and dropped wholesale by the metamodel loader and are nobody's edit.
|
|
17
|
+
*
|
|
18
|
+
* A diff records only effective changes: adding a quad that is already there,
|
|
19
|
+
* or removing one that is not, is not part of it, so its inverse never deletes
|
|
20
|
+
* a triple the operation did not create. And it records them as the store holds
|
|
21
|
+
* them, which for a typed literal may not be as they were added.
|
|
22
|
+
*
|
|
23
|
+
* It also keeps a copy of the model graph in JavaScript (Task 22): a read of the
|
|
24
|
+
* model — the model whole, or a pattern in the default graph — is answered from
|
|
25
|
+
* it, without a crossing into Oxigraph's WebAssembly and a conversion of every
|
|
26
|
+
* quad back. The inner store keeps the metamodels, and the model for SPARQL
|
|
27
|
+
* alone (KD-28): it is given the model when a SPARQL query, an update, a bulk
|
|
28
|
+
* load into the model or the store's size asks for it, in one native load from
|
|
29
|
+
* the copy. Until then a write of the model reaches the copy only, its terms
|
|
30
|
+
* checked at once as the inner store would check them — but for a small write
|
|
31
|
+
* once the inner store holds the model, which reaches both, so that SPARQL after
|
|
32
|
+
* an edit does not wait for the model again. While the inner store is behind, a
|
|
33
|
+
* read of every graph is the copy's model and the inner store's named graphs.
|
|
34
|
+
*
|
|
35
|
+
* And it lets a local edit be stamped inside itself (`setStamper`, the provenance of edits): once at the end of
|
|
36
|
+
* each outermost write — a {@link record}, a {@link batch}, or a write outside both — what the local edit
|
|
37
|
+
* changed is given to the stamper, whose own writes join the edit, its undo step and its notification. Undo,
|
|
38
|
+
* redo ({@link applyDiff}), a collaborator's changes (another origin) and what runs {@link withoutStamps} are
|
|
39
|
+
* not stamped.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { DataFactory, Store as N3Store } from 'n3';
|
|
43
|
+
import type { NamedNode, Quad } from '@rdfjs/types';
|
|
44
|
+
import type { RdfStore, SparqlResult } from './interfaces.js';
|
|
45
|
+
import { nTriples, splitForNativeLoad } from './native-load.js';
|
|
46
|
+
|
|
47
|
+
/** Quads an operation added and removed, in the default graph. */
|
|
48
|
+
export interface RdfDiff {
|
|
49
|
+
added: Quad[];
|
|
50
|
+
removed: Quad[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function appendDiff(target: RdfDiff, added: readonly Quad[], removed: readonly Quad[]): void {
|
|
54
|
+
// A load or undo can contain enough quads to exceed the function argument limit (KReq 1.6).
|
|
55
|
+
for (const quad of added) target.added.push(quad);
|
|
56
|
+
for (const quad of removed) target.removed.push(quad);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Who made a change: the local user, a remote collaborator, a file load… */
|
|
60
|
+
export type ChangeOrigin = 'local' | 'remote' | 'load' | 'undo' | 'redo' | (string & {});
|
|
61
|
+
|
|
62
|
+
/** A batch of effective changes to the model. */
|
|
63
|
+
export interface StoreChange extends RdfDiff {
|
|
64
|
+
origin: ChangeOrigin;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Listener for {@link ObservableRdfStore.subscribe}. */
|
|
68
|
+
export type StoreChangeListener = (change: StoreChange) => void;
|
|
69
|
+
|
|
70
|
+
const DEFAULT_GRAPH = DataFactory.defaultGraph();
|
|
71
|
+
/**
|
|
72
|
+
* A write of the model this large leaves the inner store behind, to be given the model whole when SPARQL asks,
|
|
73
|
+
* rather than being written into it quad by quad (KD-28).
|
|
74
|
+
*/
|
|
75
|
+
const LARGE_WRITE = 5000;
|
|
76
|
+
/** Subject and predicate of the quad a literal pattern is put in its held form through. */
|
|
77
|
+
const SCRATCH = DataFactory.namedNode('urn:la-gram:pattern');
|
|
78
|
+
|
|
79
|
+
/** Whether a quad is in the default graph (the model). */
|
|
80
|
+
function inDefaultGraph(q: Quad): boolean {
|
|
81
|
+
return q.graph.termType === 'DefaultGraph';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* An update that drops or clears one named graph, and nothing else: `DROP SILENT GRAPH <…>`, `CLEAR GRAPH <…>`. Never
|
|
86
|
+
* the default graph, which `DEFAULT`, `ALL` and `NAMED` name, and never one of several operations.
|
|
87
|
+
*/
|
|
88
|
+
const NAMED_GRAPH_DROP = /^\s*(?:DROP|CLEAR)\s+(?:SILENT\s+)?GRAPH\s+<[^<>"{}|^`\\\s]*>\s*;?\s*$/i;
|
|
89
|
+
|
|
90
|
+
/** Wraps a store and observes its default graph. */
|
|
91
|
+
export class ObservableRdfStore implements RdfStore {
|
|
92
|
+
private listeners = new Set<StoreChangeListener>();
|
|
93
|
+
private writeListeners = new Set<(diff: RdfDiff) => void>();
|
|
94
|
+
private recording: RdfDiff[] = [];
|
|
95
|
+
private origin: ChangeOrigin = 'local';
|
|
96
|
+
/** Changes made inside {@link batch}, delivered once at the end. */
|
|
97
|
+
private pending: RdfDiff | null = null;
|
|
98
|
+
/** The model graph, as the inner store holds it. */
|
|
99
|
+
private model = new N3Store();
|
|
100
|
+
/** Whether the inner store holds an earlier state of the model, or none of it, and is to be given the copy (KD-28). */
|
|
101
|
+
private stale = false;
|
|
102
|
+
/** What stamps a local edit; none, nothing is stamped. */
|
|
103
|
+
private stamper: ((diff: RdfDiff) => void) | null = null;
|
|
104
|
+
/** The local edit not yet stamped. */
|
|
105
|
+
private unstamped: RdfDiff = { added: [], removed: [] };
|
|
106
|
+
/** Open {@link record} and {@link batch} scopes. */
|
|
107
|
+
private depth = 0;
|
|
108
|
+
private stamping = false;
|
|
109
|
+
/** Open {@link withoutStamps} scopes. */
|
|
110
|
+
private stampsOff = 0;
|
|
111
|
+
|
|
112
|
+
constructor(readonly inner: RdfStore & { has?(q: Quad): boolean }) {
|
|
113
|
+
this.model.addQuads(this.defaultGraph() as never);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** End a host-owned session, including pending WASM writes (workspace Req 1.5). */
|
|
117
|
+
dispose(): void {
|
|
118
|
+
this.stale = false; this.listeners.clear(); this.writeListeners.clear(); this.stamper = null;
|
|
119
|
+
this.model = new N3Store();
|
|
120
|
+
(this.inner as RdfStore & { dispose?(): void }).dispose?.();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── Observation ────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
/** Be told about every effective change to the model. Returns an unsubscribe. */
|
|
126
|
+
subscribe(listener: StoreChangeListener): () => void {
|
|
127
|
+
this.listeners.add(listener);
|
|
128
|
+
return () => this.listeners.delete(listener);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Be told of each write to the model as it is made — inside a {@link batch}
|
|
133
|
+
* too, where {@link subscribe}rs hear only at its end — for a cache of what
|
|
134
|
+
* was read from the store, which must not outlive it. Returns an unsubscribe.
|
|
135
|
+
*/
|
|
136
|
+
onEveryWrite(listener: (diff: RdfDiff) => void): () => void {
|
|
137
|
+
this.writeListeners.add(listener);
|
|
138
|
+
return () => this.writeListeners.delete(listener);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Run `fn` and return what it changed. Nested recordings each see their own
|
|
143
|
+
* changes and their callers' recordings see them too.
|
|
144
|
+
*/
|
|
145
|
+
record<T>(fn: () => T): { result: T } & RdfDiff {
|
|
146
|
+
const diff: RdfDiff = { added: [], removed: [] };
|
|
147
|
+
this.recording.push(diff);
|
|
148
|
+
try {
|
|
149
|
+
const result = this.scope(fn);
|
|
150
|
+
return { result, ...diff };
|
|
151
|
+
} finally {
|
|
152
|
+
this.recording.splice(this.recording.indexOf(diff), 1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* What stamps a local edit (`model-manager/provenance.ts`): given what the edit changed, once at its end,
|
|
158
|
+
* while it is still being recorded and batched.
|
|
159
|
+
*/
|
|
160
|
+
setStamper(stamper: ((diff: RdfDiff) => void) | null): void {
|
|
161
|
+
this.stamper = stamper;
|
|
162
|
+
this.unstamped = { added: [], removed: [] };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Run `fn`, writing the model in many small steps — an import — to the copy alone: the inner store is given it
|
|
167
|
+
* when SPARQL next asks, in one native load, instead of quad by quad as it is written (KD-28). Reads, diffs and
|
|
168
|
+
* notifications are as ever.
|
|
169
|
+
*/
|
|
170
|
+
inBulk<T>(fn: () => T): T {
|
|
171
|
+
if (!this.inner.check) return fn();
|
|
172
|
+
this.bulk++;
|
|
173
|
+
try {
|
|
174
|
+
return fn();
|
|
175
|
+
} finally {
|
|
176
|
+
this.bulk--;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Open {@link inBulk} scopes. */
|
|
181
|
+
private bulk = 0;
|
|
182
|
+
|
|
183
|
+
/** Run `fn` without stamping what it changes: opening, merging, restoring — no edit of the user's. */
|
|
184
|
+
withoutStamps<T>(fn: () => T): T {
|
|
185
|
+
this.stampsOff++;
|
|
186
|
+
try {
|
|
187
|
+
return fn();
|
|
188
|
+
} finally {
|
|
189
|
+
this.stampsOff--;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A write scope: the outermost stamps the local edit before it closes. */
|
|
194
|
+
private scope<T>(fn: () => T): T {
|
|
195
|
+
this.depth++;
|
|
196
|
+
try {
|
|
197
|
+
const result = fn();
|
|
198
|
+
if (this.depth === 1) this.stamp();
|
|
199
|
+
return result;
|
|
200
|
+
} finally {
|
|
201
|
+
this.depth--;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Give the stamper the local edit not yet stamped; its writes are not stamped again. */
|
|
206
|
+
private stamp(): void {
|
|
207
|
+
if (!this.stamper || this.stamping) return;
|
|
208
|
+
const diff = this.unstamped;
|
|
209
|
+
if (diff.added.length === 0 && diff.removed.length === 0) return;
|
|
210
|
+
this.unstamped = { added: [], removed: [] };
|
|
211
|
+
this.stamping = true;
|
|
212
|
+
try {
|
|
213
|
+
this.stamper(diff);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
console.warn('[la-gram] Recording the provenance of an edit failed', err);
|
|
216
|
+
} finally {
|
|
217
|
+
this.stamping = false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Run `fn` with changes attributed to `origin` (e.g. `remote`). */
|
|
222
|
+
withOrigin<T>(origin: ChangeOrigin, fn: () => T): T {
|
|
223
|
+
const previous = this.origin;
|
|
224
|
+
this.origin = origin;
|
|
225
|
+
try {
|
|
226
|
+
return fn();
|
|
227
|
+
} finally {
|
|
228
|
+
this.origin = previous;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Run `fn` and notify listeners once, with everything it changed, instead of
|
|
234
|
+
* once per `addQuads`/`removeQuads` call. Nested batches fold into the outer.
|
|
235
|
+
*/
|
|
236
|
+
batch<T>(fn: () => T): T {
|
|
237
|
+
if (this.pending) return this.scope(fn);
|
|
238
|
+
this.pending = { added: [], removed: [] };
|
|
239
|
+
try {
|
|
240
|
+
return this.scope(fn);
|
|
241
|
+
} finally {
|
|
242
|
+
const change = this.pending;
|
|
243
|
+
this.pending = null;
|
|
244
|
+
if (change.added.length > 0 || change.removed.length > 0) this.notify(change);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Apply a recorded diff, or its inverse. */
|
|
249
|
+
applyDiff(diff: RdfDiff, inverse = false): void {
|
|
250
|
+
// A diff replayed — undo, redo — is no new edit: its stamps, if it had any, are in it.
|
|
251
|
+
this.withoutStamps(() => this.batch(() => {
|
|
252
|
+
const [remove, add] = inverse ? [diff.added, diff.removed] : [diff.removed, diff.added];
|
|
253
|
+
if (remove.length > 0) this.removeQuads(remove);
|
|
254
|
+
if (add.length > 0) this.addQuads(add);
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ── RdfStore ───────────────────────────────────────────────────────────
|
|
259
|
+
|
|
260
|
+
addQuads(quads: Quad[]): void {
|
|
261
|
+
const named = quads.filter((q) => !inDefaultGraph(q));
|
|
262
|
+
if (named.length > 0) {
|
|
263
|
+
this.namedChanged();
|
|
264
|
+
this.inner.addQuads(named);
|
|
265
|
+
}
|
|
266
|
+
// What the model did not have: n3 says whether a quad was new as it adds it.
|
|
267
|
+
const added = this.held(quads.filter(inDefaultGraph)).filter((q) => this.model.addQuad(q as never));
|
|
268
|
+
if (added.length === 0) return;
|
|
269
|
+
try {
|
|
270
|
+
if (this.inner.check && (this.stale || this.bulk > 0 || added.length >= LARGE_WRITE)) {
|
|
271
|
+
// Refused now, as adding them would be; given to the inner store with the rest of the model when SPARQL asks.
|
|
272
|
+
this.inner.check(added);
|
|
273
|
+
this.stale = true;
|
|
274
|
+
} else {
|
|
275
|
+
this.inner.addQuads(added);
|
|
276
|
+
}
|
|
277
|
+
} catch (err) {
|
|
278
|
+
// What the inner store refused is not the model's.
|
|
279
|
+
for (const q of added) if (!this.innerHas(q)) this.model.removeQuad(q as never);
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
this.track(added, []);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
removeQuads(quads: Quad[]): void {
|
|
286
|
+
const named = quads.filter((q) => !inDefaultGraph(q));
|
|
287
|
+
if (named.length > 0) {
|
|
288
|
+
this.namedChanged();
|
|
289
|
+
this.inner.removeQuads(named);
|
|
290
|
+
}
|
|
291
|
+
const removed = this.held(quads.filter(inDefaultGraph)).filter((q) => this.model.removeQuad(q as never));
|
|
292
|
+
if (removed.length === 0) return;
|
|
293
|
+
try {
|
|
294
|
+
const large = removed.length >= LARGE_WRITE || this.bulk > 0;
|
|
295
|
+
if (this.model.size === 0 && (this.stale || large) && this.inner.update) {
|
|
296
|
+
// The whole model removed — as opening another does: cleared in the
|
|
297
|
+
// inner store in one go, not converted into it quad by quad to be
|
|
298
|
+
// deleted (3.8 s for 347 000); the inner store and the copy agree again.
|
|
299
|
+
this.inner.update('CLEAR SILENT DEFAULT');
|
|
300
|
+
this.stale = false;
|
|
301
|
+
} else if (!this.stale) {
|
|
302
|
+
if (large && this.inner.check) this.stale = true;
|
|
303
|
+
else this.inner.removeQuads(removed);
|
|
304
|
+
}
|
|
305
|
+
// Behind, the inner store is given the copy, without these, when SPARQL asks.
|
|
306
|
+
} catch (err) {
|
|
307
|
+
for (const q of removed) if (this.innerHas(q)) this.model.addQuad(q as never);
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
this.track([], removed);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
getQuads(
|
|
314
|
+
subject?: NamedNode | null,
|
|
315
|
+
predicate?: NamedNode | null,
|
|
316
|
+
object?: NamedNode | null,
|
|
317
|
+
graph?: NamedNode | null,
|
|
318
|
+
): Quad[] {
|
|
319
|
+
const termType = (term: unknown) => (term as { termType?: string } | null | undefined)?.termType;
|
|
320
|
+
// A literal asked for, in the form held: the inner store matches any of its
|
|
321
|
+
// forms (`"010"^^xsd:int` finds `"10"^^xsd:integer`), and so must the copy.
|
|
322
|
+
const pattern = termType(object) === 'Literal' ? this.heldTerm(object as unknown as Quad['object']) : object;
|
|
323
|
+
// The model, from the copy.
|
|
324
|
+
if (termType(graph) === 'DefaultGraph') {
|
|
325
|
+
return this.model.getQuads(subject ?? null, predicate ?? null, (pattern ?? null) as never, DEFAULT_GRAPH) as unknown as Quad[];
|
|
326
|
+
}
|
|
327
|
+
// Everything: the model from the copy, the inner store's named graphs one by one.
|
|
328
|
+
if (!subject && !predicate && !object && !graph && this.inner.namedGraphs) {
|
|
329
|
+
const quads = this.model.getQuads(null, null, null, DEFAULT_GRAPH) as unknown as Quad[];
|
|
330
|
+
for (const named of this.namedGraphs()) {
|
|
331
|
+
for (const q of this.inner.getQuads(null, null, null, named)) quads.push(q);
|
|
332
|
+
}
|
|
333
|
+
return quads;
|
|
334
|
+
}
|
|
335
|
+
// One named graph; or every graph, once the inner store has the whole model.
|
|
336
|
+
if (graph || !this.behind) return this.inner.getQuads(subject, predicate, object, graph);
|
|
337
|
+
// Every graph while the inner store is being given the model: the model
|
|
338
|
+
// from the copy, the rest from the inner store.
|
|
339
|
+
const quads = this.model.getQuads(subject ?? null, predicate ?? null, (pattern ?? null) as never, DEFAULT_GRAPH) as unknown as Quad[];
|
|
340
|
+
for (const q of this.inner.getQuads(subject, predicate, object, null)) if (!inDefaultGraph(q)) quads.push(q);
|
|
341
|
+
return quads;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** How many quads the model has. */
|
|
345
|
+
modelSize(): number {
|
|
346
|
+
return this.model.size;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** The model graph, to read from without a copy — never to write to. */
|
|
350
|
+
modelGraph(): N3Store {
|
|
351
|
+
return this.model;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* The named graphs — the metamodels' documents — as last listed, until one
|
|
356
|
+
* is written to: listing them was a scan of every metamodel quad, asked for
|
|
357
|
+
* at every relationship lookup (Task 22).
|
|
358
|
+
*/
|
|
359
|
+
namedGraphs(): NamedNode[] {
|
|
360
|
+
if (!this.namedList) this.namedList = this.inner.namedGraphs?.() ?? [];
|
|
361
|
+
return this.namedList;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private namedList: NamedNode[] | undefined;
|
|
365
|
+
|
|
366
|
+
/** A named graph may have been written to: its list is to be read again. */
|
|
367
|
+
private namedChanged(): void {
|
|
368
|
+
this.namedList = undefined;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Every quad of the named graphs: the metamodels. */
|
|
372
|
+
namedGraphQuads(): Quad[] {
|
|
373
|
+
const quads: Quad[] = [];
|
|
374
|
+
const graphs = this.inner.namedGraphs ? this.namedGraphs() : [];
|
|
375
|
+
for (const graph of graphs) for (const q of this.inner.getQuads(null, null, null, graph)) quads.push(q);
|
|
376
|
+
if (!this.inner.namedGraphs) for (const q of this.inner.getQuads()) if (!inDefaultGraph(q)) quads.push(q);
|
|
377
|
+
return quads;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** SPARQL over everything — the model the inner store is still to be given, given first. */
|
|
381
|
+
query(sparql: string): SparqlResult {
|
|
382
|
+
this.giveAll();
|
|
383
|
+
return this.inner.query(sparql);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* SPARQL about the metamodels — viewpoints, relationship tables, the class
|
|
388
|
+
* hierarchy, the model questions — which reads the default graph only for
|
|
389
|
+
* metamodel data put there. It does not give the inner store the model: until
|
|
390
|
+
* SPARQL over the model asks, it may hold none of it, or an earlier state
|
|
391
|
+
* (Task 22, KD-28).
|
|
392
|
+
*/
|
|
393
|
+
queryMetamodels(sparql: string): SparqlResult {
|
|
394
|
+
return this.inner.query(sparql);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* SPARQL Update is diffed by reading the default graph after it against the
|
|
399
|
+
* copy — the only way to know what an arbitrary update touched. But for one
|
|
400
|
+
* that drops or clears a named graph alone — a metamodel's document
|
|
401
|
+
* unloaded — which cannot touch the model: reading the model back cost about
|
|
402
|
+
* 3 s a document with a model of 347 000 triples, and unloading a metamodel
|
|
403
|
+
* of ten documents held the page for 34 s (the kernel's KD-23).
|
|
404
|
+
*/
|
|
405
|
+
update(sparqlUpdate: string): void {
|
|
406
|
+
if (NAMED_GRAPH_DROP.test(sparqlUpdate)) {
|
|
407
|
+
this.namedChanged();
|
|
408
|
+
this.inner.update(sparqlUpdate);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
this.giveAll();
|
|
412
|
+
this.namedChanged();
|
|
413
|
+
this.guarded(() => this.inner.update(sparqlUpdate));
|
|
414
|
+
const { added, removed } = this.resync();
|
|
415
|
+
this.track(added, removed);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
load(data: string, options: { format: string; graph?: string; baseIri?: string }): number {
|
|
419
|
+
if (!this.inner.load) throw new Error('The underlying store cannot bulk-load');
|
|
420
|
+
// Bulk loads target metamodel graphs; into the default graph they are rare
|
|
421
|
+
// and are reported as one change computed by snapshot.
|
|
422
|
+
if (options.graph) {
|
|
423
|
+
this.namedChanged();
|
|
424
|
+
return this.inner.load(data, options);
|
|
425
|
+
}
|
|
426
|
+
this.giveAll();
|
|
427
|
+
const count = this.guarded(() => (this.inner.load as NonNullable<RdfStore['load']>)(data, options));
|
|
428
|
+
this.track(this.resync().added, []);
|
|
429
|
+
return count;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
size(): number {
|
|
433
|
+
this.giveAll();
|
|
434
|
+
return this.inner.size ? this.inner.size() : this.inner.getQuads().length;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Whether the inner store is still to be given the model (KD-28). */
|
|
438
|
+
get behind(): boolean {
|
|
439
|
+
return this.stale;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Give the inner store the model now, if it is behind: its default graph
|
|
444
|
+
* cleared and given the copy — in one native load, the quads N-Triples
|
|
445
|
+
* cannot carry as they are (a blank node, which a bulk load renames) one by
|
|
446
|
+
* one (KD-28). Neither the copy nor anyone listening sees a change, unless the
|
|
447
|
+
* inner store refuses a quad, which then leaves the model and is told as removed.
|
|
448
|
+
*/
|
|
449
|
+
giveAll(): void {
|
|
450
|
+
if (!this.stale) return;
|
|
451
|
+
if (this.inner.update) this.inner.update('CLEAR SILENT DEFAULT');
|
|
452
|
+
else this.inner.removeQuads(this.defaultGraph());
|
|
453
|
+
const { native, oneByOne } = splitForNativeLoad(this.model.getQuads(null, null, null, DEFAULT_GRAPH) as unknown as Quad[]);
|
|
454
|
+
this.stale = false;
|
|
455
|
+
// Inserting a statement already loaded is safe: a native load that fails part-way is finished one by one.
|
|
456
|
+
if (!this.giveNatively(native)) for (const q of native) oneByOne.push(q);
|
|
457
|
+
this.giveOneByOne(oneByOne);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ── Internals ──────────────────────────────────────────────────────────
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Quads as the store holds them: what it gives back — what the copy keeps,
|
|
464
|
+
* undo removes, a peer keys and validation sees — is their form, not
|
|
465
|
+
* necessarily the one added (`"010"^^xsd:int` kept as `"10"^^xsd:integer`).
|
|
466
|
+
*/
|
|
467
|
+
private held(quads: Quad[]): Quad[] {
|
|
468
|
+
if (quads.length === 0 || !this.inner.canonical) return quads;
|
|
469
|
+
return this.inner.canonical(quads);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Model quads into the inner store in one native load of N-Triples — 26 times faster than quad by quad, and a
|
|
474
|
+
* third less WebAssembly memory (KD-28). Whether it took them: a failure, even part-way, is for the quad path.
|
|
475
|
+
*/
|
|
476
|
+
private giveNatively(quads: Quad[]): boolean {
|
|
477
|
+
if (quads.length === 0) return true;
|
|
478
|
+
if (!this.inner.load || quads.length < LARGE_WRITE) return false;
|
|
479
|
+
try {
|
|
480
|
+
this.inner.load(nTriples(quads), { format: 'application/n-triples' });
|
|
481
|
+
return true;
|
|
482
|
+
} catch {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Model quads into the inner store one step at a time. Their terms were
|
|
489
|
+
* checked when added; should it refuse one even so, that quad leaves the
|
|
490
|
+
* model — said, and told to listeners as a removal — rather than the copy and
|
|
491
|
+
* the store differ.
|
|
492
|
+
*/
|
|
493
|
+
private giveOneByOne(quads: Quad[]): void {
|
|
494
|
+
const refused: Quad[] = [];
|
|
495
|
+
for (let at = 0; at < quads.length; at += 1000) {
|
|
496
|
+
const step = quads.slice(at, at + 1000);
|
|
497
|
+
try {
|
|
498
|
+
this.inner.addQuads(step);
|
|
499
|
+
continue;
|
|
500
|
+
} catch {
|
|
501
|
+
// One at a time, to find the one refused.
|
|
502
|
+
}
|
|
503
|
+
for (const q of step) {
|
|
504
|
+
try {
|
|
505
|
+
this.inner.addQuads([q]);
|
|
506
|
+
} catch (err) {
|
|
507
|
+
console.warn('[la-gram] The store refused a quad of the model', err);
|
|
508
|
+
if (this.model.removeQuad(q as never)) refused.push(q);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
this.track([], refused);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** Whether the inner store has a quad — not one it cannot even hold. */
|
|
516
|
+
private innerHas(q: Quad): boolean {
|
|
517
|
+
try {
|
|
518
|
+
if (this.inner.has) return this.inner.has(q);
|
|
519
|
+
return this.inner.getQuads(q.subject as NamedNode, q.predicate as NamedNode, q.object as NamedNode, q.graph as NamedNode).length > 0;
|
|
520
|
+
} catch {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** A term in the form the store holds it (a literal canonical, as Oxigraph keeps it). */
|
|
526
|
+
private heldTerm(term: Quad['object']): Quad['object'] {
|
|
527
|
+
if (!this.inner.canonical) return term;
|
|
528
|
+
return this.inner.canonical([DataFactory.quad(SCRATCH, SCRATCH, term as never) as unknown as Quad])[0].object;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Run a write to the inner store; if it fails part-way, the copy is read again from it. */
|
|
532
|
+
private guarded<T>(write: () => T): T {
|
|
533
|
+
try {
|
|
534
|
+
return write();
|
|
535
|
+
} catch (err) {
|
|
536
|
+
this.resync();
|
|
537
|
+
throw err;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Read the model graph again from the inner store into the copy: what that added and removed. */
|
|
542
|
+
private resync(): RdfDiff {
|
|
543
|
+
this.giveAll();
|
|
544
|
+
const before = this.model;
|
|
545
|
+
const after = new N3Store();
|
|
546
|
+
after.addQuads(this.defaultGraph() as never);
|
|
547
|
+
const added = (after.getQuads(null, null, null, null) as unknown as Quad[]).filter((q) => !before.has(q as never));
|
|
548
|
+
const removed = (before.getQuads(null, null, null, null) as unknown as Quad[]).filter((q) => !after.has(q as never));
|
|
549
|
+
this.model = after;
|
|
550
|
+
return { added, removed };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
private defaultGraph(): Quad[] {
|
|
554
|
+
return this.inner.getQuads(null, null, null, { termType: 'DefaultGraph', value: '' } as unknown as NamedNode);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
private track(added: Quad[], removed: Quad[]): void {
|
|
558
|
+
if (added.length === 0 && removed.length === 0) return;
|
|
559
|
+
const stamped = this.stamper !== null && !this.stamping && this.stampsOff === 0 && this.origin === 'local';
|
|
560
|
+
if (stamped) appendDiff(this.unstamped, added, removed);
|
|
561
|
+
for (const listener of this.writeListeners) listener({ added, removed });
|
|
562
|
+
for (const diff of this.recording) appendDiff(diff, added, removed);
|
|
563
|
+
if (this.pending) {
|
|
564
|
+
appendDiff(this.pending, added, removed);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
this.notify({ added, removed });
|
|
568
|
+
// A write outside any scope is an edit of its own: stamped now, as one more change.
|
|
569
|
+
if (stamped && this.depth === 0) this.batch(() => undefined);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
private notify(diff: RdfDiff): void {
|
|
573
|
+
const change: StoreChange = { ...diff, origin: this.origin };
|
|
574
|
+
for (const listener of this.listeners) listener(change);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* A canonical string for a quad — N-Quads-like, stable across stores. Used as a
|
|
580
|
+
* map key here and as the CRDT key in the collaboration binding.
|
|
581
|
+
*/
|
|
582
|
+
export function quadKey(q: Quad): string {
|
|
583
|
+
return `${termKey(q.subject)} ${termKey(q.predicate)} ${termKey(q.object)}${
|
|
584
|
+
q.graph.termType === 'DefaultGraph' ? '' : ` ${termKey(q.graph)}`
|
|
585
|
+
}`;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function termKey(term: Quad['object']): string {
|
|
589
|
+
switch (term.termType) {
|
|
590
|
+
case 'NamedNode':
|
|
591
|
+
return `<${term.value}>`;
|
|
592
|
+
case 'BlankNode':
|
|
593
|
+
return `_:${term.value}`;
|
|
594
|
+
case 'Literal': {
|
|
595
|
+
const lit = term as { value: string; language?: string; datatype?: { value: string } };
|
|
596
|
+
const escaped = JSON.stringify(lit.value);
|
|
597
|
+
if (lit.language) return `${escaped}@${lit.language}`;
|
|
598
|
+
const dt = lit.datatype?.value;
|
|
599
|
+
return dt && dt !== 'http://www.w3.org/2001/XMLSchema#string' ? `${escaped}^^<${dt}>` : escaped;
|
|
600
|
+
}
|
|
601
|
+
case 'Quad': {
|
|
602
|
+
// An RDF 1.2 triple term, as N-Triples 1.2 writes it: `<<( s p o )>>`.
|
|
603
|
+
const triple = term as Quad;
|
|
604
|
+
return `<<( ${termKey(triple.subject)} ${termKey(triple.predicate)} ${termKey(triple.object)} )>>`;
|
|
605
|
+
}
|
|
606
|
+
default:
|
|
607
|
+
return `?${term.value}`;
|
|
608
|
+
}
|
|
609
|
+
}
|