@xyo-network/node 2.47.9 → 2.48.0

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.
@@ -61,7 +61,7 @@ export class MemoryNode extends AbstractNode {
61
61
  const local = this.resolver?.resolve(filter) || [];
62
62
  const resolved = await Promise.allSettled([internal, external, local]);
63
63
  const errors = resolved.filter(rejected).map((r) => Error(r.reason));
64
- if (errors) {
64
+ if (errors.length) {
65
65
  this.logger?.error(`Resolve Errors: ${JSON.stringify(errors, null, 2)}`);
66
66
  }
67
67
  return resolved
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryNode.js","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAA;AAE5E,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAc,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIvD,MAAM,OAAO,UAAoD,SAAQ,YAAqB;IAC5F,MAAM,CAAU,YAAY,GAAG,gBAAgB,CAAA;IAEvC,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAA;IAEvD,MAAM,CAAU,KAAK,CAAC,MAAM,CAAC,MAAkC;QAC7D,OAAO,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAe,CAAA;IACnD,CAAC;IAEQ,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,QAAkB;QACvD,MAAM,cAAc,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;QAC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C,SAAS,CAAC;aACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;aACnB,IAAI,EAAE;aACN,MAAM,CAAC,MAAM,CAAC;aACd,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC7B,CAAC;IAEQ,UAAU,CAAC,MAAc;QAChC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC3B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC"}
package/package.json CHANGED
@@ -10,18 +10,18 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^2.7.1",
14
- "@xylabs/exists": "^2.7.1",
15
- "@xylabs/promise": "^2.7.1",
16
- "@xyo-network/account": "^2.47.9",
17
- "@xyo-network/address-payload-plugin": "^2.47.9",
18
- "@xyo-network/archivist-wrapper": "^2.47.9",
19
- "@xyo-network/module": "^2.47.9",
20
- "@xyo-network/module-model": "^2.47.9",
21
- "@xyo-network/payload-builder": "^2.47.9",
22
- "@xyo-network/payload-model": "^2.47.9",
23
- "@xyo-network/payload-wrapper": "^2.47.9",
24
- "@xyo-network/promise": "^2.47.9"
13
+ "@xylabs/assert": "^2.7.4",
14
+ "@xylabs/exists": "^2.7.4",
15
+ "@xylabs/promise": "^2.7.4",
16
+ "@xyo-network/account": "^2.48.0",
17
+ "@xyo-network/address-payload-plugin": "^2.48.0",
18
+ "@xyo-network/archivist-wrapper": "^2.48.0",
19
+ "@xyo-network/module": "^2.48.0",
20
+ "@xyo-network/module-model": "^2.48.0",
21
+ "@xyo-network/payload-builder": "^2.48.0",
22
+ "@xyo-network/payload-model": "^2.48.0",
23
+ "@xyo-network/payload-wrapper": "^2.48.0",
24
+ "@xyo-network/promise": "^2.48.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@xylabs/ts-scripts-yarn3": "^2.15.0",
@@ -61,5 +61,5 @@
61
61
  },
62
62
  "sideEffects": false,
63
63
  "types": "dist/types/index.d.ts",
64
- "version": "2.47.9"
64
+ "version": "2.48.0"
65
65
  }
package/src/MemoryNode.ts CHANGED
@@ -85,7 +85,7 @@ export class MemoryNode<TConfig extends NodeConfig = NodeConfig> extends Abstrac
85
85
 
86
86
  const errors = resolved.filter(rejected).map((r) => Error(r.reason))
87
87
 
