grafast 0.1.1-beta.4 → 0.1.1-beta.6

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 (57) hide show
  1. package/dist/bucket.d.ts +1 -89
  2. package/dist/dev.d.ts +0 -4
  3. package/dist/dev.js +18 -1
  4. package/dist/engine/LayerPlan.d.ts +1 -96
  5. package/dist/engine/OperationPlan.d.ts +3 -92
  6. package/dist/engine/OperationPlan.js +48 -30
  7. package/dist/engine/OutputPlan.d.ts +0 -12
  8. package/dist/engine/StepTracker.d.ts +1 -95
  9. package/dist/engine/StepTracker.js +18 -3
  10. package/dist/engine/executeBucket.d.ts +1 -7
  11. package/dist/engine/executeBucket.js +7 -6
  12. package/dist/engine/executeOutputPlan.d.ts +0 -53
  13. package/dist/engine/lock.d.ts +4 -0
  14. package/dist/engine/lock.js +82 -0
  15. package/dist/error.d.ts +4 -48
  16. package/dist/error.js +4 -0
  17. package/dist/execute.d.ts +0 -5
  18. package/dist/execute.js +2 -2
  19. package/dist/exportAs.d.ts +1 -18
  20. package/dist/graphqlCollectFields.d.ts +1 -34
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +13 -1
  23. package/dist/input.d.ts +1 -9
  24. package/dist/interfaces.d.ts +1 -12
  25. package/dist/makeGrafastSchema.js +22 -0
  26. package/dist/mermaid.d.ts +0 -17
  27. package/dist/prepare.d.ts +1 -7
  28. package/dist/step.d.ts +4 -65
  29. package/dist/step.js +5 -1
  30. package/dist/steps/__item.d.ts +1 -4
  31. package/dist/steps/__item.js +3 -0
  32. package/dist/steps/__trackedValue.d.ts +0 -11
  33. package/dist/steps/access.d.ts +0 -2
  34. package/dist/steps/applyTransforms.d.ts +0 -23
  35. package/dist/steps/connection.d.ts +1 -1
  36. package/dist/steps/each.js +1 -1
  37. package/dist/steps/first.d.ts +1 -1
  38. package/dist/steps/first.js +1 -1
  39. package/dist/steps/graphqlResolver.d.ts +2 -75
  40. package/dist/steps/index.d.ts +5 -1
  41. package/dist/steps/index.js +17 -2
  42. package/dist/steps/lambda.js +5 -0
  43. package/dist/steps/last.d.ts +1 -1
  44. package/dist/steps/last.js +1 -1
  45. package/dist/steps/list.d.ts +2 -0
  46. package/dist/steps/list.js +6 -0
  47. package/dist/steps/listTransform.d.ts +0 -6
  48. package/dist/steps/load.d.ts +0 -2
  49. package/dist/steps/load.js +1 -2
  50. package/dist/steps/object.d.ts +1 -1
  51. package/dist/steps/sideEffect.d.ts +29 -0
  52. package/dist/steps/sideEffect.js +40 -0
  53. package/dist/utils.d.ts +1 -24
  54. package/dist/utils.js +25 -4
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/package.json +4 -4
package/dist/bucket.d.ts CHANGED
@@ -1,90 +1,2 @@
1
- import type { LayerPlan } from "./engine/LayerPlan";
2
- import type { MetaByMetaKey } from "./engine/OperationPlan";
3
- import type { ExecutionEventEmitter } from "./interfaces.js";
4
- /**
5
- * @internal
6
- */
7
- export interface RequestTools {
8
- /** The `timeSource.now()` at which the request started executing */
9
- startTime: number;
10
- /** The `timeSource.now()` at which the request should stop executing (if a timeout was configured) */
11
- stopTime: number | null;
12
- readonly eventEmitter: ExecutionEventEmitter | undefined;
13
- /**
14
- * If we're running inside GraphQL then we should not serialize scalars,
15
- * otherwise we'll face the double-serialization problem.
16
- */
17
- insideGraphQL: false;
18
- }
19
- /**
20
- * A "bucket" is where the results from plans are stored so that other plans
21
- * can retrieve them, it may take on different forms depending on the mode of
22
- * execution. A "LayerPlan" is used to both identify the bucket and to specify
23
- * why it exists and how it behaves.
24
- *
25
- * Every `ExecutableStep` belongs to exactly one LayerPlan (and thus bucket),
26
- * specified by `plan.layerPlan`.
27
- *
28
- * @internal
29
- */
30
- export interface Bucket {
31
- /**
32
- * The LayerPlan definition this bucket adheres to
33
- */
34
- layerPlan: LayerPlan;
35
- /**
36
- * How many entries are there in the bucket?
37
- */
38
- size: number;
39
- /**
40
- * The polymorphic path through which each of the entries (respectively) has
41
- * travelled. This influences the steps that will be executed using the
42
- * related inputs.
43
- */
44
- polymorphicPathList: readonly (string | null)[];
45
- /**
46
- * These are the iterators the bucket (or its descendents, without crossing a
47
- * stream/defer boundary) have created (if any). Each of these must either be
48
- * processed via `processRoot`, or must be manually released (via
49
- * `releaseUnusedIterators`) otherwise a memory leak could occur.
50
- */
51
- iterators: Array<Set<AsyncIterator<any> | Iterator<any>>>;
52
- /**
53
- * `metaByMetaKey` belongs to the bucket rather than the request context
54
- * because mutations and subscriptions shouldn't re-use caches.
55
- *
56
- * TODO: `inheritMeta: boolean`?
57
- */
58
- metaByMetaKey: MetaByMetaKey;
59
- /**
60
- * Every entry in the store is a list with the same length as the bucket has
61
- * `size`.
62
- *
63
- * The entry for '-1' is the request indexes, so we can associate the results
64
- * back to the request that triggered them.
65
- */
66
- store: Map<number, any[]>;
67
- /**
68
- * Set this true when the bucket is fully executed.
69
- *
70
- * Initialize it to false.
71
- */
72
- isComplete: boolean;
73
- /**
74
- * If an error occurred at any stage we need to drop down to more careful
75
- * (and slower) handling.
76
- *
77
- * Initialize it to false.
78
- */
79
- hasErrors: boolean;
80
- /**
81
- * The child buckets of this bucket.
82
- */
83
- children: {
84
- [layerPlanId: number]: {
85
- bucket: Bucket;
86
- map: Map<number, number | number[]>;
87
- };
88
- };
89
- }
1
+ export {};
90
2
  //# sourceMappingURL=bucket.d.ts.map
