Skip to content

Commit 76a284d

Browse files
pyphiliakim
andauthored
feat: save page updates (#1965)
* feat: save page updates * test: write test for page and yjs * docs: update page readme --------- Co-authored-by: kim <kim.phanhoang@epfl.ch>
1 parent d773276 commit 76a284d

21 files changed

Lines changed: 4414 additions & 356 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"url-http": "1.3.0",
121121
"uuid": "11.1.0",
122122
"ws": "8.18.1",
123-
"y-leveldb": "0.2.0",
124123
"y-protocols": "1.0.6",
125124
"yazl": "3.3.1",
126125
"yjs": "13.6.27"
@@ -175,7 +174,8 @@
175174
"ts-node": "10.9.2",
176175
"typescript": "5.8.3",
177176
"vitest": "3.2.3",
178-
"wait-for-expect": "3.0.2"
177+
"wait-for-expect": "3.0.2",
178+
"y-websocket": "3.0.0"
179179
},
180180
"resolutions": {
181181
"sodium-native": "4.2.0"

src/app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// should not be reimported in any other files !
33
import 'reflect-metadata';
44

5+
import fws from '@fastify/websocket';
56
import type { FastifyInstance } from 'fastify';
67
import fp from 'fastify-plugin';
78

@@ -20,6 +21,15 @@ import tagPlugin from './services/tag/tag.controller';
2021
import websocketsPlugin from './services/websockets/websocket.controller';
2122

2223
export default async function (instance: FastifyInstance): Promise<void> {
24+
const { log } = instance;
25+
26+
await instance.register(fws, {
27+
errorHandler: (error, conn, _req, _reply) => {
28+
log.error(`graasp-websockets: an error occured: ${error}\n\tDestroying connection`);
29+
conn.terminate();
30+
},
31+
});
32+
2333
await instance
2434
.register(fp(swaggerPlugin))
2535
.register(fp(schemaRegisterPlugin))

src/drizzle/0010_page-update.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP TABLE "page" CASCADE;--> statement-breakpoint
2+
CREATE TABLE "page_update" (
3+
"item_id" uuid NOT NULL,
4+
"update" "bytea" NOT NULL,
5+
"clock" integer NOT NULL
6+
);--> statement-breakpoint
7+
ALTER TABLE "page_update" ADD CONSTRAINT "FK_page_update_item_id" FOREIGN KEY ("item_id") REFERENCES "public"."item"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
8+
CREATE INDEX "IDX_page_item_id" ON "page_update" USING btree ("item_id" uuid_ops);

src/drizzle/customTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ export const customNumeric = customType<{ data: number; driverData: string }>({
1818
return +value;
1919
},
2020
});
21+
22+
export const binaryHash = customType<{ data: Uint8Array; driverData: Buffer }>({
23+
dataType() {
24+
return 'bytea';
25+
},
26+
});

0 commit comments

Comments
 (0)