@react-typed-forms/schemas 1.0.0-dev.14 → 1.0.0-dev.15
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/lib/schemaBuilder.d.ts
CHANGED
|
@@ -14,9 +14,11 @@ type AllowedSchema<T> = T extends string ? SchemaField & {
|
|
|
14
14
|
} : SchemaField & {
|
|
15
15
|
type: FieldType.Any;
|
|
16
16
|
};
|
|
17
|
-
type AllowedField<T> = (name: string) =>
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
type AllowedField<T, K> = (name: string) => (SchemaField & {
|
|
18
|
+
type: K;
|
|
19
|
+
}) | AllowedSchema<T>;
|
|
20
|
+
export declare function buildSchema<T, Custom = "">(def: {
|
|
21
|
+
[K in keyof T]-?: AllowedField<T[K], Custom>;
|
|
20
22
|
}): SchemaField[];
|
|
21
23
|
export declare function stringField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
|
|
22
24
|
field?: string | undefined;
|
package/package.json
CHANGED
package/src/schemaBuilder.ts
CHANGED
|
@@ -21,10 +21,13 @@ type AllowedSchema<T> = T extends string
|
|
|
21
21
|
type: FieldType.Compound;
|
|
22
22
|
}
|
|
23
23
|
: SchemaField & { type: FieldType.Any };
|
|
24
|
-
type AllowedField<T> = (name: string) => AllowedSchema<T>;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
type AllowedField<T, K> = (
|
|
26
|
+
name: string
|
|
27
|
+
) => (SchemaField & { type: K }) | AllowedSchema<T>;
|
|
28
|
+
|
|
29
|
+
export function buildSchema<T, Custom = "">(def: {
|
|
30
|
+
[K in keyof T]-?: AllowedField<T[K], Custom>;
|
|
28
31
|
}): SchemaField[] {
|
|
29
32
|
return Object.entries(def).map((x) =>
|
|
30
33
|
(x[1] as (n: string) => SchemaField)(x[0])
|