@kaapi/validator-zod 0.0.17 → 0.0.19

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.
Files changed (2) hide show
  1. package/lib/types.d.ts +10 -5
  2. package/package.json +17 -10
package/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ReqRefDefaults, ReqRef, KaapiServerRoute, HandlerDecorations, Lifecycle, Server } from '@kaapi/kaapi';
1
+ import type { ReqRefDefaults, ReqRef, KaapiServerRoute, HandlerDecorations, Lifecycle, Server, MergeRefs } from '@kaapi/kaapi';
2
2
  import { z, type ZodType } from 'zod';
3
3
  import type { ParseContext, $ZodIssue } from 'zod/v4/core';
4
4
  export type ZodSchema = ZodType<any, any> | undefined | null;
@@ -14,11 +14,16 @@ export type ValidatorZodSchema = {
14
14
  };
15
15
  export type ZodlessReqRefDefaults = Omit<ReqRefDefaults, 'Query' | 'Headers' | 'Params' | 'Payload'>;
16
16
  export type ZodlessReqRef = Omit<ReqRef, 'Query' | 'Headers' | 'Params' | 'Payload'>;
17
+ export type output<T, D = unknown> = T extends {
18
+ _zod: {
19
+ output: any;
20
+ };
21
+ } ? z.infer<T> : D;
17
22
  export interface ValidatorZodReqRef<RS extends ValidatorZodSchema = ValidatorZodSchema> {
18
- Query: z.infer<RS['query']>;
19
- Headers: z.infer<RS['headers']>;
20
- Params: z.infer<RS['params']>;
21
- Payload: z.infer<RS['payload']>;
23
+ Query: output<RS['query'], MergeRefs<ZodlessReqRefDefaults>['Query']>;
24
+ Headers: output<RS['headers'], MergeRefs<ZodlessReqRefDefaults>['Headers']>;
25
+ Params: output<RS['params'], MergeRefs<ZodlessReqRefDefaults>['Params']>;
26
+ Payload: output<RS['payload'], MergeRefs<ZodlessReqRefDefaults>['Payload']>;
22
27
  }
23
28
  export type ValidatorZod = <V extends ValidatorZodSchema>(schema: V) => {
24
29
  route<R extends ZodlessReqRef = ZodlessReqRefDefaults>(serverRoute: KaapiServerRoute<ValidatorZodReqRef<V> & R>, handler?: HandlerDecorations | Lifecycle.Method<ValidatorZodReqRef<V> & R, Lifecycle.ReturnValue<ValidatorZodReqRef<V> & R>>): Server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaapi/validator-zod",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "private": false,
5
5
  "description": "Zod-powered request validation and documentation plugin for Kaapi.",
6
6
  "main": "lib/index.js",
@@ -10,12 +10,13 @@
10
10
  "default": "./lib/index.js"
11
11
  }
12
12
  },
13
- "scripts": {
14
- "lint": "eslint .",
15
- "build": "tsc && node ./scripts/buildDT.mjs",
16
- "test": "kaukau --require ts-node/register --config kaukau.config.mjs",
17
- "coverage": "c8 npm test"
18
- },
13
+ "keywords": [
14
+ "kaapi",
15
+ "hapi",
16
+ "zod",
17
+ "typescript",
18
+ "validation"
19
+ ],
19
20
  "author": "demingongo",
20
21
  "repository": {
21
22
  "type": "git",
@@ -25,15 +26,21 @@
25
26
  "license": "MIT",
26
27
  "dependencies": {
27
28
  "@hapi/boom": "^10.0.1",
28
- "@kaapi/kaapi": "workspace:^",
29
29
  "@novice1/api-doc-zod-helper": "^0.1.9",
30
30
  "tslib": "^2.8.1",
31
- "zod": "^4.1.12"
31
+ "zod": "^4.1.12",
32
+ "@kaapi/kaapi": "^0.0.19"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "zod": "^4.0.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/mocha": "^10.0.10"
39
+ },
40
+ "scripts": {
41
+ "lint": "eslint .",
42
+ "build": "tsc && node ./scripts/buildDT.mjs",
43
+ "test": "kaukau --require ts-node/register --config kaukau.config.mjs",
44
+ "coverage": "c8 npm test"
38
45
  }
39
- }
46
+ }