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,96 +1,2 @@
1
- import type { OperationPlan } from "../index.js";
2
- import type { ExecutableStep } from "../step";
3
- import type { LayerPlan, LayerPlanReasonsWithParentStep } from "./LayerPlan";
4
- import type { OutputPlan } from "./OutputPlan";
5
- /**
6
- * This class keeps track of all of our steps, and the dependencies between
7
- * steps and other steps, layer plans and steps, and output plans and steps.
8
- *
9
- * When a step is replaced by another step, all the dependencies are updated
10
- * such that the replaced step simply evaporates.
11
- *
12
- * @internal
13
- */
14
- export declare class StepTracker {
15
- private readonly operationPlan;
16
- /** @internal */
17
- stepCount: number;
18
- /** @internal */
19
- activeSteps: Set<ExecutableStep<any>>;
20
- /** @internal */
21
- stepById: {
22
- [stepId: number]: ExecutableStep | null;
23
- };
24
- /** @internal */
25
- private aliasesById;
26
- /** @internal */
27
- stepsWithNoDependencies: Set<ExecutableStep<any>>;
28
- /** @internal */
29
- outputPlansByRootStep: Map<ExecutableStep<any>, Set<OutputPlan<import("./OutputPlan").OutputPlanType>>>;
30
- /** @internal */
31
- layerPlansByRootStep: Map<ExecutableStep<any>, Set<LayerPlan<import("./LayerPlan").LayerPlanReason>>>;
32
- /** @internal */
33
- layerPlansByParentStep: Map<ExecutableStep<any>, Set<LayerPlan<LayerPlanReasonsWithParentStep>>>;
34
- /** @internal */
35
- layerPlans: Array<LayerPlan | null>;
36
- /**
37
- * All the OutputPlans that were created to allow a more efficient
38
- * walkOutputPlans implementation.
39
- *
40
- * @internal
41
- */
42
- allOutputPlans: OutputPlan[];
43
- nextStepIdToDeduplicate: number;
44
- constructor(operationPlan: OperationPlan);
45
- newStepsSince(oldStepCount: number): ExecutableStep<any>[];
46
- private forbid;
47
- /** Called when OperationPlan enters finalize phase. */
48
- finalizeSteps(): void;
49
- /** Called when OperationPlan is about to finalize the output plans. */
50
- finalizeOutputPlans(): void;
51
- addStep($step: ExecutableStep): number;
52
- /**
53
- * @internal
54
- */
55
- addLayerPlan(layerPlan: LayerPlan): number;
56
- /**
57
- * @internal
58
- */
59
- addOutputPlan(outputPlan: OutputPlan): void;
60
- /**
61
- * HIGHLY EXPERIMENTAL!
62
- *
63
- * @internal
64
- */
65
- deleteLayerPlan(layerPlan: LayerPlan): void;
66
- getStepById(id: number): ExecutableStep;
67
- getStepById(id: number, allowUnset: true): ExecutableStep | null;
68
- addStepDependency($dependent: ExecutableStep, $dependency: ExecutableStep): number;
69
- setOutputPlanRootStep(outputPlan: OutputPlan, $dependency: ExecutableStep): void;
70
- setLayerPlanRootStep(layerPlan: LayerPlan, $dependency: ExecutableStep): void;
71
- /** @internal */
72
- replaceStep($original: ExecutableStep, $replacement: ExecutableStep): void;
73
- treeShakeSteps(): void;
74
- /**
75
- * Return true if this step can be tree-shaken.
76
- */
77
- private isNotNeeded;
78
- /**
79
- * Only for use during planField.
80
- */
81
- purgeBackTo(count: number): void;
82
- /**
83
- * ONLY CALL THIS IF NOTHING DEPENDS ON $original! It's intended to be called
84
- * from `replaceStep` or from itself.
85
- *
86
- * This method removes $original from the various maps/sets/lists, and also
87
- * removes the fact that it was dependent on other steps. If these other
88
- * steps no longer have any dependents (steps, layer plans or output plans)
89
- * then they can also be eradicated _except_ during the 'plan' phase.
90
- */
91
- private eradicate;
92
- moveStepToLayerPlan(step: ExecutableStep, targetLayerPlan: LayerPlan): void;
93
- addStepToItsLayerPlan(step: ExecutableStep): void;
94
- removeStepFromItsLayerPlan(step: ExecutableStep): void;
95
- }
1
+ export {};
96
2
  //# sourceMappingURL=StepTracker.d.ts.map
