yuppi 1.2.2 → 1.2.4
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/Yuppi.class.js +10 -2
- package/dist/Yuppi.class.mjs +10 -2
- package/dist/defaults/YuppiOptions.default.js +2 -0
- package/dist/defaults/YuppiOptions.default.mjs +2 -0
- package/dist/main.js +10 -2
- package/dist/main.mjs +10 -2
- package/dist/patterns/Any.pattern.d.mts +1 -1
- package/dist/patterns/Any.pattern.d.ts +1 -1
- package/dist/patterns/Domain.pattern.d.mts +1 -1
- package/dist/patterns/Domain.pattern.d.ts +1 -1
- package/dist/patterns/Email.pattern.d.mts +1 -1
- package/dist/patterns/Email.pattern.d.ts +1 -1
- package/dist/patterns/HTTP.pattern.d.mts +1 -1
- package/dist/patterns/HTTP.pattern.d.ts +1 -1
- package/dist/patterns/PhoneNumber.pattern.d.mts +1 -1
- package/dist/patterns/PhoneNumber.pattern.d.ts +1 -1
- package/dist/patterns/URI.pattern.d.mts +1 -1
- package/dist/patterns/URI.pattern.d.ts +1 -1
- package/dist/patterns/Username.pattern.d.mts +1 -1
- package/dist/patterns/Username.pattern.d.ts +1 -1
- package/dist/types/Schema.type.d.mts +2 -0
- package/dist/types/Schema.type.d.ts +2 -0
- package/dist/types/YuppiOptions.type.d.mts +2 -0
- package/dist/types/YuppiOptions.type.d.ts +2 -0
- package/dist/utils/ConvertToJSONSchema.util.js +2 -2
- package/dist/utils/ConvertToJSONSchema.util.mjs +2 -2
- package/dist/utils/ConvertToYup.util.js +6 -0
- package/dist/utils/ConvertToYup.util.mjs +6 -0
- package/package.json +5 -7
package/dist/Yuppi.class.js
CHANGED
|
@@ -71,6 +71,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
71
71
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
72
72
|
schema2 = base(schema2, key, config);
|
|
73
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
|
+
);
|
|
74
79
|
if (config.min !== void 0)
|
|
75
80
|
schema2 = schema2.min(
|
|
76
81
|
config.min,
|
|
@@ -87,6 +92,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
87
92
|
} else if (config.type === "number") {
|
|
88
93
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
89
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));
|
|
90
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()));
|
|
91
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()));
|
|
92
98
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
@@ -137,11 +143,11 @@ var import_typebox = require("@sinclair/typebox");
|
|
|
137
143
|
var convertToJSONSchema = (schema) => {
|
|
138
144
|
const build = (key, config) => {
|
|
139
145
|
if (config.type === "string") {
|
|
140
|
-
let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
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 });
|
|
141
147
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
142
148
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
143
149
|
} else if (config.type === "number") {
|
|
144
|
-
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 });
|
|
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 });
|
|
145
151
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
146
152
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
147
153
|
} else if (config.type === "boolean") {
|
|
@@ -179,11 +185,13 @@ var YuppiOptionsDefault = {
|
|
|
179
185
|
},
|
|
180
186
|
string: {
|
|
181
187
|
type: "Field {path} must be a string",
|
|
188
|
+
enum: "Field {path} must be one of the allowed values",
|
|
182
189
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
183
190
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
184
191
|
},
|
|
185
192
|
number: {
|
|
186
193
|
type: "Field {path} must be a number",
|
|
194
|
+
enum: "Field {path} must be one of the allowed values",
|
|
187
195
|
min: "Field {path} must be greater than or equal to {min}",
|
|
188
196
|
max: "Field {path} must be less than or equal to {max}",
|
|
189
197
|
integer: "Field {path} must be an integer",
|
package/dist/Yuppi.class.mjs
CHANGED
|
@@ -37,6 +37,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
37
37
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
38
38
|
schema2 = base(schema2, key, config);
|
|
39
39
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
40
|
+
if (config.enum !== void 0)
|
|
41
|
+
schema2 = schema2.oneOf(
|
|
42
|
+
config.enum.map((item) => item.trim()),
|
|
43
|
+
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
44
|
+
);
|
|
40
45
|
if (config.min !== void 0)
|
|
41
46
|
schema2 = schema2.min(
|
|
42
47
|
config.min,
|
|
@@ -53,6 +58,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
53
58
|
} else if (config.type === "number") {
|
|
54
59
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
55
60
|
schema2 = base(schema2, key, config);
|
|
61
|
+
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
56
62
|
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()));
|
|
57
63
|
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()));
|
|
58
64
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
@@ -103,11 +109,11 @@ import { Type } from "@sinclair/typebox";
|
|
|
103
109
|
var convertToJSONSchema = (schema) => {
|
|
104
110
|
const build = (key, config) => {
|
|
105
111
|
if (config.type === "string") {
|
|
106
|
-
let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
112
|
+
let schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
107
113
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
108
114
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
109
115
|
} else if (config.type === "number") {
|
|
110
|
-
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 });
|
|
116
|
+
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 });
|
|
111
117
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
112
118
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
113
119
|
} else if (config.type === "boolean") {
|
|
@@ -145,11 +151,13 @@ var YuppiOptionsDefault = {
|
|
|
145
151
|
},
|
|
146
152
|
string: {
|
|
147
153
|
type: "Field {path} must be a string",
|
|
154
|
+
enum: "Field {path} must be one of the allowed values",
|
|
148
155
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
149
156
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
150
157
|
},
|
|
151
158
|
number: {
|
|
152
159
|
type: "Field {path} must be a number",
|
|
160
|
+
enum: "Field {path} must be one of the allowed values",
|
|
153
161
|
min: "Field {path} must be greater than or equal to {min}",
|
|
154
162
|
max: "Field {path} must be less than or equal to {max}",
|
|
155
163
|
integer: "Field {path} must be an integer",
|
|
@@ -32,11 +32,13 @@ var YuppiOptionsDefault = {
|
|
|
32
32
|
},
|
|
33
33
|
string: {
|
|
34
34
|
type: "Field {path} must be a string",
|
|
35
|
+
enum: "Field {path} must be one of the allowed values",
|
|
35
36
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
36
37
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
37
38
|
},
|
|
38
39
|
number: {
|
|
39
40
|
type: "Field {path} must be a number",
|
|
41
|
+
enum: "Field {path} must be one of the allowed values",
|
|
40
42
|
min: "Field {path} must be greater than or equal to {min}",
|
|
41
43
|
max: "Field {path} must be less than or equal to {max}",
|
|
42
44
|
integer: "Field {path} must be an integer",
|
|
@@ -8,11 +8,13 @@ var YuppiOptionsDefault = {
|
|
|
8
8
|
},
|
|
9
9
|
string: {
|
|
10
10
|
type: "Field {path} must be a string",
|
|
11
|
+
enum: "Field {path} must be one of the allowed values",
|
|
11
12
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
12
13
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
13
14
|
},
|
|
14
15
|
number: {
|
|
15
16
|
type: "Field {path} must be a number",
|
|
17
|
+
enum: "Field {path} must be one of the allowed values",
|
|
16
18
|
min: "Field {path} must be greater than or equal to {min}",
|
|
17
19
|
max: "Field {path} must be less than or equal to {max}",
|
|
18
20
|
integer: "Field {path} must be an integer",
|
package/dist/main.js
CHANGED
|
@@ -74,6 +74,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
74
74
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
75
75
|
schema2 = base(schema2, key, config);
|
|
76
76
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
77
|
+
if (config.enum !== void 0)
|
|
78
|
+
schema2 = schema2.oneOf(
|
|
79
|
+
config.enum.map((item) => item.trim()),
|
|
80
|
+
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
81
|
+
);
|
|
77
82
|
if (config.min !== void 0)
|
|
78
83
|
schema2 = schema2.min(
|
|
79
84
|
config.min,
|
|
@@ -90,6 +95,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
90
95
|
} else if (config.type === "number") {
|
|
91
96
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
92
97
|
schema2 = base(schema2, key, config);
|
|
98
|
+
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
93
99
|
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
100
|
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
101
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
@@ -140,11 +146,11 @@ var import_typebox = require("@sinclair/typebox");
|
|
|
140
146
|
var convertToJSONSchema = (schema) => {
|
|
141
147
|
const build = (key, config) => {
|
|
142
148
|
if (config.type === "string") {
|
|
143
|
-
let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
149
|
+
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 });
|
|
144
150
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
145
151
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
146
152
|
} else if (config.type === "number") {
|
|
147
|
-
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 });
|
|
153
|
+
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 });
|
|
148
154
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
149
155
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
150
156
|
} else if (config.type === "boolean") {
|
|
@@ -182,11 +188,13 @@ var YuppiOptionsDefault = {
|
|
|
182
188
|
},
|
|
183
189
|
string: {
|
|
184
190
|
type: "Field {path} must be a string",
|
|
191
|
+
enum: "Field {path} must be one of the allowed values",
|
|
185
192
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
186
193
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
187
194
|
},
|
|
188
195
|
number: {
|
|
189
196
|
type: "Field {path} must be a number",
|
|
197
|
+
enum: "Field {path} must be one of the allowed values",
|
|
190
198
|
min: "Field {path} must be greater than or equal to {min}",
|
|
191
199
|
max: "Field {path} must be less than or equal to {max}",
|
|
192
200
|
integer: "Field {path} must be an integer",
|
package/dist/main.mjs
CHANGED
|
@@ -43,6 +43,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
43
43
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
44
44
|
schema2 = base(schema2, key, config);
|
|
45
45
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
46
|
+
if (config.enum !== void 0)
|
|
47
|
+
schema2 = schema2.oneOf(
|
|
48
|
+
config.enum.map((item) => item.trim()),
|
|
49
|
+
({ path }) => (error_messages?.string?.enum ?? "").split("{path}").join(path)
|
|
50
|
+
);
|
|
46
51
|
if (config.min !== void 0)
|
|
47
52
|
schema2 = schema2.min(
|
|
48
53
|
config.min,
|
|
@@ -59,6 +64,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
59
64
|
} else if (config.type === "number") {
|
|
60
65
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
61
66
|
schema2 = base(schema2, key, config);
|
|
67
|
+
if (config.enum !== void 0) schema2 = schema2.oneOf(config.enum, ({ path }) => (error_messages?.number?.enum ?? "").split("{path}").join(path));
|
|
62
68
|
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()));
|
|
63
69
|
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()));
|
|
64
70
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
@@ -109,11 +115,11 @@ import { Type } from "@sinclair/typebox";
|
|
|
109
115
|
var convertToJSONSchema = (schema) => {
|
|
110
116
|
const build = (key, config) => {
|
|
111
117
|
if (config.type === "string") {
|
|
112
|
-
let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
118
|
+
let schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
113
119
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
114
120
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
115
121
|
} else if (config.type === "number") {
|
|
116
|
-
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 });
|
|
122
|
+
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 });
|
|
117
123
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
118
124
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
119
125
|
} else if (config.type === "boolean") {
|
|
@@ -151,11 +157,13 @@ var YuppiOptionsDefault = {
|
|
|
151
157
|
},
|
|
152
158
|
string: {
|
|
153
159
|
type: "Field {path} must be a string",
|
|
160
|
+
enum: "Field {path} must be one of the allowed values",
|
|
154
161
|
min: "Field {path} must be at least {min} character{plural_suffix}",
|
|
155
162
|
max: "Field {path} must be at most {max} character{plural_suffix}"
|
|
156
163
|
},
|
|
157
164
|
number: {
|
|
158
165
|
type: "Field {path} must be a number",
|
|
166
|
+
enum: "Field {path} must be one of the allowed values",
|
|
159
167
|
min: "Field {path} must be greater than or equal to {min}",
|
|
160
168
|
max: "Field {path} must be less than or equal to {max}",
|
|
161
169
|
integer: "Field {path} must be an integer",
|
|
@@ -6,6 +6,7 @@ type Base = {
|
|
|
6
6
|
};
|
|
7
7
|
type String = Base & {
|
|
8
8
|
type: "string";
|
|
9
|
+
enum?: string[];
|
|
9
10
|
min?: number;
|
|
10
11
|
max?: number;
|
|
11
12
|
lowercase?: boolean;
|
|
@@ -13,6 +14,7 @@ type String = Base & {
|
|
|
13
14
|
};
|
|
14
15
|
type Number = Base & {
|
|
15
16
|
type: "number";
|
|
17
|
+
enum?: number[];
|
|
16
18
|
min?: number;
|
|
17
19
|
max?: number;
|
|
18
20
|
integer?: boolean;
|
|
@@ -6,6 +6,7 @@ type Base = {
|
|
|
6
6
|
};
|
|
7
7
|
type String = Base & {
|
|
8
8
|
type: "string";
|
|
9
|
+
enum?: string[];
|
|
9
10
|
min?: number;
|
|
10
11
|
max?: number;
|
|
11
12
|
lowercase?: boolean;
|
|
@@ -13,6 +14,7 @@ type String = Base & {
|
|
|
13
14
|
};
|
|
14
15
|
type Number = Base & {
|
|
15
16
|
type: "number";
|
|
17
|
+
enum?: number[];
|
|
16
18
|
min?: number;
|
|
17
19
|
max?: number;
|
|
18
20
|
integer?: boolean;
|
|
@@ -32,11 +32,11 @@ var Any = "[\\s\\S]*";
|
|
|
32
32
|
var convertToJSONSchema = (schema) => {
|
|
33
33
|
const build = (key, config) => {
|
|
34
34
|
if (config.type === "string") {
|
|
35
|
-
let schema2 = import_typebox.Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
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
36
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
37
37
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
38
38
|
} else if (config.type === "number") {
|
|
39
|
-
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 });
|
|
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
40
|
if (config.nullable) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
41
41
|
return config.required ? schema2 : import_typebox.Type.Optional(schema2);
|
|
42
42
|
} else if (config.type === "boolean") {
|
|
@@ -8,11 +8,11 @@ var Any = "[\\s\\S]*";
|
|
|
8
8
|
var convertToJSONSchema = (schema) => {
|
|
9
9
|
const build = (key, config) => {
|
|
10
10
|
if (config.type === "string") {
|
|
11
|
-
let schema2 = Type.String({ minLength: config.min, maxLength: config.max, pattern: new RegExp(config.pattern ?? Any).source, default: config.default });
|
|
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
12
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
13
13
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
14
14
|
} else if (config.type === "number") {
|
|
15
|
-
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 });
|
|
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
16
|
if (config.nullable) schema2 = Type.Union([schema2, Type.Null()]);
|
|
17
17
|
return config.required ? schema2 : Type.Optional(schema2);
|
|
18
18
|
} else if (config.type === "boolean") {
|
|
@@ -68,6 +68,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
68
68
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
69
69
|
schema2 = base(schema2, key, config);
|
|
70
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
|
+
);
|
|
71
76
|
if (config.min !== void 0)
|
|
72
77
|
schema2 = schema2.min(
|
|
73
78
|
config.min,
|
|
@@ -84,6 +89,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
84
89
|
} else if (config.type === "number") {
|
|
85
90
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
86
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));
|
|
87
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()));
|
|
88
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()));
|
|
89
95
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
|
@@ -34,6 +34,11 @@ var convertToYup = (schema, error_messages) => {
|
|
|
34
34
|
schema2 = Yup.string().typeError(({ path }) => (error_messages?.string?.type ?? "").split("{path}").join(path));
|
|
35
35
|
schema2 = base(schema2, key, config);
|
|
36
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
|
+
);
|
|
37
42
|
if (config.min !== void 0)
|
|
38
43
|
schema2 = schema2.min(
|
|
39
44
|
config.min,
|
|
@@ -50,6 +55,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
50
55
|
} else if (config.type === "number") {
|
|
51
56
|
schema2 = Yup.number().typeError(({ path }) => (error_messages?.number?.type ?? "").split("{path}").join(path));
|
|
52
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));
|
|
53
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()));
|
|
54
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()));
|
|
55
61
|
if (config.integer === true) schema2 = schema2.integer(({ path }) => (error_messages?.number?.integer ?? "").split("{path}").join(path));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuppi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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",
|
|
@@ -15,17 +15,15 @@
|
|
|
15
15
|
"lint": "eslint ./"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sinclair/typebox": "^0.34.
|
|
18
|
+
"@sinclair/typebox": "^0.34.41",
|
|
19
19
|
"@types/lodash": "^4.17.20",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
|
-
"yup": "^1.
|
|
21
|
+
"yup": "^1.7.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"
|
|
24
|
+
"neatlint": "^1.0.0",
|
|
25
25
|
"prettier": "^3.6.2",
|
|
26
|
-
"tsup": "^8.5.0"
|
|
27
|
-
"typescript": "^5.8.3",
|
|
28
|
-
"typescript-eslint": "^8.37.0"
|
|
26
|
+
"tsup": "^8.5.0"
|
|
29
27
|
},
|
|
30
28
|
"repository": {
|
|
31
29
|
"type": "git",
|