@sinclair/typebox 0.32.20 → 0.32.22

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.
@@ -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, TSetDistinct<[...Acc, ...TKeyOfPropertyKeys<L>]>> : Acc);
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, TFilterNever<[...Acc, ...TIndexFromPropertyKeys<L, [K]>]>> : Acc);
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 SetDistinct([...Acc, ...KeyOfPropertyKeys(L)]);
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 FilterNever([...Acc, ...IndexFromPropertyKeys(L, [K])]);
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) {
@@ -1,13 +1,19 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import type { Static } from '../static/index.mjs';
3
3
  import type { Ensure } from '../helpers/index.mjs';
4
+ import type { TReadonlyOptional } from '../readonly-optional/index.mjs';
5
+ import type { TReadonly } from '../readonly/index.mjs';
6
+ import type { TOptional } from '../optional/index.mjs';
4
7
  import { Kind } from '../symbols/index.mjs';
5
- type ConstructorStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
6
- type ConstructorStaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? ConstructorStaticParameters<R, P, [...Acc, Static<L, P>]> : Acc;
7
- type ConstructorStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<new (...param: ConstructorStaticParameters<T, P>) => ConstructorStaticReturnType<U, P>>);
8
+ type StaticReturnType<U extends TSchema, P extends unknown[]> = Static<U, P>;
9
+ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
10
+ Static<T, P>
11
+ ];
12
+ type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
+ type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
8
14
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
9
15
  [Kind]: 'Constructor';
10
- static: ConstructorStatic<T, U, this['params']>;
16
+ static: StaticConstructor<T, U, this['params']>;
11
17
  type: 'Constructor';
12
18
  parameters: T;
13
19
  returns: U;
@@ -1,13 +1,19 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import type { Static } from '../static/index.mjs';
3
3
  import type { Ensure } from '../helpers/index.mjs';
4
+ import type { TReadonlyOptional } from '../readonly-optional/index.mjs';
5
+ import type { TReadonly } from '../readonly/index.mjs';
6
+ import type { TOptional } from '../optional/index.mjs';
4
7
  import { Kind } from '../symbols/index.mjs';
5
- type FunctionStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
6
- type FunctionStaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FunctionStaticParameters<R, P, [...Acc, Static<L, P>]> : Acc;
7
- type FunctionStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<(...param: FunctionStaticParameters<T, P>) => FunctionStaticReturnType<U, P>>);
8
+ type StaticReturnType<U extends TSchema, P extends unknown[]> = Static<U, P>;
9
+ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
10
+ Static<T, P>
11
+ ];
12
+ type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
+ type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
8
14
  export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
9
15
  [Kind]: 'Function';
10
- static: FunctionStatic<T, U, this['params']>;
16
+ static: StaticFunction<T, U, this['params']>;
11
17
  type: 'Function';
12
18
  parameters: T;
13
19
  returns: U;
@@ -110,10 +110,8 @@ function Default(value) {
110
110
  // Convert
111
111
  // ------------------------------------------------------------------
112
112
  function FromArray(schema, references, value) {
113
- if (IsArray(value)) {
114
- return value.map((value) => Visit(schema.items, references, value));
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);
@@ -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, TSetDistinct<[...Acc, ...TKeyOfPropertyKeys<L>]>> : Acc);
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, TFilterNever<[...Acc, ...TIndexFromPropertyKeys<L, [K]>]>> : Acc);
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 (0, index_5.SetDistinct)([...Acc, ...(0, index_3.KeyOfPropertyKeys)(L)]);
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 FilterNever([...Acc, ...(0, index_2.IndexFromPropertyKeys)(L, [K])]);
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) {
@@ -1,13 +1,19 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import type { Static } from '../static/index';
3
3
  import type { Ensure } from '../helpers/index';
4
+ import type { TReadonlyOptional } from '../readonly-optional/index';
5
+ import type { TReadonly } from '../readonly/index';
6
+ import type { TOptional } from '../optional/index';
4
7
  import { Kind } from '../symbols/index';
5
- type ConstructorStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
6
- type ConstructorStaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? ConstructorStaticParameters<R, P, [...Acc, Static<L, P>]> : Acc;
7
- type ConstructorStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<new (...param: ConstructorStaticParameters<T, P>) => ConstructorStaticReturnType<U, P>>);
8
+ type StaticReturnType<U extends TSchema, P extends unknown[]> = Static<U, P>;
9
+ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
10
+ Static<T, P>
11
+ ];
12
+ type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
+ type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
8
14
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
9
15
  [Kind]: 'Constructor';
10
- static: ConstructorStatic<T, U, this['params']>;
16
+ static: StaticConstructor<T, U, this['params']>;
11
17
  type: 'Constructor';
12
18
  parameters: T;
13
19
  returns: U;
@@ -1,13 +1,19 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import type { Static } from '../static/index';
3
3
  import type { Ensure } from '../helpers/index';
4
+ import type { TReadonlyOptional } from '../readonly-optional/index';
5
+ import type { TReadonly } from '../readonly/index';
6
+ import type { TOptional } from '../optional/index';
4
7
  import { Kind } from '../symbols/index';
5
- type FunctionStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
6
- type FunctionStaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FunctionStaticParameters<R, P, [...Acc, Static<L, P>]> : Acc;
7
- type FunctionStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<(...param: FunctionStaticParameters<T, P>) => FunctionStaticReturnType<U, P>>);
8
+ type StaticReturnType<U extends TSchema, P extends unknown[]> = Static<U, P>;
9
+ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
10
+ Static<T, P>
11
+ ];
12
+ type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
+ type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
8
14
  export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
9
15
  [Kind]: 'Function';
10
- static: FunctionStatic<T, U, this['params']>;
16
+ static: StaticFunction<T, U, this['params']>;
11
17
  type: 'Function';
12
18
  parameters: T;
13
19
  returns: U;
@@ -114,10 +114,8 @@ function Default(value) {
114
114
  // Convert
115
115
  // ------------------------------------------------------------------
116
116
  function FromArray(schema, references, value) {
117
- if ((0, index_5.IsArray)(value)) {
118
- return value.map((value) => Visit(schema.items, references, value));
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.32.20",
3
+ "version": "0.32.22",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
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 |