@rjsf/utils 5.12.1 → 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/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) {
|
|
@@ -613,7 +708,7 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
613
708
|
return resolvedSchema;
|
|
614
709
|
});
|
|
615
710
|
}
|
|
616
|
-
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
711
|
+
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData) {
|
|
617
712
|
let anyOrOneOf;
|
|
618
713
|
const { oneOf, anyOf, ...remaining } = schema;
|
|
619
714
|
if (Array.isArray(oneOf)) {
|
|
@@ -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, recurseList);
|
|
629
724
|
});
|
|
630
725
|
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
631
726
|
if (expandAllBranches) {
|
|
@@ -635,23 +730,32 @@ 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,
|
|
642
737
|
remainingSchema,
|
|
643
738
|
rootSchema,
|
|
644
739
|
expandAllBranches,
|
|
740
|
+
recurseList,
|
|
645
741
|
formData
|
|
646
742
|
);
|
|
647
743
|
return resolvedSchemas.flatMap(
|
|
648
|
-
(resolvedSchema) => processDependencies(
|
|
744
|
+
(resolvedSchema) => processDependencies(
|
|
745
|
+
validator,
|
|
746
|
+
dependencies,
|
|
747
|
+
resolvedSchema,
|
|
748
|
+
rootSchema,
|
|
749
|
+
expandAllBranches,
|
|
750
|
+
recurseList,
|
|
751
|
+
formData
|
|
752
|
+
)
|
|
649
753
|
);
|
|
650
754
|
}
|
|
651
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
755
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
652
756
|
let schemas = [resolvedSchema];
|
|
653
757
|
for (const dependencyKey in dependencies) {
|
|
654
|
-
if (!expandAllBranches && (0,
|
|
758
|
+
if (!expandAllBranches && (0, import_get4.default)(formData, [dependencyKey]) === void 0) {
|
|
655
759
|
continue;
|
|
656
760
|
}
|
|
657
761
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -671,11 +775,20 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
671
775
|
dependencyKey,
|
|
672
776
|
dependencyValue,
|
|
673
777
|
expandAllBranches,
|
|
778
|
+
recurseList,
|
|
674
779
|
formData
|
|
675
780
|
);
|
|
676
781
|
}
|
|
677
782
|
return schemas.flatMap(
|
|
678
|
-
(schema) => processDependencies(
|
|
783
|
+
(schema) => processDependencies(
|
|
784
|
+
validator,
|
|
785
|
+
remainingDependencies,
|
|
786
|
+
schema,
|
|
787
|
+
rootSchema,
|
|
788
|
+
expandAllBranches,
|
|
789
|
+
recurseList,
|
|
790
|
+
formData
|
|
791
|
+
)
|
|
679
792
|
);
|
|
680
793
|
}
|
|
681
794
|
return schemas;
|
|
@@ -687,13 +800,14 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
687
800
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
688
801
|
return { ...schema, required };
|
|
689
802
|
}
|
|
690
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
803
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
691
804
|
const dependentSchemas = retrieveSchemaInternal(
|
|
692
805
|
validator,
|
|
693
806
|
dependencyValue,
|
|
694
807
|
rootSchema,
|
|
695
808
|
formData,
|
|
696
|
-
expandAllBranches
|
|
809
|
+
expandAllBranches,
|
|
810
|
+
recurseList
|
|
697
811
|
);
|
|
698
812
|
return dependentSchemas.flatMap((dependent) => {
|
|
699
813
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -705,7 +819,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
705
819
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
706
820
|
return [subschema];
|
|
707
821
|
}
|
|
708
|
-
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
822
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData);
|
|
709
823
|
});
|
|
710
824
|
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
711
825
|
return allPermutations.flatMap(
|
|
@@ -716,12 +830,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
716
830
|
dependencyKey,
|
|
717
831
|
resolvedOneOf,
|
|
718
832
|
expandAllBranches,
|
|
833
|
+
recurseList,
|
|
719
834
|
formData
|
|
720
835
|
)
|
|
721
836
|
);
|
|
722
837
|
});
|
|
723
838
|
}
|
|
724
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
839
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
725
840
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
726
841
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
727
842
|
return false;
|
|
@@ -751,7 +866,8 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
751
866
|
dependentSchema,
|
|
752
867
|
rootSchema,
|
|
753
868
|
formData,
|
|
754
|
-
expandAllBranches
|
|
869
|
+
expandAllBranches,
|
|
870
|
+
recurseList
|
|
755
871
|
);
|
|
756
872
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
757
873
|
});
|
|
@@ -774,7 +890,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
774
890
|
totalScore += (0, import_reduce.default)(
|
|
775
891
|
schema.properties,
|
|
776
892
|
(score, value, key) => {
|
|
777
|
-
const formValue = (0,
|
|
893
|
+
const formValue = (0, import_get5.default)(formData, key);
|
|
778
894
|
if (typeof value === "boolean") {
|
|
779
895
|
return score;
|
|
780
896
|
}
|
|
@@ -789,7 +905,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
789
905
|
validator,
|
|
790
906
|
rootSchema,
|
|
791
907
|
formValue,
|
|
792
|
-
(0,
|
|
908
|
+
(0, import_get5.default)(value, key2),
|
|
793
909
|
-1,
|
|
794
910
|
discriminator
|
|
795
911
|
);
|
|
@@ -818,8 +934,12 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
818
934
|
}
|
|
819
935
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
820
936
|
const resolvedOptions = options.map((option) => {
|
|
821
|
-
return resolveAllReferences(option, rootSchema);
|
|
937
|
+
return resolveAllReferences(option, rootSchema, []);
|
|
822
938
|
});
|
|
939
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
940
|
+
if ((0, import_isNumber2.default)(simpleDiscriminatorMatch)) {
|
|
941
|
+
return simpleDiscriminatorMatch;
|
|
942
|
+
}
|
|
823
943
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
824
944
|
const testOptions = [JUNK_OPTION, option];
|
|
825
945
|
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
@@ -860,7 +980,7 @@ function isFixedItems(schema) {
|
|
|
860
980
|
}
|
|
861
981
|
|
|
862
982
|
// src/mergeDefaultsWithFormData.ts
|
|
863
|
-
var
|
|
983
|
+
var import_get6 = __toESM(require("lodash/get"));
|
|
864
984
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
865
985
|
if (Array.isArray(formData)) {
|
|
866
986
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
@@ -879,8 +999,8 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
879
999
|
const acc = Object.assign({}, defaults);
|
|
880
1000
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
881
1001
|
acc2[key] = mergeDefaultsWithFormData(
|
|
882
|
-
defaults ? (0,
|
|
883
|
-
(0,
|
|
1002
|
+
defaults ? (0, import_get6.default)(defaults, key) : {},
|
|
1003
|
+
(0, import_get6.default)(formData, key),
|
|
884
1004
|
mergeExtraArrayDefaults
|
|
885
1005
|
);
|
|
886
1006
|
return acc2;
|
|
@@ -1001,7 +1121,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1001
1121
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1002
1122
|
}
|
|
1003
1123
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1004
|
-
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
1124
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData);
|
|
1005
1125
|
schemaToCompute = resolvedSchema[0];
|
|
1006
1126
|
} else if (isFixedItems(schema)) {
|
|
1007
1127
|
defaults = schema.items.map(
|
|
@@ -1063,13 +1183,13 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1063
1183
|
switch (getSchemaType(schema)) {
|
|
1064
1184
|
case "object": {
|
|
1065
1185
|
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
1066
|
-
const computedDefault = computeDefaults(validator, (0,
|
|
1186
|
+
const computedDefault = computeDefaults(validator, (0, import_get7.default)(schema, [PROPERTIES_KEY, key]), {
|
|
1067
1187
|
rootSchema,
|
|
1068
1188
|
_recurseList,
|
|
1069
1189
|
experimental_defaultFormStateBehavior,
|
|
1070
1190
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1071
|
-
parentDefaults: (0,
|
|
1072
|
-
rawFormData: (0,
|
|
1191
|
+
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1192
|
+
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1073
1193
|
required: schema.required?.includes(key)
|
|
1074
1194
|
});
|
|
1075
1195
|
maybeAddDefaultToObject(
|
|
@@ -1089,22 +1209,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1089
1209
|
if (isObject(defaults)) {
|
|
1090
1210
|
Object.keys(defaults).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => keys.add(key));
|
|
1091
1211
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
formDataRequired.push(key);
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1212
|
+
const formDataRequired = [];
|
|
1213
|
+
Object.keys(formData).filter((key) => !schema.properties || !schema.properties[key]).forEach((key) => {
|
|
1214
|
+
keys.add(key);
|
|
1215
|
+
formDataRequired.push(key);
|
|
1216
|
+
});
|
|
1100
1217
|
keys.forEach((key) => {
|
|
1101
1218
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1102
1219
|
rootSchema,
|
|
1103
1220
|
_recurseList,
|
|
1104
1221
|
experimental_defaultFormStateBehavior,
|
|
1105
1222
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1106
|
-
parentDefaults: (0,
|
|
1107
|
-
rawFormData: (0,
|
|
1223
|
+
parentDefaults: (0, import_get7.default)(defaults, [key]),
|
|
1224
|
+
rawFormData: (0, import_get7.default)(formData, [key]),
|
|
1108
1225
|
required: schema.required?.includes(key)
|
|
1109
1226
|
});
|
|
1110
1227
|
maybeAddDefaultToObject(
|
|
@@ -1145,7 +1262,7 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1145
1262
|
_recurseList,
|
|
1146
1263
|
experimental_defaultFormStateBehavior,
|
|
1147
1264
|
rawFormData: item,
|
|
1148
|
-
parentDefaults: (0,
|
|
1265
|
+
parentDefaults: (0, import_get7.default)(defaults, [idx]),
|
|
1149
1266
|
required
|
|
1150
1267
|
});
|
|
1151
1268
|
});
|
|
@@ -1261,7 +1378,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1261
1378
|
}
|
|
1262
1379
|
|
|
1263
1380
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1264
|
-
var
|
|
1381
|
+
var import_get8 = __toESM(require("lodash/get"));
|
|
1265
1382
|
var import_has3 = __toESM(require("lodash/has"));
|
|
1266
1383
|
var NO_VALUE = Symbol("no Value");
|
|
1267
1384
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
@@ -1269,27 +1386,27 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1269
1386
|
if ((0, import_has3.default)(newSchema, PROPERTIES_KEY)) {
|
|
1270
1387
|
const removeOldSchemaData = {};
|
|
1271
1388
|
if ((0, import_has3.default)(oldSchema, PROPERTIES_KEY)) {
|
|
1272
|
-
const properties = (0,
|
|
1389
|
+
const properties = (0, import_get8.default)(oldSchema, PROPERTIES_KEY, {});
|
|
1273
1390
|
Object.keys(properties).forEach((key) => {
|
|
1274
1391
|
if ((0, import_has3.default)(data, key)) {
|
|
1275
1392
|
removeOldSchemaData[key] = void 0;
|
|
1276
1393
|
}
|
|
1277
1394
|
});
|
|
1278
1395
|
}
|
|
1279
|
-
const keys = Object.keys((0,
|
|
1396
|
+
const keys = Object.keys((0, import_get8.default)(newSchema, PROPERTIES_KEY, {}));
|
|
1280
1397
|
const nestedData = {};
|
|
1281
1398
|
keys.forEach((key) => {
|
|
1282
|
-
const formValue = (0,
|
|
1283
|
-
let oldKeyedSchema = (0,
|
|
1284
|
-
let newKeyedSchema = (0,
|
|
1399
|
+
const formValue = (0, import_get8.default)(data, key);
|
|
1400
|
+
let oldKeyedSchema = (0, import_get8.default)(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1401
|
+
let newKeyedSchema = (0, import_get8.default)(newSchema, [PROPERTIES_KEY, key], {});
|
|
1285
1402
|
if ((0, import_has3.default)(oldKeyedSchema, REF_KEY)) {
|
|
1286
1403
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
1287
1404
|
}
|
|
1288
1405
|
if ((0, import_has3.default)(newKeyedSchema, REF_KEY)) {
|
|
1289
1406
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1290
1407
|
}
|
|
1291
|
-
const oldSchemaTypeForKey = (0,
|
|
1292
|
-
const newSchemaTypeForKey = (0,
|
|
1408
|
+
const oldSchemaTypeForKey = (0, import_get8.default)(oldKeyedSchema, "type");
|
|
1409
|
+
const newSchemaTypeForKey = (0, import_get8.default)(newKeyedSchema, "type");
|
|
1293
1410
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1294
1411
|
if ((0, import_has3.default)(removeOldSchemaData, key)) {
|
|
1295
1412
|
delete removeOldSchemaData[key];
|
|
@@ -1306,17 +1423,17 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1306
1423
|
nestedData[key] = itemData;
|
|
1307
1424
|
}
|
|
1308
1425
|
} else {
|
|
1309
|
-
const newOptionDefault = (0,
|
|
1310
|
-
const oldOptionDefault = (0,
|
|
1426
|
+
const newOptionDefault = (0, import_get8.default)(newKeyedSchema, "default", NO_VALUE);
|
|
1427
|
+
const oldOptionDefault = (0, import_get8.default)(oldKeyedSchema, "default", NO_VALUE);
|
|
1311
1428
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1312
1429
|
if (oldOptionDefault === formValue) {
|
|
1313
1430
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1314
|
-
} else if ((0,
|
|
1431
|
+
} else if ((0, import_get8.default)(newKeyedSchema, "readOnly") === true) {
|
|
1315
1432
|
removeOldSchemaData[key] = void 0;
|
|
1316
1433
|
}
|
|
1317
1434
|
}
|
|
1318
|
-
const newOptionConst = (0,
|
|
1319
|
-
const oldOptionConst = (0,
|
|
1435
|
+
const newOptionConst = (0, import_get8.default)(newKeyedSchema, "const", NO_VALUE);
|
|
1436
|
+
const oldOptionConst = (0, import_get8.default)(oldKeyedSchema, "const", NO_VALUE);
|
|
1320
1437
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1321
1438
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1322
1439
|
}
|
|
@@ -1328,9 +1445,9 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1328
1445
|
...removeOldSchemaData,
|
|
1329
1446
|
...nestedData
|
|
1330
1447
|
};
|
|
1331
|
-
} else if ((0,
|
|
1332
|
-
let oldSchemaItems = (0,
|
|
1333
|
-
let newSchemaItems = (0,
|
|
1448
|
+
} else if ((0, import_get8.default)(oldSchema, "type") === "array" && (0, import_get8.default)(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1449
|
+
let oldSchemaItems = (0, import_get8.default)(oldSchema, "items");
|
|
1450
|
+
let newSchemaItems = (0, import_get8.default)(newSchema, "items");
|
|
1334
1451
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1335
1452
|
if ((0, import_has3.default)(oldSchemaItems, REF_KEY)) {
|
|
1336
1453
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
@@ -1338,10 +1455,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1338
1455
|
if ((0, import_has3.default)(newSchemaItems, REF_KEY)) {
|
|
1339
1456
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1340
1457
|
}
|
|
1341
|
-
const oldSchemaType = (0,
|
|
1342
|
-
const newSchemaType = (0,
|
|
1458
|
+
const oldSchemaType = (0, import_get8.default)(oldSchemaItems, "type");
|
|
1459
|
+
const newSchemaType = (0, import_get8.default)(newSchemaItems, "type");
|
|
1343
1460
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1344
|
-
const maxItems = (0,
|
|
1461
|
+
const maxItems = (0, import_get8.default)(newSchema, "maxItems", -1);
|
|
1345
1462
|
if (newSchemaType === "object") {
|
|
1346
1463
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1347
1464
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1368,12 +1485,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1368
1485
|
}
|
|
1369
1486
|
|
|
1370
1487
|
// src/schema/toIdSchema.ts
|
|
1371
|
-
var
|
|
1372
|
-
var
|
|
1488
|
+
var import_get9 = __toESM(require("lodash/get"));
|
|
1489
|
+
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
1373
1490
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1374
1491
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1375
1492
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1376
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => (0,
|
|
1493
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual2.default)(item, _schema));
|
|
1377
1494
|
if (sameSchemaIndex === -1) {
|
|
1378
1495
|
return toIdSchemaInternal(
|
|
1379
1496
|
validator,
|
|
@@ -1387,10 +1504,10 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1387
1504
|
);
|
|
1388
1505
|
}
|
|
1389
1506
|
}
|
|
1390
|
-
if (ITEMS_KEY in schema && !(0,
|
|
1507
|
+
if (ITEMS_KEY in schema && !(0, import_get9.default)(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1391
1508
|
return toIdSchemaInternal(
|
|
1392
1509
|
validator,
|
|
1393
|
-
(0,
|
|
1510
|
+
(0, import_get9.default)(schema, ITEMS_KEY),
|
|
1394
1511
|
idPrefix,
|
|
1395
1512
|
idSeparator,
|
|
1396
1513
|
id,
|
|
@@ -1403,7 +1520,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1403
1520
|
const idSchema = { $id };
|
|
1404
1521
|
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1405
1522
|
for (const name in schema.properties) {
|
|
1406
|
-
const field = (0,
|
|
1523
|
+
const field = (0, import_get9.default)(schema, [PROPERTIES_KEY, name]);
|
|
1407
1524
|
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1408
1525
|
idSchema[name] = toIdSchemaInternal(
|
|
1409
1526
|
validator,
|
|
@@ -1414,7 +1531,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1414
1531
|
rootSchema,
|
|
1415
1532
|
// It's possible that formData is not an object -- this can happen if an
|
|
1416
1533
|
// array item has just been added, but not populated with data yet
|
|
1417
|
-
(0,
|
|
1534
|
+
(0, import_get9.default)(formData, [name]),
|
|
1418
1535
|
_recurseList
|
|
1419
1536
|
);
|
|
1420
1537
|
}
|
|
@@ -1426,13 +1543,13 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1426
1543
|
}
|
|
1427
1544
|
|
|
1428
1545
|
// src/schema/toPathSchema.ts
|
|
1429
|
-
var
|
|
1430
|
-
var
|
|
1546
|
+
var import_get10 = __toESM(require("lodash/get"));
|
|
1547
|
+
var import_isEqual3 = __toESM(require("lodash/isEqual"));
|
|
1431
1548
|
var import_set2 = __toESM(require("lodash/set"));
|
|
1432
1549
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1433
1550
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1434
1551
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1435
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => (0,
|
|
1552
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual3.default)(item, _schema));
|
|
1436
1553
|
if (sameSchemaIndex === -1) {
|
|
1437
1554
|
return toPathSchemaInternal(
|
|
1438
1555
|
validator,
|
|
@@ -1473,7 +1590,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1473
1590
|
});
|
|
1474
1591
|
} else if (PROPERTIES_KEY in schema) {
|
|
1475
1592
|
for (const property in schema.properties) {
|
|
1476
|
-
const field = (0,
|
|
1593
|
+
const field = (0, import_get10.default)(schema, [PROPERTIES_KEY, property]);
|
|
1477
1594
|
pathSchema[property] = toPathSchemaInternal(
|
|
1478
1595
|
validator,
|
|
1479
1596
|
field,
|
|
@@ -1481,7 +1598,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1481
1598
|
rootSchema,
|
|
1482
1599
|
// It's possible that formData is not an object -- this can happen if an
|
|
1483
1600
|
// array item has just been added, but not populated with data yet
|
|
1484
|
-
(0,
|
|
1601
|
+
(0, import_get10.default)(formData, [property]),
|
|
1485
1602
|
_recurseList
|
|
1486
1603
|
);
|
|
1487
1604
|
}
|
|
@@ -1746,7 +1863,7 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1746
1863
|
}
|
|
1747
1864
|
|
|
1748
1865
|
// src/enumOptionsDeselectValue.ts
|
|
1749
|
-
var
|
|
1866
|
+
var import_isEqual4 = __toESM(require("lodash/isEqual"));
|
|
1750
1867
|
|
|
1751
1868
|
// src/enumOptionsValueForIndex.ts
|
|
1752
1869
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
@@ -1762,18 +1879,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1762
1879
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1763
1880
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1764
1881
|
if (Array.isArray(selected)) {
|
|
1765
|
-
return selected.filter((v) => !(0,
|
|
1882
|
+
return selected.filter((v) => !(0, import_isEqual4.default)(v, value));
|
|
1766
1883
|
}
|
|
1767
|
-
return (0,
|
|
1884
|
+
return (0, import_isEqual4.default)(value, selected) ? void 0 : selected;
|
|
1768
1885
|
}
|
|
1769
1886
|
|
|
1770
1887
|
// src/enumOptionsIsSelected.ts
|
|
1771
|
-
var
|
|
1888
|
+
var import_isEqual5 = __toESM(require("lodash/isEqual"));
|
|
1772
1889
|
function enumOptionsIsSelected(value, selected) {
|
|
1773
1890
|
if (Array.isArray(selected)) {
|
|
1774
|
-
return selected.some((sel) => (0,
|
|
1891
|
+
return selected.some((sel) => (0, import_isEqual5.default)(sel, value));
|
|
1775
1892
|
}
|
|
1776
|
-
return (0,
|
|
1893
|
+
return (0, import_isEqual5.default)(selected, value);
|
|
1777
1894
|
}
|
|
1778
1895
|
|
|
1779
1896
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1800,7 +1917,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1800
1917
|
|
|
1801
1918
|
// src/ErrorSchemaBuilder.ts
|
|
1802
1919
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
1803
|
-
var
|
|
1920
|
+
var import_get11 = __toESM(require("lodash/get"));
|
|
1804
1921
|
var import_set3 = __toESM(require("lodash/set"));
|
|
1805
1922
|
var ErrorSchemaBuilder = class {
|
|
1806
1923
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
@@ -1828,7 +1945,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1828
1945
|
*/
|
|
1829
1946
|
getOrCreateErrorBlock(pathOfError) {
|
|
1830
1947
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1831
|
-
let errorBlock = hasPath ? (0,
|
|
1948
|
+
let errorBlock = hasPath ? (0, import_get11.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1832
1949
|
if (!errorBlock && pathOfError) {
|
|
1833
1950
|
errorBlock = {};
|
|
1834
1951
|
(0, import_set3.default)(this.errorSchema, pathOfError, errorBlock);
|
|
@@ -1854,7 +1971,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1854
1971
|
*/
|
|
1855
1972
|
addErrors(errorOrList, pathOfError) {
|
|
1856
1973
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1857
|
-
let errorsList = (0,
|
|
1974
|
+
let errorsList = (0, import_get11.default)(errorBlock, ERRORS_KEY);
|
|
1858
1975
|
if (!Array.isArray(errorsList)) {
|
|
1859
1976
|
errorsList = [];
|
|
1860
1977
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
@@ -1969,7 +2086,7 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
1969
2086
|
// src/getWidget.tsx
|
|
1970
2087
|
var import_react = require("react");
|
|
1971
2088
|
var import_react_is = __toESM(require("react-is"));
|
|
1972
|
-
var
|
|
2089
|
+
var import_get12 = __toESM(require("lodash/get"));
|
|
1973
2090
|
var import_set4 = __toESM(require("lodash/set"));
|
|
1974
2091
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1975
2092
|
var widgetMap = {
|
|
@@ -2025,7 +2142,7 @@ var widgetMap = {
|
|
|
2025
2142
|
}
|
|
2026
2143
|
};
|
|
2027
2144
|
function mergeWidgetOptions(AWidget) {
|
|
2028
|
-
let MergedWidget = (0,
|
|
2145
|
+
let MergedWidget = (0, import_get12.default)(AWidget, "MergedWidget");
|
|
2029
2146
|
if (!MergedWidget) {
|
|
2030
2147
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2031
2148
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2430,11 +2547,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2430
2547
|
|
|
2431
2548
|
// src/parser/schemaParser.ts
|
|
2432
2549
|
var import_forEach = __toESM(require("lodash/forEach"));
|
|
2433
|
-
var
|
|
2550
|
+
var import_isEqual7 = __toESM(require("lodash/isEqual"));
|
|
2434
2551
|
|
|
2435
2552
|
// src/parser/ParserValidator.ts
|
|
2436
|
-
var
|
|
2437
|
-
var
|
|
2553
|
+
var import_get13 = __toESM(require("lodash/get"));
|
|
2554
|
+
var import_isEqual6 = __toESM(require("lodash/isEqual"));
|
|
2438
2555
|
var ParserValidator = class {
|
|
2439
2556
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2440
2557
|
* first.
|
|
@@ -2455,12 +2572,12 @@ var ParserValidator = class {
|
|
|
2455
2572
|
* @param hash - The hash value at which to map the schema
|
|
2456
2573
|
*/
|
|
2457
2574
|
addSchema(schema, hash) {
|
|
2458
|
-
const key = (0,
|
|
2575
|
+
const key = (0, import_get13.default)(schema, ID_KEY, hash);
|
|
2459
2576
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2460
2577
|
const existing = this.schemaMap[key];
|
|
2461
2578
|
if (!existing) {
|
|
2462
2579
|
this.schemaMap[key] = identifiedSchema;
|
|
2463
|
-
} else if (!(0,
|
|
2580
|
+
} else if (!(0, import_isEqual6.default)(existing, identifiedSchema)) {
|
|
2464
2581
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2465
2582
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2466
2583
|
throw new Error(
|
|
@@ -2482,7 +2599,7 @@ var ParserValidator = class {
|
|
|
2482
2599
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2483
2600
|
*/
|
|
2484
2601
|
isValid(schema, _formData, rootSchema) {
|
|
2485
|
-
if (!(0,
|
|
2602
|
+
if (!(0, import_isEqual6.default)(rootSchema, this.rootSchema)) {
|
|
2486
2603
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2487
2604
|
}
|
|
2488
2605
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2520,12 +2637,13 @@ var ParserValidator = class {
|
|
|
2520
2637
|
|
|
2521
2638
|
// src/parser/schemaParser.ts
|
|
2522
2639
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2523
|
-
const
|
|
2640
|
+
const recurseRefs = [];
|
|
2641
|
+
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true, recurseRefs);
|
|
2524
2642
|
schemas.forEach((schema2) => {
|
|
2525
|
-
const sameSchemaIndex = recurseList.findIndex((item) => (0,
|
|
2643
|
+
const sameSchemaIndex = recurseList.findIndex((item) => (0, import_isEqual7.default)(item, schema2));
|
|
2526
2644
|
if (sameSchemaIndex === -1) {
|
|
2527
2645
|
recurseList.push(schema2);
|
|
2528
|
-
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
2646
|
+
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true, recurseRefs);
|
|
2529
2647
|
allOptions.forEach((s) => {
|
|
2530
2648
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
2531
2649
|
(0, import_forEach.default)(schema2[PROPERTIES_KEY], (value) => {
|