Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 159 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion app/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"system-manager:grant": "node dist/admin/grant-system-manager.command.js"
},
"dependencies": {
"@hocuspocus/server": "4.7.0",
"@nestjs/common": "12.1.0",
"@nestjs/config": "12.0.1",
"@nestjs/core": "12.1.0",
Expand All @@ -34,14 +35,19 @@
"prisma": "7.10.0",
"redis": "6.2.1",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.2"
"rxjs": "7.8.2",
"ws": "8.22.0",
"y-protocols": "1.0.7",
"yjs": "13.6.33"
},
"devDependencies": {
"@hocuspocus/provider": "4.7.0",
"@nestjs/cli": "12.0.5",
"@nestjs/testing": "12.1.0",
"@types/cookie-parser": "1.4.10",
"@types/node": "26.6.2",
"@types/passport-jwt": "4.0.1",
"@types/ws": "8.18.2",
"typescript": "6.0.2",
"vitest": "5.0.1"
}
Expand Down
25 changes: 25 additions & 0 deletions app/server/prisma/migrations/20261005020000_notes/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE "notes" (
"item_id" UUID NOT NULL,
"parent_id" UUID,
"position" DOUBLE PRECISION NOT NULL DEFAULT 0,
"icon" TEXT,
"pinned_at" TIMESTAMP(3),
CONSTRAINT "notes_pkey" PRIMARY KEY ("item_id")
);

CREATE TABLE "note_documents" (
"item_id" UUID NOT NULL,
"state" BYTEA NOT NULL,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "note_documents_pkey" PRIMARY KEY ("item_id")
);

CREATE INDEX "notes_parent_id_idx" ON "notes"("parent_id");

ALTER TABLE "notes" ADD CONSTRAINT "notes_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "notes" ADD CONSTRAINT "notes_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "items"("id") ON DELETE SET NULL ON UPDATE CASCADE;

ALTER TABLE "note_documents" ADD CONSTRAINT "note_documents_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE;

INSERT INTO "notes" ("item_id") SELECT "id" FROM "items" WHERE "kind" = 'note';
25 changes: 25 additions & 0 deletions app/server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ model Item {
prices SubscriptionPrice[]
event Event?
guests EventGuest[]
note Note? @relation("NoteItem")
childNotes Note[] @relation("NoteParent")
noteDocument NoteDocument?
tidyChanges TidyChange[]

@@index([spaceId, updatedAt])
Expand Down Expand Up @@ -644,3 +647,25 @@ model ExchangeRate {

@@map("exchange_rates")
}

model Note {
itemId String @id @map("item_id") @db.Uuid
parentId String? @map("parent_id") @db.Uuid
position Float @default(0)
icon String?
pinnedAt DateTime? @map("pinned_at")
item Item @relation("NoteItem", fields: [itemId], references: [id], onDelete: Cascade)
parent Item? @relation("NoteParent", fields: [parentId], references: [id], onDelete: SetNull)

@@index([parentId])
@@map("notes")
}

model NoteDocument {
itemId String @id @map("item_id") @db.Uuid
state Bytes
updatedAt DateTime @updatedAt @map("updated_at")
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)

@@map("note_documents")
}
4 changes: 4 additions & 0 deletions app/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { InboxModule } from './inbox/inbox.module';
import { ItemsModule } from './items/items.module';
import { JobsModule } from './jobs/jobs.module';
import { MailModule } from './mail/mail.module';
import { NotesModule } from './notes/notes.module';
import { PrismaModule } from './prisma/prisma.module';
import { RealtimeModule } from './realtime/realtime.module';
import { RedisModule } from './redis/redis.module';
import { SearchModule } from './search/search.module';
import { ShareLinksModule } from './share-links/share-links.module';
Expand Down Expand Up @@ -59,6 +61,8 @@ import { WidgetsModule } from './widgets/widgets.module';
EventsModule,
ExchangeRatesModule,
TidyModule,
NotesModule,
RealtimeModule,
WidgetsModule,
HealthModule,
],
Expand Down
2 changes: 1 addition & 1 deletion app/server/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import { TwoStepService } from './two-step.service';
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy, JwtAuthGuard, PasswordService, SessionsService, TwoStepService],
exports: [PassportModule, JwtAuthGuard, AuthService, SessionsService, TwoStepService],
exports: [PassportModule, JwtModule, JwtStrategy, JwtAuthGuard, AuthService, SessionsService, TwoStepService],
})
export class AuthModule {}
21 changes: 21 additions & 0 deletions app/server/src/notes/document-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as Y from 'yjs';

const blockSeparator = '\n';

function textOf(node: Y.XmlElement | Y.XmlText | Y.XmlFragment): string {
if (node instanceof Y.XmlText) {
return node
.toDelta()
.map((part: { insert: unknown }) => (typeof part.insert === 'string' ? part.insert : ''))
.join('');
}
return node
.toArray()
.map((child) => (child instanceof Y.XmlHook ? '' : textOf(child)))
.filter(Boolean)
.join(blockSeparator);
}

export function documentText(document: Y.Doc, maxLength = 100_000) {
return textOf(document.getXmlFragment('default')).replace(/\n{3,}/g, '\n\n').trim().slice(0, maxLength);
}
Loading
Loading