@vicin/sigil 2.0.3 → 2.2.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 +21 -3
- package/README.md +61 -52
- package/dist/index.d.mts +45 -64
- package/dist/index.d.ts +45 -64
- package/dist/index.global.js +134 -72
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +134 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* ----------------------------------------- */
|
|
4
4
|
/**
|
|
5
5
|
* Static-side interface describing methods and properties added to a class
|
|
6
|
-
* constructor when it is
|
|
6
|
+
* constructor when it is sigilified.
|
|
7
7
|
*
|
|
8
8
|
* The properties and methods described here mirror the getters and static
|
|
9
9
|
* predicates implemented by the `Sigilify` mixin.
|
|
@@ -22,8 +22,10 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
|
|
|
22
22
|
readonly __SIGIL_BRAND__: Prettify<{
|
|
23
23
|
[k in L]: true;
|
|
24
24
|
} & SigilBrandOf<P>>;
|
|
25
|
-
/** Class-level label constant (
|
|
25
|
+
/** Class-level label constant (identity). */
|
|
26
26
|
readonly SigilLabel: string;
|
|
27
|
+
/** Class-level label constant (human readable). */
|
|
28
|
+
readonly SigilEffectiveLabel: string;
|
|
27
29
|
/**
|
|
28
30
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
29
31
|
* Useful for debugging and strict lineage comparisons.
|
|
@@ -91,8 +93,10 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
91
93
|
readonly __SIGIL_BRAND__: Prettify<{
|
|
92
94
|
[k in L]: true;
|
|
93
95
|
} & SigilBrandOf<P>>;
|
|
94
|
-
/** Returns
|
|
96
|
+
/** Returns identity sigil label of the class constructor. */
|
|
95
97
|
getSigilLabel(): string;
|
|
98
|
+
/** Returns human-readable sigil label of the class constructor. */
|
|
99
|
+
getSigilEffectiveLabel(): string;
|
|
96
100
|
/** Returns copy of sigil type label lineage of the class constructor. */
|
|
97
101
|
getSigilLabelLineage(): readonly string[];
|
|
98
102
|
/** Returns copy of sigil type label set of the class constructor. */
|
|
@@ -228,6 +232,7 @@ declare const Sigil: {
|
|
|
228
232
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
229
233
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
230
234
|
getSigilLabel(): string;
|
|
235
|
+
getSigilEffectiveLabel(): string;
|
|
231
236
|
getSigilLabelLineage(): readonly string[];
|
|
232
237
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
233
238
|
};
|
|
@@ -235,6 +240,7 @@ declare const Sigil: {
|
|
|
235
240
|
Sigil: true;
|
|
236
241
|
};
|
|
237
242
|
get SigilLabel(): string;
|
|
243
|
+
get SigilEffectiveLabel(): string;
|
|
238
244
|
get SigilLabelLineage(): readonly string[];
|
|
239
245
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
240
246
|
isSigilified(obj: unknown): obj is ISigil;
|
|
@@ -260,6 +266,7 @@ declare const SigilError: {
|
|
|
260
266
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
261
267
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
262
268
|
getSigilLabel(): string;
|
|
269
|
+
getSigilEffectiveLabel(): string;
|
|
263
270
|
getSigilLabelLineage(): readonly string[];
|
|
264
271
|
getSigilLabelSet(): Readonly<Set<string>>;
|
|
265
272
|
};
|
|
@@ -268,6 +275,7 @@ declare const SigilError: {
|
|
|
268
275
|
SigilError: true;
|
|
269
276
|
};
|
|
270
277
|
get SigilLabel(): string;
|
|
278
|
+
get SigilEffectiveLabel(): string;
|
|
271
279
|
get SigilLabelLineage(): readonly string[];
|
|
272
280
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
273
281
|
isSigilified(obj: unknown): obj is ISigil;
|
|
@@ -322,7 +330,7 @@ interface SigilOptions {
|
|
|
322
330
|
*
|
|
323
331
|
* @param opts - Partial options to merge into the global `OPTIONS` object.
|
|
324
332
|
*/
|
|
325
|
-
declare const
|
|
333
|
+
declare const updateSigilOptions: (opts: SigilOptions) => void;
|
|
326
334
|
/** -----------------------------------------
|
|
327
335
|
* Label validation
|
|
328
336
|
* ----------------------------------------- */
|
|
@@ -338,21 +346,10 @@ declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
|
338
346
|
/**
|
|
339
347
|
* Class decorator factory that attaches sigil statics to a class constructor.
|
|
340
348
|
*
|
|
341
|
-
* Usage:
|
|
342
|
-
* ```ts
|
|
343
|
-
* @WithSigil('@myorg/mypkg.MyClass')
|
|
344
|
-
* class MyClass { ... }
|
|
345
|
-
* ```
|
|
346
|
-
*
|
|
347
|
-
* The returned decorator:
|
|
348
|
-
* - validates the provided label (via `verifyLabel`)
|
|
349
|
-
* - performs inheritance checks (via `checkInheritance`) in DEV builds
|
|
350
|
-
* - attaches sigil-related statics to the constructor (via `decorateCtor`)
|
|
351
|
-
*
|
|
352
349
|
* Notes:
|
|
353
350
|
* - This decorator is intended to be applied to classes only. When used
|
|
354
351
|
* incorrectly (e.g. on a property), it is a no-op.
|
|
355
|
-
* - Throws an error during class creation if the label validation fails.
|
|
352
|
+
* - Throws an error during class creation if the label validation fails (in development only).
|
|
356
353
|
*
|
|
357
354
|
* @typeParam L - Narrow string literal type for the provided label.
|
|
358
355
|
* @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
|
|
@@ -366,13 +363,6 @@ declare function WithSigil<L extends string>(label?: L, opts?: SigilOptions): (v
|
|
|
366
363
|
* HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
|
|
367
364
|
* Alternative to '@WithSigil' if you prefer HOFs.
|
|
368
365
|
*
|
|
369
|
-
* This does both:
|
|
370
|
-
* - validate (and autofill) a label,
|
|
371
|
-
* - perform runtime decoration (via `decorateCtor`),
|
|
372
|
-
*
|
|
373
|
-
* The helper is idempotent: `decorateCtor` will register the label and throw if already
|
|
374
|
-
* decorated; we handle this gracefully in DEV to support HMR flows.
|
|
375
|
-
*
|
|
376
366
|
* @typeParam S - Constructor type (should be an ISigil).
|
|
377
367
|
* @typeParam L - Label literal to attach.
|
|
378
368
|
* @param Class - The constructor (class) to enhance.
|
|
@@ -382,15 +372,7 @@ declare function WithSigil<L extends string>(label?: L, opts?: SigilOptions): (v
|
|
|
382
372
|
*/
|
|
383
373
|
declare function withSigil<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): S;
|
|
384
374
|
/**
|
|
385
|
-
* Convenience helper that combine 'withSigil' and '
|
|
386
|
-
*
|
|
387
|
-
* This does both:
|
|
388
|
-
* - validate (and autofill) a label,
|
|
389
|
-
* - perform runtime decoration (via `decorateCtor`),
|
|
390
|
-
* - return the constructor typed as `TypedSigil`.
|
|
391
|
-
*
|
|
392
|
-
* The helper is idempotent: `decorateCtor` will register the label and throw if already
|
|
393
|
-
* decorated; we handle this gracefully in DEV to support HMR flows.
|
|
375
|
+
* Convenience helper that combine 'withSigil' and update 'SigilBrand'.
|
|
394
376
|
*
|
|
395
377
|
* @typeParam S - Constructor type (should be an ISigil).
|
|
396
378
|
* @typeParam L - Label literal to attach.
|
|
@@ -405,9 +387,6 @@ declare function withSigilTyped<S extends Function, L extends string = string>(C
|
|
|
405
387
|
/**
|
|
406
388
|
* Runtime predicate that checks whether the provided value is a sigil constructor.
|
|
407
389
|
*
|
|
408
|
-
* This is a lightweight check that verifies the presence of an internal
|
|
409
|
-
* symbol attached to the constructor.
|
|
410
|
-
*
|
|
411
390
|
* @param ctor - Constructor to test.
|
|
412
391
|
* @returns `true` if `value` is a sigil constructor, otherwise `false`.
|
|
413
392
|
*/
|
|
@@ -423,8 +402,6 @@ declare function isSigilInstance(inst: unknown): inst is GetInstance<ISigil>;
|
|
|
423
402
|
/**
|
|
424
403
|
* Check whether the provided constructor was marked as a sigil base constructor.
|
|
425
404
|
*
|
|
426
|
-
* Uses `Object.hasOwn` to ensure we only check own properties.
|
|
427
|
-
*
|
|
428
405
|
* @param ctor - Constructor to check.
|
|
429
406
|
* @returns `true` if `ctor` is a sigil base constructor.
|
|
430
407
|
*/
|
|
@@ -432,8 +409,6 @@ declare function isSigilBaseCtor(ctor: Function): ctor is ISigil;
|
|
|
432
409
|
/**
|
|
433
410
|
* Check whether the provided object is an instance of a sigil base constructor.
|
|
434
411
|
*
|
|
435
|
-
* This resolves the instance's constructor and delegates to `isSigilBaseCtor`.
|
|
436
|
-
*
|
|
437
412
|
* @param inst - The instance to test.
|
|
438
413
|
* @returns `true` if `inst` is an instance of a sigil base constructor.
|
|
439
414
|
*/
|
|
@@ -441,8 +416,6 @@ declare function isSigilBaseInstance(inst: unknown): inst is GetInstance<ISigil>
|
|
|
441
416
|
/**
|
|
442
417
|
* Returns whether the constructor has been explicitly decorated with `WithSigil`.
|
|
443
418
|
*
|
|
444
|
-
* This is an own-property check and does not traverse the prototype chain.
|
|
445
|
-
*
|
|
446
419
|
* @internal
|
|
447
420
|
* @param ctor - Constructor to test.
|
|
448
421
|
* @returns `true` if the constructor is explicitly decorated.
|
|
@@ -451,8 +424,6 @@ declare function isDecorated(ctor: Function): boolean;
|
|
|
451
424
|
/**
|
|
452
425
|
* Returns whether inheritance checks have already been performed for the constructor.
|
|
453
426
|
*
|
|
454
|
-
* This is used to avoid repeated checks during development (DEV-only checks).
|
|
455
|
-
*
|
|
456
427
|
* @internal
|
|
457
428
|
* @param ctor - Constructor to test.
|
|
458
429
|
* @returns `true` if inheritance checks were marked as completed.
|
|
@@ -460,19 +431,14 @@ declare function isDecorated(ctor: Function): boolean;
|
|
|
460
431
|
declare function isInheritanceChecked(ctor: Function): boolean;
|
|
461
432
|
|
|
462
433
|
/**
|
|
463
|
-
* Mixin factory that augments an existing class with Sigil runtime metadata and
|
|
464
|
-
* helpers.
|
|
465
|
-
*
|
|
466
|
-
* The returned class:
|
|
467
|
-
* - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
|
|
468
|
-
* - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
|
|
434
|
+
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
469
435
|
*
|
|
470
436
|
* @param Base - The base constructor to extend.
|
|
471
437
|
* @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
472
438
|
* If not passed a random label is generated instead.
|
|
473
439
|
* @param opts - Options object to override any global options if needed.
|
|
474
440
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
475
|
-
* @throws Error if `Base` is already
|
|
441
|
+
* @throws Error if `Base` is already sigilified.
|
|
476
442
|
*/
|
|
477
443
|
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label?: L, opts?: SigilOptions): {
|
|
478
444
|
new (...args: any[]): {
|
|
@@ -509,11 +475,17 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
509
475
|
*/
|
|
510
476
|
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
511
477
|
/**
|
|
512
|
-
* Returns the
|
|
478
|
+
* Returns the identity sigil label of this instance's constructor.
|
|
513
479
|
*
|
|
514
|
-
* @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown'
|
|
480
|
+
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
|
|
515
481
|
*/
|
|
516
482
|
getSigilLabel(): string;
|
|
483
|
+
/**
|
|
484
|
+
* Returns the human-readable sigil label of this instance's constructor.
|
|
485
|
+
*
|
|
486
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
|
|
487
|
+
*/
|
|
488
|
+
getSigilEffectiveLabel(): string;
|
|
517
489
|
/**
|
|
518
490
|
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
519
491
|
*
|
|
@@ -538,9 +510,13 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
538
510
|
Sigil: true;
|
|
539
511
|
} & { [K in L]: true; }>;
|
|
540
512
|
/**
|
|
541
|
-
* Class-level
|
|
513
|
+
* Class-level identity label constant for this sigil constructor.
|
|
542
514
|
*/
|
|
543
515
|
get SigilLabel(): string;
|
|
516
|
+
/**
|
|
517
|
+
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
518
|
+
*/
|
|
519
|
+
get SigilEffectiveLabel(): string;
|
|
544
520
|
/**
|
|
545
521
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
546
522
|
*
|
|
@@ -587,19 +563,14 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
587
563
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
588
564
|
} & B;
|
|
589
565
|
/**
|
|
590
|
-
* Mixin factory that augments an existing class with Sigil runtime metadata and
|
|
591
|
-
* helpers. Accept and return 'abstract' class.
|
|
592
|
-
*
|
|
593
|
-
* The returned class:
|
|
594
|
-
* - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
|
|
595
|
-
* - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
|
|
566
|
+
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
596
567
|
*
|
|
597
568
|
* @param Base - The base constructor to extend.
|
|
598
569
|
* @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
599
570
|
* If not passed a random label is generated instead.
|
|
600
571
|
* @param opts - Options object to override any global options if needed.
|
|
601
572
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
602
|
-
* @throws Error if `Base` is already
|
|
573
|
+
* @throws Error if `Base` is already sigilified.
|
|
603
574
|
*/
|
|
604
575
|
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label?: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
605
576
|
/**
|
|
@@ -635,11 +606,17 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
635
606
|
*/
|
|
636
607
|
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
637
608
|
/**
|
|
638
|
-
* Returns the
|
|
609
|
+
* Returns the identity sigil label of this instance's constructor.
|
|
639
610
|
*
|
|
640
|
-
* @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown'
|
|
611
|
+
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
|
|
641
612
|
*/
|
|
642
613
|
getSigilLabel(): string;
|
|
614
|
+
/**
|
|
615
|
+
* Returns the human-readable sigil label of this instance's constructor.
|
|
616
|
+
*
|
|
617
|
+
* @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
|
|
618
|
+
*/
|
|
619
|
+
getSigilEffectiveLabel(): string;
|
|
643
620
|
/**
|
|
644
621
|
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
645
622
|
*
|
|
@@ -664,9 +641,13 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
664
641
|
Sigil: true;
|
|
665
642
|
} & { [K in L]: true; }>;
|
|
666
643
|
/**
|
|
667
|
-
* Class-level
|
|
644
|
+
* Class-level identity label constant for this sigil constructor.
|
|
668
645
|
*/
|
|
669
646
|
get SigilLabel(): string;
|
|
647
|
+
/**
|
|
648
|
+
* Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
|
|
649
|
+
*/
|
|
650
|
+
get SigilEffectiveLabel(): string;
|
|
670
651
|
/**
|
|
671
652
|
* Copy of the linearized sigil type label chain for the current constructor.
|
|
672
653
|
*
|
|
@@ -721,4 +702,4 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
721
702
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
722
703
|
}) & B;
|
|
723
704
|
|
|
724
|
-
export { DEFAULT_LABEL_REGEX, type GetInstance, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, type SigilBrandOf, SigilError, type SigilOptions, Sigilify, SigilifyAbstract, type TypedSigil, type UpdateSigilBrand, WithSigil, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance,
|
|
705
|
+
export { DEFAULT_LABEL_REGEX, type GetInstance, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, type SigilBrandOf, SigilError, type SigilOptions, Sigilify, SigilifyAbstract, type TypedSigil, type UpdateSigilBrand, WithSigil, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, updateSigilOptions, withSigil, withSigilTyped };
|