@_linked/core 1.0.0-next.20260224083238 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +4 -12
  2. package/README.md +40 -186
  3. package/lib/cjs/index.js +0 -2
  4. package/lib/cjs/index.js.map +1 -1
  5. package/lib/cjs/interfaces/IQuadStore.d.ts +7 -19
  6. package/lib/cjs/interfaces/IQueryParser.d.ts +13 -0
  7. package/lib/cjs/interfaces/IQueryParser.js +10 -0
  8. package/lib/cjs/interfaces/IQueryParser.js.map +1 -0
  9. package/lib/cjs/queries/CreateQuery.d.ts +8 -7
  10. package/lib/cjs/queries/CreateQuery.js +4 -4
  11. package/lib/cjs/queries/CreateQuery.js.map +1 -1
  12. package/lib/cjs/queries/DeleteQuery.d.ts +8 -7
  13. package/lib/cjs/queries/DeleteQuery.js +4 -4
  14. package/lib/cjs/queries/DeleteQuery.js.map +1 -1
  15. package/lib/cjs/queries/QueryFactory.d.ts +2 -0
  16. package/lib/cjs/queries/QueryFactory.js +3 -0
  17. package/lib/cjs/queries/QueryFactory.js.map +1 -1
  18. package/lib/cjs/queries/QueryParser.d.ts +1 -6
  19. package/lib/cjs/queries/QueryParser.js +22 -14
  20. package/lib/cjs/queries/QueryParser.js.map +1 -1
  21. package/lib/cjs/queries/SelectQuery.d.ts +27 -18
  22. package/lib/cjs/queries/SelectQuery.js +45 -54
  23. package/lib/cjs/queries/SelectQuery.js.map +1 -1
  24. package/lib/cjs/queries/UpdateQuery.d.ts +9 -8
  25. package/lib/cjs/queries/UpdateQuery.js +4 -4
  26. package/lib/cjs/queries/UpdateQuery.js.map +1 -1
  27. package/lib/cjs/shapes/SHACL.d.ts +0 -1
  28. package/lib/cjs/shapes/SHACL.js +2 -82
  29. package/lib/cjs/shapes/SHACL.js.map +1 -1
  30. package/lib/cjs/shapes/Shape.d.ts +10 -11
  31. package/lib/cjs/shapes/Shape.js +5 -11
  32. package/lib/cjs/shapes/Shape.js.map +1 -1
  33. package/lib/cjs/test-helpers/query-fixtures.d.ts +88 -671
  34. package/lib/cjs/test-helpers/query-fixtures.js +1 -39
  35. package/lib/cjs/test-helpers/query-fixtures.js.map +1 -1
  36. package/lib/cjs/utils/LinkedStorage.d.ts +7 -7
  37. package/lib/cjs/utils/LinkedStorage.js +3 -4
  38. package/lib/cjs/utils/LinkedStorage.js.map +1 -1
  39. package/lib/esm/index.js +0 -2
  40. package/lib/esm/index.js.map +1 -1
  41. package/lib/esm/interfaces/IQuadStore.d.ts +7 -19
  42. package/lib/esm/interfaces/IQueryParser.d.ts +13 -0
  43. package/lib/esm/interfaces/IQueryParser.js +7 -0
  44. package/lib/esm/interfaces/IQueryParser.js.map +1 -0
  45. package/lib/esm/queries/CreateQuery.d.ts +8 -7
  46. package/lib/esm/queries/CreateQuery.js +4 -4
  47. package/lib/esm/queries/CreateQuery.js.map +1 -1
  48. package/lib/esm/queries/DeleteQuery.d.ts +8 -7
  49. package/lib/esm/queries/DeleteQuery.js +4 -4
  50. package/lib/esm/queries/DeleteQuery.js.map +1 -1
  51. package/lib/esm/queries/QueryFactory.d.ts +2 -0
  52. package/lib/esm/queries/QueryFactory.js +3 -0
  53. package/lib/esm/queries/QueryFactory.js.map +1 -1
  54. package/lib/esm/queries/QueryParser.d.ts +1 -6
  55. package/lib/esm/queries/QueryParser.js +23 -14
  56. package/lib/esm/queries/QueryParser.js.map +1 -1
  57. package/lib/esm/queries/SelectQuery.d.ts +27 -18
  58. package/lib/esm/queries/SelectQuery.js +45 -54
  59. package/lib/esm/queries/SelectQuery.js.map +1 -1
  60. package/lib/esm/queries/UpdateQuery.d.ts +9 -8
  61. package/lib/esm/queries/UpdateQuery.js +4 -4
  62. package/lib/esm/queries/UpdateQuery.js.map +1 -1
  63. package/lib/esm/shapes/SHACL.d.ts +0 -1
  64. package/lib/esm/shapes/SHACL.js +2 -82
  65. package/lib/esm/shapes/SHACL.js.map +1 -1
  66. package/lib/esm/shapes/Shape.d.ts +10 -11
  67. package/lib/esm/shapes/Shape.js +5 -11
  68. package/lib/esm/shapes/Shape.js.map +1 -1
  69. package/lib/esm/test-helpers/query-fixtures.d.ts +88 -671
  70. package/lib/esm/test-helpers/query-fixtures.js +0 -38
  71. package/lib/esm/test-helpers/query-fixtures.js.map +1 -1
  72. package/lib/esm/utils/LinkedStorage.d.ts +7 -7
  73. package/lib/esm/utils/LinkedStorage.js +3 -4
  74. package/lib/esm/utils/LinkedStorage.js.map +1 -1
  75. package/package.json +1 -1
  76. package/lib/cjs/queries/IRAliasScope.d.ts +0 -20
  77. package/lib/cjs/queries/IRAliasScope.js +0 -52
  78. package/lib/cjs/queries/IRAliasScope.js.map +0 -1
  79. package/lib/cjs/queries/IRCanonicalize.d.ts +0 -36
  80. package/lib/cjs/queries/IRCanonicalize.js +0 -112
  81. package/lib/cjs/queries/IRCanonicalize.js.map +0 -1
  82. package/lib/cjs/queries/IRDesugar.d.ts +0 -98
  83. package/lib/cjs/queries/IRDesugar.js +0 -244
  84. package/lib/cjs/queries/IRDesugar.js.map +0 -1
  85. package/lib/cjs/queries/IRLower.d.ts +0 -8
  86. package/lib/cjs/queries/IRLower.js +0 -238
  87. package/lib/cjs/queries/IRLower.js.map +0 -1
  88. package/lib/cjs/queries/IRMutation.d.ts +0 -23
  89. package/lib/cjs/queries/IRMutation.js +0 -77
  90. package/lib/cjs/queries/IRMutation.js.map +0 -1
  91. package/lib/cjs/queries/IRPipeline.d.ts +0 -8
  92. package/lib/cjs/queries/IRPipeline.js +0 -25
  93. package/lib/cjs/queries/IRPipeline.js.map +0 -1
  94. package/lib/cjs/queries/IRProjection.d.ts +0 -27
  95. package/lib/cjs/queries/IRProjection.js +0 -84
  96. package/lib/cjs/queries/IRProjection.js.map +0 -1
  97. package/lib/cjs/queries/IntermediateRepresentation.d.ts +0 -200
  98. package/lib/cjs/queries/IntermediateRepresentation.js +0 -3
  99. package/lib/cjs/queries/IntermediateRepresentation.js.map +0 -1
  100. package/lib/cjs/test-helpers/query-capture-store.d.ts +0 -5
  101. package/lib/cjs/test-helpers/query-capture-store.js +0 -59
  102. package/lib/cjs/test-helpers/query-capture-store.js.map +0 -1
  103. package/lib/esm/queries/IRAliasScope.d.ts +0 -20
  104. package/lib/esm/queries/IRAliasScope.js +0 -47
  105. package/lib/esm/queries/IRAliasScope.js.map +0 -1
  106. package/lib/esm/queries/IRCanonicalize.d.ts +0 -36
  107. package/lib/esm/queries/IRCanonicalize.js +0 -107
  108. package/lib/esm/queries/IRCanonicalize.js.map +0 -1
  109. package/lib/esm/queries/IRDesugar.d.ts +0 -98
  110. package/lib/esm/queries/IRDesugar.js +0 -240
  111. package/lib/esm/queries/IRDesugar.js.map +0 -1
  112. package/lib/esm/queries/IRLower.d.ts +0 -8
  113. package/lib/esm/queries/IRLower.js +0 -234
  114. package/lib/esm/queries/IRLower.js.map +0 -1
  115. package/lib/esm/queries/IRMutation.d.ts +0 -23
  116. package/lib/esm/queries/IRMutation.js +0 -71
  117. package/lib/esm/queries/IRMutation.js.map +0 -1
  118. package/lib/esm/queries/IRPipeline.d.ts +0 -8
  119. package/lib/esm/queries/IRPipeline.js +0 -21
  120. package/lib/esm/queries/IRPipeline.js.map +0 -1
  121. package/lib/esm/queries/IRProjection.d.ts +0 -27
  122. package/lib/esm/queries/IRProjection.js +0 -78
  123. package/lib/esm/queries/IRProjection.js.map +0 -1
  124. package/lib/esm/queries/IntermediateRepresentation.d.ts +0 -200
  125. package/lib/esm/queries/IntermediateRepresentation.js +0 -2
  126. package/lib/esm/queries/IntermediateRepresentation.js.map +0 -1
  127. package/lib/esm/test-helpers/query-capture-store.d.ts +0 -5
  128. package/lib/esm/test-helpers/query-capture-store.js +0 -55
  129. package/lib/esm/test-helpers/query-capture-store.js.map +0 -1
