@getvision/adapter-hono 0.0.10 → 0.1.0-6e5c887-develop

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @getvision/adapter-hono
2
2
 
3
+ ## 0.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d5bfbe0]
8
+ - @getvision/core@0.1.0
9
+
3
10
  ## 0.0.10
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -57,5 +57,5 @@ export declare function enableAutoDiscovery(app: any, options?: {
57
57
  * Get the Vision instance (for advanced usage)
58
58
  */
59
59
  export declare function getVisionInstance(): VisionCore | null;
60
- export { zValidator } from './zod-validator';
60
+ export { validator, zValidator } from './validator';
61
61
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,iBAAiB,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EACL,UAAU,EAQX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAiB,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAM1F,UAAU,aAAa;IACrB,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAChB;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAMhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,qFAG5B;AAyID,wBAAgB,aAAa,CAAC,OAAO,GAAE,iBAAsB,GAAG,iBAAiB,CA2OhF;AAqGD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,QAGzF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,GAAG,IAAI,CAErD;AAID,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,iBAAiB,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,EACL,UAAU,EAQX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAiB,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAK1F,UAAU,aAAa;IACrB,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAChB;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAMhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,qFAG5B;AAyID,wBAAgB,aAAa,CAAC,OAAO,GAAE,iBAAsB,GAAG,iBAAiB,CA2OhF;AAqGD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,QAGzF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,GAAG,IAAI,CAErD;AAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { VisionCore, generateZodTemplate, autoDetectPackageInfo, autoDetectIntegrations, detectDrizzle, startDrizzleStudio, stopDrizzleStudio, runInTraceContext, } from '@getvision/core';
1
+ import { VisionCore, generateTemplate, autoDetectPackageInfo, autoDetectIntegrations, detectDrizzle, startDrizzleStudio, stopDrizzleStudio, runInTraceContext, } from '@getvision/core';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
- import { extractSchema } from './zod-validator';
3
+ import { extractSchema } from "./validator";
4
4
  const visionContext = new AsyncLocalStorage();
5
5
  /**
6
6
  * Get current vision context (vision instance and traceId)
@@ -89,7 +89,7 @@ function patchHonoApp(app, options) {
89
89
  for (const handler of handlers) {
90
90
  const schema = extractSchema(handler);
91
91
  if (schema) {
92
- requestBodySchema = generateZodTemplate(schema);
92
+ requestBodySchema = generateTemplate(schema);
93
93
  break;
94
94
  }
95
95
  }
@@ -489,6 +489,4 @@ export function enableAutoDiscovery(app, options) {
489
489
  export function getVisionInstance() {
490
490
  return visionInstance;
491
491
  }
492
- // Re-export monkey-patched zValidator that stores schema for Vision introspection
493
- // Use this instead of @hono/zod-validator to enable automatic schema detection
494
- export { zValidator } from './zod-validator';
492
+ export { validator, zValidator } from './validator';
@@ -1,15 +1,47 @@
1
- import type { ZodType } from 'zod';
1
+ import type { ZodTypeAny } from 'zod';
2
+ import type { MiddlewareHandler } from 'hono';
3
+ import type { StandardSchemaV1, ValidationSchema } from '@getvision/core';
2
4
  /**
3
- * Monkey-patch zValidator to attach schema for Vision introspection
5
+ * Universal validator middleware for Hono that supports any Standard Schema-compliant library
6
+ */
7
+ type ValidationTargetKey = 'json' | 'form' | 'query' | 'param' | 'header';
8
+ export declare function validator<Target extends ValidationTargetKey, S extends ZodTypeAny>(target: Target, schema: S): MiddlewareHandler<any, any, {
9
+ in: {
10
+ [K in Target]: import('zod').infer<S>;
11
+ };
12
+ out: {
13
+ [K in Target]: import('zod').infer<S>;
14
+ };
15
+ }>;
16
+ export declare function validator<Target extends ValidationTargetKey, S extends StandardSchemaV1<any, any>>(target: Target, schema: S): MiddlewareHandler<any, any, {
17
+ in: {
18
+ [K in Target]: StandardSchemaV1.Infer<S>['output'];
19
+ };
20
+ out: {
21
+ [K in Target]: StandardSchemaV1.Infer<S>['output'];
22
+ };
23
+ }>;
24
+ export declare function validator<Target extends ValidationTargetKey>(target: Target, schema: ValidationSchema): MiddlewareHandler<any, any, {
25
+ in: {
26
+ [K in Target]: any;
27
+ };
28
+ out: {
29
+ [K in Target]: any;
30
+ };
31
+ }>;
32
+ /**
33
+ * @deprecated Use validator() instead
34
+ * Backward compatibility: Monkey-patch zValidator to attach schema for Vision introspection
4
35
  */
5
36
  export declare const zValidator: <T extends import("zod/v3").ZodType<any, import("zod/v3").ZodTypeDef, any> | import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Target extends keyof import("hono").ValidationTargets, E extends import("hono").Env, P extends string, In = T extends import("zod/v3").ZodType<any, import("zod/v3").ZodTypeDef, any> ? import("zod/v3").input<T> : T extends import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> ? import("zod").input<T> : never, Out = T extends import("zod/v3").ZodType<any, import("zod/v3").ZodTypeDef, any> ? import("zod/v3").output<T> : T extends import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> ? import("zod").infer<T> : never, I extends import("hono").Input = {
6
37
  in: (undefined extends In ? true : false) extends true ? { [K in Target]?: In extends import("hono").ValidationTargets[K] ? In : { [K2 in keyof In]?: In[K2] extends import("hono").ValidationTargets[K][K2] ? In[K2] : import("hono").ValidationTargets[K][K2]; }; } : { [K in Target]: In extends import("hono").ValidationTargets[K] ? In : { [K2 in keyof In]: In[K2] extends import("hono").ValidationTargets[K][K2] ? In[K2] : import("hono").ValidationTargets[K][K2]; }; };
7
38
  out: { [K in Target]: Out; };
8
39
  }, V extends I = I, InferredValue = T extends import("zod/v3").ZodType<any, import("zod/v3").ZodTypeDef, any> ? import("zod/v3").TypeOf<T> : T extends import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> ? import("zod").infer<T> : never>(target: Target, schema: T, hook?: import("@hono/zod-validator").Hook<InferredValue, E, P, Target, {}, T>, options?: {
9
40
  validationFunction: (schema: T, value: import("hono").ValidationTargets[Target]) => (T extends import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> ? import("zod").ZodSafeParseResult<any> : import("zod/v3").SafeParseReturnType<any, any>) | Promise<T extends import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> ? import("zod").ZodSafeParseResult<any> : import("zod/v3").SafeParseReturnType<any, any>>;
10
- }) => import("hono").MiddlewareHandler<E, P, V>;
41
+ }) => MiddlewareHandler<E, P, V>;
11
42
  /**
12
43
  * Extract schema from validator middleware
13
44
  */
