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
@@ -11,7 +11,7 @@ const { valueFromAST } = graphql;
11
11
  *
12
12
  * @see __InputDynamicScalarStep
13
13
  */
14
- class __InputStaticLeafStep extends step_js_1.UnbatchedExecutableStep {
14
+ class __InputStaticLeafStep extends step_js_1.UnbatchedStep {
15
15
  static { this.$$export = {
16
16
  moduleName: "grafast",
17
17
  exportName: "__InputStaticLeafStep",
@@ -32,9 +32,11 @@ class __InputStaticLeafStep extends step_js_1.UnbatchedExecutableStep {
32
32
  optimize() {
33
33
  return (0, constant_js_1.constant)(this.coercedValue, false);
34
34
  }
35
+ /** @internal */
35
36
  eval() {
36
37
  return this.coercedValue;
37
38
  }
39
+ /** @internal */
38
40
  evalIs(expectedValue) {
39
41
  return this.coercedValue === expectedValue;
40
42
  }
@@ -1,12 +1,13 @@
1
- import type { JSONValue } from "../index.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { $$deepDepSkip, $$noExec, UnbatchedExecutableStep } from "../step.js";
1
+ import type { GrafastResultsList, JSONValue } from "../index.js";
2
+ import { $$deepDepSkip } from "../interfaces.js";
3
+ import type { Step } from "../step.js";
4
+ import { $$noExec, UnbatchedStep } from "../step.js";
4
5
  /**
5
6
  * An __ItemStep is an internal plan (users must never construct it
6
7
  * themselves!) that Grafast uses to refer to an individual item within a list
7
8
  * or stream.
8
9
  */
9
- export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
10
+ export declare class __ItemStep<TData> extends UnbatchedStep<TData> {
10
11
  readonly depth: number;
11
12
  static $$export: {
12
13
  moduleName: string;
@@ -14,16 +15,13 @@ export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
14
15
  };
15
16
  isSyncAndSafe: boolean;
16
17
  [$$noExec]: boolean;
17
- /**
18
- * @internal
19
- */
20
- transformStepId?: number;
21
- constructor(parentPlan: ExecutableStep<TData> | ExecutableStep<TData[]>, depth?: number);
18
+ constructor(parentPlan: Step<TData> | Step<TData[]>, depth?: number);
22
19
  toStringMeta(): string;
23
20
  planJSONExtra(): Record<string, JSONValue | undefined> | undefined;
24
- [$$deepDepSkip](): ExecutableStep;
25
- execute(): never;
26
- unbatchedExecute(): never;
21
+ getParentStep(): Step;
22
+ [$$deepDepSkip](): Step;
23
+ execute(): GrafastResultsList<TData>;
24
+ unbatchedExecute(): TData;
27
25
  finalize(): void;
28
26
  }
29
27
  //# sourceMappingURL=__item.d.ts.map
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.__ItemStep = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const interfaces_js_1 = require("../interfaces.js");
7
8
  const step_js_1 = require("../step.js");
8
9
  /**
9
10
  * An __ItemStep is an internal plan (users must never construct it
10
11
  * themselves!) that Grafast uses to refer to an individual item within a list
11
12
  * or stream.
12
13
  */
13
- class __ItemStep extends step_js_1.UnbatchedExecutableStep {
14
+ class __ItemStep extends step_js_1.UnbatchedStep {
14
15
  static { this.$$export = {
15
16
  moduleName: "grafast",
16
17
  exportName: "__ItemStep",
@@ -21,6 +22,8 @@ class __ItemStep extends step_js_1.UnbatchedExecutableStep {
21
22
  this.isSyncAndSafe = true;
22
23
  this[_a] = true;
23
24
  this.addDependency(parentPlan);
25
+ this._isUnary = false;
26
+ this._isUnaryLocked = true;
24
27
  }
25
28
  toStringMeta() {
26
29
  return chalk_1.default.bold.yellow(String(this.dependencies[0].id));
@@ -30,7 +33,10 @@ class __ItemStep extends step_js_1.UnbatchedExecutableStep {
30
33
  transformStepId: this.transformStepId,
31
34
  };
32
35
  }
33
- [(_a = step_js_1.$$noExec, step_js_1.$$deepDepSkip)]() {
36
+ getParentStep() {
37
+ return this.getDep(0);
38
+ }
39
+ [(_a = step_js_1.$$noExec, interfaces_js_1.$$deepDepSkip)]() {
34
40
  return this.getDep(0);
35
41
  }
36
42
  execute() {
@@ -1,8 +1,8 @@
1
1
  import type { GraphQLInputObjectType, GraphQLInputType, VariableDefinitionNode } from "graphql";
2
2
  import { GraphQLList, GraphQLNonNull } from "graphql";
3
3
  import type { Constraint } from "../constraints.js";
4
- import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../interfaces.js";
5
- import { UnbatchedExecutableStep } from "../step.js";
4
+ import type { ExecutionDetails, GrafastResultsList, UnbatchedExecutionExtra } from "../interfaces.js";
5
+ import { UnbatchedStep } from "../step.js";
6
6
  import type { __ValueStep } from "./__value.js";
7
7
  import type { AccessStep } from "./access.js";
8
8
  /**
@@ -24,7 +24,7 @@ import type { AccessStep } from "./access.js";
24
24
  * change the query plan, but it can also be used within plan resolvers to
25
25
  * branch the logic of a plan based on something in these entities.
26
26
  */
27
- export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLInputType | ReadonlyArray<VariableDefinitionNode> | undefined = undefined> extends UnbatchedExecutableStep<TData> {
27
+ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLInputType | ReadonlyArray<VariableDefinitionNode> | undefined = undefined> extends UnbatchedStep<TData> {
28
28
  static $$export: {
29
29
  moduleName: string;
30
30
  exportName: string;
@@ -35,27 +35,16 @@ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLI
35
35
  * entries such as `pgClient`.
36
36
  */
37
37
  private readonly value;
38
- /**
39
- * A reference to the relevant
40
- * operationPlan.variableValuesConstraints/contextConstraints/rootValueConstraints.
41
- *
42
- * @internal
43
- */
44
- private readonly constraints;
45
38
  /**
46
39
  * The path that we are through the original value (the one that
47
40
  * `constraints` relates to).
48
41
  */
49
42
  private readonly path;
50
- static withGraphQLType<TInputType extends GraphQLInputType, TData = any>(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path: (string | number)[] | undefined, graphqlType: TInputType): __TrackedValueStepWithDollars<TData, TInputType>;
43
+ static withGraphQLType<TInputType extends GraphQLInputType, TData = any>(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path: Array<string | number> | undefined, graphqlType: TInputType): __TrackedValueStepWithDollars<TData, TInputType>;
51
44
  private nullableGraphQLType;
52
45
  private variableDefinitions;
53
- /**
54
- * @internal
55
- */
56
- constructor(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path?: Array<string | number>, graphqlTypeOrVariableDefinitions?: TInputType);
57
- execute(_count: number, values: [GrafastValuesList<TData>]): GrafastResultsList<TData>;
58
- unbatchedExecute(_extra: ExecutionExtra, v: TData): TData;
46
+ execute({ count, values: [values0], }: ExecutionDetails<[TData]>): GrafastResultsList<TData>;
47
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, v: TData): TData;
59
48
  private getValuePlan;
60
49
  /**
61
50
  * Get the named property of an object.
@@ -65,44 +54,7 @@ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLI
65
54
  * Get the entry at the given index in an array.
66
55
  */
67
56
  at<TIndex extends keyof TData & number>(index: TIndex): __TrackedValueStepWithDollars<TData[TIndex], TInputType extends GraphQLList<infer U> ? U & GraphQLInputType : TInputType extends GraphQLNonNull<GraphQLList<infer U>> ? U & GraphQLInputType : undefined>;
68
- /**
69
- * Evaluates the current value, and adds a constraint to the OpPlan to ensure
70
- * that all future evaluations of this property will always return the same
71
- * value.
72
- *
73
- * **WARNING**: avoid using this where possible, it causes OpPlans to split.
74
- *
75
- * **WARNING**: this is the most expensive eval, if you need to eval, prefer evalIs, evalHas, etc instead.
76
- */
77
- eval(): TData | undefined;
78
- /**
79
- * Evaluates if the current value is equal to this specific value, and adds a
80
- * constraint to the OpPlan to ensure that all future evaluations of this
81
- * check will always return the same (boolean) result.
82
- *
83
- * Should only be used on scalars.
84
- *
85
- * **WARNING**: avoid using this where possible, it causes OpPlans to split.
86
- */
87
- evalIs(expectedValue: unknown): boolean;
88
- evalIsEmpty(): boolean;
89
- /**
90
- * Evaluates if the current value is an object with the given key, and adds a
91
- * constraint to the OpPlan to ensure that all future evaluations of this
92
- * check will always return the same (boolean) result.
93
- *
94
- * **WARNING**: avoid using this where possible, it causes OpPlans to split.
95
- */
96
- evalHas(key: string): boolean;
97
- /**
98
- * Evaluates the length of the current value (assumed to be an array), and
99
- * adds a constraint to the OpPlan to ensure that all future values will have
100
- * the same length.
101
- *
102
- * **WARNING**: avoid using this where possible, it causes OpPlans to split.
103
- */
104
- evalLength(): number | null;
105
- optimize(): import("../step.js").ExecutableStep<any>;
57
+ optimize(): import("../step.js").Step<any> | import("./__flag.js").__FlagStep<import("../step.js").Step<any>>;
106
58
  }
107
59
  export type __TrackedValueStepWithDollars<TData = any, TInputType extends GraphQLInputType | undefined = undefined> = __TrackedValueStep<TData, TInputType> & (TInputType extends GraphQLInputObjectType ? {
108
60
  [key in keyof ReturnType<TInputType["getFields"]> & string as `$${key}`]: __TrackedValueStepWithDollars<TData extends {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.__TrackedValueStep = void 0;
4
4
  const graphql_1 = require("graphql");
5
+ const index_js_1 = require("../index.js");
5
6
  const step_js_1 = require("../step.js");
6
7
  /**
7
8
  * Implements the `__TrackedValueStep(operationPlan, object, constraints, path)`
@@ -22,20 +23,21 @@ const step_js_1 = require("../step.js");
22
23
  * change the query plan, but it can also be used within plan resolvers to
23
24
  * branch the logic of a plan based on something in these entities.
24
25
  */
25
- class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
26
+ class __TrackedValueStep extends step_js_1.UnbatchedStep {
26
27
  static { this.$$export = {
27
28
  moduleName: "grafast",
28
29
  exportName: "__TrackedValueStep",
29
30
  }; }
30
31
  static withGraphQLType(value, valuePlan, constraints, path = [], graphqlType) {
31
- return new __TrackedValueStep(value, valuePlan, constraints, path, graphqlType);
32
+ return (0, index_js_1.operationPlan)().withRootLayerPlan(() => new __TrackedValueStep(value, valuePlan, constraints, path, true, graphqlType));
32
33
  }
33
34
  /**
34
35
  * @internal
35
36
  */
36
- constructor(value, valuePlan, constraints, path = [], graphqlTypeOrVariableDefinitions) {
37
+ constructor(value, valuePlan, constraints, path = [], isImmutable, graphqlTypeOrVariableDefinitions) {
37
38
  super();
38
39
  this.isSyncAndSafe = true;
40
+ this._isImmutable = isImmutable;
39
41
  this.addDependency(valuePlan);
40
42
  this.value = value;
41
43
  this.constraints = constraints;
@@ -79,15 +81,17 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
79
81
  }
80
82
  }
81
83
  }
82
- execute(_count, values) {
84
+ execute({ count, values: [values0], }) {
83
85
  // We have only one dependency, return the value of that.
84
- return values[0];
86
+ return values0.isBatch
87
+ ? values0.entries
88
+ : (0, index_js_1.arrayOfLength)(count, values0.value);
85
89
  }
86
90
  unbatchedExecute(_extra, v) {
87
91
  return v;
88
92
  }
89
93
  getValuePlan() {
90
- return this.getDep(0);
94
+ return this.getDep(0, true);
91
95
  }
92
96
  /**
93
97
  * Get the named property of an object.
@@ -130,8 +134,11 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
130
134
  const type = getType(def.type);
131
135
  return __TrackedValueStep.withGraphQLType(newValue, newValuePlan, constraints, newPath, type);
132
136
  }
137
+ else if (this._isImmutable) {
138
+ return this.operationPlan.withRootLayerPlan(() => new __TrackedValueStep(newValue, newValuePlan, constraints, newPath, this._isImmutable));
139
+ }
133
140
  else {
134
- return new __TrackedValueStep(newValue, newValuePlan, constraints, newPath);
141
+ return new __TrackedValueStep(newValue, newValuePlan, constraints, newPath, this._isImmutable);
135
142
  }
136
143
  }
137
144
  /**
@@ -150,8 +157,11 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
150
157
  throw new Error(`'${this.nullableGraphQLType}' is not a list type, cannot access array index '${index}' on it`);
151
158
  }
152
159
  }
160
+ else if (this._isImmutable) {
161
+ return this.operationPlan.withRootLayerPlan(() => new __TrackedValueStep(newValue, newValuePlan, constraints, newPath, this._isImmutable));
162
+ }
153
163
  else {
154
- return new __TrackedValueStep(newValue, newValuePlan, constraints, newPath);
164
+ return new __TrackedValueStep(newValue, newValuePlan, constraints, newPath, this._isImmutable);
155
165
  }
156
166
  }
157
167
  /**
@@ -162,6 +172,8 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
162
172
  * **WARNING**: avoid using this where possible, it causes OpPlans to split.
163
173
  *
164
174
  * **WARNING**: this is the most expensive eval, if you need to eval, prefer evalIs, evalHas, etc instead.
175
+ *
176
+ * @internal
165
177
  */
166
178
  eval() {
167
179
  const { path, value } = this;
@@ -180,6 +192,8 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
180
192
  * Should only be used on scalars.
181
193
  *
182
194
  * **WARNING**: avoid using this where possible, it causes OpPlans to split.
195
+ *
196
+ * @internal
183
197
  */
184
198
  evalIs(expectedValue) {
185
199
  const { value, path } = this;
@@ -192,6 +206,7 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
192
206
  });
193
207
  return pass;
194
208
  }
209
+ /** @internal */
195
210
  evalIsEmpty() {
196
211
  const { value, path } = this;
197
212
  const isEmpty = typeof value === "object" &&
@@ -210,6 +225,8 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
210
225
  * check will always return the same (boolean) result.
211
226
  *
212
227
  * **WARNING**: avoid using this where possible, it causes OpPlans to split.
228
+ *
229
+ * @internal
213
230
  */
214
231
  evalHas(key) {
215
232
  const { value, path } = this;
@@ -228,12 +245,56 @@ class __TrackedValueStep extends step_js_1.UnbatchedExecutableStep {
228
245
  });
229
246
  return exists;
230
247
  }
248
+ /**
249
+ * Evaluates the keys of the current value, and adds a
250
+ * constraint to the OpPlan to ensure that all future evaluations of this
251
+ * check will always return the same result.
252
+ *
253
+ * **WARNING**: avoid using this where possible, it causes OpPlans to split.
254
+ *
255
+ * @internal
256
+ */
257
+ evalKeys() {
258
+ const { value, path } = this;
259
+ if (!(0, graphql_1.isInputObjectType)(this.nullableGraphQLType)) {
260
+ throw new Error("evalKeys must only be called for object types");
261
+ }
262
+ if (value == null) {
263
+ this.constraints.push({
264
+ type: "keys",
265
+ path,
266
+ keys: null,
267
+ });
268
+ return null;
269
+ }
270
+ const keys = [];
271
+ const keysOfType = Object.keys(this.nullableGraphQLType.getFields());
272
+ // NOTE: it's important that we loop through the fields in their defined
273
+ // order, this ensures the `keys` array always has consistent ordering.
274
+ for (let i = 0; i < keysOfType.length; i++) {
275
+ const key = keysOfType[i];
276
+ // NOTE: `key in value` would be more performant here, but we cannot trust
277
+ // users not to pass `{foo: undefined}` so we must do the more expensive
278
+ // `value[key] !== undefined` check.
279
+ if (value[key] !== undefined) {
280
+ keys.push(key);
281
+ }
282
+ }
283
+ this.constraints.push({
284
+ type: "keys",
285
+ path,
286
+ keys,
287
+ });
288
+ return keys;
289
+ }
231
290
  /**
232
291
  * Evaluates the length of the current value (assumed to be an array), and
233
292
  * adds a constraint to the OpPlan to ensure that all future values will have
234
293
  * the same length.
235
294
  *
236
295
  * **WARNING**: avoid using this where possible, it causes OpPlans to split.
296
+ *
297
+ * @internal
237
298
  */
238
299
  evalLength() {
239
300
  const { value, path } = this;
@@ -1,20 +1,21 @@
1
- import { $$noExec, ExecutableStep } from "../step.js";
1
+ import type { GrafastResultsList } from "../index.js";
2
+ import { $$noExec, Step } from "../step.js";
2
3
  import type { AccessStep } from "./access.js";
3
4
  /**
4
5
  * Implements `__ValueStep(operationPlan)` which is never executed; it's purely
5
6
  * internal - we populate the value as part of the algorithm - see
6
7
  * `GetValueStepId` and `PopulateValueStep`.
7
8
  */
8
- export declare class __ValueStep<TData> extends ExecutableStep<TData> {
9
+ export declare class __ValueStep<TData> extends Step<TData> {
9
10
  static $$export: {
10
11
  moduleName: string;
11
12
  exportName: string;
12
13
  };
13
14
  isSyncAndSafe: boolean;
14
15
  [$$noExec]: boolean;
15
- constructor();
16
+ constructor(isImmutable: boolean);
16
17
  toStringMeta(): string | null;
17
- execute(): never;
18
+ execute(): GrafastResultsList<TData>;
18
19
  get<TAttr extends keyof TData>(attrName: TAttr): AccessStep<TData[TAttr]>;
19
20
  at<TIndex extends keyof TData>(index: TIndex): AccessStep<TData[TIndex]>;
20
21
  }
@@ -9,16 +9,17 @@ const access_js_1 = require("./access.js");
9
9
  * internal - we populate the value as part of the algorithm - see
10
10
  * `GetValueStepId` and `PopulateValueStep`.
11
11
  */
12
- class __ValueStep extends step_js_1.ExecutableStep {
12
+ class __ValueStep extends step_js_1.Step {
13
13
  static { _a = step_js_1.$$noExec; }
14
14
  static { this.$$export = {
15
15
  moduleName: "grafast",
16
16
  exportName: "__ValueStep",
17
17
  }; }
18
- constructor() {
18
+ constructor(isImmutable) {
19
19
  super();
20
20
  this.isSyncAndSafe = true;
21
21
  this[_a] = true;
22
+ this._isImmutable = isImmutable;
22
23
  }
23
24
  toStringMeta() {
24
25
  switch (this) {
@@ -37,10 +38,10 @@ class __ValueStep extends step_js_1.ExecutableStep {
37
38
  throw new Error(`GrafastInternalError<7696a514-f452-4d47-92d3-85aeb5b23f48>: ${this} is a __ValueStep and thus must never execute`);
38
39
  }
39
40
  get(attrName) {
40
- return (0, access_js_1.access)(this, [attrName]);
41
+ return this.cacheStep("get", attrName, () => (0, access_js_1.access)(this, [attrName]));
41
42
  }
42
43
  at(index) {
43
- return (0, access_js_1.access)(this, [index]);
44
+ return this.cacheStep("at", index, () => (0, access_js_1.access)(this, [index]));
44
45
  }
45
46
  }
46
47
  exports.__ValueStep = __ValueStep;
@@ -1,8 +1,6 @@
1
- import type { ExecutionExtra } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
4
- /** @internal */
5
- export declare const expressionSymbol: unique symbol;
1
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
6
4
  /**
7
5
  * Accesses a (potentially nested) property from the result of a plan.
8
6
  *
@@ -11,8 +9,8 @@ export declare const expressionSymbol: unique symbol;
11
9
  * preferably where the objects have null prototypes, and be sure to adhere to
12
10
  * the naming conventions detailed in assertSafeToAccessViaBraces.
13
11
  */
14
- export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
15
- readonly fallback?: any;
12
+ export declare class AccessStep<TData> extends UnbatchedStep<TData> {
13
+ readonly fallback?: any | undefined;
16
14
  static $$export: {
17
15
  moduleName: string;
18
16
  exportName: string;
@@ -20,8 +18,10 @@ export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
20
18
  isSyncAndSafe: boolean;
21
19
  allowMultipleOptimizations: boolean;
22
20
  readonly path: (string | number | symbol)[];
23
- constructor(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[], fallback?: any);
21
+ private readonly hasSymbols;
22
+ constructor(parentPlan: Step<unknown>, path: (string | number | symbol)[], fallback?: any | undefined);
24
23
  toStringMeta(): string;
24
+ getParentStep(): Step<any> | import("./__flag.js").__FlagStep<Step<any>>;
25
25
  /**
26
26
  * Get the named property of an object.
27
27
  */
@@ -32,12 +32,12 @@ export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
32
32
  at<TIndex extends keyof TData>(index: TIndex): AccessStep<TData[TIndex]>;
33
33
  optimize(): AccessStep<TData>;
34
34
  finalize(): void;
35
- unbatchedExecute(_extra: ExecutionExtra, ..._values: any[]): any;
35
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, ..._values: any[]): any;
36
36
  deduplicate(peers: AccessStep<unknown>[]): AccessStep<TData>[];
37
37
  }
38
38
  /**
39
39
  * Access the property at path `path` in the value returned from `parentPlan`,
40
40
  * falling back to `fallback` if it were null-ish.
41
41
  */
42
- export declare function access<TData>(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[] | string | number | symbol, fallback?: any): AccessStep<TData>;
42
+ export declare function access<TData>(parentPlan: Step<unknown>, rawPath?: (string | number | symbol)[] | string | number | symbol, fallback?: any): AccessStep<TData>;
43
43
  //# sourceMappingURL=access.d.ts.map
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.access = exports.AccessStep = exports.expressionSymbol = void 0;
3
+ exports.AccessStep = exports.expressionSymbol = void 0;
4
+ exports.access = access;
4
5
  const tslib_1 = require("tslib");
5
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const debug_1 = tslib_1.__importDefault(require("debug"));
7
7
  const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
8
8
  const inspect_js_1 = require("../inspect.js");
9
9
  const step_js_1 = require("../step.js");
10
+ const utils_js_1 = require("../utils.js");
10
11
  /** @internal */
11
12
  exports.expressionSymbol = Symbol("expression");
12
13
  const makeDestructureCache = Object.create(null);
@@ -100,8 +101,6 @@ return (_meta, value) => value?.${tamedevil_1.default.join(access, "?.")}${fallb
100
101
  });
101
102
  }
102
103
  }
103
- const debugAccessPlan = (0, debug_1.default)("grafast:AccessStep");
104
- const debugAccessPlanVerbose = debugAccessPlan.extend("verbose");
105
104
  /**
106
105
  * Accesses a (potentially nested) property from the result of a plan.
107
106
  *
@@ -110,7 +109,7 @@ const debugAccessPlanVerbose = debugAccessPlan.extend("verbose");
110
109
  * preferably where the objects have null prototypes, and be sure to adhere to
111
110
  * the naming conventions detailed in assertSafeToAccessViaBraces.
112
111
  */
113
- class AccessStep extends step_js_1.UnbatchedExecutableStep {
112
+ class AccessStep extends step_js_1.UnbatchedStep {
114
113
  static { this.$$export = {
115
114
  moduleName: "grafast",
116
115
  exportName: "AccessStep",
@@ -120,13 +119,20 @@ class AccessStep extends step_js_1.UnbatchedExecutableStep {
120
119
  this.fallback = fallback;
121
120
  this.isSyncAndSafe = true;
122
121
  this.allowMultipleOptimizations = true;
122
+ this._isImmutable = parentPlan._isImmutable;
123
123
  this.path = path;
124
+ this.hasSymbols = this.path.some((k) => typeof k === "symbol");
125
+ this.peerKey =
126
+ (this.fallback === "undefined" ? "U" : "D") +
127
+ (this.hasSymbols ? "§" : ".") +
128
+ (0, utils_js_1.digestKeys)(this.path);
124
129
  this.addDependency(parentPlan);
125
130
  }
126
131
  toStringMeta() {
127
- return `${chalk_1.default.bold.yellow(String(this.getDep(0).id))}.${this.path
128
- .map((p) => String(p))
129
- .join(".")}`;
132
+ return `${chalk_1.default.bold.yellow(String(this.getDepOptions(0).step.id))}.${this.path.map((p) => String(p)).join(".")}`;
133
+ }
134
+ getParentStep() {
135
+ return this.getDep(0);
130
136
  }
131
137
  /**
132
138
  * Get the named property of an object.
@@ -135,7 +141,7 @@ class AccessStep extends step_js_1.UnbatchedExecutableStep {
135
141
  if (typeof attrName !== "string") {
136
142
  throw new Error(`AccessStep::get can only be called with string values`);
137
143
  }
138
- return new AccessStep(this.getDep(0), [...this.path, attrName]);
144
+ return access(this.getDep(0), [...this.path, attrName]);
139
145
  }
140
146
  /**
141
147
  * Get the entry at the given index in an array.
@@ -144,7 +150,7 @@ class AccessStep extends step_js_1.UnbatchedExecutableStep {
144
150
  if (typeof index !== "number") {
145
151
  throw new Error(`AccessStep::get can only be called with string values`);
146
152
  }
147
- return new AccessStep(this.getDep(0), [...this.path, index]);
153
+ return access(this.getDep(0), [...this.path, index]);
148
154
  }
149
155
  // An access of an access can become a single access
150
156
  optimize() {
@@ -165,10 +171,23 @@ class AccessStep extends step_js_1.UnbatchedExecutableStep {
165
171
  throw new Error(`${this}: should have had unbatchedExecute method replaced`);
166
172
  }
167
173
  deduplicate(peers) {
168
- const myPath = JSON.stringify(this.path);
169
- const peersWithSamePath = peers.filter((p) => p.fallback === this.fallback && JSON.stringify(p.path) === myPath);
170
- debugAccessPlanVerbose("%c deduplicate: peers with same path %o = %c", this, this.path, peersWithSamePath);
171
- return peersWithSamePath;
174
+ if (peers.length === 0) {
175
+ return peers;
176
+ }
177
+ else if (!this.hasSymbols && this.fallback === undefined) {
178
+ // Rely entirely on peerKey
179
+ return peers;
180
+ }
181
+ else if (!this.hasSymbols) {
182
+ // Rely on peerKey for path, but check fallback
183
+ const { fallback } = this;
184
+ return peers.filter((p) => p.fallback === fallback);
185
+ }
186
+ else {
187
+ // Check both fallback and path
188
+ const { fallback, path } = this;
189
+ return peers.filter((p) => p.fallback === fallback && (0, utils_js_1.arraysMatch)(p.path, path));
190
+ }
172
191
  }
173
192
  }
174
193
  exports.AccessStep = AccessStep;
@@ -176,8 +195,22 @@ exports.AccessStep = AccessStep;
176
195
  * Access the property at path `path` in the value returned from `parentPlan`,
177
196
  * falling back to `fallback` if it were null-ish.
178
197
  */
179
- function access(parentPlan, path, fallback) {
180
- return new AccessStep(parentPlan, Array.isArray(path) ? path : [path], fallback);
198
+ function access(parentPlan, rawPath, fallback) {
199
+ const path = Array.isArray(rawPath)
200
+ ? rawPath
201
+ : rawPath != null
202
+ ? [rawPath]
203
+ : [];
204
+ if (typeof fallback === "undefined" &&
205
+ !path.some((k) => typeof k === "symbol")) {
206
+ const pathKey = (0, utils_js_1.digestKeys)(path);
207
+ if (parentPlan._isImmutable) {
208
+ return parentPlan.operationPlan.withRootLayerPlan(() => parentPlan.operationPlan.cacheStep(parentPlan, "GrafastInternal:access()", pathKey, () => new AccessStep(parentPlan, path)));
209
+ }
210
+ else {
211
+ return parentPlan.operationPlan.cacheStep(parentPlan, "GrafastInternal:access()", pathKey, () => new AccessStep(parentPlan, path));
212
+ }
213
+ }
214
+ return new AccessStep(parentPlan, path, fallback);
181
215
  }
182
- exports.access = access;
183
216
  //# sourceMappingURL=access.js.map
@@ -0,0 +1,44 @@
1
+ import type { GraphQLInputType, GraphQLSchema } from "graphql";
2
+ import type { AnyInputStep, UnbatchedExecutionExtra } from "../interfaces.js";
3
+ import type { Step } from "../step.js";
4
+ import { UnbatchedStep } from "../step.js";
5
+ import { ConstantStep } from "./index.js";
6
+ export declare class ApplyInputStep<TParent extends object = any, TTarget extends object = TParent> extends UnbatchedStep<(arg: TParent) => void> {
7
+ private inputType;
8
+ private getTargetFromParent;
9
+ static $$export: {
10
+ moduleName: string;
11
+ exportName: string;
12
+ };
13
+ isSyncAndSafe: boolean;
14
+ allowMultipleOptimizations: boolean;
15
+ valueDepId: 0;
16
+ constructor(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent: ((parent: TParent, inputValue: any) => TTarget | undefined | (() => TTarget)) | undefined);
17
+ deduplicate(peers: readonly ApplyInputStep[]): ApplyInputStep<any, any>[];
18
+ optimize(): this | ConstantStep<(parent: TParent) => void>;
19
+ unbatchedExecute(extra: UnbatchedExecutionExtra, value: any): (parentThing: TParent) => void;
20
+ }
21
+ export declare function inputArgsApply<TArg extends object, TTarget extends object = TArg>(schema: GraphQLSchema, inputType: GraphQLInputType, parent: TArg, inputValue: unknown, getTargetFromParent: ((parent: TArg, inputValue: any) => TTarget | undefined | (() => TTarget)) | undefined): void;
22
+ export declare function applyInput<TParent extends object = any, TTarget extends object = TParent>(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent?: (parent: TParent, inputValue: any) => TTarget | undefined): ConstantStep<(parent: TParent) => void> | ApplyInputStep<TParent, TTarget>;
23
+ /**
24
+ * Modifiers modify their parent (which may be another modifier or anything
25
+ * else). First they gather all the requirements from their children (if any)
26
+ * being applied to them, then they apply themselves to their parent. This
27
+ * application is done through the `apply()` method.
28
+ */
29
+ export declare abstract class Modifier<TParent> {
30
+ protected readonly parent: TParent;
31
+ static $$export: any;
32
+ constructor(parent: TParent);
33
+ /**
34
+ * In this method, you should apply the changes to your `this.parent` plan
35
+ */
36
+ abstract apply(): void;
37
+ }
38
+ export declare function isModifier<TParent>(plan: any): plan is Modifier<TParent>;
39
+ export declare function assertModifier<TParent>(plan: any, pathDescription: string): asserts plan is Modifier<TParent>;
40
+ export type ApplyableExecutableStep<TArg extends object = any, TData = any> = Step<TData> & {
41
+ apply($apply: Step<(arg: TArg) => void>): void;
42
+ };
43
+ export declare function isApplyableStep<TArg extends object = any, TData = any>(s: Step<TData>): s is ApplyableExecutableStep<TArg, TData>;
44
+ //# sourceMappingURL=applyInput.d.ts.map