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.
- package/README.md +1 -2
- package/dist/args.js +62 -0
- package/dist/assert.js +24 -0
- package/dist/bucket.js +4 -0
- package/dist/config.js +99 -0
- package/dist/constraints.js +72 -0
- package/dist/deferred.js +25 -0
- package/dist/dev.js +10 -0
- package/dist/engine/LayerPlan.js +536 -0
- package/dist/engine/OperationPlan.js +2543 -0
- package/dist/engine/OutputPlan.js +1059 -0
- package/dist/engine/StepTracker.js +524 -0
- package/dist/engine/executeBucket.js +700 -0
- package/dist/engine/executeOutputPlan.js +21 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +36 -0
- package/dist/envelop.js +73 -5
- package/dist/error.js +62 -0
- package/dist/establishOperationPlan.js +186 -0
- package/dist/execute.js +80 -0
- package/dist/exportAs.js +57 -0
- package/dist/global.js +13 -0
- package/dist/grafastGraphql.js +133 -0
- package/dist/grafastPrint.js +177 -0
- package/dist/graphqlCollectFields.js +217 -0
- package/dist/graphqlMergeSelectionSets.js +60 -0
- package/dist/index.d.ts +161 -2
- package/dist/index.js +255 -499
- package/dist/input.js +159 -0
- package/dist/inspect.js +20 -0
- package/dist/interfaces.d.ts +3 -160
- package/dist/interfaces.js +63 -0
- package/dist/makeGrafastSchema.js +174 -0
- package/dist/mermaid.js +290 -7
- package/dist/operationPlan-input.js +449 -0
- package/dist/planJSONInterfaces.js +3 -0
- package/dist/polymorphic.js +73 -0
- package/dist/prepare.js +763 -0
- package/dist/step.js +396 -0
- package/dist/steps/__inputDynamicScalar.js +125 -0
- package/dist/steps/__inputList.js +110 -0
- package/dist/steps/__inputObject.js +128 -0
- package/dist/steps/__inputStaticLeaf.js +43 -0
- package/dist/steps/__item.js +50 -0
- package/dist/steps/__trackedValue.js +257 -0
- package/dist/steps/__value.js +47 -0
- package/dist/steps/access.js +183 -0
- package/dist/steps/applyTransforms.js +151 -0
- package/dist/steps/connection.js +315 -0
- package/dist/steps/constant.js +72 -0
- package/dist/steps/each.js +64 -0
- package/dist/steps/error.js +32 -0
- package/dist/steps/filter.js +32 -0
- package/dist/steps/first.js +49 -0
- package/dist/steps/graphqlResolver.js +260 -0
- package/dist/steps/groupBy.js +40 -0
- package/dist/steps/index.js +117 -0
- package/dist/steps/lambda.js +58 -0
- package/dist/steps/last.js +41 -0
- package/dist/steps/list.js +75 -0
- package/dist/steps/listTransform.js +185 -0
- package/dist/steps/listen.js +61 -0
- package/dist/steps/load.d.ts +4 -4
- package/dist/steps/load.js +310 -0
- package/dist/steps/node.d.ts +6 -6
- package/dist/steps/node.js +107 -0
- package/dist/steps/object.js +195 -0
- package/dist/steps/partitionByIndex.js +86 -0
- package/dist/steps/proxy.js +114 -0
- package/dist/steps/remapKeys.js +84 -0
- package/dist/steps/reverse.js +52 -0
- package/dist/steps/setter.js +28 -0
- package/dist/stringifyPayload.js +59 -0
- package/dist/stripAnsi.js +14 -0
- package/dist/subscribe.js +14 -0
- package/dist/thereCanBeOnlyOne.js +21 -0
- package/dist/timeSource.js +8 -0
- package/dist/utils.js +698 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +6 -0
- package/package.json +9 -4
- package/dist/LICENSES.txt +0 -300
package/README.md
CHANGED
|
@@ -52,9 +52,8 @@ And please give some love to our featured sponsors 🤩:
|
|
|
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
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
|
-
<td align="center"><a href=""><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
|
|
56
|
-
</tr><tr>
|
|
57
55
|
<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>
|
|
56
|
+
</tr><tr>
|
|
58
57
|
<td align="center"><a href="https://www.accenture.com/"><img src="https://graphile.org/images/sponsors/accenture.svg" width="90" height="90" alt="Accenture" /><br />Accenture</a> *</td>
|
|
59
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>
|
|
60
59
|
</tr></table>
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookArgs = void 0;
|
|
4
|
+
const config_js_1 = require("./config.js");
|
|
5
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Applies Graphile Config hooks to your GraphQL request, e.g. to
|
|
9
|
+
* populate context or similar.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
function hookArgs(rawArgs, resolvedPreset, ctx) {
|
|
14
|
+
const args = rawArgs;
|
|
15
|
+
// Assert that args haven't already been hooked
|
|
16
|
+
if (args[interfaces_js_1.$$hooked]) {
|
|
17
|
+
throw new Error("Must not call hookArgs twice!");
|
|
18
|
+
}
|
|
19
|
+
args[interfaces_js_1.$$hooked] = true;
|
|
20
|
+
// Make context mutable
|
|
21
|
+
args.contextValue = Object.assign(Object.create(null), args.contextValue);
|
|
22
|
+
// finalize(args): args is deliberately shadowed
|
|
23
|
+
const finalize = (args) => {
|
|
24
|
+
const userContext = resolvedPreset.grafast?.context;
|
|
25
|
+
if (typeof userContext === "function") {
|
|
26
|
+
const result = userContext(ctx, args);
|
|
27
|
+
if ((0, utils_js_1.isPromiseLike)(result)) {
|
|
28
|
+
// Deliberately shadowed 'result'
|
|
29
|
+
return result.then((result) => {
|
|
30
|
+
Object.assign(args.contextValue, result);
|
|
31
|
+
return args;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Object.assign(args.contextValue, result);
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (typeof userContext === "object" && userContext !== null) {
|
|
40
|
+
Object.assign(args.contextValue, userContext);
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
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
|
+
}
|
|
59
|
+
return finalize(args);
|
|
60
|
+
}
|
|
61
|
+
exports.hookArgs = hookArgs;
|
|
62
|
+
//# sourceMappingURL=args.js.map
|
package/dist/assert.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Due to the following Jest issue, GraphQL's `instanceof Error` test
|
|
4
|
+
* cannot pass for Node assertions. So we have to define our own.
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/facebook/jest/issues/2549
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.strictEqual = exports.ok = void 0;
|
|
10
|
+
/** Equivalent to `assert.ok(...)` */
|
|
11
|
+
function ok(val, message) {
|
|
12
|
+
if (!val) {
|
|
13
|
+
throw new Error(message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ok = ok;
|
|
17
|
+
/** Equivalent to `assert.strictEqual(...)` */
|
|
18
|
+
function strictEqual(actual, expected, message) {
|
|
19
|
+
if (actual !== expected) {
|
|
20
|
+
throw new Error(message + ` (${actual} !== ${expected})`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.strictEqual = strictEqual;
|
|
24
|
+
//# sourceMappingURL=assert.js.map
|
package/dist/bucket.js
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hook = exports.withHooks = exports.withGraphileConfig = exports.NULL_PRESET = void 0;
|
|
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
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// PERF: optimise constraint matching, e.g. by collapsing redundant constraints
|
|
3
|
+
// and then compiling (JIT-style) remaining constraints into a function using
|
|
4
|
+
// tamedevil
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.matchesConstraints = void 0;
|
|
7
|
+
function valueAtPath(object, path) {
|
|
8
|
+
let value = object;
|
|
9
|
+
for (let i = 0, l = path.length; i < l; i++) {
|
|
10
|
+
const key = path[i];
|
|
11
|
+
const expectArray = typeof key === "number";
|
|
12
|
+
const isArray = Array.isArray(value);
|
|
13
|
+
if (expectArray !== isArray) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (value == null) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
value = value[key];
|
|
21
|
+
if (typeof value === "undefined") {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Implements the `MatchesConstraint` algorithm.
|
|
30
|
+
*/
|
|
31
|
+
function matchesConstraint(constraint, object) {
|
|
32
|
+
const value = valueAtPath(object, constraint.path);
|
|
33
|
+
switch (constraint.type) {
|
|
34
|
+
case "length": {
|
|
35
|
+
return Array.isArray(value) && value.length === constraint.expectedLength;
|
|
36
|
+
}
|
|
37
|
+
case "exists": {
|
|
38
|
+
return (value !== undefined) === constraint.exists;
|
|
39
|
+
}
|
|
40
|
+
case "equal": {
|
|
41
|
+
return (value === constraint.expectedValue) === constraint.pass;
|
|
42
|
+
}
|
|
43
|
+
case "value": {
|
|
44
|
+
return value === constraint.value;
|
|
45
|
+
}
|
|
46
|
+
case "isEmpty": {
|
|
47
|
+
const isEmpty = typeof value === "object" &&
|
|
48
|
+
value !== null &&
|
|
49
|
+
Object.keys(value).length === 0;
|
|
50
|
+
return isEmpty === constraint.isEmpty;
|
|
51
|
+
}
|
|
52
|
+
default: {
|
|
53
|
+
const never = constraint;
|
|
54
|
+
throw new Error(`Unsupported constraint type '${never.type}'`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Implements the `MatchesConstraints` algorithm.
|
|
60
|
+
*/
|
|
61
|
+
function matchesConstraints(constraints, object) {
|
|
62
|
+
// In my testing, verbose loops are still about 20% faster than for...of
|
|
63
|
+
for (let i = 0, l = constraints.length; i < l; i++) {
|
|
64
|
+
const constraint = constraints[i];
|
|
65
|
+
if (!matchesConstraint(constraint, object)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
exports.matchesConstraints = matchesConstraints;
|
|
72
|
+
//# sourceMappingURL=constraints.js.map
|
package/dist/deferred.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defer = void 0;
|
|
4
|
+
function NOOP() { }
|
|
5
|
+
/**
|
|
6
|
+
* Returns a promise that can be `.resolve()`-ed or `.reject()`-ed at a later
|
|
7
|
+
* time.
|
|
8
|
+
*/
|
|
9
|
+
function defer() {
|
|
10
|
+
let resolve;
|
|
11
|
+
let reject;
|
|
12
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
13
|
+
resolve = _resolve;
|
|
14
|
+
reject = _reject;
|
|
15
|
+
});
|
|
16
|
+
promise.resolve = resolve;
|
|
17
|
+
promise.reject = reject;
|
|
18
|
+
// PERF: this is to avoid unhandledPromiseRejection errors; generally
|
|
19
|
+
// deferred errors are handled at a later time (or can be safely ignored if
|
|
20
|
+
// another error wins). Maybe there's a better way?
|
|
21
|
+
promise.then(null, NOOP);
|
|
22
|
+
return promise;
|
|
23
|
+
}
|
|
24
|
+
exports.defer = defer;
|
|
25
|
+
//# sourceMappingURL=deferred.js.map
|
package/dist/dev.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noop = exports.isDev = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
exports.isDev = typeof process !== "undefined" && process.env.GRAPHILE_ENV === "development";
|
|
8
|
+
function noop() { }
|
|
9
|
+
exports.noop = noop;
|
|
10
|
+
//# sourceMappingURL=dev.js.map
|