package/dist/dev.d.ts CHANGED
@@ -1,6 +1,2 @@
1
- /**
2
- * @internal
3
- */
4
- export declare const isDev: boolean;
5
1
  export declare function noop(): void;
6
2
  //# sourceMappingURL=dev.d.ts.map
package/dist/dev.js CHANGED
@@ -4,7 +4,24 @@ exports.noop = exports.isDev = void 0;
4
4
  /**
5
5
  * @internal
6
6
  */
7
- exports.isDev = typeof process !== "undefined" && process.env.GRAPHILE_ENV === "development";
7
+ const graphileEnv = typeof process !== "undefined" ? process.env.GRAPHILE_ENV : undefined;
8
+ const nodeEnv = typeof process !== "undefined" ? process.env.NODE_ENV : undefined;
9
+ /**
10
+ * @internal
11
+ */
12
+ exports.isDev = graphileEnv !== undefined
13
+ ? graphileEnv === "development" || graphileEnv === "test"
14
+ : nodeEnv === "development" || nodeEnv === "test";
8
15
  function noop() { }
9
16
  exports.noop = noop;
17
+ if (typeof process !== "undefined" &&
18
+ typeof graphileEnv === "undefined" &&
19
+ typeof nodeEnv === "undefined") {
20
+ console.warn(`The GRAPHILE_ENV environmental variable is not set; Grafast will run in production mode. In your development environments, it's recommended that you set \`GRAPHILE_ENV=development\` to opt in to additional checks that will provide guidance and help you to catch issues in your code earlier, and other changes such as formatting to improve your development experience.`);
21
+ }
22
+ else if (exports.isDev) {
23
+ console.warn(`Grafast is running in development mode due to \`${graphileEnv !== undefined
24
+ ? `GRAPHILE_ENV=${graphileEnv}`
25
+ : `NODE_ENV=${nodeEnv}`}\`; this is recommended for development environments (and strongly discouraged in production), but will impact on performance - in particular, planning will be significantly more expensive.`);
26
+ }
10
27
  //# sourceMappingURL=dev.js.map
