@vicin/sigil 3.1.0 → 3.1.3
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 +26 -0
- package/README.md +88 -40
- package/dist/index.d.mts +10 -32
- package/dist/index.d.ts +10 -32
- package/dist/index.global.js +32 -60
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +32 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [3.1.3] - 2026-02-26
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Patched type tests where `sigil` should be imported as type only
|
|
10
|
+
|
|
11
|
+
## [3.1.2] - 2026-02-26
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Patched README.md
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `GetPrototype<T>` helper to get type of class instance in `protected` or `private` classes
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
|
|
23
|
+
- `isSigilified` method in `Sigil` class as it's redundant and separate check function is present
|
|
24
|
+
|
|
25
|
+
## [3.1.1] - 2026-02-25
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Updated README.md
|
|
30
|
+
|
|
5
31
|
## [3.1.0] - 2026-02-25
|
|
6
32
|
|
|
7
33
|
### Added
|
package/README.md
CHANGED
|
@@ -5,28 +5,26 @@
|
|
|
5
5
|
> - 🎉 v3.0.0 is out! Happy coding! 😄💻
|
|
6
6
|
> - 📄 **Changelog:** [CHANGELOG.md](./CHANGELOG.md)
|
|
7
7
|
|
|
8
|
-
`Sigil`
|
|
8
|
+
`Sigil` gives you the power of **safe cross-bundle class instances checks** and **simple class nominal typing** if needed.
|
|
9
9
|
|
|
10
10
|
> **Key ideas:**
|
|
11
11
|
>
|
|
12
|
-
> - **Reliable Runtime Checks:** Uses
|
|
12
|
+
> - **Reliable Runtime Checks:** Uses `isOfType` instead of `instanceof` for cross-bundle reliability.
|
|
13
13
|
> - **Nominal Typing at Compile Time:** Distinguishes structurally similar types (e.g., UserId vs. PostId).
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ✅ **Drop-in `instanceof` replacement** that works across bundles, HMR, and monorepos, Also can check for **exact class instance**
|
|
18
|
+
- ✅ **Simple nominal typing** with just one line of code for each class
|
|
19
|
+
- ✅ **Tiny less than 1.5 KB minified and brotlied** measured using [size-limit](https://www.npmjs.com/package/size-limit)
|
|
20
|
+
- ✅ **Performant as native instanceof** but with guaranteed checks
|
|
21
|
+
- ✅ **Test coverage is 100%** to ensure that runtime remains consistent and predictable
|
|
15
22
|
|
|
16
23
|
## Important Notes Before Using
|
|
17
24
|
|
|
18
25
|
- **Explicit class identity:** `Sigil` uses passed class label to identify classes, which means that the developer is responsible for uniqueness of classes by passing unique labels.
|
|
19
26
|
- **Simple instanceof Fix:** If you just need runtime checks without extras, see the [minimal mode](#minimal-mode).
|
|
20
27
|
|
|
21
|
-
## Features
|
|
22
|
-
|
|
23
|
-
- ✅ **Drop-in `instanceof` replacement** that works across bundles, HMR, and monorepos
|
|
24
|
-
- ✅ **True nominal typing** with zero runtime cost
|
|
25
|
-
- ✅ **Inheritance-aware** checks (`isOfType` knows about subclasses)
|
|
26
|
-
- ✅ **Tiny less than 1.5 KB minified and brotlied** measured using size-limit
|
|
27
|
-
- ✅ **Performant as native instanceof** but with guaranteed checks! Also can check for **exact class instance**
|
|
28
|
-
- ✅ Full TypeScript 5.0+ support + excellent JSDoc
|
|
29
|
-
|
|
30
28
|
---
|
|
31
29
|
|
|
32
30
|
## Table of contents
|
|
@@ -47,6 +45,8 @@
|
|
|
47
45
|
- [Minimal mode](#minimal-mode)
|
|
48
46
|
- [Strict mode](#strict-mode)
|
|
49
47
|
- [Benchmarks](#benchmarks)
|
|
48
|
+
- [Bundle Size](#bundle-size)
|
|
49
|
+
- [Tests](#tests)
|
|
50
50
|
- [Contributing](#contributing)
|
|
51
51
|
- [License](#license)
|
|
52
52
|
- [Author](#author)
|
|
@@ -154,8 +154,8 @@ Congratulations — you’ve opted into `Sigil` and you can start replacing `ins
|
|
|
154
154
|
|
|
155
155
|
- **Label**: An identity (string) such as `@scope/pkg.ClassName`, but can be random string (e.g. `@Sigil-auto:ClassName:mm2gkdwn:0:g1sq`) if no label passed.
|
|
156
156
|
- **EffectiveLabel:** A human-readable (string) such as `@scope/pkg.ClassName`, if no label is passed it inherit the last defined label.
|
|
157
|
-
- **
|
|
158
|
-
- **
|
|
157
|
+
- **isOfType**: Takes object argument and check if this object is an instance of calling class or it's children. Can be called from class instances as well.
|
|
158
|
+
- **isExactType**: Takes object argument and check if this object is an instance of calling class only. Can be called from class instances as well.
|
|
159
159
|
- **[sigil]**: TypeScript symbol marker for nominal types.
|
|
160
160
|
|
|
161
161
|
---
|
|
@@ -188,7 +188,7 @@ type test1 = User extends Sigil ? true : false; // true
|
|
|
188
188
|
type test2 = Sigil extends User ? true : false; // false
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
`Sigil`
|
|
191
|
+
`Sigil` makes identity management **explicit** and **error-resistant** if defined the right way.
|
|
192
192
|
|
|
193
193
|
### Implementation Mechanics
|
|
194
194
|
|
|
@@ -200,7 +200,7 @@ import { Sigil, WithSigil, sigil, ExtendSigil } from '@vicin/sigil';
|
|
|
200
200
|
|
|
201
201
|
@WithSigil('@scope/package.MyClass') // <-- Run-time values update
|
|
202
202
|
class MyClass extends Sigil {
|
|
203
|
-
declare [sigil]: ExtendSigil<'
|
|
203
|
+
declare [sigil]: ExtendSigil<'MyClass', Sigil>; // <-- compile-time type update
|
|
204
204
|
}
|
|
205
205
|
```
|
|
206
206
|
|
|
@@ -210,14 +210,14 @@ You can avoid decorators and use HOF but they are slightly more verbose:
|
|
|
210
210
|
import { Sigil, withSigil, sigil, ExtendSigil } from '@vicin/sigil';
|
|
211
211
|
|
|
212
212
|
class _MyClass extends Sigil {
|
|
213
|
-
declare [sigil]: ExtendSigil<'
|
|
213
|
+
declare [sigil]: ExtendSigil<'MyClass', Sigil>;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
const MyClass = withSigil(_MyClass, '@scope/package.MyClass');
|
|
217
217
|
type MyClass = InstanceType<typeof MyClass>;
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
Note that you can't use `InstanceType` on `private` or `protected` classes.
|
|
220
|
+
Note that you can't use `InstanceType` on `private` or `protected` classes, however you can use `GetPrototype<T>` in such cases.
|
|
221
221
|
|
|
222
222
|
### Inheritance example
|
|
223
223
|
|
|
@@ -226,12 +226,12 @@ import { Sigil, WithSigil } from '@vicin/sigil';
|
|
|
226
226
|
|
|
227
227
|
@WithSigil('@myorg/User')
|
|
228
228
|
class User extends Sigil {
|
|
229
|
-
declare [sigil]: ExtendSigil<'
|
|
229
|
+
declare [sigil]: ExtendSigil<'User', Sigil>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
@WithSigil('@myorg/Admin')
|
|
233
233
|
class Admin extends User {
|
|
234
|
-
declare [sigil]: ExtendSigil<'
|
|
234
|
+
declare [sigil]: ExtendSigil<'Admin', User>;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
const admin = new Admin();
|
|
@@ -260,8 +260,8 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
260
260
|
### Primary Exports
|
|
261
261
|
|
|
262
262
|
- **Mixins:**
|
|
263
|
-
- `Sigilify(Base, label
|
|
264
|
-
- `SigilifyAbstract(Base, label
|
|
263
|
+
- `Sigilify(Base, label, opts?)`
|
|
264
|
+
- `SigilifyAbstract(Base, label, opts?)`
|
|
265
265
|
|
|
266
266
|
- **Classes:**
|
|
267
267
|
- `Sigil`
|
|
@@ -271,15 +271,11 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
271
271
|
- `WithSigil(label, opts?)`
|
|
272
272
|
|
|
273
273
|
- **HOFs:**
|
|
274
|
-
- `withSigil(Class, label
|
|
274
|
+
- `withSigil(Class, label, opts?)`
|
|
275
275
|
|
|
276
276
|
- **Helpers:**
|
|
277
277
|
- `isSigilCtor(ctor)`
|
|
278
278
|
- `isSigilInstance(inst)`
|
|
279
|
-
- `isSigilBaseCtor(ctor)`
|
|
280
|
-
- `isSigilBaseInstance(inst)`
|
|
281
|
-
- `isDecorated(ctor)`
|
|
282
|
-
- `isInheritanceChecked(ctor)`
|
|
283
279
|
|
|
284
280
|
- **Options:**
|
|
285
281
|
- `updateSigilOptions(opts)`
|
|
@@ -291,18 +287,20 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
291
287
|
- `ISigilInstance<Label, ParentSigil?>`
|
|
292
288
|
- `SigilOf<T>`
|
|
293
289
|
- `ExtendSigil<Label, Parent>`
|
|
290
|
+
- `GetPrototype<Class>`
|
|
294
291
|
- `SigilOptions`
|
|
295
292
|
|
|
296
293
|
### Key helpers (runtime)
|
|
297
294
|
|
|
298
295
|
- `Sigil`: a minimal sigilified base class you can extend from.
|
|
299
296
|
- `SigilError`: an `Error` class decorated with a `Sigil` so it can be identified at runtime.
|
|
300
|
-
- `Sigilify(Base, label
|
|
301
|
-
- `
|
|
302
|
-
- `
|
|
297
|
+
- `Sigilify(Base, label, opts?)`: mixin function that returns a new constructor with `Sigil` types and instance helpers.
|
|
298
|
+
- `SigilifyAbstract(Base, label, opts?)`: Same as `Sigilify` but for abstract classes.
|
|
299
|
+
- `WithSigil(label, opts?)`: class decorator that attaches `Sigil` metadata at declaration time.
|
|
300
|
+
- `withSigil(Class, label, opts?)`: HOF that validates and decorates an existing class constructor.
|
|
303
301
|
- `isSigilCtor(value)`: `true` if `value` is a `Sigil` constructor.
|
|
304
302
|
- `isSigilInstance(value)`: `true` if `value` is an instance of a `Sigil` constructor.
|
|
305
|
-
- `updateSigilOptions(opts)`: change global runtime options
|
|
303
|
+
- `updateSigilOptions(opts)`: change global runtime options of `Sigil` library (e.g., `autofillLabels`).
|
|
306
304
|
- `DEFAULT_LABEL_REGEX`: regex that ensures structure of `@scope/package.ClassName` to all labels, it's advised to use it as your `SigilOptions.labelValidation`
|
|
307
305
|
|
|
308
306
|
### Instance & static helpers provided by Sigilified constructors
|
|
@@ -312,8 +310,7 @@ When a constructor is decorated/sigilified it will expose the following **static
|
|
|
312
310
|
- `SigilLabel` — the identity label string.
|
|
313
311
|
- `SigilEffectiveLabel` — the human label string.
|
|
314
312
|
- `SigilLabelLineage` — readonly array of labels representing parent → child for debugging.
|
|
315
|
-
- `SigilLabelSet` — readonly `Set<string>` for debugging.
|
|
316
|
-
- `isSigilified(obj)` — runtime predicate that delegates to `isSigilInstance`.
|
|
313
|
+
- `SigilLabelSet` — readonly `Set<string>` of sigil labels for debugging.
|
|
317
314
|
- `isOfType(other)` — check if other is an instance of this constructor or its children.
|
|
318
315
|
- `isExactType(other) `— check if other is an instance exactly this constructor.
|
|
319
316
|
|
|
@@ -337,7 +334,6 @@ import { updateSigilOptions } from '@vicin/sigil';
|
|
|
337
334
|
|
|
338
335
|
updateSigilOptions({
|
|
339
336
|
autofillLabels: true, // Automatically label unlabeled subclasses
|
|
340
|
-
skipLabelInheritanceCheck: false, // Bypass dev inheritance checks -- ALMOST NEVER WANT TO SET THIS TO TRUE
|
|
341
337
|
labelValidation: null, // Function or regex, Enforce label format
|
|
342
338
|
});
|
|
343
339
|
```
|
|
@@ -369,14 +365,22 @@ import { updateSigilOptions } from '@vicin/sigil';
|
|
|
369
365
|
updateSigilOptions({ autofillLabels: false });
|
|
370
366
|
```
|
|
371
367
|
|
|
372
|
-
Now if you forgot to pass a label error is thrown.
|
|
368
|
+
Now if you forgot to pass a label error is thrown at the moment you create class instance or use any of `Sigil` methods.
|
|
373
369
|
|
|
374
370
|
---
|
|
375
371
|
|
|
376
372
|
## Benchmarks
|
|
377
373
|
|
|
378
374
|
Sigil is built for **real-world performance**. Below are the latest micro-benchmark results (run on **Node.js v20.12.0**).
|
|
379
|
-
|
|
375
|
+
|
|
376
|
+
**Running Tests**
|
|
377
|
+
|
|
378
|
+
To run benchmarks on your machine fetch source code from [github](https://github.com/ZiadTaha62/sigil) then:
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
npm install
|
|
382
|
+
npm run bench
|
|
383
|
+
```
|
|
380
384
|
|
|
381
385
|
### 1. Runtime Type Checking
|
|
382
386
|
|
|
@@ -389,8 +393,7 @@ To run benchmarks on your machine fetch source code from [github](https://github
|
|
|
389
393
|
| 15 | 0.000058 ms | 0.000063 ms | **0.000051 ms** | 0.000069 ms | **0.000053 ms** |
|
|
390
394
|
|
|
391
395
|
> **Key takeaway**:
|
|
392
|
-
> `isOfType` has **practically the same performance as native `instanceof`**, slightly **slower** on static calls and slightly **faster** on the instance side.
|
|
393
|
-
> `isExactType` adds only a tiny negligible cost and remains extremely fast even on deep hierarchies.
|
|
396
|
+
> `isOfType` & `isExactType` has **practically the same performance as native `instanceof`**, slightly **slower** on static calls and slightly **faster** on the instance side.
|
|
394
397
|
|
|
395
398
|
### 2. Class Definition & Instance Creation
|
|
396
399
|
|
|
@@ -411,14 +414,59 @@ To run benchmarks on your machine fetch source code from [github](https://github
|
|
|
411
414
|
> - Class definition is a **one-time cost** at module load time. Even at depth 10 the cost stays well under 1 ms per class.
|
|
412
415
|
> - Instance creation adds a small fixed overhead of ~0.4–0.6 µs per object, which becomes completely negligible as your classes grow in size and complexity.
|
|
413
416
|
|
|
414
|
-
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Bundle Size
|
|
420
|
+
|
|
421
|
+
**Less than 1.5 KB (1.44 KB)** minified + Brotli, including all dependencies
|
|
422
|
+
|
|
423
|
+
**Running Tests**
|
|
424
|
+
|
|
425
|
+
To verify bundle size fetch source code from [github](https://github.com/ZiadTaha62/sigil) then:
|
|
415
426
|
|
|
416
|
-
|
|
427
|
+
```bash
|
|
428
|
+
npm install
|
|
429
|
+
npm run size
|
|
430
|
+
```
|
|
417
431
|
|
|
418
432
|
This makes Sigil one of the smallest full-featured solutions for nominal typing + reliable runtime identity.
|
|
419
433
|
|
|
420
434
|
---
|
|
421
435
|
|
|
436
|
+
## Tests
|
|
437
|
+
|
|
438
|
+
Reliability is a core pillar of `Sigil`. The library is backed by a comprehensive suite of unit tests that cover everything from basic mixins to lazy evaluation.
|
|
439
|
+
|
|
440
|
+
**Coverage Status**
|
|
441
|
+
|
|
442
|
+
We maintain **100%** test coverage across the entire codebase to ensure that runtime metadata remains consistent and predictable.
|
|
443
|
+
|
|
444
|
+
| Metric | Score |
|
|
445
|
+
| ------ | ----- |
|
|
446
|
+
| Stmts | 100% |
|
|
447
|
+
| Branch | 100% |
|
|
448
|
+
| Funcs | 100% |
|
|
449
|
+
| Lines | 100% |
|
|
450
|
+
|
|
451
|
+
**Key Test Areas**
|
|
452
|
+
|
|
453
|
+
- **Mixins, Decorators & HOFs:** Validating `Sigilify`, `WithSigil` and `withSigil` behaviors.
|
|
454
|
+
- **Sigil methods:** Ensuring `Sigil` class methods (e.g. `SigilLabel`, `getSigilLabel`) work as expected.
|
|
455
|
+
- **Lazy Evaluation:** Ensuring metadata is attached before being accessed via `Sigil` methods.
|
|
456
|
+
- **Lineage:** Verifying that `isOfType` and `isExactType` work across complex inheritance chains.
|
|
457
|
+
- **Error Handling:** Strict validation for all errors and throws.
|
|
458
|
+
|
|
459
|
+
**Running Tests**
|
|
460
|
+
|
|
461
|
+
To run the test suite locally and generate a coverage report, fetch source code from [github](https://github.com/ZiadTaha62/sigil) then:
|
|
462
|
+
|
|
463
|
+
```bash
|
|
464
|
+
npm install
|
|
465
|
+
npm run test:unit
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
422
470
|
## Contributing
|
|
423
471
|
|
|
424
472
|
Any contributions you make are **greatly appreciated**.
|
package/dist/index.d.mts
CHANGED
|
@@ -33,14 +33,6 @@ interface ISigilStatic<L extends string = string> {
|
|
|
33
33
|
* Useful for debugging.
|
|
34
34
|
*/
|
|
35
35
|
readonly SigilLabelSet: Readonly<Set<string>>;
|
|
36
|
-
/**
|
|
37
|
-
* Runtime check that determines whether `obj` is an instance produced by a
|
|
38
|
-
* sigil class.
|
|
39
|
-
*
|
|
40
|
-
* @param obj - Value to test.
|
|
41
|
-
* @returns Type guard narrowing `obj` to `ISigilInstance`.
|
|
42
|
-
*/
|
|
43
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
44
36
|
/**
|
|
45
37
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
46
38
|
* calling constructor.
|
|
@@ -160,7 +152,11 @@ type Prettify<T> = {
|
|
|
160
152
|
} & {};
|
|
161
153
|
/** Helper type to replace 'never' with another type */
|
|
162
154
|
type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
163
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Helper type to get prototype of class
|
|
157
|
+
*
|
|
158
|
+
* @template T - Class constructor.
|
|
159
|
+
*/
|
|
164
160
|
type GetPrototype<T> = T extends {
|
|
165
161
|
prototype: infer P;
|
|
166
162
|
} ? P : never;
|
|
@@ -187,7 +183,6 @@ declare const Sigil: {
|
|
|
187
183
|
get SigilEffectiveLabel(): "Sigil";
|
|
188
184
|
get SigilLabelLineage(): readonly string[];
|
|
189
185
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
190
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
191
186
|
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
192
187
|
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
193
188
|
} & {
|
|
@@ -218,7 +213,6 @@ declare const SigilError: {
|
|
|
218
213
|
get SigilEffectiveLabel(): "SigilError";
|
|
219
214
|
get SigilLabelLineage(): readonly string[];
|
|
220
215
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
221
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
222
216
|
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
223
217
|
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
224
218
|
} & ErrorConstructor;
|
|
@@ -309,13 +303,12 @@ declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
|
309
303
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
310
304
|
*
|
|
311
305
|
* @param Base - The base constructor to extend.
|
|
312
|
-
* @param label -
|
|
313
|
-
* If not passed a random label is generated instead.
|
|
306
|
+
* @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
314
307
|
* @param opts - Options object to override any global options if needed.
|
|
315
308
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
316
309
|
* @throws Error if `Base` is already sigilified.
|
|
317
310
|
*/
|
|
318
|
-
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label
|
|
311
|
+
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label: L, opts?: SigilOptions): {
|
|
319
312
|
new (...args: any[]): {
|
|
320
313
|
/**
|
|
321
314
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
@@ -394,13 +387,6 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
394
387
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
395
388
|
*/
|
|
396
389
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
397
|
-
/**
|
|
398
|
-
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
399
|
-
*
|
|
400
|
-
* @param obj - The value to test.
|
|
401
|
-
* @returns `true` if `obj` is a sigil instance.
|
|
402
|
-
*/
|
|
403
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
404
390
|
/**
|
|
405
391
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
406
392
|
* calling constructor.
|
|
@@ -429,13 +415,12 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
429
415
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
430
416
|
*
|
|
431
417
|
* @param Base - The base constructor to extend.
|
|
432
|
-
* @param label -
|
|
433
|
-
* If not passed a random label is generated instead.
|
|
418
|
+
* @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
434
419
|
* @param opts - Options object to override any global options if needed.
|
|
435
420
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
436
421
|
* @throws Error if `Base` is already sigilified.
|
|
437
422
|
*/
|
|
438
|
-
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label
|
|
423
|
+
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
439
424
|
/**
|
|
440
425
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
426
|
* calling constructor.
|
|
@@ -513,13 +498,6 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
513
498
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
514
499
|
*/
|
|
515
500
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
516
|
-
/**
|
|
517
|
-
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
518
|
-
*
|
|
519
|
-
* @param obj - The value to test.
|
|
520
|
-
* @returns `true` if `obj` is a sigil instance.
|
|
521
|
-
*/
|
|
522
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
523
501
|
/**
|
|
524
502
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
525
503
|
* calling constructor.
|
|
@@ -545,4 +523,4 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
545
523
|
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
546
524
|
}) & B;
|
|
547
525
|
|
|
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 };
|
|
526
|
+
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,14 +33,6 @@ interface ISigilStatic<L extends string = string> {
|
|
|
33
33
|
* Useful for debugging.
|
|
34
34
|
*/
|
|
35
35
|
readonly SigilLabelSet: Readonly<Set<string>>;
|
|
36
|
-
/**
|
|
37
|
-
* Runtime check that determines whether `obj` is an instance produced by a
|
|
38
|
-
* sigil class.
|
|
39
|
-
*
|
|
40
|
-
* @param obj - Value to test.
|
|
41
|
-
* @returns Type guard narrowing `obj` to `ISigilInstance`.
|
|
42
|
-
*/
|
|
43
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
44
36
|
/**
|
|
45
37
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
46
38
|
* calling constructor.
|
|
@@ -160,7 +152,11 @@ type Prettify<T> = {
|
|
|
160
152
|
} & {};
|
|
161
153
|
/** Helper type to replace 'never' with another type */
|
|
162
154
|
type IfNever<T, R = {}> = [T] extends [never] ? R : T;
|
|
163
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Helper type to get prototype of class
|
|
157
|
+
*
|
|
158
|
+
* @template T - Class constructor.
|
|
159
|
+
*/
|
|
164
160
|
type GetPrototype<T> = T extends {
|
|
165
161
|
prototype: infer P;
|
|
166
162
|
} ? P : never;
|
|
@@ -187,7 +183,6 @@ declare const Sigil: {
|
|
|
187
183
|
get SigilEffectiveLabel(): "Sigil";
|
|
188
184
|
get SigilLabelLineage(): readonly string[];
|
|
189
185
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
190
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
191
186
|
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
192
187
|
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
193
188
|
} & {
|
|
@@ -218,7 +213,6 @@ declare const SigilError: {
|
|
|
218
213
|
get SigilEffectiveLabel(): "SigilError";
|
|
219
214
|
get SigilLabelLineage(): readonly string[];
|
|
220
215
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
221
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
222
216
|
isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
223
217
|
isExactType<T extends ISigilStatic>(this: T, other: unknown): other is GetPrototype<T>;
|
|
224
218
|
} & ErrorConstructor;
|
|
@@ -309,13 +303,12 @@ declare function isSigilInstance(inst: unknown): inst is ISigilInstance;
|
|
|
309
303
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers.
|
|
310
304
|
*
|
|
311
305
|
* @param Base - The base constructor to extend.
|
|
312
|
-
* @param label -
|
|
313
|
-
* If not passed a random label is generated instead.
|
|
306
|
+
* @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
314
307
|
* @param opts - Options object to override any global options if needed.
|
|
315
308
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
316
309
|
* @throws Error if `Base` is already sigilified.
|
|
317
310
|
*/
|
|
318
|
-
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label
|
|
311
|
+
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label: L, opts?: SigilOptions): {
|
|
319
312
|
new (...args: any[]): {
|
|
320
313
|
/**
|
|
321
314
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
@@ -394,13 +387,6 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
394
387
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
395
388
|
*/
|
|
396
389
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
397
|
-
/**
|
|
398
|
-
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
399
|
-
*
|
|
400
|
-
* @param obj - The value to test.
|
|
401
|
-
* @returns `true` if `obj` is a sigil instance.
|
|
402
|
-
*/
|
|
403
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
404
390
|
/**
|
|
405
391
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
406
392
|
* calling constructor.
|
|
@@ -429,13 +415,12 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
429
415
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
430
416
|
*
|
|
431
417
|
* @param Base - The base constructor to extend.
|
|
432
|
-
* @param label -
|
|
433
|
-
* If not passed a random label is generated instead.
|
|
418
|
+
* @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
|
|
434
419
|
* @param opts - Options object to override any global options if needed.
|
|
435
420
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
436
421
|
* @throws Error if `Base` is already sigilified.
|
|
437
422
|
*/
|
|
438
|
-
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label
|
|
423
|
+
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
439
424
|
/**
|
|
440
425
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
441
426
|
* calling constructor.
|
|
@@ -513,13 +498,6 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
513
498
|
* @returns A Readonly Set of labels that represent the type lineage.
|
|
514
499
|
*/
|
|
515
500
|
get SigilLabelSet(): Readonly<Set<string>>;
|
|
516
|
-
/**
|
|
517
|
-
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
518
|
-
*
|
|
519
|
-
* @param obj - The value to test.
|
|
520
|
-
* @returns `true` if `obj` is a sigil instance.
|
|
521
|
-
*/
|
|
522
|
-
isSigilified(obj: unknown): obj is ISigilInstance;
|
|
523
501
|
/**
|
|
524
502
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
525
503
|
* calling constructor.
|
|
@@ -545,4 +523,4 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
545
523
|
isExactType<T>(this: T, other: unknown): other is GetPrototype<T>;
|
|
546
524
|
}) & B;
|
|
547
525
|
|
|
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 };
|
|
526
|
+
export { DEFAULT_LABEL_REGEX, type ExtendSigil, type GetPrototype, type ISigil, type ISigilInstance, type ISigilStatic, Sigil, SigilError, type SigilOf, type SigilOptions, Sigilify, SigilifyAbstract, WithSigil, isSigilCtor, isSigilInstance, sigil, updateSigilOptions, withSigil };
|