@vicin/sigil 1.2.7 → 1.3.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
@@ -130,8 +130,7 @@ var SigilRegistry = class _SigilRegistry {
130
130
  * @param newRegistry - New Set<string> instance to use as the active registry, or `null` to disable checks.
131
131
  */
132
132
  replaceRegistry(newRegistry) {
133
- if (newRegistry)
134
- updateOptions({ registry: new _SigilRegistry(newRegistry) });
133
+ if (newRegistry) updateOptions({ registry: new _SigilRegistry(newRegistry) });
135
134
  else updateOptions({ registry: newRegistry });
136
135
  }
137
136
  /**
@@ -188,9 +187,7 @@ var SigilRegistry = class _SigilRegistry {
188
187
  * @param thisArg - Optional `this` context for the callback.
189
188
  */
190
189
  forEach(callback, thisArg) {
191
- this._registry.forEach(
192
- (ctor, label) => callback.call(thisArg, ctor, label)
193
- );
190
+ this._registry.forEach((ctor, label) => callback.call(thisArg, ctor, label));
194
191
  }
195
192
  /**
196
193
  * Get the size (number of entries) of the active registry.
@@ -251,9 +248,7 @@ updateOptions(DEFAULT_OPTIONS);
251
248
  var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
252
249
  var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
253
250
  var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
254
- var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for(
255
- "@Sigil.__INHERITANCE_CHECKED__"
256
- );
251
+ var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
257
252
  var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
258
253
  var __TYPE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE__");
259
254
  var __TYPE_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE_LINEAGE__");
@@ -419,8 +414,7 @@ function generateRandomString(length = 16) {
419
414
 
420
415
  // src/core/mixin.ts
421
416
  function Sigilify(Base, label, opts) {
422
- if (isSigilCtor(Base))
423
- throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
417
+ if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
424
418
  let l;
425
419
  if (label) {
426
420
  verifyLabel(label, opts);
@@ -473,9 +467,7 @@ function Sigilify(Base, label, opts) {
473
467
  const ctor = getConstructor(this);
474
468
  if (!ctor) {
475
469
  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
- );
470
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
479
471
  return;
480
472
  }
481
473
  checkInheritance(ctor);
@@ -492,10 +484,6 @@ function Sigilify(Base, label, opts) {
492
484
  /**
493
485
  * Check whether `other` is (or inherits from) the type represented by the calling constructor.
494
486
  *
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
487
  * This replaces `instanceof` so that checks remain valid across bundles/realms
500
488
  * and when subclassing.
501
489
  *
@@ -505,32 +493,61 @@ function Sigilify(Base, label, opts) {
505
493
  * @returns `true` if `other` is an instance of this type or a subtype.
506
494
  */
507
495
  static isOfType(other) {
496
+ var _a;
508
497
  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);
498
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
499
+ const thisType = this[__TYPE__];
500
+ return !!otherSet && otherSet.has(thisType);
513
501
  }
514
502
  /**
515
503
  * Strict lineage check: compares the type symbol lineage arrays element-by-element.
516
504
  *
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
505
  * @typeParam T - The calling constructor type.
522
506
  * @param this - The constructor performing the check.
523
507
  * @param other - The object to test.
524
508
  * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
525
509
  */
526
510
  static isOfTypeStrict(other) {
511
+ var _a;
527
512
  if (!isSigilInstance(other)) return false;
528
- const otherCtor = getConstructor(other);
529
- if (!otherCtor) return false;
530
- const otherLineage = otherCtor[__TYPE_LINEAGE__];
513
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
531
514
  const thisLineage = this[__TYPE_LINEAGE__];
532
515
  return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
533
516
  }
