@vicin/phantom 1.1.0 → 2.0.0

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/dist/index.d.ts CHANGED
@@ -1,17 +1,4 @@
1
1
  declare namespace assertors {
2
- /**
3
- * Creates a typed caster that assigns a {@link Brand} to a value.
4
- *
5
- * This is a zero-cost runtime assertion helper — it simply returns the value
6
- * with the brand's nominal type applied. Use it for simple branded primitives
7
- * where you know the value is valid.
8
- *
9
- * @deprecated To unify Api surface 'asIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
10
- *
11
- * @template B - The brand declaration to assign.
12
- * @returns A function that casts any value to the branded type.
13
- */
14
- const asBrand: <B extends Brand.Any>() => <T>(value: T) => Brand.Assign<B, T>;
15
2
  /**
16
3
  * Creates a typed caster that assigns an {@link Identity} to a value.
17
4
  *
@@ -86,6 +73,15 @@ declare namespace assertors {
86
73
  const revertTransformation: <Tr extends Transformation.Any>() => <T, I>(transformed: T, input: I) => Transformation.Revert<Tr, T, I>;
87
74
  }
88
75
 
76
+ declare const __Phantom: unique symbol;
77
+ declare const __Tag: unique symbol;
78
+ declare const __Label: unique symbol;
79
+ declare const __Base: unique symbol;
80
+ declare const __OriginalType: unique symbol;
81
+ declare const __Input: unique symbol;
82
+ declare const __Traits: unique symbol;
83
+ declare const __Variants: unique symbol;
84
+
89
85
  /**
90
86
  * Base-type metadata.
91
87
  *
@@ -95,28 +91,28 @@ declare namespace assertors {
95
91
  declare namespace BaseCore {
96
92
  /** Marker type for base constraints */
97
93
  type Any = {
98
- __Phantom: {
99
- __Base?: unknown;
94
+ [__Phantom]: {
95
+ [__Base]?: unknown;
100
96
  };
101
97
  };
102
98
  /** Declare a base type */
103
99
  type Of<Base> = {
104
- __Phantom: {
105
- __Base?: Base;
100
+ [__Phantom]: {
101
+ [__Base]?: Base;
106
102
  };
107
103
  };
108
104
  /** Conditionally declare a base type */
109
105
  type OfIfExists<Base> = [Base] extends [never] ? {} : Of<Base>;
110
106
  /** Extract the base type */
111
107
  type BaseOf<T> = T extends {
112
- __Phantom: {
113
- __Base?: infer Base;
108
+ [__Phantom]: {
109
+ [__Base]?: infer Base;
114
110
  };
115
111
  } ? Exclude<Base, undefined> : unknown;
116
112
  /** Check whether a base constraint exists */
117
113
  type HasBase<T, B = unknown> = T extends {
118
- __Phantom: {
119
- __Base?: B;
114
+ [__Phantom]: {
115
+ [__Base]?: B;
120
116
  };
121
117
  } ? true : false;
122
118
  }
@@ -129,32 +125,32 @@ declare namespace BaseCore {
129
125
  declare namespace InputCore {
130
126
  /** Marker type for input value */
131
127
  type Any = {
132
- __Phantom: {
133
- __Input: unknown;
128
+ [__Phantom]: {
129
+ [__Input]: unknown;
134
130
  };
135
131
  };
136
132
  /** Set input */
137
133
  type Of<Input> = {
138
- __Phantom: {
139
- __Input: Input;
134
+ [__Phantom]: {
135
+ [__Input]: Input;
140
136
  };
141
137
  };
142
138
  /** Conditionally set input */
143
139
  type OfIfExists<Input> = [Input] extends [never] ? {} : {
144
- __Phantom: {
145
- __Input: Input;
140
+ [__Phantom]: {
141
+ [__Input]: Input;
146
142
  };
147
143
  };
148
144
  /** Extract the input */
149
145
  type InputOf<T> = T extends {
150
- __Phantom: {
151
- __Input: infer Input;
146
+ [__Phantom]: {
147
+ [__Input]: infer Input;
152
148
  };
153
149
  } ? Input : never;
154
150
  /** Check whether an input exists */
155
151
  type HasInput<T, I = unknown> = T extends {
156
- __Phantom: {
157
- __Input: I;
152
+ [__Phantom]: {
153
+ [__Input]: I;
158
154
  };
159
155
  } ? true : false;
160
156
  }
@@ -167,28 +163,28 @@ declare namespace InputCore {
167
163
  declare namespace LabelCore {
168
164
  /** Marker type for labeled values */
169
165
  type Any = {
170
- __Phantom: {
171
- __Label?: string;
166
+ [__Phantom]: {
167
+ [__Label]?: string;
172
168
  };
173
169
  };
174
170
  /** Attach a label */
175
171
  type Of<Label extends string> = {
176
- __Phantom: {
177
- __Label?: Label;
172
+ [__Phantom]: {
173
+ [__Label]?: Label;
178
174
  };
179
175
  };
180
176
  /** Conditionally attach a label */
181
177
  type OfIfExists<Label extends string> = [Label] extends [never] ? {} : Of<Label>;
182
178
  /** Extract the label */
183
179
  type LabelOf<T> = T extends {
184
- __Phantom: {
185
- __Label?: infer Label;
180
+ [__Phantom]: {
181
+ [__Label]?: infer Label;
186
182
  };
187
183
  } ? Exclude<Label, undefined> : never;
188
184
  /** Check whether a label exists */
189
185
  type HasLabel<T, L extends string = string> = T extends {
190
- __Phantom: {
191
- __Label?: L;
186
+ [__Phantom]: {
187
+ [__Label]?: L;
192
188
  };
193
189
  } ? true : false;
194
190
  }
@@ -202,28 +198,28 @@ declare namespace LabelCore {
202
198
  declare namespace TagCore {
203
199
  /** Marker type for any tagged value */
204
200
  type Any = {
205
- __Phantom: {
206
- __Tag: string | symbol;
201
+ [__Phantom]: {
202
+ [__Tag]: string | symbol;
207
203
  };
208
204
  };
209
205
  /** Attach a specific tag */
210
206
  type Of<Tag extends string | symbol> = {
211
- __Phantom: {
212
- __Tag: Tag;
207
+ [__Phantom]: {
208
+ [__Tag]: Tag;
213
209
  };
214
210
  };
215
211
  /** Conditionally attach a tag if it exists */
216
212
  type OfIfExists<Tag extends string | symbol> = [Tag] extends [never] ? {} : Of<Tag>;
217
213
  /** Extract the tag from a type */
218
214
  type TagOf<T> = T extends {
219
- __Phantom: {
220
- __Tag: infer Tag;
215
+ [__Phantom]: {
216
+ [__Tag]: infer Tag;
221
217
  };
222
218
  } ? Tag : never;
223
219
  /** Check whether a type is tagged */
224
220
  type HasTag<T, Ta extends string | symbol = string | symbol> = T extends {
225
- __Phantom: {
226
- __Tag: Ta;
221
+ [__Phantom]: {
222
+ [__Tag]: Ta;
227
223
  };
228
224
  } ? true : false;
229
225
  }
@@ -237,44 +233,42 @@ declare namespace TagCore {
237
233
  declare namespace TraitsCore {
238
234
  /** Marker type for trait-bearing values */
239
235
  type Any = {
240
- __Phantom: {
241
- __Traits: {};
236
+ [__Phantom]: {
237
+ [__Traits]: {};
242
238
  };
243
239
  };
244
240
  /** Declare a single trait */
245
241
  type Of<Trait extends string | symbol> = {
246
- __Phantom: {
247
- __Traits: {
242
+ [__Phantom]: {
243
+ [__Traits]: {
248
244
  [K in Trait]: true;
249
245
  };
250
246
  };
251
247
  };
252
248
  /** Construct traits from an explicit trait map */
253
249
  type FromMap<Traits extends Record<string | symbol, true>> = {
254
- __Phantom: {
255
- __Traits: Traits;
250
+ [__Phantom]: {
251
+ [__Traits]: Traits;
256
252
  };
257
253
  };
258
254
  /** Conditionally declare a trait */
259
- type OfIfExists<Trait extends string | symbol> = [Trait] extends [
260
- never
261
- ] ? {} : Of<Trait>;
255
+ type OfIfExists<Trait extends string | symbol> = [Trait] extends [never] ? {} : Of<Trait>;
262
256
  /** Extract the trait map */
263
257
  type TraitsOf<T> = T extends {
264
- __Phantom: {
265
- __Traits: infer Traits;
258
+ [__Phantom]: {
259
+ [__Traits]: infer Traits;
266
260
  };
267
261
  } ? Traits extends Record<string | symbol, true> ? Traits : never : never;
268
262
  /** Extract trait keys */
269
263
  type TraitKeysOf<T> = T extends {
270
- __Phantom: {
271
- __Traits: infer Traits;
264
+ [__Phantom]: {
265
+ [__Traits]: infer Traits;
272
266
  };
273
267
  } ? keyof Traits : never;
274
268
  /** Check if any traits exist */
275
269
  type HasTraits<T, Tr extends string | symbol = string | symbol> = T extends {
276
- __Phantom: {
277
- __Traits: Record<Tr, true>;
270
+ [__Phantom]: {
271
+ [__Traits]: Record<Tr, true>;
278
272
  };
279
273
  } ? true : false;
280
274
  }
@@ -287,38 +281,44 @@ declare namespace TraitsCore {
287
281
  declare namespace VariantsCore {
288
282
  /** Marker type for variant-bearing values */
289
283
  type Any = {
290
- __Phantom: {
291
- __Variants: string;
284
+ [__Phantom]: {
285
+ [__Variants]: string;
292
286
  };
293
287
  };
294
288
  /** Declare allowed variants */
295
289
  type Of<Variants extends string> = {
296
- __Phantom: {
297
- __Variants: Variants;
290
+ [__Phantom]: {
291
+ [__Variants]: Variants;
298
292
  };
299
293
  };
300
294
  /** Conditionally declare variants */
301
295
  type OfIfExists<Variants extends string> = [Variants] extends [never] ? {} : Of<Variants>;
302
296
  /** Extract variant union */
303
297
  type VariantsOf<T> = T extends {
304
- __Phantom: {
305
- __Variants: infer Variants;
298
+ [__Phantom]: {
299
+ [__Variants]: infer Variants;
306
300
  };
307
301
  } ? Variants extends string ? Variants : never : never;
308
302
  /** Check whether variants exist */
309
303
  type HasVariants<T> = T extends {
310
- __Phantom: {
311
- __Variants: string;
304
+ [__Phantom]: {
305
+ [__Variants]: string;
312
306
  };
313
307
  } ? true : false;
314
308
  }
315
309
 
316
310
  /** Stip phantom metadata object from a type */
317
311
  type StripPhantom<T> = T extends {
318
- __Phantom: {
319
- __OriginalType?: infer O;
312
+ [__Phantom]: {
313
+ [__OriginalType]?: infer O;
314
+ };
315
+ } ? Exclude<O, undefined> : T extends {
316
+ [__Phantom]: {
317
+ [__Base]?: infer B;
320
318
  };
321
- } ? Exclude<O, undefined> : T;
319
+ } ? Exclude<B, undefined> : T extends {
320
+ [__Phantom]: object;
321
+ } ? unknown : T;
322
322
  /** run-time helper for 'StringPhantom', used for debugging mainly */
323
323
  declare const stripPhantom: <T>(value: T) => StripPhantom<T>;
324
324
  type _StripPhantom<T> = StripPhantom<T>;
@@ -336,10 +336,16 @@ declare namespace PhantomCore {
336
336
  type StripPhantom<T> = _StripPhantom<T>;
337
337
  /** run-time helper for 'StringPhantom', used for debugging mainly */
338
338
  const stripPhantom: <T>(value: T) => T extends {
339
- __Phantom: {
340
- __OriginalType?: infer O;
339
+ [__Phantom]: {
340
+ [__OriginalType]?: infer O;
341
341
  };
342
- } ? Exclude<O, undefined> : T;
342
+ } ? Exclude<O, undefined> : T extends {
343
+ [__Phantom]: {
344
+ [__Base]?: infer B;
345
+ };
346
+ } ? Exclude<B, undefined> : T extends {
347
+ [__Phantom]: object;
348
+ } ? unknown : T;
343
349
  }
344
350
 
345
351
  /** Interface of 'Brand' and 'Identity' errors. */
@@ -389,27 +395,27 @@ type ErrorType<E> = {
389
395
  * the original runtime type.
390
396
  */
391
397
  type WithMetadata<T, Change extends object> = PhantomCore.StripPhantom<T> & {
392
- __Phantom: Prettify<Merge<IfNever<PhantomCore.PhantomOf<T>>, Omit<IfNever<PhantomCore.PhantomOf<Change>>, '__Base'> & SetType<T>>>;
398
+ [__Phantom]: Prettify<Merge<IfNever<PhantomCore.PhantomOf<T>>, Omit<IfNever<PhantomCore.PhantomOf<Change>>, typeof __Base> & SetType<T>>>;
393
399
  };
394
400
  /**
395
401
  * Patch phantom metadata without touching the original type.
396
402
  * Used when mutating metadata declarations themselves.
397
403
  */
398
404
  type PatchMetadata<T, Change extends object> = {
399
- __Phantom: Prettify<Merge<IfNever<PhantomCore.PhantomOf<T>>, IfNever<PhantomCore.PhantomOf<Change>>>>;
405
+ [__Phantom]: Prettify<Merge<IfNever<PhantomCore.PhantomOf<T>>, IfNever<PhantomCore.PhantomOf<Change>>>>;
400
406
  };
401
407
  /**
402
408
  * Remove a metadata dimension while preserving the original type.
403
409
  */
404
- type WithoutMetadata<T, S extends string> = PhantomCore.StripPhantom<T> & {
405
- __Phantom: Prettify<Omit<IfNever<PhantomCore.PhantomOf<T>>, S> & SetType<T>>;
410
+ type WithoutMetadata<T, S extends symbol> = PhantomCore.StripPhantom<T> & {
411
+ [__Phantom]: Prettify<Omit<IfNever<PhantomCore.PhantomOf<T>>, S> & SetType<T>>;
406
412
  };
407
413
  /**
408
414
  * Update '__OriginalType' if the passed type is changed.
409
415
  */
410
- type HandleOriginalType<T> = Equals<Omit<PhantomCore.StripPhantom<T>, never>, Omit<T, '__Phantom'>> extends true ? T : Omit<T, '__Phantom'> & PatchMetadata<T, {
411
- __Phantom: {
412
- __OriginalType?: Omit<T, '__Phantom'>;
416
+ type HandleOriginalType<T> = Equals<Omit<PhantomCore.StripPhantom<T>, never>, Omit<T, typeof __Phantom>> extends true ? T : Omit<T, typeof __Phantom> & PatchMetadata<T, {
417
+ [__Phantom]: {
418
+ [__OriginalType]?: Omit<T, typeof __Phantom>;
413
419
  };
414
420
  }>;
415
421
  /**
@@ -423,61 +429,30 @@ type HandleOriginalType<T> = Equals<Omit<PhantomCore.StripPhantom<T>, never>, Om
423
429
  * additional phantom metadata.
424
430
  */
425
431
  type SetType<T> = T extends {
426
- __Phantom: {
427
- __OriginalType?: infer O;
432
+ [__Phantom]: {
433
+ [__OriginalType]?: infer O;
428
434
  };
429
435
  } ? {
430
- __OriginalType?: O;
436
+ [__OriginalType]?: O;
431
437
  } : {
432
- __OriginalType?: T;
438
+ [__OriginalType]?: T;
433
439
  };
434
440
  /** --------------------------------------
435
441
  * Generic helpers
436
442
  * --------------------------------------- */
437
443
  /** Prettify type */
438
444
  type Prettify<T> = {
439
- [K in keyof T]: K extends '__Phantom' | '__Traits' ? Prettify<T[K]> : T[K];
445
+ [K in keyof T]: K extends typeof __Phantom | typeof __Traits ? Prettify<T[K]> : T[K];
440
446
  } & {};
441
447
  /** Check equality and returns true or false */
442
- type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
448
+ type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
443
449
  /** Type to replace 'never' with another type */
444
450
  type IfNever<T, R = {}> = [T] extends [never] ? R : T;
445
451
  /** Get intersection from union */
446
- type IntersectOf<U extends any> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
452
+ type IntersectOf<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
447
453
  /** Merge two objects. if matching keys between the two exists, the second object key value is used. */
448
454
  type Merge<O1 extends object, O2 extends object> = Prettify<Omit<O1, keyof O2> & O2>;
449
455
 
450
- /**
451
- * Branding API.
452
- *
453
- * Brands provide nominal typing for otherwise identical values.
454
- * A value may only be branded once.
455
- *
456
- * @deprecated To unify Api surface 'Identity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
457
- */
458
- declare namespace BrandCore {
459
- /** Type guard for any brand. */
460
- export type Any = TagCore.Of<string | symbol>;
461
- /** Declare a brand */
462
- export type Declare<T extends string | symbol, L extends string = never> = Prettify<TagCore.Of<T> & LabelCore.OfIfExists<L>>;
463
- /**
464
- * Assign a brand to a value.
465
- * Fails if the value is already branded.
466
- */
467
- export type Assign<B extends Any, T> = T extends ErrorType<any> ? T : _Assign<B, HandleOriginalType<T>>;
468
- /** Internal implementation of 'Brand.Assign' */
469
- type _Assign<B extends Any, T> = TagCore.HasTag<T> extends true ? ErrorType<Errors<B, T>['alreadyBranded']> : WithMetadata<T, B>;
470
- /**
471
- * Assign a brand if possible, otherwise return the original type.
472
- */
473
- export type AssignSafe<B extends Any, T> = T extends ErrorType<any> ? T : _AssignSafe<B, HandleOriginalType<T>>;
474
- /** Internal implementation of 'Brand.AssignSafe' */
475
- type _AssignSafe<B extends Any, T> = TagCore.HasTag<T> extends true ? T : WithMetadata<T, B>;
476
- /** Check whether value is branded with */
477
- export type isBrand<T, B extends Any> = T extends B ? true : false;
478
- export { };
479
- }
480
-
481
456
  /**
482
457
  * Identity API.
483
458
  *
@@ -489,7 +464,7 @@ declare namespace IdentityCore {
489
464
  /** Type guard for any identity. */
490
465
  export type Any = TagCore.Of<string | symbol>;
491
466
  /** Declare an identity */
492
- export type Declare<T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = IfNever<B, unknown> & Prettify<TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
467
+ export type Declare<T extends string | symbol, L extends string = never, B = never, V extends string = never> = IfNever<B, unknown> & Prettify<TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
493
468
  /**
494
469
  * Assign an identity to a value.
495
470
  * Enforces base-type compatibility.
@@ -534,11 +509,11 @@ declare namespace TraitCore {
534
509
  /** Remove a trait */
535
510
  export type Drop<Tr extends Any, T> = T extends ErrorType<any> ? T : _Drop<Tr, HandleOriginalType<T>>;
536
511
  /** Internal implementation of 'Trait.Drop' */
537
- type _Drop<Tr extends Any, T> = Equals<TraitsCore.TraitKeysOf<Tr>, TraitsCore.TraitKeysOf<T>> extends true ? Equals<keyof PhantomCore.PhantomOf<T>, '__OriginalType' | '__Traits'> extends true ? PhantomCore.StripPhantom<T> : WithoutMetadata<T, '__Traits'> : WithMetadata<T, TraitsCore.FromMap<Omit<TraitsCore.TraitsOf<T>, TraitsCore.TraitKeysOf<Tr>>>>;
512
+ type _Drop<Tr extends Any, T> = Equals<TraitsCore.TraitKeysOf<Tr>, TraitsCore.TraitKeysOf<T>> extends true ? Equals<keyof PhantomCore.PhantomOf<T>, typeof __OriginalType | typeof __Traits> extends true ? PhantomCore.StripPhantom<T> : WithoutMetadata<T, typeof __Traits> : WithMetadata<T, TraitsCore.FromMap<Omit<TraitsCore.TraitsOf<T>, TraitsCore.TraitKeysOf<Tr>>>>;
538
513
  /** Remove multiple traits */
539
514
  export type DropMulti<Tr extends readonly Any[], T> = T extends ErrorType<any> ? T : _DropMulti<Tr, HandleOriginalType<T>>;
540
515
  /** Internal implementation of 'Trait.DropMulti' */
541
- type _DropMulti<Tr extends readonly Any[], T> = Equals<TraitsCore.TraitKeysOf<IntersectOf<Tr[number]>>, TraitsCore.TraitKeysOf<T>> extends true ? Equals<keyof PhantomCore.PhantomOf<T>, '__OriginalType' | '__Traits'> extends true ? PhantomCore.StripPhantom<T> : WithoutMetadata<T, '__Traits'> : WithMetadata<T, TraitsCore.FromMap<Omit<TraitsCore.TraitsOf<T>, TraitsCore.TraitKeysOf<IntersectOf<Tr[number]>>>>>;
516
+ type _DropMulti<Tr extends readonly Any[], T> = Equals<TraitsCore.TraitKeysOf<IntersectOf<Tr[number]>>, TraitsCore.TraitKeysOf<T>> extends true ? Equals<keyof PhantomCore.PhantomOf<T>, typeof __OriginalType | typeof __Traits> extends true ? PhantomCore.StripPhantom<T> : WithoutMetadata<T, typeof __Traits> : WithMetadata<T, TraitsCore.FromMap<Omit<TraitsCore.TraitsOf<T>, TraitsCore.TraitKeysOf<IntersectOf<Tr[number]>>>>>;
542
517
  /** Check whether value has trait */
543
518
  export type HasTrait<T, Tr extends Any> = T extends Tr ? true : false;
544
519
  export { };
@@ -554,7 +529,7 @@ declare namespace TransformationCore {
554
529
  /** Type guard for any transformation. */
555
530
  export type Any = InputCore.Of<any> & TagCore.Of<string | symbol>;
556
531
  /** Declare a transformation */
557
- export type Declare<I, T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = IfNever<B, unknown> & Prettify<InputCore.Of<I> & TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
532
+ export type Declare<I, T extends string | symbol, L extends string = never, B = never, V extends string = never> = IfNever<B, unknown> & Prettify<InputCore.Of<I> & TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
558
533
  /**
559
534
  * Apply a transformation to a value.
560
535
  * Enforces base-type compatibility.
@@ -664,26 +639,6 @@ declare namespace Traits {
664
639
  /** Check if any traits exist */
665
640
  type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
666
641
  }
667
- /**
668
- * Branding API.
669
- *
670
- * Brands provide nominal typing for otherwise identical values.
671
- * A value may only be branded once.
672
- *
673
- * @deprecated To unify Api surface 'Identity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
674
- */
675
- declare namespace Brand {
676
- /** Type guard for any brand. */
677
- type Any = BrandCore.Any;
678
- /** Declare a brand */
679
- type Declare<T extends string | symbol, L extends string = never> = BrandCore.Declare<T, L>;
680
- /** Assign a brand to a value. Fails if the value is already branded */
681
- type Assign<B extends Any, T> = BrandCore.Assign<B, T>;
682
- /** Assign a brand if possible, otherwise return the original type */
683
- type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;
684
- /** Check whether value is branded with */
685
- type isBrand<T, B extends Any> = BrandCore.isBrand<T, B>;
686
- }
687
642
  /**
688
643
  * Identity API.
689
644
  *
@@ -695,7 +650,7 @@ declare namespace Identity {
695
650
  /** Type guard for any identity. */
696
651
  type Any = IdentityCore.Any;
697
652
  /** Declare an identity */
698
- type Declare<T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = IdentityCore.Declare<T, L, B, V>;
653
+ type Declare<T extends string | symbol, L extends string = never, B = never, V extends string = never> = IdentityCore.Declare<T, L, B, V>;
699
654
  /** Assign an identity to a value. Enforces base-type compatibility */
700
655
  type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;
701
656
  /** Safe identity assignment */
@@ -739,7 +694,7 @@ declare namespace Transformation {
739
694
  /** Type guard for any transformation. */
740
695
  type Any = TransformationCore.Any;
741
696
  /** Declare a transformation */
742
- type Declare<I, T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = TransformationCore.Declare<I, T, L, B, V>;
697
+ type Declare<I, T extends string | symbol, L extends string = never, B = never, V extends string = never> = TransformationCore.Declare<I, T, L, B, V>;
743
698
  /** Apply a transformation to a value. Enforces base-type compatibility */
744
699
  type Apply<Tr extends Any, I, T> = TransformationCore.Apply<Tr, I, T>;
745
700
  /** Revert a transformation */
@@ -782,12 +737,6 @@ declare namespace Inspect {
782
737
  type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
783
738
  /** Check if any traits exist */
784
739
  type HasTraits<T> = TraitsCore.HasTraits<T>;
785
- /**
786
- * Check whether value is branded with
787
- *
788
- * @deprecated To unify Api surface 'isIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
789
- */
790
- type isBrand<T, B extends BrandCore.Any> = BrandCore.isBrand<T, B>;
791
740
  /** Check whether value is branded with */
792
741
  type isIdentity<T, I extends IdentityCore.Any> = IdentityCore.isIdentity<T, I>;
793
742
  /** Check whether value has trait */
@@ -796,20 +745,6 @@ declare namespace Inspect {
796
745
  type isTransformed<T, Tr extends TransformationCore.Any> = TransformationCore.isTransformed<T, Tr>;
797
746
  }
798
747
 
799
- /**
800
- * Creates a typed caster that assigns a {@link Brand} to a value.
801
- *
802
- * This is a zero-cost runtime assertion helper — it simply returns the value
803
- * with the brand's nominal type applied. Use it for simple branded primitives
804
- * where you know the value is valid.
805
- *
806
- * @deprecated To unify Api surface 'asIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
807
- *
808
- * @template B - The brand declaration to assign.
809
- * @returns A function that casts any value to the branded type.
810
- */
811
- declare const asBrand: <B extends Brand.Any>() => <T>(value: T) => Brand.Assign<B, T>;
812
-
813
748
  /**
814
749
  * Creates a typed caster that assigns an {@link Identity} to a value.
815
750
  *
@@ -1016,26 +951,6 @@ declare namespace Phantom {
1016
951
  /** Check if any traits exist */
1017
952
  type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
1018
953
  }
1019
- /**
1020
- * Branding API.
1021
- *
1022
- * Brands provide nominal typing for otherwise identical values.
1023
- * A value may only be branded once.
1024
- *
1025
- * @deprecated To unify Api surface 'Identity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
1026
- */
1027
- namespace Brand {
1028
- /** Type guard for any brand. */
1029
- type Any = BrandCore.Any;
1030
- /** Declare a brand */
1031
- type Declare<T extends string | symbol, L extends string = never> = BrandCore.Declare<T, L>;
1032
- /** Assign a brand to a value. Fails if the value is already branded */
1033
- type Assign<B extends Any, T> = BrandCore.Assign<B, T>;
1034
- /** Assign a brand if possible, otherwise return the original type */
1035
- type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;
1036
- /** Check whether value is branded with */
1037
- type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
1038
- }
1039
954
  /**
1040
955
  * Identity API.
1041
956
  *
@@ -1047,7 +962,7 @@ declare namespace Phantom {
1047
962
  /** Type guard for any identity. */
1048
963
  type Any = IdentityCore.Any;
1049
964
  /** Declare an identity */
1050
- type Declare<T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = IdentityCore.Declare<T, L, B, V>;
965
+ type Declare<T extends string | symbol, L extends string = never, B = never, V extends string = never> = IdentityCore.Declare<T, L, B, V>;
1051
966
  /** Assign an identity to a value. Enforces base-type compatibility */
1052
967
  type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;
1053
968
  /** Safe identity assignment */
@@ -1091,7 +1006,7 @@ declare namespace Phantom {
1091
1006
  /** Type guard for any transformation. */
1092
1007
  type Any = TransformationCore.Any;
1093
1008
  /** Declare a transformation */
1094
- type Declare<I, T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = TransformationCore.Declare<I, T, L, B, V>;
1009
+ type Declare<I, T extends string | symbol, L extends string = never, B = never, V extends string = never> = TransformationCore.Declare<I, T, L, B, V>;
1095
1010
  /** Apply a transformation to a value. Enforces base-type compatibility */
1096
1011
  type Apply<Tr extends Any, I, T> = TransformationCore.Apply<Tr, I, T>;
1097
1012
  /** Revert a transformation */
@@ -1113,10 +1028,16 @@ declare namespace Phantom {
1113
1028
  type StripPhantom<T> = PhantomCore.StripPhantom<T>;
1114
1029
  /** run-time helper for 'StringPhantom', used for debugging mainly */
1115
1030
  const stripPhantom: <T>(value: T) => T extends {
1116
- __Phantom: {
1117
- __OriginalType?: infer O;
1031
+ [__Phantom]: {
1032
+ [__OriginalType]?: infer O;
1033
+ };
1034
+ } ? Exclude<O, undefined> : T extends {
1035
+ [__Phantom]: {
1036
+ [__Base]?: infer B;
1118
1037
  };
1119
- } ? Exclude<O, undefined> : T;
1038
+ } ? Exclude<B, undefined> : T extends {
1039
+ [__Phantom]: object;
1040
+ } ? unknown : T;
1120
1041
  /** Extract the label */
1121
1042
  type LabelOf<T> = LabelCore.LabelOf<T>;
1122
1043
  /** Check whether a base constraint exists */
@@ -1143,12 +1064,6 @@ declare namespace Phantom {
1143
1064
  type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
1144
1065
  /** Check if any traits exist */
1145
1066
  type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
1146
- /**
1147
- * Check whether value is branded with
1148
- *
1149
- * @deprecated To unify Api surface 'isIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
1150
- */
1151
- type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
1152
1067
  /** Check whether value is branded with */
1153
1068
  type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<T, I>;
1154
1069
  /** Check whether value has trait */
@@ -1160,19 +1075,6 @@ declare namespace Phantom {
1160
1075
  * assertors
1161
1076
  * --------------------------------------- */
1162
1077
  namespace assertors {
1163
- /**
1164
- * Creates a typed caster that assigns a {@link Brand} to a value.
1165
- *
1166
- * This is a zero-cost runtime assertion helper — it simply returns the value
1167
- * with the brand's nominal type applied. Use it for simple branded primitives
1168
- * where you know the value is valid.
1169
- *
1170
- * @deprecated To unify Api surface 'asIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
1171
- *
1172
- * @template B - The brand declaration to assign.
1173
- * @returns A function that casts any value to the branded type.
1174
- */
1175
- const asBrand: <B extends Brand.Any>() => <T>(value: T) => Brand.Assign<B, T>;
1176
1078
  /**
1177
1079
  * Creates a typed caster that assigns an {@link Identity} to a value.
1178
1080
  *
@@ -1246,19 +1148,6 @@ declare namespace Phantom {
1246
1148
  */
1247
1149
  const revertTransformation: <Tr extends Transformation.Any>() => <T, I>(transformed: T, input: I) => Transformation.Revert<Tr, T, I>;
1248
1150
  }
1249
- /**
1250
- * Creates a typed caster that assigns a {@link Brand} to a value.
1251
- *
1252
- * This is a zero-cost runtime assertion helper — it simply returns the value
1253
- * with the brand's nominal type applied. Use it for simple branded primitives
1254
- * where you know the value is valid.
1255
- *
1256
- * @deprecated To unify Api surface 'asIdentity' should be used instea, will be removed in v2.0.0. for more info check 'https://www.npmjs.com/package/@vicin/phantom#deprecated-api'
1257
- *
1258
- * @template B - The brand declaration to assign.
1259
- * @returns A function that casts any value to the branded type.
1260
- */
1261
- const asBrand: <B extends Brand.Any>() => <T>(value: T) => Brand.Assign<B, T>;
1262
1151
  /**
1263
1152
  * Creates a typed caster that assigns an {@link Identity} to a value.
1264
1153
  *
@@ -1340,10 +1229,16 @@ declare namespace Phantom {
1340
1229
  type StripPhantom<T> = PhantomCore.StripPhantom<T>;
1341
1230
  /** run-time helper for 'StringPhantom', used for debugging mainly */
1342
1231
  const stripPhantom: <T>(value: T) => T extends {
1343
- __Phantom: {
1344
- __OriginalType?: infer O;
1232
+ [__Phantom]: {
1233
+ [__OriginalType]?: infer O;
1234
+ };
1235
+ } ? Exclude<O, undefined> : T extends {
1236
+ [__Phantom]: {
1237
+ [__Base]?: infer B;
1345
1238
  };
1346
- } ? Exclude<O, undefined> : T;
1239
+ } ? Exclude<B, undefined> : T extends {
1240
+ [__Phantom]: object;
1241
+ } ? unknown : T;
1347
1242
  /** --------------------------------------
1348
1243
  * Error type
1349
1244
  * --------------------------------------- */
@@ -1380,4 +1275,4 @@ declare namespace Phantom {
1380
1275
  }
1381
1276
  }
1382
1277
 
1383
- export { Base, Brand, type ErrorType, Identity, Input, Inspect, Label, Phantom, PhantomChain, PhantomCore, Tag, Trait, Traits, Transformation, Variants, addTrait, addTraits, applyTransformation, asBrand, asIdentity, assertors, Phantom as default, dropTrait, dropTraits, revertTransformation, stripPhantom };
1278
+ export { Base, type ErrorType, Identity, Input, Inspect, Label, Phantom, PhantomChain, PhantomCore, Tag, Trait, Traits, Transformation, Variants, __Base, __Input, __Label, __OriginalType, __Phantom, __Tag, __Traits, __Variants, addTrait, addTraits, applyTransformation, asIdentity, assertors, Phantom as default, dropTrait, dropTraits, revertTransformation, stripPhantom };