@vicin/sigil 1.2.6 → 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/CHANGELOG.md +12 -0
- package/README.md +16 -1
- package/dist/index.d.mts +185 -15
- package/dist/index.d.ts +185 -15
- package/dist/index.global.js +253 -34
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +253 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +253 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -132,8 +132,7 @@ var SigilRegistry = class _SigilRegistry {
|
|
|
132
132
|
* @param newRegistry - New Set<string> instance to use as the active registry, or `null` to disable checks.
|
|
133
133
|
*/
|
|
134
134
|
replaceRegistry(newRegistry) {
|
|
135
|
-
if (newRegistry)
|
|
136
|
-
updateOptions({ registry: new _SigilRegistry(newRegistry) });
|
|
135
|
+
if (newRegistry) updateOptions({ registry: new _SigilRegistry(newRegistry) });
|
|
137
136
|
else updateOptions({ registry: newRegistry });
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
@@ -190,9 +189,7 @@ var SigilRegistry = class _SigilRegistry {
|
|
|
190
189
|
* @param thisArg - Optional `this` context for the callback.
|
|
191
190
|
*/
|
|
192
191
|
forEach(callback, thisArg) {
|
|
193
|
-
this._registry.forEach(
|
|
194
|
-
(ctor, label) => callback.call(thisArg, ctor, label)
|
|
195
|
-
);
|
|
192
|
+
this._registry.forEach((ctor, label) => callback.call(thisArg, ctor, label));
|
|
196
193
|
}
|
|
197
194
|
/**
|
|
198
195
|
* Get the size (number of entries) of the active registry.
|
|
@@ -253,9 +250,7 @@ updateOptions(DEFAULT_OPTIONS);
|
|
|
253
250
|
var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
|
|
254
251
|
var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
|
|
255
252
|
var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
|
|
256
|
-
var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for(
|
|
257
|
-
"@Sigil.__INHERITANCE_CHECKED__"
|
|
258
|
-
);
|
|
253
|
+
var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
|
|
259
254
|
var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
|
|
260
255
|
var __TYPE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE__");
|
|
261
256
|
var __TYPE_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__TYPE_LINEAGE__");
|
|
@@ -421,8 +416,7 @@ function generateRandomString(length = 16) {
|
|
|
421
416
|
|
|
422
417
|
// src/core/mixin.ts
|
|
423
418
|
function Sigilify(Base, label, opts) {
|
|
424
|
-
if (isSigilCtor(Base))
|
|
425
|
-
throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
|
|
419
|
+
if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
|
|
426
420
|
let l;
|
|
427
421
|
if (label) {
|
|
428
422
|
verifyLabel(label, opts);
|
|
@@ -475,9 +469,208 @@ function Sigilify(Base, label, opts) {
|
|
|
475
469
|
const ctor = getConstructor(this);
|
|
476
470
|
if (!ctor) {
|
|
477
471
|
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
478
|
-
throw new Error(
|
|
479
|
-
|
|
480
|
-
|
|
472
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
checkInheritance(ctor);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
479
|
+
*
|
|
480
|
+
* @param obj - The value to test.
|
|
481
|
+
* @returns `true` if `obj` is a sigil instance.
|
|
482
|
+
*/
|
|
483
|
+
static isSigilified(obj) {
|
|
484
|
+
return isSigilInstance(obj);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Check whether `other` is (or inherits from) the type represented by the calling constructor.
|
|
488
|
+
*
|
|
489
|
+
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
490
|
+
* and when subclassing.
|
|
491
|
+
*
|
|
492
|
+
* @typeParam T - The calling constructor type (narrowing the returned instance type).
|
|
493
|
+
* @param this - The constructor performing the check.
|
|
494
|
+
* @param other - The object to test.
|
|
495
|
+
* @returns `true` if `other` is an instance of this type or a subtype.
|
|
496
|
+
*/
|
|
497
|
+
static isOfType(other) {
|
|
498
|
+
var _a;
|
|
499
|
+
if (!isSigilInstance(other)) return false;
|
|
500
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
|
|
501
|
+
const thisType = this[__TYPE__];
|
|
502
|
+
return !!otherSet && otherSet.has(thisType);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Strict lineage check: compares the type symbol lineage arrays element-by-element.
|
|
506
|
+
*
|
|
507
|
+
* @typeParam T - The calling constructor type.
|
|
508
|
+
* @param this - The constructor performing the check.
|
|
509
|
+
* @param other - The object to test.
|
|
510
|
+
* @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
|
|
511
|
+
*/
|
|
512
|
+
static isOfTypeStrict(other) {
|
|
513
|
+
var _a;
|
|
514
|
+
if (!isSigilInstance(other)) return false;
|
|
515
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
|
|
516
|
+
const thisLineage = this[__TYPE_LINEAGE__];
|
|
517
|
+
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Check whether `other` is (or inherits from) the type instance.
|
|
521
|
+
*
|
|
522
|
+
* Allows 'instanceof' like checks but in instances.
|
|
523
|
+
*
|
|
524
|
+
* @typeParam T - The instance type.
|
|
525
|
+
* @param this - The instance performing the check.
|
|
526
|
+
* @param other - The object to test.
|
|
527
|
+
* @returns `true` if `other` is the same instance of this type or a subtype.
|
|
528
|
+
*/
|
|
529
|
+
isOfType(other) {
|
|
530
|
+
var _a;
|
|
531
|
+
if (!isSigilInstance(other)) return false;
|
|
532
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
|
|
533
|
+
const thisType = getConstructor(this)[__TYPE__];
|
|
534
|
+
return !!otherSet && otherSet.has(thisType);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Strict lineage check: compares the type symbol lineage arrays element-by-element.
|
|
538
|
+
*
|
|
539
|
+
* Allows 'instanceof' like checks but in instances.
|
|
540
|
+
*
|
|
541
|
+
* @typeParam T - The instance type.
|
|
542
|
+
* @param this - The instance performing the check.
|
|
543
|
+
* @param other - The object to test.
|
|
544
|
+
* @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
|
|
545
|
+
*/
|
|
546
|
+
isOfTypeStrict(other) {
|
|
547
|
+
var _a, _b;
|
|
548
|
+
if (!isSigilInstance(other)) return false;
|
|
549
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
|
|
550
|
+
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__TYPE_LINEAGE__];
|
|
551
|
+
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Returns the human-readable sigil label of this instance's constructor.
|
|
555
|
+
*
|
|
556
|
+
* @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
|
|
557
|
+
*/
|
|
558
|
+
getSigilLabel() {
|
|
559
|
+
var _a;
|
|
560
|
+
const ctor = getConstructor(this);
|
|
561
|
+
if (!ctor) {
|
|
562
|
+
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
563
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
564
|
+
return "@Sigil.unknown";
|
|
565
|
+
}
|
|
566
|
+
return ctor.SigilLabel;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Returns the runtime sigil type symbol of this instance's constructor.
|
|
570
|
+
*
|
|
571
|
+
* @returns The symbol that identifies this type at runtime.
|
|
572
|
+
*/
|
|
573
|
+
getSigilType() {
|
|
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(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
579
|
+
return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
|
|
580
|
+
}
|
|
581
|
+
return ctor.SigilType;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Returns a copy of the sigil type symbol lineage for this instance's constructor.
|
|
585
|
+
*
|
|
586
|
+
* @returns readonly array of symbols representing the type lineage.
|
|
587
|
+
*/
|
|
588
|
+
getSigilTypeLineage() {
|
|
589
|
+
var _a;
|
|
590
|
+
const ctor = getConstructor(this);
|
|
591
|
+
if (!ctor) {
|
|
592
|
+
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
593
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
594
|
+
return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
|
|
595
|
+
}
|
|
596
|
+
return ctor.SigilTypeLineage;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Returns a readonly copy of the sigil type symbol set for this instance's constructor.
|
|
600
|
+
*
|
|
601
|
+
* @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
|
|
602
|
+
*/
|
|
603
|
+
getSigilTypeSet() {
|
|
604
|
+
var _a;
|
|
605
|
+
const ctor = getConstructor(this);
|
|
606
|
+
if (!ctor) {
|
|
607
|
+
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
608
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
609
|
+
return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
|
|
610
|
+
}
|
|
611
|
+
return ctor.SigilTypeSet;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
decorateCtor(Sigilified, l, opts, true);
|
|
615
|
+
markSigil(Sigilified);
|
|
616
|
+
markSigilBase(Sigilified);
|
|
617
|
+
return Sigilified;
|
|
618
|
+
}
|
|
619
|
+
function SigilifyAbstract(Base, label, opts) {
|
|
620
|
+
if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already siglified.`);
|
|
621
|
+
let l;
|
|
622
|
+
if (label) {
|
|
623
|
+
verifyLabel(label, opts);
|
|
624
|
+
l = label;
|
|
625
|
+
} else l = generateRandomLabel();
|
|
626
|
+
class Sigilified extends Base {
|
|
627
|
+
/**
|
|
628
|
+
* Class-level human-readable label constant for this sigil constructor.
|
|
629
|
+
*/
|
|
630
|
+
static get SigilLabel() {
|
|
631
|
+
return this[__LABEL__];
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Class-level unique runtime symbol used as the type identifier.
|
|
635
|
+
*
|
|
636
|
+
* This symbol is created with `Symbol.for(label)` during decoration so it is
|
|
637
|
+
* stable across realms that share the same global symbol registry.
|
|
638
|
+
*/
|
|
639
|
+
static get SigilType() {
|
|
640
|
+
return this[__TYPE__];
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
644
|
+
*
|
|
645
|
+
* Useful for debugging and performing strict lineage comparisons.
|
|
646
|
+
*
|
|
647
|
+
* @returns An array of symbols representing parent → child type symbols.
|
|
648
|
+
*/
|
|
649
|
+
static get SigilTypeLineage() {
|
|
650
|
+
var _a;
|
|
651
|
+
return [...(_a = this[__TYPE_LINEAGE__]) != null ? _a : []];
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Copy of the sigil type symbol set for the current constructor.
|
|
655
|
+
*
|
|
656
|
+
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
657
|
+
*
|
|
658
|
+
* @returns A Readonly Set of symbols that represent the type lineage.
|
|
659
|
+
*/
|
|
660
|
+
static get SigilTypeSet() {
|
|
661
|
+
const set = /* @__PURE__ */ new Set();
|
|
662
|
+
for (const s of this[__TYPE_SET__]) set.add(s);
|
|
663
|
+
return set;
|
|
664
|
+
}
|
|
665
|
+
constructor(...args) {
|
|
666
|
+
var _a;
|
|
667
|
+
super(...args);
|
|
668
|
+
if (Object.getPrototypeOf(this) !== new.target.prototype)
|
|
669
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
670
|
+
const ctor = getConstructor(this);
|
|
671
|
+
if (!ctor) {
|
|
672
|
+
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
673
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
481
674
|
return;
|
|
482
675
|
}
|
|
483
676
|
checkInheritance(ctor);
|
|
@@ -507,11 +700,11 @@ function Sigilify(Base, label, opts) {
|
|
|
507
700
|
* @returns `true` if `other` is an instance of this type or a subtype.
|
|
508
701
|
*/
|
|
509
702
|
static isOfType(other) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
return !!otherSet && otherSet.has(
|
|
703
|
+
var _a;
|
|
704
|
+
if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
|
|
705
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
|
|
706
|
+
const thisType = this[__TYPE__];
|
|
707
|
+
return !!otherSet && otherSet.has(thisType);
|
|
515
708
|
}
|
|
516
709
|
/**
|
|
517
710
|
* Strict lineage check: compares the type symbol lineage arrays element-by-element.
|
|
@@ -526,13 +719,46 @@ function Sigilify(Base, label, opts) {
|
|
|
526
719
|
* @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
|
|
527
720
|
*/
|
|
528
721
|
static isOfTypeStrict(other) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const otherLineage = otherCtor[__TYPE_LINEAGE__];
|
|
722
|
+
var _a;
|
|
723
|
+
if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
|
|
724
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
|
|
533
725
|
const thisLineage = this[__TYPE_LINEAGE__];
|
|
534
726
|
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
535
727
|
}
|
|
728
|
+
/**
|
|
729
|
+
* Check whether `other` is (or inherits from) the type instance.
|
|
730
|
+
*
|
|
731
|
+
* Allows 'instanceof' like checks but in instances.
|
|
732
|
+
*
|
|
733
|
+
* @typeParam T - The instance type.
|
|
734
|
+
* @param this - The instance performing the check.
|
|
735
|
+
* @param other - The object to test.
|
|
736
|
+
* @returns `true` if `other` is the same instance of this type or a subtype.
|
|
737
|
+
*/
|
|
738
|
+
isOfType(other) {
|
|
739
|
+
var _a;
|
|
740
|
+
if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
|
|
741
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_SET__];
|
|
742
|
+
const thisType = getConstructor(this)[__TYPE__];
|
|
743
|
+
return !!otherSet && otherSet.has(thisType);
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Strict lineage check: compares the type symbol lineage arrays element-by-element.
|
|
747
|
+
*
|
|
748
|
+
* Allows 'instanceof' like checks but in instances.
|
|
749
|
+
*
|
|
750
|
+
* @typeParam T - The instance type.
|
|
751
|
+
* @param this - The instance performing the check.
|
|
752
|
+
* @param other - The object to test.
|
|
753
|
+
* @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
|
|
754
|
+
*/
|
|
755
|
+
isOfTypeStrict(other) {
|
|
756
|
+
var _a, _b;
|
|
757
|
+
if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
|
|
758
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__TYPE_LINEAGE__];
|
|
759
|
+
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__TYPE_LINEAGE__];
|
|
760
|
+
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
761
|
+
}
|
|
536
762
|
/**
|
|
537
763
|
* Returns the human-readable sigil label of this instance's constructor.
|
|
538
764
|
*
|
|
@@ -543,9 +769,7 @@ function Sigilify(Base, label, opts) {
|
|
|
543
769
|
const ctor = getConstructor(this);
|
|
544
770
|
if (!ctor) {
|
|
545
771
|
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
546
|
-
throw new Error(
|
|
547
|
-
`[Sigil Error] 'Sigilify(${label})' instance without constructor`
|
|
548
|
-
);
|
|
772
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
549
773
|
return "@Sigil.unknown";
|
|
550
774
|
}
|
|
551
775
|
return ctor.SigilLabel;
|
|
@@ -560,9 +784,7 @@ function Sigilify(Base, label, opts) {
|
|
|
560
784
|
const ctor = getConstructor(this);
|
|
561
785
|
if (!ctor) {
|
|
562
786
|
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
563
|
-
throw new Error(
|
|
564
|
-
`[Sigil Error] 'Sigilify(${label})' instance without constructor`
|
|
565
|
-
);
|
|
787
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
566
788
|
return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
|
|
567
789
|
}
|
|
568
790
|
return ctor.SigilType;
|
|
@@ -577,9 +799,7 @@ function Sigilify(Base, label, opts) {
|
|
|
577
799
|
const ctor = getConstructor(this);
|
|
578
800
|
if (!ctor) {
|
|
579
801
|
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
580
|
-
throw new Error(
|
|
581
|
-
`[Sigil Error] 'Sigilify(${label})' instance without constructor`
|
|
582
|
-
);
|
|
802
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
583
803
|
return [/* @__PURE__ */ Symbol.for("@Sigil.unknown")];
|
|
584
804
|
}
|
|
585
805
|
return ctor.SigilTypeLineage;
|
|
@@ -594,9 +814,7 @@ function Sigilify(Base, label, opts) {
|
|
|
594
814
|
const ctor = getConstructor(this);
|
|
595
815
|
if (!ctor) {
|
|
596
816
|
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
597
|
-
throw new Error(
|
|
598
|
-
`[Sigil Error] 'Sigilify(${label})' instance without constructor`
|
|
599
|
-
);
|
|
817
|
+
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
600
818
|
return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
|
|
601
819
|
}
|
|
602
820
|
return ctor.SigilTypeSet;
|
|
@@ -686,6 +904,7 @@ exports.Sigil = Sigil;
|
|
|
686
904
|
exports.SigilError = SigilError;
|
|
687
905
|
exports.SigilRegistry = SigilRegistry;
|
|
688
906
|
exports.Sigilify = Sigilify;
|
|
907
|
+
exports.SigilifyAbstract = SigilifyAbstract;
|
|
689
908
|
exports.WithSigil = WithSigil;
|
|
690
909
|
exports.getActiveRegistry = getActiveRegistry;
|
|
691
910
|
exports.isDecorated = isDecorated;
|