@valbuild/core 0.16.0 → 0.18.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.
Files changed (104) hide show
  1. package/ROADMAP.md +106 -0
  2. package/dist/declarations/src/ValApi.d.ts +26 -0
  3. package/dist/declarations/src/expr/eval.d.ts +1 -1
  4. package/dist/declarations/src/future/fetchVal.d.ts +5 -0
  5. package/dist/declarations/src/index.d.ts +36 -9
  6. package/dist/declarations/src/initSchema.d.ts +8 -10
  7. package/dist/declarations/src/initVal.d.ts +3 -21
  8. package/dist/declarations/src/module.d.ts +2 -14
  9. package/dist/declarations/src/schema/image.d.ts +1 -1
  10. package/dist/declarations/src/schema/index.d.ts +3 -5
  11. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  12. package/dist/declarations/src/schema/record.d.ts +19 -0
  13. package/dist/declarations/src/schema/union.d.ts +1 -0
  14. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  15. package/dist/declarations/src/selector/array.d.ts +2 -13
  16. package/dist/declarations/src/selector/file.d.ts +1 -4
  17. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  18. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  19. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  20. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  21. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  22. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  23. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  24. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  25. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  26. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  27. package/dist/declarations/src/selector/index.d.ts +5 -32
  28. package/dist/declarations/src/selector/object.d.ts +2 -9
  29. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  30. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  31. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  32. package/dist/declarations/src/source/index.d.ts +4 -3
  33. package/dist/declarations/src/val/index.d.ts +2 -2
  34. package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
  35. package/dist/{index-af761363.esm.js → index-4abf3a1f.esm.js} +189 -1
  36. package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
  37. package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
  38. package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
  39. package/dist/{SelectorProxy-63c2d0e2.esm.js → index-a9235737.esm.js} +23 -195
  40. package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
  41. package/dist/{ops-74661336.esm.js → ops-a2a295f8.esm.js} +195 -65
  42. package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
  43. package/dist/valbuild-core.cjs.dev.js +784 -197
  44. package/dist/valbuild-core.cjs.prod.js +784 -197
  45. package/dist/valbuild-core.esm.js +719 -133
  46. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  47. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  48. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  49. package/package.json +2 -3
  50. package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
  51. package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
  52. package/patch/dist/valbuild-core-patch.esm.js +3 -3
  53. package/src/ValApi.ts +85 -0
  54. package/src/expr/eval.test.ts +2 -2
  55. package/src/expr/eval.ts +2 -2
  56. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  57. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  58. package/src/index.ts +46 -14
  59. package/src/initSchema.ts +17 -12
  60. package/src/initVal.ts +42 -52
  61. package/src/module.test.ts +40 -40
  62. package/src/module.ts +53 -43
  63. package/src/patch/deref.test.ts +1 -1
  64. package/src/patch/deref.ts +1 -1
  65. package/src/patch/json.test.ts +0 -1
  66. package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
  67. package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
  68. package/src/schema/image.ts +1 -1
  69. package/src/schema/index.ts +16 -13
  70. package/src/schema/keyOf.ts +167 -0
  71. package/src/schema/record.ts +103 -0
  72. package/src/schema/union.ts +1 -1
  73. package/src/schema/validation.test.ts +195 -130
  74. package/src/selector/SelectorProxy.ts +15 -15
  75. package/src/selector/array.ts +2 -26
  76. package/src/selector/file.ts +1 -9
  77. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  78. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  79. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  80. package/src/selector/future/SelectorProxy.ts +238 -0
  81. package/src/selector/future/array.ts +37 -0
  82. package/src/selector/future/boolean.ts +4 -0
  83. package/src/selector/future/file.ts +14 -0
  84. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  85. package/src/selector/future/index.ts +165 -0
  86. package/src/selector/future/number.ts +4 -0
  87. package/src/selector/future/object.ts +22 -0
  88. package/src/selector/future/primitive.ts +17 -0
  89. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  90. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  91. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  92. package/src/selector/future/string.ts +4 -0
  93. package/src/selector/index.ts +4 -46
  94. package/src/selector/object.ts +2 -19
  95. package/src/selector/primitive.ts +3 -16
  96. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  97. package/src/source/{remote.ts → future/remote.ts} +3 -3
  98. package/src/source/index.ts +3 -2
  99. package/src/val/array.ts +1 -1
  100. package/src/val/index.ts +2 -2
  101. package/src/val/object.ts +1 -1
  102. package/dist/declarations/src/fetchVal.d.ts +0 -5
  103. package/dist/declarations/src/schema/i18n.d.ts +0 -22
  104. package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -2,98 +2,32 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var SelectorProxy = require('./SelectorProxy-873782a5.cjs.dev.js');
6
- var ops = require('./ops-ea4827fc.cjs.dev.js');
7
- var expr_dist_valbuildCoreExpr = require('./index-2fff5ca8.cjs.dev.js');
5
+ var index = require('./index-a6e642dd.cjs.dev.js');
6
+ var ops = require('./ops-f3015423.cjs.dev.js');
7
+ var expr_dist_valbuildCoreExpr = require('./index-486c7fbf.cjs.dev.js');
8
8
  var result = require('./result-48320acd.cjs.dev.js');
9
9
 
