import PocketBase from "pocketbase"; import type { RecordService } from "pocketbase"; export enum Collections { Microblogs = "microblogs", Tags = "tags", Users = "users", } export type IsoDateString = string; export type RecordIdString = string; export type HTMLString = string; export type BaseSystemFields = { id: RecordIdString; created: IsoDateString; updated: IsoDateString; collectionId: string; collectionName: Collections; expand?: T; }; export type AuthSystemFields = { email: string; emailVisibility: boolean; username: string; verified: boolean; } & BaseSystemFields; export type MicroblogsRecord = { content?: string; published: IsoDateString; tags?: RecordIdString[]; }; export type TagsRecord = { name?: string; }; export type UsersRecord = { avatar?: string; name?: string; }; export type MicroblogsResponse = Required & BaseSystemFields; export type TagsResponse = Required & BaseSystemFields; export type UsersResponse = Required & AuthSystemFields; export type CollectionRecords = { microblogs: MicroblogsRecord; tags: TagsRecord; users: UsersRecord; }; export type CollectionResponses = { microblogs: MicroblogsResponse; tags: TagsResponse; users: UsersResponse; }; export type TypedPocketBase = PocketBase & { collection(idOrName: "microblogs"): RecordService; collection(idOrName: "tags"): RecordService; collection(idOrName: "users"): RecordService; }; export function createServerClient(url: string) { if (!url) { throw new Error("Pocketbase API url not defined !"); } if (typeof window !== "undefined") { throw new Error( "This method is only supposed to call from the Server environment", ); } const client = new PocketBase(url) as TypedPocketBase; return client; }