Skip to content

Commit

Permalink
here we go
Browse files Browse the repository at this point in the history
  • Loading branch information
david-plugge committed Dec 17, 2023
1 parent bbd99cf commit 8a08bef
Show file tree
Hide file tree
Showing 12 changed files with 845 additions and 356 deletions.
158 changes: 122 additions & 36 deletions example/Database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,194 @@
*/

// https://pocketbase.io/docs/collections/#base-collection
type BaseCollectionRecord = {
interface BaseCollectionRecord {
id: string;
created: string;
updated: string;
};
collectionId: string;
collectionName: string;
}

// https://pocketbase.io/docs/collections/#auth-collection
type AuthCollectionRecord = {
id: string;
created: string;
updated: string;
interface AuthCollectionRecord extends BaseCollectionRecord {
username: string;
email: string;
emailVisibility: boolean;
verified: boolean;
};
}

// https://pocketbase.io/docs/collections/#view-collection
type ViewCollectionRecord = {
interface ViewCollectionRecord {
id: string;
};
}

// utilities

type MaybeArray<T> = T | T[];

// ===== users =====

export type UsersResponse = {
export interface UsersResponse extends AuthCollectionRecord {
collectionName: 'users';
name?: string;
avatar?: string;
} & AuthCollectionRecord;
}

export type UsersCreate = {
export interface UsersCreate {
name?: string;
avatar?: string;
};
}

export type UsersUpdate = {
export interface UsersUpdate {
name?: string;
avatar?: string;
};
}

export type UsersCollection = {
export interface UsersCollection {
type: 'auth';
collectionId: '_pb_users_auth_';
collectionId: string;
collectionName: 'users';
response: UsersResponse;
create: UsersCreate;
update: UsersUpdate;
relations: {
'posts(owner)': PostsCollection[];
};
};
}

// ===== posts =====

export type PostsResponse = {
export interface PostsResponse extends BaseCollectionRecord {
collectionName: 'posts';
title: string;
slug: string;
date?: string;
content?: string;
published?: boolean;
owner?: string;
metadata?: any;
} & BaseCollectionRecord;
slug: string;
date?: string;
}

export type PostsCreate = {
export interface PostsCreate {
title: string;
slug: string;
date?: string | Date;
content?: string;
published?: boolean;
owner?: string;
metadata?: any;
};
slug: string;
date?: string | Date;
}

export type PostsUpdate = {
export interface PostsUpdate {
title?: string;
slug?: string;
date?: string | Date;
content?: string;
published?: boolean;
owner?: string;
metadata?: any;
};
slug?: string;
date?: string | Date;
}

export type PostsCollection = {
export interface PostsCollection {
type: 'base';
collectionId: 'sbrth2mzfnqba9e';
collectionId: string;
collectionName: 'posts';
response: PostsResponse;
create: PostsCreate;
update: PostsUpdate;
relations: {
owner: UsersCollection;
};
};
}

// ===== test =====

export interface TestResponse extends BaseCollectionRecord {
collectionName: 'test';
test?: string;
editor?: string;
number?: number;
bool?: boolean;
email?: string;
url?: string;
date?: string;
select?: 'a' | 'b' | 'c' | 'd';
file?: string;
relation?: string;
json?: any;
}

export interface TestCreate {
test?: string;
editor?: string;
number?: number;
bool?: boolean;
email?: string;
url?: string | URL;
date?: string | Date;
select?: 'a' | 'b' | 'c' | 'd';
file?: string;
relation?: string;
json?: any;
}

export interface TestUpdate {
test?: string;
editor?: string;
number?: number;
'number+'?: number;
'number-'?: number;
bool?: boolean;
email?: string;
url?: string | URL;
date?: string | Date;
select?: 'a' | 'b' | 'c' | 'd';
file?: string;
relation?: string;
json?: any;
}

export interface TestCollection {
type: 'base';
collectionId: string;
collectionName: 'test';
response: TestResponse;
create: TestCreate;
update: TestUpdate;
relations: {
relation: Test2Collection;
};
}

// ===== test2 =====

export interface Test2Response extends BaseCollectionRecord {
collectionName: 'test2';
test?: string;
}

export interface Test2Create {
test?: string;
}

export interface Test2Update {
test?: string;
}

export interface Test2Collection {
type: 'base';
collectionId: string;
collectionName: 'test2';
response: Test2Response;
create: Test2Create;
update: Test2Update;
relations: {
'test(relation)': TestCollection;
};
}

// ===== Schema =====

export type Schema = {
users: UsersCollection;
posts: PostsCollection;
test: TestCollection;
test2: Test2Collection;
};
Loading

0 comments on commit 8a08bef

Please sign in to comment.