@sinclair/typebox 0.31.2 → 0.31.4

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.
@@ -384,7 +384,7 @@ var TypeCompiler;
384
384
  if ((0, guard_1.IsNumber)(schema.maxProperties))
385
385
  yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
386
386
  const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
387
- const variable = CreateVariable(`new RegExp(/${patternKey}/)`);
387
+ const variable = CreateVariable(`${new RegExp(patternKey)}`);
388
388
  const check1 = CreateExpression(patternSchema, references, 'value');
389
389
  const check2 = Types.TypeGuard.TSchema(schema.additionalProperties) ? CreateExpression(schema.additionalProperties, references, value) : schema.additionalProperties === false ? 'false' : 'true';
390
390
  const expression = `(${variable}.test(key) ? ${check1} : ${check2})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.31.2",
3
+ "version": "0.31.4",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
@@ -59,6 +59,6 @@
59
59
  "ajv-formats": "^2.1.1",
60
60
  "mocha": "^9.2.2",
61
61
  "prettier": "^2.7.1",
62
- "typescript": "^5.1.6"
62
+ "typescript": "^5.2.2"
63
63
  }
64
64
  }
package/readme.md CHANGED
@@ -60,7 +60,7 @@ type T = Static<typeof T> // type T = {
60
60
 
61
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 checked using standard Json Schema validation.
62
62
 
63
- TypeBox is built upon industry standard specifications. It offers reflectable, serializable and publishable types as standard, a fully extensible type system capable of supporting multiple schema specifications, includes a high performance validation compiler, offers various tools for working with dynamic data and provides detailed structured error reporting.
63
+ TypeBox types are designed to express industry standard schematics as TypeScript types. All types are runtime reflectable, serializable and publishable by default. It includes an extensible type system able to represent type safe schematics 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
64
 
65
65
  TypeBox can be used as a simple tool to build up complex schemas or integrated into applications to enable high performance runtime validation for data received over the wire.
66
66
 
@@ -949,7 +949,7 @@ const U = Type.Union(R) // const U = {
949
949
 
950
950
  ### Transform Types
951
951
 
952
- TypeBox supports bi-directional decode and encode with Transform types. These types are designed to operate with the Value and TypeCompiler Encode and Decode functions. Transform types are useful to convert Json encoded values into constructs more natural to JavaScript. The following creates a Transform type to convert between Date and number using the Value module.
952
+ TypeBox supports value decoding and encoding with Transform types. These types work in tandem with the Encode and Decode functions available on the Value and TypeCompiler modules. Transform types can be used to convert Json encoded values into constructs more natural to JavaScript. The following creates a Transform type to decode numbers into Dates using the Value module.
953
953
 
954
954
  ```typescript
955
955
  import { Value } from '@sinclair/typebox/value'
@@ -1604,13 +1604,16 @@ The following is a list of community packages that offer general tooling, extend
1604
1604
 
1605
1605
  | Package | Description |
1606
1606
  | ------------- | ------------- |
