@forklaunch/validator 0.5.4 → 0.6.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/__test__/utils/mockSchemaValidator.d.mts +12 -2
- package/lib/__test__/utils/mockSchemaValidator.d.ts +12 -2
- package/lib/__test__/utils/mockSchemaValidator.js +17 -2
- package/lib/__test__/utils/mockSchemaValidator.mjs +17 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/{schema.types-DyZIpu-x.d.mts → schema.types-MvSNOCj2.d.mts} +50 -16
- package/lib/{schema.types-DyZIpu-x.d.ts → schema.types-MvSNOCj2.d.ts} +50 -16
- package/lib/src/typebox/index.d.mts +15 -7
- package/lib/src/typebox/index.d.ts +15 -7
- package/lib/src/typebox/index.js +133 -42
- package/lib/src/typebox/index.mjs +132 -42
- package/lib/src/zod/index.d.mts +16 -8
- package/lib/src/zod/index.d.ts +16 -8
- package/lib/src/zod/index.js +138 -21
- package/lib/src/zod/index.mjs +137 -22
- package/package.json +13 -12
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
2
|
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
3
|
-
import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as TUnionTupleContainer, i as UnionTupleTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-
|
|
4
|
-
export {
|
|
3
|
+
import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as TUnionTupleContainer, i as UnionTupleTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult, k as TSchemaTranslate } from '../../schema.types-MvSNOCj2.mjs';
|
|
4
|
+
export { n as TObject, m as TObjectShape, l as TOuterArray, o as UnboxedTObjectSchema } from '../../schema.types-MvSNOCj2.mjs';
|
|
5
|
+
import * as _forklaunch_common from '@forklaunch/common';
|
|
5
6
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
6
|
-
import '@forklaunch/common';
|
|
7
7
|
import 'zod';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -30,7 +30,7 @@ declare const email: _sinclair_typebox.TString;
|
|
|
30
30
|
/**
|
|
31
31
|
* TypeBox schema definition for number type.
|
|
32
32
|
*/
|
|
33
|
-
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.
|
|
33
|
+
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TBigInt, _sinclair_typebox.TDate]>, number>;
|
|
34
34
|
/**
|
|
35
35
|
* TypeBox schema definition for bigint type.
|
|
36
36
|
*/
|
|
@@ -42,7 +42,7 @@ declare const boolean: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_s
|
|
|
42
42
|
/**
|
|
43
43
|
* TypeBox schema definition for date type.
|
|
44
44
|
*/
|
|
45
|
-
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.
|
|
45
|
+
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNumber, _sinclair_typebox.TDate]>, Date>;
|
|
46
46
|
/**
|
|
47
47
|
* TypeBox schema definition for symbol type.
|
|
48
48
|
*/
|
|
@@ -75,6 +75,14 @@ declare const unknown: _sinclair_typebox.TUnknown;
|
|
|
75
75
|
* TypeBox schema definition for never type.
|
|
76
76
|
*/
|
|
77
77
|
declare const never: _sinclair_typebox.TNever;
|
|
78
|
+
/**
|
|
79
|
+
* TypeBox schema definition for blob type.
|
|
80
|
+
*/
|
|
81
|
+
declare const binary: _sinclair_typebox.TTransform<_sinclair_typebox.TString, Buffer<ArrayBuffer>>;
|
|
82
|
+
/**
|
|
83
|
+
* TypeBox schema definition for file type.
|
|
84
|
+
*/
|
|
85
|
+
declare const file: (name: string, type: _forklaunch_common.MimeType) => _sinclair_typebox.TTransform<_sinclair_typebox.TString, File>;
|
|
78
86
|
/**
|
|
79
87
|
* Transforms valid schema into TypeBox schema.
|
|
80
88
|
*/
|
|
@@ -122,10 +130,10 @@ declare const validate: <T extends TIdiomaticSchema | TCatchall>(schema: T | _si
|
|
|
122
130
|
/**
|
|
123
131
|
* Parses a value against a valid schema.
|
|
124
132
|
*/
|
|
125
|
-
declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T
|
|
133
|
+
declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TSchemaTranslate<TResolve<T>>>;
|
|
126
134
|
/**
|
|
127
135
|
* Generates an OpenAPI schema object from a valid schema.
|
|
128
136
|
*/
|
|
129
137
|
declare const openapi: <T extends TIdiomaticSchema | TCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
|
|
130
138
|
|
|
131
|
-
export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve, TUnionTupleContainer, TypeboxSchemaValidator, UnionTupleTResolve, 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_ };
|
|
139
|
+
export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve, TSchemaTranslate, TUnionTupleContainer, TypeboxSchemaValidator, UnionTupleTResolve, any, array, bigint, binary, boolean, date, email, enum_, file, function_, isSchema, literal, never, null_, nullish, number, openapi, optional, parse, promise, record, schemify, string, symbol, undefined_, union, unknown, uri, uuid, validate, void_ };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
2
|
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
3
|
-
import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as TUnionTupleContainer, i as UnionTupleTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-
|
|
4
|
-
export {
|
|
3
|
+
import { T as TypeboxSchemaValidator, f as TIdiomaticSchema, g as TResolve, h as TUnionTupleContainer, i as UnionTupleTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult, k as TSchemaTranslate } from '../../schema.types-MvSNOCj2.js';
|
|
4
|
+
export { n as TObject, m as TObjectShape, l as TOuterArray, o as UnboxedTObjectSchema } from '../../schema.types-MvSNOCj2.js';
|
|
5
|
+
import * as _forklaunch_common from '@forklaunch/common';
|
|
5
6
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
6
|
-
import '@forklaunch/common';
|
|
7
7
|
import 'zod';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -30,7 +30,7 @@ declare const email: _sinclair_typebox.TString;
|
|
|
30
30
|
/**
|
|
31
31
|
* TypeBox schema definition for number type.
|
|
32
32
|
*/
|
|
33
|
-
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.
|
|
33
|
+
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TBigInt, _sinclair_typebox.TDate]>, number>;
|
|
34
34
|
/**
|
|
35
35
|
* TypeBox schema definition for bigint type.
|
|
36
36
|
*/
|
|
@@ -42,7 +42,7 @@ declare const boolean: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_s
|
|
|
42
42
|
/**
|
|
43
43
|
* TypeBox schema definition for date type.
|
|
44
44
|
*/
|
|
45
|
-
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.
|
|
45
|
+
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNumber, _sinclair_typebox.TDate]>, Date>;
|
|
46
46
|
/**
|
|
47
47
|
* TypeBox schema definition for symbol type.
|
|
48
48
|
*/
|
|
@@ -75,6 +75,14 @@ declare const unknown: _sinclair_typebox.TUnknown;
|
|
|
75
75
|
* TypeBox schema definition for never type.
|
|
76
76
|
*/
|
|
77
77
|
declare const never: _sinclair_typebox.TNever;
|
|
78
|
+
/**
|
|
79
|
+
* TypeBox schema definition for blob type.
|
|
80
|
+
*/
|
|
81
|
+
declare const binary: _sinclair_typebox.TTransform<_sinclair_typebox.TString, Buffer<ArrayBuffer>>;
|
|
82
|
+
/**
|
|
83
|
+
* TypeBox schema definition for file type.
|
|
84
|
+
*/
|
|
85
|
+
declare const file: (name: string, type: _forklaunch_common.MimeType) => _sinclair_typebox.TTransform<_sinclair_typebox.TString, File>;
|
|
78
86
|
/**
|
|
79
87
|
* Transforms valid schema into TypeBox schema.
|
|
80
88
|
*/
|
|
@@ -122,10 +130,10 @@ declare const validate: <T extends TIdiomaticSchema | TCatchall>(schema: T | _si
|
|
|
122
130
|
/**
|
|
123
131
|
* Parses a value against a valid schema.
|
|
124
132
|
*/
|
|
125
|
-
declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T
|
|
133
|
+
declare const parse: <T extends TIdiomaticSchema | TCatchall>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TSchemaTranslate<TResolve<T>>>;
|
|
126
134
|
/**
|
|
127
135
|
* Generates an OpenAPI schema object from a valid schema.
|
|
128
136
|
*/
|
|
129
137
|
declare const openapi: <T extends TIdiomaticSchema | TCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
|
|
130
138
|
|
|
131
|
-
export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve, TUnionTupleContainer, TypeboxSchemaValidator, UnionTupleTResolve, 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_ };
|
|
139
|
+
export { SchemaValidator, TCatchall, TIdiomaticSchema, TResolve, TSchemaTranslate, TUnionTupleContainer, TypeboxSchemaValidator, UnionTupleTResolve, any, array, bigint, binary, boolean, date, email, enum_, file, function_, isSchema, literal, never, null_, nullish, number, openapi, optional, parse, promise, record, schemify, string, symbol, undefined_, union, unknown, uri, uuid, validate, void_ };
|
package/lib/src/typebox/index.js
CHANGED
|
@@ -24,10 +24,12 @@ __export(typebox_exports, {
|
|
|
24
24
|
any: () => any,
|
|
25
25
|
array: () => array,
|
|
26
26
|
bigint: () => bigint,
|
|
27
|
+
binary: () => binary,
|
|
27
28
|
boolean: () => boolean,
|
|
28
29
|
date: () => date,
|
|
29
30
|
email: () => email,
|
|
30
31
|
enum_: () => enum_,
|
|
32
|
+
file: () => file,
|
|
31
33
|
function_: () => function_,
|
|
32
34
|
isSchema: () => isSchema,
|
|
33
35
|
literal: () => literal,
|
|
@@ -54,10 +56,12 @@ __export(typebox_exports, {
|
|
|
54
56
|
module.exports = __toCommonJS(typebox_exports);
|
|
55
57
|
|
|
56
58
|
// src/typebox/typeboxSchemaValidator.ts
|
|
59
|
+
var import_common = require("@forklaunch/common");
|
|
57
60
|
var import_typebox = require("@sinclair/typebox");
|
|
58
61
|
var import_compiler = require("@sinclair/typebox/compiler");
|
|
59
62
|
var import_errors = require("@sinclair/typebox/errors");
|
|
60
63
|
var import_value = require("@sinclair/typebox/value");
|
|
64
|
+
import_typebox.FormatRegistry.Set("binary", (value) => typeof value === "string");
|
|
61
65
|
(0, import_errors.SetErrorFunction)((params) => {
|
|
62
66
|
switch (params.errorType) {
|
|
63
67
|
case import_errors.ValueErrorType.Union:
|
|
@@ -73,18 +77,27 @@ var TypeboxSchemaValidator = class {
|
|
|
73
77
|
_Type = "TypeBox";
|
|
74
78
|
_SchemaCatchall;
|
|
75
79
|
_ValidSchemaObject;
|
|
76
|
-
string = import_typebox.Type.String(
|
|
80
|
+
string = import_typebox.Type.String({
|
|
81
|
+
example: "a string",
|
|
82
|
+
title: "String"
|
|
83
|
+
});
|
|
77
84
|
uuid = import_typebox.Type.String({
|
|
78
85
|
pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
|
|
79
|
-
errorType: "uuid"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
pattern: "^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$",
|
|
83
|
-
errorType: "uri"
|
|
86
|
+
errorType: "uuid",
|
|
87
|
+
example: "a8b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6",
|
|
88
|
+
title: "UUID"
|
|
84
89
|
});
|
|
85
90
|
email = import_typebox.Type.String({
|
|
86
91
|
pattern: `(?:[a-z0-9!#$%&'*+/=?^_{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])`,
|
|
87
|
-
errorType: "email"
|
|
92
|
+
errorType: "email",
|
|
93
|
+
example: "a@b.com",
|
|
94
|
+
title: "Email"
|
|
95
|
+
});
|
|
96
|
+
uri = import_typebox.Type.String({
|
|
97
|
+
pattern: "^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$",
|
|
98
|
+
errorType: "uri",
|
|
99
|
+
example: "https://forklaunch.com",
|
|
100
|
+
title: "URI"
|
|
88
101
|
});
|
|
89
102
|
number = import_typebox.Type.Transform(
|
|
90
103
|
import_typebox.Type.Union(
|
|
@@ -93,12 +106,13 @@ var TypeboxSchemaValidator = class {
|
|
|
93
106
|
import_typebox.Type.String({ pattern: "^[0-9]+$" }),
|
|
94
107
|
import_typebox.Type.Boolean(),
|
|
95
108
|
import_typebox.Type.Null(),
|
|
96
|
-
import_typebox.Type.
|
|
97
|
-
import_typebox.Type.
|
|
109
|
+
import_typebox.Type.BigInt(),
|
|
110
|
+
import_typebox.Type.Date()
|
|
98
111
|
],
|
|
99
112
|
{
|
|
100
113
|
errorType: "number-like",
|
|
101
|
-
|
|
114
|
+
example: 123,
|
|
115
|
+
title: "Number"
|
|
102
116
|
}
|
|
103
117
|
)
|
|
104
118
|
).Decode((value) => {
|
|
@@ -117,19 +131,23 @@ var TypeboxSchemaValidator = class {
|
|
|
117
131
|
[
|
|
118
132
|
import_typebox.Type.BigInt(),
|
|
119
133
|
import_typebox.Type.Number(),
|
|
120
|
-
import_typebox.Type.String({ pattern: "^[0-9]
|
|
134
|
+
import_typebox.Type.String({ pattern: "^[0-9]+n?$" }),
|
|
121
135
|
import_typebox.Type.Boolean(),
|
|
122
136
|
import_typebox.Type.Date()
|
|
123
137
|
],
|
|
124
138
|
{
|
|
125
139
|
errorType: "BigInt-like",
|
|
126
|
-
|
|
140
|
+
example: 123n,
|
|
141
|
+
title: "BigInt"
|
|
127
142
|
}
|
|
128
143
|
)
|
|
129
144
|
).Decode((value) => {
|
|
130
145
|
if (typeof value !== "bigint") {
|
|
131
146
|
try {
|
|
132
|
-
|
|
147
|
+
if (value instanceof Date) {
|
|
148
|
+
return BigInt(value.getTime());
|
|
149
|
+
}
|
|
150
|
+
return BigInt(value);
|
|
133
151
|
} catch {
|
|
134
152
|
throw new Error("Invalid bigint");
|
|
135
153
|
}
|
|
@@ -146,7 +164,8 @@ var TypeboxSchemaValidator = class {
|
|
|
146
164
|
],
|
|
147
165
|
{
|
|
148
166
|
errorType: "boolean-like",
|
|
149
|
-
|
|
167
|
+
example: true,
|
|
168
|
+
title: "Boolean"
|
|
150
169
|
}
|
|
151
170
|
)
|
|
152
171
|
).Decode((value) => {
|
|
@@ -160,38 +179,80 @@ var TypeboxSchemaValidator = class {
|
|
|
160
179
|
date = import_typebox.Type.Transform(
|
|
161
180
|
import_typebox.Type.Union(
|
|
162
181
|
[
|
|
163
|
-
import_typebox.Type.Date(),
|
|
164
|
-
import_typebox.Type.Number(),
|
|
165
182
|
import_typebox.Type.String({
|
|
166
183
|
pattern: "^\\d{4}(-\\d{2}){0,2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|([+-]\\d{2}:\\d{2}))?)?$|^\\d{1,2}\\/\\d{1,2}\\/\\d{4}$|^\\d{4}\\/\\d{1,2}\\/\\d{1,2}$|^\\d+$"
|
|
167
184
|
}),
|
|
168
|
-
import_typebox.Type.
|
|
169
|
-
import_typebox.Type.
|
|
185
|
+
import_typebox.Type.Number(),
|
|
186
|
+
import_typebox.Type.Date()
|
|
170
187
|
],
|
|
171
188
|
{
|
|
172
189
|
errorType: "date",
|
|
173
|
-
|
|
190
|
+
example: "2025-05-16T21:13:04.123Z",
|
|
191
|
+
title: "Date"
|
|
174
192
|
}
|
|
175
193
|
)
|
|
176
194
|
).Decode((value) => {
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
return /* @__PURE__ */ new Date(value ? 1 : 0);
|
|
180
|
-
}
|
|
181
|
-
return new Date(value);
|
|
195
|
+
if (value === null || typeof value === "boolean") {
|
|
196
|
+
return /* @__PURE__ */ new Date(value ? 1 : 0);
|
|
182
197
|
}
|
|
183
|
-
return value;
|
|
184
|
-
}).Encode((value) => new Date(value));
|
|
185
|
-
symbol = import_typebox.Type.Symbol(
|
|
198
|
+
return new Date(value);
|
|
199
|
+
}).Encode((value) => new Date(value).toISOString());
|
|
200
|
+
symbol = import_typebox.Type.Symbol({
|
|
201
|
+
title: "Symbol"
|
|
202
|
+
});
|
|
186
203
|
nullish = import_typebox.Type.Union([import_typebox.Type.Void(), import_typebox.Type.Null(), import_typebox.Type.Undefined()], {
|
|
187
|
-
errorType: "nullish"
|
|
204
|
+
errorType: "nullish",
|
|
205
|
+
type: "null",
|
|
206
|
+
example: "null",
|
|
207
|
+
title: "Nullish"
|
|
208
|
+
});
|
|
209
|
+
void = import_typebox.Type.Void({
|
|
210
|
+
type: "null",
|
|
211
|
+
example: "void",
|
|
212
|
+
title: "Void"
|
|
188
213
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
214
|
+
null = import_typebox.Type.Null({
|
|
215
|
+
type: "null",
|
|
216
|
+
example: "null",
|
|
217
|
+
title: "Null"
|
|
218
|
+
});
|
|
219
|
+
undefined = import_typebox.Type.Undefined({
|
|
220
|
+
type: "null",
|
|
221
|
+
example: "undefined",
|
|
222
|
+
title: "Undefined"
|
|
223
|
+
});
|
|
224
|
+
any = import_typebox.Type.Any({
|
|
225
|
+
type: "object",
|
|
226
|
+
example: "any",
|
|
227
|
+
title: "Any"
|
|
228
|
+
});
|
|
229
|
+
unknown = import_typebox.Type.Unknown({
|
|
230
|
+
type: "object",
|
|
231
|
+
example: "unknown",
|
|
232
|
+
title: "Unknown"
|
|
233
|
+
});
|
|
234
|
+
never = import_typebox.Type.Never({
|
|
235
|
+
type: "null",
|
|
236
|
+
example: "never",
|
|
237
|
+
title: "Never"
|
|
238
|
+
});
|
|
239
|
+
binary = import_typebox.Type.Transform(
|
|
240
|
+
import_typebox.Type.String({
|
|
241
|
+
errorType: "binary",
|
|
242
|
+
format: "binary",
|
|
243
|
+
example: "a utf-8 encodable string",
|
|
244
|
+
title: "Binary"
|
|
245
|
+
})
|
|
246
|
+
).Decode(Buffer.from).Encode((value) => value.toString());
|
|
247
|
+
file = (name, type) => import_typebox.Type.Transform(
|
|
248
|
+
import_typebox.Type.String({
|
|
249
|
+
errorType: "binary",
|
|
250
|
+
format: "binary",
|
|
251
|
+
contentMediaType: type,
|
|
252
|
+
example: "a utf-8 encodable string",
|
|
253
|
+
title: "File"
|
|
254
|
+
})
|
|
255
|
+
).Decode((value) => new import_common.InMemoryFile(value, name, { type })).Encode((value) => value.content);
|
|
195
256
|
/**
|
|
196
257
|
* Extracts the error type of a schema for error messages.
|
|
197
258
|
*
|
|
@@ -221,12 +282,12 @@ var TypeboxSchemaValidator = class {
|
|
|
221
282
|
* @returns {TResolve<T>} The resolved schema.
|
|
222
283
|
*/
|
|
223
284
|
schemify(schema) {
|
|
224
|
-
if (typeof schema === "string" || typeof schema === "number" || typeof schema === "boolean") {
|
|
225
|
-
return import_typebox.Type.Literal(schema);
|
|
226
|
-
}
|
|
227
285
|
if (import_typebox.KindGuard.IsSchema(schema) || schema instanceof import_compiler.TypeCheck) {
|
|
228
286
|
return schema;
|
|
229
287
|
}
|
|
288
|
+
if (typeof schema === "string" || typeof schema === "number" || typeof schema === "boolean") {
|
|
289
|
+
return import_typebox.Type.Literal(schema);
|
|
290
|
+
}
|
|
230
291
|
const newSchema = {};
|
|
231
292
|
Object.getOwnPropertyNames(schema).forEach((key) => {
|
|
232
293
|
if (import_typebox.KindGuard.IsSchema(schema[key])) {
|
|
@@ -335,6 +396,15 @@ var TypeboxSchemaValidator = class {
|
|
|
335
396
|
isSchema(value) {
|
|
336
397
|
return import_typebox.KindGuard.IsSchema(value);
|
|
337
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Check if a value is an instance of a TypeBox schema.
|
|
401
|
+
* @param {object} value - The value to check.
|
|
402
|
+
* @param {TCatchall} type - The schema to check against.
|
|
403
|
+
* @returns {boolean} True if the value is an instance of the schema.
|
|
404
|
+
*/
|
|
405
|
+
isInstanceOf(value, type) {
|
|
406
|
+
return typeof value === "object" && value != null && import_typebox.Kind in value && value[import_typebox.Kind] === type[import_typebox.Kind];
|
|
407
|
+
}
|
|
338
408
|
/**
|
|
339
409
|
* Validate a value against a schema.
|
|
340
410
|
*
|
|
@@ -408,21 +478,38 @@ var TypeboxSchemaValidator = class {
|
|
|
408
478
|
* @returns {SchemaObject} The OpenAPI schema object.
|
|
409
479
|
*/
|
|
410
480
|
openapi(schema) {
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
|
|
481
|
+
let schemified = this.schemify(schema);
|
|
482
|
+
if (import_typebox.KindGuard.IsDate(schemified)) {
|
|
483
|
+
schemified = import_typebox.Type.String({
|
|
484
|
+
format: "date-time"
|
|
485
|
+
});
|
|
414
486
|
}
|
|
415
487
|
const newSchema = Object.assign({}, schemified);
|
|
416
488
|
if (Object.hasOwn(newSchema, "properties")) {
|
|
417
|
-
newSchema.properties = { ...schemified.properties };
|
|
418
489
|
if (newSchema.properties) {
|
|
419
|
-
Object.entries(
|
|
490
|
+
Object.entries({ ...schemified.properties }).forEach(([key, value]) => {
|
|
420
491
|
if (import_typebox.KindGuard.IsSchema(value) && newSchema.properties) {
|
|
421
492
|
newSchema.properties[key] = this.openapi(value);
|
|
422
493
|
}
|
|
423
494
|
});
|
|
424
495
|
}
|
|
425
496
|
}
|
|
497
|
+
if (Object.hasOwn(newSchema, "items")) {
|
|
498
|
+
newSchema.items = this.openapi(newSchema.items);
|
|
499
|
+
}
|
|
500
|
+
if (Array.isArray(newSchema.anyOf)) {
|
|
501
|
+
newSchema.anyOf = newSchema.anyOf.map(
|
|
502
|
+
(item) => this.openapi(item)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
if (Array.isArray(newSchema.oneOf)) {
|
|
506
|
+
newSchema.oneOf = newSchema.oneOf.map(
|
|
507
|
+
(item) => this.openapi(item)
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
if ("errorType" in newSchema) {
|
|
511
|
+
delete newSchema["errorType"];
|
|
512
|
+
}
|
|
426
513
|
return newSchema;
|
|
427
514
|
}
|
|
428
515
|
};
|
|
@@ -446,6 +533,8 @@ var undefined_ = StaticSchemaValidator.undefined;
|
|
|
446
533
|
var any = StaticSchemaValidator.any;
|
|
447
534
|
var unknown = StaticSchemaValidator.unknown;
|
|
448
535
|
var never = StaticSchemaValidator.never;
|
|
536
|
+
var binary = StaticSchemaValidator.binary;
|
|
537
|
+
var file = StaticSchemaValidator.file;
|
|
449
538
|
var schemify = StaticSchemaValidator.schemify.bind(
|
|
450
539
|
StaticSchemaValidator
|
|
451
540
|
);
|
|
@@ -481,10 +570,12 @@ var openapi = StaticSchemaValidator.openapi.bind(
|
|
|
481
570
|
any,
|
|
482
571
|
array,
|
|
483
572
|
bigint,
|
|
573
|
+
binary,
|
|
484
574
|
boolean,
|
|
485
575
|
date,
|
|
486
576
|
email,
|
|
487
577
|
enum_,
|
|
578
|
+
file,
|
|
488
579
|
function_,
|
|
489
580
|
isSchema,
|
|
490
581
|
literal,
|