@vicin/sigil 1.0.1 → 1.1.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.
Files changed (53) hide show
  1. package/README.md +157 -37
  2. package/dist/index.d.mts +777 -0
  3. package/dist/index.d.ts +777 -3
  4. package/dist/index.js +701 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +684 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +7 -4
  9. package/dist/core/classes.d.ts +0 -48
  10. package/dist/core/classes.d.ts.map +0 -1
  11. package/dist/core/classes.js +0 -18
  12. package/dist/core/classes.js.map +0 -1
  13. package/dist/core/decorator.d.ts +0 -28
  14. package/dist/core/decorator.d.ts.map +0 -1
  15. package/dist/core/decorator.js +0 -48
  16. package/dist/core/decorator.js.map +0 -1
  17. package/dist/core/enhancers.d.ts +0 -58
  18. package/dist/core/enhancers.d.ts.map +0 -1
  19. package/dist/core/enhancers.js +0 -101
  20. package/dist/core/enhancers.js.map +0 -1
  21. package/dist/core/helpers.d.ts +0 -192
  22. package/dist/core/helpers.d.ts.map +0 -1
  23. package/dist/core/helpers.js +0 -349
  24. package/dist/core/helpers.js.map +0 -1
  25. package/dist/core/index.d.ts +0 -9
  26. package/dist/core/index.d.ts.map +0 -1
  27. package/dist/core/index.js +0 -8
  28. package/dist/core/index.js.map +0 -1
  29. package/dist/core/mixin.d.ts +0 -115
  30. package/dist/core/mixin.d.ts.map +0 -1
  31. package/dist/core/mixin.js +0 -209
  32. package/dist/core/mixin.js.map +0 -1
  33. package/dist/core/options.d.ts +0 -74
  34. package/dist/core/options.d.ts.map +0 -1
  35. package/dist/core/options.js +0 -39
  36. package/dist/core/options.js.map +0 -1
  37. package/dist/core/registry.d.ts +0 -104
  38. package/dist/core/registry.d.ts.map +0 -1
  39. package/dist/core/registry.js +0 -174
  40. package/dist/core/registry.js.map +0 -1
  41. package/dist/core/symbols.d.ts +0 -96
  42. package/dist/core/symbols.d.ts.map +0 -1
  43. package/dist/core/symbols.js +0 -96
  44. package/dist/core/symbols.js.map +0 -1
  45. package/dist/core/types.d.ts +0 -169
  46. package/dist/core/types.d.ts.map +0 -1
  47. package/dist/core/types.js +0 -2
  48. package/dist/core/types.js.map +0 -1
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/utils/index.d.ts +0 -2
  51. package/dist/utils/index.d.ts.map +0 -1
  52. package/dist/utils/index.js +0 -2
  53. package/dist/utils/index.js.map +0 -1
