@sinclair/typebox 0.28.9 → 0.28.11

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.
@@ -257,7 +257,7 @@ var TypeCompiler;
257
257
  }
258
258
  else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
259
259
  const keyCheck = PushLocal(`${new RegExp(Types.KeyResolver.ResolvePattern(schema))};`);
260
- const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, 'value[key]')})`;
260
+ const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
261
261
  yield `${check1} && ${check2}`;
262
262
  }
263
263
  else {
@@ -326,7 +326,7 @@ var TypeCompiler;
326
326
  }
327
327
  }
328
328
  if (typeof schema.additionalProperties === 'object') {
329
- const expression = CreateExpression(schema.additionalProperties, references, 'value[key]');
329
+ const expression = CreateExpression(schema.additionalProperties, references, `${value}[key]`);
330
330
  const keys = `[${knownKeys.map((key) => `'${key}'`).join(', ')}]`;
331
331
  yield `(Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key) || ${expression}))`;
332
332
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.28.9",
3
+ "version": "0.28.11",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -11,9 +11,8 @@
11
11
 
12
12
  [![npm version](https://badge.fury.io/js/%40sinclair%2Ftypebox.svg)](https://badge.fury.io/js/%40sinclair%2Ftypebox)
13
13
  [![Downloads](https://img.shields.io/npm/dm/%40sinclair%2Ftypebox.svg)](https://www.npmjs.com/package/%40sinclair%2Ftypebox)
14
- [![Install Size](https://packagephobia.com/badge?p=@sinclair/typebox)](https://packagephobia.com/result?p=@sinclair/typebox)
15
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
16
14
  [![GitHub CI](https://github.com/sinclairzx81/typebox/workflows/GitHub%20CI/badge.svg)](https://github.com/sinclairzx81/typebox/actions)
15
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
17
16
 
18
17
  </div>
19
18
 
@@ -109,6 +108,7 @@ License MIT
109
108
  - [Types](#typesystem-types)
110
109
  - [Formats](#typesystem-formats)
111
110
  - [Policies](#typesystem-policies)
111
+ - [Workbench](#workbench)
112
112
  - [Benchmark](#benchmark)
113
113
  - [Compile](#benchmark-compile)
114
114
  - [Validate](#benchmark-validate)
@@ -1346,26 +1346,31 @@ import { TypeSystem } from '@sinclair/typebox/system'
1346
1346
 
1347
1347
  ### Types
1348
1348
 
1349
- Use the `Type(...)` function to create a custom type. This function will return a type factory function that can be used to construct the type. The following creates a Point type.
1349
+ Use the `Type(...)` function to create custom types. This function lets you specify custom value assertion logic and will return a type factory function which is used to instance the type. This function accepts two generic arguments, the first is the inference type, the second is options used to constrain the type. The following creates a Vector type.
1350
1350
 
1351
1351
  ```typescript
1352
- type PointOptions = { } // The Type Options
1352
+ type VectorOptions = { abs: boolean }
1353
1353
 
1354
- type PointType = { x: number, y: number } // The Static<T> Type
1354
+ type Vector = { x: number, y: number }
1355
1355
 
1356
- const Point = TypeSystem.Type<PointType, PointOptions>('Point', (options, value) => {
1356
+ const Vector = TypeSystem.Type<Vector, VectorOptions>('Vector', (options, value) => {
1357
1357
  return (
1358
1358
  typeof value === 'object' && value !== null &&
1359
- typeof value.x === 'number' &&
1360
- typeof value.y === 'number'
1359
+ 'x' in value && typeof value.x === 'number' &&
1360
+ 'y' in value && typeof value.y === 'number' &&
1361
+ (options.abs ? (value.x === Math.abs(value.x) && value.y === Math.abs(value.y)) : true)
1361
1362
  )
1362
1363
  })
1363
1364
 
1364
- const T = Point()
1365
+ const T = Vector({ abs: true })
1366
+
1367
+ type T = Static<typeof T> // type T = Vector
1368
+
1369
+ const R1 = Value.Check(T, { x: 1, y: 1 }) // const R1 = true
1365
1370
 
1366
- type T = Static<typeof T> // type T = { x: number, y: number }
1371
+ const R2 = Value.Check(T, { x: 1, y: '1' }) // const R2 = false
1367
1372
 
1368
- const R = Value.Check(T, { x: 1, y: 2 }) // const R = true
1373
+ const R3 = Value.Check(T, { x: 1, y: -1 }) // const R3 = false
1369
1374
  ```
1370
1375
 
1371
1376
  <a name='typesystem-formats'></a>
@@ -1410,6 +1415,20 @@ TypeSystem.AllowArrayObjects = true
1410
1415
  TypeSystem.AllowNaN = true
1411
1416
  ```
1412
1417
 
1418
+ <a name='workbench'></a>
1419
+
1420
+ ## Workbench
1421
+
1422
+ TypeBox offers a web based code generation tool that can be used to create TypeBox types from TypeScript type definitions. This tool is written to prototype new TypeBox features, but can be used to rapidly convert TypeScript type definitions in to TypeBox types as well as raw JSON Schema.
1423
+
1424
+ [Workbench Link Here](https://sinclairzx81.github.io/typebox-workbench/)
1425
+
1426
+ <div align='center'>
1427
+
1428
+ <a href="https://sinclairzx81.github.io/typebox-workbench/"><img src="https://github.com/sinclairzx81/typebox/blob/master/workbench.png?raw=true" /></a>
1429
+
1430
+ </div>
1431
+
1413
1432
  <a name='benchmark'></a>
1414
1433
 
1415
1434
  ## Benchmark
package/typebox.js CHANGED
@@ -621,6 +621,14 @@ var ExtendsUndefined;
621
621
  function Check(schema) {
622
622
  if (schema[exports.Kind] === 'Undefined')
623
623
  return true;
624
+ if (schema[exports.Kind] === 'Not') {
625
+ const not = schema;
626
+ return Check(not.allOf[1]);
627
+ }
628
+ if (schema[exports.Kind] === 'Intersect') {
629
+ const intersect = schema;
630
+ return intersect.allOf.every((schema) => Check(schema));
631
+ }
624
632
  if (schema[exports.Kind] === 'Union') {
625
633
  const union = schema;
626
634
  return union.anyOf.some((schema) => Check(schema));
package/value/check.js CHANGED
@@ -254,8 +254,8 @@ var ValueCheck;
254
254
  if (!Visit(property, references, value[knownKey])) {
255
255
  return false;
256
256
  }
257
- if (Types.ExtendsUndefined.Check(property)) {
258
- return knownKey in value;
257
+ if (Types.ExtendsUndefined.Check(property) && !(knownKey in value)) {
258
+ return false;
259
259
  }
260
260
  }
261
261
  else {