@@ -1,5 +1,5 @@
1
1
  import type { Bucket } from "../bucket.js";
2
- import type { ExecutableStep, ModifierStep, UnbatchedExecutableStep } from "../step";
2
+ import type { ExecutableStep } from "../step";
3
3
  import type { OperationPlan } from "./OperationPlan";
4
4
  /** Non-branching, non-deferred */
5
5
  export interface LayerPlanReasonRoot {
@@ -71,43 +71,6 @@ export type HasParent<A extends LayerPlanReason> = A extends any ? A extends {
71
71
  parentStep: ExecutableStep;
72
72
  } ? A : never : never;
73
73
  export type LayerPlanReasonsWithParentStep = HasParent<LayerPlanReason>;
74
- /** @internal */
75
- export interface LayerPlanPhase {
76
- /**
77
- * If true, we should check before the layer plan executes to see if the
78
- * execution has already timed out.
79
- *
80
- * @see {@link RequestTools.stopTime}
81
- */
82
- checkTimeout: boolean;
83
- /**
84
- * A list of steps that can be ran in parallel at this point, since all
85
- * their previous dependencies have already been satisfied.
86
- */
87
- normalSteps: Array<{
88
- step: ExecutableStep;
89
- }> | undefined;
90
- /**
91
- * A list of 'isSyncAndSafe' steps with unbatchedExecute methods that can be
92
- * ran once the `normalSteps` have completed; they must only depend on steps
93
- * that have already been executed before them (including previous
94
- * unbatchedSyncAndSafeSteps in the same list).
95
- */
96
- unbatchedSyncAndSafeSteps: Array<{
97
- step: UnbatchedExecutableStep;
98
- /**
99
- * Store the result of the step here if you want - useful to avoid lookups
100
- * and when there's no storage. HIGHLY VOLATILE, will not survive a tick!
101
- */
102
- scratchpad: any;
103
- }> | undefined;
104
- /**
105
- * Optimization - a digest of all steps in normalSteps and unbatchedSyncAndSafeSteps
106
- *
107
- * @internal
108
- */
109
- _allSteps: ExecutableStep[];
110
- }
111
74
  /**
112
75
  * A LayerPlan represents (via "reason") either the root (root), when something
113
76
  * happens at a later time (mutationField, defer), when plurality changes
@@ -138,58 +101,6 @@ export declare class LayerPlan<TReason extends LayerPlanReason = LayerPlanReason
138
101
  parentLayerPlan: LayerPlan | null;
139
102
  readonly reason: TReason;
140
103
  id: number;
141
- /**
142
- * Every layer plan has a "root step" that shapes the value the layer
143
- * returns. Note that this step may be dependent on other steps included in
144
- * the LayerPlan, or could be provided externally.
145
- *
146
- * The root step is different for different layer step reasons:
147
- *
148
- * - root: the `operationPlan.rootValue`
149
- * - listItem: the `__ItemStep`
150
- * - stream: also the `__ItemStep`
151
- * - subscription: also the `__ItemStep`
152
- * - mutationField: the result plan of the mutation field
153
- * - defer: the parent layer's rootStep (defer always results in an object, unless an error occurs)
154
- * - polymorphic: the plan for the particular type
155
- * - subroutine: the result (returned) plan of the subroutine
156
- *
157
- * @internal
158
- */
159
- readonly rootStep: ExecutableStep | null;
160
- /**
161
- * Which plans the results for which are available in a parent bucket need to
162
- * be "copied across" to this bucket because plans in this bucket still
163
- * reference them?
164
- *
165
- * @internal
166
- */
167
- copyStepIds: number[];
168
- /** @internal */
169
- children: LayerPlan[];
170
- /** @internal */
171
- steps: ExecutableStep[];
172
- /** @internal */
173
- pendingSteps: ExecutableStep[];
174
- /**
175
- * Describes the order in which the steps within this LayerPlan are executed.
176
- *
177
- * Special attention must be paid to steps that have side effects.
178
- *
179
- * @internal
180
- */
181
- phases: Array<LayerPlanPhase>;
182
- /**
183
- * The list of layerPlans that steps added to this LayerPlan may depend upon.
184
- * Note this includes self, so it has one more entry than `depth`.
185
- *
186
- * ```
187
- * this.ancestry[this.depth] === this;
188
- * ```
189
- *
190
- * @internal
191
- */
192
- ancestry: LayerPlan[];
193
104
  /** How "deep" this layer plan is (how many ancestors it has). The root layer plan has a depth of 0. */
194
105
  depth: number;
195
106
  /** The depth at which a "defer boundary" occurs (OperationPlan.getPeers cannot pass a defer boundary), or 0. */
@@ -203,12 +114,6 @@ export declare class LayerPlan<TReason extends LayerPlanReason = LayerPlanReason
203
114
  toString(): string;
204
115
  print(depth?: number): string;
205
116
  setRootStep($root: ExecutableStep): void;
206
- /** @internal Use plan.getStep(id) instead. */
207
- getStep(id: number, requestingStep: ExecutableStep): ExecutableStep;
208
- /** @internal */
209
- _addStep(step: ExecutableStep): number;
210
- /** @internal */
211
- _addModifierStep(step: ModifierStep<any>): string;
212
117
  finalize(): void;
213
118
  newBucket(parentBucket: Bucket): Bucket | null;
214
119
  }
