本文整理汇总了TypeScript中deepcopy.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
) => new Promise<any>(async (resolve, reject) => {
const opts = options || {
includeSecret: false,
includeProfileImageIds: false
};
let _app: any;
// Populate the app if 'app' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(app)) {
_app = await App.findOne({
_id: app
});
} else if (typeof app === 'string') {
_app = await User.findOne({
_id: new mongo.ObjectID(app)
});
} else {
_app = deepcopy(app);
}
// Me
if (me && !mongo.ObjectID.prototype.isPrototypeOf(me)) {
if (typeof me === 'string') {
me = new mongo.ObjectID(me);
} else {
me = me._id;
}
}
// Rename _id to id
_app.id = _app._id;
delete _app._id;
delete _app.name_id_lower;
// Visible by only owner
if (!opts.includeSecret) {
delete _app.secret;
}
_app.icon_url = _app.icon != null
? `${config.drive_url}/${_app.icon}`
: `${config.drive_url}/app-default.jpg`;
if (me) {
// 既に連携しているか
const exist = await Userkey.count({
app_id: _app.id,
user_id: me,
}, {
limit: 1
});
_app.is_authorized = exist === 1;
}
resolve(_app);
});
示例2: if
export const pack = (notification: any) => new Promise<any>(async (resolve, reject) => {
let _notification: any;
// Populate the notification if 'notification' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(notification)) {
_notification = await Notification.findOne({
_id: notification
});
} else if (typeof notification === 'string') {
_notification = await Notification.findOne({
_id: new mongo.ObjectID(notification)
});
} else {
_notification = deepcopy(notification);
}
// Rename _id to id
_notification.id = _notification._id;
delete _notification._id;
// Rename notifierId to userId
_notification.userId = _notification.notifierId;
delete _notification.notifierId;
const me = _notification.notifieeId;
delete _notification.notifieeId;
// Populate notifier
_notification.user = await packUser(_notification.userId, me);
switch (_notification.type) {
case 'follow':
case 'receiveFollowRequest':
// nope
break;
case 'mention':
case 'reply':
case 'renote':
case 'quote':
case 'reaction':
case 'poll_vote':
// Populate note
_notification.note = await packNote(_notification.noteId, me);
break;
default:
console.error(`Unknown type: ${_notification.type}`);
break;
}
resolve(_notification);
});
示例3: if
) => new Promise<Object>(async (resolve, reject) => {
const opts = options || {
includeParent: false
};
let _folder: any;
// Populate the folder if 'folder' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(folder)) {
_folder = await DriveFolder.findOne({_id: folder});
} else if (typeof folder === 'string') {
_folder = await DriveFolder.findOne({_id: new mongo.ObjectID(folder)});
} else {
_folder = deepcopy(folder);
}
// Rename _id to id
_folder.id = _folder._id;
delete _folder._id;
if (opts.includeParent && _folder.parent_id) {
// Populate parent folder
_folder.parent = await self(_folder.parent_id, {
includeParent: true
});
}
resolve(_folder);
});
示例4: normalizeLibExtension
return pkg.libExtensions.map( ext => {
normalizeLibExtension(ext);
const meta: PackageMetadata = deepcopy(pkg);
meta.parent = pkg;
meta.extension = ext;
meta.name = meta.name + titleCamelCase(ext.name);
meta.umd = meta.umd + '-' + ext.name;
meta.dirName = ext.name;
meta.dir = meta.dir + '/' + ext.dir;
meta.moduleName = meta.moduleName + '.' + voca.camelCase(ext.name);
meta.externals.push(meta.parent.dir);
meta.externalsWebpack.push(getExternalsWebpack(meta.dir)[0]);
// TODO: remove object 'ext', only string... move everything to local package.json of extension
meta.entry = ext.entry;
if (meta.entry.indexOf('.') > -1) {
meta.entry = meta.entry.substr(0, meta.entry.lastIndexOf('.'));
}
tsConfigUpdate(meta.tsConfigObj, meta);
tryRunHook(meta.dir, 'tsconfig', meta.tsConfigObj);
normalizeTsConfig(meta);
meta.libExtensions = undefined;
return meta;
});
示例5: if
) => new Promise<any>(async (resolve, reject) => {
let _reaction: any;
// Populate the reaction if 'reaction' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(reaction)) {
_reaction = await Reaction.findOne({
_id: reaction
});
} else if (typeof reaction === 'string') {
_reaction = await Reaction.findOne({
_id: new mongo.ObjectID(reaction)
});
} else {
_reaction = deepcopy(reaction);
}
// Rename _id to id
_reaction.id = _reaction._id;
delete _reaction._id;
// Populate user
_reaction.user = await packUser(_reaction.userId, me);
resolve(_reaction);
});
示例6: if
) => new Promise<any>(async (resolve, reject) => {
let _request: any;
// Populate the request if 'request' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(request)) {
_request = await FollowRequest.findOne({
_id: request
});
} else if (typeof request === 'string') {
_request = await FollowRequest.findOne({
_id: new mongo.ObjectID(request)
});
} else {
_request = deepcopy(request);
}
// Rename _id to id
_request.id = _request._id;
delete _request._id;
// Populate follower
_request.follower = await packUser(_request.followerId, me);
// Populate followee
_request.followee = await packUser(_request.followeeId, me);
resolve(_request);
});
示例7: if
) => new Promise<any>(async (resolve, reject) => {
let _favorite: any;
// Populate the favorite if 'favorite' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(favorite)) {
_favorite = await Favorite.findOne({
_id: favorite
});
} else if (typeof favorite === 'string') {
_favorite = await Favorite.findOne({
_id: new mongo.ObjectID(favorite)
});
} else {
_favorite = deepcopy(favorite);
}
// Rename _id to id
_favorite.id = _favorite._id;
delete _favorite._id;
// Populate note
_favorite.note = await packNote(_favorite.noteId, me);
resolve(_favorite);
});
示例8: serializeDriveTag
) => new Promise<any>(async (resolve, reject) => {
const opts = Object.assign({
detail: false
}, options);
let _file: any;
// Populate the file if 'file' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(file)) {
_file = await DriveFile.findOne({
_id: file
});
} else if (typeof file === 'string') {
_file = await DriveFile.findOne({
_id: new mongo.ObjectID(file)
});
} else {
_file = deepcopy(file);
}
if (!_file) return reject('invalid file arg.');
// rendered target
let _target: any = {};
_target.id = _file._id;
_target.createdAt = _file.uploadDate;
_target.name = _file.filename;
_target.type = _file.contentType;
_target.datasize = _file.length;
_target.md5 = _file.md5;
_target = Object.assign(_target, _file.metadata);
_target.url = _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`;
_target.thumbnailUrl = _file.metadata.thumbnailUrl ? _file.metadata.thumbnailUrl : _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}?thumbnail`;
_target.isRemote = _file.metadata.isRemote;
if (_target.properties == null) _target.properties = {};
if (opts.detail) {
if (_target.folderId) {
// Populate folder
_target.folder = await packFolder(_target.folderId, {
detail: true
});
}
/*
if (_target.tags) {
// Populate tags
_target.tags = await _target.tags.map(async (tag: any) =>
await serializeDriveTag(tag)
);
}
*/
}
resolve(_target);
});
示例9: deepcopy
) => new Promise<Object>(async (resolve, reject) => {
const _record = deepcopy(record);
// Rename _id to id
_record.id = _record._id;
delete _record._id;
resolve(_record);
});
示例10: if
) => new Promise<any>(async (resolve, reject) => {
const opts = Object.assign({
detail: true
}, options);
let _game: any;
// Populate the game if 'game' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(game)) {
_game = await ReversiGame.findOne({
_id: game
});
} else if (typeof game === 'string') {
_game = await ReversiGame.findOne({
_id: new mongo.ObjectID(game)
});
} else {
_game = deepcopy(game);
}
// Me
const meId: mongo.ObjectID = me
? mongo.ObjectID.prototype.isPrototypeOf(me)
? me as mongo.ObjectID
: typeof me === 'string'
? new mongo.ObjectID(me)
: (me as IUser)._id
: null;
// Rename _id to id
_game.id = _game._id;
delete _game._id;
if (opts.detail === false) {
delete _game.logs;
delete _game.settings.map;
} else {
// 互換性のため
if (_game.settings.map.hasOwnProperty('size')) {
_game.settings.map = _game.settings.map.data.match(new RegExp(`.{1,${_game.settings.map.size}}`, 'g'));
}
}
// Populate user
_game.user1 = await packUser(_game.user1Id, meId);
_game.user2 = await packUser(_game.user2Id, meId);
if (_game.winnerId) {
_game.winner = await packUser(_game.winnerId, meId);
} else {
_game.winner = null;
}
resolve(_game);
});