@wizzard-packages/adapter-zod 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aziz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // src/ZodAdapter.ts
4
+ var ZodAdapter = class {
5
+ constructor(schema) {
6
+ this.schema = schema;
7
+ }
8
+ async validate(data) {
9
+ const result = await this.schema.safeParseAsync(data);
10
+ if (result.success) {
11
+ return { isValid: true };
12
+ }
13
+ const errors = {};
14
+ if (result.error) {
15
+ result.error.issues.forEach((err) => {
16
+ const path = err.path.join(".");
17
+ errors[path] = err.message;
18
+ });
19
+ }
20
+ return { isValid: false, errors };
21
+ }
22
+ };
23
+
24
+ exports.ZodAdapter = ZodAdapter;
25
+ //# sourceMappingURL=index.cjs.map
26
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ZodAdapter.ts"],"names":[],"mappings":";;;AAMO,IAAM,aAAN,MAAoD;AAAA,EAGzD,YAAY,MAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EAEA,MAAM,SAAS,IAAA,EAA0C;AACvD,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,MAAA,CAAO,eAAe,IAAS,CAAA;AACzD,IAAA,IAAI,OAAO,OAAA,EAAS;AAClB,MAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AAAA,IACzB;AAEA,IAAA,MAAM,SAAiC,EAAC;AACxC,IAAA,IAAI,OAAO,KAAA,EAAO;AAChB,MAAA,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,OAAA,CAAQ,CAAC,GAAA,KAAQ;AACnC,QAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAC9B,QAAA,MAAA,CAAO,IAAI,IAAI,GAAA,CAAI,OAAA;AAAA,MACrB,CAAC,CAAA;AAAA,IACH;AACA,IAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,EAClC;AACF","file":"index.cjs","sourcesContent":["import type { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';\nimport type { ZodLikeSchema } from './types';\n\n/**\n * Validation adapter for Zod-like schemas.\n */\nexport class ZodAdapter<T> implements IValidatorAdapter<T> {\n private schema: ZodLikeSchema<T>;\n\n constructor(schema: ZodLikeSchema<T>) {\n this.schema = schema;\n }\n\n async validate(data: unknown): Promise<ValidationResult> {\n const result = await this.schema.safeParseAsync(data as T);\n if (result.success) {\n return { isValid: true };\n }\n\n const errors: Record<string, string> = {};\n if (result.error) {\n result.error.issues.forEach((err) => {\n const path = err.path.join('.');\n errors[path] = err.message;\n });\n }\n return { isValid: false, errors };\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';
2
+
3
+ /**
4
+ * Minimal structural interface for Zod-like schemas.
5
+ */
6
+ interface ZodLikeSchema<T = any> {
7
+ safeParseAsync: (data: T) => Promise<{
8
+ success: boolean;
9
+ data?: T;
10
+ error?: {
11
+ issues: Array<{
12
+ path: any[];
13
+ message: string;
14
+ }>;
15
+ };
16
+ }>;
17
+ }
18
+
19
+ /**
20
+ * Validation adapter for Zod-like schemas.
21
+ */
22
+ declare class ZodAdapter<T> implements IValidatorAdapter<T> {
23
+ private schema;
24
+ constructor(schema: ZodLikeSchema<T>);
25
+ validate(data: unknown): Promise<ValidationResult>;
26
+ }
27
+
28
+ export { ZodAdapter, type ZodLikeSchema };
@@ -0,0 +1,28 @@
1
+ import { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';
2
+
3
+ /**
4
+ * Minimal structural interface for Zod-like schemas.
5
+ */
6
+ interface ZodLikeSchema<T = any> {
7
+ safeParseAsync: (data: T) => Promise<{
8
+ success: boolean;
9
+ data?: T;
10
+ error?: {
11
+ issues: Array<{
12
+ path: any[];
13
+ message: string;
14
+ }>;
15
+ };
16
+ }>;
17
+ }
18
+
19
+ /**
20
+ * Validation adapter for Zod-like schemas.
21
+ */
22
+ declare class ZodAdapter<T> implements IValidatorAdapter<T> {
23
+ private schema;
24
+ constructor(schema: ZodLikeSchema<T>);
25
+ validate(data: unknown): Promise<ValidationResult>;
26
+ }
27
+
28
+ export { ZodAdapter, type ZodLikeSchema };
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ // src/ZodAdapter.ts
2
+ var ZodAdapter = class {
3
+ constructor(schema) {
4
+ this.schema = schema;
5
+ }
6
+ async validate(data) {
7
+ const result = await this.schema.safeParseAsync(data);
8
+ if (result.success) {
9
+ return { isValid: true };
10
+ }
11
+ const errors = {};
12
+ if (result.error) {
13
+ result.error.issues.forEach((err) => {
14
+ const path = err.path.join(".");
15
+ errors[path] = err.message;
16
+ });
17
+ }
18
+ return { isValid: false, errors };
19
+ }
20
+ };
21
+
22
+ export { ZodAdapter };
23
+ //# sourceMappingURL=index.js.map
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ZodAdapter.ts"],"names":[],"mappings":";AAMO,IAAM,aAAN,MAAoD;AAAA,EAGzD,YAAY,MAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EAEA,MAAM,SAAS,IAAA,EAA0C;AACvD,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,MAAA,CAAO,eAAe,IAAS,CAAA;AACzD,IAAA,IAAI,OAAO,OAAA,EAAS;AAClB,MAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AAAA,IACzB;AAEA,IAAA,MAAM,SAAiC,EAAC;AACxC,IAAA,IAAI,OAAO,KAAA,EAAO;AAChB,MAAA,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,OAAA,CAAQ,CAAC,GAAA,KAAQ;AACnC,QAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAC9B,QAAA,MAAA,CAAO,IAAI,IAAI,GAAA,CAAI,OAAA;AAAA,MACrB,CAAC,CAAA;AAAA,IACH;AACA,IAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,EAClC;AACF","file":"index.js","sourcesContent":["import type { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';\nimport type { ZodLikeSchema } from './types';\n\n/**\n * Validation adapter for Zod-like schemas.\n */\nexport class ZodAdapter<T> implements IValidatorAdapter<T> {\n private schema: ZodLikeSchema<T>;\n\n constructor(schema: ZodLikeSchema<T>) {\n this.schema = schema;\n }\n\n async validate(data: unknown): Promise<ValidationResult> {\n const result = await this.schema.safeParseAsync(data as T);\n if (result.success) {\n return { isValid: true };\n }\n\n const errors: Record<string, string> = {};\n if (result.error) {\n result.error.issues.forEach((err) => {\n const path = err.path.join('.');\n errors[path] = err.message;\n });\n }\n return { isValid: false, errors };\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@wizzard-packages/adapter-zod",
3
+ "version": "0.1.0",
4
+ "description": "Zod validation adapter for Wizzard Stepper.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/ZizzX/wizzard-packages.git",
8
+ "directory": "packages/adapter-zod"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.cjs",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@wizzard-packages/core": "0.1.0"
29
+ },
30
+ "devDependencies": {
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.7.2",
33
+ "vitest": "^4.0.16",
34
+ "zod": "^4.2.1"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "dev": "tsup src/index.ts --format cjs,esm --watch --dts",
39
+ "lint": "eslint .",
40
+ "test": "vitest",
41
+ "test:run": "vitest run",
42
+ "type-check": "tsc --noEmit"
43
+ }
44
+ }