Add generation types for Create and Update requests
#110 This PR adds the generation of types for Create and Update requests. Also, using the new generated types for create/update I think #65 can be solved due to the proper typing of "file" fields.
(Collections _authOrigins,_externalAuths,_mfas and _otps were excluded from this PR as they are internal and I think it is very rare to create/update them via API)
Any hope on getting this merged in?
Hey @ivanpajon! Thanks for the contribution and sorry for the delay. There's a lot of duplication going on with the new output. Could this issue be solved with utility functions? Something like this:
type BooksRecord = {
title: string
}
type Update<T> = Partial<T> & {
oldPassword?: string
password?: string
passwordConfirm?: string
}
type Create<T> = Omit<T, 'id'>
const newBook: Create<BooksRecord> = { title: 'hello' }
const myUpdate: Update<BooksRecord> = { title: 'hello'}
@patmood I have done like this to not introduce breaking changes to the library (and because it was easier than a refactor), but definitely using utility types would be a cleaner approach
@patmood I updated the PR to implement utility types and reduce duplicated code.
Changes:
- Could be used through Collections enum or Record type
- Utility types now can be used with any collection (including
_authOrigins,_externalAuths,_mfas and _otps) - Handle file fields in Record definitions (string | File)
- Any Autodate fields omitted from Create and Update
- Improved TypedPocketBase definition to be more generic and type-safe
- Tests updated
Usage example:
export type PostsRecord = {
id: string
active: boolean
creator: string
created?: IsoAutoDateString
updated?: IsoAutoDateString
}
const post: CreateBase<PostsRecord> = {
id: 'UNIQUE_ID',
active: true,
creator: 'user',
}
// OR
const post: Create<Collections.Posts> = {
id: 'UNIQUE_ID',
active: true,
creator: 'user',
}
// Same for update with UpdateBase<> and Update<> types
// For Auth collections also can be used CreateAuth<> and UpdateAuth<> types
@patmood I fixed the tests
@patmood I didn't update the readme yet, when I have a moment to write some good examples I will make a commit with them
@patmood I updated the README
Thanks there are some merge conflicts, so the branch needs to be updated. Resolve the source file conflicts first, then just run npm run build to update the dist file.
Could you also replace AUTODATE_STRING_TYPE_NAME with DATE_STRING_TYPE_NAME (the unresolved comment).
I just updated the branch.
Regarding the AUTODATE_STRING_TYPE_NAME, I left a comment in the conversation explaining why I can't remove it:
I needed to do this "trick" in order to be able to exclude any autodate field (without knowing its name in the collection) from the create/update types, as in latest pocketbase versions you can create multiple autodate fields with any name.
Just adding a comment to say that i would love to see this PR Land. Been a while since last update is there anything that can be done to wrap it up?
I’m about to start using pocketbase on a new project and will update this library at the same time
On Thu, 21 Aug 2025 at 12:22 am, sean-at-heady @.***> wrote:
sean-at-heady left a comment (patmood/pocketbase-typegen#111) https://github.com/patmood/pocketbase-typegen/pull/111#issuecomment-3206636049
Just adding a comment to say that i would love to see this PR Land. Been a while since last update is there anything that can be done to wrap it up?
— Reply to this email directly, view it on GitHub https://github.com/patmood/pocketbase-typegen/pull/111#issuecomment-3206636049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6YGPGHDWP6IBRJ25BEBQ33OSAEHAVCNFSM6AAAAABUE3Z6OKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMBWGYZTMMBUHE . You are receiving this because you were mentioned.Message ID: @.***>
I’m about to start using pocketbase on a new project and will update this
library at the same time
On Thu, 21 Aug 2025 at 12:22 am, sean-at-heady @.***>
wrote:
sean-at-heady left a comment (patmood/pocketbase-typegen#111)
https://github.com/patmood/pocketbase-typegen/pull/111#issuecomment-3206636049
Just adding a comment to say that i would love to see this PR Land. Been a
while since last update is there anything that can be done to wrap it up?
—
Reply to this email directly, view it on GitHub
https://github.com/patmood/pocketbase-typegen/pull/111#issuecomment-3206636049,
or unsubscribe
.
You are receiving this because you were mentioned.Message ID:
@.***>
I'd be open to collaborating on that.
With my last commit the local tests were passing, and since I couldn't find out why and what those integration tests are I left them as they were.
going to merge this and fix the outstanding issues + tests