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
@@ -0,0 +1,65 @@
1
+ import type { DataFromStep, ExecutionDetails, ExecutionEntryFlags, GrafastResultsList } from "../interfaces.js";
2
+ import { $$deepDepSkip } from "../interfaces.js";
3
+ import type { ListCapableStep } from "../step.js";
4
+ import { Step } from "../step.js";
5
+ import type { __ItemStep } from "./__item.js";
6
+ export declare const TRAP_ERROR: ExecutionEntryFlags;
7
+ export declare const TRAP_INHIBITED: ExecutionEntryFlags;
8
+ export declare const TRAP_ERROR_OR_INHIBITED: ExecutionEntryFlags;
9
+ declare const TRAP_VALUES: readonly ["NULL", "EMPTY_LIST", "PASS_THROUGH"];
10
+ /** @defaultValue `'PASS_THROUGH'` */
11
+ export type TrapValue = (typeof TRAP_VALUES)[number];
12
+ /** `false` means pass-through; all others are literal */
13
+ export type ResolvedTrapValue = false | null | undefined | readonly never[];
14
+ export interface FlagStepOptions {
15
+ acceptFlags?: ExecutionEntryFlags;
16
+ onReject?: Error | null;
17
+ if?: Step<boolean>;
18
+ valueForInhibited?: TrapValue;
19
+ valueForError?: TrapValue;
20
+ }
21
+ export declare class __FlagStep<TStep extends Step> extends Step<DataFromStep<TStep>> {
22
+ static $$export: {
23
+ moduleName: string;
24
+ exportName: string;
25
+ };
26
+ isSyncAndSafe: boolean;
27
+ private ifDep;
28
+ private forbiddenFlags;
29
+ private onRejectReturnValue;
30
+ private valueForInhibited;
31
+ private valueForError;
32
+ private canBeInlined;
33
+ constructor(step: TStep, options: FlagStepOptions);
34
+ toStringMeta(): string | null;
35
+ [$$deepDepSkip](): Step;
36
+ listItem?: ($item: __ItemStep<ListCapableStep<unknown, Step<unknown>>>) => Step;
37
+ _listItem($item: __ItemStep<ListCapableStep<unknown, Step<unknown>>>): Step<unknown>;
38
+ deduplicate(_peers: readonly Step<any>[]): readonly Step<any>[];
39
+ execute(_details: ExecutionDetails<[data: DataFromStep<TStep>, cond?: boolean]>): GrafastResultsList<DataFromStep<TStep>>;
40
+ finalize(): void;
41
+ private fancyExecute;
42
+ private passThroughExecute;
43
+ }
44
+ /**
45
+ * Example use case: get user by id, but id is null: no need to fetch the user
46
+ * since we know they won't exist.
47
+ */
48
+ export declare function inhibitOnNull<TStep extends Step>($step: TStep, options?: {
49
+ if?: FlagStepOptions["if"];
50
+ }): __FlagStep<TStep>;
51
+ /**
52
+ * Example use case: expecting a node ID that represents a User, but get one
53
+ * that represents a Post instead: throw error to tell user they've sent invalid
54
+ * data.
55
+ */
56
+ export declare function assertNotNull<TStep extends Step>($step: TStep, message: string, options?: {
57
+ if?: FlagStepOptions["if"];
58
+ }): __FlagStep<TStep>;
59
+ export declare function trap<TStep extends Step>($step: TStep, acceptFlags: ExecutionEntryFlags, options?: {
60
+ valueForInhibited?: FlagStepOptions["valueForInhibited"];
61
+ valueForError?: FlagStepOptions["valueForError"];
62
+ if?: FlagStepOptions["if"];
63
+ }): __FlagStep<TStep>;
64
+ export {};
65
+ //# sourceMappingURL=__flag.d.ts.map
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__FlagStep = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_INHIBITED = exports.TRAP_ERROR = void 0;
4
+ exports.inhibitOnNull = inhibitOnNull;
5
+ exports.assertNotNull = assertNotNull;
6
+ exports.trap = trap;
7
+ const error_js_1 = require("../error.js");
8
+ const inspect_js_1 = require("../inspect.js");
9
+ const interfaces_js_1 = require("../interfaces.js");
10
+ const step_js_1 = require("../step.js");
11
+ // PUBLIC FLAGS
12
+ exports.TRAP_ERROR = interfaces_js_1.FLAG_ERROR;
13
+ exports.TRAP_INHIBITED = interfaces_js_1.FLAG_INHIBITED;
14
+ exports.TRAP_ERROR_OR_INHIBITED = (interfaces_js_1.FLAG_ERROR |
15
+ interfaces_js_1.FLAG_INHIBITED);
16
+ function digestAcceptFlags(acceptFlags) {
17
+ const parts = [];
18
+ if ((acceptFlags & interfaces_js_1.FLAG_NULL) === 0) {
19
+ parts.push("rejectNull");
20
+ }
21
+ if ((acceptFlags & interfaces_js_1.FLAG_ERROR) !== 0) {
22
+ parts.push("trapError");
23
+ }
24
+ if ((acceptFlags & interfaces_js_1.FLAG_INHIBITED) !== 0) {
25
+ parts.push("trapInhibited");
26
+ }
27
+ return parts.join("&");
28
+ }
29
+ const TRAP_VALUES = [
30
+ "NULL",
31
+ "EMPTY_LIST",
32
+ "PASS_THROUGH",
33
+ // "UNDEFINED", // waiting for a need
34
+ ];
35
+ const EMPTY_LIST = Object.freeze([]);
36
+ function trim(string, length = 15) {
37
+ if (string.length > length) {
38
+ return string.substring(0, length - 2) + "…";
39
+ }
40
+ else {
41
+ return string;
42
+ }
43
+ }
44
+ function resolveTrapValue(tv) {
45
+ switch (tv) {
46
+ case "NULL":
47
+ return null;
48
+ case "EMPTY_LIST":
49
+ return EMPTY_LIST;
50
+ case "PASS_THROUGH":
51
+ return false;
52
+ default: {
53
+ const never = tv;
54
+ throw new Error(`TrapValue '${never}' not understood; please use one of: ${TRAP_VALUES.join(", ")}`);
55
+ }
56
+ }
57
+ }
58
+ class __FlagStep extends step_js_1.Step {
59
+ static { this.$$export = {
60
+ moduleName: "grafast",
61
+ exportName: "__FlagStep",
62
+ }; }
63
+ constructor(step, options) {
64
+ super();
65
+ this.isSyncAndSafe = false;
66
+ this.ifDep = null;
67
+ const { acceptFlags = interfaces_js_1.DEFAULT_ACCEPT_FLAGS, onReject, if: $cond, valueForInhibited = "PASS_THROUGH", valueForError = "PASS_THROUGH", } = options;
68
+ this.forbiddenFlags = interfaces_js_1.ALL_FLAGS & ~acceptFlags;
69
+ this.onRejectReturnValue =
70
+ onReject == null ? error_js_1.$$inhibit : (0, error_js_1.flagError)(onReject, step.id);
71
+ this.valueForInhibited = resolveTrapValue(valueForInhibited);
72
+ this.valueForError = resolveTrapValue(valueForError);
73
+ this.canBeInlined =
74
+ !$cond &&
75
+ valueForInhibited === "PASS_THROUGH" &&
76
+ valueForError === "PASS_THROUGH" &&
77
+ // Can't PASS_THROUGH errors since they need to be converted into TRAPPED
78
+ // error.
79
+ // TODO: should we be handling this in Grafast core?
80
+ (acceptFlags & interfaces_js_1.FLAG_ERROR) === 0;
81
+ if (!this.canBeInlined) {
82
+ this.addDependency({ step, acceptFlags: interfaces_js_1.TRAPPABLE_FLAGS });
83
+ if ($cond) {
84
+ this.ifDep = this.addDependency($cond);
85
+ }
86
+ }
87
+ else {
88
+ this.addDependency({ step, acceptFlags, onReject });
89
+ }
90
+ if ((0, step_js_1.isListCapableStep)(step)) {
91
+ this.listItem = this._listItem;
92
+ }
93
+ }
94
+ toStringMeta() {
95
+ const acceptFlags = interfaces_js_1.ALL_FLAGS & ~this.forbiddenFlags;
96
+ const rej = this.onRejectReturnValue
97
+ ? trim(String(this.onRejectReturnValue))
98
+ : (0, inspect_js_1.inspect)(this.onRejectReturnValue);
99
+ const $if = this.ifDep !== null ? this.getDepOptions(this.ifDep).step : null;
100
+ return `${this.dependencies[0].id}, ${$if ? `if(${$if.id}), ` : ``}${digestAcceptFlags(acceptFlags)}, onReject: ${rej}`;
101
+ }
102
+ [interfaces_js_1.$$deepDepSkip]() {
103
+ return this.getDepOptions(0).step;
104
+ }
105
+ // Copied over listItem if the dependent step is a list capable step
106
+ _listItem($item) {
107
+ const $dep = this.dependencies[0];
108
+ return (0, step_js_1.isListCapableStep)($dep) ? $dep.listItem($item) : $item;
109
+ }
110
+ /** Return inlining instructions if we can be inlined. @internal */
111
+ inline(options) {
112
+ if (!this.canBeInlined) {
113
+ return null;
114
+ }
115
+ const step = this.dependencies[0];
116
+ const forbiddenFlags = this.dependencyForbiddenFlags[0];
117
+ const onReject = this.dependencyOnReject[0];
118
+ const acceptFlags = interfaces_js_1.ALL_FLAGS & ~forbiddenFlags;
119
+ if (
120
+ // TODO: this logic could be improved so that more flag checks were
121
+ // inlined, e.g. `trap(inhibitOnNull($foo), TRAP_INHIBIT)` should just
122
+ // become `$foo`.
123
+ //
124
+ // However, we must be careful that we don't optimize away flags, e.g.
125
+ // `trap(inhibitOnNull($foo), TRAP_INHIBIT, { if: $cond })` needs to see
126
+ // the inhibit flag to know what to do, so in this case we shouldn't be
127
+ // inlined. This may only apply to __FlagStep and might be something we
128
+ // want to optimize later.
129
+ options.onReject === undefined ||
130
+ options.onReject === onReject) {
131
+ if (options.acceptFlags === undefined ||
132
+ options.acceptFlags === interfaces_js_1.DEFAULT_ACCEPT_FLAGS ||
133
+ options.acceptFlags === acceptFlags ||
134
+ false) {
135
+ return { step, acceptFlags, onReject };
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+ deduplicate(_peers) {
141
+ return _peers.filter((p) => {
142
+ // ifDep has already been tested by Grafast (it's a dependency)
143
+ if (p.forbiddenFlags !== this.forbiddenFlags)
144
+ return false;
145
+ if (p.onRejectReturnValue !== this.onRejectReturnValue)
146
+ return false;
147
+ if (p.valueForInhibited !== this.valueForInhibited)
148
+ return false;
149
+ if (p.valueForError !== this.valueForError)
150
+ return false;
151
+ if (p.canBeInlined !== this.canBeInlined)
152
+ return false;
153
+ return true;
154
+ });
155
+ }
156
+ execute(_details) {
157
+ throw new Error(`${this} not finalized?`);
158
+ }
159
+ finalize() {
160
+ if (this.canBeInlined) {
161
+ this.execute = this.passThroughExecute;
162
+ }
163
+ else {
164
+ this.execute = this.fancyExecute;
165
+ }
166
+ super.finalize();
167
+ }
168
+ fancyExecute(details) {
169
+ const dataEv = details.values[0];
170
+ const condEv = this.ifDep === null ? null : details.values[this.ifDep];
171
+ const { forbiddenFlags: thisForbiddenFlags, onRejectReturnValue, valueForError, valueForInhibited, } = this;
172
+ return details.indexMap((i) => {
173
+ const cond = condEv ? condEv.at(i) : true;
174
+ const forbiddenFlags = cond
175
+ ? thisForbiddenFlags
176
+ : interfaces_js_1.DEFAULT_FORBIDDEN_FLAGS;
177
+ // Search for "f2b3b1b3" for similar block
178
+ const flags = dataEv._flagsAt(i);
179
+ const disallowedFlags = flags & forbiddenFlags;
180
+ if (disallowedFlags) {
181
+ if (disallowedFlags & interfaces_js_1.FLAG_INHIBITED) {
182
+ // We were already rejected, maintain this
183
+ return error_js_1.$$inhibit;
184
+ }
185
+ else if (disallowedFlags & interfaces_js_1.FLAG_ERROR) {
186
+ // We were already rejected, maintain this
187
+ return (0, error_js_1.flagError)(dataEv.at(i));
188
+ }
189
+ else {
190
+ // We weren't already inhibited
191
+ return onRejectReturnValue;
192
+ }
193
+ }
194
+ else {
195
+ if (flags & interfaces_js_1.FLAG_ERROR && this.valueForError !== false) {
196
+ return valueForError;
197
+ }
198
+ if (flags & interfaces_js_1.FLAG_INHIBITED && this.valueForInhibited !== false) {
199
+ return valueForInhibited;
200
+ }
201
+ // Assume pass-through
202
+ return dataEv.at(i);
203
+ }
204
+ });
205
+ }
206
+ // Checks already performed via addDependency, just pass everything through. Should have been inlined!
207
+ passThroughExecute(details) {
208
+ const ev = details.values[0];
209
+ if (ev.isBatch) {
210
+ return ev.entries;
211
+ }
212
+ else {
213
+ const val = ev.value;
214
+ return details.indexMap(() => val);
215
+ }
216
+ }
217
+ }
218
+ exports.__FlagStep = __FlagStep;
219
+ /**
220
+ * Example use case: get user by id, but id is null: no need to fetch the user
221
+ * since we know they won't exist.
222
+ */
223
+ function inhibitOnNull($step, options) {
224
+ return new __FlagStep($step, {
225
+ ...options,
226
+ acceptFlags: interfaces_js_1.DEFAULT_ACCEPT_FLAGS & ~interfaces_js_1.FLAG_NULL,
227
+ });
228
+ }
229
+ /**
230
+ * Example use case: expecting a node ID that represents a User, but get one
231
+ * that represents a Post instead: throw error to tell user they've sent invalid
232
+ * data.
233
+ */
234
+ function assertNotNull($step, message, options) {
235
+ return new __FlagStep($step, {
236
+ ...options,
237
+ acceptFlags: interfaces_js_1.DEFAULT_ACCEPT_FLAGS & ~interfaces_js_1.FLAG_NULL,
238
+ onReject: new error_js_1.SafeError(message),
239
+ });
240
+ }
241
+ function trap($step, acceptFlags, options) {
242
+ return new __FlagStep($step, {
243
+ ...options,
244
+ acceptFlags: (acceptFlags & interfaces_js_1.TRAPPABLE_FLAGS) | interfaces_js_1.FLAG_NULL,
245
+ });
246
+ }
247
+ // Have to overwrite the getDep method due to circular dependency
248
+ step_js_1.Step.prototype.getDep = function (depId, throwOnFlagged = false) {
249
+ const { step, acceptFlags, onReject } = this.getDepOptions(depId);
250
+ if (acceptFlags === interfaces_js_1.DEFAULT_ACCEPT_FLAGS && onReject == null) {
251
+ return step;
252
+ }
253
+ else {
254
+ if (throwOnFlagged) {
255
+ throw new Error(`When retrieving dependency ${step} of ${this}, the dependency is flagged as ${digestAcceptFlags(acceptFlags)}/onReject=${String(onReject)}. Please use \`this.getDepOptions(depId)\` instead, and handle the flags`);
256
+ }
257
+ // Return a __FlagStep around options.step so that all the options are preserved.
258
+ return new __FlagStep(step, { acceptFlags, onReject });
259
+ }
260
+ };
261
+ //# sourceMappingURL=__flag.js.map
@@ -0,0 +1,14 @@
1
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import { UnbatchedStep } from "../step.js";
3
+ import type { __TrackedValueStep } from "./__trackedValue.js";
4
+ export declare class __InputDefaultStep extends UnbatchedStep {
5
+ private defaultValue;
6
+ static $$export: {
7
+ moduleName: string;
8
+ exportName: string;
9
+ };
10
+ isSyncAndSafe: boolean;
11
+ constructor($variableValue: __TrackedValueStep, defaultValue: unknown);
12
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, variableValue: unknown): unknown;
13
+ }
14
+ //# sourceMappingURL=__inputDefault.d.ts.map
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__InputDefaultStep = void 0;
4
+ const step_js_1 = require("../step.js");
5
+ class __InputDefaultStep extends step_js_1.UnbatchedStep {
6
+ static { this.$$export = {
7
+ moduleName: "grafast",
8
+ exportName: "__InputDefaultStep",
9
+ }; }
10
+ constructor($variableValue, defaultValue) {
11
+ super();
12
+ this.defaultValue = defaultValue;
13
+ this.isSyncAndSafe = true;
14
+ this.addUnaryDependency($variableValue);
15
+ }
16
+ unbatchedExecute(_extra, variableValue) {
17
+ return variableValue === undefined ? this.defaultValue : variableValue;
18
+ }
19
+ /** @internal */
20
+ eval() {
21
+ const $variable = this.getDep(0);
22
+ const variableValue = $variable.eval();
23
+ return variableValue === undefined ? this.defaultValue : variableValue;
24
+ }
25
+ /** @internal */
26
+ evalIs(value) {
27
+ if (value === undefined) {
28
+ return false;
29
+ }
30
+ else {
31
+ const $variable = this.getDep(0);
32
+ return $variable.evalIs(undefined)
33
+ ? this.defaultValue === value
34
+ : $variable.evalIs(value);
35
+ }
36
+ }
37
+ /** @internal */
38
+ evalLength() {
39
+ const $variable = this.getDep(0);
40
+ return $variable.evalIs(undefined)
41
+ ? Array.isArray(this.defaultValue)
42
+ ? this.defaultValue.length
43
+ : null
44
+ : $variable.evalLength();
45
+ }
46
+ }
47
+ exports.__InputDefaultStep = __InputDefaultStep;
48
+ //# sourceMappingURL=__inputDefault.js.map
@@ -1,10 +1,10 @@
1
1
  import type { GraphQLScalarType, ListValueNode, ObjectValueNode } from "graphql";
2
- import type { ExecutionExtra } from "../interfaces.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
2
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
3
+ import { UnbatchedStep } from "../step.js";
4
4
  /**
5
5
  * Handles "leaves" (scalars)
6
6
  */
7
- export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
7
+ export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedStep<TLeaf> {
8
8
  private value;
9
9
  static $$export: {
10
10
  moduleName: string;
@@ -14,8 +14,6 @@ export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedExec
14
14
  private variableNames;
15
15
  constructor(inputType: GraphQLScalarType, value: ListValueNode | ObjectValueNode);
16
16
  valueFromValues(variableValues: any[]): any;
17
- unbatchedExecute: (_extra: ExecutionExtra, ...variableValues: any[]) => TLeaf;
18
- eval(): TLeaf;
19
- evalIs(expectedValue: undefined | null | 0): boolean;
17
+ unbatchedExecute: (_extra: UnbatchedExecutionExtra, ...variableValues: any[]) => TLeaf;
20
18
  }
21
19
  //# sourceMappingURL=__inputDynamicScalar.d.ts.map
@@ -9,7 +9,7 @@ const { Kind } = graphql;
9
9
  /**
10
10
  * Handles "leaves" (scalars)
11
11
  */
12
- class __InputDynamicScalarStep extends step_js_1.UnbatchedExecutableStep {
12
+ class __InputDynamicScalarStep extends step_js_1.UnbatchedStep {
13
13
  static { this.$$export = {
14
14
  moduleName: "grafast",
15
15
  exportName: "__InputDynamicScalarStep",
@@ -106,10 +106,12 @@ class __InputDynamicScalarStep extends step_js_1.UnbatchedExecutableStep {
106
106
  };
107
107
  return convert(this.value);
108
108
  }
109
+ /** @internal */
109
110
  eval() {
110
- const variableValues = this.variableNames.map((variableName, i) => this.getDep(i).eval());
111
+ const variableValues = this.variableNames.map((variableName, i) => this.getDep(i, true).eval());
111
112
  return this.valueFromValues(variableValues);
112
113
  }
114
+ /** @internal */
113
115
  evalIs(expectedValue) {
114
116
  if (expectedValue === undefined ||
115
117
  expectedValue === null ||
@@ -1,12 +1,11 @@
1
1
  import type { GraphQLInputType } from "graphql";
2
2
  import * as graphql from "graphql";
3
- import type { InputStep, NotVariableValueNode } from "../interfaces.js";
4
- import { ExecutableStep } from "../step.js";
5
- import type { ConstantStep } from "./constant.js";
3
+ import type { AnyInputStep, NotVariableValueNode } from "../interfaces.js";
4
+ import { Step } from "../step.js";
6
5
  /**
7
6
  * Implements `__InputListStep`.
8
7
  */
9
- export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends ExecutableStep {
8
+ export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends Step {
10
9
  private readonly inputValues;
11
10
  static $$export: {
12
11
  moduleName: string;
@@ -15,12 +14,9 @@ export declare class __InputListStep<TInputType extends graphql.GraphQLList<Grap
15
14
  isSyncAndSafe: boolean;
16
15
  private itemCount;
17
16
  constructor(inputType: TInputType, inputValues: NotVariableValueNode | undefined);
18
- optimize(): ExecutableStep;
17
+ optimize(): Step;
19
18
  execute(): any[];
20
19
  unbatchedExecute: () => any;
21
- at(index: number): InputStep | ConstantStep<undefined>;
22
- eval(): any[] | null;
23
- evalIs(value: null | undefined | 0): boolean;
24
- evalLength(): number | null;
20
+ at(index: number): AnyInputStep;
25
21
  }
26
22
  //# sourceMappingURL=__inputList.d.ts.map
@@ -12,7 +12,7 @@ const { GraphQLList, Kind } = graphql;
12
12
  /**
13
13
  * Implements `__InputListStep`.
14
14
  */
15
- class __InputListStep extends step_js_1.ExecutableStep {
15
+ class __InputListStep extends step_js_1.Step {
16
16
  static { this.$$export = {
17
17
  moduleName: "grafast",
18
18
  exportName: "__InputListStep",
@@ -66,6 +66,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
66
66
  (0, input_js_1.assertInputStep)(itemPlan);
67
67
  return itemPlan;
68
68
  }
69
+ /** @internal */
69
70
  eval() {
70
71
  if (this.inputValues?.kind === "NullValue") {
71
72
  return null;
@@ -79,6 +80,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
79
80
  }
80
81
  return list;
81
82
  }
83
+ /** @internal */
82
84
  evalIs(value) {
83
85
  if (value === undefined) {
84
86
  return this.inputValues === value;
@@ -90,6 +92,7 @@ class __InputListStep extends step_js_1.ExecutableStep {
90
92
  throw new Error("__InputListStep cannot evalIs values other than null and undefined currently");
91
93
  }
92
94
  }
95
+ /** @internal */
93
96
  evalLength() {
94
97
  if (this.inputValues === undefined) {
95
98
  return null;
@@ -1,10 +1,10 @@
1
1
  import type { GraphQLInputObjectType } from "graphql";
2
- import type { ExecutionExtra, InputStep, NotVariableValueNode } from "../interfaces.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
2
+ import type { AnyInputStep, NotVariableValueNode, UnbatchedExecutionExtra } from "../interfaces.js";
3
+ import { UnbatchedStep } from "../step.js";
4
4
  /**
5
5
  * Implements `InputObjectStep`
6
6
  */
7
- export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType = GraphQLInputObjectType> extends UnbatchedExecutableStep {
7
+ export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType = GraphQLInputObjectType> extends UnbatchedStep {
8
8
  private inputObjectType;
9
9
  private inputValues;
10
10
  static $$export: {
@@ -14,16 +14,12 @@ export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType
14
14
  isSyncAndSafe: boolean;
15
15
  private inputFields;
16
16
  constructor(inputObjectType: TInputType, inputValues: NotVariableValueNode | undefined);
17
- optimize(): this | import("./constant.js").ConstantStep<null>;
17
+ optimize(): import("./constant.js").ConstantStep<null> | this;
18
18
  finalize(): void;
19
- unbatchedExecute(_extra: ExecutionExtra, ...values: any[]): any;
20
- get(attrName: string): InputStep;
21
- eval(): any;
22
- evalIs(value: null | undefined | 0): boolean;
23
- evalIsEmpty(): boolean;
24
- evalHas(attrName: string): boolean;
19
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, ...values: any[]): any;
20
+ get(attrName: string): AnyInputStep;
25
21
  }
26
22
  export type __InputObjectStepWithDollars<TInputType extends GraphQLInputObjectType = GraphQLInputObjectType> = __InputObjectStep<TInputType> & {
27
- [key in keyof ReturnType<TInputType["getFields"]> & string as `$${key}`]: InputStep<ReturnType<TInputType["getFields"]>[key]["type"]>;
23
+ [key in keyof ReturnType<TInputType["getFields"]> & string as `$${key}`]: AnyInputStep;
28
24
  };
29
25
  //# sourceMappingURL=__inputObject.d.ts.map
@@ -2,15 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.__InputObjectStep = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const graphql = tslib_1.__importStar(require("graphql"));
5
6
  const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
6
7
  const input_js_1 = require("../input.js");
7
8
  const step_js_1 = require("../step.js");
8
9
  const utils_js_1 = require("../utils.js");
9
10
  const constant_js_1 = require("./constant.js");
11
+ const { Kind } = graphql;
10
12
  /**
11
13
  * Implements `InputObjectStep`
12
14
  */
13
- class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
15
+ class __InputObjectStep extends step_js_1.UnbatchedStep {
14
16
  static { this.$$export = {
15
17
  moduleName: "grafast",
16
18
  exportName: "__InputObjectStep",
@@ -53,8 +55,11 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
53
55
  if (dependencyIndex == null) {
54
56
  throw new Error("inputFieldPlan has gone missing.");
55
57
  }
58
+ const teVal = tamedevil_1.default.identifier(`val${dependencyIndex}`);
56
59
  return (0, tamedevil_1.default) `\
57
- resultValues${tamedevil_1.default.set(inputFieldName, true)} = ${tamedevil_1.default.identifier(`val${dependencyIndex}`)};`;
60
+ if (${teVal} !== undefined) {
61
+ resultValues${tamedevil_1.default.set(inputFieldName, true)} = ${teVal};
62
+ }`;
58
63
  }), "\n")}
59
64
  return resultValues;
60
65
  })`, (fn) => {
@@ -70,7 +75,9 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
70
75
  throw new Error("inputFieldPlan has gone missing.");
71
76
  }
72
77
  const value = values[dependencyIndex];
73
- resultValues[inputFieldName] = value;
78
+ if (value !== undefined) {
79
+ resultValues[inputFieldName] = value;
80
+ }
74
81
  }
75
82
  return resultValues;
76
83
  }
@@ -81,6 +88,7 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
81
88
  }
82
89
  return step;
83
90
  }
91
+ /** @internal */
84
92
  eval() {
85
93
  if (this.inputValues?.kind === "NullValue") {
86
94
  return null;
@@ -92,6 +100,7 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
92
100
  }
93
101
  return resultValues;
94
102
  }
103
+ /** @internal */
95
104
  evalIs(value) {
96
105
  if (value === undefined) {
97
106
  return this.inputValues === value;
@@ -106,11 +115,13 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
106
115
  throw new Error("__InputObjectStep cannot evalIs values other than null and undefined currently");
107
116
  }
108
117
  }
118
+ /** @internal */
109
119
  evalIsEmpty() {
110
120
  return (this.inputValues?.kind === "ObjectValue" &&
111
121
  this.inputValues.fields.length === 0);
112
122
  }
113
123
  // Written without consulting spec.
124
+ /** @internal */
114
125
  evalHas(attrName) {
115
126
  if (!this.inputValues) {
116
127
  return false;
@@ -123,6 +134,41 @@ class __InputObjectStep extends step_js_1.UnbatchedExecutableStep {
123
134
  }
124
135
  return !this.inputFields[attrName].step.evalIs(undefined);
125
136
  }
137
+ /** @internal */
138
+ evalKeys() {
139
+ if (this.inputValues === undefined) {
140
+ return null;
141
+ }
142
+ else if (this.inputValues.kind === Kind.NULL) {
143
+ return null;
144
+ }
145
+ else if (this.inputValues.kind !== Kind.OBJECT) {
146
+ throw new Error("evalKeys must only be called for object types");
147
+ }
148
+ const keys = [];
149
+ const inputFieldKeys = Object.keys(this.inputFields);
150
+ for (let i = 0; i < inputFieldKeys.length; i++) {
151
+ const key = inputFieldKeys[i];
152
+ const inputFieldPlan = this.inputFields[key].step;
153
+ // This evalIs() is required. With __inputObject we know that it's an
154
+ // explicit input object (not variable) in the GraphQL document, but the
155
+ // values of each key may still be undefined if they're a variable that
156
+ // isn't supplied and has no default. In these cases we do not wish to
157
+ // return these keys (since the input object is not seen as having those
158
+ // keys set), but that will differ on an operation-to-operation basis,
159
+ // and thus we must evaluate whether or not they are undefined. Note that
160
+ // this implicitly adds constraints for these values; we do not need to
161
+ // explicitly add any constraint for the object itself because the
162
+ // document itself guarantees it will always be present.
163
+ //
164
+ // PERF: We should not need to .evalIs(undefined) for any input field
165
+ // that is declared as non-nullable, I think?
166
+ if (!inputFieldPlan.evalIs(undefined)) {
167
+ keys.push(key);
168
+ }
169
+ }
170
+ return keys;
171
+ }
126
172
  }
127
173
  exports.__InputObjectStep = __InputObjectStep;
128
174
  //# sourceMappingURL=__inputObject.js.map
@@ -1,11 +1,11 @@
1
1
  import type { BooleanValueNode, EnumValueNode, FloatValueNode, GraphQLLeafType, IntValueNode, NullValueNode, StringValueNode } from "graphql";
2
- import { UnbatchedExecutableStep } from "../step.js";
2
+ import { UnbatchedStep } from "../step.js";
3
3
  /**
4
4
  * Implements `InputStaticLeafStep`
5
5
  *
6
6
  * @see __InputDynamicScalarStep
7
7
  */
8
- export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
8
+ export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedStep<TLeaf> {
9
9
  static $$export: {
10
10
  moduleName: string;
11
11
  exportName: string;
@@ -15,7 +15,5 @@ export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedExecuta
15
15
  constructor(inputType: GraphQLLeafType, value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | undefined);
16
16
  unbatchedExecute(): TLeaf;
17
17
  optimize(): import("./constant.js").ConstantStep<any>;
18
- eval(): TLeaf;
19
- evalIs(expectedValue: unknown): boolean;
20
18
  }
21
19
  //# sourceMappingURL=__inputStaticLeaf.d.ts.map