Skip to content

Commit

Permalink
refactor: move infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Jan 17, 2025
1 parent 94f30ed commit c748ce7
Show file tree
Hide file tree
Showing 38 changed files with 65 additions and 40 deletions.
5 changes: 2 additions & 3 deletions packages/connector/src/AbstractConnectorRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Runtime, RuntimeConfig, RuntimeServices } from "@nmshd/runtime";

export interface IInfrastructureRegistry {}
import { ConnectorInfrastructureRegistry } from "./infrastructure/ConnectorInfrastructureRegistry";

export abstract class AbstractConnectorRuntime<TConfig extends RuntimeConfig = RuntimeConfig> extends Runtime<TConfig> {
public abstract override getServices(): RuntimeServices;
public abstract getBackboneAuthenticationToken(): Promise<string>;
public abstract readonly infrastructure: IInfrastructureRegistry;
public abstract readonly infrastructure: ConnectorInfrastructureRegistry;
}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/connector/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./AbstractConnectorRuntime";
export * from "./ConnectorLoggerFactory";
export * from "./ConnectorMode";
export * from "./ConnectorRuntimeModule";
export * from "./infrastructure";
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ILogger } from "@js-soft/logging-abstractions";
import { ConnectorMode } from "@nmshd/connector";
import { ConnectorRuntime } from "../ConnectorRuntime";
import { AbstractConnectorRuntime } from "../AbstractConnectorRuntime";
import { ConnectorMode } from "../ConnectorMode";

export interface InfrastructureConfiguration {
enabled: boolean;
}

