xanv 1.1.12 → 1.1.13
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/index.cjs +6 -0
- package/index.cjs.map +1 -1
- package/index.d.ts +5 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types/Function.cjs +33 -0
- package/types/Function.cjs.map +1 -0
- package/types/Function.d.ts +15 -0
- package/types/Function.js +31 -0
- package/types/Function.js.map +1 -0
- package/types/Promise.cjs +29 -0
- package/types/Promise.cjs.map +1 -0
- package/types/Promise.d.ts +11 -0
- package/types/Promise.js +27 -0
- package/types/Promise.js.map +1 -0
- package/types.d.ts +6 -2
package/index.cjs
CHANGED
|
@@ -16,6 +16,8 @@ var String = require('./types/String.cjs');
|
|
|
16
16
|
var Tuple = require('./types/Tuple.cjs');
|
|
17
17
|
var Union = require('./types/Union.cjs');
|
|
18
18
|
var Json = require('./types/Json.cjs');
|
|
19
|
+
var Function = require('./types/Function.cjs');
|
|
20
|
+
var Promise$1 = require('./types/Promise.cjs');
|
|
19
21
|
|
|
20
22
|
const xv = {
|
|
21
23
|
any: () => new Any(),
|
|
@@ -33,6 +35,8 @@ const xv = {
|
|
|
33
35
|
tuple: (type) => new Tuple(type),
|
|
34
36
|
union: (types) => new Union(types),
|
|
35
37
|
json: () => new Json(),
|
|
38
|
+
function: (args, ret) => new Function(args, ret),
|
|
39
|
+
promise: (type) => new Promise$1(type),
|
|
36
40
|
};
|
|
37
41
|
|
|
38
42
|
exports.XanvType = XanvType;
|
|
@@ -51,5 +55,7 @@ exports.XVString = String;
|
|
|
51
55
|
exports.XVTuple = Tuple;
|
|
52
56
|
exports.XVUnion = Union;
|
|
53
57
|
exports.XVJson = Json;
|
|
58
|
+
exports.XVFunction = Function;
|
|
59
|
+
exports.XVPromise = Promise$1;
|
|
54
60
|
exports.xv = xv;
|
|
55
61
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import XanvType from \"./XanvType\";\r\nimport XVAny from \"./types/Any\";\r\nimport XVArray from \"./types/Array\";\r\nimport XVBoolean from \"./types/Boolean\";\r\nimport XVDate from \"./types/Date\";\r\nimport XVEnum from \"./types/Enum\";\r\nimport XVFile from \"./types/File\";\r\nimport XVMap from \"./types/Map\";\r\nimport XVNumber from \"./types/Number\";\r\nimport XVObject, { XVObjectShape } from \"./types/Object\";\r\nimport XVRecord from \"./types/Record\";\r\nimport XVSet from \"./types/Set\";\r\nimport XVString from \"./types/String\";\r\nimport XVTuple from \"./types/Tuple\";\r\nimport XVUnion from \"./types/Union\";\r\nimport XVJson from \"./types/Json\";\r\n\r\nimport {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer,\r\n} from \"./types\";\r\n\r\nexport type {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer\r\n};\r\n\r\nexport {\r\n XanvType,\r\n XVAny,\r\n XVArray,\r\n XVBoolean,\r\n XVDate,\r\n XVEnum,\r\n XVFile,\r\n XVMap,\r\n XVNumber,\r\n XVObject,\r\n XVRecord,\r\n XVSet,\r\n XVString,\r\n XVTuple,\r\n XVUnion,\r\n XVJson,\r\n};\r\n\r\nexport const xv = {\r\n any: () => new XVAny(),\r\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import XanvType from \"./XanvType\";\r\nimport XVAny from \"./types/Any\";\r\nimport XVArray from \"./types/Array\";\r\nimport XVBoolean from \"./types/Boolean\";\r\nimport XVDate from \"./types/Date\";\r\nimport XVEnum from \"./types/Enum\";\r\nimport XVFile from \"./types/File\";\r\nimport XVMap from \"./types/Map\";\r\nimport XVNumber from \"./types/Number\";\r\nimport XVObject, { XVObjectShape } from \"./types/Object\";\r\nimport XVRecord from \"./types/Record\";\r\nimport XVSet from \"./types/Set\";\r\nimport XVString from \"./types/String\";\r\nimport XVTuple from \"./types/Tuple\";\r\nimport XVUnion from \"./types/Union\";\r\nimport XVJson from \"./types/Json\";\r\nimport XVFunction from \"./types/Function\";\r\n\r\nimport {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer,\r\n} from \"./types\";\r\nimport XVPromise from \"./types/Promise\";\r\n\r\nexport type {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer\r\n};\r\n\r\nexport {\r\n XanvType,\r\n XVAny,\r\n XVArray,\r\n XVBoolean,\r\n XVFunction,\r\n XVPromise,\r\n XVDate,\r\n XVEnum,\r\n XVFile,\r\n XVMap,\r\n XVNumber,\r\n XVObject,\r\n XVRecord,\r\n XVSet,\r\n XVString,\r\n XVTuple,\r\n XVUnion,\r\n XVJson,\r\n};\r\n\r\nexport const xv = {\r\n any: () => new XVAny(),\r\n array: <T extends XVInstanceType>(type: T, length?: number) => new XVArray<T>(type, length),\r\n boolean: () => new XVBoolean(),\r\n date: () => new XVDate(),\r\n enum: <T extends readonly (string | number)[]>(...values: T) => new XVEnum<T>(values),\r\n file: () => new XVFile(),\r\n number: (length?: number) => new XVNumber(length),\r\n object: <T extends XVObjectShape>(arg?: T) => new XVObject<T>(arg),\r\n record: <K extends XVInstanceType, V extends XVInstanceType>(key: K, value: V) => new XVRecord<K, V>(key, value),\r\n map: <K extends XVInstanceType, V extends XVInstanceType>(key: K, value: V) => new XVMap<K, V>(key, value),\r\n set: <T extends XVInstanceType>(type: T) => new XVSet<T>(type),\r\n string: (length?: number) => new XVString(length),\r\n tuple: <T extends XVInstanceType[]>(type: T) => new XVTuple<T>(type),\r\n union: <T extends XVInstanceType[]>(types: T) => new XVUnion<T>(types),\r\n json: () => new XVJson(),\r\n function: <A extends XVInstanceType[], R extends XVInstanceType>(args: A, ret: R) => new XVFunction<A, R>(args, ret),\r\n promise: <T extends XVInstanceType>(type: T) => new XVPromise(type),\r\n};\r\n\r\n"],"names":["XVAny","XVArray","XVBoolean","XVDate","XVEnum","XVFile","XVNumber","XVObject","XVRecord","XVMap","XVSet","XVString","XVTuple","XVUnion","XVJson","XVFunction","XVPromise"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoDO,MAAM,EAAE,GAAG;AACf,IAAA,GAAG,EAAE,MAAM,IAAIA,GAAK,EAAE;AACtB,IAAA,KAAK,EAAE,CAA2B,IAAO,EAAE,MAAe,KAAK,IAAIC,KAAO,CAAI,IAAI,EAAE,MAAM,CAAC;AAC3F,IAAA,OAAO,EAAE,MAAM,IAAIC,OAAS,EAAE;AAC9B,IAAA,IAAI,EAAE,MAAM,IAAIC,IAAM,EAAE;IACxB,IAAI,EAAE,CAAyC,GAAG,MAAS,KAAK,IAAIC,IAAM,CAAI,MAAM,CAAC;AACrF,IAAA,IAAI,EAAE,MAAM,IAAIC,IAAM,EAAE;IACxB,MAAM,EAAE,CAAC,MAAe,KAAK,IAAIC,MAAQ,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,CAA0B,GAAO,KAAK,IAAIC,QAAQ,CAAI,GAAG,CAAC;AAClE,IAAA,MAAM,EAAE,CAAqD,GAAM,EAAE,KAAQ,KAAK,IAAIC,MAAQ,CAAO,GAAG,EAAE,KAAK,CAAC;AAChH,IAAA,GAAG,EAAE,CAAqD,GAAM,EAAE,KAAQ,KAAK,IAAIC,GAAK,CAAO,GAAG,EAAE,KAAK,CAAC;IAC1G,GAAG,EAAE,CAA2B,IAAO,KAAK,IAAIC,GAAK,CAAI,IAAI,CAAC;IAC9D,MAAM,EAAE,CAAC,MAAe,KAAK,IAAIC,MAAQ,CAAC,MAAM,CAAC;IACjD,KAAK,EAAE,CAA6B,IAAO,KAAK,IAAIC,KAAO,CAAI,IAAI,CAAC;IACpE,KAAK,EAAE,CAA6B,KAAQ,KAAK,IAAIC,KAAO,CAAI,KAAK,CAAC;AACtE,IAAA,IAAI,EAAE,MAAM,IAAIC,IAAM,EAAE;AACxB,IAAA,QAAQ,EAAE,CAAuD,IAAO,EAAE,GAAM,KAAK,IAAIC,QAAU,CAAO,IAAI,EAAE,GAAG,CAAC;IACpH,OAAO,EAAE,CAA2B,IAAO,KAAK,IAAIC,SAAS,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ import XVString from './types/String.js';
|
|
|
14
14
|
import XVTuple from './types/Tuple.js';
|
|
15
15
|
import XVUnion from './types/Union.js';
|
|
16
16
|
import XVJson from './types/Json.js';
|
|
17
|
+
import XVFunction from './types/Function.js';
|
|
17
18
|
import { XVInstanceType } from './types.js';
|
|
18
19
|
export { Infer, XVCheckCallback } from './types.js';
|
|
20
|
+
import XVPromise from './types/Promise.js';
|
|
19
21
|
|
|
20
22
|
declare const xv: {
|
|
21
23
|
any: () => XVAny;
|
|
@@ -33,6 +35,8 @@ declare const xv: {
|
|
|
33
35
|
tuple: <T_4 extends XVInstanceType[]>(type: T_4) => XVTuple<T_4>;
|
|
34
36
|
union: <T_5 extends XVInstanceType[]>(types: T_5) => XVUnion<T_5>;
|
|
35
37
|
json: () => XVJson<Record<string, any>>;
|
|
38
|
+
function: <A extends XVInstanceType[], R extends XVInstanceType>(args: A, ret: R) => XVFunction<A, R>;
|
|
39
|
+
promise: <T_6 extends XVInstanceType>(type: T_6) => XVPromise<T_6>;
|
|
36
40
|
};
|
|
37
41
|
|
|
38
|
-
export { XVAny, XVArray, XVBoolean, XVDate, XVEnum, XVFile, XVInstanceType, XVJson, XVMap, XVNumber, XVObject, XVRecord, XVSet, XVString, XVTuple, XVUnion, xv };
|
|
42
|
+
export { XVAny, XVArray, XVBoolean, XVDate, XVEnum, XVFile, XVFunction, XVInstanceType, XVJson, XVMap, XVNumber, XVObject, XVPromise, XVRecord, XVSet, XVString, XVTuple, XVUnion, xv };
|
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import XVString from './types/String.js';
|
|
|
14
14
|
import XVTuple from './types/Tuple.js';
|
|
15
15
|
import XVUnion from './types/Union.js';
|
|
16
16
|
import XVJson from './types/Json.js';
|
|
17
|
+
import XVFunction from './types/Function.js';
|
|
18
|
+
import XVPromise from './types/Promise.js';
|
|
17
19
|
|
|
18
20
|
const xv = {
|
|
19
21
|
any: () => new XVAny(),
|
|
@@ -31,7 +33,9 @@ const xv = {
|
|
|
31
33
|
tuple: (type) => new XVTuple(type),
|
|
32
34
|
union: (types) => new XVUnion(types),
|
|
33
35
|
json: () => new XVJson(),
|
|
36
|
+
function: (args, ret) => new XVFunction(args, ret),
|
|
37
|
+
promise: (type) => new XVPromise(type),
|
|
34
38
|
};
|
|
35
39
|
|
|
36
|
-
export { XVAny, XVArray, XVBoolean, XVDate, XVEnum, XVFile, XVJson, XVMap, XVNumber, XVObject, XVRecord, XVSet, XVString, XVTuple, XVUnion, xv };
|
|
40
|
+
export { XVAny, XVArray, XVBoolean, XVDate, XVEnum, XVFile, XVFunction, XVJson, XVMap, XVNumber, XVObject, XVPromise, XVRecord, XVSet, XVString, XVTuple, XVUnion, xv };
|
|
37
41
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import XanvType from \"./XanvType\";\r\nimport XVAny from \"./types/Any\";\r\nimport XVArray from \"./types/Array\";\r\nimport XVBoolean from \"./types/Boolean\";\r\nimport XVDate from \"./types/Date\";\r\nimport XVEnum from \"./types/Enum\";\r\nimport XVFile from \"./types/File\";\r\nimport XVMap from \"./types/Map\";\r\nimport XVNumber from \"./types/Number\";\r\nimport XVObject, { XVObjectShape } from \"./types/Object\";\r\nimport XVRecord from \"./types/Record\";\r\nimport XVSet from \"./types/Set\";\r\nimport XVString from \"./types/String\";\r\nimport XVTuple from \"./types/Tuple\";\r\nimport XVUnion from \"./types/Union\";\r\nimport XVJson from \"./types/Json\";\r\n\r\nimport {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer,\r\n} from \"./types\";\r\n\r\nexport type {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer\r\n};\r\n\r\nexport {\r\n XanvType,\r\n XVAny,\r\n XVArray,\r\n XVBoolean,\r\n XVDate,\r\n XVEnum,\r\n XVFile,\r\n XVMap,\r\n XVNumber,\r\n XVObject,\r\n XVRecord,\r\n XVSet,\r\n XVString,\r\n XVTuple,\r\n XVUnion,\r\n XVJson,\r\n};\r\n\r\nexport const xv = {\r\n any: () => new XVAny(),\r\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import XanvType from \"./XanvType\";\r\nimport XVAny from \"./types/Any\";\r\nimport XVArray from \"./types/Array\";\r\nimport XVBoolean from \"./types/Boolean\";\r\nimport XVDate from \"./types/Date\";\r\nimport XVEnum from \"./types/Enum\";\r\nimport XVFile from \"./types/File\";\r\nimport XVMap from \"./types/Map\";\r\nimport XVNumber from \"./types/Number\";\r\nimport XVObject, { XVObjectShape } from \"./types/Object\";\r\nimport XVRecord from \"./types/Record\";\r\nimport XVSet from \"./types/Set\";\r\nimport XVString from \"./types/String\";\r\nimport XVTuple from \"./types/Tuple\";\r\nimport XVUnion from \"./types/Union\";\r\nimport XVJson from \"./types/Json\";\r\nimport XVFunction from \"./types/Function\";\r\n\r\nimport {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer,\r\n} from \"./types\";\r\nimport XVPromise from \"./types/Promise\";\r\n\r\nexport type {\r\n XVInstanceType,\r\n XVCheckCallback,\r\n Infer\r\n};\r\n\r\nexport {\r\n XanvType,\r\n XVAny,\r\n XVArray,\r\n XVBoolean,\r\n XVFunction,\r\n XVPromise,\r\n XVDate,\r\n XVEnum,\r\n XVFile,\r\n XVMap,\r\n XVNumber,\r\n XVObject,\r\n XVRecord,\r\n XVSet,\r\n XVString,\r\n XVTuple,\r\n XVUnion,\r\n XVJson,\r\n};\r\n\r\nexport const xv = {\r\n any: () => new XVAny(),\r\n array: <T extends XVInstanceType>(type: T, length?: number) => new XVArray<T>(type, length),\r\n boolean: () => new XVBoolean(),\r\n date: () => new XVDate(),\r\n enum: <T extends readonly (string | number)[]>(...values: T) => new XVEnum<T>(values),\r\n file: () => new XVFile(),\r\n number: (length?: number) => new XVNumber(length),\r\n object: <T extends XVObjectShape>(arg?: T) => new XVObject<T>(arg),\r\n record: <K extends XVInstanceType, V extends XVInstanceType>(key: K, value: V) => new XVRecord<K, V>(key, value),\r\n map: <K extends XVInstanceType, V extends XVInstanceType>(key: K, value: V) => new XVMap<K, V>(key, value),\r\n set: <T extends XVInstanceType>(type: T) => new XVSet<T>(type),\r\n string: (length?: number) => new XVString(length),\r\n tuple: <T extends XVInstanceType[]>(type: T) => new XVTuple<T>(type),\r\n union: <T extends XVInstanceType[]>(types: T) => new XVUnion<T>(types),\r\n json: () => new XVJson(),\r\n function: <A extends XVInstanceType[], R extends XVInstanceType>(args: A, ret: R) => new XVFunction<A, R>(args, ret),\r\n promise: <T extends XVInstanceType>(type: T) => new XVPromise(type),\r\n};\r\n\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAoDO,MAAM,EAAE,GAAG;AACf,IAAA,GAAG,EAAE,MAAM,IAAI,KAAK,EAAE;AACtB,IAAA,KAAK,EAAE,CAA2B,IAAO,EAAE,MAAe,KAAK,IAAI,OAAO,CAAI,IAAI,EAAE,MAAM,CAAC;AAC3F,IAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE;AAC9B,IAAA,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE;IACxB,IAAI,EAAE,CAAyC,GAAG,MAAS,KAAK,IAAI,MAAM,CAAI,MAAM,CAAC;AACrF,IAAA,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE;IACxB,MAAM,EAAE,CAAC,MAAe,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,CAA0B,GAAO,KAAK,IAAI,QAAQ,CAAI,GAAG,CAAC;AAClE,IAAA,MAAM,EAAE,CAAqD,GAAM,EAAE,KAAQ,KAAK,IAAI,QAAQ,CAAO,GAAG,EAAE,KAAK,CAAC;AAChH,IAAA,GAAG,EAAE,CAAqD,GAAM,EAAE,KAAQ,KAAK,IAAI,KAAK,CAAO,GAAG,EAAE,KAAK,CAAC;IAC1G,GAAG,EAAE,CAA2B,IAAO,KAAK,IAAI,KAAK,CAAI,IAAI,CAAC;IAC9D,MAAM,EAAE,CAAC,MAAe,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;IACjD,KAAK,EAAE,CAA6B,IAAO,KAAK,IAAI,OAAO,CAAI,IAAI,CAAC;IACpE,KAAK,EAAE,CAA6B,KAAQ,KAAK,IAAI,OAAO,CAAI,KAAK,CAAC;AACtE,IAAA,IAAI,EAAE,MAAM,IAAI,MAAM,EAAE;AACxB,IAAA,QAAQ,EAAE,CAAuD,IAAO,EAAE,GAAM,KAAK,IAAI,UAAU,CAAO,IAAI,EAAE,GAAG,CAAC;IACpH,OAAO,EAAE,CAA2B,IAAO,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC;;;;;"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var XanvType = require('../XanvType.cjs');
|
|
4
|
+
|
|
5
|
+
class XVFunction extends XanvType {
|
|
6
|
+
constructor(args, ret) {
|
|
7
|
+
super();
|
|
8
|
+
this._args = args;
|
|
9
|
+
this._return = ret;
|
|
10
|
+
}
|
|
11
|
+
check(value) {
|
|
12
|
+
if (typeof value !== "function") {
|
|
13
|
+
throw new Error(`Value should be a function, received ${typeof value}`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
parse(fn) {
|
|
18
|
+
super.parse(fn);
|
|
19
|
+
return ((...args) => {
|
|
20
|
+
// Validate each argument
|
|
21
|
+
this._args.forEach((argValidator, i) => {
|
|
22
|
+
argValidator.parse(args[i]);
|
|
23
|
+
});
|
|
24
|
+
const result = fn(...args);
|
|
25
|
+
// Validate return value
|
|
26
|
+
this._return.parse(result);
|
|
27
|
+
return result;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = XVFunction;
|
|
33
|
+
//# sourceMappingURL=Function.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Function.cjs","sources":["../../src/types/Function.ts"],"sourcesContent":["import { Infer, XVInstanceType } from \"../types\";\r\nimport XanvType from \"../XanvType\";\r\n\r\ntype Func<A extends XVInstanceType[], R extends XVInstanceType> =\r\n (...args: { [K in keyof A]: Infer<A[K]> }) => Infer<R>;\r\n\r\nclass XVFunction<A extends XVInstanceType[], R extends XVInstanceType>\r\n extends XanvType<Func<A, R>, unknown> {\r\n\r\n private _args: A;\r\n private _return: R;\r\n\r\n constructor(args: A, ret: R) {\r\n super();\r\n this._args = args;\r\n this._return = ret;\r\n }\r\n\r\n protected check(value: any): Func<A, R> {\r\n if (typeof value !== \"function\") {\r\n throw new Error(`Value should be a function, received ${typeof value}`);\r\n }\r\n return value;\r\n }\r\n\r\n parse(fn: any): Func<A, R> {\r\n super.parse(fn);\r\n\r\n return ((...args: any[]) => {\r\n // Validate each argument\r\n this._args.forEach((argValidator, i) => {\r\n argValidator.parse(args[i]);\r\n });\r\n\r\n const result = fn(...args);\r\n\r\n // Validate return value\r\n this._return.parse(result);\r\n\r\n return result;\r\n }) as Func<A, R>;\r\n }\r\n}\r\n\r\nexport default XVFunction;\r\n"],"names":[],"mappings":";;;;AAMA,MAAM,UACH,SAAQ,QAA6B,CAAA;IAKrC,WAAA,CAAY,IAAO,EAAE,GAAM,EAAA;AACxB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;AAClB,QAAA,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACtB,CAAC;AAES,IAAA,KAAK,CAAC,KAAU,EAAA;AACvB,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,CAAA,qCAAA,EAAwC,OAAO,KAAK,CAAA,CAAE,CAAC,CAAC;AAC1E,QAAA,CAAA;AACD,QAAA,OAAO,KAAK,CAAC;IAChB,CAAC;AAED,IAAA,KAAK,CAAC,EAAO,EAAA;AACV,QAAA,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEhB,QAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;;YAExB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,CAAC,KAAI;gBACpC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,YAAA,CAAC,CAAC,CAAC;AAEH,YAAA,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;;AAG3B,YAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAE3B,YAAA,OAAO,MAAM,CAAC;AACjB,QAAA,CAAC,EAAgB;IACpB,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { XVInstanceType, Infer } from '../types.js';
|
|
2
|
+
import XanvType from '../XanvType.js';
|
|
3
|
+
|
|
4
|
+
type Func<A extends XVInstanceType[], R extends XVInstanceType> = (...args: {
|
|
5
|
+
[K in keyof A]: Infer<A[K]>;
|
|
6
|
+
}) => Infer<R>;
|
|
7
|
+
declare class XVFunction<A extends XVInstanceType[], R extends XVInstanceType> extends XanvType<Func<A, R>, unknown> {
|
|
8
|
+
private _args;
|
|
9
|
+
private _return;
|
|
10
|
+
constructor(args: A, ret: R);
|
|
11
|
+
protected check(value: any): Func<A, R>;
|
|
12
|
+
parse(fn: any): Func<A, R>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { XVFunction as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import XanvType from '../XanvType.js';
|
|
2
|
+
|
|
3
|
+
class XVFunction extends XanvType {
|
|
4
|
+
constructor(args, ret) {
|
|
5
|
+
super();
|
|
6
|
+
this._args = args;
|
|
7
|
+
this._return = ret;
|
|
8
|
+
}
|
|
9
|
+
check(value) {
|
|
10
|
+
if (typeof value !== "function") {
|
|
11
|
+
throw new Error(`Value should be a function, received ${typeof value}`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
parse(fn) {
|
|
16
|
+
super.parse(fn);
|
|
17
|
+
return ((...args) => {
|
|
18
|
+
// Validate each argument
|
|
19
|
+
this._args.forEach((argValidator, i) => {
|
|
20
|
+
argValidator.parse(args[i]);
|
|
21
|
+
});
|
|
22
|
+
const result = fn(...args);
|
|
23
|
+
// Validate return value
|
|
24
|
+
this._return.parse(result);
|
|
25
|
+
return result;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { XVFunction as default };
|
|
31
|
+
//# sourceMappingURL=Function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Function.js","sources":["../../src/types/Function.ts"],"sourcesContent":["import { Infer, XVInstanceType } from \"../types\";\r\nimport XanvType from \"../XanvType\";\r\n\r\ntype Func<A extends XVInstanceType[], R extends XVInstanceType> =\r\n (...args: { [K in keyof A]: Infer<A[K]> }) => Infer<R>;\r\n\r\nclass XVFunction<A extends XVInstanceType[], R extends XVInstanceType>\r\n extends XanvType<Func<A, R>, unknown> {\r\n\r\n private _args: A;\r\n private _return: R;\r\n\r\n constructor(args: A, ret: R) {\r\n super();\r\n this._args = args;\r\n this._return = ret;\r\n }\r\n\r\n protected check(value: any): Func<A, R> {\r\n if (typeof value !== \"function\") {\r\n throw new Error(`Value should be a function, received ${typeof value}`);\r\n }\r\n return value;\r\n }\r\n\r\n parse(fn: any): Func<A, R> {\r\n super.parse(fn);\r\n\r\n return ((...args: any[]) => {\r\n // Validate each argument\r\n this._args.forEach((argValidator, i) => {\r\n argValidator.parse(args[i]);\r\n });\r\n\r\n const result = fn(...args);\r\n\r\n // Validate return value\r\n this._return.parse(result);\r\n\r\n return result;\r\n }) as Func<A, R>;\r\n }\r\n}\r\n\r\nexport default XVFunction;\r\n"],"names":[],"mappings":";;AAMA,MAAM,UACH,SAAQ,QAA6B,CAAA;IAKrC,WAAA,CAAY,IAAO,EAAE,GAAM,EAAA;AACxB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;AAClB,QAAA,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACtB,CAAC;AAES,IAAA,KAAK,CAAC,KAAU,EAAA;AACvB,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,CAAA,qCAAA,EAAwC,OAAO,KAAK,CAAA,CAAE,CAAC,CAAC;AAC1E,QAAA,CAAA;AACD,QAAA,OAAO,KAAK,CAAC;IAChB,CAAC;AAED,IAAA,KAAK,CAAC,EAAO,EAAA;AACV,QAAA,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEhB,QAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;;YAExB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,CAAC,KAAI;gBACpC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,YAAA,CAAC,CAAC,CAAC;AAEH,YAAA,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;;AAG3B,YAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAE3B,YAAA,OAAO,MAAM,CAAC;AACjB,QAAA,CAAC,EAAgB;IACpB,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var XanvType = require('../XanvType.cjs');
|
|
4
|
+
|
|
5
|
+
class XVPromise extends XanvType {
|
|
6
|
+
constructor(inner) {
|
|
7
|
+
super();
|
|
8
|
+
this._inner = inner;
|
|
9
|
+
}
|
|
10
|
+
check(value) {
|
|
11
|
+
if (!(value instanceof Promise)) {
|
|
12
|
+
throw new Error(`Value should be a Promise, received ${typeof value}`);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
parse(value) {
|
|
17
|
+
super.parse(value);
|
|
18
|
+
// Wrap the promise so the resolved value is validated
|
|
19
|
+
return value.then((res) => {
|
|
20
|
+
if (this._inner) {
|
|
21
|
+
this._inner.parse(res);
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = XVPromise;
|
|
29
|
+
//# sourceMappingURL=Promise.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Promise.cjs","sources":["../../src/types/Promise.ts"],"sourcesContent":["import XanvType from \"../XanvType\";\r\nimport { XVInstanceType, Infer } from \"../types\";\r\n\r\nclass XVPromise<T extends XVInstanceType> extends XanvType<Promise<Infer<T>>, unknown> {\r\n private _inner: T;\r\n\r\n constructor(inner: T) {\r\n super();\r\n this._inner = inner;\r\n }\r\n\r\n protected check(value: any): Promise<Infer<T>> {\r\n if (!(value instanceof Promise)) {\r\n throw new Error(`Value should be a Promise, received ${typeof value}`);\r\n }\r\n return value;\r\n }\r\n\r\n parse(value: any): Promise<Infer<T>> {\r\n super.parse(value);\r\n\r\n // Wrap the promise so the resolved value is validated\r\n return (value as Promise<any>).then((res) => {\r\n if (this._inner) {\r\n this._inner.parse(res);\r\n }\r\n return res;\r\n });\r\n }\r\n}\r\n\r\nexport default XVPromise;\r\n"],"names":[],"mappings":";;;;AAGA,MAAM,SAAoC,SAAQ,QAAoC,CAAA;AAGnF,IAAA,WAAA,CAAY,KAAQ,EAAA;AACjB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACvB,CAAC;AAES,IAAA,KAAK,CAAC,KAAU,EAAA;AACvB,QAAA,IAAI,EAAE,KAAK,YAAY,OAAO,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,CAAA,oCAAA,EAAuC,OAAO,KAAK,CAAA,CAAE,CAAC,CAAC;AACzE,QAAA,CAAA;AACD,QAAA,OAAO,KAAK,CAAC;IAChB,CAAC;AAED,IAAA,KAAK,CAAC,KAAU,EAAA;AACb,QAAA,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAGnB,QAAA,OAAQ,KAAsB,CAAC,IAAI,CAAC,CAAC,GAAG,KAAI;YACzC,IAAI,IAAI,CAAC,MAAM,EAAE;AACd,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,YAAA,CAAA;AACD,YAAA,OAAO,GAAG,CAAC;AACd,QAAA,CAAC,CAAC,CAAC;IACN,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import XanvType from '../XanvType.js';
|
|
2
|
+
import { XVInstanceType, Infer } from '../types.js';
|
|
3
|
+
|
|
4
|
+
declare class XVPromise<T extends XVInstanceType> extends XanvType<Promise<Infer<T>>, unknown> {
|
|
5
|
+
private _inner;
|
|
6
|
+
constructor(inner: T);
|
|
7
|
+
protected check(value: any): Promise<Infer<T>>;
|
|
8
|
+
parse(value: any): Promise<Infer<T>>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { XVPromise as default };
|
package/types/Promise.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import XanvType from '../XanvType.js';
|
|
2
|
+
|
|
3
|
+
class XVPromise extends XanvType {
|
|
4
|
+
constructor(inner) {
|
|
5
|
+
super();
|
|
6
|
+
this._inner = inner;
|
|
7
|
+
}
|
|
8
|
+
check(value) {
|
|
9
|
+
if (!(value instanceof Promise)) {
|
|
10
|
+
throw new Error(`Value should be a Promise, received ${typeof value}`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
parse(value) {
|
|
15
|
+
super.parse(value);
|
|
16
|
+
// Wrap the promise so the resolved value is validated
|
|
17
|
+
return value.then((res) => {
|
|
18
|
+
if (this._inner) {
|
|
19
|
+
this._inner.parse(res);
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { XVPromise as default };
|
|
27
|
+
//# sourceMappingURL=Promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Promise.js","sources":["../../src/types/Promise.ts"],"sourcesContent":["import XanvType from \"../XanvType\";\r\nimport { XVInstanceType, Infer } from \"../types\";\r\n\r\nclass XVPromise<T extends XVInstanceType> extends XanvType<Promise<Infer<T>>, unknown> {\r\n private _inner: T;\r\n\r\n constructor(inner: T) {\r\n super();\r\n this._inner = inner;\r\n }\r\n\r\n protected check(value: any): Promise<Infer<T>> {\r\n if (!(value instanceof Promise)) {\r\n throw new Error(`Value should be a Promise, received ${typeof value}`);\r\n }\r\n return value;\r\n }\r\n\r\n parse(value: any): Promise<Infer<T>> {\r\n super.parse(value);\r\n\r\n // Wrap the promise so the resolved value is validated\r\n return (value as Promise<any>).then((res) => {\r\n if (this._inner) {\r\n this._inner.parse(res);\r\n }\r\n return res;\r\n });\r\n }\r\n}\r\n\r\nexport default XVPromise;\r\n"],"names":[],"mappings":";;AAGA,MAAM,SAAoC,SAAQ,QAAoC,CAAA;AAGnF,IAAA,WAAA,CAAY,KAAQ,EAAA;AACjB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACvB,CAAC;AAES,IAAA,KAAK,CAAC,KAAU,EAAA;AACvB,QAAA,IAAI,EAAE,KAAK,YAAY,OAAO,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,CAAA,oCAAA,EAAuC,OAAO,KAAK,CAAA,CAAE,CAAC,CAAC;AACzE,QAAA,CAAA;AACD,QAAA,OAAO,KAAK,CAAC;IAChB,CAAC;AAED,IAAA,KAAK,CAAC,KAAU,EAAA;AACb,QAAA,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAGnB,QAAA,OAAQ,KAAsB,CAAC,IAAI,CAAC,CAAC,GAAG,KAAI;YACzC,IAAI,IAAI,CAAC,MAAM,EAAE;AACd,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,YAAA,CAAA;AACD,YAAA,OAAO,GAAG,CAAC;AACd,QAAA,CAAC,CAAC,CAAC;IACN,CAAC;AACH;;;;"}
|
package/types.d.ts
CHANGED
|
@@ -4,17 +4,19 @@ import XVBoolean from './types/Boolean.js';
|
|
|
4
4
|
import XVDate from './types/Date.js';
|
|
5
5
|
import XVEnum from './types/Enum.js';
|
|
6
6
|
import XVFile from './types/File.js';
|
|
7
|
+
import XVFunction from './types/Function.js';
|
|
7
8
|
import XVJson from './types/Json.js';
|
|
8
9
|
import XVMap from './types/Map.js';
|
|
9
10
|
import XVNumber from './types/Number.js';
|
|
10
11
|
import XVObject, { XVObjectShape } from './types/Object.js';
|
|
12
|
+
import XVPromise from './types/Promise.js';
|
|
11
13
|
import XVRecord from './types/Record.js';
|
|
12
14
|
import XVSet from './types/Set.js';
|
|
13
15
|
import XVString from './types/String.js';
|
|
14
16
|
import XVTuple from './types/Tuple.js';
|
|
15
17
|
import XVUnion from './types/Union.js';
|
|
16
18
|
|
|
17
|
-
type XVInstanceType = XVAny | XVArray<any> | XVBoolean | XVDate | XVEnum<any> | XVFile | XVMap<any, any> | XVNumber | XVObject<XVObjectShape> | XVRecord<XVInstanceType, XVInstanceType> | XVSet<any> | XVString | XVTuple<any> | XVUnion<any> | XVJson<Record<string, any
|
|
19
|
+
type XVInstanceType = XVAny | XVArray<any> | XVBoolean | XVDate | XVEnum<any> | XVFile | XVMap<any, any> | XVNumber | XVObject<XVObjectShape> | XVRecord<XVInstanceType, XVInstanceType> | XVSet<any> | XVString | XVTuple<any> | XVUnion<any> | XVJson<Record<string, any>> | XVFunction<any[], any> | XVPromise<any>;
|
|
18
20
|
type XVCheckCallback<T> = (value: T) => void;
|
|
19
21
|
type Dec<N extends number> = N extends 5 ? 4 : N extends 4 ? 3 : N extends 3 ? 2 : N extends 2 ? 1 : N extends 1 ? 0 : 0;
|
|
20
22
|
type Infer<T, Depth extends number = 5> = Depth extends 0 ? any : T extends {
|
|
@@ -31,7 +33,9 @@ type Infer<T, Depth extends number = 5> = Depth extends 0 ? any : T extends {
|
|
|
31
33
|
nullable: true;
|
|
32
34
|
};
|
|
33
35
|
} ? InferType<T, Dec<Depth>> | null : InferType<T, Dec<Depth>>;
|
|
34
|
-
type InferType<T, Depth extends number> = T extends
|
|
36
|
+
type InferType<T, Depth extends number> = T extends XVFunction<infer A extends XVInstanceType[], infer R> ? (...args: {
|
|
37
|
+
[K in keyof A]: Infer<A[K], Depth>;
|
|
38
|
+
}) => Infer<R, Depth> : T extends XVPromise<infer U> ? Promise<Infer<U, Depth>> : T extends XVString ? string : T extends XVNumber ? number : T extends XVBoolean ? boolean : T extends XVDate ? Date : T extends XVAny ? any : T extends XVFile ? File | Blob : T extends XVEnum<infer U> ? U[number] : T extends XVArray<infer U> ? Infer<U, Depth>[] : T extends XVTuple<infer U extends XVInstanceType[]> ? {
|
|
35
39
|
[K in keyof U]: Infer<U[K], Depth>;
|
|
36
40
|
} : T extends XVUnion<infer U extends XVInstanceType[]> ? Infer<U[number], Depth> : T extends XVMap<infer K, infer V> ? Map<Infer<K, Depth>, Infer<V, Depth>> : T extends XVSet<infer U> ? Set<Infer<U, Depth>> : T extends XVRecord<infer K, infer V> ? Record<Infer<K, Depth>, Infer<V, Depth>> : T extends XVJson ? Record<string, any> : T extends XVObject<infer O> ? {
|
|
37
41
|
[K in keyof O]: Infer<O[K], Depth>;
|