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