grafast 0.1.1-beta.20 → 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 (133) hide show
  1. package/dist/args.js +2 -3
  2. package/dist/assert.js +2 -3
  3. package/dist/constraints.js +1 -2
  4. package/dist/deferred.js +1 -2
  5. package/dist/dev.js +2 -2
  6. package/dist/engine/LayerPlan.d.ts +20 -16
  7. package/dist/engine/LayerPlan.js +5 -10
  8. package/dist/engine/OperationPlan.d.ts +12 -13
  9. package/dist/engine/OperationPlan.js +210 -146
  10. package/dist/engine/OutputPlan.d.ts +4 -4
  11. package/dist/engine/OutputPlan.js +13 -10
  12. package/dist/engine/StepTracker.js +11 -2
  13. package/dist/engine/executeBucket.js +135 -94
  14. package/dist/engine/executeOutputPlan.js +1 -2
  15. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  16. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  17. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -2
  18. package/dist/engine/lib/withGlobalLayerPlan.js +4 -5
  19. package/dist/engine/lock.d.ts +3 -3
  20. package/dist/engine/lock.js +3 -3
  21. package/dist/error.js +4 -4
  22. package/dist/establishOperationPlan.js +2 -3
  23. package/dist/execute.js +3 -4
  24. package/dist/exportAs.js +2 -3
  25. package/dist/global.js +2 -3
  26. package/dist/grafastGraphql.js +2 -3
  27. package/dist/grafastPrint.js +7 -8
  28. package/dist/graphqlCollectFields.js +6 -7
  29. package/dist/graphqlMergeSelectionSets.js +1 -2
  30. package/dist/index.d.ts +22 -18
  31. package/dist/index.js +41 -16
  32. package/dist/input.js +75 -28
  33. package/dist/inspect.d.ts +9 -4
  34. package/dist/inspect.js +2 -2
  35. package/dist/interfaces.d.ts +110 -89
  36. package/dist/makeGrafastSchema.d.ts +18 -9
  37. package/dist/makeGrafastSchema.js +64 -30
  38. package/dist/mermaid.js +53 -14
  39. package/dist/middleware.js +1 -2
  40. package/dist/multistep.d.ts +6 -6
  41. package/dist/multistep.js +6 -7
  42. package/dist/operationPlan-input.d.ts +5 -4
  43. package/dist/operationPlan-input.js +131 -399
  44. package/dist/planJSONInterfaces.d.ts +6 -2
  45. package/dist/polymorphic.js +4 -5
  46. package/dist/prepare.js +6 -6
  47. package/dist/step.d.ts +67 -99
  48. package/dist/step.js +99 -127
  49. package/dist/steps/__flag.d.ts +16 -16
  50. package/dist/steps/__flag.js +9 -6
  51. package/dist/steps/__inputDefault.d.ts +14 -0
  52. package/dist/steps/__inputDefault.js +48 -0
  53. package/dist/steps/__inputDynamicScalar.d.ts +2 -4
  54. package/dist/steps/__inputDynamicScalar.js +4 -2
  55. package/dist/steps/__inputList.d.ts +5 -9
  56. package/dist/steps/__inputList.js +4 -1
  57. package/dist/steps/__inputObject.d.ts +6 -11
  58. package/dist/steps/__inputObject.js +13 -3
  59. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  60. package/dist/steps/__inputStaticLeaf.js +3 -1
  61. package/dist/steps/__item.d.ts +6 -6
  62. package/dist/steps/__item.js +1 -1
  63. package/dist/steps/__trackedValue.d.ts +4 -49
  64. package/dist/steps/__trackedValue.js +24 -6
  65. package/dist/steps/__value.d.ts +3 -3
  66. package/dist/steps/__value.js +3 -2
  67. package/dist/steps/access.d.ts +7 -6
  68. package/dist/steps/access.js +14 -7
  69. package/dist/steps/applyInput.d.ts +44 -0
  70. package/dist/steps/applyInput.js +206 -0
  71. package/dist/steps/applyTransforms.d.ts +2 -2
  72. package/dist/steps/applyTransforms.js +7 -5
  73. package/dist/steps/bakedInput.d.ts +23 -0
  74. package/dist/steps/bakedInput.js +90 -0
  75. package/dist/steps/condition.d.ts +5 -5
  76. package/dist/steps/condition.js +3 -3
  77. package/dist/steps/connection.d.ts +42 -39
  78. package/dist/steps/connection.js +51 -35
  79. package/dist/steps/constant.d.ts +4 -8
  80. package/dist/steps/constant.js +54 -6
  81. package/dist/steps/each.d.ts +3 -3
  82. package/dist/steps/each.js +1 -2
  83. package/dist/steps/error.d.ts +2 -2
  84. package/dist/steps/error.js +3 -3
  85. package/dist/steps/filter.d.ts +3 -2
  86. package/dist/steps/filter.js +1 -2
  87. package/dist/steps/first.d.ts +6 -5
  88. package/dist/steps/first.js +5 -4
  89. package/dist/steps/graphqlResolver.d.ts +2 -2
  90. package/dist/steps/graphqlResolver.js +44 -56
  91. package/dist/steps/groupBy.d.ts +3 -2
  92. package/dist/steps/groupBy.js +1 -2
  93. package/dist/steps/index.d.ts +4 -2
  94. package/dist/steps/index.js +21 -9
  95. package/dist/steps/lambda.d.ts +5 -5
  96. package/dist/steps/lambda.js +4 -4
  97. package/dist/steps/last.d.ts +6 -5
  98. package/dist/steps/last.js +5 -4
  99. package/dist/steps/list.d.ts +7 -7
  100. package/dist/steps/list.js +3 -3
  101. package/dist/steps/listTransform.d.ts +14 -12
  102. package/dist/steps/listTransform.js +14 -7
  103. package/dist/steps/listen.d.ts +6 -8
  104. package/dist/steps/listen.js +7 -7
  105. package/dist/steps/load.d.ts +6 -6
  106. package/dist/steps/load.js +7 -7
  107. package/dist/steps/node.d.ts +16 -10
  108. package/dist/steps/node.js +14 -7
  109. package/dist/steps/object.d.ts +11 -11
  110. package/dist/steps/object.js +5 -5
  111. package/dist/steps/partitionByIndex.d.ts +3 -2
  112. package/dist/steps/partitionByIndex.js +1 -2
  113. package/dist/steps/polymorphicBranch.d.ts +8 -8
  114. package/dist/steps/polymorphicBranch.js +4 -4
  115. package/dist/steps/proxy.d.ts +8 -8
  116. package/dist/steps/proxy.js +3 -3
  117. package/dist/steps/remapKeys.d.ts +6 -6
  118. package/dist/steps/remapKeys.js +3 -3
  119. package/dist/steps/reverse.d.ts +5 -5
  120. package/dist/steps/reverse.js +4 -4
  121. package/dist/steps/setter.d.ts +9 -18
  122. package/dist/steps/setter.js +24 -14
  123. package/dist/steps/sideEffect.d.ts +4 -4
  124. package/dist/steps/sideEffect.js +3 -3
  125. package/dist/stringifyPayload.js +1 -2
  126. package/dist/stripAnsi.js +2 -2
  127. package/dist/subscribe.js +2 -3
  128. package/dist/timeSource.d.ts +0 -1
  129. package/dist/utils.d.ts +43 -31
  130. package/dist/utils.js +97 -61
  131. package/dist/version.d.ts +1 -1
  132. package/dist/version.js +1 -1
  133. package/package.json +2 -2
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Modifier = exports.ApplyInputStep = void 0;
4
+ exports.inputArgsApply = inputArgsApply;
5
+ exports.applyInput = applyInput;
6
+ exports.isModifier = isModifier;
7
+ exports.assertModifier = assertModifier;
8
+ exports.isApplyableStep = isApplyableStep;
9
+ const graphql_1 = require("graphql");
10
+ const step_js_1 = require("../step.js");
11
+ const index_js_1 = require("./index.js");
12
+ let currentModifiers = [];
13
+ let applyingModifiers = false;
14
+ let inputArgsApplyDepth = 0;
15
+ class ApplyInputStep extends step_js_1.UnbatchedStep {
16
+ static { this.$$export = {
17
+ moduleName: "grafast",
18
+ exportName: "ApplyInputStep",
19
+ }; }
20
+ constructor(inputType, $value, getTargetFromParent) {
21
+ super();
22
+ this.inputType = inputType;
23
+ this.getTargetFromParent = getTargetFromParent;
24
+ this.isSyncAndSafe = true;
25
+ this.allowMultipleOptimizations = true;
26
+ this.valueDepId = this.addUnaryDependency($value);
27
+ if (!this._isUnary) {
28
+ throw new Error(`applyInput() must be unary`);
29
+ }
30
+ this._isUnaryLocked = true;
31
+ }
32
+ deduplicate(peers) {
33
+ return peers.filter((p) => p.inputType === this.inputType &&
34
+ p.getTargetFromParent === this.getTargetFromParent);
35
+ }
36
+ optimize() {
37
+ const $value = this.getDep(this.valueDepId);
38
+ if ($value instanceof index_js_1.ConstantStep) {
39
+ // Replace myself with a constant!
40
+ const { operationPlan: { schema }, inputType, getTargetFromParent, } = this;
41
+ const { data } = $value;
42
+ return (0, index_js_1.constant)(function applyInputConstant(parent) {
43
+ inputArgsApply(schema, inputType, parent, data, getTargetFromParent);
44
+ }, false);
45
+ }
46
+ return this;
47
+ }
48
+ unbatchedExecute(extra, value) {
49
+ const { getTargetFromParent } = this;
50
+ return (parentThing) => inputArgsApply(this.operationPlan.schema, this.inputType, parentThing, value, getTargetFromParent);
51
+ }
52
+ }
53
+ exports.ApplyInputStep = ApplyInputStep;
54
+ function inputArgsApply(schema, inputType, parent, inputValue, getTargetFromParent) {
55
+ try {
56
+ inputArgsApplyDepth++;
57
+ const target = getTargetFromParent
58
+ ? getTargetFromParent(parent, inputValue)
59
+ : parent;
60
+ if (target != null) {
61
+ _inputArgsApply(schema, inputType, target, inputValue);
62
+ }
63
+ }
64
+ finally {
65
+ inputArgsApplyDepth--;
66
+ }
67
+ let l;
68
+ if (inputArgsApplyDepth === 0 && (l = currentModifiers.length) > 0) {
69
+ applyingModifiers = true;
70
+ try {
71
+ for (let i = l - 1; i >= 0; i--) {
72
+ currentModifiers[i].apply();
73
+ }
74
+ }
75
+ finally {
76
+ applyingModifiers = false;
77
+ currentModifiers = [];
78
+ }
79
+ }
80
+ }
81
+ function applyInput(inputType, $value, getTargetFromParent) {
82
+ const opPlan = (0, index_js_1.operationPlan)();
83
+ const { schema } = opPlan;
84
+ return opPlan.withRootLayerPlan(() => {
85
+ if ($value instanceof index_js_1.ConstantStep) {
86
+ // Replace us with a constant
87
+ const { data } = $value;
88
+ return (0, index_js_1.constant)(function applyInputConstant(parent) {
89
+ inputArgsApply(schema, inputType, parent, data, getTargetFromParent);
90
+ }, false);
91
+ }
92
+ else {
93
+ return new ApplyInputStep(inputType, $value, getTargetFromParent);
94
+ }
95
+ });
96
+ }
97
+ /*
98
+ const defaultInputObjectTypeInputPlanResolver: InputObjectTypeInputPlanResolver =
99
+ (input, info) => {
100
+ const fields = info.type.getFields();
101
+ const obj: { [key: string]: ExecutableStep } = Object.create(null);
102
+ for (const fieldName in fields) {
103
+ obj[fieldName] = input.get(fieldName);
104
+ }
105
+ return object(obj);
106
+ };
107
+ */
108
+ function _inputArgsApply(schema, inputType, target, inputValue) {
109
+ // PERF: we should have the plan generate a digest of `inputType` so that we
110
+ // can jump right to the relevant parts without too much traversal cost.
111
+ if (inputValue === undefined) {
112
+ return;
113
+ }
114
+ if ((0, graphql_1.isNonNullType)(inputType)) {
115
+ if (inputValue === null) {
116
+ throw new Error(`null value found in non-null position`);
117
+ }
118
+ _inputArgsApply(schema, inputType.ofType, target, inputValue);
119
+ }
120
+ else if ((0, graphql_1.isListType)(inputType)) {
121
+ if (inputValue == null)
122
+ return;
123
+ if (!Array.isArray(inputValue)) {
124
+ throw new Error(`Expected list in list position`);
125
+ }
126
+ for (const item of inputValue) {
127
+ const itemTarget = typeof target === "function" ? target() : target;
128
+ _inputArgsApply(schema, inputType.ofType, itemTarget, item);
129
+ }
130
+ }
131
+ else if (typeof target === "function") {
132
+ throw new Error("Functions may only be used as the target for list types (the function is called once per list item)");
133
+ }
134
+ else if ((0, graphql_1.isInputObjectType)(inputType)) {
135
+ if (inputValue === null) {
136
+ return;
137
+ }
138
+ const fields = inputType.getFields();
139
+ for (const [fieldName, field] of Object.entries(fields)) {
140
+ const val = inputValue[fieldName];
141
+ if (val === undefined)
142
+ continue;
143
+ if (field.extensions.grafast?.apply) {
144
+ const newTarget = field.extensions.grafast.apply(target, val, {
145
+ schema,
146
+ field,
147
+ fieldName,
148
+ });
149
+ if (newTarget != null) {
150
+ _inputArgsApply(schema, field.type, newTarget, val);
151
+ }
152
+ }
153
+ }
154
+ }
155
+ else if ((0, graphql_1.isScalarType)(inputType)) {
156
+ // if (inputType.extensions.grafast?.apply) {
157
+ // }
158
+ }
159
+ else if ((0, graphql_1.isEnumType)(inputType)) {
160
+ if (inputValue === null) {
161
+ return;
162
+ }
163
+ const values = inputType.getValues();
164
+ const value = values.find((v) => v.value === inputValue);
165
+ if (value) {
166
+ if (value.extensions.grafast?.apply) {
167
+ value.extensions.grafast.apply(target);
168
+ }
169
+ }
170
+ else {
171
+ throw new Error(`Couldn't find value in ${inputType} for ${inputValue}`);
172
+ }
173
+ }
174
+ else {
175
+ const never = inputType;
176
+ throw new Error(`Input type expected, but found ${never}`);
177
+ }
178
+ }
179
+ /**
180
+ * Modifiers modify their parent (which may be another modifier or anything
181
+ * else). First they gather all the requirements from their children (if any)
182
+ * being applied to them, then they apply themselves to their parent. This
183
+ * application is done through the `apply()` method.
184
+ */
185
+ class Modifier {
186
+ constructor(parent) {
187
+ this.parent = parent;
188
+ if (applyingModifiers) {
189
+ throw new Error(`Must not create new modifier whilst modifiers are being applied!`);
190
+ }
191
+ currentModifiers.push(this);
192
+ }
193
+ }
194
+ exports.Modifier = Modifier;
195
+ function isModifier(plan) {
196
+ return plan instanceof Modifier;
197
+ }
198
+ function assertModifier(plan, pathDescription) {
199
+ if (!isModifier(plan)) {
200
+ throw new Error(`The plan returned from '${pathDescription}' should be a modifier plan, but it does not implement the 'apply' method.`);
201
+ }
202
+ }
203
+ function isApplyableStep(s) {
204
+ return typeof s.apply === "function";
205
+ }
206
+ //# sourceMappingURL=applyInput.js.map
@@ -1,9 +1,9 @@
1
- import { ExecutableStep } from "../step.js";
1
+ import { Step } from "../step.js";
2
2
  /**
3
3
  * If you want to use a step that might represent a list and you need all of
4
4
  * the `listItem` transforms to have already taken place (e.g. you're going to
5
5
  * send the result to an external service) rather than processing them through
6
6
  * the GraphQL response, then you may need to call `applyTransforms` on it.
7
7
  */
