@rjsf/utils 5.13.0 → 5.13.1
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 +243 -125
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +243 -125
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +223 -111
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +12 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js +36 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -0
- package/lib/getSchemaType.js +7 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/parser/schemaParser.js +3 -2
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.js +7 -1
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +9 -12
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getMatchingOption.js +6 -0
- package/lib/schema/getMatchingOption.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +16 -14
- package/lib/schema/retrieveSchema.js +57 -43
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +15 -15
- package/src/getOptionMatchingSimpleDiscriminator.ts +46 -0
- package/src/getSchemaType.ts +6 -2
- package/src/index.ts +2 -0
- package/src/parser/schemaParser.ts +3 -2
- package/src/schema/getClosestMatchingOption.ts +9 -1
- package/src/schema/getDefaultFormState.ts +9 -12
- package/src/schema/getMatchingOption.ts +8 -0
- package/src/schema/retrieveSchema.ts +145 -39
- package/src/types.ts +1 -1
package/dist/utils.esm.js
CHANGED
|
@@ -138,7 +138,7 @@ function deepEquals(a, b) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// src/schema/getDefaultFormState.ts
|
|
141
|
-
import
|
|
141
|
+
import get7 from "lodash/get";
|
|
142
142
|
import isEmpty from "lodash/isEmpty";
|
|
143
143
|
|
|
144
144
|
// src/findSchemaDefinition.ts
|
|
@@ -172,25 +172,58 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// src/schema/getClosestMatchingOption.ts
|
|
175
|
-
import
|
|
175
|
+
import get5 from "lodash/get";
|
|
176
176
|
import has2 from "lodash/has";
|
|
177
|
+
import isNumber2 from "lodash/isNumber";
|
|
177
178
|
import isObject2 from "lodash/isObject";
|
|
178
179
|
import isString2 from "lodash/isString";
|
|
179
180
|
import reduce from "lodash/reduce";
|
|
180
181
|
import times2 from "lodash/times";
|
|
181
182
|
|
|
182
183
|
// src/schema/getMatchingOption.ts
|
|
183
|
-
import
|
|
184
|
+
import get2 from "lodash/get";
|
|
184
185
|
import has from "lodash/has";
|
|
186
|
+
import isNumber from "lodash/isNumber";
|
|
187
|
+
|
|
188
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
189
|
+
import get from "lodash/get";
|
|
190
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
191
|
+
if (formData && discriminatorField) {
|
|
192
|
+
const value = get(formData, discriminatorField);
|
|
193
|
+
if (value === void 0) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < options.length; i++) {
|
|
197
|
+
const option = options[i];
|
|
198
|
+
const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
199
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (discriminator.const === value) {
|
|
203
|
+
return i;
|
|
204
|
+
}
|
|
205
|
+
if (discriminator.enum?.includes(value)) {
|
|
206
|
+
return i;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/schema/getMatchingOption.ts
|
|
185
214
|
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
186
215
|
if (formData === void 0) {
|
|
187
216
|
return 0;
|
|
188
217
|
}
|
|
218
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
219
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
220
|
+
return simpleDiscriminatorMatch;
|
|
221
|
+
}
|
|
189
222
|
for (let i = 0; i < options.length; i++) {
|
|
190
223
|
const option = options[i];
|
|
191
224
|
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
192
|
-
const value =
|
|
193
|
-
const discriminator =
|
|
225
|
+
const value = get2(formData, discriminatorField);
|
|
226
|
+
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
194
227
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
195
228
|
return i;
|
|
196
229
|
}
|
|
@@ -230,18 +263,19 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
230
263
|
}
|
|
231
264
|
|
|
232
265
|
// src/schema/retrieveSchema.ts
|
|
233
|
-
import
|
|
266
|
+
import get4 from "lodash/get";
|
|
267
|
+
import isEqual from "lodash/isEqual";
|
|
234
268
|
import set from "lodash/set";
|
|
235
269
|
import times from "lodash/times";
|
|
236
270
|
import transform from "lodash/transform";
|
|
237
271
|
import mergeAllOf from "json-schema-merge-allof";
|
|
238
272
|
|
|
239
273
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
240
|
-
import
|
|
274
|
+
import get3 from "lodash/get";
|
|
241
275
|
import isString from "lodash/isString";
|
|
242
276
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
243
277
|
let discriminator;
|
|
244
|
-
const maybeString =
|
|
278
|
+
const maybeString = get3(schema, "discriminator.propertyName", void 0);
|
|
245
279
|
if (isString(maybeString)) {
|
|
246
280
|
discriminator = maybeString;
|
|
247
281
|
} else if (maybeString !== void 0) {
|
|
@@ -288,8 +322,12 @@ function getSchemaType(schema) {
|
|
|
288
322
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
289
323
|
return "object";
|
|
290
324
|
}
|
|
291
|
-
if (Array.isArray(type)
|
|
292
|
-
|
|
325
|
+
if (Array.isArray(type)) {
|
|
326
|
+
if (type.length === 2 && type.includes("null")) {
|
|
327
|
+
type = type.find((type2) => type2 !== "null");
|
|
328
|
+
} else {
|
|
329
|
+
type = type[0];
|
|
330
|
+
}
|
|
293
331
|
}
|
|
294
332
|
return type;
|
|
295
333
|
}
|
|
@@ -314,7 +352,7 @@ function mergeSchemas(obj1, obj2) {
|
|
|
314
352
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
315
353
|
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
316
354
|
}
|
|
317
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
355
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
318
356
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
319
357
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
320
358
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -322,19 +360,26 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
322
360
|
if (expandAllBranches) {
|
|
323
361
|
if (then && typeof then !== "boolean") {
|
|
324
362
|
schemas = schemas.concat(
|
|
325
|
-
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
|
|
363
|
+
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList)
|
|
326
364
|
);
|
|
327
365
|
}
|
|
328
366
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
329
367
|
schemas = schemas.concat(
|
|
330
|
-
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
|
|
368
|
+
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList)
|
|
331
369
|
);
|
|
332
370
|
}
|
|
333
371
|
} else {
|
|
334
372
|
const conditionalSchema = conditionValue ? then : otherwise;
|
|
335
373
|
if (conditionalSchema && typeof conditionalSchema !== "boolean") {
|
|
336
374
|
schemas = schemas.concat(
|
|
337
|
-
retrieveSchemaInternal(
|
|
375
|
+
retrieveSchemaInternal(
|
|
376
|
+
validator,
|
|
377
|
+
conditionalSchema,
|
|
378
|
+
rootSchema,
|
|
379
|
+
formData,
|
|
380
|
+
expandAllBranches,
|
|
381
|
+
recurseList
|
|
382
|
+
)
|
|
338
383
|
);
|
|
339
384
|
}
|
|
340
385
|
}
|
|
@@ -342,7 +387,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
342
387
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
343
388
|
}
|
|
344
389
|
return resolvedSchemas.flatMap(
|
|
345
|
-
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
|
|
390
|
+
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList)
|
|
346
391
|
);
|
|
347
392
|
}
|
|
348
393
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -359,40 +404,72 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
359
404
|
);
|
|
360
405
|
return allPermutations;
|
|
361
406
|
}
|
|
362
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
363
|
-
|
|
364
|
-
|
|
407
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
408
|
+
const updatedSchemas = resolveReference(
|
|
409
|
+
validator,
|
|
410
|
+
schema,
|
|
411
|
+
rootSchema,
|
|
412
|
+
expandAllBranches,
|
|
413
|
+
recurseList,
|
|
414
|
+
formData
|
|
415
|
+
);
|
|
416
|
+
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
417
|
+
return updatedSchemas;
|
|
365
418
|
}
|
|
366
419
|
if (DEPENDENCIES_KEY in schema) {
|
|
367
|
-
const resolvedSchemas = resolveDependencies(
|
|
420
|
+
const resolvedSchemas = resolveDependencies(
|
|
421
|
+
validator,
|
|
422
|
+
schema,
|
|
423
|
+
rootSchema,
|
|
424
|
+
expandAllBranches,
|
|
425
|
+
recurseList,
|
|
426
|
+
formData
|
|
427
|
+
);
|
|
368
428
|
return resolvedSchemas.flatMap((s) => {
|
|
369
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
429
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList);
|
|
370
430
|
});
|
|
371
431
|
}
|
|
372
432
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
373
433
|
const allOfSchemaElements = schema.allOf.map(
|
|
374
|
-
(allOfSubschema) => retrieveSchemaInternal(
|
|
434
|
+
(allOfSubschema) => retrieveSchemaInternal(
|
|
435
|
+
validator,
|
|
436
|
+
allOfSubschema,
|
|
437
|
+
rootSchema,
|
|
438
|
+
formData,
|
|
439
|
+
expandAllBranches,
|
|
440
|
+
recurseList
|
|
441
|
+
)
|
|
375
442
|
);
|
|
376
443
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
377
444
|
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
378
445
|
}
|
|
379
446
|
return [schema];
|
|
380
447
|
}
|
|
381
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
448
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
449
|
+
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
450
|
+
if (updatedSchema !== schema) {
|
|
451
|
+
return retrieveSchemaInternal(
|
|
452
|
+
validator,
|
|
453
|
+
updatedSchema,
|
|
454
|
+
rootSchema,
|
|
455
|
+
formData,
|
|
456
|
+
expandAllBranches,
|
|
457
|
+
recurseList
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
return [schema];
|
|
391
461
|
}
|
|
392
|
-
function resolveAllReferences(schema, rootSchema) {
|
|
462
|
+
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
463
|
+
if (!isObject(schema)) {
|
|
464
|
+
return schema;
|
|
465
|
+
}
|
|
393
466
|
let resolvedSchema = schema;
|
|
394
467
|
if (REF_KEY in resolvedSchema) {
|
|
395
468
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
469
|
+
if (recurseList.includes($ref)) {
|
|
470
|
+
return resolvedSchema;
|
|
471
|
+
}
|
|
472
|
+
recurseList.push($ref);
|
|
396
473
|
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
397
474
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
398
475
|
}
|
|
@@ -400,16 +477,19 @@ function resolveAllReferences(schema, rootSchema) {
|
|
|
400
477
|
const updatedProps = transform(
|
|
401
478
|
resolvedSchema[PROPERTIES_KEY],
|
|
402
479
|
(result, value, key) => {
|
|
403
|
-
result[key] = resolveAllReferences(value, rootSchema);
|
|
480
|
+
result[key] = resolveAllReferences(value, rootSchema, recurseList);
|
|
404
481
|
},
|
|
405
482
|
{}
|
|
406
483
|
);
|
|
407
484
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
408
485
|
}
|
|
409
486
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
410
|
-
resolvedSchema = {
|
|
487
|
+
resolvedSchema = {
|
|
488
|
+
...resolvedSchema,
|
|
489
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
490
|
+
};
|
|
411
491
|
}
|
|
412
|
-
return resolvedSchema;
|
|
492
|
+
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
413
493
|
}
|
|
414
494
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
415
495
|
const schema = {
|
|
@@ -426,7 +506,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
426
506
|
if (REF_KEY in schema.additionalProperties) {
|
|
427
507
|
additionalProperties = retrieveSchema(
|
|
428
508
|
validator,
|
|
429
|
-
{ $ref:
|
|
509
|
+
{ $ref: get4(schema.additionalProperties, [REF_KEY]) },
|
|
430
510
|
rootSchema,
|
|
431
511
|
formData
|
|
432
512
|
);
|
|
@@ -438,25 +518,39 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
438
518
|
...schema.additionalProperties
|
|
439
519
|
};
|
|
440
520
|
} else {
|
|
441
|
-
additionalProperties = { type: guessType(
|
|
521
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
442
522
|
}
|
|
443
523
|
} else {
|
|
444
|
-
additionalProperties = { type: guessType(
|
|
524
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
445
525
|
}
|
|
446
526
|
schema.properties[key] = additionalProperties;
|
|
447
527
|
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
448
528
|
});
|
|
449
529
|
return schema;
|
|
450
530
|
}
|
|
451
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
531
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
452
532
|
if (!isObject(schema)) {
|
|
453
533
|
return [{}];
|
|
454
534
|
}
|
|
455
|
-
const resolvedSchemas = resolveSchema(
|
|
535
|
+
const resolvedSchemas = resolveSchema(
|
|
536
|
+
validator,
|
|
537
|
+
schema,
|
|
538
|
+
rootSchema,
|
|
539
|
+
expandAllBranches,
|
|
540
|
+
recurseList,
|
|
541
|
+
rawFormData
|
|
542
|
+
);
|
|
456
543
|
return resolvedSchemas.flatMap((s) => {
|
|
457
544
|
let resolvedSchema = s;
|
|
458
545
|
if (IF_KEY in resolvedSchema) {
|
|
459
|
-
return resolveCondition(
|
|
546
|
+
return resolveCondition(
|
|
547
|
+
validator,
|
|
548
|
+
resolvedSchema,
|
|
549
|
+
rootSchema,
|
|
550
|
+
expandAllBranches,
|
|
551
|
+
recurseList,
|
|
552
|
+
rawFormData
|
|
553
|
+
);
|
|
460
554
|
}
|
|
461
555
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
462
556
|
if (expandAllBranches) {
|
|
@@ -480,7 +574,7 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
480
574
|
return resolvedSchema;
|
|
481
575
|
});
|
|
482
576
|
}
|
|
483
|
-
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
577
|
+
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData) {
|
|
484
578
|
let anyOrOneOf;
|
|
485
579
|
const { oneOf, anyOf, ...remaining } = schema;
|
|
486
580
|
if (Array.isArray(oneOf)) {
|
|
@@ -492,7 +586,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
492
586
|
const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
|
|
493
587
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
494
588
|
anyOrOneOf = anyOrOneOf.map((s) => {
|
|
495
|
-
return resolveAllReferences(s, rootSchema);
|
|
589
|
+
return resolveAllReferences(s, rootSchema, recurseList);
|
|
496
590
|
});
|
|
497
591
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
498
592
|
if (expandAllBranches) {
|
|
@@ -502,23 +596,32 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
502
596
|
}
|
|
503
597
|
return [schema];
|
|
504
598
|
}
|
|
505
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
599
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
506
600
|
const { dependencies, ...remainingSchema } = schema;
|
|
507
601
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
508
602
|
validator,
|
|
509
603
|
remainingSchema,
|
|
510
604
|
rootSchema,
|
|
511
605
|
expandAllBranches,
|
|
606
|
+
recurseList,
|
|
512
607
|
formData
|
|
513
608
|
);
|
|
514
609
|
return resolvedSchemas.flatMap(
|
|
515
|
-
(resolvedSchema) => processDependencies(
|
|
610
|
+
(resolvedSchema) => processDependencies(
|
|
611
|
+
validator,
|
|
612
|
+
dependencies,
|
|
613
|
+
resolvedSchema,
|
|
614
|
+
rootSchema,
|
|
615
|
+
expandAllBranches,
|
|
616
|
+
recurseList,
|
|
617
|
+
formData
|
|
618
|
+
)
|
|
516
619
|
);
|
|
517
620
|
}
|
|
518
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
621
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
519
622
|
let schemas = [resolvedSchema];
|
|
520
623
|
for (const dependencyKey in dependencies) {
|
|
521
|
-
if (!expandAllBranches &&
|
|
624
|
+
if (!expandAllBranches && get4(formData, [dependencyKey]) === void 0) {
|
|
522
625
|
continue;
|
|
523
626
|
}
|
|
524
627
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -538,11 +641,20 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
538
641
|
dependencyKey,
|
|
539
642
|
dependencyValue,
|
|
540
643
|
expandAllBranches,
|
|
644
|
+
recurseList,
|
|
541
645
|
formData
|
|
542
646
|
);
|
|
543
647
|
}
|
|
544
648
|
return schemas.flatMap(
|
|
545
|
-
(schema) => processDependencies(
|
|
649
|
+
(schema) => processDependencies(
|
|
650
|
+
validator,
|
|
651
|
+
remainingDependencies,
|
|
652
|
+
schema,
|
|
653
|
+
rootSchema,
|
|
654
|
+
expandAllBranches,
|
|
655
|
+
recurseList,
|
|
656
|
+
formData
|
|
657
|
+
)
|
|
546
658
|
);
|
|
547
659
|
}
|
|
548
660
|
return schemas;
|
|
@@ -554,13 +666,14 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
554
666
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
555
667
|
return { ...schema, required };
|
|
556
668
|
}
|
|
557
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
669
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
558
670
|
const dependentSchemas = retrieveSchemaInternal(
|
|
559
671
|
validator,
|
|
560
672
|
dependencyValue,
|
|
561
673
|
rootSchema,
|
|
562
674
|
formData,
|
|
563
|
-
expandAllBranches
|
|
675
|
+
expandAllBranches,
|
|
676
|
+
recurseList
|
|
564
677
|
);
|
|
565
678
|
return dependentSchemas.flatMap((dependent) => {
|
|
566
679
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -572,7 +685,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
572
685
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
573
686
|
return [subschema];
|
|
574
687
|
}
|
|
575
|
-
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
688
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
576
689
|
});
|
|
577
690
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
578
691
|
return allPermutations.flatMap(
|
|
@@ -583,12 +696,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
583
696
|
dependencyKey,
|
|
584
697
|
resolvedOneOf,
|
|
585
698
|
expandAllBranches,
|
|
699
|
+
recurseList,
|
|
586
700
|
formData
|
|
587
701
|
)
|
|
588
702
|
);
|
|
589
703
|
});
|
|
590
704
|
}
|
|
591
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
705
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
592
706
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
593
707
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
594
708
|
return false;
|
|
@@ -618,7 +732,8 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
618
732
|
dependentSchema,
|
|
619
733
|
rootSchema,
|
|
620
734
|
formData,
|
|
621
|
-
expandAllBranches
|
|
735
|
+
expandAllBranches,
|
|
736
|
+
recurseList
|
|
622
737
|
);
|
|
623
738
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
624
739
|
});
|
|
@@ -641,7 +756,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
641
756
|
totalScore += reduce(
|
|
642
757
|
schema.properties,
|
|
643
758
|
(score, value, key) => {
|
|
644
|
-
const formValue =
|
|
759
|
+
const formValue = get5(formData, key);
|
|
645
760
|
if (typeof value === "boolean") {
|
|
646
761
|
return score;
|
|
647
762
|
}
|
|
@@ -656,7 +771,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
656
771
|
validator,
|
|
657
772
|
rootSchema,
|
|
658
773
|
formValue,
|
|
659
|
-
|
|
774
|
+
get5(value, key2),
|
|
660
775
|
-1,
|
|
661
776
|
discriminator
|
|
662
777
|
);
|
|
@@ -685,8 +800,12 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
685
800
|
}
|
|
686
801
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
687
802
|
const resolvedOptions = options.map((option) => {
|
|
688
|
-
return resolveAllReferences(option, rootSchema);
|
|
803
|
+
return resolveAllReferences(option, rootSchema, []);
|
|
689
804
|
});
|
|
805
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
806
|
+
if (isNumber2(simpleDiscriminatorMatch)) {
|
|
807
|
+
return simpleDiscriminatorMatch;
|
|
808
|
+
}
|
|
690
809
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
691
810
|
const testOptions = [JUNK_OPTION, option];
|
|
692
811
|
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
@@ -727,7 +846,7 @@ function isFixedItems(schema) {
|
|
|
727
846
|
}
|
|
728
847
|
|
|
729
848
|
// src/mergeDefaultsWithFormData.ts
|
|
730
|
-
import
|
|
849
|
+
import get6 from "lodash/get";
|
|
731
850
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
732
851
|
if (Array.isArray(formData)) {
|
|
733
852
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
@@ -746,8 +865,8 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
746
865
|
const acc = Object.assign({}, defaults);
|
|
747
866
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
748
867
|
acc2[key] = mergeDefaultsWithFormData(
|
|
749
|
-
defaults ?
|
|
750
|
-
|
|
868
|
+
defaults ? get6(defaults, key) : {},
|
|
869
|
+
get6(formData, key),
|
|
751
870
|
mergeExtraArrayDefaults
|
|
752
871
|
);
|
|
753
872
|
return acc2;
|
|
@@ -868,7 +987,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
868
987
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
869
988
|
}
|
|
870
989
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
871
|
-
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
990
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData);
|
|
872
991
|
schemaToCompute = resolvedSchema[0];
|
|
873
992
|
} else if (isFixedItems(schema)) {
|
|
874
993
|
defaults = schema.items.map(
|
|
@@ -930,13 +1049,13 @@ function computeDefaults(validator, rawSchema, {
|
|
|
930
1049
|
switch (getSchemaType(schema)) {
|
|
931
1050
|
case "object": {
|
|
932
1051
|
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
933
|
-
const computedDefault = computeDefaults(validator,
|
|
1052
|
+
const computedDefault = computeDefaults(validator, get7(schema, [PROPERTIES_KEY, key]), {
|
|
934
1053
|
rootSchema,
|
|
935
1054
|
_recurseList,
|
|
936
1055
|
experimental_defaultFormStateBehavior,
|
|
937
1056
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
938
|
-
parentDefaults:
|
|
939
|
-
rawFormData:
|
|
1057
|
+
parentDefaults: get7(defaults, [key]),
|
|
1058
|
+
rawFormData: get7(formData, [key]),
|
|
940
1059
|
required: schema.required?.includes(key)
|
|
941
1060
|
});
|
|
942
1061
|
maybeAddDefaultToObject(
|
|
@@ -956,22 +1075,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
956
1075
|
if (isObject(defaults)) {
|
|
957
1076
|
Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
|
|
958
1077
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
formDataRequired.push(key);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
1078
|
+
const formDataRequired = [];
|
|
1079
|
+
Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
|
|
1080
|
+
keys.add(key);
|
|
1081
|
+
formDataRequired.push(key);
|
|
1082
|
+
});
|
|
967
1083
|
keys.forEach((key) => {
|
|
968
1084
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
969
1085
|
rootSchema,
|
|
970
1086
|
_recurseList,
|
|
971
1087
|
experimental_defaultFormStateBehavior,
|
|
972
1088
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
973
|
-
parentDefaults:
|
|
974
|
-
rawFormData:
|
|
1089
|
+
parentDefaults: get7(defaults, [key]),
|
|
1090
|
+
rawFormData: get7(formData, [key]),
|
|
975
1091
|
required: schema.required?.includes(key)
|
|
976
1092
|
});
|
|
977
1093
|
maybeAddDefaultToObject(
|
|
@@ -1012,7 +1128,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1012
1128
|
_recurseList,
|
|
1013
1129
|
experimental_defaultFormStateBehavior,
|
|
1014
1130
|
rawFormData: item,
|
|
1015
|
-
parentDefaults:
|
|
1131
|
+
parentDefaults: get7(defaults, [idx]),
|
|
1016
1132
|
required
|
|
1017
1133
|
});
|
|
1018
1134
|
});
|
|
@@ -1128,7 +1244,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1128
1244
|
}
|
|
1129
1245
|
|
|
1130
1246
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1131
|
-
import
|
|
1247
|
+
import get8 from "lodash/get";
|
|
1132
1248
|
import has3 from "lodash/has";
|
|
1133
1249
|
var NO_VALUE = Symbol("no Value");
|
|
1134
1250
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
@@ -1136,27 +1252,27 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1136
1252
|
if (has3(newSchema, PROPERTIES_KEY)) {
|
|
1137
1253
|
const removeOldSchemaData = {};
|
|
1138
1254
|
if (has3(oldSchema, PROPERTIES_KEY)) {
|
|
1139
|
-
const properties =
|
|
1255
|
+
const properties = get8(oldSchema, PROPERTIES_KEY, {});
|
|
1140
1256
|
Object.keys(properties).forEach((key) => {
|
|
1141
1257
|
if (has3(data, key)) {
|
|
1142
1258
|
removeOldSchemaData[key] = void 0;
|
|
1143
1259
|
}
|
|
1144
1260
|
});
|
|
1145
1261
|
}
|
|
1146
|
-
const keys = Object.keys(
|
|
1262
|
+
const keys = Object.keys(get8(newSchema, PROPERTIES_KEY, {}));
|
|
1147
1263
|
const nestedData = {};
|
|
1148
1264
|
keys.forEach((key) => {
|
|
1149
|
-
const formValue =
|
|
1150
|
-
let oldKeyedSchema =
|
|
1151
|
-
let newKeyedSchema =
|
|
1265
|
+
const formValue = get8(data, key);
|
|
1266
|
+
let oldKeyedSchema = get8(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1267
|
+
let newKeyedSchema = get8(newSchema, [PROPERTIES_KEY, key], {});
|
|
1152
1268
|
if (has3(oldKeyedSchema, REF_KEY)) {
|
|
1153
1269
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
1154
1270
|
}
|
|
1155
1271
|
if (has3(newKeyedSchema, REF_KEY)) {
|
|
1156
1272
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1157
1273
|
}
|
|
1158
|
-
const oldSchemaTypeForKey =
|
|
1159
|
-
const newSchemaTypeForKey =
|
|
1274
|
+
const oldSchemaTypeForKey = get8(oldKeyedSchema, "type");
|
|
1275
|
+
const newSchemaTypeForKey = get8(newKeyedSchema, "type");
|
|
1160
1276
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1161
1277
|
if (has3(removeOldSchemaData, key)) {
|
|
1162
1278
|
delete removeOldSchemaData[key];
|
|
@@ -1173,17 +1289,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1173
1289
|
nestedData[key] = itemData;
|
|
1174
1290
|
}
|
|
1175
1291
|
} else {
|
|
1176
|
-
const newOptionDefault =
|
|
1177
|
-
const oldOptionDefault =
|
|
1292
|
+
const newOptionDefault = get8(newKeyedSchema, "default", NO_VALUE);
|
|
1293
|
+
const oldOptionDefault = get8(oldKeyedSchema, "default", NO_VALUE);
|
|
1178
1294
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1179
1295
|
if (oldOptionDefault === formValue) {
|
|
1180
1296
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1181
|
-
} else if (
|
|
1297
|
+
} else if (get8(newKeyedSchema, "readOnly") === true) {
|
|
1182
1298
|
removeOldSchemaData[key] = void 0;
|
|
1183
1299
|
}
|
|
1184
1300
|
}
|
|
1185
|
-
const newOptionConst =
|
|
1186
|
-
const oldOptionConst =
|
|
1301
|
+
const newOptionConst = get8(newKeyedSchema, "const", NO_VALUE);
|
|
1302
|
+
const oldOptionConst = get8(oldKeyedSchema, "const", NO_VALUE);
|
|
1187
1303
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1188
1304
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1189
1305
|
}
|
|
@@ -1195,9 +1311,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1195
1311
|
...removeOldSchemaData,
|
|
1196
1312
|
...nestedData
|
|
1197
1313
|
};
|
|
1198
|
-
} else if (
|
|
1199
|
-
let oldSchemaItems =
|
|
1200
|
-
let newSchemaItems =
|
|
1314
|
+
} else if (get8(oldSchema, "type") === "array" && get8(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1315
|
+
let oldSchemaItems = get8(oldSchema, "items");
|
|
1316
|
+
let newSchemaItems = get8(newSchema, "items");
|
|
1201
1317
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1202
1318
|
if (has3(oldSchemaItems, REF_KEY)) {
|
|
1203
1319
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
@@ -1205,10 +1321,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1205
1321
|
if (has3(newSchemaItems, REF_KEY)) {
|
|
1206
1322
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1207
1323
|
}
|
|
1208
|
-
const oldSchemaType =
|
|
1209
|
-
const newSchemaType =
|
|
1324
|
+
const oldSchemaType = get8(oldSchemaItems, "type");
|
|
1325
|
+
const newSchemaType = get8(newSchemaItems, "type");
|
|
1210
1326
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1211
|
-
const maxItems =
|
|
1327
|
+
const maxItems = get8(newSchema, "maxItems", -1);
|
|
1212
1328
|
if (newSchemaType === "object") {
|
|
1213
1329
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1214
1330
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1235,12 +1351,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1235
1351
|
}
|
|
1236
1352
|
|
|
1237
1353
|
// src/schema/toIdSchema.ts
|
|
1238
|
-
import
|
|
1239
|
-
import
|
|
1354
|
+
import get9 from "lodash/get";
|
|
1355
|
+
import isEqual2 from "lodash/isEqual";
|
|
1240
1356
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1241
1357
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1242
1358
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1243
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1359
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual2(item, _schema));
|
|
1244
1360
|
if (sameSchemaIndex === -1) {
|
|
1245
1361
|
return toIdSchemaInternal(
|
|
1246
1362
|
validator,
|
|
@@ -1254,10 +1370,10 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1254
1370
|
);
|
|
1255
1371
|
}
|
|
1256
1372
|
}
|
|
1257
|
-
if (ITEMS_KEY in schema && !
|
|
1373
|
+
if (ITEMS_KEY in schema && !get9(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1258
1374
|
return toIdSchemaInternal(
|
|
1259
1375
|
validator,
|
|
1260
|
-
|
|
1376
|
+
get9(schema, ITEMS_KEY),
|
|
1261
1377
|
idPrefix,
|
|
1262
1378
|
idSeparator,
|
|
1263
1379
|
id,
|
|
@@ -1270,7 +1386,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1270
1386
|
const idSchema = { $id };
|
|
1271
1387
|
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1272
1388
|
for (const name in schema.properties) {
|
|
1273
|
-
const field =
|
|
1389
|
+
const field = get9(schema, [PROPERTIES_KEY, name]);
|
|
1274
1390
|
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1275
1391
|
idSchema[name] = toIdSchemaInternal(
|
|
1276
1392
|
validator,
|
|
@@ -1281,7 +1397,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1281
1397
|
rootSchema,
|
|
1282
1398
|
// It's possible that formData is not an object -- this can happen if an
|
|
1283
1399
|
// array item has just been added, but not populated with data yet
|
|
1284
|
-
|
|
1400
|
+
get9(formData, [name]),
|
|
1285
1401
|
_recurseList
|
|
1286
1402
|
);
|
|
1287
1403
|
}
|
|
@@ -1293,13 +1409,13 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1293
1409
|
}
|
|
1294
1410
|
|
|
1295
1411
|
// src/schema/toPathSchema.ts
|
|
1296
|
-
import
|
|
1297
|
-
import
|
|
1412
|
+
import get10 from "lodash/get";
|
|
1413
|
+
import isEqual3 from "lodash/isEqual";
|
|
1298
1414
|
import set2 from "lodash/set";
|
|
1299
1415
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1300
1416
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1301
1417
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1302
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1418
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual3(item, _schema));
|
|
1303
1419
|
if (sameSchemaIndex === -1) {
|
|
1304
1420
|
return toPathSchemaInternal(
|
|
1305
1421
|
validator,
|
|
@@ -1340,7 +1456,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1340
1456
|
});
|
|
1341
1457
|
} else if (PROPERTIES_KEY in schema) {
|
|
1342
1458
|
for (const property in schema.properties) {
|
|
1343
|
-
const field =
|
|
1459
|
+
const field = get10(schema, [PROPERTIES_KEY, property]);
|
|
1344
1460
|
pathSchema[property] = toPathSchemaInternal(
|
|
1345
1461
|
validator,
|
|
1346
1462
|
field,
|
|
@@ -1348,7 +1464,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1348
1464
|
rootSchema,
|
|
1349
1465
|
// It's possible that formData is not an object -- this can happen if an
|
|
1350
1466
|
// array item has just been added, but not populated with data yet
|
|
1351
|
-
|
|
1467
|
+
get10(formData, [property]),
|
|
1352
1468
|
_recurseList
|
|
1353
1469
|
);
|
|
1354
1470
|
}
|
|
@@ -1613,7 +1729,7 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1613
1729
|
}
|
|
1614
1730
|
|
|
1615
1731
|
// src/enumOptionsDeselectValue.ts
|
|
1616
|
-
import
|
|
1732
|
+
import isEqual4 from "lodash/isEqual";
|
|
1617
1733
|
|
|
1618
1734
|
// src/enumOptionsValueForIndex.ts
|
|
1619
1735
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
@@ -1629,18 +1745,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1629
1745
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1630
1746
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1631
1747
|
if (Array.isArray(selected)) {
|
|
1632
|
-
return selected.filter((v) => !
|
|
1748
|
+
return selected.filter((v) => !isEqual4(v, value));
|
|
1633
1749
|
}
|
|
1634
|
-
return
|
|
1750
|
+
return isEqual4(value, selected) ? void 0 : selected;
|
|
1635
1751
|
}
|
|
1636
1752
|
|
|
1637
1753
|
// src/enumOptionsIsSelected.ts
|
|
1638
|
-
import
|
|
1754
|
+
import isEqual5 from "lodash/isEqual";
|
|
1639
1755
|
function enumOptionsIsSelected(value, selected) {
|
|
1640
1756
|
if (Array.isArray(selected)) {
|
|
1641
|
-
return selected.some((sel) =>
|
|
1757
|
+
return selected.some((sel) => isEqual5(sel, value));
|
|
1642
1758
|
}
|
|
1643
|
-
return
|
|
1759
|
+
return isEqual5(selected, value);
|
|
1644
1760
|
}
|
|
1645
1761
|
|
|
1646
1762
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1667,7 +1783,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1667
1783
|
|
|
1668
1784
|
// src/ErrorSchemaBuilder.ts
|
|
1669
1785
|
import cloneDeep from "lodash/cloneDeep";
|
|
1670
|
-
import
|
|
1786
|
+
import get11 from "lodash/get";
|
|
1671
1787
|
import set3 from "lodash/set";
|
|
1672
1788
|
var ErrorSchemaBuilder = class {
|
|
1673
1789
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
@@ -1695,7 +1811,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1695
1811
|
*/
|
|
1696
1812
|
getOrCreateErrorBlock(pathOfError) {
|
|
1697
1813
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1698
|
-
let errorBlock = hasPath ?
|
|
1814
|
+
let errorBlock = hasPath ? get11(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1699
1815
|
if (!errorBlock && pathOfError) {
|
|
1700
1816
|
errorBlock = {};
|
|
1701
1817
|
set3(this.errorSchema, pathOfError, errorBlock);
|
|
@@ -1721,7 +1837,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1721
1837
|
*/
|
|
1722
1838
|
addErrors(errorOrList, pathOfError) {
|
|
1723
1839
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1724
|
-
let errorsList =
|
|
1840
|
+
let errorsList = get11(errorBlock, ERRORS_KEY);
|
|
1725
1841
|
if (!Array.isArray(errorsList)) {
|
|
1726
1842
|
errorsList = [];
|
|
1727
1843
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -1836,7 +1952,7 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
1836
1952
|
// src/getWidget.tsx
|
|
1837
1953
|
import { createElement } from "react";
|
|
1838
1954
|
import ReactIs from "react-is";
|
|
1839
|
-
import
|
|
1955
|
+
import get12 from "lodash/get";
|
|
1840
1956
|
import set4 from "lodash/set";
|
|
1841
1957
|
import { jsx } from "react/jsx-runtime";
|
|
1842
1958
|
var widgetMap = {
|
|
@@ -1892,7 +2008,7 @@ var widgetMap = {
|
|
|
1892
2008
|
}
|
|
1893
2009
|
};
|
|
1894
2010
|
function mergeWidgetOptions(AWidget) {
|
|
1895
|
-
let MergedWidget =
|
|
2011
|
+
let MergedWidget = get12(AWidget, "MergedWidget");
|
|
1896
2012
|
if (!MergedWidget) {
|
|
1897
2013
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
1898
2014
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2297,11 +2413,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2297
2413
|
|
|
2298
2414
|
// src/parser/schemaParser.ts
|
|
2299
2415
|
import forEach from "lodash/forEach";
|
|
2300
|
-
import
|
|
2416
|
+
import isEqual7 from "lodash/isEqual";
|
|
2301
2417
|
|
|
2302
2418
|
// src/parser/ParserValidator.ts
|
|
2303
|
-
import
|
|
2304
|
-
import
|
|
2419
|
+
import get13 from "lodash/get";
|
|
2420
|
+
import isEqual6 from "lodash/isEqual";
|
|
2305
2421
|
var ParserValidator = class {
|
|
2306
2422
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2307
2423
|
* first.
|
|
@@ -2322,12 +2438,12 @@ var ParserValidator = class {
|
|
|
2322
2438
|
* @param hash - The hash value at which to map the schema
|
|
2323
2439
|
*/
|
|
2324
2440
|
addSchema(schema, hash) {
|
|
2325
|
-
const key =
|
|
2441
|
+
const key = get13(schema, ID_KEY, hash);
|
|
2326
2442
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2327
2443
|
const existing = this.schemaMap[key];
|
|
2328
2444
|
if (!existing) {
|
|
2329
2445
|
this.schemaMap[key] = identifiedSchema;
|
|
2330
|
-
} else if (!
|
|
2446
|
+
} else if (!isEqual6(existing, identifiedSchema)) {
|
|
2331
2447
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2332
2448
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2333
2449
|
throw new Error(
|
|
@@ -2349,7 +2465,7 @@ var ParserValidator = class {
|
|
|
2349
2465
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2350
2466
|
*/
|
|
2351
2467
|
isValid(schema, _formData, rootSchema) {
|
|
2352
|
-
if (!
|
|
2468
|
+
if (!isEqual6(rootSchema, this.rootSchema)) {
|
|
2353
2469
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2354
2470
|
}
|
|
2355
2471
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2387,12 +2503,13 @@ var ParserValidator = class {
|
|
|
2387
2503
|
|
|
2388
2504
|
// src/parser/schemaParser.ts
|
|
2389
2505
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2390
|
-
const
|
|
2506
|
+
const recurseRefs = [];
|
|
2507
|
+
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true, recurseRefs);
|
|
2391
2508
|
schemas.forEach((schema2) => {
|
|
2392
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
2509
|
+
const sameSchemaIndex = recurseList.findIndex((item) => isEqual7(item, schema2));
|
|
2393
2510
|
if (sameSchemaIndex === -1) {
|
|
2394
2511
|
recurseList.push(schema2);
|
|
2395
|
-
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
2512
|
+
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true, recurseRefs);
|
|
2396
2513
|
allOptions.forEach((s) => {
|
|
2397
2514
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
2398
2515
|
forEach(schema2[PROPERTIES_KEY], (value) => {
|
|
@@ -2466,6 +2583,7 @@ export {
|
|
|
2466
2583
|
getFirstMatchingOption,
|
|
2467
2584
|
getInputProps,
|
|
2468
2585
|
getMatchingOption,
|
|
2586
|
+
getOptionMatchingSimpleDiscriminator,
|
|
2469
2587
|
getSchemaType,
|
|
2470
2588
|
getSubmitButtonOptions,
|
|
2471
2589
|
getTemplate,
|