grafast 0.0.1-alpha.13 → 0.0.1-alpha.15

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 (66) hide show
  1. package/dist/args.d.ts +7 -5
  2. package/dist/assert.d.ts +2 -0
  3. package/dist/bucket.d.ts +64 -0
  4. package/dist/constraints.d.ts +31 -0
  5. package/dist/deferred.d.ts +7 -0
  6. package/dist/dev.d.ts +3 -0
  7. package/dist/engine/LayerPlan.d.ts +131 -0
  8. package/dist/engine/OperationPlan.d.ts +151 -0
  9. package/dist/engine/OutputPlan.d.ts +105 -1
  10. package/dist/engine/StepTracker.d.ts +53 -0
  11. package/dist/engine/executeBucket.d.ts +2 -0
  12. package/dist/engine/executeOutputPlan.d.ts +41 -0
  13. package/dist/envelop.d.ts +12 -0
  14. package/dist/envelop.js +4 -4
  15. package/dist/error.d.ts +23 -0
  16. package/dist/establishOperationPlan.d.ts +7 -0
  17. package/dist/execute.d.ts +8 -0
  18. package/dist/exportAs.d.ts +14 -0
  19. package/dist/grafastGraphql.d.ts +8 -3
  20. package/dist/grafastPrint.d.ts +8 -0
  21. package/dist/graphqlCollectFields.d.ts +22 -0
  22. package/dist/graphqlMergeSelectionSets.d.ts +4 -0
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +4 -4
  25. package/dist/input.d.ts +7 -0
  26. package/dist/interfaces.d.ts +267 -5
  27. package/dist/makeGrafastSchema.d.ts +27 -0
  28. package/dist/mermaid.d.ts +28 -0
  29. package/dist/polymorphic.d.ts +8 -0
  30. package/dist/prepare.d.ts +16 -0
  31. package/dist/step.d.ts +183 -0
  32. package/dist/steps/__inputDynamicScalar.d.ts +3 -0
  33. package/dist/steps/__inputList.d.ts +3 -0
  34. package/dist/steps/__inputObject.d.ts +3 -0
  35. package/dist/steps/__inputStaticLeaf.d.ts +5 -0
  36. package/dist/steps/__item.d.ts +8 -0
  37. package/dist/steps/__trackedValue.d.ts +74 -0
  38. package/dist/steps/__value.d.ts +5 -0
  39. package/dist/steps/access.d.ts +19 -0
  40. package/dist/steps/applyTransforms.d.ts +13 -0
  41. package/dist/steps/connection.d.ts +47 -0
  42. package/dist/steps/constant.d.ts +7 -0
  43. package/dist/steps/each.d.ts +3 -0
  44. package/dist/steps/filter.d.ts +4 -0
  45. package/dist/steps/first.d.ts +4 -0
  46. package/dist/steps/graphqlResolver.d.ts +18 -0
  47. package/dist/steps/groupBy.d.ts +6 -0
  48. package/dist/steps/index.d.ts +4 -0
  49. package/dist/steps/lambda.d.ts +8 -0
  50. package/dist/steps/last.d.ts +4 -0
  51. package/dist/steps/list.d.ts +7 -0
  52. package/dist/steps/listTransform.d.ts +21 -0
  53. package/dist/steps/listen.d.ts +16 -0
  54. package/dist/steps/load.d.ts +13 -0
  55. package/dist/steps/node.d.ts +12 -0
  56. package/dist/steps/object.d.ts +15 -0
  57. package/dist/steps/partitionByIndex.d.ts +35 -0
  58. package/dist/steps/proxy.d.ts +11 -0
  59. package/dist/steps/remapKeys.d.ts +8 -0
  60. package/dist/steps/reverse.d.ts +9 -0
  61. package/dist/subscribe.d.ts +4 -0
  62. package/dist/utils.d.ts +102 -0
  63. package/dist/version.d.ts +1 -1
  64. package/fwd/graphql/index.d.ts +1 -0
  65. package/fwd/graphql/index.js +1 -0
  66. package/package.json +2 -2
package/dist/step.d.ts CHANGED
@@ -4,51 +4,218 @@ import type { OperationPlan } from "./engine/OperationPlan.js";
4
4
  import type { ExecutionExtra, GrafastResultsList, GrafastResultStreamList, GrafastValuesList, PromiseOrDirect, StepOptimizeOptions, StepOptions } from "./interfaces.js";
5
5
  import { $$subroutine } from "./interfaces.js";
6
6
  import type { __ItemStep } from "./steps/index.js";
7
+ /**
8
+ * @internal
9
+ */
7
10
  export declare const $$deepDepSkip: unique symbol;
