@forklaunch/validator 0.4.12 → 0.5.0
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/lib/__test__/utils/mockSchemaValidator.d.mts +111 -3
- package/lib/__test__/utils/mockSchemaValidator.d.ts +111 -3
- package/lib/__test__/utils/mockSchemaValidator.js +105 -0
- package/lib/__test__/utils/mockSchemaValidator.mjs +102 -0
- package/lib/index.d.mts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/{schema.types-LkSEBFTv.d.mts → schema.types-BL6n8u4w.d.mts} +113 -20
- package/lib/{schema.types-LkSEBFTv.d.ts → schema.types-BL6n8u4w.d.ts} +113 -20
- package/lib/src/typebox/index.d.mts +28 -4
- package/lib/src/typebox/index.d.ts +28 -4
- package/lib/src/typebox/index.js +68 -11
- package/lib/src/typebox/index.mjs +61 -10
- package/lib/src/zod/index.d.mts +28 -4
- package/lib/src/zod/index.d.ts +28 -4
- package/lib/src/zod/index.js +65 -23
- package/lib/src/zod/index.mjs +60 -24
- package/package.json +2 -2
package/lib/src/zod/index.js
CHANGED
|
@@ -28,22 +28,28 @@ __export(zod_exports, {
|
|
|
28
28
|
date: () => date,
|
|
29
29
|
email: () => email,
|
|
30
30
|
enum_: () => enum_,
|
|
31
|
+
function_: () => function_,
|
|
31
32
|
isSchema: () => isSchema,
|
|
32
33
|
literal: () => literal,
|
|
33
34
|
never: () => never,
|
|
35
|
+
null_: () => null_,
|
|
34
36
|
nullish: () => nullish,
|
|
35
37
|
number: () => number,
|
|
36
38
|
openapi: () => openapi,
|
|
37
39
|
optional: () => optional,
|
|
38
40
|
parse: () => parse,
|
|
41
|
+
promise: () => promise,
|
|
42
|
+
record: () => record,
|
|
39
43
|
schemify: () => schemify,
|
|
40
44
|
string: () => string,
|
|
41
45
|
symbol: () => symbol,
|
|
46
|
+
undefined_: () => undefined_,
|
|
42
47
|
union: () => union,
|
|
43
48
|
unknown: () => unknown,
|
|
44
49
|
uri: () => uri,
|
|
45
50
|
uuid: () => uuid,
|
|
46
|
-
validate: () => validate
|
|
51
|
+
validate: () => validate,
|
|
52
|
+
void_: () => void_
|
|
47
53
|
});
|
|
48
54
|
module.exports = __toCommonJS(zod_exports);
|
|
49
55
|
|
|
@@ -88,6 +94,9 @@ var ZodSchemaValidator = class {
|
|
|
88
94
|
}).pipe(import_zod.z.date());
|
|
89
95
|
symbol = import_zod.z.symbol();
|
|
90
96
|
nullish = import_zod.z.union([import_zod.z.void(), import_zod.z.null(), import_zod.z.undefined()]);
|
|
97
|
+
void = import_zod.z.void();
|
|
98
|
+
null = import_zod.z.null();
|
|
99
|
+
undefined = import_zod.z.undefined();
|
|
91
100
|
any = import_zod.z.any();
|
|
92
101
|
unknown = import_zod.z.unknown();
|
|
93
102
|
never = import_zod.z.never();
|
|
@@ -128,11 +137,8 @@ var ZodSchemaValidator = class {
|
|
|
128
137
|
* @returns {ZodOptional<ZodResolve<T>>} The optional schema.
|
|
129
138
|
*/
|
|
130
139
|
optional(schema) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
} else {
|
|
134
|
-
return this.schemify(schema).optional();
|
|
135
|
-
}
|
|
140
|
+
const resolvedSchema = this.schemify(schema);
|
|
141
|
+
return resolvedSchema.optional();
|
|
136
142
|
}
|
|
137
143
|
/**
|
|
138
144
|
* Create an array schema.
|
|
@@ -140,11 +146,8 @@ var ZodSchemaValidator = class {
|
|
|
140
146
|
* @returns {ZodArray<ZodResolve<T>>} The array schema.
|
|
141
147
|
*/
|
|
142
148
|
array(schema) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} else {
|
|
146
|
-
return this.schemify(schema).array();
|
|
147
|
-
}
|
|
149
|
+
const resolvedSchema = this.schemify(schema);
|
|
150
|
+
return resolvedSchema.array();
|
|
148
151
|
}
|
|
149
152
|
/**
|
|
150
153
|
* Create a union schema.
|
|
@@ -152,12 +155,7 @@ var ZodSchemaValidator = class {
|
|
|
152
155
|
* @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
|
|
153
156
|
*/
|
|
154
157
|
union(schemas) {
|
|
155
|
-
const resolvedSchemas = schemas.map((schema) =>
|
|
156
|
-
if (schema instanceof import_zod.ZodType) {
|
|
157
|
-
return schema;
|
|
158
|
-
}
|
|
159
|
-
return this.schemify(schema);
|
|
160
|
-
});
|
|
158
|
+
const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
|
|
161
159
|
return import_zod.z.union(
|
|
162
160
|
resolvedSchemas
|
|
163
161
|
);
|
|
@@ -180,6 +178,36 @@ var ZodSchemaValidator = class {
|
|
|
180
178
|
Object.values(schemaEnum)
|
|
181
179
|
);
|
|
182
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Create a function schema.
|
|
183
|
+
* @param {ZodTuple} args - The arguments of the function.
|
|
184
|
+
* @param {ZodAny} returnType - The return type of the function.
|
|
185
|
+
* @returns {ZodFunction<Args, ReturnType>} The function schema.
|
|
186
|
+
*/
|
|
187
|
+
function_(args, returnType) {
|
|
188
|
+
const schemaArgs = args.map((schema) => this.schemify(schema));
|
|
189
|
+
const schemaReturnType = this.schemify(returnType);
|
|
190
|
+
return import_zod.z.function(import_zod.z.tuple(schemaArgs), schemaReturnType);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create a record schema.
|
|
194
|
+
* @param {ZodIdiomaticSchema} key - The key schema.
|
|
195
|
+
* @param {ZodIdiomaticSchema} value - The value schema.
|
|
196
|
+
* @returns {ZodRecord<ZodResolve<Key>, ZodResolve<Value>>} The record schema.
|
|
197
|
+
*/
|
|
198
|
+
record(key, value) {
|
|
199
|
+
const keySchema = this.schemify(key);
|
|
200
|
+
const valueSchema = this.schemify(value);
|
|
201
|
+
return import_zod.z.record(keySchema, valueSchema);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create a promise schema.
|
|
205
|
+
* @param {ZodIdiomaticSchema} schema - The schema to use for the promise.
|
|
206
|
+
* @returns {ZodPromise<ZodResolve<T>>} The promise schema.
|
|
207
|
+
*/
|
|
208
|
+
promise(schema) {
|
|
209
|
+
return import_zod.z.promise(this.schemify(schema));
|
|
210
|
+
}
|
|
183
211
|
/**
|
|
184
212
|
* Checks if a value is a Zod schema.
|
|
185
213
|
* @param {unknown} value - The value to check.
|
|
@@ -195,7 +223,7 @@ var ZodSchemaValidator = class {
|
|
|
195
223
|
* @returns {boolean} True if valid, otherwise false.
|
|
196
224
|
*/
|
|
197
225
|
validate(schema, value) {
|
|
198
|
-
const resolvedSchema =
|
|
226
|
+
const resolvedSchema = this.schemify(schema);
|
|
199
227
|
return resolvedSchema.safeParse(value).success;
|
|
200
228
|
}
|
|
201
229
|
/**
|
|
@@ -206,7 +234,7 @@ var ZodSchemaValidator = class {
|
|
|
206
234
|
* @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
|
|
207
235
|
*/
|
|
208
236
|
parse(schema, value) {
|
|
209
|
-
const resolvedSchema =
|
|
237
|
+
const resolvedSchema = this.schemify(schema);
|
|
210
238
|
const result = resolvedSchema.safeParse(value);
|
|
211
239
|
return result.success ? { ok: true, value: result.data } : {
|
|
212
240
|
ok: false,
|
|
@@ -240,9 +268,7 @@ var ZodSchemaValidator = class {
|
|
|
240
268
|
* @returns {SchemaObject} The OpenAPI schema object.
|
|
241
269
|
*/
|
|
242
270
|
openapi(schema) {
|
|
243
|
-
return (0, import_zod_openapi.generateSchema)(
|
|
244
|
-
schema instanceof import_zod.ZodType ? schema : this.schemify(schema)
|
|
245
|
-
);
|
|
271
|
+
return (0, import_zod_openapi.generateSchema)(this.schemify(schema));
|
|
246
272
|
}
|
|
247
273
|
};
|
|
248
274
|
|
|
@@ -259,6 +285,9 @@ var boolean = StaticSchemaValidator.boolean;
|
|
|
259
285
|
var date = StaticSchemaValidator.date;
|
|
260
286
|
var symbol = StaticSchemaValidator.symbol;
|
|
261
287
|
var nullish = StaticSchemaValidator.nullish;
|
|
288
|
+
var void_ = StaticSchemaValidator.void;
|
|
289
|
+
var null_ = StaticSchemaValidator.null;
|
|
290
|
+
var undefined_ = StaticSchemaValidator.undefined;
|
|
262
291
|
var any = StaticSchemaValidator.any;
|
|
263
292
|
var unknown = StaticSchemaValidator.unknown;
|
|
264
293
|
var never = StaticSchemaValidator.never;
|
|
@@ -274,6 +303,13 @@ var literal = StaticSchemaValidator.literal.bind(
|
|
|
274
303
|
StaticSchemaValidator
|
|
275
304
|
);
|
|
276
305
|
var enum_ = StaticSchemaValidator.enum_.bind(StaticSchemaValidator);
|
|
306
|
+
var function_ = StaticSchemaValidator.function_.bind(
|
|
307
|
+
StaticSchemaValidator
|
|
308
|
+
);
|
|
309
|
+
var record = StaticSchemaValidator.record.bind(StaticSchemaValidator);
|
|
310
|
+
var promise = StaticSchemaValidator.promise.bind(
|
|
311
|
+
StaticSchemaValidator
|
|
312
|
+
);
|
|
277
313
|
var isSchema = StaticSchemaValidator.isSchema.bind(
|
|
278
314
|
StaticSchemaValidator
|
|
279
315
|
);
|
|
@@ -294,20 +330,26 @@ var openapi = StaticSchemaValidator.openapi.bind(
|
|
|
294
330
|
date,
|
|
295
331
|
email,
|
|
296
332
|
enum_,
|
|
333
|
+
function_,
|
|
297
334
|
isSchema,
|
|
298
335
|
literal,
|
|
299
336
|
never,
|
|
337
|
+
null_,
|
|
300
338
|
nullish,
|
|
301
339
|
number,
|
|
302
340
|
openapi,
|
|
303
341
|
optional,
|
|
304
342
|
parse,
|
|
343
|
+
promise,
|
|
344
|
+
record,
|
|
305
345
|
schemify,
|
|
306
346
|
string,
|
|
307
347
|
symbol,
|
|
348
|
+
undefined_,
|
|
308
349
|
union,
|
|
309
350
|
unknown,
|
|
310
351
|
uri,
|
|
311
352
|
uuid,
|
|
312
|
-
validate
|
|
353
|
+
validate,
|
|
354
|
+
void_
|
|
313
355
|
});
|
package/lib/src/zod/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/zod/zodSchemaValidator.ts
|
|
2
2
|
import { generateSchema } from "@anatine/zod-openapi";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
z,
|
|
5
|
+
ZodType
|
|
6
6
|
} from "zod";
|
|
7
7
|
var ZodSchemaValidator = class {
|
|
8
8
|
_Type = "Zod";
|
|
@@ -42,6 +42,9 @@ var ZodSchemaValidator = class {
|
|
|
42
42
|
}).pipe(z.date());
|
|
43
43
|
symbol = z.symbol();
|
|
44
44
|
nullish = z.union([z.void(), z.null(), z.undefined()]);
|
|
45
|
+
void = z.void();
|
|
46
|
+
null = z.null();
|
|
47
|
+
undefined = z.undefined();
|
|
45
48
|
any = z.any();
|
|
46
49
|
unknown = z.unknown();
|
|
47
50
|
never = z.never();
|
|
@@ -82,11 +85,8 @@ var ZodSchemaValidator = class {
|
|
|
82
85
|
* @returns {ZodOptional<ZodResolve<T>>} The optional schema.
|
|
83
86
|
*/
|
|
84
87
|
optional(schema) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
return this.schemify(schema).optional();
|
|
89
|
-
}
|
|
88
|
+
const resolvedSchema = this.schemify(schema);
|
|
89
|
+
return resolvedSchema.optional();
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Create an array schema.
|
|
@@ -94,11 +94,8 @@ var ZodSchemaValidator = class {
|
|
|
94
94
|
* @returns {ZodArray<ZodResolve<T>>} The array schema.
|
|
95
95
|
*/
|
|
96
96
|
array(schema) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
return this.schemify(schema).array();
|
|
101
|
-
}
|
|
97
|
+
const resolvedSchema = this.schemify(schema);
|
|
98
|
+
return resolvedSchema.array();
|
|
102
99
|
}
|
|
103
100
|
/**
|
|
104
101
|
* Create a union schema.
|
|
@@ -106,12 +103,7 @@ var ZodSchemaValidator = class {
|
|
|
106
103
|
* @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
|
|
107
104
|
*/
|
|
108
105
|
union(schemas) {
|
|
109
|
-
const resolvedSchemas = schemas.map((schema) =>
|
|
110
|
-
if (schema instanceof ZodType) {
|
|
111
|
-
return schema;
|
|
112
|
-
}
|
|
113
|
-
return this.schemify(schema);
|
|
114
|
-
});
|
|
106
|
+
const resolvedSchemas = schemas.map((schema) => this.schemify(schema));
|
|
115
107
|
return z.union(
|
|
116
108
|
resolvedSchemas
|
|
117
109
|
);
|
|
@@ -134,6 +126,36 @@ var ZodSchemaValidator = class {
|
|
|
134
126
|
Object.values(schemaEnum)
|
|
135
127
|
);
|
|
136
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a function schema.
|
|
131
|
+
* @param {ZodTuple} args - The arguments of the function.
|
|
132
|
+
* @param {ZodAny} returnType - The return type of the function.
|
|
133
|
+
* @returns {ZodFunction<Args, ReturnType>} The function schema.
|
|
134
|
+
*/
|
|
135
|
+
function_(args, returnType) {
|
|
136
|
+
const schemaArgs = args.map((schema) => this.schemify(schema));
|
|
137
|
+
const schemaReturnType = this.schemify(returnType);
|
|
138
|
+
return z.function(z.tuple(schemaArgs), schemaReturnType);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a record schema.
|
|
142
|
+
* @param {ZodIdiomaticSchema} key - The key schema.
|
|
143
|
+
* @param {ZodIdiomaticSchema} value - The value schema.
|
|
144
|
+
* @returns {ZodRecord<ZodResolve<Key>, ZodResolve<Value>>} The record schema.
|
|
145
|
+
*/
|
|
146
|
+
record(key, value) {
|
|
147
|
+
const keySchema = this.schemify(key);
|
|
148
|
+
const valueSchema = this.schemify(value);
|
|
149
|
+
return z.record(keySchema, valueSchema);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a promise schema.
|
|
153
|
+
* @param {ZodIdiomaticSchema} schema - The schema to use for the promise.
|
|
154
|
+
* @returns {ZodPromise<ZodResolve<T>>} The promise schema.
|
|
155
|
+
*/
|
|
156
|
+
promise(schema) {
|
|
157
|
+
return z.promise(this.schemify(schema));
|
|
158
|
+
}
|
|
137
159
|
/**
|
|
138
160
|
* Checks if a value is a Zod schema.
|
|
139
161
|
* @param {unknown} value - The value to check.
|
|
@@ -149,7 +171,7 @@ var ZodSchemaValidator = class {
|
|
|
149
171
|
* @returns {boolean} True if valid, otherwise false.
|
|
150
172
|
*/
|
|
151
173
|
validate(schema, value) {
|
|
152
|
-
const resolvedSchema =
|
|
174
|
+
const resolvedSchema = this.schemify(schema);
|
|
153
175
|
return resolvedSchema.safeParse(value).success;
|
|
154
176
|
}
|
|
155
177
|
/**
|
|
@@ -160,7 +182,7 @@ var ZodSchemaValidator = class {
|
|
|
160
182
|
* @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
|
|
161
183
|
*/
|
|
162
184
|
parse(schema, value) {
|
|
163
|
-
const resolvedSchema =
|
|
185
|
+
const resolvedSchema = this.schemify(schema);
|
|
164
186
|
const result = resolvedSchema.safeParse(value);
|
|
165
187
|
return result.success ? { ok: true, value: result.data } : {
|
|
166
188
|
ok: false,
|
|
@@ -194,9 +216,7 @@ var ZodSchemaValidator = class {
|
|
|
194
216
|
* @returns {SchemaObject} The OpenAPI schema object.
|
|
195
217
|
*/
|
|
196
218
|
openapi(schema) {
|
|
197
|
-
return generateSchema(
|
|
198
|
-
schema instanceof ZodType ? schema : this.schemify(schema)
|
|
199
|
-
);
|
|
219
|
+
return generateSchema(this.schemify(schema));
|
|
200
220
|
}
|
|
201
221
|
};
|
|
202
222
|
|
|
@@ -213,6 +233,9 @@ var boolean = StaticSchemaValidator.boolean;
|
|
|
213
233
|
var date = StaticSchemaValidator.date;
|
|
214
234
|
var symbol = StaticSchemaValidator.symbol;
|
|
215
235
|
var nullish = StaticSchemaValidator.nullish;
|
|
236
|
+
var void_ = StaticSchemaValidator.void;
|
|
237
|
+
var null_ = StaticSchemaValidator.null;
|
|
238
|
+
var undefined_ = StaticSchemaValidator.undefined;
|
|
216
239
|
var any = StaticSchemaValidator.any;
|
|
217
240
|
var unknown = StaticSchemaValidator.unknown;
|
|
218
241
|
var never = StaticSchemaValidator.never;
|
|
@@ -228,6 +251,13 @@ var literal = StaticSchemaValidator.literal.bind(
|
|
|
228
251
|
StaticSchemaValidator
|
|
229
252
|
);
|
|
230
253
|
var enum_ = StaticSchemaValidator.enum_.bind(StaticSchemaValidator);
|
|
254
|
+
var function_ = StaticSchemaValidator.function_.bind(
|
|
255
|
+
StaticSchemaValidator
|
|
256
|
+
);
|
|
257
|
+
var record = StaticSchemaValidator.record.bind(StaticSchemaValidator);
|
|
258
|
+
var promise = StaticSchemaValidator.promise.bind(
|
|
259
|
+
StaticSchemaValidator
|
|
260
|
+
);
|
|
231
261
|
var isSchema = StaticSchemaValidator.isSchema.bind(
|
|
232
262
|
StaticSchemaValidator
|
|
233
263
|
);
|
|
@@ -247,20 +277,26 @@ export {
|
|
|
247
277
|
date,
|
|
248
278
|
email,
|
|
249
279
|
enum_,
|
|
280
|
+
function_,
|
|
250
281
|
isSchema,
|
|
251
282
|
literal,
|
|
252
283
|
never,
|
|
284
|
+
null_,
|
|
253
285
|
nullish,
|
|
254
286
|
number,
|
|
255
287
|
openapi,
|
|
256
288
|
optional,
|
|
257
289
|
parse,
|
|
290
|
+
promise,
|
|
291
|
+
record,
|
|
258
292
|
schemify,
|
|
259
293
|
string,
|
|
260
294
|
symbol,
|
|
295
|
+
undefined_,
|
|
261
296
|
union,
|
|
262
297
|
unknown,
|
|
263
298
|
uri,
|
|
264
299
|
uuid,
|
|
265
|
-
validate
|
|
300
|
+
validate,
|
|
301
|
+
void_
|
|
266
302
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Schema validator for ForkLaunch components.",
|
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@anatine/zod-openapi": "^2.2.8",
|
|
62
62
|
"@sinclair/typebox": "^0.34.33",
|
|
63
63
|
"zod": "^3.24.2",
|
|
64
|
-
"@forklaunch/common": "0.2.
|
|
64
|
+
"@forklaunch/common": "0.2.7"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@eslint/js": "^9.24.0",
|