14
- export declare function extractSchema(validator: any): ZodType | undefined;
15
- //# sourceMappingURL=zod-validator.d.ts.map
45
+ export declare function extractSchema(validator: any): ValidationSchema | undefined;
46
+ export {};
47
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,KAAK,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOzE;;GAEG;AACH,KAAK,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEzE,wBAAgB,SAAS,CAAC,MAAM,SAAS,mBAAmB,EAAE,CAAC,SAAS,UAAU,EAChF,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,GACR,iBAAiB,CAClB,GAAG,EACH,GAAG,EACH;IACE,EAAE,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;KAAE,CAAA;IAC7C,GAAG,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;KAAE,CAAA;CAC/C,CACF,CAAA;AAED,wBAAgB,SAAS,CAAC,MAAM,SAAS,mBAAmB,EAAE,CAAC,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAChG,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,GACR,iBAAiB,CAClB,GAAG,EACH,GAAG,EACH;IACE,EAAE,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KAAE,CAAA;IAC1D,GAAG,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KAAE,CAAA;CAC5D,CACF,CAAA;AAED,wBAAgB,SAAS,CAAC,MAAM,SAAS,mBAAmB,EAC1D,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,GACvB,iBAAiB,CAClB,GAAG,EACH,GAAG,EACH;IACE,EAAE,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,GAAG;KAAE,CAAA;IAC1B,GAAG,EAAE;SAAG,CAAC,IAAI,MAAM,GAAG,GAAG;KAAE,CAAA;CAC5B,CACF,CAAA;AAkDD;;;GAGG;AACH,eAAO,MAAM,UAAU;4EA/CnB,CAAF,0EAGE,CAAD,iBAAiB,mCACF,gBACH,mCAAoB,uHAGkB,mCAEjD,gBACI,mCAAY;;;;gCAiDlB,CAAA;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,GAAG,GAAG,gBAAgB,GAAG,SAAS,CAE1E"}
@@ -0,0 +1,63 @@
1
+ import { zValidator as originalZValidator } from '@hono/zod-validator';
2
+ import { ValidationError, createValidationErrorResponse, UniversalValidator } from '@getvision/core';
3
+ export function validator(target, schema) {
4
+ const middleware = async (c, next) => {
5
+ let data;
6
+ // Extract data based on target
7
+ switch (target) {
8
+ case 'json':
9
+ data = await c.req.json().catch(() => ({}));
10
+ break;
11
+ case 'form':
12
+ data = await c.req.formData().catch(() => ({}));
13
+ break;
14
+ case 'query':
15
+ data = c.req.query();
16
+ break;
17
+ case 'param':
18
+ data = c.req.param();
19
+ break;
20
+ case 'header':
21
+ data = c.req.header();
22
+ break;
23
+ }
24
+ try {
25
+ const validated = UniversalValidator.parse(schema, data);
26
+ // Store in Hono's validation context
27
+ c.set(`valid_${target}`, validated);
28
+ await next();
29
+ }
30
+ catch (error) {
31
+ if (error instanceof ValidationError) {
32
+ const requestId = c.req.header('x-request-id');
33
+ return c.json(createValidationErrorResponse(error.issues, requestId), 400);
34
+ }
35
+ throw error;
36
+ }
37
+ };
38
+ middleware.__visionSchema = schema;
39
+ return middleware;
40
+ }
41
+ /**
42
+ * @deprecated Use validator() instead
43
+ * Backward compatibility: Monkey-patch zValidator to attach schema for Vision introspection
44
+ */
45
+ export const zValidator = new Proxy(originalZValidator, {
46
+ apply(target, thisArg, args) {
47
+ // Call original zValidator
48
+ const validator = Reflect.apply(target, thisArg, args);
49
+ // Attach schema (2nd argument) to the returned middleware handler
50
+ const schema = args[1];
51
+ if (schema && typeof schema === 'object' && '_def' in schema) {
52
+ ;
53
+ validator.__visionSchema = schema;
54
+ }
55
+ return validator;
56
+ }
57
+ });
58
+ /**
59
+ * Extract schema from validator middleware
60
+ */
61
+ export function extractSchema(validator) {
62
+ return validator?.__visionSchema;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getvision/adapter-hono",
3
- "version": "0.0.10",
3
+ "version": "0.1.0-6e5c887-develop",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -13,7 +13,7 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@hono/zod-validator": "^0.7.3",
16
- "@getvision/core": "0.0.8",
16
+ "@getvision/core": "0.1.0",
17
17
  "zod": "^4.1.11"
18
18
  },
