@protobase/server 0.67.10 → 0.67.11
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/dist/package.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import { badRequest } from "../problem.js";
|
|
2
|
+
import { requiredStepInputs } from "@protobase/schema/internal";
|
|
2
3
|
import { sql } from "kysely";
|
|
3
4
|
import { checkDefinition, problemText } from "@protobase/workflows";
|
|
4
5
|
//#region src/workflows/save-hook.ts
|
|
5
6
|
/**
|
|
6
7
|
* Checks a workflow's definition on every save that changes it, against the language's schema and the named-reads
|
|
7
8
|
* profile, with the step types the app has, and keeps it as the version the table's trigger numbered, saved by the
|
|
8
|
-
* caller. A refusal is a 400 problem naming each state and field, also listed as `problems
|
|
9
|
+
* caller. A refusal is a 400 problem naming each state and field, also listed as `problems`, and as the `definition`
|
|
10
|
+
* field's `errors` with the state and field in their `params`, for a form to show each on its step; the write rolls back.
|
|
9
11
|
*/
|
|
10
12
|
const workflowSaveHook = (schema, stepTypes) => async (event, trx) => {
|
|
11
13
|
if (event.resource.name !== "workflows" || !event.after) return;
|
|
12
14
|
if (event.operation !== "create" && event.operation !== "update") return;
|
|
13
15
|
if (event.operation === "update" && event.after.version === event.before?.version) return;
|
|
14
|
-
const problems = checkDefinition(event.after.definition, {
|
|
15
|
-
|
|
16
|
+
const problems = checkDefinition(event.after.definition, {
|
|
17
|
+
resources: stepTypes,
|
|
18
|
+
required: requiredStepInputs
|
|
19
|
+
});
|
|
20
|
+
if (problems.length > 0) {
|
|
21
|
+
const errors = problems.map((problem) => ({
|
|
22
|
+
code: "invalid-workflow",
|
|
23
|
+
field: "definition",
|
|
24
|
+
message: problemText(problem),
|
|
25
|
+
params: {
|
|
26
|
+
state: problem.state,
|
|
27
|
+
field: problem.field
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
throw badRequest("invalid-workflow", `The workflow cannot be saved: ${problems.map(problemText).join("; ")}`, {
|
|
31
|
+
problems,
|
|
32
|
+
errors
|
|
33
|
+
});
|
|
34
|
+
}
|
|
16
35
|
await sql`insert into ${sql.id(schema, "versions")} (workflow_id, version, definition, saved_by, tenant_id)
|
|
17
36
|
select w.id, w.version, w.definition, ${String(event.user.id)}, w.tenant_id from ${sql.id(schema, "workflows")} w where w.id = ${String(event.after.id)}`.execute(trx);
|
|
18
37
|
};
|
|
@@ -2,17 +2,10 @@ import { httpStep } from "./http-step.js";
|
|
|
2
2
|
import { mailStep } from "./mail-step.js";
|
|
3
3
|
import { pieceStep } from "./piece-step.js";
|
|
4
4
|
import { recordsSteps } from "./records-step.js";
|
|
5
|
+
import { workflowStepTypes } from "@protobase/schema/internal";
|
|
5
6
|
//#region src/workflows/step-types.ts
|
|
6
|
-
/** The step types a Task names as its `Resource`, as the
|
|
7
|
-
const stepTypeNames =
|
|
8
|
-
"app:http",
|
|
9
|
-
"app:records.create",
|
|
10
|
-
"app:records.update",
|
|
11
|
-
"app:records.get",
|
|
12
|
-
"app:records.list",
|
|
13
|
-
"app:mail.send",
|
|
14
|
-
"app:piece"
|
|
15
|
-
];
|
|
7
|
+
/** The step types a Task names as its `Resource`, as the editor offers them. */
|
|
8
|
+
const stepTypeNames = Object.keys(workflowStepTypes);
|
|
16
9
|
/** The step types of one segment, which sends mail with the mailer of the job that runs it. */
|
|
17
10
|
const stepTypes = ({ deps, schema, roles, allowPrivateAddresses }, mail) => {
|
|
18
11
|
const files = () => deps().files;
|
package/dist/workflows/store.js
CHANGED
|
@@ -17,15 +17,18 @@ const postgresRunStore = (schema) => {
|
|
|
17
17
|
from ${steps} where run_id = ${id} order by scope, seq`.execute(db);
|
|
18
18
|
return rows;
|
|
19
19
|
},
|
|
20
|
-
save: async (db, id,
|
|
20
|
+
save: async (db, id, records) => {
|
|
21
|
+
const row = (step) => sql`(${step.scope}, ${step.seq}::integer, ${step.state}, ${step.type}, ${step.status}, ${step.attempt}::integer,
|
|
22
|
+
${json(step.input)}::jsonb, ${json(step.output)}::jsonb, ${json(step.assigned)}::jsonb, ${step.next}, ${step.resumeAt ?? null}::timestamptz,
|
|
23
|
+
${step.error ?? null}, ${step.cause ?? null}, ${JSON.stringify(step.logs)}::jsonb, ${step.startedAt}::timestamptz, ${step.finishedAt}::timestamptz)`;
|
|
21
24
|
const { rows } = await sql`insert into ${steps}
|
|
22
25
|
(run_id, tenant_id, scope, seq, state, type, status, attempt, input, output, assigned, next, resume_at, error, cause, logs, started_at, finished_at)
|
|
23
|
-
select r.id, r.tenant_id,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
select r.id, r.tenant_id, s.*
|
|
27
|
+
from ${runs} r, (values ${sql.join(records.map(row))})
|
|
28
|
+
as s (scope, seq, state, type, status, attempt, input, output, assigned, next, resume_at, error, cause, logs, started_at, finished_at)
|
|
29
|
+
where r.id = ${id}
|
|
27
30
|
on conflict (run_id, scope, seq) do nothing returning id`.execute(db);
|
|
28
|
-
return rows.length
|
|
31
|
+
return rows.length === records.length;
|
|
29
32
|
},
|
|
30
33
|
update: async (db, id, change) => {
|
|
31
34
|
const ended = change.status === "succeeded" || change.status === "failed";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.67.
|
|
3
|
+
"version": "0.67.11",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.67.
|
|
48
|
-
"@protobase/query": "0.67.
|
|
49
|
-
"@protobase/schema": "0.67.
|
|
50
|
-
"@protobase/workflows": "0.67.
|
|
47
|
+
"@protobase/layout": "0.67.11",
|
|
48
|
+
"@protobase/query": "0.67.11",
|
|
49
|
+
"@protobase/schema": "0.67.11",
|
|
50
|
+
"@protobase/workflows": "0.67.11",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@react-pdf/primitives": "^4.4.0",
|
|
53
53
|
"@react-pdf/renderer": "^4.9.0",
|