@vicin/phantom 1.0.8 → 1.1.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/README.md +39 -82
- package/dist/index.d.mts +49 -10
- package/dist/index.d.ts +49 -10
- package/dist/index.global.js +8 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> - 🎉 First stable release — v1.0! Happy coding! 😄💻
|
|
6
6
|
> - 📄 **Changelog:** [CHANGELOG.md](./CHANGELOG.md)
|
|
7
7
|
|
|
8
|
-
`Phantom` is a powerful, lightweight TypeScript library for nominal typing. it uses **type-only** metadata object that can be attached to any type with clean IDE. It enables compile-time distinctions between structurally identical types (e.g., `Email` vs. `Username` as branded strings) while supporting advanced features like **constrained identities**,**state variants**, **additive traits**, and **reversible transformations**. making it ideal for domain-driven design (DDD), APIs, and type-safe primitives with
|
|
8
|
+
`Phantom` is a powerful, lightweight TypeScript library for nominal typing. it uses **type-only** metadata object that can be attached to any type with clean IDE. It enables compile-time distinctions between structurally identical types (e.g., `Email` vs. `Username` as branded strings) while supporting advanced features like **constrained identities**,**state variants**, **additive traits**, and **reversible transformations**. making it ideal for domain-driven design (DDD), APIs, and type-safe primitives with near zero performance overhead.
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
- [Terminology](#terminology)
|
|
18
18
|
- [\_\_Phantom object](#__phantom-object)
|
|
19
19
|
- [Type constructs](#type-constructs)
|
|
20
|
-
- [Branding](#branding)
|
|
21
20
|
- [Identities with constraints](#identities-with-constraints)
|
|
22
21
|
- [Traits (additive capabilities)](#traits-additive-capabilities)
|
|
23
22
|
- [Transformations (Type pipe-like behavior)](#transformations-type-pipe-like-behavior)
|
|
@@ -29,6 +28,7 @@
|
|
|
29
28
|
- [Debugging](#debugging)
|
|
30
29
|
- [API reference](#api-reference)
|
|
31
30
|
- [Full examples](#full-examples)
|
|
31
|
+
- [Deprecated API](#deprecated-api)
|
|
32
32
|
- [Sigil](#sigil)
|
|
33
33
|
- [Contributing](#contributing)
|
|
34
34
|
- [License](#license)
|
|
@@ -101,6 +101,7 @@ type X = string & {
|
|
|
101
101
|
__Phantom: {
|
|
102
102
|
__Tag: 'X';
|
|
103
103
|
__Label?: 'Label of X';
|
|
104
|
+
__Base?: string;
|
|
104
105
|
__Variants: 'Variant1' | 'Variant2';
|
|
105
106
|
__Traits: {
|
|
106
107
|
trait1: true;
|
|
@@ -118,6 +119,8 @@ From the first glance you can spot that`Phantom` is designed to separate origina
|
|
|
118
119
|
|
|
119
120
|
- **\_\_Label?:** Optional label describing this nominal identity.
|
|
120
121
|
|
|
122
|
+
- **\_\_Base?:** Optional constraint to nominal identity, so only values that extend this type can be branded.
|
|
123
|
+
|
|
121
124
|
- **\_\_Variants:** Optional states of the nominal identity.
|
|
122
125
|
|
|
123
126
|
- **\_\_Traits:** Additional properties the type holds, unlike `__Tag` that tells who `__Traits` tell what this type hold or can do (e.g. `Validated`, `PII` etc...).
|
|
@@ -132,51 +135,6 @@ More details of these properties will be discussed later.
|
|
|
132
135
|
|
|
133
136
|
## Type constructs
|
|
134
137
|
|
|
135
|
-
### Branding
|
|
136
|
-
|
|
137
|
-
Use brands for simple nominal distinctions on primitives.
|
|
138
|
-
|
|
139
|
-
#### Structure
|
|
140
|
-
|
|
141
|
-
**`Brand.Declare<Tag, Label?>`**
|
|
142
|
-
|
|
143
|
-
- **Tag:** Unique identifier which can string or symbol.
|
|
144
|
-
- **Label?:** Optional label description. can be set to `never`.
|
|
145
|
-
|
|
146
|
-
#### Basic example
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
import { Phantom } from '@vicin/phantom';
|
|
150
|
-
|
|
151
|
-
// Declare a brand
|
|
152
|
-
type UserId = Phantom.Brand.Declare<'UserId', 'Unique user identifier'>;
|
|
153
|
-
|
|
154
|
-
// Assertor for assigning the brand
|
|
155
|
-
const asUserId = Phantom.assertors.asBrand<UserId>();
|
|
156
|
-
|
|
157
|
-
// Usage
|
|
158
|
-
const id: string = '123';
|
|
159
|
-
const userId = asUserId(id); // type: string & { __Phantom: { __Tag: "UserId"; __Label?: "Unique user identifier"; __OriginalType: string; } }
|
|
160
|
-
|
|
161
|
-
// Type safety: prevents assignment
|
|
162
|
-
let postId: string = 'abc';
|
|
163
|
-
postId = userId; // Type error: 'UserId' is not assignable to unbranded string
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
#### Re-brand
|
|
167
|
-
|
|
168
|
-
Branding already branded value is prohibited and results in Error type:
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
const value = '123';
|
|
172
|
-
|
|
173
|
-
// Branding string as UserId
|
|
174
|
-
const userId = asUserId(value);
|
|
175
|
-
|
|
176
|
-
// Trying to brand userId as PostId returns type error
|
|
177
|
-
const postId = asPostId(userId); // type: Flow.TypeError<{ code: "ALREADY_BRANDED"; message: "Type already branded"; context: { type: <userId type>; }; }>
|
|
178
|
-
```
|
|
179
|
-
|
|
180
138
|
---
|
|
181
139
|
|
|
182
140
|
### Identities with constraints
|
|
@@ -189,7 +147,8 @@ const postId = asPostId(userId); // type: Flow.TypeError<{ code: "ALREADY_BRANDE
|
|
|
189
147
|
|
|
190
148
|
- **Tag:** Unique identifier which can string or symbol.
|
|
191
149
|
- **Label?:** Optional label description. can be set to `never`.
|
|
192
|
-
- **Base?:** Optional base that constrains identity so only `string` for example can be casted as `Email`. can be set to `never`.
|
|
150
|
+
- **Base?:** Optional base that constrains identity so only `string` for example can be casted as `Email`. can be set to `never` or `unknown`.
|
|
151
|
+
Type passed is also added to declared `Identity` (`<Base> & <PhantomObject>`).
|
|
193
152
|
- **Variants?:** Optional variants (states) of the identity. can be set to `never`.
|
|
194
153
|
|
|
195
154
|
#### Basic example
|
|
@@ -320,7 +279,8 @@ Type identity is `Transformed` and stores `Input` under special field inside `__
|
|
|
320
279
|
- **Input:** Type input to the transformation.
|
|
321
280
|
- **Tag:** Unique identifier of transformed which can string or symbol.
|
|
322
281
|
- **Label?:** Optional label description of transformed. can be set to `never`.
|
|
323
|
-
- **Base?:** Optional base that constrains identity of transformed so only `Uint8Array` for example can be casted as `Encoded`. can be set to `never`.
|
|
282
|
+
- **Base?:** Optional base that constrains identity of transformed so only `Uint8Array` for example can be casted as `Encoded`. can be set to `never` or `unknown`.
|
|
283
|
+
Type passed is also added to declared `Transformation` (`<Base> & <PhantomObject>`).
|
|
324
284
|
- **Variants?:** Optional variants (states) of the identity. can be set to `never`.
|
|
325
285
|
|
|
326
286
|
#### Basic example
|
|
@@ -394,7 +354,7 @@ When passed value violate specific rule, descripted `ErrorType` is returned.
|
|
|
394
354
|
|
|
395
355
|
**ErrorTypes:**
|
|
396
356
|
|
|
397
|
-
- **ALREADY_BRANDED:** Error returned if already branded value (with
|
|
357
|
+
- **ALREADY_BRANDED:** Error returned if already branded value (with `Identity`) is passed to `.Assign<>` again.
|
|
398
358
|
|
|
399
359
|
- **TYPE_NOT_EXTEND_BASE:** Error returned if type not extend `Base` constraint of `Identity`.
|
|
400
360
|
|
|
@@ -402,7 +362,7 @@ When passed value violate specific rule, descripted `ErrorType` is returned.
|
|
|
402
362
|
|
|
403
363
|
- **NOT_TRANSFORMED:** Error returned if you tried to revert a non-transformed type.
|
|
404
364
|
|
|
405
|
-
All the types inside `Phantom` check for `ErrorType` first before applying any change, so if you tried to pass `ErrorType` to `
|
|
365
|
+
All the types inside `Phantom` check for `ErrorType` first before applying any change, so if you tried to pass `ErrorType` to `Identity.Assign<>` or `asIdentity<B>()` for example the error will return unchanged.
|
|
406
366
|
|
|
407
367
|
---
|
|
408
368
|
|
|
@@ -415,7 +375,7 @@ import { Phantom } from '@vicin/phantom';
|
|
|
415
375
|
|
|
416
376
|
// type
|
|
417
377
|
declare const __UserId: unique symbol;
|
|
418
|
-
type UserId = Phantom.
|
|
378
|
+
type UserId = Phantom.Identity.Declare<typeof __UserId, 'User id'>;
|
|
419
379
|
|
|
420
380
|
// assertor
|
|
421
381
|
export const asUserId = Phantom.assertors.asBrand<UserId>();
|
|
@@ -430,11 +390,11 @@ Now `UserId` can't be re-defined anywhere else in the codebase.
|
|
|
430
390
|
Some devs (including me) may find `Phantom` namespace everywhere repetitive and prefer using `Brand` or `assertors` directly, every namespace under `Phantom` can be imported alone:
|
|
431
391
|
|
|
432
392
|
```ts
|
|
433
|
-
import {
|
|
393
|
+
import { Identity, assertors } from '@vicin/phantom';
|
|
434
394
|
|
|
435
395
|
// type
|
|
436
396
|
declare const __UserId: unique symbol; // declare type only unique symbol to be our tag
|
|
437
|
-
type UserId =
|
|
397
|
+
type UserId = Identity.Declare<typeof __UserId, 'User id'>;
|
|
438
398
|
|
|
439
399
|
// assertor
|
|
440
400
|
export const asUserId = assertors.asBrand<UserId>();
|
|
@@ -447,13 +407,13 @@ import P from '@vicin/phantom';
|
|
|
447
407
|
|
|
448
408
|
// type
|
|
449
409
|
declare const __UserId: unique symbol; // declare type only unique symbol to be our tag
|
|
450
|
-
type UserId = P.
|
|
410
|
+
type UserId = P.Identity.Declare<typeof __UserId, 'User id'>;
|
|
451
411
|
|
|
452
412
|
// assertor
|
|
453
413
|
export const asUserId = P.assertors.asBrand<UserId>();
|
|
454
414
|
```
|
|
455
415
|
|
|
456
|
-
Also you can import single assertor function:
|
|
416
|
+
Also you can import single run-time function as `assertor functions` and `stripPhantom` function:
|
|
457
417
|
|
|
458
418
|
```ts
|
|
459
419
|
import { asBrand } from '@vicin/phantom';
|
|
@@ -470,9 +430,9 @@ You are free to pick whatever pattern you are comfortable with.
|
|
|
470
430
|
If you need to call multiple assertors on a single value (e.g. mark brand and attach two traits) the code can get messy:
|
|
471
431
|
|
|
472
432
|
```ts
|
|
473
|
-
import {
|
|
433
|
+
import { Identity, Trait, assertors } from '@vicin/phantom';
|
|
474
434
|
|
|
475
|
-
type UserId =
|
|
435
|
+
type UserId = Identity.Declare<'UserId', 'User id', string>;
|
|
476
436
|
const asUserId = assertors.asBrand<UserId>();
|
|
477
437
|
|
|
478
438
|
type PII = Trait.Declare<'PII'>;
|
|
@@ -508,17 +468,6 @@ The `.with()` is order sensitive, so previous example is equivalent to `addValid
|
|
|
508
468
|
|
|
509
469
|
In hot-path code every function call matters, and although assertor functions makes code much cleaner but you may prefer to use `as` in performance critical situations so `Phantom` lives in type system entirely and have zero run-time trace, these examples defines best practices to do so:
|
|
510
470
|
|
|
511
|
-
**Brand**:
|
|
512
|
-
|
|
513
|
-
```ts
|
|
514
|
-
import { Brand } from '@vicin/phantom';
|
|
515
|
-
|
|
516
|
-
type UserId = Brand.Declare<'UserId'>;
|
|
517
|
-
type AsUserId<T> = Brand.Assign<UserId, T>;
|
|
518
|
-
|
|
519
|
-
const userId = '123' as AsUserId<string>;
|
|
520
|
-
```
|
|
521
|
-
|
|
522
471
|
**Identity**:
|
|
523
472
|
|
|
524
473
|
```ts
|
|
@@ -568,10 +517,10 @@ function decode<E extends Encoded>(encoded: E) {
|
|
|
568
517
|
Chaining is not supported in **type-only pattern** and nesting is the only way to reliably calculate types:
|
|
569
518
|
|
|
570
519
|
```ts
|
|
571
|
-
import {
|
|
520
|
+
import { Identity, Trait, assertors } from '@vicin/phantom';
|
|
572
521
|
|
|
573
|
-
type UserId =
|
|
574
|
-
type AsUserId<T> =
|
|
522
|
+
type UserId = Identity.Declare<'UserId', 'User id', string>;
|
|
523
|
+
type AsUserId<T> = Identity.Assign<UserId, T>;
|
|
575
524
|
|
|
576
525
|
type PII = Trait.Declare<'PII'>;
|
|
577
526
|
type AddPII<T> = Trait.Add<PII, T>;
|
|
@@ -635,13 +584,6 @@ These handle individual metadata fields in the `__Phantom` object.
|
|
|
635
584
|
|
|
636
585
|
These provide nominal typing and metadata operations.
|
|
637
586
|
|
|
638
|
-
- **Brand:** Simple nominal branding.
|
|
639
|
-
- `Any`: Marker for branded types.
|
|
640
|
-
- `Declare<T, L>`: Declare a brand with tag `T` and optional label `L`.
|
|
641
|
-
- `Assign<B, T>`: Assign brand `B` to `T` (fails if already branded).
|
|
642
|
-
- `AssignSafe<B, T>`: Assign if possible, else return `T`.
|
|
643
|
-
- `isBrand<T, B>`: Check if `T` is branded with `B`.
|
|
644
|
-
|
|
645
587
|
- **Identity**: Brands with bases and variants.
|
|
646
588
|
- `Any`: Marker for identity types.
|
|
647
589
|
- `Declare<T, L, B, V>`: Declare identity with tag `T`, label `L`, base `B`, variants `V`.
|
|
@@ -682,7 +624,6 @@ Aliases for core and feature extractors: `LabelOf<T>`, `HasLabel<T, L>`, `TagOf<
|
|
|
682
624
|
|
|
683
625
|
Zero-cost casting functions.
|
|
684
626
|
|
|
685
|
-
`asBrand<B>()`: Assign brand `B`.
|
|
686
627
|
`asIdentity<I>()`: Assign identity `I`.
|
|
687
628
|
`addTrait<Tr>()`: Add trait `Tr`.
|
|
688
629
|
`addTraits<Tr[]>()`: Add multiple traits `Tr[]`.
|
|
@@ -705,10 +646,10 @@ Zero-cost casting functions.
|
|
|
705
646
|
Defining brands and identities at our app entry points after validation:
|
|
706
647
|
|
|
707
648
|
```ts
|
|
708
|
-
import {
|
|
649
|
+
import { Identity, assertors } from '@vicin/phantom';
|
|
709
650
|
|
|
710
651
|
declare const __UserId: unique symbol;
|
|
711
|
-
type UserId =
|
|
652
|
+
type UserId = Identity.Declare<typeof __UserId, 'UserId', string>;
|
|
712
653
|
const asUserId = assertors.asBrand<UserId>();
|
|
713
654
|
|
|
714
655
|
function validateUserId(userId: string) {
|
|
@@ -859,6 +800,22 @@ function hash<V>(value: V) {
|
|
|
859
800
|
|
|
860
801
|
---
|
|
861
802
|
|
|
803
|
+
## Deprecated API
|
|
804
|
+
|
|
805
|
+
### Brand
|
|
806
|
+
|
|
807
|
+
To unify Api surface `Identity` should be used instead. **marked with `deprecated` and will be removed in v2.0.0**
|
|
808
|
+
|
|
809
|
+
### asBrand
|
|
810
|
+
|
|
811
|
+
To unify Api surface `asIdentity` should be used instead. **marked with `deprecated` and will be removed in v2.0.0**
|
|
812
|
+
|
|
813
|
+
### isBrand
|
|
814
|
+
|
|
815
|
+
To unify Api surface `isIdentity` should be used instead. **marked with `deprecated` and will be removed in v2.0.0**
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
862
819
|
## Sigil
|
|
863
820
|
|
|
864
821
|
`Sigil` is another lightweight TypeScript library I created for **nominal identity on classes**, providing compile-time branding and reliable runtime type checks. It solves the unreliability of `instanceof` in monorepos, bundled/HMR environments (where classes can duplicate), and manual branding boilerplate in DDD by using `symbols`, `lineages`, and a `centralized registry` for stable identity across codebases.
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,8 @@ declare namespace assertors {
|
|
|
6
6
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
7
7
|
* where you know the value is valid.
|
|
8
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
|
+
*
|
|
9
11
|
* @template B - The brand declaration to assign.
|
|
10
12
|
* @returns A function that casts any value to the branded type.
|
|
11
13
|
*/
|
|
@@ -311,6 +313,15 @@ declare namespace VariantsCore {
|
|
|
311
313
|
} ? true : false;
|
|
312
314
|
}
|
|
313
315
|
|
|
316
|
+
/** Stip phantom metadata object from a type */
|
|
317
|
+
type StripPhantom<T> = T extends {
|
|
318
|
+
__Phantom: {
|
|
319
|
+
__OriginalType?: infer O;
|
|
320
|
+
};
|
|
321
|
+
} ? Exclude<O, undefined> : T;
|
|
322
|
+
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
323
|
+
declare const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
324
|
+
type _StripPhantom<T> = StripPhantom<T>;
|
|
314
325
|
/**
|
|
315
326
|
* Phantom meatadata object manipulators.
|
|
316
327
|
*
|
|
@@ -322,13 +333,13 @@ declare namespace PhantomCore {
|
|
|
322
333
|
__Phantom: infer Phantom extends object;
|
|
323
334
|
} ? Phantom : never;
|
|
324
335
|
/** Stip phantom metadata object from a type */
|
|
325
|
-
type StripPhantom<T> = T
|
|
336
|
+
type StripPhantom<T> = _StripPhantom<T>;
|
|
337
|
+
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
338
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
326
339
|
__Phantom: {
|
|
327
340
|
__OriginalType?: infer O;
|
|
328
341
|
};
|
|
329
342
|
} ? Exclude<O, undefined> : T;
|
|
330
|
-
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
331
|
-
const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
332
343
|
}
|
|
333
344
|
|
|
334
345
|
/** Interface of 'Brand' and 'Identity' errors. */
|
|
@@ -441,6 +452,8 @@ type Merge<O1 extends object, O2 extends object> = Prettify<Omit<O1, keyof O2> &
|
|
|
441
452
|
*
|
|
442
453
|
* Brands provide nominal typing for otherwise identical values.
|
|
443
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'
|
|
444
457
|
*/
|
|
445
458
|
declare namespace BrandCore {
|
|
446
459
|
/** Type guard for any brand. */
|
|
@@ -476,7 +489,7 @@ declare namespace IdentityCore {
|
|
|
476
489
|
/** Type guard for any identity. */
|
|
477
490
|
export type Any = TagCore.Of<string | symbol>;
|
|
478
491
|
/** Declare an identity */
|
|
479
|
-
export type Declare<T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = Prettify<TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
|
|
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>>;
|
|
480
493
|
/**
|
|
481
494
|
* Assign an identity to a value.
|
|
482
495
|
* Enforces base-type compatibility.
|
|
@@ -541,7 +554,7 @@ declare namespace TransformationCore {
|
|
|
541
554
|
/** Type guard for any transformation. */
|
|
542
555
|
export type Any = InputCore.Of<any> & TagCore.Of<string | symbol>;
|
|
543
556
|
/** Declare a transformation */
|
|
544
|
-
export type Declare<I, T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = Prettify<InputCore.Of<I> & TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
|
|
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>>;
|
|
545
558
|
/**
|
|
546
559
|
* Apply a transformation to a value.
|
|
547
560
|
* Enforces base-type compatibility.
|
|
@@ -656,6 +669,8 @@ declare namespace Traits {
|
|
|
656
669
|
*
|
|
657
670
|
* Brands provide nominal typing for otherwise identical values.
|
|
658
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'
|
|
659
674
|
*/
|
|
660
675
|
declare namespace Brand {
|
|
661
676
|
/** Type guard for any brand. */
|
|
@@ -767,7 +782,11 @@ declare namespace Inspect {
|
|
|
767
782
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
768
783
|
/** Check if any traits exist */
|
|
769
784
|
type HasTraits<T> = TraitsCore.HasTraits<T>;
|
|
770
|
-
/**
|
|
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
|
+
*/
|
|
771
790
|
type isBrand<T, B extends BrandCore.Any> = BrandCore.isBrand<T, B>;
|
|
772
791
|
/** Check whether value is branded with */
|
|
773
792
|
type isIdentity<T, I extends IdentityCore.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -784,6 +803,8 @@ declare namespace Inspect {
|
|
|
784
803
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
785
804
|
* where you know the value is valid.
|
|
786
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
|
+
*
|
|
787
808
|
* @template B - The brand declaration to assign.
|
|
788
809
|
* @returns A function that casts any value to the branded type.
|
|
789
810
|
*/
|
|
@@ -1000,6 +1021,8 @@ declare namespace Phantom {
|
|
|
1000
1021
|
*
|
|
1001
1022
|
* Brands provide nominal typing for otherwise identical values.
|
|
1002
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'
|
|
1003
1026
|
*/
|
|
1004
1027
|
namespace Brand {
|
|
1005
1028
|
/** Type guard for any brand. */
|
|
@@ -1089,7 +1112,11 @@ declare namespace Phantom {
|
|
|
1089
1112
|
/** Stip phantom metadata object from a type */
|
|
1090
1113
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1091
1114
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1092
|
-
const stripPhantom: <T>(value: T) =>
|
|
1115
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
1116
|
+
__Phantom: {
|
|
1117
|
+
__OriginalType?: infer O;
|
|
1118
|
+
};
|
|
1119
|
+
} ? Exclude<O, undefined> : T;
|
|
1093
1120
|
/** Extract the label */
|
|
1094
1121
|
type LabelOf<T> = LabelCore.LabelOf<T>;
|
|
1095
1122
|
/** Check whether a base constraint exists */
|
|
@@ -1116,7 +1143,11 @@ declare namespace Phantom {
|
|
|
1116
1143
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
1117
1144
|
/** Check if any traits exist */
|
|
1118
1145
|
type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
|
|
1119
|
-
/**
|
|
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
|
+
*/
|
|
1120
1151
|
type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
|
|
1121
1152
|
/** Check whether value is branded with */
|
|
1122
1153
|
type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -1136,6 +1167,8 @@ declare namespace Phantom {
|
|
|
1136
1167
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1137
1168
|
* where you know the value is valid.
|
|
1138
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
|
+
*
|
|
1139
1172
|
* @template B - The brand declaration to assign.
|
|
1140
1173
|
* @returns A function that casts any value to the branded type.
|
|
1141
1174
|
*/
|
|
@@ -1220,6 +1253,8 @@ declare namespace Phantom {
|
|
|
1220
1253
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1221
1254
|
* where you know the value is valid.
|
|
1222
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
|
+
*
|
|
1223
1258
|
* @template B - The brand declaration to assign.
|
|
1224
1259
|
* @returns A function that casts any value to the branded type.
|
|
1225
1260
|
*/
|
|
@@ -1304,7 +1339,11 @@ declare namespace Phantom {
|
|
|
1304
1339
|
/** Stip phantom metadata object from a type */
|
|
1305
1340
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1306
1341
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1307
|
-
const stripPhantom: <T>(value: T) =>
|
|
1342
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
1343
|
+
__Phantom: {
|
|
1344
|
+
__OriginalType?: infer O;
|
|
1345
|
+
};
|
|
1346
|
+
} ? Exclude<O, undefined> : T;
|
|
1308
1347
|
/** --------------------------------------
|
|
1309
1348
|
* Error type
|
|
1310
1349
|
* --------------------------------------- */
|
|
@@ -1341,4 +1380,4 @@ declare namespace Phantom {
|
|
|
1341
1380
|
}
|
|
1342
1381
|
}
|
|
1343
1382
|
|
|
1344
|
-
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ declare namespace assertors {
|
|
|
6
6
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
7
7
|
* where you know the value is valid.
|
|
8
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
|
+
*
|
|
9
11
|
* @template B - The brand declaration to assign.
|
|
10
12
|
* @returns A function that casts any value to the branded type.
|
|
11
13
|
*/
|
|
@@ -311,6 +313,15 @@ declare namespace VariantsCore {
|
|
|
311
313
|
} ? true : false;
|
|
312
314
|
}
|
|
313
315
|
|
|
316
|
+
/** Stip phantom metadata object from a type */
|
|
317
|
+
type StripPhantom<T> = T extends {
|
|
318
|
+
__Phantom: {
|
|
319
|
+
__OriginalType?: infer O;
|
|
320
|
+
};
|
|
321
|
+
} ? Exclude<O, undefined> : T;
|
|
322
|
+
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
323
|
+
declare const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
324
|
+
type _StripPhantom<T> = StripPhantom<T>;
|
|
314
325
|
/**
|
|
315
326
|
* Phantom meatadata object manipulators.
|
|
316
327
|
*
|
|
@@ -322,13 +333,13 @@ declare namespace PhantomCore {
|
|
|
322
333
|
__Phantom: infer Phantom extends object;
|
|
323
334
|
} ? Phantom : never;
|
|
324
335
|
/** Stip phantom metadata object from a type */
|
|
325
|
-
type StripPhantom<T> = T
|
|
336
|
+
type StripPhantom<T> = _StripPhantom<T>;
|
|
337
|
+
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
338
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
326
339
|
__Phantom: {
|
|
327
340
|
__OriginalType?: infer O;
|
|
328
341
|
};
|
|
329
342
|
} ? Exclude<O, undefined> : T;
|
|
330
|
-
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
331
|
-
const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
332
343
|
}
|
|
333
344
|
|
|
334
345
|
/** Interface of 'Brand' and 'Identity' errors. */
|
|
@@ -441,6 +452,8 @@ type Merge<O1 extends object, O2 extends object> = Prettify<Omit<O1, keyof O2> &
|
|
|
441
452
|
*
|
|
442
453
|
* Brands provide nominal typing for otherwise identical values.
|
|
443
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'
|
|
444
457
|
*/
|
|
445
458
|
declare namespace BrandCore {
|
|
446
459
|
/** Type guard for any brand. */
|
|
@@ -476,7 +489,7 @@ declare namespace IdentityCore {
|
|
|
476
489
|
/** Type guard for any identity. */
|
|
477
490
|
export type Any = TagCore.Of<string | symbol>;
|
|
478
491
|
/** Declare an identity */
|
|
479
|
-
export type Declare<T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = Prettify<TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
|
|
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>>;
|
|
480
493
|
/**
|
|
481
494
|
* Assign an identity to a value.
|
|
482
495
|
* Enforces base-type compatibility.
|
|
@@ -541,7 +554,7 @@ declare namespace TransformationCore {
|
|
|
541
554
|
/** Type guard for any transformation. */
|
|
542
555
|
export type Any = InputCore.Of<any> & TagCore.Of<string | symbol>;
|
|
543
556
|
/** Declare a transformation */
|
|
544
|
-
export type Declare<I, T extends string | symbol, L extends string = never, B extends unknown = never, V extends string = never> = Prettify<InputCore.Of<I> & TagCore.Of<T> & LabelCore.OfIfExists<L> & BaseCore.OfIfExists<B> & VariantsCore.OfIfExists<V>>;
|
|
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>>;
|
|
545
558
|
/**
|
|
546
559
|
* Apply a transformation to a value.
|
|
547
560
|
* Enforces base-type compatibility.
|
|
@@ -656,6 +669,8 @@ declare namespace Traits {
|
|
|
656
669
|
*
|
|
657
670
|
* Brands provide nominal typing for otherwise identical values.
|
|
658
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'
|
|
659
674
|
*/
|
|
660
675
|
declare namespace Brand {
|
|
661
676
|
/** Type guard for any brand. */
|
|
@@ -767,7 +782,11 @@ declare namespace Inspect {
|
|
|
767
782
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
768
783
|
/** Check if any traits exist */
|
|
769
784
|
type HasTraits<T> = TraitsCore.HasTraits<T>;
|
|
770
|
-
/**
|
|
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
|
+
*/
|
|
771
790
|
type isBrand<T, B extends BrandCore.Any> = BrandCore.isBrand<T, B>;
|
|
772
791
|
/** Check whether value is branded with */
|
|
773
792
|
type isIdentity<T, I extends IdentityCore.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -784,6 +803,8 @@ declare namespace Inspect {
|
|
|
784
803
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
785
804
|
* where you know the value is valid.
|
|
786
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
|
+
*
|
|
787
808
|
* @template B - The brand declaration to assign.
|
|
788
809
|
* @returns A function that casts any value to the branded type.
|
|
789
810
|
*/
|
|
@@ -1000,6 +1021,8 @@ declare namespace Phantom {
|
|
|
1000
1021
|
*
|
|
1001
1022
|
* Brands provide nominal typing for otherwise identical values.
|
|
1002
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'
|
|
1003
1026
|
*/
|
|
1004
1027
|
namespace Brand {
|
|
1005
1028
|
/** Type guard for any brand. */
|
|
@@ -1089,7 +1112,11 @@ declare namespace Phantom {
|
|
|
1089
1112
|
/** Stip phantom metadata object from a type */
|
|
1090
1113
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1091
1114
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1092
|
-
const stripPhantom: <T>(value: T) =>
|
|
1115
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
1116
|
+
__Phantom: {
|
|
1117
|
+
__OriginalType?: infer O;
|
|
1118
|
+
};
|
|
1119
|
+
} ? Exclude<O, undefined> : T;
|
|
1093
1120
|
/** Extract the label */
|
|
1094
1121
|
type LabelOf<T> = LabelCore.LabelOf<T>;
|
|
1095
1122
|
/** Check whether a base constraint exists */
|
|
@@ -1116,7 +1143,11 @@ declare namespace Phantom {
|
|
|
1116
1143
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
1117
1144
|
/** Check if any traits exist */
|
|
1118
1145
|
type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
|
|
1119
|
-
/**
|
|
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
|
+
*/
|
|
1120
1151
|
type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
|
|
1121
1152
|
/** Check whether value is branded with */
|
|
1122
1153
|
type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -1136,6 +1167,8 @@ declare namespace Phantom {
|
|
|
1136
1167
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1137
1168
|
* where you know the value is valid.
|
|
1138
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
|
+
*
|
|
1139
1172
|
* @template B - The brand declaration to assign.
|
|
1140
1173
|
* @returns A function that casts any value to the branded type.
|
|
1141
1174
|
*/
|
|
@@ -1220,6 +1253,8 @@ declare namespace Phantom {
|
|
|
1220
1253
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1221
1254
|
* where you know the value is valid.
|
|
1222
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
|
+
*
|
|
1223
1258
|
* @template B - The brand declaration to assign.
|
|
1224
1259
|
* @returns A function that casts any value to the branded type.
|
|
1225
1260
|
*/
|
|
@@ -1304,7 +1339,11 @@ declare namespace Phantom {
|
|
|
1304
1339
|
/** Stip phantom metadata object from a type */
|
|
1305
1340
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1306
1341
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1307
|
-
const stripPhantom: <T>(value: T) =>
|
|
1342
|
+
const stripPhantom: <T>(value: T) => T extends {
|
|
1343
|
+
__Phantom: {
|
|
1344
|
+
__OriginalType?: infer O;
|
|
1345
|
+
};
|
|
1346
|
+
} ? Exclude<O, undefined> : T;
|
|
1308
1347
|
/** --------------------------------------
|
|
1309
1348
|
* Error type
|
|
1310
1349
|
* --------------------------------------- */
|
|
@@ -1341,4 +1380,4 @@ declare namespace Phantom {
|
|
|
1341
1380
|
}
|
|
1342
1381
|
}
|
|
1343
1382
|
|
|
1344
|
-
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 };
|
|
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 };
|
package/dist/index.global.js
CHANGED
|
@@ -68,10 +68,12 @@
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
// src/core/phantom.ts
|
|
71
|
-
var
|
|
71
|
+
var stripPhantom = (value) => value;
|
|
72
|
+
var _stripPhantom = stripPhantom;
|
|
73
|
+
exports.PhantomCore = void 0;
|
|
72
74
|
((PhantomCore2) => {
|
|
73
|
-
PhantomCore2.stripPhantom =
|
|
74
|
-
})(PhantomCore || (PhantomCore = {}));
|
|
75
|
+
PhantomCore2.stripPhantom = _stripPhantom;
|
|
76
|
+
})(exports.PhantomCore || (exports.PhantomCore = {}));
|
|
75
77
|
|
|
76
78
|
// src/phantom.ts
|
|
77
79
|
var _addTrait2 = addTrait;
|
|
@@ -86,7 +88,7 @@
|
|
|
86
88
|
exports.Phantom = void 0;
|
|
87
89
|
((Phantom2) => {
|
|
88
90
|
((Inspect2) => {
|
|
89
|
-
Inspect2.stripPhantom = PhantomCore.stripPhantom;
|
|
91
|
+
Inspect2.stripPhantom = exports.PhantomCore.stripPhantom;
|
|
90
92
|
})(Phantom2.Inspect || (Phantom2.Inspect = {}));
|
|
91
93
|
((assertors3) => {
|
|
92
94
|
assertors3.asBrand = _asBrand2;
|
|
@@ -106,7 +108,7 @@
|
|
|
106
108
|
Phantom2.dropTraits = _dropTraits2;
|
|
107
109
|
Phantom2.applyTransformation = _applyTransformation2;
|
|
108
110
|
Phantom2.revertTransformation = _revertTransformation2;
|
|
109
|
-
Phantom2.stripPhantom = PhantomCore.stripPhantom;
|
|
111
|
+
Phantom2.stripPhantom = exports.PhantomCore.stripPhantom;
|
|
110
112
|
class PhantomChain2 extends _PhantomChain {
|
|
111
113
|
}
|
|
112
114
|
Phantom2.PhantomChain = PhantomChain2;
|
|
@@ -125,6 +127,7 @@
|
|
|
125
127
|
exports.dropTrait = dropTrait;
|
|
126
128
|
exports.dropTraits = dropTraits;
|
|
127
129
|
exports.revertTransformation = revertTransformation;
|
|
130
|
+
exports.stripPhantom = stripPhantom;
|
|
128
131
|
|
|
129
132
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
130
133
|
|
package/dist/index.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revertTransformation","Phantom","Inspect","PhantomChain"],"mappings":";;;;;;;;AAYO,MAAM,OAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACHG,MAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,MAAM,QAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACvCG,MAAM,mBAAA,GACX,MACA,CAAO,KAAA,EAAU,WAAA,KACf;AAcG,MAAM,oBAAA,GACX,MACA,CAAO,WAAA,EAAgB,KAAA,KACrB;;;EC5BJ,IAAM,SAAA,GAAY,QAAA;EAClB,IAAM,UAAA,GAAa,SAAA;EACnB,IAAM,oBAAA,GAAuB,mBAAA;EAC7B,IAAM,QAAA,GAAW,OAAA;EACjB,IAAM,WAAA,GAAc,UAAA;EACpB,IAAM,UAAA,GAAa,SAAA;EACnB,IAAM,WAAA,GAAc,UAAA;EACpB,I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;EAAA,EAqCjC,MAAME,sBAAwB,aAAA,CAAiB;EAAA;EAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;EAAA,CAAA,EA5gBEF,eAAA,KAAAA,eAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,MAAO,aAAA,GAAQA","file":"index.global.js","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n }\n ? Exclude<O, undefined>\n : T;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n PhantomCore,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revertTransformation","Phantom","Inspect","PhantomChain"],"mappings":";;;;;;;;AAcO,MAAM,OAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,MAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,MAAM,QAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,MAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACvCG,MAAM,mBAAA,GACX,MACA,CAAO,KAAA,EAAU,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B,EAAMK,SAAA,UAAA,GAAaJ,YAAAA;EAUnB,EAAMI,SAAA,QAAA,GAAWR,UAAAA;EAUjB,EAAMQ,SAAA,SAAA,GAAYP,WAAAA;EAUlB,EAAMO,SAAA,SAAA,GAAYH,WAAAA;EAUlB,EAAMG,SAAA,UAAA,GAAaF,YAAAA;EAanB,EAAME,SAAA,mBAAA,GAAsBN,qBAAAA;EAc5B,EAAMM,SAAA,oBAAA,GAAuBD,sBAAAA;EAW7B,EAAMC,QAAAA,CAAA,eAAeT,mBAAA,CAAY,YAAA;EAAA,EAqCjC,MAAMW,sBAAwB,aAAA,CAAiB;EAAA;EAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;EAAA,CAAA,EAthBEF,eAAA,KAAAA,eAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,MAAO,aAAA,GAAQA","file":"index.global.js","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/** Stip phantom metadata object from a type */\ntype StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n}\n ? Exclude<O, undefined>\n : T;\n\n/** run-time helper for 'StringPhantom', used for debugging mainly */\nexport const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n\n// Avoid bundler bugs\ntype _StripPhantom<T> = StripPhantom<T>;\nconst _stripPhantom = stripPhantom;\n\n/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = _StripPhantom<T>;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = _stripPhantom;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n *\n * @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'\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /**\n * Check whether value is branded with\n *\n * @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'\n */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nexport { PhantomCore, stripPhantom } from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
package/dist/index.js
CHANGED
|
@@ -69,10 +69,12 @@ var PhantomChain = class _PhantomChain2 {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// src/core/phantom.ts
|
|
72
|
-
var
|
|
72
|
+
var stripPhantom = (value) => value;
|
|
73
|
+
var _stripPhantom = stripPhantom;
|
|
74
|
+
exports.PhantomCore = void 0;
|
|
73
75
|
((PhantomCore2) => {
|
|
74
|
-
PhantomCore2.stripPhantom =
|
|
75
|
-
})(PhantomCore || (PhantomCore = {}));
|
|
76
|
+
PhantomCore2.stripPhantom = _stripPhantom;
|
|
77
|
+
})(exports.PhantomCore || (exports.PhantomCore = {}));
|
|
76
78
|
|
|
77
79
|
// src/phantom.ts
|
|
78
80
|
var _addTrait2 = addTrait;
|
|
@@ -87,7 +89,7 @@ var _PhantomChain = PhantomChain;
|
|
|
87
89
|
exports.Phantom = void 0;
|
|
88
90
|
((Phantom2) => {
|
|
89
91
|
((Inspect2) => {
|
|
90
|
-
Inspect2.stripPhantom = PhantomCore.stripPhantom;
|
|
92
|
+
Inspect2.stripPhantom = exports.PhantomCore.stripPhantom;
|
|
91
93
|
})(Phantom2.Inspect || (Phantom2.Inspect = {}));
|
|
92
94
|
((assertors3) => {
|
|
93
95
|
assertors3.asBrand = _asBrand2;
|
|
@@ -107,7 +109,7 @@ exports.Phantom = void 0;
|
|
|
107
109
|
Phantom2.dropTraits = _dropTraits2;
|
|
108
110
|
Phantom2.applyTransformation = _applyTransformation2;
|
|
109
111
|
Phantom2.revertTransformation = _revertTransformation2;
|
|
110
|
-
Phantom2.stripPhantom = PhantomCore.stripPhantom;
|
|
112
|
+
Phantom2.stripPhantom = exports.PhantomCore.stripPhantom;
|
|
111
113
|
class PhantomChain2 extends _PhantomChain {
|
|
112
114
|
}
|
|
113
115
|
Phantom2.PhantomChain = PhantomChain2;
|
|
@@ -126,5 +128,6 @@ exports.default = index_default;
|
|
|
126
128
|
exports.dropTrait = dropTrait;
|
|
127
129
|
exports.dropTraits = dropTraits;
|
|
128
130
|
exports.revertTransformation = revertTransformation;
|
|
131
|
+
exports.stripPhantom = stripPhantom;
|
|
129
132
|
//# sourceMappingURL=index.js.map
|
|
130
133
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revertTransformation","Phantom","Inspect","PhantomChain"],"mappings":";;;;;;;;;AAYO,IAAM,OAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACHG,IAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,IAAM,QAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,UAAA,GACX,MAC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AA,OAAA,GAAUL,SAAAA;AAYhB,EAAMK,SAAA,UAAA,GAAaJ,YAAAA;AAUnB,EAAMI,SAAA,QAAA,GAAWR,UAAAA;AAUjB,EAAMQ,SAAA,SAAA,GAAYP,WAAAA;AAUlB,EAAMO,SAAA,SAAA,GAAYH,WAAAA;AAUlB,EAAMG,SAAA,UAAA,GAAaF,YAAAA;AAanB,EAAME,SAAA,mBAAA,GAAsBN,qBAAAA;AAc5B,EAAMM,SAAA,oBAAA,GAAuBD,sBAAAA;AAW7B,EAAMC,QAAAA,CAAA,eAAe,WAAA,CAAY,YAAA;AAAA,EAqCjC,MAAME,sBAAwB,aAAA,CAAiB;AAAA;AAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;AAAA,CAAA,EA5gBEF,eAAA,KAAAA,eAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,IAAO,aAAA,GAAQA","file":"index.js","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n }\n ? Exclude<O, undefined>\n : T;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n PhantomCore,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revert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AWG,UAAAA;AAUjB,IAAMH,WAAA,SAAA,GAAYI,WAAAA;AAUlB,IAAMJ,WAAA,SAAA,GAAYQ,WAAAA;AAUlB,IAAMR,WAAA,UAAA,GAAaS,YAAAA;AAanB,IAAMT,WAAA,mBAAA,GAAsBK,qBAAAA;AAc5B,IAAML,WAAA,oBAAA,GAAuBU,sBAAAA;AAAA,EAAA,CAAA,EA5FrBC,QAAAA,CAAA,SAAA,KAAAA,QAAAA,CAAA,SAAA,GAAA,EAAA,CAAA,CAAA;AA2GV,EAAMA,SAAA,OAAA,GAAUL,SAAAA;AAYhB,EAAMK,SAAA,UAAA,GAAaJ,YAAAA;AAUnB,EAAMI,SAAA,QAAA,GAAWR,UAAAA;AAUjB,EAAMQ,SAAA,SAAA,GAAYP,WAAAA;AAUlB,EAAMO,SAAA,SAAA,GAAYH,WAAAA;AAUlB,EAAMG,SAAA,UAAA,GAAaF,YAAAA;AAanB,EAAME,SAAA,mBAAA,GAAsBN,qBAAAA;AAc5B,EAAMM,SAAA,oBAAA,GAAuBD,sBAAAA;AAW7B,EAAMC,QAAAA,CAAA,eAAeT,mBAAA,CAAY,YAAA;AAAA,EAqCjC,MAAMW,sBAAwB,aAAA,CAAiB;AAAA;AAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;AAAA,CAAA,EAthBEF,eAAA,KAAAA,eAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,IAAO,aAAA,GAAQA","file":"index.js","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/** Stip phantom metadata object from a type */\ntype StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n}\n ? Exclude<O, undefined>\n : T;\n\n/** run-time helper for 'StringPhantom', used for debugging mainly */\nexport const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n\n// Avoid bundler bugs\ntype _StripPhantom<T> = StripPhantom<T>;\nconst _stripPhantom = stripPhantom;\n\n/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = _StripPhantom<T>;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = _stripPhantom;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n *\n * @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'\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /**\n * Check whether value is branded with\n *\n * @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'\n */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nexport { PhantomCore, stripPhantom } from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -65,9 +65,11 @@ var PhantomChain = class _PhantomChain2 {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
// src/core/phantom.ts
|
|
68
|
+
var stripPhantom = (value) => value;
|
|
69
|
+
var _stripPhantom = stripPhantom;
|
|
68
70
|
var PhantomCore;
|
|
69
71
|
((PhantomCore2) => {
|
|
70
|
-
PhantomCore2.stripPhantom =
|
|
72
|
+
PhantomCore2.stripPhantom = _stripPhantom;
|
|
71
73
|
})(PhantomCore || (PhantomCore = {}));
|
|
72
74
|
|
|
73
75
|
// src/phantom.ts
|
|
@@ -112,6 +114,6 @@ var Phantom;
|
|
|
112
114
|
// src/index.ts
|
|
113
115
|
var index_default = Phantom;
|
|
114
116
|
|
|
115
|
-
export { Phantom, PhantomChain, addTrait, addTraits, applyTransformation, asBrand, asIdentity, assertors, index_default as default, dropTrait, dropTraits, revertTransformation };
|
|
117
|
+
export { Phantom, PhantomChain, PhantomCore, addTrait, addTraits, applyTransformation, asBrand, asIdentity, assertors, index_default as default, dropTrait, dropTraits, revertTransformation, stripPhantom };
|
|
116
118
|
//# sourceMappingURL=index.mjs.map
|
|
117
119
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revertTransformation","Phantom","Inspect","PhantomChain"],"mappings":";;;;;AAYO,IAAM,OAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACHG,IAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,IAAM,QAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACvCG,IAAM,mBAAA,GACX,MACA,CAAO,KAAA,EAAU,WAAA,KACf;AAcG,IAAM,oBAAA,GACX,MACA,CAAO,WAAA,EAAgB,KAAA,KACrB;;;AC5BJ,IAAM,SAAA,GAAY,QAAA;AAClB,IAAM,UAAA,GAAa,SAAA;AACnB,IAAM,oBAAA,GAAuB,mBAAA;AAC7B,IAAM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AA,mBAAA,GAAsBN,qBAAAA;AAc5B,EAAMM,SAAA,oBAAA,GAAuBD,sBAAAA;AAW7B,EAAMC,QAAAA,CAAA,eAAe,WAAA,CAAY,YAAA;AAAA,EAqCjC,MAAME,sBAAwB,aAAA,CAAiB;AAAA;AAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;AAAA,CAAA,EA5gBE,OAAA,KAAA,OAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,IAAO,aAAA,GAAQ","file":"index.mjs","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n }\n ? Exclude<O, undefined>\n : T;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n PhantomCore,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/assertors/brand.ts","../src/assertors/identity.ts","../src/assertors/trait.ts","../src/assertors/transformation.ts","../src/assertors/assertors.ts","../src/chain/chain.ts","../src/core/phantom.ts","../src/phantom.ts","../src/index.ts"],"names":["assertors","_PhantomChain","PhantomCore","_addTrait","_addTraits","_applyTransformation","_asBrand","_asIdentity","_dropTrait","_dropTraits","_revertTransformation","Phantom","Inspect","PhantomChain"],"mappings":";;;;;AAcO,IAAM,OAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,IAAM,UAAA,GACX,MACA,CAAI,KAAA,KACF;;;ACLG,IAAM,QAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,MACA,CAAI,KAAA,KACF;AAUG,IAAM,SAAA,GACX,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rBC,QAAAA,CAAA,SAAA,KAAAA,QAAAA,CAAA,SAAA,GAAA,EAAA,CAAA,CAAA;AA2GV,EAAMA,SAAA,OAAA,GAAUL,SAAAA;AAYhB,EAAMK,SAAA,UAAA,GAAaJ,YAAAA;AAUnB,EAAMI,SAAA,QAAA,GAAWR,UAAAA;AAUjB,EAAMQ,SAAA,SAAA,GAAYP,WAAAA;AAUlB,EAAMO,SAAA,SAAA,GAAYH,WAAAA;AAUlB,EAAMG,SAAA,UAAA,GAAaF,YAAAA;AAanB,EAAME,SAAA,mBAAA,GAAsBN,qBAAAA;AAc5B,EAAMM,SAAA,oBAAA,GAAuBD,sBAAAA;AAW7B,EAAMC,QAAAA,CAAA,eAAe,WAAA,CAAY,YAAA;AAAA,EAqCjC,MAAME,sBAAwB,aAAA,CAAiB;AAAA;AAA/C,EAAAF,SAAM,YAAA,GAAAE,aAAAA;AAAA,CAAA,EAthBE,OAAA,KAAA,OAAA,GAAA,EAAA,CAAA,CAAA;;;ACRjB,IAAO,aAAA,GAAQ","file":"index.mjs","sourcesContent":["import type { Brand } from '../core';\n\n/**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\nexport const asBrand =\n <B extends Brand.Any>() =>\n <T>(value: T) =>\n value as Brand.Assign<B, T>;\n","import type { Identity } from '../core';\n\n/**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\nexport const asIdentity =\n <I extends Identity.Any>() =>\n <V>(value: V): Identity.Assign<I, V> =>\n value as any;\n","import type { Trait } from '../core';\n\n/**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\nexport const addTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Add<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\nexport const addTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.AddMulti<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\nexport const dropTrait =\n <Tr extends Trait.Any>() =>\n <V>(value: V): Trait.Drop<Tr, V> =>\n value as any;\n\n/**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\nexport const dropTraits =\n <Tr extends Trait.Any[]>() =>\n <V>(value: V): Trait.DropMulti<Tr, V> =>\n value as any;\n","import type { Transformation } from '../core';\n\n/**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\nexport const applyTransformation =\n <Tr extends Transformation.Any>() =>\n <I, T>(input: I, transformed: T) =>\n transformed as Transformation.Apply<Tr, I, T>;\n\n/**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\nexport const revertTransformation =\n <Tr extends Transformation.Any>() =>\n <T, I>(transformed: T, input: I) =>\n input as Transformation.Revert<Tr, T, I>;\n","import { asBrand } from './brand';\nimport { asIdentity } from './identity';\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\nimport { applyTransformation, revertTransformation } from './transformation';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\n\nexport namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n}\n","/**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\nexport class PhantomChain<T> {\n private value: T;\n\n constructor(value: T) {\n this.value = value;\n }\n\n /**\n * Apply the next assertor in the chain.\n *\n * @param assertor A function that takes the current value and returns the updated value (with new type).\n * @returns A new PhantomChain instance with the updated value and type.\n */\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\n return new PhantomChain(assertor(this.value));\n }\n\n /**\n * End the chain and return the final value.\n *\n * @returns The value after all transformations.\n */\n end(): T {\n return this.value;\n }\n}\n","/** Stip phantom metadata object from a type */\ntype StripPhantom<T> = T extends {\n __Phantom: { __OriginalType?: infer O };\n}\n ? Exclude<O, undefined>\n : T;\n\n/** run-time helper for 'StringPhantom', used for debugging mainly */\nexport const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\n\n// Avoid bundler bugs\ntype _StripPhantom<T> = StripPhantom<T>;\nconst _stripPhantom = stripPhantom;\n\n/**\n * Phantom meatadata object manipulators.\n *\n * Phantom matadata object holds all metadata used by 'phantom'.\n */\nexport namespace PhantomCore {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = T extends {\n __Phantom: infer Phantom extends object;\n }\n ? Phantom\n : never;\n\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = _StripPhantom<T>;\n\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = _stripPhantom;\n}\n","import {\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nimport { PhantomChain } from './chain';\nimport type {\n BaseCore,\n InputCore,\n LabelCore,\n TagCore,\n TraitsCore,\n VariantsCore,\n BrandCore,\n IdentityCore,\n TraitCore,\n TransformationCore,\n ErrorType,\n} from './core';\nimport { PhantomCore } from './core';\n\nconst _addTrait = addTrait;\nconst _addTraits = addTraits;\nconst _applyTransformation = applyTransformation;\nconst _asBrand = asBrand;\nconst _asIdentity = asIdentity;\nconst _dropTrait = dropTrait;\nconst _dropTraits = dropTraits;\nconst _revertTransformation = revertTransformation;\nconst _PhantomChain = PhantomChain;\ntype _ErrorType<E> = ErrorType<E>;\n\nexport namespace Phantom {\n /** --------------------------------------\n * Types\n * --------------------------------------- */\n\n /**\n * Optional human-readable label metadata.\n *\n * Labels are descriptive only and do not affect identity.\n */\n export namespace Label {\n /** Marker type for labeled values */\n export type Any = LabelCore.Any;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a label exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n }\n\n /**\n * Nominal tag metadata.\n *\n * Tags uniquely identify a branded or identified type.\n * A value may only have a single tag.\n */\n export namespace Tag {\n /** Marker type for any tagged value */\n export type Any = TagCore.Any;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n }\n\n /**\n * Variant metadata.\n *\n * Variants represent mutually exclusive states of a type.\n */\n export namespace Variants {\n /** Marker type for variant-bearing values */\n export type Any = VariantsCore.Any;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n }\n\n /**\n * Base-type metadata.\n *\n * Used to constrain which runtime types a brand, identity,\n * or transformation may be applied to.\n */\n export namespace Base {\n /** Marker type for base constraints */\n export type Any = BaseCore.Any;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n }\n\n /**\n * Input metadata.\n *\n * Utilities for attaching and querying input metadata in transformations.\n */\n export namespace Input {\n /** Marker type for input value */\n export type Any = InputCore.Any;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n }\n\n /**\n * Trait metadata.\n *\n * Traits behave like a set of capabilities that can be\n * added or removed independently.\n */\n export namespace Traits {\n /** Marker type for trait-bearing values */\n export type Any = TraitsCore.Any;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n }\n\n /**\n * Branding API.\n *\n * Brands provide nominal typing for otherwise identical values.\n * A value may only be branded once.\n *\n * @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'\n */\n export namespace Brand {\n /** Type guard for any brand. */\n export type Any = BrandCore.Any;\n /** Declare a brand */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n > = BrandCore.Declare<T, L>;\n /** Assign a brand to a value. Fails if the value is already branded */\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\n /** Assign a brand if possible, otherwise return the original type */\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\n /** Check whether value is branded with */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n }\n\n /**\n * Identity API.\n *\n * Identities are brands with additional constraints:\n * - Base type\n * - Variants\n */\n export namespace Identity {\n /** Type guard for any identity. */\n export type Any = IdentityCore.Any;\n /** Declare an identity */\n export type Declare<\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = IdentityCore.Declare<T, L, B, V>;\n /** Assign an identity to a value. Enforces base-type compatibility */\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\n /** Safe identity assignment */\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\n /** Set the active variant on an identity */\n export type WithVariant<\n I extends Any,\n V extends Variants.VariantsOf<I>,\n > = IdentityCore.WithVariant<I, V>;\n /** Set the active variant on a value */\n export type WithTypeVariant<\n T,\n V extends Variants.VariantsOf<T>,\n > = IdentityCore.WithTypeVariant<T, V>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\n }\n\n /**\n * Trait API.\n *\n * Traits are additive capabilities that can be attached\n * or removed independently.\n */\n export namespace Trait {\n /** Type guard for any trait. */\n export type Any = TraitCore.Any;\n /** Declare a trait */\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\n /** Add a trait */\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\n /** Add multiple traits */\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\n Tr,\n T\n >;\n /** Remove a trait */\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\n /** Remove multiple traits */\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\n Tr,\n T\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\n }\n\n /**\n * Transformation API.\n *\n * Transformations represent reversible operations that\n * change the shape of a value while preserving its origin.\n */\n export namespace Transformation {\n /** Type guard for any transformation. */\n export type Any = TransformationCore.Any;\n /** Declare a transformation */\n export type Declare<\n I,\n T extends string | symbol,\n L extends string = never,\n B extends unknown = never,\n V extends string = never,\n > = TransformationCore.Declare<I, T, L, B, V>;\n /** Apply a transformation to a value. Enforces base-type compatibility */\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\n Tr,\n I,\n T\n >;\n /** Revert a transformation */\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\n Tr,\n T,\n I\n >;\n /** Revert a transformation whatever transformation was */\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /**\n * Inspect API.\n *\n * Inspection helpers of phantom types.\n */\n export namespace Inspect {\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n /** Extract the label */\n export type LabelOf<T> = LabelCore.LabelOf<T>;\n /** Check whether a base constraint exists */\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\n T,\n L\n >;\n /** Extract the tag from a type */\n export type TagOf<T> = TagCore.TagOf<T>;\n /** Check whether a type is tagged */\n export type HasTag<\n T,\n Ta extends string | symbol = string | symbol,\n > = TagCore.HasTag<T, Ta>;\n /** Extract variant union */\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\n /** Check whether variants exist */\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\n /** Extract the base type */\n export type BaseOf<T> = BaseCore.BaseOf<T>;\n /** Check whether a base constraint exists */\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\n /** Extract the input */\n export type InputOf<T> = InputCore.InputOf<T>;\n /** Check whether an input exists */\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\n /** Extract the trait map */\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\n /** Extract trait keys */\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\n /** Check if any traits exist */\n export type HasTraits<\n T,\n Tr extends string | symbol = string | symbol,\n > = TraitsCore.HasTraits<T, Tr>;\n /**\n * Check whether value is branded with\n *\n * @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'\n */\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\n /** Check whether value is branded with */\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\n T,\n I\n >;\n /** Check whether value has trait */\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\n /** Check whether value is transformed with */\n export type isTransformed<\n T,\n Tr extends Transformation.Any,\n > = TransformationCore.isTransformed<T, Tr>;\n }\n\n /** --------------------------------------\n * assertors\n * --------------------------------------- */\n\n export namespace assertors {\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n }\n\n /**\n * Creates a typed caster that assigns a {@link Brand} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the brand's nominal type applied. Use it for simple branded primitives\n * where you know the value is valid.\n *\n * @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'\n *\n * @template B - The brand declaration to assign.\n * @returns A function that casts any value to the branded type.\n */\n export const asBrand = _asBrand;\n\n /**\n * Creates a typed caster that assigns an {@link Identity} to a value.\n *\n * This is a zero-cost runtime assertion helper — it simply returns the value\n * with the identity's nominal type applied. Use it when you know a value\n * conforms to an identity but need to assert it for the type system.\n *\n * @template I - The identity declaration to assign.\n * @returns A function that casts any value to the assigned identity type.\n */\n export const asIdentity = _asIdentity;\n\n /**\n * Creates a typed caster that adds a single {@link Trait} to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to add.\n * @returns A function that adds the trait to any value.\n */\n export const addTrait = _addTrait;\n\n /**\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to add.\n * @returns A function that adds all traits to any value.\n */\n export const addTraits = _addTraits;\n\n /**\n * Creates a typed caster that removes a single {@link Trait} from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The trait declaration to remove.\n * @returns A function that drops the trait from any value.\n */\n export const dropTrait = _dropTrait;\n\n /**\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - Tuple of trait declarations to remove.\n * @returns A function that drops all specified traits from any value.\n */\n export const dropTraits = _dropTraits;\n\n /**\n * Creates a typed applicator for a {@link Transformation}.\n *\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\n * The `input` parameter is only used for type inference — it is not used at runtime.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that applies the transformation while preserving the input type for later revert.\n */\n export const applyTransformation = _applyTransformation;\n\n /**\n * Creates a typed reverter for a {@link Transformation}.\n *\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\n * The `transformed` parameter is used for type inference of the expected input,\n * and `input` is the computed result that must match the stored input type.\n *\n * Zero-runtime-cost assertion helper.\n *\n * @template Tr - The transformation declaration.\n * @returns A function that reverts the transformation, stripping phantom metadata.\n */\n export const revertTransformation = _revertTransformation;\n\n /** --------------------------------------\n * Phantom object manipulators\n * --------------------------------------- */\n\n /** Get phantom metadata object from a type */\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\n /** Stip phantom metadata object from a type */\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\n /** run-time helper for 'StringPhantom', used for debugging mainly */\n export const stripPhantom = PhantomCore.stripPhantom;\n\n /** --------------------------------------\n * Error type\n * --------------------------------------- */\n\n /** Unique Error type for rules validation in phantom. */\n export type ErrorType<E> = _ErrorType<E>;\n\n /** --------------------------------------\n * Chain class\n * --------------------------------------- */\n\n /**\n * A fluent PhantomChain class for chaining Phantom assertors.\n *\n * This provides a better developer experience (DX) by allowing method chaining\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\n * Call `.end()` to retrieve the final value.\n *\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\n * (just object creation and method calls).\n *\n * Example:\n * ```ts\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\n *\n * const result = new PhantomChain(\"value\")\n * .with(asMyBrand)\n * .with(asMyTrait)\n * .with(applyMyTransform)\n * .end();\n * ```\n */\n export class PhantomChain<T> extends _PhantomChain<T> {}\n}\n","export {\n assertors,\n addTrait,\n addTraits,\n applyTransformation,\n asBrand,\n asIdentity,\n dropTrait,\n dropTraits,\n revertTransformation,\n} from './assertors';\nexport { PhantomChain } from './chain';\nexport { Phantom } from './phantom';\nexport type {\n Base,\n Brand,\n ErrorType,\n Identity,\n Input,\n Inspect,\n Label,\n Tag,\n Trait,\n Traits,\n Transformation,\n Variants,\n} from './core';\nexport { PhantomCore, stripPhantom } from './core';\nimport { Phantom } from './phantom';\nexport default Phantom;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vicin/phantom",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Powerful, lightweight TypeScript library for nominal typing.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,7 +38,20 @@
|
|
|
38
38
|
"keywords": [
|
|
39
39
|
"typescript",
|
|
40
40
|
"nominal-typing",
|
|
41
|
-
"ddd"
|
|
41
|
+
"ddd",
|
|
42
|
+
"domain-driven-design",
|
|
43
|
+
"branding",
|
|
44
|
+
"branded-types",
|
|
45
|
+
"type-safety",
|
|
46
|
+
"metadata",
|
|
47
|
+
"type-metadata",
|
|
48
|
+
"identity",
|
|
49
|
+
"traits",
|
|
50
|
+
"type-transformations",
|
|
51
|
+
"state-variants",
|
|
52
|
+
"type-pipe",
|
|
53
|
+
"zero-runtime",
|
|
54
|
+
"type-only"
|
|
42
55
|
],
|
|
43
56
|
"author": "Ziad ziadtaha62@gmail.com",
|
|
44
57
|
"license": "MIT",
|