chore: Removed comment related codes from RTS (#20639)
As part of the removing comment related codes, this PR removes the unused codes from RTS.
This commit is contained in:
parent
73ba3a39c5
commit
95b5e8ce9e
|
|
@ -1,3 +1,2 @@
|
|||
APPSMITH_MONGODB_URI=mongodb://localhost:27017/appsmith
|
||||
APPSMITH_API_BASE_URL=http://localhost:8080/api/v1
|
||||
PORT=8091
|
||||
|
|
@ -13,7 +13,6 @@
|
|||
"devDependencies": {
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/jest": "^29.2.3",
|
||||
"@types/mongodb": "^3.6.10",
|
||||
"axios": "^1.2.0",
|
||||
"jest": "^29.3.1",
|
||||
"source-map-support": "^0.5.19",
|
||||
|
|
@ -23,8 +22,8 @@
|
|||
"typescript": "^4.5.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test:unit": "export APPSMITH_API_BASE_URL=http APPSMITH_MONGODB_URI=mongodb && $(npm bin)/jest -b --colors --no-cache --silent --coverage --collectCoverage=true --coverageDirectory='./' --coverageReporters='json-summary'",
|
||||
"test:jest": "export APPSMITH_API_BASE_URL=http APPSMITH_MONGODB_URI=mongodb && $(npm bin)/jest --watch ",
|
||||
"test:unit": "export APPSMITH_API_BASE_URL=http && $(npm bin)/jest -b --colors --no-cache --silent --coverage --collectCoverage=true --coverageDirectory='./' --coverageReporters='json-summary'",
|
||||
"test:jest": "export APPSMITH_API_BASE_URL=http && $(npm bin)/jest --watch ",
|
||||
"preinstall": "CURRENT_SCOPE=rts node ../shared/build-shared-dep.js",
|
||||
"build": "./build.sh",
|
||||
"postinstall": "CURRENT_SCOPE=rts node ../shared/install-dependencies.js",
|
||||
|
|
@ -35,7 +34,6 @@
|
|||
"express-validator": "^6.14.2",
|
||||
"http-status-codes": "^2.2.0",
|
||||
"loglevel": "^1.8.1",
|
||||
"mongodb": "^3.6.4",
|
||||
"socket.io": "^4.5.4",
|
||||
"socket.io-adapter": "^2.4.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,16 +18,6 @@ const logLevel: LogLevelDesc = (process.env.APPSMITH_LOG_LEVEL ||
|
|||
"debug") as LogLevelDesc;
|
||||
log.setLevel(logLevel);
|
||||
|
||||
// Verifing Environment Variables
|
||||
const MONGODB_URI = process.env.APPSMITH_MONGODB_URI;
|
||||
if (
|
||||
MONGODB_URI == null ||
|
||||
MONGODB_URI === "" ||
|
||||
!MONGODB_URI.startsWith("mongodb")
|
||||
) {
|
||||
log.error("Please provide a valid value for `APPSMITH_MONGODB_URI`.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const API_BASE_URL = process.env.APPSMITH_API_BASE_URL;
|
||||
if (API_BASE_URL == null || API_BASE_URL === "") {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import { watchMongoDB } from "./mongo";
|
||||
import { watchEvents } from "./events";
|
||||
import { Server } from "socket.io";
|
||||
import log from "loglevel";
|
||||
|
||||
// Initializing Multiple Sockets
|
||||
export function initializeSockets(io: Server) {
|
||||
watchMongoDB(io).catch((error) => log.error("Error watching MongoDB", error));
|
||||
watchEvents(io);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,157 +0,0 @@
|
|||
import type mongodb from "mongodb";
|
||||
import log from "loglevel";
|
||||
import { MongoClient } from "mongodb";
|
||||
import { CommentThread, Comment } from "@utils/models";
|
||||
import { findPolicyEmails } from "@controllers/socket";
|
||||
|
||||
const MONGODB_URI = process.env.APPSMITH_MONGODB_URI;
|
||||
|
||||
export async function watchMongoDB(io) {
|
||||
const client = await MongoClient.connect(MONGODB_URI, {
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
const db = client.db();
|
||||
|
||||
const threadCollection: mongodb.Collection<CommentThread> =
|
||||
db.collection("commentThread");
|
||||
|
||||
const commentChangeStream = db.collection("comment").watch(
|
||||
[
|
||||
// Prevent server-internal fields from being sent to the client.
|
||||
{
|
||||
$unset: ["deletedAt", "_class"].map((f) => "fullDocument." + f),
|
||||
},
|
||||
],
|
||||
{ fullDocument: "updateLookup" }
|
||||
);
|
||||
|
||||
commentChangeStream.on(
|
||||
"change",
|
||||
async (event: mongodb.ChangeEventCR<Comment>) => {
|
||||
let eventName = event.operationType + ":" + event.ns.coll;
|
||||
|
||||
const comment: Comment = event.fullDocument;
|
||||
if (comment.deleted) {
|
||||
eventName = "delete" + ":" + event.ns.coll; // emit delete event if deleted=true
|
||||
}
|
||||
|
||||
comment.creationTime = comment.createdAt;
|
||||
comment.updationTime = comment.updatedAt;
|
||||
|
||||
delete comment.createdAt;
|
||||
delete comment.updatedAt;
|
||||
delete comment.deleted;
|
||||
|
||||
let target = io;
|
||||
let shouldEmit = false;
|
||||
|
||||
for (const email of findPolicyEmails(comment.policies, "read:comments")) {
|
||||
shouldEmit = true;
|
||||
target = target.to("email:" + email);
|
||||
}
|
||||
|
||||
if (shouldEmit) {
|
||||
target.emit(eventName, { comment });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const threadChangeStream = threadCollection.watch(
|
||||
[
|
||||
// Prevent server-internal fields from being sent to the client.
|
||||
{
|
||||
$unset: ["deletedAt", "_class"].map((f) => "fullDocument." + f),
|
||||
},
|
||||
],
|
||||
{ fullDocument: "updateLookup" }
|
||||
);
|
||||
|
||||
threadChangeStream.on("change", async (event: mongodb.ChangeEventCR) => {
|
||||
let eventName = event.operationType + ":" + event.ns.coll;
|
||||
|
||||
const thread = event.fullDocument;
|
||||
if (thread.deleted) {
|
||||
eventName = "delete" + ":" + event.ns.coll; // emit delete event if deleted=true
|
||||
}
|
||||
|
||||
if (thread === null) {
|
||||
// This happens when `event.operationType === "drop"`, when a comment is deleted.
|
||||
log.error("Null document recieved for comment change event", event);
|
||||
return;
|
||||
}
|
||||
|
||||
thread.creationTime = thread.createdAt;
|
||||
thread.updationTime = thread.updatedAt;
|
||||
|
||||
delete thread.createdAt;
|
||||
delete thread.updatedAt;
|
||||
delete thread.deleted;
|
||||
|
||||
thread.isViewed = false;
|
||||
|
||||
let target = io;
|
||||
let shouldEmit = false;
|
||||
|
||||
for (const email of findPolicyEmails(
|
||||
thread.policies,
|
||||
"read:commentThreads"
|
||||
)) {
|
||||
shouldEmit = true;
|
||||
target = target.to("email:" + email);
|
||||
}
|
||||
|
||||
if (shouldEmit) {
|
||||
target.emit(eventName, { thread });
|
||||
}
|
||||
});
|
||||
|
||||
const notificationsStream = db.collection("notification").watch(
|
||||
[
|
||||
// Prevent server-internal fields from being sent to the client.
|
||||
{
|
||||
$unset: ["deletedAt", "deleted"].map((f) => "fullDocument." + f),
|
||||
},
|
||||
],
|
||||
{ fullDocument: "updateLookup" }
|
||||
);
|
||||
|
||||
notificationsStream.on("change", async (event: mongodb.ChangeEventCR) => {
|
||||
const notification = event.fullDocument;
|
||||
|
||||
if (notification === null) {
|
||||
// This happens when `event.operationType === "drop"`, when a notification is deleted.
|
||||
log.error("Null document recieved for notification change event", event);
|
||||
return;
|
||||
}
|
||||
|
||||
// set the type from _class attribute
|
||||
notification.type = notification._class.slice(
|
||||
notification._class.lastIndexOf(".") + 1
|
||||
);
|
||||
delete notification._class;
|
||||
|
||||
const eventName = event.operationType + ":" + event.ns.coll;
|
||||
io.to("email:" + notification.forUsername).emit(eventName, {
|
||||
notification,
|
||||
});
|
||||
});
|
||||
|
||||
process.on("uncaughtExceptionMonitor", (err, origin) => {
|
||||
log.error(`Caught exception: ${err}\n` + `Exception origin: ${origin}`);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
log.debug("Unhandled Rejection at:", promise, "reason:", reason);
|
||||
});
|
||||
|
||||
process.on("exit", () => {
|
||||
(commentChangeStream != null
|
||||
? commentChangeStream.close()
|
||||
: Promise.bind(client).resolve()
|
||||
)
|
||||
.then(client.close.bind(client))
|
||||
.finally("Fin");
|
||||
});
|
||||
|
||||
log.debug("Watching MongoDB");
|
||||
}
|
||||
|
|
@ -30,17 +30,3 @@ export interface Policy {
|
|||
users: string[];
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
export interface CommentThread {
|
||||
applicationId: string;
|
||||
}
|
||||
|
||||
export interface Comment {
|
||||
threadId: string;
|
||||
policies: Policy[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
creationTime: string;
|
||||
updationTime: string;
|
||||
deleted: boolean;
|
||||
}
|
||||
|
|
|
|||
4549
app/rts/yarn.lock
4549
app/rts/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user