typebox 1.1.16 → 1.1.18

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,9 +1,7 @@
1
1
  export interface TExternal {
2
- /** The name of the variable that holds external variables in generated code */
3
- identifier: string;
4
- /** An array of external variables */
2
+ identifier: 'External';
5
3
  variables: unknown[];
6
4
  }
7
- export declare function ResetExternal(): void;
8
5
  export declare function CreateVariable(value: unknown): string;
6
+ export declare function ResetExternal(): void;
9
7
  export declare function GetExternal(): TExternal;
@@ -1,34 +1,25 @@
1
1
  // deno-fmt-ignore-file
2
- const identifier = 'external_';
3
- let resetCount = 0;
4
2
  const state = {
5
- identifier: `${identifier}${resetCount}`,
3
+ identifier: 'External',
6
4
  variables: []
7
5
  };
8
6
  // ------------------------------------------------------------------
9
- // ResetExternals
10
- //
11
- // Each reset results in a new external group identifier. This is done
12
- // to prevent variable name overlap when generating and evaluating
13
- // multiple types in the same scope.
14
- //
15
- // ------------------------------------------------------------------
16
- export function ResetExternal() {
17
- state.identifier = `${identifier}${resetCount}`;
18
- state.variables = [];
19
- resetCount += 1;
20
- }
21
- // ------------------------------------------------------------------
22
7
  // CreateVariable
23
8
  // ------------------------------------------------------------------
24
9
  export function CreateVariable(value) {
25
- const call = `${state.identifier}[${state.variables.length}]`;
10
+ const call = `External[${state.variables.length}]`;
26
11
  state.variables.push(value);
27
12
  return call;
28
13
  }
29
14
  // ------------------------------------------------------------------
15
+ // ResetExternal
16
+ // ------------------------------------------------------------------
17
+ export function ResetExternal() {
18
+ state.variables = [];
19
+ }
20
+ // ------------------------------------------------------------------
30
21
  // GetExternals
31
22
  // ------------------------------------------------------------------
32
23
  export function GetExternal() {
33
- return state;
24
+ return { ...state };
34
25
  }
@@ -9,6 +9,6 @@ export declare class AssertError extends Error {
9
9
  constructor(source: string, value: unknown, errors: TLocalizedValidationError[]);
10
10
  }
11
11
  /** 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. */
12
- 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;
12
+ export declare function Assert<const Type extends TSchema>(type: Type, value: unknown): asserts value is Static<Type>;
13
13
  /** 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. */
14
- export declare function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): asserts value is Result;
14
+ export declare function Assert<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): asserts value is Static<Type, Context>;
@@ -1,3 +1,4 @@
1
+ // deno-fmt-ignore-file
1
2
  import { Arguments } from '../../system/arguments/index.mjs';
2
3
  import { Check } from '../check/index.mjs';
3
4
  import { Errors } from '../errors/index.mjs';
@@ -1,5 +1,5 @@
1
1
  import type { Static, TProperties, TSchema } from '../../type/index.mjs';
2
2
  /** Checks a value matches the provided type. */
3
- export declare function Check<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): value is Result;
3
+ export declare function Check<const Type extends TSchema>(type: Type, value: unknown): value is Static<Type>;
4
4
  /** Checks a value matches the provided type. */
5
- export declare function Check<Context extends TProperties, const Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type, value: unknown): value is Result;
5
+ export declare function Check<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): value is Static<Type, Context>;
@@ -6,17 +6,7 @@ export declare class DecodeError extends AssertError {
6
6
  }
7
7
  /** Executes Decode callbacks only */
8
8
  export declare function DecodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
9
- /**
10
- * Decodes a value against the given type by applying a sequence of Clone,
11
- * Default, Convert, and Clone operations, then executing any embedded Decode
12
- * callbacks. If the processing sequence fails to produce a value matching the
13
- * provided type, a DecodeError is thrown.
14
- */
15
- export declare function Decode<const Type extends TSchema, Result extends unknown = StaticDecode<Type>>(type: Type, value: unknown): Result;
16
- /**
17
- * Decodes a value against the given type by applying a sequence of Clone,
18
- * Default, Convert, and Clone operations, then executing any embedded Decode
19
- * callbacks. If the processing sequence fails to produce a value matching the
20
- * provided type, a DecodeError is thrown.
21
- */
22
- export declare function Decode<Context extends TProperties, const Type extends TSchema, Result extends unknown = StaticDecode<Type, Context>>(context: Context, type: Type, value: unknown): Result;
9
+ /** Decodes a value with the given type. */
10
+ export declare function Decode<const Type extends TSchema>(type: Type, value: unknown): StaticDecode<Type>;
11
+ /** Decodes a value with the given type. */
12
+ export declare function Decode<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticDecode<Type, Context>;
@@ -40,12 +40,7 @@ const Decoder = Pipeline([
40
40
  (context, type, value) => Assert(context, type, value),
41
41
  (context, type, value) => DecodeUnsafe(context, type, value)
42
42
  ]);
