From 9427a756c9e4a1d95210ccfca56fdb67d62183ec Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 16 Oct 2018 11:38:09 +0900 Subject: Update mongodb --- src/misc/cafy-id.ts | 5 +++-- src/misc/is-objectid.ts | 3 +++ src/misc/should-mute-this-note.ts | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/misc/is-objectid.ts (limited to 'src/misc') diff --git a/src/misc/cafy-id.ts b/src/misc/cafy-id.ts index f3e1f5251b..3880f0bd0c 100644 --- a/src/misc/cafy-id.ts +++ b/src/misc/cafy-id.ts @@ -1,5 +1,6 @@ import * as mongo from 'mongodb'; import { Context } from 'cafy'; +import isObjectId from './is-objectid'; export const isAnId = (x: any) => mongo.ObjectID.isValid(x); export const isNotAnId = (x: any) => !isAnId(x); @@ -12,7 +13,7 @@ export default class ID extends Context { super(); this.transform = v => { - if (isAnId(v) && !mongo.ObjectID.prototype.isPrototypeOf(v)) { + if (isAnId(v) && !isObjectId(v)) { return new mongo.ObjectID(v); } else { return v; @@ -20,7 +21,7 @@ export default class ID extends Context { }; this.push(v => { - if (!mongo.ObjectID.prototype.isPrototypeOf(v) && isNotAnId(v)) { + if (!isObjectId(v) && isNotAnId(v)) { return new Error('must-be-an-id'); } return true; diff --git a/src/misc/is-objectid.ts b/src/misc/is-objectid.ts new file mode 100644 index 0000000000..8c1aabd568 --- /dev/null +++ b/src/misc/is-objectid.ts @@ -0,0 +1,3 @@ +export default function(x: any): boolean { + return x.hasOwnProperty('toHexString') || x.hasOwnProperty('_bsontype'); +} diff --git a/src/misc/should-mute-this-note.ts b/src/misc/should-mute-this-note.ts index 663e60af6d..b1d29c6a28 100644 --- a/src/misc/should-mute-this-note.ts +++ b/src/misc/should-mute-this-note.ts @@ -1,7 +1,8 @@ import * as mongo from 'mongodb'; +import isObjectId from './is-objectid'; function toString(id: any) { - return mongo.ObjectID.prototype.isPrototypeOf(id) ? (id as mongo.ObjectID).toHexString() : id; + return isObjectId(id) ? (id as mongo.ObjectID).toHexString() : id; } export default function(note: any, mutedUserIds: string[]): boolean { -- cgit v1.2.3-freya