[WEB-1116] chore: live server code splitting (#5508)
* chore: live server code splitting * chore: update import paths * chore: update bebel path alias * fix: document types type * chore: updated error messages
This commit is contained in:
parent
1ef535af7b
commit
5840b40d96
16 changed files with 189 additions and 23 deletions
23
live/.babelrc
Normal file
23
live/.babelrc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"modules": false
|
||||
}
|
||||
],
|
||||
"@babel/preset-typescript"
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
"module-resolver",
|
||||
{
|
||||
"root": ["./src"],
|
||||
"alias": {
|
||||
"@/core": "./src/core",
|
||||
"@/plane-live": "./src/ce"
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "babel src --out-dir dist --extensions \".ts,.js\"",
|
||||
"start": "node dist/server.js",
|
||||
"dev": "PORT=3003 nodemon --exec \"node -r esbuild-register ./src/server.ts\" -e .ts"
|
||||
},
|
||||
|
|
@ -32,10 +32,15 @@
|
|||
"yjs": "^13.6.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.25.6",
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.4",
|
||||
"@babel/preset-typescript": "^7.24.7",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/express-ws": "^3.0.4",
|
||||
"@types/node": "^20.14.9",
|
||||
"babel-plugin-module-resolver": "^5.0.2",
|
||||
"nodemon": "^3.1.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsup": "^7.2.0",
|
||||
|
|
|
|||
17
live/src/ce/lib/authentication.ts
Normal file
17
live/src/ce/lib/authentication.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { ConnectionConfiguration } from "@hocuspocus/server";
|
||||
// types
|
||||
import { TDocumentTypes } from "@/core/types/common.js";
|
||||
|
||||
type TArgs = {
|
||||
connection: ConnectionConfiguration
|
||||
cookie: string | undefined;
|
||||
params: URLSearchParams;
|
||||
}
|
||||
|
||||
export const authenticateUser = (args: TArgs): Promise<void> => {
|
||||
const { params } = args;
|
||||
const documentType = params.get("documentType")?.toString() as
|
||||
| TDocumentTypes
|
||||
| undefined;
|
||||
throw Error(`Authentication failed: Invalid document type ${documentType} provided.`);
|
||||
}
|
||||
14
live/src/ce/lib/fetch-document.ts
Normal file
14
live/src/ce/lib/fetch-document.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// types
|
||||
import { TDocumentTypes } from "@/core/types/common.js";
|
||||
|
||||
type TArgs = {
|
||||
cookie: string | undefined;
|
||||
documentType: TDocumentTypes | undefined;
|
||||
pageId: string;
|
||||
params: URLSearchParams;
|
||||
}
|
||||
|
||||
export const fetchDocument = async (args: TArgs): Promise<Uint8Array | null> => {
|
||||
const { documentType } = args;
|
||||
throw Error(`Fetch failed: Invalid document type ${documentType} provided.`);
|
||||
}
|
||||
17
live/src/ce/lib/update-document.ts
Normal file
17
live/src/ce/lib/update-document.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// types
|
||||
import { TDocumentTypes } from "@/core/types/common.js";
|
||||
|
||||
type TArgs = {
|
||||
params: URLSearchParams;
|
||||
pageId: string;
|
||||
updatedDescription: Uint8Array;
|
||||
cookie: string | undefined;
|
||||
}
|
||||
|
||||
export const updateDocument = (args: TArgs): Promise<void> => {
|
||||
const { params } = args;
|
||||
const documentType = params.get("documentType")?.toString() as
|
||||
| TDocumentTypes
|
||||
| undefined;
|
||||
throw Error(`Update failed: Invalid document type ${documentType} provided.`);
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
import { ConnectionConfiguration } from "@hocuspocus/server";
|
||||
// services
|
||||
import { UserService } from "../services/user.service.js";
|
||||
import { UserService } from "@/core/services/user.service.js";
|
||||
// types
|
||||
import { TDocumentTypes } from "../types/common.js";
|
||||
import { TDocumentTypes } from "@/core/types/common.js";
|
||||
// plane live lib
|
||||
import { authenticateUser } from "@/plane-live/lib/authentication.js";
|
||||
|
||||
const userService = new UserService();
|
||||
|
||||
|
|
@ -51,7 +53,11 @@ export const handleAuthentication = async (props: Props) => {
|
|||
connection.readOnly = true;
|
||||
}
|
||||
} else {
|
||||
throw Error("Authentication failed: Invalid document type provided.");
|
||||
await authenticateUser({
|
||||
connection,
|
||||
cookie,
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// helpers
|
||||
import { getAllDocumentFormatsFromBinaryData, getBinaryDataFromHTMLString } from "../../core/helpers/page.js";
|
||||
import { getAllDocumentFormatsFromBinaryData, getBinaryDataFromHTMLString } from "@/core/helpers/page.js";
|
||||
// services
|
||||
import { PageService } from "../services/page.service.js";
|
||||
import { PageService } from "@/core/services/page.service.js";
|
||||
const pageService = new PageService();
|
||||
|
||||
export const updatePageDescription = async (
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// types
|
||||
import { TPage } from "@plane/types";
|
||||
// services
|
||||
import { API_BASE_URL, APIService } from "./api.service.js";
|
||||
import { API_BASE_URL, APIService } from "@/core/services/api.service.js";
|
||||
|
||||
export class PageService extends APIService {
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// types
|
||||
import type { IProjectMember, IUser } from "@plane/types";
|
||||
// services
|
||||
import { API_BASE_URL, APIService } from "./api.service.js";
|
||||
import { API_BASE_URL, APIService } from "@/core/services/api.service.js";
|
||||
|
||||
export class UserService extends APIService {
|
||||
constructor() {
|
||||
|
|
|
|||
3
live/src/core/types/common.d.ts
vendored
3
live/src/core/types/common.d.ts
vendored
|
|
@ -1,3 +1,4 @@
|
|||
// types
|
||||
import { TAdditionalDocumentTypes } from "@/plane-live/types/common.js";
|
||||
|
||||
export type TDocumentTypes = "project_page" & TAdditionalDocumentTypes;
|
||||
export type TDocumentTypes = "project_page" | TAdditionalDocumentTypes;
|
||||
|
|
|
|||
1
live/src/ee/lib/authentication.ts
Normal file
1
live/src/ee/lib/authentication.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "../../ce/lib/authentication.js"
|
||||
1
live/src/ee/lib/fetch-document.ts
Normal file
1
live/src/ee/lib/fetch-document.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "../../ce/lib/fetch-document.js"
|
||||
1
live/src/ee/lib/update-document.ts
Normal file
1
live/src/ee/lib/update-document.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "../../ce/lib/update-document.js"
|
||||
|
|
@ -5,15 +5,17 @@ import { Database } from "@hocuspocus/extension-database";
|
|||
import { Logger } from "@hocuspocus/extension-logger";
|
||||
import express from "express";
|
||||
import expressWs, { Application } from "express-ws";
|
||||
// page actions
|
||||
// lib
|
||||
import { handleAuthentication } from "@/core/lib/authentication.js";
|
||||
import {
|
||||
fetchPageDescriptionBinary,
|
||||
updatePageDescription,
|
||||
} from "./core/lib/page.js";
|
||||
} from "@/core/lib/page.js";
|
||||
// types
|
||||
import { TDocumentTypes } from "./core/types/common.js";
|
||||
// helpers
|
||||
import { handleAuthentication } from "./core/lib/authentication.js";
|
||||
import { TDocumentTypes } from "@/core/types/common.js";
|
||||
// plane live lib
|
||||
import { fetchDocument } from "@/plane-live/lib/fetch-document.js";
|
||||
import { updateDocument } from "@/plane-live/lib/update-document.js";
|
||||
|
||||
const server = Server.configure({
|
||||
onAuthenticate: async ({
|
||||
|
|
@ -65,14 +67,22 @@ const server = Server.configure({
|
|||
|
||||
return new Promise(async (resolve) => {
|
||||
try {
|
||||
let fetchedData = null;
|
||||
if (documentType === "project_page") {
|
||||
const fetchedData = await fetchPageDescriptionBinary(
|
||||
fetchedData = await fetchPageDescriptionBinary(
|
||||
params,
|
||||
pageId,
|
||||
cookie,
|
||||
);
|
||||
resolve(fetchedData);
|
||||
} else {
|
||||
fetchedData = await fetchDocument({
|
||||
cookie,
|
||||
documentType,
|
||||
pageId,
|
||||
params,
|
||||
});
|
||||
}
|
||||
resolve(fetchedData);
|
||||
} catch (error) {
|
||||
console.error("Error in fetching document", error);
|
||||
}
|
||||
|
|
@ -96,6 +106,13 @@ const server = Server.configure({
|
|||
try {
|
||||
if (documentType === "project_page") {
|
||||
await updatePageDescription(params, pageId, state, cookie);
|
||||
} else {
|
||||
await updateDocument({
|
||||
params,
|
||||
pageId,
|
||||
updatedDescription: state,
|
||||
cookie,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error in updating document", error);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"rootDir": "./src",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/core/*"],
|
||||
"@/core/*": ["./src/core/*"],
|
||||
"@/plane-live/*": ["./src/ce/*"]
|
||||
},
|
||||
"removeComments": true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue