From f47bc6bceded7060dc804e9644cee21a62e1516d Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 19 Mar 2019 18:47:14 +0900 Subject: [PATCH] Revert "Remove deepcopy dependency" This reverts commit cbf5663179c60abb6d9f1a612027065432500643. --- package.json | 1 + src/@types/deepcopy.d.ts | 17 +++++++++++++++++ src/misc/deepcopy.ts | 3 --- src/models/abuse-user-report.ts | 2 +- src/models/app.ts | 2 +- src/models/auth-session.ts | 2 +- src/models/blocking.ts | 2 +- src/models/drive-file.ts | 2 +- src/models/drive-folder.ts | 2 +- src/models/favorite.ts | 2 +- src/models/follow-request.ts | 2 +- src/models/games/reversi/game.ts | 2 +- src/models/games/reversi/matching.ts | 2 +- src/models/messaging-message.ts | 2 +- src/models/mute.ts | 2 +- src/models/note-reaction.ts | 2 +- src/models/note.ts | 2 +- src/models/notification.ts | 2 +- src/models/signin.ts | 2 +- src/models/user-list.ts | 2 +- src/models/user.ts | 2 +- src/services/note/create.ts | 2 +- 22 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 src/@types/deepcopy.d.ts delete mode 100644 src/misc/deepcopy.ts diff --git a/package.json b/package.json index 23bcced51..e5eb6b81f 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "cssnano": "4.1.10", "dateformat": "3.0.3", "deep-equal": "1.0.1", + "deepcopy": "0.6.3", "diskusage": "1.0.0", "double-ended-queue": "2.1.0-0", "elasticsearch": "15.4.1", diff --git a/src/@types/deepcopy.d.ts b/src/@types/deepcopy.d.ts new file mode 100644 index 000000000..3eb08d577 --- /dev/null +++ b/src/@types/deepcopy.d.ts @@ -0,0 +1,17 @@ +declare module 'deepcopy'; + +declare namespace deepcopy { + type DeepcopyCustomizerValueType = 'Object'; + + type DeepcopyCustomizer = ( + value: T, + valueType: DeepcopyCustomizerValueType) => T; + + interface DeepcopyOptions { + customizer: DeepcopyCustomizer; + } + + export function deepcopy( + value: T, + options?: DeepcopyOptions | DeepcopyCustomizer): T; +} diff --git a/src/misc/deepcopy.ts b/src/misc/deepcopy.ts deleted file mode 100644 index b3bf09ddb..000000000 --- a/src/misc/deepcopy.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function deepcopy(x: any) { - return JSON.parse(JSON.stringify(x)); -} diff --git a/src/models/abuse-user-report.ts b/src/models/abuse-user-report.ts index 5a1530deb..f3900d348 100644 --- a/src/models/abuse-user-report.ts +++ b/src/models/abuse-user-report.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import { pack as packUser } from './user'; diff --git a/src/models/app.ts b/src/models/app.ts index f46995ea2..45d50bccd 100644 --- a/src/models/app.ts +++ b/src/models/app.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import AccessToken from './access-token'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; diff --git a/src/models/auth-session.ts b/src/models/auth-session.ts index 66454d732..428c70747 100644 --- a/src/models/auth-session.ts +++ b/src/models/auth-session.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import { pack as packApp } from './app'; diff --git a/src/models/blocking.ts b/src/models/blocking.ts index a8025c0ca..4bdaa741e 100644 --- a/src/models/blocking.ts +++ b/src/models/blocking.ts @@ -1,7 +1,7 @@ import * as mongo from 'mongodb'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import { pack as packUser, IUser } from './user'; const Blocking = db.get('blocking'); diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 626ab4ce4..c31e9a709 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import { pack as packFolder } from './drive-folder'; import { pack as packUser } from './user'; import monkDb, { nativeDbConn } from '../db/mongodb'; diff --git a/src/models/drive-folder.ts b/src/models/drive-folder.ts index f9d599950..b0f6e4273 100644 --- a/src/models/drive-folder.ts +++ b/src/models/drive-folder.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import DriveFile from './drive-file'; diff --git a/src/models/favorite.ts b/src/models/favorite.ts index a7504088f..2008edbfa 100644 --- a/src/models/favorite.ts +++ b/src/models/favorite.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import { pack as packNote } from './note'; diff --git a/src/models/follow-request.ts b/src/models/follow-request.ts index 8f7c2b0f6..4f75c63a3 100644 --- a/src/models/follow-request.ts +++ b/src/models/follow-request.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import { pack as packUser } from './user'; diff --git a/src/models/games/reversi/game.ts b/src/models/games/reversi/game.ts index 22710424d..57c493cff 100644 --- a/src/models/games/reversi/game.ts +++ b/src/models/games/reversi/game.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../../../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../../../db/mongodb'; import isObjectId from '../../../misc/is-objectid'; import { IUser, pack as packUser } from '../../user'; diff --git a/src/models/games/reversi/matching.ts b/src/models/games/reversi/matching.ts index 29a6f9a9a..ba2ac1bc0 100644 --- a/src/models/games/reversi/matching.ts +++ b/src/models/games/reversi/matching.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../../../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../../../db/mongodb'; import isObjectId from '../../../misc/is-objectid'; import { IUser, pack as packUser } from '../../user'; diff --git a/src/models/messaging-message.ts b/src/models/messaging-message.ts index e5ffba68b..67abb4d11 100644 --- a/src/models/messaging-message.ts +++ b/src/models/messaging-message.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import { pack as packUser } from './user'; import { pack as packFile } from './drive-file'; import db from '../db/mongodb'; diff --git a/src/models/mute.ts b/src/models/mute.ts index 317beaf0b..52775e13c 100644 --- a/src/models/mute.ts +++ b/src/models/mute.ts @@ -1,7 +1,7 @@ import * as mongo from 'mongodb'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import { pack as packUser, IUser } from './user'; const Mute = db.get('mute'); diff --git a/src/models/note-reaction.ts b/src/models/note-reaction.ts index aaa0c4866..4e449b400 100644 --- a/src/models/note-reaction.ts +++ b/src/models/note-reaction.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import Reaction from './note-reaction'; diff --git a/src/models/note.ts b/src/models/note.ts index 4eab0dd6b..af45ff966 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import rap from '@prezzemolo/rap'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; diff --git a/src/models/notification.ts b/src/models/notification.ts index fc2b829cd..75456af57 100644 --- a/src/models/notification.ts +++ b/src/models/notification.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import { IUser, pack as packUser } from './user'; diff --git a/src/models/signin.ts b/src/models/signin.ts index 2739f214d..d8b05c0e3 100644 --- a/src/models/signin.ts +++ b/src/models/signin.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; const Signin = db.get('signin'); diff --git a/src/models/user-list.ts b/src/models/user-list.ts index b67a6e130..e7dd74bdd 100644 --- a/src/models/user-list.ts +++ b/src/models/user-list.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; diff --git a/src/models/user.ts b/src/models/user.ts index f09cf294a..0c3f7b550 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { deepcopy } from '../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import rap from '@prezzemolo/rap'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 933f5671a..5f69329a4 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -25,7 +25,7 @@ import notesChart from '../../services/chart/notes'; import perUserNotesChart from '../../services/chart/per-user-notes'; import activeUsersChart from '../../services/chart/active-users'; import instanceChart from '../../services/chart/instance'; -import { deepcopy } from '../../misc/deepcopy'; +import * as deepcopy from 'deepcopy'; import { erase, concat } from '../../prelude/array'; import insertNoteUnread from './unread';