@sinclair/typebox 0.24.49 → 0.24.51
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 +1 -1
- package/typebox.d.ts +8 -8
- package/typebox.js +1 -1
package/package.json
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -178,15 +178,15 @@ export interface TProperties {
|
|
|
178
178
|
export declare type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
|
|
179
179
|
export declare type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
|
|
180
180
|
export declare type TAdditionalProperties = undefined | TSchema | boolean;
|
|
181
|
-
export interface ObjectOptions
|
|
182
|
-
additionalProperties?:
|
|
181
|
+
export interface ObjectOptions extends SchemaOptions {
|
|
182
|
+
additionalProperties?: TAdditionalProperties;
|
|
183
183
|
minProperties?: number;
|
|
184
184
|
maxProperties?: number;
|
|
185
185
|
}
|
|
186
|
-
export interface TObject<T extends TProperties = TProperties
|
|
186
|
+
export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
187
187
|
[Kind]: 'Object';
|
|
188
|
-
static:
|
|
189
|
-
additionalProperties?:
|
|
188
|
+
static: PropertiesReduce<T, this['params']>;
|
|
189
|
+
additionalProperties?: TAdditionalProperties;
|
|
190
190
|
type: 'object';
|
|
191
191
|
properties: T;
|
|
192
192
|
required?: string[];
|
|
@@ -210,7 +210,7 @@ export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
|
210
210
|
type: 'promise';
|
|
211
211
|
item: TSchema;
|
|
212
212
|
}
|
|
213
|
-
export declare type TRecordKey = TString |
|
|
213
|
+
export declare type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
|
|
214
214
|
export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
|
|
215
215
|
[Kind]: 'Record';
|
|
216
216
|
static: Record<Static<K>, Static<T, this['params']>>;
|
|
@@ -351,7 +351,7 @@ export declare class TypeBuilder {
|
|
|
351
351
|
/** Creates a number type */
|
|
352
352
|
Number(options?: NumericOptions): TNumber;
|
|
353
353
|
/** Creates an object type with the given properties */
|
|
354
|
-
Object<T extends TProperties
|
|
354
|
+
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
355
355
|
/** Creates a new object whose properties are omitted from the given object */
|
|
356
356
|
Omit<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TOmit<T, UnionStringLiteralToTuple<K>>;
|
|
357
357
|
/** Creates a new object whose properties are omitted from the given object */
|
|
@@ -369,7 +369,7 @@ export declare class TypeBuilder {
|
|
|
369
369
|
/** Creates an object whose properties are derived from the given string literal union. */
|
|
370
370
|
Record<K extends TUnion<TLiteral[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordProperties<K, T>>;
|
|
371
371
|
/** Creates a record type */
|
|
372
|
-
Record<K extends TString |
|
|
372
|
+
Record<K extends TString | TNumeric, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecord<K, T>;
|
|
373
373
|
/** Creates a recursive object type */
|
|
374
374
|
Recursive<T extends TSchema>(callback: (self: TSelf) => T, options?: SchemaOptions): TRecursive<T>;
|
|
375
375
|
/** Creates a reference schema */
|
package/typebox.js
CHANGED
|
@@ -259,7 +259,7 @@ class TypeBuilder {
|
|
|
259
259
|
}, {}), { ...options, [exports.Hint]: 'Record' });
|
|
260
260
|
}
|
|
261
261
|
// otherwise return TRecord with patternProperties
|
|
262
|
-
const pattern = key[exports.Kind]
|
|
262
|
+
const pattern = ['Integer', 'Number'].includes(key[exports.Kind]) ? '^(0|[1-9][0-9]*)$' : key[exports.Kind] === 'String' && key.pattern ? key.pattern : '^.*$';
|
|
263
263
|
return this.Create({
|
|
264
264
|
...options,
|
|
265
265
|
[exports.Kind]: 'Record',
|