@vicin/sigil 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +620 -0
- package/dist/core/classes.d.ts +48 -0
- package/dist/core/classes.d.ts.map +1 -0
- package/dist/core/classes.js +18 -0
- package/dist/core/classes.js.map +1 -0
- package/dist/core/decorator.d.ts +28 -0
- package/dist/core/decorator.d.ts.map +1 -0
- package/dist/core/decorator.js +48 -0
- package/dist/core/decorator.js.map +1 -0
- package/dist/core/enhancers.d.ts +58 -0
- package/dist/core/enhancers.d.ts.map +1 -0
- package/dist/core/enhancers.js +101 -0
- package/dist/core/enhancers.js.map +1 -0
- package/dist/core/helpers.d.ts +192 -0
- package/dist/core/helpers.d.ts.map +1 -0
- package/dist/core/helpers.js +349 -0
- package/dist/core/helpers.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/mixin.d.ts +115 -0
- package/dist/core/mixin.d.ts.map +1 -0
- package/dist/core/mixin.js +209 -0
- package/dist/core/mixin.js.map +1 -0
- package/dist/core/options.d.ts +74 -0
- package/dist/core/options.d.ts.map +1 -0
- package/dist/core/options.js +39 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/registry.d.ts +104 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +174 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/symbols.d.ts +96 -0
- package/dist/core/symbols.d.ts.map +1 -0
- package/dist/core/symbols.js +96 -0
- package/dist/core/symbols.js.map +1 -0
- package/dist/core/types.d.ts +169 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol to uniquely identify sigil classes.
|
|
3
|
+
*
|
|
4
|
+
* Uses `Symbol.for()` so the symbol is stable across multiple bundles/realms
|
|
5
|
+
* that share the same global symbol registry.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
* @constant {symbol}
|
|
9
|
+
*/
|
|
10
|
+
export declare const __SIGIL__: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Symbol to uniquely identify the base of sigil classes.
|
|
13
|
+
*
|
|
14
|
+
* When attached to a constructor it indicates that the constructor is a
|
|
15
|
+
* sigil base and should be treated specially by inheritance checks.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
* @constant {symbol}
|
|
19
|
+
*/
|
|
20
|
+
export declare const __SIGIL_BASE__: unique symbol;
|
|
21
|
+
/**
|
|
22
|
+
* Symbol to mark constructors that were explicitly decorated with `WithSigil()`.
|
|
23
|
+
*
|
|
24
|
+
* This differs from `__SIGIL__` in that `__DECORATED__` indicates explicit
|
|
25
|
+
* decoration (as opposed to automatically assigned labels).
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
* @constant {symbol}
|
|
29
|
+
*/
|
|
30
|
+
export declare const __DECORATED__: unique symbol;
|
|
31
|
+
/**
|
|
32
|
+
* Symbol to mark that inheritance checks for a given constructor have been completed.
|
|
33
|
+
*
|
|
34
|
+
* This is used to avoid repeated DEV-time validation on subsequent instance creations.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
* @constant {symbol}
|
|
38
|
+
*/
|
|
39
|
+
export declare const __INHERITANCE_CHECKED__: unique symbol;
|
|
40
|
+
/**
|
|
41
|
+
* Symbol used to store the human-readable label for a sigil constructor.
|
|
42
|
+
*
|
|
43
|
+
* Stored on the constructor as a non-enumerable property.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
* @constant {symbol}
|
|
47
|
+
*/
|
|
48
|
+
export declare const __LABEL__: unique symbol;
|
|
49
|
+
/**
|
|
50
|
+
* Symbol used to store the linearized label lineage for a sigil constructor.
|
|
51
|
+
*
|
|
52
|
+
* This is an array of labels (strings) representing the inheritance path of labels.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
* @constant {symbol}
|
|
56
|
+
*/
|
|
57
|
+
export declare const __LABEL_LINEAGE__: unique symbol;
|
|
58
|
+
/**
|
|
59
|
+
* Symbol used to store the set of labels for a sigil constructor.
|
|
60
|
+
*
|
|
61
|
+
* This is a `Set<string>` that mirrors `__LABEL_LINEAGE__` for fast membership checks.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
* @constant {symbol}
|
|
65
|
+
*/
|
|
66
|
+
export declare const __LABEL_SET__: unique symbol;
|
|
67
|
+
/**
|
|
68
|
+
* Symbol used to store the runtime type symbol for a sigil constructor.
|
|
69
|
+
*
|
|
70
|
+
* This symbol (usually created via `Symbol.for(label)`) is the canonical runtime
|
|
71
|
+
* identifier used by `isOfType` checks.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
* @constant {symbol}
|
|
75
|
+
*/
|
|
76
|
+
export declare const __TYPE__: unique symbol;
|
|
77
|
+
/**
|
|
78
|
+
* Symbol used to store the linearized sigil type symbol chain for a constructor.
|
|
79
|
+
*
|
|
80
|
+
* The value stored is an array of `symbol`s representing parent → child type symbols,
|
|
81
|
+
* useful for strict lineage comparisons.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
* @constant {symbol}
|
|
85
|
+
*/
|
|
86
|
+
export declare const __TYPE_LINEAGE__: unique symbol;
|
|
87
|
+
/**
|
|
88
|
+
* Symbol used to store the sigil type symbol set for a constructor.
|
|
89
|
+
*
|
|
90
|
+
* The value stored is a `Set<symbol>` built from `__TYPE_LINEAGE__` for O(1) membership checks.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
* @constant {symbol}
|
|
94
|
+
*/
|
|
95
|
+
export declare const __TYPE_SET__: unique symbol;
|
|
96
|
+
//# sourceMappingURL=symbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../src/core/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,eAAiC,CAAC;AAExD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,eAAsC,CAAC;AAElE;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,eAAqC,CAAC;AAEhE;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,eAEnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,eAAiC,CAAC;AAExD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,eAAyC,CAAC;AAExE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,eAAqC,CAAC;AAEhE;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,eAAgC,CAAC;AAEtD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,eAAwC,CAAC;AAEtE;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,eAAoC,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol to uniquely identify sigil classes.
|
|
3
|
+
*
|
|
4
|
+
* Uses `Symbol.for()` so the symbol is stable across multiple bundles/realms
|
|
5
|
+
* that share the same global symbol registry.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
* @constant {symbol}
|
|
9
|
+
*/
|
|
10
|
+
export const __SIGIL__ = Symbol.for('@Sigil.__SIGIL__');
|
|
11
|
+
/**
|
|
12
|
+
* Symbol to uniquely identify the base of sigil classes.
|
|
13
|
+
*
|
|
14
|
+
* When attached to a constructor it indicates that the constructor is a
|
|
15
|
+
* sigil base and should be treated specially by inheritance checks.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
* @constant {symbol}
|
|
19
|
+
*/
|
|
20
|
+
export const __SIGIL_BASE__ = Symbol.for('@Sigil.__SIGIL_BASE__');
|
|
21
|
+
/**
|
|
22
|
+
* Symbol to mark constructors that were explicitly decorated with `WithSigil()`.
|
|
23
|
+
*
|
|
24
|
+
* This differs from `__SIGIL__` in that `__DECORATED__` indicates explicit
|
|
25
|
+
* decoration (as opposed to automatically assigned labels).
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
* @constant {symbol}
|
|
29
|
+
*/
|
|
30
|
+
export const __DECORATED__ = Symbol.for('@Sigil.__DECORATED__');
|
|
31
|
+
/**
|
|
32
|
+
* Symbol to mark that inheritance checks for a given constructor have been completed.
|
|
33
|
+
*
|
|
34
|
+
* This is used to avoid repeated DEV-time validation on subsequent instance creations.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
* @constant {symbol}
|
|
38
|
+
*/
|
|
39
|
+
export const __INHERITANCE_CHECKED__ = Symbol.for('@Sigil.__INHERITANCE_CHECKED__');
|
|
40
|
+
/**
|
|
41
|
+
* Symbol used to store the human-readable label for a sigil constructor.
|
|
42
|
+
*
|
|
43
|
+
* Stored on the constructor as a non-enumerable property.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
* @constant {symbol}
|
|
47
|
+
*/
|
|
48
|
+
export const __LABEL__ = Symbol.for('@Sigil.__LABEL__');
|
|
49
|
+
/**
|
|
50
|
+
* Symbol used to store the linearized label lineage for a sigil constructor.
|
|
51
|
+
*
|
|
52
|
+
* This is an array of labels (strings) representing the inheritance path of labels.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
* @constant {symbol}
|
|
56
|
+
*/
|
|
57
|
+
export const __LABEL_LINEAGE__ = Symbol.for('@Sigil.__LABEL_LINEAGE__');
|
|
58
|
+
/**
|
|
59
|
+
* Symbol used to store the set of labels for a sigil constructor.
|
|
60
|
+
*
|
|
61
|
+
* This is a `Set<string>` that mirrors `__LABEL_LINEAGE__` for fast membership checks.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
* @constant {symbol}
|
|
65
|
+
*/
|
|
66
|
+
export const __LABEL_SET__ = Symbol.for('@Sigil.__LABEL_SET__');
|
|
67
|
+
/**
|
|
68
|
+
* Symbol used to store the runtime type symbol for a sigil constructor.
|
|
69
|
+
*
|
|
70
|
+
* This symbol (usually created via `Symbol.for(label)`) is the canonical runtime
|
|
71
|
+
* identifier used by `isOfType` checks.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
* @constant {symbol}
|
|
75
|
+
*/
|
|
76
|
+
export const __TYPE__ = Symbol.for('@Sigil.__TYPE__');
|
|
77
|
+
/**
|
|
78
|
+
* Symbol used to store the linearized sigil type symbol chain for a constructor.
|
|
79
|
+
*
|
|
80
|
+
* The value stored is an array of `symbol`s representing parent → child type symbols,
|
|
81
|
+
* useful for strict lineage comparisons.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
* @constant {symbol}
|
|
85
|
+
*/
|
|
86
|
+
export const __TYPE_LINEAGE__ = Symbol.for('@Sigil.__TYPE_LINEAGE__');
|
|
87
|
+
/**
|
|
88
|
+
* Symbol used to store the sigil type symbol set for a constructor.
|
|
89
|
+
*
|
|
90
|
+
* The value stored is a `Set<symbol>` built from `__TYPE_LINEAGE__` for O(1) membership checks.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
* @constant {symbol}
|
|
94
|
+
*/
|
|
95
|
+
export const __TYPE_SET__ = Symbol.for('@Sigil.__TYPE_SET__');
|
|
96
|
+
//# sourceMappingURL=symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/core/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAC/C,gCAAgC,CACjC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAExE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEtE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic type for class constructors used by the Sigil utilities.
|
|
3
|
+
*
|
|
4
|
+
* - `T` is the instance type produced by the constructor.
|
|
5
|
+
* - `P` is the tuple of parameter types accepted by the constructor.
|
|
6
|
+
*
|
|
7
|
+
* @template T - Instance type produced by the constructor (defaults to `object`).
|
|
8
|
+
* @template P - Parameter tuple type for the constructor.
|
|
9
|
+
*/
|
|
10
|
+
export type Constructor<T = object, P extends any[] = any[]> = new (...args: P) => T;
|
|
11
|
+
/**
|
|
12
|
+
* Static-side interface describing methods and properties added to a class
|
|
13
|
+
* constructor when it is sigilized.
|
|
14
|
+
*
|
|
15
|
+
* The properties and methods described here mirror the getters and static
|
|
16
|
+
* predicates implemented by the `Sigilify` mixin.
|
|
17
|
+
*
|
|
18
|
+
* @template L - Narrow string literal type representing the label.
|
|
19
|
+
* @template US - Optinal original Untyped Sigil constructor type being augmented.
|
|
20
|
+
*/
|
|
21
|
+
export interface ISigilStatic<L extends string = string, US extends Function = never> {
|
|
22
|
+
/**
|
|
23
|
+
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
24
|
+
*
|
|
25
|
+
* - Provides a *type-only* unique marker that makes instances nominally
|
|
26
|
+
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
27
|
+
* - Runtime: **no runtime value is required**; this property exists only for the type system.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Consumers should not read or set this property at runtime. It is used by helper
|
|
31
|
+
* types (e.g. `SigilBrandOf`, `TypedSigil`) to extract/propagate compile-time brands.
|
|
32
|
+
*/
|
|
33
|
+
readonly __SIGIL_BRAND__: Prettify<{
|
|
34
|
+
[k in L]: true;
|
|
35
|
+
} & SigilBrandOf<US>>;
|
|
36
|
+
/** Class-level label constant (human readable). */
|
|
37
|
+
readonly SigilLabel: string;
|
|
38
|
+
/** Class-level unique symbol used as the runtime type identifier. */
|
|
39
|
+
readonly SigilType: symbol;
|
|
40
|
+
/**
|
|
41
|
+
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
42
|
+
* Useful for debugging and strict lineage comparisons.
|
|
43
|
+
*/
|
|
44
|
+
readonly SigilTypeLineage: readonly symbol[];
|
|
45
|
+
/**
|
|
46
|
+
* Copy of the sigil type symbol set for the current constructor. Useful for
|
|
47
|
+
* O(1) membership checks and debugging.
|
|
48
|
+
*/
|
|
49
|
+
readonly SigilTypeSet: Readonly<Set<symbol>>;
|
|
50
|
+
/**
|
|
51
|
+
* Runtime check that determines whether `obj` is an instance produced by a
|
|
52
|
+
* sigil class.
|
|
53
|
+
*
|
|
54
|
+
* Note: the concrete implementation provided by the mixin delegates to
|
|
55
|
+
* `isSigilInstance`.
|
|
56
|
+
*
|
|
57
|
+
* @param obj - Value to test.
|
|
58
|
+
* @returns Type guard narrowing `obj` to `ISigil`.
|
|
59
|
+
*/
|
|
60
|
+
isSigilified(obj: unknown): obj is ISigil;
|
|
61
|
+
/**
|
|
62
|
+
* Check whether `other` is (or inherits from) the type represented by the
|
|
63
|
+
* calling constructor. Uses the other instance's `SigilTypeSet` to check
|
|
64
|
+
* membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
65
|
+
*
|
|
66
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
67
|
+
* and when subclassing.
|
|
68
|
+
*
|
|
69
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
70
|
+
* @param this - The constructor performing the type check.
|
|
71
|
+
* @param other - The object to test.
|
|
72
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
73
|
+
*/
|
|
74
|
+
isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Strict lineage comparison: verifies that the calling constructor's type
|
|
77
|
+
* lineage (by symbol) matches the `other`'s lineage element-by-element.
|
|
78
|
+
*
|
|
79
|
+
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
80
|
+
* and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
81
|
+
*
|
|
82
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
83
|
+
* @param this - The constructor performing the strict check.
|
|
84
|
+
* @param other - The object to test.
|
|
85
|
+
* @returns A type guard asserting `other` is an instance whose lineage matches exactly.
|
|
86
|
+
*/
|
|
87
|
+
isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Instance-side interface describing properties present on sigil instances.
|
|
91
|
+
* The methods mirror the instance helpers injected by the mixin.
|
|
92
|
+
*
|
|
93
|
+
* @template L - Narrow string literal type for the label returned by `getSigilLabel`.
|
|
94
|
+
* @template US - Optinal original Untyped Sigil constructor type being augmented.
|
|
95
|
+
*/
|
|
96
|
+
export interface ISigilInstance<L extends string = string, US extends Function = never> {
|
|
97
|
+
/**
|
|
98
|
+
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
99
|
+
*
|
|
100
|
+
* - Provides a *type-only* unique marker that makes instances nominally
|
|
101
|
+
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
102
|
+
* - Runtime: **no runtime value is required**; this property exists only for the type system.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* Consumers should not read or set this property at runtime. It is used by helper
|
|
106
|
+
* types (e.g. `SigilBrandOf`, `TypedSigil`) to extract/propagate compile-time brands.
|
|
107
|
+
*/
|
|
108
|
+
readonly __SIGIL_BRAND__: Prettify<{
|
|
109
|
+
[k in L]: true;
|
|
110
|
+
} & SigilBrandOf<US>>;
|
|
111
|
+
/** Returns human-readable sigil label of the class constructor. */
|
|
112
|
+
getSigilLabel(): string;
|
|
113
|
+
/** Returns runtime sigil type symbol of the class constructor. */
|
|
114
|
+
getSigilType(): symbol;
|
|
115
|
+
/** Returns copy of sigil type symbol lineage of the class constructor. */
|
|
116
|
+
getSigilTypeLineage(): readonly symbol[];
|
|
117
|
+
/** Returns copy of sigil type symbol set of the class constructor. */
|
|
118
|
+
getSigilTypeSet(): Readonly<Set<symbol>>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Combined constructor + static interface for a sigil class.
|
|
122
|
+
*
|
|
123
|
+
* This composes the instance-side shape (Constructor<ISigilInstance<L>>) with
|
|
124
|
+
* the static-side interface (ISigilStatic<L>), matching the runtime shape added
|
|
125
|
+
* by `Sigilify`.
|
|
126
|
+
*
|
|
127
|
+
* @template L - Narrow string literal type for the label.
|
|
128
|
+
* @template US - Optinal original Untyped Sigil constructor type being augmented.
|
|
129
|
+
*/
|
|
130
|
+
export type ISigil<L extends string = string, US extends Function = never> = Constructor<ISigilInstance<L, US>> & ISigilStatic<L, US>;
|
|
131
|
+
/**
|
|
132
|
+
* Extract the compile-time brand map from a sigil constructor `S`.
|
|
133
|
+
*
|
|
134
|
+
* @typeParam S - A sigil constructor type (e.g. `typeof SomeSigilClass`).
|
|
135
|
+
* @returns The brand record carried on the constructor's instance type (e.g. `{ User: true, Admin: true }`).
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* - This helper is used purely at the type level to compute the set of brand keys
|
|
139
|
+
* that should be propagated to derived sigils.
|
|
140
|
+
* - If `S` does not carry a `__SIGIL_BRAND__`, the resulting type is `never` and `IfNever<>`
|
|
141
|
+
* collapses it to an empty record.
|
|
142
|
+
*/
|
|
143
|
+
export type SigilBrandOf<S> = IfNever<S extends {
|
|
144
|
+
readonly __SIGIL_BRAND__: infer Brand;
|
|
145
|
+
} ? Prettify<Brand> : never, Record<string, true>>;
|
|
146
|
+
/**
|
|
147
|
+
* Combine an existing sigil constructor type `S` with a **new** label `L`,
|
|
148
|
+
* while inheriting/propagating compile-time brands from an optional parent sigil `P`.
|
|
149
|
+
*
|
|
150
|
+
* @template US - The original Untyped Sigil constructor type being augmented.
|
|
151
|
+
* @template L - The new label literal to associate with the resulting constructor.
|
|
152
|
+
*/
|
|
153
|
+
export type TypedSigil<US extends Function, L extends string = string> = US & ISigil<L, US>;
|
|
154
|
+
/**
|
|
155
|
+
* Generic helper extract instance of the class even in protected and private constructors.
|
|
156
|
+
*/
|
|
157
|
+
export type GetInstance<T> = T extends {
|
|
158
|
+
prototype: infer R;
|
|
159
|
+
} ? Prettify<R & {
|
|
160
|
+
__SIGIL_BRAND__: SigilBrandOf<T>;
|
|
161
|
+
}> : never;
|
|
162
|
+
/** Helper type to prettify value. */
|
|
163
|
+
type Prettify<T> = {
|
|
164
|
+
[K in keyof T]: T[K];
|
|
165
|
+
} & {};
|
|
166
|
+
/** Helper type to replace 'never' with another type */
|
|
167
|
+
type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
168
|
+
export {};
|
|
169
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vicin/sigil",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight TypeScript library for nominal identity classes",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"lint": "eslint --fix",
|
|
13
|
+
"format": "prettier --write",
|
|
14
|
+
"test": "jest tests && tsd",
|
|
15
|
+
"test:unit": "jest tests/unit --coverage",
|
|
16
|
+
"test:unit:sigil": "jest tests/unit/sigil.test.ts",
|
|
17
|
+
"test:unit:registry": "jest tests/unit/registry.test.ts",
|
|
18
|
+
"test:performance": "jest tests/performance",
|
|
19
|
+
"test:performance:creation": "jest tests/performance/creation.test.ts",
|
|
20
|
+
"test:performance:instanceof": "jest tests/performance/instanceof.test.ts",
|
|
21
|
+
"test:types": "tsd",
|
|
22
|
+
"prepublishOnly": "npm run build && npm run test:unit && npm run test:types"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"tsd": {
|
|
29
|
+
"directory": "tests/types",
|
|
30
|
+
"compilerOptions": {
|
|
31
|
+
"strict": true,
|
|
32
|
+
"esModuleInterop": true,
|
|
33
|
+
"moduleResolution": "node"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"typescript",
|
|
38
|
+
"nominal-typing",
|
|
39
|
+
"ddd"
|
|
40
|
+
],
|
|
41
|
+
"author": "Ziad ziadtaha62@gmail.com",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/jest": "^30.0.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
46
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
47
|
+
"eslint": "^9.39.2",
|
|
48
|
+
"eslint-config-prettier": "^10.1.8",
|
|
49
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
50
|
+
"globals": "^17.3.0",
|
|
51
|
+
"jest": "^30.2.0",
|
|
52
|
+
"prettier": "^3.8.1",
|
|
53
|
+
"ts-jest": "^29.4.6",
|
|
54
|
+
"tsd": "^0.33.0",
|
|
55
|
+
"typescript": "^5.9.3"
|
|
56
|
+
}
|
|
57
|
+
}
|