-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): implement custom api types (#257)
* feat: implement custom api types * fix(types): plural
- Loading branch information
1 parent
04d7068
commit 5a313a0
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ListResult } from "pocketbase"; | ||
import type { BaseSystemFields } from "@/types/pb"; | ||
|
||
export type BaseAPIFields = Omit< | ||
BaseSystemFields, | ||
"collectionId" | "collectionName" | "expand" | ||
>; | ||
|
||
export type BaseAPIListResult<T> = { | ||
success: boolean; | ||
} & ListResult<T & BaseAPIFields>; | ||
|
||
export type BaseAPISingleResult<T> = { | ||
success: boolean; | ||
item: T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import type { | ||
BaseAPIFields, | ||
BaseAPISingleResult, | ||
BaseAPIListResult, | ||
} from "@/types/api"; | ||
import type { | ||
CollectionsRecord, | ||
CollectionsResponse as PBCollectionsResponse, | ||
CollectionBooksResponse as PBCollectionBooksResponse, | ||
CollectionMembersResponse as PBCollectionMembersResponse, | ||
UsersRecord, | ||
CollectionMembersRoleOptions, | ||
BooksRecord, | ||
CollectionBooksStatusOptions, | ||
} from "@/types/pb"; | ||
|
||
/** | ||
* Collection items returned from `/api/user-collections/:userId` | ||
* | ||
* Slightly modified (and similar to) PocketBase {@link PBCollectionsResponse|CollectionsResponse} schema | ||
* | ||
* `collectionId` here is explicitly "Tana.moe user's books collection", not "PocketBase collections" | ||
* | ||
* @see {@link UserCollectionsResponse} | ||
*/ | ||
export type CollectionResponse = { | ||
collectionId: string; | ||
userId: string; | ||
collection?: CollectionsRecord & BaseAPIFields; | ||
user?: UsersRecord & BaseAPIFields; | ||
role: CollectionMembersRoleOptions; | ||
}; | ||
|
||
/** | ||
* User collections returned from `/api/user-collections/:userId` | ||
* | ||
* @see {@link https://github.com/tanamoe/momoka-lite/blob/master/models/collection_member.go} | ||
*/ | ||
export type UserCollectionsResponse = BaseAPIListResult<CollectionResponse>; | ||
|
||
/** | ||
* User collection returned from `/api/user-collection/:collectionId` | ||
* | ||
* @see {@link https://github.com/tanamoe/momoka-lite/blob/master/models/collection.go} | ||
*/ | ||
export type UserCollectionResponse = BaseAPISingleResult< | ||
CollectionsRecord & BaseAPIFields | ||
>; | ||
|
||
/** | ||
* Book items returned from `/api/user-collection/:userId/books` | ||
* | ||
* Slightly modified (and similar to) PocketBase {@link PBCollectionBooksResponse|CollectionBooksResponse} schema | ||
* | ||
* `collectionId` here is explicitly "Tana.moe user's books collection", not "PocketBase collections" | ||
* | ||
* @see {@link UserCollectionBooksResponse} | ||
*/ | ||
export type CollectionBookResponse = { | ||
collectionId: string; | ||
bookId: string; | ||
collection?: CollectionsRecord & BaseAPIFields; | ||
book?: BooksRecord & BaseAPIFields; | ||
quantity: number; | ||
status: CollectionBooksStatusOptions; | ||
}; | ||
|
||
/** | ||
* User collection books returned from `/api/user-collection/:userId/books` | ||
* | ||
* @see {@link https://github.com/tanamoe/momoka-lite/blob/master/models/collection_book.go} | ||
*/ | ||
export type UserCollectionBooksResponse = | ||
BaseAPIListResult<CollectionBookResponse>; | ||
|
||
/** | ||
* Members items returned from `/api/user-collection/:userId/members` | ||
* | ||
* Slightly modified (and similar to) PocketBase {@link PBCollectionMembersResponse|CollectionMembersResponse} schema | ||
* | ||
* `collectionId` here is explicitly "Tana.moe user's books collection", not "PocketBase collections" | ||
* | ||
* @see {@link UserCollectionMembersResponse} | ||
*/ | ||
export type CollectionMemberResponse = { | ||
collectionId: string; | ||
userId: string; | ||
collection?: CollectionsRecord & BaseAPIFields; | ||
user?: UsersRecord & BaseAPIFields; | ||
role: CollectionMembersRoleOptions; | ||
}; | ||
|
||
/** | ||
* User collection members returned from `/api/user-collection/:userId/members` | ||
* | ||
* @see {@link https://github.com/tanamoe/momoka-lite/blob/master/models/collection_member.go} | ||
*/ | ||
export type UserCollectionMembersResponse = | ||
BaseAPIListResult<CollectionMemberResponse>; |