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,16 +1,15 @@
1
1
  import type { FragmentDefinitionNode, GraphQLFieldMap, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, OperationDefinitionNode } from "graphql";
2
2
  import type { Constraint } from "../constraints.js";
3
3
  import type { SelectionSetDigest } from "../graphqlCollectFields.js";
4
- import type { GrafastPlanJSON, ModifierStep } from "../index.js";
5
- import { __TrackedValueStep, __ValueStep, ExecutableStep } from "../index.js";
4
+ import type { GrafastPlanJSON } from "../index.js";
5
+ import { Step } from "../index.js";
6
6
  import { $$timeout, $$ts } from "../interfaces.js";
7
7
  import type { LayerPlanReasonSubroutine } from "./LayerPlan.js";
8
8
  import { LayerPlan } from "./LayerPlan.js";
9
9
  import { OutputPlan } from "./OutputPlan.js";
10
- import { StepTracker } from "./StepTracker.js";
11
10
  export declare const POLYMORPHIC_ROOT_PATH: null;
12
11
  export declare const POLYMORPHIC_ROOT_PATHS: ReadonlySet<string> | null;
13
- /** @internal */
12
+ /** Beware: the list of phases may change over time... @experimental */
14
13
  export type OperationPlanPhase = "init" | "plan" | "validate" | "optimize" | "finalize" | "ready";
