@vicin/sigil 1.2.7 → 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/dist/index.mjs CHANGED
@@ -1,295 +1,53 @@
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);
1
+ import { createId } from '@paralleldrive/cuid2';
4
2
 
5
3
  // src/core/options.ts
6
4
  var OPTIONS = {
7
5
  labelValidation: null,
8
6
  skipLabelInheritanceCheck: false,
9
7
  autofillLabels: false,
10
- devMarker: false,
11
- registry: null,
12
- useGlobalRegistry: false,
13
- storeConstructor: false
8
+ devMarker: false
14
9
  };
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#deprecated-api 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);
10
+ var updateOptions = (opts) => {
226
11
  for (const [k, v] of Object.entries(opts)) OPTIONS[k] = v;
227
- applyAfterSideEffects(OPTIONS);
228
12
  };
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
13
  var DEFAULT_OPTIONS = {
240
14
  labelValidation: null,
241
15
  skipLabelInheritanceCheck: false,
242
16
  autofillLabels: false,
243
- devMarker: process.env.NODE_ENV !== "production",
244
- registry: new SigilRegistry(),
245
- useGlobalRegistry: true,
246
- storeConstructor: true
17
+ devMarker: process.env.NODE_ENV !== "production"
247
18
  };
248
19
  updateOptions(DEFAULT_OPTIONS);
20
+ var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
249
21
 
250
22
  // src/core/symbols.ts
251
23
  var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
252
24
  var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
253
25
  var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
