mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
added format command and added trailing commas to reduce conflicts
This commit is contained in:
@@ -30,14 +30,14 @@ beforeAll(() =>
|
||||
method: init?.method ?? "GET",
|
||||
// @ts-ignore
|
||||
headers: Object.fromEntries(init?.headers?.entries() ?? []),
|
||||
body: init?.body
|
||||
body: init?.body,
|
||||
};
|
||||
|
||||
return new Response(JSON.stringify({ todos: [1, 2], request }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
})
|
||||
}),
|
||||
);
|
||||
afterAll(unmockFetch);
|
||||
|
||||
@@ -46,7 +46,7 @@ describe("FetchTask", async () => {
|
||||
const task = new FetchTask("Fetch Something", {
|
||||
url: "https://jsonplaceholder.typicode.com/todos/1",
|
||||
method: "GET",
|
||||
headers: [{ key: "Content-Type", value: "application/json" }]
|
||||
headers: [{ key: "Content-Type", value: "application/json" }],
|
||||
});
|
||||
|
||||
const result = await task.run();
|
||||
@@ -62,18 +62,18 @@ describe("FetchTask", async () => {
|
||||
|
||||
expect(
|
||||
// // @ts-expect-error
|
||||
() => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: 1 })
|
||||
() => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: 1 }),
|
||||
).toThrow();
|
||||
|
||||
expect(
|
||||
new FetchTask("", {
|
||||
url: "https://jsonplaceholder.typicode.com",
|
||||
method: "invalid"
|
||||
}).execute()
|
||||
method: "invalid",
|
||||
}).execute(),
|
||||
).rejects.toThrow(/^Invalid method/);
|
||||
|
||||
expect(
|
||||
() => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: "GET" })
|
||||
() => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: "GET" }),
|
||||
).toBeDefined();
|
||||
|
||||
expect(() => new FetchTask("", { url: "", method: "Invalid" })).toThrow();
|
||||
@@ -85,17 +85,17 @@ describe("FetchTask", async () => {
|
||||
method: "{{ flow.output.method }}",
|
||||
headers: [
|
||||
{ key: "Content-{{ flow.output.headerKey }}", value: "application/json" },
|
||||
{ key: "Authorization", value: "Bearer {{ flow.output.apiKey }}" }
|
||||
{ key: "Authorization", value: "Bearer {{ flow.output.apiKey }}" },
|
||||
],
|
||||
body: JSON.stringify({
|
||||
email: "{{ flow.output.email }}"
|
||||
})
|
||||
email: "{{ flow.output.email }}",
|
||||
}),
|
||||
});
|
||||
const inputs = {
|
||||
headerKey: "Type",
|
||||
apiKey: 123,
|
||||
email: "what@else.com",
|
||||
method: "PATCH"
|
||||
method: "PATCH",
|
||||
};
|
||||
|
||||
const flow = new Flow("", [task]);
|
||||
|
||||
@@ -4,16 +4,16 @@ import { Flow, LogTask, RenderTask, SubFlowTask } from "../../src/flows";
|
||||
describe("SubFlowTask", async () => {
|
||||
test("Simple Subflow", async () => {
|
||||
const subTask = new RenderTask("render", {
|
||||
render: "subflow"
|
||||
render: "subflow",
|
||||
});
|
||||
const subflow = new Flow("subflow", [subTask]);
|
||||
|
||||
const task = new LogTask("log");
|
||||
const task2 = new SubFlowTask("sub", {
|
||||
flow: subflow
|
||||
flow: subflow,
|
||||
});
|
||||
const task3 = new RenderTask("render2", {
|
||||
render: "Subflow output: {{ sub.output }}"
|
||||
render: "Subflow output: {{ sub.output }}",
|
||||
});
|
||||
|
||||
const flow = new Flow("test", [task, task2, task3], []);
|
||||
@@ -30,7 +30,7 @@ describe("SubFlowTask", async () => {
|
||||
|
||||
test("Simple loop", async () => {
|
||||
const subTask = new RenderTask("render", {
|
||||
render: "run {{ flow.output }}"
|
||||
render: "run {{ flow.output }}",
|
||||
});
|
||||
const subflow = new Flow("subflow", [subTask]);
|
||||
|
||||
@@ -38,10 +38,10 @@ describe("SubFlowTask", async () => {
|
||||
const task2 = new SubFlowTask("sub", {
|
||||
flow: subflow,
|
||||
loop: true,
|
||||
input: [1, 2, 3]
|
||||
input: [1, 2, 3],
|
||||
});
|
||||
const task3 = new RenderTask("render2", {
|
||||
render: `Subflow output: {{ sub.output | join: ", " }}`
|
||||
render: `Subflow output: {{ sub.output | join: ", " }}`,
|
||||
});
|
||||
|
||||
const flow = new Flow("test", [task, task2, task3], []);
|
||||
@@ -61,7 +61,7 @@ describe("SubFlowTask", async () => {
|
||||
|
||||
test("Simple loop from flow input", async () => {
|
||||
const subTask = new RenderTask("render", {
|
||||
render: "run {{ flow.output }}"
|
||||
render: "run {{ flow.output }}",
|
||||
});
|
||||
|
||||
const subflow = new Flow("subflow", [subTask]);
|
||||
@@ -70,10 +70,10 @@ describe("SubFlowTask", async () => {
|
||||
const task2 = new SubFlowTask("sub", {
|
||||
flow: subflow,
|
||||
loop: true,
|
||||
input: "{{ flow.output | json }}"
|
||||
input: "{{ flow.output | json }}",
|
||||
});
|
||||
const task3 = new RenderTask("render2", {
|
||||
render: `Subflow output: {{ sub.output | join: ", " }}`
|
||||
render: `Subflow output: {{ sub.output | join: ", " }}`,
|
||||
});
|
||||
|
||||
const flow = new Flow("test", [task, task2, task3], []);
|
||||
|
||||
@@ -8,13 +8,13 @@ describe("Task", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({ test: dynamic(Type.Number()) }),
|
||||
{
|
||||
test: "{{ some.path }}"
|
||||
test: "{{ some.path }}",
|
||||
},
|
||||
{
|
||||
some: {
|
||||
path: 1
|
||||
}
|
||||
}
|
||||
path: 1,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toBe(1);
|
||||
@@ -24,13 +24,13 @@ describe("Task", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({ test: Type.String() }),
|
||||
{
|
||||
test: "{{ some.path }}"
|
||||
test: "{{ some.path }}",
|
||||
},
|
||||
{
|
||||
some: {
|
||||
path: "1/1"
|
||||
}
|
||||
}
|
||||
path: "1/1",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toBe("1/1");
|
||||
@@ -40,13 +40,13 @@ describe("Task", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({ test: dynamic(Type.Object({ key: Type.String(), value: Type.String() })) }),
|
||||
{
|
||||
test: { key: "path", value: "{{ some.path }}" }
|
||||
test: { key: "path", value: "{{ some.path }}" },
|
||||
},
|
||||
{
|
||||
some: {
|
||||
path: "1/1"
|
||||
}
|
||||
}
|
||||
path: "1/1",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toEqual({ key: "path", value: "1/1" });
|
||||
@@ -55,17 +55,17 @@ describe("Task", async () => {
|
||||
test("resolveParams: with json", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({
|
||||
test: dynamic(Type.Object({ key: Type.String(), value: Type.String() }))
|
||||
test: dynamic(Type.Object({ key: Type.String(), value: Type.String() })),
|
||||
}),
|
||||
{
|
||||
test: "{{ some | json }}"
|
||||
test: "{{ some | json }}",
|
||||
},
|
||||
{
|
||||
some: {
|
||||
key: "path",
|
||||
value: "1/1"
|
||||
}
|
||||
}
|
||||
value: "1/1",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toEqual({ key: "path", value: "1/1" });
|
||||
@@ -74,11 +74,11 @@ describe("Task", async () => {
|
||||
test("resolveParams: with array", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({
|
||||
test: dynamic(Type.Array(Type.String()))
|
||||
test: dynamic(Type.Array(Type.String())),
|
||||
}),
|
||||
{
|
||||
test: '{{ "1,2,3" | split: "," | json }}'
|
||||
}
|
||||
test: '{{ "1,2,3" | split: "," | json }}',
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toEqual(["1", "2", "3"]);
|
||||
@@ -87,11 +87,11 @@ describe("Task", async () => {
|
||||
test("resolveParams: boolean", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({
|
||||
test: dynamic(Type.Boolean())
|
||||
test: dynamic(Type.Boolean()),
|
||||
}),
|
||||
{
|
||||
test: "{{ true }}"
|
||||
}
|
||||
test: "{{ true }}",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toEqual(true);
|
||||
@@ -100,11 +100,11 @@ describe("Task", async () => {
|
||||
test("resolveParams: float", async () => {
|
||||
const result = await Task.resolveParams(
|
||||
Type.Object({
|
||||
test: dynamic(Type.Number(), Number.parseFloat)
|
||||
test: dynamic(Type.Number(), Number.parseFloat),
|
||||
}),
|
||||
{
|
||||
test: "{{ 3.14 }}"
|
||||
}
|
||||
test: "{{ 3.14 }}",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.test).toEqual(3.14);
|
||||
|
||||
@@ -7,11 +7,11 @@ const first = getNamedTask(
|
||||
//throw new Error("Error");
|
||||
return {
|
||||
inner: {
|
||||
result: 2
|
||||
}
|
||||
result: 2,
|
||||
},
|
||||
};
|
||||
},
|
||||
1000
|
||||
1000,
|
||||
);
|
||||
const second = getNamedTask("second (if match)");
|
||||
const third = getNamedTask("third (if error)");
|
||||
|
||||
@@ -11,7 +11,7 @@ class ExecTask extends Task {
|
||||
constructor(
|
||||
name: string,
|
||||
params: any,
|
||||
private fn: () => any
|
||||
private fn: () => any,
|
||||
) {
|
||||
super(name, params);
|
||||
}
|
||||
@@ -54,8 +54,8 @@ export function getNamedTask(name: string, _func?: () => Promise<any>, delay?: n
|
||||
return new ExecTask(
|
||||
name,
|
||||
{
|
||||
delay
|
||||
delay,
|
||||
},
|
||||
func
|
||||
func,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const first = new LogTask("First", { delay: 1000 });
|
||||
const second = new LogTask("Second", { delay: 1000 });
|
||||
const third = new LogTask("Long Third", { delay: 2500 });
|
||||
const fourth = new FetchTask("Fetch Something", {
|
||||
url: "https://jsonplaceholder.typicode.com/todos/1"
|
||||
url: "https://jsonplaceholder.typicode.com/todos/1",
|
||||
});
|
||||
const fifth = new LogTask("Task 4", { delay: 500 }); // without connection
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ class OutputParamTask extends Task<typeof OutputParamTask.schema> {
|
||||
static override schema = Type.Object({
|
||||
number: dynamic(
|
||||
Type.Number({
|
||||
title: "Output number"
|
||||
title: "Output number",
|
||||
}),
|
||||
Number.parseInt
|
||||
)
|
||||
Number.parseInt,
|
||||
),
|
||||
});
|
||||
|
||||
async execute(inputs: InputsMap) {
|
||||
@@ -75,7 +75,7 @@ describe("Flow task inputs", async () => {
|
||||
test("output/input", async () => {
|
||||
const task = new OutputParamTask("task1", { number: 111 });
|
||||
const task2 = new OutputParamTask("task2", {
|
||||
number: "{{ task1.output }}"
|
||||
number: "{{ task1.output }}",
|
||||
});
|
||||
|
||||
const flow = new Flow("test", [task, task2]);
|
||||
@@ -94,10 +94,10 @@ describe("Flow task inputs", async () => {
|
||||
|
||||
test("input from flow", async () => {
|
||||
const task = new OutputParamTask("task1", {
|
||||
number: "{{flow.output.someFancyParam}}"
|
||||
number: "{{flow.output.someFancyParam}}",
|
||||
});
|
||||
const task2 = new OutputParamTask("task2", {
|
||||
number: "{{task1.output}}"
|
||||
number: "{{task1.output}}",
|
||||
});
|
||||
|
||||
const flow = new Flow("test", [task, task2]);
|
||||
@@ -126,7 +126,7 @@ describe("Flow task inputs", async () => {
|
||||
const emgr = new EventManager({ EventTriggerClass });
|
||||
|
||||
const task = new OutputParamTask("event", {
|
||||
number: "{{flow.output.number}}"
|
||||
number: "{{flow.output.number}}",
|
||||
});
|
||||
const flow = new Flow(
|
||||
"test",
|
||||
@@ -134,8 +134,8 @@ describe("Flow task inputs", async () => {
|
||||
[],
|
||||
new EventTrigger({
|
||||
event: "test-event",
|
||||
mode: "sync"
|
||||
})
|
||||
mode: "sync",
|
||||
}),
|
||||
);
|
||||
flow.setRespondingTask(task);
|
||||
flow.trigger.register(flow, emgr);
|
||||
@@ -155,8 +155,8 @@ describe("Flow task inputs", async () => {
|
||||
new HttpTrigger({
|
||||
path: "/test",
|
||||
method: "GET",
|
||||
mode: "sync"
|
||||
})
|
||||
mode: "sync",
|
||||
}),
|
||||
);
|
||||
flow.setRespondingTask(task);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const flows = {
|
||||
back,
|
||||
fanout,
|
||||
parallel,
|
||||
simpleFetch
|
||||
simpleFetch,
|
||||
};
|
||||
|
||||
const arg = process.argv[2];
|
||||
@@ -32,7 +32,7 @@ const colors = [
|
||||
"#F78F1E", // Saffron
|
||||
"#BD10E0", // Vivid Purple
|
||||
"#50E3C2", // Turquoise
|
||||
"#9013FE" // Grape
|
||||
"#9013FE", // Grape
|
||||
];
|
||||
|
||||
const colorsCache: Record<string, string> = {};
|
||||
@@ -82,7 +82,7 @@ function TerminalFlow({ flow }: { flow: Flow }) {
|
||||
}
|
||||
|
||||
return t;
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -92,7 +92,7 @@ function TerminalFlow({ flow }: { flow: Flow }) {
|
||||
console.log("done", response ? response : "(no response)");
|
||||
console.log(
|
||||
"Executed tasks:",
|
||||
execution.logs.map((l) => l.task.name)
|
||||
execution.logs.map((l) => l.task.name),
|
||||
);
|
||||
console.log("Executed count:", execution.logs.length);
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ class ExecTask extends Task {
|
||||
constructor(
|
||||
name: string,
|
||||
params: any,
|
||||
private fn: () => any
|
||||
private fn: () => any,
|
||||
) {
|
||||
super(name, params);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ describe("Flow trigger", async () => {
|
||||
"test",
|
||||
[task],
|
||||
[],
|
||||
new EventTrigger({ event: "test-event", mode: "sync" })
|
||||
new EventTrigger({ event: "test-event", mode: "sync" }),
|
||||
);
|
||||
|
||||
flow.trigger.register(flow, emgr);
|
||||
@@ -107,8 +107,8 @@ describe("Flow trigger", async () => {
|
||||
new HttpTrigger({
|
||||
path: "/test",
|
||||
method: "GET",
|
||||
mode: "sync"
|
||||
})
|
||||
mode: "sync",
|
||||
}),
|
||||
);
|
||||
|
||||
const hono = new Hono();
|
||||
@@ -123,7 +123,7 @@ describe("Flow trigger", async () => {
|
||||
|
||||
test("http trigger with response", async () => {
|
||||
const task = ExecTask.create("http", () => ({
|
||||
called: true
|
||||
called: true,
|
||||
}));
|
||||
const flow = new Flow(
|
||||
"test",
|
||||
@@ -132,8 +132,8 @@ describe("Flow trigger", async () => {
|
||||
new HttpTrigger({
|
||||
path: "/test",
|
||||
method: "GET",
|
||||
mode: "sync"
|
||||
})
|
||||
mode: "sync",
|
||||
}),
|
||||
);
|
||||
flow.setRespondingTask(task);
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ class ExecTask extends Task<typeof ExecTask.schema> {
|
||||
type = "exec";
|
||||
|
||||
static override schema = Type.Object({
|
||||
delay: Type.Number({ default: 10 })
|
||||
delay: Type.Number({ default: 10 }),
|
||||
});
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
params: Static<typeof ExecTask.schema>,
|
||||
private func: () => Promise<any>
|
||||
private func: () => Promise<any>,
|
||||
) {
|
||||
super(name, params);
|
||||
}
|
||||
@@ -36,12 +36,12 @@ function getTask(num: number = 0, delay: number = 5) {
|
||||
return new ExecTask(
|
||||
`Task ${num}`,
|
||||
{
|
||||
delay
|
||||
delay,
|
||||
},
|
||||
async () => {
|
||||
//console.log(`[DONE] Task: ${num}`);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
);
|
||||
//return new LogTask(`Log ${num}`, { delay });
|
||||
}
|
||||
@@ -56,9 +56,9 @@ function getNamedTask(name: string, _func?: () => Promise<any>, delay?: number)
|
||||
return new ExecTask(
|
||||
name,
|
||||
{
|
||||
delay: delay ?? 0
|
||||
delay: delay ?? 0,
|
||||
},
|
||||
func
|
||||
func,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ describe("Flow tests", async () => {
|
||||
back
|
||||
.task(third)
|
||||
.getOutTasks()
|
||||
.map((t) => t.name)
|
||||
.map((t) => t.name),
|
||||
).toEqual(["second", "fourth"]);
|
||||
|
||||
const execution = back.createExecution();
|
||||
@@ -263,7 +263,7 @@ describe("Flow tests", async () => {
|
||||
back
|
||||
.task(third)
|
||||
.getOutTasks()
|
||||
.map((t) => t.name)
|
||||
.map((t) => t.name),
|
||||
).toEqual(["second", "fourth"]);
|
||||
|
||||
const execution = back.createExecution();
|
||||
@@ -324,8 +324,8 @@ describe("Flow tests", async () => {
|
||||
const first = getNamedTask("first", async () => {
|
||||
return {
|
||||
inner: {
|
||||
result: 2
|
||||
}
|
||||
result: 2,
|
||||
},
|
||||
};
|
||||
});
|
||||
const second = getNamedTask("second");
|
||||
@@ -361,7 +361,7 @@ describe("Flow tests", async () => {
|
||||
"[event]",
|
||||
event.isStart() ? "start" : "end",
|
||||
event.task().name,
|
||||
event.isStart() ? undefined : event.succeeded()
|
||||
event.isStart() ? undefined : event.succeeded(),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -389,7 +389,7 @@ describe("Flow tests", async () => {
|
||||
const second = new LogTask("Task 1");
|
||||
const third = new LogTask("Task 2", { delay: 50 });
|
||||
const fourth = new FetchTask("Fetch Something", {
|
||||
url: "https://jsonplaceholder.typicode.com/todos/1"
|
||||
url: "https://jsonplaceholder.typicode.com/todos/1",
|
||||
});
|
||||
const fifth = new LogTask("Task 4"); // without connection
|
||||
|
||||
@@ -405,7 +405,7 @@ describe("Flow tests", async () => {
|
||||
// @todo: fix
|
||||
const deserialized = Flow.fromObject("", original, {
|
||||
fetch: { cls: FetchTask },
|
||||
log: { cls: LogTask }
|
||||
log: { cls: LogTask },
|
||||
} as any);
|
||||
|
||||
const diffdeep = getObjectDiff(original, deserialized.toJSON());
|
||||
@@ -414,7 +414,7 @@ describe("Flow tests", async () => {
|
||||
expect(flow.startTask.name).toEqual(deserialized.startTask.name);
|
||||
expect(flow.respondingTask?.name).toEqual(
|
||||
// @ts-ignore
|
||||
deserialized.respondingTask?.name
|
||||
deserialized.respondingTask?.name,
|
||||
);
|
||||
|
||||
//console.log("--- creating original sequence");
|
||||
|
||||
Reference in New Issue
Block a user