@@ -1,71 +0,0 @@
1
- import { isSetModificationValue, } from './QueryFactory.js';
2
- const toNodeReference = (value) => ({
3
- id: value.id,
4
- });
5
- const toSetModification = (value) => {
6
- return {
7
- add: value.$add
8
- ? value.$add.map((item) => toFieldValue(item))
9
- : undefined,
10
- remove: value.$remove ? value.$remove.map((item) => toNodeReference(item)) : undefined,
11
- };
12
- };
13
- const toSingleFieldValue = (value) => {
14
- if (value === undefined) {
15
- return undefined;
16
- }
17
- if (typeof value === 'string' ||
18
- typeof value === 'number' ||
19
- typeof value === 'boolean' ||
20
- value instanceof Date) {
21
- return value;
22
- }
23
- if ('id' in value) {
24
- return toNodeReference(value);
25
- }
26
- return toNodeData(value);
27
- };
28
- const toFieldValue = (value) => {
29
- if (Array.isArray(value)) {
30
- return value.map((item) => toSingleFieldValue(item));
31
- }
32
- if (isSetModificationValue(value)) {
33
- return toSetModification(value);
34
- }
35
- return toSingleFieldValue(value);
36
- };
37
- const toFieldUpdate = (field) => {
38
- return {
39
- property: field.prop.id,
40
- value: toFieldValue(field.val),
41
- };
42
- };
43
- const toNodeData = (description) => {
44
- return Object.assign({ shape: description.shape.id, fields: description.fields.map(toFieldUpdate) }, (description.__id ? { id: description.__id } : {}));
45
- };
46
- /** Builds an IRCreateMutation from a create factory's internal description. */
47
- export const buildCanonicalCreateMutationIR = (query) => {
48
- return {
49
- kind: 'create',
50
- shape: query.shape.id,
51
- data: toNodeData(query.description),
52
- };
53
- };
54
- /** Builds an IRUpdateMutation from an update factory's internal description. */
55
- export const buildCanonicalUpdateMutationIR = (query) => {
56
- return {
57
- kind: 'update',
58
- shape: query.shape.id,
59
- id: query.id,
60
- data: toNodeData(query.updates),
61
- };
62
- };
63
- /** Builds an IRDeleteMutation from a delete factory's internal description. */
64
- export const buildCanonicalDeleteMutationIR = (query) => {
65
- return {
66
- kind: 'delete',
67
- shape: query.shape.id,
68
- ids: query.ids.map((id) => ({ id: id.id })),
69
- };
70
- };
71
- //# sourceMappingURL=IRMutation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRMutation.js","sourceRoot":"","sources":["../../../src/queries/IRMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAML,sBAAsB,GACvB,MAAM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C,CAAC;AAEF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,KAA0B,EACR,EAAE;IACpB,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;QACrB,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAC,CAAC,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { RawSelectInput } from './IRDesugar.js';
2
- import { IRSelectQuery } from './IntermediateRepresentation.js';
3
- /**
4
- * Runs the full select pipeline: desugar → canonicalize → lower.
5
- * Accepts either a RawSelectInput (from a query factory) or an already-built
6
- * IRSelectQuery (returned as-is).
7
- */
8
- export declare const buildSelectQuery: (query: RawSelectInput | IRSelectQuery) => IRSelectQuery;
@@ -1,21 +0,0 @@
1
- import { desugarSelectQuery } from './IRDesugar.js';
2
- import { canonicalizeDesugaredSelectQuery } from './IRCanonicalize.js';
3
- import { lowerSelectQuery } from './IRLower.js';
4
- const isIRSelectQuery = (query) => !!query &&
5
- typeof query === 'object' &&
6
- 'kind' in query &&
7
- query.kind === 'select';
8
- /**
9
- * Runs the full select pipeline: desugar → canonicalize → lower.
10
- * Accepts either a RawSelectInput (from a query factory) or an already-built
11
- * IRSelectQuery (returned as-is).
12
- */
13
- export const buildSelectQuery = (query) => {
14
- if (isIRSelectQuery(query)) {
15
- return query;
16
- }
17
- const desugared = desugarSelectQuery(query);
18
- const canonical = canonicalizeDesugaredSelectQuery(desugared);
19
- return lowerSelectQuery(canonical);
20
- };
21
- //# sourceMappingURL=IRPipeline.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRPipeline.js","sourceRoot":"","sources":["../../../src/queries/IRPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAiB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAC,gCAAgC,EAAC,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAG9C,MAAM,eAAe,GAAG,CAAC,KAAc,EAA0B,EAAE,CACjE,CAAC,CAAC,KAAK;IACP,OAAO,KAAK,KAAK,QAAQ;IACzB,MAAM,IAAI,KAAK;IACd,KAAuB,CAAC,IAAI,KAAK,QAAQ,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAqC,EAAiB,EAAE;IACvF,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,kBAAkB,CAAC,KAAuB,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC,CAAC"}
@@ -1,27 +0,0 @@
1
- import { DesugaredSelectionPath } from './IRDesugar.js';
2
- import { IRAliasScope } from './IRAliasScope.js';
3
- import { IRExpression, IRProjectionItem, IRResultMapEntry } from './IntermediateRepresentation.js';
4
- export type ProjectionPathLoweringOptions = {
5
- rootAlias: string;
6
- resolveTraversal: (fromAlias: string, propertyShapeId: string) => string;
7
- };
8
- export type CanonicalProjectionResult = {
9
- projection: IRProjectionItem[];
10
- resultMap?: IRResultMapEntry[];
11
- };
12
- export type ProjectionPathInput = DesugaredSelectionPath | {
13
- path: DesugaredSelectionPath;
14
- key?: string;
15
- };
16
- /** Derives a result key name from the last step of a selection path. */
17
- export declare const projectionKeyFromPath: (path: DesugaredSelectionPath) => string;
18
- /**
19
- * Lowers a single desugared selection path into an IR expression,
20
- * creating traversal aliases for intermediate property steps.
21
- */
22
- export declare const lowerSelectionPathExpression: (path: DesugaredSelectionPath, options: ProjectionPathLoweringOptions) => IRExpression;
23
- /**
24
- * Builds projection items and a result map from an array of selection paths.
25
- * Each path gets a unique alias and is lowered into an IR expression.
26
- */
27
- export declare const buildCanonicalProjection: (selections: ProjectionPathInput[], options: ProjectionPathLoweringOptions, scope?: IRAliasScope) => CanonicalProjectionResult;
@@ -1,78 +0,0 @@
1
- import { IRAliasScope } from './IRAliasScope.js';
2
- /** Derives a result key name from the last step of a selection path. */
3
- export const projectionKeyFromPath = (path) => {
4
- if (!path.steps.length)
5
- return 'value';
6
- const lastStep = path.steps[path.steps.length - 1];
7
- if (lastStep.kind === 'property_step')
8
- return lastStep.propertyShapeId;
9
- if (lastStep.kind === 'count_step')
10
- return lastStep.label || 'count';
11
- if (lastStep.kind === 'type_cast_step')
12
- return lastStep.shapeId;
13
- return 'value';
14
- };
15
- /**
16
- * Lowers a single desugared selection path into an IR expression,
17
- * creating traversal aliases for intermediate property steps.
18
- */
19
- export const lowerSelectionPathExpression = (path, options) => {
20
- if (path.steps.length === 0) {
21
- return { kind: 'alias_expr', alias: options.rootAlias };
22
- }
23
- let currentAlias = options.rootAlias;
24
- for (let i = 0; i < path.steps.length; i++) {
25
- const step = path.steps[i];
26
- const isLast = i === path.steps.length - 1;
27
- if (step.kind === 'property_step') {
28
- if (isLast) {
29
- return {
30
- kind: 'property_expr',
31
- sourceAlias: currentAlias,
32
- property: step.propertyShapeId,
33
- };
34
- }
35
- currentAlias = options.resolveTraversal(currentAlias, step.propertyShapeId);
36
- continue;
37
- }
38
- if (step.kind === 'count_step') {
39
- return {
40
- kind: 'aggregate_expr',
41
- name: 'count',
42
- args: step.path.map((propertyStep) => ({
43
- kind: 'property_expr',
44
- sourceAlias: currentAlias,
45
- property: propertyStep.propertyShapeId,
46
- })),
47
- };
48
- }
49
- }
50
- return { kind: 'alias_expr', alias: currentAlias };
51
- };
52
- /**
53
- * Builds projection items and a result map from an array of selection paths.
54
- * Each path gets a unique alias and is lowered into an IR expression.
55
- */
56
- export const buildCanonicalProjection = (selections, options, scope = new IRAliasScope('projection')) => {
57
- const projection = [];
58
- const entries = [];
59
- selections.forEach((selection) => {
60
- const path = 'path' in selection ? selection.path : selection;
61
- const key = 'path' in selection ? selection.key : undefined;
62
- const resultKey = key || projectionKeyFromPath(path);
63
- const binding = scope.generateAlias(resultKey);
64
- projection.push({
65
- alias: binding.alias,
66
- expression: lowerSelectionPathExpression(path, options),
67
- });
68
- entries.push({
69
- key: resultKey,
70
- alias: binding.alias,
71
- });
72
- });
73
- return {
74
- projection,
75
- resultMap: entries,
76
- };
77
- };
78
- //# sourceMappingURL=IRProjection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRProjection.js","sourceRoot":"","sources":["../../../src/queries/IRProjection.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAoB/C,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAA4B,EAAU,EAAE;IAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,QAAQ,CAAC,eAAe,CAAC;IACvE,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC;IACrE,IAAI,QAAQ,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,QAAQ,CAAC,OAAO,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,IAA4B,EAC5B,OAAsC,EACxB,EAAE;IAChB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAC,IAAI,EAAE,Y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AAG,IAAI,YAAY,CAAC,YAAY,CAAC,EACX,EAAE;IAC7B,MAAM,UAAU,GAAuB,EAAE,CAAC;IAC1C,MAAM,OAAO,GAAuB,EAAE,CAAC;IAEvC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9D,MAAM,GAAG,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5D,MAAM,SAAS,GAAG,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAC/C,UAAU,CAAC,IAAI,CAAC;YACd,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,UAAU,EAAE,4BAA4B,CAAC,IAAI,EAAE,OAAO,CAAC;SACxD,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC;YACX,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,UAAU;QACV,SAAS,EAAE,OAAO;KACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -1,200 +0,0 @@
1
- import { NodeReferenceValue } from './QueryFactory.js';
2
- export type IRDirection = 'ASC' | 'DESC';
3
- export type IRAlias = string;
4
- export type IRValue = string | number | boolean | null;
5
- export type IRQuery = IRSelectQuery | IRCreateMutation | IRUpdateMutation | IRDeleteMutation;
6
- export type IRSelectQuery = {
7
- kind: 'select';
8
- root: IRShapeScanPattern;
9
- patterns: IRGraphPattern[];
10
- projection: IRProjectionItem[];
11
- where?: IRExpression;
12
- orderBy?: IROrderByItem[];
13
- limit?: number;
14
- offset?: number;
15
- subjectId?: string;
16
- singleResult?: boolean;
17
- resultMap?: IRResultMapEntry[];
18
- };
19
- export type IRProjectionItem = {
20
- alias: IRAlias;
21
- expression: IRExpression;
22
- };
23
- export type IROrderByItem = {
24
- expression: IRExpression;
25
- direction: IRDirection;
26
- };
27
- export type IRResultMapEntry = {
28
- key: string;
29
- alias: IRAlias;
30
- };
31
- export type IRGraphPattern = IRShapeScanPattern | IRTraversePattern | IRJoinPattern | IROptionalPattern | IRUnionPattern | IRExistsPattern;
32
- export type IRShapeScanPattern = {
33
- kind: 'shape_scan';
34
- shape: string;
35
- alias: IRAlias;
36
- };
37
- export type IRTraversePattern = {
38
- kind: 'traverse';
39
- from: IRAlias;
40
- to: IRAlias;
41
- property: string;
42
- };
43
- export type IRJoinPattern = {
44
- kind: 'join';
45
- patterns: IRGraphPattern[];
46
- };
47
- export type IROptionalPattern = {
48
- kind: 'optional';
49
- pattern: IRGraphPattern;
50
- };
51
- export type IRUnionPattern = {
52
- kind: 'union';
53
- branches: IRGraphPattern[];
54
- };
55
- export type IRExistsPattern = {
56
- kind: 'exists';
57
- pattern: IRGraphPattern;
58
- };
59
- export type IRExpression = IRLiteralExpression | IRAliasExpression | IRPropertyExpression | IRBinaryExpression | IRLogicalExpression | IRNotExpression | IRFunctionExpression | IRAggregateExpression | IRExistsExpression;
60
- export type IRLiteralExpression = {
61
- kind: 'literal_expr';
62
- value: IRValue;
63
- };
64
- export type IRAliasExpression = {
65
- kind: 'alias_expr';
66
- alias: IRAlias;
67
- };
68
- export type IRPropertyExpression = {
69
- kind: 'property_expr';
70
- sourceAlias: IRAlias;
71
- property: string;
72
- };
73
- export type IRBinaryOperator = '=' | '!=' | '>' | '>=' | '<' | '<=';
74
- export type IRBinaryExpression = {
75
- kind: 'binary_expr';
76
- operator: IRBinaryOperator;
77
- left: IRExpression;
78
- right: IRExpression;
79
- };
80
- export type IRLogicalOperator = 'and' | 'or';
81
- export type IRLogicalExpression = {
82
- kind: 'logical_expr';
83
- operator: IRLogicalOperator;
84
- expressions: IRExpression[];
85
- };
86
- export type IRNotExpression = {
87
- kind: 'not_expr';
88
- expression: IRExpression;
89
- };
90
- export type IRFunctionExpression = {
91
- kind: 'function_expr';
92
- name: string;
93
- args: IRExpression[];
94
- };
95
- export type IRAggregateExpression = {
96
- kind: 'aggregate_expr';
97
- name: 'count' | 'sum' | 'avg' | 'min' | 'max';
98
- args: IRExpression[];
99
- };
100
- export type IRExistsExpression = {
101
- kind: 'exists_expr';
102
- pattern: IRGraphPattern;
103
- filter?: IRExpression;
104
- };
105
- export type IRCreateMutation = {
106
- kind: 'create';
107
- shape: string;
108
- data: IRNodeData;
109
- };
110
- export type IRUpdateMutation = {
111
- kind: 'update';
112
- shape: string;
113
- id: string;
114
- data: IRNodeData;
115
- };
116
- export type IRDeleteMutation = {
117
- kind: 'delete';
118
- shape: string;
119
- ids: NodeReferenceValue[];
120
- };
121
- export type IRNodeData = {
122
- shape: string;
123
- fields: IRFieldUpdate[];
124
- id?: string;
125
- };
126
- export type IRFieldUpdate = {
127
- property: string;
128
- value: IRFieldValue;
129
- };
130
- export type IRSetModificationValue = {
131
- add?: IRFieldValue[];
132
- remove?: NodeReferenceValue[];
133
- };
134
- export type IRFieldValue = IRValue | Date | NodeReferenceValue | IRNodeData | IRSetModificationValue | IRFieldValue[] | undefined;
135
- /**
136
- * A single result row — an object with a node id and dynamic fields.
137
- * Used in select and create results.
138
- */
139
- export type ResultRow = {
140
- id: string;
141
- [key: string]: ResultFieldValue;
142
- };
143
- /**
144
- * Possible field values in a select or create result row.
145
- */
146
- export type ResultFieldValue = string | number | boolean | Date | null | undefined | ResultRow | ResultRow[];
147
- /**
148
- * What `selectQuery` should return.
149
- *
150
- * - Array of rows for multi-result queries (the default).
151
- * - A single row when `query.singleResult` is true (`.one()` or subject-targeted query).
152
- * - `null` when `singleResult` is true and the target node doesn't exist.
153
- */
154
- export type SelectResult = ResultRow[] | ResultRow | null;
155
- /**
156
- * What `createQuery` should return.
157
- *
158
- * A single row with the generated `id` and the created field values.
159
- * Nested creates appear as nested `ResultRow` objects (with their own ids).
160
- * Array fields (e.g. friends) appear as `ResultRow[]`.
161
- */
162
- export type CreateResult = ResultRow;
163
- /**
164
- * When a set property is fully overwritten, the result contains `updatedTo`
165
- * with the new complete set of values.
166
- */
167
- export type SetOverwriteResult = {
168
- updatedTo: ResultRow[];
169
- };
170
- /**
171
- * When a set property is incrementally modified with `{add, remove}`,
172
- * the result contains the added and removed entries.
173
- */
174
- export type SetModificationResult = {
175
- added: ResultRow[];
176
- removed: ResultRow[];
177
- };
178
- /**
179
- * Possible field values in an update result row.
180
- * Extends `ResultFieldValue` with set modification shapes.
181
- */
182
- export type UpdateFieldValue = ResultFieldValue | SetOverwriteResult | SetModificationResult;
183
- /**
184
- * What `updateQuery` should return.
185
- *
186
- * A single row with the target node's `id` and only the changed fields.
187
- * Fields not included in the update are omitted (not returned).
188
- *
189
- * Field value shapes depend on the type of update:
190
- * - Literal fields: the new value (string, number, boolean, Date).
191
- * - Single object fields: a `ResultRow` with the referenced/created node.
192
- * - Set overwrite (passing an array): `{updatedTo: ResultRow[]}`.
193
- * - Set add/remove (passing `{add, remove}`): `{added: ResultRow[], removed: ResultRow[]}`.
194
- * - Unset single field (passing `undefined` or `null`): field is `undefined`.
195
- * - Unset multi-value field (passing `undefined`): empty array `[]`.
196
- */
197
- export type UpdateResult = {
198
- id: string;
199
- [key: string]: UpdateFieldValue;
200
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntermediateRepresentation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntermediateRepresentation.js","sourceRoot":"","sources":["../../../src/queries/IntermediateRepresentation.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- /**
2
- * Execute a query-producing callback and return whatever
3
- * the capture intercepted.
4
- */
5
- export declare const captureQuery: (runner: () => Promise<unknown>) => Promise<any>;
@@ -1,55 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jest } from '@jest/globals';
11
- import { QueryParser } from '../queries/QueryParser';
12
- import { UpdateQueryFactory } from '../queries/UpdateQuery';
13
- import { CreateQueryFactory } from '../queries/CreateQuery';
14
- import { DeleteQueryFactory } from '../queries/DeleteQuery';
15
- /**
16
- * Test utility that intercepts QueryParser methods via jest.spyOn and captures
17
- * the query object for inspection by test assertions.
18
- *
19
- * For select queries, captures the RawSelectInput (pipeline input format).
20
- * For mutations, captures the IR (canonical format).
21
- *
22
- * Import this module and call `captureQuery(runner)` to execute a DSL
23
- * call (e.g. Person.select(...)) and retrieve the captured query.
24
- */
25
- let _lastQuery;
26
- jest.spyOn(QueryParser, 'selectQuery').mockImplementation((query) => __awaiter(void 0, void 0, void 0, function* () {
27
- _lastQuery = query.toRawInput();
28
- return [];
29
- }));
30
- jest.spyOn(QueryParser, 'createQuery').mockImplementation((updateObjectOrFn, shapeClass) => __awaiter(void 0, void 0, void 0, function* () {
31
- const factory = new CreateQueryFactory(shapeClass, updateObjectOrFn);
32
- _lastQuery = factory.build();
33
- return {};
34
- }));
35
- jest.spyOn(QueryParser, 'updateQuery').mockImplementation((id, updateObjectOrFn, shapeClass) => __awaiter(void 0, void 0, void 0, function* () {
36
- const factory = new UpdateQueryFactory(shapeClass, id, updateObjectOrFn);
37
- _lastQuery = factory.build();
38
- return {};
39
- }));
40
- jest.spyOn(QueryParser, 'deleteQuery').mockImplementation((id, shapeClass) => __awaiter(void 0, void 0, void 0, function* () {
41
- const ids = (Array.isArray(id) ? id : [id]);
42
- const factory = new DeleteQueryFactory(shapeClass, ids);
43
- _lastQuery = factory.build();
44
- return { deleted: [], count: 0 };
45
- }));
46
- /**
47
- * Execute a query-producing callback and return whatever
48
- * the capture intercepted.
49
- */
50
- export const captureQuery = (runner) => __awaiter(void 0, void 0, void 0, function* () {
51
- _lastQuery = undefined;
52
- yield runner();
53
- return _lastQuery;
54
- });
55
- //# sourceMappingURL=query-capture-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-capture-store.js","sourceRoot":"","sources":["../../../src/test-helpers/query-capture-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAG1D;;;;;;;;;GASG;AACH,IAAI,UAAe,CAAC;AAEpB,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,kBAAkB,CAAC,CAAO,KAAU,EAAE,EAAE;IAC7E,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IAChC,OAAO,EAAS,CAAC;AACnB,CAAC,CAAA,CAAC,CAAC;AAEH,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,kBAAkB,CACvD,CAAO,gBAAqB,EAAE,UAAe,EAAE,EAAE;IAC/C,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACrE,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7B,OAAO,EAAS,CAAC;AACnB,CAAC,CAAA,CACF,CAAC;AAEF,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,kBAAk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