@rjsf/utils 5.13.0 → 5.13.2
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 +238 -122
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +238 -122
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +218 -108
- 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/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 +23 -13
- package/lib/schema/retrieveSchema.js +65 -41
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +16 -16
- package/src/getOptionMatchingSimpleDiscriminator.ts +46 -0
- package/src/getSchemaType.ts +6 -2
- package/src/index.ts +2 -0
- 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 +146 -38
- package/src/types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -83,6 +83,7 @@ __export(src_exports, {
|
|
|
83
83
|
getFirstMatchingOption: () => getFirstMatchingOption,
|
|
84
84
|
getInputProps: () => getInputProps,
|
|
85
85
|
getMatchingOption: () => getMatchingOption,
|
|
86
|
+
getOptionMatchingSimpleDiscriminator: () => getOptionMatchingSimpleDiscriminator,
|
|
86
87
|
getSchemaType: () => getSchemaType,
|
|
87
88
|
getSubmitButtonOptions: () => getSubmitButtonOptions,
|
|
88
89
|
getTemplate: () => getTemplate,
|
|
@@ -271,7 +272,7 @@ function deepEquals(a, b) {
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
// src/schema/getDefaultFormState.ts
|
|
274
|
-
var
|
|
275
|
+
var import_get7 = __toESM(require("lodash/get"));
|
|
275
276
|
var import_isEmpty = __toESM(require("lodash/isEmpty"));
|
|
276
277
|
|
|
277
278
|
// src/findSchemaDefinition.ts
|
|
@@ -305,25 +306,58 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
305
306
|
}
|
|
306
307
|
|
|
307
308
|
// src/schema/getClosestMatchingOption.ts
|
|
308
|
-
var
|
|
309
|
+
var import_get5 = __toESM(require("lodash/get"));
|
|
309
310
|
var import_has2 = __toESM(require("lodash/has"));
|
|
311
|
+
var import_isNumber2 = __toESM(require("lodash/isNumber"));
|
|
310
312
|
var import_isObject5 = __toESM(require("lodash/isObject"));
|
|
311
313
|
var import_isString2 = __toESM(require("lodash/isString"));
|
|
312
314
|
var import_reduce = __toESM(require("lodash/reduce"));
|
|
313
315
|
var import_times2 = __toESM(require("lodash/times"));
|
|
314
316
|
|
|
315
317
|
// src/schema/getMatchingOption.ts
|
|
316
|
-
var
|
|
318
|
+
var import_get2 = __toESM(require("lodash/get"));
|
|
317
319
|
var import_has = __toESM(require("lodash/has"));
|
|
320
|
+
var import_isNumber = __toESM(require("lodash/isNumber"));
|
|
321
|
+
|
|
322
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
323
|
+
var import_get = __toESM(require("lodash/get"));
|
|
324
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
325
|
+
if (formData && discriminatorField) {
|
|
326
|
+
const value = (0, import_get.default)(formData, discriminatorField);
|
|
327
|
+
if (value === void 0) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
for (let i = 0; i < options.length; i++) {
|
|
331
|
+
const option = options[i];
|
|
332
|
+
const discriminator = (0, import_get.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
333
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (discriminator.const === value) {
|
|
337
|
+
return i;
|
|
338
|
+
}
|
|
339
|
+
if (discriminator.enum?.includes(value)) {
|
|
340
|
+
return i;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/schema/getMatchingOption.ts
|
|
318
348
|
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
319
349
|
if (formData === void 0) {
|
|
320
350
|
return 0;
|
|
321
351
|
}
|
|
352
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
353
|
+
if ((0, import_isNumber.default)(simpleDiscriminatorMatch)) {
|
|
354
|
+
return simpleDiscriminatorMatch;
|
|
355
|
+
}
|
|
322
356
|
for (let i = 0; i < options.length; i++) {
|
|
323
357
|
const option = options[i];
|
|
324
358
|
if (discriminatorField && (0, import_has.default)(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
325
|
-
const value = (0,
|
|
326
|
-
const discriminator = (0,
|
|
359
|
+
const value = (0, import_get2.default)(formData, discriminatorField);
|
|
360
|
+
const discriminator = (0, import_get2.default)(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
327
361
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
328
362
|
return i;
|
|
329
363
|
}
|
|
@@ -363,18 +397,19 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
363
397
|
}
|
|
364
398
|
|
|
365
399
|
// src/schema/retrieveSchema.ts
|
|
366
|
-
var
|
|
400
|
+
var import_get4 = __toESM(require("lodash/get"));
|
|
401
|
+
var import_isEqual = __toESM(require("lodash/isEqual"));
|
|
367
402
|
var import_set = __toESM(require("lodash/set"));
|
|
368
403
|
var import_times = __toESM(require("lodash/times"));
|
|
369
404
|
var import_transform = __toESM(require("lodash/transform"));
|
|
370
405
|
var import_json_schema_merge_allof = __toESM(require("json-schema-merge-allof"));
|
|
371
406
|
|
|
372
407
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
373
|
-
var
|
|
408
|
+
var import_get3 = __toESM(require("lodash/get"));
|
|
374
409
|
var import_isString = __toESM(require("lodash/isString"));
|
|
375
410
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
376
411
|
let discriminator;
|
|
377
|
-
const maybeString = (0,
|
|
412
|
+
const maybeString = (0, import_get3.default)(schema, "discriminator.propertyName", void 0);
|
|
378
413
|
if ((0, import_isString.default)(maybeString)) {
|
|
379
414
|
discriminator = maybeString;
|
|
380
415
|
} else if (maybeString !== void 0) {
|
|
@@ -421,8 +456,12 @@ function getSchemaType(schema) {
|
|
|
421
456
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
422
457
|
return "object";
|
|
423
458
|
}
|
|
424
|
-
if (Array.isArray(type)
|
|
425
|
-
|
|
459
|
+
if (Array.isArray(type)) {
|
|
460
|
+
if (type.length === 2 && type.includes("null")) {
|
|
461
|
+
type = type.find((type2) => type2 !== "null");
|
|
462
|
+
} else {
|
|
463
|
+
type = type[0];
|
|
464
|
+
}
|
|
426
465
|
}
|
|
427
466
|
return type;
|
|
428
467
|
}
|
|
@@ -447,7 +486,7 @@ function mergeSchemas(obj1, obj2) {
|
|
|
447
486
|
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
448
487
|
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
449
488
|
}
|
|
450
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
489
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
451
490
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
452
491
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
453
492
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -455,19 +494,26 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
455
494
|
if (expandAllBranches) {
|
|
456
495
|
if (then && typeof then !== "boolean") {
|
|
457
496
|
schemas = schemas.concat(
|
|
458
|
-
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)
|
|
497
|
+
retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList)
|
|
459
498
|
);
|
|
460
499
|
}
|
|
461
500
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
462
501
|
schemas = schemas.concat(
|
|
463
|
-
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)
|
|
502
|
+
retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList)
|
|
464
503
|
);
|
|
465
504
|
}
|
|
466
505
|
} else {
|
|
467
506
|
const conditionalSchema = conditionValue ? then : otherwise;
|
|
468
507
|
if (conditionalSchema && typeof conditionalSchema !== "boolean") {
|
|
469
508
|
schemas = schemas.concat(
|
|
470
|
-
retrieveSchemaInternal(
|
|
509
|
+
retrieveSchemaInternal(
|
|
510
|
+
validator,
|
|
511
|
+
conditionalSchema,
|
|
512
|
+
rootSchema,
|
|
513
|
+
formData,
|
|
514
|
+
expandAllBranches,
|
|
515
|
+
recurseList
|
|
516
|
+
)
|
|
471
517
|
);
|
|
472
518
|
}
|
|
473
519
|
}
|
|
@@ -475,7 +521,7 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
475
521
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
476
522
|
}
|
|
477
523
|
return resolvedSchemas.flatMap(
|
|
478
|
-
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)
|
|
524
|
+
(s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList)
|
|
479
525
|
);
|
|
480
526
|
}
|
|
481
527
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -492,40 +538,72 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
492
538
|
);
|
|
493
539
|
return allPermutations;
|
|
494
540
|
}
|
|
495
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
496
|
-
|
|
497
|
-
|
|
541
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
542
|
+
const updatedSchemas = resolveReference(
|
|
543
|
+
validator,
|
|
544
|
+
schema,
|
|
545
|
+
rootSchema,
|
|
546
|
+
expandAllBranches,
|
|
547
|
+
recurseList,
|
|
548
|
+
formData
|
|
549
|
+
);
|
|
550
|
+
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
551
|
+
return updatedSchemas;
|
|
498
552
|
}
|
|
499
553
|
if (DEPENDENCIES_KEY in schema) {
|
|
500
|
-
const resolvedSchemas = resolveDependencies(
|
|
554
|
+
const resolvedSchemas = resolveDependencies(
|
|
555
|
+
validator,
|
|
556
|
+
schema,
|
|
557
|
+
rootSchema,
|
|
558
|
+
expandAllBranches,
|
|
559
|
+
recurseList,
|
|
560
|
+
formData
|
|
561
|
+
);
|
|
501
562
|
return resolvedSchemas.flatMap((s) => {
|
|
502
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
563
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList);
|
|
503
564
|
});
|
|
504
565
|
}
|
|
505
566
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
506
567
|
const allOfSchemaElements = schema.allOf.map(
|
|
507
|
-
(allOfSubschema) => retrieveSchemaInternal(
|
|
568
|
+
(allOfSubschema) => retrieveSchemaInternal(
|
|
569
|
+
validator,
|
|
570
|
+
allOfSubschema,
|
|
571
|
+
rootSchema,
|
|
572
|
+
formData,
|
|
573
|
+
expandAllBranches,
|
|
574
|
+
recurseList
|
|
575
|
+
)
|
|
508
576
|
);
|
|
509
577
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
510
578
|
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
511
579
|
}
|
|
512
580
|
return [schema];
|
|
513
581
|
}
|
|
514
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
582
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
583
|
+
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
584
|
+
if (updatedSchema !== schema) {
|
|
585
|
+
return retrieveSchemaInternal(
|
|
586
|
+
validator,
|
|
587
|
+
updatedSchema,
|
|
588
|
+
rootSchema,
|
|
589
|
+
formData,
|
|
590
|
+
expandAllBranches,
|
|
591
|
+
recurseList
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
return [schema];
|
|
524
595
|
}
|
|
525
|
-
function resolveAllReferences(schema, rootSchema) {
|
|
596
|
+
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
597
|
+
if (!isObject(schema)) {
|
|
598
|
+
return schema;
|
|
599
|
+
}
|
|
526
600
|
let resolvedSchema = schema;
|
|
527
601
|
if (REF_KEY in resolvedSchema) {
|
|
528
602
|
const { $ref, ...localSchema } = resolvedSchema;
|
|
603
|
+
if (recurseList.includes($ref)) {
|
|
604
|
+
return resolvedSchema;
|
|
605
|
+
}
|
|
606
|
+
recurseList.push($ref);
|
|
529
607
|
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
530
608
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
531
609
|
}
|
|
@@ -533,16 +611,19 @@ function resolveAllReferences(schema, rootSchema) {
|
|
|
533
611
|
const updatedProps = (0, import_transform.default)(
|
|
534
612
|
resolvedSchema[PROPERTIES_KEY],
|
|
535
613
|
(result, value, key) => {
|
|
536
|
-
result[key] = resolveAllReferences(value, rootSchema);
|
|
614
|
+
result[key] = resolveAllReferences(value, rootSchema, recurseList);
|
|
537
615
|
},
|
|
538
616
|
{}
|
|
539
617
|
);
|
|
540
618
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
541
619
|
}
|
|
542
620
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
543
|
-
resolvedSchema = {
|
|
621
|
+
resolvedSchema = {
|
|
622
|
+
...resolvedSchema,
|
|
623
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
624
|
+
};
|
|
544
625
|
}
|
|
545
|
-
return resolvedSchema;
|
|
626
|
+
return (0, import_isEqual.default)(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
546
627
|
}
|
|
547
628
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
548
629
|
const schema = {
|
|
@@ -559,7 +640,7 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
559
640
|
if (REF_KEY in schema.additionalProperties) {
|
|
560
641
|
additionalProperties = retrieveSchema(
|
|
561
642
|
validator,
|
|
562
|
-
{ $ref: (0,
|
|
643
|
+
{ $ref: (0, import_get4.default)(schema.additionalProperties, [REF_KEY]) },
|
|
563
644
|
rootSchema,
|
|
564
645
|
formData
|
|
565
646
|
);
|
|
@@ -571,25 +652,39 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
571
652
|
...schema.additionalProperties
|
|
572
653
|
};
|
|
573
654
|
} else {
|
|
574
|
-
additionalProperties = { type: guessType((0,
|
|
655
|
+
additionalProperties = { type: guessType((0, import_get4.default)(formData, [key])) };
|
|
575
656
|
}
|
|
576
657
|
} else {
|
|
577
|
-
additionalProperties = { type: guessType((0,
|
|
658
|
+
additionalProperties = { type: guessType((0, import_get4.default)(formData, [key])) };
|
|
578
659
|
}
|
|
579
660
|
schema.properties[key] = additionalProperties;
|
|
580
661
|
(0, import_set.default)(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
581
662
|
});
|
|
582
663
|
return schema;
|
|
583
664
|
}
|
|
584
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
665
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
585
666
|
if (!isObject(schema)) {
|
|
586
667
|
return [{}];
|
|
587
668
|
}
|
|
588
|
-
const resolvedSchemas = resolveSchema(
|
|
669
|
+
const resolvedSchemas = resolveSchema(
|
|
670
|
+
validator,
|
|
671
|
+
schema,
|
|
672
|
+
rootSchema,
|
|
673
|
+
expandAllBranches,
|
|
674
|
+
recurseList,
|
|
675
|
+
rawFormData
|
|
676
|
+
);
|
|
589
677
|
return resolvedSchemas.flatMap((s) => {
|
|
590
678
|
let resolvedSchema = s;
|
|
591
679
|
if (IF_KEY in resolvedSchema) {
|
|
592
|
-
return resolveCondition(
|
|
680
|
+
return resolveCondition(
|
|
681
|
+
validator,
|
|
682
|
+
resolvedSchema,
|
|
683
|
+
rootSchema,
|
|
684
|
+
expandAllBranches,
|
|
685
|
+
recurseList,
|
|
686
|
+
rawFormData
|
|
687
|
+
);
|
|
593
688
|
}
|
|
594
689
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
595
690
|
if (expandAllBranches) {
|
|
@@ -625,7 +720,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
625
720
|
const formData = rawFormData === void 0 && expandAllBranches ? {} : rawFormData;
|
|
626
721
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
627
722
|
anyOrOneOf = anyOrOneOf.map((s) => {
|
|
628
|
-
return resolveAllReferences(s, rootSchema);
|
|
723
|
+
return resolveAllReferences(s, rootSchema, []);
|
|
629
724
|
});
|
|
630
725
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
631
726
|
if (expandAllBranches) {
|
|
@@ -635,7 +730,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
635
730
|
}
|
|
636
731
|
return [schema];
|
|
637
732
|
}
|
|
638
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
733
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
639
734
|
const { dependencies, ...remainingSchema } = schema;
|
|
640
735
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
641
736
|
validator,
|
|
@@ -645,13 +740,21 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, f
|
|
|
645
740
|
formData
|
|
646
741
|
);
|
|
647
742
|
return resolvedSchemas.flatMap(
|
|
648
|
-
(resolvedSchema) => processDependencies(
|
|
743
|
+
(resolvedSchema) => processDependencies(
|
|
744
|
+
validator,
|
|
745
|
+
dependencies,
|
|
746
|
+
resolvedSchema,
|
|
747
|
+
rootSchema,
|
|
748
|
+
expandAllBranches,
|
|
749
|
+
recurseList,
|
|
750
|
+
formData
|
|
751
|
+
)
|
|
649
752
|
);
|
|
650
753
|
}
|
|
651
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
754
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
652
755
|
let schemas = [resolvedSchema];
|
|
653
756
|
for (const dependencyKey in dependencies) {
|
|
654
|
-
if (!expandAllBranches && (0,
|
|
757
|
+
if (!expandAllBranches && (0, import_get4.default)(formData, [dependencyKey]) === void 0) {
|
|
655
758
|
continue;
|
|
656
759
|
}
|
|
657
760
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -671,11 +774,20 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
671
774
|
dependencyKey,
|
|
672
775
|
dependencyValue,
|
|
673
776
|
expandAllBranches,
|
|
777
|
+
recurseList,
|
|
674
778
|
formData
|
|
675
779
|
);
|
|
676
780
|
}
|
|
677
781
|
return schemas.flatMap(
|
|
678
|
-
(schema) => processDependencies(
|
|
782
|
+
(schema) => processDependencies(
|
|
783
|
+
validator,
|
|
784
|
+
remainingDependencies,
|
|
785
|
+
schema,
|
|
786
|
+
rootSchema,
|
|
787
|
+
expandAllBranches,
|
|
788
|
+
recurseList,
|
|
789
|
+
formData
|
|
790
|
+
)
|
|
679
791
|
);
|
|
680
792
|
}
|
|
681
793
|
return schemas;
|
|
@@ -687,13 +799,14 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
687
799
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
688
800
|
return { ...schema, required };
|
|
689
801
|
}
|
|
690
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
802
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
691
803
|
const dependentSchemas = retrieveSchemaInternal(
|
|
692
804
|
validator,
|
|
693
805
|
dependencyValue,
|
|
694
806
|
rootSchema,
|
|
695
807
|
formData,
|
|
696
|
-
expandAllBranches
|
|
808
|
+
expandAllBranches,
|
|
809
|
+
recurseList
|
|
697
810
|
);
|
|
698
811
|
return dependentSchemas.flatMap((dependent) => {
|
|
699
812
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -705,7 +818,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
705
818
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
706
819
|
return [subschema];
|
|
707
820
|
}
|
|
708
|
-
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
821
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
709
822
|
});
|
|
710
823
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
711
824
|
return allPermutations.flatMap(
|
|
@@ -716,12 +829,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
716
829
|
dependencyKey,
|
|
717
830
|
resolvedOneOf,
|
|
718
831
|
expandAllBranches,
|
|
832
|
+
recurseList,
|
|
719
833
|
formData
|
|
720
834
|
)
|
|
721
835
|
);
|
|
722
836
|
});
|
|
723
837
|
}
|
|
724
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
838
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
725
839
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
726
840
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
727
841
|
return false;
|
|
@@ -751,7 +865,8 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
751
865
|
dependentSchema,
|
|
752
866
|
rootSchema,
|
|
753
867
|
formData,
|
|
754
|
-
expandAllBranches
|
|
868
|
+
expandAllBranches,
|
|
869
|
+
recurseList
|
|
755
870
|
);
|
|
756
871
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
757
872
|
});
|
|
@@ -774,7 +889,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
774
889
|
totalScore += (0, import_reduce.default)(
|
|
775
890
|
schema.properties,
|
|
776
891
|
(score, value, key) => {
|
|
777
|
-
const formValue = (0,
|
|
892
|
+
const formValue = (0, import_get5.default)(formData, key);
|
|
778
893
|
if (typeof value === "boolean") {
|
|
779
894
|
return score;
|
|
780
895
|
}
|
|
@@ -789,7 +904,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
789
904
|
validator,
|
|
790
905
|
rootSchema,
|
|
791
906
|
formValue,
|
|
792
|
-
(0,
|
|
907
|
+
(0, import_get5.default)(value, key2),
|
|
793
908
|
-1,
|
|
794
909
|
discriminator
|
|
795
910
|
);
|
|
@@ -818,8 +933,12 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
818
933
|
}
|
|
819
934
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
820
935
|
const resolvedOptions = options.map((option) => {
|
|
821
|
-
return resolveAllReferences(option, rootSchema);
|
|
936
|
+
return resolveAllReferences(option, rootSchema, []);
|
|
822
937
|
});
|
|
938
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
939
|
+
if ((0, import_isNumber2.default)(simpleDiscriminatorMatch)) {
|
|
940
|
+
return simpleDiscriminatorMatch;
|
|
941
|
+
}
|
|
823
942
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
824
943
|
const testOptions = [JUNK_OPTION, option];
|
|
825
944
|
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
@@ -860,7 +979,7 @@ function isFixedItems(schema) {
|
|
|
860
979
|
}
|
|
861
980
|
|
|
862
981
|
// src/mergeDefaultsWithFormData.ts
|
|
863
|
-
var
|
|
982
|
+
var import_get6 = __toESM(require("lodash/get"));
|
|
864
983
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
865
984
|
if (Array.isArray(formData)) {
|
|
866
985
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
@@ -879,8 +998,8 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
879
998
|
const acc = Object.assign({}, defaults);
|
|
880
999
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
881
1000
|
acc2[key] = mergeDefaultsWithFormData(
|
|
882
|
-
defaults ? (0,
|
|
883
|
-
(0,
|
|
1001
|
+
defaults ? (0, import_get6.default)(defaults, key) : {},
|
|
1002
|
+
(0, import_get6.default)(formData, key),
|
|
884
1003
|
mergeExtraArrayDefaults
|
|
885
1004
|
);
|
|
886
1005
|
return acc2;
|
|
@@ -1001,7 +1120,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1001
1120
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1002
1121
|
}
|
|
1003
1122
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1004
|
-
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
1123
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData);
|
|
1005
1124
|
schemaToCompute = resolvedSchema[0];
|
|
1006
1125
|
} else if (isFixedItems(schema)) {
|
|
1007
1126
|
defaults = schema.items.map(
|
|
@@ -1063,13 +1182,13 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1063
1182
|
switch (getSchemaType(schema)) {
|
|
1064
1183
|
case "object": {
|
|
1065
1184
|
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
1066
|
-
const computedDefault = computeDefaults(validator, (0,
|
|
1185
|
+
const computedDefault = computeDefaults(validator, (0, import_get7.default)(schema, [PROPERTIES_KEY, key]), {
|
|
1067
1186
|
rootSchema,
|
|
1068
1187
|
_recurseList,
|
|
1069
1188
|
experimental_defaultFormStateBehavior,
|
|
1070
1189
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1071
|
-
parentDefaults: (0,
|
|
1072
|
-
rawFormData: (0,
|
|
1190
|
+
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1191
|
+
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1073
1192
|
required: schema.required?.includes(key)
|
|
1074
1193
|
});
|
|
1075
1194
|
maybeAddDefaultToObject(
|
|
@@ -1089,22 +1208,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1089
1208
|
if (isObject(defaults)) {
|
|
1090
1209
|
Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
|
|
1091
1210
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
formDataRequired.push(key);
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1211
|
+
const formDataRequired = [];
|
|
1212
|
+
Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
|
|
1213
|
+
keys.add(key);
|
|
1214
|
+
formDataRequired.push(key);
|
|
1215
|
+
});
|
|
1100
1216
|
keys.forEach((key) => {
|
|
1101
1217
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1102
1218
|
rootSchema,
|
|
1103
1219
|
_recurseList,
|
|
1104
1220
|
experimental_defaultFormStateBehavior,
|
|
1105
1221
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1106
|
-
parentDefaults: (0,
|
|
1107
|
-
rawFormData: (0,
|
|
1222
|
+
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1223
|
+
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1108
1224
|
required: schema.required?.includes(key)
|
|
1109
1225
|
});
|
|
1110
1226
|
maybeAddDefaultToObject(
|
|
@@ -1145,7 +1261,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1145
1261
|
_recurseList,
|
|
1146
1262
|
experimental_defaultFormStateBehavior,
|
|
1147
1263
|
rawFormData: item,
|
|
1148
|
-
parentDefaults: (0,
|
|
1264
|
+
parentDefaults: (0, import_get7.default)(defaults, [idx]),
|
|
1149
1265
|
required
|
|
1150
1266
|
});
|
|
1151
1267
|
});
|
|
@@ -1261,7 +1377,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1261
1377
|
}
|
|
1262
1378
|
|
|
1263
1379
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1264
|
-
var
|
|
1380
|
+
var import_get8 = __toESM(require("lodash/get"));
|
|
1265
1381
|
var import_has3 = __toESM(require("lodash/has"));
|
|
1266
1382
|
var NO_VALUE = Symbol("no Value");
|
|
1267
1383
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
@@ -1269,27 +1385,27 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1269
1385
|
if ((0, import_has3.default)(newSchema, PROPERTIES_KEY)) {
|
|
1270
1386
|
const removeOldSchemaData = {};
|
|
1271
1387
|
if ((0, import_has3.default)(oldSchema, PROPERTIES_KEY)) {
|
|
1272
|
-
const properties = (0,
|
|
1388
|
+
const properties = (0, import_get8.default)(oldSchema, PROPERTIES_KEY, {});
|
|
1273
1389
|
Object.keys(properties).forEach((key) => {
|
|
1274
1390
|
if ((0, import_has3.default)(data, key)) {
|
|
1275
1391
|
removeOldSchemaData[key] = void 0;
|
|
1276
1392
|
}
|
|
1277
1393
|
});
|
|
1278
1394
|
}
|
|
1279
|
-
const keys = Object.keys((0,
|
|
1395
|
+
const keys = Object.keys((0, import_get8.default)(newSchema, PROPERTIES_KEY, {}));
|
|
1280
1396
|
const nestedData = {};
|
|
1281
1397
|
keys.forEach((key) => {
|
|
1282
|
-
const formValue = (0,
|
|
1283
|
-
let oldKeyedSchema = (0,
|
|
1284
|
-
let newKeyedSchema = (0,
|
|
1398
|
+
const formValue = (0, import_get8.default)(data, key);
|
|
1399
|
+
let oldKeyedSchema = (0, import_get8.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1400
|
+
let newKeyedSchema = (0, import_get8.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1285
1401
|
if ((0, import_has3.default)(oldKeyedSchema, REF_KEY)) {
|
|
1286
1402
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
1287
1403
|
}
|
|
1288
1404
|
if ((0, import_has3.default)(newKeyedSchema, REF_KEY)) {
|
|
1289
1405
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1290
1406
|
}
|
|
1291
|
-
const oldSchemaTypeForKey = (0,
|
|
1292
|
-
const newSchemaTypeForKey = (0,
|
|
1407
|
+
const oldSchemaTypeForKey = (0, import_get8.default)(oldKeyedSchema, "type");
|
|
1408
|
+
const newSchemaTypeForKey = (0, import_get8.default)(newKeyedSchema, "type");
|
|
1293
1409
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1294
1410
|
if ((0, import_has3.default)(removeOldSchemaData, key)) {
|
|
1295
1411
|
delete removeOldSchemaData[key];
|
|
@@ -1306,17 +1422,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1306
1422
|
nestedData[key] = itemData;
|
|
1307
1423
|
}
|
|
1308
1424
|
} else {
|
|
1309
|
-
const newOptionDefault = (0,
|
|
1310
|
-
const oldOptionDefault = (0,
|
|
1425
|
+
const newOptionDefault = (0, import_get8.default)(newKeyedSchema, "default", NO_VALUE);
|
|
1426
|
+
const oldOptionDefault = (0, import_get8.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
1311
1427
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1312
1428
|
if (oldOptionDefault === formValue) {
|
|
1313
1429
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1314
|
-
} else if ((0,
|
|
1430
|
+
} else if ((0, import_get8.default)(newKeyedSchema, "readOnly") === true) {
|
|
1315
1431
|
removeOldSchemaData[key] = void 0;
|
|
1316
1432
|
}
|
|
1317
1433
|
}
|
|
1318
|
-
const newOptionConst = (0,
|
|
1319
|
-
const oldOptionConst = (0,
|
|
1434
|
+
const newOptionConst = (0, import_get8.default)(newKeyedSchema, "const", NO_VALUE);
|
|
1435
|
+
const oldOptionConst = (0, import_get8.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
1320
1436
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1321
1437
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1322
1438
|
}
|
|
@@ -1328,9 +1444,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1328
1444
|
...removeOldSchemaData,
|
|
1329
1445
|
...nestedData
|
|
1330
1446
|
};
|
|
1331
|
-
} else if ((0,
|
|
1332
|
-
let oldSchemaItems = (0,
|
|
1333
|
-
let newSchemaItems = (0,
|
|
1447
|
+
} else if ((0, import_get8.default)(oldSchema, "type") === "array" && (0, import_get8.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1448
|
+
let oldSchemaItems = (0, import_get8.default)(oldSchema, "items");
|
|
1449
|
+
let newSchemaItems = (0, import_get8.default)(newSchema, "items");
|
|
1334
1450
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1335
1451
|
if ((0, import_has3.default)(oldSchemaItems, REF_KEY)) {
|
|
1336
1452
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
@@ -1338,10 +1454,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1338
1454
|
if ((0, import_has3.default)(newSchemaItems, REF_KEY)) {
|
|
1339
1455
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1340
1456
|
}
|
|
1341
|
-
const oldSchemaType = (0,
|
|
1342
|
-
const newSchemaType = (0,
|
|
1457
|
+
const oldSchemaType = (0, import_get8.default)(oldSchemaItems, "type");
|
|
1458
|
+
const newSchemaType = (0, import_get8.default)(newSchemaItems, "type");
|
|
1343
1459
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1344
|
-
const maxItems = (0,
|
|
1460
|
+
const maxItems = (0, import_get8.default)(newSchema, "maxItems", -1);
|
|
1345
1461
|
if (newSchemaType === "object") {
|
|
1346
1462
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1347
1463
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1368,12 +1484,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1368
1484
|
}
|
|
1369
1485
|
|
|
1370
1486
|
// src/schema/toIdSchema.ts
|
|
1371
|
-
var
|
|
1372
|
-
var
|
|
1487
|
+
var import_get9 = __toESM(require("lodash/get"));
|
|
1488
|
+
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
1373
1489
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1374
1490
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1375
1491
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1376
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => (0,
|
|
1492
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual2.default)(item, _schema));
|
|
1377
1493
|
if (sameSchemaIndex === -1) {
|
|
1378
1494
|
return toIdSchemaInternal(
|
|
1379
1495
|
validator,
|
|
@@ -1387,10 +1503,10 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1387
1503
|
);
|
|
1388
1504
|
}
|
|
1389
1505
|
}
|
|
1390
|
-
if (ITEMS_KEY in schema && !(0,
|
|
1506
|
+
if (ITEMS_KEY in schema && !(0, import_get9.default)(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1391
1507
|
return toIdSchemaInternal(
|
|
1392
1508
|
validator,
|
|
1393
|
-
(0,
|
|
1509
|
+
(0, import_get9.default)(schema, ITEMS_KEY),
|
|
1394
1510
|
idPrefix,
|
|
1395
1511
|
idSeparator,
|
|
1396
1512
|
id,
|
|
@@ -1403,7 +1519,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1403
1519
|
const idSchema = { $id };
|
|
1404
1520
|
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1405
1521
|
for (const name in schema.properties) {
|
|
1406
|
-
const field = (0,
|
|
1522
|
+
const field = (0, import_get9.default)(schema, [PROPERTIES_KEY, name]);
|
|
1407
1523
|
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1408
1524
|
idSchema[name] = toIdSchemaInternal(
|
|
1409
1525
|
validator,
|
|
@@ -1414,7 +1530,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1414
1530
|
rootSchema,
|
|
1415
1531
|
// It's possible that formData is not an object -- this can happen if an
|
|
1416
1532
|
// array item has just been added, but not populated with data yet
|
|
1417
|
-
(0,
|
|
1533
|
+
(0, import_get9.default)(formData, [name]),
|
|
1418
1534
|
_recurseList
|
|
1419
1535
|
);
|
|
1420
1536
|
}
|
|
@@ -1426,13 +1542,13 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1426
1542
|
}
|
|
1427
1543
|
|
|
1428
1544
|
// src/schema/toPathSchema.ts
|
|
1429
|
-
var
|
|
1430
|
-
var
|
|
1545
|
+
var import_get10 = __toESM(require("lodash/get"));
|
|
1546
|
+
var import_isEqual3 = __toESM(require("lodash/isEqual"));
|
|
1431
1547
|
var import_set2 = __toESM(require("lodash/set"));
|
|
1432
1548
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1433
1549
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1434
1550
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1435
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => (0,
|
|
1551
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual3.default)(item, _schema));
|
|
1436
1552
|
if (sameSchemaIndex === -1) {
|
|
1437
1553
|
return toPathSchemaInternal(
|
|
1438
1554
|
validator,
|
|
@@ -1473,7 +1589,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1473
1589
|
});
|
|
1474
1590
|
} else if (PROPERTIES_KEY in schema) {
|
|
1475
1591
|
for (const property in schema.properties) {
|
|
1476
|
-
const field = (0,
|
|
1592
|
+
const field = (0, import_get10.default)(schema, [PROPERTIES_KEY, property]);
|
|
1477
1593
|
pathSchema[property] = toPathSchemaInternal(
|
|
1478
1594
|
validator,
|
|
1479
1595
|
field,
|
|
@@ -1481,7 +1597,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1481
1597
|
rootSchema,
|
|
1482
1598
|
// It's possible that formData is not an object -- this can happen if an
|
|
1483
1599
|
// array item has just been added, but not populated with data yet
|
|
1484
|
-
(0,
|
|
1600
|
+
(0, import_get10.default)(formData, [property]),
|
|
1485
1601
|
_recurseList
|
|
1486
1602
|
);
|
|
1487
1603
|
}
|
|
@@ -1746,7 +1862,7 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1746
1862
|
}
|
|
1747
1863
|
|
|
1748
1864
|
// src/enumOptionsDeselectValue.ts
|
|
1749
|
-
var
|
|
1865
|
+
var import_isEqual4 = __toESM(require("lodash/isEqual"));
|
|
1750
1866
|
|
|
1751
1867
|
// src/enumOptionsValueForIndex.ts
|
|
1752
1868
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
@@ -1762,18 +1878,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1762
1878
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1763
1879
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1764
1880
|
if (Array.isArray(selected)) {
|
|
1765
|
-
return selected.filter((v) => !(0,
|
|
1881
|
+
return selected.filter((v) => !(0, import_isEqual4.default)(v, value));
|
|
1766
1882
|
}
|
|
1767
|
-
return (0,
|
|
1883
|
+
return (0, import_isEqual4.default)(value, selected) ? void 0 : selected;
|
|
1768
1884
|
}
|
|
1769
1885
|
|
|
1770
1886
|
// src/enumOptionsIsSelected.ts
|
|
1771
|
-
var
|
|
1887
|
+
var import_isEqual5 = __toESM(require("lodash/isEqual"));
|
|
1772
1888
|
function enumOptionsIsSelected(value, selected) {
|
|
1773
1889
|
if (Array.isArray(selected)) {
|
|
1774
|
-
return selected.some((sel) => (0,
|
|
1890
|
+
return selected.some((sel) => (0, import_isEqual5.default)(sel, value));
|
|
1775
1891
|
}
|
|
1776
|
-
return (0,
|
|
1892
|
+
return (0, import_isEqual5.default)(selected, value);
|
|
1777
1893
|
}
|
|
1778
1894
|
|
|
1779
1895
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1800,7 +1916,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1800
1916
|
|
|
1801
1917
|
// src/ErrorSchemaBuilder.ts
|
|
1802
1918
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
1803
|
-
var
|
|
1919
|
+
var import_get11 = __toESM(require("lodash/get"));
|
|
1804
1920
|
var import_set3 = __toESM(require("lodash/set"));
|
|
1805
1921
|
var ErrorSchemaBuilder = class {
|
|
1806
1922
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
@@ -1828,7 +1944,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1828
1944
|
*/
|
|
1829
1945
|
getOrCreateErrorBlock(pathOfError) {
|
|
1830
1946
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1831
|
-
let errorBlock = hasPath ? (0,
|
|
1947
|
+
let errorBlock = hasPath ? (0, import_get11.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1832
1948
|
if (!errorBlock && pathOfError) {
|
|
1833
1949
|
errorBlock = {};
|
|
1834
1950
|
(0, import_set3.default)(this.errorSchema, pathOfError, errorBlock);
|
|
@@ -1854,7 +1970,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1854
1970
|
*/
|
|
1855
1971
|
addErrors(errorOrList, pathOfError) {
|
|
1856
1972
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1857
|
-
let errorsList = (0,
|
|
1973
|
+
let errorsList = (0, import_get11.default)(errorBlock, ERRORS_KEY);
|
|
1858
1974
|
if (!Array.isArray(errorsList)) {
|
|
1859
1975
|
errorsList = [];
|
|
1860
1976
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -1969,7 +2085,7 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
1969
2085
|
// src/getWidget.tsx
|
|
1970
2086
|
var import_react = require("react");
|
|
1971
2087
|
var import_react_is = __toESM(require("react-is"));
|
|
1972
|
-
var
|
|
2088
|
+
var import_get12 = __toESM(require("lodash/get"));
|
|
1973
2089
|
var import_set4 = __toESM(require("lodash/set"));
|
|
1974
2090
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1975
2091
|
var widgetMap = {
|
|
@@ -2025,7 +2141,7 @@ var widgetMap = {
|
|
|
2025
2141
|
}
|
|
2026
2142
|
};
|
|
2027
2143
|
function mergeWidgetOptions(AWidget) {
|
|
2028
|
-
let MergedWidget = (0,
|
|
2144
|
+
let MergedWidget = (0, import_get12.default)(AWidget, "MergedWidget");
|
|
2029
2145
|
if (!MergedWidget) {
|
|
2030
2146
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2031
2147
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2430,11 +2546,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2430
2546
|
|
|
2431
2547
|
// src/parser/schemaParser.ts
|
|
2432
2548
|
var import_forEach = __toESM(require("lodash/forEach"));
|
|
2433
|
-
var
|
|
2549
|
+
var import_isEqual7 = __toESM(require("lodash/isEqual"));
|
|
2434
2550
|
|
|
2435
2551
|
// src/parser/ParserValidator.ts
|
|
2436
|
-
var
|
|
2437
|
-
var
|
|
2552
|
+
var import_get13 = __toESM(require("lodash/get"));
|
|
2553
|
+
var import_isEqual6 = __toESM(require("lodash/isEqual"));
|
|
2438
2554
|
var ParserValidator = class {
|
|
2439
2555
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2440
2556
|
* first.
|
|
@@ -2455,12 +2571,12 @@ var ParserValidator = class {
|
|
|
2455
2571
|
* @param hash - The hash value at which to map the schema
|
|
2456
2572
|
*/
|
|
2457
2573
|
addSchema(schema, hash) {
|
|
2458
|
-
const key = (0,
|
|
2574
|
+
const key = (0, import_get13.default)(schema, ID_KEY, hash);
|
|
2459
2575
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2460
2576
|
const existing = this.schemaMap[key];
|
|
2461
2577
|
if (!existing) {
|
|
2462
2578
|
this.schemaMap[key] = identifiedSchema;
|
|
2463
|
-
} else if (!(0,
|
|
2579
|
+
} else if (!(0, import_isEqual6.default)(existing, identifiedSchema)) {
|
|
2464
2580
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2465
2581
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2466
2582
|
throw new Error(
|
|
@@ -2482,7 +2598,7 @@ var ParserValidator = class {
|
|
|
2482
2598
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2483
2599
|
*/
|
|
2484
2600
|
isValid(schema, _formData, rootSchema) {
|
|
2485
|
-
if (!(0,
|
|
2601
|
+
if (!(0, import_isEqual6.default)(rootSchema, this.rootSchema)) {
|
|
2486
2602
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2487
2603
|
}
|
|
2488
2604
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2522,7 +2638,7 @@ var ParserValidator = class {
|
|
|
2522
2638
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2523
2639
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2524
2640
|
schemas.forEach((schema2) => {
|
|
2525
|
-
const sameSchemaIndex = recurseList.findIndex((item) => (0,
|
|
2641
|
+
const sameSchemaIndex = recurseList.findIndex((item) => (0, import_isEqual7.default)(item, schema2));
|
|
2526
2642
|
if (sameSchemaIndex === -1) {
|
|
2527
2643
|
recurseList.push(schema2);
|
|
2528
2644
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|