@sinclair/typebox 0.34.12 → 0.34.13

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.
@@ -11,18 +11,31 @@ export type TRefUnsafe<Type extends TSchema> = TUnsafe<Static<Type>>;
11
11
  /** `[Json]` Creates a Ref type.*/
12
12
  export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
13
13
  /**
14
- * @deprecated `[Json]` Creates a Ref type. The referenced type MUST contain a $id. The Ref(TSchema) signature was
15
- * deprecated on 0.34.0 in support of a new type referencing model (Module). Existing implementations using Ref(TSchema)
16
- * can migrate using the following. The Ref(TSchema) validation behavior of Ref will be preserved how the construction
17
- * of legacy Ref(TSchema) will require wrapping in TUnsafe (where TUnsafe is used for inference only)
14
+ * @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
15
+ * a `string` value for the reference (and not a schema).
16
+ *
17
+ * To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
18
18
  *
19
19
  * ```typescript
20
+ * // pre-0.34.0
21
+ *
22
+ * const T = Type.String({ $id: 'T' })
23
+ *
20
24
  * const R = Type.Ref(T)
21
25
  * ```
22
- * to
26
+ * should be changed to the following
27
+ *
28
+ * ```typescript
29
+ * // post-0.34.0
30
+ *
31
+ * const T = Type.String({ $id: 'T' })
32
+ *
33
+ * const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
34
+ * ```
35
+ * You can also create a generic function to replicate the pre-0.34.0 signature if required
23
36
  *
24
37
  * ```typescript
25
- * const R = Type.Unsafe<Static<T>>(T.$id)
38
+ * const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
26
39
  * ```
27
40
  */
28
41
  export declare function Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
