typebox 1.2.15 → 1.2.17
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/build/type/engine/immutable/instantiate_remove.d.mts +1 -1
- package/build/type/engine/optional/instantiate_remove.d.mts +1 -1
- package/build/type/engine/readonly/instantiate_remove.d.mts +1 -1
- package/build/value/codec/from_array.mjs +1 -4
- package/build/value/codec/from_object.mjs +1 -4
- package/build/value/codec/from_record.mjs +2 -7
- package/build/value/codec/from_tuple.mjs +1 -4
- package/package.json +1 -1
- package/readme.md +2 -2
|
@@ -2,7 +2,7 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TImmutable } from '../../types/_immutable.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
type TRemoveImmutableOperation<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? Type : Type> = Result;
|
|
5
|
+
type TRemoveImmutableOperation<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? TRemoveImmutableOperation<Type> : Type> = Result;
|
|
6
6
|
export type TRemoveImmutableAction<Type extends TSchema, Result extends TSchema = TRemoveImmutableOperation<Type>> = Result;
|
|
7
7
|
export declare function RemoveImmutableAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveImmutableAction<Type>;
|
|
8
8
|
export type TRemoveImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveImmutableAction<InstantiateType>;
|
|
@@ -2,7 +2,7 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TOptional } from '../../types/_optional.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
type TRemoveOptionalOperation<Type extends TSchema, Result extends TSchema = Type extends TOptional<infer Type extends TSchema> ? Type : Type> = Result;
|
|
5
|
+
type TRemoveOptionalOperation<Type extends TSchema, Result extends TSchema = Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalOperation<Type> : Type> = Result;
|
|
6
6
|
export type TRemoveOptionalAction<Type extends TSchema, Result extends TSchema = TRemoveOptionalOperation<Type>> = Result;
|
|
7
7
|
export declare function RemoveOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveOptionalAction<Type>;
|
|
8
8
|
export type TRemoveOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveOptionalAction<InstantiateType>;
|
|
@@ -2,7 +2,7 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TReadonly } from '../../types/_readonly.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
type TRemoveReadonlyOperation<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? Type : Type> = Result;
|
|
5
|
+
type TRemoveReadonlyOperation<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? TRemoveReadonlyOperation<Type> : Type> = Result;
|
|
6
6
|
export type TRemoveReadonlyAction<Type extends TSchema, Result extends TSchema = TRemoveReadonlyOperation<Type>> = Result;
|
|
7
7
|
export declare function RemoveReadonlyAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveReadonlyAction<Type>;
|
|
8
8
|
export type TRemoveReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveReadonlyAction<InstantiateType>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Unreachable } from '../../system/unreachable/index.mjs';
|
|
3
2
|
import { Guard } from '../../guard/index.mjs';
|
|
4
3
|
import { FromType } from './from_type.mjs';
|
|
5
4
|
import { Callback } from './callback.mjs';
|
|
@@ -7,10 +6,8 @@ import { Callback } from './callback.mjs';
|
|
|
7
6
|
// Decode
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
function Decode(direction, context, type, value) {
|
|
10
|
-
// deno-coverage-ignore-start - unreachable | checked
|
|
11
9
|
if (!Guard.IsArray(value))
|
|
12
|
-
return
|
|
13
|
-
// deno-coverage-ignore-stop
|
|
10
|
+
return value;
|
|
14
11
|
for (let i = 0; i < value.length; i++) {
|
|
15
12
|
value[i] = FromType(direction, context, type.items, value[i]);
|
|
16
13
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Unreachable } from '../../system/unreachable/index.mjs';
|
|
3
2
|
import { Guard } from '../../guard/index.mjs';
|
|
4
3
|
import { FromType } from './from_type.mjs';
|
|
5
4
|
import { Callback } from './callback.mjs';
|
|
@@ -8,10 +7,8 @@ import { IsOptionalUndefined } from '../shared/optional_undefined.mjs';
|
|
|
8
7
|
// Decode
|
|
9
8
|
// ------------------------------------------------------------------
|
|
10
9
|
function Decode(direction, context, type, value) {
|
|
11
|
-
// deno-coverage-ignore-start - unreachable | checked
|
|
12
10
|
if (!Guard.IsObjectNotArray(value))
|
|
13
|
-
return
|
|
14
|
-
// deno-coverage-ignore-stop
|
|
11
|
+
return value;
|
|
15
12
|
for (const key of Guard.Keys(type.properties)) {
|
|
16
13
|
// Ignore for non-present or optional-undefined
|
|
17
14
|
if (!Guard.HasPropertyKey(value, key) || IsOptionalUndefined(type.properties[key], key, value))
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Unreachable } from '../../system/unreachable/index.mjs';
|
|
3
2
|
import { Guard } from '../../guard/index.mjs';
|
|
4
3
|
import { RecordPattern, RecordValue } from '../../type/index.mjs';
|
|
5
4
|
import { FromType } from './from_type.mjs';
|
|
@@ -8,16 +7,12 @@ import { Callback } from './callback.mjs';
|
|
|
8
7
|
// Decode
|
|
9
8
|
// ------------------------------------------------------------------
|
|
10
9
|
function Decode(direction, context, type, value) {
|
|
11
|
-
// deno-coverage-ignore-start - unreachable | checked
|
|
12
10
|
if (!Guard.IsObjectNotArray(value))
|
|
13
|
-
return
|
|
14
|
-
// deno-coverage-ignore-stop
|
|
11
|
+
return value;
|
|
15
12
|
const regexp = new RegExp(RecordPattern(type));
|
|
16
13
|
for (const key of Guard.Keys(value)) {
|
|
17
|
-
// deno-coverage-ignore-start - unreachable | checked
|
|
18
14
|
if (!regexp.test(key))
|
|
19
|
-
|
|
20
|
-
// deno-coverage-ignore-stop
|
|
15
|
+
continue;
|
|
21
16
|
value[key] = FromType(direction, context, RecordValue(type), value[key]);
|
|
22
17
|
}
|
|
23
18
|
return Callback(direction, context, type, value);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Unreachable } from '../../system/unreachable/index.mjs';
|
|
3
2
|
import { Guard } from '../../guard/index.mjs';
|
|
4
3
|
import { FromType } from './from_type.mjs';
|
|
5
4
|
import { Callback } from './callback.mjs';
|
|
@@ -7,10 +6,8 @@ import { Callback } from './callback.mjs';
|
|
|
7
6
|
// Decode
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
function Decode(direction, context, type, value) {
|
|
10
|
-
// deno-coverage-ignore-start - unreachable | checked
|
|
11
9
|
if (!Guard.IsArray(value))
|
|
12
|
-
return
|
|
13
|
-
// deno-coverage-ignore-stop
|
|
10
|
+
return value;
|
|
14
11
|
for (let i = 0; i < Math.min(type.items.length, value.length); i++) {
|
|
15
12
|
value[i] = FromType(direction, context, type.items[i], value[i]);
|
|
16
13
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -50,7 +50,7 @@ type T = Type.Static<typeof T> // type T = {
|
|
|
50
50
|
|
|
51
51
|
[Documentation](https://sinclairzx81.github.io/typebox/)
|
|
52
52
|
|
|
53
|
-
TypeBox is a runtime type system 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
|
|
53
|
+
TypeBox is a runtime type system 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 checked using standard JSON Schema validation.
|
|
54
54
|
|
|
55
55
|
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.
|
|
56
56
|
|
|
@@ -111,7 +111,7 @@ type User = Type.Static<typeof User> // type User = {
|
|
|
111
111
|
|
|
112
112
|
## Script
|
|
113
113
|
|
|
114
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdAGUAxlGBgYACjwC5eAJS9G3VWvXdqdOADkAhiFQBnMHpGpKIiADsj8ALJ6YACzgBeREWFiJ0gAaUcHCEaHAAaqgiMNAATO5wAN5wZABccNYAriDEqFAANHBIaZnZuXAAvoHBROGR0VAAzPEAogBuegA2GU6oADwRUbFwAGSJcABexVk5UBUAfFUh6AP1ACwt7V09-XXQTaNJAO5TpbPlC35KygAiqGjWACao1vD6hiZmFla28En2xq5yvF+KhvOJJFIknIBI4XBUCn4gosahFYKgyPEElUgpAjMAYMAbGkVtBVnlseloCBOsTdo1yUEghlWrTBlAYlVKkElnAAOKoHCoGBQJCYimtXIE8xGWlosgAbQAugzGcBHsBpScZkrOcjQrDcsBOmLGXADMRgM8YKy1iqgg9gBgMBkjKgbaS7XATJEMh09FB3VBVrruTV-kZXB4saaAOYCwzCop8+NCkWe6kwQ00uAG8SdXWXLT0ABKGReoHQxdQGA6dUJ1ko4ecAjA2DQsEtRgEccFiZbbclnYEEo70oE+NQIC7rYg7YJxhbEDxBJs-dng4XZEbALXc6HPYTIt3G67I6lC4nU+PHYX1ipnWv867W6bj-3Kb7M73C7PGovmavL8TwEZk303bcIzArsMyzDooIEB0nRdUEgJvZ8IObVCnwEGC8zgrCh3NS0Xngl8dwIhdcKNfCBzQgRvREX1-VIos4CEGAnA1OAAElrAwXJnnMShnWsKJ6zgKBnieKApHeZw0hBYQOKlXolggDAcwBOYFESKo5O7D8j1-aV5QABkVRdl3rAQtyCfSD1TJBh0HEzzIEO8oGpODbLgezDKc4zjDMizQJ8-SqIfRDnVdGy9J3CK4KIq1Yrs+Kejw+i0EYv0oFi8ogA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdACpejbuImTu1OnAByAQxCoAzmAUBjVJQB2S1eq1wAsgpgALOAG9KcOKjKRYcDRB0r4ANVQaY0AExwALyIRAIA8sQAVj4wABRWcGQAXKGCcgCuIMSoUHEAlAA0cEip-KgCmdm5BXAAvvm29o7Q8K7uXrHQAMzBaRUAogBuCgA2GWaoceUCAJI6MLkqsXEA2t6+AcUzkTG+CXAAXmVhVTl5+fX5ALr5jXYOTm1uHnAbflAALH0zw2MTi2mYXmiygy326y6UG62zCuxWiQA7id0llzrUGrdGnUZPQACKoNA6AAmqAW8n0ak02nar28sAcPzh0QRTUgKmAMGAblSpgsAne0E+hSaOmgIDGvLM5gFUJhTQyQyl-MFUH8lAalFp8AA4qgcKgYFAkEzBPD9jY7ENclytCoURUAIJQKAKJBxemLMhFJrAEnAO0OgTO13umZnGp3DWNbUmSZQYBjU0Vc3xS1wJTEYBkmDKmWq4VNYnADAYDLLPOyzZfEV2NQ+DKjBRQSsF6Nal7wYyqSwhHYsi1NADm+uURtKcD1BvHtbgEtBidGytyi-bogAShkFqB0OvUBhRrFuTpKN2VDKwNg0LBsyoBCPp8aBJeINeuaoBNab3aBJzUCA7xfN9b2fCAOS5NxnyvG0QLIU8eyg18YI-B8xyfIDkLvL9bQ-P8AMQ4CPzFKAJVGAjMIEOCzwvaCbxQ0dDXQ2j3ywmCfzwwDmJAxVyLou8qIQjC+IEecVzGXiWIEYtS3LCohMkgTzwkkDRITcT5JAzNswWZSP0UmikOE1TF10u96w0Rtm1MyjcTgABlGAzADOB5gwXIyS0Sgyx0XxjzgKAyVJPJlHPIMHKcjQAB5CDQCAMBMHsAD5LnTEKZVQxikE-NjVFWAAGa5QPA48bLsNL7wY8dsu-XKCoEYjSNKucEIyqrsIDWrCp4uCyoQ4zxOkstlia8r+rIrScxGvr4xM8zLKgGy6iAA)
|
|
114
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdAGUAxlGBgYACjwC5eAJS9G3VWvXdqdOADkAhiFQBnMHpGpKIiADsj8ALJ6YACzgBeREWFiJ0gAaUcHCEaHAAaqgiMNAATO5wAN5wZABccNYAriDEqFAANHBIaZnZuXAAvoHBROGR0VAAzPEAogBuegA2GU6oADwRUbFwAGSJcABexVk5UBUAfFUh6AP1ACwt7V09-XXQTaNJAO5TpbPlC35KygAiqGjWACao1vD6hiZmFla28En2xq5yvF+KhvOJJFIknIBI4XBUCn4gosahFYKgyPEElUgpAjMAYMAbGkVtBVnlseloCBOsTdo1yUEghlWrTBlAYlVKkElnAAOKoHCoGBQJCYimtXIE8xGWlosgAbQAugzGcBHsBpScZkrOcjQrDcsBOmLGXADMRgM8YKy1iqgg9gBgMBkjKgbaS7XATJEMh09FB3VBVrruTV-kZXB4saaAOYCwzCop8+NCkWe6kwQ00uAG8SdXWXLT0ABKGReoHQxdQGA6dUJ1ko4ecAjA2DQsEtRgEccFiZbbclnYEEo70oE+NQIC7rYg7YJxhbEDxBJs-dng4XZEbALXc6HPYTIt3G67I6lC4nU+PHYX1ipnWv867W6bj-3Kb7M73C7PGovmavL8TwEZk303bcIzArsMyzDooIEB0nRdUEgJvZ8IObVCnwEGC8zgrCh3NS0Xngl8dwIhdcKNfCBzQgRvREX1-VIos4CEGAnA1OAAElrAwXJnnMShnWsKJ6zgKBnieKApHeZw0hBYQOKlXolggDAcwBOYFESKo5O7D8j1-aV5QABkVRdl3rAQtyCfSD1TJBh0HEzzIEO8oGpODbLgezDKc4zjDMizQJ8-SqIfRDnVdGy9J3CK4KIq1Yrs+Kejw+i0EYv0oFi8ogA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdACpejbuImTu1OnAByAQxCoAzmAUBjVJQB2S1eq1wAsgpgALOAG9KcOKjKRYcDRB0r4ANVQaY0AExwALyIRAIA8sQAVj4wABRWcGQAXKGCcgCuIMSoUHEAlAA0cEip-KgCmdm5BXAAvvm29o7Q8K7uXrHQAMzBaRUAogBuCgA2GWaoceUCAJI6MLkqsXEA2t6+AcUzkTG+CXAAXmVhVTl5+fX5ALr5jXYOTm1uHnAbflAALH0zw2MTi2mYXmiygy326y6UG62zCuxWiQA7id0llzrUGrdGnUZPQACKoNA6AAmqAW8n0ak02nar28sAcPzh0QRTUgKmAMGAblSpgsAne0E+hSaOmgIDGvLM5gFUJhTQyQyl-MFUH8lAalFp8AA4qgcKgYFAkEzBPD9jY7ENclytCoURUAIJQKAKJBxemLMhFJrAEnAO0OgTO13umZnGp3DWNbUmSZQYBjU0Vc3xS1wJTEYBkmDKmWq4VNYnADAYDLLPOyzZfEV2NQ+DKjBRQSsF6Nal7wYyqSwhHYsi1NADm+uURtKcD1BvHtbgEtBidGytyi-bogAShkFqB0OvUBhRrFuTpKN2VDKwNg0LBsyoBCPp8aBJeINeuaoBNab3aBJzUCA7xfN9b2fCAOS5NxnyvG0QLIU8eyg18YI-B8xyfIDkLvL9bQ-P8AMQ4CPzFKAJVGAjMIEOCzwvaCbxQ0dDXQ2j3ywmCfzwwDmJAxVyLou8qIQjC+IEecVzGXiWIEYtS3LCohMkgTzwkkDRITcT5JAzNswWZSP0UmikOE1TF10u96w0Rtm1MyjcTgABlGAzADOB5gwXIyS0Sgyx0XxjzgKAyVJPJlHPIMHKcjQAB5CDQCAMBMHsAD5LnTEKZVQxikE-NjVFWAAGa5QPA48bLsNL7wY8dsu-XKCoEYjSNKucEIyqrsIDWrCp4uCyoQ4zxOkstlia8r+rIrScxGvr4xM8zLKgGy6iAA) | [Challenges](test/typescript/readme.md)
|
|
115
115
|
|
|
116
116
|
TypeBox includes a syntax engine that can transform TypeScript declarations into JSON Schema. The engine is a full syntactic frontend to Type.* and supports many advanced type-level constructs such as Conditional, Mapped, Indexed, Infer, Generics, Distributed types and more. This feature is implemented symmetrically at runtime and statically via TypeScript Template Literal types.
|
|
117
117
|
|