15
14
  export interface MetaByMetaKey {
16
15
  [metaKey: string | number | symbol]: Record<string, any>;
@@ -49,62 +48,12 @@ export declare class OperationPlan {
49
48
  * 7. ready
50
49
  *
51
50
  * Once in 'ready' state we can execute the plan.
52
- *
53
- * @internal
54
51
  */
55
52
  phase: OperationPlanPhase;
56
53
  /**
57
54
  * Gets updated as we work our way through the plan, useful for making errors more helpful.
58
55
  */
59
56
  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
- private modifierStepCount;
70
- private modifierDepthCount;
71
- private modifierSteps;
72
- /** @internal */
73
- readonly stepTracker: StepTracker;
74
- private maxDeduplicatedStepId;
75
- 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
57
  /**
109
58
  * If true, then this operation doesn't use (custom) resolvers.
110
59
  */
@@ -116,42 +65,13 @@ export declare class OperationPlan {
116
65
  private scalarPlanInfo;
117
66
  constructor(schema: GraphQLSchema, operation: OperationDefinitionNode, fragments: {
118
67
  [fragmentName: string]: FragmentDefinitionNode;
119
- }, variableValues: {
68
+ }, variableValuesConstraints: Constraint[], variableValues: {
120
69
  [key: string]: any;
121
- }, context: {
70
+ }, contextConstraints: Constraint[], context: {
122
71
  [key: string]: any;
123
- }, rootValue: any, planningTimeout: number | null);
72
+ }, rootValueConstraints: Constraint[], rootValue: any, planningTimeout: number | null);
124
73
  private lap;
125
74
  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
75
  private planOperation;
156
76
  /**
157
77
  * Plans a GraphQL query operation.
@@ -170,7 +90,7 @@ export declare class OperationPlan {
170
90
  * create one item plan per parent plan.
171
91
  */
172
92
  private itemStepForListStep;
173
- processGroupedFieldSet(outputPlan: OutputPlan, path: readonly string[], polymorphicPath: string | null, polymorphicPaths: ReadonlySet<string> | null, parentStep: ExecutableStep, objectType: GraphQLObjectType, objectTypeFields: GraphQLFieldMap<any, any>, isMutation: boolean, groupedFieldSet: SelectionSetDigest): void;
93
+ processGroupedFieldSet(outputPlan: OutputPlan, path: readonly string[], polymorphicPath: string | null, polymorphicPaths: ReadonlySet<string> | null, parentStep: Step, objectType: GraphQLObjectType, objectTypeFields: GraphQLFieldMap<any, any>, isMutation: boolean, groupedFieldSet: SelectionSetDigest): void;
174
94
  /**
175
95
  *
176
96
  * @param outputPlan - The output plan that this selection set is being added to
@@ -181,6 +101,7 @@ export declare class OperationPlan {
181
101
  * @param isMutation - If true this selection set should be executed serially rather than in parallel (each field gets its own LayerPlan)
182
102
  */
183
103
  private planSelectionSet;
104
+ private internalDependency;
184
105
  private planIntoOutputPlan;
185
106
  private polymorphicLayerPlanByPathByLayerPlan;
186
107
  private getPolymorphicLayerPlan;
@@ -192,7 +113,6 @@ export declare class OperationPlan {
192
113
  * @see https://spec.graphql.org/draft/#CoerceArgumentValues()
193
114
  */
194
115
  private getTrackedArguments;
195
- withModifiers<T>(cb: () => T): T;
196
116
  /**
197
117
  * Sets up tracking for the given value (variableValues, context, rootValue).
198
118
  */
@@ -204,13 +124,6 @@ export declare class OperationPlan {
204
124
  private validateSteps;
205
125
  private replaceStep;
206
126
  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
127
  /**
215
128
  * Peers are steps of the same type (but not the same step!) that are in
216
129
  * compatible layers and have the same dependencies. Peers must not have side
@@ -246,7 +159,6 @@ export declare class OperationPlan {
246
159
  private hoistAndDeduplicate;
247
160
  private hoistSteps;
248
161
  private pushDownSteps;
249
- private getStepOptionsForStep;
250
162
  /**
251
163
  * Calls the 'optimize' method on a plan, which may cause the plan to
252
164
  * communicate with its (deep) dependencies, and even to replace itself with
@@ -258,6 +170,7 @@ export declare class OperationPlan {
258
170
  * know all our dependent's needs before we optimise ourself.
259
171
  */
260
172
  private optimizeSteps;
173
+ private inlineSteps;
261
174
  /** Finalizes each step */
262
175
  private finalizeSteps;
263
176
  private finalizeLayerPlans;
@@ -267,16 +180,29 @@ export declare class OperationPlan {
267
180
  private finalizeOutputPlans;
268
181
  private walkOutputPlans;
269
182
  generatePlanJSON(): GrafastPlanJSON;
270
- finishSubroutine(subroutineStep: ExecutableStep, layerPlan: LayerPlan<LayerPlanReasonSubroutine>): void;
183
+ finishSubroutine(subroutineStep: Step, layerPlan: LayerPlan<LayerPlanReasonSubroutine>): void;
184
+ getStepsByMetaKey(metaKey: string | number | symbol): Step[];
185
+ getStepsByStepClass<TClass extends Step>(klass: {
186
+ new (...args: any[]): TClass;
187
+ }): TClass[];
188
+ private _cacheStepStoreByLayerPlanAndActionKey;
271
189
  /**
272
- * HIGHLY EXPERIMENTAL!
190
+ * Cache a generated step by a given identifier (cacheKey) such that we don't
191
+ * need to regenerate it on future calls, significantly reducing the load on
192
+ * deduplication later.
193
+ *
194
+ * Note: automatically extends the cached step into other (relevant)
195
+ * polymorphic paths; if this shouldn't be the case then don't use cacheStep
196
+ * and instead rely on deduplication as usual.
273
197
  *
274
- * @internal
198
+ * @experimental
275
199
  */
276
- deleteLayerPlan(layerPlan: LayerPlan): void;
277
- getStepsByMetaKey(metaKey: string | number | symbol): ExecutableStep[];
278
- getStepsByStepClass<TClass extends ExecutableStep>(klass: {
279
- new (...args: any[]): TClass;
280
- }): TClass[];
200
+ cacheStep<T extends Step>(ownerStep: Step, actionKey: string, cacheKey: symbol | string | number | boolean | null | undefined, cb: () => T): T;
201
+ /**
202
+ * Clears the cache, typically due to side effects having taken place. Called
203
+ * from setting hasSideEffects on an ExecutableStep, among other places.
204
+ */
205
+ resetCache(): void;
206
+ withRootLayerPlan<T>(cb: () => T): T;
281
207
  }
282
208
  //# sourceMappingURL=OperationPlan.d.ts.map