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