@vicin/sigil 3.4.0 → 4.0.1
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 +7 -249
- package/CONTRIBUTING.md +24 -0
- package/LICENSE +3 -1
- package/README.md +140 -189
- package/dist/index.cjs +298 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +67 -242
- package/dist/index.d.ts +67 -242
- package/dist/index.global.js +116 -207
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +115 -218
- package/dist/index.js.map +1 -1
- package/package.json +43 -59
- package/dist/index.mjs +0 -374
- package/dist/index.mjs.map +0 -1
package/dist/index.global.js
CHANGED
|
@@ -1,172 +1,128 @@
|
|
|
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
|
+
var __SIGIL_REGISTRY__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_REGISTRY__");
|
|
10
|
+
|
|
11
|
+
// src/is.ts
|
|
12
|
+
function isSigilCtor(ctor) {
|
|
13
|
+
return typeof ctor === "function" && ctor.prototype && __SIGIL__ in ctor.prototype;
|
|
14
|
+
}
|
|
15
|
+
function isSigilInstance(inst) {
|
|
16
|
+
return !!inst && typeof inst === "object" && __SIGIL__ in inst;
|
|
17
|
+
}
|
|
18
|
+
|
|
4
19
|
// src/options.ts
|
|
5
20
|
var OPTIONS = {
|
|
6
|
-
labelValidation: null
|
|
7
|
-
autofillLabels: true,
|
|
8
|
-
skipLabelUniquenessCheck: false
|
|
21
|
+
labelValidation: null
|
|
9
22
|
};
|
|
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
|
-
}
|
|
23
|
+
var updateSigilOptions = ({ labelValidation = null } = {}) => {
|
|
24
|
+
OPTIONS.labelValidation = labelValidation;
|
|
27
25
|
};
|
|
28
26
|
var RECOMMENDED_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
29
|
-
var DEFAULT_LABEL_REGEX = RECOMMENDED_LABEL_REGEX;
|
|
30
27
|
|
|
31
|
-
// src/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
// src/registry.ts
|
|
29
|
+
function getSigilRegistry() {
|
|
30
|
+
if (globalThis[__SIGIL_REGISTRY__]) return globalThis[__SIGIL_REGISTRY__];
|
|
31
|
+
const resolved = /* @__PURE__ */ new WeakSet();
|
|
32
|
+
const hasOwnSigil2 = /* @__PURE__ */ new WeakSet();
|
|
33
|
+
const registry = {
|
|
34
|
+
registerResolved(ctor) {
|
|
35
|
+
resolved.add(ctor);
|
|
36
|
+
},
|
|
37
|
+
checkResolved(ctor) {
|
|
38
|
+
return resolved.has(ctor);
|
|
39
|
+
},
|
|
40
|
+
registerHasOwn(ctor) {
|
|
41
|
+
hasOwnSigil2.add(ctor);
|
|
42
|
+
},
|
|
43
|
+
checkHasOwn(ctor) {
|
|
44
|
+
return hasOwnSigil2.has(ctor);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
Object.freeze(registry);
|
|
48
|
+
Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {
|
|
49
|
+
value: registry,
|
|
50
|
+
writable: false,
|
|
51
|
+
configurable: false,
|
|
52
|
+
enumerable: false
|
|
53
|
+
});
|
|
54
|
+
return registry;
|
|
55
|
+
}
|
|
36
56
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function handleSigilExplicit(ctor, label, opts) {
|
|
42
|
-
if (handledCtorsExplicit.has(ctor))
|
|
57
|
+
// src/sigilify.ts
|
|
58
|
+
var sigilRegistry = getSigilRegistry();
|
|
59
|
+
function sigilify(ctor, label, opts) {
|
|
60
|
+
if (sigilRegistry.checkResolved(ctor))
|
|
43
61
|
throw new Error(
|
|
44
62
|
`[Sigil Error] Class '${ctor.name}' with label '${ctor.SigilLabel}' is already sigilified`
|
|
45
63
|
);
|
|
46
|
-
verifyLabel(
|
|
47
|
-
handleAncestors(ctor, opts);
|
|
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
|
-
);
|
|
64
|
+
verifyLabel(label, opts);
|
|
56
65
|
handleAncestors(ctor);
|
|
57
|
-
|
|
66
|
+
updateSigil(ctor, label);
|
|
67
|
+
sigilRegistry.registerResolved(ctor);
|
|
68
|
+
sigilRegistry.registerHasOwn(ctor);
|
|
69
|
+
}
|
|
70
|
+
function hasOwnSigil(ctor) {
|
|
71
|
+
return sigilRegistry.checkHasOwn(ctor);
|
|
58
72
|
}
|
|
59
|
-
function
|
|
73
|
+
function verifyLabel(label, opts) {
|
|
60
74
|
var _a;
|
|
61
|
-
const
|
|
75
|
+
const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
|
|
76
|
+
if (labelValidation) {
|
|
77
|
+
let valid;
|
|
78
|
+
if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
|
|
79
|
+
else valid = labelValidation(label);
|
|
80
|
+
if (!valid)
|
|
81
|
+
throw new Error(
|
|
82
|
+
`[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function handleAncestors(ctor) {
|
|
62
87
|
let a = Object.getPrototypeOf(ctor);
|
|
63
88
|
while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
|
|
64
|
-
|
|
89
|
+
sigilRegistry.registerResolved(a);
|
|
65
90
|
a = Object.getPrototypeOf(a);
|
|
66
91
|
}
|
|
67
|
-
const labelOwner = /* @__PURE__ */ new Map();
|
|
68
|
-
const autofillLabels = (_a = opts == null ? void 0 : opts.autofillLabels) != null ? _a : OPTIONS.autofillLabels;
|
|
69
|
-
for (const a2 of ancestors) {
|
|
70
|
-
const l = a2.prototype[__LABEL__];
|
|
71
|
-
if (labelOwner.has(l)) {
|
|
72
|
-
if (!autofillLabels)
|
|
73
|
-
throw new Error(
|
|
74
|
-
`[Sigil Error] Class '${a2.name}' is not sigilified, Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`
|
|
75
|
-
);
|
|
76
|
-
sigilify(a2, generateRandomLabel(a2), false);
|
|
77
|
-
}
|
|
78
|
-
labelOwner.set(a2.prototype[__LABEL__], a2.name);
|
|
79
|
-
}
|
|
80
92
|
}
|
|
81
|
-
function
|
|
82
|
-
var _a;
|
|
93
|
+
function updateSigil(ctor, label) {
|
|
94
|
+
var _a, _b;
|
|
83
95
|
const sym = Symbol.for(label);
|
|
84
96
|
Object.defineProperty(ctor.prototype, __SIGIL__, {
|
|
85
97
|
value: sym,
|
|
86
|
-
configurable:
|
|
98
|
+
configurable: false,
|
|
87
99
|
enumerable: false,
|
|
88
100
|
writable: false
|
|
89
101
|
});
|
|
90
102
|
Object.defineProperty(ctor.prototype, __LABEL__, {
|
|
91
103
|
value: label,
|
|
92
|
-
configurable:
|
|
104
|
+
configurable: false,
|
|
93
105
|
enumerable: false,
|
|
94
106
|
writable: false
|
|
95
107
|
});
|
|
96
|
-
|
|
97
|
-
Object.
|
|
98
|
-
value: label,
|
|
99
|
-
configurable: false,
|
|
100
|
-
enumerable: false,
|
|
101
|
-
writable: false
|
|
102
|
-
});
|
|
103
|
-
if (!handledCtors.has(ctor))
|
|
104
|
-
Object.defineProperty(ctor.prototype, __DEPTH__, {
|
|
105
|
-
value: ((_a = ctor.prototype[__DEPTH__]) != null ? _a : -1) + 1,
|
|
106
|
-
configurable: false,
|
|
107
|
-
enumerable: false,
|
|
108
|
-
writable: false
|
|
109
|
-
});
|
|
110
|
-
Object.defineProperty(ctor.prototype, sym, {
|
|
111
|
-
value: true,
|
|
108
|
+
Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {
|
|
109
|
+
value: [...(_a = Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__]) != null ? _a : [], sym],
|
|
112
110
|
configurable: false,
|
|
113
111
|
enumerable: false,
|
|
114
112
|
writable: false
|
|
115
113
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
function isSigilCtor(ctor) {
|
|
120
|
-
return typeof ctor === "function" && ctor.prototype && __SIGIL__ in ctor.prototype;
|
|
121
|
-
}
|
|
122
|
-
function isSigilInstance(inst) {
|
|
123
|
-
return !!inst && typeof inst === "object" && __SIGIL__ in inst;
|
|
124
|
-
}
|
|
125
|
-
function getSigilLabels() {
|
|
126
|
-
return getLabelRegistry().labels();
|
|
127
|
-
}
|
|
128
|
-
function getLabelRegistry() {
|
|
129
|
-
if ("__labelRegistry__" in globalThis) return globalThis.__labelRegistry__;
|
|
130
|
-
const labelSet = /* @__PURE__ */ new Set();
|
|
131
|
-
let count = 0;
|
|
132
|
-
const labelRegistry = {
|
|
133
|
-
has: (label) => labelSet.has(label),
|
|
134
|
-
add: (label) => labelSet.add(label),
|
|
135
|
-
labels: () => [...labelSet],
|
|
136
|
-
enc: () => ++count
|
|
137
|
-
};
|
|
138
|
-
Object.freeze(labelRegistry);
|
|
139
|
-
Object.defineProperty(globalThis, "__labelRegistry__", {
|
|
140
|
-
value: labelRegistry,
|
|
141
|
-
writable: false,
|
|
114
|
+
Object.defineProperty(ctor.prototype, __DEPTH__, {
|
|
115
|
+
value: ((_b = ctor.prototype[__DEPTH__]) != null ? _b : -1) + 1,
|
|
142
116
|
configurable: false,
|
|
143
|
-
enumerable: false
|
|
117
|
+
enumerable: false,
|
|
118
|
+
writable: false
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(ctor.prototype, sym, {
|
|
121
|
+
value: true,
|
|
122
|
+
configurable: false,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
writable: false
|
|
144
125
|
});
|
|
145
|
-
return labelRegistry;
|
|
146
|
-
}
|
|
147
|
-
function verifyLabel(ctor, label, opts) {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
const reg = getLabelRegistry();
|
|
150
|
-
if (label.startsWith(AUTO_LABEL_PREFEX))
|
|
151
|
-
throw new Error(`'${AUTO_LABEL_PREFEX}' is a prefex reserved by the library`);
|
|
152
|
-
if (!((_a = opts == null ? void 0 : opts.skipLabelUniquenessCheck) != null ? _a : OPTIONS.skipLabelUniquenessCheck) && reg.has(label))
|
|
153
|
-
throw new Error(
|
|
154
|
-
`[Sigil Error] Passed label '${label}' to class '${ctor == null ? void 0 : ctor.name}' is re-used, passed labels must be unique`
|
|
155
|
-
);
|
|
156
|
-
const labelValidation = (_b = opts == null ? void 0 : opts.labelValidation) != null ? _b : OPTIONS.labelValidation;
|
|
157
|
-
if (labelValidation) {
|
|
158
|
-
let valid;
|
|
159
|
-
if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
|
|
160
|
-
else valid = labelValidation(label);
|
|
161
|
-
if (!valid)
|
|
162
|
-
throw new Error(
|
|
163
|
-
`[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
reg.add(label);
|
|
167
|
-
}
|
|
168
|
-
function generateRandomLabel(ctor) {
|
|
169
|
-
return `${AUTO_LABEL_PREFEX}:${ctor == null ? void 0 : ctor.name}:${getLabelRegistry().enc()}:${Math.random().toString(36).slice(2, 10)}`;
|
|
170
126
|
}
|
|
171
127
|
|
|
172
128
|
// src/mixin.ts
|
|
@@ -176,47 +132,24 @@
|
|
|
176
132
|
* Class-level identity label constant for this sigil constructor.
|
|
177
133
|
*/
|
|
178
134
|
static get SigilLabel() {
|
|
179
|
-
handleSigilLazy(this);
|
|
180
135
|
return this.prototype[__LABEL__];
|
|
181
136
|
}
|
|
182
137
|
/**
|
|
183
|
-
*
|
|
184
|
-
*/
|
|
185
|
-
static get SigilEffectiveLabel() {
|
|
186
|
-
handleSigilLazy(this);
|
|
187
|
-
return this.prototype[__EFFECTIVE_LABEL__];
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Linearized sigil type label chain for the current constructor.
|
|
138
|
+
* Copy of the sigil label lineage for this instance's constructor.
|
|
191
139
|
*
|
|
192
|
-
* Useful for debugging and
|
|
140
|
+
* Useful for debugging and logging.
|
|
193
141
|
*
|
|
194
|
-
* @returns An array of labels representing parent → child
|
|
142
|
+
* @returns An array of sigil labels representing parent → child labels.
|
|
195
143
|
*/
|
|
196
144
|
static get SigilLabelLineage() {
|
|
197
|
-
|
|
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;
|
|
145
|
+
return this.prototype[__SIGIL_LINEAGE__].map((v) => v.description);
|
|
205
146
|
}
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
*
|
|
210
|
-
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
211
|
-
* @returns A Readonly Set of labels that represent the type lineage.
|
|
212
|
-
*/
|
|
213
|
-
static get SigilLabelSet() {
|
|
214
|
-
return new Set(this.SigilLabelLineage);
|
|
147
|
+
/** Check if sigil label has been attached to this class */
|
|
148
|
+
static get hasOwnSigil() {
|
|
149
|
+
return hasOwnSigil(this);
|
|
215
150
|
}
|
|
216
151
|
constructor(...args) {
|
|
217
152
|
super(...args);
|
|
218
|
-
const ctor = new.target;
|
|
219
|
-
handleSigilLazy(ctor);
|
|
220
153
|
}
|
|
221
154
|
/**
|
|
222
155
|
* Check whether `other` is (or inherits from) the instance represented by the
|
|
@@ -230,8 +163,7 @@
|
|
|
230
163
|
* @param other - The object to test.
|
|
231
164
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
232
165
|
*/
|
|
233
|
-
static
|
|
234
|
-
handleSigilLazy(this);
|
|
166
|
+
static isInstance(other) {
|
|
235
167
|
if (other == null || typeof other !== "object") return false;
|
|
236
168
|
return other[this.prototype[__SIGIL__]] === true;
|
|
237
169
|
}
|
|
@@ -244,8 +176,7 @@
|
|
|
244
176
|
* @param other - The object to test.
|
|
245
177
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
246
178
|
*/
|
|
247
|
-
static
|
|
248
|
-
handleSigilLazy(this);
|
|
179
|
+
static isExactInstance(other) {
|
|
249
180
|
if (other == null || typeof other !== "object") return false;
|
|
250
181
|
if (this.prototype[__DEPTH__] !== other[__DEPTH__]) return false;
|
|
251
182
|
return other[this.prototype[__SIGIL__]] === true;
|
|
@@ -262,7 +193,7 @@
|
|
|
262
193
|
* @param other - The object to test.
|
|
263
194
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
264
195
|
*/
|
|
265
|
-
|
|
196
|
+
isInstance(other) {
|
|
266
197
|
if (other == null || typeof other !== "object") return false;
|
|
267
198
|
return other[this[__SIGIL__]] === true;
|
|
268
199
|
}
|
|
@@ -275,7 +206,7 @@
|
|
|
275
206
|
* @param other - The object to test.
|
|
276
207
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
277
208
|
*/
|
|
278
|
-
|
|
209
|
+
isExactInstance(other) {
|
|
279
210
|
if (other == null || typeof other !== "object") return false;
|
|
280
211
|
if (this[__DEPTH__] !== other[__DEPTH__]) return false;
|
|
281
212
|
return other[this[__SIGIL__]] === true;
|
|
@@ -285,42 +216,25 @@
|
|
|
285
216
|
*
|
|
286
217
|
* @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').
|
|
287
218
|
*/
|
|
288
|
-
|
|
219
|
+
get SigilLabel() {
|
|
289
220
|
return this[__LABEL__];
|
|
290
221
|
}
|
|
291
222
|
/**
|
|
292
|
-
*
|
|
223
|
+
* Copy of the sigil label lineage for this instance's constructor.
|
|
293
224
|
*
|
|
294
|
-
*
|
|
295
|
-
*/
|
|
296
|
-
getSigilEffectiveLabel() {
|
|
297
|
-
return this[__EFFECTIVE_LABEL__];
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
225
|
+
* Useful for debugging and logging.
|
|
301
226
|
*
|
|
302
|
-
* @returns
|
|
227
|
+
* @returns An array of sigil labels representing parent → child labels.
|
|
303
228
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
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;
|
|
229
|
+
get SigilLabelLineage() {
|
|
230
|
+
return this[__SIGIL_LINEAGE__].map((v) => v.description);
|
|
312
231
|
}
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
* @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4
|
|
317
|
-
* @returns readonly array of labels representing the type lineage.
|
|
318
|
-
*/
|
|
319
|
-
getSigilLabelSet() {
|
|
320
|
-
return new Set(this.getSigilLabelLineage());
|
|
232
|
+
/** Check if sigil label has been attached to this class */
|
|
233
|
+
get hasOwnSigil() {
|
|
234
|
+
return this.constructor.hasOwnSigil;
|
|
321
235
|
}
|
|
322
236
|
}
|
|
323
|
-
|
|
237
|
+
sigilify(Sigil2, "Sigil");
|
|
324
238
|
return Sigil2;
|
|
325
239
|
}
|
|
326
240
|
function Sigilify(Base, label, opts) {
|
|
@@ -331,7 +245,7 @@
|
|
|
331
245
|
const BaseSigil = BaseSigilify(Base);
|
|
332
246
|
class Sigilified extends BaseSigil {
|
|
333
247
|
}
|
|
334
|
-
|
|
248
|
+
sigilify(Sigilified, label, opts);
|
|
335
249
|
return Sigilified;
|
|
336
250
|
}
|
|
337
251
|
function SigilifyAbstract(Base, label, opts) {
|
|
@@ -342,7 +256,7 @@
|
|
|
342
256
|
const BaseSigil = BaseSigilify(Base);
|
|
343
257
|
class Sigilified extends BaseSigil {
|
|
344
258
|
}
|
|
345
|
-
|
|
259
|
+
sigilify(Sigilified, label, opts);
|
|
346
260
|
return Sigilified;
|
|
347
261
|
}
|
|
348
262
|
|
|
@@ -353,39 +267,34 @@
|
|
|
353
267
|
|
|
354
268
|
// src/attach.ts
|
|
355
269
|
function AttachSigil(label, opts) {
|
|
356
|
-
return function(
|
|
357
|
-
if (!isSigilCtor(
|
|
270
|
+
return function(target, ctx) {
|
|
271
|
+
if (!isSigilCtor(target))
|
|
358
272
|
throw new Error(
|
|
359
|
-
`[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${
|
|
273
|
+
`[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`
|
|
360
274
|
);
|
|
361
|
-
|
|
275
|
+
sigilify(target, label, opts);
|
|
362
276
|
};
|
|
363
277
|
}
|
|
364
|
-
var WithSigil = AttachSigil;
|
|
365
278
|
function attachSigil(Class, label, opts) {
|
|
366
279
|
if (!isSigilCtor(Class))
|
|
367
280
|
throw new Error(
|
|
368
281
|
`[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`
|
|
369
282
|
);
|
|
370
|
-
|
|
283
|
+
sigilify(Class, label, opts);
|
|
371
284
|
return Class;
|
|
372
285
|
}
|
|
373
|
-
var withSigil = attachSigil;
|
|
374
286
|
|
|
375
287
|
exports.AttachSigil = AttachSigil;
|
|
376
|
-
exports.DEFAULT_LABEL_REGEX = DEFAULT_LABEL_REGEX;
|
|
377
288
|
exports.RECOMMENDED_LABEL_REGEX = RECOMMENDED_LABEL_REGEX;
|
|
378
289
|
exports.Sigil = Sigil;
|
|
379
290
|
exports.SigilError = SigilError;
|
|
380
291
|
exports.Sigilify = Sigilify;
|
|
381
292
|
exports.SigilifyAbstract = SigilifyAbstract;
|
|
382
|
-
exports.WithSigil = WithSigil;
|
|
383
293
|
exports.attachSigil = attachSigil;
|
|
384
|
-
exports.
|
|
294
|
+
exports.hasOwnSigil = hasOwnSigil;
|
|
385
295
|
exports.isSigilCtor = isSigilCtor;
|
|
386
296
|
exports.isSigilInstance = isSigilInstance;
|
|
387
297
|
exports.updateSigilOptions = updateSigilOptions;
|
|
388
|
-
exports.withSigil = withSigil;
|
|
389
298
|
|
|
390
299
|
return exports;
|
|
391
300
|
|
package/dist/index.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/options.ts","../src/symbols.ts","../src/helpers.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["a","Sigil"],"mappings":";;;;EA6CO,IAAM,OAAA,GAAkC;EAAA,EAC7C,eAAA,EAAiB,IAAA;EAAA,EACjB,cAAA,EAAgB,IAAA;EAAA,EAChB,wBAAA,EAA0B;EAC5B,CAAA;AAYO,MAAM,kBAAA,GAAqB,CAAC,IAAA,KAA6B;EAC9D,EAAA,IAAI,oBAAoB,IAAA,EAAM;EAC5B,IAAA,IAAI,OAAO,KAAK,cAAA,KAAmB,SAAA;EACjC,MAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;EACvE,IAAA,OAAA,CAAQ,iBAAiB,IAAA,CAAK,cAAA;EAAA,EAChC;EAEA,EAAA,IAAI,qBAAqB,IAAA,EAAM;EAC7B,IAAA,MAAM,MAAM,IAAA,CAAK,eAAA;EACjB,IAAA,IAAI,QAAQ,IAAA,IAAQ,OAAO,GAAA,KAAQ,UAAA,IAAc,EAAE,GAAA,YAAe,MAAA,CAAA;EAChE,MAAA,MAAM,IAAI,MAAM,uEAAuE,CAAA;EACzF,IAAA,OAAA,CAAQ,eAAA,GAAkB,GAAA;EAAA,EAC5B;EAEA,EAAA,IAAI,8BAA8B,IAAA,EAAM;EACtC,IAAA,IAAI,OAAO,KAAK,wBAAA,KAA6B,SAAA;EAC3C,MAAA,MAAM,IAAI,MAAM,+DAA+D,CAAA;EACjF,IAAA,OAAA,CAAQ,2BAA2B,IAAA,CAAK,wBAAA;EAAA,EAC1C;EACF;AAaO,MAAM,uBAAA,GAA0B;AAGhC,MAAM,mBAAA,GAAsB;;;EC3F5B,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EASrD,IAAM,SAAA,mBAAY,MAAA,CAAO,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MAAM,IAAI,KAAA;EAAA,MACR,CAAA,qBAAA,EAAwB,IAAA,CAAK,IAAI,CAAA,cAAA,EAAiB,KAAK,UAAU,CAAA,uBAAA;EAAA,KACnE;EAEF,EAAA,MAAM,SAAA,GAAY,aAAa,IAAI,CAAA;EAAA,EACnC,MAAe,mBAAmB,SAAA,CAAU;EAAA;EAI5C,EAAA,mBAAA,CAAoB,UAAA,EAAY,OAAO,IAAI,CAAA;EAC3C,EAAA,OAAO,UAAA;EACT;;;ACjOO,MAAM,KAAA,GAAQ,aAAa,MAAM;EAAC,CAAC;AAUnC,MAAM,UAAA,GAAa,QAAA,CAAS,KAAA,EAAO,YAAY;;;ECT/C,SAAS,WAAA,CAAY,OAAe,IAAA,EAAqB;EAC9D,EAAA,OAAO,SAAU,OAAiB,OAAA,EAAc;EAC9C,IAAA,IAAI,CAAC,YAAY,KAAK,CAAA;EACpB,MAAA,MAAM,IAAI,KAAA;EAAA,QACR,CAAA,mFAAA,EAAsF,MAAM,IAAI,CAAA,CAAA;EAAA,OAClG;EAEF,IAAA,mBAAA,CAAoB,KAAA,EAAO,OAAO,IAAI,CAAA;EAAA,EACxC,CAAA;EACF;AAKO,MAAM,SAAA,GAAY;EAYlB,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;EAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;EACpB,IAAA,MAAM,IAAI,KAAA;EAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;EAAA,KACjG;EAEF,EAAA,mBAAA,CAAoB,KAAA,EAAO,OAAO,IAAI,CAAA;EACtC,EAAA,OAAO,KAAA;EACT;AAKO,MAAM,SAAA,GAAY","file":"index.global.js","sourcesContent":["/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n\n /**\n * When enabled, non-decorated subclasses that would otherwise inherit an ancestor's label\n * will be assigned an autogenerated random label (so that explicit labels stay unique).\n */\n autofillLabels?: boolean;\n\n /**\n * Option for Hot module reload set-ups, reload of files can result in class redefinition which will throw\n * duplicate label error, setting this to 'true' will disabel this error.\n * However as it disables unique label check bugs can appear if the same label is passed to two different\n * classes so set this to 'true' only when needed and ensure uniqueness of passed labels.\n */\n skipLabelUniquenessCheck?: boolean;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n autofillLabels: true,\n skipLabelUniquenessCheck: false,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = (opts: SigilOptions): void => {\n if ('autofillLabels' in opts) {\n if (typeof opts.autofillLabels !== 'boolean')\n throw new Error(\"'updateSigilOptions.autofillLabels' must be boolean\");\n OPTIONS.autofillLabels = opts.autofillLabels!;\n }\n\n if ('labelValidation' in opts) {\n const val = opts.labelValidation;\n if (val !== null && typeof val !== 'function' && !(val instanceof RegExp))\n throw new Error(\"'updateSigilOptions.labelValidation' must be null, function or RegExp\");\n OPTIONS.labelValidation = val;\n }\n\n if ('skipLabelUniquenessCheck' in opts) {\n if (typeof opts.skipLabelUniquenessCheck !== 'boolean')\n throw new Error(\"'updateSigilOptions.skipLabelUniquenessCheck' must be boolean\");\n OPTIONS.skipLabelUniquenessCheck = opts.skipLabelUniquenessCheck;\n }\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n\n/** @deprecated - Use 'RECOMMENDED_LABEL_REGEX' instead, will be removed in v4 */\nexport const DEFAULT_LABEL_REGEX = RECOMMENDED_LABEL_REGEX;\n","/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the human-readable label for a sigil constructor, it can be inherited if no label is deined.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __EFFECTIVE_LABEL__ = Symbol.for('@vicin/sigil.__EFFECTIVE_LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __EFFECTIVE_LABEL__, __SIGIL__, __DEPTH__ } from './symbols';\nimport type { ISigil, ISigilInstance } from './types';\n\n/** -----------------------------------------\n * Constants\n * ----------------------------------------- */\n\n/** Prefex use by the lib to identify auto-generated classes */\nconst AUTO_LABEL_PREFEX = '@Sigil-auto';\n\n/** -----------------------------------------\n * Weak maps\n * ----------------------------------------- */\n\n/** Weak set to ensure that every ctor is handled only once. register both explicit and lazy handles */\nconst handledCtors = new WeakSet<Function>();\n\n/** Weak set to ensure that every ctor is handled only once. register explicit handles only */\nconst handledCtorsExplicit = new WeakSet<Function>();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function handleSigilExplicit(ctor: Function, label: string, opts?: SigilOptions): void {\n // fast return if already defined\n if (handledCtorsExplicit.has(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(ctor, label, opts);\n // lazy evaluate ancestors\n handleAncestors(ctor, opts);\n // sigilify ctor\n sigilify(ctor, label, true);\n}\n\n/** Function to lazily evaluate 'Sigil' ( update with auto-generated metadata or throw ) */\nexport function handleSigilLazy(ctor: Function): void {\n // fast return if already handled\n if (handledCtors.has(ctor)) return;\n // if autofillLabels is set to false throw error\n if (!OPTIONS.autofillLabels)\n throw new Error(\n `[Sigil Error] Class '${ctor?.name}' is not sigilified, Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`\n );\n // lazy evaluate ancestors\n handleAncestors(ctor);\n // sigilify ctor\n sigilify(ctor, generateRandomLabel(ctor), false);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\nfunction handleAncestors(ctor: Function, opts?: Pick<SigilOptions, 'autofillLabels'>): void {\n // get line age of this class (ancestors only)\n const ancestors: Function[] = [];\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n ancestors.unshift(a);\n a = Object.getPrototypeOf(a);\n }\n\n /** Map<label, className> to record the owner of each label. */\n const labelOwner = new Map<string, string>();\n\n // loop lineage to insure that each label is unique in ancestors\n const autofillLabels = opts?.autofillLabels ?? OPTIONS.autofillLabels;\n for (const a of ancestors) {\n // get label\n const l = a.prototype[__LABEL__] as string;\n // if duplicate (no label is passed for this class) update class with new label\n if (labelOwner.has(l)) {\n if (!autofillLabels)\n throw new Error(\n `[Sigil Error] Class '${a.name}' is not sigilified, Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`\n );\n sigilify(a, generateRandomLabel(a), false);\n }\n // register current label with class name\n labelOwner.set(a.prototype[__LABEL__], a.name);\n }\n}\n\nfunction sigilify(ctor: Function, label: string, explicit: boolean) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: !explicit,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: !explicit,\n enumerable: false,\n writable: false,\n });\n if (explicit)\n Object.defineProperty(ctor.prototype, __EFFECTIVE_LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n if (!handledCtors.has(ctor))\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Mark as handled\n // -------------------------\n\n // mark as handled (explicit or lazy)\n handledCtors.add(ctor);\n // if explicit mark as handled explicit\n if (explicit) handledCtorsExplicit.add(ctor);\n}\n\n/** -----------------------------------------\n * Inspection helpers\n * ----------------------------------------- */\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is ISigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is ISigilInstance {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n\n/**\n * Helper function to get labels registered by 'Sigil'\n * @returns Sigil labels registered\n */\nexport function getSigilLabels(): string[] {\n return getLabelRegistry().labels();\n}\n\n/** -----------------------------------------\n * Label helpers\n * ----------------------------------------- */\n\n/** Exposed methods of global label registry */\ninterface LabelRegistry {\n has: (label: string) => boolean;\n add: (label: string) => void;\n labels: () => string[];\n enc: () => number;\n}\n\n/** Internal helper to get (or init then get) global label registry */\nfunction getLabelRegistry(): LabelRegistry {\n if ('__labelRegistry__' in globalThis) return (globalThis as any).__labelRegistry__;\n\n const labelSet = new Set<string>();\n let count = 0;\n\n const labelRegistry: LabelRegistry = {\n has: (label: string) => labelSet.has(label),\n add: (label: string) => labelSet.add(label),\n labels: () => [...labelSet],\n enc: () => ++count,\n };\n\n Object.freeze(labelRegistry);\n\n Object.defineProperty(globalThis, '__labelRegistry__', {\n value: labelRegistry,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n\n return labelRegistry;\n}\n\n/** Internal helper to validate passed label */\nfunction verifyLabel<L extends string>(ctor: Function, label: L, opts?: SigilOptions): void {\n // get label registry\n const reg = getLabelRegistry();\n\n // If label starts with '@Sigil-auto:' throw error\n if (label.startsWith(AUTO_LABEL_PREFEX))\n throw new Error(`'${AUTO_LABEL_PREFEX}' is a prefex reserved by the library`);\n\n // If label is duplicate throw error\n if (!(opts?.skipLabelUniquenessCheck ?? OPTIONS.skipLabelUniquenessCheck) && reg.has(label))\n throw new Error(\n `[Sigil Error] Passed label '${label}' to class '${ctor?.name}' is re-used, passed labels must be unique`\n );\n\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n\n // Add label to registry\n reg.add(label);\n}\n\n/** Internal helper to generate random label */\nfunction generateRandomLabel(ctor: Function): string {\n return `${AUTO_LABEL_PREFEX}:${ctor?.name}:${getLabelRegistry().enc()}:${Math.random().toString(36).slice(2, 10)}`;\n}\n","import { handleSigilExplicit, handleSigilLazy, isSigilCtor } from './helpers';\nimport type { SigilOptions } from './options';\nimport { __SIGIL__, __LABEL__, __EFFECTIVE_LABEL__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n handleSigilLazy(this);\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.\n */\n static get SigilEffectiveLabel(): string {\n handleSigilLazy(this);\n return (this as any).prototype[__EFFECTIVE_LABEL__];\n }\n\n /**\n * Linearized sigil type label chain for the current constructor.\n *\n * Useful for debugging and performing strict lineage comparisons.\n *\n * @returns An array of labels representing parent → child type labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n handleSigilLazy(this);\n const lineage = [];\n let c = this;\n while (c && typeof c === 'function' && (c.prototype as any)[__SIGIL__]) {\n lineage.unshift(c.SigilLabel);\n c = Object.getPrototypeOf(c);\n }\n return lineage;\n }\n\n /**\n * Sigil type label set for the current constructor.\n * Useful for debugging.\n *\n * @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4\n * @returns A Readonly Set of labels that represent the type lineage.\n */\n static get SigilLabelSet(): Readonly<Set<string>> {\n return new Set(this.SigilLabelLineage);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n const ctor = new.target;\n handleSigilLazy(ctor);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isOfType<T>(this: T, other: unknown): other is GetPrototype<T> {\n handleSigilLazy(this as any);\n if (other == null || typeof other !== 'object') return false;\n return (other as any)[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactType<T>(this: T, other: unknown): other is GetPrototype<T> {\n handleSigilLazy(this as any);\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return (other as any)[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isOfType<T>(this: T, other: unknown): other is T {\n if (other == null || typeof other !== 'object') return false;\n return (other as any)[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactType<T>(this: T, other: unknown): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return (other as any)[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n getSigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Returns the human-readable sigil label of this instance's constructor.\n *\n * @returns The last passed label string (e.g. '@scope/pkg.ClassName').\n */\n getSigilEffectiveLabel(): string {\n return (this as any)[__EFFECTIVE_LABEL__];\n }\n\n /**\n * Returns a copy of the sigil type label lineage for this instance's constructor.\n *\n * @returns readonly array of labels representing the type lineage.\n */\n getSigilLabelLineage(): readonly string[] {\n const lineage: string[] = [];\n let proto = Object.getPrototypeOf(this);\n while (proto && proto[__SIGIL__]) {\n lineage.unshift(proto[__LABEL__]);\n proto = Object.getPrototypeOf(proto);\n }\n return lineage;\n }\n\n /**\n * Returns a copy of the sigil type label lineage set for this instance's constructor.\n *\n * @deprecated To minize API and bundle size, internally this method is 'new Set(this.SigilLabelLineage)' only. will be removed in v4\n * @returns readonly array of labels representing the type lineage.\n */\n getSigilLabelSet(): Readonly<Set<string>> {\n return new Set(this.getSigilLabelLineage());\n }\n }\n\n handleSigilExplicit(Sigil, 'Sigil', { skipLabelUniquenessCheck: true });\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n handleSigilExplicit(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n handleSigilExplicit(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isOfType(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { handleSigilExplicit, isSigilCtor } from './helpers';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (value: Function, context: any) {\n if (!isSigilCtor(value))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${value.name}'`\n );\n\n handleSigilExplicit(value, label, opts);\n };\n}\n\n/**\n * @deprecated Use 'AttachSigil' instead, updated for clarity. will be removed in v4\n */\nexport const WithSigil = AttachSigil;\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n handleSigilExplicit(Class, label, opts);\n return Class;\n}\n\n/**\n * @deprecated Use 'attachSigil' instead, updated for clarity. will be removed in v4\n */\nexport const withSigil = attachSigil;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/registry.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["hasOwnSigil","Sigil"],"mappings":";;;;EAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,iBAAA,mBAAoB,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;EASrE,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,iCAAiC,CAAA;;;EC1BvE,SAAS,YAAY,IAAA,EAAqC;EAC/D,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,IAAc,IAAA,CAA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;EACrB,MAAA,MAAM,IAAI,KAAA;EAAA,QACR,CAAA,mFAAA,EAAsF,OAAO,IAAI,CAAA,CAAA;EAAA,OACnG;EAEF,IAAA,QAAA,CAAS,MAAA,EAAQ,OAAO,IAAI,CAAA;EAAA,EAC9B,CAAA;EACF;EAYO,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;EAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;EACpB,IAAA,MAAM,IAAI,KAAA;EAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;EAAA,KACjG;EAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;EAC3B,EAAA,OAAO,KAAA;EACT","file":"index.global.js","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n\n/**\n * Symbol of global Sigil registry\n *\n * @constant {symbol}\n */\nexport const __SIGIL_REGISTRY__ = Symbol.for('@vicin/sigil.__SIGIL_REGISTRY__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { __SIGIL_REGISTRY__ } from './symbols';\n\ninterface SigilRegistry {\n registerResolved: (ctor: Function) => void;\n checkResolved: (ctor: Function) => boolean;\n registerHasOwn: (ctor: Function) => void;\n checkHasOwn: (ctor: Function) => boolean;\n}\n\nexport function getSigilRegistry(): SigilRegistry {\n if ((globalThis as any)[__SIGIL_REGISTRY__]) return (globalThis as any)[__SIGIL_REGISTRY__];\n\n /** Weak set to ensure that every ctor is handled only once */\n const resolved = new WeakSet<Function>();\n\n /** Weak set to store ctors that called sigilify function */\n const hasOwnSigil = new WeakSet<Function>();\n\n /** Registry */\n const registry: SigilRegistry = {\n registerResolved(ctor) {\n resolved.add(ctor);\n },\n checkResolved(ctor) {\n return resolved.has(ctor);\n },\n registerHasOwn(ctor) {\n hasOwnSigil.add(ctor);\n },\n checkHasOwn(ctor) {\n return hasOwnSigil.has(ctor);\n },\n };\n\n // Freeze registy to prevent any mutations\n Object.freeze(registry);\n // Append registry into globalThis and make it non-writable\n Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {\n value: registry,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n // return registry\n return registry;\n}\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport { getSigilRegistry } from './registry';\n\n/** -----------------------------------------\n * Get registry\n * ----------------------------------------- */\n\nconst sigilRegistry = getSigilRegistry();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (sigilRegistry.checkResolved(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n sigilRegistry.registerResolved(ctor);\n sigilRegistry.registerHasOwn(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return sigilRegistry.checkHasOwn(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n sigilRegistry.registerResolved(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|