@sinclair/typebox 0.24.46 → 0.24.48

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.
@@ -25,23 +25,24 @@ export declare enum ValueErrorType {
25
25
  ObjectMinProperties = 22,
26
26
  ObjectMaxProperties = 23,
27
27
  ObjectAdditionalProperties = 24,
28
- Promise = 25,
29
- RecordKeyNumeric = 26,
30
- RecordKeyString = 27,
31
- String = 28,
32
- StringMinLength = 29,
33
- StringMaxLength = 30,
34
- StringPattern = 31,
35
- StringFormatUnknown = 32,
36
- StringFormat = 33,
37
- TupleZeroLength = 34,
38
- TupleLength = 35,
39
- Undefined = 36,
40
- Union = 37,
41
- Uint8Array = 38,
42
- Uint8ArrayMinByteLength = 39,
43
- Uint8ArrayMaxByteLength = 40,
44
- Void = 41
28
+ ObjectRequiredProperties = 25,
29
+ Promise = 26,
30
+ RecordKeyNumeric = 27,
31
+ RecordKeyString = 28,
32
+ String = 29,
33
+ StringMinLength = 30,
34
+ StringMaxLength = 31,
35
+ StringPattern = 32,
36
+ StringFormatUnknown = 33,
37
+ StringFormat = 34,
38
+ TupleZeroLength = 35,
39
+ TupleLength = 36,
40
+ Undefined = 37,
41
+ Union = 38,
42
+ Uint8Array = 39,
43
+ Uint8ArrayMinByteLength = 40,
44
+ Uint8ArrayMaxByteLength = 41,
45
+ Void = 42
45
46
  }
46
47
  export interface ValueError {
47
48
  type: ValueErrorType;
package/errors/errors.js CHANGED
@@ -60,23 +60,24 @@ var ValueErrorType;
60
60
  ValueErrorType[ValueErrorType["ObjectMinProperties"] = 22] = "ObjectMinProperties";
61
61
  ValueErrorType[ValueErrorType["ObjectMaxProperties"] = 23] = "ObjectMaxProperties";
62
62
  ValueErrorType[ValueErrorType["ObjectAdditionalProperties"] = 24] = "ObjectAdditionalProperties";
63
- ValueErrorType[ValueErrorType["Promise"] = 25] = "Promise";
64
- ValueErrorType[ValueErrorType["RecordKeyNumeric"] = 26] = "RecordKeyNumeric";
65
- ValueErrorType[ValueErrorType["RecordKeyString"] = 27] = "RecordKeyString";
66
- ValueErrorType[ValueErrorType["String"] = 28] = "String";
67
- ValueErrorType[ValueErrorType["StringMinLength"] = 29] = "StringMinLength";
68
- ValueErrorType[ValueErrorType["StringMaxLength"] = 30] = "StringMaxLength";
69
- ValueErrorType[ValueErrorType["StringPattern"] = 31] = "StringPattern";
70
- ValueErrorType[ValueErrorType["StringFormatUnknown"] = 32] = "StringFormatUnknown";
71
- ValueErrorType[ValueErrorType["StringFormat"] = 33] = "StringFormat";
72
- ValueErrorType[ValueErrorType["TupleZeroLength"] = 34] = "TupleZeroLength";
73
- ValueErrorType[ValueErrorType["TupleLength"] = 35] = "TupleLength";
74
- ValueErrorType[ValueErrorType["Undefined"] = 36] = "Undefined";
75
- ValueErrorType[ValueErrorType["Union"] = 37] = "Union";
76
- ValueErrorType[ValueErrorType["Uint8Array"] = 38] = "Uint8Array";
77
- ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 39] = "Uint8ArrayMinByteLength";
78
- ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 40] = "Uint8ArrayMaxByteLength";
79
- ValueErrorType[ValueErrorType["Void"] = 41] = "Void";
63
+ ValueErrorType[ValueErrorType["ObjectRequiredProperties"] = 25] = "ObjectRequiredProperties";
64
+ ValueErrorType[ValueErrorType["Promise"] = 26] = "Promise";
65
+ ValueErrorType[ValueErrorType["RecordKeyNumeric"] = 27] = "RecordKeyNumeric";
66
+ ValueErrorType[ValueErrorType["RecordKeyString"] = 28] = "RecordKeyString";
67
+ ValueErrorType[ValueErrorType["String"] = 29] = "String";
68
+ ValueErrorType[ValueErrorType["StringMinLength"] = 30] = "StringMinLength";
69
+ ValueErrorType[ValueErrorType["StringMaxLength"] = 31] = "StringMaxLength";
70
+ ValueErrorType[ValueErrorType["StringPattern"] = 32] = "StringPattern";
71
+ ValueErrorType[ValueErrorType["StringFormatUnknown"] = 33] = "StringFormatUnknown";
72
+ ValueErrorType[ValueErrorType["StringFormat"] = 34] = "StringFormat";
73
+ ValueErrorType[ValueErrorType["TupleZeroLength"] = 35] = "TupleZeroLength";
74
+ ValueErrorType[ValueErrorType["TupleLength"] = 36] = "TupleLength";
75
+ ValueErrorType[ValueErrorType["Undefined"] = 37] = "Undefined";
76
+ ValueErrorType[ValueErrorType["Union"] = 38] = "Union";
77
+ ValueErrorType[ValueErrorType["Uint8Array"] = 39] = "Uint8Array";
78
+ ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 40] = "Uint8ArrayMinByteLength";
79
+ ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 41] = "Uint8ArrayMaxByteLength";
80
+ ValueErrorType[ValueErrorType["Void"] = 42] = "Void";
80
81
  })(ValueErrorType = exports.ValueErrorType || (exports.ValueErrorType = {}));