19
19
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Context, MiddlewareHandler } from 'hono'
2
2
  import {
3
3
  VisionCore,
4
- generateZodTemplate,
4
+ generateTemplate,
5
5
  autoDetectPackageInfo,
6
6
  autoDetectIntegrations,
7
7
  detectDrizzle,
@@ -10,9 +10,8 @@ import {
10
10
  runInTraceContext,
11
11
  } from '@getvision/core'
12
12
  import type { RouteMetadata, VisionHonoOptions, ServiceDefinition } from '@getvision/core'
13
- import { existsSync } from 'fs'
14
13
  import { AsyncLocalStorage } from 'async_hooks'
15
- import { extractSchema } from './zod-validator'
14
+ import { extractSchema } from "./validator";
16
15
 
17
16
  // Context storage for vision and traceId
18
17
  interface VisionContext {
@@ -114,7 +113,7 @@ function patchHonoApp(app: any, options?: { services?: ServiceDefinition[] }) {
114
113
  for (const handler of handlers) {
115
114
  const schema = extractSchema(handler)
116
115
  if (schema) {
117
- requestBodySchema = generateZodTemplate(schema)
116
+ requestBodySchema = generateTemplate(schema)
118
117
  break
119
118
  }
120
119
  }
@@ -560,6 +559,4 @@ export function getVisionInstance(): VisionCore | null {
560
559
  return visionInstance
561
560
  }
562
561
 
563
- // Re-export monkey-patched zValidator that stores schema for Vision introspection
564
- // Use this instead of @hono/zod-validator to enable automatic schema detection
565
- export { zValidator } from './zod-validator'
562
+ export { validator, zValidator } from './validator';
@@ -0,0 +1,124 @@
1
+ import { zValidator as originalZValidator } from '@hono/zod-validator'
2
+ import type { ZodType, ZodTypeAny } from 'zod'
3
+ import type { MiddlewareHandler } from 'hono'
4
+ import type { StandardSchemaV1, ValidationSchema } from '@getvision/core'
5
+ import {
6
+ ValidationError,
7
+ createValidationErrorResponse,
8
+ UniversalValidator
9
+ } from '@getvision/core'
10
+
11
+ /**
12
+ * Universal validator middleware for Hono that supports any Standard Schema-compliant library
13
+ */
14
+ type ValidationTargetKey = 'json' | 'form' | 'query' | 'param' | 'header'
15
+
16
+ export function validator<Target extends ValidationTargetKey, S extends ZodTypeAny>(
17
+ target: Target,
18
+ schema: S
19
+ ): MiddlewareHandler<
20
+ any,
21
+ any,
22
+ {
23
+ in: { [K in Target]: import('zod').infer<S> }
24
+ out: { [K in Target]: import('zod').infer<S> }
25
+ }
26
+ >
27
+
28
+ export function validator<Target extends ValidationTargetKey, S extends StandardSchemaV1<any, any>>(
29
+ target: Target,
30
+ schema: S
31
+ ): MiddlewareHandler<
32
+ any,
33
+ any,
34
+ {
35
+ in: { [K in Target]: StandardSchemaV1.Infer<S>['output'] }
36
+ out: { [K in Target]: StandardSchemaV1.Infer<S>['output'] }
37
+ }
38
+ >
39
+
40
+ export function validator<Target extends ValidationTargetKey>(
41
+ target: Target,
42
+ schema: ValidationSchema
43
+ ): MiddlewareHandler<
44
+ any,
45
+ any,
46
+ {
47
+ in: { [K in Target]: any }
48
+ out: { [K in Target]: any }
49
+ }
50
+ >
51
+
52
+ export function validator<Target extends ValidationTargetKey>(
53
+ target: Target,
54
+ schema: ValidationSchema
55
+ ): MiddlewareHandler {
56
+ const middleware: MiddlewareHandler = async (c, next) => {
57
+ let data: unknown
58
+
59
+ // Extract data based on target
60
+ switch (target) {
61
+ case 'json':
62
+ data = await c.req.json().catch(() => ({}))
63
+ break
64
+ case 'form':
65
+ data = await c.req.formData().catch(() => ({}))
66
+ break
67
+ case 'query':
68
+ data = c.req.query()
69
+ break
70
+ case 'param':
71
+ data = c.req.param()
72
+ break
73
+ case 'header':
74
+ data = c.req.header()
75
+ break
76
+ }
77
+
78
+ try {
79
+ const validated = UniversalValidator.parse(schema, data)
80
+ // Store in Hono's validation context
81
+ c.set(`valid_${target}`, validated)
82
+ await next()
83
+ } catch (error) {
84
+ if (error instanceof ValidationError) {
85
+ const requestId = c.req.header('x-request-id')
86
+ return c.json(
87
+ createValidationErrorResponse(error.issues, requestId),
88
+ 400
89
+ )
90
+ }
91
+ throw error
92
+ }
93
+ }
94
+
95
+ (middleware as any).__visionSchema = schema
96
+
97
+ return middleware
98
+ }
99
+
100
+ /**
101
+ * @deprecated Use validator() instead
102
+ * Backward compatibility: Monkey-patch zValidator to attach schema for Vision introspection
103
+ */
104
+ export const zValidator = new Proxy(originalZValidator, {
105
+ apply(target, thisArg, args: any[]) {
106
+ // Call original zValidator
107
+ const validator = Reflect.apply(target, thisArg, args)
108
+
109
+ // Attach schema (2nd argument) to the returned middleware handler
110
+ const schema = args[1]
111
+ if (schema && typeof schema === 'object' && '_def' in schema) {
112
+ ;(validator as any).__visionSchema = schema
113
+ }
114
+
115
+ return validator
116
+ }
117
+ })
118
+
119
+ /**
120
+ * Extract schema from validator middleware
121
+ */
122
+ export function extractSchema(validator: any): ValidationSchema | undefined {
123
+ return validator?.__visionSchema
124
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-validator.d.ts","sourceRoot":"","sources":["../src/zod-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,UAAU;4EAqBgrB,CAAC,0EAA2D,CAAC,iBAAgB,mCAAqB,gBAAe,mCAAqB,uHAAuG,mCAAqB,gBAAe,mCAAqB;;;;+CAR3+B,CAAA;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,GAAG,SAAS,CAEjE"}
@@ -1,23 +0,0 @@
1
- import { zValidator as originalZValidator } from '@hono/zod-validator';
2
- /**
3
- * Monkey-patch zValidator to attach schema for Vision introspection
4
- */
5
- export const zValidator = new Proxy(originalZValidator, {
6
- apply(target, thisArg, args) {
7
- // Call original zValidator
8
- const validator = Reflect.apply(target, thisArg, args);
9
- // Attach schema (2nd argument) to the returned middleware handler
10
- const schema = args[1];
11
- if (schema && typeof schema === 'object' && '_def' in schema) {
12
- ;
13
- validator.__visionSchema = schema;
14
- }
15
- return validator;
16
- }
17
- });
18
- /**
19
- * Extract schema from validator middleware
20
- */
21
- export function extractSchema(validator) {
22
- return validator?.__visionSchema;
23
- }
@@ -1,27 +0,0 @@
1
- import { zValidator as originalZValidator } from '@hono/zod-validator'
2
- import type { ZodType } from 'zod'
3
-
4
- /**
5
- * Monkey-patch zValidator to attach schema for Vision introspection
6
- */
7
- export const zValidator = new Proxy(originalZValidator, {
8
- apply(target, thisArg, args: any[]) {
9
- // Call original zValidator
10
- const validator = Reflect.apply(target, thisArg, args)
11
-
12
- // Attach schema (2nd argument) to the returned middleware handler
13
- const schema = args[1]
14
- if (schema && typeof schema === 'object' && '_def' in schema) {
15
- ;(validator as any).__visionSchema = schema
16
- }
17
-
18
- return validator
19
- }
20
- })
21
-
22
- /**
23
- * Extract schema from validator middleware
24
- */
25
- export function extractSchema(validator: any): ZodType | undefined {
26
- return validator?.__visionSchema
27
- }