@augment-vir/core 31.43.0 → 31.43.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.
@@ -1,15 +1,21 @@
1
1
  /**
2
- * A symbol used for {@link Branded}.
2
+ * Property key used to mark {@link Branded}.
3
3
  *
4
4
  * @category Internal
5
5
  */
6
- export declare const brandedTypeTag: unique symbol;
6
+ export type BrandedTypeTag = '$_brand_$';
7
+ /**
8
+ * Applies a branding to types for {@link Branded}.
9
+ *
10
+ * @category Internal
11
+ */
12
+ export type Brand<BrandKey extends PropertyKey> = Readonly<Record<BrandedTypeTag, Record<BrandKey, never>>>;
7
13
  /**
8
14
  * Brand any type so that it is no longer assignable to itself. For example, brand a database id
9
15
  * `string` type so that standard strings cannot be assigned to it.
10
16
  *
11
17
  * Largely inspired by the `Tagged` type from the `type-fest` package at
12
- * https://github.com/sindresorhus/type-fest/tree/687a89d94c4403d93ac5cb969ac7f492cee006cb/source
18
+ * https://github.com/sindresorhus/type-fest/blob/687a89d94c4403d93ac5cb969ac7f492cee006cb/source/tagged.d.ts
13
19
  *
14
20
  * @category Type
15
21
  * @example
@@ -22,21 +28,33 @@ export declare const brandedTypeTag: unique symbol;
22
28
  */
23
29
  export type Branded<OriginalType,
24
30
  /** The key for this brand. Two branded types with the same key will be assignable to each other. */
25
- BrandKey extends PropertyKey> = OriginalType & Readonly<{
26
- [brandedTypeTag]: Record<BrandKey, never>;
27
- }>;
31
+ BrandKey extends PropertyKey> = OriginalType & Brand<BrandKey>;
28
32
  /**
29
33
  * Unwrap a type brand applied via {@link Branded}.
30
34
  *
31
35
  * Largely inspired by the `Tagged` type from the `type-fest` package at
32
- * https://github.com/sindresorhus/type-fest/tree/687a89d94c4403d93ac5cb969ac7f492cee006cb/source
36
+ * https://github.com/sindresorhus/type-fest/blob/687a89d94c4403d93ac5cb969ac7f492cee006cb/source/tagged.d.ts
33
37
  *
34
38
  * @category Type
35
39
  */
36
- export type UnwrapBrand<BrandedType extends Branded<any, any>> = BrandedType extends Branded<infer OriginalType, any> ? OriginalType : BrandedType;
40
+ export type UnwrapBrand<BrandedType extends Branded<any, any>> = RemoveAllBranding<BrandedType>;
41
+ /**
42
+ * Removes all branding for {@link UnwrapBrand}.
43
+ *
44
+ * Largely inspired by the `RemoveAllTags` type from the `type-fest` package at
45
+ * https://github.com/sindresorhus/type-fest/blob/687a89d94c4403d93ac5cb969ac7f492cee006cb/source/tagged.d.ts
46
+ *
47
+ * @category Internal
48
+ */
49
+ export type RemoveAllBranding<T> = T extends Brand<any> ? {
50
+ [ThisBrand in keyof T[BrandedTypeTag]]: T extends Branded<infer OriginalType, ThisBrand> ? RemoveAllBranding<OriginalType> : never;
51
+ }[keyof T[BrandedTypeTag]] : T;
37
52
  /**
38
53
  * Wrap a value in a brand that matches its original type.
39
54
  *
40
55
  * @category Type
41
56
  */
42
- export declare function applyBrand<Brand extends Branded<any, any>>(value: UnwrapBrand<Brand>): Brand;
57
+ export declare function applyBrand<const NewBrand extends Branded<any, any> = never>(value: string): NewBrand;
58
+ export declare function applyBrand<const NewBrand extends Branded<any, any> = never>(value: string | undefined): NewBrand | undefined;
59
+ export declare function applyBrand<const NewBrand extends Branded<any, any> = never>(value: string | null): NewBrand | null;
60
+ export declare function applyBrand<const NewBrand extends Branded<any, any> = never>(value: string | undefined | null): NewBrand | undefined | null;
@@ -1,14 +1,3 @@
1
- /**
2
- * A symbol used for {@link Branded}.
3
- *
4
- * @category Internal
5
- */
6
- export const brandedTypeTag = Symbol.for('augment-vir-core-branded-type-tag');
7
- /**
8
- * Wrap a value in a brand that matches its original type.
9
- *
10
- * @category Type
11
- */
12
1
  export function applyBrand(value) {
13
2
  return value;
14
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/core",
3
- "version": "31.43.0",
3
+ "version": "31.43.2",
4
4
  "description": "Core augment-vir augments. Use @augment-vir/common instead.",
5
5
  "homepage": "https://github.com/electrovir/augment-vir",
6
6
  "bugs": {