@wizzard-packages/adapter-yup 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 +21 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
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,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/YupAdapter.ts
|
|
4
|
+
var YupAdapter = class {
|
|
5
|
+
constructor(schema) {
|
|
6
|
+
this.schema = schema;
|
|
7
|
+
}
|
|
8
|
+
async validate(data) {
|
|
9
|
+
try {
|
|
10
|
+
await this.schema.validate(data, { abortEarly: false });
|
|
11
|
+
return { isValid: true };
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err && typeof err === "object" && "inner" in err) {
|
|
14
|
+
const yupError = err;
|
|
15
|
+
const errors = {};
|
|
16
|
+
yupError.inner.forEach((error) => {
|
|
17
|
+
if (error.path) {
|
|
18
|
+
errors[error.path] = error.message;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return { isValid: false, errors };
|
|
22
|
+
}
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.YupAdapter = YupAdapter;
|
|
29
|
+
//# sourceMappingURL=index.cjs.map
|
|
30
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/YupAdapter.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,IAAI;AACF,MAAA,MAAM,KAAK,MAAA,CAAO,QAAA,CAAS,MAAW,EAAE,UAAA,EAAY,OAAO,CAAA;AAC3D,MAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AAAA,IACzB,SAAS,GAAA,EAAK;AACZ,MAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,WAAW,GAAA,EAAK;AACpD,QAAA,MAAM,QAAA,GAAW,GAAA;AACjB,QAAA,MAAM,SAAiC,EAAC;AACxC,QAAA,QAAA,CAAS,KAAA,CAAM,OAAA,CAAQ,CAAC,KAAA,KAAU;AAChC,UAAA,IAAI,MAAM,IAAA,EAAM;AACd,YAAA,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,KAAA,CAAM,OAAA;AAAA,UAC7B;AAAA,QACF,CAAC,CAAA;AACD,QAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,MAClC;AACA,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';\nimport type { YupLikeSchema, YupLikeError } from './types';\n\n/**\n * Validation adapter for Yup-like schemas.\n */\nexport class YupAdapter<T> implements IValidatorAdapter<T> {\n private schema: YupLikeSchema<T>;\n\n constructor(schema: YupLikeSchema<T>) {\n this.schema = schema;\n }\n\n async validate(data: unknown): Promise<ValidationResult> {\n try {\n await this.schema.validate(data as T, { abortEarly: false });\n return { isValid: true };\n } catch (err) {\n if (err && typeof err === 'object' && 'inner' in err) {\n const yupError = err as YupLikeError;\n const errors: Record<string, string> = {};\n yupError.inner.forEach((error) => {\n if (error.path) {\n errors[error.path] = error.message;\n }\n });\n return { isValid: false, errors };\n }\n throw err;\n }\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal structural interface for Yup-like schemas.
|
|
5
|
+
*/
|
|
6
|
+
interface YupLikeSchema<T = any> {
|
|
7
|
+
validate: (data: T, options: {
|
|
8
|
+
abortEarly: boolean;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Minimal structural interface for Yup-like validation errors.
|
|
13
|
+
*/
|
|
14
|
+
interface YupLikeError {
|
|
15
|
+
inner: Array<{
|
|
16
|
+
path?: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Validation adapter for Yup-like schemas.
|
|
23
|
+
*/
|
|
24
|
+
declare class YupAdapter<T> implements IValidatorAdapter<T> {
|
|
25
|
+
private schema;
|
|
26
|
+
constructor(schema: YupLikeSchema<T>);
|
|
27
|
+
validate(data: unknown): Promise<ValidationResult>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { YupAdapter, type YupLikeError, type YupLikeSchema };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal structural interface for Yup-like schemas.
|
|
5
|
+
*/
|
|
6
|
+
interface YupLikeSchema<T = any> {
|
|
7
|
+
validate: (data: T, options: {
|
|
8
|
+
abortEarly: boolean;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Minimal structural interface for Yup-like validation errors.
|
|
13
|
+
*/
|
|
14
|
+
interface YupLikeError {
|
|
15
|
+
inner: Array<{
|
|
16
|
+
path?: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Validation adapter for Yup-like schemas.
|
|
23
|
+
*/
|
|
24
|
+
declare class YupAdapter<T> implements IValidatorAdapter<T> {
|
|
25
|
+
private schema;
|
|
26
|
+
constructor(schema: YupLikeSchema<T>);
|
|
27
|
+
validate(data: unknown): Promise<ValidationResult>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { YupAdapter, type YupLikeError, type YupLikeSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/YupAdapter.ts
|
|
2
|
+
var YupAdapter = class {
|
|
3
|
+
constructor(schema) {
|
|
4
|
+
this.schema = schema;
|
|
5
|
+
}
|
|
6
|
+
async validate(data) {
|
|
7
|
+
try {
|
|
8
|
+
await this.schema.validate(data, { abortEarly: false });
|
|
9
|
+
return { isValid: true };
|
|
10
|
+
} catch (err) {
|
|
11
|
+
if (err && typeof err === "object" && "inner" in err) {
|
|
12
|
+
const yupError = err;
|
|
13
|
+
const errors = {};
|
|
14
|
+
yupError.inner.forEach((error) => {
|
|
15
|
+
if (error.path) {
|
|
16
|
+
errors[error.path] = error.message;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return { isValid: false, errors };
|
|
20
|
+
}
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { YupAdapter };
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/YupAdapter.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,IAAI;AACF,MAAA,MAAM,KAAK,MAAA,CAAO,QAAA,CAAS,MAAW,EAAE,UAAA,EAAY,OAAO,CAAA;AAC3D,MAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AAAA,IACzB,SAAS,GAAA,EAAK;AACZ,MAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,WAAW,GAAA,EAAK;AACpD,QAAA,MAAM,QAAA,GAAW,GAAA;AACjB,QAAA,MAAM,SAAiC,EAAC;AACxC,QAAA,QAAA,CAAS,KAAA,CAAM,OAAA,CAAQ,CAAC,KAAA,KAAU;AAChC,UAAA,IAAI,MAAM,IAAA,EAAM;AACd,YAAA,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,KAAA,CAAM,OAAA;AAAA,UAC7B;AAAA,QACF,CAAC,CAAA;AACD,QAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,MAClC;AACA,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { IValidatorAdapter, ValidationResult } from '@wizzard-packages/core';\nimport type { YupLikeSchema, YupLikeError } from './types';\n\n/**\n * Validation adapter for Yup-like schemas.\n */\nexport class YupAdapter<T> implements IValidatorAdapter<T> {\n private schema: YupLikeSchema<T>;\n\n constructor(schema: YupLikeSchema<T>) {\n this.schema = schema;\n }\n\n async validate(data: unknown): Promise<ValidationResult> {\n try {\n await this.schema.validate(data as T, { abortEarly: false });\n return { isValid: true };\n } catch (err) {\n if (err && typeof err === 'object' && 'inner' in err) {\n const yupError = err as YupLikeError;\n const errors: Record<string, string> = {};\n yupError.inner.forEach((error) => {\n if (error.path) {\n errors[error.path] = error.message;\n }\n });\n return { isValid: false, errors };\n }\n throw err;\n }\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wizzard-packages/adapter-yup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Yup validation adapter for Wizzard Stepper.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@wizzard-packages/core": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"tsup": "^8.3.5",
|
|
27
|
+
"typescript": "^5.7.2",
|
|
28
|
+
"vitest": "^4.0.16",
|
|
29
|
+
"yup": "^1.7.1"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"test": "vitest",
|
|
36
|
+
"test:run": "vitest run",
|
|
37
|
+
"type-check": "tsc --noEmit"
|
|
38
|
+
}
|
|
39
|
+
}
|