81
82
  // -------------------------------------------------------------------
82
83
  // ValueErrors
@@ -190,12 +191,20 @@ var ValueErrors;
190
191
  }
191
192
  const propertyKeys = globalThis.Object.keys(schema.properties);
192
193
  if (schema.additionalProperties === false) {
193
- for (const propKey of globalThis.Object.keys(value)) {
194
- if (!propertyKeys.includes(propKey)) {
195
- yield { type: ValueErrorType.ObjectAdditionalProperties, schema, path: `${path}/${propKey}`, value: value[propKey], message: 'Unexpected property' };
194
+ for (const objectKey of globalThis.Object.keys(value)) {
195
+ if (!propertyKeys.includes(objectKey)) {
196
+ yield { type: ValueErrorType.ObjectAdditionalProperties, schema, path: `${path}/${objectKey}`, value: value[objectKey], message: `Unexpected property` };
196
197
  }
197
198
  }
198
199
  }
200
+ if (schema.required && schema.required.length > 0) {
201
+ const objectKeys = globalThis.Object.keys(value);
202
+ for (const requiredKey of schema.required) {
203
+ if (objectKeys.includes(requiredKey))
204
+ continue;
205
+ yield { type: ValueErrorType.ObjectRequiredProperties, schema: schema.properties[requiredKey], path: `${path}/${requiredKey}`, value: undefined, message: `Expected required property` };
206
+ }
207
+ }
199
208
  for (const propertyKey of propertyKeys) {
200
209
  const propertySchema = schema.properties[propertyKey];
201
210
  if (schema.required && schema.required.includes(propertyKey)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.24.46",
3
+ "version": "0.24.48",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/typebox.d.ts CHANGED
@@ -353,7 +353,7 @@ export declare class TypeBuilder {
353
353
  /** Creates a new object whose properties are omitted from the given object */
354
354
  Omit<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TOmit<T, UnionStringLiteralToTuple<K>>;
355
355
  /** Creates a new object whose properties are omitted from the given object */
356
- Omit<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: [...K], options?: ObjectOptions): TOmit<T, K>;
356
+ Omit<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TOmit<T, K>;
357
357
  /** Creates a tuple type from this functions parameters */
358
358
  Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
359
359
  /** Creates an object type whose properties are all optional */
@@ -361,7 +361,7 @@ export declare class TypeBuilder {
361
361
  /** Creates a object whose properties are picked from the given object */
362
362
  Pick<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TPick<T, UnionStringLiteralToTuple<K>>;
363
363
  /** Creates a object whose properties are picked from the given object */
364
- Pick<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: [...K], options?: ObjectOptions): TPick<T, K>;
364
+ Pick<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TPick<T, K>;
365
365
  /** Creates a promise type. This type cannot be represented in schema. */
366
366
  Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
367
367
  /** Creates an object whose properties are derived from the given string literal union. */