@vicin/sigil 3.2.1 → 3.4.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 +28 -1
- package/README.md +140 -73
- package/dist/index.d.mts +66 -58
- package/dist/index.d.ts +66 -58
- package/dist/index.global.js +105 -235
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +105 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -236
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -18,11 +18,11 @@ declare const sigil: unique symbol;
|
|
|
18
18
|
* @template L - Narrow string literal type representing the label.
|
|
19
19
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
20
20
|
*/
|
|
21
|
-
interface ISigilStatic
|
|
21
|
+
interface ISigilStatic {
|
|
22
22
|
/** Class-level label constant (identity). */
|
|
23
|
-
readonly SigilLabel:
|
|
23
|
+
readonly SigilLabel: string;
|
|
24
24
|
/** Class-level label constant (human readable). */
|
|
25
|
-
readonly SigilEffectiveLabel:
|
|
25
|
+
readonly SigilEffectiveLabel: string;
|
|
26
26
|
/**
|
|
27
27
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
28
28
|
* Useful for debugging.
|
|
@@ -109,7 +109,7 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
109
109
|
* @template L - Narrow string literal type for the label.
|
|
110
110
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
111
111
|
*/
|
|
112
|
-
type ISigil<L extends string = string, P extends Function = never> = ConstructorAbstract<ISigilInstance<L, P
|
|
112
|
+
type ISigil<L extends string = string, P extends Function = never> = ISigilStatic & ConstructorAbstract<ISigilInstance<L, P>>;
|
|
113
113
|
/** Update '[sigil]' field for nominal typing */
|
|
114
114
|
type ExtendSigil<L extends string, P extends ISigilInstance> = Prettify<IfNever<SigilOf<P>, {}> & {
|
|
115
115
|
[K in L]: true;
|
|
@@ -169,8 +169,8 @@ type GetPrototype<T> = T extends {
|
|
|
169
169
|
*/
|
|
170
170
|
declare const Sigil: {
|
|
171
171
|
new (...args: any[]): {
|
|
172
|
-
isOfType<T
|
|
173
|
-
isExactType<T
|
|
172
|
+
isOfType<T>(this: T, other: unknown): other is T;
|
|
173
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
174
174
|
getSigilLabel(): string;
|
|
175
175
|
getSigilEffectiveLabel(): string;
|
|
176
176
|
getSigilLabelLineage(): readonly string[];
|
|
@@ -179,14 +179,12 @@ declare const Sigil: {
|
|
|
179
179
|
Sigil: true;
|
|
180
180
|
};
|
|
181
181
|
};
|
|
182
|
-
get SigilLabel():
|
|
183
|
-
get SigilEffectiveLabel():
|
|
182
|
+
get SigilLabel(): string;
|
|
183
|
+
get SigilEffectiveLabel(): string;
|
|
184
184
|
get SigilLabelLineage(): readonly string[];
|
|
185
185
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
186
|
-
isOfType<T
|
|
187
|
-
isExactType<T
|
|
188
|
-
} & {
|
|
189
|
-
new (): {};
|
|
186
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
187
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
190
188
|
};
|
|
191
189
|
type Sigil = InstanceType<typeof Sigil>;
|
|
192
190
|
/**
|
|
@@ -198,24 +196,24 @@ type Sigil = InstanceType<typeof Sigil>;
|
|
|
198
196
|
*/
|
|
199
197
|
declare const SigilError: {
|
|
200
198
|
new (...args: any[]): {
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
[sigil]: {
|
|
200
|
+
Sigil: true;
|
|
201
|
+
SigilError: true;
|
|
202
|
+
};
|
|
203
|
+
isOfType<T>(this: T, other: unknown): other is T;
|
|
204
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
203
205
|
getSigilLabel(): string;
|
|
204
206
|
getSigilEffectiveLabel(): string;
|
|
205
207
|
getSigilLabelLineage(): readonly string[];
|
|
206
208
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
207
|
-
readonly [sigil]: {
|
|
208
|
-
Sigil: true;
|
|
209
|
-
SigilError: true;
|
|
210
|
-
};
|
|
211
209
|
};
|
|
212
|
-
get SigilLabel():
|
|
213
|
-
get SigilEffectiveLabel():
|
|
210
|
+
get SigilLabel(): string;
|
|
211
|
+
get SigilEffectiveLabel(): string;
|
|
214
212
|
get SigilLabelLineage(): readonly string[];
|
|
215
213
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
216
|
-
isOfType<T
|
|
217
|
-
isExactType<T
|
|
218
|
-
}
|
|
214
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
215
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
216
|
+
};
|
|
219
217
|
type SigilError = InstanceType<typeof SigilError>;
|
|
220
218
|
|
|
221
219
|
/** -----------------------------------------
|
|
@@ -242,6 +240,13 @@ interface SigilOptions {
|
|
|
242
240
|
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
243
241
|
*/
|
|
244
242
|
autofillLabels?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Option for Hot module reload set-ups, reload of files can result in class redefinition which will throw
|
|
245
|
+
* duplicate label error, setting this to 'true' will disabel this error.
|
|
246
|
+
* However as it disables unique label check bugs can appear if the same label is passed to two different
|
|
247
|
+
* classes so set this to 'true' only when needed and ensure uniqueness of passed labels.
|
|
248
|
+
*/
|
|
249
|
+
skipLabelUniquenessCheck?: boolean;
|
|
245
250
|
}
|
|
246
251
|
/** -----------------------------------------
|
|
247
252
|
* Update options
|
|
@@ -274,11 +279,14 @@ declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
|
274
279
|
* @param opts - Options object to override any global options if needed.
|
|
275
280
|
* @returns A class decorator compatible with the ECMAScript decorator context.
|
|
276
281
|
*/
|
|
277
|
-
declare function
|
|
278
|
-
|
|
282
|
+
declare function AttachSigil(label: string, opts?: SigilOptions): (value: Function, context: any) => void;
|
|
279
283
|
/**
|
|
280
|
-
*
|
|
281
|
-
|
|
284
|
+
* @deprecated Use 'AttachSigil' instead, updated for clarity. will be removed in v4
|
|
285
|
+
*/
|
|
286
|
+
declare const WithSigil: typeof AttachSigil;
|
|
287
|
+
/**
|
|
288
|
+
* Function that attaches runtime sigil metadata to Sigil class.
|
|
289
|
+
* Alternative to '@AttachSigil' if you prefer normal functions.
|
|
282
290
|
*
|
|
283
291
|
* @typeParam S - Constructor type (should be an instance of sigil class).
|
|
284
292
|
* @param Class - The constructor (class) to enhance.
|
|
@@ -286,7 +294,11 @@ declare function WithSigil(label: string, opts?: SigilOptions): (value: Function
|
|
|
286
294
|
* @param opts - Options object to override any global options if needed.
|
|
287
295
|
* @returns The same constructor value, with runtime metadata ensured.
|
|
288
296
|
*/
|
|
289
|
-
declare function
|
|
297
|
+
declare function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S;
|
|
298
|
+
/**
|
|
299
|
+
* @deprecated Use 'attachSigil' instead, updated for clarity. will be removed in v4
|
|
300
|
+
*/
|
|
301
|
+
declare const withSigil: typeof attachSigil;
|
|
290
302
|
|
|
291
303
|
/** -----------------------------------------
|
|
292
304
|
* Inspection helpers
|
|
@@ -308,11 +320,9 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
|
|
|
308
320
|
declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
309
321
|
/**
|
|
310
322
|
* Helper function to get labels registered by 'Sigil'
|
|
311
|
-
*
|
|
312
|
-
* @param includeAuto - Flag to include auto-generated labels as well, default is 'false'.
|
|
313
323
|
* @returns Sigil labels registered
|
|
314
324
|
*/
|
|
315
|
-
declare function getSigilLabels(
|
|
325
|
+
declare function getSigilLabels(): string[];
|
|
316
326
|
|
|
317
327
|
/**
|
|
318
328
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
@@ -323,8 +333,11 @@ declare function getSigilLabels(includeAuto?: boolean): string[];
|
|
|
323
333
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
324
334
|
* @throws Error if `Base` is already sigilified.
|
|
325
335
|
*/
|
|
326
|
-
declare function Sigilify<
|
|
336
|
+
declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions): {
|
|
327
337
|
new (...args: any[]): {
|
|
338
|
+
[sigil]: {
|
|
339
|
+
Sigil: true;
|
|
340
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
328
341
|
/**
|
|
329
342
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
330
343
|
* calling constructor.
|
|
@@ -337,7 +350,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
337
350
|
* @param other - The object to test.
|
|
338
351
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
339
352
|
*/
|
|
340
|
-
isOfType<
|
|
353
|
+
isOfType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
341
354
|
/**
|
|
342
355
|
* Check whether `other` is exactly the same instance represented by the
|
|
343
356
|
* calling constructor.
|
|
@@ -347,7 +360,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
347
360
|
* @param other - The object to test.
|
|
348
361
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
349
362
|
*/
|
|
350
|
-
isExactType<
|
|
363
|
+
isExactType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
351
364
|
/**
|
|
352
365
|
* Returns the identity sigil label of this instance's constructor.
|
|
353
366
|
*
|
|
@@ -369,24 +382,19 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
369
382
|
/**
|
|
370
383
|
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
371
384
|
*
|
|
385
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
372
386
|
* @returns readonly array of labels representing the type lineage.
|
|
373
387
|
*/
|
|
374
388
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
375
|
-
/**
|
|
376
|
-
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
377
|
-
*/
|
|
378
|
-
readonly [sigil]: {
|
|
379
|
-
Sigil: true;
|
|
380
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
381
389
|
};
|
|
382
390
|
/**
|
|
383
391
|
* Class-level identity label constant for this sigil constructor.
|
|
384
392
|
*/
|
|
385
|
-
get SigilLabel():
|
|
393
|
+
get SigilLabel(): string;
|
|
386
394
|
/**
|
|
387
395
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
388
396
|
*/
|
|
389
|
-
get SigilEffectiveLabel():
|
|
397
|
+
get SigilEffectiveLabel(): string;
|
|
390
398
|
/**
|
|
391
399
|
* Linearized sigil type label chain for the current constructor.
|
|
392
400
|
*
|
|
@@ -399,6 +407,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
399
407
|
* Sigil type label set for the current constructor.
|
|
400
408
|
* Useful for debugging.
|
|
401
409
|
*
|
|
410
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
402
411
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
403
412
|
*/
|
|
404
413
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
@@ -414,7 +423,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
414
423
|
* @param other - The object to test.
|
|
415
424
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
416
425
|
*/
|
|
417
|
-
isOfType<T
|
|
426
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
418
427
|
/**
|
|
419
428
|
* Check whether `other` is exactly the same instance represented by the
|
|
420
429
|
* calling constructor.
|
|
@@ -424,8 +433,8 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
424
433
|
* @param other - The object to test.
|
|
425
434
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
426
435
|
*/
|
|
427
|
-
isExactType<T
|
|
428
|
-
}
|
|
436
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
437
|
+
};
|
|
429
438
|
/**
|
|
430
439
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
431
440
|
*
|
|
@@ -435,7 +444,10 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
435
444
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
436
445
|
* @throws Error if `Base` is already sigilified.
|
|
437
446
|
*/
|
|
438
|
-
declare function SigilifyAbstract<
|
|
447
|
+
declare function SigilifyAbstract<L extends string>(Base: ConstructorAbstract, label: L, opts?: SigilOptions): (abstract new (...args: any[]) => {
|
|
448
|
+
[sigil]: {
|
|
449
|
+
Sigil: true;
|
|
450
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
439
451
|
/**
|
|
440
452
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
453
|
* calling constructor.
|
|
@@ -448,7 +460,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
448
460
|
* @param other - The object to test.
|
|
449
461
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
450
462
|
*/
|
|
451
|
-
isOfType<
|
|
463
|
+
isOfType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
452
464
|
/**
|
|
453
465
|
* Check whether `other` is exactly the same instance represented by the
|
|
454
466
|
* calling constructor.
|
|
@@ -458,7 +470,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
458
470
|
* @param other - The object to test.
|
|
459
471
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
460
472
|
*/
|
|
461
|
-
isExactType<
|
|
473
|
+
isExactType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
462
474
|
/**
|
|
463
475
|
* Returns the identity sigil label of this instance's constructor.
|
|
464
476
|
*
|
|
@@ -480,24 +492,19 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
480
492
|
/**
|
|
481
493
|
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
482
494
|
*
|
|
495
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
483
496
|
* @returns readonly array of labels representing the type lineage.
|
|
484
497
|
*/
|
|
485
498
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
486
|
-
/**
|
|
487
|
-
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
488
|
-
*/
|
|
489
|
-
readonly [sigil]: {
|
|
490
|
-
Sigil: true;
|
|
491
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
492
499
|
}) & {
|
|
493
500
|
/**
|
|
494
501
|
* Class-level identity label constant for this sigil constructor.
|
|
495
502
|
*/
|
|
496
|
-
get SigilLabel():
|
|
503
|
+
get SigilLabel(): string;
|
|
497
504
|
/**
|
|
498
505
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
499
506
|
*/
|
|
500
|
-
get SigilEffectiveLabel():
|
|
507
|
+
get SigilEffectiveLabel(): string;
|
|
501
508
|
/**
|
|
502
509
|
* Linearized sigil type label chain for the current constructor.
|
|
503
510
|
*
|
|
@@ -510,6 +517,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
510
517
|
* Sigil type label set for the current constructor.
|
|
511
518
|
* Useful for debugging.
|
|
512
519
|
*
|
|
520
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
513
521
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
514
522
|
*/
|
|
515
523
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
@@ -536,6 +544,6 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
536
544
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
537
545
|
*/
|
|
538
546
|
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
539
|
-
}
|
|
547
|
+
};
|
|
540
548
|
|
|
541
|
-
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, RECOMMENDED_LABEL_REGEX, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, getSigilLabels, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|
|
549
|
+
export { AttachSigil, DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, RECOMMENDED_LABEL_REGEX, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, attachSigil, getSigilLabels, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ declare const sigil: unique symbol;
|
|
|
18
18
|
* @template L - Narrow string literal type representing the label.
|
|
19
19
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
20
20
|
*/
|
|
21
|
-
interface ISigilStatic
|
|
21
|
+
interface ISigilStatic {
|
|
22
22
|
/** Class-level label constant (identity). */
|
|
23
|
-
readonly SigilLabel:
|
|
23
|
+
readonly SigilLabel: string;
|
|
24
24
|
/** Class-level label constant (human readable). */
|
|
25
|
-
readonly SigilEffectiveLabel:
|
|
25
|
+
readonly SigilEffectiveLabel: string;
|
|
26
26
|
/**
|
|
27
27
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
28
28
|
* Useful for debugging.
|
|
@@ -109,7 +109,7 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
109
109
|
* @template L - Narrow string literal type for the label.
|
|
110
110
|
* @template P - Optinal parent to extend its '[sigil]'.
|
|
111
111
|
*/
|
|
112
|
-
type ISigil<L extends string = string, P extends Function = never> = ConstructorAbstract<ISigilInstance<L, P
|
|
112
|
+
type ISigil<L extends string = string, P extends Function = never> = ISigilStatic & ConstructorAbstract<ISigilInstance<L, P>>;
|
|
113
113
|
/** Update '[sigil]' field for nominal typing */
|
|
114
114
|
type ExtendSigil<L extends string, P extends ISigilInstance> = Prettify<IfNever<SigilOf<P>, {}> & {
|
|
115
115
|
[K in L]: true;
|
|
@@ -169,8 +169,8 @@ type GetPrototype<T> = T extends {
|
|
|
169
169
|
*/
|
|
170
170
|
declare const Sigil: {
|
|
171
171
|
new (...args: any[]): {
|
|
172
|
-
isOfType<T
|
|
173
|
-
isExactType<T
|
|
172
|
+
isOfType<T>(this: T, other: unknown): other is T;
|
|
173
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
174
174
|
getSigilLabel(): string;
|
|
175
175
|
getSigilEffectiveLabel(): string;
|
|
176
176
|
getSigilLabelLineage(): readonly string[];
|
|
@@ -179,14 +179,12 @@ declare const Sigil: {
|
|
|
179
179
|
Sigil: true;
|
|
180
180
|
};
|
|
181
181
|
};
|
|
182
|
-
get SigilLabel():
|
|
183
|
-
get SigilEffectiveLabel():
|
|
182
|
+
get SigilLabel(): string;
|
|
183
|
+
get SigilEffectiveLabel(): string;
|
|
184
184
|
get SigilLabelLineage(): readonly string[];
|
|
185
185
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
186
|
-
isOfType<T
|
|
187
|
-
isExactType<T
|
|
188
|
-
} & {
|
|
189
|
-
new (): {};
|
|
186
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
187
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
190
188
|
};
|
|
191
189
|
type Sigil = InstanceType<typeof Sigil>;
|
|
192
190
|
/**
|
|
@@ -198,24 +196,24 @@ type Sigil = InstanceType<typeof Sigil>;
|
|
|
198
196
|
*/
|
|
199
197
|
declare const SigilError: {
|
|
200
198
|
new (...args: any[]): {
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
[sigil]: {
|
|
200
|
+
Sigil: true;
|
|
201
|
+
SigilError: true;
|
|
202
|
+
};
|
|
203
|
+
isOfType<T>(this: T, other: unknown): other is T;
|
|
204
|
+
isExactType<T>(this: T, other: unknown): other is T;
|
|
203
205
|
getSigilLabel(): string;
|
|
204
206
|
getSigilEffectiveLabel(): string;
|
|
205
207
|
getSigilLabelLineage(): readonly string[];
|
|
206
208
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
207
|
-
readonly [sigil]: {
|
|
208
|
-
Sigil: true;
|
|
209
|
-
SigilError: true;
|
|
210
|
-
};
|
|
211
209
|
};
|
|
212
|
-
get SigilLabel():
|
|
213
|
-
get SigilEffectiveLabel():
|
|
210
|
+
get SigilLabel(): string;
|
|
211
|
+
get SigilEffectiveLabel(): string;
|
|
214
212
|
get SigilLabelLineage(): readonly string[];
|
|
215
213
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
216
|
-
isOfType<T
|
|
217
|
-
isExactType<T
|
|
218
|
-
}
|
|
214
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
215
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
216
|
+
};
|
|
219
217
|
type SigilError = InstanceType<typeof SigilError>;
|
|
220
218
|
|
|
221
219
|
/** -----------------------------------------
|
|
@@ -242,6 +240,13 @@ interface SigilOptions {
|
|
|
242
240
|
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
243
241
|
*/
|
|
244
242
|
autofillLabels?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Option for Hot module reload set-ups, reload of files can result in class redefinition which will throw
|
|
245
|
+
* duplicate label error, setting this to 'true' will disabel this error.
|
|
246
|
+
* However as it disables unique label check bugs can appear if the same label is passed to two different
|
|
247
|
+
* classes so set this to 'true' only when needed and ensure uniqueness of passed labels.
|
|
248
|
+
*/
|
|
249
|
+
skipLabelUniquenessCheck?: boolean;
|
|
245
250
|
}
|
|
246
251
|
/** -----------------------------------------
|
|
247
252
|
* Update options
|
|
@@ -274,11 +279,14 @@ declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
|
274
279
|
* @param opts - Options object to override any global options if needed.
|
|
275
280
|
* @returns A class decorator compatible with the ECMAScript decorator context.
|
|
276
281
|
*/
|
|
277
|
-
declare function
|
|
278
|
-
|
|
282
|
+
declare function AttachSigil(label: string, opts?: SigilOptions): (value: Function, context: any) => void;
|
|
279
283
|
/**
|
|
280
|
-
*
|
|
281
|
-
|
|
284
|
+
* @deprecated Use 'AttachSigil' instead, updated for clarity. will be removed in v4
|
|
285
|
+
*/
|
|
286
|
+
declare const WithSigil: typeof AttachSigil;
|
|
287
|
+
/**
|
|
288
|
+
* Function that attaches runtime sigil metadata to Sigil class.
|
|
289
|
+
* Alternative to '@AttachSigil' if you prefer normal functions.
|
|
282
290
|
*
|
|
283
291
|
* @typeParam S - Constructor type (should be an instance of sigil class).
|
|
284
292
|
* @param Class - The constructor (class) to enhance.
|
|
@@ -286,7 +294,11 @@ declare function WithSigil(label: string, opts?: SigilOptions): (value: Function
|
|
|
286
294
|
* @param opts - Options object to override any global options if needed.
|
|
287
295
|
* @returns The same constructor value, with runtime metadata ensured.
|
|
288
296
|
*/
|
|
289
|
-
declare function
|
|
297
|
+
declare function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S;
|
|
298
|
+
/**
|
|
299
|
+
* @deprecated Use 'attachSigil' instead, updated for clarity. will be removed in v4
|
|
300
|
+
*/
|
|
301
|
+
declare const withSigil: typeof attachSigil;
|
|
290
302
|
|
|
291
303
|
/** -----------------------------------------
|
|
292
304
|
* Inspection helpers
|
|
@@ -308,11 +320,9 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
|
|
|
308
320
|
declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
309
321
|
/**
|
|
310
322
|
* Helper function to get labels registered by 'Sigil'
|
|
311
|
-
*
|
|
312
|
-
* @param includeAuto - Flag to include auto-generated labels as well, default is 'false'.
|
|
313
323
|
* @returns Sigil labels registered
|
|
314
324
|
*/
|
|
315
|
-
declare function getSigilLabels(
|
|
325
|
+
declare function getSigilLabels(): string[];
|
|
316
326
|
|
|
317
327
|
/**
|
|
318
328
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
@@ -323,8 +333,11 @@ declare function getSigilLabels(includeAuto?: boolean): string[];
|
|
|
323
333
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
324
334
|
* @throws Error if `Base` is already sigilified.
|
|
325
335
|
*/
|
|
326
|
-
declare function Sigilify<
|
|
336
|
+
declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions): {
|
|
327
337
|
new (...args: any[]): {
|
|
338
|
+
[sigil]: {
|
|
339
|
+
Sigil: true;
|
|
340
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
328
341
|
/**
|
|
329
342
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
330
343
|
* calling constructor.
|
|
@@ -337,7 +350,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
337
350
|
* @param other - The object to test.
|
|
338
351
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
339
352
|
*/
|
|
340
|
-
isOfType<
|
|
353
|
+
isOfType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
341
354
|
/**
|
|
342
355
|
* Check whether `other` is exactly the same instance represented by the
|
|
343
356
|
* calling constructor.
|
|
@@ -347,7 +360,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
347
360
|
* @param other - The object to test.
|
|
348
361
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
349
362
|
*/
|
|
350
|
-
isExactType<
|
|
363
|
+
isExactType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
351
364
|
/**
|
|
352
365
|
* Returns the identity sigil label of this instance's constructor.
|
|
353
366
|
*
|
|
@@ -369,24 +382,19 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
369
382
|
/**
|
|
370
383
|
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
371
384
|
*
|
|
385
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
372
386
|
* @returns readonly array of labels representing the type lineage.
|
|
373
387
|
*/
|
|
374
388
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
375
|
-
/**
|
|
376
|
-
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
377
|
-
*/
|
|
378
|
-
readonly [sigil]: {
|
|
379
|
-
Sigil: true;
|
|
380
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
381
389
|
};
|
|
382
390
|
/**
|
|
383
391
|
* Class-level identity label constant for this sigil constructor.
|
|
384
392
|
*/
|
|
385
|
-
get SigilLabel():
|
|
393
|
+
get SigilLabel(): string;
|
|
386
394
|
/**
|
|
387
395
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
388
396
|
*/
|
|
389
|
-
get SigilEffectiveLabel():
|
|
397
|
+
get SigilEffectiveLabel(): string;
|
|
390
398
|
/**
|
|
391
399
|
* Linearized sigil type label chain for the current constructor.
|
|
392
400
|
*
|
|
@@ -399,6 +407,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
399
407
|
* Sigil type label set for the current constructor.
|
|
400
408
|
* Useful for debugging.
|
|
401
409
|
*
|
|
410
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
402
411
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
403
412
|
*/
|
|
404
413
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
@@ -414,7 +423,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
414
423
|
* @param other - The object to test.
|
|
415
424
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
416
425
|
*/
|
|
417
|
-
isOfType<T
|
|
426
|
+
isOfType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
418
427
|
/**
|
|
419
428
|
* Check whether `other` is exactly the same instance represented by the
|
|
420
429
|
* calling constructor.
|
|
@@ -424,8 +433,8 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
424
433
|
* @param other - The object to test.
|
|
425
434
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
426
435
|
*/
|
|
427
|
-
isExactType<T
|
|
428
|
-
}
|
|
436
|
+
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
437
|
+
};
|
|
429
438
|
/**
|
|
430
439
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
431
440
|
*
|
|
@@ -435,7 +444,10 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
435
444
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
436
445
|
* @throws Error if `Base` is already sigilified.
|
|
437
446
|
*/
|
|
438
|
-
declare function SigilifyAbstract<
|
|
447
|
+
declare function SigilifyAbstract<L extends string>(Base: ConstructorAbstract, label: L, opts?: SigilOptions): (abstract new (...args: any[]) => {
|
|
448
|
+
[sigil]: {
|
|
449
|
+
Sigil: true;
|
|
450
|
+
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
439
451
|
/**
|
|
440
452
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
453
|
* calling constructor.
|
|
@@ -448,7 +460,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
448
460
|
* @param other - The object to test.
|
|
449
461
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
450
462
|
*/
|
|
451
|
-
isOfType<
|
|
463
|
+
isOfType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
452
464
|
/**
|
|
453
465
|
* Check whether `other` is exactly the same instance represented by the
|
|
454
466
|
* calling constructor.
|
|
@@ -458,7 +470,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
458
470
|
* @param other - The object to test.
|
|
459
471
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
460
472
|
*/
|
|
461
|
-
isExactType<
|
|
473
|
+
isExactType<T_1>(this: T_1, other: unknown): other is T_1;
|
|
462
474
|
/**
|
|
463
475
|
* Returns the identity sigil label of this instance's constructor.
|
|
464
476
|
*
|
|
@@ -480,24 +492,19 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
480
492
|
/**
|
|
481
493
|
* Returns a copy of the sigil type label lineage set for this instance's constructor.
|
|
482
494
|
*
|
|
495
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
483
496
|
* @returns readonly array of labels representing the type lineage.
|
|
484
497
|
*/
|
|
485
498
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
486
|
-
/**
|
|
487
|
-
* Compile-time nominal brand that encodes the class sigil labels object.
|
|
488
|
-
*/
|
|
489
|
-
readonly [sigil]: {
|
|
490
|
-
Sigil: true;
|
|
491
|
-
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
492
499
|
}) & {
|
|
493
500
|
/**
|
|
494
501
|
* Class-level identity label constant for this sigil constructor.
|
|
495
502
|
*/
|
|
496
|
-
get SigilLabel():
|
|
503
|
+
get SigilLabel(): string;
|
|
497
504
|
/**
|
|
498
505
|
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
499
506
|
*/
|
|
500
|
-
get SigilEffectiveLabel():
|
|
507
|
+
get SigilEffectiveLabel(): string;
|
|
501
508
|
/**
|
|
502
509
|
* Linearized sigil type label chain for the current constructor.
|
|
503
510
|
*
|
|
@@ -510,6 +517,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
510
517
|
* Sigil type label set for the current constructor.
|
|
511
518
|
* Useful for debugging.
|
|
512
519
|
*
|
|
520
|
+
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
513
521
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
514
522
|
*/
|
|
515
523
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
@@ -536,6 +544,6 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
536
544
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
537
545
|
*/
|
|
538
546
|
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
539
|
-
}
|
|
547
|
+
};
|
|
540
548
|
|
|
541
|
-
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, RECOMMENDED_LABEL_REGEX, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, getSigilLabels, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|
|
549
|
+
export { AttachSigil, DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, RECOMMENDED_LABEL_REGEX, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, attachSigil, getSigilLabels, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|