@sinclair/typebox 0.28.10 → 0.28.12
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/package.json +2 -2
- package/readme.md +17 -3
- package/typebox.d.ts +1 -1
- package/typebox.js +8 -0
- package/value/check.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.12",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"chai": "^4.3.6",
|
|
43
43
|
"mocha": "^9.2.2",
|
|
44
44
|
"prettier": "^2.7.1",
|
|
45
|
-
"typescript": "^5.0.
|
|
45
|
+
"typescript": "^5.0.4"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/readme.md
CHANGED
|
@@ -109,6 +109,7 @@ License MIT
|
|
|
109
109
|
- [Formats](#typesystem-formats)
|
|
110
110
|
- [Policies](#typesystem-policies)
|
|
111
111
|
- [Workbench](#workbench)
|
|
112
|
+
- [Ecosystem](#ecosystem)
|
|
112
113
|
- [Benchmark](#benchmark)
|
|
113
114
|
- [Compile](#benchmark-compile)
|
|
114
115
|
- [Validate](#benchmark-validate)
|
|
@@ -1277,7 +1278,7 @@ The TypeCompiler is provided as an optional import.
|
|
|
1277
1278
|
import { TypeCompiler } from '@sinclair/typebox/compiler'
|
|
1278
1279
|
```
|
|
1279
1280
|
|
|
1280
|
-
Use the `Compile(...)` function to compile a type.
|
|
1281
|
+
Use the `Compile(...)` function to compile a type. Note that compilation is an expensive operation that should typically be performed once per type during application start up. TypeBox does not cache previously compiled types, so applications are expected to hold references to each compiled type for the lifetime of the application.
|
|
1281
1282
|
|
|
1282
1283
|
```typescript
|
|
1283
1284
|
const C = TypeCompiler.Compile(Type.Object({ // const C: TypeCheck<TObject<{
|
|
@@ -1419,16 +1420,29 @@ TypeSystem.AllowNaN = true
|
|
|
1419
1420
|
|
|
1420
1421
|
## Workbench
|
|
1421
1422
|
|
|
1422
|
-
TypeBox offers a web based code generation tool that can be used to
|
|
1423
|
+
TypeBox offers a small web based code generation tool that can be used to convert TypeScript types into TypeBox type definitions as well as a variety of other formats.
|
|
1423
1424
|
|
|
1424
1425
|
[Workbench Link Here](https://sinclairzx81.github.io/typebox-workbench/)
|
|
1425
1426
|
|
|
1426
1427
|
<div align='center'>
|
|
1427
|
-
|
|
1428
|
+
|
|
1428
1429
|
<a href="https://sinclairzx81.github.io/typebox-workbench/"><img src="https://github.com/sinclairzx81/typebox/blob/master/workbench.png?raw=true" /></a>
|
|
1429
1430
|
|
|
1430
1431
|
</div>
|
|
1431
1432
|
|
|
1433
|
+
<a name='ecosystem'></a>
|
|
1434
|
+
|
|
1435
|
+
## Ecosystem
|
|
1436
|
+
|
|
1437
|
+
The following is a list of community packages that provide general tooling and framework support for TypeBox.
|
|
1438
|
+
|
|
1439
|
+
| Package | Description |
|
|
1440
|
+
| ------------- | ------------- |
|
|
1441
|
+
| [elysia](https://github.com/elysiajs/elysia) | Fast and friendly Bun web framework |
|
|
1442
|
+
| [fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox) | Fastify TypeBox integration with the Fastify Type Provider |
|
|
1443
|
+
| [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
|
|
1444
|
+
| [ts2typebox](https://github.com/xddq/ts2typebox) | Cli tool to generate TypeBox JSON schemas based on your Typescript types |
|
|
1445
|
+
|
|
1432
1446
|
<a name='benchmark'></a>
|
|
1433
1447
|
|
|
1434
1448
|
## Benchmark
|
package/typebox.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ export interface TEnumOption<T> {
|
|
|
132
132
|
export interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
|
|
133
133
|
[Kind]: 'Union';
|
|
134
134
|
static: T[keyof T];
|
|
135
|
-
anyOf: TLiteral<
|
|
135
|
+
anyOf: TLiteral<T[keyof T]>[];
|
|
136
136
|
}
|
|
137
137
|
export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = (Static<L> extends Static<R> ? T : U) extends infer O ? UnionToTuple<O> extends [infer X, infer Y] ? TUnion<[AssertType<X>, AssertType<Y>]> : AssertType<O> : never;
|
|
138
138
|
export type TExcludeTemplateLiteralResult<T extends string> = UnionType<AssertRest<UnionToTuple<{
|
package/typebox.js
CHANGED
|
@@ -621,6 +621,14 @@ var ExtendsUndefined;
|
|
|
621
621
|
function Check(schema) {
|
|
622
622
|
if (schema[exports.Kind] === 'Undefined')
|
|
623
623
|
return true;
|
|
624
|
+
if (schema[exports.Kind] === 'Not') {
|
|
625
|
+
const not = schema;
|
|
626
|
+
return Check(not.allOf[1]);
|
|
627
|
+
}
|
|
628
|
+
if (schema[exports.Kind] === 'Intersect') {
|
|
629
|
+
const intersect = schema;
|
|
630
|
+
return intersect.allOf.every((schema) => Check(schema));
|
|
631
|
+
}
|
|
624
632
|
if (schema[exports.Kind] === 'Union') {
|
|
625
633
|
const union = schema;
|
|
626
634
|
return union.anyOf.some((schema) => Check(schema));
|
package/value/check.js
CHANGED
|
@@ -254,8 +254,8 @@ var ValueCheck;
|
|
|
254
254
|
if (!Visit(property, references, value[knownKey])) {
|
|
255
255
|
return false;
|
|
256
256
|
}
|
|
257
|
-
if (Types.ExtendsUndefined.Check(property)) {
|
|
258
|
-
return
|
|
257
|
+
if (Types.ExtendsUndefined.Check(property) && !(knownKey in value)) {
|
|
258
|
+
return false;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else {
|