@trpc/next
Version:
26 lines (25 loc) • 1.21 kB
JavaScript
import { t as _objectSpread2 } from "../../objectSpread2-Dh4InpQf.mjs";
import { t as generateCacheTag } from "../../shared-DJ-gGeuI.mjs";
import { httpBatchLink, httpLink } from "@trpc/client";
//#region src/app-dir/links/nextHttp.ts
function experimental_nextHttpLink(opts) {
return (runtime) => {
return (ctx) => {
var _ref;
const { path, input, context } = ctx.op;
const cacheTag = generateCacheTag(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: [cacheTag]
} }));
};
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