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