@@ -1,16 +1,14 @@
1
1
  import type { FragmentDefinitionNode, GraphQLFieldMap, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, OperationDefinitionNode } from "graphql";
2
- import type { Constraint } from "../constraints.js";
3
2
  import type { SelectionSetDigest } from "../graphqlCollectFields.js";
4
- import type { GrafastPlanJSON, ModifierStep } from "../index.js";
5
- import { __TrackedValueStep, __ValueStep, ExecutableStep } from "../index.js";
3
+ import type { GrafastPlanJSON } from "../index.js";
4
+ import { ExecutableStep } from "../index.js";
6
5
  import { $$timeout, $$ts } from "../interfaces.js";
7
6
  import type { LayerPlanReasonSubroutine } from "./LayerPlan.js";
8
7
  import { LayerPlan } from "./LayerPlan.js";
9
8
  import { OutputPlan } from "./OutputPlan.js";
10
- import { StepTracker } from "./StepTracker.js";
11
9
  export declare const POLYMORPHIC_ROOT_PATH: null;
12
10
  export declare const POLYMORPHIC_ROOT_PATHS: ReadonlySet<string> | null;
13
- /** @internal */
11
+ /** Beware: the list of phases may change over time... @experimental */
14
12
  export type OperationPlanPhase = "init" | "plan" | "validate" | "optimize" | "finalize" | "ready";
