Commit 258f5f15 authored by Cédric Moreau's avatar Cédric Moreau

[enh] Upgrading to TypeScript 3

parent 221a6be5
......@@ -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();
......
......@@ -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]))
}))
......
......@@ -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]))
......
......@@ -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)))
......
......@@ -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]))
}
......
......@@ -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]) {
......
......@@ -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
......
......@@ -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 {
......
......@@ -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": {
......
......@@ -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) {
......
......@@ -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) {
......
rules:
semicolon: [true, "never"]
\ No newline at end of file
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment