yuppi 1.2.6 → 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/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 -7
- package/dist/utils/ConvertToJSONSchema.util.d.ts +0 -7
- 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
package/dist/main.d.mts
CHANGED
|
@@ -1,17 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { AnyObject as AnyObject$1, ValidateOptions as ValidateOptions$1, ValidationError as ValidationError$1 } from 'yup';
|
|
3
|
+
import { TObject } from '@sinclair/typebox';
|
|
4
|
+
|
|
5
|
+
type AnyObject = AnyObject$1;
|
|
6
|
+
|
|
7
|
+
type JSONSchema = TObject;
|
|
8
|
+
|
|
9
|
+
type Base = {
|
|
10
|
+
pattern?: string;
|
|
11
|
+
default?: unknown;
|
|
12
|
+
nullable: boolean;
|
|
13
|
+
required: boolean;
|
|
14
|
+
};
|
|
15
|
+
type String = Base & {
|
|
16
|
+
type: 'string';
|
|
17
|
+
enum?: string[];
|
|
18
|
+
min?: number;
|
|
19
|
+
max?: number;
|
|
20
|
+
lowercase?: boolean;
|
|
21
|
+
uppercase?: boolean;
|
|
22
|
+
};
|
|
23
|
+
type Number = Base & {
|
|
24
|
+
type: 'number';
|
|
25
|
+
enum?: number[];
|
|
26
|
+
min?: number;
|
|
27
|
+
max?: number;
|
|
28
|
+
integer?: boolean;
|
|
29
|
+
positive?: boolean;
|
|
30
|
+
negative?: boolean;
|
|
31
|
+
};
|
|
32
|
+
type Boolean = Base & {
|
|
33
|
+
type: 'boolean';
|
|
34
|
+
};
|
|
35
|
+
type Date = Base & {
|
|
36
|
+
type: 'date';
|
|
37
|
+
min?: string;
|
|
38
|
+
max?: string;
|
|
39
|
+
};
|
|
40
|
+
type Object$1 = Base & {
|
|
41
|
+
type: 'object';
|
|
42
|
+
properties: Schema;
|
|
43
|
+
};
|
|
44
|
+
type Array = Base & {
|
|
45
|
+
type: 'array';
|
|
46
|
+
min?: number;
|
|
47
|
+
max?: number;
|
|
48
|
+
items: Types;
|
|
49
|
+
};
|
|
50
|
+
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
51
|
+
type Schema = Record<string, Types>;
|
|
52
|
+
|
|
53
|
+
type ValidateOptions = ValidateOptions$1;
|
|
54
|
+
|
|
55
|
+
type YuppiOptions = {
|
|
56
|
+
error_messages?: {
|
|
57
|
+
base?: {
|
|
58
|
+
pattern?: string;
|
|
59
|
+
nullable?: string;
|
|
60
|
+
required?: string;
|
|
61
|
+
};
|
|
62
|
+
string?: {
|
|
63
|
+
type?: string;
|
|
64
|
+
enum?: string;
|
|
65
|
+
min?: string;
|
|
66
|
+
max?: string;
|
|
67
|
+
};
|
|
68
|
+
number?: {
|
|
69
|
+
type?: string;
|
|
70
|
+
enum?: string;
|
|
71
|
+
min?: string;
|
|
72
|
+
max?: string;
|
|
73
|
+
integer?: string;
|
|
74
|
+
positive?: string;
|
|
75
|
+
negative?: string;
|
|
76
|
+
};
|
|
77
|
+
boolean?: {
|
|
78
|
+
type?: string;
|
|
79
|
+
};
|
|
80
|
+
date?: {
|
|
81
|
+
type?: string;
|
|
82
|
+
min?: string;
|
|
83
|
+
max?: string;
|
|
84
|
+
};
|
|
85
|
+
object?: {
|
|
86
|
+
type?: string;
|
|
87
|
+
};
|
|
88
|
+
array?: {
|
|
89
|
+
type?: string;
|
|
90
|
+
min?: string;
|
|
91
|
+
max?: string;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
validate_options?: ValidateOptions;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare class Yuppi {
|
|
98
|
+
private readonly options;
|
|
99
|
+
constructor(options?: YuppiOptions);
|
|
100
|
+
validate(schema: Schema, properties: AnyObject): {
|
|
101
|
+
[x: string]: any;
|
|
102
|
+
[x: number]: any;
|
|
103
|
+
};
|
|
104
|
+
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
105
|
+
[x: string]: any;
|
|
106
|
+
}, yup.AnyObject, {
|
|
107
|
+
[x: string]: any;
|
|
108
|
+
}, "">;
|
|
109
|
+
convertToJSONSchema(schema: Schema): JSONSchema;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare const Any = "[\\s\\S]*";
|
|
113
|
+
|
|
114
|
+
declare const Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
|
|
115
|
+
|
|
116
|
+
declare const Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
|
|
117
|
+
|
|
118
|
+
declare const HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
|
|
119
|
+
|
|
120
|
+
declare const PhoneNumber = "^\\d{4}-\\d{7,12}$";
|
|
121
|
+
|
|
122
|
+
declare const URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
|
|
123
|
+
|
|
124
|
+
declare const Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
|
|
125
|
+
|
|
126
|
+
declare const Patterns_barrel_Any: typeof Any;
|
|
127
|
+
declare const Patterns_barrel_Domain: typeof Domain;
|
|
128
|
+
declare const Patterns_barrel_Email: typeof Email;
|
|
129
|
+
declare const Patterns_barrel_HTTP: typeof HTTP;
|
|
130
|
+
declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
|
|
131
|
+
declare const Patterns_barrel_URI: typeof URI;
|
|
132
|
+
declare const Patterns_barrel_Username: typeof Username;
|
|
133
|
+
declare namespace Patterns_barrel {
|
|
134
|
+
export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type ValidationError = ValidationError$1;
|
|
138
|
+
|
|
139
|
+
export { type AnyObject, type JSONSchema, Patterns_barrel as Patterns, type Schema, type ValidateOptions, type ValidationError, Yuppi, type YuppiOptions };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,17 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { AnyObject as AnyObject$1, ValidateOptions as ValidateOptions$1, ValidationError as ValidationError$1 } from 'yup';
|
|
3
|
+
import { TObject } from '@sinclair/typebox';
|
|
4
|
+
|
|
5
|
+
type AnyObject = AnyObject$1;
|
|
6
|
+
|
|
7
|
+
type JSONSchema = TObject;
|
|
8
|
+
|
|
9
|
+
type Base = {
|
|
10
|
+
pattern?: string;
|
|
11
|
+
default?: unknown;
|
|
12
|
+
nullable: boolean;
|
|
13
|
+
required: boolean;
|
|
14
|
+
};
|
|
15
|
+
type String = Base & {
|
|
16
|
+
type: 'string';
|
|
17
|
+
enum?: string[];
|
|
18
|
+
min?: number;
|
|
19
|
+
max?: number;
|
|
20
|
+
lowercase?: boolean;
|
|
21
|
+
uppercase?: boolean;
|
|
22
|
+
};
|
|
23
|
+
type Number = Base & {
|
|
24
|
+
type: 'number';
|
|
25
|
+
enum?: number[];
|
|
26
|
+
min?: number;
|
|
27
|
+
max?: number;
|
|
28
|
+
integer?: boolean;
|
|
29
|
+
positive?: boolean;
|
|
30
|
+
negative?: boolean;
|
|
31
|
+
};
|
|
32
|
+
type Boolean = Base & {
|
|
33
|
+
type: 'boolean';
|
|
34
|
+
};
|
|
35
|
+
type Date = Base & {
|
|
36
|
+
type: 'date';
|
|
37
|
+
min?: string;
|
|
38
|
+
max?: string;
|
|
39
|
+
};
|
|
40
|
+
type Object$1 = Base & {
|
|
41
|
+
type: 'object';
|
|
42
|
+
properties: Schema;
|
|
43
|
+
};
|
|
44
|
+
type Array = Base & {
|
|
45
|
+
type: 'array';
|
|
46
|
+
min?: number;
|
|
47
|
+
max?: number;
|
|
48
|
+
items: Types;
|
|
49
|
+
};
|
|
50
|
+
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
51
|
+
type Schema = Record<string, Types>;
|
|
52
|
+
|
|
53
|
+
type ValidateOptions = ValidateOptions$1;
|
|
54
|
+
|
|
55
|
+
type YuppiOptions = {
|
|
56
|
+
error_messages?: {
|
|
57
|
+
base?: {
|
|
58
|
+
pattern?: string;
|
|
59
|
+
nullable?: string;
|
|
60
|
+
required?: string;
|
|
61
|
+
};
|
|
62
|
+
string?: {
|
|
63
|
+
type?: string;
|
|
64
|
+
enum?: string;
|
|
65
|
+
min?: string;
|
|
66
|
+
max?: string;
|
|
67
|
+
};
|
|
68
|
+
number?: {
|
|
69
|
+
type?: string;
|
|
70
|
+
enum?: string;
|
|
71
|
+
min?: string;
|
|
72
|
+
max?: string;
|
|
73
|
+
integer?: string;
|
|
74
|
+
positive?: string;
|
|
75
|
+
negative?: string;
|
|
76
|
+
};
|
|
77
|
+
boolean?: {
|
|
78
|
+
type?: string;
|
|
79
|
+
};
|
|
80
|
+
date?: {
|
|
81
|
+
type?: string;
|
|
82
|
+
min?: string;
|
|
83
|
+
max?: string;
|
|
84
|
+
};
|
|
85
|
+
object?: {
|
|
86
|
+
type?: string;
|
|
87
|
+
};
|
|
88
|
+
array?: {
|
|
89
|
+
type?: string;
|
|
90
|
+
min?: string;
|
|
91
|
+
max?: string;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
validate_options?: ValidateOptions;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare class Yuppi {
|
|
98
|
+
private readonly options;
|
|
99
|
+
constructor(options?: YuppiOptions);
|
|
100
|
+
validate(schema: Schema, properties: AnyObject): {
|
|
101
|
+
[x: string]: any;
|
|
102
|
+
[x: number]: any;
|
|
103
|
+
};
|
|
104
|
+
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
105
|
+
[x: string]: any;
|
|
106
|
+
}, yup.AnyObject, {
|
|
107
|
+
[x: string]: any;
|
|
108
|
+
}, "">;
|
|
109
|
+
convertToJSONSchema(schema: Schema): JSONSchema;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare const Any = "[\\s\\S]*";
|
|
113
|
+
|
|
114
|
+
declare const Domain = "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
|
|
115
|
+
|
|
116
|
+
declare const Email = "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$";
|
|
117
|
+
|
|
118
|
+
declare const HTTP = "^(https?:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
|
|
119
|
+
|
|
120
|
+
declare const PhoneNumber = "^\\d{4}-\\d{7,12}$";
|
|
121
|
+
|
|
122
|
+
declare const URI = "^([a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\/)([a-zA-Z0-9._%+-]+(:[a-zA-Z0-9._%+-]+)?@)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[a-zA-Z0-9._-~%!$&'()*+,;=:@/]*)?(\\?[a-zA-Z0-9._~%!$&'()*+,;=:@/?-]*)?$";
|
|
123
|
+
|
|
124
|
+
declare const Username = "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$";
|
|
125
|
+
|
|
126
|
+
declare const Patterns_barrel_Any: typeof Any;
|
|
127
|
+
declare const Patterns_barrel_Domain: typeof Domain;
|
|
128
|
+
declare const Patterns_barrel_Email: typeof Email;
|
|
129
|
+
declare const Patterns_barrel_HTTP: typeof HTTP;
|
|
130
|
+
declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
|
|
131
|
+
declare const Patterns_barrel_URI: typeof URI;
|
|
132
|
+
declare const Patterns_barrel_Username: typeof Username;
|
|
133
|
+
declare namespace Patterns_barrel {
|
|
134
|
+
export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type ValidationError = ValidationError$1;
|
|
138
|
+
|
|
139
|
+
export { type AnyObject, type JSONSchema, Patterns_barrel as Patterns, type Schema, type ValidateOptions, type ValidationError, Yuppi, type YuppiOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuppi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "Schemas that can be converted to Yup and JSON Schema.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/keift/yuppi",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"yup": "^1.7.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"neatlint": "^1.1.
|
|
24
|
+
"neatlint": "^1.1.8",
|
|
25
25
|
"prettier": "^3.6.2",
|
|
26
26
|
"tsup": "^8.5.0"
|
|
27
27
|
},
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Any } from './patterns/Any.pattern.mjs';
|
|
2
|
-
import { Domain } from './patterns/Domain.pattern.mjs';
|
|
3
|
-
import { Email } from './patterns/Email.pattern.mjs';
|
|
4
|
-
import { HTTP } from './patterns/HTTP.pattern.mjs';
|
|
5
|
-
import { PhoneNumber } from './patterns/PhoneNumber.pattern.mjs';
|
|
6
|
-
import { URI } from './patterns/URI.pattern.mjs';
|
|
7
|
-
import { Username } from './patterns/Username.pattern.mjs';
|
|
8
|
-
|
|
9
|
-
declare const Patterns_barrel_Any: typeof Any;
|
|
10
|
-
declare const Patterns_barrel_Domain: typeof Domain;
|
|
11
|
-
declare const Patterns_barrel_Email: typeof Email;
|
|
12
|
-
declare const Patterns_barrel_HTTP: typeof HTTP;
|
|
13
|
-
declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
|
|
14
|
-
declare const Patterns_barrel_URI: typeof URI;
|
|
15
|
-
declare const Patterns_barrel_Username: typeof Username;
|
|
16
|
-
declare namespace Patterns_barrel {
|
|
17
|
-
export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { Patterns_barrel as P };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Any } from './patterns/Any.pattern.js';
|
|
2
|
-
import { Domain } from './patterns/Domain.pattern.js';
|
|
3
|
-
import { Email } from './patterns/Email.pattern.js';
|
|
4
|
-
import { HTTP } from './patterns/HTTP.pattern.js';
|
|
5
|
-
import { PhoneNumber } from './patterns/PhoneNumber.pattern.js';
|
|
6
|
-
import { URI } from './patterns/URI.pattern.js';
|
|
7
|
-
import { Username } from './patterns/Username.pattern.js';
|
|
8
|
-
|
|
9
|
-
declare const Patterns_barrel_Any: typeof Any;
|
|
10
|
-
declare const Patterns_barrel_Domain: typeof Domain;
|
|
11
|
-
declare const Patterns_barrel_Email: typeof Email;
|
|
12
|
-
declare const Patterns_barrel_HTTP: typeof HTTP;
|
|
13
|
-
declare const Patterns_barrel_PhoneNumber: typeof PhoneNumber;
|
|
14
|
-
declare const Patterns_barrel_URI: typeof URI;
|
|
15
|
-
declare const Patterns_barrel_Username: typeof Username;
|
|
16
|
-
declare namespace Patterns_barrel {
|
|
17
|
-
export { Patterns_barrel_Any as Any, Patterns_barrel_Domain as Domain, Patterns_barrel_Email as Email, Patterns_barrel_HTTP as HTTP, Patterns_barrel_PhoneNumber as PhoneNumber, Patterns_barrel_URI as URI, Patterns_barrel_Username as Username };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { Patterns_barrel as P };
|
package/dist/Yuppi.class.d.mts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
2
|
-
import { AnyObject } from './types/AnyObject.type.mjs';
|
|
3
|
-
import { JSONSchema } from './types/JSONSchema.type.mjs';
|
|
4
|
-
import { Schema } from './types/Schema.type.mjs';
|
|
5
|
-
import { YuppiOptions } from './types/YuppiOptions.type.mjs';
|
|
6
|
-
import '@sinclair/typebox';
|
|
7
|
-
import './types/ValidateOptions.type.mjs';
|
|
8
|
-
|
|
9
|
-
declare class Yuppi {
|
|
10
|
-
private readonly options;
|
|
11
|
-
constructor(options?: YuppiOptions);
|
|
12
|
-
validate(schema: Schema, properties: AnyObject): {
|
|
13
|
-
[x: string]: any;
|
|
14
|
-
[x: number]: any;
|
|
15
|
-
};
|
|
16
|
-
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
17
|
-
[x: string]: any;
|
|
18
|
-
}, yup.AnyObject, {
|
|
19
|
-
[x: string]: any;
|
|
20
|
-
}, "">;
|
|
21
|
-
convertToJSONSchema(schema: Schema): JSONSchema;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { Yuppi };
|
package/dist/Yuppi.class.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
2
|
-
import { AnyObject } from './types/AnyObject.type.js';
|
|
3
|
-
import { JSONSchema } from './types/JSONSchema.type.js';
|
|
4
|
-
import { Schema } from './types/Schema.type.js';
|
|
5
|
-
import { YuppiOptions } from './types/YuppiOptions.type.js';
|
|
6
|
-
import '@sinclair/typebox';
|
|
7
|
-
import './types/ValidateOptions.type.js';
|
|
8
|
-
|
|
9
|
-
declare class Yuppi {
|
|
10
|
-
private readonly options;
|
|
11
|
-
constructor(options?: YuppiOptions);
|
|
12
|
-
validate(schema: Schema, properties: AnyObject): {
|
|
13
|
-
[x: string]: any;
|
|
14
|
-
[x: number]: any;
|
|
15
|
-
};
|
|
16
|
-
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
17
|
-
[x: string]: any;
|
|
18
|
-
}, yup.AnyObject, {
|
|
19
|
-
[x: string]: any;
|
|
20
|
-
}, "">;
|
|
21
|
-
convertToJSONSchema(schema: Schema): JSONSchema;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { Yuppi };
|
package/dist/Yuppi.class.js
DELETED
|
@@ -1,244 +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/Yuppi.class.ts
|
|
31
|
-
var Yuppi_class_exports = {};
|
|
32
|
-
__export(Yuppi_class_exports, {
|
|
33
|
-
Yuppi: () => Yuppi
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(Yuppi_class_exports);
|
|
36
|
-
var import_lodash = __toESM(require("lodash"));
|
|
37
|
-
|
|
38
|
-
// src/utils/ConvertToYup.util.ts
|
|
39
|
-
var Yup = __toESM(require("yup"));
|
|
40
|
-
|
|
41
|
-
// src/patterns/Any.pattern.ts
|
|
42
|
-
var Any = "[\\s\\S]*";
|
|
43
|
-
|
|
44
|
-
// src/utils/ConvertToYup.util.ts
|
|
45
|
-
var convertToYup = (schema, error_messages) => {
|
|
46
|
-
const base = (schema2, key, config) => {
|
|
47
|
-
schema2 = schema2.nullable();
|
|
48
|
-
if (config.required)
|
|
49
|
-
schema2 = schema2.test(
|
|
50
|
-
"required",
|
|
51
|
-
({ path }) => (error_messages?.base?.required ?? "").split("{path}").join(path),
|
|
52
|
-
(property) => {
|
|
53
|
-
if (property === void 0) return false;
|
|
54
|
-
if (typeof property === "string" && property.trim() === "") return false;
|
|
55
|
-
if (Array.isArray(property) && property.length === 0) return false;
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path }) => (error_messages?.base?.nullable ?? "").split("{path}").join(path));
|
|
60
|
-
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
61
|
-
if (config.pattern !== void 0 && schema2.matches !== void 0)
|
|
62
|
-
schema2 = schema2.matches(
|
|
63
|
-
new RegExp(config.pattern ?? Any),
|
|
64
|
-
({ path }) => (error_messages?.base?.pattern ?? "").split("{path}").join(path).split("{pattern}").join(new RegExp(config.pattern ?? Any).source)
|
|
65
|
-
);
|
|
66
|
-
return schema2;
|
|
67
|
-
};
|
|
68
|
-
const build = (key, config) => {
|
|
69
|
-
let schema2;
|
|
70
|
-
if (config.type === "string") {
|
|
71
|
-
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
72
|
-
schema2 = base(schema2, key, config);
|
|
73
|
-
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
74
|
-
if (config.enum !== void 0)
|
|
75
|
-
schema2 = schema2.oneOf(
|
|
76
|
-
config.enum.map((item) => item.trim()),
|
|
77
|
-
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
78
|
-
);
|
|
79
|
-
if (config.min !== void 0)
|
|
80
|
-
schema2 = schema2.min(
|
|
81
|
-
config.min,
|
|
82
|
-
({ path, min }) => (error_messages?.string?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
83
|
-
);
|
|
84
|
-
if (config.max !== void 0)
|
|
85
|
-
schema2 = schema2.max(
|
|
86
|
-
config.max,
|
|
87
|
-
({ path, max }) => (error_messages?.string?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
88
|
-
);
|
|
89
|
-
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
90
|
-
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
91
|
-
return schema2;
|
|
92
|
-
} else if (config.type === "number") {
|
|
93
|
-
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
94
|
-
schema2 = base(schema2, key, config);
|
|
95
|
-
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
96
|
-
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()));
|
|
97
|
-
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()));
|
|
98
|
-
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
99
|
-
if (config.positive === true) schema2 = schema2.positive(({ path }) => (error_messages?.number?.positive ?? "").split("{path}").join(path));
|
|
100
|
-
if (config.negative === true) schema2 = schema2.negative(({ path }) => (error_messages?.number?.negative ?? "").split("{path}").join(path));
|
|
101
|
-
return schema2;
|
|
102
|
-
} else if (config.type === "boolean") {
|
|
103
|
-
schema2 = Yup.boolean().typeError(({ path }) => (error_messages?.boolean?.type ?? "").split("{path}").join(path));
|
|
104
|
-
schema2 = base(schema2, key, config);
|
|
105
|
-
return schema2;
|
|
106
|
-
} else if (config.type === "date") {
|
|
107
|
-
schema2 = Yup.date().typeError(({ path }) => (error_messages?.date?.type ?? "").split("{path}").join(path));
|
|
108
|
-
schema2 = base(schema2, key, config);
|
|
109
|
-
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()));
|
|
110
|
-
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()));
|
|
111
|
-
return schema2;
|
|
112
|
-
} else if (config.type === "object") {
|
|
113
|
-
schema2 = Yup.object().typeError(({ path }) => (error_messages?.object?.type ?? "").split("{path}").join(path));
|
|
114
|
-
schema2 = base(schema2, key, config);
|
|
115
|
-
const nested_properties = {};
|
|
116
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
117
|
-
schema2 = schema2.shape(nested_properties);
|
|
118
|
-
return schema2;
|
|
119
|
-
} else if (config.type === "array") {
|
|
120
|
-
schema2 = Yup.array().typeError(({ path }) => (error_messages?.array?.type ?? "").split("{path}").join(path));
|
|
121
|
-
schema2 = base(schema2, key, config);
|
|
122
|
-
if (config.min !== void 0)
|
|
123
|
-
schema2 = schema2.min(
|
|
124
|
-
config.min,
|
|
125
|
-
({ path, min }) => (error_messages?.array?.min ?? "").split("{path}").join(path).split("{min}").join(min.toString()).split("{plural_suffix}").join(min > 1 ? "s" : "")
|
|
126
|
-
);
|
|
127
|
-
if (config.max !== void 0)
|
|
128
|
-
schema2 = schema2.max(
|
|
129
|
-
config.max,
|
|
130
|
-
({ path, max }) => (error_messages?.array?.max ?? "").split("{path}").join(path).split("{max}").join(max.toString()).split("{plural_suffix}").join(max > 1 ? "s" : "")
|
|
131
|
-
);
|
|
132
|
-
schema2 = schema2.of(build(key, config.items));
|
|
133
|
-
return schema2;
|
|
134
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
135
|
-
};
|
|
136
|
-
const properties = {};
|
|
137
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
138
|
-
return Yup.object().shape(properties);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// src/utils/ConvertToJSONSchema.util.ts
|
|
142
|
-
var import_typebox = require("@sinclair/typebox");
|
|
143
|
-
var convertToJSONSchema = (schema) => {
|
|
144
|
-
const build = (key, config) => {
|
|
145
|
-
if (config.type === "string") {
|
|
146
|
-
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 });
|
|
147
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
148
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
149
|
-
} else if (config.type === "number") {
|
|
150
|
-
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 });
|
|
151
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
152
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
153
|
-
} else if (config.type === "boolean") {
|
|
154
|
-
let schema2 = import_typebox.Type.Boolean({ default: config.default });
|
|
155
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
156
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
157
|
-
} else if (config.type === "date") {
|
|
158
|
-
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 });
|
|
159
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
160
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
161
|
-
} else if (config.type === "object") {
|
|
162
|
-
const nested_properties = {};
|
|
163
|
-
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
164
|
-
let schema2 = import_typebox.Type.Object(nested_properties);
|
|
165
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
166
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
167
|
-
} else if (config.type === "array") {
|
|
168
|
-
let schema2 = import_typebox.Type.Array(build(key, config.items), { minItems: config.min, maxItems: config.max, default: config.default });
|
|
169
|
-
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
170
|
-
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
171
|
-
} else throw new Error(`Unsupported schema type for ${key}`);
|
|
172
|
-
};
|
|
173
|
-
const properties = {};
|
|
174
|
-
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
175
|
-
return import_typebox.Type.Object(properties);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// src/defaults/YuppiOptions.default.ts
|
|
179
|
-
var YuppiOptionsDefault = {
|
|
180
|
-
error_messages: {
|
|
181
|
-
base: {
|
|
182
|
-
pattern: "Field {path} must match the required pattern {pattern}",
|
|
183
|
-
nullable: "Field {path} cannot be null",
|
|
184
|
-
required: "Field {path} is required"
|
|
185
|
-
},
|
|
186
|
-
string: {
|
|
187
|
-
type: "Field {path} must be a string",
|
|
188
|
-
enum: "Field {path} must be one of the allowed values",
|
|
189
|
-
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
190
|
-
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
191
|
-
},
|
|
192
|
-
number: {
|
|
193
|
-
type: "Field {path} must be a number",
|
|
194
|
-
enum: "Field {path} must be one of the allowed values",
|
|
195
|
-
min: "Field {path} must be greater than or equal to {min}",
|
|
196
|
-
max: "Field {path} must be less than or equal to {max}",
|
|
197
|
-
integer: "Field {path} must be an integer",
|
|
198
|
-
positive: "Field {path} must be a positive",
|
|
199
|
-
negative: "Field {path} must be a negative"
|
|
200
|
-
},
|
|
201
|
-
boolean: {
|
|
202
|
-
type: "Field {path} must be a boolean"
|
|
203
|
-
},
|
|
204
|
-
date: {
|
|
205
|
-
type: "Field {path} must be a date",
|
|
206
|
-
min: "Field {path} must be after {min}",
|
|
207
|
-
max: "Field {path} must be before {max}"
|
|
208
|
-
},
|
|
209
|
-
object: {
|
|
210
|
-
type: "Field {path} must be an object"
|
|
211
|
-
},
|
|
212
|
-
array: {
|
|
213
|
-
type: "Field {path} must be an array",
|
|
214
|
-
min: "Field {path} must be at least {min} item${plural_suffix}",
|
|
215
|
-
max: "Field {path} must be at most {max} item${plural_suffix}"
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
validate_options: {
|
|
219
|
-
abortEarly: false,
|
|
220
|
-
stripUnknown: true
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
// src/Yuppi.class.ts
|
|
225
|
-
var Yuppi = class {
|
|
226
|
-
constructor(options = YuppiOptionsDefault) {
|
|
227
|
-
this.options = import_lodash.default.merge({}, YuppiOptionsDefault, options);
|
|
228
|
-
}
|
|
229
|
-
validate(schema, properties) {
|
|
230
|
-
const yup_schema = convertToYup(schema, this.options.error_messages);
|
|
231
|
-
const validation = yup_schema.validateSync(properties, this.options.validate_options);
|
|
232
|
-
return validation;
|
|
233
|
-
}
|
|
234
|
-
convertToYup(schema) {
|
|
235
|
-
return convertToYup(schema, this.options.error_messages);
|
|
236
|
-
}
|
|
237
|
-
convertToJSONSchema(schema) {
|
|
238
|
-
return convertToJSONSchema(schema);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
-
0 && (module.exports = {
|
|
243
|
-
Yuppi
|
|
244
|
-
});
|