517
+ /**
518
+ * Check whether `other` is (or inherits from) the type instance.
519
+ *
520
+ * Allows 'instanceof' like checks but in instances.
521
+ *
522
+ * @typeParam T - The instance type.
523
+ * @param this - The instance performing the check.
524
+ * @param other - The object to test.
525
+ * @returns `true` if `other` is the same instance of this type or a subtype.
526
+ */
527
+ isOfType(other) {
528
+ var _a;
529
+ if (!isSigilInstance(other)) return false;
530
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
531
+ const thisType = getConstructor(this)[__TYPE__];
532
+ return !!otherSet && otherSet.has(thisType);
533
+ }
534
+ /**
535
+ * Strict lineage check: compares the type symbol lineage arrays element-by-element.
536
+ *
537
+ * Allows 'instanceof' like checks but in instances.
538
+ *
539
+ * @typeParam T - The instance type.
540
+ * @param this - The instance performing the check.
541
+ * @param other - The object to test.
542
+ * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
543
+ */
544
+ isOfTypeStrict(other) {
545
+ var _a, _b;
546
+ if (!isSigilInstance(other)) return false;
547
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
548
+ const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__TYPE_LINEAGE__];
549
+ return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
550
+ }
534
551
  /**
535
552
  * Returns the human-readable sigil label of this instance's constructor.
536
553
  *
@@ -541,9 +558,7 @@ function Sigilify(Base, label, opts) {
541
558
  const ctor = getConstructor(this);
542
559
  if (!ctor) {
543
560
  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
- );
561
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
547
562
  return "@Sigil.unknown";
548
563
  }
549
564
  return ctor.SigilLabel;
@@ -558,9 +573,7 @@ function Sigilify(Base, label, opts) {
558
573
  const ctor = getConstructor(this);
559
574
  if (!ctor) {
560
575
  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
- );
576
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
564
577
  return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
565
578
  }
566
579
  return ctor.SigilType;
@@ -575,9 +588,7 @@ function Sigilify(Base, label, opts) {
575
588
  const ctor = getConstructor(this);
576
589
  if (!ctor) {
577
590
  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
- );
591
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
581
592
  return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
582
593
  }
583
594
  return ctor.SigilTypeLineage;
@@ -592,9 +603,7 @@ function Sigilify(Base, label, opts) {
592
603
  const ctor = getConstructor(this);
593
604
  if (!ctor) {
594
605
  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
- );
606
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
598
607
  return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
599
608
  }
600
609
  return ctor.SigilTypeSet;
@@ -606,8 +615,7 @@ function Sigilify(Base, label, opts) {
606
615
  return Sigilified;
607
616
  }
608
617
  function SigilifyAbstract(Base, label, opts) {
609
- if (isSigilCtor(Base))
610
- throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
618
+ if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
611
619
  let l;
612
620
  if (label) {
613
621
  verifyLabel(label, opts);
@@ -660,9 +668,7 @@ function SigilifyAbstract(Base, label, opts) {
660
668
  const ctor = getConstructor(this);
661
669
  if (!ctor) {
662
670
  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
- );
671
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
666
672
  return;
667
673
  }
668
674
  checkInheritance(ctor);
@@ -692,11 +698,11 @@ function SigilifyAbstract(Base, label, opts) {
692
698
  * @returns `true` if `other` is an instance of this type or a subtype.
693
699
  */
694
700
  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);
701
+ var _a;
702
+ if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
703
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
704
+ const thisType = this[__TYPE__];
705
+ return !!otherSet && otherSet.has(thisType);
700
706
  }
701
707
  /**
702
708
  * Strict lineage check: compares the type symbol lineage arrays element-by-element.
@@ -711,13 +717,46 @@ function SigilifyAbstract(Base, label, opts) {
711
717
  * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
712
718
  */
713
719
  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__];
720
+ var _a;
721
+ if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
722
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
718
723
  const thisLineage = this[__TYPE_LINEAGE__];
719
724
  return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
720
725
  }
726
+ /**
727
+ * Check whether `other` is (or inherits from) the type instance.
728
+ *
729
+ * Allows 'instanceof' like checks but in instances.
730
+ *
731
+ * @typeParam T - The instance type.
732
+ * @param this - The instance performing the check.
733
+ * @param other - The object to test.
734
+ * @returns `true` if `other` is the same instance of this type or a subtype.
735
+ */
736
+ isOfType(other) {
737
+ var _a;
738
+ if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
739
+ const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
740
+ const thisType = getConstructor(this)[__TYPE__];
741
+ return !!otherSet && otherSet.has(thisType);
742
+ }
743
+ /**
744
+ * Strict lineage check: compares the type symbol lineage arrays element-by-element.
745
+ *
746
+ * Allows 'instanceof' like checks but in instances.
747
+ *
748
+ * @typeParam T - The instance type.
749
+ * @param this - The instance performing the check.
750
+ * @param other - The object to test.
751
+ * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
752
+ */
753
+ isOfTypeStrict(other) {
754
+ var _a, _b;
755
+ if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
756
+ const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
757
+ const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__TYPE_LINEAGE__];
758
+ return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
759
+ }
721
760
  /**
722
761
  * Returns the human-readable sigil label of this instance's constructor.
723
762
  *
@@ -728,9 +767,7 @@ function SigilifyAbstract(Base, label, opts) {
728
767
  const ctor = getConstructor(this);
729
768
  if (!ctor) {
730
769
  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
- );
770
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
734
771
  return "@Sigil.unknown";
735
772
  }
736
773
  return ctor.SigilLabel;
@@ -745,9 +782,7 @@ function SigilifyAbstract(Base, label, opts) {
745
782
  const ctor = getConstructor(this);
746
783
  if (!ctor) {
747
784
  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
- );
785
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
751
786
  return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
752
787
  }
753
788
  return ctor.SigilType;
@@ -762,9 +797,7 @@ function SigilifyAbstract(Base, label, opts) {
762
797
  const ctor = getConstructor(this);
763
798
  if (!ctor) {
764
799
  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
- );
800
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
768
801
  return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
769
802
  }
770
803
  return ctor.SigilTypeLineage;
@@ -779,9 +812,7 @@ function SigilifyAbstract(Base, label, opts) {
779
812
  const ctor = getConstructor(this);
780
813
  if (!ctor) {
781
814
  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
- );
815
+ throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
785
816
  return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
786
817
  }
787
818
  return ctor.SigilTypeSet;