254
- var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for(
255
- "@Sigil.__INHERITANCE_CHECKED__"
256
- );
26
+ var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
257
27
  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, isMixin = false) {
264
- var _a;
28
+ var __LABEL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_LINEAGE__");
29
+ var __LABEL_SET__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_SET__");
30
+ function decorateCtor(ctor, label, isMixin = false) {
265
31
  if (isDecorated(ctor))
266
32
  throw new Error(
267
33
  `Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`
268
34
  );
269
- const symbol = Symbol.for(label);
270
- (_a = getActiveRegistry()) == null ? void 0 : _a.register(label, ctor, opts);
271
35
  Object.defineProperty(ctor, __LABEL__, {
272
36
  value: label,
273
37
  configurable: false,
274
38
  enumerable: false,
275
39
  writable: false
276
40
  });
277
- Object.defineProperty(ctor, __TYPE__, {
278
- value: symbol,
279
- configurable: false,
280
- enumerable: false,
281
- writable: false
282
- });
283
41
  const parent = Object.getPrototypeOf(ctor);
284
- const parentChain = parent && parent[__TYPE_LINEAGE__] ? parent[__TYPE_LINEAGE__] : [];
285
- const ctorChain = isMixin && label !== "Sigil" ? [/* @__PURE__ */ Symbol.for("Sigil"), ...parentChain, symbol] : [...parentChain, symbol];
286
- Object.defineProperty(ctor, __TYPE_LINEAGE__, {
42
+ const parentChain = parent && parent[__LABEL_LINEAGE__] ? parent[__LABEL_LINEAGE__] : [];
43
+ const ctorChain = isMixin && label !== "Sigil" ? ["Sigil", ...parentChain, label] : [...parentChain, label];
44
+ Object.defineProperty(ctor, __LABEL_LINEAGE__, {
287
45
  value: ctorChain,
288
46
  configurable: false,
289
47
  enumerable: false,
290
48
  writable: false
291
49
  });
292
- Object.defineProperty(ctor, __TYPE_SET__, {
50
+ Object.defineProperty(ctor, __LABEL_SET__, {
293
51
  value: new Set(ctorChain),
294
52
  configurable: false,
295
53
  enumerable: false,
@@ -324,7 +82,7 @@ function checkInheritance(ctor, opts) {
324
82
  );
325
83
  }
326
84
  label = generateRandomLabel();
327
- decorateCtor(ctor2, label, opts);
85
+ decorateCtor(ctor2, label);
328
86
  }
329
87
  labelOwner.set(label, ctor2.name);
330
88
  }
@@ -343,10 +101,8 @@ function verifyLabel(label, opts) {
343
101
  );
344
102
  }
345
103
  }
346
- function generateRandomLabel(length = 16) {
347
- let label = generateRandomString(length);
348
- const registry = getActiveRegistry();
349
- if (registry) while (registry.has(label)) label = generateRandomLabel();
104
+ function generateRandomLabel() {
105
+ let label = createId();
350
106
  return `@Sigil.auto-${label}`;
351
107
  }
352
108
  function markSigil(ctor) {
@@ -408,19 +164,10 @@ function getConstructor(obj) {
408
164
  if (!obj || typeof obj !== "object") return null;
409
165
  return (_c = (_b = obj.constructor) != null ? _b : (_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.constructor) != null ? _c : null;
410
166
  }
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
167
 
420
168
  // src/core/mixin.ts
421
169
  function Sigilify(Base, label, opts) {
422
- if (isSigilCtor(Base))
423
- throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
170
+ if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
424
171
  let l;
425
172
  if (label) {
426
173
  verifyLabel(label, opts);
@@ -434,35 +181,26 @@ function Sigilify(Base, label, opts) {
434
181
  return this[__LABEL__];
435
182
  }
436
183
  /**
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.
184
+ * Copy of the linearized sigil type label chain for the current constructor.
447
185
  *
448
186
  * Useful for debugging and performing strict lineage comparisons.
449
187
  *
450
- * @returns An array of symbols representing parent → child type symbols.
188
+ * @returns An array of labels representing parent → child type labels.
451
189
  */
452
- static get SigilTypeLineage() {
190
+ static get SigilLabelLineage() {
453
191
  var _a;
454
- return [...(_a = this[__TYPE_LINEAGE__]) != null ? _a : []];
192
+ return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
455
193
  }
456
194
  /**
457
- * Copy of the sigil type symbol set for the current constructor.
195
+ * Copy of the sigil type label set for the current constructor.
458
196
  *
459
197
  * Useful for quick membership checks (O(1) lookups) and debugging.
460
198
  *
461
- * @returns A Readonly Set of symbols that represent the type lineage.
199
+ * @returns A Readonly Set of labels that represent the type lineage.
462
200
  */
463
- static get SigilTypeSet() {
201
+ static get SigilLabelSet() {
464
202
  const set = /* @__PURE__ */ new Set();
465
- for (const s of this[__TYPE_SET__]) set.add(s);
203
+ for (const s of this[__LABEL_SET__]) set.add(s);
466
204
  return set;
467
205
  }
468
206
  constructor(...args) {
@@ -473,9 +211,7 @@ function Sigilify(Base, label, opts) {
473
211
  const ctor = getConstructor(this);
474
212
  if (!ctor) {
475
213
  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
- );
214
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
479
215
  return;
480
216
  }
481
217
  checkInheritance(ctor);
@@ -492,10 +228,6 @@ function Sigilify(Base, label, opts) {
492
228
  /**
493
229
  * Check whether `other` is (or inherits from) the type represented by the calling constructor.
494
230
  *
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
231
  * This replaces `instanceof` so that checks remain valid across bundles/realms
500
232
  * and when subclassing.
501
233
  *
@@ -505,18 +237,14 @@ function Sigilify(Base, label, opts) {
505
237
  * @returns `true` if `other` is an instance of this type or a subtype.
506
238
  */
507
239
  static isOfType(other) {
240
+ var _a;
508
241
  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);
242
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
243
+ const thisType = this[__LABEL__];
244
+ return !!otherSet && otherSet.has(thisType);
513
245
  }
514
246
  /**
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`.
247
+ * Strict lineage check: compares the type label lineage arrays element-by-element.
520
248
  *
521
249
  * @typeParam T - The calling constructor type.
522
250
  * @param this - The constructor performing the check.
@@ -524,90 +252,99 @@ function Sigilify(Base, label, opts) {
524
252
  * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
525
253
  */
526
254
  static isOfTypeStrict(other) {
255
+ var _a;
527
256
  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__];
257
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
258
+ const thisLineage = this[__LABEL_LINEAGE__];
532
259
  return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
533
260
  }
534
261
  /**
535
- * Returns the human-readable sigil label of this instance's constructor.
262
+ * Check whether `other` is (or inherits from) the type instance.
536
263
  *
537
- * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
264
+ * Allows 'instanceof' like checks but in instances.
265
+ *
266
+ * @typeParam T - The instance type.
267
+ * @param this - The instance performing the check.
268
+ * @param other - The object to test.
269
+ * @returns `true` if `other` is the same instance of this type or a subtype.
538
270
  */
539
- getSigilLabel() {
271
+ isOfType(other) {
540
272
  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;
273
+ if (!isSigilInstance(other)) return false;
274
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
275
+ const thisType = getConstructor(this)[__LABEL__];
276
+ return !!otherSet && otherSet.has(thisType);
550
277
  }
551
278
  /**
552
- * Returns the runtime sigil type symbol of this instance's constructor.
279
+ * Strict lineage check: compares the type label lineage arrays element-by-element.
280
+ *
281
+ * Allows 'instanceof' like checks but in instances.
553
282
  *
554
- * @returns The symbol that identifies this type at runtime.
283
+ * @typeParam T - The instance type.
284
+ * @param this - The instance performing the check.
285
+ * @param other - The object to test.
286
+ * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
287
+ */
288
+ isOfTypeStrict(other) {
289
+ var _a, _b;
290
+ if (!isSigilInstance(other)) return false;
291
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
292
+ const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
293
+ return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
294
+ }
295
+ /**
296
+ * Returns the human-readable sigil label of this instance's constructor.
297
+ *
298
+ * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
555
299
  */
556
- getSigilType() {
300
+ getSigilLabel() {
557
301
  var _a;
558
302
  const ctor = getConstructor(this);
559
303
  if (!ctor) {
560
304
  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");
305
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
306
+ return "@Sigil.unknown";
565
307
  }
566
- return ctor.SigilType;
308
+ return ctor.SigilLabel;
567
309
  }
568
310
  /**
569
- * Returns a copy of the sigil type symbol lineage for this instance's constructor.
311
+ * Returns a copy of the sigil type label lineage for this instance's constructor.
570
312
  *
571
- * @returns readonly array of symbols representing the type lineage.
313
+ * @returns readonly array of labels representing the type lineage.
572
314
  */
573
- getSigilTypeLineage() {
315
+ getSigilLabelLineage() {
574
316
  var _a;
575
317
  const ctor = getConstructor(this);
576
318
  if (!ctor) {
577
319
  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")];
320
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
321
+ return ["@Sigil.unknown"];
582
322
  }
583
- return ctor.SigilTypeLineage;
323
+ return ctor.SigilLabelLineage;
584
324
  }
585
325
  /**
586
- * Returns a readonly copy of the sigil type symbol set for this instance's constructor.
326
+ * Returns a readonly copy of the sigil type label set for this instance's constructor.
587
327
  *
588
- * @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
328
+ * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
589
329
  */
590
- getSigilTypeSet() {
330
+ getSigilLabelSet() {
591
331
  var _a;
592
332
  const ctor = getConstructor(this);
593
333
  if (!ctor) {
594
334
  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")]);
335
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
336
+ return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
599
337
  }
600
- return ctor.SigilTypeSet;
338
+ return ctor.SigilLabelSet;
601
339
  }
602
340
  }
603
- decorateCtor(Sigilified, l, opts, true);
341
+ decorateCtor(Sigilified, l, true);
604
342
  markSigil(Sigilified);
605
343
  markSigilBase(Sigilified);
606
344
  return Sigilified;
607
345
  }
608
346
  function SigilifyAbstract(Base, label, opts) {
609
- if (isSigilCtor(Base))
610
- throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
347
+ if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
611
348
  let l;
612
349
  if (label) {
613
350
  verifyLabel(label, opts);
@@ -621,35 +358,26 @@ function SigilifyAbstract(Base, label, opts) {
621
358
  return this[__LABEL__];
622
359
  }
623
360
  /**
624
- * Class-level unique runtime symbol used as the type identifier.
625
- *
626
- * This symbol is created with `Symbol.for(label)` during decoration so it is
627
- * stable across realms that share the same global symbol registry.
628
- */
629
- static get SigilType() {
630
- return this[__TYPE__];
631
- }
632
- /**
633
- * Copy of the linearized sigil type symbol chain for the current constructor.
361
+ * Copy of the linearized sigil type label chain for the current constructor.
634
362
  *
635
363
  * Useful for debugging and performing strict lineage comparisons.
636
364
  *
637
- * @returns An array of symbols representing parent → child type symbols.
365
+ * @returns An array of labels representing parent → child type labels.
638
366
  */
639
- static get SigilTypeLineage() {
367
+ static get SigilLabelLineage() {
640
368
  var _a;
641
- return [...(_a = this[__TYPE_LINEAGE__]) != null ? _a : []];
369
+ return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
642
370
  }
643
371
  /**
644
- * Copy of the sigil type symbol set for the current constructor.
372
+ * Copy of the sigil type label set for the current constructor.
645
373
  *
646
374
  * Useful for quick membership checks (O(1) lookups) and debugging.
647
375
  *
648
- * @returns A Readonly Set of symbols that represent the type lineage.
376
+ * @returns A Readonly Set of labels that represent the type lineage.
649
377
  */
650
- static get SigilTypeSet() {
378
+ static get SigilLabelSet() {
651
379
  const set = /* @__PURE__ */ new Set();
652
- for (const s of this[__TYPE_SET__]) set.add(s);
380
+ for (const s of this[__LABEL_SET__]) set.add(s);
653
381
  return set;
654
382
  }
655
383
  constructor(...args) {
@@ -660,9 +388,7 @@ function SigilifyAbstract(Base, label, opts) {
660
388
  const ctor = getConstructor(this);
661
389
  if (!ctor) {
662
390
  if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
663
- throw new Error(
664
- `[Sigil Error] 'Sigilify(${label})' instance without constructor`
665
- );
391
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
666
392
  return;
667
393
  }
668
394
  checkInheritance(ctor);
@@ -680,7 +406,7 @@ function SigilifyAbstract(Base, label, opts) {
680
406
  * Check whether `other` is (or inherits from) the type represented by the calling constructor.
681
407
  *
682
408
  * Implementation detail:
683
- * - Uses the other instance's `__TYPE_SET__` for O(1) membership test.
409
+ * - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
684
410
  * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
685
411
  *
686
412
  * This replaces `instanceof` so that checks remain valid across bundles/realms
@@ -692,14 +418,14 @@ function SigilifyAbstract(Base, label, opts) {
692
418
  * @returns `true` if `other` is an instance of this type or a subtype.
693
419
  */
694
420
  static isOfType(other) {
695
- if (!isSigilInstance(other)) return false;
696
- const otherCtor = getConstructor(other);
697
- if (!otherCtor) return false;
698
- const otherSet = otherCtor[__TYPE_SET__];
699
- return !!otherSet && otherSet.has(this.SigilType);
421
+ var _a;
422
+ if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
423
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
424
+ const thisType = this[__LABEL__];
425
+ return !!otherSet && otherSet.has(thisType);
700
426
  }
701
427
  /**
702
- * Strict lineage check: compares the type symbol lineage arrays element-by-element.
428
+ * Strict lineage check: compares the type label lineage arrays element-by-element.
703
429
  *
704
430
  * Implementation detail:
705
431
  * - Works in O(n) time where n is the depth of the lineage.
@@ -711,83 +437,93 @@ function SigilifyAbstract(Base, label, opts) {
711
437
  * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
712
438
  */
713
439
  static isOfTypeStrict(other) {
714
- if (!isSigilInstance(other)) return false;
715
- const otherCtor = getConstructor(other);
716
- if (!otherCtor) return false;
717
- const otherLineage = otherCtor[__TYPE_LINEAGE__];
718
- const thisLineage = this[__TYPE_LINEAGE__];
440
+ var _a;
441
+ if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
442
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
443
+ const thisLineage = this[__LABEL_LINEAGE__];
719
444
  return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
720
445
  }
721
446
  /**
722
- * Returns the human-readable sigil label of this instance's constructor.
447
+ * Check whether `other` is (or inherits from) the type instance.
723
448
  *
724
- * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
449
+ * Allows 'instanceof' like checks but in instances.
450
+ *
451
+ * @typeParam T - The instance type.
452
+ * @param this - The instance performing the check.
453
+ * @param other - The object to test.
454
+ * @returns `true` if `other` is the same instance of this type or a subtype.
725
455
  */
726
- getSigilLabel() {
456
+ isOfType(other) {
727
457
  var _a;
728
- const ctor = getConstructor(this);
729
- if (!ctor) {
730
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
731
- throw new Error(
732
- `[Sigil Error] 'Sigilify(${label})' instance without constructor`
733
- );
734
- return "@Sigil.unknown";
735
- }
736
- return ctor.SigilLabel;
458
+ if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
459
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
460
+ const thisType = getConstructor(this)[__LABEL__];
461
+ return !!otherSet && otherSet.has(thisType);
737
462
  }
738
463
  /**
739
- * Returns the runtime sigil type symbol of this instance's constructor.
464
+ * Strict lineage check: compares the type label lineage arrays element-by-element.
740
465
  *
741
- * @returns The symbol that identifies this type at runtime.
466
+ * Allows 'instanceof' like checks but in instances.
467
+ *
468
+ * @typeParam T - The instance type.
469
+ * @param this - The instance performing the check.
470
+ * @param other - The object to test.
471
+ * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
742
472
  */
743
- getSigilType() {
473
+ isOfTypeStrict(other) {
474
+ var _a, _b;
475
+ if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
476
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
477
+ const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
478
+ return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
479
+ }
480
+ /**
481
+ * Returns the human-readable sigil label of this instance's constructor.
482
+ *
483
+ * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
484
+ */
485
+ getSigilLabel() {
744
486
  var _a;
745
487
  const ctor = getConstructor(this);
746
488
  if (!ctor) {
747
489
  if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
748
- throw new Error(
749
- `[Sigil Error] 'Sigilify(${label})' instance without constructor`
750
- );
751
- return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
490
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
491
+ return "@Sigil.unknown";
752
492
  }
753
- return ctor.SigilType;
493
+ return ctor.SigilLabel;
754
494
  }
755
495
  /**
756
- * Returns a copy of the sigil type symbol lineage for this instance's constructor.
496
+ * Returns a copy of the sigil type label lineage for this instance's constructor.
757
497
  *
758
- * @returns readonly array of symbols representing the type lineage.
498
+ * @returns readonly array of labels representing the type lineage.
759
499
  */
760
- getSigilTypeLineage() {
500
+ getSigilLabelLineage() {
761
501
  var _a;
762
502
  const ctor = getConstructor(this);
763
503
  if (!ctor) {
764
504
  if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
765
- throw new Error(
766
- `[Sigil Error] 'Sigilify(${label})' instance without constructor`
767
- );
768
- return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
505
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
506
+ return ["@Sigil.unknown"];
769
507
  }
770
- return ctor.SigilTypeLineage;
508
+ return ctor.SigilLabelLineage;
771
509
  }
772
510
  /**
773
- * Returns a readonly copy of the sigil type symbol set for this instance's constructor.
511
+ * Returns a readonly copy of the sigil type label set for this instance's constructor.
774
512
  *
775
- * @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
513
+ * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
776
514
  */
777
- getSigilTypeSet() {
515
+ getSigilLabelSet() {
778
516
  var _a;
779
517
  const ctor = getConstructor(this);
780
518
  if (!ctor) {
781
519
  if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
782
- throw new Error(
783
- `[Sigil Error] 'Sigilify(${label})' instance without constructor`
784
- );
785
- return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
520
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
521
+ return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
786
522
  }
787
- return ctor.SigilTypeSet;
523
+ return ctor.SigilLabelSet;
788
524
  }
789
525
  }
790
- decorateCtor(Sigilified, l, opts, true);
526
+ decorateCtor(Sigilified, l, true);
791
527
  markSigil(Sigilified);
792
528
  markSigilBase(Sigilified);
793
529
  return Sigilified;
@@ -811,7 +547,7 @@ function WithSigil(label, opts) {
811
547
  throw new Error(
812
548
  `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
813
549
  );
814
- decorateCtor(value, l, opts);
550
+ decorateCtor(value, l);
815
551
  checkInheritance(value, opts);
816
552
  };
817
553
  }
@@ -829,26 +565,10 @@ function withSigil(Class, label, opts) {
829
565
  l = label;
830
566
  } else l = generateRandomLabel();
831
567
  const ctor = Class;
832
- decorateCtor(ctor, l, opts);
568
+ decorateCtor(ctor, l);
833
569
  checkInheritance(ctor, opts);
834
570
  return Class;
835
571
  }
836
- function typed(Class, label, opts) {
837
- var _a, _b;
838
- const devMarker = (_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker;
839
- if (!isSigilCtor(Class))
840
- throw new Error(
841
- `[Sigil Error] 'typed' HOF accept only Sigil classes but used on class ${(_b = Class == null ? void 0 : Class.name) != null ? _b : "unknown"}`
842
- );
843
- if (devMarker && label) {
844
- const runtimeLabel = Class.SigilLabel;
845
- if (runtimeLabel && runtimeLabel !== label)
846
- throw new Error(
847
- `[Sigil Error][typed] runtime label "${runtimeLabel}" does not match asserted label "${label}".`
848
- );
849
- }
850
- return Class;
851
- }
852
572
  function withSigilTyped(Class, label, opts) {
853
573
  var _a;
854
574
  if (!isSigilCtor(Class))
@@ -861,11 +581,11 @@ function withSigilTyped(Class, label, opts) {
861
581
  l = label;
862
582
  } else l = generateRandomLabel();
863
583
  const ctor = Class;
864
- decorateCtor(ctor, l, opts);
584
+ decorateCtor(ctor, l);
865
585
  checkInheritance(ctor, opts);
866
586
  return Class;
867
587
  }
868
588
 
869
- export { DEFAULT_LABEL_REGEX, REGISTRY, Sigil, SigilError, SigilRegistry, Sigilify, SigilifyAbstract, WithSigil, getActiveRegistry, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, typed, updateOptions, withSigil, withSigilTyped };
589
+ export { DEFAULT_LABEL_REGEX, Sigil, SigilError, Sigilify, SigilifyAbstract, WithSigil, isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, updateOptions, withSigil, withSigilTyped };
870
590
  //# sourceMappingURL=index.mjs.map
871
591
  //# sourceMappingURL=index.mjs.map