@pipelex/mthds-form 0.2.0 → 0.4.0
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/README.md +7 -2
- package/dist/chunk-6XD6UZSU.js +28 -0
- package/dist/chunk-6XD6UZSU.js.map +1 -0
- package/dist/chunk-7BMOPXDY.js +205 -0
- package/dist/chunk-7BMOPXDY.js.map +1 -0
- package/dist/chunk-GKV77RAS.js +46 -0
- package/dist/chunk-GKV77RAS.js.map +1 -0
- package/dist/chunk-HARYEWNG.js +31 -0
- package/dist/chunk-HARYEWNG.js.map +1 -0
- package/dist/chunk-KFZ5MZOM.js +44 -0
- package/dist/chunk-KFZ5MZOM.js.map +1 -0
- package/dist/chunk-NMT7BRLO.js +40 -0
- package/dist/chunk-NMT7BRLO.js.map +1 -0
- package/dist/chunk-O4O3QNVC.js +146 -0
- package/dist/chunk-O4O3QNVC.js.map +1 -0
- package/dist/chunk-PM55AHRO.js +52 -0
- package/dist/chunk-PM55AHRO.js.map +1 -0
- package/dist/chunk-RPA7DNSK.js +41 -0
- package/dist/chunk-RPA7DNSK.js.map +1 -0
- package/dist/chunk-V3OV2XQT.js +12 -0
- package/dist/chunk-V3OV2XQT.js.map +1 -0
- package/dist/chunk-VMLXO5JS.js +132 -0
- package/dist/chunk-VMLXO5JS.js.map +1 -0
- package/dist/chunk-VTPUDBSJ.js +61 -0
- package/dist/chunk-VTPUDBSJ.js.map +1 -0
- package/dist/chunk-WXBSM2CE.js +201 -0
- package/dist/chunk-WXBSM2CE.js.map +1 -0
- package/dist/chunk-XEPD5VJQ.js +99 -0
- package/dist/chunk-XEPD5VJQ.js.map +1 -0
- package/dist/core/contracts.d.ts +143 -0
- package/dist/core/contracts.js +4 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/date-format.d.ts +87 -0
- package/dist/core/date-format.js +3 -0
- package/dist/core/date-format.js.map +1 -0
- package/dist/core/derive.d.ts +20 -0
- package/dist/core/derive.js +7 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{descriptor-X6MwFIWu.d.ts → core/descriptor.d.ts} +42 -1
- package/dist/core/descriptor.js +3 -0
- package/dist/core/descriptor.js.map +1 -0
- package/dist/core/gate-validator.d.ts +27 -0
- package/dist/core/gate-validator.js +4 -0
- package/dist/core/gate-validator.js.map +1 -0
- package/dist/core/gate.d.ts +144 -0
- package/dist/core/gate.js +13 -0
- package/dist/core/gate.js.map +1 -0
- package/dist/core/index.d.ts +12 -615
- package/dist/core/index.js +14 -1
- package/dist/core/native-concepts.d.ts +78 -0
- package/dist/core/native-concepts.js +3 -0
- package/dist/core/native-concepts.js.map +1 -0
- package/dist/core/normalize-schema.d.ts +30 -0
- package/dist/core/normalize-schema.js +4 -0
- package/dist/core/normalize-schema.js.map +1 -0
- package/dist/core/own-property.d.ts +46 -0
- package/dist/core/own-property.js +3 -0
- package/dist/core/own-property.js.map +1 -0
- package/dist/core/readiness.d.ts +89 -0
- package/dist/core/readiness.js +4 -0
- package/dist/core/readiness.js.map +1 -0
- package/dist/core/schema-utils.d.ts +74 -0
- package/dist/core/schema-utils.js +3 -0
- package/dist/core/schema-utils.js.map +1 -0
- package/dist/core/validation-message.d.ts +39 -0
- package/dist/core/validation-message.js +4 -0
- package/dist/core/validation-message.js.map +1 -0
- package/dist/core/values.d.ts +91 -0
- package/dist/core/values.js +11 -0
- package/dist/core/values.js.map +1 -0
- package/dist/core/wire-format.d.ts +95 -0
- package/dist/core/wire-format.js +7 -0
- package/dist/core/wire-format.js.map +1 -0
- package/dist/react/index.d.ts +22 -1
- package/dist/react/index.js +128 -48
- package/dist/react/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -1
- package/dist/chunk-YWMUM7BC.js +0 -966
- package/dist/chunk-YWMUM7BC.js.map +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { inflateAllInputs, deflateAllInputs } from './chunk-7BMOPXDY.js';
|
|
2
|
+
import { isFilled } from './chunk-PM55AHRO.js';
|
|
3
|
+
import { buildRunFields } from './chunk-VMLXO5JS.js';
|
|
4
|
+
import { isOptionalInput, isPluralInput } from './chunk-HARYEWNG.js';
|
|
5
|
+
import { ownProp } from './chunk-V3OV2XQT.js';
|
|
6
|
+
|
|
7
|
+
// src/core/values.ts
|
|
8
|
+
function wrapContent(field, value) {
|
|
9
|
+
return field.contentKey === void 0 ? value : { [field.contentKey]: value };
|
|
10
|
+
}
|
|
11
|
+
function unwrapContent(field, value) {
|
|
12
|
+
const key = field.contentKey;
|
|
13
|
+
if (key === void 0 || !value || typeof value !== "object" || Array.isArray(value))
|
|
14
|
+
return value;
|
|
15
|
+
return ownProp(value, key);
|
|
16
|
+
}
|
|
17
|
+
var MAX_UNWRAP_DEPTH = 8;
|
|
18
|
+
function textFromStored(value, depth = 0) {
|
|
19
|
+
if (value == null) return void 0;
|
|
20
|
+
if (typeof value === "string") return value;
|
|
21
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
22
|
+
if (typeof value !== "object" || depth >= MAX_UNWRAP_DEPTH) return void 0;
|
|
23
|
+
const envelope = value;
|
|
24
|
+
if ("text" in envelope) return textFromStored(envelope.text, depth + 1);
|
|
25
|
+
if ("content" in envelope) return textFromStored(envelope.content, depth + 1);
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
function fromRjsf(field, value) {
|
|
29
|
+
switch (field.kind) {
|
|
30
|
+
case "text":
|
|
31
|
+
case "prose":
|
|
32
|
+
return textFromStored(value);
|
|
33
|
+
case "number": {
|
|
34
|
+
const raw = unwrapContent(field, value);
|
|
35
|
+
if (typeof raw === "number") return Number.isFinite(raw) ? raw : void 0;
|
|
36
|
+
if (typeof raw === "string" && raw.trim() !== "") {
|
|
37
|
+
const parsed = Number(raw);
|
|
38
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
39
|
+
}
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
case "boolean": {
|
|
43
|
+
const raw = unwrapContent(field, value);
|
|
44
|
+
return typeof raw === "boolean" ? raw : void 0;
|
|
45
|
+
}
|
|
46
|
+
case "unknown":
|
|
47
|
+
if (typeof value === "string") return value;
|
|
48
|
+
if (value == null) return void 0;
|
|
49
|
+
if (typeof value === "object") {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.stringify(value, null, 2);
|
|
52
|
+
} catch {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return String(value);
|
|
57
|
+
case "document":
|
|
58
|
+
case "image": {
|
|
59
|
+
if (value && typeof value === "object") {
|
|
60
|
+
const o = value;
|
|
61
|
+
return o.url ? { url: String(o.url), filename: o.filename } : void 0;
|
|
62
|
+
}
|
|
63
|
+
return typeof value === "string" && value ? { url: value } : void 0;
|
|
64
|
+
}
|
|
65
|
+
case "object": {
|
|
66
|
+
const obj = value && typeof value === "object" ? value : {};
|
|
67
|
+
const out = {};
|
|
68
|
+
for (const child of field.fields) out[child.name] = fromRjsf(child, ownProp(obj, child.name));
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
case "list": {
|
|
72
|
+
const arr = Array.isArray(value) ? value : [];
|
|
73
|
+
return arr.map((item) => fromRjsf(field.item, item));
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function toRjsf(field, value, collapseEmpty = true) {
|
|
80
|
+
switch (field.kind) {
|
|
81
|
+
case "text":
|
|
82
|
+
case "prose":
|
|
83
|
+
return wrapContent(field, typeof value === "string" ? value : "");
|
|
84
|
+
case "number":
|
|
85
|
+
return typeof value === "number" && Number.isFinite(value) ? wrapContent(field, value) : void 0;
|
|
86
|
+
case "boolean":
|
|
87
|
+
return typeof value === "boolean" ? wrapContent(field, value) : void 0;
|
|
88
|
+
case "unknown":
|
|
89
|
+
return typeof value === "string" ? value : "";
|
|
90
|
+
case "document":
|
|
91
|
+
case "image": {
|
|
92
|
+
const url = value && typeof value === "object" ? value.url : value;
|
|
93
|
+
const filename = value && typeof value === "object" ? value.filename : void 0;
|
|
94
|
+
return { url: url ? String(url) : "", ...filename ? { filename } : {} };
|
|
95
|
+
}
|
|
96
|
+
case "object": {
|
|
97
|
+
const obj = value && typeof value === "object" ? value : {};
|
|
98
|
+
const out = {};
|
|
99
|
+
for (const child of field.fields) out[child.name] = toRjsf(child, ownProp(obj, child.name));
|
|
100
|
+
return collapseEmpty && !isFilled(out) ? void 0 : out;
|
|
101
|
+
}
|
|
102
|
+
case "list": {
|
|
103
|
+
const arr = Array.isArray(value) ? value : [];
|
|
104
|
+
return arr.map((item) => toRjsf(field.item, item, false));
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function runValuesFromStore(inputData, fields, inputSchemas) {
|
|
111
|
+
const full = inflateAllInputs(inputData ?? {}, inputSchemas);
|
|
112
|
+
const out = {};
|
|
113
|
+
for (const field of fields) out[field.name] = fromRjsf(field, ownProp(full, field.name));
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function rjsfDataFromRunValues(values, fields) {
|
|
117
|
+
const full = {};
|
|
118
|
+
for (const field of fields) full[field.name] = toRjsf(field, ownProp(values, field.name));
|
|
119
|
+
return full;
|
|
120
|
+
}
|
|
121
|
+
function storeInputDataFromRunValues(values, fields, inputSchemas) {
|
|
122
|
+
return deflateAllInputs(rjsfDataFromRunValues(values, fields), inputSchemas);
|
|
123
|
+
}
|
|
124
|
+
function apiInputsFromRunValues(values, fields, inputSchemas) {
|
|
125
|
+
const out = {};
|
|
126
|
+
for (const field of fields) {
|
|
127
|
+
const schema = ownProp(inputSchemas, field.name);
|
|
128
|
+
if (!schema) continue;
|
|
129
|
+
const value = ownProp(values, field.name);
|
|
130
|
+
if (isOptionalInput(schema) && !isFilled(value)) continue;
|
|
131
|
+
if (isPluralInput(schema) && !isFilled(value)) {
|
|
132
|
+
out[field.name] = [];
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
out[field.name] = { concept: schema.concept_ref, content: toRjsf(field, value) };
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
function hasWorkingMemoryRoot(value) {
|
|
140
|
+
return !!value && typeof value === "object" && "working_memory" in value && !!value.working_memory && typeof value.working_memory.root === "object";
|
|
141
|
+
}
|
|
142
|
+
function entryConceptRef(data) {
|
|
143
|
+
if (!data || typeof data !== "object") return void 0;
|
|
144
|
+
const raw = data.concept;
|
|
145
|
+
if (raw && typeof raw === "object")
|
|
146
|
+
return (raw.concept_code ?? raw.code) || void 0;
|
|
147
|
+
if (typeof raw === "string") return raw;
|
|
148
|
+
return data.concept_code || void 0;
|
|
149
|
+
}
|
|
150
|
+
function outputsFromPipeOutput(pipeOutput, inputKeys) {
|
|
151
|
+
if (!hasWorkingMemoryRoot(pipeOutput)) return null;
|
|
152
|
+
const wm = pipeOutput.working_memory;
|
|
153
|
+
const entries = Object.entries(wm.root).filter(([key]) => !inputKeys.includes(key));
|
|
154
|
+
if (entries.length === 0) return null;
|
|
155
|
+
const toEntry = ([key, data]) => ({
|
|
156
|
+
key,
|
|
157
|
+
conceptRef: entryConceptRef(data),
|
|
158
|
+
value: data?.content ?? data
|
|
159
|
+
});
|
|
160
|
+
const mainKey = wm.aliases?.["main_stuff"];
|
|
161
|
+
const mainEntry = mainKey && Object.prototype.hasOwnProperty.call(wm.root, mainKey) ? [mainKey, wm.root[mainKey]] : entries[entries.length - 1];
|
|
162
|
+
const intermediates = entries.filter(([key]) => key !== mainEntry[0]).map(toEntry);
|
|
163
|
+
return { main: toEntry(mainEntry), intermediates };
|
|
164
|
+
}
|
|
165
|
+
function inputDataFromWorkingMemory(workingMemory, inputSchemas) {
|
|
166
|
+
const root = workingMemory?.root;
|
|
167
|
+
if (!root || typeof root !== "object") return null;
|
|
168
|
+
const full = {};
|
|
169
|
+
let found = false;
|
|
170
|
+
for (const key of Object.keys(inputSchemas)) {
|
|
171
|
+
const entry = ownProp(root, key);
|
|
172
|
+
if (entry && typeof entry === "object" && "content" in entry) {
|
|
173
|
+
full[key] = entry.content;
|
|
174
|
+
found = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!found) return null;
|
|
178
|
+
return deflateAllInputs(full, inputSchemas);
|
|
179
|
+
}
|
|
180
|
+
function fieldsForContract(contract) {
|
|
181
|
+
return contract?.inputs ? buildRunFields(contract.inputs) : [];
|
|
182
|
+
}
|
|
183
|
+
function setValueAtPath(root, path, value) {
|
|
184
|
+
const head = path[0];
|
|
185
|
+
if (head === void 0) return root;
|
|
186
|
+
const rest = path.slice(1);
|
|
187
|
+
if (rest.length === 0) return { ...root, [head]: value };
|
|
188
|
+
const nextSeg = rest[0];
|
|
189
|
+
const child = root[head];
|
|
190
|
+
if (/^\d+$/.test(nextSeg)) {
|
|
191
|
+
const arr = Array.isArray(child) ? child.slice() : [];
|
|
192
|
+
const idx = Number(nextSeg);
|
|
193
|
+
arr[idx] = rest.length === 1 ? value : setValueAtPath(arr[idx] ?? {}, rest.slice(1), value);
|
|
194
|
+
return { ...root, [head]: arr };
|
|
195
|
+
}
|
|
196
|
+
return { ...root, [head]: setValueAtPath(child ?? {}, rest, value) };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues };
|
|
200
|
+
//# sourceMappingURL=chunk-WXBSM2CE.js.map
|
|
201
|
+
//# sourceMappingURL=chunk-WXBSM2CE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/values.ts"],"names":[],"mappings":";;;;;;;AA6CA,SAAS,WAAA,CAAY,OAAiB,KAAA,EAAyB;AAC7D,EAAA,OAAO,KAAA,CAAM,eAAe,MAAA,GAAY,KAAA,GAAQ,EAAE,CAAC,KAAA,CAA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AO,EAAE,GAAG,IAAA,EAAM,CAAC,IAAI,GAAG,cAAA,CAAgB,KAAA,IAAkB,EAAC,EAAG,IAAA,EAAM,KAAK,CAAA,EAAE;AAC/E","file":"chunk-WXBSM2CE.js","sourcesContent":["/**\n * Bridges the `MethodRunner`'s field values to the rest of the host.\n *\n * The method-store keeps inputs in the *simplified* format and runs send the\n * *full* RJSF form shape - both already handled by `inflate/deflateAllInputs`.\n * The only gap is that a few field controls use a friendlier value than RJSF: a\n * scalar is the bare scalar where the full shape is the content model its\n * concept declares (`{ text }`, `{ number }`, `{ yes_no }`), and a file is\n * `{ url, filename }`. `fromRjsf`/`toRjsf` translate just those, so store\n * reads/writes and run payloads stay byte-for-byte compatible with the proven\n * playground path.\n *\n * Which property a scalar wraps into is NOT decided here - it arrives on the\n * descriptor as `contentKey`, derived from the contract by `buildRunFields`.\n *\n * Pure module - no React, unit-tested.\n */\nimport type { RunField } from './descriptor';\nimport { buildRunFields } from './derive';\nimport { ownProp } from './own-property';\nimport { isFilled } from './readiness';\nimport { isOptionalInput, isPluralInput } from './contracts';\nimport { deflateAllInputs, inflateAllInputs } from './wire-format';\nimport type { PipeIOContract, PipeInputContract } from './contracts';\n\ntype Dict = Record<string, unknown>;\ntype InputSchemas = Record<string, PipeInputContract>;\n\n// ─── RJSF full shape ↔ RunField value ──────────────────────────────────────\n\n/**\n * Put a scalar back inside the content model its concept declares:\n * `\"hi\"` → `{ text: \"hi\" }`, `2` → `{ number: 2 }`, `false` → `{ yes_no: false }`.\n *\n * The property name comes from the DESCRIPTOR (`contentKey`, stamped by\n * `buildRunFields` - the only reader of JSON Schema). This module holds no\n * taxonomy of its own, which is the point: the version that did held a list of\n * concepts that wrap, `native.Number` was missing from it, and every run\n * carrying a number was rejected by the gate against `NumberContent`.\n *\n * A field with no `contentKey` keeps its value plain. That is not an oversight\n * either - a child property of a structured concept, or a custom concept whose\n * schema is a bare string, IS its value, and wrapping it double-nests it\n * (`{ text: { text } }`) into a payload no schema accepts.\n */\nfunction wrapContent(field: RunField, value: unknown): unknown {\n return field.contentKey === undefined ? value : { [field.contentKey]: value };\n}\n\n/**\n * The inverse. A value that is already bare passes through untouched: persisted\n * `inputData` predates the number and yes/no wrappers, and an inputs.json\n * written by hand or by an agent says `2`, not `{number: 2}`.\n */\nfunction unwrapContent(field: RunField, value: unknown): unknown {\n const key = field.contentKey;\n if (key === undefined || !value || typeof value !== 'object' || Array.isArray(value))\n return value;\n return ownProp(value as Record<string, unknown>, key);\n}\n\n/** How deep a nested `{ text: … }` / `{ content: … }` chain we bother unwrapping. */\nconst MAX_UNWRAP_DEPTH = 8;\n\n/**\n * Pull a plain string out of whatever the store hands a text field.\n *\n * Persisted `inputData` carries historical corruptions - a double-wrapped\n * `{ text: { text } }`, a `{ concept, content }` envelope that was never\n * deflated - and the old fallback ran `String()` over them, which renders the\n * literal `\"[object Object]\"` into the textarea. That is worse than showing\n * nothing: it looks exactly like content the user typed, and one keystroke\n * later it is content the user typed. So unwrap the envelopes we know, and give\n * up with `undefined` (an empty field) rather than displaying garbage.\n *\n * Genuine primitives still stringify - a number or a boolean in a text slot is\n * a value, not a wrapper.\n */\nfunction textFromStored(value: unknown, depth = 0): string | undefined {\n if (value == null) return undefined;\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (typeof value !== 'object' || depth >= MAX_UNWRAP_DEPTH) return undefined;\n const envelope = value as { text?: unknown; content?: unknown };\n if ('text' in envelope) return textFromStored(envelope.text, depth + 1);\n if ('content' in envelope) return textFromStored(envelope.content, depth + 1);\n return undefined;\n}\n\n/** RJSF full form value → the runner's field value. */\nfunction fromRjsf(field: RunField, value: unknown): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return textFromStored(value);\n case 'number': {\n // The control holds `number | undefined`. A numeric STRING is tolerated\n // because that is what a hand-written inputs.json tends to carry; anything\n // else empties the field rather than feeding NaN to a number input.\n const raw = unwrapContent(field, value);\n if (typeof raw === 'number') return Number.isFinite(raw) ? raw : undefined;\n if (typeof raw === 'string' && raw.trim() !== '') {\n const parsed = Number(raw);\n return Number.isFinite(parsed) ? parsed : undefined;\n }\n return undefined;\n }\n case 'boolean': {\n // Strictly a real boolean, deliberately: pipelex declares `YesNoContent.\n // yes_no` with `strict=True` precisely to refuse \"yes\"/1/\"true\", and\n // coercing here would smuggle back in what the runtime closed off.\n const raw = unwrapContent(field, value);\n return typeof raw === 'boolean' ? raw : undefined;\n }\n case 'unknown':\n // The escape hatch is a raw-JSON textarea, so a structured value belongs\n // there as JSON - `String(value)` would have shown \"[object Object]\" and\n // thrown the actual value away.\n if (typeof value === 'string') return value;\n if (value == null) return undefined;\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return undefined;\n }\n }\n return String(value);\n case 'document':\n case 'image': {\n if (value && typeof value === 'object') {\n const o = value as { url?: unknown; filename?: unknown };\n return o.url\n ? { url: String(o.url), filename: o.filename as string | undefined }\n : undefined;\n }\n return typeof value === 'string' && value ? { url: value } : undefined;\n }\n case 'object': {\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = fromRjsf(child, ownProp(obj, child.name));\n return out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n return arr.map((item) => fromRjsf(field.item, item));\n }\n default:\n return value;\n }\n}\n\n/**\n * The runner's field value → RJSF full form value (what runs/store expect).\n *\n * `collapseEmpty` is what a SINGULAR slot does and a LIST ITEM must not: an\n * untouched structure in a singular slot is absent, but an item exists only\n * because the user added it, so adding IS the touch. Only the structure case\n * reads the flag.\n */\nfunction toRjsf(field: RunField, value: unknown, collapseEmpty = true): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return wrapContent(field, typeof value === 'string' ? value : '');\n case 'number':\n // An untouched number stays ABSENT rather than becoming an empty wrapper.\n // The gate then does the right thing on both counts: it prunes an absent\n // optional input, and it reports a required one as missing by name -\n // where `{number: undefined}` would read as a malformed value instead.\n return typeof value === 'number' && Number.isFinite(value)\n ? wrapContent(field, value)\n : undefined;\n case 'boolean':\n // `false` is a value, not an absence - hence the type test rather than a\n // truthiness one.\n return typeof value === 'boolean' ? wrapContent(field, value) : undefined;\n case 'unknown':\n return typeof value === 'string' ? value : '';\n case 'document':\n case 'image': {\n const url = value && typeof value === 'object' ? (value as { url?: unknown }).url : value;\n const filename =\n value && typeof value === 'object' ? (value as { filename?: unknown }).filename : undefined;\n return { url: url ? String(url) : '', ...(filename ? { filename } : {}) };\n }\n case 'object': {\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = toRjsf(child, ownProp(obj, child.name));\n // A structure nobody put anything into stays ABSENT, exactly as an\n // untouched number does above - it does NOT become a shell of empty\n // children. Materializing that shell made an OPTIONAL structured input\n // unrunnable whenever its concept declared a required child: readiness\n // ignored the input (correctly - the method said it may be omitted), Run\n // lit up, and the gate then judged an object the kernel had invented\n // against the concept's full schema and rejected the run for a child the\n // user was never asked to fill.\n //\n // Emptiness is `isFilled`, the SAME predicate readiness and the wire\n // payload use, so the three cannot disagree about whether this input is\n // there. Which also says what the touch is NOT: opening the optional\n // disclosure is local view state the value never sees, so a section\n // opened and left blank collapses exactly like one never opened. What\n // keeps a structure is a VALUE in it - and then the whole shell survives,\n // empty children and all, so a required child left blank still fails, and\n // loudly.\n return collapseEmpty && !isFilled(out) ? undefined : out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n // An item is NEVER absent: it is in the array because the user added it,\n // and `ListField`'s \"Add\" seeds an object item with `{}`. Letting it\n // collapse the way an untouched singular slot does put `undefined` in the\n // array, which ajv rejects as `must be object` - blocking an empty item\n // the item schema allowed, and turning a required-child complaint into a\n // type error that names nothing the user can act on.\n return arr.map((item) => toRjsf(field.item, item, false));\n }\n default:\n return value;\n }\n}\n\n// ─── Store ↔ RunField values ──────────────────────────────────────────────\n\n/** Seed the runner's form values from the method-store's simplified inputData. */\nexport function runValuesFromStore(\n inputData: Dict | undefined,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n const full = inflateAllInputs(inputData ?? {}, inputSchemas);\n const out: Dict = {};\n for (const field of fields) out[field.name] = fromRjsf(field, ownProp(full, field.name));\n return out;\n}\n\n/**\n * The runner's form values in **schema shape** - the same shape an RJSF panel\n * holds, and therefore the shape `gate.ts` validates against the per-input\n * JSON Schemas.\n *\n * Deliberately stops short of `deflateAllInputs`: deflation is the STORE's\n * compact form, and ajv validates the full one.\n */\nexport function rjsfDataFromRunValues(values: Dict, fields: RunField[]): Dict {\n const full: Dict = {};\n for (const field of fields) full[field.name] = toRjsf(field, ownProp(values, field.name));\n return full;\n}\n\n/** Convert the runner's form values back to the store's simplified inputData. */\nexport function storeInputDataFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n return deflateAllInputs(rjsfDataFromRunValues(values, fields), inputSchemas);\n}\n\n/**\n * Build the `{ concept, content }` map a run expects from the form values.\n *\n * The two ways a method says \"this may be nothing\" land differently on the wire,\n * and both matter:\n * - an **optional (`?`)** input left blank is OMITTED, so the runtime records a\n * real absence the method can branch on - sending `{ text: \"\" }` would look\n * like the caller supplied an empty string;\n * - a **plural (`[]`)** input keeps its key, because a plural slot is never\n * absent - its empty form IS the empty list, and the runtime requires the key.\n * When that list is EMPTY it is sent BARE, without the envelope: the envelope\n * is the runtime's \"explicit form\", which bypasses the top-down shaper and\n * hands the value to the bottom-up factory, and that factory types a list from\n * its first item - so an empty list there raises \"Cannot create Stuff from\n * empty list in content\". The bare form keeps the shaper, which reads the\n * DECLARED concept and builds the empty list correctly. (pipelex/#1096 makes\n * the envelope agree; the bare form runs today and stays correct after.)\n */\nexport function apiInputsFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const field of fields) {\n const schema = ownProp(inputSchemas, field.name);\n if (!schema) continue;\n const value = ownProp(values, field.name);\n if (isOptionalInput(schema) && !isFilled(value)) continue;\n if (isPluralInput(schema) && !isFilled(value)) {\n out[field.name] = [];\n continue;\n }\n out[field.name] = { concept: schema.concept_ref, content: toRjsf(field, value) };\n }\n return out;\n}\n\n// ─── Pipe output → result entries ────────────────────────────────────────────\n\n/** One named output pulled out of a run's working memory, ready to render. */\nexport interface OutputEntry {\n /** The output variable key (mono). */\n key: string;\n conceptRef?: string;\n value: unknown;\n}\n\n/**\n * The slice of a serialized pipe output this module actually reads. Structural\n * on purpose: the SDK's `DictPipeOutput` is the host's wire type, and the kernel\n * must not depend on `@pipelex/sdk` - the guard below verifies the shape at\n * runtime anyway.\n */\ninterface PipeOutputWithWorkingMemory {\n working_memory: {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n}\n\nfunction hasWorkingMemoryRoot(value: unknown): value is PipeOutputWithWorkingMemory {\n return (\n !!value &&\n typeof value === 'object' &&\n 'working_memory' in value &&\n !!(value as { working_memory?: { root?: unknown } }).working_memory &&\n typeof (value as { working_memory: { root?: unknown } }).working_memory.root === 'object'\n );\n}\n\n/** The concept code of a working-memory entry (`{concept}` may be obj/str/absent). */\nfunction entryConceptRef(data: unknown): string | undefined {\n if (!data || typeof data !== 'object') return undefined;\n const raw = (data as { concept?: unknown; concept_code?: unknown }).concept;\n if (raw && typeof raw === 'object')\n return (\n ((raw as { concept_code?: string }).concept_code ?? (raw as { code?: string }).code) ||\n undefined\n );\n if (typeof raw === 'string') return raw;\n return (data as { concept_code?: string }).concept_code || undefined;\n}\n\n/**\n * Split a run's pipe output into the main result and any intermediate outputs,\n * excluding the inputs. The main output's identity comes from the working\n * memory's `main_stuff` alias (the authoritative pointer to the output variable)\n * - so its label is the REAL stuff name, not a positional guess. Falls back to\n * the last produced stuff only when the alias is absent.\n */\nexport function outputsFromPipeOutput(\n pipeOutput: unknown,\n inputKeys: string[],\n): { main: OutputEntry; intermediates: OutputEntry[] } | null {\n if (!hasWorkingMemoryRoot(pipeOutput)) return null;\n const wm = pipeOutput.working_memory as {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n const entries = Object.entries(wm.root).filter(([key]) => !inputKeys.includes(key));\n if (entries.length === 0) return null;\n\n const toEntry = ([key, data]: [string, unknown]): OutputEntry => ({\n key,\n conceptRef: entryConceptRef(data),\n value: (data as { content?: unknown })?.content ?? data,\n });\n\n // The real main-output name: `aliases.main_stuff` → its root key.\n const mainKey = wm.aliases?.['main_stuff'];\n const mainEntry: [string, unknown] =\n mainKey && Object.prototype.hasOwnProperty.call(wm.root, mainKey)\n ? [mainKey, wm.root[mainKey]]\n : entries[entries.length - 1]!;\n const intermediates = entries.filter(([key]) => key !== mainEntry[0]).map(toEntry);\n\n return { main: toEntry(mainEntry), intermediates };\n}\n\n/**\n * Recover the inputs a run was executed with from its working memory. The run's\n * `working_memory.root` holds every named stuff - inputs AND outputs - keyed by\n * variable name; we pull the entries whose keys are declared inputs and deflate\n * their `content` (the full form shape) back into the store's simplified\n * `inputData`. Lets the runner repopulate the form for a past/shared run - the\n * inputs that produced the result. Returns `null` when no inputs are present.\n */\nexport function inputDataFromWorkingMemory(\n workingMemory: unknown,\n inputSchemas: InputSchemas,\n): Dict | null {\n const root = (workingMemory as { root?: Record<string, unknown> } | null | undefined)?.root;\n if (!root || typeof root !== 'object') return null;\n const full: Dict = {};\n let found = false;\n for (const key of Object.keys(inputSchemas)) {\n const entry = ownProp(root, key);\n if (entry && typeof entry === 'object' && 'content' in entry) {\n full[key] = (entry as { content: unknown }).content;\n found = true;\n }\n }\n if (!found) return null;\n return deflateAllInputs(full, inputSchemas);\n}\n\n/** Field descriptors for a method's main pipe. */\nexport function fieldsForContract(contract: PipeIOContract | undefined): RunField[] {\n return contract?.inputs ? buildRunFields(contract.inputs) : [];\n}\n\n/**\n * Immutably set a value at a dotted/indexed path (`a.0.b`). Used to write an\n * uploaded file's URL back to a field anywhere in the (possibly nested) tree.\n */\nexport function setValueAtPath(root: Dict, path: string[], value: unknown): Dict {\n const head = path[0];\n if (head === undefined) return root;\n const rest = path.slice(1);\n if (rest.length === 0) return { ...root, [head]: value };\n\n const nextSeg = rest[0] as string;\n const child = root[head];\n if (/^\\d+$/.test(nextSeg)) {\n const arr = Array.isArray(child) ? child.slice() : [];\n const idx = Number(nextSeg);\n arr[idx] =\n rest.length === 1 ? value : setValueAtPath((arr[idx] as Dict) ?? {}, rest.slice(1), value);\n return { ...root, [head]: arr };\n }\n return { ...root, [head]: setValueAtPath((child as Dict) ?? {}, rest, value) };\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { prepareSchemaForRjsf } from './chunk-KFZ5MZOM.js';
|
|
2
|
+
import { pruneEmptyOptionals, healStringWrappers } from './chunk-7BMOPXDY.js';
|
|
3
|
+
import { isFilled, mustBeFilled, fieldFilled } from './chunk-PM55AHRO.js';
|
|
4
|
+
import { buildRunFields } from './chunk-VMLXO5JS.js';
|
|
5
|
+
import { inputMustBeFilled, isOptionalInput, isPluralInput } from './chunk-HARYEWNG.js';
|
|
6
|
+
import { ownProp } from './chunk-V3OV2XQT.js';
|
|
7
|
+
import { validateRunInputsSchema } from './chunk-VTPUDBSJ.js';
|
|
8
|
+
|
|
9
|
+
// src/core/gate.ts
|
|
10
|
+
function buildRunInputsSchema(inputs) {
|
|
11
|
+
const properties = {};
|
|
12
|
+
const required = [];
|
|
13
|
+
for (const [varName, input] of Object.entries(inputs)) {
|
|
14
|
+
const inputSchema = { ...input.json_schema };
|
|
15
|
+
inputSchema.title = varName;
|
|
16
|
+
if (input.concept_ref && input.concept_ref !== varName) {
|
|
17
|
+
inputSchema.description = input.concept_ref;
|
|
18
|
+
}
|
|
19
|
+
properties[varName] = inputSchema;
|
|
20
|
+
if (inputMustBeFilled(input)) required.push(varName);
|
|
21
|
+
}
|
|
22
|
+
return prepareSchemaForRjsf({ type: "object", properties, required });
|
|
23
|
+
}
|
|
24
|
+
function prepareRunInputs(data, schema) {
|
|
25
|
+
return pruneEmptyOptionals(healStringWrappers(data, schema), schema);
|
|
26
|
+
}
|
|
27
|
+
function validateRunInputs(preparedData, inputs, schema) {
|
|
28
|
+
const errors = validateRunInputsSchema(preparedData, schema);
|
|
29
|
+
if (errors.length === 0) return { isValid: true, missingInputs: [], errors: [] };
|
|
30
|
+
const record0 = typeof preparedData === "object" && preparedData !== null && !Array.isArray(preparedData) ? preparedData : void 0;
|
|
31
|
+
const missingInputs = [];
|
|
32
|
+
for (const [varName, input] of Object.entries(inputs)) {
|
|
33
|
+
if (!inputMustBeFilled(input)) continue;
|
|
34
|
+
const varData = ownProp(record0, varName);
|
|
35
|
+
if (varData == null) {
|
|
36
|
+
missingInputs.push(varName);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const inputSchema = input.json_schema;
|
|
40
|
+
const requiredFields = inputSchema.required || [];
|
|
41
|
+
if (requiredFields.length === 0) continue;
|
|
42
|
+
if (typeof varData !== "object") {
|
|
43
|
+
missingInputs.push(varName);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const record = varData;
|
|
47
|
+
if (requiredFields.some((f) => {
|
|
48
|
+
const child = ownProp(record, f);
|
|
49
|
+
return child === void 0 || child === "";
|
|
50
|
+
})) {
|
|
51
|
+
missingInputs.push(varName);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { isValid: false, missingInputs, errors };
|
|
55
|
+
}
|
|
56
|
+
function apiInputsFromSchemaData(preparedData, inputs) {
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const [varName, input] of Object.entries(inputs)) {
|
|
59
|
+
const raw = ownProp(preparedData, varName);
|
|
60
|
+
if (isOptionalInput(input) && !isFilled(raw)) continue;
|
|
61
|
+
if (isPluralInput(input) && !isFilled(raw)) {
|
|
62
|
+
out[varName] = [];
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const content = isPluralInput(input) && !Array.isArray(raw) ? [] : raw;
|
|
66
|
+
out[varName] = { concept: input.concept_ref, content };
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
var SCHEMA_CACHE = /* @__PURE__ */ new WeakMap();
|
|
71
|
+
function schemaForContract(contract) {
|
|
72
|
+
const cached = SCHEMA_CACHE.get(contract);
|
|
73
|
+
if (cached) return cached;
|
|
74
|
+
const schema = buildRunInputsSchema(contract.inputs);
|
|
75
|
+
SCHEMA_CACHE.set(contract, schema);
|
|
76
|
+
return schema;
|
|
77
|
+
}
|
|
78
|
+
function gateRunInputs(contract, data) {
|
|
79
|
+
const isRecord = typeof data === "object" && data !== null && !Array.isArray(data);
|
|
80
|
+
const payload = isRecord ? data : {};
|
|
81
|
+
const schema = schemaForContract(contract);
|
|
82
|
+
const preparedData = prepareRunInputs(payload, schema);
|
|
83
|
+
const verdict = validateRunInputs(isRecord ? preparedData : data, contract.inputs, schema);
|
|
84
|
+
if (!verdict.isValid) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
missingInputs: verdict.missingInputs,
|
|
88
|
+
errors: verdict.errors,
|
|
89
|
+
preparedData
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const missingInputs = buildRunFields(contract.inputs).filter((field) => mustBeFilled(field) || isFilled(ownProp(preparedData, field.name))).filter((field) => !fieldFilled(field, ownProp(preparedData, field.name))).map((field) => field.name);
|
|
93
|
+
if (missingInputs.length) return { ok: false, missingInputs, errors: [], preparedData };
|
|
94
|
+
return { ok: true, inputs: apiInputsFromSchemaData(preparedData, contract.inputs) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs };
|
|
98
|
+
//# sourceMappingURL=chunk-XEPD5VJQ.js.map
|
|
99
|
+
//# sourceMappingURL=chunk-XEPD5VJQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/gate.ts"],"names":[],"mappings":";;;;;;;;;AAqDO,SAAS,qBAAqB,M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AAS,QAAQ,MAAM,CAAA;AACzF,EAAA,IAAI,CAAC,QAAQ,OAAA,EAAS;AACpB,IAAA,OAAO;AAAA,MACL,EAAA,EAAI,KAAA;AAAA,MACJ,eAAe,OAAA,CAAQ,aAAA;AAAA,MACvB,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB;AAAA,KACF;AAAA,EACF;AAcA,EAAA,MAAM,gBAAgB,cAAA,CAAe,QAAA,CAAS,MAAM,CAAA,CACjD,OAAO,CAAC,KAAA,KAAU,YAAA,CAAa,KAAK,KAAK,QAAA,CAAS,OAAA,CAAQ,YAAA,EAAc,KAAA,CAAM,IAAI,CAAC,CAAC,CAAA,CACpF,MAAA,CAAO,CAAC,KAAA,KAAU,CAAC,WAAA,CAAY,KAAA,EAAO,QAAQ,YAAA,EAAc,KAAA,CAAM,IAAI,CAAC,CAAC,CAAA,CACxE,GAAA,CAAI,CAAC,KAAA,KAAU,MAAM,IAAI,CAAA;AAC5B,EAAA,IAAI,aAAA,CAAc,MAAA,EAAQ,OAAO,EAAE,EAAA,EAAI,OAAO,aAAA,EAAe,MAAA,EAAQ,EAAC,EAAG,YAAA,EAAa;AAEtF,EAAA,OAAO,EAAE,IAAI,IAAA,EAAM,MAAA,EAAQ,wBAAwB,YAAA,EAAc,QAAA,CAAS,MAAM,CAAA,EAAE;AACpF","file":"chunk-XEPD5VJQ.js","sourcesContent":["/**\n * The gate every run passes through, whichever surface starts it.\n *\n * A host may offer more than one place to run a method - a schema-driven\n * inputs panel (an RJSF form) and a standalone run page (a bespoke field\n * renderer), say. **Only the rendering of inputs differs.** Everything between\n * \"the user pressed Run\" and \"the payload goes on the wire\" lives here, so\n * those surfaces cannot drift:\n *\n * 1. `buildRunInputsSchema` - the combined JSON Schema, whose `required` list\n * is `inputMustBeFilled` (optional `?` and variable-plural `[]` never\n * block; a fixed-count `[N]` list does).\n * 2. `prepareRunInputs` - heal legacy wrappers, then prune empty optionals.\n * 3. `validateRunInputs` - ajv, plus the missing-input scan that names the\n * VARIABLE at fault.\n * 4. `apiInputsFromSchemaData` - the `{concept, content}` payload, built from\n * the PREPARED data so the pruning reaches the wire too.\n *\n * **`gateRunInputs` is that whole chain as one call**, and it is what a server\n * should use. The four steps stay exported because a host that renders its own\n * panel needs the schema and the verdict separately, but assembling them is not\n * a host's job: the step between validation and the payload is an emptiness\n * check with four look-alike predicates to choose from, only two of which are\n * the ones the Run button reads, and choosing the near-miss pair produces a\n * server that is more permissive than the button in front of it.\n *\n * This module is pure: no React, no toasts, no i18n. Each caller renders the\n * verdict in its own idiom.\n */\nimport { inputMustBeFilled, isOptionalInput, isPluralInput } from './contracts';\nimport { buildRunFields } from './derive';\nimport { fieldFilled, isFilled, mustBeFilled } from './readiness';\nimport { validateRunInputsSchema, type RunInputError } from './gate-validator';\nimport { healStringWrappers, pruneEmptyOptionals } from './wire-format';\nimport { prepareSchemaForRjsf } from './normalize-schema';\nimport { ownProp } from './own-property';\nimport type { PipeIOContract, PipeInputContract } from './contracts';\n\ntype Dict = Record<string, unknown>;\n\n/**\n * Combine the per-input schemas into one object schema.\n *\n * Each input variable becomes a property, titled with the variable name and\n * described with the concept code. Only the inputs the method actually demands\n * land in `required` - an optional (`?`) or variable-plural (`[]`) input must\n * not block the form (see `inputMustBeFilled`).\n *\n * The per-input schema travels verbatim, which is how a fixed-count (`[N]`)\n * list's declared count reaches ajv: pipelex states it as `minItems`/`maxItems`\n * on the array wrapper, so the count is enforced here without the kernel\n * restating it.\n */\nexport function buildRunInputsSchema(inputs: Record<string, PipeInputContract>): Dict {\n const properties: Dict = {};\n const required: string[] = [];\n\n for (const [varName, input] of Object.entries(inputs)) {\n const inputSchema = { ...input.json_schema } as Dict;\n inputSchema.title = varName;\n if (input.concept_ref && input.concept_ref !== varName) {\n inputSchema.description = input.concept_ref;\n }\n properties[varName] = inputSchema;\n if (inputMustBeFilled(input)) required.push(varName);\n }\n\n return prepareSchemaForRjsf({ type: 'object', properties, required });\n}\n\n/**\n * Last-gate repair, in two passes against the exact schema ajv validates.\n *\n * 1. **HEAL** - persisted `inputData` may still carry the legacy double-wrapped\n * `{ text: { text } }` shape (or a form's state may lag a store fix).\n * 2. **PRUNE** - RJSF fills every unset string with `\"\"` on mount, which an\n * optional CONSTRAINED field rejects (`DateContent.time` is `format: \"time\"`)\n * - blocking a run on a field the user never opened. An absent optional field\n * is what pipelex means by `None` anyway, so dropping it is the semantically\n * correct repair, not a validation dodge.\n */\nexport function prepareRunInputs(data: Dict, schema: Dict): Dict {\n return pruneEmptyOptionals(healStringWrappers(data, schema), schema) as Dict;\n}\n\nexport interface RunInputsVerdict {\n isValid: boolean;\n /** Variable names the scan could pin a missing required field on. */\n missingInputs: string[];\n /** Raw ajv errors, for when the scan cannot name anything. */\n errors: RunInputError[];\n}\n\n/**\n * Validate PREPARED data against the combined schema.\n *\n * `missingInputs` is reported by VARIABLE NAME - the name on the node the user\n * clicks - never by `concept_ref`, which used to produce \"Missing required\n * fields in: native.Text\" and named neither the input at fault nor, when several\n * inputs share a concept, which of them. Inputs the method declared omittable\n * are skipped: an empty `?` input is not a missing one.\n *\n * The scan can come up empty even on an invalid form (a wrong value shape, a\n * nested mismatch); `errors` is what the caller falls back to then, so a failure\n * is never undiagnosable.\n *\n * `preparedData` is `unknown` for the same reason `gateRunInputs`' `data` is: on\n * a public endpoint the body is whatever was sent, and ajv must be shown that\n * rather than a repair of it, or `must be object` is a verdict no caller can\n * ever receive. The name-the-variable scan below needs something indexable, so\n * a body that is not a record scans against nothing and names every input the\n * method demands - which is the honest answer for a body that carried none.\n */\nexport function validateRunInputs(\n preparedData: unknown,\n inputs: Record<string, PipeInputContract>,\n schema: Dict,\n): RunInputsVerdict {\n const errors = validateRunInputsSchema(preparedData, schema);\n if (errors.length === 0) return { isValid: true, missingInputs: [], errors: [] };\n\n const record0 =\n typeof preparedData === 'object' && preparedData !== null && !Array.isArray(preparedData)\n ? (preparedData as Dict)\n : undefined;\n const missingInputs: string[] = [];\n for (const [varName, input] of Object.entries(inputs)) {\n if (!inputMustBeFilled(input)) continue;\n const varData = ownProp(record0, varName);\n // A demanded input that is not there at all is missing whatever its concept\n // declares inside. The check has to come BEFORE the required-children one:\n // a struct whose concept demands no child used to fall out of the scan\n // here, so the run was refused by the combined schema's `required` list\n // while the scan named nothing and the caller could only quote ajv.\n if (varData == null) {\n missingInputs.push(varName);\n continue;\n }\n const inputSchema = input.json_schema as Dict;\n const requiredFields = (inputSchema.required as string[]) || [];\n if (requiredFields.length === 0) continue;\n if (typeof varData !== 'object') {\n missingInputs.push(varName);\n continue;\n }\n const record = varData as Dict;\n if (\n requiredFields.some((f) => {\n const child = ownProp(record, f);\n return child === undefined || child === '';\n })\n ) {\n missingInputs.push(varName);\n }\n }\n\n return { isValid: false, missingInputs, errors };\n}\n\n/**\n * Build the `{ concept, content }` map a run expects, from PREPARED data.\n *\n * The two ways a method says \"this may be nothing\" land differently on the wire:\n * - an **optional (`?`)** input left blank is OMITTED, so the runtime records a\n * real absence the method can branch on - sending `{ text: \"\" }` would look\n * like the caller supplied an empty string;\n * - a **plural (`[]`)** input keeps its key, because a plural slot is never\n * absent - its empty form IS the empty list, and the runtime requires the key.\n * When that list is EMPTY it is sent BARE, without the envelope: the envelope\n * is the runtime's \"explicit form\", which bypasses the top-down shaper and\n * hands the value to the bottom-up factory, and that factory types a list from\n * its first item - so an empty list there raises \"Cannot create Stuff from\n * empty list in content\". The bare form keeps the shaper, which reads the\n * DECLARED concept and builds the empty list correctly. (pipelex/#1096 makes\n * the envelope agree; the bare form runs today and stays correct after.)\n *\n * A fixed-count (`[N]`) list takes that same empty-list path, and an empty one\n * is not a payload the method can accept. It is unreachable through the gate,\n * which demands the input and rejects a short list on `minItems`; building the\n * payload straight from unvalidated data is what would reach it, and inventing\n * a different absence here would only hide that.\n */\nexport function apiInputsFromSchemaData(\n preparedData: Dict,\n inputs: Record<string, PipeInputContract>,\n): Dict {\n const out: Dict = {};\n for (const [varName, input] of Object.entries(inputs)) {\n const raw = ownProp(preparedData, varName);\n if (isOptionalInput(input) && !isFilled(raw)) continue;\n if (isPluralInput(input) && !isFilled(raw)) {\n out[varName] = [];\n continue;\n }\n const content = isPluralInput(input) && !Array.isArray(raw) ? [] : raw;\n out[varName] = { concept: input.concept_ref, content };\n }\n return out;\n}\n\n// ─── The whole chain, as one call ────────────────────────────────────────────\n\n/** The gate's verdict: the payload to send, or why the run may not start. */\nexport type RunInputsGateResult =\n | { ok: true; inputs: Dict }\n | {\n ok: false;\n /** Variable names the caller left empty or short. */\n missingInputs: string[];\n /** Raw ajv errors, for when the scan cannot name anything. */\n errors: RunInputError[];\n /** The repaired data the verdict was reached on - what\n * `describeValidationError` needs to quote the value it received. */\n preparedData: Dict;\n };\n\n/**\n * One schema object per contract, for the lifetime of the process.\n *\n * `buildRunInputsSchema` is a pure function of the contract, so rebuilding it is\n * *semantically* free - but validation runs through a module-level ajv whose\n * compiled-schema cache is keyed on **schema object identity** and is never\n * evicted. A fresh object per call therefore misses every time and retains\n * another compiled validator. On a publicly callable server endpoint that is\n * unbounded growth driven by the cheapest request there is: an empty body,\n * rejected in a fraction of a millisecond, costing nothing to send.\n *\n * Weakly keyed so the map never pins a contract that goes out of scope. The\n * schema a run has been gated against is pinned for the process lifetime anyway\n * by ajv's own cache; the point is that the NUMBER of them is bounded by the\n * number of distinct contracts rather than by traffic.\n */\nconst SCHEMA_CACHE = new WeakMap<PipeIOContract, Dict>();\n\nfunction schemaForContract(contract: PipeIOContract): Dict {\n const cached = SCHEMA_CACHE.get(contract);\n if (cached) return cached;\n const schema = buildRunInputsSchema(contract.inputs);\n SCHEMA_CACHE.set(contract, schema);\n return schema;\n}\n\n/**\n * Gate a run: repair the caller's data, validate it against the contract,\n * refuse anything the Run button would have refused, and build the payload.\n *\n * Returns a verdict rather than throwing. A server endpoint must not throw\n * across the boundary to its client - frameworks routinely strip the message to\n * an opaque digest in a production build - and a rejection here is an ordinary\n * outcome, not an exceptional one.\n *\n * **`data` is `unknown` because that is what it is.** A run endpoint is public\n * and no framework enforces a declared parameter type, so the argument is\n * whatever the caller put in the body. The chain indexes the payload by\n * variable name without first checking it is indexable, so a `null` body would\n * throw *after* ajv had already reported `must be object` and before any\n * verdict came back.\n *\n * So the two uses are separated rather than collapsed into one repair. **ajv\n * judges the value the caller actually sent**, which is what makes `must be\n * object` the verdict for a body that is not one; the indexing that follows\n * uses a safe `{}` stand-in, which is what keeps the gate from throwing. Repair\n * FIRST - coercing a non-object to `{}` before validating - is the shape that\n * looks equivalent and is not: a contract whose inputs are all optional has an\n * empty `required` list, so `{}` validates, and `gateRunInputs(\"garbage\", …)`\n * came back `ok: true` on a body the caller never meant as a run. Fail-closed\n * costs a malformed caller an error it earned; the other direction bills a run.\n *\n * **The schema alone is not the rule.** ajv's `required` asserts only that a\n * key is PRESENT, and a content model carries no `minLength` - so a required\n * input that arrived empty (`{document: {url: \"\"}}`, `{text: {text: \"\"}}`)\n * satisfies the schema. That is the natural payload, not a contrived one:\n * `rjsfDataFromRunValues({}, fields)` emits exactly that when nothing is\n * selected. So the gate re-applies the emptiness rule using\n * `computeReadiness`'s OWN two functions over the same derived fields, which is\n * the only way to be sure the two sides cannot disagree.\n *\n * Picking a pair that merely looks equivalent is not enough, and this is the\n * whole reason the assembly lives here rather than in each host: the obvious\n * choice, `inputMustBeFilled` + `isFilled`, agrees on every leaf kind and\n * diverges on a structured concept in BOTH directions - `isFilled` on an object\n * is `some(child filled)` where `fieldFilled` is `every(required child\n * filled)`. That accepts a half-filled struct the browser refuses (a paid run\n * past a disabled button) and rejects a filled all-optional struct the browser\n * accepts. A host whose methods happen to use only native concepts has no test\n * that can catch either.\n */\nexport function gateRunInputs(contract: PipeIOContract, data: unknown): RunInputsGateResult {\n const isRecord = typeof data === 'object' && data !== null && !Array.isArray(data);\n const payload = isRecord ? (data as Dict) : {};\n const schema = schemaForContract(contract);\n const preparedData = prepareRunInputs(payload, schema);\n\n // The value ajv is shown is the caller's, not the stand-in - see above.\n const verdict = validateRunInputs(isRecord ? preparedData : data, contract.inputs, schema);\n if (!verdict.isValid) {\n return {\n ok: false,\n missingInputs: verdict.missingInputs,\n errors: verdict.errors,\n preparedData,\n };\n }\n\n // The SELECTION is half the rule, and leaving it out is what made the two\n // halves disagree. `computeReadiness` reckons with an input the method\n // demands AND one it left optional that the user has touched - because a\n // structure with something in it owes its concept every field the concept\n // declares. Filtering on `mustBeFilled` alone dropped the second kind, so a\n // half-filled optional struct was refused by the button and accepted here.\n //\n // ajv cannot cover for it: a required child that is a plain string arrives as\n // `''`, which satisfies `required`. And the payload builder below then SENDS\n // that input, because `isFilled` is exactly what it tests. Which is the rule\n // stated properly: the gate holds to its concept precisely the inputs it is\n // about to put on the wire, and nothing it will omit.\n const missingInputs = buildRunFields(contract.inputs)\n .filter((field) => mustBeFilled(field) || isFilled(ownProp(preparedData, field.name)))\n .filter((field) => !fieldFilled(field, ownProp(preparedData, field.name)))\n .map((field) => field.name);\n if (missingInputs.length) return { ok: false, missingInputs, errors: [], preparedData };\n\n return { ok: true, inputs: apiInputsFromSchemaData(preparedData, contract.inputs) };\n}\n"]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed `pipe_io_contracts` mirror and its gating predicates.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors pipelex's `PipeIOContract` (pipelex/pipeline/pipe_io_contracts.py).
|
|
5
|
+
* The SDK deliberately keeps `pipe_io_contracts` opaque, so the kernel is the
|
|
6
|
+
* canonical TS home for this shape until the D-track specs it.
|
|
7
|
+
*
|
|
8
|
+
* The map itself is keyed by namespaced pipe ref (`<domain>.<pipe_code>`),
|
|
9
|
+
* NOT bare pipe code - use `getPipeIOContract` to look entries up by the bare
|
|
10
|
+
* codes the UI tracks.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The authored presence marker on an input slot, verbatim.
|
|
14
|
+
*
|
|
15
|
+
* - `plain` - no marker: the caller must supply the input.
|
|
16
|
+
* - `optional` (`?`) - the caller may omit it and the pipe handles the absence
|
|
17
|
+
* itself.
|
|
18
|
+
* - `force` (`!`) - a use-site assertion that the value IS present. It must be
|
|
19
|
+
* supplied, exactly like `plain`; the distinction is the authored assertion,
|
|
20
|
+
* which lint and graph surfaces read and a form does not.
|
|
21
|
+
*/
|
|
22
|
+
type InputPresence = 'plain' | 'optional' | 'force';
|
|
23
|
+
/**
|
|
24
|
+
* How many items a slot carries.
|
|
25
|
+
*
|
|
26
|
+
* - `single` - one item. `Concept[1]` is single too: no list framing.
|
|
27
|
+
* - `variable` (`Concept[]`) - a list of any length, the empty list included.
|
|
28
|
+
* - `fixed` (`Concept[N]`, N > 1) - a list of exactly `item_count` items.
|
|
29
|
+
*/
|
|
30
|
+
type IOMultiplicity = 'single' | 'variable' | 'fixed';
|
|
31
|
+
interface PipeInputContract {
|
|
32
|
+
concept_ref: string;
|
|
33
|
+
/** The declared presence marker - see `InputPresence`. */
|
|
34
|
+
presence: InputPresence;
|
|
35
|
+
/** The declared multiplicity - see `IOMultiplicity`. */
|
|
36
|
+
multiplicity: IOMultiplicity;
|
|
37
|
+
/**
|
|
38
|
+
* The exact item count, non-null exactly when `multiplicity` is `fixed`. The
|
|
39
|
+
* slot is always on the wire, `null` off the fixed arm.
|
|
40
|
+
*/
|
|
41
|
+
item_count: number | null;
|
|
42
|
+
/**
|
|
43
|
+
* The input's JSON Schema. A plural slot (`variable` or `fixed`) is an array
|
|
44
|
+
* wrapper around the item schema, and a `fixed` one additionally carries
|
|
45
|
+
* `minItems` / `maxItems` set to `item_count` - which is what makes the gate's
|
|
46
|
+
* ajv pass enforce the declared count without the kernel restating it.
|
|
47
|
+
*/
|
|
48
|
+
json_schema: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface PipeOutputContract {
|
|
51
|
+
concept_ref: string;
|
|
52
|
+
multiplicity: IOMultiplicity;
|
|
53
|
+
/** As on the input: non-null exactly on the `fixed` arm, always on the wire. */
|
|
54
|
+
item_count: number | null;
|
|
55
|
+
/**
|
|
56
|
+
* `true` when the output is declared optional (`?`) - the pipe may resolve it
|
|
57
|
+
* as a recorded absence instead of a value.
|
|
58
|
+
*
|
|
59
|
+
* Deliberately still a boolean while the INPUT side carries three-valued
|
|
60
|
+
* `presence`: output presence is genuinely two-valued, because `!` is
|
|
61
|
+
* rejected on an output. The asymmetry is the wire's, not ours.
|
|
62
|
+
*/
|
|
63
|
+
optional: boolean;
|
|
64
|
+
}
|
|
65
|
+
interface PipeIOContract {
|
|
66
|
+
inputs: Record<string, PipeInputContract>;
|
|
67
|
+
output: PipeOutputContract;
|
|
68
|
+
}
|
|
69
|
+
/** The `pipe_io_contracts` map: namespaced `pipe_ref` → IO contract. */
|
|
70
|
+
type PipeIOContracts = Record<string, PipeIOContract>;
|
|
71
|
+
/** Namespaced pipe ref (`<domain>.<pipe_code>`) - the identity convention the
|
|
72
|
+
* validate artifacts key on. */
|
|
73
|
+
declare function buildPipeRef(domain: string, pipeCode: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Look up a pipe's IO contract by pipe code, tolerant of both key conventions.
|
|
76
|
+
*
|
|
77
|
+
* The map may be keyed by namespaced `pipe_ref` (`<domain>.<code>`, the
|
|
78
|
+
* canonical convention) OR by bare pipe code - the current hosted `/validate`
|
|
79
|
+
* keys `pipe_structures` by bare code, and methods persisted before the
|
|
80
|
+
* pipe_ref re-keying also carry bare-code keys. Try the namespaced ref first
|
|
81
|
+
* (when the caller supplies a domain), then fall back to the bare code.
|
|
82
|
+
* Returns `undefined` (never crashes) when neither matches.
|
|
83
|
+
*
|
|
84
|
+
* Both lookups read OWN properties only. A bare index returned the inherited
|
|
85
|
+
* `Object` constructor for a pipe code named `constructor` (or `toString`, …) -
|
|
86
|
+
* a truthy non-contract that sailed straight through the `if (!contract)` guard
|
|
87
|
+
* hosts are shown writing, so a pipe that does not exist rendered as one taking
|
|
88
|
+
* no inputs instead of reaching the host's not-found path. See `ownProp`.
|
|
89
|
+
*/
|
|
90
|
+
declare function getPipeIOContract(pipeIoContracts: PipeIOContracts | null | undefined, domain: string | null | undefined, pipeCode: string | null | undefined): PipeIOContract | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* True when the method declared the input omittable (`?`).
|
|
93
|
+
*
|
|
94
|
+
* The ONE reader of `presence` in the package: everything that asks "may this
|
|
95
|
+
* be absent?" - the descriptor's `required`, the gate's `required` list, the
|
|
96
|
+
* payload builders that omit an unfilled input - goes through here, so a
|
|
97
|
+
* marker the wire adds later cannot mean one thing on one surface and another
|
|
98
|
+
* elsewhere. `force` (`!`) reads as NOT optional, like `plain`.
|
|
99
|
+
*/
|
|
100
|
+
declare function isOptionalInput(input: PipeInputContract): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* True when the input carries a plural concept (`Image[]`, `Image[3]`): its
|
|
103
|
+
* JSON Schema is an array wrapper.
|
|
104
|
+
*
|
|
105
|
+
* Deliberately a SCHEMA test rather than a read of the declared `multiplicity`,
|
|
106
|
+
* even though the wire now states both. The schema is what `buildRunFields`
|
|
107
|
+
* maps and therefore what the user is shown; a predicate reading the other
|
|
108
|
+
* field could disagree with the rendered control, which is the exact failure
|
|
109
|
+
* mode `mustBeFilled` (readiness.ts) exists to prevent. The two agree by
|
|
110
|
+
* construction upstream - pipelex wraps the schema in an array exactly when it
|
|
111
|
+
* reports `variable` or `fixed`.
|
|
112
|
+
*/
|
|
113
|
+
declare function isPluralInput(input: PipeInputContract): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* True when the slot declares an EXACT number of items (`Concept[N]`), whose
|
|
116
|
+
* count is `item_count`.
|
|
117
|
+
*
|
|
118
|
+
* The distinction that matters to the gate: a variable list can legitimately be
|
|
119
|
+
* empty, a fixed one cannot.
|
|
120
|
+
*/
|
|
121
|
+
declare function isFixedCountInput(input: PipeInputContract): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* True when the user MUST put a value in before a run can start.
|
|
124
|
+
*
|
|
125
|
+
* Two declarations relieve an input of that duty, for different reasons:
|
|
126
|
+
* - **optional (`?`)** - the method itself states the caller may omit it;
|
|
127
|
+
* - **variable-plural (`[]`)** - the empty list is a legitimate value and the
|
|
128
|
+
* language cannot declare "at least one", so gating on it would invent a
|
|
129
|
+
* constraint the method never made.
|
|
130
|
+
*
|
|
131
|
+
* Everything else gates: `plain`, `force` (`!`), and a **fixed-count** list
|
|
132
|
+
* (`[N]`), which is a list whose empty form the method has explicitly ruled out.
|
|
133
|
+
* This is the derivation the input-form descriptor spec states for `gating`.
|
|
134
|
+
*
|
|
135
|
+
* Emptiness is all this predicate answers for - WHETHER a slot gates, never how
|
|
136
|
+
* much it needs. A fixed-count list that holds fewer items than it declares
|
|
137
|
+
* gates here and is refused by `fieldFilled`, which reads the declared count off
|
|
138
|
+
* the descriptor's `itemCount`, and by the gate's ajv pass on the schema's
|
|
139
|
+
* `minItems`. All three read the one number the method stated.
|
|
140
|
+
*/
|
|
141
|
+
declare function inputMustBeFilled(input: PipeInputContract): boolean;
|
|
142
|
+
|
|
143
|
+
export { type IOMultiplicity, type InputPresence, type PipeIOContract, type PipeIOContracts, type PipeInputContract, type PipeOutputContract, buildPipeRef, getPipeIOContract, inputMustBeFilled, isFixedCountInput, isOptionalInput, isPluralInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"contracts.js"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure conversions between a stored date value and what a native `<input
|
|
3
|
+
* type="date">` shows, plus the leniency rules our schema validation uses.
|
|
4
|
+
* Kept React-free so both the runner's `DateField` and the RJSF `DateWidget`
|
|
5
|
+
* share one source of truth (and it's trivially unit-tested).
|
|
6
|
+
*
|
|
7
|
+
* Two schema shapes reach us, and they are NOT interchangeable:
|
|
8
|
+
* - an MTHDS `type = "date"` structure field compiles to `format: date-time`,
|
|
9
|
+
* so its value round-trips as a full RFC 3339 timestamp;
|
|
10
|
+
* - `native.Date`'s own `date` field is a python `datetime.date`, i.e.
|
|
11
|
+
* `format: date` - a bare `YYYY-MM-DD`.
|
|
12
|
+
*
|
|
13
|
+
* ## Why these rules exist
|
|
14
|
+
*
|
|
15
|
+
* The runtime (pydantic) is LENIENT in both directions, and our client used to
|
|
16
|
+
* be stricter than the contract it was enforcing: `ajv`'s stock `format: "date"`
|
|
17
|
+
* accepts a bare `YYYY-MM-DD` and nothing else, so a hand-written
|
|
18
|
+
* `"2026-07-06T00:00:00Z"` in an `inputs.json` was rejected here even though
|
|
19
|
+
* pydantic accepts it happily and coerces it to `date(2026, 7, 6)`. The run
|
|
20
|
+
* never even reached the runner. These predicates mirror pydantic exactly
|
|
21
|
+
* (measured, not assumed):
|
|
22
|
+
*
|
|
23
|
+
* format: date "2026-07-06" -> date(2026, 7, 6)
|
|
24
|
+
* "2026-07-06T00:00:00Z" -> date(2026, 7, 6)
|
|
25
|
+
* "2026-07-06T00:00:00+02:00" -> date(2026, 7, 6) (literal date, no UTC shift)
|
|
26
|
+
* "2026-07-06T15:40:00Z" -> REJECTED "should have zero time"
|
|
27
|
+
* format: date-time "2026-07-06" -> datetime(2026, 7, 6, 0, 0)
|
|
28
|
+
* "2026-07-06T00:00:00Z" -> datetime(2026, 7, 6, 0, 0, tz)
|
|
29
|
+
*
|
|
30
|
+
* A midnight-padded timestamp is unambiguously "just a day", so take it. A real
|
|
31
|
+
* time is data - refusing it is the point (`DateContentError`: "no silent
|
|
32
|
+
* midnight"), because silently dropping 15:40 corrupts the value. And an
|
|
33
|
+
* ambiguous `06/07/2026` is never accepted by anyone: 6 July or June 7 depends
|
|
34
|
+
* on who's reading, and guessing wrong fails silently.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* The calendar day a value denotes, or `null` when it doesn't denote one.
|
|
38
|
+
* Accepts a bare date or a midnight-padded timestamp; the day is taken
|
|
39
|
+
* LITERALLY from the string (never shifted through a timezone), matching
|
|
40
|
+
* pydantic - `2026-07-06T00:00:00+02:00` is 2026-07-06, not the 5th.
|
|
41
|
+
*/
|
|
42
|
+
declare function asCalendarDate(value: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The calendar day inside a value that carries a REAL time - precisely the case
|
|
45
|
+
* `asCalendarDate` refuses. `null` when the value isn't a timestamp at all, or
|
|
46
|
+
* when it IS already an acceptable day (nothing to report).
|
|
47
|
+
*
|
|
48
|
+
* This exists to EXPLAIN, never to coerce. `2026-07-06T14:30:00+02:00` is
|
|
49
|
+
* rejected for a `format: date` field, and the rejection is right (DT3, "no
|
|
50
|
+
* silent midnight" - dropping 14:30 corrupts the value). But telling the user
|
|
51
|
+
* "pick a valid date" while the picker shows them a perfectly good 06/07/2026
|
|
52
|
+
* reads as a lie: `toDateInputValue` renders the day, the stored value carries
|
|
53
|
+
* the time, and only one of those is what gets validated. Naming both the value
|
|
54
|
+
* we hold and the day it would have to become is what makes the error legible.
|
|
55
|
+
*/
|
|
56
|
+
declare function dayWithinDateTime(value: string): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* What `format: "date"` accepts: a bare `YYYY-MM-DD`, and nothing else.
|
|
59
|
+
*
|
|
60
|
+
* DO NOT relax this to take a midnight-padded timestamp. `DateContent` in
|
|
61
|
+
* pipelex carries a `mode="before"` field validator (`_reject_lax_temporal`)
|
|
62
|
+
* that deliberately CLOSES pydantic's lax coercion for exactly this case:
|
|
63
|
+
*
|
|
64
|
+
* "A Date's `date` field takes a calendar date alone; a string carrying a
|
|
65
|
+
* time (e.g. '2026-07-07T00:00:00') would drop it - put the time and offset
|
|
66
|
+
* in `time` instead."
|
|
67
|
+
*
|
|
68
|
+
* That rule (DT3, "no silent midnight") is the concept's whole point, so a
|
|
69
|
+
* lenient client here does not help anyone: it just forwards the value and the
|
|
70
|
+
* runner answers with a 500 instead of the field saying so up front.
|
|
71
|
+
*
|
|
72
|
+
* The leniency belongs in `asCalendarDate` - normalize the pasted timestamp to
|
|
73
|
+
* the day it denotes, then this passes. Accept-and-fix, not accept-and-forward.
|
|
74
|
+
*/
|
|
75
|
+
declare function isAcceptableDate(value: string): boolean;
|
|
76
|
+
/** What `format: "date-time"` should accept - a bare day is midnight. */
|
|
77
|
+
declare function isAcceptableDateTime(value: string): boolean;
|
|
78
|
+
/** The `YYYY-MM-DD` a native date input shows, from any stored date/date-time. */
|
|
79
|
+
declare function toDateInputValue(value: string | undefined): string;
|
|
80
|
+
/**
|
|
81
|
+
* The value to store for a picked day. A `date-time` field becomes midnight-UTC
|
|
82
|
+
* (`2026-07-06T00:00:00Z`); a plain `date` field keeps the bare `YYYY-MM-DD`.
|
|
83
|
+
* An empty day clears the value.
|
|
84
|
+
*/
|
|
85
|
+
declare function toStoredDateValue(day: string, datetime: boolean): string | undefined;
|
|
86
|
+
|
|
87
|
+
export { asCalendarDate, dayWithinDateTime, isAcceptableDate, isAcceptableDateTime, toDateInputValue, toStoredDateValue };
|