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/dist/steps/node.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { GraphQLObjectType } from "graphql";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
2
|
+
import type { Maybe, NodeIdHandler, PolymorphicData, UnbatchedExecutionExtra } from "../interfaces.js";
|
|
3
|
+
import type { PolymorphicStep, Step } from "../step.js";
|
|
4
|
+
import { UnbatchedStep } from "../step.js";
|
|
5
5
|
/**
|
|
6
6
|
* A plan to get a Node by its global object identifier (string). Accepts an
|
|
7
7
|
* object specifying the supported codecs, an object map detailing the
|
|
8
8
|
* typeNames supported and their details (codec to use, how to find the record,
|
|
9
9
|
* etc), and finally the Node id string plan.
|
|
10
10
|
*/
|
|
11
|
-
export declare class NodeStep extends
|
|
11
|
+
export declare class NodeStep extends UnbatchedStep implements PolymorphicStep {
|
|
12
12
|
private possibleTypes;
|
|
13
13
|
static $$export: {
|
|
14
14
|
moduleName: string;
|
|
@@ -19,10 +19,10 @@ export declare class NodeStep extends UnbatchedExecutableStep implements Polymor
|
|
|
19
19
|
private specPlanDep;
|
|
20
20
|
constructor(possibleTypes: {
|
|
21
21
|
[typeName: string]: NodeIdHandler;
|
|
22
|
-
}, $id:
|
|
23
|
-
planForType(type: GraphQLObjectType):
|
|
22
|
+
}, $id: Step<string | null | undefined>);
|
|
23
|
+
planForType(type: GraphQLObjectType): Step;
|
|
24
24
|
private getTypeNameFromSpecifier;
|
|
25
|
-
unbatchedExecute: (_extra:
|
|
25
|
+
unbatchedExecute: (_extra: UnbatchedExecutionExtra, specifier: any) => PolymorphicData<string, ReadonlyArray<any>> | null;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* A plan to get a Node by its global object identifier (string). Accepts an
|
|
@@ -32,9 +32,16 @@ export declare class NodeStep extends UnbatchedExecutableStep implements Polymor
|
|
|
32
32
|
*/
|
|
33
33
|
export declare function node(possibleTypes: {
|
|
34
34
|
[typeName: string]: NodeIdHandler;
|
|
35
|
-
}, $id:
|
|
36
|
-
export declare function specFromNodeId(handler: NodeIdHandler<any>, $id:
|
|
37
|
-
export declare function
|
|
35
|
+
}, $id: Step<string | null | undefined>): NodeStep;
|
|
36
|
+
export declare function specFromNodeId(handler: NodeIdHandler<any>, $id: Step<Maybe<string>>): any;
|
|
37
|
+
export declare function nodeIdFromNode(handler: NodeIdHandler<any>, $node: Step): import("./lambda.js").LambdaStep<any, string | null>;
|
|
38
|
+
export declare function makeDecodeNodeIdRuntime(handlers: readonly NodeIdHandler[]): {
|
|
39
|
+
(raw: string | null | undefined): {
|
|
40
|
+
[codecName: string]: any;
|
|
41
|
+
} | null;
|
|
42
|
+
isSyncAndSafe: boolean;
|
|
43
|
+
};
|
|
44
|
+
export declare function makeDecodeNodeId(handlers: readonly NodeIdHandler[]): ($id: Step<string | null | undefined>) => import("./lambda.js").LambdaStep<string | null | undefined, {
|
|
38
45
|
[codecName: string]: any;
|
|
39
46
|
} | null>;
|
|
40
47
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/steps/node.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NodeStep = void 0;
|
|
4
|
+
exports.node = node;
|
|
5
|
+
exports.specFromNodeId = specFromNodeId;
|
|
6
|
+
exports.nodeIdFromNode = nodeIdFromNode;
|
|
7
|
+
exports.makeDecodeNodeIdRuntime = makeDecodeNodeIdRuntime;
|
|
8
|
+
exports.makeDecodeNodeId = makeDecodeNodeId;
|
|
4
9
|
const dev_js_1 = require("../dev.js");
|
|
5
10
|
const inspect_js_1 = require("../inspect.js");
|
|
6
11
|
const polymorphic_js_1 = require("../polymorphic.js");
|
|
@@ -14,7 +19,7 @@ const lambda_js_1 = require("./lambda.js");
|
|
|
14
19
|
* typeNames supported and their details (codec to use, how to find the record,
|
|
15
20
|
* etc), and finally the Node id string plan.
|
|
16
21
|
*/
|
|
17
|
-
class NodeStep extends step_js_1.
|
|
22
|
+
class NodeStep extends step_js_1.UnbatchedStep {
|
|
18
23
|
static { this.$$export = {
|
|
19
24
|
moduleName: "grafast",
|
|
20
25
|
exportName: "NodeStep",
|
|
@@ -65,9 +70,10 @@ exports.NodeStep = NodeStep;
|
|
|
65
70
|
function node(possibleTypes, $id) {
|
|
66
71
|
return new NodeStep(possibleTypes, $id);
|
|
67
72
|
}
|
|
68
|
-
exports.node = node;
|
|
69
73
|
function specFromNodeId(handler, $id) {
|
|
70
74
|
function decodeWithCodecAndHandler(raw) {
|
|
75
|
+
if (raw == null)
|
|
76
|
+
return raw;
|
|
71
77
|
try {
|
|
72
78
|
const decoded = handler.codec.decode(raw);
|
|
73
79
|
if (handler.match(decoded)) {
|
|
@@ -84,8 +90,11 @@ function specFromNodeId(handler, $id) {
|
|
|
84
90
|
const $decoded = (0, lambda_js_1.lambda)($id, decodeWithCodecAndHandler);
|
|
85
91
|
return handler.getSpec($decoded);
|
|
86
92
|
}
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
function nodeIdFromNode(handler, $node) {
|
|
94
|
+
const specifier = handler.plan($node);
|
|
95
|
+
return (0, lambda_js_1.lambda)(specifier, handler.codec.encode);
|
|
96
|
+
}
|
|
97
|
+
function makeDecodeNodeIdRuntime(handlers) {
|
|
89
98
|
const codecs = [...new Set(handlers.map((h) => h.codec))];
|
|
90
99
|
function decodeNodeIdWithCodecs(raw) {
|
|
91
100
|
if (raw == null)
|
|
@@ -101,7 +110,10 @@ function makeDecodeNodeId(handlers) {
|
|
|
101
110
|
}, { raw });
|
|
102
111
|
}
|
|
103
112
|
decodeNodeIdWithCodecs.isSyncAndSafe = true; // Optimization
|
|
113
|
+
return decodeNodeIdWithCodecs;
|
|
114
|
+
}
|
|
115
|
+
function makeDecodeNodeId(handlers) {
|
|
116
|
+
const decodeNodeIdWithCodecs = makeDecodeNodeIdRuntime(handlers);
|
|
104
117
|
return ($id) => (0, lambda_js_1.lambda)($id, decodeNodeIdWithCodecs);
|
|
105
118
|
}
|
|
106
|
-
exports.makeDecodeNodeId = makeDecodeNodeId;
|
|
107
119
|
//# sourceMappingURL=node.js.map
|
package/dist/steps/object.d.ts
CHANGED
|
@@ -1,56 +1,62 @@
|
|
|
1
|
-
import type { ExecutionExtra, StepOptimizeOptions } from "../interfaces.js";
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import type { DataFromStep, ExecutionDetails, ExecutionExtra, StepOptimizeOptions, UnbatchedExecutionExtra } from "../interfaces.js";
|
|
2
|
+
import type { Step } from "../step.js";
|
|
3
|
+
import { UnbatchedStep } from "../step.js";
|
|
4
4
|
import { ConstantStep } from "./constant.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type DataFromPlans<TPlans extends {
|
|
8
|
-
[key: string]: ExecutableStep;
|
|
5
|
+
export type DataFromObjectSteps<TSteps extends {
|
|
6
|
+
[key: string]: Step;
|
|
9
7
|
}> = {
|
|
10
|
-
[key in keyof
|
|
8
|
+
[key in keyof TSteps]: DataFromStep<TSteps[key]>;
|
|
11
9
|
};
|
|
12
|
-
type Results<
|
|
13
|
-
[key: string]:
|
|
10
|
+
type Results<TSteps extends {
|
|
11
|
+
[key: string]: Step;
|
|
14
12
|
}> = Array<[
|
|
15
|
-
Array<
|
|
16
|
-
|
|
13
|
+
Array<DataFromObjectSteps<TSteps>[keyof TSteps]>,
|
|
14
|
+
DataFromObjectSteps<TSteps>
|
|
17
15
|
]>;
|
|
18
|
-
export interface ObjectPlanMeta<
|
|
19
|
-
[key: string]:
|
|
16
|
+
export interface ObjectPlanMeta<TSteps extends {
|
|
17
|
+
[key: string]: Step;
|
|
20
18
|
}> {
|
|
21
|
-
results: Results<
|
|
19
|
+
results: Results<TSteps>;
|
|
20
|
+
}
|
|
21
|
+
interface ObjectStepCacheConfig {
|
|
22
|
+
identifier?: string;
|
|
23
|
+
cacheSize?: number;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* A plan that represents an object using the keys given and the values being
|
|
25
27
|
* the results of the associated plans.
|
|
26
28
|
*/
|
|
27
29
|
export declare class ObjectStep<TPlans extends {
|
|
28
|
-
[key: string]:
|
|
30
|
+
[key: string]: Step;
|
|
29
31
|
} = {
|
|
30
|
-
[key: string]:
|
|
31
|
-
}> extends
|
|
32
|
+
[key: string]: Step;
|
|
33
|
+
}> extends UnbatchedStep<DataFromObjectSteps<TPlans>> {
|
|
34
|
+
private cacheConfig?;
|
|
32
35
|
static $$export: {
|
|
33
36
|
moduleName: string;
|
|
34
37
|
exportName: string;
|
|
35
38
|
};
|
|
36
39
|
isSyncAndSafe: boolean;
|
|
37
40
|
allowMultipleOptimizations: boolean;
|
|
38
|
-
private keys;
|
|
41
|
+
private readonly keys;
|
|
39
42
|
optimizeMetaKey: string;
|
|
40
|
-
|
|
43
|
+
private cacheSize;
|
|
44
|
+
constructor(obj: TPlans, cacheConfig?: ObjectStepCacheConfig | undefined);
|
|
45
|
+
private _setKeys;
|
|
41
46
|
/**
|
|
42
47
|
* This key doesn't get typed, but it can be added later which can be quite
|
|
43
48
|
* handy.
|
|
44
49
|
*/
|
|
45
50
|
set<TKey extends keyof TPlans>(key: TKey, plan: TPlans[TKey]): void;
|
|
46
|
-
getStepForKey<TKey extends keyof TPlans>(key: TKey
|
|
51
|
+
getStepForKey<TKey extends keyof TPlans>(key: TKey): TPlans[TKey];
|
|
52
|
+
getStepForKey<TKey extends keyof TPlans>(key: TKey, allowMissing: true): TPlans[TKey] | null;
|
|
47
53
|
toStringMeta(): string;
|
|
48
|
-
tupleToObjectJIT(callback: (fn: (extra: ExecutionExtra, ...tuple: Array<
|
|
54
|
+
tupleToObjectJIT(callback: (fn: (extra: ExecutionExtra, ...tuple: Array<DataFromObjectSteps<TPlans>[keyof TPlans]>) => DataFromObjectSteps<TPlans>) => void): void;
|
|
49
55
|
finalize(): void;
|
|
50
|
-
execute(
|
|
51
|
-
unbatchedExecute(_extra:
|
|
56
|
+
execute({ indexMap, values, extra, }: ExecutionDetails<Array<DataFromObjectSteps<TPlans>[keyof TPlans]>>): ReadonlyArray<DataFromObjectSteps<TPlans>>;
|
|
57
|
+
unbatchedExecute(_extra: UnbatchedExecutionExtra, ..._values: any[]): any;
|
|
52
58
|
deduplicate(peers: ObjectStep<any>[]): ObjectStep<TPlans>[];
|
|
53
|
-
optimize(opts: StepOptimizeOptions): this | ConstantStep<any
|
|
59
|
+
optimize(opts: StepOptimizeOptions): ConstantStep<any> | this | ConstantStep<Record<string, any>>;
|
|
54
60
|
/**
|
|
55
61
|
* Get the original plan with the given key back again.
|
|
56
62
|
*/
|
|
@@ -61,7 +67,7 @@ export declare class ObjectStep<TPlans extends {
|
|
|
61
67
|
* the results of the associated plans.
|
|
62
68
|
*/
|
|
63
69
|
export declare function object<TPlans extends {
|
|
64
|
-
[key: string]:
|
|
65
|
-
}>(obj: TPlans): ObjectStep<TPlans>;
|
|
70
|
+
[key: string]: Step;
|
|
71
|
+
}>(obj: TPlans, cacheConfig?: ObjectStepCacheConfig): ObjectStep<TPlans>;
|
|
66
72
|
export {};
|
|
67
73
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/steps/object.js
CHANGED
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// import debugFactory from "debug";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.ObjectStep = void 0;
|
|
5
|
+
exports.object = object;
|
|
5
6
|
const tslib_1 = require("tslib");
|
|
6
7
|
const tamedevil_1 = tslib_1.__importStar(require("tamedevil"));
|
|
7
8
|
const step_js_1 = require("../step.js");
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
8
10
|
const constant_js_1 = require("./constant.js");
|
|
11
|
+
const DEFAULT_CACHE_SIZE = 100;
|
|
9
12
|
const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
|
10
13
|
/**
|
|
11
14
|
* A plan that represents an object using the keys given and the values being
|
|
12
15
|
* the results of the associated plans.
|
|
13
16
|
*/
|
|
14
|
-
class ObjectStep extends step_js_1.
|
|
17
|
+
class ObjectStep extends step_js_1.UnbatchedStep {
|
|
15
18
|
static { this.$$export = {
|
|
16
19
|
moduleName: "grafast",
|
|
17
20
|
exportName: "ObjectStep",
|
|
18
21
|
}; }
|
|
19
|
-
constructor(obj) {
|
|
22
|
+
constructor(obj, cacheConfig) {
|
|
20
23
|
super();
|
|
24
|
+
this.cacheConfig = cacheConfig;
|
|
21
25
|
this.isSyncAndSafe = true;
|
|
22
26
|
this.allowMultipleOptimizations = true;
|
|
27
|
+
this.keys = [];
|
|
23
28
|
// Optimize needs the same 'meta' for all ObjectSteps
|
|
24
29
|
this.optimizeMetaKey = "ObjectStep";
|
|
25
|
-
this.
|
|
26
|
-
|
|
30
|
+
this.cacheSize =
|
|
31
|
+
cacheConfig?.cacheSize ??
|
|
32
|
+
(cacheConfig?.identifier ? DEFAULT_CACHE_SIZE : 0);
|
|
33
|
+
const keys = Object.keys(obj);
|
|
34
|
+
this._setKeys(keys);
|
|
27
35
|
for (let i = 0, l = this.keys.length; i < l; i++) {
|
|
28
|
-
this.addDependency(obj[
|
|
36
|
+
this.addDependency({ step: obj[keys[i]], skipDeduplication: true });
|
|
29
37
|
}
|
|
30
38
|
}
|
|
39
|
+
_setKeys(keys) {
|
|
40
|
+
this.keys = keys;
|
|
41
|
+
this.peerKey = (0, utils_js_1.digestKeys)(keys);
|
|
42
|
+
this.metaKey =
|
|
43
|
+
this.cacheSize <= 0
|
|
44
|
+
? undefined
|
|
45
|
+
: this.cacheConfig?.identifier
|
|
46
|
+
? `object|${this.peerKey}|${this.cacheConfig.identifier}`
|
|
47
|
+
: this.id;
|
|
48
|
+
}
|
|
31
49
|
/**
|
|
32
50
|
* This key doesn't get typed, but it can be added later which can be quite
|
|
33
51
|
* handy.
|
|
34
52
|
*/
|
|
35
53
|
set(key, plan) {
|
|
36
|
-
this.keys
|
|
37
|
-
this.addDependency(plan, true);
|
|
54
|
+
this._setKeys([...this.keys, key]);
|
|
55
|
+
this.addDependency({ step: plan, skipDeduplication: true });
|
|
38
56
|
}
|
|
39
57
|
getStepForKey(key, allowMissing = false) {
|
|
40
58
|
const idx = this.keys.indexOf(key);
|
|
@@ -44,7 +62,7 @@ class ObjectStep extends step_js_1.UnbatchedExecutableStep {
|
|
|
44
62
|
}
|
|
45
63
|
return null;
|
|
46
64
|
}
|
|
47
|
-
return this.
|
|
65
|
+
return this.getDepOptions(idx).step;
|
|
48
66
|
}
|
|
49
67
|
toStringMeta() {
|
|
50
68
|
return "{" + this.keys.join(",") + "}";
|
|
@@ -52,8 +70,8 @@ class ObjectStep extends step_js_1.UnbatchedExecutableStep {
|
|
|
52
70
|
/*
|
|
53
71
|
tupleToObject(
|
|
54
72
|
meta: ObjectPlanMeta<TPlans>,
|
|
55
|
-
...tuple: Array<
|
|
56
|
-
):
|
|
73
|
+
...tuple: Array<DataFromObjectSteps<TPlans>[keyof TPlans]>
|
|
74
|
+
): DataFromObjectSteps<TPlans> {
|
|
57
75
|
// Note: `outerloop` is a JavaScript "label". They are not very common.
|
|
58
76
|
// First look for an existing match:
|
|
59
77
|
outerloop: for (let i = 0, l = meta.results.length; i < l; i++) {
|
|
@@ -79,7 +97,7 @@ class ObjectStep extends step_js_1.UnbatchedExecutableStep {
|
|
|
79
97
|
const newObj = this.keys.reduce((memo, key, i) => {
|
|
80
98
|
memo[key] = tuple[i];
|
|
81
99
|
return memo;
|
|
82
|
-
}, {} as Partial<
|
|
100
|
+
}, {} as Partial<DataFromObjectSteps<TPlans>>) as DataFromObjectSteps<TPlans>;
|
|
83
101
|
|
|
84
102
|
// Cache newObj so the same tuple values result in the exact same object.
|
|
85
103
|
meta.results.push([tuple, newObj]);
|
|
@@ -102,9 +120,11 @@ ${tamedevil_1.default.join(this.keys.map((key, i) => (0, tamedevil_1.default) `
|
|
|
102
120
|
const newObj = Object.create(null);
|
|
103
121
|
${tamedevil_1.default.join(this.keys.map((key, i) => (0, tamedevil_1.default) ` newObj${tamedevil_1.default.set(key, true)} = ${tamedevil_1.default.identifier(`val${i}`)};\n`), "")}\
|
|
104
122
|
`;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
123
|
+
const vals = tamedevil_1.default.join(this.keys.map((_k, i) => tamedevil_1.default.identifier(`val${i}`)), ", ");
|
|
124
|
+
if (this.cacheSize > 0) {
|
|
125
|
+
return tamedevil_1.default.runInBatch((0, tamedevil_1.default) `\
|
|
126
|
+
(function ({ meta }, ${vals}) {
|
|
127
|
+
if (meta.nextIndex != null) {
|
|
108
128
|
for (let i = 0, l = meta.results.length; i < l; i++) {
|
|
109
129
|
const [values, obj] = meta.results[i];
|
|
110
130
|
if (${tamedevil_1.default.join(this.keys.map((_key, i) => (0, tamedevil_1.default) `values[${tamedevil_1.default.lit(i)}] === ${tamedevil_1.default.identifier(`val${i}`)}`), " && ")}) {
|
|
@@ -113,16 +133,22 @@ ${tamedevil_1.default.join(this.keys.map((key, i) => (0, tamedevil_1.default) `
|
|
|
113
133
|
}
|
|
114
134
|
} else {
|
|
115
135
|
meta.nextIndex = 0;
|
|
116
|
-
|
|
117
|
-
meta.results = [];
|
|
118
|
-
}
|
|
136
|
+
meta.results = [];
|
|
119
137
|
}
|
|
120
138
|
${inner}
|
|
121
139
|
meta.results[meta.nextIndex] = [[${tamedevil_1.default.join(this.keys.map((_key, i) => tamedevil_1.default.identifier(`val${i}`)), ",")}], newObj];
|
|
122
|
-
// Only cache
|
|
123
|
-
meta.nextIndex = meta.nextIndex ===
|
|
140
|
+
// Only cache ${tamedevil_1.default.lit(this.cacheSize)} results, use a round-robin
|
|
141
|
+
meta.nextIndex = meta.nextIndex === ${tamedevil_1.default.lit(this.cacheSize - 1)} ? 0 : meta.nextIndex + 1;
|
|
142
|
+
return newObj;
|
|
143
|
+
})`, callback);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return tamedevil_1.default.runInBatch((0, tamedevil_1.default) `\
|
|
147
|
+
(function (_, ${vals}) {
|
|
148
|
+
${inner}
|
|
124
149
|
return newObj;
|
|
125
150
|
})`, callback);
|
|
151
|
+
}
|
|
126
152
|
}
|
|
127
153
|
finalize() {
|
|
128
154
|
this.tupleToObjectJIT((fn) => {
|
|
@@ -130,19 +156,15 @@ ${inner}
|
|
|
130
156
|
});
|
|
131
157
|
return super.finalize();
|
|
132
158
|
}
|
|
133
|
-
execute(
|
|
134
|
-
|
|
135
|
-
for (let i = 0; i < count; i++) {
|
|
136
|
-
result[i] = this.unbatchedExecute(extra, ...values.map((v) => v[i]));
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
159
|
+
execute({ indexMap, values, extra, }) {
|
|
160
|
+
return indexMap((i) => this.unbatchedExecute(extra, ...values.map((v) => v.at(i))));
|
|
139
161
|
}
|
|
140
162
|
unbatchedExecute(_extra, ..._values) {
|
|
141
163
|
throw new Error(`${this} didn't finalize? No unbatchedExecute method.`);
|
|
142
164
|
}
|
|
143
165
|
deduplicate(peers) {
|
|
144
|
-
|
|
145
|
-
return peers
|
|
166
|
+
// Managed through peerKey
|
|
167
|
+
return peers;
|
|
146
168
|
}
|
|
147
169
|
optimize(opts) {
|
|
148
170
|
if (this.dependencies.every((dep) => dep instanceof constant_js_1.ConstantStep)) {
|
|
@@ -180,7 +202,7 @@ ${inner}
|
|
|
180
202
|
if (index < 0) {
|
|
181
203
|
throw new Error(`This ObjectStep doesn't have key '${String(key)}'; supported keys: '${this.keys.join("', '")}'`);
|
|
182
204
|
}
|
|
183
|
-
return this.
|
|
205
|
+
return this.getDepOptions(index).step;
|
|
184
206
|
}
|
|
185
207
|
}
|
|
186
208
|
exports.ObjectStep = ObjectStep;
|
|
@@ -188,8 +210,7 @@ exports.ObjectStep = ObjectStep;
|
|
|
188
210
|
* A plan that represents an object using the keys given and the values being
|
|
189
211
|
* the results of the associated plans.
|
|
190
212
|
*/
|
|
191
|
-
function object(obj) {
|
|
192
|
-
return new ObjectStep(obj);
|
|
213
|
+
function object(obj, cacheConfig) {
|
|
214
|
+
return new ObjectStep(obj, cacheConfig);
|
|
193
215
|
}
|
|
194
|
-
exports.object = object;
|
|
195
216
|
//# sourceMappingURL=object.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Step } from "../step.js";
|
|
2
|
+
import type { ConnectionCapableStep, ItemsStep } from "./connection.js";
|
|
2
3
|
import type { __ListTransformStep, ListTransformItemPlanCallback } from "./listTransform.js";
|
|
3
4
|
/**
|
|
4
5
|
* Takes a single dimensional list plan and a mapper that calculates a
|
|
@@ -35,5 +36,5 @@ import type { __ListTransformStep, ListTransformItemPlanCallback } from "./listT
|
|
|
35
36
|
*
|
|
36
37
|
* Beware: the target indexes should not contain gaps.
|
|
37
38
|
*/
|
|
38
|
-
export declare function partitionByIndex<TListStep extends
|
|
39
|
+
export declare function partitionByIndex<TListStep extends Step<readonly any[]> | ConnectionCapableStep<any, any>, TItemStep extends Step<number>>(listStep: TListStep, mapper: ListTransformItemPlanCallback<ItemsStep<TListStep>, TItemStep>, startIndex?: 0 | 1): __ListTransformStep<TListStep, TItemStep, unknown[][], any>;
|
|
39
40
|
//# sourceMappingURL=partitionByIndex.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.partitionByIndex =
|
|
3
|
+
exports.partitionByIndex = partitionByIndex;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
6
|
const step_js_1 = require("../step.js");
|
|
@@ -82,5 +82,4 @@ function partitionByIndex(listStep, mapper, startIndex = 0) {
|
|
|
82
82
|
meta: `partitionByIndex${startIndex}:${chalk_1.default.yellow(listStep.id)}${mapper.name ? `/${mapper.name}` : ""}`,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
exports.partitionByIndex = partitionByIndex;
|
|
86
85
|
//# sourceMappingURL=partitionByIndex.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GraphQLObjectType } from "graphql";
|
|
2
|
+
import type { ExecutionDetails, GrafastResultsList, PromiseOrDirect } from "../index.js";
|
|
3
|
+
import type { PolymorphicStep } from "../step.js";
|
|
4
|
+
import { Step } from "../step.js";
|
|
5
|
+
type StepData<TStep extends Step> = TStep extends Step<infer U> ? U : any;
|
|
6
|
+
export interface PolymorphicBranchMatchers<TStep extends Step> {
|
|
7
|
+
[typeName: string]: PolymorphicBranchMatcher<TStep>;
|
|
8
|
+
}
|
|
9
|
+
export interface PolymorphicBranchMatcher<TStep extends Step> {
|
|
10
|
+
match?: (obj: StepData<TStep>) => boolean;
|
|
11
|
+
plan?: ($obj: TStep) => Step;
|
|
12
|
+
}
|
|
13
|
+
export declare class PolymorphicBranchStep<TStep extends Step> extends Step implements PolymorphicStep {
|
|
14
|
+
static $$export: {
|
|
15
|
+
moduleName: string;
|
|
16
|
+
exportName: string;
|
|
17
|
+
};
|
|
18
|
+
isSyncAndSafe: boolean;
|
|
19
|
+
private typeNames;
|
|
20
|
+
private matchers;
|
|
21
|
+
constructor($step: TStep, matchers: PolymorphicBranchMatchers<TStep>);
|
|
22
|
+
planForType(objectType: GraphQLObjectType): Step;
|
|
23
|
+
execute({ indexMap, values: [values0], }: ExecutionDetails): PromiseOrDirect<GrafastResultsList<any>>;
|
|
24
|
+
}
|
|
25
|
+
export declare function polymorphicBranch<TStep extends Step>($step: TStep, matchers: PolymorphicBranchMatchers<TStep>): PolymorphicBranchStep<TStep>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=polymorphicBranch.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolymorphicBranchStep = void 0;
|
|
4
|
+
exports.polymorphicBranch = polymorphicBranch;
|
|
5
|
+
const index_js_1 = require("../index.js");
|
|
6
|
+
const step_js_1 = require("../step.js");
|
|
7
|
+
const constant_js_1 = require("./constant.js");
|
|
8
|
+
class PolymorphicBranchStep extends step_js_1.Step {
|
|
9
|
+
static { this.$$export = {
|
|
10
|
+
moduleName: "grafast",
|
|
11
|
+
exportName: "PolymorphicBranchStep",
|
|
12
|
+
}; }
|
|
13
|
+
constructor($step, matchers) {
|
|
14
|
+
super();
|
|
15
|
+
this.isSyncAndSafe = true;
|
|
16
|
+
this.addDependency($step);
|
|
17
|
+
this.typeNames = Object.keys(matchers);
|
|
18
|
+
this.matchers = Object.fromEntries(Object.entries(matchers).map(([typeName, matcher]) => {
|
|
19
|
+
const fixedMatcher = {
|
|
20
|
+
match: matcher.match ?? ((obj) => obj.__typename === typeName),
|
|
21
|
+
plan: matcher.plan ?? (($obj) => $obj),
|
|
22
|
+
};
|
|
23
|
+
return [typeName, fixedMatcher];
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
planForType(objectType) {
|
|
27
|
+
const matcher = this.matchers[objectType.name];
|
|
28
|
+
const $step = this.getDep(0, true);
|
|
29
|
+
if (matcher) {
|
|
30
|
+
if (typeof matcher.plan === "function") {
|
|
31
|
+
return matcher.plan($step);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return $step;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// TODO: should this be an error?
|
|
39
|
+
return (0, constant_js_1.constant)(null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
execute({ indexMap, values: [values0], }) {
|
|
43
|
+
return indexMap((i) => {
|
|
44
|
+
const obj = values0.at(i);
|
|
45
|
+
let match = null;
|
|
46
|
+
if (obj != null) {
|
|
47
|
+
for (const typeName of this.typeNames) {
|
|
48
|
+
if (this.matchers[typeName].match(obj)) {
|
|
49
|
+
match = typeName;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return match !== null ? (0, index_js_1.polymorphicWrap)(match, obj) : null;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.PolymorphicBranchStep = PolymorphicBranchStep;
|
|
59
|
+
function polymorphicBranch($step, matchers) {
|
|
60
|
+
return new PolymorphicBranchStep($step, matchers);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=polymorphicBranch.js.map
|
package/dist/steps/proxy.d.ts
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import type { GrafastResultsList,
|
|
2
|
-
import type { ExecutionExtra } from "../interfaces.js";
|
|
1
|
+
import type { ExecutionDetails, GrafastResultsList, UnbatchedExecutionExtra } from "../interfaces.js";
|
|
3
2
|
import { $$proxy } from "../interfaces.js";
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
3
|
+
import type { Step } from "../step.js";
|
|
4
|
+
import { UnbatchedStep } from "../step.js";
|
|
6
5
|
/**
|
|
7
6
|
* @experimental
|
|
8
7
|
*
|
|
9
8
|
* Never build this class directly.
|
|
10
9
|
*/
|
|
11
|
-
export declare class ProxyStep<T> extends
|
|
10
|
+
export declare class ProxyStep<T> extends UnbatchedStep<T> {
|
|
12
11
|
static $$export: {
|
|
13
12
|
moduleName: string;
|
|
14
13
|
exportName: string;
|
|
15
14
|
};
|
|
16
15
|
isSyncAndSafe: boolean;
|
|
17
16
|
private $depId;
|
|
18
|
-
constructor($dep:
|
|
17
|
+
constructor($dep: Step<T>, $actualDep: Step);
|
|
19
18
|
toStringMeta(): string | null;
|
|
20
|
-
addDependency(step:
|
|
21
|
-
execute(
|
|
22
|
-
unbatchedExecute(_extra:
|
|
19
|
+
addDependency(step: Step): number;
|
|
20
|
+
execute({ count, values: [values0], }: ExecutionDetails<[T]>): GrafastResultsList<T>;
|
|
21
|
+
unbatchedExecute(_extra: UnbatchedExecutionExtra, value: T): T;
|
|
23
22
|
stream: undefined;
|
|
24
23
|
}
|
|
25
24
|
declare module "../step.js" {
|
|
26
|
-
interface
|
|
25
|
+
interface Step {
|
|
27
26
|
[$$proxy]?: any;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
@@ -33,7 +32,7 @@ declare module "../step.js" {
|
|
|
33
32
|
* This could change at any time, may impact performance, and just, generally,
|
|
34
33
|
* needs more work. You shouldn't need this in the vast majority of cases.
|
|
35
34
|
*/
|
|
36
|
-
export declare function proxy<TData, TStep extends
|
|
37
|
-
addDependency(step:
|
|
35
|
+
export declare function proxy<TData, TStep extends Step<TData>>($step: TStep, $actualDep?: Step): TStep & {
|
|
36
|
+
addDependency(step: Step): number;
|
|
38
37
|
};
|
|
39
38
|
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/steps/proxy.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ProxyStep = void 0;
|
|
4
|
+
exports.proxy = proxy;
|
|
4
5
|
const interfaces_js_1 = require("../interfaces.js");
|
|
5
6
|
const step_js_1 = require("../step.js");
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
6
8
|
/**
|
|
7
9
|
* @experimental
|
|
8
10
|
*
|
|
9
11
|
* Never build this class directly.
|
|
10
12
|
*/
|
|
11
|
-
class ProxyStep extends step_js_1.
|
|
13
|
+
class ProxyStep extends step_js_1.UnbatchedStep {
|
|
12
14
|
static { this.$$export = {
|
|
13
15
|
moduleName: "grafast",
|
|
14
16
|
exportName: "ProxyStep",
|
|
@@ -29,8 +31,10 @@ class ProxyStep extends step_js_1.UnbatchedExecutableStep {
|
|
|
29
31
|
addDependency(step) {
|
|
30
32
|
return super.addDependency(step);
|
|
31
33
|
}
|
|
32
|
-
execute(
|
|
33
|
-
return
|
|
34
|
+
execute({ count, values: [values0], }) {
|
|
35
|
+
return values0.isBatch
|
|
36
|
+
? values0.entries
|
|
37
|
+
: (0, utils_js_1.arrayOfLength)(count, values0.value);
|
|
34
38
|
}
|
|
35
39
|
unbatchedExecute(_extra, value) {
|
|
36
40
|
return value;
|
|
@@ -110,5 +114,4 @@ function proxy($step, $actualDep = $step) {
|
|
|
110
114
|
$proxy[interfaces_js_1.$$proxy] = proxy;
|
|
111
115
|
return proxy;
|
|
112
116
|
}
|
|
113
|
-
exports.proxy = proxy;
|
|
114
117
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import type { ExecutionDetails, GrafastResultsList, UnbatchedExecutionExtra } from "../interfaces.js";
|
|
2
|
+
import type { Step } from "../step.js";
|
|
3
|
+
import { UnbatchedStep } from "../step.js";
|
|
4
4
|
export type ActualKeyByDesiredKey = {
|
|
5
5
|
[desiredKey: string]: string;
|
|
6
6
|
};
|
|
@@ -8,8 +8,8 @@ export type ActualKeyByDesiredKey = {
|
|
|
8
8
|
* A plan that returns an object resulting from extracting the given
|
|
9
9
|
* `actualKey` from the input and storing it as the `desiredKey` in the output.
|
|
10
10
|
*/
|
|
11
|
-
export declare class RemapKeysStep extends
|
|
12
|
-
private actualKeyByDesiredKey;
|
|
11
|
+
export declare class RemapKeysStep extends UnbatchedStep {
|
|
12
|
+
private readonly actualKeyByDesiredKey;
|
|
13
13
|
static $$export: {
|
|
14
14
|
moduleName: string;
|
|
15
15
|
exportName: string;
|
|
@@ -17,19 +17,19 @@ export declare class RemapKeysStep extends UnbatchedExecutableStep {
|
|
|
17
17
|
isSyncAndSafe: boolean;
|
|
18
18
|
allowMultipleOptimizations: boolean;
|
|
19
19
|
private mapper;
|
|
20
|
-
constructor($plan:
|
|
20
|
+
constructor($plan: Step, actualKeyByDesiredKey: ActualKeyByDesiredKey);
|
|
21
21
|
toStringMeta(): string;
|
|
22
|
-
optimize():
|
|
22
|
+
optimize(): Step<any> | this;
|
|
23
23
|
finalize(): void;
|
|
24
|
-
execute(
|
|
25
|
-
unbatchedExecute(_extra:
|
|
24
|
+
execute({ count, values: [values0], }: ExecutionDetails): GrafastResultsList<any>;
|
|
25
|
+
unbatchedExecute(_extra: UnbatchedExecutionExtra, value: any): any;
|
|
26
26
|
deduplicate(peers: RemapKeysStep[]): RemapKeysStep[];
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* A plan that returns an object resulting from extracting the given
|
|
30
30
|
* `actualKey` from the input and storing it as the `desiredKey` in the output.
|
|
31
31
|
*/
|
|
32
|
-
export declare function remapKeys($step:
|
|
32
|
+
export declare function remapKeys($step: Step, actualKeyByDesiredKey: {
|
|
33
33
|
[desiredKey: string]: string;
|
|
34
34
|
}): RemapKeysStep;
|
|
35
35
|
//# sourceMappingURL=remapKeys.d.ts.map
|