@sinclair/typebox 0.30.4 → 0.31.0-dev-2

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/value/hash.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /*--------------------------------------------------------------------------
3
3
 
4
- @sinclair/typebox/hash
4
+ @sinclair/typebox/value
5
5
 
6
6
  The MIT License (MIT)
7
7
 
@@ -28,13 +28,13 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.Hash = exports.ByteMarker = exports.ValueHashError = void 0;
31
- const ValueGuard = require("./guard");
31
+ const guard_1 = require("./guard");
32
32
  // --------------------------------------------------------------------------
33
33
  // Errors
34
34
  // --------------------------------------------------------------------------
35
35
  class ValueHashError extends Error {
36
36
  constructor(value) {
37
- super(`Hash: Unable to hash value`);
37
+ super(`Unable to hash value`);
38
38
  this.value = value;
39
39
  }
40
40
  }
@@ -126,27 +126,27 @@ function UndefinedType(value) {
126
126
  return FNV1A64(ByteMarker.Undefined);
127
127
  }
128
128
  function Visit(value) {
129
- if (ValueGuard.IsArray(value))
129
+ if ((0, guard_1.IsArray)(value))
130
130
  return ArrayType(value);
131
- if (ValueGuard.IsBoolean(value))
131
+ if ((0, guard_1.IsBoolean)(value))
132
132
  return BooleanType(value);
133
- if (ValueGuard.IsBigInt(value))
133
+ if ((0, guard_1.IsBigInt)(value))
134
134
  return BigIntType(value);
135
- if (ValueGuard.IsDate(value))
135
+ if ((0, guard_1.IsDate)(value))
136
136
  return DateType(value);
137
- if (ValueGuard.IsNull(value))
137
+ if ((0, guard_1.IsNull)(value))
138
138
  return NullType(value);
139
- if (ValueGuard.IsNumber(value))
139
+ if ((0, guard_1.IsNumber)(value))
140
140
  return NumberType(value);
141
- if (ValueGuard.IsPlainObject(value))
141
+ if ((0, guard_1.IsPlainObject)(value))
142
142
  return ObjectType(value);
143
- if (ValueGuard.IsString(value))
143
+ if ((0, guard_1.IsString)(value))
144
144
  return StringType(value);
145
- if (ValueGuard.IsSymbol(value))
145
+ if ((0, guard_1.IsSymbol)(value))
146
146
  return SymbolType(value);
147
- if (ValueGuard.IsUint8Array(value))
147
+ if ((0, guard_1.IsUint8Array)(value))
148
148
  return Uint8ArrayType(value);
149
- if (ValueGuard.IsUndefined(value))
149
+ if ((0, guard_1.IsUndefined)(value))
150
150
  return UndefinedType(value);
151
151
  throw new ValueHashError(value);
152
152
  }
package/value/mutate.js CHANGED
@@ -28,27 +28,27 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.Mutate = exports.ValueMutateInvalidRootMutationError = exports.ValueMutateTypeMismatchError = void 0;
31
+ const guard_1 = require("./guard");
31
32
  const pointer_1 = require("./pointer");
32
- const ValueClone = require("./clone");
33
- const ValueGuard = require("./guard");
33
+ const clone_1 = require("./clone");
34
34
  // --------------------------------------------------------------------------
35
35
  // Errors
36
36
  // --------------------------------------------------------------------------
37
37
  class ValueMutateTypeMismatchError extends Error {
38
38
  constructor() {
39
- super('ValueMutate: Cannot assign due type mismatch of assignable values');
39
+ super('Cannot assign due type mismatch of assignable values');
40
40
  }
41
41
  }
42
42
  exports.ValueMutateTypeMismatchError = ValueMutateTypeMismatchError;
43
43
  class ValueMutateInvalidRootMutationError extends Error {
44
44
  constructor() {
45
- super('ValueMutate: Only object and array types can be mutated at the root level');
45
+ super('Only object and array types can be mutated at the root level');
46
46
  }
47
47
  }
48
48
  exports.ValueMutateInvalidRootMutationError = ValueMutateInvalidRootMutationError;
49
49
  function ObjectType(root, path, current, next) {
50
- if (!ValueGuard.IsPlainObject(current)) {
51
- pointer_1.ValuePointer.Set(root, path, ValueClone.Clone(next));
50
+ if (!(0, guard_1.IsPlainObject)(current)) {
51
+ pointer_1.ValuePointer.Set(root, path, (0, clone_1.Clone)(next));
52
52
  }
53
53
  else {
54
54
  const currentKeys = Object.keys(current);
@@ -69,8 +69,8 @@ function ObjectType(root, path, current, next) {
69
69
  }
70
70
  }
71
71
  function ArrayType(root, path, current, next) {
72
- if (!ValueGuard.IsArray(current)) {
73
- pointer_1.ValuePointer.Set(root, path, ValueClone.Clone(next));
72
+ if (!(0, guard_1.IsArray)(current)) {
73
+ pointer_1.ValuePointer.Set(root, path, (0, clone_1.Clone)(next));
74
74
  }
75
75
  else {
76
76
  for (let index = 0; index < next.length; index++) {
@@ -80,13 +80,13 @@ function ArrayType(root, path, current, next) {
80
80
  }
81
81
  }
82
82
  function TypedArrayType(root, path, current, next) {
83
- if (ValueGuard.IsTypedArray(current) && current.length === next.length) {
83
+ if ((0, guard_1.IsTypedArray)(current) && current.length === next.length) {
84
84
  for (let i = 0; i < current.length; i++) {
85
85
  current[i] = next[i];
86
86
  }
87
87
  }
88
88
  else {
89
- pointer_1.ValuePointer.Set(root, path, ValueClone.Clone(next));
89
+ pointer_1.ValuePointer.Set(root, path, (0, clone_1.Clone)(next));
90
90
  }
91
91
  }
92
92
  function ValueType(root, path, current, next) {
@@ -95,25 +95,25 @@ function ValueType(root, path, current, next) {
95
95
  pointer_1.ValuePointer.Set(root, path, next);
96
96
  }
97
97
  function Visit(root, path, current, next) {
98
- if (ValueGuard.IsArray(next))
98
+ if ((0, guard_1.IsArray)(next))
99
99
  return ArrayType(root, path, current, next);
100
- if (ValueGuard.IsTypedArray(next))
100
+ if ((0, guard_1.IsTypedArray)(next))
101
101
  return TypedArrayType(root, path, current, next);
102
- if (ValueGuard.IsPlainObject(next))
102
+ if ((0, guard_1.IsPlainObject)(next))
103
103
  return ObjectType(root, path, current, next);
104
- if (ValueGuard.IsValueType(next))
104
+ if ((0, guard_1.IsValueType)(next))
105
105
  return ValueType(root, path, current, next);
106
106
  }
107
107
  // --------------------------------------------------------------------------
108
108
  // Mutate
109
109
  // --------------------------------------------------------------------------
110
110
  function IsNonMutableValue(value) {
111
- return ValueGuard.IsTypedArray(value) || ValueGuard.IsValueType(value);
111
+ return (0, guard_1.IsTypedArray)(value) || (0, guard_1.IsValueType)(value);
112
112
  }
113
113
  function IsMismatchedValue(current, next) {
114
114
  // prettier-ignore
115
- return ((ValueGuard.IsPlainObject(current) && ValueGuard.IsArray(next)) ||
116
- (ValueGuard.IsArray(current) && ValueGuard.IsPlainObject(next)));
115
+ return (((0, guard_1.IsPlainObject)(current) && (0, guard_1.IsArray)(next)) ||
116
+ ((0, guard_1.IsArray)(current) && (0, guard_1.IsPlainObject)(next)));
117
117
  }
118
118
  // --------------------------------------------------------------------------
119
119
  // Mutate
package/value/pointer.js CHANGED
@@ -33,7 +33,7 @@ exports.ValuePointer = exports.ValuePointerRootDeleteError = exports.ValuePointe
33
33
  // --------------------------------------------------------------------------
34
34
  class ValuePointerRootSetError extends Error {
35
35
  constructor(value, path, update) {
36
- super('ValuePointer: Cannot set root value');
36
+ super('Cannot set root value');
37
37
  this.value = value;
38
38
  this.path = path;
39
39
  this.update = update;
@@ -42,7 +42,7 @@ class ValuePointerRootSetError extends Error {
42
42
  exports.ValuePointerRootSetError = ValuePointerRootSetError;
43
43
  class ValuePointerRootDeleteError extends Error {
44
44
  constructor(value, path) {
45
- super('ValuePointer: Cannot delete root value');
45
+ super('Cannot delete root value');
46
46
  this.value = value;
47
47
  this.path = path;
48
48
  }
@@ -0,0 +1,42 @@
1
+ import { ValueError } from '../errors/errors';
2
+ import * as Types from '../typebox';
3
+ export type CheckFunction = (schema: Types.TSchema, references: Types.TSchema[], value: unknown) => boolean;
4
+ export declare class TransformUnknownTypeError extends Types.TypeBoxError {
5
+ readonly schema: Types.TRef | Types.TThis;
6
+ constructor(schema: Types.TRef | Types.TThis);
7
+ }
8
+ export declare class TransformDecodeCheckError extends Types.TypeBoxError {
9
+ readonly schema: Types.TSchema;
10
+ readonly value: unknown;
11
+ readonly error: ValueError;
12
+ constructor(schema: Types.TSchema, value: unknown, error: ValueError);
13
+ }
14
+ export declare class TransformEncodeCheckError extends Types.TypeBoxError {
15
+ readonly schema: Types.TSchema;
16
+ readonly value: unknown;
17
+ readonly error: ValueError;
18
+ constructor(schema: Types.TSchema, value: unknown, error: ValueError);
19
+ }
20
+ export declare class TransformDecodeError extends Types.TypeBoxError {
21
+ readonly schema: Types.TSchema;
22
+ readonly value: unknown;
23
+ constructor(schema: Types.TSchema, value: unknown, error: any);
24
+ }
25
+ export declare class TransformEncodeError extends Types.TypeBoxError {
26
+ readonly schema: Types.TSchema;
27
+ readonly value: unknown;
28
+ constructor(schema: Types.TSchema, value: unknown, error: any);
29
+ }
30
+ /** Recursively checks a schema for transform codecs */
31
+ export declare namespace HasTransform {
32
+ /** Returns true if this schema contains a transform codec */
33
+ function Has(schema: Types.TSchema, references: Types.TSchema[]): boolean;
34
+ }
35
+ /** Decodes a value using transform decoders if available. Does not ensure correct results. */
36
+ export declare namespace DecodeTransform {
37
+ function Decode(schema: Types.TSchema, references: Types.TSchema[], value: unknown, check: CheckFunction): unknown;
38
+ }
39
+ /** Encodes a value using transform encoders if available. Does not ensure correct results. */
40
+ export declare namespace EncodeTransform {
41
+ function Encode(schema: Types.TSchema, references: Types.TSchema[], value: unknown, check: CheckFunction): unknown;
42
+ }