@_linked/core 2.12.0 → 2.13.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.
Files changed (246) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/lib/esm/queries/IRPipeline.d.ts +7 -1
  3. package/lib/esm/queries/IRPipeline.js +20 -6
  4. package/lib/esm/queries/IRPipeline.js.map +1 -1
  5. package/lib/esm/queries/queryDispatch.js +12 -2
  6. package/lib/esm/queries/queryDispatch.js.map +1 -1
  7. package/package.json +10 -13
  8. package/lib/cjs/collections/CoreSet.d.ts +0 -47
  9. package/lib/cjs/collections/CoreSet.js +0 -136
  10. package/lib/cjs/collections/CoreSet.js.map +0 -1
  11. package/lib/cjs/collections/ShapeSet.d.ts +0 -6
  12. package/lib/cjs/collections/ShapeSet.js +0 -20
  13. package/lib/cjs/collections/ShapeSet.js.map +0 -1
  14. package/lib/cjs/expressions/Expr.d.ts +0 -29
  15. package/lib/cjs/expressions/Expr.js +0 -80
  16. package/lib/cjs/expressions/Expr.js.map +0 -1
  17. package/lib/cjs/expressions/ExpressionMethods.d.ts +0 -85
  18. package/lib/cjs/expressions/ExpressionMethods.js +0 -3
  19. package/lib/cjs/expressions/ExpressionMethods.js.map +0 -1
  20. package/lib/cjs/expressions/ExpressionNode.d.ts +0 -144
  21. package/lib/cjs/expressions/ExpressionNode.js +0 -432
  22. package/lib/cjs/expressions/ExpressionNode.js.map +0 -1
  23. package/lib/cjs/index.d.ts +0 -29
  24. package/lib/cjs/index.js +0 -65
  25. package/lib/cjs/index.js.map +0 -1
  26. package/lib/cjs/interfaces/ICoreIterable.d.ts +0 -14
  27. package/lib/cjs/interfaces/ICoreIterable.js +0 -3
  28. package/lib/cjs/interfaces/ICoreIterable.js.map +0 -1
  29. package/lib/cjs/interfaces/IDataset.d.ts +0 -26
  30. package/lib/cjs/interfaces/IDataset.js +0 -3
  31. package/lib/cjs/interfaces/IDataset.js.map +0 -1
  32. package/lib/cjs/interfaces/IFileStore.d.ts +0 -16
  33. package/lib/cjs/interfaces/IFileStore.js +0 -3
  34. package/lib/cjs/interfaces/IFileStore.js.map +0 -1
  35. package/lib/cjs/ontologies/linked-core.d.ts +0 -15
  36. package/lib/cjs/ontologies/linked-core.js +0 -38
  37. package/lib/cjs/ontologies/linked-core.js.map +0 -1
  38. package/lib/cjs/ontologies/npm.d.ts +0 -6
  39. package/lib/cjs/ontologies/npm.js +0 -15
  40. package/lib/cjs/ontologies/npm.js.map +0 -1
  41. package/lib/cjs/ontologies/owl.d.ts +0 -14
  42. package/lib/cjs/ontologies/owl.js +0 -21
  43. package/lib/cjs/ontologies/owl.js.map +0 -1
  44. package/lib/cjs/ontologies/rdf.d.ts +0 -13
  45. package/lib/cjs/ontologies/rdf.js +0 -27
  46. package/lib/cjs/ontologies/rdf.js.map +0 -1
  47. package/lib/cjs/ontologies/rdfs.d.ts +0 -16
  48. package/lib/cjs/ontologies/rdfs.js +0 -33
  49. package/lib/cjs/ontologies/rdfs.js.map +0 -1
  50. package/lib/cjs/ontologies/shacl.d.ts +0 -103
  51. package/lib/cjs/ontologies/shacl.js +0 -152
  52. package/lib/cjs/ontologies/shacl.js.map +0 -1
  53. package/lib/cjs/ontologies/xsd.d.ts +0 -19
  54. package/lib/cjs/ontologies/xsd.js +0 -41
  55. package/lib/cjs/ontologies/xsd.js.map +0 -1
  56. package/lib/cjs/package.d.ts +0 -4
  57. package/lib/cjs/package.js +0 -6
  58. package/lib/cjs/package.js.map +0 -1
  59. package/lib/cjs/package.json +0 -9
  60. package/lib/cjs/paths/PropertyPathExpr.d.ts +0 -38
  61. package/lib/cjs/paths/PropertyPathExpr.js +0 -221
  62. package/lib/cjs/paths/PropertyPathExpr.js.map +0 -1
  63. package/lib/cjs/paths/normalizePropertyPath.d.ts +0 -23
  64. package/lib/cjs/paths/normalizePropertyPath.js +0 -75
  65. package/lib/cjs/paths/normalizePropertyPath.js.map +0 -1
  66. package/lib/cjs/paths/pathExprToSparql.d.ts +0 -14
  67. package/lib/cjs/paths/pathExprToSparql.js +0 -136
  68. package/lib/cjs/paths/pathExprToSparql.js.map +0 -1
  69. package/lib/cjs/queries/ContextRef.d.ts +0 -32
  70. package/lib/cjs/queries/ContextRef.js +0 -69
  71. package/lib/cjs/queries/ContextRef.js.map +0 -1
  72. package/lib/cjs/queries/CreateBuilder.d.ts +0 -59
  73. package/lib/cjs/queries/CreateBuilder.js +0 -138
  74. package/lib/cjs/queries/CreateBuilder.js.map +0 -1
  75. package/lib/cjs/queries/CreateQuery.d.ts +0 -20
  76. package/lib/cjs/queries/CreateQuery.js +0 -3
  77. package/lib/cjs/queries/CreateQuery.js.map +0 -1
  78. package/lib/cjs/queries/DeleteBuilder.d.ts +0 -56
  79. package/lib/cjs/queries/DeleteBuilder.js +0 -172
  80. package/lib/cjs/queries/DeleteBuilder.js.map +0 -1
  81. package/lib/cjs/queries/DeleteQuery.d.ts +0 -37
  82. package/lib/cjs/queries/DeleteQuery.js +0 -3
  83. package/lib/cjs/queries/DeleteQuery.js.map +0 -1
  84. package/lib/cjs/queries/DslJsonExpression.d.ts +0 -68
  85. package/lib/cjs/queries/DslJsonExpression.js +0 -427
  86. package/lib/cjs/queries/DslJsonExpression.js.map +0 -1
  87. package/lib/cjs/queries/FieldSet.d.ts +0 -310
  88. package/lib/cjs/queries/FieldSet.js +0 -802
  89. package/lib/cjs/queries/FieldSet.js.map +0 -1
  90. package/lib/cjs/queries/IRAliasScope.d.ts +0 -20
  91. package/lib/cjs/queries/IRAliasScope.js +0 -52
  92. package/lib/cjs/queries/IRAliasScope.js.map +0 -1
  93. package/lib/cjs/queries/IRCanonicalize.d.ts +0 -19
  94. package/lib/cjs/queries/IRCanonicalize.js +0 -19
  95. package/lib/cjs/queries/IRCanonicalize.js.map +0 -1
  96. package/lib/cjs/queries/IRDesugar.d.ts +0 -123
  97. package/lib/cjs/queries/IRDesugar.js +0 -261
  98. package/lib/cjs/queries/IRDesugar.js.map +0 -1
  99. package/lib/cjs/queries/IRLower.d.ts +0 -25
  100. package/lib/cjs/queries/IRLower.js +0 -398
  101. package/lib/cjs/queries/IRLower.js.map +0 -1
  102. package/lib/cjs/queries/IRMutation.d.ts +0 -53
  103. package/lib/cjs/queries/IRMutation.js +0 -130
  104. package/lib/cjs/queries/IRMutation.js.map +0 -1
  105. package/lib/cjs/queries/IRPipeline.d.ts +0 -8
  106. package/lib/cjs/queries/IRPipeline.js +0 -25
  107. package/lib/cjs/queries/IRPipeline.js.map +0 -1
  108. package/lib/cjs/queries/IRProjection.d.ts +0 -39
  109. package/lib/cjs/queries/IRProjection.js +0 -105
  110. package/lib/cjs/queries/IRProjection.js.map +0 -1
  111. package/lib/cjs/queries/IntermediateRepresentation.d.ts +0 -282
  112. package/lib/cjs/queries/IntermediateRepresentation.js +0 -3
  113. package/lib/cjs/queries/IntermediateRepresentation.js.map +0 -1
  114. package/lib/cjs/queries/MutationQuery.d.ts +0 -50
  115. package/lib/cjs/queries/MutationQuery.js +0 -334
  116. package/lib/cjs/queries/MutationQuery.js.map +0 -1
  117. package/lib/cjs/queries/MutationSerialization.d.ts +0 -102
  118. package/lib/cjs/queries/MutationSerialization.js +0 -207
  119. package/lib/cjs/queries/MutationSerialization.js.map +0 -1
  120. package/lib/cjs/queries/MutationThenable.d.ts +0 -18
  121. package/lib/cjs/queries/MutationThenable.js +0 -32
  122. package/lib/cjs/queries/MutationThenable.js.map +0 -1
  123. package/lib/cjs/queries/PropertyPath.d.ts +0 -38
  124. package/lib/cjs/queries/PropertyPath.js +0 -82
  125. package/lib/cjs/queries/PropertyPath.js.map +0 -1
  126. package/lib/cjs/queries/ProxiedPathBuilder.d.ts +0 -14
  127. package/lib/cjs/queries/ProxiedPathBuilder.js +0 -29
  128. package/lib/cjs/queries/ProxiedPathBuilder.js.map +0 -1
  129. package/lib/cjs/queries/QueryBuilder.d.ts +0 -193
  130. package/lib/cjs/queries/QueryBuilder.js +0 -519
  131. package/lib/cjs/queries/QueryBuilder.js.map +0 -1
  132. package/lib/cjs/queries/QueryBuilderSerialization.d.ts +0 -31
  133. package/lib/cjs/queries/QueryBuilderSerialization.js +0 -68
  134. package/lib/cjs/queries/QueryBuilderSerialization.js.map +0 -1
  135. package/lib/cjs/queries/QueryContext.d.ts +0 -50
  136. package/lib/cjs/queries/QueryContext.js +0 -147
  137. package/lib/cjs/queries/QueryContext.js.map +0 -1
  138. package/lib/cjs/queries/QueryFactory.d.ts +0 -80
  139. package/lib/cjs/queries/QueryFactory.js +0 -21
  140. package/lib/cjs/queries/QueryFactory.js.map +0 -1
  141. package/lib/cjs/queries/SelectQuery.d.ts +0 -302
  142. package/lib/cjs/queries/SelectQuery.js +0 -761
  143. package/lib/cjs/queries/SelectQuery.js.map +0 -1
  144. package/lib/cjs/queries/UpdateBuilder.d.ts +0 -69
  145. package/lib/cjs/queries/UpdateBuilder.js +0 -199
  146. package/lib/cjs/queries/UpdateBuilder.js.map +0 -1
  147. package/lib/cjs/queries/UpdateQuery.d.ts +0 -18
  148. package/lib/cjs/queries/UpdateQuery.js +0 -3
  149. package/lib/cjs/queries/UpdateQuery.js.map +0 -1
  150. package/lib/cjs/queries/fromJSON.d.ts +0 -16
  151. package/lib/cjs/queries/fromJSON.js +0 -41
  152. package/lib/cjs/queries/fromJSON.js.map +0 -1
  153. package/lib/cjs/queries/lower.d.ts +0 -28
  154. package/lib/cjs/queries/lower.js +0 -114
  155. package/lib/cjs/queries/lower.js.map +0 -1
  156. package/lib/cjs/queries/lowerMutationJSON.d.ts +0 -25
  157. package/lib/cjs/queries/lowerMutationJSON.js +0 -173
  158. package/lib/cjs/queries/lowerMutationJSON.js.map +0 -1
  159. package/lib/cjs/queries/mutationLowerSpec.d.ts +0 -32
  160. package/lib/cjs/queries/mutationLowerSpec.js +0 -8
  161. package/lib/cjs/queries/mutationLowerSpec.js.map +0 -1
  162. package/lib/cjs/queries/queryDispatch.d.ts +0 -33
  163. package/lib/cjs/queries/queryDispatch.js +0 -33
  164. package/lib/cjs/queries/queryDispatch.js.map +0 -1
  165. package/lib/cjs/queries/resolveShape.d.ts +0 -10
  166. package/lib/cjs/queries/resolveShape.js +0 -23
  167. package/lib/cjs/queries/resolveShape.js.map +0 -1
  168. package/lib/cjs/queries/wireVersion.d.ts +0 -7
  169. package/lib/cjs/queries/wireVersion.js +0 -25
  170. package/lib/cjs/queries/wireVersion.js.map +0 -1
  171. package/lib/cjs/shapes/List.d.ts +0 -35
  172. package/lib/cjs/shapes/List.js +0 -72
  173. package/lib/cjs/shapes/List.js.map +0 -1
  174. package/lib/cjs/shapes/PathNode.d.ts +0 -20
  175. package/lib/cjs/shapes/PathNode.js +0 -68
  176. package/lib/cjs/shapes/PathNode.js.map +0 -1
  177. package/lib/cjs/shapes/SHACL.d.ts +0 -300
  178. package/lib/cjs/shapes/SHACL.js +0 -612
  179. package/lib/cjs/shapes/SHACL.js.map +0 -1
  180. package/lib/cjs/shapes/Shape.d.ts +0 -74
  181. package/lib/cjs/shapes/Shape.js +0 -124
  182. package/lib/cjs/shapes/Shape.js.map +0 -1
  183. package/lib/cjs/shapes/serializePathToNodeData.d.ts +0 -24
  184. package/lib/cjs/shapes/serializePathToNodeData.js +0 -67
  185. package/lib/cjs/shapes/serializePathToNodeData.js.map +0 -1
  186. package/lib/cjs/shapes/syncShapes.d.ts +0 -38
  187. package/lib/cjs/shapes/syncShapes.js +0 -214
  188. package/lib/cjs/shapes/syncShapes.js.map +0 -1
  189. package/lib/cjs/sparql/SparqlAlgebra.d.ts +0 -190
  190. package/lib/cjs/sparql/SparqlAlgebra.js +0 -4
  191. package/lib/cjs/sparql/SparqlAlgebra.js.map +0 -1
  192. package/lib/cjs/sparql/SparqlDataset.d.ts +0 -60
  193. package/lib/cjs/sparql/SparqlDataset.js +0 -117
  194. package/lib/cjs/sparql/SparqlDataset.js.map +0 -1
  195. package/lib/cjs/sparql/algebraToString.d.ts +0 -13
  196. package/lib/cjs/sparql/algebraToString.js +0 -385
  197. package/lib/cjs/sparql/algebraToString.js.map +0 -1
  198. package/lib/cjs/sparql/index.d.ts +0 -9
  199. package/lib/cjs/sparql/index.js +0 -41
  200. package/lib/cjs/sparql/index.js.map +0 -1
  201. package/lib/cjs/sparql/irToAlgebra.d.ts +0 -79
  202. package/lib/cjs/sparql/irToAlgebra.js +0 -2042
  203. package/lib/cjs/sparql/irToAlgebra.js.map +0 -1
  204. package/lib/cjs/sparql/resultMapping.d.ts +0 -36
  205. package/lib/cjs/sparql/resultMapping.js +0 -563
  206. package/lib/cjs/sparql/resultMapping.js.map +0 -1
  207. package/lib/cjs/sparql/sparqlUtils.d.ts +0 -53
  208. package/lib/cjs/sparql/sparqlUtils.js +0 -154
  209. package/lib/cjs/sparql/sparqlUtils.js.map +0 -1
  210. package/lib/cjs/utils/LinkedErrorLogging.d.ts +0 -13
  211. package/lib/cjs/utils/LinkedErrorLogging.js +0 -22
  212. package/lib/cjs/utils/LinkedErrorLogging.js.map +0 -1
  213. package/lib/cjs/utils/LinkedFileStorage.d.ts +0 -23
  214. package/lib/cjs/utils/LinkedFileStorage.js +0 -62
  215. package/lib/cjs/utils/LinkedFileStorage.js.map +0 -1
  216. package/lib/cjs/utils/LinkedStorage.d.ts +0 -40
  217. package/lib/cjs/utils/LinkedStorage.js +0 -148
  218. package/lib/cjs/utils/LinkedStorage.js.map +0 -1
  219. package/lib/cjs/utils/NameSpace.d.ts +0 -2
  220. package/lib/cjs/utils/NameSpace.js +0 -8
  221. package/lib/cjs/utils/NameSpace.js.map +0 -1
  222. package/lib/cjs/utils/NodeReference.d.ts +0 -30
  223. package/lib/cjs/utils/NodeReference.js +0 -54
  224. package/lib/cjs/utils/NodeReference.js.map +0 -1
  225. package/lib/cjs/utils/Package.d.ts +0 -153
  226. package/lib/cjs/utils/Package.js +0 -419
  227. package/lib/cjs/utils/Package.js.map +0 -1
  228. package/lib/cjs/utils/Prefix.d.ts +0 -22
  229. package/lib/cjs/utils/Prefix.js +0 -104
  230. package/lib/cjs/utils/Prefix.js.map +0 -1
  231. package/lib/cjs/utils/ShapeClass.d.ts +0 -30
  232. package/lib/cjs/utils/ShapeClass.js +0 -180
  233. package/lib/cjs/utils/ShapeClass.js.map +0 -1
  234. package/lib/cjs/utils/URI.d.ts +0 -18
  235. package/lib/cjs/utils/URI.js +0 -42
  236. package/lib/cjs/utils/URI.js.map +0 -1
  237. package/lib/cjs/utils/cached.d.ts +0 -14
  238. package/lib/cjs/utils/cached.js +0 -71
  239. package/lib/cjs/utils/cached.js.map +0 -1
  240. package/lib/cjs/utils/loadStores.d.ts +0 -34
  241. package/lib/cjs/utils/loadStores.js +0 -105
  242. package/lib/cjs/utils/loadStores.js.map +0 -1
  243. package/lib/cjs/utils/parseDatasetsConfig.d.ts +0 -49
  244. package/lib/cjs/utils/parseDatasetsConfig.js +0 -110
  245. package/lib/cjs/utils/parseDatasetsConfig.js.map +0 -1
  246. package/lib/esm/package.json +0 -9