@@ -2,17 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StepTracker = void 0;
4
4
  const dev_js_1 = require("../dev.js");
5
+ const inspect_js_1 = require("../inspect.js");
5
6
  const interfaces_js_1 = require("../interfaces.js");
6
- /**
7
- * We want everything else to treat things like `dependencies` as read only,
8
- * however we ourselves want to be able to write to them, so we can use
9
- * writeable for this.
10
- *
11
- * @internal
12
- */
13
- function writeableArray(a) {
14
- return a;
15
- }
7
+ const step_js_1 = require("../step.js");
8
+ const utils_js_1 = require("../utils.js");
9
+ const lock_js_1 = require("./lock.js");
16
10
  /**
17
11
  * This class keeps track of all of our steps, and the dependencies between
18
12
  * steps and other steps, layer plans and steps, and output plans and steps.
@@ -28,13 +22,17 @@ class StepTracker {
28
22
  /** @internal */
29
23
  this.stepCount = 0;
30
24
  /** @internal */
25
+ this.lockedStepCount = 0;
26
+ /** @internal */
31
27
  this.activeSteps = new Set();
32
28
  /** @internal */
33
29
  this.stepById = [];
34
30
  /** @internal */
35
31
  this.aliasesById = [];
36
32
  /** @internal */
37
- this.stepsWithNoDependencies = new Set();
33
+ this.stepsWithNoDependenciesByConstructor = new Map();
34
+ /** @internal */
35
+ this.internalDependencies = new Set();
38
36
  /** @internal */
39
37
  this.outputPlansByRootStep = new Map();
40
38
  /** @internal */
