Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"prepublishOnly": "pnpm clean && pnpm build"
},
"devDependencies": {
"payload": "3.0.0-beta.58",
"typescript": "^5.5.2"
"payload": "3.1.0",
"typescript": "^5.8.2"
},
"publishConfig": {
"exports": {
Expand All @@ -44,8 +44,8 @@
"types": "./dist/index.d.ts"
},
"dependencies": {
"@types/qs": "^6.9.15",
"qs": "^6.12.2",
"ts-essentials": "^10.0.1"
"@types/qs": "^6.9.18",
"qs": "^6.14.0",
"ts-essentials": "^10.0.4"
}
}
}
14 changes: 6 additions & 8 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PayloadApiClient<C extends Config> {
return response.json();
}

async find<T extends keyof C['collections'], K extends (keyof C['collections'][T])[]>({
async find<T extends keyof C['collections'], K extends Partial<Record<keyof C['collections'][T], boolean>>>({
collection,
...toQs
}: {
Expand All @@ -113,17 +113,15 @@ export class PayloadApiClient<C extends Config> {
select?: K;
sort?: `-${Exclude<keyof C['collections'][T], symbol>}` | keyof C['collections'][T];
where?: Where;
}): Promise<
PaginatedDocs<K extends undefined ? C['collections'][T] : Pick<C['collections'][T], K[0]>>
> {
}): Promise<PaginatedDocs<K extends undefined ? C['collections'][T] : Pick<C['collections'][T], Extract<keyof K, keyof C['collections'][T]>>>> {
const qs = buildQueryString(toQs);

const response = await this.fetcher(`${this.apiURL}/${collection.toString()}${qs}`);

return response.json();
}

async findById<T extends keyof C['collections'], K extends (keyof C['collections'][T])[]>({
async findById<T extends keyof C['collections'], K extends Partial<Record<keyof C['collections'][T], boolean>>>({
collection,
id,
...toQs
Expand All @@ -135,15 +133,15 @@ export class PayloadApiClient<C extends Config> {
id: C['collections'][T]['id'];
locale?: 'all' | C['locale'];
select?: K;
}): Promise<K extends undefined ? C['collections'][T] : Pick<C['collections'][T], K[0]>> {
}): Promise<K extends undefined ? C['collections'][T] : Pick<C['collections'][T], Extract<keyof K, keyof C['collections'][T]>>> {
const qs = buildQueryString(toQs);

const response = await this.fetcher(`${this.apiURL}/${collection.toString()}/${id}${qs}`);

return response.json();
}

async findGlobal<T extends keyof C['globals'], K extends (keyof C['globals'][T])[]>({
async findGlobal<T extends keyof C['globals'], K extends Partial<Record<keyof C['globals'][T], boolean>>>({
slug,
...toQs
}: {
Expand All @@ -152,7 +150,7 @@ export class PayloadApiClient<C extends Config> {
locale?: 'all' | C['locale'];
select?: K;
slug: T;
}): Promise<K extends undefined ? C['globals'][T] : Pick<C['globals'][T], K[0]>> {
}): Promise<K extends undefined ? C['globals'][T] : Pick<C['globals'][T], Extract<keyof K, keyof C['globals'][T]>>> {
const qs = buildQueryString(toQs);

const response = await this.fetcher(`${this.apiURL}/globals/${slug.toString()}${qs}`);
Expand Down
Loading