@vicin/sigil 3.3.0 → 4.0.0

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