Skip to content

Commit

Permalink
maxDepth and down only for manifest queries
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Oct 3, 2023
1 parent 6bcf328 commit 52e9a4c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 19 deletions.
5 changes: 4 additions & 1 deletion packages/manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
}
}
},
"./schema": {
"default": "./src/schema.json"
},
"./docs": {
"default": "./dist/docs.json"
},
Expand All @@ -70,4 +73,4 @@
},
"sideEffects": false,
"version": "2.75.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> impl
})
}

manifest(): Promisable<ModuleManifestPayload> {
manifest(_depth?: number): Promisable<ModuleManifestPayload> {
const name = this.config.name ?? 'Anonymous'
return { config: { name, ...this.config }, schema: ManifestPayloadSchema }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
}
}

protected manifestHandler(_ignoreAddresses?: string[]): Promisable<ModuleManifestPayload> {
protected manifestHandler(_depth?: number, _ignoreAddresses?: string[]): Promisable<ModuleManifestPayload> {
const name = this.config.name ?? 'Anonymous'
return { config: { name, ...this.config }, schema: ModuleManifestPayloadSchema }
}
Expand Down Expand Up @@ -581,7 +581,7 @@ export abstract class AbstractModule<TParams extends ModuleParams = ModuleParams
const resultPayloads: Payload[] = []
switch (queryPayload.schema) {
case ModuleManifestQuerySchema: {
resultPayloads.push(await this.manifestHandler())
resultPayloads.push(await this.manifestHandler(queryPayload.depth))
break
}
case ModuleDiscoverQuerySchema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export abstract class AbstractModuleInstance<TParams extends ModuleParams = Modu
})
}

manifest(ignoreAddresses?: string[]): Promise<ModuleManifestPayload> {
manifest(maxDepth?: number, ignoreAddresses?: string[]): Promise<ModuleManifestPayload> {
return this.busy(async () => {
return await this.manifestHandler(ignoreAddresses)
return await this.manifestHandler(maxDepth, ignoreAddresses)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export type ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'
export const ModuleManifestQuerySchema: ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'

export type ModuleManifestQuery = Query<{
depth?: number
schema: ModuleManifestQuerySchema
}>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { AddressPreviousHashPayload } from '../Queries'
export type ModuleQueryFunctions = {
describe: () => Promise<ModuleDescription>
discover: () => Promisable<Payload[]>
manifest: (ignoreAddresses?: string[]) => Promisable<ModuleManifestPayload>
manifest: (maxDepth?: number, ignoreAddresses?: string[]) => Promisable<ModuleManifestPayload>
moduleAddress: () => Promisable<AddressPreviousHashPayload[]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ export class ModuleWrapper<TWrappedModule extends Module = Module>
return this.module.listenerCount(eventNames)
}

async manifest(): Promise<ModuleManifestPayload> {
const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema }
async manifest(maxDepth?: number): Promise<ModuleManifestPayload> {
const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema, ...(maxDepth !== undefined ? { maxDepth } : {}) }
return (await this.sendQuery(queryPayload))[0] as ModuleManifestPayload
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
return (await (this.resolve(undefined, { direction: 'down', maxDepth: 2 }) ?? [])).filter((module) => module.address !== this.address)
}

override async manifest(ignoreAddresses?: string[]): Promise<NodeManifestPayload> {
return await this.manifestHandler(ignoreAddresses)
override async manifest(maxDepth?: number, ignoreAddresses?: string[]): Promise<NodeManifestPayload> {
return await this.manifestHandler(maxDepth, ignoreAddresses)
}

register(_module: ModuleInstance): Promisable<void> {
Expand Down Expand Up @@ -135,20 +135,20 @@ export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEve
return [...(await super.discoverHandler()), ...childModAddresses]
}

protected override async manifestHandler(ignoreAddresses: string[] = []): Promise<NodeManifestPayload> {
protected override async manifestHandler(maxDepth?: number, ignoreAddresses: string[] = []): Promise<NodeManifestPayload> {
const manifest: NodeManifestPayload = { ...(await super.manifestHandler()), schema: NodeManifestPayloadSchema }
const newIgnoreAddresses = [...ignoreAddresses, this.address]

const notThisModule = (module: ModuleInstance) => module.address !== this.address && !ignoreAddresses.includes(module.address)
const toManifest = (module: ModuleInstance) => module.manifest(newIgnoreAddresses)

const privateModules = await Promise.all((await this.privateResolver.resolve()).filter(notThisModule).map(toManifest))
/*const privateModules = await Promise.all((await this.privateResolver.resolve()).filter(notThisModule).map(toManifest))
if (privateModules.length > 0) {
manifest.modules = manifest.modules ?? {}
manifest.modules.private = privateModules
}
}*/

const publicModules = await Promise.all((await this.resolve()).filter(notThisModule).map(toManifest))
const publicModules = await Promise.all((await this.resolve(undefined, { direction: 'down', maxDepth })).filter(notThisModule).map(toManifest))
if (publicModules.length > 0) {
manifest.modules = manifest.modules ?? {}
manifest.modules.public = publicModules
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/packages/node/packages/model/src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface NodeQueryFunctions {
attach(nameOrAddress: string, external?: boolean): Promisable<string | undefined>
attached(): Promisable<string[]>
detach(nameOrAddress: string): Promisable<string | undefined>
manifest(): Promise<NodeManifestPayload>
manifest(maxDepth?: number): Promise<NodeManifestPayload>
registered(): Promisable<string[]>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class NodeWrapper<TWrappedModule extends NodeModule = NodeModule>
return payloads.pop()?.address
}

override async manifest(): Promise<NodeManifestPayload> {
const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema }
override async manifest(maxDepth?: number): Promise<NodeManifestPayload> {
const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema, ...(maxDepth ? { maxDepth } : {}) }
const payloads: NodeManifestPayload[] = (await this.sendQuery(queryPayload)).filter(
isPayloadOfSchemaType<NodeManifestPayload>(NodeManifestPayloadSchema),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ describe('MemoryNode', () => {

const manifest = (await memoryNode.manifest()) as NodeManifestPayload
expect(manifest.modules?.public).toBeArrayOfSize(4)
expect(manifest.modules?.private).toBeArrayOfSize(3)
//expect(manifest.modules?.private).toBeArrayOfSize(3)
})
})

0 comments on commit 52e9a4c

Please sign in to comment.