@vicin/sigil 2.2.1 → 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,11 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var cuid2 = require('@paralleldrive/cuid2');
4
-
5
- // src/core/options.ts
3
+ // src/options.ts
6
4
  var OPTIONS = {
7
5
  labelValidation: null,
8
- skipLabelInheritanceCheck: false,
9
6
  autofillLabels: true
10
7
  };
11
8
  var updateSigilOptions = (opts) => {
@@ -14,11 +11,6 @@ var updateSigilOptions = (opts) => {
14
11
  throw new Error("'updateSigilOptions.autofillLabels' must be boolean");
15
12
  OPTIONS.autofillLabels = opts.autofillLabels;
16
13
  }
17
- if ("skipLabelInheritanceCheck" in opts) {
18
- if (typeof opts.skipLabelInheritanceCheck !== "boolean")
19
- throw new Error("'updateSigilOptions.skipLabelInheritanceCheck' must be boolean");
20
- OPTIONS.skipLabelInheritanceCheck = opts.skipLabelInheritanceCheck;
21
- }
22
14
  if ("labelValidation" in opts) {
23
15
  const val = opts.labelValidation;
24
16
  if (val !== null && typeof val !== "function" && !(val instanceof RegExp))
@@ -28,218 +20,191 @@ var updateSigilOptions = (opts) => {
28
20
  };
29
21
  var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
30
22
 
31
- // src/core/symbols.ts
32
- var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
33
- var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
34
- var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
35
- var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
36
- var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
37
- var __EFFECTIVE_LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__EFFECTIVE_LABEL__");
38
- var __LABEL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_LINEAGE__");
39
- var __LABEL_SET__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_SET__");
40
- function decorateCtor(ctor, label, runtime) {
41
- if (process.env.NODE_ENV !== "production") {
42
- if (isDecorated(ctor))
43
- throw new Error(
44
- `Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`
45
- );
46
- }
47
- Object.defineProperty(ctor, __LABEL__, {
48
- value: label,
49
- configurable: true,
50
- enumerable: false,
51
- writable: false
52
- });
53
- if (!(runtime == null ? void 0 : runtime.isInheritanceCheck))
54
- Object.defineProperty(ctor, __EFFECTIVE_LABEL__, {
55
- value: label,
56
- configurable: true,
57
- enumerable: false,
58
- writable: false
59
- });
60
- const parent = Object.getPrototypeOf(ctor);
61
- const parentChain = parent && parent[__LABEL_LINEAGE__] ? parent[__LABEL_LINEAGE__] : [];
62
- const ctorChain = (runtime == null ? void 0 : runtime.isMixin) && label !== "Sigil" ? ["Sigil", ...parentChain, label] : [...parentChain, label];
63
- Object.defineProperty(ctor, __LABEL_LINEAGE__, {
64
- value: ctorChain,
65
- configurable: true,
66
- enumerable: false,
67
- writable: false
68
- });
69
- Object.defineProperty(ctor, __LABEL_SET__, {
70
- value: new Set(ctorChain),
71
- configurable: true,
72
- enumerable: false,
73
- writable: false
74
- });
75
- if (!(runtime == null ? void 0 : runtime.isInheritanceCheck)) markDecorated(ctor);
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));
76
42
  }
