yuppi 1.2.5 → 1.2.7
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/README.md +16 -16
- package/dist/main.d.mts +139 -17
- package/dist/main.d.ts +139 -17
- package/package.json +2 -2
- package/dist/Patterns.barrel-D-k3IHDq.d.mts +0 -20
- package/dist/Patterns.barrel-JdN3lL2Q.d.ts +0 -20
- package/dist/Yuppi.class.d.mts +0 -24
- package/dist/Yuppi.class.d.ts +0 -24
- package/dist/Yuppi.class.js +0 -244
- package/dist/Yuppi.class.mjs +0 -209
- package/dist/barrels/Patterns.barrel.d.mts +0 -7
- package/dist/barrels/Patterns.barrel.d.ts +0 -7
- package/dist/barrels/Patterns.barrel.js +0 -62
- package/dist/barrels/Patterns.barrel.mjs +0 -29
- package/dist/barrels/Types.barrel.d.mts +0 -8
- package/dist/barrels/Types.barrel.d.ts +0 -8
- package/dist/barrels/Types.barrel.js +0 -18
- package/dist/barrels/Types.barrel.mjs +0 -0
- package/dist/defaults/YuppiOptions.default.d.mts +0 -7
- package/dist/defaults/YuppiOptions.default.d.ts +0 -7
- package/dist/defaults/YuppiOptions.default.js +0 -73
- package/dist/defaults/YuppiOptions.default.mjs +0 -48
- package/dist/patterns/Any.pattern.d.mts +0 -3
- package/dist/patterns/Any.pattern.d.ts +0 -3
- package/dist/patterns/Any.pattern.js +0 -30
- package/dist/patterns/Any.pattern.mjs +0 -5
- package/dist/patterns/Domain.pattern.d.mts +0 -3
- package/dist/patterns/Domain.pattern.d.ts +0 -3
- package/dist/patterns/Domain.pattern.js +0 -30
- package/dist/patterns/Domain.pattern.mjs +0 -5
- package/dist/patterns/Email.pattern.d.mts +0 -3
- package/dist/patterns/Email.pattern.d.ts +0 -3
- package/dist/patterns/Email.pattern.js +0 -30
- package/dist/patterns/Email.pattern.mjs +0 -5
- package/dist/patterns/HTTP.pattern.d.mts +0 -3
- package/dist/patterns/HTTP.pattern.d.ts +0 -3
- package/dist/patterns/HTTP.pattern.js +0 -30
- package/dist/patterns/HTTP.pattern.mjs +0 -5
- package/dist/patterns/PhoneNumber.pattern.d.mts +0 -3
- package/dist/patterns/PhoneNumber.pattern.d.ts +0 -3
- package/dist/patterns/PhoneNumber.pattern.js +0 -30
- package/dist/patterns/PhoneNumber.pattern.mjs +0 -5
- package/dist/patterns/URI.pattern.d.mts +0 -3
- package/dist/patterns/URI.pattern.d.ts +0 -3
- package/dist/patterns/URI.pattern.js +0 -30
- package/dist/patterns/URI.pattern.mjs +0 -5
- package/dist/patterns/Username.pattern.d.mts +0 -3
- package/dist/patterns/Username.pattern.d.ts +0 -3
- package/dist/patterns/Username.pattern.js +0 -30
- package/dist/patterns/Username.pattern.mjs +0 -5
- package/dist/types/AnyObject.type.d.mts +0 -5
- package/dist/types/AnyObject.type.d.ts +0 -5
- package/dist/types/AnyObject.type.js +0 -18
- package/dist/types/AnyObject.type.mjs +0 -0
- package/dist/types/JSONSchema.type.d.mts +0 -5
- package/dist/types/JSONSchema.type.d.ts +0 -5
- package/dist/types/JSONSchema.type.js +0 -18
- package/dist/types/JSONSchema.type.mjs +0 -0
- package/dist/types/Schema.type.d.mts +0 -45
- package/dist/types/Schema.type.d.ts +0 -45
- package/dist/types/Schema.type.js +0 -18
- package/dist/types/Schema.type.mjs +0 -0
- package/dist/types/ValidateOptions.type.d.mts +0 -5
- package/dist/types/ValidateOptions.type.d.ts +0 -5
- package/dist/types/ValidateOptions.type.js +0 -18
- package/dist/types/ValidateOptions.type.mjs +0 -0
- package/dist/types/ValidationError.type.d.mts +0 -5
- package/dist/types/ValidationError.type.d.ts +0 -5
- package/dist/types/ValidationError.type.js +0 -18
- package/dist/types/ValidationError.type.mjs +0 -0
- package/dist/types/YuppiOptions.type.d.mts +0 -46
- package/dist/types/YuppiOptions.type.d.ts +0 -46
- package/dist/types/YuppiOptions.type.js +0 -18
- package/dist/types/YuppiOptions.type.mjs +0 -0
- package/dist/utils/ConvertToJSONSchema.util.d.mts +0 -6
- package/dist/utils/ConvertToJSONSchema.util.d.ts +0 -6
- package/dist/utils/ConvertToJSONSchema.util.js +0 -69
- package/dist/utils/ConvertToJSONSchema.util.mjs +0 -44
- package/dist/utils/ConvertToYup.util.d.mts +0 -12
- package/dist/utils/ConvertToYup.util.d.ts +0 -12
- package/dist/utils/ConvertToYup.util.js +0 -140
- package/dist/utils/ConvertToYup.util.mjs +0 -105
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
enum?: string;
|
|
14
|
-
min?: string;
|
|
15
|
-
max?: string;
|
|
16
|
-
};
|
|
17
|
-
number?: {
|
|
18
|
-
type?: string;
|
|
19
|
-
enum?: string;
|
|
20
|
-
min?: string;
|
|
21
|
-
max?: string;
|
|
22
|
-
integer?: string;
|
|
23
|
-
positive?: string;
|
|
24
|
-
negative?: string;
|
|
25
|
-
};
|
|
26
|
-
boolean?: {
|
|
27
|
-
type?: string;
|
|
28
|
-
};
|
|
29
|
-
date?: {
|
|
30
|
-
type?: string;
|
|
31
|
-
min?: string;
|
|
32
|
-
max?: string;
|
|
33
|
-
};
|
|
34
|
-
object?: {
|
|
35
|
-
type?: string;
|
|
36
|
-
};
|
|
37
|
-
array?: {
|
|
38
|
-
type?: string;
|
|
39
|
-
min?: string;
|
|
40
|
-
max?: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
validate_options?: ValidateOptions;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type { YuppiOptions };
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
enum?: string;
|
|
14
|
-
min?: string;
|
|
15
|
-
max?: string;
|
|
16
|
-
};
|
|
17
|
-
number?: {
|
|
18
|
-
type?: string;
|
|
19
|
-
enum?: string;
|
|
20
|
-
min?: string;
|
|
21
|
-
max?: string;
|
|
22
|
-
integer?: string;
|
|
23
|
-
positive?: string;
|
|
24
|
-
negative?: string;
|
|
25
|
-
};
|
|
26
|
-
boolean?: {
|
|
27
|
-
type?: string;
|
|
28
|
-
};
|
|
29
|
-
date?: {
|
|
30
|
-
type?: string;
|
|
31
|
-
min?: string;
|
|
32
|
-
max?: string;
|
|
33
|
-
};
|
|
34
|
-
object?: {
|
|
35
|
-
type?: string;
|
|
36
|
-
};
|
|
37
|
-
array?: {
|
|
38
|
-
type?: string;
|
|
39
|
-
min?: string;
|
|
40
|
-
max?: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
validate_options?: ValidateOptions;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type { YuppiOptions };
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
|
|
28
|
-
// src/patterns/Any.pattern.ts
|
|
29
|
-
var Any = "[\\s\\S]*";
|
|
30
|
-
|
|
31
|
-
// src/utils/ConvertToJSONSchema.util.ts
|
|
32
|
-
var convertToJSONSchema = (schema) => {
|
|
33
|
-
const build = (key, config) => {
|
|
34
|
-
if (config.type === "string") {
|
|
35
|
-
let schema2 = import_typebox.Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
36
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
37
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
38
|
-
} else if (config.type === "number") {
|
|
39
|
-
let schema2 = config.integer === true ? import_typebox.Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default }) : import_typebox.Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default });
|
|
40
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
41
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
42
|
-
} else if (config.type === "boolean") {
|
|
43
|
-
let schema2 = import_typebox.Type.Boolean({ default: config.default });
|
|
44
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
45
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
46
|
-
} else if (config.type === "date") {
|
|
47
|
-
let schema2 = import_typebox.Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
48
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
49
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
50
|
-
} else if (config.type === "object") {
|
|
51
|
-
const nested_properties = {};
|
|
52
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
53
|
-
let schema2 = import_typebox.Type.Object(nested_properties);
|
|
54
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
55
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
56
|
-
} else if (config.type === "array") {
|
|
57
|
-
let schema2 = import_typebox.Type.Array(build(key, config.items), { minItems: config.min, maxItems: config.max, default: config.default });
|
|
58
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
59
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
60
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
61
|
-
};
|
|
62
|
-
const properties = {};
|
|
63
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
64
|
-
return import_typebox.Type.Object(properties);
|
|
65
|
-
};
|
|
66
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
-
0 && (module.exports = {
|
|
68
|
-
convertToJSONSchema
|
|
69
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// src/utils/ConvertToJSONSchema.util.ts
|
|
2
|
-
import { Type } from "@sinclair/typebox";
|
|
3
|
-
|
|
4
|
-
// src/patterns/Any.pattern.ts
|
|
5
|
-
var Any = "[\\s\\S]*";
|
|
6
|
-
|
|
7
|
-
// src/utils/ConvertToJSONSchema.util.ts
|
|
8
|
-
var convertToJSONSchema = (schema) => {
|
|
9
|
-
const build = (key, config) => {
|
|
10
|
-
if (config.type === "string") {
|
|
11
|
-
let schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
12
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
13
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
14
|
-
} else if (config.type === "number") {
|
|
15
|
-
let schema2 = config.integer === true ? Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default }) : Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default });
|
|
16
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
17
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
18
|
-
} else if (config.type === "boolean") {
|
|
19
|
-
let schema2 = Type.Boolean({ default: config.default });
|
|
20
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
21
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
22
|
-
} else if (config.type === "date") {
|
|
23
|
-
let schema2 = Type.String({ format: "date-time", minimum: config.min, maximum: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
24
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
25
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
26
|
-
} else if (config.type === "object") {
|
|
27
|
-
const nested_properties = {};
|
|
28
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
29
|
-
let schema2 = Type.Object(nested_properties);
|
|
30
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
31
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
32
|
-
} else if (config.type === "array") {
|
|
33
|
-
let schema2 = Type.Array(build(key, config.items), { minItems: config.min, maxItems: config.max, default: config.default });
|
|
34
|
-
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
35
|
-
return config.required ? schema2 : Type.Optional(schema2);
|
|
36
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
37
|
-
};
|
|
38
|
-
const properties = {};
|
|
39
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
40
|
-
return Type.Object(properties);
|
|
41
|
-
};
|
|
42
|
-
export {
|
|
43
|
-
convertToJSONSchema
|
|
44
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
2
|
-
import { Schema } from '../types/Schema.type.mjs';
|
|
3
|
-
import { YuppiOptions } from '../types/YuppiOptions.type.mjs';
|
|
4
|
-
import '../types/ValidateOptions.type.mjs';
|
|
5
|
-
|
|
6
|
-
declare const convertToYup: (schema: Schema, error_messages: YuppiOptions["error_messages"]) => yup.ObjectSchema<{
|
|
7
|
-
[x: string]: any;
|
|
8
|
-
}, yup.AnyObject, {
|
|
9
|
-
[x: string]: any;
|
|
10
|
-
}, "">;
|
|
11
|
-
|
|
12
|
-
export { convertToYup };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
2
|
-
import { Schema } from '../types/Schema.type.js';
|
|
3
|
-
import { YuppiOptions } from '../types/YuppiOptions.type.js';
|
|
4
|
-
import '../types/ValidateOptions.type.js';
|
|
5
|
-
|
|
6
|
-
declare const convertToYup: (schema: Schema, error_messages: YuppiOptions["error_messages"]) => yup.ObjectSchema<{
|
|
7
|
-
[x: string]: any;
|
|
8
|
-
}, yup.AnyObject, {
|
|
9
|
-
[x: string]: any;
|
|
10
|
-
}, "">;
|
|
11
|
-
|
|
12
|
-
export { convertToYup };
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
|
|
38
|
-
// src/patterns/Any.pattern.ts
|
|
39
|
-
var Any = "[\\s\\S]*";
|
|
40
|
-
|
|
41
|
-
// src/utils/ConvertToYup.util.ts
|
|
42
|
-
var convertToYup = (schema, error_messages) => {
|
|
43
|
-
const base = (schema2, key, config) => {
|
|
44
|
-
schema2 = schema2.nullable();
|
|
45
|
-
if (config.required)
|
|
46
|
-
schema2 = schema2.test(
|
|
47
|
-
"required",
|
|
48
|
-
({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path),
|
|
49
|
-
(property) => {
|
|
50
|
-
if (property === void 0) return false;
|
|
51
|
-
if (typeof property === "string" && property.trim() === "") return false;
|
|
52
|
-
if (Array.isArray(property) && property.length === 0) return false;
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
|
|
57
|
-
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
58
|
-
if (config.pattern !== void 0 && schema2.matches !== void 0)
|
|
59
|
-
schema2 = schema2.matches(
|
|
60
|
-
new RegExp(config.pattern ?? Any),
|
|
61
|
-
({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
|
|
62
|
-
);
|
|
63
|
-
return schema2;
|
|
64
|
-
};
|
|
65
|
-
const build = (key, config) => {
|
|
66
|
-
let schema2;
|
|
67
|
-
if (config.type === "string") {
|
|
68
|
-
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
69
|
-
schema2 = base(schema2, key, config);
|
|
70
|
-
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
71
|
-
if (config.enum !== void 0)
|
|
72
|
-
schema2 = schema2.oneOf(
|
|
73
|
-
config.enum.map((item) => item.trim()),
|
|
74
|
-
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
75
|
-
);
|
|
76
|
-
if (config.min !== void 0)
|
|
77
|
-
schema2 = schema2.min(
|
|
78
|
-
config.min,
|
|
79
|
-
({ path, min }) => (error_messages?.string?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
80
|
-
);
|
|
81
|
-
if (config.max !== void 0)
|
|
82
|
-
schema2 = schema2.max(
|
|
83
|
-
config.max,
|
|
84
|
-
({ path, max }) => (error_messages?.string?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
85
|
-
);
|
|
86
|
-
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
87
|
-
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
88
|
-
return schema2;
|
|
89
|
-
} else if (config.type === "number") {
|
|
90
|
-
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
91
|
-
schema2 = base(schema2, key, config);
|
|
92
|
-
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
93
|
-
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()));
|
|
94
|
-
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()));
|
|
95
|
-
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
96
|
-
if (config.positive === true) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
|
|
97
|
-
if (config.negative === true) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
|
|
98
|
-
return schema2;
|
|
99
|
-
} else if (config.type === "boolean") {
|
|
100
|
-
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
|
|
101
|
-
schema2 = base(schema2, key, config);
|
|
102
|
-
return schema2;
|
|
103
|
-
} else if (config.type === "date") {
|
|
104
|
-
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
|
|
105
|
-
schema2 = base(schema2, key, config);
|
|
106
|
-
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()));
|
|
107
|
-
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()));
|
|
108
|
-
return schema2;
|
|
109
|
-
} else if (config.type === "object") {
|
|
110
|
-
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
|
|
111
|
-
schema2 = base(schema2, key, config);
|
|
112
|
-
const nested_properties = {};
|
|
113
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
114
|
-
schema2 = schema2.shape(nested_properties);
|
|
115
|
-
return schema2;
|
|
116
|
-
} else if (config.type === "array") {
|
|
117
|
-
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
|
|
118
|
-
schema2 = base(schema2, key, config);
|
|
119
|
-
if (config.min !== void 0)
|
|
120
|
-
schema2 = schema2.min(
|
|
121
|
-
config.min,
|
|
122
|
-
({ path, min }) => (error_messages?.array?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
123
|
-
);
|
|
124
|
-
if (config.max !== void 0)
|
|
125
|
-
schema2 = schema2.max(
|
|
126
|
-
config.max,
|
|
127
|
-
({ path, max }) => (error_messages?.array?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
128
|
-
);
|
|
129
|
-
schema2 = schema2.of(build(key, config.items));
|
|
130
|
-
return schema2;
|
|
131
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
132
|
-
};
|
|
133
|
-
const properties = {};
|
|
134
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
135
|
-
return Yup.object().shape(properties);
|
|
136
|
-
};
|
|
137
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
-
0 && (module.exports = {
|
|
139
|
-
convertToYup
|
|
140
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// src/utils/ConvertToYup.util.ts
|
|
2
|
-
import * as Yup from "yup";
|
|
3
|
-
|
|
4
|
-
// src/patterns/Any.pattern.ts
|
|
5
|
-
var Any = "[\\s\\S]*";
|
|
6
|
-
|
|
7
|
-
// src/utils/ConvertToYup.util.ts
|
|
8
|
-
var convertToYup = (schema, error_messages) => {
|
|
9
|
-
const base = (schema2, key, config) => {
|
|
10
|
-
schema2 = schema2.nullable();
|
|
11
|
-
if (config.required)
|
|
12
|
-
schema2 = schema2.test(
|
|
13
|
-
"required",
|
|
14
|
-
({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path),
|
|
15
|
-
(property) => {
|
|
16
|
-
if (property === void 0) return false;
|
|
17
|
-
if (typeof property === "string" && property.trim() === "") return false;
|
|
18
|
-
if (Array.isArray(property) && property.length === 0) return false;
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
|
|
23
|
-
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
24
|
-
if (config.pattern !== void 0 && schema2.matches !== void 0)
|
|
25
|
-
schema2 = schema2.matches(
|
|
26
|
-
new RegExp(config.pattern ?? Any),
|
|
27
|
-
({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
|
|
28
|
-
);
|
|
29
|
-
return schema2;
|
|
30
|
-
};
|
|
31
|
-
const build = (key, config) => {
|
|
32
|
-
let schema2;
|
|
33
|
-
if (config.type === "string") {
|
|
34
|
-
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
35
|
-
schema2 = base(schema2, key, config);
|
|
36
|
-
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
37
|
-
if (config.enum !== void 0)
|
|
38
|
-
schema2 = schema2.oneOf(
|
|
39
|
-
config.enum.map((item) => item.trim()),
|
|
40
|
-
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
41
|
-
);
|
|
42
|
-
if (config.min !== void 0)
|
|
43
|
-
schema2 = schema2.min(
|
|
44
|
-
config.min,
|
|
45
|
-
({ path, min }) => (error_messages?.string?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
46
|
-
);
|
|
47
|
-
if (config.max !== void 0)
|
|
48
|
-
schema2 = schema2.max(
|
|
49
|
-
config.max,
|
|
50
|
-
({ path, max }) => (error_messages?.string?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
51
|
-
);
|
|
52
|
-
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
53
|
-
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
54
|
-
return schema2;
|
|
55
|
-
} else if (config.type === "number") {
|
|
56
|
-
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
57
|
-
schema2 = base(schema2, key, config);
|
|
58
|
-
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
59
|
-
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()));
|
|
60
|
-
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()));
|
|
61
|
-
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
62
|
-
if (config.positive === true) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
|
|
63
|
-
if (config.negative === true) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
|
|
64
|
-
return schema2;
|
|
65
|
-
} else if (config.type === "boolean") {
|
|
66
|
-
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
|
|
67
|
-
schema2 = base(schema2, key, config);
|
|
68
|
-
return schema2;
|
|
69
|
-
} else if (config.type === "date") {
|
|
70
|
-
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
|
|
71
|
-
schema2 = base(schema2, key, config);
|
|
72
|
-
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()));
|
|
73
|
-
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()));
|
|
74
|
-
return schema2;
|
|
75
|
-
} else if (config.type === "object") {
|
|
76
|
-
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
|
|
77
|
-
schema2 = base(schema2, key, config);
|
|
78
|
-
const nested_properties = {};
|
|
79
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
80
|
-
schema2 = schema2.shape(nested_properties);
|
|
81
|
-
return schema2;
|
|
82
|
-
} else if (config.type === "array") {
|
|
83
|
-
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
|
|
84
|
-
schema2 = base(schema2, key, config);
|
|
85
|
-
if (config.min !== void 0)
|
|
86
|
-
schema2 = schema2.min(
|
|
87
|
-
config.min,
|
|
88
|
-
({ path, min }) => (error_messages?.array?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
89
|
-
);
|
|
90
|
-
if (config.max !== void 0)
|
|
91
|
-
schema2 = schema2.max(
|
|
92
|
-
config.max,
|
|
93
|
-
({ path, max }) => (error_messages?.array?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
94
|
-
);
|
|
95
|
-
schema2 = schema2.of(build(key, config.items));
|
|
96
|
-
return schema2;
|
|
97
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
98
|
-
};
|
|
99
|
-
const properties = {};
|
|
100
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
101
|
-
return Yup.object().shape(properties);
|
|
102
|
-
};
|
|
103
|
-
export {
|
|
104
|
-
convertToYup
|
|
105
|
-
};
|