43
- /**
44
- * Decodes a value against the given type by applying a sequence of Clone,
45
- * Default, Convert, and Clone operations, then executing any embedded Decode
46
- * callbacks. If the processing sequence fails to produce a value matching the
47
- * provided type, a DecodeError is thrown.
48
- */
43
+ /** Decodes a value with the given type. */
49
44
  export function Decode(...args) {
50
45
  const [context, type, value] = Arguments.Match(args, {
51
46
  3: (context, type, value) => [context, type, value],
@@ -6,7 +6,7 @@ export declare class EncodeError extends AssertError {
6
6
  }
7
7
  /** Executes Encode callbacks only */
8
8
  export declare function EncodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
9
- /** Encodes a value. */
10
- export declare function Encode<const Type extends TSchema, Result extends unknown = StaticEncode<Type>>(type: Type, value: unknown): Result;
11
- /** Encodes a value. */
12
- export declare function Encode<Context extends TProperties, const Type extends TSchema, Result extends unknown = StaticEncode<Type, Context>>(context: Context, type: Type, value: unknown): Result;
9
+ /** Encodes a value with the given type. */
10
+ export declare function Encode<const Type extends TSchema>(type: Type, value: unknown): StaticEncode<Type>;
11
+ /** Encodes a value with the given type. */
12
+ export declare function Encode<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticEncode<Type, Context>;
@@ -40,7 +40,7 @@ const Encoder = Pipeline([
40
40
  (context, type, value) => Clean(context, type, value),
41
41
  (context, type, value) => Assert(context, type, value),
42
42
  ]);
43
- /** Encodes a value. */
43
+ /** Encodes a value with the given type. */
44
44
  export function Encode(...args) {
45
45
  const [context, type, value] = Arguments.Match(args, {
46
46
  3: (context, type, value) => [context, type, value],
@@ -1,5 +1,5 @@
1
1
  import type { TProperties, TSchema, Static } from '../../type/index.mjs';
2
2
  /** Creates a value from the provided type. This function will use `default` annotations if present. */
3
- export declare function Create<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type): Result;
3
+ export declare function Create<const Type extends TSchema>(type: Type): Static<Type>;
4
4
  /** Creates a value from the provided type. This function will use `default` annotations if present. */
5
- export declare function Create<const Context extends TProperties, Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type): Result;
5
+ export declare function Create<const Context extends TProperties, Type extends TSchema>(context: Context, type: Type): Static<Type, Context>;
@@ -6,6 +6,6 @@ export declare class ParseError extends AssertError {
6
6
  }
7
7
  export declare const Parser: import("../pipeline/pipeline.mjs").PipelineInterface;
8
8
  /** Parses a value with the given type. */
9
- export declare function Parse<const Type extends TSchema, Result extends unknown = StaticParse<Type>>(type: Type, value: unknown): Result;
9
+ export declare function Parse<const Type extends TSchema>(type: Type, value: unknown): StaticParse<Type>;
10
10
  /** Parses a value with the given type. */
11
- export declare function Parse<Context extends TProperties, const Type extends TSchema, Result extends unknown = StaticParse<Type, Context>>(context: Context, type: Type, value: unknown): Result;
11
+ export declare function Parse<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticParse<Type, Context>;
@@ -6,7 +6,7 @@ import type { TProperties, TSchema, Static } from '../../type/index.mjs';
6
6
  * default structures derived from the type. If the value already conforms to the type, no
7
7
  * action is performed.
8
8
  */
9
- export declare function Repair<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): Result;
9
+ export declare function Repair<const Type extends TSchema>(type: Type, value: unknown): Static<Type>;
10
10
  /**
11
11
  * Repairs a value to match the provided type. This function is intended for data migration
12
12
  * scenarios where existing values need to be migrating to an updated type. This function will
@@ -14,4 +14,4 @@ export declare function Repair<const Type extends TSchema, Result extends unknow
14
14
  * default structures derived from the type. If the value already conforms to the type, no
15
15
  * action is performed.
16
16
  */
17
- export declare function Repair<Context extends TProperties, const Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type, value: unknown): Result;
17
+ export declare function Repair<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): Static<Type, Context>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.1.16",
4
+ "version": "1.1.18",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"