11
+ /**
12
+ * This indicates that a step never executes (e.g. __ItemStep and __ValueStep)
13
+ * and thus when executed skips direct to reallyCompletedStep.
14
+ *
15
+ * @internal
16
+ */
8
17
  export declare const $$noExec: unique symbol;
9
18
  declare function reallyAssertFinalized(plan: BaseStep): void;
10
19
  export declare const assertFinalized: typeof reallyAssertFinalized;
20
+ /**
21
+ * The base abstract plan type; you should not extend this directly - instead
22
+ * use an ExecutableStep (for use when planning output fields) or a
23
+ * ModifierStep (for use when planning arguments/input fields).
24
+ *
25
+ * @remarks
26
+ *
27
+ * Though it might seem that ModifierStep should be used for all inputs
28
+ * (arguments, input objects), this is not the case. When planning an output
29
+ * field, all inputs to it (including arguments, parent plan, context, etc)
30
+ * should be other executable plans. The only time that ModifierStep is used is
31
+ * when writing specific plans as part of the argument or input field
32
+ * definitions themself; even in these cases the inputs to these plan resolvers
33
+ * will be ExecutablePlans.
34
+ */
11
35
  export declare abstract class BaseStep {
36
+ /**
37
+ * This identifies the "bucket" into which this plan's results will be stored.
38
+ * New buckets are introduced when you cross boundaries that may change the
39
+ * number of results in the bucket, or where control over execution is desired.
40
+ *
41
+ * - Lists / list items (generally multiplies up)
42
+ * - Polymorphism - different entries may go into different buckets
43
+ * - Mutations - early termination is likely
44
+ * - Defer boundaries - don't execute this stuff until later
45
+ * - null boundaries - if a null is met, no need to continue execution
46
+ *
47
+ * This bucket influences:
48
+ *
49
+ * 1. how plans are deduplicated
50
+ * 2. the order in which the plans are executed
51
+ * 3. where the result of executing the plan is stored
52
+ * 4. when the plan execution cache is allowed to be GC'd
53
+ *
54
+ * NOTE: `__ListTransformStep`'s effectively have a temporary bucket inside
55
+ * them (built on the `__Item`) that's thrown away once the transform is
56
+ * complete.
57
+ *
58
+ * @internal
59
+ */
12
60
  readonly layerPlan: LayerPlan;
13
61
  readonly operationPlan: OperationPlan;
14
62
  [$$subroutine]: LayerPlan<LayerPlanReasonSubroutine> | null;
15
63
  isArgumentsFinalized: boolean;
16
64
  isFinalized: boolean;
17
65
  debug: boolean;
66
+ /**
67
+ * Set this true for plans that implement mutations; this will prevent them
68
+ * from being tree-shaken.
69
+ */
18
70
  hasSideEffects: boolean;
19
71
  constructor();
20
72
  toString(): string;
73
+ /**
74
+ * This metadata will be merged into toString when referencing this plan.
75
+ */
21
76
  toStringMeta(): string | null;
22
77
  finalize(): void;
23
78
  destroy(): void;
24
79
  }
