@vicin/sigil 1.3.0 → 2.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 +16 -0
- package/README.md +22 -133
- package/dist/index.d.mts +113 -400
- package/dist/index.d.ts +113 -400
- package/dist/index.global.js +1808 -415
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +96 -417
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -415
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,250 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
3
|
+
var cuid2 = require('@paralleldrive/cuid2');
|
|
6
4
|
|
|
7
5
|
// src/core/options.ts
|
|
8
6
|
var OPTIONS = {
|
|
9
7
|
labelValidation: null,
|
|
10
8
|
skipLabelInheritanceCheck: false,
|
|
11
|
-
autofillLabels: false
|
|
12
|
-
devMarker: false,
|
|
13
|
-
registry: null,
|
|
14
|
-
useGlobalRegistry: false,
|
|
15
|
-
storeConstructor: false
|
|
9
|
+
autofillLabels: false
|
|
16
10
|
};
|
|
17
|
-
var
|
|
18
|
-
var updateGlobalRegistry = (map) => {
|
|
19
|
-
if (map === null) delete globalThis[__SIGIL_REGISTRY__];
|
|
20
|
-
else globalThis[__SIGIL_REGISTRY__] = map;
|
|
21
|
-
};
|
|
22
|
-
var getGlobalRegistry = () => {
|
|
23
|
-
const val = globalThis[__SIGIL_REGISTRY__];
|
|
24
|
-
return val === void 0 ? null : val;
|
|
25
|
-
};
|
|
26
|
-
var SigilRegistry = class _SigilRegistry {
|
|
27
|
-
/**
|
|
28
|
-
* @param map - Map used to register 'Sigil' classes. if not passed it will be auto-generated internally.
|
|
29
|
-
*/
|
|
30
|
-
constructor(map) {
|
|
31
|
-
/** Internal private registry map. */
|
|
32
|
-
__publicField(this, "_registry");
|
|
33
|
-
this._registry = map != null ? map : /* @__PURE__ */ new Map();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Return a readonly view (array) of the current registry entries.
|
|
37
|
-
*
|
|
38
|
-
* @returns An array containing all registered labels, or an empty array when registry is disabled.
|
|
39
|
-
*/
|
|
40
|
-
listLabels() {
|
|
41
|
-
return this._registry ? Array.from(this._registry.keys()) : [];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Determine whether the registry currently contains `label`.
|
|
45
|
-
*
|
|
46
|
-
* @param label - The label to test.
|
|
47
|
-
* @returns `true` if present; `false` otherwise.
|
|
48
|
-
*/
|
|
49
|
-
has(label) {
|
|
50
|
-
return !!this._registry && this._registry.has(label);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get class constructor using its label.
|
|
54
|
-
*
|
|
55
|
-
* @param label - Label appended to Sigil class.
|
|
56
|
-
* @returns Reference to Sigil class constructor or null if stored with 'SigilOptions.storeConstructor = false'.
|
|
57
|
-
*/
|
|
58
|
-
get(label) {
|
|
59
|
-
var _a;
|
|
60
|
-
return (_a = this._registry.get(label)) != null ? _a : null;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Register a label and class constructor in the active registry.
|
|
64
|
-
*
|
|
65
|
-
* If the label already exists then:
|
|
66
|
-
* - In DEV builds: prints a console warning (HMR friendly) and returns early.
|
|
67
|
-
* - In non-DEV builds: throws an Error to prevent duplicate registration.
|
|
68
|
-
*
|
|
69
|
-
* @param label - Label string to register (e.g. '@scope/pkg.ClassName').
|
|
70
|
-
* @param Class - Constructor of the class being registered.
|
|
71
|
-
* @param opts - Optional per-call overrides.
|
|
72
|
-
*/
|
|
73
|
-
register(label, Class, opts) {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
75
|
-
if (!OPTIONS.registry) return;
|
|
76
|
-
const storeCtor = (_a = opts == null ? void 0 : opts.storeConstructor) != null ? _a : OPTIONS.storeConstructor;
|
|
77
|
-
const devMarker = (_b = opts == null ? void 0 : opts.devMarker) != null ? _b : OPTIONS.devMarker;
|
|
78
|
-
if (this._registry.has(label)) {
|
|
79
|
-
const existing = this._registry.get(label);
|
|
80
|
-
const isLikelyHMR = (existing == null ? void 0 : existing.name) === (Class == null ? void 0 : Class.name);
|
|
81
|
-
if (devMarker) {
|
|
82
|
-
if (isLikelyHMR) {
|
|
83
|
-
console.warn(
|
|
84
|
-
`[Sigil] Duplicate label "${label}" may be due to HMR \u2014 ignore if you are sure that it's defined once.`
|
|
85
|
-
);
|
|
86
|
-
} else {
|
|
87
|
-
throw new Error(
|
|
88
|
-
`[Sigil Error] Duplicate label '${label}' (different classes: ${(_c = existing == null ? void 0 : existing.name) != null ? _c : "unknown"} vs ${(_d = Class == null ? void 0 : Class.name) != null ? _d : "unknown"}).`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`[Sigil Error] Duplicate label '${label}' detected. Labels must be unique.`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
this._registry.set(label, storeCtor ? Class : null);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Alias for 'SigilRegistry.register'.
|
|
102
|
-
*
|
|
103
|
-
* @param label - Label string to register (e.g. '@scope/pkg.ClassName').
|
|
104
|
-
* @param Class - Constructor of the class being registered.
|
|
105
|
-
* @param opts - Optional per-call overrides.
|
|
106
|
-
*/
|
|
107
|
-
set(label, Class, opts) {
|
|
108
|
-
return this.register(label, Class, opts);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Unregister a previously registered class.
|
|
112
|
-
*
|
|
113
|
-
* @param label - The label to remove from the registry.
|
|
114
|
-
* @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
|
|
115
|
-
*/
|
|
116
|
-
unregister(label) {
|
|
117
|
-
return this._registry.delete(label);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Alias for 'SigilRegistry.unregister'.
|
|
121
|
-
*
|
|
122
|
-
* @param label - The label to remove from the registry.
|
|
123
|
-
* @returns `true` if the label was present and removed; `false` otherwise (or when registry is disabled).
|
|
124
|
-
*/
|
|
125
|
-
delete(label) {
|
|
126
|
-
return this.unregister(label);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Replace active registry with new one. deprecated use 'updateOptions({ registry: newRegistry })' instead.
|
|
130
|
-
*
|
|
131
|
-
* @deprecated Will be removed in v2.0.0, check https://www.npmjs.com/package/@vicin/sigil?activeTab=readme#deprecated-api for more details.
|
|
132
|
-
* @param newRegistry - New Set<string> instance to use as the active registry, or `null` to disable checks.
|
|
133
|
-
*/
|
|
134
|
-
replaceRegistry(newRegistry) {
|
|
135
|
-
if (newRegistry) updateOptions({ registry: new _SigilRegistry(newRegistry) });
|
|
136
|
-
else updateOptions({ registry: newRegistry });
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Clear the registry completely.
|
|
140
|
-
*
|
|
141
|
-
* Useful for test teardown, or when explicitly resetting state during development.
|
|
142
|
-
* No-op when the registry is disabled.
|
|
143
|
-
*/
|
|
144
|
-
clear() {
|
|
145
|
-
this._registry.clear();
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Merge another SigilRegistry into this one.
|
|
149
|
-
*
|
|
150
|
-
* Entries from `other` will be registered into this registry. Duplicate labels
|
|
151
|
-
* are handled via this registry's `register` logic (i.e., will warn in DEV or
|
|
152
|
-
* throw in production).
|
|
153
|
-
*
|
|
154
|
-
* @param other - Another `SigilRegistry` whose entries will be merged into this registry.
|
|
155
|
-
*/
|
|
156
|
-
merge(other) {
|
|
157
|
-
if (!OPTIONS.registry) return;
|
|
158
|
-
for (const [label, ctor] of other) this.register(label, ctor);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Return a Map-style iterator over entries: `[label, constructor]`.
|
|
162
|
-
* Equivalent to calling `registry[Symbol.iterator]()`.
|
|
163
|
-
*
|
|
164
|
-
* @returns IterableIterator of `[label, ISigil]`.
|
|
165
|
-
*/
|
|
166
|
-
entries() {
|
|
167
|
-
return this._registry.entries();
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Return an iterator over registered constructors.
|
|
171
|
-
*
|
|
172
|
-
* @returns IterableIterator of `ISigil` constructors.
|
|
173
|
-
*/
|
|
174
|
-
values() {
|
|
175
|
-
return this._registry.values();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Return an iterator over registered labels (keys).
|
|
179
|
-
*
|
|
180
|
-
* @returns IterableIterator of `string` labels.
|
|
181
|
-
*/
|
|
182
|
-
keys() {
|
|
183
|
-
return this._registry.keys();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Execute a provided function once per registry entry.
|
|
187
|
-
*
|
|
188
|
-
* @param callback - Function invoked with `(ctor, label)` for each entry.
|
|
189
|
-
* @param thisArg - Optional `this` context for the callback.
|
|
190
|
-
*/
|
|
191
|
-
forEach(callback, thisArg) {
|
|
192
|
-
this._registry.forEach((ctor, label) => callback.call(thisArg, ctor, label));
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Get the size (number of entries) of the active registry.
|
|
196
|
-
*
|
|
197
|
-
* @returns The number of registered labels, or 0 when registry is disabled.
|
|
198
|
-
*/
|
|
199
|
-
get size() {
|
|
200
|
-
return this._registry.size;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Return an iterator over `[label, constructor]` pairs.
|
|
204
|
-
*
|
|
205
|
-
* This makes the registry compatible with `for..of` and other iterable helpers:
|
|
206
|
-
* ```ts
|
|
207
|
-
* for (const [label, ctor] of registry) { ... }
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @returns An iterable iterator that yields `[label, ISigil]` tuples.
|
|
211
|
-
*/
|
|
212
|
-
[Symbol.iterator]() {
|
|
213
|
-
return this._registry[Symbol.iterator]();
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
var getActiveRegistry = () => {
|
|
217
|
-
const globalRegistry = getGlobalRegistry();
|
|
218
|
-
if (globalRegistry) return globalRegistry;
|
|
219
|
-
return OPTIONS.registry;
|
|
220
|
-
};
|
|
221
|
-
exports.REGISTRY = OPTIONS.registry;
|
|
222
|
-
var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
223
|
-
var updateOptions = (opts, mergeRegistries = true) => {
|
|
224
|
-
applyBeforeSideEffects(OPTIONS, opts, mergeRegistries);
|
|
11
|
+
var updateOptions = (opts) => {
|
|
225
12
|
for (const [k, v] of Object.entries(opts)) OPTIONS[k] = v;
|
|
226
|
-
applyAfterSideEffects(OPTIONS);
|
|
227
13
|
};
|
|
228
|
-
function applyBeforeSideEffects(oldOpts, newOpts, mergeRegistries) {
|
|
229
|
-
if (mergeRegistries && newOpts.registry && oldOpts.registry)
|
|
230
|
-
newOpts.registry.merge(oldOpts.registry);
|
|
231
|
-
}
|
|
232
|
-
function applyAfterSideEffects(opts) {
|
|
233
|
-
if (opts.useGlobalRegistry) updateGlobalRegistry(opts.registry);
|
|
234
|
-
else updateGlobalRegistry(null);
|
|
235
|
-
if (OPTIONS.registry) exports.REGISTRY = OPTIONS.registry;
|
|
236
|
-
else exports.REGISTRY = new SigilRegistry();
|
|
237
|
-
}
|
|
238
14
|
var DEFAULT_OPTIONS = {
|
|
239
15
|
labelValidation: null,
|
|
240
16
|
skipLabelInheritanceCheck: false,
|
|
241
|
-
autofillLabels: false
|
|
242
|
-
devMarker: process.env.NODE_ENV !== "production",
|
|
243
|
-
registry: new SigilRegistry(),
|
|
244
|
-
useGlobalRegistry: true,
|
|
245
|
-
storeConstructor: true
|
|
17
|
+
autofillLabels: false
|
|
246
18
|
};
|
|
247
19
|
updateOptions(DEFAULT_OPTIONS);
|
|
20
|
+
var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
248
21
|
|
|
249
22
|
// src/core/symbols.ts
|
|
250
23
|
var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
|
|
@@ -252,41 +25,34 @@ var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
|
|
|
252
25
|
var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
|
|
253
26
|
var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
|
|
254
27
|
var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
|
|
28
|
+
var __LABEL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_LINEAGE__");
|
|
29
|
+
var __LABEL_SET__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_SET__");
|
|
30
|
+
|
|
31
|
+
// src/core/constants.ts
|
|
32
|
+
var __DEV__ = typeof process !== "undefined" && process.env.NODE_ENV === "development";
|
|
258
33
|
|
|
259
34
|
// src/core/helpers.ts
|
|
260
|
-
function decorateCtor(ctor, label,
|
|
261
|
-
var _a;
|
|
35
|
+
function decorateCtor(ctor, label, isMixin = false) {
|
|
262
36
|
if (isDecorated(ctor))
|
|
263
37
|
throw new Error(
|
|
264
38
|
`Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`
|
|
265
39
|
);
|
|
266
|
-
const symbol = Symbol.for(label);
|
|
267
|
-
(_a = getActiveRegistry()) == null ? void 0 : _a.register(label, ctor, opts);
|
|
268
40
|
Object.defineProperty(ctor, __LABEL__, {
|
|
269
41
|
value: label,
|
|
270
42
|
configurable: false,
|
|
271
43
|
enumerable: false,
|
|
272
44
|
writable: false
|
|
273
45
|
});
|
|
274
|
-
Object.defineProperty(ctor, __TYPE__, {
|
|
275
|
-
value: symbol,
|
|
276
|
-
configurable: false,
|
|
277
|
-
enumerable: false,
|
|
278
|
-
writable: false
|
|
279
|
-
});
|
|
280
46
|
const parent = Object.getPrototypeOf(ctor);
|
|
281
|
-
const parentChain = parent && parent[
|
|
282
|
-
const ctorChain = isMixin && label !== "Sigil" ? [
|
|
283
|
-
Object.defineProperty(ctor,
|
|
47
|
+
const parentChain = parent && parent[__LABEL_LINEAGE__] ? parent[__LABEL_LINEAGE__] : [];
|
|
48
|
+
const ctorChain = isMixin && label !== "Sigil" ? ["Sigil", ...parentChain, label] : [...parentChain, label];
|
|
49
|
+
Object.defineProperty(ctor, __LABEL_LINEAGE__, {
|
|
284
50
|
value: ctorChain,
|
|
285
51
|
configurable: false,
|
|
286
52
|
enumerable: false,
|
|
287
53
|
writable: false
|
|
288
54
|
});
|
|
289
|
-
Object.defineProperty(ctor,
|
|
55
|
+
Object.defineProperty(ctor, __LABEL_SET__, {
|
|
290
56
|
value: new Set(ctorChain),
|
|
291
57
|
configurable: false,
|
|
292
58
|
enumerable: false,
|
|
@@ -295,11 +61,9 @@ function decorateCtor(ctor, label, opts, isMixin = false) {
|
|
|
295
61
|
markDecorated(ctor);
|
|
296
62
|
}
|
|
297
63
|
function checkInheritance(ctor, opts) {
|
|
298
|
-
var _a, _b
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
const autofillLabels = (_c = opts == null ? void 0 : opts.autofillLabels) != null ? _c : OPTIONS.autofillLabels;
|
|
302
|
-
if (!devMarker) return;
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const skipLabelInheritanceCheck = (_a = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _a : OPTIONS.skipLabelInheritanceCheck;
|
|
66
|
+
const autofillLabels = (_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels;
|
|
303
67
|
if (!isSigilCtor(ctor)) return;
|
|
304
68
|
if (isInheritanceChecked(ctor) || skipLabelInheritanceCheck) return;
|
|
305
69
|
const ctors = [ctor];
|
|
@@ -321,7 +85,7 @@ function checkInheritance(ctor, opts) {
|
|
|
321
85
|
);
|
|
322
86
|
}
|
|
323
87
|
label = generateRandomLabel();
|
|
324
|
-
decorateCtor(ctor2, label
|
|
88
|
+
decorateCtor(ctor2, label);
|
|
325
89
|
}
|
|
326
90
|
labelOwner.set(label, ctor2.name);
|
|
327
91
|
}
|
|
@@ -340,10 +104,8 @@ function verifyLabel(label, opts) {
|
|
|
340
104
|
);
|
|
341
105
|
}
|
|
342
106
|
}
|
|
343
|
-
function generateRandomLabel(
|
|
344
|
-
let label =
|
|
345
|
-
const registry = getActiveRegistry();
|
|
346
|
-
if (registry) while (registry.has(label)) label = generateRandomLabel();
|
|
107
|
+
function generateRandomLabel() {
|
|
108
|
+
let label = cuid2.createId();
|
|
347
109
|
return `@Sigil.auto-${label}`;
|
|
348
110
|
}
|
|
349
111
|
function markSigil(ctor) {
|
|
@@ -405,14 +167,6 @@ function getConstructor(obj) {
|
|
|
405
167
|
if (!obj || typeof obj !== "object") return null;
|
|
406
168
|
return (_c = (_b = obj.constructor) != null ? _b : (_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.constructor) != null ? _c : null;
|
|
407
169
|
}
|
|
408
|
-
function generateRandomString(length = 16) {
|
|
409
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
410
|
-
let result = "";
|
|
411
|
-
for (let i = 0; i < length; i++) {
|
|
412
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
413
|
-
}
|
|
414
|
-
return result;
|
|
415
|
-
}
|
|
416
170
|
|
|
417
171
|
// src/core/mixin.ts
|
|
418
172
|
function Sigilify(Base, label, opts) {
|
|
@@ -430,49 +184,39 @@ function Sigilify(Base, label, opts) {
|
|
|
430
184
|
return this[__LABEL__];
|
|
431
185
|
}
|
|
432
186
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* This symbol is created with `Symbol.for(label)` during decoration so it is
|
|
436
|
-
* stable across realms that share the same global symbol registry.
|
|
437
|
-
*/
|
|
438
|
-
static get SigilType() {
|
|
439
|
-
return this[__TYPE__];
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
187
|
+
* Copy of the linearized sigil type label chain for the current constructor.
|
|
443
188
|
*
|
|
444
189
|
* Useful for debugging and performing strict lineage comparisons.
|
|
445
190
|
*
|
|
446
|
-
* @returns An array of
|
|
191
|
+
* @returns An array of labels representing parent → child type labels.
|
|
447
192
|
*/
|
|
448
|
-
static get
|
|
193
|
+
static get SigilLabelLineage() {
|
|
449
194
|
var _a;
|
|
450
|
-
return [...(_a = this[
|
|
195
|
+
return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
|
|
451
196
|
}
|
|
452
197
|
/**
|
|
453
|
-
* Copy of the sigil type
|
|
198
|
+
* Copy of the sigil type label set for the current constructor.
|
|
454
199
|
*
|
|
455
200
|
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
456
201
|
*
|
|
457
|
-
* @returns A Readonly Set of
|
|
202
|
+
* @returns A Readonly Set of labels that represent the type lineage.
|
|
458
203
|
*/
|
|
459
|
-
static get
|
|
204
|
+
static get SigilLabelSet() {
|
|
460
205
|
const set = /* @__PURE__ */ new Set();
|
|
461
|
-
for (const s of this[
|
|
206
|
+
for (const s of this[__LABEL_SET__]) set.add(s);
|
|
462
207
|
return set;
|
|
463
208
|
}
|
|
464
209
|
constructor(...args) {
|
|
465
|
-
var _a;
|
|
466
210
|
super(...args);
|
|
467
211
|
if (Object.getPrototypeOf(this) !== new.target.prototype)
|
|
468
212
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
469
213
|
const ctor = getConstructor(this);
|
|
470
214
|
if (!ctor) {
|
|
471
|
-
if (
|
|
215
|
+
if (__DEV__)
|
|
472
216
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
473
217
|
return;
|
|
474
218
|
}
|
|
475
|
-
checkInheritance(ctor);
|
|
219
|
+
if (__DEV__) checkInheritance(ctor);
|
|
476
220
|
}
|
|
477
221
|
/**
|
|
478
222
|
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
@@ -497,12 +241,12 @@ function Sigilify(Base, label, opts) {
|
|
|
497
241
|
static isOfType(other) {
|
|
498
242
|
var _a;
|
|
499
243
|
if (!isSigilInstance(other)) return false;
|
|
500
|
-
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
501
|
-
const thisType = this[
|
|
244
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
|
|
245
|
+
const thisType = this[__LABEL__];
|
|
502
246
|
return !!otherSet && otherSet.has(thisType);
|
|
503
247
|
}
|
|
504
248
|
/**
|
|
505
|
-
* Strict lineage check: compares the type
|
|
249
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
506
250
|
*
|
|
507
251
|
* @typeParam T - The calling constructor type.
|
|
508
252
|
* @param this - The constructor performing the check.
|
|
@@ -512,8 +256,8 @@ function Sigilify(Base, label, opts) {
|
|
|
512
256
|
static isOfTypeStrict(other) {
|
|
513
257
|
var _a;
|
|
514
258
|
if (!isSigilInstance(other)) return false;
|
|
515
|
-
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
516
|
-
const thisLineage = this[
|
|
259
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
|
|
260
|
+
const thisLineage = this[__LABEL_LINEAGE__];
|
|
517
261
|
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
518
262
|
}
|
|
519
263
|
/**
|
|
@@ -529,12 +273,12 @@ function Sigilify(Base, label, opts) {
|
|
|
529
273
|
isOfType(other) {
|
|
530
274
|
var _a;
|
|
531
275
|
if (!isSigilInstance(other)) return false;
|
|
532
|
-
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
533
|
-
const thisType = getConstructor(this)[
|
|
276
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
|
|
277
|
+
const thisType = getConstructor(this)[__LABEL__];
|
|
534
278
|
return !!otherSet && otherSet.has(thisType);
|
|
535
279
|
}
|
|
536
280
|
/**
|
|
537
|
-
* Strict lineage check: compares the type
|
|
281
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
538
282
|
*
|
|
539
283
|
* Allows 'instanceof' like checks but in instances.
|
|
540
284
|
*
|
|
@@ -546,8 +290,8 @@ function Sigilify(Base, label, opts) {
|
|
|
546
290
|
isOfTypeStrict(other) {
|
|
547
291
|
var _a, _b;
|
|
548
292
|
if (!isSigilInstance(other)) return false;
|
|
549
|
-
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
550
|
-
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[
|
|
293
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
|
|
294
|
+
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
|
|
551
295
|
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
552
296
|
}
|
|
553
297
|
/**
|
|
@@ -556,62 +300,44 @@ function Sigilify(Base, label, opts) {
|
|
|
556
300
|
* @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
|
|
557
301
|
*/
|
|
558
302
|
getSigilLabel() {
|
|
559
|
-
var _a;
|
|
560
303
|
const ctor = getConstructor(this);
|
|
561
304
|
if (!ctor) {
|
|
562
|
-
if (
|
|
305
|
+
if (__DEV__)
|
|
563
306
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
564
307
|
return "@Sigil.unknown";
|
|
565
308
|
}
|
|
566
309
|
return ctor.SigilLabel;
|
|
567
310
|
}
|
|
568
311
|
/**
|
|
569
|
-
* Returns the
|
|
312
|
+
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
570
313
|
*
|
|
571
|
-
* @returns
|
|
314
|
+
* @returns readonly array of labels representing the type lineage.
|
|
572
315
|
*/
|
|
573
|
-
|
|
574
|
-
var _a;
|
|
316
|
+
getSigilLabelLineage() {
|
|
575
317
|
const ctor = getConstructor(this);
|
|
576
318
|
if (!ctor) {
|
|
577
|
-
if (
|
|
319
|
+
if (__DEV__)
|
|
578
320
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
579
|
-
return
|
|
321
|
+
return ["@Sigil.unknown"];
|
|
580
322
|
}
|
|
581
|
-
return ctor.
|
|
323
|
+
return ctor.SigilLabelLineage;
|
|
582
324
|
}
|
|
583
325
|
/**
|
|
584
|
-
* Returns a copy of the sigil type
|
|
326
|
+
* Returns a readonly copy of the sigil type label set for this instance's constructor.
|
|
585
327
|
*
|
|
586
|
-
* @returns
|
|
328
|
+
* @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
|
|
587
329
|
*/
|
|
588
|
-
|
|
589
|
-
var _a;
|
|
330
|
+
getSigilLabelSet() {
|
|
590
331
|
const ctor = getConstructor(this);
|
|
591
332
|
if (!ctor) {
|
|
592
|
-
if (
|
|
333
|
+
if (__DEV__)
|
|
593
334
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
594
|
-
return
|
|
335
|
+
return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
|
|
595
336
|
}
|
|
596
|
-
return ctor.
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Returns a readonly copy of the sigil type symbol set for this instance's constructor.
|
|
600
|
-
*
|
|
601
|
-
* @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
|
|
602
|
-
*/
|
|
603
|
-
getSigilTypeSet() {
|
|
604
|
-
var _a;
|
|
605
|
-
const ctor = getConstructor(this);
|
|
606
|
-
if (!ctor) {
|
|
607
|
-
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
608
|
-
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
609
|
-
return /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("@Sigil.unknown")]);
|
|
610
|
-
}
|
|
611
|
-
return ctor.SigilTypeSet;
|
|
337
|
+
return ctor.SigilLabelSet;
|
|
612
338
|
}
|
|
613
339
|
}
|
|
614
|
-
decorateCtor(Sigilified, l,
|
|
340
|
+
decorateCtor(Sigilified, l, true);
|
|
615
341
|
markSigil(Sigilified);
|
|
616
342
|
markSigilBase(Sigilified);
|
|
617
343
|
return Sigilified;
|
|
@@ -631,49 +357,39 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
631
357
|
return this[__LABEL__];
|
|
632
358
|
}
|
|
633
359
|
/**
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* This symbol is created with `Symbol.for(label)` during decoration so it is
|
|
637
|
-
* stable across realms that share the same global symbol registry.
|
|
638
|
-
*/
|
|
639
|
-
static get SigilType() {
|
|
640
|
-
return this[__TYPE__];
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* Copy of the linearized sigil type symbol chain for the current constructor.
|
|
360
|
+
* Copy of the linearized sigil type label chain for the current constructor.
|
|
644
361
|
*
|
|
645
362
|
* Useful for debugging and performing strict lineage comparisons.
|
|
646
363
|
*
|
|
647
|
-
* @returns An array of
|
|
364
|
+
* @returns An array of labels representing parent → child type labels.
|
|
648
365
|
*/
|
|
649
|
-
static get
|
|
366
|
+
static get SigilLabelLineage() {
|
|
650
367
|
var _a;
|
|
651
|
-
return [...(_a = this[
|
|
368
|
+
return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
|
|
652
369
|
}
|
|
653
370
|
/**
|
|
654
|
-
* Copy of the sigil type
|
|
371
|
+
* Copy of the sigil type label set for the current constructor.
|
|
655
372
|
*
|
|
656
373
|
* Useful for quick membership checks (O(1) lookups) and debugging.
|
|
657
374
|
*
|
|
658
|
-
* @returns A Readonly Set of
|
|
375
|
+
* @returns A Readonly Set of labels that represent the type lineage.
|
|
659
376
|
*/
|
|
660
|
-
static get
|
|
377
|
+
static get SigilLabelSet() {
|
|
661
378
|
const set = /* @__PURE__ */ new Set();
|
|
662
|
-
for (const s of this[
|
|
379
|
+
for (const s of this[__LABEL_SET__]) set.add(s);
|
|
663
380
|
return set;
|
|
664
381
|
}
|
|
665
382
|
constructor(...args) {
|
|
666
|
-
var _a;
|
|
667
383
|
super(...args);
|
|
668
384
|
if (Object.getPrototypeOf(this) !== new.target.prototype)
|
|
669
385
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
670
386
|
const ctor = getConstructor(this);
|
|
671
387
|
if (!ctor) {
|
|
672
|
-
if (
|
|
388
|
+
if (__DEV__)
|
|
673
389
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
674
390
|
return;
|
|
675
391
|
}
|
|
676
|
-
checkInheritance(ctor);
|
|
392
|
+
if (__DEV__) checkInheritance(ctor);
|
|
677
393
|
}
|
|
678
394
|
/**
|
|
679
395
|
* Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
|
|
@@ -688,7 +404,7 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
688
404
|
* Check whether `other` is (or inherits from) the type represented by the calling constructor.
|
|
689
405
|
*
|
|
690
406
|
* Implementation detail:
|
|
691
|
-
* - Uses the other instance's `
|
|
407
|
+
* - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
|
|
692
408
|
* - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
|
|
693
409
|
*
|
|
694
410
|
* This replaces `instanceof` so that checks remain valid across bundles/realms
|
|
@@ -702,12 +418,12 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
702
418
|
static isOfType(other) {
|
|
703
419
|
var _a;
|
|
704
420
|
if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
|
|
705
|
-
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
706
|
-
const thisType = this[
|
|
421
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
|
|
422
|
+
const thisType = this[__LABEL__];
|
|
707
423
|
return !!otherSet && otherSet.has(thisType);
|
|
708
424
|
}
|
|
709
425
|
/**
|
|
710
|
-
* Strict lineage check: compares the type
|
|
426
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
711
427
|
*
|
|
712
428
|
* Implementation detail:
|
|
713
429
|
* - Works in O(n) time where n is the depth of the lineage.
|
|
@@ -721,8 +437,8 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
721
437
|
static isOfTypeStrict(other) {
|
|
722
438
|
var _a;
|
|
723
439
|
if (!isSigilInstance(other) || !isSigilCtor(this)) return false;
|
|
724
|
-
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
725
|
-
const thisLineage = this[
|
|
440
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
|
|
441
|
+
const thisLineage = this[__LABEL_LINEAGE__];
|
|
726
442
|
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
727
443
|
}
|
|
728
444
|
/**
|
|
@@ -738,12 +454,12 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
738
454
|
isOfType(other) {
|
|
739
455
|
var _a;
|
|
740
456
|
if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
|
|
741
|
-
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
742
|
-
const thisType = getConstructor(this)[
|
|
457
|
+
const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
|
|
458
|
+
const thisType = getConstructor(this)[__LABEL__];
|
|
743
459
|
return !!otherSet && otherSet.has(thisType);
|
|
744
460
|
}
|
|
745
461
|
/**
|
|
746
|
-
* Strict lineage check: compares the type
|
|
462
|
+
* Strict lineage check: compares the type label lineage arrays element-by-element.
|
|
747
463
|
*
|
|
748
464
|
* Allows 'instanceof' like checks but in instances.
|
|
749
465
|
*
|
|
@@ -755,8 +471,8 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
755
471
|
isOfTypeStrict(other) {
|
|
756
472
|
var _a, _b;
|
|
757
473
|
if (!isSigilInstance(other) || !isSigilInstance(this)) return false;
|
|
758
|
-
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[
|
|
759
|
-
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[
|
|
474
|
+
const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
|
|
475
|
+
const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
|
|
760
476
|
return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
|
|
761
477
|
}
|
|
762
478
|
/**
|
|
@@ -765,62 +481,44 @@ function SigilifyAbstract(Base, label, opts) {
|
|
|
765
481
|
* @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
|
|
766
482
|
*/
|
|
767
483
|
getSigilLabel() {
|
|
768
|
-
var _a;
|
|
769
484
|
const ctor = getConstructor(this);
|
|
770
485
|
if (!ctor) {
|
|
771
|
-
if (
|
|
486
|
+
if (__DEV__)
|
|
772
487
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
773
488
|
return "@Sigil.unknown";
|
|
774
489
|
}
|
|
775
490
|
return ctor.SigilLabel;
|
|
776
491
|
}
|
|
777
492
|
/**
|
|
778
|
-
* Returns the
|
|
493
|
+
* Returns a copy of the sigil type label lineage for this instance's constructor.
|
|
779
494
|
*
|
|
780
|
-
* @returns
|
|
495
|
+
* @returns readonly array of labels representing the type lineage.
|
|
781
496
|
*/
|
|
782
|
-
|
|
783
|
-
var _a;
|
|
784
|
-
const ctor = getConstructor(this);
|
|
785
|
-
if (!ctor) {
|
|
786
|
-
if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
|
|
787
|
-
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
788
|
-
return /* @__PURE__ */ Symbol.for("@Sigil.unknown");
|
|
789
|
-
}
|
|
790
|
-
return ctor.SigilType;
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
* Returns a copy of the sigil type symbol lineage for this instance's constructor.
|
|
794
|
-
*
|
|
795
|
-
* @returns readonly array of symbols representing the type lineage.
|
|
796
|
-
*/
|
|
797
|
-
getSigilTypeLineage() {
|
|
798
|
-
var _a;
|
|
497
|
+
getSigilLabelLineage() {
|
|
799
498
|
const ctor = getConstructor(this);
|
|
800
499
|
if (!ctor) {
|
|
801
|
-
if (
|
|
500
|
+
if (__DEV__)
|
|
802
501
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
803
|
-
return [
|
|
502
|
+
return ["@Sigil.unknown"];
|
|
804
503
|
}
|
|
805
|
-
return ctor.
|
|
504
|
+
return ctor.SigilLabelLineage;
|
|
806
505
|
}
|
|
807
506
|
/**
|
|
808
|
-
* Returns a readonly copy of the sigil type
|
|
507
|
+
* Returns a readonly copy of the sigil type label set for this instance's constructor.
|
|
809
508
|
*
|
|
810
|
-
* @returns A Readonly Set of
|
|
509
|
+
* @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
|
|
811
510
|
*/
|
|
812
|
-
|
|
813
|
-
var _a;
|
|
511
|
+
getSigilLabelSet() {
|
|
814
512
|
const ctor = getConstructor(this);
|
|
815
513
|
if (!ctor) {
|
|
816
|
-
if (
|
|
514
|
+
if (__DEV__)
|
|
817
515
|
throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
|
|
818
|
-
return /* @__PURE__ */ new Set([
|
|
516
|
+
return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
|
|
819
517
|
}
|
|
820
|
-
return ctor.
|
|
518
|
+
return ctor.SigilLabelSet;
|
|
821
519
|
}
|
|
822
520
|
}
|
|
823
|
-
decorateCtor(Sigilified, l,
|
|
521
|
+
decorateCtor(Sigilified, l, true);
|
|
824
522
|
markSigil(Sigilified);
|
|
825
523
|
markSigilBase(Sigilified);
|
|
826
524
|
return Sigilified;
|
|
@@ -844,8 +542,8 @@ function WithSigil(label, opts) {
|
|
|
844
542
|
throw new Error(
|
|
845
543
|
`[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
|
|
846
544
|
);
|
|
847
|
-
decorateCtor(value, l
|
|
848
|
-
checkInheritance(value, opts);
|
|
545
|
+
decorateCtor(value, l);
|
|
546
|
+
if (__DEV__) checkInheritance(value, opts);
|
|
849
547
|
};
|
|
850
548
|
}
|
|
851
549
|
|
|
@@ -862,24 +560,8 @@ function withSigil(Class, label, opts) {
|
|
|
862
560
|
l = label;
|
|
863
561
|
} else l = generateRandomLabel();
|
|
864
562
|
const ctor = Class;
|
|
865
|
-
decorateCtor(ctor, l
|
|
866
|
-
checkInheritance(ctor, opts);
|
|
867
|
-
return Class;
|
|
868
|
-
}
|
|
869
|
-
function typed(Class, label, opts) {
|
|
870
|
-
var _a, _b;
|
|
871
|
-
const devMarker = (_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker;
|
|
872
|
-
if (!isSigilCtor(Class))
|
|
873
|
-
throw new Error(
|
|
874
|
-
`[Sigil Error] 'typed' HOF accept only Sigil classes but used on class ${(_b = Class == null ? void 0 : Class.name) != null ? _b : "unknown"}`
|
|
875
|
-
);
|
|
876
|
-
if (devMarker && label) {
|
|
877
|
-
const runtimeLabel = Class.SigilLabel;
|
|
878
|
-
if (runtimeLabel && runtimeLabel !== label)
|
|
879
|
-
throw new Error(
|
|
880
|
-
`[Sigil Error][typed] runtime label "${runtimeLabel}" does not match asserted label "${label}".`
|
|
881
|
-
);
|
|
882
|
-
}
|
|
563
|
+
decorateCtor(ctor, l);
|
|
564
|
+
if (__DEV__) checkInheritance(ctor, opts);
|
|
883
565
|
return Class;
|
|
884
566
|
}
|
|
885
567
|
function withSigilTyped(Class, label, opts) {
|
|
@@ -894,26 +576,23 @@ function withSigilTyped(Class, label, opts) {
|
|
|
894
576
|
l = label;
|
|
895
577
|
} else l = generateRandomLabel();
|
|
896
578
|
const ctor = Class;
|
|
897
|
-
decorateCtor(ctor, l
|
|
898
|
-
checkInheritance(ctor, opts);
|
|
579
|
+
decorateCtor(ctor, l);
|
|
580
|
+
if (__DEV__) checkInheritance(ctor, opts);
|
|
899
581
|
return Class;
|
|
900
582
|
}
|
|
901
583
|
|
|
902
584
|
exports.DEFAULT_LABEL_REGEX = DEFAULT_LABEL_REGEX;
|
|
903
585
|
exports.Sigil = Sigil;
|
|
904
586
|
exports.SigilError = SigilError;
|
|
905
|
-
exports.SigilRegistry = SigilRegistry;
|
|
906
587
|
exports.Sigilify = Sigilify;
|
|
907
588
|
exports.SigilifyAbstract = SigilifyAbstract;
|
|
908
589
|
exports.WithSigil = WithSigil;
|
|
909
|
-
exports.getActiveRegistry = getActiveRegistry;
|
|
910
590
|
exports.isDecorated = isDecorated;
|
|
911
591
|
exports.isInheritanceChecked = isInheritanceChecked;
|
|
912
592
|
exports.isSigilBaseCtor = isSigilBaseCtor;
|
|
913
593
|
exports.isSigilBaseInstance = isSigilBaseInstance;
|
|
914
594
|
exports.isSigilCtor = isSigilCtor;
|
|
915
595
|
exports.isSigilInstance = isSigilInstance;
|
|
916
|
-
exports.typed = typed;
|
|
917
596
|
exports.updateOptions = updateOptions;
|
|
918
597
|
exports.withSigil = withSigil;
|
|
919
598
|
exports.withSigilTyped = withSigilTyped;
|