@pogodisco/task-runner 0.2.0 → 0.2.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.
@@ -1,4 +1,5 @@
1
1
  import type { TResponse } from "@pogodisco/response";
2
2
  export type CommandInputFor<R extends Record<string, any>, K extends keyof R> = R[K] extends (args: infer I) => any ? I : never;
3
3
  export type CommandOutputFor<R extends Record<string, any>, K extends keyof R> = R[K] extends (args: any) => Promise<TResponse<infer O>> ? O : never;
4
- export declare function createCommandRegistrar<R extends Record<string, (...args: any) => Promise<TResponse<any>>>>(registry: R): <K extends keyof R & string>(name: K, params: CommandInputFor<R, K>) => Promise<TResponse<CommandOutputFor<R, K>>>;
4
+ export declare function createCommandRegistrar<R extends Record<string, (...args: any) => Promise<TResponse<any>>>>(registry: R): CommandRegistrar<R>;
5
+ export type CommandRegistrar<R extends Record<string, (...args: any) => Promise<TResponse<any>>>> = <K extends keyof R & string>(name: K, params: CommandInputFor<R, K>) => Promise<TResponse<CommandOutputFor<R, K>>>;
@@ -1,9 +1,20 @@
1
1
  // -----------------------------
2
2
  // Registrar creator
3
3
  // -----------------------------