@@ -151,18 +151,31 @@ export declare class JsonTypeBuilder {
151
151
  /** `[Json]` Creates a Ref type.*/
152
152
  Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
153
153
  /**
154
- * @deprecated `[Json]` Creates a Ref type. The referenced type MUST contain a $id. The Ref(TSchema) signature was
155
- * deprecated on 0.34.0 in support of a new type referencing model (Module). Existing implementations using Ref(TSchema)
156
- * can migrate using the following. The Ref(TSchema) validation behavior of Ref will be preserved how the construction
157
- * of legacy Ref(TSchema) will require wrapping in TUnsafe (where TUnsafe is used for inference only)
154
+ * @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
155
+ * a `string` value for the reference (and not a schema).
156
+ *
157
+ * To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
158
158
  *
159
159
  * ```typescript
160
+ * // pre-0.34.0
161
+ *
162
+ * const T = Type.String({ $id: 'T' })
163
+ *
160
164
  * const R = Type.Ref(T)
161
165
  * ```
162
- * to
166
+ * should be changed to the following
167
+ *
168
+ * ```typescript
169
+ * // post-0.34.0
170
+ *
171
+ * const T = Type.String({ $id: 'T' })
172
+ *
173
+ * const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
174
+ * ```
175
+ * You can also create a generic function to replicate the pre-0.34.0 signature if required
163
176
  *
164
177
  * ```typescript
165
- * const R = Type.Unsafe<Static<T>>(T.$id)
178
+ * const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
166
179
  * ```
167
180
  */
168
181
  Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
@@ -70,7 +70,7 @@ function TryConvertBigInt(value) {
70
70
  return IsStringNumeric(value) ? BigInt(truncateInteger(value)) : (0, index_5.IsNumber)(value) ? BigInt(Math.trunc(value)) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
71
71
  }
72
72
  function TryConvertString(value) {
73
- return IsValueToString(value) ? value.toString() : (0, index_5.IsSymbol)(value) && value.description !== undefined ? value.description.toString() : value;
73
+ return (0, index_5.IsSymbol)(value) && value.description !== undefined ? value.description.toString() : IsValueToString(value) ? value.toString() : value;
74
74
  }
75
75
  function TryConvertNumber(value) {
76
76
  return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
@@ -11,18 +11,31 @@ export type TRefUnsafe<Type extends TSchema> = TUnsafe<Static<Type>>;
11
11
  /** `[Json]` Creates a Ref type.*/
12
12
  export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
13
13
  /**
14
- * @deprecated `[Json]` Creates a Ref type. The referenced type MUST contain a $id. The Ref(TSchema) signature was
15
- * deprecated on 0.34.0 in support of a new type referencing model (Module). Existing implementations using Ref(TSchema)
16
- * can migrate using the following. The Ref(TSchema) validation behavior of Ref will be preserved how the construction
17
- * of legacy Ref(TSchema) will require wrapping in TUnsafe (where TUnsafe is used for inference only)
14
+ * @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
15
+ * a `string` value for the reference (and not a schema).
16
+ *
17
+ * To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
18
18
  *
19
19
  * ```typescript
20
+ * // pre-0.34.0
21
+ *
22
+ * const T = Type.String({ $id: 'T' })
23
+ *
20
24
  * const R = Type.Ref(T)
21
25
  * ```
22
- * to
26
+ * should be changed to the following
27
+ *
28
+ * ```typescript
29
+ * // post-0.34.0
30
+ *
31
+ * const T = Type.String({ $id: 'T' })
32
+ *
33
+ * const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
34
+ * ```
35
+ * You can also create a generic function to replicate the pre-0.34.0 signature if required
23
36
  *
24
37
  * ```typescript
25
- * const R = Type.Unsafe<Static<T>>(T.$id)
38
+ * const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
26
39
  * ```
27
40
  */
28
41
  export declare function Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
@@ -151,18 +151,31 @@ export declare class JsonTypeBuilder {
151
151
  /** `[Json]` Creates a Ref type.*/
152
152
  Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
153
153
  /**
154
- * @deprecated `[Json]` Creates a Ref type. The referenced type MUST contain a $id. The Ref(TSchema) signature was
155
- * deprecated on 0.34.0 in support of a new type referencing model (Module). Existing implementations using Ref(TSchema)
156
- * can migrate using the following. The Ref(TSchema) validation behavior of Ref will be preserved how the construction
157
- * of legacy Ref(TSchema) will require wrapping in TUnsafe (where TUnsafe is used for inference only)
154
+ * @deprecated `[Json]` Creates a Ref type. This signature was deprecated in 0.34.0 where Ref requires callers to pass
155
+ * a `string` value for the reference (and not a schema).
156
+ *
157
+ * To adhere to the 0.34.0 signature, Ref implementations should be updated to the following.
158
158
  *
159
159
  * ```typescript
160
+ * // pre-0.34.0
161
+ *
162
+ * const T = Type.String({ $id: 'T' })
163
+ *
160
164
  * const R = Type.Ref(T)
161
165
  * ```
162
- * to
166
+ * should be changed to the following
167
+ *
168
+ * ```typescript
169
+ * // post-0.34.0
170
+ *
171
+ * const T = Type.String({ $id: 'T' })
172
+ *
173
+ * const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))
174
+ * ```
175
+ * You can also create a generic function to replicate the pre-0.34.0 signature if required
163
176
  *
164
177
  * ```typescript
165
- * const R = Type.Unsafe<Static<T>>(T.$id)
178
+ * const LegacyRef = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T>>(Type.Ref(schema.$id!))
166
179
  * ```
167
180
  */
168
181
  Ref<Type extends TSchema>(type: Type, options?: SchemaOptions): TRefUnsafe<Type>;
@@ -66,7 +66,7 @@ function TryConvertBigInt(value) {
66
66
  return IsStringNumeric(value) ? BigInt(truncateInteger(value)) : IsNumber(value) ? BigInt(Math.trunc(value)) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
67
67
  }
68
68
  function TryConvertString(value) {
69
- return IsValueToString(value) ? value.toString() : IsSymbol(value) && value.description !== undefined ? value.description.toString() : value;
69
+ return IsSymbol(value) && value.description !== undefined ? value.description.toString() : IsValueToString(value) ? value.toString() : value;
70
70
  }
71
71
  function TryConvertNumber(value) {
72
72
  return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.12",
3
+ "version": "0.34.13",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",