@sinclair/typebox 0.23.2 → 0.23.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.23.2",
3
+ "version": "0.23.5",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "json-schema",
@@ -26,15 +26,15 @@
26
26
  "test": "npm run spec"
27
27
  },
28
28
  "devDependencies": {
29
- "@sinclair/hammer": "^0.15.8",
30
- "@types/chai": "^4.2.22",
31
- "@types/mocha": "^9.0.0",
32
- "@types/node": "^16.11.9",
33
- "ajv": "^8.8.2",
29
+ "@sinclair/hammer": "^0.16.3",
30
+ "@types/chai": "^4.3.0",
31
+ "@types/mocha": "^9.1.0",
32
+ "@types/node": "^17.0.12",
33
+ "ajv": "^8.9.0",
34
34
  "ajv-formats": "^2.1.1",
35
- "chai": "^4.3.4",
36
- "mocha": "^9.1.3",
37
- "tsd": "^0.19.0",
38
- "typescript": "^4.5.2"
35
+ "chai": "^4.3.5",
36
+ "mocha": "^9.2.0",
37
+ "tsd": "^0.19.1",
38
+ "typescript": "^4.5.5"
39
39
  }
40
40
  }
package/readme.md CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  <h1>TypeBox</h1>
4
4
 
5
- <img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
6
-
7
5
  <p>JSON Schema Type Builder with Static Type Resolution for TypeScript</p>
6
+
7
+ <img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
8
8
 
9
-
9
+ <br />
10
+ <br />
10
11
 
11
12
  [![npm version](https://badge.fury.io/js/%40sinclair%2Ftypebox.svg)](https://badge.fury.io/js/%40sinclair%2Ftypebox) [![GitHub CI](https://github.com/sinclairzx81/typebox/workflows/GitHub%20CI/badge.svg)](https://github.com/sinclairzx81/typebox/actions)
12
13
 
@@ -266,7 +267,7 @@ The following table outlines the TypeBox mappings between TypeScript and JSON sc
266
267
  │ Type.Object({ │ } │ x: { │
267
268
  │ y: Type.Number() │ │ type: 'number' │
268
269
  │ }) │ │ } │
269
- }) │ │ }, │
270
+ ]) │ │ }, │
270
271
  │ │ │ required: ['x'] │
