SurfSense/surfsense_web/zero/schema.ts
CREDO23 af2bd744fb feat: add Zero schema with 6 table definitions and relationships
- Create zero/tables/inbox.ts (notifications)
- Create zero/tables/documents.ts (documents, search_source_connectors)
- Create zero/tables/chat.ts (new_chat_messages, chat_comments, chat_session_state)
- Create zero/schema.ts (combines tables, defines relationships, exports zql)
- Consolidate Zero type augmentations into types/zero.d.ts
2026-03-23 17:44:05 +02:00

41 lines
1.1 KiB
TypeScript

import { createSchema, createBuilder, relationships } from "@rocicorp/zero";
import { chatCommentTable, chatSessionStateTable, newChatMessageTable } from "./tables/chat";
import { documentTable, searchSourceConnectorTable } from "./tables/documents";
import { notificationTable } from "./tables/inbox";
const chatCommentRelationships = relationships(chatCommentTable, ({ one }) => ({
message: one({
sourceField: ["messageId"],
destSchema: newChatMessageTable,
destField: ["id"],
}),
parent: one({
sourceField: ["parentId"],
destSchema: chatCommentTable,
destField: ["id"],
}),
}));
const newChatMessageRelationships = relationships(newChatMessageTable, ({ many }) => ({
comments: many({
sourceField: ["id"],
destSchema: chatCommentTable,
destField: ["messageId"],
}),
}));
export const schema = createSchema({
tables: [
notificationTable,
documentTable,
searchSourceConnectorTable,
newChatMessageTable,
chatCommentTable,
chatSessionStateTable,
],
relationships: [chatCommentRelationships, newChatMessageRelationships],
});
export type Schema = typeof schema;
export const zql = createBuilder(schema);