@vicin/sigil 1.3.0 → 2.0.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 +6 -0
- package/README.md +22 -132
- package/dist/index.d.mts +119 -400
- package/dist/index.d.ts +119 -400
- package/dist/index.global.js +1789 -387
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +77 -391
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -389
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,298 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small wrapper around a shared registry Set that provides safe operations
|
|
3
|
-
* and hot-reload-friendly behavior.
|
|
4
|
-
*
|
|
5
|
-
* Responsibilities:
|
|
6
|
-
* - Query the current registry (may be `null` to indicate disabled checks).
|
|
7
|
-
* - Register / unregister labels in a controlled manner.
|
|
8
|
-
* - Query class constructors using their 'SigilLabel'.
|
|
9
|
-
* - Support hot-reload tolerant registration (avoid throwing in DEV).
|
|
10
|
-
*/
|
|
11
|
-
declare class SigilRegistry {
|
|
12
|
-
/** Internal private registry map. */
|
|
13
|
-
private _registry;
|
|
14
|
-
/**
|
|
15
|
-
* @param map - Map used to register 'Sigil' classes. if not passed it will be auto-generated internally.
|
|
16
|
-
*/
|
|
17
|
-
constructor(map?: Map<string, ISigil | null>);
|
|
18
|
-
/**
|
|
19
|
-
* Return a readonly view (array) of the current registry entries.
|
|
20
|
-
*
|
|
21
|
-
* @returns An array containing all registered labels, or an empty array when registry is disabled.
|
|
22
|
-
*/
|
|
23
|
-
listLabels(): string[];
|
|
24
|
-
/**
|
|
25
|
-
* Determine whether the registry currently contains `label`.
|
|
26
|
-
*
|
|
27
|
-
* @param label - The label to test.
|
|
28
|
-
* @returns `true` if present; `false` otherwise.
|
|
29
|
-
*/
|
|
30
|
-
has(label: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Get class constructor using its label.
|
|
33
|
-
*
|
|
34
|
-
* @param label - Label appended to Sigil class.
|
|
35
|
-
* @returns Reference to Sigil class constructor or null if stored with 'SigilOptions.storeConstructor = false'.
|
|
36
|
-
*/
|
|
37
|
-
get(label: string): ISigil | null;
|
|
38
|
-
/**
|
|
39
|
-
* Register a label and class constructor in the active registry.
|
|
40
|
-
*
|
|
41
|
-
* If the label already exists then:
|
|
42
|
-
* - In DEV builds: prints a console warning (HMR friendly) and returns early.
|
|
43
|
-
* - In non-DEV builds: throws an Error to prevent duplicate registration.
|
|
44
|
-
*
|
|
45
|
-
* @param label - Label string to register (e.g. '@scope/pkg.ClassName').
|
|
46
|
-
* @param Class - Constructor of the class being registered.
|
|
47
|
-
* @param opts - Optional per-call overrides.
|
|
48
|
-
*/
|
|
49
|
-
register(label: string, Class: ISigil | null, opts?: Pick<SigilOptions, 'devMarker' | 'storeConstructor'>): void;
|
|
50
|
-
/**
|
|
51
|
-
* Alias for 'SigilRegistry.register'.
|
|
52
|
-
*
|
|
53
|
-
* @param label - Label string to register (e.g. '@scope/pkg.ClassName').
|
|
54
|
-
* @param Class - Constructor of the class being registered.
|
|
55
|
-
* @param opts - Optional per-call overrides.
|
|
56
|
-
*/
|
|
57
|
-
set(label: string, Class: ISigil | null, opts?: Pick<SigilOptions, 'devMarker' | 'storeConstructor'>): void;
|
|
58
|
-
/**
|
|
59
|
-
* Unregister a previously registered class.
|
|
60
|
-
*
|
|
61
|
-
* @param label - The label to remove from the registry.
|
|
62
|
-
* @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
|
|
63
|
-
*/
|
|
64
|
-
unregister(label: string): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Alias for 'SigilRegistry.unregister'.
|
|
67
|
-
*
|
|
68
|
-
* @param label - The label to remove from the registry.
|
|
69
|
-
* @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
|
|
70
|
-
*/
|
|
71
|
-
delete(label: string): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Replace active registry with new one. deprecated use 'updateOptions({ registry: newRegistry })' instead.
|
|
74
|
-
*
|
|
75
|
-
* @deprecated Will be removed in v2.0.0, check https://www.npmjs.com/package/@vicin/sigil?activeTab=readme#deprecated-api for more details.
|
|
76
|
-
* @param newRegistry - New Set<string> instance to use as the active registry, or `null` to disable checks.
|
|
77
|
-
*/
|
|
78
|
-
replaceRegistry(newRegistry: Map<string, ISigil | null> | null): void;
|
|
79
|
-
/**
|
|
80
|
-
* Clear the registry completely.
|
|
81
|
-
*
|
|
82
|
-
* Useful for test teardown, or when explicitly resetting state during development.
|
|
83
|
-
* No-op when the registry is disabled.
|
|
84
|
-
*/
|
|
85
|
-
clear(): void;
|
|
86
|
-
/**
|
|
87
|
-
* Merge another SigilRegistry into this one.
|
|
88
|
-
*
|
|
89
|
-
* Entries from `other` will be registered into this registry. Duplicate labels
|
|
90
|
-
* are handled via this registry's `register` logic (i.e., will warn in DEV or
|
|
91
|
-
* throw in production).
|
|
92
|
-
*
|
|
93
|
-
* @param other - Another `SigilRegistry` whose entries will be merged into this registry.
|
|
94
|
-
*/
|
|
95
|
-
merge(other: SigilRegistry): void;
|
|
96
|
-
/**
|
|
97
|
-
* Return a Map-style iterator over entries: `[label, constructor]`.
|
|
98
|
-
* Equivalent to calling `registry[Symbol.iterator]()`.
|
|
99
|
-
*
|
|
100
|
-
* @returns IterableIterator of `[label, ISigil]`.
|
|
101
|
-
*/
|
|
102
|
-
entries(): IterableIterator<[string, ISigil | null]>;
|
|
103
|
-
/**
|
|
104
|
-
* Return an iterator over registered constructors.
|
|
105
|
-
*
|
|
106
|
-
* @returns IterableIterator of `ISigil` constructors.
|
|
107
|
-
*/
|
|
108
|
-
values(): IterableIterator<ISigil | null>;
|
|
109
|
-
/**
|
|
110
|
-
* Return an iterator over registered labels (keys).
|
|
111
|
-
*
|
|
112
|
-
* @returns IterableIterator of `string` labels.
|
|
113
|
-
*/
|
|
114
|
-
keys(): IterableIterator<string>;
|
|
115
|
-
/**
|
|
116
|
-
* Execute a provided function once per registry entry.
|
|
117
|
-
*
|
|
118
|
-
* @param callback - Function invoked with `(ctor, label)` for each entry.
|
|
119
|
-
* @param thisArg - Optional `this` context for the callback.
|
|
120
|
-
*/
|
|
121
|
-
forEach(callback: (ctor: ISigil | null, label: string) => void, thisArg?: any): void;
|
|
122
|
-
/**
|
|
123
|
-
* Get the size (number of entries) of the active registry.
|
|
124
|
-
*
|
|
125
|
-
* @returns The number of registered labels, or 0 when registry is disabled.
|
|
126
|
-
*/
|
|
127
|
-
get size(): number;
|
|
128
|
-
/**
|
|
129
|
-
* Return an iterator over `[label, constructor]` pairs.
|
|
130
|
-
*
|
|
131
|
-
* This makes the registry compatible with `for..of` and other iterable helpers:
|
|
132
|
-
* ```ts
|
|
133
|
-
* for (const [label, ctor] of registry) { ... }
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* @returns An iterable iterator that yields `[label, ISigil]` tuples.
|
|
137
|
-
*/
|
|
138
|
-
[Symbol.iterator](): IterableIterator<[string, ISigil | null]>;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Returns the currently configured SigilRegistry instance (or `null` if no registry is active).
|
|
142
|
-
*
|
|
143
|
-
* IMPORTANT: this function reflects the live `OPTIONS.registry` value and therefore
|
|
144
|
-
* will reflect any changes made via `updateOptions(...)`. Consumers that need a stable
|
|
145
|
-
* registry instance for mutation should call this function each time rather than
|
|
146
|
-
* holding a long-lived reference to the previously returned object.
|
|
147
|
-
*
|
|
148
|
-
* It gets global registry if defined, otherwise returns registry stored in SigilOptions.
|
|
149
|
-
*
|
|
150
|
-
* @returns {SigilRegistry | null} The active registry or `null` when no registry is in use.
|
|
151
|
-
*/
|
|
152
|
-
declare const getActiveRegistry: () => SigilRegistry | null;
|
|
153
|
-
/** -----------------------------------------
|
|
154
|
-
* Deprecated registry
|
|
155
|
-
* ----------------------------------------- */
|
|
156
|
-
/**
|
|
157
|
-
* Old 'REGISTRY' alias to interact with registy.
|
|
158
|
-
*
|
|
159
|
-
* 'REGISTRY' is a live binding for compat; prefer getActiveRegistry() to avoid manual sync.
|
|
160
|
-
* @deprecated Will be removed in v2.0.0, check https://www.npmjs.com/package/@vicin/sigil?activeTab=readme#deprecated-api for more details.
|
|
161
|
-
*/
|
|
162
|
-
declare let REGISTRY: SigilRegistry;
|
|
163
|
-
/** -----------------------------------------
|
|
164
|
-
* Label validation
|
|
165
|
-
* ----------------------------------------- */
|
|
166
|
-
/**
|
|
167
|
-
* Label validation regex. Labels must follow the pattern
|
|
168
|
-
* `@scope/package.ClassName` where `ClassName` begins with an uppercase
|
|
169
|
-
* letter. This avoids collisions across packages and helps debugging.
|
|
170
|
-
*
|
|
171
|
-
* It's advised to use this regex in 'SigilOptions.labelValidation'.
|
|
172
|
-
*/
|
|
173
|
-
declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
174
|
-
/** -----------------------------------------
|
|
175
|
-
* Deprecated registry
|
|
176
|
-
* ----------------------------------------- */
|
|
177
|
-
/**
|
|
178
|
-
* Update runtime options for the Sigil library.
|
|
179
|
-
* Call this early during application startup if you want non-default behavior.
|
|
180
|
-
*
|
|
181
|
-
* Example:
|
|
182
|
-
* ```ts
|
|
183
|
-
* updateOptions({ autofillLabels: true, labelValidation: /^@[\w-]+\/[\w-]+\.[A-Za-z0-9]+$/ });
|
|
184
|
-
* ```
|
|
185
|
-
*
|
|
186
|
-
* @param opts - Partial options to merge into the global `OPTIONS` object.
|
|
187
|
-
* @param mergeRegistries - Boolean to merge old registry into new one directly, default is 'true'.
|
|
188
|
-
*/
|
|
189
|
-
declare const updateOptions: (opts: SigilOptions, mergeRegistries?: boolean) => void;
|
|
190
|
-
|
|
191
|
-
/** -----------------------------------------
|
|
192
|
-
* Options
|
|
193
|
-
* ----------------------------------------- */
|
|
194
|
-
/**
|
|
195
|
-
* Configuration options for the Sigil library.
|
|
196
|
-
*
|
|
197
|
-
* These options control runtime validation, inheritance checks, label autofill behavior,
|
|
198
|
-
* and whether duplicate labels are permitted globally.
|
|
199
|
-
*
|
|
200
|
-
* Note: these options are read by runtime code during class decoration and inheritance
|
|
201
|
-
* checks. Some behaviors (like `skipLabelInheritanceCheck`) are meant primarily for
|
|
202
|
-
* development/test scenarios and may weaken type/identity guarantees when changed.
|
|
203
|
-
*/
|
|
204
|
-
interface SigilOptions {
|
|
205
|
-
/**
|
|
206
|
-
* Validation rule applied to sigil labels before registration.
|
|
207
|
-
*
|
|
208
|
-
* - A function receives the label and must return `true` if valid.
|
|
209
|
-
* - A `RegExp` must match the label.
|
|
210
|
-
* - `null` disables validation entirely.
|
|
211
|
-
*
|
|
212
|
-
* Defaults to `null`.
|
|
213
|
-
*/
|
|
214
|
-
labelValidation?: ((label: string) => boolean) | RegExp | null;
|
|
215
|
-
/**
|
|
216
|
-
* Skips the runtime check that prevents subclasses from inheriting
|
|
217
|
-
* the same sigil label as their ancestors.
|
|
218
|
-
*
|
|
219
|
-
* When `false` (default), extending a sigil class without
|
|
220
|
-
* using `WithSigil(newLabel)` decorator will throw an error if the label
|
|
221
|
-
* is reused and `OPTIONS.autofillLabels` is set to `false`.
|
|
222
|
-
*
|
|
223
|
-
* Set this to `true` only if you intentionally want subclasses to inherit labels
|
|
224
|
-
* from their ancestors (this weakens the uniqueness guarantees).
|
|
225
|
-
*
|
|
226
|
-
* WARNING:
|
|
227
|
-
* Disabling inheritanceCheck removes guaranties by 'Sigil' or unique label for
|
|
228
|
-
* each class and allow multiple child classes to use the same label which can
|
|
229
|
-
* result on false 'isOfType' result. this options should be used in debugging
|
|
230
|
-
* only to silence all errors but never in production.
|
|
231
|
-
*/
|
|
232
|
-
skipLabelInheritanceCheck?: boolean;
|
|
233
|
-
/**
|
|
234
|
-
* When enabled, non-decorated subclasses that would otherwise inherit an ancestor's label
|
|
235
|
-
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
236
|
-
*/
|
|
237
|
-
autofillLabels?: boolean;
|
|
238
|
-
/**
|
|
239
|
-
* Marker used internally to control dev only checks to optimize performace while preserving
|
|
240
|
-
* consistency for things like inheritance checks.
|
|
241
|
-
* defaults to 'process.env.NODE_ENV !== "production'.
|
|
242
|
-
*/
|
|
243
|
-
devMarker?: boolean;
|
|
244
|
-
/**
|
|
245
|
-
* Registry instance used to store and resolve sigil labels at runtime.
|
|
246
|
-
*
|
|
247
|
-
* - When `useGlobalRegistry` is `true` (default), this registry will be
|
|
248
|
-
* registered as the active global registry via `updateGlobalRegistry(...)`.
|
|
249
|
-
* - When `useGlobalRegistry` is `false`, this registry is kept local and will
|
|
250
|
-
* not participate in global identity checks.
|
|
251
|
-
*
|
|
252
|
-
* IMPORTANT:
|
|
253
|
-
* Replacing the registry via `updateOptions({ registry })` changes the active
|
|
254
|
-
* registry used by Sigil, but consumers should always retrieve the registry
|
|
255
|
-
* through `getRegistry()` rather than holding a long-lived reference.
|
|
256
|
-
*
|
|
257
|
-
* Defaults to a new `SigilRegistry` instance.
|
|
258
|
-
*
|
|
259
|
-
* WARNING:
|
|
260
|
-
* Setting registry to null disables:
|
|
261
|
-
* - Label re-use checks entirly.
|
|
262
|
-
* - Feature relying on get(label) → class (e.g., deserialization)
|
|
263
|
-
*/
|
|
264
|
-
registry?: SigilRegistry | null;
|
|
265
|
-
/**
|
|
266
|
-
* Controls whether the configured `registry` is stored in 'globalThis'.
|
|
267
|
-
*
|
|
268
|
-
* When `true` (default):
|
|
269
|
-
* - The registry is registered globally
|
|
270
|
-
* - All sigilized classes participate in the same identity space
|
|
271
|
-
*
|
|
272
|
-
* When `false`:
|
|
273
|
-
* - No global registry is used
|
|
274
|
-
* - Identity checks are limited to explicitly provided registry
|
|
275
|
-
*
|
|
276
|
-
* WARNING:
|
|
277
|
-
* Disabling the global registry may lead to duplicate labels across
|
|
278
|
-
* isolated registries and should only be done in advanced or test scenarios.
|
|
279
|
-
*/
|
|
280
|
-
useGlobalRegistry?: boolean;
|
|
281
|
-
/**
|
|
282
|
-
* Controls whether the configured 'registry' should store class constructors.
|
|
283
|
-
* This is useful if you want to use 'Sigil' while keeping the constructor private.
|
|
284
|
-
*
|
|
285
|
-
* Note that any feature relying on get(label) → class (e.g., deserialization) will
|
|
286
|
-
* not work if set to 'true' as class is replaced with 'null'.
|
|
287
|
-
*
|
|
288
|
-
* When 'true' (default):
|
|
289
|
-
* - Class passed will be stored in the registry map under its label.
|
|
290
|
-
*
|
|
291
|
-
* When 'false':
|
|
292
|
-
* - Registry map stored only label key and class constructor is replaced with null ([label, null])
|
|
293
|
-
*/
|
|
294
|
-
storeConstructor?: boolean;
|
|
295
|
-
}
|
|
296
1
|
/** -----------------------------------------
|
|
297
2
|
* Class and instance
|
|
298
3
|
* ----------------------------------------- */
|
|
@@ -319,18 +24,16 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
|
|
|
319
24
|
} & SigilBrandOf<P>>;
|
|
320
25
|
/** Class-level label constant (human readable). */
|
|
321
26
|
readonly SigilLabel: string;
|
|
322
|
-
/** Class-level unique symbol used as the runtime type identifier. */
|
|
323
|
-
readonly SigilType: symbol;
|
|
324
27
|
/**
|
|
325
|
-
* Copy of the linearized sigil type
|
|
28
|
+
* Copy of the linearized sigil type label chain for the current constructor.
|
|
326
29
|
* Useful for debugging and strict lineage comparisons.
|
|
327
30
|
*/
|
|
328
|
-
readonly
|
|
31
|
+
readonly SigilLabelLineage: readonly string[];
|
|
329
32
|
/**
|
|
330
|
-
* Copy of the sigil type
|
|
33
|
+
* Copy of the sigil type label set for the current constructor. Useful for
|
|
331
34
|
* O(1) membership checks and debugging.
|
|
332
35
|
*/
|
|
333
|
-
readonly
|
|
36
|
+
readonly SigilLabelSet: Readonly<Set<string>>;
|
|
334
37
|
/**
|
|
335
38
|
* Runtime check that determines whether `obj` is an instance produced by a
|
|
336
39
|
* sigil class.
|
|
@@ -344,7 +47,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
|
|
|
344
47
|
isSigilified(obj: unknown): obj is ISigil;
|
|
345
48
|
/**
|
|
346
49
|
* Check whether `other` is (or inherits from) the type represented by the
|
|
347
|
-
* calling constructor. Uses the other instance's `
|
|
50
|
+
* calling constructor. Uses the other instance's `SigilLabelSet` to check
|
|
348
51
|
* membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
349
52
|
*
|
|
350
53
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
@@ -358,7 +61,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
|
|
|
358
61
|
isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
|
|
359
62
|
/**
|
|
360
63
|
* Strict lineage comparison: verifies that the calling constructor's type
|
|
361
|
-
* lineage (by
|
|
64
|
+
* lineage (by label) matches the `other`'s lineage element-by-element.
|
|
362
65
|
*
|
|
363
66
|
* Works in O(n) where `n` is the lineage length and is useful when order
|
|
364
67
|
* and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
@@ -390,12 +93,12 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
|
|
|
390
93
|
} & SigilBrandOf<P>>;
|
|
391
94
|
/** Returns human-readable sigil label of the class constructor. */
|
|
392
95
|
getSigilLabel(): string;
|
|
393
|
-
/** Returns runtime sigil type
|
|
394
|
-
getSigilType():
|
|
395
|
-
/** Returns copy of sigil type
|
|
396
|
-
|
|
397
|
-
/** Returns copy of sigil type
|
|
398
|
-
|
|
96
|
+
/** Returns runtime sigil type label of the class constructor. */
|
|
97
|
+
getSigilType(): string;
|
|
98
|
+
/** Returns copy of sigil type label lineage of the class constructor. */
|
|
99
|
+
getSigilLabelLineage(): readonly string[];
|
|
100
|
+
/** Returns copy of sigil type label set of the class constructor. */
|
|
101
|
+
getSigilLabelSet(): Readonly<Set<string>>;
|
|
399
102
|
}
|
|
400
103
|
/**
|
|
401
104
|
* Combined constructor + static interface for a sigil class.
|
|
@@ -498,19 +201,17 @@ declare const Sigil: {
|
|
|
498
201
|
Sigil: true;
|
|
499
202
|
};
|
|
500
203
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
501
|
-
isOfTypeStrict<T>(this: T, other: unknown): other is
|
|
204
|
+
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
502
205
|
getSigilLabel(): string;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
getSigilTypeSet(): Readonly<Set<symbol>>;
|
|
206
|
+
getSigilLabelLineage(): readonly string[];
|
|
207
|
+
getSigilLabelSet(): Readonly<Set<string>>;
|
|
506
208
|
};
|
|
507
209
|
readonly __SIGIL_BRAND__: {
|
|
508
210
|
Sigil: true;
|
|
509
211
|
};
|
|
510
212
|
get SigilLabel(): string;
|
|
511
|
-
get
|
|
512
|
-
get
|
|
513
|
-
get SigilTypeSet(): Readonly<Set<symbol>>;
|
|
213
|
+
get SigilLabelLineage(): readonly string[];
|
|
214
|
+
get SigilLabelSet(): Readonly<Set<string>>;
|
|
514
215
|
isSigilified(obj: unknown): obj is ISigil;
|
|
515
216
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
516
217
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
@@ -532,26 +233,89 @@ declare const SigilError: {
|
|
|
532
233
|
SigilError: true;
|
|
533
234
|
};
|
|
534
235
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
535
|
-
isOfTypeStrict<T>(this: T, other: unknown): other is
|
|
236
|
+
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
536
237
|
getSigilLabel(): string;
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
getSigilTypeSet(): Readonly<Set<symbol>>;
|
|
238
|
+
getSigilLabelLineage(): readonly string[];
|
|
239
|
+
getSigilLabelSet(): Readonly<Set<string>>;
|
|
540
240
|
};
|
|
541
241
|
readonly __SIGIL_BRAND__: {
|
|
542
242
|
Sigil: true;
|
|
543
243
|
SigilError: true;
|
|
544
244
|
};
|
|
545
245
|
get SigilLabel(): string;
|
|
546
|
-
get
|
|
547
|
-
get
|
|
548
|
-
get SigilTypeSet(): Readonly<Set<symbol>>;
|
|
246
|
+
get SigilLabelLineage(): readonly string[];
|
|
247
|
+
get SigilLabelSet(): Readonly<Set<string>>;
|
|
549
248
|
isSigilified(obj: unknown): obj is ISigil;
|
|
550
249
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
551
250
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
552
251
|
} & ErrorConstructor;
|
|
553
252
|
type SigilError = InstanceType<typeof SigilError>;
|
|
554
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Configuration options for the Sigil library.
|
|
256
|
+
*
|
|
257
|
+
* These options control runtime validation, inheritance checks, label autofill behavior.
|
|
258
|
+
*/
|
|
259
|
+
interface SigilOptions {
|
|
260
|
+
/**
|
|
261
|
+
* Validation rule applied to sigil labels before registration.
|
|
262
|
+
*
|
|
263
|
+
* - A function receives the label and must return `true` if valid.
|
|
264
|
+
* - A `RegExp` must match the label.
|
|
265
|
+
* - `null` disables validation entirely.
|
|
266
|
+
*
|
|
267
|
+
* Defaults to `null`.
|
|
268
|
+
*/
|
|
269
|
+
labelValidation?: ((label: string) => boolean) | RegExp | null;
|
|
270
|
+
/**
|
|
271
|
+
* Skips the runtime check that prevents subclasses from inheriting
|
|
272
|
+
* the same sigil label as their ancestors.
|
|
273
|
+
*
|
|
274
|
+
* When `false` (default), extending a sigil class without
|
|
275
|
+
* using `WithSigil(newLabel)` decorator will throw an error if the label
|
|
276
|
+
* is reused and `OPTIONS.autofillLabels` is set to `false`.
|
|
277
|
+
*
|
|
278
|
+
* Set this to `true` only if you intentionally want subclasses to inherit labels
|
|
279
|
+
* from their ancestors (this weakens the uniqueness guarantees).
|
|
280
|
+
*
|
|
281
|
+
* WARNING:
|
|
282
|
+
* Disabling inheritanceCheck removes guaranties by 'Sigil' or unique label for
|
|
283
|
+
* each class and allow multiple child classes to use the same label which can
|
|
284
|
+
* result on false 'isOfType' result. this options should be used in debugging
|
|
285
|
+
* only to silence all errors but never in production.
|
|
286
|
+
*/
|
|
287
|
+
skipLabelInheritanceCheck?: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* When enabled, non-decorated subclasses that would otherwise inherit an ancestor's label
|
|
290
|
+
* will be assigned an autogenerated random label (so that explicit labels stay unique).
|
|
291
|
+
*/
|
|
292
|
+
autofillLabels?: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Marker used internally to control dev only checks to optimize performace while preserving
|
|
295
|
+
* consistency for things like inheritance checks.
|
|
296
|
+
* defaults to 'process.env.NODE_ENV !== "production'.
|
|
297
|
+
*/
|
|
298
|
+
devMarker?: boolean;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Update runtime options for the Sigil library.
|
|
302
|
+
* Call this early during application startup if you want non-default behavior.
|
|
303
|
+
*
|
|
304
|
+
* @param opts - Partial options to merge into the global `OPTIONS` object.
|
|
305
|
+
*/
|
|
306
|
+
declare const updateOptions: (opts: SigilOptions) => void;
|
|
307
|
+
/** -----------------------------------------
|
|
308
|
+
* Label validation
|
|
309
|
+
* ----------------------------------------- */
|
|
310
|
+
/**
|
|
311
|
+
* Label validation regex. Labels must follow the pattern
|
|
312
|
+
* `@scope/package.ClassName` where `ClassName` begins with an uppercase
|
|
313
|
+
* letter. This avoids collisions across packages and helps debugging.
|
|
314
|
+
*
|
|
315
|
+
* It's advised to use this regex in 'SigilOptions.labelValidation'.
|
|
316
|
+
*/
|
|
317
|
+
declare const DEFAULT_LABEL_REGEX: RegExp;
|
|
318
|
+
|
|
555
319
|
/**
|
|
556
320
|
* Class decorator factory that attaches sigil statics to a class constructor.
|
|
557
321
|
*
|
|
@@ -598,23 +362,6 @@ declare function WithSigil<L extends string>(label?: L, opts?: SigilOptions): (v
|
|
|
598
362
|
* @returns The same constructor value, with runtime metadata ensured.
|
|
599
363
|
*/
|
|
600
364
|
declare function withSigil<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): S;
|
|
601
|
-
/**
|
|
602
|
-
* Narrow a constructor to a compile-time `TypedSigil` without modifying runtime.
|
|
603
|
-
*
|
|
604
|
-
* This is a *purely type-level* helper (no runtime changes). It optionally
|
|
605
|
-
* verifies in DEV that the runtime `SigilLabel` matches the provided `label`.
|
|
606
|
-
*
|
|
607
|
-
* Use this when the runtime metadata is already present (for example the class
|
|
608
|
-
* is already decorated or was created via `Sigilify`).
|
|
609
|
-
*
|
|
610
|
-
* @deprecated Will be removed in v2.0.0, check https://www.npmjs.com/package/@vicin/sigil?activeTab=readme#deprecated-api for more details.
|
|
611
|
-
* @typeParam S - Constructor type (should be an ISigil).
|
|
612
|
-
* @typeParam L - Label literal to associate at compile-time.
|
|
613
|
-
* @param Class - The constructor to assert as typed sigil.
|
|
614
|
-
* @param label - Optional label literal to assert at compile-time (and to verify in DEV).
|
|
615
|
-
* @returns The same constructor value, typed as `TypedSigil<S, L, P>`.
|
|
616
|
-
*/
|
|
617
|
-
declare function typed<S extends Function, L extends string = string>(Class: S, label?: L, opts?: Pick<SigilOptions, 'devMarker'>): TypedSigil<S, L>;
|
|
618
365
|
/**
|
|
619
366
|
* Convenience helper that combine 'withSigil' and 'typeSigil'.
|
|
620
367
|
*
|
|
@@ -698,7 +445,6 @@ declare function isInheritanceChecked(ctor: Function): boolean;
|
|
|
698
445
|
* helpers.
|
|
699
446
|
*
|
|
700
447
|
* The returned class:
|
|
701
|
-
* - registers a stable symbol for the provided `label` (via `WithSigil`)
|
|
702
448
|
* - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
|
|
703
449
|
* - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
|
|
704
450
|
*
|
|
@@ -733,7 +479,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
733
479
|
*/
|
|
734
480
|
isOfType<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
735
481
|
/**
|
|
736
|
-
* Strict lineage check: compares the type
|
|
482
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
737
483
|
*
|
|
738
484
|
* Allows 'instanceof' like checks but in instances.
|
|
739
485
|
*
|
|
@@ -742,7 +488,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
742
488
|
* @param other - The object to test.
|
|
743
489
|
* @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
|
|
744
490
|
*/
|
|
745
|
-
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is
|
|
491
|
+
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
746
492
|
/**
|
|
747
493
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
748
494
|
*
|
|
@@ -750,23 +496,17 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
750
496
|
*/
|
|
751
497
|
getSigilLabel(): string;
|
|
752
498
|
/**
|
|
753
|
-
* Returns the
|
|
499
|
+
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
754
500
|
*
|
|
755
|
-
* @returns
|
|
501
|
+
* @returns readonly array of labels representing the type lineage.
|
|
756
502
|
*/
|
|
757
|
-
|
|
503
|
+
getSigilLabelLineage(): readonly string[];
|
|
758
504
|
/**
|
|
759
|
-
* Returns a copy of the sigil type
|
|
505
|
+
* Returns a readonly copy of the sigil type label set for this instance's constructor.
|
|
760
506
|
*
|
|
761
|
-
* @returns
|
|
507
|
+
* @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
|
|
762
508
|
*/
|
|
763
|
-
|
|
764
|
-
/**
|
|
765
|
-
* Returns a readonly copy of the sigil type symbol set for this instance's constructor.
|
|
766
|
-
*
|
|
767
|
-
* @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
|
|
768
|
-
*/
|
|
769
|
-
getSigilTypeSet(): Readonly<Set<symbol>>;
|
|
509
|
+
getSigilLabelSet(): Readonly<Set<string>>;
|
|
770
510
|
};
|
|
771
511
|
/**
|
|
772
512
|
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
@@ -783,28 +523,21 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
783
523
|
*/
|
|
784
524
|
get SigilLabel(): string;
|
|
785
525
|
/**
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
* This symbol is created with `Symbol.for(label)` during decoration so it is
|
|
789
|
-
* stable across realms that share the same global symbol registry.
|
|
790
|
-
*/
|
|
791
|
-
get SigilType(): symbol;
|
|
792
|
-
/**
|
|
793
|
-
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
526
|
+
* Copy of the linearized sigil type label chain for the current constructor.
|
|
794
527
|
*
|
|
795
528
|
* Useful for debugging and performing strict lineage comparisons.
|
|
796
529
|
*
|
|
797
|
-
* @returns An array of
|
|
530
|
+
* @returns An array of labels representing parent → child type labels.
|
|
798
531
|
*/
|
|
799
|
-
get
|
|
532
|
+
get SigilLabelLineage(): readonly string[];
|
|
800
533
|
/**
|
|
801
|
-
* Copy of the sigil type
|
|
534
|
+
* Copy of the sigil type label set for the current constructor.
|
|
802
535
|
*
|
|
803
536
|
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
804
537
|
*
|
|
805
|
-
* @returns A Readonly Set of
|
|
538
|
+
* @returns A Readonly Set of labels that represent the type lineage.
|
|
806
539
|
*/
|
|
807
|
-
get
|
|
540
|
+
get SigilLabelSet(): Readonly<Set<string>>;
|
|
808
541
|
/**
|
|
809
542
|
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
810
543
|
*
|
|
@@ -825,7 +558,7 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
825
558
|
*/
|
|
826
559
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
827
560
|
/**
|
|
828
|
-
* Strict lineage check: compares the type
|
|
561
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
829
562
|
*
|
|
830
563
|
* @typeParam T - The calling constructor type.
|
|
831
564
|
* @param this - The constructor performing the check.
|
|
@@ -839,7 +572,6 @@ declare function Sigilify<B extends Constructor, L extends string>(Base: B, labe
|
|
|
839
572
|
* helpers. Accept and return 'abstract' class.
|
|
840
573
|
*
|
|
841
574
|
* The returned class:
|
|
842
|
-
* - registers a stable symbol for the provided `label` (via `WithSigil`)
|
|
843
575
|
* - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
|
|
844
576
|
* - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
|
|
845
577
|
*
|
|
@@ -873,7 +605,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
873
605
|
*/
|
|
874
606
|
isOfType<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
875
607
|
/**
|
|
876
|
-
* Strict lineage check: compares the type
|
|
608
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
877
609
|
*
|
|
878
610
|
* Allows 'instanceof' like checks but in instances.
|
|
879
611
|
*
|
|
@@ -882,7 +614,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
882
614
|
* @param other - The object to test.
|
|
883
615
|
* @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
|
|
884
616
|
*/
|
|
885
|
-
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is
|
|
617
|
+
isOfTypeStrict<T_1>(this: T_1, other: unknown): other is GetInstance<T_1>;
|
|
886
618
|
/**
|
|
887
619
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
888
620
|
*
|
|
@@ -890,23 +622,17 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
890
622
|
*/
|
|
891
623
|
getSigilLabel(): string;
|
|
892
624
|
/**
|
|
893
|
-
* Returns the
|
|
894
|
-
*
|
|
895
|
-
* @returns The symbol that identifies this type at runtime.
|
|
896
|
-
*/
|
|
897
|
-
getSigilType(): symbol;
|
|
898
|
-
/**
|
|
899
|
-
* Returns a copy of the sigil type symbol lineage for this instance's constructor.
|
|
625
|
+
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
900
626
|
*
|
|
901
|
-
* @returns readonly array of
|
|
627
|
+
* @returns readonly array of labels representing the type lineage.
|
|
902
628
|
*/
|
|
903
|
-
|
|
629
|
+
getSigilLabelLineage(): readonly string[];
|
|
904
630
|
/**
|
|
905
|
-
* Returns a readonly copy of the sigil type
|
|
631
|
+
* Returns a readonly copy of the sigil type label set for this instance's constructor.
|
|
906
632
|
*
|
|
907
|
-
* @returns A Readonly Set of
|
|
633
|
+
* @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
|
|
908
634
|
*/
|
|
909
|
-
|
|
635
|
+
getSigilLabelSet(): Readonly<Set<string>>;
|
|
910
636
|
}) & {
|
|
911
637
|
/**
|
|
912
638
|
* Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
|
|
@@ -923,28 +649,21 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
923
649
|
*/
|
|
924
650
|
get SigilLabel(): string;
|
|
925
651
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
* This symbol is created with `Symbol.for(label)` during decoration so it is
|
|
929
|
-
* stable across realms that share the same global symbol registry.
|
|
930
|
-
*/
|
|
931
|
-
get SigilType(): symbol;
|
|
932
|
-
/**
|
|
933
|
-
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
652
|
+
* Copy of the linearized sigil type label chain for the current constructor.
|
|
934
653
|
*
|
|
935
654
|
* Useful for debugging and performing strict lineage comparisons.
|
|
936
655
|
*
|
|
937
|
-
* @returns An array of
|
|
656
|
+
* @returns An array of labels representing parent → child type labels.
|
|
938
657
|
*/
|
|
939
|
-
get
|
|
658
|
+
get SigilLabelLineage(): readonly string[];
|
|
940
659
|
/**
|
|
941
|
-
* Copy of the sigil type
|
|
660
|
+
* Copy of the sigil type label set for the current constructor.
|
|
942
661
|
*
|
|
943
662
|
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
944
663
|
*
|
|
945
|
-
* @returns A Readonly Set of
|
|
664
|
+
* @returns A Readonly Set of labels that represent the type lineage.
|
|
946
665
|
*/
|
|
947
|
-
get
|
|
666
|
+
get SigilLabelSet(): Readonly<Set<string>>;
|
|
948
667
|
/**
|
|
949
668
|
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
950
669
|
*
|
|
@@ -956,7 +675,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
956
675
|
* Check whether `other` is (or inherits from) the type represented by the calling constructor.
|
|
957
676
|
*
|
|
958
677
|
* Implementation detail:
|
|
959
|
-
* - Uses the other instance's `
|
|
678
|
+
* - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
|
|
960
679
|
* - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
961
680
|
*
|
|
962
681
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
@@ -969,7 +688,7 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
969
688
|
*/
|
|
970
689
|
isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
971
690
|
/**
|
|
972
|
-
* Strict lineage check: compares the type
|
|
691
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
973
692
|
*
|
|
974
693
|
* Implementation detail:
|
|
975
694
|
* - Works in O(n) time where n is the depth of the lineage.
|
|
@@ -983,4 +702,4 @@ declare function SigilifyAbstract<B extends ConstructorAbstract, L extends strin
|
|
|
983
702
|
isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
|
|
984
703
|
}) & B;
|
|
985
704
|
|
|
986
|
-
export { DEFAULT_LABEL_REGEX, type GetInstance, type ISigil, type ISigilInstance, type ISigilStatic,
|
|
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, updateOptions, withSigil, withSigilTyped };
|