From 258f5f15782ce823ae7618152ec78e95b45fedaa Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Sat, 3 Nov 2018 16:59:51 +0100 Subject: [PATCH] [enh] Upgrading to TypeScript 3 --- app/lib/dal/fileDAL.ts | 2 +- app/lib/dal/indexDAL/leveldb/LevelDBIindex.ts | 2 +- app/lib/dal/indexDAL/leveldb/LevelDBMindex.ts | 2 +- app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts | 4 +-- app/lib/dal/sqliteDAL/AbstractSQLite.ts | 6 ++--- app/lib/indexer.ts | 2 +- .../crawler/lib/sync/v2/GlobalIndexStream.ts | 26 +++++++++---------- app/modules/prover/lib/blockGenerator.ts | 2 +- package.json | 2 +- test/integration/misc/http-api.ts | 2 +- test/integration/tools/http-expect.ts | 2 +- tslint.yaml | 2 ++ yarn.lock | 6 ++--- 13 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 tslint.yaml diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 5181d4517..be9960bb1 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -1301,7 +1301,7 @@ export class FileDAL { async close() { await Promise.all(Underscore.values(this.newDals).map(async (dal:Initiable) => { - dal.cleanCache() && dal.cleanCache() + dal.cleanCache() await dal.close() })) await this.sqliteDriver.closeConnection(); diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBIindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBIindex.ts index 3fd3c87f7..1e86f9a76 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBIindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBIindex.ts @@ -62,7 +62,7 @@ export class LevelDBIindex extends LevelDBTable<IindexEntry[]> implements IIndex async insertBatch(records: IindexEntry[]): Promise<void> { // Database insertion const recordsByPub = reduceGroupBy(records, 'pub') - await Promise.all(Underscore.keys(recordsByPub).map(async pub => { + await Promise.all(Underscore.keys(recordsByPub).map(String).map(async pub => { const existing = (await this.getOrNull(pub)) || [] await this.put(pub, existing.concat(recordsByPub[pub])) })) diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBMindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBMindex.ts index 6ce9d3e80..f01f699c0 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBMindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBMindex.ts @@ -55,7 +55,7 @@ export class LevelDBMindex extends LevelDBTable<MindexEntry[]> implements MIndex // Database insertion let prevRecords: MindexEntry[] = [] const recordsByPub = reduceGroupBy(records, 'pub') - await Promise.all(Underscore.keys(recordsByPub).map(async pub => { + await Promise.all(Underscore.keys(recordsByPub).map(String).map(async pub => { const existing = (await this.getOrNull(pub)) || [] prevRecords = prevRecords.concat(existing) await this.put(pub, existing.concat(recordsByPub[pub])) diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts index e2e84cdcb..f4b7c469b 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts @@ -151,7 +151,7 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry> implements SIndexDA } // We update indexes - for (const id of Underscore.keys(mapIds)) { + for (const id of Underscore.keys(mapIds).map(String)) { const map = mapIds[id] await this.trimConditions(map.conditions, id) await this.trimConsumed(map.writtenOn, id) @@ -314,7 +314,7 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry> implements SIndexDA await this.indexForTrimming.put(LevelDBSindex.trimWrittenOnKey(k), byWrittenOn[k].map(r => LevelDBSindex.trimPartialKey(r.identifier, r.pos))) } // Index conditions => (identifier + pos)[] - for (const k of Underscore.keys(byConditions)) { + for (const k of Underscore.keys(byConditions).map(String)) { const existing = (await this.indexForConditions.getOrNull(k)) || [] const newSources = byConditions[k].map(r => LevelDBSindex.trimPartialKey(r.identifier, r.pos)) await this.indexForConditions.put(k, Underscore.uniq(existing.concat(newSources))) diff --git a/app/lib/dal/sqliteDAL/AbstractSQLite.ts b/app/lib/dal/sqliteDAL/AbstractSQLite.ts index 864665ab7..39dce4618 100644 --- a/app/lib/dal/sqliteDAL/AbstractSQLite.ts +++ b/app/lib/dal/sqliteDAL/AbstractSQLite.ts @@ -65,7 +65,7 @@ export abstract class AbstractSQLite<T> extends Initiable { sqlFind(obj:any, sortObj:any = {}): Promise<T[]> { const conditions = this.toConditionsArray(obj).join(' and '); const values = this.toParams(obj); - const sortKeys: string[] = Underscore.keys(sortObj) + const sortKeys: string[] = Underscore.keys(sortObj).map(String) const sort = sortKeys.length ? ' ORDER BY ' + sortKeys.map((k) => "`" + k + "` " + (sortObj[k] ? 'DESC' : 'ASC')).join(',') : ''; return this.query('SELECT * FROM ' + this.table + ' WHERE ' + conditions + sort, values); } @@ -76,12 +76,12 @@ export abstract class AbstractSQLite<T> extends Initiable { } sqlFindLikeAny(obj:any): Promise<T[]> { - const keys:string[] = Underscore.keys(obj) + const keys:string[] = Underscore.keys(obj).map(String) return this.query('SELECT * FROM ' + this.table + ' WHERE ' + keys.map((k) => 'UPPER(`' + k + '`) like ?').join(' or '), keys.map((k) => obj[k].toUpperCase())) } async sqlRemoveWhere(obj:any): Promise<void> { - const keys:string[] = Underscore.keys(obj) + const keys:string[] = Underscore.keys(obj).map(String) await this.query('DELETE FROM ' + this.table + ' WHERE ' + keys.map((k) => '`' + k + '` = ?').join(' and '), keys.map((k) => obj[k])) } diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 818266499..c8bd03467 100644 --- a/app/lib/indexer.ts +++ b/app/lib/indexer.ts @@ -2019,7 +2019,7 @@ async function checkPeopleAreNotOudistanced (pubkeys: string[], newLinks: { [k:s }, <{ [k:string]: number }>{}); // Add temporarily the links to the WoT let tempLinks = []; - let toKeys = Underscore.keys(newLinks) + let toKeys = Underscore.keys(newLinks).map(String) for (const toKey of toKeys) { let toNode = await getNodeIDfromPubkey(nodesCache, toKey, dal); for (const fromKey of newLinks[toKey]) { diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts index d180c9a4d..de32a3a97 100644 --- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts +++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts @@ -104,9 +104,9 @@ export class GlobalIndexStream extends Duplex { } private async injectLoki<T, K extends keyof T>(dal: T, f: K, obj: T[K]) { - this.mapInjection[f] = dal[f] - dal[f] = obj - await (obj as any).triggerInit() + // this.mapInjection[f] = dal[f] + // dal[f] = obj + // await (obj as any).triggerInit() } readChunk(i: number) { @@ -422,16 +422,16 @@ export class GlobalIndexStream extends Duplex { // Disabled for now async function inject<T, K extends keyof T, R, S extends T[K]>(fileDal: T, field: K, getRows: () => Promise<R[]>) { - const dao = that.mapInjection[field] - if (dao) { - NewLogger().info(`Mem2File [${field}]...`) - const rows = await getRows() - await (dao as any).insertBatch(rows) // TODO : "any" complicated to remove - fileDal[field] = dao - } - else { - throw Error(DataErrors[DataErrors.SYNC_FAST_MEM_ERROR_DURING_INJECTION]) - } + // const dao = that.mapInjection[field] + // if (dao) { + // NewLogger().info(`Mem2File [${field}]...`) + // const rows = await getRows() + // await (dao as any).insertBatch(rows) // TODO : "any" complicated to remove + // fileDal[field] = dao + // } + // else { + // throw Error(DataErrors[DataErrors.SYNC_FAST_MEM_ERROR_DURING_INJECTION]) + // } } this.memToCopyDone = true diff --git a/app/modules/prover/lib/blockGenerator.ts b/app/modules/prover/lib/blockGenerator.ts index 9b5690aa9..1f30d044e 100644 --- a/app/modules/prover/lib/blockGenerator.ts +++ b/app/modules/prover/lib/blockGenerator.ts @@ -198,7 +198,7 @@ export class BlockGenerator { const members = await this.dal.getMembers(); const wotMembers = Underscore.pluck(members, 'pubkey'); // Checking step - let newcomers = Underscore.keys(joinData) + let newcomers = Underscore.keys(joinData).map(String) newcomers = Underscore.shuffle(newcomers) const nextBlockNumber = current ? current.number + 1 : 0; try { diff --git a/package.json b/package.json index 5cdd60b4f..793d8b3d1 100644 --- a/package.json +++ b/package.json @@ -131,7 +131,7 @@ "tmp": "0.0.29", "ts-node": "^3.3.0", "typedoc-plugin-sourcefile-url": "^1.0.3", - "typescript": "~2.8.1" + "typescript": "^3.1.6" }, "peerDependencies": {}, "bin": { diff --git a/test/integration/misc/http-api.ts b/test/integration/misc/http-api.ts index 4280e4dcb..2eb0ec0eb 100644 --- a/test/integration/misc/http-api.ts +++ b/test/integration/misc/http-api.ts @@ -333,7 +333,7 @@ async function expectJSON<T>(promise:Promise<T>, json:any) { try { const resJson = await promise; Underscore.keys(json).forEach(function(key){ - resJson.should.have.property(key).equal(json[key]); + resJson.should.have.property(String(key)).equal(json[key]); }); } catch (err) { if (err.response) { diff --git a/test/integration/tools/http-expect.ts b/test/integration/tools/http-expect.ts index 19053cfbf..141650719 100644 --- a/test/integration/tools/http-expect.ts +++ b/test/integration/tools/http-expect.ts @@ -59,7 +59,7 @@ export async function expectJSON<T>(promise:Promise<T>, json:any) { try { const resJson = await promise; Underscore.keys(json).forEach(function(key){ - resJson.should.have.property(key).equal(json[key]); + resJson.should.have.property(String(key)).equal(json[key]); }); } catch (err) { if (err.response) { diff --git a/tslint.yaml b/tslint.yaml new file mode 100644 index 000000000..81270d0b4 --- /dev/null +++ b/tslint.yaml @@ -0,0 +1,2 @@ +rules: + semicolon: [true, "never"] \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 6c3d7cbd5..57f38ec65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4444,9 +4444,9 @@ typescript@2.7.2: version "2.7.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836" -typescript@~2.8.1: - version "2.8.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.4.tgz#0b1db68e6bdfb0b767fa2ab642136a35b059b199" +typescript@^3.1.6: + version "3.1.6" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68" uglify-js@^2.6: version "2.8.29" -- GitLab