@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,7 +1,8 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, d as _defineProperty, e as _typeof, S as Schema, i as image, V as VAL_EXTENSION, f as
|
2
|
-
export { F as FILE_REF_PROP,
|
3
|
-
import { a as array, o as object, u as union, r as richtext$1, c as content, P as PatchError, n as newSelectorProxy,
|
4
|
-
|
1
|
+
import { _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, d as _defineProperty, e as _typeof, S as Schema, G as GetSchema, g as getValPath, i as image, V as VAL_EXTENSION, f as convertFileSource, h as file, j as _objectSpread2, k as _slicedToArray, l as isFile, F as FILE_REF_PROP, P as Path, m as GetSource, n as isSerializedVal, o as getSchema, p as isVal } from './index-bccf1907.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, q as GenericSelector, S as Schema, V as VAL_EXTENSION } from './index-bccf1907.esm.js';
|
3
|
+
import { a as array, o as object, u as union, r as richtext$1, b as record, c as content, P as PatchError, n as newSelectorProxy, d as createValPathOfItem, i as isSelector, g as getSource, e as resolvePath, s as splitModuleIdAndModulePath } from './ops-7ef32b0a.esm.js';
|
4
|
+
import * as marked from 'marked';
|
5
|
+
export { i as expr } from './index-5d1ab97c.esm.js';
|
5
6
|
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok, r as result } from './result-b96df128.esm.js';
|
6
7
|
|
7
8
|
var NumberSchema = /*#__PURE__*/function (_Schema) {
|
@@ -65,10 +66,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
65
66
|
function StringSchema(options) {
|
66
67
|
var _this;
|
67
68
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
69
|
+
var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
68
70
|
_classCallCheck(this, StringSchema);
|
69
71
|
_this = _super.call(this);
|
70
72
|
_this.options = options;
|
71
73
|
_this.opt = opt;
|
74
|
+
_this.isRaw = isRaw;
|
72
75
|
return _this;
|
73
76
|
}
|
74
77
|
_createClass(StringSchema, [{
|
@@ -96,7 +99,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
96
99
|
}, {
|
97
100
|
key: "optional",
|
98
101
|
value: function optional() {
|
99
|
-
return new StringSchema(this.options, true);
|
102
|
+
return new StringSchema(this.options, true, this.isRaw);
|
103
|
+
}
|
104
|
+
}, {
|
105
|
+
key: "raw",
|
106
|
+
value: function raw() {
|
107
|
+
return new StringSchema(this.options, this.opt, true);
|
100
108
|
}
|
101
109
|
}, {
|
102
110
|
key: "serialize",
|
@@ -104,7 +112,8 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
104
112
|
return {
|
105
113
|
type: "string",
|
106
114
|
options: this.options,
|
107
|
-
opt: this.opt
|
115
|
+
opt: this.opt,
|
116
|
+
raw: this.isRaw
|
108
117
|
};
|
109
118
|
}
|
110
119
|
}]);
|
@@ -228,6 +237,115 @@ var literal = function literal(value) {
|
|
228
237
|
return new LiteralSchema(value);
|
229
238
|
};
|
230
239
|
|
240
|
+
var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
241
|
+
_inherits(KeyOfSchema, _Schema);
|
242
|
+
var _super = _createSuper(KeyOfSchema);
|
243
|
+
function KeyOfSchema(selector) {
|
244
|
+
var _this;
|
245
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
246
|
+
_classCallCheck(this, KeyOfSchema);
|
247
|
+
_this = _super.call(this);
|
248
|
+
_this.selector = selector;
|
249
|
+
_this.opt = opt;
|
250
|
+
return _this;
|
251
|
+
}
|
252
|
+
_createClass(KeyOfSchema, [{
|
253
|
+
key: "validate",
|
254
|
+
value: function validate(path, src) {
|
255
|
+
if (this.opt && (src === null || src === undefined)) {
|
256
|
+
return false;
|
257
|
+
}
|
258
|
+
var schema = this.selector[GetSchema];
|
259
|
+
if (!schema) {
|
260
|
+
return _defineProperty({}, path, [{
|
261
|
+
message: "Schema not found for module. keyOf must be used with a Val Module"
|
262
|
+
}]);
|
263
|
+
}
|
264
|
+
var serializedSchema = schema.serialize();
|
265
|
+
if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
266
|
+
return _defineProperty({}, path, [{
|
267
|
+
message: "Schema in keyOf must be an 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
|
268
|
+
}]);
|
269
|
+
}
|
270
|
+
if (serializedSchema.opt && (src === null || src === undefined)) {
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
if (serializedSchema.type === "array" && typeof src !== "number") {
|
274
|
+
return _defineProperty({}, path, [{
|
275
|
+
message: "Type of value in keyof (array) must be 'number'"
|
276
|
+
}]);
|
277
|
+
}
|
278
|
+
if (serializedSchema.type === "record" && typeof src !== "string") {
|
279
|
+
return _defineProperty({}, path, [{
|
280
|
+
message: "Type of value in keyof (record) must be 'string'"
|
281
|
+
}]);
|
282
|
+
}
|
283
|
+
if (serializedSchema.type === "object") {
|
284
|
+
var keys = Object.keys(serializedSchema.items);
|
285
|
+
if (!keys.includes(src)) {
|
286
|
+
return _defineProperty({}, path, [{
|
287
|
+
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
|
288
|
+
}]);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
return false;
|
292
|
+
}
|
293
|
+
}, {
|
294
|
+
key: "assert",
|
295
|
+
value: function assert(src) {
|
296
|
+
if (this.opt && (src === null || src === undefined)) {
|
297
|
+
return true;
|
298
|
+
}
|
299
|
+
var schema = this.selector[GetSchema];
|
300
|
+
if (!schema) {
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
var serializedSchema = schema.serialize();
|
304
|
+
if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
305
|
+
return false;
|
306
|
+
}
|
307
|
+
if (serializedSchema.opt && (src === null || src === undefined)) {
|
308
|
+
return true;
|
309
|
+
}
|
310
|
+
if (serializedSchema.type === "array" && typeof src !== "number") {
|
311
|
+
return false;
|
312
|
+
}
|
313
|
+
if (serializedSchema.type === "record" && typeof src !== "string") {
|
314
|
+
return false;
|
315
|
+
}
|
316
|
+
if (serializedSchema.type === "object") {
|
317
|
+
var keys = Object.keys(serializedSchema.items);
|
318
|
+
if (!keys.includes(src)) {
|
319
|
+
return false;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
return true;
|
323
|
+
}
|
324
|
+
}, {
|
325
|
+
key: "optional",
|
326
|
+
value: function optional() {
|
327
|
+
return new KeyOfSchema(this.selector, true);
|
328
|
+
}
|
329
|
+
}, {
|
330
|
+
key: "serialize",
|
331
|
+
value: function serialize() {
|
332
|
+
var path = getValPath(this.selector);
|
333
|
+
if (!path) {
|
334
|
+
throw new Error("Cannot serialize oneOf schema with empty selector. keyOf must be used with a Val Module.");
|
335
|
+
}
|
336
|
+
return {
|
337
|
+
type: "keyOf",
|
338
|
+
selector: path,
|
339
|
+
opt: this.opt
|
340
|
+
};
|
341
|
+
}
|
342
|
+
}]);
|
343
|
+
return KeyOfSchema;
|
344
|
+
}(Schema);
|
345
|
+
var keyOf = function keyOf(valModule) {
|
346
|
+
return new KeyOfSchema(valModule);
|
347
|
+
};
|
348
|
+
|
231
349
|
// import type { F } from "ts-toolbelt";
|
232
350
|
// import { i18n, I18n } from "./schema/future/i18n";
|
233
351
|
// import { oneOf } from "./schema/future/oneOf";
|
@@ -246,23 +364,145 @@ function initSchema() {
|
|
246
364
|
// oneOf,
|
247
365
|
richtext: richtext$1,
|
248
366
|
image: image,
|
249
|
-
literal: literal
|
367
|
+
literal: literal,
|
368
|
+
keyOf: keyOf,
|
369
|
+
record: record
|
250
370
|
// i18n: i18n(locales),
|
251
371
|
};
|
252
372
|
}
|
253
373
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
374
|
+
// export type FontFamily<O extends RichTextOptions> =
|
375
|
+
// O["fontFamily"] extends Record<string, unknown>
|
376
|
+
// ? `font-${keyof O["fontFamily"] & string}`
|
377
|
+
// : never;
|
378
|
+
// export type FontSize<O extends RichTextOptions> = O["fontSize"] extends Record<
|
379
|
+
// string,
|
380
|
+
// unknown
|
381
|
+
// >
|
382
|
+
// ? `text-${keyof O["fontSize"] & string}`
|
383
|
+
// : never;
|
384
|
+
// | FontFamily<O>
|
385
|
+
// | FontSize<O>;
|
386
|
+
// export type AnchorNode<O extends RichTextOptions> = never; // TODO:
|
387
|
+
// O["link"] extends true
|
388
|
+
// ? {
|
389
|
+
// tag: "a";
|
390
|
+
// href: string;
|
391
|
+
// children: [string];
|
392
|
+
// }
|
393
|
+
// : never;
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
395
|
+
// export type BlockQuoteNode<O extends RichTextOptions> =
|
396
|
+
// O["blockQuote"] extends true
|
397
|
+
// ? { tag: "blockquote"; children: [string] }
|
398
|
+
// : never;
|
399
|
+
// TODO: rename to RichTextSelector?
|
400
|
+
function parseTokens(tokens) {
|
401
|
+
return tokens.flatMap(function (token) {
|
402
|
+
if (token.type === "heading") {
|
403
|
+
return [{
|
404
|
+
tag: "h".concat(token.depth),
|
405
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
406
|
+
}];
|
407
|
+
}
|
408
|
+
if (token.type === "paragraph") {
|
409
|
+
return [{
|
410
|
+
tag: "p",
|
411
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
412
|
+
}];
|
413
|
+
}
|
414
|
+
if (token.type === "strong") {
|
415
|
+
return [{
|
416
|
+
tag: "span",
|
417
|
+
classes: ["bold"],
|
418
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
419
|
+
}];
|
420
|
+
}
|
421
|
+
if (token.type === "em") {
|
422
|
+
return [{
|
423
|
+
tag: "span",
|
424
|
+
classes: ["italic"],
|
425
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
426
|
+
}];
|
427
|
+
}
|
428
|
+
if (token.type === "del") {
|
429
|
+
return [{
|
430
|
+
tag: "span",
|
431
|
+
classes: ["line-through"],
|
432
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
433
|
+
}];
|
434
|
+
}
|
435
|
+
if (token.type === "text") {
|
436
|
+
return [token.text];
|
437
|
+
}
|
438
|
+
if (token.type === "list") {
|
439
|
+
return [{
|
440
|
+
tag: token.ordered ? "ol" : "ul",
|
441
|
+
children: parseTokens(token.items)
|
442
|
+
}];
|
443
|
+
}
|
444
|
+
if (token.type === "list_item") {
|
445
|
+
return [{
|
446
|
+
tag: "li",
|
447
|
+
children: parseTokens(token.tokens ? token.tokens : [])
|
448
|
+
}];
|
449
|
+
}
|
450
|
+
if (token.type === "space") {
|
451
|
+
return [];
|
452
|
+
}
|
453
|
+
if (token.type === "code") {
|
454
|
+
return [{
|
455
|
+
tag: "span",
|
456
|
+
classes: [],
|
457
|
+
children: [token.text]
|
458
|
+
}];
|
459
|
+
}
|
460
|
+
console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
|
461
|
+
return [token.raw];
|
462
|
+
});
|
463
|
+
}
|
464
|
+
|
465
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
466
|
+
function nodeToTag(node) {
|
467
|
+
if (node[VAL_EXTENSION] === "file") {
|
468
|
+
return node;
|
264
469
|
}
|
265
|
-
|
470
|
+
throw Error("Unexpected node: ".concat(JSON.stringify(node)));
|
471
|
+
}
|
472
|
+
function imgSrcToImgTag(imageSrc) {
|
473
|
+
var _imageSrc$metadata, _imageSrc$metadata2;
|
474
|
+
var converted = convertFileSource(imageSrc);
|
475
|
+
return {
|
476
|
+
tag: "img",
|
477
|
+
src: converted.url,
|
478
|
+
width: (_imageSrc$metadata = imageSrc.metadata) === null || _imageSrc$metadata === void 0 ? void 0 : _imageSrc$metadata.width,
|
479
|
+
height: (_imageSrc$metadata2 = imageSrc.metadata) === null || _imageSrc$metadata2 === void 0 ? void 0 : _imageSrc$metadata2.height
|
480
|
+
};
|
481
|
+
}
|
482
|
+
function convertRichTextSource(src) {
|
483
|
+
var _ref;
|
484
|
+
return _ref = {}, _defineProperty(_ref, VAL_EXTENSION, "richtext"), _defineProperty(_ref, "children", src.children.map(function (source) {
|
485
|
+
if (VAL_EXTENSION in source && source[VAL_EXTENSION] === "file") {
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
487
|
+
return imgSrcToImgTag(source);
|
488
|
+
}
|
489
|
+
return source;
|
490
|
+
})), _ref;
|
491
|
+
}
|
492
|
+
function richtext(templateStrings) {
|
493
|
+
var _ref2;
|
494
|
+
for (var _len = arguments.length, expr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
495
|
+
expr[_key - 1] = arguments[_key];
|
496
|
+
}
|
497
|
+
return _ref2 = {}, _defineProperty(_ref2, VAL_EXTENSION, "richtext"), _defineProperty(_ref2, "children", templateStrings.flatMap(function (templateString, i) {
|
498
|
+
var lex = marked.lexer(templateString, {
|
499
|
+
gfm: true
|
500
|
+
});
|
501
|
+
if (expr[i]) {
|
502
|
+
return parseTokens(lex).concat(nodeToTag(expr[i]));
|
503
|
+
}
|
504
|
+
return parseTokens(lex);
|
505
|
+
})), _ref2;
|
266
506
|
}
|
267
507
|
|
268
508
|
// import { i18n, I18n } from "./source/future/i18n";
|
@@ -400,6 +640,14 @@ function derefPatch(patch, document, ops) {
|
|
400
640
|
} else {
|
401
641
|
dereferencedPatch.push(op);
|
402
642
|
}
|
643
|
+
} else if (op.op === "file") {
|
644
|
+
if (op.path[0] !== "public") {
|
645
|
+
return err(new PatchError("Path must start with public"));
|
646
|
+
}
|
647
|
+
if (typeof op.value !== "string") {
|
648
|
+
return err(new PatchError("File operation must have a value that is typeof string. Found: ".concat(_typeof(op.value))));
|
649
|
+
}
|
650
|
+
fileUpdates["/".concat(op.path.join("/"))] = op.value;
|
403
651
|
} else {
|
404
652
|
var _maybeDerefRes = derefPath(op.path);
|
405
653
|
if (isErr(_maybeDerefRes)) {
|
@@ -893,6 +1141,32 @@ function _asyncToGenerator(fn) {
|
|
893
1141
|
};
|
894
1142
|
}
|
895
1143
|
|
1144
|
+
var getSHA256Hash = /*#__PURE__*/function () {
|
1145
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(bits) {
|
1146
|
+
var hashBuffer, hashArray, hash;
|
1147
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
1148
|
+
while (1) switch (_context.prev = _context.next) {
|
1149
|
+
case 0:
|
1150
|
+
_context.next = 2;
|
1151
|
+
return crypto.subtle.digest("SHA-256", bits);
|
1152
|
+
case 2:
|
1153
|
+
hashBuffer = _context.sent;
|
1154
|
+
hashArray = Array.from(new Uint8Array(hashBuffer));
|
1155
|
+
hash = hashArray.map(function (item) {
|
1156
|
+
return item.toString(16).padStart(2, "0");
|
1157
|
+
}).join("");
|
1158
|
+
return _context.abrupt("return", hash);
|
1159
|
+
case 6:
|
1160
|
+
case "end":
|
1161
|
+
return _context.stop();
|
1162
|
+
}
|
1163
|
+
}, _callee);
|
1164
|
+
}));
|
1165
|
+
return function getSHA256Hash(_x) {
|
1166
|
+
return _ref.apply(this, arguments);
|
1167
|
+
};
|
1168
|
+
}();
|
1169
|
+
|
896
1170
|
// TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
|
897
1171
|
var ValApi = /*#__PURE__*/function () {
|
898
1172
|
function ValApi(host) {
|
@@ -1002,6 +1276,7 @@ function _parse() {
|
|
1002
1276
|
|
1003
1277
|
var Internal = {
|
1004
1278
|
convertFileSource: convertFileSource,
|
1279
|
+
convertRichTextSource: convertRichTextSource,
|
1005
1280
|
getSchema: getSchema,
|
1006
1281
|
getValPath: getValPath,
|
1007
1282
|
getVal: getVal,
|
@@ -1010,6 +1285,7 @@ var Internal = {
|
|
1010
1285
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1011
1286
|
isVal: isVal,
|
1012
1287
|
createValPathOfItem: createValPathOfItem,
|
1288
|
+
getSHA256Hash: getSHA256Hash,
|
1013
1289
|
createPatchJSONPath: function createPatchJSONPath(modulePath) {
|
1014
1290
|
return "/".concat(modulePath.split(".").map(function (segment) {
|
1015
1291
|
return JSON.parse(segment);
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export { e as evaluate, p as parse } from '../../dist/index-
|
2
|
-
export { C as Call, E as Expr, N as NilSym,
|
1
|
+
export { e as evaluate, p as parse } from '../../dist/index-5d1ab97c.esm.js';
|
2
|
+
export { C as Call, E as Expr, N as NilSym, s as StringLiteral, t as StringTemplate, r as Sym } from '../../dist/index-bccf1907.esm.js';
|
3
3
|
import '../../dist/result-b96df128.esm.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/core",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.19.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "Val - supercharged hard-coded content",
|
6
6
|
"scripts": {
|
@@ -41,5 +41,8 @@
|
|
41
41
|
},
|
42
42
|
"devDependencies": {
|
43
43
|
"ts-toolbelt": "^9.6.0"
|
44
|
+
},
|
45
|
+
"dependencies": {
|
46
|
+
"marked": "^9.0.3"
|
44
47
|
}
|
45
48
|
}
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var index = require('../../dist/index-a6e642dd.cjs.dev.js');
|
6
6
|
var result = require('../../dist/result-48320acd.cjs.dev.js');
|
7
7
|
var util = require('../../dist/util-b213092b.cjs.dev.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-2d7e1742.cjs.dev.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -350,6 +350,7 @@ function isProperPathPrefix(prefix, path) {
|
|
350
350
|
function parseOperation(operation) {
|
351
351
|
var path = parseJSONPointer(operation.path);
|
352
352
|
switch (operation.op) {
|
353
|
+
case "file":
|
353
354
|
case "add":
|
354
355
|
case "replace":
|
355
356
|
case "test":
|
@@ -431,6 +432,10 @@ function apply(document, ops$1, op) {
|
|
431
432
|
}
|
432
433
|
return result.ok(document);
|
433
434
|
}
|
435
|
+
case "file":
|
436
|
+
{
|
437
|
+
return result.err(new ops.PatchError("Cannot apply a file patch here"));
|
438
|
+
}
|
434
439
|
}
|
435
440
|
}
|
436
441
|
function applyPatch(document, ops, patch) {
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var index = require('../../dist/index-8706c87e.cjs.prod.js');
|
6
6
|
var result = require('../../dist/result-26f67b40.cjs.prod.js');
|
7
7
|
var util = require('../../dist/util-030d8a1f.cjs.prod.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-ae089ab2.cjs.prod.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -350,6 +350,7 @@ function isProperPathPrefix(prefix, path) {
|
|
350
350
|
function parseOperation(operation) {
|
351
351
|
var path = parseJSONPointer(operation.path);
|
352
352
|
switch (operation.op) {
|
353
|
+
case "file":
|
353
354
|
case "add":
|
354
355
|
case "replace":
|
355
356
|
case "test":
|
@@ -431,6 +432,10 @@ function apply(document, ops$1, op) {
|
|
431
432
|
}
|
432
433
|
return result.ok(document);
|
433
434
|
}
|
435
|
+
case "file":
|
436
|
+
{
|
437
|
+
return result.err(new ops.PatchError("Cannot apply a file patch here"));
|
438
|
+
}
|
434
439
|
}
|
435
440
|
}
|
436
441
|
function applyPatch(document, ops, patch) {
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { e as _typeof,
|
1
|
+
import { e as _typeof, k as _slicedToArray, c as _createClass, b as _classCallCheck, u as _toConsumableArray } from '../../dist/index-bccf1907.esm.js';
|
2
2
|
import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-b96df128.esm.js';
|
3
3
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
4
|
-
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-
|
5
|
-
export { P as PatchError } from '../../dist/ops-
|
4
|
+
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-7ef32b0a.esm.js';
|
5
|
+
export { P as PatchError } from '../../dist/ops-7ef32b0a.esm.js';
|
6
6
|
|
7
7
|
function isNotRoot(path) {
|
8
8
|
return isNonEmpty(path);
|
@@ -347,6 +347,7 @@ function isProperPathPrefix(prefix, path) {
|
|
347
347
|
function parseOperation(operation) {
|
348
348
|
var path = parseJSONPointer(operation.path);
|
349
349
|
switch (operation.op) {
|
350
|
+
case "file":
|
350
351
|
case "add":
|
351
352
|
case "replace":
|
352
353
|
case "test":
|
@@ -428,6 +429,10 @@ function apply(document, ops, op) {
|
|
428
429
|
}
|
429
430
|
return ok(document);
|
430
431
|
}
|
432
|
+
case "file":
|
433
|
+
{
|
434
|
+
return err(new PatchError("Cannot apply a file patch here"));
|
435
|
+
}
|
431
436
|
}
|
432
437
|
}
|
433
438
|
function applyPatch(document, ops, patch) {
|
package/src/getSha256.ts
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
export const getSHA256Hash = async (bits: Uint8Array) => {
|
2
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", bits);
|
3
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
4
|
+
const hash = hashArray
|
5
|
+
.map((item) => item.toString(16).padStart(2, "0"))
|
6
|
+
.join("");
|
7
|
+
return hash;
|
8
|
+
};
|
package/src/index.ts
CHANGED
@@ -5,13 +5,25 @@ export type { ValModule, SerializedModule } from "./module";
|
|
5
5
|
export type { SourceObject, SourcePrimitive, Source } from "./source";
|
6
6
|
export type { FileSource } from "./source/file";
|
7
7
|
export type {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
ParagraphNode,
|
8
|
+
AnyRichTextOptions,
|
9
|
+
Bold,
|
10
|
+
Classes,
|
12
11
|
HeadingNode,
|
12
|
+
ImageNode,
|
13
|
+
Italic,
|
14
|
+
LineThrough,
|
13
15
|
ListItemNode,
|
14
|
-
|
16
|
+
OrderedListNode,
|
17
|
+
ParagraphNode,
|
18
|
+
RichText,
|
19
|
+
RichTextNode,
|
20
|
+
RichTextOptions,
|
21
|
+
RichTextSource,
|
22
|
+
RichTextSourceNode,
|
23
|
+
RootNode,
|
24
|
+
SourceNode,
|
25
|
+
SpanNode,
|
26
|
+
UnorderedListNode,
|
15
27
|
} from "./source/richtext";
|
16
28
|
export {
|
17
29
|
type Val,
|
@@ -44,6 +56,8 @@ import { createValPathOfItem } from "./selector/SelectorProxy";
|
|
44
56
|
import { getVal } from "./future/fetchVal";
|
45
57
|
import { Json } from "./Json";
|
46
58
|
import { SerializedSchema } from "./schema";
|
59
|
+
import { convertRichTextSource } from "./source/richtext";
|
60
|
+
import { getSHA256Hash } from "./getSha256";
|
47
61
|
export { ValApi } from "./ValApi";
|
48
62
|
|
49
63
|
export type ApiTreeResponse = {
|
@@ -68,6 +82,7 @@ export type ApiPatchResponse = Record<ModuleId, string[]>;
|
|
68
82
|
|
69
83
|
const Internal = {
|
70
84
|
convertFileSource,
|
85
|
+
convertRichTextSource,
|
71
86
|
getSchema,
|
72
87
|
getValPath,
|
73
88
|
getVal,
|
@@ -76,6 +91,7 @@ const Internal = {
|
|
76
91
|
splitModuleIdAndModulePath,
|
77
92
|
isVal,
|
78
93
|
createValPathOfItem,
|
94
|
+
getSHA256Hash,
|
79
95
|
createPatchJSONPath: (modulePath: ModulePath) =>
|
80
96
|
`/${modulePath
|
81
97
|
.split(".")
|
package/src/initSchema.ts
CHANGED
@@ -8,6 +8,8 @@ import { union } from "./schema/union";
|
|
8
8
|
import { richtext } from "./schema/richtext";
|
9
9
|
import { image } from "./schema/image";
|
10
10
|
import { literal } from "./schema/literal";
|
11
|
+
import { keyOf } from "./schema/keyOf";
|
12
|
+
import { record } from "./schema/record";
|
11
13
|
// import { i18n, I18n } from "./schema/future/i18n";
|
12
14
|
// import { oneOf } from "./schema/future/oneOf";
|
13
15
|
|
@@ -22,6 +24,8 @@ export type InitSchema = {
|
|
22
24
|
readonly richtext: typeof richtext;
|
23
25
|
readonly image: typeof image;
|
24
26
|
readonly literal: typeof literal;
|
27
|
+
readonly keyOf: typeof keyOf;
|
28
|
+
readonly record: typeof record;
|
25
29
|
};
|
26
30
|
// export type InitSchemaLocalized<Locales extends readonly string[]> = {
|
27
31
|
// readonly i18n: I18n<Locales>;
|
@@ -39,6 +43,8 @@ export function initSchema() {
|
|
39
43
|
richtext,
|
40
44
|
image,
|
41
45
|
literal,
|
46
|
+
keyOf,
|
47
|
+
record,
|
42
48
|
// i18n: i18n(locales),
|
43
49
|
};
|
44
50
|
}
|
package/src/module.ts
CHANGED
@@ -21,7 +21,8 @@ import {
|
|
21
21
|
SerializedImageSchema,
|
22
22
|
} from "./schema/image";
|
23
23
|
import { FileSource } from "./source/file";
|
24
|
-
import { RichText } from "./source/richtext";
|
24
|
+
import { AnyRichTextOptions, RichText } from "./source/richtext";
|
25
|
+
import { RecordSchema, SerializedRecordSchema } from "./schema/record";
|
25
26
|
|
26
27
|
const brand = Symbol("ValModule");
|
27
28
|
export type ValModule<T extends SelectorSource> = SelectorOf<T> &
|
@@ -94,6 +95,15 @@ function isObjectSchema(
|
|
94
95
|
);
|
95
96
|
}
|
96
97
|
|
98
|
+
function isRecordSchema(
|
99
|
+
schema: Schema<SelectorSource> | SerializedSchema
|
100
|
+
): schema is RecordSchema<Schema<SelectorSource>> | SerializedRecordSchema {
|
101
|
+
return (
|
102
|
+
schema instanceof RecordSchema ||
|
103
|
+
(typeof schema === "object" && "type" in schema && schema.type === "record")
|
104
|
+
);
|
105
|
+
}
|
106
|
+
|
97
107
|
function isArraySchema(
|
98
108
|
schema: Schema<SelectorSource> | SerializedSchema
|
99
109
|
): schema is ArraySchema<Schema<SelectorSource>> | SerializedArraySchema {
|
@@ -126,7 +136,7 @@ function isUnionSchema(
|
|
126
136
|
function isRichTextSchema(
|
127
137
|
schema: Schema<SelectorSource> | SerializedSchema
|
128
138
|
): schema is
|
129
|
-
| Schema<RichText
|
139
|
+
| Schema<RichText<AnyRichTextOptions>> // TODO: RichTextSchema
|
130
140
|
| SerializedRichTextSchema {
|
131
141
|
return (
|
132
142
|
schema instanceof RichTextSchema ||
|
@@ -192,6 +202,27 @@ export function resolvePath(
|
|
192
202
|
}
|
193
203
|
resolvedSource = resolvedSource[part];
|
194
204
|
resolvedSchema = resolvedSchema.item;
|
205
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
206
|
+
if (typeof part !== "string") {
|
207
|
+
throw Error(
|
208
|
+
`Invalid path: record schema ${resolvedSchema} must have path: ${part} as string`
|
209
|
+
);
|
210
|
+
}
|
211
|
+
if (
|
212
|
+
typeof resolvedSource !== "object" &&
|
213
|
+
!Array.isArray(resolvedSource)
|
214
|
+
) {
|
215
|
+
throw Error(
|
216
|
+
`Schema type error: expected source to be type of record, but got ${typeof resolvedSource}`
|
217
|
+
);
|
218
|
+
}
|
219
|
+
if (!resolvedSource[part]) {
|
220
|
+
throw Error(
|
221
|
+
`Invalid path: record source did not have key ${part} from path: ${path}`
|
222
|
+
);
|
223
|
+
}
|
224
|
+
resolvedSource = resolvedSource[part];
|
225
|
+
resolvedSchema = resolvedSchema.item;
|
195
226
|
} else if (isObjectSchema(resolvedSchema)) {
|
196
227
|
if (typeof resolvedSource !== "object") {
|
197
228
|
throw Error(
|