@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.
- package/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +96 -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 +923 -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 +893 -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 +7302 -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 +840 -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 +470 -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/observable-store.ts +631 -0
- package/src/rdf-engine/rdf-store.ts +508 -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 +334 -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 +682 -0
- package/src/rdf-engine/validation-service.ts +184 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RDF Store implementation using Oxigraph WASM.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Oxigraph WASM `Store` to implement the `RdfStore` interface,
|
|
5
|
+
* providing SPARQL 1.1 support (SELECT, CONSTRUCT, ASK, DESCRIBE) and
|
|
6
|
+
* quad CRUD operations. Handles conversion between @rdfjs/types Quad
|
|
7
|
+
* (used by N3.js throughout the app) and Oxigraph's internal term types.
|
|
8
|
+
*
|
|
9
|
+
* ## Two Oxigraph builds, two initialization contracts
|
|
10
|
+
*
|
|
11
|
+
* `oxigraph`'s package.json declares `"main": "node.js"` and
|
|
12
|
+
* `"browser": "web.js"`, so bundlers targeting the browser get a *different*
|
|
13
|
+
* module than Node/Vitest:
|
|
14
|
+
*
|
|
15
|
+
* - `node.js` (CommonJS) reads `node_bg.wasm` off disk and instantiates it
|
|
16
|
+
* synchronously at import time. Every API is usable immediately.
|
|
17
|
+
* - `web.js` (ESM) ends with `export { initSync }; export default __wbg_init;`.
|
|
18
|
+
* Its internal `wasm` binding stays `undefined` until the default export is
|
|
19
|
+
* awaited, so calling `namedNode()` / `new Store()` beforehand throws.
|
|
20
|
+
*
|
|
21
|
+
* A namespace import (`import * as oxigraph`) is required rather than a
|
|
22
|
+
* default import: for `web.js` the default export is the *initializer*, not
|
|
23
|
+
* the API surface, so `oxigraph.namedNode` would be `undefined` in the browser.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import * as oxigraph from 'oxigraph';
|
|
27
|
+
import { DataFactory } from 'n3';
|
|
28
|
+
import type { Quad, NamedNode, Term } from '@rdfjs/types';
|
|
29
|
+
import type { RdfStore, SparqlResult } from './interfaces.js';
|
|
30
|
+
|
|
31
|
+
const { namedNode, blankNode, literal, defaultGraph, quad: n3Quad } = DataFactory;
|
|
32
|
+
|
|
33
|
+
// ── Term conversion helpers ────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/** Convert an @rdfjs/types Term to an Oxigraph term. */
|
|
36
|
+
function toOxTerm(term: Term): oxigraph.Term {
|
|
37
|
+
switch (term.termType) {
|
|
38
|
+
case 'NamedNode':
|
|
39
|
+
return oxigraph.namedNode(term.value);
|
|
40
|
+
case 'BlankNode':
|
|
41
|
+
return oxigraph.blankNode(term.value);
|
|
42
|
+
case 'Literal': {
|
|
43
|
+
const lit = term as import('@rdfjs/types').Literal;
|
|
44
|
+
if (lit.language) {
|
|
45
|
+
return oxigraph.literal(lit.value, lit.language);
|
|
46
|
+
}
|
|
47
|
+
return oxigraph.literal(lit.value, oxigraph.namedNode(lit.datatype.value));
|
|
48
|
+
}
|
|
49
|
+
case 'DefaultGraph':
|
|
50
|
+
return oxigraph.defaultGraph();
|
|
51
|
+
case 'Quad': {
|
|
52
|
+
// An RDF 1.2 triple term (`<<( s p o )>>` — the object of rdf:reifies).
|
|
53
|
+
const triple = term as Quad;
|
|
54
|
+
return oxigraph.triple(toOxTerm(triple.subject), toOxTerm(triple.predicate), toOxTerm(triple.object));
|
|
55
|
+
}
|
|
56
|
+
default:
|
|
57
|
+
throw new Error(`Unsupported term type: ${term.termType}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Convert an @rdfjs/types Quad to an Oxigraph Quad. */
|
|
62
|
+
export function toOxQuad(q: Quad): oxigraph.Quad {
|
|
63
|
+
return oxigraph.quad(
|
|
64
|
+
toOxTerm(q.subject) as oxigraph.Quad_Subject,
|
|
65
|
+
toOxTerm(q.predicate) as oxigraph.Quad_Predicate,
|
|
66
|
+
toOxTerm(q.object) as oxigraph.Quad_Object,
|
|
67
|
+
toOxTerm(q.graph) as oxigraph.Quad_Graph,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Convert an Oxigraph term back to an @rdfjs/types Term (N3.js DataFactory). */
|
|
72
|
+
function fromOxTerm(term: oxigraph.Term): Term {
|
|
73
|
+
switch (term.termType) {
|
|
74
|
+
case 'NamedNode':
|
|
75
|
+
return namedNode(term.value) as unknown as Term;
|
|
76
|
+
case 'BlankNode':
|
|
77
|
+
return blankNode(term.value) as unknown as Term;
|
|
78
|
+
case 'Literal': {
|
|
79
|
+
const lit = term as oxigraph.Literal;
|
|
80
|
+
if (lit.language) {
|
|
81
|
+
return literal(lit.value, lit.language) as unknown as Term;
|
|
82
|
+
}
|
|
83
|
+
return literal(lit.value, namedNode(lit.datatype.value)) as unknown as Term;
|
|
84
|
+
}
|
|
85
|
+
case 'DefaultGraph':
|
|
86
|
+
return defaultGraph() as unknown as Term;
|
|
87
|
+
case 'Quad': {
|
|
88
|
+
// An RDF 1.2 triple term: n3 represents it as a quad in the default graph.
|
|
89
|
+
const triple = term as oxigraph.Quad;
|
|
90
|
+
return n3Quad(
|
|
91
|
+
fromOxTerm(triple.subject) as Quad['subject'],
|
|
92
|
+
fromOxTerm(triple.predicate) as Quad['predicate'],
|
|
93
|
+
fromOxTerm(triple.object) as Quad['object'],
|
|
94
|
+
) as unknown as Term;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Unsupported Oxigraph term type: ${(term as { termType: string }).termType}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Convert an Oxigraph Quad back to an @rdfjs/types Quad (N3.js DataFactory). */
|
|
102
|
+
function fromOxQuad(q: oxigraph.Quad): Quad {
|
|
103
|
+
return n3Quad(
|
|
104
|
+
fromOxTerm(q.subject) as Quad['subject'],
|
|
105
|
+
fromOxTerm(q.predicate) as Quad['predicate'],
|
|
106
|
+
fromOxTerm(q.object) as Quad['object'],
|
|
107
|
+
fromOxTerm(q.graph) as Quad['graph'],
|
|
108
|
+
) as unknown as Quad;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string';
|
|
112
|
+
const XSD_INTEGER = 'http://www.w3.org/2001/XMLSchema#integer';
|
|
113
|
+
const XSD_BOOLEAN = 'http://www.w3.org/2001/XMLSchema#boolean';
|
|
114
|
+
const RDF_LANG_STRING = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString';
|
|
115
|
+
const RDF_DIR_LANG_STRING = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString';
|
|
116
|
+
const CANONICAL_INTEGER = /^(?:0|-?[1-9][0-9]*)$/;
|
|
117
|
+
const XSD_DOUBLE = 'http://www.w3.org/2001/XMLSchema#double';
|
|
118
|
+
const XSD_DECIMAL = 'http://www.w3.org/2001/XMLSchema#decimal';
|
|
119
|
+
/** A number written plainly — no exponent, no leading or trailing zeros — as Oxigraph keeps a double or decimal. */
|
|
120
|
+
const CANONICAL_PLAIN_NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*[1-9])?$/;
|
|
121
|
+
|
|
122
|
+
/** The XML Schema integer types: Oxigraph keeps a value of any of them as an `xsd:integer`. */
|
|
123
|
+
const INTEGER_TYPES = new Set(
|
|
124
|
+
['integer', 'int', 'long', 'short', 'byte', 'nonNegativeInteger', 'positiveInteger', 'nonPositiveInteger', 'negativeInteger', 'unsignedLong', 'unsignedInt', 'unsignedShort', 'unsignedByte'].map(
|
|
125
|
+
(t) => 'http://www.w3.org/2001/XMLSchema#' + t,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A number literal in the form Oxigraph keeps it, where that form is known —
|
|
131
|
+
* else `undefined`, and Oxigraph is asked. An integer of any integer type: an
|
|
132
|
+
* `xsd:integer`, without sign `+`, leading zeros or `-0` (within 18 digits). A
|
|
133
|
+
* double or decimal written plainly: without sign `+`, leading zeros, trailing
|
|
134
|
+
* fractional zeros or a bare point; zero `0` — `-0` for a double (within 15
|
|
135
|
+
* significant digits). Checked against Oxigraph in rdf-store.test.
|
|
136
|
+
*/
|
|
137
|
+
function canonicalNumber(term: Term & { termType: 'Literal' }): Term | undefined {
|
|
138
|
+
const dt = term.datatype.value;
|
|
139
|
+
if (INTEGER_TYPES.has(dt)) {
|
|
140
|
+
const m = /^([+-]?)([0-9]+)$/.exec(term.value);
|
|
141
|
+
if (!m) return undefined;
|
|
142
|
+
const digits = m[2].replace(/^0+(?=[0-9])/, '');
|
|
143
|
+
if (digits.length > 18) return undefined;
|
|
144
|
+
return literal(`${m[1] === '-' && digits !== '0' ? '-' : ''}${digits}`, namedNode(XSD_INTEGER));
|
|
145
|
+
}
|
|
146
|
+
if (dt === XSD_DOUBLE || dt === XSD_DECIMAL) {
|
|
147
|
+
const m = /^([+-]?)([0-9]*)(?:\.([0-9]*))?$/.exec(term.value);
|
|
148
|
+
if (!m || m[2].length + (m[3] ?? '').length === 0) return undefined;
|
|
149
|
+
const whole = m[2].replace(/^0+/, '');
|
|
150
|
+
const fraction = (m[3] ?? '').replace(/0+$/, '');
|
|
151
|
+
const significant = (whole + fraction).replace(/^0+/, '');
|
|
152
|
+
if (significant.length > 15) return undefined;
|
|
153
|
+
const negative = m[1] === '-' && (significant !== '' || dt === XSD_DOUBLE);
|
|
154
|
+
return literal(`${negative ? '-' : ''}${whole || '0'}${fraction ? `.${fraction}` : ''}`, namedNode(dt));
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Whether a double or decimal is written as Oxigraph keeps it: plainly, in at most 15 significant digits. */
|
|
160
|
+
function plainNumber(value: string): boolean {
|
|
161
|
+
return CANONICAL_PLAIN_NUMBER.test(value) && value !== '-0' && value.replace(/[-.]/g, '').replace(/^0+/, '').length <= 15;
|
|
162
|
+
}
|
|
163
|
+
/** Subjects in the scratch store {@link OxigraphRdfStore.canonical} uses. */
|
|
164
|
+
const SCRATCH = 'urn:la-gram:canonical:';
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Whether Oxigraph may keep this object in another form: a typed literal not a
|
|
168
|
+
* string — but for an integer, a boolean or a plainly written double or decimal
|
|
169
|
+
* already canonical, most of a diagram's — a language tag not in lower case
|
|
170
|
+
* (`en-GB` is kept as `en-gb`), or a triple term with one.
|
|
171
|
+
*/
|
|
172
|
+
function mayBeRewritten(term: Term): boolean {
|
|
173
|
+
if (term.termType === 'Literal') {
|
|
174
|
+
const dt = term.datatype.value;
|
|
175
|
+
if (dt === XSD_INTEGER) return !CANONICAL_INTEGER.test(term.value);
|
|
176
|
+
if (dt === XSD_BOOLEAN) return term.value !== 'true' && term.value !== 'false';
|
|
177
|
+
// A diagram's bounds and points: kept as written when written plainly.
|
|
178
|
+
if (dt === XSD_DOUBLE || dt === XSD_DECIMAL) return !plainNumber(term.value);
|
|
179
|
+
if (dt === RDF_LANG_STRING || dt === RDF_DIR_LANG_STRING) return term.language !== term.language.toLowerCase();
|
|
180
|
+
return dt !== XSD_STRING;
|
|
181
|
+
}
|
|
182
|
+
if (term.termType === 'Quad') return mayBeRewritten((term as unknown as Quad).object);
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── SPARQL query type detection ────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
type SparqlQueryType = 'SELECT' | 'CONSTRUCT' | 'ASK' | 'DESCRIBE';
|
|
189
|
+
|
|
190
|
+
/** Detect the SPARQL query form from the query string. */
|
|
191
|
+
export function detectQueryType(sparql: string): SparqlQueryType {
|
|
192
|
+
// The query form is the first form keyword after the prologue; subqueries
|
|
193
|
+
// come later. IRIs and strings are masked before comments are stripped: a
|
|
194
|
+
// '#' inside <…/core#> is not a comment, and stripping from it used to take
|
|
195
|
+
// the closing '>' along, so a CONSTRUCT with a SELECT subquery read as SELECT.
|
|
196
|
+
const code = sparql
|
|
197
|
+
.replace(/<[^<>"{}|^`\\\s]*>/g, '<>')
|
|
198
|
+
.replace(/"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'/g, '""')
|
|
199
|
+
.replace(/#[^\n]*/g, '');
|
|
200
|
+
const form = /\b(SELECT|CONSTRUCT|ASK|DESCRIBE)\b/i.exec(code);
|
|
201
|
+
return (form ? form[1].toUpperCase() : 'SELECT') as SparqlQueryType;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ── WASM initialization ────────────────────────────────────────────────
|
|
205
|
+
|
|
206
|
+
/** Signature of the wasm-bindgen async initializer exported by `web.js`. */
|
|
207
|
+
type WasmInitializer = (moduleOrPath?: unknown) => Promise<unknown>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Returns the WASM initializer if the resolved Oxigraph build needs one.
|
|
211
|
+
*
|
|
212
|
+
* Environment is detected from the module shape rather than by sniffing
|
|
213
|
+
* `window` or `process`:
|
|
214
|
+
* - `web.js` is an ES module whose default export is the async
|
|
215
|
+
* `__wbg_init` function → returns that function.
|
|
216
|
+
* - `node.js` is CommonJS; under ESM interop its `default` is the
|
|
217
|
+
* `module.exports` namespace object (not callable) and WASM is already
|
|
218
|
+
* instantiated → returns `null`.
|
|
219
|
+
*/
|
|
220
|
+
function getWasmInitializer(): WasmInitializer | null {
|
|
221
|
+
const maybeInit = (oxigraph as unknown as { default?: unknown }).default;
|
|
222
|
+
return typeof maybeInit === 'function' ? (maybeInit as WasmInitializer) : null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Memoized init promise so concurrent callers share a single instantiation. */
|
|
226
|
+
let wasmInitPromise: Promise<void> | null = null;
|
|
227
|
+
|
|
228
|
+
/** Set once WASM instantiation has actually completed. */
|
|
229
|
+
let wasmReady = false;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Ensure the Oxigraph WASM module is instantiated.
|
|
233
|
+
*
|
|
234
|
+
* No-op on the Node build. On the browser build the default export is awaited;
|
|
235
|
+
* `__wbg_init` itself short-circuits with `if (wasm !== undefined) return wasm`,
|
|
236
|
+
* and the promise is memoized here, so calling this repeatedly is safe.
|
|
237
|
+
*/
|
|
238
|
+
export async function initOxigraph(): Promise<void> {
|
|
239
|
+
const init = getWasmInitializer();
|
|
240
|
+
if (init === null) return;
|
|
241
|
+
|
|
242
|
+
if (wasmInitPromise === null) {
|
|
243
|
+
wasmInitPromise = Promise.resolve(init()).then(() => {
|
|
244
|
+
wasmReady = true;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
await wasmInitPromise;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Whether Oxigraph can be used synchronously right now — always true on the
|
|
252
|
+
* Node build, true on the browser build only after `initOxigraph()` resolved.
|
|
253
|
+
*/
|
|
254
|
+
export function isOxigraphReady(): boolean {
|
|
255
|
+
return getWasmInitializer() === null || wasmReady;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ── OxigraphRdfStore ───────────────────────────────────────────────────
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* RdfStore implementation backed by Oxigraph WASM.
|
|
262
|
+
*
|
|
263
|
+
* Oxigraph provides full SPARQL 1.1 support in-browser via WebAssembly.
|
|
264
|
+
* All store operations are synchronous, but the browser build needs a
|
|
265
|
+
* one-time async WASM instantiation first — use {@link OxigraphRdfStore.create}
|
|
266
|
+
* for environment-agnostic construction. The bare constructor stays usable in
|
|
267
|
+
* Node (and after `initOxigraph()` has resolved) where WASM is already live.
|
|
268
|
+
*/
|
|
269
|
+
export class OxigraphRdfStore implements RdfStore {
|
|
270
|
+
private store: oxigraph.Store;
|
|
271
|
+
|
|
272
|
+
constructor() {
|
|
273
|
+
this.store = new oxigraph.Store();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Environment-agnostic factory: awaits the Oxigraph WASM initialization when
|
|
278
|
+
* the browser build is in use, then constructs the store.
|
|
279
|
+
*
|
|
280
|
+
* Always prefer this over `new OxigraphRdfStore()` in application code.
|
|
281
|
+
*/
|
|
282
|
+
static async create(): Promise<OxigraphRdfStore> {
|
|
283
|
+
await initOxigraph();
|
|
284
|
+
return new OxigraphRdfStore();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
addQuads(quads: Quad[]): void {
|
|
288
|
+
for (const q of quads) {
|
|
289
|
+
this.store.add(toOxQuad(q));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
removeQuads(quads: Quad[]): void {
|
|
294
|
+
for (const q of quads) {
|
|
295
|
+
this.store.delete(toOxQuad(q));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
getQuads(
|
|
300
|
+
subject?: NamedNode | null,
|
|
301
|
+
predicate?: NamedNode | null,
|
|
302
|
+
object?: NamedNode | null,
|
|
303
|
+
graph?: NamedNode | null,
|
|
304
|
+
): Quad[] {
|
|
305
|
+
const s = subject ? toOxTerm(subject as unknown as Term) : null;
|
|
306
|
+
const p = predicate ? toOxTerm(predicate as unknown as Term) : null;
|
|
307
|
+
const o = object ? toOxTerm(object as unknown as Term) : null;
|
|
308
|
+
const g = graph ? toOxTerm(graph as unknown as Term) : null;
|
|
309
|
+
|
|
310
|
+
const oxQuads = this.store.match(s, p, o, g);
|
|
311
|
+
return oxQuads.map(fromOxQuad);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
query(sparql: string): SparqlResult {
|
|
315
|
+
const result = this.store.query(sparql);
|
|
316
|
+
|
|
317
|
+
// ASK → boolean
|
|
318
|
+
if (typeof result === 'boolean') {
|
|
319
|
+
return { type: 'boolean', value: result };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// CONSTRUCT / DESCRIBE → Quad[]
|
|
323
|
+
if (Array.isArray(result) && result.length > 0 && 'subject' in result[0]) {
|
|
324
|
+
return {
|
|
325
|
+
type: 'quads',
|
|
326
|
+
quads: (result as oxigraph.Quad[]).map(fromOxQuad),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Empty array — need to check query type to determine result shape
|
|
331
|
+
if (Array.isArray(result) && result.length === 0) {
|
|
332
|
+
const qtype = detectQueryType(sparql);
|
|
333
|
+
if (qtype === 'CONSTRUCT' || qtype === 'DESCRIBE') {
|
|
334
|
+
return { type: 'quads', quads: [] };
|
|
335
|
+
}
|
|
336
|
+
return { type: 'bindings', results: [] };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// SELECT → Map<string, Term>[]
|
|
340
|
+
if (Array.isArray(result)) {
|
|
341
|
+
const bindings = (result as Map<string, oxigraph.Term>[]).map((row) => {
|
|
342
|
+
const record: Record<string, NamedNode | { value: string }> = {};
|
|
343
|
+
for (const [key, val] of row.entries()) {
|
|
344
|
+
const converted = fromOxTerm(val);
|
|
345
|
+
if ((converted as { termType: string }).termType === 'NamedNode') {
|
|
346
|
+
record[key] = converted as unknown as NamedNode;
|
|
347
|
+
} else {
|
|
348
|
+
record[key] = { value: converted.value };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return record;
|
|
352
|
+
});
|
|
353
|
+
return { type: 'bindings', results: bindings };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// String result (e.g. results_format specified) — shouldn't happen in normal use
|
|
357
|
+
throw new Error('Unexpected SPARQL result type');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
update(sparqlUpdate: string): void {
|
|
361
|
+
this.store.update(sparqlUpdate);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Parse and insert a whole document natively.
|
|
366
|
+
*
|
|
367
|
+
* Measured on the ArchiMate 3.2 relationship shapes (72 740 quads): 110 ms
|
|
368
|
+
* here against 1.4 s through {@link addQuads}, whose cost is the per-quad term
|
|
369
|
+
* conversion across the WASM boundary rather than the parse.
|
|
370
|
+
*/
|
|
371
|
+
load(data: string, options: { format: string; graph?: string; baseIri?: string }): number {
|
|
372
|
+
const before = this.store.size;
|
|
373
|
+
this.store.load(data, {
|
|
374
|
+
format: options.format,
|
|
375
|
+
...(options.graph ? { to_graph_name: oxigraph.namedNode(options.graph) } : {}),
|
|
376
|
+
...(options.baseIri ? { base_iri: options.baseIri } : {}),
|
|
377
|
+
no_transaction: true,
|
|
378
|
+
});
|
|
379
|
+
return this.store.size - before;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
size(): number {
|
|
383
|
+
return this.store.size;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Throw as adding these quads would — an IRI that is not one, a language tag
|
|
388
|
+
* or blank node label Oxigraph refuses, a term out of place — without adding
|
|
389
|
+
* them: each distinct term is made once with Oxigraph's own constructors.
|
|
390
|
+
*/
|
|
391
|
+
check(quads: Quad[]): void {
|
|
392
|
+
const made = new Set<string>();
|
|
393
|
+
const make = (term: Term): void => {
|
|
394
|
+
switch (term.termType) {
|
|
395
|
+
case 'NamedNode':
|
|
396
|
+
if (!made.has(term.value)) {
|
|
397
|
+
oxigraph.namedNode(term.value);
|
|
398
|
+
made.add(term.value);
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
case 'BlankNode': {
|
|
402
|
+
const key = `_:${term.value}`;
|
|
403
|
+
if (!made.has(key)) {
|
|
404
|
+
oxigraph.blankNode(term.value);
|
|
405
|
+
made.add(key);
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
case 'Literal': {
|
|
410
|
+
const language = term.language;
|
|
411
|
+
if (!language) return make(term.datatype);
|
|
412
|
+
const key = `@${language}`;
|
|
413
|
+
if (!made.has(key)) {
|
|
414
|
+
oxigraph.literal('', language);
|
|
415
|
+
made.add(key);
|
|
416
|
+
}
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
case 'Quad': {
|
|
420
|
+
const triple = term as unknown as Quad;
|
|
421
|
+
place(triple.subject, triple.predicate);
|
|
422
|
+
make(triple.subject);
|
|
423
|
+
make(triple.predicate);
|
|
424
|
+
make(triple.object);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
case 'DefaultGraph':
|
|
428
|
+
return;
|
|
429
|
+
default:
|
|
430
|
+
throw new Error(`Not a term the store can hold: ${term.termType}`);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const place = (subject: Term, predicate: Term) => {
|
|
434
|
+
if (subject.termType !== 'NamedNode' && subject.termType !== 'BlankNode') throw new Error(`Not a subject: ${subject.termType}`);
|
|
435
|
+
if (predicate.termType !== 'NamedNode') throw new Error(`Not a predicate: ${predicate.termType}`);
|
|
436
|
+
};
|
|
437
|
+
for (const q of quads) {
|
|
438
|
+
place(q.subject, q.predicate);
|
|
439
|
+
make(q.subject);
|
|
440
|
+
make(q.predicate);
|
|
441
|
+
make(q.object);
|
|
442
|
+
make(q.graph);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** The named graphs this store holds. */
|
|
447
|
+
namedGraphs(): NamedNode[] {
|
|
448
|
+
const rows = this.store.query('SELECT DISTINCT ?g WHERE { GRAPH ?g {} }') as Map<string, oxigraph.Term>[];
|
|
449
|
+
return rows.map((row) => fromOxTerm(row.get('g') as oxigraph.Term) as NamedNode);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Whether the store holds exactly this quad (graph included). */
|
|
453
|
+
has(q: Quad): boolean {
|
|
454
|
+
return this.store.has(toOxQuad(q));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The quads as this store holds them. Oxigraph keeps a literal of a type it
|
|
459
|
+
* computes with — a number, a boolean, a date or time — in canonical form:
|
|
460
|
+
* `"010"^^xsd:int` is kept, and read back, as `"10"^^xsd:integer`, `"1"^^xsd:boolean`
|
|
461
|
+
* as `"true"`; and a language tag in lower case. Only an object is rewritten: the objects that may be are put
|
|
462
|
+
* through a scratch store at once, each on a numbered subject, and read back;
|
|
463
|
+
* the array itself is returned when none changes. (One at a time, adding and
|
|
464
|
+
* deleting, is quadratic: the store keeps what was deleted.)
|
|
465
|
+
*/
|
|
466
|
+
canonical(quads: Quad[]): Quad[] {
|
|
467
|
+
const candidates: number[] = [];
|
|
468
|
+
let held: Quad[] | undefined;
|
|
469
|
+
quads.forEach((q, i) => {
|
|
470
|
+
if (!mayBeRewritten(q.object)) return;
|
|
471
|
+
// A number whose form Oxigraph's is known for is rewritten here (Task 22):
|
|
472
|
+
// a converter's `"132.0"^^xsd:double`, `"9"^^xsd:int`, on every node.
|
|
473
|
+
const number = q.object.termType === 'Literal' ? canonicalNumber(q.object) : undefined;
|
|
474
|
+
if (!number) {
|
|
475
|
+
candidates.push(i);
|
|
476
|
+
} else if (!number.equals(q.object)) {
|
|
477
|
+
held ??= quads.slice();
|
|
478
|
+
held[i] = n3Quad(q.subject as never, q.predicate as never, number as never, q.graph as never) as unknown as Quad;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
if (candidates.length === 0) return held ?? quads;
|
|
482
|
+
const scratch = new oxigraph.Store();
|
|
483
|
+
const p = oxigraph.namedNode(SCRATCH + 'p');
|
|
484
|
+
for (const i of candidates) {
|
|
485
|
+
scratch.add(oxigraph.quad(oxigraph.namedNode(SCRATCH + i), p, toOxTerm(quads[i].object) as oxigraph.Quad_Object, oxigraph.defaultGraph()));
|
|
486
|
+
}
|
|
487
|
+
const kept = new Map<number, oxigraph.Term>();
|
|
488
|
+
for (const q of scratch.match(null, null, null, null)) kept.set(Number(q.subject.value.slice(SCRATCH.length)), q.object);
|
|
489
|
+
(scratch as unknown as { free?: () => void }).free?.();
|
|
490
|
+
for (const i of candidates) {
|
|
491
|
+
const object = fromOxTerm(kept.get(i) as oxigraph.Term);
|
|
492
|
+
if (object.equals(quads[i].object)) continue;
|
|
493
|
+
const q = quads[i];
|
|
494
|
+
held ??= quads.slice();
|
|
495
|
+
held[i] = n3Quad(q.subject as never, q.predicate as never, object as never, q.graph as never) as unknown as Quad;
|
|
496
|
+
}
|
|
497
|
+
return held ?? quads;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Release the WASM memory behind the store. Stores are otherwise freed only
|
|
502
|
+
* when the garbage collector finalises the wrapper, which in a test run that
|
|
503
|
+
* builds dozens of metamodel-sized stores is late enough to matter.
|
|
504
|
+
*/
|
|
505
|
+
dispose(): void {
|
|
506
|
+
(this.store as unknown as { free?: () => void }).free?.();
|
|
507
|
+
}
|
|
508
|
+
}
|