@vicin/sigil 1.0.1 → 1.1.1

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 (55) 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.global.js +707 -0
  5. package/dist/index.global.js.map +1 -0
  6. package/dist/index.js +701 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +684 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/package.json +7 -4
  11. package/dist/core/classes.d.ts +0 -48
  12. package/dist/core/classes.d.ts.map +0 -1
  13. package/dist/core/classes.js +0 -18
  14. package/dist/core/classes.js.map +0 -1
  15. package/dist/core/decorator.d.ts +0 -28
  16. package/dist/core/decorator.d.ts.map +0 -1
  17. package/dist/core/decorator.js +0 -48
  18. package/dist/core/decorator.js.map +0 -1
  19. package/dist/core/enhancers.d.ts +0 -58
  20. package/dist/core/enhancers.d.ts.map +0 -1
  21. package/dist/core/enhancers.js +0 -101
  22. package/dist/core/enhancers.js.map +0 -1
  23. package/dist/core/helpers.d.ts +0 -192
  24. package/dist/core/helpers.d.ts.map +0 -1
  25. package/dist/core/helpers.js +0 -349
  26. package/dist/core/helpers.js.map +0 -1
  27. package/dist/core/index.d.ts +0 -9
  28. package/dist/core/index.d.ts.map +0 -1
  29. package/dist/core/index.js +0 -8
  30. package/dist/core/index.js.map +0 -1
  31. package/dist/core/mixin.d.ts +0 -115
  32. package/dist/core/mixin.d.ts.map +0 -1
  33. package/dist/core/mixin.js +0 -209
  34. package/dist/core/mixin.js.map +0 -1
  35. package/dist/core/options.d.ts +0 -74
  36. package/dist/core/options.d.ts.map +0 -1
  37. package/dist/core/options.js +0 -39
  38. package/dist/core/options.js.map +0 -1
  39. package/dist/core/registry.d.ts +0 -104
  40. package/dist/core/registry.d.ts.map +0 -1
  41. package/dist/core/registry.js +0 -174
  42. package/dist/core/registry.js.map +0 -1
  43. package/dist/core/symbols.d.ts +0 -96
  44. package/dist/core/symbols.d.ts.map +0 -1
  45. package/dist/core/symbols.js +0 -96
  46. package/dist/core/symbols.js.map +0 -1
  47. package/dist/core/types.d.ts +0 -169
  48. package/dist/core/types.d.ts.map +0 -1
  49. package/dist/core/types.js +0 -2
  50. package/dist/core/types.js.map +0 -1
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/utils/index.d.ts +0 -2
  53. package/dist/utils/index.d.ts.map +0 -1
  54. package/dist/utils/index.js +0 -2
  55. package/dist/utils/index.js.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,684 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
