-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-generate record types #152
Comments
I was able to make a PoC using sql-ts it is definitely doable, but I think it would require some work/effort, I would argue that as it could be an awesome thing to have in pocketbase (being typesafe would be another plus), but at the cost of having more API surface to take care and probably having the need to have in dev-mode more dependencies (sql-ts require to use a driver as well) so it would be sql-ts + sqlite-3 in the dev-bundle. But the end result is good for a PoC Would love some input/feedback. |
@Grubba27, @septatrix There is a non-official/community maintained library that do this to some extend - https://github.com/patmood/pocketbase-typegen. Something like the above eventually will be integrated in the SDK, but for now remains a low priority. |
I faced this issue aswell and created typed-pocketbase to apply the types generated by https://github.com/patmood/pocketbase-typegen to the js sdk |
This is awesome @david-plugge, thanks! |
Hi I'm interested to know how this more TypeScript support is going to be implemented (whenever it's added). Is it going to be something like Typed PocketBase, or Drizzle? Can we have something like Drizzle? "Typed PocketBase" was great, however I had to deal with things like this: import type { ListResult } from "pocketbase"
import type { EventsResponse, UsersResponse, TiersResponse } from "$utilities/pb-typegen"
export type CustomEventsResponse = EventsResponse & {
expand: {
user: UsersResponse & {
expand: {
retainedTiers: TiersResponse[]
}
}
inviter: UsersResponse & {
expand: {
retainedTiers: TiersResponse[]
}
}
}
}
export type ListResultEventsResponse = ListResult<CustomEventsResponse>
const events: ListResultEventsResponse = await locals.pb
.collection("events")
.getList(1, 50, {
sort: "-created",
expand: "user,user.retainedTiers,inviter,inviter.retainedTiers",
}) I would have liked to not write any of the code before I tried to use new things like Drizzle and Turso, but they were difficult to work with. I spent a day to get them working but, I was facing issues, one after another. I would love to use PocketBase, but when I think about adding types (same as the above code) and struggling to find free hosting, it starts to hurt. I hate writing this comment, I don't want to bring negativity to such an awesome project with just an awesome author, and it bugs me that I can't support this project in any way (I have no skills and no money). I hope this doesn't bring in any negative feelings ❤️. I have a question, is it possible to use Drizzle? I don't even know what I mean, I don't even fully understand Drizzle, but I like type safety and doing less work :) Anyways, thanks. |
A new version of typed-pocketbase is going to be released soon with support for nested selects. And you will never worry about the expand field again! |
Can be type like this for all collections and methods I manage to achieve this using patmood's typegen and some type tweaks. But i can't achieve the auto completion for the fields at the time of writing it. But when I provide the fields string it provide type according to the value. file contains my type tweaks: |
Currently many areas are still untyped and the user has to provide custom record types in many cases. Manually maintaining these types and keeping them in sync is cumbersome and error prone.
It would be fantastic if pocketbase could export/generate a type file which one can use to get more complete type coverage similar to many OpenAPI generators. For this SDK it might even be possible to just provide a .d.ts file exporting a single interface which can be set as the generic type during client creation.
The text was updated successfully, but these errors were encountered: