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