@xyo-network/bridge-websocket 5.1.22 → 5.1.23
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 +25 -22
- package/dist/browser/spec/WebsocketBridge.spec.d.ts +0 -2
- package/dist/browser/spec/WebsocketBridge.spec.d.ts.map +0 -1
- package/dist/browser/spec/socketServer.spec.d.ts +0 -2
- package/dist/browser/spec/socketServer.spec.d.ts.map +0 -1
- package/dist/neutral/spec/WebsocketBridge.spec.d.ts +0 -2
- package/dist/neutral/spec/WebsocketBridge.spec.d.ts.map +0 -1
- package/dist/neutral/spec/socketServer.spec.d.ts +0 -2
- package/dist/neutral/spec/socketServer.spec.d.ts.map +0 -1
- package/dist/node/spec/WebsocketBridge.spec.d.ts +0 -2
- package/dist/node/spec/WebsocketBridge.spec.d.ts.map +0 -1
- package/dist/node/spec/socketServer.spec.d.ts +0 -2
- package/dist/node/spec/socketServer.spec.d.ts.map +0 -1
- package/src/spec/WebsocketBridge.spec.ts +0 -89
- package/src/spec/socketServer.spec.ts +0 -76
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/bridge-websocket",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.23",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -38,38 +38,41 @@
|
|
|
38
38
|
"types": "dist/neutral/index.d.ts",
|
|
39
39
|
"files": [
|
|
40
40
|
"dist",
|
|
41
|
-
"src"
|
|
41
|
+
"src",
|
|
42
|
+
"!**/*.bench.*",
|
|
43
|
+
"!**/*.spec.*",
|
|
44
|
+
"!**/*.test.*"
|
|
42
45
|
],
|
|
43
46
|
"dependencies": {
|
|
44
|
-
"@xylabs/assert": "~5.0.
|
|
45
|
-
"@xylabs/hex": "~5.0.
|
|
46
|
-
"@xylabs/object": "~5.0.
|
|
47
|
-
"@xylabs/promise": "~5.0.
|
|
48
|
-
"@xyo-network/account": "~5.1.
|
|
49
|
-
"@xyo-network/boundwitness-model": "~5.1.
|
|
50
|
-
"@xyo-network/bridge-abstract": "~5.1.
|
|
51
|
-
"@xyo-network/bridge-model": "~5.1.
|
|
52
|
-
"@xyo-network/config-payload-plugin": "~5.1.
|
|
53
|
-
"@xyo-network/module-model": "~5.1.
|
|
54
|
-
"@xyo-network/payload-model": "~5.1.
|
|
47
|
+
"@xylabs/assert": "~5.0.33",
|
|
48
|
+
"@xylabs/hex": "~5.0.33",
|
|
49
|
+
"@xylabs/object": "~5.0.33",
|
|
50
|
+
"@xylabs/promise": "~5.0.33",
|
|
51
|
+
"@xyo-network/account": "~5.1.23",
|
|
52
|
+
"@xyo-network/boundwitness-model": "~5.1.23",
|
|
53
|
+
"@xyo-network/bridge-abstract": "~5.1.23",
|
|
54
|
+
"@xyo-network/bridge-model": "~5.1.23",
|
|
55
|
+
"@xyo-network/config-payload-plugin": "~5.1.23",
|
|
56
|
+
"@xyo-network/module-model": "~5.1.23",
|
|
57
|
+
"@xyo-network/payload-model": "~5.1.23",
|
|
55
58
|
"async-mutex": "~0.5.0",
|
|
56
59
|
"lru-cache": "~11.2.2",
|
|
57
60
|
"socket.io": "~4.8.1"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@xylabs/creatable": "~5.0.
|
|
63
|
+
"@xylabs/creatable": "~5.0.33",
|
|
61
64
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
62
65
|
"@xylabs/tsconfig": "~7.2.8",
|
|
63
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
64
|
-
"@xyo-network/account": "~5.1.
|
|
65
|
-
"@xyo-network/archivist-model": "~5.1.
|
|
66
|
-
"@xyo-network/node-memory": "~5.1.
|
|
67
|
-
"@xyo-network/node-model": "~5.1.
|
|
68
|
-
"@xyo-network/payload-builder": "~5.1.
|
|
69
|
-
"@xyo-network/payload-wrapper": "~5.1.
|
|
66
|
+
"@xylabs/vitest-extended": "~5.0.33",
|
|
67
|
+
"@xyo-network/account": "~5.1.23",
|
|
68
|
+
"@xyo-network/archivist-model": "~5.1.23",
|
|
69
|
+
"@xyo-network/node-memory": "~5.1.23",
|
|
70
|
+
"@xyo-network/node-model": "~5.1.23",
|
|
71
|
+
"@xyo-network/payload-builder": "~5.1.23",
|
|
72
|
+
"@xyo-network/payload-wrapper": "~5.1.23",
|
|
70
73
|
"socket.io-client": "~4.8.1",
|
|
71
74
|
"typescript": "~5.9.3",
|
|
72
|
-
"vitest": "~4.0.
|
|
75
|
+
"vitest": "~4.0.9"
|
|
73
76
|
},
|
|
74
77
|
"publishConfig": {
|
|
75
78
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketBridge.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/WebsocketBridge.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"socketServer.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/socketServer.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketBridge.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/WebsocketBridge.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"socketServer.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/socketServer.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketBridge.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/WebsocketBridge.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"socketServer.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/socketServer.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { ModuleDescriptionPayload } from '@xyo-network/module-model'
|
|
5
|
-
import { ModuleDescriptionSchema } from '@xyo-network/module-model'
|
|
6
|
-
import { MemoryNode } from '@xyo-network/node-memory'
|
|
7
|
-
import { asAttachableNodeInstance } from '@xyo-network/node-model'
|
|
8
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
10
|
-
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
11
|
-
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
12
|
-
import {
|
|
13
|
-
describe, expect, it,
|
|
14
|
-
} from 'vitest'
|
|
15
|
-
|
|
16
|
-
import { WebsocketBridge } from '../Bridge.ts'
|
|
17
|
-
import { WebsocketClientBridge } from '../ClientBridge.ts'
|
|
18
|
-
import { WebsocketBridgeConfigSchema } from '../Config.ts'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @group module
|
|
22
|
-
* @group bridge
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
describe.skip('WebsocketBridge', () => {
|
|
26
|
-
const url = `${process.env.API_WEBSOCKET_DOMAIN ?? 'ws://localhost:8080'}`
|
|
27
|
-
|
|
28
|
-
console.log(`WebsocketBridge:url ${url}`)
|
|
29
|
-
|
|
30
|
-
it('WebsocketBridge: %s', async () => {
|
|
31
|
-
const memClientNode = await MemoryNode.create({
|
|
32
|
-
account: 'random',
|
|
33
|
-
config: { name: 'TestClientNode', schema: 'network.xyo.node.config' },
|
|
34
|
-
})
|
|
35
|
-
const memHostNode = await MemoryNode.create({ account: 'random' })
|
|
36
|
-
|
|
37
|
-
const host = await WebsocketBridge.create({
|
|
38
|
-
account: 'random',
|
|
39
|
-
config: {
|
|
40
|
-
host: {}, name: 'TestHostBridge', schema: WebsocketBridgeConfigSchema, security: { allowAnonymous: true },
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
await memHostNode.register(host)
|
|
45
|
-
await memHostNode.attach(host?.address, true)
|
|
46
|
-
|
|
47
|
-
const bridge = await WebsocketClientBridge.create({
|
|
48
|
-
account: 'random',
|
|
49
|
-
config: {
|
|
50
|
-
client: { url }, name: 'TestClientBridge', schema: WebsocketBridgeConfigSchema, security: { allowAnonymous: true },
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
await memClientNode.register(bridge)
|
|
55
|
-
await memClientNode.attach(bridge?.address, true)
|
|
56
|
-
const resolvedBridge = await memClientNode.resolve(bridge.id)
|
|
57
|
-
expect(resolvedBridge).toBeDefined()
|
|
58
|
-
|
|
59
|
-
const rootModule = await bridge?.resolve('TestClientNode')
|
|
60
|
-
expect(rootModule).toBeDefined()
|
|
61
|
-
|
|
62
|
-
const remoteNode = asAttachableNodeInstance(
|
|
63
|
-
rootModule,
|
|
64
|
-
() => `Failed to resolve correct object type [XYOPublic] [${rootModule?.constructor.name}]`,
|
|
65
|
-
{ required: true },
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const state = await remoteNode.state()
|
|
69
|
-
const description = state.find(isPayloadOfSchemaType<ModuleDescriptionPayload>(ModuleDescriptionSchema))
|
|
70
|
-
expect(description?.children).toBeArray()
|
|
71
|
-
expect(description?.children?.length).toBeGreaterThan(0)
|
|
72
|
-
expect(description?.queries).toBeArray()
|
|
73
|
-
expect(description?.queries?.length).toBeGreaterThan(0)
|
|
74
|
-
|
|
75
|
-
const archivistByName1 = await rootModule?.resolve('Archivist')
|
|
76
|
-
expect(archivistByName1).toBeDefined()
|
|
77
|
-
const archivistByName2 = await bridge.resolve('XYOPublic:Archivist')
|
|
78
|
-
expect(archivistByName2).toBeDefined()
|
|
79
|
-
const archivistInstance = asArchivistInstance(archivistByName2, 'Failed to cast archivist', { required: true })
|
|
80
|
-
expect(archivistInstance).toBeDefined()
|
|
81
|
-
const knownPayload = PayloadWrapper.parse({ schema: 'network.xyo.test' })?.payload as Payload
|
|
82
|
-
expect(knownPayload).toBeDefined()
|
|
83
|
-
const knownHash = await PayloadBuilder.dataHash(knownPayload as Payload)
|
|
84
|
-
const insertResult = await archivistInstance.insert([knownPayload])
|
|
85
|
-
expect(insertResult).toBeDefined()
|
|
86
|
-
const roundTripPayload = (await archivistInstance.get([knownHash]))[0]
|
|
87
|
-
expect(roundTripPayload).toBeDefined()
|
|
88
|
-
})
|
|
89
|
-
})
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { Socket } from 'socket.io-client'
|
|
4
|
-
import { io as Client } from 'socket.io-client'
|
|
5
|
-
import {
|
|
6
|
-
afterAll,
|
|
7
|
-
afterEach,
|
|
8
|
-
beforeAll,
|
|
9
|
-
beforeEach,
|
|
10
|
-
describe, expect, test,
|
|
11
|
-
} from 'vitest'
|
|
12
|
-
|
|
13
|
-
import { BridgeCommands, createServer } from '../socketServer.ts'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @group module
|
|
17
|
-
* @group bridge
|
|
18
|
-
*/
|
|
19
|
-
describe.skip('WebsocketBridge', () => {
|
|
20
|
-
let ioServer: { start: () => void; stop: () => void }
|
|
21
|
-
let moduleClientA: Socket
|
|
22
|
-
const port = 3001
|
|
23
|
-
const serverUrl = `http://localhost:${port}`
|
|
24
|
-
const moduleAddressA = 'f4f4fa193a3b785bcf3f9902d031d49f1cf01a11'
|
|
25
|
-
const moduleAddressB = '0d8cf1ea18281a34c166624ff9d4e5a473d05ae5'
|
|
26
|
-
|
|
27
|
-
beforeAll(() => {
|
|
28
|
-
ioServer = createServer(port)
|
|
29
|
-
ioServer.start()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
afterAll(() => {
|
|
33
|
-
ioServer.stop()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
beforeEach(async () => {
|
|
37
|
-
await new Promise((resolve) => {
|
|
38
|
-
moduleClientA = Client(serverUrl, {
|
|
39
|
-
forceNew: true,
|
|
40
|
-
reconnection: true,
|
|
41
|
-
reconnectionAttempts: 5,
|
|
42
|
-
reconnectionDelay: 0,
|
|
43
|
-
transports: ['websocket'],
|
|
44
|
-
})
|
|
45
|
-
moduleClientA.on('connect', () => {
|
|
46
|
-
resolve(1)
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
if (moduleClientA.connected) {
|
|
53
|
-
moduleClientA.disconnect()
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('should communicate between modules', () => {
|
|
58
|
-
const moduleClientB = Client(serverUrl, {
|
|
59
|
-
forceNew: true,
|
|
60
|
-
reconnection: true,
|
|
61
|
-
reconnectionAttempts: 5,
|
|
62
|
-
reconnectionDelay: 0,
|
|
63
|
-
transports: ['websocket'],
|
|
64
|
-
})
|
|
65
|
-
const query = `Hello from ${moduleAddressB}`
|
|
66
|
-
moduleClientB.on('connect', () => {
|
|
67
|
-
moduleClientB.emit(BridgeCommands.bridge, moduleAddressA)
|
|
68
|
-
moduleClientA.emit(BridgeCommands.sendMessage, { address: moduleAddressA, query })
|
|
69
|
-
})
|
|
70
|
-
moduleClientB.on('message', (received) => {
|
|
71
|
-
expect(received).toBe(query)
|
|
72
|
-
moduleClientB.disconnect()
|
|
73
|
-
})
|
|
74
|
-
moduleClientA.emit(BridgeCommands.bridge, moduleAddressA)
|
|
75
|
-
})
|
|
76
|
-
})
|