271
272
  │ │ │ }, { │
272
273
  │ │ │ type: 'object', │
@@ -598,7 +599,7 @@ In addition to JSON schema types, TypeBox provides several extended types that a
598
599
 
599
600
  ### Strict
600
601
 
601
- TypeBox schemas contain the properties `kind` and `modifier`. These properties are provided to enable runtime type reflection on schemas, as well as helping TypeBox apply the appropriate static type inference rules. These properties are not strictly valid JSON schema so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict()` function that will omit these properties if nessasary.
602
+ TypeBox schemas contain the properties `kind` and `modifier`. These properties are provided to enable runtime type reflection on schemas, as well as helping TypeBox apply the appropriate static type inference rules. These properties are not strictly valid JSON schema so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict()` function that will omit these properties if necessary.
602
603
 
603
604
  ```typescript
604
605
  const T = Type.Object({ // const T = {
@@ -697,7 +698,7 @@ Please refer to the official AJV [documentation](https://ajv.js.org/guide/gettin
697
698
 
698
699
  ### OpenAPI
699
700
 
700
- TypeBox can be used to create schemas for OpenAPI, however users should be aware of the various disparities between the JSON Schema and OpenAPI schema specifications. Two common instances where OpenAPI diverges from the JSON Schema specification is OpenAPI's handling of string enums and nullable schemas. The following shows how you can use TypeBox to construct these types.
701
+ TypeBox can be used to create schemas for OpenAPI, however users should be mindful of some disparities between the JSON Schema and OpenAPI for versions prior to OpenAPI 3.1. Two common instances where OpenAPI diverges is the handling nullable and string enum schemas types. The following shows how you can use TypeBox to construct these types.
701
702
 
702
703
  ```typescript
703
704
  import { Type, Static, TNull, TLiteral, TUnion, TSchema } from '@sinclair/typebox'
package/typebox.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare type TOptional<T extends TSchema> = T & {
11
11
  export declare type TReadonly<T extends TSchema> = T & {
12
12
  modifier: typeof ReadonlyModifier;
13
13
  };
14
- export declare const BoxKind: unique symbol;
14
+ export declare const NamespaceKind: unique symbol;
15
15
  export declare const KeyOfKind: unique symbol;
16
16
  export declare const IntersectKind: unique symbol;
17
17
  export declare const UnionKind: unique symbol;
@@ -63,12 +63,14 @@ export declare type IntersectOptions = {
63
63
  } & CustomOptions;
64
64
  export declare type ObjectOptions = {
65
65
  additionalProperties?: boolean;
66
+ minProperties?: number;
67
+ maxProperties?: number;
66
68
  } & CustomOptions;
67
69
  export declare type TDefinitions = {
68
70
  [key: string]: TSchema;
69
71
  };
70
72
  export declare type TNamespace<T extends TDefinitions> = {
71
- kind: typeof BoxKind;
73
+ kind: typeof NamespaceKind;
72
74
  $defs: T;
73
75
  } & CustomOptions;
74
76
  export interface TSchema {
@@ -272,6 +274,7 @@ export declare type StaticPromise<T extends TSchema> = Promise<Static<T>>;
272
274
  export declare type Static<T extends TSchema> = T['$static'];
273
275
  export declare class TypeBuilder {
274
276
  protected readonly schemas: Map<string, TSchema>;
277
+ constructor();
275
278
  /** `Standard` Modifies an object property to be both readonly and optional */
276
279
  ReadonlyOptional<T extends TSchema>(item: T): TReadonlyOptional<T>;
277
280
  /** `Standard` Modifies an object property to be readonly */
package/typebox.js CHANGED
@@ -27,7 +27,7 @@ THE SOFTWARE.
27
27
 
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.Type = exports.TypeBuilder = exports.VoidKind = exports.UndefinedKind = exports.PromiseKind = exports.FunctionKind = exports.ConstructorKind = exports.RefKind = exports.AnyKind = exports.UnknownKind = exports.NullKind = exports.BooleanKind = exports.IntegerKind = exports.NumberKind = exports.StringKind = exports.LiteralKind = exports.EnumKind = exports.ArrayKind = exports.RecordKind = exports.ObjectKind = exports.TupleKind = exports.UnionKind = exports.IntersectKind = exports.KeyOfKind = exports.BoxKind = exports.ReadonlyModifier = exports.OptionalModifier = exports.ReadonlyOptionalModifier = void 0;
30
+ exports.Type = exports.TypeBuilder = exports.VoidKind = exports.UndefinedKind = exports.PromiseKind = exports.FunctionKind = exports.ConstructorKind = exports.RefKind = exports.AnyKind = exports.UnknownKind = exports.NullKind = exports.BooleanKind = exports.IntegerKind = exports.NumberKind = exports.StringKind = exports.LiteralKind = exports.EnumKind = exports.ArrayKind = exports.RecordKind = exports.ObjectKind = exports.TupleKind = exports.UnionKind = exports.IntersectKind = exports.KeyOfKind = exports.NamespaceKind = exports.ReadonlyModifier = exports.OptionalModifier = exports.ReadonlyOptionalModifier = void 0;
31
31
  // --------------------------------------------------------------------------
32
32
  // Modifiers
33
33
  // --------------------------------------------------------------------------
@@ -37,7 +37,7 @@ exports.ReadonlyModifier = Symbol('ReadonlyModifier');
37
37
  // --------------------------------------------------------------------------
38
38
  // Schema Standard
39
39
  // --------------------------------------------------------------------------
40
- exports.BoxKind = Symbol('BoxKind');
40
+ exports.NamespaceKind = Symbol('NamespaceKind');
41
41
  exports.KeyOfKind = Symbol('KeyOfKind');
42
42
  exports.IntersectKind = Symbol('IntersectKind');
43
43
  exports.UnionKind = Symbol('UnionKind');
@@ -83,7 +83,10 @@ function clone(object) {
83
83
  // TypeBuilder
84
84
  // --------------------------------------------------------------------------
85
85
  class TypeBuilder {
86
- schemas = new Map();
86
+ schemas;
87
+ constructor() {
88
+ this.schemas = new Map();
89
+ }
87
90
  /** `Standard` Modifies an object property to be both readonly and optional */
88
91
  ReadonlyOptional(item) {
89
92
  return { ...item, modifier: exports.ReadonlyOptionalModifier };
@@ -290,7 +293,7 @@ class TypeBuilder {
290
293
  }
291
294
  /** `Standard` Creates a namespace for a set of related types */
292
295
  Namespace($defs, options = {}) {
293
- return this.Store({ ...options, kind: exports.BoxKind, $defs });
296
+ return this.Store({ ...options, kind: exports.NamespaceKind, $defs });
294
297
  }
295
298
  Ref(...args) {
296
299
  if (args.length === 2) {