@sinclair/typebox 0.31.14 → 0.31.16

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.31.14",
3
+ "version": "0.31.16",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -58,11 +58,9 @@ type T = Static<typeof T> // type T = {
58
58
 
59
59
  ## Overview
60
60
 
61
- TypeBox is a runtime type builder that creates Json Schema objects that infer as TypeScript types. The schemas produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript or runtime asserted using standard Json Schema validation.
61
+ TypeBox is a runtime type builder 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 assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
62
62
 
63
- TypeBox uses industry standard schematics for runtime type representation; enabling types to be reflected, serialized and published directly. Its type system is fully extensible and able to support type representation for multiple schema specifications. It also provides a high performance validation compiler, various tools for working with dynamic data and offers detailed structured error reporting.
64
-
65
- TypeBox can be used as a simple tool to build up complex schemas or integrated into applications and frameworks to enable high performance runtime type checking for data received over the wire.
63
+ This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
66
64
 
67
65
  License MIT
68
66
 
@@ -1610,6 +1608,7 @@ The following is a list of community packages that offer general tooling, extend
1610
1608
  | [feathersjs](https://github.com/feathersjs/feathers) | The API and real-time application framework |
1611
1609
  | [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
1612
1610
  | [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
1611
+ | [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
1613
1612
  | [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
1614
1613
  | [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
1615
1614
  | [typebox-client](https://github.com/flodlc/typebox-client) | Type safe http client library for Fastify |
package/typebox.d.ts CHANGED
@@ -339,11 +339,11 @@ export type TRecordFromUnionLiteralNumber<K extends TLiteralNumber, T extends TS
339
339
  };
340
340
  export type TRecordFromUnionRest<K extends TSchema[], T extends TSchema> = K extends [infer L, ...infer R] ? (L extends TUnion<infer S> ? TRecordFromUnionRest<S, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralString ? TRecordFromUnionLiteralString<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralNumber ? TRecordFromUnionLiteralNumber<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : {}) : {};
341
341
  export type TRecordFromUnion<K extends TSchema[], T extends TSchema> = Ensure<TObject<AssertProperties<Evaluate<TRecordFromUnionRest<K, T>>>>>;
342
- export type TRecordFromTemplateLiteralKeyInfinite<T extends TSchema> = Ensure<TRecord<TString, T>>;
342
+ export type TRecordFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
343
343
  export type TRecordFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I = Static<K>> = Ensure<TObject<Evaluate<{
344
344
  [_ in Assert<I, string>]: T;
345
345
  }>>>;
346
- export type TRecordFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = IsTemplateLiteralFinite<K> extends false ? TRecordFromTemplateLiteralKeyInfinite<T> : TRecordFromTemplateLiteralKeyFinite<K, T>;
346
+ export type TRecordFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = IsTemplateLiteralFinite<K> extends false ? TRecordFromTemplateLiteralKeyInfinite<K, T> : TRecordFromTemplateLiteralKeyFinite<K, T>;
347
347
  export type TRecordFromLiteralStringKey<K extends TLiteralString, T extends TSchema> = Ensure<TObject<{
348
348
  [_ in K['const']]: T;
349
349
  }>>;
package/value/hash.js CHANGED
@@ -66,6 +66,15 @@ const F64 = new Float64Array(1);
66
66
  const F64In = new DataView(F64.buffer);
67
67
  const F64Out = new Uint8Array(F64.buffer);
68
68
  // --------------------------------------------------------------------------
69
+ // NumberToBytes
70
+ // --------------------------------------------------------------------------
71
+ function* NumberToBytes(value) {
72
+ const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8);
73
+ for (let i = 0; i < byteCount; i++) {
74
+ yield (value >> (8 * (byteCount - 1 - i))) & 0xff;
75
+ }
76
+ }
77
+ // --------------------------------------------------------------------------
69
78
  // Hashing Functions
70
79
  // --------------------------------------------------------------------------
71
80
  function ArrayType(value) {
@@ -109,7 +118,9 @@ function ObjectType(value) {
109
118
  function StringType(value) {
110
119
  FNV1A64(ByteMarker.String);
111
120
  for (let i = 0; i < value.length; i++) {
112
- FNV1A64(value.charCodeAt(i));
121
+ for (const byte of NumberToBytes(value.charCodeAt(i))) {
122
+ FNV1A64(byte);
123
+ }
113
124
  }
114
125
  }
115
126
  function SymbolType(value) {