Add credential references for steps: field ids, addUse/findFieldRef, usesView (Refs #24)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
19
src/model.js
19
src/model.js
@@ -31,7 +31,12 @@ import { isImageDataUrl, MAX_IMAGE_DATA_CHARS } from './images.js';
|
||||
// frames: [Frame] } -- a numbered series of pictures with optional text.
|
||||
// Frame: { image: PNG/JPEG data URL or '', text, layout: 'right'|'under'|'none', secret?: boolean,
|
||||
// ifStuck?: string, what to do if the screen looks different or the step fails
|
||||
// stop?: boolean } "stop here and call someone" marker; ifStuck says who/why
|
||||
// stop?: boolean, "stop here and call someone" marker; ifStuck says who/why
|
||||
// uses?: [{ record: <record id>, field: <field id> }] credentials this step needs,
|
||||
// shown beside the step with Show/Hide and Copy. A reference
|
||||
// that no longer resolves is shown as missing, never an error.
|
||||
// A record Field may carry `id` (unique within its record): assigned the first time a step
|
||||
// references it, so the reference survives reordering and renaming the field.
|
||||
// A sequence may also carry `captured: 'YYYY-MM-DD'`, set when a step is captured from the screen.
|
||||
// A sequence lives in the same ordered list as the records (records sections) or
|
||||
// items (steps / checklist sections), so it sits wherever the user puts it, but it
|
||||
@@ -168,12 +173,18 @@ export function validate(doc) {
|
||||
if (!DATE_RE.test(r.updated ?? '')) errs.push(`${where}: updated must be YYYY-MM-DD`);
|
||||
if (r.notes !== undefined && !isStr(r.notes)) errs.push(`${where}: notes must be a string`);
|
||||
if (!Array.isArray(r.fields)) return errs.push(`${where}: fields must be an array`);
|
||||
const fieldIds = new Set();
|
||||
r.fields.forEach((f, k) => {
|
||||
const fw = `${where}.fields[${k}]`;
|
||||
if (!isObj(f)) return errs.push(`${fw}: must be an object`);
|
||||
if (!isStr(f.label) || !f.label) errs.push(`${fw}: missing label`);
|
||||
if (!isStr(f.value)) errs.push(`${fw}: value must be a string`);
|
||||
if (f.secret !== undefined && typeof f.secret !== 'boolean') errs.push(`${fw}: secret must be a boolean`);
|
||||
if (f.id !== undefined) {
|
||||
if (!isStr(f.id) || !f.id) errs.push(`${fw}: id must be a non-empty string`);
|
||||
else if (fieldIds.has(f.id)) errs.push(`${fw}: duplicate field id "${f.id}"`);
|
||||
else fieldIds.add(f.id);
|
||||
}
|
||||
if (f.kind !== undefined && !FIELD_KINDS.includes(f.kind)) errs.push(`${fw}: unknown kind "${f.kind}"`);
|
||||
if (f.kind === 'image' && isStr(f.value) && f.value !== '' && !isImageDataUrl(f.value)) {
|
||||
errs.push(`${fw}: image must be a PNG or JPEG under ${Math.round(MAX_IMAGE_DATA_CHARS / 1e6)} MB`);
|
||||
@@ -199,6 +210,12 @@ export function validate(doc) {
|
||||
if (f.secret !== undefined && typeof f.secret !== 'boolean') errs.push(`${fw}: secret must be a boolean`);
|
||||
if (f.ifStuck !== undefined && !isStr(f.ifStuck)) errs.push(`${fw}: ifStuck must be a string`);
|
||||
if (f.stop !== undefined && typeof f.stop !== 'boolean') errs.push(`${fw}: stop must be a boolean`);
|
||||
if (f.uses !== undefined) {
|
||||
if (!Array.isArray(f.uses)) errs.push(`${fw}: uses must be an array`);
|
||||
else f.uses.forEach((u, m) => {
|
||||
if (!isObj(u) || !isStr(u.record) || !u.record || !isStr(u.field) || !u.field) errs.push(`${fw}.uses[${m}]: needs record and field ids`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user