yuppi 1.3.18 → 1.3.20
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 +2 -2
- package/dist/main.d.mts +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +10 -12
- package/dist/main.mjs +10 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,14 +223,14 @@ Declare your Yuppi schema for TypeScript.
|
|
|
223
223
|
> | schema | [Schema] | | Yuppi schema. |
|
|
224
224
|
> | name | [String] | | Declaration name. |
|
|
225
225
|
>
|
|
226
|
-
> returns [Void]
|
|
226
|
+
> returns [Promise]<[Void]>
|
|
227
227
|
>
|
|
228
228
|
> Example:
|
|
229
229
|
>
|
|
230
230
|
> ```typescript
|
|
231
231
|
> import type { User } from './yuppi/types/User';
|
|
232
232
|
>
|
|
233
|
-
> Yupp.declare(schema, 'User');
|
|
233
|
+
> await Yupp.declare(schema, 'User');
|
|
234
234
|
>
|
|
235
235
|
> const user = (await Yupp.validate(schema, properties)) as User;
|
|
236
236
|
> /*
|
package/dist/main.d.mts
CHANGED
|
@@ -115,7 +115,7 @@ declare class Yuppi {
|
|
|
115
115
|
[x: string]: any;
|
|
116
116
|
[x: number]: any;
|
|
117
117
|
}>;
|
|
118
|
-
declare(schema: Schema, name: string): void
|
|
118
|
+
declare(schema: Schema, name: string): Promise<void>;
|
|
119
119
|
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
120
120
|
[x: string]: any;
|
|
121
121
|
}, yup.AnyObject, {
|
package/dist/main.d.ts
CHANGED
|
@@ -115,7 +115,7 @@ declare class Yuppi {
|
|
|
115
115
|
[x: string]: any;
|
|
116
116
|
[x: number]: any;
|
|
117
117
|
}>;
|
|
118
|
-
declare(schema: Schema, name: string): void
|
|
118
|
+
declare(schema: Schema, name: string): Promise<void>;
|
|
119
119
|
convertToYup(schema: Schema): yup.ObjectSchema<{
|
|
120
120
|
[x: string]: any;
|
|
121
121
|
}, yup.AnyObject, {
|
package/dist/main.js
CHANGED
|
@@ -122,12 +122,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
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}", min
|
|
125
|
+
({ path: path2, min }) => (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}", max
|
|
130
|
+
({ path: path2, max }) => (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);
|
|
@@ -136,8 +136,8 @@ var convertToYup = (schema, error_messages) => {
|
|
|
136
136
|
} else if (config.type === "number") {
|
|
137
137
|
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
138
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}", min
|
|
140
|
-
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max
|
|
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
141
|
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
142
142
|
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
143
143
|
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
@@ -165,12 +165,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
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}", min
|
|
168
|
+
({ path: path2, min }) => (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}", max
|
|
173
|
+
({ path: path2, max }) => (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);
|
|
@@ -244,7 +244,7 @@ var Yuppi = class {
|
|
|
244
244
|
const yup_schema = this.convertToYup(schema);
|
|
245
245
|
return yup_schema.validate(properties, this.options.validate_options);
|
|
246
246
|
}
|
|
247
|
-
declare(schema, name) {
|
|
247
|
+
async declare(schema, name) {
|
|
248
248
|
name = pascalCase(name);
|
|
249
249
|
const types_dir = import_path.default.join(this.options.folder_path ?? "./", "yuppi", "types");
|
|
250
250
|
const banner_comment = `/* eslint-disable */
|
|
@@ -254,11 +254,9 @@ var Yuppi = class {
|
|
|
254
254
|
* _DO NOT MODIFY IT BY HAND_. Instead, modify your Yuppi schema.
|
|
255
255
|
* Use \`Yuppi.declare()\` to regenerate this type.
|
|
256
256
|
*/`;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
await import_promises.default.writeFile(import_path.default.join(types_dir, `${name}.d.ts`), type);
|
|
261
|
-
})();
|
|
257
|
+
const type = await (0, import_json_schema_to_typescript.compile)(this.convertToJSONSchema(schema), name, { bannerComment: banner_comment });
|
|
258
|
+
await import_promises.default.mkdir(types_dir, { recursive: true });
|
|
259
|
+
await import_promises.default.writeFile(import_path.default.join(types_dir, `${name}.d.ts`), type);
|
|
262
260
|
}
|
|
263
261
|
convertToYup(schema) {
|
|
264
262
|
return convertToYup(schema, this.options.error_messages);
|
package/dist/main.mjs
CHANGED
|
@@ -91,12 +91,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
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}", min
|
|
94
|
+
({ path: path2, min }) => (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}", max
|
|
99
|
+
({ path: path2, max }) => (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);
|
|
@@ -105,8 +105,8 @@ var convertToYup = (schema, error_messages) => {
|
|
|
105
105
|
} else if (config.type === "number") {
|
|
106
106
|
schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
|
|
107
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}", min
|
|
109
|
-
if (config.max !== void 0) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max
|
|
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
110
|
if (config.integer === true) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
|
|
111
111
|
if (config.positive === true) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
|
|
112
112
|
if (config.negative === true) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
|
|
@@ -134,12 +134,12 @@ var convertToYup = (schema, error_messages) => {
|
|
|
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}", min
|
|
137
|
+
({ path: path2, min }) => (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}", max
|
|
142
|
+
({ path: path2, max }) => (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);
|
|
@@ -213,7 +213,7 @@ var Yuppi = class {
|
|
|
213
213
|
const yup_schema = this.convertToYup(schema);
|
|
214
214
|
return yup_schema.validate(properties, this.options.validate_options);
|
|
215
215
|
}
|
|
216
|
-
declare(schema, name) {
|
|
216
|
+
async declare(schema, name) {
|
|
217
217
|
name = pascalCase(name);
|
|
218
218
|
const types_dir = path.join(this.options.folder_path ?? "./", "yuppi", "types");
|
|
219
219
|
const banner_comment = `/* eslint-disable */
|
|
@@ -223,11 +223,9 @@ var Yuppi = class {
|
|
|
223
223
|
* _DO NOT MODIFY IT BY HAND_. Instead, modify your Yuppi schema.
|
|
224
224
|
* Use \`Yuppi.declare()\` to regenerate this type.
|
|
225
225
|
*/`;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
await fs.writeFile(path.join(types_dir, `${name}.d.ts`), type);
|
|
230
|
-
})();
|
|
226
|
+
const type = await compile(this.convertToJSONSchema(schema), name, { bannerComment: banner_comment });
|
|
227
|
+
await fs.mkdir(types_dir, { recursive: true });
|
|
228
|
+
await fs.writeFile(path.join(types_dir, `${name}.d.ts`), type);
|
|
231
229
|
}
|
|
232
230
|
convertToYup(schema) {
|
|
233
231
|
return convertToYup(schema, this.options.error_messages);
|