@forklaunch/validator 0.4.11 → 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.
@@ -1,6 +1,6 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { Z as ZodSchemaValidator, o as ZodIdiomaticSchema, p as ZodResolve, q as ZodUnionContainer, r as UnionZodResolve, L as LiteralSchema, s as ZodCatchall, a as ParseResult } from '../../schema.types-BA3PeCI5.js';
3
- export { x as UnboxedZodObjectSchema, v as ZodObject, u as ZodObjectShape, t as ZodOuterArray, w as ZodSchemaTranslate } from '../../schema.types-BA3PeCI5.js';
2
+ import { Z as ZodSchemaValidator, p as ZodIdiomaticSchema, q as ZodResolve, r as ZodUnionContainer, s as UnionZodResolve, L as LiteralSchema, t as ZodTupleContainer, u as TupleZodResolve, v as ZodRecordKey, w as ZodCatchall, a as ParseResult } from '../../schema.types-BL6n8u4w.js';
3
+ export { C as UnboxedZodObjectSchema, z as ZodObject, y as ZodObjectShape, x as ZodOuterArray, B as ZodSchemaTranslate } from '../../schema.types-BL6n8u4w.js';
4
4
  import * as zod from 'zod';
5
5
  import '@forklaunch/common';
6
6
  import '@sinclair/typebox';
@@ -51,6 +51,18 @@ declare const symbol: zod.ZodSymbol;
51
51
  * Zod schema definition for undefined, null, void types.
52
52
  */
53
53
  declare const nullish: zod.ZodUnion<[zod.ZodVoid, zod.ZodNull, zod.ZodUndefined]>;
54
+ /**
55
+ * Zod schema definition for void type.
56
+ */
57
+ declare const void_: zod.ZodVoid;
58
+ /**
59
+ * Zod schema definition for null type.
60
+ */
61
+ declare const null_: zod.ZodNull;
62
+ /**
63
+ * Zod schema definition for undefined type.
64
+ */
65
+ declare const undefined_: zod.ZodUndefined;
54
66
  /**
55
67
  * Zod schema definition for any type.
56
68
  */
@@ -82,11 +94,23 @@ declare const union: <T extends ZodUnionContainer>(schemas: T) => zod.ZodUnion<U
82
94
  /**
83
95
  * Defines a literal for a valid schema.
84
96
  */
85
- declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<ZodResolve<T>>;
97
+ declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<T>;
86
98
  /**
87
99
  * Defines an enum for a valid schema.
88
100
  */
89
101
  declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => zod.ZodUnion<[{ [K in keyof T]: zod.ZodLiteral<T[K]>; }[keyof T]]>;
102
+ /**
103
+ * Defines a function for a valid schema.
104
+ */
105
+ declare const function_: <Args extends ZodTupleContainer, ReturnType extends ZodIdiomaticSchema>(args: Args, returnType: ReturnType) => zod.ZodFunction<zod.ZodTuple<TupleZodResolve<Args>, null>, ZodResolve<ReturnType>>;
106
+ /**
107
+ * Defines a record for a valid schema.
108
+ */
109
+ declare const record: <Key extends ZodIdiomaticSchema, Value extends ZodIdiomaticSchema>(key: Key, value: Value) => zod.ZodRecord<ZodRecordKey<Key>, ZodResolve<Value>>;
110
+ /**
111
+ * Defines a promise for a valid schema.
112
+ */
113
+ declare const promise: <T extends ZodIdiomaticSchema>(schema: T) => zod.ZodPromise<ZodResolve<T>>;
90
114
  /**
91
115
  * Checks if a value is a Zod schema.
92
116
  */
@@ -104,4 +128,4 @@ declare const parse: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, val
104
128
  */
105
129
  declare const openapi: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
106
130
 
107
- export { SchemaValidator, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodResolve, ZodSchemaValidator, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
131
+ export { SchemaValidator, TupleZodResolve, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodRecordKey, ZodResolve, ZodSchemaValidator, ZodTupleContainer, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, function_, isSchema, literal, never, null_, nullish, number, openapi, optional, parse, promise, record, schemify, string, symbol, undefined_, union, unknown, uri, uuid, validate, void_ };
@@ -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
- if (schema instanceof import_zod.ZodType) {
132
- return schema.optional();
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
- if (schema instanceof import_zod.ZodType) {
144
- return schema.array();
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 = schema instanceof import_zod.ZodType ? schema : this.schemify(schema);
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 = schema instanceof import_zod.ZodType ? schema : this.schemify(schema);
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
  });
@@ -1,8 +1,8 @@
1
1
  // src/zod/zodSchemaValidator.ts
2
2
  import { generateSchema } from "@anatine/zod-openapi";
3
3
  import {
4
- ZodType,
5
- z
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
- if (schema instanceof ZodType) {
86
- return schema.optional();
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
- if (schema instanceof ZodType) {
98
- return schema.array();
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 = schema instanceof ZodType ? schema : this.schemify(schema);
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 = schema instanceof ZodType ? schema : this.schemify(schema);
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.4.11",
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.6"
64
+ "@forklaunch/common": "0.2.7"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@eslint/js": "^9.24.0",