@_linked/core 2.30.1 → 2.31.0
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/CHANGELOG.md +35 -0
- package/README.md +54 -7
- package/lib/esm/queries/IRMutation.js +1 -1
- package/lib/esm/queries/IRMutation.js.map +1 -1
- package/lib/esm/queries/IntermediateRepresentation.d.ts +0 -5
- package/lib/esm/queries/IntermediateRepresentation.js.map +1 -1
- package/lib/esm/queries/MutationQuery.js +0 -15
- package/lib/esm/queries/MutationQuery.js.map +1 -1
- package/lib/esm/queries/MutationSerialization.d.ts +6 -5
- package/lib/esm/queries/MutationSerialization.js +1 -9
- package/lib/esm/queries/MutationSerialization.js.map +1 -1
- package/lib/esm/queries/QueryFactory.d.ts +0 -6
- package/lib/esm/queries/QueryFactory.js.map +1 -1
- package/lib/esm/queries/lowerMutationJSON.js +1 -6
- package/lib/esm/queries/lowerMutationJSON.js.map +1 -1
- package/lib/esm/shapes/List.d.ts +0 -1
- package/lib/esm/shapes/List.js.map +1 -1
- package/lib/esm/shapes/PathList.d.ts +27 -0
- package/lib/esm/shapes/PathList.js +63 -0
- package/lib/esm/shapes/PathList.js.map +1 -0
- package/lib/esm/shapes/PathNode.d.ts +10 -9
- package/lib/esm/shapes/PathNode.js +21 -13
- package/lib/esm/shapes/PathNode.js.map +1 -1
- package/lib/esm/shapes/index.d.ts +1 -0
- package/lib/esm/shapes/index.js +1 -0
- package/lib/esm/shapes/index.js.map +1 -1
- package/lib/esm/shapes/serializePathToNodeData.d.ts +12 -11
- package/lib/esm/shapes/serializePathToNodeData.js +12 -11
- package/lib/esm/shapes/serializePathToNodeData.js.map +1 -1
- package/lib/esm/shapes/validation.js +2 -2
- package/lib/esm/shapes/validation.js.map +1 -1
- package/lib/esm/sparql/irToAlgebra.d.ts +7 -2
- package/lib/esm/sparql/irToAlgebra.js +415 -181
- package/lib/esm/sparql/irToAlgebra.js.map +1 -1
- package/lib/esm/utils/Package.js +6 -3
- package/lib/esm/utils/Package.js.map +1 -1
- package/package.json +1 -1
|
@@ -64,12 +64,6 @@ export type NodeDescriptionValue = {
|
|
|
64
64
|
* Optional, if not provided a new id will be generated.
|
|
65
65
|
*/
|
|
66
66
|
__id?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Write this nested node as a fresh blank node carrying only its field triples (no
|
|
69
|
-
* `rdf:type`). For RDF syntax structures whose meaning comes from the triple that
|
|
70
|
-
* references them, like a SHACL property path. Create-only and never with `__id`.
|
|
71
|
-
*/
|
|
72
|
-
__blank?: true;
|
|
73
67
|
};
|
|
74
68
|
export type UpdateNodePropertyValue = {
|
|
75
69
|
prop: PropertyShapeData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryFactory.js","sourceRoot":"","sources":["../../../src/queries/QueryFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryFactory.js","sourceRoot":"","sources":["../../../src/queries/QueryFactory.ts"],"names":[],"mappings":"AAmKA,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAG1D,MAAM,OAAgB,YAAY;CAAG;AAErC,MAAM,UAAU,sBAAsB,CACpC,KAAU;IAEV,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE9D,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IAC3B,IAAI,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC;IACjC,IAAI,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACxC,mBAAmB;IACnB,OAAO,CACL,CAAC,SAAS,IAAI,YAAY,IAAI,OAAO,KAAK,CAAC,CAAC;QAC5C,CAAC,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC;QAC5B,CAAC,YAAY,IAAI,OAAO,KAAK,CAAC,CAAC,CAChC,CAAC;AACJ,CAAC","sourcesContent":["import type {NodeShapeData, PropertyShapeData} from '../shapes/SHACL.js';\nimport {Shape} from '../shapes/Shape.js';\nimport {ShapeSet} from '../collections/ShapeSet.js';\nimport type {NodeReferenceValue} from '../utils/NodeReference.js';\nimport {ExpressionNode} from '../expressions/ExpressionNode.js';\n\nexport type Prettify<T> = T extends infer R\n ? {\n [K in keyof R]: R[K];\n }\n : never;\n\n/**\n * Recursively adds an id property to all objects in the object.\n * Also makes all keys optional.\n */\ntype _AddId<U> = U extends string | number | boolean | Date | null | undefined\n ? U\n : U extends Array<infer T>\n ? Array<_AddId<T>>\n : WithId<U>;\n\ntype RemoveId<U> = Omit<U, 'id'>;\n\ntype WithId<U> = U & {id: string};\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n\ntype CombineTypes<T> = {\n [K in keyof UnionToIntersection<T>]: T extends {[P in K]?: infer V}\n ? _AddId<V>\n : never;\n};\n\ntype IsPlainObject<T> = T extends object\n ? T extends any[]\n ? false\n : T extends Function\n ? false\n : T extends Date\n ? false\n : T extends RegExp\n ? false\n : T extends Error\n ? false\n : T extends null\n ? false\n : T extends undefined\n ? false\n : T extends object\n ? true\n : false\n : false;\n\ntype RecursiveTransform<T, IsCreate = false> = T extends\n | string\n | number\n | boolean\n | Date\n | null\n | undefined\n ? T\n : T extends Array<infer U>\n ? UpdatedSet<Prettify<RecursiveTransform<U>>, IsCreate>\n : IsSetModification<T> extends true\n ? ModifiedSet<T, IsCreate>\n : IsPlainObject<T> extends true\n ? // ? WithId<{ [K in keyof T]-?: Prettify<RecursiveTransform<T[K]>> }>\n WithId<{[K in keyof T]: Prettify<RecursiveTransform<T[K], IsCreate>>}>\n : T;\n\n//for update() we use {updatedTo} but for create() we actually just return the array of new values;\ntype UpdatedSet<U, IsCreate> = IsCreate extends true\n ? U[]\n : {\n updatedTo: U[];\n };\ntype IsSetModification<T> = T extends {add?: any; remove?: any} ? true : false;\ntype AddedType<T> = T extends {add: (infer U)[]}\n ? U\n : T extends {add: infer U}\n ? U\n : never;\n\ntype RemovedType<T> = T extends {remove: (infer U)[]}\n ? U\n : T extends {remove: infer U}\n ? U\n : never;\n\ntype ModifiedSet<T, IsCreate = false> = {\n added: AddId<AddedType<T>, IsCreate>[];\n removed: AddId<RemovedType<T>, IsCreate>[];\n};\n\nexport type AddId<T, IsCreate = false> = Prettify<\n RecursiveTransform<T, IsCreate>\n>;\n\nexport type UpdatePartial<S = Shape> =\n | UpdateNodeDescription<S>\n | NodeReferenceValue;\ntype UpdateNodeDescription<Shape> = Partial<\n Omit<\n {\n [P in KeysWithoutFunctions<Shape>]: ShapePropValueToUpdatePartial<\n Shape[P]\n >;\n },\n 'node' | 'nodeShape' | 'namedNode' | 'targetClass'\n >\n>;\ntype KeysWithoutFunctions<T> = {\n [K in keyof T]: T[K] extends Function ? never : K;\n}[keyof T];\n\ntype ShapePropValueToUpdatePartial<ShapeProperty> = ShapeProperty extends Shape\n ? UpdatePartial<ShapeProperty>\n : ShapeProperty extends ShapeSet<infer SSType>\n ? SetUpdateValue<SSType>\n : ShapeProperty | ExpressionNode;\n\ntype SetUpdateValue<SSType> = UpdatePartial<SSType>[] | SetModification<SSType>;\n\nexport type SetModification<SSType> = {\n add?: UpdatePartial<SSType>[] | UpdatePartial<SSType>;\n remove?: UpdatePartial<SSType>[] | UpdatePartial<SSType>;\n};\n\nexport type SetModificationValue = {\n $add?: UpdatePartial[];\n $remove?: NodeReferenceValue[];\n};\n\ntype UnsetValue = undefined;\nexport type LiteralUpdateValue = string | number | boolean | Date;\nexport type PropUpdateValue =\n | SinglePropertyUpdateValue\n | SinglePropertyUpdateValue[]\n | SetModificationValue;\nexport type SinglePropertyUpdateValue =\n | NodeDescriptionValue\n | NodeReferenceValue\n | LiteralUpdateValue\n | UnsetValue;\nexport type NodeDescriptionValue = {\n shape: NodeShapeData;\n fields: UpdateNodePropertyValue[];\n /**\n * The id of the node to be created.\n * Optional, if not provided a new id will be generated.\n */\n __id?: string;\n};\nexport type UpdateNodePropertyValue = {\n prop: PropertyShapeData;\n val: PropUpdateValue;\n};\nexport type ShapeReferenceValue = {id: string; shape: NodeReferenceValue};\nexport {toNodeReference} from '../utils/NodeReference.js';\nexport type {NodeReferenceValue};\n\nexport abstract class QueryFactory {}\n\nexport function isSetModificationValue(\n value: any,\n): value is SetModificationValue {\n if (value === null || typeof value !== 'object') return false;\n\n let hasAddKey = value.$add;\n let hasRemoveKey = value.$remove;\n let numKeys = Object.keys(value).length;\n //has no other keys\n return (\n (hasAddKey && hasRemoveKey && numKeys === 2) ||\n (hasAddKey && numKeys === 1) ||\n (hasRemoveKey && numKeys === 1)\n );\n}\n\n"]}
|
|
@@ -98,7 +98,7 @@ export function decodeNodeData(json, shape) {
|
|
|
98
98
|
const nodeShape = typeof json.__shape === 'string' ? requireShape(json.__shape) : shape;
|
|
99
99
|
const fields = [];
|
|
100
100
|
for (const [key, val] of Object.entries(json)) {
|
|
101
|
-
if (key === '__id' || key === '__shape' ||
|
|
101
|
+
if (key === '__id' || key === '__shape' || val === undefined)
|
|
102
102
|
continue;
|
|
103
103
|
const prop = getPropertyShape(nodeShape, key);
|
|
104
104
|
if (!prop) {
|
|
@@ -109,11 +109,6 @@ export function decodeNodeData(json, shape) {
|
|
|
109
109
|
const desc = { shape: nodeShape, fields };
|
|
110
110
|
if (typeof json.__id === 'string')
|
|
111
111
|
desc.__id = json.__id;
|
|
112
|
-
if (json.__blank !== undefined) {
|
|
113
|
-
if (json.__blank !== true)
|
|
114
|
-
throw new Error(`__blank must be true when given, got ${JSON.stringify(json.__blank)}`);
|
|
115
|
-
desc.__blank = true;
|
|
116
|
-
}
|
|
117
112
|
return desc;
|
|
118
113
|
}
|
|
119
114
|
function lowerWhere(shape, json) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lowerMutationJSON.js","sourceRoot":"","sources":["../../../src/queries/lowerMutationJSON.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAC,gBAAgB,E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,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAC,CAAC,CAAC;QACrF,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvC,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACxB,OAAO,8BAA8B,CAAC;oBACpC,KAAK;oBACL,mEAAmE;oBACnE,kDAAkD;oBAClD,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACvB,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAC,EAAE,EAAE,gBAAgB,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,CAAE,EAAC,CAAC,CAAC,CAAC,EAAC,EAAE,EAAC,CACxE;iBACF,CAAC,CAAC;YACL,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACxB,OAAO,iCAAiC,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,EAAC,KAAK,EAAE,aAAa,EAAC,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7D,OAAO,mCAAmC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,aAAa,EAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n\n/**\n * Lower mutation DSL-JSON to canonical IR.\n *\n * This is the **IR side** of mutation (de)serialization, kept deliberately\n * separate from the IR-free wire codec in `MutationSerialization.ts`. The\n * canonical-IR builders (`IRMutation` / `IRLower` / …) are reachable only from\n * here and from `lower()`, so a client that serializes mutations to JSON and\n * forwards them (without ever lowering) tree-shakes the whole IR pipeline away.\n */\nimport type {NodeShapeData} from '../shapes/SHACL.js';\nimport {getPropertyShape} from '../shapes/nodeShapeData.js';\nimport {\n type NodeDescriptionValue,\n type PropUpdateValue,\n type SetModificationValue,\n type SinglePropertyUpdateValue,\n type UpdateNodePropertyValue,\n} from './QueryFactory.js';\nimport {ExpressionNode} from '../expressions/ExpressionNode.js';\nimport {getNodeShape, getShapeClass} from '../utils/ShapeClass.js';\nimport type {IRExpression, IRGraphPattern} from './IntermediateRepresentation.js';\nimport {\n deserializeWherePath,\n type WherePathJSON,\n} from './QueryBuilderSerialization.js';\nimport {toWhere} from './IRDesugar.js';\nimport {lowerWhereToIR} from './IRLower.js';\nimport {\n buildCanonicalCreateMutationIR,\n buildCanonicalUpdateMutationIR,\n buildCanonicalUpsertMutationIR,\n buildCanonicalUpdateWhereMutationIR,\n buildCanonicalDeleteMutationIR,\n buildCanonicalDeleteAllMutationIR,\n buildCanonicalDeleteWhereMutationIR,\n} from './IRMutation.js';\nimport type {IRCreateQuery} from './CreateQuery.js';\nimport type {IRUpdateQuery} from './UpdateQuery.js';\nimport type {IRDeleteQuery} from './DeleteQuery.js';\nimport {isContextRefJSON, resolveContextId} from './ContextRef.js';\nimport {assertWireVersion} from './wireVersion.js';\nimport {\n decodeNodeDataToRaw,\n valueShapeOf,\n type MutationJSON,\n type MutationNodeDataJSON,\n type MutationValueJSON,\n} from './MutationSerialization.js';\nimport {assertValid, type ValidationMode} from '../shapes/validation.js';\nimport {decodeValueExpr, type DslJsonValue} from './DslJsonExpression.js';\nimport type {PropertyShapeData} from '../shapes/SHACL.js';\n\nfunction requireShape(shapeId: string): NodeShapeData {\n // Either registry: a project-authored shape arrives as metadata with no class, and\n // requiring a class here made every mutation against one fail at the boundary.\n const shape = getShapeClass(shapeId)?.shape ?? getNodeShape(shapeId);\n if (!shape) {\n throw new Error(\n `Shape '${shapeId}' is not registered. The receiving side must have the shape registered to lower mutation DSL-JSON.`,\n );\n }\n return shape;\n}\n\n// Bound the DSL-JSON decode recursion so a deeply-nested payload from\n// `fromJSON()` cannot exhaust the stack (RangeError DoS). Normal mutation data\n// nests only a handful of levels; 128 is far above any real query.\nconst MAX_DECODE_DEPTH = 128;\nlet _decodeDepth = 0;\n\n/**\n * Decode a DSL-JSON value to the normalized form the canonical-IR builders consume.\n * `currentShape` resolves computed `{@path}`/S-expr; `prop` gives a nested node's shape.\n * Depth-guarded wrapper around {@link decodeValueInner}.\n */\nfunction decodeValue(\n json: MutationValueJSON,\n currentShape: NodeShapeData,\n prop?: PropertyShapeData,\n): PropUpdateValue {\n if (++_decodeDepth > MAX_DECODE_DEPTH) {\n _decodeDepth = 0;\n throw new Error('DSL-JSON value nested too deeply');\n }\n try {\n return decodeValueInner(json, currentShape, prop);\n } finally {\n _decodeDepth--;\n }\n}\n\nfunction decodeValueInner(\n json: MutationValueJSON,\n currentShape: NodeShapeData,\n prop?: PropertyShapeData,\n): PropUpdateValue {\n // S-expr computed value (no IR on the wire)\n if (Array.isArray(json)) {\n const {ir, refs} = decodeValueExpr(json as DslJsonValue, currentShape);\n return new ExpressionNode(ir, refs) as unknown as PropUpdateValue;\n }\n if (json === null) return null as unknown as PropUpdateValue;\n if (typeof json !== 'object') return json as PropUpdateValue; // bare scalar literal\n const o = json as Record<string, unknown>;\n if ('@unset' in o) return undefined;\n if ('@date' in o) return new Date(o['@date'] as string) as unknown as PropUpdateValue;\n if ('@ctx' in o) {\n // Lowering path: a mutation must hit a concrete node, so resolve the\n // context now and throw if it isn't set.\n const id = resolveContextId(o['@ctx'] as string, true)!;\n return {id} as PropUpdateValue;\n }\n if ('@id' in o) return {id: o['@id']} as PropUpdateValue;\n if ('@list' in o) {\n return (o['@list'] as MutationValueJSON[]).map(\n (item) => decodeValue(item, currentShape, prop) as SinglePropertyUpdateValue,\n );\n }\n if ('@add' in o || '@remove' in o) {\n const mod: SetModificationValue = {};\n if (o['@add']) {\n mod.$add = (o['@add'] as MutationValueJSON[]).map((v) =>\n decodeValue(v, currentShape, prop),\n ) as SetModificationValue['$add'];\n }\n if (o['@remove']) mod.$remove = (o['@remove'] as string[]).map((id) => ({id}));\n return mod as PropUpdateValue;\n }\n if ('@path' in o) {\n const {ir, refs} = decodeValueExpr(json as DslJsonValue, currentShape);\n return new ExpressionNode(ir, refs) as unknown as PropUpdateValue;\n }\n // Otherwise: a bare path-keyed nested-node create.\n return decodeNodeData(\n o as MutationNodeDataJSON,\n valueShapeOf(prop) ?? currentShape,\n ) as unknown as PropUpdateValue;\n}\n\n/**\n * Rebuild a normalized node description from path-keyed JSON, resolving labels via the\n * shape. `shape` is the shape inferred from context; `__shape` overrides it.\n */\nexport function decodeNodeData(\n json: MutationNodeDataJSON,\n shape?: NodeShapeData,\n): NodeDescriptionValue {\n const nodeShape =\n typeof json.__shape === 'string' ? requireShape(json.__shape) : shape!;\n const fields: UpdateNodePropertyValue[] = [];\n for (const [key, val] of Object.entries(json)) {\n if (key === '__id' || key === '__shape' || key === '__blank' || val === undefined) continue;\n const prop = getPropertyShape(nodeShape, key);\n if (!prop) {\n throw new Error(\n `Property '${key}' not found on shape '${nodeShape.label || nodeShape.id}'`,\n );\n }\n fields.push({prop, val: decodeValue(val as MutationValueJSON, nodeShape, prop)} as UpdateNodePropertyValue);\n }\n const desc: NodeDescriptionValue = {shape: nodeShape, fields};\n if (typeof json.__id === 'string') desc.__id = json.__id;\n if (json.__blank !== undefined) {\n if (json.__blank !== true) throw new Error(`__blank must be true when given, got ${JSON.stringify(json.__blank)}`);\n desc.__blank = true;\n }\n return desc;\n}\n\nfunction lowerWhere(\n shape: NodeShapeData,\n json: WherePathJSON,\n): {where: IRExpression; wherePatterns: IRGraphPattern[]} {\n const wherePath = deserializeWherePath(shape, json);\n return lowerWhereToIR(toWhere(wherePath));\n}\n\n/**\n * Lower a mutation DSL-JSON envelope to the canonical IR mutation the dataset\n * expects. Mirrors the IR that `lower()` produces from the live builder.\n */\n/**\n * Validate inbound node data against its shape before it becomes IR.\n *\n * The builders validate through `describe()`, which sees raw DSL data. This path\n * never touches a builder, so without this an inbound mutation would be held to\n * a weaker standard than a locally-built one — on the *less* trusted input, at\n * that. `decodeNodeDataToRaw` produces exactly the raw form `describe()` would\n * have validated (it is what `CreateBuilder.fromJSON` feeds through `.set()`),\n * so both paths run the same checks. The second decode is the cost of validating\n * at a boundary; it happens once per inbound mutation.\n */\nfunction assertInboundDataValid(\n json: MutationNodeDataJSON,\n shape: NodeShapeData,\n mode: ValidationMode,\n): void {\n assertValid(shape, decodeNodeDataToRaw(json, shape), {mode});\n}\n\nexport function lowerMutationJSON(\n json: MutationJSON,\n): IRCreateQuery | IRUpdateQuery | IRDeleteQuery {\n assertWireVersion(json.v);\n switch (json.op) {\n case 'create': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'complete');\n return buildCanonicalCreateMutationIR({\n shape,\n description: decodeNodeData(json.data, shape),\n });\n }\n case 'upsert': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'partial');\n const updates = decodeNodeData(json.data, shape);\n const id = isContextRefJSON(json.targetId)\n ? resolveContextId(json.targetId['@ctx'], true)\n : json.targetId;\n if (!id) {\n throw new Error('upsert requires a targetId');\n }\n return buildCanonicalUpsertMutationIR({id, shape, updates});\n }\n case 'update': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'partial');\n const updates = decodeNodeData(json.data, shape);\n if (json.mode === 'for') {\n // A `{@ctx}` target resolves against the current context map; a mutation\n // must hit a concrete subject, so an unresolved context throws.\n const id = isContextRefJSON(json.targetId)\n ? resolveContextId(json.targetId['@ctx'], true)\n : json.targetId;\n if (!id) {\n throw new Error('update mode \"for\" requires a targetId');\n }\n return buildCanonicalUpdateMutationIR({id, shape, updates});\n }\n let where: IRExpression | undefined;\n let wherePatterns: IRGraphPattern[] | undefined;\n if (json.mode === 'where') {\n if (!json.where) throw new Error('update mode \"where\" requires a where clause');\n ({where, wherePatterns} = lowerWhere(shape, json.where));\n }\n return buildCanonicalUpdateWhereMutationIR({shape, updates, where, wherePatterns});\n }\n case 'delete': {\n const shape = requireShape(json.shape);\n if (json.mode === 'ids') {\n return buildCanonicalDeleteMutationIR({\n shape,\n // A `{@ctx}` id resolves against the live map; a delete must hit a\n // concrete node, so an unresolved context throws.\n ids: json.ids.map((id) =>\n isContextRefJSON(id) ? {id: resolveContextId(id['@ctx'], true)!} : {id},\n ),\n });\n }\n if (json.mode === 'all') {\n return buildCanonicalDeleteAllMutationIR({shape});\n }\n const {where, wherePatterns} = lowerWhere(shape, json.where);\n return buildCanonicalDeleteWhereMutationIR({shape, where, wherePatterns});\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lowerMutationJSON.js","sourceRoot":"","sources":["../../../src/queries/lowerMutationJSON.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AAQ5D,OAAO,EAAC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EACL,oBAAoB,GAErB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,YAAY,GAIb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,WAAW,EAAsB,MAAM,yBAAyB,CAAC;AACzE,O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to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n\n/**\n * Lower mutation DSL-JSON to canonical IR.\n *\n * This is the **IR side** of mutation (de)serialization, kept deliberately\n * separate from the IR-free wire codec in `MutationSerialization.ts`. The\n * canonical-IR builders (`IRMutation` / `IRLower` / …) are reachable only from\n * here and from `lower()`, so a client that serializes mutations to JSON and\n * forwards them (without ever lowering) tree-shakes the whole IR pipeline away.\n */\nimport type {NodeShapeData} from '../shapes/SHACL.js';\nimport {getPropertyShape} from '../shapes/nodeShapeData.js';\nimport {\n type NodeDescriptionValue,\n type PropUpdateValue,\n type SetModificationValue,\n type SinglePropertyUpdateValue,\n type UpdateNodePropertyValue,\n} from './QueryFactory.js';\nimport {ExpressionNode} from '../expressions/ExpressionNode.js';\nimport {getNodeShape, getShapeClass} from '../utils/ShapeClass.js';\nimport type {IRExpression, IRGraphPattern} from './IntermediateRepresentation.js';\nimport {\n deserializeWherePath,\n type WherePathJSON,\n} from './QueryBuilderSerialization.js';\nimport {toWhere} from './IRDesugar.js';\nimport {lowerWhereToIR} from './IRLower.js';\nimport {\n buildCanonicalCreateMutationIR,\n buildCanonicalUpdateMutationIR,\n buildCanonicalUpsertMutationIR,\n buildCanonicalUpdateWhereMutationIR,\n buildCanonicalDeleteMutationIR,\n buildCanonicalDeleteAllMutationIR,\n buildCanonicalDeleteWhereMutationIR,\n} from './IRMutation.js';\nimport type {IRCreateQuery} from './CreateQuery.js';\nimport type {IRUpdateQuery} from './UpdateQuery.js';\nimport type {IRDeleteQuery} from './DeleteQuery.js';\nimport {isContextRefJSON, resolveContextId} from './ContextRef.js';\nimport {assertWireVersion} from './wireVersion.js';\nimport {\n decodeNodeDataToRaw,\n valueShapeOf,\n type MutationJSON,\n type MutationNodeDataJSON,\n type MutationValueJSON,\n} from './MutationSerialization.js';\nimport {assertValid, type ValidationMode} from '../shapes/validation.js';\nimport {decodeValueExpr, type DslJsonValue} from './DslJsonExpression.js';\nimport type {PropertyShapeData} from '../shapes/SHACL.js';\n\nfunction requireShape(shapeId: string): NodeShapeData {\n // Either registry: a project-authored shape arrives as metadata with no class, and\n // requiring a class here made every mutation against one fail at the boundary.\n const shape = getShapeClass(shapeId)?.shape ?? getNodeShape(shapeId);\n if (!shape) {\n throw new Error(\n `Shape '${shapeId}' is not registered. The receiving side must have the shape registered to lower mutation DSL-JSON.`,\n );\n }\n return shape;\n}\n\n// Bound the DSL-JSON decode recursion so a deeply-nested payload from\n// `fromJSON()` cannot exhaust the stack (RangeError DoS). Normal mutation data\n// nests only a handful of levels; 128 is far above any real query.\nconst MAX_DECODE_DEPTH = 128;\nlet _decodeDepth = 0;\n\n/**\n * Decode a DSL-JSON value to the normalized form the canonical-IR builders consume.\n * `currentShape` resolves computed `{@path}`/S-expr; `prop` gives a nested node's shape.\n * Depth-guarded wrapper around {@link decodeValueInner}.\n */\nfunction decodeValue(\n json: MutationValueJSON,\n currentShape: NodeShapeData,\n prop?: PropertyShapeData,\n): PropUpdateValue {\n if (++_decodeDepth > MAX_DECODE_DEPTH) {\n _decodeDepth = 0;\n throw new Error('DSL-JSON value nested too deeply');\n }\n try {\n return decodeValueInner(json, currentShape, prop);\n } finally {\n _decodeDepth--;\n }\n}\n\nfunction decodeValueInner(\n json: MutationValueJSON,\n currentShape: NodeShapeData,\n prop?: PropertyShapeData,\n): PropUpdateValue {\n // S-expr computed value (no IR on the wire)\n if (Array.isArray(json)) {\n const {ir, refs} = decodeValueExpr(json as DslJsonValue, currentShape);\n return new ExpressionNode(ir, refs) as unknown as PropUpdateValue;\n }\n if (json === null) return null as unknown as PropUpdateValue;\n if (typeof json !== 'object') return json as PropUpdateValue; // bare scalar literal\n const o = json as Record<string, unknown>;\n if ('@unset' in o) return undefined;\n if ('@date' in o) return new Date(o['@date'] as string) as unknown as PropUpdateValue;\n if ('@ctx' in o) {\n // Lowering path: a mutation must hit a concrete node, so resolve the\n // context now and throw if it isn't set.\n const id = resolveContextId(o['@ctx'] as string, true)!;\n return {id} as PropUpdateValue;\n }\n if ('@id' in o) return {id: o['@id']} as PropUpdateValue;\n if ('@list' in o) {\n return (o['@list'] as MutationValueJSON[]).map(\n (item) => decodeValue(item, currentShape, prop) as SinglePropertyUpdateValue,\n );\n }\n if ('@add' in o || '@remove' in o) {\n const mod: SetModificationValue = {};\n if (o['@add']) {\n mod.$add = (o['@add'] as MutationValueJSON[]).map((v) =>\n decodeValue(v, currentShape, prop),\n ) as SetModificationValue['$add'];\n }\n if (o['@remove']) mod.$remove = (o['@remove'] as string[]).map((id) => ({id}));\n return mod as PropUpdateValue;\n }\n if ('@path' in o) {\n const {ir, refs} = decodeValueExpr(json as DslJsonValue, currentShape);\n return new ExpressionNode(ir, refs) as unknown as PropUpdateValue;\n }\n // Otherwise: a bare path-keyed nested-node create.\n return decodeNodeData(\n o as MutationNodeDataJSON,\n valueShapeOf(prop) ?? currentShape,\n ) as unknown as PropUpdateValue;\n}\n\n/**\n * Rebuild a normalized node description from path-keyed JSON, resolving labels via the\n * shape. `shape` is the shape inferred from context; `__shape` overrides it.\n */\nexport function decodeNodeData(\n json: MutationNodeDataJSON,\n shape?: NodeShapeData,\n): NodeDescriptionValue {\n const nodeShape =\n typeof json.__shape === 'string' ? requireShape(json.__shape) : shape!;\n const fields: UpdateNodePropertyValue[] = [];\n for (const [key, val] of Object.entries(json)) {\n if (key === '__id' || key === '__shape' || val === undefined) continue;\n const prop = getPropertyShape(nodeShape, key);\n if (!prop) {\n throw new Error(\n `Property '${key}' not found on shape '${nodeShape.label || nodeShape.id}'`,\n );\n }\n fields.push({prop, val: decodeValue(val as MutationValueJSON, nodeShape, prop)} as UpdateNodePropertyValue);\n }\n const desc: NodeDescriptionValue = {shape: nodeShape, fields};\n if (typeof json.__id === 'string') desc.__id = json.__id;\n return desc;\n}\n\nfunction lowerWhere(\n shape: NodeShapeData,\n json: WherePathJSON,\n): {where: IRExpression; wherePatterns: IRGraphPattern[]} {\n const wherePath = deserializeWherePath(shape, json);\n return lowerWhereToIR(toWhere(wherePath));\n}\n\n/**\n * Lower a mutation DSL-JSON envelope to the canonical IR mutation the dataset\n * expects. Mirrors the IR that `lower()` produces from the live builder.\n */\n/**\n * Validate inbound node data against its shape before it becomes IR.\n *\n * The builders validate through `describe()`, which sees raw DSL data. This path\n * never touches a builder, so without this an inbound mutation would be held to\n * a weaker standard than a locally-built one — on the *less* trusted input, at\n * that. `decodeNodeDataToRaw` produces exactly the raw form `describe()` would\n * have validated (it is what `CreateBuilder.fromJSON` feeds through `.set()`),\n * so both paths run the same checks. The second decode is the cost of validating\n * at a boundary; it happens once per inbound mutation.\n */\nfunction assertInboundDataValid(\n json: MutationNodeDataJSON,\n shape: NodeShapeData,\n mode: ValidationMode,\n): void {\n assertValid(shape, decodeNodeDataToRaw(json, shape), {mode});\n}\n\nexport function lowerMutationJSON(\n json: MutationJSON,\n): IRCreateQuery | IRUpdateQuery | IRDeleteQuery {\n assertWireVersion(json.v);\n switch (json.op) {\n case 'create': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'complete');\n return buildCanonicalCreateMutationIR({\n shape,\n description: decodeNodeData(json.data, shape),\n });\n }\n case 'upsert': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'partial');\n const updates = decodeNodeData(json.data, shape);\n const id = isContextRefJSON(json.targetId)\n ? resolveContextId(json.targetId['@ctx'], true)\n : json.targetId;\n if (!id) {\n throw new Error('upsert requires a targetId');\n }\n return buildCanonicalUpsertMutationIR({id, shape, updates});\n }\n case 'update': {\n const shape = requireShape(json.shape);\n assertInboundDataValid(json.data, shape, 'partial');\n const updates = decodeNodeData(json.data, shape);\n if (json.mode === 'for') {\n // A `{@ctx}` target resolves against the current context map; a mutation\n // must hit a concrete subject, so an unresolved context throws.\n const id = isContextRefJSON(json.targetId)\n ? resolveContextId(json.targetId['@ctx'], true)\n : json.targetId;\n if (!id) {\n throw new Error('update mode \"for\" requires a targetId');\n }\n return buildCanonicalUpdateMutationIR({id, shape, updates});\n }\n let where: IRExpression | undefined;\n let wherePatterns: IRGraphPattern[] | undefined;\n if (json.mode === 'where') {\n if (!json.where) throw new Error('update mode \"where\" requires a where clause');\n ({where, wherePatterns} = lowerWhere(shape, json.where));\n }\n return buildCanonicalUpdateWhereMutationIR({shape, updates, where, wherePatterns});\n }\n case 'delete': {\n const shape = requireShape(json.shape);\n if (json.mode === 'ids') {\n return buildCanonicalDeleteMutationIR({\n shape,\n // A `{@ctx}` id resolves against the live map; a delete must hit a\n // concrete node, so an unresolved context throws.\n ids: json.ids.map((id) =>\n isContextRefJSON(id) ? {id: resolveContextId(id['@ctx'], true)!} : {id},\n ),\n });\n }\n if (json.mode === 'all') {\n return buildCanonicalDeleteAllMutationIR({shape});\n }\n const {where, wherePatterns} = lowerWhere(shape, json.where);\n return buildCanonicalDeleteWhereMutationIR({shape, where, wherePatterns});\n }\n }\n}\n"]}
|
package/lib/esm/shapes/List.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../src/shapes/List.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,2FAA2F;AAC3F,yFAAyF;AACzF,wFAAwF;AACxF,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAC;AAEzC,OAAO,EAAC,IAAI,EAAC,CAAC;AASd;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,KAAU,EACV,IAAsB;IAEtB,MAAM,IAAI,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAC;IACxB,MAAM,KAAK,GAAG,CAAC,CAAS,EAAmB,EAAE;QAC3C,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,EAAC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAC,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,GAAoB;YAC5B,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACf,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;SACnB,CAAC;QACF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n// Registers List (together with the rest of the SHACL metamodel), so importing this module\n// on its own is enough to make List resolvable. The class lives in List.class.ts because\n// utils/Package.ts needs it by value and cannot import this module's registration path.\nimport '../utils/Package.js';\nimport {List} from './List.class.js';\nimport {rdf} from '../ontologies/rdf.js';\n\nexport {List};\n\n/**\n * Node-data for a single cell / the `rdf:nil` terminal. Accepted by the create pipeline.\n */\nexport type RdfListNodeData =\n | {id: string}\n | {shape: typeof List; first: unknown; rest: RdfListNodeData; __id?: string
|
|
1
|
+
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../src/shapes/List.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,2FAA2F;AAC3F,yFAAyF;AACzF,wFAAwF;AACxF,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAC;AAEzC,OAAO,EAAC,IAAI,EAAC,CAAC;AASd;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,KAAU,EACV,IAAsB;IAEtB,MAAM,IAAI,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAC;IACxB,MAAM,KAAK,GAAG,CAAC,CAAS,EAAmB,EAAE;QAC3C,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,EAAC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAC,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,GAAoB;YAC5B,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACf,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;SACnB,CAAC;QACF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n// Registers List (together with the rest of the SHACL metamodel), so importing this module\n// on its own is enough to make List resolvable. The class lives in List.class.ts because\n// utils/Package.ts needs it by value and cannot import this module's registration path.\nimport '../utils/Package.js';\nimport {List} from './List.class.js';\nimport {rdf} from '../ontologies/rdf.js';\n\nexport {List};\n\n/**\n * Node-data for a single cell / the `rdf:nil` terminal. Accepted by the create pipeline.\n */\nexport type RdfListNodeData =\n | {id: string}\n | {shape: typeof List; first: unknown; rest: RdfListNodeData; __id?: string};\n\n/**\n * Build the nested `List` node-data chain for an ordered `rdf:List`, terminating at `rdf:nil`.\n * Pass `opts.base` to mint deterministic cell ids (`{base}/0`, `{base}/1`, …); otherwise the\n * create pipeline mints ids. The empty list serializes to `rdf:nil`.\n *\n * @example Playlist.create({ tracks: rdfList([t1, t2, t3]) })\n */\nexport function rdfList<T>(\n items: T[],\n opts?: {base?: string},\n): RdfListNodeData {\n const base = opts?.base;\n const build = (i: number): RdfListNodeData => {\n if (i >= items.length) {\n return {id: rdf.nil.id};\n }\n const cell: RdfListNodeData = {\n shape: List,\n first: items[i],\n rest: build(i + 1),\n };\n if (base !== undefined) {\n cell.__id = `${base}/${i}`;\n }\n return cell;\n };\n return build(0);\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Shape } from './Shape.js';
|
|
2
|
+
/**
|
|
3
|
+
* A cell of the `rdf:List` inside a SHACL property path: the members of a sequence path, or the
|
|
4
|
+
* operand of `sh:alternativePath`.
|
|
5
|
+
*
|
|
6
|
+
* Both properties are `sh:BlankNodeOrIRI`, so a cell written without an id is a blank node, and so
|
|
7
|
+
* is an operator node (`PathNode`) held by `first`. That keeps a sequence path a blank list, which
|
|
8
|
+
* SHACL §2.3.1 needs: an IRI as the `sh:path` value is a predicate path.
|
|
9
|
+
*
|
|
10
|
+
* It is a separate shape from `List` on purpose. `List.first` also holds literals (`sh:in`), so it
|
|
11
|
+
* cannot be declared node-only, and making `List.rest` blank-capable would turn the tail cells of
|
|
12
|
+
* every list built without ids into blank nodes. Both shapes target `rdf:List`; `List` is
|
|
13
|
+
* registered first, so a lookup by `rdf:List` still returns `List`.
|
|
14
|
+
*
|
|
15
|
+
* `dependent` and the `contains` on `rest` keep removing the IRI-named, typed list cells of
|
|
16
|
+
* versions before 2.30 through the typed cascade.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PathList extends Shape {
|
|
19
|
+
static targetClass: import("../utils/NodeReference.js").NodeReferenceValue;
|
|
20
|
+
/**
|
|
21
|
+
* A predicate IRI, or an operator node (`PathNode`). Not `contains`: ownership is decided per
|
|
22
|
+
* predicate across the registry, and `rdf:first` of every other list holds values the list
|
|
23
|
+
* does not own. The blank-node cascade follows it anyway, because it is blank-capable.
|
|
24
|
+
*/
|
|
25
|
+
get first(): unknown;
|
|
26
|
+
get rest(): PathList;
|
|
27
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
/*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
11
|
+
*/
|
|
12
|
+
import { linkedShape } from '../package.js';
|
|
13
|
+
import { Shape } from './Shape.js';
|
|
14
|
+
import { objectProperty } from './SHACL.js';
|
|
15
|
+
import { shacl } from '../ontologies/shacl.js';
|
|
16
|
+
import { rdf } from '../ontologies/rdf.js';
|
|
17
|
+
/**
|
|
18
|
+
* A cell of the `rdf:List` inside a SHACL property path: the members of a sequence path, or the
|
|
19
|
+
* operand of `sh:alternativePath`.
|
|
20
|
+
*
|
|
21
|
+
* Both properties are `sh:BlankNodeOrIRI`, so a cell written without an id is a blank node, and so
|
|
22
|
+
* is an operator node (`PathNode`) held by `first`. That keeps a sequence path a blank list, which
|
|
23
|
+
* SHACL §2.3.1 needs: an IRI as the `sh:path` value is a predicate path.
|
|
24
|
+
*
|
|
25
|
+
* It is a separate shape from `List` on purpose. `List.first` also holds literals (`sh:in`), so it
|
|
26
|
+
* cannot be declared node-only, and making `List.rest` blank-capable would turn the tail cells of
|
|
27
|
+
* every list built without ids into blank nodes. Both shapes target `rdf:List`; `List` is
|
|
28
|
+
* registered first, so a lookup by `rdf:List` still returns `List`.
|
|
29
|
+
*
|
|
30
|
+
* `dependent` and the `contains` on `rest` keep removing the IRI-named, typed list cells of
|
|
31
|
+
* versions before 2.30 through the typed cascade.
|
|
32
|
+
*/
|
|
33
|
+
let PathList = class PathList extends Shape {
|
|
34
|
+
/**
|
|
35
|
+
* A predicate IRI, or an operator node (`PathNode`). Not `contains`: ownership is decided per
|
|
36
|
+
* predicate across the registry, and `rdf:first` of every other list holds values the list
|
|
37
|
+
* does not own. The blank-node cascade follows it anyway, because it is blank-capable.
|
|
38
|
+
*/
|
|
39
|
+
get first() {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
get rest() {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
PathList.targetClass = rdf.List;
|
|
47
|
+
__decorate([
|
|
48
|
+
objectProperty({ path: rdf.first, maxCount: 1, nodeKind: shacl.BlankNodeOrIRI })
|
|
49
|
+
], PathList.prototype, "first", null);
|
|
50
|
+
__decorate([
|
|
51
|
+
objectProperty({
|
|
52
|
+
path: rdf.rest,
|
|
53
|
+
maxCount: 1,
|
|
54
|
+
shape: PathList,
|
|
55
|
+
contains: true,
|
|
56
|
+
nodeKind: shacl.BlankNodeOrIRI,
|
|
57
|
+
})
|
|
58
|
+
], PathList.prototype, "rest", null);
|
|
59
|
+
PathList = __decorate([
|
|
60
|
+
linkedShape({ name: 'PathList', dependent: true })
|
|
61
|
+
], PathList);
|
|
62
|
+
export { PathList };
|
|
63
|
+
//# sourceMappingURL=PathList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathList.js","sourceRoot":"","sources":["../../../src/shapes/PathList.ts"],"names":[],"mappings":";;;;;;AAAA;;;;GAIG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAC;AAEzC;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,KAAK;IAGjC;;;;OAIG;IAEH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IASD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC;IACd,CAAC;;AArBM,oBAAW,GAAG,GAAG,CAAC,IAAI,AAAX,CAAY;AAQ9B;IADC,cAAc,CAAC,EAAC,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,EAAC,CAAC;qCAG9E;AASD;IAPC,cAAc,CAAC;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK,CAAC,cAAc;KAC/B,CAAC;oCAGD;AAtBU,QAAQ;IADpB,WAAW,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC;GACpC,QAAQ,CAuBpB","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\nimport {linkedShape} from '../package.js';\nimport {Shape} from './Shape.js';\nimport {objectProperty} from './SHACL.js';\nimport {shacl} from '../ontologies/shacl.js';\nimport {rdf} from '../ontologies/rdf.js';\n\n/**\n * A cell of the `rdf:List` inside a SHACL property path: the members of a sequence path, or the\n * operand of `sh:alternativePath`.\n *\n * Both properties are `sh:BlankNodeOrIRI`, so a cell written without an id is a blank node, and so\n * is an operator node (`PathNode`) held by `first`. That keeps a sequence path a blank list, which\n * SHACL §2.3.1 needs: an IRI as the `sh:path` value is a predicate path.\n *\n * It is a separate shape from `List` on purpose. `List.first` also holds literals (`sh:in`), so it\n * cannot be declared node-only, and making `List.rest` blank-capable would turn the tail cells of\n * every list built without ids into blank nodes. Both shapes target `rdf:List`; `List` is\n * registered first, so a lookup by `rdf:List` still returns `List`.\n *\n * `dependent` and the `contains` on `rest` keep removing the IRI-named, typed list cells of\n * versions before 2.30 through the typed cascade.\n */\n@linkedShape({name: 'PathList', dependent: true})\nexport class PathList extends Shape {\n static targetClass = rdf.List;\n\n /**\n * A predicate IRI, or an operator node (`PathNode`). Not `contains`: ownership is decided per\n * predicate across the registry, and `rdf:first` of every other list holds values the list\n * does not own. The blank-node cascade follows it anyway, because it is blank-capable.\n */\n @objectProperty({path: rdf.first, maxCount: 1, nodeKind: shacl.BlankNodeOrIRI})\n get first(): unknown {\n return null;\n }\n\n @objectProperty({\n path: rdf.rest,\n maxCount: 1,\n shape: PathList,\n contains: true,\n nodeKind: shacl.BlankNodeOrIRI,\n })\n get rest(): PathList {\n return null;\n }\n}\n"]}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { Shape } from './Shape.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PathList } from './PathList.js';
|
|
3
3
|
/**
|
|
4
4
|
* Operator node for SHACL property paths that are NOT a simple predicate or a sequence:
|
|
5
5
|
* inverse (`sh:inversePath`), alternative (`sh:alternativePath` → an `rdf:List`), and the
|
|
6
6
|
* cardinality forms (`sh:zeroOrMorePath`/`sh:oneOrMorePath`/`sh:zeroOrOnePath`).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* only form SHACL §2.3.1 defines, a blank node that is
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* Every slot is `sh:BlankNodeOrIRI`, as is `PropertyShape.path`, so an operator node written
|
|
9
|
+
* without an id is an untyped blank node: the only form SHACL §2.3.1 defines, a blank node that is
|
|
10
|
+
* the subject of exactly one triple (see `serializePathToNodeData`). The blank-node cascade
|
|
11
|
+
* follows these blank-capable slots on delete / replace. The class stays `dependent`, with
|
|
12
|
+
* `contains` slots and its `core:PathNode` type, for the IRI-named, typed nodes versions before
|
|
13
|
+
* 2.30 wrote: the typed cascade removes those on the next sync.
|
|
14
|
+
* Operands are polymorphic (a predicate IRI, a nested `PathNode`, or a `PathList`), so no fixed
|
|
15
|
+
* `valueShape` is declared except for `alternativePath`, which is always a `PathList`.
|
|
15
16
|
*/
|
|
16
17
|
export declare class PathNode extends Shape {
|
|
17
18
|
static targetClass: import("../utils/NodeReference.js").NodeReferenceValue;
|
|
18
19
|
get inversePath(): unknown;
|
|
19
|
-
get alternativePath():
|
|
20
|
+
get alternativePath(): PathList;
|
|
20
21
|
get zeroOrMorePath(): unknown;
|
|
21
22
|
get oneOrMorePath(): unknown;
|
|
22
23
|
get zeroOrOnePath(): unknown;
|
|
@@ -14,19 +14,21 @@ import { Shape } from './Shape.js';
|
|
|
14
14
|
import { objectProperty } from './SHACL.js';
|
|
15
15
|
import { shacl } from '../ontologies/shacl.js';
|
|
16
16
|
import { coreOntology } from '../ontologies/linked-core.js';
|
|
17
|
-
import {
|
|
17
|
+
import { PathList } from './PathList.js';
|
|
18
|
+
const BLANK_OR_IRI = shacl.BlankNodeOrIRI;
|
|
18
19
|
/**
|
|
19
20
|
* Operator node for SHACL property paths that are NOT a simple predicate or a sequence:
|
|
20
21
|
* inverse (`sh:inversePath`), alternative (`sh:alternativePath` → an `rdf:List`), and the
|
|
21
22
|
* cardinality forms (`sh:zeroOrMorePath`/`sh:oneOrMorePath`/`sh:zeroOrOnePath`).
|
|
22
23
|
*
|
|
23
|
-
*
|
|
24
|
-
* only form SHACL §2.3.1 defines, a blank node that is
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
24
|
+
* Every slot is `sh:BlankNodeOrIRI`, as is `PropertyShape.path`, so an operator node written
|
|
25
|
+
* without an id is an untyped blank node: the only form SHACL §2.3.1 defines, a blank node that is
|
|
26
|
+
* the subject of exactly one triple (see `serializePathToNodeData`). The blank-node cascade
|
|
27
|
+
* follows these blank-capable slots on delete / replace. The class stays `dependent`, with
|
|
28
|
+
* `contains` slots and its `core:PathNode` type, for the IRI-named, typed nodes versions before
|
|
29
|
+
* 2.30 wrote: the typed cascade removes those on the next sync.
|
|
30
|
+
* Operands are polymorphic (a predicate IRI, a nested `PathNode`, or a `PathList`), so no fixed
|
|
31
|
+
* `valueShape` is declared except for `alternativePath`, which is always a `PathList`.
|
|
30
32
|
*/
|
|
31
33
|
// Named explicitly: the class shares its name with the ontology term coreOntology.PathNode,
|
|
32
34
|
// and a bundler resolving that collision renames the class (PathNode2), which would change
|
|
@@ -50,19 +52,25 @@ let PathNode = class PathNode extends Shape {
|
|
|
50
52
|
};
|
|
51
53
|
PathNode.targetClass = coreOntology.PathNode;
|
|
52
54
|
__decorate([
|
|
53
|
-
objectProperty({ path: shacl.inversePath, maxCount: 1, contains: true })
|
|
55
|
+
objectProperty({ path: shacl.inversePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI })
|
|
54
56
|
], PathNode.prototype, "inversePath", null);
|
|
55
57
|
__decorate([
|
|
56
|
-
objectProperty({
|
|
58
|
+
objectProperty({
|
|
59
|
+
path: shacl.alternativePath,
|
|
60
|
+
maxCount: 1,
|
|
61
|
+
shape: PathList,
|
|
62
|
+
contains: true,
|
|
63
|
+
nodeKind: BLANK_OR_IRI,
|
|
64
|
+
})
|
|
57
65
|
], PathNode.prototype, "alternativePath", null);
|
|
58
66
|
__decorate([
|
|
59
|
-
objectProperty({ path: shacl.zeroOrMorePath, maxCount: 1, contains: true })
|
|
67
|
+
objectProperty({ path: shacl.zeroOrMorePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI })
|
|
60
68
|
], PathNode.prototype, "zeroOrMorePath", null);
|
|
61
69
|
__decorate([
|
|
62
|
-
objectProperty({ path: shacl.oneOrMorePath, maxCount: 1, contains: true })
|
|
70
|
+
objectProperty({ path: shacl.oneOrMorePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI })
|
|
63
71
|
], PathNode.prototype, "oneOrMorePath", null);
|
|
64
72
|
__decorate([
|
|
65
|
-
objectProperty({ path: shacl.zeroOrOnePath, maxCount: 1, contains: true })
|
|
73
|
+
objectProperty({ path: shacl.zeroOrOnePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI })
|
|
66
74
|
], PathNode.prototype, "zeroOrOnePath", null);
|
|
67
75
|
PathNode = __decorate([
|
|
68
76
|
linkedShape({ name: 'PathNode', dependent: true })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathNode.js","sourceRoot":"","sources":["../../../src/shapes/PathNode.ts"],"names":[],"mappings":";;;;;;AAAA;;;;GAIG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"PathNode.js","sourceRoot":"","sources":["../../../src/shapes/PathNode.ts"],"names":[],"mappings":";;;;;;AAAA;;;;GAIG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC,MAAM,YAAY,GAAG,KAAK,CAAC,cAAc,CAAC;AAE1C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AAhCU,QAAQ;IADpB,WAAW,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC;GACpC,QAAQ,CAiCpB","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\nimport {linkedShape} from '../package.js';\nimport {Shape} from './Shape.js';\nimport {objectProperty} from './SHACL.js';\nimport {shacl} from '../ontologies/shacl.js';\nimport {coreOntology} from '../ontologies/linked-core.js';\nimport {PathList} from './PathList.js';\n\nconst BLANK_OR_IRI = shacl.BlankNodeOrIRI;\n\n/**\n * Operator node for SHACL property paths that are NOT a simple predicate or a sequence:\n * inverse (`sh:inversePath`), alternative (`sh:alternativePath` → an `rdf:List`), and the\n * cardinality forms (`sh:zeroOrMorePath`/`sh:oneOrMorePath`/`sh:zeroOrOnePath`).\n *\n * Every slot is `sh:BlankNodeOrIRI`, as is `PropertyShape.path`, so an operator node written\n * without an id is an untyped blank node: the only form SHACL §2.3.1 defines, a blank node that is\n * the subject of exactly one triple (see `serializePathToNodeData`). The blank-node cascade\n * follows these blank-capable slots on delete / replace. The class stays `dependent`, with\n * `contains` slots and its `core:PathNode` type, for the IRI-named, typed nodes versions before\n * 2.30 wrote: the typed cascade removes those on the next sync.\n * Operands are polymorphic (a predicate IRI, a nested `PathNode`, or a `PathList`), so no fixed\n * `valueShape` is declared except for `alternativePath`, which is always a `PathList`.\n */\n// Named explicitly: the class shares its name with the ontology term coreOntology.PathNode,\n// and a bundler resolving that collision renames the class (PathNode2), which would change\n// the shape's IRI.\n@linkedShape({name: 'PathNode', dependent: true})\nexport class PathNode extends Shape {\n static targetClass = coreOntology.PathNode;\n\n @objectProperty({path: shacl.inversePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI})\n get inversePath(): unknown {\n return null;\n }\n\n @objectProperty({\n path: shacl.alternativePath,\n maxCount: 1,\n shape: PathList,\n contains: true,\n nodeKind: BLANK_OR_IRI,\n })\n get alternativePath(): PathList {\n return null;\n }\n\n @objectProperty({path: shacl.zeroOrMorePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI})\n get zeroOrMorePath(): unknown {\n return null;\n }\n\n @objectProperty({path: shacl.oneOrMorePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI})\n get oneOrMorePath(): unknown {\n return null;\n }\n\n @objectProperty({path: shacl.zeroOrOnePath, maxCount: 1, contains: true, nodeKind: BLANK_OR_IRI})\n get zeroOrOnePath(): unknown {\n return null;\n }\n}\n"]}
|
package/lib/esm/shapes/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qFAAqF;AACrF,mFAAmF;AACnF,EAAE;AACF,2FAA2F;AAC3F,qFAAqF;AACrF,OAAO,YAAY,CAAC;AACpB,OAAO,WAAW,CAAC;AACnB,OAAO,eAAe,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n// Loads every shape @_linked/core defines, for their registration side effects only.\n// Consumers: `import '@_linked/core/shapes/index'`. Nothing is exported from here.\n//\n// Shape, NodeShape, PropertyShape and List are registered by utils/Package.ts, because the\n// SHACL metamodel cannot decorate itself. List.js loads it; SHACL.js alone does not.\nimport './SHACL.js';\nimport './List.js';\nimport './PathNode.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qFAAqF;AACrF,mFAAmF;AACnF,EAAE;AACF,2FAA2F;AAC3F,qFAAqF;AACrF,OAAO,YAAY,CAAC;AACpB,OAAO,WAAW,CAAC;AACnB,OAAO,eAAe,CAAC;AACvB,OAAO,eAAe,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\n// Loads every shape @_linked/core defines, for their registration side effects only.\n// Consumers: `import '@_linked/core/shapes/index'`. Nothing is exported from here.\n//\n// Shape, NodeShape, PropertyShape and List are registered by utils/Package.ts, because the\n// SHACL metamodel cannot decorate itself. List.js loads it; SHACL.js alone does not.\nimport './SHACL.js';\nimport './List.js';\nimport './PathList.js';\nimport './PathNode.js';\n"]}
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import type { PathExpr } from '../paths/PropertyPathExpr.js';
|
|
2
2
|
import type { NodeReferenceValue } from '../utils/NodeReference.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PathList } from './PathList.js';
|
|
4
4
|
import { PathNode } from './PathNode.js';
|
|
5
5
|
/**
|
|
6
6
|
* Node-data the create pipeline accepts for a `sh:path` value: an IRI reference (simple path),
|
|
7
|
-
*
|
|
7
|
+
* a `PathList` (sequence / alternative members), or a `PathNode` operator node.
|
|
8
8
|
*/
|
|
9
9
|
export type PathNodeData = NodeReferenceValue | {
|
|
10
|
-
shape: typeof
|
|
11
|
-
__blank: true;
|
|
10
|
+
shape: typeof PathList | typeof PathNode;
|
|
12
11
|
[k: string]: unknown;
|
|
13
12
|
};
|
|
14
13
|
/**
|
|
15
14
|
* Translate a `PathExpr` into create-pipeline node-data for `sh:path`.
|
|
16
15
|
*
|
|
17
16
|
* - simple `PathRef` → `{id}` (a shared predicate IRI; NOT owned)
|
|
18
|
-
* - sequence → an `rdf:List` of segments
|
|
19
|
-
* - inverse / alternative / cardinality → a `PathNode` operator node (alt's operand is
|
|
17
|
+
* - sequence → a `PathList` (an `rdf:List`) of segments
|
|
18
|
+
* - inverse / alternative / cardinality → a `PathNode` operator node (alt's operand is a `PathList`)
|
|
20
19
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* Operator nodes and list cells carry no id. `PropertyShape.path`, the `PathNode` slots and
|
|
21
|
+
* `PathList.first` / `.rest` are `sh:BlankNodeOrIRI`, so the create writes each of them as an
|
|
22
|
+
* untyped blank node, the only form SHACL §2.3.1 defines: an IRI in `sh:path` is a predicate path,
|
|
23
|
+
* and an inverse, alternative or cardinality path is a blank node that is the subject of exactly
|
|
24
|
+
* one triple.
|
|
24
25
|
*
|
|
25
26
|
* ```turtle
|
|
26
27
|
* <ps> sh:path [ sh:inversePath schema:image ] .
|
|
27
28
|
* <ps> sh:path ( schema:knows [ sh:zeroOrMorePath schema:parent ] ) .
|
|
28
29
|
* ```
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* A re-sync's delete removes the structure (the blank-node cascade follows the blank-capable
|
|
32
|
+
* properties) before the create writes it again.
|
|
32
33
|
*
|
|
33
34
|
* @param _base ignored. It seeded the IRIs of the nodes this used to mint (`{base}/inv`, …);
|
|
34
35
|
* blank nodes have none. Kept so existing two-argument calls still compile.
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { isPathRef } from '../paths/PropertyPathExpr.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PathList } from './PathList.js';
|
|
3
3
|
import { rdf } from '../ontologies/rdf.js';
|
|
4
4
|
import { PathNode } from './PathNode.js';
|
|
5
5
|
/**
|
|
6
6
|
* Translate a `PathExpr` into create-pipeline node-data for `sh:path`.
|
|
7
7
|
*
|
|
8
8
|
* - simple `PathRef` → `{id}` (a shared predicate IRI; NOT owned)
|
|
9
|
-
* - sequence → an `rdf:List` of segments
|
|
10
|
-
* - inverse / alternative / cardinality → a `PathNode` operator node (alt's operand is
|
|
9
|
+
* - sequence → a `PathList` (an `rdf:List`) of segments
|
|
10
|
+
* - inverse / alternative / cardinality → a `PathNode` operator node (alt's operand is a `PathList`)
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Operator nodes and list cells carry no id. `PropertyShape.path`, the `PathNode` slots and
|
|
13
|
+
* `PathList.first` / `.rest` are `sh:BlankNodeOrIRI`, so the create writes each of them as an
|
|
14
|
+
* untyped blank node, the only form SHACL §2.3.1 defines: an IRI in `sh:path` is a predicate path,
|
|
15
|
+
* and an inverse, alternative or cardinality path is a blank node that is the subject of exactly
|
|
16
|
+
* one triple.
|
|
15
17
|
*
|
|
16
18
|
* ```turtle
|
|
17
19
|
* <ps> sh:path [ sh:inversePath schema:image ] .
|
|
18
20
|
* <ps> sh:path ( schema:knows [ sh:zeroOrMorePath schema:parent ] ) .
|
|
19
21
|
* ```
|
|
20
22
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* A re-sync's delete removes the structure (the blank-node cascade follows the blank-capable
|
|
24
|
+
* properties) before the create writes it again.
|
|
23
25
|
*
|
|
24
26
|
* @param _base ignored. It seeded the IRIs of the nodes this used to mint (`{base}/inv`, …);
|
|
25
27
|
* blank nodes have none. Kept so existing two-argument calls still compile.
|
|
@@ -27,7 +29,6 @@ import { PathNode } from './PathNode.js';
|
|
|
27
29
|
export function serializePathToNodeData(path, _base) {
|
|
28
30
|
const operator = (key, operand) => ({
|
|
29
31
|
shape: PathNode,
|
|
30
|
-
__blank: true,
|
|
31
32
|
[key]: operand,
|
|
32
33
|
});
|
|
33
34
|
const serialize = (e) => {
|
|
@@ -71,8 +72,8 @@ export function serializePathToNodeData(path, _base) {
|
|
|
71
72
|
};
|
|
72
73
|
return serialize(path);
|
|
73
74
|
}
|
|
74
|
-
/**
|
|
75
|
+
/** A `PathList` of cells without ids (blank once written), terminated by `rdf:nil`. */
|
|
75
76
|
function blankList(items) {
|
|
76
|
-
return items.reduceRight((rest, first) => ({ shape:
|
|
77
|
+
return items.reduceRight((rest, first) => ({ shape: PathList, first, rest }), { id: rdf.nil.id });
|
|
77
78
|
}
|
|
78
79
|
//# sourceMappingURL=serializePathToNodeData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializePathToNodeData.js","sourceRoot":"","sources":["../../../src/shapes/serializePathToNodeData.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AAEvD,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"serializePathToNodeData.js","sourceRoot":"","sources":["../../../src/shapes/serializePathToNodeData.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AAEvD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAUvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAc,EAAE,KAAc;IACpE,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,OAAgB,EAAgB,EAAE,CAAC,CAAC;QACjE,KAAK,EAAE,QAAQ;QACf,CAAC,GAAG,CAAC,EAAE,OAAO;KACf,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,CAAC,CAAW,EAAgB,EAAE;QAC9C,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,OAAO,EAAC,EAAE,EAAE,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAC,CAAC;QAChD,CAAC;QACD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,yEAAyE;YACzE,yEAAyE;YACzE,wEAAwE;YACxE,yEAAyE;YACzE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;YAC/E,CAAC;YACD,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO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AAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC;IACF,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,uFAAuF;AACvF,SAAS,SAAS,CAAC,KAAqB;IACtC,OAAO,KAAK,CAAC,WAAW,CACtB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,EACjD,EAAC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAC,CACjB,CAAC;AACJ,CAAC","sourcesContent":["/*\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/.\n */\nimport type {PathExpr} from '../paths/PropertyPathExpr.js';\nimport {isPathRef} from '../paths/PropertyPathExpr.js';\nimport type {NodeReferenceValue} from '../utils/NodeReference.js';\nimport {PathList} from './PathList.js';\nimport {rdf} from '../ontologies/rdf.js';\nimport {PathNode} from './PathNode.js';\n\n/**\n * Node-data the create pipeline accepts for a `sh:path` value: an IRI reference (simple path),\n * a `PathList` (sequence / alternative members), or a `PathNode` operator node.\n */\nexport type PathNodeData =\n | NodeReferenceValue\n | {shape: typeof PathList | typeof PathNode; [k: string]: unknown};\n\n/**\n * Translate a `PathExpr` into create-pipeline node-data for `sh:path`.\n *\n * - simple `PathRef` → `{id}` (a shared predicate IRI; NOT owned)\n * - sequence → a `PathList` (an `rdf:List`) of segments\n * - inverse / alternative / cardinality → a `PathNode` operator node (alt's operand is a `PathList`)\n *\n * Operator nodes and list cells carry no id. `PropertyShape.path`, the `PathNode` slots and\n * `PathList.first` / `.rest` are `sh:BlankNodeOrIRI`, so the create writes each of them as an\n * untyped blank node, the only form SHACL §2.3.1 defines: an IRI in `sh:path` is a predicate path,\n * and an inverse, alternative or cardinality path is a blank node that is the subject of exactly\n * one triple.\n *\n * ```turtle\n * <ps> sh:path [ sh:inversePath schema:image ] .\n * <ps> sh:path ( schema:knows [ sh:zeroOrMorePath schema:parent ] ) .\n * ```\n *\n * A re-sync's delete removes the structure (the blank-node cascade follows the blank-capable\n * properties) before the create writes it again.\n *\n * @param _base ignored. It seeded the IRIs of the nodes this used to mint (`{base}/inv`, …);\n * blank nodes have none. Kept so existing two-argument calls still compile.\n */\nexport function serializePathToNodeData(path: PathExpr, _base?: string): PathNodeData {\n const operator = (key: string, operand: unknown): PathNodeData => ({\n shape: PathNode,\n [key]: operand,\n });\n const serialize = (e: PathExpr): PathNodeData => {\n if (isPathRef(e)) {\n return {id: typeof e === 'string' ? e : e.id};\n }\n if ('seq' in e) {\n // SHACL §2.3.1: a sequence path is a list with **at least two** members.\n // A 0/1-member sequence is not a list — collapse a singleton to its bare\n // member, reject an empty one. (normalizePropertyPath already collapses\n // these upstream; this keeps the serializer independently spec-correct.)\n if (e.seq.length === 0) {\n throw new Error('Cannot serialize an empty sequence path to SHACL sh:path.');\n }\n if (e.seq.length === 1) return serialize(e.seq[0]);\n return blankList(e.seq.map(serialize));\n }\n if ('inv' in e) return operator('inversePath', serialize(e.inv));\n if ('alt' in e) {\n // SHACL §2.3.2: sh:alternativePath is a list with **at least two** members.\n // Collapse a singleton alternative to its bare member, reject an empty one.\n if (e.alt.length === 0) {\n throw new Error('Cannot serialize an empty alternative path to SHACL sh:path.');\n }\n if (e.alt.length === 1) return serialize(e.alt[0]);\n return operator('alternativePath', blankList(e.alt.map(serialize)));\n }\n if ('zeroOrMore' in e) return operator('zeroOrMorePath', serialize(e.zeroOrMore));\n if ('oneOrMore' in e) return operator('oneOrMorePath', serialize(e.oneOrMore));\n if ('zeroOrOne' in e) return operator('zeroOrOnePath', serialize(e.zeroOrOne));\n if ('negatedPropertySet' in e) {\n throw new Error(\n 'negatedPropertySet cannot be serialized to SHACL sh:path — no SHACL representation.',\n );\n }\n throw new Error(`Unknown PathExpr shape: ${JSON.stringify(e)}`);\n };\n return serialize(path);\n}\n\n/** A `PathList` of cells without ids (blank once written), terminated by `rdf:nil`. */\nfunction blankList(items: PathNodeData[]): PathNodeData {\n return items.reduceRight<PathNodeData>(\n (rest, first) => ({shape: PathList, first, rest}),\n {id: rdf.nil.id},\n );\n}\n"]}
|
|
@@ -55,10 +55,10 @@ export class ShapeValidationError extends Error {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Keys that carry metadata about the node rather than a property value: `id` /
|
|
58
|
-
* `__id` name it,
|
|
58
|
+
* `__id` name it, and `shape` names the shape of a nested value when the
|
|
59
59
|
* property shape itself doesn't declare one (see `convertUpdateValue`).
|
|
60
60
|
*/
|
|
61
|
-
const RESERVED_KEYS = new Set(['id', '__id', '
|
|
61
|
+
const RESERVED_KEYS = new Set(['id', '__id', 'shape']);
|
|
62
62
|
/**
|
|
63
63
|
* The message for an undeclared property key. Shared with the normalization path
|
|
64
64
|
* in `MutationQuery`, which needs the same guard to build a field at all.
|