@sinclair/typebox 0.32.19 → 0.32.21
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/import/type/composite/composite.d.mts +3 -3
- package/build/import/type/composite/composite.mjs +6 -6
- package/build/import/value/convert/convert.mjs +2 -4
- package/build/import/value/delta/delta.d.mts +17 -23
- package/build/import/value/delta/delta.mjs +17 -17
- package/build/require/type/composite/composite.d.ts +3 -3
- package/build/require/type/composite/composite.js +6 -6
- package/build/require/value/convert/convert.js +2 -4
- package/build/require/value/delta/delta.d.ts +17 -23
- package/package.json +1 -1
- package/readme.md +1 -0
|
@@ -6,9 +6,9 @@ import { type TKeyOfPropertyKeys } from '../keyof/index.mjs';
|
|
|
6
6
|
import { type TNever } from '../never/index.mjs';
|
|
7
7
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
8
8
|
import { TSetDistinct } from '../sets/index.mjs';
|
|
9
|
-
type TCompositeKeys<T extends TSchema[], Acc extends PropertyKey[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeKeys<R,
|
|
10
|
-
type TFilterNever<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? Acc : TFilterNever<R, [...Acc, L]> : Acc);
|
|
11
|
-
type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeProperty<R, K,
|
|
9
|
+
type TCompositeKeys<T extends TSchema[], Acc extends PropertyKey[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeKeys<R, [...Acc, ...TKeyOfPropertyKeys<L>]> : TSetDistinct<Acc>);
|
|
10
|
+
type TFilterNever<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFilterNever<R, [...Acc]> : TFilterNever<R, [...Acc, L]> : Acc);
|
|
11
|
+
type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeProperty<R, K, [...Acc, ...TIndexFromPropertyKeys<L, [K]>]> : TFilterNever<Acc>);
|
|
12
12
|
type TCompositeProperties<T extends TSchema[], K extends PropertyKey[], Acc = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TCompositeProperties<T, R, Acc & {
|
|
13
13
|
[_ in L]: TIntersectEvaluated<TCompositeProperty<T, L>>;
|
|
14
14
|
}> : Acc);
|
|
@@ -9,9 +9,9 @@ import { SetDistinct } from '../sets/index.mjs';
|
|
|
9
9
|
import { IsNever } from '../guard/type.mjs';
|
|
10
10
|
// prettier-ignore
|
|
11
11
|
function CompositeKeys(T) {
|
|
12
|
-
return T.reduce((Acc, L) => {
|
|
13
|
-
return
|
|
14
|
-
}, []);
|
|
12
|
+
return SetDistinct(T.reduce((Acc, L) => {
|
|
13
|
+
return ([...Acc, ...KeyOfPropertyKeys(L)]);
|
|
14
|
+
}, []));
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function FilterNever(T) {
|
|
@@ -19,9 +19,9 @@ function FilterNever(T) {
|
|
|
19
19
|
}
|
|
20
20
|
// prettier-ignore
|
|
21
21
|
function CompositeProperty(T, K) {
|
|
22
|
-
return T.reduce((Acc, L) => {
|
|
23
|
-
return
|
|
24
|
-
}, []);
|
|
22
|
+
return FilterNever(T.reduce((Acc, L) => {
|
|
23
|
+
return [...Acc, ...IndexFromPropertyKeys(L, [K])];
|
|
24
|
+
}, []));
|
|
25
25
|
}
|
|
26
26
|
// prettier-ignore
|
|
27
27
|
function CompositeProperties(T, K) {
|
|
@@ -110,10 +110,8 @@ function Default(value) {
|
|
|
110
110
|
// Convert
|
|
111
111
|
// ------------------------------------------------------------------
|
|
112
112
|
function FromArray(schema, references, value) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
return value;
|
|
113
|
+
const elements = IsArray(value) ? value : [value];
|
|
114
|
+
return elements.map((element) => Visit(schema.items, references, element));
|
|
117
115
|
}
|
|
118
116
|
function FromBigInt(schema, references, value) {
|
|
119
117
|
return TryConvertBigInt(value);
|
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
import type { Static } from '../../type/static/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
3
|
+
import { type TLiteral } from '../../type/literal/index.mjs';
|
|
4
|
+
import { type TObject } from '../../type/object/index.mjs';
|
|
5
|
+
import { type TString } from '../../type/string/index.mjs';
|
|
6
|
+
import { type TUnknown } from '../../type/unknown/index.mjs';
|
|
7
|
+
import { type TUnion } from '../../type/union/index.mjs';
|
|
3
8
|
export type Insert = Static<typeof Insert>;
|
|
4
|
-
export declare const Insert:
|
|
5
|
-
type:
|
|
6
|
-
path:
|
|
7
|
-
value:
|
|
9
|
+
export declare const Insert: TObject<{
|
|
10
|
+
type: TLiteral<'insert'>;
|
|
11
|
+
path: TString;
|
|
12
|
+
value: TUnknown;
|
|
8
13
|
}>;
|
|
9
14
|
export type Update = Static<typeof Update>;
|
|
10
|
-
export declare const Update:
|
|
11
|
-
type:
|
|
12
|
-
path:
|
|
13
|
-
value:
|
|
15
|
+
export declare const Update: TObject<{
|
|
16
|
+
type: TLiteral<'update'>;
|
|
17
|
+
path: TString;
|
|
18
|
+
value: TUnknown;
|
|
14
19
|
}>;
|
|
15
20
|
export type Delete = Static<typeof Delete>;
|
|
16
|
-
export declare const Delete:
|
|
17
|
-
type:
|
|
18
|
-
path:
|
|
21
|
+
export declare const Delete: TObject<{
|
|
22
|
+
type: TLiteral<'delete'>;
|
|
23
|
+
path: TString;
|
|
19
24
|
}>;
|
|
20
25
|
export type Edit = Static<typeof Edit>;
|
|
21
|
-
export declare const Edit:
|
|
22
|
-
type: import("src/type/literal/literal.mjs").TLiteral<"insert">;
|
|
23
|
-
path: import("src/type/string/string.mjs").TString;
|
|
24
|
-
value: import("src/type/unknown/unknown.mjs").TUnknown;
|
|
25
|
-
}>, import("src/type/object/object.mjs").TObject<{
|
|
26
|
-
type: import("src/type/literal/literal.mjs").TLiteral<"update">;
|
|
27
|
-
path: import("src/type/string/string.mjs").TString;
|
|
28
|
-
value: import("src/type/unknown/unknown.mjs").TUnknown;
|
|
29
|
-
}>, import("src/type/object/object.mjs").TObject<{
|
|
30
|
-
type: import("src/type/literal/literal.mjs").TLiteral<"delete">;
|
|
31
|
-
path: import("src/type/string/string.mjs").TString;
|
|
32
|
-
}>]>;
|
|
26
|
+
export declare const Edit: TUnion<[typeof Insert, typeof Update, typeof Delete]>;
|
|
33
27
|
export declare class ValueDeltaError extends TypeBoxError {
|
|
34
28
|
readonly value: unknown;
|
|
35
29
|
constructor(value: unknown, message: string);
|
|
@@ -2,26 +2,26 @@ import { IsStandardObject, IsArray, IsTypedArray, IsValueType, IsSymbol, IsUndef
|
|
|
2
2
|
import { ValuePointer } from '../pointer/index.mjs';
|
|
3
3
|
import { Clone } from '../clone/index.mjs';
|
|
4
4
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
5
|
-
import { Literal
|
|
6
|
-
import { Object
|
|
7
|
-
import { String
|
|
8
|
-
import { Unknown
|
|
9
|
-
import { Union
|
|
10
|
-
export const Insert =
|
|
11
|
-
type:
|
|
12
|
-
path:
|
|
13
|
-
value:
|
|
5
|
+
import { Literal } from '../../type/literal/index.mjs';
|
|
6
|
+
import { Object } from '../../type/object/index.mjs';
|
|
7
|
+
import { String } from '../../type/string/index.mjs';
|
|
8
|
+
import { Unknown } from '../../type/unknown/index.mjs';
|
|
9
|
+
import { Union } from '../../type/union/index.mjs';
|
|
10
|
+
export const Insert = Object({
|
|
11
|
+
type: Literal('insert'),
|
|
12
|
+
path: String(),
|
|
13
|
+
value: Unknown(),
|
|
14
14
|
});
|
|
15
|
-
export const Update =
|
|
16
|
-
type:
|
|
17
|
-
path:
|
|
18
|
-
value:
|
|
15
|
+
export const Update = Object({
|
|
16
|
+
type: Literal('update'),
|
|
17
|
+
path: String(),
|
|
18
|
+
value: Unknown(),
|
|
19
19
|
});
|
|
20
|
-
export const Delete =
|
|
21
|
-
type:
|
|
22
|
-
path:
|
|
20
|
+
export const Delete = Object({
|
|
21
|
+
type: Literal('delete'),
|
|
22
|
+
path: String(),
|
|
23
23
|
});
|
|
24
|
-
export const Edit =
|
|
24
|
+
export const Edit = Union([Insert, Update, Delete]);
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
26
|
// Errors
|
|
27
27
|
// ------------------------------------------------------------------
|
|
@@ -6,9 +6,9 @@ import { type TKeyOfPropertyKeys } from '../keyof/index';
|
|
|
6
6
|
import { type TNever } from '../never/index';
|
|
7
7
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index';
|
|
8
8
|
import { TSetDistinct } from '../sets/index';
|
|
9
|
-
type TCompositeKeys<T extends TSchema[], Acc extends PropertyKey[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeKeys<R,
|
|
10
|
-
type TFilterNever<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? Acc : TFilterNever<R, [...Acc, L]> : Acc);
|
|
11
|
-
type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeProperty<R, K,
|
|
9
|
+
type TCompositeKeys<T extends TSchema[], Acc extends PropertyKey[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeKeys<R, [...Acc, ...TKeyOfPropertyKeys<L>]> : TSetDistinct<Acc>);
|
|
10
|
+
type TFilterNever<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFilterNever<R, [...Acc]> : TFilterNever<R, [...Acc, L]> : Acc);
|
|
11
|
+
type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TCompositeProperty<R, K, [...Acc, ...TIndexFromPropertyKeys<L, [K]>]> : TFilterNever<Acc>);
|
|
12
12
|
type TCompositeProperties<T extends TSchema[], K extends PropertyKey[], Acc = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TCompositeProperties<T, R, Acc & {
|
|
13
13
|
[_ in L]: TIntersectEvaluated<TCompositeProperty<T, L>>;
|
|
14
14
|
}> : Acc);
|
|
@@ -13,9 +13,9 @@ const index_5 = require("../sets/index");
|
|
|
13
13
|
const type_1 = require("../guard/type");
|
|
14
14
|
// prettier-ignore
|
|
15
15
|
function CompositeKeys(T) {
|
|
16
|
-
return T.reduce((Acc, L) => {
|
|
17
|
-
return (
|
|
18
|
-
}, []);
|
|
16
|
+
return (0, index_5.SetDistinct)(T.reduce((Acc, L) => {
|
|
17
|
+
return ([...Acc, ...(0, index_3.KeyOfPropertyKeys)(L)]);
|
|
18
|
+
}, []));
|
|
19
19
|
}
|
|
20
20
|
// prettier-ignore
|
|
21
21
|
function FilterNever(T) {
|
|
@@ -23,9 +23,9 @@ function FilterNever(T) {
|
|
|
23
23
|
}
|
|
24
24
|
// prettier-ignore
|
|
25
25
|
function CompositeProperty(T, K) {
|
|
26
|
-
return T.reduce((Acc, L) => {
|
|
27
|
-
return
|
|
28
|
-
}, []);
|
|
26
|
+
return FilterNever(T.reduce((Acc, L) => {
|
|
27
|
+
return [...Acc, ...(0, index_2.IndexFromPropertyKeys)(L, [K])];
|
|
28
|
+
}, []));
|
|
29
29
|
}
|
|
30
30
|
// prettier-ignore
|
|
31
31
|
function CompositeProperties(T, K) {
|
|
@@ -114,10 +114,8 @@ function Default(value) {
|
|
|
114
114
|
// Convert
|
|
115
115
|
// ------------------------------------------------------------------
|
|
116
116
|
function FromArray(schema, references, value) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return value;
|
|
117
|
+
const elements = (0, index_5.IsArray)(value) ? value : [value];
|
|
118
|
+
return elements.map((element) => Visit(schema.items, references, element));
|
|
121
119
|
}
|
|
122
120
|
function FromBigInt(schema, references, value) {
|
|
123
121
|
return TryConvertBigInt(value);
|
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
import type { Static } from '../../type/static/index';
|
|
2
2
|
import { TypeBoxError } from '../../type/error/index';
|
|
3
|
+
import { type TLiteral } from '../../type/literal/index';
|
|
4
|
+
import { type TObject } from '../../type/object/index';
|
|
5
|
+
import { type TString } from '../../type/string/index';
|
|
6
|
+
import { type TUnknown } from '../../type/unknown/index';
|
|
7
|
+
import { type TUnion } from '../../type/union/index';
|
|
3
8
|
export type Insert = Static<typeof Insert>;
|
|
4
|
-
export declare const Insert:
|
|
5
|
-
type:
|
|
6
|
-
path:
|
|
7
|
-
value:
|
|
9
|
+
export declare const Insert: TObject<{
|
|
10
|
+
type: TLiteral<'insert'>;
|
|
11
|
+
path: TString;
|
|
12
|
+
value: TUnknown;
|
|
8
13
|
}>;
|
|
9
14
|
export type Update = Static<typeof Update>;
|
|
10
|
-
export declare const Update:
|
|
11
|
-
type:
|
|
12
|
-
path:
|
|
13
|
-
value:
|
|
15
|
+
export declare const Update: TObject<{
|
|
16
|
+
type: TLiteral<'update'>;
|
|
17
|
+
path: TString;
|
|
18
|
+
value: TUnknown;
|
|
14
19
|
}>;
|
|
15
20
|
export type Delete = Static<typeof Delete>;
|
|
16
|
-
export declare const Delete:
|
|
17
|
-
type:
|
|
18
|
-
path:
|
|
21
|
+
export declare const Delete: TObject<{
|
|
22
|
+
type: TLiteral<'delete'>;
|
|
23
|
+
path: TString;
|
|
19
24
|
}>;
|
|
20
25
|
export type Edit = Static<typeof Edit>;
|
|
21
|
-
export declare const Edit:
|
|
22
|
-
type: import("src/type/literal/literal").TLiteral<"insert">;
|
|
23
|
-
path: import("src/type/string/string").TString;
|
|
24
|
-
value: import("src/type/unknown/unknown").TUnknown;
|
|
25
|
-
}>, import("src/type/object/object").TObject<{
|
|
26
|
-
type: import("src/type/literal/literal").TLiteral<"update">;
|
|
27
|
-
path: import("src/type/string/string").TString;
|
|
28
|
-
value: import("src/type/unknown/unknown").TUnknown;
|
|
29
|
-
}>, import("src/type/object/object").TObject<{
|
|
30
|
-
type: import("src/type/literal/literal").TLiteral<"delete">;
|
|
31
|
-
path: import("src/type/string/string").TString;
|
|
32
|
-
}>]>;
|
|
26
|
+
export declare const Edit: TUnion<[typeof Insert, typeof Update, typeof Delete]>;
|
|
33
27
|
export declare class ValueDeltaError extends TypeBoxError {
|
|
34
28
|
readonly value: unknown;
|
|
35
29
|
constructor(value: unknown, message: string);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1693,6 +1693,7 @@ The following is a list of community packages that offer general tooling, extend
|
|
|
1693
1693
|
| [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
|
|
1694
1694
|
| [http-wizard](https://github.com/flodlc/http-wizard) | Type safe http client library for Fastify |
|
|
1695
1695
|
| [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
|
|
1696
|
+
| [prismabox](https://github.com/m1212e/prismabox) | Converts a prisma.schema to typebox schema matching the database models |
|
|
1696
1697
|
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
|
|
1697
1698
|
| [sveltekit-superforms](https://github.com/ciscoheat/sveltekit-superforms) | A comprehensive SvelteKit form library for server and client validation |
|
|
1698
1699
|
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|