80
+ /**
81
+ * Executable plans are the plans associated with leaves on the GraphQL tree,
82
+ * they must be able to execute to return values.
83
+ */
25
84
  export declare class ExecutableStep<TData = any> extends BaseStep {
26
85
  static $$export: any;
86
+ /**
87
+ * Setting this true is a performance optimisation, but it comes with strong
88
+ * rules; we do not test you comply with these rules (as that would undo the
89
+ * performance gains) but should you break them the behaviour is undefined
90
+ * (and, basically, the schema may no longer be GraphQL compliant).
91
+ *
92
+ * Do not set this true unless the following hold:
93
+ *
94
+ * - The `execute` method must be a regular (not async) function
95
+ * - The `execute` method must NEVER return a promise
96
+ * - The values within the list returned from `execute` must NEVER include
97
+ * promises or GrafastError objects
98
+ * - The result of calling `execute` should not differ after a
99
+ * `step.hasSideEffects` has executed (i.e. it should be pure, only
100
+ * dependent on its deps and use no external state)
101
+ *
102
+ * It's acceptable for the `execute` method to throw if it needs to.
103
+ *
104
+ * This optimisation applies to the majority of the built in plans and allows
105
+ * the engine to execute without needing to resolve any promises which saves
106
+ * precious event-loop ticks.
107
+ */
27
108
  isSyncAndSafe: boolean;
109
+ /**
110
+ * The plan this plan will need data from in order to execute.
111
+ * @internal
112
+ */
28
113
  readonly dependencies: ReadonlyArray<ExecutableStep>;
114
+ /**
115
+ * Just for mermaid
116
+ * @internal
117
+ */
29
118
  readonly dependents: ReadonlyArray<{
30
119
  step: ExecutableStep;
31
120
  dependencyIndex: number;
32
121
  }>;
122
+ /**
123
+ * We reserve the right to change our mind as to whether this is a string or
124
+ * number.
125
+ *
126
+ * @internal
127
+ */
33
128
  readonly id: number;
129
+ /**
130
+ /**
131
+ * True when `optimize` has been called at least once.
132
+ */
34
133
  isOptimized: boolean;
134
+ /**
135
+ * Set this true if your plan's optimize method can be called a second time;
136
+ * note that in this situation it's likely that your dependencies will not be
137
+ * what you expect them to be (e.g. a PgSelectSingleStep might become an
138
+ * AccessStep).
139
+ */
35
140
  allowMultipleOptimizations: boolean;
141
+ /** @internal */
36
142
  _stepOptions: StepOptions;
143
+ /** @internal */
37
144
  polymorphicPaths: ReadonlySet<string> | null;
145
+ /**
146
+ * True if this needs to be permanently stored; for example:
147
+ *
148
+ * - Is the dep of another LayerPlan
149
+ * - Is used in an OutputPlan
150
+ *
151
+ * @internal
152
+ */
38
153
  store: boolean;
154
+ /**
155
+ * Set the metaKey so `execute` will be passed a meta object to use.
156
+ * Depending on what you set it to, you can share execution meta between
157
+ * multiple steps of the same class (or even a family of step classes).
158
+ *
159
+ * A sensible value for it is `this.metaKey = this.id;`.
160
+ */
39
161
  metaKey: number | string | symbol | undefined;
162
+ /**
163
+ * Like `metaKey` but for the optimize phase
164
+ */
40
165
  optimizeMetaKey: number | string | symbol | undefined;
41
166
  constructor();
42
167
  protected withMyLayerPlan<T>(callback: () => T): T;
43
168
  protected getStep(id: number): ExecutableStep;
44
169
  getDep(depId: number): ExecutableStep;
170
+ /**
171
+ * Like getDep, except it skips over __ItemStep and similar steps to get to
172
+ * where the parent really is.
173
+ *
174
+ * @experimental
175
+ */
45
176
  protected getDepDeep(depId: number): ExecutableStep;
46
177
  toString(): string;
47
178
  protected addDependency(step: ExecutableStep, skipDeduplication?: boolean): number;
179
+ /**
180
+ * Given a list of "peer" steps, return a list of these `peers` that are
181
+ * equivalent to this step.
182
+ *
183
+ * NOTE: equivalence goes both ways: `a.deduplicate([b]).includes(b)` if and
184
+ * only if `b.deduplicate([a]).includes(a)`.
185
+ *
186
+ * If you need to transform the peer to be equivalent you should do so via
187
+ * the `deduplicatedWith` callback later.
188
+ */
48
189
  deduplicate?(_peers: readonly ExecutableStep[]): readonly ExecutableStep[];
190
+ /**
191
+ * If this plan is replaced via deduplication, this method gives it a chance
192
+ * to hand over its responsibilities to its replacement.
193
+ */
49
194
  deduplicatedWith?(replacement: ExecutableStep): void;
195
+ /**
196
+ * Our chance to optimise the plan (which could go as far as to inline the
197
+ * plan into the parent plan).
198
+ */
50
199
  optimize?(_options: StepOptimizeOptions): ExecutableStep;
51
200
  finalize(): void;
201
+ /**
202
+ * This function will be called with a `values` list: an array of entries for
203
+ * each incoming grafast object, where each entry in the array is a list of
204
+ * the values retrieved from executing the plans in `this.dependencies` for
205
+ * that grafast object.
206
+ *
207
+ * It must return a list with the same length as `values`, where each value
208
+ * in the list relates to the result of executing this plan for the
209
+ * corresponding entry in the `values` list.
210
+ *
211
+ * IMPORTANT: it is up to the execute function to cache/memoize results as
212
+ * appropriate for performance, this can be done via the `meta` object.
213
+ *
214
+ * The `meta` object is an empty object stored to `grafastContext.metaByPlan`
215
+ * that can be used to store anything this plan needs. We recommend that you
216
+ * add attributes to meta for each purpose (e.g. use `meta.cache` for
217
+ * memoizing results) so that you can expand your usage of meta in future.
218
+ */
52
219
  execute(count: number, values: ReadonlyArray<GrafastValuesList<any>>, extra: ExecutionExtra): PromiseOrDirect<GrafastResultsList<TData>>;
53
220
  destroy(): void;
54
221
  }
