@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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.1.1] - 2026-02-23
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `SigilEffectiveLabel`/`getSigilEffectiveLabel()` which are last passed label for logging purposes.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Patched multiple bugs.
|
|
14
|
+
- Updated defualt options, now `SigilOptions.autofillLabels` is `true` by default.
|
|
15
|
+
|
|
16
|
+
## [2.1.0] - 2026-02-22
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Changed name of `updateOptions` to be `updateSigilOptions`
|
|
21
|
+
- Updated JSDOCs of multiple APIs
|
|
22
|
+
|
|
5
23
|
## [2.0.3] - 2026-02-21
|
|
6
24
|
|
|
7
25
|
- Patched types
|
|
@@ -26,19 +44,19 @@ All notable changes to this project will be documented in this file.
|
|
|
26
44
|
|
|
27
45
|
### Breaking changes
|
|
28
46
|
|
|
29
|
-
- All `SigilRegistry`options, methods and classes are removed
|
|
47
|
+
- All `SigilRegistry`options, methods and classes are removed
|
|
30
48
|
|
|
31
49
|
## [1.3.0] - 2026-02-18
|
|
32
50
|
|
|
33
51
|
### Added
|
|
34
52
|
|
|
35
|
-
- `isOfType()` & `isOfTypeStrict()` now can be called from instances
|
|
53
|
+
- `isOfType()` & `isOfTypeStrict()` now can be called from instances
|
|
36
54
|
|
|
37
55
|
## [1.2.7] - 2026-02-13
|
|
38
56
|
|
|
39
57
|
### Added
|
|
40
58
|
|
|
41
|
-
- Support for `abstract` classes using `SigilifyAbstract` factory
|
|
59
|
+
- Support for `abstract` classes using `SigilifyAbstract` factory
|
|
42
60
|
|
|
43
61
|
## [1.2.6] - 2026-02-11
|
|
44
62
|
|
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
> - 🎉 v2.0.0 is out! Happy coding! 😄💻
|
|
6
6
|
> - 📄 **Changelog:** [CHANGELOG.md](./CHANGELOG.md)
|
|
7
7
|
|
|
8
|
-
`Sigil`
|
|
8
|
+
`Sigil` replaces `instanceof` across bundles, enforces nominal class identity, and makes inheritance-aware runtime type checks reliable in large TypeScript systems. It organizes class identities across your codebase and gives you the power of **nominal typing** and **safe cross-bundle class checks** where each class constructor is stored under a unique label.
|
|
9
9
|
|
|
10
10
|
> **Key ideas:**
|
|
11
11
|
>
|
|
12
|
+
> - **Reliable Runtime Checks:** Uses labels instead of instanceof for cross-bundle reliability.
|
|
12
13
|
> - **Nominal Typing at Compile Time:** Distinguishes structurally similar types (e.g., UserId vs. PostId).
|
|
13
|
-
> - **Reliable Runtime Checks:** Uses symbols instead of instanceof for cross-bundle reliability.
|
|
14
14
|
> - **Inheritance Awareness:** Tracks lineages for subtype/supertype checks.
|
|
15
15
|
|
|
16
16
|
## Important Notes Before Using
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
## Why Registry is dropped
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
In v2 we simplified the architecture to remove global registries and reduce complexity across packages.
|
|
26
26
|
|
|
27
27
|
---
|
|
28
28
|
|
|
@@ -48,8 +48,9 @@ Although registry added label checks and central class management but it also in
|
|
|
48
48
|
- [API reference](#api-reference)
|
|
49
49
|
- [Options & configuration](#options--configuration)
|
|
50
50
|
- [Minimal mode](#minimal-mode)
|
|
51
|
+
- [Strict mode](#strict-mode)
|
|
52
|
+
- [## Which pattern should I use?](#which-pattern-should-i-use)
|
|
51
53
|
- [Troubleshooting & FAQ](#troubleshooting--faq)
|
|
52
|
-
- [Phantom](#phantom)
|
|
53
54
|
- [Contributing](#contributing)
|
|
54
55
|
- [License](#license)
|
|
55
56
|
- [Author](#author)
|
|
@@ -151,16 +152,9 @@ console.log(User.isOfType(u)); // true
|
|
|
151
152
|
|
|
152
153
|
### Migration
|
|
153
154
|
|
|
154
|
-
Migrating old code into `Sigil` can be done
|
|
155
|
+
Migrating old code into `Sigil` can be done with extra couple lines of code only:
|
|
155
156
|
|
|
156
|
-
1.
|
|
157
|
-
|
|
158
|
-
```ts
|
|
159
|
-
import { updateOptions } from '@vicin/sigil';
|
|
160
|
-
updateOptions({ autofillLabels: true });
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
2. Pass your base class to `Sigilify` mixin:
|
|
157
|
+
1. Pass your base class to `Sigilify` mixin:
|
|
164
158
|
|
|
165
159
|
```ts
|
|
166
160
|
import { Sigilify } from '@vicin/sigil';
|
|
@@ -168,7 +162,7 @@ import { Sigilify } from '@vicin/sigil';
|
|
|
168
162
|
const MySigilBaseClass = Sigilify(MyBaseClass);
|
|
169
163
|
```
|
|
170
164
|
|
|
171
|
-
|
|
165
|
+
2. Or extend it with `Sigil`:
|
|
172
166
|
|
|
173
167
|
```ts
|
|
174
168
|
import { Sigil } from '@vicin/sigil';
|
|
@@ -186,11 +180,9 @@ This section states clearly what `Sigil` provides and what it does **not** provi
|
|
|
186
180
|
|
|
187
181
|
### What Sigil guarantees
|
|
188
182
|
|
|
189
|
-
**1.
|
|
183
|
+
**1. Reliable runtime identity (when used as intended).**
|
|
190
184
|
|
|
191
|
-
**2.
|
|
192
|
-
|
|
193
|
-
**3. Nominal typing that is inheritance-aware**
|
|
185
|
+
**2. Nominal typing that is inheritance-aware**
|
|
194
186
|
|
|
195
187
|
### What Sigil does not guarantee
|
|
196
188
|
|
|
@@ -204,10 +196,10 @@ This section states clearly what `Sigil` provides and what it does **not** provi
|
|
|
204
196
|
|
|
205
197
|
### Terminology
|
|
206
198
|
|
|
207
|
-
- **Label**:
|
|
208
|
-
- **
|
|
209
|
-
- **
|
|
210
|
-
- **
|
|
199
|
+
- **Label**: An identity (string) such as `@scope/pkg.ClassName`, but can be random string (e.g. `@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h`) if no label passed.
|
|
200
|
+
- **EffictiveLabel:** A human-readable (string) such as `@scope/pkg.ClassName`, if no label is passed it inherit the last defined label.
|
|
201
|
+
- **Label lineage**: Array of labels for ancestry.
|
|
202
|
+
- **Label set**: Set of labels for fast checks.
|
|
211
203
|
- **Brand**: TypeScript marker (`__SIGIL_BRAND__`) for nominal types.
|
|
212
204
|
|
|
213
205
|
---
|
|
@@ -217,6 +209,15 @@ This section states clearly what `Sigil` provides and what it does **not** provi
|
|
|
217
209
|
Sigil addresses issues in large monorepos and Domain-Driven Design (DDD):
|
|
218
210
|
|
|
219
211
|
- **Unreliable `instanceof`:** Bundling and HMR cause class redefinitions, breaking checks.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
// Broken in monorepo or HMR
|
|
215
|
+
if (obj instanceof User) { ... }
|
|
216
|
+
|
|
217
|
+
// With Sigil
|
|
218
|
+
if (User.isOfType(obj)) { ... } // This still works even if User was bundled twice.
|
|
219
|
+
```
|
|
220
|
+
|
|
220
221
|
- **Manual Branding Overhead:** Custom identifiers lead to boilerplate and maintenance issues.
|
|
221
222
|
|
|
222
223
|
`Sigil` abstracts these into a **centralized system**, making identity management **explicit** and **error-resistant** if defined the right way.
|
|
@@ -225,7 +226,7 @@ Sigil addresses issues in large monorepos and Domain-Driven Design (DDD):
|
|
|
225
226
|
|
|
226
227
|
- **Runtime Contract:** Established via extending `Sigil` or using `Sigilify` mixin.
|
|
227
228
|
- **Update metadata:** With each new child, HOF or decorators are used to attach metadata and update nominal type.
|
|
228
|
-
- **Accessors & Type guards:** Classes expose `SigilLabel
|
|
229
|
+
- **Accessors & Type guards:** Classes expose `SigilLabel`; instances provide `getSigilLabel()` for querying unique identifier label. also when typed it hold nominal identity used to prevent subtle bugs.
|
|
229
230
|
|
|
230
231
|
```ts
|
|
231
232
|
import { Sigil, withSigilTyped, GetInstance } from '@vicin/sigil';
|
|
@@ -239,9 +240,9 @@ type MyClass = GetInstance<typeof MyClass>;
|
|
|
239
240
|
|
|
240
241
|
// Accessors & Type guards
|
|
241
242
|
console.log(MyClass.SigilLabel); // '@scope/package.MyClass'
|
|
242
|
-
console.log(new MyClass().
|
|
243
|
+
console.log(new MyClass().getSigilLabel()); // '@scope/package.MyClass'
|
|
243
244
|
console.log(MyClass.isOfType(new MyClass())); // true
|
|
244
|
-
function x(c: MyClass) {} // Only instances
|
|
245
|
+
function x(c: MyClass) {} // Only instances of 'MyClass' can be passed
|
|
245
246
|
```
|
|
246
247
|
|
|
247
248
|
---
|
|
@@ -315,7 +316,7 @@ type Y = GetInstance<typeof Y>;
|
|
|
315
316
|
const y = new Y(); // <-- Type here is any
|
|
316
317
|
```
|
|
317
318
|
|
|
318
|
-
|
|
319
|
+
This is a known TypeScript limitation.
|
|
319
320
|
|
|
320
321
|
---
|
|
321
322
|
|
|
@@ -384,7 +385,7 @@ class X extends Sigil {
|
|
|
384
385
|
- `isInheritanceChecked(ctor)`
|
|
385
386
|
|
|
386
387
|
- **Options:**
|
|
387
|
-
- `
|
|
388
|
+
- `updateSigilOptions(opts)`
|
|
388
389
|
- `DEFAULT_LABEL_REGEX`
|
|
389
390
|
|
|
390
391
|
- **Types:**
|
|
@@ -407,14 +408,15 @@ class X extends Sigil {
|
|
|
407
408
|
- `withSigilTyped(Class, label?, opts?)`: like `withSigil` but narrows the TypeScript type to include brands.
|
|
408
409
|
- `isSigilCtor(value)`: `true` if `value` is a `Sigil` constructor.
|
|
409
410
|
- `isSigilInstance(value)`: `true` if `value` is an instance of a `Sigil` constructor.
|
|
410
|
-
- `
|
|
411
|
+
- `updateSigilOptions(opts)`: change global runtime options before `Sigil` decoration (e.g., `autofillLabels`).
|
|
411
412
|
- `DEFAULT_LABEL_REGEX`: regex that ensures structure of `@scope/package.ClassName` to all labels, it's advised to use it as your `SigilOptions.labelValidation`
|
|
412
413
|
|
|
413
414
|
### Instance & static helpers provided by Sigilified constructors
|
|
414
415
|
|
|
415
416
|
When a constructor is decorated/sigilified it will expose the following **static** getters/methods:
|
|
416
417
|
|
|
417
|
-
- `SigilLabel` — the
|
|
418
|
+
- `SigilLabel` — the identity label string.
|
|
419
|
+
- `SigilEffectiveLabel` — the human label string.
|
|
418
420
|
- `SigilLabelLineage` — readonly array of labels representing parent → child.
|
|
419
421
|
- `SigilLabelSet` — readonly `Set<string>` for O(1) checks.
|
|
420
422
|
- `isSigilified(obj)` — runtime predicate that delegates to `isSigilInstance`.
|
|
@@ -423,10 +425,10 @@ When a constructor is decorated/sigilified it will expose the following **static
|
|
|
423
425
|
|
|
424
426
|
Instances of sigilified classes expose instance helpers:
|
|
425
427
|
|
|
426
|
-
- `getSigilLabel()` — returns the
|
|
427
|
-
- `
|
|
428
|
-
- `
|
|
429
|
-
- `
|
|
428
|
+
- `getSigilLabel()` — returns the identity label.
|
|
429
|
+
- `getSigilEffectiveLabel()` — returns the human label.
|
|
430
|
+
- `getSigilLabelLineage()` — returns lineage array.
|
|
431
|
+
- `getSigilLabelSet()` — returns readonly Set.
|
|
430
432
|
- `isOfType(other)` — O(1) membership test using `other`'s `__LABEL_SET__`.
|
|
431
433
|
- `isOfTypeStrict(other)` — strict lineage comparison element-by-element.
|
|
432
434
|
|
|
@@ -437,11 +439,11 @@ Instances of sigilified classes expose instance helpers:
|
|
|
437
439
|
Customize behavior globally at startup:
|
|
438
440
|
|
|
439
441
|
```ts
|
|
440
|
-
import {
|
|
442
|
+
import { updateSigilOptions } from '@vicin/sigil';
|
|
441
443
|
|
|
442
|
-
|
|
443
|
-
autofillLabels:
|
|
444
|
-
skipLabelInheritanceCheck: false, // Bypass dev inheritance checks -- ALMOST NEVER WANT TO SET THIS TO TRUE
|
|
444
|
+
updateSigilOptions({
|
|
445
|
+
autofillLabels: true, // Automatically label unlabeled subclasses
|
|
446
|
+
skipLabelInheritanceCheck: false, // Bypass dev inheritance checks -- ALMOST NEVER WANT TO SET THIS TO TRUE
|
|
445
447
|
labelValidation: null, // Function or regex, Enforce label format
|
|
446
448
|
});
|
|
447
449
|
```
|
|
@@ -452,13 +454,10 @@ Values defined in previous example are defaults, per-class overrides available i
|
|
|
452
454
|
|
|
453
455
|
## Minimal mode
|
|
454
456
|
|
|
455
|
-
|
|
457
|
+
You can ignore all decorators and HOFs and just make base class extend `Sigil`:
|
|
456
458
|
|
|
457
459
|
```ts
|
|
458
|
-
import { Sigil,
|
|
459
|
-
|
|
460
|
-
// run at the start of the app
|
|
461
|
-
updateOptions({ autofillLabels: true });
|
|
460
|
+
import { Sigil, updateSigilOptions } from '@vicin/sigil';
|
|
462
461
|
|
|
463
462
|
// No decorators or HOF needed to use 'isOfType' ('instanceof' replacement)
|
|
464
463
|
class A extends Sigil {}
|
|
@@ -466,24 +465,34 @@ class B extends A {}
|
|
|
466
465
|
class C extends B {}
|
|
467
466
|
```
|
|
468
467
|
|
|
469
|
-
|
|
468
|
+
## Strict mode
|
|
470
469
|
|
|
471
|
-
|
|
470
|
+
If you want to inforce passing a label to every class defined in your codebase, you can set `autofillLabels` to `false` at the start of app:
|
|
472
471
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
472
|
+
```ts
|
|
473
|
+
import { updateSigilOptions } from '@vicin/sigil';
|
|
474
|
+
|
|
475
|
+
updateSigilOptions({ autofillLabels: false });
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
Now if you forgot to pass a label error is thrown.
|
|
476
479
|
|
|
477
480
|
---
|
|
478
481
|
|
|
479
|
-
##
|
|
482
|
+
## Which pattern should I use?
|
|
480
483
|
|
|
481
|
-
|
|
484
|
+
- Want simplest setup? → Extend `Sigil`
|
|
485
|
+
- Want full nominal typing? → Use HOF pattern
|
|
486
|
+
- Want clean class bodies? → Use HOF
|
|
487
|
+
- Want fewer wrapper exports? → Use Decorators
|
|
482
488
|
|
|
483
|
-
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## Troubleshooting & FAQ
|
|
484
492
|
|
|
485
|
-
- **
|
|
486
|
-
- **
|
|
493
|
+
- **Dev Extension Errors:** Add labels or enable autofillLabels.
|
|
494
|
+
- **Anonymous Class Errors:** Export untyped bases.
|
|
495
|
+
- **Selective Labeling:** Use `autofillLabels: true` or empty `@WithSigil()` for auto-generation.
|
|
487
496
|
|
|
488
497
|
---
|
|
489
498
|
|
package/dist/index.d.mts
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 };
|