@trpc/next
Version:
31 lines (30 loc) • 1.59 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_shared = require("../../shared-Dti-OX_U.cjs");
const require_objectSpread2 = require("../../objectSpread2-BrE3MaRD.cjs");
let _trpc_client = require("@trpc/client");
// 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);
};
};
}
exports.experimental_nextHttpLink = experimental_nextHttpLink;