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