@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
@@ -1,213 +1,8 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper,
|
2
|
-
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION
|
3
|
-
import {
|
1
|
+
import { _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, g as getValPath, S as Schema, d as _objectSpread2, e as _defineProperty, V as VAL_EXTENSION, f as _typeof, i as image, h as file, j as _slicedToArray, k as isFile, F as FILE_REF_PROP, n as newSelectorProxy, P as Path, l as createValPathOfItem, m as SourceOrExpr, o as isSelector, p as isSerializedVal, q as convertImageSource, r as getSchema, s as isVal } from './SelectorProxy-63c2d0e2.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION } from './SelectorProxy-63c2d0e2.esm.js';
|
3
|
+
import { a as array, o as object, u as union, r as richtext$1, i as i18n$1, c as content, P as PatchError, g as getRawSource, b as resolvePath, s as splitModuleIdAndModulePath } from './ops-74661336.esm.js';
|
4
|
+
export { i as expr } from './index-af761363.esm.js';
|
4
5
|
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok } from './result-b96df128.esm.js';
|
5
|
-
import { P as PatchError } from './ops-6fae92a1.esm.js';
|
6
|
-
|
7
|
-
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
8
|
-
_inherits(ObjectSchema, _Schema);
|
9
|
-
var _super = _createSuper(ObjectSchema);
|
10
|
-
function ObjectSchema(items) {
|
11
|
-
var _this;
|
12
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
13
|
-
_classCallCheck(this, ObjectSchema);
|
14
|
-
_this = _super.call(this);
|
15
|
-
_this.items = items;
|
16
|
-
_this.opt = opt;
|
17
|
-
return _this;
|
18
|
-
}
|
19
|
-
_createClass(ObjectSchema, [{
|
20
|
-
key: "validate",
|
21
|
-
value: function validate(src) {
|
22
|
-
throw new Error("Method not implemented.");
|
23
|
-
}
|
24
|
-
}, {
|
25
|
-
key: "match",
|
26
|
-
value: function match(src) {
|
27
|
-
if (this.opt && (src === null || src === undefined)) {
|
28
|
-
return true;
|
29
|
-
}
|
30
|
-
if (!src) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
|
34
|
-
// TODO: checks all props
|
35
|
-
|
36
|
-
return _typeof(src) === "object" && !Array.isArray(src);
|
37
|
-
}
|
38
|
-
}, {
|
39
|
-
key: "optional",
|
40
|
-
value: function optional() {
|
41
|
-
return new ObjectSchema(this.items, true);
|
42
|
-
}
|
43
|
-
}, {
|
44
|
-
key: "serialize",
|
45
|
-
value: function serialize() {
|
46
|
-
return {
|
47
|
-
type: "object",
|
48
|
-
items: Object.fromEntries(Object.entries(this.items).map(function (_ref) {
|
49
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
50
|
-
key = _ref2[0],
|
51
|
-
schema = _ref2[1];
|
52
|
-
return [key, schema.serialize()];
|
53
|
-
})),
|
54
|
-
opt: this.opt
|
55
|
-
};
|
56
|
-
}
|
57
|
-
}]);
|
58
|
-
return ObjectSchema;
|
59
|
-
}(Schema);
|
60
|
-
var object = function object(schema) {
|
61
|
-
return new ObjectSchema(schema);
|
62
|
-
};
|
63
|
-
|
64
|
-
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
65
|
-
_inherits(ArraySchema, _Schema);
|
66
|
-
var _super = _createSuper(ArraySchema);
|
67
|
-
function ArraySchema(item) {
|
68
|
-
var _this;
|
69
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
70
|
-
_classCallCheck(this, ArraySchema);
|
71
|
-
_this = _super.call(this);
|
72
|
-
_this.item = item;
|
73
|
-
_this.opt = opt;
|
74
|
-
return _this;
|
75
|
-
}
|
76
|
-
_createClass(ArraySchema, [{
|
77
|
-
key: "validate",
|
78
|
-
value: function validate(src) {
|
79
|
-
throw new Error("Method not implemented.");
|
80
|
-
}
|
81
|
-
}, {
|
82
|
-
key: "match",
|
83
|
-
value: function match(src) {
|
84
|
-
if (this.opt && (src === null || src === undefined)) {
|
85
|
-
return true;
|
86
|
-
}
|
87
|
-
if (!src) {
|
88
|
-
return false;
|
89
|
-
}
|
90
|
-
|
91
|
-
// TODO: checks all items
|
92
|
-
return _typeof(src) === "object" && Array.isArray(src);
|
93
|
-
}
|
94
|
-
}, {
|
95
|
-
key: "optional",
|
96
|
-
value: function optional() {
|
97
|
-
return new ArraySchema(this.item, true);
|
98
|
-
}
|
99
|
-
}, {
|
100
|
-
key: "serialize",
|
101
|
-
value: function serialize() {
|
102
|
-
return {
|
103
|
-
type: "array",
|
104
|
-
item: this.item.serialize(),
|
105
|
-
opt: this.opt
|
106
|
-
};
|
107
|
-
}
|
108
|
-
}]);
|
109
|
-
return ArraySchema;
|
110
|
-
}(Schema);
|
111
|
-
var array = function array(schema) {
|
112
|
-
return new ArraySchema(schema);
|
113
|
-
};
|
114
|
-
|
115
|
-
var I18nSchema = /*#__PURE__*/function (_Schema) {
|
116
|
-
_inherits(I18nSchema, _Schema);
|
117
|
-
var _super = _createSuper(I18nSchema);
|
118
|
-
function I18nSchema(locales, item) {
|
119
|
-
var _this;
|
120
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
121
|
-
_classCallCheck(this, I18nSchema);
|
122
|
-
_this = _super.call(this);
|
123
|
-
_this.locales = locales;
|
124
|
-
_this.item = item;
|
125
|
-
_this.opt = opt;
|
126
|
-
return _this;
|
127
|
-
}
|
128
|
-
_createClass(I18nSchema, [{
|
129
|
-
key: "validate",
|
130
|
-
value: function validate(src) {
|
131
|
-
throw new Error("Method not implemented.");
|
132
|
-
}
|
133
|
-
}, {
|
134
|
-
key: "match",
|
135
|
-
value: function match(src) {
|
136
|
-
throw new Error("Method not implemented.");
|
137
|
-
}
|
138
|
-
}, {
|
139
|
-
key: "optional",
|
140
|
-
value: function optional() {
|
141
|
-
return new I18nSchema(this.locales, this.item, true);
|
142
|
-
}
|
143
|
-
}, {
|
144
|
-
key: "serialize",
|
145
|
-
value: function serialize() {
|
146
|
-
return {
|
147
|
-
type: "i18n",
|
148
|
-
item: this.item.serialize(),
|
149
|
-
locales: this.locales,
|
150
|
-
opt: this.opt
|
151
|
-
};
|
152
|
-
}
|
153
|
-
}]);
|
154
|
-
return I18nSchema;
|
155
|
-
}(Schema);
|
156
|
-
var i18n$1 = function i18n(locales) {
|
157
|
-
return function (schema) {
|
158
|
-
return new I18nSchema(locales, schema);
|
159
|
-
};
|
160
|
-
};
|
161
|
-
|
162
|
-
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
163
|
-
_inherits(UnionSchema, _Schema);
|
164
|
-
var _super = _createSuper(UnionSchema);
|
165
|
-
function UnionSchema(key, items) {
|
166
|
-
var _this;
|
167
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
168
|
-
_classCallCheck(this, UnionSchema);
|
169
|
-
_this = _super.call(this);
|
170
|
-
_this.key = key;
|
171
|
-
_this.items = items;
|
172
|
-
_this.opt = opt;
|
173
|
-
return _this;
|
174
|
-
}
|
175
|
-
_createClass(UnionSchema, [{
|
176
|
-
key: "validate",
|
177
|
-
value: function validate(src) {
|
178
|
-
throw new Error("Method not implemented.");
|
179
|
-
}
|
180
|
-
}, {
|
181
|
-
key: "match",
|
182
|
-
value: function match(src) {
|
183
|
-
throw new Error("Method not implemented.");
|
184
|
-
}
|
185
|
-
}, {
|
186
|
-
key: "optional",
|
187
|
-
value: function optional() {
|
188
|
-
throw new Error("Method not implemented.");
|
189
|
-
}
|
190
|
-
}, {
|
191
|
-
key: "serialize",
|
192
|
-
value: function serialize() {
|
193
|
-
return {
|
194
|
-
type: "union",
|
195
|
-
key: this.key,
|
196
|
-
items: this.items.map(function (o) {
|
197
|
-
return o.serialize();
|
198
|
-
}),
|
199
|
-
opt: this.opt
|
200
|
-
};
|
201
|
-
}
|
202
|
-
}]);
|
203
|
-
return UnionSchema;
|
204
|
-
}(Schema);
|
205
|
-
var union = function union(key) {
|
206
|
-
for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
207
|
-
objects[_key - 1] = arguments[_key];
|
208
|
-
}
|
209
|
-
return new UnionSchema(key, objects);
|
210
|
-
};
|
211
6
|
|
212
7
|
var OneOfSchema = /*#__PURE__*/function (_Schema) {
|
213
8
|
_inherits(OneOfSchema, _Schema);
|
@@ -223,12 +18,12 @@ var OneOfSchema = /*#__PURE__*/function (_Schema) {
|
|
223
18
|
}
|
224
19
|
_createClass(OneOfSchema, [{
|
225
20
|
key: "validate",
|
226
|
-
value: function validate(src) {
|
21
|
+
value: function validate(path, src) {
|
227
22
|
throw new Error("Method not implemented.");
|
228
23
|
}
|
229
24
|
}, {
|
230
|
-
key: "
|
231
|
-
value: function
|
25
|
+
key: "assert",
|
26
|
+
value: function assert(src) {
|
232
27
|
throw new Error("Method not implemented.");
|
233
28
|
}
|
234
29
|
}, {
|
@@ -256,223 +51,6 @@ var oneOf = function oneOf(valModule) {
|
|
256
51
|
return new OneOfSchema(valModule);
|
257
52
|
};
|
258
53
|
|
259
|
-
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
260
|
-
_inherits(RichTextSchema, _Schema);
|
261
|
-
var _super = _createSuper(RichTextSchema);
|
262
|
-
function RichTextSchema() {
|
263
|
-
var _this;
|
264
|
-
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
265
|
-
_classCallCheck(this, RichTextSchema);
|
266
|
-
_this = _super.call(this);
|
267
|
-
_this.opt = opt;
|
268
|
-
return _this;
|
269
|
-
}
|
270
|
-
_createClass(RichTextSchema, [{
|
271
|
-
key: "validate",
|
272
|
-
value: function validate(src) {
|
273
|
-
throw new Error("Method not implemented.");
|
274
|
-
}
|
275
|
-
}, {
|
276
|
-
key: "match",
|
277
|
-
value: function match(src) {
|
278
|
-
// TODO:
|
279
|
-
return true;
|
280
|
-
}
|
281
|
-
}, {
|
282
|
-
key: "optional",
|
283
|
-
value: function optional() {
|
284
|
-
return new RichTextSchema(true);
|
285
|
-
}
|
286
|
-
}, {
|
287
|
-
key: "serialize",
|
288
|
-
value: function serialize() {
|
289
|
-
return {
|
290
|
-
type: "richtext",
|
291
|
-
opt: this.opt
|
292
|
-
};
|
293
|
-
}
|
294
|
-
}]);
|
295
|
-
return RichTextSchema;
|
296
|
-
}(Schema);
|
297
|
-
var richtext$1 = function richtext() {
|
298
|
-
return new RichTextSchema();
|
299
|
-
};
|
300
|
-
|
301
|
-
function content(
|
302
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
303
|
-
id,
|
304
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
305
|
-
schema,
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
307
|
-
source) {
|
308
|
-
return newSelectorProxy(source, id, schema);
|
309
|
-
}
|
310
|
-
function getRawSource(valModule) {
|
311
|
-
var sourceOrExpr = valModule[SourceOrExpr];
|
312
|
-
if (sourceOrExpr instanceof Expr) {
|
313
|
-
throw Error("Cannot get raw source of an Expr");
|
314
|
-
}
|
315
|
-
var source = sourceOrExpr;
|
316
|
-
return source;
|
317
|
-
}
|
318
|
-
function splitModuleIdAndModulePath(path) {
|
319
|
-
return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
|
320
|
-
}
|
321
|
-
function isObjectSchema(schema) {
|
322
|
-
return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
323
|
-
}
|
324
|
-
function isArraySchema(schema) {
|
325
|
-
return schema instanceof ArraySchema || _typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
326
|
-
}
|
327
|
-
function isI18nSchema(schema) {
|
328
|
-
return schema instanceof I18nSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "i18n";
|
329
|
-
}
|
330
|
-
function isUnionSchema(schema) {
|
331
|
-
return schema instanceof UnionSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "union";
|
332
|
-
}
|
333
|
-
|
334
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
335
|
-
function isRichTextSchema(schema) {
|
336
|
-
return schema instanceof RichTextSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
|
337
|
-
}
|
338
|
-
function isImageSchema(schema) {
|
339
|
-
return schema instanceof ImageSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "image";
|
340
|
-
}
|
341
|
-
function resolvePath(path, valModule, schema) {
|
342
|
-
var parts = parsePath(path);
|
343
|
-
var origParts = _toConsumableArray(parts);
|
344
|
-
var resolvedSchema = schema;
|
345
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
346
|
-
var resolvedSource = valModule;
|
347
|
-
var _loop = function _loop() {
|
348
|
-
var part = parts.shift();
|
349
|
-
if (part === undefined) {
|
350
|
-
throw Error("Unexpected undefined part");
|
351
|
-
}
|
352
|
-
if (isArraySchema(resolvedSchema)) {
|
353
|
-
if (Number.isNaN(Number(part))) {
|
354
|
-
throw Error("Invalid path: array schema ".concat(resolvedSchema, " must have ").concat(part, " a number as path"));
|
355
|
-
}
|
356
|
-
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
357
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
|
358
|
-
}
|
359
|
-
if (!resolvedSource[part]) {
|
360
|
-
var _resolvedSource;
|
361
|
-
throw Error("Invalid path: array source (length: ".concat((_resolvedSource = resolvedSource) === null || _resolvedSource === void 0 ? void 0 : _resolvedSource.length, ") did not have index ").concat(part, " from path: ").concat(path));
|
362
|
-
}
|
363
|
-
resolvedSource = resolvedSource[part];
|
364
|
-
resolvedSchema = resolvedSchema.item;
|
365
|
-
} else if (isObjectSchema(resolvedSchema)) {
|
366
|
-
if (_typeof(resolvedSource) !== "object") {
|
367
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
368
|
-
}
|
369
|
-
if (!resolvedSource[part]) {
|
370
|
-
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
371
|
-
}
|
372
|
-
resolvedSource = resolvedSource[part];
|
373
|
-
resolvedSchema = resolvedSchema.items[part];
|
374
|
-
} else if (isI18nSchema(resolvedSchema)) {
|
375
|
-
if (!resolvedSchema.locales.includes(part)) {
|
376
|
-
throw Error("Invalid path: i18n schema ".concat(resolvedSchema, " supports locales ").concat(resolvedSchema.locales.join(", "), ", but found: ").concat(part));
|
377
|
-
}
|
378
|
-
if (!Object.keys(resolvedSource).includes(part)) {
|
379
|
-
throw Error("Schema type error: expected source to be type of i18n with locale ".concat(part, ", but got ").concat(JSON.stringify(Object.keys(resolvedSource))));
|
380
|
-
}
|
381
|
-
resolvedSource = resolvedSource[part];
|
382
|
-
resolvedSchema = resolvedSchema.item;
|
383
|
-
} else if (isImageSchema(resolvedSchema)) {
|
384
|
-
return {
|
385
|
-
v: {
|
386
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
387
|
-
return JSON.stringify(p);
|
388
|
-
}).join("."),
|
389
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
390
|
-
schema: resolvedSchema,
|
391
|
-
source: resolvedSource
|
392
|
-
}
|
393
|
-
};
|
394
|
-
} else if (isUnionSchema(resolvedSchema)) {
|
395
|
-
var _key = resolvedSchema.key;
|
396
|
-
var keyValue = resolvedSource[_key];
|
397
|
-
if (!keyValue) {
|
398
|
-
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
399
|
-
}
|
400
|
-
var schemaOfUnionKey = resolvedSchema.items.find(
|
401
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
402
|
-
function (child) {
|
403
|
-
var _child$items, _child$items$_key;
|
404
|
-
return (child === null || child === void 0 ? void 0 : (_child$items = child.items) === null || _child$items === void 0 ? void 0 : (_child$items$_key = _child$items[_key]) === null || _child$items$_key === void 0 ? void 0 : _child$items$_key.value) === keyValue;
|
405
|
-
});
|
406
|
-
if (!schemaOfUnionKey) {
|
407
|
-
throw Error("Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key, " of value ").concat(keyValue, " in path: ").concat(path));
|
408
|
-
}
|
409
|
-
resolvedSchema = schemaOfUnionKey.items[part];
|
410
|
-
resolvedSource = resolvedSource[part];
|
411
|
-
} else if (isRichTextSchema(resolvedSchema)) {
|
412
|
-
return {
|
413
|
-
v: {
|
414
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
415
|
-
return JSON.stringify(p);
|
416
|
-
}).join("."),
|
417
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
418
|
-
schema: resolvedSchema,
|
419
|
-
source: resolvedSource
|
420
|
-
}
|
421
|
-
};
|
422
|
-
} else {
|
423
|
-
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
424
|
-
}
|
425
|
-
};
|
426
|
-
while (parts.length > 0) {
|
427
|
-
var _ret = _loop();
|
428
|
-
if (_typeof(_ret) === "object") return _ret.v;
|
429
|
-
}
|
430
|
-
if (parts.length > 0) {
|
431
|
-
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|
432
|
-
}
|
433
|
-
return {
|
434
|
-
path: path,
|
435
|
-
schema: resolvedSchema,
|
436
|
-
source: resolvedSource
|
437
|
-
};
|
438
|
-
}
|
439
|
-
function parsePath(input) {
|
440
|
-
var result = [];
|
441
|
-
var i = 0;
|
442
|
-
while (i < input.length) {
|
443
|
-
var part = "";
|
444
|
-
if (input[i] === '"') {
|
445
|
-
// Parse a quoted string
|
446
|
-
i++;
|
447
|
-
while (i < input.length && input[i] !== '"') {
|
448
|
-
if (input[i] === "\\" && input[i + 1] === '"') {
|
449
|
-
// Handle escaped double quotes
|
450
|
-
part += '"';
|
451
|
-
i++;
|
452
|
-
} else {
|
453
|
-
part += input[i];
|
454
|
-
}
|
455
|
-
i++;
|
456
|
-
}
|
457
|
-
if (input[i] !== '"') {
|
458
|
-
var _input$i;
|
459
|
-
throw new Error("Invalid input (".concat(JSON.stringify(input), "): Missing closing double quote: ").concat((_input$i = input[i]) !== null && _input$i !== void 0 ? _input$i : "at end of string", " (char: ").concat(i, "; length: ").concat(input.length, ")"));
|
460
|
-
}
|
461
|
-
} else {
|
462
|
-
// Parse a regular string
|
463
|
-
while (i < input.length && input[i] !== ".") {
|
464
|
-
part += input[i];
|
465
|
-
i++;
|
466
|
-
}
|
467
|
-
}
|
468
|
-
if (part !== "") {
|
469
|
-
result.push(part);
|
470
|
-
}
|
471
|
-
i++;
|
472
|
-
}
|
473
|
-
return result;
|
474
|
-
}
|
475
|
-
|
476
54
|
/**
|
477
55
|
* I18n sources cannot have nested remote sources.
|
478
56
|
*/
|
@@ -506,12 +84,21 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
506
84
|
}
|
507
85
|
_createClass(NumberSchema, [{
|
508
86
|
key: "validate",
|
509
|
-
value: function validate(src) {
|
510
|
-
|
87
|
+
value: function validate(path, src) {
|
88
|
+
if (this.opt && (src === null || src === undefined)) {
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
if (typeof src !== "number") {
|
92
|
+
return _defineProperty({}, path, [{
|
93
|
+
message: "Expected 'number', got '".concat(_typeof(src), "'"),
|
94
|
+
value: src
|
95
|
+
}]);
|
96
|
+
}
|
97
|
+
return false;
|
511
98
|
}
|
512
99
|
}, {
|
513
|
-
key: "
|
514
|
-
value: function
|
100
|
+
key: "assert",
|
101
|
+
value: function assert(src) {
|
515
102
|
if (this.opt && (src === null || src === undefined)) {
|
516
103
|
return true;
|
517
104
|
}
|
@@ -552,12 +139,21 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
552
139
|
}
|
553
140
|
_createClass(StringSchema, [{
|
554
141
|
key: "validate",
|
555
|
-
value: function validate(src) {
|
556
|
-
|
142
|
+
value: function validate(path, src) {
|
143
|
+
if (this.opt && (src === null || src === undefined)) {
|
144
|
+
return false;
|
145
|
+
}
|
146
|
+
if (typeof src !== "string") {
|
147
|
+
return _defineProperty({}, path, [{
|
148
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
149
|
+
value: src
|
150
|
+
}]);
|
151
|
+
}
|
152
|
+
return false;
|
557
153
|
}
|
558
154
|
}, {
|
559
|
-
key: "
|
560
|
-
value: function
|
155
|
+
key: "assert",
|
156
|
+
value: function assert(src) {
|
561
157
|
if (this.opt && (src === null || src === undefined)) {
|
562
158
|
return true;
|
563
159
|
}
|
@@ -597,12 +193,21 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
|
|
597
193
|
}
|
598
194
|
_createClass(BooleanSchema, [{
|
599
195
|
key: "validate",
|
600
|
-
value: function validate(src) {
|
601
|
-
|
196
|
+
value: function validate(path, src) {
|
197
|
+
if (this.opt && (src === null || src === undefined)) {
|
198
|
+
return false;
|
199
|
+
}
|
200
|
+
if (typeof src !== "boolean") {
|
201
|
+
return _defineProperty({}, path, [{
|
202
|
+
message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
|
203
|
+
value: src
|
204
|
+
}]);
|
205
|
+
}
|
206
|
+
return false;
|
602
207
|
}
|
603
208
|
}, {
|
604
|
-
key: "
|
605
|
-
value: function
|
209
|
+
key: "assert",
|
210
|
+
value: function assert(src) {
|
606
211
|
if (this.opt && (src === null || src === undefined)) {
|
607
212
|
return true;
|
608
213
|
}
|
@@ -642,12 +247,27 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
|
642
247
|
}
|
643
248
|
_createClass(LiteralSchema, [{
|
644
249
|
key: "validate",
|
645
|
-
value: function validate(src) {
|
646
|
-
|
250
|
+
value: function validate(path, src) {
|
251
|
+
if (this.opt && (src === null || src === undefined)) {
|
252
|
+
return false;
|
253
|
+
}
|
254
|
+
if (typeof src !== "string") {
|
255
|
+
return _defineProperty({}, path, [{
|
256
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
257
|
+
value: src
|
258
|
+
}]);
|
259
|
+
}
|
260
|
+
if (src !== this.value) {
|
261
|
+
return _defineProperty({}, path, [{
|
262
|
+
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
263
|
+
value: src
|
264
|
+
}]);
|
265
|
+
}
|
266
|
+
return false;
|
647
267
|
}
|
648
268
|
}, {
|
649
|
-
key: "
|
650
|
-
value: function
|
269
|
+
key: "assert",
|
270
|
+
value: function assert(src) {
|
651
271
|
if (this.opt && (src === null || src === undefined)) {
|
652
272
|
return true;
|
653
273
|
}
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('../../dist/index-
|
6
|
-
require('../../dist/
|
5
|
+
var expr_dist_valbuildCoreExpr = require('../../dist/index-2fff5ca8.cjs.dev.js');
|
6
|
+
var SelectorProxy = require('../../dist/SelectorProxy-873782a5.cjs.dev.js');
|
7
7
|
require('../../dist/result-48320acd.cjs.dev.js');
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
exports.Call = expr_dist_valbuildCoreExpr.Call;
|
12
|
-
exports.Expr = expr_dist_valbuildCoreExpr.Expr;
|
13
|
-
exports.NilSym = expr_dist_valbuildCoreExpr.NilSym;
|
14
|
-
exports.StringLiteral = expr_dist_valbuildCoreExpr.StringLiteral;
|
15
|
-
exports.StringTemplate = expr_dist_valbuildCoreExpr.StringTemplate;
|
16
|
-
exports.Sym = expr_dist_valbuildCoreExpr.Sym;
|
17
11
|
exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
|
18
12
|
exports.parse = expr_dist_valbuildCoreExpr.parse;
|
13
|
+
exports.Call = SelectorProxy.Call;
|
14
|
+
exports.Expr = SelectorProxy.Expr;
|
15
|
+
exports.NilSym = SelectorProxy.NilSym;
|
16
|
+
exports.StringLiteral = SelectorProxy.StringLiteral;
|
17
|
+
exports.StringTemplate = SelectorProxy.StringTemplate;
|
18
|
+
exports.Sym = SelectorProxy.Sym;
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('../../dist/index-
|
6
|
-
require('../../dist/
|
5
|
+
var expr_dist_valbuildCoreExpr = require('../../dist/index-cac9ecbd.cjs.prod.js');
|
6
|
+
var SelectorProxy = require('../../dist/SelectorProxy-2af1b2b8.cjs.prod.js');
|
7
7
|
require('../../dist/result-26f67b40.cjs.prod.js');
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
exports.Call = expr_dist_valbuildCoreExpr.Call;
|
12
|
-
exports.Expr = expr_dist_valbuildCoreExpr.Expr;
|
13
|
-
exports.NilSym = expr_dist_valbuildCoreExpr.NilSym;
|
14
|
-
exports.StringLiteral = expr_dist_valbuildCoreExpr.StringLiteral;
|
15
|
-
exports.StringTemplate = expr_dist_valbuildCoreExpr.StringTemplate;
|
16
|
-
exports.Sym = expr_dist_valbuildCoreExpr.Sym;
|
17
11
|
exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
|
18
12
|
exports.parse = expr_dist_valbuildCoreExpr.parse;
|
13
|
+
exports.Call = SelectorProxy.Call;
|
14
|
+
exports.Expr = SelectorProxy.Expr;
|
15
|
+
exports.NilSym = SelectorProxy.NilSym;
|
16
|
+
exports.StringLiteral = SelectorProxy.StringLiteral;
|
17
|
+
exports.StringTemplate = SelectorProxy.StringTemplate;
|
18
|
+
exports.Sym = SelectorProxy.Sym;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export {
|
2
|
-
|
1
|
+
export { e as evaluate, p as parse } from '../../dist/index-af761363.esm.js';
|
2
|
+
export { C as Call, E as Expr, N as NilSym, u as StringLiteral, v as StringTemplate, t as Sym } from '../../dist/SelectorProxy-63c2d0e2.esm.js';
|
3
3
|
import '../../dist/result-b96df128.esm.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/core",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.16.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "Val - supercharged hard-coded content",
|
6
6
|
"scripts": {
|
@@ -40,6 +40,7 @@
|
|
40
40
|
"exports": true
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
|
+
"image-size": "^1.0.2",
|
43
44
|
"ts-toolbelt": "^9.6.0"
|
44
45
|
}
|
45
46
|
}
|