@_linked/core 2.27.0 → 2.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.28.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#315](https://github.com/linked-fw/core/pull/315) [`cbd3045`](https://github.com/linked-fw/core/commit/cbd3045d0d0ce9c80368e20e7c423d1f2d24b506) Thanks [@flyon](https://github.com/flyon)! - The `build` script is now `linked build`, the same build CI and the release workflow already run, so a local build produces the published `lib/`. `@_linked/cli` is added as a dev dependency to provide it, and the `rimraf` dev dependency is removed.
8
+
9
+ ## 2.28.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#257](https://github.com/linked-fw/core/pull/257) [`0995b96`](https://github.com/linked-fw/core/commit/0995b961ee52d9432ab6f378f14d11963d398fff) Thanks [@abdipramana](https://github.com/abdipramana)! - Add `SaveFileOptions.preservePath` for generated release artifacts whose object keys must remain identical to their manifest paths. File-store implementations should store safe keys verbatim and reject absolute or traversal paths instead of silently sanitising them.
14
+
15
+ ## 2.27.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#298](https://github.com/linked-fw/core/pull/298) [`a379b4c`](https://github.com/linked-fw/core/commit/a379b4ca5d1c9e3aeacb089b300986428673aeb5) Thanks [@flyon](https://github.com/flyon)! - The published `.d.ts` now type-checks in a `strict` consumer. `SelectQuery.d.ts` passed `null` as a type argument to parameters constrained to `string | number | symbol`, `Shape` and `QueryPrimitive`, which is only legal without `strictNullChecks`. TypeScript 6+ makes `strict` the default, so every consumer without `skipLibCheck` failed with eight TS2344 errors inside core. The `null` sentinels in key positions are now `never` (identical in non-strict mode: a mapped type over either is `{}`), `QueryResponseToResultType`'s unused shape parameter defaults to `Shape`, and `QueryPrimitiveSet` admits `null` in its constraint. Adds `npm run check:dts`, which checks the built declarations under `strict` with `skipLibCheck: false`.
20
+
3
21
  ## 2.27.0
4
22
 
5
23
  ### Minor Changes
package/README.md CHANGED
@@ -419,6 +419,7 @@ await store.saveFile('/app.js', bytes, {
419
419
  mimeType: 'application/javascript',
420
420
  cacheControl: 'public, max-age=31536000, immutable',
421
421
  metadata: {release: '1.2.3'},
422
+ preservePath: true, // keep a generated release key exactly as supplied
422
423
  preventDuplicates: true, // rename instead of overwriting when the path is taken
423
424
  });
424
425
 
@@ -428,6 +429,11 @@ await store.saveFile('/photo.webp', bytes, 'image/webp', true);
428
429
 
429
430
  `options.preventDuplicates` wins over the positional fourth argument. Implementations should start with `normalizeSaveFileOptions(options, preventDuplicates)`, which collapses both forms into one object.
430
431
 
432
+ Set `preservePath: true` only for generated object keys whose paths are already part of an external contract, such as
433
+ a release manifest. A store must either keep that key verbatim or reject it; it must not silently sanitise or rename
434
+ the key. Filesystem-backed stores must reject absolute and traversal paths before writing. Ordinary user uploads should
435
+ leave this option unset and retain the store's normal filename hygiene.
436
+
431
437
  > **There is no core-wide `preventDuplicates` default.** When a caller does not specify one it stays `undefined` all the way to the store, and **each store applies its own**: `LocalFileStore` adds a random suffix, `S3FileStore` overwrites. Pass it explicitly whenever the behaviour matters — never assume a default.
432
438
 
433
439
  ### Optional `statFile`