4
+ // export function createCommandRegistrar<
5
+ // R extends Record<string, (...args: any) => Promise<TResponse<any>>>,
6
+ // >(registry: R): CommandRegistrar<R> {
7
+ // return async function appCommand<K extends keyof R & string>(
8
+ // name: K,
9
+ // params: CommandInputFor<R, K>,
10
+ // ): Promise<TResponse<CommandOutputFor<R, K>>> {
11
+ // const fn = registry[name];
12
+ // return await fn(params);
13
+ // };
14
+ // }
4
15
  export function createCommandRegistrar(registry) {
5
- return async function appCommand(name, params) {
16
+ return async (name, params) => {
6
17
  const fn = registry[name];
7
- return await fn(params);
18
+ return fn(params);
8
19
  };
9
20
  }
@@ -1,3 +1,3 @@
1
- export { type GraphRegistry, type GraphInput, type GraphOutput, } from "./types/index.js";
1
+ export * from "./types/index.js";
2
2
  export { createGraph, runGraph } from "./main.js";
3
- export { createGraphRegistrar } from "./registry.js";
3
+ export * from "./registry.js";
@@ -1,2 +1,3 @@
1
+ export * from "./types/index.js";
1
2
  export { createGraph, runGraph } from "./main.js";
2
- export { createGraphRegistrar } from "./registry.js";
3
+ export * from "./registry.js";
@@ -1,4 +1,3 @@
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>;
1
+ import { GraphBuilder, GraphNode, RuntimeCtx, SchemaGraph } from "./types/index.js";
3
2
  export declare function createGraph<Init = {}>(): GraphBuilder<{}, Init>;
4
3
  export declare function runGraph<Nodes extends Record<string, GraphNode<any>>, Init>(graph: SchemaGraph<Nodes, Init>, initArgs: Init): Promise<RuntimeCtx<Nodes, Init>>;
@@ -1,6 +1,10 @@
1
- export function edge(from, to, when) {
2
- return { from, to, when };
3
- }
1
+ // function edge<K extends keyof any>(
2
+ // from: K,
3
+ // to: K,
4
+ // when?: (ctx: any) => boolean,
5
+ // ): GraphEdge<K> {
6
+ // return { from, to, when };
7
+ // }
4
8
  export function createGraph() {
5
9
  const nodes = {};
6
10
  // const edges: GraphEdge<string>[] = [];
@@ -13,12 +17,8 @@ export function createGraph() {
13
17
  nodes[key] = { schema, mapInput };
14
18
  return builder;
15
19
  },
16
- edge(from, to) {
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
- edges.push({ from, to });
20
+ edge(from, to, when) {
21
+ edges.push({ from, to, when });
22
22
  return builder;
23
23
  },
24
24
  build() {
@@ -1,5 +1,5 @@
1
1
  import { RuntimeCtx, SchemaGraph } from "./types/index.js";
2
- type GraphInputFor<R extends Record<string, SchemaGraph<any, any>>, K extends keyof R> = R[K] extends SchemaGraph<any, infer I> ? I : never;
3
- type GraphOutputFor<R extends Record<string, SchemaGraph<any, any>>, K extends keyof R> = R[K] extends SchemaGraph<infer N, infer I> ? RuntimeCtx<N, I> : never;
4
- export declare function createGraphRegistrar<R extends Record<string, SchemaGraph<any, any>>>(registry: R): <K extends keyof R & string>(name: K, params: GraphInputFor<R, K>) => Promise<GraphOutputFor<R, K>>;
5
- export {};
2
+ export type GraphInputFor<R extends Record<string, SchemaGraph<any, any>>, K extends keyof R> = R[K] extends SchemaGraph<any, infer I> ? I : never;
3
+ export type GraphOutputFor<R extends Record<string, SchemaGraph<any, any>>, K extends keyof R> = R[K] extends SchemaGraph<infer N, infer I> ? RuntimeCtx<N, I> : never;
4
+ export type GraphRegistrar<R extends Record<string, SchemaGraph<any, any>>> = <K extends keyof R & string>(name: K, params: GraphInputFor<R, K>) => Promise<GraphOutputFor<R, K>>;
5
+ export declare function createGraphRegistrar<R extends Record<string, SchemaGraph<any, any>>>(registry: R): GraphRegistrar<R>;
@@ -1,7 +1,10 @@
1
1
  import { runGraph } from "./main.js";
2
+ // -----------------------------
3
+ // Factory
4
+ // -----------------------------
2
5
  export function createGraphRegistrar(registry) {
3
- return async function graphCommand(name, params) {
6
+ return async (name, params) => {
4
7
  const graph = registry[name];
5
- return runGraph(graph, params); // safe internally
8
+ return runGraph(graph, params);
6
9
  };
7
10
  }
@@ -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<NodeKeys extends keyof any> = {
16
- from: NodeKeys;
17
- to: NodeKeys;
18
- when?: (ctx: any) => boolean;
15
+ export type GraphEdge<Nodes extends Record<string, GraphNode<any>>, Init> = {
16
+ from: keyof Nodes;
17
+ to: keyof Nodes;
18
+ when?: (ctx: RuntimeCtx<Nodes, Init>) => 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<keyof Nodes>[];
24
+ edges: GraphEdge<Nodes, Init>[];
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): GraphBuilder<Nodes, Init>;
28
+ edge<From extends keyof Nodes, To extends keyof Nodes>(from: From, to: To, when?: (ctx: RuntimeCtx<Nodes, Init>) => 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;
@@ -1,6 +1,5 @@
1
1
  export { runSchema, defineSchema } from "./main.js";
2
2
  export { wrapSchema } from "./utils/index.js";
3
- export { type TaskLogger, type LogEvent, type TasksFromFns, } from "./types/index.js";
4
3
  export * from "./graph/index.js";
5
- export { createCommandRegistrar } from "./command/main.js";
6
- export { createGraphRegistrar } from "./graph/index.js";
4
+ export * from "./types/index.js";
5
+ export * from "./command/main.js";
package/dist/v2/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { runSchema, defineSchema } from "./main.js";
2
2
  export { wrapSchema } from "./utils/index.js";
3
3
  export * from "./graph/index.js";
4
- export { createCommandRegistrar } from "./command/main.js";
5
- export { createGraphRegistrar } from "./graph/index.js";
4
+ export * from "./types/index.js";
5
+ export * from "./command/main.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/task-runner",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },