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.
- package/README.md +2 -3
- package/dist/args.d.ts +4 -7
- package/dist/args.js +53 -38
- package/dist/assert.js +2 -3
- package/dist/bucket.d.ts +1 -89
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/constraints.d.ts +15 -1
- package/dist/constraints.js +41 -3
- package/dist/deferred.js +1 -2
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +18 -3
- package/dist/engine/LayerPlan.d.ts +21 -111
- package/dist/engine/LayerPlan.js +196 -78
- package/dist/engine/OperationPlan.d.ts +30 -104
- package/dist/engine/OperationPlan.js +763 -471
- package/dist/engine/OutputPlan.d.ts +9 -20
- package/dist/engine/OutputPlan.js +432 -444
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +94 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +646 -244
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +7 -2
- package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
- package/dist/engine/lib/defaultPlanResolver.js +11 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
- package/dist/engine/lock.d.ts +4 -0
- package/dist/engine/lock.js +82 -0
- package/dist/envelop.js +5 -4
- package/dist/error.d.ts +18 -49
- package/dist/error.js +50 -39
- package/dist/establishOperationPlan.js +57 -42
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +31 -15
- package/dist/exportAs.d.ts +1 -18
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +35 -16
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +67 -6
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +24 -13
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +44 -29
- package/dist/index.js +91 -18
- package/dist/input.d.ts +1 -9
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -3
- package/dist/inspect.js +3 -3
- package/dist/interfaces.d.ts +238 -93
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +21 -9
- package/dist/makeGrafastSchema.js +353 -133
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +131 -19
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +24 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +54 -0
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +140 -368
- package/dist/planJSONInterfaces.d.ts +12 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +100 -74
- package/dist/step.d.ts +118 -172
- package/dist/step.js +262 -183
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +261 -0
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +4 -6
- package/dist/steps/__inputDynamicScalar.js +4 -2
- package/dist/steps/__inputList.d.ts +5 -9
- package/dist/steps/__inputList.js +4 -1
- package/dist/steps/__inputObject.d.ts +7 -11
- package/dist/steps/__inputObject.js +49 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +10 -12
- package/dist/steps/__item.js +8 -2
- package/dist/steps/__trackedValue.d.ts +7 -55
- package/dist/steps/__trackedValue.js +69 -8
- package/dist/steps/__value.d.ts +5 -4
- package/dist/steps/__value.js +5 -4
- package/dist/steps/access.d.ts +10 -10
- package/dist/steps/access.js +50 -17
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -25
- package/dist/steps/applyTransforms.js +53 -31
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +56 -42
- package/dist/steps/connection.js +97 -44
- package/dist/steps/constant.d.ts +7 -7
- package/dist/steps/constant.js +86 -7
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +2 -3
- package/dist/steps/error.d.ts +4 -4
- package/dist/steps/error.js +7 -6
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +10 -9
- package/dist/steps/first.js +9 -13
- package/dist/steps/graphqlResolver.d.ts +3 -76
- package/dist/steps/graphqlResolver.js +89 -72
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +12 -3
- package/dist/steps/index.js +48 -6
- package/dist/steps/lambda.d.ts +9 -9
- package/dist/steps/lambda.js +18 -9
- package/dist/steps/last.d.ts +9 -8
- package/dist/steps/last.js +7 -6
- package/dist/steps/list.d.ts +20 -9
- package/dist/steps/list.js +56 -13
- package/dist/steps/listTransform.d.ts +18 -22
- package/dist/steps/listTransform.js +58 -27
- package/dist/steps/listen.d.ts +6 -11
- package/dist/steps/listen.js +14 -16
- package/dist/steps/load.d.ts +42 -33
- package/dist/steps/load.js +60 -27
- package/dist/steps/node.d.ts +17 -10
- package/dist/steps/node.js +18 -6
- package/dist/steps/object.d.ts +33 -27
- package/dist/steps/object.js +53 -32
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +11 -12
- package/dist/steps/proxy.js +8 -5
- package/dist/steps/remapKeys.d.ts +10 -10
- package/dist/steps/remapKeys.js +14 -7
- package/dist/steps/reverse.d.ts +8 -8
- package/dist/steps/reverse.js +10 -7
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +24 -9
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +56 -55
- package/dist/utils.js +179 -59
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -51,11 +51,10 @@ And please give some love to our featured sponsors 🤩:
|
|
|
51
51
|
<table><tr>
|
|
52
52
|
<td align="center"><a href="https://www.the-guild.dev/"><img src="https://graphile.org/images/sponsors/theguild.png" width="90" height="90" alt="The Guild" /><br />The Guild</a> *</td>
|
|
53
53
|
<td align="center"><a href="https://dovetailapp.com/"><img src="https://graphile.org/images/sponsors/dovetail.png" width="90" height="90" alt="Dovetail" /><br />Dovetail</a> *</td>
|
|
54
|
-
<td align="center"><a href="https://www.netflix.com/"><img src="https://graphile.org/images/sponsors/Netflix.png" width="90" height="90" alt="Netflix" /><br />Netflix</a> *</td>
|
|
55
54
|
<td align="center"><a href="https://stellate.co/"><img src="https://graphile.org/images/sponsors/Stellate.png" width="90" height="90" alt="Stellate" /><br />Stellate</a> *</td>
|
|
55
|
+
<td align="center"><a href="https://gosteelhead.com/"><img src="https://graphile.org/images/sponsors/steelhead.svg" width="90" height="90" alt="Steelhead" /><br />Steelhead</a> *</td>
|
|
56
56
|
</tr><tr>
|
|
57
|
-
<td align="center"><a href="
|
|
58
|
-
<td align="center"><a href="https://microteam.io/"><img src="https://graphile.org/images/sponsors/micro.png" width="90" height="90" alt="We Love Micro" /><br />We Love Micro</a> *</td>
|
|
57
|
+
<td align="center"><a href=""><img src="https://graphile.org/images/sponsors/latchbio.jpg" width="90" height="90" alt="LatchBio" /><br />LatchBio</a> *</td>
|
|
59
58
|
</tr></table>
|
|
60
59
|
|
|
61
60
|
<em>\* Sponsors the entire Graphile suite</em>
|
package/dist/args.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { ExecutionArgs } from "graphql";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): Grafast.ExecutionArgs | PromiseLike<Grafast.ExecutionArgs>;
|
|
2
|
+
import type { GrafastExecutionArgs, PromiseOrDirect } from "./interfaces.js";
|
|
3
|
+
/** @deprecated Pass `resolvedPreset` and `requestContext` via args directly */
|
|
4
|
+
export declare function hookArgs(rawArgs: ExecutionArgs, resolvedPreset: GraphileConfig.ResolvedPreset, ctx: Partial<Grafast.RequestContext>): PromiseOrDirect<Grafast.ExecutionArgs>;
|
|
5
|
+
export declare function hookArgs(rawArgs: GrafastExecutionArgs): PromiseOrDirect<Grafast.ExecutionArgs>;
|
|
9
6
|
//# sourceMappingURL=args.d.ts.map
|
package/dist/args.js
CHANGED
|
@@ -1,62 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookArgs =
|
|
4
|
-
const config_js_1 = require("./config.js");
|
|
3
|
+
exports.hookArgs = hookArgs;
|
|
5
4
|
const interfaces_js_1 = require("./interfaces.js");
|
|
5
|
+
const middleware_js_1 = require("./middleware.js");
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
|
8
|
+
const $$writeTest = Symbol("grafastWriteTest");
|
|
7
9
|
/**
|
|
8
10
|
* Applies Graphile Config hooks to your GraphQL request, e.g. to
|
|
9
11
|
* populate context or similar.
|
|
10
12
|
*
|
|
11
13
|
* @experimental
|
|
12
14
|
*/
|
|
13
|
-
function hookArgs(rawArgs,
|
|
15
|
+
function hookArgs(rawArgs, legacyResolvedPreset, legacyCtx) {
|
|
16
|
+
if (legacyResolvedPreset !== undefined) {
|
|
17
|
+
rawArgs.resolvedPreset = legacyResolvedPreset;
|
|
18
|
+
}
|
|
19
|
+
if (legacyCtx !== undefined) {
|
|
20
|
+
rawArgs.requestContext = rawArgs.requestContext ?? legacyCtx;
|
|
21
|
+
}
|
|
22
|
+
const { middleware: rawMiddleware, resolvedPreset, contextValue: rawContextValue, } = rawArgs;
|
|
23
|
+
try {
|
|
24
|
+
rawContextValue[$$writeTest] = true;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// Make context mutable
|
|
28
|
+
rawArgs.contextValue = Object.assign(Object.create(null), rawContextValue);
|
|
29
|
+
}
|
|
30
|
+
const middleware = rawMiddleware === undefined && resolvedPreset != null
|
|
31
|
+
? (0, middleware_js_1.getGrafastMiddleware)(resolvedPreset)
|
|
32
|
+
: (rawMiddleware ?? null);
|
|
33
|
+
if (rawMiddleware === undefined) {
|
|
34
|
+
rawArgs.middleware = middleware;
|
|
35
|
+
}
|
|
14
36
|
const args = rawArgs;
|
|
15
37
|
// Assert that args haven't already been hooked
|
|
16
38
|
if (args[interfaces_js_1.$$hooked]) {
|
|
17
39
|
throw new Error("Must not call hookArgs twice!");
|
|
18
40
|
}
|
|
19
41
|
args[interfaces_js_1.$$hooked] = true;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Object.assign(
|
|
42
|
+
if (middleware != null) {
|
|
43
|
+
return middleware.run("prepareArgs", { args }, finalizeWithEvent);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return finalize(args);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function finalize(args) {
|
|
50
|
+
const userContext = args.resolvedPreset?.grafast?.context;
|
|
51
|
+
const contextValue = args.contextValue;
|
|
52
|
+
if (typeof userContext === "function") {
|
|
53
|
+
const result = userContext(args.requestContext ?? EMPTY_OBJECT, args);
|
|
54
|
+
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
55
|
+
// Deliberately shadowed 'result'
|
|
56
|
+
return result.then((result) => {
|
|
57
|
+
Object.assign(contextValue, result);
|
|
36
58
|
return args;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (typeof userContext === "object" && userContext !== null) {
|
|
40
|
-
Object.assign(args.contextValue, userContext);
|
|
41
|
-
return args;
|
|
59
|
+
});
|
|
42
60
|
}
|
|
43
61
|
else {
|
|
62
|
+
Object.assign(contextValue, result);
|
|
44
63
|
return args;
|
|
45
64
|
}
|
|
46
|
-
};
|
|
47
|
-
if (resolvedPreset !== config_js_1.NULL_PRESET &&
|
|
48
|
-
resolvedPreset.plugins &&
|
|
49
|
-
resolvedPreset.plugins.length > 0) {
|
|
50
|
-
const event = { args, ctx, resolvedPreset };
|
|
51
|
-
const result = (0, config_js_1.hook)(resolvedPreset, "args", event);
|
|
52
|
-
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
53
|
-
return result.then(() => finalize(event.args));
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return finalize(event.args);
|
|
57
|
-
}
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
else if (typeof userContext === "object" && userContext !== null) {
|
|
67
|
+
Object.assign(contextValue, userContext);
|
|
68
|
+
return args;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return args;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function finalizeWithEvent(event) {
|
|
75
|
+
return finalize(event.args);
|
|
60
76
|
}
|
|
61
|
-
exports.hookArgs = hookArgs;
|
|
62
77
|
//# sourceMappingURL=args.js.map
|
package/dist/assert.js
CHANGED
|
@@ -6,19 +6,18 @@
|
|
|
6
6
|
* https://github.com/facebook/jest/issues/2549
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.ok = ok;
|
|
10
|
+
exports.strictEqual = strictEqual;
|
|
10
11
|
/** Equivalent to `assert.ok(...)` */
|
|
11
12
|
function ok(val, message) {
|
|
12
13
|
if (!val) {
|
|
13
14
|
throw new Error(message);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
exports.ok = ok;
|
|
17
17
|
/** Equivalent to `assert.strictEqual(...)` */
|
|
18
18
|
function strictEqual(actual, expected, message) {
|
|
19
19
|
if (actual !== expected) {
|
|
20
20
|
throw new Error(message + ` (${actual} !== ${expected})`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
exports.strictEqual = strictEqual;
|
|
24
23
|
//# sourceMappingURL=assert.js.map
|
package/dist/bucket.d.ts
CHANGED
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { MetaByMetaKey } from "./engine/OperationPlan";
|
|
3
|
-
import type { ExecutionEventEmitter } from "./interfaces.js";
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export interface RequestTools {
|
|
8
|
-
/** The `timeSource.now()` at which the request started executing */
|
|
9
|
-
startTime: number;
|
|
10
|
-
/** The `timeSource.now()` at which the request should stop executing (if a timeout was configured) */
|
|
11
|
-
stopTime: number | null;
|
|
12
|
-
readonly eventEmitter: ExecutionEventEmitter | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* If we're running inside GraphQL then we should not serialize scalars,
|
|
15
|
-
* otherwise we'll face the double-serialization problem.
|
|
16
|
-
*/
|
|
17
|
-
insideGraphQL: false;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A "bucket" is where the results from plans are stored so that other plans
|
|
21
|
-
* can retrieve them, it may take on different forms depending on the mode of
|
|
22
|
-
* execution. A "LayerPlan" is used to both identify the bucket and to specify
|
|
23
|
-
* why it exists and how it behaves.
|
|
24
|
-
*
|
|
25
|
-
* Every `ExecutableStep` belongs to exactly one LayerPlan (and thus bucket),
|
|
26
|
-
* specified by `plan.layerPlan`.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export interface Bucket {
|
|
31
|
-
/**
|
|
32
|
-
* The LayerPlan definition this bucket adheres to
|
|
33
|
-
*/
|
|
34
|
-
layerPlan: LayerPlan;
|
|
35
|
-
/**
|
|
36
|
-
* How many entries are there in the bucket?
|
|
37
|
-
*/
|
|
38
|
-
size: number;
|
|
39
|
-
/**
|
|
40
|
-
* The polymorphic path through which each of the entries (respectively) has
|
|
41
|
-
* travelled. This influences the steps that will be executed using the
|
|
42
|
-
* related inputs.
|
|
43
|
-
*/
|
|
44
|
-
polymorphicPathList: readonly (string | null)[];
|
|
45
|
-
/**
|
|
46
|
-
* These are the iterators the bucket (or its descendents, without crossing a
|
|
47
|
-
* stream/defer boundary) have created (if any). Each of these must either be
|
|
48
|
-
* processed via `processRoot`, or must be manually released (via
|
|
49
|
-
* `releaseUnusedIterators`) otherwise a memory leak could occur.
|
|
50
|
-
*/
|
|
51
|
-
iterators: Array<Set<AsyncIterator<any> | Iterator<any>>>;
|
|
52
|
-
/**
|
|
53
|
-
* `metaByMetaKey` belongs to the bucket rather than the request context
|
|
54
|
-
* because mutations and subscriptions shouldn't re-use caches.
|
|
55
|
-
*
|
|
56
|
-
* TODO: `inheritMeta: boolean`?
|
|
57
|
-
*/
|
|
58
|
-
metaByMetaKey: MetaByMetaKey;
|
|
59
|
-
/**
|
|
60
|
-
* Every entry in the store is a list with the same length as the bucket has
|
|
61
|
-
* `size`.
|
|
62
|
-
*
|
|
63
|
-
* The entry for '-1' is the request indexes, so we can associate the results
|
|
64
|
-
* back to the request that triggered them.
|
|
65
|
-
*/
|
|
66
|
-
store: Map<number, any[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Set this true when the bucket is fully executed.
|
|
69
|
-
*
|
|
70
|
-
* Initialize it to false.
|
|
71
|
-
*/
|
|
72
|
-
isComplete: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* If an error occurred at any stage we need to drop down to more careful
|
|
75
|
-
* (and slower) handling.
|
|
76
|
-
*
|
|
77
|
-
* Initialize it to false.
|
|
78
|
-
*/
|
|
79
|
-
hasErrors: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* The child buckets of this bucket.
|
|
82
|
-
*/
|
|
83
|
-
children: {
|
|
84
|
-
[layerPlanId: number]: {
|
|
85
|
-
bucket: Bucket;
|
|
86
|
-
map: Map<number, number | number[]>;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
}
|
|
1
|
+
export {};
|
|
90
2
|
//# sourceMappingURL=bucket.d.ts.map
|
package/dist/config.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
import type { AsyncHooks, PluginHook } from "graphile-config";
|
|
2
1
|
export declare const NULL_PRESET: GraphileConfig.ResolvedPreset;
|
|
3
|
-
type GraphileConfigModule = typeof import("graphile-config");
|
|
4
|
-
type PromiseOrValue<T> = T | Promise<T>;
|
|
5
|
-
export declare function withGraphileConfig<T>(callback: (graphileConfig: GraphileConfigModule | null) => PromiseOrValue<T>): PromiseOrValue<T>;
|
|
6
|
-
declare const $$skipHooks: unique symbol;
|
|
7
|
-
declare const $$hooksForPreset: unique symbol;
|
|
8
|
-
declare global {
|
|
9
|
-
namespace GraphileConfig {
|
|
10
|
-
interface ResolvedPreset {
|
|
11
|
-
[$$hooksForPreset]?: null | AsyncHooks<GraphileConfig.GrafastHooks>;
|
|
12
|
-
[$$skipHooks]?: Record<string, boolean>;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export declare function withHooks<TResult>(resolvedPreset: GraphileConfig.ResolvedPreset, callback: (hooks: AsyncHooks<GraphileConfig.GrafastHooks> | null) => PromiseOrValue<TResult>): PromiseOrValue<TResult>;
|
|
17
|
-
export declare function hook<THookName extends keyof GraphileConfig.GrafastHooks>(resolvedPreset: GraphileConfig.ResolvedPreset, hookName: THookName, ...args: Parameters<GraphileConfig.GrafastHooks[THookName] extends PluginHook<infer U> ? U : never>): PromiseOrValue<void>;
|
|
18
|
-
export {};
|
|
19
2
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,99 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NULL_PRESET = void 0;
|
|
4
4
|
exports.NULL_PRESET = Object.freeze(Object.create(null));
|
|
5
|
-
let graphileConfig = undefined;
|
|
6
|
-
let graphileConfigLoaded = false;
|
|
7
|
-
function withGraphileConfig(callback) {
|
|
8
|
-
if (graphileConfig === undefined) {
|
|
9
|
-
// ESM:
|
|
10
|
-
// This should be
|
|
11
|
-
// graphileConfig = import("graphile-config").then(
|
|
12
|
-
// but that causes a segfault in jest/node when testing third party
|
|
13
|
-
// modules. So we had to convert everything to CommonJS.
|
|
14
|
-
graphileConfig = new Promise((resolve, reject) => {
|
|
15
|
-
try {
|
|
16
|
-
resolve(require("graphile-config"));
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
if (e.code === "ERR_REQUIRE_ESM") {
|
|
20
|
-
return import("graphile-config").then(resolve, reject);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}).then((GC) => {
|
|
27
|
-
graphileConfig = GC;
|
|
28
|
-
graphileConfigLoaded = true;
|
|
29
|
-
return GC;
|
|
30
|
-
}, () => {
|
|
31
|
-
graphileConfig = null;
|
|
32
|
-
graphileConfigLoaded = true;
|
|
33
|
-
return null;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
if (graphileConfigLoaded) {
|
|
37
|
-
return callback(graphileConfig);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return graphileConfig.then(callback);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.withGraphileConfig = withGraphileConfig;
|
|
44
|
-
const $$skipHooks = Symbol("skipHooks");
|
|
45
|
-
const $$hooksForPreset = Symbol("grafastHooks");
|
|
46
|
-
function withHooks(resolvedPreset, callback) {
|
|
47
|
-
const existing = resolvedPreset[$$hooksForPreset];
|
|
48
|
-
if (existing !== undefined) {
|
|
49
|
-
return callback(existing);
|
|
50
|
-
}
|
|
51
|
-
if (!resolvedPreset.plugins || resolvedPreset.plugins.length === 0) {
|
|
52
|
-
resolvedPreset[$$hooksForPreset] = null;
|
|
53
|
-
return callback(null);
|
|
54
|
-
}
|
|
55
|
-
const plugins = resolvedPreset.plugins;
|
|
56
|
-
return withGraphileConfig((gc) => {
|
|
57
|
-
if (gc !== null) {
|
|
58
|
-
const hooks = new gc.AsyncHooks();
|
|
59
|
-
gc.applyHooks(plugins, (p) => p.grafast?.hooks, (name, fn, _plugin) => {
|
|
60
|
-
hooks.hook(name, fn);
|
|
61
|
-
});
|
|
62
|
-
resolvedPreset[$$hooksForPreset] = hooks;
|
|
63
|
-
return callback(hooks);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
resolvedPreset[$$hooksForPreset] = null;
|
|
67
|
-
return callback(null);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.withHooks = withHooks;
|
|
72
|
-
function hook(resolvedPreset, hookName, ...args) {
|
|
73
|
-
if (resolvedPreset[$$skipHooks]?.[hookName]) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
return withHooks(resolvedPreset, (hooks) => {
|
|
77
|
-
if (hooks !== null) {
|
|
78
|
-
if (hooks.callbacks[hookName] !== undefined) {
|
|
79
|
-
return hooks.process(hookName, ...args);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
if (!resolvedPreset[$$skipHooks]) {
|
|
83
|
-
resolvedPreset[$$skipHooks] = Object.create(null);
|
|
84
|
-
}
|
|
85
|
-
resolvedPreset[$$skipHooks][hookName] = true;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (!resolvedPreset[$$skipHooks]) {
|
|
91
|
-
resolvedPreset[$$skipHooks] = Object.create(null);
|
|
92
|
-
}
|
|
93
|
-
resolvedPreset[$$skipHooks][hookName] = true;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
exports.hook = hook;
|
|
99
5
|
//# sourceMappingURL=config.js.map
|
package/dist/constraints.d.ts
CHANGED
|
@@ -27,6 +27,20 @@ interface ExistsConstraint {
|
|
|
27
27
|
path: (string | number)[];
|
|
28
28
|
exists: boolean;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* If `keys` is null: asserts that there is no value at the given
|
|
32
|
+
* path.
|
|
33
|
+
*
|
|
34
|
+
* Otherwise: asserts that the value at the given path has the exact same keys.
|
|
35
|
+
*/
|
|
36
|
+
interface KeysConstraint {
|
|
37
|
+
type: "keys";
|
|
38
|
+
path: (string | number)[];
|
|
39
|
+
/**
|
|
40
|
+
* If this is null it implies that the object did not exist.
|
|
41
|
+
*/
|
|
42
|
+
keys: ReadonlyArray<string> | null;
|
|
43
|
+
}
|
|
30
44
|
/**
|
|
31
45
|
* If `expectedLength` is null: asserts that there is no value at the given
|
|
32
46
|
* path.
|
|
@@ -52,7 +66,7 @@ interface IsEmptyConstraint {
|
|
|
52
66
|
path: (string | number)[];
|
|
53
67
|
isEmpty: boolean;
|
|
54
68
|
}
|
|
55
|
-
export type Constraint = ValueConstraint | EqualityConstraint | ExistsConstraint | LengthConstraint | IsEmptyConstraint;
|
|
69
|
+
export type Constraint = ValueConstraint | EqualityConstraint | ExistsConstraint | LengthConstraint | IsEmptyConstraint | KeysConstraint;
|
|
56
70
|
/**
|
|
57
71
|
* Implements the `MatchesConstraints` algorithm.
|
|
58
72
|
*/
|
package/dist/constraints.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// and then compiling (JIT-style) remaining constraints into a function using
|
|
4
4
|
// tamedevil
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.matchesConstraints =
|
|
6
|
+
exports.matchesConstraints = matchesConstraints;
|
|
7
7
|
function valueAtPath(object, path) {
|
|
8
8
|
let value = object;
|
|
9
9
|
for (let i = 0, l = path.length; i < l; i++) {
|
|
@@ -32,7 +32,8 @@ function matchesConstraint(constraint, object) {
|
|
|
32
32
|
const value = valueAtPath(object, constraint.path);
|
|
33
33
|
switch (constraint.type) {
|
|
34
34
|
case "length": {
|
|
35
|
-
|
|
35
|
+
const actualLength = Array.isArray(value) ? value.length : null;
|
|
36
|
+
return actualLength === constraint.expectedLength;
|
|
36
37
|
}
|
|
37
38
|
case "exists": {
|
|
38
39
|
return (value !== undefined) === constraint.exists;
|
|
@@ -49,6 +50,44 @@ function matchesConstraint(constraint, object) {
|
|
|
49
50
|
Object.keys(value).length === 0;
|
|
50
51
|
return isEmpty === constraint.isEmpty;
|
|
51
52
|
}
|
|
53
|
+
case "keys": {
|
|
54
|
+
const { keys: expectedKeys } = constraint;
|
|
55
|
+
if (expectedKeys === null) {
|
|
56
|
+
return value == null || typeof value !== "object";
|
|
57
|
+
}
|
|
58
|
+
else if (value == null || typeof value !== "object") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// keys are always in order of the gql type; see coerceInputValue and __InputObjectStep ctor
|
|
63
|
+
const valueKeys = Object.keys(value);
|
|
64
|
+
const valueKeyCount = valueKeys.length;
|
|
65
|
+
const expectedKeyCount = expectedKeys.length;
|
|
66
|
+
// Optimization: early bail
|
|
67
|
+
if (valueKeyCount < expectedKeyCount) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This is `i` but adjusted so that `undefined` doesn't increment it.
|
|
72
|
+
* Should match index in `expectedKeys`.
|
|
73
|
+
*/
|
|
74
|
+
let definedRawKeyCount = 0;
|
|
75
|
+
for (let i = 0; i < valueKeyCount; i++) {
|
|
76
|
+
const valueKey = valueKeys[i];
|
|
77
|
+
if (value[valueKey] !== undefined) {
|
|
78
|
+
if (valueKey !== expectedKeys[definedRawKeyCount]) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
definedRawKeyCount++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Make sure there aren't any additional expected keys
|
|
85
|
+
if (definedRawKeyCount !== expectedKeyCount) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
52
91
|
default: {
|
|
53
92
|
const never = constraint;
|
|
54
93
|
throw new Error(`Unsupported constraint type '${never.type}'`);
|
|
@@ -68,5 +107,4 @@ function matchesConstraints(constraints, object) {
|
|
|
68
107
|
}
|
|
69
108
|
return true;
|
|
70
109
|
}
|
|
71
|
-
exports.matchesConstraints = matchesConstraints;
|
|
72
110
|
//# sourceMappingURL=constraints.js.map
|
package/dist/deferred.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defer =
|
|
3
|
+
exports.defer = defer;
|
|
4
4
|
function NOOP() { }
|
|
5
5
|
/**
|
|
6
6
|
* Returns a promise that can be `.resolve()`-ed or `.reject()`-ed at a later
|
|
@@ -21,5 +21,4 @@ function defer() {
|
|
|
21
21
|
promise.then(null, NOOP);
|
|
22
22
|
return promise;
|
|
23
23
|
}
|
|
24
|
-
exports.defer = defer;
|
|
25
24
|
//# sourceMappingURL=deferred.js.map
|
package/dist/dev.d.ts
CHANGED
package/dist/dev.js
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isTest = exports.isDev = void 0;
|
|
4
|
+
exports.noop = noop;
|
|
4
5
|
/**
|
|
5
6
|
* @internal
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
const graphileEnv = typeof process !== "undefined" ? process.env.GRAPHILE_ENV : undefined;
|
|
9
|
+
const nodeEnv = typeof process !== "undefined" ? process.env.NODE_ENV : undefined;
|
|
10
|
+
const mode = graphileEnv !== undefined ? graphileEnv : nodeEnv;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
exports.isDev = mode === "development" || mode === "test";
|
|
15
|
+
exports.isTest = mode === "test";
|
|
8
16
|
function noop() { }
|
|
9
|
-
|
|
17
|
+
if (typeof process !== "undefined" &&
|
|
18
|
+
typeof graphileEnv === "undefined" &&
|
|
19
|
+
typeof nodeEnv === "undefined") {
|
|
20
|
+
console.warn(`The GRAPHILE_ENV environmental variable is not set; Grafast will run in production mode. In your development environments, it's recommended that you set \`GRAPHILE_ENV=development\` to opt in to additional checks that will provide guidance and help you to catch issues in your code earlier, and other changes such as formatting to improve your development experience.`);
|
|
21
|
+
}
|
|
22
|
+
else if (exports.isDev && !exports.isTest && typeof graphileEnv === "undefined") {
|
|
23
|
+
console.warn(`Grafast is running in development mode due to \`NODE_ENV=${nodeEnv}\`; this is recommended for development environments (and strongly discouraged in production), but will impact on performance - in particular, planning will be significantly more expensive. To remove this warning, make this explicit with \`GRAPHILE_ENV=development\` envvar.`);
|
|
24
|
+
}
|
|
10
25
|
//# sourceMappingURL=dev.js.map
|