mlform 0.1.2 → 0.1.3
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 +166 -85
- package/dist/FieldStrategy-CW2h8YyB.js +2427 -0
- package/dist/{ReportStrategy-DY3GC_mJ.js → ReportStrategy-CxPzs4b2.js} +1 -1
- package/dist/{boolean-field-Cd3uhIPj.js → boolean-field-Dwz0ejWl.js} +2 -2
- package/dist/{category-field-D_Ms1x9u.js → category-field-DIgX--Px.js} +2 -2
- package/dist/{classifier-prediction-C5QzorTo.js → classifier-prediction-DgiEREf_.js} +2 -2
- package/dist/{custom-element-ttkHUa8w.js → custom-element-DFxkZ1wU.js} +0 -5
- package/dist/{date-field-Cg_ja679.js → date-field-91U2Xe46.js} +2 -2
- package/dist/{error-card-BwjPChwf.js → error-card-DHdkE18B.js} +2 -2
- package/dist/{field-wrapper-DqIQl76d.js → field-wrapper-CBmpN5T_.js} +3 -3
- package/dist/{ml-layout-Dx63KKf7.js → ml-layout-BJax9HVW.js} +3 -3
- package/dist/mlform/extensions.mjs +4 -4
- package/dist/mlform/strategies.mjs +9 -9
- package/dist/mlform.mjs +210 -202
- package/dist/{number-field-CC2DrVEb.js → number-field-Bcp45dJb.js} +31 -32
- package/dist/{property-jKFNMQpR.js → property-B2UZ3Oii.js} +0 -25
- package/dist/{range-field-Cr7LEtsJ.js → range-field-CD0kkCt0.js} +2 -2
- package/dist/{regressor-prediction-C18dHlfK.js → regressor-prediction-CPzZXlmA.js} +2 -2
- package/dist/src/core/domain/index.d.ts +2 -1
- package/dist/state-Ba1Gr1cr.js +7 -0
- package/dist/test/integration/lifecycle.integration.test.d.ts +1 -0
- package/dist/test/integration/registration.integration.test.d.ts +1 -0
- package/dist/test/integration/state.integration.test.d.ts +1 -0
- package/dist/test/integration/validation.integration.test.d.ts +1 -0
- package/dist/test/unit/Strategies.extensions.test.d.ts +1 -0
- package/dist/test/unit/Strategies.test.d.ts +1 -0
- package/dist/{text-field-DwP-Fa1w.js → text-field-CSBBr4gN.js} +2 -2
- package/package.json +59 -15
- package/dist/FieldStrategy-pPekBtH-.js +0 -2318
- package/dist/state-CLlTRyl1.js +0 -12
package/dist/mlform.mjs
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { F as
|
|
3
|
-
class
|
|
1
|
+
import { $ as R, g as M, c as D, d as z, e as $, u as T, l as I, f as N, s as P, F as k, o as U } from "./FieldStrategy-CW2h8YyB.js";
|
|
2
|
+
import { F as L, M as H } from "./ModelTypes-B9_veCKB.js";
|
|
3
|
+
class x {
|
|
4
4
|
constructor(e) {
|
|
5
|
-
this.counter = 0, this.metadataRegistry = e?.metadata ??
|
|
5
|
+
this.counter = 0, this.metadataRegistry = e?.metadata ?? M, this.target = e?.target ?? "draft-2020-12", this.unrepresentable = e?.unrepresentable ?? "throw", this.override = e?.override ?? (() => {
|
|
6
6
|
}), this.io = e?.io ?? "output", this.seen = /* @__PURE__ */ new Map();
|
|
7
7
|
}
|
|
8
8
|
process(e, r = { path: [], schemaPath: [] }) {
|
|
9
9
|
var o;
|
|
10
|
-
const
|
|
10
|
+
const s = e._zod.def, u = {
|
|
11
11
|
guid: "uuid",
|
|
12
12
|
url: "uri",
|
|
13
13
|
datetime: "date-time",
|
|
14
14
|
json_string: "json-string",
|
|
15
15
|
regex: ""
|
|
16
16
|
// do not set
|
|
17
|
-
},
|
|
18
|
-
if (
|
|
19
|
-
return
|
|
17
|
+
}, g = this.seen.get(e);
|
|
18
|
+
if (g)
|
|
19
|
+
return g.count++, r.schemaPath.includes(e) && (g.cycle = r.path), g.schema;
|
|
20
20
|
const p = { schema: {}, count: 1, cycle: void 0, path: r.path };
|
|
21
21
|
this.seen.set(e, p);
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
p.schema =
|
|
22
|
+
const b = e._zod.toJSONSchema?.();
|
|
23
|
+
if (b)
|
|
24
|
+
p.schema = b;
|
|
25
25
|
else {
|
|
26
26
|
const n = {
|
|
27
27
|
...r,
|
|
28
28
|
schemaPath: [...r.schemaPath, e],
|
|
29
29
|
path: r.path
|
|
30
|
-
},
|
|
31
|
-
if (
|
|
32
|
-
p.ref =
|
|
30
|
+
}, S = e._zod.parent;
|
|
31
|
+
if (S)
|
|
32
|
+
p.ref = S, this.process(S, n), this.seen.get(S).isParent = !0;
|
|
33
33
|
else {
|
|
34
34
|
const c = p.schema;
|
|
35
|
-
switch (
|
|
35
|
+
switch (s.type) {
|
|
36
36
|
case "string": {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const { minimum: i, maximum: a, format: h, patterns: f, contentEncoding:
|
|
40
|
-
if (typeof i == "number" && (
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
...
|
|
44
|
-
...this.target === "draft-7" ? { type: "string" } : {},
|
|
45
|
-
pattern:
|
|
37
|
+
const t = c;
|
|
38
|
+
t.type = "string";
|
|
39
|
+
const { minimum: i, maximum: a, format: h, patterns: f, contentEncoding: d } = e._zod.bag;
|
|
40
|
+
if (typeof i == "number" && (t.minLength = i), typeof a == "number" && (t.maxLength = a), h && (t.format = u[h] ?? h, t.format === "" && delete t.format), d && (t.contentEncoding = d), f && f.size > 0) {
|
|
41
|
+
const w = [...f];
|
|
42
|
+
w.length === 1 ? t.pattern = w[0].source : w.length > 1 && (p.schema.allOf = [
|
|
43
|
+
...w.map((O) => ({
|
|
44
|
+
...this.target === "draft-7" || this.target === "draft-4" || this.target === "openapi-3.0" ? { type: "string" } : {},
|
|
45
|
+
pattern: O.source
|
|
46
46
|
}))
|
|
47
47
|
]);
|
|
48
48
|
}
|
|
49
49
|
break;
|
|
50
50
|
}
|
|
51
51
|
case "number": {
|
|
52
|
-
const
|
|
53
|
-
typeof h == "string" && h.includes("int") ?
|
|
52
|
+
const t = c, { minimum: i, maximum: a, format: h, multipleOf: f, exclusiveMaximum: d, exclusiveMinimum: w } = e._zod.bag;
|
|
53
|
+
typeof h == "string" && h.includes("int") ? t.type = "integer" : t.type = "number", typeof w == "number" && (this.target === "draft-4" || this.target === "openapi-3.0" ? (t.minimum = w, t.exclusiveMinimum = !0) : t.exclusiveMinimum = w), typeof i == "number" && (t.minimum = i, typeof w == "number" && this.target !== "draft-4" && (w >= i ? delete t.minimum : delete t.exclusiveMinimum)), typeof d == "number" && (this.target === "draft-4" || this.target === "openapi-3.0" ? (t.maximum = d, t.exclusiveMaximum = !0) : t.exclusiveMaximum = d), typeof a == "number" && (t.maximum = a, typeof d == "number" && this.target !== "draft-4" && (d <= a ? delete t.maximum : delete t.exclusiveMaximum)), typeof f == "number" && (t.multipleOf = f);
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
56
|
case "boolean": {
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const t = c;
|
|
58
|
+
t.type = "boolean";
|
|
59
59
|
break;
|
|
60
60
|
}
|
|
61
61
|
case "bigint": {
|
|
@@ -69,7 +69,7 @@ class T {
|
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
case "null": {
|
|
72
|
-
c.type = "null";
|
|
72
|
+
this.target === "openapi-3.0" ? (c.type = "string", c.nullable = !0, c.enum = [null]) : c.type = "null";
|
|
73
73
|
break;
|
|
74
74
|
}
|
|
75
75
|
case "any":
|
|
@@ -96,73 +96,74 @@ class T {
|
|
|
96
96
|
break;
|
|
97
97
|
}
|
|
98
98
|
case "array": {
|
|
99
|
-
const
|
|
100
|
-
typeof i == "number" && (
|
|
99
|
+
const t = c, { minimum: i, maximum: a } = e._zod.bag;
|
|
100
|
+
typeof i == "number" && (t.minItems = i), typeof a == "number" && (t.maxItems = a), t.type = "array", t.items = this.process(s.element, { ...n, path: [...n.path, "items"] });
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
103
103
|
case "object": {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const i =
|
|
104
|
+
const t = c;
|
|
105
|
+
t.type = "object", t.properties = {};
|
|
106
|
+
const i = s.shape;
|
|
107
107
|
for (const f in i)
|
|
108
|
-
|
|
108
|
+
t.properties[f] = this.process(i[f], {
|
|
109
109
|
...n,
|
|
110
110
|
path: [...n.path, "properties", f]
|
|
111
111
|
});
|
|
112
112
|
const a = new Set(Object.keys(i)), h = new Set([...a].filter((f) => {
|
|
113
|
-
const
|
|
114
|
-
return this.io === "input" ?
|
|
113
|
+
const d = s.shape[f]._zod;
|
|
114
|
+
return this.io === "input" ? d.optin === void 0 : d.optout === void 0;
|
|
115
115
|
}));
|
|
116
|
-
h.size > 0 && (
|
|
116
|
+
h.size > 0 && (t.required = Array.from(h)), s.catchall?._zod.def.type === "never" ? t.additionalProperties = !1 : s.catchall ? s.catchall && (t.additionalProperties = this.process(s.catchall, {
|
|
117
117
|
...n,
|
|
118
118
|
path: [...n.path, "additionalProperties"]
|
|
119
|
-
})) : this.io === "output" && (
|
|
119
|
+
})) : this.io === "output" && (t.additionalProperties = !1);
|
|
120
120
|
break;
|
|
121
121
|
}
|
|
122
122
|
case "union": {
|
|
123
|
-
const
|
|
124
|
-
s.anyOf = t.options.map((i, a) => this.process(i, {
|
|
123
|
+
const t = c, i = s.options.map((a, h) => this.process(a, {
|
|
125
124
|
...n,
|
|
126
|
-
path: [...n.path, "anyOf",
|
|
125
|
+
path: [...n.path, "anyOf", h]
|
|
127
126
|
}));
|
|
127
|
+
t.anyOf = i;
|
|
128
128
|
break;
|
|
129
129
|
}
|
|
130
130
|
case "intersection": {
|
|
131
|
-
const
|
|
131
|
+
const t = c, i = this.process(s.left, {
|
|
132
132
|
...n,
|
|
133
133
|
path: [...n.path, "allOf", 0]
|
|
134
|
-
}), a = this.process(
|
|
134
|
+
}), a = this.process(s.right, {
|
|
135
135
|
...n,
|
|
136
136
|
path: [...n.path, "allOf", 1]
|
|
137
|
-
}), h = (
|
|
137
|
+
}), h = (d) => "allOf" in d && Object.keys(d).length === 1, f = [
|
|
138
138
|
...h(i) ? i.allOf : [i],
|
|
139
139
|
...h(a) ? a.allOf : [a]
|
|
140
140
|
];
|
|
141
|
-
|
|
141
|
+
t.allOf = f;
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
144
|
case "tuple": {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const i =
|
|
148
|
-
if (this.target === "draft-2020-12" ? s.prefixItems = i : s.items = i, t.rest) {
|
|
149
|
-
const f = this.process(t.rest, {
|
|
150
|
-
...n,
|
|
151
|
-
path: [...n.path, "items"]
|
|
152
|
-
});
|
|
153
|
-
this.target === "draft-2020-12" ? s.items = f : s.additionalItems = f;
|
|
154
|
-
}
|
|
155
|
-
t.rest && (s.items = this.process(t.rest, {
|
|
145
|
+
const t = c;
|
|
146
|
+
t.type = "array";
|
|
147
|
+
const i = this.target === "draft-2020-12" ? "prefixItems" : "items", a = this.target === "draft-2020-12" || this.target === "openapi-3.0" ? "items" : "additionalItems", h = s.items.map((O, J) => this.process(O, {
|
|
156
148
|
...n,
|
|
157
|
-
path: [...n.path,
|
|
158
|
-
}))
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
path: [...n.path, i, J]
|
|
150
|
+
})), f = s.rest ? this.process(s.rest, {
|
|
151
|
+
...n,
|
|
152
|
+
path: [...n.path, a, ...this.target === "openapi-3.0" ? [s.items.length] : []]
|
|
153
|
+
}) : null;
|
|
154
|
+
this.target === "draft-2020-12" ? (t.prefixItems = h, f && (t.items = f)) : this.target === "openapi-3.0" ? (t.items = {
|
|
155
|
+
anyOf: h
|
|
156
|
+
}, f && t.items.anyOf.push(f), t.minItems = h.length, f || (t.maxItems = h.length)) : (t.items = h, f && (t.additionalItems = f));
|
|
157
|
+
const { minimum: d, maximum: w } = e._zod.bag;
|
|
158
|
+
typeof d == "number" && (t.minItems = d), typeof w == "number" && (t.maxItems = w);
|
|
161
159
|
break;
|
|
162
160
|
}
|
|
163
161
|
case "record": {
|
|
164
|
-
const
|
|
165
|
-
|
|
162
|
+
const t = c;
|
|
163
|
+
t.type = "object", (this.target === "draft-7" || this.target === "draft-2020-12") && (t.propertyNames = this.process(s.keyType, {
|
|
164
|
+
...n,
|
|
165
|
+
path: [...n.path, "propertyNames"]
|
|
166
|
+
})), t.additionalProperties = this.process(s.valueType, {
|
|
166
167
|
...n,
|
|
167
168
|
path: [...n.path, "additionalProperties"]
|
|
168
169
|
});
|
|
@@ -179,13 +180,13 @@ class T {
|
|
|
179
180
|
break;
|
|
180
181
|
}
|
|
181
182
|
case "enum": {
|
|
182
|
-
const
|
|
183
|
-
i.every((a) => typeof a == "number") && (
|
|
183
|
+
const t = c, i = D(s.entries);
|
|
184
|
+
i.every((a) => typeof a == "number") && (t.type = "number"), i.every((a) => typeof a == "string") && (t.type = "string"), t.enum = i;
|
|
184
185
|
break;
|
|
185
186
|
}
|
|
186
187
|
case "literal": {
|
|
187
|
-
const
|
|
188
|
-
for (const a of
|
|
188
|
+
const t = c, i = [];
|
|
189
|
+
for (const a of s.values)
|
|
189
190
|
if (a === void 0) {
|
|
190
191
|
if (this.unrepresentable === "throw")
|
|
191
192
|
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
@@ -197,18 +198,18 @@ class T {
|
|
|
197
198
|
i.push(a);
|
|
198
199
|
if (i.length !== 0) if (i.length === 1) {
|
|
199
200
|
const a = i[0];
|
|
200
|
-
|
|
201
|
+
t.type = a === null ? "null" : typeof a, this.target === "draft-4" || this.target === "openapi-3.0" ? t.enum = [a] : t.const = a;
|
|
201
202
|
} else
|
|
202
|
-
i.every((a) => typeof a == "number") && (
|
|
203
|
+
i.every((a) => typeof a == "number") && (t.type = "number"), i.every((a) => typeof a == "string") && (t.type = "string"), i.every((a) => typeof a == "boolean") && (t.type = "string"), i.every((a) => a === null) && (t.type = "null"), t.enum = i;
|
|
203
204
|
break;
|
|
204
205
|
}
|
|
205
206
|
case "file": {
|
|
206
|
-
const
|
|
207
|
+
const t = c, i = {
|
|
207
208
|
type: "string",
|
|
208
209
|
format: "binary",
|
|
209
210
|
contentEncoding: "binary"
|
|
210
211
|
}, { minimum: a, maximum: h, mime: f } = e._zod.bag;
|
|
211
|
-
a !== void 0 && (i.minLength = a), h !== void 0 && (i.maxLength = h), f ? f.length === 1 ? (i.contentMediaType = f[0], Object.assign(
|
|
212
|
+
a !== void 0 && (i.minLength = a), h !== void 0 && (i.maxLength = h), f ? f.length === 1 ? (i.contentMediaType = f[0], Object.assign(t, i)) : t.anyOf = f.map((d) => ({ ...i, contentMediaType: d })) : Object.assign(t, i);
|
|
212
213
|
break;
|
|
213
214
|
}
|
|
214
215
|
case "transform": {
|
|
@@ -217,36 +218,36 @@ class T {
|
|
|
217
218
|
break;
|
|
218
219
|
}
|
|
219
220
|
case "nullable": {
|
|
220
|
-
const
|
|
221
|
-
c.anyOf = [
|
|
221
|
+
const t = this.process(s.innerType, n);
|
|
222
|
+
this.target === "openapi-3.0" ? (p.ref = s.innerType, c.nullable = !0) : c.anyOf = [t, { type: "null" }];
|
|
222
223
|
break;
|
|
223
224
|
}
|
|
224
225
|
case "nonoptional": {
|
|
225
|
-
this.process(
|
|
226
|
+
this.process(s.innerType, n), p.ref = s.innerType;
|
|
226
227
|
break;
|
|
227
228
|
}
|
|
228
229
|
case "success": {
|
|
229
|
-
const
|
|
230
|
-
|
|
230
|
+
const t = c;
|
|
231
|
+
t.type = "boolean";
|
|
231
232
|
break;
|
|
232
233
|
}
|
|
233
234
|
case "default": {
|
|
234
|
-
this.process(
|
|
235
|
+
this.process(s.innerType, n), p.ref = s.innerType, c.default = JSON.parse(JSON.stringify(s.defaultValue));
|
|
235
236
|
break;
|
|
236
237
|
}
|
|
237
238
|
case "prefault": {
|
|
238
|
-
this.process(
|
|
239
|
+
this.process(s.innerType, n), p.ref = s.innerType, this.io === "input" && (c._prefault = JSON.parse(JSON.stringify(s.defaultValue)));
|
|
239
240
|
break;
|
|
240
241
|
}
|
|
241
242
|
case "catch": {
|
|
242
|
-
this.process(
|
|
243
|
-
let
|
|
243
|
+
this.process(s.innerType, n), p.ref = s.innerType;
|
|
244
|
+
let t;
|
|
244
245
|
try {
|
|
245
|
-
|
|
246
|
+
t = s.catchValue(void 0);
|
|
246
247
|
} catch {
|
|
247
248
|
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
248
249
|
}
|
|
249
|
-
c.default =
|
|
250
|
+
c.default = t;
|
|
250
251
|
break;
|
|
251
252
|
}
|
|
252
253
|
case "nan": {
|
|
@@ -255,33 +256,33 @@ class T {
|
|
|
255
256
|
break;
|
|
256
257
|
}
|
|
257
258
|
case "template_literal": {
|
|
258
|
-
const
|
|
259
|
+
const t = c, i = e._zod.pattern;
|
|
259
260
|
if (!i)
|
|
260
261
|
throw new Error("Pattern not found in template literal");
|
|
261
|
-
|
|
262
|
+
t.type = "string", t.pattern = i.source;
|
|
262
263
|
break;
|
|
263
264
|
}
|
|
264
265
|
case "pipe": {
|
|
265
|
-
const
|
|
266
|
-
this.process(
|
|
266
|
+
const t = this.io === "input" ? s.in._zod.def.type === "transform" ? s.out : s.in : s.out;
|
|
267
|
+
this.process(t, n), p.ref = t;
|
|
267
268
|
break;
|
|
268
269
|
}
|
|
269
270
|
case "readonly": {
|
|
270
|
-
this.process(
|
|
271
|
+
this.process(s.innerType, n), p.ref = s.innerType, c.readOnly = !0;
|
|
271
272
|
break;
|
|
272
273
|
}
|
|
273
274
|
// passthrough types
|
|
274
275
|
case "promise": {
|
|
275
|
-
this.process(
|
|
276
|
+
this.process(s.innerType, n), p.ref = s.innerType;
|
|
276
277
|
break;
|
|
277
278
|
}
|
|
278
279
|
case "optional": {
|
|
279
|
-
this.process(
|
|
280
|
+
this.process(s.innerType, n), p.ref = s.innerType;
|
|
280
281
|
break;
|
|
281
282
|
}
|
|
282
283
|
case "lazy": {
|
|
283
|
-
const
|
|
284
|
-
this.process(
|
|
284
|
+
const t = e._zod.innerType;
|
|
285
|
+
this.process(t, n), p.ref = t;
|
|
285
286
|
break;
|
|
286
287
|
}
|
|
287
288
|
case "custom": {
|
|
@@ -289,11 +290,16 @@ class T {
|
|
|
289
290
|
throw new Error("Custom types cannot be represented in JSON Schema");
|
|
290
291
|
break;
|
|
291
292
|
}
|
|
293
|
+
case "function": {
|
|
294
|
+
if (this.unrepresentable === "throw")
|
|
295
|
+
throw new Error("Function types cannot be represented in JSON Schema");
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
292
298
|
}
|
|
293
299
|
}
|
|
294
300
|
}
|
|
295
|
-
const
|
|
296
|
-
return
|
|
301
|
+
const v = this.metadataRegistry.get(e);
|
|
302
|
+
return v && Object.assign(p.schema, v), this.io === "input" && m(e) && (delete p.schema.examples, delete p.schema.default), this.io === "input" && p.schema._prefault && ((o = p.schema).default ?? (o.default = p.schema._prefault)), delete p.schema._prefault, this.seen.get(e).schema;
|
|
297
303
|
}
|
|
298
304
|
emit(e, r) {
|
|
299
305
|
const o = {
|
|
@@ -302,8 +308,8 @@ class T {
|
|
|
302
308
|
// unrepresentable: _params?.unrepresentable ?? "throw",
|
|
303
309
|
// uri: _params?.uri ?? ((id) => `${id}`),
|
|
304
310
|
external: r?.external ?? void 0
|
|
305
|
-
},
|
|
306
|
-
if (!
|
|
311
|
+
}, s = this.seen.get(e);
|
|
312
|
+
if (!s)
|
|
307
313
|
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
308
314
|
const u = (l) => {
|
|
309
315
|
const n = this.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
@@ -314,19 +320,19 @@ class T {
|
|
|
314
320
|
const h = l[1].defId ?? l[1].schema.id ?? `schema${this.counter++}`;
|
|
315
321
|
return l[1].defId = h, { defId: h, ref: `${a("__shared")}#/${n}/${h}` };
|
|
316
322
|
}
|
|
317
|
-
if (l[1] ===
|
|
323
|
+
if (l[1] === s)
|
|
318
324
|
return { ref: "#" };
|
|
319
|
-
const c = `#/${n}/`,
|
|
320
|
-
return { defId:
|
|
321
|
-
},
|
|
325
|
+
const c = `#/${n}/`, t = l[1].schema.id ?? `__schema${this.counter++}`;
|
|
326
|
+
return { defId: t, ref: c + t };
|
|
327
|
+
}, g = (l) => {
|
|
322
328
|
if (l[1].schema.$ref)
|
|
323
329
|
return;
|
|
324
|
-
const n = l[1], { ref:
|
|
330
|
+
const n = l[1], { ref: S, defId: c } = u(l);
|
|
325
331
|
n.def = { ...n.schema }, c && (n.defId = c);
|
|
326
|
-
const
|
|
327
|
-
for (const i in
|
|
328
|
-
delete
|
|
329
|
-
|
|
332
|
+
const t = n.schema;
|
|
333
|
+
for (const i in t)
|
|
334
|
+
delete t[i];
|
|
335
|
+
t.$ref = S;
|
|
330
336
|
};
|
|
331
337
|
if (o.cycles === "throw")
|
|
332
338
|
for (const l of this.seen.entries()) {
|
|
@@ -339,105 +345,105 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
339
345
|
for (const l of this.seen.entries()) {
|
|
340
346
|
const n = l[1];
|
|
341
347
|
if (e === l[0]) {
|
|
342
|
-
|
|
348
|
+
g(l);
|
|
343
349
|
continue;
|
|
344
350
|
}
|
|
345
351
|
if (o.external) {
|
|
346
352
|
const c = o.external.registry.get(l[0])?.id;
|
|
347
353
|
if (e !== l[0] && c) {
|
|
348
|
-
|
|
354
|
+
g(l);
|
|
349
355
|
continue;
|
|
350
356
|
}
|
|
351
357
|
}
|
|
352
358
|
if (this.metadataRegistry.get(l[0])?.id) {
|
|
353
|
-
|
|
359
|
+
g(l);
|
|
354
360
|
continue;
|
|
355
361
|
}
|
|
356
362
|
if (n.cycle) {
|
|
357
|
-
|
|
363
|
+
g(l);
|
|
358
364
|
continue;
|
|
359
365
|
}
|
|
360
366
|
if (n.count > 1 && o.reused === "ref") {
|
|
361
|
-
|
|
367
|
+
g(l);
|
|
362
368
|
continue;
|
|
363
369
|
}
|
|
364
370
|
}
|
|
365
371
|
const p = (l, n) => {
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
372
|
+
const S = this.seen.get(l), c = S.def ?? S.schema, t = { ...c };
|
|
373
|
+
if (S.ref === null)
|
|
368
374
|
return;
|
|
369
|
-
const i =
|
|
370
|
-
if (
|
|
375
|
+
const i = S.ref;
|
|
376
|
+
if (S.ref = null, i) {
|
|
371
377
|
p(i, n);
|
|
372
378
|
const a = this.seen.get(i).schema;
|
|
373
|
-
a.$ref && n.target === "draft-7" ? (c.allOf = c.allOf ?? [], c.allOf.push(a)) : (Object.assign(c, a), Object.assign(c,
|
|
379
|
+
a.$ref && (n.target === "draft-7" || n.target === "draft-4" || n.target === "openapi-3.0") ? (c.allOf = c.allOf ?? [], c.allOf.push(a)) : (Object.assign(c, a), Object.assign(c, t));
|
|
374
380
|
}
|
|
375
|
-
|
|
381
|
+
S.isParent || this.override({
|
|
376
382
|
zodSchema: l,
|
|
377
383
|
jsonSchema: c,
|
|
378
|
-
path:
|
|
384
|
+
path: S.path ?? []
|
|
379
385
|
});
|
|
380
386
|
};
|
|
381
387
|
for (const l of [...this.seen.entries()].reverse())
|
|
382
388
|
p(l[0], { target: this.target });
|
|
383
|
-
const
|
|
384
|
-
if (this.target === "draft-2020-12" ?
|
|
389
|
+
const b = {};
|
|
390
|
+
if (this.target === "draft-2020-12" ? b.$schema = "https://json-schema.org/draft/2020-12/schema" : this.target === "draft-7" ? b.$schema = "http://json-schema.org/draft-07/schema#" : this.target === "draft-4" ? b.$schema = "http://json-schema.org/draft-04/schema#" : this.target === "openapi-3.0" || console.warn(`Invalid target: ${this.target}`), o.external?.uri) {
|
|
385
391
|
const l = o.external.registry.get(e)?.id;
|
|
386
392
|
if (!l)
|
|
387
393
|
throw new Error("Schema is missing an `id` property");
|
|
388
|
-
|
|
394
|
+
b.$id = o.external.uri(l);
|
|
389
395
|
}
|
|
390
|
-
Object.assign(
|
|
391
|
-
const
|
|
396
|
+
Object.assign(b, s.def);
|
|
397
|
+
const v = o.external?.defs ?? {};
|
|
392
398
|
for (const l of this.seen.entries()) {
|
|
393
399
|
const n = l[1];
|
|
394
|
-
n.def && n.defId && (
|
|
400
|
+
n.def && n.defId && (v[n.defId] = n.def);
|
|
395
401
|
}
|
|
396
|
-
o.external || Object.keys(
|
|
402
|
+
o.external || Object.keys(v).length > 0 && (this.target === "draft-2020-12" ? b.$defs = v : b.definitions = v);
|
|
397
403
|
try {
|
|
398
|
-
return JSON.parse(JSON.stringify(
|
|
404
|
+
return JSON.parse(JSON.stringify(b));
|
|
399
405
|
} catch {
|
|
400
406
|
throw new Error("Error converting schema to JSON.");
|
|
401
407
|
}
|
|
402
408
|
}
|
|
403
409
|
}
|
|
404
|
-
function
|
|
405
|
-
if (
|
|
406
|
-
const o = new
|
|
407
|
-
for (const p of
|
|
408
|
-
const [
|
|
409
|
-
o.process(
|
|
410
|
+
function C(y, e) {
|
|
411
|
+
if (y instanceof R) {
|
|
412
|
+
const o = new x(e), s = {};
|
|
413
|
+
for (const p of y._idmap.entries()) {
|
|
414
|
+
const [b, v] = p;
|
|
415
|
+
o.process(v);
|
|
410
416
|
}
|
|
411
|
-
const u = {},
|
|
412
|
-
registry:
|
|
417
|
+
const u = {}, g = {
|
|
418
|
+
registry: y,
|
|
413
419
|
uri: e?.uri,
|
|
414
|
-
defs:
|
|
420
|
+
defs: s
|
|
415
421
|
};
|
|
416
|
-
for (const p of
|
|
417
|
-
const [
|
|
418
|
-
u[
|
|
422
|
+
for (const p of y._idmap.entries()) {
|
|
423
|
+
const [b, v] = p;
|
|
424
|
+
u[b] = o.emit(v, {
|
|
419
425
|
...e,
|
|
420
|
-
external:
|
|
426
|
+
external: g
|
|
421
427
|
});
|
|
422
428
|
}
|
|
423
|
-
if (Object.keys(
|
|
429
|
+
if (Object.keys(s).length > 0) {
|
|
424
430
|
const p = o.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
425
431
|
u.__shared = {
|
|
426
|
-
[p]:
|
|
432
|
+
[p]: s
|
|
427
433
|
};
|
|
428
434
|
}
|
|
429
435
|
return { schemas: u };
|
|
430
436
|
}
|
|
431
|
-
const r = new
|
|
432
|
-
return r.process(
|
|
437
|
+
const r = new x(e);
|
|
438
|
+
return r.process(y), r.emit(y, e);
|
|
433
439
|
}
|
|
434
|
-
function
|
|
440
|
+
function m(y, e) {
|
|
435
441
|
const r = e ?? { seen: /* @__PURE__ */ new Set() };
|
|
436
|
-
if (r.seen.has(
|
|
442
|
+
if (r.seen.has(y))
|
|
437
443
|
return !1;
|
|
438
|
-
r.seen.add(
|
|
439
|
-
const
|
|
440
|
-
switch (
|
|
444
|
+
r.seen.add(y);
|
|
445
|
+
const s = y._zod.def;
|
|
446
|
+
switch (s.type) {
|
|
441
447
|
case "string":
|
|
442
448
|
case "number":
|
|
443
449
|
case "bigint":
|
|
@@ -457,77 +463,79 @@ function d(m, e) {
|
|
|
457
463
|
case "template_literal":
|
|
458
464
|
return !1;
|
|
459
465
|
case "array":
|
|
460
|
-
return
|
|
466
|
+
return m(s.element, r);
|
|
461
467
|
case "object": {
|
|
462
|
-
for (const u in
|
|
463
|
-
if (
|
|
468
|
+
for (const u in s.shape)
|
|
469
|
+
if (m(s.shape[u], r))
|
|
464
470
|
return !0;
|
|
465
471
|
return !1;
|
|
466
472
|
}
|
|
467
473
|
case "union": {
|
|
468
|
-
for (const u of
|
|
469
|
-
if (
|
|
474
|
+
for (const u of s.options)
|
|
475
|
+
if (m(u, r))
|
|
470
476
|
return !0;
|
|
471
477
|
return !1;
|
|
472
478
|
}
|
|
473
479
|
case "intersection":
|
|
474
|
-
return
|
|
480
|
+
return m(s.left, r) || m(s.right, r);
|
|
475
481
|
case "tuple": {
|
|
476
|
-
for (const u of
|
|
477
|
-
if (
|
|
482
|
+
for (const u of s.items)
|
|
483
|
+
if (m(u, r))
|
|
478
484
|
return !0;
|
|
479
|
-
return !!(
|
|
485
|
+
return !!(s.rest && m(s.rest, r));
|
|
480
486
|
}
|
|
481
487
|
case "record":
|
|
482
|
-
return
|
|
488
|
+
return m(s.keyType, r) || m(s.valueType, r);
|
|
483
489
|
case "map":
|
|
484
|
-
return
|
|
490
|
+
return m(s.keyType, r) || m(s.valueType, r);
|
|
485
491
|
case "set":
|
|
486
|
-
return
|
|
492
|
+
return m(s.valueType, r);
|
|
487
493
|
// inner types
|
|
488
494
|
case "promise":
|
|
489
495
|
case "optional":
|
|
490
496
|
case "nonoptional":
|
|
491
497
|
case "nullable":
|
|
492
498
|
case "readonly":
|
|
493
|
-
return
|
|
499
|
+
return m(s.innerType, r);
|
|
494
500
|
case "lazy":
|
|
495
|
-
return
|
|
501
|
+
return m(s.getter(), r);
|
|
496
502
|
case "default":
|
|
497
|
-
return
|
|
503
|
+
return m(s.innerType, r);
|
|
498
504
|
case "prefault":
|
|
499
|
-
return
|
|
505
|
+
return m(s.innerType, r);
|
|
500
506
|
case "custom":
|
|
501
507
|
return !1;
|
|
502
508
|
case "transform":
|
|
503
509
|
return !0;
|
|
504
510
|
case "pipe":
|
|
505
|
-
return
|
|
511
|
+
return m(s.in, r) || m(s.out, r);
|
|
506
512
|
case "success":
|
|
507
513
|
return !1;
|
|
508
514
|
case "catch":
|
|
509
515
|
return !1;
|
|
516
|
+
case "function":
|
|
517
|
+
return !1;
|
|
510
518
|
}
|
|
511
|
-
throw new Error(`Unknown schema type: ${
|
|
519
|
+
throw new Error(`Unknown schema type: ${s.type}`);
|
|
512
520
|
}
|
|
513
|
-
const
|
|
521
|
+
const F = $, A = T, V = z, _ = $(
|
|
514
522
|
I({
|
|
515
|
-
type:
|
|
523
|
+
type: T(Object.values(L).map((y) => N(y)))
|
|
516
524
|
})
|
|
517
525
|
);
|
|
518
526
|
I({
|
|
519
|
-
type:
|
|
527
|
+
type: T(Object.values(H).map((y) => N(y)))
|
|
520
528
|
});
|
|
521
|
-
|
|
529
|
+
P({
|
|
522
530
|
inputs: _,
|
|
523
531
|
outputs: _
|
|
524
532
|
});
|
|
525
|
-
const
|
|
526
|
-
class
|
|
533
|
+
const Y = "[Registry] The type «{type}» already exists.", E = "[Registry] The type «{type}» does not exist.";
|
|
534
|
+
class q {
|
|
527
535
|
catalog = /* @__PURE__ */ new Map();
|
|
528
|
-
combinedSchema =
|
|
536
|
+
combinedSchema = V();
|
|
529
537
|
get schema() {
|
|
530
|
-
return
|
|
538
|
+
return F(this.combinedSchema);
|
|
531
539
|
}
|
|
532
540
|
get(e) {
|
|
533
541
|
return this.catalog.get(e);
|
|
@@ -537,7 +545,7 @@ class F {
|
|
|
537
545
|
}
|
|
538
546
|
register(e) {
|
|
539
547
|
if (this.catalog.has(e.type))
|
|
540
|
-
throw new Error(
|
|
548
|
+
throw new Error(Y.replace("{type}", e.type));
|
|
541
549
|
this.catalog.set(e.type, e), this.rebuildSchema();
|
|
542
550
|
}
|
|
543
551
|
unregister(e) {
|
|
@@ -552,12 +560,12 @@ class F {
|
|
|
552
560
|
}
|
|
553
561
|
rebuildSchema() {
|
|
554
562
|
const e = Array.from(this.catalog.values()).map((r) => r.schema);
|
|
555
|
-
this.combinedSchema =
|
|
563
|
+
this.combinedSchema = A(e);
|
|
556
564
|
}
|
|
557
565
|
}
|
|
558
|
-
const
|
|
566
|
+
const B = "[DescriptorService] Unsupported <<type>>";
|
|
559
567
|
class j {
|
|
560
|
-
registry = new
|
|
568
|
+
registry = new q();
|
|
561
569
|
loadedTypes = /* @__PURE__ */ new Set();
|
|
562
570
|
temporalOutputs = null;
|
|
563
571
|
constructor(e = "") {
|
|
@@ -576,15 +584,15 @@ class j {
|
|
|
576
584
|
}
|
|
577
585
|
async ensureComponents(e) {
|
|
578
586
|
const r = [
|
|
579
|
-
import("./error-card-
|
|
580
|
-
import("./ml-layout-
|
|
581
|
-
import("./field-wrapper-
|
|
587
|
+
import("./error-card-DHdkE18B.js"),
|
|
588
|
+
import("./ml-layout-BJax9HVW.js"),
|
|
589
|
+
import("./field-wrapper-CBmpN5T_.js")
|
|
582
590
|
];
|
|
583
591
|
for (const o of e) {
|
|
584
|
-
const
|
|
592
|
+
const s = o.type, u = this.reg.get(s);
|
|
585
593
|
if (!u)
|
|
586
|
-
throw new Error(
|
|
587
|
-
this.loadedTypes.has(
|
|
594
|
+
throw new Error(B.replace("type", s));
|
|
595
|
+
this.loadedTypes.has(s) || (this.loadedTypes.add(s), r.push(u.loader()));
|
|
588
596
|
}
|
|
589
597
|
await Promise.all(r);
|
|
590
598
|
}
|
|
@@ -592,9 +600,9 @@ class j {
|
|
|
592
600
|
this.reg.schema.parse(e);
|
|
593
601
|
const r = [];
|
|
594
602
|
for (const o of e) {
|
|
595
|
-
const
|
|
603
|
+
const s = o.type, u = this.reg.get(s), g = u.parse(o);
|
|
596
604
|
r.push(
|
|
597
|
-
u.buildDescriptor(
|
|
605
|
+
u.buildDescriptor(g)
|
|
598
606
|
);
|
|
599
607
|
}
|
|
600
608
|
return r;
|
|
@@ -612,8 +620,8 @@ class j {
|
|
|
612
620
|
async render(e) {
|
|
613
621
|
const r = this.reg.schema.parse(e);
|
|
614
622
|
await this.ensureComponents(r);
|
|
615
|
-
const o = this.renderDescriptors(r),
|
|
616
|
-
|
|
623
|
+
const o = this.renderDescriptors(r), s = document.querySelector('div[slot="report"]');
|
|
624
|
+
s && (s.innerHTML = this.reportDescriptorsToInnerHtml(o));
|
|
617
625
|
}
|
|
618
626
|
async submit(e) {
|
|
619
627
|
let r;
|
|
@@ -628,9 +636,9 @@ class j {
|
|
|
628
636
|
});
|
|
629
637
|
if (!o.ok) throw new Error(await o.text());
|
|
630
638
|
r = await o.json();
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
const u = this.reg.schema.parse(
|
|
639
|
+
const s = this.reg.schema.parse(this.temporalOutputs);
|
|
640
|
+
s[0].execution_time = r.outputs[0].execution_time, s[0].type === "regressor" ? s[0].values = r.outputs[0].values : s[0].type === "classifier" && (s[0].probabilities = r.outputs[0].probabilities);
|
|
641
|
+
const u = this.reg.schema.parse(s);
|
|
634
642
|
this.render(u), r = u;
|
|
635
643
|
} catch (o) {
|
|
636
644
|
throw new Error(
|
|
@@ -650,7 +658,7 @@ class j {
|
|
|
650
658
|
).join(" ");
|
|
651
659
|
}
|
|
652
660
|
}
|
|
653
|
-
class
|
|
661
|
+
class X {
|
|
654
662
|
backendUrl;
|
|
655
663
|
fieldService;
|
|
656
664
|
modelService;
|
|
@@ -661,13 +669,13 @@ class B {
|
|
|
661
669
|
this.backendUrl = e, this.fieldService = new j(), this.modelService = new j(this.backendUrl);
|
|
662
670
|
}
|
|
663
671
|
register(e) {
|
|
664
|
-
e instanceof
|
|
672
|
+
e instanceof k ? this.fieldService.reg.register(e) : this.modelService.reg.register(e);
|
|
665
673
|
}
|
|
666
674
|
update(e) {
|
|
667
|
-
e instanceof
|
|
675
|
+
e instanceof k ? this.fieldService.reg.update(e) : this.modelService.reg.update(e);
|
|
668
676
|
}
|
|
669
677
|
unregister(e) {
|
|
670
|
-
e instanceof
|
|
678
|
+
e instanceof k ? this.fieldService.reg.unregister(e.type) : this.modelService.reg.unregister(e.type);
|
|
671
679
|
}
|
|
672
680
|
/** Lectura sincrónica del último envío */
|
|
673
681
|
get lastInputs() {
|
|
@@ -683,11 +691,11 @@ class B {
|
|
|
683
691
|
async toHTMLElement(e, r) {
|
|
684
692
|
const o = this.fieldService.reg.schema.parse(e.inputs);
|
|
685
693
|
this.modelService.tmpOutputs = e.outputs, await this.fieldService.mount(o, r);
|
|
686
|
-
const
|
|
687
|
-
return
|
|
688
|
-
const { inputs:
|
|
689
|
-
this._lastInputs =
|
|
690
|
-
},
|
|
694
|
+
const s = r.firstChild;
|
|
695
|
+
return s.modelService = this.modelService, s.__mlSubmitHandler && s.removeEventListener("ml-submit", s.__mlSubmitHandler), s.__mlSubmitHandler = (u) => {
|
|
696
|
+
const { inputs: g, response: p } = u.detail;
|
|
697
|
+
this._lastInputs = g, this._lastResponse = p, this._listeners.forEach((b) => b(g, p));
|
|
698
|
+
}, s.addEventListener("ml-submit", s.__mlSubmitHandler, {
|
|
691
699
|
passive: !0
|
|
692
700
|
}), r;
|
|
693
701
|
}
|
|
@@ -695,15 +703,15 @@ class B {
|
|
|
695
703
|
return this.fieldService.reg.schema.safeParseAsync(e.inputs);
|
|
696
704
|
}
|
|
697
705
|
schema() {
|
|
698
|
-
return
|
|
699
|
-
|
|
706
|
+
return C(
|
|
707
|
+
P({
|
|
700
708
|
inputs: this.fieldService.reg.schema,
|
|
701
|
-
outputs:
|
|
709
|
+
outputs: U(this.modelService.reg.schema)
|
|
702
710
|
}),
|
|
703
711
|
{ target: "draft-2020-12" }
|
|
704
712
|
);
|
|
705
713
|
}
|
|
706
714
|
}
|
|
707
715
|
export {
|
|
708
|
-
|
|
716
|
+
X as MLForm
|
|
709
717
|
};
|