@xyo-network/module-abstract 2.65.5 → 2.66.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.
- package/dist/cjs/AbstractIndirectModule.js +88 -36
- package/dist/cjs/AbstractIndirectModule.js.map +1 -1
- package/dist/esm/AbstractIndirectModule.js +80 -34
- package/dist/esm/AbstractIndirectModule.js.map +1 -1
- package/dist/types/AbstractIndirectModule.d.ts +10 -7
- package/dist/types/AbstractIndirectModule.d.ts.map +1 -1
- package/package.json +22 -22
- package/src/AbstractIndirectModule.ts +87 -36
- package/dist/docs.json +0 -35184
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractIndirectModule.d.ts","sourceRoot":"","sources":["../../src/AbstractIndirectModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AbstractIndirectModule.d.ts","sourceRoot":"","sources":["../../src/AbstractIndirectModule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAEhE,OAAO,EAAuB,iBAAiB,EAAsD,MAAM,mCAAmC,CAAA;AAC9I,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAG9D,OAAO,EAAE,qBAAqB,EAA+B,MAAM,6BAA6B,CAAA;AAChG,OAAO,EAEL,0BAA0B,EAE1B,eAAe,EACf,sBAAsB,EAEtB,cAAc,EAId,YAAY,EAEZ,wBAAwB,EAGxB,eAAe,EAEf,YAAY,EACZ,mBAAmB,EAEnB,YAAY,EAGZ,eAAe,EACf,iBAAiB,EAEjB,YAAY,EAGb,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,UAAU,EA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GAAG,UAAU,CAAC,OAAO,CAAC;IAK7D,SAAS,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,eAAe;IAI1D,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,OAAO;IA2B3E,SAAS,CAAC,cAAc,+CAAmC;YAE7C,YAAY;CAS3B"}
|
package/package.json
CHANGED
|
@@ -12,30 +12,30 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.9.3",
|
|
14
14
|
"@xylabs/exists": "^2.9.3",
|
|
15
|
-
"@xyo-network/account": "^2.
|
|
16
|
-
"@xyo-network/account-model": "^2.
|
|
17
|
-
"@xyo-network/address-payload-plugin": "^2.
|
|
18
|
-
"@xyo-network/archivist-model": "^2.
|
|
19
|
-
"@xyo-network/archivist-wrapper": "^2.
|
|
20
|
-
"@xyo-network/boundwitness-builder": "^2.
|
|
21
|
-
"@xyo-network/boundwitness-model": "^2.
|
|
22
|
-
"@xyo-network/config-payload-plugin": "^2.
|
|
23
|
-
"@xyo-network/core": "^2.
|
|
24
|
-
"@xyo-network/error": "^2.
|
|
25
|
-
"@xyo-network/manifest-model": "^2.
|
|
26
|
-
"@xyo-network/module-events": "^2.
|
|
27
|
-
"@xyo-network/module-model": "^2.
|
|
28
|
-
"@xyo-network/payload-builder": "^2.
|
|
29
|
-
"@xyo-network/payload-model": "^2.
|
|
30
|
-
"@xyo-network/payload-wrapper": "^2.
|
|
31
|
-
"@xyo-network/promise": "^2.
|
|
32
|
-
"@xyo-network/query-payload-plugin": "^2.
|
|
33
|
-
"@xyo-network/shared": "^2.
|
|
15
|
+
"@xyo-network/account": "^2.66.0",
|
|
16
|
+
"@xyo-network/account-model": "^2.66.0",
|
|
17
|
+
"@xyo-network/address-payload-plugin": "^2.66.0",
|
|
18
|
+
"@xyo-network/archivist-model": "^2.66.0",
|
|
19
|
+
"@xyo-network/archivist-wrapper": "^2.66.0",
|
|
20
|
+
"@xyo-network/boundwitness-builder": "^2.66.0",
|
|
21
|
+
"@xyo-network/boundwitness-model": "^2.66.0",
|
|
22
|
+
"@xyo-network/config-payload-plugin": "^2.66.0",
|
|
23
|
+
"@xyo-network/core": "^2.66.0",
|
|
24
|
+
"@xyo-network/error": "^2.66.0",
|
|
25
|
+
"@xyo-network/manifest-model": "^2.66.0",
|
|
26
|
+
"@xyo-network/module-events": "^2.66.0",
|
|
27
|
+
"@xyo-network/module-model": "^2.66.0",
|
|
28
|
+
"@xyo-network/payload-builder": "^2.66.0",
|
|
29
|
+
"@xyo-network/payload-model": "^2.66.0",
|
|
30
|
+
"@xyo-network/payload-wrapper": "^2.66.0",
|
|
31
|
+
"@xyo-network/promise": "^2.66.0",
|
|
32
|
+
"@xyo-network/query-payload-plugin": "^2.66.0",
|
|
33
|
+
"@xyo-network/shared": "^2.66.0",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@xylabs/ts-scripts-yarn3": "^2.18.
|
|
38
|
-
"@xylabs/tsconfig": "^2.18.
|
|
37
|
+
"@xylabs/ts-scripts-yarn3": "^2.18.11",
|
|
38
|
+
"@xylabs/tsconfig": "^2.18.11",
|
|
39
39
|
"jest": "^29.6.1",
|
|
40
40
|
"jest-mock-extended": "^3.0.4",
|
|
41
41
|
"typescript": "^5.1.6"
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
},
|
|
74
74
|
"sideEffects": false,
|
|
75
75
|
"types": "dist/types/index.d.ts",
|
|
76
|
-
"version": "2.
|
|
76
|
+
"version": "2.66.0"
|
|
77
77
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
import { assertEx } from '@xylabs/assert'
|
|
2
3
|
import { exists } from '@xylabs/exists'
|
|
3
4
|
import { HDWallet } from '@xyo-network/account'
|
|
@@ -8,7 +9,7 @@ import { IndirectArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
|
8
9
|
import { BoundWitnessBuilder, QueryBoundWitness, QueryBoundWitnessBuilder, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
|
|
9
10
|
import { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
10
11
|
import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin'
|
|
11
|
-
import { handleErrorAsync } from '@xyo-network/error'
|
|
12
|
+
import { handleError, handleErrorAsync } from '@xyo-network/error'
|
|
12
13
|
import { ModuleManifestPayload, ModuleManifestPayloadSchema } from '@xyo-network/manifest-model'
|
|
13
14
|
import {
|
|
14
15
|
AccountModuleParams,
|
|
@@ -29,6 +30,8 @@ import {
|
|
|
29
30
|
ModuleEventData,
|
|
30
31
|
ModuleFactory,
|
|
31
32
|
ModuleFilter,
|
|
33
|
+
ModuleFilterOptions,
|
|
34
|
+
ModuleManifestQuerySchema,
|
|
32
35
|
ModuleParams,
|
|
33
36
|
ModuleQueriedEventArgs,
|
|
34
37
|
ModuleQuery,
|
|
@@ -44,7 +47,7 @@ import { ModuleError, Payload, Query } from '@xyo-network/payload-model'
|
|
|
44
47
|
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
45
48
|
import { Promisable, PromiseEx } from '@xyo-network/promise'
|
|
46
49
|
import { QueryPayload, QuerySchema } from '@xyo-network/query-payload-plugin'
|
|
47
|
-
import { IdLogger } from '@xyo-network/shared'
|
|
50
|
+
import { getFunctionName, IdLogger } from '@xyo-network/shared'
|
|
48
51
|
import compact from 'lodash/compact'
|
|
49
52
|
|
|
50
53
|
import { BaseEmitter } from './BaseEmitter'
|
|
@@ -53,7 +56,6 @@ import { ModuleConfigQueryValidator, Queryable, SupportedQueryValidator } from '
|
|
|
53
56
|
import { CompositeModuleResolver } from './Resolver'
|
|
54
57
|
|
|
55
58
|
/** @description Abstract class for modules that allow access only through querying and not through direct calls */
|
|
56
|
-
|
|
57
59
|
export abstract class AbstractIndirectModule<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>
|
|
58
60
|
extends BaseEmitter<TParams, TEventData>
|
|
59
61
|
implements IndirectModule<TParams, TEventData>, IndirectModule
|
|
@@ -71,15 +73,18 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
71
73
|
[ModuleAddressQuerySchema]: '1',
|
|
72
74
|
[ModuleDescribeQuerySchema]: '4',
|
|
73
75
|
[ModuleDiscoverQuerySchema]: '2',
|
|
76
|
+
[ModuleManifestQuerySchema]: '5',
|
|
74
77
|
[ModuleSubscribeQuerySchema]: '3',
|
|
75
78
|
}
|
|
76
79
|
protected readonly _queryAccounts: Record<ModuleQueryBase['schema'], AccountInstance | undefined> = {
|
|
77
80
|
[ModuleAddressQuerySchema]: undefined,
|
|
78
81
|
[ModuleDescribeQuerySchema]: undefined,
|
|
79
82
|
[ModuleDiscoverQuerySchema]: undefined,
|
|
83
|
+
[ModuleManifestQuerySchema]: undefined,
|
|
80
84
|
[ModuleSubscribeQuerySchema]: undefined,
|
|
81
85
|
}
|
|
82
|
-
protected _started =
|
|
86
|
+
protected _started: Promise<boolean> | true | undefined = undefined
|
|
87
|
+
protected _starting: Promise<boolean> | true | undefined = undefined
|
|
83
88
|
protected readonly moduleConfigQueryValidator: Queryable
|
|
84
89
|
protected readonly supportedQueryValidator: Queryable
|
|
85
90
|
|
|
@@ -149,7 +154,6 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
149
154
|
const mutatedParams = { ...params, config: mutatedConfig } as TModule['params']
|
|
150
155
|
const newModule = new this(AbstractIndirectModule.privateConstructorKey, mutatedParams)
|
|
151
156
|
await newModule.loadAccount?.()
|
|
152
|
-
await newModule.start?.()
|
|
153
157
|
return newModule
|
|
154
158
|
}
|
|
155
159
|
|
|
@@ -206,7 +210,7 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
206
210
|
queryConfig?: TConfig,
|
|
207
211
|
): Promise<ModuleQueryResult> {
|
|
208
212
|
return await this.busy(async () => {
|
|
209
|
-
this.started('throw')
|
|
213
|
+
await this.started('throw')
|
|
210
214
|
const result = await this.queryHandler(assertEx(QueryBoundWitnessWrapper.unwrap(query)), payloads, queryConfig)
|
|
211
215
|
|
|
212
216
|
const args: ModuleQueriedEventArgs = { module: this, payloads, query, result }
|
|
@@ -230,47 +234,83 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
230
234
|
return validators.every((validator) => validator(query, payloads))
|
|
231
235
|
}
|
|
232
236
|
|
|
233
|
-
async resolve<TModule extends IndirectModule = IndirectModule>(filter?: ModuleFilter): Promise<TModule[]>
|
|
234
|
-
async resolve<TModule extends IndirectModule = IndirectModule>(nameOrAddress: string): Promise<TModule | undefined>
|
|
237
|
+
async resolve<TModule extends IndirectModule = IndirectModule>(filter?: ModuleFilter, options?: ModuleFilterOptions): Promise<TModule[]>
|
|
238
|
+
async resolve<TModule extends IndirectModule = IndirectModule>(nameOrAddress: string, options?: ModuleFilterOptions): Promise<TModule | undefined>
|
|
235
239
|
async resolve<TModule extends IndirectModule = IndirectModule>(
|
|
236
240
|
nameOrAddressOrFilter?: ModuleFilter | string,
|
|
241
|
+
options?: ModuleFilterOptions,
|
|
237
242
|
): Promise<TModule | TModule[] | undefined> {
|
|
243
|
+
const direction = options?.direction ?? 'all'
|
|
244
|
+
const up = direction === 'up' || direction === 'all'
|
|
245
|
+
const down = direction === 'down' || direction === 'all'
|
|
238
246
|
switch (typeof nameOrAddressOrFilter) {
|
|
239
247
|
case 'string': {
|
|
240
|
-
return (
|
|
248
|
+
return (
|
|
249
|
+
(down ? await this.downResolver.resolve<TModule>(nameOrAddressOrFilter) : undefined) ??
|
|
250
|
+
(up ? await this.upResolver.resolve<TModule>(nameOrAddressOrFilter) : undefined)
|
|
251
|
+
)
|
|
241
252
|
}
|
|
242
253
|
default: {
|
|
243
254
|
const filter: ModuleFilter | undefined = nameOrAddressOrFilter
|
|
244
|
-
return [
|
|
255
|
+
return [
|
|
256
|
+
...(down ? await this.downResolver.resolve<TModule>(filter) : []),
|
|
257
|
+
...(up ? await this.upResolver.resolve<TModule>(filter) : []),
|
|
258
|
+
].filter(duplicateModules)
|
|
245
259
|
}
|
|
246
260
|
}
|
|
247
261
|
}
|
|
248
262
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.
|
|
263
|
+
start(_timeout?: number): Promise<boolean> | boolean {
|
|
264
|
+
//using promise as mutex
|
|
265
|
+
this._starting = this._starting ?? this.startHandler()
|
|
266
|
+
return this._starting
|
|
253
267
|
}
|
|
254
268
|
|
|
255
|
-
started(notStartedAction
|
|
269
|
+
async started(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log', tryStart = true): Promise<boolean> {
|
|
270
|
+
if (this._started === true) {
|
|
271
|
+
return true
|
|
272
|
+
}
|
|
256
273
|
if (!this._started) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
274
|
+
//using promise as mutex
|
|
275
|
+
this._started = (async () => {
|
|
276
|
+
if (tryStart) {
|
|
277
|
+
try {
|
|
278
|
+
await this.start()
|
|
279
|
+
return true
|
|
280
|
+
} catch (ex) {
|
|
281
|
+
handleError(ex, (error) => {
|
|
282
|
+
this.logger?.warn(`Autostart of Module Failed: ${error.message})`)
|
|
283
|
+
this._started = undefined
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
switch (notStartedAction) {
|
|
288
|
+
case 'throw':
|
|
289
|
+
throw Error(`Module not Started [${this.address}]`)
|
|
290
|
+
case 'warn':
|
|
291
|
+
this.logger?.warn('Module not started')
|
|
292
|
+
break
|
|
293
|
+
case 'error':
|
|
294
|
+
this.logger?.error('Module not started')
|
|
295
|
+
break
|
|
296
|
+
case 'none':
|
|
297
|
+
break
|
|
298
|
+
case 'log':
|
|
299
|
+
default: {
|
|
300
|
+
this.logger?.log('Module not started')
|
|
301
|
+
break
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return false
|
|
305
|
+
})()
|
|
272
306
|
}
|
|
273
|
-
return this._started
|
|
307
|
+
return await this._started
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async stop(_timeout?: number): Promise<boolean> {
|
|
311
|
+
return await this.busy(async () => {
|
|
312
|
+
return await this.stopHandler()
|
|
313
|
+
})
|
|
274
314
|
}
|
|
275
315
|
|
|
276
316
|
protected bindHashes(hashes: string[], schema: SchemaString[], account?: AccountInstance) {
|
|
@@ -384,7 +424,7 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
384
424
|
}
|
|
385
425
|
|
|
386
426
|
protected manifestHandler(): Promisable<ModuleManifestPayload> {
|
|
387
|
-
const name =
|
|
427
|
+
const name = this.config.name ?? 'Anonymous'
|
|
388
428
|
return { config: { name, ...this.config }, schema: ModuleManifestPayloadSchema }
|
|
389
429
|
}
|
|
390
430
|
|
|
@@ -417,7 +457,7 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
417
457
|
payloads?: Payload[],
|
|
418
458
|
queryConfig?: TConfig,
|
|
419
459
|
): Promise<ModuleQueryResult> {
|
|
420
|
-
this.started('throw')
|
|
460
|
+
await this.started('throw')
|
|
421
461
|
const wrapper = QueryBoundWitnessWrapper.parseQuery<ModuleQuery>(query, payloads)
|
|
422
462
|
if (!this.allowAnonymous) {
|
|
423
463
|
if (query.addresses.length === 0) {
|
|
@@ -431,6 +471,10 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
431
471
|
const queryAccount = this.ephemeralQueryAccountEnabled ? await HDWallet.random() : undefined
|
|
432
472
|
try {
|
|
433
473
|
switch (queryPayload.schema) {
|
|
474
|
+
case ModuleManifestQuerySchema: {
|
|
475
|
+
resultPayloads.push(await this.manifestHandler())
|
|
476
|
+
break
|
|
477
|
+
}
|
|
434
478
|
case ModuleDiscoverQuerySchema: {
|
|
435
479
|
resultPayloads.push(...(await this.discoverHandler()))
|
|
436
480
|
break
|
|
@@ -467,9 +511,16 @@ export abstract class AbstractIndirectModule<TParams extends ModuleParams = Modu
|
|
|
467
511
|
|
|
468
512
|
protected readArchivist = () => this.getArchivist('read')
|
|
469
513
|
|
|
470
|
-
protected
|
|
471
|
-
this.
|
|
472
|
-
|
|
514
|
+
protected async startHandler(): Promise<boolean> {
|
|
515
|
+
this.validateConfig()
|
|
516
|
+
await this.initializeQueryAccounts()
|
|
517
|
+
this._started = true
|
|
518
|
+
return true
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
protected stopHandler(_timeout?: number): Promisable<boolean> {
|
|
522
|
+
this._started = undefined
|
|
523
|
+
return true
|
|
473
524
|
}
|
|
474
525
|
|
|
475
526
|
protected subscribeHandler(_queryAccount?: AccountInstance) {
|