88
- if (errors) {
88
+ if (errors.length) {
89
89
  this.logger?.error(`Resolve Errors: ${JSON.stringify(errors, null, 2)}`)
90
90
  }
91
91
 
@@ -1,410 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
3
- import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
4
- import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
5
- import {
6
- ArchivistPayloadDiviner,
7
- DivinerModule,
8
- DivinerWrapper,
9
- XyoArchivistPayloadDivinerConfigSchema,
10
- XyoHuriPayload,
11
- XyoHuriSchema,
12
- } from '@xyo-network/diviner'
13
- import { AbstractModule, Module, ModuleDescription } from '@xyo-network/module'
14
- import { Account, PayloadWrapper, XyoPayload, XyoPayloadBuilder, XyoPayloadSchema } from '@xyo-network/protocol'
15
-
16
- import { NodeConfigSchema } from '../Config'
17
- import { MemoryNode } from '../MemoryNode'
18
- import { NodeWrapper } from '../NodeWrapper'
19
-
20
- describe('MemoryNode', () => {
21
- const testAccount1 = new Account({ phrase: 'testPhrase1' })
22
- const testAccount2 = new Account({ phrase: 'testPhrase2' })
23
- const testAccount3 = new Account({ phrase: 'testPhrase3' })
24
- const testAccount4 = new Account({ phrase: 'testPhrase4' })
25
- const archivistConfig = { schema: MemoryArchivistConfigSchema }
26
- const nodeConfig = { schema: NodeConfigSchema }
27
- let node: MemoryNode
28
- beforeEach(async () => {
29
- node = await MemoryNode.create({ account: testAccount1, config: nodeConfig })
30
- })
31
- describe('create', () => {
32
- it('Creates MemoryNode', async () => {
33
- const XyoMemoryArchivist = (await import('@xyo-network/archivist')).MemoryArchivist
34
- const node = await MemoryNode.create()
35
- const archivist = await XyoMemoryArchivist.create()
36
- const diviner: AbstractModule = await ArchivistPayloadDiviner.create({
37
- config: { archivist: archivist.address, schema: XyoArchivistPayloadDivinerConfigSchema },
38
- })
39
- await node.register(archivist).attach(archivist.address, true)
40
- await node.register(diviner).attach(diviner.address, true)
41
- expect(node.registered()).toBeArrayOfSize(2)
42
- expect(await node.attached()).toBeArrayOfSize(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()
49
-
50
- const foundArchivistWrapper = foundArchivist ? new ArchivistWrapper(foundArchivist) : undefined
51
- await foundArchivistWrapper?.insert([testPayload])
52
-
53
- /*const subscribeQuery: AbstractModuleSubscribeQuery = { payloads: [testPayload], schema: AbstractModuleSubscribeQuerySchema }
54
- await foundArchivist?.query(subscribeQuery)*/
55
-
56
- const payloads = await foundArchivistWrapper?.all()
57
- expect(payloads?.length).toBe(1)
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 | undefined
63
- const foundDiviner = module ? new DivinerWrapper(module) : null
64
- expect(foundDiviner).toBeDefined()
65
- if (foundDiviner) {
66
- const foundDivinerWrapper = new DivinerWrapper(foundDiviner)
67
- const payloads = await foundDivinerWrapper.divine([huriPayload])
68
- expect(payloads?.length).toBe(1)
69
- expect(payloads[0]).toBeDefined()
70
- if (payloads?.length === 1 && payloads[0]) {
71
- expect(new PayloadWrapper(payloads[0]).hash).toBe(huri)
72
- }
73
- }
74
- }
75
- })
76
- /*describe('with autoAttachExternallyResolved true', () => {
77
- it('attaches external modules to internal resolver', async () => {
78
- // Arrange
79
- // Create a MemoryNode with no modules in the internal
80
- // resolver and one module in the external resolver
81
- const resolver = new CompositeModuleResolver()
82
- const internalResolver = new CompositeModuleResolver()
83
- const params: MemoryNodeParams = {
84
- config: { schema: NodeConfigSchema },
85
- internalResolver,
86
- resolver,
87
- }
88
- const module = await MemoryArchivist.create()
89
- const filter = { address: [module.address] }
90
- resolver.add(module)
91
- // No modules exist in internal resolver
92
- expect(await internalResolver.resolve(filter)).toBeArrayOfSize(0)
93
- // Module exists in external resolver
94
- expect(await resolver.resolve(filter)).toBeArrayOfSize(1)
95
- const node = await MemoryNode.create(params)
96
- // No modules are attached
97
- expect(await node.attached()).toBeArrayOfSize(0)
98
-
99
- // Act
100
- // Query for unattached module (by address) that exists in
101
- // external resolver
102
- expect(await node.resolve(filter)).toBeArrayOfSize(1)
103
-
104
- // Assert
105
- // Module is now attached
106
- expect(await node.attached()).toBeArrayOfSize(1)
107
- // Module exists in internal resolver
108
- expect(await internalResolver.resolve(filter)).toBeArrayOfSize(1)
109
- // Module still exists in external resolver
110
- expect(await resolver.resolve(filter)).toBeArrayOfSize(1)
111
- })
112
- })*/
113
- })
114
- describe('register', () => {
115
- it('registers module', async () => {
116
- const module = await MemoryArchivist.create()
117
- node.register(module)
118
- })
119
- })
120
- describe('registered', () => {
121
- describe('with no modules registered', () => {
122
- it('returns empty array', () => {
123
- const result = node.registered()
124
- expect(result).toBeArrayOfSize(0)
125
- })
126
- })
127
- describe('with modules registered', () => {
128
- let module: AbstractModule
129
- beforeEach(async () => {
130
- module = await MemoryArchivist.create()
131
- node.register(module)
132
- })
133
- it('lists addresses of registered modules', () => {
134
- const result = node.registered()
135
- expect(result).toBeArrayOfSize(1)
136
- expect(result).toEqual([module.address])
137
- })
138
- })
139
- })
140
- describe('attach', () => {
141
- let module: AbstractModule
142
- beforeEach(async () => {
143
- module = await MemoryArchivist.create()
144
- node.register(module)
145
- })
146
- it('attaches module', async () => {
147
- await node.attach(module.address, true)
148
- })
149
- it('emits event on module attach', async () => {
150
- let attachDone = false
151
- let eventDone = false
152
- return await new Promise<void>((resolve, reject) => {
153
- node.on('moduleAttached', (args) => {
154
- expect(args.module).toBeObject()
155
- expect(args.module.address).toBe(module.address)
156
- expect(args.module).toBe(module)
157
- eventDone = true
158
- if (attachDone) {
159
- resolve()
160
- }
161
- })
162
- node
163
- .attach(module.address, true)
164
- .then(() => {
165
- attachDone = true
166
- if (eventDone) {
167
- resolve()
168
- }
169
- })
170
- .catch(() => {
171
- reject('Attach failed')
172
- })
173
- })
174
- })
175
- })
176
- describe('attached', () => {
177
- let module: AbstractModule
178
- beforeEach(async () => {
179
- module = await MemoryArchivist.create()
180
- node.register(module)
181
- })
182
- describe('with no modules attached', () => {
183
- it('returns empty array', async () => {
184
- const result = await node.attached()
185
- expect(result).toBeArrayOfSize(0)
186
- })
187
- })
188
- describe('with modules attached', () => {
189
- it('lists addresses of attached modules', async () => {
190
- await node.attach(module.address, true)
191
- const result = await node.attached()
192
- expect(result).toBeArrayOfSize(1)
193
- expect(result).toEqual([module.address])
194
- })
195
- })
196
- })
197
- describe('detach', () => {
198
- let module: AbstractModule
199
- beforeEach(async () => {
200
- module = await MemoryArchivist.create()
201
- node.register(module)
202
- await node.attach(module.address, true)
203
- })
204
- it('deregisters existing module', () => {
205
- node.detach(module.address)
206
- })
207
- /*it('allows deregistering non-existent module', () => {
208
- node.detach('4a15a6c96665931b76c1d2a587ea1132dbfdc266')
209
- })*/
210
- })
211
- describe('registeredModules', () => {
212
- let module: AbstractModule
213
- beforeEach(async () => {
214
- module = await MemoryArchivist.create()
215
- })
216
- describe('with no modules registered', () => {
217
- it('returns empty array', () => {
218
- const modules = node.registeredModules()
219
- expect(modules).toBeArrayOfSize(0)
220
- })
221
- })
222
- describe('with modules registered', () => {
223
- it('returns registered modules', () => {
224
- node.register(module)
225
- const modules = node.registeredModules()
226
- expect(modules).toBeArrayOfSize(1)
227
- expect(modules).toContain(module)
228
- })
229
- })
230
- })
231
- describe('unregister', () => {
232
- it('un-registers module', async () => {
233
- const module = await MemoryArchivist.create()
234
- node.register(module)
235
- expect(node.registeredModules()).toContain(module)
236
- node.unregister(module)
237
- expect(node.registeredModules()).not.toContain(module)
238
- })
239
- })
240
- describe('description', () => {
241
- const validateModuleDescription = (description: ModuleDescription) => {
242
- expect(description).toBeObject()
243
- expect(description.address).toBeString()
244
- expect(description.queries).toBeArray()
245
- description.queries.map((query) => {
246
- expect(query).toBeString()
247
- })
248
- }
249
- describe('node without child modules', () => {
250
- it('describes node alone', async () => {
251
- const wrapper = NodeWrapper.wrap(node)
252
- const description = await wrapper.describe()
253
- validateModuleDescription(description)
254
- expect(description.children).toBeArrayOfSize(0)
255
- })
256
- it('serializes to JSON consistently', async () => {
257
- const wrapper = NodeWrapper.wrap(node)
258
- const description = await wrapper.describe()
259
- expect(prettyPrintDescription(description)).toMatchSnapshot()
260
- })
261
- })
262
- describe('node with child modules', () => {
263
- beforeEach(async () => {
264
- const modules = await Promise.all([
265
- await MemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
266
- await MemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
267
- ])
268
- modules.map(async (mod) => {
269
- node.register(mod)
270
- await node.attach(mod.address, true)
271
- })
272
- })
273
- it('describes node and child modules', async () => {
274
- const wrapper = NodeWrapper.wrap(node)
275
- const description = await wrapper.describe()
276
- validateModuleDescription(description)
277
- expect(description.children).toBeArrayOfSize(2)
278
- //description.children?.map(validateModuleDescription)
279
- })
280
- it('serializes to JSON consistently', async () => {
281
- const wrapper = NodeWrapper.wrap(node)
282
- const description = await wrapper.describe()
283
- expect(prettyPrintDescription(description)).toMatchSnapshot()
284
- })
285
- })
286
- describe('node with nested nodes and modules', () => {
287
- beforeEach(async () => {
288
- const nestedNode = await MemoryNode.create({ account: testAccount2, config: nodeConfig })
289
- const nestedModules = await Promise.all([await MemoryArchivist.create({ account: testAccount3, config: archivistConfig })])
290
- nestedModules.map(async (mod) => {
291
- nestedNode.register(mod)
292
- await nestedNode.attach(mod.address, true)
293
- })
294
- const rootModules: AbstractModule[] = await Promise.all([await MemoryArchivist.create({ account: testAccount4, config: archivistConfig })])
295
- rootModules.push(nestedNode)
296
- rootModules.map(async (mod) => {
297
- node.register(mod)
298
- await node.attach(mod.address, true)
299
- })
300
- })
301
- it('describes node and all nested nodes and child modules', async () => {
302
- const memoryNode = await MemoryNode.create()
303
- const archivist1 = await MemoryArchivist.create()
304
- const archivist2 = await MemoryArchivist.create()
305
- const wrapper = NodeWrapper.wrap(memoryNode)
306
- await memoryNode.register(archivist1).attach(archivist1.address, true)
307
- await memoryNode.register(archivist2).attach(archivist2.address, true)
308
- const description = await wrapper.describe()
309
- validateModuleDescription(description)
310
- expect(description.children).toBeArrayOfSize(2)
311
- //description.children?.map(validateModuleDescription)
312
- })
313
- it('serializes to JSON consistently', async () => {
314
- const wrapper = NodeWrapper.wrap(node)
315
- const description = await wrapper.describe()
316
- expect(prettyPrintDescription(description)).toMatchSnapshot()
317
- })
318
- })
319
- })
320
- describe('discover', () => {
321
- const archivistConfig = { schema: MemoryArchivistConfigSchema }
322
- const validateDiscoveryResponse = (mod: Module, response: XyoPayload[]) => {
323
- expect(response).toBeArray()
324
- const address = response.find((p) => p.schema === AddressSchema) as AddressPayload
325
- expect(address).toBeObject()
326
- expect(address.address).toEqual(mod.address)
327
- const config = response.find((p) => p.schema === mod.config.schema)
328
- expect(config).toBeObject()
329
- expect(config).toEqual(mod.config)
330
- const queries = response.filter((p) => mod.queries.includes(p.schema))
331
- expect(queries.length).toBeGreaterThanOrEqual(0)
332
- queries.map((query) => {
333
- expect(query).toBeObject()
334
- })
335
- }
336
- describe('node without child modules', () => {
337
- it('describes node alone', async () => {
338
- const description = await node.discover()
339
- validateDiscoveryResponse(node, description)
340
- })
341
- })
342
- describe('node with child modules', () => {
343
- it('describes node and child modules', async () => {
344
- const memoryNode = await MemoryNode.create()
345
- const modules = await Promise.all([
346
- await MemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
347
- await MemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
348
- ])
349
- await Promise.all(
350
- modules.map(async (mod) => {
351
- memoryNode.register(mod)
352
- await memoryNode.attach(mod.address, true)
353
- }),
354
- )
355
- const discover = await memoryNode.discover()
356
-
357
- const address0 = discover.find((p) => p.schema === AddressSchema && (p as AddressPayload).address === modules[0].address) as AddressPayload
358
- expect(address0).toBeObject()
359
- const address1 = discover.find((p) => p.schema === AddressSchema && (p as AddressPayload).address === modules[1].address) as AddressPayload
360
- expect(address1).toBeObject()
361
- })
362
- })
363
- describe('node with nested nodes and modules', () => {
364
- beforeEach(async () => {
365
- const nestedNode = await MemoryNode.create({ account: testAccount2, config: nodeConfig })
366
- const nestedModules = await Promise.all([await MemoryArchivist.create({ account: testAccount3, config: archivistConfig })])
367
- nestedModules.map(async (mod) => {
368
- nestedNode.register(mod)
369
- await nestedNode.attach(mod.address, true)
370
- })
371
- const rootModules: AbstractModule[] = await Promise.all([await MemoryArchivist.create({ account: testAccount4, config: archivistConfig })])
372
- rootModules.push(nestedNode)
373
- rootModules.map(async (mod) => {
374
- node.register(mod)
375
- await node.attach(mod.address, true)
376
- })
377
- })
378
- it('describes node and all nested nodes and child modules', async () => {
379
- const description = await node.discover()
380
- validateDiscoveryResponse(node, description)
381
- })
382
- })
383
- })
384
- describe('resolveWrapped', () => {
385
- beforeEach(async () => {
386
- const modules = await Promise.all([
387
- await MemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
388
- await MemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
389
- ])
390
- modules.map(async (mod) => {
391
- node.register(mod)
392
- await node.attach(mod.address, true)
393
- })
394
- })
395
- it('resolves modules wrapped as the specified type', async () => {
396
- const filter = { address: [testAccount2.addressValue.hex] }
397
- const modules = await node.resolveWrapped(ArchivistWrapper, filter)
398
- expect(modules.length).toBeGreaterThan(0)
399
- modules.map((mod) => {
400
- expect(mod.get).toBeFunction()
401
- expect(mod.find).toBeFunction()
402
- expect(mod.insert).toBeFunction()
403
- })
404
- })
405
- })
406
- })
407
-
408
- const prettyPrintDescription = (description: ModuleDescription) => {
409
- return JSON.stringify(description, null, 2)
410
- }
@@ -1,53 +0,0 @@
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.node.attached",
10
- "network.xyo.query.node.registered",
11
- "network.xyo.query.module.discover",
12
- "network.xyo.query.module.subscribe"
13
- ],
14
- "children": [
15
- "b3bbeb946d88cd5fe70146a6bb276c7b384f6582",
16
- "ca2e94ac3ae1084072b3a4407881bf940dc2019c"
17
- ]
18
- }"
19
- `;
20
-
21
- exports[`MemoryNode description node with nested nodes and modules serializes to JSON consistently 1`] = `
22
- "{
23
- "address": "3a15a6c96665931b76c1d2a587ea1132dbfdc266",
24
- "queries": [
25
- "network.xyo.query.node.attach",
26
- "network.xyo.query.node.detach",
27
- "network.xyo.query.node.attached",
28
- "network.xyo.query.node.registered",
29
- "network.xyo.query.module.discover",
30
- "network.xyo.query.module.subscribe"
31
- ],
32
- "children": [
33
- "f59810a9da8a99e464355a411afe06f8c2d1c4b8",
34
- "b3bbeb946d88cd5fe70146a6bb276c7b384f6582",
35
- "ca2e94ac3ae1084072b3a4407881bf940dc2019c"
36
- ]
37
- }"
38
- `;
39
-
40
- exports[`MemoryNode description node without child modules serializes to JSON consistently 1`] = `
41
- "{
42
- "address": "3a15a6c96665931b76c1d2a587ea1132dbfdc266",
43
- "queries": [
44
- "network.xyo.query.node.attach",
45
- "network.xyo.query.node.detach",
46
- "network.xyo.query.node.attached",
47
- "network.xyo.query.node.registered",
48
- "network.xyo.query.module.discover",
49
- "network.xyo.query.module.subscribe"
50
- ],
51
- "children": []
52
- }"
53
- `;