4
+
5
+ // src/core/options.ts
6
+ var OPTIONS = {
7
+ labelValidation: null,
8
+ skipLabelInheritanceCheck: false,
9
+ autofillLabels: false,
10
+ devMarker: false,
11
+ registry: null,
12
+ useGlobalRegistry: false,
13
+ storeConstructor: false
14
+ };
15
+ var __SIGIL_REGISTRY__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_REGISTRY__");
16
+ var updateGlobalRegistry = (map) => {
17
+ if (map === null) delete globalThis[__SIGIL_REGISTRY__];
18
+ else globalThis[__SIGIL_REGISTRY__] = map;
19
+ };
20
+ var getGlobalRegistry = () => {
21
+ const val = globalThis[__SIGIL_REGISTRY__];
22
+ return val === void 0 ? null : val;
23
+ };
24
+ var SigilRegistry = class _SigilRegistry {
25
+ /**
26
+ * @param map - Map used to register 'Sigil' classes. if not passed it will be auto-generated internally.
27
+ */
28
+ constructor(map) {
29
+ /** Internal private registry map. */
30
+ __publicField(this, "_registry");
31
+ this._registry = map != null ? map : /* @__PURE__ */ new Map();
32
+ }
33
+ /**
34
+ * Return a readonly view (array) of the current registry entries.
35
+ *
36
+ * @returns An array containing all registered labels, or an empty array when registry is disabled.
37
+ */
38
+ listLabels() {
39
+ return this._registry ? Array.from(this._registry.keys()) : [];
40
+ }
41
+ /**
42
+ * Determine whether the registry currently contains `label`.
43
+ *
44
+ * @param label - The label to test.
45
+ * @returns `true` if present; `false` otherwise.
46
+ */
47
+ has(label) {
48
+ return !!this._registry && this._registry.has(label);
49
+ }
50
+ /**
51
+ * Get class constructor using its label.
52
+ *
53
+ * @param label - Label appended to Sigil class.
54
+ * @returns Reference to Sigil class constructor or null if stored with 'SigilOptions.storeConstructor = false'.
55
+ */
56
+ get(label) {
57
+ var _a;
58
+ return (_a = this._registry.get(label)) != null ? _a : null;
59
+ }
60
+ /**
61
+ * Register a label and class constructor in the active registry.
62
+ *
63
+ * If the label already exists then:
64
+ * - In DEV builds: prints a console warning (HMR friendly) and returns early.
65
+ * - In non-DEV builds: throws an Error to prevent duplicate registration.
66
+ *
67
+ * @param label - Label string to register (e.g. '@scope/pkg.ClassName').
68
+ * @param Class - Constructor of the class being registered.
69
+ * @param opts - Optional per-call overrides.
70
+ */
71
+ register(label, Class, opts) {
72
+ var _a, _b, _c, _d;
73
+ if (!OPTIONS.registry) return;
74
+ const storeCtor = (_a = opts == null ? void 0 : opts.storeConstructor) != null ? _a : OPTIONS.storeConstructor;
75
+ const devMarker = (_b = opts == null ? void 0 : opts.devMarker) != null ? _b : OPTIONS.devMarker;
76
+ if (this._registry.has(label)) {
77
+ const existing = this._registry.get(label);
78
+ const isLikelyHMR = (existing == null ? void 0 : existing.name) === (Class == null ? void 0 : Class.name);
79
+ if (devMarker) {
80
+ if (isLikelyHMR) {
81
+ console.warn(
82
+ `[Sigil] Duplicate label "${label}" may be due to HMR \u2014 ignore if you are sure that it's defined once.`
83
+ );
84
+ } else {
85
+ throw new Error(
86
+ `[Sigil Error] Duplicate label '${label}' (different classes: ${(_c = existing == null ? void 0 : existing.name) != null ? _c : "unknown"} vs ${(_d = Class == null ? void 0 : Class.name) != null ? _d : "unknown"}).`
87
+ );
88
+ }
89
+ } else {
90
+ throw new Error(
91
+ `[Sigil Error] Duplicate label '${label}' detected. Labels must be unique.`
92
+ );
93
+ }
94
+ } else {
95
+ this._registry.set(label, storeCtor ? Class : null);
96
+ }
97
+ }
98
+ /**
99
+ * Alias for 'SigilRegistry.register'.
100
+ *
101
+ * @param label - Label string to register (e.g. '@scope/pkg.ClassName').
102
+ * @param Class - Constructor of the class being registered.
103
+ * @param opts - Optional per-call overrides.
104
+ */
105
+ set(label, Class, opts) {
106
+ return this.register(label, Class, opts);
107
+ }
108
+ /**
109
+ * Unregister a previously registered class.
110
+ *
111
+ * @param label - The label to remove from the registry.
112
+ * @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
113
+ */
114
+ unregister(label) {
115
+ return this._registry.delete(label);
116
+ }
117
+ /**
118
+ * Alias for 'SigilRegistry.unregister'.
119
+ *
120
+ * @param label - The label to remove from the registry.
121
+ * @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
122
+ */
123
+ delete(label) {
124
+ return this.unregister(label);
125
+ }
126
+ /**
127
+ * Replace active registry with new one. deprecated use 'updateOptions({ registry: newRegistry })' instead.
128
+ *
129
+ * @deprecated Will be removed in v2.0.0, check https://www.npmjs.com/package/@vicin/sigil?activeTab=readme#registry for more details.
130
+ * @param newRegistry - New Set<string> instance to use as the active registry, or `null` to disable checks.
131
+ */
132
+ replaceRegistry(newRegistry) {
133
+ if (newRegistry)
134
+ updateOptions({ registry: new _SigilRegistry(newRegistry) });
135
+ else updateOptions({ registry: newRegistry });
136
+ }
137
+ /**
138
+ * Clear the registry completely.
139
+ *
140
+ * Useful for test teardown, or when explicitly resetting state during development.
141
+ * No-op when the registry is disabled.
142
+ */
143
+ clear() {
144
+ this._registry.clear();
145
+ }
146
+ /**
147
+ * Merge another SigilRegistry into this one.
148
+ *
149
+ * Entries from `other` will be registered into this registry. Duplicate labels
150
+ * are handled via this registry's `register` logic (i.e., will warn in DEV or
151
+ * throw in production).
152
+ *
153
+ * @param other - Another `SigilRegistry` whose entries will be merged into this registry.
154
+ */
155
+ merge(other) {
156
+ if (!OPTIONS.registry) return;
157
+ for (const [label, ctor] of other) this.register(label, ctor);
158
+ }
159
+ /**
160
+ * Return a Map-style iterator over entries: `[label, constructor]`.
161
+ * Equivalent to calling `registry[Symbol.iterator]()`.
162
+ *
163
+ * @returns IterableIterator of `[label, ISigil]`.
164
+ */
165
+ entries() {
166
+ return this._registry.entries();
167
+ }
168
+ /**
169
+ * Return an iterator over registered constructors.
170
+ *
171
+ * @returns IterableIterator of `ISigil` constructors.
172
+ */
173
+ values() {
174
+ return this._registry.values();
175
+ }
176
+ /**
177
+ * Return an iterator over registered labels (keys).
178
+ *
179
+ * @returns IterableIterator of `string` labels.
180
+ */
181
+ keys() {
182
+ return this._registry.keys();
183
+ }
184
+ /**
185
+ * Execute a provided function once per registry entry.
186
+ *
187
+ * @param callback - Function invoked with `(ctor, label)` for each entry.
188
+ * @param thisArg - Optional `this` context for the callback.
189
+ */
190
+ forEach(callback, thisArg) {
191
+ this._registry.forEach(
192
+ (ctor, label) => callback.call(thisArg, ctor, label)
193
+ );
194
+ }
195
+ /**
196
+ * Get the size (number of entries) of the active registry.
197
+ *
198
+ * @returns The number of registered labels, or 0 when registry is disabled.
199
+ */
200
+ get size() {
201
+ return this._registry.size;
202
+ }
203
+ /**
204
+ * Return an iterator over `[label, constructor]` pairs.
205
+ *
206
+ * This makes the registry compatible with `for..of` and other iterable helpers:
207
+ * ```ts
208
+ * for (const [label, ctor] of registry) { ... }
209
+ * ```
210
+ *
211
+ * @returns An iterable iterator that yields `[label, ISigil]` tuples.
212
+ */
213
+ [Symbol.iterator]() {
214
+ return this._registry[Symbol.iterator]();
215
+ }
216
+ };
217
+ var getActiveRegistry = () => {
218
+ const globalRegistry = getGlobalRegistry();
219
+ if (globalRegistry) return globalRegistry;
220
+ return OPTIONS.registry;
221
+ };
222
+ var REGISTRY = OPTIONS.registry;
223
+ var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
224
+ var updateOptions = (opts, mergeRegistries = true) => {
225
+ applyBeforeSideEffects(OPTIONS, opts, mergeRegistries);
226
+ for (const [k, v] of Object.entries(opts)) OPTIONS[k] = v;
227
+ applyAfterSideEffects(OPTIONS);
228
+ };
229
+ function applyBeforeSideEffects(oldOpts, newOpts, mergeRegistries) {
230
+ if (mergeRegistries && newOpts.registry && oldOpts.registry)
231
+ newOpts.registry.merge(oldOpts.registry);
232
+ }
233
+ function applyAfterSideEffects(opts) {
234
+ if (opts.useGlobalRegistry) updateGlobalRegistry(opts.registry);
235
+ else updateGlobalRegistry(null);
236
+ if (OPTIONS.registry) REGISTRY = OPTIONS.registry;
237
+ else REGISTRY = new SigilRegistry();
238
+ }
239
+ var DEFAULT_OPTIONS = {
240
+ labelValidation: null,
241
+ skipLabelInheritanceCheck: false,
242
+ autofillLabels: false,
243
+ devMarker: process.env.NODE_ENV !== "production",
244
+ registry: new SigilRegistry(),
245
+ useGlobalRegistry: true,
246
+ storeConstructor: true
247
+ };
248
+ updateOptions(DEFAULT_OPTIONS);
249
+
250
+ // src/core/symbols.ts
251
+ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
252
+ var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
253
+ var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
254
+ var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for(
255
+ "@Sigil.__INHERITANCE_CHECKED__"
256
+ );
257
+ var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
258
+ var __TYPE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE__");
259
+ var __TYPE_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE_LINEAGE__");
260
+ var __TYPE_SET__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE_SET__");
261
+
262
+ // src/core/helpers.ts
263
+ function decorateCtor(ctor, label, opts) {
264
+ var _a;
265
+ if (isDecorated(ctor))
266
+ throw new Error(
267
+ `Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`
268
+ );
269
+ const symbol = Symbol.for(label);
270
+ (_a = getActiveRegistry()) == null ? void 0 : _a.register(label, ctor, opts);
271
+ Object.defineProperty(ctor, __LABEL__, {
272
+ value: label,
273
+ configurable: false,
274
+ enumerable: false,
275
+ writable: false
276
+ });
277
+ Object.defineProperty(ctor, __TYPE__, {
278
+ value: symbol,
279
+ configurable: false,
280
+ enumerable: false,
281
+ writable: false
282
+ });
283
+ const parent = Object.getPrototypeOf(ctor);
284
+ const parentChain = parent && parent[__TYPE_LINEAGE__] ? parent[__TYPE_LINEAGE__] : [];
285
+ const ctorChain = [...parentChain, symbol];
286
+ Object.defineProperty(ctor, __TYPE_LINEAGE__, {
287
+ value: ctorChain,
288
+ configurable: false,
289
+ enumerable: false,
290
+ writable: false
291
+ });
292
+ Object.defineProperty(ctor, __TYPE_SET__, {
293
+ value: new Set(ctorChain),
294
+ configurable: false,
295
+ enumerable: false,
296
+ writable: false
297
+ });
298
+ markDecorated(ctor);
299
+ }
300
+ function checkInheritance(ctor, opts) {
301
+ var _a, _b, _c;
302
+ const devMarker = (_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker;
303
+ const skipLabelInheritanceCheck = (_b = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _b : OPTIONS.skipLabelInheritanceCheck;
304
+ const autofillLabels = (_c = opts == null ? void 0 : opts.autofillLabels) != null ? _c : OPTIONS.autofillLabels;
305
+ if (!devMarker) return;
306
+ if (!isSigilCtor(ctor)) return;
307
+ if (isInheritanceChecked(ctor) || skipLabelInheritanceCheck) return;
308
+ const ctors = [ctor];
309
+ let ancestor = Object.getPrototypeOf(ctor);
310
+ while (isSigilCtor(ancestor)) {
311
+ ctors.push(ancestor);
312
+ ancestor = Object.getPrototypeOf(ancestor);
313
+ }
314
+ const labelOwner = /* @__PURE__ */ new Map();
315
+ for (let i = ctors.length - 1; i >= 0; i--) {
316
+ const ctor2 = ctors[i];
317
+ if (!ctor2) continue;
318
+ let label = ctor2.SigilLabel;
319
+ if (labelOwner.has(label)) {
320
+ if (isDecorated(ctor2) || !autofillLabels) {
321
+ const ancestorName = labelOwner.get(label);
322
+ throw new Error(
323
+ `[Sigil Error] Class "${ctor2.name}" re-uses Sigil label "${label}" from ancestor "${ancestorName}". Each Sigil subclass must use a unique label. Did you forget to use "WithSigil(newLabel)" on the subclass?`
324
+ );
325
+ }
326
+ label = generateRandomLabel();
327
+ decorateCtor(ctor2, label, opts);
328
+ }
329
+ labelOwner.set(label, ctor2.name);
330
+ }
331
+ markInheritanceChecked(ctor);
332
+ }
333
+ function verifyLabel(label, opts) {
334
+ var _a;
335
+ const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
336
+ if (labelValidation) {
337
+ let valid;
338
+ if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
339
+ else valid = labelValidation(label);
340
+ if (!valid)
341
+ throw new Error(
342
+ `[Sigil] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function.`
343
+ );
344
+ }
345
+ }
346
+ function generateRandomLabel(length = 16) {
347
+ let label = generateRandomString(length);
348
+ const registry = getActiveRegistry();
349
+ if (registry) while (registry.has(label)) label = generateRandomLabel();
350
+ return `@Sigil.auto-${label}`;
351
+ }
352
+ function markSigil(ctor) {
353
+ Object.defineProperty(ctor, __SIGIL__, {
354
+ value: true,
355
+ configurable: false,
356
+ enumerable: false,
357
+ writable: false
358
+ });
359
+ }
360
+ function markSigilBase(ctor) {
361
+ Object.defineProperty(ctor, __SIGIL_BASE__, {
362
+ value: true,
363
+ configurable: false,
364
+ enumerable: false,
365
+ writable: false
366
+ });
367
+ }
368
+ function markDecorated(ctor) {
369
+ Object.defineProperty(ctor, __DECORATED__, {
370
+ value: true,
371
+ configurable: false,
372
+ enumerable: false,
373
+ writable: false
374
+ });
375
+ }
376
+ function markInheritanceChecked(ctor) {
377
+ Object.defineProperty(ctor, __INHERITANCE_CHECKED__, {
378
+ value: true,
379
+ configurable: false,
380
+ enumerable: false,
381
+ writable: false
382
+ });
383
+ }
384
+ function isSigilCtor(value) {
385
+ return typeof value === "function" && value[__SIGIL__] === true;
386
+ }
387
+ function isSigilInstance(obj) {
388
+ if (!obj || typeof obj !== "object") return false;
389
+ const ctor = getConstructor(obj);
390
+ return isSigilCtor(ctor);
391
+ }
392
+ function isSigilBaseCtor(ctor) {
393
+ return Object.hasOwn(ctor, __SIGIL_BASE__);
394
+ }
395
+ function isSigilBaseInstance(obj) {
396
+ if (!obj || typeof obj !== "object") return false;
397
+ const ctor = getConstructor(obj);
398
+ return isSigilBaseCtor(ctor);
399
+ }
400
+ function isDecorated(ctor) {
401
+ return Object.hasOwn(ctor, __DECORATED__);
402
+ }
403
+ function isInheritanceChecked(ctor) {
404
+ return Object.hasOwn(ctor, __INHERITANCE_CHECKED__);
405
+ }
406
+ function getConstructor(obj) {
407
+ var _a, _b, _c;
408
+ if (!obj || typeof obj !== "object") return null;
409
+ return (_c = (_b = obj.constructor) != null ? _b : (_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.constructor) != null ? _c : null;
410
+ }
411
+ function generateRandomString(length = 16) {
412
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
413
+ let result = "";
414
+ for (let i = 0; i < length; i++) {
415
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
416
+ }
417
+ return result;
418
+ }
419
+
420
+ // src/core/mixin.ts
421
+ function Sigilify(Base, label, opts) {
422
+ if (isSigilCtor(Base))
423
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
424
+ let l;
425
+ if (label) {
426
+ verifyLabel(label, opts);
427
+ l = label;
428
+ } else l = generateRandomLabel();
429
+ class Sigilified extends Base {
430
+ /**
431
+ * Class-level human-readable label constant for this sigil constructor.
432
+ */
433
+ static get SigilLabel() {
434
+ return this[__LABEL__];
435
+ }
436
+ /**
437
+ * Class-level unique runtime symbol used as the type identifier.
438
+ *
439
+ * This symbol is created with `Symbol.for(label)` during decoration so it is
440
+ * stable across realms that share the same global symbol registry.
441
+ */
442
+ static get SigilType() {
443
+ return this[__TYPE__];
444
+ }
445
+ /**
446
+ * Copy of the linearized sigil type symbol chain for the current constructor.
447
+ *
448
+ * Useful for debugging and performing strict lineage comparisons.
449
+ *
450
+ * @returns An array of symbols representing parent → child type symbols.
451
+ */
452
+ static get SigilTypeLineage() {
453
+ var _a;
454
+ return [...(_a = this[__TYPE_LINEAGE__]) != null ? _a : []];
455
+ }
456
+ /**
457
+ * Copy of the sigil type symbol set for the current constructor.
458
+ *
459
+ * Useful for quick membership checks (O(1) lookups) and debugging.
460
+ *
461
+ * @returns A Readonly Set of symbols that represent the type lineage.
462
+ */
463
+ static get SigilTypeSet() {
464
+ const set = /* @__PURE__ */ new Set();
465
+ for (const s of this[__TYPE_SET__]) set.add(s);
466
+ return set;
467
+ }
468
+ constructor(...args) {
469
+ var _a;
470
+ super(...args);
471
+ if (Object.getPrototypeOf(this) !== new.target.prototype)
472
+ Object.setPrototypeOf(this, new.target.prototype);
473
+ const ctor = getConstructor(this);
474
+ if (!ctor) {
475
+ if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
476
+ throw new Error(
477
+ `[Sigil Error] 'Sigilify(${label})' instance without constructor`
478
+ );
479
+ return;
480
+ }
481
+ checkInheritance(ctor);
482
+ }
483
+ /**
484
+ * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
485
+ *
486
+ * @param obj - The value to test.
487
+ * @returns `true` if `obj` is a sigil instance.
488
+ */
489
+ static isSigilified(obj) {
490
+ return isSigilInstance(obj);
491
+ }
492
+ /**
493
+ * Check whether `other` is (or inherits from) the type represented by the calling constructor.
494
+ *
495
+ * Implementation detail:
496
+ * - Uses the other instance's `__TYPE_SET__` for O(1) membership test.
497
+ * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
498
+ *
499
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
500
+ * and when subclassing.
501
+ *
502
+ * @typeParam T - The calling constructor type (narrowing the returned instance type).
503
+ * @param this - The constructor performing the check.
504
+ * @param other - The object to test.
505
+ * @returns `true` if `other` is an instance of this type or a subtype.
506
+ */
507
+ static isOfType(other) {
508
+ if (!isSigilInstance(other)) return false;
509
+ const otherCtor = getConstructor(other);
510
+ if (!otherCtor) return false;
511
+ const otherSet = otherCtor[__TYPE_SET__];
512
+ return !!otherSet && otherSet.has(this.SigilType);
513
+ }
514
+ /**
515
+ * Strict lineage check: compares the type symbol lineage arrays element-by-element.
516
+ *
517
+ * Implementation detail:
518
+ * - Works in O(n) time where n is the depth of the lineage.
519
+ * - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
520
+ *
521
+ * @typeParam T - The calling constructor type.
522
+ * @param this - The constructor performing the check.
523
+ * @param other - The object to test.
524
+ * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
525
+ */
526
+ static isOfTypeStrict(other) {
527
+ if (!isSigilInstance(other)) return false;
528
+ const otherCtor = getConstructor(other);
529
+ if (!otherCtor) return false;
530
+ const otherLineage = otherCtor[__TYPE_LINEAGE__];
531
+ const thisLineage = this[__TYPE_LINEAGE__];
532
+ return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
533
+ }
534
+ /**
535
+ * Returns the human-readable sigil label of this instance's constructor.
536
+ *
537
+ * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
538
+ */
539
+ getSigilLabel() {
540
+ var _a;
541
+ const ctor = getConstructor(this);
542
+ if (!ctor) {
543
+ if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
544
+ throw new Error(
545
+ `[Sigil Error] 'Sigilify(${label})' instance without constructor`
546
+ );
547
+ return "@Sigil.unknown";
548
+ }
549
+ return ctor.SigilLabel;
550
+ }
551
+ /**
552
+ * Returns the runtime sigil type symbol of this instance's constructor.
553
+ *
554
+ * @returns The symbol that identifies this type at runtime.
555
+ */
556
+ getSigilType() {
557
+ var _a;
558
+ const ctor = getConstructor(this);
559
+ if (!ctor) {
560
+ if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
561
+ throw new Error(
562
+ `[Sigil Error] 'Sigilify(${label})' instance without constructor`
563
+ );
564
+ return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
565
+ }
566
+ return ctor.SigilType;
567
+ }
568
+ /**
569
+ * Returns a copy of the sigil type symbol lineage for this instance's constructor.
570
+ *
571
+ * @returns readonly array of symbols representing the type lineage.
572
+ */
573
+ getSigilTypeLineage() {
574
+ var _a;
575
+ const ctor = getConstructor(this);
576
+ if (!ctor) {
577
+ if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
578
+ throw new Error(
579
+ `[Sigil Error] 'Sigilify(${label})' instance without constructor`
580
+ );
581
+ return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
582
+ }
583
+ return ctor.SigilTypeLineage;
584
+ }
585
+ /**
586
+ * Returns a readonly copy of the sigil type symbol set for this instance's constructor.
587
+ *
588
+ * @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
589
+ */
590
+ getSigilTypeSet() {
591
+ var _a;
592
+ const ctor = getConstructor(this);
593
+ if (!ctor) {
594
+ if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
595
+ throw new Error(
596
+ `[Sigil Error] 'Sigilify(${label})' instance without constructor`
597
+ );
598
+ return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
599
+ }
600
+ return ctor.SigilTypeSet;
601
+ }
602
+ }
603
+ decorateCtor(Sigilified, l);
604
+ markSigil(Sigilified);
605
+ markSigilBase(Sigilified);
606
+ return Sigilified;
607
+ }
608
+
609
+ // src/core/classes.ts
610
+ var Sigil = Sigilify(class {
611
+ }, "Sigil");
612
+ var SigilError = Sigilify(Error, "SigilError");
613
+
614
+ // src/core/decorator.ts
615
+ function WithSigil(label, opts) {
616
+ let l;
617
+ if (label) {
618
+ verifyLabel(label, opts);
619
+ l = label;
620
+ } else l = generateRandomLabel();
621
+ return function(value, context) {
622
+ if (context.kind !== "class") return;
623
+ if (!isSigilCtor(value))
624
+ throw new Error(
625
+ `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
626
+ );
627
+ decorateCtor(value, l);
628
+ checkInheritance(value, opts);
629
+ };
630
+ }
631
+
632
+ // src/core/enhancers.ts
633
+ function withSigil(Class, label, opts) {
634
+ var _a;
635
+ if (!isSigilCtor(Class))
636
+ throw new Error(
637
+ `[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
638
+ );
639
+ let l;
640
+ if (label) {
641
+ verifyLabel(label, opts);
642
+ l = label;
643
+ } else l = generateRandomLabel();
644
+ const ctor = Class;
645
+ decorateCtor(ctor, l);
646
+ checkInheritance(ctor, opts);
647
+ return Class;
648
+ }
649
+ function typed(Class, label, opts) {
650
+ var _a, _b;
651
+ const devMarker = (_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker;
652
+ if (!isSigilCtor(Class))
653
+ throw new Error(
654
+ `[Sigil Error] 'typed' HOF accept only Sigil classes but used on class ${(_b = Class == null ? void 0 : Class.name) != null ? _b : "unknown"}`
655
+ );
656
+ if (devMarker && label) {
657
+ const runtimeLabel = Class.SigilLabel;
658
+ if (runtimeLabel && runtimeLabel !== label)
659
+ throw new Error(
660
+ `[Sigil Error][typed] runtime label "${runtimeLabel}" does not match asserted label "${label}".`
661
+ );
662
+ }
663
+ return Class;
664
+ }
665
+ function withSigilTyped(Class, label, opts) {
666
+ var _a;
667
+ if (!isSigilCtor(Class))
668
+ throw new Error(
669
+ `[Sigil Error] 'withSigilTyped' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
670
+ );
671
+ let l;
672
+ if (label) {
673
+ verifyLabel(label, opts);
674
+ l = label;
675
+ } else l = generateRandomLabel();
676
+ const ctor = Class;
677
+ decorateCtor(ctor, l);
678
+ checkInheritance(ctor, opts);
679
+ return Class;
680
+ }
681
+
682
+ export { DEFAULT_LABEL_REGEX, REGISTRY, Sigil, SigilError, SigilRegistry, Sigilify, WithSigil, getActiveRegistry, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, typed, updateOptions, withSigil, withSigilTyped };
683
+ //# sourceMappingURL=index.mjs.map
684
+ //# sourceMappingURL=index.mjs.map