export abstract class ConnectorInfrastructure<TConfig extends InfrastructureConfiguration = InfrastructureConfiguration> {
public constructor(
protected runtime: ConnectorRuntime,
protected runtime: AbstractConnectorRuntime,
protected configuration: TConfig,
protected logger: ILogger,
public readonly name: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { IInfrastructureRegistry } from "@nmshd/connector";
import { DocumentationLink } from "../DocumentationLink";
import { ConnectorInfrastructure } from "./ConnectorInfastructure";
import { ConnectorInfrastructure } from "./ConnectorInfrastructure";
import { HttpServer } from "./httpServer";

export class ConnectorInfrastructureRegistry implements IInfrastructureRegistry {
export class ConnectorInfrastructureRegistry {
private readonly infrastructure: Record<string, ConnectorInfrastructure | undefined> = {};

public get httpServer(): HttpServer {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ILogger } from "@js-soft/logging-abstractions";
import { sleep } from "@js-soft/ts-utils";
import { Container } from "@nmshd/typescript-ioc";
import { Server } from "@nmshd/typescript-rest";
Expand All @@ -7,8 +8,9 @@ import cors, { CorsOptions } from "cors";
import express, { Application, RequestHandler } from "express";
import helmet, { HelmetOptions } from "helmet";
import http from "http";
import { buildInformation } from "../../buildInformation";
import { ConnectorInfrastructure, InfrastructureConfiguration } from "../ConnectorInfastructure";
import { AbstractConnectorRuntime } from "../../AbstractConnectorRuntime";
import { ConnectorMode } from "../../ConnectorMode";
import { ConnectorInfrastructure, InfrastructureConfiguration } from "../ConnectorInfrastructure";
import { HttpMethod } from "./HttpMethod";
import { RequestTracker } from "./RequestTracker";
import { Envelope, HttpErrors } from "./common";
Expand Down Expand Up @@ -52,6 +54,17 @@ export class HttpServer extends ConnectorInfrastructure<HttpServerConfiguration>

private readonly requestTracker = new RequestTracker();

public constructor(
runtime: AbstractConnectorRuntime,
configuration: HttpServerConfiguration,
logger: ILogger,
name: string,
connectorMode: ConnectorMode,
private readonly buildInformation: unknown
) {
super(runtime, configuration, logger, name, connectorMode);
}

public init(): void {
this.app = express();
}
Expand Down Expand Up @@ -228,7 +241,7 @@ export class HttpServer extends ConnectorInfrastructure<HttpServerConfiguration>

private useVersionEndpoint() {
this.app.get("/Monitoring/Version", (_req: any, res: any) => {
res.status(200).json(buildInformation);
res.status(200).json(this.buildInformation);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectorMode } from "@nmshd/connector";
import { ConnectorMode } from "../../../ConnectorMode";
import { HttpError, HttpErrorJSON } from "./HttpError";

export class Envelope {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApplicationError } from "@js-soft/ts-utils";
import { ConnectorMode } from "@nmshd/connector";
import { RuntimeErrors } from "@nmshd/runtime";
import { RequestError, TransportCoreErrors } from "@nmshd/transport";
import { Errors } from "@nmshd/typescript-rest";
import express from "express";
import stringify from "json-stringify-safe";
import { ConnectorLoggerFactory } from "../../../logging/ConnectorLoggerFactory";
import { ConnectorLoggerFactory } from "../../../ConnectorLoggerFactory";
import { ConnectorMode } from "../../../ConnectorMode";
import { Envelope, HttpError, HttpErrors } from "../common";

export class RouteNotFoundError extends Error {}
Expand Down
3 changes: 3 additions & 0 deletions packages/connector/src/infrastructure/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./ConnectorInfrastructure";
export * from "./ConnectorInfrastructureRegistry";
export * from "./httpServer";
24 changes: 18 additions & 6 deletions src/ConnectorRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import { MongoDbConnection } from "@js-soft/docdb-access-mongo";
import { ILogger } from "@js-soft/logging-abstractions";
import { NodeLoggerFactory } from "@js-soft/node-logger";
import { ApplicationError } from "@js-soft/ts-utils";
import { AbstractConnectorRuntime, ConnectorMode, ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration } from "@nmshd/connector";
import {
AbstractConnectorRuntime,
ConnectorInfrastructureRegistry,
ConnectorLoggerFactory,
ConnectorMode,
ConnectorRuntimeModule,
ConnectorRuntimeModuleConfiguration,
HttpServer
} from "@nmshd/connector";

Check failure on line 15 in src/ConnectorRuntime.ts

View workflow job for this annotation

GitHub Actions / run-checks

Cannot find module '@nmshd/connector' or its corresponding type declarations.
import { DocumentationLink } from "@nmshd/connector/src/DocumentationLink";
import { ConsumptionController } from "@nmshd/consumption";
import { ConsumptionServices, DataViewExpander, GetIdentityInfoResponse, ModuleConfiguration, RuntimeHealth, RuntimeServices, TransportServices } from "@nmshd/runtime";
import { AccountController, TransportCoreErrors } from "@nmshd/transport";
Expand All @@ -14,12 +23,8 @@ import { HttpsProxyAgent } from "https-proxy-agent";
import path from "path";
import { checkServerIdentity, PeerCertificate } from "tls";
import { ConnectorRuntimeConfig } from "./ConnectorRuntimeConfig";
import { DocumentationLink } from "./DocumentationLink";
import { HealthChecker } from "./HealthChecker";
import { buildInformation } from "./buildInformation";
import { HttpServer } from "./infrastructure";
import { ConnectorInfrastructureRegistry } from "./infrastructure/ConnectorInfrastructureRegistry";
import { ConnectorLoggerFactory } from "./logging/ConnectorLoggerFactory";

interface SupportInformation {
health: RuntimeHealth;
Expand Down Expand Up @@ -325,7 +330,14 @@ export class ConnectorRuntime extends AbstractConnectorRuntime<ConnectorRuntimeC

protected async initInfrastructure(): Promise<void> {
if (this.runtimeConfig.infrastructure.httpServer.enabled) {
const httpServer = new HttpServer(this, this.runtimeConfig.infrastructure.httpServer, this.loggerFactory.getLogger(HttpServer), "httpServer", this.connectorMode);
const httpServer = new HttpServer(
this,
this.runtimeConfig.infrastructure.httpServer,
this.loggerFactory.getLogger(HttpServer),
"httpServer",
this.connectorMode,
buildInformation
);
this.infrastructure.add(httpServer);
}

Expand Down
3 changes: 1 addition & 2 deletions src/ConnectorRuntimeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ConnectorRuntimeModuleConfiguration } from "@nmshd/connector";
import { ConnectorRuntimeModuleConfiguration, HttpServerConfiguration } from "@nmshd/connector";
import { DeciderModuleConfiguration, RuntimeConfig } from "@nmshd/runtime";
import * as log4js from "log4js";
import { HttpServerConfiguration } from "./infrastructure";

export interface MongoDBSettings {
driver: "mongodb";
Expand Down
1 change: 0 additions & 1 deletion src/infrastructure/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/modules/coreHttpApi/CoreHttpApiModule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration, HttpMethod } from "@nmshd/connector";
import path from "path";
import swaggerUi, { SwaggerUiOptions } from "swagger-ui-express";
import yamlJs from "yamljs";
import { ConnectorRuntimeModule, ConnectorRuntimeModuleConfiguration } from "../../ConnectorRuntimeModule";
import { HttpMethod } from "../../infrastructure";

export interface CoreHttpApiModuleConfiguration extends ConnectorRuntimeModuleConfiguration {
docs: {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/common/BaseController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Result } from "@js-soft/ts-utils";
import { Envelope } from "@nmshd/connector";
import { Return } from "@nmshd/typescript-rest";
import express from "express";
import { Envelope } from "../../../infrastructure";

export abstract class BaseController {
protected created<T>(result: Result<T>): Return.NewResource<Envelope> {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/controllers/AccountController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, GET, Path, POST } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Account")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { ConsumptionServices, RuntimeErrors, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Attributes")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Path, POST, Return } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Challenges")
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/controllers/FilesController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Envelope } from "@nmshd/connector";
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Reference } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, FileParam, FormParam, GET, POST, Path, PathParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

@Path("/api/v2/Files")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, DELETE, GET, PUT, Path, QueryParam } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/IdentityMetadata")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, GET, Path, PathParam, PUT, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Requests/Incoming")
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/controllers/MessagesController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Envelope } from "@nmshd/connector";
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextResponse, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

@Path("/api/v2/Messages")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Requests/Outgoing")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Envelope } from "@nmshd/connector";
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, POST, Path, PathParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

@Path("/api/v2/RelationshipTemplates")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, Path, PathParam, POST, PUT, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Relationships")
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/controllers/TokensController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Envelope } from "@nmshd/connector";
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

@Path("/api/v2/Tokens")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Envelope } from "@nmshd/connector";
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, DELETE, GET, Path, POST, QueryParam } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/IdentityDeletionProcess")
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"lib": ["es2021", "dom"],
"typeRoots": ["./node_modules/@types"]
},
"include": ["src/**/*"]
"include": ["src/**/*", "packages/connector/src/DocumentationLink.ts"]
}

0 comments on commit c748ce7

Please sign in to comment.