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.
- package/dist/args.js +2 -3
- package/dist/assert.js +2 -3
- package/dist/constraints.js +1 -2
- package/dist/deferred.js +1 -2
- package/dist/dev.js +2 -2
- package/dist/engine/LayerPlan.d.ts +20 -16
- package/dist/engine/LayerPlan.js +5 -10
- package/dist/engine/OperationPlan.d.ts +12 -13
- package/dist/engine/OperationPlan.js +210 -146
- package/dist/engine/OutputPlan.d.ts +4 -4
- package/dist/engine/OutputPlan.js +13 -10
- package/dist/engine/StepTracker.js +11 -2
- package/dist/engine/executeBucket.js +135 -94
- package/dist/engine/executeOutputPlan.js +1 -2
- package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
- package/dist/engine/lib/defaultPlanResolver.js +11 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -2
- package/dist/engine/lib/withGlobalLayerPlan.js +4 -5
- package/dist/engine/lock.d.ts +3 -3
- package/dist/engine/lock.js +3 -3
- package/dist/error.js +4 -4
- package/dist/establishOperationPlan.js +2 -3
- package/dist/execute.js +3 -4
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.js +2 -3
- package/dist/grafastPrint.js +7 -8
- package/dist/graphqlCollectFields.js +6 -7
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +22 -18
- package/dist/index.js +41 -16
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -4
- package/dist/inspect.js +2 -2
- package/dist/interfaces.d.ts +110 -89
- package/dist/makeGrafastSchema.d.ts +18 -9
- package/dist/makeGrafastSchema.js +64 -30
- package/dist/mermaid.js +53 -14
- package/dist/middleware.js +1 -2
- package/dist/multistep.d.ts +6 -6
- package/dist/multistep.js +6 -7
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +131 -399
- package/dist/planJSONInterfaces.d.ts +6 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.js +6 -6
- package/dist/step.d.ts +67 -99
- package/dist/step.js +99 -127
- package/dist/steps/__flag.d.ts +16 -16
- package/dist/steps/__flag.js +9 -6
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +2 -4
- package/dist/steps/__inputDynamicScalar.js +4 -2
- package/dist/steps/__inputList.d.ts +5 -9
- package/dist/steps/__inputList.js +4 -1
- package/dist/steps/__inputObject.d.ts +6 -11
- package/dist/steps/__inputObject.js +13 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +6 -6
- package/dist/steps/__item.js +1 -1
- package/dist/steps/__trackedValue.d.ts +4 -49
- package/dist/steps/__trackedValue.js +24 -6
- package/dist/steps/__value.d.ts +3 -3
- package/dist/steps/__value.js +3 -2
- package/dist/steps/access.d.ts +7 -6
- package/dist/steps/access.js +14 -7
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -2
- package/dist/steps/applyTransforms.js +7 -5
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +5 -5
- package/dist/steps/condition.js +3 -3
- package/dist/steps/connection.d.ts +42 -39
- package/dist/steps/connection.js +51 -35
- package/dist/steps/constant.d.ts +4 -8
- package/dist/steps/constant.js +54 -6
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +1 -2
- package/dist/steps/error.d.ts +2 -2
- package/dist/steps/error.js +3 -3
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +6 -5
- package/dist/steps/first.js +5 -4
- package/dist/steps/graphqlResolver.d.ts +2 -2
- package/dist/steps/graphqlResolver.js +44 -56
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +4 -2
- package/dist/steps/index.js +21 -9
- package/dist/steps/lambda.d.ts +5 -5
- package/dist/steps/lambda.js +4 -4
- package/dist/steps/last.d.ts +6 -5
- package/dist/steps/last.js +5 -4
- package/dist/steps/list.d.ts +7 -7
- package/dist/steps/list.js +3 -3
- package/dist/steps/listTransform.d.ts +14 -12
- package/dist/steps/listTransform.js +14 -7
- package/dist/steps/listen.d.ts +6 -8
- package/dist/steps/listen.js +7 -7
- package/dist/steps/load.d.ts +6 -6
- package/dist/steps/load.js +7 -7
- package/dist/steps/node.d.ts +16 -10
- package/dist/steps/node.js +14 -7
- package/dist/steps/object.d.ts +11 -11
- package/dist/steps/object.js +5 -5
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +8 -8
- package/dist/steps/polymorphicBranch.js +4 -4
- package/dist/steps/proxy.d.ts +8 -8
- package/dist/steps/proxy.js +3 -3
- package/dist/steps/remapKeys.d.ts +6 -6
- package/dist/steps/remapKeys.js +3 -3
- package/dist/steps/reverse.d.ts +5 -5
- package/dist/steps/reverse.js +4 -4
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +4 -4
- package/dist/steps/sideEffect.js +3 -3
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.js +2 -3
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +43 -31
- package/dist/utils.js +97 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/step.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.isExecutableStep = exports.UnbatchedExecutableStep = exports.ExecutableStep = exports.UnbatchedStep = exports.Step = exports.assertFinalized = exports.$$noExec = void 0;
|
|
5
|
+
exports.isStep = isStep;
|
|
6
|
+
exports.assertStep = assertStep;
|
|
7
|
+
exports.isUnbatchedStep = isUnbatchedStep;
|
|
8
|
+
exports.isObjectLikeStep = isObjectLikeStep;
|
|
9
|
+
exports.isListLikeStep = isListLikeStep;
|
|
10
|
+
exports.isPolymorphicStep = isPolymorphicStep;
|
|
11
|
+
exports.isListCapableStep = isListCapableStep;
|
|
12
|
+
exports.assertListCapableStep = assertListCapableStep;
|
|
13
|
+
exports.assertExecutableStep = assertExecutableStep;
|
|
5
14
|
const tslib_1 = require("tslib");
|
|
6
15
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
16
|
const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
|
|
@@ -41,66 +50,21 @@ function reallyAssertFinalized(plan) {
|
|
|
41
50
|
}
|
|
42
51
|
// Optimise this away in production.
|
|
43
52
|
exports.assertFinalized = !dev_js_1.isDev ? dev_js_1.noop : reallyAssertFinalized;
|
|
44
|
-
/**
|
|
45
|
-
* The base abstract plan type; you should not extend this directly - instead
|
|
46
|
-
* use an ExecutableStep (for use when planning output fields) or a
|
|
47
|
-
* ModifierStep (for use when planning arguments/input fields).
|
|
48
|
-
*
|
|
49
|
-
* @remarks
|
|
50
|
-
*
|
|
51
|
-
* Though it might seem that ModifierStep should be used for all inputs
|
|
52
|
-
* (arguments, input objects), this is not the case. When planning an output
|
|
53
|
-
* field, all inputs to it (including arguments, parent plan, context, etc)
|
|
54
|
-
* should be other executable plans. The only time that ModifierStep is used is
|
|
55
|
-
* when writing specific plans as part of the argument or input field
|
|
56
|
-
* definitions themself; even in these cases the inputs to these plan resolvers
|
|
57
|
-
* will be ExecutablePlans.
|
|
58
|
-
*/
|
|
59
|
-
class BaseStep {
|
|
60
|
-
static { _a = interfaces_js_1.$$subroutine; }
|
|
61
|
-
constructor() {
|
|
62
|
-
this[_a] = null;
|
|
63
|
-
this.isArgumentsFinalized = false;
|
|
64
|
-
this.isFinalized = false;
|
|
65
|
-
this.debug = (0, global_js_1.getDebug)();
|
|
66
|
-
const layerPlan = (0, withGlobalLayerPlan_js_1.currentLayerPlan)();
|
|
67
|
-
this.layerPlan = layerPlan;
|
|
68
|
-
this.operationPlan = layerPlan.operationPlan;
|
|
69
|
-
this._isUnary = true;
|
|
70
|
-
this._isUnaryLocked = false;
|
|
71
|
-
}
|
|
72
|
-
toString() {
|
|
73
|
-
const meta = this.toStringMeta();
|
|
74
|
-
return chalk_1.default.bold.blue(`${this.constructor.name.replace(/Step$/, "")}${meta != null && meta.length ? chalk_1.default.grey(`<${meta}>`) : ""}`);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* This metadata will be merged into toString when referencing this plan.
|
|
78
|
-
*/
|
|
79
|
-
toStringMeta() {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
planJSONExtra() {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
finalize() {
|
|
86
|
-
if (!this.isFinalized) {
|
|
87
|
-
this.isFinalized = true;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error(`Step ${this} has already been finalized - do not call \`finalize()\` from user code!`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
destroy() { }
|
|
94
|
-
}
|
|
95
|
-
exports.BaseStep = BaseStep;
|
|
96
53
|
/**
|
|
97
54
|
* Executable plans are the plans associated with leaves on the GraphQL tree,
|
|
98
55
|
* they must be able to execute to return values.
|
|
99
56
|
*/
|
|
100
|
-
class
|
|
101
|
-
static { _b = lock_js_1.$$unlock; }
|
|
57
|
+
class Step {
|
|
58
|
+
static { _a = interfaces_js_1.$$subroutine, _b = lock_js_1.$$unlock; }
|
|
102
59
|
constructor() {
|
|
103
|
-
|
|
60
|
+
this[_a] = null;
|
|
61
|
+
/**
|
|
62
|
+
* For input values, set `true` if it comes from variables/arguments since
|
|
63
|
+
* they cannot be modified (even by mutations), set `false` otherwise.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
this._isImmutable = false;
|
|
104
68
|
/** @internal */
|
|
105
69
|
this[_b] = undefined;
|
|
106
70
|
/**
|
|
@@ -119,6 +83,14 @@ class ExecutableStep extends BaseStep {
|
|
|
119
83
|
* @experimental
|
|
120
84
|
*/
|
|
121
85
|
this.peerKey = null;
|
|
86
|
+
this.isArgumentsFinalized = false;
|
|
87
|
+
this.isFinalized = false;
|
|
88
|
+
this.debug = (0, global_js_1.getDebug)();
|
|
89
|
+
const layerPlan = (0, withGlobalLayerPlan_js_1.currentLayerPlan)();
|
|
90
|
+
this.layerPlan = layerPlan;
|
|
91
|
+
this.operationPlan = layerPlan.operationPlan;
|
|
92
|
+
this._isUnary = true;
|
|
93
|
+
this._isUnaryLocked = false;
|
|
122
94
|
this.implicitSideEffectStep = null;
|
|
123
95
|
this.hasSideEffects ??= false;
|
|
124
96
|
let hasSideEffects = false;
|
|
@@ -177,15 +149,28 @@ class ExecutableStep extends BaseStep {
|
|
|
177
149
|
this.dependents = [];
|
|
178
150
|
this.isOptimized = false;
|
|
179
151
|
this.allowMultipleOptimizations = false;
|
|
180
|
-
this._stepOptions = { stream: null };
|
|
152
|
+
this._stepOptions = { stream: null, walkIterable: false };
|
|
181
153
|
this.store = true;
|
|
182
154
|
this.polymorphicPaths = (0, withGlobalLayerPlan_js_1.currentPolymorphicPaths)();
|
|
183
155
|
// Important: MUST come after `this.layerPlan = ...`
|
|
184
156
|
this.id = this.layerPlan._addStep(this);
|
|
185
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Generally you should only use this once the dependencies of a step are
|
|
160
|
+
* established, if you use it beforehand and it returns `true` then adding a
|
|
161
|
+
* non-unary dependency later will result in an error.
|
|
162
|
+
*/
|
|
163
|
+
getAndFreezeIsUnary() {
|
|
164
|
+
this._isUnaryLocked = true;
|
|
165
|
+
return this._isUnary;
|
|
166
|
+
}
|
|
186
167
|
withMyLayerPlan(callback) {
|
|
187
168
|
return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, callback);
|
|
188
169
|
}
|
|
170
|
+
/** @experimental */
|
|
171
|
+
withLayerPlan(callback) {
|
|
172
|
+
return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, callback);
|
|
173
|
+
}
|
|
189
174
|
getStep(id) {
|
|
190
175
|
return this.layerPlan.getStep(id, this);
|
|
191
176
|
}
|
|
@@ -196,12 +181,25 @@ class ExecutableStep extends BaseStep {
|
|
|
196
181
|
const acceptFlags = interfaces_js_1.ALL_FLAGS & ~forbiddenFlags;
|
|
197
182
|
return { step, acceptFlags, onReject };
|
|
198
183
|
}
|
|
199
|
-
getDep(_depId) {
|
|
184
|
+
getDep(_depId, _throwOnFlagged = false) {
|
|
200
185
|
// This gets replaced when `__FlagStep` is loaded. Were we on ESM we could
|
|
201
186
|
// just put the code here, but since we're not we have to avoid the
|
|
202
187
|
// circular dependency.
|
|
203
188
|
throw new Error(`Grafast failed to load correctly`);
|
|
204
189
|
}
|
|
190
|
+
maybeGetDep(depId, throwOnFlagged = false) {
|
|
191
|
+
return depId == null
|
|
192
|
+
? null
|
|
193
|
+
: throwOnFlagged
|
|
194
|
+
? this.getDep(depId, true)
|
|
195
|
+
: this.getDep(depId);
|
|
196
|
+
}
|
|
197
|
+
getDepOrConstant(_depId, _fallback) {
|
|
198
|
+
// This gets replaced when `constant` is loaded. Were we on ESM we could
|
|
199
|
+
// just put the code here, but since we're not we have to avoid the
|
|
200
|
+
// circular dependency.
|
|
201
|
+
throw new Error(`Grafast failed to load correctly`);
|
|
202
|
+
}
|
|
205
203
|
/**
|
|
206
204
|
* Like getDep, except it skips over __ItemStep and similar steps to get to
|
|
207
205
|
* where the parent really is.
|
|
@@ -237,15 +235,22 @@ class ExecutableStep extends BaseStep {
|
|
|
237
235
|
catch (e) {
|
|
238
236
|
// Ignore
|
|
239
237
|
}
|
|
240
|
-
return chalk_1.default.bold.blue(`${this.constructor.name.replace(/Step$/, "")}${this.layerPlan.id === 0 ? "" : chalk_1.default.grey(`{${this.layerPlan.id}}`)}${this._isUnary ? "➊" : ""}${meta != null && meta.length ? chalk_1.default.grey(`<${meta}>`) : ""}[${(0, inspect_js_1.inspect)(this.id, {
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
return chalk_1.default.bold.blue(`${this.constructor.name.replace(/Step$/, "")}${this.layerPlan.id === 0 ? "" : chalk_1.default.grey(`{${this.layerPlan.id}}`)}${this._isUnary ? "➊" : ""}${this._stepOptions.stream != null ? "@s" : ""}${meta != null && meta.length ? chalk_1.default.grey(`<${meta}>`) : ""}[${(0, inspect_js_1.inspect)(this.id, { colors: true })}]`);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* This metadata will be merged into toString when referencing this plan.
|
|
242
|
+
*/
|
|
243
|
+
toStringMeta() {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
planJSONExtra() {
|
|
247
|
+
return undefined;
|
|
243
248
|
}
|
|
244
249
|
canAddDependency(step) {
|
|
245
250
|
return (0, utils_js_1.stepAMayDependOnStepB)(this, step);
|
|
246
251
|
}
|
|
247
252
|
addDependency(stepOrOptions) {
|
|
248
|
-
const options = stepOrOptions instanceof
|
|
253
|
+
const options = stepOrOptions instanceof Step
|
|
249
254
|
? { step: stepOrOptions, skipDeduplication: false }
|
|
250
255
|
: stepOrOptions;
|
|
251
256
|
if (options.step.layerPlan.id > this.layerPlan.id) {
|
|
@@ -260,9 +265,7 @@ class ExecutableStep extends BaseStep {
|
|
|
260
265
|
* directly.
|
|
261
266
|
*/
|
|
262
267
|
addUnaryDependency(stepOrOptions) {
|
|
263
|
-
const options = stepOrOptions instanceof
|
|
264
|
-
? { step: stepOrOptions }
|
|
265
|
-
: stepOrOptions;
|
|
268
|
+
const options = stepOrOptions instanceof Step ? { step: stepOrOptions } : stepOrOptions;
|
|
266
269
|
if (options.step.layerPlan.id > this.layerPlan.id) {
|
|
267
270
|
throw new Error(`Cannot add dependency ${options.step} to ${this} since the former is in a deeper layerPlan (creates a catch-22)`);
|
|
268
271
|
}
|
|
@@ -286,7 +289,12 @@ class ExecutableStep extends BaseStep {
|
|
|
286
289
|
this.execute.constructor.name === "AsyncFunction") {
|
|
287
290
|
throw new Error(`${this} claims to be synchronous, however the execute method is asynchronous`);
|
|
288
291
|
}
|
|
289
|
-
|
|
292
|
+
if (!this.isFinalized) {
|
|
293
|
+
this.isFinalized = true;
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
throw new Error(`Step ${this} has already been finalized - do not call \`finalize()\` from user code!`);
|
|
297
|
+
}
|
|
290
298
|
}
|
|
291
299
|
/**
|
|
292
300
|
* This function will be called with 'execution details', an object containing:
|
|
@@ -329,10 +337,10 @@ class ExecutableStep extends BaseStep {
|
|
|
329
337
|
this.optimize = throwDestroyed;
|
|
330
338
|
this.finalize = throwDestroyed;
|
|
331
339
|
this.execute = throwDestroyed;
|
|
332
|
-
super.destroy();
|
|
333
340
|
}
|
|
334
341
|
}
|
|
335
|
-
exports.
|
|
342
|
+
exports.Step = Step;
|
|
343
|
+
exports.ExecutableStep = Step;
|
|
336
344
|
function _buildOptimizedExecuteV2Expression(depCount, isSyncAndSafe) {
|
|
337
345
|
const identifiers = [];
|
|
338
346
|
for (let i = 0; i < depCount; i++) {
|
|
@@ -396,13 +404,13 @@ function buildOptimizedExecute(depCount, isSyncAndSafe, callback) {
|
|
|
396
404
|
callback(fn);
|
|
397
405
|
});
|
|
398
406
|
}
|
|
399
|
-
class
|
|
407
|
+
class UnbatchedStep extends Step {
|
|
400
408
|
static { this.$$export = {
|
|
401
409
|
moduleName: "grafast",
|
|
402
|
-
exportName: "
|
|
410
|
+
exportName: "UnbatchedStep",
|
|
403
411
|
}; }
|
|
404
412
|
finalize() {
|
|
405
|
-
if (this.execute ===
|
|
413
|
+
if (this.execute === UnbatchedStep.prototype.execute) {
|
|
406
414
|
// If they've not replaced 'execute', use our optimized form
|
|
407
415
|
buildOptimizedExecute(this.dependencies.length, this.isSyncAndSafe, (fn) => {
|
|
408
416
|
this.execute = fn;
|
|
@@ -412,9 +420,13 @@ class UnbatchedExecutableStep extends ExecutableStep {
|
|
|
412
420
|
}
|
|
413
421
|
execute({ indexMap, values, extra, }) {
|
|
414
422
|
console.warn(`${this} didn't call 'super.finalize()' in the finalize method.`);
|
|
423
|
+
const depCount = this.dependencies.length;
|
|
415
424
|
return indexMap((i) => {
|
|
416
425
|
try {
|
|
417
|
-
const tuple =
|
|
426
|
+
const tuple = [];
|
|
427
|
+
for (let j = 0; j < depCount; j++) {
|
|
428
|
+
tuple[j] = values[j].at(i);
|
|
429
|
+
}
|
|
418
430
|
return this.unbatchedExecute(extra, ...tuple);
|
|
419
431
|
}
|
|
420
432
|
catch (e) {
|
|
@@ -423,81 +435,41 @@ class UnbatchedExecutableStep extends ExecutableStep {
|
|
|
423
435
|
});
|
|
424
436
|
}
|
|
425
437
|
}
|
|
426
|
-
exports.
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
typeof step.execute === "function");
|
|
438
|
+
exports.UnbatchedStep = UnbatchedStep;
|
|
439
|
+
exports.UnbatchedExecutableStep = UnbatchedStep;
|
|
440
|
+
function isStep(step) {
|
|
441
|
+
return step instanceof Step;
|
|
431
442
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
throw new Error(`Expected an executable step, but received something else: ${(0, inspect_js_1.inspect)(step)}`);
|
|
443
|
+
function assertStep(step) {
|
|
444
|
+
if (!isStep(step)) {
|
|
445
|
+
throw new Error(`Expected a step, but received something else: ${(0, inspect_js_1.inspect)(step)}`);
|
|
436
446
|
}
|
|
437
447
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return (isExecutableStep(step) &&
|
|
441
|
-
typeof step.unbatchedExecute === "function");
|
|
448
|
+
function isUnbatchedStep(step) {
|
|
449
|
+
return isStep(step) && typeof step.unbatchedExecute === "function";
|
|
442
450
|
}
|
|
443
|
-
exports.isUnbatchedExecutableStep = isUnbatchedExecutableStep;
|
|
444
451
|
function isObjectLikeStep(plan) {
|
|
445
452
|
return "get" in plan && typeof plan.get === "function";
|
|
446
453
|
}
|
|
447
|
-
exports.isObjectLikeStep = isObjectLikeStep;
|
|
448
454
|
function isListLikeStep(plan) {
|
|
449
455
|
return "at" in plan && typeof plan.at === "function";
|
|
450
456
|
}
|
|
451
|
-
exports.isListLikeStep = isListLikeStep;
|
|
452
|
-
function isStreamableStep(plan) {
|
|
453
|
-
return typeof plan.stream === "function";
|
|
454
|
-
}
|
|
455
|
-
exports.isStreamableStep = isStreamableStep;
|
|
456
457
|
function isPolymorphicStep(s) {
|
|
457
458
|
return ("planForType" in s &&
|
|
458
459
|
typeof s.planForType === "function");
|
|
459
460
|
}
|
|
460
|
-
exports.isPolymorphicStep = isPolymorphicStep;
|
|
461
|
-
/**
|
|
462
|
-
* Modifier plans modify their parent plan (which may be another ModifierStep
|
|
463
|
-
* or an ExecutableStep). First they gather all the requirements from their
|
|
464
|
-
* children (if any) being applied to them, then they apply themselves to their
|
|
465
|
-
* parent plan. This application is done through the `apply()` method.
|
|
466
|
-
*
|
|
467
|
-
* Modifier plans do not use dependencies.
|
|
468
|
-
*/
|
|
469
|
-
class ModifierStep extends BaseStep {
|
|
470
|
-
constructor($parent) {
|
|
471
|
-
super();
|
|
472
|
-
this.$parent = $parent;
|
|
473
|
-
this.id = this.layerPlan._addModifierStep(this);
|
|
474
|
-
}
|
|
475
|
-
toString() {
|
|
476
|
-
const meta = this.toStringMeta();
|
|
477
|
-
return chalk_1.default.bold.blue(`${this.constructor.name.replace(/Step$/, "")}${meta != null && meta.length ? chalk_1.default.grey(`<${meta}>`) : ""}[${(0, inspect_js_1.inspect)(this.id, {
|
|
478
|
-
colors: true,
|
|
479
|
-
})}]`);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
exports.ModifierStep = ModifierStep;
|
|
483
|
-
function isModifierStep(plan) {
|
|
484
|
-
return "apply" in plan && typeof plan.apply === "function";
|
|
485
|
-
}
|
|
486
|
-
exports.isModifierStep = isModifierStep;
|
|
487
|
-
function assertModifierStep(plan, pathDescription) {
|
|
488
|
-
if (!isModifierStep(plan)) {
|
|
489
|
-
throw new Error(`The plan returned from '${pathDescription}' should be a modifier plan, but it does not implement the 'apply' method.`);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
exports.assertModifierStep = assertModifierStep;
|
|
493
461
|
function isListCapableStep(plan) {
|
|
494
462
|
return "listItem" in plan && typeof plan.listItem === "function";
|
|
495
463
|
}
|
|
496
|
-
exports.isListCapableStep = isListCapableStep;
|
|
497
464
|
function assertListCapableStep(plan, pathDescription) {
|
|
498
465
|
if (!isListCapableStep(plan)) {
|
|
499
466
|
throw new Error(`The plan returned from '${pathDescription}' should be a list capable plan, but ${plan} does not implement the 'listItem' method.`);
|
|
500
467
|
}
|
|
501
468
|
}
|
|
502
|
-
|
|
469
|
+
/** @deprecated Use isStep instead */
|
|
470
|
+
exports.isExecutableStep = isStep;
|
|
471
|
+
/** @deprecated Use isStep instead */
|
|
472
|
+
function assertExecutableStep(step) {
|
|
473
|
+
return assertStep(step);
|
|
474
|
+
}
|
|
503
475
|
//# sourceMappingURL=step.js.map
|
package/dist/steps/__flag.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ExecutionDetails, ExecutionEntryFlags, GrafastResultsList } from "../interfaces.js";
|
|
1
|
+
import type { DataFromStep, ExecutionDetails, ExecutionEntryFlags, GrafastResultsList } from "../interfaces.js";
|
|
2
2
|
import { $$deepDepSkip } from "../interfaces.js";
|
|
3
3
|
import type { ListCapableStep } from "../step.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Step } from "../step.js";
|
|
5
5
|
import type { __ItemStep } from "./__item.js";
|
|
6
6
|
export declare const TRAP_ERROR: ExecutionEntryFlags;
|
|
7
7
|
export declare const TRAP_INHIBITED: ExecutionEntryFlags;
|
|
@@ -14,11 +14,11 @@ export type ResolvedTrapValue = false | null | undefined | readonly never[];
|
|
|
14
14
|
export interface FlagStepOptions {
|
|
15
15
|
acceptFlags?: ExecutionEntryFlags;
|
|
16
16
|
onReject?: Error | null;
|
|
17
|
-
if?:
|
|
17
|
+
if?: Step<boolean>;
|
|
18
18
|
valueForInhibited?: TrapValue;
|
|
19
19
|
valueForError?: TrapValue;
|
|
20
20
|
}
|
|
21
|
-
export declare class __FlagStep<
|
|
21
|
+
export declare class __FlagStep<TStep extends Step> extends Step<DataFromStep<TStep>> {
|
|
22
22
|
static $$export: {
|
|
23
23
|
moduleName: string;
|
|
24
24
|
exportName: string;
|
|
@@ -30,13 +30,13 @@ export declare class __FlagStep<TData> extends ExecutableStep<TData> {
|
|
|
30
30
|
private valueForInhibited;
|
|
31
31
|
private valueForError;
|
|
32
32
|
private canBeInlined;
|
|
33
|
-
constructor(step:
|
|
33
|
+
constructor(step: TStep, options: FlagStepOptions);
|
|
34
34
|
toStringMeta(): string | null;
|
|
35
|
-
[$$deepDepSkip]():
|
|
36
|
-
listItem?: ($item: __ItemStep<ListCapableStep<unknown,
|
|
37
|
-
_listItem($item: __ItemStep<ListCapableStep<unknown,
|
|
38
|
-
deduplicate(_peers: readonly
|
|
39
|
-
execute(_details: ExecutionDetails<[data:
|
|
35
|
+
[$$deepDepSkip](): Step;
|
|
36
|
+
listItem?: ($item: __ItemStep<ListCapableStep<unknown, Step<unknown>>>) => Step;
|
|
37
|
+
_listItem($item: __ItemStep<ListCapableStep<unknown, Step<unknown>>>): Step<unknown>;
|
|
38
|
+
deduplicate(_peers: readonly Step<any>[]): readonly Step<any>[];
|
|
39
|
+
execute(_details: ExecutionDetails<[data: DataFromStep<TStep>, cond?: boolean]>): GrafastResultsList<DataFromStep<TStep>>;
|
|
40
40
|
finalize(): void;
|
|
41
41
|
private fancyExecute;
|
|
42
42
|
private passThroughExecute;
|
|
@@ -45,21 +45,21 @@ export declare class __FlagStep<TData> extends ExecutableStep<TData> {
|
|
|
45
45
|
* Example use case: get user by id, but id is null: no need to fetch the user
|
|
46
46
|
* since we know they won't exist.
|
|
47
47
|
*/
|
|
48
|
-
export declare function inhibitOnNull<
|
|
48
|
+
export declare function inhibitOnNull<TStep extends Step>($step: TStep, options?: {
|
|
49
49
|
if?: FlagStepOptions["if"];
|
|
50
|
-
}): __FlagStep<
|
|
50
|
+
}): __FlagStep<TStep>;
|
|
51
51
|
/**
|
|
52
52
|
* Example use case: expecting a node ID that represents a User, but get one
|
|
53
53
|
* that represents a Post instead: throw error to tell user they've sent invalid
|
|
54
54
|
* data.
|
|
55
55
|
*/
|
|
56
|
-
export declare function assertNotNull<
|
|
56
|
+
export declare function assertNotNull<TStep extends Step>($step: TStep, message: string, options?: {
|
|
57
57
|
if?: FlagStepOptions["if"];
|
|
58
|
-
}): __FlagStep<
|
|
59
|
-
export declare function trap<
|
|
58
|
+
}): __FlagStep<TStep>;
|
|
59
|
+
export declare function trap<TStep extends Step>($step: TStep, acceptFlags: ExecutionEntryFlags, options?: {
|
|
60
60
|
valueForInhibited?: FlagStepOptions["valueForInhibited"];
|
|
61
61
|
valueForError?: FlagStepOptions["valueForError"];
|
|
62
62
|
if?: FlagStepOptions["if"];
|
|
63
|
-
}): __FlagStep<
|
|
63
|
+
}): __FlagStep<TStep>;
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=__flag.d.ts.map
|
package/dist/steps/__flag.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.__FlagStep = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_INHIBITED = exports.TRAP_ERROR = void 0;
|
|
4
|
+
exports.inhibitOnNull = inhibitOnNull;
|
|
5
|
+
exports.assertNotNull = assertNotNull;
|
|
6
|
+
exports.trap = trap;
|
|
4
7
|
const error_js_1 = require("../error.js");
|
|
5
8
|
const inspect_js_1 = require("../inspect.js");
|
|
6
9
|
const interfaces_js_1 = require("../interfaces.js");
|
|
@@ -52,7 +55,7 @@ function resolveTrapValue(tv) {
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
class __FlagStep extends step_js_1.
|
|
58
|
+
class __FlagStep extends step_js_1.Step {
|
|
56
59
|
static { this.$$export = {
|
|
57
60
|
moduleName: "grafast",
|
|
58
61
|
exportName: "__FlagStep",
|
|
@@ -223,7 +226,6 @@ function inhibitOnNull($step, options) {
|
|
|
223
226
|
acceptFlags: interfaces_js_1.DEFAULT_ACCEPT_FLAGS & ~interfaces_js_1.FLAG_NULL,
|
|
224
227
|
});
|
|
225
228
|
}
|
|
226
|
-
exports.inhibitOnNull = inhibitOnNull;
|
|
227
229
|
/**
|
|
228
230
|
* Example use case: expecting a node ID that represents a User, but get one
|
|
229
231
|
* that represents a Post instead: throw error to tell user they've sent invalid
|
|
@@ -236,21 +238,22 @@ function assertNotNull($step, message, options) {
|
|
|
236
238
|
onReject: new error_js_1.SafeError(message),
|
|
237
239
|
});
|
|
238
240
|
}
|
|
239
|
-
exports.assertNotNull = assertNotNull;
|
|
240
241
|
function trap($step, acceptFlags, options) {
|
|
241
242
|
return new __FlagStep($step, {
|
|
242
243
|
...options,
|
|
243
244
|
acceptFlags: (acceptFlags & interfaces_js_1.TRAPPABLE_FLAGS) | interfaces_js_1.FLAG_NULL,
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
|
-
exports.trap = trap;
|
|
247
247
|
// Have to overwrite the getDep method due to circular dependency
|
|
248
|
-
step_js_1.
|
|
248
|
+
step_js_1.Step.prototype.getDep = function (depId, throwOnFlagged = false) {
|
|
249
249
|
const { step, acceptFlags, onReject } = this.getDepOptions(depId);
|
|
250
250
|
if (acceptFlags === interfaces_js_1.DEFAULT_ACCEPT_FLAGS && onReject == null) {
|
|
251
251
|
return step;
|
|
252
252
|
}
|
|
253
253
|
else {
|
|
254
|
+
if (throwOnFlagged) {
|
|
255
|
+
throw new Error(`When retrieving dependency ${step} of ${this}, the dependency is flagged as ${digestAcceptFlags(acceptFlags)}/onReject=${String(onReject)}. Please use \`this.getDepOptions(depId)\` instead, and handle the flags`);
|
|
256
|
+
}
|
|
254
257
|
// Return a __FlagStep around options.step so that all the options are preserved.
|
|
255
258
|
return new __FlagStep(step, { acceptFlags, onReject });
|
|
256
259
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UnbatchedExecutionExtra } from "../interfaces.js";
|
|
2
|
+
import { UnbatchedStep } from "../step.js";
|
|
3
|
+
import type { __TrackedValueStep } from "./__trackedValue.js";
|
|
4
|
+
export declare class __InputDefaultStep extends UnbatchedStep {
|
|
5
|
+
private defaultValue;
|
|
6
|
+
static $$export: {
|
|
7
|
+
moduleName: string;
|
|
8
|
+
exportName: string;
|
|
9
|
+
};
|
|
10
|
+
isSyncAndSafe: boolean;
|
|
11
|
+
constructor($variableValue: __TrackedValueStep, defaultValue: unknown);
|
|
12
|
+
unbatchedExecute(_extra: UnbatchedExecutionExtra, variableValue: unknown): unknown;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=__inputDefault.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__InputDefaultStep = void 0;
|
|
4
|
+
const step_js_1 = require("../step.js");
|
|
5
|
+
class __InputDefaultStep extends step_js_1.UnbatchedStep {
|
|
6
|
+
static { this.$$export = {
|
|
7
|
+
moduleName: "grafast",
|
|
8
|
+
exportName: "__InputDefaultStep",
|
|
9
|
+
}; }
|
|
10
|
+
constructor($variableValue, defaultValue) {
|
|
11
|
+
super();
|
|
12
|
+
this.defaultValue = defaultValue;
|
|
13
|
+
this.isSyncAndSafe = true;
|
|
14
|
+
this.addUnaryDependency($variableValue);
|
|
15
|
+
}
|
|
16
|
+
unbatchedExecute(_extra, variableValue) {
|
|
17
|
+
return variableValue === undefined ? this.defaultValue : variableValue;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
eval() {
|
|
21
|
+
const $variable = this.getDep(0);
|
|
22
|
+
const variableValue = $variable.eval();
|
|
23
|
+
return variableValue === undefined ? this.defaultValue : variableValue;
|
|
24
|
+
}
|
|
25
|
+
/** @internal */
|
|
26
|
+
evalIs(value) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const $variable = this.getDep(0);
|
|
32
|
+
return $variable.evalIs(undefined)
|
|
33
|
+
? this.defaultValue === value
|
|
34
|
+
: $variable.evalIs(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
evalLength() {
|
|
39
|
+
const $variable = this.getDep(0);
|
|
40
|
+
return $variable.evalIs(undefined)
|
|
41
|
+
? Array.isArray(this.defaultValue)
|
|
42
|
+
? this.defaultValue.length
|
|
43
|
+
: null
|
|
44
|
+
: $variable.evalLength();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.__InputDefaultStep = __InputDefaultStep;
|
|
48
|
+
//# sourceMappingURL=__inputDefault.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { GraphQLScalarType, ListValueNode, ObjectValueNode } from "graphql";
|
|
2
2
|
import type { UnbatchedExecutionExtra } from "../interfaces.js";
|
|
3
|
-
import {
|
|
3
|
+
import { UnbatchedStep } from "../step.js";
|
|
4
4
|
/**
|
|
5
5
|
* Handles "leaves" (scalars)
|
|
6
6
|
*/
|
|
7
|
-
export declare class __InputDynamicScalarStep<TLeaf = any> extends
|
|
7
|
+
export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedStep<TLeaf> {
|
|
8
8
|
private value;
|
|
9
9
|
static $$export: {
|
|
10
10
|
moduleName: string;
|
|
@@ -15,7 +15,5 @@ export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedExec
|
|
|
15
15
|
constructor(inputType: GraphQLScalarType, value: ListValueNode | ObjectValueNode);
|
|
16
16
|
valueFromValues(variableValues: any[]): any;
|
|
17
17
|
unbatchedExecute: (_extra: UnbatchedExecutionExtra, ...variableValues: any[]) => TLeaf;
|
|
18
|
-
eval(): TLeaf;
|
|
19
|
-
evalIs(expectedValue: undefined | null | 0): boolean;
|
|
20
18
|
}
|
|
21
19
|
//# sourceMappingURL=__inputDynamicScalar.d.ts.map
|
|
@@ -9,7 +9,7 @@ const { Kind } = graphql;
|
|
|
9
9
|
/**
|
|
10
10
|
* Handles "leaves" (scalars)
|
|
11
11
|
*/
|
|
12
|
-
class __InputDynamicScalarStep extends step_js_1.
|
|
12
|
+
class __InputDynamicScalarStep extends step_js_1.UnbatchedStep {
|
|
13
13
|
static { this.$$export = {
|
|
14
14
|
moduleName: "grafast",
|
|
15
15
|
exportName: "__InputDynamicScalarStep",
|
|
@@ -106,10 +106,12 @@ class __InputDynamicScalarStep extends step_js_1.UnbatchedExecutableStep {
|
|
|
106
106
|
};
|
|
107
107
|
return convert(this.value);
|
|
108
108
|
}
|
|
109
|
+
/** @internal */
|
|
109
110
|
eval() {
|
|
110
|
-
const variableValues = this.variableNames.map((variableName, i) => this.getDep(i).eval());
|
|
111
|
+
const variableValues = this.variableNames.map((variableName, i) => this.getDep(i, true).eval());
|
|
111
112
|
return this.valueFromValues(variableValues);
|
|
112
113
|
}
|
|
114
|
+
/** @internal */
|
|
113
115
|
evalIs(expectedValue) {
|
|
114
116
|
if (expectedValue === undefined ||
|
|
115
117
|
expectedValue === null ||
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { GraphQLInputType } from "graphql";
|
|
2
2
|
import * as graphql from "graphql";
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type { ConstantStep } from "./constant.js";
|
|
3
|
+
import type { AnyInputStep, NotVariableValueNode } from "../interfaces.js";
|
|
4
|
+
import { Step } from "../step.js";
|
|
6
5
|
/**
|
|
7
6
|
* Implements `__InputListStep`.
|
|
8
7
|
*/
|
|
9
|
-
export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends
|
|
8
|
+
export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends Step {
|
|
10
9
|
private readonly inputValues;
|
|
11
10
|
static $$export: {
|
|
12
11
|
moduleName: string;
|
|
@@ -15,12 +14,9 @@ export declare class __InputListStep<TInputType extends graphql.GraphQLList<Grap
|
|
|
15
14
|
isSyncAndSafe: boolean;
|
|
16
15
|
private itemCount;
|
|
17
16
|
constructor(inputType: TInputType, inputValues: NotVariableValueNode | undefined);
|
|
18
|
-
optimize():
|
|
17
|
+
optimize(): Step;
|
|
19
18
|
execute(): any[];
|
|
20
19
|
unbatchedExecute: () => any;
|
|
21
|
-
at(index: number):
|
|
22
|
-
eval(): any[] | null;
|
|
23
|
-
evalIs(value: null | undefined | 0): boolean;
|
|
24
|
-
evalLength(): number | null;
|
|
20
|
+
at(index: number): AnyInputStep;
|
|
25
21
|
}
|
|
26
22
|
//# sourceMappingURL=__inputList.d.ts.map
|
|
@@ -12,7 +12,7 @@ const { GraphQLList, Kind } = graphql;
|
|
|
12
12
|
/**
|
|
13
13
|
* Implements `__InputListStep`.
|
|
14
14
|
*/
|
|
15
|
-
class __InputListStep extends step_js_1.
|
|
15
|
+
class __InputListStep extends step_js_1.Step {
|
|
16
16
|
static { this.$$export = {
|
|
17
17
|
moduleName: "grafast",
|
|
18
18
|
exportName: "__InputListStep",
|
|
@@ -66,6 +66,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
|
|
|
66
66
|
(0, input_js_1.assertInputStep)(itemPlan);
|
|
67
67
|
return itemPlan;
|
|
68
68
|
}
|
|
69
|
+
/** @internal */
|
|
69
70
|
eval() {
|
|
70
71
|
if (this.inputValues?.kind === "NullValue") {
|
|
71
72
|
return null;
|
|
@@ -79,6 +80,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
|
|
|
79
80
|
}
|
|
80
81
|
return list;
|
|
81
82
|
}
|
|
83
|
+
/** @internal */
|
|
82
84
|
evalIs(value) {
|
|
83
85
|
if (value === undefined) {
|
|
84
86
|
return this.inputValues === value;
|
|
@@ -90,6 +92,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
|
|
|
90
92
|
throw new Error("__InputListStep cannot evalIs values other than null and undefined currently");
|
|
91
93
|
}
|
|
92
94
|
}
|
|
95
|
+
/** @internal */
|
|
93
96
|
evalLength() {
|
|
94
97
|
if (this.inputValues === undefined) {
|
|
95
98
|
return null;
|