@overlayed/cli 0.0.1 → 0.0.3

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,1041 +0,0 @@
1
- import { __commonJS } from "./chunk-RDQt0V5E.js";
2
-
3
- //#region ../../node_modules/.pnpm/typanion@3.14.0/node_modules/typanion/lib/index.js
4
- var require_lib = __commonJS({ "../../node_modules/.pnpm/typanion@3.14.0/node_modules/typanion/lib/index.js"(exports) {
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
7
- function getPrintable(value) {
8
- if (value === null) return `null`;
9
- if (value === void 0) return `undefined`;
10
- if (value === ``) return `an empty string`;
11
- if (typeof value === "symbol") return `<${value.toString()}>`;
12
- if (Array.isArray(value)) return `an array`;
13
- return JSON.stringify(value);
14
- }
15
- function getPrintableArray(value, conjunction) {
16
- if (value.length === 0) return `nothing`;
17
- if (value.length === 1) return getPrintable(value[0]);
18
- const rest = value.slice(0, -1);
19
- const trailing = value[value.length - 1];
20
- const separator = value.length > 2 ? `, ${conjunction} ` : ` ${conjunction} `;
21
- return `${rest.map((value$1) => getPrintable(value$1)).join(`, `)}${separator}${getPrintable(trailing)}`;
22
- }
23
- function computeKey(state, key) {
24
- var _a, _b, _c;
25
- if (typeof key === `number`) return `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}[${key}]`;
26
- else if (simpleKeyRegExp.test(key)) return `${(_b = state === null || state === void 0 ? void 0 : state.p) !== null && _b !== void 0 ? _b : ``}.${key}`;
27
- else return `${(_c = state === null || state === void 0 ? void 0 : state.p) !== null && _c !== void 0 ? _c : `.`}[${JSON.stringify(key)}]`;
28
- }
29
- function plural(n, singular, plural$1) {
30
- return n === 1 ? singular : plural$1;
31
- }
32
- const colorStringRegExp = /^#[0-9a-f]{6}$/i;
33
- const colorStringAlphaRegExp = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
34
- const base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
35
- const uuid4RegExp = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/i;
36
- const iso8601RegExp = /^(?:[1-9]\d{3}(-?)(?:(?:0[1-9]|1[0-2])\1(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])\1(?:29|30)|(?:0[13578]|1[02])(?:\1)31|00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[0-5]))|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)(?:(-?)02(?:\2)29|-?366))T(?:[01]\d|2[0-3])(:?)[0-5]\d(?:\3[0-5]\d)?(?:Z|[+-][01]\d(?:\3[0-5]\d)?)$/;
37
- function pushError({ errors, p } = {}, message) {
38
- errors === null || errors === void 0 || errors.push(`${p !== null && p !== void 0 ? p : `.`}: ${message}`);
39
- return false;
40
- }
41
- function makeSetter(target, key) {
42
- return (v) => {
43
- target[key] = v;
44
- };
45
- }
46
- function makeCoercionFn(target, key) {
47
- return (v) => {
48
- const previous = target[key];
49
- target[key] = v;
50
- return makeCoercionFn(target, key).bind(null, previous);
51
- };
52
- }
53
- function makeLazyCoercionFn(fn$1, orig, generator) {
54
- const commit = () => {
55
- fn$1(generator());
56
- return revert;
57
- };
58
- const revert = () => {
59
- fn$1(orig);
60
- return commit;
61
- };
62
- return commit;
63
- }
64
- /**
65
- * Create a validator that always returns true and never refines the type.
66
- */
67
- function isUnknown() {
68
- return makeValidator({ test: (value, state) => {
69
- return true;
70
- } });
71
- }
72
- function isLiteral(expected) {
73
- return makeValidator({ test: (value, state) => {
74
- if (value !== expected) return pushError(state, `Expected ${getPrintable(expected)} (got ${getPrintable(value)})`);
75
- return true;
76
- } });
77
- }
78
- /**
79
- * Create a validator that only returns true when the tested value is a string.
80
- * Refines the type to `string`.
81
- */
82
- function isString() {
83
- return makeValidator({ test: (value, state) => {
84
- if (typeof value !== `string`) return pushError(state, `Expected a string (got ${getPrintable(value)})`);
85
- return true;
86
- } });
87
- }
88
- function isEnum(enumSpec) {
89
- const valuesArray = Array.isArray(enumSpec) ? enumSpec : Object.values(enumSpec);
90
- const isAlphaNum = valuesArray.every((item) => typeof item === "string" || typeof item === "number");
91
- const values = new Set(valuesArray);
92
- if (values.size === 1) return isLiteral([...values][0]);
93
- return makeValidator({ test: (value, state) => {
94
- if (!values.has(value)) if (isAlphaNum) return pushError(state, `Expected one of ${getPrintableArray(valuesArray, `or`)} (got ${getPrintable(value)})`);
95
- else return pushError(state, `Expected a valid enumeration value (got ${getPrintable(value)})`);
96
- return true;
97
- } });
98
- }
99
- const BOOLEAN_COERCIONS = new Map([
100
- [`true`, true],
101
- [`True`, true],
102
- [`1`, true],
103
- [1, true],
104
- [`false`, false],
105
- [`False`, false],
106
- [`0`, false],
107
- [0, false]
108
- ]);
109
- /**
110
- * Create a validator that only returns true when the tested value is a
111
- * boolean. Refines the type to `boolean`.
112
- *
113
- * Supports coercion:
114
- * - 'true' / 'True' / '1' / 1 will turn to `true`
115
- * - 'false' / 'False' / '0' / 0 will turn to `false`
116
- */
117
- function isBoolean() {
118
- return makeValidator({ test: (value, state) => {
119
- var _a;
120
- if (typeof value !== `boolean`) {
121
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
122
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
123
- const coercion = BOOLEAN_COERCIONS.get(value);
124
- if (typeof coercion !== `undefined`) {
125
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
126
- return true;
127
- }
128
- }
129
- return pushError(state, `Expected a boolean (got ${getPrintable(value)})`);
130
- }
131
- return true;
132
- } });
133
- }
134
- /**
135
- * Create a validator that only returns true when the tested value is a
136
- * number (including floating numbers; use `cascade` and `isInteger` to
137
- * restrict the range further). Refines the type to `number`.
138
- *
139
- * Supports coercion.
140
- */
141
- function isNumber() {
142
- return makeValidator({ test: (value, state) => {
143
- var _a;
144
- if (typeof value !== `number`) {
145
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
146
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
147
- let coercion;
148
- if (typeof value === `string`) {
149
- let val;
150
- try {
151
- val = JSON.parse(value);
152
- } catch (_b) {}
153
- if (typeof val === `number`) if (JSON.stringify(val) === value) coercion = val;
154
- else return pushError(state, `Received a number that can't be safely represented by the runtime (${value})`);
155
- }
156
- if (typeof coercion !== `undefined`) {
157
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
158
- return true;
159
- }
160
- }
161
- return pushError(state, `Expected a number (got ${getPrintable(value)})`);
162
- }
163
- return true;
164
- } });
165
- }
166
- /**
167
- * Important: This validator only makes sense when used in conjunction with
168
- * coercion! It will always error when used without.
169
- *
170
- * Create a validator that only returns true when the tested value is a
171
- * JSON representation of the expected type. Refines the type to the
172
- * expected type, and casts the value into its inner value.
173
- */
174
- function isPayload(spec) {
175
- return makeValidator({ test: (value, state) => {
176
- var _a;
177
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) === `undefined`) return pushError(state, `The isPayload predicate can only be used with coercion enabled`);
178
- if (typeof state.coercion === `undefined`) return pushError(state, `Unbound coercion result`);
179
- if (typeof value !== `string`) return pushError(state, `Expected a string (got ${getPrintable(value)})`);
180
- let inner;
181
- try {
182
- inner = JSON.parse(value);
183
- } catch (_b) {
184
- return pushError(state, `Expected a JSON string (got ${getPrintable(value)})`);
185
- }
186
- const wrapper = { value: inner };
187
- if (!spec(inner, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(wrapper, `value`) }))) return false;
188
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, wrapper.value)]);
189
- return true;
190
- } });
191
- }
192
- /**
193
- * Create a validator that only returns true when the tested value is a
194
- * valid date. Refines the type to `Date`.
195
- *
196
- * Supports coercion via one of the following formats:
197
- * - ISO86001 strings
198
- * - Unix timestamps
199
- */
200
- function isDate() {
201
- return makeValidator({ test: (value, state) => {
202
- var _a;
203
- if (!(value instanceof Date)) {
204
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
205
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
206
- let coercion;
207
- if (typeof value === `string` && iso8601RegExp.test(value)) coercion = new Date(value);
208
- else {
209
- let timestamp;
210
- if (typeof value === `string`) {
211
- let val;
212
- try {
213
- val = JSON.parse(value);
214
- } catch (_b) {}
215
- if (typeof val === `number`) timestamp = val;
216
- } else if (typeof value === `number`) timestamp = value;
217
- if (typeof timestamp !== `undefined`) if (Number.isSafeInteger(timestamp) || !Number.isSafeInteger(timestamp * 1e3)) coercion = /* @__PURE__ */ new Date(timestamp * 1e3);
218
- else return pushError(state, `Received a timestamp that can't be safely represented by the runtime (${value})`);
219
- }
220
- if (typeof coercion !== `undefined`) {
221
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
222
- return true;
223
- }
224
- }
225
- return pushError(state, `Expected a date (got ${getPrintable(value)})`);
226
- }
227
- return true;
228
- } });
229
- }
230
- /**
231
- * Create a validator that only returns true when the tested value is an
232
- * array whose all values match the provided subspec. Refines the type to
233
- * `Array<T>`, with `T` being the subspec inferred type.
234
- *
235
- * Supports coercion if the `delimiter` option is set, in which case strings
236
- * will be split accordingly.
237
- */
238
- function isArray(spec, { delimiter } = {}) {
239
- return makeValidator({ test: (value, state) => {
240
- var _a;
241
- const originalValue = value;
242
- if (typeof value === `string` && typeof delimiter !== `undefined`) {
243
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
244
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
245
- value = value.split(delimiter);
246
- }
247
- }
248
- if (!Array.isArray(value)) return pushError(state, `Expected an array (got ${getPrintable(value)})`);
249
- let valid = true;
250
- for (let t = 0, T = value.length; t < T; ++t) {
251
- valid = spec(value[t], Object.assign(Object.assign({}, state), {
252
- p: computeKey(state, t),
253
- coercion: makeCoercionFn(value, t)
254
- })) && valid;
255
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
256
- }
257
- if (value !== originalValue) state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
258
- return valid;
259
- } });
260
- }
261
- /**
262
- * Create a validator that only returns true when the tested value is an
263
- * set whose all values match the provided subspec. Refines the type to
264
- * `Set<T>`, with `T` being the subspec inferred type.
265
- *
266
- * Supports coercion from arrays (or anything that can be coerced into an
267
- * array).
268
- */
269
- function isSet(spec, { delimiter } = {}) {
270
- const isArrayValidator = isArray(spec, { delimiter });
271
- return makeValidator({ test: (value, state) => {
272
- var _a, _b;
273
- if (Object.getPrototypeOf(value).toString() === `[object Set]`) if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
274
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
275
- const originalValues = [...value];
276
- const coercedValues = [...value];
277
- if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 }))) return false;
278
- const updateValue = () => coercedValues.some((val, t) => val !== originalValues[t]) ? new Set(coercedValues) : value;
279
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
280
- return true;
281
- } else {
282
- let valid = true;
283
- for (const subValue of value) {
284
- valid = spec(subValue, Object.assign({}, state)) && valid;
285
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
286
- }
287
- return valid;
288
- }
289
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
290
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
291
- const store = { value };
292
- if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) }))) return false;
293
- state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Set(store.value))]);
294
- return true;
295
- }
296
- return pushError(state, `Expected a set (got ${getPrintable(value)})`);
297
- } });
298
- }
299
- /**
300
- * Create a validator that only returns true when the tested value is an
301
- * map whose all values match the provided subspecs. Refines the type to
302
- * `Map<U, V>`, with `U` being the key subspec inferred type and `V` being
303
- * the value subspec inferred type.
304
- *
305
- * Supports coercion from array of tuples (or anything that can be coerced into
306
- * an array of tuples).
307
- */
308
- function isMap(keySpec, valueSpec) {
309
- const isArrayValidator = isArray(isTuple([keySpec, valueSpec]));
310
- const isRecordValidator = isRecord(valueSpec, { keys: keySpec });
311
- return makeValidator({ test: (value, state) => {
312
- var _a, _b, _c;
313
- if (Object.getPrototypeOf(value).toString() === `[object Map]`) if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
314
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
315
- const originalValues = [...value];
316
- const coercedValues = [...value];
317
- if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 }))) return false;
318
- const updateValue = () => coercedValues.some((val, t) => val[0] !== originalValues[t][0] || val[1] !== originalValues[t][1]) ? new Map(coercedValues) : value;
319
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
320
- return true;
321
- } else {
322
- let valid = true;
323
- for (const [key, subValue] of value) {
324
- valid = keySpec(key, Object.assign({}, state)) && valid;
325
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
326
- valid = valueSpec(subValue, Object.assign(Object.assign({}, state), { p: computeKey(state, key) })) && valid;
327
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
328
- }
329
- return valid;
330
- }
331
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
332
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
333
- const store = { value };
334
- if (Array.isArray(value)) {
335
- if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 }))) return false;
336
- state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(store.value))]);
337
- return true;
338
- } else {
339
- if (!isRecordValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) }))) return false;
340
- state.coercions.push([(_c = state.p) !== null && _c !== void 0 ? _c : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(Object.entries(store.value)))]);
341
- return true;
342
- }
343
- }
344
- return pushError(state, `Expected a map (got ${getPrintable(value)})`);
345
- } });
346
- }
347
- /**
348
- * Create a validator that only returns true when the tested value is a
349
- * tuple whose each value matches the corresponding subspec. Refines the type
350
- * into a tuple whose each item has the type inferred by the corresponding
351
- * tuple.
352
- *
353
- * Supports coercion if the `delimiter` option is set, in which case strings
354
- * will be split accordingly.
355
- */
356
- function isTuple(spec, { delimiter } = {}) {
357
- const lengthValidator = hasExactLength(spec.length);
358
- return makeValidator({ test: (value, state) => {
359
- var _a;
360
- if (typeof value === `string` && typeof delimiter !== `undefined`) {
361
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
362
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
363
- value = value.split(delimiter);
364
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
365
- }
366
- }
367
- if (!Array.isArray(value)) return pushError(state, `Expected a tuple (got ${getPrintable(value)})`);
368
- let valid = lengthValidator(value, Object.assign({}, state));
369
- for (let t = 0, T = value.length; t < T && t < spec.length; ++t) {
370
- valid = spec[t](value[t], Object.assign(Object.assign({}, state), {
371
- p: computeKey(state, t),
372
- coercion: makeCoercionFn(value, t)
373
- })) && valid;
374
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
375
- }
376
- return valid;
377
- } });
378
- }
379
- /**
380
- * Create a validator that only returns true when the tested value is an
381
- * object with any amount of properties that must all match the provided
382
- * subspec. Refines the type to `Record<string, T>`, with `T` being the
383
- * subspec inferred type.
384
- *
385
- * Keys can be optionally validated as well by using the `keys` optional
386
- * subspec parameter.
387
- */
388
- function isRecord(spec, { keys: keySpec = null } = {}) {
389
- const isArrayValidator = isArray(isTuple([keySpec !== null && keySpec !== void 0 ? keySpec : isString(), spec]));
390
- return makeValidator({ test: (value, state) => {
391
- var _a;
392
- if (Array.isArray(value)) {
393
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
394
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
395
- if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 }))) return false;
396
- value = Object.fromEntries(value);
397
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
398
- return true;
399
- }
400
- }
401
- if (typeof value !== `object` || value === null) return pushError(state, `Expected an object (got ${getPrintable(value)})`);
402
- const keys = Object.keys(value);
403
- let valid = true;
404
- for (let t = 0, T = keys.length; t < T && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null); ++t) {
405
- const key = keys[t];
406
- const sub = value[key];
407
- if (key === `__proto__` || key === `constructor`) {
408
- valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
409
- continue;
410
- }
411
- if (keySpec !== null && !keySpec(key, state)) {
412
- valid = false;
413
- continue;
414
- }
415
- if (!spec(sub, Object.assign(Object.assign({}, state), {
416
- p: computeKey(state, key),
417
- coercion: makeCoercionFn(value, key)
418
- }))) {
419
- valid = false;
420
- continue;
421
- }
422
- }
423
- return valid;
424
- } });
425
- }
426
- /**
427
- * @deprecated Replace `isDict` by `isRecord`
428
- */
429
- function isDict(spec, opts = {}) {
430
- return isRecord(spec, opts);
431
- }
432
- /**
433
- * Create a validator that only returns true when the tested value is an
434
- * object whose all properties match their corresponding subspec. Refines
435
- * the type into an object whose each property has the type inferred by the
436
- * corresponding subspec.
437
- *
438
- * Unlike `t.isPartial`, `t.isObject` doesn't allow extraneous properties by
439
- * default. This behaviour can be altered by using the `extra` optional
440
- * subspec parameter, which will be called to validate an object only
441
- * containing the extraneous properties.
442
- *
443
- * Calling `t.isObject(..., {extra: t.isRecord(t.isUnknown())})` is
444
- * essentially the same as calling `t.isPartial(...)`.
445
- */
446
- function isObject(props, { extra: extraSpec = null } = {}) {
447
- const specKeys = Object.keys(props);
448
- const validator = makeValidator({ test: (value, state) => {
449
- if (typeof value !== `object` || value === null) return pushError(state, `Expected an object (got ${getPrintable(value)})`);
450
- const keys = new Set([...specKeys, ...Object.keys(value)]);
451
- const extra = {};
452
- let valid = true;
453
- for (const key of keys) {
454
- if (key === `constructor` || key === `__proto__`) valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
455
- else {
456
- const spec = Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
457
- const sub = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
458
- if (typeof spec !== `undefined`) valid = spec(sub, Object.assign(Object.assign({}, state), {
459
- p: computeKey(state, key),
460
- coercion: makeCoercionFn(value, key)
461
- })) && valid;
462
- else if (extraSpec === null) valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Extraneous property (got ${getPrintable(sub)})`);
463
- else Object.defineProperty(extra, key, {
464
- enumerable: true,
465
- get: () => sub,
466
- set: makeSetter(value, key)
467
- });
468
- }
469
- if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) break;
470
- }
471
- if (extraSpec !== null && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null)) valid = extraSpec(extra, state) && valid;
472
- return valid;
473
- } });
474
- return Object.assign(validator, { properties: props });
475
- }
476
- /**
477
- * Create a validator that only returns true when the tested value is an
478
- * object whose all properties match their corresponding subspec. Refines
479
- * the type into an object whose each property has the type inferred by the
480
- * corresponding subspec.
481
- *
482
- * Unlike `t.isObject`, `t.isPartial` allows extraneous properties. The
483
- * resulting type will reflect this behaviour by including an index
484
- * signature (each extraneous property being typed `unknown`).
485
- *
486
- * Calling `t.isPartial(...)` is essentially the same as calling
487
- * `t.isObject(..., {extra: t.isRecord(t.isUnknown())})`.
488
- */
489
- function isPartial(props) {
490
- return isObject(props, { extra: isRecord(isUnknown()) });
491
- }
492
- /**
493
- * Create a validator that only returns true when the tested value is an
494
- * object whose prototype is derived from the given class. Refines the type
495
- * into a class instance.
496
- */
497
- const isInstanceOf = (constructor) => makeValidator({ test: (value, state) => {
498
- if (!(value instanceof constructor)) return pushError(state, `Expected an instance of ${constructor.name} (got ${getPrintable(value)})`);
499
- return true;
500
- } });
501
- /**
502
- * Create a validator that only returns true when the tested value is an
503
- * object matching any of the provided subspecs. If the optional `exclusive`
504
- * parameter is set to `true`, the behaviour changes so that the validator
505
- * only returns true when exactly one subspec matches.
506
- */
507
- const isOneOf = (specs, { exclusive = false } = {}) => makeValidator({ test: (value, state) => {
508
- var _a, _b, _c;
509
- const matches = [];
510
- const errorBuffer = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
511
- for (let t = 0, T = specs.length; t < T; ++t) {
512
- const subErrors = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
513
- const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
514
- if (specs[t](value, Object.assign(Object.assign({}, state), {
515
- errors: subErrors,
516
- coercions: subCoercions,
517
- p: `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}#${t + 1}`
518
- }))) {
519
- matches.push([`#${t + 1}`, subCoercions]);
520
- if (!exclusive) break;
521
- } else errorBuffer === null || errorBuffer === void 0 || errorBuffer.push(subErrors[0]);
522
- }
523
- if (matches.length === 1) {
524
- const [, subCoercions] = matches[0];
525
- if (typeof subCoercions !== `undefined`) (_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 || _b.push(...subCoercions);
526
- return true;
527
- }
528
- if (matches.length > 1) pushError(state, `Expected to match exactly a single predicate (matched ${matches.join(`, `)})`);
529
- else (_c = state === null || state === void 0 ? void 0 : state.errors) === null || _c === void 0 || _c.push(...errorBuffer);
530
- return false;
531
- } });
532
- function makeTrait(value) {
533
- return () => {
534
- return value;
535
- };
536
- }
537
- function makeValidator({ test }) {
538
- return makeTrait(test)();
539
- }
540
- var TypeAssertionError = class extends Error {
541
- constructor({ errors } = {}) {
542
- let errorMessage = `Type mismatch`;
543
- if (errors && errors.length > 0) {
544
- errorMessage += `\n`;
545
- for (const error of errors) errorMessage += `\n- ${error}`;
546
- }
547
- super(errorMessage);
548
- }
549
- };
550
- /**
551
- * Check that the specified value matches the given validator, and throws an
552
- * exception if it doesn't. Refine the type if it passes.
553
- */
554
- function assert(val, validator) {
555
- if (!validator(val)) throw new TypeAssertionError();
556
- }
557
- /**
558
- * Check that the specified value matches the given validator, and throws an
559
- * exception if it doesn't. Refine the type if it passes.
560
- *
561
- * Thrown exceptions include details about what exactly looks invalid in the
562
- * tested value.
563
- */
564
- function assertWithErrors(val, validator) {
565
- const errors = [];
566
- if (!validator(val, { errors })) throw new TypeAssertionError({ errors });
567
- }
568
- /**
569
- * Compile-time only. Refine the type as if the validator was matching the
570
- * tested value, but doesn't actually run it. Similar to the classic `as`
571
- * operator in TypeScript.
572
- */
573
- function softAssert(val, validator) {}
574
- function as(value, validator, { coerce = false, errors: storeErrors, throw: throws } = {}) {
575
- const errors = storeErrors ? [] : void 0;
576
- if (!coerce) if (validator(value, { errors })) return throws ? value : {
577
- value,
578
- errors: void 0
579
- };
580
- else if (!throws) return {
581
- value: void 0,
582
- errors: errors !== null && errors !== void 0 ? errors : true
583
- };
584
- else throw new TypeAssertionError({ errors });
585
- const state = { value };
586
- const coercion = makeCoercionFn(state, `value`);
587
- const coercions = [];
588
- if (!validator(value, {
589
- errors,
590
- coercion,
591
- coercions
592
- })) if (!throws) return {
593
- value: void 0,
594
- errors: errors !== null && errors !== void 0 ? errors : true
595
- };
596
- else throw new TypeAssertionError({ errors });
597
- for (const [, apply] of coercions) apply();
598
- if (throws) return state.value;
599
- else return {
600
- value: state.value,
601
- errors: void 0
602
- };
603
- }
604
- /**
605
- * Create and return a new function that apply the given validators to each
606
- * corresponding argument passed to the function and throws an exception in
607
- * case of a mismatch.
608
- */
609
- function fn(validators, fn$1) {
610
- const isValidArgList = isTuple(validators);
611
- return (...args) => {
612
- const check = isValidArgList(args);
613
- if (!check) throw new TypeAssertionError();
614
- return fn$1(...args);
615
- };
616
- }
617
- /**
618
- * Create a validator that checks that the tested array or string has at least
619
- * the specified length.
620
- */
621
- function hasMinLength(length) {
622
- return makeValidator({ test: (value, state) => {
623
- if (!(value.length >= length)) return pushError(state, `Expected to have a length of at least ${length} elements (got ${value.length})`);
624
- return true;
625
- } });
626
- }
627
- /**
628
- * Create a validator that checks that the tested array or string has at most
629
- * the specified length.
630
- */
631
- function hasMaxLength(length) {
632
- return makeValidator({ test: (value, state) => {
633
- if (!(value.length <= length)) return pushError(state, `Expected to have a length of at most ${length} elements (got ${value.length})`);
634
- return true;
635
- } });
636
- }
637
- /**
638
- * Create a validator that checks that the tested array or string has exactly
639
- * the specified length.
640
- */
641
- function hasExactLength(length) {
642
- return makeValidator({ test: (value, state) => {
643
- if (!(value.length === length)) return pushError(state, `Expected to have a length of exactly ${length} elements (got ${value.length})`);
644
- return true;
645
- } });
646
- }
647
- /**
648
- * Create a validator that checks that the tested array only contains unique
649
- * elements. The optional `map` parameter lets you define a transform to
650
- * apply before making the check (the result of this transform will be
651
- * discarded afterwards).
652
- */
653
- function hasUniqueItems({ map } = {}) {
654
- return makeValidator({ test: (value, state) => {
655
- const set = /* @__PURE__ */ new Set();
656
- const dup = /* @__PURE__ */ new Set();
657
- for (let t = 0, T = value.length; t < T; ++t) {
658
- const sub = value[t];
659
- const key = typeof map !== `undefined` ? map(sub) : sub;
660
- if (set.has(key)) {
661
- if (dup.has(key)) continue;
662
- pushError(state, `Expected to contain unique elements; got a duplicate with ${getPrintable(value)}`);
663
- dup.add(key);
664
- } else set.add(key);
665
- }
666
- return dup.size === 0;
667
- } });
668
- }
669
- /**
670
- * Create a validator that checks that the tested number is strictly less than 0.
671
- */
672
- function isNegative() {
673
- return makeValidator({ test: (value, state) => {
674
- if (!(value <= 0)) return pushError(state, `Expected to be negative (got ${value})`);
675
- return true;
676
- } });
677
- }
678
- /**
679
- * Create a validator that checks that the tested number is equal or greater
680
- * than 0.
681
- */
682
- function isPositive() {
683
- return makeValidator({ test: (value, state) => {
684
- if (!(value >= 0)) return pushError(state, `Expected to be positive (got ${value})`);
685
- return true;
686
- } });
687
- }
688
- /**
689
- * Create a validator that checks that the tested number is equal or greater
690
- * than the specified reference.
691
- */
692
- function isAtLeast(n) {
693
- return makeValidator({ test: (value, state) => {
694
- if (!(value >= n)) return pushError(state, `Expected to be at least ${n} (got ${value})`);
695
- return true;
696
- } });
697
- }
698
- /**
699
- * Create a validator that checks that the tested number is equal or smaller
700
- * than the specified reference.
701
- */
702
- function isAtMost(n) {
703
- return makeValidator({ test: (value, state) => {
704
- if (!(value <= n)) return pushError(state, `Expected to be at most ${n} (got ${value})`);
705
- return true;
706
- } });
707
- }
708
- /**
709
- * Create a validator that checks that the tested number is between the
710
- * specified references (including the upper boundary).
711
- */
712
- function isInInclusiveRange(a, b) {
713
- return makeValidator({ test: (value, state) => {
714
- if (!(value >= a && value <= b)) return pushError(state, `Expected to be in the [${a}; ${b}] range (got ${value})`);
715
- return true;
716
- } });
717
- }
718
- /**
719
- * Create a validator that checks that the tested number is between the
720
- * specified references (excluding the upper boundary).
721
- */
722
- function isInExclusiveRange(a, b) {
723
- return makeValidator({ test: (value, state) => {
724
- if (!(value >= a && value < b)) return pushError(state, `Expected to be in the [${a}; ${b}[ range (got ${value})`);
725
- return true;
726
- } });
727
- }
728
- /**
729
- * Create a validator that checks that the tested number is an integer.
730
- *
731
- * By default Typanion will also check that it's a *safe* integer. For example,
732
- * 2^53 wouldn't be a safe integer because 2^53+1 would be rounded to 2^53,
733
- * which could put your applications at risk when used in loops.
734
- */
735
- function isInteger({ unsafe = false } = {}) {
736
- return makeValidator({ test: (value, state) => {
737
- if (value !== Math.round(value)) return pushError(state, `Expected to be an integer (got ${value})`);
738
- if (!unsafe && !Number.isSafeInteger(value)) return pushError(state, `Expected to be a safe integer (got ${value})`);
739
- return true;
740
- } });
741
- }
742
- /**
743
- * Create a validator that checks that the tested string matches the given
744
- * regular expression.
745
- */
746
- function matchesRegExp(regExp) {
747
- return makeValidator({ test: (value, state) => {
748
- if (!regExp.test(value)) return pushError(state, `Expected to match the pattern ${regExp.toString()} (got ${getPrintable(value)})`);
749
- return true;
750
- } });
751
- }
752
- /**
753
- * Create a validator that checks that the tested string only contain lowercase
754
- * characters.
755
- */
756
- function isLowerCase() {
757
- return makeValidator({ test: (value, state) => {
758
- if (value !== value.toLowerCase()) return pushError(state, `Expected to be all-lowercase (got ${value})`);
759
- return true;
760
- } });
761
- }
762
- /**
763
- * Create a validator that checks that the tested string only contain uppercase
764
- * characters.
765
- */
766
- function isUpperCase() {
767
- return makeValidator({ test: (value, state) => {
768
- if (value !== value.toUpperCase()) return pushError(state, `Expected to be all-uppercase (got ${value})`);
769
- return true;
770
- } });
771
- }
772
- /**
773
- * Create a validator that checks that the tested string is a valid UUID v4.
774
- */
775
- function isUUID4() {
776
- return makeValidator({ test: (value, state) => {
777
- if (!uuid4RegExp.test(value)) return pushError(state, `Expected to be a valid UUID v4 (got ${getPrintable(value)})`);
778
- return true;
779
- } });
780
- }
781
- /**
782
- * Create a validator that checks that the tested string is a valid ISO8601
783
- * date.
784
- */
785
- function isISO8601() {
786
- return makeValidator({ test: (value, state) => {
787
- if (!iso8601RegExp.test(value)) return pushError(state, `Expected to be a valid ISO 8601 date string (got ${getPrintable(value)})`);
788
- return true;
789
- } });
790
- }
791
- /**
792
- * Create a validator that checks that the tested string is a valid hexadecimal
793
- * color. Setting the optional `alpha` parameter to `true` allows an additional
794
- * transparency channel to be included.
795
- */
796
- function isHexColor({ alpha = false }) {
797
- return makeValidator({ test: (value, state) => {
798
- const res = alpha ? colorStringRegExp.test(value) : colorStringAlphaRegExp.test(value);
799
- if (!res) return pushError(state, `Expected to be a valid hexadecimal color string (got ${getPrintable(value)})`);
800
- return true;
801
- } });
802
- }
803
- /**
804
- * Create a validator that checks that the tested string is valid base64.
805
- */
806
- function isBase64() {
807
- return makeValidator({ test: (value, state) => {
808
- if (!base64RegExp.test(value)) return pushError(state, `Expected to be a valid base 64 string (got ${getPrintable(value)})`);
809
- return true;
810
- } });
811
- }
812
- /**
813
- * Create a validator that checks that the tested string is valid JSON. A
814
- * optional spec can be passed as parameter, in which case the data will be
815
- * deserialized and validated against the spec (coercion will be disabled
816
- * for this check, and even if successful the returned value will still be
817
- * the original string).
818
- */
819
- function isJSON(spec = isUnknown()) {
820
- return makeValidator({ test: (value, state) => {
821
- let data;
822
- try {
823
- data = JSON.parse(value);
824
- } catch (_a) {
825
- return pushError(state, `Expected to be a valid JSON string (got ${getPrintable(value)})`);
826
- }
827
- return spec(data, state);
828
- } });
829
- }
830
- function cascade(spec, ...followups) {
831
- const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
832
- return makeValidator({ test: (value, state) => {
833
- var _a, _b;
834
- const context = { value };
835
- const subCoercion = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? makeCoercionFn(context, `value`) : void 0;
836
- const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
837
- if (!spec(value, Object.assign(Object.assign({}, state), {
838
- coercion: subCoercion,
839
- coercions: subCoercions
840
- }))) return false;
841
- const reverts = [];
842
- if (typeof subCoercions !== `undefined`) for (const [, coercion] of subCoercions) reverts.push(coercion());
843
- try {
844
- if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
845
- if (context.value !== value) {
846
- if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`) return pushError(state, `Unbound coercion result`);
847
- state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, context.value)]);
848
- }
849
- (_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 || _b.push(...subCoercions);
850
- }
851
- return resolvedFollowups.every((spec$1) => {
852
- return spec$1(context.value, state);
853
- });
854
- } finally {
855
- for (const revert of reverts) revert();
856
- }
857
- } });
858
- }
859
- function applyCascade(spec, ...followups) {
860
- const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
861
- return cascade(spec, resolvedFollowups);
862
- }
863
- /**
864
- * Wraps the given spec to also allow `undefined`.
865
- */
866
- function isOptional(spec) {
867
- return makeValidator({ test: (value, state) => {
868
- if (typeof value === `undefined`) return true;
869
- return spec(value, state);
870
- } });
871
- }
872
- /**
873
- * Wraps the given spec to also allow `null`.
874
- */
875
- function isNullable(spec) {
876
- return makeValidator({ test: (value, state) => {
877
- if (value === null) return true;
878
- return spec(value, state);
879
- } });
880
- }
881
- const checks = {
882
- missing: (keys, key) => keys.has(key),
883
- undefined: (keys, key, value) => keys.has(key) && typeof value[key] !== `undefined`,
884
- nil: (keys, key, value) => keys.has(key) && value[key] != null,
885
- falsy: (keys, key, value) => keys.has(key) && !!value[key]
886
- };
887
- /**
888
- * Create a validator that checks that the tested object contains the specified
889
- * keys.
890
- */
891
- function hasRequiredKeys(requiredKeys, options) {
892
- var _a;
893
- const requiredSet = new Set(requiredKeys);
894
- const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
895
- return makeValidator({ test: (value, state) => {
896
- const keys = new Set(Object.keys(value));
897
- const problems = [];
898
- for (const key of requiredSet) if (!check(keys, key, value)) problems.push(key);
899
- if (problems.length > 0) return pushError(state, `Missing required ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
900
- return true;
901
- } });
902
- }
903
- /**
904
- * Create a validator that checks that the tested object contains at least one
905
- * of the specified keys.
906
- */
907
- function hasAtLeastOneKey(requiredKeys, options) {
908
- var _a;
909
- const requiredSet = new Set(requiredKeys);
910
- const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
911
- return makeValidator({ test: (value, state) => {
912
- const keys = Object.keys(value);
913
- const valid = keys.some((key) => check(requiredSet, key, value));
914
- if (!valid) return pushError(state, `Missing at least one property from ${getPrintableArray(Array.from(requiredSet), `or`)}`);
915
- return true;
916
- } });
917
- }
918
- /**
919
- * Create a validator that checks that the tested object contains none of the
920
- * specified keys.
921
- */
922
- function hasForbiddenKeys(forbiddenKeys, options) {
923
- var _a;
924
- const forbiddenSet = new Set(forbiddenKeys);
925
- const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
926
- return makeValidator({ test: (value, state) => {
927
- const keys = new Set(Object.keys(value));
928
- const problems = [];
929
- for (const key of forbiddenSet) if (check(keys, key, value)) problems.push(key);
930
- if (problems.length > 0) return pushError(state, `Forbidden ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
931
- return true;
932
- } });
933
- }
934
- /**
935
- * Create a validator that checks that the tested object contains at most one
936
- * of the specified keys.
937
- */
938
- function hasMutuallyExclusiveKeys(exclusiveKeys, options) {
939
- var _a;
940
- const exclusiveSet = new Set(exclusiveKeys);
941
- const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
942
- return makeValidator({ test: (value, state) => {
943
- const keys = new Set(Object.keys(value));
944
- const used = [];
945
- for (const key of exclusiveSet) if (check(keys, key, value)) used.push(key);
946
- if (used.length > 1) return pushError(state, `Mutually exclusive properties ${getPrintableArray(used, `and`)}`);
947
- return true;
948
- } });
949
- }
950
- (function(KeyRelationship) {
951
- KeyRelationship["Forbids"] = "Forbids";
952
- KeyRelationship["Requires"] = "Requires";
953
- })(exports.KeyRelationship || (exports.KeyRelationship = {}));
954
- const keyRelationships = {
955
- [exports.KeyRelationship.Forbids]: {
956
- expect: false,
957
- message: `forbids using`
958
- },
959
- [exports.KeyRelationship.Requires]: {
960
- expect: true,
961
- message: `requires using`
962
- }
963
- };
964
- /**
965
- * Create a validator that checks that, when the specified subject property is
966
- * set, the relationship is satisfied.
967
- */
968
- function hasKeyRelationship(subject, relationship, others, options) {
969
- var _a, _b;
970
- const skipped = new Set((_a = options === null || options === void 0 ? void 0 : options.ignore) !== null && _a !== void 0 ? _a : []);
971
- const check = checks[(_b = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _b !== void 0 ? _b : "missing"];
972
- const otherSet = new Set(others);
973
- const spec = keyRelationships[relationship];
974
- const conjunction = relationship === exports.KeyRelationship.Forbids ? `or` : `and`;
975
- return makeValidator({ test: (value, state) => {
976
- const keys = new Set(Object.keys(value));
977
- if (!check(keys, subject, value) || skipped.has(value[subject])) return true;
978
- const problems = [];
979
- for (const key of otherSet) if ((check(keys, key, value) && !skipped.has(value[key])) !== spec.expect) problems.push(key);
980
- if (problems.length >= 1) return pushError(state, `Property "${subject}" ${spec.message} ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, conjunction)}`);
981
- return true;
982
- } });
983
- }
984
- exports.TypeAssertionError = TypeAssertionError;
985
- exports.applyCascade = applyCascade;
986
- exports.as = as;
987
- exports.assert = assert;
988
- exports.assertWithErrors = assertWithErrors;
989
- exports.cascade = cascade;
990
- exports.fn = fn;
991
- exports.hasAtLeastOneKey = hasAtLeastOneKey;
992
- exports.hasExactLength = hasExactLength;
993
- exports.hasForbiddenKeys = hasForbiddenKeys;
994
- exports.hasKeyRelationship = hasKeyRelationship;
995
- exports.hasMaxLength = hasMaxLength;
996
- exports.hasMinLength = hasMinLength;
997
- exports.hasMutuallyExclusiveKeys = hasMutuallyExclusiveKeys;
998
- exports.hasRequiredKeys = hasRequiredKeys;
999
- exports.hasUniqueItems = hasUniqueItems;
1000
- exports.isArray = isArray;
1001
- exports.isAtLeast = isAtLeast;
1002
- exports.isAtMost = isAtMost;
1003
- exports.isBase64 = isBase64;
1004
- exports.isBoolean = isBoolean;
1005
- exports.isDate = isDate;
1006
- exports.isDict = isDict;
1007
- exports.isEnum = isEnum;
1008
- exports.isHexColor = isHexColor;
1009
- exports.isISO8601 = isISO8601;
1010
- exports.isInExclusiveRange = isInExclusiveRange;
1011
- exports.isInInclusiveRange = isInInclusiveRange;
1012
- exports.isInstanceOf = isInstanceOf;
1013
- exports.isInteger = isInteger;
1014
- exports.isJSON = isJSON;
1015
- exports.isLiteral = isLiteral;
1016
- exports.isLowerCase = isLowerCase;
1017
- exports.isMap = isMap;
1018
- exports.isNegative = isNegative;
1019
- exports.isNullable = isNullable;
1020
- exports.isNumber = isNumber;
1021
- exports.isObject = isObject;
1022
- exports.isOneOf = isOneOf;
1023
- exports.isOptional = isOptional;
1024
- exports.isPartial = isPartial;
1025
- exports.isPayload = isPayload;
1026
- exports.isPositive = isPositive;
1027
- exports.isRecord = isRecord;
1028
- exports.isSet = isSet;
1029
- exports.isString = isString;
1030
- exports.isTuple = isTuple;
1031
- exports.isUUID4 = isUUID4;
1032
- exports.isUnknown = isUnknown;
1033
- exports.isUpperCase = isUpperCase;
1034
- exports.makeTrait = makeTrait;
1035
- exports.makeValidator = makeValidator;
1036
- exports.matchesRegExp = matchesRegExp;
1037
- exports.softAssert = softAssert;
1038
- } });
1039
-
1040
- //#endregion
1041
- export default require_lib();