Skip to content

Commit 9e85e27

Browse files
committed
Adjust IRuntimeAdapter interface
1 parent 73a2951 commit 9e85e27

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

packages/adapter-process/src/process-instance-adapter.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { STHConfiguration,
22
ExitCode,
3-
IComponent,
4-
ILifeCycleAdapterMain,
5-
ILifeCycleAdapterRun,
63
InstanceConfig,
74
InstanceLimits,
85
IObjectLogger,
96
MonitoringMessageData,
10-
SequenceConfig
7+
SequenceConfig,
8+
IInstanceAdapter
119
} from "@scramjet/types";
1210
import { ObjLogger } from "@scramjet/obj-logger";
1311
import { streamToString } from "@scramjet/utility";
@@ -22,10 +20,7 @@ const gotPython = "\n _ \n __ _____ _ __ ___
2220
/**
2321
* Adapter for running Instance by Runner executed in separate process.
2422
*/
25-
class ProcessInstanceAdapter implements
26-
ILifeCycleAdapterMain,
27-
ILifeCycleAdapterRun,
28-
IComponent {
23+
class ProcessInstanceAdapter implements IInstanceAdapter {
2924
logger: IObjectLogger;
3025
sthConfig: STHConfiguration;
3126

packages/adapter-process/src/process-sequence-adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
ProcessSequenceConfig,
33
ISequenceAdapter,
4-
STHConfiguration,
54
SequenceConfig,
65
IObjectLogger,
6+
ProcessAdapterConfiguration,
77
} from "@scramjet/types";
88
import { ObjLogger } from "@scramjet/obj-logger";
99
import { isDefined, readStreamedJSON } from "@scramjet/utility";
@@ -56,11 +56,11 @@ class ProcessSequenceAdapter implements ISequenceAdapter {
5656
logger: IObjectLogger;
5757

5858
name = "ProcessSequenceAdapter";
59-
config: NonNullable<STHConfiguration["adapters"]["@scramjet/adapter-process"]>;
59+
config: ProcessAdapterConfiguration;
6060

61-
constructor(config: STHConfiguration) {
61+
constructor(config: ProcessAdapterConfiguration) {
6262
this.logger = new ObjLogger(this);
63-
this.config = config.adapters["@scramjet/adapter-process"]!;
63+
this.config = config;
6464
}
6565

6666
/**

packages/host/src/lib/adapter-manager.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class AdapterManager {
1212
}
1313

1414
/**
15-
* Initializes configured adapters.
15+
* Initializes all configured adapters.
1616
*
1717
* @returns True if any adapter is available. False otherwise.
1818
*/
@@ -37,6 +37,7 @@ export class AdapterManager {
3737
}
3838

3939
if (this.adapters[adapter.pkgName]) throw new Error("Invalid adapters configuration, duplicated adapter name");
40+
4041
this.adapters[adapter.pkgName] = adapter;
4142
}
4243
)
@@ -48,23 +49,41 @@ export class AdapterManager {
4849
this.logger.info(`${adaptersCount} Adapters available:`, this.adapters);
4950

5051
return true;
51-
} else {
52-
this.logger.warn("No adapters defined. Sequences and Instances unsupported.");
53-
54-
return false;
5552
}
53+
54+
this.logger.warn("No adapters defined. Sequences and Instances unsupported.");
55+
56+
return false;
5657
}
5758

59+
/**
60+
* Validates adapter.
61+
*
62+
* @param {IRuntimeAdapter} adapter Checks if adapter provides required fields.
63+
* @returns {boolean} True if required fields are available.
64+
*/
5865
static validateAdapter(adapter: IRuntimeAdapter): boolean {
5966
return !!(adapter.name.trim() && ["SequenceAdapter", "InstanceAdapter", "init"].every((className: string) => className in adapter));
6067
}
6168

69+
/**
70+
* Initializes adapter with adapter config.
71+
*
72+
* @param {IRuntimeAdapter} adapter Adapter to initialize
73+
* @returns
74+
*/
6275
async initAdapter(adapter: IRuntimeAdapter): Promise<{ error?: string } | "ready"> {
6376
const initResult = await adapter.init(adapter.config);
6477

6578
return initResult.error ? initResult : Promise.resolve("ready");
6679
}
6780

81+
/**
82+
* Returns Adapter by given package name.
83+
*
84+
* @param {string} pkgName Adapter package name.
85+
* @returns {IRuntimeAdapter} Adapter
86+
*/
6887
getAdapterByName(pkgName: string): IRuntimeAdapter | undefined {
6988
return Object.values(this.adapters).find(a => a.pkgName === pkgName);
7089
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { ILifeCycleAdapterMain, ILifeCycleAdapterRun } from "./lifecycle-adapters";
22
import { IComponent } from "./component";
33

4-
export interface IInstanceAdapter extends ILifeCycleAdapterMain, ILifeCycleAdapterRun, IComponent {}
4+
export interface IInstanceAdapter extends ILifeCycleAdapterMain, ILifeCycleAdapterRun, IComponent {
5+
}
6+
7+
export interface IInstanceAdapterContructor {
8+
new (config: any): IInstanceAdapter
9+
}

packages/types/src/runtime-adapter.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import { IComponent } from "./component";
2-
import { IInstanceAdapter } from "./instance-adapter";
3-
import { ILifeCycleAdapterMain, ILifeCycleAdapterRun } from "./lifecycle-adapters";
4-
import { ISequenceAdapter } from "./sequence-adapter";
5-
import { STHConfiguration } from "./sth-configuration";
1+
import { IInstanceAdapterContructor } from "./instance-adapter";
2+
import { ISequenceAdapterContructor } from "./sequence-adapter";
63

74
export interface IRuntimeAdapter {
8-
SequenceAdapter: ISequenceAdapter & { new (config: STHConfiguration): ISequenceAdapter };
9-
InstanceAdapter:
10-
ILifeCycleAdapterMain &
11-
ILifeCycleAdapterRun &
12-
IComponent &
13-
{ new (config: STHConfiguration): IInstanceAdapter };
5+
SequenceAdapter: ISequenceAdapterContructor;
6+
InstanceAdapter: IInstanceAdapterContructor;
147
name: string;
158
pkgName: string;
169
init(config: any): Promise<{ error?: string }>;

packages/types/src/sequence-adapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export interface ISequenceAdapter {
3232

3333
logger: IObjectLogger;
3434
}
35+
36+
export interface ISequenceAdapterContructor {
37+
new (config: any): ISequenceAdapter;
38+
}

0 commit comments

Comments
 (0)