@xyo-network/module-abstract 2.95.2 → 2.95.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/browser/AbstractModule.d.cts +5 -1
  2. package/dist/browser/AbstractModule.d.cts.map +1 -1
  3. package/dist/browser/AbstractModule.d.mts +5 -1
  4. package/dist/browser/AbstractModule.d.mts.map +1 -1
  5. package/dist/browser/AbstractModule.d.ts +5 -1
  6. package/dist/browser/AbstractModule.d.ts.map +1 -1
  7. package/dist/browser/AbstractModuleInstance.d.cts +1 -0
  8. package/dist/browser/AbstractModuleInstance.d.cts.map +1 -1
  9. package/dist/browser/AbstractModuleInstance.d.mts +1 -0
  10. package/dist/browser/AbstractModuleInstance.d.mts.map +1 -1
  11. package/dist/browser/AbstractModuleInstance.d.ts +1 -0
  12. package/dist/browser/AbstractModuleInstance.d.ts.map +1 -1
  13. package/dist/browser/index.cjs +49 -34
  14. package/dist/browser/index.cjs.map +1 -1
  15. package/dist/browser/index.js +49 -34
  16. package/dist/browser/index.js.map +1 -1
  17. package/dist/node/AbstractModule.d.cts +5 -1
  18. package/dist/node/AbstractModule.d.cts.map +1 -1
  19. package/dist/node/AbstractModule.d.mts +5 -1
  20. package/dist/node/AbstractModule.d.mts.map +1 -1
  21. package/dist/node/AbstractModule.d.ts +5 -1
  22. package/dist/node/AbstractModule.d.ts.map +1 -1
  23. package/dist/node/AbstractModuleInstance.d.cts +1 -0
  24. package/dist/node/AbstractModuleInstance.d.cts.map +1 -1
  25. package/dist/node/AbstractModuleInstance.d.mts +1 -0
  26. package/dist/node/AbstractModuleInstance.d.mts.map +1 -1
  27. package/dist/node/AbstractModuleInstance.d.ts +1 -0
  28. package/dist/node/AbstractModuleInstance.d.ts.map +1 -1
  29. package/dist/node/index.cjs +49 -34
  30. package/dist/node/index.cjs.map +1 -1
  31. package/dist/node/index.js +49 -34
  32. package/dist/node/index.js.map +1 -1
  33. package/package.json +17 -17
  34. package/src/AbstractModule.ts +26 -25
  35. package/src/AbstractModuleInstance.ts +24 -1
@@ -16,7 +16,7 @@ import { BoundWitnessBuilder, QueryBoundWitnessBuilder } from '@xyo-network/boun
16
16
  import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'
17
17
  import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
18
18
  import { ConfigPayload, ConfigSchema } from '@xyo-network/config-payload-plugin'
19
- import { ModuleManifestPayload, ModuleManifestPayloadSchema } from '@xyo-network/manifest-model'
19
+ import { ModuleManifestPayload } from '@xyo-network/manifest-model'
20
20
  import {
21
21
  AddressPreviousHashPayload,
22
22
  AddressPreviousHashSchema,
@@ -35,7 +35,6 @@ import {
35
35
  ModuleEventData,
36
36
  ModuleFactory,
37
37
  ModuleManifestQuerySchema,
38
- ModuleName,
39
38
  ModuleParams,
40
39
  ModuleQueriedEventArgs,
41
40
  ModuleQueries,
@@ -133,6 +132,10 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
133
132
  return this.config.archiving
134
133
  }
135
134
 
135
+ get archivist() {
136
+ return this.config.archivist
137
+ }
138
+
136
139
  get config(): TParams['config'] {
137
140
  return this.params.config
138
141
  }
@@ -441,6 +444,23 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
441
444
  assertEx(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)
442
445
  }
443
446
 
