@vicin/sigil 3.0.0 → 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 +11 -0
- package/README.md +65 -9
- package/dist/index.d.mts +120 -196
- package/dist/index.d.ts +120 -196
- package/dist/index.global.js +530 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +526 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +515 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
package/dist/index.d.mts
CHANGED
|
@@ -25,29 +25,25 @@ interface ISigilStatic<L extends string = string> {
|
|
|
25
25
|
readonly SigilEffectiveLabel: L;
|
|
26
26
|
/**
|
|
27
27
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
28
|
-
* Useful for debugging
|
|
28
|
+
* Useful for debugging.
|
|
29
29
|
*/
|
|
30
30
|
readonly SigilLabelLineage: readonly string[];
|
|
31
31
|
/**
|
|
32
|
-
* Copy of the sigil type label set for the current constructor.
|
|
33
|
-
*
|
|
32
|
+
* Copy of the sigil type label set for the current constructor.
|
|
33
|
+
* Useful for debugging.
|
|
34
34
|
*/
|
|
35
35
|
readonly SigilLabelSet: Readonly<Set<string>>;
|
|
36
36
|
/**
|
|
37
37
|
* Runtime check that determines whether `obj` is an instance produced by a
|
|
38
38
|
* sigil class.
|
|
39
39
|
*
|
|
40
|
-
* Note: the concrete implementation provided by the mixin delegates to
|
|
41
|
-
* `isSigilInstance`.
|
|
42
|
-
*
|
|
43
40
|
* @param obj - Value to test.
|
|
44
|
-
* @returns Type guard narrowing `obj` to `
|
|
41
|
+
* @returns Type guard narrowing `obj` to `ISigilInstance`.
|
|
45
42
|
*/
|
|
46
|
-
isSigilified(obj: unknown): obj is
|
|
43
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
47
44
|
/**
|
|
48
|
-
* Check whether `other` is (or inherits from) the
|
|
49
|
-
* calling constructor.
|
|
50
|
-
* 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.
|
|
51
47
|
*
|
|
52
48
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
53
49
|
* and when subclassing.
|
|
@@ -57,20 +53,17 @@ interface ISigilStatic<L extends string = string> {
|
|
|
57
53
|
* @param other - The object to test.
|
|
58
54
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
59
55
|
*/
|
|
60
|
-
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is T
|
|
56
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
61
57
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
66
|
-
* 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.
|
|
67
60
|
*
|
|
68
61
|
* @typeParam T - The specific sigil constructor (`this`).
|
|
69
|
-
* @param this - The constructor performing the
|
|
62
|
+
* @param this - The constructor performing the type check.
|
|
70
63
|
* @param other - The object to test.
|
|
71
|
-
* @returns A type guard asserting `other` is an instance
|
|
64
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
72
65
|
*/
|
|
73
|
-
|
|
66
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
74
67
|
}
|
|
75
68
|
/**
|
|
76
69
|
* Instance-side interface describing properties present on sigil instances.
|
|
@@ -80,14 +73,10 @@ interface ISigilStatic<L extends string = string> {
|
|
|
80
73
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
81
74
|
*/
|
|
82
75
|
interface ISigilInstance<L extends string = string, P extends Function = never> {
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
88
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
89
|
-
*/
|
|
90
|
-
readonly [sigil]: Prettify<IfNever<SigilOf<P>, {}> & {
|
|
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>, {}> & {
|
|
91
80
|
[k in L]: true;
|
|
92
81
|
}>;
|
|
93
82
|
/** Returns identity sigil label of the class constructor. */
|
|
@@ -99,9 +88,8 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
99
88
|
/** Returns copy of sigil type label set of the class constructor. */
|
|
100
89
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
101
90
|
/**
|
|
102
|
-
* Check whether `other` is (or inherits from) the
|
|
103
|
-
* calling constructor.
|
|
104
|
-
* 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.
|
|
105
93
|
*
|
|
106
94
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
107
95
|
* and when subclassing.
|
|
@@ -113,18 +101,15 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
113
101
|
*/
|
|
114
102
|
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
115
103
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
120
|
-
* 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.
|
|
121
106
|
*
|
|
122
107
|
* @typeParam T - The specific sigil constructor (`this`).
|
|
123
|
-
* @param this - The constructor performing the
|
|
108
|
+
* @param this - The constructor performing the type check.
|
|
124
109
|
* @param other - The object to test.
|
|
125
|
-
* @returns A type guard asserting `other` is an instance
|
|
110
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
126
111
|
*/
|
|
127
|
-
|
|
112
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
128
113
|
}
|
|
129
114
|
/**
|
|
130
115
|
* Combined constructor + static interface for a sigil class.
|
|
@@ -133,15 +118,15 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
133
118
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
134
119
|
*/
|
|
135
120
|
type ISigil<L extends string = string, P extends Function = never> = ConstructorAbstract<ISigilInstance<L, P>> & ISigilStatic<L>;
|
|
136
|
-
/** Update '[sigil]' field
|
|
121
|
+
/** Update '[sigil]' field for nominal typing */
|
|
137
122
|
type ExtendSigil<L extends string, P extends ISigilInstance> = Prettify<IfNever<SigilOf<P>, {}> & {
|
|
138
123
|
[K in L]: true;
|
|
139
124
|
}>;
|
|
140
125
|
/**
|
|
141
|
-
* Extract the compile-time
|
|
126
|
+
* Extract the compile-time label map from a sigil instance `S`.
|
|
142
127
|
*
|
|
143
128
|
* @typeParam S - A sigil instance type.
|
|
144
|
-
* @returns The sigil
|
|
129
|
+
* @returns The sigil label record (e.g. `{ User: true, Admin: true }`) or never if not Sigil class instance.
|
|
145
130
|
*/
|
|
146
131
|
type SigilOf<S> = S extends {
|
|
147
132
|
readonly [sigil]: infer Sigil;
|
|
@@ -175,6 +160,10 @@ type Prettify<T> = {
|
|
|
175
160
|
} & {};
|
|
176
161
|
/** Helper type to replace 'never' with another type */
|
|
177
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;
|
|
178
167
|
|
|
179
168
|
/**
|
|
180
169
|
* A minimal root Sigil class used by the library as a base identity.
|
|
@@ -184,8 +173,8 @@ type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
|
184
173
|
*/
|
|
185
174
|
declare const Sigil: {
|
|
186
175
|
new (...args: any[]): {
|
|
187
|
-
isOfType<T>(this: T, other: unknown): other is T;
|
|
188
|
-
|
|
176
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
177
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
189
178
|
getSigilLabel(): string;
|
|
190
179
|
getSigilEffectiveLabel(): string;
|
|
191
180
|
getSigilLabelLineage(): readonly string[];
|
|
@@ -198,9 +187,9 @@ declare const Sigil: {
|
|
|
198
187
|
get SigilEffectiveLabel(): "Sigil";
|
|
199
188
|
get SigilLabelLineage(): readonly string[];
|
|
200
189
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
201
|
-
isSigilified(obj: unknown): obj is
|
|
202
|
-
isOfType<T>(this: T, other: unknown): other is T
|
|
203
|
-
|
|
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>;
|
|
204
193
|
} & {
|
|
205
194
|
new (): {};
|
|
206
195
|
};
|
|
@@ -214,8 +203,8 @@ type Sigil = InstanceType<typeof Sigil>;
|
|
|
214
203
|
*/
|
|
215
204
|
declare const SigilError: {
|
|
216
205
|
new (...args: any[]): {
|
|
217
|
-
isOfType<T>(this: T, other: unknown): other is T;
|
|
218
|
-
|
|
206
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
207
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
219
208
|
getSigilLabel(): string;
|
|
220
209
|
getSigilEffectiveLabel(): string;
|
|
221
210
|
getSigilLabelLineage(): readonly string[];
|
|
@@ -229,9 +218,9 @@ declare const SigilError: {
|
|
|
229
218
|
get SigilEffectiveLabel(): "SigilError";
|
|
230
219
|
get SigilLabelLineage(): readonly string[];
|
|
231
220
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
232
|
-
isSigilified(obj: unknown): obj is
|
|
233
|
-
isOfType<T>(this: T, other: unknown): other is T
|
|
234
|
-
|
|
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>;
|
|
235
224
|
} & ErrorConstructor;
|
|
236
225
|
type SigilError = InstanceType<typeof SigilError>;
|
|
237
226
|
|
|
@@ -251,24 +240,6 @@ interface SigilOptions {
|
|
|
251
240
|
* Defaults to `null`.
|
|
252
241
|
*/
|
|
253
242
|
labelValidation?: ((label: string) => boolean) | RegExp | null;
|
|
254
|
-
/**
|
|
255
|
-
* Skips the runtime check that prevents subclasses from inheriting
|
|
256
|
-
* the same sigil label as their ancestors.
|
|
257
|
-
*
|
|
258
|
-
* When `false` (default), extending a sigil class without
|
|
259
|
-
* using `WithSigil(newLabel)` decorator will throw an error if the label
|
|
260
|
-
* is reused and `OPTIONS.autofillLabels` is set to `false`.
|
|
261
|
-
*
|
|
262
|
-
* Set this to `true` only if you intentionally want subclasses to inherit labels
|
|
263
|
-
* from their ancestors (this weakens the uniqueness guarantees).
|
|
264
|
-
*
|
|
265
|
-
* WARNING:
|
|
266
|
-
* Disabling inheritanceCheck removes guaranties by 'Sigil' or unique label for
|
|
267
|
-
* each class and allow multiple child classes to use the same label which can
|
|
268
|
-
* result on false 'isOfType' result. this options should be used in debugging
|
|
269
|
-
* only to silence all errors but never in production.
|
|
270
|
-
*/
|
|
271
|
-
skipLabelInheritanceCheck?: boolean;
|
|
272
243
|
/**
|
|
273
244
|
* When enabled, non-decorated subclasses that would otherwise inherit an ancestor's label
|
|
274
245
|
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
@@ -297,32 +268,27 @@ declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
|
297
268
|
/**
|
|
298
269
|
* Class decorator factory that attaches sigil statics to a class constructor.
|
|
299
270
|
*
|
|
300
|
-
*
|
|
301
|
-
* - This decorator is intended to be applied to classes only. When used
|
|
302
|
-
* incorrectly (e.g. on a property), it is a no-op.
|
|
303
|
-
* - Throws an error during class creation if the label validation fails (in development only).
|
|
304
|
-
*
|
|
305
|
-
* @typeParam L - Narrow string literal type for the provided label.
|
|
306
|
-
* @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
307
|
-
* 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`).
|
|
308
272
|
* @param opts - Options object to override any global options if needed.
|
|
309
273
|
* @returns A class decorator compatible with the ECMAScript decorator context.
|
|
310
274
|
*/
|
|
311
|
-
declare function WithSigil
|
|
275
|
+
declare function WithSigil(label: string, opts?: SigilOptions): (value: Function, context: any) => void;
|
|
312
276
|
|
|
313
277
|
/**
|
|
314
278
|
* HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
|
|
315
279
|
* Alternative to '@WithSigil' if you prefer HOFs.
|
|
316
280
|
*
|
|
317
|
-
* @typeParam S - Constructor type (should be an
|
|
318
|
-
* @typeParam L - Label literal to attach.
|
|
281
|
+
* @typeParam S - Constructor type (should be an instance of sigil class).
|
|
319
282
|
* @param Class - The constructor (class) to enhance.
|
|
320
|
-
* @param label -
|
|
283
|
+
* @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
321
284
|
* @param opts - Options object to override any global options if needed.
|
|
322
285
|
* @returns The same constructor value, with runtime metadata ensured.
|
|
323
286
|
*/
|
|
324
|
-
declare function withSigil<S extends Function
|
|
287
|
+
declare function withSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S;
|
|
325
288
|
|
|
289
|
+
/** -----------------------------------------
|
|
290
|
+
* Introspection helpers
|
|
291
|
+
* ----------------------------------------- */
|
|
326
292
|
/**
|
|
327
293
|
* Runtime predicate that checks whether the provided value is a sigil constructor.
|
|
328
294
|
*
|
|
@@ -338,36 +304,6 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
|
|
|
338
304
|
* @returns `true` if `obj` is an instance produced by a sigil constructor.
|
|
339
305
|
*/
|
|
340
306
|
declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
341
|
-
/**
|
|
342
|
-
* Check whether the provided constructor was marked as a sigil base constructor.
|
|
343
|
-
*
|
|
344
|
-
* @param ctor - Constructor to check.
|
|
345
|
-
* @returns `true` if `ctor` is a sigil base constructor.
|
|
346
|
-
*/
|
|
347
|
-
declare function isSigilBaseCtor(ctor: Function): ctor is ISigil;
|
|
348
|
-
/**
|
|
349
|
-
* Check whether the provided object is an instance of a sigil base constructor.
|
|
350
|
-
*
|
|
351
|
-
* @param inst - The instance to test.
|
|
352
|
-
* @returns `true` if `inst` is an instance of a sigil base constructor.
|
|
353
|
-
*/
|
|
354
|
-
declare function isSigilBaseInstance(inst: unknown): inst is ISigilInstance;
|
|
355
|
-
/**
|
|
356
|
-
* Returns whether the constructor has been explicitly decorated with `WithSigil`.
|
|
357
|
-
*
|
|
358
|
-
* @internal
|
|
359
|
-
* @param ctor - Constructor to test.
|
|
360
|
-
* @returns `true` if the constructor is explicitly decorated.
|
|
361
|
-
*/
|
|
362
|
-
declare function isDecorated(ctor: Function): boolean;
|
|
363
|
-
/**
|
|
364
|
-
* Returns whether inheritance checks have already been performed for the constructor.
|
|
365
|
-
*
|
|
366
|
-
* @internal
|
|
367
|
-
* @param ctor - Constructor to test.
|
|
368
|
-
* @returns `true` if inheritance checks were marked as completed.
|
|
369
|
-
*/
|
|
370
|
-
declare function isInheritanceChecked(ctor: Function): boolean;
|
|
371
307
|
|
|
372
308
|
/**
|
|
373
309
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
@@ -376,43 +312,44 @@ declare function isInheritanceChecked(ctor: Function): boolean;
|
|
|
376
312
|
* @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
377
313
|
* If not passed a random label is generated instead.
|
|
378
314
|
* @param opts - Options object to override any global options if needed.
|
|
379
|
-
* @returns A new
|
|
315
|
+
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
380
316
|
* @throws Error if `Base` is already sigilified.
|
|
381
317
|
*/
|
|
382
318
|
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label?: L, opts?: SigilOptions): {
|
|
383
319
|
new (...args: any[]): {
|
|
384
320
|
/**
|
|
385
|
-
* Check whether `other` is (or inherits from) the
|
|
321
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
322
|
+
* calling constructor.
|
|
386
323
|
*
|
|
387
|
-
*
|
|
324
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
325
|
+
* and when subclassing.
|
|
388
326
|
*
|
|
389
|
-
* @typeParam T - The
|
|
390
|
-
* @param this - The
|
|
327
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
328
|
+
* @param this - The constructor performing the type check.
|
|
391
329
|
* @param other - The object to test.
|
|
392
|
-
* @returns
|
|
330
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
393
331
|
*/
|
|
394
|
-
isOfType<T>(this: T, other: unknown): other is T;
|
|
332
|
+
isOfType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
395
333
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* Allows 'instanceof' like checks but in instances.
|
|
334
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
335
|
+
* calling constructor.
|
|
399
336
|
*
|
|
400
|
-
* @typeParam T - The
|
|
401
|
-
* @param this - The
|
|
337
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
338
|
+
* @param this - The constructor performing the type check.
|
|
402
339
|
* @param other - The object to test.
|
|
403
|
-
* @returns
|
|
340
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
404
341
|
*/
|
|
405
|
-
|
|
342
|
+
isExactType<T extends ISigilInstance>(this: T, other: unknown): other is T;
|
|
406
343
|
/**
|
|
407
344
|
* Returns the identity sigil label of this instance's constructor.
|
|
408
345
|
*
|
|
409
|
-
* @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').
|
|
410
347
|
*/
|
|
411
348
|
getSigilLabel(): string;
|
|
412
349
|
/**
|
|
413
350
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
414
351
|
*
|
|
415
|
-
* @returns The last passed label string (e.g. '@scope/pkg.ClassName')
|
|
352
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName').
|
|
416
353
|
*/
|
|
417
354
|
getSigilEffectiveLabel(): string;
|
|
418
355
|
/**
|
|
@@ -422,17 +359,13 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
422
359
|
*/
|
|
423
360
|
getSigilLabelLineage(): readonly string[];
|
|
424
361
|
/**
|
|
425
|
-
* Returns a
|
|
362
|
+
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
426
363
|
*
|
|
427
|
-
* @returns
|
|
364
|
+
* @returns readonly array of labels representing the type lineage.
|
|
428
365
|
*/
|
|
429
366
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
430
367
|
/**
|
|
431
|
-
* Compile-time nominal brand that encodes the class
|
|
432
|
-
*
|
|
433
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
434
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
435
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
368
|
+
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
436
369
|
*/
|
|
437
370
|
readonly [sigil]: {
|
|
438
371
|
Sigil: true;
|
|
@@ -447,7 +380,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
447
380
|
*/
|
|
448
381
|
get SigilEffectiveLabel(): L;
|
|
449
382
|
/**
|
|
450
|
-
*
|
|
383
|
+
* Linearized sigil type label chain for the current constructor.
|
|
451
384
|
*
|
|
452
385
|
* Useful for debugging and performing strict lineage comparisons.
|
|
453
386
|
*
|
|
@@ -455,9 +388,8 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
455
388
|
*/
|
|
456
389
|
get SigilLabelLineage(): readonly string[];
|
|
457
390
|
/**
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
391
|
+
* Sigil type label set for the current constructor.
|
|
392
|
+
* Useful for debugging.
|
|
461
393
|
*
|
|
462
394
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
463
395
|
*/
|
|
@@ -468,28 +400,30 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
468
400
|
* @param obj - The value to test.
|
|
469
401
|
* @returns `true` if `obj` is a sigil instance.
|
|
470
402
|
*/
|
|
471
|
-
isSigilified(obj: unknown): obj is
|
|
403
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
472
404
|
/**
|
|
473
|
-
* Check whether `other` is (or inherits from) the
|
|
405
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
406
|
+
* calling constructor.
|
|
474
407
|
*
|
|
475
408
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
476
409
|
* and when subclassing.
|
|
477
410
|
*
|
|
478
|
-
* @typeParam T - The
|
|
479
|
-
* @param this - The constructor performing the check.
|
|
411
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
412
|
+
* @param this - The constructor performing the type check.
|
|
480
413
|
* @param other - The object to test.
|
|
481
|
-
* @returns
|
|
414
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
482
415
|
*/
|
|
483
|
-
isOfType<T>(this: T, other: unknown): other is T
|
|
416
|
+
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
484
417
|
/**
|
|
485
|
-
*
|
|
418
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
419
|
+
* calling constructor.
|
|
486
420
|
*
|
|
487
|
-
* @typeParam T - The
|
|
488
|
-
* @param this - The constructor performing the check.
|
|
421
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
422
|
+
* @param this - The constructor performing the type check.
|
|
489
423
|
* @param other - The object to test.
|
|
490
|
-
* @returns
|
|
424
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
491
425
|
*/
|
|
492
|
-
|
|
426
|
+
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
493
427
|
} & B;
|
|
494
428
|
/**
|
|
495
429
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
@@ -503,37 +437,38 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
503
437
|
*/
|
|
504
438
|
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label?: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
505
439
|
/**
|
|
506
|
-
* Check whether `other` is (or inherits from) the
|
|
440
|
+
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
|
+
* calling constructor.
|
|
507
442
|
*
|
|
508
|
-
*
|
|
443
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
444
|
+
* and when subclassing.
|
|
509
445
|
*
|
|
510
|
-
* @typeParam T - The
|
|
511
|
-
* @param this - The
|
|
446
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
447
|
+
* @param this - The constructor performing the type check.
|
|
512
448
|
* @param other - The object to test.
|
|
513
|
-
* @returns
|
|
449
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
514
450
|
*/
|
|
515
451
|
isOfType<T>(this: T, other: unknown): other is T;
|
|
516
452
|
/**
|
|
517
|
-
*
|
|
453
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
454
|
+
* calling constructor.
|
|
518
455
|
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* @typeParam T - The instance type.
|
|
522
|
-
* @param this - The instance performing the check.
|
|
456
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
457
|
+
* @param this - The constructor performing the type check.
|
|
523
458
|
* @param other - The object to test.
|
|
524
|
-
* @returns
|
|
459
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
525
460
|
*/
|
|
526
|
-
|
|
461
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
527
462
|
/**
|
|
528
463
|
* Returns the identity sigil label of this instance's constructor.
|
|
529
464
|
*
|
|
530
|
-
* @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').
|
|
531
466
|
*/
|
|
532
467
|
getSigilLabel(): string;
|
|
533
468
|
/**
|
|
534
469
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
535
470
|
*
|
|
536
|
-
* @returns The last passed label string (e.g. '@scope/pkg.ClassName')
|
|
471
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName').
|
|
537
472
|
*/
|
|
538
473
|
getSigilEffectiveLabel(): string;
|
|
539
474
|
/**
|
|
@@ -543,17 +478,13 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
543
478
|
*/
|
|
544
479
|
getSigilLabelLineage(): readonly string[];
|
|
545
480
|
/**
|
|
546
|
-
* Returns a
|
|
481
|
+
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
547
482
|
*
|
|
548
|
-
* @returns
|
|
483
|
+
* @returns readonly array of labels representing the type lineage.
|
|
549
484
|
*/
|
|
550
485
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
551
486
|
/**
|
|
552
|
-
* Compile-time nominal brand that encodes the class
|
|
553
|
-
*
|
|
554
|
-
* - HAVE NO RUN-TIME VALUE (undefined)
|
|
555
|
-
* - Provides a *type-only* unique marker that makes instances nominally
|
|
556
|
-
* distinct by label and allows propagation/merging of brand keys across inheritance.
|
|
487
|
+
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
557
488
|
*/
|
|
558
489
|
readonly [sigil]: {
|
|
559
490
|
Sigil: true;
|
|
@@ -568,7 +499,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
568
499
|
*/
|
|
569
500
|
get SigilEffectiveLabel(): L;
|
|
570
501
|
/**
|
|
571
|
-
*
|
|
502
|
+
* Linearized sigil type label chain for the current constructor.
|
|
572
503
|
*
|
|
573
504
|
* Useful for debugging and performing strict lineage comparisons.
|
|
574
505
|
*
|
|
@@ -576,9 +507,8 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
576
507
|
*/
|
|
577
508
|
get SigilLabelLineage(): readonly string[];
|
|
578
509
|
/**
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
510
|
+
* Sigil type label set for the current constructor.
|
|
511
|
+
* Useful for debugging.
|
|
582
512
|
*
|
|
583
513
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
584
514
|
*/
|
|
@@ -589,36 +519,30 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
589
519
|
* @param obj - The value to test.
|
|
590
520
|
* @returns `true` if `obj` is a sigil instance.
|
|
591
521
|
*/
|
|
592
|
-
isSigilified(obj: unknown): obj is
|
|
522
|
+
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
593
523
|
/**
|
|
594
|
-
* Check whether `other` is (or inherits from) the
|
|
595
|
-
*
|
|
596
|
-
* Implementation detail:
|
|
597
|
-
* - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
|
|
598
|
-
* - 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.
|
|
599
526
|
*
|
|
600
527
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
601
528
|
* and when subclassing.
|
|
602
529
|
*
|
|
603
|
-
* @typeParam T - The
|
|
604
|
-
* @param this - The constructor performing the check.
|
|
530
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
531
|
+
* @param this - The constructor performing the type check.
|
|
605
532
|
* @param other - The object to test.
|
|
606
|
-
* @returns
|
|
533
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
607
534
|
*/
|
|
608
|
-
isOfType<T>(this: T, other: unknown): other is T
|
|
535
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
609
536
|
/**
|
|
610
|
-
*
|
|
537
|
+
* Check whether `other` is exactly the same instance represented by the
|
|
538
|
+
* calling constructor.
|
|
611
539
|
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
* - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
615
|
-
*
|
|
616
|
-
* @typeParam T - The calling constructor type.
|
|
617
|
-
* @param this - The constructor performing the check.
|
|
540
|
+
* @typeParam T - The specific sigil constructor (`this`).
|
|
541
|
+
* @param this - The constructor performing the type check.
|
|
618
542
|
* @param other - The object to test.
|
|
619
|
-
* @returns
|
|
543
|
+
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
620
544
|
*/
|
|
621
|
-
|
|
545
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
622
546
|
}) & B;
|
|
623
547
|
|
|
624
|
-
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil,
|
|
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 };
|