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
package/dist/engine/LayerPlan.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LayerPlan =
|
|
3
|
+
exports.LayerPlan = void 0;
|
|
4
|
+
exports.isBranchingLayerPlan = isBranchingLayerPlan;
|
|
5
|
+
exports.isDeferredLayerPlan = isDeferredLayerPlan;
|
|
6
|
+
exports.isPolymorphicLayerPlan = isPolymorphicLayerPlan;
|
|
4
7
|
const tslib_1 = require("tslib");
|
|
5
8
|
const lru_1 = tslib_1.__importDefault(require("@graphile/lru"));
|
|
6
9
|
const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
|
|
7
10
|
const assert = tslib_1.__importStar(require("../assert.js"));
|
|
8
|
-
const error_js_1 = require("../error.js");
|
|
9
11
|
const inspect_js_1 = require("../inspect.js");
|
|
12
|
+
const interfaces_js_1 = require("../interfaces.js");
|
|
10
13
|
const polymorphic_js_1 = require("../polymorphic.js");
|
|
11
14
|
const executeBucket_js_1 = require("./executeBucket.js");
|
|
12
15
|
function isBranchingLayerPlan(layerPlan) {
|
|
13
16
|
return layerPlan.reason.type === "polymorphic";
|
|
14
17
|
}
|
|
15
|
-
exports.isBranchingLayerPlan = isBranchingLayerPlan;
|
|
16
18
|
function isDeferredLayerPlan(layerPlan) {
|
|
17
19
|
const t = layerPlan.reason.type;
|
|
18
|
-
return (t === "
|
|
20
|
+
return ((t === "listItem" && layerPlan.reason.stream != null) ||
|
|
19
21
|
t === "subscription" ||
|
|
20
22
|
t === "mutationField" ||
|
|
21
23
|
t === "defer");
|
|
22
24
|
}
|
|
23
|
-
exports.isDeferredLayerPlan = isDeferredLayerPlan;
|
|
24
25
|
function isPolymorphicLayerPlan(layerPlan) {
|
|
25
26
|
const t = layerPlan.reason.type;
|
|
26
27
|
return t === "polymorphic";
|
|
27
28
|
}
|
|
28
|
-
exports.isPolymorphicLayerPlan = isPolymorphicLayerPlan;
|
|
29
29
|
/**
|
|
30
30
|
* A LayerPlan represents (via "reason") either the root (root), when something
|
|
31
31
|
* happens at a later time (mutationField, defer), when plurality changes
|
|
@@ -65,7 +65,6 @@ class LayerPlan {
|
|
|
65
65
|
*
|
|
66
66
|
* - root: the `operationPlan.rootValue`
|
|
67
67
|
* - listItem: the `__ItemStep`
|
|
68
|
-
* - stream: also the `__ItemStep`
|
|
69
68
|
* - subscription: also the `__ItemStep`
|
|
70
69
|
* - mutationField: the result plan of the mutation field
|
|
71
70
|
* - defer: the parent layer's rootStep (defer always results in an object, unless an error occurs)
|
|
@@ -76,8 +75,8 @@ class LayerPlan {
|
|
|
76
75
|
*/
|
|
77
76
|
this.rootStep = null;
|
|
78
77
|
/**
|
|
79
|
-
* Which
|
|
80
|
-
* be "copied across" to this bucket because
|
|
78
|
+
* Which steps the results for which are available in a parent bucket need to
|
|
79
|
+
* be "copied across" to this bucket because steps in this bucket still
|
|
81
80
|
* reference them?
|
|
82
81
|
*
|
|
83
82
|
* @internal
|
|
@@ -89,6 +88,23 @@ class LayerPlan {
|
|
|
89
88
|
this.steps = [];
|
|
90
89
|
/** @internal */
|
|
91
90
|
this.pendingSteps = [];
|
|
91
|
+
/**
|
|
92
|
+
* This goes along with `parentStep` in the reason, except it applies to all
|
|
93
|
+
* layer plan types and we figure it out automatically from the parent layer
|
|
94
|
+
* plan. If this step has an error at a given index, then it should be
|
|
95
|
+
* treated as if the parentStep had an error at that same index.
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
this.parentSideEffectStep = null;
|
|
100
|
+
/**
|
|
101
|
+
* This tracks the latest seen side effect at the current point in planning
|
|
102
|
+
* (such that created steps take this to be their implicitSideEffectStep).
|
|
103
|
+
* This isn't used once planning is complete.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
this.latestSideEffectStep = null;
|
|
92
108
|
/**
|
|
93
109
|
* Describes the order in which the steps within this LayerPlan are executed.
|
|
94
110
|
*
|
|
@@ -97,6 +113,13 @@ class LayerPlan {
|
|
|
97
113
|
* @internal
|
|
98
114
|
*/
|
|
99
115
|
this.phases = [];
|
|
116
|
+
this._hasSetRootStep = false;
|
|
117
|
+
// This layer plan is dependent on the latest side effect. Note that when
|
|
118
|
+
// we set a `rootStep` later, if the root step is dependent on this step
|
|
119
|
+
// (directly or indirectly) we will clear this property.
|
|
120
|
+
this.parentSideEffectStep = parentLayerPlan?.latestSideEffectStep ?? null;
|
|
121
|
+
// There has yet to be any side effects created in this layer.
|
|
122
|
+
this.latestSideEffectStep = null;
|
|
100
123
|
this.stepsByConstructor = new Map();
|
|
101
124
|
if (parentLayerPlan !== null) {
|
|
102
125
|
this.depth = parentLayerPlan.depth + 1;
|
|
@@ -132,8 +155,8 @@ class LayerPlan {
|
|
|
132
155
|
const reasonExtra = this.reason.type === "polymorphic"
|
|
133
156
|
? `{${this.reason.typeNames.join(",")}}`
|
|
134
157
|
: "";
|
|
135
|
-
const deps = this.copyStepIds.length > 0 ?
|
|
136
|
-
return `LayerPlan<${this.id}${chain}?${this.reason.type}${reasonExtra}!${this.rootStep?.id ?? "x"}${deps}>`;
|
|
158
|
+
const deps = this.copyStepIds.length > 0 ? `/${this.copyStepIds}` : "";
|
|
159
|
+
return `LayerPlan<${this.id}${chain}${this.parentSideEffectStep ? `^${this.parentSideEffectStep.id}` : ""}?${this.reason.type}${reasonExtra}!${this.rootStep?.id ?? "x"}${deps}>`;
|
|
137
160
|
}
|
|
138
161
|
print(depth = 0) {
|
|
139
162
|
const output = [`${" ".repeat(depth * 2)}${this}`];
|
|
@@ -143,7 +166,15 @@ class LayerPlan {
|
|
|
143
166
|
return output.join("\n");
|
|
144
167
|
}
|
|
145
168
|
setRootStep($root) {
|
|
169
|
+
if (this._hasSetRootStep) {
|
|
170
|
+
throw new Error(`Set root step on ${this} more than once`);
|
|
171
|
+
}
|
|
172
|
+
this._hasSetRootStep = true;
|
|
146
173
|
this.operationPlan.stepTracker.setLayerPlanRootStep(this, $root);
|
|
174
|
+
// NOTE: we may clear `this.parentSideEffectStep` based on the `$root` step
|
|
175
|
+
// having an explicit dependency on `this.parentSideEffectStep`; but that
|
|
176
|
+
// will be done as part of `OperationPlan::finalizeLayerPlans()` because
|
|
177
|
+
// steps aren't assigned `implicitSideEffectStep`s until that point.
|
|
147
178
|
}
|
|
148
179
|
/** @internal Use plan.getStep(id) instead. */
|
|
149
180
|
getStep(id, requestingStep) {
|
|
@@ -153,45 +184,76 @@ class LayerPlan {
|
|
|
153
184
|
_addStep(step) {
|
|
154
185
|
return this.operationPlan._addStep(step);
|
|
155
186
|
}
|
|
156
|
-
/** @internal */
|
|
157
|
-
_addModifierStep(step) {
|
|
158
|
-
return this.operationPlan._addModifierStep(step);
|
|
159
|
-
}
|
|
160
187
|
finalize() {
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
188
|
+
if (
|
|
189
|
+
// this.reason.type === "nullableBoundary" ||
|
|
190
|
+
this.reason.type === "listItem") {
|
|
191
|
+
const u = this.copyStepIds.length;
|
|
192
|
+
const signature = `${this.reason.type[0]}_${u}`;
|
|
193
|
+
withNewBucketFactory(signature, u, this.reason.type, (fn) => {
|
|
166
194
|
this.newBucket = fn(this.copyStepIds);
|
|
167
195
|
});
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
newBucket(parentBucket) {
|
|
171
|
-
const copyStepIds = this
|
|
199
|
+
const { copyStepIds } = this;
|
|
172
200
|
const store = new Map();
|
|
173
201
|
const polymorphicPathList = this.reason.type === "mutationField"
|
|
174
202
|
? parentBucket.polymorphicPathList
|
|
175
203
|
: [];
|
|
176
204
|
const iterators = this.reason.type === "mutationField" ? parentBucket.iterators : [];
|
|
177
205
|
const map = new Map();
|
|
206
|
+
const $parentSideEffect = this.parentSideEffectStep;
|
|
207
|
+
let parentSideEffectValue;
|
|
208
|
+
if ($parentSideEffect) {
|
|
209
|
+
parentSideEffectValue = parentBucket.store.get($parentSideEffect.id);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
parentSideEffectValue = null;
|
|
213
|
+
}
|
|
178
214
|
let size = 0;
|
|
179
215
|
switch (this.reason.type) {
|
|
180
216
|
case "nullableBoundary": {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const nullableStepStore = parentBucket.store.get(itemStepId);
|
|
184
|
-
if (!nullableStepStore) {
|
|
185
|
-
throw new Error(`GrafastInternalError<017dc8bf-1db1-4983-a41e-e69c6652e4c7>: could not find entry '${itemStepId}' (${parentBucket.layerPlan.operationPlan.dangerouslyGetStep(itemStepId)}) in store for ${parentBucket.layerPlan}`);
|
|
217
|
+
if (this.rootStep == null) {
|
|
218
|
+
throw new Error("GrafastInternalError<f8136364-46c7-4886-b2ae-51319826f97d>: nullableStepStore layer plan has no rootStepId");
|
|
186
219
|
}
|
|
220
|
+
const itemStepId = this.rootStep.id;
|
|
187
221
|
// PERF: if parent bucket has no nulls/errors in `itemStepId`
|
|
188
222
|
// then we can just copy everything wholesale rather than building
|
|
189
223
|
// new arrays and looping.
|
|
190
224
|
const hasNoNullsOrErrors = false;
|
|
191
|
-
if (
|
|
225
|
+
if (this.rootStep._isUnary) {
|
|
226
|
+
const fieldValue = parentBucket.store.get(itemStepId);
|
|
227
|
+
const forbiddenFlags = fieldValue._entryFlags & interfaces_js_1.FORBIDDEN_BY_NULLABLE_BOUNDARY_FLAGS;
|
|
228
|
+
if (forbiddenFlags) {
|
|
229
|
+
size = 0;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
store.set(itemStepId, fieldValue);
|
|
233
|
+
for (const stepId of copyStepIds) {
|
|
234
|
+
store.set(stepId, parentBucket.store.get(stepId));
|
|
235
|
+
}
|
|
236
|
+
const parentBucketSize = parentBucket.size;
|
|
237
|
+
for (let originalIndex = 0; originalIndex < parentBucketSize; originalIndex++) {
|
|
238
|
+
if (parentSideEffectValue === null ||
|
|
239
|
+
!(parentSideEffectValue._flagsAt(originalIndex) & interfaces_js_1.FLAG_ERROR)) {
|
|
240
|
+
const newIndex = size++;
|
|
241
|
+
map.set(originalIndex, newIndex);
|
|
242
|
+
polymorphicPathList[newIndex] =
|
|
243
|
+
parentBucket.polymorphicPathList[originalIndex];
|
|
244
|
+
iterators[newIndex] = parentBucket.iterators[originalIndex];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else if (hasNoNullsOrErrors) {
|
|
250
|
+
const nullableStepStore = parentBucket.store.get(itemStepId);
|
|
251
|
+
if (!nullableStepStore) {
|
|
252
|
+
throw new Error(`GrafastInternalError<017dc8bf-1db1-4983-a41e-e69c6652e4c7>: could not find entry '${itemStepId}' (${parentBucket.layerPlan.operationPlan.dangerouslyGetStep(itemStepId)}) in store for ${parentBucket.layerPlan}`);
|
|
253
|
+
}
|
|
192
254
|
store.set(itemStepId, nullableStepStore);
|
|
193
|
-
for (const
|
|
194
|
-
store.set(
|
|
255
|
+
for (const stepId of copyStepIds) {
|
|
256
|
+
store.set(stepId, parentBucket.store.get(stepId));
|
|
195
257
|
}
|
|
196
258
|
for (let originalIndex = 0; originalIndex < parentBucket.size; originalIndex++) {
|
|
197
259
|
const newIndex = size++;
|
|
@@ -203,26 +265,41 @@ class LayerPlan {
|
|
|
203
265
|
}
|
|
204
266
|
else {
|
|
205
267
|
const itemStepIdList = [];
|
|
206
|
-
store.set(itemStepId, itemStepIdList);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
268
|
+
store.set(itemStepId, (0, executeBucket_js_1.batchExecutionValue)(itemStepIdList));
|
|
269
|
+
for (const stepId of copyStepIds) {
|
|
270
|
+
const ev = parentBucket.store.get(stepId);
|
|
271
|
+
if (ev.isBatch) {
|
|
272
|
+
// Prepare store with an empty list for each copyPlanId
|
|
273
|
+
store.set(stepId, (0, executeBucket_js_1.batchExecutionValue)([]));
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
store.set(stepId, ev);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const nullableStepStore = parentBucket.store.get(itemStepId);
|
|
280
|
+
if (!nullableStepStore) {
|
|
281
|
+
throw new Error(`GrafastInternalError<017dc8bf-1db1-4983-a41e-e69c6652e4c7>: could not find entry '${itemStepId}' (${parentBucket.layerPlan.operationPlan.dangerouslyGetStep(itemStepId)}) in store for ${parentBucket.layerPlan}`);
|
|
210
282
|
}
|
|
211
283
|
// We'll typically be creating fewer nullableBoundary bucket entries
|
|
212
284
|
// than we have parent bucket entries (because we exclude nulls), so
|
|
213
285
|
// we must "multiply up" (down) the store entries.
|
|
214
286
|
for (let originalIndex = 0; originalIndex < parentBucket.size; originalIndex++) {
|
|
215
|
-
|
|
216
|
-
|
|
287
|
+
if ((parentSideEffectValue === null ||
|
|
288
|
+
!(parentSideEffectValue._flagsAt(originalIndex) & interfaces_js_1.FLAG_ERROR)) &&
|
|
289
|
+
!(nullableStepStore._flagsAt(originalIndex) & interfaces_js_1.FLAG_NULL)) {
|
|
217
290
|
const newIndex = size++;
|
|
218
291
|
map.set(originalIndex, newIndex);
|
|
292
|
+
const fieldValue = nullableStepStore.at(originalIndex);
|
|
219
293
|
itemStepIdList[newIndex] = fieldValue;
|
|
220
294
|
polymorphicPathList[newIndex] =
|
|
221
295
|
parentBucket.polymorphicPathList[originalIndex];
|
|
222
296
|
iterators[newIndex] = parentBucket.iterators[originalIndex];
|
|
223
|
-
for (const
|
|
224
|
-
store.get(
|
|
225
|
-
|
|
297
|
+
for (const stepId of copyStepIds) {
|
|
298
|
+
const ev = store.get(stepId);
|
|
299
|
+
if (ev.isBatch) {
|
|
300
|
+
const orig = parentBucket.store.get(stepId);
|
|
301
|
+
ev._copyResult(newIndex, orig, originalIndex);
|
|
302
|
+
}
|
|
226
303
|
}
|
|
227
304
|
}
|
|
228
305
|
}
|
|
@@ -235,32 +312,51 @@ class LayerPlan {
|
|
|
235
312
|
if (!listStepStore) {
|
|
236
313
|
throw new Error(`GrafastInternalError<314865b0-f7e8-4e81-b966-56e5a0de562e>: could not find entry '${listStepId}' (${parentBucket.layerPlan.operationPlan.dangerouslyGetStep(listStepId)}) in store for layerPlan ${parentBucket.layerPlan}`);
|
|
237
314
|
}
|
|
238
|
-
|
|
239
|
-
if (itemStepId == null) {
|
|
315
|
+
if (this.rootStep == null) {
|
|
240
316
|
throw new Error("GrafastInternalError<b3a2bff9-15c6-47e2-aa82-19c862324f1a>: listItem layer plan has no rootStepId");
|
|
241
317
|
}
|
|
242
|
-
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
318
|
+
const itemStepId = this.rootStep.id;
|
|
319
|
+
// Item steps are **NOT** unary
|
|
320
|
+
if (this.rootStep._isUnary) {
|
|
321
|
+
throw new Error("listItem layer plan can't have a unary root step!");
|
|
322
|
+
}
|
|
323
|
+
const ev = (0, executeBucket_js_1.batchExecutionValue)([]);
|
|
324
|
+
store.set(itemStepId, ev);
|
|
325
|
+
for (const stepId of copyStepIds) {
|
|
326
|
+
// Deliberate shadowing
|
|
327
|
+
const ev = parentBucket.store.get(stepId);
|
|
328
|
+
if (ev.isBatch) {
|
|
329
|
+
// Prepare store with an empty list for each copyPlanId
|
|
330
|
+
store.set(stepId, (0, executeBucket_js_1.batchExecutionValue)([]));
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
store.set(stepId, ev);
|
|
334
|
+
}
|
|
246
335
|
}
|
|
247
336
|
// We'll typically be creating more listItem bucket entries than we
|
|
248
337
|
// have parent buckets, so we must "multiply up" the store entries.
|
|
249
338
|
for (let originalIndex = 0; originalIndex < parentBucket.size; originalIndex++) {
|
|
250
|
-
const list = listStepStore
|
|
251
|
-
if (
|
|
339
|
+
const list = listStepStore.at(originalIndex);
|
|
340
|
+
if ((parentSideEffectValue === null ||
|
|
341
|
+
!(parentSideEffectValue._flagsAt(originalIndex) & interfaces_js_1.FLAG_ERROR)) &&
|
|
342
|
+
Array.isArray(list)) {
|
|
252
343
|
const newIndexes = [];
|
|
253
344
|
map.set(originalIndex, newIndexes);
|
|
254
345
|
for (let j = 0, l = list.length; j < l; j++) {
|
|
255
346
|
const newIndex = size++;
|
|
256
347
|
newIndexes.push(newIndex);
|
|
257
|
-
|
|
348
|
+
ev.entries[newIndex] = list[j];
|
|
349
|
+
// TODO: are these the right flags?
|
|
350
|
+
ev._flags[newIndex] = list[j] == null ? interfaces_js_1.FLAG_NULL : interfaces_js_1.NO_FLAGS;
|
|
258
351
|
polymorphicPathList[newIndex] =
|
|
259
352
|
parentBucket.polymorphicPathList[originalIndex];
|
|
260
353
|
iterators[newIndex] = parentBucket.iterators[originalIndex];
|
|
261
|
-
for (const
|
|
262
|
-
store.get(
|
|
263
|
-
|
|
354
|
+
for (const stepId of copyStepIds) {
|
|
355
|
+
const ev = store.get(stepId);
|
|
356
|
+
if (ev.isBatch) {
|
|
357
|
+
const orig = parentBucket.store.get(stepId);
|
|
358
|
+
ev._copyResult(newIndex, orig, originalIndex);
|
|
359
|
+
}
|
|
264
360
|
}
|
|
265
361
|
}
|
|
266
362
|
}
|
|
@@ -273,8 +369,8 @@ class LayerPlan {
|
|
|
273
369
|
for (let i = 0; i < parentBucket.size; i++) {
|
|
274
370
|
map.set(i, i);
|
|
275
371
|
}
|
|
276
|
-
for (const
|
|
277
|
-
store.set(
|
|
372
|
+
for (const stepId of copyStepIds) {
|
|
373
|
+
store.set(stepId, parentBucket.store.get(stepId));
|
|
278
374
|
}
|
|
279
375
|
break;
|
|
280
376
|
}
|
|
@@ -287,20 +383,28 @@ class LayerPlan {
|
|
|
287
383
|
// We're only copying over the entries that match this type (note:
|
|
288
384
|
// they may end up being null, but that's okay)
|
|
289
385
|
const targetTypeNames = this.reason.typeNames;
|
|
290
|
-
for (const
|
|
291
|
-
store.
|
|
292
|
-
if (!
|
|
293
|
-
throw new Error(`GrafastInternalError<548f0d84-4556-4189-8655-fb16aa3345a6>: new bucket for ${this} wants to copy ${this.operationPlan.dangerouslyGetStep(
|
|
386
|
+
for (const stepId of copyStepIds) {
|
|
387
|
+
const ev = parentBucket.store.get(stepId);
|
|
388
|
+
if (!ev) {
|
|
389
|
+
throw new Error(`GrafastInternalError<548f0d84-4556-4189-8655-fb16aa3345a6>: new bucket for ${this} wants to copy ${this.operationPlan.dangerouslyGetStep(stepId)}, but bucket for ${parentBucket.layerPlan} doesn't contain that plan`);
|
|
390
|
+
}
|
|
391
|
+
if (ev.isBatch) {
|
|
392
|
+
store.set(stepId, (0, executeBucket_js_1.batchExecutionValue)([]));
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
store.set(stepId, ev);
|
|
294
396
|
}
|
|
295
397
|
}
|
|
296
398
|
for (let originalIndex = 0; originalIndex < parentBucket.size; originalIndex++) {
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
399
|
+
const flags = polymorphicPlanStore._flagsAt(originalIndex);
|
|
400
|
+
if (flags & (interfaces_js_1.FLAG_ERROR | interfaces_js_1.FLAG_INHIBITED | interfaces_js_1.FLAG_NULL)) {
|
|
299
401
|
continue;
|
|
300
402
|
}
|
|
301
|
-
if (
|
|
403
|
+
if (parentSideEffectValue !== null &&
|
|
404
|
+
parentSideEffectValue._flagsAt(originalIndex) & interfaces_js_1.FLAG_ERROR) {
|
|
302
405
|
continue;
|
|
303
406
|
}
|
|
407
|
+
const value = polymorphicPlanStore.at(originalIndex);
|
|
304
408
|
const typeName = (0, polymorphic_js_1.resolveType)(value);
|
|
305
409
|
if (!targetTypeNames.includes(typeName)) {
|
|
306
410
|
continue;
|
|
@@ -314,8 +418,11 @@ class LayerPlan {
|
|
|
314
418
|
polymorphicPathList[newIndex] = newPolymorphicPath;
|
|
315
419
|
iterators[newIndex] = parentBucket.iterators[originalIndex];
|
|
316
420
|
for (const planId of copyStepIds) {
|
|
317
|
-
store.get(planId)
|
|
318
|
-
|
|
421
|
+
const ev = store.get(planId);
|
|
422
|
+
if (ev.isBatch) {
|
|
423
|
+
const orig = parentBucket.store.get(planId);
|
|
424
|
+
ev._copyResult(newIndex, orig, originalIndex);
|
|
425
|
+
}
|
|
319
426
|
}
|
|
320
427
|
}
|
|
321
428
|
break;
|
|
@@ -345,7 +452,7 @@ class LayerPlan {
|
|
|
345
452
|
size,
|
|
346
453
|
store,
|
|
347
454
|
// PERF: not necessarily, if we don't copy the errors, we don't have the errors.
|
|
348
|
-
|
|
455
|
+
flagUnion: parentBucket.flagUnion,
|
|
349
456
|
polymorphicPathList,
|
|
350
457
|
iterators,
|
|
351
458
|
}, parentBucket.metaByMetaKey);
|
|
@@ -369,8 +476,9 @@ const te_parentBucketDotPolymorphicPathList = (0, tamedevil_1.default) `parentBu
|
|
|
369
476
|
const te_parentBucketDotIterators = (0, tamedevil_1.default) `parentBucket.iterators`;
|
|
370
477
|
const te_emptyArray = (0, tamedevil_1.default) `[]`;
|
|
371
478
|
const ref_newBucket = tamedevil_1.default.ref(executeBucket_js_1.newBucket, "newBucket");
|
|
479
|
+
const ref_batchExecutionValue = tamedevil_1.default.ref(executeBucket_js_1.batchExecutionValue, "batchExecutionValue");
|
|
372
480
|
function makeNewBucketExpression(signature, reasonType, inner) {
|
|
373
|
-
|
|
481
|
+
const expr = (0, tamedevil_1.default) `\
|
|
374
482
|
(function ${tamedevil_1.default.identifier(`newBucket_${signature}`)}(parentBucket) {
|
|
375
483
|
const store = new Map();
|
|
376
484
|
const polymorphicPathList = ${reasonType === "mutationField"
|
|
@@ -389,7 +497,7 @@ ${inner}
|
|
|
389
497
|
size,
|
|
390
498
|
store,
|
|
391
499
|
// PERF: not necessarily, if we don't copy the errors, we don't have the errors.
|
|
392
|
-
|
|
500
|
+
flagUnion: parentBucket.flagUnion,
|
|
393
501
|
polymorphicPathList,
|
|
394
502
|
iterators,
|
|
395
503
|
}, parentBucket.metaByMetaKey);
|
|
@@ -401,9 +509,14 @@ ${inner}
|
|
|
401
509
|
return null;
|
|
402
510
|
}
|
|
403
511
|
})`;
|
|
512
|
+
// te.debug(expr);
|
|
513
|
+
return expr;
|
|
404
514
|
}
|
|
405
515
|
function newBucketFactoryInnerExpression(signature, copyCount, reasonType) {
|
|
406
516
|
if (reasonType === "nullableBoundary") {
|
|
517
|
+
if (Math.random() < 2) {
|
|
518
|
+
throw new Error("This code no longer works since we added unary steps.");
|
|
519
|
+
}
|
|
407
520
|
// PERF: if parent bucket has no nulls/errors in itemStepId
|
|
408
521
|
// then we can just copy everything wholesale rather than building
|
|
409
522
|
// new arrays and looping.
|
|
@@ -414,12 +527,14 @@ function newBucketFactoryInnerExpression(signature, copyCount, reasonType) {
|
|
|
414
527
|
const te_target = tamedevil_1.default.identifier(`target${i}`);
|
|
415
528
|
const te_i = tamedevil_1.default.lit(i);
|
|
416
529
|
blocks.push((0, tamedevil_1.default) `\
|
|
417
|
-
const ${te_source} = parentBucket.store.get(
|
|
418
|
-
const ${te_target} = [];
|
|
419
|
-
store.set(
|
|
530
|
+
const ${te_source} = parentBucket.store.get(copyStepIds[${te_i}]);
|
|
531
|
+
const ${te_target} = ${te_source}.isBatch ? ${ref_batchExecutionValue}([]) : ${te_source};
|
|
532
|
+
store.set(copyStepIds[${te_i}], ${te_target});
|
|
420
533
|
`);
|
|
421
534
|
copyBlocks.push((0, tamedevil_1.default) `\
|
|
422
|
-
${te_target}
|
|
535
|
+
if(${te_target}.isBatch) {
|
|
536
|
+
${te_target}.entries[newIndex] = ${te_source}.at(originalIndex);
|
|
537
|
+
}
|
|
423
538
|
`);
|
|
424
539
|
}
|
|
425
540
|
return makeNewBucketExpression(signature, reasonType, (0, tamedevil_1.default) `\
|
|
@@ -427,7 +542,7 @@ function newBucketFactoryInnerExpression(signature, copyCount, reasonType) {
|
|
|
427
542
|
const nullableStepStore = parentBucket.store.get(itemStepId);
|
|
428
543
|
|
|
429
544
|
const itemStepIdList = [];
|
|
430
|
-
store.set(itemStepId, itemStepIdList);
|
|
545
|
+
store.set(itemStepId, ${ref_batchExecutionValue}(itemStepIdList));
|
|
431
546
|
|
|
432
547
|
// Prepare store with an empty list for each copyPlanId
|
|
433
548
|
${tamedevil_1.default.join(blocks, "")}
|
|
@@ -440,7 +555,7 @@ ${tamedevil_1.default.join(blocks, "")}
|
|
|
440
555
|
originalIndex < parentBucket.size;
|
|
441
556
|
originalIndex++
|
|
442
557
|
) {
|
|
443
|
-
const fieldValue = nullableStepStore
|
|
558
|
+
const fieldValue = nullableStepStore.at(originalIndex);
|
|
444
559
|
if (fieldValue != null) {
|
|
445
560
|
const newIndex = size++;
|
|
446
561
|
map.set(originalIndex, newIndex);
|
|
@@ -461,19 +576,22 @@ ${tamedevil_1.default.join(copyBlocks, "")}
|
|
|
461
576
|
const te_target = tamedevil_1.default.identifier(`target${i}`);
|
|
462
577
|
const te_i = tamedevil_1.default.lit(i);
|
|
463
578
|
blocks.push((0, tamedevil_1.default) `\
|
|
464
|
-
const ${te_source} = parentBucket.store.get(
|
|
465
|
-
const ${te_target} = [];
|
|
466
|
-
store.set(
|
|
579
|
+
const ${te_source} = parentBucket.store.get(copyStepIds[${te_i}]);
|
|
580
|
+
const ${te_target} = ${te_source}.isBatch ? ${ref_batchExecutionValue}([]) : ${te_source};
|
|
581
|
+
store.set(copyStepIds[${te_i}], ${te_target});
|
|
467
582
|
`);
|
|
468
583
|
copyBlocks.push((0, tamedevil_1.default) `\
|
|
469
|
-
${te_target}
|
|
584
|
+
if (${te_target}.isBatch) {
|
|
585
|
+
${te_target}.entries[newIndex] = ${te_source}.at(originalIndex);
|
|
586
|
+
}
|
|
470
587
|
`);
|
|
471
588
|
}
|
|
472
589
|
return makeNewBucketExpression(signature, reasonType, (0, tamedevil_1.default) `\
|
|
473
|
-
const
|
|
590
|
+
const listStepId = this.reason.parentStep.id;
|
|
591
|
+
const listStepStore = parentBucket.store.get(listStepId);
|
|
474
592
|
|
|
475
593
|
const itemStepIdList = [];
|
|
476
|
-
store.set(this.rootStep.id, itemStepIdList);
|
|
594
|
+
store.set(this.rootStep.id, ${ref_batchExecutionValue}(itemStepIdList));
|
|
477
595
|
|
|
478
596
|
// Prepare store with an empty list for each copyPlanId
|
|
479
597
|
${tamedevil_1.default.join(blocks, "")}
|
|
@@ -485,7 +603,7 @@ ${tamedevil_1.default.join(copyBlocks, "")}
|
|
|
485
603
|
originalIndex < parentBucket.size;
|
|
486
604
|
originalIndex++
|
|
487
605
|
) {
|
|
488
|
-
const list = listStepStore
|
|
606
|
+
const list = listStepStore.at(originalIndex);
|
|
489
607
|
if (Array.isArray(list)) {
|
|
490
608
|
const newIndexes = [];
|
|
491
609
|
map.set(originalIndex, newIndexes);
|
|
@@ -522,7 +640,7 @@ function withNewBucketFactory(signature, copyCount, reasonType, callback) {
|
|
|
522
640
|
makingNewBucketCallbacks.set(signature, callbacks);
|
|
523
641
|
const executorExpression = newBucketFactoryInnerExpression(signature, copyCount, reasonType);
|
|
524
642
|
const factoryExpression = (0, tamedevil_1.default) `\
|
|
525
|
-
function ${tamedevil_1.default.identifier(`layerPlanNewBucketFactory_${signature}`)}(
|
|
643
|
+
function ${tamedevil_1.default.identifier(`layerPlanNewBucketFactory_${signature}`)}(copyStepIds) {
|
|
526
644
|
return ${executorExpression};
|
|
527
645
|
}`;
|
|
528
646
|
tamedevil_1.default.runInBatch(factoryExpression, (factory) => {
|