@pogodisco/task-runner 0.2.2 → 0.2.3
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TasksFromFns } from "../types/index.js";
|
|
2
|
+
export declare const startSchema: import("../types/index.js").TaskSchemaWithContracts<TasksFromFns<{}>, {
|
|
3
|
+
foo: string;
|
|
4
|
+
}, {
|
|
5
|
+
data: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const secondSchema: import("../types/index.js").TaskSchemaWithContracts<TasksFromFns<{}>, {
|
|
8
|
+
testNumber: number;
|
|
9
|
+
}, {
|
|
10
|
+
numeric: number;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createGraph } from "../graph/main.js";
|
|
2
|
+
import { createGraphRegistrar } from "../graph/registry.js";
|
|
3
|
+
import { defineSchema } from "../main.js";
|
|
4
|
+
import { wrapSchema } from "../utils/wrap-schema.js";
|
|
5
|
+
export const startSchema = defineSchema({
|
|
6
|
+
_output: (r) => ({ data: r._init.foo }),
|
|
7
|
+
});
|
|
8
|
+
export const secondSchema = defineSchema({
|
|
9
|
+
_output: (r) => ({ numeric: r._init.testNumber }),
|
|
10
|
+
});
|
|
11
|
+
const g = createGraph()
|
|
12
|
+
.node("one", wrapSchema(startSchema), (ctx) => ({
|
|
13
|
+
foo: ctx._init.foo,
|
|
14
|
+
}))
|
|
15
|
+
.node("two", wrapSchema(secondSchema))
|
|
16
|
+
.edge("one", "two", (ctx) => ctx.results.one.data === "bar")
|
|
17
|
+
.build();
|
|
18
|
+
const reg = {
|
|
19
|
+
one: g,
|
|
20
|
+
};
|
|
21
|
+
const fromGraph = createGraphRegistrar(reg);
|
|
22
|
+
const r = await fromGraph("one", { foo: "bar" });
|
package/dist/v2/graph/main.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { GraphBuilder, GraphNode, RuntimeCtx, SchemaGraph } from "./types/index.js";
|
|
1
|
+
import { GraphBuilder, GraphEdge, GraphNode, RuntimeCtx, SchemaGraph } from "./types/index.js";
|
|
2
|
+
export declare function edge<K extends keyof any>(from: K, to: K, when?: (ctx: any) => boolean): GraphEdge<K>;
|
|
2
3
|
export declare function createGraph<Init = {}>(): GraphBuilder<{}, Init>;
|
|
3
4
|
export declare function runGraph<Nodes extends Record<string, GraphNode<any>>, Init>(graph: SchemaGraph<Nodes, Init>, initArgs: Init): Promise<RuntimeCtx<Nodes, Init>>;
|
package/dist/v2/graph/main.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// when?: (ctx: any) => boolean,
|
|
5
|
-
// ): GraphEdge<K> {
|
|
6
|
-
// return { from, to, when };
|
|
7
|
-
// }
|
|
1
|
+
export function edge(from, to, when) {
|
|
2
|
+
return { from, to, when };
|
|
3
|
+
}
|
|
8
4
|
export function createGraph() {
|
|
9
5
|
const nodes = {};
|
|
10
6
|
// const edges: GraphEdge<string>[] = [];
|
|
@@ -18,6 +14,10 @@ export function createGraph() {
|
|
|
18
14
|
return builder;
|
|
19
15
|
},
|
|
20
16
|
edge(from, to, when) {
|
|
17
|
+
// if (!(from in nodes))
|
|
18
|
+
// throw new Error(`Edge 'from' node "${from}" does not exist`);
|
|
19
|
+
// if (!(to in nodes))
|
|
20
|
+
// throw new Error(`Edge 'to' node "${to}" does not exist`);
|
|
21
21
|
edges.push({ from, to, when });
|
|
22
22
|
return builder;
|
|
23
23
|
},
|
|
@@ -12,20 +12,20 @@ export type RuntimeCtx<Nodes extends Record<string, GraphNode<any>>, Init> = {
|
|
|
12
12
|
[K in keyof Nodes]: ExtractOutput<Nodes[K]["schema"]>;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export type GraphEdge<
|
|
16
|
-
from:
|
|
17
|
-
to:
|
|
18
|
-
when?: (ctx:
|
|
15
|
+
export type GraphEdge<NodeKeys extends keyof any> = {
|
|
16
|
+
from: NodeKeys;
|
|
17
|
+
to: NodeKeys;
|
|
18
|
+
when?: (ctx: any) => boolean;
|
|
19
19
|
};
|
|
20
20
|
export type BuiltNode<FN extends WrappedSchema<any, any>, Nodes extends Record<string, GraphNode<any>>> = GraphNode<FN>;
|
|
21
21
|
export type SchemaGraph<Nodes extends Record<string, GraphNode<any>>, Init> = {
|
|
22
22
|
entry: keyof Nodes;
|
|
23
23
|
nodes: Nodes;
|
|
24
|
-
edges: GraphEdge<Nodes
|
|
24
|
+
edges: GraphEdge<keyof Nodes>[];
|
|
25
25
|
};
|
|
26
26
|
export type GraphBuilder<Nodes extends Record<string, GraphNode<any>> = {}, Init = {}> = {
|
|
27
27
|
node<K extends string, FN extends WrappedSchema<any, any>>(key: K, schema: FN, mapInput?: (ctx: RuntimeCtx<Nodes & Record<K, GraphNode<FN>>, Init>) => ExtractInput<FN>): GraphBuilder<Nodes & Record<K, GraphNode<FN>>, Init>;
|
|
28
|
-
edge<From extends keyof Nodes, To extends keyof Nodes>(from: From, to: To, when?: (ctx:
|
|
28
|
+
edge<From extends keyof Nodes, To extends keyof Nodes>(from: From, to: To, when?: (ctx: any) => boolean): GraphBuilder<Nodes, Init>;
|
|
29
29
|
build(): SchemaGraph<Nodes, Init>;
|
|
30
30
|
};
|
|
31
31
|
export type GraphEntryInput<G extends SchemaGraph<any, any>> = G extends SchemaGraph<infer Nodes, any> ? RuntimeCtx<Nodes, any>["_init"] : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|