@@ -0,0 +1,777 @@
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#registry 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#registry 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
+ /** -----------------------------------------
297
+ * Class and instance
298
+ * ----------------------------------------- */
299
+ /**
300
+ * Static-side interface describing methods and properties added to a class
301
+ * constructor when it is sigilized.
302
+ *
303
+ * The properties and methods described here mirror the getters and static
304
+ * predicates implemented by the `Sigilify` mixin.
305
+ *
306
+ * @template L - Narrow string literal type representing the label.
307
+ * @template US - Optinal original Untyped Sigil constructor type being augmented.
308
+ */
309
+ interface ISigilStatic<L extends string = string, US extends Function = never> {
310
+ /**
311
+ * Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
312
+ *
313
+ * - Provides a *type-only* unique marker that makes instances nominally
314
+ * distinct by label and allows propagation/merging of brand keys across inheritance.
315
+ * - Runtime: **no runtime value is required**; this property exists only for the type system.
316
+ *
317
+ * @remarks
318
+ * Consumers should not read or set this property at runtime. It is used by helper
319
+ * types (e.g. `SigilBrandOf`, `TypedSigil`) to extract/propagate compile-time brands.
320
+ */
321
+ readonly __SIGIL_BRAND__: Prettify<{
322
+ [k in L]: true;
323
+ } & SigilBrandOf<US>>;
324
+ /** Class-level label constant (human readable). */
325
+ readonly SigilLabel: string;
326
+ /** Class-level unique symbol used as the runtime type identifier. */
327
+ readonly SigilType: symbol;
328
+ /**
329
+ * Copy of the linearized sigil type symbol chain for the current constructor.
330
+ * Useful for debugging and strict lineage comparisons.
331
+ */
332
+ readonly SigilTypeLineage: readonly symbol[];
333
+ /**
334
+ * Copy of the sigil type symbol set for the current constructor. Useful for
335
+ * O(1) membership checks and debugging.
336
+ */
337
+ readonly SigilTypeSet: Readonly<Set<symbol>>;
338
+ /**
339
+ * Runtime check that determines whether `obj` is an instance produced by a
340
+ * sigil class.
341
+ *
342
+ * Note: the concrete implementation provided by the mixin delegates to
343
+ * `isSigilInstance`.
344
+ *
345
+ * @param obj - Value to test.
346
+ * @returns Type guard narrowing `obj` to `ISigil`.
347
+ */
348
+ isSigilified(obj: unknown): obj is ISigil;
349
+ /**
350
+ * Check whether `other` is (or inherits from) the type represented by the
351
+ * calling constructor. Uses the other instance's `SigilTypeSet` to check
352
+ * membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
353
+ *
354
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
355
+ * and when subclassing.
356
+ *
357
+ * @typeParam T - The specific sigil constructor (`this`).
358
+ * @param this - The constructor performing the type check.
359
+ * @param other - The object to test.
360
+ * @returns A type guard asserting `other` is an instance of the constructor.
361
+ */
362
+ isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
363
+ /**
364
+ * Strict lineage comparison: verifies that the calling constructor's type
365
+ * lineage (by symbol) matches the `other`'s lineage element-by-element.
366
+ *
367
+ * Works in O(n) where `n` is the lineage length and is useful when order
368
+ * and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
369
+ *
370
+ * @typeParam T - The specific sigil constructor (`this`).
371
+ * @param this - The constructor performing the strict check.
372
+ * @param other - The object to test.
373
+ * @returns A type guard asserting `other` is an instance whose lineage matches exactly.
374
+ */
375
+ isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
376
+ }
377
+ /**
378
+ * Instance-side interface describing properties present on sigil instances.
379
+ * The methods mirror the instance helpers injected by the mixin.
380
+ *
381
+ * @template L - Narrow string literal type for the label returned by `getSigilLabel`.
382
+ * @template US - Optinal original Untyped Sigil constructor type being augmented.
383
+ */
384
+ interface ISigilInstance<L extends string = string, US extends Function = never> {
385
+ /**
386
+ * Compile-time nominal brand that encodes the class label `L` plus parent's brand keys `BrandOf<P>`.
387
+ *
388
+ * - Provides a *type-only* unique marker that makes instances nominally
389
+ * distinct by label and allows propagation/merging of brand keys across inheritance.
390
+ * - Runtime: **no runtime value is required**; this property exists only for the type system.
391
+ *
392
+ * @remarks
393
+ * Consumers should not read or set this property at runtime. It is used by helper
394
+ * types (e.g. `SigilBrandOf`, `TypedSigil`) to extract/propagate compile-time brands.
395
+ */
396
+ readonly __SIGIL_BRAND__: Prettify<{
397
+ [k in L]: true;
398
+ } & SigilBrandOf<US>>;
399
+ /** Returns human-readable sigil label of the class constructor. */
400
+ getSigilLabel(): string;
401
+ /** Returns runtime sigil type symbol of the class constructor. */
402
+ getSigilType(): symbol;
403
+ /** Returns copy of sigil type symbol lineage of the class constructor. */
404
+ getSigilTypeLineage(): readonly symbol[];
405
+ /** Returns copy of sigil type symbol set of the class constructor. */
406
+ getSigilTypeSet(): Readonly<Set<symbol>>;
407
+ }
408
+ /**
409
+ * Combined constructor + static interface for a sigil class.
410
+ *
411
+ * This composes the instance-side shape (Constructor<ISigilInstance<L>>) with
412
+ * the static-side interface (ISigilStatic<L>), matching the runtime shape added
413
+ * by `Sigilify`.
414
+ *
415
+ * @template L - Narrow string literal type for the label.
416
+ * @template US - Optinal original Untyped Sigil constructor type being augmented.
417
+ */
418
+ type ISigil<L extends string = string, US extends Function = never> = Constructor<ISigilInstance<L, US>> & ISigilStatic<L, US>;
419
+ /** -----------------------------------------
420
+ * Helper sigil types
421
+ * ----------------------------------------- */
422
+ /**
423
+ * Extract the compile-time brand map from a sigil constructor `S`.
424
+ *
425
+ * @typeParam S - A sigil constructor type (e.g. `typeof SomeSigilClass`).
426
+ * @returns The brand record carried on the constructor's instance type (e.g. `{ User: true, Admin: true }`).
427
+ *
428
+ * @remarks
429
+ * - This helper is used purely at the type level to compute the set of brand keys
430
+ * that should be propagated to derived sigils.
431
+ * - If `S` does not carry a `__SIGIL_BRAND__`, the resulting type is `never` and `IfNever<>`
432
+ * collapses it to an empty record.
433
+ */
434
+ type SigilBrandOf<S> = IfNever<S extends {
435
+ readonly __SIGIL_BRAND__: infer Brand;
436
+ } ? Prettify<Brand> : never, Record<string, true>>;
437
+ /**
438
+ * Combine an existing sigil constructor type `S` with a **new** label `L`,
439
+ * while inheriting/propagating compile-time brands from an optional parent sigil `P`.
440
+ *
441
+ * @template US - The original Untyped Sigil constructor type being augmented.
442
+ * @template L - The new label literal to associate with the resulting constructor.
443
+ */
444
+ type TypedSigil<US extends Function, L extends string = string> = US & ISigil<L, US>;
445
+ /**
446
+ * Generic helper extract instance of the class even in protected and private constructors.
447
+ */
448
+ type GetInstance<T> = T extends {
449
+ prototype: infer R;
450
+ } ? Prettify<R & {
451
+ __SIGIL_BRAND__: SigilBrandOf<T>;
452
+ }> : never;
453
+ /** -----------------------------------------
454
+ * Generic types
455
+ * ----------------------------------------- */
456
+ /**
457
+ * Generic type for class constructors used by the Sigil utilities.
458
+ *
459
+ * - `T` is the instance type produced by the constructor.
460
+ * - `P` is the tuple of parameter types accepted by the constructor.
461
+ *
462
+ * @template T - Instance type produced by the constructor (defaults to `object`).
463
+ * @template P - Parameter tuple type for the constructor.
464
+ */
465
+ type Constructor<T = object, P extends any[] = any[]> = new (...args: P) => T;
466
+ /** Helper type to prettify value. */
467
+ type Prettify<T> = {
468
+ [K in keyof T]: T[K];
469
+ } & {};
470
+ /** Helper type to replace 'never' with another type */
471
+ type IfNever<T, R = {}> = [T] extends [never] ? R : T;
472
+
473
+ /**
474
+ * A minimal root Sigil class used by the library as a base identity.
475
+ *
476
+ * This is produced by `Sigilify` and can serve as a basic sentinel/base
477
+ * class for other sigil classes or for debugging/inspection.
478
+ */
479
+ declare const Sigil: {
480
+ new (...args: any[]): {
481
+ readonly __SIGIL_BRAND__: Record<string, true>;
482
+ getSigilLabel(): string;
483
+ getSigilType(): symbol;
484
+ getSigilTypeLineage(): readonly symbol[];
485
+ getSigilTypeSet(): Readonly<Set<symbol>>;
486
+ };
487
+ readonly __SIGIL_BRAND__: Record<string, true>;
488
+ get SigilLabel(): string;
489
+ get SigilType(): symbol;
490
+ get SigilTypeLineage(): readonly symbol[];
491
+ get SigilTypeSet(): Readonly<Set<symbol>>;
492
+ isSigilified(obj: unknown): obj is ISigil;
493
+ isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
494
+ isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
495
+ };
496
+ /**
497
+ * A sigil variant of the built-in `Error` constructor used by the library
498
+ * to represent Sigil-specific errors.
499
+ *
500
+ * Use `SigilError` when you want an Error type that is identifiable via sigil
501
+ * runtime checks (e.g. `SigilError.isOfType(someError)`).
502
+ */
503
+ declare const SigilError: {
504
+ new (...args: any[]): {
505
+ readonly __SIGIL_BRAND__: Record<string, true>;
506
+ getSigilLabel(): string;
507
+ getSigilType(): symbol;
508
+ getSigilTypeLineage(): readonly symbol[];
509
+ getSigilTypeSet(): Readonly<Set<symbol>>;
510
+ };
511
+ readonly __SIGIL_BRAND__: Record<string, true>;
512
+ get SigilLabel(): string;
513
+ get SigilType(): symbol;
514
+ get SigilTypeLineage(): readonly symbol[];
515
+ get SigilTypeSet(): Readonly<Set<symbol>>;
516
+ isSigilified(obj: unknown): obj is ISigil;
517
+ isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
518
+ isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
519
+ };
520
+
521
+ /**
522
+ * Class decorator factory that attaches sigil statics to a class constructor.
523
+ *
524
+ * Usage:
525
+ * ```ts
526
+ * @WithSigil('@myorg/mypkg.MyClass')
527
+ * class MyClass { ... }
528
+ * ```
529
+ *
530
+ * The returned decorator:
531
+ * - validates the provided label (via `verifyLabel`)
532
+ * - performs inheritance checks (via `checkInheritance`) in DEV builds
533
+ * - attaches sigil-related statics to the constructor (via `decorateCtor`)
534
+ *
535
+ * Notes:
536
+ * - This decorator is intended to be applied to classes only. When used
537
+ * incorrectly (e.g. on a property), it is a no-op.
538
+ * - Throws an error during class creation if the label validation fails.
539
+ *
540
+ * @typeParam L - Narrow string literal type for the provided label.
541
+ * @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
542
+ * If not passed a random label is generated instead.
543
+ * @param opts - Options object to override any global options if needed.
544
+ * @returns A class decorator compatible with the ECMAScript decorator context.
545
+ */
546
+ declare function WithSigil<L extends string>(label?: L, opts?: SigilOptions): (value: Function, context: ClassDecoratorContext) => void;
547
+
548
+ /**
549
+ * HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
550
+ * Alternative to '@WithSigil' if you prefer HOFs.
551
+ *
552
+ * This does both:
553
+ * - validate (and autofill) a label,
554
+ * - perform runtime decoration (via `decorateCtor`),
555
+ *
556
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
557
+ * decorated; we handle this gracefully in DEV to support HMR flows.
558
+ *
559
+ * @typeParam S - Constructor type (should be an ISigil).
560
+ * @typeParam L - Label literal to attach.
561
+ * @param Class - The constructor (class) to enhance.
562
+ * @param label - Optional label string. If omitted, a random label is generated.
563
+ * @param opts - Options object to override any global options if needed.
564
+ * @returns The same constructor value, with runtime metadata ensured.
565
+ */
566
+ declare function withSigil<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): S;
567
+ /**
568
+ * Narrow a constructor to a compile-time `TypedSigil` without modifying runtime.
569
+ *
570
+ * This is a *purely type-level* helper (no runtime changes). It optionally
571
+ * verifies in DEV that the runtime `SigilLabel` matches the provided `label`.
572
+ *
573
+ * Use this when the runtime metadata is already present (for example the class
574
+ * is already decorated or was created via `Sigilify`).
575
+ *
576
+ * @typeParam S - Constructor type (should be an ISigil).
577
+ * @typeParam L - Label literal to associate at compile-time.
578
+ * @param Class - The constructor to assert as typed sigil.
579
+ * @param label - Optional label literal to assert at compile-time (and to verify in DEV).
580
+ * @returns The same constructor value, typed as `TypedSigil<S, L, P>`.
581
+ */
582
+ declare function typed<S extends Function, L extends string = string>(Class: S, label?: L, opts?: Pick<SigilOptions, 'devMarker'>): TypedSigil<S, L>;
583
+ /**
584
+ * Convenience helper that combine 'withSigil' and 'typeSigil'.
585
+ *
586
+ * This does both:
587
+ * - validate (and autofill) a label,
588
+ * - perform runtime decoration (via `decorateCtor`),
589
+ * - return the constructor typed as `TypedSigil`.
590
+ *
591
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
592
+ * decorated; we handle this gracefully in DEV to support HMR flows.
593
+ *
594
+ * @typeParam S - Constructor type (should be an ISigil).
595
+ * @typeParam L - Label literal to attach.
596
+ * @param Class - The constructor (class) to decorate and type.
597
+ * @param label - Optional label string. If omitted, a random label is generated.
598
+ * @param parent - Optional parent sigil constructor (type-only).
599
+ * @param opts - Options object to override any global options if needed.
600
+ * @returns The same constructor value, with runtime metadata ensured and typed as `TypedSigil<S,L,P>`.
601
+ */
602
+ declare function withSigilTyped<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): TypedSigil<S, L>;
603
+
604
+ /**
605
+ * Runtime predicate that checks whether the provided value is a sigil constructor.
606
+ *
607
+ * This is a lightweight check that verifies the presence of an internal
608
+ * symbol attached to the constructor.
609
+ *
610
+ * @param value - Value to test.
611
+ * @returns `true` if `value` is a sigil constructor, otherwise `false`.
612
+ */
613
+ declare function isSigilCtor(value: unknown): value is ISigil;
614
+ /**
615
+ * Runtime predicate that checks whether the provided object is an instance
616
+ * of a sigil class.
617
+ *
618
+ * The function is defensive: non-objects return `false`. If an object is
619
+ * passed, the object's constructor is resolved and tested with `isSigilCtor`.
620
+ *
621
+ * @param obj - The value to test.
622
+ * @returns `true` if `obj` is an instance produced by a sigil constructor.
623
+ */
624
+ declare function isSigilInstance(obj: unknown): obj is ISigilInstance;
625
+ /**
626
+ * Check whether the provided constructor was marked as a sigil base constructor.
627
+ *
628
+ * Uses `Object.hasOwn` to ensure we only check own properties.
629
+ *
630
+ * @param ctor - Constructor to check.
631
+ * @returns `true` if `ctor` is a sigil base constructor.
632
+ */
633
+ declare function isSigilBaseCtor(ctor: Function): boolean;
634
+ /**
635
+ * Check whether the provided object is an instance of a sigil base constructor.
636
+ *
637
+ * This resolves the object's constructor and delegates to `isSigilBaseCtor`.
638
+ *
639
+ * @param obj - The object to test.
640
+ * @returns `true` if `obj` is an instance of a sigil base constructor.
641
+ */
642
+ declare function isSigilBaseInstance(obj: unknown): obj is ISigilInstance;
643
+ /**
644
+ * Returns whether the constructor has been explicitly decorated with `WithSigil`.
645
+ *
646
+ * This is an own-property check and does not traverse the prototype chain.
647
+ *
648
+ * @internal
649
+ * @param ctor - Constructor to test.
650
+ * @returns `true` if the constructor is explicitly decorated.
651
+ */
652
+ declare function isDecorated(ctor: Function): boolean;
653
+ /**
654
+ * Returns whether inheritance checks have already been performed for the constructor.
655
+ *
656
+ * This is used to avoid repeated checks during development (DEV-only checks).
657
+ *
658
+ * @internal
659
+ * @param ctor - Constructor to test.
660
+ * @returns `true` if inheritance checks were marked as completed.
661
+ */
662
+ declare function isInheritanceChecked(ctor: Function): boolean;
663
+
664
+ /**
665
+ * Mixin factory that augments an existing class with Sigil runtime metadata and
666
+ * helpers. The returned class:
667
+ * - registers a stable symbol for the provided `label` (via `WithSigil`)
668
+ * - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
669
+ * - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
670
+ *
671
+ * Notes:
672
+ * - Uses `Symbol.for(label)` internally so symbols are stable across bundles/realms
673
+ * that share the global symbol registry.
674
+ * - Throws if `Base` is already a sigil constructor.
675
+ *
676
+ * @param Base - The base constructor to extend.
677
+ * @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
678
+ * If not passed a random label is generated instead.
679
+ * @param opts - Options object to override any global options if needed.
680
+ * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
681
+ * @throws Error if `Base` is already sigilized.
682
+ */
683
+ declare function Sigilify(Base: Constructor, label?: string, opts?: SigilOptions): {
684
+ new (...args: any[]): {
685
+ readonly __SIGIL_BRAND__: Record<string, true>;
686
+ /**
687
+ * Returns the human-readable sigil label of this instance's constructor.
688
+ *
689
+ * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
690
+ */
691
+ getSigilLabel(): string;
692
+ /**
693
+ * Returns the runtime sigil type symbol of this instance's constructor.
694
+ *
695
+ * @returns The symbol that identifies this type at runtime.
696
+ */
697
+ getSigilType(): symbol;
698
+ /**
699
+ * Returns a copy of the sigil type symbol lineage for this instance's constructor.
700
+ *
701
+ * @returns readonly array of symbols representing the type lineage.
702
+ */
703
+ getSigilTypeLineage(): readonly symbol[];
704
+ /**
705
+ * Returns a readonly copy of the sigil type symbol set for this instance's constructor.
706
+ *
707
+ * @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
708
+ */
709
+ getSigilTypeSet(): Readonly<Set<symbol>>;
710
+ };
711
+ readonly __SIGIL_BRAND__: Record<string, true>;
712
+ /**
713
+ * Class-level human-readable label constant for this sigil constructor.
714
+ */
715
+ get SigilLabel(): string;
716
+ /**
717
+ * Class-level unique runtime symbol used as the type identifier.
718
+ *
719
+ * This symbol is created with `Symbol.for(label)` during decoration so it is
720
+ * stable across realms that share the same global symbol registry.
721
+ */
722
+ get SigilType(): symbol;
723
+ /**
724
+ * Copy of the linearized sigil type symbol chain for the current constructor.
725
+ *
726
+ * Useful for debugging and performing strict lineage comparisons.
727
+ *
728
+ * @returns An array of symbols representing parent → child type symbols.
729
+ */
730
+ get SigilTypeLineage(): readonly symbol[];
731
+ /**
732
+ * Copy of the sigil type symbol set for the current constructor.
733
+ *
734
+ * Useful for quick membership checks (O(1) lookups) and debugging.
735
+ *
736
+ * @returns A Readonly Set of symbols that represent the type lineage.
737
+ */
738
+ get SigilTypeSet(): Readonly<Set<symbol>>;
739
+ /**
740
+ * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
741
+ *
742
+ * @param obj - The value to test.
743
+ * @returns `true` if `obj` is a sigil instance.
744
+ */
745
+ isSigilified(obj: unknown): obj is ISigil;
746
+ /**
747
+ * Check whether `other` is (or inherits from) the type represented by the calling constructor.
748
+ *
749
+ * Implementation detail:
750
+ * - Uses the other instance's `__TYPE_SET__` for O(1) membership test.
751
+ * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
752
+ *
753
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
754
+ * and when subclassing.
755
+ *
756
+ * @typeParam T - The calling constructor type (narrowing the returned instance type).
757
+ * @param this - The constructor performing the check.
758
+ * @param other - The object to test.
759
+ * @returns `true` if `other` is an instance of this type or a subtype.
760
+ */
761
+ isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
762
+ /**
763
+ * Strict lineage check: compares the type symbol lineage arrays element-by-element.
764
+ *
765
+ * Implementation detail:
766
+ * - Works in O(n) time where n is the depth of the lineage.
767
+ * - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
768
+ *
769
+ * @typeParam T - The calling constructor type.
770
+ * @param this - The constructor performing the check.
771
+ * @param other - The object to test.
772
+ * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
773
+ */
774
+ isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
775
+ };
776
+
777
+ export { DEFAULT_LABEL_REGEX, type GetInstance, type ISigil, type ISigilInstance, type ISigilStatic, REGISTRY, Sigil, type SigilBrandOf, SigilError, type SigilOptions, SigilRegistry, Sigilify, type TypedSigil, WithSigil, getActiveRegistry, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, typed, updateOptions, withSigil, withSigilTyped };