feat(cms-client): add dual-mode Payload client (local + HTTP)
This commit is contained in:
78
packages/cms-client/src/local-client.ts
Normal file
78
packages/cms-client/src/local-client.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import type { Payload } from "payload";
|
||||
import type {
|
||||
FindOptions,
|
||||
PayloadClient,
|
||||
PayloadClientResult,
|
||||
} from "./types.js";
|
||||
|
||||
export class LocalPayloadClient implements PayloadClient {
|
||||
constructor(private payload: Payload) {}
|
||||
|
||||
async find<T = Record<string, unknown>>(
|
||||
collection: string,
|
||||
options?: FindOptions
|
||||
): Promise<PayloadClientResult<T>> {
|
||||
const result = await this.payload.find({
|
||||
collection: collection as any,
|
||||
where: options?.where as any,
|
||||
sort: options?.sort,
|
||||
limit: options?.limit,
|
||||
page: options?.page,
|
||||
depth: options?.depth,
|
||||
locale: options?.locale as any,
|
||||
});
|
||||
return result as unknown as PayloadClientResult<T>;
|
||||
}
|
||||
|
||||
async findByID<T = Record<string, unknown>>(
|
||||
collection: string,
|
||||
id: string,
|
||||
options?: { depth?: number }
|
||||
): Promise<T> {
|
||||
const result = await this.payload.findByID({
|
||||
collection: collection as any,
|
||||
id,
|
||||
depth: options?.depth,
|
||||
});
|
||||
return result as unknown as T;
|
||||
}
|
||||
|
||||
async create<T = Record<string, unknown>>(
|
||||
collection: string,
|
||||
data: Record<string, unknown>,
|
||||
options?: { depth?: number }
|
||||
): Promise<T> {
|
||||
const result = await this.payload.create({
|
||||
collection: collection as any,
|
||||
data: data as any,
|
||||
depth: options?.depth,
|
||||
});
|
||||
return result as unknown as T;
|
||||
}
|
||||
|
||||
async update<T = Record<string, unknown>>(
|
||||
collection: string,
|
||||
id: string,
|
||||
data: Record<string, unknown>,
|
||||
options?: { depth?: number }
|
||||
): Promise<T> {
|
||||
const result = await this.payload.update({
|
||||
collection: collection as any,
|
||||
id,
|
||||
data: data as any,
|
||||
depth: options?.depth,
|
||||
});
|
||||
return result as unknown as T;
|
||||
}
|
||||
|
||||
async delete<T = Record<string, unknown>>(
|
||||
collection: string,
|
||||
id: string
|
||||
): Promise<T> {
|
||||
const result = await this.payload.delete({
|
||||
collection: collection as any,
|
||||
id,
|
||||
});
|
||||
return result as unknown as T;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user