10
- var OneOfSchema = /*#__PURE__*/function (_Schema) {
11
- SelectorProxy._inherits(OneOfSchema, _Schema);
12
- var _super = SelectorProxy._createSuper(OneOfSchema);
13
- function OneOfSchema(selector) {
14
- var _this;
15
- var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
16
- SelectorProxy._classCallCheck(this, OneOfSchema);
17
- _this = _super.call(this);
18
- _this.selector = selector;
19
- _this.opt = opt;
20
- return _this;
21
- }
22
- SelectorProxy._createClass(OneOfSchema, [{
23
- key: "validate",
24
- value: function validate(path, src) {
25
- throw new Error("Method not implemented.");
26
- }
27
- }, {
28
- key: "assert",
29
- value: function assert(src) {
30
- throw new Error("Method not implemented.");
31
- }
32
- }, {
33
- key: "optional",
34
- value: function optional() {
35
- return new OneOfSchema(this.selector, true);
36
- }
37
- }, {
38
- key: "serialize",
39
- value: function serialize() {
40
- var path = SelectorProxy.getValPath(this.selector);
41
- if (!path) {
42
- throw new Error("Cannot serialize oneOf schema with empty selector. Make sure a Val module is used.");
43
- }
44
- return {
45
- type: "oneOf",
46
- selector: path,
47
- opt: this.opt
48
- };
49
- }
50
- }]);
51
- return OneOfSchema;
52
- }(SelectorProxy.Schema);
53
- var oneOf = function oneOf(valModule) {
54
- return new OneOfSchema(valModule);
55
- };
56
-
57
- /**
58
- * I18n sources cannot have nested remote sources.
59
- */
60
-
61
- /**
62
- * An i18n source is a map of locales to sources.
63
- *
64
- * 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
65
- *
66
- */
67
-
68
- function i18n(
69
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
- locales) {
71
- return function (source) {
72
- return SelectorProxy._objectSpread2(SelectorProxy._objectSpread2({}, source), {}, SelectorProxy._defineProperty({}, SelectorProxy.VAL_EXTENSION, "i18n"));
73
- };
74
- }
75
-
76
10
  var NumberSchema = /*#__PURE__*/function (_Schema) {
77
- SelectorProxy._inherits(NumberSchema, _Schema);
78
- var _super = SelectorProxy._createSuper(NumberSchema);
11
+ index._inherits(NumberSchema, _Schema);
12
+ var _super = index._createSuper(NumberSchema);
79
13
  function NumberSchema(options) {
80
14
  var _this;
81
15
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
82
- SelectorProxy._classCallCheck(this, NumberSchema);
16
+ index._classCallCheck(this, NumberSchema);
83
17
  _this = _super.call(this);
84
18
  _this.options = options;
85
19
  _this.opt = opt;
86
20
  return _this;
87
21
  }
88
- SelectorProxy._createClass(NumberSchema, [{
22
+ index._createClass(NumberSchema, [{
89
23
  key: "validate",
90
24
  value: function validate(path, src) {
91
25
  if (this.opt && (src === null || src === undefined)) {
92
26
  return false;
93
27
  }
94
28
  if (typeof src !== "number") {
95
- return SelectorProxy._defineProperty({}, path, [{
96
- message: "Expected 'number', got '".concat(SelectorProxy._typeof(src), "'"),
29
+ return index._defineProperty({}, path, [{
30
+ message: "Expected 'number', got '".concat(index._typeof(src), "'"),
97
31
  value: src
98
32
  }]);
99
33
  }
@@ -123,32 +57,32 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
123
57
  }
124
58
  }]);
125
59
  return NumberSchema;
126
- }(SelectorProxy.Schema);
60
+ }(index.Schema);
127
61
  var number = function number(options) {
128
62
  return new NumberSchema(options);
129
63
  };
130
64
 
131
65
  var StringSchema = /*#__PURE__*/function (_Schema) {
132
- SelectorProxy._inherits(StringSchema, _Schema);
133
- var _super = SelectorProxy._createSuper(StringSchema);
66
+ index._inherits(StringSchema, _Schema);
67
+ var _super = index._createSuper(StringSchema);
134
68
  function StringSchema(options) {
135
69
  var _this;
136
70
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
137
- SelectorProxy._classCallCheck(this, StringSchema);
71
+ index._classCallCheck(this, StringSchema);
138
72
  _this = _super.call(this);
139
73
  _this.options = options;
140
74
  _this.opt = opt;
141
75
  return _this;
142
76
  }
143
- SelectorProxy._createClass(StringSchema, [{
77
+ index._createClass(StringSchema, [{
144
78
  key: "validate",
145
79
  value: function validate(path, src) {
146
80
  if (this.opt && (src === null || src === undefined)) {
147
81
  return false;
148
82
  }
149
83
  if (typeof src !== "string") {
150
- return SelectorProxy._defineProperty({}, path, [{
151
- message: "Expected 'string', got '".concat(SelectorProxy._typeof(src), "'"),
84
+ return index._defineProperty({}, path, [{
85
+ message: "Expected 'string', got '".concat(index._typeof(src), "'"),
152
86
  value: src
153
87
  }]);
154
88
  }
@@ -178,31 +112,31 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
178
112
  }
179
113
  }]);
180
114
  return StringSchema;
181
- }(SelectorProxy.Schema);
115
+ }(index.Schema);
182
116
  var string = function string(options) {
183
117
  return new StringSchema(options);
184
118
  };
185
119
 
186
120
  var BooleanSchema = /*#__PURE__*/function (_Schema) {
187
- SelectorProxy._inherits(BooleanSchema, _Schema);
188
- var _super = SelectorProxy._createSuper(BooleanSchema);
121
+ index._inherits(BooleanSchema, _Schema);
122
+ var _super = index._createSuper(BooleanSchema);
189
123
  function BooleanSchema() {
190
124
  var _this;
191
125
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
192
- SelectorProxy._classCallCheck(this, BooleanSchema);
126
+ index._classCallCheck(this, BooleanSchema);
193
127
  _this = _super.call(this);
194
128
  _this.opt = opt;
195
129
  return _this;
196
130
  }
197
- SelectorProxy._createClass(BooleanSchema, [{
131
+ index._createClass(BooleanSchema, [{
198
132
  key: "validate",
199
133
  value: function validate(path, src) {
200
134
  if (this.opt && (src === null || src === undefined)) {
201
135
  return false;
202
136
  }
203
137
  if (typeof src !== "boolean") {
204
- return SelectorProxy._defineProperty({}, path, [{
205
- message: "Expected 'boolean', got '".concat(SelectorProxy._typeof(src), "'"),
138
+ return index._defineProperty({}, path, [{
139
+ message: "Expected 'boolean', got '".concat(index._typeof(src), "'"),
206
140
  value: src
207
141
  }]);
208
142
  }
@@ -231,37 +165,37 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
231
165
  }
232
166
  }]);
233
167
  return BooleanSchema;
234
- }(SelectorProxy.Schema);
168
+ }(index.Schema);
235
169
  var _boolean = function _boolean() {
236
170
  return new BooleanSchema();
237
171
  };
238
172
 
239
173
  var LiteralSchema = /*#__PURE__*/function (_Schema) {
240
- SelectorProxy._inherits(LiteralSchema, _Schema);
241
- var _super = SelectorProxy._createSuper(LiteralSchema);
174
+ index._inherits(LiteralSchema, _Schema);
175
+ var _super = index._createSuper(LiteralSchema);
242
176
  function LiteralSchema(value) {
243
177
  var _this;
244
178
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
245
- SelectorProxy._classCallCheck(this, LiteralSchema);
179
+ index._classCallCheck(this, LiteralSchema);
246
180
  _this = _super.call(this);
247
181
  _this.value = value;
248
182
  _this.opt = opt;
249
183
  return _this;
250
184
  }
251
- SelectorProxy._createClass(LiteralSchema, [{
185
+ index._createClass(LiteralSchema, [{
252
186
  key: "validate",
253
187
  value: function validate(path, src) {
254
188
  if (this.opt && (src === null || src === undefined)) {
255
189
  return false;
256
190
  }
257
191
  if (typeof src !== "string") {
258
- return SelectorProxy._defineProperty({}, path, [{
259
- message: "Expected 'string', got '".concat(SelectorProxy._typeof(src), "'"),
192
+ return index._defineProperty({}, path, [{
193
+ message: "Expected 'string', got '".concat(index._typeof(src), "'"),
260
194
  value: src
261
195
  }]);
262
196
  }
263
197
  if (src !== this.value) {
264
- return SelectorProxy._defineProperty({}, path, [{
198
+ return index._defineProperty({}, path, [{
265
199
  message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
266
200
  value: src
267
201
  }]);
@@ -292,12 +226,217 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
292
226
  }
293
227
  }]);
294
228
  return LiteralSchema;
295
- }(SelectorProxy.Schema);
229
+ }(index.Schema);
296
230
  var literal = function literal(value) {
297
231
  return new LiteralSchema(value);
298
232
  };
299
233
 
300
- function initSchema(locales) {
234
+ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
235
+ index._inherits(KeyOfSchema, _Schema);
236
+ var _super = index._createSuper(KeyOfSchema);
237
+ function KeyOfSchema(selector) {
238
+ var _this;
239
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
240
+ index._classCallCheck(this, KeyOfSchema);
241
+ _this = _super.call(this);
242
+ _this.selector = selector;
243
+ _this.opt = opt;
244
+ return _this;
245
+ }
246
+ index._createClass(KeyOfSchema, [{
247
+ key: "validate",
248
+ value: function validate(path, src) {
249
+ if (this.opt && (src === null || src === undefined)) {
250
+ return false;
251
+ }
252
+ var schema = this.selector[index.GetSchema];
253
+ if (!schema) {
254
+ return index._defineProperty({}, path, [{
255
+ message: "Schema not found for module. keyOf must be used with a Val Module"
256
+ }]);
257
+ }
258
+ var serializedSchema = schema.serialize();
259
+ if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
260
+ return index._defineProperty({}, path, [{
261
+ message: "Schema in keyOf must be an 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
262
+ }]);
263
+ }
264
+ if (serializedSchema.opt && (src === null || src === undefined)) {
265
+ return false;
266
+ }
267
+ if (serializedSchema.type === "array" && typeof src !== "number") {
268
+ return index._defineProperty({}, path, [{
269
+ message: "Type of value in keyof (array) must be 'number'"
270
+ }]);
271
+ }
272
+ if (serializedSchema.type === "record" && typeof src !== "string") {
273
+ return index._defineProperty({}, path, [{
274
+ message: "Type of value in keyof (record) must be 'string'"
275
+ }]);
276
+ }
277
+ if (serializedSchema.type === "object") {
278
+ var keys = Object.keys(serializedSchema.items);
279
+ if (!keys.includes(src)) {
280
+ return index._defineProperty({}, path, [{
281
+ message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
282
+ }]);
283
+ }
284
+ }
285
+ return false;
286
+ }
287
+ }, {
288
+ key: "assert",
289
+ value: function assert(src) {
290
+ if (this.opt && (src === null || src === undefined)) {
291
+ return true;
292
+ }
293
+ var schema = this.selector[index.GetSchema];
294
+ if (!schema) {
295
+ return false;
296
+ }
297
+ var serializedSchema = schema.serialize();
298
+ if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
299
+ return false;
300
+ }
301
+ if (serializedSchema.opt && (src === null || src === undefined)) {
302
+ return true;
303
+ }
304
+ if (serializedSchema.type === "array" && typeof src !== "number") {
305
+ return false;
306
+ }
307
+ if (serializedSchema.type === "record" && typeof src !== "string") {
308
+ return false;
309
+ }
310
+ if (serializedSchema.type === "object") {
311
+ var keys = Object.keys(serializedSchema.items);
312
+ if (!keys.includes(src)) {
313
+ return false;
314
+ }
315
+ }
316
+ return true;
317
+ }
318
+ }, {
319
+ key: "optional",
320
+ value: function optional() {
321
+ return new KeyOfSchema(this.selector, true);
322
+ }
323
+ }, {
324
+ key: "serialize",
325
+ value: function serialize() {
326
+ var path = index.getValPath(this.selector);
327
+ if (!path) {
328
+ throw new Error("Cannot serialize oneOf schema with empty selector. keyOf must be used with a Val Module.");
329
+ }
330
+ return {
331
+ type: "keyOf",
332
+ selector: path,
333
+ opt: this.opt
334
+ };
335
+ }
336
+ }]);
337
+ return KeyOfSchema;
338
+ }(index.Schema);
339
+ var keyOf = function keyOf(valModule) {
340
+ return new KeyOfSchema(valModule);
341
+ };
342
+
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
+ // import type { F } from "ts-toolbelt";
433
+ // import { i18n, I18n } from "./schema/future/i18n";
434
+ // import { oneOf } from "./schema/future/oneOf";
435
+ // export type InitSchemaLocalized<Locales extends readonly string[]> = {
436
+ // readonly i18n: I18n<Locales>;
437
+ // };
438
+ function initSchema() {
439
+ // locales: F.Narrow<Locales>
301
440
  return {
302
441
  string: string,
303
442
  "boolean": _boolean,
@@ -305,38 +444,20 @@ function initSchema(locales) {
305
444
  object: ops.object,
306
445
  number: number,
307
446
  union: ops.union,
308
- oneOf: oneOf,
447
+ // oneOf,
309
448
  richtext: ops.richtext,
310
- image: SelectorProxy.image,
449
+ image: index.image,
311
450
  literal: literal,
312
- i18n: ops.i18n(locales)
451
+ keyOf: keyOf,
452
+ record: record
453
+ // i18n: i18n(locales),
313
454
  };
314
455
  }
315
456
 
316
- /**
317
- * Remote sources cannot include other remote sources.
318
- */
319
-
320
- var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
321
-
322
- /**
323
- * A remote source is a hash that represents a remote object.
324
- *
325
- * It will be resolved into a ValRemote object.
326
- */
327
-
328
- function remote(ref) {
329
- var _ref;
330
- return _ref = {}, SelectorProxy._defineProperty(_ref, REMOTE_REF_PROP, ref), SelectorProxy._defineProperty(_ref, SelectorProxy.VAL_EXTENSION, "remote"), _ref;
331
- }
332
- function isRemote(obj) {
333
- return SelectorProxy._typeof(obj) === "object" && obj !== null && SelectorProxy.VAL_EXTENSION in obj && obj[SelectorProxy.VAL_EXTENSION] === "remote" && REMOTE_REF_PROP in obj && typeof obj[REMOTE_REF_PROP] === "string";
334
- }
335
-
336
457
  function richtext(data) {
337
458
  if (typeof data === "string") {
338
459
  var _ref;
339
- return _ref = {}, SelectorProxy._defineProperty(_ref, SelectorProxy.VAL_EXTENSION, "richtext"), SelectorProxy._defineProperty(_ref, "type", "root"), SelectorProxy._defineProperty(_ref, "children", [{
460
+ return _ref = {}, index._defineProperty(_ref, index.VAL_EXTENSION, "richtext"), index._defineProperty(_ref, "type", "root"), index._defineProperty(_ref, "children", [{
340
461
  type: "paragraph",
341
462
  children: [{
342
463
  type: "text",
@@ -344,43 +465,58 @@ function richtext(data) {
344
465
  }]
345
466
  }]), _ref;
346
467
  }
347
- return SelectorProxy._objectSpread2(SelectorProxy._objectSpread2({}, data), {}, SelectorProxy._defineProperty({}, SelectorProxy.VAL_EXTENSION, "richtext"));
468
+ return index._objectSpread2(index._objectSpread2({}, data), {}, index._defineProperty({}, index.VAL_EXTENSION, "richtext"));
348
469
  }
349
470
 
350
- var initVal = function initVal(options) {
351
- var locales = options === null || options === void 0 ? void 0 : options.locales;
352
- var s = initSchema(locales === null || locales === void 0 ? void 0 : locales.required);
353
- if (locales !== null && locales !== void 0 && locales.required) {
354
- console.error("Locales / i18n currently not implemented");
355
- return {
356
- val: {
357
- content: ops.content,
358
- i18n: i18n,
359
- remote: remote,
360
- getPath: SelectorProxy.getValPath,
361
- file: SelectorProxy.file,
362
- richtext: richtext
363
- },
364
- s: s
365
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
366
- };
367
- }
368
-
471
+ // import { i18n, I18n } from "./source/future/i18n";
472
+ // import { remote } from "./source/future/remote";
473
+ // type NarrowStrings<A> =
474
+ // | (A extends [] ? [] : never)
475
+ // | (A extends string ? A : never)
476
+ // | {
477
+ // [K in keyof A]: NarrowStrings<A[K]>;
478
+ // };
479
+ // TODO: Rename to createValSystem (only to be used by internal things), we can then export * from '@valbuild/core' in the next package then.
480
+ var initVal = function initVal() {
481
+ // const locales = options?.locales;
482
+ var s = initSchema();
483
+ // if (locales?.required) {
484
+ // console.error("Locales / i18n currently not implemented");
485
+ // return {
486
+ // val: {
487
+ // content,
488
+ // i18n,
489
+ // remote,
490
+ // getPath,
491
+ // file,
492
+ // richtext,
493
+ // },
494
+ // s,
495
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
496
+ // } as any;
497
+ // }
369
498
  return {
370
499
  val: {
371
500
  content: ops.content,
372
- remote: remote,
373
- getPath: SelectorProxy.getValPath,
374
- file: SelectorProxy.file,
501
+ // remote,
502
+ getPath: index.getValPath,
503
+ file: index.file,
375
504
  richtext: richtext
376
505
  },
377
- s: SelectorProxy._objectSpread2(SelectorProxy._objectSpread2({}, s), {}, {
378
- i18n: undefined
379
- })
506
+ s: index._objectSpread2({}, s)
380
507
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
381
508
  };
382
509
  };
383
510
 
511
+ /**
512
+ * Remote sources cannot include other remote sources.
513
+ */
514
+
515
+ var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
516
+ function isRemote(obj) {
517
+ return index._typeof(obj) === "object" && obj !== null && index.VAL_EXTENSION in obj && obj[index.VAL_EXTENSION] === "remote" && REMOTE_REF_PROP in obj && typeof obj[REMOTE_REF_PROP] === "string";
518
+ }
519
+
384
520
  function derefPath(path) {
385
521
  var dereffedPath = [];
386
522
  var referencedPath = null;
@@ -434,21 +570,21 @@ function derefPatch(patch, document, ops$1) {
434
570
  if (result.isErr(maybeDerefRes)) {
435
571
  return maybeDerefRes;
436
572
  }
437
- var _maybeDerefRes$value = SelectorProxy._slicedToArray(maybeDerefRes.value, 2),
573
+ var _maybeDerefRes$value = index._slicedToArray(maybeDerefRes.value, 2),
438
574
  dereffedPath = _maybeDerefRes$value[0],
439
575
  referencedPath = _maybeDerefRes$value[1];
440
576
  if (referencedPath) {
441
577
  var maybeValue = ops$1.get(document, dereffedPath);
442
578
  if (result.isOk(maybeValue)) {
443
579
  var value = maybeValue.value;
444
- if (SelectorProxy.isFile(value)) {
580
+ if (index.isFile(value)) {
445
581
  if (referencedPath.length > 0) {
446
582
  return result.err(new ops.PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
447
583
  }
448
584
  if (typeof op.value !== "string") {
449
585
  return result.err(new ops.PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
450
586
  }
451
- fileUpdates[value[SelectorProxy.FILE_REF_PROP]] = op.value;
587
+ fileUpdates[value[index.FILE_REF_PROP]] = op.value;
452
588
  } else if (isRemote(value)) {
453
589
  if (!remotePatches[value[REMOTE_REF_PROP]]) {
454
590
  remotePatches[value[REMOTE_REF_PROP]] = [];
@@ -472,7 +608,7 @@ function derefPatch(patch, document, ops$1) {
472
608
  if (result.isErr(_maybeDerefRes)) {
473
609
  return _maybeDerefRes;
474
610
  }
475
- var _maybeDerefRes$value2 = SelectorProxy._slicedToArray(_maybeDerefRes.value, 2),
611
+ var _maybeDerefRes$value2 = index._slicedToArray(_maybeDerefRes.value, 2),
476
612
  _referencedPath = _maybeDerefRes$value2[1];
477
613
  if (_referencedPath) {
478
614
  throw new Error("Unimplemented operation: ".concat(JSON.stringify(op)));
@@ -492,63 +628,58 @@ function derefPatch(patch, document, ops$1) {
492
628
  });
493
629
  }
494
630
 
495
- function fetchVal(selector, locale) {
496
- return Promise.resolve(getVal(selector));
497
- }
498
- function getVal(selector,
499
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
500
- locale) {
631
+ function getVal(selector) {
501
632
  return newValProxy(serializedValOfSelectorSource(selector));
502
633
  }
503
634
 
504
635
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
505
636
  function isArrayOrArraySelector(child) {
506
- if (SelectorProxy.isSelector(child)) {
507
- return SelectorProxy._typeof(child[SelectorProxy.SourceOrExpr]) === "object" && SelectorProxy._typeof(child[SelectorProxy.SourceOrExpr]) !== null && Array.isArray(child[SelectorProxy.SourceOrExpr]);
637
+ if (ops.isSelector(child)) {
638
+ return index._typeof(child[index.GetSource]) === "object" && index._typeof(child[index.GetSource]) !== null && Array.isArray(child[index.GetSource]);
508
639
  }
509
640
  return Array.isArray(child);
510
641
  }
511
642
 
512
643
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
513
644
  function isObjectOrObjectSelector(child) {
514
- if (SelectorProxy.isSelector(child)) {
515
- return SelectorProxy._typeof(child[SelectorProxy.SourceOrExpr]) === "object" && SelectorProxy._typeof(child[SelectorProxy.SourceOrExpr]) !== null && !Array.isArray(child[SelectorProxy.SourceOrExpr]);
645
+ if (ops.isSelector(child)) {
646
+ return index._typeof(child[index.GetSource]) === "object" && index._typeof(child[index.GetSource]) !== null && !Array.isArray(child[index.GetSource]);
516
647
  }
517
- return SelectorProxy._typeof(child) === "object";
648
+ return index._typeof(child) === "object";
518
649
  }
519
650
  function serializedValOfSelectorSource(selector) {
520
- var wrappedSelector = SelectorProxy.newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
651
+ var wrappedSelector = ops.newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
521
652
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
522
653
  function rec(child) {
523
654
  var isArray = isArrayOrArraySelector(child);
524
655
  var isObject = isObjectOrObjectSelector(child);
525
656
  if (isArray) {
526
- var array = SelectorProxy.SourceOrExpr in child ? child[SelectorProxy.SourceOrExpr] : child;
527
- var valPath = SelectorProxy.Path in child ? child[SelectorProxy.Path] : undefined;
657
+ var array = index.GetSource in child ? child[index.GetSource] : child;
658
+ var valPath = index.Path in child ? child[index.Path] : undefined;
528
659
  return {
529
660
  val: array.map(function (item, i) {
530
- return rec(SelectorProxy.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
531
- ? item : SelectorProxy.newSelectorProxy(item, SelectorProxy.createValPathOfItem(valPath, i)));
661
+ return rec(ops.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
662
+ ? item : ops.newSelectorProxy(item, ops.createValPathOfItem(valPath, i)));
532
663
  }),
533
664
  valPath: valPath
534
665
  };
535
666
  } else if (isObject) {
536
- var obj = SelectorProxy.SourceOrExpr in child ? child[SelectorProxy.SourceOrExpr] : child;
537
- var _valPath = SelectorProxy.Path in child ? child[SelectorProxy.Path] : undefined;
667
+ var obj = index.GetSource in child ? child[index.GetSource] : child;
668
+ var _valPath = index.Path in child ? child[index.Path] : undefined;
538
669
  return {
539
670
  val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
540
- var _ref2 = SelectorProxy._slicedToArray(_ref, 2),
671
+ var _ref2 = index._slicedToArray(_ref, 2),
541
672
  key = _ref2[0],
542
673
  value = _ref2[1];
543
- return [key, rec(SelectorProxy.isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
544
- ? value : SelectorProxy.newSelectorProxy(value, SelectorProxy.createValPathOfItem(_valPath, key)))];
674
+ return [key, rec(ops.isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
675
+ ? value : ops.newSelectorProxy(value, ops.createValPathOfItem(_valPath, key)))];
545
676
  })),
546
677
  valPath: _valPath
547
678
  };
548
- } else if (SelectorProxy.isSelector(child)) {
679
+ } else if (ops.isSelector(child)) {
549
680
  return {
550
- val: rec(child[SelectorProxy.SourceOrExpr]),
551
- valPath: child[SelectorProxy.Path]
681
+ val: rec(child[index.GetSource]),
682
+ valPath: child[index.Path]
552
683
  };
553
684
  } else {
554
685
  return child;
@@ -557,11 +688,11 @@ function serializedValOfSelectorSource(selector) {
557
688
  return rec(wrappedSelector);
558
689
  }
559
690
  function strip(value) {
560
- var val = SelectorProxy.isSerializedVal(value) ? value.val : value;
561
- switch (SelectorProxy._typeof(val)) {
691
+ var val = index.isSerializedVal(value) ? value.val : value;
692
+ switch (index._typeof(val)) {
562
693
  case "function":
563
694
  case "symbol":
564
- throw Error("Invalid val type: ".concat(SelectorProxy._typeof(val)));
695
+ throw Error("Invalid val type: ".concat(index._typeof(val)));
565
696
  case "object":
566
697
  if (val === null) {
567
698
  return null;
@@ -569,7 +700,7 @@ function strip(value) {
569
700
  return val.map(strip);
570
701
  } else {
571
702
  return Object.fromEntries(Object.entries(val).map(function (_ref3) {
572
- var _ref4 = SelectorProxy._slicedToArray(_ref3, 2),
703
+ var _ref4 = index._slicedToArray(_ref3, 2),
573
704
  key = _ref4[0],
574
705
  value = _ref4[1];
575
706
  return [key, value && strip(value)];
@@ -584,10 +715,10 @@ function strip(value) {
584
715
  function newValProxy(val) {
585
716
  var _ref5;
586
717
  var source = val.val;
587
- switch (SelectorProxy._typeof(source)) {
718
+ switch (index._typeof(source)) {
588
719
  case "function":
589
720
  case "symbol":
590
- throw Error("Invalid val type: ".concat(SelectorProxy._typeof(source)));
721
+ throw Error("Invalid val type: ".concat(index._typeof(source)));
591
722
  case "object":
592
723
  if (source !== null) {
593
724
  // Handles both objects and arrays!
@@ -596,13 +727,13 @@ function newValProxy(val) {
596
727
  if (prop === "val") {
597
728
  return true;
598
729
  }
599
- if (prop === SelectorProxy.Path) {
730
+ if (prop === index.Path) {
600
731
  return true;
601
732
  }
602
733
  return hasOwn(target, prop);
603
734
  },
604
735
  get: function get(target, prop) {
605
- if (prop === SelectorProxy.Path) {
736
+ if (prop === index.Path) {
606
737
  return val.valPath;
607
738
  }
608
739
  if (prop === "val") {
@@ -615,7 +746,7 @@ function newValProxy(val) {
615
746
  var _Reflect$get$valPath, _Reflect$get;
616
747
  return newValProxy({
617
748
  val: Reflect.get(target, prop).val,
618
- valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : SelectorProxy.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
749
+ valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : ops.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
619
750
  });
620
751
  }
621
752
  return Reflect.get(target, prop);
@@ -625,30 +756,486 @@ function newValProxy(val) {
625
756
  // intentional fallthrough
626
757
  // eslint-disable-next-line no-fallthrough
627
758
  default:
628
- return _ref5 = {}, SelectorProxy._defineProperty(_ref5, SelectorProxy.Path, val.valPath), SelectorProxy._defineProperty(_ref5, "val", val.val), _ref5;
759
+ return _ref5 = {}, index._defineProperty(_ref5, index.Path, val.valPath), index._defineProperty(_ref5, "val", val.val), _ref5;
629
760
  }
630
761
  }
631
762
  function hasOwn(obj, prop) {
632
763
  return Object.prototype.hasOwnProperty.call(obj, prop);
633
764
  }
634
765
 
766
+ function _regeneratorRuntime() {
767
+ _regeneratorRuntime = function () {
768
+ return exports;
769
+ };
770
+ var exports = {},
771
+ Op = Object.prototype,
772
+ hasOwn = Op.hasOwnProperty,
773
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
774
+ obj[key] = desc.value;
775
+ },
776
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
777
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
778
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
779
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
780
+ function define(obj, key, value) {
781
+ return Object.defineProperty(obj, key, {
782
+ value: value,
783
+ enumerable: !0,
784
+ configurable: !0,
785
+ writable: !0
786
+ }), obj[key];
787
+ }
788
+ try {
789
+ define({}, "");
790
+ } catch (err) {
791
+ define = function (obj, key, value) {
792
+ return obj[key] = value;
793
+ };
794
+ }
795
+ function wrap(innerFn, outerFn, self, tryLocsList) {
796
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
797
+ generator = Object.create(protoGenerator.prototype),
798
+ context = new Context(tryLocsList || []);
799
+ return defineProperty(generator, "_invoke", {
800
+ value: makeInvokeMethod(innerFn, self, context)
801
+ }), generator;
802
+ }
803
+ function tryCatch(fn, obj, arg) {
804
+ try {
805
+ return {
806
+ type: "normal",
807
+ arg: fn.call(obj, arg)
808
+ };
809
+ } catch (err) {
810
+ return {
811
+ type: "throw",
812
+ arg: err
813
+ };
814
+ }
815
+ }
816
+ exports.wrap = wrap;
817
+ var ContinueSentinel = {};
818
+ function Generator() {}
819
+ function GeneratorFunction() {}
820
+ function GeneratorFunctionPrototype() {}
821
+ var IteratorPrototype = {};
822
+ define(IteratorPrototype, iteratorSymbol, function () {
823
+ return this;
824
+ });
825
+ var getProto = Object.getPrototypeOf,
826
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
827
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
828
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
829
+ function defineIteratorMethods(prototype) {
830
+ ["next", "throw", "return"].forEach(function (method) {
831
+ define(prototype, method, function (arg) {
832
+ return this._invoke(method, arg);
833
+ });
834
+ });
835
+ }
836
+ function AsyncIterator(generator, PromiseImpl) {
837
+ function invoke(method, arg, resolve, reject) {
838
+ var record = tryCatch(generator[method], generator, arg);
839
+ if ("throw" !== record.type) {
840
+ var result = record.arg,
841
+ value = result.value;
842
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
843
+ invoke("next", value, resolve, reject);
844
+ }, function (err) {
845
+ invoke("throw", err, resolve, reject);
846
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
847
+ result.value = unwrapped, resolve(result);
848
+ }, function (error) {
849
+ return invoke("throw", error, resolve, reject);
850
+ });
851
+ }
852
+ reject(record.arg);
853
+ }
854
+ var previousPromise;
855
+ defineProperty(this, "_invoke", {
856
+ value: function (method, arg) {
857
+ function callInvokeWithMethodAndArg() {
858
+ return new PromiseImpl(function (resolve, reject) {
859
+ invoke(method, arg, resolve, reject);
860
+ });
861
+ }
862
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
863
+ }
864
+ });
865
+ }
866
+ function makeInvokeMethod(innerFn, self, context) {
867
+ var state = "suspendedStart";
868
+ return function (method, arg) {
869
+ if ("executing" === state) throw new Error("Generator is already running");
870
+ if ("completed" === state) {
871
+ if ("throw" === method) throw arg;
872
+ return doneResult();
873
+ }
874
+ for (context.method = method, context.arg = arg;;) {
875
+ var delegate = context.delegate;
876
+ if (delegate) {
877
+ var delegateResult = maybeInvokeDelegate(delegate, context);
878
+ if (delegateResult) {
879
+ if (delegateResult === ContinueSentinel) continue;
880
+ return delegateResult;
881
+ }
882
+ }
883
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
884
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
885
+ context.dispatchException(context.arg);
886
+ } else "return" === context.method && context.abrupt("return", context.arg);
887
+ state = "executing";
888
+ var record = tryCatch(innerFn, self, context);
889
+ if ("normal" === record.type) {
890
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
891
+ return {
892
+ value: record.arg,
893
+ done: context.done
894
+ };
895
+ }
896
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
897
+ }
898
+ };
899
+ }
900
+ function maybeInvokeDelegate(delegate, context) {
901
+ var methodName = context.method,
902
+ method = delegate.iterator[methodName];
903
+ 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;
904
+ var record = tryCatch(method, delegate.iterator, context.arg);
905
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
906
+ var info = record.arg;
907
+ 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);
908
+ }
909
+ function pushTryEntry(locs) {
910
+ var entry = {
911
+ tryLoc: locs[0]
912
+ };
913
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
914
+ }
915
+ function resetTryEntry(entry) {
916
+ var record = entry.completion || {};
917
+ record.type = "normal", delete record.arg, entry.completion = record;
918
+ }
919
+ function Context(tryLocsList) {
920
+ this.tryEntries = [{
921
+ tryLoc: "root"
922
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
923
+ }
924
+ function values(iterable) {
925
+ if (iterable) {
926
+ var iteratorMethod = iterable[iteratorSymbol];
927
+ if (iteratorMethod) return iteratorMethod.call(iterable);
928
+ if ("function" == typeof iterable.next) return iterable;
929
+ if (!isNaN(iterable.length)) {
930
+ var i = -1,
931
+ next = function next() {
932
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
933
+ return next.value = undefined, next.done = !0, next;
934
+ };
935
+ return next.next = next;
936
+ }
937
+ }
938
+ return {
939
+ next: doneResult
940
+ };
941
+ }
942
+ function doneResult() {
943
+ return {
944
+ value: undefined,
945
+ done: !0
946
+ };
947
+ }
948
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
949
+ value: GeneratorFunctionPrototype,
950
+ configurable: !0
951
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
952
+ value: GeneratorFunction,
953
+ configurable: !0
954
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
955
+ var ctor = "function" == typeof genFun && genFun.constructor;
956
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
957
+ }, exports.mark = function (genFun) {
958
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
959
+ }, exports.awrap = function (arg) {
960
+ return {
961
+ __await: arg
962
+ };
963
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
964
+ return this;
965
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
966
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
967
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
968
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
969
+ return result.done ? result.value : iter.next();
970
+ });
971
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
972
+ return this;
973
+ }), define(Gp, "toString", function () {
974
+ return "[object Generator]";
975
+ }), exports.keys = function (val) {
976
+ var object = Object(val),
977
+ keys = [];
978
+ for (var key in object) keys.push(key);
979
+ return keys.reverse(), function next() {
980
+ for (; keys.length;) {
981
+ var key = keys.pop();
982
+ if (key in object) return next.value = key, next.done = !1, next;
983
+ }
984
+ return next.done = !0, next;
985
+ };
986
+ }, exports.values = values, Context.prototype = {
987
+ constructor: Context,
988
+ reset: function (skipTempReset) {
989
+ 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);
990
+ },
991
+ stop: function () {
992
+ this.done = !0;
993
+ var rootRecord = this.tryEntries[0].completion;
994
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
995
+ return this.rval;
996
+ },
997
+ dispatchException: function (exception) {
998
+ if (this.done) throw exception;
999
+ var context = this;
1000
+ function handle(loc, caught) {
1001
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1002
+ }
1003
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1004
+ var entry = this.tryEntries[i],
1005
+ record = entry.completion;
1006
+ if ("root" === entry.tryLoc) return handle("end");
1007
+ if (entry.tryLoc <= this.prev) {
1008
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1009
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1010
+ if (hasCatch && hasFinally) {
1011
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1012
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1013
+ } else if (hasCatch) {
1014
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1015
+ } else {
1016
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1017
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1018
+ }
1019
+ }
1020
+ }
1021
+ },
1022
+ abrupt: function (type, arg) {
1023
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1024
+ var entry = this.tryEntries[i];
1025
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1026
+ var finallyEntry = entry;
1027
+ break;
1028
+ }
1029
+ }
1030
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1031
+ var record = finallyEntry ? finallyEntry.completion : {};
1032
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1033
+ },
1034
+ complete: function (record, afterLoc) {
1035
+ if ("throw" === record.type) throw record.arg;
1036
+ 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;
1037
+ },
1038
+ finish: function (finallyLoc) {
1039
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1040
+ var entry = this.tryEntries[i];
1041
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1042
+ }
1043
+ },
1044
+ catch: function (tryLoc) {
1045
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1046
+ var entry = this.tryEntries[i];
1047
+ if (entry.tryLoc === tryLoc) {
1048
+ var record = entry.completion;
1049
+ if ("throw" === record.type) {
1050
+ var thrown = record.arg;
1051
+ resetTryEntry(entry);
1052
+ }
1053
+ return thrown;
1054
+ }
1055
+ }
1056
+ throw new Error("illegal catch attempt");
1057
+ },
1058
+ delegateYield: function (iterable, resultName, nextLoc) {
1059
+ return this.delegate = {
1060
+ iterator: values(iterable),
1061
+ resultName: resultName,
1062
+ nextLoc: nextLoc
1063
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1064
+ }
1065
+ }, exports;
1066
+ }
1067
+
1068
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1069
+ try {
1070
+ var info = gen[key](arg);
1071
+ var value = info.value;
1072
+ } catch (error) {
1073
+ reject(error);
1074
+ return;
1075
+ }
1076
+ if (info.done) {
1077
+ resolve(value);
1078
+ } else {
1079
+ Promise.resolve(value).then(_next, _throw);
1080
+ }
1081
+ }
1082
+ function _asyncToGenerator(fn) {
1083
+ return function () {
1084
+ var self = this,
1085
+ args = arguments;
1086
+ return new Promise(function (resolve, reject) {
1087
+ var gen = fn.apply(self, args);
1088
+ function _next(value) {
1089
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1090
+ }
1091
+ function _throw(err) {
1092
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1093
+ }
1094
+ _next(undefined);
1095
+ });
1096
+ };
1097
+ }
1098
+
1099
+ // TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
1100
+ var ValApi = /*#__PURE__*/function () {
1101
+ function ValApi(host) {
1102
+ index._classCallCheck(this, ValApi);
1103
+ this.host = host;
1104
+ }
1105
+ index._createClass(ValApi, [{
1106
+ key: "getDisableUrl",
1107
+ value: function getDisableUrl() {
1108
+ return "".concat(this.host, "/disable");
1109
+ }
1110
+ }, {
1111
+ key: "postPatches",
1112
+ value: function postPatches(moduleId, patches, commit, headers) {
1113
+ var params = "";
1114
+ if (commit) {
1115
+ var p = new URLSearchParams();
1116
+ p.set("commit", commit);
1117
+ params = "?".concat(p.toString());
1118
+ }
1119
+ return fetch("".concat(this.host, "/patches/~").concat(moduleId).concat(params), {
1120
+ headers: headers || {
1121
+ "Content-Type": "application/json"
1122
+ },
1123
+ method: "POST",
1124
+ body: JSON.stringify(patches)
1125
+ }).then(parse);
1126
+ }
1127
+ }, {
1128
+ key: "getSession",
1129
+ value: function getSession() {
1130
+ return fetch("".concat(this.host, "/session")).then(parse);
1131
+ }
1132
+ }, {
1133
+ key: "getModules",
1134
+ value: function getModules(_ref) {
1135
+ var _ref$patch = _ref.patch,
1136
+ patch = _ref$patch === void 0 ? false : _ref$patch,
1137
+ _ref$includeSchema = _ref.includeSchema,
1138
+ includeSchema = _ref$includeSchema === void 0 ? false : _ref$includeSchema,
1139
+ _ref$includeSource = _ref.includeSource,
1140
+ includeSource = _ref$includeSource === void 0 ? false : _ref$includeSource,
1141
+ _ref$treePath = _ref.treePath,
1142
+ treePath = _ref$treePath === void 0 ? "/" : _ref$treePath,
1143
+ headers = _ref.headers;
1144
+ var params = new URLSearchParams();
1145
+ params.set("patch", patch.toString());
1146
+ params.set("schema", includeSchema.toString());
1147
+ params.set("source", includeSource.toString());
1148
+ return fetch("".concat(this.host, "/tree/~").concat(treePath, "?").concat(params.toString()), {
1149
+ headers: headers
1150
+ }).then(parse);
1151
+ }
1152
+ }]);
1153
+ return ValApi;
1154
+ }();
1155
+
1156
+ // TODO: validate
1157
+ function parse(_x) {
1158
+ return _parse.apply(this, arguments);
1159
+ }
1160
+ function _parse() {
1161
+ _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
1162
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1163
+ while (1) switch (_context.prev = _context.next) {
1164
+ case 0:
1165
+ _context.prev = 0;
1166
+ if (!res.ok) {
1167
+ _context.next = 9;
1168
+ break;
1169
+ }
1170
+ _context.t0 = result.result;
1171
+ _context.next = 5;
1172
+ return res.json();
1173
+ case 5:
1174
+ _context.t1 = _context.sent;
1175
+ return _context.abrupt("return", _context.t0.ok.call(_context.t0, _context.t1));
1176
+ case 9:
1177
+ _context.t2 = result.result;
1178
+ _context.t3 = res.status;
1179
+ _context.next = 13;
1180
+ return res.text();
1181
+ case 13:
1182
+ _context.t4 = _context.sent;
1183
+ _context.t5 = {
1184
+ statusCode: _context.t3,
1185
+ message: _context.t4
1186
+ };
1187
+ return _context.abrupt("return", _context.t2.err.call(_context.t2, _context.t5));
1188
+ case 16:
1189
+ _context.next = 21;
1190
+ break;
1191
+ case 18:
1192
+ _context.prev = 18;
1193
+ _context.t6 = _context["catch"](0);
1194
+ return _context.abrupt("return", result.err({
1195
+ message: _context.t6 instanceof Error ? _context.t6.message : "Unknown error"
1196
+ }));
1197
+ case 21:
1198
+ case "end":
1199
+ return _context.stop();
1200
+ }
1201
+ }, _callee, null, [[0, 18]]);
1202
+ }));
1203
+ return _parse.apply(this, arguments);
1204
+ }
1205
+
635
1206
  var Internal = {
636
- convertImageSource: SelectorProxy.convertImageSource,
637
- getSchema: SelectorProxy.getSchema,
638
- getValPath: SelectorProxy.getValPath,
1207
+ convertFileSource: index.convertFileSource,
1208
+ getSchema: index.getSchema,
1209
+ getValPath: index.getValPath,
639
1210
  getVal: getVal,
640
- getRawSource: ops.getRawSource,
1211
+ getSource: ops.getSource,
641
1212
  resolvePath: ops.resolvePath,
642
1213
  splitModuleIdAndModulePath: ops.splitModuleIdAndModulePath,
643
- fetchVal: fetchVal,
644
- isVal: SelectorProxy.isVal
1214
+ isVal: index.isVal,
1215
+ createValPathOfItem: ops.createValPathOfItem,
1216
+ createPatchJSONPath: function createPatchJSONPath(modulePath) {
1217
+ return "/".concat(modulePath.split(".").map(function (segment) {
1218
+ return JSON.parse(segment);
1219
+ }).join("/"));
1220
+ },
1221
+ /**
1222
+ * Enables draft mode: updates all Val modules with patches
1223
+ */
1224
+ VAL_DRAFT_MODE_COOKIE: "val_draft_mode",
1225
+ /**
1226
+ * Enables Val: show the overlay / menu
1227
+ */
1228
+ VAL_ENABLE_COOKIE_NAME: "val_enable",
1229
+ VAL_STATE_COOKIE: "val_state",
1230
+ VAL_SESSION_COOKIE: "val_session"
645
1231
  };
646
1232
 
647
- exports.FILE_REF_PROP = SelectorProxy.FILE_REF_PROP;
648
- exports.GenericSelector = SelectorProxy.GenericSelector;
649
- exports.Schema = SelectorProxy.Schema;
650
- exports.VAL_EXTENSION = SelectorProxy.VAL_EXTENSION;
1233
+ exports.FILE_REF_PROP = index.FILE_REF_PROP;
1234
+ exports.GenericSelector = index.GenericSelector;
1235
+ exports.Schema = index.Schema;
1236
+ exports.VAL_EXTENSION = index.VAL_EXTENSION;
651
1237
  exports.expr = expr_dist_valbuildCoreExpr.index;
652
1238
  exports.Internal = Internal;
1239
+ exports.ValApi = ValApi;
653
1240
  exports.derefPatch = derefPatch;
654
1241
  exports.initVal = initVal;