mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 16:46:00 +00:00
added format command and added trailing commas to reduce conflicts
This commit is contained in:
@@ -21,7 +21,7 @@ export type TaskRenderProps<T extends Task = Task> = any;
|
||||
|
||||
export function dynamic<Type extends TSchema>(
|
||||
type: Type,
|
||||
parse?: (val: any | string) => Static<Type>
|
||||
parse?: (val: any | string) => Static<Type>,
|
||||
) {
|
||||
const guessDecode = (val: unknown): Static<Type> => {
|
||||
if (typeof val === "string") {
|
||||
@@ -46,7 +46,7 @@ export function dynamic<Type extends TSchema>(
|
||||
|
||||
return val as Static<Type>;
|
||||
};
|
||||
const title = type.title ?? type.type ? ucFirst(type.type) : "Raw";
|
||||
const title = (type.title ?? type.type) ? ucFirst(type.type) : "Raw";
|
||||
|
||||
return (
|
||||
Type.Transform(Type.Union([{ title, ...type }, Type.String({ title: "Template" })]))
|
||||
@@ -87,7 +87,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
Object.keys(params).length > 0
|
||||
) {
|
||||
throw new Error(
|
||||
`Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}`
|
||||
`Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
static async resolveParams<S extends TSchema>(
|
||||
schema: S,
|
||||
params: any,
|
||||
inputs: object = {}
|
||||
inputs: object = {},
|
||||
): Promise<StaticDecode<S>> {
|
||||
const newParams: any = {};
|
||||
const renderer = new SimpleRenderer(inputs, { strictVariables: true, renderKeys: true });
|
||||
@@ -141,9 +141,9 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
{
|
||||
key,
|
||||
value,
|
||||
error: e.message
|
||||
error: e.message,
|
||||
},
|
||||
"resolve-params"
|
||||
"resolve-params",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
const newParams = await Task.resolveParams(
|
||||
(this.constructor as any).schema,
|
||||
this._params,
|
||||
inputs
|
||||
inputs,
|
||||
);
|
||||
//console.log("--clone:newParams", this.name, newParams);
|
||||
|
||||
@@ -207,7 +207,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
} else {
|
||||
error = {
|
||||
type: "unknown",
|
||||
message: (e as any).message
|
||||
message: (e as any).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
|
||||
toJSON() {
|
||||
return {
|
||||
type: this.type,
|
||||
params: this.params
|
||||
params: this.params,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ export class TaskConnection {
|
||||
target: this.target.name,
|
||||
config: {
|
||||
...this.config,
|
||||
condition: this.config.condition?.toJSON()
|
||||
}
|
||||
condition: this.config.condition?.toJSON(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export class Condition {
|
||||
private constructor(
|
||||
public type: "success" | "error" | "matches",
|
||||
public path: string = "",
|
||||
public value: any = undefined
|
||||
public value: any = undefined,
|
||||
) {}
|
||||
|
||||
static default() {
|
||||
@@ -96,7 +96,7 @@ export class Condition {
|
||||
return {
|
||||
type: this.type,
|
||||
path: this.path.length === 0 ? undefined : this.path,
|
||||
value: this.value
|
||||
value: this.value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
|
||||
static override schema = Type.Object({
|
||||
url: Type.String({
|
||||
pattern: "^(http|https)://"
|
||||
pattern: "^(http|https)://",
|
||||
}),
|
||||
//method: Type.Optional(Type.Enum(FetchMethodsEnum)),
|
||||
//method: Type.Optional(dynamic(Type.String({ enum: FetchMethods, default: "GET" }))),
|
||||
@@ -22,14 +22,14 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
Type.Array(
|
||||
Type.Object({
|
||||
key: Type.String(),
|
||||
value: Type.String()
|
||||
})
|
||||
value: Type.String(),
|
||||
}),
|
||||
),
|
||||
JSON.parse
|
||||
)
|
||||
JSON.parse,
|
||||
),
|
||||
),
|
||||
body: Type.Optional(dynamic(Type.String())),
|
||||
normal: Type.Optional(dynamic(Type.Number(), Number.parseInt))
|
||||
normal: Type.Optional(dynamic(Type.Number(), Number.parseInt)),
|
||||
});
|
||||
|
||||
protected getBody(): string | undefined {
|
||||
@@ -46,7 +46,7 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
if (!FetchMethods.includes(this.params.method ?? "GET")) {
|
||||
throw this.error("Invalid method", {
|
||||
given: this.params.method,
|
||||
valid: FetchMethods
|
||||
valid: FetchMethods,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
|
||||
const result = await fetch(this.params.url, {
|
||||
method: this.params.method ?? "GET",
|
||||
headers,
|
||||
body
|
||||
body,
|
||||
});
|
||||
|
||||
//console.log("fetch:response", result);
|
||||
if (!result.ok) {
|
||||
throw this.error("Failed to fetch", {
|
||||
status: result.status,
|
||||
statusText: result.statusText
|
||||
statusText: result.statusText,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export class LogTask extends Task<typeof LogTask.schema> {
|
||||
type = "log";
|
||||
|
||||
static override schema = Type.Object({
|
||||
delay: Type.Number({ default: 10 })
|
||||
delay: Type.Number({ default: 10 }),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
@@ -8,7 +8,7 @@ export class RenderTask<Output extends Record<string, any>> extends Task<
|
||||
type = "render";
|
||||
|
||||
static override schema = Type.Object({
|
||||
render: Type.String()
|
||||
render: Type.String(),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class SubFlowTask<Output extends Record<string, any>> extends Task<
|
||||
static override schema = Type.Object({
|
||||
flow: Type.Any(),
|
||||
input: Type.Optional(dynamic(Type.Any(), JSON.parse)),
|
||||
loop: Type.Optional(Type.Boolean())
|
||||
loop: Type.Optional(Type.Boolean()),
|
||||
});
|
||||
|
||||
async execute() {
|
||||
|
||||
Reference in New Issue
Block a user