-
Notifications
You must be signed in to change notification settings - Fork 0
/
pocketbase-types.ts
118 lines (101 loc) · 2.99 KB
/
pocketbase-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* This file was @generated using pocketbase-typegen
*/
import type PocketBase from "pocketbase";
import type { RecordService } from "pocketbase";
export enum Collections {
Albums = "albums",
Artists = "artists",
Playlists = "playlists",
Songs = "songs",
Users = "users",
}
// Alias types for improved usability
export type IsoDateString = string;
export type RecordIdString = string;
export type HTMLString = string;
// System fields
export type BaseSystemFields<T = never> = {
id: RecordIdString;
created: IsoDateString;
updated: IsoDateString;
collectionId: string;
collectionName: Collections;
expand?: T;
};
export type AuthSystemFields<T = never> = {
email: string;
emailVisibility: boolean;
username: string;
verified: boolean;
} & BaseSystemFields<T>;
// Record types for each collection
export type AlbumsRecord = {
image?: string;
name?: string;
released?: IsoDateString;
};
export type ArtistsRecord = {
image: string;
name: string;
};
export type PlaylistsRecord = {
createdBy?: RecordIdString;
image?: string;
name?: string;
songs?: RecordIdString[];
};
export enum SongsTypeOptions {
"orginal" = "orginal",
"cover" = "cover",
"remaster" = "remaster",
}
export type SongsRecord = {
album?: RecordIdString[];
artists: RecordIdString[];
file?: string;
image?: string;
name: string;
orginal_song?: RecordIdString;
released?: IsoDateString;
type?: SongsTypeOptions;
};
export type UsersRecord = {
avatar?: string;
name?: string;
};
// Response types include system fields and match responses from the PocketBase API
export type AlbumsResponse<Texpand = unknown> = Required<AlbumsRecord> &
BaseSystemFields<Texpand>;
export type ArtistsResponse<Texpand = unknown> = Required<ArtistsRecord> &
BaseSystemFields<Texpand>;
export type PlaylistsResponse<Texpand = unknown> = Required<PlaylistsRecord> &
BaseSystemFields<Texpand>;
export type SongsResponse<Texpand = unknown> = Required<SongsRecord> &
BaseSystemFields<Texpand>;
export type UsersResponse<Texpand = unknown> = Required<UsersRecord> &
AuthSystemFields<Texpand>;
// Types containing all Records and Responses, useful for creating typing helper functions
export type CollectionRecords = {
albums: AlbumsRecord;
artists: ArtistsRecord;
playlists: PlaylistsRecord;
songs: SongsRecord;
users: UsersRecord;
};
export type CollectionResponses = {
albums: AlbumsResponse;
artists: ArtistsResponse;
playlists: PlaylistsResponse;
songs: SongsResponse;
users: UsersResponse;
};
// Type for usage with type asserted PocketBase instance
// https://github.com/pocketbase/js-sdk#specify-typescript-definitions
export type TypedPocketBase = PocketBase & {
collection(idOrName: "albums"): RecordService<AlbumsResponse>;
collection(idOrName: "artists"): RecordService<ArtistsResponse>;
collection(idOrName: "playlists"): RecordService<PlaylistsResponse>;
collection(idOrName: "songs"): RecordService<SongsResponse>;
collection(idOrName: "users"): RecordService<UsersResponse>;
};