@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,602 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHACL Validator implementation using rdf-validate-shacl.
|
|
3
|
+
*
|
|
4
|
+
* Validates RDF data graphs against SHACL shapes graphs,
|
|
5
|
+
* supporting both full validation and incremental (single-resource) validation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import SHACLValidator from 'rdf-validate-shacl';
|
|
9
|
+
import { isInstanceOf } from 'rdf-validate-shacl/src/dataset-utils.js';
|
|
10
|
+
import { Store as N3Store, DataFactory } from 'n3';
|
|
11
|
+
import type { Quad, NamedNode, Term } from '@rdfjs/types';
|
|
12
|
+
import { selectLocalizedLiteral } from './localized-text.js';
|
|
13
|
+
import type {
|
|
14
|
+
ShaclValidator,
|
|
15
|
+
ValidationReport,
|
|
16
|
+
ValidationResult,
|
|
17
|
+
ValidationSeverity,
|
|
18
|
+
} from './interfaces.js';
|
|
19
|
+
|
|
20
|
+
const { namedNode } = DataFactory;
|
|
21
|
+
|
|
22
|
+
const SH = 'http://www.w3.org/ns/shacl#';
|
|
23
|
+
const SKOS_PREF_LABEL = 'http://www.w3.org/2004/02/skos/core#prefLabel';
|
|
24
|
+
const RDFS_LABEL = 'http://www.w3.org/2000/01/rdf-schema#label';
|
|
25
|
+
|
|
26
|
+
/** sh:sparql — SPARQL-based constraints, unsupported by rdf-validate-shacl. */
|
|
27
|
+
const SH_SPARQL = `${SH}sparql`;
|
|
28
|
+
/** sh:SPARQLConstraintComponent — the component rdf-validate-shacl cannot resolve. */
|
|
29
|
+
const SH_SPARQL_CONSTRAINT_COMPONENT = `${SH}SPARQLConstraintComponent`;
|
|
30
|
+
/** sh:message — used to tell an authored message from a library default. */
|
|
31
|
+
const SH_MESSAGE = `${SH}message`;
|
|
32
|
+
|
|
33
|
+
/** How deep to walk sh:detail sub-results looking for a usable message. */
|
|
34
|
+
const MAX_DETAIL_DEPTH = 5;
|
|
35
|
+
|
|
36
|
+
/** SHACL severity IRIs mapped to our union type. */
|
|
37
|
+
const SEVERITY_MAP: Record<string, ValidationSeverity> = {
|
|
38
|
+
[`${SH}Violation`]: 'Violation',
|
|
39
|
+
[`${SH}Warning`]: 'Warning',
|
|
40
|
+
[`${SH}Info`]: 'Info',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Options accepted by rdf-validate-shacl.
|
|
45
|
+
*
|
|
46
|
+
* The bundled type declarations for 0.5.x do not include `importGraph`, but
|
|
47
|
+
* newer releases resolve `owl:imports` in the shapes graph over the network
|
|
48
|
+
* when it is absent. la-gram loads every import into the store up front and
|
|
49
|
+
* must never fetch (it would fail in Electron over `file://`), so we always
|
|
50
|
+
* pass a no-op resolver. Widening the type here keeps that forward-compatible
|
|
51
|
+
* without an `any` cast at the call site.
|
|
52
|
+
*/
|
|
53
|
+
type ValidatorOptions = ConstructorParameters<typeof SHACLValidator>[1] & {
|
|
54
|
+
importGraph?: () => Promise<N3Store>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Minimal structural view of a rdf-validate-shacl result, incl. nested details. */
|
|
58
|
+
interface ResultLike {
|
|
59
|
+
message?: readonly { value: string }[];
|
|
60
|
+
detail?: readonly ResultLike[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Concrete implementation of ShaclValidator backed by rdf-validate-shacl.
|
|
65
|
+
*/
|
|
66
|
+
export class RdfShaclValidator implements ShaclValidator {
|
|
67
|
+
/**
|
|
68
|
+
* The compiled validator for the last shapes graph, keyed by the array's
|
|
69
|
+
* identity. Compiling is the expensive part — the ArchiMate relationship
|
|
70
|
+
* shapes alone are 70 000 quads — and the shapes only change when a
|
|
71
|
+
* metamodel is loaded or dropped, so callers that pass the same array get the
|
|
72
|
+
* same engine back.
|
|
73
|
+
*/
|
|
74
|
+
private cache: { shapes: Quad[]; engine: CompiledShapes } | null = null;
|
|
75
|
+
|
|
76
|
+
validate(dataGraph: Quad[], shapesGraph: Quad[]): ValidationReport {
|
|
77
|
+
return runCompiledOn(this.compiled(shapesGraph), quadsToStore(dataGraph));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Validate the data graph a store holds — every graph in it — as it is: no
|
|
82
|
+
* copy made. For a caller that keeps its data graph in a store of its own
|
|
83
|
+
* (the validation engine, Task 22).
|
|
84
|
+
*/
|
|
85
|
+
validateStore(data: N3Store, shapesGraph: Quad[], options: RunOptions = {}): ValidationReport {
|
|
86
|
+
const engine = this.compiled(shapesGraph);
|
|
87
|
+
guard(engine, options);
|
|
88
|
+
return runCompiledOn(engine, data, options.preferredLanguage);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Validate only these focus nodes of the data graph a store holds: each
|
|
93
|
+
* against the shapes that target it — chosen as a whole validation chooses
|
|
94
|
+
* them (a class target with the data's subclasses, `sh:targetNode`,
|
|
95
|
+
* `sh:targetSubjectsOf`, `sh:targetObjectsOf`) — so that its findings are
|
|
96
|
+
* the whole validation's findings for those nodes (Task 22).
|
|
97
|
+
*/
|
|
98
|
+
validateNodes(data: N3Store, shapesGraph: Quad[], focus: readonly Term[], options: RunOptions = {}): ValidationReport {
|
|
99
|
+
const engine = this.compiled(shapesGraph);
|
|
100
|
+
guard(engine, options);
|
|
101
|
+
const lib = engine.validator as unknown as LibraryInternals;
|
|
102
|
+
engine.targets ??= targetsOf(lib);
|
|
103
|
+
lib.setDataGraph(data);
|
|
104
|
+
const run = lib.validationEngine;
|
|
105
|
+
run.initReport();
|
|
106
|
+
const classesOf = classMembership(data);
|
|
107
|
+
const nodes = focus.filter((n) => n.termType === 'NamedNode' || n.termType === 'BlankNode');
|
|
108
|
+
for (const target of engine.targets) {
|
|
109
|
+
for (const node of nodes) {
|
|
110
|
+
if (isTarget(target, node, data, classesOf)) run.validateNodeAgainstShape(node, target.shape, lib.$data);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return toValidationReport(run.getReport(), engine.shapesStore, data, options.preferredLanguage);
|
|
115
|
+
} finally {
|
|
116
|
+
release(engine.validator);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private compiled(shapesGraph: Quad[]): CompiledShapes {
|
|
121
|
+
if (this.cache?.shapes !== shapesGraph) {
|
|
122
|
+
this.cache = { shapes: shapesGraph, engine: compileShapes(shapesGraph) };
|
|
123
|
+
}
|
|
124
|
+
return this.cache.engine;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
validateIncremental(
|
|
128
|
+
changedResource: NamedNode,
|
|
129
|
+
dataGraph: Quad[],
|
|
130
|
+
shapesGraph: Quad[],
|
|
131
|
+
): ValidationReport {
|
|
132
|
+
// Filter data graph to only triples where the changed resource is the subject
|
|
133
|
+
const filteredQuads = dataGraph.filter(
|
|
134
|
+
(q) => q.subject.value === changedResource.value,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return runValidation(filteredQuads, shapesGraph);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Build the validator, run it, and map the report. Shared by both entry points. */
|
|
142
|
+
/** A shapes graph compiled into a reusable engine. */
|
|
143
|
+
interface CompiledShapes {
|
|
144
|
+
validator: SHACLValidator;
|
|
145
|
+
shapesStore: N3Store;
|
|
146
|
+
/** The library's own limit of checks of a node against a shape in a run. */
|
|
147
|
+
nodeChecks: number;
|
|
148
|
+
/** What each shape with a target targets, read when nodes are first validated alone. */
|
|
149
|
+
targets?: ShapeTargets[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** How to run a validation. */
|
|
153
|
+
export interface RunOptions {
|
|
154
|
+
/** Preferred language for labels quoted in generated findings. Defaults to English. */
|
|
155
|
+
preferredLanguage?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Whether to stop checking a node against a shape after 50 checks in one
|
|
158
|
+
* run — rdf-validate-shacl's guard against a shape nested in itself. When no
|
|
159
|
+
* shape is (`shapesReach`), it only makes a node referred to from many
|
|
160
|
+
* places pass unchecked after the 50th, and differently when nodes are
|
|
161
|
+
* validated alone; and keying its counter costs a JSON string per check.
|
|
162
|
+
* Default: on.
|
|
163
|
+
*/
|
|
164
|
+
recursionGuard?: boolean;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** What of rdf-validate-shacl's internals validating chosen nodes uses (0.5). */
|
|
168
|
+
interface LibraryInternals {
|
|
169
|
+
$shapes: { node(term: Term): unknown; dataset: { match(s: Term | null, p: Term | null, o: Term | null): Iterable<Quad> } };
|
|
170
|
+
$data: unknown;
|
|
171
|
+
ns: { rdfs: { Class: Term } };
|
|
172
|
+
shapesGraph: { shapesWithTarget: LibraryShape[] };
|
|
173
|
+
setDataGraph(data: unknown): void;
|
|
174
|
+
validationEngine: {
|
|
175
|
+
maxNodeChecks: number;
|
|
176
|
+
initReport(): void;
|
|
177
|
+
validateNodeAgainstShape(node: Term, shape: LibraryShape, data: unknown): boolean;
|
|
178
|
+
getReport(): ReturnType<SHACLValidator['validate']>;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
interface LibraryShape {
|
|
183
|
+
shapeNode: Term;
|
|
184
|
+
shapeNodePointer: { out(predicate: Term): { terms: Term[] } };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** What a shape targets. */
|
|
188
|
+
interface ShapeTargets {
|
|
189
|
+
shape: LibraryShape;
|
|
190
|
+
/** Classes whose instances it targets — itself, when it is a class (an implicit target). */
|
|
191
|
+
classes: string[];
|
|
192
|
+
nodes: Set<string>;
|
|
193
|
+
subjectsOf: Term[];
|
|
194
|
+
objectsOf: Term[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const RDF_TYPE = namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
|
|
198
|
+
const RDFS_SUBCLASS_OF = namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf');
|
|
199
|
+
|
|
200
|
+
function targetsOf(lib: LibraryInternals): ShapeTargets[] {
|
|
201
|
+
const out = (shape: LibraryShape, predicate: string) => shape.shapeNodePointer.out(namedNode(SH + predicate) as unknown as Term).terms;
|
|
202
|
+
return lib.shapesGraph.shapesWithTarget.map((shape) => {
|
|
203
|
+
const classes = [...lib.$shapes.dataset.match(shape.shapeNode, namedNode(SH + 'targetClass') as unknown as Term, null)].map((q) => q.object.value);
|
|
204
|
+
if (isInstanceOf(lib.$shapes.node(shape.shapeNode) as never, lib.$shapes.node(lib.ns.rdfs.Class) as never, lib.ns as never)) {
|
|
205
|
+
classes.push(shape.shapeNode.value);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
shape,
|
|
209
|
+
classes,
|
|
210
|
+
nodes: new Set(out(shape, 'targetNode').map((t) => t.value)),
|
|
211
|
+
subjectsOf: out(shape, 'targetSubjectsOf'),
|
|
212
|
+
objectsOf: out(shape, 'targetObjectsOf'),
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** A node's classes in the data: its types and their superclasses there. */
|
|
218
|
+
function classMembership(data: N3Store): (node: Term) => Set<string> {
|
|
219
|
+
const supers = new Map<string, string[]>();
|
|
220
|
+
const superclasses = (cls: Term): string[] => {
|
|
221
|
+
const known = supers.get(cls.value);
|
|
222
|
+
if (known) return known;
|
|
223
|
+
const seen = new Map<string, Term>([[cls.value, cls]]);
|
|
224
|
+
const stack = [cls];
|
|
225
|
+
while (stack.length > 0) {
|
|
226
|
+
const current = stack.pop() as Term;
|
|
227
|
+
for (const parent of data.getObjects(current as never, RDFS_SUBCLASS_OF, null)) {
|
|
228
|
+
if (!seen.has(parent.value)) {
|
|
229
|
+
seen.set(parent.value, parent as unknown as Term);
|
|
230
|
+
stack.push(parent as unknown as Term);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const all = [...seen.keys()];
|
|
235
|
+
supers.set(cls.value, all);
|
|
236
|
+
return all;
|
|
237
|
+
};
|
|
238
|
+
return (node) => {
|
|
239
|
+
const classes = new Set<string>();
|
|
240
|
+
for (const type of data.getObjects(node as never, RDF_TYPE, null)) for (const c of superclasses(type as unknown as Term)) classes.add(c);
|
|
241
|
+
return classes;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Whether a shape targets the node — as `Shape.getTargetNodes` decides it. */
|
|
246
|
+
function isTarget(target: ShapeTargets, node: Term, data: N3Store, classesOf: (node: Term) => Set<string>): boolean {
|
|
247
|
+
if (target.classes.length > 0) {
|
|
248
|
+
const classes = classesOf(node);
|
|
249
|
+
if (target.classes.some((c) => classes.has(c))) return true;
|
|
250
|
+
}
|
|
251
|
+
if (target.nodes.has(node.value)) {
|
|
252
|
+
const n = node as never;
|
|
253
|
+
if (data.countQuads(n, null, null, null) + data.countQuads(null, n, null, null) + data.countQuads(null, null, n, null) > 0) return true;
|
|
254
|
+
}
|
|
255
|
+
if (target.subjectsOf.some((p) => data.countQuads(node as never, p as never, null, null) > 0)) return true;
|
|
256
|
+
return target.objectsOf.some((p) => data.countQuads(null, p as never, node as never, null) > 0);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Set the library's per-run limit of checks of a node against a shape. */
|
|
260
|
+
function guard(engine: CompiledShapes, options: RunOptions): void {
|
|
261
|
+
const lib = engine.validator as unknown as LibraryInternals;
|
|
262
|
+
lib.validationEngine.maxNodeChecks = options.recursionGuard === false ? 0 : engine.nodeChecks;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function compileShapes(shapesGraph: Quad[]): CompiledShapes {
|
|
266
|
+
const usableShapes = stripSparqlConstraints(shapesGraph);
|
|
267
|
+
const shapesStore = quadsToStore(usableShapes);
|
|
268
|
+
const options: ValidatorOptions = {
|
|
269
|
+
importGraph: () => Promise.resolve(new N3Store()),
|
|
270
|
+
};
|
|
271
|
+
const validator = new SHACLValidator(shapesStore, options);
|
|
272
|
+
const nodeChecks = (validator as unknown as LibraryInternals).validationEngine.maxNodeChecks;
|
|
273
|
+
return { validator, shapesStore, nodeChecks };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function runCompiledOn(engine: CompiledShapes, dataStore: N3Store, preferredLanguage?: string): ValidationReport {
|
|
277
|
+
const report = engine.validator.validate(dataStore);
|
|
278
|
+
try {
|
|
279
|
+
return toValidationReport(report, engine.shapesStore, dataStore, preferredLanguage);
|
|
280
|
+
} finally {
|
|
281
|
+
release(engine.validator);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Drop what a run kept for itself once its report is read: rdf-validate-shacl
|
|
287
|
+
* holds, until the next run, a counter per node and shape it checked (keyed by
|
|
288
|
+
* both, as JSON), the report's own graph, and the data graph — 250 MB after a
|
|
289
|
+
* run on a 350 000-triple model (Task 22). A compiled validator is kept between
|
|
290
|
+
* runs, so they were kept too.
|
|
291
|
+
*/
|
|
292
|
+
function release(validator: SHACLValidator): void {
|
|
293
|
+
const internal = validator as unknown as { $data?: unknown; validationEngine?: { initReport?(): void } };
|
|
294
|
+
internal.validationEngine?.initReport?.();
|
|
295
|
+
internal.$data = undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function runValidation(dataGraph: Quad[], shapesGraph: Quad[]): ValidationReport {
|
|
299
|
+
return runCompiledOn(compileShapes(shapesGraph), quadsToStore(dataGraph));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Remove SPARQL-based SHACL constraints from a shapes graph.
|
|
304
|
+
*
|
|
305
|
+
* rdf-validate-shacl has no validator for `sh:SPARQLConstraintComponent` and
|
|
306
|
+
* throws "Cannot find validator for constraint component ..." the moment a
|
|
307
|
+
* shape carrying one is evaluated. Published Linked.Archi shape files use
|
|
308
|
+
* `sh:sparql` heavily (self-loop and cycle detection, for instance), so we
|
|
309
|
+
* drop those constraints rather than fail the whole validation run.
|
|
310
|
+
*
|
|
311
|
+
* Dropping the two quad patterns is sufficient. The blank nodes that held the
|
|
312
|
+
* `sh:select` / `sh:prefixes` / `sh:message` bodies stay in the graph, but once
|
|
313
|
+
* the `sh:sparql` link is gone nothing reaches them: they are not typed as
|
|
314
|
+
* `sh:NodeShape` or `sh:PropertyShape`, so they are not implicit class targets,
|
|
315
|
+
* and no shape references them. Verified against the real ArchiMate 4.0
|
|
316
|
+
* element shapes, which contain 20 such quads.
|
|
317
|
+
*
|
|
318
|
+
* The tradeoff is real: shapes whose *only* constraint is `sh:sparql` become
|
|
319
|
+
* inert, so their rule is silently not enforced.
|
|
320
|
+
*/
|
|
321
|
+
function stripSparqlConstraints(quads: Quad[]): Quad[] {
|
|
322
|
+
return quads.filter(
|
|
323
|
+
(q) =>
|
|
324
|
+
q.predicate.value !== SH_SPARQL &&
|
|
325
|
+
q.object.value !== SH_SPARQL_CONSTRAINT_COMPONENT,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Convert an array of quads into an N3.js Store (RDF/JS DatasetCore). */
|
|
330
|
+
function quadsToStore(quads: Quad[]): N3Store {
|
|
331
|
+
const store = new N3Store();
|
|
332
|
+
store.addQuads(quads as Parameters<typeof store.addQuads>[0]);
|
|
333
|
+
return store;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Map the library's ValidationReport to our interface. */
|
|
337
|
+
function toValidationReport(
|
|
338
|
+
report: ReturnType<SHACLValidator['validate']>,
|
|
339
|
+
shapesStore: N3Store,
|
|
340
|
+
dataStore: N3Store,
|
|
341
|
+
preferredLanguage?: string,
|
|
342
|
+
): ValidationReport {
|
|
343
|
+
const results: ValidationResult[] = report.results.map((r) => {
|
|
344
|
+
const severityIri = r.severity?.value ?? `${SH}Violation`;
|
|
345
|
+
const severity: ValidationSeverity = SEVERITY_MAP[severityIri] ?? 'Violation';
|
|
346
|
+
|
|
347
|
+
const focusNode = r.focusNode?.value ?? '';
|
|
348
|
+
const path = r.path?.value ?? '';
|
|
349
|
+
const sourceShape = r.sourceShape?.value ?? '';
|
|
350
|
+
const sourceComponent = r.sourceConstraintComponent?.value ?? '';
|
|
351
|
+
const value = r.value?.value ?? '';
|
|
352
|
+
|
|
353
|
+
const message = resolveMessage({
|
|
354
|
+
result: r,
|
|
355
|
+
shapesStore,
|
|
356
|
+
dataStore,
|
|
357
|
+
shapeTerm: r.sourceShape ?? null,
|
|
358
|
+
focusNode,
|
|
359
|
+
sourceShape,
|
|
360
|
+
sourceComponent,
|
|
361
|
+
path,
|
|
362
|
+
value,
|
|
363
|
+
preferredLanguage,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const mapped: ValidationResult = {
|
|
367
|
+
focusNode: namedNode(focusNode),
|
|
368
|
+
resultPath: namedNode(path),
|
|
369
|
+
sourceShape: namedNode(sourceShape),
|
|
370
|
+
message,
|
|
371
|
+
severity,
|
|
372
|
+
};
|
|
373
|
+
if (sourceComponent) {
|
|
374
|
+
mapped.sourceConstraintComponent = namedNode(sourceComponent);
|
|
375
|
+
}
|
|
376
|
+
const within = r.sourceShape?.termType === 'BlankNode' ? enclosingShape(shapesStore, r.sourceShape) : undefined;
|
|
377
|
+
if (within) mapped.withinShape = namedNode(within);
|
|
378
|
+
// The value it is about, copied out of the library's terms: an IRI or a literal (a blank node names nothing).
|
|
379
|
+
if (r.value?.termType === 'NamedNode') mapped.value = namedNode(r.value.value);
|
|
380
|
+
else if (r.value?.termType === 'Literal') {
|
|
381
|
+
const literal = r.value as Term & { language?: string; datatype?: NamedNode };
|
|
382
|
+
mapped.value = DataFactory.literal(literal.value, literal.language || (literal.datatype ? namedNode(literal.datatype.value) : undefined));
|
|
383
|
+
}
|
|
384
|
+
return mapped;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
conforms: report.conforms,
|
|
389
|
+
results,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** What writes a shape inside another: a property, a nested shape, a list of shapes. */
|
|
394
|
+
const ENCLOSING = new Set(
|
|
395
|
+
['property', 'node', 'not', 'qualifiedValueShape', 'or', 'and', 'xone'].map((p) => SH + p).concat(
|
|
396
|
+
['first', 'rest'].map((p) => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' + p),
|
|
397
|
+
),
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
/** Per shapes graph, the named shape each inline shape is written in. */
|
|
401
|
+
const enclosingCache = new WeakMap<N3Store, Map<string, string | undefined>>();
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* The named shape an inline shape (a blank node) is written in: up through
|
|
405
|
+
* `sh:property`, `sh:node`, `sh:not`, `sh:qualifiedValueShape` and the lists of
|
|
406
|
+
* `sh:or`, `sh:and`, `sh:xone`, to the first named node. None when it is
|
|
407
|
+
* written in nothing named.
|
|
408
|
+
*
|
|
409
|
+
* Exported for direct testing.
|
|
410
|
+
*/
|
|
411
|
+
export function enclosingShape(shapesStore: N3Store, shape: Term): string | undefined {
|
|
412
|
+
let cache = enclosingCache.get(shapesStore);
|
|
413
|
+
if (!cache) enclosingCache.set(shapesStore, (cache = new Map()));
|
|
414
|
+
if (cache.has(shape.value)) return cache.get(shape.value);
|
|
415
|
+
const seen = new Set<string>([shape.value]);
|
|
416
|
+
let level: Term[] = [shape];
|
|
417
|
+
let found: string | undefined;
|
|
418
|
+
while (level.length > 0 && !found) {
|
|
419
|
+
const next: Term[] = [];
|
|
420
|
+
for (const term of level) {
|
|
421
|
+
for (const q of shapesStore.getQuads(null, null, term as never, null)) {
|
|
422
|
+
if (!ENCLOSING.has(q.predicate.value)) continue;
|
|
423
|
+
if (q.subject.termType === 'NamedNode') {
|
|
424
|
+
found = q.subject.value;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
if (!seen.has(q.subject.value)) {
|
|
428
|
+
seen.add(q.subject.value);
|
|
429
|
+
next.push(q.subject as Term);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (found) break;
|
|
433
|
+
}
|
|
434
|
+
level = next;
|
|
435
|
+
}
|
|
436
|
+
cache.set(shape.value, found);
|
|
437
|
+
return found;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Pick the most useful message available for a result.
|
|
442
|
+
*
|
|
443
|
+
* Precedence:
|
|
444
|
+
* 1. A message the shape author declared with `sh:message`. Checked against
|
|
445
|
+
* the shapes graph rather than by string-matching, because
|
|
446
|
+
* rdf-validate-shacl also emits terse built-in messages ("Less than 1
|
|
447
|
+
* values") that are indistinguishable from authored ones on the result.
|
|
448
|
+
* 2. The deepest message found in nested `sh:detail` sub-results. `sh:node`
|
|
449
|
+
* violations report only "Value does not have shape <X>" at the top level
|
|
450
|
+
* and bury the actionable message one or more levels down.
|
|
451
|
+
* 3. A synthesised message built from the constraint component.
|
|
452
|
+
*/
|
|
453
|
+
function resolveMessage(ctx: {
|
|
454
|
+
result: ResultLike;
|
|
455
|
+
shapesStore: N3Store;
|
|
456
|
+
dataStore: N3Store;
|
|
457
|
+
shapeTerm: Term | null;
|
|
458
|
+
focusNode: string;
|
|
459
|
+
sourceShape: string;
|
|
460
|
+
sourceComponent: string;
|
|
461
|
+
path: string;
|
|
462
|
+
value: string;
|
|
463
|
+
preferredLanguage?: string;
|
|
464
|
+
}): string {
|
|
465
|
+
if (hasAuthoredMessage(ctx.shapesStore, ctx.shapeTerm)) {
|
|
466
|
+
const authored = firstMessage(ctx.result);
|
|
467
|
+
if (authored) return authored;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const nested = deepestDetailMessage(ctx.result);
|
|
471
|
+
if (nested) return nested;
|
|
472
|
+
|
|
473
|
+
return buildReadableMessage(
|
|
474
|
+
ctx.focusNode,
|
|
475
|
+
ctx.sourceShape,
|
|
476
|
+
ctx.sourceComponent,
|
|
477
|
+
ctx.path,
|
|
478
|
+
ctx.value,
|
|
479
|
+
ctx.dataStore,
|
|
480
|
+
ctx.preferredLanguage,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** True when the shape node carries an explicit `sh:message` in the shapes graph. */
|
|
485
|
+
function hasAuthoredMessage(shapesStore: N3Store, shapeTerm: Term | null): boolean {
|
|
486
|
+
if (!shapeTerm) return false;
|
|
487
|
+
if (shapeTerm.termType !== 'NamedNode' && shapeTerm.termType !== 'BlankNode') {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
return (
|
|
491
|
+
shapesStore.countQuads(
|
|
492
|
+
shapeTerm as Parameters<N3Store['countQuads']>[0],
|
|
493
|
+
namedNode(SH_MESSAGE),
|
|
494
|
+
null,
|
|
495
|
+
null,
|
|
496
|
+
) > 0
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Join the messages on a single result into one string, or '' when there are none. */
|
|
501
|
+
function firstMessage(result: ResultLike): string {
|
|
502
|
+
const messages = result.message ?? [];
|
|
503
|
+
return messages
|
|
504
|
+
.map((m) => m.value)
|
|
505
|
+
.filter((v) => v.length > 0)
|
|
506
|
+
.join('; ');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Walk `sh:detail` sub-results depth-first and return the innermost message.
|
|
511
|
+
*
|
|
512
|
+
* Nesting is produced by `sh:node` constraints, where every level above the
|
|
513
|
+
* leaf says only "Value does not have shape <X>". Preferring the deepest
|
|
514
|
+
* message surfaces the leaf constraint that actually failed.
|
|
515
|
+
*
|
|
516
|
+
* Exported for direct testing.
|
|
517
|
+
*/
|
|
518
|
+
export function deepestDetailMessage(result: ResultLike, depth = 0): string {
|
|
519
|
+
if (depth >= MAX_DETAIL_DEPTH) return '';
|
|
520
|
+
|
|
521
|
+
const details = result.detail ?? [];
|
|
522
|
+
for (const detail of details) {
|
|
523
|
+
const deeper = deepestDetailMessage(detail, depth + 1);
|
|
524
|
+
if (deeper) return deeper;
|
|
525
|
+
const own = firstMessage(detail);
|
|
526
|
+
if (own) return own;
|
|
527
|
+
}
|
|
528
|
+
return '';
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Shorten an IRI to its local name for display. */
|
|
532
|
+
function shortenIri(iri: string): string {
|
|
533
|
+
if (!iri) return '';
|
|
534
|
+
const hash = iri.lastIndexOf('#');
|
|
535
|
+
if (hash >= 0) return iri.slice(hash + 1);
|
|
536
|
+
const slash = iri.lastIndexOf('/');
|
|
537
|
+
if (slash >= 0) return iri.slice(slash + 1);
|
|
538
|
+
return iri;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Look up a display label for a node in the data graph.
|
|
543
|
+
* Prefers skos:prefLabel, then rdfs:label, then the IRI local name.
|
|
544
|
+
*/
|
|
545
|
+
function labelFor(dataStore: N3Store, iri: string, preferredLanguage?: string): string {
|
|
546
|
+
if (!iri) return 'node';
|
|
547
|
+
for (const predicate of [SKOS_PREF_LABEL, RDFS_LABEL]) {
|
|
548
|
+
// Stores can enumerate the same RDF terms in different orders after an interchange.
|
|
549
|
+
const labels = dataStore.getObjects(namedNode(iri), namedNode(predicate), null)
|
|
550
|
+
.filter(term => term.termType === 'Literal')
|
|
551
|
+
.sort((a, b) => a.language.localeCompare(b.language, 'en') || a.value.localeCompare(b.value, 'en'));
|
|
552
|
+
const label = selectLocalizedLiteral(labels, preferredLanguage);
|
|
553
|
+
if (label) return label.value;
|
|
554
|
+
}
|
|
555
|
+
return shortenIri(iri);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Synthesise a human-readable message for a violation whose shape declares no
|
|
560
|
+
* `sh:message`. Ported from the la-modeller-excalidraw validator, with scene
|
|
561
|
+
* lookups replaced by data-graph label lookups.
|
|
562
|
+
*
|
|
563
|
+
* Exported for direct testing.
|
|
564
|
+
*/
|
|
565
|
+
export function buildReadableMessage(
|
|
566
|
+
focusNode: string,
|
|
567
|
+
sourceShape: string,
|
|
568
|
+
sourceComponent: string,
|
|
569
|
+
path: string,
|
|
570
|
+
value: string,
|
|
571
|
+
dataStore: N3Store,
|
|
572
|
+
preferredLanguage?: string,
|
|
573
|
+
): string {
|
|
574
|
+
const elementLabel = labelFor(dataStore, focusNode, preferredLanguage);
|
|
575
|
+
const component = shortenIri(sourceComponent);
|
|
576
|
+
const shapeName = shortenIri(sourceShape);
|
|
577
|
+
const pathName = shortenIri(path);
|
|
578
|
+
|
|
579
|
+
if (component === 'OrConstraintComponent') {
|
|
580
|
+
return `"${elementLabel}" violates ${shapeName} — none of the allowed source/target combinations match.`;
|
|
581
|
+
}
|
|
582
|
+
if (component === 'ClassConstraintComponent') {
|
|
583
|
+
return `"${elementLabel}" has invalid ${pathName || 'value'}: ${shortenIri(value)} is not an allowed class for ${shapeName}.`;
|
|
584
|
+
}
|
|
585
|
+
if (component === 'MinCountConstraintComponent') {
|
|
586
|
+
return `"${elementLabel}" is missing required property "${pathName}" (required by ${shapeName}).`;
|
|
587
|
+
}
|
|
588
|
+
if (component === 'MaxCountConstraintComponent') {
|
|
589
|
+
return `"${elementLabel}" has too many values for "${pathName}" (constrained by ${shapeName}).`;
|
|
590
|
+
}
|
|
591
|
+
if (component === 'DatatypeConstraintComponent') {
|
|
592
|
+
return `"${elementLabel}" has wrong datatype for "${pathName}" (expected by ${shapeName}).`;
|
|
593
|
+
}
|
|
594
|
+
if (component === 'NodeKindConstraintComponent') {
|
|
595
|
+
return `"${elementLabel}" has a value of the wrong node kind for "${pathName}" (expected by ${shapeName}).`;
|
|
596
|
+
}
|
|
597
|
+
if (component === 'NodeConstraintComponent' || component === 'AndConstraintComponent') {
|
|
598
|
+
return `"${elementLabel}" does not satisfy all constraints in ${shapeName}.`;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return `"${elementLabel}" violates ${shapeName || 'a SHACL constraint'}${pathName ? ` on property "${pathName}"` : ''} (${component || 'unknown component'}).`;
|
|
602
|
+
}
|