From 52e9a4ca5b107462abaee4344ea40b2839cfe344 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 3 Oct 2023 15:29:35 -0700 Subject: [PATCH] maxDepth and down only for manifest queries --- packages/manifest/package.json | 5 ++++- .../packages/module-resolver/src/ProxyModule.ts | 2 +- .../module/packages/abstract/src/AbstractModule.ts | 4 ++-- .../packages/abstract/src/AbstractModuleInstance.ts | 4 ++-- .../module/packages/model/src/Queries/Manifest.ts | 1 + .../model/src/module/ModuleQueryFunctions.ts | 2 +- .../module/packages/wrapper/src/ModuleWrapper.ts | 4 ++-- .../node/packages/abstract/src/AbstractNode.ts | 12 ++++++------ .../modules/packages/node/packages/model/src/Node.ts | 2 +- .../node/packages/wrapper/src/NodeWrapper.ts | 4 ++-- .../packages/node/spec/MemoryNode/Manifest.spec.ts | 2 +- 11 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/manifest/package.json b/packages/manifest/package.json index b559045507a..31db5b1da93 100644 --- a/packages/manifest/package.json +++ b/packages/manifest/package.json @@ -51,6 +51,9 @@ } } }, + "./schema": { + "default": "./src/schema.json" + }, "./docs": { "default": "./dist/docs.json" }, @@ -70,4 +73,4 @@ }, "sideEffects": false, "version": "2.75.6" -} +} \ No newline at end of file diff --git a/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts b/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts index c79956512c9..f2f6796b351 100644 --- a/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts +++ b/packages/modules/packages/bridge/packages/module-resolver/src/ProxyModule.ts @@ -116,7 +116,7 @@ export class ProxyModule extends BaseEmitter impl }) } - manifest(): Promisable { + manifest(_depth?: number): Promisable { const name = this.config.name ?? 'Anonymous' return { config: { name, ...this.config }, schema: ManifestPayloadSchema } } diff --git a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts index 9e7f55b7408..0ce1a7ee119 100644 --- a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts +++ b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts @@ -540,7 +540,7 @@ export abstract class AbstractModule { + protected manifestHandler(_depth?: number, _ignoreAddresses?: string[]): Promisable { const name = this.config.name ?? 'Anonymous' return { config: { name, ...this.config }, schema: ModuleManifestPayloadSchema } } @@ -581,7 +581,7 @@ export abstract class AbstractModule { + manifest(maxDepth?: number, ignoreAddresses?: string[]): Promise { return this.busy(async () => { - return await this.manifestHandler(ignoreAddresses) + return await this.manifestHandler(maxDepth, ignoreAddresses) }) } diff --git a/packages/modules/packages/module/packages/model/src/Queries/Manifest.ts b/packages/modules/packages/module/packages/model/src/Queries/Manifest.ts index 540231216ab..4c5f18ce4f5 100644 --- a/packages/modules/packages/module/packages/model/src/Queries/Manifest.ts +++ b/packages/modules/packages/module/packages/model/src/Queries/Manifest.ts @@ -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 }> diff --git a/packages/modules/packages/module/packages/model/src/module/ModuleQueryFunctions.ts b/packages/modules/packages/module/packages/model/src/module/ModuleQueryFunctions.ts index f7a23d3dcd5..8b48537ac79 100644 --- a/packages/modules/packages/module/packages/model/src/module/ModuleQueryFunctions.ts +++ b/packages/modules/packages/module/packages/model/src/module/ModuleQueryFunctions.ts @@ -8,6 +8,6 @@ import { AddressPreviousHashPayload } from '../Queries' export type ModuleQueryFunctions = { describe: () => Promise discover: () => Promisable - manifest: (ignoreAddresses?: string[]) => Promisable + manifest: (maxDepth?: number, ignoreAddresses?: string[]) => Promisable moduleAddress: () => Promisable } diff --git a/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts b/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts index 2c0ea9e2a80..e22877893a6 100644 --- a/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts +++ b/packages/modules/packages/module/packages/wrapper/src/ModuleWrapper.ts @@ -253,8 +253,8 @@ export class ModuleWrapper return this.module.listenerCount(eventNames) } - async manifest(): Promise { - const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema } + async manifest(maxDepth?: number): Promise { + const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema, ...(maxDepth !== undefined ? { maxDepth } : {}) } return (await this.sendQuery(queryPayload))[0] as ModuleManifestPayload } diff --git a/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts b/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts index 74a309e4fad..e79d11dbf4c 100644 --- a/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts +++ b/packages/modules/packages/node/packages/abstract/src/AbstractNode.ts @@ -71,8 +71,8 @@ export abstract class AbstractNode module.address !== this.address) } - override async manifest(ignoreAddresses?: string[]): Promise { - return await this.manifestHandler(ignoreAddresses) + override async manifest(maxDepth?: number, ignoreAddresses?: string[]): Promise { + return await this.manifestHandler(maxDepth, ignoreAddresses) } register(_module: ModuleInstance): Promisable { @@ -135,20 +135,20 @@ export abstract class AbstractNode { + protected override async manifestHandler(maxDepth?: number, ignoreAddresses: string[] = []): Promise { 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 diff --git a/packages/modules/packages/node/packages/model/src/Node.ts b/packages/modules/packages/node/packages/model/src/Node.ts index ba77199a58a..ba618da4ac3 100644 --- a/packages/modules/packages/node/packages/model/src/Node.ts +++ b/packages/modules/packages/node/packages/model/src/Node.ts @@ -9,7 +9,7 @@ export interface NodeQueryFunctions { attach(nameOrAddress: string, external?: boolean): Promisable attached(): Promisable detach(nameOrAddress: string): Promisable - manifest(): Promise + manifest(maxDepth?: number): Promise registered(): Promisable } diff --git a/packages/modules/packages/node/packages/wrapper/src/NodeWrapper.ts b/packages/modules/packages/node/packages/wrapper/src/NodeWrapper.ts index aa884f467ee..d8352ca8b63 100644 --- a/packages/modules/packages/node/packages/wrapper/src/NodeWrapper.ts +++ b/packages/modules/packages/node/packages/wrapper/src/NodeWrapper.ts @@ -46,8 +46,8 @@ export class NodeWrapper return payloads.pop()?.address } - override async manifest(): Promise { - const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema } + override async manifest(maxDepth?: number): Promise { + const queryPayload: ModuleManifestQuery = { schema: ModuleManifestQuerySchema, ...(maxDepth ? { maxDepth } : {}) } const payloads: NodeManifestPayload[] = (await this.sendQuery(queryPayload)).filter( isPayloadOfSchemaType(NodeManifestPayloadSchema), ) diff --git a/packages/modules/packages/node/spec/MemoryNode/Manifest.spec.ts b/packages/modules/packages/node/spec/MemoryNode/Manifest.spec.ts index b4cbe1539c0..44bae871700 100644 --- a/packages/modules/packages/node/spec/MemoryNode/Manifest.spec.ts +++ b/packages/modules/packages/node/spec/MemoryNode/Manifest.spec.ts @@ -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) }) })