You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import type { CommittedMessage } from "../types";
|
|
import type { Users } from "./generated/public/Users";
|
|
|
|
export type Conversation = {
|
|
id: string;
|
|
title: string;
|
|
userId: string;
|
|
createdAt?: string;
|
|
};
|
|
|
|
export type Fact = {
|
|
id: string;
|
|
userId: string;
|
|
sourceMessageId: string;
|
|
content: string;
|
|
createdAt?: string;
|
|
};
|
|
|
|
export type FactTrigger = {
|
|
id: string;
|
|
sourceFactId: string;
|
|
content: string;
|
|
priorityMultiplier: number;
|
|
priorityMultiplierReason: string | null;
|
|
scopeConversationId: string;
|
|
createdAt?: string;
|
|
};
|
|
|
|
export type User = Omit<Users, "id"> & {
|
|
id: string;
|
|
};
|
|
|
|
export interface Entity<T> {
|
|
construct: (data: T) => T;
|
|
create: (data: Omit<T, "id">) => Promise<T>;
|
|
createMany: (data: Omit<T, "id">[]) => Promise<T[]>;
|
|
findAll: () => Promise<T[]>;
|
|
findById: (id: string) => Promise<T | undefined>;
|
|
update: (id: string, data: Partial<T>) => Promise<void>;
|
|
delete: (id: string) => Promise<void>;
|
|
}
|
|
|
|
export interface ConversationEntity extends Entity<Conversation> {
|
|
fetchMessages: (conversationId: string) => Promise<Array<CommittedMessage>>;
|
|
}
|
|
|
|
export interface FactEntity extends Entity<Fact> {
|
|
findByConversationId: (conversationId: string) => Promise<Array<Fact>>;
|
|
}
|
|
|
|
export interface MessageEntity extends Entity<CommittedMessage> {
|
|
findByConversationId: (
|
|
conversationId: string
|
|
) => Promise<Array<CommittedMessage>>;
|
|
}
|
|
|
|
export type FactTriggerEntity = Entity<FactTrigger> & {
|
|
findByFactId: (factId: string) => Promise<Array<FactTrigger>>;
|
|
findByConversationId: (conversationId: string) => Promise<Array<FactTrigger>>;
|
|
};
|
|
|
|
export type UserEntity = Entity<User> & {
|
|
findByEmailAddress: (emailAddress: string) => Promise<User | undefined>;
|
|
};
|
|
|
|
export interface ApplicationDatabase {
|
|
conversations: ConversationEntity;
|
|
factTriggers: FactTriggerEntity;
|
|
facts: FactEntity;
|
|
messages: MessageEntity;
|
|
users: UserEntity;
|
|
}
|