@xyo-network/node 2.41.2 → 2.41.4
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/cjs/Config.d.ts +2 -2
- package/dist/cjs/Config.d.ts.map +1 -1
- package/dist/cjs/MemoryNode.d.ts +1 -1
- package/dist/cjs/MemoryNode.d.ts.map +1 -1
- package/dist/cjs/MemoryNode.js +2 -2
- package/dist/cjs/MemoryNode.js.map +1 -1
- package/dist/cjs/Node.d.ts +1 -5
- package/dist/cjs/Node.d.ts.map +1 -1
- package/dist/cjs/NodeModule.d.ts +2 -3
- package/dist/cjs/NodeModule.d.ts.map +1 -1
- package/dist/cjs/PartialConfig.d.ts +1 -1
- package/dist/cjs/PartialConfig.d.ts.map +1 -1
- package/dist/cjs/Queries/Attach.d.ts +3 -2
- package/dist/cjs/Queries/Attach.d.ts.map +1 -1
- package/dist/cjs/Queries/Attached.d.ts +2 -2
- package/dist/cjs/Queries/Attached.d.ts.map +1 -1
- package/dist/cjs/Queries/Detach.d.ts +2 -2
- package/dist/cjs/Queries/Detach.d.ts.map +1 -1
- package/dist/cjs/Queries/Registered.d.ts +2 -2
- package/dist/cjs/Queries/Registered.d.ts.map +1 -1
- package/dist/cjs/Queries/index.d.ts +2 -2
- package/dist/cjs/Queries/index.d.ts.map +1 -1
- package/dist/cjs/XyoNode.d.ts +6 -7
- package/dist/cjs/XyoNode.d.ts.map +1 -1
- package/dist/cjs/XyoNode.js +7 -17
- package/dist/cjs/XyoNode.js.map +1 -1
- package/dist/cjs/XyoNodeWrapper.d.ts +2 -1
- package/dist/cjs/XyoNodeWrapper.d.ts.map +1 -1
- package/dist/cjs/XyoNodeWrapper.js +6 -2
- package/dist/cjs/XyoNodeWrapper.js.map +1 -1
- package/dist/docs.json +1461 -1466
- package/dist/esm/Config.d.ts +2 -2
- package/dist/esm/Config.d.ts.map +1 -1
- package/dist/esm/MemoryNode.d.ts +1 -1
- package/dist/esm/MemoryNode.d.ts.map +1 -1
- package/dist/esm/MemoryNode.js +2 -2
- package/dist/esm/MemoryNode.js.map +1 -1
- package/dist/esm/Node.d.ts +1 -5
- package/dist/esm/Node.d.ts.map +1 -1
- package/dist/esm/NodeModule.d.ts +2 -3
- package/dist/esm/NodeModule.d.ts.map +1 -1
- package/dist/esm/PartialConfig.d.ts +1 -1
- package/dist/esm/PartialConfig.d.ts.map +1 -1
- package/dist/esm/Queries/Attach.d.ts +3 -2
- package/dist/esm/Queries/Attach.d.ts.map +1 -1
- package/dist/esm/Queries/Attached.d.ts +2 -2
- package/dist/esm/Queries/Attached.d.ts.map +1 -1
- package/dist/esm/Queries/Detach.d.ts +2 -2
- package/dist/esm/Queries/Detach.d.ts.map +1 -1
- package/dist/esm/Queries/Registered.d.ts +2 -2
- package/dist/esm/Queries/Registered.d.ts.map +1 -1
- package/dist/esm/Queries/index.d.ts +2 -2
- package/dist/esm/Queries/index.d.ts.map +1 -1
- package/dist/esm/XyoNode.d.ts +6 -7
- package/dist/esm/XyoNode.d.ts.map +1 -1
- package/dist/esm/XyoNode.js +4 -16
- package/dist/esm/XyoNode.js.map +1 -1
- package/dist/esm/XyoNodeWrapper.d.ts +2 -1
- package/dist/esm/XyoNodeWrapper.d.ts.map +1 -1
- package/dist/esm/XyoNodeWrapper.js +3 -2
- package/dist/esm/XyoNodeWrapper.js.map +1 -1
- package/package.json +6 -7
- package/src/MemoryNode.spec.ts +233 -42
- package/src/MemoryNode.ts +2 -2
- package/src/Node.ts +1 -6
- package/src/NodeModule.ts +2 -3
- package/src/Queries/Attach.ts +1 -0
- package/src/XyoNode.ts +9 -22
- package/src/XyoNodeWrapper.ts +5 -2
- package/src/__snapshots__/MemoryNode.spec.ts.snap +109 -0
package/src/MemoryNode.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable max-statements */
|
|
2
|
-
import { XyoArchivistWrapper } from '@xyo-network/archivist'
|
|
2
|
+
import { XyoArchivistWrapper, XyoMemoryArchivist, XyoMemoryArchivistConfigSchema } from '@xyo-network/archivist'
|
|
3
3
|
import {
|
|
4
4
|
DivinerModule,
|
|
5
5
|
XyoArchivistPayloadDiviner,
|
|
@@ -8,57 +8,248 @@ import {
|
|
|
8
8
|
XyoHuriPayload,
|
|
9
9
|
XyoHuriSchema,
|
|
10
10
|
} from '@xyo-network/diviner'
|
|
11
|
-
import { XyoModule, XyoModuleResolver } from '@xyo-network/module'
|
|
12
|
-
import { PayloadWrapper, XyoPayload, XyoPayloadBuilder, XyoPayloadSchema } from '@xyo-network/
|
|
11
|
+
import { ModuleDescription, XyoModule, XyoModuleResolver } from '@xyo-network/module'
|
|
12
|
+
import { PayloadWrapper, XyoAccount, XyoPayload, XyoPayloadBuilder, XyoPayloadSchema } from '@xyo-network/protocol'
|
|
13
13
|
|
|
14
|
+
import { NodeConfigSchema } from './Config'
|
|
14
15
|
import { MemoryNode } from './MemoryNode'
|
|
15
16
|
import { NodeModule } from './NodeModule'
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
describe('MemoryNode', () => {
|
|
19
|
+
const testAccount1 = new XyoAccount({ phrase: 'testPhrase1' })
|
|
20
|
+
const testAccount2 = new XyoAccount({ phrase: 'testPhrase2' })
|
|
21
|
+
const testAccount3 = new XyoAccount({ phrase: 'testPhrase3' })
|
|
22
|
+
const testAccount4 = new XyoAccount({ phrase: 'testPhrase4' })
|
|
23
|
+
const nodeConfig = { schema: NodeConfigSchema }
|
|
24
|
+
let node: MemoryNode
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
node = await MemoryNode.create({ account: testAccount1, config: nodeConfig })
|
|
24
27
|
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
describe('create', () => {
|
|
29
|
+
it('Creates MemoryNode', async () => {
|
|
30
|
+
const XyoMemoryArchivist = (await import('@xyo-network/archivist')).XyoMemoryArchivist
|
|
31
|
+
const node: NodeModule = await MemoryNode.create()
|
|
32
|
+
const archivist = await XyoMemoryArchivist.create()
|
|
33
|
+
const diviner: XyoModule = await XyoArchivistPayloadDiviner.create({
|
|
34
|
+
config: { archivist: archivist.address, schema: XyoArchivistPayloadDivinerConfigSchema },
|
|
35
|
+
resolver: new XyoModuleResolver().add(archivist),
|
|
36
|
+
})
|
|
37
|
+
await node.register(archivist)
|
|
38
|
+
node.attach(archivist.address)
|
|
39
|
+
await node.register(diviner)
|
|
40
|
+
node.attach(diviner.address)
|
|
41
|
+
expect((await node.registered()).length).toBe(2)
|
|
42
|
+
expect((await node.attached()).length).toBe(2)
|
|
43
|
+
const foundArchivist = (await node.resolve({ address: [archivist.address] })).shift()
|
|
44
|
+
expect(foundArchivist).toBeDefined()
|
|
45
|
+
expect(foundArchivist?.address).toBe(archivist.address)
|
|
46
|
+
const testPayload = new XyoPayloadBuilder<XyoPayload<{ schema: XyoPayloadSchema; test: boolean }>>({ schema: XyoPayloadSchema })
|
|
47
|
+
.fields({ test: true })
|
|
48
|
+
.build()
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
const foundArchivistWrapper = foundArchivist ? new XyoArchivistWrapper(foundArchivist) : undefined
|
|
51
|
+
await foundArchivistWrapper?.insert([testPayload])
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
/*const subscribeQuery: XyoModuleSubscribeQuery = { payloads: [testPayload], schema: XyoModuleSubscribeQuerySchema }
|
|
42
54
|
await foundArchivist?.query(subscribeQuery)*/
|
|
43
55
|
|
|
44
|
-
|
|
45
|
-
expect(payloads?.length).toBe(1)
|
|
46
|
-
|
|
47
|
-
if (payloads && payloads[0]) {
|
|
48
|
-
const huri = new PayloadWrapper(payloads[0]).hash
|
|
49
|
-
const huriPayload: XyoHuriPayload = { huri: [huri], schema: XyoHuriSchema }
|
|
50
|
-
const module = (await node.resolve({ address: [diviner.address] })).shift() as DivinerModule
|
|
51
|
-
const foundDiviner = module ? new XyoDivinerWrapper(module) : null
|
|
52
|
-
expect(foundDiviner).toBeDefined()
|
|
53
|
-
if (foundDiviner) {
|
|
54
|
-
const foundDivinerWrapper = new XyoDivinerWrapper(foundDiviner)
|
|
55
|
-
const payloads = await foundDivinerWrapper.divine([huriPayload])
|
|
56
|
-
console.log(`payloads: ${JSON.stringify(payloads, null, 2)}`)
|
|
56
|
+
const payloads = await foundArchivistWrapper?.all()
|
|
57
57
|
expect(payloads?.length).toBe(1)
|
|
58
|
-
|
|
59
|
-
if (payloads
|
|
60
|
-
|
|
58
|
+
|
|
59
|
+
if (payloads && payloads[0]) {
|
|
60
|
+
const huri = new PayloadWrapper(payloads[0]).hash
|
|
61
|
+
const huriPayload: XyoHuriPayload = { huri: [huri], schema: XyoHuriSchema }
|
|
62
|
+
const module = (await node.resolve({ address: [diviner.address] })).shift() as DivinerModule
|
|
63
|
+
const foundDiviner = module ? new XyoDivinerWrapper(module) : null
|
|
64
|
+
expect(foundDiviner).toBeDefined()
|
|
65
|
+
if (foundDiviner) {
|
|
66
|
+
const foundDivinerWrapper = new XyoDivinerWrapper(foundDiviner)
|
|
67
|
+
const payloads = await foundDivinerWrapper.divine([huriPayload])
|
|
68
|
+
// console.log(`payloads: ${JSON.stringify(payloads, null, 2)}`)
|
|
69
|
+
expect(payloads?.length).toBe(1)
|
|
70
|
+
expect(payloads[0]).toBeDefined()
|
|
71
|
+
if (payloads?.length === 1 && payloads[0]) {
|
|
72
|
+
expect(new PayloadWrapper(payloads[0]).hash).toBe(huri)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
}
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
describe('register', () => {
|
|
79
|
+
it('registers module', async () => {
|
|
80
|
+
const module = await XyoMemoryArchivist.create()
|
|
81
|
+
node.register(module)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
describe('registered', () => {
|
|
85
|
+
describe('with no modules registered', () => {
|
|
86
|
+
it('returns empty array', () => {
|
|
87
|
+
const result = node.registered()
|
|
88
|
+
expect(result).toBeArrayOfSize(0)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
describe('with modules registered', () => {
|
|
92
|
+
let module: XyoModule
|
|
93
|
+
beforeEach(async () => {
|
|
94
|
+
module = await XyoMemoryArchivist.create()
|
|
95
|
+
node.register(module)
|
|
96
|
+
})
|
|
97
|
+
it('lists addresses of registered modules', () => {
|
|
98
|
+
const result = node.registered()
|
|
99
|
+
expect(result).toBeArrayOfSize(1)
|
|
100
|
+
expect(result).toEqual([module.address])
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
describe('attach', () => {
|
|
105
|
+
let module: XyoModule
|
|
106
|
+
beforeEach(async () => {
|
|
107
|
+
module = await XyoMemoryArchivist.create()
|
|
108
|
+
node.register(module)
|
|
109
|
+
})
|
|
110
|
+
it('attaches module', () => {
|
|
111
|
+
node.attach(module.address)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
describe('attached', () => {
|
|
115
|
+
let module: XyoModule
|
|
116
|
+
beforeEach(async () => {
|
|
117
|
+
module = await XyoMemoryArchivist.create()
|
|
118
|
+
node.register(module)
|
|
119
|
+
})
|
|
120
|
+
describe('with no modules attached', () => {
|
|
121
|
+
it('returns empty array', async () => {
|
|
122
|
+
const result = await node.attached()
|
|
123
|
+
expect(result).toBeArrayOfSize(0)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
describe('with modules attached', () => {
|
|
127
|
+
beforeEach(() => {
|
|
128
|
+
node.attach(module.address)
|
|
129
|
+
})
|
|
130
|
+
it('lists addresses of attached modules', async () => {
|
|
131
|
+
node.attach(module.address)
|
|
132
|
+
const result = await node.attached()
|
|
133
|
+
expect(result).toBeArrayOfSize(1)
|
|
134
|
+
expect(result).toEqual([module.address])
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
describe('detach', () => {
|
|
139
|
+
let module: XyoModule
|
|
140
|
+
beforeEach(async () => {
|
|
141
|
+
module = await XyoMemoryArchivist.create()
|
|
142
|
+
node.register(module)
|
|
143
|
+
node.attach(module.address)
|
|
144
|
+
})
|
|
145
|
+
it('deregisters existing module', () => {
|
|
146
|
+
node.detach(module.address)
|
|
147
|
+
})
|
|
148
|
+
it('allows deregistering non-existent module', () => {
|
|
149
|
+
node.detach('4a15a6c96665931b76c1d2a587ea1132dbfdc266')
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
describe('registeredModules', () => {
|
|
153
|
+
let module: XyoModule
|
|
154
|
+
beforeEach(async () => {
|
|
155
|
+
module = await XyoMemoryArchivist.create()
|
|
156
|
+
})
|
|
157
|
+
describe('with no modules registered', () => {
|
|
158
|
+
it('returns empty array', () => {
|
|
159
|
+
const modules = node.registeredModules()
|
|
160
|
+
expect(modules).toBeArrayOfSize(0)
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
describe('with modules registered', () => {
|
|
164
|
+
it('returns registered modules', () => {
|
|
165
|
+
node.register(module)
|
|
166
|
+
const modules = node.registeredModules()
|
|
167
|
+
expect(modules).toBeArrayOfSize(1)
|
|
168
|
+
expect(modules).toContain(module)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
describe('unregister', () => {
|
|
173
|
+
it('un-registers module', async () => {
|
|
174
|
+
const module = await XyoMemoryArchivist.create()
|
|
175
|
+
node.register(module)
|
|
176
|
+
expect(node.registeredModules()).toContain(module)
|
|
177
|
+
node.unregister(module)
|
|
178
|
+
expect(node.registeredModules()).not.toContain(module)
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
describe('description', () => {
|
|
182
|
+
const archivistConfig = { schema: XyoMemoryArchivistConfigSchema }
|
|
183
|
+
const validateModuleDescription = (description: ModuleDescription) => {
|
|
184
|
+
expect(description).toBeObject()
|
|
185
|
+
expect(description.address).toBeString()
|
|
186
|
+
expect(description.queries).toBeArray()
|
|
187
|
+
description.queries.map((query) => {
|
|
188
|
+
expect(query).toBeString()
|
|
189
|
+
})
|
|
62
190
|
}
|
|
63
|
-
|
|
191
|
+
describe('node without child modules', () => {
|
|
192
|
+
it('describes node alone', async () => {
|
|
193
|
+
const description = await node.description()
|
|
194
|
+
validateModuleDescription(description)
|
|
195
|
+
expect(description.children).toBeArrayOfSize(0)
|
|
196
|
+
})
|
|
197
|
+
it('serializes to JSON consistently', async () => {
|
|
198
|
+
const description = await node.description()
|
|
199
|
+
expect(prettyPrintDescription(description)).toMatchSnapshot()
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
describe('node with child modules', () => {
|
|
203
|
+
beforeEach(async () => {
|
|
204
|
+
const modules = await Promise.all([
|
|
205
|
+
await XyoMemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
|
|
206
|
+
await XyoMemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
|
|
207
|
+
])
|
|
208
|
+
modules.map((mod) => {
|
|
209
|
+
node.register(mod)
|
|
210
|
+
node.attach(mod.address)
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
it('describes node and child modules', async () => {
|
|
214
|
+
const description = await node.description()
|
|
215
|
+
validateModuleDescription(description)
|
|
216
|
+
expect(description.children).toBeArrayOfSize(2)
|
|
217
|
+
description.children?.map(validateModuleDescription)
|
|
218
|
+
})
|
|
219
|
+
it('serializes to JSON consistently', async () => {
|
|
220
|
+
const description = await node.description()
|
|
221
|
+
expect(prettyPrintDescription(description)).toMatchSnapshot()
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
describe('node with nested nodes and modules', () => {
|
|
225
|
+
beforeEach(async () => {
|
|
226
|
+
const nestedNode = await MemoryNode.create({ account: testAccount2, config: nodeConfig })
|
|
227
|
+
const nestedModules = await Promise.all([await XyoMemoryArchivist.create({ account: testAccount3, config: archivistConfig })])
|
|
228
|
+
nestedModules.map((mod) => {
|
|
229
|
+
nestedNode.register(mod)
|
|
230
|
+
nestedNode.attach(mod.address)
|
|
231
|
+
})
|
|
232
|
+
const rootModules: XyoModule[] = await Promise.all([await XyoMemoryArchivist.create({ account: testAccount4, config: archivistConfig })])
|
|
233
|
+
rootModules.push(nestedNode)
|
|
234
|
+
rootModules.map((mod) => {
|
|
235
|
+
node.register(mod)
|
|
236
|
+
node.attach(mod.address)
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
it('describes node and all nested nodes and child modules', async () => {
|
|
240
|
+
const description = await node.description()
|
|
241
|
+
validateModuleDescription(description)
|
|
242
|
+
expect(description.children).toBeArrayOfSize(2)
|
|
243
|
+
description.children?.map(validateModuleDescription)
|
|
244
|
+
})
|
|
245
|
+
it('serializes to JSON consistently', async () => {
|
|
246
|
+
const description = await node.description()
|
|
247
|
+
expect(prettyPrintDescription(description)).toMatchSnapshot()
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
})
|
|
64
251
|
})
|
|
252
|
+
|
|
253
|
+
const prettyPrintDescription = (description: ModuleDescription) => {
|
|
254
|
+
return JSON.stringify(description, null, 2)
|
|
255
|
+
}
|
package/src/MemoryNode.ts
CHANGED
|
@@ -12,9 +12,9 @@ export class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends
|
|
|
12
12
|
return (await super.create(params)) as MemoryNode
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
override attach(address: string) {
|
|
15
|
+
override attach(address: string, name?: string) {
|
|
16
16
|
const module = assertEx(this.registeredModuleMap.get(address), 'No module found at that address')
|
|
17
|
-
this.internalResolver.add(module)
|
|
17
|
+
this.internalResolver.add(module, name)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
override detach(address: string) {
|
package/src/Node.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { Promisable } from '@xyo-network/promise'
|
|
2
2
|
|
|
3
|
-
export interface ModuleIdentifier {
|
|
4
|
-
address?: string
|
|
5
|
-
schema?: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
3
|
export interface Node {
|
|
9
|
-
attach(address: string): void
|
|
4
|
+
attach(address: string, name?: string): void
|
|
10
5
|
attached(): Promisable<string[]>
|
|
11
6
|
detach(address: string): void
|
|
12
7
|
registered(): Promisable<string[]>
|
package/src/NodeModule.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Module,
|
|
1
|
+
import { Module, ModuleResolver } from '@xyo-network/module'
|
|
2
2
|
import { Promisable, PromisableArray } from '@xyo-network/promise'
|
|
3
3
|
|
|
4
4
|
import { Node } from './Node'
|
|
5
5
|
|
|
6
|
-
export interface NodeModule<TModule extends Module = Module> extends Node, Module {
|
|
6
|
+
export interface NodeModule<TModule extends Module = Module> extends Node, Module, ModuleResolver {
|
|
7
7
|
attachedModules(): PromisableArray<TModule>
|
|
8
8
|
register(module: TModule): Promisable<void>
|
|
9
9
|
registeredModules(): PromisableArray<TModule>
|
|
10
|
-
resolve(filter?: ModuleFilter): Promisable<TModule[]>
|
|
11
10
|
unregister(module: TModule): Promisable<void>
|
|
12
11
|
}
|
package/src/Queries/Attach.ts
CHANGED
package/src/XyoNode.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { XyoAccount } from '@xyo-network/account'
|
|
3
|
-
import { XyoArchivistWrapper, XyoMemoryArchivist } from '@xyo-network/archivist'
|
|
4
3
|
import {
|
|
5
4
|
Module,
|
|
5
|
+
ModuleDescription,
|
|
6
6
|
ModuleFilter,
|
|
7
7
|
ModuleQueryResult,
|
|
8
|
-
ModuleResolver,
|
|
9
8
|
QueryBoundWitnessWrapper,
|
|
10
9
|
XyoErrorBuilder,
|
|
11
10
|
XyoModule,
|
|
@@ -13,7 +12,6 @@ import {
|
|
|
13
12
|
XyoModuleResolver,
|
|
14
13
|
XyoQueryBoundWitness,
|
|
15
14
|
} from '@xyo-network/module'
|
|
16
|
-
import { XyoModuleInstanceSchema } from '@xyo-network/module-instance-payload-plugin'
|
|
17
15
|
import { XyoPayload } from '@xyo-network/payload'
|
|
18
16
|
import { Promisable } from '@xyo-network/promise'
|
|
19
17
|
|
|
@@ -23,7 +21,7 @@ import { XyoNodeAttachedQuerySchema, XyoNodeAttachQuerySchema, XyoNodeDetachQuer
|
|
|
23
21
|
|
|
24
22
|
export abstract class XyoNode<TConfig extends NodeConfig = NodeConfig, TModule extends XyoModule = XyoModule>
|
|
25
23
|
extends XyoModule<TConfig>
|
|
26
|
-
implements NodeModule
|
|
24
|
+
implements NodeModule
|
|
27
25
|
{
|
|
28
26
|
public isModuleResolver = true
|
|
29
27
|
|
|
@@ -47,14 +45,10 @@ export abstract class XyoNode<TConfig extends NodeConfig = NodeConfig, TModule e
|
|
|
47
45
|
return await (this.internalResolver.resolve() ?? [])
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(this.config?.archivist ? ((await this.resolver?.resolve({ address: [this.config?.archivist] })) ?? []).shift() : undefined) ??
|
|
55
|
-
(await XyoMemoryArchivist.create())
|
|
56
|
-
}
|
|
57
|
-
return this._archivist
|
|
48
|
+
override async description(): Promise<ModuleDescription> {
|
|
49
|
+
const desc = await super.description()
|
|
50
|
+
const children = await Promise.all((await this.attachedModules()).map((mod) => mod.description()))
|
|
51
|
+
return { ...desc, children }
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
override async query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult> {
|
|
@@ -106,7 +100,6 @@ export abstract class XyoNode<TConfig extends NodeConfig = NodeConfig, TModule e
|
|
|
106
100
|
|
|
107
101
|
override async start() {
|
|
108
102
|
await super.start()
|
|
109
|
-
await this.storeInstanceData()
|
|
110
103
|
return this
|
|
111
104
|
}
|
|
112
105
|
|
|
@@ -114,13 +107,7 @@ export abstract class XyoNode<TConfig extends NodeConfig = NodeConfig, TModule e
|
|
|
114
107
|
throw new Error('Method not implemented.')
|
|
115
108
|
}
|
|
116
109
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await new XyoArchivistWrapper(await this.getArchivist()).insert([bw, payload])
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
abstract attach(_address: string): void
|
|
124
|
-
abstract detach(_address: string): void
|
|
125
|
-
abstract resolve(_filter?: ModuleFilter): Promisable<TModule[]>
|
|
110
|
+
abstract attach(address: string): void
|
|
111
|
+
abstract detach(address: string): void
|
|
112
|
+
abstract resolve(filter?: ModuleFilter): Promisable<TModule[]>
|
|
126
113
|
}
|
package/src/XyoNodeWrapper.ts
CHANGED
|
@@ -17,14 +17,17 @@ import {
|
|
|
17
17
|
} from './Queries'
|
|
18
18
|
|
|
19
19
|
export class XyoNodeWrapper extends XyoModuleWrapper implements NodeModule {
|
|
20
|
+
public isModuleResolver = true
|
|
21
|
+
|
|
20
22
|
private _archivist?: XyoArchivistWrapper
|
|
23
|
+
|
|
21
24
|
public get archivist() {
|
|
22
25
|
this._archivist = this._archivist ?? new XyoArchivistWrapper(this.module)
|
|
23
26
|
return this._archivist
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
async attach(address: string): Promise<void> {
|
|
27
|
-
const queryPayload = PayloadWrapper.parse<XyoNodeAttachQuery>({ address, schema: XyoNodeAttachQuerySchema })
|
|
29
|
+
async attach(address: string, name?: string): Promise<void> {
|
|
30
|
+
const queryPayload = PayloadWrapper.parse<XyoNodeAttachQuery>({ address, name, schema: XyoNodeAttachQuerySchema })
|
|
28
31
|
const query = await this.bindQuery(queryPayload)
|
|
29
32
|
const result = await this.module.query(query[0], query[1])
|
|
30
33
|
this.throwErrors(query, result)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`MemoryNode description node with child modules serializes to JSON consistently 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"address": "3a15a6c96665931b76c1d2a587ea1132dbfdc266",
|
|
6
|
+
"queries": [
|
|
7
|
+
"network.xyo.query.node.attach",
|
|
8
|
+
"network.xyo.query.node.detach",
|
|
9
|
+
"network.xyo.query.module.discover",
|
|
10
|
+
"network.xyo.query.module.subscribe"
|
|
11
|
+
],
|
|
12
|
+
"children": [
|
|
13
|
+
{
|
|
14
|
+
"address": "b3bbeb946d88cd5fe70146a6bb276c7b384f6582",
|
|
15
|
+
"queries": [
|
|
16
|
+
"network.xyo.query.archivist.all",
|
|
17
|
+
"network.xyo.query.archivist.delete",
|
|
18
|
+
"network.xyo.query.archivist.clear",
|
|
19
|
+
"network.xyo.query.archivist.find",
|
|
20
|
+
"network.xyo.query.archivist.commit",
|
|
21
|
+
"network.xyo.query.archivist.get",
|
|
22
|
+
"network.xyo.query.archivist.insert",
|
|
23
|
+
"network.xyo.query.module.discover",
|
|
24
|
+
"network.xyo.query.module.subscribe"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"address": "ca2e94ac3ae1084072b3a4407881bf940dc2019c",
|
|
29
|
+
"queries": [
|
|
30
|
+
"network.xyo.query.archivist.all",
|
|
31
|
+
"network.xyo.query.archivist.delete",
|
|
32
|
+
"network.xyo.query.archivist.clear",
|
|
33
|
+
"network.xyo.query.archivist.find",
|
|
34
|
+
"network.xyo.query.archivist.commit",
|
|
35
|
+
"network.xyo.query.archivist.get",
|
|
36
|
+
"network.xyo.query.archivist.insert",
|
|
37
|
+
"network.xyo.query.module.discover",
|
|
38
|
+
"network.xyo.query.module.subscribe"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}"
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`MemoryNode description node with nested nodes and modules serializes to JSON consistently 1`] = `
|
|
46
|
+
"{
|
|
47
|
+
"address": "3a15a6c96665931b76c1d2a587ea1132dbfdc266",
|
|
48
|
+
"queries": [
|
|
49
|
+
"network.xyo.query.node.attach",
|
|
50
|
+
"network.xyo.query.node.detach",
|
|
51
|
+
"network.xyo.query.module.discover",
|
|
52
|
+
"network.xyo.query.module.subscribe"
|
|
53
|
+
],
|
|
54
|
+
"children": [
|
|
55
|
+
{
|
|
56
|
+
"address": "f59810a9da8a99e464355a411afe06f8c2d1c4b8",
|
|
57
|
+
"queries": [
|
|
58
|
+
"network.xyo.query.archivist.all",
|
|
59
|
+
"network.xyo.query.archivist.delete",
|
|
60
|
+
"network.xyo.query.archivist.clear",
|
|
61
|
+
"network.xyo.query.archivist.find",
|
|
62
|
+
"network.xyo.query.archivist.commit",
|
|
63
|
+
"network.xyo.query.archivist.get",
|
|
64
|
+
"network.xyo.query.archivist.insert",
|
|
65
|
+
"network.xyo.query.module.discover",
|
|
66
|
+
"network.xyo.query.module.subscribe"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"address": "b3bbeb946d88cd5fe70146a6bb276c7b384f6582",
|
|
71
|
+
"queries": [
|
|
72
|
+
"network.xyo.query.node.attach",
|
|
73
|
+
"network.xyo.query.node.detach",
|
|
74
|
+
"network.xyo.query.module.discover",
|
|
75
|
+
"network.xyo.query.module.subscribe"
|
|
76
|
+
],
|
|
77
|
+
"children": [
|
|
78
|
+
{
|
|
79
|
+
"address": "ca2e94ac3ae1084072b3a4407881bf940dc2019c",
|
|
80
|
+
"queries": [
|
|
81
|
+
"network.xyo.query.archivist.all",
|
|
82
|
+
"network.xyo.query.archivist.delete",
|
|
83
|
+
"network.xyo.query.archivist.clear",
|
|
84
|
+
"network.xyo.query.archivist.find",
|
|
85
|
+
"network.xyo.query.archivist.commit",
|
|
86
|
+
"network.xyo.query.archivist.get",
|
|
87
|
+
"network.xyo.query.archivist.insert",
|
|
88
|
+
"network.xyo.query.module.discover",
|
|
89
|
+
"network.xyo.query.module.subscribe"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}"
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
exports[`MemoryNode description node without child modules serializes to JSON consistently 1`] = `
|
|
99
|
+
"{
|
|
100
|
+
"address": "3a15a6c96665931b76c1d2a587ea1132dbfdc266",
|
|
101
|
+
"queries": [
|
|
102
|
+
"network.xyo.query.node.attach",
|
|
103
|
+
"network.xyo.query.node.detach",
|
|
104
|
+
"network.xyo.query.module.discover",
|
|
105
|
+
"network.xyo.query.module.subscribe"
|
|
106
|
+
],
|
|
107
|
+
"children": []
|
|
108
|
+
}"
|
|
109
|
+
`;
|