grafast 0.1.1-beta.0 → 0.1.1-beta.2

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 (81) hide show
  1. package/README.md +1 -2
  2. package/dist/args.js +62 -0
  3. package/dist/assert.js +24 -0
  4. package/dist/bucket.js +4 -0
  5. package/dist/config.js +99 -0
  6. package/dist/constraints.js +72 -0
  7. package/dist/deferred.js +25 -0
  8. package/dist/dev.js +10 -0
  9. package/dist/engine/LayerPlan.js +536 -0
  10. package/dist/engine/OperationPlan.js +2543 -0
  11. package/dist/engine/OutputPlan.js +1059 -0
  12. package/dist/engine/StepTracker.js +524 -0
  13. package/dist/engine/executeBucket.js +700 -0
  14. package/dist/engine/executeOutputPlan.js +21 -0
  15. package/dist/engine/lib/withGlobalLayerPlan.js +36 -0
  16. package/dist/envelop.js +73 -5
  17. package/dist/error.js +62 -0
  18. package/dist/establishOperationPlan.js +186 -0
  19. package/dist/execute.js +80 -0
  20. package/dist/exportAs.js +57 -0
  21. package/dist/global.js +13 -0
  22. package/dist/grafastGraphql.js +133 -0
  23. package/dist/grafastPrint.js +177 -0
  24. package/dist/graphqlCollectFields.js +217 -0
  25. package/dist/graphqlMergeSelectionSets.js +60 -0
  26. package/dist/index.d.ts +161 -2
  27. package/dist/index.js +255 -499
  28. package/dist/input.js +159 -0
  29. package/dist/inspect.js +20 -0
  30. package/dist/interfaces.d.ts +3 -160
  31. package/dist/interfaces.js +63 -0
  32. package/dist/makeGrafastSchema.js +174 -0
  33. package/dist/mermaid.js +290 -7
  34. package/dist/operationPlan-input.js +449 -0
  35. package/dist/planJSONInterfaces.js +3 -0
  36. package/dist/polymorphic.js +73 -0
  37. package/dist/prepare.js +763 -0
  38. package/dist/step.js +396 -0
  39. package/dist/steps/__inputDynamicScalar.js +125 -0
  40. package/dist/steps/__inputList.js +110 -0
  41. package/dist/steps/__inputObject.js +128 -0
  42. package/dist/steps/__inputStaticLeaf.js +43 -0
  43. package/dist/steps/__item.js +50 -0
  44. package/dist/steps/__trackedValue.js +257 -0
  45. package/dist/steps/__value.js +47 -0
  46. package/dist/steps/access.js +183 -0
  47. package/dist/steps/applyTransforms.js +151 -0
  48. package/dist/steps/connection.js +315 -0
  49. package/dist/steps/constant.js +72 -0
  50. package/dist/steps/each.js +64 -0
  51. package/dist/steps/error.js +32 -0
  52. package/dist/steps/filter.js +32 -0
  53. package/dist/steps/first.js +49 -0
  54. package/dist/steps/graphqlResolver.js +260 -0
  55. package/dist/steps/groupBy.js +40 -0
  56. package/dist/steps/index.js +117 -0
  57. package/dist/steps/lambda.js +58 -0
  58. package/dist/steps/last.js +41 -0
  59. package/dist/steps/list.js +75 -0
  60. package/dist/steps/listTransform.js +185 -0
  61. package/dist/steps/listen.js +61 -0
  62. package/dist/steps/load.d.ts +4 -4
  63. package/dist/steps/load.js +310 -0
  64. package/dist/steps/node.d.ts +6 -6
  65. package/dist/steps/node.js +107 -0
  66. package/dist/steps/object.js +195 -0
  67. package/dist/steps/partitionByIndex.js +86 -0
  68. package/dist/steps/proxy.js +114 -0
  69. package/dist/steps/remapKeys.js +84 -0
  70. package/dist/steps/reverse.js +52 -0
  71. package/dist/steps/setter.js +28 -0
  72. package/dist/stringifyPayload.js +59 -0
  73. package/dist/stripAnsi.js +14 -0
  74. package/dist/subscribe.js +14 -0
  75. package/dist/thereCanBeOnlyOne.js +21 -0
  76. package/dist/timeSource.js +8 -0
  77. package/dist/utils.js +698 -0
  78. package/dist/version.d.ts +1 -1
  79. package/dist/version.js +6 -0
  80. package/package.json +9 -4
  81. package/dist/LICENSES.txt +0 -300
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ansiPad = exports.grafastPrint = exports.grafastColor = exports._grafastPrint = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const inspect_js_1 = require("./inspect.js");
7
+ const step_js_1 = require("./step.js");
8
+ const stripAnsi_js_1 = require("./stripAnsi.js");
9
+ const utils_js_1 = require("./utils.js");
10
+ /*
11
+ * This file contains utilities used with the `debug` module primarily (but
12
+ * also used elsewhere) that are useful for outputting Grafast stuff in a
13
+ * more helpful way - typically with more relevant detail and colours to help
14
+ * you (me) digest things.
15
+ */
16
+ const COLORS = [
17
+ //chalk.black,
18
+ chalk_1.default.yellow,
19
+ chalk_1.default.magenta,
20
+ //chalk.cyan,
21
+ chalk_1.default.red,
22
+ //chalk.white,
23
+ //chalk.blackBright,
24
+ chalk_1.default.greenBright,
25
+ chalk_1.default.yellowBright,
26
+ chalk_1.default.blueBright,
27
+ chalk_1.default.magentaBright,
28
+ chalk_1.default.cyanBright,
29
+ chalk_1.default.redBright,
30
+ chalk_1.default.blue,
31
+ chalk_1.default.green,
32
+ //chalk.whiteBright,
33
+ ];
34
+ const BG_COLORS = [
35
+ // chalk.bgRgb(53, 0, 0),
36
+ // chalk.bgRgb(0, 53, 0),
37
+ // chalk.bgRgb(0, 0, 53),
38
+ chalk_1.default.visible,
39
+ chalk_1.default.underline,
40
+ ];
41
+ function _grafastPrint(symbol, seen) {
42
+ if ((0, utils_js_1.isDeferred)(symbol)) {
43
+ return chalk_1.default.gray `<Deferred>`;
44
+ }
45
+ if ((0, utils_js_1.isPromise)(symbol)) {
46
+ return chalk_1.default.gray `<Promise>`;
47
+ }
48
+ if (symbol === utils_js_1.ROOT_VALUE_OBJECT) {
49
+ return chalk_1.default.gray `(blank)`;
50
+ }
51
+ if (symbol instanceof step_js_1.ExecutableStep) {
52
+ return String(symbol);
53
+ }
54
+ if (Array.isArray(symbol)) {
55
+ if (seen.has(symbol)) {
56
+ return chalk_1.default.gray `(loop)`;
57
+ }
58
+ seen.add(symbol);
59
+ return `[${symbol
60
+ .map((value, i) => BG_COLORS[i % BG_COLORS.length](_grafastPrint(value, new Set(seen))))
61
+ .join(", ")}]`;
62
+ }
63
+ if (symbol instanceof Map) {
64
+ if (seen.has(symbol)) {
65
+ return chalk_1.default.gray `(loop)`;
66
+ }
67
+ seen.add(symbol);
68
+ const pairs = [];
69
+ let i = 0;
70
+ for (const [key, value] of symbol.entries()) {
71
+ pairs.push(BG_COLORS[i % BG_COLORS.length](`${_grafastPrint(key, new Set(seen))}: ${_grafastPrint(value, new Set(seen))}`));
72
+ i++;
73
+ }
74
+ return `Map{${pairs.join(", ")}}`;
75
+ }
76
+ if (typeof symbol === "object" && symbol) {
77
+ if (symbol instanceof Error) {
78
+ return chalk_1.default.red(`ERROR<${(0, stripAnsi_js_1.stripAnsi)(String(symbol.message))
79
+ .replace(/\s+/g, " ")
80
+ .substring(0, 30) + "..."}>`);
81
+ }
82
+ if (![null, Object.prototype, utils_js_1.sharedNull].includes(Object.getPrototypeOf(symbol))) {
83
+ return chalk_1.default.red(`OBJECT<${(0, stripAnsi_js_1.stripAnsi)(String(symbol))}>`);
84
+ }
85
+ if (seen.has(symbol)) {
86
+ return chalk_1.default.gray `(loop)`;
87
+ }
88
+ seen.add(symbol);
89
+ return `{${[...Object.keys(symbol), ...Object.getOwnPropertySymbols(symbol)]
90
+ .map((key, i) => BG_COLORS[i % BG_COLORS.length](`${_grafastPrint(key, new Set(seen))}: ${_grafastPrint(symbol[key], new Set(seen))}`))
91
+ .join(", ")}}`;
92
+ }
93
+ if (typeof symbol !== "symbol") {
94
+ return (0, inspect_js_1.inspect)(symbol, { colors: true });
95
+ }
96
+ return grafastPrintSymbol(symbol);
97
+ }
98
+ exports._grafastPrint = _grafastPrint;
99
+ function _grafastSymbolDescription(symbol) {
100
+ if (!symbol.description) {
101
+ return chalk_1.default.green("Symbol()");
102
+ }
103
+ const nStr = symbol.description?.replace(/[^0-9]/g, "") || "";
104
+ const n = parseInt(nStr, 10) || 0;
105
+ if (n > 0) {
106
+ return grafastColor(symbol.description, n);
107
+ }
108
+ else {
109
+ return chalk_1.default.cyan(`$$${symbol.description}`);
110
+ }
111
+ }
112
+ function grafastColor(text, n) {
113
+ const color = COLORS[Math.abs(n) % COLORS.length];
114
+ return color(text);
115
+ }
116
+ exports.grafastColor = grafastColor;
117
+ const symbolsByAlias = new Map();
118
+ let symbolClear = null;
119
+ /**
120
+ * Returns a text description for a symbol that helps differentiate similar
121
+ * symbols by keeping track of the symbols/descriptions it has seen and adding
122
+ * numeric identifiers to the output. Only tracks symbols over a short period
123
+ * so counts will reset very frequently.
124
+ */
125
+ function grafastPrintSymbol(symbol) {
126
+ const description = _grafastSymbolDescription(symbol);
127
+ if (!symbolClear) {
128
+ // Only cache symbols for a few milliseconds, we don't want a memory leak!
129
+ symbolClear = setTimeout(() => {
130
+ symbolClear = null;
131
+ symbolsByAlias.clear();
132
+ }, 200);
133
+ }
134
+ const symbols = symbolsByAlias.get(description);
135
+ if (!symbols) {
136
+ symbolsByAlias.set(description, [symbol]);
137
+ return description;
138
+ }
139
+ let idx = symbols.indexOf(symbol);
140
+ if (idx === 0) {
141
+ return description;
142
+ }
143
+ if (idx < 0) {
144
+ idx = symbols.push(symbol) - 1;
145
+ }
146
+ return `${description}${chalk_1.default.gray(`:${idx + 1}`)}`;
147
+ }
148
+ /**
149
+ * Prints something grafast-style (i.e. concise, coloured, with helpful detail)
150
+ */
151
+ function grafastPrint(symbol) {
152
+ return _grafastPrint(symbol, new Set());
153
+ }
154
+ exports.grafastPrint = grafastPrint;
155
+ /**
156
+ * An ANSI-aware pad function; strips ANSI sequences from the string, figures
157
+ * out how much it needs to pad it by, and then pads the original string by
158
+ * that amount.
159
+ */
160
+ function ansiPad(ansiString, targetLength, fill, position) {
161
+ const string = (0, stripAnsi_js_1.stripAnsi)(ansiString);
162
+ const fillLength = targetLength - string.length;
163
+ if (fillLength >= 0) {
164
+ const fillString = fill.repeat(fillLength);
165
+ if (position === "start") {
166
+ return fillString + ansiString;
167
+ }
168
+ else {
169
+ return ansiString + fillString;
170
+ }
171
+ }
172
+ else {
173
+ return ansiString;
174
+ }
175
+ }
176
+ exports.ansiPad = ansiPad;
177
+ //# sourceMappingURL=grafastPrint.js.map
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphqlCollectFields = exports.evalDirectiveArgDirect = exports.evalDirectiveArg = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const graphql = tslib_1.__importStar(require("graphql"));
6
+ const error_js_1 = require("./error.js");
7
+ const { GraphQLError, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, } = graphql;
8
+ /**
9
+ * Given a selection, finds the first directive named `directiveName`.
10
+ *
11
+ * @internal
12
+ *
13
+ * PERF: inline.
14
+ */
15
+ function getDirective(selection, directiveName) {
16
+ return selection.directives?.find((d) => d.name.value === directiveName);
17
+ }
18
+ /**
19
+ * Given a selection, finds the first directive named `directiveName` and, if
20
+ * found, extracts and returns the value from the argument named
21
+ * `argumentName`, tracking variable access if necessary.
22
+ *
23
+ * @remarks Currently only supports booleans.
24
+ *
25
+ * @internal
26
+ *
27
+ * PERF: inline.
28
+ */
29
+ function evalDirectiveArg(selection, directiveName, argumentName, variableValuesStep, defaultValue) {
30
+ const directive = getDirective(selection, directiveName);
31
+ if (!directive)
32
+ return undefined;
33
+ return evalDirectiveArgDirect(directive, argumentName, variableValuesStep, defaultValue);
34
+ }
35
+ exports.evalDirectiveArg = evalDirectiveArg;
36
+ function evalDirectiveArgDirect(directive, argumentName, variableValuesStep, defaultValue) {
37
+ if (!directive.arguments)
38
+ return defaultValue;
39
+ const argument = directive.arguments.find((a) => a.name.value === argumentName);
40
+ if (argument !== undefined) {
41
+ const value = argument.value;
42
+ switch (value.kind) {
43
+ case "Variable": {
44
+ return variableValuesStep.get(value.name.value).eval();
45
+ }
46
+ case "BooleanValue": {
47
+ return value.value;
48
+ }
49
+ case "IntValue": {
50
+ return parseInt(value.value, 10);
51
+ }
52
+ case "NullValue": {
53
+ return null;
54
+ }
55
+ default: {
56
+ throw new error_js_1.SafeError(`Unsupported @${directive.name}(${argumentName}:) argument; expected Variable, Boolean or null; but received '${value.kind}'`);
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ return defaultValue;
62
+ }
63
+ }
64
+ exports.evalDirectiveArgDirect = evalDirectiveArgDirect;
65
+ /**
66
+ * Implements the `DoesFragmentTypeApply` algorithm from the GraphQL
67
+ * specification.
68
+ *
69
+ * @see https://spec.graphql.org/draft/#DoesFragmentTypeApply()
70
+ *
71
+ * @internal
72
+ */
73
+ function graphqlDoesFragmentTypeApply(objectType, fragmentType) {
74
+ if (fragmentType instanceof GraphQLObjectType) {
75
+ return objectType === fragmentType;
76
+ }
77
+ else if (fragmentType instanceof GraphQLInterfaceType) {
78
+ const interfaces = objectType.getInterfaces();
79
+ return interfaces.includes(fragmentType);
80
+ }
81
+ else if (fragmentType instanceof GraphQLUnionType) {
82
+ const types = fragmentType.getTypes();
83
+ return types.includes(objectType);
84
+ }
85
+ else {
86
+ throw new Error("Invalid call to graphqlDoesFragmentTypeApply");
87
+ }
88
+ }
89
+ const processFragment = (operationPlan, parentStepId, objectType, isMutation, selectionSetDigest, selection, fragmentSelectionSet, visitedFragments) => {
90
+ const trackedVariableValuesStep = operationPlan.trackedVariableValuesStep;
91
+ const defer = selection.directives?.find((d) => d.name.value === "defer");
92
+ const deferIf = defer
93
+ ? evalDirectiveArgDirect(defer, "if", trackedVariableValuesStep, true) ?? true
94
+ : undefined;
95
+ const label = defer
96
+ ? evalDirectiveArgDirect(defer, "label", trackedVariableValuesStep, null) ?? undefined
97
+ : undefined;
98
+ const deferredDigest = deferIf === true
99
+ ? {
100
+ label,
101
+ fields: new Map(),
102
+ deferred: undefined,
103
+ }
104
+ : null;
105
+ if (deferredDigest !== null) {
106
+ if (selectionSetDigest.deferred === undefined) {
107
+ selectionSetDigest.deferred = [deferredDigest];
108
+ }
109
+ else {
110
+ selectionSetDigest.deferred.push(deferredDigest);
111
+ }
112
+ }
113
+ graphqlCollectFields(operationPlan, parentStepId, objectType, fragmentSelectionSet.selections, isMutation, visitedFragments, deferredDigest ?? selectionSetDigest);
114
+ };
115
+ /**
116
+ * Implements the `GraphQLCollectFields` algorithm - like `CollectFields` the
117
+ * GraphQL spec, but modified such that access to variables is tracked.
118
+ *
119
+ * @see https://spec.graphql.org/draft/#CollectFields()
120
+ *
121
+ * @internal
122
+ */
123
+ function graphqlCollectFields(operationPlan, parentStepId, objectType, selections, isMutation = false,
124
+ // This is significantly faster than an array or a Set
125
+ visitedFragments = Object.create(null), selectionSetDigest = {
126
+ label: undefined,
127
+ fields: new Map(),
128
+ deferred: undefined,
129
+ }) {
130
+ // const objectTypeFields = objectType.getFields();
131
+ const trackedVariableValuesStep = operationPlan.trackedVariableValuesStep;
132
+ for (let i = 0, l = selections.length; i < l; i++) {
133
+ const selection = selections[i];
134
+ if (selection.directives !== undefined) {
135
+ if (evalDirectiveArg(selection, "skip", "if", trackedVariableValuesStep, true) === true) {
136
+ continue;
137
+ }
138
+ if (evalDirectiveArg(selection, "include", "if", trackedVariableValuesStep, true) === false) {
139
+ continue;
140
+ }
141
+ }
142
+ switch (selection.kind) {
143
+ case "Field": {
144
+ const field = selection;
145
+ const responseKey = field.alias ? field.alias.value : field.name.value;
146
+ let groupForResponseKey = selectionSetDigest.fields.get(responseKey);
147
+ if (groupForResponseKey === undefined) {
148
+ groupForResponseKey = [field];
149
+ selectionSetDigest.fields.set(responseKey, groupForResponseKey);
150
+ }
151
+ else {
152
+ groupForResponseKey.push(field);
153
+ }
154
+ break;
155
+ }
156
+ case "FragmentSpread": {
157
+ const fragmentSpreadName = selection.name.value;
158
+ if (visitedFragments[fragmentSpreadName]) {
159
+ continue;
160
+ }
161
+ const fragment = operationPlan.fragments[fragmentSpreadName];
162
+ // This is forbidden by validation
163
+ if (fragment == null)
164
+ continue;
165
+ const fragmentTypeName = fragment.typeCondition.name.value;
166
+ if (fragmentTypeName === objectType.name) {
167
+ // No further checks needed
168
+ }
169
+ else {
170
+ const fragmentType = operationPlan.schema.getType(fragmentTypeName);
171
+ // This is forbidden by validation
172
+ if (!fragmentType)
173
+ continue;
174
+ if (fragmentType.constructor === GraphQLObjectType ||
175
+ /* According to validation, this must be the case */
176
+ // !(isInterfaceType(fragmentType) || isUnionType(fragmentType)) ||
177
+ !graphqlDoesFragmentTypeApply(objectType, fragmentType)) {
178
+ continue;
179
+ }
180
+ }
181
+ const fragmentSelectionSet = fragment.selectionSet;
182
+ const newVisitedFragments = Object.assign(Object.create(null), visitedFragments);
183
+ newVisitedFragments[fragmentSpreadName] = true;
184
+ processFragment(operationPlan, parentStepId, objectType, isMutation, selectionSetDigest, selection, fragmentSelectionSet, newVisitedFragments);
185
+ break;
186
+ }
187
+ case "InlineFragment": {
188
+ const fragmentTypeAst = selection.typeCondition;
189
+ if (fragmentTypeAst != null) {
190
+ const fragmentTypeName = fragmentTypeAst.name.value;
191
+ if (fragmentTypeName === objectType.name) {
192
+ // No further checks required
193
+ }
194
+ else {
195
+ const fragmentType = operationPlan.schema.getType(fragmentTypeName);
196
+ // This is forbidden by validation
197
+ if (fragmentType == null) {
198
+ throw new GraphQLError(`We don't have a type named '${fragmentTypeName}'`);
199
+ }
200
+ if (fragmentType.constructor === GraphQLObjectType ||
201
+ /* According to validation, this must be the case */
202
+ // !(isInterfaceType(fragmentType) || isUnionType(fragmentType)) ||
203
+ !graphqlDoesFragmentTypeApply(objectType, fragmentType)) {
204
+ continue;
205
+ }
206
+ }
207
+ }
208
+ const fragmentSelectionSet = selection.selectionSet;
209
+ processFragment(operationPlan, parentStepId, objectType, isMutation, selectionSetDigest, selection, fragmentSelectionSet, visitedFragments);
210
+ break;
211
+ }
212
+ }
213
+ }
214
+ return selectionSetDigest;
215
+ }
216
+ exports.graphqlCollectFields = graphqlCollectFields;
217
+ //# sourceMappingURL=graphqlCollectFields.js.map
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fieldSelectionsForType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const graphql = tslib_1.__importStar(require("graphql"));
6
+ const inspect_js_1 = require("./inspect.js");
7
+ const { Kind } = graphql;
8
+ // PERF: this is incredibly inefficient
9
+ function typeMatchesCondition(operationPlan, type, condition) {
10
+ const name = condition.name.value;
11
+ if (type.name === name) {
12
+ return true;
13
+ }
14
+ if (type.getInterfaces().some((i) => i.name === name)) {
15
+ return true;
16
+ }
17
+ if (operationPlan.unionsContainingObjectType[type.name].some((u) => u.name === name)) {
18
+ return true;
19
+ }
20
+ return false;
21
+ }
22
+ /**
23
+ * Given a list of polymorphic selections, return a list of the nested field
24
+ * selections that apply to the object type `type`.
25
+ */
26
+ function fieldSelectionsForType(operationPlan, type, selections, result = []) {
27
+ for (let i = 0, l = selections.length; i < l; i++) {
28
+ const selection = selections[i];
29
+ switch (selection.kind) {
30
+ case Kind.FRAGMENT_SPREAD: {
31
+ // Assumed to exist because query passed validation.
32
+ const fragment = operationPlan.fragments[selection.name.value];
33
+ const typeCondition = fragment.typeCondition;
34
+ if (typeMatchesCondition(operationPlan, type, typeCondition)) {
35
+ fieldSelectionsForType(operationPlan, type, fragment.selectionSet.selections, result);
36
+ }
37
+ break;
38
+ }
39
+ case Kind.INLINE_FRAGMENT: {
40
+ const typeCondition = selection.typeCondition;
41
+ if (!typeCondition ||
42
+ typeMatchesCondition(operationPlan, type, typeCondition)) {
43
+ fieldSelectionsForType(operationPlan, type, selection.selectionSet.selections, result);
44
+ }
45
+ break;
46
+ }
47
+ case Kind.FIELD: {
48
+ result.push(selection);
49
+ break;
50
+ }
51
+ default: {
52
+ const never = selection;
53
+ throw new Error(`GrafastInternalError<10b01e35-cf2b-4f48-9c66-486cdef00323>: cannot process selection '${(0, inspect_js_1.inspect)(never)}'`);
54
+ }
55
+ }
56
+ }
57
+ return result;
58
+ }
59
+ exports.fieldSelectionsForType = fieldSelectionsForType;
60
+ //# sourceMappingURL=graphqlMergeSelectionSets.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import "./thereCanBeOnlyOne.js";
2
+ import type LRU from "@graphile/lru";
3
+ import type { PluginHook } from "graphile-config";
4
+ import type { DocumentNode, ExecutionArgs as GraphQLExecutionArgs, GraphQLError, OperationDefinitionNode } from "graphql";
5
+ type PromiseOrValue<T> = T | Promise<T>;
2
6
  import { exportAs, exportAsMany } from "./exportAs.js";
3
7
  import { grafastPrint } from "./grafastPrint.js";
4
8
  import { EnumPlans, FieldPlans, GrafastPlans, InputObjectPlans, InterfaceOrUnionPlans, makeGrafastSchema, ObjectPlans, ScalarPlans } from "./makeGrafastSchema.js";
@@ -8,7 +12,8 @@ import { OperationPlan } from "./engine/OperationPlan.js";
8
12
  import { GrafastError, isGrafastError, isSafeError, SafeError } from "./error.js";
9
13
  import { execute } from "./execute.js";
10
14
  import { grafast, grafastSync } from "./grafastGraphql.js";
11
- import { $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, EnumValueApplyPlanResolver, EventCallback, EventMapKey, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, FieldArgs, FieldInfo, FieldPlanResolver, GrafastArgumentConfig, GrafastFieldConfig, GrafastFieldConfigArgumentMap, GrafastInputFieldConfig, GrafastPlanJSON, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, GrafastValuesList, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, InputObjectTypeInputPlanResolver, InputStep, JSONArray, JSONObject, JSONValue, NodeIdCodec, NodeIdHandler, OutputPlanForType, PolymorphicData, PromiseOrDirect, ScalarPlanResolver, StepOptimizeOptions, StepStreamOptions, TypedEventEmitter } from "./interfaces.js";
15
+ import type { $$cacheByOperation, $$hooked, $$queryCache, CacheByOperationEntry, GrafastTimeouts, ScalarInputPlanResolver } from "./interfaces.js";
16
+ import { $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, EnumValueApplyPlanResolver, EventCallback, EventMapKey, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, FieldArgs, FieldInfo, FieldPlanResolver, GrafastArgumentConfig, GrafastFieldConfig, GrafastFieldConfigArgumentMap, GrafastInputFieldConfig, GrafastPlanJSON, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, GrafastValuesList, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, InputObjectTypeInputPlanResolver, InputStep, JSONArray, JSONObject, JSONValue, Maybe, NodeIdCodec, NodeIdHandler, OutputPlanForType, PolymorphicData, PromiseOrDirect, ScalarPlanResolver, StepOptimizeOptions, StepStreamOptions, TypedEventEmitter } from "./interfaces.js";
12
17
  import { polymorphicWrap } from "./polymorphic.js";
13
18
  import { assertExecutableStep, assertListCapableStep, assertModifierStep, BaseStep, ExecutableStep, isExecutableStep, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isStreamableStep, ListCapableStep, ListLikeStep, ModifierStep, ObjectLikeStep, PolymorphicStep, StreamableStep, UnbatchedExecutableStep } from "./step.js";
14
19
  import { __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, assertEdgeCapableStep, assertPageInfoCapableStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, debugPlans, each, EdgeCapableStep, EdgeStep, error, ErrorStep, filter, FilterPlanMemo, first, FirstStep, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, lambda, LambdaStep, last, LastStep, list, listen, ListenStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, node, NodeStep, object, ObjectPlanMeta, ObjectStep, operationPlan, PageInfoCapableStep, partitionByIndex, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, setter, SetterCapableStep, SetterStep, specFromNodeId } from "./steps/index.js";
@@ -17,11 +22,165 @@ import { stripAnsi } from "./stripAnsi.js";
17
22
  import { subscribe } from "./subscribe.js";
18
23
  import { arrayOfLength, arraysMatch, getEnumValueConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, inputObjectFieldSpec, InputObjectTypeSpec, isPromiseLike, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, objectFieldSpec, objectSpec, ObjectTypeFields, ObjectTypeSpec, stepADependsOnStepB, stepAMayDependOnStepB, stepsAreInSamePhase } from "./utils.js";
19
24
  export { isAsyncIterable } from "iterall";
20
- export { __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifierStep, assertPageInfoCapableStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BaseStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, debugPlans, defer, Deferred, each, EdgeCapableStep, EdgeStep, EnumPlans, EnumValueApplyPlanResolver, error, ErrorStep, EventCallback, EventMapKey, ExecutableStep, execute, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, exportAs, exportAsMany, FieldArgs, FieldInfo, FieldPlanResolver, FieldPlans, filter, FilterPlanMemo, first, FirstStep, getEnumValueConfig, grafast, GrafastArgumentConfig, GrafastError, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, GrafastPlans, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, grafastSync, GrafastValuesList, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, inputObjectFieldSpec, InputObjectPlans, InputObjectTypeInputPlanResolver, InputObjectTypeSpec, InputStep, InterfaceOrUnionPlans, isDev, isExecutableStep, isGrafastError, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isPromiseLike, isSafeError, isStreamableStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeGrafastSchema, ModifierStep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, NodeIdHandler, NodeStep, noop, object, objectFieldSpec, ObjectLikeStep, ObjectPlanMeta, ObjectPlans, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, OutputPlanForType, PageInfoCapableStep, partitionByIndex, PolymorphicData, PolymorphicStep, polymorphicWrap, PromiseOrDirect, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, SafeError, ScalarPlanResolver, ScalarPlans, setter, SetterCapableStep, SetterStep, specFromNodeId, stepADependsOnStepB, stepAMayDependOnStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, StreamableStep, stringifyPayload, stripAnsi, subscribe, TypedEventEmitter, UnbatchedExecutableStep, };
25
+ export { __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, access, AccessStep, ActualKeyByDesiredKey, applyTransforms, ApplyTransformsStep, ArgumentApplyPlanResolver, ArgumentInputPlanResolver, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifierStep, assertPageInfoCapableStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BaseStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, debugPlans, defer, Deferred, each, EdgeCapableStep, EdgeStep, EnumPlans, EnumValueApplyPlanResolver, error, ErrorStep, EventCallback, EventMapKey, ExecutableStep, execute, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, exportAs, exportAsMany, FieldArgs, FieldInfo, FieldPlanResolver, FieldPlans, filter, FilterPlanMemo, first, FirstStep, getEnumValueConfig, grafast, GrafastArgumentConfig, GrafastError, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, GrafastPlans, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSubscriber, grafastSync, GrafastValuesList, GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, InputObjectFieldApplyPlanResolver, InputObjectFieldInputPlanResolver, inputObjectFieldSpec, InputObjectPlans, InputObjectTypeInputPlanResolver, InputObjectTypeSpec, InputStep, InterfaceOrUnionPlans, isDev, isExecutableStep, isGrafastError, isListCapableStep, isListLikeStep, isModifierStep, isObjectLikeStep, isPromiseLike, isSafeError, isStreamableStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeGrafastSchema, Maybe, ModifierStep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, NodeIdHandler, NodeStep, noop, object, objectFieldSpec, ObjectLikeStep, ObjectPlanMeta, ObjectPlans, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, OutputPlanForType, PageInfoCapableStep, partitionByIndex, PolymorphicData, PolymorphicStep, polymorphicWrap, PromiseOrDirect, proxy, ProxyStep, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, SafeError, ScalarPlanResolver, ScalarPlans, setter, SetterCapableStep, SetterStep, specFromNodeId, stepADependsOnStepB, stepAMayDependOnStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, StreamableStep, stringifyPayload, stripAnsi, subscribe, TypedEventEmitter, UnbatchedExecutableStep, };
21
26
  export { hookArgs } from "./args.js";
22
27
  export { version } from "./version.js";
23
28
  /** @deprecated Renamed to 'applyTransforms' */
24
29
  export declare const deepEval: typeof applyTransforms;
25
30
  /** @deprecated Renamed to 'ApplyTransformsStep' */
26
31
  export declare const DeepEvalStep: typeof ApplyTransformsStep;
32
+ declare global {
33
+ namespace Grafast {
34
+ type ExecutionArgs = Pick<GraphQLExecutionArgs, "schema" | "document" | "rootValue" | "variableValues" | "operationName"> & {
35
+ [$$hooked]?: boolean;
36
+ contextValue: Grafast.Context;
37
+ };
38
+ /**
39
+ * Details about the incoming GraphQL request - e.g. if it was sent over an
40
+ * HTTP request, the request itself so headers can be interrogated.
41
+ *
42
+ * It's anticipated this will be expanded via declaration merging, e.g. if
43
+ * your server is Koa v2 then `RequestContext.koav2` might be added.
44
+ */
45
+ interface RequestContext {
46
+ }
47
+ /**
48
+ * The GraphQL context our schemas expect, generally generated from details in Grafast.RequestContext
49
+ */
50
+ interface Context {
51
+ }
52
+ interface FieldExtensions {
53
+ plan?: FieldPlanResolver<any, any, any>;
54
+ subscribePlan?: FieldPlanResolver<any, any, any>;
55
+ }
56
+ interface ArgumentExtensions {
57
+ inputPlan?: ArgumentInputPlanResolver;
58
+ applyPlan?: ArgumentApplyPlanResolver;
59
+ autoApplyAfterParentPlan?: boolean;
60
+ autoApplyAfterParentSubscribePlan?: boolean;
61
+ }
62
+ interface InputObjectTypeExtensions {
63
+ inputPlan?: InputObjectTypeInputPlanResolver;
64
+ }
65
+ interface InputFieldExtensions {
66
+ inputPlan?: InputObjectFieldInputPlanResolver;
67
+ applyPlan?: InputObjectFieldApplyPlanResolver;
68
+ autoApplyAfterParentInputPlan?: boolean;
69
+ autoApplyAfterParentApplyPlan?: boolean;
70
+ }
71
+ interface ObjectTypeExtensions {
72
+ assertStep?: ((step: ExecutableStep) => asserts step is ExecutableStep) | {
73
+ new (...args: any[]): ExecutableStep;
74
+ } | null;
75
+ }
76
+ interface EnumTypeExtensions {
77
+ }
78
+ interface EnumValueExtensions {
79
+ /**
80
+ * EXPERIMENTAL!
81
+ *
82
+ * @internal
83
+ */
84
+ applyPlan?: EnumValueApplyPlanResolver<any>;
85
+ }
86
+ interface ScalarTypeExtensions {
87
+ plan?: ScalarPlanResolver;
88
+ inputPlan?: ScalarInputPlanResolver;
89
+ /**
90
+ * Set true if `serialize(serialize(foo)) === serialize(foo)` for all foo
91
+ */
92
+ idempotent?: boolean;
93
+ }
94
+ interface SchemaExtensions {
95
+ /**
96
+ * Maximum number of queries to store in this schema's query cache.
97
+ */
98
+ queryCacheMaxLength?: number;
99
+ /**
100
+ * The underlying query cache
101
+ */
102
+ [$$queryCache]?: LRU<string, DocumentNode | ReadonlyArray<GraphQLError>>;
103
+ /**
104
+ * Maximum number of operations to store an operation plan lookup cache for
105
+ */
106
+ operationsCacheMaxLength?: number;
107
+ /**
108
+ * Maximum number of operation plans to store in a single operation's cache
109
+ */
110
+ operationOperationPlansCacheMaxLength?: number;
111
+ /**
112
+ * The starting point for finding/storing the relevant OperationPlan for a request.
113
+ */
114
+ [$$cacheByOperation]?: LRU<OperationDefinitionNode, CacheByOperationEntry>;
115
+ }
116
+ }
117
+ namespace GraphileConfig {
118
+ interface GrafastOptions {
119
+ /**
120
+ * An object to merge into the GraphQL context. Alternatively, pass an
121
+ * (optionally asynchronous) function that returns an object to merge into
122
+ * the GraphQL context.
123
+ */
124
+ context?: Partial<Grafast.Context> | ((ctx: Partial<Grafast.RequestContext>, args: Grafast.ExecutionArgs) => PromiseOrValue<Partial<Grafast.Context>>);
125
+ /**
126
+ * A list of 'explain' types that should be included in `extensions.explain`.
127
+ *
128
+ * - `plan` will cause the plan JSON to be included
129
+ * - other values are dependent on the plugins in play
130
+ *
131
+ * If set to `true` then all possible explain types will be exposed.
132
+ */
133
+ explain?: boolean | string[];
134
+ timeouts?: GrafastTimeouts;
135
+ }
136
+ interface Preset {
137
+ /**
138
+ * Options that control how `grafast` should execute your GraphQL
139
+ * operations.
140
+ */
141
+ grafast?: GraphileConfig.GrafastOptions;
142
+ }
143
+ interface GrafastHooks {
144
+ args: PluginHook<(event: {
145
+ args: Grafast.ExecutionArgs;
146
+ ctx: Grafast.RequestContext;
147
+ resolvedPreset: GraphileConfig.ResolvedPreset;
148
+ }) => PromiseOrValue<void>>;
149
+ }
150
+ interface Plugin {
151
+ grafast?: {
152
+ hooks?: GrafastHooks;
153
+ };
154
+ }
155
+ }
156
+ }
157
+ declare module "graphql" {
158
+ interface GraphQLFieldExtensions<_TSource, _TContext, _TArgs = any> {
159
+ grafast?: Grafast.FieldExtensions;
160
+ }
161
+ interface GraphQLArgumentExtensions {
162
+ grafast?: Grafast.ArgumentExtensions;
163
+ }
164
+ interface GraphQLInputObjectTypeExtensions {
165
+ grafast?: Grafast.InputObjectTypeExtensions;
166
+ }
167
+ interface GraphQLInputFieldExtensions {
168
+ grafast?: Grafast.InputFieldExtensions;
169
+ }
170
+ interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
171
+ grafast?: Grafast.ObjectTypeExtensions;
172
+ }
173
+ interface GraphQLEnumTypeExtensions {
174
+ grafast?: Grafast.EnumTypeExtensions;
175
+ }
176
+ interface GraphQLEnumValueExtensions {
177
+ grafast?: Grafast.EnumValueExtensions;
178
+ }
179
+ interface GraphQLScalarTypeExtensions {
180
+ grafast?: Grafast.ScalarTypeExtensions;
181
+ }
182
+ interface GraphQLSchemaExtensions {
183
+ grafast?: Grafast.SchemaExtensions;
184
+ }
185
+ }
27
186
  //# sourceMappingURL=index.d.ts.map