Skip to content

Commit

Permalink
fix: update typescript version
Browse files Browse the repository at this point in the history
  • Loading branch information
playerx committed Apr 14, 2020
1 parent eeb62c8 commit b921cc0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"ts-jest": "24.0.0",
"ts-node": "8.0.3",
"tslint": "5.13.1",
"typescript": "3.3.3333"
"typescript": "3.8.3"
},
"resolutions": {
"**/event-stream": "^4.0.1"
Expand Down
19 changes: 10 additions & 9 deletions src/common/mapIdFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ import { FilterQuery } from 'mongodb'
import { DocumentBase } from '../types'

export default function <T extends DocumentBase>(filter: FilterQuery<T>) {

// map filter.id to _id
if (filter.id) {
// if just one id is specified
if (typeof filter.id === 'string') {
filter['_id'] = filter.id
const filterAny = filter as any
filterAny['_id'] = filter.id
}
// if $in is used
else if (filter.id['$in'] && (Array.isArray(filter.id['$in']))) {
else if (filter.id['$in'] && Array.isArray(filter.id['$in'])) {
const ids = filter.id['$in']
filter['_id'] = {
$in: ids.map(x => x),
const filterAny = filter as any
filterAny['_id'] = {
$in: ids.map((x) => x),
}
}
else if (filter.id['$ne']) {
} else if (filter.id['$ne']) {
const id = filter.id['$ne']
filter['_id'] = {
const filterAny = filter as any
filterAny['_id'] = {
$ne: id,
}
}
// otherwise please use collection
else {
throw new Error('id can\'t be complex object, please use collection')
throw new Error("id can't be complex object, please use collection")
}

delete filter.id
Expand Down
21 changes: 12 additions & 9 deletions src/common/transformIdFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ import { FilterQuery, ObjectId } from 'mongodb'
import { DocumentBase } from '../types'

export default function <T extends DocumentBase>(filter: FilterQuery<T>) {

// map filter.id if its presented to objectId
// if we need advanced use cases, please use collection
if (filter.id) {
// if just one id is specified
if (typeof filter.id === 'string') {
filter['_id'] = new ObjectId(filter.id)
const filterAny = filter as any
filterAny['_id'] = new ObjectId(filter.id)
}
// if $in is used
else if (filter.id['$in'] && (Array.isArray(filter.id['$in']))) {
else if (filter.id['$in'] && Array.isArray(filter.id['$in'])) {
const ids = filter.id['$in']
filter['_id'] = {
$in: ids.map(x => new ObjectId(x)),

const filterAny = filter as any
filterAny['_id'] = {
$in: ids.map((x) => new ObjectId(x)),
}
}
else if (filter.id['$ne']) {
} else if (filter.id['$ne']) {
const id = filter.id['$ne']
filter['_id'] = {

const filterAny = filter as any
filterAny['_id'] = {
$ne: new ObjectId(id),
}
}
// otherwise please use collection
else {
throw new Error('id can\'t be complex object, please use collection')
throw new Error("id can't be complex object, please use collection")
}

delete filter.id
Expand Down
11 changes: 2 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
"noUnusedParameters": true,
"strict": true,
"outDir": "dist",
"lib": [
"esnext"
]
"lib": ["esnext"]
},
"exclude": [
"node_modules",
"examples",
"dist",
"tests"
]
"exclude": ["node_modules", "examples", "dist", "tests"]
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4096,10 +4096,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@3.3.3333:
version "3.3.3333"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6"
integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw==
typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==

uglify-js@^3.1.4:
version "3.6.0"
Expand Down

0 comments on commit b921cc0

Please sign in to comment.