@pipelex/mthds-form 0.3.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-DPrrfAjL.d.ts → core/descriptor.d.ts} +28 -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 -623
- 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-S6KOTTGD.js +0 -990
- package/dist/chunk-S6KOTTGD.js.map +0 -1
package/dist/chunk-S6KOTTGD.js
DELETED
|
@@ -1,990 +0,0 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
import addFormats from 'ajv-formats';
|
|
3
|
-
|
|
4
|
-
// src/core/descriptor.ts
|
|
5
|
-
function conceptCategory(field) {
|
|
6
|
-
switch (field.kind) {
|
|
7
|
-
case "text":
|
|
8
|
-
case "prose":
|
|
9
|
-
return "text";
|
|
10
|
-
case "date":
|
|
11
|
-
return "date";
|
|
12
|
-
case "document":
|
|
13
|
-
return "document";
|
|
14
|
-
case "image":
|
|
15
|
-
return "image";
|
|
16
|
-
case "number":
|
|
17
|
-
return "number";
|
|
18
|
-
case "boolean":
|
|
19
|
-
return "boolean";
|
|
20
|
-
case "enum":
|
|
21
|
-
return "choice";
|
|
22
|
-
case "list":
|
|
23
|
-
return "list";
|
|
24
|
-
default:
|
|
25
|
-
return "structured";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/core/contracts.ts
|
|
30
|
-
function buildPipeRef(domain, pipeCode) {
|
|
31
|
-
return `${domain}.${pipeCode}`;
|
|
32
|
-
}
|
|
33
|
-
function getPipeIOContract(pipeIoContracts, domain, pipeCode) {
|
|
34
|
-
if (!pipeIoContracts || !pipeCode) return void 0;
|
|
35
|
-
if (domain) {
|
|
36
|
-
const byRef = pipeIoContracts[buildPipeRef(domain, pipeCode)];
|
|
37
|
-
if (byRef) return byRef;
|
|
38
|
-
}
|
|
39
|
-
return pipeIoContracts[pipeCode];
|
|
40
|
-
}
|
|
41
|
-
function isPluralInput(input) {
|
|
42
|
-
return input.json_schema?.type === "array";
|
|
43
|
-
}
|
|
44
|
-
function inputMustBeFilled(input) {
|
|
45
|
-
return input.optional !== true && !isPluralInput(input);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/core/native-concepts.ts
|
|
49
|
-
function nativeSet(...names) {
|
|
50
|
-
return new Set(names.flatMap((n) => [n, `native.${n}`]));
|
|
51
|
-
}
|
|
52
|
-
var TEXT_CONCEPTS = nativeSet("Text");
|
|
53
|
-
var DATE_CONCEPTS = nativeSet("Date");
|
|
54
|
-
var HTML_CONCEPTS = nativeSet("HTML");
|
|
55
|
-
var DOCUMENT_CONCEPTS = nativeSet("Document");
|
|
56
|
-
var PAGE_CONCEPTS = nativeSet("Page");
|
|
57
|
-
var IMAGE_CONCEPTS = nativeSet("Image");
|
|
58
|
-
var NUMBER_CONCEPTS = nativeSet("Number");
|
|
59
|
-
var YES_NO_CONCEPTS = nativeSet("YesNo");
|
|
60
|
-
var FIELD_TEXT_CONCEPTS = /* @__PURE__ */ new Set([
|
|
61
|
-
...TEXT_CONCEPTS,
|
|
62
|
-
...DATE_CONCEPTS
|
|
63
|
-
]);
|
|
64
|
-
var FIELD_DOCUMENT_CONCEPTS = /* @__PURE__ */ new Set([
|
|
65
|
-
...DOCUMENT_CONCEPTS,
|
|
66
|
-
...PAGE_CONCEPTS
|
|
67
|
-
]);
|
|
68
|
-
function isWireTextConcept(concept) {
|
|
69
|
-
return TEXT_CONCEPTS.has(concept);
|
|
70
|
-
}
|
|
71
|
-
function isWireDocumentLikeConcept(concept) {
|
|
72
|
-
return DOCUMENT_CONCEPTS.has(concept) || IMAGE_CONCEPTS.has(concept) || PAGE_CONCEPTS.has(concept);
|
|
73
|
-
}
|
|
74
|
-
var TEXT_WRAPPER_CONCEPTS = /* @__PURE__ */ new Set([
|
|
75
|
-
...TEXT_CONCEPTS,
|
|
76
|
-
...DATE_CONCEPTS,
|
|
77
|
-
...HTML_CONCEPTS
|
|
78
|
-
]);
|
|
79
|
-
function splitListConcept(conceptRef) {
|
|
80
|
-
if (!conceptRef) return { isList: false };
|
|
81
|
-
if (conceptRef.endsWith("[]")) return { base: conceptRef.slice(0, -2), isList: true };
|
|
82
|
-
return { base: conceptRef, isList: false };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/core/schema-utils.ts
|
|
86
|
-
function collapseNullable(schema) {
|
|
87
|
-
const anyOf = schema.anyOf;
|
|
88
|
-
if (!Array.isArray(anyOf)) return schema;
|
|
89
|
-
const branches = anyOf;
|
|
90
|
-
const nonNull = branches.filter((b) => b?.type !== "null");
|
|
91
|
-
if (nonNull.length === 1) return { ...stripAnyOf(schema), ...nonNull[0] };
|
|
92
|
-
return schema;
|
|
93
|
-
}
|
|
94
|
-
var PRIMITIVE_TYPES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "null"]);
|
|
95
|
-
function isSimplePrimitive(schema) {
|
|
96
|
-
const type = schema.type;
|
|
97
|
-
if (typeof type !== "string" || !PRIMITIVE_TYPES.has(type)) return false;
|
|
98
|
-
const allowedKeys = /* @__PURE__ */ new Set(["type", "default", "description", "title"]);
|
|
99
|
-
return Object.keys(schema).every((key) => allowedKeys.has(key));
|
|
100
|
-
}
|
|
101
|
-
function flattenAnyOf(schema) {
|
|
102
|
-
const anyOf = schema.anyOf;
|
|
103
|
-
if (!Array.isArray(anyOf)) return schema;
|
|
104
|
-
const branches = anyOf;
|
|
105
|
-
if (branches.every(
|
|
106
|
-
(branch) => typeof branch === "object" && branch !== null && isSimplePrimitive(branch)
|
|
107
|
-
)) {
|
|
108
|
-
const types = [];
|
|
109
|
-
let mergedDefault = void 0;
|
|
110
|
-
for (const branch of branches) {
|
|
111
|
-
types.push(branch.type);
|
|
112
|
-
if (branch.default !== void 0) mergedDefault = branch.default;
|
|
113
|
-
}
|
|
114
|
-
const { anyOf: _, ...rest } = schema;
|
|
115
|
-
const result = { ...rest, type: types };
|
|
116
|
-
if (mergedDefault !== void 0 && result.default === void 0) {
|
|
117
|
-
result.default = mergedDefault;
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
if (branches.length === 2) {
|
|
122
|
-
const nullBranch = branches.find(
|
|
123
|
-
(b) => typeof b === "object" && b !== null && b.type === "null"
|
|
124
|
-
);
|
|
125
|
-
const otherBranch = branches.find((b) => b !== nullBranch);
|
|
126
|
-
if (nullBranch && otherBranch && typeof otherBranch === "object") {
|
|
127
|
-
const { anyOf: _, ...rest } = schema;
|
|
128
|
-
return { ...rest, ...otherBranch };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return schema;
|
|
132
|
-
}
|
|
133
|
-
function stripAnyOf(schema) {
|
|
134
|
-
const { anyOf: _drop, ...rest } = schema;
|
|
135
|
-
return rest;
|
|
136
|
-
}
|
|
137
|
-
function schemaTypeOf(schema) {
|
|
138
|
-
const t = schema.type;
|
|
139
|
-
if (typeof t === "string") return t;
|
|
140
|
-
if (Array.isArray(t)) return t.find((x) => x !== "null");
|
|
141
|
-
return void 0;
|
|
142
|
-
}
|
|
143
|
-
function derefSchema(schema, defs) {
|
|
144
|
-
const ref = schema.$ref;
|
|
145
|
-
if (typeof ref === "string" && ref.startsWith("#/$defs/")) {
|
|
146
|
-
const resolved = defs[ref.slice("#/$defs/".length)];
|
|
147
|
-
if (resolved) return { ...resolved, ...stripRef(schema) };
|
|
148
|
-
}
|
|
149
|
-
return schema;
|
|
150
|
-
}
|
|
151
|
-
function stripRef(schema) {
|
|
152
|
-
const { $ref: _drop, ...rest } = schema;
|
|
153
|
-
return rest;
|
|
154
|
-
}
|
|
155
|
-
function resolveSchemaIndirection(schema, defs) {
|
|
156
|
-
let current = schema;
|
|
157
|
-
for (; ; ) {
|
|
158
|
-
const ref = current.$ref;
|
|
159
|
-
if (typeof ref === "string" && ref.startsWith("#/$defs/")) {
|
|
160
|
-
const resolved = defs[ref.slice("#/$defs/".length)];
|
|
161
|
-
if (resolved) {
|
|
162
|
-
current = resolved;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (Array.isArray(current.anyOf)) {
|
|
167
|
-
const nonNull = current.anyOf.filter((b) => b?.type !== "null");
|
|
168
|
-
if (nonNull.length === 1) {
|
|
169
|
-
current = nonNull[0];
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return current;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
function collectSchemaDefs(schema, into, options) {
|
|
177
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
178
|
-
if (key === "$defs" && value && typeof value === "object" && !Array.isArray(value)) {
|
|
179
|
-
for (const [name, def] of Object.entries(value)) {
|
|
180
|
-
if (!(name in into) && def && typeof def === "object") {
|
|
181
|
-
into[name] = def;
|
|
182
|
-
collectSchemaDefs(def, into, options);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
} else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
186
|
-
collectSchemaDefs(value, into, options);
|
|
187
|
-
} else if (options.traverseArrays && Array.isArray(value)) {
|
|
188
|
-
for (const item of value) {
|
|
189
|
-
if (item && typeof item === "object") {
|
|
190
|
-
collectSchemaDefs(item, into, options);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return into;
|
|
196
|
-
}
|
|
197
|
-
function walkAndCollectDefs(schema, collected) {
|
|
198
|
-
const out = {};
|
|
199
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
200
|
-
if (key === "$defs" && value && typeof value === "object" && !Array.isArray(value)) {
|
|
201
|
-
for (const [defName, defValue] of Object.entries(value)) {
|
|
202
|
-
if (!(defName in collected) && defValue && typeof defValue === "object") {
|
|
203
|
-
collected[defName] = {};
|
|
204
|
-
collected[defName] = walkAndCollectDefs(defValue, collected);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
} else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
208
|
-
out[key] = walkAndCollectDefs(value, collected);
|
|
209
|
-
} else if (Array.isArray(value)) {
|
|
210
|
-
out[key] = value.map(
|
|
211
|
-
(item) => item && typeof item === "object" && !Array.isArray(item) ? walkAndCollectDefs(item, collected) : item
|
|
212
|
-
);
|
|
213
|
-
} else {
|
|
214
|
-
out[key] = value;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return out;
|
|
218
|
-
}
|
|
219
|
-
function hoistDefsToRoot(schema) {
|
|
220
|
-
const collected = {};
|
|
221
|
-
const stripped = walkAndCollectDefs(schema, collected);
|
|
222
|
-
if (Object.keys(collected).length > 0) {
|
|
223
|
-
stripped.$defs = collected;
|
|
224
|
-
}
|
|
225
|
-
return stripped;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/core/derive.ts
|
|
229
|
-
function isDocumentObject(schema) {
|
|
230
|
-
const props = schema.properties;
|
|
231
|
-
return Boolean(props?.url);
|
|
232
|
-
}
|
|
233
|
-
function scalarWrapper(schema, ctx) {
|
|
234
|
-
const props = schema.properties;
|
|
235
|
-
const entries = props ? Object.entries(props) : [];
|
|
236
|
-
const only = entries.length === 1 ? entries[0] : void 0;
|
|
237
|
-
if (!only) return void 0;
|
|
238
|
-
const [key, propSchema] = only;
|
|
239
|
-
return { key, schema: collapseNullable(derefSchema(propSchema ?? {}, ctx.defs)) };
|
|
240
|
-
}
|
|
241
|
-
function mapSchema(name, conceptRef, rawSchema, required, ctx) {
|
|
242
|
-
const schema = collapseNullable(derefSchema(rawSchema, ctx.defs));
|
|
243
|
-
const common = {
|
|
244
|
-
name,
|
|
245
|
-
conceptRef,
|
|
246
|
-
description: typeof schema.description === "string" ? schema.description : void 0,
|
|
247
|
-
required
|
|
248
|
-
};
|
|
249
|
-
const { base, isList } = splitListConcept(conceptRef);
|
|
250
|
-
if (isList || schemaTypeOf(schema) === "array") {
|
|
251
|
-
const itemsSchema = schema.items ?? {};
|
|
252
|
-
const item = mapSchema(name, base, itemsSchema, true, { ...ctx, depth: ctx.depth + 1 });
|
|
253
|
-
return { ...common, kind: "list", item };
|
|
254
|
-
}
|
|
255
|
-
if (Array.isArray(schema.enum)) {
|
|
256
|
-
return { ...common, kind: "enum", options: schema.enum.map(String) };
|
|
257
|
-
}
|
|
258
|
-
if (base) {
|
|
259
|
-
if (FIELD_DOCUMENT_CONCEPTS.has(base))
|
|
260
|
-
return { ...common, kind: "document", accept: "PDF, DOCX, TXT" };
|
|
261
|
-
if (IMAGE_CONCEPTS.has(base)) return { ...common, kind: "image", accept: "PNG, JPG, WEBP" };
|
|
262
|
-
const wrapper = scalarWrapper(schema, ctx);
|
|
263
|
-
if (FIELD_TEXT_CONCEPTS.has(base) || HTML_CONCEPTS.has(base)) {
|
|
264
|
-
const contentKey = wrapper?.key ?? (TEXT_WRAPPER_CONCEPTS.has(base) ? "text" : void 0);
|
|
265
|
-
return ctx.depth === 0 ? { ...common, contentKey, kind: "prose" } : { ...common, contentKey, kind: "text" };
|
|
266
|
-
}
|
|
267
|
-
if (NUMBER_CONCEPTS.has(base))
|
|
268
|
-
return {
|
|
269
|
-
...common,
|
|
270
|
-
contentKey: wrapper?.key,
|
|
271
|
-
kind: "number",
|
|
272
|
-
// `NumberContent.number` is `int | float`, an unresolvable union, so the
|
|
273
|
-
// control stays a float input. Constraints are read off the WRAPPED
|
|
274
|
-
// property - the wrapper object never carries them, which is why the
|
|
275
|
-
// outer schema always answered `undefined`.
|
|
276
|
-
integer: false,
|
|
277
|
-
min: numOrUndef(wrapper?.schema.minimum ?? schema.minimum),
|
|
278
|
-
max: numOrUndef(wrapper?.schema.maximum ?? schema.maximum)
|
|
279
|
-
};
|
|
280
|
-
if (YES_NO_CONCEPTS.has(base)) return { ...common, contentKey: wrapper?.key, kind: "boolean" };
|
|
281
|
-
}
|
|
282
|
-
if (isDocumentObject(schema)) {
|
|
283
|
-
return { ...common, kind: "document", accept: "PDF, DOCX, TXT" };
|
|
284
|
-
}
|
|
285
|
-
const type = schemaTypeOf(schema);
|
|
286
|
-
switch (type) {
|
|
287
|
-
case "string": {
|
|
288
|
-
if (base && (FIELD_DOCUMENT_CONCEPTS.has(base) || base === "native.Document"))
|
|
289
|
-
return { ...common, kind: "document", accept: "PDF, DOCX, TXT" };
|
|
290
|
-
if (schema.format === "date" || schema.format === "date-time")
|
|
291
|
-
return { ...common, kind: "date", datetime: schema.format === "date-time" };
|
|
292
|
-
const long = base && FIELD_TEXT_CONCEPTS.has(base) ? ctx.depth === 0 : typeof schema.maxLength === "number" ? schema.maxLength > 120 : false;
|
|
293
|
-
return long ? { ...common, kind: "prose" } : { ...common, kind: "text", placeholder: void 0 };
|
|
294
|
-
}
|
|
295
|
-
case "integer":
|
|
296
|
-
return {
|
|
297
|
-
...common,
|
|
298
|
-
kind: "number",
|
|
299
|
-
integer: true,
|
|
300
|
-
min: numOrUndef(schema.minimum),
|
|
301
|
-
max: numOrUndef(schema.maximum)
|
|
302
|
-
};
|
|
303
|
-
case "number":
|
|
304
|
-
return {
|
|
305
|
-
...common,
|
|
306
|
-
kind: "number",
|
|
307
|
-
integer: false,
|
|
308
|
-
min: numOrUndef(schema.minimum),
|
|
309
|
-
max: numOrUndef(schema.maximum)
|
|
310
|
-
};
|
|
311
|
-
case "boolean":
|
|
312
|
-
return { ...common, kind: "boolean" };
|
|
313
|
-
case "object": {
|
|
314
|
-
const props = schema.properties ?? {};
|
|
315
|
-
const req = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
316
|
-
const fields = Object.entries(props).map(
|
|
317
|
-
([fieldName, fieldSchema]) => mapSchema(fieldName, void 0, fieldSchema, req.has(fieldName), {
|
|
318
|
-
...ctx,
|
|
319
|
-
depth: ctx.depth + 1
|
|
320
|
-
})
|
|
321
|
-
);
|
|
322
|
-
return { ...common, kind: "object", fields };
|
|
323
|
-
}
|
|
324
|
-
default:
|
|
325
|
-
if (base && FIELD_TEXT_CONCEPTS.has(base))
|
|
326
|
-
return ctx.depth === 0 ? { ...common, kind: "prose" } : { ...common, kind: "text" };
|
|
327
|
-
return { ...common, kind: "unknown" };
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
function numOrUndef(v) {
|
|
331
|
-
return typeof v === "number" ? v : void 0;
|
|
332
|
-
}
|
|
333
|
-
function buildRunFields(inputs) {
|
|
334
|
-
return Object.entries(inputs).map(([name, input]) => {
|
|
335
|
-
const defs = {};
|
|
336
|
-
collectSchemaDefs(input.json_schema, defs, { traverseArrays: true });
|
|
337
|
-
const field = mapSchema(name, input.concept_ref, input.json_schema, input.optional !== true, {
|
|
338
|
-
defs,
|
|
339
|
-
depth: 0
|
|
340
|
-
});
|
|
341
|
-
return { ...field, gating: inputMustBeFilled(input) };
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// src/core/readiness.ts
|
|
346
|
-
function isFilled(value) {
|
|
347
|
-
if (value == null || value === "") return false;
|
|
348
|
-
if (Array.isArray(value)) return value.length > 0 && value.some(isFilled);
|
|
349
|
-
if (typeof value === "object") {
|
|
350
|
-
const obj = value;
|
|
351
|
-
if ("url" in obj) return isFilled(obj.url);
|
|
352
|
-
return Object.values(obj).some(isFilled);
|
|
353
|
-
}
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
function fieldFilled(field, value) {
|
|
357
|
-
if (field.kind === "object") {
|
|
358
|
-
if (!value || typeof value !== "object") return field.fields.every((f) => !f.required);
|
|
359
|
-
const obj = value;
|
|
360
|
-
return field.fields.every((f) => !f.required || fieldFilled(f, obj[f.name]));
|
|
361
|
-
}
|
|
362
|
-
return isFilled(value);
|
|
363
|
-
}
|
|
364
|
-
function mustBeFilled(field) {
|
|
365
|
-
return field.gating ?? (field.required && field.kind !== "list");
|
|
366
|
-
}
|
|
367
|
-
function computeReadiness(fields, values) {
|
|
368
|
-
const gating = fields.filter(mustBeFilled);
|
|
369
|
-
const missing = gating.filter((f) => !fieldFilled(f, values[f.name])).map((f) => f.title ?? f.name);
|
|
370
|
-
return { total: gating.length, ready: gating.length - missing.length, missing };
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// src/core/date-format.ts
|
|
374
|
-
var FULL_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
375
|
-
var ZERO_TIME_DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})[T ]00:00(?::00(?:\.0+)?)?(?:Z|z|[+-]\d{2}:?\d{2})?$/;
|
|
376
|
-
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|z|[+-]\d{2}:?\d{2})?$/;
|
|
377
|
-
function isRealCalendarDate(value) {
|
|
378
|
-
const match = FULL_DATE_RE.exec(value);
|
|
379
|
-
if (!match) return false;
|
|
380
|
-
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
381
|
-
if (month < 1 || month > 12) return false;
|
|
382
|
-
const date = new Date(Date.UTC(year, month - 1, day));
|
|
383
|
-
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
384
|
-
}
|
|
385
|
-
function asCalendarDate(value) {
|
|
386
|
-
if (isRealCalendarDate(value)) return value;
|
|
387
|
-
const zeroTime = ZERO_TIME_DATE_TIME_RE.exec(value);
|
|
388
|
-
if (zeroTime && isRealCalendarDate(zeroTime[1])) return zeroTime[1];
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
function dayWithinDateTime(value) {
|
|
392
|
-
if (asCalendarDate(value) !== null) return null;
|
|
393
|
-
const match = DATE_TIME_RE.exec(value);
|
|
394
|
-
if (!match || !isRealCalendarDate(match[1])) return null;
|
|
395
|
-
return match[1];
|
|
396
|
-
}
|
|
397
|
-
function isAcceptableDate(value) {
|
|
398
|
-
return isRealCalendarDate(value);
|
|
399
|
-
}
|
|
400
|
-
function isAcceptableDateTime(value) {
|
|
401
|
-
if (isRealCalendarDate(value)) return true;
|
|
402
|
-
const match = DATE_TIME_RE.exec(value);
|
|
403
|
-
if (!match || !isRealCalendarDate(match[1])) return false;
|
|
404
|
-
const [hours, minutes, seconds] = [Number(match[2]), Number(match[3]), Number(match[4] ?? 0)];
|
|
405
|
-
return hours <= 23 && minutes <= 59 && seconds <= 59;
|
|
406
|
-
}
|
|
407
|
-
function toDateInputValue(value) {
|
|
408
|
-
if (typeof value !== "string") return "";
|
|
409
|
-
return asCalendarDate(value) ?? value.slice(0, 10);
|
|
410
|
-
}
|
|
411
|
-
function toStoredDateValue(day, datetime) {
|
|
412
|
-
if (!day) return void 0;
|
|
413
|
-
return datetime ? `${day}T00:00:00Z` : day;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/core/gate-validator.ts
|
|
417
|
-
var ajv = new Ajv({
|
|
418
|
-
allErrors: true,
|
|
419
|
-
multipleOfPrecision: 8,
|
|
420
|
-
strict: false,
|
|
421
|
-
verbose: true,
|
|
422
|
-
discriminator: false,
|
|
423
|
-
coerceTypes: true
|
|
424
|
-
});
|
|
425
|
-
addFormats(ajv);
|
|
426
|
-
ajv.addFormat("data-url", /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/);
|
|
427
|
-
ajv.addFormat(
|
|
428
|
-
"color",
|
|
429
|
-
/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/
|
|
430
|
-
);
|
|
431
|
-
ajv.addFormat("date", isAcceptableDate);
|
|
432
|
-
ajv.addFormat("date-time", isAcceptableDateTime);
|
|
433
|
-
function validateRunInputsSchema(data, schema) {
|
|
434
|
-
let validate;
|
|
435
|
-
try {
|
|
436
|
-
validate = ajv.compile(schema);
|
|
437
|
-
} catch (err) {
|
|
438
|
-
return [{ stack: err instanceof Error ? err.message : String(err) }];
|
|
439
|
-
}
|
|
440
|
-
validate(data);
|
|
441
|
-
const errors = (validate.errors ?? []).map(toRunInputError);
|
|
442
|
-
validate.errors = null;
|
|
443
|
-
return errors;
|
|
444
|
-
}
|
|
445
|
-
function toRunInputError(e) {
|
|
446
|
-
const { instancePath, keyword, schemaPath, parentSchema } = e;
|
|
447
|
-
const params = e.params;
|
|
448
|
-
const message = e.message ?? "";
|
|
449
|
-
let property = instancePath.replace(/\//g, ".");
|
|
450
|
-
let stack = `${property} ${message}`.trim();
|
|
451
|
-
const namesAProperty = [
|
|
452
|
-
...typeof params.deps === "string" ? params.deps.split(", ") : [],
|
|
453
|
-
params.missingProperty,
|
|
454
|
-
params.property
|
|
455
|
-
].some((item) => typeof item === "string" && item.length > 0);
|
|
456
|
-
if (namesAProperty) {
|
|
457
|
-
stack = message;
|
|
458
|
-
} else {
|
|
459
|
-
const parentTitle = parentSchema?.title;
|
|
460
|
-
if (typeof parentTitle === "string" && parentTitle) {
|
|
461
|
-
stack = `'${parentTitle}' ${message}`.trim();
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if ("missingProperty" in params) {
|
|
465
|
-
const missing = String(params.missingProperty);
|
|
466
|
-
property = property ? `${property}.${missing}` : missing;
|
|
467
|
-
}
|
|
468
|
-
return { name: keyword, property, message, params, stack, schemaPath };
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// src/core/wire-format.ts
|
|
472
|
-
function isListConcept(conceptCode) {
|
|
473
|
-
const { base, isList } = splitListConcept(conceptCode);
|
|
474
|
-
return { isList, baseConcept: base ?? "" };
|
|
475
|
-
}
|
|
476
|
-
var isTextConcept = isWireTextConcept;
|
|
477
|
-
var isDocumentLikeConcept = isWireDocumentLikeConcept;
|
|
478
|
-
function deflateInput(value, conceptCode) {
|
|
479
|
-
const { isList, baseConcept } = isListConcept(conceptCode);
|
|
480
|
-
if (isList) {
|
|
481
|
-
const items = Array.isArray(value) ? value : [];
|
|
482
|
-
return items.map((item) => deflateListItem(item, baseConcept));
|
|
483
|
-
}
|
|
484
|
-
return deflateSingleValue(value, baseConcept);
|
|
485
|
-
}
|
|
486
|
-
function deflateListItem(value, concept) {
|
|
487
|
-
if (isTextConcept(concept)) {
|
|
488
|
-
if (value && typeof value === "object" && "text" in value) {
|
|
489
|
-
return value.text;
|
|
490
|
-
}
|
|
491
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
492
|
-
}
|
|
493
|
-
if (isDocumentLikeConcept(concept)) {
|
|
494
|
-
if (value && typeof value === "object" && "url" in value) {
|
|
495
|
-
return value.url;
|
|
496
|
-
}
|
|
497
|
-
if (typeof value === "string") return value;
|
|
498
|
-
return "";
|
|
499
|
-
}
|
|
500
|
-
return { concept, content: unwrapAllWrappers(value) };
|
|
501
|
-
}
|
|
502
|
-
function deflateSingleValue(value, concept) {
|
|
503
|
-
if (isTextConcept(concept)) {
|
|
504
|
-
if (value && typeof value === "object" && "text" in value) {
|
|
505
|
-
return value.text;
|
|
506
|
-
}
|
|
507
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
508
|
-
}
|
|
509
|
-
if (isDocumentLikeConcept(concept)) {
|
|
510
|
-
if (value && typeof value === "object" && "url" in value) {
|
|
511
|
-
return value.url;
|
|
512
|
-
}
|
|
513
|
-
if (typeof value === "string") return value;
|
|
514
|
-
return "";
|
|
515
|
-
}
|
|
516
|
-
return { concept, content: unwrapAllWrappers(value) };
|
|
517
|
-
}
|
|
518
|
-
function inflateInput(value, conceptCode) {
|
|
519
|
-
const { isList, baseConcept } = isListConcept(conceptCode);
|
|
520
|
-
if (isList) {
|
|
521
|
-
const unwrapped = isWrappedForm(value) ? value.content : value;
|
|
522
|
-
let items;
|
|
523
|
-
if (Array.isArray(unwrapped)) {
|
|
524
|
-
items = unwrapped;
|
|
525
|
-
} else if (unwrapped != null && typeof unwrapped === "object") {
|
|
526
|
-
items = [unwrapped];
|
|
527
|
-
} else {
|
|
528
|
-
items = [];
|
|
529
|
-
}
|
|
530
|
-
return items.map((item) => inflateSingleValue(item, baseConcept));
|
|
531
|
-
}
|
|
532
|
-
return inflateSingleValue(value, baseConcept);
|
|
533
|
-
}
|
|
534
|
-
var DOCUMENT_FIELDS = /* @__PURE__ */ new Set(["url", "public_url", "mime_type", "filename", "title", "snippet"]);
|
|
535
|
-
function looksLikeDocument(obj) {
|
|
536
|
-
return Object.keys(obj).some((k) => DOCUMENT_FIELDS.has(k));
|
|
537
|
-
}
|
|
538
|
-
function isWrappedForm(value) {
|
|
539
|
-
return !!value && typeof value === "object" && "concept" in value && "content" in value && typeof value.concept === "string";
|
|
540
|
-
}
|
|
541
|
-
function inflateSingleValue(value, concept) {
|
|
542
|
-
if (isWrappedForm(value) && (isTextConcept(concept) || isDocumentLikeConcept(concept))) {
|
|
543
|
-
return inflateSingleValue(value.content, concept);
|
|
544
|
-
}
|
|
545
|
-
if (isTextConcept(concept)) {
|
|
546
|
-
if (typeof value === "string") {
|
|
547
|
-
return { text: value };
|
|
548
|
-
}
|
|
549
|
-
if (value && typeof value === "object" && "text" in value) {
|
|
550
|
-
return value;
|
|
551
|
-
}
|
|
552
|
-
return { text: "" };
|
|
553
|
-
}
|
|
554
|
-
if (isDocumentLikeConcept(concept)) {
|
|
555
|
-
if (typeof value === "string") {
|
|
556
|
-
return { url: value };
|
|
557
|
-
}
|
|
558
|
-
if (value && typeof value === "object" && "url" in value) {
|
|
559
|
-
return value;
|
|
560
|
-
}
|
|
561
|
-
if (value && typeof value === "object" && looksLikeDocument(value)) {
|
|
562
|
-
return { ...value, url: "" };
|
|
563
|
-
}
|
|
564
|
-
return { url: "" };
|
|
565
|
-
}
|
|
566
|
-
return unwrapAllWrappers(value);
|
|
567
|
-
}
|
|
568
|
-
function unwrapAllWrappers(value) {
|
|
569
|
-
let current = value;
|
|
570
|
-
while (isWrappedForm(current)) {
|
|
571
|
-
current = current.content;
|
|
572
|
-
}
|
|
573
|
-
if (current && typeof current === "object" && !Array.isArray(current) && "content" in current) {
|
|
574
|
-
return current.content;
|
|
575
|
-
}
|
|
576
|
-
return current;
|
|
577
|
-
}
|
|
578
|
-
function resolveConceptCode(schema) {
|
|
579
|
-
const code = schema.concept_ref;
|
|
580
|
-
if (!code) return "";
|
|
581
|
-
if (!code.endsWith("[]") && schema.json_schema?.type === "array") {
|
|
582
|
-
return code + "[]";
|
|
583
|
-
}
|
|
584
|
-
return code;
|
|
585
|
-
}
|
|
586
|
-
function deflateAllInputs(formData, inputSchemas) {
|
|
587
|
-
const result = {};
|
|
588
|
-
for (const [stuffName, schema] of Object.entries(inputSchemas)) {
|
|
589
|
-
result[stuffName] = deflateInput(formData[stuffName], resolveConceptCode(schema));
|
|
590
|
-
}
|
|
591
|
-
return result;
|
|
592
|
-
}
|
|
593
|
-
function healStringWrappers(value, rawSchema, defs) {
|
|
594
|
-
if (!rawSchema || value == null) return value;
|
|
595
|
-
const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });
|
|
596
|
-
const schema = resolveSchemaIndirection(rawSchema, allDefs);
|
|
597
|
-
const type = schemaTypeOf(schema);
|
|
598
|
-
if (type === "string" && schema.format === "date" && typeof value === "string") {
|
|
599
|
-
return asCalendarDate(value) ?? value;
|
|
600
|
-
}
|
|
601
|
-
if (type === "string") {
|
|
602
|
-
if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 1 && typeof value.text === "string") {
|
|
603
|
-
return value.text;
|
|
604
|
-
}
|
|
605
|
-
return value;
|
|
606
|
-
}
|
|
607
|
-
if (type === "object" && typeof value === "object" && !Array.isArray(value)) {
|
|
608
|
-
const props = schema.properties;
|
|
609
|
-
if (!props) return value;
|
|
610
|
-
const out = { ...value };
|
|
611
|
-
for (const [key, propSchema] of Object.entries(props)) {
|
|
612
|
-
if (key in out) out[key] = healStringWrappers(out[key], propSchema, allDefs);
|
|
613
|
-
}
|
|
614
|
-
return out;
|
|
615
|
-
}
|
|
616
|
-
if (type === "array" && Array.isArray(value)) {
|
|
617
|
-
const items = schema.items;
|
|
618
|
-
return value.map((item) => healStringWrappers(item, items, allDefs));
|
|
619
|
-
}
|
|
620
|
-
return value;
|
|
621
|
-
}
|
|
622
|
-
function isEmptyAfterPruning(value) {
|
|
623
|
-
if (value === "" || value === null || value === void 0) return true;
|
|
624
|
-
return typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
625
|
-
}
|
|
626
|
-
function pruneEmptyOptionals(value, rawSchema, defs) {
|
|
627
|
-
if (!rawSchema || value == null) return value;
|
|
628
|
-
const allDefs = defs ?? collectSchemaDefs(rawSchema, {}, { traverseArrays: false });
|
|
629
|
-
const schema = resolveSchemaIndirection(rawSchema, allDefs);
|
|
630
|
-
const type = schemaTypeOf(schema);
|
|
631
|
-
if (type === "array" && Array.isArray(value)) {
|
|
632
|
-
const items = schema.items;
|
|
633
|
-
return value.map((item) => pruneEmptyOptionals(item, items, allDefs));
|
|
634
|
-
}
|
|
635
|
-
if (type !== "object" || typeof value !== "object" || Array.isArray(value)) return value;
|
|
636
|
-
const props = schema.properties;
|
|
637
|
-
if (!props) return value;
|
|
638
|
-
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
639
|
-
const out = {};
|
|
640
|
-
for (const [key, raw] of Object.entries(value)) {
|
|
641
|
-
const propSchema = props[key];
|
|
642
|
-
if (!propSchema) {
|
|
643
|
-
out[key] = raw;
|
|
644
|
-
continue;
|
|
645
|
-
}
|
|
646
|
-
const pruned = pruneEmptyOptionals(raw, propSchema, allDefs);
|
|
647
|
-
if (isEmptyAfterPruning(pruned) && !required.has(key)) continue;
|
|
648
|
-
out[key] = pruned;
|
|
649
|
-
}
|
|
650
|
-
return out;
|
|
651
|
-
}
|
|
652
|
-
function inflateAllInputs(simplifiedData, inputSchemas) {
|
|
653
|
-
const result = {};
|
|
654
|
-
for (const [stuffName, value] of Object.entries(simplifiedData)) {
|
|
655
|
-
const schema = inputSchemas[stuffName];
|
|
656
|
-
if (schema) {
|
|
657
|
-
result[stuffName] = healStringWrappers(
|
|
658
|
-
inflateInput(value, resolveConceptCode(schema)),
|
|
659
|
-
schema.json_schema
|
|
660
|
-
);
|
|
661
|
-
} else {
|
|
662
|
-
result[stuffName] = value;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
return result;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// src/core/normalize-schema.ts
|
|
669
|
-
function normalizeSchemaForRjsf(schema) {
|
|
670
|
-
let normalized = flattenAnyOf(schema);
|
|
671
|
-
if (normalized.properties && typeof normalized.properties === "object") {
|
|
672
|
-
const props = normalized.properties;
|
|
673
|
-
const normalizedProps = {};
|
|
674
|
-
for (const [key, value] of Object.entries(props)) {
|
|
675
|
-
normalizedProps[key] = value && typeof value === "object" ? normalizeSchemaForRjsf(value) : value;
|
|
676
|
-
}
|
|
677
|
-
normalized = { ...normalized, properties: normalizedProps };
|
|
678
|
-
}
|
|
679
|
-
if (normalized.items && typeof normalized.items === "object" && !Array.isArray(normalized.items)) {
|
|
680
|
-
normalized = {
|
|
681
|
-
...normalized,
|
|
682
|
-
items: normalizeSchemaForRjsf(normalized.items)
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
if (Array.isArray(normalized.anyOf)) {
|
|
686
|
-
normalized = {
|
|
687
|
-
...normalized,
|
|
688
|
-
anyOf: normalized.anyOf.map(
|
|
689
|
-
(branch) => typeof branch === "object" && branch !== null ? normalizeSchemaForRjsf(branch) : branch
|
|
690
|
-
)
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
if (normalized.$defs && typeof normalized.$defs === "object" && !Array.isArray(normalized.$defs)) {
|
|
694
|
-
const defs = normalized.$defs;
|
|
695
|
-
const normalizedDefs = {};
|
|
696
|
-
for (const [key, value] of Object.entries(defs)) {
|
|
697
|
-
normalizedDefs[key] = value && typeof value === "object" ? normalizeSchemaForRjsf(value) : value;
|
|
698
|
-
}
|
|
699
|
-
normalized = { ...normalized, $defs: normalizedDefs };
|
|
700
|
-
}
|
|
701
|
-
return normalized;
|
|
702
|
-
}
|
|
703
|
-
function prepareSchemaForRjsf(schema) {
|
|
704
|
-
return normalizeSchemaForRjsf(hoistDefsToRoot(schema));
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// src/core/gate.ts
|
|
708
|
-
function buildRunInputsSchema(inputs) {
|
|
709
|
-
const properties = {};
|
|
710
|
-
const required = [];
|
|
711
|
-
for (const [varName, input] of Object.entries(inputs)) {
|
|
712
|
-
const inputSchema = { ...input.json_schema };
|
|
713
|
-
inputSchema.title = varName;
|
|
714
|
-
if (input.concept_ref && input.concept_ref !== varName) {
|
|
715
|
-
inputSchema.description = input.concept_ref;
|
|
716
|
-
}
|
|
717
|
-
properties[varName] = inputSchema;
|
|
718
|
-
if (inputMustBeFilled(input)) required.push(varName);
|
|
719
|
-
}
|
|
720
|
-
return prepareSchemaForRjsf({ type: "object", properties, required });
|
|
721
|
-
}
|
|
722
|
-
function prepareRunInputs(data, schema) {
|
|
723
|
-
return pruneEmptyOptionals(healStringWrappers(data, schema), schema);
|
|
724
|
-
}
|
|
725
|
-
function validateRunInputs(preparedData, inputs, schema) {
|
|
726
|
-
const errors = validateRunInputsSchema(preparedData, schema);
|
|
727
|
-
if (errors.length === 0) return { isValid: true, missingInputs: [], errors: [] };
|
|
728
|
-
const missingInputs = [];
|
|
729
|
-
for (const [varName, input] of Object.entries(inputs)) {
|
|
730
|
-
if (!inputMustBeFilled(input)) continue;
|
|
731
|
-
const varData = preparedData[varName];
|
|
732
|
-
const inputSchema = input.json_schema;
|
|
733
|
-
const requiredFields = inputSchema.required || [];
|
|
734
|
-
if (requiredFields.length === 0) continue;
|
|
735
|
-
if (!varData || typeof varData !== "object") {
|
|
736
|
-
missingInputs.push(varName);
|
|
737
|
-
continue;
|
|
738
|
-
}
|
|
739
|
-
const record = varData;
|
|
740
|
-
if (requiredFields.some((f) => record[f] === void 0 || record[f] === "")) {
|
|
741
|
-
missingInputs.push(varName);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
return { isValid: false, missingInputs, errors };
|
|
745
|
-
}
|
|
746
|
-
function apiInputsFromSchemaData(preparedData, inputs) {
|
|
747
|
-
const out = {};
|
|
748
|
-
for (const [varName, input] of Object.entries(inputs)) {
|
|
749
|
-
const raw = preparedData[varName];
|
|
750
|
-
if (input.optional === true && !isFilled(raw)) continue;
|
|
751
|
-
if (isPluralInput(input) && !isFilled(raw)) {
|
|
752
|
-
out[varName] = [];
|
|
753
|
-
continue;
|
|
754
|
-
}
|
|
755
|
-
const content = isPluralInput(input) && !Array.isArray(raw) ? [] : raw;
|
|
756
|
-
out[varName] = { concept: input.concept_ref, content };
|
|
757
|
-
}
|
|
758
|
-
return out;
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
// src/core/values.ts
|
|
762
|
-
function wrapContent(field, value) {
|
|
763
|
-
return field.contentKey === void 0 ? value : { [field.contentKey]: value };
|
|
764
|
-
}
|
|
765
|
-
function unwrapContent(field, value) {
|
|
766
|
-
const key = field.contentKey;
|
|
767
|
-
if (key === void 0 || !value || typeof value !== "object" || Array.isArray(value))
|
|
768
|
-
return value;
|
|
769
|
-
return value[key];
|
|
770
|
-
}
|
|
771
|
-
var MAX_UNWRAP_DEPTH = 8;
|
|
772
|
-
function textFromStored(value, depth = 0) {
|
|
773
|
-
if (value == null) return void 0;
|
|
774
|
-
if (typeof value === "string") return value;
|
|
775
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
776
|
-
if (typeof value !== "object" || depth >= MAX_UNWRAP_DEPTH) return void 0;
|
|
777
|
-
const envelope = value;
|
|
778
|
-
if ("text" in envelope) return textFromStored(envelope.text, depth + 1);
|
|
779
|
-
if ("content" in envelope) return textFromStored(envelope.content, depth + 1);
|
|
780
|
-
return void 0;
|
|
781
|
-
}
|
|
782
|
-
function fromRjsf(field, value) {
|
|
783
|
-
switch (field.kind) {
|
|
784
|
-
case "text":
|
|
785
|
-
case "prose":
|
|
786
|
-
return textFromStored(value);
|
|
787
|
-
case "number": {
|
|
788
|
-
const raw = unwrapContent(field, value);
|
|
789
|
-
if (typeof raw === "number") return Number.isFinite(raw) ? raw : void 0;
|
|
790
|
-
if (typeof raw === "string" && raw.trim() !== "") {
|
|
791
|
-
const parsed = Number(raw);
|
|
792
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
793
|
-
}
|
|
794
|
-
return void 0;
|
|
795
|
-
}
|
|
796
|
-
case "boolean": {
|
|
797
|
-
const raw = unwrapContent(field, value);
|
|
798
|
-
return typeof raw === "boolean" ? raw : void 0;
|
|
799
|
-
}
|
|
800
|
-
case "unknown":
|
|
801
|
-
if (typeof value === "string") return value;
|
|
802
|
-
if (value == null) return void 0;
|
|
803
|
-
if (typeof value === "object") {
|
|
804
|
-
try {
|
|
805
|
-
return JSON.stringify(value, null, 2);
|
|
806
|
-
} catch {
|
|
807
|
-
return void 0;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
return String(value);
|
|
811
|
-
case "document":
|
|
812
|
-
case "image": {
|
|
813
|
-
if (value && typeof value === "object") {
|
|
814
|
-
const o = value;
|
|
815
|
-
return o.url ? { url: String(o.url), filename: o.filename } : void 0;
|
|
816
|
-
}
|
|
817
|
-
return typeof value === "string" && value ? { url: value } : void 0;
|
|
818
|
-
}
|
|
819
|
-
case "object": {
|
|
820
|
-
const obj = value && typeof value === "object" ? value : {};
|
|
821
|
-
const out = {};
|
|
822
|
-
for (const child of field.fields) out[child.name] = fromRjsf(child, obj[child.name]);
|
|
823
|
-
return out;
|
|
824
|
-
}
|
|
825
|
-
case "list": {
|
|
826
|
-
const arr = Array.isArray(value) ? value : [];
|
|
827
|
-
return arr.map((item) => fromRjsf(field.item, item));
|
|
828
|
-
}
|
|
829
|
-
default:
|
|
830
|
-
return value;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
function toRjsf(field, value, collapseEmpty = true) {
|
|
834
|
-
switch (field.kind) {
|
|
835
|
-
case "text":
|
|
836
|
-
case "prose":
|
|
837
|
-
return wrapContent(field, typeof value === "string" ? value : "");
|
|
838
|
-
case "number":
|
|
839
|
-
return typeof value === "number" && Number.isFinite(value) ? wrapContent(field, value) : void 0;
|
|
840
|
-
case "boolean":
|
|
841
|
-
return typeof value === "boolean" ? wrapContent(field, value) : void 0;
|
|
842
|
-
case "unknown":
|
|
843
|
-
return typeof value === "string" ? value : "";
|
|
844
|
-
case "document":
|
|
845
|
-
case "image": {
|
|
846
|
-
const url = value && typeof value === "object" ? value.url : value;
|
|
847
|
-
const filename = value && typeof value === "object" ? value.filename : void 0;
|
|
848
|
-
return { url: url ? String(url) : "", ...filename ? { filename } : {} };
|
|
849
|
-
}
|
|
850
|
-
case "object": {
|
|
851
|
-
const obj = value && typeof value === "object" ? value : {};
|
|
852
|
-
const out = {};
|
|
853
|
-
for (const child of field.fields) out[child.name] = toRjsf(child, obj[child.name]);
|
|
854
|
-
return collapseEmpty && !isFilled(out) ? void 0 : out;
|
|
855
|
-
}
|
|
856
|
-
case "list": {
|
|
857
|
-
const arr = Array.isArray(value) ? value : [];
|
|
858
|
-
return arr.map((item) => toRjsf(field.item, item, false));
|
|
859
|
-
}
|
|
860
|
-
default:
|
|
861
|
-
return value;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
function runValuesFromStore(inputData, fields, inputSchemas) {
|
|
865
|
-
const full = inflateAllInputs(inputData ?? {}, inputSchemas);
|
|
866
|
-
const out = {};
|
|
867
|
-
for (const field of fields) out[field.name] = fromRjsf(field, full[field.name]);
|
|
868
|
-
return out;
|
|
869
|
-
}
|
|
870
|
-
function rjsfDataFromRunValues(values, fields) {
|
|
871
|
-
const full = {};
|
|
872
|
-
for (const field of fields) full[field.name] = toRjsf(field, values[field.name]);
|
|
873
|
-
return full;
|
|
874
|
-
}
|
|
875
|
-
function storeInputDataFromRunValues(values, fields, inputSchemas) {
|
|
876
|
-
return deflateAllInputs(rjsfDataFromRunValues(values, fields), inputSchemas);
|
|
877
|
-
}
|
|
878
|
-
function apiInputsFromRunValues(values, fields, inputSchemas) {
|
|
879
|
-
const out = {};
|
|
880
|
-
for (const field of fields) {
|
|
881
|
-
const schema = inputSchemas[field.name];
|
|
882
|
-
if (!schema) continue;
|
|
883
|
-
if (schema.optional === true && !isFilled(values[field.name])) continue;
|
|
884
|
-
if (isPluralInput(schema) && !isFilled(values[field.name])) {
|
|
885
|
-
out[field.name] = [];
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
|
-
out[field.name] = { concept: schema.concept_ref, content: toRjsf(field, values[field.name]) };
|
|
889
|
-
}
|
|
890
|
-
return out;
|
|
891
|
-
}
|
|
892
|
-
function hasWorkingMemoryRoot(value) {
|
|
893
|
-
return !!value && typeof value === "object" && "working_memory" in value && !!value.working_memory && typeof value.working_memory.root === "object";
|
|
894
|
-
}
|
|
895
|
-
function entryConceptRef(data) {
|
|
896
|
-
if (!data || typeof data !== "object") return void 0;
|
|
897
|
-
const raw = data.concept;
|
|
898
|
-
if (raw && typeof raw === "object")
|
|
899
|
-
return (raw.concept_code ?? raw.code) || void 0;
|
|
900
|
-
if (typeof raw === "string") return raw;
|
|
901
|
-
return data.concept_code || void 0;
|
|
902
|
-
}
|
|
903
|
-
function outputsFromPipeOutput(pipeOutput, inputKeys) {
|
|
904
|
-
if (!hasWorkingMemoryRoot(pipeOutput)) return null;
|
|
905
|
-
const wm = pipeOutput.working_memory;
|
|
906
|
-
const entries = Object.entries(wm.root).filter(([key]) => !inputKeys.includes(key));
|
|
907
|
-
if (entries.length === 0) return null;
|
|
908
|
-
const toEntry = ([key, data]) => ({
|
|
909
|
-
key,
|
|
910
|
-
conceptRef: entryConceptRef(data),
|
|
911
|
-
value: data?.content ?? data
|
|
912
|
-
});
|
|
913
|
-
const mainKey = wm.aliases?.["main_stuff"];
|
|
914
|
-
const mainEntry = mainKey && Object.prototype.hasOwnProperty.call(wm.root, mainKey) ? [mainKey, wm.root[mainKey]] : entries[entries.length - 1];
|
|
915
|
-
const intermediates = entries.filter(([key]) => key !== mainEntry[0]).map(toEntry);
|
|
916
|
-
return { main: toEntry(mainEntry), intermediates };
|
|
917
|
-
}
|
|
918
|
-
function inputDataFromWorkingMemory(workingMemory, inputSchemas) {
|
|
919
|
-
const root = workingMemory?.root;
|
|
920
|
-
if (!root || typeof root !== "object") return null;
|
|
921
|
-
const full = {};
|
|
922
|
-
let found = false;
|
|
923
|
-
for (const key of Object.keys(inputSchemas)) {
|
|
924
|
-
const entry = root[key];
|
|
925
|
-
if (entry && typeof entry === "object" && "content" in entry) {
|
|
926
|
-
full[key] = entry.content;
|
|
927
|
-
found = true;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (!found) return null;
|
|
931
|
-
return deflateAllInputs(full, inputSchemas);
|
|
932
|
-
}
|
|
933
|
-
function fieldsForContract(contract) {
|
|
934
|
-
return contract?.inputs ? buildRunFields(contract.inputs) : [];
|
|
935
|
-
}
|
|
936
|
-
function setValueAtPath(root, path, value) {
|
|
937
|
-
const head = path[0];
|
|
938
|
-
if (head === void 0) return root;
|
|
939
|
-
const rest = path.slice(1);
|
|
940
|
-
if (rest.length === 0) return { ...root, [head]: value };
|
|
941
|
-
const nextSeg = rest[0];
|
|
942
|
-
const child = root[head];
|
|
943
|
-
if (/^\d+$/.test(nextSeg)) {
|
|
944
|
-
const arr = Array.isArray(child) ? child.slice() : [];
|
|
945
|
-
const idx = Number(nextSeg);
|
|
946
|
-
arr[idx] = rest.length === 1 ? value : setValueAtPath(arr[idx] ?? {}, rest.slice(1), value);
|
|
947
|
-
return { ...root, [head]: arr };
|
|
948
|
-
}
|
|
949
|
-
return { ...root, [head]: setValueAtPath(child ?? {}, rest, value) };
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
// src/core/validation-message.ts
|
|
953
|
-
var MAX_SHOWN_VALUE_CHARS = 120;
|
|
954
|
-
function valueAtProperty(data, property) {
|
|
955
|
-
if (!property) return void 0;
|
|
956
|
-
let current = data;
|
|
957
|
-
for (const segment of property.split(".").filter(Boolean)) {
|
|
958
|
-
if (typeof current !== "object" || current === null) return void 0;
|
|
959
|
-
current = current[segment];
|
|
960
|
-
}
|
|
961
|
-
return current;
|
|
962
|
-
}
|
|
963
|
-
function displayValue(value) {
|
|
964
|
-
if (value === void 0 || value === null) return null;
|
|
965
|
-
if (typeof value === "string" && value.trim() === "") return null;
|
|
966
|
-
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
967
|
-
if (text === void 0) return null;
|
|
968
|
-
return text.length > MAX_SHOWN_VALUE_CHARS ? `${text.slice(0, MAX_SHOWN_VALUE_CHARS)}\u2026` : text;
|
|
969
|
-
}
|
|
970
|
-
function labelOf(error, t) {
|
|
971
|
-
return error.stack?.match(/'([^']+)'/)?.[1] ?? t("inputPanel.aDateField");
|
|
972
|
-
}
|
|
973
|
-
function describeValidationError(error, t, formData) {
|
|
974
|
-
const format = error.params?.format;
|
|
975
|
-
const value = valueAtProperty(formData, error.property);
|
|
976
|
-
const shown = displayValue(value);
|
|
977
|
-
if (error.name === "format" && (format === "date" || format === "date-time")) {
|
|
978
|
-
const label = labelOf(error, t);
|
|
979
|
-
if (shown === null) return t("inputPanel.pickValidDateEmpty", { label });
|
|
980
|
-
const day = format === "date" && typeof value === "string" ? dayWithinDateTime(value) : null;
|
|
981
|
-
if (day !== null) return t("inputPanel.dateCarriesTime", { label, value: shown, day });
|
|
982
|
-
return t("inputPanel.pickValidDate", { label, value: shown });
|
|
983
|
-
}
|
|
984
|
-
const stack = error.stack ?? error.message ?? t("inputPanel.invalidValue");
|
|
985
|
-
return shown === null ? stack : t("inputPanel.invalidValueWithData", { stack, value: shown });
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
export { apiInputsFromRunValues, apiInputsFromSchemaData, asCalendarDate, buildPipeRef, buildRunFields, buildRunInputsSchema, collapseNullable, collectSchemaDefs, computeReadiness, conceptCategory, dayWithinDateTime, deflateAllInputs, deflateInput, derefSchema, describeValidationError, displayValue, fieldFilled, fieldsForContract, flattenAnyOf, getPipeIOContract, healStringWrappers, hoistDefsToRoot, inflateAllInputs, inflateInput, inputDataFromWorkingMemory, inputMustBeFilled, isAcceptableDate, isAcceptableDateTime, isFilled, isPluralInput, mustBeFilled, normalizeSchemaForRjsf, outputsFromPipeOutput, prepareRunInputs, prepareSchemaForRjsf, pruneEmptyOptionals, resolveConceptCode, resolveSchemaIndirection, rjsfDataFromRunValues, runValuesFromStore, schemaTypeOf, setValueAtPath, storeInputDataFromRunValues, toDateInputValue, toStoredDateValue, validateRunInputs, validateRunInputsSchema, valueAtProperty };
|
|
989
|
-
//# sourceMappingURL=chunk-S6KOTTGD.js.map
|
|
990
|
-
//# sourceMappingURL=chunk-S6KOTTGD.js.map
|