@valbuild/core 0.16.0 → 0.17.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/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +36 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-369caccf.esm.js} +23 -195
- package/dist/{index-af761363.esm.js → index-3e3e839e.esm.js} +189 -1
- package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-23a5abb2.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +585 -198
- package/dist/valbuild-core.cjs.prod.js +585 -198
- package/dist/valbuild-core.esm.js +520 -134
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +46 -14
- package/src/initSchema.ts +11 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -1,74 +1,8 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass,
|
2
|
-
export { F as FILE_REF_PROP,
|
3
|
-
import { a as array, o as object, u as union, r as richtext$1,
|
4
|
-
export { i as expr } from './index-
|
5
|
-
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok } from './result-b96df128.esm.js';
|
6
|
-
|
7
|
-
var OneOfSchema = /*#__PURE__*/function (_Schema) {
|
8
|
-
_inherits(OneOfSchema, _Schema);
|
9
|
-
var _super = _createSuper(OneOfSchema);
|
10
|
-
function OneOfSchema(selector) {
|
11
|
-
var _this;
|
12
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
13
|
-
_classCallCheck(this, OneOfSchema);
|
14
|
-
_this = _super.call(this);
|
15
|
-
_this.selector = selector;
|
16
|
-
_this.opt = opt;
|
17
|
-
return _this;
|
18
|
-
}
|
19
|
-
_createClass(OneOfSchema, [{
|
20
|
-
key: "validate",
|
21
|
-
value: function validate(path, src) {
|
22
|
-
throw new Error("Method not implemented.");
|
23
|
-
}
|
24
|
-
}, {
|
25
|
-
key: "assert",
|
26
|
-
value: function assert(src) {
|
27
|
-
throw new Error("Method not implemented.");
|
28
|
-
}
|
29
|
-
}, {
|
30
|
-
key: "optional",
|
31
|
-
value: function optional() {
|
32
|
-
return new OneOfSchema(this.selector, true);
|
33
|
-
}
|
34
|
-
}, {
|
35
|
-
key: "serialize",
|
36
|
-
value: function serialize() {
|
37
|
-
var path = getValPath(this.selector);
|
38
|
-
if (!path) {
|
39
|
-
throw new Error("Cannot serialize oneOf schema with empty selector. Make sure a Val module is used.");
|
40
|
-
}
|
41
|
-
return {
|
42
|
-
type: "oneOf",
|
43
|
-
selector: path,
|
44
|
-
opt: this.opt
|
45
|
-
};
|
46
|
-
}
|
47
|
-
}]);
|
48
|
-
return OneOfSchema;
|
49
|
-
}(Schema);
|
50
|
-
var oneOf = function oneOf(valModule) {
|
51
|
-
return new OneOfSchema(valModule);
|
52
|
-
};
|
53
|
-
|
54
|
-
/**
|
55
|
-
* I18n sources cannot have nested remote sources.
|
56
|
-
*/
|
57
|
-
|
58
|
-
/**
|
59
|
-
* An i18n source is a map of locales to sources.
|
60
|
-
*
|
61
|
-
* Its selector will default to the underlying source. It is possible to call `.all` on i18n sources, which returns an object with all the locales
|
62
|
-
*
|
63
|
-
*/
|
64
|
-
|
65
|
-
function i18n(
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
67
|
-
locales) {
|
68
|
-
return function (source) {
|
69
|
-
return _objectSpread2(_objectSpread2({}, source), {}, _defineProperty({}, VAL_EXTENSION, "i18n"));
|
70
|
-
};
|
71
|
-
}
|
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 _objectSpread2, g as getValPath, h as file, j as _slicedToArray, k as isFile, F as FILE_REF_PROP, P as Path, G as GetSource, l as isSerializedVal, m as convertFileSource, n as getSchema, o as isVal } from './index-369caccf.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, p as GenericSelector, S as Schema, V as VAL_EXTENSION } from './index-369caccf.esm.js';
|
3
|
+
import { a as array, o as object, u as union, r as richtext$1, c as content, P as PatchError, n as newSelectorProxy, b as createValPathOfItem, i as isSelector, g as getSource, d as resolvePath, s as splitModuleIdAndModulePath } from './ops-23a5abb2.esm.js';
|
4
|
+
export { i as expr } from './index-3e3e839e.esm.js';
|
5
|
+
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok, r as result } from './result-b96df128.esm.js';
|
72
6
|
|
73
7
|
var NumberSchema = /*#__PURE__*/function (_Schema) {
|
74
8
|
_inherits(NumberSchema, _Schema);
|
@@ -294,7 +228,14 @@ var literal = function literal(value) {
|
|
294
228
|
return new LiteralSchema(value);
|
295
229
|
};
|
296
230
|
|
297
|
-
|
231
|
+
// import type { F } from "ts-toolbelt";
|
232
|
+
// import { i18n, I18n } from "./schema/future/i18n";
|
233
|
+
// import { oneOf } from "./schema/future/oneOf";
|
234
|
+
// export type InitSchemaLocalized<Locales extends readonly string[]> = {
|
235
|
+
// readonly i18n: I18n<Locales>;
|
236
|
+
// };
|
237
|
+
function initSchema() {
|
238
|
+
// locales: F.Narrow<Locales>
|
298
239
|
return {
|
299
240
|
string: string,
|
300
241
|
"boolean": _boolean,
|
@@ -302,34 +243,14 @@ function initSchema(locales) {
|
|
302
243
|
object: object,
|
303
244
|
number: number,
|
304
245
|
union: union,
|
305
|
-
|
246
|
+
// oneOf,
|
306
247
|
richtext: richtext$1,
|
307
248
|
image: image,
|
308
|
-
literal: literal
|
309
|
-
i18n: i18n
|
249
|
+
literal: literal
|
250
|
+
// i18n: i18n(locales),
|
310
251
|
};
|
311
252
|
}
|
312
253
|
|
313
|
-
/**
|
314
|
-
* Remote sources cannot include other remote sources.
|
315
|
-
*/
|
316
|
-
|
317
|
-
var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
|
318
|
-
|
319
|
-
/**
|
320
|
-
* A remote source is a hash that represents a remote object.
|
321
|
-
*
|
322
|
-
* It will be resolved into a ValRemote object.
|
323
|
-
*/
|
324
|
-
|
325
|
-
function remote(ref) {
|
326
|
-
var _ref;
|
327
|
-
return _ref = {}, _defineProperty(_ref, REMOTE_REF_PROP, ref), _defineProperty(_ref, VAL_EXTENSION, "remote"), _ref;
|
328
|
-
}
|
329
|
-
function isRemote(obj) {
|
330
|
-
return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "remote" && REMOTE_REF_PROP in obj && typeof obj[REMOTE_REF_PROP] === "string";
|
331
|
-
}
|
332
|
-
|
333
254
|
function richtext(data) {
|
334
255
|
if (typeof data === "string") {
|
335
256
|
var _ref;
|
@@ -344,40 +265,55 @@ function richtext(data) {
|
|
344
265
|
return _objectSpread2(_objectSpread2({}, data), {}, _defineProperty({}, VAL_EXTENSION, "richtext"));
|
345
266
|
}
|
346
267
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
268
|
+
// import { i18n, I18n } from "./source/future/i18n";
|
269
|
+
// import { remote } from "./source/future/remote";
|
270
|
+
// type NarrowStrings<A> =
|
271
|
+
// | (A extends [] ? [] : never)
|
272
|
+
// | (A extends string ? A : never)
|
273
|
+
// | {
|
274
|
+
// [K in keyof A]: NarrowStrings<A[K]>;
|
275
|
+
// };
|
276
|
+
// TODO: Rename to createValSystem (only to be used by internal things), we can then export * from '@valbuild/core' in the next package then.
|
277
|
+
var initVal = function initVal() {
|
278
|
+
// const locales = options?.locales;
|
279
|
+
var s = initSchema();
|
280
|
+
// if (locales?.required) {
|
281
|
+
// console.error("Locales / i18n currently not implemented");
|
282
|
+
// return {
|
283
|
+
// val: {
|
284
|
+
// content,
|
285
|
+
// i18n,
|
286
|
+
// remote,
|
287
|
+
// getPath,
|
288
|
+
// file,
|
289
|
+
// richtext,
|
290
|
+
// },
|
291
|
+
// s,
|
292
|
+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
293
|
+
// } as any;
|
294
|
+
// }
|
366
295
|
return {
|
367
296
|
val: {
|
368
297
|
content: content,
|
369
|
-
|
298
|
+
// remote,
|
370
299
|
getPath: getValPath,
|
371
300
|
file: file,
|
372
301
|
richtext: richtext
|
373
302
|
},
|
374
|
-
s: _objectSpread2(
|
375
|
-
i18n: undefined
|
376
|
-
})
|
303
|
+
s: _objectSpread2({}, s)
|
377
304
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
378
305
|
};
|
379
306
|
};
|
380
307
|
|
308
|
+
/**
|
309
|
+
* Remote sources cannot include other remote sources.
|
310
|
+
*/
|
311
|
+
|
312
|
+
var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
|
313
|
+
function isRemote(obj) {
|
314
|
+
return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "remote" && REMOTE_REF_PROP in obj && typeof obj[REMOTE_REF_PROP] === "string";
|
315
|
+
}
|
316
|
+
|
381
317
|
function derefPath(path) {
|
382
318
|
var dereffedPath = [];
|
383
319
|
var referencedPath = null;
|
@@ -489,19 +425,14 @@ function derefPatch(patch, document, ops) {
|
|
489
425
|
});
|
490
426
|
}
|
491
427
|
|
492
|
-
function
|
493
|
-
return Promise.resolve(getVal(selector));
|
494
|
-
}
|
495
|
-
function getVal(selector,
|
496
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
497
|
-
locale) {
|
428
|
+
function getVal(selector) {
|
498
429
|
return newValProxy(serializedValOfSelectorSource(selector));
|
499
430
|
}
|
500
431
|
|
501
432
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
502
433
|
function isArrayOrArraySelector(child) {
|
503
434
|
if (isSelector(child)) {
|
504
|
-
return _typeof(child[
|
435
|
+
return _typeof(child[GetSource]) === "object" && _typeof(child[GetSource]) !== null && Array.isArray(child[GetSource]);
|
505
436
|
}
|
506
437
|
return Array.isArray(child);
|
507
438
|
}
|
@@ -509,7 +440,7 @@ function isArrayOrArraySelector(child) {
|
|
509
440
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
510
441
|
function isObjectOrObjectSelector(child) {
|
511
442
|
if (isSelector(child)) {
|
512
|
-
return _typeof(child[
|
443
|
+
return _typeof(child[GetSource]) === "object" && _typeof(child[GetSource]) !== null && !Array.isArray(child[GetSource]);
|
513
444
|
}
|
514
445
|
return _typeof(child) === "object";
|
515
446
|
}
|
@@ -520,7 +451,7 @@ function serializedValOfSelectorSource(selector) {
|
|
520
451
|
var isArray = isArrayOrArraySelector(child);
|
521
452
|
var isObject = isObjectOrObjectSelector(child);
|
522
453
|
if (isArray) {
|
523
|
-
var array =
|
454
|
+
var array = GetSource in child ? child[GetSource] : child;
|
524
455
|
var valPath = Path in child ? child[Path] : undefined;
|
525
456
|
return {
|
526
457
|
val: array.map(function (item, i) {
|
@@ -530,7 +461,7 @@ function serializedValOfSelectorSource(selector) {
|
|
530
461
|
valPath: valPath
|
531
462
|
};
|
532
463
|
} else if (isObject) {
|
533
|
-
var obj =
|
464
|
+
var obj = GetSource in child ? child[GetSource] : child;
|
534
465
|
var _valPath = Path in child ? child[Path] : undefined;
|
535
466
|
return {
|
536
467
|
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
@@ -544,7 +475,7 @@ function serializedValOfSelectorSource(selector) {
|
|
544
475
|
};
|
545
476
|
} else if (isSelector(child)) {
|
546
477
|
return {
|
547
|
-
val: rec(child[
|
478
|
+
val: rec(child[GetSource]),
|
548
479
|
valPath: child[Path]
|
549
480
|
};
|
550
481
|
} else {
|
@@ -629,16 +560,471 @@ function hasOwn(obj, prop) {
|
|
629
560
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
630
561
|
}
|
631
562
|
|
563
|
+
function _regeneratorRuntime() {
|
564
|
+
_regeneratorRuntime = function () {
|
565
|
+
return exports;
|
566
|
+
};
|
567
|
+
var exports = {},
|
568
|
+
Op = Object.prototype,
|
569
|
+
hasOwn = Op.hasOwnProperty,
|
570
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
571
|
+
obj[key] = desc.value;
|
572
|
+
},
|
573
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
574
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
575
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
576
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
577
|
+
function define(obj, key, value) {
|
578
|
+
return Object.defineProperty(obj, key, {
|
579
|
+
value: value,
|
580
|
+
enumerable: !0,
|
581
|
+
configurable: !0,
|
582
|
+
writable: !0
|
583
|
+
}), obj[key];
|
584
|
+
}
|
585
|
+
try {
|
586
|
+
define({}, "");
|
587
|
+
} catch (err) {
|
588
|
+
define = function (obj, key, value) {
|
589
|
+
return obj[key] = value;
|
590
|
+
};
|
591
|
+
}
|
592
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
593
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
594
|
+
generator = Object.create(protoGenerator.prototype),
|
595
|
+
context = new Context(tryLocsList || []);
|
596
|
+
return defineProperty(generator, "_invoke", {
|
597
|
+
value: makeInvokeMethod(innerFn, self, context)
|
598
|
+
}), generator;
|
599
|
+
}
|
600
|
+
function tryCatch(fn, obj, arg) {
|
601
|
+
try {
|
602
|
+
return {
|
603
|
+
type: "normal",
|
604
|
+
arg: fn.call(obj, arg)
|
605
|
+
};
|
606
|
+
} catch (err) {
|
607
|
+
return {
|
608
|
+
type: "throw",
|
609
|
+
arg: err
|
610
|
+
};
|
611
|
+
}
|
612
|
+
}
|
613
|
+
exports.wrap = wrap;
|
614
|
+
var ContinueSentinel = {};
|
615
|
+
function Generator() {}
|
616
|
+
function GeneratorFunction() {}
|
617
|
+
function GeneratorFunctionPrototype() {}
|
618
|
+
var IteratorPrototype = {};
|
619
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
620
|
+
return this;
|
621
|
+
});
|
622
|
+
var getProto = Object.getPrototypeOf,
|
623
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
624
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
625
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
626
|
+
function defineIteratorMethods(prototype) {
|
627
|
+
["next", "throw", "return"].forEach(function (method) {
|
628
|
+
define(prototype, method, function (arg) {
|
629
|
+
return this._invoke(method, arg);
|
630
|
+
});
|
631
|
+
});
|
632
|
+
}
|
633
|
+
function AsyncIterator(generator, PromiseImpl) {
|
634
|
+
function invoke(method, arg, resolve, reject) {
|
635
|
+
var record = tryCatch(generator[method], generator, arg);
|
636
|
+
if ("throw" !== record.type) {
|
637
|
+
var result = record.arg,
|
638
|
+
value = result.value;
|
639
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
640
|
+
invoke("next", value, resolve, reject);
|
641
|
+
}, function (err) {
|
642
|
+
invoke("throw", err, resolve, reject);
|
643
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
644
|
+
result.value = unwrapped, resolve(result);
|
645
|
+
}, function (error) {
|
646
|
+
return invoke("throw", error, resolve, reject);
|
647
|
+
});
|
648
|
+
}
|
649
|
+
reject(record.arg);
|
650
|
+
}
|
651
|
+
var previousPromise;
|
652
|
+
defineProperty(this, "_invoke", {
|
653
|
+
value: function (method, arg) {
|
654
|
+
function callInvokeWithMethodAndArg() {
|
655
|
+
return new PromiseImpl(function (resolve, reject) {
|
656
|
+
invoke(method, arg, resolve, reject);
|
657
|
+
});
|
658
|
+
}
|
659
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
660
|
+
}
|
661
|
+
});
|
662
|
+
}
|
663
|
+
function makeInvokeMethod(innerFn, self, context) {
|
664
|
+
var state = "suspendedStart";
|
665
|
+
return function (method, arg) {
|
666
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
667
|
+
if ("completed" === state) {
|
668
|
+
if ("throw" === method) throw arg;
|
669
|
+
return doneResult();
|
670
|
+
}
|
671
|
+
for (context.method = method, context.arg = arg;;) {
|
672
|
+
var delegate = context.delegate;
|
673
|
+
if (delegate) {
|
674
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
675
|
+
if (delegateResult) {
|
676
|
+
if (delegateResult === ContinueSentinel) continue;
|
677
|
+
return delegateResult;
|
678
|
+
}
|
679
|
+
}
|
680
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
681
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
682
|
+
context.dispatchException(context.arg);
|
683
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
684
|
+
state = "executing";
|
685
|
+
var record = tryCatch(innerFn, self, context);
|
686
|
+
if ("normal" === record.type) {
|
687
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
688
|
+
return {
|
689
|
+
value: record.arg,
|
690
|
+
done: context.done
|
691
|
+
};
|
692
|
+
}
|
693
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
694
|
+
}
|
695
|
+
};
|
696
|
+
}
|
697
|
+
function maybeInvokeDelegate(delegate, context) {
|
698
|
+
var methodName = context.method,
|
699
|
+
method = delegate.iterator[methodName];
|
700
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
701
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
702
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
703
|
+
var info = record.arg;
|
704
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
705
|
+
}
|
706
|
+
function pushTryEntry(locs) {
|
707
|
+
var entry = {
|
708
|
+
tryLoc: locs[0]
|
709
|
+
};
|
710
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
711
|
+
}
|
712
|
+
function resetTryEntry(entry) {
|
713
|
+
var record = entry.completion || {};
|
714
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
715
|
+
}
|
716
|
+
function Context(tryLocsList) {
|
717
|
+
this.tryEntries = [{
|
718
|
+
tryLoc: "root"
|
719
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
720
|
+
}
|
721
|
+
function values(iterable) {
|
722
|
+
if (iterable) {
|
723
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
724
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
725
|
+
if ("function" == typeof iterable.next) return iterable;
|
726
|
+
if (!isNaN(iterable.length)) {
|
727
|
+
var i = -1,
|
728
|
+
next = function next() {
|
729
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
730
|
+
return next.value = undefined, next.done = !0, next;
|
731
|
+
};
|
732
|
+
return next.next = next;
|
733
|
+
}
|
734
|
+
}
|
735
|
+
return {
|
736
|
+
next: doneResult
|
737
|
+
};
|
738
|
+
}
|
739
|
+
function doneResult() {
|
740
|
+
return {
|
741
|
+
value: undefined,
|
742
|
+
done: !0
|
743
|
+
};
|
744
|
+
}
|
745
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
746
|
+
value: GeneratorFunctionPrototype,
|
747
|
+
configurable: !0
|
748
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
749
|
+
value: GeneratorFunction,
|
750
|
+
configurable: !0
|
751
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
752
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
753
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
754
|
+
}, exports.mark = function (genFun) {
|
755
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
756
|
+
}, exports.awrap = function (arg) {
|
757
|
+
return {
|
758
|
+
__await: arg
|
759
|
+
};
|
760
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
761
|
+
return this;
|
762
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
763
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
764
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
765
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
766
|
+
return result.done ? result.value : iter.next();
|
767
|
+
});
|
768
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
769
|
+
return this;
|
770
|
+
}), define(Gp, "toString", function () {
|
771
|
+
return "[object Generator]";
|
772
|
+
}), exports.keys = function (val) {
|
773
|
+
var object = Object(val),
|
774
|
+
keys = [];
|
775
|
+
for (var key in object) keys.push(key);
|
776
|
+
return keys.reverse(), function next() {
|
777
|
+
for (; keys.length;) {
|
778
|
+
var key = keys.pop();
|
779
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
780
|
+
}
|
781
|
+
return next.done = !0, next;
|
782
|
+
};
|
783
|
+
}, exports.values = values, Context.prototype = {
|
784
|
+
constructor: Context,
|
785
|
+
reset: function (skipTempReset) {
|
786
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
787
|
+
},
|
788
|
+
stop: function () {
|
789
|
+
this.done = !0;
|
790
|
+
var rootRecord = this.tryEntries[0].completion;
|
791
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
792
|
+
return this.rval;
|
793
|
+
},
|
794
|
+
dispatchException: function (exception) {
|
795
|
+
if (this.done) throw exception;
|
796
|
+
var context = this;
|
797
|
+
function handle(loc, caught) {
|
798
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
799
|
+
}
|
800
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
801
|
+
var entry = this.tryEntries[i],
|
802
|
+
record = entry.completion;
|
803
|
+
if ("root" === entry.tryLoc) return handle("end");
|
804
|
+
if (entry.tryLoc <= this.prev) {
|
805
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
806
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
807
|
+
if (hasCatch && hasFinally) {
|
808
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
809
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
810
|
+
} else if (hasCatch) {
|
811
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
812
|
+
} else {
|
813
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
814
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
815
|
+
}
|
816
|
+
}
|
817
|
+
}
|
818
|
+
},
|
819
|
+
abrupt: function (type, arg) {
|
820
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
821
|
+
var entry = this.tryEntries[i];
|
822
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
823
|
+
var finallyEntry = entry;
|
824
|
+
break;
|
825
|
+
}
|
826
|
+
}
|
827
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
828
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
829
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
830
|
+
},
|
831
|
+
complete: function (record, afterLoc) {
|
832
|
+
if ("throw" === record.type) throw record.arg;
|
833
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
834
|
+
},
|
835
|
+
finish: function (finallyLoc) {
|
836
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
837
|
+
var entry = this.tryEntries[i];
|
838
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
839
|
+
}
|
840
|
+
},
|
841
|
+
catch: function (tryLoc) {
|
842
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
843
|
+
var entry = this.tryEntries[i];
|
844
|
+
if (entry.tryLoc === tryLoc) {
|
845
|
+
var record = entry.completion;
|
846
|
+
if ("throw" === record.type) {
|
847
|
+
var thrown = record.arg;
|
848
|
+
resetTryEntry(entry);
|
849
|
+
}
|
850
|
+
return thrown;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
throw new Error("illegal catch attempt");
|
854
|
+
},
|
855
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
856
|
+
return this.delegate = {
|
857
|
+
iterator: values(iterable),
|
858
|
+
resultName: resultName,
|
859
|
+
nextLoc: nextLoc
|
860
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
861
|
+
}
|
862
|
+
}, exports;
|
863
|
+
}
|
864
|
+
|
865
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
866
|
+
try {
|
867
|
+
var info = gen[key](arg);
|
868
|
+
var value = info.value;
|
869
|
+
} catch (error) {
|
870
|
+
reject(error);
|
871
|
+
return;
|
872
|
+
}
|
873
|
+
if (info.done) {
|
874
|
+
resolve(value);
|
875
|
+
} else {
|
876
|
+
Promise.resolve(value).then(_next, _throw);
|
877
|
+
}
|
878
|
+
}
|
879
|
+
function _asyncToGenerator(fn) {
|
880
|
+
return function () {
|
881
|
+
var self = this,
|
882
|
+
args = arguments;
|
883
|
+
return new Promise(function (resolve, reject) {
|
884
|
+
var gen = fn.apply(self, args);
|
885
|
+
function _next(value) {
|
886
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
887
|
+
}
|
888
|
+
function _throw(err) {
|
889
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
890
|
+
}
|
891
|
+
_next(undefined);
|
892
|
+
});
|
893
|
+
};
|
894
|
+
}
|
895
|
+
|
896
|
+
// TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
|
897
|
+
var ValApi = /*#__PURE__*/function () {
|
898
|
+
function ValApi(host) {
|
899
|
+
_classCallCheck(this, ValApi);
|
900
|
+
this.host = host;
|
901
|
+
}
|
902
|
+
_createClass(ValApi, [{
|
903
|
+
key: "getDisableUrl",
|
904
|
+
value: function getDisableUrl() {
|
905
|
+
return "".concat(this.host, "/disable");
|
906
|
+
}
|
907
|
+
}, {
|
908
|
+
key: "postPatches",
|
909
|
+
value: function postPatches(moduleId, patches, commit, headers) {
|
910
|
+
var params = "";
|
911
|
+
if (commit) {
|
912
|
+
var p = new URLSearchParams();
|
913
|
+
p.set("commit", commit);
|
914
|
+
params = "?".concat(p.toString());
|
915
|
+
}
|
916
|
+
return fetch("".concat(this.host, "/patches/~").concat(moduleId).concat(params), {
|
917
|
+
headers: headers || {
|
918
|
+
"Content-Type": "application/json"
|
919
|
+
},
|
920
|
+
method: "POST",
|
921
|
+
body: JSON.stringify(patches)
|
922
|
+
}).then(parse);
|
923
|
+
}
|
924
|
+
}, {
|
925
|
+
key: "getSession",
|
926
|
+
value: function getSession() {
|
927
|
+
return fetch("".concat(this.host, "/session")).then(parse);
|
928
|
+
}
|
929
|
+
}, {
|
930
|
+
key: "getModules",
|
931
|
+
value: function getModules(_ref) {
|
932
|
+
var _ref$patch = _ref.patch,
|
933
|
+
patch = _ref$patch === void 0 ? false : _ref$patch,
|
934
|
+
_ref$includeSchema = _ref.includeSchema,
|
935
|
+
includeSchema = _ref$includeSchema === void 0 ? false : _ref$includeSchema,
|
936
|
+
_ref$includeSource = _ref.includeSource,
|
937
|
+
includeSource = _ref$includeSource === void 0 ? false : _ref$includeSource,
|
938
|
+
_ref$treePath = _ref.treePath,
|
939
|
+
treePath = _ref$treePath === void 0 ? "/" : _ref$treePath,
|
940
|
+
headers = _ref.headers;
|
941
|
+
var params = new URLSearchParams();
|
942
|
+
params.set("patch", patch.toString());
|
943
|
+
params.set("schema", includeSchema.toString());
|
944
|
+
params.set("source", includeSource.toString());
|
945
|
+
return fetch("".concat(this.host, "/tree/~").concat(treePath, "?").concat(params.toString()), {
|
946
|
+
headers: headers
|
947
|
+
}).then(parse);
|
948
|
+
}
|
949
|
+
}]);
|
950
|
+
return ValApi;
|
951
|
+
}();
|
952
|
+
|
953
|
+
// TODO: validate
|
954
|
+
function parse(_x) {
|
955
|
+
return _parse.apply(this, arguments);
|
956
|
+
}
|
957
|
+
function _parse() {
|
958
|
+
_parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
|
959
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
960
|
+
while (1) switch (_context.prev = _context.next) {
|
961
|
+
case 0:
|
962
|
+
_context.prev = 0;
|
963
|
+
if (!res.ok) {
|
964
|
+
_context.next = 9;
|
965
|
+
break;
|
966
|
+
}
|
967
|
+
_context.t0 = result;
|
968
|
+
_context.next = 5;
|
969
|
+
return res.json();
|
970
|
+
case 5:
|
971
|
+
_context.t1 = _context.sent;
|
972
|
+
return _context.abrupt("return", _context.t0.ok.call(_context.t0, _context.t1));
|
973
|
+
case 9:
|
974
|
+
_context.t2 = result;
|
975
|
+
_context.t3 = res.status;
|
976
|
+
_context.next = 13;
|
977
|
+
return res.text();
|
978
|
+
case 13:
|
979
|
+
_context.t4 = _context.sent;
|
980
|
+
_context.t5 = {
|
981
|
+
statusCode: _context.t3,
|
982
|
+
message: _context.t4
|
983
|
+
};
|
984
|
+
return _context.abrupt("return", _context.t2.err.call(_context.t2, _context.t5));
|
985
|
+
case 16:
|
986
|
+
_context.next = 21;
|
987
|
+
break;
|
988
|
+
case 18:
|
989
|
+
_context.prev = 18;
|
990
|
+
_context.t6 = _context["catch"](0);
|
991
|
+
return _context.abrupt("return", err({
|
992
|
+
message: _context.t6 instanceof Error ? _context.t6.message : "Unknown error"
|
993
|
+
}));
|
994
|
+
case 21:
|
995
|
+
case "end":
|
996
|
+
return _context.stop();
|
997
|
+
}
|
998
|
+
}, _callee, null, [[0, 18]]);
|
999
|
+
}));
|
1000
|
+
return _parse.apply(this, arguments);
|
1001
|
+
}
|
1002
|
+
|
632
1003
|
var Internal = {
|
633
|
-
|
1004
|
+
convertFileSource: convertFileSource,
|
634
1005
|
getSchema: getSchema,
|
635
1006
|
getValPath: getValPath,
|
636
1007
|
getVal: getVal,
|
637
|
-
|
1008
|
+
getSource: getSource,
|
638
1009
|
resolvePath: resolvePath,
|
639
1010
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
640
|
-
|
641
|
-
|
1011
|
+
isVal: isVal,
|
1012
|
+
createValPathOfItem: createValPathOfItem,
|
1013
|
+
createPatchJSONPath: function createPatchJSONPath(modulePath) {
|
1014
|
+
return "/".concat(modulePath.split(".").map(function (segment) {
|
1015
|
+
return JSON.parse(segment);
|
1016
|
+
}).join("/"));
|
1017
|
+
},
|
1018
|
+
/**
|
1019
|
+
* Enables draft mode: updates all Val modules with patches
|
1020
|
+
*/
|
1021
|
+
VAL_DRAFT_MODE_COOKIE: "val_draft_mode",
|
1022
|
+
/**
|
1023
|
+
* Enables Val: show the overlay / menu
|
1024
|
+
*/
|
1025
|
+
VAL_ENABLE_COOKIE_NAME: "val_enable",
|
1026
|
+
VAL_STATE_COOKIE: "val_state",
|
1027
|
+
VAL_SESSION_COOKIE: "val_session"
|
642
1028
|
};
|
643
1029
|
|
644
|
-
export { Internal, derefPatch, initVal };
|
1030
|
+
export { Internal, ValApi, derefPatch, initVal };
|