Skip to content

Commit

Permalink
feat: introduce EdcControlelr class
Browse files Browse the repository at this point in the history
  • Loading branch information
fdionisi committed Jun 7, 2024
1 parent c83a12b commit ad4bc71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 51 deletions.
34 changes: 14 additions & 20 deletions src/controllers/observability-controller.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { EdcConnectorClientContext } from "../context";
import { HealthStatus } from "../entities";
import { Inner } from "../inner";
import { EdcController } from "../edc-controller";

export class ObservabilityController {
#inner: Inner;
#context?: EdcConnectorClientContext;

constructor(inner: Inner, context?: EdcConnectorClientContext) {
this.#inner = inner;
this.#context = context;
}

async checkHealth(context?: EdcConnectorClientContext): Promise<HealthStatus> {
const actualContext = context || this.#context!;
export class ObservabilityController extends EdcController {
async checkHealth(
context?: EdcConnectorClientContext,
): Promise<HealthStatus> {
const actualContext = context || this.context!;

return this.#inner.request(actualContext.default, {
return this.inner.request(actualContext.default, {
path: "/check/health",
method: "GET",
apiToken: actualContext.apiToken,
Expand All @@ -24,9 +18,9 @@ export class ObservabilityController {
async checkLiveness(
context?: EdcConnectorClientContext,
): Promise<HealthStatus> {
const actualContext = context || this.#context!;
const actualContext = context || this.context!;

return this.#inner.request(actualContext.default, {
return this.inner.request(actualContext.default, {
path: "/check/liveness",
method: "GET",
apiToken: actualContext.apiToken,
Expand All @@ -36,9 +30,9 @@ export class ObservabilityController {
async checkReadiness(
context?: EdcConnectorClientContext,
): Promise<HealthStatus> {
const actualContext = context || this.#context!;
const actualContext = context || this.context!;

return this.#inner.request(actualContext.default, {
return this.inner.request(actualContext.default, {
path: "/check/readiness",
method: "GET",
apiToken: actualContext.apiToken,
Expand All @@ -48,9 +42,9 @@ export class ObservabilityController {
async checkStartup(
context?: EdcConnectorClientContext,
): Promise<HealthStatus> {
const actualContext = context || this.#context!;
return this.#inner.request(actualContext.default, {
const actualContext = context || this.context!;

return this.inner.request(actualContext.default, {
path: "/check/startup",
method: "GET",
apiToken: actualContext.apiToken,
Expand Down
16 changes: 4 additions & 12 deletions src/controllers/public-controller.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { EdcConnectorClientContext } from "../context";
import { Inner } from "../inner";

export class PublicController {
#inner: Inner;
#context?: EdcConnectorClientContext;

constructor(inner: Inner, context?: EdcConnectorClientContext) {
this.#inner = inner;
this.#context = context;
}
import { EdcController } from "../edc-controller";

export class PublicController extends EdcController {
async getTransferredData(
headers: Record<string, string | undefined>,
context?: EdcConnectorClientContext,
): Promise<Response> {
const actualContext = context || this.#context!;
const actualContext = context || this.context!;

return this.#inner.stream(actualContext.public, {
return this.inner.stream(actualContext.public, {
path: "/",
method: "GET",
headers,
Expand Down
12 changes: 12 additions & 0 deletions src/edc-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EdcConnectorClientContext } from "./context";
import { Inner } from "./inner";

export class EdcController {
protected inner: Inner;
protected context?: EdcConnectorClientContext;

constructor(inner: Inner, context?: EdcConnectorClientContext) {
this.inner = inner;
this.context = context;
}
}
29 changes: 10 additions & 19 deletions src/facades/management.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Inner } from "../inner";
import { EdcConnectorClientContext } from "../context";
import {
AssetController,
CatalogController,
Expand All @@ -10,38 +8,31 @@ import {
PolicyDefinitionController,
TransferProcessController,
} from "../controllers/management-controllers";
import { EdcController } from "../edc-controller";

export class ManagementController {
#inner: Inner;
#context: EdcConnectorClientContext | undefined;

constructor(inner: Inner, context?: EdcConnectorClientContext) {
this.#inner = inner;
this.#context = context;
}

export class ManagementController extends EdcController {
get assets() {
return new AssetController(this.#inner, this.#context);
return new AssetController(this.inner, this.context);
}
get catalog() {
return new CatalogController(this.#inner, this.#context);
return new CatalogController(this.inner, this.context);
}
get contractAgreements() {
return new ContractAgreementController(this.#inner, this.#context);
return new ContractAgreementController(this.inner, this.context);
}
get contractDefinitions() {
return new ContractDefinitionController(this.#inner, this.#context);
return new ContractDefinitionController(this.inner, this.context);
}
get contractNegotiations() {
return new ContractNegotiationController(this.#inner, this.#context);
return new ContractNegotiationController(this.inner, this.context);
}
get dataplanes() {
return new DataplaneController(this.#inner, this.#context);
return new DataplaneController(this.inner, this.context);
}
get policyDefinitions() {
return new PolicyDefinitionController(this.#inner, this.#context);
return new PolicyDefinitionController(this.inner, this.context);
}
get transferProcesses() {
return new TransferProcessController(this.#inner, this.#context);
return new TransferProcessController(this.inner, this.context);
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./context";
export * from "./client";
export * from "./entities";
export * from "./error";
export * from "./edc-controller";

0 comments on commit ad4bc71

Please sign in to comment.