Skip to content

Commit

Permalink
fix: adapt to latest db-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Apr 16, 2022
1 parent 03b4732 commit 6785658
Show file tree
Hide file tree
Showing 5 changed files with 1,633 additions and 1,537 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
if: "!contains(github.event.head_commit.message, 'skip ci')"
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v2, with: { persist-credentials: true } }
- { uses: actions/setup-node@v2, with: { node-version: 16, cache: 'yarn' } }
- { uses: actions/checkout@v3, with: { persist-credentials: true } }
- { uses: actions/setup-node@v3, with: { node-version: 16, cache: 'yarn' } }

# Cache for npm/npx in ~/.npm
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.npm
key: npm-v1-${{ runner.os }}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"devDependencies": {
"@naturalcycles/dev-lib": "^12.0.3",
"@types/node": "^16.3.3",
"dotenv": "^10.0.0",
"@types/node": "^17.0.24",
"dotenv": "^16.0.0",
"jest": "^27.0.4"
},
"files": [
Expand Down
12 changes: 6 additions & 6 deletions src/mongo.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ReadableTyped } from '@naturalcycles/nodejs-lib'
import { CommandOperationOptions, Filter, MongoClient, MongoClientOptions } from 'mongodb'
import { dbQueryToMongoQuery } from './query.util'

export type MongoObject<T> = T & { _id: string }
export type MongoObject<T> = T & { _id: string | number }

export interface MongoDBCfg {
uri: string
Expand Down Expand Up @@ -133,7 +133,7 @@ export class MongoDB extends BaseCommonDB implements CommonDB {

override async getByIds<ROW extends ObjectWithId>(
table: string,
ids: string[],
ids: ROW['id'][],
_opt?: CommonDBOptions,
): Promise<ROW[]> {
if (!ids.length) return []
Expand All @@ -147,13 +147,13 @@ export class MongoDB extends BaseCommonDB implements CommonDB {
$in: ids,
},
})
.toArray()) as MongoObject<ROW>[]
.toArray()) as any as MongoObject<ROW>[]
return items.map(i => this.mapFromMongo(i))
}

override async deleteByIds(
override async deleteByIds<ROW extends ObjectWithId>(
table: string,
ids: string[],
ids: ROW['id'][],
opt: MongoDBOptions = {},
): Promise<number> {
if (!ids.length) return 0
Expand Down Expand Up @@ -185,7 +185,7 @@ export class MongoDB extends BaseCommonDB implements CommonDB {
.db(this.cfg.db)
.collection<ROW>(q.table)
.find(query, options) // eslint-disable-line unicorn/no-array-method-this-argument
.toArray()) as MongoObject<ROW>[]
.toArray()) as any as MongoObject<ROW>[]

let rows = items.map(i => this.mapFromMongo(i as any))

Expand Down
2 changes: 1 addition & 1 deletion src/query.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function dbQueryToMongoQuery<ROW extends ObjectWithId>(
[OP_MAP[f.op] || f.op]: f.val,
}
return q
}, {} as Filter<any>)
}, {} as Filter<ROW>)

// order
// eslint-disable-next-line unicorn/no-array-reduce, unicorn/prefer-object-from-entries
Expand Down
Loading

0 comments on commit 6785658

Please sign in to comment.