@shware/workflow-ui 2.2.5 → 2.2.6
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/cli.mjs +3 -57
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/plan-DtFyMukp.mjs +64 -0
- package/dist/plan-DtFyMukp.mjs.map +1 -0
- package/package.json +2 -2
- package/src/cli.ts +3 -1
- package/src/components/layout.ts +5 -1
- package/src/plan.ts +9 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { checkInFlight, compileConfig, describeInFlight, isConfig, pinnedWorkflows } from "@shware/workflow";
|
|
3
|
+
import { postgresJsStore } from "@shware/workflow/postgres-js";
|
|
4
|
+
import { runnerImport } from "vite";
|
|
5
|
+
import { t as findConfig } from "./cli.mjs";
|
|
6
|
+
// src/plan.ts
|
|
7
|
+
async function planDeploy(options) {
|
|
8
|
+
const cwd = options.cwd ?? process.cwd();
|
|
9
|
+
const configPath = findConfig(cwd, options.config);
|
|
10
|
+
const { module } = await runnerImport(configPath);
|
|
11
|
+
if (!isConfig(module.default)) throw new Error(`workflow-ui: ${relative(cwd, configPath)} must \`export default defineConfig({...})\``);
|
|
12
|
+
const config = module.default;
|
|
13
|
+
const bundle = compileConfig(config);
|
|
14
|
+
const schemaName = config.database?.schema;
|
|
15
|
+
const { store, close } = postgresJsStore(options.databaseUrl, schemaName === void 0 ? {} : { schema: schemaName });
|
|
16
|
+
try {
|
|
17
|
+
const schema = await store.checkSchema();
|
|
18
|
+
const pinned = schema.some(isEntryTableMissing) ? [] : await pinnedWorkflows(store);
|
|
19
|
+
const carried = new Set(bundle.workflows.map((w) => w.contentHash));
|
|
20
|
+
return {
|
|
21
|
+
pinned: pinned.map((pin) => ({
|
|
22
|
+
workflow: pin.workflow,
|
|
23
|
+
contentHash: pin.contentHash,
|
|
24
|
+
running: pin.running,
|
|
25
|
+
ir: pin.ir,
|
|
26
|
+
carried: carried.has(pin.contentHash)
|
|
27
|
+
})),
|
|
28
|
+
problems: checkInFlight(pinned, bundle, config),
|
|
29
|
+
schema
|
|
30
|
+
};
|
|
31
|
+
} finally {
|
|
32
|
+
await close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** `checkSchema`'s line for a missing entry ledger (`table "<schema>"."entry" is missing`). */
|
|
36
|
+
const isEntryTableMissing = (problem) => /^table (?:"[^"]*"\.)?"entry" is missing$/.test(problem);
|
|
37
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
38
|
+
/** The report as the lines the CLI prints. */
|
|
39
|
+
function formatPlan(report) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
const journeys = report.pinned.reduce((sum, pin) => sum + pin.running, 0);
|
|
42
|
+
if (report.pinned.length === 0) lines.push("no journey is running: nothing is pinned");
|
|
43
|
+
else {
|
|
44
|
+
lines.push(`${plural(report.pinned.length, "pinned version")}, ${plural(journeys, "running journey")}:`);
|
|
45
|
+
for (const pin of report.pinned) {
|
|
46
|
+
const note = pin.carried ? "" : " (finish on their version; this bundle changes the workflow)";
|
|
47
|
+
lines.push(` ${pin.workflow}@${pin.contentHash.slice(0, 8)} ${pin.running} running${note}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (report.schema.length > 0) {
|
|
51
|
+
lines.push("the database lacks (run the migrations before deploying):");
|
|
52
|
+
for (const problem of report.schema) lines.push(` ${problem}`);
|
|
53
|
+
}
|
|
54
|
+
if (report.problems.length === 0) lines.push("this bundle keeps every running journey: safe to deploy");
|
|
55
|
+
else {
|
|
56
|
+
lines.push("this bundle would break running journeys:");
|
|
57
|
+
for (const line of describeInFlight(report.problems)) lines.push(` ${line}`);
|
|
58
|
+
lines.push("fix the bundle (keep the segment or action, give the template a new id, make the prop optional), or deploy with POST /bundle/deploy?force=1 to fail them");
|
|
59
|
+
}
|
|
60
|
+
return lines;
|
|
61
|
+
}
|
|
62
|
+
export { formatPlan, planDeploy };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=plan-DtFyMukp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-DtFyMukp.mjs","names":[],"sources":["../src/plan.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport {\n type InFlightProblem,\n type JourneyConfig,\n type PinnedWorkflow,\n checkInFlight,\n compileConfig,\n describeInFlight,\n isConfig,\n pinnedWorkflows,\n} from '@shware/workflow';\nimport { postgresJsStore } from '@shware/workflow/postgres-js';\nimport { runnerImport } from 'vite';\nimport { findConfig } from './server';\n\n/**\n * `workflow-ui plan` — the deploy-time check, before the deploy: compiles the project and holds\n * the bundle, with the templates this code would serve, against the workflow versions journeys\n * are still running on in the database (`checkInFlight` in `@shware/workflow`). On Cloudflare a\n * new version's code serves the moment it is published, so the host's own refusal comes too late\n * to protect a running journey from a template change; CI runs this ahead of `wrangler deploy`\n * and stops on a non-zero exit.\n */\n\nexport interface PlanOptions {\n cwd?: string;\n config?: string;\n /** The engine's database, as `postgres` connects to it. */\n databaseUrl: string;\n}\n\nexport interface PlanReport {\n /**\n * Every workflow version with running journeys; `carried` when this bundle still contains that\n * exact version (otherwise those journeys finish on theirs, and new ones enter the new version).\n */\n pinned: (PinnedWorkflow & { carried: boolean })[];\n /** What this bundle would take from them; empty when the deploy is safe. */\n problems: InFlightProblem[];\n /** What the database lacks against the SDK's tables: migrations to run before the deploy. */\n schema: string[];\n}\n\nexport async function planDeploy(options: PlanOptions): Promise<PlanReport> {\n const cwd = options.cwd ?? process.cwd();\n const configPath = findConfig(cwd, options.config);\n const { module } = await runnerImport<{ default?: unknown }>(configPath);\n if (!isConfig(module.default)) {\n throw new Error(\n `workflow-ui: ${relative(cwd, configPath)} must \\`export default defineConfig({...})\\``\n );\n }\n const config: JourneyConfig = module.default;\n const bundle = compileConfig(config);\n const schemaName = config.database?.schema;\n const { store, close } = postgresJsStore(\n options.databaseUrl,\n schemaName === undefined ? {} : { schema: schemaName }\n );\n try {\n const schema = await store.checkSchema();\n // Running journeys live in the entry ledger: without that table (a database not migrated\n // yet) there is none to keep. Any other gap leaves the pins to read — a table this SDK\n // version adds says nothing about the journeys already running, and taking it for \"nothing\n // is pinned\" would report every deploy safe. A read that then fails fails the plan.\n const pinned = schema.some(isEntryTableMissing) ? [] : await pinnedWorkflows(store);\n const carried = new Set(bundle.workflows.map((w) => w.contentHash));\n return {\n pinned: pinned.map((pin) => ({\n workflow: pin.workflow,\n contentHash: pin.contentHash,\n running: pin.running,\n ir: pin.ir,\n carried: carried.has(pin.contentHash),\n })),\n problems: checkInFlight(pinned, bundle, config),\n schema,\n };\n } finally {\n await close();\n }\n}\n\n/** `checkSchema`'s line for a missing entry ledger (`table \"<schema>\".\"entry\" is missing`). */\nexport const isEntryTableMissing = (problem: string): boolean =>\n /^table (?:\"[^\"]*\"\\.)?\"entry\" is missing$/.test(problem);\n\nconst plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;\n\n/** The report as the lines the CLI prints. */\nexport function formatPlan(report: PlanReport): string[] {\n const lines: string[] = [];\n const journeys = report.pinned.reduce((sum, pin) => sum + pin.running, 0);\n if (report.pinned.length === 0) {\n lines.push('no journey is running: nothing is pinned');\n } else {\n lines.push(\n `${plural(report.pinned.length, 'pinned version')}, ${plural(journeys, 'running journey')}:`\n );\n for (const pin of report.pinned) {\n const note = pin.carried\n ? ''\n : ' (finish on their version; this bundle changes the workflow)';\n lines.push(` ${pin.workflow}@${pin.contentHash.slice(0, 8)} ${pin.running} running${note}`);\n }\n }\n if (report.schema.length > 0) {\n lines.push('the database lacks (run the migrations before deploying):');\n for (const problem of report.schema) lines.push(` ${problem}`);\n }\n if (report.problems.length === 0) {\n lines.push('this bundle keeps every running journey: safe to deploy');\n } else {\n lines.push('this bundle would break running journeys:');\n for (const line of describeInFlight(report.problems)) lines.push(` ${line}`);\n lines.push(\n 'fix the bundle (keep the segment or action, give the template a new id, make the prop optional), or deploy with POST /bundle/deploy?force=1 to fail them'\n );\n }\n return lines;\n}\n"],"mappings":";;;;;;AA2CA,eAAsB,WAAW,SAA2C;CAC1E,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;CACvC,MAAM,aAAa,WAAW,KAAK,QAAQ,MAAM;CACjD,MAAM,EAAE,WAAW,MAAM,aAAoC,UAAU;CACvE,IAAI,CAAC,SAAS,OAAO,OAAO,GAC1B,MAAM,IAAI,MACR,gBAAgB,SAAS,KAAK,UAAU,EAAE,6CAC5C;CAEF,MAAM,SAAwB,OAAO;CACrC,MAAM,SAAS,cAAc,MAAM;CACnC,MAAM,aAAa,OAAO,UAAU;CACpC,MAAM,EAAE,OAAO,UAAU,gBACvB,QAAQ,aACR,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,WAAW,CACvD;CACA,IAAI;EACF,MAAM,SAAS,MAAM,MAAM,YAAY;EAKvC,MAAM,SAAS,OAAO,KAAK,mBAAmB,IAAI,CAAC,IAAI,MAAM,gBAAgB,KAAK;EAClF,MAAM,UAAU,IAAI,IAAI,OAAO,UAAU,KAAK,MAAM,EAAE,WAAW,CAAC;EAClE,OAAO;GACL,QAAQ,OAAO,KAAK,SAAS;IAC3B,UAAU,IAAI;IACd,aAAa,IAAI;IACjB,SAAS,IAAI;IACb,IAAI,IAAI;IACR,SAAS,QAAQ,IAAI,IAAI,WAAW;GACtC,EAAE;GACF,UAAU,cAAc,QAAQ,QAAQ,MAAM;GAC9C;EACF;CACF,UAAU;EACR,MAAM,MAAM;CACd;AACF;;AAGA,MAAa,uBAAuB,YAClC,2CAA2C,KAAK,OAAO;AAEzD,MAAM,UAAU,GAAW,SAAiB,GAAG,EAAE,GAAG,OAAO,MAAM,IAAI,KAAK;;AAG1E,SAAgB,WAAW,QAA8B;CACvD,MAAM,QAAkB,CAAC;CACzB,MAAM,WAAW,OAAO,OAAO,QAAQ,KAAK,QAAQ,MAAM,IAAI,SAAS,CAAC;CACxE,IAAI,OAAO,OAAO,WAAW,GAC3B,MAAM,KAAK,0CAA0C;MAChD;EACL,MAAM,KACJ,GAAG,OAAO,OAAO,OAAO,QAAQ,gBAAgB,EAAE,IAAI,OAAO,UAAU,iBAAiB,EAAE,EAC5F;EACA,KAAK,MAAM,OAAO,OAAO,QAAQ;GAC/B,MAAM,OAAO,IAAI,UACb,KACA;GACJ,MAAM,KAAK,KAAK,IAAI,SAAS,GAAG,IAAI,YAAY,MAAM,GAAG,CAAC,EAAE,IAAI,IAAI,QAAQ,UAAU,MAAM;EAC9F;CACF;CACA,IAAI,OAAO,OAAO,SAAS,GAAG;EAC5B,MAAM,KAAK,2DAA2D;EACtE,KAAK,MAAM,WAAW,OAAO,QAAQ,MAAM,KAAK,KAAK,SAAS;CAChE;CACA,IAAI,OAAO,SAAS,WAAW,GAC7B,MAAM,KAAK,yDAAyD;MAC/D;EACL,MAAM,KAAK,2CAA2C;EACtD,KAAK,MAAM,QAAQ,iBAAiB,OAAO,QAAQ,GAAG,MAAM,KAAK,KAAK,MAAM;EAC5E,MAAM,KACJ,0JACF;CACF;CACA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/workflow-ui",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ShwareHQ/shware-sdk.git"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@floating-ui/react": "^0.27.20",
|
|
41
41
|
"@fontsource-variable/inter": "^5.3.0",
|
|
42
42
|
"@react-email/render": "^2.3.1",
|
|
43
|
-
"@shware/workflow": "12.0.
|
|
43
|
+
"@shware/workflow": "12.0.4",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.5",
|
|
45
45
|
"@tanstack/react-query": "^5.108.3",
|
|
46
46
|
"@tanstack/react-router": "^1.170.46",
|
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { generateSchema } from './generate';
|
|
3
|
-
import { formatPlan, planDeploy } from './plan';
|
|
4
3
|
import { startStudio } from './server';
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -102,6 +101,9 @@ async function main(): Promise<void> {
|
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
103
|
try {
|
|
104
|
+
// Loaded here, not at the top: `plan` is the one command that needs `postgres`, an optional
|
|
105
|
+
// peer — a static import would make every command, `--help` included, fail without it
|
|
106
|
+
const { formatPlan, planDeploy } = await import('./plan');
|
|
105
107
|
const report = await planDeploy({
|
|
106
108
|
databaseUrl,
|
|
107
109
|
...(args.config !== undefined ? { config: args.config } : {}),
|
package/src/components/layout.ts
CHANGED
|
@@ -212,7 +212,11 @@ function nodeData(n: NodeIR): CanvasNodeData {
|
|
|
212
212
|
case 'wait_until':
|
|
213
213
|
return {
|
|
214
214
|
title: `Wait until ${conditionLabel(n.condition, '…')}`,
|
|
215
|
-
|
|
215
|
+
// A timeout flow is drawn as its own arm; the two that are not must still read apart —
|
|
216
|
+
// one ends the journey, the other goes on to the next node
|
|
217
|
+
subtitle: Array.isArray(n.onTimeout)
|
|
218
|
+
? `timeout ${n.timeout.value}`
|
|
219
|
+
: `timeout ${n.timeout.value} → ${n.onTimeout === 'exit' ? 'exit' : 'continue'}`,
|
|
216
220
|
category: 'delay',
|
|
217
221
|
variant: 'card',
|
|
218
222
|
icon: 'wait_until',
|
package/src/plan.ts
CHANGED
|
@@ -59,10 +59,11 @@ export async function planDeploy(options: PlanOptions): Promise<PlanReport> {
|
|
|
59
59
|
);
|
|
60
60
|
try {
|
|
61
61
|
const schema = await store.checkSchema();
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
// Running journeys live in the entry ledger: without that table (a database not migrated
|
|
63
|
+
// yet) there is none to keep. Any other gap leaves the pins to read — a table this SDK
|
|
64
|
+
// version adds says nothing about the journeys already running, and taking it for "nothing
|
|
65
|
+
// is pinned" would report every deploy safe. A read that then fails fails the plan.
|
|
66
|
+
const pinned = schema.some(isEntryTableMissing) ? [] : await pinnedWorkflows(store);
|
|
66
67
|
const carried = new Set(bundle.workflows.map((w) => w.contentHash));
|
|
67
68
|
return {
|
|
68
69
|
pinned: pinned.map((pin) => ({
|
|
@@ -80,6 +81,10 @@ export async function planDeploy(options: PlanOptions): Promise<PlanReport> {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
/** `checkSchema`'s line for a missing entry ledger (`table "<schema>"."entry" is missing`). */
|
|
85
|
+
export const isEntryTableMissing = (problem: string): boolean =>
|
|
86
|
+
/^table (?:"[^"]*"\.)?"entry" is missing$/.test(problem);
|
|
87
|
+
|
|
83
88
|
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
84
89
|
|
|
85
90
|
/** The report as the lines the CLI prints. */
|