1607
+ | [drizzle-typebox](https://www.npmjs.com/package/drizzle-typebox) | Generates TypeBox types from Drizzle ORM schemas |
1607
1608
  | [elysia](https://github.com/elysiajs/elysia) | Fast and friendly Bun web framework |
1608
1609
  | [fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox) | Fastify TypeBox integration with the Fastify Type Provider |
1609
1610
  | [feathersjs](https://github.com/feathersjs/feathers) | The API and real-time application framework |
1610
1611
  | [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
1612
+ | [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
1611
1613
  | [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
1612
1614
  | [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
1613
1615
  | [typebox-client](https://github.com/flodlc/typebox-client) | Type safe http client library for Fastify |
1616
+ | [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |
1614
1617
  | [typebox-validators](https://github.com/jtlapp/typebox-validators) | Advanced validators supporting discriminated and heterogeneous unions |
1615
1618
 
1616
1619
  <a name='benchmark'></a>
package/system/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export { ValueErrorType } from '../errors/errors';
1
2
  export * from './system';
package/system/index.js CHANGED
@@ -41,4 +41,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
41
41
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
42
42
  };
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.ValueErrorType = void 0;
45
+ var errors_1 = require("../errors/errors");
46
+ Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return errors_1.ValueErrorType; } });
44
47
  __exportStar(require("./system"), exports);
package/typebox.d.ts CHANGED
@@ -6,9 +6,9 @@ export declare const Kind: unique symbol;
6
6
  export declare const PatternBoolean = "(true|false)";
7
7
  export declare const PatternNumber = "(0|[1-9][0-9]*)";
8
8
  export declare const PatternString = "(.*)";
9
- export declare const PatternBooleanExact: string;
10
- export declare const PatternNumberExact: string;
11
- export declare const PatternStringExact: string;
9
+ export declare const PatternBooleanExact = "^(true|false)$";
10
+ export declare const PatternNumberExact = "^(0|[1-9][0-9]*)$";
11
+ export declare const PatternStringExact = "^(.*)$";
12
12
  export type TupleToIntersect<T extends any[]> = T extends [infer I] ? I : T extends [infer I, ...infer R] ? I & TupleToIntersect<R> : never;
13
13
  export type TupleToUnion<T extends any[]> = {
14
14
  [K in keyof T]: T[K];
@@ -436,11 +436,12 @@ export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLi
436
436
  type: 'string';
437
437
  pattern: string;
438
438
  }
439
- export type DecodeStaticProperties<T extends TProperties> = {
440
- [K in keyof T]: DecodeStaticType<T[K]>;
439
+ export type DecodeModifier<D extends TSchema, T extends TSchema> = T extends TReadonly<T> & TOptional<T> ? TReadonly<TOptional<D>> : T extends TReadonly<T> ? TReadonly<D> : T extends TOptional<T> ? TOptional<D> : D;
440
+ export type DecodeProperties<T extends TProperties> = {
441
+ [K in keyof T]: DecodeType<T[K]>;
441
442
  };
442
- export type DecodeStaticRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? [DecodeStaticType<AssertType<L>>, ...DecodeStaticRest<AssertRest<R>>] : [];
443
- export type DecodeStaticType<T extends TSchema> = T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S> ? TArray<DecodeStaticType<S>> : T extends TAsyncIterator<infer S> ? TAsyncIterator<DecodeStaticType<S>> : T extends TConstructor<infer P, infer R> ? TConstructor<AssertRest<DecodeStaticRest<P>>, DecodeStaticType<R>> : T extends TFunction<infer P, infer R> ? TFunction<AssertRest<DecodeStaticRest<P>>, DecodeStaticType<R>> : T extends TIntersect<infer S> ? TIntersect<AssertRest<DecodeStaticRest<S>>> : T extends TIterator<infer S> ? TIterator<DecodeStaticType<S>> : T extends TNot<infer S> ? TNot<DecodeStaticType<S>> : T extends TObject<infer S> ? TObject<Evaluate<DecodeStaticProperties<S>>> : T extends TPromise<infer S> ? TPromise<DecodeStaticType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, DecodeStaticType<S>> : T extends TRecursive<infer S> ? TRecursive<DecodeStaticType<S>> : T extends TRef<infer S> ? TRef<DecodeStaticType<S>> : T extends TTuple<infer S> ? TTuple<AssertRest<DecodeStaticRest<S>>> : T extends TUnion<infer S> ? TUnion<AssertRest<DecodeStaticRest<S>>> : T;
443
+ export type DecodeRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? [DecodeType<AssertType<L>>, ...DecodeRest<AssertRest<R>>] : [];
444
+ export type DecodeType<T extends TSchema> = T extends TTransform<infer _, infer R> ? DecodeModifier<TUnsafe<R>, T> : T extends TArray<infer S> ? DecodeModifier<TArray<DecodeType<S>>, T> : T extends TAsyncIterator<infer S> ? DecodeModifier<TAsyncIterator<DecodeType<S>>, T> : T extends TConstructor<infer P, infer R> ? DecodeModifier<TConstructor<AssertRest<DecodeRest<P>>, DecodeType<R>>, T> : T extends TFunction<infer P, infer R> ? DecodeModifier<TFunction<AssertRest<DecodeRest<P>>, DecodeType<R>>, T> : T extends TIntersect<infer S> ? DecodeModifier<TIntersect<AssertRest<DecodeRest<S>>>, T> : T extends TIterator<infer S> ? DecodeModifier<TIterator<DecodeType<S>>, T> : T extends TNot<infer S> ? DecodeModifier<TNot<DecodeType<S>>, T> : T extends TObject<infer S> ? DecodeModifier<TObject<Evaluate<DecodeProperties<S>>>, T> : T extends TPromise<infer S> ? DecodeModifier<TPromise<DecodeType<S>>, T> : T extends TRecord<infer K, infer S> ? DecodeModifier<TRecord<K, DecodeType<S>>, T> : T extends TRecursive<infer S> ? DecodeModifier<TRecursive<DecodeType<S>>, T> : T extends TRef<infer S> ? DecodeModifier<TRef<DecodeType<S>>, T> : T extends TTuple<infer S> ? DecodeModifier<TTuple<AssertRest<DecodeRest<S>>>, T> : T extends TUnion<infer S> ? DecodeModifier<TUnion<AssertRest<DecodeRest<S>>>, T> : T;
444
445
  export type TransformFunction<T = any, U = any> = (value: T) => U;
445
446
  export interface TransformOptions<I extends TSchema = TSchema, O extends unknown = unknown> {
446
447
  Decode: TransformFunction<StaticDecode<I>, O>;
@@ -507,7 +508,7 @@ export interface TVoid extends TSchema {
507
508
  type: 'void';
508
509
  }
509
510
  /** Creates the decoded static form for a TypeBox type */
510
- export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeStaticType<T>, P>;
511
+ export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeType<T>, P>;
511
512
  /** Creates the encoded static form for a TypeBox type */
512
513
  export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
513
514
  /** Creates the static type for a TypeBox type */
@@ -799,7 +800,7 @@ export declare class JsonTypeBuilder extends TypeBuilder {
799
800
  /** `[Json]` Creates a Composite object type */
800
801
  Composite<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TComposite<T>;
801
802
  /** `[Json]` Creates a Enum type */
802
- Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
803
+ Enum<V extends string | number, T extends Record<string, V>>(item: T, options?: SchemaOptions): TEnum<T>;
803
804
  /** `[Json]` Creates a Conditional type */
804
805
  Extends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U, options?: SchemaOptions): TExtends<L, R, T, U>;
805
806
  /** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */