Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rjsf/utils

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rjsf/utils - npm Package Compare versions

Comparing version 5.14.3 to 5.15.0

27

lib/schema/getDefaultFormState.js
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { ANY_OF_KEY, DEFAULT_KEY, DEPENDENCIES_KEY, PROPERTIES_KEY, ONE_OF_KEY, REF_KEY } from '../constants';
import { ANY_OF_KEY, DEFAULT_KEY, DEPENDENCIES_KEY, PROPERTIES_KEY, ONE_OF_KEY, REF_KEY, ALL_OF_KEY, } from '../constants';
import findSchemaDefinition from '../findSchemaDefinition';

@@ -195,7 +195,12 @@ import getClosestMatchingOption from './getClosestMatchingOption';

case 'object': {
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
// This is a custom addition that fixes this issue:
// https://github.com/rjsf-team/react-jsonschema-form/issues/3832
const retrievedSchema = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.allOf) === 'populateDefaults' && ALL_OF_KEY in schema
? retrieveSchema(validator, schema, rootSchema, formData)
: schema;
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce((acc, key) => {
var _a;
// Compute the defaults for this node, with the parent defaults we might
// have from a previous run: defaults[key].
const computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), {
const computedDefault = computeDefaults(validator, get(retrievedSchema, [PROPERTIES_KEY, key]), {
rootSchema,

@@ -207,14 +212,16 @@ _recurseList,

rawFormData: get(formData, [key]),
required: (_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
required: (_a = retrievedSchema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
});
maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, schema.required, experimental_defaultFormStateBehavior);
maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, required, retrievedSchema.required, experimental_defaultFormStateBehavior);
return acc;
}, {});
if (schema.additionalProperties) {
if (retrievedSchema.additionalProperties) {
// as per spec additionalProperties may be either schema or boolean
const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties)
? retrievedSchema.additionalProperties
: {};
const keys = new Set();
if (isObject(defaults)) {
Object.keys(defaults)
.filter((key) => !schema.properties || !schema.properties[key])
.filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key])
.forEach((key) => keys.add(key));

@@ -224,3 +231,3 @@ }

Object.keys(formData)
.filter((key) => !schema.properties || !schema.properties[key])
.filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key])
.forEach((key) => {

@@ -239,3 +246,3 @@ keys.add(key);

rawFormData: get(formData, [key]),
required: (_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
required: (_a = retrievedSchema.required) === null || _a === void 0 ? void 0 : _a.includes(key),
});

@@ -242,0 +249,0 @@ // Since these are additional properties we don't need to add the `experimental_defaultFormStateBehavior` prop

@@ -6,2 +6,5 @@ import get from 'lodash/get';

import transform from 'lodash/transform';
import merge from 'lodash/merge';
import flattenDeep from 'lodash/flattenDeep';
import uniq from 'lodash/uniq';
import mergeAllOf from 'json-schema-merge-allof';

@@ -172,5 +175,9 @@ import { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, DEPENDENCIES_KEY, IF_KEY, ONE_OF_KEY, REF_KEY, PROPERTIES_KEY, ITEMS_KEY, } from '../constants';

if (PROPERTIES_KEY in resolvedSchema) {
const childrenLists = [];
const updatedProps = transform(resolvedSchema[PROPERTIES_KEY], (result, value, key) => {
result[key] = resolveAllReferences(value, rootSchema, recurseList);
const childList = [...recurseList];
result[key] = resolveAllReferences(value, rootSchema, childList);
childrenLists.push(childList);
}, {});
merge(recurseList, uniq(flattenDeep(childrenLists)));
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };

@@ -177,0 +184,0 @@ }

@@ -55,2 +55,6 @@ import type { ButtonHTMLAttributes, ChangeEvent, ComponentType, HTMLAttributes, ReactElement, ReactNode, StyleHTMLAttributes } from 'react';

emptyObjectFields?: 'populateAllDefaults' | 'populateRequiredDefaults' | 'skipDefaults';
/**
* Optional flag to compute the default form state using allOf and if/then/else schemas. Defaults to `skipDefaults'.
*/
allOf?: 'populateDefaults' | 'skipDefaults';
};

@@ -57,0 +61,0 @@ /** The interface representing a Date object that contains an optional time */

{
"name": "@rjsf/utils",
"version": "5.14.3",
"version": "5.15.0",
"main": "dist/index.js",

@@ -89,3 +89,3 @@ "module": "lib/index.js",

"license": "Apache-2.0",
"gitHead": "cc96dee0be20d873a00ec00d1f7d033d4b9c9058"
"gitHead": "12781f3527ff494668913637e5aabcf27db952b1"
}
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { ANY_OF_KEY, DEFAULT_KEY, DEPENDENCIES_KEY, PROPERTIES_KEY, ONE_OF_KEY, REF_KEY } from '../constants';
import {
ANY_OF_KEY,
DEFAULT_KEY,
DEPENDENCIES_KEY,
PROPERTIES_KEY,
ONE_OF_KEY,
REF_KEY,
ALL_OF_KEY,
} from '../constants';
import findSchemaDefinition from '../findSchemaDefinition';

@@ -258,32 +266,44 @@ import getClosestMatchingOption from './getClosestMatchingOption';

case 'object': {
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc: GenericObjectType, key: string) => {
// Compute the defaults for this node, with the parent defaults we might
// have from a previous run: defaults[key].
const computedDefault = computeDefaults<T, S, F>(validator, get(schema, [PROPERTIES_KEY, key]), {
rootSchema,
_recurseList,
experimental_defaultFormStateBehavior,
includeUndefinedValues: includeUndefinedValues === true,
parentDefaults: get(defaults, [key]),
rawFormData: get(formData, [key]),
required: schema.required?.includes(key),
});
maybeAddDefaultToObject<T>(
acc,
key,
computedDefault,
includeUndefinedValues,
required,
schema.required,
experimental_defaultFormStateBehavior
);
return acc;
}, {}) as T;
if (schema.additionalProperties) {
// This is a custom addition that fixes this issue:
// https://github.com/rjsf-team/react-jsonschema-form/issues/3832
const retrievedSchema =
experimental_defaultFormStateBehavior?.allOf === 'populateDefaults' && ALL_OF_KEY in schema
? retrieveSchema<T, S, F>(validator, schema, rootSchema, formData)
: schema;
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
(acc: GenericObjectType, key: string) => {
// Compute the defaults for this node, with the parent defaults we might
// have from a previous run: defaults[key].
const computedDefault = computeDefaults<T, S, F>(validator, get(retrievedSchema, [PROPERTIES_KEY, key]), {
rootSchema,
_recurseList,
experimental_defaultFormStateBehavior,
includeUndefinedValues: includeUndefinedValues === true,
parentDefaults: get(defaults, [key]),
rawFormData: get(formData, [key]),
required: retrievedSchema.required?.includes(key),
});
maybeAddDefaultToObject<T>(
acc,
key,
computedDefault,
includeUndefinedValues,
required,
retrievedSchema.required,
experimental_defaultFormStateBehavior
);
return acc;
},
{}
) as T;
if (retrievedSchema.additionalProperties) {
// as per spec additionalProperties may be either schema or boolean
const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties)
? retrievedSchema.additionalProperties
: {};
const keys = new Set<string>();
if (isObject(defaults)) {
Object.keys(defaults as GenericObjectType)
.filter((key) => !schema.properties || !schema.properties[key])
.filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key])
.forEach((key) => keys.add(key));

@@ -293,3 +313,3 @@ }

Object.keys(formData as GenericObjectType)
.filter((key) => !schema.properties || !schema.properties[key])
.filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key])
.forEach((key) => {

@@ -307,3 +327,3 @@ keys.add(key);

rawFormData: get(formData, [key]),
required: schema.required?.includes(key),
required: retrievedSchema.required?.includes(key),
});

@@ -310,0 +330,0 @@ // Since these are additional properties we don't need to add the `experimental_defaultFormStateBehavior` prop

@@ -6,2 +6,5 @@ import get from 'lodash/get';

import transform from 'lodash/transform';
import merge from 'lodash/merge';
import flattenDeep from 'lodash/flattenDeep';
import uniq from 'lodash/uniq';
import mergeAllOf, { Options } from 'json-schema-merge-allof';

@@ -269,9 +272,13 @@

if (PROPERTIES_KEY in resolvedSchema) {
const childrenLists: string[][] = [];
const updatedProps = transform(
resolvedSchema[PROPERTIES_KEY]!,
(result, value, key: string) => {
result[key] = resolveAllReferences(value as S, rootSchema, recurseList);
const childList: string[] = [...recurseList];
result[key] = resolveAllReferences(value as S, rootSchema, childList);
childrenLists.push(childList);
},
{} as RJSFSchema
);
merge(recurseList, uniq(flattenDeep(childrenLists)));
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };

@@ -278,0 +285,0 @@ }

@@ -70,2 +70,6 @@ import type {

emptyObjectFields?: 'populateAllDefaults' | 'populateRequiredDefaults' | 'skipDefaults';
/**
* Optional flag to compute the default form state using allOf and if/then/else schemas. Defaults to `skipDefaults'.
*/
allOf?: 'populateDefaults' | 'skipDefaults';
};

@@ -72,0 +76,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc