Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Upgrade mongodb typings #27424

Merged
merged 4 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Expand Up @@ -270,7 +270,6 @@ API.v1.addRoute(
return API.v1.unauthorized();
}

// @ts-expect-error recursive types are causing issues here
const { cursor, totalCount } = Messages.findPaginated(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
Expand Down
@@ -1,6 +1,6 @@
import { MongoInternals } from 'meteor/mongo';
import { ObjectId } from 'mongodb';
import type { GridFSBucket, GridFSBucketWriteStream } from 'mongodb';
import type { GridFSBucketWriteStream } from 'mongodb';
import { ObjectId, GridFSBucket } from 'mongodb';
import type { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage';
import { AppSourceStorage } from '@rocket.chat/apps-engine/server/storage';

Expand All @@ -14,7 +14,6 @@ export class AppGridFSSourceStorage extends AppSourceStorage {
constructor() {
super();

const { GridFSBucket } = MongoInternals.NpmModules.mongodb.module;
const { db } = MongoInternals.defaultRemoteCollectionDriver().mongo;

this.bucket = new GridFSBucket(db, {
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/inquiries.ts
Expand Up @@ -58,7 +58,6 @@ export async function findInquiries({
],
};

// @ts-ignore - LivechatInquiry has a ref to messages
const { cursor, totalCount } = LivechatInquiry.findPaginated(filter, options);

const [inquiries, total] = await Promise.all([cursor.toArray(), totalCount]);
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/transfer.ts
Expand Up @@ -13,7 +13,6 @@ export async function findLivechatTransferHistory({
rid: string;
pagination: { offset: number; count: number; sort: Record<string, number> };
}): Promise<PaginatedResult<{ history: IOmnichannelSystemMessage['transferData'][] }>> {
// @ts-ignore - Messages destroys everything it touches
const { cursor, totalCount } = Messages.findPaginated(
{ rid, t: 'livechat_transfer_history' },
{
Expand Down
Expand Up @@ -2,6 +2,7 @@ import moment from 'moment-timezone';
import type { ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHoursModel, IUsersModel } from '@rocket.chat/model-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';
import type { UpdateFilter } from 'mongodb';

import type { IWorkHoursCronJobsWrapper } from '../../../../server/models/raw/LivechatBusinessHours';

Expand Down Expand Up @@ -62,7 +63,9 @@ export abstract class AbstractBusinessHourType {
businessHourData.active = Boolean(businessHourData.active);
businessHourData = this.convertWorkHours(businessHourData);
if (businessHourData._id) {
await this.BusinessHourRepository.updateOne({ _id: businessHourData._id }, { $set: businessHourData });
await this.BusinessHourRepository.updateOne({ _id: businessHourData._id }, {
$set: businessHourData,
} as UpdateFilter<ILivechatBusinessHour>); // TODO: Remove this cast when TypeScript is updated
return businessHourData._id;
}
const { insertedId } = await this.BusinessHourRepository.insertOne(businessHourData);
Expand Down
8 changes: 3 additions & 5 deletions apps/meteor/app/ui/client/lib/ChatMessages.ts
Expand Up @@ -379,16 +379,15 @@ export class ChatMessages {
readMessage.readNow(rid);
readMessage.refreshUnreadMark(rid);

const message = await onClientBeforeSendMessage({
const message = (await onClientBeforeSendMessage({
_id: Random.id(),
rid,
tshow,
tmid,
msg,
});
})) as IMessage;

try {
// @ts-ignore
await this.processMessageSend(message);
this.quotedMessages.clear();
} catch (error) {
Expand All @@ -405,8 +404,7 @@ export class ChatMessages {

try {
if (message.attachments && message.attachments?.length > 0) {
// @ts-ignore
await this.processMessageEditing({ _id: this.editing.id, rid, msg: '' });
await this.processMessageEditing({ _id: this.editing.id, rid, msg: '' } as IMessage);
return;
}

Expand Down
14 changes: 5 additions & 9 deletions apps/meteor/ee/server/lib/registerServiceModels.ts
Expand Up @@ -28,28 +28,24 @@ import { EmailInboxRaw } from '../../../server/models/raw/EmailInbox';
import { PbxEventsRaw } from '../../../server/models/raw/PbxEvents';

// TODO add trash param to appropiate model instances
export function registerServiceModels(db: Db, trash?: Collection): void {
export function registerServiceModels(db: Db, trash?: Collection<RocketChatRecordDeleted<any>>): void {
registerModel('IRolesModel', () => new RolesRaw(db));
registerModel('IRoomsModel', () => new RoomsRaw(db));
registerModel('ISettingsModel', () => new SettingsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ISetting>>));
registerModel(
'ISubscriptionsModel',
() => new SubscriptionsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ISubscription>>),
);
registerModel('ISettingsModel', () => new SettingsRaw(db, trash as Collection<RocketChatRecordDeleted<ISetting>>));
registerModel('ISubscriptionsModel', () => new SubscriptionsRaw(db, trash as Collection<RocketChatRecordDeleted<ISubscription>>));
registerModel('ITeamModel', () => new TeamRaw(db));
registerModel('ITeamMemberModel', () => new TeamMemberRaw(db));
registerModel('IUsersModel', () => new UsersRaw(db));

// @ts-ignore-error
registerModel('IMessagesModel', () => new MessagesRaw(db));

registerModel(
'ILivechatInquiryModel',
() => new LivechatInquiryRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ILivechatInquiryRecord>>),
() => new LivechatInquiryRaw(db, trash as Collection<RocketChatRecordDeleted<ILivechatInquiryRecord>>),
);
registerModel(
'ILivechatDepartmentAgentsModel',
() => new LivechatDepartmentAgentsRaw(db, trash as unknown as Collection<RocketChatRecordDeleted<ILivechatDepartmentAgents>>),
() => new LivechatDepartmentAgentsRaw(db, trash as Collection<RocketChatRecordDeleted<ILivechatDepartmentAgents>>),
);
registerModel('IUsersSessionsModel', () => new UsersSessionsRaw(db));
registerModel('IPermissionsModel', () => new PermissionsRaw(db));
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/ee/server/models/raw/LivechatRooms.ts
Expand Up @@ -23,7 +23,6 @@ declare module '@rocket.chat/model-typings' {
}
}

// Note: Expect a circular dependency error here 😓
export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoomsModel {
async unsetAllPredictedVisitorAbandonment(): Promise<void> {
return this.updateMany(
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/services/package.json
Expand Up @@ -40,7 +40,7 @@
"jaeger-client": "^3.19.0",
"mem": "^8.1.1",
"moleculer": "^0.14.21",
"mongodb": "^4.3.1",
"mongodb": "^4.12.1",
"nats": "^2.6.1",
"pino": "^7.11.0",
"sodium-native": "^3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Expand Up @@ -333,7 +333,7 @@
"moleculer": "^0.14.21",
"moment": "^2.29.4",
"moment-timezone": "^0.5.34",
"mongodb": "^4.3.1",
"mongodb": "^4.12.1",
"mongodb-memory-server": "^7.6.3",
"nats": "^2.6.1",
"node-dogstatsd": "^0.0.7",
Expand Down