@vicin/sigil 3.1.1 → 3.1.4
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 -38
- 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 +3 -3
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.4] - 2026-02-26
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Updated description in `package.json`
|
|
10
|
+
|
|
11
|
+
## [3.1.3] - 2026-02-26
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Patched type tests where `sigil` should be imported as type only
|
|
16
|
+
|
|
17
|
+
## [3.1.2] - 2026-02-26
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Patched README.md
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `GetPrototype<T>` helper to get type of class instance in `protected` or `private` classes
|
|
26
|
+
|
|
27
|
+
### Removed
|
|
28
|
+
|
|
29
|
+
- `isSigilified` method in `Sigil` class as it's redundant and separate check function is present
|
|
30
|
+
|
|
5
31
|
## [3.1.1] - 2026-02-25
|
|
6
32
|
|
|
7
33
|
### Changed
|
package/README.md
CHANGED
|
@@ -5,25 +5,25 @@
|
|
|
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
|
-
> - **Inheritance Awareness:** Tracks lineages for subtype/supertype checks.
|
|
15
|
-
|
|
16
|
-
## Important Notes Before Using
|
|
17
|
-
|
|
18
|
-
- **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
|
-
- **Simple instanceof Fix:** If you just need runtime checks without extras, see the [minimal mode](#minimal-mode).
|
|
20
14
|
|
|
21
15
|
## Features
|
|
22
16
|
|
|
23
17
|
- ✅ **Drop-in `instanceof` replacement** that works across bundles, HMR, and monorepos, Also can check for **exact class instance**
|
|
24
|
-
- ✅ **
|
|
25
|
-
- ✅ **Tiny less than 1.5 KB minified and brotlied** measured using size-limit
|
|
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)
|
|
26
20
|
- ✅ **Performant as native instanceof** but with guaranteed checks
|
|
21
|
+
- ✅ **Test coverage is 100%** to ensure that runtime remains consistent and predictable
|
|
22
|
+
|
|
23
|
+
## Important Notes Before Using
|
|
24
|
+
|
|
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.
|
|
26
|
+
- **Simple instanceof Fix:** If you just need runtime checks without extras, see the [minimal mode](#minimal-mode).
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
- [Minimal mode](#minimal-mode)
|
|
46
46
|
- [Strict mode](#strict-mode)
|
|
47
47
|
- [Benchmarks](#benchmarks)
|
|
48
|
+
- [Bundle Size](#bundle-size)
|
|
49
|
+
- [Tests](#tests)
|
|
48
50
|
- [Contributing](#contributing)
|
|
49
51
|
- [License](#license)
|
|
50
52
|
- [Author](#author)
|
|
@@ -152,8 +154,8 @@ Congratulations — you’ve opted into `Sigil` and you can start replacing `ins
|
|
|
152
154
|
|
|
153
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.
|
|
154
156
|
- **EffectiveLabel:** A human-readable (string) such as `@scope/pkg.ClassName`, if no label is passed it inherit the last defined label.
|
|
155
|
-
- **
|
|
156
|
-
- **
|
|
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.
|
|
157
159
|
- **[sigil]**: TypeScript symbol marker for nominal types.
|
|
158
160
|
|
|
159
161
|
---
|
|
@@ -186,7 +188,7 @@ type test1 = User extends Sigil ? true : false; // true
|
|
|
186
188
|
type test2 = Sigil extends User ? true : false; // false
|
|
187
189
|
```
|
|
188
190
|
|
|
189
|
-
`Sigil`
|
|
191
|
+
`Sigil` makes identity management **explicit** and **error-resistant** if defined the right way.
|
|
190
192
|
|
|
191
193
|
### Implementation Mechanics
|
|
192
194
|
|
|
@@ -198,7 +200,7 @@ import { Sigil, WithSigil, sigil, ExtendSigil } from '@vicin/sigil';
|
|
|
198
200
|
|
|
199
201
|
@WithSigil('@scope/package.MyClass') // <-- Run-time values update
|
|
200
202
|
class MyClass extends Sigil {
|
|
201
|
-
declare [sigil]: ExtendSigil<'
|
|
203
|
+
declare [sigil]: ExtendSigil<'MyClass', Sigil>; // <-- compile-time type update
|
|
202
204
|
}
|
|
203
205
|
```
|
|
204
206
|
|
|
@@ -208,14 +210,14 @@ You can avoid decorators and use HOF but they are slightly more verbose:
|
|
|
208
210
|
import { Sigil, withSigil, sigil, ExtendSigil } from '@vicin/sigil';
|
|
209
211
|
|
|
210
212
|
class _MyClass extends Sigil {
|
|
211
|
-
declare [sigil]: ExtendSigil<'
|
|
213
|
+
declare [sigil]: ExtendSigil<'MyClass', Sigil>;
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
const MyClass = withSigil(_MyClass, '@scope/package.MyClass');
|
|
215
217
|
type MyClass = InstanceType<typeof MyClass>;
|
|
216
218
|
```
|
|
217
219
|
|
|
218
|
-
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.
|
|
219
221
|
|
|
220
222
|
### Inheritance example
|
|
221
223
|
|
|
@@ -224,12 +226,12 @@ import { Sigil, WithSigil } from '@vicin/sigil';
|
|
|
224
226
|
|
|
225
227
|
@WithSigil('@myorg/User')
|
|
226
228
|
class User extends Sigil {
|
|
227
|
-
declare [sigil]: ExtendSigil<'
|
|
229
|
+
declare [sigil]: ExtendSigil<'User', Sigil>;
|
|
228
230
|
}
|
|
229
231
|
|
|
230
232
|
@WithSigil('@myorg/Admin')
|
|
231
233
|
class Admin extends User {
|
|
232
|
-
declare [sigil]: ExtendSigil<'
|
|
234
|
+
declare [sigil]: ExtendSigil<'Admin', User>;
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
const admin = new Admin();
|
|
@@ -258,8 +260,8 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
258
260
|
### Primary Exports
|
|
259
261
|
|
|
260
262
|
- **Mixins:**
|
|
261
|
-
- `Sigilify(Base, label
|
|
262
|
-
- `SigilifyAbstract(Base, label
|
|
263
|
+
- `Sigilify(Base, label, opts?)`
|
|
264
|
+
- `SigilifyAbstract(Base, label, opts?)`
|
|
263
265
|
|
|
264
266
|
- **Classes:**
|
|
265
267
|
- `Sigil`
|
|
@@ -269,15 +271,11 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
269
271
|
- `WithSigil(label, opts?)`
|
|
270
272
|
|
|
271
273
|
- **HOFs:**
|
|
272
|
-
- `withSigil(Class, label
|
|
274
|
+
- `withSigil(Class, label, opts?)`
|
|
273
275
|
|
|
274
276
|
- **Helpers:**
|
|
275
277
|
- `isSigilCtor(ctor)`
|
|
276
278
|
- `isSigilInstance(inst)`
|
|
277
|
-
- `isSigilBaseCtor(ctor)`
|
|
278
|
-
- `isSigilBaseInstance(inst)`
|
|
279
|
-
- `isDecorated(ctor)`
|
|
280
|
-
- `isInheritanceChecked(ctor)`
|
|
281
279
|
|
|
282
280
|
- **Options:**
|
|
283
281
|
- `updateSigilOptions(opts)`
|
|
@@ -289,18 +287,20 @@ type test2 = User extends Admin ? true : false; // false
|
|
|
289
287
|
- `ISigilInstance<Label, ParentSigil?>`
|
|
290
288
|
- `SigilOf<T>`
|
|
291
289
|
- `ExtendSigil<Label, Parent>`
|
|
290
|
+
- `GetPrototype<Class>`
|
|
292
291
|
- `SigilOptions`
|
|
293
292
|
|
|
294
293
|
### Key helpers (runtime)
|
|
295
294
|
|
|
296
295
|
- `Sigil`: a minimal sigilified base class you can extend from.
|
|
297
296
|
- `SigilError`: an `Error` class decorated with a `Sigil` so it can be identified at runtime.
|
|
298
|
-
- `Sigilify(Base, label
|
|
299
|
-
- `
|
|
300
|
-
- `
|
|
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.
|
|
301
301
|
- `isSigilCtor(value)`: `true` if `value` is a `Sigil` constructor.
|
|
302
302
|
- `isSigilInstance(value)`: `true` if `value` is an instance of a `Sigil` constructor.
|
|
303
|
-
- `updateSigilOptions(opts)`: change global runtime options
|
|
303
|
+
- `updateSigilOptions(opts)`: change global runtime options of `Sigil` library (e.g., `autofillLabels`).
|
|
304
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`
|
|
305
305
|
|
|
306
306
|
### Instance & static helpers provided by Sigilified constructors
|
|
@@ -310,8 +310,7 @@ When a constructor is decorated/sigilified it will expose the following **static
|
|
|
310
310
|
- `SigilLabel` — the identity label string.
|
|
311
311
|
- `SigilEffectiveLabel` — the human label string.
|
|
312
312
|
- `SigilLabelLineage` — readonly array of labels representing parent → child for debugging.
|
|
313
|
-
- `SigilLabelSet` — readonly `Set<string>` for debugging.
|
|
314
|
-
- `isSigilified(obj)` — runtime predicate that delegates to `isSigilInstance`.
|
|
313
|
+
- `SigilLabelSet` — readonly `Set<string>` of sigil labels for debugging.
|
|
315
314
|
- `isOfType(other)` — check if other is an instance of this constructor or its children.
|
|
316
315
|
- `isExactType(other) `— check if other is an instance exactly this constructor.
|
|
317
316
|
|
|
@@ -335,7 +334,6 @@ import { updateSigilOptions } from '@vicin/sigil';
|
|
|
335
334
|
|
|
336
335
|
updateSigilOptions({
|
|
337
336
|
autofillLabels: true, // Automatically label unlabeled subclasses
|
|
338
|
-
skipLabelInheritanceCheck: false, // Bypass dev inheritance checks -- ALMOST NEVER WANT TO SET THIS TO TRUE
|
|
339
337
|
labelValidation: null, // Function or regex, Enforce label format
|
|
340
338
|
});
|
|
341
339
|
```
|
|
@@ -367,14 +365,22 @@ import { updateSigilOptions } from '@vicin/sigil';
|
|
|
367
365
|
updateSigilOptions({ autofillLabels: false });
|
|
368
366
|
```
|
|
369
367
|
|
|
370
|
-
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.
|
|
371
369
|
|
|
372
370
|
---
|
|
373
371
|
|
|
374
372
|
## Benchmarks
|
|
375
373
|
|
|
376
374
|
Sigil is built for **real-world performance**. Below are the latest micro-benchmark results (run on **Node.js v20.12.0**).
|
|
377
|
-
|
|
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
|
+
```
|
|
378
384
|
|
|
379
385
|
### 1. Runtime Type Checking
|
|
380
386
|
|
|
@@ -387,8 +393,7 @@ To run benchmarks on your machine fetch source code from [github](https://github
|
|
|
387
393
|
| 15 | 0.000058 ms | 0.000063 ms | **0.000051 ms** | 0.000069 ms | **0.000053 ms** |
|
|
388
394
|
|
|
389
395
|
> **Key takeaway**:
|
|
390
|
-
> `isOfType` has **practically the same performance as native `instanceof`**, slightly **slower** on static calls and slightly **faster** on the instance side.
|
|
391
|
-
> `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.
|
|
392
397
|
|
|
393
398
|
### 2. Class Definition & Instance Creation
|
|
394
399
|
|
|
@@ -409,14 +414,59 @@ To run benchmarks on your machine fetch source code from [github](https://github
|
|
|
409
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.
|
|
410
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.
|
|
411
416
|
|
|
412
|
-
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Bundle Size
|
|
420
|
+
|
|
421
|
+
**Less than 1.5 KB (1.44 KB)** minified + Brotli, including all dependencies
|
|
413
422
|
|
|
414
|
-
**
|
|
423
|
+
**Running Tests**
|
|
424
|
+
|
|
425
|
+
To verify bundle size fetch source code from [github](https://github.com/ZiadTaha62/sigil) then:
|
|
426
|
+
|
|
427
|
+
```bash
|
|
428
|
+
npm install
|
|
429
|
+
npm run size
|
|
430
|
+
```
|
|
415
431
|
|
|
416
432
|
This makes Sigil one of the smallest full-featured solutions for nominal typing + reliable runtime identity.
|
|
417
433
|
|
|
418
434
|
---
|
|
419
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
|
+
|
|
420
470
|
## Contributing
|
|
421
471
|
|
|
422
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 };
|