@xyo-network/node 2.43.3 → 2.43.5
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 +31 -5
- package/dist/cjs/AbstractNode.d.ts.map +1 -1
- package/dist/cjs/AbstractNode.js +46 -4
- package/dist/cjs/AbstractNode.js.map +1 -1
- package/dist/cjs/MemoryNode.d.ts +3 -4
- package/dist/cjs/MemoryNode.d.ts.map +1 -1
- package/dist/cjs/MemoryNode.js +22 -6
- package/dist/cjs/MemoryNode.js.map +1 -1
- package/dist/docs.json +3504 -2143
- package/dist/esm/AbstractNode.d.ts +31 -5
- package/dist/esm/AbstractNode.d.ts.map +1 -1
- package/dist/esm/AbstractNode.js +41 -5
- package/dist/esm/AbstractNode.js.map +1 -1
- package/dist/esm/MemoryNode.d.ts +3 -4
- package/dist/esm/MemoryNode.d.ts.map +1 -1
- package/dist/esm/MemoryNode.js +20 -4
- package/dist/esm/MemoryNode.js.map +1 -1
- package/package.json +13 -12
- package/src/AbstractNode.ts +56 -7
- package/src/MemoryNode.spec.ts +23 -1
- package/src/MemoryNode.ts +24 -6
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { Account } from '@xyo-network/account';
|
|
2
|
-
import { AbstractModule, Module, ModuleDescription, ModuleFilter, ModuleParams, ModuleQueryResult,
|
|
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';
|
|
6
6
|
import { NodeModule } from './Node';
|
|
7
|
+
export interface AbstractNodeParams<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends ModuleParams<TConfig> {
|
|
8
|
+
internalResolver?: ModuleRepository<TModule>;
|
|
9
|
+
}
|
|
7
10
|
export declare abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractModule<TConfig> implements NodeModule {
|
|
8
11
|
static readonly configSchema: "network.xyo.node.config";
|
|
9
|
-
protected internalResolver:
|
|
10
|
-
|
|
11
|
-
protected constructor(params: ModuleParams<TConfig>, internalResolver?: ModuleResolver<TModule>);
|
|
12
|
+
protected internalResolver: ModuleRepository<TModule>;
|
|
13
|
+
protected constructor(params: AbstractNodeParams<TConfig, TModule>);
|
|
12
14
|
get isModuleResolver(): boolean;
|
|
13
|
-
static create(params?: Partial<
|
|
15
|
+
static create(params?: Partial<AbstractNodeParams>): Promise<AbstractNode>;
|
|
14
16
|
attached(): Promise<string[]>;
|
|
15
17
|
attachedModules(): Promise<TModule[]>;
|
|
16
18
|
description(): Promise<ModuleDescription>;
|
|
@@ -20,7 +22,31 @@ export declare abstract class AbstractNode<TConfig extends NodeConfig = NodeConf
|
|
|
20
22
|
register(_module: TModule): Promisable<void>;
|
|
21
23
|
registered(): Promisable<string[]>;
|
|
22
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[]>;
|
|
23
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[]>;
|
|
24
50
|
unregister(_module: TModule): Promisable<void>;
|
|
25
51
|
abstract attach(address: string): Promisable<void>;
|
|
26
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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CAAC,SAAS,aAAa,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAC5E,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,EACxC,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC;IAIA,KAAK;IAKpB;;;;;;;;;;OAUG;IACG,iBAAiB,CAAC,CAAC,SAAS,aAAa,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAC/E,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,EACxC,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC;IAYf,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;IAI9C,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;IAClD,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,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,18 +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 { AbstractModule, QueryBoundWitnessWrapper, SimpleModuleResolver, XyoErrorBuilder, } from '@xyo-network/module';
|
|
5
6
|
import { XyoPayloadBuilder } from '@xyo-network/payload-builder';
|
|
6
7
|
import { NodeConfigSchema } from './Config';
|
|
7
8
|
import { XyoNodeAttachedQuerySchema, XyoNodeAttachQuerySchema, XyoNodeDetachQuerySchema, XyoNodeRegisteredQuerySchema } from './Queries';
|
|
8
|
-
//const childModuleDiscoverQueryPayload = PayloadWrapper.parse<AbstractModuleDiscoverQuery>({ schema: AbstractModuleDiscoverQuerySchema })
|
|
9
9
|
export class AbstractNode extends AbstractModule {
|
|
10
10
|
static configSchema = NodeConfigSchema;
|
|
11
11
|
internalResolver;
|
|
12
|
-
|
|
13
|
-
constructor(params, internalResolver) {
|
|
12
|
+
constructor(params) {
|
|
14
13
|
super(params);
|
|
15
|
-
this.internalResolver = internalResolver ?? new SimpleModuleResolver();
|
|
14
|
+
this.internalResolver = params.internalResolver ?? new SimpleModuleResolver();
|
|
16
15
|
}
|
|
17
16
|
get isModuleResolver() {
|
|
18
17
|
return true;
|
|
@@ -51,7 +50,7 @@ export class AbstractNode extends AbstractModule {
|
|
|
51
50
|
// const [bw, payloads] = result
|
|
52
51
|
// return [bw, ...payloads]
|
|
53
52
|
// })
|
|
54
|
-
// .
|
|
53
|
+
// .flat()
|
|
55
54
|
// return [...parent, ...children]
|
|
56
55
|
return parent;
|
|
57
56
|
}
|
|
@@ -109,10 +108,47 @@ export class AbstractNode extends AbstractModule {
|
|
|
109
108
|
registeredModules() {
|
|
110
109
|
throw new Error('Method not implemented.');
|
|
111
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
|
+
}
|
|
112
125
|
async start() {
|
|
113
126
|
await super.start();
|
|
114
127
|
return this;
|
|
115
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
|
+
}
|
|
116
152
|
unregister(_module) {
|
|
117
153
|
throw new Error('Method not implemented.');
|
|
118
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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AA;aACjB;QACH,CAAC,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,11 +1,10 @@
|
|
|
1
|
-
import { Module, ModuleFilter
|
|
2
|
-
import { AbstractNode } from './AbstractNode';
|
|
1
|
+
import { Module, ModuleFilter } from '@xyo-network/module';
|
|
2
|
+
import { AbstractNode, AbstractNodeParams } from './AbstractNode';
|
|
3
3
|
import { NodeConfig } from './Config';
|
|
4
4
|
export declare class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractNode<TConfig, TModule> {
|
|
5
5
|
static configSchema: "network.xyo.node.config";
|
|
6
|
-
protected internalResolver: SimpleModuleResolver<TModule>;
|
|
7
6
|
private registeredModuleMap;
|
|
8
|
-
static create(params?:
|
|
7
|
+
static create(params?: Partial<AbstractNodeParams>): Promise<MemoryNode>;
|
|
9
8
|
attach(address: string, name?: string): void;
|
|
10
9
|
detach(address: string): void;
|
|
11
10
|
register(module: TModule): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryNode.d.ts","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"MemoryNode.d.ts","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAkB,MAAM,qBAAqB,CAAA;AAE1E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAoB,MAAM,UAAU,CAAA;AAevD,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,kBAAkB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9E,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;IAO3D,UAAU,CAAC,MAAM,EAAE,OAAO;CAGpC"}
|
package/dist/esm/MemoryNode.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert';
|
|
2
|
-
import { SimpleModuleResolver } from '@xyo-network/module';
|
|
3
2
|
import { AbstractNode } from './AbstractNode';
|
|
4
3
|
import { NodeConfigSchema } from './Config';
|
|
4
|
+
/**
|
|
5
|
+
* Used to filter duplicates during module resolution since we search
|
|
6
|
+
* internal and external resolvers for modules
|
|
7
|
+
* @param value Current Module
|
|
8
|
+
* @param index Current Module's index
|
|
9
|
+
* @param array Module Array
|
|
10
|
+
* @returns True if the Module's address is the first occurrence of
|
|
11
|
+
* that address in the array, false otherwise
|
|
12
|
+
*/
|
|
13
|
+
const duplicateModules = (value, index, array) => {
|
|
14
|
+
return array.findIndex((v) => v.address === value.address) === index;
|
|
15
|
+
};
|
|
5
16
|
export class MemoryNode extends AbstractNode {
|
|
6
17
|
static configSchema = NodeConfigSchema;
|
|
7
|
-
internalResolver = new SimpleModuleResolver();
|
|
8
18
|
registeredModuleMap = new Map();
|
|
9
19
|
static async create(params) {
|
|
10
20
|
return (await super.create(params));
|
|
@@ -30,10 +40,16 @@ export class MemoryNode extends AbstractNode {
|
|
|
30
40
|
});
|
|
31
41
|
}
|
|
32
42
|
async resolve(filter) {
|
|
33
|
-
|
|
43
|
+
const internal = this.internalResolver.resolve(filter);
|
|
44
|
+
const external = this.resolver?.resolve(filter) || [];
|
|
45
|
+
const resolved = await Promise.all([internal, external]);
|
|
46
|
+
return resolved.flat().filter(duplicateModules);
|
|
34
47
|
}
|
|
35
48
|
async tryResolve(filter) {
|
|
36
|
-
|
|
49
|
+
const internal = this.internalResolver.tryResolve(filter);
|
|
50
|
+
const external = this.resolver?.tryResolve(filter) || [];
|
|
51
|
+
const resolved = await Promise.all([internal, external]);
|
|
52
|
+
return resolved.flat().filter(duplicateModules);
|
|
37
53
|
}
|
|
38
54
|
unregister(module) {
|
|
39
55
|
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;AAGzC,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAc,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,KAAe,EAAmB,EAAE;IAC1F,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,C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AAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACtD,MAAM,QAAQ,GAAI,IAAI,CAAC,QAAgD,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QAC9F,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;QACxD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACjD,CAAC;IAEQ,KAAK,CAAC,UAAU,CAAC,MAAqB;QAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QACzD,MAAM,QAAQ,GAAI,IAAI,CAAC,QAAgD,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QACjG,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;QACxD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACjD,CAAC;IAEQ,UAAU,CAAC,MAAe;QACjC,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,19 +10,20 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^2.6.
|
|
14
|
-
"@
|
|
15
|
-
"@xyo-network/
|
|
16
|
-
"@xyo-network/
|
|
17
|
-
"@xyo-network/
|
|
18
|
-
"@xyo-network/module
|
|
19
|
-
"@xyo-network/
|
|
20
|
-
"@xyo-network/payload-
|
|
21
|
-
"@xyo-network/payload-
|
|
22
|
-
"@xyo-network/
|
|
13
|
+
"@xylabs/assert": "^2.6.15",
|
|
14
|
+
"@xylabs/exists": "^2.6.15",
|
|
15
|
+
"@xyo-network/account": "^2.43.5",
|
|
16
|
+
"@xyo-network/address-payload-plugin": "^2.43.5",
|
|
17
|
+
"@xyo-network/archivist-wrapper": "^2.43.5",
|
|
18
|
+
"@xyo-network/module": "^2.43.5",
|
|
19
|
+
"@xyo-network/module-model": "^2.43.5",
|
|
20
|
+
"@xyo-network/payload-builder": "^2.43.5",
|
|
21
|
+
"@xyo-network/payload-model": "^2.43.5",
|
|
22
|
+
"@xyo-network/payload-wrapper": "^2.43.5",
|
|
23
|
+
"@xyo-network/promise": "^2.43.5"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^2.
|
|
26
|
+
"@xylabs/ts-scripts-yarn3": "^2.12.0"
|
|
26
27
|
},
|
|
27
28
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
28
29
|
"browser": "dist/esm/index.js",
|
|
@@ -57,5 +58,5 @@
|
|
|
57
58
|
},
|
|
58
59
|
"sideEffects": false,
|
|
59
60
|
"types": "dist/esm/index.d.ts",
|
|
60
|
-
"version": "2.43.
|
|
61
|
+
"version": "2.43.5"
|
|
61
62
|
}
|
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,
|
|
@@ -24,25 +27,27 @@ import { XyoNodeAttachedQuerySchema, XyoNodeAttachQuerySchema, XyoNodeDetachQuer
|
|
|
24
27
|
|
|
25
28
|
//const childModuleDiscoverQueryPayload = PayloadWrapper.parse<AbstractModuleDiscoverQuery>({ schema: AbstractModuleDiscoverQuerySchema })
|
|
26
29
|
|
|
30
|
+
export interface AbstractNodeParams<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends ModuleParams<TConfig> {
|
|
31
|
+
internalResolver?: ModuleRepository<TModule>
|
|
32
|
+
}
|
|
27
33
|
export abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module>
|
|
28
34
|
extends AbstractModule<TConfig>
|
|
29
35
|
implements NodeModule
|
|
30
36
|
{
|
|
31
37
|
static readonly configSchema = NodeConfigSchema
|
|
32
38
|
|
|
33
|
-
protected internalResolver:
|
|
34
|
-
private _archivist?: Module
|
|
39
|
+
protected internalResolver: ModuleRepository<TModule>
|
|
35
40
|
|
|
36
|
-
protected constructor(params:
|
|
41
|
+
protected constructor(params: AbstractNodeParams<TConfig, TModule>) {
|
|
37
42
|
super(params)
|
|
38
|
-
this.internalResolver = internalResolver ?? new SimpleModuleResolver<TModule>()
|
|
43
|
+
this.internalResolver = params.internalResolver ?? new SimpleModuleResolver<TModule>()
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
get isModuleResolver(): boolean {
|
|
42
47
|
return true
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
static override async create(params?: Partial<
|
|
50
|
+
static override async create(params?: Partial<AbstractNodeParams>): Promise<AbstractNode> {
|
|
46
51
|
return (await super.create(params)) as AbstractNode
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -79,7 +84,7 @@ export abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TMod
|
|
|
79
84
|
// const [bw, payloads] = result
|
|
80
85
|
// return [bw, ...payloads]
|
|
81
86
|
// })
|
|
82
|
-
// .
|
|
87
|
+
// .flat()
|
|
83
88
|
// return [...parent, ...children]
|
|
84
89
|
return parent
|
|
85
90
|
}
|
|
@@ -143,11 +148,55 @@ export abstract class AbstractNode<TConfig extends NodeConfig = NodeConfig, TMod
|
|
|
143
148
|
throw new Error('Method not implemented.')
|
|
144
149
|
}
|
|
145
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Resolves the supplied filter into wrapped modules
|
|
153
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
154
|
+
* const filter = { address: [address] }
|
|
155
|
+
* const mods: ArchivistWrapper[] = await node.resolveWrapped(ArchivistWrapper, filter)
|
|
156
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
157
|
+
* DivinerWrapper, etc.)
|
|
158
|
+
* @param filter The ModuleFilter
|
|
159
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
160
|
+
* the underlying modules matching the supplied filter
|
|
161
|
+
*/
|
|
162
|
+
async resolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(
|
|
163
|
+
wrapper: ModuleConstructable<TModule, T>,
|
|
164
|
+
filter?: ModuleFilter,
|
|
165
|
+
): Promise<T[]> {
|
|
166
|
+
return (await this.resolve(filter)).map((mod) => new wrapper(mod))
|
|
167
|
+
}
|
|
168
|
+
|
|
146
169
|
override async start() {
|
|
147
170
|
await super.start()
|
|
148
171
|
return this
|
|
149
172
|
}
|
|
150
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Tries to resolve the supplied filter into wrapped modules
|
|
176
|
+
* @example <caption>Example using ArchivistWrapper</caption>
|
|
177
|
+
* const filter = { address: [address] }
|
|
178
|
+
* const mods: ArchivistWrapper[] = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
179
|
+
* @param wrapper The ModuleWrapper class (ArchivistWrapper,
|
|
180
|
+
* DivinerWrapper, etc.)
|
|
181
|
+
* @param filter The ModuleFilter
|
|
182
|
+
* @returns An array of ModuleWrapper instances corresponding to
|
|
183
|
+
* the underlying modules matching the supplied filter
|
|
184
|
+
*/
|
|
185
|
+
async tryResolveWrapped<T extends ModuleWrapper<TModule> = ModuleWrapper<TModule>>(
|
|
186
|
+
wrapper: ModuleConstructable<TModule, T>,
|
|
187
|
+
filter?: ModuleFilter,
|
|
188
|
+
): Promise<T[]> {
|
|
189
|
+
return (await this.tryResolve(filter))
|
|
190
|
+
.map((mod) => {
|
|
191
|
+
try {
|
|
192
|
+
return new wrapper(mod)
|
|
193
|
+
} catch (_err) {
|
|
194
|
+
return undefined
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
.filter(exists)
|
|
198
|
+
}
|
|
199
|
+
|
|
151
200
|
unregister(_module: TModule): Promisable<void> {
|
|
152
201
|
throw new Error('Method not implemented.')
|
|
153
202
|
}
|
package/src/MemoryNode.spec.ts
CHANGED
|
@@ -21,6 +21,7 @@ describe('MemoryNode', () => {
|
|
|
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 () => {
|
|
@@ -180,7 +181,6 @@ describe('MemoryNode', () => {
|
|
|
180
181
|
})
|
|
181
182
|
})
|
|
182
183
|
describe('description', () => {
|
|
183
|
-
const archivistConfig = { schema: MemoryArchivistConfigSchema }
|
|
184
184
|
const validateModuleDescription = (description: ModuleDescription) => {
|
|
185
185
|
expect(description).toBeObject()
|
|
186
186
|
expect(description.address).toBeString()
|
|
@@ -308,6 +308,28 @@ describe('MemoryNode', () => {
|
|
|
308
308
|
})
|
|
309
309
|
})
|
|
310
310
|
})
|
|
311
|
+
describe('tryResolveWrapped', () => {
|
|
312
|
+
beforeEach(async () => {
|
|
313
|
+
const modules = await Promise.all([
|
|
314
|
+
await MemoryArchivist.create({ account: testAccount2, config: archivistConfig }),
|
|
315
|
+
await MemoryArchivist.create({ account: testAccount3, config: archivistConfig }),
|
|
316
|
+
])
|
|
317
|
+
modules.map((mod) => {
|
|
318
|
+
node.register(mod)
|
|
319
|
+
node.attach(mod.address)
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
it('resolves modules wrapped as the specified type', async () => {
|
|
323
|
+
const filter = { address: [testAccount2.addressValue.hex] }
|
|
324
|
+
const modules = await node.tryResolveWrapped(ArchivistWrapper, filter)
|
|
325
|
+
expect(modules.length).toBeGreaterThan(0)
|
|
326
|
+
modules.map((mod) => {
|
|
327
|
+
expect(mod.get).toBeFunction()
|
|
328
|
+
expect(mod.find).toBeFunction()
|
|
329
|
+
expect(mod.insert).toBeFunction()
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
})
|
|
311
333
|
})
|
|
312
334
|
|
|
313
335
|
const prettyPrintDescription = (description: ModuleDescription) => {
|
package/src/MemoryNode.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { Module, ModuleFilter,
|
|
2
|
+
import { Module, ModuleFilter, ModuleResolver } from '@xyo-network/module'
|
|
3
3
|
|
|
4
|
-
import { AbstractNode } from './AbstractNode'
|
|
4
|
+
import { AbstractNode, AbstractNodeParams } from './AbstractNode'
|
|
5
5
|
import { NodeConfig, NodeConfigSchema } from './Config'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Used to filter duplicates during module resolution since we search
|
|
9
|
+
* internal and external resolvers for modules
|
|
10
|
+
* @param value Current Module
|
|
11
|
+
* @param index Current Module's index
|
|
12
|
+
* @param array Module Array
|
|
13
|
+
* @returns True if the Module's address is the first occurrence of
|
|
14
|
+
* that address in the array, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
const duplicateModules = (value: Module, index: number, array: Module[]): value is Module => {
|
|
17
|
+
return array.findIndex((v) => v.address === value.address) === index
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
export class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends Module = Module> extends AbstractNode<TConfig, TModule> {
|
|
8
21
|
static configSchema = NodeConfigSchema
|
|
9
|
-
protected override internalResolver: SimpleModuleResolver<TModule> = new SimpleModuleResolver<TModule>()
|
|
10
22
|
private registeredModuleMap = new Map<string, TModule>()
|
|
11
23
|
|
|
12
|
-
static override async create(params?:
|
|
24
|
+
static override async create(params?: Partial<AbstractNodeParams>): Promise<MemoryNode> {
|
|
13
25
|
return (await super.create(params)) as MemoryNode
|
|
14
26
|
}
|
|
15
27
|
|
|
@@ -39,11 +51,17 @@ export class MemoryNode<TConfig extends NodeConfig = NodeConfig, TModule extends
|
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
override async resolve(filter?: ModuleFilter): Promise<TModule[]> {
|
|
42
|
-
|
|
54
|
+
const internal = this.internalResolver.resolve(filter)
|
|
55
|
+
const external = (this.resolver as ModuleResolver<TModule> | undefined)?.resolve(filter) || []
|
|
56
|
+
const resolved = await Promise.all([internal, external])
|
|
57
|
+
return resolved.flat().filter(duplicateModules)
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
override async tryResolve(filter?: ModuleFilter): Promise<TModule[]> {
|
|
46
|
-
|
|
61
|
+
const internal = this.internalResolver.tryResolve(filter)
|
|
62
|
+
const external = (this.resolver as ModuleResolver<TModule> | undefined)?.tryResolve(filter) || []
|
|
63
|
+
const resolved = await Promise.all([internal, external])
|
|
64
|
+
return resolved.flat().filter(duplicateModules)
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
override unregister(module: TModule) {
|