65 lines
1.3 KiB
TypeScript
65 lines
1.3 KiB
TypeScript
import type { RecordModel } from "pocketbase";
|
|
|
|
export type Id<T extends string> = string & { __type: T };
|
|
|
|
export type UserId = Id<"User">;
|
|
export type CampaignId = Id<"Campaign">;
|
|
export type DocumentId = Id<"Document">;
|
|
|
|
export type Campaign = RecordModel & {
|
|
id: CampaignId;
|
|
name: string;
|
|
owner: UserId;
|
|
};
|
|
|
|
export type Document = RecordModel & {
|
|
id: DocumentId;
|
|
campaign: Campaign;
|
|
data: {};
|
|
// These two are not in Pocketbase's types, but they seem to always be present
|
|
created: string;
|
|
updated: string;
|
|
};
|
|
|
|
export type DocumentData<K extends string, V> = {
|
|
data: Record<K, V>;
|
|
};
|
|
|
|
export type Session = Document &
|
|
DocumentData<
|
|
"session",
|
|
{
|
|
strongStart: string;
|
|
}
|
|
>;
|
|
|
|
export function isSession(doc: Document): doc is Session {
|
|
return Object.hasOwn(doc.data, "session");
|
|
}
|
|
|
|
export type ISO8601Date = string & { __type: "iso8601date" };
|
|
|
|
export type Secret = Document &
|
|
DocumentData<
|
|
"secret",
|
|
{
|
|
text: string;
|
|
discovered: boolean;
|
|
}
|
|
>;
|
|
|
|
export function isSecret(doc: Document): doc is Secret {
|
|
return Object.hasOwn(doc.data, "secret");
|
|
}
|
|
|
|
export const RelationshipType = {
|
|
Secrets: "secrets",
|
|
DiscoveredIn: "discoveredIn",
|
|
} as const;
|
|
|
|
export type Relationship = RecordModel & {
|
|
primary: DocumentId;
|
|
secondary: DocumentId[];
|
|
type: (typeof RelationshipType)[keyof typeof RelationshipType];
|
|
};
|