@@ -79,6 +246,11 @@ export declare function isObjectLikeStep<TData extends {
79
246
  [key: string]: ExecutableStep;
80
247
  }>(plan: ExecutableStep): plan is ObjectLikeStep<TData>;
81
248
  export type StreamableStep<TData> = ExecutableStep<ReadonlyArray<TData>> & {
249
+ /**
250
+ * If this plan supports streaming then it should implement this method. It's
251
+ * basically the same as `execute` except it returns a list of result streams
252
+ * rather than a list of results.
253
+ */
82
254
  stream(count: number, values: ReadonlyArray<GrafastValuesList<any>>, extra: ExecutionExtra, streamOptions: {
83
255
  initialCount: number;
84
256
  }): PromiseOrDirect<GrafastResultStreamList<TData>>;
@@ -88,12 +260,23 @@ export type PolymorphicStep = ExecutableStep & {
88
260
  planForType(objectType: GraphQLObjectType): ExecutableStep;
89
261
  };
90
262
  export declare function isPolymorphicStep(s: ExecutableStep): s is PolymorphicStep;
263
+ /**
264
+ * Modifier plans modify their parent plan (which may be another ModifierStep
265
+ * or an ExecutableStep). First they gather all the requirements from their
266
+ * children (if any) being applied to them, then they apply themselves to their
267
+ * parent plan. This application is done through the `apply()` method.
268
+ *
269
+ * Modifier plans do not use dependencies.
270
+ */
91
271
  export declare abstract class ModifierStep<TParentStep extends BaseStep = BaseStep> extends BaseStep {
92
272
  protected readonly $parent: TParentStep;
93
273
  static $$export: any;
94
274
  readonly id: string;
95
275
  constructor($parent: TParentStep);
96
276
  toString(): string;
277
+ /**
278
+ * In this method, you should apply the changes to your `this.$parent` plan
279
+ */
97
280
  abstract apply(): void;
98
281
  }
99
282
  export declare function isModifierStep<TParentStep extends ExecutableStep | ModifierStep<any>>(plan: BaseStep): plan is ModifierStep<TParentStep>;
@@ -1,6 +1,9 @@
1
1
  import type { GraphQLScalarType, ListValueNode, ObjectValueNode } from "graphql";
2
2
  import type { ExecutionExtra } from "../interfaces.js";
3
3
  import { UnbatchedExecutableStep } from "../step.js";
4
+ /**
5
+ * Handles "leaves" (scalars)
6
+ */
4
7
  export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
5
8
  private value;
6
9
  static $$export: {
@@ -3,6 +3,9 @@ import * as graphql from "graphql";
3
3
  import type { InputStep, NotVariableValueNode } from "../interfaces.js";
4
4
  import { ExecutableStep } from "../step.js";
5
5
  import type { ConstantStep } from "./constant.js";
6
+ /**
7
+ * Implements `__InputListStep`.
8
+ */
6
9
  export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends ExecutableStep {
7
10
  private readonly inputValues;
8
11
  static $$export: {
@@ -1,6 +1,9 @@
1
1
  import type { GraphQLInputObjectType } from "graphql";
2
2
  import type { ExecutionExtra, InputStep, NotVariableValueNode } from "../interfaces.js";
3
3
  import { UnbatchedExecutableStep } from "../step.js";
4
+ /**
5
+ * Implements `InputObjectStep`
6
+ */
4
7
  export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType = GraphQLInputObjectType> extends UnbatchedExecutableStep {
5
8
  private inputObjectType;
6
9
  private inputValues;
@@ -1,5 +1,10 @@
1
1
  import type { BooleanValueNode, EnumValueNode, FloatValueNode, GraphQLLeafType, IntValueNode, NullValueNode, StringValueNode } from "graphql";
2
2
  import { UnbatchedExecutableStep } from "../step.js";
3
+ /**
4
+ * Implements `InputStaticLeafStep`
5
+ *
6
+ * @see __InputDynamicScalarStep
7
+ */
3
8
  export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
4
9
  static $$export: {
5
10
  moduleName: string;
@@ -1,5 +1,10 @@
1
1
  import type { ExecutableStep } from "../step.js";
2
2
  import { $$deepDepSkip, $$noExec, UnbatchedExecutableStep } from "../step.js";
3
+ /**
4
+ * An __ItemStep is an internal plan (users must never construct it
5
+ * themselves!) that Grafast uses to refer to an individual item within a list
6
+ * or stream.
7
+ */
3
8
  export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
4
9
  readonly depth: number;
5
10
  static $$export: {
@@ -8,6 +13,9 @@ export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
8
13
  };
9
14
  isSyncAndSafe: boolean;
10
15
  [$$noExec]: boolean;
16
+ /**
17
+ * @internal
18
+ */
11
19
  transformStepId?: number;
12
20
  constructor(parentPlan: ExecutableStep<TData> | ExecutableStep<TData[]>, depth?: number);
13
21
  toStringMeta(): string;
@@ -5,28 +5,102 @@ import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../i
5
5
  import { UnbatchedExecutableStep } from "../step.js";
6
6
  import type { __ValueStep } from "./__value.js";
7
7
  import type { AccessStep } from "./access.js";
8
+ /**
9
+ * Implements the `__TrackedValueStep(operationPlan, object, constraints, path)`
10
+ * algorithm used to allow runtime AND plan-time access to the three special
11
+ * entities: `variableValues`, `rootValue` and `context`.
12
+ *
13
+ * ExecutableStep-time access can evaluate the `object` passed to the constructor, and
14
+ * will add constraints to the relevant operationPlan.variableValuesConstraints,
15
+ * operationPlan.rootValueConstraints or operationPlan.contextConstraints to
16
+ * ensure that all future variableValues, rootValues and context will match the
17
+ * assumptions made.
18
+ *
19
+ * Run-time access will see the runtime values of these properties, it will
20
+ * **NOT** reference the `object` passed to the constructor.
21
+ *
22
+ * In core this will be used for evaluating `@skip`, `@include`, `@defer` and
23
+ * `@stream` directives so that a different OpPlan will be used if these would
24
+ * change the query plan, but it can also be used within plan resolvers to
25
+ * branch the logic of a plan based on something in these entities.
26
+ */
8
27
  export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLInputType | ReadonlyArray<VariableDefinitionNode> | undefined = undefined> extends UnbatchedExecutableStep<TData> {
9
28
  static $$export: {
10
29
  moduleName: string;
11
30
  exportName: string;
12
31
  };
13
32
  isSyncAndSafe: boolean;
33
+ /**
34
+ * Could be anything. In the case of context it could even have exotic
35
+ * entries such as `pgClient`.
36
+ */
14
37
  private readonly value;
38
+ /**
39
+ * A reference to the relevant
40
+ * operationPlan.variableValuesConstraints/contextConstraints/rootValueConstraints.
41
+ *
42
+ * @internal
43
+ */
15
44
  private readonly constraints;
45
+ /**
46
+ * The path that we are through the original value (the one that
47
+ * `constraints` relates to).
48
+ */
16
49
  private readonly path;
17
50
  static withGraphQLType<TInputType extends GraphQLInputType, TData = any>(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path: (string | number)[] | undefined, graphqlType: TInputType): __TrackedValueStepWithDollars<TData, TInputType>;
18
51
  private nullableGraphQLType;
19
52
  private variableDefinitions;
53
+ /**
54
+ * @internal
55
+ */
20
56
  constructor(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path?: Array<string | number>, graphqlTypeOrVariableDefinitions?: TInputType);
21
57
  execute(_count: number, values: [GrafastValuesList<TData>]): GrafastResultsList<TData>;
22
58
  unbatchedExecute(_extra: ExecutionExtra, v: TData): TData;
23
59
  private getValuePlan;
60
+ /**
61
+ * Get the named property of an object.
62
+ */
24
63
  get<TAttribute extends keyof TData & string>(attrName: TAttribute): __TrackedValueStepWithDollars<TData[TAttribute], TInputType extends GraphQLInputObjectType ? ReturnType<TInputType["getFields"]>[TAttribute]["type"] : undefined>;
64
+ /**
65
+ * Get the entry at the given index in an array.
66
+ */
25
67
  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>;
68
+ /**
69
+ * Evaluates the current value, and adds a constraint to the OpPlan to ensure
70
+ * that all future evaluations of this property will always return the same
71
+ * value.
72
+ *
73
+ * **WARNING**: avoid using this where possible, it causes OpPlans to split.
74
+ *
75
+ * **WARNING**: this is the most expensive eval, if you need to eval, prefer evalIs, evalHas, etc instead.
76
+ */
26
77
  eval(): TData | undefined;
78
+ /**
79
+ * Evaluates if the current value is equal to this specific value, and adds a
80
+ * constraint to the OpPlan to ensure that all future evaluations of this
81
+ * check will always return the same (boolean) result.
82
+ *
83
+ * Should only be used on scalars.
84
+ *
85
+ * **WARNING**: avoid using this where possible, it causes OpPlans to split.
86
+ */
27
87
  evalIs(expectedValue: unknown): boolean;
28
88
  evalIsEmpty(): boolean;
89
+ /**
90
+ * Evaluates if the current value is an object with the given key, and adds a
91
+ * constraint to the OpPlan to ensure that all future evaluations of this
92
+ * check will always return the same (boolean) result.
93
+ *
94
+ * **WARNING**: avoid using this where possible, it causes OpPlans to split.
95
+ */
29
96
  evalHas(key: string): boolean;
97
+ /**
98
+ * Evaluates the length of the current value (assumed to be an array), and
99
+ * adds a constraint to the OpPlan to ensure that all future values will have
100
+ * the same length.
101
+ *
102
+ * **WARNING**: avoid using this where possible, it causes OpPlans to split.
103
+ */
30
104
  evalLength(): number | null;
31
105
  optimize(): import("../step.js").ExecutableStep<any>;
32
106
  }
@@ -1,5 +1,10 @@
1
1
  import { $$noExec, ExecutableStep } from "../step.js";
2
2
  import type { AccessStep } from "./access.js";
3
+ /**
4
+ * Implements `__ValueStep(operationPlan)` which is never executed; it's purely
5
+ * internal - we populate the value as part of the algorithm - see
6
+ * `GetValueStepId` and `PopulateValueStep`.
7
+ */
3
8
  export declare class __ValueStep<TData> extends ExecutableStep<TData> {
4
9
  static $$export: {
5
10
  moduleName: string;
@@ -1,7 +1,16 @@
1
1
  import type { ExecutionExtra } from "../interfaces.js";
2
2
  import type { ExecutableStep } from "../step.js";
3
3
  import { UnbatchedExecutableStep } from "../step.js";
4
+ /** @internal */
4
5
  export declare const expressionSymbol: unique symbol;
6
+ /**
7
+ * Accesses a (potentially nested) property from the result of a plan.
8
+ *
9
+ * NOTE: this could lead to unexpected results (which could introduce security
10
+ * issues) if it is not used carefully; only use it on JSON-like data,
11
+ * preferably where the objects have null prototypes, and be sure to adhere to
12
+ * the naming conventions detailed in assertSafeToAccessViaBraces.
13
+ */
5
14
  export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
6
15
  readonly fallback?: any;
7
16
  static $$export: {
@@ -13,12 +22,22 @@ export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
13
22
  readonly path: (string | number | symbol)[];
14
23
  constructor(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[], fallback?: any);
15
24
  toStringMeta(): string;
25
+ /**
26
+ * Get the named property of an object.
27
+ */
16
28
  get<TAttr extends keyof TData>(attrName: TAttr): AccessStep<TData[TAttr]>;
29
+ /**
30
+ * Get the entry at the given index in an array.
31
+ */
17
32
  at<TIndex extends keyof TData>(index: TIndex): AccessStep<TData[TIndex]>;
18
33
  optimize(): AccessStep<TData>;
19
34
  finalize(): void;
20
35
  unbatchedExecute(_extra: ExecutionExtra, ..._values: any[]): any;
21
36
  deduplicate(peers: AccessStep<unknown>[]): AccessStep<TData>[];
22
37
  }
38
+ /**
39
+ * Access the property at path `path` in the value returned from `parentPlan`,
40
+ * falling back to `fallback` if it were null-ish.
41
+ */
23
42
  export declare function access<TData>(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[] | string | number | symbol, fallback?: any): AccessStep<TData>;
24
43
  //# sourceMappingURL=access.d.ts.map
@@ -4,16 +4,29 @@ import type { GrafastError } from "../error.js";
4
4
  import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../interfaces.js";
5
5
  import type { ListCapableStep } from "../step.js";
6
6
  import { ExecutableStep } from "../step.js";
7
+ /**
8
+ * @internal
9
+ */
7
10
  export declare class ApplyTransformsStep extends ExecutableStep {
8
11
  static $$export: {
9
12
  moduleName: string;
10
13
  exportName: string;
11
14
  };
12
15
  isSyncAndSafe: boolean;
16
+ /** Set during query planning. */
13
17
  itemStepId: number;
18
+ /**
19
+ * @internal
20
+ */
14
21
  subroutineLayer: LayerPlan<LayerPlanReasonSubroutine>;
15
22
  constructor(listPlan: ListCapableStep<any, any>);
16
23
  execute(_count: number, values: [GrafastValuesList<any[] | null | undefined | GrafastError>], extra: ExecutionExtra): Promise<GrafastResultsList<any[]>>;
17
24
  }
25
+ /**
26
+ * If you want to use a step that might represent a list and you need all of
27
+ * the `listItem` transforms to have already taken place (e.g. you're going to
28
+ * send the result to an external service) rather than processing them through
29
+ * the GraphQL response, then you may need to call `applyTransforms` on it.
30
+ */
18
31
  export declare function applyTransforms($step: ExecutableStep): ExecutableStep<any>;
19
32
  //# sourceMappingURL=applyTransforms.d.ts.map
@@ -2,6 +2,10 @@ import type { ExecutionExtra, GrafastResultsList, InputStep } from "../interface
2
2
  import type { ExecutableStep } from "../step.js";
3
3
  import { UnbatchedExecutableStep } from "../step.js";
4
4
  type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never[];
5
+ /**
6
+ * Describes what a plan needs to implement in order to be suitable for
7
+ * supplying what the `PageInfo` type requires.
8
+ */
5
9
  export interface PageInfoCapableStep extends ExecutableStep {
6
10
  hasNextPage(): ExecutableStep<boolean>;
7
11
  hasPreviousPage(): ExecutableStep<boolean>;
@@ -9,7 +13,16 @@ export interface PageInfoCapableStep extends ExecutableStep {
9
13
  endCursor(): ExecutableStep<string | null>;
10
14
  }
11
15
  export declare function assertPageInfoCapableStep($step: ExecutableStep | PageInfoCapableStep): asserts $step is PageInfoCapableStep;
16
+ /**
17
+ * Describes what a plan needs to implement in order to be suitable for
18
+ * supplying what a ConnectionStep requires.
19
+ */
12
20
  export interface ConnectionCapableStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep> extends ExecutableStep<ReadonlyArray<TItemStep extends ExecutableStep<infer U> ? U : any>> {
21
+ /**
22
+ * Clone the plan; it's recommended that you add `$connection` as a
23
+ * dependency so that you can abort execution early in the case of errors
24
+ * (e.g. if the cursors cannot be parsed).
25
+ */
13
26
  connectionClone($connection: ConnectionStep<TItemStep, TCursorStep, any, any>, ...args: any[]): ConnectionCapableStep<TItemStep, TCursorStep>;
14
27
  pageInfo($connection: ConnectionStep<TItemStep, TCursorStep, ConnectionCapableStep<TItemStep, TCursorStep>, any>): PageInfoCapableStep;
15
28
  setFirst($plan: InputStep): void;
@@ -19,6 +32,10 @@ export interface ConnectionCapableStep<TItemStep extends ExecutableStep, TCursor
19
32
  setBefore($plan: TCursorStep): void;
20
33
  setAfter($plan: TCursorStep): void;
21
34
  }
35
+ /**
36
+ * Handles GraphQL cursor pagination in a standard and consistent way
37
+ * indepdenent of data source.
38
+ */
22
39
  export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TNodeStep extends ExecutableStep = ExecutableStep> extends UnbatchedExecutableStep<unknown> {
23
40
  readonly itemPlan?: (($item: TItemStep) => TNodeStep) | undefined;
24
41
  readonly cursorPlan?: (($item: TItemStep) => ExecutableStep<string | null> | undefined) | undefined;
@@ -45,9 +62,35 @@ export declare class ConnectionStep<TItemStep extends ExecutableStep, TCursorSte
45
62
  setBefore($beforePlan: InputStep): void;
46
63
  getAfter(): TCursorStep | null;
47
64
  setAfter($afterPlan: InputStep): void;
65
+ /**
66
+ * This should not be called after the arguments have been finalized.
67
+ */
48
68
  getSubplan(): TStep;
69
+ /**
70
+ * This represents the entire collection with conditions and ordering
71
+ * applied, but without any pagination constraints (before, after, first,
72
+ * last, offset) applied. It's useful for the following:
73
+ *
74
+ * - performing aggregates e.g. totalCount across the entire collection
75
+ * - determining fields for pageInfo, e.g. is there a next/previous page
76
+ *
77
+ * This cannot be called before the arguments have been finalized.
78
+ */
49
79
  cloneSubplanWithoutPagination(...args: ParametersExceptFirst<TStep["connectionClone"]>): TStep;
80
+ /**
81
+ * This represents a single page from the collection - not only have
82
+ * conditions and ordering been applied but we've also applied the pagination
83
+ * constraints (before, after, first, last, offset). It's useful for
84
+ * returning the actual edges and nodes of the connection.
85
+ *
86
+ * This cannot be called before the arguments have been finalized.
87
+ */
50
88
  cloneSubplanWithPagination(...args: ParametersExceptFirst<TStep["connectionClone"]> | []): TStep;
89
+ /**
90
+ * Subplans may call this from their `setBefore`/`setAfter`/etc plans in order
91
+ * to add a dependency to us, which is typically useful for adding validation
92
+ * functions so that they are thrown "earlier", avoiding error bubbling.
93
+ */
51
94
  addValidation(callback: () => ExecutableStep): void;
52
95
  edges(): ExecutableStep;
53
96
  nodes(): TStep | import("./listTransform.js").__ListTransformStep<any, any, any, any>;
@@ -81,6 +124,10 @@ export declare class EdgeStep<TItemStep extends ExecutableStep, TCursorStep exte
81
124
  deduplicatedWith(replacement: EdgeStep<any, any, any, any>): void;
82
125
  unbatchedExecute(_extra: ExecutionExtra, record: any, cursor: any): any;
83
126
  }
127
+ /**
128
+ * Wraps a collection fetch to provide the utilities for working with GraphQL
129
+ * cursor connections.
130
+ */
84
131
  export declare function connection<TItemStep extends ExecutableStep, TCursorStep extends ExecutableStep, TStep extends ConnectionCapableStep<TItemStep, TCursorStep>, TNodeStep extends ExecutableStep = ExecutableStep>(step: TStep, itemPlan?: ($item: TItemStep) => TNodeStep, cursorPlan?: ($item: TItemStep) => ExecutableStep<string | null>): ConnectionStep<TItemStep, TCursorStep, TStep, TNodeStep>;
85
132
  export {};
86
133
  //# sourceMappingURL=connection.d.ts.map
@@ -1,5 +1,8 @@
1
1
  import type { GrafastResultsList } from "../interfaces.js";
2
2
  import { UnbatchedExecutableStep } from "../step.js";
3
+ /**
4
+ * Converts a constant value (e.g. a string/number/etc) into a plan
5
+ */
3
6
  export declare class ConstantStep<TData> extends UnbatchedExecutableStep<TData> {
4
7
  readonly data: TData;
5
8
  readonly isSensitive: boolean;
@@ -19,6 +22,10 @@ export declare class ConstantStep<TData> extends UnbatchedExecutableStep<TData>
19
22
  isNull(): boolean;
20
23
  isUndefined(): boolean;
21
24
  }
25
+ /**
26
+ * Call this as a template string or as a function. Only intended for handling
27
+ * scalar values, not arrays/objects/etc.
28
+ */
22
29
  export declare function constant<const TString extends string>(strings: TemplateStringsArray & [TString]): ConstantStep<TString>;
23
30
  export declare function constant<TData>(data: TData, isSecret?: boolean): ConstantStep<TData>;
24
31
  //# sourceMappingURL=constant.d.ts.map
@@ -2,5 +2,8 @@ import type { ExecutableStep, ListCapableStep } from "../step.js";
2
2
  import { __ItemStep } from "./__item.js";
3
3
  import type { ConnectionCapableStep } from "./connection.js";
4
4
  import type { __ListTransformStep } from "./listTransform.js";
5
+ /**
6
+ * Transforms a list by wrapping each element in the list with the given mapper.
7
+ */
5
8
  export declare function each<TListStep extends ExecutableStep<readonly any[]> & Partial<ConnectionCapableStep<any, any>>, TResultItemStep extends ExecutableStep>(listStep: TListStep, mapper: (itemPlan: TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>) => TResultItemStep): __ListTransformStep<any, any, any, any>;
6
9
  //# sourceMappingURL=each.d.ts.map
@@ -2,5 +2,9 @@ import type { ExecutableStep, ListCapableStep } from "../step.js";
2
2
  import type { __ItemStep } from "./__item.js";
3
3
  import type { __ListTransformStep, ListTransformItemPlanCallback } from "./listTransform.js";
4
4
  export type FilterPlanMemo = unknown[];
5
+ /**
6
+ * Filters a list plan to only include entries for which the `filterCallback`
7
+ * plan results in a truthy value.
8
+ */
5
9
  export declare function filter<TListStep extends ExecutableStep<readonly any[]>, TItemStep extends ExecutableStep<boolean>>(listStep: TListStep, filterCallback: ListTransformItemPlanCallback<TListStep, TItemStep>): __ListTransformStep<TListStep, TItemStep, FilterPlanMemo, TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>>;
6
10
  //# sourceMappingURL=filter.d.ts.map
@@ -14,5 +14,9 @@ export declare class FirstStep<TData> extends UnbatchedExecutableStep<TData> {
14
14
  deduplicate(peers: FirstStep<TData>[]): FirstStep<TData>[];
15
15
  optimize(): ExecutableStep<any> | this;
16
16
  }
17
+ /**
18
+ * A plan that resolves to the first entry in the list returned by the given
19
+ * plan.
20
+ */
17
21
  export declare function first<TData>(plan: ExecutableStep<ReadonlyArray<TData>>): FirstStep<TData>;
18
22
  //# sourceMappingURL=first.d.ts.map