Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Sep 4, 2023
1 parent a8ecf4c commit 0597be4
Show file tree
Hide file tree
Showing 5 changed files with 1,483 additions and 1,660 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"dependencies": {
"@naturalcycles/db-lib": "^8.0.1",
"@naturalcycles/js-lib": "^14.0.0",
"@naturalcycles/nodejs-lib": "^12.2.2",
"mongodb": "^5.0.0"
"@naturalcycles/nodejs-lib": "^13.1.3",
"mongodb": "^6.0.0"
},
"devDependencies": {
"@naturalcycles/dev-lib": "^13.6.0",
"@types/node": "^18.7.18",
"@types/node": "^20.5.9",
"dotenv": "^16.0.0",
"jest": "^29.0.3"
},
Expand Down
3 changes: 1 addition & 2 deletions scripts/backup.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ DEBUG=nc* yarn tsn backup.script.ts
*/

import { dbPipelineBackup } from '@naturalcycles/db-lib'
import { requireEnvKeys } from '@naturalcycles/nodejs-lib'
import { runScript } from '@naturalcycles/nodejs-lib/dist/script'
import { requireEnvKeys, runScript } from '@naturalcycles/nodejs-lib'
import { MongoDB } from '../src'
import { tmpDir } from '../src/test/paths.cnst'

Expand Down
10 changes: 7 additions & 3 deletions src/mongo.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface MongoDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjec

export interface MongoDBOptions extends CommonDBOptions, CommandOperationOptions {}

export class MongoDB extends BaseCommonDB implements CommonDB {
export class MongoDB extends BaseCommonDB implements CommonDB, AsyncDisposable {
constructor(cfg: MongoDBCfg) {
super()

Expand All @@ -52,7 +52,7 @@ export class MongoDB extends BaseCommonDB implements CommonDB {
}
}

public cfg: MongoDBCfg & { logger: CommonLogger }
cfg: MongoDBCfg & { logger: CommonLogger }

@_Memo()
async client(): Promise<MongoClient> {
Expand All @@ -74,6 +74,10 @@ export class MongoDB extends BaseCommonDB implements CommonDB {
this.cfg.logger.log(`closed`)
}

async [Symbol.asyncDispose](): Promise<void> {
await this.close()
}

override async ping(): Promise<void> {
await this.client()
}
Expand Down Expand Up @@ -287,7 +291,7 @@ export class MongoDB extends BaseCommonDB implements CommonDB {
}
})
} finally {
await session.endSession() // eslint-disable-line @typescript-eslint/await-thenable
await session.endSession()
}
// todo: is catch/revert needed?
}
Expand Down
13 changes: 8 additions & 5 deletions src/query.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ export function dbQueryToMongoQuery<ROW extends ObjectWithId>(
}, {} as Filter<ROW>)

// order
// eslint-disable-next-line unicorn/no-array-reduce, unicorn/prefer-object-from-entries
options.sort = dbQuery._orders.reduce((map, ord) => {
map[FNAME_MAP[ord.name as string] || (ord.name as string)] = ord.descending ? -1 : 1
return map
}, {} as Record<string, SortDirection>)
// eslint-disable-next-line unicorn/no-array-reduce
options.sort = dbQuery._orders.reduce(
(map, ord) => {
map[FNAME_MAP[ord.name as string] || (ord.name as string)] = ord.descending ? -1 : 1
return map
},
{} as Record<string, SortDirection>,
)

// limit
options.limit = dbQuery._limitValue || undefined
Expand Down
Loading

0 comments on commit 0597be4

Please sign in to comment.