grafast 0.1.1-beta.2 → 0.1.1-beta.21

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 (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
@@ -1,23 +1,23 @@
1
- import type { ExecutionExtra, GrafastResultsList, InputStep } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
1
+ import type { ExecutionDetails, GrafastResultsList, Maybe, UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
4
4
  type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never[];
5
5
  /**
6
6
  * Describes what a plan needs to implement in order to be suitable for
7
7
  * supplying what the `PageInfo` type requires.
8
8
  */
9
- export interface PageInfoCapableStep extends ExecutableStep {
10
- hasNextPage(): ExecutableStep<boolean>;
11
- hasPreviousPage(): ExecutableStep<boolean>;
12
- startCursor(): ExecutableStep<string | null>;
13
- endCursor(): ExecutableStep<string | null>;
9
+ export interface PageInfoCapableStep extends Step {
10
+ hasNextPage(): Step<boolean>;
11
+ hasPreviousPage(): Step<boolean>;
12
+ startCursor(): Step<string | null>;
13
+ endCursor(): Step<string | null>;
14
14
  }
15
- export declare function assertPageInfoCapableStep($step: ExecutableStep | PageInfoCapableStep): asserts $step is PageInfoCapableStep;
15
+ export declare function assertPageInfoCapableStep($step: Step | PageInfoCapableStep): asserts $step is PageInfoCapableStep;
16
16
  /**
17
17
  * Describes what a plan needs to implement in order to be suitable for
18
18
  * supplying what a ConnectionStep requires.
19
19
  */
20
- export interface ConnectionCapableStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep> extends ExecutableStep<ReadonlyArray<TItemStep extends ExecutableStep<infer U> ? U : any>> {
20
+ export interface ConnectionCapableStep<TItemStep extends Step, TCursorStep extends Step> extends Step {
21
21
  /**
22
22
  * Clone the plan; it's recommended that you add `$connection` as a
23
23
  * dependency so that you can abort execution early in the case of errors
@@ -25,20 +25,19 @@ export interface ConnectionCapableStep<TItemStep extends ExecutableStep, TCursor
25
25
  */
26
26
  connectionClone($connection: ConnectionStep<TItemStep, TCursorStep, any, any>, ...args: any[]): ConnectionCapableStep<TItemStep, TCursorStep>;
27
27
  pageInfo($connection: ConnectionStep<TItemStep, TCursorStep, ConnectionCapableStep<TItemStep, TCursorStep>, any>): PageInfoCapableStep;
28
- setFirst($plan: InputStep): void;
29
- setLast($plan: InputStep): void;
30
- setOffset($plan: InputStep): void;
31
- parseCursor($plan: InputStep): TCursorStep | null | undefined;
32
- setBefore($plan: TCursorStep): void;
33
- setAfter($plan: TCursorStep): void;
28
+ setFirst($first: Step<Maybe<number>>): void;
29
+ setLast($last: Step<Maybe<number>>): void;
30
+ setOffset($offset: Step<Maybe<number>>): void;
31
+ parseCursor($cursor: Step<Maybe<string>>): TCursorStep;
32
+ setBefore($before: TCursorStep): void;
33
+ setAfter($after: TCursorStep): void;
34
+ items(): Step<ReadonlyArray<TItemStep extends Step<infer U> ? U : any>>;
34
35
  }
35
36
  /**
36
37
  * Handles GraphQL cursor pagination in a standard and consistent way
37
38
  * indepdenent of data source.
38
39
  */
39
- export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TNodeStep extends ExecutableStep = ExecutableStep> extends UnbatchedExecutableStep<unknown> {
40
- readonly itemPlan?: (($item: TItemStep) => TNodeStep) | undefined;
41
- readonly cursorPlan?: (($item: TItemStep) => ExecutableStep<string | null> | undefined) | undefined;
40
+ export declare class ConnectionStep<TItemStep extends Step, TCursorStep extends Step, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TEdgeDataStep extends Step = TItemStep, TNodeStep extends Step = Step> extends UnbatchedStep<unknown> {
42
41
  static $$export: {
43
42
  moduleName: string;
44
43
  exportName: string;
@@ -50,18 +49,23 @@ export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorSte
50
49
  private _offsetDepId;
51
50
  private _beforeDepId;
52
51
  private _afterDepId;
53
- constructor(subplan: TStep, itemPlan?: (($item: TItemStep) => TNodeStep) | undefined, cursorPlan?: (($item: TItemStep) => ExecutableStep<string | null> | undefined) | undefined);
52
+ /** Plan for data to associate with the edge */
53
+ readonly edgeDataPlan?: ($item: TItemStep) => TEdgeDataStep;
54
+ /** The node plan */
55
+ readonly itemPlan?: ($item: TItemStep) => TNodeStep;
56
+ readonly cursorPlan?: ($item: TItemStep) => Step<string | null> | undefined;
57
+ constructor(subplan: TStep, config?: ConnectionConfig<TItemStep, TEdgeDataStep, TNodeStep>);
54
58
  toStringMeta(): string;
55
- getFirst(): InputStep | null;
56
- setFirst($firstPlan: InputStep): void;
57
- getLast(): InputStep | null;
58
- setLast($lastPlan: InputStep): void;
59
- getOffset(): InputStep | null;
60
- setOffset($offsetPlan: InputStep): void;
59
+ getFirst(): Step<number | null | undefined> | null;
60
+ setFirst(first: Step<number | null | undefined> | number): void;
61
+ getLast(): Step<number | null | undefined> | null;
62
+ setLast(last: Step<number | null | undefined> | number): void;
63
+ getOffset(): Step<number | null | undefined> | null;
64
+ setOffset(offset: Step<number | null | undefined> | number): void;
61
65
  getBefore(): TCursorStep | null;
62
- setBefore($beforePlan: InputStep): void;
66
+ setBefore($beforePlan: Step<string | null | undefined>): void;
63
67
  getAfter(): TCursorStep | null;
64
- setAfter($afterPlan: InputStep): void;
68
+ setAfter($afterPlan: Step<string | null | undefined>): void;
65
69
  /**
66
70
  * This should not be called after the arguments have been finalized.
67
71
  */
@@ -91,20 +95,21 @@ export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorSte
91
95
  * to add a dependency to us, which is typically useful for adding validation
92
96
  * functions so that they are thrown "earlier", avoiding error bubbling.
93
97
  */
94
- addValidation(callback: () => ExecutableStep): void;
95
- edges(): ExecutableStep;
96
- nodes(): TStep | import("./listTransform.js").__ListTransformStep<any, any, any, any>;
97
- wrapEdge($edge: TItemStep): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep>;
98
+ addValidation(callback: () => Step): void;
99
+ get(fieldName: string): Step<any> | undefined;
100
+ edges(): Step;
101
+ nodes(): import("./listTransform.js").__ListTransformStep<any, any, any, any> | TStep;
102
+ wrapEdge($edge: TItemStep): EdgeStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>;
98
103
  pageInfo(): PageInfoCapableStep;
99
- execute(count: number): GrafastResultsList<Record<string, never>>;
104
+ execute({ count, }: ExecutionDetails): GrafastResultsList<Record<string, never>>;
100
105
  unbatchedExecute(): any;
101
106
  }
102
- export interface EdgeCapableStep<TNodeStep extends ExecutableStep> extends ExecutableStep {
107
+ export interface EdgeCapableStep<TNodeStep extends Step> extends Step {
103
108
  node(): TNodeStep;
104
- cursor(): ExecutableStep<string | null>;
109
+ cursor(): Step<string | null>;
105
110
  }
106
- export declare function assertEdgeCapableStep<TNodeStep extends ExecutableStep>($step: ExecutableStep | EdgeCapableStep<TNodeStep>): asserts $step is EdgeCapableStep<TNodeStep>;
107
- export declare class EdgeStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TNodeStep extends ExecutableStep = ExecutableStep> extends UnbatchedExecutableStep implements EdgeCapableStep<TNodeStep> {
111
+ export declare function assertEdgeCapableStep<TNodeStep extends Step>($step: Step | EdgeCapableStep<TNodeStep>): asserts $step is EdgeCapableStep<TNodeStep>;
112
+ export declare class EdgeStep<TItemStep extends Step, TCursorStep extends Step, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TEdgeDataStep extends Step = TItemStep, TNodeStep extends Step = Step> extends UnbatchedStep implements EdgeCapableStep<TNodeStep> {
108
113
  private skipCursor;
109
114
  static $$export: {
110
115
  moduleName: string;
@@ -114,20 +119,29 @@ export declare class EdgeStep<TItemStep extends ExecutableStep, TCursorStep exte
114
119
  private connectionDepId;
115
120
  private readonly cursorDepId;
116
121
  private needCursor;
117
- constructor($connection: ConnectionStep<TItemStep, TCursorStep, TStep, TNodeStep>, $item: TItemStep, skipCursor?: boolean);
122
+ constructor($connection: ConnectionStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>, $item: TItemStep, skipCursor?: boolean);
123
+ get(fieldName: string): Step<string | null> | TNodeStep | undefined;
118
124
  private getConnectionStep;
119
125
  private getItemStep;
126
+ data(): TEdgeDataStep;
120
127
  node(): TNodeStep;
121
- cursor(): ExecutableStep<string | null>;
122
- optimize(): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep>;
128
+ cursor(): Step<string | null>;
129
+ optimize(): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep, Step<any>>;
123
130
  deduplicate(_peers: EdgeStep<any, any, any, any>[]): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep>[];
124
131
  deduplicatedWith(replacement: EdgeStep<any, any, any, any>): void;
125
- unbatchedExecute(_extra: ExecutionExtra, record: any, cursor: any): any;
132
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, record: any, cursor: any): any;
133
+ }
134
+ interface ConnectionConfig<TItemStep extends Step, TEdgeDataStep extends Step = TItemStep, TNodeStep extends Step = Step> {
135
+ nodePlan?: ($item: TItemStep) => TNodeStep;
136
+ edgeDataPlan?: ($item: TItemStep) => TEdgeDataStep;
137
+ cursorPlan?: ($item: TItemStep) => Step<string | null>;
126
138
  }
127
139
  /**
128
140
  * Wraps a collection fetch to provide the utilities for working with GraphQL
129
141
  * cursor connections.
130
142
  */
131
- export declare function connection<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TNodeStep extends ExecutableStep = ExecutableStep>(step: TStep, itemPlan?: ($item: TItemStep) => TNodeStep, cursorPlan?: ($item: TItemStep) => ExecutableStep<string | null>): ConnectionStep<TItemStep, TCursorStep, TStep, TNodeStep>;
143
+ export declare function connection<TItemStep extends Step, TCursorStep extends Step, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TEdgeDataStep extends Step = TItemStep, TNodeStep extends Step = Step>(step: TStep, config?: ConnectionConfig<TItemStep, TEdgeDataStep, TNodeStep>): ConnectionStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>;
144
+ export type ItemsStep<T extends Step<readonly any[]> | ConnectionCapableStep<any, any>> = T extends ConnectionCapableStep<any, any> ? ReturnType<T["items"]> : T;
145
+ export declare function itemsOrStep<T extends Step<readonly any[]> | ConnectionCapableStep<any, any>>($step: T): Step<readonly any[]>;
132
146
  export {};
133
147
  //# sourceMappingURL=connection.d.ts.map
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.connection = exports.EdgeStep = exports.assertEdgeCapableStep = exports.ConnectionStep = exports.assertPageInfoCapableStep = void 0;
3
+ exports.EdgeStep = exports.ConnectionStep = void 0;
4
+ exports.assertPageInfoCapableStep = assertPageInfoCapableStep;
5
+ exports.assertEdgeCapableStep = assertEdgeCapableStep;
6
+ exports.connection = connection;
7
+ exports.itemsOrStep = itemsOrStep;
4
8
  const tslib_1 = require("tslib");
5
9
  const assert = tslib_1.__importStar(require("../assert.js"));
6
10
  const step_js_1 = require("../step.js");
7
11
  const utils_js_1 = require("../utils.js");
12
+ const constant_js_1 = require("./constant.js");
8
13
  const each_js_1 = require("./each.js");
9
14
  function assertPageInfoCapableStep($step) {
10
15
  const $typed = $step;
@@ -15,22 +20,19 @@ function assertPageInfoCapableStep($step) {
15
20
  throw new Error(`Expected a PageInfoCapableStep, but found '${$step}'`);
16
21
  }
17
22
  }
18
- exports.assertPageInfoCapableStep = assertPageInfoCapableStep;
19
23
  const EMPTY_OBJECT = Object.freeze(Object.create(null));
20
24
  /**
21
25
  * Handles GraphQL cursor pagination in a standard and consistent way
22
26
  * indepdenent of data source.
23
27
  */
24
- class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
28
+ class ConnectionStep extends step_js_1.UnbatchedStep {
25
29
  static { this.$$export = {
26
30
  moduleName: "grafast",
27
31
  exportName: "ConnectionStep",
28
32
  }; }
29
- // TYPES: if subplan is `ConnectionCapableStep<EdgeCapableStep<any>>` then `itemPlan`/`cursorPlan` aren't needed; otherwise `cursorPlan` is required.
30
- constructor(subplan, itemPlan, cursorPlan) {
33
+ // TYPES: if subplan is `ConnectionCapableStep<EdgeCapableStep<any>>` then `nodePlan`/`cursorPlan` aren't needed; otherwise `cursorPlan` is required.
34
+ constructor(subplan, config = {}) {
31
35
  super();
32
- this.itemPlan = itemPlan;
33
- this.cursorPlan = cursorPlan;
34
36
  this.isSyncAndSafe = true;
35
37
  // Pagination stuff
36
38
  this._firstDepId = null;
@@ -38,8 +40,12 @@ class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
38
40
  this._offsetDepId = null;
39
41
  this._beforeDepId = undefined;
40
42
  this._afterDepId = undefined;
43
+ const { edgeDataPlan, nodePlan, cursorPlan } = config;
44
+ this.edgeDataPlan = edgeDataPlan;
45
+ this.itemPlan = nodePlan;
46
+ this.cursorPlan = cursorPlan;
41
47
  if (!cursorPlan) {
42
- // ENHANCE: Assert that the `itemPlan` has a `.cursor()` method.
48
+ // ENHANCE: Assert that the `nodePlan` has a `.cursor()` method.
43
49
  }
44
50
  // This is a _soft_ reference to the plan; we're not adding it as a
45
51
  // dependency since we do not actually need it to execute; it's our
@@ -50,65 +56,75 @@ class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
50
56
  return String(this.subplanId);
51
57
  }
52
58
  getFirst() {
53
- return this._firstDepId != null
54
- ? this.getDep(this._firstDepId)
55
- : null;
59
+ return this.maybeGetDep(this._firstDepId);
56
60
  }
57
- setFirst($firstPlan) {
61
+ setFirst(first) {
58
62
  if (this._firstDepId != null) {
59
63
  throw new Error(`${this}->setFirst already called`);
60
64
  }
61
- this._firstDepId = this.addDependency($firstPlan);
65
+ const $first = typeof first === "number" ? (0, constant_js_1.constant)(first) : first;
66
+ this._firstDepId = this.addUnaryDependency({
67
+ step: $first,
68
+ nonUnaryMessage: () => `${this}.setFirst(...) must be passed a _unary_ step, but ${$first} is not unary. See: https://err.red/gud#connection`,
69
+ });
62
70
  }
63
71
  getLast() {
64
- return this._lastDepId != null
65
- ? this.getDep(this._lastDepId)
66
- : null;
72
+ return this.maybeGetDep(this._lastDepId);
67
73
  }
68
- setLast($lastPlan) {
74
+ setLast(last) {
69
75
  if (this._lastDepId != null) {
70
76
  throw new Error(`${this}->setLast already called`);
71
77
  }
72
- this._lastDepId = this.addDependency($lastPlan);
78
+ const $last = typeof last === "number" ? (0, constant_js_1.constant)(last) : last;
79
+ this._lastDepId = this.addUnaryDependency({
80
+ step: $last,
81
+ nonUnaryMessage: () => `${this}.setLast(...) must be passed a _unary_ step, but ${$last} is not unary. See: https://err.red/gud#connection`,
82
+ });
73
83
  }
74
84
  getOffset() {
75
- return this._offsetDepId != null
76
- ? this.getDep(this._offsetDepId)
77
- : null;
85
+ return this.maybeGetDep(this._offsetDepId);
78
86
  }
79
- setOffset($offsetPlan) {
87
+ setOffset(offset) {
80
88
  if (this._offsetDepId != null) {
81
89
  throw new Error(`${this}->setOffset already called`);
82
90
  }
83
- this._offsetDepId = this.addDependency($offsetPlan);
91
+ const $offset = typeof offset === "number" ? (0, constant_js_1.constant)(offset) : offset;
92
+ this._offsetDepId = this.addUnaryDependency({
93
+ step: $offset,
94
+ nonUnaryMessage: () => `${this}.setOffset(...) must be passed a _unary_ step, but ${$offset} is not unary. See: https://err.red/gud#connection`,
95
+ });
84
96
  }
85
97
  getBefore() {
86
- return this._beforeDepId != null
87
- ? this.getDep(this._beforeDepId)
88
- : null;
98
+ return this.maybeGetDep(this._beforeDepId, true);
89
99
  }
90
100
  setBefore($beforePlan) {
101
+ if ($beforePlan instanceof constant_js_1.ConstantStep && $beforePlan.data == null) {
102
+ return;
103
+ }
91
104
  if (this._beforeDepId !== undefined) {
92
105
  throw new Error(`${this}->setBefore already called`);
93
106
  }
94
107
  const $parsedBeforePlan = this.getSubplan().parseCursor($beforePlan);
95
- this._beforeDepId = $parsedBeforePlan
96
- ? this.addDependency($parsedBeforePlan)
97
- : null;
108
+ this._beforeDepId = this.addUnaryDependency({
109
+ step: $parsedBeforePlan,
110
+ nonUnaryMessage: () => `${this}.setBefore(...) must be passed a _unary_ step, but ${$parsedBeforePlan} (and presumably ${$beforePlan}) is not unary. See: https://err.red/gud#connection`,
111
+ });
98
112
  }
99
113
  getAfter() {
100
- return this._afterDepId != null
101
- ? this.getDep(this._afterDepId)
102
- : null;
114
+ return this.maybeGetDep(this._afterDepId, true);
103
115
  }
104
116
  setAfter($afterPlan) {
117
+ if ($afterPlan instanceof constant_js_1.ConstantStep && $afterPlan.data == null) {
118
+ return;
119
+ }
105
120
  if (this._afterDepId !== undefined) {
106
121
  throw new Error(`${this}->setAfter already called`);
107
122
  }
108
123
  const $parsedAfterPlan = this.getSubplan().parseCursor($afterPlan);
109
- this._afterDepId = $parsedAfterPlan
110
- ? this.addDependency($parsedAfterPlan)
111
- : null;
124
+ this._afterDepId = this.addUnaryDependency({
125
+ step: $parsedAfterPlan,
126
+ nonUnaryMessage: () => `${this}.setAfter(...) must be passed a _unary_ step, but ${$parsedAfterPlan} (and presumably ${$afterPlan}) is not unary. See: https://err.red/gud#connection`,
127
+ });
112
128
  }
113
129
  /**
114
130
  * This should not be called after the arguments have been finalized.
@@ -192,8 +208,18 @@ class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
192
208
  this.addDependency(callback());
193
209
  });
194
210
  }
211
+ get(fieldName) {
212
+ switch (fieldName) {
213
+ case "edges":
214
+ return this.edges();
215
+ case "nodes":
216
+ return this.nodes();
217
+ case "pageInfo":
218
+ return this.pageInfo();
219
+ }
220
+ }
195
221
  edges() {
196
- if (this.cursorPlan || this.itemPlan) {
222
+ if (this.cursorPlan || this.itemPlan || this.edgeDataPlan) {
197
223
  return (0, each_js_1.each)(this.cloneSubplanWithPagination(), ($intermediate) => this.wrapEdge($intermediate));
198
224
  }
199
225
  else {
@@ -213,8 +239,7 @@ class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
213
239
  return new EdgeStep(this, $edge);
214
240
  }
215
241
  pageInfo() {
216
- const plan = this.getStep(this.subplanId);
217
- return plan.pageInfo(this);
242
+ return this.cloneSubplanWithPagination().pageInfo(this);
218
243
  }
219
244
  /*
220
245
 
@@ -225,7 +250,7 @@ class ConnectionStep extends step_js_1.UnbatchedExecutableStep {
225
250
  return constant(EMPTY_OBJECT, false);
226
251
  }
227
252
  */
228
- execute(count) {
253
+ execute({ count, }) {
229
254
  // Fake execution; data actually comes from the child plans
230
255
  return (0, utils_js_1.arrayOfLength)(count, EMPTY_OBJECT);
231
256
  }
@@ -241,8 +266,7 @@ function assertEdgeCapableStep($step) {
241
266
  throw new Error(`Expected a EdgeCapableStep, but found '${$step}'`);
242
267
  }
243
268
  }
244
- exports.assertEdgeCapableStep = assertEdgeCapableStep;
245
- class EdgeStep extends step_js_1.UnbatchedExecutableStep {
269
+ class EdgeStep extends step_js_1.UnbatchedStep {
246
270
  static { this.$$export = {
247
271
  moduleName: "grafast",
248
272
  exportName: "EdgeStep",
@@ -268,12 +292,24 @@ class EdgeStep extends step_js_1.UnbatchedExecutableStep {
268
292
  }
269
293
  this.connectionDepId = this.addDependency($connection);
270
294
  }
295
+ get(fieldName) {
296
+ switch (fieldName) {
297
+ case "node":
298
+ return this.node();
299
+ case "cursor":
300
+ return this.cursor();
301
+ }
302
+ }
271
303
  getConnectionStep() {
272
304
  return this.getDep(this.connectionDepId);
273
305
  }
274
306
  getItemStep() {
275
307
  return this.getDep(0);
276
308
  }
309
+ data() {
310
+ const $item = this.getItemStep();
311
+ return this.getConnectionStep().edgeDataPlan?.($item) ?? $item;
312
+ }
277
313
  node() {
278
314
  const $item = this.getItemStep();
279
315
  return this.getConnectionStep().itemPlan?.($item) ?? $item;
@@ -304,12 +340,29 @@ class EdgeStep extends step_js_1.UnbatchedExecutableStep {
304
340
  }
305
341
  }
306
342
  exports.EdgeStep = EdgeStep;
343
+ let warned = false;
307
344
  /**
308
345
  * Wraps a collection fetch to provide the utilities for working with GraphQL
309
346
  * cursor connections.
310
347
  */
311
- function connection(step, itemPlan, cursorPlan) {
312
- return new ConnectionStep(step, itemPlan, cursorPlan);
348
+ function connection(step, config) {
349
+ if (typeof config === "function") {
350
+ if (!warned) {
351
+ warned = true;
352
+ console.warn(`The call signature for connection() has changed, arguments after the first argument should be specified via a config object`);
353
+ }
354
+ return connection(step, {
355
+ // eslint-disable-next-line prefer-rest-params
356
+ nodePlan: arguments[1],
357
+ // eslint-disable-next-line prefer-rest-params
358
+ cursorPlan: arguments[2],
359
+ });
360
+ }
361
+ return new ConnectionStep(step, config);
362
+ }
363
+ function itemsOrStep($step) {
364
+ return "items" in $step && typeof $step.items === "function"
365
+ ? $step.items()
366
+ : $step;
313
367
  }
314
- exports.connection = connection;
315
368
  //# sourceMappingURL=connection.js.map
@@ -1,9 +1,9 @@
1
- import type { GrafastResultsList } from "../interfaces.js";
2
- import { UnbatchedExecutableStep } from "../step.js";
1
+ import type { ExecutionDetails, GrafastResultsList, JSONValue } from "../interfaces.js";
2
+ import { UnbatchedStep } from "../step.js";
3
3
  /**
4
4
  * Converts a constant value (e.g. a string/number/etc) into a plan
5
5
  */
6
- export declare class ConstantStep<TData> extends UnbatchedExecutableStep<TData> {
6
+ export declare class ConstantStep<TData> extends UnbatchedStep<TData> {
7
7
  readonly data: TData;
8
8
  readonly isSensitive: boolean;
9
9
  static $$export: {
@@ -13,14 +13,14 @@ export declare class ConstantStep<TData> extends UnbatchedExecutableStep<TData>
13
13
  isSyncAndSafe: boolean;
14
14
  constructor(data: TData, isSensitive?: boolean);
15
15
  toStringMeta(): string;
16
+ planJSONExtra(): undefined | Record<string, JSONValue>;
16
17
  deduplicate(peers: readonly ConstantStep<any>[]): ConstantStep<any>[];
17
- execute(count: number): GrafastResultsList<TData>;
18
- eval(): TData;
19
- evalIs(value: any): boolean;
20
- evalIsEmpty(): boolean;
18
+ execute({ count }: ExecutionDetails): GrafastResultsList<TData>;
21
19
  unbatchedExecute(): TData;
22
20
  isNull(): boolean;
23
21
  isUndefined(): boolean;
22
+ get(key: string): ConstantStep<any>;
23
+ at(index: number): ConstantStep<any>;
24
24
  }
25
25
  /**
26
26
  * Call this as a template string or as a function. Only intended for handling
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constant = exports.ConstantStep = void 0;
3
+ exports.ConstantStep = void 0;
4
+ exports.constant = constant;
4
5
  const inspect_js_1 = require("../inspect.js");
5
6
  const step_js_1 = require("../step.js");
6
7
  const utils_js_1 = require("../utils.js");
8
+ const index_js_1 = require("./index.js");
7
9
  /**
8
10
  * Converts a constant value (e.g. a string/number/etc) into a plan
9
11
  */
10
- class ConstantStep extends step_js_1.UnbatchedExecutableStep {
12
+ class ConstantStep extends step_js_1.UnbatchedStep {
11
13
  static { this.$$export = {
12
14
  moduleName: "grafast",
13
15
  exportName: "ConstantStep",
@@ -17,32 +19,82 @@ class ConstantStep extends step_js_1.UnbatchedExecutableStep {
17
19
  this.data = data;
18
20
  this.isSensitive = isSensitive;
19
21
  this.isSyncAndSafe = true;
22
+ const t = typeof data;
23
+ if (data == null ||
24
+ t === "boolean" ||
25
+ t === "number" ||
26
+ (t === "string" && t.length < 200)) {
27
+ this.peerKey = t + "|" + String(data);
28
+ }
20
29
  }
21
30
  toStringMeta() {
22
31
  // ENHANCE: use nicer simplification
23
32
  return this.isSensitive
24
33
  ? `[HIDDEN]`
25
- : (0, inspect_js_1.inspect)(this.data)
34
+ : (0, inspect_js_1.inspect)(this.data, {
35
+ compact: Infinity,
36
+ breakLength: Infinity,
37
+ })
26
38
  .replace(/[\r\n]/g, " ")
39
+ .replaceAll("[Object: null prototype] ", "§")
27
40
  .slice(0, 60);
28
41
  }
42
+ planJSONExtra() {
43
+ if (this.isSensitive)
44
+ return;
45
+ const data = this.data;
46
+ if (data === null) {
47
+ return {
48
+ constant: {
49
+ type: "null",
50
+ },
51
+ };
52
+ }
53
+ else if (data === undefined ||
54
+ typeof data === "boolean" ||
55
+ typeof data === "number" ||
56
+ typeof data === "string") {
57
+ return {
58
+ constant: {
59
+ type: typeof data,
60
+ },
61
+ };
62
+ }
63
+ }
29
64
  deduplicate(peers) {
30
65
  return peers.filter((p) => p.data === this.data);
31
66
  }
32
- execute(count) {
67
+ execute({ count }) {
33
68
  return (0, utils_js_1.arrayOfLength)(count, this.data);
34
69
  }
70
+ /** @internal */
35
71
  eval() {
36
72
  return this.data;
37
73
  }
74
+ /** @internal */
38
75
  evalIs(value) {
39
76
  return this.data === value;
40
77
  }
78
+ /** @internal */
41
79
  evalIsEmpty() {
42
80
  return (typeof this.data === "object" &&
43
81
  this.data !== null &&
44
82
  Object.keys(this.data).length === 0);
45
83
  }
84
+ /** @internal */
85
+ evalLength() {
86
+ return Array.isArray(this.data) ? this.data.length : null;
87
+ }
88
+ /** @internal */
89
+ evalKeys() {
90
+ if (this.data == null || typeof this.data !== "object") {
91
+ return null;
92
+ }
93
+ else {
94
+ const data = this.data;
95
+ return Object.keys(data).filter((k) => data[k] !== undefined);
96
+ }
97
+ }
46
98
  unbatchedExecute() {
47
99
  return this.data;
48
100
  }
@@ -52,6 +104,18 @@ class ConstantStep extends step_js_1.UnbatchedExecutableStep {
52
104
  isUndefined() {
53
105
  return this.data === undefined;
54
106
  }
107
+ get(key) {
108
+ const value = typeof this.data === "object" &&
109
+ this.data !== null &&
110
+ Object.hasOwn(this.data, key)
111
+ ? this.data[key]
112
+ : undefined;
113
+ return constant(value);
114
+ }
115
+ at(index) {
116
+ const value = Array.isArray(this.data) ? this.data[index] : undefined;
117
+ return constant(value);
118
+ }
55
119
  }
56
120
  exports.ConstantStep = ConstantStep;
57
121
  function isTemplateStringsArray(data) {
@@ -64,9 +128,24 @@ function constant(data, isSecret) {
64
128
  if (data.length !== 1) {
65
129
  throw new Error("constant`...` doesn't currently support placeholders; please use 'constant(`...`)' instead");
66
130
  }
67
- return new ConstantStep(data[0], false);
131
+ return constant(data[0], false);
132
+ }
133
+ const opPlan = (0, index_js_1.operationPlan)();
134
+ const makeConst = () => (0, index_js_1.operationPlan)().withRootLayerPlan(() => new ConstantStep(data, isSecret));
135
+ const t = typeof data;
136
+ if (data == null ||
137
+ t === "boolean" ||
138
+ t === "string" ||
139
+ t === "number" ||
140
+ t === "symbol") {
141
+ return opPlan.cacheStep(opPlan.contextStep, isSecret ? `constant-secret` : `constant`, data, makeConst);
142
+ }
143
+ else {
144
+ return makeConst();
68
145
  }
69
- return new ConstantStep(data, isSecret);
70
146
  }
71
- exports.constant = constant;
147
+ // Have to overwrite the getDepOrConstant method due to circular dependency
148
+ step_js_1.Step.prototype.getDepOrConstant = function (depId, fallback) {
149
+ return this.maybeGetDep(depId) ?? constant(fallback, false);
150
+ };
72
151
  //# sourceMappingURL=constant.js.map
@@ -1,9 +1,9 @@
1
- import type { ExecutableStep, ListCapableStep } from "../step.js";
1
+ import type { ListCapableStep, Step } from "../step.js";
2
2
  import { __ItemStep } from "./__item.js";
3
- import type { ConnectionCapableStep } from "./connection.js";
3
+ import type { ConnectionCapableStep, ItemsStep } from "./connection.js";
4
4
  import type { __ListTransformStep } from "./listTransform.js";
5
5
  /**
6
6
  * Transforms a list by wrapping each element in the list with the given mapper.
7
7
  */
8
- export declare function each<TListStep extends ExecutableStep<readonly any[]> & Partial<ConnectionCapableStep<any, any>>, TResultItemStep extends ExecutableStep>(listStep: TListStep, mapper: (itemPlan: TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>) => TResultItemStep): __ListTransformStep<any, any, any, any>;
8
+ export declare function each<TListStep extends (Step<readonly any[]> & Partial<ConnectionCapableStep<any, any>>) | ConnectionCapableStep<any, any>, TResultItemStep extends Step>(listStep: TListStep, mapper: (itemPlan: ItemsStep<TListStep> extends ListCapableStep<any, any> ? ReturnType<ItemsStep<TListStep>["listItem"]> : __ItemStep<any>) => TResultItemStep): __ListTransformStep<any, any, any, any>;
9
9
  //# sourceMappingURL=each.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.each = void 0;
3
+ exports.each = each;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const step_js_1 = require("../step.js");
@@ -43,7 +43,7 @@ function each(listStep, mapper) {
43
43
  const layerPlan = this.subroutineLayer;
44
44
  const rootStep = layerPlan.rootStep;
45
45
  if (rootStep instanceof __item_js_1.__ItemStep &&
46
- rootStep.dependencies[0].layerPlan !== layerPlan) {
46
+ rootStep.getParentStep().layerPlan !== layerPlan) {
47
47
  // We don't do anything; replace ourself with our parent
48
48
  return this.getListStep();
49
49
  }
@@ -60,5 +60,4 @@ function each(listStep, mapper) {
60
60
  : null),
61
61
  });
62
62
  }
63
- exports.each = each;
64
63
  //# sourceMappingURL=each.js.map