@xyo-network/module-resolver
Advanced tools
Comparing version 2.110.19 to 2.111.0
@@ -13,16 +13,16 @@ { | ||
"dependencies": { | ||
"@xylabs/assert": "^3.6.6", | ||
"@xylabs/exists": "^3.6.6", | ||
"@xylabs/hex": "^3.6.6", | ||
"@xylabs/lodash": "^3.6.6", | ||
"@xylabs/object": "^3.6.6", | ||
"@xylabs/promise": "^3.6.6", | ||
"@xyo-network/diviner-model": "^2.110.19", | ||
"@xyo-network/diviner-payload-model": "^2.110.19", | ||
"@xyo-network/module-model": "^2.110.19", | ||
"@xylabs/assert": "^3.6.8", | ||
"@xylabs/exists": "^3.6.8", | ||
"@xylabs/hex": "^3.6.8", | ||
"@xylabs/lodash": "^3.6.8", | ||
"@xylabs/object": "^3.6.8", | ||
"@xylabs/promise": "^3.6.8", | ||
"@xyo-network/diviner-model": "^2.111.0", | ||
"@xyo-network/diviner-payload-model": "^2.111.0", | ||
"@xyo-network/module-model": "^2.111.0", | ||
"lru-cache": "^11.0.0" | ||
}, | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.14.1", | ||
"@xylabs/tsconfig": "^3.14.1", | ||
"@xylabs/ts-scripts-yarn3": "^3.15.5", | ||
"@xylabs/tsconfig": "^3.15.5", | ||
"jest": "^29.7.0", | ||
@@ -43,3 +43,3 @@ "jest-mock-extended": "^3.0.7", | ||
"types": "./dist/browser/index.d.mts", | ||
"default": "./dist/browser/index.js" | ||
"default": "./dist/browser/index.mjs" | ||
} | ||
@@ -54,3 +54,3 @@ }, | ||
"types": "./dist/node/index.d.mts", | ||
"default": "./dist/node/index.js" | ||
"default": "./dist/node/index.mjs" | ||
} | ||
@@ -62,3 +62,3 @@ } | ||
"main": "dist/node/index.cjs", | ||
"module": "dist/node/index.js", | ||
"module": "dist/node/index.mjs", | ||
"homepage": "https://xyo.network", | ||
@@ -74,4 +74,4 @@ "license": "LGPL-3.0-only", | ||
"sideEffects": false, | ||
"version": "2.110.19", | ||
"version": "2.111.0", | ||
"type": "module" | ||
} |
@@ -23,4 +23,3 @@ import { assertEx } from '@xylabs/assert' | ||
extends Base<TParams> | ||
implements ModuleResolverInstance | ||
{ | ||
implements ModuleResolverInstance { | ||
get priority() { | ||
@@ -50,3 +49,3 @@ return this.params.priority ?? ObjectResolverPriority.Normal | ||
assertEx(Array.isArray(values), () => 'resolveHandler returned a non-array') | ||
return values.map((value) => | ||
return values.map(value => | ||
asModuleInstance<T>(value, () => { | ||
@@ -71,3 +70,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
assertEx(Array.isArray(values), () => 'resolveHandler returned a non-array') | ||
return values.map((value) => | ||
return values.map(value => | ||
asModuleInstance<T>(value, () => { | ||
@@ -74,0 +73,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
@@ -38,4 +38,3 @@ /* eslint-disable max-statements */ | ||
extends AbstractModuleResolver<T> | ||
implements ModuleRepository, ModuleResolverInstance | ||
{ | ||
implements ModuleRepository, ModuleResolverInstance { | ||
static defaultMaxDepth = 3 | ||
@@ -102,3 +101,3 @@ | ||
removeResolver(resolver: ModuleResolverInstance): this { | ||
this.resolvers = this.resolvers.filter((item) => item !== resolver) | ||
this.resolvers = this.resolvers.filter(item => item !== resolver) | ||
return this | ||
@@ -114,7 +113,7 @@ } | ||
//resolve all | ||
// resolve all | ||
if (idOrFilter === '*') { | ||
const all = idOrFilter | ||
//wen't too far? | ||
// wen't too far? | ||
if (mutatedOptions.maxDepth < 0) { | ||
@@ -124,3 +123,3 @@ return [] | ||
//identity resolve? | ||
// identity resolve? | ||
if (mutatedOptions.maxDepth === 0) { | ||
@@ -143,3 +142,3 @@ return (await this._localResolver.resolve(all, mutatedOptions)) ?? [] | ||
if (typeof idOrFilter === 'string') { | ||
//wen't too far? | ||
// wen't too far? | ||
if (mutatedOptions.maxDepth < 0) { | ||
@@ -149,3 +148,3 @@ return [] | ||
//resolve ModuleIdentifier | ||
// resolve ModuleIdentifier | ||
const idParts = moduleIdentifierParts(idOrFilter) | ||
@@ -155,7 +154,7 @@ if (idParts.length > 1) { | ||
return ( | ||
mod ? | ||
Array.isArray(mod) ? | ||
mod | ||
: [mod] | ||
: [] | ||
mod | ||
? Array.isArray(mod) | ||
? mod | ||
: [mod] | ||
: [] | ||
) | ||
@@ -177,17 +176,17 @@ } | ||
//identity resolve? | ||
// identity resolve? | ||
if (mutatedOptions.maxDepth === 0) { | ||
const mod = await this._localResolver.resolve(idOrFilter, mutatedOptions) | ||
return ( | ||
mod ? | ||
Array.isArray(mod) ? | ||
mod | ||
: [mod] | ||
: [] | ||
mod | ||
? Array.isArray(mod) | ||
? mod | ||
: [mod] | ||
: [] | ||
) | ||
} | ||
//recursive function to resolve by priority | ||
// recursive function to resolve by priority | ||
const resolvePriority = async (priority: ObjectResolverPriority): Promise<T | undefined> => { | ||
const resolvers = this.resolvers.filter((resolver) => resolver.priority === priority) | ||
const resolvers = this.resolvers.filter(resolver => resolver.priority === priority) | ||
const results: T[] = ( | ||
@@ -211,11 +210,11 @@ await Promise.all( | ||
return ( | ||
mod ? | ||
Array.isArray(mod) ? | ||
mod | ||
: [mod] | ||
: [] | ||
mod | ||
? Array.isArray(mod) | ||
? mod | ||
: [mod] | ||
: [] | ||
) | ||
} | ||
} else if (typeof idOrFilter === 'object') { | ||
//wen't too far? | ||
// wen't too far? | ||
if (mutatedOptions.maxDepth < 0) { | ||
@@ -227,3 +226,3 @@ return [] | ||
//identity resolve? | ||
// identity resolve? | ||
if (mutatedOptions.maxDepth === 0) { | ||
@@ -277,2 +276,3 @@ return await this._localResolver.resolve(filter, mutatedOptions) | ||
} | ||
private removeSingleModule(address: Address) { | ||
@@ -279,0 +279,0 @@ this._localResolver.remove(address) |
@@ -20,7 +20,7 @@ import { Address } from '@xylabs/hex' | ||
if (nameParts?.length === 2 && nameParts[1] === this.root) { | ||
//check cache | ||
// check cache | ||
const cachedResult = this._cache.get(identifier) | ||
if (cachedResult) return cachedResult | ||
//not cached, so check registrar | ||
// not cached, so check registrar | ||
const query = { domain: nameParts[0], order: 'desc' as const, schema: PayloadDivinerQuerySchema, tld: nameParts[1] } | ||
@@ -32,3 +32,3 @@ const result = await this.registrarDiviner?.divine([query]) | ||
} | ||
//TODO: Use proper types for this check | ||
// TODO: Use proper types for this check | ||
if (resultPayload) { | ||
@@ -35,0 +35,0 @@ const address = (resultPayload as unknown as { address: Address[] }).address?.shift() |
@@ -37,3 +37,3 @@ import { Module, ModuleFilter, ModuleResolver } from '@xyo-network/module-model' | ||
const modules: Module[] = await originalResolve(filter) | ||
await Promise.allSettled(modules.map((mod) => onModuleResolved(mod, filter))) | ||
await Promise.allSettled(modules.map(mod => onModuleResolved(mod, filter))) | ||
return modules | ||
@@ -40,0 +40,0 @@ }, |
@@ -81,4 +81,4 @@ import { assertEx } from '@xylabs/assert' | ||
return ( | ||
(name ? this.resolveByName<T>(Object.values(this.modules), [name]).pop() : undefined) ?? | ||
(address ? this.resolveByAddress<T>(this.modules, [address]).pop() : undefined) | ||
(name ? this.resolveByName<T>(Object.values(this.modules), [name]).pop() : undefined) | ||
?? (address ? this.resolveByAddress<T>(this.modules, [address]).pop() : undefined) | ||
) | ||
@@ -102,13 +102,15 @@ } else { | ||
return ( | ||
Array.isArray(unfiltered) ? unfiltered?.filter((mod) => identity(mod)) | ||
: identity(unfiltered) ? [unfiltered] | ||
: [] | ||
Array.isArray(unfiltered) | ||
? unfiltered?.filter(mod => identity(mod)) | ||
: identity(unfiltered) | ||
? [unfiltered] | ||
: [] | ||
) | ||
} else { | ||
return ( | ||
unfiltered ? | ||
Array.isArray(unfiltered) ? | ||
unfiltered | ||
: [unfiltered] | ||
: [] | ||
unfiltered | ||
? Array.isArray(unfiltered) | ||
? unfiltered | ||
: [unfiltered] | ||
: [] | ||
) | ||
@@ -119,3 +121,3 @@ } | ||
resolveIdentifier(id: ModuleIdentifier, _options?: ObjectFilterOptions): Promisable<Address | undefined> { | ||
//check if id is a name of one of modules in the resolver | ||
// check if id is a name of one of modules in the resolver | ||
const moduleFromName = this.nameToModule[id] | ||
@@ -126,3 +128,3 @@ if (moduleFromName) { | ||
//check if any of the modules have the id as an address | ||
// check if any of the modules have the id as an address | ||
for (const mod of Object.values(this.modules)) { | ||
@@ -139,3 +141,3 @@ if (mod.address === id) { | ||
if (modName && this.allowNameResolution) { | ||
//check for collision | ||
// check for collision | ||
assertEx(this.nameToModule[modName] === undefined, () => `Module with name ${modName} already added`) | ||
@@ -169,3 +171,3 @@ this.nameToModule[modName] = mod | ||
name.map((name) => { | ||
return modules.find((mod) => mod.modName === name) | ||
return modules.find(mod => mod.modName === name) | ||
}), | ||
@@ -177,3 +179,3 @@ ) as T[] | ||
return compact( | ||
modules.filter((mod) => | ||
modules.filter(mod => | ||
query?.reduce((supported, queryList) => { | ||
@@ -180,0 +182,0 @@ return ( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
488829
Updated@xylabs/assert@^3.6.8
Updated@xylabs/exists@^3.6.8
Updated@xylabs/hex@^3.6.8
Updated@xylabs/lodash@^3.6.8
Updated@xylabs/object@^3.6.8
Updated@xylabs/promise@^3.6.8