grafast 0.1.1-beta.21 → 0.1.1-beta.22

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 (94) hide show
  1. package/README.md +0 -4
  2. package/dist/args.js +3 -3
  3. package/dist/constants.d.ts +79 -0
  4. package/dist/constants.js +79 -0
  5. package/dist/engine/LayerPlan.d.ts +71 -8
  6. package/dist/engine/LayerPlan.js +375 -265
  7. package/dist/engine/OperationPlan.d.ts +77 -14
  8. package/dist/engine/OperationPlan.js +1508 -382
  9. package/dist/engine/OperationPlanTypes.d.ts +66 -0
  10. package/dist/engine/OperationPlanTypes.js +3 -0
  11. package/dist/engine/OutputPlan.d.ts +6 -0
  12. package/dist/engine/OutputPlan.js +138 -82
  13. package/dist/engine/StepTracker.js +76 -17
  14. package/dist/engine/executeBucket.js +327 -166
  15. package/dist/engine/lib/defaultPlanResolver.d.ts +1 -4
  16. package/dist/engine/lib/defaultPlanResolver.js +1 -5
  17. package/dist/engine/lib/withGlobalLayerPlan.d.ts +3 -1
  18. package/dist/engine/lib/withGlobalLayerPlan.js +19 -1
  19. package/dist/envelop.js +14 -3
  20. package/dist/error.d.ts +1 -1
  21. package/dist/error.js +9 -9
  22. package/dist/establishOperationPlan.d.ts +2 -1
  23. package/dist/establishOperationPlan.js +10 -10
  24. package/dist/execute.js +7 -5
  25. package/dist/global.d.ts +10 -0
  26. package/dist/global.js +25 -0
  27. package/dist/grafastGraphql.js +4 -3
  28. package/dist/grafastPrint.js +36 -4
  29. package/dist/index.d.ts +76 -8
  30. package/dist/index.js +37 -33
  31. package/dist/input.js +20 -1
  32. package/dist/inspect.js +1 -0
  33. package/dist/interfaces.d.ts +80 -122
  34. package/dist/interfaces.js +0 -77
  35. package/dist/makeGrafastSchema.d.ts +118 -35
  36. package/dist/makeGrafastSchema.js +197 -29
  37. package/dist/mermaid.js +198 -97
  38. package/dist/operationPlan-input.d.ts +1 -1
  39. package/dist/operationPlan-input.js +15 -5
  40. package/dist/planJSONInterfaces.d.ts +24 -5
  41. package/dist/prepare.d.ts +16 -9
  42. package/dist/prepare.js +54 -51
  43. package/dist/step.d.ts +45 -9
  44. package/dist/step.js +139 -22
  45. package/dist/steps/__flag.d.ts +3 -2
  46. package/dist/steps/__flag.js +31 -29
  47. package/dist/steps/__inputObject.d.ts +1 -1
  48. package/dist/steps/__inputStaticLeaf.d.ts +3 -2
  49. package/dist/steps/__inputStaticLeaf.js +13 -7
  50. package/dist/steps/__item.d.ts +1 -1
  51. package/dist/steps/__item.js +3 -3
  52. package/dist/steps/__trackedValue.d.ts +6 -3
  53. package/dist/steps/__trackedValue.js +25 -9
  54. package/dist/steps/__value.d.ts +2 -1
  55. package/dist/steps/__value.js +5 -0
  56. package/dist/steps/access.d.ts +17 -1
  57. package/dist/steps/access.js +14 -1
  58. package/dist/steps/applyInput.d.ts +1 -1
  59. package/dist/steps/applyInput.js +7 -6
  60. package/dist/steps/applyTransforms.js +9 -7
  61. package/dist/steps/bakedInput.js +2 -2
  62. package/dist/steps/coalesce.d.ts +15 -0
  63. package/dist/steps/coalesce.js +36 -0
  64. package/dist/steps/constant.js +16 -14
  65. package/dist/steps/each.d.ts +2 -2
  66. package/dist/steps/first.d.ts +2 -0
  67. package/dist/steps/first.js +5 -1
  68. package/dist/steps/graphqlResolver.d.ts +2 -2
  69. package/dist/steps/graphqlResolver.js +63 -161
  70. package/dist/steps/index.d.ts +3 -15
  71. package/dist/steps/index.js +6 -41
  72. package/dist/steps/lambda.js +1 -1
  73. package/dist/steps/last.d.ts +2 -0
  74. package/dist/steps/last.js +4 -0
  75. package/dist/steps/listTransform.d.ts +2 -2
  76. package/dist/steps/listTransform.js +11 -13
  77. package/dist/steps/load.d.ts +28 -22
  78. package/dist/steps/load.js +47 -1
  79. package/dist/steps/node.d.ts +10 -7
  80. package/dist/steps/node.js +5 -19
  81. package/dist/steps/object.js +6 -1
  82. package/dist/steps/proxy.d.ts +0 -6
  83. package/dist/steps/proxy.js +3 -3
  84. package/dist/steps/remapKeys.d.ts +1 -1
  85. package/dist/steps/remapKeys.js +0 -1
  86. package/dist/utils.d.ts +27 -5
  87. package/dist/utils.js +235 -15
  88. package/dist/version.d.ts +1 -1
  89. package/dist/version.js +1 -1
  90. package/package.json +6 -6
  91. package/dist/polymorphic.d.ts +0 -14
  92. package/dist/polymorphic.js +0 -72
  93. package/dist/steps/polymorphicBranch.d.ts +0 -27
  94. package/dist/steps/polymorphicBranch.js +0 -62
