@xyo-network/module-resolver 2.107.3 → 2.107.4
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/dist/browser/index.cjs +510 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +489 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +510 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +489 -1
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +522 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +493 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +6 -6
package/dist/neutral/index.js
CHANGED
|
@@ -1,2 +1,490 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/AbstractModuleResolver.ts
|
|
5
|
+
import { assertEx } from "@xylabs/assert";
|
|
6
|
+
import { Base, toJsonString } from "@xylabs/object";
|
|
7
|
+
import { asModuleInstance, ObjectResolverPriority } from "@xyo-network/module-model";
|
|
8
|
+
var AbstractModuleResolver = class extends Base {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "AbstractModuleResolver");
|
|
11
|
+
}
|
|
12
|
+
get priority() {
|
|
13
|
+
return this.params.priority ?? ObjectResolverPriority.Normal;
|
|
14
|
+
}
|
|
15
|
+
set priority(value) {
|
|
16
|
+
this.params.priority = value;
|
|
17
|
+
}
|
|
18
|
+
get root() {
|
|
19
|
+
return assertEx(this.params.root, () => "root is not set");
|
|
20
|
+
}
|
|
21
|
+
async resolve(idOrFilter = "*", options) {
|
|
22
|
+
if (idOrFilter === "*") {
|
|
23
|
+
const values = await this.resolveHandler(idOrFilter, options);
|
|
24
|
+
assertEx(Array.isArray(values), () => "resolveHandler returned a non-array");
|
|
25
|
+
return values.map((value) => asModuleInstance(value, () => {
|
|
26
|
+
return `resolveHandler returned invalid result (*) [${value?.constructor?.name}][${toJsonString(value)}]`;
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
switch (typeof idOrFilter) {
|
|
30
|
+
case "string": {
|
|
31
|
+
const [value] = await this.resolveHandler(idOrFilter, options);
|
|
32
|
+
return asModuleInstance(value, () => (
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
`resolveHandler returned invalid result (string) [${value?.constructor?.name}][${toJsonString(value)}]`
|
|
35
|
+
));
|
|
36
|
+
}
|
|
37
|
+
default: {
|
|
38
|
+
const values = await this.resolveHandler(idOrFilter, options);
|
|
39
|
+
assertEx(Array.isArray(values), () => "resolveHandler returned a non-array");
|
|
40
|
+
return values.map((value) => asModuleInstance(value, () => {
|
|
41
|
+
return `resolveHandler returned invalid result (filter) [${value?.constructor?.name}][${toJsonString(value)}]`;
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async resolvePrivate(id, _options) {
|
|
47
|
+
if (id === "*") return await Promise.resolve([]);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/CompositeModuleResolver.ts
|
|
52
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
53
|
+
import { exists } from "@xylabs/exists";
|
|
54
|
+
import { duplicateModules, ObjectResolverPriority as ObjectResolverPriority2, ResolveHelper } from "@xyo-network/module-model";
|
|
55
|
+
import { LRUCache } from "lru-cache";
|
|
56
|
+
|
|
57
|
+
// src/SimpleModuleResolver.ts
|
|
58
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
59
|
+
import { isAddress } from "@xylabs/hex";
|
|
60
|
+
import { compact } from "@xylabs/lodash";
|
|
61
|
+
import { isAddressModuleFilter, isModuleName, isNameModuleFilter, isQueryModuleFilter } from "@xyo-network/module-model";
|
|
62
|
+
var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
63
|
+
static {
|
|
64
|
+
__name(this, "SimpleModuleResolver");
|
|
65
|
+
}
|
|
66
|
+
modules = {};
|
|
67
|
+
nameToModule = {};
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super(params);
|
|
70
|
+
}
|
|
71
|
+
get allowNameResolution() {
|
|
72
|
+
return this.params.allowNameResolution ?? true;
|
|
73
|
+
}
|
|
74
|
+
add(mods) {
|
|
75
|
+
if (Array.isArray(mods)) {
|
|
76
|
+
for (const mod of mods) this.addSingleModule(mod);
|
|
77
|
+
} else {
|
|
78
|
+
this.addSingleModule(mods);
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
addResolver(_resolver) {
|
|
83
|
+
throw "Adding resolvers not supported";
|
|
84
|
+
}
|
|
85
|
+
remove(address) {
|
|
86
|
+
if (Array.isArray(address)) {
|
|
87
|
+
for (const addr of address) this.removeSingleModule(addr);
|
|
88
|
+
} else {
|
|
89
|
+
this.removeSingleModule(address);
|
|
90
|
+
}
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
removeResolver(_resolver) {
|
|
94
|
+
throw "Removing resolvers not supported";
|
|
95
|
+
}
|
|
96
|
+
resolveHandler(idOrFilter = "*", options) {
|
|
97
|
+
const unfiltered = (() => {
|
|
98
|
+
if (idOrFilter) {
|
|
99
|
+
if (typeof idOrFilter === "string") {
|
|
100
|
+
if (idOrFilter === "*") {
|
|
101
|
+
return Object.values(this.modules);
|
|
102
|
+
}
|
|
103
|
+
const id = idOrFilter;
|
|
104
|
+
const name = isModuleName(id) ? id : void 0;
|
|
105
|
+
const address = isAddress(id) ? id : void 0;
|
|
106
|
+
assertEx2(name || address, () => "module identifier must be a ModuleName or Address");
|
|
107
|
+
return (name ? this.resolveByName(Object.values(this.modules), [
|
|
108
|
+
name
|
|
109
|
+
]).pop() : void 0) ?? (address ? this.resolveByAddress(this.modules, [
|
|
110
|
+
address
|
|
111
|
+
]).pop() : void 0);
|
|
112
|
+
} else {
|
|
113
|
+
const filter = idOrFilter;
|
|
114
|
+
if (isAddressModuleFilter(filter)) {
|
|
115
|
+
return this.resolveByAddress(this.modules, filter.address);
|
|
116
|
+
} else if (isNameModuleFilter(filter)) {
|
|
117
|
+
return this.resolveByName(Object.values(this.modules), filter.name);
|
|
118
|
+
} else if (isQueryModuleFilter(filter)) {
|
|
119
|
+
return this.resolveByQuery(Object.values(this.modules), filter.query);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
return Object.values(this.modules);
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
const identity = options?.identity;
|
|
127
|
+
if (identity) {
|
|
128
|
+
return Array.isArray(unfiltered) ? unfiltered?.filter((module) => identity(module)) : identity(unfiltered) ? [
|
|
129
|
+
unfiltered
|
|
130
|
+
] : [];
|
|
131
|
+
} else {
|
|
132
|
+
return unfiltered ? Array.isArray(unfiltered) ? unfiltered : [
|
|
133
|
+
unfiltered
|
|
134
|
+
] : [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
resolveIdentifier(id, _options) {
|
|
138
|
+
const moduleFromName = this.nameToModule[id];
|
|
139
|
+
if (moduleFromName) {
|
|
140
|
+
return moduleFromName.address;
|
|
141
|
+
}
|
|
142
|
+
for (const module of Object.values(this.modules)) {
|
|
143
|
+
if (module.address === id) {
|
|
144
|
+
return module.address;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
addSingleModule(mod) {
|
|
149
|
+
if (mod) {
|
|
150
|
+
const modName = mod.modName;
|
|
151
|
+
if (modName && this.allowNameResolution) {
|
|
152
|
+
assertEx2(this.nameToModule[modName] === void 0, () => `Module with name ${modName} already added`);
|
|
153
|
+
this.nameToModule[modName] = mod;
|
|
154
|
+
}
|
|
155
|
+
this.modules[mod.address] = mod;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
removeSingleModule(address) {
|
|
159
|
+
assertEx2(isAddress(address), () => "Invalid address");
|
|
160
|
+
const mod = assertEx2(this.modules[address], () => "Address not found in modules");
|
|
161
|
+
delete this.modules[address];
|
|
162
|
+
const modName = mod.modName;
|
|
163
|
+
if (modName) {
|
|
164
|
+
delete this.nameToModule[modName];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
resolveByAddress(modules, address) {
|
|
168
|
+
return compact(address.map((address2) => {
|
|
169
|
+
return modules[address2];
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
resolveByName(modules, name) {
|
|
173
|
+
return compact(name.map((name2) => {
|
|
174
|
+
return modules.find((module) => module.modName === name2);
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
resolveByQuery(modules, query) {
|
|
178
|
+
return compact(modules.filter((module) => query?.reduce((supported, queryList) => {
|
|
179
|
+
return (
|
|
180
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
181
|
+
queryList.reduce((supported2, query2) => {
|
|
182
|
+
const queryable = module.queries.includes(query2);
|
|
183
|
+
return supported2 && queryable;
|
|
184
|
+
}, true) || supported
|
|
185
|
+
);
|
|
186
|
+
}, false)));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/CompositeModuleResolver.ts
|
|
191
|
+
var moduleIdentifierParts = /* @__PURE__ */ __name((moduleIdentifier) => {
|
|
192
|
+
return moduleIdentifier?.split(":");
|
|
193
|
+
}, "moduleIdentifierParts");
|
|
194
|
+
var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractModuleResolver {
|
|
195
|
+
static {
|
|
196
|
+
__name(this, "CompositeModuleResolver");
|
|
197
|
+
}
|
|
198
|
+
static defaultMaxDepth = 3;
|
|
199
|
+
_cache;
|
|
200
|
+
resolvers = [];
|
|
201
|
+
_allowAddResolver = true;
|
|
202
|
+
_localResolver;
|
|
203
|
+
constructor(params) {
|
|
204
|
+
super(params);
|
|
205
|
+
const localResolver = new SimpleModuleResolver({
|
|
206
|
+
allowNameResolution: params.allowNameResolution,
|
|
207
|
+
root: params.root
|
|
208
|
+
});
|
|
209
|
+
this.addResolver(localResolver);
|
|
210
|
+
const {
|
|
211
|
+
max = 100,
|
|
212
|
+
ttl = 1e3 * 5
|
|
213
|
+
/* five seconds */
|
|
214
|
+
} = params.cache ?? {};
|
|
215
|
+
this._cache = new LRUCache({
|
|
216
|
+
max,
|
|
217
|
+
ttl,
|
|
218
|
+
...params.cache
|
|
219
|
+
});
|
|
220
|
+
this._localResolver = localResolver;
|
|
221
|
+
}
|
|
222
|
+
get allowAddResolver() {
|
|
223
|
+
return this._allowAddResolver;
|
|
224
|
+
}
|
|
225
|
+
set allowAddResolver(value) {
|
|
226
|
+
this.resolvers = [
|
|
227
|
+
this._localResolver
|
|
228
|
+
];
|
|
229
|
+
this._allowAddResolver = value;
|
|
230
|
+
}
|
|
231
|
+
get allowNameResolution() {
|
|
232
|
+
return this.params.allowNameResolution ?? true;
|
|
233
|
+
}
|
|
234
|
+
get moduleIdentifierTransformers() {
|
|
235
|
+
return this.params.moduleIdentifierTransformers ?? ResolveHelper.transformers;
|
|
236
|
+
}
|
|
237
|
+
add(module) {
|
|
238
|
+
if (Array.isArray(module)) {
|
|
239
|
+
for (const mod of module) this.addSingleModule(mod);
|
|
240
|
+
} else {
|
|
241
|
+
this.addSingleModule(module);
|
|
242
|
+
}
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
addResolver(resolver) {
|
|
246
|
+
if (this.allowAddResolver) {
|
|
247
|
+
this.resolvers.push(resolver);
|
|
248
|
+
}
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
remove(addresses) {
|
|
252
|
+
if (Array.isArray(addresses)) {
|
|
253
|
+
for (const address of addresses) this.removeSingleModule(address);
|
|
254
|
+
} else {
|
|
255
|
+
this.removeSingleModule(addresses);
|
|
256
|
+
}
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
removeResolver(resolver) {
|
|
260
|
+
this.resolvers = this.resolvers.filter((item) => item !== resolver);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
// eslint-disable-next-line complexity
|
|
264
|
+
async resolveHandler(idOrFilter = "*", options = {}) {
|
|
265
|
+
const mutatedOptions = {
|
|
266
|
+
...options,
|
|
267
|
+
maxDepth: options?.maxDepth ?? _CompositeModuleResolver.defaultMaxDepth
|
|
268
|
+
};
|
|
269
|
+
if (idOrFilter === "*") {
|
|
270
|
+
const all = idOrFilter;
|
|
271
|
+
if (mutatedOptions.maxDepth < 0) {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
if (mutatedOptions.maxDepth === 0) {
|
|
275
|
+
return await this._localResolver.resolve(all, mutatedOptions) ?? [];
|
|
276
|
+
}
|
|
277
|
+
const childOptions = {
|
|
278
|
+
...mutatedOptions,
|
|
279
|
+
maxDepth: mutatedOptions?.maxDepth - 1
|
|
280
|
+
};
|
|
281
|
+
const result = await Promise.all(this.resolvers.map(async (resolver) => {
|
|
282
|
+
const result2 = await resolver.resolve(all, childOptions);
|
|
283
|
+
return result2;
|
|
284
|
+
}));
|
|
285
|
+
const flatResult = result.flat().filter(exists);
|
|
286
|
+
return flatResult.filter(duplicateModules);
|
|
287
|
+
}
|
|
288
|
+
if (typeof idOrFilter === "string") {
|
|
289
|
+
if (mutatedOptions.maxDepth < 0) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
const idParts = moduleIdentifierParts(idOrFilter);
|
|
293
|
+
if (idParts.length > 1) {
|
|
294
|
+
const mod = await this.resolveMultipartIdentifier(idOrFilter);
|
|
295
|
+
return mod ? Array.isArray(mod) ? mod : [
|
|
296
|
+
mod
|
|
297
|
+
] : [];
|
|
298
|
+
}
|
|
299
|
+
const id = await ResolveHelper.transformModuleIdentifier(idOrFilter, this.moduleIdentifierTransformers);
|
|
300
|
+
if (id) {
|
|
301
|
+
if (mutatedOptions.maxDepth < 0) {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
const cachedResult = this._cache.get(id);
|
|
305
|
+
if (cachedResult) {
|
|
306
|
+
if (cachedResult.status === "dead") {
|
|
307
|
+
this._cache.delete(id);
|
|
308
|
+
} else {
|
|
309
|
+
return [
|
|
310
|
+
cachedResult
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (mutatedOptions.maxDepth === 0) {
|
|
315
|
+
const mod2 = await this._localResolver.resolve(idOrFilter, mutatedOptions);
|
|
316
|
+
return mod2 ? Array.isArray(mod2) ? mod2 : [
|
|
317
|
+
mod2
|
|
318
|
+
] : [];
|
|
319
|
+
}
|
|
320
|
+
const resolvePriority = /* @__PURE__ */ __name(async (priority) => {
|
|
321
|
+
const resolvers = this.resolvers.filter((resolver) => resolver.priority === priority);
|
|
322
|
+
const results = (await Promise.all(resolvers.map(async (resolver) => {
|
|
323
|
+
const result2 = await resolver.resolve(id, mutatedOptions);
|
|
324
|
+
return result2;
|
|
325
|
+
}))).filter(exists);
|
|
326
|
+
const result = results.filter(exists).findLast(duplicateModules);
|
|
327
|
+
if (result) {
|
|
328
|
+
this._cache.set(id, result);
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
return priority === ObjectResolverPriority2.VeryLow ? void 0 : await resolvePriority(priority - 1);
|
|
332
|
+
}, "resolvePriority");
|
|
333
|
+
const mod = await resolvePriority(ObjectResolverPriority2.VeryHigh);
|
|
334
|
+
return mod ? Array.isArray(mod) ? mod : [
|
|
335
|
+
mod
|
|
336
|
+
] : [];
|
|
337
|
+
}
|
|
338
|
+
} else if (typeof idOrFilter === "object") {
|
|
339
|
+
if (mutatedOptions.maxDepth < 0) {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
const filter = idOrFilter;
|
|
343
|
+
if (mutatedOptions.maxDepth === 0) {
|
|
344
|
+
return await this._localResolver.resolve(filter, mutatedOptions);
|
|
345
|
+
}
|
|
346
|
+
const childOptions = {
|
|
347
|
+
...mutatedOptions,
|
|
348
|
+
maxDepth: mutatedOptions?.maxDepth - 1
|
|
349
|
+
};
|
|
350
|
+
const result = await Promise.all(this.resolvers.map(async (resolver) => {
|
|
351
|
+
const result2 = await resolver.resolve(filter, childOptions);
|
|
352
|
+
return result2;
|
|
353
|
+
}));
|
|
354
|
+
const flatResult = result.flat().filter(exists);
|
|
355
|
+
return flatResult.filter(duplicateModules);
|
|
356
|
+
}
|
|
357
|
+
return [];
|
|
358
|
+
}
|
|
359
|
+
async resolveIdentifier(id, _options) {
|
|
360
|
+
const idParts = id.split(":");
|
|
361
|
+
if (idParts.length > 1) {
|
|
362
|
+
return this.resolveComplexIdentifier(id);
|
|
363
|
+
}
|
|
364
|
+
const results = (await Promise.all(this.resolvers.map(async (resolver) => {
|
|
365
|
+
const result2 = await resolver.resolveIdentifier(id);
|
|
366
|
+
return result2;
|
|
367
|
+
}))).filter(exists);
|
|
368
|
+
const result = results.shift();
|
|
369
|
+
if (results.length > 0) {
|
|
370
|
+
for (const altResult of results) {
|
|
371
|
+
assertEx3(altResult === result, () => `Inconsistent results for ${id} [${result}][${altResult}]`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
resolveComplexIdentifier(_id, _options) {
|
|
377
|
+
throw new Error("Method not implemented.");
|
|
378
|
+
}
|
|
379
|
+
addSingleModule(module) {
|
|
380
|
+
if (module) {
|
|
381
|
+
this._localResolver.add(module);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
removeSingleModule(address) {
|
|
385
|
+
this._localResolver.remove(address);
|
|
386
|
+
}
|
|
387
|
+
async resolveMultipartIdentifier(moduleIdentifier) {
|
|
388
|
+
const idParts = moduleIdentifierParts(moduleIdentifier);
|
|
389
|
+
assertEx3(idParts.length >= 2, () => "Not a valid multipart identifier");
|
|
390
|
+
const id = assertEx3(idParts.shift());
|
|
391
|
+
const module = await this.resolve(id) ?? await this.resolvePrivate(id);
|
|
392
|
+
return await module?.resolve(idParts.join(":")) ?? await module?.resolvePrivate(idParts.join(":"));
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/NameRegistrarTransformer.ts
|
|
397
|
+
import { PayloadDivinerQuerySchema } from "@xyo-network/diviner-payload-model";
|
|
398
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
399
|
+
var NameRegistrarTransformer = class {
|
|
400
|
+
static {
|
|
401
|
+
__name(this, "NameRegistrarTransformer");
|
|
402
|
+
}
|
|
403
|
+
registrarDiviner;
|
|
404
|
+
root;
|
|
405
|
+
_cache;
|
|
406
|
+
constructor(registrarDiviner, root) {
|
|
407
|
+
this.registrarDiviner = registrarDiviner;
|
|
408
|
+
this.root = root;
|
|
409
|
+
this._cache = new LRUCache2({
|
|
410
|
+
max: 1e3,
|
|
411
|
+
ttl: 1e3 * 5
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
async transform(identifier) {
|
|
415
|
+
const parts = identifier.split(":");
|
|
416
|
+
const first = parts.shift();
|
|
417
|
+
const nameParts = first?.split(".");
|
|
418
|
+
if (nameParts?.length === 2 && nameParts[1] === this.root) {
|
|
419
|
+
const cachedResult = this._cache.get(identifier);
|
|
420
|
+
if (cachedResult) return cachedResult;
|
|
421
|
+
const query = {
|
|
422
|
+
domain: nameParts[0],
|
|
423
|
+
order: "desc",
|
|
424
|
+
schema: PayloadDivinerQuerySchema,
|
|
425
|
+
tld: nameParts[1]
|
|
426
|
+
};
|
|
427
|
+
const result = await this.registrarDiviner?.divine([
|
|
428
|
+
query
|
|
429
|
+
]);
|
|
430
|
+
const resultPayload = result?.shift();
|
|
431
|
+
if (!resultPayload) {
|
|
432
|
+
throw new Error(`Unable to resolve registrar name (failed) [${first}]`);
|
|
433
|
+
}
|
|
434
|
+
if (resultPayload) {
|
|
435
|
+
const address = resultPayload.address?.shift();
|
|
436
|
+
if (address) {
|
|
437
|
+
this._cache.set(identifier, address);
|
|
438
|
+
return address;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
throw new Error(`Unable to resolve registrar name (not found) [${first}]`);
|
|
442
|
+
}
|
|
443
|
+
return identifier;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/ResolverEventEmitter.ts
|
|
448
|
+
var getMixin = /* @__PURE__ */ __name((resolver) => {
|
|
449
|
+
const listeners = [];
|
|
450
|
+
const emit = /* @__PURE__ */ __name((event, args) => {
|
|
451
|
+
if (listeners.length === 0) return false;
|
|
452
|
+
listeners.map((listener) => listener(args));
|
|
453
|
+
return true;
|
|
454
|
+
}, "emit");
|
|
455
|
+
const onModuleResolved = /* @__PURE__ */ __name((module, filter) => {
|
|
456
|
+
const args = {
|
|
457
|
+
filter,
|
|
458
|
+
module
|
|
459
|
+
};
|
|
460
|
+
emit("moduleResolved", args);
|
|
461
|
+
}, "onModuleResolved");
|
|
462
|
+
const { resolve } = resolver;
|
|
463
|
+
function originalResolve(filter) {
|
|
464
|
+
return resolve.bind(resolver)(filter);
|
|
465
|
+
}
|
|
466
|
+
__name(originalResolve, "originalResolve");
|
|
467
|
+
return {
|
|
468
|
+
on: /* @__PURE__ */ __name((event, listener) => {
|
|
469
|
+
listeners.push(listener);
|
|
470
|
+
}, "on"),
|
|
471
|
+
resolve: /* @__PURE__ */ __name(async (filter) => {
|
|
472
|
+
const modules = await originalResolve(filter);
|
|
473
|
+
await Promise.allSettled(modules.map((mod) => onModuleResolved(mod, filter)));
|
|
474
|
+
return modules;
|
|
475
|
+
}, "resolve")
|
|
476
|
+
};
|
|
477
|
+
}, "getMixin");
|
|
478
|
+
var mixinResolverEventEmitter = /* @__PURE__ */ __name((resolver) => {
|
|
479
|
+
const mixin = getMixin(resolver);
|
|
480
|
+
const ret = Object.assign(resolver, mixin);
|
|
481
|
+
return ret;
|
|
482
|
+
}, "mixinResolverEventEmitter");
|
|
483
|
+
export {
|
|
484
|
+
AbstractModuleResolver,
|
|
485
|
+
CompositeModuleResolver,
|
|
486
|
+
NameRegistrarTransformer,
|
|
487
|
+
SimpleModuleResolver,
|
|
488
|
+
mixinResolverEventEmitter
|
|
489
|
+
};
|
|
2
490
|
//# sourceMappingURL=index.js.map
|