@trpc/next
Version:
32 lines (31 loc) • 1.61 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_objectSpread2 = require("../../objectSpread2-C2ceYbQe.cjs");
const require_shared = require("../../shared-DOM8k8Lu.cjs");
let _trpc_client = require("@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 = require_shared.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, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, fetchOpts), {}, { next: {
revalidate,
tags: cacheTags
} }));
};
return (opts.batch ? (0, _trpc_client.httpBatchLink)(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, { fetch: _fetch })) : (0, _trpc_client.httpLink)(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, { fetch: _fetch })))(runtime)(ctx);
};
};
}
//#endregion
exports.experimental_nextHttpLink = experimental_nextHttpLink;