447
+ protected async archivistInstance(): Promise<ArchivistInstance | undefined>
448
+ protected async archivistInstance(required: true): Promise<ArchivistInstance>
449
+ protected async archivistInstance(required = false): Promise<ArchivistInstance | undefined> {
450
+ const archivist = this.archivist
451
+ if (!archivist) {
452
+ if (required) {
453
+ throw new Error('No archivist specified')
454
+ }
455
+ return undefined
456
+ }
457
+ const resolved = (await this.upResolver.resolve(archivist)) ?? (await this.downResolver.resolve(archivist))
458
+ if (required) {
459
+ assertEx(resolved, () => `Unable to resolve archivist [${archivist}]`)
460
+ }
461
+ return resolved ? asArchivistInstance(resolved, () => `Specified archivist is not an Archivist [${archivist}]`) : undefined
462
+ }
463
+
444
464
  protected bindHashes(hashes: Hash[], schema: Schema[], account?: AccountInstance) {
445
465
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
446
466
  const promise = new PromiseEx((resolve) => {
@@ -542,10 +562,9 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
542
562
  return description
543
563
  }
544
564
 
565
+ /** @deprecated use archivistInstance() instead */
545
566
  protected async getArchivist(): Promise<ArchivistInstance | undefined> {
546
- if (!this.config.archivist) return undefined
547
- const resolved = await this.upResolver.resolve(this.config.archivist)
548
- return asArchivistInstance(resolved)
567
+ return await this.archivistInstance()
549
568
  }
550
569
 
551
570
  protected async initializeQueryAccounts() {
@@ -568,26 +587,8 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
568
587
  }
569
588
  }
570
589
 
571
- protected async manifestHandler(maxDepth: number = 1, _ignoreAddresses: Address[] = []): Promise<ModuleManifestPayload> {
572
- const cachedResult = this._cachedManifests.get(maxDepth)
573
- if (cachedResult) {
574
- return cachedResult
575
- }
576
- const name = this.config.name ?? 'Anonymous'
577
- const children = await this.downResolver.resolve('*', { direction: 'down', maxDepth })
578
- const childAddressToName: Record<Address, ModuleName | null> = {}
579
- for (const child of children) {
580
- if (child.address !== this.address) {
581
- childAddressToName[child.address] = child.config.name ?? null
582
- }
583
- }
584
- const result = {
585
- config: { name, ...this.config },
586
- schema: ModuleManifestPayloadSchema,
587
- status: { address: this.address, children: childAddressToName },
588
- }
589
- this._cachedManifests.set(maxDepth, result)
590
- return result
590
+ protected manifestHandler(_maxDepth: number = 1, _ignoreAddresses: Address[] = []): Promisable<ModuleManifestPayload> {
591
+ throw new Error('Not supported')
591
592
  }
592
593
 
593
594
  protected moduleAddressHandler(): Promisable<AddressPreviousHashPayload[]> {
@@ -5,7 +5,7 @@ import { globallyUnique } from '@xylabs/object'
5
5
  import { Promisable } from '@xylabs/promise'
6
6
  import { AccountInstance } from '@xyo-network/account-model'
7
7
  import { ArchivistInstance, asArchivistInstance } from '@xyo-network/archivist-model'
8
- import { ModuleManifestPayload } from '@xyo-network/manifest-model'
8
+ import { ModuleManifestPayload, ModuleManifestPayloadSchema } from '@xyo-network/manifest-model'
9
9
  import {
10
10
  AddressPreviousHashPayload,
11
11
  duplicateModules,
@@ -16,6 +16,7 @@ import {
16
16
  ModuleInstance,
17
17
  ModuleManifestQuery,
18
18
  ModuleManifestQuerySchema,
19
+ ModuleName,
19
20
  ModuleNameResolver,
20
21
  ModuleParams,
21
22
  ModuleQueryResult,
@@ -223,6 +224,28 @@ export abstract class AbstractModuleInstance<TParams extends ModuleParams = Modu
223
224
  return this.subscribeHandler()
224
225
  }
225
226
 
227
+ protected override async manifestHandler(maxDepth: number = 1, _ignoreAddresses: Address[] = []): Promise<ModuleManifestPayload> {
228
+ const cachedResult = this._cachedManifests.get(maxDepth)
229
+ if (cachedResult) {
230
+ return cachedResult
231
+ }
232
+ const name = this.config.name ?? 'Anonymous'
233
+ const children = await this.publicChildren()
234
+ const childAddressToName: Record<Address, ModuleName | null> = {}
235
+ for (const child of children) {
236
+ if (child.address !== this.address) {
237
+ childAddressToName[child.address] = child.config.name ?? null
238
+ }
239
+ }
240
+ const result = {
241
+ config: { name, ...this.config },
242
+ schema: ModuleManifestPayloadSchema,
243
+ status: { address: this.address, children: childAddressToName },
244
+ }
245
+ this._cachedManifests.set(maxDepth, result)
246
+ return result
247
+ }
248
+
226
249
  protected async resolveArchivingArchivists(): Promise<ArchivistInstance[]> {
227
250
  const archivists = this.config.archiving?.archivists
228
251
  if (!archivists) return []