summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-10-16 11:38:09 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-10-16 11:38:09 +0900
commit9427a756c9e4a1d95210ccfca56fdb67d62183ec (patch)
tree667cf5f4d6ecf80d0e3a22c4085a410537d1dc9d /src/misc
parentfix(package): update @types/node to version 10.12.0 (#2912) (diff)
downloadsharkey-9427a756c9e4a1d95210ccfca56fdb67d62183ec.tar.gz
sharkey-9427a756c9e4a1d95210ccfca56fdb67d62183ec.tar.bz2
sharkey-9427a756c9e4a1d95210ccfca56fdb67d62183ec.zip
Update mongodb
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/cafy-id.ts5
-rw-r--r--src/misc/is-objectid.ts3
-rw-r--r--src/misc/should-mute-this-note.ts3
3 files changed, 8 insertions, 3 deletions
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<mongo.ObjectID> {
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<mongo.ObjectID> {
};
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 {