79 lines
1.9 KiB
TypeScript
79 lines
1.9 KiB
TypeScript
import type { Payload } from "payload";
|
|
import type {
|
|
FindOptions,
|
|
PayloadClient,
|
|
PayloadClientResult,
|
|
} from "./types";
|
|
|
|
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;
|
|
}
|
|
}
|