@xyo-network/bridge-worker 5.3.22 → 5.3.24
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/package.json +34 -38
- package/src/WorkerBridge.ts +0 -122
- package/src/WorkerBridgeConfig.ts +0 -8
- package/src/defaultNodeManifest.ts +0 -41
- package/src/docsEntry.ts +0 -4
- package/src/index.ts +0 -4
- package/src/tsconfig.json +0 -4
- package/src/worker/Worker.ts +0 -3
- package/src/worker/WorkerNodeHost.ts +0 -103
- package/src/worker/index.ts +0 -1
- package/src/worker/tsconfig.json +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/bridge-worker",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.24",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src",
|
|
34
33
|
"!**/*.bench.*",
|
|
35
34
|
"!**/*.spec.*",
|
|
36
35
|
"!**/*.test.*",
|
|
@@ -38,51 +37,48 @@
|
|
|
38
37
|
],
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"@scure/bip39": "~2.0.1",
|
|
41
|
-
"
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/bridge-
|
|
45
|
-
"@xyo-network/manifest": "~5.3.
|
|
46
|
-
"@xyo-network/manifest-model": "~5.3.
|
|
47
|
-
"@xyo-network/module-
|
|
48
|
-
"@xyo-network/module-
|
|
49
|
-
"@xyo-network/
|
|
50
|
-
"@xyo-network/
|
|
51
|
-
"@xyo-network/sentinel-model": "~5.3.
|
|
52
|
-
"@xyo-network/wallet": "~5.3.
|
|
53
|
-
"
|
|
40
|
+
"lru-cache": "~11.2.7",
|
|
41
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
42
|
+
"@xyo-network/boundwitness-model": "~5.3.24",
|
|
43
|
+
"@xyo-network/bridge-abstract": "~5.3.24",
|
|
44
|
+
"@xyo-network/manifest": "~5.3.24",
|
|
45
|
+
"@xyo-network/manifest-model": "~5.3.24",
|
|
46
|
+
"@xyo-network/module-model": "~5.3.24",
|
|
47
|
+
"@xyo-network/module-factory-locator": "~5.3.24",
|
|
48
|
+
"@xyo-network/bridge-model": "~5.3.24",
|
|
49
|
+
"@xyo-network/node-model": "~5.3.24",
|
|
50
|
+
"@xyo-network/sentinel-model": "~5.3.24",
|
|
51
|
+
"@xyo-network/wallet": "~5.3.24",
|
|
52
|
+
"@xyo-network/payload-model": "~5.3.24"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
55
|
"@opentelemetry/api": "^1.9.1",
|
|
57
56
|
"@scure/bip39": "~2.0.1",
|
|
58
57
|
"@types/node": "^25.5.0",
|
|
59
|
-
"@xylabs/sdk-js": "^5.0.
|
|
60
|
-
"@xylabs/ts-scripts-common": "~7.6.
|
|
61
|
-
"@xylabs/ts-scripts-
|
|
62
|
-
"@xylabs/tsconfig": "~7.6.
|
|
63
|
-
"@xyo-network/archivist-model": "~5.3.22",
|
|
64
|
-
"@xyo-network/boundwitness-model": "~5.3.22",
|
|
65
|
-
"@xyo-network/bridge-abstract": "~5.3.22",
|
|
66
|
-
"@xyo-network/bridge-model": "~5.3.22",
|
|
67
|
-
"@xyo-network/manifest": "~5.3.22",
|
|
68
|
-
"@xyo-network/manifest-model": "~5.3.22",
|
|
69
|
-
"@xyo-network/module-factory-locator": "~5.3.22",
|
|
70
|
-
"@xyo-network/module-model": "~5.3.22",
|
|
71
|
-
"@xyo-network/node-model": "~5.3.22",
|
|
72
|
-
"@xyo-network/payload-model": "~5.3.22",
|
|
73
|
-
"@xyo-network/sentinel-model": "~5.3.22",
|
|
74
|
-
"@xyo-network/wallet": "~5.3.22",
|
|
58
|
+
"@xylabs/sdk-js": "^5.0.93",
|
|
59
|
+
"@xylabs/ts-scripts-common": "~7.6.16",
|
|
60
|
+
"@xylabs/ts-scripts-pnpm": "~7.6.16",
|
|
61
|
+
"@xylabs/tsconfig": "~7.6.16",
|
|
75
62
|
"acorn": "^8.16.0",
|
|
76
63
|
"axios": "^1.14.0",
|
|
77
|
-
"
|
|
78
|
-
"esbuild": "^0.27.4",
|
|
79
|
-
"eslint": "^10.1.0",
|
|
64
|
+
"esbuild": "^0.28.0",
|
|
80
65
|
"ethers": "^6.16.0",
|
|
81
|
-
"lru-cache": "
|
|
82
|
-
"rollup": "^4.60.1",
|
|
66
|
+
"lru-cache": "~11.2.7",
|
|
83
67
|
"tslib": "^2.8.1",
|
|
84
68
|
"typescript": "~5.9.3",
|
|
85
|
-
"zod": "^4.3.6"
|
|
69
|
+
"zod": "^4.3.6",
|
|
70
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
71
|
+
"@xyo-network/manifest": "~5.3.24",
|
|
72
|
+
"@xyo-network/bridge-abstract": "~5.3.24",
|
|
73
|
+
"@xyo-network/manifest-model": "~5.3.24",
|
|
74
|
+
"@xyo-network/bridge-model": "~5.3.24",
|
|
75
|
+
"@xyo-network/boundwitness-model": "~5.3.24",
|
|
76
|
+
"@xyo-network/module-factory-locator": "~5.3.24",
|
|
77
|
+
"@xyo-network/node-model": "~5.3.24",
|
|
78
|
+
"@xyo-network/payload-model": "~5.3.24",
|
|
79
|
+
"@xyo-network/module-model": "~5.3.24",
|
|
80
|
+
"@xyo-network/sentinel-model": "~5.3.24",
|
|
81
|
+
"@xyo-network/wallet": "~5.3.24"
|
|
86
82
|
},
|
|
87
83
|
"peerDependencies": {
|
|
88
84
|
"@xylabs/sdk-js": "^5",
|
|
@@ -93,4 +89,4 @@
|
|
|
93
89
|
"publishConfig": {
|
|
94
90
|
"access": "public"
|
|
95
91
|
}
|
|
96
|
-
}
|
|
92
|
+
}
|
package/src/WorkerBridge.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address, assertEx, Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
|
-
import { AbstractBridge } from '@xyo-network/bridge-abstract'
|
|
6
|
-
import {
|
|
7
|
-
BridgeExposeOptions, BridgeModule, BridgeUnexposeOptions,
|
|
8
|
-
} from '@xyo-network/bridge-model'
|
|
9
|
-
import { PackageManifestPayload } from '@xyo-network/manifest-model'
|
|
10
|
-
import {
|
|
11
|
-
AnyConfigSchema,
|
|
12
|
-
CacheConfig,
|
|
13
|
-
creatableModule,
|
|
14
|
-
ModuleConfig,
|
|
15
|
-
ModuleInstance,
|
|
16
|
-
ModuleQueryResult,
|
|
17
|
-
QueryableModuleParams,
|
|
18
|
-
} from '@xyo-network/module-model'
|
|
19
|
-
import { Payload, Schema } from '@xyo-network/payload-model'
|
|
20
|
-
import { LRUCache } from 'lru-cache'
|
|
21
|
-
|
|
22
|
-
import { defaultPackageManifest } from './defaultNodeManifest.ts'
|
|
23
|
-
import { WorkerBridgeConfig, WorkerBridgeConfigSchema } from './WorkerBridgeConfig.ts'
|
|
24
|
-
|
|
25
|
-
export interface WorkerBridgeParams<TConfig extends AnyConfigSchema<WorkerBridgeConfig> = AnyConfigSchema<WorkerBridgeConfig>> extends QueryableModuleParams<
|
|
26
|
-
TConfig
|
|
27
|
-
> {
|
|
28
|
-
worker?: Worker
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface Message<T extends string = string> {
|
|
32
|
-
type: T
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface QueryMessage extends Message<'xyoQuery'> {
|
|
36
|
-
address: Address
|
|
37
|
-
msgId?: string
|
|
38
|
-
payloads?: Payload[]
|
|
39
|
-
query: QueryBoundWitness
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface QueryResultMessage {
|
|
43
|
-
address: Address
|
|
44
|
-
msgId?: string
|
|
45
|
-
result: ModuleQueryResult
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@creatableModule()
|
|
49
|
-
export class WorkerBridge<TParams extends WorkerBridgeParams = WorkerBridgeParams> extends AbstractBridge<TParams> implements BridgeModule<TParams> {
|
|
50
|
-
static override readonly configSchemas: Schema[] = [...super.configSchemas, WorkerBridgeConfigSchema]
|
|
51
|
-
static override readonly defaultConfigSchema: Schema = WorkerBridgeConfigSchema
|
|
52
|
-
|
|
53
|
-
private _discoverCache?: LRUCache<string, Payload[]>
|
|
54
|
-
private _targetConfigs: Record<string, ModuleConfig> = {}
|
|
55
|
-
private _targetQueries: Record<string, string[]> = {}
|
|
56
|
-
|
|
57
|
-
get discoverCache() {
|
|
58
|
-
const config = this.discoverCacheConfig
|
|
59
|
-
this._discoverCache = this._discoverCache ?? new LRUCache<string, Payload[]>({ ttlAutopurge: true, ...config })
|
|
60
|
-
return this._discoverCache
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get discoverCacheConfig(): LRUCache.Options<string, Payload[], unknown> {
|
|
64
|
-
const discoverCacheConfig: CacheConfig | undefined = {}
|
|
65
|
-
return {
|
|
66
|
-
max: 100, ttl: 1000 * 60 * 5, ...discoverCacheConfig,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get worker(): Worker {
|
|
71
|
-
return assertEx(this.params.worker)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static async createWorkerNode(manifest: PackageManifestPayload = defaultPackageManifest as PackageManifestPayload) {
|
|
75
|
-
const worker = new Worker(new URL('worker/Worker.ts', import.meta?.url ?? __filename))
|
|
76
|
-
worker.postMessage({ manifest, type: 'createNode' })
|
|
77
|
-
|
|
78
|
-
await new Promise((resolve, reject) => {
|
|
79
|
-
const eventFunc = (event: MessageEvent) => {
|
|
80
|
-
const timeout = setTimeout(() => {
|
|
81
|
-
console.log('Node creation timeout')
|
|
82
|
-
worker.removeEventListener('message', eventFunc)
|
|
83
|
-
reject('Timeout')
|
|
84
|
-
}, 1000)
|
|
85
|
-
switch (event.data.type) {
|
|
86
|
-
case 'nodeCreated': {
|
|
87
|
-
clearTimeout(timeout)
|
|
88
|
-
worker.removeEventListener('message', eventFunc)
|
|
89
|
-
resolve(true)
|
|
90
|
-
break
|
|
91
|
-
}
|
|
92
|
-
default: {
|
|
93
|
-
const message: Message = event.data
|
|
94
|
-
console.log(`Unknown Event (nodeCreated listener) [${JSON.stringify(event)}]: ${JSON.stringify(message, null, 2)}`)
|
|
95
|
-
break
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
worker.addEventListener('message', eventFunc)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const bridge = await WorkerBridge.create({ config: { schema: WorkerBridgeConfigSchema }, worker })
|
|
103
|
-
await bridge.start()
|
|
104
|
-
return bridge
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
override exposeHandler(_id: string, _options?: BridgeExposeOptions | undefined): Promisable<ModuleInstance[]> {
|
|
108
|
-
return []
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
override exposedHandler(): Promisable<Address[]> {
|
|
112
|
-
return []
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
override getRoots(_force?: boolean | undefined): Promise<ModuleInstance[]> {
|
|
116
|
-
return Promise.resolve([])
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
override unexposeHandler(_id: string, _options?: BridgeUnexposeOptions | undefined): Promisable<ModuleInstance[]> {
|
|
120
|
-
return []
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BridgeConfig } from '@xyo-network/bridge-model'
|
|
3
|
-
import { asSchema } from '@xyo-network/payload-model'
|
|
4
|
-
|
|
5
|
-
export const WorkerBridgeConfigSchema = asSchema('network.xyo.bridge.worker.config', true)
|
|
6
|
-
export type WorkerBridgeConfigSchema = typeof WorkerBridgeConfigSchema
|
|
7
|
-
|
|
8
|
-
export type WorkerBridgeConfig<TConfig extends EmptyObject = EmptyObject> = BridgeConfig<TConfig, WorkerBridgeConfigSchema>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ArchivistConfigSchema } from '@xyo-network/archivist-model'
|
|
2
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest-model'
|
|
3
|
-
import { PackageManifestPayloadSchema } from '@xyo-network/manifest-model'
|
|
4
|
-
import { NodeConfigSchema } from '@xyo-network/node-model'
|
|
5
|
-
import { SentinelConfigSchema } from '@xyo-network/sentinel-model'
|
|
6
|
-
|
|
7
|
-
export const defaultPackageManifest: PackageManifestPayload = {
|
|
8
|
-
nodes: [
|
|
9
|
-
{
|
|
10
|
-
config: {
|
|
11
|
-
name: 'SimpleMemoryDapp',
|
|
12
|
-
schema: NodeConfigSchema,
|
|
13
|
-
},
|
|
14
|
-
modules: {
|
|
15
|
-
private: [
|
|
16
|
-
{
|
|
17
|
-
config: {
|
|
18
|
-
name: 'ScratchArchivist',
|
|
19
|
-
schema: ArchivistConfigSchema,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
public: [
|
|
24
|
-
{
|
|
25
|
-
config: {
|
|
26
|
-
name: 'SimpleArchivist',
|
|
27
|
-
schema: ArchivistConfigSchema,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
config: {
|
|
32
|
-
name: 'SimpleSentinel',
|
|
33
|
-
schema: SentinelConfigSchema,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
schema: PackageManifestPayloadSchema,
|
|
41
|
-
}
|
package/src/docsEntry.ts
DELETED
package/src/index.ts
DELETED
package/src/tsconfig.json
DELETED
package/src/worker/Worker.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { generateMnemonic } from '@scure/bip39'
|
|
2
|
-
import { wordlist } from '@scure/bip39/wordlists/english.js'
|
|
3
|
-
import type { Address, Logger } from '@xylabs/sdk-js'
|
|
4
|
-
import { forget } from '@xylabs/sdk-js'
|
|
5
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
6
|
-
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
7
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
8
|
-
import type { ModuleFactoryLocatorInstance } from '@xyo-network/module-model'
|
|
9
|
-
import type { NodeInstance } from '@xyo-network/node-model'
|
|
10
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
Message, QueryMessage, QueryResultMessage,
|
|
14
|
-
} from '../WorkerBridge.ts'
|
|
15
|
-
|
|
16
|
-
export type QueryEvent = MessageEvent<QueryMessage>
|
|
17
|
-
|
|
18
|
-
export interface CreateNodeMessage extends Message<'createNode'> {
|
|
19
|
-
manifest: PackageManifestPayload
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type CreateNodeEvent = MessageEvent<CreateNodeMessage>
|
|
23
|
-
|
|
24
|
-
export interface NodeCreatedMessage extends Message<'nodeCreated'> {
|
|
25
|
-
address: Address
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class WorkerNodeHost {
|
|
29
|
-
protected logger?: Logger
|
|
30
|
-
protected node: NodeInstance
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
node: NodeInstance,
|
|
34
|
-
logger?: Logger,
|
|
35
|
-
) {
|
|
36
|
-
this.node = node
|
|
37
|
-
this.logger = logger
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static async create(config: PackageManifestPayload, locator: ModuleFactoryLocatorInstance) {
|
|
41
|
-
const mnemonic = generateMnemonic(wordlist, 256)
|
|
42
|
-
const manifest = new ManifestWrapper(config, await HDWallet.fromPhrase(mnemonic), locator)
|
|
43
|
-
const [node] = await manifest.loadNodes()
|
|
44
|
-
const worker = new this(node)
|
|
45
|
-
worker.attachNode(node)
|
|
46
|
-
return worker
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static start(logger?: Logger) {
|
|
50
|
-
const listener = async (event: MessageEvent) => {
|
|
51
|
-
switch (event.data.type) {
|
|
52
|
-
case 'createNode': {
|
|
53
|
-
const message: CreateNodeMessage = event.data
|
|
54
|
-
const worker = await this.create(message.manifest, new ModuleFactoryLocator())
|
|
55
|
-
logger?.log(`createNode: ${worker.node.address}`)
|
|
56
|
-
const response: NodeCreatedMessage = { address: worker.node.address, type: 'nodeCreated' }
|
|
57
|
-
postMessage(response)
|
|
58
|
-
break
|
|
59
|
-
}
|
|
60
|
-
default: {
|
|
61
|
-
const message: Message = event.data
|
|
62
|
-
logger?.debug(`Unknown Event (Static) [${JSON.stringify(event)}]: ${JSON.stringify(message, null, 2)}`)
|
|
63
|
-
break
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
self.addEventListener('message', (event: MessageEvent) => {
|
|
69
|
-
forget(listener(event))
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private attachNode(node: NodeInstance) {
|
|
74
|
-
const listener = async (event: MessageEvent) => {
|
|
75
|
-
const message = event.data as Message
|
|
76
|
-
switch (message.type) {
|
|
77
|
-
case 'xyoQuery': {
|
|
78
|
-
const message: QueryMessage = event.data
|
|
79
|
-
const {
|
|
80
|
-
address, msgId, query, payloads,
|
|
81
|
-
} = message
|
|
82
|
-
const mod = address ? await node.resolve(address, { direction: 'down' }) : node
|
|
83
|
-
if (mod) {
|
|
84
|
-
const result: QueryResultMessage = {
|
|
85
|
-
address, msgId, result: await mod.query(query, payloads),
|
|
86
|
-
}
|
|
87
|
-
self.postMessage(result)
|
|
88
|
-
}
|
|
89
|
-
break
|
|
90
|
-
}
|
|
91
|
-
default: {
|
|
92
|
-
const message: Message = event.data
|
|
93
|
-
this.logger?.debug(`Unknown Event [${JSON.stringify(event)}]: ${JSON.stringify(message, null, 2)}`)
|
|
94
|
-
break
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
self.addEventListener('message', (event: MessageEvent) => {
|
|
100
|
-
forget(listener(event))
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
}
|
package/src/worker/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './WorkerNodeHost.ts'
|