@valbuild/core 0.61.0 → 0.62.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.
@@ -1,539 +0,0 @@
1
- import { b as _arrayLikeToArray, c as _unsupportedIterableToArray } from './result-b96df128.esm.js';
2
-
3
- function _arrayWithoutHoles(arr) {
4
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
5
- }
6
-
7
- function _iterableToArray(iter) {
8
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
9
- }
10
-
11
- function _nonIterableSpread() {
12
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
13
- }
14
-
15
- function _toConsumableArray(arr) {
16
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
17
- }
18
-
19
- function _typeof(o) {
20
- "@babel/helpers - typeof";
21
-
22
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
23
- return typeof o;
24
- } : function (o) {
25
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
26
- }, _typeof(o);
27
- }
28
-
29
- function toPrimitive(t, r) {
30
- if ("object" != typeof t || !t) return t;
31
- var e = t[Symbol.toPrimitive];
32
- if (void 0 !== e) {
33
- var i = e.call(t, r || "default");
34
- if ("object" != typeof i) return i;
35
- throw new TypeError("@@toPrimitive must return a primitive value.");
36
- }
37
- return ("string" === r ? String : Number)(t);
38
- }
39
-
40
- function toPropertyKey(t) {
41
- var i = toPrimitive(t, "string");
42
- return "symbol" == typeof i ? i : String(i);
43
- }
44
-
45
- function _defineProperty(obj, key, value) {
46
- key = toPropertyKey(key);
47
- if (key in obj) {
48
- Object.defineProperty(obj, key, {
49
- value: value,
50
- enumerable: true,
51
- configurable: true,
52
- writable: true
53
- });
54
- } else {
55
- obj[key] = value;
56
- }
57
- return obj;
58
- }
59
-
60
- function ownKeys(e, r) {
61
- var t = Object.keys(e);
62
- if (Object.getOwnPropertySymbols) {
63
- var o = Object.getOwnPropertySymbols(e);
64
- r && (o = o.filter(function (r) {
65
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
66
- })), t.push.apply(t, o);
67
- }
68
- return t;
69
- }
70
- function _objectSpread2(e) {
71
- for (var r = 1; r < arguments.length; r++) {
72
- var t = null != arguments[r] ? arguments[r] : {};
73
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
74
- _defineProperty(e, r, t[r]);
75
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
76
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
77
- });
78
- }
79
- return e;
80
- }
81
-
82
- function _arrayWithHoles(arr) {
83
- if (Array.isArray(arr)) return arr;
84
- }
85
-
86
- function _iterableToArrayLimit(r, l) {
87
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
88
- if (null != t) {
89
- var e,
90
- n,
91
- i,
92
- u,
93
- a = [],
94
- f = !0,
95
- o = !1;
96
- try {
97
- if (i = (t = t.call(r)).next, 0 === l) {
98
- if (Object(t) !== t) return;
99
- f = !1;
100
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
101
- } catch (r) {
102
- o = !0, n = r;
103
- } finally {
104
- try {
105
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
106
- } finally {
107
- if (o) throw n;
108
- }
109
- }
110
- return a;
111
- }
112
- }
113
-
114
- function _nonIterableRest() {
115
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
116
- }
117
-
118
- function _slicedToArray(arr, i) {
119
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
120
- }
121
-
122
- function _classCallCheck(instance, Constructor) {
123
- if (!(instance instanceof Constructor)) {
124
- throw new TypeError("Cannot call a class as a function");
125
- }
126
- }
127
-
128
- function _defineProperties(target, props) {
129
- for (var i = 0; i < props.length; i++) {
130
- var descriptor = props[i];
131
- descriptor.enumerable = descriptor.enumerable || false;
132
- descriptor.configurable = true;
133
- if ("value" in descriptor) descriptor.writable = true;
134
- Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
135
- }
136
- }
137
- function _createClass(Constructor, protoProps, staticProps) {
138
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
139
- if (staticProps) _defineProperties(Constructor, staticProps);
140
- Object.defineProperty(Constructor, "prototype", {
141
- writable: false
142
- });
143
- return Constructor;
144
- }
145
-
146
- function _getPrototypeOf(o) {
147
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
148
- return o.__proto__ || Object.getPrototypeOf(o);
149
- };
150
- return _getPrototypeOf(o);
151
- }
152
-
153
- function _isNativeReflectConstruct() {
154
- try {
155
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
156
- } catch (t) {}
157
- return (_isNativeReflectConstruct = function () {
158
- return !!t;
159
- })();
160
- }
161
-
162
- function _assertThisInitialized(self) {
163
- if (self === void 0) {
164
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
165
- }
166
- return self;
167
- }
168
-
169
- function _possibleConstructorReturn(self, call) {
170
- if (call && (typeof call === "object" || typeof call === "function")) {
171
- return call;
172
- } else if (call !== void 0) {
173
- throw new TypeError("Derived constructors may only return object or undefined");
174
- }
175
- return _assertThisInitialized(self);
176
- }
177
-
178
- function _callSuper(t, o, e) {
179
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
180
- }
181
-
182
- function _setPrototypeOf(o, p) {
183
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
184
- o.__proto__ = p;
185
- return o;
186
- };
187
- return _setPrototypeOf(o, p);
188
- }
189
-
190
- function _inherits(subClass, superClass) {
191
- if (typeof superClass !== "function" && superClass !== null) {
192
- throw new TypeError("Super expression must either be null or a function");
193
- }
194
- subClass.prototype = Object.create(superClass && superClass.prototype, {
195
- constructor: {
196
- value: subClass,
197
- writable: true,
198
- configurable: true
199
- }
200
- });
201
- Object.defineProperty(subClass, "prototype", {
202
- writable: false
203
- });
204
- if (superClass) _setPrototypeOf(subClass, superClass);
205
- }
206
-
207
- // import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
208
-
209
- // import { SerializedI18nSchema } from "./future/i18n";
210
- // import { SerializedOneOfSchema } from "./future/oneOf";
211
-
212
- var Schema = /*#__PURE__*/function () {
213
- function Schema() {
214
- _classCallCheck(this, Schema);
215
- }
216
- _createClass(Schema, [{
217
- key: "appendValidationError",
218
- value:
219
- // remote(): Src extends RemoteCompatibleSource
220
- // ? Schema<RemoteSource<Src>>
221
- // : never {
222
- // // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
223
- // throw new Error("You need Val Ultra to use .remote()");
224
- // }
225
-
226
- /** MUTATES! since internal and perf sensitive */
227
- function appendValidationError(current, path, message, value) {
228
- if (current) {
229
- if (current[path]) {
230
- current[path].push({
231
- message: message,
232
- value: value
233
- });
234
- } else {
235
- current[path] = [{
236
- message: message,
237
- value: value
238
- }];
239
- }
240
- return current;
241
- } else {
242
- return _defineProperty({}, path, [{
243
- message: message,
244
- value: value
245
- }]);
246
- }
247
- }
248
- }]);
249
- return Schema;
250
- }();
251
-
252
- // TODO: SourceError<"Could not determine type of Schema">
253
-
254
- /**
255
- * @internal
256
- */
257
- var GetSchema = Symbol("GetSchema");
258
- /**
259
- /**
260
- * @internal
261
- */
262
- var Path = Symbol("Path");
263
- /**
264
- * @internal
265
- */
266
- var GetSource = Symbol("GetSource");
267
- /**
268
- * @internal
269
- */
270
- var ValError = Symbol("ValError");
271
- var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
272
- _classCallCheck(this, GenericSelector);
273
- this[Path] = path;
274
- this[GetSource] = valOrExpr;
275
- this[ValError] = error;
276
- this[GetSchema] = schema;
277
- });
278
-
279
- /**
280
- * Use this type to convert types that accepts both Source and Selectors
281
- *
282
- * An example would be where literals are supported like in most higher order functions (e.g. map in array)
283
- **/
284
-
285
- function getSchema(selector) {
286
- return selector[GetSchema];
287
- }
288
-
289
- /* eslint-disable @typescript-eslint/no-unused-vars */
290
-
291
- var Expr = /*#__PURE__*/_createClass(function Expr(span) {
292
- _classCallCheck(this, Expr);
293
- this.span = span;
294
- });
295
- var StringLiteral = /*#__PURE__*/function (_Expr) {
296
- _inherits(StringLiteral, _Expr);
297
- function StringLiteral(value, span) {
298
- var _this;
299
- _classCallCheck(this, StringLiteral);
300
- _this = _callSuper(this, StringLiteral, [span]);
301
- _defineProperty(_assertThisInitialized(_this), "type", "StringLiteral");
302
- _this.value = value;
303
- return _this;
304
- }
305
- _createClass(StringLiteral, [{
306
- key: "transpile",
307
- value: function transpile() {
308
- return "'".concat(this.value, "'");
309
- }
310
- }]);
311
- return StringLiteral;
312
- }(Expr);
313
- var Sym = /*#__PURE__*/function (_Expr2) {
314
- _inherits(Sym, _Expr2);
315
- function Sym(value, span) {
316
- var _this2;
317
- _classCallCheck(this, Sym);
318
- _this2 = _callSuper(this, Sym, [span]);
319
- _defineProperty(_assertThisInitialized(_this2), "type", "Sym");
320
- _this2.value = value;
321
- return _this2;
322
- }
323
- _createClass(Sym, [{
324
- key: "transpile",
325
- value: function transpile() {
326
- return this.value;
327
- }
328
- }]);
329
- return Sym;
330
- }(Expr);
331
- var NilSym = new Sym("()");
332
- var StringTemplate = /*#__PURE__*/function (_Expr3) {
333
- _inherits(StringTemplate, _Expr3);
334
- function StringTemplate(children, span) {
335
- var _this3;
336
- _classCallCheck(this, StringTemplate);
337
- _this3 = _callSuper(this, StringTemplate, [span]);
338
- _defineProperty(_assertThisInitialized(_this3), "type", "StringTemplate");
339
- _this3.children = children;
340
- return _this3;
341
- }
342
- _createClass(StringTemplate, [{
343
- key: "transpile",
344
- value: function transpile() {
345
- return "'".concat(this.children.map(function (child) {
346
- if (child instanceof StringLiteral) {
347
- return child.value;
348
- } else {
349
- return "${".concat(child.transpile(), "}");
350
- }
351
- }).join(""), "'");
352
- }
353
- }]);
354
- return StringTemplate;
355
- }(Expr);
356
- var Call = /*#__PURE__*/function (_Expr4) {
357
- _inherits(Call, _Expr4);
358
- function Call(children, isAnon, span) {
359
- var _this4;
360
- _classCallCheck(this, Call);
361
- _this4 = _callSuper(this, Call, [span]);
362
- _defineProperty(_assertThisInitialized(_this4), "type", "Call");
363
- _this4.children = children;
364
- _this4.isAnon = isAnon;
365
- return _this4;
366
- }
367
- _createClass(Call, [{
368
- key: "transpile",
369
- value: function transpile() {
370
- if (this.isAnon) {
371
- return "!(".concat(this.children.map(function (child) {
372
- return child.transpile();
373
- }).join(" "), ")");
374
- }
375
- return "(".concat(this.children.map(function (child) {
376
- return child.transpile();
377
- }).join(" "), ")");
378
- }
379
- }]);
380
- return Call;
381
- }(Expr);
382
-
383
- /* Branded extension types: file, remote, i18n */
384
- var VAL_EXTENSION = "_type";
385
-
386
- /**
387
- * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
388
- *
389
- * An example where this is useful is remote types, where the type of the remote source is known at compile time,
390
- * but the value is not there before it is fetched.
391
- *
392
- * @example
393
- * type Example<T> = string & PhantomType<T>;
394
- *
395
- **/
396
-
397
- var FILE_REF_PROP = "_ref";
398
- var FILE_REF_SUBTYPE_TAG = "_tag";
399
-
400
- /**
401
- * A file source represents the path to a (local) file.
402
- *
403
- * It will be resolved into a Asset object.
404
- *
405
- */
406
-
407
- function file$1(ref, metadata) {
408
- return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
409
- }
410
- function isFile(obj) {
411
- return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
412
- }
413
-
414
- var FileSchema = /*#__PURE__*/function (_Schema) {
415
- _inherits(FileSchema, _Schema);
416
- function FileSchema(options) {
417
- var _this;
418
- var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
419
- _classCallCheck(this, FileSchema);
420
- _this = _callSuper(this, FileSchema);
421
- _this.options = options;
422
- _this.opt = opt;
423
- return _this;
424
- }
425
- _createClass(FileSchema, [{
426
- key: "validate",
427
- value: function validate(path, src) {
428
- if (this.opt && (src === null || src === undefined)) {
429
- return false;
430
- }
431
- if (src === null || src === undefined) {
432
- return _defineProperty({}, path, [{
433
- message: "Non-optional file was null or undefined.",
434
- value: src
435
- }]);
436
- }
437
- if (typeof src[FILE_REF_PROP] !== "string") {
438
- return _defineProperty({}, path, [{
439
- message: "File did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
440
- value: src
441
- }]);
442
- }
443
- if (src[VAL_EXTENSION] !== "file") {
444
- return _defineProperty({}, path, [{
445
- message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
446
- value: src
447
- }]);
448
- }
449
- if (src.metadata) {
450
- return _defineProperty({}, path, [{
451
- message: "Found metadata, but it could not be validated. File metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
452
- // These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
453
- value: src,
454
- fixes: ["file:check-metadata"]
455
- }]);
456
- }
457
- return _defineProperty({}, path, [{
458
- message: "Missing File metadata.",
459
- value: src,
460
- fixes: ["file:add-metadata"]
461
- }]);
462
- }
463
- }, {
464
- key: "assert",
465
- value: function assert(src) {
466
- if (this.opt && (src === null || src === undefined)) {
467
- return true;
468
- }
469
- return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "file" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
470
- }
471
- }, {
472
- key: "nullable",
473
- value: function nullable() {
474
- return new FileSchema(this.options, true);
475
- }
476
- }, {
477
- key: "serialize",
478
- value: function serialize() {
479
- return {
480
- type: "file",
481
- options: this.options,
482
- opt: this.opt
483
- };
484
- }
485
- }]);
486
- return FileSchema;
487
- }(Schema);
488
- var file = function file(options) {
489
- return new FileSchema(options);
490
- };
491
- function convertFileSource(src) {
492
- var _src$metadata3, _src$metadata4;
493
- // TODO: /public should be configurable
494
- if (!src[FILE_REF_PROP].startsWith("/public")) {
495
- var _src$metadata, _src$metadata2;
496
- return {
497
- url: src[FILE_REF_PROP] + ((_src$metadata = src.metadata) !== null && _src$metadata !== void 0 && _src$metadata.sha256 ? "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256) : ""),
498
- metadata: src.metadata
499
- };
500
- }
501
- return {
502
- url: src[FILE_REF_PROP].slice("/public".length) + ((_src$metadata3 = src.metadata) !== null && _src$metadata3 !== void 0 && _src$metadata3.sha256 ? "?sha256=".concat((_src$metadata4 = src.metadata) === null || _src$metadata4 === void 0 ? void 0 : _src$metadata4.sha256) : ""),
503
- metadata: src.metadata
504
- };
505
- }
506
-
507
- function isSerializedVal(val) {
508
- return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
509
- }
510
- function isVal(val) {
511
- return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
512
- }
513
-
514
- /**
515
- * The path of the source value.
516
- *
517
- * @example
518
- * '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
519
- */
520
-
521
- /**
522
- * The path inside the module.
523
- *
524
- * @example
525
- * '0."text"' // the text property of the first element of the module
526
- */
527
-
528
- /**
529
- * The id of the module.
530
- *
531
- * @example
532
- * '/app/blogs' // the /app/blogs module
533
- */
534
-
535
- function getValPath(valOrSelector) {
536
- return valOrSelector[Path];
537
- }
538
-
539
- export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _classCallCheck as a, _callSuper as b, _createClass as c, _defineProperty as d, _typeof as e, _objectSpread2 as f, getValPath as g, file as h, FILE_REF_SUBTYPE_TAG as i, file$1 as j, _slicedToArray as k, isFile as l, GetSource as m, isSerializedVal as n, FileSchema as o, convertFileSource as p, getSchema as q, isVal as r, GenericSelector as s, Sym as t, StringLiteral as u, StringTemplate as v, _toConsumableArray as w };