@valbuild/core 0.16.0 → 0.17.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/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +36 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-369caccf.esm.js} +23 -195
- package/dist/{index-af761363.esm.js → index-3e3e839e.esm.js} +189 -1
- package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-23a5abb2.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +585 -198
- package/dist/valbuild-core.cjs.prod.js +585 -198
- package/dist/valbuild-core.esm.js +520 -134
- 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 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +46 -14
- package/src/initSchema.ts +11 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -1,21 +1,165 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var index = require('./index-8706c87e.cjs.prod.js');
|
4
4
|
var result = require('./result-26f67b40.cjs.prod.js');
|
5
5
|
|
6
|
+
function hasOwn(obj, prop) {
|
7
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
8
|
+
}
|
9
|
+
function _andThen(f, source, path) {
|
10
|
+
if (source) {
|
11
|
+
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
12
|
+
}
|
13
|
+
return newSelectorProxy(source, path);
|
14
|
+
}
|
15
|
+
function isSelector(source) {
|
16
|
+
return index._typeof(source) === "object" && source !== null && (index.GetSource in source || index.Path in source);
|
17
|
+
}
|
18
|
+
function newSelectorProxy(source, path, moduleSchema) {
|
19
|
+
var _ref;
|
20
|
+
if (index._typeof(source) === "object") {
|
21
|
+
if (isSelector(source)) {
|
22
|
+
return source;
|
23
|
+
} else if (index.isSerializedVal(source)) {
|
24
|
+
return newSelectorProxy(source.val, source.valPath);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
if (source && source[index.FILE_REF_PROP] && source[index.VAL_EXTENSION] === "file") {
|
28
|
+
var fileRef = source[index.FILE_REF_PROP];
|
29
|
+
if (typeof fileRef !== "string") {
|
30
|
+
throw Error("Invalid file ref: " + fileRef);
|
31
|
+
}
|
32
|
+
return newSelectorProxy(index.convertFileSource(source), path, moduleSchema);
|
33
|
+
}
|
34
|
+
switch (index._typeof(source)) {
|
35
|
+
case "function":
|
36
|
+
case "symbol":
|
37
|
+
throw Error("Invalid selector type: ".concat(index._typeof(source), ": ").concat(source));
|
38
|
+
case "object":
|
39
|
+
// Handles both objects and arrays!
|
40
|
+
if (source !== null) {
|
41
|
+
return new Proxy(source, {
|
42
|
+
// TODO: see proxy docs if we want more traps
|
43
|
+
has: function has(target, prop) {
|
44
|
+
if (prop === index.GetSource) {
|
45
|
+
return true;
|
46
|
+
}
|
47
|
+
if (prop === index.Path) {
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
if (prop === "andThen") {
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
if (prop === index.GetSchema) {
|
54
|
+
return true;
|
55
|
+
}
|
56
|
+
return prop in target;
|
57
|
+
},
|
58
|
+
get: function get(target, prop) {
|
59
|
+
if (prop === index.GetSource) {
|
60
|
+
return source;
|
61
|
+
}
|
62
|
+
if (prop === index.Path) {
|
63
|
+
return path;
|
64
|
+
}
|
65
|
+
if (prop === index.GetSchema) {
|
66
|
+
return moduleSchema;
|
67
|
+
}
|
68
|
+
if (prop === "andThen") {
|
69
|
+
return function (f) {
|
70
|
+
return _andThen(f, source, path);
|
71
|
+
};
|
72
|
+
}
|
73
|
+
if (Array.isArray(target)) {
|
74
|
+
if (prop === "filter") {
|
75
|
+
return function (f) {
|
76
|
+
var filtered = target.map(function (a, i) {
|
77
|
+
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
78
|
+
}).filter(function (a) {
|
79
|
+
if (f && f instanceof index.Schema) {
|
80
|
+
return f.assert(unValify(a));
|
81
|
+
} else {
|
82
|
+
return unValify(f(a));
|
83
|
+
}
|
84
|
+
});
|
85
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
86
|
+
};
|
87
|
+
} else if (prop === "map") {
|
88
|
+
return function (f) {
|
89
|
+
var filtered = target.map(function (a, i) {
|
90
|
+
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
91
|
+
if (isSelector(valueOrSelector)) {
|
92
|
+
return valueOrSelector;
|
93
|
+
}
|
94
|
+
return newSelectorProxy(valueOrSelector);
|
95
|
+
});
|
96
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
97
|
+
};
|
98
|
+
}
|
99
|
+
}
|
100
|
+
if (Array.isArray(target) && prop === "length") {
|
101
|
+
return newSelectorProxy(target.length);
|
102
|
+
}
|
103
|
+
var reflectedValue = Reflect.get(target, prop);
|
104
|
+
if (hasOwn(source, prop)) {
|
105
|
+
if (!Number.isNaN(Number(prop))) {
|
106
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
107
|
+
}
|
108
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
109
|
+
}
|
110
|
+
return reflectedValue;
|
111
|
+
}
|
112
|
+
});
|
113
|
+
}
|
114
|
+
// intentional fallthrough
|
115
|
+
// eslint-disable-next-line no-fallthrough
|
116
|
+
default:
|
117
|
+
return _ref = {
|
118
|
+
eq: function eq(other) {
|
119
|
+
var otherValue = other;
|
120
|
+
if (isSelector(other)) {
|
121
|
+
otherValue = other[index.GetSource];
|
122
|
+
if (otherValue instanceof index.Expr) {
|
123
|
+
throw Error("TODO: Cannot evaluate equality with an Expr");
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return newSelectorProxy(source === otherValue, undefined);
|
127
|
+
},
|
128
|
+
andThen: function andThen(f) {
|
129
|
+
return _andThen(f, source === undefined ? null : source, path);
|
130
|
+
}
|
131
|
+
}, index._defineProperty(_ref, index.GetSource, source === undefined ? null : source), index._defineProperty(_ref, index.Path, path), index._defineProperty(_ref, index.GetSchema, moduleSchema), _ref;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
function createValPathOfItem(arrayPath, prop) {
|
135
|
+
if (index._typeof(prop) === "symbol") {
|
136
|
+
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
137
|
+
}
|
138
|
+
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
139
|
+
}
|
140
|
+
|
141
|
+
// TODO: could we do .val on the objects instead?
|
142
|
+
function unValify(valueOrSelector) {
|
143
|
+
if (index._typeof(valueOrSelector) === "object" && (index.GetSource in valueOrSelector || index.Path in valueOrSelector)) {
|
144
|
+
var selectorValue = valueOrSelector[index.GetSource];
|
145
|
+
return selectorValue;
|
146
|
+
}
|
147
|
+
return valueOrSelector;
|
148
|
+
}
|
149
|
+
|
6
150
|
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
7
|
-
|
8
|
-
var _super =
|
151
|
+
index._inherits(ObjectSchema, _Schema);
|
152
|
+
var _super = index._createSuper(ObjectSchema);
|
9
153
|
function ObjectSchema(items) {
|
10
154
|
var _this;
|
11
155
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
12
|
-
|
156
|
+
index._classCallCheck(this, ObjectSchema);
|
13
157
|
_this = _super.call(this);
|
14
158
|
_this.items = items;
|
15
159
|
_this.opt = opt;
|
16
160
|
return _this;
|
17
161
|
}
|
18
|
-
|
162
|
+
index._createClass(ObjectSchema, [{
|
19
163
|
key: "validate",
|
20
164
|
value: function validate(path, src) {
|
21
165
|
var _this2 = this;
|
@@ -23,20 +167,20 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
23
167
|
if (this.opt && (src === null || src === undefined)) {
|
24
168
|
return false;
|
25
169
|
}
|
26
|
-
if (
|
27
|
-
return
|
28
|
-
message: "Expected 'object', got '".concat(
|
170
|
+
if (index._typeof(src) !== "object") {
|
171
|
+
return index._defineProperty({}, path, [{
|
172
|
+
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
29
173
|
}]);
|
30
174
|
} else if (Array.isArray(src)) {
|
31
|
-
return
|
175
|
+
return index._defineProperty({}, path, [{
|
32
176
|
message: "Expected 'object', got 'array'"
|
33
177
|
}]);
|
34
178
|
}
|
35
179
|
Object.entries(this.items).forEach(function (_ref3) {
|
36
|
-
var _ref4 =
|
180
|
+
var _ref4 = index._slicedToArray(_ref3, 2),
|
37
181
|
key = _ref4[0],
|
38
182
|
schema = _ref4[1];
|
39
|
-
var subPath =
|
183
|
+
var subPath = createValPathOfItem(path, key);
|
40
184
|
if (!subPath) {
|
41
185
|
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key),
|
42
186
|
// Should! never happen
|
@@ -44,7 +188,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
44
188
|
} else {
|
45
189
|
var subError = schema.validate(subPath, src[key]);
|
46
190
|
if (subError && error) {
|
47
|
-
error =
|
191
|
+
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
48
192
|
} else if (subError) {
|
49
193
|
error = subError;
|
50
194
|
}
|
@@ -62,14 +206,14 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
62
206
|
return false;
|
63
207
|
}
|
64
208
|
for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
|
65
|
-
var _Object$entries$_i =
|
209
|
+
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
66
210
|
_key = _Object$entries$_i[0],
|
67
211
|
schema = _Object$entries$_i[1];
|
68
212
|
if (!schema.assert(src[_key])) {
|
69
213
|
return false;
|
70
214
|
}
|
71
215
|
}
|
72
|
-
return
|
216
|
+
return index._typeof(src) === "object" && !Array.isArray(src);
|
73
217
|
}
|
74
218
|
}, {
|
75
219
|
key: "optional",
|
@@ -82,7 +226,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
82
226
|
return {
|
83
227
|
type: "object",
|
84
228
|
items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
|
85
|
-
var _ref6 =
|
229
|
+
var _ref6 = index._slicedToArray(_ref5, 2),
|
86
230
|
key = _ref6[0],
|
87
231
|
schema = _ref6[1];
|
88
232
|
return [key, schema.serialize()];
|
@@ -92,24 +236,24 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
92
236
|
}
|
93
237
|
}]);
|
94
238
|
return ObjectSchema;
|
95
|
-
}(
|
239
|
+
}(index.Schema);
|
96
240
|
var object = function object(schema) {
|
97
241
|
return new ObjectSchema(schema);
|
98
242
|
};
|
99
243
|
|
100
244
|
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
101
|
-
|
102
|
-
var _super =
|
245
|
+
index._inherits(ArraySchema, _Schema);
|
246
|
+
var _super = index._createSuper(ArraySchema);
|
103
247
|
function ArraySchema(item) {
|
104
248
|
var _this;
|
105
249
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
106
|
-
|
250
|
+
index._classCallCheck(this, ArraySchema);
|
107
251
|
_this = _super.call(this);
|
108
252
|
_this.item = item;
|
109
253
|
_this.opt = opt;
|
110
254
|
return _this;
|
111
255
|
}
|
112
|
-
|
256
|
+
index._createClass(ArraySchema, [{
|
113
257
|
key: "validate",
|
114
258
|
value: function validate(path, src) {
|
115
259
|
var _this2 = this;
|
@@ -117,13 +261,13 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
117
261
|
if (this.opt && (src === null || src === undefined)) {
|
118
262
|
return false;
|
119
263
|
}
|
120
|
-
if (
|
121
|
-
return
|
122
|
-
message: "Expected 'array', got '".concat(
|
264
|
+
if (index._typeof(src) !== "object" || !Array.isArray(src)) {
|
265
|
+
return index._defineProperty({}, path, [{
|
266
|
+
message: "Expected 'array', got '".concat(index._typeof(src), "'")
|
123
267
|
}]);
|
124
268
|
}
|
125
269
|
src.forEach(function (i, idx) {
|
126
|
-
var subPath =
|
270
|
+
var subPath = createValPathOfItem(path, idx);
|
127
271
|
if (!subPath) {
|
128
272
|
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at index ").concat(idx),
|
129
273
|
// Should! never happen
|
@@ -131,7 +275,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
131
275
|
} else {
|
132
276
|
var subError = _this2.item.validate(subPath, i);
|
133
277
|
if (subError && error) {
|
134
|
-
error =
|
278
|
+
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
135
279
|
} else if (subError) {
|
136
280
|
error = subError;
|
137
281
|
}
|
@@ -162,7 +306,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
162
306
|
} finally {
|
163
307
|
_iterator.f();
|
164
308
|
}
|
165
|
-
return
|
309
|
+
return index._typeof(src) === "object" && Array.isArray(src);
|
166
310
|
}
|
167
311
|
}, {
|
168
312
|
key: "optional",
|
@@ -180,72 +324,25 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
180
324
|
}
|
181
325
|
}]);
|
182
326
|
return ArraySchema;
|
183
|
-
}(
|
327
|
+
}(index.Schema);
|
184
328
|
var array = function array(schema) {
|
185
329
|
return new ArraySchema(schema);
|
186
330
|
};
|
187
331
|
|
188
|
-
var I18nSchema = /*#__PURE__*/function (_Schema) {
|
189
|
-
SelectorProxy._inherits(I18nSchema, _Schema);
|
190
|
-
var _super = SelectorProxy._createSuper(I18nSchema);
|
191
|
-
function I18nSchema(locales, item) {
|
192
|
-
var _this;
|
193
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
194
|
-
SelectorProxy._classCallCheck(this, I18nSchema);
|
195
|
-
_this = _super.call(this);
|
196
|
-
_this.locales = locales;
|
197
|
-
_this.item = item;
|
198
|
-
_this.opt = opt;
|
199
|
-
return _this;
|
200
|
-
}
|
201
|
-
SelectorProxy._createClass(I18nSchema, [{
|
202
|
-
key: "validate",
|
203
|
-
value: function validate(path, src) {
|
204
|
-
throw new Error("Method not implemented.");
|
205
|
-
}
|
206
|
-
}, {
|
207
|
-
key: "assert",
|
208
|
-
value: function assert(src) {
|
209
|
-
throw new Error("Method not implemented.");
|
210
|
-
}
|
211
|
-
}, {
|
212
|
-
key: "optional",
|
213
|
-
value: function optional() {
|
214
|
-
return new I18nSchema(this.locales, this.item, true);
|
215
|
-
}
|
216
|
-
}, {
|
217
|
-
key: "serialize",
|
218
|
-
value: function serialize() {
|
219
|
-
return {
|
220
|
-
type: "i18n",
|
221
|
-
item: this.item.serialize(),
|
222
|
-
locales: this.locales,
|
223
|
-
opt: this.opt
|
224
|
-
};
|
225
|
-
}
|
226
|
-
}]);
|
227
|
-
return I18nSchema;
|
228
|
-
}(SelectorProxy.Schema);
|
229
|
-
var i18n = function i18n(locales) {
|
230
|
-
return function (schema) {
|
231
|
-
return new I18nSchema(locales, schema);
|
232
|
-
};
|
233
|
-
};
|
234
|
-
|
235
332
|
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
236
|
-
|
237
|
-
var _super =
|
333
|
+
index._inherits(UnionSchema, _Schema);
|
334
|
+
var _super = index._createSuper(UnionSchema);
|
238
335
|
function UnionSchema(key, items) {
|
239
336
|
var _this;
|
240
337
|
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
241
|
-
|
338
|
+
index._classCallCheck(this, UnionSchema);
|
242
339
|
_this = _super.call(this);
|
243
340
|
_this.key = key;
|
244
341
|
_this.items = items;
|
245
342
|
_this.opt = opt;
|
246
343
|
return _this;
|
247
344
|
}
|
248
|
-
|
345
|
+
index._createClass(UnionSchema, [{
|
249
346
|
key: "validate",
|
250
347
|
value: function validate(path, src) {
|
251
348
|
throw new Error("Method not implemented.");
|
@@ -274,7 +371,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
274
371
|
}
|
275
372
|
}]);
|
276
373
|
return UnionSchema;
|
277
|
-
}(
|
374
|
+
}(index.Schema);
|
278
375
|
var union = function union(key) {
|
279
376
|
for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
280
377
|
objects[_key - 1] = arguments[_key];
|
@@ -283,47 +380,47 @@ var union = function union(key) {
|
|
283
380
|
};
|
284
381
|
|
285
382
|
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
286
|
-
|
287
|
-
var _super =
|
383
|
+
index._inherits(RichTextSchema, _Schema);
|
384
|
+
var _super = index._createSuper(RichTextSchema);
|
288
385
|
function RichTextSchema() {
|
289
386
|
var _this;
|
290
387
|
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
291
|
-
|
388
|
+
index._classCallCheck(this, RichTextSchema);
|
292
389
|
_this = _super.call(this);
|
293
390
|
_this.opt = opt;
|
294
391
|
return _this;
|
295
392
|
}
|
296
|
-
|
393
|
+
index._createClass(RichTextSchema, [{
|
297
394
|
key: "validate",
|
298
395
|
value: function validate(path, src) {
|
299
396
|
if (this.opt && (src === null || src === undefined)) {
|
300
397
|
return false;
|
301
398
|
}
|
302
399
|
if (src === null || src === undefined) {
|
303
|
-
return
|
400
|
+
return index._defineProperty({}, path, [{
|
304
401
|
message: "Expected non-nullable got '".concat(src, "'")
|
305
402
|
}]);
|
306
403
|
}
|
307
|
-
if (
|
308
|
-
return
|
309
|
-
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(
|
404
|
+
if (index._typeof(src) !== "object" && !Array.isArray(src)) {
|
405
|
+
return index._defineProperty({}, path, [{
|
406
|
+
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(index._typeof(src), "'"),
|
310
407
|
value: src
|
311
408
|
}]);
|
312
409
|
}
|
313
|
-
if (src[
|
314
|
-
return
|
315
|
-
message: "Expected _type key with value 'richtext' got '".concat(src[
|
410
|
+
if (src[index.VAL_EXTENSION] !== "richtext") {
|
411
|
+
return index._defineProperty({}, path, [{
|
412
|
+
message: "Expected _type key with value 'richtext' got '".concat(src[index.VAL_EXTENSION], "'"),
|
316
413
|
value: src
|
317
414
|
}]);
|
318
415
|
}
|
319
416
|
if (src.type !== "root") {
|
320
|
-
return
|
417
|
+
return index._defineProperty({}, path, [{
|
321
418
|
message: "Expected type key with value 'root' got '".concat(src.type, "'"),
|
322
419
|
value: src
|
323
420
|
}]);
|
324
421
|
}
|
325
|
-
if (
|
326
|
-
return
|
422
|
+
if (index._typeof(src.children) !== "object" && !Array.isArray(src.children)) {
|
423
|
+
return index._defineProperty({}, path, [{
|
327
424
|
message: "Expected children to be an array, but got '".concat(src.type, "'"),
|
328
425
|
value: src
|
329
426
|
}]);
|
@@ -351,7 +448,7 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
|
351
448
|
}
|
352
449
|
}]);
|
353
450
|
return RichTextSchema;
|
354
|
-
}(
|
451
|
+
}(index.Schema);
|
355
452
|
var richtext = function richtext() {
|
356
453
|
return new RichTextSchema();
|
357
454
|
};
|
@@ -363,11 +460,12 @@ id,
|
|
363
460
|
schema,
|
364
461
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
365
462
|
source) {
|
366
|
-
|
463
|
+
var _ref;
|
464
|
+
return _ref = {}, index._defineProperty(_ref, index.GetSource, source), index._defineProperty(_ref, index.GetSchema, schema), index._defineProperty(_ref, index.Path, id), _ref;
|
367
465
|
}
|
368
|
-
function
|
369
|
-
var sourceOrExpr = valModule[
|
370
|
-
if (sourceOrExpr instanceof
|
466
|
+
function getSource(valModule) {
|
467
|
+
var sourceOrExpr = valModule[index.GetSource];
|
468
|
+
if (sourceOrExpr instanceof index.Expr) {
|
371
469
|
throw Error("Cannot get raw source of an Expr");
|
372
470
|
}
|
373
471
|
var source = sourceOrExpr;
|
@@ -377,28 +475,45 @@ function splitModuleIdAndModulePath(path) {
|
|
377
475
|
return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
|
378
476
|
}
|
379
477
|
function isObjectSchema(schema) {
|
380
|
-
return schema instanceof ObjectSchema ||
|
478
|
+
return schema instanceof ObjectSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
381
479
|
}
|
382
480
|
function isArraySchema(schema) {
|
383
|
-
return schema instanceof ArraySchema ||
|
384
|
-
}
|
385
|
-
function isI18nSchema(schema) {
|
386
|
-
return schema instanceof I18nSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "i18n";
|
481
|
+
return schema instanceof ArraySchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
387
482
|
}
|
483
|
+
|
484
|
+
// function isI18nSchema(
|
485
|
+
// schema: Schema<SelectorSource> | SerializedSchema
|
486
|
+
// ): schema is I18nSchema<readonly string[]> | SerializedI18nSchema {
|
487
|
+
// return (
|
488
|
+
// schema instanceof I18nSchema ||
|
489
|
+
// (typeof schema === "object" && "type" in schema && schema.type === "i18n")
|
490
|
+
// );
|
491
|
+
// }
|
492
|
+
|
388
493
|
function isUnionSchema(schema) {
|
389
|
-
return schema instanceof UnionSchema ||
|
494
|
+
return schema instanceof UnionSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "union";
|
390
495
|
}
|
391
496
|
|
392
497
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
393
498
|
function isRichTextSchema(schema) {
|
394
|
-
return schema instanceof RichTextSchema ||
|
499
|
+
return schema instanceof RichTextSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
|
395
500
|
}
|
396
501
|
function isImageSchema(schema) {
|
397
|
-
return schema instanceof
|
502
|
+
return schema instanceof index.ImageSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "image";
|
398
503
|
}
|
504
|
+
|
505
|
+
// function isOneOfSchema(
|
506
|
+
// schema: Schema<SelectorSource> | SerializedSchema
|
507
|
+
// ): schema is OneOfSchema<GenericSelector<SourceArray>> | SerializedOneOfSchema {
|
508
|
+
// return (
|
509
|
+
// schema instanceof OneOfSchema ||
|
510
|
+
// (typeof schema === "object" && "type" in schema && schema.type === "oneOf")
|
511
|
+
// );
|
512
|
+
// }
|
513
|
+
|
399
514
|
function resolvePath(path, valModule, schema) {
|
400
515
|
var parts = parsePath(path);
|
401
|
-
var origParts =
|
516
|
+
var origParts = index._toConsumableArray(parts);
|
402
517
|
var resolvedSchema = schema;
|
403
518
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
404
519
|
var resolvedSource = valModule;
|
@@ -411,8 +526,8 @@ function resolvePath(path, valModule, schema) {
|
|
411
526
|
if (Number.isNaN(Number(part))) {
|
412
527
|
throw Error("Invalid path: array schema ".concat(resolvedSchema, " must have ").concat(part, " a number as path"));
|
413
528
|
}
|
414
|
-
if (
|
415
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(
|
529
|
+
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
530
|
+
throw Error("Schema type error: expected source to be type of array, but got ".concat(index._typeof(resolvedSource)));
|
416
531
|
}
|
417
532
|
if (!resolvedSource[part]) {
|
418
533
|
var _resolvedSource;
|
@@ -421,23 +536,31 @@ function resolvePath(path, valModule, schema) {
|
|
421
536
|
resolvedSource = resolvedSource[part];
|
422
537
|
resolvedSchema = resolvedSchema.item;
|
423
538
|
} else if (isObjectSchema(resolvedSchema)) {
|
424
|
-
if (
|
425
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(
|
539
|
+
if (index._typeof(resolvedSource) !== "object") {
|
540
|
+
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
426
541
|
}
|
427
542
|
if (!resolvedSource[part]) {
|
428
543
|
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
429
544
|
}
|
430
545
|
resolvedSource = resolvedSource[part];
|
431
546
|
resolvedSchema = resolvedSchema.items[part];
|
432
|
-
|
433
|
-
if (!resolvedSchema.locales.includes(part)) {
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
547
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
548
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
549
|
+
// throw Error(
|
550
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
551
|
+
// ", "
|
552
|
+
// )}, but found: ${part}`
|
553
|
+
// );
|
554
|
+
// }
|
555
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
556
|
+
// throw Error(
|
557
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
558
|
+
// Object.keys(resolvedSource)
|
559
|
+
// )}`
|
560
|
+
// );
|
561
|
+
// }
|
562
|
+
// resolvedSource = resolvedSource[part];
|
563
|
+
// resolvedSchema = resolvedSchema.item;
|
441
564
|
} else if (isImageSchema(resolvedSchema)) {
|
442
565
|
return {
|
443
566
|
v: {
|
@@ -483,13 +606,20 @@ function resolvePath(path, valModule, schema) {
|
|
483
606
|
};
|
484
607
|
while (parts.length > 0) {
|
485
608
|
var _ret = _loop();
|
486
|
-
if (
|
609
|
+
if (index._typeof(_ret) === "object") return _ret.v;
|
487
610
|
}
|
488
611
|
if (parts.length > 0) {
|
489
612
|
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|
490
613
|
}
|
491
614
|
return {
|
492
|
-
path:
|
615
|
+
path: origParts.map(function (p) {
|
616
|
+
if (!Number.isNaN(Number(p))) {
|
617
|
+
return p;
|
618
|
+
} else {
|
619
|
+
return JSON.stringify(p);
|
620
|
+
}
|
621
|
+
}).join("."),
|
622
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
493
623
|
schema: resolvedSchema,
|
494
624
|
source: resolvedSource
|
495
625
|
};
|
@@ -531,8 +661,8 @@ function parsePath(input) {
|
|
531
661
|
return result;
|
532
662
|
}
|
533
663
|
|
534
|
-
var PatchError = /*#__PURE__*/
|
535
|
-
|
664
|
+
var PatchError = /*#__PURE__*/index._createClass(function PatchError(message) {
|
665
|
+
index._classCallCheck(this, PatchError);
|
536
666
|
this.message = message;
|
537
667
|
});
|
538
668
|
|
@@ -543,8 +673,10 @@ var PatchError = /*#__PURE__*/SelectorProxy._createClass(function PatchError(mes
|
|
543
673
|
exports.PatchError = PatchError;
|
544
674
|
exports.array = array;
|
545
675
|
exports.content = content;
|
546
|
-
exports.
|
547
|
-
exports.
|
676
|
+
exports.createValPathOfItem = createValPathOfItem;
|
677
|
+
exports.getSource = getSource;
|
678
|
+
exports.isSelector = isSelector;
|
679
|
+
exports.newSelectorProxy = newSelectorProxy;
|
548
680
|
exports.object = object;
|
549
681
|
exports.resolvePath = resolvePath;
|
550
682
|
exports.richtext = richtext;
|