@forklaunch/validator 0.4.0 → 0.4.2
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/index.d.mts +12 -1
- package/lib/index.d.ts +12 -1
- package/lib/index.js +26 -0
- package/lib/index.mjs +17 -0
- package/lib/{index-V6qNDTlr.d.mts → schema.types-Do9dhcdB.d.mts} +12 -12
- package/lib/{index-V6qNDTlr.d.ts → schema.types-Do9dhcdB.d.ts} +12 -12
- package/lib/src/typebox/index.d.mts +1 -8
- package/lib/src/typebox/index.d.ts +1 -8
- package/lib/src/typebox/index.js +4 -17
- package/lib/src/typebox/index.mjs +4 -17
- package/lib/src/zod/index.d.mts +4 -4
- package/lib/src/zod/index.d.ts +4 -4
- package/lib/src/zod/index.js +32 -34
- package/lib/src/zod/index.mjs +32 -34
- package/lib/tests/utils/mockSchemaValidator.d.mts +1 -1
- package/lib/tests/utils/mockSchemaValidator.d.ts +1 -1
- package/lib/tests/utils/mockSchemaValidator.js +1 -1
- package/lib/tests/utils/mockSchemaValidator.mjs +1 -1
- package/package.json +35 -35
package/lib/index.d.mts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { P as ParseError } from './schema.types-Do9dhcdB.mjs';
|
|
2
|
+
export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-Do9dhcdB.mjs';
|
|
2
3
|
import '@forklaunch/common';
|
|
3
4
|
import 'openapi3-ts/oas31';
|
|
4
5
|
import '@sinclair/typebox';
|
|
5
6
|
import '@sinclair/typebox/compiler';
|
|
6
7
|
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Pretty print parsing errors.
|
|
11
|
+
*
|
|
12
|
+
* @param {ParseError[]} errors - The errors to pretty print.
|
|
13
|
+
* @returns {string | undefined} The pretty printed errors.
|
|
14
|
+
*/
|
|
15
|
+
declare function prettyPrintParseErrors(errors?: ParseError[], prefix?: string): string | undefined;
|
|
16
|
+
|
|
17
|
+
export { ParseError, prettyPrintParseErrors };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { P as ParseError } from './schema.types-Do9dhcdB.js';
|
|
2
|
+
export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-Do9dhcdB.js';
|
|
2
3
|
import '@forklaunch/common';
|
|
3
4
|
import 'openapi3-ts/oas31';
|
|
4
5
|
import '@sinclair/typebox';
|
|
5
6
|
import '@sinclair/typebox/compiler';
|
|
6
7
|
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Pretty print parsing errors.
|
|
11
|
+
*
|
|
12
|
+
* @param {ParseError[]} errors - The errors to pretty print.
|
|
13
|
+
* @returns {string | undefined} The pretty printed errors.
|
|
14
|
+
*/
|
|
15
|
+
declare function prettyPrintParseErrors(errors?: ParseError[], prefix?: string): string | undefined;
|
|
16
|
+
|
|
17
|
+
export { ParseError, prettyPrintParseErrors };
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,4 +19,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// index.ts
|
|
17
21
|
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
prettyPrintParseErrors: () => prettyPrintParseErrors
|
|
24
|
+
});
|
|
18
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/shared/utils/prettyPrintParseErrors.ts
|
|
28
|
+
function prettyPrintParseErrors(errors, prefix) {
|
|
29
|
+
const messageStart = `${prefix != null ? `${prefix} v` : "V"}alidation failed`;
|
|
30
|
+
if (!errors || errors.length === 0) return messageStart;
|
|
31
|
+
const errorMessages = errors.map((err, index) => {
|
|
32
|
+
const path = err.path.length > 0 ? err.path.join(" > ") : "root";
|
|
33
|
+
return `${index + 1}. Path: ${path}
|
|
34
|
+
Message: ${err.message}`;
|
|
35
|
+
});
|
|
36
|
+
return `${messageStart} with the following errors:
|
|
37
|
+
${errorMessages.join(
|
|
38
|
+
"\n\n"
|
|
39
|
+
)}`;
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
prettyPrintParseErrors
|
|
44
|
+
});
|
package/lib/index.mjs
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/shared/utils/prettyPrintParseErrors.ts
|
|
2
|
+
function prettyPrintParseErrors(errors, prefix) {
|
|
3
|
+
const messageStart = `${prefix != null ? `${prefix} v` : "V"}alidation failed`;
|
|
4
|
+
if (!errors || errors.length === 0) return messageStart;
|
|
5
|
+
const errorMessages = errors.map((err, index) => {
|
|
6
|
+
const path = err.path.length > 0 ? err.path.join(" > ") : "root";
|
|
7
|
+
return `${index + 1}. Path: ${path}
|
|
8
|
+
Message: ${err.message}`;
|
|
9
|
+
});
|
|
10
|
+
return `${messageStart} with the following errors:
|
|
11
|
+
${errorMessages.join(
|
|
12
|
+
"\n\n"
|
|
13
|
+
)}`;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
prettyPrintParseErrors
|
|
17
|
+
};
|
|
@@ -73,22 +73,15 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
73
73
|
uuid: z.ZodString;
|
|
74
74
|
email: z.ZodString;
|
|
75
75
|
uri: z.ZodString;
|
|
76
|
-
number: z.ZodNumber
|
|
77
|
-
bigint: z.ZodBigInt
|
|
76
|
+
number: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodNumber>;
|
|
77
|
+
bigint: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodBigInt>;
|
|
78
78
|
boolean: z.ZodEffects<z.ZodBoolean, boolean, unknown>;
|
|
79
|
-
date: z.ZodDate
|
|
79
|
+
date: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodDate>;
|
|
80
80
|
symbol: z.ZodSymbol;
|
|
81
81
|
nullish: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
82
82
|
any: z.ZodAny;
|
|
83
83
|
unknown: z.ZodUnknown;
|
|
84
84
|
never: z.ZodNever;
|
|
85
|
-
/**
|
|
86
|
-
* Pretty print Zod errors.
|
|
87
|
-
*
|
|
88
|
-
* @param {ZodError} error - The Zod error to pretty print.
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
private prettyPrintZodErrors;
|
|
92
85
|
/**
|
|
93
86
|
* Compiles schema if this exists, for optimal performance.
|
|
94
87
|
*
|
|
@@ -223,6 +216,13 @@ type ZodResolve<T, Depth extends number = 0> = Depth extends 31 ? ZodUnknown : T
|
|
|
223
216
|
[K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
|
|
224
217
|
}> : ZodNever;
|
|
225
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Represents an error with a path and message.
|
|
221
|
+
*/
|
|
222
|
+
type ParseError = {
|
|
223
|
+
path: string[];
|
|
224
|
+
message: string;
|
|
225
|
+
};
|
|
226
226
|
/**
|
|
227
227
|
* The result associated with an attempted parsing.
|
|
228
228
|
*
|
|
@@ -232,7 +232,7 @@ type ParseResult<T> = {
|
|
|
232
232
|
value: T;
|
|
233
233
|
} | {
|
|
234
234
|
ok: false;
|
|
235
|
-
|
|
235
|
+
errors?: ParseError[];
|
|
236
236
|
};
|
|
237
237
|
/**
|
|
238
238
|
* Interface representing a schema validator.
|
|
@@ -473,4 +473,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
|
|
|
473
473
|
*/
|
|
474
474
|
type KeyTypes = string | number;
|
|
475
475
|
|
|
476
|
-
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type
|
|
476
|
+
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type ZodIdiomaticSchema as j, type ZodResolve as k, type ZodUnionContainer as l, type UnionZodResolve as m, type ZodCatchall as n };
|
|
@@ -73,22 +73,15 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
|
|
|
73
73
|
uuid: z.ZodString;
|
|
74
74
|
email: z.ZodString;
|
|
75
75
|
uri: z.ZodString;
|
|
76
|
-
number: z.ZodNumber
|
|
77
|
-
bigint: z.ZodBigInt
|
|
76
|
+
number: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodNumber>;
|
|
77
|
+
bigint: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodBigInt>;
|
|
78
78
|
boolean: z.ZodEffects<z.ZodBoolean, boolean, unknown>;
|
|
79
|
-
date: z.ZodDate
|
|
79
|
+
date: z.ZodPipeline<z.ZodEffects<z.ZodAny, any, any>, z.ZodDate>;
|
|
80
80
|
symbol: z.ZodSymbol;
|
|
81
81
|
nullish: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
|
|
82
82
|
any: z.ZodAny;
|
|
83
83
|
unknown: z.ZodUnknown;
|
|
84
84
|
never: z.ZodNever;
|
|
85
|
-
/**
|
|
86
|
-
* Pretty print Zod errors.
|
|
87
|
-
*
|
|
88
|
-
* @param {ZodError} error - The Zod error to pretty print.
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
private prettyPrintZodErrors;
|
|
92
85
|
/**
|
|
93
86
|
* Compiles schema if this exists, for optimal performance.
|
|
94
87
|
*
|
|
@@ -223,6 +216,13 @@ type ZodResolve<T, Depth extends number = 0> = Depth extends 31 ? ZodUnknown : T
|
|
|
223
216
|
[K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
|
|
224
217
|
}> : ZodNever;
|
|
225
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Represents an error with a path and message.
|
|
221
|
+
*/
|
|
222
|
+
type ParseError = {
|
|
223
|
+
path: string[];
|
|
224
|
+
message: string;
|
|
225
|
+
};
|
|
226
226
|
/**
|
|
227
227
|
* The result associated with an attempted parsing.
|
|
228
228
|
*
|
|
@@ -232,7 +232,7 @@ type ParseResult<T> = {
|
|
|
232
232
|
value: T;
|
|
233
233
|
} | {
|
|
234
234
|
ok: false;
|
|
235
|
-
|
|
235
|
+
errors?: ParseError[];
|
|
236
236
|
};
|
|
237
237
|
/**
|
|
238
238
|
* Interface representing a schema validator.
|
|
@@ -473,4 +473,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
|
|
|
473
473
|
*/
|
|
474
474
|
type KeyTypes = string | number;
|
|
475
475
|
|
|
476
|
-
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type
|
|
476
|
+
export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type ZodIdiomaticSchema as j, type ZodResolve as k, type ZodUnionContainer as l, type UnionZodResolve as m, type ZodCatchall as n };
|
|
@@ -2,7 +2,7 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
|
2
2
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
3
|
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
4
4
|
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
5
|
-
import { S as SchemaValidator$1, T as TObject,
|
|
5
|
+
import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, a as ParseResult } from '../../schema.types-Do9dhcdB.mjs';
|
|
6
6
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
7
7
|
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
|
|
8
8
|
import '@forklaunch/common';
|
|
@@ -36,13 +36,6 @@ declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TO
|
|
|
36
36
|
* @returns The type of the schema for error messages.
|
|
37
37
|
*/
|
|
38
38
|
private errorType;
|
|
39
|
-
/**
|
|
40
|
-
* Pretty print TypeBox errors.
|
|
41
|
-
*
|
|
42
|
-
* @param {ValueError[]} errors
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
private prettyPrintTypeBoxErrors;
|
|
46
39
|
/**
|
|
47
40
|
* Compiles schema if this exists, for optimal performance.
|
|
48
41
|
*
|
|
@@ -2,7 +2,7 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
|
2
2
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
3
|
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
4
4
|
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
5
|
-
import { S as SchemaValidator$1, T as TObject,
|
|
5
|
+
import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, a as ParseResult } from '../../schema.types-Do9dhcdB.js';
|
|
6
6
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
7
7
|
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
|
|
8
8
|
import '@forklaunch/common';
|
|
@@ -36,13 +36,6 @@ declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TO
|
|
|
36
36
|
* @returns The type of the schema for error messages.
|
|
37
37
|
*/
|
|
38
38
|
private errorType;
|
|
39
|
-
/**
|
|
40
|
-
* Pretty print TypeBox errors.
|
|
41
|
-
*
|
|
42
|
-
* @param {ValueError[]} errors
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
private prettyPrintTypeBoxErrors;
|
|
46
39
|
/**
|
|
47
40
|
* Compiles schema if this exists, for optimal performance.
|
|
48
41
|
*
|
package/lib/src/typebox/index.js
CHANGED
|
@@ -198,22 +198,6 @@ var TypeboxSchemaValidator = class {
|
|
|
198
198
|
}
|
|
199
199
|
return schema[import_typebox.Kind].toLowerCase();
|
|
200
200
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Pretty print TypeBox errors.
|
|
203
|
-
*
|
|
204
|
-
* @param {ValueError[]} errors
|
|
205
|
-
* @returns
|
|
206
|
-
*/
|
|
207
|
-
prettyPrintTypeBoxErrors(errors) {
|
|
208
|
-
if (!errors || errors.length === 0) return;
|
|
209
|
-
const errorMessages = errors.map((err, index) => {
|
|
210
|
-
const path = err.path.length > 0 ? err.path.split("/").slice(1).join(" > ") : "root";
|
|
211
|
-
return `${index + 1}. Path: ${path}
|
|
212
|
-
Message: ${err.message}`;
|
|
213
|
-
});
|
|
214
|
-
return `Validation failed with the following errors:
|
|
215
|
-
${errorMessages.join("\n\n")}`;
|
|
216
|
-
}
|
|
217
201
|
/**
|
|
218
202
|
* Compiles schema if this exists, for optimal performance.
|
|
219
203
|
*
|
|
@@ -353,7 +337,10 @@ ${errorMessages.join("\n\n")}`;
|
|
|
353
337
|
value: conversion
|
|
354
338
|
} : {
|
|
355
339
|
ok: false,
|
|
356
|
-
|
|
340
|
+
errors: errors.map((error) => ({
|
|
341
|
+
path: error.path.split("/").slice(1),
|
|
342
|
+
message: error.message
|
|
343
|
+
}))
|
|
357
344
|
};
|
|
358
345
|
}
|
|
359
346
|
/**
|
|
@@ -157,22 +157,6 @@ var TypeboxSchemaValidator = class {
|
|
|
157
157
|
}
|
|
158
158
|
return schema[Kind].toLowerCase();
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Pretty print TypeBox errors.
|
|
162
|
-
*
|
|
163
|
-
* @param {ValueError[]} errors
|
|
164
|
-
* @returns
|
|
165
|
-
*/
|
|
166
|
-
prettyPrintTypeBoxErrors(errors) {
|
|
167
|
-
if (!errors || errors.length === 0) return;
|
|
168
|
-
const errorMessages = errors.map((err, index) => {
|
|
169
|
-
const path = err.path.length > 0 ? err.path.split("/").slice(1).join(" > ") : "root";
|
|
170
|
-
return `${index + 1}. Path: ${path}
|
|
171
|
-
Message: ${err.message}`;
|
|
172
|
-
});
|
|
173
|
-
return `Validation failed with the following errors:
|
|
174
|
-
${errorMessages.join("\n\n")}`;
|
|
175
|
-
}
|
|
176
160
|
/**
|
|
177
161
|
* Compiles schema if this exists, for optimal performance.
|
|
178
162
|
*
|
|
@@ -312,7 +296,10 @@ ${errorMessages.join("\n\n")}`;
|
|
|
312
296
|
value: conversion
|
|
313
297
|
} : {
|
|
314
298
|
ok: false,
|
|
315
|
-
|
|
299
|
+
errors: errors.map((error) => ({
|
|
300
|
+
path: error.path.split("/").slice(1),
|
|
301
|
+
message: error.message
|
|
302
|
+
}))
|
|
316
303
|
};
|
|
317
304
|
}
|
|
318
305
|
/**
|
package/lib/src/zod/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
-
import { Z as ZodSchemaValidator,
|
|
2
|
+
import { Z as ZodSchemaValidator, j as ZodIdiomaticSchema, k as ZodResolve, l as ZodUnionContainer, m as UnionZodResolve, L as LiteralSchema, n as ZodCatchall, a as ParseResult } from '../../schema.types-Do9dhcdB.mjs';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import '@forklaunch/common';
|
|
5
5
|
import '@sinclair/typebox';
|
|
@@ -29,11 +29,11 @@ declare const uri: zod.ZodString;
|
|
|
29
29
|
/**
|
|
30
30
|
* Zod schema definition for number type.
|
|
31
31
|
*/
|
|
32
|
-
declare const number: zod.ZodNumber
|
|
32
|
+
declare const number: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodNumber>;
|
|
33
33
|
/**
|
|
34
34
|
* Zod schema definition for bigint type.
|
|
35
35
|
*/
|
|
36
|
-
declare const bigint: zod.ZodBigInt
|
|
36
|
+
declare const bigint: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodBigInt>;
|
|
37
37
|
/**
|
|
38
38
|
* Zod schema definition for boolean type.
|
|
39
39
|
*/
|
|
@@ -41,7 +41,7 @@ declare const boolean: zod.ZodEffects<zod.ZodBoolean, boolean, unknown>;
|
|
|
41
41
|
/**
|
|
42
42
|
* Zod schema definition for date type.
|
|
43
43
|
*/
|
|
44
|
-
declare const date: zod.ZodDate
|
|
44
|
+
declare const date: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodDate>;
|
|
45
45
|
/**
|
|
46
46
|
* Zod schema definition for symbol type.
|
|
47
47
|
*/
|
package/lib/src/zod/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
-
import { Z as ZodSchemaValidator,
|
|
2
|
+
import { Z as ZodSchemaValidator, j as ZodIdiomaticSchema, k as ZodResolve, l as ZodUnionContainer, m as UnionZodResolve, L as LiteralSchema, n as ZodCatchall, a as ParseResult } from '../../schema.types-Do9dhcdB.js';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import '@forklaunch/common';
|
|
5
5
|
import '@sinclair/typebox';
|
|
@@ -29,11 +29,11 @@ declare const uri: zod.ZodString;
|
|
|
29
29
|
/**
|
|
30
30
|
* Zod schema definition for number type.
|
|
31
31
|
*/
|
|
32
|
-
declare const number: zod.ZodNumber
|
|
32
|
+
declare const number: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodNumber>;
|
|
33
33
|
/**
|
|
34
34
|
* Zod schema definition for bigint type.
|
|
35
35
|
*/
|
|
36
|
-
declare const bigint: zod.ZodBigInt
|
|
36
|
+
declare const bigint: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodBigInt>;
|
|
37
37
|
/**
|
|
38
38
|
* Zod schema definition for boolean type.
|
|
39
39
|
*/
|
|
@@ -41,7 +41,7 @@ declare const boolean: zod.ZodEffects<zod.ZodBoolean, boolean, unknown>;
|
|
|
41
41
|
/**
|
|
42
42
|
* Zod schema definition for date type.
|
|
43
43
|
*/
|
|
44
|
-
declare const date: zod.ZodDate
|
|
44
|
+
declare const date: zod.ZodPipeline<zod.ZodEffects<zod.ZodAny, any, any>, zod.ZodDate>;
|
|
45
45
|
/**
|
|
46
46
|
* Zod schema definition for symbol type.
|
|
47
47
|
*/
|
package/lib/src/zod/index.js
CHANGED
|
@@ -55,11 +55,23 @@ var ZodSchemaValidator = class {
|
|
|
55
55
|
_SchemaCatchall;
|
|
56
56
|
_ValidSchemaObject;
|
|
57
57
|
string = import_zod.z.string();
|
|
58
|
-
uuid = import_zod.z.
|
|
59
|
-
email = import_zod.z.
|
|
60
|
-
uri = import_zod.z.
|
|
61
|
-
number = import_zod.z.
|
|
62
|
-
|
|
58
|
+
uuid = import_zod.z.string().uuid();
|
|
59
|
+
email = import_zod.z.string().email();
|
|
60
|
+
uri = import_zod.z.string().url();
|
|
61
|
+
number = import_zod.z.any().transform((value) => {
|
|
62
|
+
try {
|
|
63
|
+
return Number(value);
|
|
64
|
+
} catch {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
}).pipe(import_zod.z.number());
|
|
68
|
+
bigint = import_zod.z.any().transform((value) => {
|
|
69
|
+
try {
|
|
70
|
+
return BigInt(value);
|
|
71
|
+
} catch {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
}).pipe(import_zod.z.bigint());
|
|
63
75
|
boolean = import_zod.z.preprocess((val) => {
|
|
64
76
|
if (typeof val === "string") {
|
|
65
77
|
if (val.toLowerCase() === "true") return true;
|
|
@@ -67,28 +79,18 @@ var ZodSchemaValidator = class {
|
|
|
67
79
|
}
|
|
68
80
|
return val;
|
|
69
81
|
}, import_zod.z.boolean());
|
|
70
|
-
date = import_zod.z.
|
|
82
|
+
date = import_zod.z.any().transform((value) => {
|
|
83
|
+
try {
|
|
84
|
+
return new Date(value);
|
|
85
|
+
} catch {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
}).pipe(import_zod.z.date());
|
|
71
89
|
symbol = import_zod.z.symbol();
|
|
72
90
|
nullish = import_zod.z.union([import_zod.z.void(), import_zod.z.null(), import_zod.z.undefined()]);
|
|
73
91
|
any = import_zod.z.any();
|
|
74
92
|
unknown = import_zod.z.unknown();
|
|
75
93
|
never = import_zod.z.never();
|
|
76
|
-
/**
|
|
77
|
-
* Pretty print Zod errors.
|
|
78
|
-
*
|
|
79
|
-
* @param {ZodError} error - The Zod error to pretty print.
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
prettyPrintZodErrors(error) {
|
|
83
|
-
if (!error) return;
|
|
84
|
-
const errorMessages = error.errors.map((err, index) => {
|
|
85
|
-
const path = err.path.length > 0 ? err.path.join(" > ") : "root";
|
|
86
|
-
return `${index + 1}. Path: ${path}
|
|
87
|
-
Message: ${err.message}`;
|
|
88
|
-
});
|
|
89
|
-
return `Validation failed with the following errors:
|
|
90
|
-
${errorMessages.join("\n\n")}`;
|
|
91
|
-
}
|
|
92
94
|
/**
|
|
93
95
|
* Compiles schema if this exists, for optimal performance.
|
|
94
96
|
*
|
|
@@ -201,18 +203,14 @@ ${errorMessages.join("\n\n")}`;
|
|
|
201
203
|
* @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
|
|
202
204
|
*/
|
|
203
205
|
parse(schema, value) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
ok: false,
|
|
213
|
-
error: `Unexpected zod safeParse error: ${error.message}`
|
|
214
|
-
};
|
|
215
|
-
}
|
|
206
|
+
const result = schema.safeParse(value);
|
|
207
|
+
return result.success ? { ok: true, value: result.data } : {
|
|
208
|
+
ok: false,
|
|
209
|
+
errors: result.error.errors.map((error) => ({
|
|
210
|
+
path: error.path.map((p) => p.toString()),
|
|
211
|
+
message: error.message
|
|
212
|
+
}))
|
|
213
|
+
};
|
|
216
214
|
}
|
|
217
215
|
/**
|
|
218
216
|
* Convert a schema to an OpenAPI schema object.
|
package/lib/src/zod/index.mjs
CHANGED
|
@@ -9,11 +9,23 @@ var ZodSchemaValidator = class {
|
|
|
9
9
|
_SchemaCatchall;
|
|
10
10
|
_ValidSchemaObject;
|
|
11
11
|
string = z.string();
|
|
12
|
-
uuid = z.
|
|
13
|
-
email = z.
|
|
14
|
-
uri = z.
|
|
15
|
-
number = z.
|
|
16
|
-
|
|
12
|
+
uuid = z.string().uuid();
|
|
13
|
+
email = z.string().email();
|
|
14
|
+
uri = z.string().url();
|
|
15
|
+
number = z.any().transform((value) => {
|
|
16
|
+
try {
|
|
17
|
+
return Number(value);
|
|
18
|
+
} catch {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}).pipe(z.number());
|
|
22
|
+
bigint = z.any().transform((value) => {
|
|
23
|
+
try {
|
|
24
|
+
return BigInt(value);
|
|
25
|
+
} catch {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
}).pipe(z.bigint());
|
|
17
29
|
boolean = z.preprocess((val) => {
|
|
18
30
|
if (typeof val === "string") {
|
|
19
31
|
if (val.toLowerCase() === "true") return true;
|
|
@@ -21,28 +33,18 @@ var ZodSchemaValidator = class {
|
|
|
21
33
|
}
|
|
22
34
|
return val;
|
|
23
35
|
}, z.boolean());
|
|
24
|
-
date = z.
|
|
36
|
+
date = z.any().transform((value) => {
|
|
37
|
+
try {
|
|
38
|
+
return new Date(value);
|
|
39
|
+
} catch {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}).pipe(z.date());
|
|
25
43
|
symbol = z.symbol();
|
|
26
44
|
nullish = z.union([z.void(), z.null(), z.undefined()]);
|
|
27
45
|
any = z.any();
|
|
28
46
|
unknown = z.unknown();
|
|
29
47
|
never = z.never();
|
|
30
|
-
/**
|
|
31
|
-
* Pretty print Zod errors.
|
|
32
|
-
*
|
|
33
|
-
* @param {ZodError} error - The Zod error to pretty print.
|
|
34
|
-
* @returns
|
|
35
|
-
*/
|
|
36
|
-
prettyPrintZodErrors(error) {
|
|
37
|
-
if (!error) return;
|
|
38
|
-
const errorMessages = error.errors.map((err, index) => {
|
|
39
|
-
const path = err.path.length > 0 ? err.path.join(" > ") : "root";
|
|
40
|
-
return `${index + 1}. Path: ${path}
|
|
41
|
-
Message: ${err.message}`;
|
|
42
|
-
});
|
|
43
|
-
return `Validation failed with the following errors:
|
|
44
|
-
${errorMessages.join("\n\n")}`;
|
|
45
|
-
}
|
|
46
48
|
/**
|
|
47
49
|
* Compiles schema if this exists, for optimal performance.
|
|
48
50
|
*
|
|
@@ -155,18 +157,14 @@ ${errorMessages.join("\n\n")}`;
|
|
|
155
157
|
* @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
|
|
156
158
|
*/
|
|
157
159
|
parse(schema, value) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
ok: false,
|
|
167
|
-
error: `Unexpected zod safeParse error: ${error.message}`
|
|
168
|
-
};
|
|
169
|
-
}
|
|
160
|
+
const result = schema.safeParse(value);
|
|
161
|
+
return result.success ? { ok: true, value: result.data } : {
|
|
162
|
+
ok: false,
|
|
163
|
+
errors: result.error.errors.map((error) => ({
|
|
164
|
+
path: error.path.map((p) => p.toString()),
|
|
165
|
+
message: error.message
|
|
166
|
+
}))
|
|
167
|
+
};
|
|
170
168
|
}
|
|
171
169
|
/**
|
|
172
170
|
* Convert a schema to an OpenAPI schema object.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { S as SchemaValidator, L as LiteralSchema,
|
|
2
|
+
import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-Do9dhcdB.mjs';
|
|
3
3
|
import '@forklaunch/common';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '@sinclair/typebox/compiler';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { S as SchemaValidator, L as LiteralSchema,
|
|
2
|
+
import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-Do9dhcdB.js';
|
|
3
3
|
import '@forklaunch/common';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '@sinclair/typebox/compiler';
|
package/package.json
CHANGED
|
@@ -1,44 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forklaunch/validator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Schema validator for ForkLaunch components.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"types": "lib/index.d.ts",
|
|
9
|
-
"directories": {
|
|
10
|
-
"test": "tests"
|
|
5
|
+
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/forklaunch/forklaunch-js/issues"
|
|
11
8
|
},
|
|
12
9
|
"repository": {
|
|
13
10
|
"type": "git",
|
|
14
11
|
"url": "git+https://github.com/forklaunch/forklaunch-js.git"
|
|
15
12
|
},
|
|
16
|
-
"author": "Rohin Bhargava",
|
|
17
13
|
"license": "MIT",
|
|
18
|
-
"
|
|
19
|
-
"url": "https://github.com/forklaunch/forklaunch-js/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@anatine/zod-openapi": "^2.2.6",
|
|
24
|
-
"@sinclair/typebox": "^0.34.13",
|
|
25
|
-
"zod": "^3.24.1",
|
|
26
|
-
"@forklaunch/common": "0.2.0"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@eslint/js": "^9.17.0",
|
|
30
|
-
"@types/jest": "^29.5.14",
|
|
31
|
-
"@vitest/coverage-v8": "^2.1.8",
|
|
32
|
-
"eslint-config-prettier": "^9.1.0",
|
|
33
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
34
|
-
"globals": "^15.14.0",
|
|
35
|
-
"jest": "^29.7.0",
|
|
36
|
-
"openapi3-ts": "^4.4.0",
|
|
37
|
-
"ts-jest": "^29.2.5",
|
|
38
|
-
"ts-node": "^10.9.2",
|
|
39
|
-
"tsup": "^8.3.5",
|
|
40
|
-
"typescript-eslint": "^8.19.1"
|
|
41
|
-
},
|
|
14
|
+
"author": "Rohin Bhargava",
|
|
42
15
|
"exports": {
|
|
43
16
|
".": {
|
|
44
17
|
"types": "./lib/index.d.ts",
|
|
@@ -77,14 +50,41 @@
|
|
|
77
50
|
"default": "./lib/tests/utils/mockSchemaValidator.js"
|
|
78
51
|
}
|
|
79
52
|
},
|
|
53
|
+
"types": "lib/index.d.ts",
|
|
54
|
+
"directories": {
|
|
55
|
+
"test": "tests"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"lib"
|
|
59
|
+
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@anatine/zod-openapi": "^2.2.6",
|
|
62
|
+
"@sinclair/typebox": "^0.34.13",
|
|
63
|
+
"zod": "^3.24.1",
|
|
64
|
+
"@forklaunch/common": "0.2.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@eslint/js": "^9.17.0",
|
|
68
|
+
"@types/jest": "^29.5.14",
|
|
69
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
70
|
+
"eslint-config-prettier": "^9.1.0",
|
|
71
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
72
|
+
"globals": "^15.14.0",
|
|
73
|
+
"jest": "^29.7.0",
|
|
74
|
+
"openapi3-ts": "^4.4.0",
|
|
75
|
+
"ts-jest": "^29.2.5",
|
|
76
|
+
"ts-node": "^10.9.2",
|
|
77
|
+
"tsup": "^8.3.5",
|
|
78
|
+
"typescript-eslint": "^8.19.1"
|
|
79
|
+
},
|
|
80
80
|
"scripts": {
|
|
81
|
-
"test": "vitest --passWithNoTests",
|
|
82
81
|
"build": "tsc --noEmit && tsup index.ts src/typebox/index.ts src/zod/index.ts tests/utils/mockSchemaValidator.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",
|
|
83
82
|
"clean": "rm -rf lib pnpm.lock.yaml node_modules",
|
|
84
83
|
"docs": "typedoc --out docs *",
|
|
84
|
+
"format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
|
|
85
85
|
"lint": "eslint . -c eslint.config.mjs",
|
|
86
86
|
"lint:fix": "eslint . -c eslint.config.mjs --fix",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
87
|
+
"publish:package": "./publish-package.bash",
|
|
88
|
+
"test": "vitest --passWithNoTests"
|
|
89
89
|
}
|
|
90
90
|
}
|