@_linked/core 1.3.0 → 2.0.0-next.20260310085832

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 (143) hide show
  1. package/CHANGELOG.md +113 -10
  2. package/README.md +209 -14
  3. package/lib/cjs/index.d.ts +10 -2
  4. package/lib/cjs/index.js +31 -6
  5. package/lib/cjs/index.js.map +1 -1
  6. package/lib/cjs/package.d.ts +1 -1
  7. package/lib/cjs/queries/CreateBuilder.d.ts +38 -0
  8. package/lib/cjs/queries/CreateBuilder.js +100 -0
  9. package/lib/cjs/queries/CreateBuilder.js.map +1 -0
  10. package/lib/cjs/queries/CreateQuery.d.ts +3 -3
  11. package/lib/cjs/queries/CreateQuery.js.map +1 -1
  12. package/lib/cjs/queries/DeleteBuilder.d.ts +39 -0
  13. package/lib/cjs/queries/DeleteBuilder.js +85 -0
  14. package/lib/cjs/queries/DeleteBuilder.js.map +1 -0
  15. package/lib/cjs/queries/DeleteQuery.d.ts +3 -3
  16. package/lib/cjs/queries/DeleteQuery.js.map +1 -1
  17. package/lib/cjs/queries/FieldSet.d.ts +203 -0
  18. package/lib/cjs/queries/FieldSet.js +533 -0
  19. package/lib/cjs/queries/FieldSet.js.map +1 -0
  20. package/lib/cjs/queries/IRDesugar.d.ts +13 -8
  21. package/lib/cjs/queries/IRDesugar.js +143 -132
  22. package/lib/cjs/queries/IRDesugar.js.map +1 -1
  23. package/lib/cjs/queries/IRLower.js +1 -0
  24. package/lib/cjs/queries/IRLower.js.map +1 -1
  25. package/lib/cjs/queries/IntermediateRepresentation.d.ts +1 -0
  26. package/lib/cjs/queries/MutationQuery.d.ts +1 -1
  27. package/lib/cjs/queries/MutationQuery.js +1 -6
  28. package/lib/cjs/queries/MutationQuery.js.map +1 -1
  29. package/lib/cjs/queries/PropertyPath.d.ts +38 -0
  30. package/lib/cjs/queries/PropertyPath.js +82 -0
  31. package/lib/cjs/queries/PropertyPath.js.map +1 -0
  32. package/lib/cjs/queries/ProxiedPathBuilder.d.ts +14 -0
  33. package/lib/cjs/queries/ProxiedPathBuilder.js +29 -0
  34. package/lib/cjs/queries/ProxiedPathBuilder.js.map +1 -0
  35. package/lib/cjs/queries/QueryBuilder.d.ts +141 -0
  36. package/lib/cjs/queries/QueryBuilder.js +334 -0
  37. package/lib/cjs/queries/QueryBuilder.js.map +1 -0
  38. package/lib/cjs/queries/SelectQuery.d.ts +60 -134
  39. package/lib/cjs/queries/SelectQuery.js +67 -526
  40. package/lib/cjs/queries/SelectQuery.js.map +1 -1
  41. package/lib/cjs/queries/UpdateBuilder.d.ts +37 -0
  42. package/lib/cjs/queries/UpdateBuilder.js +84 -0
  43. package/lib/cjs/queries/UpdateBuilder.js.map +1 -0
  44. package/lib/cjs/queries/UpdateQuery.d.ts +3 -3
  45. package/lib/cjs/queries/UpdateQuery.js.map +1 -1
  46. package/lib/cjs/queries/WhereCondition.d.ts +18 -0
  47. package/lib/cjs/queries/WhereCondition.js +3 -0
  48. package/lib/cjs/queries/WhereCondition.js.map +1 -0
  49. package/lib/cjs/queries/resolveShape.d.ts +10 -0
  50. package/lib/cjs/queries/resolveShape.js +23 -0
  51. package/lib/cjs/queries/resolveShape.js.map +1 -0
  52. package/lib/cjs/shapes/SHACL.js +7 -5
  53. package/lib/cjs/shapes/SHACL.js.map +1 -1
  54. package/lib/cjs/shapes/Shape.d.ts +33 -52
  55. package/lib/cjs/shapes/Shape.js +36 -56
  56. package/lib/cjs/shapes/Shape.js.map +1 -1
  57. package/lib/cjs/sparql/SparqlAlgebra.d.ts +6 -1
  58. package/lib/cjs/sparql/algebraToString.js +10 -0
  59. package/lib/cjs/sparql/algebraToString.js.map +1 -1
  60. package/lib/cjs/sparql/irToAlgebra.js +6 -2
  61. package/lib/cjs/sparql/irToAlgebra.js.map +1 -1
  62. package/lib/cjs/test-helpers/query-fixtures.d.ts +568 -3049
  63. package/lib/cjs/test-helpers/query-fixtures.js +59 -18
  64. package/lib/cjs/test-helpers/query-fixtures.js.map +1 -1
  65. package/lib/cjs/test-helpers/test-utils.d.ts +18 -0
  66. package/lib/cjs/test-helpers/test-utils.js +47 -0
  67. package/lib/cjs/test-helpers/test-utils.js.map +1 -0
  68. package/lib/cjs/utils/Package.d.ts +8 -8
  69. package/lib/cjs/utils/Package.js.map +1 -1
  70. package/lib/cjs/utils/ShapeClass.d.ts +2 -2
  71. package/lib/cjs/utils/ShapeClass.js +4 -22
  72. package/lib/cjs/utils/ShapeClass.js.map +1 -1
  73. package/lib/esm/index.d.ts +10 -2
  74. package/lib/esm/index.js +23 -2
  75. package/lib/esm/index.js.map +1 -1
  76. package/lib/esm/package.d.ts +1 -1
  77. package/lib/esm/queries/CreateBuilder.d.ts +38 -0
  78. package/lib/esm/queries/CreateBuilder.js +96 -0
  79. package/lib/esm/queries/CreateBuilder.js.map +1 -0
  80. package/lib/esm/queries/CreateQuery.d.ts +3 -3
  81. package/lib/esm/queries/CreateQuery.js.map +1 -1
  82. package/lib/esm/queries/DeleteBuilder.d.ts +39 -0
  83. package/lib/esm/queries/DeleteBuilder.js +81 -0
  84. package/lib/esm/queries/DeleteBuilder.js.map +1 -0
  85. package/lib/esm/queries/DeleteQuery.d.ts +3 -3
  86. package/lib/esm/queries/DeleteQuery.js.map +1 -1
  87. package/lib/esm/queries/FieldSet.d.ts +203 -0
  88. package/lib/esm/queries/FieldSet.js +529 -0
  89. package/lib/esm/queries/FieldSet.js.map +1 -0
  90. package/lib/esm/queries/IRDesugar.d.ts +13 -8
  91. package/lib/esm/queries/IRDesugar.js +143 -132
  92. package/lib/esm/queries/IRDesugar.js.map +1 -1
  93. package/lib/esm/queries/IRLower.js +1 -0
  94. package/lib/esm/queries/IRLower.js.map +1 -1
  95. package/lib/esm/queries/IntermediateRepresentation.d.ts +1 -0
  96. package/lib/esm/queries/MutationQuery.d.ts +1 -1
  97. package/lib/esm/queries/MutationQuery.js +1 -6
  98. package/lib/esm/queries/MutationQuery.js.map +1 -1
  99. package/lib/esm/queries/PropertyPath.d.ts +38 -0
  100. package/lib/esm/queries/PropertyPath.js +77 -0
  101. package/lib/esm/queries/PropertyPath.js.map +1 -0
  102. package/lib/esm/queries/ProxiedPathBuilder.d.ts +14 -0
  103. package/lib/esm/queries/ProxiedPathBuilder.js +26 -0
  104. package/lib/esm/queries/ProxiedPathBuilder.js.map +1 -0
  105. package/lib/esm/queries/QueryBuilder.d.ts +141 -0
  106. package/lib/esm/queries/QueryBuilder.js +330 -0
  107. package/lib/esm/queries/QueryBuilder.js.map +1 -0
  108. package/lib/esm/queries/SelectQuery.d.ts +60 -134
  109. package/lib/esm/queries/SelectQuery.js +61 -515
  110. package/lib/esm/queries/SelectQuery.js.map +1 -1
  111. package/lib/esm/queries/UpdateBuilder.d.ts +37 -0
  112. package/lib/esm/queries/UpdateBuilder.js +80 -0
  113. package/lib/esm/queries/UpdateBuilder.js.map +1 -0
  114. package/lib/esm/queries/UpdateQuery.d.ts +3 -3
  115. package/lib/esm/queries/UpdateQuery.js.map +1 -1
  116. package/lib/esm/queries/WhereCondition.d.ts +18 -0
  117. package/lib/esm/queries/WhereCondition.js +2 -0
  118. package/lib/esm/queries/WhereCondition.js.map +1 -0
  119. package/lib/esm/queries/resolveShape.d.ts +10 -0
  120. package/lib/esm/queries/resolveShape.js +20 -0
  121. package/lib/esm/queries/resolveShape.js.map +1 -0
  122. package/lib/esm/shapes/SHACL.js +7 -5
  123. package/lib/esm/shapes/SHACL.js.map +1 -1
  124. package/lib/esm/shapes/Shape.d.ts +33 -52
  125. package/lib/esm/shapes/Shape.js +36 -53
  126. package/lib/esm/shapes/Shape.js.map +1 -1
  127. package/lib/esm/sparql/SparqlAlgebra.d.ts +6 -1
  128. package/lib/esm/sparql/algebraToString.js +10 -0
  129. package/lib/esm/sparql/algebraToString.js.map +1 -1
  130. package/lib/esm/sparql/irToAlgebra.js +6 -2
  131. package/lib/esm/sparql/irToAlgebra.js.map +1 -1
  132. package/lib/esm/test-helpers/query-fixtures.d.ts +568 -3049
  133. package/lib/esm/test-helpers/query-fixtures.js +59 -18
  134. package/lib/esm/test-helpers/query-fixtures.js.map +1 -1
  135. package/lib/esm/test-helpers/test-utils.d.ts +18 -0
  136. package/lib/esm/test-helpers/test-utils.js +41 -0
  137. package/lib/esm/test-helpers/test-utils.js.map +1 -0
  138. package/lib/esm/utils/Package.d.ts +8 -8
  139. package/lib/esm/utils/Package.js.map +1 -1
  140. package/lib/esm/utils/ShapeClass.d.ts +2 -2
  141. package/lib/esm/utils/ShapeClass.js +4 -22
  142. package/lib/esm/utils/ShapeClass.js.map +1 -1
  143. package/package.json +1 -1
