typebox 1.0.63 → 1.0.65
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/build/guard/emit.mjs +1 -1
- package/build/guard/guard.mjs +2 -1
- package/build/schema/static/if.d.mts +8 -0
- package/build/schema/static/if.mjs +2 -0
- package/build/schema/static/schema.d.mts +3 -1
- package/build/value/default/from-object.mjs +1 -1
- package/package.json +1 -1
- package/readme.md +0 -12
package/build/guard/emit.mjs
CHANGED
|
@@ -125,7 +125,7 @@ export function Keys(value) {
|
|
|
125
125
|
return `Object.getOwnPropertyNames(${value})`;
|
|
126
126
|
}
|
|
127
127
|
export function HasPropertyKey(value, key) {
|
|
128
|
-
const isProtoField = G.IsEqual(key, '"__proto__"') || G.IsEqual(key, '"
|
|
128
|
+
const isProtoField = G.IsEqual(key, '"__proto__"') || G.IsEqual(key, '"constructor"');
|
|
129
129
|
return isProtoField ? `Object.prototype.hasOwnProperty.call(${value}, ${key})` : `${key} in ${value}`;
|
|
130
130
|
}
|
|
131
131
|
export function IsDeepEqual(left, right) {
|
package/build/guard/guard.mjs
CHANGED
|
@@ -156,7 +156,8 @@ export function EveryAll(value, offset, callback) {
|
|
|
156
156
|
// --------------------------------------------------------------------------
|
|
157
157
|
/** Returns true if this value has this property key */
|
|
158
158
|
export function HasPropertyKey(value, key) {
|
|
159
|
-
|
|
159
|
+
const isProtoField = IsEqual(key, '__proto__') || IsEqual(key, 'constructor');
|
|
160
|
+
return isProtoField ? Object.prototype.hasOwnProperty.call(value, key) : key in value;
|
|
160
161
|
}
|
|
161
162
|
/** Returns object entries as `[RegExp, Value][]` */
|
|
162
163
|
export function EntriesRegExp(value) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { XSchema } from '../types/schema.mjs';
|
|
2
|
+
import type { XStaticSchema } from './schema.mjs';
|
|
3
|
+
import type { XIf } from '../types/if.mjs';
|
|
4
|
+
import type { XElse } from '../types/else.mjs';
|
|
5
|
+
import type { XThen } from '../types/then.mjs';
|
|
6
|
+
type XStaticIfReduce<Types extends unknown[], Result extends unknown = never> = (Types extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticIfReduce<Right, Result | Left> : Result);
|
|
7
|
+
export type XStaticIf<Stack extends string[], Root extends XSchema, Schema extends XIf, IfSchema extends XSchema, Then extends unknown[] = Schema extends XThen<infer ThenSchema extends XSchema> ? [XStaticSchema<Stack, Root, IfSchema> & XStaticSchema<Stack, Root, ThenSchema>] : [], Else extends unknown[] = Schema extends XElse<infer ElseSchema extends XSchema> ? [...Then, XStaticSchema<Stack, Root, ElseSchema>] : Then, Result extends unknown = Else extends [] ? unknown : XStaticIfReduce<Else>> = Result;
|
|
8
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import type { XAnyOf } from '../types/anyOf.mjs';
|
|
|
3
3
|
import type { XAllOf } from '../types/allOf.mjs';
|
|
4
4
|
import type { XConst } from '../types/const.mjs';
|
|
5
5
|
import type { XEnum } from '../types/enum.mjs';
|
|
6
|
+
import type { XIf } from '../types/if.mjs';
|
|
6
7
|
import type { XItems } from '../types/items.mjs';
|
|
7
8
|
import type { XOneOf } from '../types/oneOf.mjs';
|
|
8
9
|
import type { XPatternProperties } from '../types/patternProperties.mjs';
|
|
@@ -18,6 +19,7 @@ import type { XStaticAllOf } from './allOf.mjs';
|
|
|
18
19
|
import type { XStaticAnyOf } from './anyOf.mjs';
|
|
19
20
|
import type { XStaticConst } from './const.mjs';
|
|
20
21
|
import type { XStaticEnum } from './enum.mjs';
|
|
22
|
+
import type { XStaticIf } from './if.mjs';
|
|
21
23
|
import type { XStaticItems } from './items.mjs';
|
|
22
24
|
import type { XStaticOneOf } from './oneOf.mjs';
|
|
23
25
|
import type { XStaticPatternProperties } from './patternProperties.mjs';
|
|
@@ -32,7 +34,7 @@ type TFromKeywords<Stack extends string[], Root extends XSchema, Schema extends
|
|
|
32
34
|
Schema extends XAllOf<infer Types extends XSchema[]> ? XStaticAllOf<Stack, Root, Types> : unknown,
|
|
33
35
|
Schema extends XAnyOf<infer Types extends XSchema[]> ? XStaticAnyOf<Stack, Root, Types> : unknown,
|
|
34
36
|
Schema extends XConst<infer Value extends unknown> ? XStaticConst<Value> : unknown,
|
|
35
|
-
Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
|
|
37
|
+
Schema extends XIf<infer Type extends XSchema> ? XStaticIf<Stack, Root, Schema, Type> : Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
|
|
36
38
|
Schema extends XItems<infer Types extends XSchema[] | XSchema> ? XStaticItems<Stack, Root, Schema, Types> : unknown,
|
|
37
39
|
Schema extends XOneOf<infer Types extends XSchema[]> ? XStaticOneOf<Stack, Root, Types> : unknown,
|
|
38
40
|
Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticPatternProperties<Stack, Root, Properties> : unknown,
|
|
@@ -20,7 +20,7 @@ export function FromObject(context, type, value) {
|
|
|
20
20
|
value[key] = FromType(context, type.properties[key], value[key]);
|
|
21
21
|
}
|
|
22
22
|
// return if not additional properties
|
|
23
|
-
if (!IsAdditionalProperties(type))
|
|
23
|
+
if (!IsAdditionalProperties(type) || Guard.IsBoolean(type.additionalProperties))
|
|
24
24
|
return value;
|
|
25
25
|
// AdditionalProperties
|
|
26
26
|
for (const key of Guard.Keys(value)) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -254,18 +254,6 @@ const A = C.Parse({ // const A: {
|
|
|
254
254
|
}) // } = ...
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
It can also be used to accelerate remote libraries via Json Schema translation.
|
|
258
|
-
|
|
259
|
-
```typescript
|
|
260
|
-
const C = Compile(x.toJsonSchema(x.object({
|
|
261
|
-
x: x.number(),
|
|
262
|
-
y: x.number(),
|
|
263
|
-
z: x.number()
|
|
264
|
-
})))
|
|
265
|
-
|
|
266
|
-
const A = C.Check(...) // high performance runtime checking
|
|
267
|
-
```
|
|
268
|
-
|
|
269
257
|
## Contribute
|
|
270
258
|
|
|
271
259
|
TypeBox is open to community contribution. Please ensure you submit an issue before submitting a pull request. The TypeBox project prefers open community discussion before accepting new features.
|