grafast 0.1.1-beta.2 → 0.1.1-beta.20
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 -37
- 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 +40 -1
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +17 -2
- package/dist/engine/LayerPlan.d.ts +2 -96
- package/dist/engine/LayerPlan.js +191 -68
- package/dist/engine/OperationPlan.d.ts +21 -94
- package/dist/engine/OperationPlan.js +570 -342
- package/dist/engine/OutputPlan.d.ts +6 -17
- package/dist/engine/OutputPlan.js +423 -438
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +85 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +591 -230
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +6 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +5 -1
- 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 +49 -38
- package/dist/establishOperationPlan.js +55 -39
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +29 -12
- package/dist/exportAs.d.ts +1 -18
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +33 -13
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +63 -1
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +20 -8
- package/dist/index.d.ts +27 -16
- package/dist/index.js +53 -5
- package/dist/input.d.ts +1 -9
- package/dist/inspect.d.ts +2 -1
- package/dist/inspect.js +1 -1
- package/dist/interfaces.d.ts +146 -22
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +5 -2
- package/dist/makeGrafastSchema.js +318 -132
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +85 -12
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +25 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +55 -0
- package/dist/operationPlan-input.js +64 -24
- package/dist/planJSONInterfaces.d.ts +6 -0
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +94 -68
- package/dist/step.d.ts +66 -88
- package/dist/step.js +180 -73
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +258 -0
- package/dist/steps/__inputDynamicScalar.d.ts +2 -2
- package/dist/steps/__inputObject.d.ts +3 -2
- package/dist/steps/__inputObject.js +36 -0
- package/dist/steps/__item.d.ts +6 -8
- package/dist/steps/__item.js +7 -1
- package/dist/steps/__trackedValue.d.ts +11 -14
- package/dist/steps/__trackedValue.js +45 -2
- package/dist/steps/__value.d.ts +2 -1
- package/dist/steps/__value.js +2 -2
- package/dist/steps/access.d.ts +4 -5
- package/dist/steps/access.js +37 -11
- package/dist/steps/applyTransforms.d.ts +0 -23
- package/dist/steps/applyTransforms.js +47 -27
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +24 -13
- package/dist/steps/connection.js +46 -9
- package/dist/steps/constant.d.ts +6 -2
- package/dist/steps/constant.js +32 -1
- package/dist/steps/each.js +1 -1
- package/dist/steps/error.d.ts +2 -2
- package/dist/steps/error.js +4 -3
- package/dist/steps/first.d.ts +4 -4
- package/dist/steps/first.js +4 -9
- package/dist/steps/graphqlResolver.d.ts +2 -75
- package/dist/steps/graphqlResolver.js +59 -30
- package/dist/steps/index.d.ts +9 -2
- package/dist/steps/index.js +32 -2
- package/dist/steps/lambda.d.ts +4 -4
- package/dist/steps/lambda.js +14 -5
- package/dist/steps/last.d.ts +3 -3
- package/dist/steps/last.js +2 -2
- package/dist/steps/list.d.ts +16 -5
- package/dist/steps/list.js +53 -10
- package/dist/steps/listTransform.d.ts +5 -11
- package/dist/steps/listTransform.js +45 -21
- package/dist/steps/listen.d.ts +3 -6
- package/dist/steps/listen.js +8 -10
- package/dist/steps/load.d.ts +38 -29
- package/dist/steps/load.js +53 -20
- package/dist/steps/node.d.ts +3 -2
- package/dist/steps/node.js +6 -1
- package/dist/steps/object.d.ts +23 -17
- package/dist/steps/object.js +48 -27
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +3 -4
- package/dist/steps/proxy.js +5 -2
- package/dist/steps/remapKeys.d.ts +4 -4
- package/dist/steps/remapKeys.js +11 -4
- package/dist/steps/reverse.d.ts +3 -3
- package/dist/steps/reverse.js +6 -3
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +23 -7
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/utils.d.ts +14 -25
- package/dist/utils.js +89 -5
- 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,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hookArgs = void 0;
|
|
4
|
-
const config_js_1 = require("./config.js");
|
|
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
|
-
|
|
42
|
+
if (middleware != null) {
|
|
43
|
+
return middleware.run("prepareArgs", { args }, finalizeWithEvent);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return finalize(args);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.hookArgs = hookArgs;
|
|
50
|
+
function finalize(args) {
|
|
51
|
+
const userContext = args.resolvedPreset?.grafast?.context;
|
|
52
|
+
const contextValue = args.contextValue;
|
|
53
|
+
if (typeof userContext === "function") {
|
|
54
|
+
const result = userContext(args.requestContext ?? EMPTY_OBJECT, args);
|
|
55
|
+
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
56
|
+
// Deliberately shadowed 'result'
|
|
57
|
+
return result.then((result) => {
|
|
58
|
+
Object.assign(contextValue, result);
|
|
36
59
|
return args;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (typeof userContext === "object" && userContext !== null) {
|
|
40
|
-
Object.assign(args.contextValue, userContext);
|
|
41
|
-
return args;
|
|
60
|
+
});
|
|
42
61
|
}
|
|
43
62
|
else {
|
|
63
|
+
Object.assign(contextValue, result);
|
|
44
64
|
return args;
|
|
45
65
|
}
|
|
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
66
|
}
|
|
59
|
-
|
|
67
|
+
else if (typeof userContext === "object" && userContext !== null) {
|
|
68
|
+
Object.assign(contextValue, userContext);
|
|
69
|
+
return args;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return args;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function finalizeWithEvent(event) {
|
|
76
|
+
return finalize(event.args);
|
|
60
77
|
}
|
|
61
|
-
exports.hookArgs = hookArgs;
|
|
62
78
|
//# sourceMappingURL=args.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
|
@@ -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}'`);
|
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.noop = exports.isDev = void 0;
|
|
3
|
+
exports.noop = exports.isTest = exports.isDev = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const graphileEnv = typeof process !== "undefined" ? process.env.GRAPHILE_ENV : undefined;
|
|
8
|
+
const nodeEnv = typeof process !== "undefined" ? process.env.NODE_ENV : undefined;
|
|
9
|
+
const mode = graphileEnv !== undefined ? graphileEnv : nodeEnv;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
exports.isDev = mode === "development" || mode === "test";
|
|
14
|
+
exports.isTest = mode === "test";
|
|
8
15
|
function noop() { }
|
|
9
16
|
exports.noop = noop;
|
|
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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Bucket } from "../bucket.js";
|
|
2
|
-
import type { ExecutableStep
|
|
2
|
+
import type { ExecutableStep } from "../step";
|
|
3
3
|
import type { OperationPlan } from "./OperationPlan";
|
|
4
4
|
/** Non-branching, non-deferred */
|
|
5
5
|
export interface LayerPlanReasonRoot {
|
|
@@ -71,43 +71,6 @@ export type HasParent<A extends LayerPlanReason> = A extends any ? A extends {
|
|
|
71
71
|
parentStep: ExecutableStep;
|
|
72
72
|
} ? A : never : never;
|
|
73
73
|
export type LayerPlanReasonsWithParentStep = HasParent<LayerPlanReason>;
|
|
74
|
-
/** @internal */
|
|
75
|
-
export interface LayerPlanPhase {
|
|
76
|
-
/**
|
|
77
|
-
* If true, we should check before the layer plan executes to see if the
|
|
78
|
-
* execution has already timed out.
|
|
79
|
-
*
|
|
80
|
-
* @see {@link RequestTools.stopTime}
|
|
81
|
-
*/
|
|
82
|
-
checkTimeout: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* A list of steps that can be ran in parallel at this point, since all
|
|
85
|
-
* their previous dependencies have already been satisfied.
|
|
86
|
-
*/
|
|
87
|
-
normalSteps: Array<{
|
|
88
|
-
step: ExecutableStep;
|
|
89
|
-
}> | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* A list of 'isSyncAndSafe' steps with unbatchedExecute methods that can be
|
|
92
|
-
* ran once the `normalSteps` have completed; they must only depend on steps
|
|
93
|
-
* that have already been executed before them (including previous
|
|
94
|
-
* unbatchedSyncAndSafeSteps in the same list).
|
|
95
|
-
*/
|
|
96
|
-
unbatchedSyncAndSafeSteps: Array<{
|
|
97
|
-
step: UnbatchedExecutableStep;
|
|
98
|
-
/**
|
|
99
|
-
* Store the result of the step here if you want - useful to avoid lookups
|
|
100
|
-
* and when there's no storage. HIGHLY VOLATILE, will not survive a tick!
|
|
101
|
-
*/
|
|
102
|
-
scratchpad: any;
|
|
103
|
-
}> | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* Optimization - a digest of all steps in normalSteps and unbatchedSyncAndSafeSteps
|
|
106
|
-
*
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
_allSteps: ExecutableStep[];
|
|
110
|
-
}
|
|
111
74
|
/**
|
|
112
75
|
* A LayerPlan represents (via "reason") either the root (root), when something
|
|
113
76
|
* happens at a later time (mutationField, defer), when plurality changes
|
|
@@ -138,58 +101,6 @@ export declare class LayerPlan<TReason extends LayerPlanReason = LayerPlanReason
|
|
|
138
101
|
parentLayerPlan: LayerPlan | null;
|
|
139
102
|
readonly reason: TReason;
|
|
140
103
|
id: number;
|
|
141
|
-
/**
|
|
142
|
-
* Every layer plan has a "root step" that shapes the value the layer
|
|
143
|
-
* returns. Note that this step may be dependent on other steps included in
|
|
144
|
-
* the LayerPlan, or could be provided externally.
|
|
145
|
-
*
|
|
146
|
-
* The root step is different for different layer step reasons:
|
|
147
|
-
*
|
|
148
|
-
* - root: the `operationPlan.rootValue`
|
|
149
|
-
* - listItem: the `__ItemStep`
|
|
150
|
-
* - stream: also the `__ItemStep`
|
|
151
|
-
* - subscription: also the `__ItemStep`
|
|
152
|
-
* - mutationField: the result plan of the mutation field
|
|
153
|
-
* - defer: the parent layer's rootStep (defer always results in an object, unless an error occurs)
|
|
154
|
-
* - polymorphic: the plan for the particular type
|
|
155
|
-
* - subroutine: the result (returned) plan of the subroutine
|
|
156
|
-
*
|
|
157
|
-
* @internal
|
|
158
|
-
*/
|
|
159
|
-
readonly rootStep: ExecutableStep | null;
|
|
160
|
-
/**
|
|
161
|
-
* Which plans the results for which are available in a parent bucket need to
|
|
162
|
-
* be "copied across" to this bucket because plans in this bucket still
|
|
163
|
-
* reference them?
|
|
164
|
-
*
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
copyStepIds: number[];
|
|
168
|
-
/** @internal */
|
|
169
|
-
children: LayerPlan[];
|
|
170
|
-
/** @internal */
|
|
171
|
-
steps: ExecutableStep[];
|
|
172
|
-
/** @internal */
|
|
173
|
-
pendingSteps: ExecutableStep[];
|
|
174
|
-
/**
|
|
175
|
-
* Describes the order in which the steps within this LayerPlan are executed.
|
|
176
|
-
*
|
|
177
|
-
* Special attention must be paid to steps that have side effects.
|
|
178
|
-
*
|
|
179
|
-
* @internal
|
|
180
|
-
*/
|
|
181
|
-
phases: Array<LayerPlanPhase>;
|
|
182
|
-
/**
|
|
183
|
-
* The list of layerPlans that steps added to this LayerPlan may depend upon.
|
|
184
|
-
* Note this includes self, so it has one more entry than `depth`.
|
|
185
|
-
*
|
|
186
|
-
* ```
|
|
187
|
-
* this.ancestry[this.depth] === this;
|
|
188
|
-
* ```
|
|
189
|
-
*
|
|
190
|
-
* @internal
|
|
191
|
-
*/
|
|
192
|
-
ancestry: LayerPlan[];
|
|
193
104
|
/** How "deep" this layer plan is (how many ancestors it has). The root layer plan has a depth of 0. */
|
|
194
105
|
depth: number;
|
|
195
106
|
/** The depth at which a "defer boundary" occurs (OperationPlan.getPeers cannot pass a defer boundary), or 0. */
|
|
@@ -202,13 +113,8 @@ export declare class LayerPlan<TReason extends LayerPlanReason = LayerPlanReason
|
|
|
202
113
|
constructor(operationPlan: OperationPlan, parentLayerPlan: LayerPlan | null, reason: TReason);
|
|
203
114
|
toString(): string;
|
|
204
115
|
print(depth?: number): string;
|
|
116
|
+
_hasSetRootStep: boolean;
|
|
205
117
|
setRootStep($root: ExecutableStep): void;
|
|
206
|
-
/** @internal Use plan.getStep(id) instead. */
|
|
207
|
-
getStep(id: number, requestingStep: ExecutableStep): ExecutableStep;
|
|
208
|
-
/** @internal */
|
|
209
|
-
_addStep(step: ExecutableStep): number;
|
|
210
|
-
/** @internal */
|
|
211
|
-
_addModifierStep(step: ModifierStep<any>): string;
|
|
212
118
|
finalize(): void;
|
|
213
119
|
newBucket(parentBucket: Bucket): Bucket | null;
|
|
214
120
|
}
|