@@ -1,334 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MutationQueryFactory = void 0;
4
- const QueryFactory_js_1 = require("./QueryFactory.js");
5
- const ShapeClass_js_1 = require("../utils/ShapeClass.js");
6
- const ExpressionNode_js_1 = require("../expressions/ExpressionNode.js");
7
- const ProxiedPathBuilder_js_1 = require("./ProxiedPathBuilder.js");
8
- const QueryContext_js_1 = require("./QueryContext.js");
9
- const shacl_js_1 = require("../ontologies/shacl.js");
10
- class MutationQueryFactory extends QueryFactory_js_1.QueryFactory {
11
- /**
12
- * Normalize raw create/update data into a {@link NodeDescriptionValue} — the
13
- * IR-free step shared by `toJSON()` and `lower()`. Kept on this base (which
14
- * imports no IR) so the builders can normalize for serialization without
15
- * pulling the canonical-IR pipeline.
16
- */
17
- describe(shape, data, allowTopLevelId = false) {
18
- return this.convertUpdateObject(data, shape, allowTopLevelId);
19
- }
20
- /** Normalize delete ids (strings / `{id}`) to `NodeReferenceValue[]` (IR-free). */
21
- normalizeNodeRefs(ids) {
22
- return this.convertNodeReferences(ids);
23
- }
24
- convertUpdateObject(obj, shape, allowTopLevelId = false) {
25
- if (typeof obj === 'object' && !(obj instanceof Date) && obj !== null) {
26
- if (!allowTopLevelId && 'id' in obj) {
27
- throw new Error('You cannot use id in the top level of an update object');
28
- }
29
- return this.convertNodeDescription(obj, shape);
30
- }
31
- else if (typeof obj === 'function') {
32
- const shapeClass = shape.id ? (0, ShapeClass_js_1.getShapeClass)(shape.id) : undefined;
33
- if (!shapeClass) {
34
- throw new Error(`Shape class not found for ${shape.id || 'unknown'}`);
35
- }
36
- const proxy = (0, ProxiedPathBuilder_js_1.createProxiedPathBuilder)(shapeClass);
37
- const result = obj(proxy);
38
- if (typeof result !== 'object' || result === null) {
39
- throw new Error('Update function must return an object');
40
- }
41
- return this.convertNodeDescription(result, shape);
42
- }
43
- else {
44
- throw new Error('Invalid update object');
45
- }
46
- }
47
- isSetModification(obj, shape) {
48
- let hasAdd = obj.add;
49
- let hasRemove = obj.remove;
50
- let numKeysExpected = (hasAdd ? 1 : 0) + (hasRemove ? 1 : 0);
51
- let numKeys = Object.getOwnPropertyNames(obj).length;
52
- // A set modification is ONLY add/remove keys. Mixing them with other keys
53
- // (e.g. {add:[…], name:'x'}) must NOT be silently treated as a set mod —
54
- // that dropped the sibling fields. Require an exact key-count match for
55
- // both add and remove (mirrors isSetModificationValue).
56
- return (hasAdd || hasRemove) && numKeysExpected === numKeys;
57
- }
58
- convertSetModification(obj, shape) {
59
- if (!obj.add && !obj.remove) {
60
- throw new Error('Set modification should have either add or remove key');
61
- }
62
- const res = {};
63
- if (obj.add) {
64
- res.$add = this.convertSetAddValue(obj.add, shape);
65
- }
66
- if (obj.remove) {
67
- res.$remove = this.convertSetRemoveValue(obj.remove, shape);
68
- }
69
- return res;
70
- }
71
- convertSetRemoveValue(obj, shape) {
72
- //the user can either pass an array of node references or a single node reference
73
- //either way we should return an array of node reference values
74
- if (Array.isArray(obj)) {
75
- return obj.map((o) => this.convertSingleRemoveValue(o, shape));
76
- }
77
- else {
78
- return [this.convertSingleRemoveValue(obj, shape)];
79
- }
80
- }
81
- convertSetAddValue(obj, shape) {
82
- if (Array.isArray(obj)) {
83
- return obj.map((o) => this.convertUpdateValue(o, shape));
84
- }
85
- else {
86
- return [this.convertUpdateValue(obj, shape)];
87
- }
88
- }
89
- convertSingleRemoveValue(value, shape) {
90
- const ctx = (0, QueryContext_js_1.asContextRef)(value);
91
- if (ctx) {
92
- return ctx;
93
- }
94
- if (this.isNodeReference(value)) {
95
- return this.convertNodeReference(value);
96
- }
97
- else {
98
- throw new Error(`Invalid value for ${shape.label}.$remove. Expected an object with an id as key: {id:string}`);
99
- }
100
- }
101
- convertNodeDescription(inputObj, shape) {
102
- // Shallow-copy so we never mutate the caller's object
103
- const obj = Object.assign({}, inputObj);
104
- const props = shape.getPropertyShapes(true);
105
- const fields = [];
106
- let id;
107
- if ('__id' in obj) {
108
- //if the object has a __id key, then we should use that in the result
109
- id = obj.__id.toString();
110
- //but we should not include it in the fields
111
- delete obj.__id;
112
- }
113
- else if ('id' in obj) {
114
- //if the object has an id key alongside other data properties,
115
- //treat it as a nested create with a predefined ID
116
- id = String(obj.id);
117
- delete obj.id;
118
- }
119
- for (var key in obj) {
120
- let propShape = props.find((p) => p.label === key);
121
- if (!propShape) {
122
- throw Error(`Invalid property key: ${key}. The shape ${shape.label || shape.id.split('/').pop()} does not have a registered property with this name. Make sure the get/set method exists, and that it uses a @objectProperty or @literalProperty decorator.`);
123
- }
124
- else {
125
- fields.push(this.createNodePropertyValue(obj[key], propShape));
126
- }
127
- }
128
- const res = {
129
- fields,
130
- shape,
131
- };
132
- if (id) {
133
- res.__id = id;
134
- }
135
- return res;
136
- }
137
- createNodePropertyValue(value, propShape) {
138
- this.validateAgainstShape(value, propShape);
139
- return {
140
- prop: propShape,
141
- val: this.convertUpdateValue(value, propShape),
142
- };
143
- }
144
- /**
145
- * Lightweight structural validation of a single property value against its
146
- * PropertyShape — cardinality (`minCount`/`maxCount`) and node-kind (literal
147
- * vs relation). This is *structural* only (from metadata already in hand); it
148
- * does not duplicate datatype/deep validation, which the store performs. It
149
- * fails fast at the call site with a clear message instead of surfacing a
150
- * confusing store error later.
151
- *
152
- * Skips values whose final shape isn't known here: computed expressions,
153
- * context refs, `unset` (null/undefined), and set-modifications (`{add,remove}`
154
- * — the resulting count depends on the node's current state).
155
- */
156
- validateAgainstShape(value, propShape) {
157
- // A `null` value clears the property. Clearing a required (minCount>=1)
158
- // property is a cardinality violation — the same as providing zero values —
159
- // so it is rejected exactly like an empty array (both spellings of "clear
160
- // it" behave identically).
161
- if (value === null) {
162
- if (typeof propShape.minCount === 'number' && propShape.minCount > 0) {
163
- throw new Error(`Property '${propShape.label || propShape.id}' requires at least ${propShape.minCount} value(s) and cannot be cleared.`);
164
- }
165
- return;
166
- }
167
- if (value === undefined ||
168
- (0, ExpressionNode_js_1.isExpressionNode)(value) ||
169
- (0, QueryContext_js_1.asContextRef)(value) ||
170
- (typeof value === 'function') ||
171
- (typeof value === 'object' && this.isSetModification(value, propShape))) {
172
- return;
173
- }
174
- const label = propShape.label || propShape.id;
175
- const elems = Array.isArray(value) ? value : [value];
176
- const count = elems.length;
177
- // --- cardinality ---
178
- if (typeof propShape.maxCount === 'number' && count > propShape.maxCount) {
179
- throw new Error(`Property '${label}' allows at most ${propShape.maxCount} value(s), but ${count} were provided.`);
180
- }
181
- if (typeof propShape.minCount === 'number' && propShape.minCount > 0 && count < propShape.minCount) {
182
- throw new Error(`Property '${label}' requires at least ${propShape.minCount} value(s), but ${count} were provided.`);
183
- }
184
- // --- node kind: literal vs relation ---
185
- const expectsLiteral = this.expectsLiteral(propShape);
186
- const expectsNode = this.expectsNode(propShape);
187
- if (!expectsLiteral && !expectsNode)
188
- return; // ambiguous/unspecified kind — don't enforce
189
- for (const el of elems) {
190
- if (el === null || el === undefined || (0, ExpressionNode_js_1.isExpressionNode)(el) || (0, QueryContext_js_1.asContextRef)(el))
191
- continue;
192
- const isScalar = typeof el === 'string' ||
193
- typeof el === 'number' ||
194
- typeof el === 'boolean' ||
195
- el instanceof Date;
196
- if (expectsLiteral && !isScalar) {
197
- throw new Error(`Property '${label}' is a literal property but was given a ${typeof el === 'object' ? 'node/object' : typeof el} value.`);
198
- }
199
- if (expectsNode && isScalar) {
200
- throw new Error(`Property '${label}' is a relation (object) property but was given a literal (${typeof el}). Provide a {id} reference or a nested object.`);
201
- }
202
- }
203
- }
204
- /** True when the property clearly accepts only literal values. */
205
- expectsLiteral(ps) {
206
- if (ps.nodeKind)
207
- return ps.nodeKind.id === shacl_js_1.shacl.Literal.id;
208
- return !!ps.datatype && !ps.valueShape;
209
- }
210
- /** True when the property clearly accepts only nodes (IRIs/blank nodes). */
211
- expectsNode(ps) {
212
- if (ps.nodeKind) {
213
- return (ps.nodeKind.id === shacl_js_1.shacl.IRI.id ||
214
- ps.nodeKind.id === shacl_js_1.shacl.BlankNode.id ||
215
- ps.nodeKind.id === shacl_js_1.shacl.BlankNodeOrIRI.id);
216
- }
217
- return !!ps.valueShape;
218
- }
219
- convertUpdateValue(value, propShape, allowArrays = true) {
220
- // ExpressionNode → pass through as-is (will be converted to IRExpression by IRMutation)
221
- if ((0, ExpressionNode_js_1.isExpressionNode)(value)) {
222
- return value;
223
- }
224
- // Query-context reference → preserve the live ref (do NOT collapse to {id},
225
- // which would read an unresolved `.id` as undefined). Handles both an unset
226
- // PendingQueryContext and a resolved context shape; both serialize as a {@ctx}
227
- // marker and are resolved — or throw — at lowering time.
228
- {
229
- const ctx = (0, QueryContext_js_1.asContextRef)(value);
230
- if (ctx)
231
- return ctx;
232
- }
233
- //single value which will
234
- if (typeof value === 'string' ||
235
- typeof value === 'number' ||
236
- typeof value === 'boolean' ||
237
- value instanceof Date) {
238
- return value;
239
- }
240
- //if multiple items are given as value of this prop
241
- if (Array.isArray(value)) {
242
- if (!allowArrays) {
243
- throw new Error('Nested arrays are not allowed as values of keys');
244
- }
245
- //then convert each value, but disallow nested arrays moving forward
246
- return value.map((o) => {
247
- return this.convertUpdateValue(o, propShape, false);
248
- });
249
- }
250
- else if (typeof value === 'undefined') {
251
- return value;
252
- }
253
- else if (value === null) {
254
- //unsetting a value with null is also possible. But we pass it as undefined in the query object
255
- return undefined;
256
- }
257
- else if (typeof value === 'object') {
258
- if (this.isNodeReference(value)) {
259
- return this.convertNodeReference(value);
260
- }
261
- else {
262
- let valueShape = null;
263
- if (propShape.valueShape) {
264
- const shapeClass = (0, ShapeClass_js_1.getShapeClass)(propShape.valueShape);
265
- valueShape = (shapeClass === null || shapeClass === void 0 ? void 0 : shapeClass.shape) || null;
266
- if (!valueShape) {
267
- throw new Error(`Shape class not found for ${propShape.valueShape.id}`);
268
- }
269
- }
270
- //pass the value shape of the property as the node shape of this value
271
- if (!propShape.valueShape) {
272
- //It's possible to define the shape of the value in the value itself for properties who do not define the shape in their objectProperty
273
- if (value.shape) {
274
- if (!value.shape.shape || typeof value.shape.shape.getPropertyShapes !== 'function') {
275
- throw new Error(`The value of property "shape" is invalid and should be a class that extends Shape.`);
276
- }
277
- valueShape = value.shape.shape;
278
- }
279
- else {
280
- //TODO: not sure if this should be an error. Does every @linkedObject need to define the shape of the values?
281
- // If not, then how do we continue? because currently we use the value shape to look up further property shapes
282
- throw new Error(`Cannot update properties with plain objects if the shape of the values is not known. Make sure get/set ${propShape.parentNodeShape.label}.${propShape.label} defines the 'shape' key in its @objectProperty decorator.`);
283
- }
284
- }
285
- //never keep a shape key in the value object
286
- if (value.shape) {
287
- //double check that IF a shape value is provided, that it matches the shape from the @objectProperty decorator
288
- if (value.shape.shape.id !== valueShape.id) {
289
- throw new Error(`The property 'shape' is reserved in LINCD and should not be used here in this way. The ${propShape.label} property already defines the shape of the value as ${propShape.label}. If you want to use a different shape, use the 'shape' key in the @objectProperty decorator.`);
290
- }
291
- delete value.shape;
292
- }
293
- if (this.isSetModification(value, propShape)) {
294
- return this.convertSetModification(value, propShape);
295
- }
296
- else {
297
- return this.convertNodeDescription(value, valueShape);
298
- }
299
- }
300
- }
301
- throw new Error(`Unsupported update value type: ${typeof value}`);
302
- }
303
- isNodeReference(obj) {
304
- //check if obj is an object with only an id property
305
- //if additional data properties are present, it's a nested create with predefined ID
306
- return typeof obj === 'object' && obj !== null && 'id' in obj && Object.keys(obj).length === 1;
307
- }
308
- convertNodeReferences(input) {
309
- if (Array.isArray(input)) {
310
- return input.map((o) => {
311
- return this.convertNodeReferenceOrString(o);
312
- });
313
- }
314
- else {
315
- return [this.convertNodeReferenceOrString(input)];
316
- }
317
- }
318
- convertNodeReferenceOrString(o) {
319
- if (typeof o === 'string') {
320
- return { id: o };
321
- }
322
- else if (this.isNodeReference(o)) {
323
- return this.convertNodeReference(o);
324
- }
325
- else {
326
- throw new Error(`Invalid node reference: ${JSON.stringify(o)}`);
327
- }
328
- }
329
- convertNodeReference(obj) {
330
- return { id: obj.id };
331
- }
332
- }
333
- exports.MutationQueryFactory = MutationQueryFactory;
334
- //# sourceMappingURL=MutationQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MutationQuery.js","sourceRoot":"","sources":["../../../src/queries/MutationQuery.ts"],"names":[],"mappings":";;;AAAA,uDAW2B;AAG3B,0DAAqD;AACrD,wEAAkF;AAClF,mEAAiE;AACjE,uDAA+C;AAC/C,qDAA6C;AAI7C,MAAa,oBAAqB,SAAQ,8BAAY;IACpD;;;;;OAKG;IACH,QAAQ,CACN,KAAgB,EAChB,IAAa,EACb,kBAA2B,KAAK;QAEhC,OAAO,IAAI,CAAC,mBAAmB,CAAC,IAAW,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;IACvE,CAAC;IAED,mFAAmF;IACnF,iBAAiB,CAAC,GAAsB;QACtC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAES,mBAAmB,CAC3B,GAAG,EACH,KAAgB,EAChB,kBAA2B,KAAK;QAEhC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,YAAY,IAAI,CAAC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACt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AC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAES,4BAA4B,CACpC,CAAwB;QAExB,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC1B,OAAO,EAAC,EAAE,EAAE,CAAC,EAAC,CAAC;QACjB,CAAC;aAAM,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,GAAiB;QAC9C,OAAO,EAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAC,CAAC;IACtB,CAAC;CACF;AAxYD,oDAwYC"}
@@ -1,102 +0,0 @@
1
- /**
2
- * Lossless JSON (de)serialization for mutations (create / update / delete) — the
3
- * **IR-free wire codec**. The companion IR side (`decodeNodeData` / `lowerMutationJSON`)
4
- * lives in `lowerMutationJSON.ts` so this module never pulls the canonical-IR pipeline.
5
- *
6
- * The serialization unit is the normalized `NodeDescriptionValue` produced by the
7
- * IR-free factory base (`MutationQueryFactory.describe()`) — i.e. after `.set()` and
8
- * after any update-expression callback has been evaluated, but before canonical IR.
9
- * Property keys are serialized as **labels** (shape-relative, lightweight); decoding
10
- * resolves them back via the registered shape.
11
- *
12
- * Values use the DSL-JSON grammar (documentation/dsl-json.md): a bare scalar is a
13
- * literal; objects tag the kinds `JSON.stringify` can't represent natively
14
- * (`{@date}`, `{@id}`, `{@ctx}`, `{@list}`, `{@add,@remove}`, `{@unset}`); and a
15
- * computed value is an S-expr array via the shared `DslJsonExpression` codec —
16
- * so the wire carries no IR.
17
- */
18
- import { type NodeDescriptionValue, type PropUpdateValue } from './QueryFactory.js';
19
- import type { WherePathJSON } from './QueryBuilderSerialization.js';
20
- import type { ContextRefJSON } from './ContextRef.js';
21
- import type { NodeShape, PropertyShape } from '../shapes/SHACL.js';
22
- import { type DslJsonValue } from './DslJsonExpression.js';
23
- /**
24
- * A mutation field value in the DSL-JSON grammar. A bare scalar is a literal; objects
25
- * tag the non-JSON-native kinds (`@`-sigiled); a computed value is an S-expr array (no IR); a
26
- * nested-node create is a bare path-keyed object ({@link MutationNodeDataJSON}),
27
- * disambiguated from the tagged forms by having no reserved value-key.
28
- */
29
- export type MutationValueJSON = string | number | boolean | null | {
30
- '@date': string;
31
- } | {
32
- '@id': string;
33
- } | {
34
- '@ctx': string;
35
- } | {
36
- '@list': MutationValueJSON[];
37
- } | {
38
- '@add'?: MutationValueJSON[];
39
- '@remove'?: string[];
40
- } | {
41
- '@unset': true;
42
- } | MutationNodeDataJSON | DslJsonValue;
43
- /**
44
- * A node description in **path-keyed** form: `label → value`, plus two reserved
45
- * keys — `__id` (a fixed/predefined id) and `__shape` (the concrete shape IRI,
46
- * emitted only when it differs from the shape inferred from context, e.g. a
47
- * subclass instance under a superclass-typed relation).
48
- */
49
- export type MutationNodeDataJSON = {
50
- [key: string]: MutationValueJSON | undefined;
51
- };
52
- export type CreateMutationJSON = {
53
- v?: string;
54
- op: 'create';
55
- shape: string;
56
- data: MutationNodeDataJSON;
57
- };
58
- export type UpdateMutationJSON = {
59
- v?: string;
60
- op: 'update';
61
- shape: string;
62
- mode: 'for' | 'forAll' | 'where';
63
- /** A node id, or a `{@ctx: name}` context reference resolved at lowering. */
64
- targetId?: string | ContextRefJSON;
65
- where?: WherePathJSON;
66
- data: MutationNodeDataJSON;
67
- };
68
- export type DeleteMutationJSON = {
69
- v?: string;
70
- op: 'delete';
71
- shape: string;
72
- mode: 'ids';
73
- ids: (string | ContextRefJSON)[];
74
- } | {
75
- v?: string;
76
- op: 'delete';
77
- shape: string;
78
- mode: 'all';
79
- } | {
80
- v?: string;
81
- op: 'delete';
82
- shape: string;
83
- mode: 'where';
84
- where: WherePathJSON;
85
- };
86
- export type MutationJSON = CreateMutationJSON | UpdateMutationJSON | DeleteMutationJSON;
87
- /** The shape a nested node is expected to have (a property's value shape), if resolvable. */
88
- export declare function valueShapeOf(prop?: PropertyShape): NodeShape | undefined;
89
- /** Encode any property value, including arrays and set modifications. */
90
- export declare function encodeValue(value: PropUpdateValue, prop?: PropertyShape): MutationValueJSON;
91
- /**
92
- * Encode a normalized node description to path-keyed form. `expectedShape` is the
93
- * shape inferable from context (the envelope, or the parent relation's value shape);
94
- * `__shape` is emitted only when the concrete shape differs (a subclass instance).
95
- */
96
- export declare function encodeNodeData(desc: NodeDescriptionValue, expectedShape?: NodeShape): MutationNodeDataJSON;
97
- /**
98
- * Decode path-keyed node data into a raw object the mutation builders' `.set()` accepts.
99
- * `__id` becomes `id`; `__shape` (if present) overrides the inferred `shape`. Mirrors
100
- * {@link encodeNodeData}.
101
- */
102
- export declare function decodeNodeDataToRaw(json: MutationNodeDataJSON, shape?: NodeShape): Record<string, unknown>;
@@ -1,207 +0,0 @@
1
- "use strict";
2
- /*
3
- * This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.valueShapeOf = valueShapeOf;
9
- exports.encodeValue = encodeValue;
10
- exports.encodeNodeData = encodeNodeData;
11
- exports.decodeNodeDataToRaw = decodeNodeDataToRaw;
12
- /**
13
- * Lossless JSON (de)serialization for mutations (create / update / delete) — the
14
- * **IR-free wire codec**. The companion IR side (`decodeNodeData` / `lowerMutationJSON`)
15
- * lives in `lowerMutationJSON.ts` so this module never pulls the canonical-IR pipeline.
16
- *
17
- * The serialization unit is the normalized `NodeDescriptionValue` produced by the
18
- * IR-free factory base (`MutationQueryFactory.describe()`) — i.e. after `.set()` and
19
- * after any update-expression callback has been evaluated, but before canonical IR.
20
- * Property keys are serialized as **labels** (shape-relative, lightweight); decoding
21
- * resolves them back via the registered shape.
22
- *
23
- * Values use the DSL-JSON grammar (documentation/dsl-json.md): a bare scalar is a
24
- * literal; objects tag the kinds `JSON.stringify` can't represent natively
25
- * (`{@date}`, `{@id}`, `{@ctx}`, `{@list}`, `{@add,@remove}`, `{@unset}`); and a
26
- * computed value is an S-expr array via the shared `DslJsonExpression` codec —
27
- * so the wire carries no IR.
28
- */
29
- const QueryFactory_js_1 = require("./QueryFactory.js");
30
- const ExpressionNode_js_1 = require("../expressions/ExpressionNode.js");
31
- const QueryContext_js_1 = require("./QueryContext.js");
32
- const ShapeClass_js_1 = require("../utils/ShapeClass.js");
33
- const DslJsonExpression_js_1 = require("./DslJsonExpression.js");
34
- /** Reserved node-data keys (not property labels). */
35
- const NODE_ID_KEY = '__id';
36
- const NODE_SHAPE_KEY = '__shape';
37
- // =============================================================================
38
- // Value codec
39
- // =============================================================================
40
- /** The shape a nested node is expected to have (a property's value shape), if resolvable. */
41
- function valueShapeOf(prop) {
42
- var _a, _b;
43
- const id = (_a = prop === null || prop === void 0 ? void 0 : prop.valueShape) === null || _a === void 0 ? void 0 : _a.id;
44
- return id ? (_b = (0, ShapeClass_js_1.getShapeClass)(id)) === null || _b === void 0 ? void 0 : _b.shape : undefined;
45
- }
46
- /** Encode a single (non-array, non-setMod) property value. `prop` gives the nested-node shape. */
47
- function encodeSingleValue(value, prop) {
48
- if (value === undefined)
49
- return { '@unset': true };
50
- if ((0, ExpressionNode_js_1.isExpressionNode)(value)) {
51
- // A computed value is an S-expr (or {@path}) via the shared codec — no IR.
52
- return (0, DslJsonExpression_js_1.encodeValueExpr)(value.ir, value._refs);
53
- }
54
- if (value instanceof Date)
55
- return { '@date': value.toISOString() };
56
- if (typeof value === 'string' ||
57
- typeof value === 'number' ||
58
- typeof value === 'boolean') {
59
- return value;
60
- }
61
- if (value && typeof value === 'object') {
62
- // Query-context reference — carry the name, resolve at lowering (checked
63
- // before the generic `.id` branch since a PendingQueryContext has an `.id` getter).
64
- if (value instanceof QueryContext_js_1.PendingQueryContext) {
65
- return { '@ctx': value.contextName };
66
- }
67
- if ('fields' in value) {
68
- // Nested-node create — bare path-keyed; expected shape = the relation's value shape.
69
- return encodeNodeData(value, valueShapeOf(prop));
70
- }
71
- if ('id' in value)
72
- return { '@id': value.id };
73
- }
74
- throw new Error(`Cannot serialize mutation value: ${JSON.stringify(value)}`);
75
- }
76
- /** Encode any property value, including arrays and set modifications. */
77
- function encodeValue(value, prop) {
78
- if (value === undefined)
79
- return { '@unset': true };
80
- if (Array.isArray(value)) {
81
- return { '@list': value.map((v) => encodeSingleValue(v, prop)) };
82
- }
83
- if ((0, QueryFactory_js_1.isSetModificationValue)(value)) {
84
- const mod = value;
85
- const json = {};
86
- if (mod.$add)
87
- json['@add'] = mod.$add.map((v) => encodeValue(v, prop));
88
- if (mod.$remove)
89
- json['@remove'] = mod.$remove.map((r) => r.id);
90
- return json;
91
- }
92
- return encodeSingleValue(value, prop);
93
- }
94
- /**
95
- * Encode a normalized node description to path-keyed form. `expectedShape` is the
96
- * shape inferable from context (the envelope, or the parent relation's value shape);
97
- * `__shape` is emitted only when the concrete shape differs (a subclass instance).
98
- */
99
- function encodeNodeData(desc, expectedShape) {
100
- const json = {};
101
- if (desc.__id)
102
- json[NODE_ID_KEY] = desc.__id;
103
- if (!expectedShape || desc.shape.id !== expectedShape.id) {
104
- json[NODE_SHAPE_KEY] = desc.shape.id;
105
- }
106
- for (const f of desc.fields) {
107
- json[f.prop.label] = encodeValue(f.val, f.prop);
108
- }
109
- return json;
110
- }
111
- // =============================================================================
112
- // JSON → raw UpdatePartial (for builder rehydration / fromJSON)
113
- // =============================================================================
114
- // Bound the DSL-JSON decode recursion (rehydration path) against a deeply-nested
115
- // payload exhausting the stack. Mirrors the cap in lowerMutationJSON.
116
- const MAX_DECODE_DEPTH = 128;
117
- let _decodeDepth = 0;
118
- /**
119
- * Decode a DSL-JSON value back to a raw DSL value (the form `.set()` accepts).
120
- * `currentShape` resolves computed `{@path}`/S-expr; `prop` gives a nested node's shape.
121
- * Depth-guarded wrapper around {@link decodeValueToRawInner}.
122
- */
123
- function decodeValueToRaw(json, currentShape, prop) {
124
- if (++_decodeDepth > MAX_DECODE_DEPTH) {
125
- _decodeDepth = 0;
126
- throw new Error('DSL-JSON value nested too deeply');
127
- }
128
- try {
129
- return decodeValueToRawInner(json, currentShape, prop);
130
- }
131
- finally {
132
- _decodeDepth--;
133
- }
134
- }
135
- function decodeValueToRawInner(json, currentShape, prop) {
136
- var _a;
137
- // S-expr computed value
138
- if (Array.isArray(json)) {
139
- const { ir, refs } = (0, DslJsonExpression_js_1.decodeValueExpr)(json, requireShapeForExpr(currentShape));
140
- return new ExpressionNode_js_1.ExpressionNode(ir, refs);
141
- }
142
- if (json === null)
143
- return null;
144
- if (typeof json !== 'object')
145
- return json; // bare scalar literal
146
- const o = json;
147
- if ('@unset' in o)
148
- return undefined;
149
- if ('@date' in o)
150
- return new Date(o['@date']);
151
- // Rehydration path: preserve the live reference so it re-serializes as a
152
- // `{@ctx}` marker and resolves at the rebuilt builder's own lowering.
153
- if ('@ctx' in o)
154
- return new QueryContext_js_1.PendingQueryContext(o['@ctx']);
155
- if ('@id' in o)
156
- return { id: o['@id'] };
157
- if ('@list' in o) {
158
- return o['@list'].map((i) => decodeValueToRaw(i, currentShape, prop));
159
- }
160
- if ('@add' in o || '@remove' in o) {
161
- // Raw DSL set-modifications use `@add`/`@remove` on the wire.
162
- const mod = {};
163
- if (o['@add'])
164
- mod.add = o['@add'].map((i) => decodeValueToRaw(i, currentShape, prop));
165
- if (o['@remove'])
166
- mod.remove = o['@remove'].map((id) => ({ id }));
167
- return mod;
168
- }
169
- // A computed-path value (`{@path}`) used as a value.
170
- if ('@path' in o) {
171
- const { ir, refs } = (0, DslJsonExpression_js_1.decodeValueExpr)(json, requireShapeForExpr(currentShape));
172
- return new ExpressionNode_js_1.ExpressionNode(ir, refs);
173
- }
174
- // Otherwise: a bare path-keyed nested-node create.
175
- return decodeNodeDataToRaw(o, (_a = valueShapeOf(prop)) !== null && _a !== void 0 ? _a : currentShape);
176
- }
177
- function requireShapeForExpr(shape) {
178
- if (!shape) {
179
- throw new Error('A shape is required to decode a computed mutation value');
180
- }
181
- return shape;
182
- }
183
- /**
184
- * Decode path-keyed node data into a raw object the mutation builders' `.set()` accepts.
185
- * `__id` becomes `id`; `__shape` (if present) overrides the inferred `shape`. Mirrors
186
- * {@link encodeNodeData}.
187
- */
188
- function decodeNodeDataToRaw(json, shape) {
189
- var _a, _b;
190
- const nodeShape = typeof json[NODE_SHAPE_KEY] === 'string'
191
- ? (_b = (_a = (0, ShapeClass_js_1.getShapeClass)(json[NODE_SHAPE_KEY])) === null || _a === void 0 ? void 0 : _a.shape) !== null && _b !== void 0 ? _b : shape
192
- : shape;
193
- const obj = {};
194
- if (typeof json[NODE_ID_KEY] === 'string')
195
- obj.id = json[NODE_ID_KEY];
196
- for (const [key, val] of Object.entries(json)) {
197
- if (key === NODE_ID_KEY || key === NODE_SHAPE_KEY || val === undefined)
198
- continue;
199
- // Skip prototype-polluting keys from untrusted DSL-JSON input.
200
- if (key === '__proto__' || key === 'constructor' || key === 'prototype')
201
- continue;
202
- const prop = nodeShape === null || nodeShape === void 0 ? void 0 : nodeShape.getPropertyShape(key);
203
- obj[key] = decodeValueToRaw(val, nodeShape, prop);
204
- }
205
- return obj;
206
- }
207
- //# sourceMappingURL=MutationSerialization.js.map