@rjsf/utils 6.5.3 → 6.6.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.
- package/dist/index.cjs +618 -433
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +614 -429
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +623 -438
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.js +1 -1
- package/lib/constIsAjvDataReference.js.map +1 -1
- package/lib/createSchemaUtils.js +3 -3
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enumOptionSelectedValue.js.map +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionsDeselectValue.js +1 -1
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.js +1 -1
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.js +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/findSchemaDefinition.js +4 -4
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +3 -3
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getTestIds.js +4 -3
- package/lib/getTestIds.js.map +1 -1
- package/lib/getWidget.js +1 -1
- package/lib/getWidget.js.map +1 -1
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +6 -6
- package/lib/index.js.map +1 -1
- package/lib/isFormDataAvailable.js +1 -1
- package/lib/isFormDataAvailable.js.map +1 -1
- package/lib/isRootSchema.js +1 -1
- package/lib/isRootSchema.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +1 -1
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/parser/ParserValidator.js +1 -1
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/schemaParser.js +2 -2
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +2 -0
- package/lib/removeOptionalEmptyObjects.js +8 -29
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/schema/findFieldInSchema.js +1 -1
- package/lib/schema/findFieldInSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +3 -3
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +17 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getFromSchema.js +1 -1
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/schema/index.d.ts +4 -4
- package/lib/schema/index.js +4 -4
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +18 -8
- package/lib/schema/omitExtraData.js +352 -16
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +15 -0
- package/lib/schema/retrieveSchema.js +36 -13
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/shallowAllOfMerge.d.ts +11 -0
- package/lib/schema/shallowAllOfMerge.js +18 -0
- package/lib/schema/shallowAllOfMerge.js.map +1 -0
- package/lib/schema/toPathSchema.d.ts +1 -0
- package/lib/schema/toPathSchema.js +2 -1
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/shouldRenderOptionalField.js +1 -1
- package/lib/shouldRenderOptionalField.js.map +1 -1
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +4 -1
- package/lib/useFileWidgetProps.d.ts +1 -1
- package/lib/useFileWidgetProps.js +9 -10
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/withIdRefPrefix.js +1 -1
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +10 -10
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +3 -2
- package/src/createSchemaUtils.ts +18 -17
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +2 -2
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +3 -2
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/findSchemaDefinition.ts +4 -4
- package/src/getChangedFields.ts +4 -3
- package/src/getDiscriminatorFieldFromSchema.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +1 -0
- package/src/getTestIds.ts +4 -3
- package/src/getWidget.tsx +2 -2
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +6 -6
- package/src/isFormDataAvailable.ts +1 -1
- package/src/isRootSchema.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +2 -2
- package/src/parser/ParserValidator.ts +1 -1
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +3 -3
- package/src/removeOptionalEmptyObjects.ts +8 -30
- package/src/schema/findFieldInSchema.ts +2 -2
- package/src/schema/findSelectedOptionInXxxOf.ts +1 -1
- package/src/schema/getClosestMatchingOption.ts +4 -4
- package/src/schema/getDefaultFormState.ts +18 -24
- package/src/schema/getFromSchema.ts +2 -2
- package/src/schema/index.ts +5 -3
- package/src/schema/isMultiSelect.ts +0 -1
- package/src/schema/omitExtraData.ts +398 -19
- package/src/schema/retrieveSchema.ts +41 -15
- package/src/schema/sanitizeDataForNewSchema.ts +1 -1
- package/src/schema/shallowAllOfMerge.ts +19 -0
- package/src/schema/toPathSchema.ts +2 -1
- package/src/shouldRenderOptionalField.ts +2 -2
- package/src/toErrorSchema.ts +1 -1
- package/src/tsconfig.json +0 -1
- package/src/types.ts +4 -1
- package/src/useFileWidgetProps.ts +9 -10
- package/src/withIdRefPrefix.ts +2 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import flattenDeep from 'lodash/flattenDeep';
|
|
1
2
|
import get from 'lodash/get';
|
|
3
|
+
import isEmpty from 'lodash/isEmpty';
|
|
4
|
+
import merge from 'lodash/merge';
|
|
2
5
|
import set from 'lodash/set';
|
|
3
6
|
import times from 'lodash/times';
|
|
4
7
|
import transform from 'lodash/transform';
|
|
5
|
-
import merge from 'lodash/merge';
|
|
6
|
-
import flattenDeep from 'lodash/flattenDeep';
|
|
7
8
|
import uniq from 'lodash/uniq';
|
|
8
|
-
import isEmpty from 'lodash/isEmpty';
|
|
9
|
-
import { createComparator, createMerger, createShallowAllOfMerge } from '@x0k/json-schema-merge';
|
|
10
|
-
import { createDeduplicator, createIntersector } from '@x0k/json-schema-merge/lib/array';
|
|
11
9
|
|
|
12
10
|
import {
|
|
13
11
|
ADDITIONAL_PROPERTIES_KEY,
|
|
@@ -24,6 +22,7 @@ import {
|
|
|
24
22
|
REF_KEY,
|
|
25
23
|
RJSF_REF_KEY,
|
|
26
24
|
} from '../constants';
|
|
25
|
+
import deepEquals from '../deepEquals';
|
|
27
26
|
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition';
|
|
28
27
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
29
28
|
import guessType from '../guessType';
|
|
@@ -38,7 +37,7 @@ import {
|
|
|
38
37
|
ValidatorType,
|
|
39
38
|
} from '../types';
|
|
40
39
|
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
41
|
-
import
|
|
40
|
+
import shallowAllOfMerge from './shallowAllOfMerge';
|
|
42
41
|
|
|
43
42
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
44
43
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
@@ -514,15 +513,6 @@ export function stubExistingAdditionalProperties<
|
|
|
514
513
|
return schema;
|
|
515
514
|
}
|
|
516
515
|
|
|
517
|
-
// Set up @x0k/json-schema-merge utilities
|
|
518
|
-
const { compareSchemaDefinitions, compareSchemaValues } = createComparator();
|
|
519
|
-
const { mergeArrayOfSchemaDefinitions } = createMerger({
|
|
520
|
-
intersectJson: createIntersector(compareSchemaValues),
|
|
521
|
-
deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions),
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
const shallowAllOfMerge = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
|
|
525
|
-
|
|
526
516
|
/**
|
|
527
517
|
* Internal helper that merges allOf schemas using @x0k/json-schema-merge's shallow allOf merge
|
|
528
518
|
* @param schema - The schema containing an `allOf` keyword
|
|
@@ -694,6 +684,14 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
694
684
|
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
695
685
|
const option = getFirstMatchingOption<T, S, F>(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
696
686
|
if (expandAllBranches) {
|
|
687
|
+
// Also trigger isValid() for the relaxed variants so that precompiled validators capture their hashes.
|
|
688
|
+
// omitExtraData's handleOneOf relaxes additionalProperties:false → true before scoring; those mutated
|
|
689
|
+
// schemas must be present in a precompiled validator's compiled set or isValid() will throw at runtime.
|
|
690
|
+
// Using getFirstMatchingOption (rather than calling isValid directly) ensures that the augmented forms
|
|
691
|
+
// of each option (as constructed internally by getFirstMatchingOption for options with properties) are
|
|
692
|
+
// also captured. The return value is discarded — the call is purely for ParserValidator's side effect.
|
|
693
|
+
const relaxed = relaxOptionsForScoring<S>(anyOrOneOf, false, rootSchema);
|
|
694
|
+
getFirstMatchingOption<T, S, F>(validator, formData, relaxed, rootSchema, discriminator);
|
|
697
695
|
return anyOrOneOf.map((item) => mergeSchemas(remaining, item) as S);
|
|
698
696
|
}
|
|
699
697
|
schema = mergeSchemas(remaining, anyOrOneOf[option]) as S;
|
|
@@ -701,6 +699,34 @@ export function resolveAnyOrOneOfSchemas<
|
|
|
701
699
|
return [schema];
|
|
702
700
|
}
|
|
703
701
|
|
|
702
|
+
/** Normalises a list of `oneOf`/`anyOf` options for use in option-scoring only (not for filtering).
|
|
703
|
+
* Boolean schemas are converted to their object equivalents (`true` → `{}`, `false` → `{not:{}}`).
|
|
704
|
+
* When `resolveRefs` is `true`, each object option is first passed through `resolveAllReferences`
|
|
705
|
+
* so that `$ref`-based options expose their `additionalProperties` constraint before relaxation.
|
|
706
|
+
* Any option whose `additionalProperties` is `false` is widened to `true` so that
|
|
707
|
+
* `getClosestMatchingOption` / `validator.isValid()` does not produce false negatives when the
|
|
708
|
+
* form data contains keys not listed in `properties`.
|
|
709
|
+
*
|
|
710
|
+
* @param options - The raw `oneOf`/`anyOf` array, which may contain boolean schemas
|
|
711
|
+
* @param [resolveRefs=false] - When `true`, resolve `$ref`s in each option before relaxing; pass
|
|
712
|
+
* `rootSchema` as well. Set `false` (default) when refs are already resolved at the call site.
|
|
713
|
+
* @param [rootSchema] - Required when `resolveRefs` is `true`; the root schema used to look up `$ref`s
|
|
714
|
+
* @returns - A new array of plain schema objects with `additionalProperties` relaxed where needed
|
|
715
|
+
*/
|
|
716
|
+
export function relaxOptionsForScoring<S extends StrictRJSFSchema = RJSFSchema>(
|
|
717
|
+
options: Array<S | boolean>,
|
|
718
|
+
resolveRefs = false,
|
|
719
|
+
rootSchema?: S,
|
|
720
|
+
): S[] {
|
|
721
|
+
return options.map((d) => {
|
|
722
|
+
if (!isObject(d)) {
|
|
723
|
+
return (d ? {} : { not: {} }) as S;
|
|
724
|
+
}
|
|
725
|
+
const schema = resolveRefs && rootSchema ? resolveAllReferences<S>(d as S, rootSchema, []) : (d as S);
|
|
726
|
+
return schema.additionalProperties === false ? { ...schema, additionalProperties: true } : schema;
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
704
730
|
/** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
|
|
705
731
|
* the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
|
|
706
732
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
|
|
4
|
+
import { PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
4
5
|
import {
|
|
5
6
|
Experimental_CustomMergeAllOf,
|
|
6
7
|
FormContextType,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
StrictRJSFSchema,
|
|
10
11
|
ValidatorType,
|
|
11
12
|
} from '../types';
|
|
12
|
-
import { PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
13
13
|
import retrieveSchema from './retrieveSchema';
|
|
14
14
|
|
|
15
15
|
const NO_VALUE = Symbol('no Value');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createComparator, createMerger, createShallowAllOfMerge } from '@x0k/json-schema-merge';
|
|
2
|
+
import { createDeduplicator, createIntersector } from '@x0k/json-schema-merge/lib/array';
|
|
3
|
+
|
|
4
|
+
const { compareSchemaDefinitions, compareSchemaValues } = createComparator();
|
|
5
|
+
const { mergeArrayOfSchemaDefinitions } = createMerger({
|
|
6
|
+
intersectJson: createIntersector(compareSchemaValues),
|
|
7
|
+
deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/** Shared `@x0k/json-schema-merge` shallow-allOf merge function used by `retrieveSchema` and
|
|
11
|
+
* `omitExtraData`. Constructed once from a single comparator/merger/intersector/deduplicator
|
|
12
|
+
* pipeline so both consumers share the same configuration without duplicating setup code.
|
|
13
|
+
*
|
|
14
|
+
* Usage: pass a schema that contains an `allOf` keyword and receive the merged result.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const merged = shallowAllOfMerge(schema); // schema.allOf is merged into the parent schema
|
|
18
|
+
*/
|
|
19
|
+
export default createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
REF_KEY,
|
|
16
16
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
17
17
|
} from '../constants';
|
|
18
|
+
import deepEquals from '../deepEquals';
|
|
18
19
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
19
20
|
import {
|
|
20
21
|
Experimental_CustomMergeAllOf,
|
|
@@ -27,7 +28,6 @@ import {
|
|
|
27
28
|
} from '../types';
|
|
28
29
|
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
29
30
|
import retrieveSchema from './retrieveSchema';
|
|
30
|
-
import deepEquals from '../deepEquals';
|
|
31
31
|
|
|
32
32
|
/** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
|
|
33
33
|
* infinite recursion
|
|
@@ -188,6 +188,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
188
188
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
189
189
|
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
190
190
|
* @returns - The `PathSchema` object for the `schema`
|
|
191
|
+
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
|
|
191
192
|
*/
|
|
192
193
|
export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
193
194
|
validator: ValidatorType<T, S, F>,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import isObject from 'lodash/isObject';
|
|
2
2
|
import uniq from 'lodash/uniq';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ANY_OF_KEY, ONE_OF_KEY } from './constants';
|
|
5
5
|
import getSchemaType from './getSchemaType';
|
|
6
6
|
import getUiOptions from './getUiOptions';
|
|
7
7
|
import isRootSchema from './isRootSchema';
|
|
8
|
-
import {
|
|
8
|
+
import { FormContextType, Registry, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
|
|
9
9
|
|
|
10
10
|
/** Returns the unique list of schema types for all of the options in a anyOf/oneOf
|
|
11
11
|
*
|
package/src/toErrorSchema.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import toPath from 'lodash/toPath';
|
|
2
2
|
|
|
3
|
-
import { ErrorSchema, RJSFValidationError } from './types';
|
|
4
3
|
import ErrorSchemaBuilder from './ErrorSchemaBuilder';
|
|
4
|
+
import { ErrorSchema, RJSFValidationError } from './types';
|
|
5
5
|
|
|
6
6
|
/** Transforms a rjsf validation errors list:
|
|
7
7
|
* [
|
package/src/tsconfig.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -205,7 +205,9 @@ export type FieldPath = {
|
|
|
205
205
|
$name: string;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
-
/** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys
|
|
208
|
+
/** Type describing a recursive structure of `FieldPath`s for an object with a non-empty set of keys
|
|
209
|
+
* @deprecated - To be removed as an exported `@rjsf/utils` type in a future release
|
|
210
|
+
*/
|
|
209
211
|
export type PathSchema<T = any> =
|
|
210
212
|
T extends Array<infer U>
|
|
211
213
|
? FieldPath & {
|
|
@@ -1473,6 +1475,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
1473
1475
|
* @param [name] - The base name for the schema
|
|
1474
1476
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1475
1477
|
* @returns - The `PathSchema` object for the `schema`
|
|
1478
|
+
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
|
|
1476
1479
|
*/
|
|
1477
1480
|
toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T>;
|
|
1478
1481
|
}
|
|
@@ -20,7 +20,7 @@ export interface UseFileWidgetPropsResult {
|
|
|
20
20
|
/** The list of FileInfoType contained within the FileWidget */
|
|
21
21
|
filesInfo: FileInfoType[];
|
|
22
22
|
/** The callback handler to pass to the onChange of the input */
|
|
23
|
-
handleChange: (files: FileList) => void
|
|
23
|
+
handleChange: (files: FileList) => void | Promise<void>;
|
|
24
24
|
/** The callback handler to pass in order to delete a file */
|
|
25
25
|
handleRemove: (index: number) => void;
|
|
26
26
|
}
|
|
@@ -129,15 +129,14 @@ export default function useFileWidgetProps(
|
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
const handleChange = useCallback(
|
|
132
|
-
(files: FileList) => {
|
|
133
|
-
processFiles(files)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
132
|
+
async (files: FileList) => {
|
|
133
|
+
const filesInfoEvent = await processFiles(files);
|
|
134
|
+
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
|
|
135
|
+
if (multiple) {
|
|
136
|
+
onChange(values.concat(...newValue));
|
|
137
|
+
} else {
|
|
138
|
+
onChange(newValue[0]);
|
|
139
|
+
}
|
|
141
140
|
},
|
|
142
141
|
[values, multiple, onChange],
|
|
143
142
|
);
|
package/src/withIdRefPrefix.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import isObject from 'lodash/isObject';
|
|
2
|
+
|
|
1
3
|
import { REF_KEY, ROOT_SCHEMA_PREFIX } from './constants';
|
|
2
4
|
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
|
-
import isObject from 'lodash/isObject';
|
|
4
5
|
|
|
5
6
|
/** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
6
7
|
* `withIdRefPrefix` for any other elements.
|