@vicin/phantom 1.0.5 → 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/LICENSE +7 -7
- package/README.md +860 -884
- package/dist/index.d.mts +50 -20
- package/dist/index.d.ts +50 -20
- 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 +73 -61
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
|
*/
|
|
@@ -20,16 +22,7 @@ declare namespace assertors {
|
|
|
20
22
|
* @template I - The identity declaration to assign.
|
|
21
23
|
* @returns A function that casts any value to the assigned identity type.
|
|
22
24
|
*/
|
|
23
|
-
const asIdentity: <I extends Identity.Any>() =>
|
|
24
|
-
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
25
|
-
*
|
|
26
|
-
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
27
|
-
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
28
|
-
* where you know the value is valid.
|
|
29
|
-
*
|
|
30
|
-
* @template B - The brand declaration to assign.
|
|
31
|
-
* @returns A function that casts any value to the branded type.
|
|
32
|
-
*/ V>(value: V) => Identity.Assign<I, V>;
|
|
25
|
+
const asIdentity: <I extends Identity.Any>() => <V>(value: V) => Identity.Assign<I, V>;
|
|
33
26
|
/**
|
|
34
27
|
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
35
28
|
*
|
|
@@ -320,6 +313,15 @@ declare namespace VariantsCore {
|
|
|
320
313
|
} ? true : false;
|
|
321
314
|
}
|
|
322
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>;
|
|
323
325
|
/**
|
|
324
326
|
* Phantom meatadata object manipulators.
|
|
325
327
|
*
|
|
@@ -331,13 +333,13 @@ declare namespace PhantomCore {
|
|
|
331
333
|
__Phantom: infer Phantom extends object;
|
|
332
334
|
} ? Phantom : never;
|
|
333
335
|
/** Stip phantom metadata object from a type */
|
|
334
|
-
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 {
|
|
335
339
|
__Phantom: {
|
|
336
340
|
__OriginalType?: infer O;
|
|
337
341
|
};
|
|
338
342
|
} ? Exclude<O, undefined> : T;
|
|
339
|
-
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
340
|
-
const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
341
343
|
}
|
|
342
344
|
|
|
343
345
|
/** Interface of 'Brand' and 'Identity' errors. */
|
|
@@ -450,6 +452,8 @@ type Merge<O1 extends object, O2 extends object> = Prettify<Omit<O1, keyof O2> &
|
|
|
450
452
|
*
|
|
451
453
|
* Brands provide nominal typing for otherwise identical values.
|
|
452
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'
|
|
453
457
|
*/
|
|
454
458
|
declare namespace BrandCore {
|
|
455
459
|
/** Type guard for any brand. */
|
|
@@ -485,7 +489,7 @@ declare namespace IdentityCore {
|
|
|
485
489
|
/** Type guard for any identity. */
|
|
486
490
|
export type Any = TagCore.Of<string | symbol>;
|
|
487
491
|
/** Declare an identity */
|
|
488
|
-
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>>;
|
|
489
493
|
/**
|
|
490
494
|
* Assign an identity to a value.
|
|
491
495
|
* Enforces base-type compatibility.
|
|
@@ -550,7 +554,7 @@ declare namespace TransformationCore {
|
|
|
550
554
|
/** Type guard for any transformation. */
|
|
551
555
|
export type Any = InputCore.Of<any> & TagCore.Of<string | symbol>;
|
|
552
556
|
/** Declare a transformation */
|
|
553
|
-
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>>;
|
|
554
558
|
/**
|
|
555
559
|
* Apply a transformation to a value.
|
|
556
560
|
* Enforces base-type compatibility.
|
|
@@ -665,6 +669,8 @@ declare namespace Traits {
|
|
|
665
669
|
*
|
|
666
670
|
* Brands provide nominal typing for otherwise identical values.
|
|
667
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'
|
|
668
674
|
*/
|
|
669
675
|
declare namespace Brand {
|
|
670
676
|
/** Type guard for any brand. */
|
|
@@ -776,7 +782,11 @@ declare namespace Inspect {
|
|
|
776
782
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
777
783
|
/** Check if any traits exist */
|
|
778
784
|
type HasTraits<T> = TraitsCore.HasTraits<T>;
|
|
779
|
-
/**
|
|
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
|
+
*/
|
|
780
790
|
type isBrand<T, B extends BrandCore.Any> = BrandCore.isBrand<T, B>;
|
|
781
791
|
/** Check whether value is branded with */
|
|
782
792
|
type isIdentity<T, I extends IdentityCore.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -793,6 +803,8 @@ declare namespace Inspect {
|
|
|
793
803
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
794
804
|
* where you know the value is valid.
|
|
795
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
|
+
*
|
|
796
808
|
* @template B - The brand declaration to assign.
|
|
797
809
|
* @returns A function that casts any value to the branded type.
|
|
798
810
|
*/
|
|
@@ -1009,6 +1021,8 @@ declare namespace Phantom {
|
|
|
1009
1021
|
*
|
|
1010
1022
|
* Brands provide nominal typing for otherwise identical values.
|
|
1011
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'
|
|
1012
1026
|
*/
|
|
1013
1027
|
namespace Brand {
|
|
1014
1028
|
/** Type guard for any brand. */
|
|
@@ -1098,7 +1112,11 @@ declare namespace Phantom {
|
|
|
1098
1112
|
/** Stip phantom metadata object from a type */
|
|
1099
1113
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1100
1114
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1101
|
-
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;
|
|
1102
1120
|
/** Extract the label */
|
|
1103
1121
|
type LabelOf<T> = LabelCore.LabelOf<T>;
|
|
1104
1122
|
/** Check whether a base constraint exists */
|
|
@@ -1125,7 +1143,11 @@ declare namespace Phantom {
|
|
|
1125
1143
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
1126
1144
|
/** Check if any traits exist */
|
|
1127
1145
|
type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
|
|
1128
|
-
/**
|
|
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
|
+
*/
|
|
1129
1151
|
type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
|
|
1130
1152
|
/** Check whether value is branded with */
|
|
1131
1153
|
type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -1145,6 +1167,8 @@ declare namespace Phantom {
|
|
|
1145
1167
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1146
1168
|
* where you know the value is valid.
|
|
1147
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
|
+
*
|
|
1148
1172
|
* @template B - The brand declaration to assign.
|
|
1149
1173
|
* @returns A function that casts any value to the branded type.
|
|
1150
1174
|
*/
|
|
@@ -1229,6 +1253,8 @@ declare namespace Phantom {
|
|
|
1229
1253
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1230
1254
|
* where you know the value is valid.
|
|
1231
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
|
+
*
|
|
1232
1258
|
* @template B - The brand declaration to assign.
|
|
1233
1259
|
* @returns A function that casts any value to the branded type.
|
|
1234
1260
|
*/
|
|
@@ -1313,7 +1339,11 @@ declare namespace Phantom {
|
|
|
1313
1339
|
/** Stip phantom metadata object from a type */
|
|
1314
1340
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1315
1341
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1316
|
-
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;
|
|
1317
1347
|
/** --------------------------------------
|
|
1318
1348
|
* Error type
|
|
1319
1349
|
* --------------------------------------- */
|
|
@@ -1350,4 +1380,4 @@ declare namespace Phantom {
|
|
|
1350
1380
|
}
|
|
1351
1381
|
}
|
|
1352
1382
|
|
|
1353
|
-
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
|
*/
|
|
@@ -20,16 +22,7 @@ declare namespace assertors {
|
|
|
20
22
|
* @template I - The identity declaration to assign.
|
|
21
23
|
* @returns A function that casts any value to the assigned identity type.
|
|
22
24
|
*/
|
|
23
|
-
const asIdentity: <I extends Identity.Any>() =>
|
|
24
|
-
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
25
|
-
*
|
|
26
|
-
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
27
|
-
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
28
|
-
* where you know the value is valid.
|
|
29
|
-
*
|
|
30
|
-
* @template B - The brand declaration to assign.
|
|
31
|
-
* @returns A function that casts any value to the branded type.
|
|
32
|
-
*/ V>(value: V) => Identity.Assign<I, V>;
|
|
25
|
+
const asIdentity: <I extends Identity.Any>() => <V>(value: V) => Identity.Assign<I, V>;
|
|
33
26
|
/**
|
|
34
27
|
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
35
28
|
*
|
|
@@ -320,6 +313,15 @@ declare namespace VariantsCore {
|
|
|
320
313
|
} ? true : false;
|
|
321
314
|
}
|
|
322
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>;
|
|
323
325
|
/**
|
|
324
326
|
* Phantom meatadata object manipulators.
|
|
325
327
|
*
|
|
@@ -331,13 +333,13 @@ declare namespace PhantomCore {
|
|
|
331
333
|
__Phantom: infer Phantom extends object;
|
|
332
334
|
} ? Phantom : never;
|
|
333
335
|
/** Stip phantom metadata object from a type */
|
|
334
|
-
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 {
|
|
335
339
|
__Phantom: {
|
|
336
340
|
__OriginalType?: infer O;
|
|
337
341
|
};
|
|
338
342
|
} ? Exclude<O, undefined> : T;
|
|
339
|
-
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
340
|
-
const stripPhantom: <T>(value: T) => StripPhantom<T>;
|
|
341
343
|
}
|
|
342
344
|
|
|
343
345
|
/** Interface of 'Brand' and 'Identity' errors. */
|
|
@@ -450,6 +452,8 @@ type Merge<O1 extends object, O2 extends object> = Prettify<Omit<O1, keyof O2> &
|
|
|
450
452
|
*
|
|
451
453
|
* Brands provide nominal typing for otherwise identical values.
|
|
452
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'
|
|
453
457
|
*/
|
|
454
458
|
declare namespace BrandCore {
|
|
455
459
|
/** Type guard for any brand. */
|
|
@@ -485,7 +489,7 @@ declare namespace IdentityCore {
|
|
|
485
489
|
/** Type guard for any identity. */
|
|
486
490
|
export type Any = TagCore.Of<string | symbol>;
|
|
487
491
|
/** Declare an identity */
|
|
488
|
-
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>>;
|
|
489
493
|
/**
|
|
490
494
|
* Assign an identity to a value.
|
|
491
495
|
* Enforces base-type compatibility.
|
|
@@ -550,7 +554,7 @@ declare namespace TransformationCore {
|
|
|
550
554
|
/** Type guard for any transformation. */
|
|
551
555
|
export type Any = InputCore.Of<any> & TagCore.Of<string | symbol>;
|
|
552
556
|
/** Declare a transformation */
|
|
553
|
-
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>>;
|
|
554
558
|
/**
|
|
555
559
|
* Apply a transformation to a value.
|
|
556
560
|
* Enforces base-type compatibility.
|
|
@@ -665,6 +669,8 @@ declare namespace Traits {
|
|
|
665
669
|
*
|
|
666
670
|
* Brands provide nominal typing for otherwise identical values.
|
|
667
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'
|
|
668
674
|
*/
|
|
669
675
|
declare namespace Brand {
|
|
670
676
|
/** Type guard for any brand. */
|
|
@@ -776,7 +782,11 @@ declare namespace Inspect {
|
|
|
776
782
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
777
783
|
/** Check if any traits exist */
|
|
778
784
|
type HasTraits<T> = TraitsCore.HasTraits<T>;
|
|
779
|
-
/**
|
|
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
|
+
*/
|
|
780
790
|
type isBrand<T, B extends BrandCore.Any> = BrandCore.isBrand<T, B>;
|
|
781
791
|
/** Check whether value is branded with */
|
|
782
792
|
type isIdentity<T, I extends IdentityCore.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -793,6 +803,8 @@ declare namespace Inspect {
|
|
|
793
803
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
794
804
|
* where you know the value is valid.
|
|
795
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
|
+
*
|
|
796
808
|
* @template B - The brand declaration to assign.
|
|
797
809
|
* @returns A function that casts any value to the branded type.
|
|
798
810
|
*/
|
|
@@ -1009,6 +1021,8 @@ declare namespace Phantom {
|
|
|
1009
1021
|
*
|
|
1010
1022
|
* Brands provide nominal typing for otherwise identical values.
|
|
1011
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'
|
|
1012
1026
|
*/
|
|
1013
1027
|
namespace Brand {
|
|
1014
1028
|
/** Type guard for any brand. */
|
|
@@ -1098,7 +1112,11 @@ declare namespace Phantom {
|
|
|
1098
1112
|
/** Stip phantom metadata object from a type */
|
|
1099
1113
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1100
1114
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1101
|
-
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;
|
|
1102
1120
|
/** Extract the label */
|
|
1103
1121
|
type LabelOf<T> = LabelCore.LabelOf<T>;
|
|
1104
1122
|
/** Check whether a base constraint exists */
|
|
@@ -1125,7 +1143,11 @@ declare namespace Phantom {
|
|
|
1125
1143
|
type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;
|
|
1126
1144
|
/** Check if any traits exist */
|
|
1127
1145
|
type HasTraits<T, Tr extends string | symbol = string | symbol> = TraitsCore.HasTraits<T, Tr>;
|
|
1128
|
-
/**
|
|
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
|
+
*/
|
|
1129
1151
|
type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;
|
|
1130
1152
|
/** Check whether value is branded with */
|
|
1131
1153
|
type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<T, I>;
|
|
@@ -1145,6 +1167,8 @@ declare namespace Phantom {
|
|
|
1145
1167
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1146
1168
|
* where you know the value is valid.
|
|
1147
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
|
+
*
|
|
1148
1172
|
* @template B - The brand declaration to assign.
|
|
1149
1173
|
* @returns A function that casts any value to the branded type.
|
|
1150
1174
|
*/
|
|
@@ -1229,6 +1253,8 @@ declare namespace Phantom {
|
|
|
1229
1253
|
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
1230
1254
|
* where you know the value is valid.
|
|
1231
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
|
+
*
|
|
1232
1258
|
* @template B - The brand declaration to assign.
|
|
1233
1259
|
* @returns A function that casts any value to the branded type.
|
|
1234
1260
|
*/
|
|
@@ -1313,7 +1339,11 @@ declare namespace Phantom {
|
|
|
1313
1339
|
/** Stip phantom metadata object from a type */
|
|
1314
1340
|
type StripPhantom<T> = PhantomCore.StripPhantom<T>;
|
|
1315
1341
|
/** run-time helper for 'StringPhantom', used for debugging mainly */
|
|
1316
|
-
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;
|
|
1317
1347
|
/** --------------------------------------
|
|
1318
1348
|
* Error type
|
|
1319
1349
|
* --------------------------------------- */
|
|
@@ -1350,4 +1380,4 @@ declare namespace Phantom {
|
|
|
1350
1380
|
}
|
|
1351
1381
|
}
|
|
1352
1382
|
|
|
1353
|
-
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":"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","file":"index.global.js","sourcesContent":["import type { Brand } from '../core';\r\n\r\n/**\r\n * Creates a typed caster that assigns a {@link Brand} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the brand's nominal type applied. Use it for simple branded primitives\r\n * where you know the value is valid.\r\n *\r\n * @template B - The brand declaration to assign.\r\n * @returns A function that casts any value to the branded type.\r\n */\r\nexport const asBrand =\r\n <B extends Brand.Any>() =>\r\n <T>(value: T) =>\r\n value as Brand.Assign<B, T>;\r\n","import type { Identity } from '../core';\r\n\r\n/**\r\n * Creates a typed caster that assigns an {@link Identity} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the identity's nominal type applied. Use it when you know a value\r\n * conforms to an identity but need to assert it for the type system.\r\n *\r\n * @template I - The identity declaration to assign.\r\n * @returns A function that casts any value to the assigned identity type.\r\n */\r\nexport const asIdentity =\r\n <I extends Identity.Any>() =>\r\n <V>(value: V): Identity.Assign<I, V> =>\r\n value as any;\r\n","import type { Trait } from '../core';\r\n\r\n/**\r\n * Creates a typed caster that adds a single {@link Trait} to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to add.\r\n * @returns A function that adds the trait to any value.\r\n */\r\nexport const addTrait =\r\n <Tr extends Trait.Any>() =>\r\n <V>(value: V): Trait.Add<Tr, V> =>\r\n value as any;\r\n\r\n/**\r\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to add.\r\n * @returns A function that adds all traits to any value.\r\n */\r\nexport const addTraits =\r\n <Tr extends Trait.Any[]>() =>\r\n <V>(value: V): Trait.AddMulti<Tr, V> =>\r\n value as any;\r\n\r\n/**\r\n * Creates a typed caster that removes a single {@link Trait} from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to remove.\r\n * @returns A function that drops the trait from any value.\r\n */\r\nexport const dropTrait =\r\n <Tr extends Trait.Any>() =>\r\n <V>(value: V): Trait.Drop<Tr, V> =>\r\n value as any;\r\n\r\n/**\r\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to remove.\r\n * @returns A function that drops all specified traits from any value.\r\n */\r\nexport const dropTraits =\r\n <Tr extends Trait.Any[]>() =>\r\n <V>(value: V): Trait.DropMulti<Tr, V> =>\r\n value as any;\r\n","import type { Transformation } from '../core';\r\n\r\n/**\r\n * Creates a typed applicator for a {@link Transformation}.\r\n *\r\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\r\n * The `input` parameter is only used for type inference — it is not used at runtime.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that applies the transformation while preserving the input type for later revert.\r\n */\r\nexport const applyTransformation =\r\n <Tr extends Transformation.Any>() =>\r\n <I, T>(input: I, transformed: T) =>\r\n transformed as Transformation.Apply<Tr, I, T>;\r\n\r\n/**\r\n * Creates a typed reverter for a {@link Transformation}.\r\n *\r\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\r\n * The `transformed` parameter is used for type inference of the expected input,\r\n * and `input` is the computed result that must match the stored input type.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that reverts the transformation, stripping phantom metadata.\r\n */\r\nexport const revertTransformation =\r\n <Tr extends Transformation.Any>() =>\r\n <T, I>(transformed: T, input: I) =>\r\n input as Transformation.Revert<Tr, T, I>;\r\n","import { asBrand } from './brand';\r\nimport { asIdentity } from './identity';\r\nimport { addTrait, addTraits, dropTrait, dropTraits } from './trait';\r\nimport { applyTransformation, revertTransformation } from './transformation';\r\n\r\nconst _addTrait = addTrait;\r\nconst _addTraits = addTraits;\r\nconst _applyTransformation = applyTransformation;\r\nconst _asBrand = asBrand;\r\nconst _asIdentity = asIdentity;\r\nconst _dropTrait = dropTrait;\r\nconst _dropTraits = dropTraits;\r\nconst _revertTransformation = revertTransformation;\r\n\r\nexport namespace assertors {\r\n /**\r\n * Creates a typed caster that assigns a {@link Brand} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the brand's nominal type applied. Use it for simple branded primitives\r\n * where you know the value is valid.\r\n *\r\n * @template B - The brand declaration to assign.\r\n * @returns A function that casts any value to the branded type.\r\n */\r\n export const asBrand = _asBrand;\r\n\r\n /**\r\n * Creates a typed caster that assigns an {@link Identity} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the identity's nominal type applied. Use it when you know a value\r\n * conforms to an identity but need to assert it for the type system.\r\n *\r\n * @template I - The identity declaration to assign.\r\n * @returns A function that casts any value to the assigned identity type.\r\n */\r\n export const asIdentity = _asIdentity;\r\n\r\n /**\r\n * Creates a typed caster that adds a single {@link Trait} to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to add.\r\n * @returns A function that adds the trait to any value.\r\n */\r\n export const addTrait = _addTrait;\r\n\r\n /**\r\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to add.\r\n * @returns A function that adds all traits to any value.\r\n */\r\n export const addTraits = _addTraits;\r\n\r\n /**\r\n * Creates a typed caster that removes a single {@link Trait} from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to remove.\r\n * @returns A function that drops the trait from any value.\r\n */\r\n export const dropTrait = _dropTrait;\r\n\r\n /**\r\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to remove.\r\n * @returns A function that drops all specified traits from any value.\r\n */\r\n export const dropTraits = _dropTraits;\r\n\r\n /**\r\n * Creates a typed applicator for a {@link Transformation}.\r\n *\r\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\r\n * The `input` parameter is only used for type inference — it is not used at runtime.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that applies the transformation while preserving the input type for later revert.\r\n */\r\n export const applyTransformation = _applyTransformation;\r\n\r\n /**\r\n * Creates a typed reverter for a {@link Transformation}.\r\n *\r\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\r\n * The `transformed` parameter is used for type inference of the expected input,\r\n * and `input` is the computed result that must match the stored input type.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that reverts the transformation, stripping phantom metadata.\r\n */\r\n export const revertTransformation = _revertTransformation;\r\n}\r\n","/**\r\n * A fluent PhantomChain class for chaining Phantom assertors.\r\n *\r\n * This provides a better developer experience (DX) by allowing method chaining\r\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\r\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\r\n * Call `.end()` to retrieve the final value.\r\n *\r\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\r\n * (just object creation and method calls).\r\n *\r\n * Example:\r\n * ```ts\r\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\r\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\r\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\r\n *\r\n * const result = new PhantomChain(\"value\")\r\n * .with(asMyBrand)\r\n * .with(asMyTrait)\r\n * .with(applyMyTransform)\r\n * .end();\r\n * ```\r\n */\r\nexport class PhantomChain<T> {\r\n private value: T;\r\n\r\n constructor(value: T) {\r\n this.value = value;\r\n }\r\n\r\n /**\r\n * Apply the next assertor in the chain.\r\n *\r\n * @param assertor A function that takes the current value and returns the updated value (with new type).\r\n * @returns A new PhantomChain instance with the updated value and type.\r\n */\r\n with<U>(assertor: (value: T) => U): PhantomChain<U> {\r\n return new PhantomChain(assertor(this.value));\r\n }\r\n\r\n /**\r\n * End the chain and return the final value.\r\n *\r\n * @returns The value after all transformations.\r\n */\r\n end(): T {\r\n return this.value;\r\n }\r\n}\r\n","/**\r\n * Phantom meatadata object manipulators.\r\n *\r\n * Phantom matadata object holds all metadata used by 'phantom'.\r\n */\r\nexport namespace PhantomCore {\r\n /** Get phantom metadata object from a type */\r\n export type PhantomOf<T> = T extends {\r\n __Phantom: infer Phantom extends object;\r\n }\r\n ? Phantom\r\n : never;\r\n\r\n /** Stip phantom metadata object from a type */\r\n export type StripPhantom<T> = T extends {\r\n __Phantom: { __OriginalType?: infer O };\r\n }\r\n ? Exclude<O, undefined>\r\n : T;\r\n\r\n /** run-time helper for 'StringPhantom', used for debugging mainly */\r\n export const stripPhantom = <T>(value: T): StripPhantom<T> => value as any;\r\n}\r\n","import {\r\n addTrait,\r\n addTraits,\r\n applyTransformation,\r\n asBrand,\r\n asIdentity,\r\n dropTrait,\r\n dropTraits,\r\n revertTransformation,\r\n} from './assertors';\r\nimport { PhantomChain } from './chain';\r\nimport type {\r\n BaseCore,\r\n InputCore,\r\n LabelCore,\r\n TagCore,\r\n TraitsCore,\r\n VariantsCore,\r\n BrandCore,\r\n IdentityCore,\r\n TraitCore,\r\n TransformationCore,\r\n ErrorType,\r\n} from './core';\r\nimport { PhantomCore } from './core';\r\n\r\nconst _addTrait = addTrait;\r\nconst _addTraits = addTraits;\r\nconst _applyTransformation = applyTransformation;\r\nconst _asBrand = asBrand;\r\nconst _asIdentity = asIdentity;\r\nconst _dropTrait = dropTrait;\r\nconst _dropTraits = dropTraits;\r\nconst _revertTransformation = revertTransformation;\r\nconst _PhantomChain = PhantomChain;\r\ntype _ErrorType<E> = ErrorType<E>;\r\n\r\nexport namespace Phantom {\r\n /** --------------------------------------\r\n * Types\r\n * --------------------------------------- */\r\n\r\n /**\r\n * Optional human-readable label metadata.\r\n *\r\n * Labels are descriptive only and do not affect identity.\r\n */\r\n export namespace Label {\r\n /** Marker type for labeled values */\r\n export type Any = LabelCore.Any;\r\n /** Extract the label */\r\n export type LabelOf<T> = LabelCore.LabelOf<T>;\r\n /** Check whether a label exists */\r\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\r\n T,\r\n L\r\n >;\r\n }\r\n\r\n /**\r\n * Nominal tag metadata.\r\n *\r\n * Tags uniquely identify a branded or identified type.\r\n * A value may only have a single tag.\r\n */\r\n export namespace Tag {\r\n /** Marker type for any tagged value */\r\n export type Any = TagCore.Any;\r\n /** Extract the tag from a type */\r\n export type TagOf<T> = TagCore.TagOf<T>;\r\n /** Check whether a type is tagged */\r\n export type HasTag<\r\n T,\r\n Ta extends string | symbol = string | symbol,\r\n > = TagCore.HasTag<T, Ta>;\r\n }\r\n\r\n /**\r\n * Variant metadata.\r\n *\r\n * Variants represent mutually exclusive states of a type.\r\n */\r\n export namespace Variants {\r\n /** Marker type for variant-bearing values */\r\n export type Any = VariantsCore.Any;\r\n /** Extract variant union */\r\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\r\n /** Check whether variants exist */\r\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\r\n }\r\n\r\n /**\r\n * Base-type metadata.\r\n *\r\n * Used to constrain which runtime types a brand, identity,\r\n * or transformation may be applied to.\r\n */\r\n export namespace Base {\r\n /** Marker type for base constraints */\r\n export type Any = BaseCore.Any;\r\n /** Extract the base type */\r\n export type BaseOf<T> = BaseCore.BaseOf<T>;\r\n /** Check whether a base constraint exists */\r\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\r\n }\r\n\r\n /**\r\n * Input metadata.\r\n *\r\n * Utilities for attaching and querying input metadata in transformations.\r\n */\r\n export namespace Input {\r\n /** Marker type for input value */\r\n export type Any = InputCore.Any;\r\n /** Extract the input */\r\n export type InputOf<T> = InputCore.InputOf<T>;\r\n /** Check whether an input exists */\r\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\r\n }\r\n\r\n /**\r\n * Trait metadata.\r\n *\r\n * Traits behave like a set of capabilities that can be\r\n * added or removed independently.\r\n */\r\n export namespace Traits {\r\n /** Marker type for trait-bearing values */\r\n export type Any = TraitsCore.Any;\r\n /** Extract the trait map */\r\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\r\n /** Extract trait keys */\r\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\r\n /** Check if any traits exist */\r\n export type HasTraits<\r\n T,\r\n Tr extends string | symbol = string | symbol,\r\n > = TraitsCore.HasTraits<T, Tr>;\r\n }\r\n\r\n /**\r\n * Branding API.\r\n *\r\n * Brands provide nominal typing for otherwise identical values.\r\n * A value may only be branded once.\r\n */\r\n export namespace Brand {\r\n /** Type guard for any brand. */\r\n export type Any = BrandCore.Any;\r\n /** Declare a brand */\r\n export type Declare<\r\n T extends string | symbol,\r\n L extends string = never,\r\n > = BrandCore.Declare<T, L>;\r\n /** Assign a brand to a value. Fails if the value is already branded */\r\n export type Assign<B extends Any, T> = BrandCore.Assign<B, T>;\r\n /** Assign a brand if possible, otherwise return the original type */\r\n export type AssignSafe<B extends Any, T> = BrandCore.AssignSafe<B, T>;\r\n /** Check whether value is branded with */\r\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\r\n }\r\n\r\n /**\r\n * Identity API.\r\n *\r\n * Identities are brands with additional constraints:\r\n * - Base type\r\n * - Variants\r\n */\r\n export namespace Identity {\r\n /** Type guard for any identity. */\r\n export type Any = IdentityCore.Any;\r\n /** Declare an identity */\r\n export type Declare<\r\n T extends string | symbol,\r\n L extends string = never,\r\n B extends unknown = never,\r\n V extends string = never,\r\n > = IdentityCore.Declare<T, L, B, V>;\r\n /** Assign an identity to a value. Enforces base-type compatibility */\r\n export type Assign<I extends Any, T> = IdentityCore.Assign<I, T>;\r\n /** Safe identity assignment */\r\n export type AssignSafe<I extends Any, T> = IdentityCore.AssignSafe<I, T>;\r\n /** Set the active variant on an identity */\r\n export type WithVariant<\r\n I extends Any,\r\n V extends Variants.VariantsOf<I>,\r\n > = IdentityCore.WithVariant<I, V>;\r\n /** Set the active variant on a value */\r\n export type WithTypeVariant<\r\n T,\r\n V extends Variants.VariantsOf<T>,\r\n > = IdentityCore.WithTypeVariant<T, V>;\r\n /** Check whether value is branded with */\r\n export type isIdentity<T, I extends Any> = IdentityCore.isIdentity<T, I>;\r\n }\r\n\r\n /**\r\n * Trait API.\r\n *\r\n * Traits are additive capabilities that can be attached\r\n * or removed independently.\r\n */\r\n export namespace Trait {\r\n /** Type guard for any trait. */\r\n export type Any = TraitCore.Any;\r\n /** Declare a trait */\r\n export type Declare<Tr extends string | symbol> = TraitCore.Declare<Tr>;\r\n /** Add a trait */\r\n export type Add<Tr extends Any, T> = TraitCore.Add<Tr, T>;\r\n /** Add multiple traits */\r\n export type AddMulti<Tr extends readonly Any[], T> = TraitCore.AddMulti<\r\n Tr,\r\n T\r\n >;\r\n /** Remove a trait */\r\n export type Drop<Tr extends Any, T> = TraitCore.Drop<Tr, T>;\r\n /** Remove multiple traits */\r\n export type DropMulti<Tr extends readonly Any[], T> = TraitCore.DropMulti<\r\n Tr,\r\n T\r\n >;\r\n /** Check whether value has trait */\r\n export type HasTrait<T, Tr extends Any> = TraitCore.HasTrait<T, Tr>;\r\n }\r\n\r\n /**\r\n * Transformation API.\r\n *\r\n * Transformations represent reversible operations that\r\n * change the shape of a value while preserving its origin.\r\n */\r\n export namespace Transformation {\r\n /** Type guard for any transformation. */\r\n export type Any = TransformationCore.Any;\r\n /** Declare a transformation */\r\n export type Declare<\r\n I,\r\n T extends string | symbol,\r\n L extends string = never,\r\n B extends unknown = never,\r\n V extends string = never,\r\n > = TransformationCore.Declare<I, T, L, B, V>;\r\n /** Apply a transformation to a value. Enforces base-type compatibility */\r\n export type Apply<Tr extends Any, I, T> = TransformationCore.Apply<\r\n Tr,\r\n I,\r\n T\r\n >;\r\n /** Revert a transformation */\r\n export type Revert<Tr extends Any, T, I> = TransformationCore.Revert<\r\n Tr,\r\n T,\r\n I\r\n >;\r\n /** Revert a transformation whatever transformation was */\r\n export type RevertAny<T, I> = TransformationCore.RevertAny<T, I>;\r\n /** Check whether value is transformed with */\r\n export type isTransformed<\r\n T,\r\n Tr extends Any,\r\n > = TransformationCore.isTransformed<T, Tr>;\r\n }\r\n\r\n /**\r\n * Inspect API.\r\n *\r\n * Inspection helpers of phantom types.\r\n */\r\n export namespace Inspect {\r\n /** Get phantom metadata object from a type */\r\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\r\n /** Stip phantom metadata object from a type */\r\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\r\n /** run-time helper for 'StringPhantom', used for debugging mainly */\r\n export const stripPhantom = PhantomCore.stripPhantom;\r\n /** Extract the label */\r\n export type LabelOf<T> = LabelCore.LabelOf<T>;\r\n /** Check whether a base constraint exists */\r\n export type HasLabel<T, L extends string = string> = LabelCore.HasLabel<\r\n T,\r\n L\r\n >;\r\n /** Extract the tag from a type */\r\n export type TagOf<T> = TagCore.TagOf<T>;\r\n /** Check whether a type is tagged */\r\n export type HasTag<\r\n T,\r\n Ta extends string | symbol = string | symbol,\r\n > = TagCore.HasTag<T, Ta>;\r\n /** Extract variant union */\r\n export type VariantsOf<T> = VariantsCore.VariantsOf<T>;\r\n /** Check whether variants exist */\r\n export type HasVariants<T> = VariantsCore.HasVariants<T>;\r\n /** Extract the base type */\r\n export type BaseOf<T> = BaseCore.BaseOf<T>;\r\n /** Check whether a base constraint exists */\r\n export type HasBase<T, B = unknown> = BaseCore.HasBase<T, B>;\r\n /** Extract the input */\r\n export type InputOf<T> = InputCore.InputOf<T>;\r\n /** Check whether an input exists */\r\n export type HasInput<T, I = unknown> = InputCore.HasInput<T, I>;\r\n /** Extract the trait map */\r\n export type TraitsOf<T> = TraitsCore.TraitsOf<T>;\r\n /** Extract trait keys */\r\n export type TraitKeysOf<T> = TraitsCore.TraitKeysOf<T>;\r\n /** Check if any traits exist */\r\n export type HasTraits<\r\n T,\r\n Tr extends string | symbol = string | symbol,\r\n > = TraitsCore.HasTraits<T, Tr>;\r\n /** Check whether value is branded with */\r\n export type isBrand<T, B extends Brand.Any> = BrandCore.isBrand<T, B>;\r\n /** Check whether value is branded with */\r\n export type isIdentity<T, I extends Identity.Any> = IdentityCore.isIdentity<\r\n T,\r\n I\r\n >;\r\n /** Check whether value has trait */\r\n export type HasTrait<T, Tr extends Trait.Any> = TraitCore.HasTrait<T, Tr>;\r\n /** Check whether value is transformed with */\r\n export type isTransformed<\r\n T,\r\n Tr extends Transformation.Any,\r\n > = TransformationCore.isTransformed<T, Tr>;\r\n }\r\n\r\n /** --------------------------------------\r\n * assertors\r\n * --------------------------------------- */\r\n\r\n export namespace assertors {\r\n /**\r\n * Creates a typed caster that assigns a {@link Brand} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the brand's nominal type applied. Use it for simple branded primitives\r\n * where you know the value is valid.\r\n *\r\n * @template B - The brand declaration to assign.\r\n * @returns A function that casts any value to the branded type.\r\n */\r\n export const asBrand = _asBrand;\r\n\r\n /**\r\n * Creates a typed caster that assigns an {@link Identity} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the identity's nominal type applied. Use it when you know a value\r\n * conforms to an identity but need to assert it for the type system.\r\n *\r\n * @template I - The identity declaration to assign.\r\n * @returns A function that casts any value to the assigned identity type.\r\n */\r\n export const asIdentity = _asIdentity;\r\n\r\n /**\r\n * Creates a typed caster that adds a single {@link Trait} to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to add.\r\n * @returns A function that adds the trait to any value.\r\n */\r\n export const addTrait = _addTrait;\r\n\r\n /**\r\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to add.\r\n * @returns A function that adds all traits to any value.\r\n */\r\n export const addTraits = _addTraits;\r\n\r\n /**\r\n * Creates a typed caster that removes a single {@link Trait} from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to remove.\r\n * @returns A function that drops the trait from any value.\r\n */\r\n export const dropTrait = _dropTrait;\r\n\r\n /**\r\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to remove.\r\n * @returns A function that drops all specified traits from any value.\r\n */\r\n export const dropTraits = _dropTraits;\r\n\r\n /**\r\n * Creates a typed applicator for a {@link Transformation}.\r\n *\r\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\r\n * The `input` parameter is only used for type inference — it is not used at runtime.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that applies the transformation while preserving the input type for later revert.\r\n */\r\n export const applyTransformation = _applyTransformation;\r\n\r\n /**\r\n * Creates a typed reverter for a {@link Transformation}.\r\n *\r\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\r\n * The `transformed` parameter is used for type inference of the expected input,\r\n * and `input` is the computed result that must match the stored input type.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that reverts the transformation, stripping phantom metadata.\r\n */\r\n export const revertTransformation = _revertTransformation;\r\n }\r\n\r\n /**\r\n * Creates a typed caster that assigns a {@link Brand} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the brand's nominal type applied. Use it for simple branded primitives\r\n * where you know the value is valid.\r\n *\r\n * @template B - The brand declaration to assign.\r\n * @returns A function that casts any value to the branded type.\r\n */\r\n export const asBrand = _asBrand;\r\n\r\n /**\r\n * Creates a typed caster that assigns an {@link Identity} to a value.\r\n *\r\n * This is a zero-cost runtime assertion helper — it simply returns the value\r\n * with the identity's nominal type applied. Use it when you know a value\r\n * conforms to an identity but need to assert it for the type system.\r\n *\r\n * @template I - The identity declaration to assign.\r\n * @returns A function that casts any value to the assigned identity type.\r\n */\r\n export const asIdentity = _asIdentity;\r\n\r\n /**\r\n * Creates a typed caster that adds a single {@link Trait} to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to add.\r\n * @returns A function that adds the trait to any value.\r\n */\r\n export const addTrait = _addTrait;\r\n\r\n /**\r\n * Creates a typed caster that adds multiple {@link Trait}s to a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to add.\r\n * @returns A function that adds all traits to any value.\r\n */\r\n export const addTraits = _addTraits;\r\n\r\n /**\r\n * Creates a typed caster that removes a single {@link Trait} from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The trait declaration to remove.\r\n * @returns A function that drops the trait from any value.\r\n */\r\n export const dropTrait = _dropTrait;\r\n\r\n /**\r\n * Creates a typed caster that removes multiple {@link Trait}s from a value.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - Tuple of trait declarations to remove.\r\n * @returns A function that drops all specified traits from any value.\r\n */\r\n export const dropTraits = _dropTraits;\r\n\r\n /**\r\n * Creates a typed applicator for a {@link Transformation}.\r\n *\r\n * Use this for \"forward\" operations (e.g., encrypt, encode, wrap).\r\n * The `input` parameter is only used for type inference — it is not used at runtime.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that applies the transformation while preserving the input type for later revert.\r\n */\r\n export const applyTransformation = _applyTransformation;\r\n\r\n /**\r\n * Creates a typed reverter for a {@link Transformation}.\r\n *\r\n * Use this for \"reverse\" operations (e.g., decrypt, decode, unwrap).\r\n * The `transformed` parameter is used for type inference of the expected input,\r\n * and `input` is the computed result that must match the stored input type.\r\n *\r\n * Zero-runtime-cost assertion helper.\r\n *\r\n * @template Tr - The transformation declaration.\r\n * @returns A function that reverts the transformation, stripping phantom metadata.\r\n */\r\n export const revertTransformation = _revertTransformation;\r\n\r\n /** --------------------------------------\r\n * Phantom object manipulators\r\n * --------------------------------------- */\r\n\r\n /** Get phantom metadata object from a type */\r\n export type PhantomOf<T> = PhantomCore.PhantomOf<T>;\r\n /** Stip phantom metadata object from a type */\r\n export type StripPhantom<T> = PhantomCore.StripPhantom<T>;\r\n /** run-time helper for 'StringPhantom', used for debugging mainly */\r\n export const stripPhantom = PhantomCore.stripPhantom;\r\n\r\n /** --------------------------------------\r\n * Error type\r\n * --------------------------------------- */\r\n\r\n /** Unique Error type for rules validation in phantom. */\r\n export type ErrorType<E> = _ErrorType<E>;\r\n\r\n /** --------------------------------------\r\n * Chain class\r\n * --------------------------------------- */\r\n\r\n /**\r\n * A fluent PhantomChain class for chaining Phantom assertors.\r\n *\r\n * This provides a better developer experience (DX) by allowing method chaining\r\n * with `.with(assertor)` instead of nesting function calls or using a variadic chain.\r\n * Each `.with()` applies the assertor to the current value, updating the type incrementally.\r\n * Call `.end()` to retrieve the final value.\r\n *\r\n * At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead\r\n * (just object creation and method calls).\r\n *\r\n * Example:\r\n * ```ts\r\n * const asMyBrand = Phantom.assertors.asBrand<MyBrand>();\r\n * const asMyTrait = Phantom.assertors.asTrait<MyTrait>();\r\n * const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();\r\n *\r\n * const result = new PhantomChain(\"value\")\r\n * .with(asMyBrand)\r\n * .with(asMyTrait)\r\n * .with(applyMyTransform)\r\n * .end();\r\n * ```\r\n */\r\n export class PhantomChain<T> extends _PhantomChain<T> {}\r\n}\r\n","export {\r\n assertors,\r\n addTrait,\r\n addTraits,\r\n applyTransformation,\r\n asBrand,\r\n asIdentity,\r\n dropTrait,\r\n dropTraits,\r\n revertTransformation,\r\n} from './assertors';\r\nexport { PhantomChain } from './chain';\r\nexport { Phantom } from './phantom';\r\nexport type {\r\n Base,\r\n Brand,\r\n ErrorType,\r\n Identity,\r\n Input,\r\n Inspect,\r\n Label,\r\n PhantomCore,\r\n Tag,\r\n Trait,\r\n Traits,\r\n Transformation,\r\n Variants,\r\n} from './core';\r\nimport { Phantom } from './phantom';\r\nexport default Phantom;\r\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":"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","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
|