@vicin/sigil 3.0.0 → 3.1.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,2 +1,516 @@
1
- import {createId}from'@paralleldrive/cuid2';var w={labelValidation:null,skipLabelInheritanceCheck:false,autofillLabels:true},V=i=>{if("autofillLabels"in i){if(typeof i.autofillLabels!="boolean")throw new Error("'updateSigilOptions.autofillLabels' must be boolean");w.autofillLabels=i.autofillLabels;}if("skipLabelInheritanceCheck"in i){if(typeof i.skipLabelInheritanceCheck!="boolean")throw new Error("'updateSigilOptions.skipLabelInheritanceCheck' must be boolean");w.skipLabelInheritanceCheck=i.skipLabelInheritanceCheck;}if("labelValidation"in i){let t=i.labelValidation;if(t!==null&&typeof t!="function"&&!(t instanceof RegExp))throw new Error("'updateSigilOptions.labelValidation' must be null, function or RegExp");w.labelValidation=t!=null?t:null;}},P=/^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;var k=Symbol.for("@vicin/sigil.__SIGIL__"),T=Symbol.for("@vicin/sigil.__SIGIL_BASE__"),C=Symbol.for("@vicin/sigil.__DECORATED__"),v=Symbol.for("@vicin/sigil.__INHERITANCE_CHECKED__"),p=Symbol.for("@vicin/sigil.__LABEL__"),O=Symbol.for("@vicin/sigil.__EFFECTIVE_LABEL__"),g=Symbol.for("@vicin/sigil.__LABEL_LINEAGE__"),_=Symbol.for("@vicin/sigil.__LABEL_SET__");function L(i,t,n){if(process.env.NODE_ENV!=="production"&&B(i))throw new Error(`Constructor ${i} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`);Object.defineProperty(i,p,{value:t,configurable:true,enumerable:false,writable:false}),n!=null&&n.isInheritanceCheck||Object.defineProperty(i,O,{value:t,configurable:true,enumerable:false,writable:false});let o=Object.getPrototypeOf(i),l=o&&o[g]?o[g]:[],S=n!=null&&n.isMixin&&t!=="Sigil"?["Sigil",...l,t]:[...l,t];Object.defineProperty(i,g,{value:S,configurable:true,enumerable:false,writable:false}),Object.defineProperty(i,_,{value:new Set(S),configurable:true,enumerable:false,writable:false}),n!=null&&n.isInheritanceCheck||F(i);}function f(i,t){var S,e;if(b(i)||((S=t==null?void 0:t.skipLabelInheritanceCheck)!=null?S:w.skipLabelInheritanceCheck))return;let n=[i],o=Object.getPrototypeOf(i);for(;h(o);)n.push(o),o=Object.getPrototypeOf(o);let l=new Map;for(let r=n.length-1;r>=0;r--){let c=n[r];if(!c)continue;let s=c[p];if(l.has(s)){if(process.env.NODE_ENV!=="production"&&(B(c)||!((e=t==null?void 0:t.autofillLabels)!=null?e:w.autofillLabels)))throw new Error(`[Sigil Error] Class "${c.name}" re-uses Sigil label "${s}" from ancestor "${l.get(s)}". Each Sigil subclass must use a unique label. Did you forget to use "WithSigil(newLabel)" on the subclass?`);s=y(),L(c,s,{isInheritanceCheck:true});}l.set(s,c.name);}R(i);}function I(i,t){var o;let n=(o=t==null?void 0:t.labelValidation)!=null?o:w.labelValidation;if(n){let l;if(n instanceof RegExp?l=n.test(i):l=n(i),process.env.NODE_ENV!=="production"&&!l)throw new Error(`[Sigil] Invalid identity label "${i}". Make sure that supplied label matches validation regex or function.`)}}function y(){return `@Sigil.auto-${createId()}`}function A(i){Object.defineProperty(i,k,{value:true,configurable:false,enumerable:false,writable:false});}function N(i){Object.defineProperty(i,T,{value:true,configurable:false,enumerable:false,writable:false});}function F(i){Object.defineProperty(i,C,{value:true,configurable:false,enumerable:false,writable:false});}function R(i){Object.defineProperty(i,v,{value:true,configurable:false,enumerable:false,writable:false});}function h(i){return typeof i=="function"&&i[k]===true}function u(i){if(!i||typeof i!="object")return false;let t=a(i);return h(t)}function D(i){return Object.hasOwn(i,T)}function $(i){if(!i||typeof i!="object")return false;let t=a(i);return D(t)}function B(i){return Object.hasOwn(i,C)}function b(i){return Object.hasOwn(i,v)}function a(i){var t,n,o;return !i||typeof i!="object"?null:(o=(n=i.constructor)!=null?n:(t=Object.getPrototypeOf(i))==null?void 0:t.constructor)!=null?o:null}function m(i,t,n){if(h(i))throw new Error(`[Sigil Error] 'Sigilify(${t})' already sigilified.`);let o;t?(I(t,n),o=t):o=y();class l extends i{static get SigilLabel(){return b(this)||f(this),this[p]}static get SigilEffectiveLabel(){return this[O]}static get SigilLabelLineage(){var e;return b(this)||f(this),[...(e=this[g])!=null?e:[]]}static get SigilLabelSet(){b(this)||f(this);let e=new Set;for(let r of this[_])e.add(r);return e}constructor(...e){super(...e),Object.getPrototypeOf(this)!==new.target.prototype&&Object.setPrototypeOf(this,new.target.prototype);let r=a(this);if(!r){if(process.env.NODE_ENV!=="production")throw new Error(`[Sigil Error] 'Sigilify(${t})' instance without constructor`);return}f(r);}static isSigilified(e){return u(e)}static isOfType(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[_],c=this[p];return !!r&&r.has(c)}static isOfTypeStrict(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[g],c=this[g];return !!r&&c.every((E,d)=>E===r[d])}isOfType(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[_],c=a(this)[p];return !!r&&r.has(c)}isOfTypeStrict(e){var s,E;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[g],c=(E=a(this))==null?void 0:E[g];return !!r&&c.every((d,x)=>d===r[x])}getSigilLabel(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return "@Sigil.unknown"}return e.SigilLabel}getSigilEffectiveLabel(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return "@Sigil.unknown"}return e.SigilEffectiveLabel}getSigilLabelLineage(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return ["@Sigil.unknown"]}return e.SigilLabelLineage}getSigilLabelSet(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return new Set(["@Sigil.unknown"])}return e.SigilLabelSet}}return L(l,o,{isMixin:true}),A(l),N(l),l}function G(i,t,n){if(h(i))throw new Error(`[Sigil Error] 'Sigilify(${t})' already sigilified.`);let o;t?(I(t,n),o=t):o=y();class l extends i{static get SigilLabel(){return b(this)||f(this),this[p]}static get SigilEffectiveLabel(){return this[O]}static get SigilLabelLineage(){var e;return b(this)||f(this),[...(e=this[g])!=null?e:[]]}static get SigilLabelSet(){b(this)||f(this);let e=new Set;for(let r of this[_])e.add(r);return e}constructor(...e){super(...e),Object.getPrototypeOf(this)!==new.target.prototype&&Object.setPrototypeOf(this,new.target.prototype);let r=a(this);if(!r){if(process.env.NODE_ENV!=="production")throw new Error(`[Sigil Error] 'Sigilify(${t})' instance without constructor`);return}f(r);}static isSigilified(e){return u(e)}static isOfType(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[_],c=this[p];return !!r&&r.has(c)}static isOfTypeStrict(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[g],c=this[g];return !!r&&c.every((E,d)=>E===r[d])}isOfType(e){var s;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[_],c=a(this)[p];return !!r&&r.has(c)}isOfTypeStrict(e){var s,E;if(!u(e))return false;let r=(s=a(e))==null?void 0:s[g],c=(E=a(this))==null?void 0:E[g];return !!r&&c.every((d,x)=>d===r[x])}getSigilLabel(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return "@Sigil.unknown"}return e.SigilLabel}getSigilEffectiveLabel(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return "@Sigil.unknown"}return e.SigilEffectiveLabel}getSigilLabelLineage(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return ["@Sigil.unknown"]}return e.SigilLabelLineage}getSigilLabelSet(){let e=a(this);if(!e){if(process.env.NODE_ENV!=="production")throw new Error("[Sigil Error] Sigil class instance without constructor");return new Set(["@Sigil.unknown"])}return e.SigilLabelSet}}return L(l,o,{isMixin:true}),A(l),N(l),l}var H=m(class{},"Sigil"),M=m(Error,"SigilError");function K(i,t){let n;return i?(I(i,t),n=i):n=y(),function(o,l){if(l.kind==="class"){if(!h(o))throw new Error(`[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${o.name}`);L(o,n),f(o,t);}}}function W(i,t,n){var S;if(!h(i))throw new Error(`[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${(S=i==null?void 0:i.name)!=null?S:"unknown"}`);let o;t?(I(t,n),o=t):o=y();let l=i;return L(l,o),f(l,n),i}export{P as DEFAULT_LABEL_REGEX,H as Sigil,M as SigilError,m as Sigilify,G as SigilifyAbstract,K as WithSigil,B as isDecorated,b as isInheritanceChecked,D as isSigilBaseCtor,$ as isSigilBaseInstance,h as isSigilCtor,u as isSigilInstance,V as updateSigilOptions,W as withSigil};//# sourceMappingURL=index.mjs.map
1
+ // src/options.ts
2
+ var OPTIONS = {
3
+ labelValidation: null,
4
+ autofillLabels: true
5
+ };
6
+ var updateSigilOptions = (opts) => {
7
+ if ("autofillLabels" in opts) {
8
+ if (typeof opts.autofillLabels !== "boolean")
9
+ throw new Error("'updateSigilOptions.autofillLabels' must be boolean");
10
+ OPTIONS.autofillLabels = opts.autofillLabels;
11
+ }
12
+ if ("labelValidation" in opts) {
13
+ const val = opts.labelValidation;
14
+ if (val !== null && typeof val !== "function" && !(val instanceof RegExp))
15
+ throw new Error("'updateSigilOptions.labelValidation' must be null, function or RegExp");
16
+ OPTIONS.labelValidation = val != null ? val : null;
17
+ }
18
+ };
19
+ var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
20
+
21
+ // src/symbols.ts
22
+ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL__");
23
+ var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
24
+ var __EFFECTIVE_LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__EFFECTIVE_LABEL__");
25
+ var __LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LINEAGE__");
26
+
27
+ // src/helpers.ts
28
+ var AUTO_LABEL_PREFEX = "@Sigil-auto";
29
+ var handledCtors = /* @__PURE__ */ new WeakSet();
30
+ function handleSigil(ctor, label, opts) {
31
+ if (handledCtors.has(ctor)) return;
32
+ handledCtors.add(ctor);
33
+ verifyLabel(ctor, label, opts);
34
+ const ancLabelsMap = handleAncestors(ctor, opts);
35
+ if (label && ancLabelsMap.has(label))
36
+ throw new Error(
37
+ `[Sigil Error] Attempt to assign label '${label}' to ${ctor.name} but label is already used by parent '${ancLabelsMap.get(label)}', Make sure that every class has a unique label`
38
+ );
39
+ sigilify(ctor, label != null ? label : generateRandomLabel(ctor));
40
+ }
41
+ function handleAncestors(ctor, opts) {
42
+ var _a;
43
+ const autofillLabels = (_a = opts == null ? void 0 : opts.autofillLabels) != null ? _a : OPTIONS.autofillLabels;
44
+ const ancestors = [];
45
+ let a = Object.getPrototypeOf(ctor);
46
+ while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
47
+ ancestors.unshift(a);
48
+ a = Object.getPrototypeOf(a);
49
+ }
50
+ const labelOwner = /* @__PURE__ */ new Map();
51
+ for (const a2 of ancestors) {
52
+ const l = a2.prototype[__LABEL__];
53
+ if (labelOwner.has(l)) {
54
+ if (!autofillLabels)
55
+ throw new Error(
56
+ `[Sigil Error] Class '${a2.name}' is not sigilified with 'autofillLabels' setted to 'false', Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`
57
+ );
58
+ sigilify(a2, generateRandomLabel(a2));
59
+ }
60
+ labelOwner.set(labelOf(a2), a2.name);
61
+ }
62
+ return labelOwner;
63
+ }
64
+ function sigilify(ctor, label) {
65
+ var _a;
66
+ const sym = Symbol.for(label);
67
+ Object.defineProperty(ctor.prototype, __SIGIL__, {
68
+ value: sym,
69
+ configurable: false,
70
+ enumerable: false,
71
+ writable: false
72
+ });
73
+ Object.defineProperty(ctor.prototype, sym, {
74
+ value: true,
75
+ configurable: false,
76
+ enumerable: false,
77
+ writable: false
78
+ });
79
+ Object.defineProperty(ctor.prototype, __LABEL__, {
80
+ value: label,
81
+ configurable: false,
82
+ enumerable: false,
83
+ writable: false
84
+ });
85
+ if (!label.startsWith(AUTO_LABEL_PREFEX))
86
+ Object.defineProperty(ctor.prototype, __EFFECTIVE_LABEL__, {
87
+ value: label,
88
+ configurable: false,
89
+ enumerable: false,
90
+ writable: false
91
+ });
92
+ Object.defineProperty(ctor.prototype, __LINEAGE__, {
93
+ value: /* @__PURE__ */ new Set(["Sigil", ...(_a = lineageOf(ctor)) != null ? _a : [], label]),
94
+ configurable: false,
95
+ enumerable: false,
96
+ writable: false
97
+ });
98
+ const sigilSym = /* @__PURE__ */ Symbol.for("Sigil");
99
+ if (ctor.prototype[sigilSym] !== true)
100
+ Object.defineProperty(ctor.prototype, sigilSym, {
101
+ value: true,
102
+ configurable: false,
103
+ enumerable: false,
104
+ writable: false
105
+ });
106
+ }
107
+ function isSigilCtor(ctor) {
108
+ return typeof ctor === "function" && __SIGIL__ in ctor.prototype;
109
+ }
110
+ function isSigilInstance(inst) {
111
+ return !!inst && typeof inst === "object" && __SIGIL__ in inst;
112
+ }
113
+ function hasOwnSigil(ctor) {
114
+ return typeof ctor === "function" && Object.hasOwn(ctor.prototype, __SIGIL__);
115
+ }
116
+ function labelOf(ctor) {
117
+ return ctor.prototype[__LABEL__];
118
+ }
119
+ function lineageOf(ctor) {
120
+ return ctor.prototype[__LINEAGE__];
121
+ }
122
+ function verifyLabel(ctor, label, opts) {
123
+ var _a, _b;
124
+ const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
125
+ const autofillLabels = (_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels;
126
+ if (!label) {
127
+ if (!autofillLabels)
128
+ throw new Error(
129
+ `[Sigil Error] Class '${ctor.name}' is not sigilified with 'autofillLabels' setted to 'false', Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`
130
+ );
131
+ return;
132
+ }
133
+ if (label.startsWith(AUTO_LABEL_PREFEX))
134
+ throw new Error(`'${AUTO_LABEL_PREFEX}' is a prefex reserved by the library`);
135
+ if (labelValidation) {
136
+ let valid;
137
+ if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
138
+ else valid = labelValidation(label);
139
+ if (process.env.NODE_ENV !== "production") {
140
+ if (!valid)
141
+ throw new Error(
142
+ `[Sigil Error] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function`
143
+ );
144
+ }
145
+ }
146
+ }
147
+ if (!globalThis.__SigilabelCounter) globalThis.__SigilabelCounter = 0;
148
+ function generateRandomLabel(ctor) {
149
+ const namePart = ctor && typeof ctor.name === "string" && ctor.name.length ? ctor.name : "C";
150
+ const counter = globalThis.__SigilabelCounter++;
151
+ const time = Date.now().toString(36);
152
+ const rand = Math.random().toString(36).slice(2, 6);
153
+ return `${AUTO_LABEL_PREFEX}:${namePart}:${time}:${counter.toString(36)}:${rand}`;
154
+ }
155
+
156
+ // src/mixin.ts
157
+ function Sigilify(Base, label, opts) {
158
+ if (hasOwnSigil(Base))
159
+ throw new Error(
160
+ `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
161
+ );
162
+ class Sigilified extends Base {
163
+ /**
164
+ * Class-level identity label constant for this sigil constructor.
165
+ */
166
+ static get SigilLabel() {
167
+ var _a;
168
+ handleSigil(this);
169
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
170
+ }
171
+ /**
172
+ * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
173
+ */
174
+ static get SigilEffectiveLabel() {
175
+ var _a;
176
+ handleSigil(this);
177
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
178
+ }
179
+ /**
180
+ * Linearized sigil type label chain for the current constructor.
181
+ *
182
+ * Useful for debugging and performing strict lineage comparisons.
183
+ *
184
+ * @returns An array of labels representing parent → child type labels.
185
+ */
186
+ static get SigilLabelLineage() {
187
+ var _a, _b;
188
+ handleSigil(this);
189
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
190
+ }
191
+ /**
192
+ * Sigil type label set for the current constructor.
193
+ * Useful for debugging.
194
+ *
195
+ * @returns A Readonly Set of labels that represent the type lineage.
196
+ */
197
+ static get SigilLabelSet() {
198
+ var _a;
199
+ handleSigil(this);
200
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
201
+ }
202
+ constructor(...args) {
203
+ super(...args);
204
+ const ctor = new.target;
205
+ handleSigil(ctor);
206
+ }
207
+ /**
208
+ * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
209
+ *
210
+ * @param obj - The value to test.
211
+ * @returns `true` if `obj` is a sigil instance.
212
+ */
213
+ static isSigilified(obj) {
214
+ return isSigilInstance(obj);
215
+ }
216
+ /**
217
+ * Check whether `other` is (or inherits from) the instance represented by the
218
+ * calling constructor.
219
+ *
220
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
221
+ * and when subclassing.
222
+ *
223
+ * @typeParam T - The specific sigil constructor (`this`).
224
+ * @param this - The constructor performing the type check.
225
+ * @param other - The object to test.
226
+ * @returns A type guard asserting `other` is an instance of the constructor.
227
+ */
228
+ static isOfType(other) {
229
+ var _a;
230
+ handleSigil(this);
231
+ if (other == null || typeof other !== "object") return false;
232
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
233
+ }
234
+ /**
235
+ * Check whether `other` is exactly the same instance represented by the
236
+ * calling constructor.
237
+ *
238
+ * @typeParam T - The specific sigil constructor (`this`).
239
+ * @param this - The constructor performing the type check.
240
+ * @param other - The object to test.
241
+ * @returns A type guard asserting `other` is an instance of the constructor.
242
+ */
243
+ static isExactType(other) {
244
+ var _a, _b, _c;
245
+ handleSigil(this);
246
+ if (other == null || typeof other !== "object") return false;
247
+ if (((_a = this.prototype) == null ? void 0 : _a[__LINEAGE__].size) !== ((_b = other[__LINEAGE__]) == null ? void 0 : _b.size))
248
+ return false;
249
+ return other[(_c = this.prototype) == null ? void 0 : _c[__SIGIL__]] === true;
250
+ }
251
+ /**
252
+ * Check whether `other` is (or inherits from) the instance represented by the
253
+ * calling constructor.
254
+ *
255
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
256
+ * and when subclassing.
257
+ *
258
+ * @typeParam T - The specific sigil constructor (`this`).
259
+ * @param this - The constructor performing the type check.
260
+ * @param other - The object to test.
261
+ * @returns A type guard asserting `other` is an instance of the constructor.
262
+ */
263
+ isOfType(other) {
264
+ if (other == null || typeof other !== "object") return false;
265
+ return other[this[__SIGIL__]] === true;
266
+ }
267
+ /**
268
+ * Check whether `other` is exactly the same instance represented by the
269
+ * calling constructor.
270
+ *
271
+ * @typeParam T - The specific sigil constructor (`this`).
272
+ * @param this - The constructor performing the type check.
273
+ * @param other - The object to test.
274
+ * @returns A type guard asserting `other` is an instance of the constructor.
275
+ */
276
+ isExactType(other) {
277
+ var _a;
278
+ if (other == null || typeof other !== "object") return false;
279
+ if (this[__LINEAGE__].size !== ((_a = other[__LINEAGE__]) == null ? void 0 : _a.size)) return false;
280
+ return other[this[__SIGIL__]] === true;
281
+ }
282
+ /**
283
+ * Returns the identity sigil label of this instance's constructor.
284
+ *
285
+ * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
286
+ */
287
+ getSigilLabel() {
288
+ return this[__LABEL__];
289
+ }
290
+ /**
291
+ * Returns the human-readable sigil label of this instance's constructor.
292
+ *
293
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
294
+ */
295
+ getSigilEffectiveLabel() {
296
+ return this[__EFFECTIVE_LABEL__];
297
+ }
298
+ /**
299
+ * Returns a copy of the sigil type label lineage for this instance's constructor.
300
+ *
301
+ * @returns readonly array of labels representing the type lineage.
302
+ */
303
+ getSigilLabelLineage() {
304
+ return [...this[__LINEAGE__]];
305
+ }
306
+ /**
307
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
308
+ *
309
+ * @returns readonly array of labels representing the type lineage.
310
+ */
311
+ getSigilLabelSet() {
312
+ return this[__LINEAGE__];
313
+ }
314
+ }
315
+ handleSigil(Sigilified, label, opts);
316
+ return Sigilified;
317
+ }
318
+ function SigilifyAbstract(Base, label, opts) {
319
+ if (hasOwnSigil(Base))
320
+ throw new Error(
321
+ `[Sigil Error] Base class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
322
+ );
323
+ class Sigilified extends Base {
324
+ /**
325
+ * Class-level identity label constant for this sigil constructor.
326
+ */
327
+ static get SigilLabel() {
328
+ var _a;
329
+ handleSigil(this);
330
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
331
+ }
332
+ /**
333
+ * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
334
+ */
335
+ static get SigilEffectiveLabel() {
336
+ var _a;
337
+ handleSigil(this);
338
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
339
+ }
340
+ /**
341
+ * Linearized sigil type label chain for the current constructor.
342
+ *
343
+ * Useful for debugging and performing strict lineage comparisons.
344
+ *
345
+ * @returns An array of labels representing parent → child type labels.
346
+ */
347
+ static get SigilLabelLineage() {
348
+ var _a, _b;
349
+ handleSigil(this);
350
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
351
+ }
352
+ /**
353
+ * Sigil type label set for the current constructor.
354
+ * Useful for debugging.
355
+ *
356
+ * @returns A Readonly Set of labels that represent the type lineage.
357
+ */
358
+ static get SigilLabelSet() {
359
+ var _a;
360
+ handleSigil(this);
361
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
362
+ }
363
+ constructor(...args) {
364
+ super(...args);
365
+ const ctor = new.target;
366
+ handleSigil(ctor);
367
+ }
368
+ /**
369
+ * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
370
+ *
371
+ * @param obj - The value to test.
372
+ * @returns `true` if `obj` is a sigil instance.
373
+ */
374
+ static isSigilified(obj) {
375
+ return isSigilInstance(obj);
376
+ }
377
+ /**
378
+ * Check whether `other` is (or inherits from) the instance represented by the
379
+ * calling constructor.
380
+ *
381
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
382
+ * and when subclassing.
383
+ *
384
+ * @typeParam T - The specific sigil constructor (`this`).
385
+ * @param this - The constructor performing the type check.
386
+ * @param other - The object to test.
387
+ * @returns A type guard asserting `other` is an instance of the constructor.
388
+ */
389
+ static isOfType(other) {
390
+ var _a;
391
+ if (other == null || typeof other !== "object") return false;
392
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
393
+ }
394
+ /**
395
+ * Check whether `other` is exactly the same instance represented by the
396
+ * calling constructor.
397
+ *
398
+ * @typeParam T - The specific sigil constructor (`this`).
399
+ * @param this - The constructor performing the type check.
400
+ * @param other - The object to test.
401
+ * @returns A type guard asserting `other` is an instance of the constructor.
402
+ */
403
+ static isExactType(other) {
404
+ var _a, _b, _c;
405
+ if (other == null || typeof other !== "object") return false;
406
+ if (((_a = this.prototype) == null ? void 0 : _a[__LINEAGE__].size) !== ((_b = other[__LINEAGE__]) == null ? void 0 : _b.size))
407
+ return false;
408
+ return other[(_c = this.prototype) == null ? void 0 : _c[__SIGIL__]] === true;
409
+ }
410
+ /**
411
+ * Check whether `other` is (or inherits from) the instance represented by the
412
+ * calling constructor.
413
+ *
414
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
415
+ * and when subclassing.
416
+ *
417
+ * @typeParam T - The specific sigil constructor (`this`).
418
+ * @param this - The constructor performing the type check.
419
+ * @param other - The object to test.
420
+ * @returns A type guard asserting `other` is an instance of the constructor.
421
+ */
422
+ isOfType(other) {
423
+ if (other == null || typeof other !== "object") return false;
424
+ return other[this[__SIGIL__]] === true;
425
+ }
426
+ /**
427
+ * Check whether `other` is exactly the same instance represented by the
428
+ * calling constructor.
429
+ *
430
+ * @typeParam T - The specific sigil constructor (`this`).
431
+ * @param this - The constructor performing the type check.
432
+ * @param other - The object to test.
433
+ * @returns A type guard asserting `other` is an instance of the constructor.
434
+ */
435
+ isExactType(other) {
436
+ var _a;
437
+ if (other == null || typeof other !== "object") return false;
438
+ if (this[__LINEAGE__].size !== ((_a = other[__LINEAGE__]) == null ? void 0 : _a.size)) return false;
439
+ return other[this[__SIGIL__]] === true;
440
+ }
441
+ /**
442
+ * Returns the identity sigil label of this instance's constructor.
443
+ *
444
+ * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
445
+ */
446
+ getSigilLabel() {
447
+ return this[__LABEL__];
448
+ }
449
+ /**
450
+ * Returns the human-readable sigil label of this instance's constructor.
451
+ *
452
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
453
+ */
454
+ getSigilEffectiveLabel() {
455
+ return this[__EFFECTIVE_LABEL__];
456
+ }
457
+ /**
458
+ * Returns a copy of the sigil type label lineage for this instance's constructor.
459
+ *
460
+ * @returns readonly array of labels representing the type lineage.
461
+ */
462
+ getSigilLabelLineage() {
463
+ return [...this[__LINEAGE__]];
464
+ }
465
+ /**
466
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
467
+ *
468
+ * @returns readonly array of labels representing the type lineage.
469
+ */
470
+ getSigilLabelSet() {
471
+ return this[__LINEAGE__];
472
+ }
473
+ }
474
+ handleSigil(Sigilified, label, opts);
475
+ return Sigilified;
476
+ }
477
+
478
+ // src/classes.ts
479
+ var Sigil = Sigilify(class {
480
+ }, "Sigil");
481
+ var SigilError = Sigilify(Error, "SigilError");
482
+
483
+ // src/decorator.ts
484
+ function WithSigil(label, opts) {
485
+ return function(value, context) {
486
+ if (context.kind !== "class") return;
487
+ if (!isSigilCtor(value))
488
+ throw new Error(
489
+ `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
490
+ );
491
+ if (hasOwnSigil(value))
492
+ throw new Error(
493
+ `[Sigil Error] Class '${value.name}' with label '${value.SigilLabel}' is already sigilified`
494
+ );
495
+ handleSigil(value, label, opts);
496
+ };
497
+ }
498
+
499
+ // src/hof.ts
500
+ function withSigil(Class, label, opts) {
501
+ var _a;
502
+ if (!isSigilCtor(Class))
503
+ throw new Error(
504
+ `[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
505
+ );
506
+ if (hasOwnSigil(Class))
507
+ throw new Error(
508
+ `[Sigil Error] Class '${Class.name}' with label '${Class.SigilLabel}' is already sigilified`
509
+ );
510
+ handleSigil(Class, label, opts);
511
+ return Class;
512
+ }
513
+
514
+ export { DEFAULT_LABEL_REGEX, Sigil, SigilError, Sigilify, SigilifyAbstract, WithSigil, isSigilCtor, isSigilInstance, updateSigilOptions, withSigil };
515
+ //# sourceMappingURL=index.mjs.map
2
516
  //# sourceMappingURL=index.mjs.map