@vicin/sigil 3.3.0 → 4.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.cjs ADDED
@@ -0,0 +1,269 @@
1
+ 'use strict';
2
+
3
+ // src/symbols.ts
4
+ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL__");
5
+ var __SIGIL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_LINEAGE__");
6
+ var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
7
+ var __DEPTH__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__DEPTH__");
8
+
9
+ // src/is.ts
10
+ function isSigilCtor(ctor) {
11
+ return typeof ctor === "function" && ctor.prototype && __SIGIL__ in ctor.prototype;
12
+ }
13
+ function isSigilInstance(inst) {
14
+ return !!inst && typeof inst === "object" && __SIGIL__ in inst;
15
+ }
16
+
17
+ // src/options.ts
18
+ var OPTIONS = {
19
+ labelValidation: null
20
+ };
21
+ var updateSigilOptions = ({ labelValidation = null } = {}) => {
22
+ OPTIONS.labelValidation = labelValidation;
23
+ };
24
+ var RECOMMENDED_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
25
+
26
+ // src/sigilify.ts
27
+ var resolved = /* @__PURE__ */ new WeakSet();
28
+ var hasOwnSigilRegistry = /* @__PURE__ */ new WeakSet();
29
+ function sigilify(ctor, label, opts) {
30
+ if (resolved.has(ctor))
31
+ throw new Error(
32
+ `[Sigil Error] Class '${ctor.name}' with label '${ctor.SigilLabel}' is already sigilified`
33
+ );
34
+ verifyLabel(label, opts);
35
+ handleAncestors(ctor);
36
+ updateSigil(ctor, label);
37
+ resolved.add(ctor);
38
+ hasOwnSigilRegistry.add(ctor);
39
+ }
40
+ function hasOwnSigil(ctor) {
41
+ return hasOwnSigilRegistry.has(ctor);
42
+ }
43
+ function verifyLabel(label, opts) {
44
+ var _a;
45
+ const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
46
+ if (labelValidation) {
47
+ let valid;
48
+ if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
49
+ else valid = labelValidation(label);
50
+ if (!valid)
51
+ throw new Error(
52
+ `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`
53
+ );
54
+ }
55
+ }
56
+ function handleAncestors(ctor) {
57
+ let a = Object.getPrototypeOf(ctor);
58
+ while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
59
+ resolved.add(a);
60
+ a = Object.getPrototypeOf(a);
61
+ }
62
+ }
63
+ function updateSigil(ctor, label) {
64
+ var _a, _b, _c;
65
+ const sym = Symbol.for(label);
66
+ Object.defineProperty(ctor.prototype, __SIGIL__, {
67
+ value: sym,
68
+ configurable: false,
69
+ enumerable: false,
70
+ writable: false
71
+ });
72
+ Object.defineProperty(ctor.prototype, __LABEL__, {
73
+ value: label,
74
+ configurable: false,
75
+ enumerable: false,
76
+ writable: false
77
+ });
78
+ Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {
79
+ value: [...(_b = (_a = Object.getPrototypeOf(ctor)) == null ? void 0 : _a.prototype[__SIGIL_LINEAGE__]) != null ? _b : [], sym],
80
+ configurable: false,
81
+ enumerable: false,
82
+ writable: false
83
+ });
84
+ Object.defineProperty(ctor.prototype, __DEPTH__, {
85
+ value: ((_c = ctor.prototype[__DEPTH__]) != null ? _c : -1) + 1,
86
+ configurable: false,
87
+ enumerable: false,
88
+ writable: false
89
+ });
90
+ Object.defineProperty(ctor.prototype, sym, {
91
+ value: true,
92
+ configurable: false,
93
+ enumerable: false,
94
+ writable: false
95
+ });
96
+ }
97
+
98
+ // src/mixin.ts
99
+ function BaseSigilify(Base) {
100
+ class Sigil2 extends Base {
101
+ /**
102
+ * Class-level identity label constant for this sigil constructor.
103
+ */
104
+ static get SigilLabel() {
105
+ return this.prototype[__LABEL__];
106
+ }
107
+ /**
108
+ * Copy of the sigil label lineage for this instance's constructor.
109
+ *
110
+ * Useful for debugging and logging.
111
+ *
112
+ * @returns An array of sigil labels representing parent → child labels.
113
+ */
114
+ static get SigilLabelLineage() {
115
+ return this.prototype[__SIGIL_LINEAGE__].map((v) => v.description);
116
+ }
117
+ /** Check if sigil label has been attached to this class */
118
+ static get hasOwnSigil() {
119
+ return hasOwnSigil(this);
120
+ }
121
+ constructor(...args) {
122
+ super(...args);
123
+ }
124
+ /**
125
+ * Check whether `other` is (or inherits from) the instance represented by the
126
+ * calling constructor.
127
+ *
128
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
129
+ * and when subclassing.
130
+ *
131
+ * @typeParam T - The specific sigil constructor (`this`).
132
+ * @param this - The constructor performing the type check.
133
+ * @param other - The object to test.
134
+ * @returns A type guard asserting `other` is an instance of the constructor.
135
+ */
136
+ static isInstance(other) {
137
+ if (other == null || typeof other !== "object") return false;
138
+ return other[this.prototype[__SIGIL__]] === true;
139
+ }
140
+ /**
141
+ * Check whether `other` is exactly the same instance represented by the
142
+ * calling constructor.
143
+ *
144
+ * @typeParam T - The specific sigil constructor (`this`).
145
+ * @param this - The constructor performing the type check.
146
+ * @param other - The object to test.
147
+ * @returns A type guard asserting `other` is an instance of the constructor.
148
+ */
149
+ static isExactInstance(other) {
150
+ if (other == null || typeof other !== "object") return false;
151
+ if (this.prototype[__DEPTH__] !== other[__DEPTH__]) return false;
152
+ return other[this.prototype[__SIGIL__]] === true;
153
+ }
154
+ /**
155
+ * Check whether `other` is (or inherits from) the instance represented by the
156
+ * calling constructor.
157
+ *
158
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
159
+ * and when subclassing.
160
+ *
161
+ * @typeParam T - The specific sigil constructor (`this`).
162
+ * @param this - The constructor performing the type check.
163
+ * @param other - The object to test.
164
+ * @returns A type guard asserting `other` is an instance of the constructor.
165
+ */
166
+ isInstance(other) {
167
+ if (other == null || typeof other !== "object") return false;
168
+ return other[this[__SIGIL__]] === true;
169
+ }
170
+ /**
171
+ * Check whether `other` is exactly the same instance represented by the
172
+ * calling constructor.
173
+ *
174
+ * @typeParam T - The specific sigil constructor (`this`).
175
+ * @param this - The constructor performing the type check.
176
+ * @param other - The object to test.
177
+ * @returns A type guard asserting `other` is an instance of the constructor.
178
+ */
179
+ isExactInstance(other) {
180
+ if (other == null || typeof other !== "object") return false;
181
+ if (this[__DEPTH__] !== other[__DEPTH__]) return false;
182
+ return other[this[__SIGIL__]] === true;
183
+ }
184
+ /**
185
+ * Returns the identity sigil label of this instance's constructor.
186
+ *
187
+ * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').
188
+ */
189
+ get SigilLabel() {
190
+ return this[__LABEL__];
191
+ }
192
+ /**
193
+ * Copy of the sigil label lineage for this instance's constructor.
194
+ *
195
+ * Useful for debugging and logging.
196
+ *
197
+ * @returns An array of sigil labels representing parent → child labels.
198
+ */
199
+ get SigilLabelLineage() {
200
+ return this[__SIGIL_LINEAGE__].map((v) => v.description);
201
+ }
202
+ /** Check if sigil label has been attached to this class */
203
+ get hasOwnSigil() {
204
+ return this.constructor.hasOwnSigil;
205
+ }
206
+ }
207
+ sigilify(Sigil2, "Sigil");
208
+ return Sigil2;
209
+ }
210
+ function Sigilify(Base, label, opts) {
211
+ if (isSigilCtor(Base))
212
+ throw new Error(
213
+ `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
214
+ );
215
+ const BaseSigil = BaseSigilify(Base);
216
+ class Sigilified extends BaseSigil {
217
+ }
218
+ sigilify(Sigilified, label, opts);
219
+ return Sigilified;
220
+ }
221
+ function SigilifyAbstract(Base, label, opts) {
222
+ if (isSigilCtor(Base))
223
+ throw new Error(
224
+ `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
225
+ );
226
+ const BaseSigil = BaseSigilify(Base);
227
+ class Sigilified extends BaseSigil {
228
+ }
229
+ sigilify(Sigilified, label, opts);
230
+ return Sigilified;
231
+ }
232
+
233
+ // src/classes.ts
234
+ var Sigil = BaseSigilify(class {
235
+ });
236
+ var SigilError = Sigilify(Error, "SigilError");
237
+
238
+ // src/attach.ts
239
+ function AttachSigil(label, opts) {
240
+ return function(target, ctx) {
241
+ if (!isSigilCtor(target))
242
+ throw new Error(
243
+ `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`
244
+ );
245
+ sigilify(target, label, opts);
246
+ };
247
+ }
248
+ function attachSigil(Class, label, opts) {
249
+ if (!isSigilCtor(Class))
250
+ throw new Error(
251
+ `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`
252
+ );
253
+ sigilify(Class, label, opts);
254
+ return Class;
255
+ }
256
+
257
+ exports.AttachSigil = AttachSigil;
258
+ exports.RECOMMENDED_LABEL_REGEX = RECOMMENDED_LABEL_REGEX;
259
+ exports.Sigil = Sigil;
260
+ exports.SigilError = SigilError;
261
+ exports.Sigilify = Sigilify;
262
+ exports.SigilifyAbstract = SigilifyAbstract;
263
+ exports.attachSigil = attachSigil;
264
+ exports.hasOwnSigil = hasOwnSigil;
265
+ exports.isSigilCtor = isSigilCtor;
266
+ exports.isSigilInstance = isSigilInstance;
267
+ exports.updateSigilOptions = updateSigilOptions;
268
+ //# sourceMappingURL=index.cjs.map
269
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["Sigil"],"mappings":";;;AAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,iBAAA,mBAAoB,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;AASrE,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,SA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AAA,EACA,IAAA,EACA;AACA,EAAA,IAAI,YAAY,IAAI,CAAA;AAClB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,qBAAA,EAAwB,IAAA,CAAK,IAAI,CAAA,cAAA,EAAiB,KAAK,UAAU,CAAA,uBAAA;AAAA,KACnE;AAEF,EAAA,MAAM,SAAA,GAAY,aAAa,IAAI,CAAA;AAAA,EACnC,MAAe,mBAAmB,SAAA,CAAU;AAAA;AAI5C,EAAA,QAAA,CAAS,UAAA,EAAY,OAAO,IAAI,CAAA;AAChC,EAAA,OAAO,UAAA;AACT;;;ACtLO,IAAM,KAAA,GAAQ,aAAa,MAAM;AAAC,CAAC;AAUnC,IAAM,UAAA,GAAa,QAAA,CAAS,KAAA,EAAO,YAAY;;;ACR/C,SAAS,WAAA,CAAY,OAAe,IAAA,EAAqB;AAC9D,EAAA,OAAO,SAAU,QAAkB,GAAA,EAAU;AAC3C,IAAA,IAAI,CAAC,YAAY,MAAM,CAAA;AACrB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,mFAAA,EAAsF,OAAO,IAAI,CAAA,CAAA;AAAA,OACnG;AAEF,IAAA,QAAA,CAAS,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EAC9B,CAAA;AACF;AAYO,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;AAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;AACpB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;AAAA,KACjG;AAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;AAC3B,EAAA,OAAO,KAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\n\n/** -----------------------------------------\n * Maps\n * ----------------------------------------- */\n\n/** Weak set to ensure that every ctor is handled only once */\nconst resolved = new WeakSet<Function>();\n\n/** Weak set to store ctors that called sigilify function */\nconst hasOwnSigilRegistry = new WeakSet<Function>();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (resolved.has(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n resolved.add(ctor);\n hasOwnSigilRegistry.add(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return hasOwnSigilRegistry.has(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n resolved.add(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor)?.prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}