@@ -1,11 +1,13 @@
1
- import { Shape, ShapeType } from '../shapes/Shape.js';
1
+ import { Shape, ShapeConstructor } from '../shapes/Shape.js';
2
2
  import { PropertyShape } from '../shapes/SHACL.js';
3
3
  import { ShapeSet } from '../collections/ShapeSet.js';
4
4
  import { CoreSet } from '../collections/CoreSet.js';
5
5
  import { CoreMap } from '../collections/CoreMap.js';
6
- import { NodeReferenceValue, Prettify, QueryFactory, ShapeReferenceValue } from './QueryFactory.js';
7
- import type { RawSelectInput } from './IRDesugar.js';
6
+ import { NodeReferenceValue, Prettify, ShapeReferenceValue } from './QueryFactory.js';
8
7
  import type { IRSelectQuery } from './IntermediateRepresentation.js';
8
+ import { FieldSet } from './FieldSet.js';
9
+ import { PropertyPath } from './PropertyPath.js';
10
+ import type { QueryBuilder } from './QueryBuilder.js';
9
11
  /**
10
12
  * The canonical SelectQuery type — an IR AST node representing a select query.
11
13
  * This is the type received by IQuadStore.selectQuery().
@@ -24,32 +26,22 @@ export type SingleResult<ResultType> = ResultType extends Array<infer R> ? R : R
24
26
  */
