xanv 1.1.27 → 1.1.28
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/package.json
CHANGED
|
@@ -16,6 +16,12 @@ class XVFunctionComponent extends XVType {
|
|
|
16
16
|
}
|
|
17
17
|
parse(fn) {
|
|
18
18
|
const checked = super.parse(fn);
|
|
19
|
+
if (this.meta.optional && !checked) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (this.meta.nullable && !checked) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
19
25
|
return ((inputProps) => {
|
|
20
26
|
const parsed = {};
|
|
21
27
|
for (const key in this.props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionComponent.cjs","sources":["../../src/types/FunctionComponent.ts"],"sourcesContent":["import { Infer } from \"../types\";\nimport XVType from \"../XVType\";\n\n/**\n * Function component type (sync + async)\n */\ntype FuncComponent<P, Async extends boolean = false> = Async extends true\n ? (props: P) => Promise<any>\n : (props: P) => any;\n\n/**\n * Convert schema props → runtime props\n */\ntype InferProps<P extends Record<string, XVType<any>>> = {\n [K in keyof P]: Infer<P[K]>;\n};\n\nclass XVFunctionComponent<\n P extends Record<string, XVType<any>>,\n Async extends boolean = false,\n> extends XVType<FuncComponent<InferProps<P>, Async>> {\n readonly props: P;\n readonly is_async: Async;\n\n constructor(props: P, async?: Async) {\n super();\n this.props = props;\n this.is_async = (async ?? false) as Async;\n }\n\n protected check(value: unknown): any {\n if (typeof value !== \"function\") {\n throw new Error(\"Component must be a function\");\n }\n return value;\n }\n\n parse(fn: unknown) {\n const checked = super.parse(fn);\n\n return ((inputProps: InferProps<P>) => {\n const parsed: InferProps<P> = {} as InferProps<P>;\n\n for (const key in this.props) {\n parsed[key] = this.props[key].parse((inputProps as any)[key]);\n }\n\n const result = (checked as any)(parsed);\n\n if (this.is_async) {\n return Promise.resolve(result);\n }\n\n return result;\n }) as FuncComponent<InferProps<P>, Async>;\n }\n}\n\nexport default XVFunctionComponent;\n"],"names":[],"mappings":";;;;AAiBA,MAAM,mBAGJ,SAAQ,MAA2C,CAAA;IAInD,WAAA,CAAY,KAAQ,EAAE,KAAa,EAAA;AACjC,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;AAClB,QAAA,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAA,IAAA,IAAL,KAAK,KAAA,MAAA,GAAL,KAAK,GAAI,KAAK,CAAU;IAC3C;AAEU,IAAA,KAAK,CAAC,KAAc,EAAA;AAC5B,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;QACjD;AACA,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,KAAK,CAAC,EAAW,EAAA;QACf,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionComponent.cjs","sources":["../../src/types/FunctionComponent.ts"],"sourcesContent":["import { Infer } from \"../types\";\nimport XVType from \"../XVType\";\n\n/**\n * Function component type (sync + async)\n */\ntype FuncComponent<P, Async extends boolean = false> = Async extends true\n ? (props: P) => Promise<any>\n : (props: P) => any;\n\n/**\n * Convert schema props → runtime props\n */\ntype InferProps<P extends Record<string, XVType<any>>> = {\n [K in keyof P]: Infer<P[K]>;\n};\n\nclass XVFunctionComponent<\n P extends Record<string, XVType<any>>,\n Async extends boolean = false,\n> extends XVType<FuncComponent<InferProps<P>, Async>> {\n readonly props: P;\n readonly is_async: Async;\n\n constructor(props: P, async?: Async) {\n super();\n this.props = props;\n this.is_async = (async ?? false) as Async;\n }\n\n protected check(value: unknown): any {\n if (typeof value !== \"function\") {\n throw new Error(\"Component must be a function\");\n }\n return value;\n }\n\n parse(fn: unknown) {\n const checked = super.parse(fn);\n\n if (this.meta.optional && !checked) {\n return;\n }\n if (this.meta.nullable && !checked) {\n return null;\n }\n\n return ((inputProps: InferProps<P>) => {\n const parsed: InferProps<P> = {} as InferProps<P>;\n\n for (const key in this.props) {\n parsed[key] = this.props[key].parse((inputProps as any)[key]);\n }\n\n const result = (checked as any)(parsed);\n\n if (this.is_async) {\n return Promise.resolve(result);\n }\n\n return result;\n }) as FuncComponent<InferProps<P>, Async>;\n }\n}\n\nexport default XVFunctionComponent;\n"],"names":[],"mappings":";;;;AAiBA,MAAM,mBAGJ,SAAQ,MAA2C,CAAA;IAInD,WAAA,CAAY,KAAQ,EAAE,KAAa,EAAA;AACjC,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;AAClB,QAAA,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAA,IAAA,IAAL,KAAK,KAAA,MAAA,GAAL,KAAK,GAAI,KAAK,CAAU;IAC3C;AAEU,IAAA,KAAK,CAAC,KAAc,EAAA;AAC5B,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;QACjD;AACA,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,KAAK,CAAC,EAAW,EAAA;QACf,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAE/B,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE;YAClC;QACF;QACA,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE;AAClC,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,QAAQ,CAAC,UAAyB,KAAI;YACpC,MAAM,MAAM,GAAkB,EAAmB;AAEjD,YAAA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;AAC5B,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAE,UAAkB,CAAC,GAAG,CAAC,CAAC;YAC/D;AAEA,YAAA,MAAM,MAAM,GAAI,OAAe,CAAC,MAAM,CAAC;AAEvC,YAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,gBAAA,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YAChC;AAEA,YAAA,OAAO,MAAM;AACf,QAAA,CAAC;IACH;AACD;;;;"}
|
|
@@ -16,7 +16,7 @@ declare class XVFunctionComponent<P extends Record<string, XVType<any>>, Async e
|
|
|
16
16
|
readonly is_async: Async;
|
|
17
17
|
constructor(props: P, async?: Async);
|
|
18
18
|
protected check(value: unknown): any;
|
|
19
|
-
parse(fn: unknown): FuncComponent<InferProps<P>, Async
|
|
19
|
+
parse(fn: unknown): FuncComponent<InferProps<P>, Async> | null | undefined;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { XVFunctionComponent as default };
|
|
@@ -14,6 +14,12 @@ class XVFunctionComponent extends XVType {
|
|
|
14
14
|
}
|
|
15
15
|
parse(fn) {
|
|
16
16
|
const checked = super.parse(fn);
|
|
17
|
+
if (this.meta.optional && !checked) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (this.meta.nullable && !checked) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
17
23
|
return ((inputProps) => {
|
|
18
24
|
const parsed = {};
|
|
19
25
|
for (const key in this.props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionComponent.js","sources":["../../src/types/FunctionComponent.ts"],"sourcesContent":["import { Infer } from \"../types\";\nimport XVType from \"../XVType\";\n\n/**\n * Function component type (sync + async)\n */\ntype FuncComponent<P, Async extends boolean = false> = Async extends true\n ? (props: P) => Promise<any>\n : (props: P) => any;\n\n/**\n * Convert schema props → runtime props\n */\ntype InferProps<P extends Record<string, XVType<any>>> = {\n [K in keyof P]: Infer<P[K]>;\n};\n\nclass XVFunctionComponent<\n P extends Record<string, XVType<any>>,\n Async extends boolean = false,\n> extends XVType<FuncComponent<InferProps<P>, Async>> {\n readonly props: P;\n readonly is_async: Async;\n\n constructor(props: P, async?: Async) {\n super();\n this.props = props;\n this.is_async = (async ?? false) as Async;\n }\n\n protected check(value: unknown): any {\n if (typeof value !== \"function\") {\n throw new Error(\"Component must be a function\");\n }\n return value;\n }\n\n parse(fn: unknown) {\n const checked = super.parse(fn);\n\n return ((inputProps: InferProps<P>) => {\n const parsed: InferProps<P> = {} as InferProps<P>;\n\n for (const key in this.props) {\n parsed[key] = this.props[key].parse((inputProps as any)[key]);\n }\n\n const result = (checked as any)(parsed);\n\n if (this.is_async) {\n return Promise.resolve(result);\n }\n\n return result;\n }) as FuncComponent<InferProps<P>, Async>;\n }\n}\n\nexport default XVFunctionComponent;\n"],"names":[],"mappings":";;AAiBA,MAAM,mBAGJ,SAAQ,MAA2C,CAAA;IAInD,WAAA,CAAY,KAAQ,EAAE,KAAa,EAAA;AACjC,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;AAClB,QAAA,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAA,IAAA,IAAL,KAAK,KAAA,MAAA,GAAL,KAAK,GAAI,KAAK,CAAU;IAC3C;AAEU,IAAA,KAAK,CAAC,KAAc,EAAA;AAC5B,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;QACjD;AACA,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,KAAK,CAAC,EAAW,EAAA;QACf,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionComponent.js","sources":["../../src/types/FunctionComponent.ts"],"sourcesContent":["import { Infer } from \"../types\";\nimport XVType from \"../XVType\";\n\n/**\n * Function component type (sync + async)\n */\ntype FuncComponent<P, Async extends boolean = false> = Async extends true\n ? (props: P) => Promise<any>\n : (props: P) => any;\n\n/**\n * Convert schema props → runtime props\n */\ntype InferProps<P extends Record<string, XVType<any>>> = {\n [K in keyof P]: Infer<P[K]>;\n};\n\nclass XVFunctionComponent<\n P extends Record<string, XVType<any>>,\n Async extends boolean = false,\n> extends XVType<FuncComponent<InferProps<P>, Async>> {\n readonly props: P;\n readonly is_async: Async;\n\n constructor(props: P, async?: Async) {\n super();\n this.props = props;\n this.is_async = (async ?? false) as Async;\n }\n\n protected check(value: unknown): any {\n if (typeof value !== \"function\") {\n throw new Error(\"Component must be a function\");\n }\n return value;\n }\n\n parse(fn: unknown) {\n const checked = super.parse(fn);\n\n if (this.meta.optional && !checked) {\n return;\n }\n if (this.meta.nullable && !checked) {\n return null;\n }\n\n return ((inputProps: InferProps<P>) => {\n const parsed: InferProps<P> = {} as InferProps<P>;\n\n for (const key in this.props) {\n parsed[key] = this.props[key].parse((inputProps as any)[key]);\n }\n\n const result = (checked as any)(parsed);\n\n if (this.is_async) {\n return Promise.resolve(result);\n }\n\n return result;\n }) as FuncComponent<InferProps<P>, Async>;\n }\n}\n\nexport default XVFunctionComponent;\n"],"names":[],"mappings":";;AAiBA,MAAM,mBAGJ,SAAQ,MAA2C,CAAA;IAInD,WAAA,CAAY,KAAQ,EAAE,KAAa,EAAA;AACjC,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;AAClB,QAAA,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAA,IAAA,IAAL,KAAK,KAAA,MAAA,GAAL,KAAK,GAAI,KAAK,CAAU;IAC3C;AAEU,IAAA,KAAK,CAAC,KAAc,EAAA;AAC5B,QAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;QACjD;AACA,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,KAAK,CAAC,EAAW,EAAA;QACf,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAE/B,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE;YAClC;QACF;QACA,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE;AAClC,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,QAAQ,CAAC,UAAyB,KAAI;YACpC,MAAM,MAAM,GAAkB,EAAmB;AAEjD,YAAA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;AAC5B,gBAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAE,UAAkB,CAAC,GAAG,CAAC,CAAC;YAC/D;AAEA,YAAA,MAAM,MAAM,GAAI,OAAe,CAAC,MAAM,CAAC;AAEvC,YAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,gBAAA,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YAChC;AAEA,YAAA,OAAO,MAAM;AACf,QAAA,CAAC;IACH;AACD;;;;"}
|