@sinclair/typebox 0.23.1 → 0.23.2

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.1",
3
+ "version": "0.23.2",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "json-schema",
package/readme.md CHANGED
@@ -42,7 +42,7 @@ type T = Static<typeof T> // type T = string
42
42
 
43
43
  ## Overview
44
44
 
45
- TypeBox is a library that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox allows one to create a unified type that can be both statically asserted by the TypeScript compiler and runtime asserted using industry standard JSON Schema validation.
45
+ TypeBox is a library that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox allows one to create a unified type that can be both statically asserted by the TypeScript compiler and runtime asserted using standard JSON Schema validation.
46
46
 
47
47
  TypeBox can be used as a simple tool to build up complex schemas or integrated into RPC or REST services to help validate JSON data received over the wire. TypeBox does not provide any JSON schema validation. Please use libraries such as AJV to validate schemas built with this library.
48
48
 
@@ -263,19 +263,19 @@ The following table outlines the TypeBox mappings between TypeScript and JSON sc
263
263
  │ Type.Object({ │ x: number │ allOf: [{ │
264
264
  │ x: Type.Number() │ } & { │ type: 'object', │
265
265
  │ }), │ y: number │ properties: { │
266
- │ Type.Object({ │ } │ a: { │
266
+ │ Type.Object({ │ } │ x: { │
267
267
  │ y: Type.Number() │ │ type: 'number' │
268
268
  │ }) │ │ } │
269
269
  │ }) │ │ }, │
270
- │ │ │ required: ['a'] │
270
+ │ │ │ required: ['x'] │
271
271
  │ │ │ }, { │
272
272
  │ │ │ type: 'object', │
273
273
  │ │ │ properties: { │
274
- │ │ │ b: { │
274
+ │ │ │ y: { │
275
275
  │ │ │ type: 'number' │
276
276
  │ │ │ } │
277
277
  │ │ │ }, │
278
- │ │ │ required: ['b'] │
278
+ │ │ │ required: ['y'] │
279
279
  │ │ │ }] │
280
280
  │ │ │ } │
281
281
  │ │ │ │
package/typebox.d.ts CHANGED
@@ -340,9 +340,9 @@ export declare class TypeBuilder {
340
340
  Ref<T extends TSchema>(schema: T): TRef<T>;
341
341
  /** `Experimental` Creates a recursive type */
342
342
  Rec<T extends TSchema>(callback: (self: TAny) => T, options?: CustomOptions): T;
343
- /** Conditionally stores and schema if it contains an $id and returns. */
344
- protected Store(schema: any): any;
345
- /** Conditionally dereferences a schema if RefKind. Otherwise return argument. */
346
- protected Deref(schema: any): any;
343
+ /** Conditionally stores and schema if it contains an $id and returns */
344
+ protected Store<T extends TSchema | TNamespace<TDefinitions>, S = Omit<T, '$static'>>(schema: S): T;
345
+ /** Conditionally dereferences a schema if RefKind. Otherwise return argument */
346
+ protected Deref<T extends TSchema>(schema: T): any;
347
347
  }
348
348
  export declare const Type: TypeBuilder;
package/typebox.js CHANGED
@@ -320,20 +320,22 @@ class TypeBuilder {
320
320
  const self = callback({ $ref: `${$id}#/$defs/self` });
321
321
  return this.Store({ ...options, $ref: `${$id}#/$defs/self`, $defs: { self } });
322
322
  }
323
- /** Conditionally stores and schema if it contains an $id and returns. */
323
+ /** Conditionally stores and schema if it contains an $id and returns */
324
324
  Store(schema) {
325
- if (!schema.$id)
326
- return schema;
327
- this.schemas.set(schema.$id, schema);
328
- return schema;
325
+ const $schema = schema;
326
+ if (!$schema['$id'])
327
+ return $schema;
328
+ this.schemas.set($schema['$id'], $schema);
329
+ return $schema;
329
330
  }
330
- /** Conditionally dereferences a schema if RefKind. Otherwise return argument. */
331
+ /** Conditionally dereferences a schema if RefKind. Otherwise return argument */
331
332
  Deref(schema) {
332
- if (schema.kind !== exports.RefKind)
333
+ const $schema = schema;
334
+ if ($schema['kind'] !== exports.RefKind)
333
335
  return schema;
334
- if (!this.schemas.has(schema.$ref))
335
- throw Error(`Unable to locate schema with $id '${schema.$ref}'`);
336
- return this.Deref(this.schemas.get(schema.$ref));
336
+ if (!this.schemas.has($schema['$ref']))
337
+ throw Error(`Unable to locate schema with $id '${$schema['$ref']}'`);
338
+ return this.Deref(this.schemas.get($schema['$ref']));
337
339
  }
338
340
  }
339
341
  exports.TypeBuilder = TypeBuilder;