@vicin/sigil 2.2.1 → 3.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/CHANGELOG.md +31 -0
- package/README.md +110 -187
- package/dist/index.d.mts +170 -327
- package/dist/index.d.ts +170 -327
- package/dist/index.global.js +245 -2094
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +248 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +249 -377
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** -----------------------------------------
|
|
2
|
+
* Nominal identity symbol
|
|
3
|
+
* ----------------------------------------- */
|
|
4
|
+
/**
|
|
5
|
+
* Symbol used for nominal typing
|
|
6
|
+
*/
|
|
7
|
+
declare const sigil: unique symbol;
|
|
1
8
|
/** -----------------------------------------
|
|
2
9
|
* Class and instance
|
|
3
10
|
* ----------------------------------------- */
|
|
@@ -9,48 +16,34 @@
|
|
|
9
16
|
* predicates implemented by the `Sigilify` mixin.
|
|
10
17
|
*
|
|
11
18
|
* @template L - Narrow string literal type representing the label.
|
|
12
|
-
* @template P - Optinal parent to extend its '
|
|
19
|
+
* @template P - Optinal parent to extend its '[sigil]'.
|
|
13
20
|
*/
|
|
14
|
-
interface ISigilStatic<L extends string = string
|
|
15
|
-
/**
|
|
16
|
-
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
17
|
-
*
|
|
18
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
19
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
20
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
21
|
-
*/
|
|
22
|
-
readonly __SIGIL_BRAND__: Prettify<{
|
|
23
|
-
[k in L]: true;
|
|
24
|
-
} & SigilBrandOf<P>>;
|
|
21
|
+
interface ISigilStatic<L extends string = string> {
|
|
25
22
|
/** Class-level label constant (identity). */
|
|
26
|
-
readonly SigilLabel:
|
|
23
|
+
readonly SigilLabel: L;
|
|
27
24
|
/** Class-level label constant (human readable). */
|
|
28
|
-
readonly SigilEffectiveLabel:
|
|
25
|
+
readonly SigilEffectiveLabel: L;
|
|
29
26
|
/**
|
|
30
27
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
31
|
-
* Useful for debugging
|
|
28
|
+
* Useful for debugging.
|
|
32
29
|
*/
|
|
33
30
|
readonly SigilLabelLineage: readonly string[];
|
|
34
31
|
/**
|
|
35
|
-
* Copy of the sigil type label set for the current constructor.
|
|
36
|
-
*
|
|
32
|
+
* Copy of the sigil type label set for the current constructor.
|
|
33
|
+
* Useful for debugging.
|
|
37
34
|
*/
|
|
38
35
|
readonly SigilLabelSet: Readonly<Set<string>>;
|
|
39
36
|
/**
|
|
40
37
|
* Runtime check that determines whether `obj` is an instance produced by a
|
|
41
38
|
* sigil class.
|
|
42
39
|
*
|
|
43
|
-
* Note: the concrete implementation provided by the mixin delegates to
|
|
44
|
-
* `isSigilInstance`.
|
|
45
|
-
*
|
|
46
40
|
* @param obj - Value to test.
|
|
47
|
-
* @returns Type guard narrowing `obj` to `
|
|
41
|
+
* @returns Type guard narrowing `obj` to `ISigilInstance`.
|
|
48
42
|
*/
|
|
49
|
-
isSigilified(obj: unknown): obj is
|
|
43
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
50
44
|
/**
|
|
51
|
-
* Check whether `other` is (or inherits from) the
|
|
52
|
-
* calling constructor.
|
|
53
|
-
* membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
45
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
46
|
+
* calling constructor.
|
|
54
47
|
*
|
|
55
48
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
56
49
|
* and when subclassing.
|
|
@@ -60,39 +53,32 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
|
|
|
60
53
|
* @param other - The object to test.
|
|
61
54
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
62
55
|
*/
|
|
63
|
-
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is
|
|
56
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
64
57
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
69
|
-
* and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
58
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
59
|
+
* calling constructor.
|
|
70
60
|
*
|
|
71
61
|
* @typeParam T - The specific sigil constructor (`this`).
|
|
72
|
-
* @param this - The constructor performing the
|
|
62
|
+
* @param this - The constructor performing the type check.
|
|
73
63
|
* @param other - The object to test.
|
|
74
|
-
* @returns A type guard asserting `other` is an instance
|
|
64
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
75
65
|
*/
|
|
76
|
-
|
|
66
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
77
67
|
}
|
|
78
68
|
/**
|
|
79
69
|
* Instance-side interface describing properties present on sigil instances.
|
|
80
70
|
* The methods mirror the instance helpers injected by the mixin.
|
|
81
71
|
*
|
|
82
72
|
* @template L - Narrow string literal type for the label returned by `getSigilLabel`.
|
|
83
|
-
* @template P - Optinal parent to extend its '
|
|
73
|
+
* @template P - Optinal parent to extend its '[sigil]'.
|
|
84
74
|
*/
|
|
85
75
|
interface ISigilInstance<L extends string = string, P extends Function = never> {
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
91
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
92
|
-
*/
|
|
93
|
-
readonly __SIGIL_BRAND__: Prettify<{
|
|
76
|
+
/** Compile-time nominal brand that encodes the class label `L` plus parent's sigil labels `SigilOf<P>`. */
|
|
77
|
+
readonly [sigil]: Prettify<{
|
|
78
|
+
Sigil: true;
|
|
79
|
+
} & IfNever<SigilOf<P>, {}> & {
|
|
94
80
|
[k in L]: true;
|
|
95
|
-
}
|
|
81
|
+
}>;
|
|
96
82
|
/** Returns identity sigil label of the class constructor. */
|
|
97
83
|
getSigilLabel(): string;
|
|
98
84
|
/** Returns human-readable sigil label of the class constructor. */
|
|
@@ -102,9 +88,8 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
102
88
|
/** Returns copy of sigil type label set of the class constructor. */
|
|
103
89
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
104
90
|
/**
|
|
105
|
-
* Check whether `other` is (or inherits from) the
|
|
106
|
-
* calling constructor.
|
|
107
|
-
* membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
91
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
92
|
+
* calling constructor.
|
|
108
93
|
*
|
|
109
94
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
110
95
|
* and when subclassing.
|
|
@@ -114,79 +99,41 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
114
99
|
* @param other - The object to test.
|
|
115
100
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
116
101
|
*/
|
|
117
|
-
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is
|
|
102
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
118
103
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
123
|
-
* and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
104
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
105
|
+
* calling constructor.
|
|
124
106
|
*
|
|
125
107
|
* @typeParam T - The specific sigil constructor (`this`).
|
|
126
|
-
* @param this - The constructor performing the
|
|
108
|
+
* @param this - The constructor performing the type check.
|
|
127
109
|
* @param other - The object to test.
|
|
128
|
-
* @returns A type guard asserting `other` is an instance
|
|
110
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
129
111
|
*/
|
|
130
|
-
|
|
112
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
131
113
|
}
|
|
132
114
|
/**
|
|
133
115
|
* Combined constructor + static interface for a sigil class.
|
|
134
116
|
*
|
|
135
117
|
* @template L - Narrow string literal type for the label.
|
|
136
|
-
* @template P - Optinal parent to extend its '
|
|
118
|
+
* @template P - Optinal parent to extend its '[sigil]'.
|
|
137
119
|
*/
|
|
138
|
-
type ISigil<L extends string = string, P extends Function = never> = ConstructorAbstract<ISigilInstance<L, P>> & ISigilStatic<L
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
120
|
+
type ISigil<L extends string = string, P extends Function = never> = ConstructorAbstract<ISigilInstance<L, P>> & ISigilStatic<L>;
|
|
121
|
+
/** Update '[sigil]' field for nominal typing */
|
|
122
|
+
type ExtendSigil<L extends string, P extends ISigilInstance> = Prettify<IfNever<SigilOf<P>, {}> & {
|
|
123
|
+
[K in L]: true;
|
|
124
|
+
}>;
|
|
142
125
|
/**
|
|
143
|
-
*
|
|
144
|
-
* while inheriting/propagating compile-time brands from an optional parent sigil `P`.
|
|
126
|
+
* Extract the compile-time label map from a sigil instance `S`.
|
|
145
127
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @
|
|
128
|
+
* @typeParam S - A sigil instance type.
|
|
129
|
+
* @returns The sigil label record (e.g. `{ User: true, Admin: true }`) or never if not Sigil class instance.
|
|
148
130
|
*/
|
|
149
|
-
type
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
* @remark Return same type is passed type has no 'prototype'
|
|
153
|
-
*/
|
|
154
|
-
type GetInstance<T> = T extends {
|
|
155
|
-
prototype: infer R;
|
|
156
|
-
} ? PrettifyBrand<R & {
|
|
157
|
-
__SIGIL_BRAND__: SigilBrandOf<T>;
|
|
158
|
-
}> : T;
|
|
159
|
-
/** Helper to append label into a class. */
|
|
160
|
-
type AppendLabel<L extends string> = {
|
|
161
|
-
readonly __SIGIL_BRAND__: Prettify<{
|
|
162
|
-
[K in L]: true;
|
|
163
|
-
}>;
|
|
164
|
-
};
|
|
165
|
-
/** -----------------------------------------
|
|
166
|
-
* Manual pattern types
|
|
167
|
-
* ----------------------------------------- */
|
|
168
|
-
/** Update '__SIGIL_BRAND__' field when manual typing is used. */
|
|
169
|
-
type UpdateSigilBrand<L extends string, P extends ISigilInstance> = Prettify<SigilBrandOf<P> & {
|
|
170
|
-
[K in L]: true;
|
|
171
|
-
}>;
|
|
131
|
+
type SigilOf<S> = S extends {
|
|
132
|
+
readonly [sigil]: infer Sigil;
|
|
133
|
+
} ? Sigil : never;
|
|
172
134
|
/** -----------------------------------------
|
|
173
135
|
* Generic types
|
|
174
136
|
* ----------------------------------------- */
|
|
175
|
-
/**
|
|
176
|
-
* Extract the compile-time brand map from a sigil constructor `S`.
|
|
177
|
-
*
|
|
178
|
-
* @typeParam S - A sigil constructor type (e.g. `typeof SomeSigilClass`).
|
|
179
|
-
* @returns The brand record carried on the constructor's instance type (e.g. `{ User: true, Admin: true }`).
|
|
180
|
-
*
|
|
181
|
-
* @remarks
|
|
182
|
-
* - This helper is used purely at the type level to compute the set of brand keys
|
|
183
|
-
* that should be propagated to derived sigils.
|
|
184
|
-
* - If `S` does not carry a `__SIGIL_BRAND__`, the resulting type is `never` and `IfNever<>`
|
|
185
|
-
* collapses it to an empty record.
|
|
186
|
-
*/
|
|
187
|
-
type SigilBrandOf<S> = IfNever<S extends {
|
|
188
|
-
readonly __SIGIL_BRAND__: infer Brand;
|
|
189
|
-
} ? Brand : never, Record<string, true>>;
|
|
190
137
|
/**
|
|
191
138
|
* Generic type for class constructors used by the Sigil utilities.
|
|
192
139
|
*
|
|
@@ -211,12 +158,12 @@ type ConstructorAbstract<T = object, P extends any[] = any[]> = abstract new (..
|
|
|
211
158
|
type Prettify<T> = {
|
|
212
159
|
[K in keyof T]: T[K];
|
|
213
160
|
} & {};
|
|
214
|
-
/** Helper type to prettify value, handles nested '__SIGIL_BRAND__' field */
|
|
215
|
-
type PrettifyBrand<T> = {
|
|
216
|
-
[K in keyof T]: K extends '__SIGIL_BRAND__' ? PrettifyBrand<T[K]> : T[K];
|
|
217
|
-
} & {};
|
|
218
161
|
/** Helper type to replace 'never' with another type */
|
|
219
162
|
type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
163
|
+
/** Helper type to get prototype of class */
|
|
164
|
+
type GetPrototype<T> = T extends {
|
|
165
|
+
prototype: infer P;
|
|
166
|
+
} ? P : never;
|
|
220
167
|
|
|
221
168
|
/**
|
|
222
169
|
* A minimal root Sigil class used by the library as a base identity.
|
|
@@ -226,30 +173,27 @@ type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
|
226
173
|
*/
|
|
227
174
|
declare const Sigil: {
|
|
228
175
|
new (...args: any[]): {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
232
|
-
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
233
|
-
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
176
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
177
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
234
178
|
getSigilLabel(): string;
|
|
235
179
|
getSigilEffectiveLabel(): string;
|
|
236
180
|
getSigilLabelLineage(): readonly string[];
|
|
237
181
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
182
|
+
readonly [sigil]: {
|
|
183
|
+
Sigil: true;
|
|
184
|
+
};
|
|
238
185
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
242
|
-
get SigilLabel(): string;
|
|
243
|
-
get SigilEffectiveLabel(): string;
|
|
186
|
+
get SigilLabel(): "Sigil";
|
|
187
|
+
get SigilEffectiveLabel(): "Sigil";
|
|
244
188
|
get SigilLabelLineage(): readonly string[];
|
|
245
189
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
246
|
-
isSigilified(obj: unknown): obj is
|
|
247
|
-
isOfType<T>(this: T, other: unknown): other is
|
|
248
|
-
|
|
190
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
191
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
192
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
249
193
|
} & {
|
|
250
194
|
new (): {};
|
|
251
195
|
};
|
|
252
|
-
type Sigil =
|
|
196
|
+
type Sigil = InstanceType<typeof Sigil>;
|
|
253
197
|
/**
|
|
254
198
|
* A sigil variant of the built-in `Error` constructor used by the library
|
|
255
199
|
* to represent Sigil-specific errors.
|
|
@@ -259,30 +203,26 @@ type Sigil = GetInstance<typeof Sigil>;
|
|
|
259
203
|
*/
|
|
260
204
|
declare const SigilError: {
|
|
261
205
|
new (...args: any[]): {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
SigilError: true;
|
|
265
|
-
};
|
|
266
|
-
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
267
|
-
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
206
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
207
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
268
208
|
getSigilLabel(): string;
|
|
269
209
|
getSigilEffectiveLabel(): string;
|
|
270
210
|
getSigilLabelLineage(): readonly string[];
|
|
271
211
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
212
|
+
readonly [sigil]: {
|
|
213
|
+
Sigil: true;
|
|
214
|
+
SigilError: true;
|
|
215
|
+
};
|
|
272
216
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
SigilError: true;
|
|
276
|
-
};
|
|
277
|
-
get SigilLabel(): string;
|
|
278
|
-
get SigilEffectiveLabel(): string;
|
|
217
|
+
get SigilLabel(): "SigilError";
|
|
218
|
+
get SigilEffectiveLabel(): "SigilError";
|
|
279
219
|
get SigilLabelLineage(): readonly string[];
|
|
280
220
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
281
|
-
isSigilified(obj: unknown): obj is
|
|
282
|
-
isOfType<T>(this: T, other: unknown): other is
|
|
283
|
-
|
|
221
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
222
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
223
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
284
224
|
} & ErrorConstructor;
|
|
285
|
-
type SigilError =
|
|
225
|
+
type SigilError = InstanceType<typeof SigilError>;
|
|
286
226
|
|
|
287
227
|
/**
|
|
288
228
|
* Configuration options for the Sigil library.
|
|
@@ -300,24 +240,6 @@ interface SigilOptions {
|
|
|
300
240
|
* Defaults to `null`.
|
|
301
241
|
*/
|
|
302
242
|
labelValidation?: ((label: string) => boolean) | RegExp | null;
|
|
303
|
-
/**
|
|
304
|
-
* Skips the runtime check that prevents subclasses from inheriting
|
|
305
|
-
* the same sigil label as their ancestors.
|
|
306
|
-
*
|
|
307
|
-
* When `false` (default), extending a sigil class without
|
|
308
|
-
* using `WithSigil(newLabel)` decorator will throw an error if the label
|
|
309
|
-
* is reused and `OPTIONS.autofillLabels` is set to `false`.
|
|
310
|
-
*
|
|
311
|
-
* Set this to `true` only if you intentionally want subclasses to inherit labels
|
|
312
|
-
* from their ancestors (this weakens the uniqueness guarantees).
|
|
313
|
-
*
|
|
314
|
-
* WARNING:
|
|
315
|
-
* Disabling inheritanceCheck removes guaranties by 'Sigil' or unique label for
|
|
316
|
-
* each class and allow multiple child classes to use the same label which can
|
|
317
|
-
* result on false 'isOfType' result. this options should be used in debugging
|
|
318
|
-
* only to silence all errors but never in production.
|
|
319
|
-
*/
|
|
320
|
-
skipLabelInheritanceCheck?: boolean;
|
|
321
243
|
/**
|
|
322
244
|
* When enabled, non-decorated subclasses that would otherwise inherit an ancestor's label
|
|
323
245
|
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
@@ -346,44 +268,27 @@ declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
|
346
268
|
/**
|
|
347
269
|
* Class decorator factory that attaches sigil statics to a class constructor.
|
|
348
270
|
*
|
|
349
|
-
*
|
|
350
|
-
* - This decorator is intended to be applied to classes only. When used
|
|
351
|
-
* incorrectly (e.g. on a property), it is a no-op.
|
|
352
|
-
* - Throws an error during class creation if the label validation fails (in development only).
|
|
353
|
-
*
|
|
354
|
-
* @typeParam L - Narrow string literal type for the provided label.
|
|
355
|
-
* @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
356
|
-
* If not passed a random label is generated instead.
|
|
271
|
+
* @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
357
272
|
* @param opts - Options object to override any global options if needed.
|
|
358
273
|
* @returns A class decorator compatible with the ECMAScript decorator context.
|
|
359
274
|
*/
|
|
360
|
-
declare function WithSigil
|
|
275
|
+
declare function WithSigil(label: string, opts?: SigilOptions): (value: Function, context: any) => void;
|
|
361
276
|
|
|
362
277
|
/**
|
|
363
278
|
* HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
|
|
364
279
|
* Alternative to '@WithSigil' if you prefer HOFs.
|
|
365
280
|
*
|
|
366
|
-
* @typeParam S - Constructor type (should be an
|
|
367
|
-
* @typeParam L - Label literal to attach.
|
|
281
|
+
* @typeParam S - Constructor type (should be an instance of sigil class).
|
|
368
282
|
* @param Class - The constructor (class) to enhance.
|
|
369
|
-
* @param label -
|
|
283
|
+
* @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
370
284
|
* @param opts - Options object to override any global options if needed.
|
|
371
285
|
* @returns The same constructor value, with runtime metadata ensured.
|
|
372
286
|
*/
|
|
373
|
-
declare function withSigil<S extends Function
|
|
374
|
-
/**
|
|
375
|
-
* Convenience helper that combine 'withSigil' and update 'SigilBrand'.
|
|
376
|
-
*
|
|
377
|
-
* @typeParam S - Constructor type (should be an ISigil).
|
|
378
|
-
* @typeParam L - Label literal to attach.
|
|
379
|
-
* @param Class - The constructor (class) to decorate and type.
|
|
380
|
-
* @param label - Optional label string. If omitted, a random label is generated.
|
|
381
|
-
* @param parent - Optional parent sigil constructor (type-only).
|
|
382
|
-
* @param opts - Options object to override any global options if needed.
|
|
383
|
-
* @returns The same constructor value, with runtime metadata ensured and typed as `TypedSigil<S,L,P>`.
|
|
384
|
-
*/
|
|
385
|
-
declare function withSigilTyped<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): TypedSigil<S, L>;
|
|
287
|
+
declare function withSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S;
|
|
386
288
|
|
|
289
|
+
/** -----------------------------------------
|
|
290
|
+
* Introspection helpers
|
|
291
|
+
* ----------------------------------------- */
|
|
387
292
|
/**
|
|
388
293
|
* Runtime predicate that checks whether the provided value is a sigil constructor.
|
|
389
294
|
*
|
|
@@ -398,37 +303,7 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
|
|
|
398
303
|
* @param inst - The instanca to test.
|
|
399
304
|
* @returns `true` if `obj` is an instance produced by a sigil constructor.
|
|
400
305
|
*/
|
|
401
|
-
declare function isSigilInstance(inst: unknown): inst is
|
|
402
|
-
/**
|
|
403
|
-
* Check whether the provided constructor was marked as a sigil base constructor.
|
|
404
|
-
*
|
|
405
|
-
* @param ctor - Constructor to check.
|
|
406
|
-
* @returns `true` if `ctor` is a sigil base constructor.
|
|
407
|
-
*/
|
|
408
|
-
declare function isSigilBaseCtor(ctor: Function): ctor is ISigil;
|
|
409
|
-
/**
|
|
410
|
-
* Check whether the provided object is an instance of a sigil base constructor.
|
|
411
|
-
*
|
|
412
|
-
* @param inst - The instance to test.
|
|
413
|
-
* @returns `true` if `inst` is an instance of a sigil base constructor.
|
|
414
|
-
*/
|
|
415
|
-
declare function isSigilBaseInstance(inst: unknown): inst is GetInstance<ISigil>;
|
|
416
|
-
/**
|
|
417
|
-
* Returns whether the constructor has been explicitly decorated with `WithSigil`.
|
|
418
|
-
*
|
|
419
|
-
* @internal
|
|
420
|
-
* @param ctor - Constructor to test.
|
|
421
|
-
* @returns `true` if the constructor is explicitly decorated.
|
|
422
|
-
*/
|
|
423
|
-
declare function isDecorated(ctor: Function): boolean;
|
|
424
|
-
/**
|
|
425
|
-
* Returns whether inheritance checks have already been performed for the constructor.
|
|
426
|
-
*
|
|
427
|
-
* @internal
|
|
428
|
-
* @param ctor - Constructor to test.
|
|
429
|
-
* @returns `true` if inheritance checks were marked as completed.
|
|
430
|
-
*/
|
|
431
|
-
declare function isInheritanceChecked(ctor: Function): boolean;
|
|
306
|
+
declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
432
307
|
|
|
433
308
|
/**
|
|
434
309
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
@@ -437,53 +312,44 @@ declare function isInheritanceChecked(ctor: Function): boolean;
|
|
|
437
312
|
* @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
438
313
|
* If not passed a random label is generated instead.
|
|
439
314
|
* @param opts - Options object to override any global options if needed.
|
|
440
|
-
* @returns A new
|
|
315
|
+
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
441
316
|
* @throws Error if `Base` is already sigilified.
|
|
442
317
|
*/
|
|
443
318
|
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label?: L, opts?: SigilOptions): {
|
|
444
319
|
new (...args: any[]): {
|
|
445
320
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
449
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
450
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
451
|
-
*/
|
|
452
|
-
readonly __SIGIL_BRAND__: {
|
|
453
|
-
Sigil: true;
|
|
454
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
455
|
-
/**
|
|
456
|
-
* Check whether `other` is (or inherits from) the type instance.
|
|
321
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
322
|
+
* calling constructor.
|
|
457
323
|
*
|
|
458
|
-
*
|
|
324
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
325
|
+
* and when subclassing.
|
|
459
326
|
*
|
|
460
|
-
* @typeParam T - The
|
|
461
|
-
* @param this - The
|
|
327
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
328
|
+
* @param this - The constructor performing the type check.
|
|
462
329
|
* @param other - The object to test.
|
|
463
|
-
* @returns
|
|
330
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
464
331
|
*/
|
|
465
|
-
isOfType<
|
|
332
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
466
333
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
* Allows 'instanceof' like checks but in instances.
|
|
334
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
335
|
+
* calling constructor.
|
|
470
336
|
*
|
|
471
|
-
* @typeParam T - The
|
|
472
|
-
* @param this - The
|
|
337
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
338
|
+
* @param this - The constructor performing the type check.
|
|
473
339
|
* @param other - The object to test.
|
|
474
|
-
* @returns
|
|
340
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
475
341
|
*/
|
|
476
|
-
|
|
342
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
477
343
|
/**
|
|
478
344
|
* Returns the identity sigil label of this instance's constructor.
|
|
479
345
|
*
|
|
480
|
-
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil
|
|
346
|
+
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
|
|
481
347
|
*/
|
|
482
348
|
getSigilLabel(): string;
|
|
483
349
|
/**
|
|
484
350
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
485
351
|
*
|
|
486
|
-
* @returns The last passed label string (e.g. '@scope/pkg.ClassName')
|
|
352
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName').
|
|
487
353
|
*/
|
|
488
354
|
getSigilEffectiveLabel(): string;
|
|
489
355
|
/**
|
|
@@ -493,32 +359,28 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
493
359
|
*/
|
|
494
360
|
getSigilLabelLineage(): readonly string[];
|
|
495
361
|
/**
|
|
496
|
-
* Returns a
|
|
362
|
+
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
497
363
|
*
|
|
498
|
-
* @returns
|
|
364
|
+
* @returns readonly array of labels representing the type lineage.
|
|
499
365
|
*/
|
|
500
366
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
367
|
+
/**
|
|
368
|
+
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
369
|
+
*/
|
|
370
|
+
readonly [sigil]: {
|
|
371
|
+
Sigil: true;
|
|
372
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
501
373
|
};
|
|
502
|
-
/**
|
|
503
|
-
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
504
|
-
*
|
|
505
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
506
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
507
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
508
|
-
*/
|
|
509
|
-
readonly __SIGIL_BRAND__: Prettify<{
|
|
510
|
-
Sigil: true;
|
|
511
|
-
} & { [K in L]: true; }>;
|
|
512
374
|
/**
|
|
513
375
|
* Class-level identity label constant for this sigil constructor.
|
|
514
376
|
*/
|
|
515
|
-
get SigilLabel():
|
|
377
|
+
get SigilLabel(): L;
|
|
516
378
|
/**
|
|
517
379
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
518
380
|
*/
|
|
519
|
-
get SigilEffectiveLabel():
|
|
381
|
+
get SigilEffectiveLabel(): L;
|
|
520
382
|
/**
|
|
521
|
-
*
|
|
383
|
+
* Linearized sigil type label chain for the current constructor.
|
|
522
384
|
*
|
|
523
385
|
* Useful for debugging and performing strict lineage comparisons.
|
|
524
386
|
*
|
|
@@ -526,9 +388,8 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
526
388
|
*/
|
|
527
389
|
get SigilLabelLineage(): readonly string[];
|
|
528
390
|
/**
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
391
|
+
* Sigil type label set for the current constructor.
|
|
392
|
+
* Useful for debugging.
|
|
532
393
|
*
|
|
533
394
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
534
395
|
*/
|
|
@@ -539,28 +400,30 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
539
400
|
* @param obj - The value to test.
|
|
540
401
|
* @returns `true` if `obj` is a sigil instance.
|
|
541
402
|
*/
|
|
542
|
-
isSigilified(obj: unknown): obj is
|
|
403
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
543
404
|
/**
|
|
544
|
-
* Check whether `other` is (or inherits from) the
|
|
405
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
406
|
+
* calling constructor.
|
|
545
407
|
*
|
|
546
408
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
547
409
|
* and when subclassing.
|
|
548
410
|
*
|
|
549
|
-
* @typeParam T - The
|
|
550
|
-
* @param this - The constructor performing the check.
|
|
411
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
412
|
+
* @param this - The constructor performing the type check.
|
|
551
413
|
* @param other - The object to test.
|
|
552
|
-
* @returns
|
|
414
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
553
415
|
*/
|
|
554
|
-
isOfType<T>(this: T, other: unknown): other is
|
|
416
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
555
417
|
/**
|
|
556
|
-
*
|
|
418
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
419
|
+
* calling constructor.
|
|
557
420
|
*
|
|
558
|
-
* @typeParam T - The
|
|
559
|
-
* @param this - The constructor performing the check.
|
|
421
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
422
|
+
* @param this - The constructor performing the type check.
|
|
560
423
|
* @param other - The object to test.
|
|
561
|
-
* @returns
|
|
424
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
562
425
|
*/
|
|
563
|
-
|
|
426
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
564
427
|
} & B;
|
|
565
428
|
/**
|
|
566
429
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
@@ -574,47 +437,38 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
574
437
|
*/
|
|
575
438
|
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label?: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
576
439
|
/**
|
|
577
|
-
*
|
|
440
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
|
+
* calling constructor.
|
|
578
442
|
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
582
|
-
*/
|
|
583
|
-
readonly __SIGIL_BRAND__: {
|
|
584
|
-
Sigil: true;
|
|
585
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
586
|
-
/**
|
|
587
|
-
* Check whether `other` is (or inherits from) the type instance.
|
|
588
|
-
*
|
|
589
|
-
* Allows 'instanceof' like checks but in instances.
|
|
443
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
444
|
+
* and when subclassing.
|
|
590
445
|
*
|
|
591
|
-
* @typeParam T - The
|
|
592
|
-
* @param this - The
|
|
446
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
447
|
+
* @param this - The constructor performing the type check.
|
|
593
448
|
* @param other - The object to test.
|
|
594
|
-
* @returns
|
|
449
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
595
450
|
*/
|
|
596
|
-
isOfType<
|
|
451
|
+
isOfType<T>(this: T, other: unknown): other is T;
|
|
597
452
|
/**
|
|
598
|
-
*
|
|
453
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
454
|
+
* calling constructor.
|
|
599
455
|
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* @typeParam T - The instance type.
|
|
603
|
-
* @param this - The instance performing the check.
|
|
456
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
457
|
+
* @param this - The constructor performing the type check.
|
|
604
458
|
* @param other - The object to test.
|
|
605
|
-
* @returns
|
|
459
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
606
460
|
*/
|
|
607
|
-
|
|
461
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
608
462
|
/**
|
|
609
463
|
* Returns the identity sigil label of this instance's constructor.
|
|
610
464
|
*
|
|
611
|
-
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil
|
|
465
|
+
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
|
|
612
466
|
*/
|
|
613
467
|
getSigilLabel(): string;
|
|
614
468
|
/**
|
|
615
469
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
616
470
|
*
|
|
617
|
-
* @returns The last passed label string (e.g. '@scope/pkg.ClassName')
|
|
471
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName').
|
|
618
472
|
*/
|
|
619
473
|
getSigilEffectiveLabel(): string;
|
|
620
474
|
/**
|
|
@@ -624,32 +478,28 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
624
478
|
*/
|
|
625
479
|
getSigilLabelLineage(): readonly string[];
|
|
626
480
|
/**
|
|
627
|
-
* Returns a
|
|
481
|
+
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
628
482
|
*
|
|
629
|
-
* @returns
|
|
483
|
+
* @returns readonly array of labels representing the type lineage.
|
|
630
484
|
*/
|
|
631
485
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
632
|
-
}) & {
|
|
633
486
|
/**
|
|
634
|
-
* Compile-time nominal brand that encodes the class
|
|
635
|
-
*
|
|
636
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
637
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
638
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
487
|
+
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
639
488
|
*/
|
|
640
|
-
readonly
|
|
489
|
+
readonly [sigil]: {
|
|
641
490
|
Sigil: true;
|
|
642
|
-
} & { [
|
|
491
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
492
|
+
}) & {
|
|
643
493
|
/**
|
|
644
494
|
* Class-level identity label constant for this sigil constructor.
|
|
645
495
|
*/
|
|
646
|
-
get SigilLabel():
|
|
496
|
+
get SigilLabel(): L;
|
|
647
497
|
/**
|
|
648
498
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
649
499
|
*/
|
|
650
|
-
get SigilEffectiveLabel():
|
|
500
|
+
get SigilEffectiveLabel(): L;
|
|
651
501
|
/**
|
|
652
|
-
*
|
|
502
|
+
* Linearized sigil type label chain for the current constructor.
|
|
653
503
|
*
|
|
654
504
|
* Useful for debugging and performing strict lineage comparisons.
|
|
655
505
|
*
|
|
@@ -657,9 +507,8 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
657
507
|
*/
|
|
658
508
|
get SigilLabelLineage(): readonly string[];
|
|
659
509
|
/**
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
510
|
+
* Sigil type label set for the current constructor.
|
|
511
|
+
* Useful for debugging.
|
|
663
512
|
*
|
|
664
513
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
665
514
|
*/
|
|
@@ -670,36 +519,30 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
670
519
|
* @param obj - The value to test.
|
|
671
520
|
* @returns `true` if `obj` is a sigil instance.
|
|
672
521
|
*/
|
|
673
|
-
isSigilified(obj: unknown): obj is
|
|
522
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
674
523
|
/**
|
|
675
|
-
* Check whether `other` is (or inherits from) the
|
|
676
|
-
*
|
|
677
|
-
* Implementation detail:
|
|
678
|
-
* - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
|
|
679
|
-
* - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
524
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
525
|
+
* calling constructor.
|
|
680
526
|
*
|
|
681
527
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
682
528
|
* and when subclassing.
|
|
683
529
|
*
|
|
684
|
-
* @typeParam T - The
|
|
685
|
-
* @param this - The constructor performing the check.
|
|
530
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
531
|
+
* @param this - The constructor performing the type check.
|
|
686
532
|
* @param other - The object to test.
|
|
687
|
-
* @returns
|
|
533
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
688
534
|
*/
|
|
689
|
-
isOfType<T>(this: T, other: unknown): other is
|
|
535
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
690
536
|
/**
|
|
691
|
-
*
|
|
537
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
538
|
+
* calling constructor.
|
|
692
539
|
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
* - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
696
|
-
*
|
|
697
|
-
* @typeParam T - The calling constructor type.
|
|
698
|
-
* @param this - The constructor performing the check.
|
|
540
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
541
|
+
* @param this - The constructor performing the type check.
|
|
699
542
|
* @param other - The object to test.
|
|
700
|
-
* @returns
|
|
543
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
701
544
|
*/
|
|
702
|
-
|
|
545
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
703
546
|
}) & B;
|
|
704
547
|
|
|
705
|
-
export { DEFAULT_LABEL_REGEX, type
|
|
548
|
+
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|