@@ -77,7 +75,13 @@ class StepTracker {
77
75
  addStep($step) {
78
76
  const stepId = this.stepCount++;
79
77
  this.activeSteps.add($step);
80
- this.stepsWithNoDependencies.add($step);
78
+ const ctor = $step.constructor;
79
+ let stepsWithNoDependencies = this.stepsWithNoDependenciesByConstructor.get(ctor);
80
+ if (!stepsWithNoDependencies) {
81
+ stepsWithNoDependencies ??= new Set();
82
+ this.stepsWithNoDependenciesByConstructor.set(ctor, stepsWithNoDependencies);
83
+ }
84
+ stepsWithNoDependencies.add($step);
81
85
  this.stepById[stepId] = $step;
82
86
  this.aliasesById[stepId] = undefined;
83
87
  this.addStepToItsLayerPlan($step);
@@ -212,21 +216,72 @@ class StepTracker {
212
216
  }
213
217
  return step;
214
218
  }
215
- addStepDependency($dependent, $dependency) {
219
+ addStepDependency(raw$dependent, options) {
220
+ const $dependent = (0, utils_js_1.sudo)(raw$dependent);
221
+ const $dependency = (0, utils_js_1.sudo)(options.step);
216
222
  if (!this.activeSteps.has($dependent)) {
217
223
  throw new Error(`Cannot add ${$dependency} as a dependency of ${$dependent}; the latter is deleted!`);
218
224
  }
219
225
  if (!this.activeSteps.has($dependency)) {
220
226
  throw new Error(`Cannot add ${$dependency} as a dependency of ${$dependent}; the former is deleted!`);
221
227
  }
222
- this.stepsWithNoDependencies.delete($dependent);
223
- const dependencyIndex = writeableArray($dependent.dependencies).push($dependency) - 1;
224
- writeableArray($dependency.dependents).push({
228
+ if ($dependent.isFinalized) {
229
+ throw new Error("You cannot add a dependency after the step is finalized.");
230
+ }
231
+ if (!($dependency instanceof step_js_1.Step)) {
232
+ throw new Error(`Error occurred when adding dependency for '${$dependent}', value passed was not a step, it was '${(0, inspect_js_1.inspect)($dependency)}'`);
233
+ }
234
+ if (dev_js_1.isDev) {
235
+ // Check that we can actually add this as a dependency
236
+ if (!$dependent.layerPlan.ancestry.includes($dependency.layerPlan)) {
237
+ throw new Error(
238
+ //console.error(
239
+ // This is not a GrafastInternalError
240
+ `Attempted to add '${$dependency}' (${$dependency.layerPlan}) as a dependency of '${$dependent}' (${$dependent.layerPlan}), but we cannot because that LayerPlan isn't an ancestor`);
241
+ }
242
+ }
243
+ const dependentDependencies = (0, utils_js_1.writeableArray)($dependent.dependencies);
244
+ const dependentDependencyForbiddenFlags = (0, utils_js_1.writeableArray)($dependent.dependencyForbiddenFlags);
245
+ const dependentDependencyOnReject = (0, utils_js_1.writeableArray)($dependent.dependencyOnReject);
246
+ const { skipDeduplication, acceptFlags = interfaces_js_1.ALL_FLAGS & ~$dependent.defaultForbiddenFlags, onReject, } = options;
247
+ // When copying dependencies between classes, we might not want to
248
+ // deduplicate because we might refer to the dependency by its index. As
249
+ // such, we should only dedupe by default but allow opting out.
250
+ // TODO: change this to `!skipDeduplication`
251
+ if (skipDeduplication === false) {
252
+ const existingIndex = dependentDependencies.indexOf($dependency);
253
+ if (existingIndex >= 0) {
254
+ return existingIndex;
255
+ }
256
+ }
257
+ if (!$dependency._isUnary && $dependent._isUnary) {
258
+ if ($dependent._isUnaryLocked) {
259
+ throw new Error(`Attempted to add non-unary step ${$dependency} as a dependency of ${$dependent}; but the latter is unary, so it cannot depend on batch steps`);
260
+ }
261
+ $dependent._isUnary = false;
262
+ }
263
+ const forbiddenFlags = interfaces_js_1.ALL_FLAGS & ~(acceptFlags & interfaces_js_1.TRAPPABLE_FLAGS);
264
+ this.stepsWithNoDependenciesByConstructor
265
+ .get($dependent.constructor)
266
+ ?.delete($dependent);
267
+ const dependencyIndex = dependentDependencies.push($dependency) - 1;
268
+ dependentDependencyForbiddenFlags[dependencyIndex] = forbiddenFlags;
269
+ dependentDependencyOnReject[dependencyIndex] = onReject;
270
+ (0, utils_js_1.writeableArray)($dependency.dependents).push({
225
271
  step: $dependent,
226
272
  dependencyIndex,
227
273
  });
228
274
  return dependencyIndex;
229
275
  }
276
+ addStepUnaryDependency($dependent, options) {
277
+ const $dependency = options.step;
278
+ if (!$dependency._isUnary) {
279
+ const { nonUnaryMessage = defaultNonUnaryMessage } = options;
280
+ throw new Error(nonUnaryMessage($dependent, $dependency));
281
+ }
282
+ $dependency._isUnaryLocked = true;
283
+ return this.addStepDependency($dependent, options);
284
+ }
230
285
  setOutputPlanRootStep(outputPlan, $dependency) {
231
286
  if (!this.activeSteps.has($dependency)) {
232
287
  throw new Error(`Cannot add ${$dependency} to ${outputPlan} because it's deleted`);
@@ -307,9 +362,9 @@ class StepTracker {
307
362
  // Transfer step dependents of $original to $replacement
308
363
  const dependents = $original.dependents;
309
364
  if (dependents.length > 0) {
310
- const replacementDependents = writeableArray($replacement.dependents);
365
+ const replacementDependents = (0, utils_js_1.writeableArray)($replacement.dependents);
311
366
  for (const dependent of dependents) {
312
- writeableArray(dependent.step.dependencies)[dependent.dependencyIndex] = $replacement;
367
+ (0, utils_js_1.writeableArray)((0, utils_js_1.sudo)(dependent.step).dependencies)[dependent.dependencyIndex] = $replacement;
313
368
  replacementDependents.push(dependent);
314
369
  }
315
370
  $original.dependents = [];
@@ -389,6 +444,9 @@ class StepTracker {
389
444
  return false;
390
445
  if ($step.hasSideEffects)
391
446
  return false;
447
+ if (this.internalDependencies.has($step)) {
448
+ return false;
449
+ }
392
450
  const s1 = this.outputPlansByRootStep.get($step);
393
451
  if (s1 && s1.size !== 0)
394
452
  return false;
@@ -456,7 +514,7 @@ class StepTracker {
456
514
  this.stepById[$original.id] = null;
457
515
  }
458
516
  // Since this step is being removed, it doesn't need its dependencies any more
459
- const oldDependencies = $original.dependencies;
517
+ const oldDependencies = (0, utils_js_1.sudo)($original).dependencies;
460
518
  for (const $dependency of oldDependencies) {
461
519
  // $dependency is no longer a dependent of $original, since we're getting
462
520
  // rid of $original
@@ -494,7 +552,9 @@ class StepTracker {
494
552
  ]}`);
495
553
  }
496
554
  }
497
- this.stepsWithNoDependencies.delete($original);
555
+ this.stepsWithNoDependenciesByConstructor
556
+ .get($original.constructor)
557
+ ?.delete($original);
498
558
  this.outputPlansByRootStep.delete($original);
499
559
  this.layerPlansByRootStep.delete($original);
500
560
  this.layerPlansByParentStep.delete($original);
@@ -519,6 +579,20 @@ class StepTracker {
519
579
  removeStepFromItsLayerPlan(step) {
520
580
  step.layerPlan.stepsByConstructor.get(step.constructor).delete(step);
521
581
  }
582
+ lockNewSteps() {
583
+ if (!dev_js_1.isDev)
584
+ return;
585
+ for (let i = this.lockedStepCount; i < this.stepCount; i++) {
586
+ const step = this.getStepById(i, true);
587
+ if (step && step.id === i) {
588
+ (0, lock_js_1.lock)(step);
589
+ }
590
+ }
591
+ this.lockedStepCount = this.stepCount;
592
+ }
522
593
  }
523
594
  exports.StepTracker = StepTracker;
595
+ function defaultNonUnaryMessage($dependent, $dependency) {
596
+ return `${$dependent} attempted to create a unary step dependency on ${$dependency}, but that step is not unary. See https://err.red/gud`;
597
+ }
524
598
  //# sourceMappingURL=StepTracker.js.map
@@ -1,8 +1,6 @@
1
- import type { Bucket, RequestTools } from "../bucket.js";
2
- import type { PromiseOrDirect } from "../interfaces.js";
3
- import type { MetaByMetaKey } from "./OperationPlan.js";
4
- /** @internal */
5
- export declare function executeBucket(bucket: Bucket, requestContext: RequestTools): PromiseOrDirect<void>;
6
- /** @internal */
7
- export declare function newBucket(spec: Pick<Bucket, "layerPlan" | "store" | "size" | "hasErrors" | "polymorphicPathList" | "iterators">, parentMetaByMetaKey: MetaByMetaKey | null): Bucket;
1
+ import type { Bucket } from "../bucket.js";
2
+ import type { BatchExecutionValue, ExecutionEntryFlags, UnaryExecutionValue } from "../interfaces.js";
3
+ export declare function bucketToString(this: Bucket): string;
4
+ export declare function batchExecutionValue<TData>(entries: TData[], _flags?: ExecutionEntryFlags[]): BatchExecutionValue<TData>;
5
+ export declare function unaryExecutionValue<TData>(value: TData, _entryFlags?: ExecutionEntryFlags): UnaryExecutionValue<TData>;
8
6
  //# sourceMappingURL=executeBucket.d.ts.map