@valbuild/core 0.18.0 → 0.20.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 +4 -1
- package/dist/declarations/src/initSchema.d.ts +2 -2
- package/dist/declarations/src/patch/deref.d.ts +2 -1
- package/dist/declarations/src/patch/operation.d.ts +8 -0
- package/dist/declarations/src/schema/richtext.d.ts +7 -6
- package/dist/declarations/src/schema/string.d.ts +6 -3
- package/dist/declarations/src/selector/future/index.d.ts +3 -3
- package/dist/declarations/src/selector/index.d.ts +3 -3
- package/dist/declarations/src/source/future/remote.d.ts +2 -2
- package/dist/declarations/src/source/index.d.ts +3 -3
- package/dist/declarations/src/source/richtext.d.ts +70 -54
- package/dist/{index-4abf3a1f.esm.js → index-5d1ab97c.esm.js} +1 -1
- package/dist/{index-a9235737.esm.js → index-bccf1907.esm.js} +1 -1
- package/dist/{ops-a2a295f8.esm.js → ops-22b624eb.esm.js} +107 -35
- package/dist/{ops-f3015423.cjs.dev.js → ops-b0a33248.cjs.dev.js} +106 -33
- package/dist/{ops-0d09f8ee.cjs.prod.js → ops-def81fc3.cjs.prod.js} +106 -33
- package/dist/valbuild-core.cjs.dev.js +202 -104
- package/dist/valbuild-core.cjs.prod.js +202 -104
- package/dist/valbuild-core.esm.js +184 -106
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +4 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +6 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +6 -1
- package/patch/dist/valbuild-core-patch.esm.js +8 -3
- package/src/getSha256.ts +8 -0
- package/src/index.ts +21 -5
- package/src/module.ts +33 -2
- package/src/patch/deref.ts +14 -1
- package/src/patch/operation.ts +10 -0
- package/src/patch/parse.ts +1 -0
- package/src/patch/patch.ts +3 -0
- package/src/schema/richtext.ts +19 -73
- package/src/schema/string.ts +14 -4
- package/src/schema/validation.test.ts +2 -2
- package/src/selector/future/index.ts +8 -4
- package/src/selector/index.ts +4 -4
- package/src/source/future/remote.ts +2 -2
- package/src/source/index.ts +2 -2
- package/src/source/richtext.test.ts +178 -0
- package/src/source/richtext.ts +295 -89
- package/tsconfig.json +2 -1
@@ -382,75 +382,132 @@ var union = function union(key) {
|
|
382
382
|
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
383
383
|
index._inherits(RichTextSchema, _Schema);
|
384
384
|
var _super = index._createSuper(RichTextSchema);
|
385
|
-
function RichTextSchema() {
|
385
|
+
function RichTextSchema(options) {
|
386
386
|
var _this;
|
387
|
-
var opt = arguments.length >
|
387
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
388
388
|
index._classCallCheck(this, RichTextSchema);
|
389
389
|
_this = _super.call(this);
|
390
|
+
_this.options = options;
|
390
391
|
_this.opt = opt;
|
391
392
|
return _this;
|
392
393
|
}
|
393
394
|
index._createClass(RichTextSchema, [{
|
394
395
|
key: "validate",
|
395
396
|
value: function validate(path, src) {
|
397
|
+
return false; //TODO
|
398
|
+
}
|
399
|
+
}, {
|
400
|
+
key: "assert",
|
401
|
+
value: function assert(src) {
|
402
|
+
return true; // TODO
|
403
|
+
}
|
404
|
+
}, {
|
405
|
+
key: "optional",
|
406
|
+
value: function optional() {
|
407
|
+
return new RichTextSchema(this.options, true);
|
408
|
+
}
|
409
|
+
}, {
|
410
|
+
key: "serialize",
|
411
|
+
value: function serialize() {
|
412
|
+
return {
|
413
|
+
type: "richtext",
|
414
|
+
opt: this.opt
|
415
|
+
};
|
416
|
+
}
|
417
|
+
}]);
|
418
|
+
return RichTextSchema;
|
419
|
+
}(index.Schema);
|
420
|
+
var richtext = function richtext(options) {
|
421
|
+
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
422
|
+
};
|
423
|
+
|
424
|
+
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
425
|
+
index._inherits(RecordSchema, _Schema);
|
426
|
+
var _super = index._createSuper(RecordSchema);
|
427
|
+
function RecordSchema(item) {
|
428
|
+
var _this;
|
429
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
430
|
+
index._classCallCheck(this, RecordSchema);
|
431
|
+
_this = _super.call(this);
|
432
|
+
_this.item = item;
|
433
|
+
_this.opt = opt;
|
434
|
+
return _this;
|
435
|
+
}
|
436
|
+
index._createClass(RecordSchema, [{
|
437
|
+
key: "validate",
|
438
|
+
value: function validate(path, src) {
|
439
|
+
var _this2 = this;
|
440
|
+
var error = false;
|
396
441
|
if (this.opt && (src === null || src === undefined)) {
|
397
442
|
return false;
|
398
443
|
}
|
399
|
-
if (src
|
400
|
-
return index._defineProperty({}, path, [{
|
401
|
-
message: "Expected non-nullable got '".concat(src, "'")
|
402
|
-
}]);
|
403
|
-
}
|
404
|
-
if (index._typeof(src) !== "object" && !Array.isArray(src)) {
|
405
|
-
return index._defineProperty({}, path, [{
|
406
|
-
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(index._typeof(src), "'"),
|
407
|
-
value: src
|
408
|
-
}]);
|
409
|
-
}
|
410
|
-
if (src[index.VAL_EXTENSION] !== "richtext") {
|
411
|
-
return index._defineProperty({}, path, [{
|
412
|
-
message: "Expected _type key with value 'richtext' got '".concat(src[index.VAL_EXTENSION], "'"),
|
413
|
-
value: src
|
414
|
-
}]);
|
415
|
-
}
|
416
|
-
if (src.type !== "root") {
|
444
|
+
if (index._typeof(src) !== "object") {
|
417
445
|
return index._defineProperty({}, path, [{
|
418
|
-
message: "Expected
|
419
|
-
value: src
|
446
|
+
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
420
447
|
}]);
|
421
448
|
}
|
422
|
-
if (
|
449
|
+
if (Array.isArray(src)) {
|
423
450
|
return index._defineProperty({}, path, [{
|
424
|
-
message: "Expected
|
425
|
-
value: src
|
451
|
+
message: "Expected 'object', got 'array'"
|
426
452
|
}]);
|
427
453
|
}
|
428
|
-
|
454
|
+
Object.entries(src).forEach(function (_ref3) {
|
455
|
+
var _ref4 = index._slicedToArray(_ref3, 2),
|
456
|
+
key = _ref4[0],
|
457
|
+
elem = _ref4[1];
|
458
|
+
var subPath = createValPathOfItem(path, key);
|
459
|
+
if (!subPath) {
|
460
|
+
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
461
|
+
// Should! never happen
|
462
|
+
src);
|
463
|
+
} else {
|
464
|
+
var subError = _this2.item.validate(subPath, elem);
|
465
|
+
if (subError && error) {
|
466
|
+
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
467
|
+
} else if (subError) {
|
468
|
+
error = subError;
|
469
|
+
}
|
470
|
+
}
|
471
|
+
});
|
472
|
+
return error;
|
429
473
|
}
|
430
474
|
}, {
|
431
475
|
key: "assert",
|
432
476
|
value: function assert(src) {
|
433
|
-
|
434
|
-
|
477
|
+
if (this.opt && (src === null || src === undefined)) {
|
478
|
+
return true;
|
479
|
+
}
|
480
|
+
if (!src) {
|
481
|
+
return false;
|
482
|
+
}
|
483
|
+
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
484
|
+
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
485
|
+
_item = _Object$entries$_i[1];
|
486
|
+
if (!this.item.assert(_item)) {
|
487
|
+
return false;
|
488
|
+
}
|
489
|
+
}
|
490
|
+
return index._typeof(src) === "object" && !Array.isArray(src);
|
435
491
|
}
|
436
492
|
}, {
|
437
493
|
key: "optional",
|
438
494
|
value: function optional() {
|
439
|
-
return new
|
495
|
+
return new RecordSchema(this.item, true);
|
440
496
|
}
|
441
497
|
}, {
|
442
498
|
key: "serialize",
|
443
499
|
value: function serialize() {
|
444
500
|
return {
|
445
|
-
type: "
|
501
|
+
type: "record",
|
502
|
+
item: this.item.serialize(),
|
446
503
|
opt: this.opt
|
447
504
|
};
|
448
505
|
}
|
449
506
|
}]);
|
450
|
-
return
|
507
|
+
return RecordSchema;
|
451
508
|
}(index.Schema);
|
452
|
-
var
|
453
|
-
return new
|
509
|
+
var record = function record(schema) {
|
510
|
+
return new RecordSchema(schema);
|
454
511
|
};
|
455
512
|
|
456
513
|
function content(
|
@@ -477,6 +534,9 @@ function splitModuleIdAndModulePath(path) {
|
|
477
534
|
function isObjectSchema(schema) {
|
478
535
|
return schema instanceof ObjectSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
479
536
|
}
|
537
|
+
function isRecordSchema(schema) {
|
538
|
+
return schema instanceof RecordSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "record";
|
539
|
+
}
|
480
540
|
function isArraySchema(schema) {
|
481
541
|
return schema instanceof ArraySchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
482
542
|
}
|
@@ -535,6 +595,18 @@ function resolvePath(path, valModule, schema) {
|
|
535
595
|
}
|
536
596
|
resolvedSource = resolvedSource[part];
|
537
597
|
resolvedSchema = resolvedSchema.item;
|
598
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
599
|
+
if (typeof part !== "string") {
|
600
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
601
|
+
}
|
602
|
+
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
603
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
|
604
|
+
}
|
605
|
+
if (!resolvedSource[part]) {
|
606
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
607
|
+
}
|
608
|
+
resolvedSource = resolvedSource[part];
|
609
|
+
resolvedSchema = resolvedSchema.item;
|
538
610
|
} else if (isObjectSchema(resolvedSchema)) {
|
539
611
|
if (index._typeof(resolvedSource) !== "object") {
|
540
612
|
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
@@ -678,6 +750,7 @@ exports.getSource = getSource;
|
|
678
750
|
exports.isSelector = isSelector;
|
679
751
|
exports.newSelectorProxy = newSelectorProxy;
|
680
752
|
exports.object = object;
|
753
|
+
exports.record = record;
|
681
754
|
exports.resolvePath = resolvePath;
|
682
755
|
exports.richtext = richtext;
|
683
756
|
exports.splitModuleIdAndModulePath = splitModuleIdAndModulePath;
|
@@ -382,75 +382,132 @@ var union = function union(key) {
|
|
382
382
|
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
383
383
|
index._inherits(RichTextSchema, _Schema);
|
384
384
|
var _super = index._createSuper(RichTextSchema);
|
385
|
-
function RichTextSchema() {
|
385
|
+
function RichTextSchema(options) {
|
386
386
|
var _this;
|
387
|
-
var opt = arguments.length >
|
387
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
388
388
|
index._classCallCheck(this, RichTextSchema);
|
389
389
|
_this = _super.call(this);
|
390
|
+
_this.options = options;
|
390
391
|
_this.opt = opt;
|
391
392
|
return _this;
|
392
393
|
}
|
393
394
|
index._createClass(RichTextSchema, [{
|
394
395
|
key: "validate",
|
395
396
|
value: function validate(path, src) {
|
397
|
+
return false; //TODO
|
398
|
+
}
|
399
|
+
}, {
|
400
|
+
key: "assert",
|
401
|
+
value: function assert(src) {
|
402
|
+
return true; // TODO
|
403
|
+
}
|
404
|
+
}, {
|
405
|
+
key: "optional",
|
406
|
+
value: function optional() {
|
407
|
+
return new RichTextSchema(this.options, true);
|
408
|
+
}
|
409
|
+
}, {
|
410
|
+
key: "serialize",
|
411
|
+
value: function serialize() {
|
412
|
+
return {
|
413
|
+
type: "richtext",
|
414
|
+
opt: this.opt
|
415
|
+
};
|
416
|
+
}
|
417
|
+
}]);
|
418
|
+
return RichTextSchema;
|
419
|
+
}(index.Schema);
|
420
|
+
var richtext = function richtext(options) {
|
421
|
+
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
422
|
+
};
|
423
|
+
|
424
|
+
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
425
|
+
index._inherits(RecordSchema, _Schema);
|
426
|
+
var _super = index._createSuper(RecordSchema);
|
427
|
+
function RecordSchema(item) {
|
428
|
+
var _this;
|
429
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
430
|
+
index._classCallCheck(this, RecordSchema);
|
431
|
+
_this = _super.call(this);
|
432
|
+
_this.item = item;
|
433
|
+
_this.opt = opt;
|
434
|
+
return _this;
|
435
|
+
}
|
436
|
+
index._createClass(RecordSchema, [{
|
437
|
+
key: "validate",
|
438
|
+
value: function validate(path, src) {
|
439
|
+
var _this2 = this;
|
440
|
+
var error = false;
|
396
441
|
if (this.opt && (src === null || src === undefined)) {
|
397
442
|
return false;
|
398
443
|
}
|
399
|
-
if (src
|
400
|
-
return index._defineProperty({}, path, [{
|
401
|
-
message: "Expected non-nullable got '".concat(src, "'")
|
402
|
-
}]);
|
403
|
-
}
|
404
|
-
if (index._typeof(src) !== "object" && !Array.isArray(src)) {
|
405
|
-
return index._defineProperty({}, path, [{
|
406
|
-
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(index._typeof(src), "'"),
|
407
|
-
value: src
|
408
|
-
}]);
|
409
|
-
}
|
410
|
-
if (src[index.VAL_EXTENSION] !== "richtext") {
|
411
|
-
return index._defineProperty({}, path, [{
|
412
|
-
message: "Expected _type key with value 'richtext' got '".concat(src[index.VAL_EXTENSION], "'"),
|
413
|
-
value: src
|
414
|
-
}]);
|
415
|
-
}
|
416
|
-
if (src.type !== "root") {
|
444
|
+
if (index._typeof(src) !== "object") {
|
417
445
|
return index._defineProperty({}, path, [{
|
418
|
-
message: "Expected
|
419
|
-
value: src
|
446
|
+
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
420
447
|
}]);
|
421
448
|
}
|
422
|
-
if (
|
449
|
+
if (Array.isArray(src)) {
|
423
450
|
return index._defineProperty({}, path, [{
|
424
|
-
message: "Expected
|
425
|
-
value: src
|
451
|
+
message: "Expected 'object', got 'array'"
|
426
452
|
}]);
|
427
453
|
}
|
428
|
-
|
454
|
+
Object.entries(src).forEach(function (_ref3) {
|
455
|
+
var _ref4 = index._slicedToArray(_ref3, 2),
|
456
|
+
key = _ref4[0],
|
457
|
+
elem = _ref4[1];
|
458
|
+
var subPath = createValPathOfItem(path, key);
|
459
|
+
if (!subPath) {
|
460
|
+
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
461
|
+
// Should! never happen
|
462
|
+
src);
|
463
|
+
} else {
|
464
|
+
var subError = _this2.item.validate(subPath, elem);
|
465
|
+
if (subError && error) {
|
466
|
+
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
467
|
+
} else if (subError) {
|
468
|
+
error = subError;
|
469
|
+
}
|
470
|
+
}
|
471
|
+
});
|
472
|
+
return error;
|
429
473
|
}
|
430
474
|
}, {
|
431
475
|
key: "assert",
|
432
476
|
value: function assert(src) {
|
433
|
-
|
434
|
-
|
477
|
+
if (this.opt && (src === null || src === undefined)) {
|
478
|
+
return true;
|
479
|
+
}
|
480
|
+
if (!src) {
|
481
|
+
return false;
|
482
|
+
}
|
483
|
+
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
484
|
+
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
485
|
+
_item = _Object$entries$_i[1];
|
486
|
+
if (!this.item.assert(_item)) {
|
487
|
+
return false;
|
488
|
+
}
|
489
|
+
}
|
490
|
+
return index._typeof(src) === "object" && !Array.isArray(src);
|
435
491
|
}
|
436
492
|
}, {
|
437
493
|
key: "optional",
|
438
494
|
value: function optional() {
|
439
|
-
return new
|
495
|
+
return new RecordSchema(this.item, true);
|
440
496
|
}
|
441
497
|
}, {
|
442
498
|
key: "serialize",
|
443
499
|
value: function serialize() {
|
444
500
|
return {
|
445
|
-
type: "
|
501
|
+
type: "record",
|
502
|
+
item: this.item.serialize(),
|
446
503
|
opt: this.opt
|
447
504
|
};
|
448
505
|
}
|
449
506
|
}]);
|
450
|
-
return
|
507
|
+
return RecordSchema;
|
451
508
|
}(index.Schema);
|
452
|
-
var
|
453
|
-
return new
|
509
|
+
var record = function record(schema) {
|
510
|
+
return new RecordSchema(schema);
|
454
511
|
};
|
455
512
|
|
456
513
|
function content(
|
@@ -477,6 +534,9 @@ function splitModuleIdAndModulePath(path) {
|
|
477
534
|
function isObjectSchema(schema) {
|
478
535
|
return schema instanceof ObjectSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
479
536
|
}
|
537
|
+
function isRecordSchema(schema) {
|
538
|
+
return schema instanceof RecordSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "record";
|
539
|
+
}
|
480
540
|
function isArraySchema(schema) {
|
481
541
|
return schema instanceof ArraySchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
482
542
|
}
|
@@ -535,6 +595,18 @@ function resolvePath(path, valModule, schema) {
|
|
535
595
|
}
|
536
596
|
resolvedSource = resolvedSource[part];
|
537
597
|
resolvedSchema = resolvedSchema.item;
|
598
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
599
|
+
if (typeof part !== "string") {
|
600
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
601
|
+
}
|
602
|
+
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
603
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
|
604
|
+
}
|
605
|
+
if (!resolvedSource[part]) {
|
606
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
607
|
+
}
|
608
|
+
resolvedSource = resolvedSource[part];
|
609
|
+
resolvedSchema = resolvedSchema.item;
|
538
610
|
} else if (isObjectSchema(resolvedSchema)) {
|
539
611
|
if (index._typeof(resolvedSource) !== "object") {
|
540
612
|
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
@@ -678,6 +750,7 @@ exports.getSource = getSource;
|
|
678
750
|
exports.isSelector = isSelector;
|
679
751
|
exports.newSelectorProxy = newSelectorProxy;
|
680
752
|
exports.object = object;
|
753
|
+
exports.record = record;
|
681
754
|
exports.resolvePath = resolvePath;
|
682
755
|
exports.richtext = richtext;
|
683
756
|
exports.splitModuleIdAndModulePath = splitModuleIdAndModulePath;
|