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