From bd9566489555f7761e241789751c4a4fac497d60 Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 19:51:29 +0100 Subject: [PATCH 01/12] feat(contrib/jtv): add JSON tree container types --- .../tree-container-descriptor.interface.mts | 37 +++++++++++++++++++ .../tree-retrieval-descriptor.interface.mts | 8 ++++ .../types/tree-root-descriptor.interface.mts | 7 ++++ .../tree-service-descriptor.interface.mts | 8 ++++ 4 files changed, 60 insertions(+) create mode 100644 src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts create mode 100644 src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts create mode 100644 src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts create mode 100644 src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts new file mode 100644 index 00000000..5b92e39f --- /dev/null +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -0,0 +1,37 @@ + +import { TreeContainerRetrievalDescriptor } from "./tree-retrieval-descriptor.interface.mjs"; +import { TreeServiceDescriptor } from "./tree-service-descriptor.interface.mjs"; + +// todo: add tsdoc to all of this + +export const enum TreeContainerDescriptorType { + Orphaned, + Child, + Parent +} + +export interface BaseTreeContainerDescriptor { + retrievals: TreeContainerRetrievalDescriptor[]; +} + +export interface TreeOrphanedContainerDescriptor { + readonly type: TreeContainerDescriptorType.Orphaned; + readonly services: TreeServiceDescriptor[]; +} + +export interface TreeChildContainerDescriptor { + readonly type: TreeContainerDescriptorType.Child; + readonly parent: TreeContainerDescriptor; + readonly services: TreeServiceDescriptor[]; +} + +export interface TreeParentContainerDescriptor { + readonly type: TreeContainerDescriptorType.Parent; + readonly services: TreeServiceDescriptor[]; + readonly children: TreeChildContainerDescriptor[]; +} + +export type TreeContainerDescriptor = + | TreeOrphanedContainerDescriptor + | TreeChildContainerDescriptor + | TreeParentContainerDescriptor; diff --git a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts new file mode 100644 index 00000000..4bf1a7c5 --- /dev/null +++ b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts @@ -0,0 +1,8 @@ +import { ServiceIdentifier } from "../../../../index.mjs"; + +// todo: add tsdoc to all of this + +export interface TreeContainerRetrievalDescriptor { + time: number; + key: ServiceIdentifier; +} diff --git a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts new file mode 100644 index 00000000..8ac75e5b --- /dev/null +++ b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts @@ -0,0 +1,7 @@ +import { TreeContainerDescriptor } from "./tree-container-descriptor.interface.mjs"; + +// todo: add tsdoc to all of this + +export interface TreeRootDescriptor { + containers: TreeContainerDescriptor[]; +} diff --git a/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts new file mode 100644 index 00000000..6667e76b --- /dev/null +++ b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts @@ -0,0 +1,8 @@ +import { ServiceIdentifier } from "../../../../index.mjs" + +// todo: add tsdoc to all of this + +export interface TreeServiceDescriptor { + readonly identifier: ServiceIdentifier; + readonly value: T; +} From 44a9fa0a785e1fe6476241a48c698a62b41254d2 Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 19:52:15 +0100 Subject: [PATCH 02/12] feat(contrib/jtv): add JSONTreeVisitorInspector --- .../json-tree-visitor-inspector.class.mts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts diff --git a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts new file mode 100644 index 00000000..1a903052 --- /dev/null +++ b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts @@ -0,0 +1,37 @@ +import { ContainerInstance, ContainerTreeVisitor, ServiceIdentifier, ServiceMetadata, VisitRetrievalOptions } from "../../../../index.mjs"; + +export interface ContainerTreeContainerDescriptor { + parent +} + +export class JSONTreeVisitorInspector implements ContainerTreeVisitor { + visitChildContainer?(child: ContainerInstance): void { + throw new Error("Method not implemented."); + } + + visitOrphanedContainer?(container: ContainerInstance): void { + throw new Error("Method not implemented."); + } + + visitNewService?(serviceOptions: ServiceMetadata): void { + throw new Error("Method not implemented."); + } + + visitContainer?(container: ContainerInstance): boolean { + throw new Error("Method not implemented."); + } + + visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { + throw new Error("Method not implemented."); + } + + disposed = false; + dispose(): void | Promise { + if (this.disposed) { + throw new Error('The JSON tree visitor has already been disposed.'); + } + + this.disposed = true; + } + +} From 9ec9710b665d1016707bc785fcbefc15081213af Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 20:05:18 +0100 Subject: [PATCH 03/12] docs(contrib/jtv): add TSDoc for type --- .../inspectors/types/tree-retrieval-descriptor.interface.mts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts index 4bf1a7c5..f99ffb91 100644 --- a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts @@ -3,6 +3,9 @@ import { ServiceIdentifier } from "../../../../index.mjs"; // todo: add tsdoc to all of this export interface TreeContainerRetrievalDescriptor { + /** The time at which the retrieval was performed. */ time: number; + + /** The key being retrieved. */ key: ServiceIdentifier; } From 4f4fc15238288f2ffb9016bd214e17826ddc1143 Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 20:06:09 +0100 Subject: [PATCH 04/12] fix(contrib/jtv): make properties readonly --- .../inspectors/types/tree-container-descriptor.interface.mts | 2 +- .../inspectors/types/tree-retrieval-descriptor.interface.mts | 4 ++-- .../inspectors/types/tree-root-descriptor.interface.mts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts index 5b92e39f..185c84eb 100644 --- a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -11,7 +11,7 @@ export const enum TreeContainerDescriptorType { } export interface BaseTreeContainerDescriptor { - retrievals: TreeContainerRetrievalDescriptor[]; + readonly retrievals: TreeContainerRetrievalDescriptor[]; } export interface TreeOrphanedContainerDescriptor { diff --git a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts index f99ffb91..49d476a8 100644 --- a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts @@ -4,8 +4,8 @@ import { ServiceIdentifier } from "../../../../index.mjs"; export interface TreeContainerRetrievalDescriptor { /** The time at which the retrieval was performed. */ - time: number; + readonly time: number; /** The key being retrieved. */ - key: ServiceIdentifier; + readonly key: ServiceIdentifier; } diff --git a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts index 8ac75e5b..45eb7f37 100644 --- a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts @@ -3,5 +3,5 @@ import { TreeContainerDescriptor } from "./tree-container-descriptor.interface.m // todo: add tsdoc to all of this export interface TreeRootDescriptor { - containers: TreeContainerDescriptor[]; + readonly containers: TreeContainerDescriptor[]; } From 7f41d9ddc7673bba4a99ff66b02ae5130258b2cd Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 20:07:32 +0100 Subject: [PATCH 05/12] fix(contrib/jtv): remove invalid type --- .../json-inspector/json-tree-visitor-inspector.class.mts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts index 1a903052..ba161824 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts @@ -1,9 +1,5 @@ import { ContainerInstance, ContainerTreeVisitor, ServiceIdentifier, ServiceMetadata, VisitRetrievalOptions } from "../../../../index.mjs"; -export interface ContainerTreeContainerDescriptor { - parent -} - export class JSONTreeVisitorInspector implements ContainerTreeVisitor { visitChildContainer?(child: ContainerInstance): void { throw new Error("Method not implemented."); From bc55698dca45023085299c6a719bc28217fbbec6 Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 9 Oct 2023 20:07:49 +0100 Subject: [PATCH 06/12] style(contrib/jtv): format with Prettier --- .../json-tree-visitor-inspector.class.mts | 53 ++++++++++--------- .../tree-container-descriptor.interface.mts | 35 ++++++------ .../tree-retrieval-descriptor.interface.mts | 10 ++-- .../types/tree-root-descriptor.interface.mts | 4 +- .../tree-service-descriptor.interface.mts | 6 +-- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts index ba161824..de07a847 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts @@ -1,33 +1,38 @@ -import { ContainerInstance, ContainerTreeVisitor, ServiceIdentifier, ServiceMetadata, VisitRetrievalOptions } from "../../../../index.mjs"; +import { + ContainerInstance, + ContainerTreeVisitor, + ServiceIdentifier, + ServiceMetadata, + VisitRetrievalOptions, +} from '../../../../index.mjs'; export class JSONTreeVisitorInspector implements ContainerTreeVisitor { - visitChildContainer?(child: ContainerInstance): void { - throw new Error("Method not implemented."); - } + visitChildContainer?(child: ContainerInstance): void { + throw new Error('Method not implemented.'); + } - visitOrphanedContainer?(container: ContainerInstance): void { - throw new Error("Method not implemented."); - } + visitOrphanedContainer?(container: ContainerInstance): void { + throw new Error('Method not implemented.'); + } - visitNewService?(serviceOptions: ServiceMetadata): void { - throw new Error("Method not implemented."); - } + visitNewService?(serviceOptions: ServiceMetadata): void { + throw new Error('Method not implemented.'); + } - visitContainer?(container: ContainerInstance): boolean { - throw new Error("Method not implemented."); - } + visitContainer?(container: ContainerInstance): boolean { + throw new Error('Method not implemented.'); + } - visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { - throw new Error("Method not implemented."); - } - - disposed = false; - dispose(): void | Promise { - if (this.disposed) { - throw new Error('The JSON tree visitor has already been disposed.'); - } + visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { + throw new Error('Method not implemented.'); + } - this.disposed = true; + disposed = false; + dispose(): void | Promise { + if (this.disposed) { + throw new Error('The JSON tree visitor has already been disposed.'); } - + + this.disposed = true; + } } diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts index 185c84eb..e67b8e27 100644 --- a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -1,37 +1,36 @@ - -import { TreeContainerRetrievalDescriptor } from "./tree-retrieval-descriptor.interface.mjs"; -import { TreeServiceDescriptor } from "./tree-service-descriptor.interface.mjs"; +import { TreeContainerRetrievalDescriptor } from './tree-retrieval-descriptor.interface.mjs'; +import { TreeServiceDescriptor } from './tree-service-descriptor.interface.mjs'; // todo: add tsdoc to all of this export const enum TreeContainerDescriptorType { - Orphaned, - Child, - Parent + Orphaned, + Child, + Parent, } export interface BaseTreeContainerDescriptor { - readonly retrievals: TreeContainerRetrievalDescriptor[]; + readonly retrievals: TreeContainerRetrievalDescriptor[]; } export interface TreeOrphanedContainerDescriptor { - readonly type: TreeContainerDescriptorType.Orphaned; - readonly services: TreeServiceDescriptor[]; + readonly type: TreeContainerDescriptorType.Orphaned; + readonly services: TreeServiceDescriptor[]; } export interface TreeChildContainerDescriptor { - readonly type: TreeContainerDescriptorType.Child; - readonly parent: TreeContainerDescriptor; - readonly services: TreeServiceDescriptor[]; + readonly type: TreeContainerDescriptorType.Child; + readonly parent: TreeContainerDescriptor; + readonly services: TreeServiceDescriptor[]; } export interface TreeParentContainerDescriptor { - readonly type: TreeContainerDescriptorType.Parent; - readonly services: TreeServiceDescriptor[]; - readonly children: TreeChildContainerDescriptor[]; + readonly type: TreeContainerDescriptorType.Parent; + readonly services: TreeServiceDescriptor[]; + readonly children: TreeChildContainerDescriptor[]; } export type TreeContainerDescriptor = - | TreeOrphanedContainerDescriptor - | TreeChildContainerDescriptor - | TreeParentContainerDescriptor; + | TreeOrphanedContainerDescriptor + | TreeChildContainerDescriptor + | TreeParentContainerDescriptor; diff --git a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts index 49d476a8..2a105011 100644 --- a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts @@ -1,11 +1,11 @@ -import { ServiceIdentifier } from "../../../../index.mjs"; +import { ServiceIdentifier } from '../../../../index.mjs'; // todo: add tsdoc to all of this export interface TreeContainerRetrievalDescriptor { - /** The time at which the retrieval was performed. */ - readonly time: number; + /** The time at which the retrieval was performed. */ + readonly time: number; - /** The key being retrieved. */ - readonly key: ServiceIdentifier; + /** The key being retrieved. */ + readonly key: ServiceIdentifier; } diff --git a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts index 45eb7f37..6258a9ed 100644 --- a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts @@ -1,7 +1,7 @@ -import { TreeContainerDescriptor } from "./tree-container-descriptor.interface.mjs"; +import { TreeContainerDescriptor } from './tree-container-descriptor.interface.mjs'; // todo: add tsdoc to all of this export interface TreeRootDescriptor { - readonly containers: TreeContainerDescriptor[]; + readonly containers: TreeContainerDescriptor[]; } diff --git a/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts index 6667e76b..ea814696 100644 --- a/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts @@ -1,8 +1,8 @@ -import { ServiceIdentifier } from "../../../../index.mjs" +import { ServiceIdentifier } from '../../../../index.mjs'; // todo: add tsdoc to all of this export interface TreeServiceDescriptor { - readonly identifier: ServiceIdentifier; - readonly value: T; + readonly identifier: ServiceIdentifier; + readonly value: T; } From f2634346fe9c862a28e7efdd1ed17143f31f9dc9 Mon Sep 17 00:00:00 2001 From: freshgum Date: Tue, 10 Oct 2023 00:37:30 +0100 Subject: [PATCH 07/12] refactor(contrib/jtv): reorganize descriptor types --- .../tree-container-descriptor.interface.mts | 22 +++++++------------ .../tree-retrieval-descriptor.interface.mts | 11 ++++++---- .../tree-service-descriptor.interface.mts | 5 ++--- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts index e67b8e27..1b5f2885 100644 --- a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -1,36 +1,30 @@ -import { TreeContainerRetrievalDescriptor } from './tree-retrieval-descriptor.interface.mjs'; +import { ContainerIdentifier } from '../../../../index.mjs'; +import { TreeRetrievalDescriptor } from './tree-retrieval-descriptor.interface.mjs'; import { TreeServiceDescriptor } from './tree-service-descriptor.interface.mjs'; // todo: add tsdoc to all of this export const enum TreeContainerDescriptorType { Orphaned, - Child, - Parent, + Parent } export interface BaseTreeContainerDescriptor { - readonly retrievals: TreeContainerRetrievalDescriptor[]; + readonly retrievals: TreeRetrievalDescriptor[]; } -export interface TreeOrphanedContainerDescriptor { +export interface TreeOrphanedContainerDescriptor extends BaseTreeContainerDescriptor { readonly type: TreeContainerDescriptorType.Orphaned; readonly services: TreeServiceDescriptor[]; } -export interface TreeChildContainerDescriptor { - readonly type: TreeContainerDescriptorType.Child; - readonly parent: TreeContainerDescriptor; - readonly services: TreeServiceDescriptor[]; -} - -export interface TreeParentContainerDescriptor { +export interface TreeParentContainerDescriptor extends BaseTreeContainerDescriptor { + readonly identifier: ContainerIdentifier; readonly type: TreeContainerDescriptorType.Parent; readonly services: TreeServiceDescriptor[]; - readonly children: TreeChildContainerDescriptor[]; + readonly children: TreeParentContainerDescriptor[]; } export type TreeContainerDescriptor = | TreeOrphanedContainerDescriptor - | TreeChildContainerDescriptor | TreeParentContainerDescriptor; diff --git a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts index 2a105011..51c2d0a3 100644 --- a/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-retrieval-descriptor.interface.mts @@ -1,11 +1,14 @@ -import { ServiceIdentifier } from '../../../../index.mjs'; +import { ServiceIdentifier, VisitRetrievalOptions } from '../../../../index.mjs'; // todo: add tsdoc to all of this -export interface TreeContainerRetrievalDescriptor { +export interface TreeRetrievalDescriptor { /** The time at which the retrieval was performed. */ readonly time: number; - /** The key being retrieved. */ - readonly key: ServiceIdentifier; + /** The identifier being retrieved. */ + readonly identifier: ServiceIdentifier; + + /** The {@link VisitRetrievalOptions} value passed to the visitor. */ + readonly options: VisitRetrievalOptions; } diff --git a/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts index ea814696..95ce29ae 100644 --- a/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-service-descriptor.interface.mts @@ -1,8 +1,7 @@ -import { ServiceIdentifier } from '../../../../index.mjs'; +import { ServiceMetadata } from '../../../../index.mjs'; // todo: add tsdoc to all of this export interface TreeServiceDescriptor { - readonly identifier: ServiceIdentifier; - readonly value: T; + readonly metadata: ServiceMetadata; } From fa8ec15bed0493ad62da456bfa340f0ab33aea46 Mon Sep 17 00:00:00 2001 From: freshgum Date: Tue, 10 Oct 2023 00:38:14 +0100 Subject: [PATCH 08/12] feat(contrib/jtv): add JSONContainerInspector --- .../json-container-inspector.class.mts | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts diff --git a/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts new file mode 100644 index 00000000..e0ca6b18 --- /dev/null +++ b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts @@ -0,0 +1,78 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { + ContainerInstance, + ContainerTreeVisitor, + ServiceIdentifier, + ServiceMetadata, + VisitRetrievalOptions, +} from '../../../../index.mjs'; +import { SynchronousDisposable } from '../../../util/synchronous-disposable.class.mjs'; +import { TreeContainerDescriptorType, TreeParentContainerDescriptor } from '../types/tree-container-descriptor.interface.mjs'; +import { TreeRetrievalDescriptor } from '../types/tree-retrieval-descriptor.interface.mjs'; +import { TreeServiceDescriptor } from '../types/tree-service-descriptor.interface.mjs'; + +export class JSONContainerInspector extends SynchronousDisposable implements ContainerTreeVisitor { + public descriptor: TreeParentContainerDescriptor | null = null; + public container: ContainerInstance | null = null; + + visitChildContainer?(childContainer: ContainerInstance): void { + /** Attach a new inspector to the child. */ + const childInspector = new JSONContainerInspector(); + childContainer.acceptTreeVisitor(childInspector); + const { descriptor } = childInspector; + + /** Add the child container's descriptor as a child of ours. */ + this.descriptor!.children.push(descriptor!); + } + + visitNewService?(newServiceMetadata: ServiceMetadata): void { + const serviceDescriptor: TreeServiceDescriptor = { metadata: newServiceMetadata }; + this.descriptor!.services.push(serviceDescriptor); + } + + visitContainer?(container: ContainerInstance): boolean { + if (this.disposed) { + throw new Error('A disposed JSONContainerInspector instance cannot be added as a visitor to a container.'); + } + + /** Prevent the visitor being added if it is already attached to a container. */ + if (this.container) { + throw new Error('The JSONContainerInspector is already attached to a container.'); + } + + /** Lazily initialize the class' fields. */ + this.container = container; + this.descriptor = { + type: TreeContainerDescriptorType.Parent, + identifier: container.id, + children: [ ] as TreeParentContainerDescriptor[], + services: [ ] as TreeServiceDescriptor[], + retrievals: [ ] as TreeRetrievalDescriptor[], + }; + + return true; + } + + visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { + const currentTime = this.getCurrentTime(); + const retrievalDescriptor: TreeRetrievalDescriptor = { + time: currentTime, + identifier, + options + }; + + this.descriptor!.retrievals.push(retrievalDescriptor); + } + + /** + * Get the current system time. + * + * @remarks + * The default implementation makes use of `performance.now()` to measure time. + * + * @returns The current time in milliseconds. + */ + protected getCurrentTime () { + return performance.now(); + } +} From de29bcb549f2042fc7025d1f95a39fe6051e7457 Mon Sep 17 00:00:00 2001 From: freshgum Date: Tue, 10 Oct 2023 00:38:40 +0100 Subject: [PATCH 09/12] feat(contrib/jtv): add skeleton root inspector --- .../json-root-inspector.class.mts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts diff --git a/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts new file mode 100644 index 00000000..f93c7800 --- /dev/null +++ b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts @@ -0,0 +1,25 @@ +import { ContainerInstance, ContainerTreeVisitor, ServiceIdentifier, ServiceMetadata, VisitRetrievalOptions } from "../../../../index.mjs"; +import { SynchronousDisposable } from "../../../util/synchronous-disposable.class.mjs"; +import { TreeRootDescriptor } from "../types/tree-root-descriptor.interface.mjs"; + +export class JSONRootContainerInspector extends SynchronousDisposable implements ContainerTreeVisitor { + private root: TreeRootDescriptor = { containers: [ ] }; + private container: ContainerInstance | null = null; + + visitOrphanedContainer?(container: ContainerInstance): void { + throw new Error("Method not implemented."); + } + + visitContainer?(container: ContainerInstance): boolean { + if (this.disposed) { + throw new Error('A disposed JSONRootContainerInspector instance cannot be added as a visitor to a container.'); + } + + if (this.container) { + throw new Error('The JSONRootContainerInspector is already attached to a container.'); + } + + this.container = container; + return true; + } +} From 405f3edbe60f3c4191030dbd657636f7093d75ea Mon Sep 17 00:00:00 2001 From: freshgum Date: Tue, 10 Oct 2023 00:39:01 +0100 Subject: [PATCH 10/12] refactor(contrib/jtv): remove unnecessary file --- .../json-tree-visitor-inspector.class.mts | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts diff --git a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts deleted file mode 100644 index de07a847..00000000 --- a/src/contrib/visitors/inspectors/json-inspector/json-tree-visitor-inspector.class.mts +++ /dev/null @@ -1,38 +0,0 @@ -import { - ContainerInstance, - ContainerTreeVisitor, - ServiceIdentifier, - ServiceMetadata, - VisitRetrievalOptions, -} from '../../../../index.mjs'; - -export class JSONTreeVisitorInspector implements ContainerTreeVisitor { - visitChildContainer?(child: ContainerInstance): void { - throw new Error('Method not implemented.'); - } - - visitOrphanedContainer?(container: ContainerInstance): void { - throw new Error('Method not implemented.'); - } - - visitNewService?(serviceOptions: ServiceMetadata): void { - throw new Error('Method not implemented.'); - } - - visitContainer?(container: ContainerInstance): boolean { - throw new Error('Method not implemented.'); - } - - visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { - throw new Error('Method not implemented.'); - } - - disposed = false; - dispose(): void | Promise { - if (this.disposed) { - throw new Error('The JSON tree visitor has already been disposed.'); - } - - this.disposed = true; - } -} From c5668612e6be2d444d502e2bba02e5528211b8ed Mon Sep 17 00:00:00 2001 From: freshgum Date: Tue, 24 Oct 2023 18:56:35 +0100 Subject: [PATCH 11/12] style(contrib/jtv): format with Prettier --- .../json-container-inspector.class.mts | 27 ++++++------ .../json-root-inspector.class.mts | 42 +++++++++++-------- .../tree-container-descriptor.interface.mts | 6 +-- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts index e0ca6b18..e6650a59 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts @@ -7,7 +7,10 @@ import { VisitRetrievalOptions, } from '../../../../index.mjs'; import { SynchronousDisposable } from '../../../util/synchronous-disposable.class.mjs'; -import { TreeContainerDescriptorType, TreeParentContainerDescriptor } from '../types/tree-container-descriptor.interface.mjs'; +import { + TreeContainerDescriptorType, + TreeParentContainerDescriptor, +} from '../types/tree-container-descriptor.interface.mjs'; import { TreeRetrievalDescriptor } from '../types/tree-retrieval-descriptor.interface.mjs'; import { TreeServiceDescriptor } from '../types/tree-service-descriptor.interface.mjs'; @@ -32,9 +35,9 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con visitContainer?(container: ContainerInstance): boolean { if (this.disposed) { - throw new Error('A disposed JSONContainerInspector instance cannot be added as a visitor to a container.'); + throw new Error('A disposed JSONContainerInspector instance cannot be added as a visitor to a container.'); } - + /** Prevent the visitor being added if it is already attached to a container. */ if (this.container) { throw new Error('The JSONContainerInspector is already attached to a container.'); @@ -45,9 +48,9 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con this.descriptor = { type: TreeContainerDescriptorType.Parent, identifier: container.id, - children: [ ] as TreeParentContainerDescriptor[], - services: [ ] as TreeServiceDescriptor[], - retrievals: [ ] as TreeRetrievalDescriptor[], + children: [] as TreeParentContainerDescriptor[], + services: [] as TreeServiceDescriptor[], + retrievals: [] as TreeRetrievalDescriptor[], }; return true; @@ -56,9 +59,9 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con visitRetrieval?(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void { const currentTime = this.getCurrentTime(); const retrievalDescriptor: TreeRetrievalDescriptor = { - time: currentTime, - identifier, - options + time: currentTime, + identifier, + options, }; this.descriptor!.retrievals.push(retrievalDescriptor); @@ -66,13 +69,13 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con /** * Get the current system time. - * + * * @remarks * The default implementation makes use of `performance.now()` to measure time. - * + * * @returns The current time in milliseconds. */ - protected getCurrentTime () { + protected getCurrentTime() { return performance.now(); } } diff --git a/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts index f93c7800..63c79ab1 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts @@ -1,25 +1,31 @@ -import { ContainerInstance, ContainerTreeVisitor, ServiceIdentifier, ServiceMetadata, VisitRetrievalOptions } from "../../../../index.mjs"; -import { SynchronousDisposable } from "../../../util/synchronous-disposable.class.mjs"; -import { TreeRootDescriptor } from "../types/tree-root-descriptor.interface.mjs"; +import { + ContainerInstance, + ContainerTreeVisitor, + ServiceIdentifier, + ServiceMetadata, + VisitRetrievalOptions, +} from '../../../../index.mjs'; +import { SynchronousDisposable } from '../../../util/synchronous-disposable.class.mjs'; +import { TreeRootDescriptor } from '../types/tree-root-descriptor.interface.mjs'; export class JSONRootContainerInspector extends SynchronousDisposable implements ContainerTreeVisitor { - private root: TreeRootDescriptor = { containers: [ ] }; - private container: ContainerInstance | null = null; + private root: TreeRootDescriptor = { containers: [] }; + private container: ContainerInstance | null = null; - visitOrphanedContainer?(container: ContainerInstance): void { - throw new Error("Method not implemented."); - } - - visitContainer?(container: ContainerInstance): boolean { - if (this.disposed) { - throw new Error('A disposed JSONRootContainerInspector instance cannot be added as a visitor to a container.'); - } + visitOrphanedContainer?(container: ContainerInstance): void { + throw new Error('Method not implemented.'); + } - if (this.container) { - throw new Error('The JSONRootContainerInspector is already attached to a container.'); - } + visitContainer?(container: ContainerInstance): boolean { + if (this.disposed) { + throw new Error('A disposed JSONRootContainerInspector instance cannot be added as a visitor to a container.'); + } - this.container = container; - return true; + if (this.container) { + throw new Error('The JSONRootContainerInspector is already attached to a container.'); } + + this.container = container; + return true; + } } diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts index 1b5f2885..347e6747 100644 --- a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -6,7 +6,7 @@ import { TreeServiceDescriptor } from './tree-service-descriptor.interface.mjs'; export const enum TreeContainerDescriptorType { Orphaned, - Parent + Parent, } export interface BaseTreeContainerDescriptor { @@ -25,6 +25,4 @@ export interface TreeParentContainerDescriptor extends BaseTreeContainerDescript readonly children: TreeParentContainerDescriptor[]; } -export type TreeContainerDescriptor = - | TreeOrphanedContainerDescriptor - | TreeParentContainerDescriptor; +export type TreeContainerDescriptor = TreeOrphanedContainerDescriptor | TreeParentContainerDescriptor; From e17d4d6b70634a2263e0abe3b60c5331eb7211dc Mon Sep 17 00:00:00 2001 From: freshgum Date: Mon, 11 Dec 2023 17:06:32 +0000 Subject: [PATCH 12/12] refactor(contrib/jtv): move around interfaces, fix impl. --- .../json-container-inspector.class.mts | 21 +++++--- .../json-root-inspector.class.mts | 48 +++++++++++++++---- ...on-tree-container-descriptor.interface.mts | 7 +++ .../tree-container-descriptor.interface.mts | 31 +++++------- .../types/tree-root-descriptor.interface.mts | 7 --- 5 files changed, 72 insertions(+), 42 deletions(-) create mode 100644 src/contrib/visitors/inspectors/types/json-tree-container-descriptor.interface.mts delete mode 100644 src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts diff --git a/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts index e6650a59..f408943c 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-container-inspector.class.mts @@ -8,14 +8,13 @@ import { } from '../../../../index.mjs'; import { SynchronousDisposable } from '../../../util/synchronous-disposable.class.mjs'; import { - TreeContainerDescriptorType, - TreeParentContainerDescriptor, + TreeContainerDescriptor } from '../types/tree-container-descriptor.interface.mjs'; import { TreeRetrievalDescriptor } from '../types/tree-retrieval-descriptor.interface.mjs'; import { TreeServiceDescriptor } from '../types/tree-service-descriptor.interface.mjs'; export class JSONContainerInspector extends SynchronousDisposable implements ContainerTreeVisitor { - public descriptor: TreeParentContainerDescriptor | null = null; + public descriptor: TreeContainerDescriptor | null = null; public container: ContainerInstance | null = null; visitChildContainer?(childContainer: ContainerInstance): void { @@ -46,11 +45,10 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con /** Lazily initialize the class' fields. */ this.container = container; this.descriptor = { - type: TreeContainerDescriptorType.Parent, identifier: container.id, - children: [] as TreeParentContainerDescriptor[], - services: [] as TreeServiceDescriptor[], - retrievals: [] as TreeRetrievalDescriptor[], + children: [], + services: [], + retrievals: [], }; return true; @@ -67,6 +65,11 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con this.descriptor!.retrievals.push(retrievalDescriptor); } + dispose() { + super.dispose(); + this.container?.detachTreeVisitor(this); + } + /** * Get the current system time. * @@ -78,4 +81,8 @@ export class JSONContainerInspector extends SynchronousDisposable implements Con protected getCurrentTime() { return performance.now(); } + + public toJSON () { + return this.descriptor; + } } diff --git a/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts index 63c79ab1..b60c668c 100644 --- a/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts +++ b/src/contrib/visitors/inspectors/json-inspector/json-root-inspector.class.mts @@ -1,19 +1,40 @@ import { ContainerInstance, - ContainerTreeVisitor, - ServiceIdentifier, - ServiceMetadata, - VisitRetrievalOptions, + ContainerTreeVisitor } from '../../../../index.mjs'; import { SynchronousDisposable } from '../../../util/synchronous-disposable.class.mjs'; -import { TreeRootDescriptor } from '../types/tree-root-descriptor.interface.mjs'; +import { TreeContainerDescriptor, TreeContainerRootDescriptor } from '../types/tree-container-descriptor.interface.mjs'; +import { JSONContainerInspector } from './json-container-inspector.class.mjs'; export class JSONRootContainerInspector extends SynchronousDisposable implements ContainerTreeVisitor { - private root: TreeRootDescriptor = { containers: [] }; - private container: ContainerInstance | null = null; + private orphans: JSONContainerInspector[] = [ ]; + public visitor: null | JSONContainerInspector = null; + + get descriptor (): TreeContainerRootDescriptor | null { + const { visitor, orphans } = this; + + if (!visitor) { + return null; + } + + const { descriptor } = visitor; + + if (descriptor) { + return { + ...descriptor, + orphans: orphans.map(x => x.descriptor as TreeContainerDescriptor) + }; + } + + return null; + } visitOrphanedContainer?(container: ContainerInstance): void { - throw new Error('Method not implemented.'); + const visitor = new JSONContainerInspector(); + + if (container.acceptTreeVisitor(visitor)) { + this.orphans.push(visitor); + } } visitContainer?(container: ContainerInstance): boolean { @@ -21,11 +42,18 @@ export class JSONRootContainerInspector extends SynchronousDisposable implements throw new Error('A disposed JSONRootContainerInspector instance cannot be added as a visitor to a container.'); } - if (this.container) { + if (this.descriptor) { throw new Error('The JSONRootContainerInspector is already attached to a container.'); } - this.container = container; + const visitor = new JSONContainerInspector(); + this.visitor = visitor; + + if(!container.acceptTreeVisitor(visitor)) { + container.detachTreeVisitor(this); + return false; + } + return true; } } diff --git a/src/contrib/visitors/inspectors/types/json-tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/json-tree-container-descriptor.interface.mts new file mode 100644 index 00000000..2445e390 --- /dev/null +++ b/src/contrib/visitors/inspectors/types/json-tree-container-descriptor.interface.mts @@ -0,0 +1,7 @@ +export type JSONTreeContainerIdentifier = + | { type: 'symbol', description: string } + | { type: 'string', text: string }; + +export interface JSONTreeContainerDescriptor { + readonly identifier: JSONTreeContainerIdentifier; +} diff --git a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts index 347e6747..af5c5e0a 100644 --- a/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts +++ b/src/contrib/visitors/inspectors/types/tree-container-descriptor.interface.mts @@ -1,28 +1,23 @@ -import { ContainerIdentifier } from '../../../../index.mjs'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { ContainerIdentifier, ContainerInstance } from '../../../../index.mjs'; import { TreeRetrievalDescriptor } from './tree-retrieval-descriptor.interface.mjs'; import { TreeServiceDescriptor } from './tree-service-descriptor.interface.mjs'; -// todo: add tsdoc to all of this - -export const enum TreeContainerDescriptorType { - Orphaned, - Parent, -} +/** An object representation of a {@link ContainerInstance}. */ +export interface TreeContainerDescriptor { + /** The identifier of the container. */ + readonly identifier: ContainerIdentifier; -export interface BaseTreeContainerDescriptor { + /** A sorted list of retrieval operations performed on this container. */ readonly retrievals: TreeRetrievalDescriptor[]; -} -export interface TreeOrphanedContainerDescriptor extends BaseTreeContainerDescriptor { - readonly type: TreeContainerDescriptorType.Orphaned; + /** An array of services provided by this container. */ readonly services: TreeServiceDescriptor[]; -} -export interface TreeParentContainerDescriptor extends BaseTreeContainerDescriptor { - readonly identifier: ContainerIdentifier; - readonly type: TreeContainerDescriptorType.Parent; - readonly services: TreeServiceDescriptor[]; - readonly children: TreeParentContainerDescriptor[]; + /** An array of children provided by this container. */ + readonly children: TreeContainerDescriptor[]; } -export type TreeContainerDescriptor = TreeOrphanedContainerDescriptor | TreeParentContainerDescriptor; +export interface TreeContainerRootDescriptor extends TreeContainerDescriptor { + readonly orphans: TreeContainerDescriptor[]; +} diff --git a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts b/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts deleted file mode 100644 index 6258a9ed..00000000 --- a/src/contrib/visitors/inspectors/types/tree-root-descriptor.interface.mts +++ /dev/null @@ -1,7 +0,0 @@ -import { TreeContainerDescriptor } from './tree-container-descriptor.interface.mjs'; - -// todo: add tsdoc to all of this - -export interface TreeRootDescriptor { - readonly containers: TreeContainerDescriptor[]; -}