25
27
  export type AccessorReturnValue = Shape | ShapeSet | JSPrimitive | NodeReferenceValue;
26
28
  export type WhereClause<S extends Shape | AccessorReturnValue> = Evaluation | ((s: ToQueryBuilderObject<S>) => Evaluation);
27
- export type QueryBuildFn<T extends Shape, ResponseType> = (p: ToQueryBuilderObject<T>, q: SelectQueryFactory<T>) => ResponseType;
29
+ export type QueryBuildFn<T extends Shape, ResponseType> = (p: ToQueryBuilderObject<T>) => ResponseType;
28
30
  export type QueryWrapperObject<ShapeType extends Shape = any> = {
29
- [key: string]: SelectQueryFactory<ShapeType>;
31
+ [key: string]: FieldSet<any, any>;
30
32
  };
31
- export type CustomQueryObject = {
32
- [key: string]: QueryPath;
33
- };
34
- export type SelectPath = QueryPath[] | CustomQueryObject;
35
33
  export type SortByPath = {
36
- paths: QueryPath[];
34
+ paths: PropertyPath[];
37
35
  direction: 'ASC' | 'DESC';
38
36
  };
39
- export type SubQueryPaths = SelectPath;
40
- /**
41
- * A QueryPath is an array of QuerySteps, representing the path of properties that were requested to reach a certain value
42
- */
43
- export type QueryPath = (QueryStep | SubQueryPaths)[] | WherePath;
44
37
  /**
45
- * Much like a querypath, except it can only contain QuerySteps
38
+ * A property-only query path, used by where/sort proxy tracing.
46
39
  */
47
40
  export type QueryPropertyPath = QueryStep[];
48
41
  /**
49
- * A QueryStep is a single step in a query path
50
- * It contains the property that was requested, and optionally a where clause
42
+ * A QueryStep is a single step in a query path.
51
43
  */