77
- function checkInheritance(ctor, opts) {
78
- var _a, _b;
79
- if (isInheritanceChecked(ctor) || ((_a = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _a : OPTIONS.skipLabelInheritanceCheck))
80
- return;
81
- const ctors = [ctor];
82
- let ancestor = Object.getPrototypeOf(ctor);
83
- while (isSigilCtor(ancestor)) {
84
- ctors.push(ancestor);
85
- ancestor = Object.getPrototypeOf(ancestor);
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);
86
51
  }
87
52
  const labelOwner = /* @__PURE__ */ new Map();
88
- for (let i = ctors.length - 1; i >= 0; i--) {
89
- const ctor2 = ctors[i];
90
- if (!ctor2) continue;
91
- let label = ctor2[__LABEL__];
92
- if (labelOwner.has(label)) {
93
- if (process.env.NODE_ENV !== "production") {
94
- if (isDecorated(ctor2) || !((_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels))
95
- throw new Error(
96
- `[Sigil Error] Class "${ctor2.name}" re-uses Sigil label "${label}" from ancestor "${labelOwner.get(label)}". Each Sigil subclass must use a unique label. Did you forget to use "WithSigil(newLabel)" on the subclass?`
97
- );
98
- }
99
- label = generateRandomLabel();
100
- decorateCtor(ctor2, label, { isInheritanceCheck: true });
101
- }
102
- labelOwner.set(label, ctor2.name);
103
- }
104
- markInheritanceChecked(ctor);
105
- }
106
- function verifyLabel(label, opts) {
107
- var _a;
108
- const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
109
- if (labelValidation) {
110
- let valid;
111
- if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
112
- else valid = labelValidation(label);
113
- if (process.env.NODE_ENV !== "production") {
114
- if (!valid)
53
+ for (const a2 of ancestors) {
54
+ const l = a2.prototype[__LABEL__];
55
+ if (labelOwner.has(l)) {
56
+ if (!autofillLabels)
115
57
  throw new Error(
116
- `[Sigil] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function.`
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'`
117
59
  );
60
+ sigilify(a2, generateRandomLabel(a2));
118
61
  }
62
+ labelOwner.set(labelOf(a2), a2.name);
119
63
  }
64
+ return labelOwner;
120
65
  }
121
- function generateRandomLabel() {
122
- let label = cuid2.createId();
123
- return `@Sigil.auto-${label}`;
124
- }
125
- function markSigil(ctor) {
126
- Object.defineProperty(ctor, __SIGIL__, {
127
- value: true,
66
+ function sigilify(ctor, label) {
67
+ var _a;
68
+ const sym = Symbol.for(label);
69
+ Object.defineProperty(ctor.prototype, __SIGIL__, {
70
+ value: sym,
128
71
  configurable: false,
129
72
  enumerable: false,
130
73
  writable: false
131
74
  });
132
- }
133
- function markSigilBase(ctor) {
134
- Object.defineProperty(ctor, __SIGIL_BASE__, {
75
+ Object.defineProperty(ctor.prototype, sym, {
135
76
  value: true,
136
77
  configurable: false,
137
78
  enumerable: false,
138
79
  writable: false
139
80
  });
140
- }
141
- function markDecorated(ctor) {
142
- Object.defineProperty(ctor, __DECORATED__, {
143
- value: true,
81
+ Object.defineProperty(ctor.prototype, __LABEL__, {
82
+ value: label,
144
83
  configurable: false,
145
84
  enumerable: false,
146
85
  writable: false
147
86
  });
148
- }
149
- function markInheritanceChecked(ctor) {
150
- Object.defineProperty(ctor, __INHERITANCE_CHECKED__, {
151
- value: true,
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]),
152
96
  configurable: false,
153
97
  enumerable: false,
154
98
  writable: false
155
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
+ });
156
108
  }
157
109
  function isSigilCtor(ctor) {
158
- return typeof ctor === "function" && ctor[__SIGIL__] === true;
110
+ return typeof ctor === "function" && __SIGIL__ in ctor.prototype;
159
111
  }
160
112
  function isSigilInstance(inst) {
161
- if (!inst || typeof inst !== "object") return false;
162
- const ctor = getConstructor(inst);
163
- return isSigilCtor(ctor);
113
+ return !!inst && typeof inst === "object" && __SIGIL__ in inst;
164
114
  }
165
- function isSigilBaseCtor(ctor) {
166
- return Object.hasOwn(ctor, __SIGIL_BASE__);
115
+ function hasOwnSigil(ctor) {
116
+ return typeof ctor === "function" && Object.hasOwn(ctor.prototype, __SIGIL__);
167
117
  }
168
- function isSigilBaseInstance(inst) {
169
- if (!inst || typeof inst !== "object") return false;
170
- const ctor = getConstructor(inst);
171
- return isSigilBaseCtor(ctor);
118
+ function labelOf(ctor) {
119
+ return ctor.prototype[__LABEL__];
172
120
  }
173
- function isDecorated(ctor) {
174
- return Object.hasOwn(ctor, __DECORATED__);
121
+ function lineageOf(ctor) {
122
+ return ctor.prototype[__LINEAGE__];
175
123
  }
176
- function isInheritanceChecked(ctor) {
177
- return Object.hasOwn(ctor, __INHERITANCE_CHECKED__);
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
+ }
178
148
  }
179
- function getConstructor(obj) {
180
- var _a, _b, _c;
181
- if (!obj || typeof obj !== "object") return null;
182
- return (_c = (_b = obj.constructor) != null ? _b : (_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.constructor) != null ? _c : null;
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}`;
183
156
  }
184
157
 
185
- // src/core/mixin.ts
158
+ // src/mixin.ts
186
159
  function Sigilify(Base, label, opts) {
187
- if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already sigilified.`);
188
- let l;
189
- if (label) {
190
- verifyLabel(label, opts);
191
- l = label;
192
- } else l = generateRandomLabel();
160
+ if (hasOwnSigil(Base))
161
+ throw new Error(
162
+ `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
163
+ );
193
164
  class Sigilified extends Base {
194
165
  /**
195
166
  * Class-level identity label constant for this sigil constructor.
196
167
  */
197
168
  static get SigilLabel() {
198
- if (!isInheritanceChecked(this)) checkInheritance(this);
199
- return this[__LABEL__];
169
+ var _a;
170
+ handleSigil(this);
171
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
200
172
  }
201
173
  /**
202
174
  * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
203
175
  */
204
176
  static get SigilEffectiveLabel() {
205
- return this[__EFFECTIVE_LABEL__];
177
+ var _a;
178
+ handleSigil(this);
179
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
206
180
  }
207
181
  /**
208
- * Copy of the linearized sigil type label chain for the current constructor.
182
+ * Linearized sigil type label chain for the current constructor.
209
183
  *
210
184
  * Useful for debugging and performing strict lineage comparisons.
211
185
  *
212
186
  * @returns An array of labels representing parent → child type labels.
213
187
  */
214
188
  static get SigilLabelLineage() {
215
- var _a;
216
- if (!isInheritanceChecked(this)) checkInheritance(this);
217
- return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
189
+ var _a, _b;
190
+ handleSigil(this);
191
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
218
192
  }
219
193
  /**
220
- * Copy of the sigil type label set for the current constructor.
221
- *
222
- * Useful for quick membership checks (O(1) lookups) and debugging.
194
+ * Sigil type label set for the current constructor.
195
+ * Useful for debugging.
223
196
  *
224
197
  * @returns A Readonly Set of labels that represent the type lineage.
225
198
  */
226
199
  static get SigilLabelSet() {
227
- if (!isInheritanceChecked(this)) checkInheritance(this);
228
- const set = /* @__PURE__ */ new Set();
229
- for (const s of this[__LABEL_SET__]) set.add(s);
230
- return set;
200
+ var _a;
201
+ handleSigil(this);
202
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
231
203
  }
232
204
  constructor(...args) {
233
205
  super(...args);
234
- if (Object.getPrototypeOf(this) !== new.target.prototype)
235
- Object.setPrototypeOf(this, new.target.prototype);
236
- const ctor = getConstructor(this);
237
- if (!ctor) {
238
- if (process.env.NODE_ENV !== "production")
239
- throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
240
- return;
241
- }
242
- checkInheritance(ctor);
206
+ const ctor = new.target;
207
+ handleSigil(ctor);
243
208
  }
244
209
  /**
245
210
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -251,99 +216,86 @@ function Sigilify(Base, label, opts) {
251
216
  return isSigilInstance(obj);
252
217
  }
253
218
  /**
254
- * Check whether `other` is (or inherits from) the type represented by the calling constructor.
219
+ * Check whether `other` is (or inherits from) the instance represented by the
220
+ * calling constructor.
255
221
  *
256
222
  * This replaces `instanceof` so that checks remain valid across bundles/realms
257
223
  * and when subclassing.
258
224
  *
259
- * @typeParam T - The calling constructor type (narrowing the returned instance type).
260
- * @param this - The constructor performing the check.
225
+ * @typeParam T - The specific sigil constructor (`this`).
226
+ * @param this - The constructor performing the type check.
261
227
  * @param other - The object to test.
262
- * @returns `true` if `other` is an instance of this type or a subtype.
228
+ * @returns A type guard asserting `other` is an instance of the constructor.
263
229
  */
264
230
  static isOfType(other) {
265
231
  var _a;
266
- if (!isSigilInstance(other)) return false;
267
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
268
- const thisType = this[__LABEL__];
269
- return !!otherSet && otherSet.has(thisType);
232
+ handleSigil(this);
233
+ if (other == null || typeof other !== "object") return false;
234
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
270
235
  }
271
236
  /**
272
- * Strict lineage check: compares the type label lineage arrays element-by-element.
237
+ * Check whether `other` is exactly the same instance represented by the
238
+ * calling constructor.
273
239
  *
274
- * @typeParam T - The calling constructor type.
275
- * @param this - The constructor performing the check.
240
+ * @typeParam T - The specific sigil constructor (`this`).
241
+ * @param this - The constructor performing the type check.
276
242
  * @param other - The object to test.
277
- * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
243
+ * @returns A type guard asserting `other` is an instance of the constructor.
278
244
  */
279
- static isOfTypeStrict(other) {
280
- var _a;
281
- if (!isSigilInstance(other)) return false;
282
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
283
- const thisLineage = this[__LABEL_LINEAGE__];
284
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
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;
285
252
  }
286
253
  /**
287
- * Check whether `other` is (or inherits from) the type instance.
254
+ * Check whether `other` is (or inherits from) the instance represented by the
255
+ * calling constructor.
288
256
  *
289
- * Allows 'instanceof' like checks but in instances.
257
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
258
+ * and when subclassing.
290
259
  *
291
- * @typeParam T - The instance type.
292
- * @param this - The instance performing the check.
260
+ * @typeParam T - The specific sigil constructor (`this`).
261
+ * @param this - The constructor performing the type check.
293
262
  * @param other - The object to test.
294
- * @returns `true` if `other` is the same instance of this type or a subtype.
263
+ * @returns A type guard asserting `other` is an instance of the constructor.
295
264
  */
296
265
  isOfType(other) {
297
- var _a;
298
- if (!isSigilInstance(other)) return false;
299
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
300
- const thisType = getConstructor(this)[__LABEL__];
301
- return !!otherSet && otherSet.has(thisType);
266
+ if (other == null || typeof other !== "object") return false;
267
+ return other[this[__SIGIL__]] === true;
302
268
  }
303
269
  /**
304
- * Strict lineage check: compares the type label lineage arrays element-by-element.
270
+ * Check whether `other` is exactly the same instance represented by the
271
+ * calling constructor.
305
272
  *
306
- * Allows 'instanceof' like checks but in instances.
307
- *
308
- * @typeParam T - The instance type.
309
- * @param this - The instance performing the check.
273
+ * @typeParam T - The specific sigil constructor (`this`).
274
+ * @param this - The constructor performing the type check.
310
275
  * @param other - The object to test.
311
- * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
276
+ * @returns A type guard asserting `other` is an instance of the constructor.
312
277
  */
313
- isOfTypeStrict(other) {
314
- var _a, _b;
315
- if (!isSigilInstance(other)) return false;
316
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
317
- const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
318
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
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;
319
283
  }
320
284
  /**
321
285
  * Returns the identity sigil label of this instance's constructor.
322
286
  *
323
- * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
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').
324
288
  */
325
289
  getSigilLabel() {
326
- const ctor = getConstructor(this);
327
- if (!ctor) {
328
- if (process.env.NODE_ENV !== "production")
329
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
330
- return "@Sigil.unknown";
331
- }
332
- return ctor.SigilLabel;
290
+ return this[__LABEL__];
333
291
  }
334
292
  /**
335
293
  * Returns the human-readable sigil label of this instance's constructor.
336
294
  *
337
- * @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
295
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
338
296
  */
339
297
  getSigilEffectiveLabel() {
340
- const ctor = getConstructor(this);
341
- if (!ctor) {
342
- if (process.env.NODE_ENV !== "production")
343
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
344
- return "@Sigil.unknown";
345
- }
346
- return ctor.SigilEffectiveLabel;
298
+ return this[__EFFECTIVE_LABEL__];
347
299
  }
348
300
  /**
349
301
  * Returns a copy of the sigil type label lineage for this instance's constructor.
@@ -351,91 +303,69 @@ function Sigilify(Base, label, opts) {
351
303
  * @returns readonly array of labels representing the type lineage.
352
304
  */
353
305
  getSigilLabelLineage() {
354
- const ctor = getConstructor(this);
355
- if (!ctor) {
356
- if (process.env.NODE_ENV !== "production")
357
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
358
- return ["@Sigil.unknown"];
359
- }
360
- return ctor.SigilLabelLineage;
306
+ return [...this[__LINEAGE__]];
361
307
  }
362
308
  /**
363
- * Returns a readonly copy of the sigil type label set for this instance's constructor.
309
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
364
310
  *
365
- * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
311
+ * @returns readonly array of labels representing the type lineage.
366
312
  */
367
313
  getSigilLabelSet() {
368
- const ctor = getConstructor(this);
369
- if (!ctor) {
370
- if (process.env.NODE_ENV !== "production")
371
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
372
- return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
373
- }
374
- return ctor.SigilLabelSet;
314
+ return this[__LINEAGE__];
375
315
  }
376
316
  }
377
- decorateCtor(Sigilified, l, { isMixin: true });
378
- markSigil(Sigilified);
379
- markSigilBase(Sigilified);
317
+ handleSigil(Sigilified, label, opts);
380
318
  return Sigilified;
381
319
  }
382
320
  function SigilifyAbstract(Base, label, opts) {
383
- if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already sigilified.`);
384
- let l;
385
- if (label) {
386
- verifyLabel(label, opts);
387
- l = label;
388
- } else l = generateRandomLabel();
321
+ if (hasOwnSigil(Base))
322
+ throw new Error(
323
+ `[Sigil Error] Base class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
324
+ );
389
325
  class Sigilified extends Base {
390
326
  /**
391
327
  * Class-level identity label constant for this sigil constructor.
392
328
  */
393
329
  static get SigilLabel() {
394
- if (!isInheritanceChecked(this)) checkInheritance(this);
395
- return this[__LABEL__];
330
+ var _a;
331
+ handleSigil(this);
332
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
396
333
  }
397
334
  /**
398
335
  * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
399
336
  */
400
337
  static get SigilEffectiveLabel() {
401
- return this[__EFFECTIVE_LABEL__];
338
+ var _a;
339
+ handleSigil(this);
340
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
402
341
  }
403
342
  /**
404
- * Copy of the linearized sigil type label chain for the current constructor.
343
+ * Linearized sigil type label chain for the current constructor.
405
344
  *
406
345
  * Useful for debugging and performing strict lineage comparisons.
407
346
  *
408
347
  * @returns An array of labels representing parent → child type labels.
409
348
  */
410
349
  static get SigilLabelLineage() {
411
- var _a;
412
- if (!isInheritanceChecked(this)) checkInheritance(this);
413
- return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
350
+ var _a, _b;
351
+ handleSigil(this);
352
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
414
353
  }
415
354
  /**
416
- * Copy of the sigil type label set for the current constructor.
417
- *
418
- * Useful for quick membership checks (O(1) lookups) and debugging.
355
+ * Sigil type label set for the current constructor.
356
+ * Useful for debugging.
419
357
  *
420
358
  * @returns A Readonly Set of labels that represent the type lineage.
421
359
  */
422
360
  static get SigilLabelSet() {
423
- if (!isInheritanceChecked(this)) checkInheritance(this);
424
- const set = /* @__PURE__ */ new Set();
425
- for (const s of this[__LABEL_SET__]) set.add(s);
426
- return set;
361
+ var _a;
362
+ handleSigil(this);
363
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
427
364
  }
428
365
  constructor(...args) {
429
366
  super(...args);
430
- if (Object.getPrototypeOf(this) !== new.target.prototype)
431
- Object.setPrototypeOf(this, new.target.prototype);
432
- const ctor = getConstructor(this);
433
- if (!ctor) {
434
- if (process.env.NODE_ENV !== "production")
435
- throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
436
- return;
437
- }
438
- checkInheritance(ctor);
367
+ const ctor = new.target;
368
+ handleSigil(ctor);
439
369
  }
440
370
  /**
441
371
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -447,107 +377,84 @@ function SigilifyAbstract(Base, label, opts) {
447
377
  return isSigilInstance(obj);
448
378
  }
449
379
  /**
450
- * Check whether `other` is (or inherits from) the type represented by the calling constructor.
451
- *
452
- * Implementation detail:
453
- * - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
454
- * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
380
+ * Check whether `other` is (or inherits from) the instance represented by the
381
+ * calling constructor.
455
382
  *
456
383
  * This replaces `instanceof` so that checks remain valid across bundles/realms
457
384
  * and when subclassing.
458
385
  *
459
- * @typeParam T - The calling constructor type (narrowing the returned instance type).
460
- * @param this - The constructor performing the check.
386
+ * @typeParam T - The specific sigil constructor (`this`).
387
+ * @param this - The constructor performing the type check.
461
388
  * @param other - The object to test.
462
- * @returns `true` if `other` is an instance of this type or a subtype.
389
+ * @returns A type guard asserting `other` is an instance of the constructor.
463
390
  */
464
391
  static isOfType(other) {
465
392
  var _a;
466
- if (!isSigilInstance(other)) return false;
467
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
468
- const thisType = this[__LABEL__];
469
- return !!otherSet && otherSet.has(thisType);
393
+ if (other == null || typeof other !== "object") return false;
394
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
470
395
  }
471
396
  /**
472
- * Strict lineage check: compares the type label lineage arrays element-by-element.
397
+ * Check whether `other` is exactly the same instance represented by the
398
+ * calling constructor.
473
399
  *
474
- * Implementation detail:
475
- * - Works in O(n) time where n is the depth of the lineage.
476
- * - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
477
- *
478
- * @typeParam T - The calling constructor type.
479
- * @param this - The constructor performing the check.
400
+ * @typeParam T - The specific sigil constructor (`this`).
401
+ * @param this - The constructor performing the type check.
480
402
  * @param other - The object to test.
481
- * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
403
+ * @returns A type guard asserting `other` is an instance of the constructor.
482
404
  */
483
- static isOfTypeStrict(other) {
484
- var _a;
485
- if (!isSigilInstance(other)) return false;
486
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
487
- const thisLineage = this[__LABEL_LINEAGE__];
488
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
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;
489
411
  }
490
412
  /**
491
- * Check whether `other` is (or inherits from) the type instance.
413
+ * Check whether `other` is (or inherits from) the instance represented by the
414
+ * calling constructor.
492
415
  *
493
- * Allows 'instanceof' like checks but in instances.
416
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
417
+ * and when subclassing.
494
418
  *
495
- * @typeParam T - The instance type.
496
- * @param this - The instance performing the check.
419
+ * @typeParam T - The specific sigil constructor (`this`).
420
+ * @param this - The constructor performing the type check.
497
421
  * @param other - The object to test.
498
- * @returns `true` if `other` is the same instance of this type or a subtype.
422
+ * @returns A type guard asserting `other` is an instance of the constructor.
499
423
  */
500
424
  isOfType(other) {
501
- var _a;
502
- if (!isSigilInstance(other)) return false;
503
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
504
- const thisType = getConstructor(this)[__LABEL__];
505
- return !!otherSet && otherSet.has(thisType);
425
+ if (other == null || typeof other !== "object") return false;
426
+ return other[this[__SIGIL__]] === true;
506
427
  }
507
428
  /**
508
- * Strict lineage check: compares the type label lineage arrays element-by-element.
429
+ * Check whether `other` is exactly the same instance represented by the
430
+ * calling constructor.
509
431
  *
510
- * Allows 'instanceof' like checks but in instances.
511
- *
512
- * @typeParam T - The instance type.
513
- * @param this - The instance performing the check.
432
+ * @typeParam T - The specific sigil constructor (`this`).
433
+ * @param this - The constructor performing the type check.
514
434
  * @param other - The object to test.
515
- * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
435
+ * @returns A type guard asserting `other` is an instance of the constructor.
516
436
  */
517
- isOfTypeStrict(other) {
518
- var _a, _b;
519
- if (!isSigilInstance(other)) return false;
520
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
521
- const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
522
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
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;
523
442
  }
524
443
  /**
525
444
  * Returns the identity sigil label of this instance's constructor.
526
445
  *
527
- * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
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').
528
447
  */
529
448
  getSigilLabel() {
530
- const ctor = getConstructor(this);
531
- if (!ctor) {
532
- if (process.env.NODE_ENV !== "production")
533
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
534
- return "@Sigil.unknown";
535
- }
536
- return ctor.SigilLabel;
449
+ return this[__LABEL__];
537
450
  }
538
451
  /**
539
452
  * Returns the human-readable sigil label of this instance's constructor.
540
453
  *
541
- * @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
454
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
542
455
  */
543
456
  getSigilEffectiveLabel() {
544
- const ctor = getConstructor(this);
545
- if (!ctor) {
546
- if (process.env.NODE_ENV !== "production")
547
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
548
- return "@Sigil.unknown";
549
- }
550
- return ctor.SigilEffectiveLabel;
457
+ return this[__EFFECTIVE_LABEL__];
551
458
  }
552
459
  /**
553
460
  * Returns a copy of the sigil type label lineage for this instance's constructor.
@@ -555,89 +462,54 @@ function SigilifyAbstract(Base, label, opts) {
555
462
  * @returns readonly array of labels representing the type lineage.
556
463
  */
557
464
  getSigilLabelLineage() {
558
- const ctor = getConstructor(this);
559
- if (!ctor) {
560
- if (process.env.NODE_ENV !== "production")
561
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
562
- return ["@Sigil.unknown"];
563
- }
564
- return ctor.SigilLabelLineage;
465
+ return [...this[__LINEAGE__]];
565
466
  }
566
467
  /**
567
- * Returns a readonly copy of the sigil type label set for this instance's constructor.
468
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
568
469
  *
569
- * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
470
+ * @returns readonly array of labels representing the type lineage.
570
471
  */
571
472
  getSigilLabelSet() {
572
- const ctor = getConstructor(this);
573
- if (!ctor) {
574
- if (process.env.NODE_ENV !== "production")
575
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
576
- return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
577
- }
578
- return ctor.SigilLabelSet;
473
+ return this[__LINEAGE__];
579
474
  }
580
475
  }
581
- decorateCtor(Sigilified, l, { isMixin: true });
582
- markSigil(Sigilified);
583
- markSigilBase(Sigilified);
476
+ handleSigil(Sigilified, label, opts);
584
477
  return Sigilified;
585
478
  }
586
479
 
587
- // src/core/classes.ts
480
+ // src/classes.ts
588
481
  var Sigil = Sigilify(class {
589
482
  }, "Sigil");
590
483
  var SigilError = Sigilify(Error, "SigilError");
591
484
 
592
- // src/core/decorator.ts
485
+ // src/decorator.ts
593
486
  function WithSigil(label, opts) {
594
- let l;
595
- if (label) {
596
- verifyLabel(label, opts);
597
- l = label;
598
- } else l = generateRandomLabel();
599
487
  return function(value, context) {
600
488
  if (context.kind !== "class") return;
601
489
  if (!isSigilCtor(value))
602
490
  throw new Error(
603
491
  `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
604
492
  );
605
- decorateCtor(value, l);
606
- checkInheritance(value, opts);
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);
607
498
  };
608
499
  }
609
500
 
610
- // src/core/hof.ts
501
+ // src/hof.ts
611
502
  function withSigil(Class, label, opts) {
612
503
  var _a;
613
504
  if (!isSigilCtor(Class))
614
505
  throw new Error(
615
506
  `[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
616
507
  );
617
- let l;
618
- if (label) {
619
- verifyLabel(label, opts);
620
- l = label;
621
- } else l = generateRandomLabel();
622
- const ctor = Class;
623
- decorateCtor(ctor, l);
624
- checkInheritance(ctor, opts);
625
- return Class;
626
- }
627
- function withSigilTyped(Class, label, opts) {
628
- var _a;
629
- if (!isSigilCtor(Class))
508
+ if (hasOwnSigil(Class))
630
509
  throw new Error(
631
- `[Sigil Error] 'withSigilTyped' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
510
+ `[Sigil Error] Class '${Class.name}' with label '${Class.SigilLabel}' is already sigilified`
632
511
  );
633
- let l;
634
- if (label) {
635
- verifyLabel(label, opts);
636
- l = label;
637
- } else l = generateRandomLabel();
638
- const ctor = Class;
639
- decorateCtor(ctor, l);
640
- checkInheritance(ctor, opts);
512
+ handleSigil(Class, label, opts);
641
513
  return Class;
642
514
  }
643
515
 
@@ -647,14 +519,9 @@ exports.SigilError = SigilError;
647
519
  exports.Sigilify = Sigilify;
648
520
  exports.SigilifyAbstract = SigilifyAbstract;
649
521
  exports.WithSigil = WithSigil;
650
- exports.isDecorated = isDecorated;
651
- exports.isInheritanceChecked = isInheritanceChecked;
652
- exports.isSigilBaseCtor = isSigilBaseCtor;
653
- exports.isSigilBaseInstance = isSigilBaseInstance;
654
522
  exports.isSigilCtor = isSigilCtor;
655
523
  exports.isSigilInstance = isSigilInstance;
656
524
  exports.updateSigilOptions = updateSigilOptions;
657
525
  exports.withSigil = withSigil;
658
- exports.withSigilTyped = withSigilTyped;
659
526
  //# sourceMappingURL=index.js.map
660
527
  //# sourceMappingURL=index.js.map