15
13
  export interface MetaByMetaKey {
16
14
  [metaKey: string | number | symbol]: Record<string, any>;
@@ -49,62 +47,17 @@ export declare class OperationPlan {
49
47
  * 7. ready
50
48
  *
51
49
  * Once in 'ready' state we can execute the plan.
52
- *
53
- * @internal
54
50
  */
55
51
  phase: OperationPlanPhase;
56
52
  /**
57
53
  * Gets updated as we work our way through the plan, useful for making errors more helpful.
58
54
  */
59
55
  loc: string[] | null;
60
- /** @internal */
61
- rootLayerPlan: LayerPlan;
62
- /**
63
- * Assigned during OperationPlan.planOperation(), guaranteed to exist after
64
- * initialization.
65
- *
66
- * @internal
67
- */
68
- rootOutputPlan: OutputPlan;
69
56
  private modifierStepCount;
70
57
  private modifierDepthCount;
71
58
  private modifierSteps;
72
- /** @internal */
73
- readonly stepTracker: StepTracker;
74
59
  private maxDeduplicatedStepId;
75
60
  private maxValidatedStepId;
76
- /** Constraints based on evaluating variables. @internal */
77
- readonly variableValuesConstraints: Constraint[];
78
- /** Stores the actual variableValues. @internal */
79
- readonly variableValuesStep: __ValueStep<{
80
- [key: string]: any;
81
- }>;
82
- /** A step for accessing variableValues in a tracked manner (allowing eval). @internal */
83
- readonly trackedVariableValuesStep: __TrackedValueStep<{
84
- [key: string]: any;
85
- }>;
86
- /** Constraints based on evaluating context. @internal */
87
- readonly contextConstraints: Constraint[];
88
- /** Stores the actual value of the context. @internal */
89
- readonly contextStep: __ValueStep<Grafast.Context>;
90
- /** Allows accessing context in a tracked manner (allowing eval). @internal */
91
- readonly trackedContextStep: __TrackedValueStep<{
92
- [key: string]: any;
93
- }>;
94
- /** Constraints based on evaluating rootValue. @internal */
95
- readonly rootValueConstraints: Constraint[];
96
- /** Stores the actual value of rootValue. @internal */
97
- readonly rootValueStep: __ValueStep<any>;
98
- /** Allows accessing rootValue in a tracked manner (allowing eval). @internal */
99
- readonly trackedRootValueStep: __TrackedValueStep<any>;
100
- /** @internal */
101
- makeMetaByMetaKey: () => MetaByMetaKey;
102
- /**
103
- * @internal
104
- */
105
- readonly itemStepIdByListStepId: {
106
- [listStepId: number]: number | undefined;
107
- };
108
61
  /**
109
62
  * If true, then this operation doesn't use (custom) resolvers.
110
63
  */
@@ -123,35 +76,6 @@ export declare class OperationPlan {
123
76
  }, rootValue: any, planningTimeout: number | null);
124
77
  private lap;
125
78
  private checkTimeout;
126
- /**
127
- * Called by the LayerPlan's constructor when it wants to get a new id to use.
128
- *
129
- * @internal
130
- */
131
- addLayerPlan(layerPlan: LayerPlan): number;
132
- /**
133
- * Adds a plan to the known steps and returns the number to use as the plan
134
- * id. ONLY to be used from Step, user code should never call this directly.
135
- *
136
- * @internal
137
- */
138
- _addStep(plan: ExecutableStep): number;
139
- /**
140
- * Adds a plan to the known steps and returns the number to use as the plan
141
- * id. ONLY to be used from Step, user code should never call this directly.
142
- *
143
- * @internal
144
- */
145
- _addModifierStep(step: ModifierStep<any>): string;
146
- /** @internal Use plan.getStep(id) instead. */
147
- getStep: (id: number, requestingStep: ExecutableStep) => ExecutableStep;
148
- /**
149
- * Get a plan without specifying who requested it; this disables all the
150
- * caller checks. Only intended to be called from internal code.
151
- *
152
- * @internal
153
- */
154
- dangerouslyGetStep(id: number): ExecutableStep;
155
79
  private planOperation;
156
80
  /**
157
81
  * Plans a GraphQL query operation.
@@ -204,13 +128,6 @@ export declare class OperationPlan {
204
128
  private validateSteps;
205
129
  private replaceStep;
206
130
  private processStep;
207
- /**
208
- * Process the given steps, either dependencies first (root to leaf) or
209
- * dependents first (leaves to root).
210
- *
211
- * @internal
212
- */
213
- processSteps(actionDescription: string, order: "dependents-first" | "dependencies-first", isReadonly: boolean, callback: (plan: ExecutableStep) => ExecutableStep): void;
214
131
  /**
215
132
  * Peers are steps of the same type (but not the same step!) that are in
216
133
  * compatible layers and have the same dependencies. Peers must not have side
@@ -268,12 +185,6 @@ export declare class OperationPlan {
268
185
  private walkOutputPlans;
269
186
  generatePlanJSON(): GrafastPlanJSON;
270
187
  finishSubroutine(subroutineStep: ExecutableStep, layerPlan: LayerPlan<LayerPlanReasonSubroutine>): void;
271
- /**
272
- * HIGHLY EXPERIMENTAL!
273
- *
274
- * @internal
275
- */
276
- deleteLayerPlan(layerPlan: LayerPlan): void;
277
188
  getStepsByMetaKey(metaKey: string | number | symbol): ExecutableStep[];
278
189
  getStepsByStepClass<TClass extends ExecutableStep>(klass: {
279
190
  new (...args: any[]): TClass;