-
Notifications
You must be signed in to change notification settings - Fork 12
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
getOne
method doesn't allow for select
and $expand
#31
Comments
Hi @shyakadavis, Take a look at it here: https://github.com/david-plugge/typed-pocketbase/tree/custom-client |
Hey, @david-plugge I don't mind trying out the new version with the Doing pnpm add [email protected] yields this error in several places:
Vite/SvelteKit has a better description:
Are you sure it works fine and it's not something wrong on my part? Thanks. |
Hey, thanks for reporting the issue. I released a new version 0.1.0-pre.2 which should resolve the type issue. There are a few more additions aswell like support for realtime events which where missing before. Give it a try and let me know if there are still some issues. My goal ist to release |
Hey, @david-plugge Thanks for your continued work on the lib. The new version works great overall, but there are some wrong/flawed cases. For example, take this; (Note: If sharing my entire generated schema is simpler, please let me know) 🙂 I have a The problem: When I do expand on this field when calling the project, it's typed as
which breaks in my Svelte component where I'm iterating like so: {#if data.project.expand && data.project.expand.user}
<span>
<dt>Founder(s)</dt>
<dd class="flex flex-wrap -space-x-3">
{#each data.project.expand.user as user}
<Avatar.Root class={cn(`ring-background size-9 ring-2`)}>
<Avatar.Image
src={get_image_url({
collection_id: user.collectionId,
record_id: user.id,
file_name: user.avatar,
size: '50x50'
})}
alt={`@${user.username}`}
/>
<Avatar.Fallback>
{user.username.slice(0, 1).toUpperCase()}
</Avatar.Fallback>
</Avatar.Root>
{/each}
</dd>
</span>
{/if} with this error:
It should be typed as P.S: If I encounter other issues, will let you know. 🙂 |
Btw, how can I There are a lot of TS comp errors that have arisen because of the
|
Another issue (sorry if they are becoming too much under this issue #31 🙂) Problem: Updating the // form.data just contains `username` key-value pair
await event.locals.pb.from('users').update(event.locals.user.id, form.data); errors like so:
I tried having a look at |
Another issue: 😅 Problem: Update: I'm simply doing like specified in the example of your P.R #29 like so: const sort = event.locals.pb.from('projects').createSort('+created');
const filter = event.locals.pb
.from('projects')
.createFilter(`user.id ?= "${event.locals.user.id}"`);
const select = event.locals.pb.from('projects').createSelect({
id: true,
name: true,
created: true,
expand: {
stage: { name: true },
user: { collectionId: true, id: true, avatar: true, username: true, name: true }
}
});
const projects = await event.locals.pb.from('projects').getFullList({ select, filter, sort }); From the PB dashboard under logs, this is the generated data.url:
I don't know why it's not being generated, and/or how to inspect where it's going wrong. Btw, is there no built-in helpers for this complex kind of filter: const filter = event.locals.pb
.from('projects')
.createFilter(`user.id ?= "${event.locals.user.id}"`); |
good catch, the update type should be optional Mhm, they should be optional already... Can you send your whole schema? |
Here you go, @david-plugge /**
* This file was @generated using typed-pocketbase
*/
// https://pocketbase.io/docs/collections/#base-collection
export interface BaseCollectionResponse {
/**
* 15 characters string to store as record ID.
*/
id: string;
/**
* Date string representation for the creation date.
*/
created: string;
/**
* Date string representation for the creation date.
*/
updated: string;
/**
* The collection id.
*/
collectionId: string;
/**
* The collection name.
*/
collectionName: string;
}
// https://pocketbase.io/docs/api-records/#create-record
export interface BaseCollectionCreate {
/**
* 15 characters string to store as record ID.
* If not set, it will be auto generated.
*/
id?: string;
}
// https://pocketbase.io/docs/api-records/#update-record
export interface BaseCollectionUpdate {}
// https://pocketbase.io/docs/collections/#auth-collection
export interface AuthCollectionResponse extends BaseCollectionResponse {
/**
* The username of the auth record.
*/
username: string;
/**
* Auth record email address.
*/
email: string;
/**
* Whether to show/hide the auth record email when fetching the record data.
*/
emailVisibility: boolean;
/**
* Indicates whether the auth record is verified or not.
*/
verified: boolean;
}
// https://pocketbase.io/docs/api-records/#create-record
export interface AuthCollectionCreate extends BaseCollectionCreate {
/**
* The username of the auth record.
* If not set, it will be auto generated.
*/
username?: string;
/**
* Auth record email address.
*/
email?: string;
/**
* Whether to show/hide the auth record email when fetching the record data.
*/
emailVisibility?: boolean;
/**
* Auth record password.
*/
password: string;
/**
* Auth record password confirmation.
*/
passwordConfirm: string;
/**
* Indicates whether the auth record is verified or not.
* This field can be set only by admins or auth records with "Manage" access.
*/
verified?: boolean;
}
// https://pocketbase.io/docs/api-records/#update-record
export interface AuthCollectionUpdate {
/**
* The username of the auth record.
*/
username?: string;
/**
* The auth record email address.
* This field can be updated only by admins or auth records with "Manage" access.
* Regular accounts can update their email by calling "Request email change".
*/
email?: string;
/**
* Whether to show/hide the auth record email when fetching the record data.
*/
emailVisibility?: boolean;
/**
* Old auth record password.
* This field is required only when changing the record password. Admins and auth records with "Manage" access can skip this field.
*/
oldPassword?: string;
/**
* New auth record password.
*/
password: string;
/**
* New auth record password confirmation.
*/
passwordConfirm: string;
/**
* Indicates whether the auth record is verified or not.
* This field can be set only by admins or auth records with "Manage" access.
*/
verified?: boolean;
}
// https://pocketbase.io/docs/collections/#view-collection
export interface ViewCollectionRecord {
id: string;
}
// utilities
type MaybeArray<T> = T | T[];
// ===== users =====
export interface UsersResponse extends AuthCollectionResponse {
collectionName: 'users';
name: string;
avatar: string;
}
export interface UsersCreate extends AuthCollectionCreate {
name?: string;
avatar?: File;
}
export interface UsersUpdate extends AuthCollectionUpdate {
name?: string;
avatar?: File;
}
export interface UsersCollection {
type: 'auth';
collectionId: string;
collectionName: 'users';
response: UsersResponse;
create: UsersCreate;
update: UsersUpdate;
relations: {
'posts(user)': PostsCollection;
'projects(user)': ProjectsCollection;
};
}
// ===== tags =====
export interface TagsResponse extends BaseCollectionResponse {
collectionName: 'tags';
name: string;
}
export interface TagsCreate extends BaseCollectionCreate {
name: string;
}
export interface TagsUpdate extends BaseCollectionUpdate {
name?: string;
}
export interface TagsCollection {
type: 'base';
collectionId: string;
collectionName: 'tags';
response: TagsResponse;
create: TagsCreate;
update: TagsUpdate;
relations: {
'posts(tags)': PostsCollection;
};
}
// ===== posts =====
export interface PostsResponse extends BaseCollectionResponse {
collectionName: 'posts';
post: string;
image: string;
user: string;
tags: Array<string>;
}
export interface PostsCreate extends BaseCollectionCreate {
post: string;
image?: File;
user?: string;
tags?: MaybeArray<string>;
}
export interface PostsUpdate extends BaseCollectionUpdate {
post?: string;
image?: File;
user?: string;
tags?: MaybeArray<string>;
'tags+'?: MaybeArray<string>;
'tags-'?: MaybeArray<string>;
}
export interface PostsCollection {
type: 'base';
collectionId: string;
collectionName: 'posts';
response: PostsResponse;
create: PostsCreate;
update: PostsUpdate;
relations: {
user: UsersCollection;
tags: TagsCollection;
};
}
// ===== projects =====
export interface ProjectsResponse extends BaseCollectionResponse {
collectionName: 'projects';
name: string;
tagline: string;
description: string;
url: string;
category: string;
stage: string;
user: Array<string>;
thumbnail: string;
twitter: string;
github: string;
mrr: number;
}
export interface ProjectsCreate extends BaseCollectionCreate {
name: string;
tagline: string;
description: string;
url: string | URL;
category: string;
stage: string;
user: MaybeArray<string>;
thumbnail?: File;
twitter?: string | URL;
github?: string | URL;
mrr?: number;
}
export interface ProjectsUpdate extends BaseCollectionUpdate {
name?: string;
tagline?: string;
description?: string;
url?: string | URL;
category?: string;
stage?: string;
user?: MaybeArray<string>;
'user+'?: MaybeArray<string>;
'user-'?: MaybeArray<string>;
thumbnail?: File;
twitter?: string | URL;
github?: string | URL;
mrr?: number;
'mrr+'?: number;
'mrr-'?: number;
}
export interface ProjectsCollection {
type: 'base';
collectionId: string;
collectionName: 'projects';
response: ProjectsResponse;
create: ProjectsCreate;
update: ProjectsUpdate;
relations: {
stage: StagesCollection;
user: UsersCollection;
};
}
// ===== stages =====
export interface StagesResponse extends BaseCollectionResponse {
collectionName: 'stages';
name: string;
}
export interface StagesCreate extends BaseCollectionCreate {
name: string;
}
export interface StagesUpdate extends BaseCollectionUpdate {
name?: string;
}
export interface StagesCollection {
type: 'base';
collectionId: string;
collectionName: 'stages';
response: StagesResponse;
create: StagesCreate;
update: StagesUpdate;
relations: {
'projects(stage)': ProjectsCollection;
};
}
// ===== Schema =====
export type Schema = {
users: UsersCollection;
tags: TagsCollection;
posts: PostsCollection;
projects: ProjectsCollection;
stages: StagesCollection;
}; |
It looks good to me and sort also returns the correct string in my case. Can you also create a minimal reproduction that i can take a look at? |
There is, you can use the array syntax: const filter = event.locals.pb
.from('projects')
.createFilter(["user.id", "?=", event.locals.user.id]); There is no good name for this filter i think, if you have one, feel free to suggest it :) |
I found the issue regarding sort, the new version |
Hey. Thanks for the quick patches; sadly, they didn't work.
So, this is the
It didn't work 🙈
Hmm... I can try. Will let you know. 🙂 Any updates on the other 2 issues; i.e.
|
This was fixed in the new version, thanks for pointing out!
Somehow the package wasn't build before publishing, you can try out the new version
You can check in the network tab if you are using a browser. Or you can supply your own fetch function that logs the url |
Thanks a lot @david-plugge AFAICT, everything is working smoothly on my end with the new custom client (as of pre.6). The only remark/annoyance is the Again, thanks a ton for the lib. 🙂 |
Awesome! I agree that it's somewhat annoying having to check for Glad you like it. Thank you for reporting all the issues and helping me figure out how to make this package even better. |
Hi;
Not sure if I'm using the methods/functions in the wrong way, but basically, I'm trying to do something like this:
but I get this error:
I also tried doing this (sorry, but I couldn't find clear intructions from the readme.md about using the lib) but this, although TS doesn't complain, it just returns the surface-level fields, but nothing for the expanded ones.
Don't know if I'm being clear enough, but anyone mind helping me out?
Thanks.
The text was updated successfully, but these errors were encountered: