@vicin/phantom 1.0.1
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 -0
- package/README.md +869 -0
- package/dist/assertors/assertors.d.ts +86 -0
- package/dist/assertors/assertors.d.ts.map +1 -0
- package/dist/assertors/assertors.js +91 -0
- package/dist/assertors/assertors.js.map +1 -0
- package/dist/assertors/brand.d.ts +13 -0
- package/dist/assertors/brand.d.ts.map +1 -0
- package/dist/assertors/brand.js +12 -0
- package/dist/assertors/brand.js.map +1 -0
- package/dist/assertors/identity.d.ts +13 -0
- package/dist/assertors/identity.d.ts.map +1 -0
- package/dist/assertors/identity.js +12 -0
- package/dist/assertors/identity.js.map +1 -0
- package/dist/assertors/index.d.ts +2 -0
- package/dist/assertors/index.d.ts.map +1 -0
- package/dist/assertors/index.js +2 -0
- package/dist/assertors/index.js.map +1 -0
- package/dist/assertors/trait.d.ts +38 -0
- package/dist/assertors/trait.d.ts.map +1 -0
- package/dist/assertors/trait.js +37 -0
- package/dist/assertors/trait.js.map +1 -0
- package/dist/assertors/transformation.d.ts +27 -0
- package/dist/assertors/transformation.d.ts.map +1 -0
- package/dist/assertors/transformation.js +26 -0
- package/dist/assertors/transformation.js.map +1 -0
- package/dist/chain/chain.d.ts +42 -0
- package/dist/chain/chain.d.ts.map +1 -0
- package/dist/chain/chain.js +48 -0
- package/dist/chain/chain.js.map +1 -0
- package/dist/chain/index.d.ts +2 -0
- package/dist/chain/index.d.ts.map +1 -0
- package/dist/chain/index.js +2 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/phantom.d.ts +352 -0
- package/dist/phantom.d.ts.map +1 -0
- package/dist/phantom.js +139 -0
- package/dist/phantom.js.map +1 -0
- package/dist/types/composed/brand.d.ts +32 -0
- package/dist/types/composed/brand.d.ts.map +1 -0
- package/dist/types/composed/brand.js +2 -0
- package/dist/types/composed/brand.js.map +1 -0
- package/dist/types/composed/helpers.d.ts +75 -0
- package/dist/types/composed/helpers.d.ts.map +1 -0
- package/dist/types/composed/helpers.js +2 -0
- package/dist/types/composed/helpers.js.map +1 -0
- package/dist/types/composed/identity.d.ts +37 -0
- package/dist/types/composed/identity.d.ts.map +1 -0
- package/dist/types/composed/identity.js +2 -0
- package/dist/types/composed/identity.js.map +1 -0
- package/dist/types/composed/index.d.ts +6 -0
- package/dist/types/composed/index.d.ts.map +1 -0
- package/dist/types/composed/index.js +2 -0
- package/dist/types/composed/index.js.map +1 -0
- package/dist/types/composed/trait.d.ts +35 -0
- package/dist/types/composed/trait.d.ts.map +1 -0
- package/dist/types/composed/trait.js +2 -0
- package/dist/types/composed/trait.js.map +1 -0
- package/dist/types/composed/transformation.d.ts +34 -0
- package/dist/types/composed/transformation.d.ts.map +1 -0
- package/dist/types/composed/transformation.js +2 -0
- package/dist/types/composed/transformation.js.map +1 -0
- package/dist/types/core/base.d.ts +35 -0
- package/dist/types/core/base.d.ts.map +1 -0
- package/dist/types/core/base.js +2 -0
- package/dist/types/core/base.js.map +1 -0
- package/dist/types/core/index.d.ts +8 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/index.js +2 -0
- package/dist/types/core/index.js.map +1 -0
- package/dist/types/core/input.d.ts +38 -0
- package/dist/types/core/input.d.ts.map +1 -0
- package/dist/types/core/input.js +2 -0
- package/dist/types/core/input.js.map +1 -0
- package/dist/types/core/label.d.ts +34 -0
- package/dist/types/core/label.d.ts.map +1 -0
- package/dist/types/core/label.js +2 -0
- package/dist/types/core/label.js.map +1 -0
- package/dist/types/core/phantom.d.ts +20 -0
- package/dist/types/core/phantom.d.ts.map +1 -0
- package/dist/types/core/phantom.js +11 -0
- package/dist/types/core/phantom.js.map +1 -0
- package/dist/types/core/tag.d.ts +35 -0
- package/dist/types/core/tag.d.ts.map +1 -0
- package/dist/types/core/tag.js +2 -0
- package/dist/types/core/tag.js.map +1 -0
- package/dist/types/core/traits.d.ts +51 -0
- package/dist/types/core/traits.d.ts.map +1 -0
- package/dist/types/core/traits.js +2 -0
- package/dist/types/core/traits.js.map +1 -0
- package/dist/types/core/variants.d.ts +34 -0
- package/dist/types/core/variants.d.ts.map +1 -0
- package/dist/types/core/variants.js +2 -0
- package/dist/types/core/variants.js.map +1 -0
- package/dist/types/errors.d.ts +40 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/public.d.ts +224 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/public.js +12 -0
- package/dist/types/public.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare namespace assertors {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
4
|
+
*
|
|
5
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
6
|
+
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
7
|
+
* where you know the value is valid.
|
|
8
|
+
*
|
|
9
|
+
* @template B - The brand declaration to assign.
|
|
10
|
+
* @returns A function that casts any value to the branded type.
|
|
11
|
+
*/
|
|
12
|
+
const asBrand: <B extends import("..").Brand.Any>() => <T>(value: T) => import("..").Brand.Assign<B, T>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a typed caster that assigns an {@link Identity} to a value.
|
|
15
|
+
*
|
|
16
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
17
|
+
* with the identity's nominal type applied. Use it when you know a value
|
|
18
|
+
* conforms to an identity but need to assert it for the type system.
|
|
19
|
+
*
|
|
20
|
+
* @template I - The identity declaration to assign.
|
|
21
|
+
* @returns A function that casts any value to the assigned identity type.
|
|
22
|
+
*/
|
|
23
|
+
const asIdentity: <I extends import("..").Identity.Any>() => <V>(value: V) => import("..").Identity.Assign<I, V>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
26
|
+
*
|
|
27
|
+
* Zero-runtime-cost assertion helper.
|
|
28
|
+
*
|
|
29
|
+
* @template Tr - The trait declaration to add.
|
|
30
|
+
* @returns A function that adds the trait to any value.
|
|
31
|
+
*/
|
|
32
|
+
const addTrait: <Tr extends import("..").Trait.Any>() => <V>(value: V) => import("..").Trait.Add<Tr, V>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a typed caster that adds multiple {@link Trait}s to a value.
|
|
35
|
+
*
|
|
36
|
+
* Zero-runtime-cost assertion helper.
|
|
37
|
+
*
|
|
38
|
+
* @template Tr - Tuple of trait declarations to add.
|
|
39
|
+
* @returns A function that adds all traits to any value.
|
|
40
|
+
*/
|
|
41
|
+
const addTraits: <Tr extends import("..").Trait.Any[]>() => <V>(value: V) => import("..").Trait.AddMulti<Tr, V>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a typed caster that removes a single {@link Trait} from a value.
|
|
44
|
+
*
|
|
45
|
+
* Zero-runtime-cost assertion helper.
|
|
46
|
+
*
|
|
47
|
+
* @template Tr - The trait declaration to remove.
|
|
48
|
+
* @returns A function that drops the trait from any value.
|
|
49
|
+
*/
|
|
50
|
+
const dropTrait: <Tr extends import("..").Trait.Any>() => <V>(value: V) => import("..").Trait.Drop<Tr, V>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a typed caster that removes multiple {@link Trait}s from a value.
|
|
53
|
+
*
|
|
54
|
+
* Zero-runtime-cost assertion helper.
|
|
55
|
+
*
|
|
56
|
+
* @template Tr - Tuple of trait declarations to remove.
|
|
57
|
+
* @returns A function that drops all specified traits from any value.
|
|
58
|
+
*/
|
|
59
|
+
const dropTraits: <Tr extends import("..").Trait.Any[]>() => <V>(value: V) => import("..").Trait.DropMulti<Tr, V>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a typed applicator for a {@link Transformation}.
|
|
62
|
+
*
|
|
63
|
+
* Use this for "forward" operations (e.g., encrypt, encode, wrap).
|
|
64
|
+
* The `input` parameter is only used for type inference — it is not used at runtime.
|
|
65
|
+
*
|
|
66
|
+
* Zero-runtime-cost assertion helper.
|
|
67
|
+
*
|
|
68
|
+
* @template Tr - The transformation declaration.
|
|
69
|
+
* @returns A function that applies the transformation while preserving the input type for later revert.
|
|
70
|
+
*/
|
|
71
|
+
const applyTransformation: <Tr extends import("..").Transformation.Any>() => <I, T>(input: I, transformed: T) => import("..").Transformation.Apply<Tr, I, T>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a typed reverter for a {@link Transformation}.
|
|
74
|
+
*
|
|
75
|
+
* Use this for "reverse" operations (e.g., decrypt, decode, unwrap).
|
|
76
|
+
* The `transformed` parameter is used for type inference of the expected input,
|
|
77
|
+
* and `input` is the computed result that must match the stored input type.
|
|
78
|
+
*
|
|
79
|
+
* Zero-runtime-cost assertion helper.
|
|
80
|
+
*
|
|
81
|
+
* @template Tr - The transformation declaration.
|
|
82
|
+
* @returns A function that reverts the transformation, stripping phantom metadata.
|
|
83
|
+
*/
|
|
84
|
+
const revertTransformation: <Tr extends import("..").Transformation.Any>() => <T, I>(transformed: T, input: I) => import("..").Transformation.Revert<Tr, T, I>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=assertors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertors.d.ts","sourceRoot":"","sources":["../../src/assertors/assertors.ts"],"names":[],"mappings":"AAaA,yBAAiB,SAAS,CAAC;IACzB;;;;;;;;;OASG;IACI,MAAM,OAAO,2CAPjB,CAAC,EAAE,QAAQ,oCAOiB,CAAC;IAEhC;;;;;;;;;OASG;IACI,MAAM,UAAU,8CAnBiC,CAAC,EAAG,QAAO,uCAmB9B,CAAC;IAEtC;;;;;;;OAOG;IACI,MAAM,QAAQ,4CApCa,CAAC,EAAE,QAAQ,kCAoCb,CAAC;IAEjC;;;;;;;OAOG;IACI,MAAM,SAAS,8CApCrB,CAAA,EACA,QAAI,uCAmC6B,CAAC;IAEnC;;;;;;;OAOG;IACI,MAAM,SAAS,4CApCO,CAAC,EAAE,QAAQ,mCAoCL,CAAC;IAEpC;;;;;;;OAOG;IACI,MAAM,UAAU,8CArC4C,CAAC,EACnE,QACH,wCAmCuC,CAAC;IAEtC;;;;;;;;;;OAUG;IACI,MAAM,mBAAmB,qDAxEqC,CAAC,EAAE,CAAC,EAAE,QACzE,EAAC,cAAe,gDAuEqC,CAAC;IAExD;;;;;;;;;;;OAWG;IACI,MAAM,oBAAoB,qDAtEN,CAAC,EAAE,CAAC,EAAE,cAAc,EAAC,QAC/C,iDAqEwD,CAAC;CAC3D"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { asBrand as _asBrand } from './brand';
|
|
2
|
+
import { asIdentity as _asIdentity } from './identity';
|
|
3
|
+
import { addTrait as _asTrait, addTraits as _asTraits, dropTrait as _dropTrait, dropTraits as _dropTraits, } from './trait';
|
|
4
|
+
import { applyTransformation as _applyTransformation, revertTransformation as _revertTransformation, } from './transformation';
|
|
5
|
+
export var assertors;
|
|
6
|
+
(function (assertors) {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
9
|
+
*
|
|
10
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
11
|
+
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
12
|
+
* where you know the value is valid.
|
|
13
|
+
*
|
|
14
|
+
* @template B - The brand declaration to assign.
|
|
15
|
+
* @returns A function that casts any value to the branded type.
|
|
16
|
+
*/
|
|
17
|
+
assertors.asBrand = _asBrand;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a typed caster that assigns an {@link Identity} to a value.
|
|
20
|
+
*
|
|
21
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
22
|
+
* with the identity's nominal type applied. Use it when you know a value
|
|
23
|
+
* conforms to an identity but need to assert it for the type system.
|
|
24
|
+
*
|
|
25
|
+
* @template I - The identity declaration to assign.
|
|
26
|
+
* @returns A function that casts any value to the assigned identity type.
|
|
27
|
+
*/
|
|
28
|
+
assertors.asIdentity = _asIdentity;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
31
|
+
*
|
|
32
|
+
* Zero-runtime-cost assertion helper.
|
|
33
|
+
*
|
|
34
|
+
* @template Tr - The trait declaration to add.
|
|
35
|
+
* @returns A function that adds the trait to any value.
|
|
36
|
+
*/
|
|
37
|
+
assertors.addTrait = _asTrait;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a typed caster that adds multiple {@link Trait}s to a value.
|
|
40
|
+
*
|
|
41
|
+
* Zero-runtime-cost assertion helper.
|
|
42
|
+
*
|
|
43
|
+
* @template Tr - Tuple of trait declarations to add.
|
|
44
|
+
* @returns A function that adds all traits to any value.
|
|
45
|
+
*/
|
|
46
|
+
assertors.addTraits = _asTraits;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a typed caster that removes a single {@link Trait} from a value.
|
|
49
|
+
*
|
|
50
|
+
* Zero-runtime-cost assertion helper.
|
|
51
|
+
*
|
|
52
|
+
* @template Tr - The trait declaration to remove.
|
|
53
|
+
* @returns A function that drops the trait from any value.
|
|
54
|
+
*/
|
|
55
|
+
assertors.dropTrait = _dropTrait;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a typed caster that removes multiple {@link Trait}s from a value.
|
|
58
|
+
*
|
|
59
|
+
* Zero-runtime-cost assertion helper.
|
|
60
|
+
*
|
|
61
|
+
* @template Tr - Tuple of trait declarations to remove.
|
|
62
|
+
* @returns A function that drops all specified traits from any value.
|
|
63
|
+
*/
|
|
64
|
+
assertors.dropTraits = _dropTraits;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a typed applicator for a {@link Transformation}.
|
|
67
|
+
*
|
|
68
|
+
* Use this for "forward" operations (e.g., encrypt, encode, wrap).
|
|
69
|
+
* The `input` parameter is only used for type inference — it is not used at runtime.
|
|
70
|
+
*
|
|
71
|
+
* Zero-runtime-cost assertion helper.
|
|
72
|
+
*
|
|
73
|
+
* @template Tr - The transformation declaration.
|
|
74
|
+
* @returns A function that applies the transformation while preserving the input type for later revert.
|
|
75
|
+
*/
|
|
76
|
+
assertors.applyTransformation = _applyTransformation;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a typed reverter for a {@link Transformation}.
|
|
79
|
+
*
|
|
80
|
+
* Use this for "reverse" operations (e.g., decrypt, decode, unwrap).
|
|
81
|
+
* The `transformed` parameter is used for type inference of the expected input,
|
|
82
|
+
* and `input` is the computed result that must match the stored input type.
|
|
83
|
+
*
|
|
84
|
+
* Zero-runtime-cost assertion helper.
|
|
85
|
+
*
|
|
86
|
+
* @template Tr - The transformation declaration.
|
|
87
|
+
* @returns A function that reverts the transformation, stripping phantom metadata.
|
|
88
|
+
*/
|
|
89
|
+
assertors.revertTransformation = _revertTransformation;
|
|
90
|
+
})(assertors || (assertors = {}));
|
|
91
|
+
//# sourceMappingURL=assertors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertors.js","sourceRoot":"","sources":["../../src/assertors/assertors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,QAAQ,IAAI,QAAQ,EACpB,SAAS,IAAI,SAAS,EACtB,SAAS,IAAI,UAAU,EACvB,UAAU,IAAI,WAAW,GAC1B,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,mBAAmB,IAAI,oBAAoB,EAC3C,oBAAoB,IAAI,qBAAqB,GAC9C,MAAM,kBAAkB,CAAC;AAE1B,MAAM,KAAW,SAAS,CA2FzB;AA3FD,WAAiB,SAAS;IACxB;;;;;;;;;OASG;IACU,iBAAO,GAAG,QAAQ,CAAC;IAEhC;;;;;;;;;OASG;IACU,oBAAU,GAAG,WAAW,CAAC;IAEtC;;;;;;;OAOG;IACU,kBAAQ,GAAG,QAAQ,CAAC;IAEjC;;;;;;;OAOG;IACU,mBAAS,GAAG,SAAS,CAAC;IAEnC;;;;;;;OAOG;IACU,mBAAS,GAAG,UAAU,CAAC;IAEpC;;;;;;;OAOG;IACU,oBAAU,GAAG,WAAW,CAAC;IAEtC;;;;;;;;;;OAUG;IACU,6BAAmB,GAAG,oBAAoB,CAAC;IAExD;;;;;;;;;;;OAWG;IACU,8BAAoB,GAAG,qBAAqB,CAAC;AAC5D,CAAC,EA3FgB,SAAS,KAAT,SAAS,QA2FzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Brand } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
4
|
+
*
|
|
5
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
6
|
+
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
7
|
+
* where you know the value is valid.
|
|
8
|
+
*
|
|
9
|
+
* @template B - The brand declaration to assign.
|
|
10
|
+
* @returns A function that casts any value to the branded type.
|
|
11
|
+
*/
|
|
12
|
+
export declare const asBrand: <B extends Brand.Any>() => <T>(value: T) => Brand.Assign<B, T>;
|
|
13
|
+
//# sourceMappingURL=brand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/assertors/brand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,GACjB,CAAC,SAAS,KAAK,CAAC,GAAG,QACnB,CAAC,EAAE,OAAO,CAAC,KACD,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a typed caster that assigns a {@link Brand} to a value.
|
|
3
|
+
*
|
|
4
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
5
|
+
* with the brand's nominal type applied. Use it for simple branded primitives
|
|
6
|
+
* where you know the value is valid.
|
|
7
|
+
*
|
|
8
|
+
* @template B - The brand declaration to assign.
|
|
9
|
+
* @returns A function that casts any value to the branded type.
|
|
10
|
+
*/
|
|
11
|
+
export const asBrand = () => (value) => value;
|
|
12
|
+
//# sourceMappingURL=brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/assertors/brand.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAClB,GAAwB,EAAE,CAC1B,CAAI,KAAQ,EAAE,EAAE,CACd,KAA2B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Identity } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed caster that assigns an {@link Identity} to a value.
|
|
4
|
+
*
|
|
5
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
6
|
+
* with the identity's nominal type applied. Use it when you know a value
|
|
7
|
+
* conforms to an identity but need to assert it for the type system.
|
|
8
|
+
*
|
|
9
|
+
* @template I - The identity declaration to assign.
|
|
10
|
+
* @returns A function that casts any value to the assigned identity type.
|
|
11
|
+
*/
|
|
12
|
+
export declare const asIdentity: <I extends Identity.Any>() => <V>(value: V) => Identity.Assign<I, V>;
|
|
13
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/assertors/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GACpB,CAAC,SAAS,QAAQ,CAAC,GAAG,QACtB,CAAC,EAAE,OAAO,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CACrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a typed caster that assigns an {@link Identity} to a value.
|
|
3
|
+
*
|
|
4
|
+
* This is a zero-cost runtime assertion helper — it simply returns the value
|
|
5
|
+
* with the identity's nominal type applied. Use it when you know a value
|
|
6
|
+
* conforms to an identity but need to assert it for the type system.
|
|
7
|
+
*
|
|
8
|
+
* @template I - The identity declaration to assign.
|
|
9
|
+
* @returns A function that casts any value to the assigned identity type.
|
|
10
|
+
*/
|
|
11
|
+
export const asIdentity = () => (value) => value;
|
|
12
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/assertors/identity.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,GAA2B,EAAE,CAC7B,CAAI,KAAQ,EAAyB,EAAE,CACrC,KAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assertors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/assertors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Trait } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
4
|
+
*
|
|
5
|
+
* Zero-runtime-cost assertion helper.
|
|
6
|
+
*
|
|
7
|
+
* @template Tr - The trait declaration to add.
|
|
8
|
+
* @returns A function that adds the trait to any value.
|
|
9
|
+
*/
|
|
10
|
+
export declare const addTrait: <Tr extends Trait.Any>() => <V>(value: V) => Trait.Add<Tr, V>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a typed caster that adds multiple {@link Trait}s to a value.
|
|
13
|
+
*
|
|
14
|
+
* Zero-runtime-cost assertion helper.
|
|
15
|
+
*
|
|
16
|
+
* @template Tr - Tuple of trait declarations to add.
|
|
17
|
+
* @returns A function that adds all traits to any value.
|
|
18
|
+
*/
|
|
19
|
+
export declare const addTraits: <Tr extends Trait.Any[]>() => <V>(value: V) => Trait.AddMulti<Tr, V>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a typed caster that removes a single {@link Trait} from a value.
|
|
22
|
+
*
|
|
23
|
+
* Zero-runtime-cost assertion helper.
|
|
24
|
+
*
|
|
25
|
+
* @template Tr - The trait declaration to remove.
|
|
26
|
+
* @returns A function that drops the trait from any value.
|
|
27
|
+
*/
|
|
28
|
+
export declare const dropTrait: <Tr extends Trait.Any>() => <V>(value: V) => Trait.Drop<Tr, V>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a typed caster that removes multiple {@link Trait}s from a value.
|
|
31
|
+
*
|
|
32
|
+
* Zero-runtime-cost assertion helper.
|
|
33
|
+
*
|
|
34
|
+
* @template Tr - Tuple of trait declarations to remove.
|
|
35
|
+
* @returns A function that drops all specified traits from any value.
|
|
36
|
+
*/
|
|
37
|
+
export declare const dropTraits: <Tr extends Trait.Any[]>() => <V>(value: V) => Trait.DropMulti<Tr, V>;
|
|
38
|
+
//# sourceMappingURL=trait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../../src/assertors/trait.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAClB,EAAE,SAAS,KAAK,CAAC,GAAG,QACpB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAChB,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GACnB,EAAE,SAAS,KAAK,CAAC,GAAG,EAAE,QACtB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CACrB,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GACnB,EAAE,SAAS,KAAK,CAAC,GAAG,QACpB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CACjB,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACpB,EAAE,SAAS,KAAK,CAAC,GAAG,EAAE,QACtB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CACtB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a typed caster that adds a single {@link Trait} to a value.
|
|
3
|
+
*
|
|
4
|
+
* Zero-runtime-cost assertion helper.
|
|
5
|
+
*
|
|
6
|
+
* @template Tr - The trait declaration to add.
|
|
7
|
+
* @returns A function that adds the trait to any value.
|
|
8
|
+
*/
|
|
9
|
+
export const addTrait = () => (value) => value;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a typed caster that adds multiple {@link Trait}s to a value.
|
|
12
|
+
*
|
|
13
|
+
* Zero-runtime-cost assertion helper.
|
|
14
|
+
*
|
|
15
|
+
* @template Tr - Tuple of trait declarations to add.
|
|
16
|
+
* @returns A function that adds all traits to any value.
|
|
17
|
+
*/
|
|
18
|
+
export const addTraits = () => (value) => value;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a typed caster that removes a single {@link Trait} from a value.
|
|
21
|
+
*
|
|
22
|
+
* Zero-runtime-cost assertion helper.
|
|
23
|
+
*
|
|
24
|
+
* @template Tr - The trait declaration to remove.
|
|
25
|
+
* @returns A function that drops the trait from any value.
|
|
26
|
+
*/
|
|
27
|
+
export const dropTrait = () => (value) => value;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a typed caster that removes multiple {@link Trait}s from a value.
|
|
30
|
+
*
|
|
31
|
+
* Zero-runtime-cost assertion helper.
|
|
32
|
+
*
|
|
33
|
+
* @template Tr - Tuple of trait declarations to remove.
|
|
34
|
+
* @returns A function that drops all specified traits from any value.
|
|
35
|
+
*/
|
|
36
|
+
export const dropTraits = () => (value) => value;
|
|
37
|
+
//# sourceMappingURL=trait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trait.js","sourceRoot":"","sources":["../../src/assertors/trait.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GACnB,GAAyB,EAAE,CAC3B,CAAI,KAAQ,EAAoB,EAAE,CAChC,KAAY,CAAC;AAEjB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GACpB,GAA2B,EAAE,CAC7B,CAAI,KAAQ,EAAyB,EAAE,CACrC,KAAY,CAAC;AAEjB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GACpB,GAAyB,EAAE,CAC3B,CAAI,KAAQ,EAAqB,EAAE,CACjC,KAAY,CAAC;AAEjB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,GAA2B,EAAE,CAC7B,CAAI,KAAQ,EAA0B,EAAE,CACtC,KAAY,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Transformation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed applicator for a {@link Transformation}.
|
|
4
|
+
*
|
|
5
|
+
* Use this for "forward" operations (e.g., encrypt, encode, wrap).
|
|
6
|
+
* The `input` parameter is only used for type inference — it is not used at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Zero-runtime-cost assertion helper.
|
|
9
|
+
*
|
|
10
|
+
* @template Tr - The transformation declaration.
|
|
11
|
+
* @returns A function that applies the transformation while preserving the input type for later revert.
|
|
12
|
+
*/
|
|
13
|
+
export declare const applyTransformation: <Tr extends Transformation.Any>() => <I, T>(input: I, transformed: T) => Transformation.Apply<Tr, I, T>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a typed reverter for a {@link Transformation}.
|
|
16
|
+
*
|
|
17
|
+
* Use this for "reverse" operations (e.g., decrypt, decode, unwrap).
|
|
18
|
+
* The `transformed` parameter is used for type inference of the expected input,
|
|
19
|
+
* and `input` is the computed result that must match the stored input type.
|
|
20
|
+
*
|
|
21
|
+
* Zero-runtime-cost assertion helper.
|
|
22
|
+
*
|
|
23
|
+
* @template Tr - The transformation declaration.
|
|
24
|
+
* @returns A function that reverts the transformation, stripping phantom metadata.
|
|
25
|
+
*/
|
|
26
|
+
export declare const revertTransformation: <Tr extends Transformation.Any>() => <T, I>(transformed: T, input: I) => Transformation.Revert<Tr, T, I>;
|
|
27
|
+
//# sourceMappingURL=transformation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.d.ts","sourceRoot":"","sources":["../../src/assertors/transformation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC7B,EAAE,SAAS,cAAc,CAAC,GAAG,QAC7B,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,KACd,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAC9B,EAAE,SAAS,cAAc,CAAC,GAAG,QAC7B,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,KACpB,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a typed applicator for a {@link Transformation}.
|
|
3
|
+
*
|
|
4
|
+
* Use this for "forward" operations (e.g., encrypt, encode, wrap).
|
|
5
|
+
* The `input` parameter is only used for type inference — it is not used at runtime.
|
|
6
|
+
*
|
|
7
|
+
* Zero-runtime-cost assertion helper.
|
|
8
|
+
*
|
|
9
|
+
* @template Tr - The transformation declaration.
|
|
10
|
+
* @returns A function that applies the transformation while preserving the input type for later revert.
|
|
11
|
+
*/
|
|
12
|
+
export const applyTransformation = () => (input, transformed) => transformed;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a typed reverter for a {@link Transformation}.
|
|
15
|
+
*
|
|
16
|
+
* Use this for "reverse" operations (e.g., decrypt, decode, unwrap).
|
|
17
|
+
* The `transformed` parameter is used for type inference of the expected input,
|
|
18
|
+
* and `input` is the computed result that must match the stored input type.
|
|
19
|
+
*
|
|
20
|
+
* Zero-runtime-cost assertion helper.
|
|
21
|
+
*
|
|
22
|
+
* @template Tr - The transformation declaration.
|
|
23
|
+
* @returns A function that reverts the transformation, stripping phantom metadata.
|
|
24
|
+
*/
|
|
25
|
+
export const revertTransformation = () => (transformed, input) => input;
|
|
26
|
+
//# sourceMappingURL=transformation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../src/assertors/transformation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,GAAkC,EAAE,CACpC,CAAO,KAAQ,EAAE,WAAc,EAAE,EAAE,CACjC,WAA6C,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAC/B,GAAkC,EAAE,CACpC,CAAO,WAAc,EAAE,KAAQ,EAAE,EAAE,CACjC,KAAwC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fluent PhantomChain class for chaining Phantom assertors.
|
|
3
|
+
*
|
|
4
|
+
* This provides a better developer experience (DX) by allowing method chaining
|
|
5
|
+
* with `.with(assertor)` instead of nesting function calls or using a variadic chain.
|
|
6
|
+
* Each `.with()` applies the assertor to the current value, updating the type incrementally.
|
|
7
|
+
* Call `.end()` to retrieve the final value.
|
|
8
|
+
*
|
|
9
|
+
* At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead
|
|
10
|
+
* (just object creation and method calls).
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```ts
|
|
14
|
+
* const asMyBrand = Phantom.assertors.asBrand<MyBrand>();
|
|
15
|
+
* const asMyTrait = Phantom.assertors.asTrait<MyTrait>();
|
|
16
|
+
* const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();
|
|
17
|
+
*
|
|
18
|
+
* const result = new PhantomChain("value")
|
|
19
|
+
* .with(asMyBrand)
|
|
20
|
+
* .with(asMyTrait)
|
|
21
|
+
* .with(applyMyTransform)
|
|
22
|
+
* .end();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class PhantomChain<T> {
|
|
26
|
+
private value;
|
|
27
|
+
constructor(value: T);
|
|
28
|
+
/**
|
|
29
|
+
* Apply the next assertor in the chain.
|
|
30
|
+
*
|
|
31
|
+
* @param assertor A function that takes the current value and returns the updated value (with new type).
|
|
32
|
+
* @returns A new PhantomChain instance with the updated value and type.
|
|
33
|
+
*/
|
|
34
|
+
with<U>(assertor: (value: T) => U): PhantomChain<U>;
|
|
35
|
+
/**
|
|
36
|
+
* End the chain and return the final value.
|
|
37
|
+
*
|
|
38
|
+
* @returns The value after all transformations.
|
|
39
|
+
*/
|
|
40
|
+
end(): T;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/chain/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,YAAY,CAAC,CAAC;IACzB,OAAO,CAAC,KAAK,CAAI;gBAEL,KAAK,EAAE,CAAC;IAIpB;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAInD;;;;OAIG;IACH,GAAG,IAAI,CAAC;CAGT"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fluent PhantomChain class for chaining Phantom assertors.
|
|
3
|
+
*
|
|
4
|
+
* This provides a better developer experience (DX) by allowing method chaining
|
|
5
|
+
* with `.with(assertor)` instead of nesting function calls or using a variadic chain.
|
|
6
|
+
* Each `.with()` applies the assertor to the current value, updating the type incrementally.
|
|
7
|
+
* Call `.end()` to retrieve the final value.
|
|
8
|
+
*
|
|
9
|
+
* At runtime, assertors are zero-cost casts, so the PhantomChain adds minimal overhead
|
|
10
|
+
* (just object creation and method calls).
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```ts
|
|
14
|
+
* const asMyBrand = Phantom.assertors.asBrand<MyBrand>();
|
|
15
|
+
* const asMyTrait = Phantom.assertors.asTrait<MyTrait>();
|
|
16
|
+
* const applyMyTransform = Phantom.assertors.applyTransformation<MyTransform>();
|
|
17
|
+
*
|
|
18
|
+
* const result = new PhantomChain("value")
|
|
19
|
+
* .with(asMyBrand)
|
|
20
|
+
* .with(asMyTrait)
|
|
21
|
+
* .with(applyMyTransform)
|
|
22
|
+
* .end();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class PhantomChain {
|
|
26
|
+
value;
|
|
27
|
+
constructor(value) {
|
|
28
|
+
this.value = value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Apply the next assertor in the chain.
|
|
32
|
+
*
|
|
33
|
+
* @param assertor A function that takes the current value and returns the updated value (with new type).
|
|
34
|
+
* @returns A new PhantomChain instance with the updated value and type.
|
|
35
|
+
*/
|
|
36
|
+
with(assertor) {
|
|
37
|
+
return new PhantomChain(assertor(this.value));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* End the chain and return the final value.
|
|
41
|
+
*
|
|
42
|
+
* @returns The value after all transformations.
|
|
43
|
+
*/
|
|
44
|
+
end() {
|
|
45
|
+
return this.value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/chain/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,YAAY;IACf,KAAK,CAAI;IAEjB,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAI,QAAyB;QAC/B,OAAO,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chain/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chain/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { assertors } from './assertors';
|
|
2
|
+
export { PhantomChain } from './chain';
|
|
3
|
+
export { Phantom } from './phantom';
|
|
4
|
+
export type { Base, Brand, ErrorType, Identity, Input, Inspect, Label, Phantom as PhantomCore, Tag, Trait, Traits, Transformation, Variants, } from './types';
|
|
5
|
+
import { Phantom } from './phantom';
|
|
6
|
+
export default Phantom;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,KAAK,EACL,OAAO,EACP,KAAK,EACL,OAAO,IAAI,WAAW,EACtB,GAAG,EACH,KAAK,EACL,MAAM,EACN,cAAc,EACd,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,eAAe,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,eAAe,OAAO,CAAC"}
|