@xyo-network/bridge-pub-sub 2.101.8 → 2.101.9
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/PubSubBridgeModuleResolver.d.cts +2 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.mts +2 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.ts +2 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/browser/index.cjs +34 -33
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +34 -33
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/PubSubBridgeModuleResolver.d.cts +2 -0
- package/dist/neutral/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/neutral/PubSubBridgeModuleResolver.d.mts +2 -0
- package/dist/neutral/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/neutral/PubSubBridgeModuleResolver.d.ts +2 -0
- package/dist/neutral/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/neutral/index.cjs +34 -33
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +34 -33
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.cts +2 -0
- package/dist/node/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.mts +2 -0
- package/dist/node/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.ts +2 -0
- package/dist/node/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/node/index.cjs +35 -34
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +35 -34
- package/dist/node/index.js.map +1 -1
- package/package.json +20 -20
- package/src/PubSubBridgeModuleResolver.ts +27 -26
|
@@ -4,6 +4,7 @@ import { AbstractBridgeModuleResolver, BridgeModuleResolverParams, wrapModuleWit
|
|
|
4
4
|
import { Account } from '@xyo-network/account'
|
|
5
5
|
import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin'
|
|
6
6
|
import { asModuleInstance, ModuleConfig, ModuleConfigSchema, ModuleFilterOptions, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model'
|
|
7
|
+
import { Mutex } from 'async-mutex'
|
|
7
8
|
import { LRUCache } from 'lru-cache'
|
|
8
9
|
|
|
9
10
|
import { AsyncQueryBusClient, AsyncQueryBusModuleProxy, AsyncQueryBusModuleProxyParams } from './AsyncQueryBus'
|
|
@@ -14,6 +15,7 @@ export interface PubSubBridgeModuleResolverParams extends BridgeModuleResolverPa
|
|
|
14
15
|
|
|
15
16
|
export class PubSubBridgeModuleResolver extends AbstractBridgeModuleResolver<PubSubBridgeModuleResolverParams> {
|
|
16
17
|
protected _resolvedCache = new LRUCache<Address, ModuleInstance>({ max: 1000 })
|
|
18
|
+
protected _resolvedCacheMutex = new Mutex()
|
|
17
19
|
|
|
18
20
|
override async resolveHandler<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T[]> {
|
|
19
21
|
const parentResult = await super.resolveHandler(id, options)
|
|
@@ -24,24 +26,24 @@ export class PubSubBridgeModuleResolver extends AbstractBridgeModuleResolver<Pub
|
|
|
24
26
|
const firstPart = idParts.shift()
|
|
25
27
|
assertEx(isAddress(firstPart), () => `Invalid module address: ${firstPart}`)
|
|
26
28
|
const remainderParts = idParts.join(':')
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
const instance: T = await this._resolvedCacheMutex.runExclusive(async () => {
|
|
30
|
+
const cachedMod = this._resolvedCache.get(firstPart as Address)
|
|
31
|
+
if (cachedMod) {
|
|
32
|
+
const result = idParts.length <= 0 ? cachedMod : cachedMod.resolve(remainderParts, { ...options, maxDepth: (options?.maxDepth ?? 5) - 1 })
|
|
33
|
+
return result as T
|
|
34
|
+
}
|
|
35
|
+
const account = Account.randomSync()
|
|
36
|
+
const finalParams: AsyncQueryBusModuleProxyParams = {
|
|
37
|
+
account,
|
|
38
|
+
archiving: this.params.archiving,
|
|
39
|
+
busClient: this.params.busClient,
|
|
40
|
+
config: { schema: ModuleConfigSchema },
|
|
41
|
+
host: this,
|
|
42
|
+
moduleAddress: firstPart as Address,
|
|
43
|
+
onQuerySendFinished: this.params.onQuerySendFinished,
|
|
44
|
+
onQuerySendStarted: this.params.onQuerySendStarted,
|
|
45
|
+
}
|
|
46
|
+
const proxy = new AsyncQueryBusModuleProxy<T, AsyncQueryBusModuleProxyParams>(finalParams)
|
|
45
47
|
const state = await proxy.state()
|
|
46
48
|
if (state) {
|
|
47
49
|
const configSchema = (state.find((payload) => payload.schema === ConfigSchema) as ConfigPayload | undefined)?.config
|
|
@@ -51,14 +53,13 @@ export class PubSubBridgeModuleResolver extends AbstractBridgeModuleResolver<Pub
|
|
|
51
53
|
) as ModuleConfig
|
|
52
54
|
proxy.setConfig(config)
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const result = remainderParts.length > 0 ? await proxy.resolve(remainderParts, options) : instance
|
|
56
|
+
await proxy.start?.()
|
|
57
|
+
const wrapped = wrapModuleWithType(proxy, account) as unknown as T
|
|
58
|
+
assertEx(asModuleInstance<T>(wrapped, {}), () => `Failed to asModuleInstance [${id}]`)
|
|
59
|
+
this._resolvedCache.set(proxy.address, proxy)
|
|
60
|
+
return proxy as ModuleInstance as T
|
|
61
|
+
})
|
|
62
|
+
const result = remainderParts.length > 0 ? await instance.resolve(remainderParts, options) : instance
|
|
62
63
|
return result ? [result] : []
|
|
63
64
|
}
|
|
64
65
|
}
|