@sinclair/typebox 0.24.47 → 0.24.49
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/compiler/compiler.js +5 -0
- package/errors/errors.d.ts +18 -17
- package/errors/errors.js +36 -20
- package/guard/guard.js +4 -1
- package/package.json +1 -1
- package/readme.md +51 -51
- package/typebox.d.ts +7 -5
- package/value/cast.js +9 -0
- package/value/check.js +9 -0
package/compiler/compiler.js
CHANGED
|
@@ -190,6 +190,11 @@ var TypeCompiler;
|
|
|
190
190
|
yield `(Object.keys(${value}).every(key => ${keys}.includes(key)))`;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
+
if (index_2.TypeGuard.TSchema(schema.additionalProperties)) {
|
|
194
|
+
const expression = CreateExpression(schema.additionalProperties, 'value[key]');
|
|
195
|
+
const keys = `[${propertyKeys.map((key) => `'${key}'`).join(', ')}]`;
|
|
196
|
+
yield `(Object.keys(${value}).every(key => ${keys}.includes(key) || ${expression}))`;
|
|
197
|
+
}
|
|
193
198
|
for (const propertyKey of propertyKeys) {
|
|
194
199
|
const memberExpression = Property.Check(propertyKey) ? `${value}.${propertyKey}` : `${value}['${propertyKey}']`;
|
|
195
200
|
const propertySchema = schema.properties[propertyKey];
|
package/errors/errors.d.ts
CHANGED
|
@@ -25,23 +25,24 @@ export declare enum ValueErrorType {
|
|
|
25
25
|
ObjectMinProperties = 22,
|
|
26
26
|
ObjectMaxProperties = 23,
|
|
27
27
|
ObjectAdditionalProperties = 24,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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["
|
|
64
|
-
ValueErrorType[ValueErrorType["
|
|
65
|
-
ValueErrorType[ValueErrorType["
|
|
66
|
-
ValueErrorType[ValueErrorType["
|
|
67
|
-
ValueErrorType[ValueErrorType["
|
|
68
|
-
ValueErrorType[ValueErrorType["
|
|
69
|
-
ValueErrorType[ValueErrorType["
|
|
70
|
-
ValueErrorType[ValueErrorType["
|
|
71
|
-
ValueErrorType[ValueErrorType["
|
|
72
|
-
ValueErrorType[ValueErrorType["
|
|
73
|
-
ValueErrorType[ValueErrorType["
|
|
74
|
-
ValueErrorType[ValueErrorType["
|
|
75
|
-
ValueErrorType[ValueErrorType["
|
|
76
|
-
ValueErrorType[ValueErrorType["
|
|
77
|
-
ValueErrorType[ValueErrorType["
|
|
78
|
-
ValueErrorType[ValueErrorType["
|
|
79
|
-
ValueErrorType[ValueErrorType["
|
|
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,27 @@ var ValueErrors;
|
|
|
190
191
|
}
|
|
191
192
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
192
193
|
if (schema.additionalProperties === false) {
|
|
193
|
-
for (const
|
|
194
|
-
if (!propertyKeys.includes(
|
|
195
|
-
yield { type: ValueErrorType.ObjectAdditionalProperties, schema, path: `${path}/${
|
|
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
|
+
}
|
|
208
|
+
if (typeof schema.additionalProperties === 'object') {
|
|
209
|
+
for (const objectKey of globalThis.Object.keys(value)) {
|
|
210
|
+
if (propertyKeys.includes(objectKey))
|
|
211
|
+
continue;
|
|
212
|
+
yield* Visit(schema.additionalProperties, references, `${path}/${objectKey}`, value[objectKey]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
199
215
|
for (const propertyKey of propertyKeys) {
|
|
200
216
|
const propertySchema = schema.properties[propertyKey];
|
|
201
217
|
if (schema.required && schema.required.includes(propertyKey)) {
|
package/guard/guard.js
CHANGED
|
@@ -89,6 +89,9 @@ var TypeGuard;
|
|
|
89
89
|
function IsOptionalFormat(value) {
|
|
90
90
|
return value === undefined || (value !== undefined && IsString(value) && IsControlCharacterFree(value));
|
|
91
91
|
}
|
|
92
|
+
function IsOptionalSchema(value) {
|
|
93
|
+
return value === undefined || TSchema(value);
|
|
94
|
+
}
|
|
92
95
|
/** Returns true if the given schema is TAny */
|
|
93
96
|
function TAny(schema) {
|
|
94
97
|
return IsObject(schema) && schema[Types.Kind] === 'Any' && IsOptionalString(schema.$id);
|
|
@@ -194,7 +197,7 @@ var TypeGuard;
|
|
|
194
197
|
schema.type === 'object' &&
|
|
195
198
|
IsOptionalString(schema.$id) &&
|
|
196
199
|
IsObject(schema.properties) &&
|
|
197
|
-
IsOptionalBoolean(schema.additionalProperties) &&
|
|
200
|
+
(IsOptionalBoolean(schema.additionalProperties) || IsOptionalSchema(schema.additionalProperties)) &&
|
|
198
201
|
IsOptionalNumber(schema.minProperties) &&
|
|
199
202
|
IsOptionalNumber(schema.maxProperties))) {
|
|
200
203
|
return false;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1062,29 +1062,29 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1062
1062
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1063
1063
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1064
1064
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1065
|
-
│ Number │ 2000 │ '
|
|
1066
|
-
│ String │ 2000 │ '
|
|
1067
|
-
│ Boolean │ 2000 │ '
|
|
1068
|
-
│ Null │ 2000 │ '
|
|
1069
|
-
│ RegEx │ 2000 │ '
|
|
1070
|
-
│ ObjectA │ 2000 │ '
|
|
1071
|
-
│ ObjectB │ 2000 │ '
|
|
1072
|
-
│ Tuple │ 2000 │ '
|
|
1073
|
-
│ Union │ 2000 │ '
|
|
1074
|
-
│ Vector4 │ 2000 │ '
|
|
1075
|
-
│ Matrix4 │ 2000 │ '
|
|
1076
|
-
│ Literal_String │ 2000 │ '
|
|
1077
|
-
│ Literal_Number │ 2000 │ '
|
|
1078
|
-
│ Literal_Boolean │ 2000 │ '
|
|
1079
|
-
│ Array_Number │ 2000 │ '
|
|
1080
|
-
│ Array_String │ 2000 │ '
|
|
1081
|
-
│ Array_Boolean │ 2000 │ '
|
|
1082
|
-
│ Array_ObjectA │ 2000 │ '
|
|
1083
|
-
│ Array_ObjectB │ 2000 │ '
|
|
1084
|
-
│ Array_Tuple │ 2000 │ '
|
|
1085
|
-
│ Array_Union │ 2000 │ '
|
|
1086
|
-
│ Array_Vector4 │ 2000 │ '
|
|
1087
|
-
│ Array_Matrix4 │ 2000 │ '
|
|
1065
|
+
│ Number │ 2000 │ ' 428 ms' │ ' 12 ms' │ ' 35.67 x' │
|
|
1066
|
+
│ String │ 2000 │ ' 337 ms' │ ' 12 ms' │ ' 28.08 x' │
|
|
1067
|
+
│ Boolean │ 2000 │ ' 317 ms' │ ' 11 ms' │ ' 28.82 x' │
|
|
1068
|
+
│ Null │ 2000 │ ' 274 ms' │ ' 10 ms' │ ' 27.40 x' │
|
|
1069
|
+
│ RegEx │ 2000 │ ' 500 ms' │ ' 18 ms' │ ' 27.78 x' │
|
|
1070
|
+
│ ObjectA │ 2000 │ ' 2717 ms' │ ' 49 ms' │ ' 55.45 x' │
|
|
1071
|
+
│ ObjectB │ 2000 │ ' 2854 ms' │ ' 37 ms' │ ' 77.14 x' │
|
|
1072
|
+
│ Tuple │ 2000 │ ' 1224 ms' │ ' 21 ms' │ ' 58.29 x' │
|
|
1073
|
+
│ Union │ 2000 │ ' 1266 ms' │ ' 23 ms' │ ' 55.04 x' │
|
|
1074
|
+
│ Vector4 │ 2000 │ ' 1513 ms' │ ' 19 ms' │ ' 79.63 x' │
|
|
1075
|
+
│ Matrix4 │ 2000 │ ' 841 ms' │ ' 12 ms' │ ' 70.08 x' │
|
|
1076
|
+
│ Literal_String │ 2000 │ ' 327 ms' │ ' 8 ms' │ ' 40.88 x' │
|
|
1077
|
+
│ Literal_Number │ 2000 │ ' 358 ms' │ ' 6 ms' │ ' 59.67 x' │
|
|
1078
|
+
│ Literal_Boolean │ 2000 │ ' 355 ms' │ ' 5 ms' │ ' 71.00 x' │
|
|
1079
|
+
│ Array_Number │ 2000 │ ' 685 ms' │ ' 7 ms' │ ' 97.86 x' │
|
|
1080
|
+
│ Array_String │ 2000 │ ' 716 ms' │ ' 11 ms' │ ' 65.09 x' │
|
|
1081
|
+
│ Array_Boolean │ 2000 │ ' 732 ms' │ ' 6 ms' │ ' 122.00 x' │
|
|
1082
|
+
│ Array_ObjectA │ 2000 │ ' 3503 ms' │ ' 34 ms' │ ' 103.03 x' │
|
|
1083
|
+
│ Array_ObjectB │ 2000 │ ' 3626 ms' │ ' 38 ms' │ ' 95.42 x' │
|
|
1084
|
+
│ Array_Tuple │ 2000 │ ' 2095 ms' │ ' 21 ms' │ ' 99.76 x' │
|
|
1085
|
+
│ Array_Union │ 2000 │ ' 1577 ms' │ ' 22 ms' │ ' 71.68 x' │
|
|
1086
|
+
│ Array_Vector4 │ 2000 │ ' 2172 ms' │ ' 17 ms' │ ' 127.76 x' │
|
|
1087
|
+
│ Array_Matrix4 │ 2000 │ ' 1468 ms' │ ' 19 ms' │ ' 77.26 x' │
|
|
1088
1088
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1089
1089
|
```
|
|
1090
1090
|
|
|
@@ -1098,31 +1098,31 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1098
1098
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1099
1099
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1100
1100
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1101
|
-
│ Number │ 1000000 │ '
|
|
1102
|
-
│ String │ 1000000 │ '
|
|
1103
|
-
│ Boolean │ 1000000 │ '
|
|
1104
|
-
│ Null │ 1000000 │ '
|
|
1105
|
-
│ RegEx │ 1000000 │ '
|
|
1106
|
-
│ ObjectA │ 1000000 │ '
|
|
1107
|
-
│ ObjectB │ 1000000 │ '
|
|
1108
|
-
│ Tuple │ 1000000 │ '
|
|
1109
|
-
│ Union │ 1000000 │ '
|
|
1110
|
-
│ Recursive │ 1000000 │ '
|
|
1111
|
-
│ Vector4 │ 1000000 │ '
|
|
1112
|
-
│ Matrix4 │ 1000000 │ '
|
|
1113
|
-
│ Literal_String │ 1000000 │ '
|
|
1114
|
-
│ Literal_Number │ 1000000 │ '
|
|
1115
|
-
│ Literal_Boolean │ 1000000 │ ' 47 ms' │ '
|
|
1116
|
-
│ Array_Number │ 1000000 │ '
|
|
1117
|
-
│ Array_String │ 1000000 │ '
|
|
1118
|
-
│ Array_Boolean │ 1000000 │ '
|
|
1119
|
-
│ Array_ObjectA │ 1000000 │ '
|
|
1120
|
-
│ Array_ObjectB │ 1000000 │ '
|
|
1121
|
-
│ Array_Tuple │ 1000000 │ '
|
|
1122
|
-
│ Array_Union │ 1000000 │ '
|
|
1123
|
-
│ Array_Recursive │ 1000000 │ '
|
|
1124
|
-
│ Array_Vector4 │ 1000000 │ '
|
|
1125
|
-
│ Array_Matrix4 │ 1000000 │ '
|
|
1101
|
+
│ Number │ 1000000 │ ' 24 ms' │ ' 9 ms' │ ' 6 ms' │ ' 1.50 x' │
|
|
1102
|
+
│ String │ 1000000 │ ' 23 ms' │ ' 19 ms' │ ' 12 ms' │ ' 1.58 x' │
|
|
1103
|
+
│ Boolean │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1104
|
+
│ Null │ 1000000 │ ' 23 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1105
|
+
│ RegEx │ 1000000 │ ' 164 ms' │ ' 46 ms' │ ' 38 ms' │ ' 1.21 x' │
|
|
1106
|
+
│ ObjectA │ 1000000 │ ' 548 ms' │ ' 36 ms' │ ' 22 ms' │ ' 1.64 x' │
|
|
1107
|
+
│ ObjectB │ 1000000 │ ' 1118 ms' │ ' 51 ms' │ ' 38 ms' │ ' 1.34 x' │
|
|
1108
|
+
│ Tuple │ 1000000 │ ' 136 ms' │ ' 25 ms' │ ' 14 ms' │ ' 1.79 x' │
|
|
1109
|
+
│ Union │ 1000000 │ ' 338 ms' │ ' 27 ms' │ ' 16 ms' │ ' 1.69 x' │
|
|
1110
|
+
│ Recursive │ 1000000 │ ' 3251 ms' │ ' 416 ms' │ ' 98 ms' │ ' 4.24 x' │
|
|
1111
|
+
│ Vector4 │ 1000000 │ ' 146 ms' │ ' 23 ms' │ ' 12 ms' │ ' 1.92 x' │
|
|
1112
|
+
│ Matrix4 │ 1000000 │ ' 584 ms' │ ' 40 ms' │ ' 25 ms' │ ' 1.60 x' │
|
|
1113
|
+
│ Literal_String │ 1000000 │ ' 46 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1114
|
+
│ Literal_Number │ 1000000 │ ' 46 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
|
|
1115
|
+
│ Literal_Boolean │ 1000000 │ ' 47 ms' │ ' 21 ms' │ ' 10 ms' │ ' 2.10 x' │
|
|
1116
|
+
│ Array_Number │ 1000000 │ ' 456 ms' │ ' 31 ms' │ ' 19 ms' │ ' 1.63 x' │
|
|
1117
|
+
│ Array_String │ 1000000 │ ' 489 ms' │ ' 40 ms' │ ' 25 ms' │ ' 1.60 x' │
|
|
1118
|
+
│ Array_Boolean │ 1000000 │ ' 458 ms' │ ' 35 ms' │ ' 27 ms' │ ' 1.30 x' │
|
|
1119
|
+
│ Array_ObjectA │ 1000000 │ ' 13559 ms' │ ' 2568 ms' │ ' 1564 ms' │ ' 1.64 x' │
|
|
1120
|
+
│ Array_ObjectB │ 1000000 │ ' 15863 ms' │ ' 2744 ms' │ ' 2060 ms' │ ' 1.33 x' │
|
|
1121
|
+
│ Array_Tuple │ 1000000 │ ' 1694 ms' │ ' 96 ms' │ ' 63 ms' │ ' 1.52 x' │
|
|
1122
|
+
│ Array_Union │ 1000000 │ ' 4736 ms' │ ' 229 ms' │ ' 86 ms' │ ' 2.66 x' │
|
|
1123
|
+
│ Array_Recursive │ 1000000 │ ' 53804 ms' │ ' 6744 ms' │ ' 1167 ms' │ ' 5.78 x' │
|
|
1124
|
+
│ Array_Vector4 │ 1000000 │ ' 2244 ms' │ ' 99 ms' │ ' 46 ms' │ ' 2.15 x' │
|
|
1125
|
+
│ Array_Matrix4 │ 1000000 │ ' 11966 ms' │ ' 378 ms' │ ' 229 ms' │ ' 1.65 x' │
|
|
1126
1126
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1127
1127
|
```
|
|
1128
1128
|
|
|
@@ -1136,11 +1136,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1136
1136
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1137
1137
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1138
1138
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1139
|
-
│ typebox/compiler │ '
|
|
1139
|
+
│ typebox/compiler │ ' 51 kb' │ ' 25 kb' │ '2.00 x' │
|
|
1140
1140
|
│ typebox/conditional │ ' 42 kb' │ ' 17 kb' │ '2.46 x' │
|
|
1141
1141
|
│ typebox/format │ ' 0 kb' │ ' 0 kb' │ '2.66 x' │
|
|
1142
|
-
│ typebox/guard │ ' 21 kb' │ ' 10 kb' │ '2.
|
|
1143
|
-
│ typebox/value │ '
|
|
1142
|
+
│ typebox/guard │ ' 21 kb' │ ' 10 kb' │ '2.08 x' │
|
|
1143
|
+
│ typebox/value │ ' 74 kb' │ ' 34 kb' │ '2.16 x' │
|
|
1144
1144
|
│ typebox │ ' 11 kb' │ ' 6 kb' │ '1.91 x' │
|
|
1145
1145
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1146
1146
|
```
|
package/typebox.d.ts
CHANGED
|
@@ -177,14 +177,16 @@ export interface TProperties {
|
|
|
177
177
|
}
|
|
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
|
-
export
|
|
181
|
-
|
|
180
|
+
export declare type TAdditionalProperties = undefined | TSchema | boolean;
|
|
181
|
+
export interface ObjectOptions<A extends TAdditionalProperties = undefined> extends SchemaOptions {
|
|
182
|
+
additionalProperties?: A;
|
|
182
183
|
minProperties?: number;
|
|
183
184
|
maxProperties?: number;
|
|
184
185
|
}
|
|
185
|
-
export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
186
|
+
export interface TObject<T extends TProperties = TProperties, A extends TAdditionalProperties = undefined> extends TSchema, ObjectOptions<A> {
|
|
186
187
|
[Kind]: 'Object';
|
|
187
|
-
static: PropertiesReduce<T, this['params']>;
|
|
188
|
+
static: A extends TSchema ? PropertiesReduce<T, this['params']> & Record<string, Static<A, ['params']>> : PropertiesReduce<T, this['params']>;
|
|
189
|
+
additionalProperties?: A;
|
|
188
190
|
type: 'object';
|
|
189
191
|
properties: T;
|
|
190
192
|
required?: string[];
|
|
@@ -349,7 +351,7 @@ export declare class TypeBuilder {
|
|
|
349
351
|
/** Creates a number type */
|
|
350
352
|
Number(options?: NumericOptions): TNumber;
|
|
351
353
|
/** Creates an object type with the given properties */
|
|
352
|
-
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
354
|
+
Object<T extends TProperties, A extends TAdditionalProperties = undefined>(properties: T, options?: ObjectOptions<A>): TObject<T, A>;
|
|
353
355
|
/** Creates a new object whose properties are omitted from the given object */
|
|
354
356
|
Omit<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TOmit<T, UnionStringLiteralToTuple<K>>;
|
|
355
357
|
/** Creates a new object whose properties are omitted from the given object */
|
package/value/cast.js
CHANGED
|
@@ -230,6 +230,15 @@ var ValueCast;
|
|
|
230
230
|
continue;
|
|
231
231
|
result[key] = Visit(property, references, value[key]);
|
|
232
232
|
}
|
|
233
|
+
// additional schema properties
|
|
234
|
+
if (typeof schema.additionalProperties === 'object') {
|
|
235
|
+
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
236
|
+
for (const objectKey of globalThis.Object.keys(value)) {
|
|
237
|
+
if (propertyKeys.includes(objectKey))
|
|
238
|
+
continue;
|
|
239
|
+
result[objectKey] = Visit(schema.additionalProperties, references, value[objectKey]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
233
242
|
return result;
|
|
234
243
|
}
|
|
235
244
|
function Promise(schema, references, value) {
|
package/value/check.js
CHANGED
|
@@ -145,6 +145,15 @@ var ValueCheck;
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
+
if (typeof schema.additionalProperties === 'object') {
|
|
149
|
+
for (const objectKey of globalThis.Object.keys(value)) {
|
|
150
|
+
if (propertyKeys.includes(objectKey))
|
|
151
|
+
continue;
|
|
152
|
+
if (!Visit(schema.additionalProperties, references, value[objectKey])) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
148
157
|
for (const propertyKey of propertyKeys) {
|
|
149
158
|
const propertySchema = schema.properties[propertyKey];
|
|
150
159
|
if (schema.required && schema.required.includes(propertyKey)) {
|