@xyo-network/module-resolver 5.3.30 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1679
- package/dist/neutral/CompositeModuleResolver.d.ts.map +1 -1
- package/dist/neutral/ResolveHelper/ResolveHelper.d.ts +26 -0
- package/dist/neutral/ResolveHelper/ResolveHelper.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/ResolveHelperStatic.d.ts +7 -0
- package/dist/neutral/ResolveHelper/ResolveHelperStatic.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/index.d.ts +10 -0
- package/dist/neutral/ResolveHelper/index.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/model.d.ts +2 -0
- package/dist/neutral/ResolveHelper/model.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolveAddressToInstance.d.ts +9 -0
- package/dist/neutral/ResolveHelper/resolveAddressToInstance.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolveAll.d.ts +6 -0
- package/dist/neutral/ResolveHelper/resolveAll.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolveLocalNameToAddress.d.ts +8 -0
- package/dist/neutral/ResolveHelper/resolveLocalNameToAddress.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolveLocalNameToInstance.d.ts +7 -0
- package/dist/neutral/ResolveHelper/resolveLocalNameToInstance.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolvePathToAddress.d.ts +4 -0
- package/dist/neutral/ResolveHelper/resolvePathToAddress.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/resolvePathToInstance.d.ts +3 -0
- package/dist/neutral/ResolveHelper/resolvePathToInstance.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/traceModuleIdentifier.d.ts +4 -0
- package/dist/neutral/ResolveHelper/traceModuleIdentifier.d.ts.map +1 -0
- package/dist/neutral/ResolveHelper/transformModuleIdentifier.d.ts +3 -0
- package/dist/neutral/ResolveHelper/transformModuleIdentifier.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +374 -32
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +21 -25
package/dist/neutral/index.mjs
CHANGED
|
@@ -49,23 +49,345 @@ var AbstractModuleResolver = class extends Base {
|
|
|
49
49
|
|
|
50
50
|
// src/CompositeModuleResolver.ts
|
|
51
51
|
import {
|
|
52
|
-
assertEx as
|
|
53
|
-
exists as
|
|
54
|
-
isDefined,
|
|
55
|
-
isString
|
|
52
|
+
assertEx as assertEx6,
|
|
53
|
+
exists as exists3,
|
|
54
|
+
isDefined as isDefined2,
|
|
55
|
+
isString as isString2
|
|
56
56
|
} from "@xylabs/sdk-js";
|
|
57
57
|
import {
|
|
58
|
-
duplicateModules,
|
|
59
|
-
ObjectResolverPriority as ObjectResolverPriority2
|
|
60
|
-
ResolveHelper
|
|
58
|
+
duplicateModules as duplicateModules3,
|
|
59
|
+
ObjectResolverPriority as ObjectResolverPriority2
|
|
61
60
|
} from "@xyo-network/module-model";
|
|
62
61
|
import { LRUCache } from "lru-cache";
|
|
63
62
|
|
|
64
|
-
// src/
|
|
63
|
+
// src/ResolveHelper/resolveAddressToInstance.ts
|
|
64
|
+
var resolveAddressToInstanceDown = async (root, address, includePrivate = void 0, ignore = []) => {
|
|
65
|
+
if (root.address === address) {
|
|
66
|
+
return root;
|
|
67
|
+
}
|
|
68
|
+
const cache = root.addressCache?.("up", !!includePrivate);
|
|
69
|
+
const privateChildren = (includePrivate ? await root.privateChildren?.() : []) ?? [];
|
|
70
|
+
const publicChildren = await root.publicChildren?.() ?? [];
|
|
71
|
+
const children = [...privateChildren, ...publicChildren];
|
|
72
|
+
for (const child of children) {
|
|
73
|
+
const found = await resolveAddressToInstanceDown(child, address, includePrivate, ignore);
|
|
74
|
+
if (found) {
|
|
75
|
+
cache?.set(address, new WeakRef(found));
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
cache?.set(address, null);
|
|
80
|
+
};
|
|
81
|
+
var resolveAddressToInstanceSiblings = async (root, address, includePrivate = void 0, ignore = []) => {
|
|
82
|
+
const siblings = await root.siblings?.() ?? [];
|
|
83
|
+
for (const sibling of siblings) {
|
|
84
|
+
const found = await resolveAddressToInstanceDown(sibling, address, includePrivate, ignore);
|
|
85
|
+
if (found) {
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var resolveAddressToInstanceUp = async (root, address, includePrivate = void 0, ignore = []) => {
|
|
91
|
+
const cache = root.addressCache?.("up", includePrivate ?? true);
|
|
92
|
+
const parents = await root.parents?.() ?? [];
|
|
93
|
+
for (const parent of parents) {
|
|
94
|
+
const found = await resolveAddressToInstance(parent, address, includePrivate, ignore);
|
|
95
|
+
if (found) {
|
|
96
|
+
cache?.set(address, new WeakRef(found));
|
|
97
|
+
return found;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
cache?.set(address, null);
|
|
101
|
+
};
|
|
102
|
+
var resolveAddressToInstanceAll = async (root, address, includePrivate = void 0, ignore = []) => {
|
|
103
|
+
const cache = root.addressCache?.("all", !!includePrivate);
|
|
104
|
+
const result = await resolveAddressToInstanceDown(root, address, includePrivate ?? false, ignore) ?? await resolveAddressToInstanceUp(root, address, includePrivate ?? true, ignore);
|
|
105
|
+
cache?.set(address, result ? new WeakRef(result) : null);
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
var resolveAddressToInstance = async (root, address, includePrivate = void 0, ignore = [], direction = "all") => {
|
|
109
|
+
switch (direction) {
|
|
110
|
+
case "all": {
|
|
111
|
+
return await resolveAddressToInstanceAll(root, address, includePrivate, ignore);
|
|
112
|
+
}
|
|
113
|
+
case "up": {
|
|
114
|
+
return await resolveAddressToInstanceUp(root, address, includePrivate ?? true, ignore);
|
|
115
|
+
}
|
|
116
|
+
case "down": {
|
|
117
|
+
return await resolveAddressToInstanceDown(root, address, includePrivate ?? false, ignore);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/ResolveHelper/resolveAll.ts
|
|
123
|
+
import { duplicateModules } from "@xyo-network/module-model";
|
|
124
|
+
var resolveAllUp = async (root, maxDepth = 10, exclude = []) => {
|
|
125
|
+
if (maxDepth === 0) {
|
|
126
|
+
return [root].filter((mod) => !exclude.includes(mod.address));
|
|
127
|
+
}
|
|
128
|
+
const parents = (await root.parents()).filter((mod) => !exclude.includes(mod.address));
|
|
129
|
+
return (maxDepth > 1 ? [
|
|
130
|
+
...(await Promise.all(parents.map(async (mod) => await resolveAllUp(mod, maxDepth - 1, [...exclude, root.address])))).flat(),
|
|
131
|
+
...(await Promise.all(parents.map(async (mod) => await resolveAllDown(mod, maxDepth - 1, [...exclude, root.address], true)))).flat(),
|
|
132
|
+
...parents,
|
|
133
|
+
root
|
|
134
|
+
] : [...parents, root]).filter((mod) => !exclude.includes(mod.address)).filter(duplicateModules);
|
|
135
|
+
};
|
|
136
|
+
var resolveAllDown = async (root, maxDepth = 10, exclude = [], includePrivate = false) => {
|
|
137
|
+
if (maxDepth === 0) {
|
|
138
|
+
return [root];
|
|
139
|
+
}
|
|
140
|
+
const children = (await root.publicChildren()).filter((mod) => !exclude.includes(mod.address));
|
|
141
|
+
const privateChildren = includePrivate ? (await root.privateChildren()).filter((mod) => !exclude.includes(mod.address)) : [];
|
|
142
|
+
return (maxDepth > 1 ? [
|
|
143
|
+
...children,
|
|
144
|
+
...(await Promise.all(children.map((child) => resolveAllDown(child, maxDepth - 1, [...exclude, root.address])))).flat(),
|
|
145
|
+
...(await Promise.all(privateChildren.map((child) => resolveAllDown(child, maxDepth - 1, [...exclude, root.address])))).flat(),
|
|
146
|
+
root
|
|
147
|
+
] : [...children, root]).filter((mod) => !exclude.includes(mod.address)).filter(duplicateModules);
|
|
148
|
+
};
|
|
149
|
+
var resolveAll = async (root, maxDepth = 10, exclude = []) => {
|
|
150
|
+
if (maxDepth === 0) {
|
|
151
|
+
return [root];
|
|
152
|
+
}
|
|
153
|
+
return [...await resolveAllUp(root, maxDepth, exclude), ...await resolveAllDown(root, maxDepth, exclude)].filter(duplicateModules);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/ResolveHelper/ResolveHelper.ts
|
|
65
157
|
import {
|
|
66
|
-
assertEx as
|
|
158
|
+
assertEx as assertEx4,
|
|
67
159
|
exists,
|
|
68
|
-
|
|
160
|
+
IdLogger,
|
|
161
|
+
isAddress,
|
|
162
|
+
isDefined,
|
|
163
|
+
isString,
|
|
164
|
+
isTruthy
|
|
165
|
+
} from "@xylabs/sdk-js";
|
|
166
|
+
import { asModuleInstance as asModuleInstance3, duplicateModules as duplicateModules2 } from "@xyo-network/module-model";
|
|
167
|
+
|
|
168
|
+
// src/ResolveHelper/ResolveHelperStatic.ts
|
|
169
|
+
var ResolveHelperStatic = class {
|
|
170
|
+
static defaultLogger;
|
|
171
|
+
static transformers = [];
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/ResolveHelper/resolvePathToInstance.ts
|
|
175
|
+
import { asAddress, assertEx as assertEx2 } from "@xylabs/sdk-js";
|
|
176
|
+
import { MODULE_PATH_SEPARATOR } from "@xyo-network/module-model";
|
|
177
|
+
|
|
178
|
+
// src/ResolveHelper/resolveLocalNameToInstance.ts
|
|
179
|
+
var resolveLocalNameToInstanceUp = async (root, modName) => {
|
|
180
|
+
const parents = await root.parents?.() ?? [];
|
|
181
|
+
return parents.find((parent) => parent.config.name === modName);
|
|
182
|
+
};
|
|
183
|
+
var resolveLocalNameToInstanceDown = async (root, modName, includePrivate = void 0) => {
|
|
184
|
+
const privateChildren = (includePrivate ? await root.privateChildren?.() : []) ?? [];
|
|
185
|
+
const publicChildren = await root.publicChildren?.() ?? [];
|
|
186
|
+
const children = [...privateChildren, ...publicChildren];
|
|
187
|
+
return children.find((child) => child.config.name === modName);
|
|
188
|
+
};
|
|
189
|
+
var resolveLocalNameToInstanceAll = async (root, modName, includePrivate = false) => {
|
|
190
|
+
return await resolveLocalNameToInstanceDown(root, modName, includePrivate) ?? await resolveLocalNameToInstanceUp(root, modName);
|
|
191
|
+
};
|
|
192
|
+
var resolveLocalNameToInstance = async (root, modName, includePrivate = false, direction = "all") => {
|
|
193
|
+
switch (direction) {
|
|
194
|
+
case "all": {
|
|
195
|
+
return await resolveLocalNameToInstanceAll(root, modName, includePrivate);
|
|
196
|
+
}
|
|
197
|
+
case "up": {
|
|
198
|
+
return await resolveLocalNameToInstanceUp(root, modName);
|
|
199
|
+
}
|
|
200
|
+
case "down": {
|
|
201
|
+
return await resolveLocalNameToInstanceDown(root, modName, includePrivate);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/ResolveHelper/resolveLocalNameToAddress.ts
|
|
207
|
+
var resolveLocalNameToAddressUp = async (root, modName) => {
|
|
208
|
+
return (await resolveLocalNameToInstanceUp(root, modName))?.address;
|
|
209
|
+
};
|
|
210
|
+
var resolveLocalNameToAddressDown = async (root, modName, includePrivate = void 0) => {
|
|
211
|
+
return (await resolveLocalNameToInstanceDown(root, modName, includePrivate))?.address;
|
|
212
|
+
};
|
|
213
|
+
var resolveLocalNameToAddressAll = async (root, modName, includePrivate = void 0) => {
|
|
214
|
+
return (await resolveLocalNameToInstanceAll(root, modName, includePrivate))?.address;
|
|
215
|
+
};
|
|
216
|
+
var resolveLocalNameToAddress = async (root, modName, includePrivate = void 0, direction = "all") => {
|
|
217
|
+
return (await resolveLocalNameToInstance(root, modName, includePrivate, direction))?.address;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/ResolveHelper/transformModuleIdentifier.ts
|
|
221
|
+
var transformModuleIdentifier = async (id, transformers) => {
|
|
222
|
+
let result = id;
|
|
223
|
+
for (const transformer of transformers) {
|
|
224
|
+
result = await transformer.transform(id);
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// src/ResolveHelper/resolvePathToInstance.ts
|
|
230
|
+
var resolvePathToInstance = async (root, path, includePrivate = void 0, transformers = ResolveHelperStatic.transformers) => {
|
|
231
|
+
const parts = path.split(MODULE_PATH_SEPARATOR);
|
|
232
|
+
const first = await transformModuleIdentifier(
|
|
233
|
+
assertEx2(parts.shift(), () => `First part is invalid [${path}]`),
|
|
234
|
+
transformers
|
|
235
|
+
);
|
|
236
|
+
if (!first) {
|
|
237
|
+
return void 0;
|
|
238
|
+
}
|
|
239
|
+
const firstAddress = asAddress(first) ?? await resolveLocalNameToAddress(root, first, includePrivate);
|
|
240
|
+
if (firstAddress) {
|
|
241
|
+
const firstModule = await resolveAddressToInstance(root, firstAddress, includePrivate);
|
|
242
|
+
if (firstModule && parts.length > 0) {
|
|
243
|
+
return resolvePathToInstance(firstModule, parts.join(MODULE_PATH_SEPARATOR));
|
|
244
|
+
}
|
|
245
|
+
return firstModule;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/ResolveHelper/resolvePathToAddress.ts
|
|
250
|
+
var resolvePathToAddress = async (root, path, includePrivate = void 0, transformers = ResolveHelperStatic.transformers) => {
|
|
251
|
+
return (await resolvePathToInstance(root, path, includePrivate, transformers))?.address;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// src/ResolveHelper/traceModuleIdentifier.ts
|
|
255
|
+
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
256
|
+
import { asModuleInstance as asModuleInstance2 } from "@xyo-network/module-model";
|
|
257
|
+
var traceModuleIdentifier = async (resolver, path) => {
|
|
258
|
+
const parts = path.split(":");
|
|
259
|
+
const first = parts.shift();
|
|
260
|
+
const firstModule = asModuleInstance2(
|
|
261
|
+
assertEx3(await resolver.resolve(first, { maxDepth: 1 }), () => `Failed to resolve [${first}]`),
|
|
262
|
+
() => `Resolved invalid module instance [${first}]`
|
|
263
|
+
);
|
|
264
|
+
if (firstModule) {
|
|
265
|
+
return parts.length > 0 ? [firstModule.address, ...await traceModuleIdentifier(firstModule, parts.join(":"))] : [firstModule.address];
|
|
266
|
+
}
|
|
267
|
+
return [];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// src/ResolveHelper/ResolveHelper.ts
|
|
271
|
+
var ResolveHelper = class _ResolveHelper extends ResolveHelperStatic {
|
|
272
|
+
static async resolve(config, id = "*", {
|
|
273
|
+
maxDepth = 3,
|
|
274
|
+
required = "log",
|
|
275
|
+
...options
|
|
276
|
+
} = {}) {
|
|
277
|
+
const {
|
|
278
|
+
transformers,
|
|
279
|
+
mod,
|
|
280
|
+
logger = this.defaultLogger,
|
|
281
|
+
dead = false,
|
|
282
|
+
upResolver,
|
|
283
|
+
downResolver,
|
|
284
|
+
privateResolver
|
|
285
|
+
} = config;
|
|
286
|
+
const log = logger ? new IdLogger(logger, () => `ResolveHelper [${mod.id}][${id}]`) : void 0;
|
|
287
|
+
const downLocalOptions = {
|
|
288
|
+
...options,
|
|
289
|
+
direction: "down",
|
|
290
|
+
maxDepth,
|
|
291
|
+
required: false
|
|
292
|
+
};
|
|
293
|
+
const upLocalOptions = { ...downLocalOptions, direction: "up" };
|
|
294
|
+
const childOptions = {
|
|
295
|
+
...options,
|
|
296
|
+
maxDepth: maxDepth - 1,
|
|
297
|
+
required: false
|
|
298
|
+
};
|
|
299
|
+
const direction = options?.direction ?? "all";
|
|
300
|
+
const up = direction === "up" || direction === "all";
|
|
301
|
+
const down = direction === "down" || direction === "all";
|
|
302
|
+
let result;
|
|
303
|
+
log?.debug("start", id, maxDepth);
|
|
304
|
+
if (id === "*") {
|
|
305
|
+
if (dead) {
|
|
306
|
+
log?.warn("failed [dead]", id);
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
const modules = [
|
|
310
|
+
...down ? await downResolver.resolve("*", downLocalOptions) : [],
|
|
311
|
+
...up ? await upResolver.resolve("*", upLocalOptions) : []
|
|
312
|
+
].filter(duplicateModules2);
|
|
313
|
+
if (modules.length > 0) {
|
|
314
|
+
log?.debug("modules [count]", modules.length);
|
|
315
|
+
}
|
|
316
|
+
if (maxDepth === 0) {
|
|
317
|
+
return modules;
|
|
318
|
+
}
|
|
319
|
+
const childModules = (await Promise.all(modules.map(async (mod2) => await mod2.resolve("*", childOptions)))).flat().filter(duplicateModules2);
|
|
320
|
+
return [...modules, ...childModules, mod].filter(duplicateModules2);
|
|
321
|
+
} else {
|
|
322
|
+
switch (typeof id) {
|
|
323
|
+
case "string": {
|
|
324
|
+
if (dead) {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
const resolvedId = assertEx4(await resolvePathToAddress(mod, id, false, transformers) ?? id, () => "Invalid resolvedId");
|
|
328
|
+
const resolvers = [
|
|
329
|
+
[downResolver, downLocalOptions],
|
|
330
|
+
[up ? upResolver : void 0, upLocalOptions],
|
|
331
|
+
[up ? privateResolver : void 0, upLocalOptions]
|
|
332
|
+
].filter(([resolver]) => exists(resolver));
|
|
333
|
+
for (const resolver of resolvers) {
|
|
334
|
+
const [resolverInstance] = resolver;
|
|
335
|
+
if (!result) {
|
|
336
|
+
result = await this.resolveModuleIdentifier(resolverInstance, resolvedId);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
default: {
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
this.validateRequiredResolve(required, result, id, logger);
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
// resolves a complex module path to addresses
|
|
350
|
+
static async resolveModuleIdentifier(resolver, path, required) {
|
|
351
|
+
const parts = path.split(":");
|
|
352
|
+
const first = parts.shift();
|
|
353
|
+
const firstIsAddress = isAddress(first);
|
|
354
|
+
const resolvedModule = await resolver.resolve(first, { maxDepth: firstIsAddress ? 10 : 1 }) ?? (isString(first) ? await resolver.resolvePrivate(first, { maxDepth: firstIsAddress ? 10 : 1 }) : void 0);
|
|
355
|
+
const finalModule = required ? assertEx4(resolvedModule, () => `Failed to resolve [${first}] [${firstIsAddress}]`) : resolvedModule;
|
|
356
|
+
const firstModule = asModuleInstance3(finalModule, () => `Resolved invalid module instance [${first}]`);
|
|
357
|
+
return isDefined(firstModule) ? parts.length > 0 ? await this.resolveModuleIdentifier(firstModule, parts.join(":")) : firstModule : void 0;
|
|
358
|
+
}
|
|
359
|
+
// translates a complex module path to addresses
|
|
360
|
+
static traceModuleIdentifier(resolver, path) {
|
|
361
|
+
return traceModuleIdentifier(resolver, path);
|
|
362
|
+
}
|
|
363
|
+
static transformModuleIdentifier(identifier, transformers = _ResolveHelper.transformers) {
|
|
364
|
+
return transformModuleIdentifier(identifier, transformers);
|
|
365
|
+
}
|
|
366
|
+
static validateRequiredResolve(required, result, id, logger = this.defaultLogger) {
|
|
367
|
+
const log = logger ? new IdLogger(logger, () => `validateRequiredResolve [${id}][${result}]`) : void 0;
|
|
368
|
+
if (isTruthy(required) && (result === void 0 || Array.isArray(result) && result.length > 0)) {
|
|
369
|
+
switch (required) {
|
|
370
|
+
case "warn": {
|
|
371
|
+
log?.warn("resolve failed", id);
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
case "log": {
|
|
375
|
+
log?.log("resolve failed", id);
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
default: {
|
|
379
|
+
throw new Error(`resolve failed [${id}]`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/SimpleModuleResolver.ts
|
|
387
|
+
import {
|
|
388
|
+
assertEx as assertEx5,
|
|
389
|
+
exists as exists2,
|
|
390
|
+
isAddress as isAddress2
|
|
69
391
|
} from "@xylabs/sdk-js";
|
|
70
392
|
import { isModuleName } from "@xyo-network/module-model";
|
|
71
393
|
var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
@@ -107,8 +429,8 @@ var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
|
107
429
|
return Object.values(this.modules);
|
|
108
430
|
}
|
|
109
431
|
const name = isModuleName(id) ? id : void 0;
|
|
110
|
-
const address =
|
|
111
|
-
|
|
432
|
+
const address = isAddress2(id) ? id : void 0;
|
|
433
|
+
assertEx5(name || address, () => "module identifier must be a ModuleName or Address");
|
|
112
434
|
return (name ? this.resolveByName(Object.values(this.modules), [name]).pop() : void 0) ?? (address ? this.resolveByAddress(this.modules, [address]).pop() : void 0);
|
|
113
435
|
}
|
|
114
436
|
} else {
|
|
@@ -137,15 +459,15 @@ var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
|
137
459
|
if (mod) {
|
|
138
460
|
const modName = mod.modName;
|
|
139
461
|
if (modName && this.allowNameResolution) {
|
|
140
|
-
|
|
462
|
+
assertEx5(this.nameToModule[modName] === void 0, () => `Module with name ${modName} already added`);
|
|
141
463
|
this.nameToModule[modName] = mod;
|
|
142
464
|
}
|
|
143
465
|
this.modules[mod.address] = mod;
|
|
144
466
|
}
|
|
145
467
|
}
|
|
146
468
|
removeSingleModule(address) {
|
|
147
|
-
|
|
148
|
-
const mod =
|
|
469
|
+
assertEx5(isAddress2(address), () => "Invalid address");
|
|
470
|
+
const mod = assertEx5(this.modules[address], () => "Address not found in modules");
|
|
149
471
|
delete this.modules[address];
|
|
150
472
|
const modName = mod.modName;
|
|
151
473
|
if (modName) {
|
|
@@ -155,12 +477,12 @@ var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
|
155
477
|
resolveByAddress(modules, address) {
|
|
156
478
|
return address.map((address2) => {
|
|
157
479
|
return modules[address2];
|
|
158
|
-
}).filter(
|
|
480
|
+
}).filter(exists2);
|
|
159
481
|
}
|
|
160
482
|
resolveByName(modules, name) {
|
|
161
483
|
return name.map((name2) => {
|
|
162
484
|
return modules.find((mod) => mod.modName === name2);
|
|
163
|
-
}).filter(
|
|
485
|
+
}).filter(exists2);
|
|
164
486
|
}
|
|
165
487
|
resolveByQuery(modules, query) {
|
|
166
488
|
return modules.filter((mod) => (
|
|
@@ -174,7 +496,7 @@ var SimpleModuleResolver = class extends AbstractModuleResolver {
|
|
|
174
496
|
}, true) || supported
|
|
175
497
|
);
|
|
176
498
|
}, false)
|
|
177
|
-
)).filter(
|
|
499
|
+
)).filter(exists2);
|
|
178
500
|
}
|
|
179
501
|
};
|
|
180
502
|
|
|
@@ -260,8 +582,8 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
260
582
|
return result2;
|
|
261
583
|
})
|
|
262
584
|
);
|
|
263
|
-
const flatResult = result.flat().filter(
|
|
264
|
-
return flatResult.filter((v, i, a) =>
|
|
585
|
+
const flatResult = result.flat().filter(exists3);
|
|
586
|
+
return flatResult.filter((v, i, a) => duplicateModules3(v, i, a));
|
|
265
587
|
}
|
|
266
588
|
if (typeof id === "string") {
|
|
267
589
|
if (mutatedOptions.maxDepth < 0) {
|
|
@@ -273,7 +595,7 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
273
595
|
return mod ? Array.isArray(mod) ? mod : [mod] : [];
|
|
274
596
|
}
|
|
275
597
|
const resolvedId = await ResolveHelper.transformModuleIdentifier(id, this.moduleIdentifierTransformers);
|
|
276
|
-
if (
|
|
598
|
+
if (isString2(resolvedId)) {
|
|
277
599
|
if (mutatedOptions.maxDepth < 0) {
|
|
278
600
|
return [];
|
|
279
601
|
}
|
|
@@ -287,7 +609,7 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
287
609
|
}
|
|
288
610
|
if (mutatedOptions.maxDepth === 0) {
|
|
289
611
|
const mod2 = await this._localResolver.resolve(resolvedId, mutatedOptions);
|
|
290
|
-
return
|
|
612
|
+
return isDefined2(mod2) ? Array.isArray(mod2) ? mod2 : [mod2] : [];
|
|
291
613
|
}
|
|
292
614
|
const resolvePriority = async (priority) => {
|
|
293
615
|
const resolvers = this.resolvers.filter((resolver) => resolver.priority === priority);
|
|
@@ -296,8 +618,8 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
296
618
|
const result2 = await resolver.resolve(resolvedId, mutatedOptions);
|
|
297
619
|
return result2;
|
|
298
620
|
})
|
|
299
|
-
)).filter(
|
|
300
|
-
const result = results.filter(
|
|
621
|
+
)).filter(exists3);
|
|
622
|
+
const result = results.filter(exists3).findLast((v, i, a) => duplicateModules3(v, i, a));
|
|
301
623
|
if (result) {
|
|
302
624
|
this._cache.set(resolvedId, result);
|
|
303
625
|
return result;
|
|
@@ -319,11 +641,11 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
319
641
|
this.resolvers.map(async (resolver) => {
|
|
320
642
|
return await resolver.resolveIdentifier(id);
|
|
321
643
|
})
|
|
322
|
-
)).filter(
|
|
644
|
+
)).filter(exists3);
|
|
323
645
|
const result = results.shift();
|
|
324
646
|
if (results.length > 0) {
|
|
325
647
|
for (const altResult of results) {
|
|
326
|
-
|
|
648
|
+
assertEx6(altResult === result, () => `Inconsistent results for ${id} [${result}][${altResult}]`);
|
|
327
649
|
}
|
|
328
650
|
}
|
|
329
651
|
return result;
|
|
@@ -341,15 +663,15 @@ var CompositeModuleResolver = class _CompositeModuleResolver extends AbstractMod
|
|
|
341
663
|
}
|
|
342
664
|
async resolveMultipartIdentifier(moduleIdentifier) {
|
|
343
665
|
const idParts = moduleIdentifierParts(moduleIdentifier);
|
|
344
|
-
|
|
345
|
-
const id =
|
|
666
|
+
assertEx6(idParts.length >= 2, () => "Not a valid multipart identifier");
|
|
667
|
+
const id = assertEx6(idParts.shift());
|
|
346
668
|
const mod = await this.resolve(id) ?? await this.resolvePrivate(id);
|
|
347
669
|
return await mod?.resolve(idParts.join(":")) ?? await mod?.resolvePrivate(idParts.join(":"));
|
|
348
670
|
}
|
|
349
671
|
};
|
|
350
672
|
|
|
351
673
|
// src/NameRegistrarTransformer.ts
|
|
352
|
-
import { isDefined as
|
|
674
|
+
import { isDefined as isDefined3, isUndefined } from "@xylabs/sdk-js";
|
|
353
675
|
import { PayloadDivinerQuerySchema } from "@xyo-network/diviner-payload-model";
|
|
354
676
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
355
677
|
var NameRegistrarTransformer = class {
|
|
@@ -366,7 +688,7 @@ var NameRegistrarTransformer = class {
|
|
|
366
688
|
const nameParts = first?.split(".");
|
|
367
689
|
if (nameParts?.length === 2 && nameParts[1] === this.root) {
|
|
368
690
|
const cachedResult = this._cache.get(identifier);
|
|
369
|
-
if (
|
|
691
|
+
if (isDefined3(cachedResult)) return cachedResult;
|
|
370
692
|
const query = {
|
|
371
693
|
domain: nameParts[0],
|
|
372
694
|
order: "desc",
|
|
@@ -378,7 +700,7 @@ var NameRegistrarTransformer = class {
|
|
|
378
700
|
if (isUndefined(resultPayload)) {
|
|
379
701
|
throw new Error(`Unable to resolve registrar name (failed) [${first}]`);
|
|
380
702
|
}
|
|
381
|
-
if (
|
|
703
|
+
if (isDefined3(resultPayload)) {
|
|
382
704
|
const address = resultPayload.address?.shift();
|
|
383
705
|
if (address) {
|
|
384
706
|
this._cache.set(identifier, address);
|
|
@@ -427,7 +749,27 @@ export {
|
|
|
427
749
|
AbstractModuleResolver,
|
|
428
750
|
CompositeModuleResolver,
|
|
429
751
|
NameRegistrarTransformer,
|
|
752
|
+
ResolveHelper,
|
|
430
753
|
SimpleModuleResolver,
|
|
431
|
-
mixinResolverEventEmitter
|
|
754
|
+
mixinResolverEventEmitter,
|
|
755
|
+
resolveAddressToInstance,
|
|
756
|
+
resolveAddressToInstanceAll,
|
|
757
|
+
resolveAddressToInstanceDown,
|
|
758
|
+
resolveAddressToInstanceSiblings,
|
|
759
|
+
resolveAddressToInstanceUp,
|
|
760
|
+
resolveAll,
|
|
761
|
+
resolveAllDown,
|
|
762
|
+
resolveAllUp,
|
|
763
|
+
resolveLocalNameToAddress,
|
|
764
|
+
resolveLocalNameToAddressAll,
|
|
765
|
+
resolveLocalNameToAddressDown,
|
|
766
|
+
resolveLocalNameToAddressUp,
|
|
767
|
+
resolveLocalNameToInstance,
|
|
768
|
+
resolveLocalNameToInstanceAll,
|
|
769
|
+
resolveLocalNameToInstanceDown,
|
|
770
|
+
resolveLocalNameToInstanceUp,
|
|
771
|
+
resolvePathToAddress,
|
|
772
|
+
resolvePathToInstance,
|
|
773
|
+
transformModuleIdentifier
|
|
432
774
|
};
|
|
433
775
|
//# sourceMappingURL=index.mjs.map
|