8
- export declare function applyTransforms($step: ExecutableStep): ExecutableStep<any>;
8
+ export declare function applyTransforms($step: Step): Step<any>;
9
9
  //# sourceMappingURL=applyTransforms.d.ts.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyTransforms = exports.ApplyTransformsStep = void 0;
3
+ exports.ApplyTransformsStep = void 0;
4
+ exports.applyTransforms = applyTransforms;
4
5
  const tslib_1 = require("tslib");
5
6
  const assert = tslib_1.__importStar(require("../assert.js"));
6
7
  const dev_js_1 = require("../dev.js");
@@ -11,18 +12,20 @@ const error_js_1 = require("../error.js");
11
12
  const interfaces_js_1 = require("../interfaces.js");
12
13
  const step_js_1 = require("../step.js");
13
14
  const __item_js_1 = require("./__item.js");
15
+ const connection_js_1 = require("./connection.js");
14
16
  /**
15
17
  * @internal
16
18
  */
17
- class ApplyTransformsStep extends step_js_1.ExecutableStep {
19
+ class ApplyTransformsStep extends step_js_1.Step {
18
20
  static { this.$$export = {
19
21
  moduleName: "grafast",
20
22
  exportName: "ApplyTransformsStep",
21
23
  }; }
22
- constructor(listPlan) {
24
+ constructor($step) {
23
25
  super();
24
26
  // OPTIMIZE: if all the steps in the inner bucket are synchronous then theoretically we can be synchronous too
25
27
  this.isSyncAndSafe = false;
28
+ const listPlan = (0, connection_js_1.itemsOrStep)($step);
26
29
  this.addDependency(listPlan);
27
30
  // Plan this subroutine
28
31
  this.subroutineLayer = new LayerPlan_js_1.LayerPlan(this.operationPlan, this.layerPlan, {
@@ -65,7 +68,7 @@ class ApplyTransformsStep extends step_js_1.ExecutableStep {
65
68
  throw new Error("GrafastInternalError<b3a2bff9-15c6-47e2-aa82-19c862324f1a>: listItem layer plan has no rootStepId");
66
69
  }
67
70
  if (itemStep._isUnary) {
68
- store.set(itemStepId, (0, executeBucket_js_1.unaryExecutionValue)(values0.at(0)));
71
+ store.set(itemStepId, (0, executeBucket_js_1.unaryExecutionValue)(values0.unaryValue()));
69
72
  }
70
73
  else {
71
74
  store.set(itemStepId, (0, executeBucket_js_1.batchExecutionValue)([]));
@@ -167,5 +170,4 @@ function applyTransforms($step) {
167
170
  return $step;
168
171
  }
169
172
  }
170
- exports.applyTransforms = applyTransforms;
171
173
  //# sourceMappingURL=applyTransforms.js.map
@@ -0,0 +1,23 @@
1
+ import type { GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLSchema } from "graphql";
2
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
3
+ import type { Step } from "../step.js";
4
+ import { UnbatchedStep } from "../step.js";
5
+ export declare class BakedInputStep<TData = any> extends UnbatchedStep<TData> {
6
+ private inputType;
7
+ static $$export: {
8
+ moduleName: string;
9
+ exportName: string;
10
+ };
11
+ isSyncAndSafe: boolean;
12
+ valueDepId: 0;
13
+ constructor(inputType: GraphQLInputObjectType | GraphQLList<any>, $value: Step);
14
+ deduplicate(peers: readonly BakedInputStep[]): BakedInputStep<any>[];
15
+ unbatchedExecute(extra: UnbatchedExecutionExtra, value: unknown): TData;
16
+ }
17
+ /**
18
+ * Takes a input type and matching value and performs runtime conversion of
19
+ * that type to the internal representation (if any).
20
+ */
21
+ export declare function bakedInput<TArg = any>(inputType: GraphQLInputType, $value: Step): Step<any>;
22
+ export declare function bakedInputRuntime(schema: GraphQLSchema, inputType: GraphQLInputType, value: unknown): unknown;
23
+ //# sourceMappingURL=bakedInput.d.ts.map
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BakedInputStep = void 0;
4
+ exports.bakedInput = bakedInput;
5
+ exports.bakedInputRuntime = bakedInputRuntime;
6
+ const graphql_1 = require("graphql");
7
+ const step_js_1 = require("../step.js");
8
+ const applyInput_js_1 = require("./applyInput.js");
9
+ const index_js_1 = require("./index.js");
10
+ class BakedInputStep extends step_js_1.UnbatchedStep {
11
+ static { this.$$export = {
12
+ moduleName: "grafast",
13
+ exportName: "BakedInputStep",
14
+ }; }
15
+ constructor(inputType, $value) {
16
+ super();
17
+ this.inputType = inputType;
18
+ this.isSyncAndSafe = true;
19
+ this.valueDepId = this.addUnaryDependency($value);
20
+ if (!this._isUnary) {
21
+ throw new Error(`bakedInput() must be unary`);
22
+ }
23
+ this._isUnaryLocked = true;
24
+ }
25
+ deduplicate(peers) {
26
+ return peers.filter((p) => p.inputType === this.inputType);
27
+ }
28
+ unbatchedExecute(extra, value) {
29
+ if (value == null)
30
+ return value;
31
+ return bakedInputRuntime(this.operationPlan.schema, this.inputType, value);
32
+ }
33
+ }
34
+ exports.BakedInputStep = BakedInputStep;
35
+ /**
36
+ * Takes a input type and matching value and performs runtime conversion of
37
+ * that type to the internal representation (if any).
38
+ */
39
+ function bakedInput(inputType, $value) {
40
+ const nullableInputType = (0, graphql_1.getNullableType)(inputType);
41
+ // Could have done this in `optimize()` but faster to do it here.
42
+ if ((0, graphql_1.isListType)(nullableInputType) ||
43
+ ((0, graphql_1.isInputObjectType)(nullableInputType) &&
44
+ typeof nullableInputType.extensions?.grafast?.baked === "function")) {
45
+ // Ooo, we're fancy! Do the thing!
46
+ return (0, index_js_1.operationPlan)().withRootLayerPlan(() => new BakedInputStep(nullableInputType, $value));
47
+ }
48
+ else {
49
+ // Nothing special, we just return the input.
50
+ return $value;
51
+ }
52
+ }
53
+ function bakedInputRuntime(schema, inputType, value) {
54
+ if (value == null)
55
+ return value;
56
+ const nullableInputType = (0, graphql_1.getNullableType)(inputType);
57
+ if ((0, graphql_1.isListType)(nullableInputType)) {
58
+ if (Array.isArray(value)) {
59
+ return value.map((v) => bakedInputRuntime(schema, nullableInputType.ofType, v));
60
+ }
61
+ else {
62
+ throw new Error(`Failed to process input for type ${inputType} - expected array`);
63
+ }
64
+ }
65
+ // Could have done this in `optimize()` but faster to do it here.
66
+ const baked = (0, graphql_1.isInputObjectType)(nullableInputType)
67
+ ? nullableInputType.extensions?.grafast?.baked
68
+ : null;
69
+ if (typeof baked !== "function") {
70
+ // Nothing special, we just return the input.
71
+ return value;
72
+ }
73
+ else {
74
+ // Ooo, we're fancy! Do the thing!
75
+ let applied = false;
76
+ const bakedObj = baked(value, {
77
+ type: nullableInputType,
78
+ schema,
79
+ applyChildren(parent) {
80
+ applied = true;
81
+ (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, parent, value, undefined);
82
+ },
83
+ });
84
+ if (!applied) {
85
+ (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, bakedObj, value, undefined);
86
+ }
87
+ return bakedObj;
88
+ }
89
+ }
90
+ //# sourceMappingURL=bakedInput.js.map
@@ -1,11 +1,12 @@
1
- import type { ExecutableStep, UnbatchedExecutionExtra } from "..";
2
- import { UnbatchedExecutableStep } from "../step.js";
1
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
3
4
  declare const unaryOperators: readonly ["null", "not null", "exists", "not exists"];
4
5
  type UnaryOperator = (typeof unaryOperators)[number];
5
6
  declare const binaryOperators: readonly ["===", "!=="];
6
7
  type BinaryOperator = (typeof binaryOperators)[number];
7
8
  type Operator = UnaryOperator | BinaryOperator;
8
- export declare class ConditionStep extends UnbatchedExecutableStep<boolean> {
9
+ export declare class ConditionStep extends UnbatchedStep<boolean> {
9
10
  private op;
10
11
  static $$export: {
11
12
  moduleName: string;
@@ -19,8 +20,7 @@ export declare class ConditionStep extends UnbatchedExecutableStep<boolean> {
19
20
  private makeUnbatchedExecute;
20
21
  unbatchedExecute(_extra: UnbatchedExecutionExtra, _value1: any, _value2: any): boolean;
21
22
  }
22
- type Step<T = any> = ExecutableStep<T>;
23
- type $Boolean = ExecutableStep<boolean>;
23
+ type $Boolean = Step<boolean>;
24
24
  declare function condition(op: "null", step: Step): $Boolean;
25
25
  declare function condition(op: "not null", step: Step): $Boolean;
26
26
  declare function condition(op: "exists", step: Step): $Boolean;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.condition = exports.ConditionStep = void 0;
3
+ exports.ConditionStep = void 0;
4
+ exports.condition = condition;
4
5
  const step_js_1 = require("../step.js");
5
6
  const unaryOperators = ["null", "not null", "exists", "not exists"];
6
7
  const binaryOperators = ["===", "!=="];
7
- class ConditionStep extends step_js_1.UnbatchedExecutableStep {
8
+ class ConditionStep extends step_js_1.UnbatchedStep {
8
9
  static { this.$$export = {
9
10
  moduleName: "grafast",
10
11
  exportName: "ConditionStep",
@@ -90,5 +91,4 @@ function isNotEqual(_extra, value1, value2) {
90
91
  function condition(op, step1, step2) {
91
92
  return new ConditionStep(op, step1, step2);
92
93
  }
93
- exports.condition = condition;
94
94
  //# sourceMappingURL=condition.js.map
@@ -1,23 +1,23 @@
1
- import type { ExecutionDetails, GrafastResultsList, InputStep, UnbatchedExecutionExtra } 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,18 +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>, TEdgeDataStep extends ExecutableStep = TItemStep, TNodeStep extends ExecutableStep = ExecutableStep> extends UnbatchedExecutableStep<unknown> {
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> {
40
41
  static $$export: {
41
42
  moduleName: string;
42
43
  exportName: string;
@@ -52,19 +53,19 @@ export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorSte
52
53
  readonly edgeDataPlan?: ($item: TItemStep) => TEdgeDataStep;
53
54
  /** The node plan */
54
55
  readonly itemPlan?: ($item: TItemStep) => TNodeStep;
55
- readonly cursorPlan?: ($item: TItemStep) => ExecutableStep<string | null> | undefined;
56
+ readonly cursorPlan?: ($item: TItemStep) => Step<string | null> | undefined;
56
57
  constructor(subplan: TStep, config?: ConnectionConfig<TItemStep, TEdgeDataStep, TNodeStep>);
57
58
  toStringMeta(): string;
58
- getFirst(): InputStep | null;
59
- setFirst($firstPlan: InputStep): void;
60
- getLast(): InputStep | null;
61
- setLast($lastPlan: InputStep): void;
62
- getOffset(): InputStep | null;
63
- 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;
64
65
  getBefore(): TCursorStep | null;
65
- setBefore($beforePlan: InputStep): void;
66
+ setBefore($beforePlan: Step<string | null | undefined>): void;
66
67
  getAfter(): TCursorStep | null;
67
- setAfter($afterPlan: InputStep): void;
68
+ setAfter($afterPlan: Step<string | null | undefined>): void;
68
69
  /**
69
70
  * This should not be called after the arguments have been finalized.
70
71
  */
@@ -94,21 +95,21 @@ export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorSte
94
95
  * to add a dependency to us, which is typically useful for adding validation
95
96
  * functions so that they are thrown "earlier", avoiding error bubbling.
96
97
  */
97
- addValidation(callback: () => ExecutableStep): void;
98
- get(fieldName: string): ExecutableStep<any> | undefined;
99
- edges(): ExecutableStep;
98
+ addValidation(callback: () => Step): void;
99
+ get(fieldName: string): Step<any> | undefined;
100
+ edges(): Step;
100
101
  nodes(): import("./listTransform.js").__ListTransformStep<any, any, any, any> | TStep;
101
102
  wrapEdge($edge: TItemStep): EdgeStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>;
102
103
  pageInfo(): PageInfoCapableStep;
103
104
  execute({ count, }: ExecutionDetails): GrafastResultsList<Record<string, never>>;
104
105
  unbatchedExecute(): any;
105
106
  }
106
- export interface EdgeCapableStep<TNodeStep extends ExecutableStep> extends ExecutableStep {
107
+ export interface EdgeCapableStep<TNodeStep extends Step> extends Step {
107
108
  node(): TNodeStep;
108
- cursor(): ExecutableStep<string | null>;
109
+ cursor(): Step<string | null>;
109
110
  }
110
- export declare function assertEdgeCapableStep<TNodeStep extends ExecutableStep>($step: ExecutableStep | EdgeCapableStep<TNodeStep>): asserts $step is EdgeCapableStep<TNodeStep>;
111
- export declare class EdgeStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TEdgeDataStep extends ExecutableStep = TItemStep, 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> {
112
113
  private skipCursor;
113
114
  static $$export: {
114
115
  moduleName: string;
@@ -119,26 +120,28 @@ export declare class EdgeStep<TItemStep extends ExecutableStep, TCursorStep exte
119
120
  private readonly cursorDepId;
120
121
  private needCursor;
121
122
  constructor($connection: ConnectionStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>, $item: TItemStep, skipCursor?: boolean);
122
- get(fieldName: string): ExecutableStep<string | null> | TNodeStep | undefined;
123
+ get(fieldName: string): Step<string | null> | TNodeStep | undefined;
123
124
  private getConnectionStep;
124
125
  private getItemStep;
125
126
  data(): TEdgeDataStep;
126
127
  node(): TNodeStep;
127
- cursor(): ExecutableStep<string | null>;
128
- optimize(): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep, ExecutableStep<any>>;
128
+ cursor(): Step<string | null>;
129
+ optimize(): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep, Step<any>>;
129
130
  deduplicate(_peers: EdgeStep<any, any, any, any>[]): EdgeStep<TItemStep, TCursorStep, TStep, TNodeStep>[];
130
131
  deduplicatedWith(replacement: EdgeStep<any, any, any, any>): void;
131
132
  unbatchedExecute(_extra: UnbatchedExecutionExtra, record: any, cursor: any): any;
132
133
  }
133
- interface ConnectionConfig<TItemStep extends ExecutableStep, TEdgeDataStep extends ExecutableStep = TItemStep, TNodeStep extends ExecutableStep = ExecutableStep> {
134
+ interface ConnectionConfig<TItemStep extends Step, TEdgeDataStep extends Step = TItemStep, TNodeStep extends Step = Step> {
134
135
  nodePlan?: ($item: TItemStep) => TNodeStep;
135
136
  edgeDataPlan?: ($item: TItemStep) => TEdgeDataStep;
136
- cursorPlan?: ($item: TItemStep) => ExecutableStep<string | null>;
137
+ cursorPlan?: ($item: TItemStep) => Step<string | null>;
137
138
  }
138
139
  /**
139
140
  * Wraps a collection fetch to provide the utilities for working with GraphQL
140
141
  * cursor connections.
141
142
  */
142
- export declare function connection<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TEdgeDataStep extends ExecutableStep = TItemStep, TNodeStep extends ExecutableStep = ExecutableStep>(step: TStep, config?: ConnectionConfig<TItemStep, TEdgeDataStep, TNodeStep>): ConnectionStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, 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[]>;
143
146
  export {};
144
147
  //# sourceMappingURL=connection.d.ts.map