Skip to content

Commit c76f413

Browse files
authored
Merge pull request #442 from NEMStudios/task/g440_open_api
Applied latest OpenAPI v0.8.2
2 parents c9a014f + e49f901 commit c76f413

File tree

16 files changed

+123
-171
lines changed

16 files changed

+123
-171
lines changed

e2e/infrastructure/DiagnosticHttp.spec.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

e2e/infrastructure/NodeHttp.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,29 @@ describe('NodeHttp', () => {
4848
expect(nodeTime.sendTimeStamp).not.to.be.undefined;
4949
});
5050
});
51+
52+
describe('getStorageInfo', () => {
53+
it('should return storage info', async () => {
54+
const blockchainStorageInfo = await nodeRepository.getStorageInfo().toPromise();
55+
expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0);
56+
expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0);
57+
expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0);
58+
});
59+
});
60+
61+
describe('getServerInfo', () => {
62+
it('should return server info', async () => {
63+
const serverInfo = await nodeRepository.getServerInfo().toPromise();
64+
expect(serverInfo.restVersion).not.to.be.null;
65+
expect(serverInfo.sdkVersion).not.to.be.null;
66+
});
67+
});
68+
69+
describe('getNodeHealth', () => {
70+
it('should return node health', async () => {
71+
const health = await nodeRepository.getNodeHealth().toPromise();
72+
expect(health.apiNode).not.to.be.null;
73+
expect(health.db).not.to.be.null;
74+
});
75+
});
5176
});

package-lock.json

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"js-sha3": "^0.8.0",
6767
"long": "^4.0.0",
6868
"merkletreejs": "^0.1.7",
69-
"nem2-sdk-openapi-typescript-node-client": "0.7.22",
69+
"nem2-sdk-openapi-typescript-node-client": "0.8.2",
7070
"request": "^2.88.0",
7171
"request-promise-native": "^1.0.5",
7272
"ripemd160": "^2.0.2",

src/infrastructure/DiagnosticHttp.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/infrastructure/NodeHttp.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
import { NodeRoutesApi } from 'nem2-sdk-openapi-typescript-node-client';
1818
import { from as observableFrom, Observable, throwError } from 'rxjs';
1919
import { catchError, map } from 'rxjs/operators';
20+
import { StorageInfo } from '../model/blockchain/StorageInfo';
21+
import { NodeHealth } from '../model/node/NodeHealth';
2022
import { NodeInfo } from '../model/node/NodeInfo';
2123
import { NodeTime } from '../model/node/NodeTime';
24+
import { ServerInfo } from '../model/node/ServerInfo';
2225
import { UInt64 } from '../model/UInt64';
2326
import { Http } from './Http';
2427
import { NodeRepository } from './NodeRepository';
@@ -81,4 +84,44 @@ export class NodeHttp extends Http implements NodeRepository {
8184
catchError((error) => throwError(this.errorHandling(error))),
8285
);
8386
}
87+
88+
/**
89+
* Gets blockchain storage info.
90+
* @returns Observable<BlockchainStorageInfo>
91+
*/
92+
public getStorageInfo(): Observable<StorageInfo> {
93+
return observableFrom(
94+
this.nodeRoutesApi.getNodeStorage()).pipe(
95+
map(({body}) => new StorageInfo(
96+
body.numBlocks,
97+
body.numTransactions,
98+
body.numAccounts,
99+
)),
100+
catchError((error) => throwError(this.errorHandling(error))),
101+
);
102+
}
103+
104+
/**
105+
* Gets blockchain server info.
106+
* @returns Observable<Server>
107+
*/
108+
public getServerInfo(): Observable<ServerInfo> {
109+
return observableFrom(
110+
this.nodeRoutesApi.getServerInfo()).pipe(
111+
map(({body}) => new ServerInfo(body.serverInfo.restVersion, body.serverInfo.sdkVersion)),
112+
catchError((error) => throwError(this.errorHandling(error))),
113+
);
114+
}
115+
116+
/**
117+
* Gets blockchain server info.
118+
* @returns Observable<Server>
119+
*/
120+
public getNodeHealth(): Observable<NodeHealth> {
121+
return observableFrom(
122+
this.nodeRoutesApi.getNodeHealth()).pipe(
123+
map(({body}) => new NodeHealth(body.status.apiNode, body.status.db)),
124+
catchError((error) => throwError(this.errorHandling(error))),
125+
);
126+
}
84127
}

