@sinclair/typebox 0.34.24 → 0.34.25

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.
@@ -2,15 +2,15 @@ import * as t from '../type/index';
2
2
  import { Static } from '../parser/index';
3
3
  import { Type, GenericArguments } from './static';
4
4
  type TParseSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (Static.Parse<GenericArguments, Code, {}> extends [infer Args extends t.TProperties, infer Rest extends string] ? Static.Parse<Type, Rest, Context & Args> : Static.Parse<Type, Code, Context>);
5
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
5
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
6
6
  export declare function NoInfer<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema;
7
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
7
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
8
8
  export declare function NoInfer<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema;
9
- /** Parses a TypeScript annotation into a TypeBox type */
9
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
10
10
  export type TSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (TParseSyntax<Context, Code> extends [infer Type extends t.TSchema, string] ? Type : t.TNever);
11
- /** Parses a TypeScript annotation into a TypeBox type */
11
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
12
12
  export declare function Syntax<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
13
- /** Parses a TypeScript annotation into a TypeBox type */
13
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
14
14
  export declare function Syntax<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
15
15
  /**
16
16
  * @deprecated Use Syntax() function
@@ -14,7 +14,7 @@ function ParseSyntax(context, code) {
14
14
  ? runtime_1.Module.Parse('Type', results[1], { ...context, ...results[0] })
15
15
  : runtime_1.Module.Parse('Type', code, context));
16
16
  }
17
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
17
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
18
18
  // prettier-ignore
19
19
  function NoInfer(...args) {
20
20
  const withContext = typeof args[0] === 'string' ? false : true;
@@ -24,7 +24,7 @@ function NoInfer(...args) {
24
24
  ? t.CloneType(result, options)
25
25
  : t.Never(options);
26
26
  }
27
- /** Parses a TypeScript annotation into a TypeBox type */
27
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
28
28
  function Syntax(...args) {
29
29
  return NoInfer.apply(null, args);
30
30
  }
@@ -24,7 +24,7 @@ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TAr
24
24
  type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
25
25
  type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
26
26
  type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
27
- type TFromObject<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = TFromProperties<Args, Properties>> = TObject<Result>;
27
+ type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TObject = TObject<MappedProperties>> = Result;
28
28
  type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
29
29
  type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
30
30
  type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
@@ -63,8 +63,8 @@ function FromPromise(args, type) {
63
63
  }
64
64
  // prettier-ignore
65
65
  function FromObject(args, type) {
66
- const properties = FromProperties(args, type.properties);
67
- return { ...type, ...(0, index_5.Object)(properties) }; // retain options
66
+ const mappedProperties = FromProperties(args, type.properties);
67
+ return { ...type, ...(0, index_5.Object)(mappedProperties) }; // retain options
68
68
  }
69
69
  // prettier-ignore
70
70
  function FromRecord(args, type) {
@@ -2,15 +2,15 @@ import * as t from '../type/index.mjs';
2
2
  import { Static } from '../parser/index.mjs';
3
3
  import { Type, GenericArguments } from './static.mjs';
4
4
  type TParseSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (Static.Parse<GenericArguments, Code, {}> extends [infer Args extends t.TProperties, infer Rest extends string] ? Static.Parse<Type, Rest, Context & Args> : Static.Parse<Type, Code, Context>);
5
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
5
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
6
6
  export declare function NoInfer<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema;
7
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
7
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
8
8
  export declare function NoInfer<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema;
9
- /** Parses a TypeScript annotation into a TypeBox type */
9
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
10
10
  export type TSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (TParseSyntax<Context, Code> extends [infer Type extends t.TSchema, string] ? Type : t.TNever);
11
- /** Parses a TypeScript annotation into a TypeBox type */
11
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
12
12
  export declare function Syntax<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
13
- /** Parses a TypeScript annotation into a TypeBox type */
13
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
14
14
  export declare function Syntax<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
15
15
  /**
16
16
  * @deprecated Use Syntax() function
@@ -7,7 +7,7 @@ function ParseSyntax(context, code) {
7
7
  ? Module.Parse('Type', results[1], { ...context, ...results[0] })
8
8
  : Module.Parse('Type', code, context));
9
9
  }
10
- /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
10
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
11
11
  // prettier-ignore
12
12
  export function NoInfer(...args) {
13
13
  const withContext = typeof args[0] === 'string' ? false : true;
@@ -17,7 +17,7 @@ export function NoInfer(...args) {
17
17
  ? t.CloneType(result, options)
18
18
  : t.Never(options);
19
19
  }
20
- /** Parses a TypeScript annotation into a TypeBox type */
20
+ /** `[Experimental]` Parses a TypeScript annotation into a TypeBox type */
21
21
  export function Syntax(...args) {
22
22
  return NoInfer.apply(null, args);
23
23
  }
@@ -24,7 +24,7 @@ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TAr
24
24
  type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
25
25
  type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
26
26
  type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
27
- type TFromObject<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = TFromProperties<Args, Properties>> = TObject<Result>;
27
+ type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TObject = TObject<MappedProperties>> = Result;
28
28
  type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
29
29
  type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
30
30
  type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
@@ -58,8 +58,8 @@ function FromPromise(args, type) {
58
58
  }
59
59
  // prettier-ignore
60
60
  function FromObject(args, type) {
61
- const properties = FromProperties(args, type.properties);
62
- return { ...type, ...Object(properties) }; // retain options
61
+ const mappedProperties = FromProperties(args, type.properties);
62
+ return { ...type, ...Object(mappedProperties) }; // retain options
63
63
  }
64
64
  // prettier-ignore
65
65
  function FromRecord(args, type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.24",
3
+ "version": "0.34.25",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -100,6 +100,7 @@ License MIT
100
100
  - [Parameters](#syntax-parameters)
101
101
  - [Generics](#syntax-generics)
102
102
  - [Options](#syntax-options)
103
+ - [NoInfer](#syntax-no-infer)
103
104
  - [TypeRegistry](#typeregistry)
104
105
  - [Type](#typeregistry-type)
105
106
  - [Format](#typeregistry-format)
@@ -1306,7 +1307,7 @@ ValuePointer.Set(A, '/z', 1) // A' = { x: 1, y: 1, z: 1
1306
1307
 
1307
1308
  ## Syntax Types
1308
1309
 
1309
- TypeBox includes support for parsing TypeScript annotation syntax into TypeBox schematics.
1310
+ TypeBox provides experimental support for parsing TypeScript annotation syntax into TypeBox types.
1310
1311
 
1311
1312
  This feature is provided via optional import.
1312
1313
 
@@ -1391,6 +1392,23 @@ const T = Syntax(`number`, { minimum: 42 }) // const T = {
1391
1392
  // }
1392
1393
  ```
1393
1394
 
1395
+ <a name='syntax-no-infer'></a>
1396
+
1397
+ ### NoInfer
1398
+
1399
+ Syntax parsing is an expensive type level operation and can impact on language service performance. Use the NoInfer function parse syntax at runtime only.
1400
+
1401
+ ```typescript
1402
+ import { NoInfer } from '@sinclair/typebox/syntax'
1403
+
1404
+ const T = NoInfer(`number | string`) // const T: TSchema = {
1405
+ // anyOf: [
1406
+ // { type: 'number' },
1407
+ // { type: 'string' }
1408
+ // ]
1409
+ // }
1410
+ ```
1411
+
1394
1412
  <a name='typeregistry'></a>
1395
1413
 
1396
1414
  ## TypeRegistry