grafast 0.1.1-beta.2 → 0.1.1-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
@@ -1,31 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LayerPlan = exports.isPolymorphicLayerPlan = exports.isDeferredLayerPlan = exports.isBranchingLayerPlan = void 0;
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 === "stream" ||
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 plans the results for which are available in a parent bucket need to
80
- * be "copied across" to this bucket because plans in this bucket still
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 ? `%${this.copyStepIds}` : "";
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 (this.reason.type === "nullableBoundary" ||
162
- this.reason.type === "listItem") {
163
- const n = this.copyStepIds.length;
164
- const signature = this.reason.type[0] + n;
165
- withNewBucketFactory(signature, n, this.reason.type, (fn) => {
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.copyStepIds;
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
- const itemStepId = this.rootStep?.id;
182
- assert.ok(itemStepId != null, "GrafastInternalError<f8136364-46c7-4886-b2ae-51319826f97d>: nullableStepStore layer plan has no rootStepId");
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 (hasNoNullsOrErrors) {
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 planId of copyStepIds) {
194
- store.set(planId, parentBucket.store.get(planId));
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
- // Prepare store with an empty list for each copyPlanId
208
- for (const planId of copyStepIds) {
209
- store.set(planId, []);
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
- const fieldValue = nullableStepStore[originalIndex];
216
- if (fieldValue != null) {
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 planId of copyStepIds) {
224
- store.get(planId)[newIndex] =
225
- parentBucket.store.get(planId)[originalIndex];
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
- const itemStepId = this.rootStep?.id;
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
- store.set(itemStepId, []);
243
- // Prepare store with an empty list for each copyPlanId
244
- for (const planId of copyStepIds) {
245
- store.set(planId, []);
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[originalIndex];
251
- if (Array.isArray(list)) {
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
- store.get(itemStepId)[newIndex] = list[j];
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 planId of copyStepIds) {
262
- store.get(planId)[newIndex] =
263
- parentBucket.store.get(planId)[originalIndex];
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 planId of copyStepIds) {
277
- store.set(planId, parentBucket.store.get(planId));
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 planId of copyStepIds) {
291
- store.set(planId, []);
292
- if (!parentBucket.store.has(planId)) {
293
- throw new Error(`GrafastInternalError<548f0d84-4556-4189-8655-fb16aa3345a6>: new bucket for ${this} wants to copy ${this.operationPlan.dangerouslyGetStep(planId)}, but bucket for ${parentBucket.layerPlan} doesn't contain that plan`);
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 value = polymorphicPlanStore[originalIndex];
298
- if (value == null) {
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 ((0, error_js_1.isGrafastError)(value)) {
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)[newIndex] =
318
- parentBucket.store.get(planId)[originalIndex];
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
- hasErrors: parentBucket.hasErrors,
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
- return (0, tamedevil_1.default) `\
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
- hasErrors: parentBucket.hasErrors,
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(copyPlanIds[${te_i}]);
418
- const ${te_target} = [];
419
- store.set(copyPlanIds[${te_i}], ${te_target});
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}[newIndex] = ${te_source}[originalIndex];
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[originalIndex];
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(copyPlanIds[${te_i}]);
465
- const ${te_target} = [];
466
- store.set(copyPlanIds[${te_i}], ${te_target});
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}[newIndex] = ${te_source}[originalIndex];
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 listStepStore = parentBucket.store.get(this.reason.parentStep.id);
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[originalIndex];
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}`)}(copyPlanIds) {
643
+ function ${tamedevil_1.default.identifier(`layerPlanNewBucketFactory_${signature}`)}(copyStepIds) {
526
644
  return ${executorExpression};
527
645
  }`;
528
646
  tamedevil_1.default.runInBatch(factoryExpression, (factory) => {