52
- export type QueryStep = PropertyQueryStep | SizeStep | CustomQueryObject | ShapeReferenceValue;
44
+ export type QueryStep = PropertyQueryStep | SizeStep | ShapeReferenceValue;
53
45
  export type SizeStep = {
54
46
  count: QueryPropertyPath;
55
47
  label?: string;
@@ -99,8 +91,10 @@ export type QShapeSet<ShapeSetType extends Shape, Source = null, Property extend
99
91
  * Shapes are converted to QueryShapes, but also inherit all the properties of the shape (with converted result types)
100
92
  */
101
93
  export type QShape<T extends Shape, Source = any, Property extends string | number | symbol = any> = QueryShape<T, Source, Property> & QueryShapeProps<T, Source, Property>;
102
- export type ToQueryBuilderObject<T, Source = null, Property extends string | number | symbol = ''> = T extends ShapeSet<infer ShapeSetType> ? QShapeSet<ShapeSetType, Source, Property> : T extends Shape ? QShape<T, Source, Property> : T extends string | number | Date | boolean ? ToQueryPrimitive<T, Source, Property> : T extends Array<infer AT> ? AT extends Date | string | number ? QueryPrimitiveSet<ToQueryPrimitive<AT, Source, Property>> : AT extends boolean ? QueryBoolean : AT[] : T extends NodeReferenceValue ? QShape<Shape, Source, Property> : QueryBuilderObject<T, Source, Property>;
103
- export type ToQueryPrimitive<T extends string | number | Date | boolean, Source, Property extends string | number | symbol = ''> = T extends string ? QueryString<Source, Property> : T extends number ? QueryNumber<Source, Property> : T extends Date ? QueryDate<Source, Property> : T extends boolean ? QueryBoolean<Source, Property> : never;
94
+ export type ToQueryBuilderObject<T, Source = null, Property extends string | number | symbol = ''> = T extends ShapeSet<infer ShapeSetType> ? QShapeSet<ShapeSetType, Source, Property> : T extends Shape ? QShape<T, Source, Property> : T extends string | number | Date | boolean ? ToQueryPrimitive<T, Source, Property> : T extends Array<infer AT> ? AT extends Date | string | number ? QueryPrimitiveSet<ToQueryPrimitive<AT, Source, Property>> : AT extends boolean ? QueryPrimitive<boolean> : AT[] : T extends NodeReferenceValue ? QShape<Shape, Source, Property> : QueryBuilderObject<T, Source, Property>;
95
+ export type ToQueryPrimitive<T extends string | number | Date | boolean, Source, Property extends string | number | symbol = ''> = T extends string ? QueryPrimitive<string, Source, Property> : T extends number ? QueryPrimitive<number, Source, Property> : T extends Date ? QueryPrimitive<Date, Source, Property> : T extends boolean ? QueryPrimitive<boolean, Source, Property> : never & {
96
+ __error: 'ToQueryPrimitive: no matching primitive type';
97
+ };
104
98
  export type WherePath = WhereEvaluationPath | WhereAndOr;
105
99
  export type WhereEvaluationPath = {
106
100
  path: QueryPropertyPath;
@@ -117,10 +111,23 @@ export type ArgPath = {
117
111
  path: QueryPropertyPath;
118
112
  subject: ShapeReferenceValue;
119
113
  };
120
- export type ComponentQueryPath = (QueryStep | SubQueryPaths)[] | WherePath;
121
114
  export type QueryComponentLike<ShapeType extends Shape, CompQueryResult> = {
122
- query: SelectQueryFactory<ShapeType, CompQueryResult> | Record<string, SelectQueryFactory<ShapeType, CompQueryResult>>;
115
+ query: QueryBuilder<ShapeType> | FieldSet | Record<string, QueryBuilder<ShapeType>>;
116
+ fields?: FieldSet;
123
117
  };
118
+ /**
119
+ * Interface that linked components (e.g. from `@_linked/react`'s `linkedComponent()`)
120
+ * must satisfy to participate in preloadFor.
121
+ *
122
+ * Components expose their data requirements as a QueryBuilder,
123
+ * and optionally a FieldSet for declarative field access.
124
+ */
125
+ export interface LinkedComponentInterface<S extends Shape = Shape, R = any> {
126
+ /** The component's data query (QueryBuilder template, not executed). */
127
+ query: QueryBuilder<S, any, R>;
128
+ /** The component's field requirements as a FieldSet. */
129
+ fields?: FieldSet;
130
+ }
124
131
  /**
125
132
  * ###################################
126
133
  * #### QUERY RESULT TYPES ####
@@ -130,7 +137,6 @@ export type NodeResultMap = CoreMap<string, QResult<any, any>>;
130
137
  export type QResult<ShapeType extends Shape = Shape, Object = {}> = Object & {
131
138
  id: string;
132
139
  };
133
- export type QueryProps<Q extends SelectQueryFactory<any>> = Q extends SelectQueryFactory<infer ShapeType, infer ResponseType> ? QueryResponseToResultType<ResponseType, ShapeType> : never;
134
140
  export type QueryControllerProps = {
135
141
  query?: QueryController;
136
142
  };
@@ -140,28 +146,25 @@ export type QueryController = {
140
146
  setLimit: (limit: number) => void;
141
147
  setPage: (page: number) => void;
142
148
  };
143
- export type PatchedQueryPromise<ResultType, ShapeType extends Shape> = {
144
- where(validation: WhereClause<ShapeType>): PatchedQueryPromise<ResultType, ShapeType>;
145
- limit(lim: number): PatchedQueryPromise<ResultType, ShapeType>;
146
- sortBy(sortParam: any, direction?: 'ASC' | 'DESC'): PatchedQueryPromise<ResultType, ShapeType>;
147
- one(): PatchedQueryPromise<SingleResult<ResultType>, ShapeType>;
148
- } & Promise<ResultType>;
149
149
  export type GetCustomObjectKeys<T> = T extends QueryWrapperObject ? {
150
- [P in keyof T]: T[P] extends SelectQueryFactory<any> ? ToQueryResultSet<T[P]> : never;
150
+ [P in keyof T]: T[P] extends FieldSet<any, any> ? ToQueryResultSet<T[P]> : never;
151
151
  } : [];
152
- export type QueryIndividualResultType<T extends SelectQueryFactory<any>> = T extends SelectQueryFactory<infer ShapeType, infer ResponseType> ? QueryResponseToResultType<ResponseType, ShapeType> : null;
153
- export type ToQueryResultSet<T> = T extends SelectQueryFactory<infer ShapeType, infer ResponseType> ? QueryResponseToResultType<ResponseType, ShapeType>[] : null;
152
+ export type ToQueryResultSet<T> = T extends FieldSet<infer ResponseType, any> ? QueryResponseToResultType<ResponseType>[] : null;
154
153
  /**
155
154
  * MAIN ENTRY to convert the response of a query into a result object
156
155
  */
157
- export type QueryResponseToResultType<T, QShapeType extends Shape = null, HasName = false> = T extends QueryBuilderObject ? GetQueryObjectResultType<T, {}, false, HasName> : T extends SelectQueryFactory<any, infer Response, infer Source> ? GetNestedQueryResultType<Response, Source> : T extends Array<infer Type> ? UnionToIntersection<QueryResponseToResultType<Type>> : T extends Evaluation ? boolean : T extends Object ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>> : never;
156
+ export type QueryResponseToResultType<T, QShapeType extends Shape = null, HasName = false> = T extends QueryBuilderObject ? GetQueryObjectResultType<T, {}, false, HasName> : T extends FieldSet<infer Response, infer Source> ? GetNestedQueryResultType<Response, Source> : T extends Array<infer Type> ? UnionToIntersection<QueryResponseToResultType<Type>> : T extends Evaluation ? boolean : T extends Object ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>> : never & {
157
+ __error: 'QueryResponseToResultType: unmatched query response type';
158
+ };
158
159
  /**
159
160
  * Turns a QueryBuilderObject into a plain JS object
160
161
  * @param QV the query value type
161
162
  * @param SubProperties to add extra properties into the result object (used to merge arrays into objects for example)
162
163
  * @param SourceOverwrite if the source of the query value should be overwritten
163
164
  */
164
- export type GetQueryObjectResultType<QV, SubProperties = {}, PrimitiveArray = false, HasName = false> = QV extends SetSize<infer Source> ? SetSizeToQueryResult<Source, HasName> : QV extends QueryPrimitive<infer Primitive, infer Source, infer Property> ? CreateQResult<Source, PrimitiveArray extends true ? Primitive[] : Primitive, Property, {}, HasName> : QV extends QueryShape<infer ShapeType, infer Source, infer Property> ? CreateQResult<Source, ShapeType, Property, SubProperties, HasName> : QV extends BoundComponent<infer Source, infer CompQueryResult> ? GetQueryObjectResultType<Source, SubProperties & QueryResponseToResultType<CompQueryResult>, PrimitiveArray, HasName> : QV extends QueryShapeSet<infer ShapeType, infer Source, infer Property> ? CreateShapeSetQResult<ShapeType, Source, Property, SubProperties, HasName> : QV extends QueryPrimitiveSet<infer QPrim extends QueryPrimitive<any>> ? GetQueryObjectResultType<QPrim, null, null, true> : QV extends Array<infer Type> ? UnionToIntersection<QueryResponseToResultType<Type>> : QV extends QueryBoolean<any, any> ? 'bool' : never;
165
+ export type GetQueryObjectResultType<QV, SubProperties = {}, PrimitiveArray = false, HasName = false> = QV extends SetSize<infer Source> ? SetSizeToQueryResult<Source, HasName> : QV extends QueryPrimitive<infer Primitive, infer Source, infer Property> ? CreateQResult<Source, PrimitiveArray extends true ? Primitive[] : Primitive, Property, {}, HasName> : QV extends QueryShape<infer ShapeType, infer Source, infer Property> ? CreateQResult<Source, ShapeType, Property, SubProperties, HasName> : QV extends BoundComponent<infer Source, infer CompQueryResult> ? GetQueryObjectResultType<Source, SubProperties & QueryResponseToResultType<CompQueryResult>, PrimitiveArray, HasName> : QV extends QueryShapeSet<infer ShapeType, infer Source, infer Property> ? CreateShapeSetQResult<ShapeType, Source, Property, SubProperties, HasName> : QV extends QueryPrimitiveSet<infer QPrim extends QueryPrimitive<any>> ? GetQueryObjectResultType<QPrim, null, null, true> : QV extends Array<infer Type> ? UnionToIntersection<QueryResponseToResultType<Type>> : QV extends QueryPrimitive<boolean, any, any> ? 'bool' : never & {
166
+ __error: 'GetQueryObjectResultType: unmatched query value type';
167
+ };
165
168
  export type GetShapesResultTypeWithSource<Source> = QueryResponseToResultType<Source>;
166
169
  export type SetSizeToQueryResult<Source, HasName = false> = Source extends QueryShapeSet<infer ShapeType, infer ParentSource, infer SourceProperty> ? HasName extends false ? CreateQResult<ParentSource, number, SourceProperty> : number : number;
167
170
  /**
@@ -181,8 +184,10 @@ type NormaliseBoolean<T> = [T] extends [boolean] ? boolean : T;
181
184
  export type CreateShapeSetQResult<ShapeType = undefined, Source = undefined, Property extends string | number | symbol = '', SubProperties = {}, HasName = false> = Source extends QueryShape<infer SourceShapeType, infer ParentSource> ? [
182
185
  HasName,
183
186
  ParentSource
184
- ] extends [true, null] ? CreateQResult<Source, null, null>[] : QResult<SourceShapeType, {
187
+ ] extends [true, null] ? CreateQResult<Source, null, null>[] : ParentSource extends null ? QResult<SourceShapeType, {
185
188
  [P in Property]: CreateQResult<Source, null, null, SubProperties>[];
189
+ }> : CreateQResult<Source, null, null, {
190
+ [P in Property]: (ShapeType extends Shape ? QResult<ShapeType, SubProperties> : QResult<Shape, SubProperties>)[];
186
191
  }> : Source extends QueryShapeSet<infer ShapeType, infer ParentSource, infer SourceProperty> ? CreateQResult<ParentSource, QResult<ShapeType, {
187
192
  [P in Property]: CreateQResult<ShapeType>[];
188
193
  }>[], SourceProperty, {}, HasName> : CreateQResult<ShapeType>;
@@ -195,9 +200,7 @@ export type ObjectToPlainResult<T> = {
195
200
  export type GetSource<Source, Overwrite> = Overwrite extends null ? Source : Overwrite;
196
201
  type GetNestedQueryResultType<Response, Source> = Source extends QueryBuilderObject ? GetQueryObjectResultType<Source, QueryResponseToResultType<Response>> : QueryResponseToResultType<Response>[];
197
202
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
198
- export type GetQueryResponseType<Q> = Q extends SelectQueryFactory<any, infer ResponseType> ? ResponseType : Q;
199
- export type GetQueryShapeType<Q> = Q extends SelectQueryFactory<infer ShapeType, infer ResponseType> ? ShapeType : never;
200
- export type QueryResponseToEndValues<T> = T extends SetSize ? number[] : T extends SelectQueryFactory<any, infer Response> ? QueryResponseToEndValues<Response>[] : T extends QueryShapeSet<infer ShapeType> ? ShapeSet<ShapeType> : T extends QueryShape<infer ShapeType> ? ShapeType : T extends QueryString ? string[] : T extends Array<infer ArrType> ? Array<QueryResponseToEndValues<ArrType>> : T extends Evaluation ? boolean[] : T;
203
+ export type GetQueryResponseType<Q> = Q extends FieldSet<infer ResponseType, any> ? ResponseType : Q;
201
204
  /**
202
205
  * ###################################
203
206
  * #### QUERY BUILDING CLASSES ####
@@ -223,7 +226,7 @@ export declare class QueryBuilderObject<OriginalValue = any, Source = any, Prope
223
226
  static generatePathValue(property: PropertyShape, subject: QueryShape<any> | QueryShapeSet<any> | QueryShape<any>): QueryBuilderObject;
224
227
  static getOriginalSource(endValue: ShapeSet<Shape> | Shape[] | QueryPrimitiveSet): ShapeSet;
225
228
  static getOriginalSource(endValue: Shape): Shape;
226
- static getOriginalSource(endValue: QueryString): Shape | string;
229
+ static getOriginalSource(endValue: QueryPrimitive<any>): Shape | string;
227
230
  static getOriginalSource(endValue: string[] | QueryBuilderObject): Shape | ShapeSet;
228
231
  getOriginalValue(): OriginalValue;
229
232
  getPropertyStep(): QueryStep;
@@ -238,9 +241,13 @@ export declare class BoundComponent<Source extends QueryBuilderObject, CompQuery
238
241
  originalValue: QueryComponentLike<any, CompQueryResult>;
239
242
  source: Source;
240
243
  constructor(originalValue: QueryComponentLike<any, CompQueryResult>, source: Source);
241
- getParentQueryFactory(): SelectQueryFactory<any>;
242
- getPropertyPath(): QueryPropertyPath;
243
244
  }
245
+ export declare const processWhereClause: (validation: WhereClause<any>, shape?: any) => WherePath;
246
+ /**
247
+ * Evaluate a sort callback through the proxy and extract a SortByPath.
248
+ * This is a standalone helper that replaces the need for the former SelectQueryFactory.sortBy().
249
+ */
250
+ export declare const evaluateSortCallback: <S extends Shape>(shape: ShapeConstructor<S>, sortFn: (p: any) => any, direction?: "ASC" | "DESC") => SortByPath;
244
251
  export declare class QueryShapeSet<S extends Shape = Shape, Source = any, Property extends string | number | symbol = any> extends QueryBuilderObject<ShapeSet<S>, Source, Property> {
245
252
  queryShapes: CoreSet<QueryShape>;
246
253
  private proxy;
@@ -256,8 +263,8 @@ export declare class QueryShapeSet<S extends Shape = Shape, Source = any, Proper
256
263
  callPropertyShapeAccessor(propertyShape: PropertyShape): QueryShapeSet | QueryPrimitiveSet;
257
264
  size(): SetSize<this>;
258
265
  where(validation: WhereClause<S>): this;
259
- select<QF = unknown>(subQueryFn: QueryBuildFn<S, QF>): SelectQueryFactory<S, QF, QueryShapeSet<S, Source, Property>>;
260
- selectAll(): SelectQueryFactory<S, SelectAllQueryResponse<S>, QueryShapeSet<S, Source, Property>>;
266
+ select<QF = unknown>(subQueryFn: QueryBuildFn<S, QF>): FieldSet<QF, QueryShapeSet<S, Source, Property>>;
267
+ selectAll(): FieldSet<SelectAllQueryResponse<S>, QueryShapeSet<S, Source, Property>>;
261
268
  some(validation: WhereClause<S>): SetEvaluation;
262
269
  every(validation: WhereClause<S>): SetEvaluation;
263
270
  private someOrEvery;
@@ -272,8 +279,8 @@ export declare class QueryShape<S extends Shape = Shape, Source = any, Property
272
279
  private static proxifyQueryShape;
273
280
  as<ShapeClass extends typeof Shape>(shape: ShapeClass): QShape<InstanceType<ShapeClass>, Source, Property>;
274
281
  equals(otherValue: NodeReferenceValue | QShape<any>): Evaluation;
275
- select<QF = unknown>(subQueryFn: QueryBuildFn<S, QF>): SelectQueryFactory<S, QF, QueryShape<S, Source, Property>>;
276
- selectAll(): SelectQueryFactory<S, SelectAllQueryResponse<S>, QueryShape<S, Source, Property>>;
282
+ select<QF = unknown>(subQueryFn: QueryBuildFn<S, QF>): FieldSet<QF, QueryShape<S, Source, Property>>;
283
+ selectAll(): FieldSet<SelectAllQueryResponse<S>, QueryShape<S, Source, Property>>;
277
284
  }
278
285
  export declare class Evaluation {
279
286
  value: QueryBuilderObject | QueryPrimitiveSet;
@@ -290,10 +297,13 @@ export declare class Evaluation {
290
297
  declare class SetEvaluation extends Evaluation {
291
298
  }
292
299
  /**
293
- * The class that is used for when JS primitives are converted to a QueryValue
294
- * This is extended by QueryString, QueryNumber, QueryBoolean, etc
300
+ * Concrete query wrapper for JS primitive values (string, number, boolean, Date).
301
+ *
302
+ * Replaces the former abstract class + subclasses (QueryString, QueryNumber,
303
+ * QueryBoolean, QueryDate) — the type parameter T carries the primitive type,
304
+ * so separate subclasses are unnecessary.
295
305
  */
296
- export declare abstract class QueryPrimitive<T, Source = any, Property extends string | number | symbol = any> extends QueryBuilderObject<T, Source, Property> {
306
+ export declare class QueryPrimitive<T, Source = any, Property extends string | number | symbol = any> extends QueryBuilderObject<T, Source, Property> {
297
307
  originalValue?: T;
298
308
  property?: PropertyShape;
299
309
  subject?: QueryShape<any> | QueryShapeSet<any> | QueryPrimitiveSet;
@@ -301,14 +311,6 @@ export declare abstract class QueryPrimitive<T, Source = any, Property extends s
301
311
  equals(otherValue: JSPrimitive | QueryBuilderObject): Evaluation;
302
312
  where(validation: WhereClause<string>): this;
303
313
  }
304
- export declare class QueryString<Source = any, Property extends string | number | symbol = ''> extends QueryPrimitive<string, Source, Property> {
305
- }
306
- export declare class QueryDate<Source = any, Property extends string | number | symbol = any> extends QueryPrimitive<Date, Source, Property> {
307
- }
308
- export declare class QueryNumber<Source = any, Property extends string | number | symbol = any> extends QueryPrimitive<number, Source, Property> {
309
- }
310
- export declare class QueryBoolean<Source = any, Property extends string | number | symbol = any> extends QueryPrimitive<boolean, Source, Property> {
311
- }
312
314
  export declare class QueryPrimitiveSet<QPrimitive extends QueryPrimitive<any> = null> extends QueryBuilderObject<any, any, any> {
313
315
  originalValue?: JSNonNullPrimitive[];
314
316
  property?: PropertyShape;
@@ -323,75 +325,7 @@ export declare class QueryPrimitiveSet<QPrimitive extends QueryPrimitive<any> =
323
325
  getPropertyPath(): QueryPropertyPath;
324
326
  size(): SetSize<this>;
325
327
  }
326
- export declare var onQueriesReady: (callback: any) => void;
327
- export declare class SelectQueryFactory<S extends Shape, ResponseType = any, Source = any> extends QueryFactory {
328
- shape: ShapeType<S>;
329
- private queryBuildFn?;
330
- subject?: S | ShapeSet<S> | QResult<S>;
331
- /**
332
- * The returned value when the query was initially run.
333
- * Will likely be an array or object or query values that can be used to trace back which methods/accessors were used in the query.
334
- * @private
335
- */
336
- traceResponse: ResponseType;
337
- sortResponse: any;
338
- sortDirection: string;
339
- parentQueryPath: QueryPath;
340
- singleResult: boolean;
341
- private limit;
342
- private offset;
343
- private wherePath;
344
- private initPromise;
345
- debugStack: string;
346
- constructor(shape: ShapeType<S>, queryBuildFn?: QueryBuildFn<S, ResponseType>, subject?: S | ShapeSet<S> | QResult<S>);
347
- setLimit(limit: number): void;
348
- getLimit(): number;
349
- setOffset(offset: number): void;
350
- getOffset(): number;
351
- setSubject(subject: any): this;
352
- where(validation: WhereClause<S>): this;
353
- exec(): Promise<QueryResponseToResultType<ResponseType>[]>;
354
- /**
355
- * Returns the raw pipeline input for this query.
356
- * Used internally by build() and by test helpers that need
357
- * to feed factory state into individual pipeline stages.
358
- */
359
- toRawInput(): RawSelectInput;
360
- build(): SelectQuery;
361
- getSubject(): {
362
- id: string;
363
- } | S | ShapeSet<S>;
364
- /**
365
- * Returns an array of query paths
366
- * A single query can request multiple things in multiple "query paths" (For example this is using 2 paths: Shape.select(p => [p.name, p.friends.name]))
367
- * Each query path is returned as array of the property paths requested, with potential where clauses (together called a QueryStep)
368
- */
369
- getQueryPaths(response?: ResponseType): CustomQueryObject | QueryPath[];
370
- isValidSetResult(qResults: QResult<any>[]): boolean;
371
- isValidResult(qResult: QResult<any>): boolean;
372
- clone(): SelectQueryFactory<S, ResponseType, any>;
373
- /**
374
- * Makes a clone of the query template, sets the subject and executes the query
375
- * @param subject
376
- */
377
- execFor(subject: any): Promise<QueryResponseToResultType<ResponseType, null, false>[]>;
378
- patchResultPromise<ResultType>(p: Promise<ResultType>): PatchedQueryPromise<any, S>;
379
- sortBy<R>(sortFn: QueryBuildFn<S, R>, direction: any): this;
380
- private init;
381
- private initialized;
382
- /**
383
- * Returns the dummy shape instance who's properties can be accessed freely inside a queryBuildFn
384
- * It is used to trace the properties that are accessed in the queryBuildFn
385
- * @private
386
- */
387
- private getQueryShape;
388
- private getSortByPath;
389
- private isValidQueryPathsResult;
390
- private isValidQueryPathResult;
391
- private isValidQueryStepResult;
392
- private isValidCustomObjectResult;
393
- }
394
- export declare class SetSize<Source = null> extends QueryNumber<Source> {
328
+ export declare class SetSize<Source = null> extends QueryPrimitive<number, Source> {
395
329
  subject: QueryShapeSet | QueryShape | QueryPrimitiveSet;
396
330
  countable?: QueryBuilderObject;
397
331
  label?: string;
@@ -399,12 +333,4 @@ export declare class SetSize<Source = null> extends QueryNumber<Source> {
399
333
  as(label: string): this;
400
334
  getPropertyPath(): QueryPropertyPath;
401
335
  }
402
- /**
403
- * A sub query that is used to filter results
404
- * i.e p.friends.where(f => //LinkedWhereQuery here)
405
- */
406
- export declare class LinkedWhereQuery<S extends Shape, ResponseType = any> extends SelectQueryFactory<S, ResponseType> {
407
- getResponse(): Evaluation;
408
- getWherePath(): WherePath;
409
- }
410
336
  export {};