@valbuild/core 0.17.0 → 0.19.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 +8 -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/keyOf.d.ts +2 -2
- 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-3e3e839e.esm.js → index-5d1ab97c.esm.js} +1 -1
- package/dist/{index-369caccf.esm.js → index-bccf1907.esm.js} +1 -1
- package/dist/{ops-f3015423.cjs.dev.js → ops-2d7e1742.cjs.dev.js} +106 -33
- package/dist/{ops-23a5abb2.esm.js → ops-7ef32b0a.esm.js} +107 -35
- package/dist/{ops-0d09f8ee.cjs.prod.js → ops-ae089ab2.cjs.prod.js} +106 -33
- package/dist/valbuild-core.cjs.dev.js +311 -15
- package/dist/valbuild-core.cjs.prod.js +311 -15
- package/dist/valbuild-core.esm.js +294 -18
- 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/initSchema.ts +6 -0
- 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/keyOf.ts +2 -2
- 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
@@ -1,4 +1,4 @@
|
|
1
|
-
import { e as _typeof,
|
1
|
+
import { e as _typeof, n as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, f as convertFileSource, d as _defineProperty, m as GetSource, P as Path, G as GetSchema, S as Schema, E as Expr, _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, k as _slicedToArray, j as _objectSpread2, u as _toConsumableArray, I as ImageSchema } from './index-bccf1907.esm.js';
|
2
2
|
import { _ as _createForOfIteratorHelper } from './result-b96df128.esm.js';
|
3
3
|
|
4
4
|
function hasOwn(obj, prop) {
|
@@ -380,75 +380,132 @@ var union = function union(key) {
|
|
380
380
|
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
381
381
|
_inherits(RichTextSchema, _Schema);
|
382
382
|
var _super = _createSuper(RichTextSchema);
|
383
|
-
function RichTextSchema() {
|
383
|
+
function RichTextSchema(options) {
|
384
384
|
var _this;
|
385
|
-
var opt = arguments.length >
|
385
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
386
386
|
_classCallCheck(this, RichTextSchema);
|
387
387
|
_this = _super.call(this);
|
388
|
+
_this.options = options;
|
388
389
|
_this.opt = opt;
|
389
390
|
return _this;
|
390
391
|
}
|
391
392
|
_createClass(RichTextSchema, [{
|
392
393
|
key: "validate",
|
393
394
|
value: function validate(path, src) {
|
395
|
+
return false; //TODO
|
396
|
+
}
|
397
|
+
}, {
|
398
|
+
key: "assert",
|
399
|
+
value: function assert(src) {
|
400
|
+
return true; // TODO
|
401
|
+
}
|
402
|
+
}, {
|
403
|
+
key: "optional",
|
404
|
+
value: function optional() {
|
405
|
+
return new RichTextSchema(this.options, true);
|
406
|
+
}
|
407
|
+
}, {
|
408
|
+
key: "serialize",
|
409
|
+
value: function serialize() {
|
410
|
+
return {
|
411
|
+
type: "richtext",
|
412
|
+
opt: this.opt
|
413
|
+
};
|
414
|
+
}
|
415
|
+
}]);
|
416
|
+
return RichTextSchema;
|
417
|
+
}(Schema);
|
418
|
+
var richtext = function richtext(options) {
|
419
|
+
return new RichTextSchema(options);
|
420
|
+
};
|
421
|
+
|
422
|
+
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
423
|
+
_inherits(RecordSchema, _Schema);
|
424
|
+
var _super = _createSuper(RecordSchema);
|
425
|
+
function RecordSchema(item) {
|
426
|
+
var _this;
|
427
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
428
|
+
_classCallCheck(this, RecordSchema);
|
429
|
+
_this = _super.call(this);
|
430
|
+
_this.item = item;
|
431
|
+
_this.opt = opt;
|
432
|
+
return _this;
|
433
|
+
}
|
434
|
+
_createClass(RecordSchema, [{
|
435
|
+
key: "validate",
|
436
|
+
value: function validate(path, src) {
|
437
|
+
var _this2 = this;
|
438
|
+
var error = false;
|
394
439
|
if (this.opt && (src === null || src === undefined)) {
|
395
440
|
return false;
|
396
441
|
}
|
397
|
-
if (src
|
398
|
-
return _defineProperty({}, path, [{
|
399
|
-
message: "Expected non-nullable got '".concat(src, "'")
|
400
|
-
}]);
|
401
|
-
}
|
402
|
-
if (_typeof(src) !== "object" && !Array.isArray(src)) {
|
403
|
-
return _defineProperty({}, path, [{
|
404
|
-
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(_typeof(src), "'"),
|
405
|
-
value: src
|
406
|
-
}]);
|
407
|
-
}
|
408
|
-
if (src[VAL_EXTENSION] !== "richtext") {
|
409
|
-
return _defineProperty({}, path, [{
|
410
|
-
message: "Expected _type key with value 'richtext' got '".concat(src[VAL_EXTENSION], "'"),
|
411
|
-
value: src
|
412
|
-
}]);
|
413
|
-
}
|
414
|
-
if (src.type !== "root") {
|
442
|
+
if (_typeof(src) !== "object") {
|
415
443
|
return _defineProperty({}, path, [{
|
416
|
-
message: "Expected
|
417
|
-
value: src
|
444
|
+
message: "Expected 'object', got '".concat(_typeof(src), "'")
|
418
445
|
}]);
|
419
446
|
}
|
420
|
-
if (
|
447
|
+
if (Array.isArray(src)) {
|
421
448
|
return _defineProperty({}, path, [{
|
422
|
-
message: "Expected
|
423
|
-
value: src
|
449
|
+
message: "Expected 'object', got 'array'"
|
424
450
|
}]);
|
425
451
|
}
|
426
|
-
|
452
|
+
Object.entries(src).forEach(function (_ref3) {
|
453
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
454
|
+
key = _ref4[0],
|
455
|
+
elem = _ref4[1];
|
456
|
+
var subPath = createValPathOfItem(path, key);
|
457
|
+
if (!subPath) {
|
458
|
+
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
459
|
+
// Should! never happen
|
460
|
+
src);
|
461
|
+
} else {
|
462
|
+
var subError = _this2.item.validate(subPath, elem);
|
463
|
+
if (subError && error) {
|
464
|
+
error = _objectSpread2(_objectSpread2({}, subError), error);
|
465
|
+
} else if (subError) {
|
466
|
+
error = subError;
|
467
|
+
}
|
468
|
+
}
|
469
|
+
});
|
470
|
+
return error;
|
427
471
|
}
|
428
472
|
}, {
|
429
473
|
key: "assert",
|
430
474
|
value: function assert(src) {
|
431
|
-
|
432
|
-
|
475
|
+
if (this.opt && (src === null || src === undefined)) {
|
476
|
+
return true;
|
477
|
+
}
|
478
|
+
if (!src) {
|
479
|
+
return false;
|
480
|
+
}
|
481
|
+
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
482
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
483
|
+
_item = _Object$entries$_i[1];
|
484
|
+
if (!this.item.assert(_item)) {
|
485
|
+
return false;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
return _typeof(src) === "object" && !Array.isArray(src);
|
433
489
|
}
|
434
490
|
}, {
|
435
491
|
key: "optional",
|
436
492
|
value: function optional() {
|
437
|
-
return new
|
493
|
+
return new RecordSchema(this.item, true);
|
438
494
|
}
|
439
495
|
}, {
|
440
496
|
key: "serialize",
|
441
497
|
value: function serialize() {
|
442
498
|
return {
|
443
|
-
type: "
|
499
|
+
type: "record",
|
500
|
+
item: this.item.serialize(),
|
444
501
|
opt: this.opt
|
445
502
|
};
|
446
503
|
}
|
447
504
|
}]);
|
448
|
-
return
|
505
|
+
return RecordSchema;
|
449
506
|
}(Schema);
|
450
|
-
var
|
451
|
-
return new
|
507
|
+
var record = function record(schema) {
|
508
|
+
return new RecordSchema(schema);
|
452
509
|
};
|
453
510
|
|
454
511
|
function content(
|
@@ -475,6 +532,9 @@ function splitModuleIdAndModulePath(path) {
|
|
475
532
|
function isObjectSchema(schema) {
|
476
533
|
return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
477
534
|
}
|
535
|
+
function isRecordSchema(schema) {
|
536
|
+
return schema instanceof RecordSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "record";
|
537
|
+
}
|
478
538
|
function isArraySchema(schema) {
|
479
539
|
return schema instanceof ArraySchema || _typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
480
540
|
}
|
@@ -533,6 +593,18 @@ function resolvePath(path, valModule, schema) {
|
|
533
593
|
}
|
534
594
|
resolvedSource = resolvedSource[part];
|
535
595
|
resolvedSchema = resolvedSchema.item;
|
596
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
597
|
+
if (typeof part !== "string") {
|
598
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
599
|
+
}
|
600
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
601
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource)));
|
602
|
+
}
|
603
|
+
if (!resolvedSource[part]) {
|
604
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
605
|
+
}
|
606
|
+
resolvedSource = resolvedSource[part];
|
607
|
+
resolvedSchema = resolvedSchema.item;
|
536
608
|
} else if (isObjectSchema(resolvedSchema)) {
|
537
609
|
if (_typeof(resolvedSource) !== "object") {
|
538
610
|
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
@@ -668,4 +740,4 @@ var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
668
740
|
* NOTE: MAY mutate the input document.
|
669
741
|
*/
|
670
742
|
|
671
|
-
export { PatchError as P, array as a,
|
743
|
+
export { PatchError as P, array as a, record as b, content as c, createValPathOfItem as d, resolvePath as e, getSource as g, isSelector as i, newSelectorProxy as n, object as o, richtext as r, splitModuleIdAndModulePath as s, union as u };
|
@@ -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);
|
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;
|