package/dist/step.js CHANGED
@@ -7,20 +7,21 @@ exports.assertStep = assertStep;
7
7
  exports.isUnbatchedStep = isUnbatchedStep;
8
8
  exports.isObjectLikeStep = isObjectLikeStep;
9
9
  exports.isListLikeStep = isListLikeStep;
10
- exports.isPolymorphicStep = isPolymorphicStep;
11
10
  exports.isListCapableStep = isListCapableStep;
12
11
  exports.assertListCapableStep = assertListCapableStep;
12
+ exports.stepHasToSpecifier = stepHasToSpecifier;
13
+ exports.stepHasToRecord = stepHasToRecord;
13
14
  exports.assertExecutableStep = assertExecutableStep;
14
15
  const tslib_1 = require("tslib");
15
16
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
16
17
  const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
18
+ const constants_js_1 = require("./constants.js");
17
19
  const dev_js_1 = require("./dev.js");
18
20
  const withGlobalLayerPlan_js_1 = require("./engine/lib/withGlobalLayerPlan.js");
19
21
  const lock_js_1 = require("./engine/lock.js");
20
22
  const error_js_1 = require("./error.js");
21
23
  const global_js_1 = require("./global.js");
22
24
  const inspect_js_1 = require("./inspect.js");
23
- const interfaces_js_1 = require("./interfaces.js");
24
25
  const utils_js_1 = require("./utils.js");
25
26
  /**
26
27
  * This indicates that a step never executes (e.g. __ItemStep and __ValueStep)
@@ -41,7 +42,7 @@ function throwDestroyed() {
41
42
  throw new Error(message);
42
43
  }
43
44
  function isDeepDepSkippable($dep) {
44
- return interfaces_js_1.$$deepDepSkip in $dep && typeof $dep[interfaces_js_1.$$deepDepSkip] === "function";
45
+ return constants_js_1.$$deepDepSkip in $dep && typeof $dep[constants_js_1.$$deepDepSkip] === "function";
45
46
  }
46
47
  function reallyAssertFinalized(plan) {
47
48
  if (!plan.isFinalized) {
@@ -55,7 +56,7 @@ exports.assertFinalized = !dev_js_1.isDev ? dev_js_1.noop : reallyAssertFinalize
55
56
  * they must be able to execute to return values.
56
57
  */