src/infrastructure/NodeRepository.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
*/
1616

1717
import {Observable} from 'rxjs';
18+
import { StorageInfo } from '../model/blockchain/StorageInfo';
19+
import { NodeHealth } from '../model/node/NodeHealth';
1820
import { NodeInfo } from '../model/node/NodeInfo';
1921
import { NodeTime } from '../model/node/NodeTime';
22+
import { ServerInfo } from '../model/node/ServerInfo';
2023

2124
/**
2225
* Node interface repository.
@@ -36,4 +39,24 @@ export interface NodeRepository {
3639
* @summary Get the node time
3740
*/
3841
getNodeTime(): Observable<NodeTime>;
42+
43+
/**
44+
* Get node health information
45+
*
46+
* @return {@link NodeHealth} of NodeHealth
47+
*/
48+
getNodeHealth(): Observable<NodeHealth>;
49+
50+
/**
51+
* Gets blockchain storage info.
52+
* @returns Observable<StorageInfo>
53+
*/
54+
getStorageInfo(): Observable<StorageInfo>;
55+
56+
/**
57+
* Gets blockchain server info.
58+
* @returns Observable<Server>
59+
*/
60+
getServerInfo(): Observable<ServerInfo>;
61+
3962
}

src/infrastructure/RepositoryFactory.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { NetworkType } from '../model/blockchain/NetworkType';
1919
import { AccountRepository } from './AccountRepository';
2020
import { BlockRepository } from './BlockRepository';
2121
import { ChainRepository } from './ChainRepository';
22-
import { DiagnosticRepository } from './DiagnosticRepository';
2322
import { IListener } from './IListener';
2423
import { MetadataRepository } from './MetadataRepository';
2524
import { MosaicRepository } from './MosaicRepository';
@@ -76,11 +75,6 @@ export interface RepositoryFactory {
7675
*/
7776
createChainRepository(): ChainRepository;
7877

79-
/**
80-
* @returns a newly created {@link DiagnosticRepository}
81-
*/
82-
createDiagnosticRepository(): DiagnosticRepository;
83-
8478
/**
8579
* @returns a newly created {@link MosaicRepository}
8680
*/

src/infrastructure/RepositoryFactoryHttp.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import { BlockHttp } from './BlockHttp';
2424
import { BlockRepository } from './BlockRepository';
2525
import { ChainHttp } from './ChainHttp';
2626
import { ChainRepository } from './ChainRepository';
27-
import { DiagnosticHttp } from './DiagnosticHttp';
28-
import { DiagnosticRepository } from './DiagnosticRepository';
2927
import { IListener } from './IListener';
3028
import { Listener } from './Listener';
3129
import { MetadataHttp } from './MetadataHttp';
@@ -85,10 +83,6 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
8583
return new ChainHttp(this.url);
8684
}
8785

88-
createDiagnosticRepository(): DiagnosticRepository {
89-
return new DiagnosticHttp(this.url);
90-
}
91-
9286
createMetadataRepository(): MetadataRepository {
9387
return new MetadataHttp(this.url);
9488
}

src/infrastructure/infrastructure.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
export * from './AccountHttp';
1818
export * from './BlockHttp';
1919
export * from './ChainHttp';
20-
export * from './DiagnosticHttp';
2120
export * from './Http';
2221
export * from './MosaicHttp';
2322
export * from './MetadataHttp';
@@ -36,7 +35,6 @@ export * from './transaction/NamespaceMosaicIdGenerator';
3635
export * from './AccountRepository';
3736
export * from './BlockRepository';
3837
export * from './ChainRepository';
39-
export * from './DiagnosticRepository';
4038
export * from './IListener';
4139
export * from './MetadataRepository';
4240
export * from './MosaicRepository';

0 commit comments

Comments
 (0)