Skip to content

Commit b667c4f

Browse files
committed
refactor: move the workflowId to a top level not catch-all
Signed-off-by: Simon Emms <simon@simonemms.com>
1 parent f1f119d commit b667c4f

File tree

16 files changed

+2048
-133
lines changed

16 files changed

+2048
-133
lines changed

src/lib/export/yaml.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export function exportToYaml(file: WorkflowFile): ExportResult {
8989

9090
const doc: Record<string, unknown> = {
9191
document: exportDocument(file),
92+
input: {
93+
schema: {
94+
format: file.input.schema.format,
95+
document: file.input.schema.document,
96+
},
97+
},
9298
do: topLevelTasks,
9399
};
94100

src/lib/i18n/messages/en.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"localeEn": "English (International)",
1919
"localeEnGb": "English (British)",
2020
"exportYaml": "Export YAML",
21+
"editInputSchema": "Edit input schema",
2122
"noGraph": "No graph to display.",
2223
"exportDialog": "YAML export"
2324
},
@@ -403,6 +404,31 @@
403404
"bodyCount": "body ({{count}} tasks)"
404405
}
405406
},
407+
"input": {
408+
"pageTitle": "Editing Input Schema",
409+
"backToEditor": "← Back to editor",
410+
"saving": "Saving…",
411+
"saved": "Saved",
412+
"unsaved": "Unsaved changes",
413+
"saveFailed": "Save failed",
414+
"schema": {
415+
"fields": "Fields",
416+
"colName": "Name",
417+
"colType": "Type",
418+
"colRequired": "Required",
419+
"addField": "+ Add field",
420+
"deleteField": "Delete field",
421+
"typeString": "string",
422+
"typeNumber": "number",
423+
"typeBoolean": "boolean",
424+
"typeObject": "object",
425+
"typeArray": "array",
426+
"itemsLabel": "Items",
427+
"addChildField": "+ Add child field",
428+
"errorNameRequired": "Name is required",
429+
"errorNameDuplicate": "Duplicate name"
430+
}
431+
},
406432
"validation": {
407433
"loop": {
408434
"collectionRequired": "Collection is required",

src/lib/tasks/actions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export function createWorkflowFile(document: DocumentMetadata): WorkflowFile {
7373
};
7474
return {
7575
document,
76+
input: {
77+
schema: { format: 'json', document: { type: 'object', properties: {} } },
78+
},
7679
workflows: { [id]: workflow },
7780
order: [id],
7881
};

src/lib/tasks/model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ export type DocumentMetadata = {
4141
metadata?: Record<string, unknown>;
4242
};
4343

44+
// Input schema — mirrors the Zigflow DSL `input.schema:` block.
45+
// `document` is a raw JSON Schema object; the Studio preserves it as-is.
46+
export type WorkflowSchema = {
47+
format: string;
48+
document: Record<string, unknown>;
49+
};
50+
51+
export type WorkflowInput = {
52+
schema: WorkflowSchema;
53+
};
54+
4455
export type WorkflowFile = {
4556
document: DocumentMetadata;
57+
input: WorkflowInput;
4658
workflows: Record<string, NamedWorkflow>;
4759
order: string[]; // stable ordering of named workflows
4860
};

src/lib/tasks/parse.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import type {
6666
TryNode,
6767
WaitConfig,
6868
WorkflowFile,
69+
WorkflowInput,
70+
WorkflowSchema,
6971
} from './model';
7072
import { ZIGFLOW_ID_KEY } from './model';
7173

@@ -121,6 +123,20 @@ export function parseWorkflowFile(
121123

122124
const doEntries = (raw['do'] as RawEntry[]) ?? [];
123125

126+
// Parse input.schema — default when absent.
127+
const rawInput = raw['input'] as Record<string, unknown> | undefined;
128+
const rawSchema = rawInput?.['schema'] as Record<string, unknown> | undefined;
129+
const schema: WorkflowSchema = rawSchema
130+
? {
131+
format: String(rawSchema['format'] ?? 'json'),
132+
document: (rawSchema['document'] ?? {
133+
type: 'object',
134+
properties: {},
135+
}) as Record<string, unknown>,
136+
}
137+
: { format: 'json', document: { type: 'object', properties: {} } };
138+
const input: WorkflowInput = { schema };
139+
124140
const ctx: ParseCtx = { modified: false, newFormat: false };
125141

126142
// Detect format: new format if every entry's value has a `do:` key.
@@ -133,12 +149,12 @@ export function parseWorkflowFile(
133149

134150
if (isNewFormat) {
135151
ctx.newFormat = true;
136-
const workflowFile = parseNewFormat(doEntries, document, ctx);
152+
const workflowFile = parseNewFormat(doEntries, document, input, ctx);
137153
return { workflowFile, modified: ctx.modified };
138154
}
139155

140156
// Old format: flat steps with hoisted sub-graph entries.
141-
return parseOldFormat(doEntries, document, ctx);
157+
return parseOldFormat(doEntries, document, input, ctx);
142158
}
143159

144160
// ---------------------------------------------------------------------------
@@ -154,6 +170,7 @@ export function parseWorkflowFile(
154170
function parseNewFormat(
155171
doEntries: RawEntry[],
156172
document: DocumentMetadata,
173+
input: WorkflowInput,
157174
ctx: ParseCtx,
158175
): WorkflowFile {
159176
const workflows: Record<string, NamedWorkflow> = {};
@@ -182,7 +199,7 @@ function parseNewFormat(
182199
order.push(id);
183200
}
184201

185-
return { document, workflows, order };
202+
return { document, input, workflows, order };
186203
}
187204

188205
// ---------------------------------------------------------------------------
@@ -196,6 +213,7 @@ function parseNewFormat(
196213
function parseOldFormat(
197214
doEntries: RawEntry[],
198215
document: DocumentMetadata,
216+
input: WorkflowInput,
199217
ctx: ParseCtx,
200218
): ParseResult {
201219
// Build a flat map of all named entries for hoisted branch resolution.
@@ -220,6 +238,7 @@ function parseOldFormat(
220238

221239
const workflowFile: WorkflowFile = {
222240
document,
241+
input,
223242
workflows: { [workflowId]: workflow },
224243
order: [workflowId],
225244
};

0 commit comments

Comments
 (0)