@@ -12,6 +12,12 @@ export interface SaveFileOptions {
12
12
  cacheControl?: string;
13
13
  /** Store-level user metadata, when the backing store supports it. */
14
14
  metadata?: Record<string, string>;
15
+ /**
16
+ * Store the supplied object key verbatim. Intended for generated release
17
+ * artifacts whose URLs already contain that exact key; stores must reject
18
+ * absolute or traversal paths instead of sanitising them.
19
+ */
20
+ preservePath?: boolean;
15
21
  /**
16
22
  * Rename instead of overwriting when the path is already taken.
17
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"IFileStore.js","sourceRoot":"","sources":["../../../src/interfaces/IFileStore.ts"],"names":[],"mappings":"AA4EA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAkC,EAClC,iBAA2B;;IAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAC,CAAC;IAChD,CAAC;IACD,uCACK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,KAClB,iBAAiB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,iBAAiB,IAClE;AACJ,CAAC","sourcesContent":["import type {Readable} from 'stream';\n\n/**\n * Options for `IFileStore.saveFile`.\n *\n * Passed as the third argument. A plain `string` is still accepted there and is\n * read as the old positional `mimeType`, so existing callers keep working.\n */\nexport interface SaveFileOptions {\n /** Content type of the stored bytes, e.g. `image/webp`. */\n mimeType?: string;\n /** Cache header the store should attach, e.g. `public, max-age=31536000, immutable`. */\n cacheControl?: string;\n /** Store-level user metadata, when the backing store supports it. */\n metadata?: Record<string, string>;\n /**\n * Rename instead of overwriting when the path is already taken.\n *\n * Left `undefined` when the caller did not say: each store then applies its\n * own default (`S3FileStore` overwrites, `LocalFileStore` adds a suffix).\n */\n preventDuplicates?: boolean;\n}\n\n/**\n * Metadata of a stored file, for verify-after-upload.\n *\n * `sha256` is only set when the store can actually report a content hash; a\n * caller that does not get one must treat the file as \"cannot verify\" rather\n * than falling back to `etag`, which is not a content hash on S3.\n */\nexport interface FileStat {\n size: number;\n /** Only when the store can report it. */\n sha256?: string;\n etag?: string;\n}\n\nexport interface IFileStore {\n /**\n * The base URL to access the filestore's files. For example:\n * - http://localhost:4000\n * - https://s3.amazonaws.com/my-bucket\n * - https://my-bucket.nyc3.digitaloceanspaces.com\n */\n readonly accessURL: string;\n\n init?(): Promise<any>;\n\n deleteFile(filePath: string): Promise<void>;\n\n fileExists(filePath: string): Promise<boolean>;\n\n getFile(filePath: string): Promise<Buffer | null>;\n\n listFiles(prefix?: string): Promise<string[]>;\n\n saveFile(\n filePath: string,\n fileContent: string | Uint8Array | Buffer | Readable,\n /** `SaveFileOptions`, or a `string` read as the old positional `mimeType`. */\n options?: SaveFileOptions | string,\n /** Only honoured when `options` is a string; otherwise use `options.preventDuplicates`. */\n preventDuplicates?: boolean,\n ): Promise<string | null>;\n\n /**\n * Optional. Metadata of a stored file, for verify-after-upload.\n * Resolves to `null` when the file does not exist.\n *\n * Optional by design (plan 011 D7): a store without it still publishes, and\n * the caller simply skips verification.\n */\n statFile?(filePath: string): Promise<FileStat | null>;\n}\n\n/**\n * Normalise `saveFile`'s widened third argument into a single options object.\n * Every `IFileStore` implementation should call this first, so the positional\n * mime-type form and the options form cannot drift apart.\n *\n * `preventDuplicates` stays `undefined` when neither `options.preventDuplicates`\n * nor the positional argument was given: \"unspecified\" travels end to end and\n * **each store applies its own default** (`S3FileStore` overwrites,\n * `LocalFileStore` adds a random suffix). This helper must never invent `false`,\n * or a two-argument `saveFile(path, bytes)` would silently start overwriting.\n *\n * `options.preventDuplicates` wins over the positional argument when both are\n * given.\n */\nexport function normalizeSaveFileOptions(\n options?: SaveFileOptions | string,\n preventDuplicates?: boolean,\n): SaveFileOptions & {preventDuplicates?: boolean | undefined} {\n if (typeof options === 'string') {\n return {mimeType: options, preventDuplicates};\n }\n return {\n ...(options ?? {}),\n preventDuplicates: options?.preventDuplicates ?? preventDuplicates,\n };\n}\n"]}
1
+ {"version":3,"file":"IFileStore.js","sourceRoot":"","sources":["../../../src/interfaces/IFileStore.ts"],"names":[],"mappings":"AAkFA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAkC,EAClC,iBAA2B;;IAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAC,CAAC;IAChD,CAAC;IACD,uCACK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,KAClB,iBAAiB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,iBAAiB,IAClE;AACJ,CAAC","sourcesContent":["import type {Readable} from 'stream';\n\n/**\n * Options for `IFileStore.saveFile`.\n *\n * Passed as the third argument. A plain `string` is still accepted there and is\n * read as the old positional `mimeType`, so existing callers keep working.\n */\nexport interface SaveFileOptions {\n /** Content type of the stored bytes, e.g. `image/webp`. */\n mimeType?: string;\n /** Cache header the store should attach, e.g. `public, max-age=31536000, immutable`. */\n cacheControl?: string;\n /** Store-level user metadata, when the backing store supports it. */\n metadata?: Record<string, string>;\n /**\n * Store the supplied object key verbatim. Intended for generated release\n * artifacts whose URLs already contain that exact key; stores must reject\n * absolute or traversal paths instead of sanitising them.\n */\n preservePath?: boolean;\n /**\n * Rename instead of overwriting when the path is already taken.\n *\n * Left `undefined` when the caller did not say: each store then applies its\n * own default (`S3FileStore` overwrites, `LocalFileStore` adds a suffix).\n */\n preventDuplicates?: boolean;\n}\n\n/**\n * Metadata of a stored file, for verify-after-upload.\n *\n * `sha256` is only set when the store can actually report a content hash; a\n * caller that does not get one must treat the file as \"cannot verify\" rather\n * than falling back to `etag`, which is not a content hash on S3.\n */\nexport interface FileStat {\n size: number;\n /** Only when the store can report it. */\n sha256?: string;\n etag?: string;\n}\n\nexport interface IFileStore {\n /**\n * The base URL to access the filestore's files. For example:\n * - http://localhost:4000\n * - https://s3.amazonaws.com/my-bucket\n * - https://my-bucket.nyc3.digitaloceanspaces.com\n */\n readonly accessURL: string;\n\n init?(): Promise<any>;\n\n deleteFile(filePath: string): Promise<void>;\n\n fileExists(filePath: string): Promise<boolean>;\n\n getFile(filePath: string): Promise<Buffer | null>;\n\n listFiles(prefix?: string): Promise<string[]>;\n\n saveFile(\n filePath: string,\n fileContent: string | Uint8Array | Buffer | Readable,\n /** `SaveFileOptions`, or a `string` read as the old positional `mimeType`. */\n options?: SaveFileOptions | string,\n /** Only honoured when `options` is a string; otherwise use `options.preventDuplicates`. */\n preventDuplicates?: boolean,\n ): Promise<string | null>;\n\n /**\n * Optional. Metadata of a stored file, for verify-after-upload.\n * Resolves to `null` when the file does not exist.\n *\n * Optional by design (plan 011 D7): a store without it still publishes, and\n * the caller simply skips verification.\n */\n statFile?(filePath: string): Promise<FileStat | null>;\n}\n\n/**\n * Normalise `saveFile`'s widened third argument into a single options object.\n * Every `IFileStore` implementation should call this first, so the positional\n * mime-type form and the options form cannot drift apart.\n *\n * `preventDuplicates` stays `undefined` when neither `options.preventDuplicates`\n * nor the positional argument was given: \"unspecified\" travels end to end and\n * **each store applies its own default** (`S3FileStore` overwrites,\n * `LocalFileStore` adds a random suffix). This helper must never invent `false`,\n * or a two-argument `saveFile(path, bytes)` would silently start overwriting.\n *\n * `options.preventDuplicates` wins over the positional argument when both are\n * given.\n */\nexport function normalizeSaveFileOptions(\n options?: SaveFileOptions | string,\n preventDuplicates?: boolean,\n): SaveFileOptions & {preventDuplicates?: boolean | undefined} {\n if (typeof options === 'string') {\n return {mimeType: options, preventDuplicates};\n }\n return {\n ...(options ?? {}),\n preventDuplicates: options?.preventDuplicates ?? preventDuplicates,\n };\n}\n"]}
@@ -89,7 +89,7 @@ export type QueryShapeSetProps<SourceShapeSet, Shape> = {
89
89
  /**
90
90
  * ShapeSets are converted to QueryShapeSets, but also inherit all the properties of the shape that each item in the set has (with converted result types)
91
91
  */
92
- export type QShapeSet<ShapeSetType extends Shape, Source = null, Property extends string | number | symbol = null> = QueryShapeSet<ShapeSetType, Source, Property> & QueryShapeSetProps<QueryShapeSet<ShapeSetType, Source, Property>, ShapeSetType>;
92
+ export type QShapeSet<ShapeSetType extends Shape, Source = null, Property extends string | number | symbol = never> = QueryShapeSet<ShapeSetType, Source, Property> & QueryShapeSetProps<QueryShapeSet<ShapeSetType, Source, Property>, ShapeSetType>;
93
93
  /**
94
94
  * Shapes are converted to QueryShapes, but also inherit all the properties of the shape (with converted result types)
95
95
  */
@@ -137,7 +137,7 @@ export type QResult<ShapeType extends Shape = Shape, Object = {}> = Object & {
137
137
  /**
138
138
  * MAIN ENTRY to convert the response of a query into a result object
139
139
  */
140
- 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 ExpressionNode ? boolean : T extends Object ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>> : never & {
140
+ export type QueryResponseToResultType<T, QShapeType extends Shape = Shape, 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 ExpressionNode ? boolean : T extends Object ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>> : never & {
141
141
  __error: 'QueryResponseToResultType: unmatched query response type';
142
142
  };
143
143
  /**
@@ -161,15 +161,15 @@ export type CreateQResult<Source, Value = undefined, Property extends string | n
161
161
  }> : CreateQResult<ParentSource, QResult<SourceShapeType, {
162
162
  [P in Property]: CreateQResult<Value, Value>;
163
163
  } & SubProperties>, SourceProperty, {}, HasName> : Source extends QueryShapeSet<infer ShapeType, infer ParentSource, infer SourceProperty> ? CreateQResult<ParentSource, QResult<ShapeType, {
164
- [P in Property]: CreateQResult<Value, Value, null, SubProperties>;
164
+ [P in Property]: CreateQResult<Value, Value, never, SubProperties>;
165
165
  }>[], SourceProperty, {}, HasName> : Value extends Shape ? QResult<Value, SubProperties> : NormaliseBoolean<Value>;
166
166
  type NormaliseBoolean<T> = [T] extends [boolean] ? boolean : T;
167
167
  export type CreateShapeSetQResult<ShapeType = undefined, Source = undefined, Property extends string | number | symbol = '', SubProperties = {}, HasName = false> = Source extends QueryShape<infer SourceShapeType, infer ParentSource> ? [
168
168
  HasName,
169
169
  ParentSource
170
- ] extends [true, null] ? CreateQResult<Source, null, null>[] : ParentSource extends null ? QResult<SourceShapeType, {
171
- [P in Property]: CreateQResult<Source, null, null, SubProperties>[];
172
- }> : CreateQResult<Source, null, null, {
170
+ ] extends [true, null] ? CreateQResult<Source, null, never>[] : ParentSource extends null ? QResult<SourceShapeType, {
171
+ [P in Property]: CreateQResult<Source, null, never, SubProperties>[];
172
+ }> : CreateQResult<Source, null, never, {
173
173
  [P in Property]: (ShapeType extends Shape ? QResult<ShapeType, SubProperties> : QResult<Shape, SubProperties>)[];
174
174
  }> : Source extends QueryShapeSet<infer ShapeType, infer ParentSource, infer SourceProperty> ? CreateQResult<ParentSource, QResult<ShapeType, {
175
175
  [P in Property]: CreateQResult<ShapeType>[];
@@ -178,7 +178,7 @@ export type CreateShapeSetQResult<ShapeType = undefined, Source = undefined, Pro
178
178
  * Ignores the source and property, and returns the converted value
179
179
  */
180
180
  export type ObjectToPlainResult<T> = {
181
- [P in keyof T]: QueryResponseToResultType<T[P], null, true>;
181
+ [P in keyof T]: QueryResponseToResultType<T[P], Shape, true>;
182
182
  };
183
183
  type GetNestedQueryResultType<Response, Source> = Source extends QueryBuilderObject ? GetQueryObjectResultType<Source, QueryResponseToResultType<Response>> : QueryResponseToResultType<Response>[];
184
184
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
@@ -276,7 +276,7 @@ export declare class QueryPrimitive<T, Source = any, Property extends string | n
276
276
  notOneOf(values: ComparisonValue[]): ExpressionNode;
277
277
  where(validation: WhereClause<string>): this;
278
278
  }
279
- export declare class QueryPrimitiveSet<QPrimitive extends QueryPrimitive<any> = null> extends QueryBuilderObject<any, any, any> {
279
+ export declare class QueryPrimitiveSet<QPrimitive extends QueryPrimitive<any> | null = null> extends QueryBuilderObject<any, any, any> {
280
280
  originalValue?: JSNonNullPrimitive[];
281
281
  property?: PropertyShapeData;
282
282
  subject?: QueryShapeSet<any> | QueryShape<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../../src/queries/SelectQuery.ts"],"names":[],"mappings":"A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import {getPropertyShapes, getUniquePropertyShapes, nodeShapeEquals} from '../shapes/nodeShapeData.js';\nimport type {NodeShapeData, PropertyShapeData} from '../shapes/SHACL.js';\nimport type {RawSelectInput} from './IRDesugar.js';\nimport {ShapeSet} from '../collections/ShapeSet.js';\nimport {shacl} from '../ontologies/shacl.js';\nimport {CoreSet} from '../collections/CoreSet.js';\nimport {getPropertyShapeByLabel, getShapeClass, resolveShapeConstructor} from '../utils/ShapeClass.js';\n\nimport {NodeReferenceValue,type Prettify,type ShapeReferenceValue} from './QueryFactory.js';\nimport {xsd} from '../ontologies/xsd.js';\nimport type {IRSelectQuery} from './IntermediateRepresentation.js';\nimport {createProxiedPathBuilder} from './ProxiedPathBuilder.js';\nimport {FieldSet} from './FieldSet.js';\nimport {PropertyPath} from './PropertyPath.js';\nimport type {QueryBuilder, QueryBuilderJSON} from './QueryBuilder.js';\nimport {ExpressionNode, ExistsCondition, isExpressionNode, isExistsCondition, tracedPropertyExpression, tracedAliasExpression} from '../expressions/ExpressionNode.js';\nimport {PendingQueryContext} from './QueryContext.js';\n\n/**\n * String keys the query-shape proxy must let through *without* treating them as\n * a property access — promise-awaiting (`then`), React (`$$typeof`), and common\n * serializer/object-protocol probes. Everything else that isn't a decorated\n * property is a genuine misuse and throws. (Symbol keys always pass through.)\n */\nconst INTEROP_PASSTHROUGH_KEYS = new Set<string>([\n 'then',\n '$$typeof',\n 'toJSON',\n 'toString',\n 'valueOf',\n 'constructor',\n 'asymmetricMatch', // jest matchers probe this\n 'nodeType', // some DOM/serializer probes\n]);\n\n/**\n * The closed, read-only select query a dataset receives (implemented by\n * `SelectBuilder`). It exposes the wire form (`toJSON`), the routing key\n * (`shape`), and the read-only lowering hook (`toRawInput`) — but none of the\n * fluent mutators, so a store cannot keep building on it. The IR algebra is\n * `IRSelectQuery`, produced on demand by `lower(query)`.\n */\nexport interface SelectQuery {\n readonly __queryKind: 'select';\n readonly shape: NodeShapeData;\n toJSON(): QueryBuilderJSON;\n toRawInput(): RawSelectInput;\n}\n\n/**\n * ###################################\n * #### TYPES FOR QUERY BUILDING ####\n * ###################################\n */\nexport type JSPrimitive = JSNonNullPrimitive | null | undefined;\nexport type JSNonNullPrimitive = string | number | boolean | Date;\n\n/**\n * What a comparison on a primitive-valued query property accepts.\n *\n * `NodeReferenceValue` belongs here because an object property may be DECLARED\n * with a primitive accessor type — `@objectProperty({path: …}) get project():\n * string` returns the referenced node's IRI — which projects to a\n * `QueryPrimitive<string>`, not a `QueryShape`. The documented way to match such\n * a property is still by reference (`.equals({id})`), and the lowering has always\n * supported it: `toIRExpression` turns `{id}` into a `reference_expr`, so the\n * comparison renders as `<iri>` rather than a string literal.\n */\nexport type ComparisonValue =\n | JSPrimitive\n | QueryBuilderObject\n | NodeReferenceValue;\n\nconst isSameRef = (\n a?: NodeReferenceValue,\n b?: NodeReferenceValue,\n): boolean => !!a && !!b && a.id === b.id;\n\nexport type SingleResult<ResultType> =\n ResultType extends Array<infer R>\n ? R\n : ResultType extends Set<infer R>\n ? R\n : ResultType;\n\n/**\n * All the possible types that a regular get/set method of a Shape can return\n */\nexport type AccessorReturnValue =\n | Shape\n | ShapeSet\n | JSPrimitive\n | NodeReferenceValue;\n\nexport type WhereClause<S extends Shape | AccessorReturnValue> =\n | ExpressionNode\n | ExistsCondition\n | ((s: ToQueryBuilderObject<S>) => ExpressionNode | ExistsCondition);\n\nexport type QueryBuildFn<T extends Shape, ResponseType> = (\n p: ToQueryBuilderObject<T>,\n) => ResponseType;\n\nexport type SortByPath = {\n paths: PropertyPath[];\n /** Per-path sort direction (parallel to `paths`). */\n directions: ('ASC' | 'DESC')[];\n};\n\n/**\n * A property-only query path, used by where/sort proxy tracing.\n */\nexport type QueryPropertyPath = QueryStep[];\n\n/**\n * A QueryStep is a single step in a query path.\n */\nexport type QueryStep =\n | PropertyQueryStep\n | SizeStep\n | ShapeReferenceValue;\nexport type SizeStep = {\n count: QueryPropertyPath;\n label?: string;\n};\nexport type PropertyQueryStep = {\n property: PropertyShapeData;\n where?: WherePath;\n};\n\n/**\n * Maps all the return types of get/set methods of a Shape and maps their return types to QueryBuilderObjects\n */\nexport type QueryShapeProps<\n T extends Shape,\n Source,\n Property extends string | number | symbol = any,\n> = {\n [P in keyof T]: ToQueryBuilderObject<T[P], QShape<T, Source, Property>, P>;\n};\n\nexport type SelectAllQueryResponse<T extends Shape> = Array<\n QueryShapeProps<T, null, ''>[Exclude<\n Extract<\n {\n [K in keyof T]-?: T[K] extends (...args: any[]) => any ? never : K;\n }[keyof T],\n string\n >,\n Extract<keyof Shape, string>\n >]\n>;\n\n/**\n * This type states that the ShapeSet has access to the same methods as the shape of all the items in the set\n * (this is enabled with the QueryShapeSet.proxifyShapeSet method)\n * Each value of the shape is converted to a QueryBuilderObject\n */\nexport type QueryShapeSetProps<SourceShapeSet, Shape> = {\n [P in keyof Shape]: ToQueryBuilderObject<Shape[P], SourceShapeSet, P>;\n};\n\n/**\n * ShapeSets are converted to QueryShapeSets, but also inherit all the properties of the shape that each item in the set has (with converted result types)\n */\nexport type QShapeSet<\n ShapeSetType extends Shape,\n Source = null,\n Property extends string | number | symbol = null,\n> = QueryShapeSet<ShapeSetType, Source, Property> &\n QueryShapeSetProps<\n QueryShapeSet<ShapeSetType, Source, Property>,\n ShapeSetType\n >;\n\n/**\n * Shapes are converted to QueryShapes, but also inherit all the properties of the shape (with converted result types)\n */\nexport type QShape<\n T extends Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> = QueryShape<T, Source, Property> & QueryShapeProps<T, Source, Property>;\n\nexport type ToQueryBuilderObject<\n T,\n Source = null,\n Property extends string | number | symbol = '',\n> =\n T extends ShapeSet<infer ShapeSetType>\n ? QShapeSet<ShapeSetType, Source, Property>\n : T extends Shape\n ? QShape<T, Source, Property>\n : T extends string | number | Date | boolean\n ? ToQueryPrimitive<T, Source, Property>\n : // : QueryBuilderObject<T,Source,Property>;\n T extends Array<infer AT>\n ? AT extends Date | string | number\n ? QueryPrimitiveSet<ToQueryPrimitive<AT, Source, Property>>\n : AT extends boolean\n ? QueryPrimitive<boolean>\n : AT[]\n : //added support for get/set methods that return NodeReferenceValue, treating them as plain Shapes\n T extends NodeReferenceValue\n ? QShape<Shape, Source, Property>\n : QueryBuilderObject<T, Source, Property>;\n\nexport type ToQueryPrimitive<\n T extends string | number | Date | boolean,\n Source,\n Property extends string | number | symbol = '',\n> = T extends string\n ? QueryPrimitive<string, Source, Property>\n : T extends number\n ? QueryPrimitive<number, Source, Property>\n : T extends Date\n ? QueryPrimitive<Date, Source, Property>\n : T extends boolean\n ? QueryPrimitive<boolean, Source, Property>\n : never & {__error: 'ToQueryPrimitive: no matching primitive type'};\n\nexport type WhereExpressionPath = {\n expressionNode: ExpressionNode;\n};\n\nexport type WhereExistsPath = {\n existsCondition: ExistsCondition;\n};\n\nexport type WherePath = WhereExpressionPath | WhereExistsPath;\n\n/**\n * An argument can be a direct reference to a node, a js primitive (boolean,number), a path to resolve (like from a query context variables)\n * Or a wherePath in the case of some() or every() (e.g. x.where(x.friends.some(f => f.age > 18) -> the argument is a wherePath)\n */\nexport type QueryComponentLike<ShapeType extends Shape, CompQueryResult> = {\n query:\n | QueryBuilder<ShapeType>\n | FieldSet\n | Record<string, QueryBuilder<ShapeType>>;\n fields?: FieldSet;\n};\n\n/**\n * Interface that linked components (e.g. from `@_linked/react`'s `linkedComponent()`)\n * must satisfy to participate in preloadFor.\n *\n * Components expose their data requirements as a QueryBuilder,\n * and optionally a FieldSet for declarative field access.\n */\nexport interface LinkedComponentInterface<S extends Shape = Shape, R = any> {\n /** The component's data query (QueryBuilder template, not executed). */\n query: QueryBuilder<S, any, R>;\n /** The component's field requirements as a FieldSet. */\n fields?: FieldSet;\n}\n\n/**\n * ###################################\n * #### QUERY RESULT TYPES ####\n * ###################################\n */\n\nexport type QResult<ShapeType extends Shape = Shape, Object = {}> = Object & {\n id: string;\n // shape?: ShapeType;\n};\n\n/**\n * MAIN ENTRY to convert the response of a query into a result object\n */\nexport type QueryResponseToResultType<\n T,\n QShapeType extends Shape = null,\n HasName = false,\n> = T extends QueryBuilderObject\n ? GetQueryObjectResultType<T, {}, false, HasName>\n : T extends FieldSet<infer Response, infer Source>\n ? GetNestedQueryResultType<Response, Source>\n : T extends Array<infer Type>\n ? UnionToIntersection<QueryResponseToResultType<Type>>\n : T extends ExpressionNode\n ? boolean\n : T extends Object\n ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>>\n : never & {__error: 'QueryResponseToResultType: unmatched query response type'};\n\n/**\n * Turns a QueryBuilderObject into a plain JS object\n * @param QV the query value type\n * @param SubProperties to add extra properties into the result object (used to merge arrays into objects for example)\n * @param SourceOverwrite if the source of the query value should be overwritten\n */\nexport type GetQueryObjectResultType<\n QV,\n SubProperties = {},\n PrimitiveArray = false,\n HasName = false,\n> =\n //note: count needs to be above primitive\n QV extends SetSize<infer Source>\n ? SetSizeToQueryResult<Source, HasName>\n : QV extends QueryPrimitive<infer Primitive, infer Source, infer Property>\n ? CreateQResult<\n Source,\n PrimitiveArray extends true ? Primitive[] : Primitive,\n Property,\n {},\n HasName\n >\n : QV extends QueryShape<infer ShapeType, infer Source, infer Property>\n ? CreateQResult<Source, ShapeType, Property, SubProperties, HasName>\n : QV extends BoundComponent<infer Source, infer CompQueryResult>\n ? GetQueryObjectResultType<\n Source,\n SubProperties & QueryResponseToResultType<CompQueryResult>,\n PrimitiveArray,\n HasName\n >\n : QV extends QueryShapeSet<\n infer ShapeType,\n infer Source,\n infer Property\n >\n ? CreateShapeSetQResult<\n ShapeType,\n Source,\n Property,\n SubProperties,\n HasName\n >\n : QV extends QueryPrimitiveSet<\n infer QPrim extends QueryPrimitive<any>\n >\n ? GetQueryObjectResultType<QPrim, null, null, true>\n : QV extends Array<infer Type>\n ? UnionToIntersection<QueryResponseToResultType<Type>>\n : QV extends QueryPrimitive<boolean, any, any>\n ? 'bool'\n : never & {__error: 'GetQueryObjectResultType: unmatched query value type'};\n\nexport type SetSizeToQueryResult<Source, HasName = false> =\n Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? HasName extends false\n ? //when we count something and we already know what the name of the variable of the resulting number is, then we return a number\n //But if we count a shapeset and its NOT in a custom object where a key (name) is already known, then we return a QResult\n //This QResult will be the same as it would be if there was no .count() statement. Except now it returns a number (hence we send number as value type)\n CreateQResult<ParentSource, number, SourceProperty>\n : number\n : number;\n\n/**\n * If the source is an object (it extends shape)\n * then the result is a plain JS Object, with Property as its key, with type Value\n */\nexport type CreateQResult<\n Source,\n Value = undefined,\n Property extends string | number | symbol = '',\n SubProperties = {},\n HasName = false,\n> =\n Source extends QueryShape<\n infer SourceShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //if the parent source is null, that means this is the final source-node in the query\n ParentSource extends null\n ? HasName extends true\n ? Value\n : //TODO: this must be simplified and rewritten\n // it is likely the most complex part of the type system currently\n // It turns out that sub-.select() on a QueryShapeSet ends up here with Value being null, and sub properties need to be added to the QResult itself\n // Whilst sub-.select() on a single QueryShape ends up here with Value being defined, in which case the SubProperties need to be included in the inner QResult\n Value extends null\n ? //hence we create a single QResult, but do not use CreateQResult (which will keep creating nested QResults)\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value>;\n } & SubProperties\n >\n : //hence we create a single QResult, but do not use CreateQResult (which will keep creating nested QResults)\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value, '', SubProperties>;\n }\n >\n : CreateQResult<\n ParentSource,\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value>;\n } & SubProperties\n >,\n SourceProperty,\n {},\n HasName\n >\n : Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //for a ShapeSet, we make the current result (a QResult) the value of a parent QResult (created with ToQueryResult)\n CreateQResult<\n ParentSource,\n QResult<\n ShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value, null, SubProperties>;\n }\n >[],\n SourceProperty,\n {},\n HasName\n >\n : //Source is not a QueryShape or QueryShape set (currently sometimes used by end QueryPrimitives) ..\n // this needs to convert to value (amongst other things) for .select({customKeys}) and ObjectToPlainResult\n Value extends Shape\n ? QResult<Value, SubProperties>\n : // : Value extends boolean ? 'boolean' : Value;\n NormaliseBoolean<Value>;\n\ntype NormaliseBoolean<T> = [T] extends [boolean] ? boolean : T;\n\nexport type CreateShapeSetQResult<\n ShapeType = undefined,\n Source = undefined,\n Property extends string | number | symbol = '',\n SubProperties = {},\n HasName = false,\n> =\n Source extends QueryShape<infer SourceShapeType, infer ParentSource>\n ? //if HasName is true and source is a QueryShape, but ITS source (ParentSource) is null\n //then we don't want to create a nested QResult, but instead we ignore this last property and we return an array of QResults of this source\n //This is used by custom object keys with values like: p.friends, which should return an array of QResult<Person> Objects, not a {friends:...} QResult\n //NOTE: this notation check if 2 statements are true: HasName is true, and ParentSource is null\n [HasName, ParentSource] extends [true, null]\n ? CreateQResult<Source, null, null>[]\n : ParentSource extends null\n ? QResult<\n SourceShapeType,\n {[P in Property]: CreateQResult<Source, null, null, SubProperties>[]}\n >\n : //when ParentSource is not null, we need to continue unwinding the source chain\n //Pass the inner ShapeSet items as SubProperties so they stay at the correct nesting level\n CreateQResult<\n Source,\n null,\n null,\n {[P in Property]: (ShapeType extends Shape ? QResult<ShapeType, SubProperties> : QResult<Shape, SubProperties>)[]}\n >\n : Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //for a shapeset source, we make the current result (a QResult) the value of a parent QResult (created with ToQueryResult)\n CreateQResult<\n ParentSource,\n QResult<\n ShapeType,\n {\n [P in Property]: CreateQResult<ShapeType>[];\n }\n >[],\n SourceProperty,\n {},\n HasName\n >\n : CreateQResult<ShapeType>;\n\n/**\n * Ignores the source and property, and returns the converted value\n */\nexport type ObjectToPlainResult<T> = {\n //passing true as sourceOverwrite will mean that the original source is ignored and so the converted value will not be wrapped in a QResult\n // [P in keyof T]: QueryResponseToResultType<T[P], null, true>;\n [P in keyof T]: QueryResponseToResultType<T[P], null, true>;\n};\n\ntype GetNestedQueryResultType<Response, Source> =\n Source extends QueryBuilderObject\n ? //if the linked query originates from within another query (like with select())\n //then we turn the source into a result. And then pass the selected properties as \"SubProperties\"\n //regardless of whether the response type is an array or object, it gets converted into a result value object\n GetQueryObjectResultType<Source, QueryResponseToResultType<Response>>\n : //by default: we just convert the response type into a result value object\n QueryResponseToResultType<Response>[];\n\n//https://stackoverflow.com/a/50375286/977206\ntype UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (\n x: infer I,\n) => void\n ? I\n : never;\n\n\n/**\n * ###################################\n * #### QUERY BUILDING CLASSES ####\n * ###################################\n */\n\nexport class QueryBuilderObject<\n OriginalValue = any,\n Source = any,\n Property extends string | number | symbol = any,\n> {\n //is null by default to avoid warnings when trying to access wherePath when its undefined\n wherePath?: WherePath = null;\n protected originalValue?: OriginalValue;\n protected source: Source;\n protected prop: Property;\n\n constructor(\n public property?: PropertyShapeData,\n public subject?: QueryShape<any> | QueryShapeSet<any> | QueryPrimitiveSet,\n ) {}\n\n /**\n * Create a Query Builder Object based on the requested PropertyShapeData\n */\n static generatePathValue(\n // originalValue: AccessorReturnValue,\n property: PropertyShapeData,\n subject: QueryShape<any> | QueryShapeSet<any> | QueryShape<any>,\n ): QueryBuilderObject {\n let datatype = property.datatype;\n let valueShape = property.valueShape;\n let singleValue = property.maxCount <= 1;\n if (datatype) {\n if (singleValue) {\n if (isSameRef(datatype, xsd.integer)) {\n return wrapWithExpressionProxy(new QueryPrimitive<number>(0, property, subject));\n } else if (isSameRef(datatype, xsd.boolean)) {\n return wrapWithExpressionProxy(new QueryPrimitive<boolean>(false, property, subject));\n } else if (\n isSameRef(datatype, xsd.dateTime) ||\n isSameRef(datatype, xsd.date)\n ) {\n return wrapWithExpressionProxy(new QueryPrimitive<Date>(new Date(), property, subject));\n } else if (isSameRef(datatype, xsd.string)) {\n return wrapWithExpressionProxy(new QueryPrimitive<string>('', property, subject));\n }\n } else {\n //TODO review this, do we need property & subject in both of these? currently yes, but why\n return new QueryPrimitiveSet([''], property, subject, [\n new QueryPrimitive<string>('', property, subject),\n ]);\n }\n }\n if (valueShape) {\n const shapeClass = resolveShapeConstructor(valueShape);\n if(!shapeClass) {\n //TODO: getShapeClassAsync -> which will lazy load the shape class\n // but Im not sure if that's even possible with dynamic import paths, that are only known at runtime\n //UPDATE: we should not need to load shapeclasses. We just need to be able to access shapes.\n // but the problem remains that the ImageObject shape needs to be available, but thats easier, as its data\n throw new Error(`Shape class not found for ${valueShape.id}`);\n }\n const shapeValue = createShapeTarget(shapeClass);\n if (singleValue) {\n return QueryShape.create(shapeValue, property, subject);\n } else {\n return QueryShapeSet.create(\n new ShapeSet([shapeValue]),\n property,\n subject,\n );\n }\n }\n\n //no value shape and no data type.\n //Lets look at the node kind\n if (\n isSameRef(property.nodeKind, shacl.Literal) ||\n isSameRef(property.nodeKind, shacl.BlankNodeOrLiteral)\n ) {\n if (singleValue) {\n //default to string if no datatype is set\n return wrapWithExpressionProxy(new QueryPrimitive<string>('', property, subject));\n } else {\n //TODO review this, do we need property & subject in both of these? currently yes, but why\n return new QueryPrimitiveSet([''], property, subject, [\n new QueryPrimitive<string>('', property, subject),\n ]);\n }\n }\n\n // An object-valued property with no value shape and a non-Literal node kind\n // (e.g. `sh:path` — a raw predicate IRI, or any bare IRI reference). Project\n // it as a generic node reference via the base `Shape`, so the query returns\n // the value's IRI `{id}` — identical to how a *shaped* object property\n // resolves (cf. `sh:targetClass`, registered `shape: Shape`). This lets the\n // DSL read raw IRI predicates back out of a store (SHACL shape catalog etc.).\n //\n // NOTE: a polymorphic value (an `rdf:List` sequence path or a `PathNode`\n // operator) resolves to its *node reference* here, not its structure. Full\n // structural projection (\"if List → members, if PathNode → operands\") is the\n // `byShape` polymorphic-projection follow-up — see\n // packages/core/docs/backlog/031-byshape-polymorphic-projection.md.\n // Build a constructor-less generic node-reference target on the base `Shape`\n // (like the `valueShape` branch above, but for the shapeless base). `Shape`'s\n // constructor throws, so we use `createShapeTarget` (Object.create) — the\n // target is only a proxy metadata carrier, never a live instance.\n const genericShape = createShapeTarget(Shape);\n return singleValue\n ? QueryShape.create(genericShape, property, subject)\n : QueryShapeSet.create(new ShapeSet([genericShape]), property, subject);\n }\n\n getOriginalValue() {\n return this.originalValue;\n }\n\n getPropertyStep(): QueryStep {\n return {\n property: this.property,\n where: this.wherePath,\n };\n }\n\n preloadFor<ShapeType extends Shape, CompQueryRes>(\n component: QueryComponentLike<ShapeType, CompQueryRes>,\n ): BoundComponent<this, CompQueryRes> {\n return new BoundComponent<this, CompQueryRes>(component, this);\n }\n\n /**\n * Pagination is applied to a nested *select*, not to a bare traversal — use\n * `p.friends.select(f => f.name).limit(n)`. Calling `.limit()` directly on a\n * traversal would silently do nothing, so we fail loudly instead.\n * (Top-level result pagination lives on the outer query builder.)\n */\n limit(lim: number): never {\n throw new Error(\n `.limit(${lim}) is not supported directly on a traversal — use ` +\n '.select(...).limit(n) on the nested collection (single-subject queries only).',\n );\n }\n\n /**\n * Returns the path of properties that were requested to reach this value\n */\n getPropertyPath(currentPath?: QueryPropertyPath): QueryPropertyPath {\n let path: QueryPropertyPath = currentPath || [];\n //add the step of this object to the beginning of the path (so that the next parent will always before the current item)\n if (this.property || this.wherePath) {\n path.unshift(this.getPropertyStep());\n }\n if (this.subject) {\n return this.subject.getPropertyPath(path);\n }\n //when query context is used as the first step, then the first step is just a pointer to the subject it represents\n if ((this.originalValue as Shape)?.__queryContextId) {\n path.unshift(convertQueryContext(this as any as QueryShape));\n }\n return path;\n }\n}\n\nexport class BoundComponent<\n Source extends QueryBuilderObject,\n CompQueryResult = any,\n> extends QueryBuilderObject {\n constructor(\n public originalValue: QueryComponentLike<any, CompQueryResult>,\n public source: Source,\n ) {\n super(null, null);\n }\n\n}\n\n/**\n * Converts query context to a ShapeReferenceValue\n */\nconst convertQueryContext = (shape: QueryShape): ShapeReferenceValue => {\n return {\n id: (shape.originalValue as Shape).__queryContextId,\n shape: {\n id: shape.originalValue.nodeShape.id,\n },\n } as ShapeReferenceValue;\n};\n\nexport const processWhereClause = (\n validation: WhereClause<any>,\n shape?,\n): WherePath => {\n if (validation instanceof Function) {\n if (!shape) {\n throw new Error('Cannot process where clause without shape');\n }\n const proxy = createProxiedPathBuilder(shape);\n const result = validation(proxy);\n if (isExpressionNode(result)) {\n return {expressionNode: result};\n }\n if (isExistsCondition(result)) {\n return {existsCondition: result};\n }\n throw new Error('WHERE callback must return ExpressionNode or ExistsCondition');\n } else if (isExpressionNode(validation)) {\n return {expressionNode: validation};\n } else if (isExistsCondition(validation)) {\n return {existsCondition: validation};\n } else {\n throw new Error('WHERE clause must be ExpressionNode, ExistsCondition, or a callback');\n }\n};\n\n// ---------------------------------------------------------------------------\n// Expression method proxy for QueryPrimitive\n// ---------------------------------------------------------------------------\n\nconst EXPRESSION_METHODS = new Set([\n 'plus', 'minus', 'times', 'divide', 'abs', 'round', 'ceil', 'floor', 'power',\n 'equals', 'eq', 'neq', 'notEquals', 'gt', 'greaterThan', 'gte', 'greaterThanOrEqual',\n 'lt', 'lessThan', 'lte', 'lessThanOrEqual', 'oneOf', 'notOneOf',\n 'concat', 'contains', 'startsWith', 'endsWith', 'substr', 'before', 'after',\n 'replace', 'ucase', 'lcase', 'strlen', 'encodeForUri', 'matches',\n 'year', 'month', 'day', 'hours', 'minutes', 'seconds', 'timezone', 'tz',\n 'and', 'or', 'not',\n 'isDefined', 'isNotDefined', 'defaultTo',\n 'lang', 'datatype', 'str', 'iri', 'isIri', 'isLiteral', 'isBlank', 'isNumeric',\n 'md5', 'sha256', 'sha512',\n]);\n\n/**\n * Convert a QueryBuilderObject to a traced ExpressionNode by extracting its\n * property path segments and creating a property expression reference.\n * This is the bridge between the query proxy world and the expression IR world.\n */\nfunction toExpressionNode(qbo: QueryBuilderObject): ExpressionNode {\n // Check if this is a query context reference. We carry the context *name*\n // (not the resolved id): it serializes as `{@ctx}` and is resolved by `lower()`.\n const contextName = findContextName(qbo);\n if (contextName) {\n const segments = FieldSet.collectPropertySegments(qbo);\n if (segments.length > 0) {\n // Context property access (e.g. getQueryContext('user').name) → context_property_expr\n const lastSegment = segments[segments.length - 1].id;\n const ir = {kind: 'context_property_expr' as const, contextName, property: lastSegment};\n return new ExpressionNode(ir);\n }\n // Context root reference (e.g. getQueryContext('user')) → reference_expr\n const ir = {kind: 'reference_expr' as const, contextName};\n return new ExpressionNode(ir);\n }\n\n const segments = FieldSet.collectPropertySegments(qbo);\n if (segments.length === 0) {\n // Root shape or entity reference — produce alias expression (the entity itself)\n return tracedAliasExpression([]);\n }\n const segmentIds = segments.map((s) => s.id);\n return tracedPropertyExpression(segmentIds);\n}\n\n/** Walk up the QueryBuilderObject chain to find a query context *name* (for `{@ctx}`). */\nfunction findContextName(qbo: QueryBuilderObject): string | undefined {\n let current: QueryBuilderObject | undefined = qbo;\n while (current) {\n if (current instanceof QueryShape && (current.originalValue as any)?.__queryContextName) {\n return (current.originalValue as any).__queryContextName;\n }\n current = current.subject as QueryBuilderObject | undefined;\n }\n return undefined;\n}\n\n/**\n * A wrapper for inline `.where()` on primitives that produces alias-based expressions.\n * When `p.hobby.where(h => h.equals('Jogging'))` is called, `h` should reference\n * the hobby variable itself (alias), not traverse to a sub-property.\n */\nclass InlineWhereProxy extends QueryBuilderObject {\n constructor(public readonly source: QueryPrimitive<any>) {\n super(source.property, source.subject);\n }\n\n equals(otherValue: any): ExpressionNode {\n // Empty traversal = \"the current alias\" — resolved by lowering\n // against the property's own alias scope\n const self = tracedAliasExpression([]);\n return self.eq(otherValue);\n }\n}\n\n/**\n * Wrap a QueryPrimitive in a Proxy that intercepts expression method calls.\n * When an expression method (e.g., `.plus()`, `.gt()`, `.equals()`) is accessed,\n * creates a traced ExpressionNode based on the QueryPrimitive's property path.\n */\nfunction wrapWithExpressionProxy<T>(qp: QueryPrimitive<T>): QueryPrimitive<T> {\n return new Proxy(qp, {\n get(target, key, receiver) {\n if (typeof key === 'string' && EXPRESSION_METHODS.has(key)) {\n const segments = FieldSet.collectPropertySegments(target);\n // Only intercept if we have valid property segments to trace\n if (segments.length > 0) {\n // Use toExpressionNode so a context property as the *self* of an\n // expression (e.g. getQueryContext('user').name.equals(x)) becomes a\n // context_property_expr, not a root-entity property_expr.\n const baseNode = toExpressionNode(target as unknown as QueryBuilderObject);\n return (...args: any[]) => {\n // Convert QueryBuilderObject arguments to ExpressionNode\n const convertedArgs = args.map((arg) =>\n arg instanceof QueryBuilderObject ? (toExpressionNode(arg) ?? arg) : arg,\n );\n return (baseNode as any)[key](...convertedArgs);\n };\n }\n }\n return Reflect.get(target, key, receiver);\n },\n }) as QueryPrimitive<T>;\n}\n\n/**\n * Evaluate a sort callback through the proxy and extract a SortByPath.\n * This is a standalone helper that replaces the need for the former SelectQueryFactory.sortBy().\n */\nexport const evaluateSortCallback = <S extends Shape>(\n shape: ShapeConstructor<S>,\n sortFn: (p: any) => any,\n direction: 'ASC' | 'DESC' = 'ASC',\n): SortByPath => {\n const proxy = createProxiedPathBuilder(shape);\n const response = sortFn(proxy);\n const nodeShape = shape.shape;\n const paths: PropertyPath[] = [];\n if (response instanceof QueryBuilderObject || response instanceof QueryPrimitiveSet) {\n paths.push(new PropertyPath(nodeShape, FieldSet.collectPropertySegments(response)));\n } else if (Array.isArray(response)) {\n for (const item of response) {\n if (item instanceof QueryBuilderObject) {\n paths.push(new PropertyPath(nodeShape, FieldSet.collectPropertySegments(item)));\n }\n }\n }\n // The DSL callback carries a single direction for all its paths; per-path\n // directions come from the wire form (deserializeSortByPath).\n return {paths, directions: paths.map(() => direction)};\n};\n\nexport class QueryShapeSet<\n S extends Shape = Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<ShapeSet<S>, Source, Property> {\n public queryShapes: CoreSet<QueryShape>;\n private proxy;\n\n constructor(\n _originalValue?: ShapeSet<S>,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n super(property, subject);\n this.originalValue = _originalValue;\n\n //Note that QueryShapeSet intentionally does not store the _originalValue shape set, because it manipulates this.queryShapes\n // and then recreates the original shape set when getOriginalValue() is called\n this.queryShapes = new CoreSet(\n _originalValue?.map((shape) =>\n QueryShape.create(shape, property, subject),\n ),\n );\n }\n\n static create<S extends Shape = Shape>(\n originalValue: ShapeSet<S>,\n property: PropertyShapeData,\n subject: QueryShape<any> | QueryShapeSet<any>,\n ) {\n let instance = new QueryShapeSet<S>(originalValue, property, subject);\n\n let proxy = this.proxifyShapeSet<S>(instance);\n return proxy;\n }\n\n static proxifyShapeSet<T extends Shape = Shape>(\n queryShapeSet: QueryShapeSet<T>,\n ) {\n let originalShapeSet = queryShapeSet.getOriginalValue();\n\n queryShapeSet.proxy = new Proxy(queryShapeSet, {\n get(target, key, receiver) {\n //if the key is a string\n if (typeof key === 'string') {\n //if this is a get method that is implemented by the QueryShapeSet, then use that\n if (key in queryShapeSet) {\n //if it's a function, then bind it to the queryShape and return it so it can be called\n if (typeof queryShapeSet[key] === 'function') {\n return target[key].bind(target);\n }\n //if it's a get method, then return that\n //NOTE: we may not need this if we don't use any get methods in QueryValue classes?\n return queryShapeSet[key];\n }\n\n //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\n //As in Shape.friends.name -> key would be name, which is requested from (each item in!) a ShapeSet of Shapes\n //So here we find back the shape that all items have in common, and then find the property shape that matches the key\n //NOTE: this will only work if the key corresponds with an accessor in the shape that uses a @linkedProperty decorator\n let leastSpecificShape = queryShapeSet\n .getOriginalValue()\n .getLeastSpecificShape();\n let valueShape = leastSpecificShape ? leastSpecificShape.shape : null;\n if (!valueShape && queryShapeSet.property?.valueShape) {\n const shapeClass = getShapeClass(queryShapeSet.property.valueShape);\n valueShape = shapeClass?.shape;\n }\n let propertyShape: PropertyShapeData = valueShape\n ? getPropertyShapes(valueShape, true).find(\n (propertyShape) => propertyShape.label === key,\n )\n : undefined;\n\n //if the property shape is found\n if (propertyShape) {\n return queryShapeSet.callPropertyShapeAccessor(propertyShape);\n } else if (\n //else if a genuine collection method of the ShapeSet is called\n //(.forEach()/.map()/… — including symbol methods like iteration)\n originalShapeSet[key] &&\n typeof originalShapeSet[key] === 'function'\n ) {\n //then return that method and bind the original value as 'this'\n return originalShapeSet[key].bind(originalShapeSet);\n } else if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {\n // Same policy as the single-node proxy: an undecorated string key\n // is a genuine misuse (it would silently return a broken path over\n // the set → silently-wrong results). Throw. Interop/framework keys\n // and symbols pass through.\n throw new Error(\n `${valueShape?.label ?? '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).`,\n );\n }\n }\n //otherwise return the value of the property on the original shape\n return originalShapeSet[key];\n },\n });\n return queryShapeSet.proxy;\n }\n\n as<ShapeClass extends typeof Shape>(\n shape: ShapeClass,\n ): QShapeSet<InstanceType<ShapeClass>, Source, Property> {\n //if the shape is not the same as the original value, then we need to create a new query shape\n // `getLeastSpecificShape()` is `undefined` for an empty set; `?.` avoids a\n // TypeError and `nodeShapeEquals(_, undefined)` is false, so we rebuild as needed.\n if (!nodeShapeEquals(shape.shape, this.originalValue.getLeastSpecificShape()?.shape)) {\n let newOriginal = new ShapeSet(\n this.originalValue.map((existing) =>\n createShapeTarget(shape as any, existing?.id),\n ),\n );\n return QueryShapeSet.create(\n newOriginal,\n this.property,\n this.subject as any,\n );\n }\n // else return this\n return this as any as QShapeSet<InstanceType<ShapeClass>, Source, Property>;\n }\n\n add(item) {\n this.queryShapes.add(item);\n }\n\n concat(other: QueryShapeSet): QueryShapeSet {\n if (other) {\n if (other instanceof QueryShapeSet) {\n (other as QueryShapeSet).queryShapes.forEach(\n this.queryShapes.add.bind(this.queryShapes),\n );\n } else {\n throw new Error('Unknown type: ' + other);\n }\n }\n return this;\n }\n\n getOriginalValue() {\n return new ShapeSet(\n this.queryShapes.map((shape) => {\n return shape.originalValue;\n }),\n ) as ShapeSet<S>;\n }\n\n callPropertyShapeAccessor(\n propertyShape: PropertyShapeData,\n ): QueryShapeSet | QueryPrimitiveSet {\n //call the get method for that property shape on each item in the shape set\n //and return the result as a new shape set\n let result: QueryPrimitiveSet | QueryShapeSet; //QueryValueSetOfSets;\n\n //if we expect the accessor to return a Primitive (string,number,boolean,Date)\n if (isSameRef(propertyShape.nodeKind, shacl.Literal)) {\n //then return a Set of QueryPrimitives\n result = new QueryPrimitiveSet(null, propertyShape, this);\n } else {\n // result = QueryValueSetOfSets.create(propertyShape, this); //QueryShapeSet.create(null, propertyShape, this);\n result = QueryShapeSet.create(null, propertyShape, this);\n }\n let expectSingleValues =\n typeof propertyShape.maxCount === 'number' && propertyShape.maxCount <= 1;\n\n this.queryShapes.forEach((shape) => {\n //access the propertyShapes accessor,\n // since the shape should already be converted to a QueryShape, the result is a QueryValue also\n let shapeQueryValue = shape[propertyShape.label];\n\n //only add results if something was actually returned, if the property is not defined for this shape the result can be undefined\n if (shapeQueryValue) {\n if (expectSingleValues) {\n (result as any).add(shapeQueryValue);\n } else {\n //if each of the shapes in a set return a new shapeset for the request accessor\n //then we merge all the returned values into a single shapeset\n (result as QueryShapeSet).concat(shapeQueryValue);\n }\n }\n });\n return result;\n }\n\n //countable?, resultKey?: string\n size(): SetSize<this> {\n //when count() is called we want to count the number of items in the entire query path\n return new SetSize(this); //countable, resultKey\n }\n\n // get testItem() {}\n where(validation: WhereClause<S>): this {\n if (\n (this.getPropertyPath() as QueryStep[]).some(\n (step) => (step as PropertyQueryStep).where,\n )\n ) {\n throw new Error(\n 'You cannot call where() from within a where() clause. Consider using some() or every() instead',\n );\n }\n let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n this.wherePath = processWhereClause(validation, leastSpecificShape);\n //return this.proxy because after Shape.friends.where() we can call other methods of Shape.friends\n //and for that we need the proxy\n return this.proxy;\n }\n\n select<QF = unknown>(\n subQueryFn: QueryBuildFn<S, QF>,\n ): FieldSet<QF, QueryShapeSet<S, Source, Property>> {\n const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n const parentSegments = FieldSet.collectPropertySegments(this);\n const fs = FieldSet.forSubSelect<QF, QueryShapeSet<S, Source, Property>>(\n leastSpecificShape,\n subQueryFn as any,\n parentSegments,\n this,\n );\n return fs;\n }\n\n selectAll(): FieldSet<\n SelectAllQueryResponse<S>,\n QueryShapeSet<S, Source, Property>\n > {\n let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n const propertyLabels = getUniquePropertyShapes(leastSpecificShape.shape)\n .map((propertyShape) => propertyShape.label);\n return this.select((shape) =>\n propertyLabels.map((label) => (shape as any)[label]),\n );\n }\n\n some(validation: WhereClause<S>): ExistsCondition {\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate, false);\n }\n\n every(validation: WhereClause<S>): ExistsCondition {\n // every(fn) = NOT EXISTS(path WHERE NOT(fn))\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate.not(), true);\n }\n\n none(validation: WhereClause<S>): ExistsCondition {\n // none(fn) = NOT EXISTS(path WHERE fn) = some(fn).not()\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate, true);\n }\n\n private buildPredicateExpression(validation: WhereClause<S>): ExpressionNode {\n const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n if (validation instanceof Function) {\n const proxy = createProxiedPathBuilder(leastSpecificShape) as any;\n const result = validation(proxy);\n if (isExpressionNode(result)) {\n return result;\n }\n throw new Error('Validation callback must return an ExpressionNode or ExistsCondition');\n }\n if (isExpressionNode(validation)) {\n return validation;\n }\n throw new Error('Expected a callback or ExpressionNode for some/every/none');\n }\n}\n\nexport class QueryShape<\n S extends Shape = Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<S, Source, Property> {\n private proxy;\n\n constructor(\n public originalValue: S,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n super(property, subject);\n }\n\n get id() {\n return (\n (this.originalValue as Shape).__queryContextId ||\n this.originalValue['id']\n );\n }\n\n static create(\n original: Shape,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n let instance = new QueryShape(original, property, subject);\n let proxy = this.proxifyQueryShape(instance);\n return proxy;\n }\n\n private static proxifyQueryShape<T extends Shape>(queryShape: QueryShape<T>) {\n let originalShape = queryShape.originalValue;\n queryShape.proxy = new Proxy(queryShape, {\n get(target, key, receiver) {\n //if the key is a string\n if (typeof key === 'string') {\n //if this is a get method that is implemented by the QueryShape, then use that\n if (key in queryShape) {\n //if it's a function, then bind it to the queryShape and return it so it can be called\n if (typeof queryShape[key] === 'function') {\n return target[key].bind(target);\n }\n //if it's a get method, then return that\n //NOTE: we may not need this if we don't use any get methods in QueryValue classes?\n return queryShape[key];\n }\n\n //if not, then a method/accessor of the original shape was called\n //then check if we have indexed any property shapes with that name for this shapes NodeShapeData\n //NOTE: this will only work with a @linkedProperty decorator\n let propertyShape = getPropertyShapeByLabel(\n originalShape.constructor as typeof Shape,\n key,\n );\n if (propertyShape) {\n return QueryBuilderObject.generatePathValue(propertyShape, target);\n }\n }\n // A string key that is neither a QueryShape member nor a decorated\n // property is a genuine misuse: it would silently return the raw value\n // and the query would run with a broken path (silently-wrong results).\n // Throw. Symbols and framework/interop keys pass through untouched so\n // promise-awaiting, React, and serializers can still introspect the proxy.\n if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {\n throw new Error(\n `${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).`,\n );\n }\n return originalShape[key];\n },\n });\n return queryShape.proxy;\n }\n\n as<ShapeClass extends typeof Shape>(\n shape: ShapeClass,\n ): QShape<InstanceType<ShapeClass>, Source, Property> {\n //if the shape is not the same as the original value, then we need to create a new query shape\n if (!nodeShapeEquals(shape.shape, this.originalValue.nodeShape)) {\n const newOriginal = createShapeTarget(shape as any, this.originalValue.id);\n return QueryShape.create(newOriginal, this.property, this.subject as any);\n }\n return this as any as QShape<InstanceType<ShapeClass>, Source, Property>;\n }\n\n equals(otherValue: NodeReferenceValue | QShape<any> | PendingQueryContext): ExpressionNode {\n const self = toExpressionNode(this);\n // An unresolved query-context reference (`getQueryContext('user')` before it\n // is set) carries no `.id` yet — keep it as a `{@ctx}` ref, resolved at lower.\n if (otherValue instanceof PendingQueryContext) {\n return self.eq(otherValue as any);\n }\n //validate the value is formed correctly\n if(!otherValue.id) {\n throw Error(`Invalid value for .equals(). ${JSON.stringify(otherValue)}`);\n }\n const arg = otherValue instanceof QueryBuilderObject\n ? toExpressionNode(otherValue)\n : otherValue;\n return self.eq(arg as any);\n }\n\n oneOf(values: (NodeReferenceValue | QShape<any>)[]): ExpressionNode {\n return toExpressionNode(this).oneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n notOneOf(values: (NodeReferenceValue | QShape<any>)[]): ExpressionNode {\n return toExpressionNode(this).notOneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n\n select<QF = unknown>(\n subQueryFn: QueryBuildFn<S, QF>,\n ): FieldSet<QF, QueryShape<S, Source, Property>> {\n // A sub-select on a project-authored value shape has no authored class, so fall\n // back to the metadata-derived constructor. Without it this returned undefined and\n // FieldSet.forSubSelect failed reading `.shape` off it, far from the cause.\n const leastSpecificShape = resolveShapeConstructor(\n (this.getOriginalValue() as Shape).nodeShape.id,\n );\n const parentSegments = FieldSet.collectPropertySegments(this);\n const fs = FieldSet.forSubSelect<QF, QueryShape<S, Source, Property>>(\n leastSpecificShape,\n subQueryFn as any,\n parentSegments,\n this,\n );\n return fs;\n }\n\n selectAll(): FieldSet<\n SelectAllQueryResponse<S>,\n QueryShape<S, Source, Property>\n > {\n // Same as `select()` above: runtime shapes resolve through the adapter.\n const shapeId = (this.getOriginalValue() as Shape).nodeShape.id;\n const leastSpecificShape = resolveShapeConstructor(shapeId);\n // An IRI that is registered nowhere resolves to nothing, and reading `.shape` off\n // it produced a bare \"Cannot read properties of undefined\" from inside the field\n // walk — a message that named neither the shape nor this call. Say which shape.\n if (!leastSpecificShape) {\n throw new Error(\n `selectAll() cannot resolve a shape for '${shapeId}'. It is registered neither ` +\n `as a class nor as metadata, so its properties are unknown.`,\n );\n }\n const propertyLabels = getUniquePropertyShapes(leastSpecificShape.shape)\n .map((propertyShape) => propertyShape.label);\n return this.select((shape) =>\n propertyLabels.map((label) => (shape as any)[label]),\n );\n }\n\n // count(countable: QueryBuilderObject, resultKey?: string): SetSize<this> {\n // return new SetSize(this, countable, resultKey);\n // // return this._count;\n // }\n}\n\n\n/**\n * Concrete query wrapper for JS primitive values (string, number, boolean, Date).\n *\n * Replaces the former abstract class + subclasses (QueryString, QueryNumber,\n * QueryBoolean, QueryDate) — the type parameter T carries the primitive type,\n * so separate subclasses are unnecessary.\n */\nexport class QueryPrimitive<\n T,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<T, Source, Property> {\n constructor(\n public originalValue?: T,\n public property?: PropertyShapeData,\n public subject?: QueryShape<any> | QueryShapeSet<any> | QueryPrimitiveSet,\n ) {\n super(property, subject);\n }\n\n equals(otherValue: ComparisonValue): ExpressionNode {\n const self = toExpressionNode(this);\n const arg = otherValue instanceof QueryBuilderObject\n ? toExpressionNode(otherValue)\n : otherValue;\n return self.eq(arg as any);\n }\n\n oneOf(values: ComparisonValue[]): ExpressionNode {\n return toExpressionNode(this).oneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n notOneOf(values: ComparisonValue[]): ExpressionNode {\n return toExpressionNode(this).notOneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n\n where(validation: WhereClause<string>): this {\n // For inline where on a primitive (p.hobby.where(h => h.equals(...))),\n // pass a clone that produces alias expressions (the bound value itself)\n // rather than property traversals\n const selfAsAlias = new InlineWhereProxy(this);\n this.wherePath = processWhereClause(validation, selfAsAlias as any);\n //return this because after Shape.friends.where() we can call other methods of Shape.friends\n return this as any;\n }\n}\n\n\nexport class QueryPrimitiveSet<\n QPrimitive extends QueryPrimitive<any> = null,\n> extends QueryBuilderObject<any, any, any> {\n public contents: CoreSet<QPrimitive>;\n\n constructor(\n public originalValue?: JSNonNullPrimitive[],\n public property?: PropertyShapeData,\n public subject?: QueryShapeSet<any> | QueryShape<any>,\n items?,\n ) {\n super(property, subject);\n this.contents = new CoreSet(items);\n }\n\n add(item) {\n this.contents.add(item);\n }\n\n values() {\n return [...this.contents.values()];\n }\n\n //this is needed because we extend CoreSet which has a createNew method but does not expect the constructor to have arguments\n createNew(...args): this {\n return new (<any>this.constructor)(\n this.property,\n this.subject,\n ...args,\n ) as this;\n }\n\n //TODO: see if we can merge these methods of QueryPrimitive and QueryPrimitiveSet\n // so that they're only defined once\n equals(other): ExpressionNode {\n return toExpressionNode(this).eq(other);\n }\n\n getPropertyStep(): QueryStep {\n if (this.contents.size > 1) {\n throw new Error(\n 'This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values',\n );\n }\n return this.contents.first().getPropertyStep();\n }\n\n getPropertyPath(): QueryPropertyPath {\n if (this.contents.size > 1) {\n throw new Error(\n 'This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values',\n );\n }\n //here we let the first item in the set return its property path, because all items will be the same\n //however, sometimes the path goes through the subject of this SET rather than the individual items (which have an individual shape as subject)\n //so we pass the subject of this set so it can be used\n let first = this.contents.first();\n if (first) {\n (first.subject as QueryShapeSet).wherePath =\n (first.subject as QueryShapeSet).wherePath || this.subject.wherePath;\n return first.getPropertyPath();\n } else {\n console.warn(\n `QueryPrimitiveSet without items. From ${this.subject.getOriginalValue().nodeShape.label}.${this.property.label}. What to return as property path?`,\n );\n return this.subject.getPropertyPath();\n }\n }\n\n //countable, resultKey?: string\n size(): SetSize<this> {\n return new SetSize(this as QueryPrimitiveSet);\n //countable, resultKey\n }\n}\n\nexport class SetSize<Source = null> extends QueryPrimitive<number, Source> {\n constructor(\n public subject: QueryShapeSet | QueryShape | QueryPrimitiveSet,\n public countable?: QueryBuilderObject,\n public label?: string,\n ) {\n super();\n }\n\n // Build an aggregate_expr(count, …) ExpressionNode for the counted property.\n private toCountExpr(): ExpressionNode {\n const countedSegments = FieldSet.collectPropertySegments(this.subject);\n const countedIds = countedSegments.map((s) => s.id);\n const countedNode = tracedPropertyExpression(countedIds);\n return new ExpressionNode(\n {kind: 'aggregate_expr', name: 'count', args: [countedNode.ir]} as any,\n countedNode._refs,\n );\n }\n\n // Comparisons on the count (lowered to a HAVING clause on COUNT(…)).\n equals(v: any): ExpressionNode { return this.toCountExpr().eq(v); }\n eq(v: any): ExpressionNode { return this.toCountExpr().eq(v); }\n neq(v: any): ExpressionNode { return this.toCountExpr().neq(v); }\n notEquals(v: any): ExpressionNode { return this.toCountExpr().neq(v); }\n gt(v: any): ExpressionNode { return this.toCountExpr().gt(v); }\n greaterThan(v: any): ExpressionNode { return this.toCountExpr().gt(v); }\n gte(v: any): ExpressionNode { return this.toCountExpr().gte(v); }\n greaterThanOrEqual(v: any): ExpressionNode { return this.toCountExpr().gte(v); }\n lt(v: any): ExpressionNode { return this.toCountExpr().lt(v); }\n lessThan(v: any): ExpressionNode { return this.toCountExpr().lt(v); }\n lte(v: any): ExpressionNode { return this.toCountExpr().lte(v); }\n lessThanOrEqual(v: any): ExpressionNode { return this.toCountExpr().lte(v); }\n\n as(label: string) {\n this.label = label;\n return this;\n }\n\n getPropertyPath(): QueryPropertyPath {\n //count the last property in the path\n //use the label of the last property as the label of the count step\n let countable = this.subject.getPropertyStep();\n let self: SizeStep = {\n count: [countable],\n label: this.label || this.subject.property.label,\n };\n\n //request the path of the subject's subject (the parent of the parent)\n //and add the SizeStep to that path, since we already used the subject as the thing that's counted\n if (this.subject.subject) {\n let path = this.subject.subject.getPropertyPath();\n path.push(self);\n return path;\n }\n return [self];\n }\n}\n\n"]}
1
+ {"version":3,"file":"SelectQuery.js","sourceRoot":"","sources":["../../../src/queries/SelectQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,iBAAiB,EAAwB,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAC,iBAAiB,EAAE,uBAAuB,EAAE,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAGvG,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAC,KAAK,EAAC,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAE,aAAa,EAAE,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAGvG,OAAO,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAC;AAEzC,OAAO,EAAC,wBAAwB,EAAC,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,qBAAqB,E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AI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;QAC/C,IAAI,IAAI,GAAa;YACnB,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK;SACjD,CAAC;QAEF,sEAAsE;QACtE,kGAAkG;QAClG,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACzB,IAAI,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;YAClD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {Shape, createShapeTarget, type ShapeConstructor} from '../shapes/Shape.js';\nimport {getPropertyShapes, getUniquePropertyShapes, nodeShapeEquals} from '../shapes/nodeShapeData.js';\nimport type {NodeShapeData, PropertyShapeData} from '../shapes/SHACL.js';\nimport type {RawSelectInput} from './IRDesugar.js';\nimport {ShapeSet} from '../collections/ShapeSet.js';\nimport {shacl} from '../ontologies/shacl.js';\nimport {CoreSet} from '../collections/CoreSet.js';\nimport {getPropertyShapeByLabel, getShapeClass, resolveShapeConstructor} from '../utils/ShapeClass.js';\n\nimport {NodeReferenceValue,type Prettify,type ShapeReferenceValue} from './QueryFactory.js';\nimport {xsd} from '../ontologies/xsd.js';\nimport type {IRSelectQuery} from './IntermediateRepresentation.js';\nimport {createProxiedPathBuilder} from './ProxiedPathBuilder.js';\nimport {FieldSet} from './FieldSet.js';\nimport {PropertyPath} from './PropertyPath.js';\nimport type {QueryBuilder, QueryBuilderJSON} from './QueryBuilder.js';\nimport {ExpressionNode, ExistsCondition, isExpressionNode, isExistsCondition, tracedPropertyExpression, tracedAliasExpression} from '../expressions/ExpressionNode.js';\nimport {PendingQueryContext} from './QueryContext.js';\n\n/**\n * String keys the query-shape proxy must let through *without* treating them as\n * a property access — promise-awaiting (`then`), React (`$$typeof`), and common\n * serializer/object-protocol probes. Everything else that isn't a decorated\n * property is a genuine misuse and throws. (Symbol keys always pass through.)\n */\nconst INTEROP_PASSTHROUGH_KEYS = new Set<string>([\n 'then',\n '$$typeof',\n 'toJSON',\n 'toString',\n 'valueOf',\n 'constructor',\n 'asymmetricMatch', // jest matchers probe this\n 'nodeType', // some DOM/serializer probes\n]);\n\n/**\n * The closed, read-only select query a dataset receives (implemented by\n * `SelectBuilder`). It exposes the wire form (`toJSON`), the routing key\n * (`shape`), and the read-only lowering hook (`toRawInput`) — but none of the\n * fluent mutators, so a store cannot keep building on it. The IR algebra is\n * `IRSelectQuery`, produced on demand by `lower(query)`.\n */\nexport interface SelectQuery {\n readonly __queryKind: 'select';\n readonly shape: NodeShapeData;\n toJSON(): QueryBuilderJSON;\n toRawInput(): RawSelectInput;\n}\n\n/**\n * ###################################\n * #### TYPES FOR QUERY BUILDING ####\n * ###################################\n */\nexport type JSPrimitive = JSNonNullPrimitive | null | undefined;\nexport type JSNonNullPrimitive = string | number | boolean | Date;\n\n/**\n * What a comparison on a primitive-valued query property accepts.\n *\n * `NodeReferenceValue` belongs here because an object property may be DECLARED\n * with a primitive accessor type — `@objectProperty({path: …}) get project():\n * string` returns the referenced node's IRI — which projects to a\n * `QueryPrimitive<string>`, not a `QueryShape`. The documented way to match such\n * a property is still by reference (`.equals({id})`), and the lowering has always\n * supported it: `toIRExpression` turns `{id}` into a `reference_expr`, so the\n * comparison renders as `<iri>` rather than a string literal.\n */\nexport type ComparisonValue =\n | JSPrimitive\n | QueryBuilderObject\n | NodeReferenceValue;\n\nconst isSameRef = (\n a?: NodeReferenceValue,\n b?: NodeReferenceValue,\n): boolean => !!a && !!b && a.id === b.id;\n\nexport type SingleResult<ResultType> =\n ResultType extends Array<infer R>\n ? R\n : ResultType extends Set<infer R>\n ? R\n : ResultType;\n\n/**\n * All the possible types that a regular get/set method of a Shape can return\n */\nexport type AccessorReturnValue =\n | Shape\n | ShapeSet\n | JSPrimitive\n | NodeReferenceValue;\n\nexport type WhereClause<S extends Shape | AccessorReturnValue> =\n | ExpressionNode\n | ExistsCondition\n | ((s: ToQueryBuilderObject<S>) => ExpressionNode | ExistsCondition);\n\nexport type QueryBuildFn<T extends Shape, ResponseType> = (\n p: ToQueryBuilderObject<T>,\n) => ResponseType;\n\nexport type SortByPath = {\n paths: PropertyPath[];\n /** Per-path sort direction (parallel to `paths`). */\n directions: ('ASC' | 'DESC')[];\n};\n\n/**\n * A property-only query path, used by where/sort proxy tracing.\n */\nexport type QueryPropertyPath = QueryStep[];\n\n/**\n * A QueryStep is a single step in a query path.\n */\nexport type QueryStep =\n | PropertyQueryStep\n | SizeStep\n | ShapeReferenceValue;\nexport type SizeStep = {\n count: QueryPropertyPath;\n label?: string;\n};\nexport type PropertyQueryStep = {\n property: PropertyShapeData;\n where?: WherePath;\n};\n\n/**\n * Maps all the return types of get/set methods of a Shape and maps their return types to QueryBuilderObjects\n */\nexport type QueryShapeProps<\n T extends Shape,\n Source,\n Property extends string | number | symbol = any,\n> = {\n [P in keyof T]: ToQueryBuilderObject<T[P], QShape<T, Source, Property>, P>;\n};\n\nexport type SelectAllQueryResponse<T extends Shape> = Array<\n QueryShapeProps<T, null, ''>[Exclude<\n Extract<\n {\n [K in keyof T]-?: T[K] extends (...args: any[]) => any ? never : K;\n }[keyof T],\n string\n >,\n Extract<keyof Shape, string>\n >]\n>;\n\n/**\n * This type states that the ShapeSet has access to the same methods as the shape of all the items in the set\n * (this is enabled with the QueryShapeSet.proxifyShapeSet method)\n * Each value of the shape is converted to a QueryBuilderObject\n */\nexport type QueryShapeSetProps<SourceShapeSet, Shape> = {\n [P in keyof Shape]: ToQueryBuilderObject<Shape[P], SourceShapeSet, P>;\n};\n\n/**\n * ShapeSets are converted to QueryShapeSets, but also inherit all the properties of the shape that each item in the set has (with converted result types)\n */\nexport type QShapeSet<\n ShapeSetType extends Shape,\n Source = null,\n Property extends string | number | symbol = never,\n> = QueryShapeSet<ShapeSetType, Source, Property> &\n QueryShapeSetProps<\n QueryShapeSet<ShapeSetType, Source, Property>,\n ShapeSetType\n >;\n\n/**\n * Shapes are converted to QueryShapes, but also inherit all the properties of the shape (with converted result types)\n */\nexport type QShape<\n T extends Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> = QueryShape<T, Source, Property> & QueryShapeProps<T, Source, Property>;\n\nexport type ToQueryBuilderObject<\n T,\n Source = null,\n Property extends string | number | symbol = '',\n> =\n T extends ShapeSet<infer ShapeSetType>\n ? QShapeSet<ShapeSetType, Source, Property>\n : T extends Shape\n ? QShape<T, Source, Property>\n : T extends string | number | Date | boolean\n ? ToQueryPrimitive<T, Source, Property>\n : // : QueryBuilderObject<T,Source,Property>;\n T extends Array<infer AT>\n ? AT extends Date | string | number\n ? QueryPrimitiveSet<ToQueryPrimitive<AT, Source, Property>>\n : AT extends boolean\n ? QueryPrimitive<boolean>\n : AT[]\n : //added support for get/set methods that return NodeReferenceValue, treating them as plain Shapes\n T extends NodeReferenceValue\n ? QShape<Shape, Source, Property>\n : QueryBuilderObject<T, Source, Property>;\n\nexport type ToQueryPrimitive<\n T extends string | number | Date | boolean,\n Source,\n Property extends string | number | symbol = '',\n> = T extends string\n ? QueryPrimitive<string, Source, Property>\n : T extends number\n ? QueryPrimitive<number, Source, Property>\n : T extends Date\n ? QueryPrimitive<Date, Source, Property>\n : T extends boolean\n ? QueryPrimitive<boolean, Source, Property>\n : never & {__error: 'ToQueryPrimitive: no matching primitive type'};\n\nexport type WhereExpressionPath = {\n expressionNode: ExpressionNode;\n};\n\nexport type WhereExistsPath = {\n existsCondition: ExistsCondition;\n};\n\nexport type WherePath = WhereExpressionPath | WhereExistsPath;\n\n/**\n * An argument can be a direct reference to a node, a js primitive (boolean,number), a path to resolve (like from a query context variables)\n * Or a wherePath in the case of some() or every() (e.g. x.where(x.friends.some(f => f.age > 18) -> the argument is a wherePath)\n */\nexport type QueryComponentLike<ShapeType extends Shape, CompQueryResult> = {\n query:\n | QueryBuilder<ShapeType>\n | FieldSet\n | Record<string, QueryBuilder<ShapeType>>;\n fields?: FieldSet;\n};\n\n/**\n * Interface that linked components (e.g. from `@_linked/react`'s `linkedComponent()`)\n * must satisfy to participate in preloadFor.\n *\n * Components expose their data requirements as a QueryBuilder,\n * and optionally a FieldSet for declarative field access.\n */\nexport interface LinkedComponentInterface<S extends Shape = Shape, R = any> {\n /** The component's data query (QueryBuilder template, not executed). */\n query: QueryBuilder<S, any, R>;\n /** The component's field requirements as a FieldSet. */\n fields?: FieldSet;\n}\n\n/**\n * ###################################\n * #### QUERY RESULT TYPES ####\n * ###################################\n */\n\nexport type QResult<ShapeType extends Shape = Shape, Object = {}> = Object & {\n id: string;\n // shape?: ShapeType;\n};\n\n/**\n * MAIN ENTRY to convert the response of a query into a result object\n */\nexport type QueryResponseToResultType<\n T,\n QShapeType extends Shape = Shape,\n HasName = false,\n> = T extends QueryBuilderObject\n ? GetQueryObjectResultType<T, {}, false, HasName>\n : T extends FieldSet<infer Response, infer Source>\n ? GetNestedQueryResultType<Response, Source>\n : T extends Array<infer Type>\n ? UnionToIntersection<QueryResponseToResultType<Type>>\n : T extends ExpressionNode\n ? boolean\n : T extends Object\n ? QResult<QShapeType, Prettify<ObjectToPlainResult<T>>>\n : never & {__error: 'QueryResponseToResultType: unmatched query response type'};\n\n/**\n * Turns a QueryBuilderObject into a plain JS object\n * @param QV the query value type\n * @param SubProperties to add extra properties into the result object (used to merge arrays into objects for example)\n * @param SourceOverwrite if the source of the query value should be overwritten\n */\nexport type GetQueryObjectResultType<\n QV,\n SubProperties = {},\n PrimitiveArray = false,\n HasName = false,\n> =\n //note: count needs to be above primitive\n QV extends SetSize<infer Source>\n ? SetSizeToQueryResult<Source, HasName>\n : QV extends QueryPrimitive<infer Primitive, infer Source, infer Property>\n ? CreateQResult<\n Source,\n PrimitiveArray extends true ? Primitive[] : Primitive,\n Property,\n {},\n HasName\n >\n : QV extends QueryShape<infer ShapeType, infer Source, infer Property>\n ? CreateQResult<Source, ShapeType, Property, SubProperties, HasName>\n : QV extends BoundComponent<infer Source, infer CompQueryResult>\n ? GetQueryObjectResultType<\n Source,\n SubProperties & QueryResponseToResultType<CompQueryResult>,\n PrimitiveArray,\n HasName\n >\n : QV extends QueryShapeSet<\n infer ShapeType,\n infer Source,\n infer Property\n >\n ? CreateShapeSetQResult<\n ShapeType,\n Source,\n Property,\n SubProperties,\n HasName\n >\n : QV extends QueryPrimitiveSet<\n infer QPrim extends QueryPrimitive<any>\n >\n ? GetQueryObjectResultType<QPrim, null, null, true>\n : QV extends Array<infer Type>\n ? UnionToIntersection<QueryResponseToResultType<Type>>\n : QV extends QueryPrimitive<boolean, any, any>\n ? 'bool'\n : never & {__error: 'GetQueryObjectResultType: unmatched query value type'};\n\nexport type SetSizeToQueryResult<Source, HasName = false> =\n Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? HasName extends false\n ? //when we count something and we already know what the name of the variable of the resulting number is, then we return a number\n //But if we count a shapeset and its NOT in a custom object where a key (name) is already known, then we return a QResult\n //This QResult will be the same as it would be if there was no .count() statement. Except now it returns a number (hence we send number as value type)\n CreateQResult<ParentSource, number, SourceProperty>\n : number\n : number;\n\n/**\n * If the source is an object (it extends shape)\n * then the result is a plain JS Object, with Property as its key, with type Value\n */\nexport type CreateQResult<\n Source,\n Value = undefined,\n Property extends string | number | symbol = '',\n SubProperties = {},\n HasName = false,\n> =\n Source extends QueryShape<\n infer SourceShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //if the parent source is null, that means this is the final source-node in the query\n ParentSource extends null\n ? HasName extends true\n ? Value\n : //TODO: this must be simplified and rewritten\n // it is likely the most complex part of the type system currently\n // It turns out that sub-.select() on a QueryShapeSet ends up here with Value being null, and sub properties need to be added to the QResult itself\n // Whilst sub-.select() on a single QueryShape ends up here with Value being defined, in which case the SubProperties need to be included in the inner QResult\n Value extends null\n ? //hence we create a single QResult, but do not use CreateQResult (which will keep creating nested QResults)\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value>;\n } & SubProperties\n >\n : //hence we create a single QResult, but do not use CreateQResult (which will keep creating nested QResults)\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value, '', SubProperties>;\n }\n >\n : CreateQResult<\n ParentSource,\n QResult<\n SourceShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value>;\n } & SubProperties\n >,\n SourceProperty,\n {},\n HasName\n >\n : Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //for a ShapeSet, we make the current result (a QResult) the value of a parent QResult (created with ToQueryResult)\n CreateQResult<\n ParentSource,\n QResult<\n ShapeType,\n {\n //we pass Value and Value but not Property, so that when the value is a Shape or ShapeSet, there is recursion\n //but for all other cases (like string, number, boolean) the value is just passed through\n [P in Property]: CreateQResult<Value, Value, never, SubProperties>;\n }\n >[],\n SourceProperty,\n {},\n HasName\n >\n : //Source is not a QueryShape or QueryShape set (currently sometimes used by end QueryPrimitives) ..\n // this needs to convert to value (amongst other things) for .select({customKeys}) and ObjectToPlainResult\n Value extends Shape\n ? QResult<Value, SubProperties>\n : // : Value extends boolean ? 'boolean' : Value;\n NormaliseBoolean<Value>;\n\ntype NormaliseBoolean<T> = [T] extends [boolean] ? boolean : T;\n\nexport type CreateShapeSetQResult<\n ShapeType = undefined,\n Source = undefined,\n Property extends string | number | symbol = '',\n SubProperties = {},\n HasName = false,\n> =\n Source extends QueryShape<infer SourceShapeType, infer ParentSource>\n ? //if HasName is true and source is a QueryShape, but ITS source (ParentSource) is null\n //then we don't want to create a nested QResult, but instead we ignore this last property and we return an array of QResults of this source\n //This is used by custom object keys with values like: p.friends, which should return an array of QResult<Person> Objects, not a {friends:...} QResult\n //NOTE: this notation check if 2 statements are true: HasName is true, and ParentSource is null\n [HasName, ParentSource] extends [true, null]\n ? CreateQResult<Source, null, never>[]\n : ParentSource extends null\n ? QResult<\n SourceShapeType,\n {[P in Property]: CreateQResult<Source, null, never, SubProperties>[]}\n >\n : //when ParentSource is not null, we need to continue unwinding the source chain\n //Pass the inner ShapeSet items as SubProperties so they stay at the correct nesting level\n CreateQResult<\n Source,\n null,\n never,\n {[P in Property]: (ShapeType extends Shape ? QResult<ShapeType, SubProperties> : QResult<Shape, SubProperties>)[]}\n >\n : Source extends QueryShapeSet<\n infer ShapeType,\n infer ParentSource,\n infer SourceProperty\n >\n ? //for a shapeset source, we make the current result (a QResult) the value of a parent QResult (created with ToQueryResult)\n CreateQResult<\n ParentSource,\n QResult<\n ShapeType,\n {\n [P in Property]: CreateQResult<ShapeType>[];\n }\n >[],\n SourceProperty,\n {},\n HasName\n >\n : CreateQResult<ShapeType>;\n\n/**\n * Ignores the source and property, and returns the converted value\n */\nexport type ObjectToPlainResult<T> = {\n //passing true as sourceOverwrite will mean that the original source is ignored and so the converted value will not be wrapped in a QResult\n // [P in keyof T]: QueryResponseToResultType<T[P], null, true>;\n [P in keyof T]: QueryResponseToResultType<T[P], Shape, true>;\n};\n\ntype GetNestedQueryResultType<Response, Source> =\n Source extends QueryBuilderObject\n ? //if the linked query originates from within another query (like with select())\n //then we turn the source into a result. And then pass the selected properties as \"SubProperties\"\n //regardless of whether the response type is an array or object, it gets converted into a result value object\n GetQueryObjectResultType<Source, QueryResponseToResultType<Response>>\n : //by default: we just convert the response type into a result value object\n QueryResponseToResultType<Response>[];\n\n//https://stackoverflow.com/a/50375286/977206\ntype UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (\n x: infer I,\n) => void\n ? I\n : never;\n\n\n/**\n * ###################################\n * #### QUERY BUILDING CLASSES ####\n * ###################################\n */\n\nexport class QueryBuilderObject<\n OriginalValue = any,\n Source = any,\n Property extends string | number | symbol = any,\n> {\n //is null by default to avoid warnings when trying to access wherePath when its undefined\n wherePath?: WherePath = null;\n protected originalValue?: OriginalValue;\n protected source: Source;\n protected prop: Property;\n\n constructor(\n public property?: PropertyShapeData,\n public subject?: QueryShape<any> | QueryShapeSet<any> | QueryPrimitiveSet,\n ) {}\n\n /**\n * Create a Query Builder Object based on the requested PropertyShapeData\n */\n static generatePathValue(\n // originalValue: AccessorReturnValue,\n property: PropertyShapeData,\n subject: QueryShape<any> | QueryShapeSet<any> | QueryShape<any>,\n ): QueryBuilderObject {\n let datatype = property.datatype;\n let valueShape = property.valueShape;\n let singleValue = property.maxCount <= 1;\n if (datatype) {\n if (singleValue) {\n if (isSameRef(datatype, xsd.integer)) {\n return wrapWithExpressionProxy(new QueryPrimitive<number>(0, property, subject));\n } else if (isSameRef(datatype, xsd.boolean)) {\n return wrapWithExpressionProxy(new QueryPrimitive<boolean>(false, property, subject));\n } else if (\n isSameRef(datatype, xsd.dateTime) ||\n isSameRef(datatype, xsd.date)\n ) {\n return wrapWithExpressionProxy(new QueryPrimitive<Date>(new Date(), property, subject));\n } else if (isSameRef(datatype, xsd.string)) {\n return wrapWithExpressionProxy(new QueryPrimitive<string>('', property, subject));\n }\n } else {\n //TODO review this, do we need property & subject in both of these? currently yes, but why\n return new QueryPrimitiveSet([''], property, subject, [\n new QueryPrimitive<string>('', property, subject),\n ]);\n }\n }\n if (valueShape) {\n const shapeClass = resolveShapeConstructor(valueShape);\n if(!shapeClass) {\n //TODO: getShapeClassAsync -> which will lazy load the shape class\n // but Im not sure if that's even possible with dynamic import paths, that are only known at runtime\n //UPDATE: we should not need to load shapeclasses. We just need to be able to access shapes.\n // but the problem remains that the ImageObject shape needs to be available, but thats easier, as its data\n throw new Error(`Shape class not found for ${valueShape.id}`);\n }\n const shapeValue = createShapeTarget(shapeClass);\n if (singleValue) {\n return QueryShape.create(shapeValue, property, subject);\n } else {\n return QueryShapeSet.create(\n new ShapeSet([shapeValue]),\n property,\n subject,\n );\n }\n }\n\n //no value shape and no data type.\n //Lets look at the node kind\n if (\n isSameRef(property.nodeKind, shacl.Literal) ||\n isSameRef(property.nodeKind, shacl.BlankNodeOrLiteral)\n ) {\n if (singleValue) {\n //default to string if no datatype is set\n return wrapWithExpressionProxy(new QueryPrimitive<string>('', property, subject));\n } else {\n //TODO review this, do we need property & subject in both of these? currently yes, but why\n return new QueryPrimitiveSet([''], property, subject, [\n new QueryPrimitive<string>('', property, subject),\n ]);\n }\n }\n\n // An object-valued property with no value shape and a non-Literal node kind\n // (e.g. `sh:path` — a raw predicate IRI, or any bare IRI reference). Project\n // it as a generic node reference via the base `Shape`, so the query returns\n // the value's IRI `{id}` — identical to how a *shaped* object property\n // resolves (cf. `sh:targetClass`, registered `shape: Shape`). This lets the\n // DSL read raw IRI predicates back out of a store (SHACL shape catalog etc.).\n //\n // NOTE: a polymorphic value (an `rdf:List` sequence path or a `PathNode`\n // operator) resolves to its *node reference* here, not its structure. Full\n // structural projection (\"if List → members, if PathNode → operands\") is the\n // `byShape` polymorphic-projection follow-up — see\n // packages/core/docs/backlog/031-byshape-polymorphic-projection.md.\n // Build a constructor-less generic node-reference target on the base `Shape`\n // (like the `valueShape` branch above, but for the shapeless base). `Shape`'s\n // constructor throws, so we use `createShapeTarget` (Object.create) — the\n // target is only a proxy metadata carrier, never a live instance.\n const genericShape = createShapeTarget(Shape);\n return singleValue\n ? QueryShape.create(genericShape, property, subject)\n : QueryShapeSet.create(new ShapeSet([genericShape]), property, subject);\n }\n\n getOriginalValue() {\n return this.originalValue;\n }\n\n getPropertyStep(): QueryStep {\n return {\n property: this.property,\n where: this.wherePath,\n };\n }\n\n preloadFor<ShapeType extends Shape, CompQueryRes>(\n component: QueryComponentLike<ShapeType, CompQueryRes>,\n ): BoundComponent<this, CompQueryRes> {\n return new BoundComponent<this, CompQueryRes>(component, this);\n }\n\n /**\n * Pagination is applied to a nested *select*, not to a bare traversal — use\n * `p.friends.select(f => f.name).limit(n)`. Calling `.limit()` directly on a\n * traversal would silently do nothing, so we fail loudly instead.\n * (Top-level result pagination lives on the outer query builder.)\n */\n limit(lim: number): never {\n throw new Error(\n `.limit(${lim}) is not supported directly on a traversal — use ` +\n '.select(...).limit(n) on the nested collection (single-subject queries only).',\n );\n }\n\n /**\n * Returns the path of properties that were requested to reach this value\n */\n getPropertyPath(currentPath?: QueryPropertyPath): QueryPropertyPath {\n let path: QueryPropertyPath = currentPath || [];\n //add the step of this object to the beginning of the path (so that the next parent will always before the current item)\n if (this.property || this.wherePath) {\n path.unshift(this.getPropertyStep());\n }\n if (this.subject) {\n return this.subject.getPropertyPath(path);\n }\n //when query context is used as the first step, then the first step is just a pointer to the subject it represents\n if ((this.originalValue as Shape)?.__queryContextId) {\n path.unshift(convertQueryContext(this as any as QueryShape));\n }\n return path;\n }\n}\n\nexport class BoundComponent<\n Source extends QueryBuilderObject,\n CompQueryResult = any,\n> extends QueryBuilderObject {\n constructor(\n public originalValue: QueryComponentLike<any, CompQueryResult>,\n public source: Source,\n ) {\n super(null, null);\n }\n\n}\n\n/**\n * Converts query context to a ShapeReferenceValue\n */\nconst convertQueryContext = (shape: QueryShape): ShapeReferenceValue => {\n return {\n id: (shape.originalValue as Shape).__queryContextId,\n shape: {\n id: shape.originalValue.nodeShape.id,\n },\n } as ShapeReferenceValue;\n};\n\nexport const processWhereClause = (\n validation: WhereClause<any>,\n shape?,\n): WherePath => {\n if (validation instanceof Function) {\n if (!shape) {\n throw new Error('Cannot process where clause without shape');\n }\n const proxy = createProxiedPathBuilder(shape);\n const result = validation(proxy);\n if (isExpressionNode(result)) {\n return {expressionNode: result};\n }\n if (isExistsCondition(result)) {\n return {existsCondition: result};\n }\n throw new Error('WHERE callback must return ExpressionNode or ExistsCondition');\n } else if (isExpressionNode(validation)) {\n return {expressionNode: validation};\n } else if (isExistsCondition(validation)) {\n return {existsCondition: validation};\n } else {\n throw new Error('WHERE clause must be ExpressionNode, ExistsCondition, or a callback');\n }\n};\n\n// ---------------------------------------------------------------------------\n// Expression method proxy for QueryPrimitive\n// ---------------------------------------------------------------------------\n\nconst EXPRESSION_METHODS = new Set([\n 'plus', 'minus', 'times', 'divide', 'abs', 'round', 'ceil', 'floor', 'power',\n 'equals', 'eq', 'neq', 'notEquals', 'gt', 'greaterThan', 'gte', 'greaterThanOrEqual',\n 'lt', 'lessThan', 'lte', 'lessThanOrEqual', 'oneOf', 'notOneOf',\n 'concat', 'contains', 'startsWith', 'endsWith', 'substr', 'before', 'after',\n 'replace', 'ucase', 'lcase', 'strlen', 'encodeForUri', 'matches',\n 'year', 'month', 'day', 'hours', 'minutes', 'seconds', 'timezone', 'tz',\n 'and', 'or', 'not',\n 'isDefined', 'isNotDefined', 'defaultTo',\n 'lang', 'datatype', 'str', 'iri', 'isIri', 'isLiteral', 'isBlank', 'isNumeric',\n 'md5', 'sha256', 'sha512',\n]);\n\n/**\n * Convert a QueryBuilderObject to a traced ExpressionNode by extracting its\n * property path segments and creating a property expression reference.\n * This is the bridge between the query proxy world and the expression IR world.\n */\nfunction toExpressionNode(qbo: QueryBuilderObject): ExpressionNode {\n // Check if this is a query context reference. We carry the context *name*\n // (not the resolved id): it serializes as `{@ctx}` and is resolved by `lower()`.\n const contextName = findContextName(qbo);\n if (contextName) {\n const segments = FieldSet.collectPropertySegments(qbo);\n if (segments.length > 0) {\n // Context property access (e.g. getQueryContext('user').name) → context_property_expr\n const lastSegment = segments[segments.length - 1].id;\n const ir = {kind: 'context_property_expr' as const, contextName, property: lastSegment};\n return new ExpressionNode(ir);\n }\n // Context root reference (e.g. getQueryContext('user')) → reference_expr\n const ir = {kind: 'reference_expr' as const, contextName};\n return new ExpressionNode(ir);\n }\n\n const segments = FieldSet.collectPropertySegments(qbo);\n if (segments.length === 0) {\n // Root shape or entity reference — produce alias expression (the entity itself)\n return tracedAliasExpression([]);\n }\n const segmentIds = segments.map((s) => s.id);\n return tracedPropertyExpression(segmentIds);\n}\n\n/** Walk up the QueryBuilderObject chain to find a query context *name* (for `{@ctx}`). */\nfunction findContextName(qbo: QueryBuilderObject): string | undefined {\n let current: QueryBuilderObject | undefined = qbo;\n while (current) {\n if (current instanceof QueryShape && (current.originalValue as any)?.__queryContextName) {\n return (current.originalValue as any).__queryContextName;\n }\n current = current.subject as QueryBuilderObject | undefined;\n }\n return undefined;\n}\n\n/**\n * A wrapper for inline `.where()` on primitives that produces alias-based expressions.\n * When `p.hobby.where(h => h.equals('Jogging'))` is called, `h` should reference\n * the hobby variable itself (alias), not traverse to a sub-property.\n */\nclass InlineWhereProxy extends QueryBuilderObject {\n constructor(public readonly source: QueryPrimitive<any>) {\n super(source.property, source.subject);\n }\n\n equals(otherValue: any): ExpressionNode {\n // Empty traversal = \"the current alias\" — resolved by lowering\n // against the property's own alias scope\n const self = tracedAliasExpression([]);\n return self.eq(otherValue);\n }\n}\n\n/**\n * Wrap a QueryPrimitive in a Proxy that intercepts expression method calls.\n * When an expression method (e.g., `.plus()`, `.gt()`, `.equals()`) is accessed,\n * creates a traced ExpressionNode based on the QueryPrimitive's property path.\n */\nfunction wrapWithExpressionProxy<T>(qp: QueryPrimitive<T>): QueryPrimitive<T> {\n return new Proxy(qp, {\n get(target, key, receiver) {\n if (typeof key === 'string' && EXPRESSION_METHODS.has(key)) {\n const segments = FieldSet.collectPropertySegments(target);\n // Only intercept if we have valid property segments to trace\n if (segments.length > 0) {\n // Use toExpressionNode so a context property as the *self* of an\n // expression (e.g. getQueryContext('user').name.equals(x)) becomes a\n // context_property_expr, not a root-entity property_expr.\n const baseNode = toExpressionNode(target as unknown as QueryBuilderObject);\n return (...args: any[]) => {\n // Convert QueryBuilderObject arguments to ExpressionNode\n const convertedArgs = args.map((arg) =>\n arg instanceof QueryBuilderObject ? (toExpressionNode(arg) ?? arg) : arg,\n );\n return (baseNode as any)[key](...convertedArgs);\n };\n }\n }\n return Reflect.get(target, key, receiver);\n },\n }) as QueryPrimitive<T>;\n}\n\n/**\n * Evaluate a sort callback through the proxy and extract a SortByPath.\n * This is a standalone helper that replaces the need for the former SelectQueryFactory.sortBy().\n */\nexport const evaluateSortCallback = <S extends Shape>(\n shape: ShapeConstructor<S>,\n sortFn: (p: any) => any,\n direction: 'ASC' | 'DESC' = 'ASC',\n): SortByPath => {\n const proxy = createProxiedPathBuilder(shape);\n const response = sortFn(proxy);\n const nodeShape = shape.shape;\n const paths: PropertyPath[] = [];\n if (response instanceof QueryBuilderObject || response instanceof QueryPrimitiveSet) {\n paths.push(new PropertyPath(nodeShape, FieldSet.collectPropertySegments(response)));\n } else if (Array.isArray(response)) {\n for (const item of response) {\n if (item instanceof QueryBuilderObject) {\n paths.push(new PropertyPath(nodeShape, FieldSet.collectPropertySegments(item)));\n }\n }\n }\n // The DSL callback carries a single direction for all its paths; per-path\n // directions come from the wire form (deserializeSortByPath).\n return {paths, directions: paths.map(() => direction)};\n};\n\nexport class QueryShapeSet<\n S extends Shape = Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<ShapeSet<S>, Source, Property> {\n public queryShapes: CoreSet<QueryShape>;\n private proxy;\n\n constructor(\n _originalValue?: ShapeSet<S>,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n super(property, subject);\n this.originalValue = _originalValue;\n\n //Note that QueryShapeSet intentionally does not store the _originalValue shape set, because it manipulates this.queryShapes\n // and then recreates the original shape set when getOriginalValue() is called\n this.queryShapes = new CoreSet(\n _originalValue?.map((shape) =>\n QueryShape.create(shape, property, subject),\n ),\n );\n }\n\n static create<S extends Shape = Shape>(\n originalValue: ShapeSet<S>,\n property: PropertyShapeData,\n subject: QueryShape<any> | QueryShapeSet<any>,\n ) {\n let instance = new QueryShapeSet<S>(originalValue, property, subject);\n\n let proxy = this.proxifyShapeSet<S>(instance);\n return proxy;\n }\n\n static proxifyShapeSet<T extends Shape = Shape>(\n queryShapeSet: QueryShapeSet<T>,\n ) {\n let originalShapeSet = queryShapeSet.getOriginalValue();\n\n queryShapeSet.proxy = new Proxy(queryShapeSet, {\n get(target, key, receiver) {\n //if the key is a string\n if (typeof key === 'string') {\n //if this is a get method that is implemented by the QueryShapeSet, then use that\n if (key in queryShapeSet) {\n //if it's a function, then bind it to the queryShape and return it so it can be called\n if (typeof queryShapeSet[key] === 'function') {\n return target[key].bind(target);\n }\n //if it's a get method, then return that\n //NOTE: we may not need this if we don't use any get methods in QueryValue classes?\n return queryShapeSet[key];\n }\n\n //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\n //As in Shape.friends.name -> key would be name, which is requested from (each item in!) a ShapeSet of Shapes\n //So here we find back the shape that all items have in common, and then find the property shape that matches the key\n //NOTE: this will only work if the key corresponds with an accessor in the shape that uses a @linkedProperty decorator\n let leastSpecificShape = queryShapeSet\n .getOriginalValue()\n .getLeastSpecificShape();\n let valueShape = leastSpecificShape ? leastSpecificShape.shape : null;\n if (!valueShape && queryShapeSet.property?.valueShape) {\n const shapeClass = getShapeClass(queryShapeSet.property.valueShape);\n valueShape = shapeClass?.shape;\n }\n let propertyShape: PropertyShapeData = valueShape\n ? getPropertyShapes(valueShape, true).find(\n (propertyShape) => propertyShape.label === key,\n )\n : undefined;\n\n //if the property shape is found\n if (propertyShape) {\n return queryShapeSet.callPropertyShapeAccessor(propertyShape);\n } else if (\n //else if a genuine collection method of the ShapeSet is called\n //(.forEach()/.map()/… — including symbol methods like iteration)\n originalShapeSet[key] &&\n typeof originalShapeSet[key] === 'function'\n ) {\n //then return that method and bind the original value as 'this'\n return originalShapeSet[key].bind(originalShapeSet);\n } else if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {\n // Same policy as the single-node proxy: an undecorated string key\n // is a genuine misuse (it would silently return a broken path over\n // the set → silently-wrong results). Throw. Interop/framework keys\n // and symbols pass through.\n throw new Error(\n `${valueShape?.label ?? '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).`,\n );\n }\n }\n //otherwise return the value of the property on the original shape\n return originalShapeSet[key];\n },\n });\n return queryShapeSet.proxy;\n }\n\n as<ShapeClass extends typeof Shape>(\n shape: ShapeClass,\n ): QShapeSet<InstanceType<ShapeClass>, Source, Property> {\n //if the shape is not the same as the original value, then we need to create a new query shape\n // `getLeastSpecificShape()` is `undefined` for an empty set; `?.` avoids a\n // TypeError and `nodeShapeEquals(_, undefined)` is false, so we rebuild as needed.\n if (!nodeShapeEquals(shape.shape, this.originalValue.getLeastSpecificShape()?.shape)) {\n let newOriginal = new ShapeSet(\n this.originalValue.map((existing) =>\n createShapeTarget(shape as any, existing?.id),\n ),\n );\n return QueryShapeSet.create(\n newOriginal,\n this.property,\n this.subject as any,\n );\n }\n // else return this\n return this as any as QShapeSet<InstanceType<ShapeClass>, Source, Property>;\n }\n\n add(item) {\n this.queryShapes.add(item);\n }\n\n concat(other: QueryShapeSet): QueryShapeSet {\n if (other) {\n if (other instanceof QueryShapeSet) {\n (other as QueryShapeSet).queryShapes.forEach(\n this.queryShapes.add.bind(this.queryShapes),\n );\n } else {\n throw new Error('Unknown type: ' + other);\n }\n }\n return this;\n }\n\n getOriginalValue() {\n return new ShapeSet(\n this.queryShapes.map((shape) => {\n return shape.originalValue;\n }),\n ) as ShapeSet<S>;\n }\n\n callPropertyShapeAccessor(\n propertyShape: PropertyShapeData,\n ): QueryShapeSet | QueryPrimitiveSet {\n //call the get method for that property shape on each item in the shape set\n //and return the result as a new shape set\n let result: QueryPrimitiveSet | QueryShapeSet; //QueryValueSetOfSets;\n\n //if we expect the accessor to return a Primitive (string,number,boolean,Date)\n if (isSameRef(propertyShape.nodeKind, shacl.Literal)) {\n //then return a Set of QueryPrimitives\n result = new QueryPrimitiveSet(null, propertyShape, this);\n } else {\n // result = QueryValueSetOfSets.create(propertyShape, this); //QueryShapeSet.create(null, propertyShape, this);\n result = QueryShapeSet.create(null, propertyShape, this);\n }\n let expectSingleValues =\n typeof propertyShape.maxCount === 'number' && propertyShape.maxCount <= 1;\n\n this.queryShapes.forEach((shape) => {\n //access the propertyShapes accessor,\n // since the shape should already be converted to a QueryShape, the result is a QueryValue also\n let shapeQueryValue = shape[propertyShape.label];\n\n //only add results if something was actually returned, if the property is not defined for this shape the result can be undefined\n if (shapeQueryValue) {\n if (expectSingleValues) {\n (result as any).add(shapeQueryValue);\n } else {\n //if each of the shapes in a set return a new shapeset for the request accessor\n //then we merge all the returned values into a single shapeset\n (result as QueryShapeSet).concat(shapeQueryValue);\n }\n }\n });\n return result;\n }\n\n //countable?, resultKey?: string\n size(): SetSize<this> {\n //when count() is called we want to count the number of items in the entire query path\n return new SetSize(this); //countable, resultKey\n }\n\n // get testItem() {}\n where(validation: WhereClause<S>): this {\n if (\n (this.getPropertyPath() as QueryStep[]).some(\n (step) => (step as PropertyQueryStep).where,\n )\n ) {\n throw new Error(\n 'You cannot call where() from within a where() clause. Consider using some() or every() instead',\n );\n }\n let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n this.wherePath = processWhereClause(validation, leastSpecificShape);\n //return this.proxy because after Shape.friends.where() we can call other methods of Shape.friends\n //and for that we need the proxy\n return this.proxy;\n }\n\n select<QF = unknown>(\n subQueryFn: QueryBuildFn<S, QF>,\n ): FieldSet<QF, QueryShapeSet<S, Source, Property>> {\n const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n const parentSegments = FieldSet.collectPropertySegments(this);\n const fs = FieldSet.forSubSelect<QF, QueryShapeSet<S, Source, Property>>(\n leastSpecificShape,\n subQueryFn as any,\n parentSegments,\n this,\n );\n return fs;\n }\n\n selectAll(): FieldSet<\n SelectAllQueryResponse<S>,\n QueryShapeSet<S, Source, Property>\n > {\n let leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n const propertyLabels = getUniquePropertyShapes(leastSpecificShape.shape)\n .map((propertyShape) => propertyShape.label);\n return this.select((shape) =>\n propertyLabels.map((label) => (shape as any)[label]),\n );\n }\n\n some(validation: WhereClause<S>): ExistsCondition {\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate, false);\n }\n\n every(validation: WhereClause<S>): ExistsCondition {\n // every(fn) = NOT EXISTS(path WHERE NOT(fn))\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate.not(), true);\n }\n\n none(validation: WhereClause<S>): ExistsCondition {\n // none(fn) = NOT EXISTS(path WHERE fn) = some(fn).not()\n const predicate = this.buildPredicateExpression(validation);\n const pathSegmentIds = FieldSet.collectPropertySegments(this).map(s => s.id);\n return new ExistsCondition(pathSegmentIds, predicate, true);\n }\n\n private buildPredicateExpression(validation: WhereClause<S>): ExpressionNode {\n const leastSpecificShape = this.getOriginalValue().getLeastSpecificShape();\n if (validation instanceof Function) {\n const proxy = createProxiedPathBuilder(leastSpecificShape) as any;\n const result = validation(proxy);\n if (isExpressionNode(result)) {\n return result;\n }\n throw new Error('Validation callback must return an ExpressionNode or ExistsCondition');\n }\n if (isExpressionNode(validation)) {\n return validation;\n }\n throw new Error('Expected a callback or ExpressionNode for some/every/none');\n }\n}\n\nexport class QueryShape<\n S extends Shape = Shape,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<S, Source, Property> {\n private proxy;\n\n constructor(\n public originalValue: S,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n super(property, subject);\n }\n\n get id() {\n return (\n (this.originalValue as Shape).__queryContextId ||\n this.originalValue['id']\n );\n }\n\n static create(\n original: Shape,\n property?: PropertyShapeData,\n subject?: QueryShape<any> | QueryShapeSet<any>,\n ) {\n let instance = new QueryShape(original, property, subject);\n let proxy = this.proxifyQueryShape(instance);\n return proxy;\n }\n\n private static proxifyQueryShape<T extends Shape>(queryShape: QueryShape<T>) {\n let originalShape = queryShape.originalValue;\n queryShape.proxy = new Proxy(queryShape, {\n get(target, key, receiver) {\n //if the key is a string\n if (typeof key === 'string') {\n //if this is a get method that is implemented by the QueryShape, then use that\n if (key in queryShape) {\n //if it's a function, then bind it to the queryShape and return it so it can be called\n if (typeof queryShape[key] === 'function') {\n return target[key].bind(target);\n }\n //if it's a get method, then return that\n //NOTE: we may not need this if we don't use any get methods in QueryValue classes?\n return queryShape[key];\n }\n\n //if not, then a method/accessor of the original shape was called\n //then check if we have indexed any property shapes with that name for this shapes NodeShapeData\n //NOTE: this will only work with a @linkedProperty decorator\n let propertyShape = getPropertyShapeByLabel(\n originalShape.constructor as typeof Shape,\n key,\n );\n if (propertyShape) {\n return QueryBuilderObject.generatePathValue(propertyShape, target);\n }\n }\n // A string key that is neither a QueryShape member nor a decorated\n // property is a genuine misuse: it would silently return the raw value\n // and the query would run with a broken path (silently-wrong results).\n // Throw. Symbols and framework/interop keys pass through untouched so\n // promise-awaiting, React, and serializers can still introspect the proxy.\n if (typeof key === 'string' && !INTEROP_PASSTHROUGH_KEYS.has(key)) {\n throw new Error(\n `${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).`,\n );\n }\n return originalShape[key];\n },\n });\n return queryShape.proxy;\n }\n\n as<ShapeClass extends typeof Shape>(\n shape: ShapeClass,\n ): QShape<InstanceType<ShapeClass>, Source, Property> {\n //if the shape is not the same as the original value, then we need to create a new query shape\n if (!nodeShapeEquals(shape.shape, this.originalValue.nodeShape)) {\n const newOriginal = createShapeTarget(shape as any, this.originalValue.id);\n return QueryShape.create(newOriginal, this.property, this.subject as any);\n }\n return this as any as QShape<InstanceType<ShapeClass>, Source, Property>;\n }\n\n equals(otherValue: NodeReferenceValue | QShape<any> | PendingQueryContext): ExpressionNode {\n const self = toExpressionNode(this);\n // An unresolved query-context reference (`getQueryContext('user')` before it\n // is set) carries no `.id` yet — keep it as a `{@ctx}` ref, resolved at lower.\n if (otherValue instanceof PendingQueryContext) {\n return self.eq(otherValue as any);\n }\n //validate the value is formed correctly\n if(!otherValue.id) {\n throw Error(`Invalid value for .equals(). ${JSON.stringify(otherValue)}`);\n }\n const arg = otherValue instanceof QueryBuilderObject\n ? toExpressionNode(otherValue)\n : otherValue;\n return self.eq(arg as any);\n }\n\n oneOf(values: (NodeReferenceValue | QShape<any>)[]): ExpressionNode {\n return toExpressionNode(this).oneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n notOneOf(values: (NodeReferenceValue | QShape<any>)[]): ExpressionNode {\n return toExpressionNode(this).notOneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n\n select<QF = unknown>(\n subQueryFn: QueryBuildFn<S, QF>,\n ): FieldSet<QF, QueryShape<S, Source, Property>> {\n // A sub-select on a project-authored value shape has no authored class, so fall\n // back to the metadata-derived constructor. Without it this returned undefined and\n // FieldSet.forSubSelect failed reading `.shape` off it, far from the cause.\n const leastSpecificShape = resolveShapeConstructor(\n (this.getOriginalValue() as Shape).nodeShape.id,\n );\n const parentSegments = FieldSet.collectPropertySegments(this);\n const fs = FieldSet.forSubSelect<QF, QueryShape<S, Source, Property>>(\n leastSpecificShape,\n subQueryFn as any,\n parentSegments,\n this,\n );\n return fs;\n }\n\n selectAll(): FieldSet<\n SelectAllQueryResponse<S>,\n QueryShape<S, Source, Property>\n > {\n // Same as `select()` above: runtime shapes resolve through the adapter.\n const shapeId = (this.getOriginalValue() as Shape).nodeShape.id;\n const leastSpecificShape = resolveShapeConstructor(shapeId);\n // An IRI that is registered nowhere resolves to nothing, and reading `.shape` off\n // it produced a bare \"Cannot read properties of undefined\" from inside the field\n // walk — a message that named neither the shape nor this call. Say which shape.\n if (!leastSpecificShape) {\n throw new Error(\n `selectAll() cannot resolve a shape for '${shapeId}'. It is registered neither ` +\n `as a class nor as metadata, so its properties are unknown.`,\n );\n }\n const propertyLabels = getUniquePropertyShapes(leastSpecificShape.shape)\n .map((propertyShape) => propertyShape.label);\n return this.select((shape) =>\n propertyLabels.map((label) => (shape as any)[label]),\n );\n }\n\n // count(countable: QueryBuilderObject, resultKey?: string): SetSize<this> {\n // return new SetSize(this, countable, resultKey);\n // // return this._count;\n // }\n}\n\n\n/**\n * Concrete query wrapper for JS primitive values (string, number, boolean, Date).\n *\n * Replaces the former abstract class + subclasses (QueryString, QueryNumber,\n * QueryBoolean, QueryDate) — the type parameter T carries the primitive type,\n * so separate subclasses are unnecessary.\n */\nexport class QueryPrimitive<\n T,\n Source = any,\n Property extends string | number | symbol = any,\n> extends QueryBuilderObject<T, Source, Property> {\n constructor(\n public originalValue?: T,\n public property?: PropertyShapeData,\n public subject?: QueryShape<any> | QueryShapeSet<any> | QueryPrimitiveSet,\n ) {\n super(property, subject);\n }\n\n equals(otherValue: ComparisonValue): ExpressionNode {\n const self = toExpressionNode(this);\n const arg = otherValue instanceof QueryBuilderObject\n ? toExpressionNode(otherValue)\n : otherValue;\n return self.eq(arg as any);\n }\n\n oneOf(values: ComparisonValue[]): ExpressionNode {\n return toExpressionNode(this).oneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n notOneOf(values: ComparisonValue[]): ExpressionNode {\n return toExpressionNode(this).notOneOf(\n values.map((v) => (v instanceof QueryBuilderObject ? toExpressionNode(v) : v)) as any,\n );\n }\n\n where(validation: WhereClause<string>): this {\n // For inline where on a primitive (p.hobby.where(h => h.equals(...))),\n // pass a clone that produces alias expressions (the bound value itself)\n // rather than property traversals\n const selfAsAlias = new InlineWhereProxy(this);\n this.wherePath = processWhereClause(validation, selfAsAlias as any);\n //return this because after Shape.friends.where() we can call other methods of Shape.friends\n return this as any;\n }\n}\n\n\nexport class QueryPrimitiveSet<\n QPrimitive extends QueryPrimitive<any> | null = null,\n> extends QueryBuilderObject<any, any, any> {\n public contents: CoreSet<QPrimitive>;\n\n constructor(\n public originalValue?: JSNonNullPrimitive[],\n public property?: PropertyShapeData,\n public subject?: QueryShapeSet<any> | QueryShape<any>,\n items?,\n ) {\n super(property, subject);\n this.contents = new CoreSet(items);\n }\n\n add(item) {\n this.contents.add(item);\n }\n\n values() {\n return [...this.contents.values()];\n }\n\n //this is needed because we extend CoreSet which has a createNew method but does not expect the constructor to have arguments\n createNew(...args): this {\n return new (<any>this.constructor)(\n this.property,\n this.subject,\n ...args,\n ) as this;\n }\n\n //TODO: see if we can merge these methods of QueryPrimitive and QueryPrimitiveSet\n // so that they're only defined once\n equals(other): ExpressionNode {\n return toExpressionNode(this).eq(other);\n }\n\n getPropertyStep(): QueryStep {\n if (this.contents.size > 1) {\n throw new Error(\n 'This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values',\n );\n }\n return this.contents.first().getPropertyStep();\n }\n\n getPropertyPath(): QueryPropertyPath {\n if (this.contents.size > 1) {\n throw new Error(\n 'This should never happen? Not implemented: get property path for a QueryPrimitiveSet with multiple values',\n );\n }\n //here we let the first item in the set return its property path, because all items will be the same\n //however, sometimes the path goes through the subject of this SET rather than the individual items (which have an individual shape as subject)\n //so we pass the subject of this set so it can be used\n let first = this.contents.first();\n if (first) {\n (first.subject as QueryShapeSet).wherePath =\n (first.subject as QueryShapeSet).wherePath || this.subject.wherePath;\n return first.getPropertyPath();\n } else {\n console.warn(\n `QueryPrimitiveSet without items. From ${this.subject.getOriginalValue().nodeShape.label}.${this.property.label}. What to return as property path?`,\n );\n return this.subject.getPropertyPath();\n }\n }\n\n //countable, resultKey?: string\n size(): SetSize<this> {\n return new SetSize(this as QueryPrimitiveSet);\n //countable, resultKey\n }\n}\n\nexport class SetSize<Source = null> extends QueryPrimitive<number, Source> {\n constructor(\n public subject: QueryShapeSet | QueryShape | QueryPrimitiveSet,\n public countable?: QueryBuilderObject,\n public label?: string,\n ) {\n super();\n }\n\n // Build an aggregate_expr(count, …) ExpressionNode for the counted property.\n private toCountExpr(): ExpressionNode {\n const countedSegments = FieldSet.collectPropertySegments(this.subject);\n const countedIds = countedSegments.map((s) => s.id);\n const countedNode = tracedPropertyExpression(countedIds);\n return new ExpressionNode(\n {kind: 'aggregate_expr', name: 'count', args: [countedNode.ir]} as any,\n countedNode._refs,\n );\n }\n\n // Comparisons on the count (lowered to a HAVING clause on COUNT(…)).\n equals(v: any): ExpressionNode { return this.toCountExpr().eq(v); }\n eq(v: any): ExpressionNode { return this.toCountExpr().eq(v); }\n neq(v: any): ExpressionNode { return this.toCountExpr().neq(v); }\n notEquals(v: any): ExpressionNode { return this.toCountExpr().neq(v); }\n gt(v: any): ExpressionNode { return this.toCountExpr().gt(v); }\n greaterThan(v: any): ExpressionNode { return this.toCountExpr().gt(v); }\n gte(v: any): ExpressionNode { return this.toCountExpr().gte(v); }\n greaterThanOrEqual(v: any): ExpressionNode { return this.toCountExpr().gte(v); }\n lt(v: any): ExpressionNode { return this.toCountExpr().lt(v); }\n lessThan(v: any): ExpressionNode { return this.toCountExpr().lt(v); }\n lte(v: any): ExpressionNode { return this.toCountExpr().lte(v); }\n lessThanOrEqual(v: any): ExpressionNode { return this.toCountExpr().lte(v); }\n\n as(label: string) {\n this.label = label;\n return this;\n }\n\n getPropertyPath(): QueryPropertyPath {\n //count the last property in the path\n //use the label of the last property as the label of the count step\n let countable = this.subject.getPropertyStep();\n let self: SizeStep = {\n count: [countable],\n label: this.label || this.subject.property.label,\n };\n\n //request the path of the subject's subject (the parent of the parent)\n //and add the SizeStep to that path, since we already used the subject as the thing that's counted\n if (this.subject.subject) {\n let path = this.subject.subject.getPropertyPath();\n path.push(self);\n return path;\n }\n return [self];\n }\n}\n\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_linked/core",
3
- "version": "2.27.0",
3
+ "version": "2.28.1",
4
4
  "packageManager": "npm@12.1.0",
5
5
  "license": "MIT",
6
6
  "linkedPackage": true,
@@ -57,22 +57,23 @@
57
57
  "LICENSE"
58
58
  ],
59
59
  "scripts": {
60
- "build": "rimraf ./lib && tsc -p tsconfig-esm.json",
60
+ "build": "linked build",
61
61
  "compile": "echo '💫 Compiling ESM' && tsc -p tsconfig-esm.json",
62
62
  "sync:agents": "node packages/skills/sync.mjs",
63
63
  "setup": "npx semantu-agents",
64
64
  "typecheck": "tsc -p tsconfig-tests.json",
65
+ "check:dts": "tsc -p tsconfig-dts-check.json",
65
66
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.cjs && npm run typecheck",
66
67
  "test:fuseki": "docker compose -f src/tests/docker-compose.test.yml up -d --wait && NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.cjs --runInBand --testPathPattern='sparql-fuseki' --verbose; EXIT=$?; docker compose -f src/tests/docker-compose.test.yml down; exit $EXIT"
67
68
  },
68
69
  "devDependencies": {
70
+ "@_linked/cli": "^1.45.5",
69
71
  "@changesets/changelog-github": "^1.0.0",
70
72
  "@changesets/cli": "^3.0.0",
71
73
  "@jest/globals": "^30.0.0",
72
74
  "@types/jest": "^30.0.0",
73
75
  "@types/node": "^24.0.0",
74
76
  "jest": "^30.0.0",
75
- "rimraf": "^6.0.0",
76
77
  "ts-jest": "^29.1.2",
77
78
  "typescript": "^5.7.3"
78
79
  },