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