Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Commit 65b5001

Browse files
authored
Be 769 convert to ts (#184)
Signed-off-by: jeeva <jeevasang@gmail.com>
1 parent 571ba55 commit 65b5001

38 files changed

+312
-295
lines changed

app/Explorer.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,31 @@
22
* SPDX-License-Identifier: Apache-2.0
33
*/
44

5-
const Express = require('express');
6-
const bodyParser = require('body-parser');
7-
const swaggerUi = require('swagger-ui-express');
8-
const compression = require('compression');
9-
const passport = require('passport');
10-
const RateLimit = require('express-rate-limit');
5+
import Express from 'express';
6+
import bodyParser from 'body-parser';
7+
import swaggerUi from 'swagger-ui-express';
8+
import compression from 'compression';
9+
import passport from 'passport';
10+
import RateLimit from 'express-rate-limit';
1111
import {PlatformBuilder } from './platform/PlatformBuilder';
12-
const explorerconfig = require('./explorerconfig.json');
13-
const PersistenceFactory = require('./persistence/PersistenceFactory');
14-
const ExplorerError = require('./common/ExplorerError');
15-
16-
const localLoginStrategy = require('./passport/local-login');
17-
const authroutes = require('./rest/authroutes');
18-
const dbroutes = require('./rest/dbroutes');
19-
const platformroutes = require('./rest/platformroutes');
20-
const adminroutes = require('./platform/fabric/rest/adminroutes');
21-
22-
const authCheckMiddleware = require('./middleware/auth-check');
23-
24-
const swaggerDocument = require('../swagger.json');
25-
12+
import explorerconfig from './explorerconfig.json';
13+
import {PersistenceFactory} from './persistence/PersistenceFactory';
14+
import {authroutes} from './rest/authroutes';
15+
import {dbroutes} from './rest/dbroutes';
16+
import {platformroutes} from './rest/platformroutes';
17+
import {adminroutes} from './platform/fabric/rest/adminroutes';
2618
import {explorerConst} from './common/ExplorerConst'
2719
import {explorerError} from './common/ExplorerMessage'
28-
20+
import authCheckMiddleware from './middleware/auth-check';
21+
import swaggerDocument from '../swagger.json';
22+
import {ExplorerError} from './common/ExplorerError';
23+
const localLoginStrategy = require('./passport/local-login');
2924
/**
3025
*
3126
*
3227
* @class Explorer
3328
*/
34-
class Explorer {
29+
export class Explorer {
3530

3631
app = Express();
3732
persistence : any;
@@ -119,12 +114,12 @@ class Explorer {
119114

120115
this.app.use('/api', authCheckMiddleware);
121116

122-
const authrouter = new Express.Router();
117+
const authrouter = Express.Router();
123118

124119
// Initializing the rest app services
125120
await authroutes(authrouter, platform);
126121

127-
const apirouter = new Express.Router();
122+
const apirouter = Express.Router();
128123

129124
// Initializing the rest app services
130125
await dbroutes(apirouter, platform);
@@ -157,6 +152,4 @@ class Explorer {
157152
}
158153
}
159154
}
160-
}
161-
162-
module.exports = Explorer;
155+
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
*/
44
/* eslint-disable import/extensions */
55
import { helper } from './common/helper';
6-
76
import { explorerConst } from './common/ExplorerConst';
87
import { explorerError } from './common/ExplorerMessage';
8+
import {ExplorerError} from './common/ExplorerError';
9+
import syncconfig from './explorerconfig.json';
10+
import {SyncBuilder} from './sync/SyncBuilder';
11+
import {PersistenceFactory} from './persistence/PersistenceFactory';
12+
import {ExplorerSender} from './sync/sender/ExplorerSender';
913
/* eslint-enable import/extensions */
10-
11-
const syncconfig = require('./explorerconfig.json');
12-
const ExplorerError = require('./common/ExplorerError');
13-
1414
const logger = helper.getLogger('Synchronizer');
15-
const SyncBuilder = require('./sync/SyncBuilder');
16-
const PersistenceFactory = require('./persistence/PersistenceFactory');
17-
const ExplorerSender = require('./sync/sender/ExplorerSender');
1815

1916
/**
2017
*
2118
*
2219
* @class Synchronizer
2320
*/
24-
class Synchronizer {
21+
export class Synchronizer {
22+
args: any;
23+
persistence: any;
24+
platform: any;
2525
/**
2626
* Creates an instance of Synchronizer.
2727
* @param {*} args
2828
* @memberof Synchronizer
2929
*/
30-
constructor(args) {
30+
constructor(args: any) {
3131
this.args = args;
3232
this.persistence = null;
3333
this.platform = null;
@@ -91,6 +91,4 @@ class Synchronizer {
9191
this.platform.destroy();
9292
}
9393
}
94-
}
95-
96-
module.exports = Synchronizer;
94+
}

app/common/ExplorerError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import util from 'util';
1313
* %% - single percent sign ('%'). This does not consume an argument.
1414
* }
1515
*/
16-
module.exports = function ExplorerError(...args) {
16+
export function ExplorerError(...args: string[]) {
1717
Error.captureStackTrace(this, this.constructor);
1818
this.name = this.constructor.name;
1919
this.message = util.format(args);
2020
};
2121

22-
require('util').inherits(module.exports, Error);
22+
//require('util').inherits(module.exports, Error);

app/common/commonUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const logger = helper.getLogger('ForkSenderHandler');
1414
* @returns
1515
*/
1616

17-
function toUTCmilliseconds(dateStr) {
17+
export function toUTCmilliseconds(dateStr: any) {
1818
let startSyncMills = null;
1919
try {
2020
startSyncMills = Date.parse(dateStr);
@@ -23,5 +23,3 @@ function toUTCmilliseconds(dateStr) {
2323
}
2424
return startSyncMills;
2525
}
26-
27-
exports.toUTCmilliseconds = toUTCmilliseconds;

app/common/helper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
* limitations under the License.
1919
*/
2020

21-
const log4js = require('log4js/lib/log4js');
21+
import log4js from 'log4js/lib/log4js';
2222

23-
const fs = require('fs-extra');
24-
const yn = require('yn');
23+
import yn from 'yn';
2524

2625
/*
2726
* Please assign the logger with the file name for the application logging and assign the logger with "PgService"
@@ -43,7 +42,7 @@ const yn = require('yn');
4342
*/
4443
export class helper {
4544

46-
static getLogger(moduleName) : any {
45+
static getLogger(moduleName: string) : any {
4746
const logger = log4js.getLogger(moduleName);
4847

4948
let appLog = 'logs/app/app.log';

app/persistence/PersistenceFactory.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import {explorerConst} from '../common/ExplorerConst'
66
import {explorerError} from '../common/ExplorerMessage'
7-
const ExplorerError = require('../common/ExplorerError');
7+
import {ExplorerError} from '../common/ExplorerError';
88

99
/**
1010
*
1111
*
1212
* @class PersistenceFactory
1313
*/
14-
class PersistenceFactory {
14+
export class PersistenceFactory {
1515
/**
1616
*
1717
*
@@ -21,7 +21,7 @@ class PersistenceFactory {
2121
* @returns
2222
* @memberof PersistenceFactory
2323
*/
24-
static async create(db, dbconfig) {
24+
static async create(db: string, dbconfig: any) {
2525
console.log("check",explorerConst.PERSISTENCE_POSTGRESQL)
2626
if (db === explorerConst.PERSISTENCE_POSTGRESQL) {
2727
// Avoid to load all db Persist module
@@ -32,6 +32,4 @@ class PersistenceFactory {
3232
}
3333
throw new ExplorerError(explorerError.ERROR_1003, db);
3434
}
35-
}
36-
37-
module.exports = PersistenceFactory;
35+
}

app/persistence/fabric/CRUDService.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CRUDService {
2727
* @memberof CRUDService
2828
*/
2929

30-
getTxCountByBlockNum(network_name, channel_genesis_hash, blockNum) {
30+
getTxCountByBlockNum(network_name: any, channel_genesis_hash: any, blockNum: any) {
3131
return this.sql.getRowByPkOne(
3232
`select blocknum ,txcount from blocks where channel_genesis_hash='${channel_genesis_hash}' and blocknum=${blockNum} and network_name = '${network_name}' `
3333
);
@@ -41,7 +41,7 @@ export class CRUDService {
4141
* @returns
4242
* @memberof CRUDService
4343
*/
44-
getTransactionByID(network_name, channel_genesis_hash, txhash) {
44+
getTransactionByID(network_name: any, channel_genesis_hash: any, txhash: any) {
4545
const sqlTxById = ` select t.txhash,t.validation_code,t.payload_proposal_hash,t.creator_msp_id,t.endorser_msp_id,t.chaincodename,t.type,t.createdt,t.read_set,
4646
t.write_set,channel.name as channelName from TRANSACTIONS as t inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name=channel.network_name
4747
where t.txhash = '${txhash}' and t.network_name = '${network_name}' `;
@@ -56,7 +56,7 @@ export class CRUDService {
5656
* @memberof CRUDService
5757
*/
5858

59-
getBlockActivityList(network_name, channel_genesis_hash) {
59+
getBlockActivityList(network_name: any, channel_genesis_hash: any) {
6060
const sqlBlockActivityList = `select blocks.blocknum,blocks.txcount ,blocks.datahash ,blocks.blockhash ,blocks.prehash,blocks.createdt, (
6161
SELECT array_agg(txhash) as txhash FROM transactions where blockid = blocks.blocknum and
6262
channel_genesis_hash = '${channel_genesis_hash}' and network_name = '${network_name}' group by transactions.blockid ),
@@ -78,7 +78,7 @@ export class CRUDService {
7878
* @returns
7979
* @memberof CRUDService
8080
*/
81-
getTxList(network_name, channel_genesis_hash, blockNum, txid, from, to, orgs) {
81+
getTxList(network_name: any, channel_genesis_hash: any, blockNum: any, txid: any, from: any, to: any, orgs: string) {
8282
let byOrgs = false;
8383
if (orgs && orgs !== '') {
8484
byOrgs = true;
@@ -113,12 +113,12 @@ export class CRUDService {
113113
* @memberof CRUDService
114114
*/
115115
getBlockAndTxList(
116-
network_name,
117-
channel_genesis_hash,
118-
blockNum,
119-
from,
120-
to,
121-
orgs
116+
network_name: any,
117+
channel_genesis_hash: any,
118+
blockNum: any,
119+
from: any,
120+
to: any,
121+
orgs: string
122122
) {
123123
let byOrgs = false;
124124
// workaround for SQL injection
@@ -162,7 +162,7 @@ export class CRUDService {
162162
* @memberof CRUDService
163163
*/
164164

165-
async getChannelConfig(network_name, channel_genesis_hash) {
165+
async getChannelConfig(network_name: any, channel_genesis_hash: any) {
166166
const channelConfig = await this.sql.getRowsBySQlCase(
167167
` select * from channel where channel_genesis_hash ='${channel_genesis_hash}' and network_name = '${network_name}' `
168168
);
@@ -177,7 +177,7 @@ export class CRUDService {
177177
* @returns
178178
* @memberof CRUDService
179179
*/
180-
async getChannel(network_name, channelname, channel_genesis_hash) {
180+
async getChannel(network_name: any, channelname: any, channel_genesis_hash: any) {
181181
const channel = await this.sql.getRowsBySQlCase(
182182
` select * from channel where name='${channelname}' and channel_genesis_hash='${channel_genesis_hash}' and network_name = '${network_name}' `
183183
);
@@ -190,7 +190,7 @@ export class CRUDService {
190190
* @returns
191191
* @memberof CRUDService
192192
*/
193-
async existChannel(network_name, channelname) {
193+
async existChannel(network_name: any, channelname: any) {
194194
const channel = await this.sql.getRowsBySQlCase(
195195
` select count(1) from channel where name='${channelname}' and network_name = '${network_name}' `
196196
);

0 commit comments

Comments
 (0)