typebox 1.0.11 → 1.0.12

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.
@@ -1,16 +1,3 @@
1
- export * as Schema from './schema.mjs';
2
- export * from './engine/index.mjs';
3
- export * from './types/index.mjs';
4
- export * from './build.mjs';
5
- export * from './check.mjs';
6
- export * from './errors.mjs';
7
- import { Build, BuildResult } from './build.mjs';
8
- import { Check } from './check.mjs';
9
- import { Errors } from './errors.mjs';
10
- declare const _default: {
11
- Build: typeof Build;
12
- BuildResult: typeof BuildResult;
13
- Check: typeof Check;
14
- Errors: typeof Errors;
15
- };
16
- export default _default;
1
+ export * from './schema.mjs';
2
+ import * as Schema from './schema.mjs';
3
+ export default Schema;
@@ -1,19 +1,9 @@
1
1
  // ------------------------------------------------------------------
2
- // Named
3
- // ------------------------------------------------------------------
4
- export * as Schema from './schema.mjs';
5
- // ------------------------------------------------------------------
6
2
  // Barrel
7
3
  // ------------------------------------------------------------------
8
- export * from './engine/index.mjs';
9
- export * from './types/index.mjs';
10
- export * from './build.mjs';
11
- export * from './check.mjs';
12
- export * from './errors.mjs';
4
+ export * from './schema.mjs';
13
5
  // ------------------------------------------------------------------
14
6
  // Default
15
7
  // ------------------------------------------------------------------
16
- import { Build, BuildResult } from './build.mjs';
17
- import { Check } from './check.mjs';
18
- import { Errors } from './errors.mjs';
19
- export default { Build, BuildResult, Check, Errors };
8
+ import * as Schema from './schema.mjs';
9
+ export default Schema;
@@ -5,4 +5,4 @@ export declare class AssertError extends Error {
5
5
  /** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
6
6
  export declare function Assert<Context extends TProperties, const Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type, value: unknown): asserts value is Result;
7
7
  /** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
8
- export declare function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type: TSchema, value: unknown): asserts value is Result;
8
+ export declare function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): asserts value is Result;
@@ -5,7 +5,7 @@ import { FromType } from './from-type.mjs';
5
5
  export function FromUnion(context, type, value) {
6
6
  for (const schema of type.anyOf) {
7
7
  const clean = FromType(context, schema, Clone(value));
8
- if (Check(context, type, clean))
8
+ if (Check(context, schema, clean))
9
9
  return clean;
10
10
  }
11
11
  return value;
@@ -3,6 +3,8 @@ import { AssertError } from '../assert/index.mjs';
3
3
  export declare class DecodeError extends AssertError {
4
4
  constructor(value: unknown, errors: object[]);
5
5
  }
6
+ /** Executes Decode callbacks only */
7
+ export declare function DecodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
6
8
  /**
7
9
  * Decodes a value against the given type by applying a sequence of Clone,
8
10
  * Default, Convert, and Clone operations, then executing any embedded Decode
@@ -23,6 +23,13 @@ function Assert(context, type, value) {
23
23
  return value;
24
24
  }
25
25
  // ------------------------------------------------------------------
26
+ // DecodeUnsafe
27
+ // ------------------------------------------------------------------
28
+ /** Executes Decode callbacks only */
29
+ export function DecodeUnsafe(context, type, value) {
30
+ return FromType('Decode', context, type, value);
31
+ }
32
+ // ------------------------------------------------------------------
26
33
  // Decoder
27
34
  // ------------------------------------------------------------------
28
35
  const Decoder = Pipeline([
@@ -31,7 +38,7 @@ const Decoder = Pipeline([
31
38
  (context, type, value) => Convert(context, type, value),
32
39
  (context, type, value) => Clean(context, type, value),
33
40
  (context, type, value) => Assert(context, type, value),
34
- (context, type, value) => FromType('Decode', context, type, value)
41
+ (context, type, value) => DecodeUnsafe(context, type, value)
35
42
  ]);
36
43
  /**
37
44
  * Decodes a value against the given type by applying a sequence of Clone,
@@ -3,6 +3,8 @@ import { AssertError } from '../assert/index.mjs';
3
3
  export declare class EncodeError extends AssertError {
4
4
  constructor(value: unknown, errors: object[]);
5
5
  }
6
+ /** Executes Encode callbacks only */
7
+ export declare function EncodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
6
8
  /** Encodes a value. */
7
9
  export declare function Encode<const Type extends TSchema, Result extends unknown = StaticEncode<Type>>(type: Type, value: unknown): Result;
8
10
  /** Encodes a value. */
@@ -23,11 +23,18 @@ function Assert(context, type, value) {
23
23
  return value;
24
24
  }
25
25
  // ------------------------------------------------------------------
26
+ // EncodeUnsafe
27
+ // ------------------------------------------------------------------
28
+ /** Executes Encode callbacks only */
29
+ export function EncodeUnsafe(context, type, value) {
30
+ return FromType('Encode', context, type, value);
31
+ }
32
+ // ------------------------------------------------------------------
26
33
  // Encoder
27
34
  // ------------------------------------------------------------------
28
35
  const Encoder = Pipeline([
29
36
  (_context, _type, value) => Clone(value),
30
- (context, type, value) => FromType('Encode', context, type, value),
37
+ (context, type, value) => EncodeUnsafe(context, type, value),
31
38
  (context, type, value) => Default(context, type, value),
32
39
  (context, type, value) => Convert(context, type, value),
33
40
  (context, type, value) => Clean(context, type, value),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "A Runtime Type System for JavaScript",
4
- "version": "1.0.11",
4
+ "version": "1.0.12",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"