forked from hyperledger/cacti
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cactus-sdk): introduces typed (compiler supported) extensibility…
… between different SDK backends An SDK backend is the generated codebase that the openapi-generator tool spits out. There are multiple ones of these because plugins need to be able to declare their own web services and still have easy programmatically generated SDKs for them. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
7 changed files
with
46 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; | ||
import { Objects } from "@hyperledger/cactus-common"; | ||
import { | ||
Configuration, | ||
DefaultApi, | ||
} from "./generated/openapi/typescript-axios"; | ||
|
||
export interface IApiClientOptions { | ||
apiHost: string; | ||
apiPort: number; | ||
} | ||
export class ApiClient extends DefaultApi { | ||
public extendWith<T extends {}>( | ||
ctor: new (configuration?: Configuration) => T | ||
): T & this { | ||
const instance = new ctor(this.configuration) as any; | ||
const self = this as any; | ||
|
||
export class ApiClient { | ||
private readonly log: Logger; | ||
Objects.getAllMethodNames(instance).forEach( | ||
(method: string) => (self[method] = instance[method]) | ||
); | ||
|
||
constructor(public readonly options: IApiClientOptions) { | ||
this.log = LoggerProvider.getOrCreate({ label: "api-client " }); | ||
} | ||
Objects.getAllFieldNames(instance).forEach( | ||
(field: string) => (self[field] = instance[field]) | ||
); | ||
|
||
public async call(): Promise<void> { | ||
this.log.debug(`call()`); | ||
return this as T & this; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
packages/cactus-sdk/src/main/typescript/consortium/consortium-service.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { ApiClient } from "./api-client"; | ||
export { ConsortiumService } from "./consortium/consortium-service"; | ||
export * from "./generated/openapi/typescript-axios/index"; |
8 changes: 2 additions & 6 deletions
8
packages/cactus-sdk/src/test/typescript/integration/api-surface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
// tslint:disable-next-line: no-var-requires | ||
const tap = require("tap"); | ||
import { | ||
ApiClient, | ||
ConsortiumService, | ||
} from "../../../main/typescript/public-api"; | ||
import { ApiClient } from "../../../main/typescript/public-api"; | ||
|
||
tap.pass("Test file can be executed"); | ||
|
||
tap.test("Library can be loaded", (assert: any) => { | ||
assert.plan(2); | ||
assert.plan(1); | ||
assert.ok(ApiClient); | ||
assert.ok(ConsortiumService); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
// tslint:disable-next-line: no-var-requires | ||
const tap = require("tap"); | ||
import { | ||
ApiClient, | ||
ConsortiumService, | ||
} from "../../../main/typescript/public-api"; | ||
import { ApiClient } from "../../../main/typescript/public-api"; | ||
|
||
tap.pass("Test file can be executed"); | ||
|
||
tap.test("Library can be loaded", (assert: any) => { | ||
assert.plan(2); | ||
assert.plan(1); | ||
assert.ok(ApiClient); | ||
assert.ok(ConsortiumService); | ||
}); |