mlform 0.1.20 → 0.1.23
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 +2 -2
- package/dist/{builtins-CUN_bP93.js → builtins-rkxD-h7K.js} +7 -7
- package/dist/mlform/builtins.mjs +1 -1
- package/dist/mlform/kit.mjs +8 -8
- package/dist/mlform/primitives.mjs +1 -1
- package/dist/mlform/runtime.mjs +1 -1
- package/dist/mlform/schema.mjs +2 -2
- package/dist/{primitives-CgFaSmAm.js → primitives-ljp3c5R8.js} +4 -8
- package/dist/{runtime-zS0p2589.js → runtime-BQsOz8iz.js} +294 -304
- package/dist/schema-BI-Ia-h9.js +339 -0
- package/dist/types/src/primitives/controller-types.d.ts +8 -16
- package/dist/types/src/runtime/submission/request.d.ts +0 -4
- package/dist/types/src/runtime/types/behavior.d.ts +0 -4
- package/dist/types/src/runtime/types/transport.d.ts +0 -12
- package/dist/types/src/schema/mapped-to.d.ts +5 -0
- package/dist/types/src/schema/normalize.d.ts +5 -0
- package/dist/types/src/schema/report-context.d.ts +2 -2
- package/dist/types/src/schema/types/report.d.ts +4 -8
- package/dist/types/src/schema/types/submit.d.ts +4 -8
- package/dist/types/src/schema/validation.d.ts +1 -0
- package/dist/types/src/transport/types.d.ts +3 -7
- package/package.json +1 -1
- package/dist/schema-CYsf2AFP.js +0 -303
package/dist/schema-CYsf2AFP.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { toJSONSchema as e } from "zod";
|
|
2
|
-
//#region src/schema/ids.ts
|
|
3
|
-
var t = (e) => e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "item", n = (e, t) => {
|
|
4
|
-
if (typeof e == "string" || typeof e == "number") return e;
|
|
5
|
-
if (e) return (t ? e[t] : void 0) ?? e.default ?? void 0;
|
|
6
|
-
}, r = (e) => String(e), i = (e, t) => {
|
|
7
|
-
let i = n(e, t);
|
|
8
|
-
if (t !== void 0 || typeof e != "object" || !e) return i === void 0 ? [] : [i];
|
|
9
|
-
let a = /* @__PURE__ */ new Set();
|
|
10
|
-
return Object.values(e).filter((e) => {
|
|
11
|
-
if (typeof e != "string" && typeof e != "number") return !1;
|
|
12
|
-
let t = r(e);
|
|
13
|
-
return a.has(t) ? !1 : (a.add(t), !0);
|
|
14
|
-
});
|
|
15
|
-
}, a = (e, t) => {
|
|
16
|
-
if (typeof e == "string" || typeof e == "number") return [{
|
|
17
|
-
backend: t ?? "default",
|
|
18
|
-
mappedTo: e
|
|
19
|
-
}];
|
|
20
|
-
if (!e) return [];
|
|
21
|
-
if (t) {
|
|
22
|
-
let r = n(e, t);
|
|
23
|
-
return r === void 0 ? [] : [{
|
|
24
|
-
backend: t,
|
|
25
|
-
mappedTo: r
|
|
26
|
-
}];
|
|
27
|
-
}
|
|
28
|
-
return Object.entries(e).flatMap(([e, t]) => typeof t == "string" || typeof t == "number" ? [{
|
|
29
|
-
backend: e,
|
|
30
|
-
mappedTo: t
|
|
31
|
-
}] : []);
|
|
32
|
-
}, o = (e, t) => {
|
|
33
|
-
let n = a(e.mappedTo, t.backend), i = t.reports.filter((e) => n.some((t) => t.backend === e.backend && r(t.mappedTo) === r(e.mappedTo)));
|
|
34
|
-
if (i.length > 1) {
|
|
35
|
-
let e = i[0];
|
|
36
|
-
throw Error(`Duplicate report result for backend "${e?.backend}" and mappedTo "${String(e?.mappedTo)}".`);
|
|
37
|
-
}
|
|
38
|
-
return i[0];
|
|
39
|
-
}, s = (e, t) => {
|
|
40
|
-
let n = o(e, t);
|
|
41
|
-
return n?.status === "ready" ? n.payload : void 0;
|
|
42
|
-
}, c = class extends Error {
|
|
43
|
-
constructor(e) {
|
|
44
|
-
super(e), this.name = "RegistryError";
|
|
45
|
-
}
|
|
46
|
-
}, l = class {
|
|
47
|
-
fieldDefinitions = /* @__PURE__ */ new Map();
|
|
48
|
-
reportDefinitions = /* @__PURE__ */ new Map();
|
|
49
|
-
registerField(e) {
|
|
50
|
-
if (this.fieldDefinitions.has(e.kind)) throw new c(`Field kind "${e.kind}" is already registered.`);
|
|
51
|
-
return this.fieldDefinitions.set(e.kind, e), this;
|
|
52
|
-
}
|
|
53
|
-
unregisterField(e) {
|
|
54
|
-
return this.fieldDefinitions.delete(e), this;
|
|
55
|
-
}
|
|
56
|
-
registerReport(e) {
|
|
57
|
-
if (this.reportDefinitions.has(e.kind)) throw new c(`Report kind "${e.kind}" is already registered.`);
|
|
58
|
-
return this.reportDefinitions.set(e.kind, e), this;
|
|
59
|
-
}
|
|
60
|
-
unregisterReport(e) {
|
|
61
|
-
return this.reportDefinitions.delete(e), this;
|
|
62
|
-
}
|
|
63
|
-
getField(e) {
|
|
64
|
-
return this.fieldDefinitions.get(e);
|
|
65
|
-
}
|
|
66
|
-
getReport(e) {
|
|
67
|
-
return this.reportDefinitions.get(e);
|
|
68
|
-
}
|
|
69
|
-
listFields() {
|
|
70
|
-
return Array.from(this.fieldDefinitions.values());
|
|
71
|
-
}
|
|
72
|
-
listReports() {
|
|
73
|
-
return Array.from(this.reportDefinitions.values());
|
|
74
|
-
}
|
|
75
|
-
}, u = () => new l(), d = (e) => e, f = (e) => e, p = (e, t, n, r) => {
|
|
76
|
-
if (typeof n != "object" || !n) throw Error(`Series field "${e}" requires "${t}" configuration.`);
|
|
77
|
-
let i = "kind" in n && typeof n.kind == "string" ? n.kind : "";
|
|
78
|
-
if (i.length === 0) throw Error(`Series field "${e}" requires "${t}.kind".`);
|
|
79
|
-
if (i === "series") throw Error(`Series field "${e}" cannot nest series in "${t}".`);
|
|
80
|
-
if (!r.getField(i)) throw new c(`Series field "${e}" uses unknown sub-field kind "${i}" in "${t}".`);
|
|
81
|
-
}, m = (e, t) => {
|
|
82
|
-
if (e.kind === "series" && (p(e.label, "field1", e.field1, t), p(e.label, "field2", e.field2, t), typeof e.minPoints == "number" && typeof e.maxPoints == "number" && e.minPoints > e.maxPoints)) throw Error(`Series field "${e.label}" requires minPoints to be less than or equal to maxPoints.`);
|
|
83
|
-
}, h = (e, n, r, i) => {
|
|
84
|
-
let a = t((e ?? n) || i);
|
|
85
|
-
if (e) {
|
|
86
|
-
if (r.has(a)) throw Error(`Duplicate explicit id "${a}" in schema.`);
|
|
87
|
-
return r.add(a), a;
|
|
88
|
-
}
|
|
89
|
-
let o = a, s = 2;
|
|
90
|
-
for (; r.has(o);) o = `${a}-${s}`, s += 1;
|
|
91
|
-
return r.add(o), o;
|
|
92
|
-
}, g = (e, t, n, r) => {
|
|
93
|
-
let i = n.getField(e.kind);
|
|
94
|
-
if (!i) throw new c(`Unknown field kind "${e.kind}".`);
|
|
95
|
-
let a = i.schema.parse(e);
|
|
96
|
-
return m(a, n), {
|
|
97
|
-
...a,
|
|
98
|
-
id: h(a.id, a.label, r, `field-${t + 1}`)
|
|
99
|
-
};
|
|
100
|
-
}, _ = (e, t, n, r) => {
|
|
101
|
-
let i = n.getReport(e.kind);
|
|
102
|
-
if (!i) throw new c(`Unknown report kind "${e.kind}".`);
|
|
103
|
-
let a = i.schema.parse(e), o = h(e.id ?? a.id, e.label ?? a.label ?? a.kind, r, `report-${t + 1}`);
|
|
104
|
-
return {
|
|
105
|
-
...a,
|
|
106
|
-
...e.label === void 0 ? {} : { label: e.label },
|
|
107
|
-
...e.description === void 0 ? {} : { description: e.description },
|
|
108
|
-
...e.mappedTo === void 0 ? {} : { mappedTo: e.mappedTo },
|
|
109
|
-
...e.ui === void 0 ? {} : { ui: e.ui },
|
|
110
|
-
id: o
|
|
111
|
-
};
|
|
112
|
-
}, v = (e, t) => {
|
|
113
|
-
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (e.reports ?? []).map((e, n) => _(e, n, t, r));
|
|
114
|
-
return {
|
|
115
|
-
fields: e.fields.map((e, r) => g(e, r, t, n)),
|
|
116
|
-
reports: i
|
|
117
|
-
};
|
|
118
|
-
}, y = (e) => e === 1 || e === "1" || e === !0, b = (e, t, i = {}) => {
|
|
119
|
-
if (e.kind !== "onehot-category" || !Array.isArray(e.options)) return;
|
|
120
|
-
let a = /* @__PURE__ */ new Set(), o;
|
|
121
|
-
for (let s of e.options) {
|
|
122
|
-
let c = n(s.mappedTo, i.backend);
|
|
123
|
-
if (c === void 0) throw Error(`onehot-category "${e.id ?? e.kind}": option "${s.value}" has no mappedTo.`);
|
|
124
|
-
let l = r(c);
|
|
125
|
-
if (a.has(l)) throw Error(`onehot-category "${e.id ?? e.kind}": duplicate mappedTo "${l}".`);
|
|
126
|
-
if (a.add(l), y(t[l])) {
|
|
127
|
-
if (o !== void 0) throw Error(`onehot-category "${e.id ?? e.kind}": multiple selected mapped values.`);
|
|
128
|
-
o = s.value;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return o;
|
|
132
|
-
}, x = (e) => {
|
|
133
|
-
if (typeof e == "string") return e;
|
|
134
|
-
if (typeof e != "number") return e.id ?? e.config?.id;
|
|
135
|
-
}, S = (e, t) => {
|
|
136
|
-
if (typeof e == "string" || typeof e == "number") return String(e);
|
|
137
|
-
let i = n(e.mappedTo ?? e.config?.mappedTo, t);
|
|
138
|
-
return i === void 0 ? void 0 : r(i);
|
|
139
|
-
}, C = (e, t) => Object.fromEntries(e.map((e) => {
|
|
140
|
-
let i = o(e, t), a = i?.context, s = i?.mappedTo ?? n(e.mappedTo, t.backend);
|
|
141
|
-
return [e.id, {
|
|
142
|
-
reportId: e.id,
|
|
143
|
-
kind: e.kind,
|
|
144
|
-
label: e.label,
|
|
145
|
-
mappedTo: e.mappedTo,
|
|
146
|
-
target: s,
|
|
147
|
-
targetKey: s === void 0 ? void 0 : r(s),
|
|
148
|
-
backend: i?.backend ?? t.backend,
|
|
149
|
-
displayValues: a?.displayValues ?? t.displayValues ?? {},
|
|
150
|
-
modelValues: a?.modelValues ?? t.modelValues ?? t.serializedValues,
|
|
151
|
-
reports: t.reports,
|
|
152
|
-
meta: a?.meta ?? t.meta,
|
|
153
|
-
raw: a && "raw" in a ? a.raw : t.raw
|
|
154
|
-
}];
|
|
155
|
-
})), w = (e, t) => {
|
|
156
|
-
let n = e.reportContexts ?? {}, r = x(t);
|
|
157
|
-
if (r && n[r]) return n[r];
|
|
158
|
-
let i = S(t, e.backend);
|
|
159
|
-
if (i === void 0) return;
|
|
160
|
-
let a = Object.values(n).filter((t) => t.targetKey === i && (e.backend === void 0 || t.backend === e.backend));
|
|
161
|
-
return a.length === 1 ? a[0] : void 0;
|
|
162
|
-
}, T = (e) => typeof e == "object" && !!e && !Array.isArray(e), E = (e, t) => {
|
|
163
|
-
if (!T(e)) return [];
|
|
164
|
-
let n = [], r = (r) => {
|
|
165
|
-
let i = e[r];
|
|
166
|
-
Array.isArray(i) && i.forEach((e, i) => {
|
|
167
|
-
!T(e) || typeof e.kind != "string" || (r === "fields" ? t.getField(e.kind) : t.getReport(e.kind)) || n.push({
|
|
168
|
-
section: r,
|
|
169
|
-
index: i,
|
|
170
|
-
kind: e.kind,
|
|
171
|
-
path: [
|
|
172
|
-
r,
|
|
173
|
-
i,
|
|
174
|
-
"kind"
|
|
175
|
-
]
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
return r("fields"), r("reports"), n;
|
|
180
|
-
}, D = (e, t, n, r) => {
|
|
181
|
-
if (!Array.isArray(t)) {
|
|
182
|
-
r.push({
|
|
183
|
-
path: [e],
|
|
184
|
-
message: `${e} must be an array.`,
|
|
185
|
-
code: "invalid-schema"
|
|
186
|
-
});
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
t.forEach((t, i) => {
|
|
190
|
-
if (!T(t)) {
|
|
191
|
-
r.push({
|
|
192
|
-
path: [e, i],
|
|
193
|
-
message: `${e === "fields" ? "Field" : "Report"} must be an object.`,
|
|
194
|
-
code: "invalid-config"
|
|
195
|
-
});
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (typeof t.kind != "string" || t.kind.length === 0) {
|
|
199
|
-
r.push({
|
|
200
|
-
path: [
|
|
201
|
-
e,
|
|
202
|
-
i,
|
|
203
|
-
"kind"
|
|
204
|
-
],
|
|
205
|
-
message: "kind must be a non-empty string.",
|
|
206
|
-
code: "invalid-config"
|
|
207
|
-
});
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
let a = e === "fields" ? n.getField(t.kind) : n.getReport(t.kind);
|
|
211
|
-
if (!a) return;
|
|
212
|
-
let o = a.schema.safeParse(t);
|
|
213
|
-
if (!o.success) for (let t of o.error.issues) r.push({
|
|
214
|
-
path: [
|
|
215
|
-
e,
|
|
216
|
-
i,
|
|
217
|
-
...t.path.map((e) => typeof e == "symbol" ? String(e) : e)
|
|
218
|
-
],
|
|
219
|
-
message: t.message,
|
|
220
|
-
code: "invalid-config"
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
}, O = (e, t) => {
|
|
224
|
-
if (!T(e)) return {
|
|
225
|
-
success: !1,
|
|
226
|
-
issues: [{
|
|
227
|
-
path: [],
|
|
228
|
-
message: "Schema must be an object.",
|
|
229
|
-
code: "invalid-schema"
|
|
230
|
-
}]
|
|
231
|
-
};
|
|
232
|
-
let n = [], r = new Set(["fields", "reports"]);
|
|
233
|
-
for (let t of Object.keys(e)) r.has(t) || n.push({
|
|
234
|
-
path: [t],
|
|
235
|
-
message: `Unsupported schema property "${t}".`,
|
|
236
|
-
code: "invalid-schema"
|
|
237
|
-
});
|
|
238
|
-
D("fields", e.fields, t, n), D("reports", e.reports ?? [], t, n);
|
|
239
|
-
for (let r of E(e, t)) n.push({
|
|
240
|
-
path: r.path,
|
|
241
|
-
message: `Unknown ${r.section === "fields" ? "field" : "report"} kind "${r.kind}".`,
|
|
242
|
-
code: "unknown-kind"
|
|
243
|
-
});
|
|
244
|
-
if (n.length > 0) return {
|
|
245
|
-
success: !1,
|
|
246
|
-
issues: n
|
|
247
|
-
};
|
|
248
|
-
try {
|
|
249
|
-
return {
|
|
250
|
-
success: !0,
|
|
251
|
-
data: v(e, t),
|
|
252
|
-
issues: []
|
|
253
|
-
};
|
|
254
|
-
} catch (e) {
|
|
255
|
-
return {
|
|
256
|
-
success: !1,
|
|
257
|
-
issues: [{
|
|
258
|
-
path: [],
|
|
259
|
-
message: e instanceof Error ? e.message : "Schema normalization failed.",
|
|
260
|
-
code: "invalid-schema"
|
|
261
|
-
}]
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
}, k = (t) => t.map((t) => e(t.schema, {
|
|
265
|
-
io: "input",
|
|
266
|
-
unrepresentable: "any"
|
|
267
|
-
})), A = (e) => {
|
|
268
|
-
let t = k(e);
|
|
269
|
-
return t.length > 0 ? { oneOf: t } : !1;
|
|
270
|
-
}, j = (e) => ({
|
|
271
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
272
|
-
type: "object",
|
|
273
|
-
additionalProperties: !1,
|
|
274
|
-
required: ["fields"],
|
|
275
|
-
properties: {
|
|
276
|
-
fields: {
|
|
277
|
-
type: "array",
|
|
278
|
-
items: A(e.listFields())
|
|
279
|
-
},
|
|
280
|
-
reports: {
|
|
281
|
-
type: "array",
|
|
282
|
-
items: A(e.listReports())
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}), M = (e, t = {}) => ({
|
|
286
|
-
reportId: t.reportId ?? "",
|
|
287
|
-
backend: e.backend,
|
|
288
|
-
inputs: e.inputs ?? [],
|
|
289
|
-
displayValues: e.displayValues ?? {},
|
|
290
|
-
modelValues: e.modelValues ?? e.serializedValues,
|
|
291
|
-
values: e.values,
|
|
292
|
-
fieldValues: e.fieldValues,
|
|
293
|
-
serializedValues: e.serializedValues,
|
|
294
|
-
serializedFieldValues: e.serializedFieldValues,
|
|
295
|
-
reports: e.reports,
|
|
296
|
-
reportContext: t.reportId === void 0 ? void 0 : w(e, t.reportId),
|
|
297
|
-
reportContexts: e.reportContexts ?? {},
|
|
298
|
-
meta: e.meta,
|
|
299
|
-
raw: e.raw,
|
|
300
|
-
signal: t.signal
|
|
301
|
-
});
|
|
302
|
-
//#endregion
|
|
303
|
-
export { n as _, C as a, v as c, d, f, i as g, o as h, O as i, c as l, s as m, E as n, w as o, r as p, j as r, b as s, M as t, u, t as v };
|