@xyo-network/node-abstract 2.92.7 → 2.92.9

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.
@@ -63,43 +63,61 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
63
63
  }
64
64
 
65
65
  async attachedModules(maxDepth = 2): Promise<ModuleInstance[]> {
66
- return (await (this.resolve(undefined, { direction: 'down', maxDepth }) ?? [])).filter((module) => module.address !== this.address)
66
+ return (await (this.resolve('*', { direction: 'down', maxDepth }) ?? [])).filter((module) => module.address !== this.address)
67
67
  }
68
68
 
69
- override async manifest(maxDepth?: number, ignoreAddresses?: string[]): Promise<ModuleManifestPayload> {
69
+ override async manifest(maxDepth?: number, ignoreAddresses?: Address[]): Promise<ModuleManifestPayload> {
70
70
  return await this.manifestHandler(maxDepth, ignoreAddresses)
71
71
  }
72
72
 
73
+ /** @deprecated do not pass undefined. If trying to get all, pass '*' */
74
+ override async resolve(): Promise<ModuleInstance[]>
75
+ override async resolve(all: '*', options?: ModuleFilterOptions): Promise<ModuleInstance[]>
76
+ override async resolve(filter: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
77
+ override async resolve(id: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
78
+ /** @deprecated do not pass undefined. If trying to get all, pass '*' */
73
79
  override async resolve(filter?: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
74
- override async resolve(nameOrAddress: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
75
80
  override async resolve(
76
- nameOrAddressOrFilter?: ModuleFilter | ModuleIdentifier,
81
+ idOrFilter: ModuleFilter | ModuleIdentifier = '*',
77
82
  options?: ModuleFilterOptions,
78
83
  ): Promise<ModuleInstance | ModuleInstance[] | undefined> {
79
84
  //checking type of nameOrAddressOrFilter before calling other functions since TS seems
80
85
  //to need help here narrowing before the call
81
- if (typeof nameOrAddressOrFilter === 'string') {
86
+ if (idOrFilter === '*') {
82
87
  switch (options?.visibility) {
83
88
  case 'private': {
84
- return await this.resolvePrivate(nameOrAddressOrFilter)
89
+ return await this.resolvePrivate('*')
85
90
  }
86
91
  case 'all': {
87
- return await this.resolveAll(nameOrAddressOrFilter)
92
+ return await this.resolveAll('*')
88
93
  }
89
94
  default: {
90
- return await super.resolve(nameOrAddressOrFilter, options)
95
+ return await super.resolve('*', options)
96
+ }
97
+ }
98
+ }
99
+ if (typeof idOrFilter === 'string') {
100
+ switch (options?.visibility) {
101
+ case 'private': {
102
+ return await this.resolvePrivate(idOrFilter)
103
+ }
104
+ case 'all': {
105
+ return await this.resolveAll(idOrFilter)
106
+ }
107
+ default: {
108
+ return await super.resolve(idOrFilter, options)
91
109
  }
92
110
  }
93
111
  } else {
94
112
  switch (options?.visibility) {
95
113
  case 'all': {
96
- return await this.resolveAll(nameOrAddressOrFilter)
114
+ return await this.resolveAll(idOrFilter)
97
115
  }
98
116
  case 'private': {
99
- return await this.resolvePrivate(nameOrAddressOrFilter)
117
+ return await this.resolvePrivate(idOrFilter)
100
118
  }
101
119
  default: {
102
- return await super.resolve(nameOrAddressOrFilter, options)
120
+ return await super.resolve(idOrFilter, options)
103
121
  }
104
122
  }
105
123
  }
@@ -116,7 +134,7 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
116
134
  return [...(await super.discoverHandler(maxDepth)), ...childModAddresses]
117
135
  }
118
136
 
119
- protected override async manifestHandler(maxDepth?: number, ignoreAddresses: string[] = []): Promise<ModuleManifestPayload> {
137
+ protected override async manifestHandler(maxDepth?: number, ignoreAddresses: Address[] = []): Promise<ModuleManifestPayload> {
120
138
  const manifest: NodeManifestPayload = { ...(await super.manifestHandler()), schema: NodeManifestPayloadSchema }
121
139
  const newIgnoreAddresses = [...ignoreAddresses, this.address]
122
140
 
@@ -129,7 +147,7 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
129
147
  manifest.modules.private = privateModules
130
148
  }*/
131
149
 
132
- const publicModules = await Promise.all((await this.resolve(undefined, { direction: 'down', maxDepth })).filter(notThisModule).map(toManifest))
150
+ const publicModules = await Promise.all((await this.resolve('*', { direction: 'down', maxDepth })).filter(notThisModule).map(toManifest))
133
151
  if (publicModules.length > 0) {
134
152
  manifest.modules = manifest.modules ?? {}
135
153
  manifest.modules.public = publicModules
@@ -187,43 +205,49 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
187
205
  return resultPayloads
188
206
  }
189
207
 
190
- private async resolveAll(filter?: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
191
- private async resolveAll(nameOrAddress: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
208
+ private async resolveAll(all: '*', options?: ModuleFilterOptions): Promise<ModuleInstance[]>
209
+ private async resolveAll(filter: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
210
+ private async resolveAll(id: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
192
211
  private async resolveAll(
193
- nameOrAddressOrFilter?: ModuleFilter | ModuleIdentifier,
212
+ idOrFilter: ModuleFilter | ModuleIdentifier,
194
213
  options?: ModuleFilterOptions,
195
214
  ): Promise<ModuleInstance | ModuleInstance[] | undefined> {
196
- switch (typeof nameOrAddressOrFilter) {
215
+ if (idOrFilter === '*') {
216
+ return [...(await this.resolvePrivate(idOrFilter, options)), ...(await super.resolve(idOrFilter, options))].filter(duplicateModules)
217
+ }
218
+ switch (typeof idOrFilter) {
197
219
  case 'string': {
198
- return (await this.resolvePrivate(nameOrAddressOrFilter, options)) ?? (await super.resolve(nameOrAddressOrFilter, options))
220
+ return (await this.resolvePrivate(idOrFilter, options)) ?? (await super.resolve(idOrFilter, options))
199
221
  }
200
222
  default: {
201
- return [...(await this.resolvePrivate(nameOrAddressOrFilter, options)), ...(await super.resolve(nameOrAddressOrFilter, options))].filter(
202
- duplicateModules,
203
- )
223
+ return [...(await this.resolvePrivate(idOrFilter, options)), ...(await super.resolve(idOrFilter, options))].filter(duplicateModules)
204
224
  }
205
225
  }
206
226
  }
207
227
 
208
- private async resolvePrivate(filter?: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
209
- private async resolvePrivate(nameOrAddress: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
228
+ private async resolvePrivate(all: '*', options?: ModuleFilterOptions): Promise<ModuleInstance[]>
229
+ private async resolvePrivate(filter: ModuleFilter, options?: ModuleFilterOptions): Promise<ModuleInstance[]>
230
+ private async resolvePrivate(id: ModuleIdentifier, options?: ModuleFilterOptions): Promise<ModuleInstance | undefined>
210
231
  private async resolvePrivate(
211
- nameOrAddressOrFilter?: ModuleFilter | ModuleIdentifier,
232
+ idOrFilter: ModuleFilter | ModuleIdentifier,
212
233
  options?: ModuleFilterOptions,
213
234
  ): Promise<ModuleInstance | ModuleInstance[] | undefined> {
214
235
  const direction = options?.direction ?? 'all'
215
236
  const down = direction === 'down' || direction === 'all'
216
- switch (typeof nameOrAddressOrFilter) {
237
+ if (idOrFilter === '*') {
238
+ return down ? await this.privateResolver.resolve(idOrFilter) : []
239
+ }
240
+ switch (typeof idOrFilter) {
217
241
  case 'string': {
218
- return down ? await this.privateResolver.resolve(nameOrAddressOrFilter) : undefined
242
+ return down ? await this.privateResolver.resolve(idOrFilter) : undefined
219
243
  }
220
244
  default: {
221
- return down ? await this.privateResolver.resolve(nameOrAddressOrFilter) : undefined
245
+ return down ? await this.privateResolver.resolve(idOrFilter) : undefined
222
246
  }
223
247
  }
224
248
  }
225
249
 
226
- abstract attach(nameOrAddress: string, external?: boolean): Promisable<Address | undefined>
227
- abstract detach(nameOrAddress: string): Promisable<Address | undefined>
250
+ abstract attach(id: ModuleIdentifier, external?: boolean): Promisable<Address | undefined>
251
+ abstract detach(id: ModuleIdentifier): Promisable<Address | undefined>
228
252
  abstract registered(): Promisable<Address[]>
229
253
  }