yuppi 1.0.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.md +9 -0
- package/README.md +368 -0
- package/dist/Patterns.barrel-KU6hZBXs.d.mts +14 -0
- package/dist/Patterns.barrel-UKU2yPZ6.d.ts +14 -0
- package/dist/Types.barrel--XGUUjIp.d.mts +18 -0
- package/dist/Types.barrel-wzQq8e9v.d.ts +18 -0
- package/dist/Yuppi.class.d.mts +17 -0
- package/dist/Yuppi.class.d.ts +17 -0
- package/dist/Yuppi.class.js +212 -0
- package/dist/Yuppi.class.mjs +177 -0
- package/dist/barrels/Patterns.barrel.d.mts +5 -0
- package/dist/barrels/Patterns.barrel.d.ts +5 -0
- package/dist/barrels/Patterns.barrel.js +47 -0
- package/dist/barrels/Patterns.barrel.mjs +17 -0
- package/dist/barrels/Types.barrel.d.mts +8 -0
- package/dist/barrels/Types.barrel.d.ts +8 -0
- package/dist/barrels/Types.barrel.js +18 -0
- package/dist/barrels/Types.barrel.mjs +0 -0
- package/dist/defaults/YuppiOptions.default.d.mts +7 -0
- package/dist/defaults/YuppiOptions.default.d.ts +7 -0
- package/dist/defaults/YuppiOptions.default.js +71 -0
- package/dist/defaults/YuppiOptions.default.mjs +46 -0
- package/dist/main.d.mts +15 -0
- package/dist/main.d.ts +15 -0
- package/dist/main.js +237 -0
- package/dist/main.mjs +205 -0
- package/dist/patterns/Email.pattern.d.mts +5 -0
- package/dist/patterns/Email.pattern.d.ts +5 -0
- package/dist/patterns/Email.pattern.js +30 -0
- package/dist/patterns/Email.pattern.mjs +5 -0
- package/dist/patterns/PhoneNumber.pattern.d.mts +5 -0
- package/dist/patterns/PhoneNumber.pattern.d.ts +5 -0
- package/dist/patterns/PhoneNumber.pattern.js +30 -0
- package/dist/patterns/PhoneNumber.pattern.mjs +5 -0
- package/dist/patterns/URL.pattern.d.mts +5 -0
- package/dist/patterns/URL.pattern.d.ts +5 -0
- package/dist/patterns/URL.pattern.js +30 -0
- package/dist/patterns/URL.pattern.mjs +5 -0
- package/dist/patterns/Username.pattern.d.mts +5 -0
- package/dist/patterns/Username.pattern.d.ts +5 -0
- package/dist/patterns/Username.pattern.js +30 -0
- package/dist/patterns/Username.pattern.mjs +5 -0
- package/dist/types/AnyObject.type.d.mts +5 -0
- package/dist/types/AnyObject.type.d.ts +5 -0
- package/dist/types/AnyObject.type.js +18 -0
- package/dist/types/AnyObject.type.mjs +0 -0
- package/dist/types/JSONSchema.type.d.mts +5 -0
- package/dist/types/JSONSchema.type.d.ts +5 -0
- package/dist/types/JSONSchema.type.js +18 -0
- package/dist/types/JSONSchema.type.mjs +0 -0
- package/dist/types/Schema.type.d.mts +45 -0
- package/dist/types/Schema.type.d.ts +45 -0
- package/dist/types/Schema.type.js +18 -0
- package/dist/types/Schema.type.mjs +0 -0
- package/dist/types/ValidateOptions.type.d.mts +5 -0
- package/dist/types/ValidateOptions.type.d.ts +5 -0
- package/dist/types/ValidateOptions.type.js +18 -0
- package/dist/types/ValidateOptions.type.mjs +0 -0
- package/dist/types/ValidationError.type.d.mts +5 -0
- package/dist/types/ValidationError.type.d.ts +5 -0
- package/dist/types/ValidationError.type.js +18 -0
- package/dist/types/ValidationError.type.mjs +0 -0
- package/dist/types/YuppiOptions.type.d.mts +44 -0
- package/dist/types/YuppiOptions.type.d.ts +44 -0
- package/dist/types/YuppiOptions.type.js +18 -0
- package/dist/types/YuppiOptions.type.mjs +0 -0
- package/dist/utils/ConvertToJSONSchema.util.d.mts +6 -0
- package/dist/utils/ConvertToJSONSchema.util.d.ts +6 -0
- package/dist/utils/ConvertToJSONSchema.util.js +64 -0
- package/dist/utils/ConvertToJSONSchema.util.mjs +39 -0
- package/dist/utils/ConvertToYup.util.d.mts +9 -0
- package/dist/utils/ConvertToYup.util.d.ts +9 -0
- package/dist/utils/ConvertToYup.util.js +110 -0
- package/dist/utils/ConvertToYup.util.mjs +75 -0
- package/package.json +42 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/AnyObject.type.ts
|
|
17
|
+
var AnyObject_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(AnyObject_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/JSONSchema.type.ts
|
|
17
|
+
var JSONSchema_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(JSONSchema_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
type Base = {
|
|
2
|
+
pattern?: string;
|
|
3
|
+
default?: unknown;
|
|
4
|
+
nullable: boolean;
|
|
5
|
+
required: boolean;
|
|
6
|
+
};
|
|
7
|
+
type String = Base & {
|
|
8
|
+
type: "string";
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
lowercase?: boolean;
|
|
12
|
+
uppercase?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type Number = Base & {
|
|
15
|
+
type: "number";
|
|
16
|
+
min?: number;
|
|
17
|
+
max?: number;
|
|
18
|
+
integer?: boolean;
|
|
19
|
+
positive?: boolean;
|
|
20
|
+
negative?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type Boolean = Base & {
|
|
23
|
+
type: "boolean";
|
|
24
|
+
};
|
|
25
|
+
type Date = Base & {
|
|
26
|
+
type: "date";
|
|
27
|
+
min?: string;
|
|
28
|
+
max?: string;
|
|
29
|
+
};
|
|
30
|
+
type Object$1 = Base & {
|
|
31
|
+
type: "object";
|
|
32
|
+
properties: Schema;
|
|
33
|
+
};
|
|
34
|
+
type Array = Base & {
|
|
35
|
+
type: "array";
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
items: Types;
|
|
39
|
+
};
|
|
40
|
+
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
41
|
+
type Schema = {
|
|
42
|
+
[key: string]: Types;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type { Array, Base, Boolean, Date, Number, Object$1 as Object, Schema, String, Types };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
type Base = {
|
|
2
|
+
pattern?: string;
|
|
3
|
+
default?: unknown;
|
|
4
|
+
nullable: boolean;
|
|
5
|
+
required: boolean;
|
|
6
|
+
};
|
|
7
|
+
type String = Base & {
|
|
8
|
+
type: "string";
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
lowercase?: boolean;
|
|
12
|
+
uppercase?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type Number = Base & {
|
|
15
|
+
type: "number";
|
|
16
|
+
min?: number;
|
|
17
|
+
max?: number;
|
|
18
|
+
integer?: boolean;
|
|
19
|
+
positive?: boolean;
|
|
20
|
+
negative?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type Boolean = Base & {
|
|
23
|
+
type: "boolean";
|
|
24
|
+
};
|
|
25
|
+
type Date = Base & {
|
|
26
|
+
type: "date";
|
|
27
|
+
min?: string;
|
|
28
|
+
max?: string;
|
|
29
|
+
};
|
|
30
|
+
type Object$1 = Base & {
|
|
31
|
+
type: "object";
|
|
32
|
+
properties: Schema;
|
|
33
|
+
};
|
|
34
|
+
type Array = Base & {
|
|
35
|
+
type: "array";
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
items: Types;
|
|
39
|
+
};
|
|
40
|
+
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
41
|
+
type Schema = {
|
|
42
|
+
[key: string]: Types;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type { Array, Base, Boolean, Date, Number, Object$1 as Object, Schema, String, Types };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/Schema.type.ts
|
|
17
|
+
var Schema_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(Schema_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/ValidateOptions.type.ts
|
|
17
|
+
var ValidateOptions_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(ValidateOptions_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/ValidationError.type.ts
|
|
17
|
+
var ValidationError_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(ValidationError_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ValidateOptions } from './ValidateOptions.type.mjs';
|
|
2
|
+
import 'yup';
|
|
3
|
+
|
|
4
|
+
type YuppiOptions = {
|
|
5
|
+
error_messages?: {
|
|
6
|
+
base?: {
|
|
7
|
+
pattern?: string;
|
|
8
|
+
nullable?: string;
|
|
9
|
+
required?: string;
|
|
10
|
+
};
|
|
11
|
+
string?: {
|
|
12
|
+
type?: string;
|
|
13
|
+
min?: string;
|
|
14
|
+
max?: string;
|
|
15
|
+
};
|
|
16
|
+
number?: {
|
|
17
|
+
type?: string;
|
|
18
|
+
min?: string;
|
|
19
|
+
max?: string;
|
|
20
|
+
integer?: string;
|
|
21
|
+
positive?: string;
|
|
22
|
+
negative?: string;
|
|
23
|
+
};
|
|
24
|
+
boolean?: {
|
|
25
|
+
type?: string;
|
|
26
|
+
};
|
|
27
|
+
date?: {
|
|
28
|
+
type?: string;
|
|
29
|
+
min?: string;
|
|
30
|
+
max?: string;
|
|
31
|
+
};
|
|
32
|
+
object?: {
|
|
33
|
+
type?: string;
|
|
34
|
+
};
|
|
35
|
+
array?: {
|
|
36
|
+
type?: string;
|
|
37
|
+
min?: string;
|
|
38
|
+
max?: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
validate_options?: ValidateOptions;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type { YuppiOptions };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ValidateOptions } from './ValidateOptions.type.js';
|
|
2
|
+
import 'yup';
|
|
3
|
+
|
|
4
|
+
type YuppiOptions = {
|
|
5
|
+
error_messages?: {
|
|
6
|
+
base?: {
|
|
7
|
+
pattern?: string;
|
|
8
|
+
nullable?: string;
|
|
9
|
+
required?: string;
|
|
10
|
+
};
|
|
11
|
+
string?: {
|
|
12
|
+
type?: string;
|
|
13
|
+
min?: string;
|
|
14
|
+
max?: string;
|
|
15
|
+
};
|
|
16
|
+
number?: {
|
|
17
|
+
type?: string;
|
|
18
|
+
min?: string;
|
|
19
|
+
max?: string;
|
|
20
|
+
integer?: string;
|
|
21
|
+
positive?: string;
|
|
22
|
+
negative?: string;
|
|
23
|
+
};
|
|
24
|
+
boolean?: {
|
|
25
|
+
type?: string;
|
|
26
|
+
};
|
|
27
|
+
date?: {
|
|
28
|
+
type?: string;
|
|
29
|
+
min?: string;
|
|
30
|
+
max?: string;
|
|
31
|
+
};
|
|
32
|
+
object?: {
|
|
33
|
+
type?: string;
|
|
34
|
+
};
|
|
35
|
+
array?: {
|
|
36
|
+
type?: string;
|
|
37
|
+
min?: string;
|
|
38
|
+
max?: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
validate_options?: ValidateOptions;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type { YuppiOptions };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/YuppiOptions.type.ts
|
|
17
|
+
var YuppiOptions_type_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(YuppiOptions_type_exports);
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/ConvertToJSONSchema.util.ts
|
|
21
|
+
var ConvertToJSONSchema_util_exports = {};
|
|
22
|
+
__export(ConvertToJSONSchema_util_exports, {
|
|
23
|
+
convertToJSONSchema: () => convertToJSONSchema
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ConvertToJSONSchema_util_exports);
|
|
26
|
+
var import_typebox = require("@sinclair/typebox");
|
|
27
|
+
var convertToJSONSchema = (schema) => {
|
|
28
|
+
const build = (key, config) => {
|
|
29
|
+
if (config.type === "string") {
|
|
30
|
+
let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
|
|
31
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
32
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
33
|
+
} else if (config.type === "number") {
|
|
34
|
+
let schema2 = config.integer === true ? import_typebox.Type.Integer({ minimum: config.min, maximum: config.max, default: config.default }) : import_typebox.Type.Number({ minimum: config.min, maximum: config.max, default: config.default });
|
|
35
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
36
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
37
|
+
} else if (config.type === "boolean") {
|
|
38
|
+
let schema2 = import_typebox.Type.Boolean({ default: config.default });
|
|
39
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
40
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
41
|
+
} else if (config.type === "date") {
|
|
42
|
+
let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
|
|
43
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
44
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
45
|
+
} else if (config.type === "object") {
|
|
46
|
+
const nested_properties = {};
|
|
47
|
+
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
48
|
+
let schema2 = import_typebox.Type.Object(nested_properties);
|
|
49
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
50
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
51
|
+
} else if (config.type === "array") {
|
|
52
|
+
let schema2 = import_typebox.Type.Array(build(key, config.items), { minItems: config.min, maxItems: config.max, default: config.default });
|
|
53
|
+
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
54
|
+
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
55
|
+
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
56
|
+
};
|
|
57
|
+
const properties = {};
|
|
58
|
+
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
59
|
+
return import_typebox.Type.Object(properties);
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
convertToJSONSchema
|
|
64
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/utils/ConvertToJSONSchema.util.ts
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
var convertToJSONSchema = (schema) => {
|
|
4
|
+
const build = (key, config) => {
|
|
5
|
+
if (config.type === "string") {
|
|
6
|
+
let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
|
|
7
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
8
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
9
|
+
} else if (config.type === "number") {
|
|
10
|
+
let schema2 = config.integer === true ? Type.Integer({ minimum: config.min, maximum: config.max, default: config.default }) : Type.Number({ minimum: config.min, maximum: config.max, default: config.default });
|
|
11
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
12
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
13
|
+
} else if (config.type === "boolean") {
|
|
14
|
+
let schema2 = Type.Boolean({ default: config.default });
|
|
15
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
16
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
17
|
+
} else if (config.type === "date") {
|
|
18
|
+
let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? "[\\s\\S]*").source, default: config.default });
|
|
19
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
20
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
21
|
+
} else if (config.type === "object") {
|
|
22
|
+
const nested_properties = {};
|
|
23
|
+
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
24
|
+
let schema2 = Type.Object(nested_properties);
|
|
25
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
26
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
27
|
+
} else if (config.type === "array") {
|
|
28
|
+
let schema2 = Type.Array(build(key, config.items), { minItems: config.min, maxItems: config.max, default: config.default });
|
|
29
|
+
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
30
|
+
return config.required ? schema2 : Type.Optional(schema2);
|
|
31
|
+
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
32
|
+
};
|
|
33
|
+
const properties = {};
|
|
34
|
+
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
35
|
+
return Type.Object(properties);
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
convertToJSONSchema
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyObject } from '../types/AnyObject.type.mjs';
|
|
2
|
+
import { Schema } from '../types/Schema.type.mjs';
|
|
3
|
+
import { YuppiOptions } from '../types/YuppiOptions.type.mjs';
|
|
4
|
+
import 'yup';
|
|
5
|
+
import '../types/ValidateOptions.type.mjs';
|
|
6
|
+
|
|
7
|
+
declare const convertToYup: (schema: Schema, error_messages: YuppiOptions["error_messages"]) => AnyObject;
|
|
8
|
+
|
|
9
|
+
export { convertToYup };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyObject } from '../types/AnyObject.type.js';
|
|
2
|
+
import { Schema } from '../types/Schema.type.js';
|
|
3
|
+
import { YuppiOptions } from '../types/YuppiOptions.type.js';
|
|
4
|
+
import 'yup';
|
|
5
|
+
import '../types/ValidateOptions.type.js';
|
|
6
|
+
|
|
7
|
+
declare const convertToYup: (schema: Schema, error_messages: YuppiOptions["error_messages"]) => AnyObject;
|
|
8
|
+
|
|
9
|
+
export { convertToYup };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/utils/ConvertToYup.util.ts
|
|
31
|
+
var ConvertToYup_util_exports = {};
|
|
32
|
+
__export(ConvertToYup_util_exports, {
|
|
33
|
+
convertToYup: () => convertToYup
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(ConvertToYup_util_exports);
|
|
36
|
+
var Yup = __toESM(require("yup"));
|
|
37
|
+
var convertToYup = (schema, error_messages) => {
|
|
38
|
+
const build = (key, config) => {
|
|
39
|
+
let schema2;
|
|
40
|
+
if (config.type === "string") {
|
|
41
|
+
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
42
|
+
schema2 = schema2.trim();
|
|
43
|
+
if (config.min !== void 0)
|
|
44
|
+
schema2 = schema2.min(
|
|
45
|
+
config.min,
|
|
46
|
+
({ path, min }) => (error_messages?.string?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
47
|
+
);
|
|
48
|
+
if (config.max !== void 0)
|
|
49
|
+
schema2 = schema2.max(
|
|
50
|
+
config.max,
|
|
51
|
+
({ path, max }) => (error_messages?.string?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
52
|
+
);
|
|
53
|
+
if (config.lowercase === true) schema2 = schema2.lowercase();
|
|
54
|
+
if (config.uppercase === true) schema2 = schema2.uppercase();
|
|
55
|
+
} else if (config.type === "number") {
|
|
56
|
+
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
57
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.number?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()));
|
|
58
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.number?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()));
|
|
59
|
+
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
60
|
+
if (config.positive === true) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
|
|
61
|
+
if (config.negative === true) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
|
|
62
|
+
} else if (config.type === "boolean") {
|
|
63
|
+
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
|
|
64
|
+
} else if (config.type === "date") {
|
|
65
|
+
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
|
|
66
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path, min }) => (error_messages?.date?.min ?? "").split("{path}").join(path).split("{min}").join(new Date(min).toISOString()));
|
|
67
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path, max }) => (error_messages?.date?.max ?? "").split("{path}").join(path).split("{max}").join(new Date(max).toISOString()));
|
|
68
|
+
} else if (config.type === "object") {
|
|
69
|
+
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
|
|
70
|
+
const nested_properties = {};
|
|
71
|
+
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
72
|
+
schema2 = schema2.shape(nested_properties);
|
|
73
|
+
} else if (config.type === "array") {
|
|
74
|
+
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
|
|
75
|
+
if (config.min !== void 0)
|
|
76
|
+
schema2 = schema2.min(
|
|
77
|
+
config.min,
|
|
78
|
+
({ path, min }) => (error_messages?.array?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
79
|
+
);
|
|
80
|
+
if (config.max !== void 0)
|
|
81
|
+
schema2 = schema2.max(
|
|
82
|
+
config.max,
|
|
83
|
+
({ path, max }) => (error_messages?.array?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
84
|
+
);
|
|
85
|
+
schema2 = schema2.of(build(key, config.items));
|
|
86
|
+
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
87
|
+
schema2 = schema2.nullable();
|
|
88
|
+
if (config.pattern !== void 0 && schema2.matches !== void 0)
|
|
89
|
+
schema2 = schema2.matches(
|
|
90
|
+
new RegExp(config.pattern ?? "[\\s\\S]*"),
|
|
91
|
+
({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? "[\\s\\S]*").source)
|
|
92
|
+
);
|
|
93
|
+
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
94
|
+
if (!config.nullable && config.default !== null)
|
|
95
|
+
schema2 = schema2.test(
|
|
96
|
+
"nullable",
|
|
97
|
+
({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path),
|
|
98
|
+
(value) => value !== null
|
|
99
|
+
);
|
|
100
|
+
if (config.required) schema2 = schema2.required(({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path));
|
|
101
|
+
return schema2;
|
|
102
|
+
};
|
|
103
|
+
const shape = {};
|
|
104
|
+
for (const [key, config] of Object.entries(schema)) shape[key] = build(key, config);
|
|
105
|
+
return Yup.object().shape(shape);
|
|
106
|
+
};
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
convertToYup
|
|
110
|
+
});
|