yuppi 1.3.5 → 1.3.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.js +22 -20
- package/dist/main.mjs +22 -20
- package/package.json +3 -3
package/dist/main.js
CHANGED
|
@@ -52,13 +52,15 @@ var convertToJSONSchema = (schema) => {
|
|
|
52
52
|
const build = (key, config) => {
|
|
53
53
|
let schema2;
|
|
54
54
|
if (config.type === "string") {
|
|
55
|
-
schema2 = import_typebox.Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern ? new RegExp(config.pattern).source : void 0, default: config.default });
|
|
55
|
+
schema2 = import_typebox.Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern !== void 0 ? new RegExp(config.pattern).source : void 0, default: config.default });
|
|
56
56
|
schema2 = base(schema2, key, config);
|
|
57
57
|
return schema2;
|
|
58
58
|
} else if (config.type === "number") {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let exclusive_minimum = void 0;
|
|
60
|
+
let exclusive_maximum = void 0;
|
|
61
|
+
if (config.positive === true && config.min === void 0) exclusive_minimum = 0;
|
|
62
|
+
if (config.negative === true && config.max === void 0) exclusive_maximum = 0;
|
|
63
|
+
schema2 = config.integer === true ? import_typebox.Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, exclusiveMinimum: exclusive_minimum, exclusiveMaximum: exclusive_maximum, positive: config.positive, negative: config.negative, default: config.default }) : import_typebox.Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, exclusiveMinimum: exclusive_minimum, exclusiveMaximum: exclusive_maximum, positive: config.positive, negative: config.negative, default: config.default });
|
|
62
64
|
schema2 = base(schema2, key, config);
|
|
63
65
|
return schema2;
|
|
64
66
|
} else if (config.type === "boolean") {
|
|
@@ -66,7 +68,7 @@ var convertToJSONSchema = (schema) => {
|
|
|
66
68
|
schema2 = base(schema2, key, config);
|
|
67
69
|
return schema2;
|
|
68
70
|
} else if (config.type === "date") {
|
|
69
|
-
schema2 = import_typebox.Type.String({ format: "date-time",
|
|
71
|
+
schema2 = import_typebox.Type.String({ format: "date-time", formatMinimum: config.min !== void 0 ? new Date(config.min).toISOString() : void 0, formatMaximum: config.max !== void 0 ? new Date(config.max).toISOString() : void 0, default: config.default });
|
|
70
72
|
schema2 = base(schema2, key, config);
|
|
71
73
|
return schema2;
|
|
72
74
|
} else if (config.type === "object") {
|
|
@@ -92,7 +94,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
92
94
|
const base = (schema2, key, config) => {
|
|
93
95
|
schema2 = schema2.nullable();
|
|
94
96
|
schema2 = schema2.optional();
|
|
95
|
-
if (config.default) schema2 = schema2.default(config.default);
|
|
97
|
+
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
96
98
|
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
97
99
|
if (config.required)
|
|
98
100
|
schema2 = schema2.test(
|
|
@@ -116,29 +118,29 @@ var convertToYup = (schema, error_messages) => {
|
|
|
116
118
|
config.enum.map((item) => item.trim()),
|
|
117
119
|
({ path: path2 }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
118
120
|
);
|
|
119
|
-
if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern ? new RegExp(config.pattern).source : ""));
|
|
120
|
-
if (config.min)
|
|
121
|
+
if (config.pattern !== void 0) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern !== void 0 ? new RegExp(config.pattern).source : ""));
|
|
122
|
+
if (config.min !== void 0)
|
|
121
123
|
schema2 = schema2.min(
|
|
122
124
|
config.min,
|
|
123
125
|
({ path: path2, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
124
126
|
);
|
|
125
|
-
if (config.max)
|
|
127
|
+
if (config.max !== void 0)
|
|
126
128
|
schema2 = schema2.max(
|
|
127
129
|
config.max,
|
|
128
130
|
({ path: path2, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
129
131
|
);
|
|
130
|
-
if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
131
|
-
if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
132
|
+
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
133
|
+
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
132
134
|
schema2 = base(schema2, key, config);
|
|
133
135
|
return schema2;
|
|
134
136
|
} else if (config.type === "number") {
|
|
135
137
|
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
136
138
|
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
|
|
137
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
|
|
138
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
|
|
139
|
-
if (config.integer) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
140
|
-
if (config.positive) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
141
|
-
if (config.negative) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
139
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
|
|
140
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
|
|
141
|
+
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
142
|
+
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
143
|
+
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
142
144
|
schema2 = base(schema2, key, config);
|
|
143
145
|
return schema2;
|
|
144
146
|
} else if (config.type === "boolean") {
|
|
@@ -147,8 +149,8 @@ var convertToYup = (schema, error_messages) => {
|
|
|
147
149
|
return schema2;
|
|
148
150
|
} else if (config.type === "date") {
|
|
149
151
|
schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
150
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
|
|
151
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
152
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
|
|
153
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
152
154
|
schema2 = base(schema2, key, config);
|
|
153
155
|
return schema2;
|
|
154
156
|
} else if (config.type === "object") {
|
|
@@ -160,12 +162,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
160
162
|
return schema2;
|
|
161
163
|
} else if (config.type === "array") {
|
|
162
164
|
schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
163
|
-
if (config.min)
|
|
165
|
+
if (config.min !== void 0)
|
|
164
166
|
schema2 = schema2.min(
|
|
165
167
|
config.min,
|
|
166
168
|
({ path: path2, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
167
169
|
);
|
|
168
|
-
if (config.max)
|
|
170
|
+
if (config.max !== void 0)
|
|
169
171
|
schema2 = schema2.max(
|
|
170
172
|
config.max,
|
|
171
173
|
({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
package/dist/main.mjs
CHANGED
|
@@ -21,13 +21,15 @@ var convertToJSONSchema = (schema) => {
|
|
|
21
21
|
const build = (key, config) => {
|
|
22
22
|
let schema2;
|
|
23
23
|
if (config.type === "string") {
|
|
24
|
-
schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern ? new RegExp(config.pattern).source : void 0, default: config.default });
|
|
24
|
+
schema2 = Type.String({ enum: config.enum, minLength: config.min, maxLength: config.max, pattern: config.pattern !== void 0 ? new RegExp(config.pattern).source : void 0, default: config.default });
|
|
25
25
|
schema2 = base(schema2, key, config);
|
|
26
26
|
return schema2;
|
|
27
27
|
} else if (config.type === "number") {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
let exclusive_minimum = void 0;
|
|
29
|
+
let exclusive_maximum = void 0;
|
|
30
|
+
if (config.positive === true && config.min === void 0) exclusive_minimum = 0;
|
|
31
|
+
if (config.negative === true && config.max === void 0) exclusive_maximum = 0;
|
|
32
|
+
schema2 = config.integer === true ? Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, exclusiveMinimum: exclusive_minimum, exclusiveMaximum: exclusive_maximum, positive: config.positive, negative: config.negative, default: config.default }) : Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, exclusiveMinimum: exclusive_minimum, exclusiveMaximum: exclusive_maximum, positive: config.positive, negative: config.negative, default: config.default });
|
|
31
33
|
schema2 = base(schema2, key, config);
|
|
32
34
|
return schema2;
|
|
33
35
|
} else if (config.type === "boolean") {
|
|
@@ -35,7 +37,7 @@ var convertToJSONSchema = (schema) => {
|
|
|
35
37
|
schema2 = base(schema2, key, config);
|
|
36
38
|
return schema2;
|
|
37
39
|
} else if (config.type === "date") {
|
|
38
|
-
schema2 = Type.String({ format: "date-time",
|
|
40
|
+
schema2 = Type.String({ format: "date-time", formatMinimum: config.min !== void 0 ? new Date(config.min).toISOString() : void 0, formatMaximum: config.max !== void 0 ? new Date(config.max).toISOString() : void 0, default: config.default });
|
|
39
41
|
schema2 = base(schema2, key, config);
|
|
40
42
|
return schema2;
|
|
41
43
|
} else if (config.type === "object") {
|
|
@@ -61,7 +63,7 @@ var convertToYup = (schema, error_messages) => {
|
|
|
61
63
|
const base = (schema2, key, config) => {
|
|
62
64
|
schema2 = schema2.nullable();
|
|
63
65
|
schema2 = schema2.optional();
|
|
64
|
-
if (config.default) schema2 = schema2.default(config.default);
|
|
66
|
+
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
65
67
|
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
66
68
|
if (config.required)
|
|
67
69
|
schema2 = schema2.test(
|
|
@@ -85,29 +87,29 @@ var convertToYup = (schema, error_messages) => {
|
|
|
85
87
|
config.enum.map((item) => item.trim()),
|
|
86
88
|
({ path: path2 }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
87
89
|
);
|
|
88
|
-
if (config.pattern) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern ? new RegExp(config.pattern).source : ""));
|
|
89
|
-
if (config.min)
|
|
90
|
+
if (config.pattern !== void 0) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern !== void 0 ? new RegExp(config.pattern).source : ""));
|
|
91
|
+
if (config.min !== void 0)
|
|
90
92
|
schema2 = schema2.min(
|
|
91
93
|
config.min,
|
|
92
94
|
({ path: path2, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
93
95
|
);
|
|
94
|
-
if (config.max)
|
|
96
|
+
if (config.max !== void 0)
|
|
95
97
|
schema2 = schema2.max(
|
|
96
98
|
config.max,
|
|
97
99
|
({ path: path2, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
98
100
|
);
|
|
99
|
-
if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
100
|
-
if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
101
|
+
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
102
|
+
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
101
103
|
schema2 = base(schema2, key, config);
|
|
102
104
|
return schema2;
|
|
103
105
|
} else if (config.type === "number") {
|
|
104
106
|
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
105
107
|
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
|
|
106
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
|
|
107
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
|
|
108
|
-
if (config.integer) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
109
|
-
if (config.positive) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
110
|
-
if (config.negative) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
108
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
|
|
109
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
|
|
110
|
+
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
111
|
+
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
112
|
+
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
111
113
|
schema2 = base(schema2, key, config);
|
|
112
114
|
return schema2;
|
|
113
115
|
} else if (config.type === "boolean") {
|
|
@@ -116,8 +118,8 @@ var convertToYup = (schema, error_messages) => {
|
|
|
116
118
|
return schema2;
|
|
117
119
|
} else if (config.type === "date") {
|
|
118
120
|
schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
119
|
-
if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
|
|
120
|
-
if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
121
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
|
|
122
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
121
123
|
schema2 = base(schema2, key, config);
|
|
122
124
|
return schema2;
|
|
123
125
|
} else if (config.type === "object") {
|
|
@@ -129,12 +131,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
129
131
|
return schema2;
|
|
130
132
|
} else if (config.type === "array") {
|
|
131
133
|
schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
132
|
-
if (config.min)
|
|
134
|
+
if (config.min !== void 0)
|
|
133
135
|
schema2 = schema2.min(
|
|
134
136
|
config.min,
|
|
135
137
|
({ path: path2, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
136
138
|
);
|
|
137
|
-
if (config.max)
|
|
139
|
+
if (config.max !== void 0)
|
|
138
140
|
schema2 = schema2.max(
|
|
139
141
|
config.max,
|
|
140
142
|
({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuppi",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@sinclair/typebox": "^0.34.41",
|
|
19
19
|
"@types/lodash.merge": "^4.6.9",
|
|
20
|
-
"@types/node": "^24.
|
|
20
|
+
"@types/node": "^24.8.1",
|
|
21
21
|
"json-schema-to-typescript": "^15.0.4",
|
|
22
22
|
"lodash.merge": "^4.6.2",
|
|
23
23
|
"yup": "^1.7.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"neatlint": "^1.1.
|
|
26
|
+
"neatlint": "^1.1.20",
|
|
27
27
|
"prettier": "^3.6.2",
|
|
28
28
|
"tsup": "^8.5.0"
|
|
29
29
|
},
|