@xyo-network/node 2.43.4 → 2.43.6
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/AbstractNode.d.ts +25 -1
- package/dist/cjs/AbstractNode.d.ts.map +1 -1
- package/dist/cjs/AbstractNode.js +43 -1
- package/dist/cjs/AbstractNode.js.map +1 -1
- package/dist/cjs/MemoryNode.d.ts +4 -1
- package/dist/cjs/MemoryNode.d.ts.map +1 -1
- package/dist/cjs/MemoryNode.js +35 -4
- package/dist/cjs/MemoryNode.js.map +1 -1
- package/dist/docs.json +2889 -1561
- package/dist/esm/AbstractNode.d.ts +25 -1
- package/dist/esm/AbstractNode.d.ts.map +1 -1
- package/dist/esm/AbstractNode.js +39 -1
- package/dist/esm/AbstractNode.js.map +1 -1
- package/dist/esm/MemoryNode.d.ts +4 -1
- package/dist/esm/MemoryNode.d.ts.map +1 -1
- package/dist/esm/MemoryNode.js +34 -4
- package/dist/esm/MemoryNode.js.map +1 -1
- package/package.json +12 -10
- package/src/AbstractNode.ts +48 -1
- package/src/MemoryNode.spec.ts +62 -2
- package/src/MemoryNode.ts +38 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account } from '@xyo-network/account';
|
|
2
|
-
import { AbstractModule, Module, ModuleDescription, ModuleFilter, ModuleParams, ModuleQueryResult, ModuleRepository, XyoQueryBoundWitness } from '@xyo-network/module';
|
|
2
|
+
import { AbstractModule, Module, ModuleConstructable, ModuleDescription, ModuleFilter, ModuleParams, ModuleQueryResult, ModuleRepository, ModuleWrapper, XyoQueryBoundWitness } from '@xyo-network/module';
|
|
3
3
|
import { XyoPayload } from '@xyo-network/payload-model';
|
|
4
4
|
import { Promisable } from '@xyo-network/promise';
|
|
5
5
|
import { NodeConfig } from './Config';
|
|
@@ -22,7 +22,31 @@ export declare abstract class AbstractNode<TConfig extends NodeConfig = NodeConf
|
|
|
22
22
|
register(_module: TModule): Promisable<void>;
|
|
23
23
|
registered(): Promisable<string[]>;
|
|
24
24
|
registeredModules(): Promisable<TModule[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the supplied filter into wrapped modules
|
|
27
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
28
|
+
* const filter = { address: [address] }
|
|
29
|
+
* const mods: ArchivistWrapper[] = await node.resolveWrapped(ArchivistWrapper, filter)
|
|
30
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
31
|
+
* DivinerWrapper, etc.)
|
|
32
|
+
* @param filter The ModuleFilter
|
|
33
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
34
|
+
* the underlying modules matching the supplied filter
|
|
35
|
+
*/
|
|
36
|
+
resolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(wrapper: ModuleConstructable<TModule, T>, filter?: ModuleFilter): Promise<T[]>;
|
|
25
37
|
start(): Promise<this>;
|
|
38
|
+
/**
|
|
39
|
+
* Tries to resolve the supplied filter into wrapped modules
|
|
40
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
41
|
+
* const filter = { address: [address] }
|
|
42
|
+
* const mods: ArchivistWrapper[] = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
43
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
44
|
+
* DivinerWrapper, etc.)
|
|
45
|
+
* @param filter The ModuleFilter
|
|
46
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
47
|
+
* the underlying modules matching the supplied filter
|
|
48
|
+
*/
|
|
49
|
+
tryResolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(wrapper: ModuleConstructable<TModule, T>, filter?: ModuleFilter): Promise<T[]>;
|
|
26
50
|
unregister(_module: TModule): Promisable<void>;
|
|
27
51
|
abstract attach(address: string): Promisable<void>;
|
|
28
52
|
abstract detach(address: string): Promisable<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractNode.d.ts","sourceRoot":"","sources":["../../src/AbstractNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AbstractNode.d.ts","sourceRoot":"","sources":["../../src/AbstractNode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,OAAO,EACL,cAAc,EACd,MAAM,EACN,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAIb,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAoB,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAKnC,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,YAAY,CAAC,OAAO,CAAC;IACzI,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;CAC7C;AAED,8BAAsB,YAAY,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,CACzG,SAAQ,cAAc,CAAC,OAAO,CAC9B,YAAW,UAAU;IAErB,MAAM,CAAC,QAAQ,CAAC,YAAY,4BAAmB;IAE/C,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAErD,SAAS,aAAa,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC;IAKlE,IAAI,gBAAgB,IAAI,OAAO,CAE9B;WAEqB,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAInF,QAAQ,IAAI,OAA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AAC,IAAI,CAAC;IAClD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;IAC9D,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;CAClE;AAED,2CAA2C;AAC3C,8BAAsB,OAAO,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,SAAS,cAAc,GAAG,cAAc,CAAE,SAAQ,YAAY,CAC1I,OAAO,EACP,OAAO,CACR;CAAG"}
|
package/dist/esm/AbstractNode.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert';
|
|
2
|
+
import { exists } from '@xylabs/exists';
|
|
2
3
|
import { Account } from '@xyo-network/account';
|
|
3
4
|
import { AddressSchema } from '@xyo-network/address-payload-plugin';
|
|
4
5
|
import { AbstractModule, QueryBoundWitnessWrapper, SimpleModuleResolver, XyoErrorBuilder, } from '@xyo-network/module';
|
|
@@ -49,7 +50,7 @@ export class AbstractNode extends AbstractModule {
|
|
|
49
50
|
// const [bw, payloads] = result
|
|
50
51
|
// return [bw, ...payloads]
|
|
51
52
|
// })
|
|
52
|
-
// .
|
|
53
|
+
// .flat()
|
|
53
54
|
// return [...parent, ...children]
|
|
54
55
|
return parent;
|
|
55
56
|
}
|
|
@@ -107,10 +108,47 @@ export class AbstractNode extends AbstractModule {
|
|
|
107
108
|
registeredModules() {
|
|
108
109
|
throw new Error('Method not implemented.');
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Resolves the supplied filter into wrapped modules
|
|
113
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
114
|
+
* const filter = { address: [address] }
|
|
115
|
+
* const mods: ArchivistWrapper[] = await node.resolveWrapped(ArchivistWrapper, filter)
|
|
116
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
117
|
+
* DivinerWrapper, etc.)
|
|
118
|
+
* @param filter The ModuleFilter
|
|
119
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
120
|
+
* the underlying modules matching the supplied filter
|
|
121
|
+
*/
|
|
122
|
+
async resolveWrapped(wrapper, filter) {
|
|
123
|
+
return (await this.resolve(filter)).map((mod) => new wrapper(mod));
|
|
124
|
+
}
|
|
110
125
|
async start() {
|
|
111
126
|
await super.start();
|
|
112
127
|
return this;
|
|
113
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Tries to resolve the supplied filter into wrapped modules
|
|
131
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
132
|
+
* const filter = { address: [address] }
|
|
133
|
+
* const mods: ArchivistWrapper[] = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
134
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
135
|
+
* DivinerWrapper, etc.)
|
|
136
|
+
* @param filter The ModuleFilter
|
|
137
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
138
|
+
* the underlying modules matching the supplied filter
|
|
139
|
+
*/
|
|
140
|
+
async tryResolveWrapped(wrapper, filter) {
|
|
141
|
+
return (await this.tryResolve(filter))
|
|
142
|
+
.map((mod) => {
|
|
143
|
+
try {
|
|
144
|
+
return new wrapper(mod);
|
|
145
|
+
}
|
|
146
|
+
catch (_err) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
.filter(exists);
|
|
151
|
+
}
|
|
114
152
|
unregister(_module) {
|
|
115
153
|
throw new Error('Method not implemented.');
|
|
116
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractNode.js","sourceRoot":"","sources":["../../src/AbstractNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qC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AAC,CAAC;aACD,MAAM,CAAC,MAAM,CAAC,CAAA;IACnB,CAAC;IAED,UAAU,CAAC,OAAgB;QACzB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;;AAQH,2CAA2C;AAC3C,MAAM,OAAgB,OAAkG,SAAQ,YAG/H;CAAG"}
|
package/dist/esm/MemoryNode.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Module, ModuleFilter } from '@xyo-network/module';
|
|
2
2
|
import { AbstractNode, AbstractNodeParams } from './AbstractNode';
|
|
3
3
|
import { NodeConfig } from './Config';
|
|
4
|
+
export interface MemoryNodeParams<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractNodeParams<TConfig, TModule> {
|
|
5
|
+
autoAttachExternallyResolved?: boolean;
|
|
6
|
+
}
|
|
4
7
|
export declare class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractNode<TConfig, TModule> {
|
|
5
8
|
static configSchema: "network.xyo.node.config";
|
|
6
9
|
private registeredModuleMap;
|
|
7
|
-
static create(params?: Partial<
|
|
10
|
+
static create(params?: Partial<MemoryNodeParams>): Promise<MemoryNode>;
|
|
8
11
|
attach(address: string, name?: string): void;
|
|
9
12
|
detach(address: string): void;
|
|
10
13
|
register(module: TModule): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryNode.d.ts","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryNode.d.ts","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+C,MAAM,EAAE,YAAY,EAAkB,MAAM,qBAAqB,CAAA;AAEvH,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAoB,MAAM,UAAU,CAAA;AAEvD,MAAM,WAAW,gBAAgB,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,CACxG,SAAQ,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC;IAC5C,4BAA4B,CAAC,EAAE,OAAO,CAAA;CACvC;AAED,qBAAa,UAAU,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC;IACtI,MAAM,CAAC,YAAY,4BAAmB;IACtC,OAAO,CAAC,mBAAmB,CAA6B;WAElC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAwB5E,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAKrC,MAAM,CAAC,OAAO,EAAE,MAAM;IAItB,QAAQ,CAAC,MAAM,EAAE,OAAO;IAIxB,UAAU;IAMV,iBAAiB;IAMX,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAOlD,UAAU,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAY3D,UAAU,CAAC,MAAM,EAAE,OAAO;CAGpC"}
|
package/dist/esm/MemoryNode.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert';
|
|
2
|
+
import { exists } from '@xylabs/exists';
|
|
3
|
+
import { fulfilled } from '@xylabs/promise';
|
|
4
|
+
import { duplicateModules, mixinResolverEventEmitter } from '@xyo-network/module';
|
|
2
5
|
import { AbstractNode } from './AbstractNode';
|
|
3
6
|
import { NodeConfigSchema } from './Config';
|
|
4
7
|
export class MemoryNode extends AbstractNode {
|
|
5
8
|
static configSchema = NodeConfigSchema;
|
|
6
9
|
registeredModuleMap = new Map();
|
|
7
10
|
static async create(params) {
|
|
8
|
-
|
|
11
|
+
const instance = (await super.create(params));
|
|
12
|
+
if (params?.resolver && params?.autoAttachExternallyResolved) {
|
|
13
|
+
const resolver = mixinResolverEventEmitter(params?.resolver);
|
|
14
|
+
resolver.on('moduleResolved', (args) => {
|
|
15
|
+
const { module, filter } = args;
|
|
16
|
+
try {
|
|
17
|
+
instance.register(module);
|
|
18
|
+
if (filter?.name?.length) {
|
|
19
|
+
filter.name.map((name) => {
|
|
20
|
+
instance.attach(module.address, name);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
instance.attach(module.address);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
params.logger?.error(`Error attaching externally resolved module: 0x${module.address}`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
instance.resolver = resolver;
|
|
32
|
+
}
|
|
33
|
+
return instance;
|
|
9
34
|
}
|
|
10
35
|
attach(address, name) {
|
|
11
36
|
const module = assertEx(this.registeredModuleMap.get(address), 'No module found at that address');
|
|
@@ -31,13 +56,18 @@ export class MemoryNode extends AbstractNode {
|
|
|
31
56
|
const internal = this.internalResolver.resolve(filter);
|
|
32
57
|
const external = this.resolver?.resolve(filter) || [];
|
|
33
58
|
const resolved = await Promise.all([internal, external]);
|
|
34
|
-
return resolved.
|
|
59
|
+
return resolved.flat().filter(exists).filter(duplicateModules);
|
|
35
60
|
}
|
|
36
61
|
async tryResolve(filter) {
|
|
37
62
|
const internal = this.internalResolver.tryResolve(filter);
|
|
38
63
|
const external = this.resolver?.tryResolve(filter) || [];
|
|
39
|
-
const resolved = await Promise.
|
|
40
|
-
return resolved
|
|
64
|
+
const resolved = await Promise.allSettled([internal, external]);
|
|
65
|
+
return resolved
|
|
66
|
+
.filter(fulfilled)
|
|
67
|
+
.map((r) => r.value)
|
|
68
|
+
.flat()
|
|
69
|
+
.filter(exists)
|
|
70
|
+
.filter(duplicateModules);
|
|
41
71
|
}
|
|
42
72
|
unregister(module) {
|
|
43
73
|
this.registeredModuleMap.delete(module.address);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryNode.js","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;
|
|
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,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAwC,MAAM,qBAAqB,CAAA;AAEvH,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAc,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAOvD,MAAM,OAAO,UAAqF,SAAQ,YAA8B;IACtI,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAA;IAC9B,mBAAmB,GAAG,IAAI,GAAG,EAAmB,CAAA;IAExD,MAAM,CAAU,KAAK,CAAC,MAAM,CAAC,MAAkC;QAC7D,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAe,CAAA;QAC3D,IAAI,MAAM,EAAE,QAAQ,IAAI,MAAM,EAAE,4BAA4B,EAAE;YAC5D,MAAM,QAAQ,GAAG,yBAAyB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;YAC5D,QAAQ,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,EAAE;gBACrC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;gBAC/B,IAAI;oBACF,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;oBACzB,I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AC"}
|
package/package.json
CHANGED
|
@@ -11,15 +11,17 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.6.15",
|
|
14
|
-
"@
|
|
15
|
-
"@
|
|
16
|
-
"@xyo-network/
|
|
17
|
-
"@xyo-network/
|
|
18
|
-
"@xyo-network/
|
|
19
|
-
"@xyo-network/
|
|
20
|
-
"@xyo-network/
|
|
21
|
-
"@xyo-network/payload-
|
|
22
|
-
"@xyo-network/
|
|
14
|
+
"@xylabs/exists": "^2.6.15",
|
|
15
|
+
"@xylabs/promise": "^2.6.15",
|
|
16
|
+
"@xyo-network/account": "^2.43.6",
|
|
17
|
+
"@xyo-network/address-payload-plugin": "^2.43.6",
|
|
18
|
+
"@xyo-network/archivist-wrapper": "^2.43.6",
|
|
19
|
+
"@xyo-network/module": "^2.43.6",
|
|
20
|
+
"@xyo-network/module-model": "^2.43.6",
|
|
21
|
+
"@xyo-network/payload-builder": "^2.43.6",
|
|
22
|
+
"@xyo-network/payload-model": "^2.43.6",
|
|
23
|
+
"@xyo-network/payload-wrapper": "^2.43.6",
|
|
24
|
+
"@xyo-network/promise": "^2.43.6"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
27
|
"@xylabs/ts-scripts-yarn3": "^2.12.0"
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
},
|
|
58
60
|
"sideEffects": false,
|
|
59
61
|
"types": "dist/esm/index.d.ts",
|
|
60
|
-
"version": "2.43.
|
|
62
|
+
"version": "2.43.6"
|
|
61
63
|
}
|
package/src/AbstractNode.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { exists } from '@xylabs/exists'
|
|
2
3
|
import { Account } from '@xyo-network/account'
|
|
3
4
|
import { AddressSchema } from '@xyo-network/address-payload-plugin'
|
|
4
5
|
import {
|
|
5
6
|
AbstractModule,
|
|
6
7
|
Module,
|
|
8
|
+
ModuleConstructable,
|
|
7
9
|
ModuleDescription,
|
|
8
10
|
ModuleFilter,
|
|
9
11
|
ModuleParams,
|
|
10
12
|
ModuleQueryResult,
|
|
11
13
|
ModuleRepository,
|
|
14
|
+
ModuleWrapper,
|
|
12
15
|
QueryBoundWitnessWrapper,
|
|
13
16
|
SimpleModuleResolver,
|
|
14
17
|
XyoErrorBuilder,
|
|
@@ -82,7 +85,7 @@ export abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TMod
|
|
|
82
85
|
// const [bw, payloads] = result
|
|
83
86
|
// return [bw, ...payloads]
|
|
84
87
|
// })
|
|
85
|
-
// .
|
|
88
|
+
// .flat()
|
|
86
89
|
// return [...parent, ...children]
|
|
87
90
|
return parent
|
|
88
91
|
}
|
|
@@ -146,11 +149,55 @@ export abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TMod
|
|
|
146
149
|
throw new Error('Method not implemented.')
|
|
147
150
|
}
|
|
148
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Resolves the supplied filter into wrapped modules
|
|
154
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
155
|
+
* const filter = { address: [address] }
|
|
156
|
+
* const mods: ArchivistWrapper[] = await node.resolveWrapped(ArchivistWrapper, filter)
|
|
157
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
158
|
+
* DivinerWrapper, etc.)
|
|
159
|
+
* @param filter The ModuleFilter
|
|
160
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
161
|
+
* the underlying modules matching the supplied filter
|
|
162
|
+
*/
|
|
163
|
+
async resolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(
|
|
164
|
+
wrapper: ModuleConstructable<TModule, T>,
|
|
165
|
+
filter?: ModuleFilter,
|
|
166
|
+
): Promise<T[]> {
|
|
167
|
+
return (await this.resolve(filter)).map((mod) => new wrapper(mod))
|
|
168
|
+
}
|
|
169
|
+
|
|
149
170
|
override async start() {
|
|
150
171
|
await super.start()
|
|
151
172
|
return this
|
|
152
173
|
}
|
|
153
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Tries to resolve the supplied filter into wrapped modules
|
|
177
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
178
|
+
* const filter = { address: [address] }
|
|
179
|
+
* const mods: ArchivistWrapper[] = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
180
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
181
|
+
* DivinerWrapper, etc.)
|
|
182
|
+
* @param filter The ModuleFilter
|
|
183
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
184
|
+
* the underlying modules matching the supplied filter
|
|
185
|
+
*/
|
|
186
|
+
async tryResolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(
|
|
187
|
+
wrapper: ModuleConstructable<TModule, T>,
|
|
188
|
+
filter?: ModuleFilter,
|
|
189
|
+
): Promise<T[]> {
|
|
190
|
+
return (await this.tryResolve(filter))
|
|
191
|
+
.map((mod) => {
|
|
192
|
+
try {
|
|
193
|
+
return new wrapper(mod)
|
|
194
|
+
} catch (_err) {
|
|
195
|
+
return undefined
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
.filter(exists)
|
|
199
|
+
}
|
|
200
|
+
|
|
154
201
|
unregister(_module: TModule): Promisable<void> {
|
|
155
202
|
throw new Error('Method not implemented.')
|
|
156
203
|
}
|
package/src/MemoryNode.spec.ts
CHANGED
|
@@ -14,13 +14,14 @@ import { AbstractModule, Module, ModuleDescription, SimpleModuleResolver } from
|
|
|
14
14
|
import { Account, PayloadWrapper, XyoPayload, XyoPayloadBuilder, XyoPayloadSchema } from '@xyo-network/protocol'
|
|
15
15
|
|
|
16
16
|
import { NodeConfigSchema } from './Config'
|
|
17
|
-
import { MemoryNode } from './MemoryNode'
|
|
17
|
+
import { MemoryNode, MemoryNodeParams } from './MemoryNode'
|
|
18
18
|
|
|
19
19
|
describe('MemoryNode', () => {
|
|
20
20
|
const testAccount1 = new Account({ phrase: 'testPhrase1' })
|
|
21
21
|
const testAccount2 = new Account({ phrase: 'testPhrase2' })
|
|
22
22
|
const testAccount3 = new Account({ phrase: 'testPhrase3' })
|
|
23
23
|
const testAccount4 = new Account({ phrase: 'testPhrase4' })
|
|
24
|
+
const archivistConfig = { schema: MemoryArchivistConfigSchema }
|
|
24
25
|
const nodeConfig = { schema: NodeConfigSchema }
|
|
25
26
|
let node: MemoryNode
|
|
26
27
|
beforeEach(async () => {
|
|
@@ -75,6 +76,44 @@ describe('MemoryNode', () => {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
})
|
|
79
|
+
describe('with autoAttachExternallyResolved true', () => {
|
|
80
|
+
it('attaches external modules to internal resolver', async () => {
|
|
81
|
+
// Arrange
|
|
82
|
+
// Create a MemoryNode with no modules in the internal
|
|
83
|
+
// resolver and one module in the external resolver
|
|
84
|
+
const resolver = new SimpleModuleResolver()
|
|
85
|
+
const internalResolver = new SimpleModuleResolver()
|
|
86
|
+
const params: MemoryNodeParams = {
|
|
87
|
+
autoAttachExternallyResolved: true,
|
|
88
|
+
config: { schema: NodeConfigSchema },
|
|
89
|
+
internalResolver,
|
|
90
|
+
resolver,
|
|
91
|
+
}
|
|
92
|
+
const module = await MemoryArchivist.create()
|
|
93
|
+
const filter = { address: [module.address] }
|
|
94
|
+
resolver.add(module)
|
|
95
|
+
// No modules exist in internal resolver
|
|
96
|
+
expect(await internalResolver.tryResolve(filter)).toBeArrayOfSize(0)
|
|
97
|
+
// Module exists in external resolver
|
|
98
|
+
expect(await resolver.tryResolve(filter)).toBeArrayOfSize(1)
|
|
99
|
+
const node = await MemoryNode.create(params)
|
|
100
|
+
// No modules are attached
|
|
101
|
+
expect(await node.attached()).toBeArrayOfSize(0)
|
|
102
|
+
|
|
103
|
+
// Act
|
|
104
|
+
// Query for unattached module (by address) that exists in
|
|
105
|
+
// external resolver
|
|
106
|
+
expect(await node.tryResolve(filter)).toBeArrayOfSize(1)
|
|
107
|
+
|
|
108
|
+
// Assert
|
|
109
|
+
// Module is now attached
|
|
110
|
+
expect(await node.attached()).toBeArrayOfSize(1)
|
|
111
|
+
// Module exists in internal resolver
|
|
112
|
+
expect(await internalResolver.tryResolve(filter)).toBeArrayOfSize(1)
|
|
113
|
+
// Module still exists in external resolver
|
|
114
|
+
expect(await resolver.tryResolve(filter)).toBeArrayOfSize(1)
|
|
115
|
+
})
|
|
116
|
+
})
|
|
78
117
|
})
|
|
79
118
|
describe('register', () => {
|
|
80
119
|
it('registers module', async () => {
|
|
@@ -180,7 +219,6 @@ describe('MemoryNode', () => {
|
|
|
180
219
|
})
|
|
181
220
|
})
|
|
182
221
|
describe('description', () => {
|
|
183
|
-
const archivistConfig = { schema: MemoryArchivistConfigSchema }
|
|
184
222
|
const validateModuleDescription = (description: ModuleDescription) => {
|
|
185
223
|
expect(description).toBeObject()
|
|
186
224
|
expect(description.address).toBeString()
|
|
@@ -308,6 +346,28 @@ describe('MemoryNode', () => {
|
|
|
308
346
|
})
|
|
309
347
|
})
|
|
310
348
|
})
|
|
349
|
+
describe('tryResolveWrapped', () => {
|
|
350
|
+
beforeEach(async () => {
|
|
351
|
+
const modules = await Promise.all([
|
|
352
|
+
await MemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
|
|
353
|
+
await MemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
|
|
354
|
+
])
|
|
355
|
+
modules.map((mod) => {
|
|
356
|
+
node.register(mod)
|
|
357
|
+
node.attach(mod.address)
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
it('resolves modules wrapped as the specified type', async () => {
|
|
361
|
+
const filter = { address: [testAccount2.addressValue.hex] }
|
|
362
|
+
const modules = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
363
|
+
expect(modules.length).toBeGreaterThan(0)
|
|
364
|
+
modules.map((mod) => {
|
|
365
|
+
expect(mod.get).toBeFunction()
|
|
366
|
+
expect(mod.find).toBeFunction()
|
|
367
|
+
expect(mod.insert).toBeFunction()
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
})
|
|
311
371
|
})
|
|
312
372
|
|
|
313
373
|
const prettyPrintDescription = (description: ModuleDescription) => {
|
package/src/MemoryNode.ts
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import {
|
|
2
|
+
import { exists } from '@xylabs/exists'
|
|
3
|
+
import { fulfilled } from '@xylabs/promise'
|
|
4
|
+
import { duplicateModules, mixinResolverEventEmitter, Module, ModuleFilter, ModuleResolver } from '@xyo-network/module'
|
|
3
5
|
|
|
4
6
|
import { AbstractNode, AbstractNodeParams } from './AbstractNode'
|
|
5
7
|
import { NodeConfig, NodeConfigSchema } from './Config'
|
|
6
8
|
|
|
9
|
+
export interface MemoryNodeParams<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module>
|
|
10
|
+
extends AbstractNodeParams<TConfig, TModule> {
|
|
11
|
+
autoAttachExternallyResolved?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
export class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractNode<TConfig, TModule> {
|
|
8
15
|
static configSchema = NodeConfigSchema
|
|
9
16
|
private registeredModuleMap = new Map<string, TModule>()
|
|
10
17
|
|
|
11
|
-
static override async create(params?: Partial<
|
|
12
|
-
|
|
18
|
+
static override async create(params?: Partial<MemoryNodeParams>): Promise<MemoryNode> {
|
|
19
|
+
const instance = (await super.create(params)) as MemoryNode
|
|
20
|
+
if (params?.resolver && params?.autoAttachExternallyResolved) {
|
|
21
|
+
const resolver = mixinResolverEventEmitter(params?.resolver)
|
|
22
|
+
resolver.on('moduleResolved', (args) => {
|
|
23
|
+
const { module, filter } = args
|
|
24
|
+
try {
|
|
25
|
+
instance.register(module)
|
|
26
|
+
if (filter?.name?.length) {
|
|
27
|
+
filter.name.map((name) => {
|
|
28
|
+
instance.attach(module.address, name)
|
|
29
|
+
})
|
|
30
|
+
} else {
|
|
31
|
+
instance.attach(module.address)
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
params.logger?.error(`Error attaching externally resolved module: 0x${module.address}`)
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
instance.resolver = resolver
|
|
38
|
+
}
|
|
39
|
+
return instance
|
|
13
40
|
}
|
|
14
41
|
|
|
15
42
|
override attach(address: string, name?: string) {
|
|
@@ -41,14 +68,19 @@ export class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends
|
|
|
41
68
|
const internal = this.internalResolver.resolve(filter)
|
|
42
69
|
const external = (this.resolver as ModuleResolver<TModule> | undefined)?.resolve(filter) || []
|
|
43
70
|
const resolved = await Promise.all([internal, external])
|
|
44
|
-
return resolved.
|
|
71
|
+
return resolved.flat().filter(exists).filter(duplicateModules)
|
|
45
72
|
}
|
|
46
73
|
|
|
47
74
|
override async tryResolve(filter?: ModuleFilter): Promise<TModule[]> {
|
|
48
75
|
const internal = this.internalResolver.tryResolve(filter)
|
|
49
76
|
const external = (this.resolver as ModuleResolver<TModule> | undefined)?.tryResolve(filter) || []
|
|
50
|
-
const resolved = await Promise.
|
|
51
|
-
return resolved
|
|
77
|
+
const resolved = await Promise.allSettled([internal, external])
|
|
78
|
+
return resolved
|
|
79
|
+
.filter(fulfilled)
|
|
80
|
+
.map((r) => r.value)
|
|
81
|
+
.flat()
|
|
82
|
+
.filter(exists)
|
|
83
|
+
.filter(duplicateModules)
|
|
52
84
|
}
|
|
53
85
|
|
|
54
86
|
override unregister(module: TModule) {
|