@valbuild/core 0.15.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 +38 -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/patch/index.d.ts +1 -1
- package/dist/declarations/src/patch/util.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +3 -2
- package/dist/declarations/src/schema/boolean.d.ts +3 -2
- package/dist/declarations/src/schema/image.d.ts +4 -3
- package/dist/declarations/src/schema/index.d.ts +8 -7
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/literal.d.ts +3 -2
- package/dist/declarations/src/schema/number.d.ts +3 -2
- package/dist/declarations/src/schema/object.d.ts +3 -2
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/richtext.d.ts +3 -2
- package/dist/declarations/src/schema/string.d.ts +3 -2
- package/dist/declarations/src/schema/union.d.ts +4 -2
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -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/index-369caccf.esm.js +550 -0
- package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
- package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
- package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
- package/dist/index-8706c87e.cjs.prod.js +582 -0
- package/dist/index-a6e642dd.cjs.dev.js +582 -0
- package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
- package/dist/ops-23a5abb2.esm.js +671 -0
- package/dist/ops-f3015423.cjs.dev.js +684 -0
- package/dist/valbuild-core.cjs.dev.js +640 -633
- package/dist/valbuild-core.cjs.prod.js +640 -633
- package/dist/valbuild-core.esm.js +578 -572
- 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 -2
- package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
- package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
- package/patch/dist/valbuild-core-patch.esm.js +12 -4
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/expr/repl.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 +51 -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/index.ts +1 -0
- package/src/patch/json.test.ts +0 -1
- package/src/patch/util.ts +7 -0
- package/src/schema/array.ts +45 -4
- package/src/schema/boolean.ts +14 -3
- package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
- package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
- package/src/schema/image.ts +66 -6
- package/src/schema/index.ts +37 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/literal.ts +24 -3
- package/src/schema/number.ts +14 -3
- package/src/schema/object.ts +50 -7
- package/src/schema/record.ts +103 -0
- package/src/schema/richtext.ts +63 -3
- package/src/schema/string.ts +14 -3
- package/src/schema/union.ts +4 -3
- package/src/schema/validation/ValidationError.ts +16 -0
- package/src/schema/validation/ValidationFix.ts +6 -0
- package/src/schema/validation.test.ts +291 -0
- package/src/selector/SelectorProxy.ts +16 -16
- 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/createClass-012eebbf.esm.js +0 -109
- package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
- package/dist/createClass-de7426aa.cjs.prod.js +0 -116
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -21
- package/dist/declarations/src/schema/oneOf.d.ts +0 -22
- package/dist/ops-6fae92a1.esm.js +0 -12
- package/dist/ops-87cdbafc.cjs.dev.js +0 -14
- package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -1,496 +1,8 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper,
|
2
|
-
export { F as FILE_REF_PROP,
|
3
|
-
import {
|
4
|
-
|
5
|
-
import {
|
6
|
-
|
7
|
-
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
8
|
-
_inherits(ObjectSchema, _Schema);
|
9
|
-
var _super = _createSuper(ObjectSchema);
|
10
|
-
function ObjectSchema(items) {
|
11
|
-
var _this;
|
12
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
13
|
-
_classCallCheck(this, ObjectSchema);
|
14
|
-
_this = _super.call(this);
|
15
|
-
_this.items = items;
|
16
|
-
_this.opt = opt;
|
17
|
-
return _this;
|
18
|
-
}
|
19
|
-
_createClass(ObjectSchema, [{
|
20
|
-
key: "validate",
|
21
|
-
value: function validate(src) {
|
22
|
-
throw new Error("Method not implemented.");
|
23
|
-
}
|
24
|
-
}, {
|
25
|
-
key: "match",
|
26
|
-
value: function match(src) {
|
27
|
-
if (this.opt && (src === null || src === undefined)) {
|
28
|
-
return true;
|
29
|
-
}
|
30
|
-
if (!src) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
|
34
|
-
// TODO: checks all props
|
35
|
-
|
36
|
-
return _typeof(src) === "object" && !Array.isArray(src);
|
37
|
-
}
|
38
|
-
}, {
|
39
|
-
key: "optional",
|
40
|
-
value: function optional() {
|
41
|
-
return new ObjectSchema(this.items, true);
|
42
|
-
}
|
43
|
-
}, {
|
44
|
-
key: "serialize",
|
45
|
-
value: function serialize() {
|
46
|
-
return {
|
47
|
-
type: "object",
|
48
|
-
items: Object.fromEntries(Object.entries(this.items).map(function (_ref) {
|
49
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
50
|
-
key = _ref2[0],
|
51
|
-
schema = _ref2[1];
|
52
|
-
return [key, schema.serialize()];
|
53
|
-
})),
|
54
|
-
opt: this.opt
|
55
|
-
};
|
56
|
-
}
|
57
|
-
}]);
|
58
|
-
return ObjectSchema;
|
59
|
-
}(Schema);
|
60
|
-
var object = function object(schema) {
|
61
|
-
return new ObjectSchema(schema);
|
62
|
-
};
|
63
|
-
|
64
|
-
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
65
|
-
_inherits(ArraySchema, _Schema);
|
66
|
-
var _super = _createSuper(ArraySchema);
|
67
|
-
function ArraySchema(item) {
|
68
|
-
var _this;
|
69
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
70
|
-
_classCallCheck(this, ArraySchema);
|
71
|
-
_this = _super.call(this);
|
72
|
-
_this.item = item;
|
73
|
-
_this.opt = opt;
|
74
|
-
return _this;
|
75
|
-
}
|
76
|
-
_createClass(ArraySchema, [{
|
77
|
-
key: "validate",
|
78
|
-
value: function validate(src) {
|
79
|
-
throw new Error("Method not implemented.");
|
80
|
-
}
|
81
|
-
}, {
|
82
|
-
key: "match",
|
83
|
-
value: function match(src) {
|
84
|
-
if (this.opt && (src === null || src === undefined)) {
|
85
|
-
return true;
|
86
|
-
}
|
87
|
-
if (!src) {
|
88
|
-
return false;
|
89
|
-
}
|
90
|
-
|
91
|
-
// TODO: checks all items
|
92
|
-
return _typeof(src) === "object" && Array.isArray(src);
|
93
|
-
}
|
94
|
-
}, {
|
95
|
-
key: "optional",
|
96
|
-
value: function optional() {
|
97
|
-
return new ArraySchema(this.item, true);
|
98
|
-
}
|
99
|
-
}, {
|
100
|
-
key: "serialize",
|
101
|
-
value: function serialize() {
|
102
|
-
return {
|
103
|
-
type: "array",
|
104
|
-
item: this.item.serialize(),
|
105
|
-
opt: this.opt
|
106
|
-
};
|
107
|
-
}
|
108
|
-
}]);
|
109
|
-
return ArraySchema;
|
110
|
-
}(Schema);
|
111
|
-
var array = function array(schema) {
|
112
|
-
return new ArraySchema(schema);
|
113
|
-
};
|
114
|
-
|
115
|
-
var I18nSchema = /*#__PURE__*/function (_Schema) {
|
116
|
-
_inherits(I18nSchema, _Schema);
|
117
|
-
var _super = _createSuper(I18nSchema);
|
118
|
-
function I18nSchema(locales, item) {
|
119
|
-
var _this;
|
120
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
121
|
-
_classCallCheck(this, I18nSchema);
|
122
|
-
_this = _super.call(this);
|
123
|
-
_this.locales = locales;
|
124
|
-
_this.item = item;
|
125
|
-
_this.opt = opt;
|
126
|
-
return _this;
|
127
|
-
}
|
128
|
-
_createClass(I18nSchema, [{
|
129
|
-
key: "validate",
|
130
|
-
value: function validate(src) {
|
131
|
-
throw new Error("Method not implemented.");
|
132
|
-
}
|
133
|
-
}, {
|
134
|
-
key: "match",
|
135
|
-
value: function match(src) {
|
136
|
-
throw new Error("Method not implemented.");
|
137
|
-
}
|
138
|
-
}, {
|
139
|
-
key: "optional",
|
140
|
-
value: function optional() {
|
141
|
-
return new I18nSchema(this.locales, this.item, true);
|
142
|
-
}
|
143
|
-
}, {
|
144
|
-
key: "serialize",
|
145
|
-
value: function serialize() {
|
146
|
-
return {
|
147
|
-
type: "i18n",
|
148
|
-
item: this.item.serialize(),
|
149
|
-
locales: this.locales,
|
150
|
-
opt: this.opt
|
151
|
-
};
|
152
|
-
}
|
153
|
-
}]);
|
154
|
-
return I18nSchema;
|
155
|
-
}(Schema);
|
156
|
-
var i18n$1 = function i18n(locales) {
|
157
|
-
return function (schema) {
|
158
|
-
return new I18nSchema(locales, schema);
|
159
|
-
};
|
160
|
-
};
|
161
|
-
|
162
|
-
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
163
|
-
_inherits(UnionSchema, _Schema);
|
164
|
-
var _super = _createSuper(UnionSchema);
|
165
|
-
function UnionSchema(key, items) {
|
166
|
-
var _this;
|
167
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
168
|
-
_classCallCheck(this, UnionSchema);
|
169
|
-
_this = _super.call(this);
|
170
|
-
_this.key = key;
|
171
|
-
_this.items = items;
|
172
|
-
_this.opt = opt;
|
173
|
-
return _this;
|
174
|
-
}
|
175
|
-
_createClass(UnionSchema, [{
|
176
|
-
key: "validate",
|
177
|
-
value: function validate(src) {
|
178
|
-
throw new Error("Method not implemented.");
|
179
|
-
}
|
180
|
-
}, {
|
181
|
-
key: "match",
|
182
|
-
value: function match(src) {
|
183
|
-
throw new Error("Method not implemented.");
|
184
|
-
}
|
185
|
-
}, {
|
186
|
-
key: "optional",
|
187
|
-
value: function optional() {
|
188
|
-
throw new Error("Method not implemented.");
|
189
|
-
}
|
190
|
-
}, {
|
191
|
-
key: "serialize",
|
192
|
-
value: function serialize() {
|
193
|
-
return {
|
194
|
-
type: "union",
|
195
|
-
key: this.key,
|
196
|
-
items: this.items.map(function (o) {
|
197
|
-
return o.serialize();
|
198
|
-
}),
|
199
|
-
opt: this.opt
|
200
|
-
};
|
201
|
-
}
|
202
|
-
}]);
|
203
|
-
return UnionSchema;
|
204
|
-
}(Schema);
|
205
|
-
var union = function union(key) {
|
206
|
-
for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
207
|
-
objects[_key - 1] = arguments[_key];
|
208
|
-
}
|
209
|
-
return new UnionSchema(key, objects);
|
210
|
-
};
|
211
|
-
|
212
|
-
var OneOfSchema = /*#__PURE__*/function (_Schema) {
|
213
|
-
_inherits(OneOfSchema, _Schema);
|
214
|
-
var _super = _createSuper(OneOfSchema);
|
215
|
-
function OneOfSchema(selector) {
|
216
|
-
var _this;
|
217
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
218
|
-
_classCallCheck(this, OneOfSchema);
|
219
|
-
_this = _super.call(this);
|
220
|
-
_this.selector = selector;
|
221
|
-
_this.opt = opt;
|
222
|
-
return _this;
|
223
|
-
}
|
224
|
-
_createClass(OneOfSchema, [{
|
225
|
-
key: "validate",
|
226
|
-
value: function validate(src) {
|
227
|
-
throw new Error("Method not implemented.");
|
228
|
-
}
|
229
|
-
}, {
|
230
|
-
key: "match",
|
231
|
-
value: function match(src) {
|
232
|
-
throw new Error("Method not implemented.");
|
233
|
-
}
|
234
|
-
}, {
|
235
|
-
key: "optional",
|
236
|
-
value: function optional() {
|
237
|
-
return new OneOfSchema(this.selector, true);
|
238
|
-
}
|
239
|
-
}, {
|
240
|
-
key: "serialize",
|
241
|
-
value: function serialize() {
|
242
|
-
var path = getValPath(this.selector);
|
243
|
-
if (!path) {
|
244
|
-
throw new Error("Cannot serialize oneOf schema with empty selector. Make sure a Val module is used.");
|
245
|
-
}
|
246
|
-
return {
|
247
|
-
type: "oneOf",
|
248
|
-
selector: path,
|
249
|
-
opt: this.opt
|
250
|
-
};
|
251
|
-
}
|
252
|
-
}]);
|
253
|
-
return OneOfSchema;
|
254
|
-
}(Schema);
|
255
|
-
var oneOf = function oneOf(valModule) {
|
256
|
-
return new OneOfSchema(valModule);
|
257
|
-
};
|
258
|
-
|
259
|
-
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
260
|
-
_inherits(RichTextSchema, _Schema);
|
261
|
-
var _super = _createSuper(RichTextSchema);
|
262
|
-
function RichTextSchema() {
|
263
|
-
var _this;
|
264
|
-
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
265
|
-
_classCallCheck(this, RichTextSchema);
|
266
|
-
_this = _super.call(this);
|
267
|
-
_this.opt = opt;
|
268
|
-
return _this;
|
269
|
-
}
|
270
|
-
_createClass(RichTextSchema, [{
|
271
|
-
key: "validate",
|
272
|
-
value: function validate(src) {
|
273
|
-
throw new Error("Method not implemented.");
|
274
|
-
}
|
275
|
-
}, {
|
276
|
-
key: "match",
|
277
|
-
value: function match(src) {
|
278
|
-
// TODO:
|
279
|
-
return true;
|
280
|
-
}
|
281
|
-
}, {
|
282
|
-
key: "optional",
|
283
|
-
value: function optional() {
|
284
|
-
return new RichTextSchema(true);
|
285
|
-
}
|
286
|
-
}, {
|
287
|
-
key: "serialize",
|
288
|
-
value: function serialize() {
|
289
|
-
return {
|
290
|
-
type: "richtext",
|
291
|
-
opt: this.opt
|
292
|
-
};
|
293
|
-
}
|
294
|
-
}]);
|
295
|
-
return RichTextSchema;
|
296
|
-
}(Schema);
|
297
|
-
var richtext$1 = function richtext() {
|
298
|
-
return new RichTextSchema();
|
299
|
-
};
|
300
|
-
|
301
|
-
function content(
|
302
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
303
|
-
id,
|
304
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
305
|
-
schema,
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
307
|
-
source) {
|
308
|
-
return newSelectorProxy(source, id, schema);
|
309
|
-
}
|
310
|
-
function getRawSource(valModule) {
|
311
|
-
var sourceOrExpr = valModule[SourceOrExpr];
|
312
|
-
if (sourceOrExpr instanceof Expr) {
|
313
|
-
throw Error("Cannot get raw source of an Expr");
|
314
|
-
}
|
315
|
-
var source = sourceOrExpr;
|
316
|
-
return source;
|
317
|
-
}
|
318
|
-
function splitModuleIdAndModulePath(path) {
|
319
|
-
return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
|
320
|
-
}
|
321
|
-
function isObjectSchema(schema) {
|
322
|
-
return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
323
|
-
}
|
324
|
-
function isArraySchema(schema) {
|
325
|
-
return schema instanceof ArraySchema || _typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
326
|
-
}
|
327
|
-
function isI18nSchema(schema) {
|
328
|
-
return schema instanceof I18nSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "i18n";
|
329
|
-
}
|
330
|
-
function isUnionSchema(schema) {
|
331
|
-
return schema instanceof UnionSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "union";
|
332
|
-
}
|
333
|
-
|
334
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
335
|
-
function isRichTextSchema(schema) {
|
336
|
-
return schema instanceof RichTextSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
|
337
|
-
}
|
338
|
-
function isImageSchema(schema) {
|
339
|
-
return schema instanceof ImageSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "image";
|
340
|
-
}
|
341
|
-
function resolvePath(path, valModule, schema) {
|
342
|
-
var parts = parsePath(path);
|
343
|
-
var origParts = _toConsumableArray(parts);
|
344
|
-
var resolvedSchema = schema;
|
345
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
346
|
-
var resolvedSource = valModule;
|
347
|
-
var _loop = function _loop() {
|
348
|
-
var part = parts.shift();
|
349
|
-
if (part === undefined) {
|
350
|
-
throw Error("Unexpected undefined part");
|
351
|
-
}
|
352
|
-
if (isArraySchema(resolvedSchema)) {
|
353
|
-
if (Number.isNaN(Number(part))) {
|
354
|
-
throw Error("Invalid path: array schema ".concat(resolvedSchema, " must have ").concat(part, " a number as path"));
|
355
|
-
}
|
356
|
-
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
357
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
|
358
|
-
}
|
359
|
-
if (!resolvedSource[part]) {
|
360
|
-
var _resolvedSource;
|
361
|
-
throw Error("Invalid path: array source (length: ".concat((_resolvedSource = resolvedSource) === null || _resolvedSource === void 0 ? void 0 : _resolvedSource.length, ") did not have index ").concat(part, " from path: ").concat(path));
|
362
|
-
}
|
363
|
-
resolvedSource = resolvedSource[part];
|
364
|
-
resolvedSchema = resolvedSchema.item;
|
365
|
-
} else if (isObjectSchema(resolvedSchema)) {
|
366
|
-
if (_typeof(resolvedSource) !== "object") {
|
367
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
368
|
-
}
|
369
|
-
if (!resolvedSource[part]) {
|
370
|
-
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
371
|
-
}
|
372
|
-
resolvedSource = resolvedSource[part];
|
373
|
-
resolvedSchema = resolvedSchema.items[part];
|
374
|
-
} else if (isI18nSchema(resolvedSchema)) {
|
375
|
-
if (!resolvedSchema.locales.includes(part)) {
|
376
|
-
throw Error("Invalid path: i18n schema ".concat(resolvedSchema, " supports locales ").concat(resolvedSchema.locales.join(", "), ", but found: ").concat(part));
|
377
|
-
}
|
378
|
-
if (!Object.keys(resolvedSource).includes(part)) {
|
379
|
-
throw Error("Schema type error: expected source to be type of i18n with locale ".concat(part, ", but got ").concat(JSON.stringify(Object.keys(resolvedSource))));
|
380
|
-
}
|
381
|
-
resolvedSource = resolvedSource[part];
|
382
|
-
resolvedSchema = resolvedSchema.item;
|
383
|
-
} else if (isImageSchema(resolvedSchema)) {
|
384
|
-
return {
|
385
|
-
v: {
|
386
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
387
|
-
return JSON.stringify(p);
|
388
|
-
}).join("."),
|
389
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
390
|
-
schema: resolvedSchema,
|
391
|
-
source: resolvedSource
|
392
|
-
}
|
393
|
-
};
|
394
|
-
} else if (isUnionSchema(resolvedSchema)) {
|
395
|
-
var _key = resolvedSchema.key;
|
396
|
-
var keyValue = resolvedSource[_key];
|
397
|
-
if (!keyValue) {
|
398
|
-
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
399
|
-
}
|
400
|
-
var schemaOfUnionKey = resolvedSchema.items.find(
|
401
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
402
|
-
function (child) {
|
403
|
-
var _child$items, _child$items$_key;
|
404
|
-
return (child === null || child === void 0 ? void 0 : (_child$items = child.items) === null || _child$items === void 0 ? void 0 : (_child$items$_key = _child$items[_key]) === null || _child$items$_key === void 0 ? void 0 : _child$items$_key.value) === keyValue;
|
405
|
-
});
|
406
|
-
if (!schemaOfUnionKey) {
|
407
|
-
throw Error("Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key, " of value ").concat(keyValue, " in path: ").concat(path));
|
408
|
-
}
|
409
|
-
resolvedSchema = schemaOfUnionKey.items[part];
|
410
|
-
resolvedSource = resolvedSource[part];
|
411
|
-
} else if (isRichTextSchema(resolvedSchema)) {
|
412
|
-
return {
|
413
|
-
v: {
|
414
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
415
|
-
return JSON.stringify(p);
|
416
|
-
}).join("."),
|
417
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
418
|
-
schema: resolvedSchema,
|
419
|
-
source: resolvedSource
|
420
|
-
}
|
421
|
-
};
|
422
|
-
} else {
|
423
|
-
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
424
|
-
}
|
425
|
-
};
|
426
|
-
while (parts.length > 0) {
|
427
|
-
var _ret = _loop();
|
428
|
-
if (_typeof(_ret) === "object") return _ret.v;
|
429
|
-
}
|
430
|
-
if (parts.length > 0) {
|
431
|
-
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|
432
|
-
}
|
433
|
-
return {
|
434
|
-
path: path,
|
435
|
-
schema: resolvedSchema,
|
436
|
-
source: resolvedSource
|
437
|
-
};
|
438
|
-
}
|
439
|
-
function parsePath(input) {
|
440
|
-
var result = [];
|
441
|
-
var i = 0;
|
442
|
-
while (i < input.length) {
|
443
|
-
var part = "";
|
444
|
-
if (input[i] === '"') {
|
445
|
-
// Parse a quoted string
|
446
|
-
i++;
|
447
|
-
while (i < input.length && input[i] !== '"') {
|
448
|
-
if (input[i] === "\\" && input[i + 1] === '"') {
|
449
|
-
// Handle escaped double quotes
|
450
|
-
part += '"';
|
451
|
-
i++;
|
452
|
-
} else {
|
453
|
-
part += input[i];
|
454
|
-
}
|
455
|
-
i++;
|
456
|
-
}
|
457
|
-
if (input[i] !== '"') {
|
458
|
-
var _input$i;
|
459
|
-
throw new Error("Invalid input (".concat(JSON.stringify(input), "): Missing closing double quote: ").concat((_input$i = input[i]) !== null && _input$i !== void 0 ? _input$i : "at end of string", " (char: ").concat(i, "; length: ").concat(input.length, ")"));
|
460
|
-
}
|
461
|
-
} else {
|
462
|
-
// Parse a regular string
|
463
|
-
while (i < input.length && input[i] !== ".") {
|
464
|
-
part += input[i];
|
465
|
-
i++;
|
466
|
-
}
|
467
|
-
}
|
468
|
-
if (part !== "") {
|
469
|
-
result.push(part);
|
470
|
-
}
|
471
|
-
i++;
|
472
|
-
}
|
473
|
-
return result;
|
474
|
-
}
|
475
|
-
|
476
|
-
/**
|
477
|
-
* I18n sources cannot have nested remote sources.
|
478
|
-
*/
|
479
|
-
|
480
|
-
/**
|
481
|
-
* An i18n source is a map of locales to sources.
|
482
|
-
*
|
483
|
-
* 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
|
484
|
-
*
|
485
|
-
*/
|
486
|
-
|
487
|
-
function i18n(
|
488
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
489
|
-
locales) {
|
490
|
-
return function (source) {
|
491
|
-
return _objectSpread2(_objectSpread2({}, source), {}, _defineProperty({}, VAL_EXTENSION, "i18n"));
|
492
|
-
};
|
493
|
-
}
|
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';
|
494
6
|
|
495
7
|
var NumberSchema = /*#__PURE__*/function (_Schema) {
|
496
8
|
_inherits(NumberSchema, _Schema);
|
@@ -506,12 +18,21 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
506
18
|
}
|
507
19
|
_createClass(NumberSchema, [{
|
508
20
|
key: "validate",
|
509
|
-
value: function validate(src) {
|
510
|
-
|
21
|
+
value: function validate(path, src) {
|
22
|
+
if (this.opt && (src === null || src === undefined)) {
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
if (typeof src !== "number") {
|
26
|
+
return _defineProperty({}, path, [{
|
27
|
+
message: "Expected 'number', got '".concat(_typeof(src), "'"),
|
28
|
+
value: src
|
29
|
+
}]);
|
30
|
+
}
|
31
|
+
return false;
|
511
32
|
}
|
512
33
|
}, {
|
513
|
-
key: "
|
514
|
-
value: function
|
34
|
+
key: "assert",
|
35
|
+
value: function assert(src) {
|
515
36
|
if (this.opt && (src === null || src === undefined)) {
|
516
37
|
return true;
|
517
38
|
}
|
@@ -552,12 +73,21 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
552
73
|
}
|
553
74
|
_createClass(StringSchema, [{
|
554
75
|
key: "validate",
|
555
|
-
value: function validate(src) {
|
556
|
-
|
76
|
+
value: function validate(path, src) {
|
77
|
+
if (this.opt && (src === null || src === undefined)) {
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
if (typeof src !== "string") {
|
81
|
+
return _defineProperty({}, path, [{
|
82
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
83
|
+
value: src
|
84
|
+
}]);
|
85
|
+
}
|
86
|
+
return false;
|
557
87
|
}
|
558
88
|
}, {
|
559
|
-
key: "
|
560
|
-
value: function
|
89
|
+
key: "assert",
|
90
|
+
value: function assert(src) {
|
561
91
|
if (this.opt && (src === null || src === undefined)) {
|
562
92
|
return true;
|
563
93
|
}
|
@@ -597,12 +127,21 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
|
|
597
127
|
}
|
598
128
|
_createClass(BooleanSchema, [{
|
599
129
|
key: "validate",
|
600
|
-
value: function validate(src) {
|
601
|
-
|
130
|
+
value: function validate(path, src) {
|
131
|
+
if (this.opt && (src === null || src === undefined)) {
|
132
|
+
return false;
|
133
|
+
}
|
134
|
+
if (typeof src !== "boolean") {
|
135
|
+
return _defineProperty({}, path, [{
|
136
|
+
message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
|
137
|
+
value: src
|
138
|
+
}]);
|
139
|
+
}
|
140
|
+
return false;
|
602
141
|
}
|
603
142
|
}, {
|
604
|
-
key: "
|
605
|
-
value: function
|
143
|
+
key: "assert",
|
144
|
+
value: function assert(src) {
|
606
145
|
if (this.opt && (src === null || src === undefined)) {
|
607
146
|
return true;
|
608
147
|
}
|
@@ -642,12 +181,27 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
|
642
181
|
}
|
643
182
|
_createClass(LiteralSchema, [{
|
644
183
|
key: "validate",
|
645
|
-
value: function validate(src) {
|
646
|
-
|
184
|
+
value: function validate(path, src) {
|
185
|
+
if (this.opt && (src === null || src === undefined)) {
|
186
|
+
return false;
|
187
|
+
}
|
188
|
+
if (typeof src !== "string") {
|
189
|
+
return _defineProperty({}, path, [{
|
190
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
191
|
+
value: src
|
192
|
+
}]);
|
193
|
+
}
|
194
|
+
if (src !== this.value) {
|
195
|
+
return _defineProperty({}, path, [{
|
196
|
+
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
197
|
+
value: src
|
198
|
+
}]);
|
199
|
+
}
|
200
|
+
return false;
|
647
201
|
}
|
648
202
|
}, {
|
649
|
-
key: "
|
650
|
-
value: function
|
203
|
+
key: "assert",
|
204
|
+
value: function assert(src) {
|
651
205
|
if (this.opt && (src === null || src === undefined)) {
|
652
206
|
return true;
|
653
207
|
}
|
@@ -674,7 +228,14 @@ var literal = function literal(value) {
|
|
674
228
|
return new LiteralSchema(value);
|
675
229
|
};
|
676
230
|
|
677
|
-
|
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>
|
678
239
|
return {
|
679
240
|
string: string,
|
680
241
|
"boolean": _boolean,
|
@@ -682,34 +243,14 @@ function initSchema(locales) {
|
|
682
243
|
object: object,
|
683
244
|
number: number,
|
684
245
|
union: union,
|
685
|
-
|
246
|
+
// oneOf,
|
686
247
|
richtext: richtext$1,
|
687
248
|
image: image,
|
688
|
-
literal: literal
|
689
|
-
i18n: i18n
|
249
|
+
literal: literal
|
250
|
+
// i18n: i18n(locales),
|
690
251
|
};
|
691
252
|
}
|
692
253
|
|
693
|
-
/**
|
694
|
-
* Remote sources cannot include other remote sources.
|
695
|
-
*/
|
696
|
-
|
697
|
-
var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
|
698
|
-
|
699
|
-
/**
|
700
|
-
* A remote source is a hash that represents a remote object.
|
701
|
-
*
|
702
|
-
* It will be resolved into a ValRemote object.
|
703
|
-
*/
|
704
|
-
|
705
|
-
function remote(ref) {
|
706
|
-
var _ref;
|
707
|
-
return _ref = {}, _defineProperty(_ref, REMOTE_REF_PROP, ref), _defineProperty(_ref, VAL_EXTENSION, "remote"), _ref;
|
708
|
-
}
|
709
|
-
function isRemote(obj) {
|
710
|
-
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";
|
711
|
-
}
|
712
|
-
|
713
254
|
function richtext(data) {
|
714
255
|
if (typeof data === "string") {
|
715
256
|
var _ref;
|
@@ -724,40 +265,55 @@ function richtext(data) {
|
|
724
265
|
return _objectSpread2(_objectSpread2({}, data), {}, _defineProperty({}, VAL_EXTENSION, "richtext"));
|
725
266
|
}
|
726
267
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
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
|
+
// }
|
746
295
|
return {
|
747
296
|
val: {
|
748
297
|
content: content,
|
749
|
-
|
298
|
+
// remote,
|
750
299
|
getPath: getValPath,
|
751
300
|
file: file,
|
752
301
|
richtext: richtext
|
753
302
|
},
|
754
|
-
s: _objectSpread2(
|
755
|
-
i18n: undefined
|
756
|
-
})
|
303
|
+
s: _objectSpread2({}, s)
|
757
304
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
758
305
|
};
|
759
306
|
};
|
760
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
|
+
|
761
317
|
function derefPath(path) {
|
762
318
|
var dereffedPath = [];
|
763
319
|
var referencedPath = null;
|
@@ -869,19 +425,14 @@ function derefPatch(patch, document, ops) {
|
|
869
425
|
});
|
870
426
|
}
|
871
427
|
|
872
|
-
function
|
873
|
-
return Promise.resolve(getVal(selector));
|
874
|
-
}
|
875
|
-
function getVal(selector,
|
876
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
877
|
-
locale) {
|
428
|
+
function getVal(selector) {
|
878
429
|
return newValProxy(serializedValOfSelectorSource(selector));
|
879
430
|
}
|
880
431
|
|
881
432
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
882
433
|
function isArrayOrArraySelector(child) {
|
883
434
|
if (isSelector(child)) {
|
884
|
-
return _typeof(child[
|
435
|
+
return _typeof(child[GetSource]) === "object" && _typeof(child[GetSource]) !== null && Array.isArray(child[GetSource]);
|
885
436
|
}
|
886
437
|
return Array.isArray(child);
|
887
438
|
}
|
@@ -889,7 +440,7 @@ function isArrayOrArraySelector(child) {
|
|
889
440
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
890
441
|
function isObjectOrObjectSelector(child) {
|
891
442
|
if (isSelector(child)) {
|
892
|
-
return _typeof(child[
|
443
|
+
return _typeof(child[GetSource]) === "object" && _typeof(child[GetSource]) !== null && !Array.isArray(child[GetSource]);
|
893
444
|
}
|
894
445
|
return _typeof(child) === "object";
|
895
446
|
}
|
@@ -900,7 +451,7 @@ function serializedValOfSelectorSource(selector) {
|
|
900
451
|
var isArray = isArrayOrArraySelector(child);
|
901
452
|
var isObject = isObjectOrObjectSelector(child);
|
902
453
|
if (isArray) {
|
903
|
-
var array =
|
454
|
+
var array = GetSource in child ? child[GetSource] : child;
|
904
455
|
var valPath = Path in child ? child[Path] : undefined;
|
905
456
|
return {
|
906
457
|
val: array.map(function (item, i) {
|
@@ -910,7 +461,7 @@ function serializedValOfSelectorSource(selector) {
|
|
910
461
|
valPath: valPath
|
911
462
|
};
|
912
463
|
} else if (isObject) {
|
913
|
-
var obj =
|
464
|
+
var obj = GetSource in child ? child[GetSource] : child;
|
914
465
|
var _valPath = Path in child ? child[Path] : undefined;
|
915
466
|
return {
|
916
467
|
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
@@ -924,7 +475,7 @@ function serializedValOfSelectorSource(selector) {
|
|
924
475
|
};
|
925
476
|
} else if (isSelector(child)) {
|
926
477
|
return {
|
927
|
-
val: rec(child[
|
478
|
+
val: rec(child[GetSource]),
|
928
479
|
valPath: child[Path]
|
929
480
|
};
|
930
481
|
} else {
|
@@ -1009,16 +560,471 @@ function hasOwn(obj, prop) {
|
|
1009
560
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
1010
561
|
}
|
1011
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
|
+
|
1012
1003
|
var Internal = {
|
1013
|
-
|
1004
|
+
convertFileSource: convertFileSource,
|
1014
1005
|
getSchema: getSchema,
|
1015
1006
|
getValPath: getValPath,
|
1016
1007
|
getVal: getVal,
|
1017
|
-
|
1008
|
+
getSource: getSource,
|
1018
1009
|
resolvePath: resolvePath,
|
1019
1010
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1020
|
-
|
1021
|
-
|
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"
|
1022
1028
|
};
|
1023
1029
|
|
1024
|
-
export { Internal, derefPatch, initVal };
|
1030
|
+
export { Internal, ValApi, derefPatch, initVal };
|