57
58
  class Step {
58
- static { _a = interfaces_js_1.$$subroutine, _b = lock_js_1.$$unlock; }
59
+ static { _a = constants_js_1.$$subroutine, _b = lock_js_1.$$unlock; }
59
60
  constructor() {
60
61
  this[_a] = null;
61
62
  /**
@@ -70,7 +71,9 @@ class Step {
70
71
  /**
71
72
  * (default = ALL_FLAGS & ~FLAG_NULL)
72
73
  */
73
- this.defaultForbiddenFlags = interfaces_js_1.DEFAULT_FORBIDDEN_FLAGS;
74
+ this.defaultForbiddenFlags = constants_js_1.DEFAULT_FORBIDDEN_FLAGS;
75
+ /** @internal */
76
+ this._refs = [];
74
77
  /**
75
78
  * If the peerKey of two steps do not match, then they are definitely not
76
79
  * peers. Use this to reduce the load on deduplicate by more quickly
@@ -83,6 +86,7 @@ class Step {
83
86
  * @experimental
84
87
  */
85
88
  this.peerKey = null;
89
+ this.__trappableFlags = constants_js_1.TRAPPABLE_FLAGS;
86
90
  this.isArgumentsFinalized = false;
87
91
  this.isFinalized = false;
88
92
  this.debug = (0, global_js_1.getDebug)();
@@ -91,6 +95,8 @@ class Step {
91
95
  this.operationPlan = layerPlan.operationPlan;
92
96
  this._isUnary = true;
93
97
  this._isUnaryLocked = false;
98
+ // Populated in `OperationPlan` during `finalizeLayerPlans`
99
+ this._isSelectiveStep = false;
94
100
  this.implicitSideEffectStep = null;
95
101
  this.hasSideEffects ??= false;
96
102
  let hasSideEffects = false;
@@ -146,6 +152,7 @@ class Step {
146
152
  this.dependencies = [];
147
153
  this.dependencyForbiddenFlags = [];
148
154
  this.dependencyOnReject = [];
155
+ this.dependencyDataOnly = [];
149
156
  this.dependents = [];
150
157
  this.isOptimized = false;
151
158
  this.allowMultipleOptimizations = false;
@@ -165,21 +172,39 @@ class Step {
165
172
  return this._isUnary;
166
173
  }
167
174
  withMyLayerPlan(callback) {
168
- return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, callback);
175
+ return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, null, callback);
169
176
  }
170
177
  /** @experimental */
171
178
  withLayerPlan(callback) {
172
- return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, callback);
179
+ return (0, withGlobalLayerPlan_js_1.withGlobalLayerPlan)(this.layerPlan, this.polymorphicPaths, null, callback);
173
180
  }
174
181
  getStep(id) {
175
182
  return this.layerPlan.getStep(id, this);
176
183
  }
177
184
  getDepOptions(depId) {
185
+ this._assertAccessAllowed(depId);
186
+ return this._getDepOptions(depId);
187
+ }
188
+ _getDepOptions(depId) {
178
189
  const step = this.dependencies[depId];
179
190
  const forbiddenFlags = this.dependencyForbiddenFlags[depId];
180
191
  const onReject = this.dependencyOnReject[depId];
181
- const acceptFlags = interfaces_js_1.ALL_FLAGS & ~forbiddenFlags;
182
- return { step, acceptFlags, onReject };
192
+ const dataOnly = this.dependencyDataOnly[depId];
193
+ const acceptFlags = constants_js_1.ALL_FLAGS & ~forbiddenFlags;
194
+ return { step, acceptFlags, onReject, dataOnly };
195
+ }
196
+ /**
197
+ * @internal
198
+ */
199
+ _assertAccessAllowed(depId) {
200
+ const phase = this.operationPlan.phase;
201
+ if (phase !== "optimize" && phase !== "plan")
202
+ return;
203
+ const step = this.dependencies[depId];
204
+ const dataOnly = this.dependencyDataOnly[depId];
205
+ if (dataOnly) {
206
+ throw new Error(`Dependency ${depId} (${step}) of ${this} was declared as "data only", so retrieval is forbidden.`);
207
+ }
183
208
  }
184
209
  getDep(_depId, _throwOnFlagged = false) {
185
210
  // This gets replaced when `__FlagStep` is loaded. Were we on ESM we could
@@ -212,7 +237,7 @@ class Step {
212
237
  // __ItemStep and __ListTransformStep are safe to walk through, but other
213
238
  // classes may not be.
214
239
  while (isDeepDepSkippable($dep)) {
215
- $dep = $dep[interfaces_js_1.$$deepDepSkip]();
240
+ $dep = $dep[constants_js_1.$$deepDepSkip]();
216
241
  }
217
242
  return $dep;
218
243
  }
@@ -246,18 +271,109 @@ class Step {
246
271
  planJSONExtra() {
247
272
  return undefined;
248
273
  }
274
+ /**
275
+ * **IF IN DOUBT, USE `.addDependency()` INSTEAD!
276
+ *
277
+ * This **DANGEROUS** method allows you to create a reference to another
278
+ * step. A reference is like a dependency except it has no runtime impact -
279
+ * the data is not passed into execute. In general you should only add
280
+ * references to steps that you directly or indirectly depend on (e.g. an
281
+ * ancestor step) so that you may communicate with said step during
282
+ * `optimize` (for example). Sometimes it's acceptable to reference steps
283
+ * that you don't transitively depend on; in those cases you're permitted to
284
+ * pass an `allowIndirectReason` to explain to yourself and others why you
285
+ * are breaking these rules.
286
+ *
287
+ * @experimental
288
+ */
289
+ addRef(rawStep, allowIndirectReason = null) {
290
+ const step = this.operationPlan.stepTracker.getStepById(rawStep.id);
291
+ if (dev_js_1.isDev && !allowIndirectReason && !(0, utils_js_1.stepADependsOnStepB)(this, step)) {
292
+ const allRefs = (step, allDepIds = new Set()) => {
293
+ allDepIds.add(step.id);
294
+ for (const dep of step.dependencies) {
295
+ allRefs(dep, allDepIds);
296
+ }
297
+ return allDepIds;
298
+ };
299
+ const refs1 = allRefs(this);
300
+ const refs2 = allRefs(step);
301
+ // const commonRefs = refs1.union(refs2);
302
+ const commonRefs = new Set([...refs1].filter((v) => refs2.has(v)));
303
+ const printDeps = (step, depth) => {
304
+ const isCommon = commonRefs.has(step.id);
305
+ const stepDesc = isCommon
306
+ ? chalk_1.default.bgWhite.black `<${step}>`
307
+ : String(step);
308
+ return `${" ".repeat(depth)}${stepDesc}${!isCommon && step.dependencies.length > 0 ? `:\n${step.dependencies.map((d) => printDeps(d, depth + 1)).join("\n")}` : ""}`;
309
+ };
310
+ throw new Error(`${this} has created a reference to ${step} which is not depended on (directly or indirectly)
311
+ Self:
312
+ ${printDeps(this, 1)}
313
+ Reference:
314
+ ${printDeps(step, 1)}
315
+ `);
316
+ }
317
+ else if (!(0, utils_js_1.stepAMayDependOnStepB)(this, step)) {
318
+ throw new Error(`${this}.addRef(${step}) forbidden: invalid plan heirarchy`);
319
+ }
320
+ return this._refs.push(step.id) - 1;
321
+ }
322
+ /**
323
+ * Allows you to dereference a reference made via `addRef`. Will resolve to
324
+ * whatever that step is now (or null if not found). Note that referenced
325
+ * referenced steps may change to a new step instance due to lifecycle
326
+ * methods (e.g. deduplicate) or even to an entirely separate class
327
+ * altogether (e.g. due to optimize). References are not guaranteed to be
328
+ * honoured.
329
+ *
330
+ * @experimental
331
+ */
332
+ getRef(refIdx) {
333
+ if (!["plan", "validate", "optimize"].includes(this.operationPlan.phase)) {
334
+ throw new Error(`Cannot call ${this}.getRef() when the operation plan phase is ${this.operationPlan.phase}; getRef may only be called during planning.`);
335
+ }
336
+ if (refIdx == null)
337
+ return null;
338
+ return (this.operationPlan.stepTracker.getStepById(this._refs[refIdx]) ?? null);
339
+ }
249
340
  canAddDependency(step) {
250
341
  return (0, utils_js_1.stepAMayDependOnStepB)(this, step);
251
342
  }
252
- addDependency(stepOrOptions) {
253
- const options = stepOrOptions instanceof Step
254
- ? { step: stepOrOptions, skipDeduplication: false }
255
- : stepOrOptions;
343
+ _addDependency(options) {
256
344
  if (options.step.layerPlan.id > this.layerPlan.id) {
257
- throw new Error(`Cannot add dependency ${options.step} to ${this} since the former is in a deeper layerPlan (creates a catch-22)`);
345
+ throw new Error(`Cannot add dependency ${options.step} to ${this} since the former is in a deeper layerPlan (${options.step.layerPlan} deeper than ${this.layerPlan}; creates a catch-22)`);
258
346
  }
259
347
  return this.operationPlan.stepTracker.addStepDependency(this, options);
260
348
  }
349
+ addDependency(stepOrOptions) {
350
+ const options = {
351
+ dataOnly: false,
352
+ skipDeduplication: false,
353
+ ...(stepOrOptions instanceof Step
354
+ ? { step: stepOrOptions }
355
+ : stepOrOptions),
356
+ };
357
+ return this._addDependency(options);
358
+ }
359
+ addDataDependency(stepOrOptions) {
360
+ const opts = stepOrOptions instanceof Step ? { step: stepOrOptions } : stepOrOptions;
361
+ return this._addDependency({
362
+ dataOnly: true,
363
+ skipDeduplication: false,
364
+ ...opts,
365
+ });
366
+ }
367
+ // Currently identical to addDependency
368
+ addStrongDependency(stepOrOptions) {
369
+ return this._addDependency({
370
+ dataOnly: false,
371
+ skipDeduplication: false,
372
+ ...(stepOrOptions instanceof Step
373
+ ? { step: stepOrOptions }
374
+ : stepOrOptions),
375
+ });
376
+ }
261
377
  /**
262
378
  * Adds "unary" dependencies; in `execute({count, values})` you'll receive a
263
379
  * `values[index]` (where `index` is the return value of this function) with
@@ -267,7 +383,7 @@ class Step {
267
383
  addUnaryDependency(stepOrOptions) {
268
384
  const options = stepOrOptions instanceof Step ? { step: stepOrOptions } : stepOrOptions;
269
385
  if (options.step.layerPlan.id > this.layerPlan.id) {
270
- throw new Error(`Cannot add dependency ${options.step} to ${this} since the former is in a deeper layerPlan (creates a catch-22)`);
386
+ throw new Error(`Cannot add a unary dependency on ${options.step} to ${this} since the former is in a deeper layerPlan (creates a catch-22)`);
271
387
  }
272
388
  return this.operationPlan.stepTracker.addStepUnaryDependency(this, options);
273
389
  }
@@ -323,7 +439,7 @@ class Step {
323
439
  */
324
440
  /* abstract */
325
441
  execute(details) {
326
- // ESLint/TS: ignore not used.
442
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
327
443
  details;
328
444
  throw new Error(`${this} has not implemented an 'execute' method`);
329
445
  }
@@ -419,7 +535,6 @@ class UnbatchedStep extends Step {
419
535
  super.finalize();
420
536
  }
421
537
  execute({ indexMap, values, extra, }) {
422
- console.warn(`${this} didn't call 'super.finalize()' in the finalize method.`);
423
538
  const depCount = this.dependencies.length;
424
539
  return indexMap((i) => {
425
540
  try {
@@ -454,10 +569,6 @@ function isObjectLikeStep(plan) {
454
569
  function isListLikeStep(plan) {
455
570
  return "at" in plan && typeof plan.at === "function";
456
571
  }
457
- function isPolymorphicStep(s) {
458
- return ("planForType" in s &&
459
- typeof s.planForType === "function");
460
- }
461
572
  function isListCapableStep(plan) {
462
573
  return "listItem" in plan && typeof plan.listItem === "function";
463
574
  }
@@ -466,6 +577,12 @@ function assertListCapableStep(plan, pathDescription) {
466
577
  throw new Error(`The plan returned from '${pathDescription}' should be a list capable plan, but ${plan} does not implement the 'listItem' method.`);
467
578
  }
468
579
  }
580
+ function stepHasToSpecifier($step) {
581
+ return typeof $step.toSpecifier === "function";
582
+ }
583
+ function stepHasToRecord($step) {
584
+ return typeof $step.toRecord === "function";
585
+ }
469
586
  /** @deprecated Use isStep instead */
470
587
  exports.isExecutableStep = isStep;
471
588
  /** @deprecated Use isStep instead */
@@ -1,5 +1,5 @@
1
+ import { $$deepDepSkip } from "../constants.js";
1
2
  import type { DataFromStep, ExecutionDetails, ExecutionEntryFlags, GrafastResultsList } from "../interfaces.js";
2
- import { $$deepDepSkip } from "../interfaces.js";
3
3
  import type { ListCapableStep } from "../step.js";
4
4
  import { Step } from "../step.js";
5
5
  import type { __ItemStep } from "./__item.js";
@@ -14,6 +14,7 @@ export type ResolvedTrapValue = false | null | undefined | readonly never[];
14
14
  export interface FlagStepOptions {
15
15
  acceptFlags?: ExecutionEntryFlags;
16
16
  onReject?: Error | null;
17
+ dataOnly?: boolean;
17
18
  if?: Step<boolean>;
18
19
  valueForInhibited?: TrapValue;
19
20
  valueForError?: TrapValue;
@@ -47,7 +48,7 @@ export declare class __FlagStep<TStep extends Step> extends Step<DataFromStep<TS
47
48
  */
48
49
  export declare function inhibitOnNull<TStep extends Step>($step: TStep, options?: {
49
50
  if?: FlagStepOptions["if"];
50
- }): __FlagStep<TStep>;
51
+ }): Step<TStep extends Step<infer U> ? Exclude<U, null | undefined> : any>;
51
52
  /**
52
53
  * Example use case: expecting a node ID that represents a User, but get one
53
54
  * that represents a Post instead: throw error to tell user they've sent invalid
@@ -4,24 +4,24 @@ exports.__FlagStep = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_INHIBITED =
4
4
  exports.inhibitOnNull = inhibitOnNull;
5
5
  exports.assertNotNull = assertNotNull;
6
6
  exports.trap = trap;
7
+ const constants_js_1 = require("../constants.js");
7
8
  const error_js_1 = require("../error.js");
8
9
  const inspect_js_1 = require("../inspect.js");
9
- const interfaces_js_1 = require("../interfaces.js");
10
10
  const step_js_1 = require("../step.js");
11
11
  // PUBLIC FLAGS
12
- exports.TRAP_ERROR = interfaces_js_1.FLAG_ERROR;
13
- exports.TRAP_INHIBITED = interfaces_js_1.FLAG_INHIBITED;
14
- exports.TRAP_ERROR_OR_INHIBITED = (interfaces_js_1.FLAG_ERROR |
15
- interfaces_js_1.FLAG_INHIBITED);
12
+ exports.TRAP_ERROR = constants_js_1.FLAG_ERROR;
13
+ exports.TRAP_INHIBITED = constants_js_1.FLAG_INHIBITED;
14
+ exports.TRAP_ERROR_OR_INHIBITED = (constants_js_1.FLAG_ERROR |
15
+ constants_js_1.FLAG_INHIBITED);
16
16
  function digestAcceptFlags(acceptFlags) {
17
17
  const parts = [];
18
- if ((acceptFlags & interfaces_js_1.FLAG_NULL) === 0) {
18
+ if ((acceptFlags & constants_js_1.FLAG_NULL) === 0) {
19
19
  parts.push("rejectNull");
20
20
  }
21
- if ((acceptFlags & interfaces_js_1.FLAG_ERROR) !== 0) {
21
+ if ((acceptFlags & constants_js_1.FLAG_ERROR) !== 0) {
22
22
  parts.push("trapError");
23
23
  }
24
- if ((acceptFlags & interfaces_js_1.FLAG_INHIBITED) !== 0) {
24
+ if ((acceptFlags & constants_js_1.FLAG_INHIBITED) !== 0) {
25
25
  parts.push("trapInhibited");
26
26
  }
27
27
  return parts.join("&");
@@ -64,8 +64,8 @@ class __FlagStep extends step_js_1.Step {
64
64
  super();
65
65
  this.isSyncAndSafe = false;
66
66
  this.ifDep = null;
67
- const { acceptFlags = interfaces_js_1.DEFAULT_ACCEPT_FLAGS, onReject, if: $cond, valueForInhibited = "PASS_THROUGH", valueForError = "PASS_THROUGH", } = options;
68
- this.forbiddenFlags = interfaces_js_1.ALL_FLAGS & ~acceptFlags;
67
+ const { acceptFlags = constants_js_1.DEFAULT_ACCEPT_FLAGS, onReject, dataOnly, if: $cond, valueForInhibited = "PASS_THROUGH", valueForError = "PASS_THROUGH", } = options;
68
+ this.forbiddenFlags = constants_js_1.ALL_FLAGS & ~acceptFlags;
69
69
  this.onRejectReturnValue =
70
70
  onReject == null ? error_js_1.$$inhibit : (0, error_js_1.flagError)(onReject, step.id);
71
71
  this.valueForInhibited = resolveTrapValue(valueForInhibited);
@@ -77,29 +77,29 @@ class __FlagStep extends step_js_1.Step {
77
77
  // Can't PASS_THROUGH errors since they need to be converted into TRAPPED
78
78
  // error.
79
79
  // TODO: should we be handling this in Grafast core?
80
- (acceptFlags & interfaces_js_1.FLAG_ERROR) === 0;
80
+ (acceptFlags & constants_js_1.FLAG_ERROR) === 0;
81
81
  if (!this.canBeInlined) {
82
- this.addDependency({ step, acceptFlags: interfaces_js_1.TRAPPABLE_FLAGS });
82
+ this.addDependency({ step, acceptFlags: constants_js_1.TRAPPABLE_FLAGS });
83
83
  if ($cond) {
84
84
  this.ifDep = this.addDependency($cond);
85
85
  }
86
86
  }
87
87
  else {
88
- this.addDependency({ step, acceptFlags, onReject });
88
+ this.addDependency({ step, acceptFlags, onReject, dataOnly });
89
89
  }
90
90
  if ((0, step_js_1.isListCapableStep)(step)) {
91
91
  this.listItem = this._listItem;
92
92
  }
93
93
  }
94
94
  toStringMeta() {
95
- const acceptFlags = interfaces_js_1.ALL_FLAGS & ~this.forbiddenFlags;
95
+ const acceptFlags = constants_js_1.ALL_FLAGS & ~this.forbiddenFlags;
96
96
  const rej = this.onRejectReturnValue
97
97
  ? trim(String(this.onRejectReturnValue))
98
98
  : (0, inspect_js_1.inspect)(this.onRejectReturnValue);
99
99
  const $if = this.ifDep !== null ? this.getDepOptions(this.ifDep).step : null;
100
100
  return `${this.dependencies[0].id}, ${$if ? `if(${$if.id}), ` : ``}${digestAcceptFlags(acceptFlags)}, onReject: ${rej}`;
101
101
  }
102
- [interfaces_js_1.$$deepDepSkip]() {
102
+ [constants_js_1.$$deepDepSkip]() {
103
103
  return this.getDepOptions(0).step;
104
104
  }
105
105
  // Copied over listItem if the dependent step is a list capable step
@@ -115,7 +115,8 @@ class __FlagStep extends step_js_1.Step {
115
115
  const step = this.dependencies[0];
116
116
  const forbiddenFlags = this.dependencyForbiddenFlags[0];
117
117
  const onReject = this.dependencyOnReject[0];
118
- const acceptFlags = interfaces_js_1.ALL_FLAGS & ~forbiddenFlags;
118
+ const dataOnly = this.dependencyDataOnly[0];
119
+ const acceptFlags = constants_js_1.ALL_FLAGS & ~forbiddenFlags;
119
120
  if (
120
121
  // TODO: this logic could be improved so that more flag checks were
121
122
  // inlined, e.g. `trap(inhibitOnNull($foo), TRAP_INHIBIT)` should just
@@ -129,10 +130,10 @@ class __FlagStep extends step_js_1.Step {
129
130
  options.onReject === undefined ||
130
131
  options.onReject === onReject) {
131
132
  if (options.acceptFlags === undefined ||
132
- options.acceptFlags === interfaces_js_1.DEFAULT_ACCEPT_FLAGS ||
133
+ options.acceptFlags === constants_js_1.DEFAULT_ACCEPT_FLAGS ||
133
134
  options.acceptFlags === acceptFlags ||
134
135
  false) {
135
- return { step, acceptFlags, onReject };
136
+ return { step, acceptFlags, onReject, dataOnly };
136
137
  }
137
138
  }
138
139
  return null;
@@ -173,16 +174,16 @@ class __FlagStep extends step_js_1.Step {
173
174
  const cond = condEv ? condEv.at(i) : true;
174
175
  const forbiddenFlags = cond
175
176
  ? thisForbiddenFlags
176
- : interfaces_js_1.DEFAULT_FORBIDDEN_FLAGS;
177
+ : constants_js_1.DEFAULT_FORBIDDEN_FLAGS;
177
178
  // Search for "f2b3b1b3" for similar block
178
179
  const flags = dataEv._flagsAt(i);
179
180
  const disallowedFlags = flags & forbiddenFlags;
180
181
  if (disallowedFlags) {
181
- if (disallowedFlags & interfaces_js_1.FLAG_INHIBITED) {
182
+ if (disallowedFlags & constants_js_1.FLAG_INHIBITED) {
182
183
  // We were already rejected, maintain this
183
184
  return error_js_1.$$inhibit;
184
185
  }
185
- else if (disallowedFlags & interfaces_js_1.FLAG_ERROR) {
186
+ else if (disallowedFlags & constants_js_1.FLAG_ERROR) {
186
187
  // We were already rejected, maintain this
187
188
  return (0, error_js_1.flagError)(dataEv.at(i));
188
189
  }
@@ -192,10 +193,10 @@ class __FlagStep extends step_js_1.Step {
192
193
  }
193
194
  }
194
195
  else {
195
- if (flags & interfaces_js_1.FLAG_ERROR && this.valueForError !== false) {
196
+ if (flags & constants_js_1.FLAG_ERROR && this.valueForError !== false) {
196
197
  return valueForError;
197
198
  }
198
- if (flags & interfaces_js_1.FLAG_INHIBITED && this.valueForInhibited !== false) {
199
+ if (flags & constants_js_1.FLAG_INHIBITED && this.valueForInhibited !== false) {
199
200
  return valueForInhibited;
200
201
  }
201
202
  // Assume pass-through
@@ -223,7 +224,7 @@ exports.__FlagStep = __FlagStep;
223
224
  function inhibitOnNull($step, options) {
224
225
  return new __FlagStep($step, {
225
226
  ...options,
226
- acceptFlags: interfaces_js_1.DEFAULT_ACCEPT_FLAGS & ~interfaces_js_1.FLAG_NULL,
227
+ acceptFlags: constants_js_1.DEFAULT_ACCEPT_FLAGS & ~constants_js_1.FLAG_NULL,
227
228
  });
228
229
  }
229
230
  /**
@@ -234,20 +235,21 @@ function inhibitOnNull($step, options) {
234
235
  function assertNotNull($step, message, options) {
235
236
  return new __FlagStep($step, {
236
237
  ...options,
237
- acceptFlags: interfaces_js_1.DEFAULT_ACCEPT_FLAGS & ~interfaces_js_1.FLAG_NULL,
238
+ acceptFlags: constants_js_1.DEFAULT_ACCEPT_FLAGS & ~constants_js_1.FLAG_NULL,
238
239
  onReject: new error_js_1.SafeError(message),
239
240
  });
240
241
  }
241
242
  function trap($step, acceptFlags, options) {
242
243
  return new __FlagStep($step, {
243
244
  ...options,
244
- acceptFlags: (acceptFlags & interfaces_js_1.TRAPPABLE_FLAGS) | interfaces_js_1.FLAG_NULL,
245
+ acceptFlags: (acceptFlags & constants_js_1.TRAPPABLE_FLAGS) | constants_js_1.FLAG_NULL,
245
246
  });
246
247
  }
247
248
  // Have to overwrite the getDep method due to circular dependency
248
249
  step_js_1.Step.prototype.getDep = function (depId, throwOnFlagged = false) {
249
- const { step, acceptFlags, onReject } = this.getDepOptions(depId);
250
- if (acceptFlags === interfaces_js_1.DEFAULT_ACCEPT_FLAGS && onReject == null) {
250
+ this._assertAccessAllowed(depId);
251
+ const { step, acceptFlags, onReject, dataOnly } = this.getDepOptions(depId);
252
+ if (acceptFlags === constants_js_1.DEFAULT_ACCEPT_FLAGS && onReject == null) {
251
253
  return step;
252
254
  }
253
255
  else {
@@ -255,7 +257,7 @@ step_js_1.Step.prototype.getDep = function (depId, throwOnFlagged = false) {
255
257
  throw new Error(`When retrieving dependency ${step} of ${this}, the dependency is flagged as ${digestAcceptFlags(acceptFlags)}/onReject=${String(onReject)}. Please use \`this.getDepOptions(depId)\` instead, and handle the flags`);
256
258
  }
257
259
  // Return a __FlagStep around options.step so that all the options are preserved.
258
- return new __FlagStep(step, { acceptFlags, onReject });
260
+ return new __FlagStep(step, { acceptFlags, onReject, dataOnly });
259
261
  }
260
262
  };
261
263
  //# sourceMappingURL=__flag.js.map
@@ -14,7 +14,7 @@ export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType
14
14
  isSyncAndSafe: boolean;
15
15
  private inputFields;
16
16
  constructor(inputObjectType: TInputType, inputValues: NotVariableValueNode | undefined);
17
- optimize(): import("./constant.js").ConstantStep<null> | this;
17
+ optimize(): this | import("./constant.js").ConstantStep<null>;
18
18
  finalize(): void;
19
19
  unbatchedExecute(_extra: UnbatchedExecutionExtra, ...values: any[]): any;
20
20
  get(attrName: string): AnyInputStep;
@@ -6,14 +6,15 @@ import { UnbatchedStep } from "../step.js";
6
6
  * @see __InputDynamicScalarStep
7
7
  */
8
8
  export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedStep<TLeaf> {
9
+ private readonly coercedValue;
9
10
  static $$export: {
10
11
  moduleName: string;
11
12
  exportName: string;
12
13
  };
13
14
  isSyncAndSafe: boolean;
14
- private readonly coercedValue;
15
- constructor(inputType: GraphQLLeafType, value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | undefined);
15
+ constructor(coercedValue: any);
16
16
  unbatchedExecute(): TLeaf;
17
17
  optimize(): import("./constant.js").ConstantStep<any>;
18
18
  }
19
+ export declare function __inputStaticLeaf(inputType: GraphQLLeafType, value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | undefined): __InputStaticLeafStep<any>;
19
20
  //# sourceMappingURL=__inputStaticLeaf.d.ts.map
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.__InputStaticLeafStep = void 0;
4
+ exports.__inputStaticLeaf = __inputStaticLeaf;
4
5
  const tslib_1 = require("tslib");
5
6
  const graphql = tslib_1.__importStar(require("graphql"));
7
+ const global_js_1 = require("../global.js");
6
8
  const step_js_1 = require("../step.js");
7
9
  const constant_js_1 = require("./constant.js");
8
10
  const { valueFromAST } = graphql;
@@ -16,15 +18,10 @@ class __InputStaticLeafStep extends step_js_1.UnbatchedStep {
16
18
  moduleName: "grafast",
17
19
  exportName: "__InputStaticLeafStep",
18
20
  }; }
19
- constructor(inputType, value) {
21
+ constructor(coercedValue) {
20
22
  super();
23
+ this.coercedValue = coercedValue;
21
24
  this.isSyncAndSafe = true;
22
- // `coerceInputValue` throws on coercion failure. NOTE: it's only safe for
23
- // us to call coerceInputValue because we already know this is a scalar,
24
- // *not* a variable, and not an object/list therefore cannot _contain_ a
25
- // variable. Otherwise we'd need to process it via
26
- // operationPlan.trackedVariableValuesStep.
27
- this.coercedValue = value != null ? valueFromAST(value, inputType) : value;
28
25
  }
29
26
  unbatchedExecute() {
30
27
  return this.coercedValue;
@@ -42,4 +39,13 @@ class __InputStaticLeafStep extends step_js_1.UnbatchedStep {
42
39
  }
43
40
  }
44
41
  exports.__InputStaticLeafStep = __InputStaticLeafStep;
42
+ function __inputStaticLeaf(inputType, value) {
43
+ // `coerceInputValue` throws on coercion failure. NOTE: it's only safe for
44
+ // us to call coerceInputValue because we already know this is a scalar,
45
+ // *not* a variable, and not an object/list therefore cannot _contain_ a
46
+ // variable. Otherwise we'd need to process it via
47
+ // operationPlan.trackedVariableValuesStep.
48
+ const coercedValue = value != null ? valueFromAST(value, inputType) : value;
49
+ return (0, global_js_1.operationPlan)().cacheImmutableStep("__inputStaticLeaf", coercedValue, () => new __InputStaticLeafStep(coercedValue));
50
+ }
45
51
  //# sourceMappingURL=__inputStaticLeaf.js.map
@@ -1,5 +1,5 @@
1
+ import { $$deepDepSkip } from "../constants.js";
1
2
  import type { GrafastResultsList, JSONValue } from "../index.js";
2
- import { $$deepDepSkip } from "../interfaces.js";
3
3
  import type { Step } from "../step.js";
4
4
  import { $$noExec, UnbatchedStep } from "../step.js";
5
5
  /**
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.__ItemStep = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
- const interfaces_js_1 = require("../interfaces.js");
7
+ const constants_js_1 = require("../constants.js");
8
8
  const step_js_1 = require("../step.js");
9
9
  /**
10
10
  * An __ItemStep is an internal plan (users must never construct it
@@ -36,8 +36,8 @@ class __ItemStep extends step_js_1.UnbatchedStep {
36
36
  getParentStep() {
37
37
  return this.getDep(0);
38
38
  }
39
- [(_a = step_js_1.$$noExec, interfaces_js_1.$$deepDepSkip)]() {
40
- return this.getDep(0);
39
+ [(_a = step_js_1.$$noExec, constants_js_1.$$deepDepSkip)]() {
40
+ return this.getDepOptions(0).step;
41
41
  }
42
42
  execute() {
43
43
  throw new Error("__ItemStep must never execute");
@@ -31,10 +31,11 @@ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLI
31
31
  };
32
32
  isSyncAndSafe: boolean;
33
33
  /**
34
- * Could be anything. In the case of context it could even have exotic
35
- * entries such as `pgClient`.
34
+ * The value that was seen during planning, for us to use during eval (and
35
+ * add constraints on). DO NOT USE IN USER CODE because it will not
36
+ * necessarily reflect the values that should be used at runtime.
36
37
  */
37
- private readonly value;
38
+ private readonly _initialValue;
38
39
  /**
39
40
  * The path that we are through the original value (the one that
40
41
  * `constraints` relates to).
@@ -50,10 +51,12 @@ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLI
50
51
  * Get the named property of an object.
51
52
  */
52
53
  get<TAttribute extends keyof TData & string>(attrName: TAttribute): __TrackedValueStepWithDollars<TData[TAttribute], TInputType extends GraphQLInputObjectType ? ReturnType<TInputType["getFields"]>[TAttribute]["type"] : undefined>;
54
+ private _get;
53
55
  /**
54
56
  * Get the entry at the given index in an array.
55
57
  */
56
58
  at<TIndex extends keyof TData & number>(index: TIndex): __TrackedValueStepWithDollars<TData[TIndex], TInputType extends GraphQLList<infer U> ? U & GraphQLInputType : TInputType extends GraphQLNonNull<GraphQLList<infer U>> ? U & GraphQLInputType : undefined>;
59
+ private _at;
57
60
  optimize(): import("../step.js").Step<any> | import("./__flag.js").__FlagStep<import("../step.js").Step<any>>;
58
61
  }
59
62
  export type __TrackedValueStepWithDollars<TData = any, TInputType extends GraphQLInputType | undefined = undefined> = __TrackedValueStep<TData, TInputType> & (TInputType extends GraphQLInputObjectType ? {