UNPKG

payload-rest-client

Version:

A typesafe rest api client for the payload cms.

178 lines 6.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCollectionsProxy = void 0; const fetch_1 = require("./fetch"); const qs_1 = require("./qs"); const createCollectionsProxy = (options) => { const fetchFn = (0, fetch_1.fetchFactory)(options); return new Proxy({}, { get: (_, slug) => { const api = { find: (params) => { return fetchFn({ type: "collection", slug, method: "GET", path: [slug], qs: (0, qs_1.createQueryString)(params), }); }, findById: (params) => { const { id, ...rest } = params; return fetchFn({ type: "collection", slug, method: "GET", path: [slug, id], qs: (0, qs_1.createQueryString)(rest), }); }, count: (params) => { return fetchFn({ type: "collection", slug, method: "GET", path: [slug, "count"], qs: (0, qs_1.createQueryString)(params), }); }, create: (params) => { const { doc, ...rest } = params; return fetchFn({ type: "collection", slug, method: "POST", path: [slug], qs: (0, qs_1.createQueryString)(rest), body: doc, }); }, createDraft: (params) => { const { doc, ...rest } = params; return fetchFn({ type: "collection", slug, method: "POST", path: [slug], qs: (0, qs_1.createQueryString)({ ...rest, draft: true, }), body: doc, }); }, update: (params) => { const { patch, ...rest } = params; return fetchFn({ type: "collection", slug, method: "PATCH", path: [slug], qs: (0, qs_1.createQueryString)(rest), body: patch, }); }, updateById: (params) => { const { id, patch, ...rest } = params; return fetchFn({ type: "collection", slug, method: "PATCH", path: [slug, id], qs: (0, qs_1.createQueryString)(rest), body: patch, }); }, delete: (params) => { return fetchFn({ type: "collection", slug, method: "DELETE", path: [slug], qs: (0, qs_1.createQueryString)(params), }); }, deleteById: (params) => { const { id, ...rest } = params; return fetchFn({ type: "collection", slug, method: "DELETE", path: [slug, id], qs: (0, qs_1.createQueryString)(rest), }); }, login: (params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "login"], qs: "", body: params, }); }, logout: (_params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "logout"], qs: "", }); }, unlock: (params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "unlock"], qs: "", body: params, }); }, "refresh-token": (_params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "refresh-token"], qs: "", }); }, me: (_params) => { return fetchFn({ type: "collection", slug, method: "GET", path: [slug, "me"], qs: "", }); }, "forgot-password": (params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "forgot-password"], qs: "", body: params, }); }, "reset-password": (params) => { return fetchFn({ type: "collection", slug, method: "POST", path: [slug, "reset-password"], qs: "", body: params, }); }, }; return api; }, }); }; exports.createCollectionsProxy = createCollectionsProxy; //# sourceMappingURL=collectionsProxy.js.map