@_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,761 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetSize = exports.QueryPrimitiveSet = exports.QueryPrimitive = exports.QueryShape = exports.QueryShapeSet = exports.evaluateSortCallback = exports.processWhereClause = exports.BoundComponent = exports.QueryBuilderObject = void 0;
4
- const ShapeSet_js_1 = require("../collections/ShapeSet.js");
5
- const shacl_js_1 = require("../ontologies/shacl.js");
6
- const CoreSet_js_1 = require("../collections/CoreSet.js");
7
- const ShapeClass_js_1 = require("../utils/ShapeClass.js");
8
- const xsd_js_1 = require("../ontologies/xsd.js");
9
- const ProxiedPathBuilder_js_1 = require("./ProxiedPathBuilder.js");
10
- const FieldSet_js_1 = require("./FieldSet.js");
11
- const PropertyPath_js_1 = require("./PropertyPath.js");
12
- const ExpressionNode_js_1 = require("../expressions/ExpressionNode.js");
13
- const QueryContext_js_1 = require("./QueryContext.js");
14
- /**
15
- * String keys the query-shape proxy must let through *without* treating them as
16
- * a property access — promise-awaiting (`then`), React (`$$typeof`), and common
17
- * serializer/object-protocol probes. Everything else that isn't a decorated
18
- * property is a genuine misuse and throws. (Symbol keys always pass through.)
19
- */
20
- const INTEROP_PASSTHROUGH_KEYS = new Set([
21
- 'then',
22
- '$$typeof',
23
- 'toJSON',
24
- 'toString',
25
- 'valueOf',
26
- 'constructor',
27
- 'asymmetricMatch', // jest matchers probe this
28
- 'nodeType', // some DOM/serializer probes
29
- ]);
30
- const isSameRef = (a, b) => !!a && !!b && a.id === b.id;
31
- /**
32
- * ###################################
33
- * #### QUERY BUILDING CLASSES ####
34
- * ###################################
35
- */
36
- class QueryBuilderObject {
37
- constructor(property, subject) {
38
- this.property = property;
39
- this.subject = subject;
40
- //is null by default to avoid warnings when trying to access wherePath when its undefined
41
- this.wherePath = null;
42
- }
43
- /**
44
- * Create a Query Builder Object based on the requested PropertyShape
45
- */
46
- static generatePathValue(
47
- // originalValue: AccessorReturnValue,
48
- property, subject) {
49
- let datatype = property.datatype;
50
- let valueShape = property.valueShape;
51
- let singleValue = property.maxCount <= 1;
52
- if (datatype) {
53
- if (singleValue) {
54
- if (isSameRef(datatype, xsd_js_1.xsd.integer)) {
55
- return wrapWithExpressionProxy(new QueryPrimitive(0, property, subject));
56
- }
57
- else if (isSameRef(datatype, xsd_js_1.xsd.boolean)) {
58
- return wrapWithExpressionProxy(new QueryPrimitive(false, property, subject));
59
- }
60
- else if (isSameRef(datatype, xsd_js_1.xsd.dateTime) ||
61
- isSameRef(datatype, xsd_js_1.xsd.date)) {
62
- return wrapWithExpressionProxy(new QueryPrimitive(new Date(), property, subject));
63
- }
64
- else if (isSameRef(datatype, xsd_js_1.xsd.string)) {
65
- return wrapWithExpressionProxy(new QueryPrimitive('', property, subject));
66
- }
67
- }
68
- else {
69
- //TODO review this, do we need property & subject in both of these? currently yes, but why
70
- return new QueryPrimitiveSet([''], property, subject, [
71
- new QueryPrimitive('', property, subject),
72
- ]);
73
- }
74
- }
75
- if (valueShape) {
76
- const shapeClass = (0, ShapeClass_js_1.getShapeClass)(valueShape);
77
- if (!shapeClass) {
78
- //TODO: getShapeClassAsync -> which will lazy load the shape class
79
- // but Im not sure if that's even possible with dynamic import paths, that are only known at runtime
80
- //UPDATE: we should not need to load shapeclasses. We just need to be able to access shapes.
81
- // but the problem remains that the ImageObject shape needs to be available, but thats easier, as its data
82
- throw new Error(`Shape class not found for ${valueShape.id}`);
83
- }
84
- const shapeValue = new shapeClass();
85
- if (singleValue) {
86
- return QueryShape.create(shapeValue, property, subject);
87
- }
88
- else {
89
- return QueryShapeSet.create(new ShapeSet_js_1.ShapeSet([shapeValue]), property, subject);
90
- }
91
- }
92
- //no value shape and no data type.
93
- //Lets look at the node kind
94
- if (isSameRef(property.nodeKind, shacl_js_1.shacl.Literal) ||
95
- isSameRef(property.nodeKind, shacl_js_1.shacl.BlankNodeOrLiteral)) {
96
- if (singleValue) {
97
- //default to string if no datatype is set
98
- return wrapWithExpressionProxy(new QueryPrimitive('', property, subject));
99
- }
100
- else {
101
- //TODO review this, do we need property & subject in both of these? currently yes, but why
102
- return new QueryPrimitiveSet([''], property, subject, [
103
- new QueryPrimitive('', property, subject),
104
- ]);
105
- }
106
- }
107
- //if an object is expected and no value shape is set, then warn
108
- throw Error(`No shape set for objectProperty ${property.parentNodeShape.label}.${property.label}`);
109
- }
110
- getOriginalValue() {
111
- return this.originalValue;
112
- }
113
- getPropertyStep() {
114
- return {
115
- property: this.property,
116
- where: this.wherePath,
117
- };
118
- }
119
- preloadFor(component) {
120
- return new BoundComponent(component, this);
121
- }
122
- /**
123
- * Pagination is applied to a nested *select*, not to a bare traversal — use
124
- * `p.friends.select(f => f.name).limit(n)`. Calling `.limit()` directly on a
125
- * traversal would silently do nothing, so we fail loudly instead.
126
- * (Top-level result pagination lives on the outer query builder.)
127
- */
128
- limit(lim) {
129
- throw new Error(`.limit(${lim}) is not supported directly on a traversal — use ` +
130
- '.select(...).limit(n) on the nested collection (single-subject queries only).');
131
- }
132
- /**
133
- * Returns the path of properties that were requested to reach this value
134
- */
135
- getPropertyPath(currentPath) {
136
- var _a;
137
- let path = currentPath || [];
138
- //add the step of this object to the beginning of the path (so that the next parent will always before the current item)
139
- if (this.property || this.wherePath) {
140
- path.unshift(this.getPropertyStep());
141
- }
142
- if (this.subject) {
143
- return this.subject.getPropertyPath(path);
144
- }
145
- //when query context is used as the first step, then the first step is just a pointer to the subject it represents
146
- if ((_a = this.originalValue) === null || _a === void 0 ? void 0 : _a.__queryContextId) {
147
- path.unshift(convertQueryContext(this));
148
- }
149
- return path;
150
- }
151
- }
152
- exports.QueryBuilderObject = QueryBuilderObject;
153
- class BoundComponent extends QueryBuilderObject {
154
- constructor(originalValue, source) {
155
- super(null, null);
156
- this.originalValue = originalValue;
157
- this.source = source;
158
- }
159
- }
160
- exports.BoundComponent = BoundComponent;
161
- /**
162
- * Converts query context to a ShapeReferenceValue
163
- */
164
- const convertQueryContext = (shape) => {
165
- return {
166
- id: shape.originalValue.__queryContextId,
167
- shape: {
168
- id: shape.originalValue.nodeShape.id,
169
- },
170
- };
171
- };
172
- const processWhereClause = (validation, shape) => {
173
- if (validation instanceof Function) {
174
- if (!shape) {
175
- throw new Error('Cannot process where clause without shape');
176
- }
177
- const proxy = (0, ProxiedPathBuilder_js_1.createProxiedPathBuilder)(shape);
178
- const result = validation(proxy);
179
- if ((0, ExpressionNode_js_1.isExpressionNode)(result)) {
180
- return { expressionNode: result };
181
- }
182
- if ((0, ExpressionNode_js_1.isExistsCondition)(result)) {
183
- return { existsCondition: result };
184
- }
185
- throw new Error('WHERE callback must return ExpressionNode or ExistsCondition');
186
- }
187
- else if ((0, ExpressionNode_js_1.isExpressionNode)(validation)) {
188
- return { expressionNode: validation };
189
- }
190
- else if ((0, ExpressionNode_js_1.isExistsCondition)(validation)) {
191
- return { existsCondition: validation };
192
- }
193
- else {
194
- throw new Error('WHERE clause must be ExpressionNode, ExistsCondition, or a callback');
195
- }
196
- };
197
- exports.processWhereClause = processWhereClause;
198
- // ---------------------------------------------------------------------------
199
- // Expression method proxy for QueryPrimitive
200
- // ---------------------------------------------------------------------------
201
- const EXPRESSION_METHODS = new Set([
202
- 'plus', 'minus', 'times', 'divide', 'abs', 'round', 'ceil', 'floor', 'power',
203
- 'equals', 'eq', 'neq', 'notEquals', 'gt', 'greaterThan', 'gte', 'greaterThanOrEqual',
204
- 'lt', 'lessThan', 'lte', 'lessThanOrEqual', 'oneOf', 'notOneOf',
205
- 'concat', 'contains', 'startsWith', 'endsWith', 'substr', 'before', 'after',
206
- 'replace', 'ucase', 'lcase', 'strlen', 'encodeForUri', 'matches',
207
- 'year', 'month', 'day', 'hours', 'minutes', 'seconds', 'timezone', 'tz',
208
- 'and', 'or', 'not',
209
- 'isDefined', 'isNotDefined', 'defaultTo',
210
- 'lang', 'datatype', 'str', 'iri', 'isIri', 'isLiteral', 'isBlank', 'isNumeric',
211
- 'md5', 'sha256', 'sha512',
212
- ]);
213
- /**
214
- * Convert a QueryBuilderObject to a traced ExpressionNode by extracting its
215
- * property path segments and creating a property expression reference.
216
- * This is the bridge between the query proxy world and the expression IR world.
217
- */
218
- function toExpressionNode(qbo) {
219
- // Check if this is a query context reference. We carry the context *name*
220
- // (not the resolved id): it serializes as `{@ctx}` and is resolved by `lower()`.
221
- const contextName = findContextName(qbo);
222
- if (contextName) {
223
- const segments = FieldSet_js_1.FieldSet.collectPropertySegments(qbo);
224
- if (segments.length > 0) {
225
- // Context property access (e.g. getQueryContext('user').name) → context_property_expr
226
- const lastSegment = segments[segments.length - 1].id;
227
- const ir = { kind: 'context_property_expr', contextName, property: lastSegment };
228
- return new ExpressionNode_js_1.ExpressionNode(ir);
229
- }
230
- // Context root reference (e.g. getQueryContext('user')) → reference_expr
231
- const ir = { kind: 'reference_expr', contextName };
232
- return new ExpressionNode_js_1.ExpressionNode(ir);
233
- }
234
- const segments = FieldSet_js_1.FieldSet.collectPropertySegments(qbo);
235
- if (segments.length === 0) {
236
- // Root shape or entity reference — produce alias expression (the entity itself)
237
- return (0, ExpressionNode_js_1.tracedAliasExpression)([]);
238
- }
239
- const segmentIds = segments.map((s) => s.id);
240
- return (0, ExpressionNode_js_1.tracedPropertyExpression)(segmentIds);
241
- }
242
- /** Walk up the QueryBuilderObject chain to find a query context *name* (for `{@ctx}`). */
243
- function findContextName(qbo) {
244
- var _a;
245
- let current = qbo;
246
- while (current) {
247
- if (current instanceof QueryShape && ((_a = current.originalValue) === null || _a === void 0 ? void 0 : _a.__queryContextName)) {
248
- return current.originalValue.__queryContextName;
249
- }
250
- current = current.subject;
251
- }
252
- return undefined;
253
- }
254
- /**
255
- * A wrapper for inline `.where()` on primitives that produces alias-based expressions.
256
- * When `p.hobby.where(h => h.equals('Jogging'))` is called, `h` should reference
257
- * the hobby variable itself (alias), not traverse to a sub-property.
258
- */
259
- class InlineWhereProxy extends QueryBuilderObject {
260
- constructor(source) {
261
- super(source.property, source.subject);
262
- this.source = source;
263
- }
264
- equals(otherValue) {
265
- // Empty traversal = "the current alias" — resolved by lowering
266
- // against the property's own alias scope
267
- const self = (0, ExpressionNode_js_1.tracedAliasExpression)([]);
268
- return self.eq(otherValue);
269
- }
270
- }
271
- /**
272
- * Wrap a QueryPrimitive in a Proxy that intercepts expression method calls.
273
- * When an expression method (e.g., `.plus()`, `.gt()`, `.equals()`) is accessed,
274
- * creates a traced ExpressionNode based on the QueryPrimitive's property path.
275
- */
276
- function wrapWithExpressionProxy(qp) {
277
- return new Proxy(qp, {
278
- get(target, key, receiver) {
279
- if (typeof key === 'string' && EXPRESSION_METHODS.has(key)) {
280
- const segments = FieldSet_js_1.FieldSet.collectPropertySegments(target);
281
- // Only intercept if we have valid property segments to trace
282
- if (segments.length > 0) {
283
- // Use toExpressionNode so a context property as the *self* of an
284
- // expression (e.g. getQueryContext('user').name.equals(x)) becomes a
285
- // context_property_expr, not a root-entity property_expr.
286
- const baseNode = toExpressionNode(target);
287
- return (...args) => {
288
- // Convert QueryBuilderObject arguments to ExpressionNode
289
- const convertedArgs = args.map((arg) => { var _a; return arg instanceof QueryBuilderObject ? ((_a = toExpressionNode(arg)) !== null && _a !== void 0 ? _a : arg) : arg; });
290
- return baseNode[key](...convertedArgs);
291
- };
292
- }
293
- }
294
- return Reflect.get(target, key, receiver);
295
- },
296
- });
297
- }
298
- /**
299
- * Evaluate a sort callback through the proxy and extract a SortByPath.
300
- * This is a standalone helper that replaces the need for the former SelectQueryFactory.sortBy().
301
- */
302
- const evaluateSortCallback = (shape, sortFn, direction = 'ASC') => {
303
- const proxy = (0, ProxiedPathBuilder_js_1.createProxiedPathBuilder)(shape);
304
- const response = sortFn(proxy);
305
- const nodeShape = shape.shape;
306
- const paths = [];
307
- if (response instanceof QueryBuilderObject || response instanceof QueryPrimitiveSet) {
308
- paths.push(new PropertyPath_js_1.PropertyPath(nodeShape, FieldSet_js_1.FieldSet.collectPropertySegments(response)));
309
- }
310
- else if (Array.isArray(response)) {
311
- for (const item of response) {
312
- if (item instanceof QueryBuilderObject) {
313
- paths.push(new PropertyPath_js_1.PropertyPath(nodeShape, FieldSet_js_1.FieldSet.collectPropertySegments(item)));
314
- }
315
- }
316
- }
317
- // The DSL callback carries a single direction for all its paths; per-path
318
- // directions come from the wire form (deserializeSortByPath).
319
- return { paths, directions: paths.map(() => direction) };
320
- };
321
- exports.evaluateSortCallback = evaluateSortCallback;
322
- class QueryShapeSet extends QueryBuilderObject {
323
- constructor(_originalValue, property, subject) {
324
- super(property, subject);
325
- this.originalValue = _originalValue;
326
- //Note that QueryShapeSet intentionally does not store the _originalValue shape set, because it manipulates this.queryShapes
327
- // and then recreates the original shape set when getOriginalValue() is called
328
- this.queryShapes = new CoreSet_js_1.CoreSet(_originalValue === null || _originalValue === void 0 ? void 0 : _originalValue.map((shape) => QueryShape.create(shape, property, subject)));
329
- }
330
- static create(originalValue, property, subject) {
331
- let instance = new QueryShapeSet(originalValue, property, subject);
332
- let proxy = this.proxifyShapeSet(instance);
333
- return proxy;
334
- }
335
- static proxifyShapeSet(queryShapeSet) {
336
- let originalShapeSet = queryShapeSet.getOriginalValue();
337
- queryShapeSet.proxy = new Proxy(queryShapeSet, {
338
- get(target, key, receiver) {
339
- var _a, _b;
340
- //if the key is a string
341
- if (typeof key === 'string') {
342
- //if this is a get method that is implemented by the QueryShapeSet, then use that
343
- if (key in queryShapeSet) {
344
- //if it's a function, then bind it to the queryShape and return it so it can be called
345
- if (typeof queryShapeSet[key] === 'function') {
346
- return target[key].bind(target);
347
- }
348
- //if it's a get method, then return that
349
- //NOTE: we may not need this if we don't use any get methods in QueryValue classes?
350
- return queryShapeSet[key];
351
- }
352
- //if not, then a method/accessor was called that likely fits with the methods of the original SHAPE of the items in the shape set
353
- //As in Shape.friends.name -> key would be name, which is requested from (each item in!) a ShapeSet of Shapes
354
- //So here we find back the shape that all items have in common, and then find the property shape that matches the key
355
- //NOTE: this will only work if the key corresponds with an accessor in the shape that uses a @linkedProperty decorator
356
- let leastSpecificShape = queryShapeSet
357
- .getOriginalValue()
358
- .getLeastSpecificShape();
359
- let valueShape = leastSpecificShape ? leastSpecificShape.shape : null;
360
- if (!valueShape && ((_a = queryShapeSet.property) === null || _a === void 0 ? void 0 : _a.valueShape)) {
361
- const shapeClass = (0, ShapeClass_js_1.getShapeClass)(queryShapeSet.property.valueShape);
362
- valueShape = shapeClass === null || shapeClass === void 0 ? void 0 : shapeClass.shape;
363
- }
364
- let propertyShape = valueShape === null || valueShape === void 0 ? void 0 : valueShape.getPropertyShapes(true).find((propertyShape) => propertyShape.label === key);
365
- //if the property shape is found
366
- if (propertyShape) {
367
- return queryShapeSet.callPropertyShapeAccessor(propertyShape);
368
- }
369
- else if (
370
- //else if a genuine collection method of the ShapeSet is called
371
- //(.forEach()/.map()/… — including symbol methods like iteration)
372
- originalShapeSet[key] &&
373
- typeof originalShapeSet[key] === 'function') {
374
- //then return that method and bind the original value as 'this'
375
- return originalShapeSet[key].bind(originalShapeSet);
376
- }
377
- else if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {
378
- // Same policy as the single-node proxy: an undecorated string key
379
- // is a genuine misuse (it would silently return a broken path over
380
- // the set → silently-wrong results). Throw. Interop/framework keys
381
- // and symbols pass through.
382
- throw new Error(`${(_b = valueShape === null || valueShape === void 0 ? void 0 : valueShape.label) !== null && _b !== void 0 ? _b : 'shape'}.${key} is accessed in a query, but it does not have a @linkedProperty decorator. Queries can only access decorated get/set methods (@objectProperty / @literalProperty).`);
383
- }
384
- }
385
- //otherwise return the value of the property on the original shape
386
- return originalShapeSet[key];
387
- },
388
- });
389
- return queryShapeSet.proxy;
390
- }
391
- as(shape) {
392
- //if the shape is not the same as the original value, then we need to create a new query shape
393
- if (!shape.shape.equals(this.originalValue.getLeastSpecificShape().shape)) {
394
- let newOriginal = new ShapeSet_js_1.ShapeSet(this.originalValue.map((existing) => {
395
- const instance = new shape();
396
- if (existing === null || existing === void 0 ? void 0 : existing.id) {
397
- instance.id = existing.id;
398
- }
399
- return instance;
400
- }));
401
- return QueryShapeSet.create(newOriginal, this.property, this.subject);
402
- }
403
- // else return this
404
- return this;
405
- }
406
- add(item) {
407
- this.queryShapes.add(item);
408
- }
409
- concat(other) {
410
- if (other) {
411
- if (other instanceof QueryShapeSet) {
412
- other.queryShapes.forEach(this.queryShapes.add.bind(this.queryShapes));
413
- }
414
- else {
415
- throw new Error('Unknown type: ' + other);
416
- }
417
- }
418
- return this;
419
- }
420
- getOriginalValue() {
421
- return new ShapeSet_js_1.ShapeSet(this.queryShapes.map((shape) => {
422
- return shape.originalValue;
423
- }));
424
- }
425
- callPropertyShapeAccessor(propertyShape) {
426
- //call the get method for that property shape on each item in the shape set
427
- //and return the result as a new shape set
428
- let result; //QueryValueSetOfSets;
429
- //if we expect the accessor to return a Primitive (string,number,boolean,Date)
430
- if (isSameRef(propertyShape.nodeKind, shacl_js_1.shacl.Literal)) {
431
- //then return a Set of QueryPrimitives
432
- result = new QueryPrimitiveSet(null, propertyShape, this);
433
- }
434
- else {
435
- // result = QueryValueSetOfSets.create(propertyShape, this); //QueryShapeSet.create(null, propertyShape, this);
436
- result = QueryShapeSet.create(null, propertyShape, this);
437
- }
438
- let expectSingleValues = typeof propertyShape.maxCount === 'number' && propertyShape.maxCount <= 1;
439
- this.queryShapes.forEach((shape) => {
440
- //access the propertyShapes accessor,
441
- // since the shape should already be converted to a QueryShape, the result is a QueryValue also
442
- let shapeQueryValue = shape[propertyShape.label];
443
- //only add results if something was actually returned, if the property is not defined for this shape the result can be undefined
444
- if (shapeQueryValue) {
445
- if (expectSingleValues) {
446
- result.add(shapeQueryValue);
447
- }
448
- else {
449
- //if each of the shapes in a set return a new shapeset for the request accessor
450
- //then we merge all the returned values into a single shapeset
451
- result.concat(shapeQueryValue);
452
- }
453
- }
454
- });
455
- return result;
456
- }
457
- //countable?, resultKey?: string
458
- size() {
459
- //when count() is called we want to count the number of items in the entire query path
460
- return new SetSize(this); //countable, resultKey
461
- }
462
- // get testItem() {}
463
- where(validation) {
464
- if (this.getPropertyPath().some((step) => step.where)) {
465
- throw new Error('You cannot call where() from within a where() clause. Consider using some() or every() instead');
466
- }
467
- let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();
468
- this.wherePath = (0, exports.processWhereClause)(validation, leastSpecificShape);
469
- //return this.proxy because after Shape.friends.where() we can call other methods of Shape.friends
470
- //and for that we need the proxy
471
- return this.proxy;
472
- }
473
- select(subQueryFn) {
474
- const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();
475
- const parentSegments = FieldSet_js_1.FieldSet.collectPropertySegments(this);
476
- const fs = FieldSet_js_1.FieldSet.forSubSelect(leastSpecificShape, subQueryFn, parentSegments, this);
477
- return fs;
478
- }
479
- selectAll() {
480
- let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();
481
- const propertyLabels = leastSpecificShape.shape
482
- .getUniquePropertyShapes()
483
- .map((propertyShape) => propertyShape.label);
484
- return this.select((shape) => propertyLabels.map((label) => shape[label]));
485
- }
486
- some(validation) {
487
- const predicate = this.buildPredicateExpression(validation);
488
- const pathSegmentIds = FieldSet_js_1.FieldSet.collectPropertySegments(this).map(s => s.id);
489
- return new ExpressionNode_js_1.ExistsCondition(pathSegmentIds, predicate, false);
490
- }
491
- every(validation) {
492
- // every(fn) = NOT EXISTS(path WHERE NOT(fn))
493
- const predicate = this.buildPredicateExpression(validation);
494
- const pathSegmentIds = FieldSet_js_1.FieldSet.collectPropertySegments(this).map(s => s.id);
495
- return new ExpressionNode_js_1.ExistsCondition(pathSegmentIds, predicate.not(), true);
496
- }
497
- none(validation) {
498
- // none(fn) = NOT EXISTS(path WHERE fn) = some(fn).not()
499
- const predicate = this.buildPredicateExpression(validation);
500
- const pathSegmentIds = FieldSet_js_1.FieldSet.collectPropertySegments(this).map(s => s.id);
501
- return new ExpressionNode_js_1.ExistsCondition(pathSegmentIds, predicate, true);
502
- }
503
- buildPredicateExpression(validation) {
504
- const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();
505
- if (validation instanceof Function) {
506
- const proxy = (0, ProxiedPathBuilder_js_1.createProxiedPathBuilder)(leastSpecificShape);
507
- const result = validation(proxy);
508
- if ((0, ExpressionNode_js_1.isExpressionNode)(result)) {
509
- return result;
510
- }
511
- throw new Error('Validation callback must return an ExpressionNode or ExistsCondition');
512
- }
513
- if ((0, ExpressionNode_js_1.isExpressionNode)(validation)) {
514
- return validation;
515
- }
516
- throw new Error('Expected a callback or ExpressionNode for some/every/none');
517
- }
518
- }
519
- exports.QueryShapeSet = QueryShapeSet;
520
- class QueryShape extends QueryBuilderObject {
521
- constructor(originalValue, property, subject) {
522
- super(property, subject);
523
- this.originalValue = originalValue;
524
- }
525
- get id() {
526
- return (this.originalValue.__queryContextId ||
527
- this.originalValue['id']);
528
- }
529
- static create(original, property, subject) {
530
- let instance = new QueryShape(original, property, subject);
531
- let proxy = this.proxifyQueryShape(instance);
532
- return proxy;
533
- }
534
- static proxifyQueryShape(queryShape) {
535
- let originalShape = queryShape.originalValue;
536
- queryShape.proxy = new Proxy(queryShape, {
537
- get(target, key, receiver) {
538
- //if the key is a string
539
- if (typeof key === 'string') {
540
- //if this is a get method that is implemented by the QueryShape, then use that
541
- if (key in queryShape) {
542
- //if it's a function, then bind it to the queryShape and return it so it can be called
543
- if (typeof queryShape[key] === 'function') {
544
- return target[key].bind(target);
545
- }
546
- //if it's a get method, then return that
547
- //NOTE: we may not need this if we don't use any get methods in QueryValue classes?
548
- return queryShape[key];
549
- }
550
- //if not, then a method/accessor of the original shape was called
551
- //then check if we have indexed any property shapes with that name for this shapes NodeShape
552
- //NOTE: this will only work with a @linkedProperty decorator
553
- let propertyShape = (0, ShapeClass_js_1.getPropertyShapeByLabel)(originalShape.constructor, key);
554
- if (propertyShape) {
555
- return QueryBuilderObject.generatePathValue(propertyShape, target);
556
- }
557
- }
558
- // A string key that is neither a QueryShape member nor a decorated
559
- // property is a genuine misuse: it would silently return the raw value
560
- // and the query would run with a broken path (silently-wrong results).
561
- // Throw. Symbols and framework/interop keys pass through untouched so
562
- // promise-awaiting, React, and serializers can still introspect the proxy.
563
- if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {
564
- throw new Error(`${originalShape.constructor.name}.${key} is accessed in a query, but it does not have a @linkedProperty decorator. Queries can only access decorated get/set methods (@objectProperty / @literalProperty).`);
565
- }
566
- return originalShape[key];
567
- },
568
- });
569
- return queryShape.proxy;
570
- }
571
- as(shape) {
572
- //if the shape is not the same as the original value, then we need to create a new query shape
573
- if (!shape.shape.equals(this.originalValue.nodeShape)) {
574
- let newOriginal = new shape();
575
- if (this.originalValue.id) {
576
- newOriginal.id = this.originalValue.id;
577
- }
578
- return QueryShape.create(newOriginal, this.property, this.subject);
579
- }
580
- return this;
581
- }
582
- equals(otherValue) {
583
- const self = toExpressionNode(this);
584
- // An unresolved query-context reference (`getQueryContext('user')` before it
585
- // is set) carries no `.id` yet — keep it as a `{@ctx}` ref, resolved at lower.
586
- if (otherValue instanceof QueryContext_js_1.PendingQueryContext) {
587
- return self.eq(otherValue);
588
- }
589
- //validate the value is formed correctly
590
- if (!otherValue.id) {
591
- throw Error(`Invalid value for .equals(). ${JSON.stringify(otherValue)}`);
592
- }
593
- const arg = otherValue instanceof QueryBuilderObject
594
- ? toExpressionNode(otherValue)
595
- : otherValue;
596
- return self.eq(arg);
597
- }
598
- oneOf(values) {
599
- return toExpressionNode(this).oneOf(values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)));
600
- }
601
- notOneOf(values) {
602
- return toExpressionNode(this).notOneOf(values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)));
603
- }
604
- select(subQueryFn) {
605
- const leastSpecificShape = (0, ShapeClass_js_1.getShapeClass)(this.getOriginalValue().nodeShape.id);
606
- const parentSegments = FieldSet_js_1.FieldSet.collectPropertySegments(this);
607
- const fs = FieldSet_js_1.FieldSet.forSubSelect(leastSpecificShape, subQueryFn, parentSegments, this);
608
- return fs;
609
- }
610
- selectAll() {
611
- let leastSpecificShape = (0, ShapeClass_js_1.getShapeClass)(this.getOriginalValue().nodeShape.id);
612
- const propertyLabels = leastSpecificShape.shape
613
- .getUniquePropertyShapes()
614
- .map((propertyShape) => propertyShape.label);
615
- return this.select((shape) => propertyLabels.map((label) => shape[label]));
616
- }
617
- }
618
- exports.QueryShape = QueryShape;
619
- /**
620
- * Concrete query wrapper for JS primitive values (string, number, boolean, Date).
621
- *
622
- * Replaces the former abstract class + subclasses (QueryString, QueryNumber,
623
- * QueryBoolean, QueryDate) — the type parameter T carries the primitive type,
624
- * so separate subclasses are unnecessary.
625
- */
626
- class QueryPrimitive extends QueryBuilderObject {
627
- constructor(originalValue, property, subject) {
628
- super(property, subject);
629
- this.originalValue = originalValue;
630
- this.property = property;
631
- this.subject = subject;
632
- }
633
- equals(otherValue) {
634
- const self = toExpressionNode(this);
635
- const arg = otherValue instanceof QueryBuilderObject
636
- ? toExpressionNode(otherValue)
637
- : otherValue;
638
- return self.eq(arg);
639
- }
640
- oneOf(values) {
641
- return toExpressionNode(this).oneOf(values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)));
642
- }
643
- notOneOf(values) {
644
- return toExpressionNode(this).notOneOf(values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)));
645
- }
646
- where(validation) {
647
- // For inline where on a primitive (p.hobby.where(h => h.equals(...))),
648
- // pass a clone that produces alias expressions (the bound value itself)
649
- // rather than property traversals
650
- const selfAsAlias = new InlineWhereProxy(this);
651
- this.wherePath = (0, exports.processWhereClause)(validation, selfAsAlias);
652
- //return this because after Shape.friends.where() we can call other methods of Shape.friends
653
- return this;
654
- }
655
- }
656
- exports.QueryPrimitive = QueryPrimitive;
657
- class QueryPrimitiveSet extends QueryBuilderObject {
658
- constructor(originalValue, property, subject, items) {
659
- super(property, subject);
660
- this.originalValue = originalValue;
661
- this.property = property;
662
- this.subject = subject;
663
- this.contents = new CoreSet_js_1.CoreSet(items);
664
- }
665
- add(item) {
666
- this.contents.add(item);
667
- }
668
- values() {
669
- return [...this.contents.values()];
670
- }
671
- //this is needed because we extend CoreSet which has a createNew method but does not expect the constructor to have arguments
672
- createNew(...args) {
673
- return new this.constructor(this.property, this.subject, ...args);
674
- }
675
- //TODO: see if we can merge these methods of QueryPrimitive and QueryPrimitiveSet
676
- // so that they're only defined once
677
- equals(other) {
678
- return toExpressionNode(this).eq(other);
679
- }
680
- getPropertyStep() {
681
- if (this.contents.size > 1) {
682
- throw new Error('This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values');
683
- }
684
- return this.contents.first().getPropertyStep();
685
- }
686
- getPropertyPath() {
687
- if (this.contents.size > 1) {
688
- throw new Error('This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values');
689
- }
690
- //here we let the first item in the set return its property path, because all items will be the same
691
- //however, sometimes the path goes through the subject of this SET rather than the individual items (which have an individual shape as subject)
692
- //so we pass the subject of this set so it can be used
693
- let first = this.contents.first();
694
- if (first) {
695
- first.subject.wherePath =
696
- first.subject.wherePath || this.subject.wherePath;
697
- return first.getPropertyPath();
698
- }
699
- else {
700
- console.warn(`QueryPrimitiveSet without items. From ${this.subject.getOriginalValue().nodeShape.label}.${this.property.label}. What to return as property path?`);
701
- return this.subject.getPropertyPath();
702
- }
703
- }
704
- //countable, resultKey?: string
705
- size() {
706
- return new SetSize(this);
707
- //countable, resultKey
708
- }
709
- }
710
- exports.QueryPrimitiveSet = QueryPrimitiveSet;
711
- class SetSize extends QueryPrimitive {
712
- constructor(subject, countable, label) {
713
- super();
714
- this.subject = subject;
715
- this.countable = countable;
716
- this.label = label;
717
- }
718
- // Build an aggregate_expr(count, …) ExpressionNode for the counted property.
719
- toCountExpr() {
720
- const countedSegments = FieldSet_js_1.FieldSet.collectPropertySegments(this.subject);
721
- const countedIds = countedSegments.map((s) => s.id);
722
- const countedNode = (0, ExpressionNode_js_1.tracedPropertyExpression)(countedIds);
723
- return new ExpressionNode_js_1.ExpressionNode({ kind: 'aggregate_expr', name: 'count', args: [countedNode.ir] }, countedNode._refs);
724
- }
725
- // Comparisons on the count (lowered to a HAVING clause on COUNT(…)).
726
- equals(v) { return this.toCountExpr().eq(v); }
727
- eq(v) { return this.toCountExpr().eq(v); }
728
- neq(v) { return this.toCountExpr().neq(v); }
729
- notEquals(v) { return this.toCountExpr().neq(v); }
730
- gt(v) { return this.toCountExpr().gt(v); }
731
- greaterThan(v) { return this.toCountExpr().gt(v); }
732
- gte(v) { return this.toCountExpr().gte(v); }
733
- greaterThanOrEqual(v) { return this.toCountExpr().gte(v); }
734
- lt(v) { return this.toCountExpr().lt(v); }
735
- lessThan(v) { return this.toCountExpr().lt(v); }
736
- lte(v) { return this.toCountExpr().lte(v); }
737
- lessThanOrEqual(v) { return this.toCountExpr().lte(v); }
738
- as(label) {
739
- this.label = label;
740
- return this;
741
- }
742
- getPropertyPath() {
743
- //count the last property in the path
744
- //use the label of the last property as the label of the count step
745
- let countable = this.subject.getPropertyStep();
746
- let self = {
747
- count: [countable],
748
- label: this.label || this.subject.property.label,
749
- };
750
- //request the path of the subject's subject (the parent of the parent)
751
- //and add the SizeStep to that path, since we already used the subject as the thing that's counted
752
- if (this.subject.subject) {
753
- let path = this.subject.subject.getPropertyPath();
754
- path.push(self);
755
- return path;
756
- }
757
- return [self];
758
- }
759
- }
760
- exports.SetSize = SetSize;
761
- //# sourceMappingURL=SelectQuery.js.map