@uniform-ts/core 0.0.0 → 0.0.2
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 +20 -1
- package/dist/index.d.mts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +46 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -61,25 +61,30 @@ function introspectSchema(schema, name = "", parentPath = "") {
|
|
|
61
61
|
let maxItems;
|
|
62
62
|
try {
|
|
63
63
|
if (kind === "string") {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
mergedMeta["inputType"] = "email";
|
|
68
|
-
} else if (defFormat === "url") {
|
|
69
|
-
mergedMeta["inputType"] = "url";
|
|
70
|
-
} else if (defFormat === "uuid") {
|
|
71
|
-
mergedMeta["inputType"] = "uuid";
|
|
64
|
+
if (mergedMeta.component === "select" && Array.isArray(mergedMeta.options) && mergedMeta.options.length > 0) {
|
|
65
|
+
type = "select";
|
|
66
|
+
options = mergedMeta.options;
|
|
72
67
|
} else {
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
if (hasFormat("email")) {
|
|
68
|
+
type = "string";
|
|
69
|
+
const defFormat = def.format;
|
|
70
|
+
if (defFormat === "email") {
|
|
78
71
|
mergedMeta["inputType"] = "email";
|
|
79
|
-
} else if (
|
|
72
|
+
} else if (defFormat === "url") {
|
|
80
73
|
mergedMeta["inputType"] = "url";
|
|
81
|
-
} else if (
|
|
74
|
+
} else if (defFormat === "uuid") {
|
|
82
75
|
mergedMeta["inputType"] = "uuid";
|
|
76
|
+
} else {
|
|
77
|
+
const checks = def.checks ?? [];
|
|
78
|
+
const hasFormat = (fmt) => checks.some(
|
|
79
|
+
(c) => c._zod.def.check === "string_format" && c._zod.def.format === fmt
|
|
80
|
+
);
|
|
81
|
+
if (hasFormat("email")) {
|
|
82
|
+
mergedMeta["inputType"] = "email";
|
|
83
|
+
} else if (hasFormat("url")) {
|
|
84
|
+
mergedMeta["inputType"] = "url";
|
|
85
|
+
} else if (hasFormat("uuid")) {
|
|
86
|
+
mergedMeta["inputType"] = "uuid";
|
|
87
|
+
}
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
} else if (kind === "number") {
|
|
@@ -116,15 +121,24 @@ function introspectSchema(schema, name = "", parentPath = "") {
|
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
} else if (def.type === "union") {
|
|
119
|
-
type = "union";
|
|
120
124
|
const unionDef = def;
|
|
125
|
+
const variants = unionDef.options;
|
|
121
126
|
if ("discriminator" in unionDef) {
|
|
127
|
+
type = "union";
|
|
122
128
|
discriminatorKey = unionDef.discriminator;
|
|
129
|
+
unionVariants = variants.map(
|
|
130
|
+
(variant, i) => introspectSchema(variant, String(i), path)
|
|
131
|
+
);
|
|
132
|
+
} else {
|
|
133
|
+
const collapsed = introspectSchema(variants[0], name, parentPath);
|
|
134
|
+
return {
|
|
135
|
+
...collapsed,
|
|
136
|
+
name: path,
|
|
137
|
+
label,
|
|
138
|
+
meta: { ...collapsed.meta, ...mergedMeta },
|
|
139
|
+
schema: inner
|
|
140
|
+
};
|
|
123
141
|
}
|
|
124
|
-
const variants = unionDef.options;
|
|
125
|
-
unionVariants = variants.map(
|
|
126
|
-
(variant, i) => introspectSchema(variant, String(i), path)
|
|
127
|
-
);
|
|
128
142
|
}
|
|
129
143
|
} catch {
|
|
130
144
|
type = "unknown";
|
|
@@ -135,6 +149,7 @@ function introspectSchema(schema, name = "", parentPath = "") {
|
|
|
135
149
|
label,
|
|
136
150
|
required,
|
|
137
151
|
meta: mergedMeta,
|
|
152
|
+
schema: inner,
|
|
138
153
|
...options !== void 0 && { options },
|
|
139
154
|
...children !== void 0 && { children },
|
|
140
155
|
...itemConfig !== void 0 && { itemConfig },
|
|
@@ -173,6 +188,7 @@ function parseDiscriminatedUnionMeta(schema) {
|
|
|
173
188
|
label: deriveLabel(discriminatorKey),
|
|
174
189
|
required: true,
|
|
175
190
|
meta: {},
|
|
191
|
+
schema,
|
|
176
192
|
options: discriminatorOptions
|
|
177
193
|
};
|
|
178
194
|
return {
|
|
@@ -473,7 +489,7 @@ function ScalarField({
|
|
|
473
489
|
onChange: (value) => {
|
|
474
490
|
const coerced = coerceValue(field.type, value, coercions);
|
|
475
491
|
rhfField.onChange(coerced);
|
|
476
|
-
field.meta.onChange?.(coerced, formMethods);
|
|
492
|
+
void field.meta.onChange?.(coerced, formMethods);
|
|
477
493
|
},
|
|
478
494
|
onBlur: rhfField.onBlur,
|
|
479
495
|
ref: rhfField.ref,
|
|
@@ -483,7 +499,9 @@ function ScalarField({
|
|
|
483
499
|
error: fieldState.error?.message,
|
|
484
500
|
required: field.required,
|
|
485
501
|
disabled: field.meta.disabled || contextDisabled,
|
|
486
|
-
|
|
502
|
+
options: field.meta.options,
|
|
503
|
+
meta: field.meta,
|
|
504
|
+
schema: field.schema
|
|
487
505
|
}
|
|
488
506
|
)
|
|
489
507
|
}
|
|
@@ -515,7 +533,7 @@ function BooleanField({
|
|
|
515
533
|
value: rhfField.value ?? false,
|
|
516
534
|
onChange: (value) => {
|
|
517
535
|
rhfField.onChange(value);
|
|
518
|
-
field.meta.onChange?.(value, formMethods);
|
|
536
|
+
void field.meta.onChange?.(value, formMethods);
|
|
519
537
|
},
|
|
520
538
|
onBlur: rhfField.onBlur,
|
|
521
539
|
ref: rhfField.ref,
|
|
@@ -525,7 +543,8 @@ function BooleanField({
|
|
|
525
543
|
error: fieldState.error?.message,
|
|
526
544
|
required: field.required,
|
|
527
545
|
disabled: field.meta.disabled || rhfField.disabled || contextDisabled,
|
|
528
|
-
meta: field.meta
|
|
546
|
+
meta: field.meta,
|
|
547
|
+
schema: field.schema
|
|
529
548
|
}
|
|
530
549
|
)
|
|
531
550
|
}
|
|
@@ -557,7 +576,7 @@ function SelectField({
|
|
|
557
576
|
value: rhfField.value ?? "",
|
|
558
577
|
onChange: (value) => {
|
|
559
578
|
rhfField.onChange(value);
|
|
560
|
-
field.meta.onChange?.(value, formMethods);
|
|
579
|
+
void field.meta.onChange?.(value, formMethods);
|
|
561
580
|
},
|
|
562
581
|
onBlur: rhfField.onBlur,
|
|
563
582
|
ref: rhfField.ref,
|
|
@@ -568,7 +587,8 @@ function SelectField({
|
|
|
568
587
|
required: field.required,
|
|
569
588
|
disabled: field.meta.disabled || contextDisabled,
|
|
570
589
|
options: field.options,
|
|
571
|
-
meta: field.meta
|
|
590
|
+
meta: field.meta,
|
|
591
|
+
schema: field.schema
|
|
572
592
|
}
|
|
573
593
|
)
|
|
574
594
|
}
|