@sinclair/typebox 0.34.47 → 0.34.49
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.
|
@@ -220,7 +220,8 @@ var TypeCompiler;
|
|
|
220
220
|
if ((0, index_12.IsNumber)(schema.minItems))
|
|
221
221
|
yield `${value}.length >= ${schema.minItems}`;
|
|
222
222
|
const elementExpression = CreateExpression(schema.items, references, 'value');
|
|
223
|
-
yield `${value}.every((${parameter}) => ${elementExpression})
|
|
223
|
+
// yield `${value}.every((${parameter}) => ${elementExpression})` // issue: 1519
|
|
224
|
+
yield `((array) => { for(const ${parameter} of array) if(!(${elementExpression})) { return false }; return true; })(${value})`;
|
|
224
225
|
if ((0, type_1.IsSchema)(schema.contains) || (0, index_12.IsNumber)(schema.minContains) || (0, index_12.IsNumber)(schema.maxContains)) {
|
|
225
226
|
const containsSchema = (0, type_1.IsSchema)(schema.contains) ? schema.contains : (0, index_10.Never)();
|
|
226
227
|
const checkExpression = CreateExpression(containsSchema, references, 'value');
|
|
@@ -60,8 +60,9 @@ function FromArray(schema, references, value) {
|
|
|
60
60
|
if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
for (const element of value) {
|
|
64
|
+
if (!Visit(schema.items, references, element))
|
|
65
|
+
return false;
|
|
65
66
|
}
|
|
66
67
|
// prettier-ignore
|
|
67
68
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
@@ -213,7 +213,8 @@ export var TypeCompiler;
|
|
|
213
213
|
if (IsNumber(schema.minItems))
|
|
214
214
|
yield `${value}.length >= ${schema.minItems}`;
|
|
215
215
|
const elementExpression = CreateExpression(schema.items, references, 'value');
|
|
216
|
-
yield `${value}.every((${parameter}) => ${elementExpression})
|
|
216
|
+
// yield `${value}.every((${parameter}) => ${elementExpression})` // issue: 1519
|
|
217
|
+
yield `((array) => { for(const ${parameter} of array) if(!(${elementExpression})) { return false }; return true; })(${value})`;
|
|
217
218
|
if (IsSchema(schema.contains) || IsNumber(schema.minContains) || IsNumber(schema.maxContains)) {
|
|
218
219
|
const containsSchema = IsSchema(schema.contains) ? schema.contains : Never();
|
|
219
220
|
const checkExpression = CreateExpression(containsSchema, references, 'value');
|
|
@@ -54,8 +54,9 @@ function FromArray(schema, references, value) {
|
|
|
54
54
|
if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
for (const element of value) {
|
|
58
|
+
if (!Visit(schema.items, references, element))
|
|
59
|
+
return false;
|
|
59
60
|
}
|
|
60
61
|
// prettier-ignore
|
|
61
62
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.49",
|
|
4
4
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/sinclairzx81/typebox
|
|
15
|
+
"url": "https://github.com/sinclairzx81/sinclair-typebox"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "echo test"
|
package/readme.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<div align='center'>
|
|
2
2
|
|
|
3
|
-
<h1>TypeBox
|
|
3
|
+
<h1>Sinclair TypeBox</h1>
|
|
4
4
|
|
|
5
5
|
<p>Json Schema Type Builder with Static Type Resolution for TypeScript</p>
|
|
6
6
|
|
|
7
|
-
<img src="https://raw.githubusercontent.com/sinclairzx81/typebox
|
|
7
|
+
<img src="https://raw.githubusercontent.com/sinclairzx81/sinclair-typebox/refs/heads/main/typebox.png" />
|
|
8
8
|
|
|
9
9
|
<br />
|
|
10
10
|
<br />
|
|
@@ -16,14 +16,17 @@
|
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
<a name="Install"></a>
|
|
20
21
|
|
|
21
22
|
## Install
|
|
22
23
|
|
|
24
|
+
For the latest version use [TypeBox 1.x](https://github.com/sinclairzx81/typebox)
|
|
25
|
+
|
|
23
26
|
```bash
|
|
24
|
-
$ npm install @sinclair/typebox # TypeBox
|
|
27
|
+
$ npm install @sinclair/typebox # TypeBox 0.x - Long Term Support
|
|
25
28
|
|
|
26
|
-
$ npm install typebox # TypeBox
|
|
29
|
+
$ npm install typebox # TypeBox 1.x - Latest
|
|
27
30
|
```
|
|
28
31
|
|
|
29
32
|
## Example
|
|
@@ -48,13 +51,10 @@ type T = Static<typeof T> // type T = {
|
|
|
48
51
|
// }
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
|
|
52
54
|
<a name="Overview"></a>
|
|
53
55
|
|
|
54
56
|
## Overview
|
|
55
57
|
|
|
56
|
-
> ⚠️ TypeBox versions (pre-1.0) will continue active maintenance through 2026 and beyond. This repository services as the OIDC publishing environment for the `@sinclair/typebox` package scope on NPM. For TypeBox versions 1.0 and above, refer to https://github.com/sinclairzx81/typebox
|
|
57
|
-
|
|
58
58
|
TypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.
|
|
59
59
|
|
|
60
60
|
This library is designed to allow Json Schema to compose similar to how types compose within TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
|