@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
@@ -3,10 +3,31 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var index = require('./index-a6e642dd.cjs.dev.js');
|
6
|
-
var ops = require('./ops-
|
6
|
+
var ops = require('./ops-b0a33248.cjs.dev.js');
|
7
|
+
var marked = require('marked');
|
7
8
|
var expr_dist_valbuildCoreExpr = require('./index-486c7fbf.cjs.dev.js');
|
8
9
|
var result = require('./result-48320acd.cjs.dev.js');
|
9
10
|
|
11
|
+
function _interopNamespace(e) {
|
12
|
+
if (e && e.__esModule) return e;
|
13
|
+
var n = Object.create(null);
|
14
|
+
if (e) {
|
15
|
+
Object.keys(e).forEach(function (k) {
|
16
|
+
if (k !== 'default') {
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () { return e[k]; }
|
21
|
+
});
|
22
|
+
}
|
23
|
+
});
|
24
|
+
}
|
25
|
+
n["default"] = e;
|
26
|
+
return Object.freeze(n);
|
27
|
+
}
|
28
|
+
|
29
|
+
var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
|
30
|
+
|
10
31
|
var NumberSchema = /*#__PURE__*/function (_Schema) {
|
11
32
|
index._inherits(NumberSchema, _Schema);
|
12
33
|
var _super = index._createSuper(NumberSchema);
|
@@ -68,10 +89,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
68
89
|
function StringSchema(options) {
|
69
90
|
var _this;
|
70
91
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
92
|
+
var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
71
93
|
index._classCallCheck(this, StringSchema);
|
72
94
|
_this = _super.call(this);
|
73
95
|
_this.options = options;
|
74
96
|
_this.opt = opt;
|
97
|
+
_this.isRaw = isRaw;
|
75
98
|
return _this;
|
76
99
|
}
|
77
100
|
index._createClass(StringSchema, [{
|
@@ -99,7 +122,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
99
122
|
}, {
|
100
123
|
key: "optional",
|
101
124
|
value: function optional() {
|
102
|
-
return new StringSchema(this.options, true);
|
125
|
+
return new StringSchema(this.options, true, this.isRaw);
|
126
|
+
}
|
127
|
+
}, {
|
128
|
+
key: "raw",
|
129
|
+
value: function raw() {
|
130
|
+
return new StringSchema(this.options, this.opt, true);
|
103
131
|
}
|
104
132
|
}, {
|
105
133
|
key: "serialize",
|
@@ -107,7 +135,8 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
107
135
|
return {
|
108
136
|
type: "string",
|
109
137
|
options: this.options,
|
110
|
-
opt: this.opt
|
138
|
+
opt: this.opt,
|
139
|
+
raw: this.isRaw
|
111
140
|
};
|
112
141
|
}
|
113
142
|
}]);
|
@@ -340,95 +369,6 @@ var keyOf = function keyOf(valModule) {
|
|
340
369
|
return new KeyOfSchema(valModule);
|
341
370
|
};
|
342
371
|
|
343
|
-
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
344
|
-
index._inherits(RecordSchema, _Schema);
|
345
|
-
var _super = index._createSuper(RecordSchema);
|
346
|
-
function RecordSchema(item) {
|
347
|
-
var _this;
|
348
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
349
|
-
index._classCallCheck(this, RecordSchema);
|
350
|
-
_this = _super.call(this);
|
351
|
-
_this.item = item;
|
352
|
-
_this.opt = opt;
|
353
|
-
return _this;
|
354
|
-
}
|
355
|
-
index._createClass(RecordSchema, [{
|
356
|
-
key: "validate",
|
357
|
-
value: function validate(path, src) {
|
358
|
-
var _this2 = this;
|
359
|
-
var error = false;
|
360
|
-
if (this.opt && (src === null || src === undefined)) {
|
361
|
-
return false;
|
362
|
-
}
|
363
|
-
if (index._typeof(src) !== "object") {
|
364
|
-
return index._defineProperty({}, path, [{
|
365
|
-
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
366
|
-
}]);
|
367
|
-
}
|
368
|
-
if (Array.isArray(src)) {
|
369
|
-
return index._defineProperty({}, path, [{
|
370
|
-
message: "Expected 'object', got 'array'"
|
371
|
-
}]);
|
372
|
-
}
|
373
|
-
Object.entries(src).forEach(function (_ref3) {
|
374
|
-
var _ref4 = index._slicedToArray(_ref3, 2),
|
375
|
-
key = _ref4[0],
|
376
|
-
elem = _ref4[1];
|
377
|
-
var subPath = ops.createValPathOfItem(path, key);
|
378
|
-
if (!subPath) {
|
379
|
-
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
380
|
-
// Should! never happen
|
381
|
-
src);
|
382
|
-
} else {
|
383
|
-
var subError = _this2.item.validate(subPath, elem);
|
384
|
-
if (subError && error) {
|
385
|
-
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
386
|
-
} else if (subError) {
|
387
|
-
error = subError;
|
388
|
-
}
|
389
|
-
}
|
390
|
-
});
|
391
|
-
return error;
|
392
|
-
}
|
393
|
-
}, {
|
394
|
-
key: "assert",
|
395
|
-
value: function assert(src) {
|
396
|
-
if (this.opt && (src === null || src === undefined)) {
|
397
|
-
return true;
|
398
|
-
}
|
399
|
-
if (!src) {
|
400
|
-
return false;
|
401
|
-
}
|
402
|
-
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
403
|
-
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
404
|
-
_item = _Object$entries$_i[1];
|
405
|
-
if (!this.item.assert(_item)) {
|
406
|
-
return false;
|
407
|
-
}
|
408
|
-
}
|
409
|
-
return index._typeof(src) === "object" && !Array.isArray(src);
|
410
|
-
}
|
411
|
-
}, {
|
412
|
-
key: "optional",
|
413
|
-
value: function optional() {
|
414
|
-
return new RecordSchema(this.item, true);
|
415
|
-
}
|
416
|
-
}, {
|
417
|
-
key: "serialize",
|
418
|
-
value: function serialize() {
|
419
|
-
return {
|
420
|
-
type: "record",
|
421
|
-
item: this.item.serialize(),
|
422
|
-
opt: this.opt
|
423
|
-
};
|
424
|
-
}
|
425
|
-
}]);
|
426
|
-
return RecordSchema;
|
427
|
-
}(index.Schema);
|
428
|
-
var record = function record(schema) {
|
429
|
-
return new RecordSchema(schema);
|
430
|
-
};
|
431
|
-
|
432
372
|
// import type { F } from "ts-toolbelt";
|
433
373
|
// import { i18n, I18n } from "./schema/future/i18n";
|
434
374
|
// import { oneOf } from "./schema/future/oneOf";
|
@@ -449,23 +389,145 @@ function initSchema() {
|
|
449
389
|
image: index.image,
|
450
390
|
literal: literal,
|
451
391
|
keyOf: keyOf,
|
452
|
-
record: record
|
392
|
+
record: ops.record
|
453
393
|
// i18n: i18n(locales),
|
454
394
|
};
|
455
395
|
}
|
456
396
|
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
397
|
+
// export type FontFamily<O extends RichTextOptions> =
|
398
|
+
// O["fontFamily"] extends Record<string, unknown>
|
399
|
+
// ? `font-${keyof O["fontFamily"] & string}`
|
400
|
+
// : never;
|
401
|
+
// export type FontSize<O extends RichTextOptions> = O["fontSize"] extends Record<
|
402
|
+
// string,
|
403
|
+
// unknown
|
404
|
+
// >
|
405
|
+
// ? `text-${keyof O["fontSize"] & string}`
|
406
|
+
// : never;
|
407
|
+
// | FontFamily<O>
|
408
|
+
// | FontSize<O>;
|
409
|
+
// export type AnchorNode<O extends RichTextOptions> = never; // TODO:
|
410
|
+
// O["link"] extends true
|
411
|
+
// ? {
|
412
|
+
// tag: "a";
|
413
|
+
// href: string;
|
414
|
+
// children: [string];
|
415
|
+
// }
|
416
|
+
// : never;
|
417
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
418
|
+
// export type BlockQuoteNode<O extends RichTextOptions> =
|
419
|
+
// O["blockQuote"] extends true
|
420
|
+
// ? { tag: "blockquote"; children: [string] }
|
421
|
+
// : never;
|
422
|
+
// TODO: rename to RichTextSelector?
|
423
|
+
function parseTokens(tokens) {
|
424
|
+
return tokens.flatMap(function (token) {
|
425
|
+
if (token.type === "heading") {
|
426
|
+
return [{
|
427
|
+
tag: "h".concat(token.depth),
|
428
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
429
|
+
}];
|
430
|
+
}
|
431
|
+
if (token.type === "paragraph") {
|
432
|
+
return [{
|
433
|
+
tag: "p",
|
434
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
435
|
+
}];
|
436
|
+
}
|
437
|
+
if (token.type === "strong") {
|
438
|
+
return [{
|
439
|
+
tag: "span",
|
440
|
+
classes: ["bold"],
|
441
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
442
|
+
}];
|
443
|
+
}
|
444
|
+
if (token.type === "em") {
|
445
|
+
return [{
|
446
|
+
tag: "span",
|
447
|
+
classes: ["italic"],
|
448
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
449
|
+
}];
|
450
|
+
}
|
451
|
+
if (token.type === "del") {
|
452
|
+
return [{
|
453
|
+
tag: "span",
|
454
|
+
classes: ["line-through"],
|
455
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
456
|
+
}];
|
457
|
+
}
|
458
|
+
if (token.type === "text") {
|
459
|
+
return [token.text];
|
460
|
+
}
|
461
|
+
if (token.type === "list") {
|
462
|
+
return [{
|
463
|
+
tag: token.ordered ? "ol" : "ul",
|
464
|
+
children: parseTokens(token.items)
|
465
|
+
}];
|
466
|
+
}
|
467
|
+
if (token.type === "list_item") {
|
468
|
+
return [{
|
469
|
+
tag: "li",
|
470
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
471
|
+
}];
|
472
|
+
}
|
473
|
+
if (token.type === "space") {
|
474
|
+
return [];
|
475
|
+
}
|
476
|
+
if (token.type === "code") {
|
477
|
+
return [{
|
478
|
+
tag: "span",
|
479
|
+
classes: [],
|
480
|
+
children: [token.text]
|
481
|
+
}];
|
482
|
+
}
|
483
|
+
// console.error(
|
484
|
+
// `Could not parse markdown: unsupported token type: ${token.type}. Found: ${token.raw}`
|
485
|
+
// );
|
486
|
+
return [token.raw];
|
487
|
+
});
|
488
|
+
}
|
489
|
+
|
490
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
491
|
+
function nodeToTag(node) {
|
492
|
+
if (node[index.VAL_EXTENSION] === "file") {
|
493
|
+
return node;
|
494
|
+
}
|
495
|
+
throw Error("Unexpected node: ".concat(JSON.stringify(node)));
|
496
|
+
}
|
497
|
+
function imgSrcToImgTag(imageSrc) {
|
498
|
+
var _imageSrc$metadata, _imageSrc$metadata2;
|
499
|
+
var converted = index.convertFileSource(imageSrc);
|
500
|
+
return {
|
501
|
+
tag: "img",
|
502
|
+
src: converted.url,
|
503
|
+
width: (_imageSrc$metadata = imageSrc.metadata) === null || _imageSrc$metadata === void 0 ? void 0 : _imageSrc$metadata.width,
|
504
|
+
height: (_imageSrc$metadata2 = imageSrc.metadata) === null || _imageSrc$metadata2 === void 0 ? void 0 : _imageSrc$metadata2.height
|
505
|
+
};
|
506
|
+
}
|
507
|
+
function convertRichTextSource(src) {
|
508
|
+
var _ref;
|
509
|
+
return _ref = {}, index._defineProperty(_ref, index.VAL_EXTENSION, "richtext"), index._defineProperty(_ref, "children", src.children.map(function (source) {
|
510
|
+
if (index.VAL_EXTENSION in source && source[index.VAL_EXTENSION] === "file") {
|
511
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
512
|
+
return imgSrcToImgTag(source);
|
513
|
+
}
|
514
|
+
return source;
|
515
|
+
})), _ref;
|
516
|
+
}
|
517
|
+
function richtext(templateStrings) {
|
518
|
+
var _ref2;
|
519
|
+
for (var _len = arguments.length, expr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
520
|
+
expr[_key - 1] = arguments[_key];
|
467
521
|
}
|
468
|
-
return
|
522
|
+
return _ref2 = {}, index._defineProperty(_ref2, index.VAL_EXTENSION, "richtext"), index._defineProperty(_ref2, "children", templateStrings.flatMap(function (templateString, i) {
|
523
|
+
var lex = marked__namespace.lexer(templateString, {
|
524
|
+
gfm: true
|
525
|
+
});
|
526
|
+
if (expr[i]) {
|
527
|
+
return parseTokens(lex).concat(nodeToTag(expr[i]));
|
528
|
+
}
|
529
|
+
return parseTokens(lex);
|
530
|
+
})), _ref2;
|
469
531
|
}
|
470
532
|
|
471
533
|
// import { i18n, I18n } from "./source/future/i18n";
|
@@ -603,6 +665,14 @@ function derefPatch(patch, document, ops$1) {
|
|
603
665
|
} else {
|
604
666
|
dereferencedPatch.push(op);
|
605
667
|
}
|
668
|
+
} else if (op.op === "file") {
|
669
|
+
if (op.path[0] !== "public") {
|
670
|
+
return result.err(new ops.PatchError("Path must start with public"));
|
671
|
+
}
|
672
|
+
if (typeof op.value !== "string") {
|
673
|
+
return result.err(new ops.PatchError("File operation must have a value that is typeof string. Found: ".concat(index._typeof(op.value))));
|
674
|
+
}
|
675
|
+
fileUpdates["/".concat(op.path.join("/"))] = op.value;
|
606
676
|
} else {
|
607
677
|
var _maybeDerefRes = derefPath(op.path);
|
608
678
|
if (result.isErr(_maybeDerefRes)) {
|
@@ -1096,6 +1166,32 @@ function _asyncToGenerator(fn) {
|
|
1096
1166
|
};
|
1097
1167
|
}
|
1098
1168
|
|
1169
|
+
var getSHA256Hash = /*#__PURE__*/function () {
|
1170
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(bits) {
|
1171
|
+
var hashBuffer, hashArray, hash;
|
1172
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
1173
|
+
while (1) switch (_context.prev = _context.next) {
|
1174
|
+
case 0:
|
1175
|
+
_context.next = 2;
|
1176
|
+
return crypto.subtle.digest("SHA-256", bits);
|
1177
|
+
case 2:
|
1178
|
+
hashBuffer = _context.sent;
|
1179
|
+
hashArray = Array.from(new Uint8Array(hashBuffer));
|
1180
|
+
hash = hashArray.map(function (item) {
|
1181
|
+
return item.toString(16).padStart(2, "0");
|
1182
|
+
}).join("");
|
1183
|
+
return _context.abrupt("return", hash);
|
1184
|
+
case 6:
|
1185
|
+
case "end":
|
1186
|
+
return _context.stop();
|
1187
|
+
}
|
1188
|
+
}, _callee);
|
1189
|
+
}));
|
1190
|
+
return function getSHA256Hash(_x) {
|
1191
|
+
return _ref.apply(this, arguments);
|
1192
|
+
};
|
1193
|
+
}();
|
1194
|
+
|
1099
1195
|
// TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
|
1100
1196
|
var ValApi = /*#__PURE__*/function () {
|
1101
1197
|
function ValApi(host) {
|
@@ -1205,6 +1301,7 @@ function _parse() {
|
|
1205
1301
|
|
1206
1302
|
var Internal = {
|
1207
1303
|
convertFileSource: index.convertFileSource,
|
1304
|
+
convertRichTextSource: convertRichTextSource,
|
1208
1305
|
getSchema: index.getSchema,
|
1209
1306
|
getValPath: index.getValPath,
|
1210
1307
|
getVal: getVal,
|
@@ -1213,6 +1310,7 @@ var Internal = {
|
|
1213
1310
|
splitModuleIdAndModulePath: ops.splitModuleIdAndModulePath,
|
1214
1311
|
isVal: index.isVal,
|
1215
1312
|
createValPathOfItem: ops.createValPathOfItem,
|
1313
|
+
getSHA256Hash: getSHA256Hash,
|
1216
1314
|
createPatchJSONPath: function createPatchJSONPath(modulePath) {
|
1217
1315
|
return "/".concat(modulePath.split(".").map(function (segment) {
|
1218
1316
|
return JSON.parse(segment);
|