@remoteoss/json-schema-form 0.10.1-beta.0 → 0.11.0-dev.20240725074901
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +201 -14
- package/dist/index.js +201 -14
- package/dist/standalone.js +371 -22
- package/package.json +1 -1
- package/src/tests/modify.test.js +477 -11
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.0-dev.20240725074901
|
|
5
|
+
Generated: Thu, 25 Jul 2024 07:49:16 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -2524,9 +2524,9 @@ var require_mapToArray = __commonJS({
|
|
|
2524
2524
|
// node_modules/lodash/_setToArray.js
|
|
2525
2525
|
var require_setToArray = __commonJS({
|
|
2526
2526
|
"node_modules/lodash/_setToArray.js"(exports2, module2) {
|
|
2527
|
-
function setToArray2(
|
|
2528
|
-
var index = -1, result = Array(
|
|
2529
|
-
|
|
2527
|
+
function setToArray2(set3) {
|
|
2528
|
+
var index = -1, result = Array(set3.size);
|
|
2529
|
+
set3.forEach(function(value) {
|
|
2530
2530
|
result[++index] = value;
|
|
2531
2531
|
});
|
|
2532
2532
|
return result;
|
|
@@ -3489,10 +3489,10 @@ var require_merge = __commonJS({
|
|
|
3489
3489
|
var require_set = __commonJS({
|
|
3490
3490
|
"node_modules/lodash/set.js"(exports2, module2) {
|
|
3491
3491
|
var baseSet = require_baseSet();
|
|
3492
|
-
function
|
|
3492
|
+
function set3(object2, path, value) {
|
|
3493
3493
|
return object2 == null ? object2 : baseSet(object2, path, value);
|
|
3494
3494
|
}
|
|
3495
|
-
module2.exports =
|
|
3495
|
+
module2.exports = set3;
|
|
3496
3496
|
}
|
|
3497
3497
|
});
|
|
3498
3498
|
|
|
@@ -6862,6 +6862,168 @@ var require_mapValues = __commonJS({
|
|
|
6862
6862
|
}
|
|
6863
6863
|
});
|
|
6864
6864
|
|
|
6865
|
+
// node_modules/lodash/_arrayIncludesWith.js
|
|
6866
|
+
var require_arrayIncludesWith = __commonJS({
|
|
6867
|
+
"node_modules/lodash/_arrayIncludesWith.js"(exports2, module2) {
|
|
6868
|
+
function arrayIncludesWith(array2, value, comparator) {
|
|
6869
|
+
var index = -1, length2 = array2 == null ? 0 : array2.length;
|
|
6870
|
+
while (++index < length2) {
|
|
6871
|
+
if (comparator(value, array2[index])) {
|
|
6872
|
+
return true;
|
|
6873
|
+
}
|
|
6874
|
+
}
|
|
6875
|
+
return false;
|
|
6876
|
+
}
|
|
6877
|
+
module2.exports = arrayIncludesWith;
|
|
6878
|
+
}
|
|
6879
|
+
});
|
|
6880
|
+
|
|
6881
|
+
// node_modules/lodash/_baseDifference.js
|
|
6882
|
+
var require_baseDifference = __commonJS({
|
|
6883
|
+
"node_modules/lodash/_baseDifference.js"(exports2, module2) {
|
|
6884
|
+
var SetCache2 = require_SetCache();
|
|
6885
|
+
var arrayIncludes = require_arrayIncludes();
|
|
6886
|
+
var arrayIncludesWith = require_arrayIncludesWith();
|
|
6887
|
+
var arrayMap2 = require_arrayMap();
|
|
6888
|
+
var baseUnary2 = require_baseUnary();
|
|
6889
|
+
var cacheHas2 = require_cacheHas();
|
|
6890
|
+
var LARGE_ARRAY_SIZE2 = 200;
|
|
6891
|
+
function baseDifference(array2, values2, iteratee, comparator) {
|
|
6892
|
+
var index = -1, includes = arrayIncludes, isCommon = true, length2 = array2.length, result = [], valuesLength = values2.length;
|
|
6893
|
+
if (!length2) {
|
|
6894
|
+
return result;
|
|
6895
|
+
}
|
|
6896
|
+
if (iteratee) {
|
|
6897
|
+
values2 = arrayMap2(values2, baseUnary2(iteratee));
|
|
6898
|
+
}
|
|
6899
|
+
if (comparator) {
|
|
6900
|
+
includes = arrayIncludesWith;
|
|
6901
|
+
isCommon = false;
|
|
6902
|
+
} else if (values2.length >= LARGE_ARRAY_SIZE2) {
|
|
6903
|
+
includes = cacheHas2;
|
|
6904
|
+
isCommon = false;
|
|
6905
|
+
values2 = new SetCache2(values2);
|
|
6906
|
+
}
|
|
6907
|
+
outer:
|
|
6908
|
+
while (++index < length2) {
|
|
6909
|
+
var value = array2[index], computed = iteratee == null ? value : iteratee(value);
|
|
6910
|
+
value = comparator || value !== 0 ? value : 0;
|
|
6911
|
+
if (isCommon && computed === computed) {
|
|
6912
|
+
var valuesIndex = valuesLength;
|
|
6913
|
+
while (valuesIndex--) {
|
|
6914
|
+
if (values2[valuesIndex] === computed) {
|
|
6915
|
+
continue outer;
|
|
6916
|
+
}
|
|
6917
|
+
}
|
|
6918
|
+
result.push(value);
|
|
6919
|
+
} else if (!includes(values2, computed, comparator)) {
|
|
6920
|
+
result.push(value);
|
|
6921
|
+
}
|
|
6922
|
+
}
|
|
6923
|
+
return result;
|
|
6924
|
+
}
|
|
6925
|
+
module2.exports = baseDifference;
|
|
6926
|
+
}
|
|
6927
|
+
});
|
|
6928
|
+
|
|
6929
|
+
// node_modules/lodash/difference.js
|
|
6930
|
+
var require_difference = __commonJS({
|
|
6931
|
+
"node_modules/lodash/difference.js"(exports2, module2) {
|
|
6932
|
+
var baseDifference = require_baseDifference();
|
|
6933
|
+
var baseFlatten = require_baseFlatten();
|
|
6934
|
+
var baseRest = require_baseRest();
|
|
6935
|
+
var isArrayLikeObject = require_isArrayLikeObject();
|
|
6936
|
+
var difference2 = baseRest(function(array2, values2) {
|
|
6937
|
+
return isArrayLikeObject(array2) ? baseDifference(array2, baseFlatten(values2, 1, isArrayLikeObject, true)) : [];
|
|
6938
|
+
});
|
|
6939
|
+
module2.exports = difference2;
|
|
6940
|
+
}
|
|
6941
|
+
});
|
|
6942
|
+
|
|
6943
|
+
// node_modules/lodash/_baseIntersection.js
|
|
6944
|
+
var require_baseIntersection = __commonJS({
|
|
6945
|
+
"node_modules/lodash/_baseIntersection.js"(exports2, module2) {
|
|
6946
|
+
var SetCache2 = require_SetCache();
|
|
6947
|
+
var arrayIncludes = require_arrayIncludes();
|
|
6948
|
+
var arrayIncludesWith = require_arrayIncludesWith();
|
|
6949
|
+
var arrayMap2 = require_arrayMap();
|
|
6950
|
+
var baseUnary2 = require_baseUnary();
|
|
6951
|
+
var cacheHas2 = require_cacheHas();
|
|
6952
|
+
var nativeMin = Math.min;
|
|
6953
|
+
function baseIntersection(arrays, iteratee, comparator) {
|
|
6954
|
+
var includes = comparator ? arrayIncludesWith : arrayIncludes, length2 = arrays[0].length, othLength = arrays.length, othIndex = othLength, caches = Array(othLength), maxLength = Infinity, result = [];
|
|
6955
|
+
while (othIndex--) {
|
|
6956
|
+
var array2 = arrays[othIndex];
|
|
6957
|
+
if (othIndex && iteratee) {
|
|
6958
|
+
array2 = arrayMap2(array2, baseUnary2(iteratee));
|
|
6959
|
+
}
|
|
6960
|
+
maxLength = nativeMin(array2.length, maxLength);
|
|
6961
|
+
caches[othIndex] = !comparator && (iteratee || length2 >= 120 && array2.length >= 120) ? new SetCache2(othIndex && array2) : void 0;
|
|
6962
|
+
}
|
|
6963
|
+
array2 = arrays[0];
|
|
6964
|
+
var index = -1, seen = caches[0];
|
|
6965
|
+
outer:
|
|
6966
|
+
while (++index < length2 && result.length < maxLength) {
|
|
6967
|
+
var value = array2[index], computed = iteratee ? iteratee(value) : value;
|
|
6968
|
+
value = comparator || value !== 0 ? value : 0;
|
|
6969
|
+
if (!(seen ? cacheHas2(seen, computed) : includes(result, computed, comparator))) {
|
|
6970
|
+
othIndex = othLength;
|
|
6971
|
+
while (--othIndex) {
|
|
6972
|
+
var cache = caches[othIndex];
|
|
6973
|
+
if (!(cache ? cacheHas2(cache, computed) : includes(arrays[othIndex], computed, comparator))) {
|
|
6974
|
+
continue outer;
|
|
6975
|
+
}
|
|
6976
|
+
}
|
|
6977
|
+
if (seen) {
|
|
6978
|
+
seen.push(computed);
|
|
6979
|
+
}
|
|
6980
|
+
result.push(value);
|
|
6981
|
+
}
|
|
6982
|
+
}
|
|
6983
|
+
return result;
|
|
6984
|
+
}
|
|
6985
|
+
module2.exports = baseIntersection;
|
|
6986
|
+
}
|
|
6987
|
+
});
|
|
6988
|
+
|
|
6989
|
+
// node_modules/lodash/_castArrayLikeObject.js
|
|
6990
|
+
var require_castArrayLikeObject = __commonJS({
|
|
6991
|
+
"node_modules/lodash/_castArrayLikeObject.js"(exports2, module2) {
|
|
6992
|
+
var isArrayLikeObject = require_isArrayLikeObject();
|
|
6993
|
+
function castArrayLikeObject(value) {
|
|
6994
|
+
return isArrayLikeObject(value) ? value : [];
|
|
6995
|
+
}
|
|
6996
|
+
module2.exports = castArrayLikeObject;
|
|
6997
|
+
}
|
|
6998
|
+
});
|
|
6999
|
+
|
|
7000
|
+
// node_modules/lodash/intersection.js
|
|
7001
|
+
var require_intersection = __commonJS({
|
|
7002
|
+
"node_modules/lodash/intersection.js"(exports2, module2) {
|
|
7003
|
+
var arrayMap2 = require_arrayMap();
|
|
7004
|
+
var baseIntersection = require_baseIntersection();
|
|
7005
|
+
var baseRest = require_baseRest();
|
|
7006
|
+
var castArrayLikeObject = require_castArrayLikeObject();
|
|
7007
|
+
var intersection2 = baseRest(function(arrays) {
|
|
7008
|
+
var mapped = arrayMap2(arrays, castArrayLikeObject);
|
|
7009
|
+
return mapped.length && mapped[0] === arrays[0] ? baseIntersection(mapped) : [];
|
|
7010
|
+
});
|
|
7011
|
+
module2.exports = intersection2;
|
|
7012
|
+
}
|
|
7013
|
+
});
|
|
7014
|
+
|
|
7015
|
+
// node_modules/lodash/mergeWith.js
|
|
7016
|
+
var require_mergeWith = __commonJS({
|
|
7017
|
+
"node_modules/lodash/mergeWith.js"(exports2, module2) {
|
|
7018
|
+
var baseMerge = require_baseMerge();
|
|
7019
|
+
var createAssigner = require_createAssigner();
|
|
7020
|
+
var mergeWith2 = createAssigner(function(object2, source, srcIndex, customizer) {
|
|
7021
|
+
baseMerge(object2, source, srcIndex, customizer);
|
|
7022
|
+
});
|
|
7023
|
+
module2.exports = mergeWith2;
|
|
7024
|
+
}
|
|
7025
|
+
});
|
|
7026
|
+
|
|
6865
7027
|
// src/createHeadlessForm.js
|
|
6866
7028
|
var import_get4 = __toESM(require_get());
|
|
6867
7029
|
var import_isNil3 = __toESM(require_isNil());
|
|
@@ -8316,9 +8478,9 @@ function mapToArray(map) {
|
|
|
8316
8478
|
var mapToArray_default = mapToArray;
|
|
8317
8479
|
|
|
8318
8480
|
// node_modules/lodash-es/_setToArray.js
|
|
8319
|
-
function setToArray(
|
|
8320
|
-
var index = -1, result = Array(
|
|
8321
|
-
|
|
8481
|
+
function setToArray(set3) {
|
|
8482
|
+
var index = -1, result = Array(set3.size);
|
|
8483
|
+
set3.forEach(function(value) {
|
|
8322
8484
|
result[++index] = value;
|
|
8323
8485
|
});
|
|
8324
8486
|
return result;
|
|
@@ -13151,11 +13313,24 @@ function createHeadlessForm(jsonSchema, customConfig = {}) {
|
|
|
13151
13313
|
}
|
|
13152
13314
|
|
|
13153
13315
|
// src/modify.js
|
|
13316
|
+
var import_difference = __toESM(require_difference());
|
|
13154
13317
|
var import_get5 = __toESM(require_get());
|
|
13318
|
+
var import_intersection = __toESM(require_intersection());
|
|
13155
13319
|
var import_merge3 = __toESM(require_merge());
|
|
13320
|
+
var import_mergeWith = __toESM(require_mergeWith());
|
|
13321
|
+
var import_set2 = __toESM(require_set());
|
|
13322
|
+
var WARNING_TYPES = {
|
|
13323
|
+
FIELD_TO_CHANGE_NOT_FOUND: "FIELD_TO_CHANGE_NOT_FOUND",
|
|
13324
|
+
ORDER_MISSING_FIELDS: "ORDER_MISSING_FIELDS",
|
|
13325
|
+
FIELD_TO_CREATE_EXISTS: "FIELD_TO_CREATE_EXISTS",
|
|
13326
|
+
PICK_MISSED_FIELD: "PICK_MISSED_FIELD"
|
|
13327
|
+
};
|
|
13156
13328
|
function shortToFullPath(path) {
|
|
13157
13329
|
return path.replace(".", ".properties.");
|
|
13158
13330
|
}
|
|
13331
|
+
function mergeReplaceArray(_, newVal) {
|
|
13332
|
+
return Array.isArray(newVal) ? newVal : void 0;
|
|
13333
|
+
}
|
|
13159
13334
|
function standardizeAttrs(attrs) {
|
|
13160
13335
|
const { errorMessage, properties, ...rest } = attrs;
|
|
13161
13336
|
return {
|
|
@@ -13163,25 +13338,52 @@ function standardizeAttrs(attrs) {
|
|
|
13163
13338
|
...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
|
|
13164
13339
|
};
|
|
13165
13340
|
}
|
|
13341
|
+
function isConditionalReferencingAnyPickedField(condition, fieldsToPick) {
|
|
13342
|
+
const { if: ifCondition, then: thenCondition, else: elseCondition } = condition;
|
|
13343
|
+
const inIf = (0, import_intersection.default)(ifCondition.required, fieldsToPick);
|
|
13344
|
+
if (inIf.length > 0) {
|
|
13345
|
+
return true;
|
|
13346
|
+
}
|
|
13347
|
+
const inThen = (0, import_intersection.default)(thenCondition.required, fieldsToPick) || (0, import_intersection.default)(Object.keys(thenCondition.properties), fieldsToPick);
|
|
13348
|
+
if (inThen.length > 0) {
|
|
13349
|
+
return true;
|
|
13350
|
+
}
|
|
13351
|
+
const inElse = (0, import_intersection.default)(elseCondition.required, fieldsToPick) || (0, import_intersection.default)(Object.keys(elseCondition.properties), fieldsToPick);
|
|
13352
|
+
if (inElse.length > 0) {
|
|
13353
|
+
return true;
|
|
13354
|
+
}
|
|
13355
|
+
return false;
|
|
13356
|
+
}
|
|
13166
13357
|
function rewriteFields(schema, fieldsConfig) {
|
|
13167
13358
|
if (!fieldsConfig)
|
|
13168
|
-
return null;
|
|
13359
|
+
return { warnings: null };
|
|
13360
|
+
const warnings = [];
|
|
13169
13361
|
const fieldsToModify = Object.entries(fieldsConfig);
|
|
13170
13362
|
fieldsToModify.forEach(([shortPath, mutation]) => {
|
|
13171
13363
|
const fieldPath = shortToFullPath(shortPath);
|
|
13172
13364
|
if (!(0, import_get5.default)(schema.properties, fieldPath)) {
|
|
13365
|
+
warnings.push({
|
|
13366
|
+
type: WARNING_TYPES.FIELD_TO_CHANGE_NOT_FOUND,
|
|
13367
|
+
message: `Changing field "${shortPath}" was ignored because it does not exist.`
|
|
13368
|
+
});
|
|
13173
13369
|
return;
|
|
13174
13370
|
}
|
|
13175
13371
|
const fieldAttrs = (0, import_get5.default)(schema.properties, fieldPath);
|
|
13176
13372
|
const fieldChanges = typeof mutation === "function" ? mutation(fieldAttrs) : mutation;
|
|
13177
|
-
(0,
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13373
|
+
(0, import_mergeWith.default)(
|
|
13374
|
+
(0, import_get5.default)(schema.properties, fieldPath),
|
|
13375
|
+
{
|
|
13376
|
+
...fieldAttrs,
|
|
13377
|
+
...standardizeAttrs(fieldChanges)
|
|
13378
|
+
},
|
|
13379
|
+
mergeReplaceArray
|
|
13380
|
+
);
|
|
13181
13381
|
if (fieldChanges.properties) {
|
|
13182
|
-
rewriteFields((0, import_get5.default)(schema.properties, fieldPath), fieldChanges.properties);
|
|
13382
|
+
const result = rewriteFields((0, import_get5.default)(schema.properties, fieldPath), fieldChanges.properties);
|
|
13383
|
+
warnings.push(result.warnings);
|
|
13183
13384
|
}
|
|
13184
13385
|
});
|
|
13386
|
+
return { warnings: warnings.flat() };
|
|
13185
13387
|
}
|
|
13186
13388
|
function rewriteAllFields(schema, configCallback, context) {
|
|
13187
13389
|
if (!configCallback)
|
|
@@ -13189,10 +13391,14 @@ function rewriteAllFields(schema, configCallback, context) {
|
|
|
13189
13391
|
const parentName = context?.parent;
|
|
13190
13392
|
Object.entries(schema.properties).forEach(([fieldName, fieldAttrs]) => {
|
|
13191
13393
|
const fullName = parentName ? `${parentName}.${fieldName}` : fieldName;
|
|
13192
|
-
(0,
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
|
|
13394
|
+
(0, import_mergeWith.default)(
|
|
13395
|
+
(0, import_get5.default)(schema.properties, fieldName),
|
|
13396
|
+
{
|
|
13397
|
+
...fieldAttrs,
|
|
13398
|
+
...configCallback(fullName, fieldAttrs)
|
|
13399
|
+
},
|
|
13400
|
+
mergeReplaceArray
|
|
13401
|
+
);
|
|
13196
13402
|
if (fieldAttrs.properties) {
|
|
13197
13403
|
rewriteAllFields(fieldAttrs, configCallback, {
|
|
13198
13404
|
parent: fieldName
|
|
@@ -13200,11 +13406,154 @@ function rewriteAllFields(schema, configCallback, context) {
|
|
|
13200
13406
|
}
|
|
13201
13407
|
});
|
|
13202
13408
|
}
|
|
13409
|
+
function reorderFields(schema, configOrder) {
|
|
13410
|
+
if (!configOrder)
|
|
13411
|
+
return { warnings: null };
|
|
13412
|
+
const warnings = [];
|
|
13413
|
+
const originalOrder = schema["x-jsf-order"] || [];
|
|
13414
|
+
const orderConfig = typeof configOrder === "function" ? configOrder(originalOrder) : configOrder;
|
|
13415
|
+
const remaining = (0, import_difference.default)(originalOrder, orderConfig);
|
|
13416
|
+
if (remaining.length > 0) {
|
|
13417
|
+
warnings.push({
|
|
13418
|
+
type: WARNING_TYPES.ORDER_MISSING_FIELDS,
|
|
13419
|
+
message: `Some fields got forgotten in the new order. They were automatically appended: ${remaining.join(
|
|
13420
|
+
", "
|
|
13421
|
+
)}`
|
|
13422
|
+
});
|
|
13423
|
+
}
|
|
13424
|
+
schema["x-jsf-order"] = [...orderConfig, ...remaining];
|
|
13425
|
+
return { warnings };
|
|
13426
|
+
}
|
|
13427
|
+
function createFields(schema, fieldsConfig) {
|
|
13428
|
+
if (!fieldsConfig)
|
|
13429
|
+
return { warnings: null };
|
|
13430
|
+
const warnings = [];
|
|
13431
|
+
const fieldsToCreate = Object.entries(fieldsConfig);
|
|
13432
|
+
fieldsToCreate.forEach(([shortPath, fieldAttrs]) => {
|
|
13433
|
+
const fieldPath = shortToFullPath(shortPath);
|
|
13434
|
+
if (fieldAttrs.properties) {
|
|
13435
|
+
const result = createFields((0, import_get5.default)(schema.properties, fieldPath), fieldAttrs.properties);
|
|
13436
|
+
warnings.push(result.warnings);
|
|
13437
|
+
}
|
|
13438
|
+
const fieldInSchema = (0, import_get5.default)(schema.properties, fieldPath);
|
|
13439
|
+
if (fieldInSchema) {
|
|
13440
|
+
warnings.push({
|
|
13441
|
+
type: WARNING_TYPES.FIELD_TO_CREATE_EXISTS,
|
|
13442
|
+
message: `Creating field "${shortPath}" was ignored because it already exists.`
|
|
13443
|
+
});
|
|
13444
|
+
return;
|
|
13445
|
+
}
|
|
13446
|
+
const fieldInObjectPath = (0, import_set2.default)({}, fieldPath, standardizeAttrs(fieldAttrs));
|
|
13447
|
+
(0, import_merge3.default)(schema.properties, fieldInObjectPath);
|
|
13448
|
+
});
|
|
13449
|
+
return { warnings: warnings.flat() };
|
|
13450
|
+
}
|
|
13451
|
+
function pickFields(originalSchema, fieldsToPick) {
|
|
13452
|
+
if (!fieldsToPick) {
|
|
13453
|
+
return { schema: originalSchema, warnings: null };
|
|
13454
|
+
}
|
|
13455
|
+
const newSchema = {
|
|
13456
|
+
properties: {}
|
|
13457
|
+
};
|
|
13458
|
+
Object.entries(originalSchema).forEach(([attrKey, attrValue]) => {
|
|
13459
|
+
switch (attrKey) {
|
|
13460
|
+
case "properties":
|
|
13461
|
+
fieldsToPick.forEach((fieldPath) => {
|
|
13462
|
+
(0, import_set2.default)(newSchema.properties, fieldPath, attrValue[fieldPath]);
|
|
13463
|
+
});
|
|
13464
|
+
break;
|
|
13465
|
+
case "x-jsf-order":
|
|
13466
|
+
case "required":
|
|
13467
|
+
newSchema[attrKey] = attrValue.filter((fieldName) => fieldsToPick.includes(fieldName));
|
|
13468
|
+
break;
|
|
13469
|
+
case "allOf": {
|
|
13470
|
+
const newAllOf = originalSchema.allOf.filter(
|
|
13471
|
+
(condition) => isConditionalReferencingAnyPickedField(condition, fieldsToPick)
|
|
13472
|
+
);
|
|
13473
|
+
newSchema[attrKey] = newAllOf;
|
|
13474
|
+
break;
|
|
13475
|
+
}
|
|
13476
|
+
default:
|
|
13477
|
+
newSchema[attrKey] = attrValue;
|
|
13478
|
+
}
|
|
13479
|
+
});
|
|
13480
|
+
let missingFields = {};
|
|
13481
|
+
newSchema.allOf.forEach((condition) => {
|
|
13482
|
+
const { if: ifCondition, then: thenCondition, else: elseCondition } = condition;
|
|
13483
|
+
const index = originalSchema.allOf.indexOf(condition);
|
|
13484
|
+
missingFields = {
|
|
13485
|
+
...missingFields,
|
|
13486
|
+
...findMissingFields(ifCondition, {
|
|
13487
|
+
fields: fieldsToPick,
|
|
13488
|
+
path: `allOf[${index}].if`
|
|
13489
|
+
}),
|
|
13490
|
+
...findMissingFields(thenCondition, {
|
|
13491
|
+
fields: fieldsToPick,
|
|
13492
|
+
path: `allOf[${index}].then`
|
|
13493
|
+
}),
|
|
13494
|
+
...findMissingFields(elseCondition, {
|
|
13495
|
+
fields: fieldsToPick,
|
|
13496
|
+
path: `allOf[${index}].else`
|
|
13497
|
+
})
|
|
13498
|
+
};
|
|
13499
|
+
});
|
|
13500
|
+
const warnings = [];
|
|
13501
|
+
if (Object.keys(missingFields).length > 0) {
|
|
13502
|
+
Object.entries(missingFields).forEach(([fieldName]) => {
|
|
13503
|
+
(0, import_set2.default)(newSchema.properties, fieldName, originalSchema.properties[fieldName]);
|
|
13504
|
+
});
|
|
13505
|
+
warnings.push({
|
|
13506
|
+
type: WARNING_TYPES.PICK_MISSED_FIELD,
|
|
13507
|
+
message: `The picked fields have related conditional fields that got added automatically. ${Object.keys(
|
|
13508
|
+
missingFields
|
|
13509
|
+
).join(", ")}. Check "meta" for more details.`,
|
|
13510
|
+
meta: missingFields
|
|
13511
|
+
});
|
|
13512
|
+
}
|
|
13513
|
+
return { schema: newSchema, warnings };
|
|
13514
|
+
}
|
|
13515
|
+
function findMissingFields(conditional, { fields, path }) {
|
|
13516
|
+
if (!conditional) {
|
|
13517
|
+
return null;
|
|
13518
|
+
}
|
|
13519
|
+
let missingFields = {};
|
|
13520
|
+
conditional.required?.forEach((fieldName) => {
|
|
13521
|
+
if (!fields.includes(fieldName)) {
|
|
13522
|
+
missingFields[fieldName] = {
|
|
13523
|
+
path
|
|
13524
|
+
};
|
|
13525
|
+
}
|
|
13526
|
+
});
|
|
13527
|
+
Object.entries(conditional.properties || []).forEach(([fieldName]) => {
|
|
13528
|
+
if (!fields.includes(fieldName)) {
|
|
13529
|
+
missingFields[fieldName] = { path };
|
|
13530
|
+
}
|
|
13531
|
+
});
|
|
13532
|
+
return missingFields;
|
|
13533
|
+
}
|
|
13203
13534
|
function modify(originalSchema, config) {
|
|
13204
13535
|
const schema = JSON.parse(JSON.stringify(originalSchema));
|
|
13205
|
-
rewriteFields(schema, config.fields);
|
|
13536
|
+
const resultRewrite = rewriteFields(schema, config.fields);
|
|
13206
13537
|
rewriteAllFields(schema, config.allFields);
|
|
13207
|
-
|
|
13538
|
+
const resultCreate = createFields(schema, config.create);
|
|
13539
|
+
const resultPick = pickFields(schema, config.pick);
|
|
13540
|
+
const finalSchema = resultPick.schema;
|
|
13541
|
+
const resultReorder = reorderFields(finalSchema, config.orderRoot);
|
|
13542
|
+
if (!config.muteLogging) {
|
|
13543
|
+
console.warn(
|
|
13544
|
+
"json-schema-form modify(): We highly recommend you to handle/report the returned `warnings` as they highlight possible bugs in your modifications. To mute this log, pass `muteLogging: true` to the config."
|
|
13545
|
+
);
|
|
13546
|
+
}
|
|
13547
|
+
const warnings = [
|
|
13548
|
+
resultRewrite.warnings,
|
|
13549
|
+
resultCreate.warnings,
|
|
13550
|
+
resultPick.warnings,
|
|
13551
|
+
resultReorder.warnings
|
|
13552
|
+
].flat().filter(Boolean);
|
|
13553
|
+
return {
|
|
13554
|
+
schema: finalSchema,
|
|
13555
|
+
warnings
|
|
13556
|
+
};
|
|
13208
13557
|
}
|
|
13209
13558
|
export {
|
|
13210
13559
|
buildCompleteYupSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-dev.20240725074901",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|