@valbuild/core 0.14.0 → 0.16.0
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/SelectorProxy-2af1b2b8.cjs.prod.js +756 -0
- package/dist/SelectorProxy-63c2d0e2.esm.js +722 -0
- package/dist/SelectorProxy-873782a5.cjs.dev.js +756 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/initVal.d.ts +1 -1
- package/dist/declarations/src/patch/index.d.ts +1 -1
- package/dist/declarations/src/patch/util.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +3 -2
- package/dist/declarations/src/schema/boolean.d.ts +3 -2
- package/dist/declarations/src/schema/i18n.d.ts +3 -2
- package/dist/declarations/src/schema/image.d.ts +3 -2
- package/dist/declarations/src/schema/index.d.ts +5 -2
- package/dist/declarations/src/schema/literal.d.ts +3 -2
- package/dist/declarations/src/schema/number.d.ts +3 -2
- package/dist/declarations/src/schema/object.d.ts +3 -2
- package/dist/declarations/src/schema/oneOf.d.ts +3 -2
- package/dist/declarations/src/schema/richtext.d.ts +3 -2
- package/dist/declarations/src/schema/string.d.ts +3 -2
- package/dist/declarations/src/schema/union.d.ts +3 -2
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
- package/dist/index-2fff5ca8.cjs.dev.js +456 -0
- package/dist/{index-06df0a5b.esm.js → index-af761363.esm.js} +2 -555
- package/dist/index-cac9ecbd.cjs.prod.js +456 -0
- package/dist/ops-1b6e0e35.cjs.prod.js +552 -0
- package/dist/ops-74661336.esm.js +541 -0
- package/dist/ops-ea4827fc.cjs.dev.js +552 -0
- package/dist/valbuild-core.cjs.dev.js +151 -531
- package/dist/valbuild-core.cjs.prod.js +151 -531
- package/dist/valbuild-core.esm.js +65 -445
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +30 -21
- package/patch/dist/valbuild-core-patch.cjs.prod.js +30 -21
- package/patch/dist/valbuild-core-patch.esm.js +12 -4
- package/src/expr/repl.ts +2 -2
- package/src/index.ts +5 -0
- package/src/initVal.ts +1 -1
- package/src/patch/index.ts +1 -0
- package/src/patch/util.ts +7 -0
- package/src/schema/array.ts +45 -4
- package/src/schema/boolean.ts +14 -3
- package/src/schema/i18n.ts +4 -2
- package/src/schema/image.ts +65 -5
- package/src/schema/index.ts +23 -2
- package/src/schema/literal.ts +24 -3
- package/src/schema/number.ts +14 -3
- package/src/schema/object.ts +50 -7
- package/src/schema/oneOf.ts +3 -2
- package/src/schema/richtext.ts +63 -3
- package/src/schema/string.ts +14 -3
- package/src/schema/union.ts +3 -2
- package/src/schema/validation/ValidationError.ts +16 -0
- package/src/schema/validation/ValidationFix.ts +6 -0
- package/src/schema/validation.test.ts +226 -0
- package/src/selector/SelectorProxy.ts +1 -1
- package/dist/createClass-012eebbf.esm.js +0 -109
- package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
- package/dist/createClass-de7426aa.cjs.prod.js +0 -116
- package/dist/index-9663f28a.cjs.dev.js +0 -1037
- package/dist/index-b2270f8f.cjs.prod.js +0 -1037
- package/dist/ops-6fae92a1.esm.js +0 -12
- package/dist/ops-87cdbafc.cjs.dev.js +0 -14
- package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var
|
5
|
+
var SelectorProxy = require('../../dist/SelectorProxy-873782a5.cjs.dev.js');
|
6
6
|
var result = require('../../dist/result-48320acd.cjs.dev.js');
|
7
7
|
var util = require('../../dist/util-b213092b.cjs.dev.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-ea4827fc.cjs.dev.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -14,7 +14,7 @@ function deepEqual(a, b) {
|
|
14
14
|
if (a === b) {
|
15
15
|
return true;
|
16
16
|
}
|
17
|
-
if (
|
17
|
+
if (SelectorProxy._typeof(a) === "object" && SelectorProxy._typeof(b) === "object" && a !== null && b !== null) {
|
18
18
|
if (Array.isArray(a) && Array.isArray(b)) {
|
19
19
|
if (a.length !== b.length) return false;
|
20
20
|
for (var i = 0; i < a.length; ++i) {
|
@@ -26,7 +26,7 @@ function deepEqual(a, b) {
|
|
26
26
|
// If the objects have a different amount of keys, they cannot be equal
|
27
27
|
if (aEntries.length !== Object.keys(b).length) return false;
|
28
28
|
for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
|
29
|
-
var _aEntries$_i =
|
29
|
+
var _aEntries$_i = SelectorProxy._slicedToArray(_aEntries[_i], 2),
|
30
30
|
key = _aEntries$_i[0],
|
31
31
|
aValue = _aEntries$_i[1];
|
32
32
|
// b must be a JSON object, so the only way for the bValue to be
|
@@ -43,9 +43,9 @@ function deepEqual(a, b) {
|
|
43
43
|
function deepClone(value) {
|
44
44
|
if (Array.isArray(value)) {
|
45
45
|
return value.map(deepClone);
|
46
|
-
} else if (
|
46
|
+
} else if (SelectorProxy._typeof(value) === "object" && value !== null) {
|
47
47
|
return Object.fromEntries(Object.entries(value).map(function (_ref) {
|
48
|
-
var _ref2 =
|
48
|
+
var _ref2 = SelectorProxy._slicedToArray(_ref, 2),
|
49
49
|
key = _ref2[0],
|
50
50
|
value = _ref2[1];
|
51
51
|
return [key, deepClone(value)];
|
@@ -60,6 +60,14 @@ function parseAndValidateArrayIndex(value) {
|
|
60
60
|
}
|
61
61
|
return result.ok(Number(value));
|
62
62
|
}
|
63
|
+
function sourceToPatchPath(sourcePath) {
|
64
|
+
var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
|
65
|
+
_splitModuleIdAndModu2 = SelectorProxy._slicedToArray(_splitModuleIdAndModu, 2),
|
66
|
+
modulePath = _splitModuleIdAndModu2[1];
|
67
|
+
return modulePath.split(".").map(function (p) {
|
68
|
+
return JSON.parse(p).toString();
|
69
|
+
});
|
70
|
+
}
|
63
71
|
|
64
72
|
function parseAndValidateArrayInsertIndex(key, nodes) {
|
65
73
|
if (key === "-") {
|
@@ -85,7 +93,7 @@ function replaceInNode(node, key, value) {
|
|
85
93
|
node[index] = value;
|
86
94
|
return replaced;
|
87
95
|
}));
|
88
|
-
} else if (
|
96
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
89
97
|
// Prototype pollution protection
|
90
98
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
91
99
|
var _replaced = node[key];
|
@@ -100,7 +108,7 @@ function replaceInNode(node, key, value) {
|
|
100
108
|
function replaceAtPath(document, path, value) {
|
101
109
|
if (isNotRoot(path)) {
|
102
110
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
|
103
|
-
var _ref2 =
|
111
|
+
var _ref2 = SelectorProxy._slicedToArray(_ref, 2),
|
104
112
|
node = _ref2[0],
|
105
113
|
key = _ref2[1];
|
106
114
|
return replaceInNode(node, key, value);
|
@@ -120,7 +128,7 @@ function getFromNode(node, key) {
|
|
120
128
|
return result.ok(node[index]);
|
121
129
|
}
|
122
130
|
}));
|
123
|
-
} else if (
|
131
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
124
132
|
// Prototype pollution protection
|
125
133
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
126
134
|
return result.ok(node[key]);
|
@@ -158,11 +166,11 @@ function removeFromNode(node, key) {
|
|
158
166
|
if (Array.isArray(node)) {
|
159
167
|
return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
|
160
168
|
var _node$splice = node.splice(index, 1),
|
161
|
-
_node$splice2 =
|
169
|
+
_node$splice2 = SelectorProxy._slicedToArray(_node$splice, 1),
|
162
170
|
removed = _node$splice2[0];
|
163
171
|
return removed;
|
164
172
|
}));
|
165
|
-
} else if (
|
173
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
166
174
|
// Prototype pollution protection
|
167
175
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
168
176
|
var removed = node[key];
|
@@ -174,7 +182,7 @@ function removeFromNode(node, key) {
|
|
174
182
|
}
|
175
183
|
function removeAtPath(document, path) {
|
176
184
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
|
177
|
-
var _ref4 =
|
185
|
+
var _ref4 = SelectorProxy._slicedToArray(_ref3, 2),
|
178
186
|
node = _ref4[0],
|
179
187
|
key = _ref4[1];
|
180
188
|
return removeFromNode(node, key);
|
@@ -186,7 +194,7 @@ function addToNode(node, key, value) {
|
|
186
194
|
node.splice(index, 0, value);
|
187
195
|
return undefined;
|
188
196
|
}));
|
189
|
-
} else if (
|
197
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
190
198
|
var _replaced2;
|
191
199
|
// Prototype pollution protection
|
192
200
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
@@ -200,7 +208,7 @@ function addToNode(node, key, value) {
|
|
200
208
|
function addAtPath(document, path, value) {
|
201
209
|
if (isNotRoot(path)) {
|
202
210
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
|
203
|
-
var _ref6 =
|
211
|
+
var _ref6 = SelectorProxy._slicedToArray(_ref5, 2),
|
204
212
|
node = _ref6[0],
|
205
213
|
key = _ref6[1];
|
206
214
|
return addToNode(node, key, value);
|
@@ -212,15 +220,15 @@ function addAtPath(document, path, value) {
|
|
212
220
|
}
|
213
221
|
}
|
214
222
|
function pickDocument(_ref7) {
|
215
|
-
var _ref8 =
|
223
|
+
var _ref8 = SelectorProxy._slicedToArray(_ref7, 1),
|
216
224
|
document = _ref8[0];
|
217
225
|
return document;
|
218
226
|
}
|
219
227
|
var JSONOps = /*#__PURE__*/function () {
|
220
228
|
function JSONOps() {
|
221
|
-
|
229
|
+
SelectorProxy._classCallCheck(this, JSONOps);
|
222
230
|
}
|
223
|
-
|
231
|
+
SelectorProxy._createClass(JSONOps, [{
|
224
232
|
key: "get",
|
225
233
|
value: function get(document, path) {
|
226
234
|
return getAtPath(document, path);
|
@@ -315,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
|
|
315
323
|
var path = _ref.path,
|
316
324
|
message = _ref.message;
|
317
325
|
return {
|
318
|
-
path: [prefix].concat(
|
326
|
+
path: [prefix].concat(SelectorProxy._toConsumableArray(path)),
|
319
327
|
message: message
|
320
328
|
};
|
321
329
|
}
|
@@ -369,14 +377,14 @@ function parseOperation(operation) {
|
|
369
377
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
|
370
378
|
return "Cannot move root";
|
371
379
|
}), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
|
372
|
-
var _ref3 =
|
380
|
+
var _ref3 = SelectorProxy._slicedToArray(_ref2, 2),
|
373
381
|
from = _ref3[0],
|
374
382
|
path = _ref3[1];
|
375
383
|
return !isProperPathPrefix(from, path);
|
376
384
|
}, function () {
|
377
385
|
return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
|
378
386
|
}), result.map(function (_ref4) {
|
379
|
-
var _ref5 =
|
387
|
+
var _ref5 = SelectorProxy._slicedToArray(_ref4, 2),
|
380
388
|
from = _ref5[0],
|
381
389
|
path = _ref5[1];
|
382
390
|
return {
|
@@ -387,7 +395,7 @@ function parseOperation(operation) {
|
|
387
395
|
}));
|
388
396
|
case "copy":
|
389
397
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.map(function (_ref6) {
|
390
|
-
var _ref7 =
|
398
|
+
var _ref7 = SelectorProxy._slicedToArray(_ref6, 2),
|
391
399
|
from = _ref7[0],
|
392
400
|
path = _ref7[1];
|
393
401
|
return {
|
@@ -441,3 +449,4 @@ exports.isNotRoot = isNotRoot;
|
|
441
449
|
exports.parseAndValidateArrayIndex = parseAndValidateArrayIndex;
|
442
450
|
exports.parseJSONPointer = parseJSONPointer;
|
443
451
|
exports.parsePatch = parsePatch;
|
452
|
+
exports.sourceToPatchPath = sourceToPatchPath;
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var
|
5
|
+
var SelectorProxy = require('../../dist/SelectorProxy-2af1b2b8.cjs.prod.js');
|
6
6
|
var result = require('../../dist/result-26f67b40.cjs.prod.js');
|
7
7
|
var util = require('../../dist/util-030d8a1f.cjs.prod.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-1b6e0e35.cjs.prod.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -14,7 +14,7 @@ function deepEqual(a, b) {
|
|
14
14
|
if (a === b) {
|
15
15
|
return true;
|
16
16
|
}
|
17
|
-
if (
|
17
|
+
if (SelectorProxy._typeof(a) === "object" && SelectorProxy._typeof(b) === "object" && a !== null && b !== null) {
|
18
18
|
if (Array.isArray(a) && Array.isArray(b)) {
|
19
19
|
if (a.length !== b.length) return false;
|
20
20
|
for (var i = 0; i < a.length; ++i) {
|
@@ -26,7 +26,7 @@ function deepEqual(a, b) {
|
|
26
26
|
// If the objects have a different amount of keys, they cannot be equal
|
27
27
|
if (aEntries.length !== Object.keys(b).length) return false;
|
28
28
|
for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
|
29
|
-
var _aEntries$_i =
|
29
|
+
var _aEntries$_i = SelectorProxy._slicedToArray(_aEntries[_i], 2),
|
30
30
|
key = _aEntries$_i[0],
|
31
31
|
aValue = _aEntries$_i[1];
|
32
32
|
// b must be a JSON object, so the only way for the bValue to be
|
@@ -43,9 +43,9 @@ function deepEqual(a, b) {
|
|
43
43
|
function deepClone(value) {
|
44
44
|
if (Array.isArray(value)) {
|
45
45
|
return value.map(deepClone);
|
46
|
-
} else if (
|
46
|
+
} else if (SelectorProxy._typeof(value) === "object" && value !== null) {
|
47
47
|
return Object.fromEntries(Object.entries(value).map(function (_ref) {
|
48
|
-
var _ref2 =
|
48
|
+
var _ref2 = SelectorProxy._slicedToArray(_ref, 2),
|
49
49
|
key = _ref2[0],
|
50
50
|
value = _ref2[1];
|
51
51
|
return [key, deepClone(value)];
|
@@ -60,6 +60,14 @@ function parseAndValidateArrayIndex(value) {
|
|
60
60
|
}
|
61
61
|
return result.ok(Number(value));
|
62
62
|
}
|
63
|
+
function sourceToPatchPath(sourcePath) {
|
64
|
+
var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
|
65
|
+
_splitModuleIdAndModu2 = SelectorProxy._slicedToArray(_splitModuleIdAndModu, 2),
|
66
|
+
modulePath = _splitModuleIdAndModu2[1];
|
67
|
+
return modulePath.split(".").map(function (p) {
|
68
|
+
return JSON.parse(p).toString();
|
69
|
+
});
|
70
|
+
}
|
63
71
|
|
64
72
|
function parseAndValidateArrayInsertIndex(key, nodes) {
|
65
73
|
if (key === "-") {
|
@@ -85,7 +93,7 @@ function replaceInNode(node, key, value) {
|
|
85
93
|
node[index] = value;
|
86
94
|
return replaced;
|
87
95
|
}));
|
88
|
-
} else if (
|
96
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
89
97
|
// Prototype pollution protection
|
90
98
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
91
99
|
var _replaced = node[key];
|
@@ -100,7 +108,7 @@ function replaceInNode(node, key, value) {
|
|
100
108
|
function replaceAtPath(document, path, value) {
|
101
109
|
if (isNotRoot(path)) {
|
102
110
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
|
103
|
-
var _ref2 =
|
111
|
+
var _ref2 = SelectorProxy._slicedToArray(_ref, 2),
|
104
112
|
node = _ref2[0],
|
105
113
|
key = _ref2[1];
|
106
114
|
return replaceInNode(node, key, value);
|
@@ -120,7 +128,7 @@ function getFromNode(node, key) {
|
|
120
128
|
return result.ok(node[index]);
|
121
129
|
}
|
122
130
|
}));
|
123
|
-
} else if (
|
131
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
124
132
|
// Prototype pollution protection
|
125
133
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
126
134
|
return result.ok(node[key]);
|
@@ -158,11 +166,11 @@ function removeFromNode(node, key) {
|
|
158
166
|
if (Array.isArray(node)) {
|
159
167
|
return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
|
160
168
|
var _node$splice = node.splice(index, 1),
|
161
|
-
_node$splice2 =
|
169
|
+
_node$splice2 = SelectorProxy._slicedToArray(_node$splice, 1),
|
162
170
|
removed = _node$splice2[0];
|
163
171
|
return removed;
|
164
172
|
}));
|
165
|
-
} else if (
|
173
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
166
174
|
// Prototype pollution protection
|
167
175
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
168
176
|
var removed = node[key];
|
@@ -174,7 +182,7 @@ function removeFromNode(node, key) {
|
|
174
182
|
}
|
175
183
|
function removeAtPath(document, path) {
|
176
184
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
|
177
|
-
var _ref4 =
|
185
|
+
var _ref4 = SelectorProxy._slicedToArray(_ref3, 2),
|
178
186
|
node = _ref4[0],
|
179
187
|
key = _ref4[1];
|
180
188
|
return removeFromNode(node, key);
|
@@ -186,7 +194,7 @@ function addToNode(node, key, value) {
|
|
186
194
|
node.splice(index, 0, value);
|
187
195
|
return undefined;
|
188
196
|
}));
|
189
|
-
} else if (
|
197
|
+
} else if (SelectorProxy._typeof(node) === "object" && node !== null) {
|
190
198
|
var _replaced2;
|
191
199
|
// Prototype pollution protection
|
192
200
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
@@ -200,7 +208,7 @@ function addToNode(node, key, value) {
|
|
200
208
|
function addAtPath(document, path, value) {
|
201
209
|
if (isNotRoot(path)) {
|
202
210
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
|
203
|
-
var _ref6 =
|
211
|
+
var _ref6 = SelectorProxy._slicedToArray(_ref5, 2),
|
204
212
|
node = _ref6[0],
|
205
213
|
key = _ref6[1];
|
206
214
|
return addToNode(node, key, value);
|
@@ -212,15 +220,15 @@ function addAtPath(document, path, value) {
|
|
212
220
|
}
|
213
221
|
}
|
214
222
|
function pickDocument(_ref7) {
|
215
|
-
var _ref8 =
|
223
|
+
var _ref8 = SelectorProxy._slicedToArray(_ref7, 1),
|
216
224
|
document = _ref8[0];
|
217
225
|
return document;
|
218
226
|
}
|
219
227
|
var JSONOps = /*#__PURE__*/function () {
|
220
228
|
function JSONOps() {
|
221
|
-
|
229
|
+
SelectorProxy._classCallCheck(this, JSONOps);
|
222
230
|
}
|
223
|
-
|
231
|
+
SelectorProxy._createClass(JSONOps, [{
|
224
232
|
key: "get",
|
225
233
|
value: function get(document, path) {
|
226
234
|
return getAtPath(document, path);
|
@@ -315,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
|
|
315
323
|
var path = _ref.path,
|
316
324
|
message = _ref.message;
|
317
325
|
return {
|
318
|
-
path: [prefix].concat(
|
326
|
+
path: [prefix].concat(SelectorProxy._toConsumableArray(path)),
|
319
327
|
message: message
|
320
328
|
};
|
321
329
|
}
|
@@ -369,14 +377,14 @@ function parseOperation(operation) {
|
|
369
377
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
|
370
378
|
return "Cannot move root";
|
371
379
|
}), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
|
372
|
-
var _ref3 =
|
380
|
+
var _ref3 = SelectorProxy._slicedToArray(_ref2, 2),
|
373
381
|
from = _ref3[0],
|
374
382
|
path = _ref3[1];
|
375
383
|
return !isProperPathPrefix(from, path);
|
376
384
|
}, function () {
|
377
385
|
return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
|
378
386
|
}), result.map(function (_ref4) {
|
379
|
-
var _ref5 =
|
387
|
+
var _ref5 = SelectorProxy._slicedToArray(_ref4, 2),
|
380
388
|
from = _ref5[0],
|
381
389
|
path = _ref5[1];
|
382
390
|
return {
|
@@ -387,7 +395,7 @@ function parseOperation(operation) {
|
|
387
395
|
}));
|
388
396
|
case "copy":
|
389
397
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.map(function (_ref6) {
|
390
|
-
var _ref7 =
|
398
|
+
var _ref7 = SelectorProxy._slicedToArray(_ref6, 2),
|
391
399
|
from = _ref7[0],
|
392
400
|
path = _ref7[1];
|
393
401
|
return {
|
@@ -441,3 +449,4 @@ exports.isNotRoot = isNotRoot;
|
|
441
449
|
exports.parseAndValidateArrayIndex = parseAndValidateArrayIndex;
|
442
450
|
exports.parseJSONPointer = parseJSONPointer;
|
443
451
|
exports.parsePatch = parsePatch;
|
452
|
+
exports.sourceToPatchPath = sourceToPatchPath;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { f as _typeof, j as _slicedToArray, c as _createClass, b as _classCallCheck, w as _toConsumableArray } from '../../dist/SelectorProxy-63c2d0e2.esm.js';
|
2
2
|
import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-b96df128.esm.js';
|
3
3
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
4
|
-
import { P as PatchError } from '../../dist/ops-
|
5
|
-
export { P as PatchError } from '../../dist/ops-
|
4
|
+
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-74661336.esm.js';
|
5
|
+
export { P as PatchError } from '../../dist/ops-74661336.esm.js';
|
6
6
|
|
7
7
|
function isNotRoot(path) {
|
8
8
|
return isNonEmpty(path);
|
@@ -57,6 +57,14 @@ function parseAndValidateArrayIndex(value) {
|
|
57
57
|
}
|
58
58
|
return ok(Number(value));
|
59
59
|
}
|
60
|
+
function sourceToPatchPath(sourcePath) {
|
61
|
+
var _splitModuleIdAndModu = splitModuleIdAndModulePath(sourcePath),
|
62
|
+
_splitModuleIdAndModu2 = _slicedToArray(_splitModuleIdAndModu, 2),
|
63
|
+
modulePath = _splitModuleIdAndModu2[1];
|
64
|
+
return modulePath.split(".").map(function (p) {
|
65
|
+
return JSON.parse(p).toString();
|
66
|
+
});
|
67
|
+
}
|
60
68
|
|
61
69
|
function parseAndValidateArrayInsertIndex(key, nodes) {
|
62
70
|
if (key === "-") {
|
@@ -428,4 +436,4 @@ function applyPatch(document, ops, patch) {
|
|
428
436
|
}, document));
|
429
437
|
}
|
430
438
|
|
431
|
-
export { JSONOps, applyPatch, deepClone, deepEqual, formatJSONPointer, isNotRoot, parseAndValidateArrayIndex, parseJSONPointer, parsePatch };
|
439
|
+
export { JSONOps, applyPatch, deepClone, deepEqual, formatJSONPointer, isNotRoot, parseAndValidateArrayIndex, parseJSONPointer, parsePatch, sourceToPatchPath };
|
package/src/expr/repl.ts
CHANGED
package/src/index.ts
CHANGED
@@ -23,6 +23,11 @@ export {
|
|
23
23
|
type JsonOfSource,
|
24
24
|
} from "./val";
|
25
25
|
export type { Json, JsonPrimitive } from "./Json";
|
26
|
+
export type {
|
27
|
+
ValidationErrors,
|
28
|
+
ValidationError,
|
29
|
+
} from "./schema/validation/ValidationError";
|
30
|
+
export type { ValidationFix } from "./schema/validation/ValidationFix";
|
26
31
|
export * as expr from "./expr/";
|
27
32
|
export { FILE_REF_PROP } from "./source/file";
|
28
33
|
export { VAL_EXTENSION, type SourceArray } from "./source";
|
package/src/initVal.ts
CHANGED
@@ -41,7 +41,7 @@ export const initVal = <
|
|
41
41
|
>(options?: {
|
42
42
|
readonly locales?: NarrowStrings<{
|
43
43
|
readonly required: Locales;
|
44
|
-
readonly
|
44
|
+
readonly default: Locales extends readonly string[]
|
45
45
|
? Locales[number]
|
46
46
|
: never;
|
47
47
|
}>;
|
package/src/patch/index.ts
CHANGED
package/src/patch/util.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { array, result } from "../fp";
|
2
2
|
import { PatchError, ReadonlyJSONValue, ToMutable } from "./ops";
|
3
|
+
import { splitModuleIdAndModulePath } from "../module";
|
4
|
+
import { SourcePath } from "../val";
|
3
5
|
|
4
6
|
export function isNotRoot(path: string[]): path is array.NonEmptyArray<string> {
|
5
7
|
return array.isNonEmpty(path);
|
@@ -65,3 +67,8 @@ export function parseAndValidateArrayIndex(
|
|
65
67
|
}
|
66
68
|
return result.ok(Number(value));
|
67
69
|
}
|
70
|
+
|
71
|
+
export function sourceToPatchPath(sourcePath: SourcePath) {
|
72
|
+
const [, modulePath] = splitModuleIdAndModulePath(sourcePath);
|
73
|
+
return modulePath.split(".").map((p) => JSON.parse(p).toString());
|
74
|
+
}
|
package/src/schema/array.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2
2
|
import { Schema, SchemaTypeOf, SerializedSchema } from ".";
|
3
3
|
import { SelectorSource } from "../selector";
|
4
|
+
import { createValPathOfItem } from "../selector/SelectorProxy";
|
4
5
|
import { SourcePath } from "../val";
|
6
|
+
import { ValidationErrors } from "./validation/ValidationError";
|
5
7
|
|
6
8
|
export type SerializedArraySchema = {
|
7
9
|
type: "array";
|
@@ -16,11 +18,46 @@ export class ArraySchema<T extends Schema<SelectorSource>> extends Schema<
|
|
16
18
|
super();
|
17
19
|
}
|
18
20
|
|
19
|
-
validate(src: SchemaTypeOf<T>[]):
|
20
|
-
|
21
|
+
validate(path: SourcePath, src: SchemaTypeOf<T>[]): ValidationErrors {
|
22
|
+
let error: ValidationErrors = false;
|
23
|
+
|
24
|
+
if (this.opt && (src === null || src === undefined)) {
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (typeof src !== "object" || !Array.isArray(src)) {
|
29
|
+
return {
|
30
|
+
[path]: [{ message: `Expected 'array', got '${typeof src}'` }],
|
31
|
+
} as ValidationErrors;
|
32
|
+
}
|
33
|
+
src.forEach((i, idx) => {
|
34
|
+
const subPath = createValPathOfItem(path, idx);
|
35
|
+
if (!subPath) {
|
36
|
+
error = this.appendValidationError(
|
37
|
+
error,
|
38
|
+
path,
|
39
|
+
`Internal error: could not create path at ${
|
40
|
+
!path && typeof path === "string" ? "<empty string>" : path
|
41
|
+
} at index ${idx}`, // Should! never happen
|
42
|
+
src
|
43
|
+
);
|
44
|
+
} else {
|
45
|
+
const subError = this.item.validate(subPath, i);
|
46
|
+
if (subError && error) {
|
47
|
+
error = {
|
48
|
+
...subError,
|
49
|
+
...error,
|
50
|
+
};
|
51
|
+
} else if (subError) {
|
52
|
+
error = subError;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
|
57
|
+
return error;
|
21
58
|
}
|
22
59
|
|
23
|
-
|
60
|
+
assert(src: SchemaTypeOf<T>[]): boolean {
|
24
61
|
if (this.opt && (src === null || src === undefined)) {
|
25
62
|
return true;
|
26
63
|
}
|
@@ -28,7 +65,11 @@ export class ArraySchema<T extends Schema<SelectorSource>> extends Schema<
|
|
28
65
|
return false;
|
29
66
|
}
|
30
67
|
|
31
|
-
|
68
|
+
for (const item of src) {
|
69
|
+
if (!this.item.assert(item)) {
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
}
|
32
73
|
return typeof src === "object" && Array.isArray(src);
|
33
74
|
}
|
34
75
|
|
package/src/schema/boolean.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2
2
|
import { Schema, SerializedSchema } from ".";
|
3
3
|
import { SourcePath } from "../val";
|
4
|
+
import { ValidationErrors } from "./validation/ValidationError";
|
4
5
|
|
5
6
|
export type SerializedBooleanSchema = {
|
6
7
|
type: "boolean";
|
@@ -11,11 +12,21 @@ export class BooleanSchema<Src extends boolean | null> extends Schema<Src> {
|
|
11
12
|
constructor(readonly opt: boolean = false) {
|
12
13
|
super();
|
13
14
|
}
|
14
|
-
validate(src: Src):
|
15
|
-
|
15
|
+
validate(path: SourcePath, src: Src): ValidationErrors {
|
16
|
+
if (this.opt && (src === null || src === undefined)) {
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
if (typeof src !== "boolean") {
|
20
|
+
return {
|
21
|
+
[path]: [
|
22
|
+
{ message: `Expected 'boolean', got '${typeof src}'`, value: src },
|
23
|
+
],
|
24
|
+
} as ValidationErrors;
|
25
|
+
}
|
26
|
+
return false;
|
16
27
|
}
|
17
28
|
|
18
|
-
|
29
|
+
assert(src: Src): boolean {
|
19
30
|
if (this.opt && (src === null || src === undefined)) {
|
20
31
|
return true;
|
21
32
|
}
|
package/src/schema/i18n.ts
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
import { Schema, SchemaTypeOf, SerializedSchema } from ".";
|
3
3
|
import { I18nCompatibleSource, I18nSource } from "../source/i18n";
|
4
4
|
import { SourcePath } from "../val";
|
5
|
+
import { ValidationErrors } from "./validation/ValidationError";
|
5
6
|
|
6
7
|
export type SerializedI18nSchema = {
|
7
8
|
type: "i18n";
|
@@ -22,12 +23,13 @@ export class I18nSchema<Locales extends readonly string[]> extends Schema<
|
|
22
23
|
}
|
23
24
|
|
24
25
|
validate(
|
26
|
+
path: SourcePath,
|
25
27
|
src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>
|
26
|
-
):
|
28
|
+
): ValidationErrors {
|
27
29
|
throw new Error("Method not implemented.");
|
28
30
|
}
|
29
31
|
|
30
|
-
|
32
|
+
assert(
|
31
33
|
src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>
|
32
34
|
): boolean {
|
33
35
|
throw new Error("Method not implemented.");
|
package/src/schema/image.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2
2
|
import { Schema, SerializedSchema } from ".";
|
3
|
+
import { VAL_EXTENSION } from "../source";
|
3
4
|
import { FileSource, FILE_REF_PROP } from "../source/file";
|
4
5
|
import { SourcePath } from "../val";
|
6
|
+
import { ValidationErrors } from "./validation/ValidationError";
|
5
7
|
|
6
8
|
export type ImageOptions = {
|
7
9
|
ext: ["jpg"] | ["webp"];
|
@@ -29,13 +31,71 @@ export class ImageSchema<
|
|
29
31
|
super();
|
30
32
|
}
|
31
33
|
|
32
|
-
validate(src: Src):
|
33
|
-
|
34
|
+
validate(path: SourcePath, src: Src): ValidationErrors {
|
35
|
+
if (this.opt && (src === null || src === undefined)) {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
if (src === null || src === undefined) {
|
39
|
+
return {
|
40
|
+
[path]: [
|
41
|
+
{
|
42
|
+
message: `Non-optional image was null or undefined.`,
|
43
|
+
value: src,
|
44
|
+
},
|
45
|
+
],
|
46
|
+
} as ValidationErrors;
|
47
|
+
}
|
48
|
+
if (typeof src[FILE_REF_PROP] !== "string") {
|
49
|
+
return {
|
50
|
+
[path]: [
|
51
|
+
{
|
52
|
+
message: `Image did not have a file reference string. Got: ${typeof src[
|
53
|
+
FILE_REF_PROP
|
54
|
+
]}`,
|
55
|
+
value: src,
|
56
|
+
},
|
57
|
+
],
|
58
|
+
} as ValidationErrors;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (src[VAL_EXTENSION] !== "file") {
|
62
|
+
return {
|
63
|
+
[path]: [
|
64
|
+
{
|
65
|
+
message: `Image did not have the valid file extension type. Got: ${src[VAL_EXTENSION]}`,
|
66
|
+
value: src,
|
67
|
+
},
|
68
|
+
],
|
69
|
+
} as ValidationErrors;
|
70
|
+
}
|
71
|
+
if (src.metadata) {
|
72
|
+
return {
|
73
|
+
[path]: [
|
74
|
+
{
|
75
|
+
message: `Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).`, // These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
76
|
+
value: src,
|
77
|
+
fixes: ["image:replace-metadata"],
|
78
|
+
},
|
79
|
+
],
|
80
|
+
} as ValidationErrors;
|
81
|
+
}
|
82
|
+
|
83
|
+
return {
|
84
|
+
[path]: [
|
85
|
+
{
|
86
|
+
message: `Could not validate Image metadata.`,
|
87
|
+
value: src,
|
88
|
+
fixes: ["image:add-metadata"],
|
89
|
+
},
|
90
|
+
],
|
91
|
+
} as ValidationErrors;
|
34
92
|
}
|
35
93
|
|
36
|
-
|
37
|
-
|
38
|
-
|
94
|
+
assert(src: Src): boolean {
|
95
|
+
if (this.opt && (src === null || src === undefined)) {
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
return src?.[FILE_REF_PROP] === "image" && src?.[VAL_EXTENSION] === "file";
|
39
99
|
}
|
40
100
|
|
41
101
|
optional(): Schema<Src | null> {
|