UNPKG

@trpc/next

Version:

The tRPC Next.js library

26 lines (25 loc) 1.44 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const require_objectSpread2 = require("../../objectSpread2-C2ceYbQe.cjs"); const require_shared = require("../../shared-BcvoW6jT.cjs"); let _trpc_client = require("@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 = require_shared.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, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, fetchOpts), {}, { next: { revalidate, tags: [cacheTag] } })); }; 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;