yuppi 1.3.20 → 1.3.22
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 +0 -3
- package/dist/main.d.mts +3 -5
- package/dist/main.d.ts +3 -5
- package/dist/main.js +30 -30
- package/dist/main.mjs +30 -30
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
[AnyObject]: ./src/types/AnyObject.type.ts
|
|
22
22
|
[JSONSchema]: ./src/types/JSONSchema.type.ts
|
|
23
23
|
[Schema]: ./src/types/Schema.type.ts
|
|
24
|
-
[ValidateOptions]: ./src/types/ValidateOptions.type.ts
|
|
25
24
|
[ValidationError]: ./src/types/ValidationError.type.ts
|
|
26
25
|
[YuppiOptions]: ./src/types/YuppiOptions.type.ts
|
|
27
26
|
|
|
@@ -119,7 +118,6 @@ yuppi
|
|
|
119
118
|
├── type AnyObject
|
|
120
119
|
├── type JSONSchema
|
|
121
120
|
├── type Schema
|
|
122
|
-
├── type ValidateOptions
|
|
123
121
|
├── type ValidationError
|
|
124
122
|
└── type YuppiOptions
|
|
125
123
|
```
|
|
@@ -319,7 +317,6 @@ Convert your Yuppi schema into [JSON Schema](https://json-schema.org).
|
|
|
319
317
|
| [AnyObject] |
|
|
320
318
|
| [JSONSchema] |
|
|
321
319
|
| [Schema] |
|
|
322
|
-
| [ValidateOptions] |
|
|
323
320
|
| [ValidationError] |
|
|
324
321
|
| [YuppiOptions] |
|
|
325
322
|
|
package/dist/main.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
import { AnyObject as AnyObject$1, ValidateOptions
|
|
2
|
+
import { AnyObject as AnyObject$1, ValidateOptions, ValidationError as ValidationError$1 } from 'yup';
|
|
3
3
|
import { TObject, TAnySchema } from '@sinclair/typebox';
|
|
4
4
|
|
|
5
5
|
type AnyObject = AnyObject$1;
|
|
@@ -63,10 +63,8 @@ type Array = {
|
|
|
63
63
|
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
64
64
|
type Schema = Record<string, Types>;
|
|
65
65
|
|
|
66
|
-
type ValidateOptions = ValidateOptions$1;
|
|
67
|
-
|
|
68
66
|
type YuppiOptions = {
|
|
69
|
-
|
|
67
|
+
output_dir?: string;
|
|
70
68
|
error_messages?: {
|
|
71
69
|
base?: {
|
|
72
70
|
nullable?: string;
|
|
@@ -148,4 +146,4 @@ declare namespace Patterns_export {
|
|
|
148
146
|
|
|
149
147
|
type ValidationError = ValidationError$1;
|
|
150
148
|
|
|
151
|
-
export { type AnyObject, type JSONSchema, Patterns_export as Patterns, type Schema, type
|
|
149
|
+
export { type AnyObject, type JSONSchema, Patterns_export as Patterns, type Schema, type ValidationError, Yuppi, type YuppiOptions };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
import { AnyObject as AnyObject$1, ValidateOptions
|
|
2
|
+
import { AnyObject as AnyObject$1, ValidateOptions, ValidationError as ValidationError$1 } from 'yup';
|
|
3
3
|
import { TObject, TAnySchema } from '@sinclair/typebox';
|
|
4
4
|
|
|
5
5
|
type AnyObject = AnyObject$1;
|
|
@@ -63,10 +63,8 @@ type Array = {
|
|
|
63
63
|
type Types = String | Number | Boolean | Date | Object$1 | Array;
|
|
64
64
|
type Schema = Record<string, Types>;
|
|
65
65
|
|
|
66
|
-
type ValidateOptions = ValidateOptions$1;
|
|
67
|
-
|
|
68
66
|
type YuppiOptions = {
|
|
69
|
-
|
|
67
|
+
output_dir?: string;
|
|
70
68
|
error_messages?: {
|
|
71
69
|
base?: {
|
|
72
70
|
nullable?: string;
|
|
@@ -148,4 +146,4 @@ declare namespace Patterns_export {
|
|
|
148
146
|
|
|
149
147
|
type ValidationError = ValidationError$1;
|
|
150
148
|
|
|
151
|
-
export { type AnyObject, type JSONSchema, Patterns_export as Patterns, type Schema, type
|
|
149
|
+
export { type AnyObject, type JSONSchema, Patterns_export as Patterns, type Schema, type ValidationError, Yuppi, type YuppiOptions };
|
package/dist/main.js
CHANGED
|
@@ -43,7 +43,7 @@ var import_path = __toESM(require("path"));
|
|
|
43
43
|
|
|
44
44
|
// src/utils/ConvertToJSONSchema.util.ts
|
|
45
45
|
var import_typebox = require("@sinclair/typebox");
|
|
46
|
-
var convertToJSONSchema = (schema) => {
|
|
46
|
+
var convertToJSONSchema = (schema, options) => {
|
|
47
47
|
const base = (schema2, key, config) => {
|
|
48
48
|
if (config.nullable || config.default === null) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
|
|
49
49
|
if (!config.required) schema2 = import_typebox.Type.Optional(schema2);
|
|
@@ -74,7 +74,7 @@ var convertToJSONSchema = (schema) => {
|
|
|
74
74
|
} else if (config.type === "object") {
|
|
75
75
|
const nested_properties = {};
|
|
76
76
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
77
|
-
schema2 = import_typebox.Type.Object(nested_properties, { default: config.default, additionalProperties: false });
|
|
77
|
+
schema2 = import_typebox.Type.Object(nested_properties, { default: config.default, additionalProperties: !(options.validate_options?.stripUnknown ?? false) });
|
|
78
78
|
schema2 = base(schema2, key, config);
|
|
79
79
|
return schema2;
|
|
80
80
|
} else if (config.type === "array") {
|
|
@@ -85,21 +85,21 @@ var convertToJSONSchema = (schema) => {
|
|
|
85
85
|
};
|
|
86
86
|
const properties = {};
|
|
87
87
|
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
88
|
-
return import_typebox.Type.Object(properties, { additionalProperties: false });
|
|
88
|
+
return import_typebox.Type.Object(properties, { additionalProperties: !(options.validate_options?.stripUnknown ?? false) });
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
// src/utils/ConvertToYup.util.ts
|
|
92
92
|
var Yup = __toESM(require("yup"));
|
|
93
|
-
var convertToYup = (schema,
|
|
93
|
+
var convertToYup = (schema, options) => {
|
|
94
94
|
const base = (schema2, key, config) => {
|
|
95
95
|
schema2 = schema2.nullable();
|
|
96
96
|
schema2 = schema2.optional();
|
|
97
97
|
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
98
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
98
|
+
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (options.error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
99
99
|
if (config.required)
|
|
100
100
|
schema2 = schema2.test(
|
|
101
101
|
"required",
|
|
102
|
-
({ path: path2 }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path2),
|
|
102
|
+
({ path: path2 }) => (options.error_messages?.base?.required ?? "").replaceAll("{path}", path2),
|
|
103
103
|
(property) => {
|
|
104
104
|
if (property === void 0) return false;
|
|
105
105
|
if (typeof property === "string" && property.trim() === "") return false;
|
|
@@ -111,66 +111,66 @@ var convertToYup = (schema, error_messages) => {
|
|
|
111
111
|
const build = (key, config) => {
|
|
112
112
|
let schema2;
|
|
113
113
|
if (config.type === "string") {
|
|
114
|
-
schema2 = Yup.string().typeError(({ path: path2 }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path2));
|
|
114
|
+
schema2 = Yup.string().typeError(({ path: path2 }) => (options.error_messages?.string?.type ?? "").replaceAll("{path}", path2));
|
|
115
115
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
116
116
|
if (config.enum)
|
|
117
117
|
schema2 = schema2.oneOf(
|
|
118
118
|
config.enum.map((item) => item.trim()),
|
|
119
|
-
({ path: path2 }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
119
|
+
({ path: path2 }) => (options.error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
120
120
|
);
|
|
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 : ""));
|
|
121
|
+
if (config.pattern !== void 0) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (options.error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern !== void 0 ? new RegExp(config.pattern).source : ""));
|
|
122
122
|
if (config.min !== void 0)
|
|
123
123
|
schema2 = schema2.min(
|
|
124
124
|
config.min,
|
|
125
|
-
({ path: path2, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
125
|
+
({ path: path2, min }) => (options.error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
126
126
|
);
|
|
127
127
|
if (config.max !== void 0)
|
|
128
128
|
schema2 = schema2.max(
|
|
129
129
|
config.max,
|
|
130
|
-
({ path: path2, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
130
|
+
({ path: path2, max }) => (options.error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
131
131
|
);
|
|
132
132
|
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
133
133
|
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
134
134
|
schema2 = base(schema2, key, config);
|
|
135
135
|
return schema2;
|
|
136
136
|
} else if (config.type === "number") {
|
|
137
|
-
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
138
|
-
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").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}", String(min)));
|
|
140
|
-
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)));
|
|
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));
|
|
137
|
+
schema2 = Yup.number().typeError(({ path: path2 }) => (options.error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
138
|
+
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (options.error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
|
|
139
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (options.error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)));
|
|
140
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (options.error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)));
|
|
141
|
+
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (options.error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
142
|
+
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (options.error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
143
|
+
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (options.error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
144
144
|
schema2 = base(schema2, key, config);
|
|
145
145
|
return schema2;
|
|
146
146
|
} else if (config.type === "boolean") {
|
|
147
|
-
schema2 = Yup.boolean().typeError(({ path: path2 }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
|
|
147
|
+
schema2 = Yup.boolean().typeError(({ path: path2 }) => (options.error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
|
|
148
148
|
schema2 = base(schema2, key, config);
|
|
149
149
|
return schema2;
|
|
150
150
|
} else if (config.type === "date") {
|
|
151
|
-
schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
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()));
|
|
151
|
+
schema2 = Yup.date().typeError(({ path: path2 }) => (options.error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
152
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (options.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 }) => (options.error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
154
154
|
schema2 = base(schema2, key, config);
|
|
155
155
|
return schema2;
|
|
156
156
|
} else if (config.type === "object") {
|
|
157
|
-
schema2 = Yup.object().typeError(({ path: path2 }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path2));
|
|
157
|
+
schema2 = Yup.object().typeError(({ path: path2 }) => (options.error_messages?.object?.type ?? "").replaceAll("{path}", path2));
|
|
158
158
|
const nested_properties = {};
|
|
159
159
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
160
160
|
schema2 = schema2.shape(nested_properties);
|
|
161
161
|
schema2 = base(schema2, key, config);
|
|
162
162
|
return schema2;
|
|
163
163
|
} else if (config.type === "array") {
|
|
164
|
-
schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
164
|
+
schema2 = Yup.array().typeError(({ path: path2 }) => (options.error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
165
165
|
if (config.min !== void 0)
|
|
166
166
|
schema2 = schema2.min(
|
|
167
167
|
config.min,
|
|
168
|
-
({ path: path2, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
168
|
+
({ path: path2, min }) => (options.error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
169
169
|
);
|
|
170
170
|
if (config.max !== void 0)
|
|
171
171
|
schema2 = schema2.max(
|
|
172
172
|
config.max,
|
|
173
|
-
({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
173
|
+
({ path: path2, max }) => (options.error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
174
174
|
);
|
|
175
175
|
schema2 = schema2.of(build(key, config.items));
|
|
176
176
|
schema2 = base(schema2, key, config);
|
|
@@ -189,7 +189,7 @@ var pascalCase = (text) => {
|
|
|
189
189
|
|
|
190
190
|
// src/defaults/YuppiOptions.default.ts
|
|
191
191
|
var YuppiOptionsDefault = {
|
|
192
|
-
|
|
192
|
+
output_dir: "./generated/yuppi",
|
|
193
193
|
error_messages: {
|
|
194
194
|
base: {
|
|
195
195
|
nullable: "Field {path} cannot be null",
|
|
@@ -246,7 +246,7 @@ var Yuppi = class {
|
|
|
246
246
|
}
|
|
247
247
|
async declare(schema, name) {
|
|
248
248
|
name = pascalCase(name);
|
|
249
|
-
const types_dir = import_path.default.join(this.options.
|
|
249
|
+
const types_dir = import_path.default.join(this.options.output_dir ?? "./", "types");
|
|
250
250
|
const banner_comment = `/* eslint-disable */
|
|
251
251
|
|
|
252
252
|
/**
|
|
@@ -259,10 +259,10 @@ var Yuppi = class {
|
|
|
259
259
|
await import_promises.default.writeFile(import_path.default.join(types_dir, `${name}.d.ts`), type);
|
|
260
260
|
}
|
|
261
261
|
convertToYup(schema) {
|
|
262
|
-
return convertToYup(schema, this.options
|
|
262
|
+
return convertToYup(schema, this.options);
|
|
263
263
|
}
|
|
264
264
|
convertToJSONSchema(schema) {
|
|
265
|
-
return JSON.parse(JSON.stringify(convertToJSONSchema(schema)));
|
|
265
|
+
return JSON.parse(JSON.stringify(convertToJSONSchema(schema, this.options)));
|
|
266
266
|
}
|
|
267
267
|
};
|
|
268
268
|
|
package/dist/main.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import path from "path";
|
|
|
12
12
|
|
|
13
13
|
// src/utils/ConvertToJSONSchema.util.ts
|
|
14
14
|
import { Type } from "@sinclair/typebox";
|
|
15
|
-
var convertToJSONSchema = (schema) => {
|
|
15
|
+
var convertToJSONSchema = (schema, options) => {
|
|
16
16
|
const base = (schema2, key, config) => {
|
|
17
17
|
if (config.nullable || config.default === null) schema2 = Type.Union([schema2, Type.Null()]);
|
|
18
18
|
if (!config.required) schema2 = Type.Optional(schema2);
|
|
@@ -43,7 +43,7 @@ var convertToJSONSchema = (schema) => {
|
|
|
43
43
|
} else if (config.type === "object") {
|
|
44
44
|
const nested_properties = {};
|
|
45
45
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
46
|
-
schema2 = Type.Object(nested_properties, { default: config.default, additionalProperties: false });
|
|
46
|
+
schema2 = Type.Object(nested_properties, { default: config.default, additionalProperties: !(options.validate_options?.stripUnknown ?? false) });
|
|
47
47
|
schema2 = base(schema2, key, config);
|
|
48
48
|
return schema2;
|
|
49
49
|
} else if (config.type === "array") {
|
|
@@ -54,21 +54,21 @@ var convertToJSONSchema = (schema) => {
|
|
|
54
54
|
};
|
|
55
55
|
const properties = {};
|
|
56
56
|
for (const [key, config] of Object.entries(schema)) properties[key] = build(key, config);
|
|
57
|
-
return Type.Object(properties, { additionalProperties: false });
|
|
57
|
+
return Type.Object(properties, { additionalProperties: !(options.validate_options?.stripUnknown ?? false) });
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
// src/utils/ConvertToYup.util.ts
|
|
61
61
|
import * as Yup from "yup";
|
|
62
|
-
var convertToYup = (schema,
|
|
62
|
+
var convertToYup = (schema, options) => {
|
|
63
63
|
const base = (schema2, key, config) => {
|
|
64
64
|
schema2 = schema2.nullable();
|
|
65
65
|
schema2 = schema2.optional();
|
|
66
66
|
if (config.default !== void 0) schema2 = schema2.default(config.default);
|
|
67
|
-
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
67
|
+
if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (options.error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
|
|
68
68
|
if (config.required)
|
|
69
69
|
schema2 = schema2.test(
|
|
70
70
|
"required",
|
|
71
|
-
({ path: path2 }) => (error_messages?.base?.required ?? "").replaceAll("{path}", path2),
|
|
71
|
+
({ path: path2 }) => (options.error_messages?.base?.required ?? "").replaceAll("{path}", path2),
|
|
72
72
|
(property) => {
|
|
73
73
|
if (property === void 0) return false;
|
|
74
74
|
if (typeof property === "string" && property.trim() === "") return false;
|
|
@@ -80,66 +80,66 @@ var convertToYup = (schema, error_messages) => {
|
|
|
80
80
|
const build = (key, config) => {
|
|
81
81
|
let schema2;
|
|
82
82
|
if (config.type === "string") {
|
|
83
|
-
schema2 = Yup.string().typeError(({ path: path2 }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path2));
|
|
83
|
+
schema2 = Yup.string().typeError(({ path: path2 }) => (options.error_messages?.string?.type ?? "").replaceAll("{path}", path2));
|
|
84
84
|
schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
|
|
85
85
|
if (config.enum)
|
|
86
86
|
schema2 = schema2.oneOf(
|
|
87
87
|
config.enum.map((item) => item.trim()),
|
|
88
|
-
({ path: path2 }) => (error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
88
|
+
({ path: path2 }) => (options.error_messages?.string?.enum ?? "").replaceAll("{path}", path2)
|
|
89
89
|
);
|
|
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 : ""));
|
|
90
|
+
if (config.pattern !== void 0) schema2 = schema2.matches(new RegExp(config.pattern), ({ path: path2 }) => (options.error_messages?.string?.pattern ?? "").replaceAll("{path}", path2).replaceAll("{pattern}", config.pattern !== void 0 ? new RegExp(config.pattern).source : ""));
|
|
91
91
|
if (config.min !== void 0)
|
|
92
92
|
schema2 = schema2.min(
|
|
93
93
|
config.min,
|
|
94
|
-
({ path: path2, min }) => (error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
94
|
+
({ path: path2, min }) => (options.error_messages?.string?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
95
95
|
);
|
|
96
96
|
if (config.max !== void 0)
|
|
97
97
|
schema2 = schema2.max(
|
|
98
98
|
config.max,
|
|
99
|
-
({ path: path2, max }) => (error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
99
|
+
({ path: path2, max }) => (options.error_messages?.string?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
100
100
|
);
|
|
101
101
|
if (config.lowercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
|
|
102
102
|
if (config.uppercase === true) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
|
|
103
103
|
schema2 = base(schema2, key, config);
|
|
104
104
|
return schema2;
|
|
105
105
|
} else if (config.type === "number") {
|
|
106
|
-
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
107
|
-
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").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}", String(min)));
|
|
109
|
-
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)));
|
|
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));
|
|
106
|
+
schema2 = Yup.number().typeError(({ path: path2 }) => (options.error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
107
|
+
if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (options.error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
|
|
108
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (options.error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)));
|
|
109
|
+
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (options.error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)));
|
|
110
|
+
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (options.error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
111
|
+
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (options.error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
112
|
+
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (options.error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
113
113
|
schema2 = base(schema2, key, config);
|
|
114
114
|
return schema2;
|
|
115
115
|
} else if (config.type === "boolean") {
|
|
116
|
-
schema2 = Yup.boolean().typeError(({ path: path2 }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
|
|
116
|
+
schema2 = Yup.boolean().typeError(({ path: path2 }) => (options.error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
|
|
117
117
|
schema2 = base(schema2, key, config);
|
|
118
118
|
return schema2;
|
|
119
119
|
} else if (config.type === "date") {
|
|
120
|
-
schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
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()));
|
|
120
|
+
schema2 = Yup.date().typeError(({ path: path2 }) => (options.error_messages?.date?.type ?? "").replaceAll("{path}", path2));
|
|
121
|
+
if (config.min !== void 0) schema2 = schema2.min(config.min, ({ path: path2, min }) => (options.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 }) => (options.error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
|
|
123
123
|
schema2 = base(schema2, key, config);
|
|
124
124
|
return schema2;
|
|
125
125
|
} else if (config.type === "object") {
|
|
126
|
-
schema2 = Yup.object().typeError(({ path: path2 }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path2));
|
|
126
|
+
schema2 = Yup.object().typeError(({ path: path2 }) => (options.error_messages?.object?.type ?? "").replaceAll("{path}", path2));
|
|
127
127
|
const nested_properties = {};
|
|
128
128
|
for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
|
|
129
129
|
schema2 = schema2.shape(nested_properties);
|
|
130
130
|
schema2 = base(schema2, key, config);
|
|
131
131
|
return schema2;
|
|
132
132
|
} else if (config.type === "array") {
|
|
133
|
-
schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
133
|
+
schema2 = Yup.array().typeError(({ path: path2 }) => (options.error_messages?.array?.type ?? "").replaceAll("{path}", path2));
|
|
134
134
|
if (config.min !== void 0)
|
|
135
135
|
schema2 = schema2.min(
|
|
136
136
|
config.min,
|
|
137
|
-
({ path: path2, min }) => (error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
137
|
+
({ path: path2, min }) => (options.error_messages?.array?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", String(min)).replaceAll("{plural_suffix}", min > 1 ? "s" : "")
|
|
138
138
|
);
|
|
139
139
|
if (config.max !== void 0)
|
|
140
140
|
schema2 = schema2.max(
|
|
141
141
|
config.max,
|
|
142
|
-
({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
142
|
+
({ path: path2, max }) => (options.error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", String(max)).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
|
|
143
143
|
);
|
|
144
144
|
schema2 = schema2.of(build(key, config.items));
|
|
145
145
|
schema2 = base(schema2, key, config);
|
|
@@ -158,7 +158,7 @@ var pascalCase = (text) => {
|
|
|
158
158
|
|
|
159
159
|
// src/defaults/YuppiOptions.default.ts
|
|
160
160
|
var YuppiOptionsDefault = {
|
|
161
|
-
|
|
161
|
+
output_dir: "./generated/yuppi",
|
|
162
162
|
error_messages: {
|
|
163
163
|
base: {
|
|
164
164
|
nullable: "Field {path} cannot be null",
|
|
@@ -215,7 +215,7 @@ var Yuppi = class {
|
|
|
215
215
|
}
|
|
216
216
|
async declare(schema, name) {
|
|
217
217
|
name = pascalCase(name);
|
|
218
|
-
const types_dir = path.join(this.options.
|
|
218
|
+
const types_dir = path.join(this.options.output_dir ?? "./", "types");
|
|
219
219
|
const banner_comment = `/* eslint-disable */
|
|
220
220
|
|
|
221
221
|
/**
|
|
@@ -228,10 +228,10 @@ var Yuppi = class {
|
|
|
228
228
|
await fs.writeFile(path.join(types_dir, `${name}.d.ts`), type);
|
|
229
229
|
}
|
|
230
230
|
convertToYup(schema) {
|
|
231
|
-
return convertToYup(schema, this.options
|
|
231
|
+
return convertToYup(schema, this.options);
|
|
232
232
|
}
|
|
233
233
|
convertToJSONSchema(schema) {
|
|
234
|
-
return JSON.parse(JSON.stringify(convertToJSONSchema(schema)));
|
|
234
|
+
return JSON.parse(JSON.stringify(convertToJSONSchema(schema, this.options)));
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuppi",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.22",
|
|
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,7 +15,7 @@
|
|
|
15
15
|
"lint": "eslint ./"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sinclair/typebox": "^0.34.
|
|
18
|
+
"@sinclair/typebox": "^0.34.48",
|
|
19
19
|
"@types/lodash.merge": "^4.6.9",
|
|
20
20
|
"json-schema-to-typescript": "^15.0.4",
|
|
21
21
|
"lodash.merge": "^4.6.2",
|