@valbuild/core 0.72.3 → 0.73.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/declarations/src/index.d.ts +20 -4
- package/dist/declarations/src/initSchema.d.ts +4 -4
- package/dist/declarations/src/initVal.d.ts +3 -1
- package/dist/declarations/src/patch/index.d.ts +1 -1
- package/dist/declarations/src/patch/operation.d.ts +3 -0
- package/dist/declarations/src/remote/fileHash.d.ts +5 -0
- package/dist/declarations/src/remote/splitRemoteRef.d.ts +13 -0
- package/dist/declarations/src/remote/validationBasis.d.ts +13 -0
- package/dist/declarations/src/schema/file.d.ts +7 -3
- package/dist/declarations/src/schema/image.d.ts +7 -3
- package/dist/declarations/src/schema/remote.d.ts +11 -0
- package/dist/declarations/src/schema/richtext.d.ts +16 -7
- package/dist/declarations/src/schema/string.d.ts +8 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/declarations/src/selector/index.d.ts +2 -1
- package/dist/declarations/src/source/file.d.ts +2 -2
- package/dist/declarations/src/source/image.d.ts +2 -2
- package/dist/declarations/src/source/index.d.ts +3 -4
- package/dist/declarations/src/source/remote.d.ts +22 -0
- package/dist/declarations/src/source/richtext.d.ts +30 -3
- package/dist/declarations/src/val/index.d.ts +4 -3
- package/dist/{index-380b80a1.cjs.prod.js → index-da9933cf.cjs.prod.js} +687 -1412
- package/dist/{index-7ae61742.cjs.dev.js → index-f6fd3df3.cjs.dev.js} +687 -1412
- package/dist/{index-7218e8b1.esm.js → index-fee3aa6d.esm.js} +688 -1405
- package/dist/{result-168dfc1d.esm.js → result-daff1cae.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +27 -27
- package/dist/valbuild-core.cjs.prod.js +27 -27
- package/dist/valbuild-core.esm.js +2 -2
- package/fp/dist/valbuild-core-fp.esm.js +1 -1
- package/package.json +2 -9
- package/patch/dist/valbuild-core-patch.cjs.dev.js +38 -37
- package/patch/dist/valbuild-core-patch.cjs.prod.js +38 -37
- package/patch/dist/valbuild-core-patch.esm.js +5 -4
- package/dist/declarations/src/expr/eval.d.ts +0 -20
- package/dist/declarations/src/expr/expr.d.ts +0 -32
- package/dist/declarations/src/expr/index.d.ts +0 -3
- package/dist/declarations/src/expr/parser.d.ts +0 -8
- package/dist/declarations/src/future/fetchVal.d.ts +0 -5
- package/dist/declarations/src/selector/future/array.d.ts +0 -17
- package/dist/declarations/src/selector/future/boolean.d.ts +0 -2
- package/dist/declarations/src/selector/future/file.d.ts +0 -9
- package/dist/declarations/src/selector/future/i18n.d.ts +0 -11
- package/dist/declarations/src/selector/future/index.d.ts +0 -82
- package/dist/declarations/src/selector/future/number.d.ts +0 -2
- package/dist/declarations/src/selector/future/object.d.ts +0 -10
- package/dist/declarations/src/selector/future/primitive.d.ts +0 -9
- package/dist/declarations/src/selector/future/remote.d.ts +0 -7
- package/dist/declarations/src/selector/future/string.d.ts +0 -2
- package/dist/declarations/src/source/future/i18n.d.ts +0 -29
- package/dist/declarations/src/source/future/remote.d.ts +0 -29
- package/expr/dist/valbuild-core-expr.cjs.d.ts +0 -2
- package/expr/dist/valbuild-core-expr.cjs.dev.js +0 -17
- package/expr/dist/valbuild-core-expr.cjs.js +0 -7
- package/expr/dist/valbuild-core-expr.cjs.prod.js +0 -17
- package/expr/dist/valbuild-core-expr.esm.js +0 -2
- package/expr/package.json +0 -4
@@ -229,12 +229,12 @@ var Schema = /*#__PURE__*/function () {
|
|
229
229
|
/**
|
230
230
|
* @internal
|
231
231
|
*/
|
232
|
-
var GetSchema
|
232
|
+
var GetSchema = Symbol("GetSchema");
|
233
233
|
/**
|
234
234
|
/**
|
235
235
|
* @internal
|
236
236
|
*/
|
237
|
-
var Path
|
237
|
+
var Path = Symbol("Path");
|
238
238
|
/**
|
239
239
|
* @internal
|
240
240
|
*/
|
@@ -245,10 +245,10 @@ var GetSource = Symbol("GetSource");
|
|
245
245
|
var ValError = Symbol("ValError");
|
246
246
|
var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
|
247
247
|
_classCallCheck(this, GenericSelector);
|
248
|
-
this[Path
|
248
|
+
this[Path] = path;
|
249
249
|
this[GetSource] = valOrExpr;
|
250
250
|
this[ValError] = error;
|
251
|
-
this[GetSchema
|
251
|
+
this[GetSchema] = schema;
|
252
252
|
});
|
253
253
|
|
254
254
|
/**
|
@@ -258,99 +258,9 @@ var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrEx
|
|
258
258
|
**/
|
259
259
|
|
260
260
|
function getSchema(selector) {
|
261
|
-
return selector[GetSchema
|
261
|
+
return selector[GetSchema];
|
262
262
|
}
|
263
263
|
|
264
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
265
|
-
|
266
|
-
var Expr = /*#__PURE__*/_createClass(function Expr(span) {
|
267
|
-
_classCallCheck(this, Expr);
|
268
|
-
this.span = span;
|
269
|
-
});
|
270
|
-
var StringLiteral = /*#__PURE__*/function (_Expr) {
|
271
|
-
function StringLiteral(value, span) {
|
272
|
-
var _this;
|
273
|
-
_classCallCheck(this, StringLiteral);
|
274
|
-
_this = _callSuper(this, StringLiteral, [span]);
|
275
|
-
_defineProperty(_this, "type", "StringLiteral");
|
276
|
-
_this.value = value;
|
277
|
-
return _this;
|
278
|
-
}
|
279
|
-
_inherits(StringLiteral, _Expr);
|
280
|
-
return _createClass(StringLiteral, [{
|
281
|
-
key: "transpile",
|
282
|
-
value: function transpile() {
|
283
|
-
return "'".concat(this.value, "'");
|
284
|
-
}
|
285
|
-
}]);
|
286
|
-
}(Expr);
|
287
|
-
var Sym = /*#__PURE__*/function (_Expr2) {
|
288
|
-
function Sym(value, span) {
|
289
|
-
var _this2;
|
290
|
-
_classCallCheck(this, Sym);
|
291
|
-
_this2 = _callSuper(this, Sym, [span]);
|
292
|
-
_defineProperty(_this2, "type", "Sym");
|
293
|
-
_this2.value = value;
|
294
|
-
return _this2;
|
295
|
-
}
|
296
|
-
_inherits(Sym, _Expr2);
|
297
|
-
return _createClass(Sym, [{
|
298
|
-
key: "transpile",
|
299
|
-
value: function transpile() {
|
300
|
-
return this.value;
|
301
|
-
}
|
302
|
-
}]);
|
303
|
-
}(Expr);
|
304
|
-
var NilSym = new Sym("()");
|
305
|
-
var StringTemplate = /*#__PURE__*/function (_Expr3) {
|
306
|
-
function StringTemplate(children, span) {
|
307
|
-
var _this3;
|
308
|
-
_classCallCheck(this, StringTemplate);
|
309
|
-
_this3 = _callSuper(this, StringTemplate, [span]);
|
310
|
-
_defineProperty(_this3, "type", "StringTemplate");
|
311
|
-
_this3.children = children;
|
312
|
-
return _this3;
|
313
|
-
}
|
314
|
-
_inherits(StringTemplate, _Expr3);
|
315
|
-
return _createClass(StringTemplate, [{
|
316
|
-
key: "transpile",
|
317
|
-
value: function transpile() {
|
318
|
-
return "'".concat(this.children.map(function (child) {
|
319
|
-
if (child instanceof StringLiteral) {
|
320
|
-
return child.value;
|
321
|
-
} else {
|
322
|
-
return "${".concat(child.transpile(), "}");
|
323
|
-
}
|
324
|
-
}).join(""), "'");
|
325
|
-
}
|
326
|
-
}]);
|
327
|
-
}(Expr);
|
328
|
-
var Call = /*#__PURE__*/function (_Expr4) {
|
329
|
-
function Call(children, isAnon, span) {
|
330
|
-
var _this4;
|
331
|
-
_classCallCheck(this, Call);
|
332
|
-
_this4 = _callSuper(this, Call, [span]);
|
333
|
-
_defineProperty(_this4, "type", "Call");
|
334
|
-
_this4.children = children;
|
335
|
-
_this4.isAnon = isAnon;
|
336
|
-
return _this4;
|
337
|
-
}
|
338
|
-
_inherits(Call, _Expr4);
|
339
|
-
return _createClass(Call, [{
|
340
|
-
key: "transpile",
|
341
|
-
value: function transpile() {
|
342
|
-
if (this.isAnon) {
|
343
|
-
return "!(".concat(this.children.map(function (child) {
|
344
|
-
return child.transpile();
|
345
|
-
}).join(" "), ")");
|
346
|
-
}
|
347
|
-
return "(".concat(this.children.map(function (child) {
|
348
|
-
return child.transpile();
|
349
|
-
}).join(" "), ")");
|
350
|
-
}
|
351
|
-
}]);
|
352
|
-
}(Expr);
|
353
|
-
|
354
264
|
/* Branded extension types: file, remote, i18n */
|
355
265
|
var VAL_EXTENSION = "_type";
|
356
266
|
|
@@ -421,14 +331,21 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
421
331
|
function FileSchema(options) {
|
422
332
|
var _this;
|
423
333
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
334
|
+
var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
424
335
|
_classCallCheck(this, FileSchema);
|
425
336
|
_this = _callSuper(this, FileSchema);
|
426
337
|
_this.options = options;
|
427
338
|
_this.opt = opt;
|
339
|
+
_this.isRemote = isRemote;
|
428
340
|
return _this;
|
429
341
|
}
|
430
342
|
_inherits(FileSchema, _Schema);
|
431
343
|
return _createClass(FileSchema, [{
|
344
|
+
key: "remote",
|
345
|
+
value: function remote() {
|
346
|
+
return new FileSchema(this.options, this.opt, true);
|
347
|
+
}
|
348
|
+
}, {
|
432
349
|
key: "validate",
|
433
350
|
value: function validate(path, src) {
|
434
351
|
if (this.opt && (src === null || src === undefined)) {
|
@@ -446,6 +363,27 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
446
363
|
value: src
|
447
364
|
}]);
|
448
365
|
}
|
366
|
+
if (this.isRemote && src[VAL_EXTENSION] !== "remote") {
|
367
|
+
return _defineProperty({}, path, [{
|
368
|
+
message: "Expected a remote file, but got a local file.",
|
369
|
+
value: src,
|
370
|
+
fixes: ["file:upload-remote"]
|
371
|
+
}]);
|
372
|
+
}
|
373
|
+
if (this.isRemote && src[VAL_EXTENSION] === "remote") {
|
374
|
+
return _defineProperty({}, path, [{
|
375
|
+
message: "Remote file was not checked.",
|
376
|
+
value: src,
|
377
|
+
fixes: ["file:check-remote"]
|
378
|
+
}]);
|
379
|
+
}
|
380
|
+
if (!this.isRemote && src[VAL_EXTENSION] === "remote") {
|
381
|
+
return _defineProperty({}, path, [{
|
382
|
+
message: "Expected locale file, but found remote.",
|
383
|
+
value: src,
|
384
|
+
fixes: ["file:download-remote"]
|
385
|
+
}]);
|
386
|
+
}
|
449
387
|
if (src[VAL_EXTENSION] !== "file") {
|
450
388
|
return _defineProperty({}, path, [{
|
451
389
|
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
@@ -453,10 +391,10 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
453
391
|
fixes: ["file:change-extension", "file:check-metadata"]
|
454
392
|
}]);
|
455
393
|
}
|
456
|
-
var
|
457
|
-
accept =
|
458
|
-
var
|
459
|
-
mimeType =
|
394
|
+
var _ref7 = this.options || {},
|
395
|
+
accept = _ref7.accept;
|
396
|
+
var _ref8 = src.metadata || {},
|
397
|
+
mimeType = _ref8.mimeType;
|
460
398
|
if (accept && mimeType && !mimeType.includes("/")) {
|
461
399
|
return _defineProperty({}, path, [{
|
462
400
|
message: "Invalid mime type format. Got: ".concat(mimeType),
|
@@ -576,7 +514,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
576
514
|
return {
|
577
515
|
type: "file",
|
578
516
|
options: this.options,
|
579
|
-
opt: this.opt
|
517
|
+
opt: this.opt,
|
518
|
+
remote: this.isRemote
|
580
519
|
};
|
581
520
|
}
|
582
521
|
}]);
|
@@ -604,11 +543,8 @@ function convertFileSource(src) {
|
|
604
543
|
};
|
605
544
|
}
|
606
545
|
|
607
|
-
function isSerializedVal(val) {
|
608
|
-
return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
|
609
|
-
}
|
610
546
|
function isVal(val) {
|
611
|
-
return _typeof(val) === "object" && val !== null && val !== undefined && Path
|
547
|
+
return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
|
612
548
|
}
|
613
549
|
|
614
550
|
/**
|
@@ -637,136 +573,9 @@ function isVal(val) {
|
|
637
573
|
*/
|
638
574
|
|
639
575
|
function getValPath(valOrSelector) {
|
640
|
-
return valOrSelector[Path
|
576
|
+
return valOrSelector[Path];
|
641
577
|
}
|
642
578
|
|
643
|
-
function hasOwn$2(obj, prop) {
|
644
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
645
|
-
}
|
646
|
-
function _andThen$1(f, source, path) {
|
647
|
-
if (source) {
|
648
|
-
return newSelectorProxy$1(f(newSelectorProxy$1(source, path)));
|
649
|
-
}
|
650
|
-
return newSelectorProxy$1(source, path);
|
651
|
-
}
|
652
|
-
function isSelector$1(source) {
|
653
|
-
return _typeof(source) === "object" && source !== null && (GetSource in source || Path$1 in source);
|
654
|
-
}
|
655
|
-
function newSelectorProxy$1(source, path, moduleSchema) {
|
656
|
-
if (_typeof(source) === "object") {
|
657
|
-
if (isSelector$1(source)) {
|
658
|
-
return source;
|
659
|
-
} else if (isSerializedVal(source)) {
|
660
|
-
return newSelectorProxy$1(source.val, source.valPath);
|
661
|
-
}
|
662
|
-
}
|
663
|
-
if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
|
664
|
-
var fileRef = source[FILE_REF_PROP];
|
665
|
-
if (typeof fileRef !== "string") {
|
666
|
-
throw Error("Invalid file ref: " + fileRef);
|
667
|
-
}
|
668
|
-
return newSelectorProxy$1(convertFileSource(source), path, moduleSchema);
|
669
|
-
}
|
670
|
-
switch (_typeof(source)) {
|
671
|
-
case "function":
|
672
|
-
case "symbol":
|
673
|
-
throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
|
674
|
-
case "object":
|
675
|
-
// Handles both objects and arrays!
|
676
|
-
if (source !== null) {
|
677
|
-
return new Proxy(source, {
|
678
|
-
// TODO: see proxy docs if we want more traps
|
679
|
-
has: function has(target, prop) {
|
680
|
-
if (prop === GetSource) {
|
681
|
-
return true;
|
682
|
-
}
|
683
|
-
if (prop === Path$1) {
|
684
|
-
return true;
|
685
|
-
}
|
686
|
-
if (prop === "andThen") {
|
687
|
-
return true;
|
688
|
-
}
|
689
|
-
if (prop === GetSchema$1) {
|
690
|
-
return true;
|
691
|
-
}
|
692
|
-
return prop in target;
|
693
|
-
},
|
694
|
-
get: function get(target, prop) {
|
695
|
-
if (prop === GetSource) {
|
696
|
-
return source;
|
697
|
-
}
|
698
|
-
if (prop === Path$1) {
|
699
|
-
return path;
|
700
|
-
}
|
701
|
-
if (prop === GetSchema$1) {
|
702
|
-
return moduleSchema;
|
703
|
-
}
|
704
|
-
if (prop === "andThen") {
|
705
|
-
return function (f) {
|
706
|
-
return _andThen$1(f, source, path);
|
707
|
-
};
|
708
|
-
}
|
709
|
-
if (Array.isArray(target)) {
|
710
|
-
if (prop === "filter") {
|
711
|
-
return function (f) {
|
712
|
-
var filtered = target.map(function (a, i) {
|
713
|
-
return newSelectorProxy$1(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
714
|
-
}).filter(function (a) {
|
715
|
-
if (f && f instanceof Schema) {
|
716
|
-
return f.assert(path || "", unValify$1(a)).success;
|
717
|
-
} else {
|
718
|
-
return unValify$1(f(a));
|
719
|
-
}
|
720
|
-
});
|
721
|
-
return newSelectorProxy$1(filtered, path, moduleSchema);
|
722
|
-
};
|
723
|
-
} else if (prop === "map") {
|
724
|
-
return function (f) {
|
725
|
-
var filtered = target.map(function (a, i) {
|
726
|
-
var valueOrSelector = f(newSelectorProxy$1(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy$1(i));
|
727
|
-
if (isSelector$1(valueOrSelector)) {
|
728
|
-
return valueOrSelector;
|
729
|
-
}
|
730
|
-
return newSelectorProxy$1(valueOrSelector);
|
731
|
-
});
|
732
|
-
return newSelectorProxy$1(filtered, path, moduleSchema);
|
733
|
-
};
|
734
|
-
}
|
735
|
-
}
|
736
|
-
if (Array.isArray(target) && prop === "length") {
|
737
|
-
return newSelectorProxy$1(target.length);
|
738
|
-
}
|
739
|
-
var reflectedValue = Reflect.get(target, prop);
|
740
|
-
if (hasOwn$2(source, prop)) {
|
741
|
-
if (!Number.isNaN(Number(prop))) {
|
742
|
-
return newSelectorProxy$1(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
743
|
-
}
|
744
|
-
return newSelectorProxy$1(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
745
|
-
}
|
746
|
-
return reflectedValue;
|
747
|
-
}
|
748
|
-
});
|
749
|
-
}
|
750
|
-
// intentional fallthrough
|
751
|
-
// eslint-disable-next-line no-fallthrough
|
752
|
-
default:
|
753
|
-
return _defineProperty(_defineProperty(_defineProperty({
|
754
|
-
eq: function eq(other) {
|
755
|
-
var otherValue = other;
|
756
|
-
if (isSelector$1(other)) {
|
757
|
-
otherValue = other[GetSource];
|
758
|
-
if (otherValue instanceof Expr) {
|
759
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
760
|
-
}
|
761
|
-
}
|
762
|
-
return newSelectorProxy$1(source === otherValue, undefined);
|
763
|
-
},
|
764
|
-
andThen: function andThen(f) {
|
765
|
-
return _andThen$1(f, source === undefined ? null : source, path);
|
766
|
-
}
|
767
|
-
}, GetSource, source === undefined ? null : source), Path$1, path), GetSchema$1, moduleSchema);
|
768
|
-
}
|
769
|
-
}
|
770
579
|
function createValPathOfItem(arrayPath, prop) {
|
771
580
|
if (_typeof(prop) === "symbol") {
|
772
581
|
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
@@ -794,15 +603,6 @@ function unsafeCreateSourcePath(path, itemKey) {
|
|
794
603
|
return "".concat(path).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(itemKey));
|
795
604
|
}
|
796
605
|
|
797
|
-
// TODO: could we do .val on the objects instead?
|
798
|
-
function unValify$1(valueOrSelector) {
|
799
|
-
if (_typeof(valueOrSelector) === "object" && (GetSource in valueOrSelector || Path$1 in valueOrSelector)) {
|
800
|
-
var selectorValue = valueOrSelector[GetSource];
|
801
|
-
return selectorValue;
|
802
|
-
}
|
803
|
-
return valueOrSelector;
|
804
|
-
}
|
805
|
-
|
806
606
|
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
807
607
|
function ObjectSchema(items) {
|
808
608
|
var _this;
|
@@ -946,634 +746,6 @@ var object = function object(schema) {
|
|
946
746
|
return new ObjectSchema(schema);
|
947
747
|
};
|
948
748
|
|
949
|
-
var WHITE_SPACE = ["\n", "\r", "\t", " "];
|
950
|
-
function tokenize(input) {
|
951
|
-
var tokens = [];
|
952
|
-
var cursor = 0;
|
953
|
-
while (cursor < input.length) {
|
954
|
-
var _char = input[cursor];
|
955
|
-
var peek = input[cursor + 1];
|
956
|
-
// TODO: remove this not used any more
|
957
|
-
if (_char === "!" && peek === "(") {
|
958
|
-
tokens.push({
|
959
|
-
type: "!(",
|
960
|
-
span: [cursor, cursor + 1]
|
961
|
-
});
|
962
|
-
cursor += 2;
|
963
|
-
} else if (_char === "(") {
|
964
|
-
tokens.push({
|
965
|
-
type: "(",
|
966
|
-
span: [cursor, cursor]
|
967
|
-
});
|
968
|
-
cursor++;
|
969
|
-
} else if (_char === ")") {
|
970
|
-
tokens.push({
|
971
|
-
type: ")",
|
972
|
-
span: [cursor, cursor]
|
973
|
-
});
|
974
|
-
cursor++;
|
975
|
-
} else if (_char === "'" || _char === "}") {
|
976
|
-
var start = cursor;
|
977
|
-
var value = "";
|
978
|
-
var unescapedValue = "";
|
979
|
-
var escaped = false;
|
980
|
-
if (_char === "}") {
|
981
|
-
tokens.push({
|
982
|
-
type: "}",
|
983
|
-
span: [cursor, cursor]
|
984
|
-
});
|
985
|
-
} else if (_char === "'") {
|
986
|
-
tokens.push({
|
987
|
-
type: "'",
|
988
|
-
span: [cursor, cursor]
|
989
|
-
});
|
990
|
-
}
|
991
|
-
while (cursor < input.length) {
|
992
|
-
if (_char === "\\") {
|
993
|
-
escaped = !escaped;
|
994
|
-
} else {
|
995
|
-
escaped = false;
|
996
|
-
}
|
997
|
-
if (peek === "'" && !escaped) {
|
998
|
-
cursor += 2;
|
999
|
-
break;
|
1000
|
-
} else if (_char === "$" && peek === "{") {
|
1001
|
-
cursor += 2;
|
1002
|
-
break;
|
1003
|
-
}
|
1004
|
-
cursor++;
|
1005
|
-
_char = input[cursor];
|
1006
|
-
peek = input[cursor + 1];
|
1007
|
-
if (!(_char === "$" && peek === "{") && cursor < input.length) {
|
1008
|
-
if (!(_char === "\\" && !escaped // counter-intuitive, but escape just became false if this was a backslash we want to escape
|
1009
|
-
)) {
|
1010
|
-
value += _char;
|
1011
|
-
}
|
1012
|
-
unescapedValue += _char;
|
1013
|
-
}
|
1014
|
-
}
|
1015
|
-
var cursorOffset = peek === "'" && !escaped ? 2 : _char === "$" && peek === "{" ? 3 : 1;
|
1016
|
-
if (value) {
|
1017
|
-
tokens.push(_objectSpread2({
|
1018
|
-
type: "string",
|
1019
|
-
span: [start + 1, cursor - cursorOffset],
|
1020
|
-
value: value
|
1021
|
-
}, unescapedValue !== value && {
|
1022
|
-
unescapedValue: unescapedValue
|
1023
|
-
}));
|
1024
|
-
}
|
1025
|
-
if (peek === "'" && !escaped) {
|
1026
|
-
tokens.push({
|
1027
|
-
type: "'",
|
1028
|
-
span: [cursor - 1, cursor - 1]
|
1029
|
-
});
|
1030
|
-
} else if (_char === "$" && peek === "{") {
|
1031
|
-
tokens.push({
|
1032
|
-
type: "${",
|
1033
|
-
span: [cursor - cursorOffset + 1, cursor - 1]
|
1034
|
-
});
|
1035
|
-
}
|
1036
|
-
} else if (WHITE_SPACE.includes(_char)) {
|
1037
|
-
var _start = cursor;
|
1038
|
-
while (WHITE_SPACE.includes(input[cursor]) && cursor < input.length) {
|
1039
|
-
cursor++;
|
1040
|
-
}
|
1041
|
-
tokens.push({
|
1042
|
-
type: "ws",
|
1043
|
-
span: [_start, cursor - 1]
|
1044
|
-
});
|
1045
|
-
} else {
|
1046
|
-
var _value = "";
|
1047
|
-
var _start2 = cursor;
|
1048
|
-
do {
|
1049
|
-
_char = input[cursor];
|
1050
|
-
peek = input[cursor + 1];
|
1051
|
-
_value += _char;
|
1052
|
-
cursor++;
|
1053
|
-
} while (!WHITE_SPACE.includes(peek) && peek !== ")" && peek !== "'" && cursor < input.length);
|
1054
|
-
tokens.push({
|
1055
|
-
type: "token",
|
1056
|
-
span: [_start2, cursor - 1],
|
1057
|
-
value: _value
|
1058
|
-
});
|
1059
|
-
}
|
1060
|
-
}
|
1061
|
-
return [tokens, cursor];
|
1062
|
-
}
|
1063
|
-
|
1064
|
-
var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span) {
|
1065
|
-
_classCallCheck(this, ParserError);
|
1066
|
-
this.message = message;
|
1067
|
-
this.span = span;
|
1068
|
-
});
|
1069
|
-
function parseTokens(inputTokens) {
|
1070
|
-
var tokens = inputTokens.slice();
|
1071
|
-
function slurpCall(first, isAnon) {
|
1072
|
-
var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
|
1073
|
-
// peek
|
1074
|
-
if (((_tokens$ = tokens[0]) === null || _tokens$ === void 0 ? void 0 : _tokens$.type) === "ws" && ((_tokens$2 = tokens[1]) === null || _tokens$2 === void 0 ? void 0 : _tokens$2.type) === ")" || ((_tokens$3 = tokens[0]) === null || _tokens$3 === void 0 ? void 0 : _tokens$3.type) === ")") {
|
1075
|
-
slurpWs();
|
1076
|
-
tokens.shift();
|
1077
|
-
return result.ok(new Sym("()", [first.span[0], first.span[1] + 1]));
|
1078
|
-
}
|
1079
|
-
var args = [];
|
1080
|
-
var completed = false;
|
1081
|
-
while (!completed) {
|
1082
|
-
var _res = slurp();
|
1083
|
-
if (result.isOk(_res)) {
|
1084
|
-
var _tokens$4, _tokens$5, _tokens$6;
|
1085
|
-
args.push(_res.value);
|
1086
|
-
completed = ((_tokens$4 = tokens[0]) === null || _tokens$4 === void 0 ? void 0 : _tokens$4.type) !== "ws" || ((_tokens$5 = tokens[0]) === null || _tokens$5 === void 0 ? void 0 : _tokens$5.type) === "ws" && ((_tokens$6 = tokens[1]) === null || _tokens$6 === void 0 ? void 0 : _tokens$6.type) === ")";
|
1087
|
-
} else {
|
1088
|
-
return _res;
|
1089
|
-
}
|
1090
|
-
}
|
1091
|
-
if (((_tokens$7 = tokens[0]) === null || _tokens$7 === void 0 ? void 0 : _tokens$7.type) === "ws" && ((_tokens$8 = tokens[1]) === null || _tokens$8 === void 0 ? void 0 : _tokens$8.type) === ")") {
|
1092
|
-
tokens.shift();
|
1093
|
-
}
|
1094
|
-
var last = tokens.shift();
|
1095
|
-
if ((last === null || last === void 0 ? void 0 : last.type) !== ")") {
|
1096
|
-
return result.err(new ParserError("unbalanced parens: missing a ')'", [first.span[0], first.span[1] + 1]));
|
1097
|
-
}
|
1098
|
-
return result.ok(new Call(args, isAnon, [first.span[0], ((_args$slice$0$span = args.slice(-1)[0].span) === null || _args$slice$0$span === void 0 ? void 0 : _args$slice$0$span[1]) || -1]));
|
1099
|
-
}
|
1100
|
-
function slurpWs() {
|
1101
|
-
while (((_tokens$9 = tokens[0]) === null || _tokens$9 === void 0 ? void 0 : _tokens$9.type) === "ws") {
|
1102
|
-
var _tokens$9;
|
1103
|
-
tokens.shift();
|
1104
|
-
}
|
1105
|
-
}
|
1106
|
-
function slurpTemplate(first) {
|
1107
|
-
var children = [];
|
1108
|
-
while (tokens.length > 0) {
|
1109
|
-
var _tokens$10;
|
1110
|
-
if (((_tokens$10 = tokens[0]) === null || _tokens$10 === void 0 ? void 0 : _tokens$10.type) === "'") {
|
1111
|
-
break;
|
1112
|
-
}
|
1113
|
-
var nextToken = tokens.shift();
|
1114
|
-
if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "${") {
|
1115
|
-
var _res2 = slurp();
|
1116
|
-
if (result.isOk(_res2)) {
|
1117
|
-
children.push(_res2.value);
|
1118
|
-
var _last = tokens.shift();
|
1119
|
-
if (!_last) {
|
1120
|
-
var _children$slice$0$spa;
|
1121
|
-
return result.err(new ParserError("unbalanced string template: missing a '}'", [first.span[0], (_children$slice$0$spa = children.slice(-1)[0].span) === null || _children$slice$0$spa === void 0 ? void 0 : _children$slice$0$spa[1]]));
|
1122
|
-
} else if (_last.type !== "}") {
|
1123
|
-
return result.err(new ParserError("unbalanced string template: expected '}'", _last.span));
|
1124
|
-
}
|
1125
|
-
} else {
|
1126
|
-
return _res2;
|
1127
|
-
}
|
1128
|
-
} else if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "string") {
|
1129
|
-
children.push(new StringLiteral(nextToken.unescapedValue || nextToken.value || "", nextToken.span));
|
1130
|
-
}
|
1131
|
-
}
|
1132
|
-
var last = tokens.shift();
|
1133
|
-
if (!last) {
|
1134
|
-
var _children$slice$0$spa2;
|
1135
|
-
return result.err(new ParserError("unbalanced string template: missing a '''", [first.span[0], (_children$slice$0$spa2 = children.slice(-1)[0].span) === null || _children$slice$0$spa2 === void 0 ? void 0 : _children$slice$0$spa2[1]]));
|
1136
|
-
} else if (last.type !== "'") {
|
1137
|
-
return result.err(new ParserError("unbalanced string template: expected '''", last.span));
|
1138
|
-
}
|
1139
|
-
return result.ok(new StringTemplate(children, [first.span[0], last.span[1]]));
|
1140
|
-
}
|
1141
|
-
function slurpString(first) {
|
1142
|
-
var _tokens$11, _tokens$12, _tokens$13;
|
1143
|
-
if (((_tokens$11 = tokens[0]) === null || _tokens$11 === void 0 ? void 0 : _tokens$11.type) === "string" && ((_tokens$12 = tokens[1]) === null || _tokens$12 === void 0 ? void 0 : _tokens$12.type) === "'") {
|
1144
|
-
var stringToken = tokens.shift();
|
1145
|
-
var last = tokens.shift();
|
1146
|
-
if (!last || !stringToken) {
|
1147
|
-
throw Error("Unexpected error: stringToken or last is undefined");
|
1148
|
-
}
|
1149
|
-
return result.ok(new StringLiteral(stringToken.unescapedValue || stringToken.value || "", [first.span[0], last.span[1]]));
|
1150
|
-
} else if (((_tokens$13 = tokens[0]) === null || _tokens$13 === void 0 ? void 0 : _tokens$13.type) === "'") {
|
1151
|
-
var _last2 = tokens.shift();
|
1152
|
-
if (!_last2) {
|
1153
|
-
throw Error("Unexpected error: last is undefined");
|
1154
|
-
}
|
1155
|
-
return result.ok(new StringLiteral("", [first.span[0], _last2.span[1]]));
|
1156
|
-
} else {
|
1157
|
-
return slurpTemplate(first);
|
1158
|
-
}
|
1159
|
-
}
|
1160
|
-
function slurp() {
|
1161
|
-
slurpWs();
|
1162
|
-
var first = tokens.shift();
|
1163
|
-
if (!first) {
|
1164
|
-
return result.err(new ParserError("expected '(', '!(', string or literal", [0, 0]));
|
1165
|
-
}
|
1166
|
-
if (first.type === "(" || first.type === "!(") {
|
1167
|
-
return slurpCall(first, first.type === "!(");
|
1168
|
-
} else if (first.type === "'") {
|
1169
|
-
return slurpString(first);
|
1170
|
-
} else if (first.type === "token") {
|
1171
|
-
var _first$value, _first$value2, _first$value3, _first$value4, _first$value5, _first$value6;
|
1172
|
-
if ((_first$value = first.value) !== null && _first$value !== void 0 && _first$value.includes("(") || (_first$value2 = first.value) !== null && _first$value2 !== void 0 && _first$value2.includes(")")) {
|
1173
|
-
return result.err(new ParserError("unexpected token: '(' and ')' are not allowed in tokens", first.span));
|
1174
|
-
}
|
1175
|
-
if ((_first$value3 = first.value) !== null && _first$value3 !== void 0 && _first$value3.includes("'")) {
|
1176
|
-
return result.err(new ParserError('unexpected token: "\'" is not allowed in tokens', first.span));
|
1177
|
-
}
|
1178
|
-
if ((_first$value4 = first.value) !== null && _first$value4 !== void 0 && _first$value4.includes(".")) {
|
1179
|
-
return result.err(new ParserError('unexpected token: "." is not allowed in tokens', first.span));
|
1180
|
-
}
|
1181
|
-
if ((_first$value5 = first.value) !== null && _first$value5 !== void 0 && _first$value5.includes("{") || (_first$value6 = first.value) !== null && _first$value6 !== void 0 && _first$value6.includes("}")) {
|
1182
|
-
return result.err(new ParserError("unexpected token: '{' and '}' are not allowed in tokens", first.span));
|
1183
|
-
}
|
1184
|
-
return result.ok(new Sym(first.value || "", first.span));
|
1185
|
-
} else {
|
1186
|
-
return result.err(new ParserError("expected '(', '!(' or literal or token".concat(first.value || first.type ? ", got: '".concat(first.value || first.type, "'") : ""), first.span));
|
1187
|
-
}
|
1188
|
-
}
|
1189
|
-
var res = slurp();
|
1190
|
-
slurpWs();
|
1191
|
-
if (result.isErr(res)) {
|
1192
|
-
return res;
|
1193
|
-
}
|
1194
|
-
if (tokens.length > 0) {
|
1195
|
-
return result.err(new ParserError("expected end of input, superfluous tokens", [tokens[0].span[0], tokens.slice(-1)[0].span[1]]));
|
1196
|
-
}
|
1197
|
-
return res;
|
1198
|
-
}
|
1199
|
-
function parse(input) {
|
1200
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1201
|
-
var _tokenize = tokenize(input),
|
1202
|
-
_tokenize2 = _slicedToArray(_tokenize, 2),
|
1203
|
-
tokens = _tokenize2[0];
|
1204
|
-
_tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
|
1205
|
-
return parseTokens(tokens);
|
1206
|
-
}
|
1207
|
-
|
1208
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
1209
|
-
|
1210
|
-
/**
|
1211
|
-
* Selectors can be used to select parts of a Val module.
|
1212
|
-
* Unlike queries, joins, aggregates etc is and will not be supported.
|
1213
|
-
*
|
1214
|
-
* They are designed to be be used as if they were "normal" JSON data,
|
1215
|
-
* though some concessions had to be made because of TypeScript limitations.
|
1216
|
-
*
|
1217
|
-
* Selectors works equally on source content, defined in code, and remote content.
|
1218
|
-
*
|
1219
|
-
* @example
|
1220
|
-
* // Select the title of a document
|
1221
|
-
* const titles = useVal(docsVal.map((doc) => doc.title));
|
1222
|
-
*
|
1223
|
-
* @example
|
1224
|
-
* // Match on a union type
|
1225
|
-
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
1226
|
-
* newsletter: (newsletter) => newsletter.title,
|
1227
|
-
* email: (email) => email.subject,
|
1228
|
-
* }));
|
1229
|
-
*
|
1230
|
-
*/
|
1231
|
-
|
1232
|
-
/**
|
1233
|
-
* @internal
|
1234
|
-
*/
|
1235
|
-
var GetSchema = Symbol("GetSchema");
|
1236
|
-
/**
|
1237
|
-
/**
|
1238
|
-
* @internal
|
1239
|
-
*/
|
1240
|
-
var Path = Symbol("Path");
|
1241
|
-
/**
|
1242
|
-
* @internal
|
1243
|
-
*/
|
1244
|
-
var SourceOrExpr = Symbol("SourceOrExpr");
|
1245
|
-
|
1246
|
-
/**
|
1247
|
-
* Use this type to convert types that accepts both Source and Selectors
|
1248
|
-
*
|
1249
|
-
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
1250
|
-
**/
|
1251
|
-
|
1252
|
-
function hasOwn$1(obj, prop) {
|
1253
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
1254
|
-
}
|
1255
|
-
function _andThen(f, source, path) {
|
1256
|
-
if (source) {
|
1257
|
-
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
1258
|
-
}
|
1259
|
-
return newSelectorProxy(source, path);
|
1260
|
-
}
|
1261
|
-
function isSelector(source) {
|
1262
|
-
return _typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
1263
|
-
}
|
1264
|
-
function newSelectorProxy(source, path, moduleSchema) {
|
1265
|
-
if (_typeof(source) === "object") {
|
1266
|
-
if (isSelector(source)) {
|
1267
|
-
return source;
|
1268
|
-
} else if (isSerializedVal(source)) {
|
1269
|
-
return newSelectorProxy(source.val, source.valPath);
|
1270
|
-
}
|
1271
|
-
}
|
1272
|
-
if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
|
1273
|
-
var fileRef = source[FILE_REF_PROP];
|
1274
|
-
if (typeof fileRef !== "string") {
|
1275
|
-
throw Error("Invalid file ref: " + fileRef);
|
1276
|
-
}
|
1277
|
-
return newSelectorProxy(convertFileSource(source), path, moduleSchema);
|
1278
|
-
}
|
1279
|
-
switch (_typeof(source)) {
|
1280
|
-
case "function":
|
1281
|
-
case "symbol":
|
1282
|
-
throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
|
1283
|
-
case "object":
|
1284
|
-
// Handles both objects and arrays!
|
1285
|
-
if (source !== null) {
|
1286
|
-
return new Proxy(source, {
|
1287
|
-
// TODO: see proxy docs if we want more traps
|
1288
|
-
has: function has(target, prop) {
|
1289
|
-
if (prop === SourceOrExpr) {
|
1290
|
-
return true;
|
1291
|
-
}
|
1292
|
-
if (prop === Path) {
|
1293
|
-
return true;
|
1294
|
-
}
|
1295
|
-
if (prop === "andThen") {
|
1296
|
-
return true;
|
1297
|
-
}
|
1298
|
-
if (prop === GetSchema) {
|
1299
|
-
return true;
|
1300
|
-
}
|
1301
|
-
return prop in target;
|
1302
|
-
},
|
1303
|
-
get: function get(target, prop) {
|
1304
|
-
if (prop === SourceOrExpr) {
|
1305
|
-
return source;
|
1306
|
-
}
|
1307
|
-
if (prop === Path) {
|
1308
|
-
return path;
|
1309
|
-
}
|
1310
|
-
if (prop === GetSchema) {
|
1311
|
-
return moduleSchema;
|
1312
|
-
}
|
1313
|
-
if (prop === "andThen") {
|
1314
|
-
return function (f) {
|
1315
|
-
return _andThen(f, source, path);
|
1316
|
-
};
|
1317
|
-
}
|
1318
|
-
if (Array.isArray(target)) {
|
1319
|
-
if (prop === "filter") {
|
1320
|
-
return function (f) {
|
1321
|
-
var filtered = target.map(function (a, i) {
|
1322
|
-
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
1323
|
-
}).filter(function (a) {
|
1324
|
-
if (f && f instanceof Schema) {
|
1325
|
-
return f.assert(path || "", unValify(a)).success;
|
1326
|
-
} else {
|
1327
|
-
return unValify(f(a));
|
1328
|
-
}
|
1329
|
-
});
|
1330
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
1331
|
-
};
|
1332
|
-
} else if (prop === "map") {
|
1333
|
-
return function (f) {
|
1334
|
-
var filtered = target.map(function (a, i) {
|
1335
|
-
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
1336
|
-
if (isSelector(valueOrSelector)) {
|
1337
|
-
return valueOrSelector;
|
1338
|
-
}
|
1339
|
-
return newSelectorProxy(valueOrSelector);
|
1340
|
-
});
|
1341
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
1342
|
-
};
|
1343
|
-
}
|
1344
|
-
}
|
1345
|
-
if (Array.isArray(target) && prop === "length") {
|
1346
|
-
return newSelectorProxy(target.length);
|
1347
|
-
}
|
1348
|
-
var reflectedValue = Reflect.get(target, prop);
|
1349
|
-
if (hasOwn$1(source, prop)) {
|
1350
|
-
if (!Number.isNaN(Number(prop))) {
|
1351
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
1352
|
-
}
|
1353
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
1354
|
-
}
|
1355
|
-
return reflectedValue;
|
1356
|
-
}
|
1357
|
-
});
|
1358
|
-
}
|
1359
|
-
// intentional fallthrough
|
1360
|
-
// eslint-disable-next-line no-fallthrough
|
1361
|
-
default:
|
1362
|
-
return _defineProperty(_defineProperty(_defineProperty({
|
1363
|
-
eq: function eq(other) {
|
1364
|
-
var otherValue = other;
|
1365
|
-
if (isSelector(other)) {
|
1366
|
-
otherValue = other[SourceOrExpr];
|
1367
|
-
if (otherValue instanceof Expr) {
|
1368
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
1369
|
-
}
|
1370
|
-
}
|
1371
|
-
return newSelectorProxy(source === otherValue, undefined);
|
1372
|
-
},
|
1373
|
-
andThen: function andThen(f) {
|
1374
|
-
return _andThen(f, source === undefined ? null : source, path);
|
1375
|
-
}
|
1376
|
-
}, SourceOrExpr, source === undefined ? null : source), Path, path), GetSchema, moduleSchema);
|
1377
|
-
}
|
1378
|
-
}
|
1379
|
-
|
1380
|
-
// TODO: could we do .val on the objects instead?
|
1381
|
-
function unValify(valueOrSelector) {
|
1382
|
-
if (_typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
1383
|
-
var selectorValue = valueOrSelector[SourceOrExpr];
|
1384
|
-
return selectorValue;
|
1385
|
-
}
|
1386
|
-
return valueOrSelector;
|
1387
|
-
}
|
1388
|
-
|
1389
|
-
var EvalError = /*#__PURE__*/function () {
|
1390
|
-
function EvalError(message, expr) {
|
1391
|
-
_classCallCheck(this, EvalError);
|
1392
|
-
this.message = message;
|
1393
|
-
this.expr = expr;
|
1394
|
-
}
|
1395
|
-
return _createClass(EvalError, [{
|
1396
|
-
key: "toString",
|
1397
|
-
value: function toString() {
|
1398
|
-
return "".concat(this.message, " in: ").concat(this.expr.transpile());
|
1399
|
-
}
|
1400
|
-
}]);
|
1401
|
-
}();
|
1402
|
-
var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
|
1403
|
-
function evaluateSync(expr, getSource, stack) {
|
1404
|
-
// TODO: amount of evaluates should be limited?
|
1405
|
-
if (stack.length > MAX_STACK_SIZE) {
|
1406
|
-
throw new EvalError("Stack overflow. Final frames: ".concat(stack.slice(-10).map(function (frame, i) {
|
1407
|
-
return frame.map(function (s, j) {
|
1408
|
-
return "@[".concat(i, ",").concat(j, "]: ").concat(JSON.stringify(s));
|
1409
|
-
}).join(", ");
|
1410
|
-
}).join(" -> ")), expr);
|
1411
|
-
}
|
1412
|
-
if (expr instanceof Call) {
|
1413
|
-
if (expr.children[0] instanceof Sym) {
|
1414
|
-
if (expr.children[0].value === "val") {
|
1415
|
-
if (expr.isAnon) {
|
1416
|
-
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
1417
|
-
}
|
1418
|
-
if (expr.children[1] instanceof StringLiteral) {
|
1419
|
-
var path = expr.children[1].value;
|
1420
|
-
return newSelectorProxy(getSource(path), path);
|
1421
|
-
} else {
|
1422
|
-
throw new EvalError("argument of 'val' must be a string literal", expr);
|
1423
|
-
}
|
1424
|
-
} else if (expr.children[0].value === "json") {
|
1425
|
-
if (expr.children.length !== 2) {
|
1426
|
-
throw new EvalError("must call 'json' with exactly one argument", expr);
|
1427
|
-
}
|
1428
|
-
var value = evaluateSync(expr.children[1], getSource, stack);
|
1429
|
-
var valObj = value[SourceOrExpr];
|
1430
|
-
var valPath = value[Path];
|
1431
|
-
if (typeof valObj !== "string") {
|
1432
|
-
throw new EvalError("cannot parse JSON: ".concat(JSON.stringify(valObj), ", expected string"), expr.children[1]);
|
1433
|
-
}
|
1434
|
-
try {
|
1435
|
-
var serialized = JSON.parse(valObj);
|
1436
|
-
if (isSerializedVal(serialized)) {
|
1437
|
-
return newSelectorProxy(serialized.val, serialized.valPath);
|
1438
|
-
}
|
1439
|
-
var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
1440
|
-
return parsedValue;
|
1441
|
-
} catch (e) {
|
1442
|
-
if (e instanceof SyntaxError) {
|
1443
|
-
throw new EvalError("cannot parse JSON: ".concat(valObj, ", ").concat(e.message, " - value: ").concat(JSON.stringify(value)), expr.children[1]);
|
1444
|
-
}
|
1445
|
-
throw e;
|
1446
|
-
}
|
1447
|
-
} else if (expr.children[0].value === "stringify") {
|
1448
|
-
// TODO: remove stringify
|
1449
|
-
if (expr.children.length !== 2) {
|
1450
|
-
throw new EvalError("must call 'stringify' with exactly one argument", expr);
|
1451
|
-
}
|
1452
|
-
var res = evaluateSync(expr.children[1], getSource, stack);
|
1453
|
-
return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
|
1454
|
-
}
|
1455
|
-
}
|
1456
|
-
var prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
|
1457
|
-
if (expr.children.length === 1) {
|
1458
|
-
// TODO: return if literal only?
|
1459
|
-
return newSelectorProxy(prop);
|
1460
|
-
}
|
1461
|
-
var obj = evaluateSync(expr.children[1], getSource, stack);
|
1462
|
-
if (typeof prop !== "string" && typeof prop !== "number") {
|
1463
|
-
throw new EvalError("cannot access ".concat(JSON.stringify(obj), " with property ").concat(JSON.stringify(prop), ": is not a string or number"), expr);
|
1464
|
-
}
|
1465
|
-
if (prop in obj) {
|
1466
|
-
if (expr.isAnon) {
|
1467
|
-
// anon functions:
|
1468
|
-
var maybeFunction = obj[prop];
|
1469
|
-
if (typeof maybeFunction !== "function") {
|
1470
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(_typeof(obj[prop])), expr);
|
1471
|
-
}
|
1472
|
-
if (expr.children[0] instanceof Sym) {
|
1473
|
-
return maybeFunction(function () {
|
1474
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
1475
|
-
args[_key] = arguments[_key];
|
1476
|
-
}
|
1477
|
-
return evaluateSync(expr.children[2], getSource, stack.concat([args]));
|
1478
|
-
});
|
1479
|
-
} else {
|
1480
|
-
throw new EvalError("cannot call an expression that is not a symbol, got: '".concat(expr.children[0].type, "'"), expr);
|
1481
|
-
}
|
1482
|
-
} else {
|
1483
|
-
// non-anon functions:
|
1484
|
-
if (expr.children[0] instanceof Sym) {
|
1485
|
-
if (expr.children[0].value === "val") {
|
1486
|
-
if (expr.children[1] instanceof StringLiteral) {
|
1487
|
-
var _path = expr.children[1].value;
|
1488
|
-
return newSelectorProxy(getSource(_path), _path);
|
1489
|
-
} else {
|
1490
|
-
throw new EvalError("argument of 'val' must be a string literal", expr);
|
1491
|
-
}
|
1492
|
-
}
|
1493
|
-
}
|
1494
|
-
var args = expr.children.slice(2);
|
1495
|
-
if (args.length > 0) {
|
1496
|
-
var _maybeFunction = obj[prop];
|
1497
|
-
if (typeof _maybeFunction !== "function") {
|
1498
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(_typeof(obj[prop])), expr);
|
1499
|
-
}
|
1500
|
-
return _maybeFunction.apply(void 0, _toConsumableArray(args.map(function (arg) {
|
1501
|
-
return evaluateSync(arg, getSource, stack);
|
1502
|
-
})));
|
1503
|
-
}
|
1504
|
-
var maybeValue = obj[prop];
|
1505
|
-
if (typeof maybeValue === "function") {
|
1506
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(_typeof(obj[prop])), expr);
|
1507
|
-
}
|
1508
|
-
return maybeValue;
|
1509
|
-
}
|
1510
|
-
}
|
1511
|
-
} else if (expr instanceof Sym) {
|
1512
|
-
if (expr.value.startsWith("@")) {
|
1513
|
-
var _stack$Number;
|
1514
|
-
var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
|
1515
|
-
_expr$value$slice$spl2 = _slicedToArray(_expr$value$slice$spl, 3),
|
1516
|
-
i = _expr$value$slice$spl2[0],
|
1517
|
-
j = _expr$value$slice$spl2[1],
|
1518
|
-
rest = _expr$value$slice$spl2[2];
|
1519
|
-
if (rest) {
|
1520
|
-
throw new EvalError("cannot access stack: too many indices", expr);
|
1521
|
-
}
|
1522
|
-
var stackValue = (_stack$Number = stack[Number(i)]) === null || _stack$Number === void 0 ? void 0 : _stack$Number[Number(j)];
|
1523
|
-
if (stackValue === undefined) {
|
1524
|
-
throw new EvalError("cannot access stack: out of bounds", expr);
|
1525
|
-
}
|
1526
|
-
return stackValue;
|
1527
|
-
} else if (expr.value === "()") {
|
1528
|
-
return newSelectorProxy(null);
|
1529
|
-
}
|
1530
|
-
return newSelectorProxy(expr.value);
|
1531
|
-
} else if (expr instanceof StringLiteral) {
|
1532
|
-
return newSelectorProxy(expr.value);
|
1533
|
-
} else if (expr instanceof StringTemplate) {
|
1534
|
-
return newSelectorProxy(expr.children.map(function (child) {
|
1535
|
-
if (child instanceof Sym && child.value === "()") {
|
1536
|
-
return "null";
|
1537
|
-
}
|
1538
|
-
var evalRes = evaluateSync(child, getSource, stack);
|
1539
|
-
if (child.type === "StringLiteral" || child.type === "StringTemplate") {
|
1540
|
-
return evalRes[SourceOrExpr];
|
1541
|
-
}
|
1542
|
-
if (Path in evalRes) {
|
1543
|
-
// a selector, so serialize to Val
|
1544
|
-
return JSON.stringify({
|
1545
|
-
val: evalRes[SourceOrExpr],
|
1546
|
-
valPath: evalRes[Path]
|
1547
|
-
});
|
1548
|
-
}
|
1549
|
-
return JSON.stringify(evalRes[SourceOrExpr]);
|
1550
|
-
}).join(""));
|
1551
|
-
}
|
1552
|
-
throw new EvalError("could not evaluate", expr);
|
1553
|
-
}
|
1554
|
-
function evaluate(expr, source, stack) {
|
1555
|
-
try {
|
1556
|
-
return result.ok(evaluateSync(expr, source, stack));
|
1557
|
-
} catch (err) {
|
1558
|
-
if (err instanceof EvalError) {
|
1559
|
-
return result.err(err);
|
1560
|
-
}
|
1561
|
-
throw err;
|
1562
|
-
}
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
var index = /*#__PURE__*/Object.freeze({
|
1566
|
-
__proto__: null,
|
1567
|
-
parse: parse,
|
1568
|
-
Call: Call,
|
1569
|
-
Expr: Expr,
|
1570
|
-
NilSym: NilSym,
|
1571
|
-
StringLiteral: StringLiteral,
|
1572
|
-
StringTemplate: StringTemplate,
|
1573
|
-
Sym: Sym,
|
1574
|
-
evaluate: evaluate
|
1575
|
-
});
|
1576
|
-
|
1577
749
|
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
1578
750
|
function ArraySchema(item) {
|
1579
751
|
var _this;
|
@@ -2089,366 +1261,25 @@ var union = function union(key) {
|
|
2089
1261
|
return new UnionSchema(key, objects);
|
2090
1262
|
};
|
2091
1263
|
|
2092
|
-
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
2093
|
-
function RichTextSchema(options) {
|
2094
|
-
var _this;
|
2095
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2096
|
-
_classCallCheck(this, RichTextSchema);
|
2097
|
-
_this = _callSuper(this, RichTextSchema);
|
2098
|
-
_this.options = options;
|
2099
|
-
_this.opt = opt;
|
2100
|
-
return _this;
|
2101
|
-
}
|
2102
|
-
_inherits(RichTextSchema, _Schema);
|
2103
|
-
return _createClass(RichTextSchema, [{
|
2104
|
-
key: "validate",
|
2105
|
-
value: function validate(path, src) {
|
2106
|
-
var assertRes = this.assert(path, src);
|
2107
|
-
if (!assertRes.success) {
|
2108
|
-
return _defineProperty({}, path, assertRes.errors[path]);
|
2109
|
-
}
|
2110
|
-
var nodes = assertRes.data;
|
2111
|
-
if (nodes === null && this.opt) {
|
2112
|
-
return false;
|
2113
|
-
}
|
2114
|
-
if (nodes === null) {
|
2115
|
-
return _defineProperty({}, path, [{
|
2116
|
-
message: "Expected 'array', got 'null'",
|
2117
|
-
typeError: true
|
2118
|
-
}]);
|
2119
|
-
}
|
2120
|
-
var current = {};
|
2121
|
-
var typeErrorRes = this.recursiveValidate(path, nodes, current);
|
2122
|
-
if (typeErrorRes) {
|
2123
|
-
return typeErrorRes;
|
2124
|
-
}
|
2125
|
-
if (Object.keys(current).length > 0) {
|
2126
|
-
return current;
|
2127
|
-
}
|
2128
|
-
return false;
|
2129
|
-
}
|
2130
|
-
}, {
|
2131
|
-
key: "recursiveValidate",
|
2132
|
-
value: function recursiveValidate(rootPath, nodes, current) {
|
2133
|
-
var addError = function addError(path, message, typeError) {
|
2134
|
-
if (!current[path]) {
|
2135
|
-
current[path] = [];
|
2136
|
-
}
|
2137
|
-
current[path].push({
|
2138
|
-
message: message,
|
2139
|
-
typeError: typeError
|
2140
|
-
});
|
2141
|
-
};
|
2142
|
-
var _iterator = result._createForOfIteratorHelper(nodes),
|
2143
|
-
_step;
|
2144
|
-
try {
|
2145
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2146
|
-
var _this$options$block, _this$options$block2, _this$options$block3, _this$options$block4, _this$options$block5, _this$options$block6, _this$options$block7, _this$options$block8, _this$options$block9, _this$options$block10, _this$options$inline, _this$options$inline2;
|
2147
|
-
var node = _step.value;
|
2148
|
-
var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
|
2149
|
-
if (typeof node === "string") {
|
2150
|
-
continue;
|
2151
|
-
}
|
2152
|
-
if (_typeof(node) !== "object") {
|
2153
|
-
return _defineProperty({}, path, [{
|
2154
|
-
message: "Expected nodes of type 'object' or 'string', got '".concat(_typeof(node), "'"),
|
2155
|
-
typeError: true
|
2156
|
-
}]);
|
2157
|
-
}
|
2158
|
-
if (node === null) {
|
2159
|
-
return _defineProperty({}, path, [{
|
2160
|
-
message: "Expected nodes of type 'object' or 'string', got 'null'",
|
2161
|
-
typeError: true
|
2162
|
-
}]);
|
2163
|
-
}
|
2164
|
-
if (!("tag" in node)) {
|
2165
|
-
return _defineProperty({}, path, [{
|
2166
|
-
message: "Expected node to either have 'tag' or be of type 'string'",
|
2167
|
-
typeError: true
|
2168
|
-
}]);
|
2169
|
-
}
|
2170
|
-
if (typeof node.tag !== "string") {
|
2171
|
-
return _defineProperty({}, path, [{
|
2172
|
-
message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
|
2173
|
-
typeError: true
|
2174
|
-
}]);
|
2175
|
-
}
|
2176
|
-
if (node.tag === "h1" && !((_this$options$block = this.options.block) !== null && _this$options$block !== void 0 && _this$options$block.h1)) {
|
2177
|
-
addError(path, "'h' block is not valid", false);
|
2178
|
-
}
|
2179
|
-
if (node.tag === "h2" && !((_this$options$block2 = this.options.block) !== null && _this$options$block2 !== void 0 && _this$options$block2.h2)) {
|
2180
|
-
addError(path, "'h2' block is not valid", false);
|
2181
|
-
}
|
2182
|
-
if (node.tag === "h3" && !((_this$options$block3 = this.options.block) !== null && _this$options$block3 !== void 0 && _this$options$block3.h3)) {
|
2183
|
-
addError(path, "'h3' block is not valid", false);
|
2184
|
-
}
|
2185
|
-
if (node.tag === "h4" && !((_this$options$block4 = this.options.block) !== null && _this$options$block4 !== void 0 && _this$options$block4.h4)) {
|
2186
|
-
addError(path, "'h4' block is not valid", false);
|
2187
|
-
}
|
2188
|
-
if (node.tag === "h5" && !((_this$options$block5 = this.options.block) !== null && _this$options$block5 !== void 0 && _this$options$block5.h5)) {
|
2189
|
-
addError(path, "'h5' block is not valid", false);
|
2190
|
-
}
|
2191
|
-
if (node.tag === "h6" && !((_this$options$block6 = this.options.block) !== null && _this$options$block6 !== void 0 && _this$options$block6.h6)) {
|
2192
|
-
addError(path, "'h6' block is not valid", false);
|
2193
|
-
}
|
2194
|
-
if (node.tag === "ol" && !((_this$options$block7 = this.options.block) !== null && _this$options$block7 !== void 0 && _this$options$block7.ol)) {
|
2195
|
-
addError(path, "'ol' block is not valid", false);
|
2196
|
-
}
|
2197
|
-
if (node.tag === "ul" && !((_this$options$block8 = this.options.block) !== null && _this$options$block8 !== void 0 && _this$options$block8.ul)) {
|
2198
|
-
addError(path, "'ul' block is not valid", false);
|
2199
|
-
}
|
2200
|
-
if (node.tag === "li" && !((_this$options$block9 = this.options.block) !== null && _this$options$block9 !== void 0 && _this$options$block9.ul) && !((_this$options$block10 = this.options.block) !== null && _this$options$block10 !== void 0 && _this$options$block10.ol)) {
|
2201
|
-
addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
|
2202
|
-
}
|
2203
|
-
if (node.tag === "a" && !((_this$options$inline = this.options.inline) !== null && _this$options$inline !== void 0 && _this$options$inline.a)) {
|
2204
|
-
addError(path, "'a' inline is not valid", false);
|
2205
|
-
}
|
2206
|
-
if (node.tag === "img" && !((_this$options$inline2 = this.options.inline) !== null && _this$options$inline2 !== void 0 && _this$options$inline2.img)) {
|
2207
|
-
addError(path, "'img' inline is not valid", false);
|
2208
|
-
}
|
2209
|
-
if ("styles" in node && node.tag !== "span") {
|
2210
|
-
return _defineProperty({}, path, [{
|
2211
|
-
message: "Cannot have styles on '".concat(node.tag, "'. This is only allowed on 'span'"),
|
2212
|
-
typeError: true
|
2213
|
-
}]);
|
2214
|
-
}
|
2215
|
-
if ("styles" in node) {
|
2216
|
-
if (!Array.isArray(node.styles)) {
|
2217
|
-
return _defineProperty({}, path, [{
|
2218
|
-
message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
|
2219
|
-
typeError: true
|
2220
|
-
}]);
|
2221
|
-
}
|
2222
|
-
var stylesPath = unsafeCreateSourcePath(path, "styles");
|
2223
|
-
for (var i = 0; i < node.styles.length; i++) {
|
2224
|
-
var _this$options$style, _this$options$style2, _this$options$style3;
|
2225
|
-
var style = node.styles[i];
|
2226
|
-
var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
|
2227
|
-
if (typeof style !== "string") {
|
2228
|
-
return _defineProperty({}, currentStylePath, [{
|
2229
|
-
message: "Expected 'string', got '".concat(_typeof(style), "'"),
|
2230
|
-
typeError: true
|
2231
|
-
}]);
|
2232
|
-
}
|
2233
|
-
if (style === "bold" && !((_this$options$style = this.options.style) !== null && _this$options$style !== void 0 && _this$options$style.bold)) {
|
2234
|
-
addError(currentStylePath, "Style 'bold' is not valid", false);
|
2235
|
-
}
|
2236
|
-
if (style === "italic" && !((_this$options$style2 = this.options.style) !== null && _this$options$style2 !== void 0 && _this$options$style2.italic)) {
|
2237
|
-
addError(currentStylePath, "Style 'italic' is not valid", false);
|
2238
|
-
}
|
2239
|
-
if (style === "lineThrough" && !((_this$options$style3 = this.options.style) !== null && _this$options$style3 !== void 0 && _this$options$style3.lineThrough)) {
|
2240
|
-
addError(currentStylePath, "Style 'lineThrough' is not valid", false);
|
2241
|
-
}
|
2242
|
-
}
|
2243
|
-
}
|
2244
|
-
if ("children" in node) {
|
2245
|
-
if (!Array.isArray(node.children)) {
|
2246
|
-
return _defineProperty({}, path, [{
|
2247
|
-
message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
|
2248
|
-
typeError: true
|
2249
|
-
}]);
|
2250
|
-
}
|
2251
|
-
var children = node.children;
|
2252
|
-
for (var _i = 0; _i < children.length; _i++) {
|
2253
|
-
var child = children[_i];
|
2254
|
-
if (_typeof(child) === "object") {
|
2255
|
-
var childPath = unsafeCreateSourcePath(path, "children");
|
2256
|
-
var res = this.recursiveValidate(childPath, [child], current);
|
2257
|
-
if (res) {
|
2258
|
-
return res;
|
2259
|
-
}
|
2260
|
-
} else if (typeof child !== "string") {
|
2261
|
-
return _defineProperty({}, path, [{
|
2262
|
-
message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
|
2263
|
-
typeError: true
|
2264
|
-
}]);
|
2265
|
-
}
|
2266
|
-
}
|
2267
|
-
}
|
2268
|
-
}
|
2269
|
-
} catch (err) {
|
2270
|
-
_iterator.e(err);
|
2271
|
-
} finally {
|
2272
|
-
_iterator.f();
|
2273
|
-
}
|
2274
|
-
return false;
|
2275
|
-
}
|
2276
|
-
}, {
|
2277
|
-
key: "assert",
|
2278
|
-
value: function assert(path, src) {
|
2279
|
-
if (this.opt && src === null) {
|
2280
|
-
return {
|
2281
|
-
success: true,
|
2282
|
-
data: src
|
2283
|
-
};
|
2284
|
-
}
|
2285
|
-
if (src === null && !this.opt) {
|
2286
|
-
return {
|
2287
|
-
success: false,
|
2288
|
-
errors: _defineProperty({}, path, [{
|
2289
|
-
message: "Expected 'array', got 'null'",
|
2290
|
-
typeError: true
|
2291
|
-
}])
|
2292
|
-
};
|
2293
|
-
}
|
2294
|
-
if (!Array.isArray(src)) {
|
2295
|
-
return {
|
2296
|
-
success: false,
|
2297
|
-
errors: _defineProperty({}, path, [{
|
2298
|
-
message: "Expected 'array', got '".concat(_typeof(src), "'"),
|
2299
|
-
typeError: true
|
2300
|
-
}])
|
2301
|
-
};
|
2302
|
-
}
|
2303
|
-
var errors = {};
|
2304
|
-
for (var i = 0; i < src.length; i++) {
|
2305
|
-
this.recursiveAssert(unsafeCreateSourcePath(path, i), src[i], errors);
|
2306
|
-
}
|
2307
|
-
if (Object.keys(errors).length > 0) {
|
2308
|
-
return {
|
2309
|
-
success: false,
|
2310
|
-
errors: errors
|
2311
|
-
};
|
2312
|
-
}
|
2313
|
-
// TODO: validate options
|
2314
|
-
return {
|
2315
|
-
success: true,
|
2316
|
-
data: src
|
2317
|
-
};
|
2318
|
-
}
|
2319
|
-
}, {
|
2320
|
-
key: "recursiveAssert",
|
2321
|
-
value: function recursiveAssert(path, node, errors) {
|
2322
|
-
if (_typeof(node) !== "object") {
|
2323
|
-
if (!errors[path]) {
|
2324
|
-
errors[path] = [];
|
2325
|
-
}
|
2326
|
-
errors[path].push({
|
2327
|
-
message: "Expected 'object', got '".concat(_typeof(node), "'"),
|
2328
|
-
typeError: true
|
2329
|
-
});
|
2330
|
-
return;
|
2331
|
-
}
|
2332
|
-
if (Array.isArray(node)) {
|
2333
|
-
if (!errors[path]) {
|
2334
|
-
errors[path] = [];
|
2335
|
-
}
|
2336
|
-
errors[path].push({
|
2337
|
-
message: "Expected 'object', got 'array'",
|
2338
|
-
typeError: true
|
2339
|
-
});
|
2340
|
-
return;
|
2341
|
-
}
|
2342
|
-
if (node === null) {
|
2343
|
-
if (!errors[path]) {
|
2344
|
-
errors[path] = [];
|
2345
|
-
}
|
2346
|
-
errors[path].push({
|
2347
|
-
message: "Expected 'object', got 'null'",
|
2348
|
-
typeError: true
|
2349
|
-
});
|
2350
|
-
return;
|
2351
|
-
}
|
2352
|
-
if ("tag" in node) {
|
2353
|
-
if (typeof node.tag !== "string") {
|
2354
|
-
if (!errors[path]) {
|
2355
|
-
errors[path] = [];
|
2356
|
-
}
|
2357
|
-
errors[path].push({
|
2358
|
-
message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
|
2359
|
-
typeError: true
|
2360
|
-
});
|
2361
|
-
return;
|
2362
|
-
}
|
2363
|
-
}
|
2364
|
-
if ("children" in node) {
|
2365
|
-
if (!Array.isArray(node.children)) {
|
2366
|
-
if (!errors[path]) {
|
2367
|
-
errors[path] = [];
|
2368
|
-
}
|
2369
|
-
errors[path].push({
|
2370
|
-
message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
|
2371
|
-
typeError: true
|
2372
|
-
});
|
2373
|
-
return;
|
2374
|
-
} else {
|
2375
|
-
for (var i = 0; i < node.children.length; i++) {
|
2376
|
-
var child = node.children[i];
|
2377
|
-
var pathAtError = unsafeCreateSourcePath(unsafeCreateSourcePath(path, "children"), i);
|
2378
|
-
if (_typeof(child) === "object") {
|
2379
|
-
this.recursiveAssert(pathAtError, child, errors);
|
2380
|
-
} else if (typeof child === "string") {
|
2381
|
-
continue;
|
2382
|
-
} else {
|
2383
|
-
if (!errors[pathAtError]) {
|
2384
|
-
errors[pathAtError] = [];
|
2385
|
-
}
|
2386
|
-
errors[pathAtError].push({
|
2387
|
-
message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
|
2388
|
-
typeError: true
|
2389
|
-
});
|
2390
|
-
}
|
2391
|
-
}
|
2392
|
-
}
|
2393
|
-
}
|
2394
|
-
if ("styles" in node) {
|
2395
|
-
if (!Array.isArray(node.styles)) {
|
2396
|
-
if (!errors[path]) {
|
2397
|
-
errors[path] = [];
|
2398
|
-
}
|
2399
|
-
errors[path].push({
|
2400
|
-
message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
|
2401
|
-
typeError: true
|
2402
|
-
});
|
2403
|
-
} else {
|
2404
|
-
for (var _i2 = 0; _i2 < node.styles.length; _i2++) {
|
2405
|
-
var style = node.styles[_i2];
|
2406
|
-
if (typeof style !== "string") {
|
2407
|
-
var _pathAtError = unsafeCreateSourcePath(path, _i2);
|
2408
|
-
if (!errors[_pathAtError]) {
|
2409
|
-
errors[_pathAtError] = [];
|
2410
|
-
}
|
2411
|
-
errors[_pathAtError].push({
|
2412
|
-
message: "Expected 'string', got '".concat(_typeof(style), "'"),
|
2413
|
-
typeError: true
|
2414
|
-
});
|
2415
|
-
}
|
2416
|
-
}
|
2417
|
-
}
|
2418
|
-
}
|
2419
|
-
}
|
2420
|
-
}, {
|
2421
|
-
key: "nullable",
|
2422
|
-
value: function nullable() {
|
2423
|
-
return new RichTextSchema(this.options, true);
|
2424
|
-
}
|
2425
|
-
}, {
|
2426
|
-
key: "serialize",
|
2427
|
-
value: function serialize() {
|
2428
|
-
return {
|
2429
|
-
type: "richtext",
|
2430
|
-
opt: this.opt,
|
2431
|
-
options: this.options
|
2432
|
-
};
|
2433
|
-
}
|
2434
|
-
}]);
|
2435
|
-
}(Schema);
|
2436
|
-
var richtext = function richtext(options) {
|
2437
|
-
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
2438
|
-
};
|
2439
|
-
|
2440
1264
|
var ImageSchema = /*#__PURE__*/function (_Schema) {
|
2441
1265
|
function ImageSchema(options) {
|
2442
1266
|
var _this;
|
2443
1267
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1268
|
+
var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
2444
1269
|
_classCallCheck(this, ImageSchema);
|
2445
1270
|
_this = _callSuper(this, ImageSchema);
|
2446
1271
|
_this.options = options;
|
2447
1272
|
_this.opt = opt;
|
1273
|
+
_this.isRemote = isRemote;
|
2448
1274
|
return _this;
|
2449
1275
|
}
|
2450
1276
|
_inherits(ImageSchema, _Schema);
|
2451
1277
|
return _createClass(ImageSchema, [{
|
1278
|
+
key: "remote",
|
1279
|
+
value: function remote() {
|
1280
|
+
return new ImageSchema(this.options, this.opt, true);
|
1281
|
+
}
|
1282
|
+
}, {
|
2452
1283
|
key: "validate",
|
2453
1284
|
value: function validate(path, src) {
|
2454
1285
|
if (this.opt && (src === null || src === undefined)) {
|
@@ -2460,6 +1291,27 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2460
1291
|
value: src
|
2461
1292
|
}]);
|
2462
1293
|
}
|
1294
|
+
if (this.isRemote && src[VAL_EXTENSION] !== "remote") {
|
1295
|
+
return _defineProperty({}, path, [{
|
1296
|
+
message: "Expected a remote image, but got a local image.",
|
1297
|
+
value: src,
|
1298
|
+
fixes: ["image:upload-remote"]
|
1299
|
+
}]);
|
1300
|
+
}
|
1301
|
+
if (this.isRemote && src[VAL_EXTENSION] === "remote") {
|
1302
|
+
return _defineProperty({}, path, [{
|
1303
|
+
message: "Remote image was not checked.",
|
1304
|
+
value: src,
|
1305
|
+
fixes: ["image:check-remote"]
|
1306
|
+
}]);
|
1307
|
+
}
|
1308
|
+
if (!this.isRemote && src[VAL_EXTENSION] === "remote") {
|
1309
|
+
return _defineProperty({}, path, [{
|
1310
|
+
message: "Expected locale image, but found remote.",
|
1311
|
+
value: src,
|
1312
|
+
fixes: ["image:download-remote"]
|
1313
|
+
}]);
|
1314
|
+
}
|
2463
1315
|
if (typeof src[FILE_REF_PROP] !== "string") {
|
2464
1316
|
return _defineProperty({}, path, [{
|
2465
1317
|
message: "Image did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
@@ -2473,10 +1325,10 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2473
1325
|
fixes: ["image:change-extension", "image:check-metadata"]
|
2474
1326
|
}]);
|
2475
1327
|
}
|
2476
|
-
var
|
2477
|
-
accept =
|
2478
|
-
var
|
2479
|
-
mimeType =
|
1328
|
+
var _ref7 = this.options || {},
|
1329
|
+
accept = _ref7.accept;
|
1330
|
+
var _ref8 = src.metadata || {},
|
1331
|
+
mimeType = _ref8.mimeType;
|
2480
1332
|
if (accept && mimeType && !mimeType.includes("/")) {
|
2481
1333
|
return _defineProperty({}, path, [{
|
2482
1334
|
message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
|
@@ -2537,11 +1389,349 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2537
1389
|
fixes: ["image:check-metadata"]
|
2538
1390
|
}]);
|
2539
1391
|
}
|
2540
|
-
return _defineProperty({}, path, [{
|
2541
|
-
message: "Could not validate Image metadata.",
|
2542
|
-
value: src,
|
2543
|
-
fixes: ["image:add-metadata"]
|
2544
|
-
}]);
|
1392
|
+
return _defineProperty({}, path, [{
|
1393
|
+
message: "Could not validate Image metadata.",
|
1394
|
+
value: src,
|
1395
|
+
fixes: ["image:add-metadata"]
|
1396
|
+
}]);
|
1397
|
+
}
|
1398
|
+
}, {
|
1399
|
+
key: "assert",
|
1400
|
+
value: function assert(path, src) {
|
1401
|
+
if (this.opt && src === null) {
|
1402
|
+
return {
|
1403
|
+
success: true,
|
1404
|
+
data: src
|
1405
|
+
};
|
1406
|
+
}
|
1407
|
+
if (src === null) {
|
1408
|
+
return {
|
1409
|
+
success: false,
|
1410
|
+
errors: _defineProperty({}, path, [{
|
1411
|
+
message: "Expected 'object', got 'null'",
|
1412
|
+
typeError: true
|
1413
|
+
}])
|
1414
|
+
};
|
1415
|
+
}
|
1416
|
+
if (_typeof(src) !== "object") {
|
1417
|
+
return {
|
1418
|
+
success: false,
|
1419
|
+
errors: _defineProperty({}, path, [{
|
1420
|
+
message: "Expected 'object', got '".concat(_typeof(src), "'"),
|
1421
|
+
typeError: true
|
1422
|
+
}])
|
1423
|
+
};
|
1424
|
+
}
|
1425
|
+
if (!(FILE_REF_PROP in src)) {
|
1426
|
+
return {
|
1427
|
+
success: false,
|
1428
|
+
errors: _defineProperty({}, path, [{
|
1429
|
+
message: "Value of this schema must use: 'c.image' (error type: missing_ref_prop)",
|
1430
|
+
typeError: true
|
1431
|
+
}])
|
1432
|
+
};
|
1433
|
+
}
|
1434
|
+
if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
|
1435
|
+
return {
|
1436
|
+
success: false,
|
1437
|
+
errors: _defineProperty({}, path, [{
|
1438
|
+
message: "Value of this schema must use: 'c.image' (error type: missing_file_extension)",
|
1439
|
+
typeError: true
|
1440
|
+
}])
|
1441
|
+
};
|
1442
|
+
}
|
1443
|
+
return {
|
1444
|
+
success: true,
|
1445
|
+
data: src
|
1446
|
+
};
|
1447
|
+
}
|
1448
|
+
}, {
|
1449
|
+
key: "nullable",
|
1450
|
+
value: function nullable() {
|
1451
|
+
return new ImageSchema(this.options, true);
|
1452
|
+
}
|
1453
|
+
}, {
|
1454
|
+
key: "serialize",
|
1455
|
+
value: function serialize() {
|
1456
|
+
return {
|
1457
|
+
type: "image",
|
1458
|
+
options: this.options,
|
1459
|
+
opt: this.opt,
|
1460
|
+
remote: this.isRemote
|
1461
|
+
};
|
1462
|
+
}
|
1463
|
+
}]);
|
1464
|
+
}(Schema);
|
1465
|
+
var image = function image(options) {
|
1466
|
+
return new ImageSchema(options);
|
1467
|
+
};
|
1468
|
+
|
1469
|
+
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
1470
|
+
function RichTextSchema(options) {
|
1471
|
+
var _this;
|
1472
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1473
|
+
_classCallCheck(this, RichTextSchema);
|
1474
|
+
_this = _callSuper(this, RichTextSchema);
|
1475
|
+
_this.options = options;
|
1476
|
+
_this.opt = opt;
|
1477
|
+
return _this;
|
1478
|
+
}
|
1479
|
+
_inherits(RichTextSchema, _Schema);
|
1480
|
+
return _createClass(RichTextSchema, [{
|
1481
|
+
key: "maxLength",
|
1482
|
+
value: function maxLength(max) {
|
1483
|
+
return new RichTextSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
1484
|
+
maxLength: max
|
1485
|
+
}), this.opt);
|
1486
|
+
}
|
1487
|
+
}, {
|
1488
|
+
key: "minLength",
|
1489
|
+
value: function minLength(min) {
|
1490
|
+
return new RichTextSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
1491
|
+
minLength: min
|
1492
|
+
}), this.opt);
|
1493
|
+
}
|
1494
|
+
}, {
|
1495
|
+
key: "validate",
|
1496
|
+
value: function validate(path, src) {
|
1497
|
+
var assertRes = this.assert(path, src);
|
1498
|
+
if (!assertRes.success) {
|
1499
|
+
return _defineProperty({}, path, assertRes.errors[path]);
|
1500
|
+
}
|
1501
|
+
var nodes = assertRes.data;
|
1502
|
+
if (nodes === null && this.opt) {
|
1503
|
+
return false;
|
1504
|
+
}
|
1505
|
+
if (nodes === null) {
|
1506
|
+
return _defineProperty({}, path, [{
|
1507
|
+
message: "Expected 'array', got 'null'",
|
1508
|
+
typeError: true
|
1509
|
+
}]);
|
1510
|
+
}
|
1511
|
+
var current = {};
|
1512
|
+
var typeErrorRes = this.internalValidate(path, nodes, current);
|
1513
|
+
if (typeErrorRes) {
|
1514
|
+
return typeErrorRes;
|
1515
|
+
}
|
1516
|
+
if (Object.keys(current).length > 0) {
|
1517
|
+
return current;
|
1518
|
+
}
|
1519
|
+
return false;
|
1520
|
+
}
|
1521
|
+
}, {
|
1522
|
+
key: "internalValidate",
|
1523
|
+
value: function internalValidate(rootPath, nodes, current) {
|
1524
|
+
var _this2 = this;
|
1525
|
+
var length = 0;
|
1526
|
+
var _recurse = function recurse(rootPath, nodes, current) {
|
1527
|
+
var addError = function addError(path, message, typeError) {
|
1528
|
+
if (!current[path]) {
|
1529
|
+
current[path] = [];
|
1530
|
+
}
|
1531
|
+
current[path].push({
|
1532
|
+
message: message,
|
1533
|
+
typeError: typeError
|
1534
|
+
});
|
1535
|
+
};
|
1536
|
+
var _iterator = result._createForOfIteratorHelper(nodes),
|
1537
|
+
_step;
|
1538
|
+
try {
|
1539
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
1540
|
+
var _this2$options$block, _this2$options$block2, _this2$options$block3, _this2$options$block4, _this2$options$block5, _this2$options$block6, _this2$options$block7, _this2$options$block8, _this2$options$block9, _this2$options$block10, _this2$options$inline;
|
1541
|
+
var node = _step.value;
|
1542
|
+
var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
|
1543
|
+
if (typeof node === "string") {
|
1544
|
+
length += node.length;
|
1545
|
+
continue;
|
1546
|
+
}
|
1547
|
+
if (_typeof(node) !== "object") {
|
1548
|
+
return _defineProperty({}, path, [{
|
1549
|
+
message: "Expected nodes of type 'object' or 'string', got '".concat(_typeof(node), "'"),
|
1550
|
+
typeError: true
|
1551
|
+
}]);
|
1552
|
+
}
|
1553
|
+
if (node === null) {
|
1554
|
+
return _defineProperty({}, path, [{
|
1555
|
+
message: "Expected nodes of type 'object' or 'string', got 'null'",
|
1556
|
+
typeError: true
|
1557
|
+
}]);
|
1558
|
+
}
|
1559
|
+
if (!("tag" in node)) {
|
1560
|
+
return _defineProperty({}, path, [{
|
1561
|
+
message: "Expected node to either have 'tag' or be of type 'string'",
|
1562
|
+
typeError: true
|
1563
|
+
}]);
|
1564
|
+
}
|
1565
|
+
if (typeof node.tag !== "string") {
|
1566
|
+
return _defineProperty({}, path, [{
|
1567
|
+
message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
|
1568
|
+
typeError: true
|
1569
|
+
}]);
|
1570
|
+
}
|
1571
|
+
if (node.tag === "h1" && !((_this2$options$block = _this2.options.block) !== null && _this2$options$block !== void 0 && _this2$options$block.h1)) {
|
1572
|
+
addError(path, "'h' block is not valid", false);
|
1573
|
+
}
|
1574
|
+
if (node.tag === "h2" && !((_this2$options$block2 = _this2.options.block) !== null && _this2$options$block2 !== void 0 && _this2$options$block2.h2)) {
|
1575
|
+
addError(path, "'h2' block is not valid", false);
|
1576
|
+
}
|
1577
|
+
if (node.tag === "h3" && !((_this2$options$block3 = _this2.options.block) !== null && _this2$options$block3 !== void 0 && _this2$options$block3.h3)) {
|
1578
|
+
addError(path, "'h3' block is not valid", false);
|
1579
|
+
}
|
1580
|
+
if (node.tag === "h4" && !((_this2$options$block4 = _this2.options.block) !== null && _this2$options$block4 !== void 0 && _this2$options$block4.h4)) {
|
1581
|
+
addError(path, "'h4' block is not valid", false);
|
1582
|
+
}
|
1583
|
+
if (node.tag === "h5" && !((_this2$options$block5 = _this2.options.block) !== null && _this2$options$block5 !== void 0 && _this2$options$block5.h5)) {
|
1584
|
+
addError(path, "'h5' block is not valid", false);
|
1585
|
+
}
|
1586
|
+
if (node.tag === "h6" && !((_this2$options$block6 = _this2.options.block) !== null && _this2$options$block6 !== void 0 && _this2$options$block6.h6)) {
|
1587
|
+
addError(path, "'h6' block is not valid", false);
|
1588
|
+
}
|
1589
|
+
if (node.tag === "ol" && !((_this2$options$block7 = _this2.options.block) !== null && _this2$options$block7 !== void 0 && _this2$options$block7.ol)) {
|
1590
|
+
addError(path, "'ol' block is not valid", false);
|
1591
|
+
}
|
1592
|
+
if (node.tag === "ul" && !((_this2$options$block8 = _this2.options.block) !== null && _this2$options$block8 !== void 0 && _this2$options$block8.ul)) {
|
1593
|
+
addError(path, "'ul' block is not valid", false);
|
1594
|
+
}
|
1595
|
+
if (node.tag === "li" && !((_this2$options$block9 = _this2.options.block) !== null && _this2$options$block9 !== void 0 && _this2$options$block9.ul) && !((_this2$options$block10 = _this2.options.block) !== null && _this2$options$block10 !== void 0 && _this2$options$block10.ol)) {
|
1596
|
+
addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
|
1597
|
+
}
|
1598
|
+
if (node.tag === "a" && !((_this2$options$inline = _this2.options.inline) !== null && _this2$options$inline !== void 0 && _this2$options$inline.a)) {
|
1599
|
+
addError(path, "'a' inline is not valid", false);
|
1600
|
+
}
|
1601
|
+
if (node.tag === "img") {
|
1602
|
+
var _this2$options$inline2, _this2$options$inline3;
|
1603
|
+
if (!((_this2$options$inline2 = _this2.options.inline) !== null && _this2$options$inline2 !== void 0 && _this2$options$inline2.img)) {
|
1604
|
+
addError(path, "'img' inline is not valid", false);
|
1605
|
+
} else if ((_this2$options$inline3 = _this2.options.inline) !== null && _this2$options$inline3 !== void 0 && _this2$options$inline3.img) {
|
1606
|
+
var _this2$options$inline4, _this2$options$inline5;
|
1607
|
+
if (!("src" in node)) {
|
1608
|
+
return _defineProperty({}, path, [{
|
1609
|
+
message: "Expected 'src' in 'img'",
|
1610
|
+
typeError: true
|
1611
|
+
}]);
|
1612
|
+
}
|
1613
|
+
var srcPath = unsafeCreateSourcePath(path, "src");
|
1614
|
+
var imageValidationErrors = _typeof((_this2$options$inline4 = _this2.options.inline) === null || _this2$options$inline4 === void 0 ? void 0 : _this2$options$inline4.img) === "object" ? (_this2$options$inline5 = _this2.options.inline) === null || _this2$options$inline5 === void 0 ? void 0 : _this2$options$inline5.img.validate(srcPath, node.src) : new ImageSchema({}, false, false).validate(srcPath, node.src);
|
1615
|
+
if (imageValidationErrors) {
|
1616
|
+
for (var validationErrorPathS in imageValidationErrors) {
|
1617
|
+
var _current$validationEr;
|
1618
|
+
var validationErrorPath = validationErrorPathS;
|
1619
|
+
if (!current[validationErrorPath]) {
|
1620
|
+
current[validationErrorPath] = [];
|
1621
|
+
}
|
1622
|
+
(_current$validationEr = current[validationErrorPath]).push.apply(_current$validationEr, _toConsumableArray(imageValidationErrors[validationErrorPath]));
|
1623
|
+
}
|
1624
|
+
}
|
1625
|
+
}
|
1626
|
+
}
|
1627
|
+
if ("styles" in node && node.tag !== "span") {
|
1628
|
+
return _defineProperty({}, path, [{
|
1629
|
+
message: "Cannot have styles on '".concat(node.tag, "'. This is only allowed on 'span'"),
|
1630
|
+
typeError: true
|
1631
|
+
}]);
|
1632
|
+
}
|
1633
|
+
if ("styles" in node) {
|
1634
|
+
if (!Array.isArray(node.styles)) {
|
1635
|
+
return _defineProperty({}, path, [{
|
1636
|
+
message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
|
1637
|
+
typeError: true
|
1638
|
+
}]);
|
1639
|
+
}
|
1640
|
+
var stylesPath = unsafeCreateSourcePath(path, "styles");
|
1641
|
+
for (var i = 0; i < node.styles.length; i++) {
|
1642
|
+
var _this2$options$style, _this2$options$style2, _this2$options$style3;
|
1643
|
+
var style = node.styles[i];
|
1644
|
+
var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
|
1645
|
+
if (typeof style !== "string") {
|
1646
|
+
return _defineProperty({}, currentStylePath, [{
|
1647
|
+
message: "Expected 'string', got '".concat(_typeof(style), "'"),
|
1648
|
+
typeError: true
|
1649
|
+
}]);
|
1650
|
+
}
|
1651
|
+
if (style === "bold" && !((_this2$options$style = _this2.options.style) !== null && _this2$options$style !== void 0 && _this2$options$style.bold)) {
|
1652
|
+
addError(currentStylePath, "Style 'bold' is not valid", false);
|
1653
|
+
}
|
1654
|
+
if (style === "italic" && !((_this2$options$style2 = _this2.options.style) !== null && _this2$options$style2 !== void 0 && _this2$options$style2.italic)) {
|
1655
|
+
addError(currentStylePath, "Style 'italic' is not valid", false);
|
1656
|
+
}
|
1657
|
+
if (style === "lineThrough" && !((_this2$options$style3 = _this2.options.style) !== null && _this2$options$style3 !== void 0 && _this2$options$style3.lineThrough)) {
|
1658
|
+
addError(currentStylePath, "Style 'lineThrough' is not valid", false);
|
1659
|
+
}
|
1660
|
+
}
|
1661
|
+
}
|
1662
|
+
if ("children" in node) {
|
1663
|
+
if (!Array.isArray(node.children)) {
|
1664
|
+
return _defineProperty({}, path, [{
|
1665
|
+
message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
|
1666
|
+
typeError: true
|
1667
|
+
}]);
|
1668
|
+
}
|
1669
|
+
var children = node.children;
|
1670
|
+
for (var _i = 0; _i < children.length; _i++) {
|
1671
|
+
var child = children[_i];
|
1672
|
+
if (_typeof(child) === "object") {
|
1673
|
+
var childPath = unsafeCreateSourcePath(path, "children");
|
1674
|
+
var res = _recurse(childPath, [child], current);
|
1675
|
+
if (res) {
|
1676
|
+
return res;
|
1677
|
+
}
|
1678
|
+
} else if (typeof child === "string") {
|
1679
|
+
length += child.length;
|
1680
|
+
continue;
|
1681
|
+
} else {
|
1682
|
+
return _defineProperty({}, path, [{
|
1683
|
+
message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
|
1684
|
+
typeError: true
|
1685
|
+
}]);
|
1686
|
+
}
|
1687
|
+
}
|
1688
|
+
}
|
1689
|
+
}
|
1690
|
+
} catch (err) {
|
1691
|
+
_iterator.e(err);
|
1692
|
+
} finally {
|
1693
|
+
_iterator.f();
|
1694
|
+
}
|
1695
|
+
return false;
|
1696
|
+
};
|
1697
|
+
var results = _recurse(rootPath, nodes, current);
|
1698
|
+
var lengthErrors = [];
|
1699
|
+
if (this.options.maxLength && length > this.options.maxLength) {
|
1700
|
+
lengthErrors.push({
|
1701
|
+
message: "Maximum length of ".concat(this.options.maxLength, " exceeded (current length: ").concat(length, ")"),
|
1702
|
+
typeError: false
|
1703
|
+
});
|
1704
|
+
}
|
1705
|
+
if (this.options.minLength && length < this.options.minLength) {
|
1706
|
+
lengthErrors.push({
|
1707
|
+
message: "Minimum length of ".concat(this.options.minLength, " not met (current length: ").concat(length, ")"),
|
1708
|
+
typeError: false
|
1709
|
+
});
|
1710
|
+
}
|
1711
|
+
if (results) {
|
1712
|
+
if (lengthErrors.length > 0) {
|
1713
|
+
var _results$rootPath;
|
1714
|
+
if (!results[rootPath]) {
|
1715
|
+
results[rootPath] = [];
|
1716
|
+
}
|
1717
|
+
(_results$rootPath = results[rootPath]).push.apply(_results$rootPath, lengthErrors);
|
1718
|
+
}
|
1719
|
+
return results;
|
1720
|
+
}
|
1721
|
+
if (Object.keys(current).length > 0) {
|
1722
|
+
if (lengthErrors.length > 0) {
|
1723
|
+
var _current$rootPath;
|
1724
|
+
if (!current[rootPath]) {
|
1725
|
+
current[rootPath] = [];
|
1726
|
+
}
|
1727
|
+
(_current$rootPath = current[rootPath]).push.apply(_current$rootPath, lengthErrors);
|
1728
|
+
}
|
1729
|
+
return current;
|
1730
|
+
}
|
1731
|
+
if (lengthErrors.length > 0) {
|
1732
|
+
return _defineProperty({}, rootPath, lengthErrors);
|
1733
|
+
}
|
1734
|
+
return false;
|
2545
1735
|
}
|
2546
1736
|
}, {
|
2547
1737
|
key: "assert",
|
@@ -2552,40 +1742,32 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2552
1742
|
data: src
|
2553
1743
|
};
|
2554
1744
|
}
|
2555
|
-
if (src === null) {
|
1745
|
+
if (src === null && !this.opt) {
|
2556
1746
|
return {
|
2557
1747
|
success: false,
|
2558
1748
|
errors: _defineProperty({}, path, [{
|
2559
|
-
message: "Expected '
|
1749
|
+
message: "Expected 'array', got 'null'",
|
2560
1750
|
typeError: true
|
2561
1751
|
}])
|
2562
1752
|
};
|
2563
1753
|
}
|
2564
|
-
if (
|
1754
|
+
if (!Array.isArray(src)) {
|
2565
1755
|
return {
|
2566
1756
|
success: false,
|
2567
1757
|
errors: _defineProperty({}, path, [{
|
2568
|
-
message: "Expected '
|
1758
|
+
message: "Expected 'array', got '".concat(_typeof(src), "'"),
|
2569
1759
|
typeError: true
|
2570
1760
|
}])
|
2571
1761
|
};
|
2572
1762
|
}
|
2573
|
-
|
2574
|
-
|
2575
|
-
|
2576
|
-
errors: _defineProperty({}, path, [{
|
2577
|
-
message: "Value of this schema must use: 'c.image' (error type: missing_ref_prop)",
|
2578
|
-
typeError: true
|
2579
|
-
}])
|
2580
|
-
};
|
1763
|
+
var errors = {};
|
1764
|
+
for (var i = 0; i < src.length; i++) {
|
1765
|
+
this.recursiveAssert(unsafeCreateSourcePath(path, i), src[i], errors);
|
2581
1766
|
}
|
2582
|
-
if (
|
1767
|
+
if (Object.keys(errors).length > 0) {
|
2583
1768
|
return {
|
2584
1769
|
success: false,
|
2585
|
-
errors:
|
2586
|
-
message: "Value of this schema must use: 'c.image' (error type: missing_file_extension)",
|
2587
|
-
typeError: true
|
2588
|
-
}])
|
1770
|
+
errors: errors
|
2589
1771
|
};
|
2590
1772
|
}
|
2591
1773
|
return {
|
@@ -2593,24 +1775,133 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2593
1775
|
data: src
|
2594
1776
|
};
|
2595
1777
|
}
|
1778
|
+
}, {
|
1779
|
+
key: "recursiveAssert",
|
1780
|
+
value: function recursiveAssert(path, node, errors) {
|
1781
|
+
if (_typeof(node) !== "object") {
|
1782
|
+
if (!errors[path]) {
|
1783
|
+
errors[path] = [];
|
1784
|
+
}
|
1785
|
+
errors[path].push({
|
1786
|
+
message: "Expected 'object', got '".concat(_typeof(node), "'"),
|
1787
|
+
typeError: true
|
1788
|
+
});
|
1789
|
+
return;
|
1790
|
+
}
|
1791
|
+
if (Array.isArray(node)) {
|
1792
|
+
if (!errors[path]) {
|
1793
|
+
errors[path] = [];
|
1794
|
+
}
|
1795
|
+
errors[path].push({
|
1796
|
+
message: "Expected 'object', got 'array'",
|
1797
|
+
typeError: true
|
1798
|
+
});
|
1799
|
+
return;
|
1800
|
+
}
|
1801
|
+
if (node === null) {
|
1802
|
+
if (!errors[path]) {
|
1803
|
+
errors[path] = [];
|
1804
|
+
}
|
1805
|
+
errors[path].push({
|
1806
|
+
message: "Expected 'object', got 'null'",
|
1807
|
+
typeError: true
|
1808
|
+
});
|
1809
|
+
return;
|
1810
|
+
}
|
1811
|
+
if ("tag" in node) {
|
1812
|
+
if (typeof node.tag !== "string") {
|
1813
|
+
if (!errors[path]) {
|
1814
|
+
errors[path] = [];
|
1815
|
+
}
|
1816
|
+
errors[path].push({
|
1817
|
+
message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
|
1818
|
+
typeError: true
|
1819
|
+
});
|
1820
|
+
return;
|
1821
|
+
}
|
1822
|
+
}
|
1823
|
+
if ("children" in node) {
|
1824
|
+
if (!Array.isArray(node.children)) {
|
1825
|
+
if (!errors[path]) {
|
1826
|
+
errors[path] = [];
|
1827
|
+
}
|
1828
|
+
errors[path].push({
|
1829
|
+
message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
|
1830
|
+
typeError: true
|
1831
|
+
});
|
1832
|
+
return;
|
1833
|
+
} else {
|
1834
|
+
for (var i = 0; i < node.children.length; i++) {
|
1835
|
+
var child = node.children[i];
|
1836
|
+
var pathAtError = unsafeCreateSourcePath(unsafeCreateSourcePath(path, "children"), i);
|
1837
|
+
if (_typeof(child) === "object") {
|
1838
|
+
this.recursiveAssert(pathAtError, child, errors);
|
1839
|
+
} else if (typeof child === "string") {
|
1840
|
+
continue;
|
1841
|
+
} else {
|
1842
|
+
if (!errors[pathAtError]) {
|
1843
|
+
errors[pathAtError] = [];
|
1844
|
+
}
|
1845
|
+
errors[pathAtError].push({
|
1846
|
+
message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
|
1847
|
+
typeError: true
|
1848
|
+
});
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
}
|
1852
|
+
}
|
1853
|
+
if ("styles" in node) {
|
1854
|
+
if (!Array.isArray(node.styles)) {
|
1855
|
+
if (!errors[path]) {
|
1856
|
+
errors[path] = [];
|
1857
|
+
}
|
1858
|
+
errors[path].push({
|
1859
|
+
message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
|
1860
|
+
typeError: true
|
1861
|
+
});
|
1862
|
+
} else {
|
1863
|
+
for (var _i2 = 0; _i2 < node.styles.length; _i2++) {
|
1864
|
+
var style = node.styles[_i2];
|
1865
|
+
if (typeof style !== "string") {
|
1866
|
+
var _pathAtError = unsafeCreateSourcePath(path, _i2);
|
1867
|
+
if (!errors[_pathAtError]) {
|
1868
|
+
errors[_pathAtError] = [];
|
1869
|
+
}
|
1870
|
+
errors[_pathAtError].push({
|
1871
|
+
message: "Expected 'string', got '".concat(_typeof(style), "'"),
|
1872
|
+
typeError: true
|
1873
|
+
});
|
1874
|
+
}
|
1875
|
+
}
|
1876
|
+
}
|
1877
|
+
}
|
1878
|
+
}
|
2596
1879
|
}, {
|
2597
1880
|
key: "nullable",
|
2598
1881
|
value: function nullable() {
|
2599
|
-
return new
|
1882
|
+
return new RichTextSchema(this.options, true);
|
2600
1883
|
}
|
2601
1884
|
}, {
|
2602
1885
|
key: "serialize",
|
2603
1886
|
value: function serialize() {
|
1887
|
+
var serializedOptions = {
|
1888
|
+
style: this.options.style,
|
1889
|
+
block: this.options.block,
|
1890
|
+
inline: this.options.inline && {
|
1891
|
+
a: this.options.inline.a,
|
1892
|
+
img: this.options.inline.img && _typeof(this.options.inline.img) === "object" ? this.options.inline.img.serialize() : this.options.inline.img
|
1893
|
+
}
|
1894
|
+
};
|
2604
1895
|
return {
|
2605
|
-
type: "
|
2606
|
-
|
2607
|
-
|
1896
|
+
type: "richtext",
|
1897
|
+
opt: this.opt,
|
1898
|
+
options: serializedOptions
|
2608
1899
|
};
|
2609
1900
|
}
|
2610
1901
|
}]);
|
2611
1902
|
}(Schema);
|
2612
|
-
var
|
2613
|
-
return new
|
1903
|
+
var richtext = function richtext(options) {
|
1904
|
+
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
2614
1905
|
};
|
2615
1906
|
|
2616
1907
|
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
@@ -2727,13 +2018,10 @@ id,
|
|
2727
2018
|
schema,
|
2728
2019
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2729
2020
|
source) {
|
2730
|
-
return _defineProperty(_defineProperty(_defineProperty({}, GetSource, source), GetSchema
|
2021
|
+
return _defineProperty(_defineProperty(_defineProperty({}, GetSource, source), GetSchema, schema), Path, id);
|
2731
2022
|
}
|
2732
2023
|
function getSource(valModule) {
|
2733
2024
|
var sourceOrExpr = valModule[GetSource];
|
2734
|
-
if (sourceOrExpr instanceof Expr) {
|
2735
|
-
throw Error("Cannot get raw source of an Expr");
|
2736
|
-
}
|
2737
2025
|
var source = sourceOrExpr;
|
2738
2026
|
return source;
|
2739
2027
|
}
|
@@ -2896,16 +2184,11 @@ function resolvePath(path, valModule, schema) {
|
|
2896
2184
|
resolvedSchema = schemaOfUnionKey.items[part];
|
2897
2185
|
resolvedSource = resolvedSource[part];
|
2898
2186
|
} else if (isRichTextSchema(resolvedSchema)) {
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
|
2903
|
-
|
2904
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
2905
|
-
schema: resolvedSchema,
|
2906
|
-
source: resolvedSource
|
2907
|
-
}
|
2908
|
-
};
|
2187
|
+
if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
|
2188
|
+
var _resolvedSchema$optio, _resolvedSchema$optio2;
|
2189
|
+
resolvedSchema = (_resolvedSchema$optio = resolvedSchema.options) !== null && _resolvedSchema$optio !== void 0 && (_resolvedSchema$optio = _resolvedSchema$optio.inline) !== null && _resolvedSchema$optio !== void 0 && _resolvedSchema$optio.img && typeof ((_resolvedSchema$optio2 = resolvedSchema.options) === null || _resolvedSchema$optio2 === void 0 || (_resolvedSchema$optio2 = _resolvedSchema$optio2.inline) === null || _resolvedSchema$optio2 === void 0 ? void 0 : _resolvedSchema$optio2.img) !== "boolean" ? resolvedSchema.options.inline.img : resolvedSchema;
|
2190
|
+
}
|
2191
|
+
resolvedSource = resolvedSource[part];
|
2909
2192
|
} else {
|
2910
2193
|
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
2911
2194
|
}
|
@@ -3085,19 +2368,37 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
3085
2368
|
_this.isRaw = isRaw;
|
3086
2369
|
return _this;
|
3087
2370
|
}
|
2371
|
+
|
2372
|
+
/**
|
2373
|
+
* @deprecated Use `minLength` instead
|
2374
|
+
*/
|
3088
2375
|
_inherits(StringSchema, _Schema);
|
3089
2376
|
return _createClass(StringSchema, [{
|
3090
2377
|
key: "min",
|
3091
2378
|
value: function min(minLength) {
|
2379
|
+
return this.minLength(minLength);
|
2380
|
+
}
|
2381
|
+
}, {
|
2382
|
+
key: "minLength",
|
2383
|
+
value: function minLength(_minLength) {
|
3092
2384
|
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
3093
|
-
minLength:
|
2385
|
+
minLength: _minLength
|
3094
2386
|
}), this.opt, this.isRaw);
|
3095
2387
|
}
|
2388
|
+
|
2389
|
+
/**
|
2390
|
+
* @deprecated Use `maxLength` instead
|
2391
|
+
*/
|
3096
2392
|
}, {
|
3097
2393
|
key: "max",
|
3098
2394
|
value: function max(maxLength) {
|
2395
|
+
return this.maxLength(maxLength);
|
2396
|
+
}
|
2397
|
+
}, {
|
2398
|
+
key: "maxLength",
|
2399
|
+
value: function maxLength(_maxLength) {
|
3099
2400
|
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
3100
|
-
maxLength:
|
2401
|
+
maxLength: _maxLength
|
3101
2402
|
}), this.opt, this.isRaw);
|
3102
2403
|
}
|
3103
2404
|
}, {
|
@@ -3444,7 +2745,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3444
2745
|
}(Schema);
|
3445
2746
|
var keyOf = function keyOf(valModule) {
|
3446
2747
|
var _valModule$GetSchema;
|
3447
|
-
return new KeyOfSchema(valModule === null || valModule === void 0 || (_valModule$GetSchema = valModule[GetSchema
|
2748
|
+
return new KeyOfSchema(valModule === null || valModule === void 0 || (_valModule$GetSchema = valModule[GetSchema]) === null || _valModule$GetSchema === void 0 ? void 0 : _valModule$GetSchema.serialize(), getValPath(valModule));
|
3448
2749
|
};
|
3449
2750
|
|
3450
2751
|
var DateSchema = /*#__PURE__*/function (_Schema) {
|
@@ -3659,6 +2960,28 @@ var initImage = function initImage(config) {
|
|
3659
2960
|
return image;
|
3660
2961
|
};
|
3661
2962
|
|
2963
|
+
/**
|
2964
|
+
* A remote source represents data that is not stored locally.
|
2965
|
+
*/
|
2966
|
+
|
2967
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2968
|
+
var initRemote = function initRemote(config) {
|
2969
|
+
function remote(ref, metadata) {
|
2970
|
+
return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "remote"), "metadata", metadata);
|
2971
|
+
}
|
2972
|
+
return remote;
|
2973
|
+
};
|
2974
|
+
function createRemoteRef(remoteHost, _ref2) {
|
2975
|
+
var publicProjectId = _ref2.publicProjectId,
|
2976
|
+
coreVersion = _ref2.coreVersion,
|
2977
|
+
validationHash = _ref2.validationHash,
|
2978
|
+
fileHash = _ref2.fileHash,
|
2979
|
+
filePath = _ref2.filePath,
|
2980
|
+
bucket = _ref2.bucket;
|
2981
|
+
// NOTE: the core version is part of the validation hash, but it is also in the uri to make it easier to understand which version the remote file was validated against.
|
2982
|
+
return "".concat(remoteHost, "/file/p/").concat(publicProjectId, "/b/").concat(bucket, "/v/").concat(coreVersion, "/h/").concat(validationHash, "/f/").concat(fileHash, "/p/").concat(filePath);
|
2983
|
+
}
|
2984
|
+
|
3662
2985
|
/* eslint-disable @typescript-eslint/ban-types */
|
3663
2986
|
// import { i18n, I18n } from "./source/future/i18n";
|
3664
2987
|
// import { remote } from "./source/future/remote";
|
@@ -3696,7 +3019,7 @@ var initVal = function initVal(config) {
|
|
3696
3019
|
},
|
3697
3020
|
c: {
|
3698
3021
|
define: define,
|
3699
|
-
|
3022
|
+
remote: initRemote(),
|
3700
3023
|
file: initFile(config),
|
3701
3024
|
image: initImage(config)
|
3702
3025
|
},
|
@@ -3725,6 +3048,52 @@ function modules(config, modules) {
|
|
3725
3048
|
};
|
3726
3049
|
}
|
3727
3050
|
|
3051
|
+
var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
|
3052
|
+
function splitRemoteRef(ref) {
|
3053
|
+
var match = ref.match(RegEx);
|
3054
|
+
if (!match) {
|
3055
|
+
return {
|
3056
|
+
status: "error",
|
3057
|
+
error: "Invalid remote ref: " + ref
|
3058
|
+
};
|
3059
|
+
}
|
3060
|
+
if (match[7].indexOf("public/val/") !== 0) {
|
3061
|
+
return {
|
3062
|
+
status: "error",
|
3063
|
+
error: "Invalid remote ref: " + ref
|
3064
|
+
};
|
3065
|
+
}
|
3066
|
+
return {
|
3067
|
+
status: "success",
|
3068
|
+
remoteHost: match[1],
|
3069
|
+
projectId: match[2],
|
3070
|
+
bucket: match[3],
|
3071
|
+
version: match[4],
|
3072
|
+
validationHash: match[5],
|
3073
|
+
fileHash: match[6],
|
3074
|
+
filePath: match[7]
|
3075
|
+
};
|
3076
|
+
}
|
3077
|
+
|
3078
|
+
var DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
|
3079
|
+
function convertRemoteSource(src) {
|
3080
|
+
if (src !== null && src !== void 0 && src.patch_id) {
|
3081
|
+
var splitRemoteRefDataRes = splitRemoteRef(src[FILE_REF_PROP]);
|
3082
|
+
if (splitRemoteRefDataRes.status === "success") {
|
3083
|
+
return {
|
3084
|
+
url: "/api/val/files/" + splitRemoteRefDataRes.filePath + "?patch_id=".concat(src["patch_id"], "&remote=true"),
|
3085
|
+
metadata: src.metadata
|
3086
|
+
};
|
3087
|
+
} else {
|
3088
|
+
console.warn("Internal Val error: failed to split remote ref: ".concat(src[FILE_REF_PROP], ". The data format is different than what is expected. Check Val versions for mismatches."), splitRemoteRefDataRes.error);
|
3089
|
+
}
|
3090
|
+
}
|
3091
|
+
return {
|
3092
|
+
url: src[FILE_REF_PROP],
|
3093
|
+
metadata: src.metadata
|
3094
|
+
};
|
3095
|
+
}
|
3096
|
+
|
3728
3097
|
var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
3729
3098
|
_classCallCheck(this, PatchError);
|
3730
3099
|
this.message = message;
|
@@ -3851,140 +3220,6 @@ function derefPatch(patch, document, ops) {
|
|
3851
3220
|
});
|
3852
3221
|
}
|
3853
3222
|
|
3854
|
-
function getVal(selector) {
|
3855
|
-
return newValProxy(serializedValOfSelectorSource(selector));
|
3856
|
-
}
|
3857
|
-
|
3858
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3859
|
-
function isArrayOrArraySelector(child) {
|
3860
|
-
if (isSelector$1(child)) {
|
3861
|
-
return _typeof(child[GetSource]) === "object" && child[GetSource] !== null && Array.isArray(child[GetSource]);
|
3862
|
-
}
|
3863
|
-
return Array.isArray(child);
|
3864
|
-
}
|
3865
|
-
|
3866
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3867
|
-
function isObjectOrObjectSelector(child) {
|
3868
|
-
if (isSelector$1(child)) {
|
3869
|
-
return _typeof(child[GetSource]) === "object" && child[GetSource] !== null && !Array.isArray(child[GetSource]);
|
3870
|
-
}
|
3871
|
-
return _typeof(child) === "object";
|
3872
|
-
}
|
3873
|
-
function serializedValOfSelectorSource(selector) {
|
3874
|
-
var wrappedSelector = newSelectorProxy$1(selector); // NOTE: we do this if call-site uses a literal with selectors inside
|
3875
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3876
|
-
function rec(child) {
|
3877
|
-
var isArray = isArrayOrArraySelector(child);
|
3878
|
-
var isObject = isObjectOrObjectSelector(child);
|
3879
|
-
if (isArray) {
|
3880
|
-
var array = GetSource in child ? child[GetSource] : child;
|
3881
|
-
var valPath = Path$1 in child ? child[Path$1] : undefined;
|
3882
|
-
return {
|
3883
|
-
val: array.map(function (item, i) {
|
3884
|
-
return rec(isSelector$1(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
3885
|
-
? item : newSelectorProxy$1(item, createValPathOfItem(valPath, i)));
|
3886
|
-
}),
|
3887
|
-
valPath: valPath
|
3888
|
-
};
|
3889
|
-
} else if (isObject) {
|
3890
|
-
var obj = GetSource in child ? child[GetSource] : child;
|
3891
|
-
var _valPath = Path$1 in child ? child[Path$1] : undefined;
|
3892
|
-
return {
|
3893
|
-
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
3894
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
3895
|
-
key = _ref2[0],
|
3896
|
-
value = _ref2[1];
|
3897
|
-
return [key, rec(isSelector$1(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
3898
|
-
? value : newSelectorProxy$1(value, createValPathOfItem(_valPath, key)))];
|
3899
|
-
})),
|
3900
|
-
valPath: _valPath
|
3901
|
-
};
|
3902
|
-
} else if (isSelector$1(child)) {
|
3903
|
-
return {
|
3904
|
-
val: rec(child[GetSource]),
|
3905
|
-
valPath: child[Path$1]
|
3906
|
-
};
|
3907
|
-
} else {
|
3908
|
-
return child;
|
3909
|
-
}
|
3910
|
-
}
|
3911
|
-
return rec(wrappedSelector);
|
3912
|
-
}
|
3913
|
-
function strip(value) {
|
3914
|
-
var val = isSerializedVal(value) ? value.val : value;
|
3915
|
-
switch (_typeof(val)) {
|
3916
|
-
case "function":
|
3917
|
-
case "symbol":
|
3918
|
-
throw Error("Invalid val type: ".concat(_typeof(val)));
|
3919
|
-
case "object":
|
3920
|
-
if (val === null) {
|
3921
|
-
return null;
|
3922
|
-
} else if (Array.isArray(val)) {
|
3923
|
-
return val.map(strip);
|
3924
|
-
} else {
|
3925
|
-
return Object.fromEntries(Object.entries(val).map(function (_ref3) {
|
3926
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
3927
|
-
key = _ref4[0],
|
3928
|
-
value = _ref4[1];
|
3929
|
-
return [key, value && strip(value)];
|
3930
|
-
}));
|
3931
|
-
}
|
3932
|
-
// intentional fallthrough
|
3933
|
-
// eslint-disable-next-line no-fallthrough
|
3934
|
-
default:
|
3935
|
-
return val;
|
3936
|
-
}
|
3937
|
-
}
|
3938
|
-
function newValProxy(val) {
|
3939
|
-
var source = val.val;
|
3940
|
-
switch (_typeof(source)) {
|
3941
|
-
case "function":
|
3942
|
-
case "symbol":
|
3943
|
-
throw Error("Invalid val type: ".concat(_typeof(source)));
|
3944
|
-
case "object":
|
3945
|
-
if (source !== null) {
|
3946
|
-
// Handles both objects and arrays!
|
3947
|
-
return new Proxy(source, {
|
3948
|
-
has: function has(target, prop) {
|
3949
|
-
if (prop === "val") {
|
3950
|
-
return true;
|
3951
|
-
}
|
3952
|
-
if (prop === Path$1) {
|
3953
|
-
return true;
|
3954
|
-
}
|
3955
|
-
return hasOwn(target, prop);
|
3956
|
-
},
|
3957
|
-
get: function get(target, prop) {
|
3958
|
-
if (prop === Path$1) {
|
3959
|
-
return val.valPath;
|
3960
|
-
}
|
3961
|
-
if (prop === "val") {
|
3962
|
-
return strip(val);
|
3963
|
-
}
|
3964
|
-
if (Array.isArray(target) && prop === "length") {
|
3965
|
-
return target.length;
|
3966
|
-
}
|
3967
|
-
if (hasOwn(source, prop)) {
|
3968
|
-
var _Reflect$get$valPath, _Reflect$get;
|
3969
|
-
return newValProxy({
|
3970
|
-
val: Reflect.get(target, prop).val,
|
3971
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
3972
|
-
});
|
3973
|
-
}
|
3974
|
-
return Reflect.get(target, prop);
|
3975
|
-
}
|
3976
|
-
});
|
3977
|
-
}
|
3978
|
-
// intentional fallthrough
|
3979
|
-
// eslint-disable-next-line no-fallthrough
|
3980
|
-
default:
|
3981
|
-
return _defineProperty(_defineProperty({}, Path$1, val.valPath), "val", val.val);
|
3982
|
-
}
|
3983
|
-
}
|
3984
|
-
function hasOwn(obj, prop) {
|
3985
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
3986
|
-
}
|
3987
|
-
|
3988
3223
|
/**
|
3989
3224
|
* From: https://github.com/kawanet/sha256-uint8array/commit/a035f83824c319d01ca1e7559fdcf1632c0cd6c4
|
3990
3225
|
*
|
@@ -5039,6 +4274,36 @@ function filenameToMimeType(filename) {
|
|
5039
4274
|
}
|
5040
4275
|
}
|
5041
4276
|
|
4277
|
+
/**
|
4278
|
+
* The validation basis is used in remote refs to determine if the remote content needs to be re-validated.
|
4279
|
+
*
|
4280
|
+
* If the validation basis changes, we need to re-validate the remote content.
|
4281
|
+
*
|
4282
|
+
* NOTE: We do not care if the file path is different as long as the extension is the same.
|
4283
|
+
* This way we can rename a file, without having to re-validate it.
|
4284
|
+
* The version is outside of the validation hash, so that it is possible to manually fix the version without having to re-validate.
|
4285
|
+
*/
|
4286
|
+
function getValidationBasis(coreVersion, schema, fileExt, metadata, fileHash) {
|
4287
|
+
var metadataValidationBasis = "".concat((metadata === null || metadata === void 0 ? void 0 : metadata.width) || "").concat((metadata === null || metadata === void 0 ? void 0 : metadata.height) || "").concat(metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
|
4288
|
+
var schemaValidationBasis = {
|
4289
|
+
type: schema.type,
|
4290
|
+
opt: schema.opt,
|
4291
|
+
options: _objectSpread2({}, schema.options)
|
4292
|
+
};
|
4293
|
+
return coreVersion + JSON.stringify(schemaValidationBasis) + fileExt + metadataValidationBasis + fileHash;
|
4294
|
+
}
|
4295
|
+
function getValidationHash(coreVersion, schema, fileExt, metadata, fileHash, textEncoder) {
|
4296
|
+
return getSHA256Hash(textEncoder.encode(getValidationBasis(coreVersion, schema, fileExt, metadata, fileHash))).slice(0, 4); // we do not need a lot of bits for the validation hash, since it is only used to identify the validation basis
|
4297
|
+
}
|
4298
|
+
|
4299
|
+
function hashToRemoteFileHash(hash) {
|
4300
|
+
return hash.slice(0, 12 // 12 hex characters = 6 bytes = 48 bits = 2^48 = 281474976710656 possibilities or 1 in 281474976710656 or using birthday problem estimate with 10K files: p = (k, n) => (k*k)/(2x2**n) and p(10_000,12*4) = 1.7763568394002505e-7 chance of collision which should be good enough
|
4301
|
+
);
|
4302
|
+
}
|
4303
|
+
function getFileHash(text) {
|
4304
|
+
return hashToRemoteFileHash(getSHA256Hash(new Uint8Array(text)));
|
4305
|
+
}
|
4306
|
+
|
5042
4307
|
function deserializeSchema(serialized) {
|
5043
4308
|
var _serialized$options;
|
5044
4309
|
switch (serialized.type) {
|
@@ -5071,7 +4336,16 @@ function deserializeSchema(serialized) {
|
|
5071
4336
|
// TODO: we do not really need any here - right?
|
5072
4337
|
serialized.opt);
|
5073
4338
|
case "richtext":
|
5074
|
-
|
4339
|
+
{
|
4340
|
+
var _serialized$options2, _serialized$options3;
|
4341
|
+
var deserializedOptions = _objectSpread2(_objectSpread2({}, serialized.options || {}), {}, {
|
4342
|
+
inline: _typeof((_serialized$options2 = serialized.options) === null || _serialized$options2 === void 0 || (_serialized$options2 = _serialized$options2.inline) === null || _serialized$options2 === void 0 ? void 0 : _serialized$options2.img) === "object" ? {
|
4343
|
+
a: serialized.options.inline.a,
|
4344
|
+
img: deserializeSchema(serialized.options.inline.img)
|
4345
|
+
} : (_serialized$options3 = serialized.options) === null || _serialized$options3 === void 0 ? void 0 : _serialized$options3.inline
|
4346
|
+
});
|
4347
|
+
return new RichTextSchema(deserializedOptions, serialized.opt);
|
4348
|
+
}
|
5075
4349
|
case "record":
|
5076
4350
|
return new RecordSchema(deserializeSchema(serialized.item), serialized.opt);
|
5077
4351
|
case "keyOf":
|
@@ -5109,14 +4383,23 @@ var Internal = {
|
|
5109
4383
|
}()
|
5110
4384
|
},
|
5111
4385
|
convertFileSource: convertFileSource,
|
4386
|
+
convertRemoteSource: convertRemoteSource,
|
5112
4387
|
getSchema: getSchema,
|
5113
4388
|
getValPath: getValPath,
|
5114
|
-
getVal: getVal,
|
5115
4389
|
getSource: getSource,
|
5116
4390
|
resolvePath: resolvePath,
|
5117
4391
|
splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
|
5118
4392
|
joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
|
4393
|
+
remote: {
|
4394
|
+
createRemoteRef: createRemoteRef,
|
4395
|
+
getValidationBasis: getValidationBasis,
|
4396
|
+
getValidationHash: getValidationHash,
|
4397
|
+
getFileHash: getFileHash,
|
4398
|
+
hashToRemoteFileHash: hashToRemoteFileHash,
|
4399
|
+
splitRemoteRef: splitRemoteRef
|
4400
|
+
},
|
5119
4401
|
isVal: isVal,
|
4402
|
+
isFile: isFile,
|
5120
4403
|
createValPathOfItem: createValPathOfItem,
|
5121
4404
|
getSHA256Hash: getSHA256Hash,
|
5122
4405
|
initSchema: initSchema,
|
@@ -5182,9 +4465,8 @@ function tryJsonParse(str) {
|
|
5182
4465
|
|
5183
4466
|
exports.ArraySchema = ArraySchema;
|
5184
4467
|
exports.BooleanSchema = BooleanSchema;
|
5185
|
-
exports.
|
4468
|
+
exports.DEFAULT_VAL_REMOTE_HOST = DEFAULT_VAL_REMOTE_HOST;
|
5186
4469
|
exports.DateSchema = DateSchema;
|
5187
|
-
exports.Expr = Expr;
|
5188
4470
|
exports.FATAL_ERROR_TYPES = FATAL_ERROR_TYPES;
|
5189
4471
|
exports.FILE_REF_PROP = FILE_REF_PROP;
|
5190
4472
|
exports.FILE_REF_SUBTYPE_TAG = FILE_REF_SUBTYPE_TAG;
|
@@ -5195,17 +4477,13 @@ exports.Internal = Internal;
|
|
5195
4477
|
exports.KeyOfSchema = KeyOfSchema;
|
5196
4478
|
exports.LiteralSchema = LiteralSchema;
|
5197
4479
|
exports.ModuleFilePathSep = ModuleFilePathSep;
|
5198
|
-
exports.NilSym = NilSym;
|
5199
4480
|
exports.NumberSchema = NumberSchema;
|
5200
4481
|
exports.ObjectSchema = ObjectSchema;
|
5201
4482
|
exports.PatchError = PatchError;
|
5202
4483
|
exports.RecordSchema = RecordSchema;
|
5203
4484
|
exports.RichTextSchema = RichTextSchema;
|
5204
4485
|
exports.Schema = Schema;
|
5205
|
-
exports.StringLiteral = StringLiteral;
|
5206
4486
|
exports.StringSchema = StringSchema;
|
5207
|
-
exports.StringTemplate = StringTemplate;
|
5208
|
-
exports.Sym = Sym;
|
5209
4487
|
exports.UnionSchema = UnionSchema;
|
5210
4488
|
exports.VAL_EXTENSION = VAL_EXTENSION;
|
5211
4489
|
exports._classCallCheck = _classCallCheck;
|
@@ -5215,9 +4493,6 @@ exports._toConsumableArray = _toConsumableArray;
|
|
5215
4493
|
exports._typeof = _typeof;
|
5216
4494
|
exports.derefPatch = derefPatch;
|
5217
4495
|
exports.deserializeSchema = deserializeSchema;
|
5218
|
-
exports.evaluate = evaluate;
|
5219
|
-
exports.index = index;
|
5220
4496
|
exports.initVal = initVal;
|
5221
4497
|
exports.modules = modules;
|
5222
|
-
exports.parse = parse;
|
5223
4498
|
exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
|