Socket
Socket
Sign inDemoInstall

@sinclair/typebox

Package Overview
Dependencies
Maintainers
1
Versions
326
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sinclair/typebox - npm Package Compare versions

Comparing version 0.24.8 to 0.24.9

1

compiler/compiler.d.ts

@@ -17,2 +17,3 @@ import { ValueError } from '../value/errors';

}
/** Compiles TypeBox Types for Runtime Type Checking */
export declare namespace TypeCompiler {

@@ -19,0 +20,0 @@ /** Compiles the given type for runtime type checking. This compiler only accepts known TypeBox types non-inclusive of unsafe types. */

7

compiler/compiler.js

@@ -64,2 +64,3 @@ "use strict";

// -------------------------------------------------------------------
/** Compiles TypeBox Types for Runtime Type Checking */
var TypeCompiler;

@@ -279,3 +280,3 @@ (function (TypeCompiler) {

default:
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
throw new Error(`TypeCompiler: Unknown schema kind '${schema[Types.Kind]}'`);
}

@@ -297,5 +298,5 @@ }

if (!schema.$id)
throw Error(`Referenced schemas must specify an $id. Failed for '${JSON.stringify(schema)}'`);
throw new Error(`TypeCompiler: Referenced schemas must specify an $id.`);
if (referenceMap.has(schema.$id))
throw Error(`Duplicate schema $id detected for '${schema.$id}'`);
throw new Error(`TypeCompiler: Duplicate schema $id found for '${schema.$id}'`);
referenceMap.set(schema.$id, schema);

@@ -302,0 +303,0 @@ }

@@ -0,2 +1,2 @@

export type { ValueError } from '../value/errors';
export * from './compiler';
export * from '../value/errors';

@@ -41,2 +41,1 @@ "use strict";

__exportStar(require("./compiler"), exports);
__exportStar(require("../value/errors"), exports);
{
"name": "@sinclair/typebox",
"version": "0.24.8",
"version": "0.24.9",
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",

@@ -5,0 +5,0 @@ "keywords": [

@@ -557,3 +557,3 @@ <div align='center'>

In some cases, you may need schema definitions that are not provided by TypeBox. In these scenarios, it's common to want to define your own schema and static type inference rules. The `Type.Unsafe(...)` function provides this functionality, allowing you to specify both schema representation and a static type to infer. Consider the following which defines a `number` schema, but will infer as a `string`.
In some scenarios, you may need specific schemas not provided by TypeBox. In these cases, it's common to want to define a custom schema with custom static inference rules. The `Type.Unsafe(...)` function provides this functionality. This function enables one to specify both schema representation and a static type to infer. Consider the following which defines a `number` schema but infers as `string`.

@@ -568,3 +568,3 @@ ```typescript

The `Type.Unsafe(...)` function can be used with function generics to create custom schema representations for validators requiring specific schema representations. An example of which would be OpenAPI's `nullable` and `string-enum` representations which are not provided by TypeBox by default. The following demonstrates creating these schemas using the `Type.Unsafe(...)` function.
The `Type.Unsafe(...)` function can be combined with function generics to create user defined schemas for validators that need specific schema representations. An example of this might be the OpenAPI `nullable` and `string-enum` schema representations which are not provided by TypeBox. The following demonstrates creating these schemas using the `Type.Unsafe(...)` function.

@@ -571,0 +571,0 @@ ```typescript

@@ -230,3 +230,3 @@ "use strict";

if (schema.$id === undefined)
throw Error('Cannot create reference schema as target schema as has no $id');
throw Error('Type.Ref: Referenced schema must specify an $id');
return this.Create({ ...options, [exports.Kind]: 'Ref', $ref: schema.$id });

@@ -233,0 +233,0 @@ }

@@ -75,3 +75,2 @@ "use strict";

(function (ValueCast) {
const ids = new Map();
function Any(schema, references, value) {

@@ -125,3 +124,2 @@ return check_1.ValueCheck.Check(schema, references, value) ? value : create_1.ValueCreate.Create(schema, references);

return create_1.ValueCreate.Create(schema, references);
ids.set(schema.$id, schema);
const required = new Set(schema.required || []);

@@ -153,3 +151,3 @@ const result = {};

function Recursive(schema, references, value) {
throw Error('Cannot patch recursive schemas');
throw new Error('CastValue.Recursive: Cannot cast recursive schemas');
}

@@ -156,0 +154,0 @@ function Ref(schema, references, value) {

@@ -276,3 +276,3 @@ "use strict";

default:
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
throw new Error(`CheckValue: Unknown schema kind '${schema[Types.Kind]}'`);
}

@@ -279,0 +279,0 @@ }

@@ -73,4 +73,4 @@ "use strict";

for (const [key, val] of globalThis.Object.entries(value)) {
const facade = this;
facade[key] = val;
const self = this;
self[key] = val;
}

@@ -173,3 +173,3 @@ }

else {
throw new Error('Rec types require a default value');
throw new Error('ValueCreate.Recursive: Recursive types require a default value');
}

@@ -202,3 +202,3 @@ }

if (schema.default === undefined) {
throw Error('String types with patterns must specify a default value');
throw new Error('ValueCreate.String: String types with patterns must specify a default value');
}

@@ -237,3 +237,3 @@ else {

else if (schema.anyOf.length === 0) {
throw Error('Cannot generate Union with empty set');
throw new Error('ValueCreate: Cannot create Union with zero variants');
}

@@ -318,3 +318,3 @@ else {

default:
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
throw new Error(`ValueCreate: Unknown schema kind '${schema[Types.Kind]}'`);
}

@@ -321,0 +321,0 @@ }

@@ -162,3 +162,3 @@ "use strict";

if (reference === undefined)
throw new Error(`CheckValue.Ref: Cannot find schema with $id '${schema.$ref}'.`);
throw new Error(`ValueErrors.Ref: Cannot find schema with $id '${schema.$ref}'.`);
yield* Visit(reference, references, path, value);

@@ -169,3 +169,3 @@ }

if (reference === undefined)
throw new Error(`CheckValue.Ref: Cannot find schema with $id '${schema.$ref}'.`);
throw new Error(`ValueErrors.Self: Cannot find schema with $id '${schema.$ref}'.`);
yield* Visit(reference, references, path, value);

@@ -285,3 +285,3 @@ }

default:
throw Error(`Unknown schema kind '${schema[Types.Kind]}'`);
throw new Error(`ValueErrors: Unknown schema kind '${schema[Types.Kind]}'`);
}

@@ -288,0 +288,0 @@ }

@@ -0,1 +1,2 @@

export type { ValueError } from './errors';
export * from './value';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc