UNPKG

@trpc/next

Version:

The tRPC Next.js library

32 lines (31 loc) • 1.39 kB
import { t as _objectSpread2 } from "../../objectSpread2-Dh4InpQf.mjs"; import { n as generateCacheTags } from "../../shared-hPVy7N3A.mjs"; import { httpBatchLink, httpLink } from "@trpc/client"; //#region src/app-dir/links/nextHttp.ts /** * A terminating link that sends calls over HTTP with Next.js cache tags, so * they can be revalidated. * * @see https://trpc.io/docs/client/nextjs/app-router-setup */ function experimental_nextHttpLink(opts) { return (runtime) => { return (ctx) => { var _ref; const { path, input, context } = ctx.op; const cacheTags = generateCacheTags(path, input); const requestRevalidate = typeof context["revalidate"] === "number" || context["revalidate"] === false ? context["revalidate"] : void 0; const revalidate = (_ref = requestRevalidate !== null && requestRevalidate !== void 0 ? requestRevalidate : opts.revalidate) !== null && _ref !== void 0 ? _ref : false; const _fetch = (url, fetchOpts) => { return fetch(url, _objectSpread2(_objectSpread2({}, fetchOpts), {}, { next: { revalidate, tags: cacheTags } })); }; return (opts.batch ? httpBatchLink(_objectSpread2(_objectSpread2({}, opts), {}, { fetch: _fetch })) : httpLink(_objectSpread2(_objectSpread2({}, opts), {}, { fetch: _fetch })))(runtime)(ctx); }; }; } //#endregion export { experimental_nextHttpLink }; //# sourceMappingURL=nextHttp.mjs.map