@rjsf/utils 5.18.4 → 5.18.6
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/dist/index.js.map +2 -2
- package/dist/utils.esm.js.map +2 -2
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +12 -10
- package/package.json +2 -2
- package/src/schema/toIdSchema.ts +4 -4
- package/src/schema/toPathSchema.ts +8 -8
- package/src/types.ts +22 -14
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
16
16
|
} from '../constants';
|
|
17
17
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
18
|
-
import { FormContextType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
18
|
+
import { FormContextType, GenericObjectType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
19
19
|
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
20
20
|
import retrieveSchema from './retrieveSchema';
|
|
21
21
|
|
|
@@ -53,9 +53,9 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
let pathSchema: PathSchema = {
|
|
56
|
+
let pathSchema: PathSchema<T> = {
|
|
57
57
|
[NAME_KEY]: name.replace(/^\./, ''),
|
|
58
|
-
} as PathSchema
|
|
58
|
+
} as PathSchema<T>;
|
|
59
59
|
|
|
60
60
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
61
61
|
const xxxOf: S[] = ONE_OF_KEY in schema ? (schema.oneOf as S[]) : (schema.anyOf as S[]);
|
|
@@ -78,7 +78,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
78
78
|
if (Array.isArray(schemaItems)) {
|
|
79
79
|
formData.forEach((element, i: number) => {
|
|
80
80
|
if (schemaItems[i]) {
|
|
81
|
-
pathSchema[i] = toPathSchemaInternal<T, S, F>(
|
|
81
|
+
(pathSchema as PathSchema<T[]>)[i] = toPathSchemaInternal<T, S, F>(
|
|
82
82
|
validator,
|
|
83
83
|
schemaItems[i] as S,
|
|
84
84
|
`${name}.${i}`,
|
|
@@ -87,7 +87,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
87
87
|
_recurseList
|
|
88
88
|
);
|
|
89
89
|
} else if (schemaAdditionalItems) {
|
|
90
|
-
pathSchema[i] = toPathSchemaInternal<T, S, F>(
|
|
90
|
+
(pathSchema as PathSchema<T[]>)[i] = toPathSchemaInternal<T, S, F>(
|
|
91
91
|
validator,
|
|
92
92
|
schemaAdditionalItems as S,
|
|
93
93
|
`${name}.${i}`,
|
|
@@ -101,7 +101,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
101
101
|
});
|
|
102
102
|
} else {
|
|
103
103
|
formData.forEach((element, i: number) => {
|
|
104
|
-
pathSchema[i] = toPathSchemaInternal<T, S, F>(
|
|
104
|
+
(pathSchema as PathSchema<T[]>)[i] = toPathSchemaInternal<T, S, F>(
|
|
105
105
|
validator,
|
|
106
106
|
schemaItems as S,
|
|
107
107
|
`${name}.${i}`,
|
|
@@ -114,7 +114,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
114
114
|
} else if (PROPERTIES_KEY in schema) {
|
|
115
115
|
for (const property in schema.properties) {
|
|
116
116
|
const field = get(schema, [PROPERTIES_KEY, property]);
|
|
117
|
-
pathSchema[property] = toPathSchemaInternal<T, S, F>(
|
|
117
|
+
(pathSchema as PathSchema<GenericObjectType>)[property] = toPathSchemaInternal<T, S, F>(
|
|
118
118
|
validator,
|
|
119
119
|
field,
|
|
120
120
|
`${name}.${property}`,
|
|
@@ -126,7 +126,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
return pathSchema
|
|
129
|
+
return pathSchema;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
package/src/types.ts
CHANGED
|
@@ -131,10 +131,12 @@ export type FieldId = {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
/** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
|
|
134
|
-
export type IdSchema<T = any> =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
export type IdSchema<T = any> = T extends GenericObjectType
|
|
135
|
+
? FieldId & {
|
|
136
|
+
/** The set of ids for fields in the recursive object structure */
|
|
137
|
+
[key in keyof T]?: IdSchema<T[key]>;
|
|
138
|
+
}
|
|
139
|
+
: FieldId;
|
|
138
140
|
|
|
139
141
|
/** Type describing a name used for a field in the `PathSchema` */
|
|
140
142
|
export type FieldPath = {
|
|
@@ -143,10 +145,16 @@ export type FieldPath = {
|
|
|
143
145
|
};
|
|
144
146
|
|
|
145
147
|
/** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys */
|
|
146
|
-
export type PathSchema<T = any> =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
148
|
+
export type PathSchema<T = any> = T extends Array<infer U>
|
|
149
|
+
? FieldPath & {
|
|
150
|
+
[i: number]: PathSchema<U>;
|
|
151
|
+
}
|
|
152
|
+
: T extends GenericObjectType
|
|
153
|
+
? FieldPath & {
|
|
154
|
+
/** The set of names for fields in the recursive object structure */
|
|
155
|
+
[key in keyof T]?: PathSchema<T[key]>;
|
|
156
|
+
}
|
|
157
|
+
: FieldPath;
|
|
150
158
|
|
|
151
159
|
/** The type for error produced by RJSF schema validation */
|
|
152
160
|
export type RJSFValidationError = {
|
|
@@ -380,11 +388,11 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
380
388
|
/** A boolean value stating if the field should autofocus */
|
|
381
389
|
autofocus?: boolean;
|
|
382
390
|
/** A boolean value stating if the field is disabled */
|
|
383
|
-
disabled
|
|
391
|
+
disabled?: boolean;
|
|
384
392
|
/** A boolean value stating if the field is hiding its errors */
|
|
385
393
|
hideError?: boolean;
|
|
386
394
|
/** A boolean value stating if the field is read-only */
|
|
387
|
-
readonly
|
|
395
|
+
readonly?: boolean;
|
|
388
396
|
/** The required status of this field */
|
|
389
397
|
required?: boolean;
|
|
390
398
|
/** The unique name of the field, usually derived from the name of the property in the JSONSchema */
|
|
@@ -545,7 +553,7 @@ export type ArrayFieldTemplateItemType<
|
|
|
545
553
|
/** The className string */
|
|
546
554
|
className: string;
|
|
547
555
|
/** A boolean value stating if the array item is disabled */
|
|
548
|
-
disabled
|
|
556
|
+
disabled?: boolean;
|
|
549
557
|
/** A boolean value stating whether new items can be added to the array */
|
|
550
558
|
canAdd: boolean;
|
|
551
559
|
/** A boolean value stating whether the array item can be copied, assumed false if missing */
|
|
@@ -571,7 +579,7 @@ export type ArrayFieldTemplateItemType<
|
|
|
571
579
|
/** Returns a function that swaps the items at `index` with `newIndex` */
|
|
572
580
|
onReorderClick: (index: number, newIndex: number) => (event?: any) => void;
|
|
573
581
|
/** A boolean value stating if the array item is read-only */
|
|
574
|
-
readonly
|
|
582
|
+
readonly?: boolean;
|
|
575
583
|
/** A stable, unique key for the array item */
|
|
576
584
|
key: string;
|
|
577
585
|
/** The schema object for this array item */
|
|
@@ -631,9 +639,9 @@ export type ObjectFieldTemplatePropertyType = {
|
|
|
631
639
|
/** A string representing the property name */
|
|
632
640
|
name: string;
|
|
633
641
|
/** A boolean value stating if the object property is disabled */
|
|
634
|
-
disabled
|
|
642
|
+
disabled?: boolean;
|
|
635
643
|
/** A boolean value stating if the property is read-only */
|
|
636
|
-
readonly
|
|
644
|
+
readonly?: boolean;
|
|
637
645
|
/** A boolean value stating if the property should be hidden */
|
|
638
646
|
hidden: boolean;
|
|
639
647
|
};
|