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.
- package/README.md +2 -3
- package/dist/args.d.ts +4 -7
- package/dist/args.js +53 -38
- package/dist/assert.js +2 -3
- package/dist/bucket.d.ts +1 -89
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/constraints.d.ts +15 -1
- package/dist/constraints.js +41 -3
- package/dist/deferred.js +1 -2
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +18 -3
- package/dist/engine/LayerPlan.d.ts +21 -111
- package/dist/engine/LayerPlan.js +196 -78
- package/dist/engine/OperationPlan.d.ts +30 -104
- package/dist/engine/OperationPlan.js +763 -471
- package/dist/engine/OutputPlan.d.ts +9 -20
- package/dist/engine/OutputPlan.js +432 -444
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +94 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +646 -244
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +7 -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 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
- package/dist/engine/lock.d.ts +4 -0
- package/dist/engine/lock.js +82 -0
- package/dist/envelop.js +5 -4
- package/dist/error.d.ts +18 -49
- package/dist/error.js +50 -39
- package/dist/establishOperationPlan.js +57 -42
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +31 -15
- package/dist/exportAs.d.ts +1 -18
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +35 -16
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +67 -6
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +24 -13
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +44 -29
- package/dist/index.js +91 -18
- package/dist/input.d.ts +1 -9
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -3
- package/dist/inspect.js +3 -3
- package/dist/interfaces.d.ts +238 -93
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +21 -9
- package/dist/makeGrafastSchema.js +353 -133
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +131 -19
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +24 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +54 -0
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +140 -368
- package/dist/planJSONInterfaces.d.ts +12 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +100 -74
- package/dist/step.d.ts +118 -172
- package/dist/step.js +262 -183
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +261 -0
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +4 -6
- 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 +7 -11
- package/dist/steps/__inputObject.js +49 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +10 -12
- package/dist/steps/__item.js +8 -2
- package/dist/steps/__trackedValue.d.ts +7 -55
- package/dist/steps/__trackedValue.js +69 -8
- package/dist/steps/__value.d.ts +5 -4
- package/dist/steps/__value.js +5 -4
- package/dist/steps/access.d.ts +10 -10
- package/dist/steps/access.js +50 -17
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -25
- package/dist/steps/applyTransforms.js +53 -31
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +56 -42
- package/dist/steps/connection.js +97 -44
- package/dist/steps/constant.d.ts +7 -7
- package/dist/steps/constant.js +86 -7
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +2 -3
- package/dist/steps/error.d.ts +4 -4
- package/dist/steps/error.js +7 -6
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +10 -9
- package/dist/steps/first.js +9 -13
- package/dist/steps/graphqlResolver.d.ts +3 -76
- package/dist/steps/graphqlResolver.js +89 -72
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +12 -3
- package/dist/steps/index.js +48 -6
- package/dist/steps/lambda.d.ts +9 -9
- package/dist/steps/lambda.js +18 -9
- package/dist/steps/last.d.ts +9 -8
- package/dist/steps/last.js +7 -6
- package/dist/steps/list.d.ts +20 -9
- package/dist/steps/list.js +56 -13
- package/dist/steps/listTransform.d.ts +18 -22
- package/dist/steps/listTransform.js +58 -27
- package/dist/steps/listen.d.ts +6 -11
- package/dist/steps/listen.js +14 -16
- package/dist/steps/load.d.ts +42 -33
- package/dist/steps/load.js +60 -27
- package/dist/steps/node.d.ts +17 -10
- package/dist/steps/node.js +18 -6
- package/dist/steps/object.d.ts +33 -27
- package/dist/steps/object.js +53 -32
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +11 -12
- package/dist/steps/proxy.js +8 -5
- package/dist/steps/remapKeys.d.ts +10 -10
- package/dist/steps/remapKeys.js +14 -7
- package/dist/steps/reverse.d.ts +8 -8
- package/dist/steps/reverse.js +10 -7
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +24 -9
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +56 -55
- package/dist/utils.js +179 -59
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -8
|
@@ -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,32 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { LayerPlan } from "../engine/LayerPlan.js";
|
|
3
|
-
import type { GrafastError } from "../error.js";
|
|
4
|
-
import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../interfaces.js";
|
|
5
|
-
import type { ListCapableStep } from "../step.js";
|
|
6
|
-
import { ExecutableStep } from "../step.js";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare class ApplyTransformsStep extends ExecutableStep {
|
|
11
|
-
static $$export: {
|
|
12
|
-
moduleName: string;
|
|
13
|
-
exportName: string;
|
|
14
|
-
};
|
|
15
|
-
isSyncAndSafe: boolean;
|
|
16
|
-
/** Set during query planning. */
|
|
17
|
-
itemStepId: number;
|
|
18
|
-
/**
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
subroutineLayer: LayerPlan<LayerPlanReasonSubroutine>;
|
|
22
|
-
constructor(listPlan: ListCapableStep<any, any>);
|
|
23
|
-
execute(_count: number, values: [GrafastValuesList<any[] | null | undefined | GrafastError>], extra: ExecutionExtra): Promise<GrafastResultsList<any[]>>;
|
|
24
|
-
}
|
|
1
|
+
import { Step } from "../step.js";
|
|
25
2
|
/**
|
|
26
3
|
* If you want to use a step that might represent a list and you need all of
|
|
27
4
|
* the `listItem` transforms to have already taken place (e.g. you're going to
|
|
28
5
|
* send the result to an external service) rather than processing them through
|
|
29
6
|
* the GraphQL response, then you may need to call `applyTransforms` on it.
|
|
30
7
|
*/
|
|
31
|
-
export declare function applyTransforms($step:
|
|
8
|
+
export declare function applyTransforms($step: Step): Step<any>;
|
|
32
9
|
//# sourceMappingURL=applyTransforms.d.ts.map
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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");
|
|
7
8
|
const executeBucket_js_1 = require("../engine/executeBucket.js");
|
|
8
9
|
const LayerPlan_js_1 = require("../engine/LayerPlan.js");
|
|
9
10
|
const withGlobalLayerPlan_js_1 = require("../engine/lib/withGlobalLayerPlan.js");
|
|
11
|
+
const error_js_1 = require("../error.js");
|
|
12
|
+
const interfaces_js_1 = require("../interfaces.js");
|
|
10
13
|
const step_js_1 = require("../step.js");
|
|
11
14
|
const __item_js_1 = require("./__item.js");
|
|
15
|
+
const connection_js_1 = require("./connection.js");
|
|
12
16
|
/**
|
|
13
17
|
* @internal
|
|
14
18
|
*/
|
|
15
|
-
class ApplyTransformsStep extends step_js_1.
|
|
19
|
+
class ApplyTransformsStep extends step_js_1.Step {
|
|
16
20
|
static { this.$$export = {
|
|
17
21
|
moduleName: "grafast",
|
|
18
22
|
exportName: "ApplyTransformsStep",
|
|
19
23
|
}; }
|
|
20
|
-
constructor(
|
|
24
|
+
constructor($step) {
|
|
21
25
|
super();
|
|
22
26
|
// OPTIMIZE: if all the steps in the inner bucket are synchronous then theoretically we can be synchronous too
|
|
23
27
|
this.isSyncAndSafe = false;
|
|
28
|
+
const listPlan = (0, connection_js_1.itemsOrStep)($step);
|
|
24
29
|
this.addDependency(listPlan);
|
|
25
30
|
// Plan this subroutine
|
|
26
31
|
this.subroutineLayer = new LayerPlan_js_1.LayerPlan(this.operationPlan, this.layerPlan, {
|
|
@@ -47,33 +52,44 @@ class ApplyTransformsStep extends step_js_1.ExecutableStep {
|
|
|
47
52
|
this.subroutineLayer.setRootStep(itemPlan);
|
|
48
53
|
this.operationPlan.finishSubroutine(this, this.subroutineLayer);
|
|
49
54
|
}
|
|
50
|
-
async execute(
|
|
55
|
+
async execute({ indexMap, values: [values0], extra, }) {
|
|
51
56
|
const bucket = extra._bucket;
|
|
52
57
|
const childLayerPlan = this.subroutineLayer;
|
|
53
|
-
const copyStepIds = childLayerPlan
|
|
58
|
+
const { copyStepIds, rootStep } = childLayerPlan;
|
|
54
59
|
const store = new Map();
|
|
55
60
|
const polymorphicPathList = [];
|
|
56
61
|
const iterators = [];
|
|
57
62
|
const map = new Map();
|
|
58
63
|
let size = 0;
|
|
59
64
|
// ENHANCE: do this better!
|
|
60
|
-
const
|
|
65
|
+
const itemStep = this.operationPlan.dangerouslyGetStep(this.itemStepId);
|
|
66
|
+
const itemStepId = itemStep.id;
|
|
61
67
|
if (itemStepId == null) {
|
|
62
68
|
throw new Error("GrafastInternalError<b3a2bff9-15c6-47e2-aa82-19c862324f1a>: listItem layer plan has no rootStepId");
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
if (itemStep._isUnary) {
|
|
71
|
+
store.set(itemStepId, (0, executeBucket_js_1.unaryExecutionValue)(values0.unaryValue()));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
store.set(itemStepId, (0, executeBucket_js_1.batchExecutionValue)([]));
|
|
75
|
+
}
|
|
76
|
+
for (const stepId of copyStepIds) {
|
|
77
|
+
const ev = bucket.store.get(stepId);
|
|
78
|
+
if (!ev) {
|
|
79
|
+
throw new Error(`GrafastInternalError<68675bbd-bc15-4c4a-902a-61c0de616325>: unary step '${stepId}' (${this.operationPlan.dangerouslyGetStep(stepId)}) listed in copyStepIds but not available in parent bucket for ${this}`);
|
|
80
|
+
}
|
|
81
|
+
if (ev.isBatch) {
|
|
82
|
+
// Prepare store with an empty list for each copyBatchPlanId
|
|
83
|
+
store.set(stepId, (0, executeBucket_js_1.batchExecutionValue)([]));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
store.set(stepId, ev);
|
|
70
87
|
}
|
|
71
88
|
}
|
|
72
|
-
const listValues = values[0];
|
|
73
89
|
// We'll typically be creating more listItem bucket entries than we
|
|
74
90
|
// have parent buckets, so we must "multiply up" the store entries.
|
|
75
|
-
|
|
76
|
-
const list =
|
|
91
|
+
indexMap((originalIndex) => {
|
|
92
|
+
const list = values0.at(originalIndex);
|
|
77
93
|
if (Array.isArray(list)) {
|
|
78
94
|
const newIndexes = [];
|
|
79
95
|
map.set(originalIndex, newIndexes);
|
|
@@ -85,40 +101,47 @@ class ApplyTransformsStep extends step_js_1.ExecutableStep {
|
|
|
85
101
|
// Copying across the iterators because we do NOT call outputBucket,
|
|
86
102
|
// so we need to ensure any streams are cleaned up.
|
|
87
103
|
iterators[newIndex] = bucket.iterators[originalIndex];
|
|
88
|
-
store.get(itemStepId)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
const ev = store.get(itemStepId);
|
|
105
|
+
if (ev.isBatch) {
|
|
106
|
+
// TODO: check for error?
|
|
107
|
+
ev._setResult(newIndex, list[j], 0);
|
|
108
|
+
}
|
|
109
|
+
for (const copyStepId of copyStepIds) {
|
|
110
|
+
const ev = store.get(copyStepId);
|
|
111
|
+
if (ev.isBatch) {
|
|
112
|
+
const orig = bucket.store.get(copyStepId);
|
|
113
|
+
ev._setResult(newIndex, orig.at(originalIndex), orig._flagsAt(originalIndex));
|
|
114
|
+
}
|
|
92
115
|
}
|
|
93
116
|
}
|
|
94
117
|
}
|
|
95
|
-
}
|
|
118
|
+
});
|
|
96
119
|
if (size > 0) {
|
|
97
120
|
const childBucket = (0, executeBucket_js_1.newBucket)({
|
|
98
121
|
layerPlan: childLayerPlan,
|
|
99
122
|
size,
|
|
100
123
|
store,
|
|
101
|
-
|
|
124
|
+
flagUnion: bucket.flagUnion,
|
|
102
125
|
polymorphicPathList,
|
|
103
126
|
iterators,
|
|
104
127
|
}, bucket.metaByMetaKey);
|
|
105
128
|
await (0, executeBucket_js_1.executeBucket)(childBucket, extra._requestContext);
|
|
106
129
|
}
|
|
107
|
-
const depResults = store.get(
|
|
108
|
-
return
|
|
130
|
+
const depResults = store.get(rootStep.id);
|
|
131
|
+
return indexMap((originalIndex) => {
|
|
132
|
+
const list = values0.at(originalIndex);
|
|
109
133
|
if (list == null) {
|
|
110
134
|
return list;
|
|
111
135
|
}
|
|
112
136
|
const indexes = map.get(originalIndex);
|
|
113
137
|
if (!Array.isArray(list) || !Array.isArray(indexes)) {
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
return null;
|
|
138
|
+
// Not a list value; just pass it straight through
|
|
139
|
+
return list;
|
|
117
140
|
}
|
|
118
141
|
const values = indexes.map((idx) => {
|
|
119
|
-
const val = depResults
|
|
120
|
-
if (
|
|
121
|
-
|
|
142
|
+
const val = depResults.at(idx);
|
|
143
|
+
if (depResults._flagsAt(idx) & interfaces_js_1.FLAG_ERROR) {
|
|
144
|
+
return (0, error_js_1.flagError)(val);
|
|
122
145
|
}
|
|
123
146
|
return val;
|
|
124
147
|
});
|
|
@@ -140,12 +163,11 @@ exports.ApplyTransformsStep = ApplyTransformsStep;
|
|
|
140
163
|
*/
|
|
141
164
|
function applyTransforms($step) {
|
|
142
165
|
if ((0, step_js_1.isListCapableStep)($step)) {
|
|
143
|
-
return new ApplyTransformsStep($step);
|
|
166
|
+
return $step.operationPlan.cacheStep($step, "GrafastInternal:applyTransforms()", "", () => new ApplyTransformsStep($step));
|
|
144
167
|
}
|
|
145
168
|
else {
|
|
146
169
|
// No eval necessary
|
|
147
170
|
return $step;
|
|
148
171
|
}
|
|
149
172
|
}
|
|
150
|
-
exports.applyTransforms = applyTransforms;
|
|
151
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
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UnbatchedExecutionExtra } from "../interfaces.js";
|
|
2
|
+
import type { Step } from "../step.js";
|
|
3
|
+
import { UnbatchedStep } from "../step.js";
|
|
4
|
+
declare const unaryOperators: readonly ["null", "not null", "exists", "not exists"];
|
|
5
|
+
type UnaryOperator = (typeof unaryOperators)[number];
|
|
6
|
+
declare const binaryOperators: readonly ["===", "!=="];
|
|
7
|
+
type BinaryOperator = (typeof binaryOperators)[number];
|
|
8
|
+
type Operator = UnaryOperator | BinaryOperator;
|
|
9
|
+
export declare class ConditionStep extends UnbatchedStep<boolean> {
|
|
10
|
+
private op;
|
|
11
|
+
static $$export: {
|
|
12
|
+
moduleName: string;
|
|
13
|
+
exportName: string;
|
|
14
|
+
};
|
|
15
|
+
isSyncAndSafe: boolean;
|
|
16
|
+
allowMultipleOptimizations: boolean;
|
|
17
|
+
constructor(op: Operator, step1: Step, step2?: Step);
|
|
18
|
+
toStringMeta(): string | null;
|
|
19
|
+
finalize(): void;
|
|
20
|
+
private makeUnbatchedExecute;
|
|
21
|
+
unbatchedExecute(_extra: UnbatchedExecutionExtra, _value1: any, _value2: any): boolean;
|
|
22
|
+
}
|
|
23
|
+
type $Boolean = Step<boolean>;
|
|
24
|
+
declare function condition(op: "null", step: Step): $Boolean;
|
|
25
|
+
declare function condition(op: "not null", step: Step): $Boolean;
|
|
26
|
+
declare function condition(op: "exists", step: Step): $Boolean;
|
|
27
|
+
declare function condition(op: "not exists", step: Step): $Boolean;
|
|
28
|
+
declare function condition(op: "===", step1: Step, step2: Step): $Boolean;
|
|
29
|
+
declare function condition(op: "!==", step1: Step, step2: Step): $Boolean;
|
|
30
|
+
export { condition };
|
|
31
|
+
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionStep = void 0;
|
|
4
|
+
exports.condition = condition;
|
|
5
|
+
const step_js_1 = require("../step.js");
|
|
6
|
+
const unaryOperators = ["null", "not null", "exists", "not exists"];
|
|
7
|
+
const binaryOperators = ["===", "!=="];
|
|
8
|
+
class ConditionStep extends step_js_1.UnbatchedStep {
|
|
9
|
+
static { this.$$export = {
|
|
10
|
+
moduleName: "grafast",
|
|
11
|
+
exportName: "ConditionStep",
|
|
12
|
+
}; }
|
|
13
|
+
constructor(op, step1, step2) {
|
|
14
|
+
super();
|
|
15
|
+
this.op = op;
|
|
16
|
+
this.isSyncAndSafe = true;
|
|
17
|
+
this.allowMultipleOptimizations = true;
|
|
18
|
+
if (!step2) {
|
|
19
|
+
// unary
|
|
20
|
+
if (!unaryOperators.includes(op)) {
|
|
21
|
+
throw new Error(`Unary operator '${op}' is not known; supported operators: ${unaryOperators.join(", ")}`);
|
|
22
|
+
}
|
|
23
|
+
this.addDependency(step1);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// binary
|
|
27
|
+
if (!binaryOperators.includes(op)) {
|
|
28
|
+
throw new Error(`Unary operator '${op}' is not known; supported operators: ${binaryOperators.join(", ")}`);
|
|
29
|
+
}
|
|
30
|
+
this.addDependency(step1);
|
|
31
|
+
this.addDependency(step2);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
toStringMeta() {
|
|
35
|
+
if (unaryOperators.includes(this.op)) {
|
|
36
|
+
return `${this.op}`;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const $dep1 = this.getDepOptions(0).step;
|
|
40
|
+
const $dep2 = this.getDepOptions(1).step;
|
|
41
|
+
return `${$dep1.id} ${this.op} ${$dep2.id}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
finalize() {
|
|
45
|
+
this.unbatchedExecute = this.makeUnbatchedExecute();
|
|
46
|
+
super.finalize();
|
|
47
|
+
}
|
|
48
|
+
makeUnbatchedExecute() {
|
|
49
|
+
switch (this.op) {
|
|
50
|
+
case "null":
|
|
51
|
+
return isNull;
|
|
52
|
+
case "not null":
|
|
53
|
+
return isNotNull;
|
|
54
|
+
case "exists":
|
|
55
|
+
return isNotNullish;
|
|
56
|
+
case "not exists":
|
|
57
|
+
return isNullish;
|
|
58
|
+
case "===":
|
|
59
|
+
return isEqual;
|
|
60
|
+
case "!==":
|
|
61
|
+
return isNotEqual;
|
|
62
|
+
default: {
|
|
63
|
+
const never = this.op;
|
|
64
|
+
throw new Error(`Operator ${never} is not supported`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
unbatchedExecute(_extra, _value1, _value2) {
|
|
69
|
+
throw new Error(`${this} was not finalized?`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ConditionStep = ConditionStep;
|
|
73
|
+
function isNull(_extra, value1) {
|
|
74
|
+
return value1 === null;
|
|
75
|
+
}
|
|
76
|
+
function isNotNull(_extra, value1) {
|
|
77
|
+
return value1 !== null;
|
|
78
|
+
}
|
|
79
|
+
function isNullish(_extra, value1) {
|
|
80
|
+
return value1 == null;
|
|
81
|
+
}
|
|
82
|
+
function isNotNullish(_extra, value1) {
|
|
83
|
+
return value1 != null;
|
|
84
|
+
}
|
|
85
|
+
function isEqual(_extra, value1, value2) {
|
|
86
|
+
return value1 === value2;
|
|
87
|
+
}
|
|
88
|
+
function isNotEqual(_extra, value1, value2) {
|
|
89
|
+
return value1 !== value2;
|
|
90
|
+
}
|
|
91
|
+
function condition(op, step1, step2) {
|
|
92
|
+
return new ConditionStep(op, step1, step2);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=condition.js.map
|