UEA-Prodem
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Alex Johansson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<p align="center">
|
||||
<a href="https://trpc.io/"><img src="https://assets.trpc.io/icons/svgs/blue-bg-rounded.svg" alt="tRPC" height="75"/></a>
|
||||
</p>
|
||||
|
||||
<h3 align="center">tRPC</h3>
|
||||
|
||||
<p align="center">
|
||||
<strong>End-to-end typesafe APIs made easy</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://assets.trpc.io/www/v10/v10-dark-landscape.gif" alt="Demo" />
|
||||
</p>
|
||||
|
||||
# `@trpc/react-query`
|
||||
|
||||
> A tRPC wrapper around react-query.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation for `@trpc/react-query` can be found [here](https://trpc.io/docs/react-query)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# npm
|
||||
npm install @trpc/react-query @tanstack/react-query
|
||||
|
||||
# Yarn
|
||||
yarn add @trpc/react-query @tanstack/react-query
|
||||
|
||||
# pnpm
|
||||
pnpm add @trpc/react-query @tanstack/react-query
|
||||
|
||||
# Bun
|
||||
bun add @trpc/react-query @tanstack/react-query
|
||||
```
|
||||
|
||||
## Basic Example
|
||||
|
||||
Create a utils file that exports tRPC hooks and providers.
|
||||
|
||||
```ts
|
||||
import { createTRPCReact } from '@trpc/react-query';
|
||||
import type { AppRouter } from './server';
|
||||
|
||||
export const trpc = createTRPCReact<AppRouter>();
|
||||
```
|
||||
|
||||
Use the provider to connect to your API.
|
||||
|
||||
```ts
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { trpc } from '~/utils/trpc';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
export function App() {
|
||||
const [queryClient] = useState(() => new QueryClient());
|
||||
const [trpcClient] = useState(() =>
|
||||
trpc.createClient({
|
||||
url: 'http://localhost:5000/trpc',
|
||||
}),
|
||||
);
|
||||
return (
|
||||
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{/* Your app here */}
|
||||
</QueryClientProvider>
|
||||
</trpc.Provider>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Now in any component, you can query your API using the proxy exported from the utils file.
|
||||
|
||||
```ts
|
||||
import { trpc } from '~/utils/trpc';
|
||||
|
||||
export function Hello() {
|
||||
const { data, error, status } = trpc.greeting.useQuery({ name: 'tRPC' });
|
||||
|
||||
if (error) {
|
||||
return <p>{error.message}</p>;
|
||||
}
|
||||
|
||||
if (status !== 'success') {
|
||||
return <p>Loading...</p>;
|
||||
}
|
||||
|
||||
return <div>{data && <p>{data.greeting}</p>}</div>;
|
||||
}
|
||||
```
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
import { skipToken } from "@tanstack/react-query";
|
||||
import { isObject } from "@trpc/server/unstable-core-do-not-import";
|
||||
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js
|
||||
var require_objectWithoutPropertiesLoose = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js"(exports, module) {
|
||||
function _objectWithoutPropertiesLoose(r, e) {
|
||||
if (null == r) return {};
|
||||
var t = {};
|
||||
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
||||
if (e.includes(n)) continue;
|
||||
t[n] = r[n];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js
|
||||
var require_objectWithoutProperties = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js"(exports, module) {
|
||||
var objectWithoutPropertiesLoose = require_objectWithoutPropertiesLoose();
|
||||
function _objectWithoutProperties$1(e, t) {
|
||||
if (null == e) return {};
|
||||
var o, r, i = objectWithoutPropertiesLoose(e, t);
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var s = Object.getOwnPropertySymbols(e);
|
||||
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
module.exports = _objectWithoutProperties$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js
|
||||
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
||||
function _typeof$2(o) {
|
||||
"@babel/helpers - typeof";
|
||||
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
||||
return typeof o$1;
|
||||
} : function(o$1) {
|
||||
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
||||
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
||||
}
|
||||
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js
|
||||
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
||||
var _typeof$1 = require_typeof()["default"];
|
||||
function toPrimitive$1(t, r) {
|
||||
if ("object" != _typeof$1(t) || !t) return t;
|
||||
var e = t[Symbol.toPrimitive];
|
||||
if (void 0 !== e) {
|
||||
var i = e.call(t, r || "default");
|
||||
if ("object" != _typeof$1(i)) return i;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return ("string" === r ? String : Number)(t);
|
||||
}
|
||||
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js
|
||||
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
||||
var _typeof = require_typeof()["default"];
|
||||
var toPrimitive = require_toPrimitive();
|
||||
function toPropertyKey$1(t) {
|
||||
var i = toPrimitive(t, "string");
|
||||
return "symbol" == _typeof(i) ? i : i + "";
|
||||
}
|
||||
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js
|
||||
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
||||
var toPropertyKey = require_toPropertyKey();
|
||||
function _defineProperty(e, r, t) {
|
||||
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
||||
value: t,
|
||||
enumerable: !0,
|
||||
configurable: !0,
|
||||
writable: !0
|
||||
}) : e[r] = t, e;
|
||||
}
|
||||
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js
|
||||
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
||||
var defineProperty = require_defineProperty();
|
||||
function ownKeys(e, r) {
|
||||
var t = Object.keys(e);
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var o = Object.getOwnPropertySymbols(e);
|
||||
r && (o = o.filter(function(r$1) {
|
||||
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
||||
})), t.push.apply(t, o);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function _objectSpread2(e) {
|
||||
for (var r = 1; r < arguments.length; r++) {
|
||||
var t = null != arguments[r] ? arguments[r] : {};
|
||||
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
||||
defineProperty(e, r$1, t[r$1]);
|
||||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
||||
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
||||
});
|
||||
}
|
||||
return e;
|
||||
}
|
||||
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/getQueryKey.ts
|
||||
var import_objectWithoutProperties = __toESM(require_objectWithoutProperties(), 1);
|
||||
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
||||
const _excluded = ["cursor", "direction"];
|
||||
/**
|
||||
* To allow easy interactions with groups of related queries, such as
|
||||
* invalidating all queries of a router, we use an array as the path when
|
||||
* storing in tanstack query.
|
||||
**/
|
||||
function getQueryKeyInternal(path, input, type) {
|
||||
const splitPath = path.flatMap((part) => part.split("."));
|
||||
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
||||
if (type === "infinite" && isObject(input) && ("direction" in input || "cursor" in input)) {
|
||||
const { cursor: _, direction: __ } = input, inputWithoutCursorAndDirection = (0, import_objectWithoutProperties.default)(input, _excluded);
|
||||
return [splitPath, {
|
||||
input: inputWithoutCursorAndDirection,
|
||||
type: "infinite"
|
||||
}];
|
||||
}
|
||||
return [splitPath, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, typeof input !== "undefined" && input !== skipToken && { input }), type && type !== "any" && { type })];
|
||||
}
|
||||
function getMutationKeyInternal(path) {
|
||||
return getQueryKeyInternal(path, void 0, "any");
|
||||
}
|
||||
/**
|
||||
* Method to extract the query key for a procedure
|
||||
* @param procedureOrRouter - procedure or AnyRouter
|
||||
* @param input - input to procedureOrRouter
|
||||
* @param type - defaults to `any`
|
||||
* @see https://trpc.io/docs/v11/getQueryKey
|
||||
*/
|
||||
function getQueryKey(procedureOrRouter, ..._params) {
|
||||
const [input, type] = _params;
|
||||
const path = procedureOrRouter._def().path;
|
||||
const queryKey = getQueryKeyInternal(path, input, type !== null && type !== void 0 ? type : "any");
|
||||
return queryKey;
|
||||
}
|
||||
/**
|
||||
* Method to extract the mutation key for a procedure
|
||||
* @param procedure - procedure
|
||||
* @see https://trpc.io/docs/v11/getQueryKey#mutations
|
||||
*/
|
||||
function getMutationKey(procedure) {
|
||||
const path = procedure._def().path;
|
||||
return getMutationKeyInternal(path);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { __commonJS, __toESM, getMutationKey, getMutationKeyInternal, getQueryKey, getQueryKeyInternal, require_objectSpread2, require_objectWithoutProperties };
|
||||
//# sourceMappingURL=getQueryKey-BY58RNzP.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+242
@@ -0,0 +1,242 @@
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
const __tanstack_react_query = __toESM(require("@tanstack/react-query"));
|
||||
const __trpc_server_unstable_core_do_not_import = __toESM(require("@trpc/server/unstable-core-do-not-import"));
|
||||
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js
|
||||
var require_objectWithoutPropertiesLoose = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js"(exports, module) {
|
||||
function _objectWithoutPropertiesLoose(r, e) {
|
||||
if (null == r) return {};
|
||||
var t = {};
|
||||
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
||||
if (e.includes(n)) continue;
|
||||
t[n] = r[n];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js
|
||||
var require_objectWithoutProperties = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js"(exports, module) {
|
||||
var objectWithoutPropertiesLoose = require_objectWithoutPropertiesLoose();
|
||||
function _objectWithoutProperties$1(e, t) {
|
||||
if (null == e) return {};
|
||||
var o, r, i = objectWithoutPropertiesLoose(e, t);
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var s = Object.getOwnPropertySymbols(e);
|
||||
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
module.exports = _objectWithoutProperties$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js
|
||||
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
||||
function _typeof$2(o) {
|
||||
"@babel/helpers - typeof";
|
||||
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
||||
return typeof o$1;
|
||||
} : function(o$1) {
|
||||
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
||||
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
||||
}
|
||||
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js
|
||||
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
||||
var _typeof$1 = require_typeof()["default"];
|
||||
function toPrimitive$1(t, r) {
|
||||
if ("object" != _typeof$1(t) || !t) return t;
|
||||
var e = t[Symbol.toPrimitive];
|
||||
if (void 0 !== e) {
|
||||
var i = e.call(t, r || "default");
|
||||
if ("object" != _typeof$1(i)) return i;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return ("string" === r ? String : Number)(t);
|
||||
}
|
||||
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js
|
||||
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
||||
var _typeof = require_typeof()["default"];
|
||||
var toPrimitive = require_toPrimitive();
|
||||
function toPropertyKey$1(t) {
|
||||
var i = toPrimitive(t, "string");
|
||||
return "symbol" == _typeof(i) ? i : i + "";
|
||||
}
|
||||
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js
|
||||
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
||||
var toPropertyKey = require_toPropertyKey();
|
||||
function _defineProperty(e, r, t) {
|
||||
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
||||
value: t,
|
||||
enumerable: !0,
|
||||
configurable: !0,
|
||||
writable: !0
|
||||
}) : e[r] = t, e;
|
||||
}
|
||||
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js
|
||||
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
||||
var defineProperty = require_defineProperty();
|
||||
function ownKeys(e, r) {
|
||||
var t = Object.keys(e);
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var o = Object.getOwnPropertySymbols(e);
|
||||
r && (o = o.filter(function(r$1) {
|
||||
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
||||
})), t.push.apply(t, o);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function _objectSpread2(e) {
|
||||
for (var r = 1; r < arguments.length; r++) {
|
||||
var t = null != arguments[r] ? arguments[r] : {};
|
||||
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
||||
defineProperty(e, r$1, t[r$1]);
|
||||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
||||
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
||||
});
|
||||
}
|
||||
return e;
|
||||
}
|
||||
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/getQueryKey.ts
|
||||
var import_objectWithoutProperties = __toESM(require_objectWithoutProperties(), 1);
|
||||
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
||||
const _excluded = ["cursor", "direction"];
|
||||
/**
|
||||
* To allow easy interactions with groups of related queries, such as
|
||||
* invalidating all queries of a router, we use an array as the path when
|
||||
* storing in tanstack query.
|
||||
**/
|
||||
function getQueryKeyInternal(path, input, type) {
|
||||
const splitPath = path.flatMap((part) => part.split("."));
|
||||
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
||||
if (type === "infinite" && (0, __trpc_server_unstable_core_do_not_import.isObject)(input) && ("direction" in input || "cursor" in input)) {
|
||||
const { cursor: _, direction: __ } = input, inputWithoutCursorAndDirection = (0, import_objectWithoutProperties.default)(input, _excluded);
|
||||
return [splitPath, {
|
||||
input: inputWithoutCursorAndDirection,
|
||||
type: "infinite"
|
||||
}];
|
||||
}
|
||||
return [splitPath, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, typeof input !== "undefined" && input !== __tanstack_react_query.skipToken && { input }), type && type !== "any" && { type })];
|
||||
}
|
||||
function getMutationKeyInternal(path) {
|
||||
return getQueryKeyInternal(path, void 0, "any");
|
||||
}
|
||||
/**
|
||||
* Method to extract the query key for a procedure
|
||||
* @param procedureOrRouter - procedure or AnyRouter
|
||||
* @param input - input to procedureOrRouter
|
||||
* @param type - defaults to `any`
|
||||
* @see https://trpc.io/docs/v11/getQueryKey
|
||||
*/
|
||||
function getQueryKey(procedureOrRouter, ..._params) {
|
||||
const [input, type] = _params;
|
||||
const path = procedureOrRouter._def().path;
|
||||
const queryKey = getQueryKeyInternal(path, input, type !== null && type !== void 0 ? type : "any");
|
||||
return queryKey;
|
||||
}
|
||||
/**
|
||||
* Method to extract the mutation key for a procedure
|
||||
* @param procedure - procedure
|
||||
* @see https://trpc.io/docs/v11/getQueryKey#mutations
|
||||
*/
|
||||
function getMutationKey(procedure) {
|
||||
const path = procedure._def().path;
|
||||
return getMutationKeyInternal(path);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, '__commonJS', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return __commonJS;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, '__toESM', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return __toESM;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getMutationKey', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getMutationKey;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getMutationKeyInternal', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getMutationKeyInternal;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getQueryKey', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getQueryKey;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getQueryKeyInternal', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getQueryKeyInternal;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'require_objectSpread2', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require_objectSpread2;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'require_objectWithoutProperties', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require_objectWithoutProperties;
|
||||
}
|
||||
});
|
||||
+892
@@ -0,0 +1,892 @@
|
||||
import * as _trpc_client1 from "@trpc/client";
|
||||
import { CreateTRPCClientOptions, TRPCClient, TRPCClientError, TRPCClientErrorLike, TRPCRequestOptions, TRPCUntypedClient, createTRPCClient } from "@trpc/client";
|
||||
import { AnyClientTypes, AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, DistributiveOmit, MaybePromise, ProcedureType, ProtectedIntersection, RouterRecord, Simplify, coerceAsyncIterableToArray, inferAsyncIterableYield, inferProcedureInput, inferProcedureOutput, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { CancelOptions, DataTag, DefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InfiniteQueryObserverSuccessResult, InitialDataFunction, InvalidateOptions, InvalidateQueryFilters, MutationOptions, Query, QueryClient, QueryClientConfig, QueryFilters, QueryKey, QueryObserverSuccessResult, QueryOptions, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, SkipToken, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UnusedSkipTokenInfiniteOptions, UnusedSkipTokenOptions, Updater, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query";
|
||||
import * as React$1 from "react";
|
||||
import { JSX, ReactNode } from "react";
|
||||
|
||||
//#region src/internals/context.d.ts
|
||||
interface TRPCUseUtilsOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCRequestOptions;
|
||||
}
|
||||
interface TRPCFetchQueryOptions<TOutput, TError> extends DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'>, TRPCUseUtilsOptions {}
|
||||
type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, TRPCQueryKey, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCUseUtilsOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
/** @internal */
|
||||
type SSRState = 'mounted' | 'mounting' | 'prepass' | false;
|
||||
interface TRPCContextPropsBase<TRouter extends AnyRouter, TSSRContext> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The SSR context when server-side rendering
|
||||
* @default null
|
||||
*/
|
||||
ssrContext?: TSSRContext | null;
|
||||
/**
|
||||
* State of SSR hydration.
|
||||
* - `false` if not using SSR.
|
||||
* - `prepass` when doing a prepass to fetch queries' data
|
||||
* - `mounting` before TRPCProvider has been rendered on the client
|
||||
* - `mounted` when the TRPCProvider has been rendered on the client
|
||||
* @default false
|
||||
*/
|
||||
ssrState?: SSRState;
|
||||
/**
|
||||
* @deprecated pass abortOnUnmount to `createTRPCReact` instead
|
||||
* Abort loading query calls when unmounting a component - usually when navigating to a new page
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedTRPCContextProps<TRouter extends AnyRouter, TSSRContext> = TRPCContextPropsBase<TRouter, TSSRContext> & {
|
||||
client: TRPCClient<TRouter>;
|
||||
};
|
||||
interface TRPCContextProps<TRouter extends AnyRouter, TSSRContext> extends TRPCContextPropsBase<TRouter, TSSRContext> {
|
||||
/**
|
||||
* The react-query `QueryClient`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
declare const contextProps: (keyof TRPCContextPropsBase<any, any>)[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface TRPCContextState<TRouter extends AnyRouter, TSSRContext = undefined> extends Required<TRPCContextProps<TRouter, TSSRContext>>, TRPCQueryUtils<TRouter> {}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts?: UndefinedTRPCQueryOptionsIn<unknown, unknown, TRPCClientError<AnyClientTypes>>): UndefinedTRPCQueryOptionsOut<unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
queryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: DefinedTRPCQueryOptionsIn<unknown, unknown, TRPCClientError<AnyClientTypes>>): DefinedTRPCQueryOptionsOut<unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: UndefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>): UndefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
infiniteQueryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: DefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>): DefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<InfiniteData<unknown, unknown>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
||||
*/
|
||||
prefetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureQueryData: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidateQueries: (queryKey: TRPCQueryKey, filters?: InvalidateQueryFilters<TRPCQueryKey>, options?: InvalidateOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
resetQueries: (queryKey: TRPCQueryKey, filters?: QueryFilters<TRPCQueryKey>, options?: ResetOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetchQueries: (queryKey: TRPCQueryKey, filters?: RefetchQueryFilters<TRPCQueryKey>, options?: RefetchOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
|
||||
*/
|
||||
cancelQuery: (queryKey: TRPCQueryKey, options?: CancelOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueryData: (queryKey: TRPCQueryKey, updater: Updater<unknown, unknown>, options?: SetDataOptions) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
|
||||
*/
|
||||
setQueriesData: (queryKey: TRPCQueryKey, filters: QueryFilters, updater: Updater<unknown, unknown>, options?: SetDataOptions) => [QueryKey, unknown][];
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getQueryData: (queryKey: TRPCQueryKey) => unknown;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteQueryData: (queryKey: TRPCQueryKey, updater: Updater<InfiniteData<unknown> | undefined, InfiniteData<unknown> | undefined>, options?: SetDataOptions) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteQueryData: (queryKey: TRPCQueryKey) => InfiniteData<unknown> | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
|
||||
*/
|
||||
setMutationDefaults: (mutationKey: TRPCMutationKey, options: MutationOptions | ((args: {
|
||||
canonicalMutationFn: (input: unknown) => Promise<unknown>;
|
||||
}) => MutationOptions)) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
|
||||
*/
|
||||
getMutationDefaults: (mutationKey: TRPCMutationKey) => MutationOptions | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
|
||||
*/
|
||||
isMutating: (filters: {
|
||||
mutationKey: TRPCMutationKey;
|
||||
}) => number;
|
||||
}
|
||||
declare const TRPCContext: React$1.Context<any>;
|
||||
//#endregion
|
||||
//#region src/shared/hooks/types.d.ts
|
||||
type OutputWithCursor<TData, TCursor = any> = {
|
||||
cursor: TCursor | null;
|
||||
data: TData;
|
||||
};
|
||||
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
||||
/**
|
||||
* Opt out of SSR for this query by passing `ssr: false`
|
||||
*/
|
||||
ssr?: boolean;
|
||||
/**
|
||||
* Opt out or into aborting request on unmount
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
interface TRPCUseQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
interface UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError> extends DistributiveOmit<UseSuspenseQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError> extends DistributiveOmit<FetchQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
/** @internal **/
|
||||
interface DefinedUseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData>, 'queryKey'> {
|
||||
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
|
||||
}
|
||||
interface TRPCQueryOptions<TData, TError> extends DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
|
||||
queryKey: TRPCQueryKey;
|
||||
}
|
||||
type ExtractCursorType<TInput> = TInput extends {
|
||||
cursor?: any;
|
||||
} ? TInput['cursor'] : unknown;
|
||||
interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseSuspenseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
interface UseTRPCMutationOptions<TInput, TError, TOutput, TContext = unknown> extends UseMutationOptions<TOutput, TError, TInput, TContext>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
||||
/**
|
||||
* @deprecated
|
||||
* use a `skipToken` from `@tanstack/react-query` instead
|
||||
* this will be removed in v12
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Called when the subscription is started
|
||||
*/
|
||||
onStarted?: () => void;
|
||||
/**
|
||||
* Called when new data is received
|
||||
*/
|
||||
onData?: (data: TOutput) => void;
|
||||
/**
|
||||
* Called when an **unrecoverable error** occurs and the subscription is closed
|
||||
*/
|
||||
onError?: (err: TError) => void;
|
||||
/**
|
||||
* Called when the subscription is completed on the server
|
||||
*/
|
||||
onComplete?: () => void;
|
||||
}
|
||||
interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'idle' | 'connecting' | 'pending' | 'error';
|
||||
data: undefined | TOutput;
|
||||
error: null | TError;
|
||||
/**
|
||||
* Reset the subscription
|
||||
*/
|
||||
reset: () => void;
|
||||
}
|
||||
interface TRPCSubscriptionIdleResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, null> {
|
||||
status: 'idle';
|
||||
data: undefined;
|
||||
error: null;
|
||||
}
|
||||
interface TRPCSubscriptionConnectingResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'connecting';
|
||||
data: undefined | TOutput;
|
||||
error: TError | null;
|
||||
}
|
||||
interface TRPCSubscriptionPendingResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
||||
status: 'pending';
|
||||
data: TOutput | undefined;
|
||||
error: null;
|
||||
}
|
||||
interface TRPCSubscriptionErrorResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'error';
|
||||
data: TOutput | undefined;
|
||||
error: TError;
|
||||
}
|
||||
type TRPCSubscriptionResult<TOutput, TError> = TRPCSubscriptionIdleResult<TOutput> | TRPCSubscriptionConnectingResult<TOutput, TError> | TRPCSubscriptionErrorResult<TOutput, TError> | TRPCSubscriptionPendingResult<TOutput>;
|
||||
interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext> extends Omit<TRPCContextProps<TRouter, TSSRContext>, 'client'> {
|
||||
children: ReactNode;
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (props: TRPCProviderProps<TRouter, TSSRContext>) => JSX.Element;
|
||||
type CreateClient<TRouter extends AnyRouter> = (opts: CreateTRPCClientOptions<TRouter>) => TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCQueryResult<TData, TError> = TRPCHookResult & UseQueryResult<coerceAsyncIterableToArray<TData>, TError>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DefinedUseTRPCQueryResult<TData, TError> = DefinedUseQueryResult<TData, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCQuerySuccessResult<TData, TError> = QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCSuspenseQueryResult<TData, TError> = [TData, UseSuspenseQueryResult<TData, TError> & TRPCHookResult];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult & UseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> = InfiniteQueryObserverSuccessResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, UseSuspenseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCMutationResult<TData, TError, TVariables, TContext> = TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
|
||||
interface TRPCHookResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/types.d.ts
|
||||
interface TRPCQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
interface TRPCQueryOptionsResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
type TRPCOptionOverrides = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
||||
type TRPCInfiniteOptionOverrides = TRPCOptionOverrides | 'initialPageParam';
|
||||
/**
|
||||
* QueryOptions API helpers
|
||||
*/
|
||||
interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>, TError>;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
/**
|
||||
* InifiniteQueryOptions helpers
|
||||
*/
|
||||
interface UndefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UndefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface DefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface DefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface UseMutationOverride {
|
||||
onSuccess: (opts: {
|
||||
/**
|
||||
* Calls the original function that was defined in the query's `onSuccess` option
|
||||
*/
|
||||
originalFn: () => MaybePromise<void>;
|
||||
queryClient: QueryClient;
|
||||
/**
|
||||
* Meta data passed in from the `useMutation()` hook
|
||||
*/
|
||||
meta: Record<string, unknown>;
|
||||
}) => MaybePromise<void>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
||||
/**
|
||||
* Override behaviors of the built-in hooks
|
||||
*/
|
||||
overrides?: {
|
||||
useMutation?: Partial<UseMutationOverride>;
|
||||
};
|
||||
/**
|
||||
* Abort all queries when unmounting
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
/**
|
||||
* Override the default context provider
|
||||
* @default undefined
|
||||
*/
|
||||
context?: React.Context<any>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/shared/hooks/createHooksInternal.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createRootHooks<TRouter extends AnyRouter, TSSRContext = unknown>(config?: CreateTRPCReactOptions<TRouter>): {
|
||||
Provider: TRPCProvider<TRouter, TSSRContext>;
|
||||
createClient: (opts: _trpc_client1.CreateTRPCClientOptions<TRouter>) => _trpc_client1.TRPCClient<TRouter>;
|
||||
useContext: () => TRPCContextState<TRouter, TSSRContext>;
|
||||
useUtils: () => TRPCContextState<TRouter, TSSRContext>;
|
||||
useQuery: (path: readonly string[], input: unknown, opts?: UseTRPCQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCQueryResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
usePrefetchQuery: (path: string[], input: unknown, opts?: UseTRPCPrefetchQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => void;
|
||||
useSuspenseQuery: (path: readonly string[], input: unknown, opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseQueryResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
useQueries: TRPCUseQueries<TRouter>;
|
||||
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
||||
useMutation: (path: readonly string[], opts?: UseTRPCMutationOptions<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>) => UseTRPCMutationResult<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>;
|
||||
useSubscription: (path: readonly string[], input: unknown, opts: UseTRPCSubscriptionOptions<unknown, TRPCClientErrorLike<TRouter>>) => TRPCSubscriptionResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
useInfiniteQuery: (path: readonly string[], input: unknown, opts: UseTRPCInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>;
|
||||
usePrefetchInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCPrefetchInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => void;
|
||||
useSuspenseInfiniteQuery: (path: readonly string[], input: unknown, opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>;
|
||||
};
|
||||
/**
|
||||
* Infer the type of a `createReactQueryHooks` function
|
||||
* @internal
|
||||
*/
|
||||
type CreateReactQueryHooks<TRouter extends AnyRouter, TSSRContext = unknown> = ReturnType<typeof createRootHooks<TRouter, TSSRContext>>;
|
||||
//# sourceMappingURL=createHooksInternal.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/proxy/decorationProxy.d.ts
|
||||
/**
|
||||
* Create proxy for decorating procedures
|
||||
* @internal
|
||||
*/
|
||||
declare function createReactDecoration<TRouter extends AnyRouter, TSSRContext = unknown>(hooks: CreateReactQueryHooks<TRouter, TSSRContext>): unknown;
|
||||
//# sourceMappingURL=decorationProxy.d.ts.map
|
||||
//#endregion
|
||||
//#region src/utils/inferReactQueryProcedure.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TData = inferTransformedProcedureOutput<TRoot, TProcedure>> = Omit<UseTRPCQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, TData>, 'select' | 'queryFn'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferMutationOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TMeta = unknown> = UseTRPCMutationOptions<inferProcedureInput<TProcedure>, TRPCClientErrorLike<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure>, TMeta>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferQueryResult<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = UseTRPCQueryResult<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferMutationResult<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TContext = unknown> = UseTRPCMutationResult<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, inferProcedureInput<TProcedure>, TContext>;
|
||||
type inferReactQueryProcedureOptionsInner<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? InferQueryOptions<TRoot, $Value> : $Value extends AnyMutationProcedure ? InferMutationOptions<TRoot, $Value> : $Value extends RouterRecord ? inferReactQueryProcedureOptionsInner<TRoot, $Value> : never : never };
|
||||
type inferReactQueryProcedureOptions<TRouter extends AnyRouter> = inferReactQueryProcedureOptionsInner<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
//#endregion
|
||||
//#region src/shared/proxy/utilsProxy.d.ts
|
||||
type DecorateQueryProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts: DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): UndefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts: DefinedTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): DefinedTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure>, opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UndefinedTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): UndefinedTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery
|
||||
*/
|
||||
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureData(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
||||
*/
|
||||
invalidate(input?: DeepPartial<inferProcedureInput<TProcedure>>, filters?: Omit<InvalidateQueryFilters, 'predicate'> & {
|
||||
predicate?: (query: Query<inferProcedureOutput<TProcedure>, TRPCClientError<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure>, QueryKeyKnown<inferProcedureInput<TProcedure>, inferProcedureInput<TProcedure> extends {
|
||||
cursor?: any;
|
||||
} | void ? 'infinite' : 'query'>>) => boolean;
|
||||
}, options?: InvalidateOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetch(input?: inferProcedureInput<TProcedure>, filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries
|
||||
*/
|
||||
cancel(input?: inferProcedureInput<TProcedure>, options?: CancelOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
reset(input?: inferProcedureInput<TProcedure>, options?: ResetOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>, updater: Updater<inferTransformedProcedureOutput<TRoot, TProcedure> | undefined, inferTransformedProcedureOutput<TRoot, TProcedure> | undefined>, options?: SetDataOptions): void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueriesData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>, filters: QueryFilters, updater: Updater<inferTransformedProcedureOutput<TRoot, TProcedure> | undefined, inferTransformedProcedureOutput<TRoot, TProcedure> | undefined>, options?: SetDataOptions): [QueryKey, inferTransformedProcedureOutput<TRoot, TProcedure>];
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteData(input: inferProcedureInput<TProcedure>, updater: Updater<InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined, InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined>, options?: SetDataOptions): void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getData(input?: inferProcedureInput<TProcedure>): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined;
|
||||
};
|
||||
type DecorateMutationProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyMutationProcedure> = {
|
||||
setMutationDefaults<TMeta = unknown>(options: InferMutationOptions<TRoot, TProcedure, TMeta> | ((args: {
|
||||
canonicalMutationFn: NonNullable<InferMutationOptions<TRoot, TProcedure>['mutationFn']>;
|
||||
}) => InferMutationOptions<TRoot, TProcedure, TMeta>)): void;
|
||||
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
||||
isMutating(): number;
|
||||
};
|
||||
/**
|
||||
* this is the type that is used to add in procedures that can be used on
|
||||
* an entire router
|
||||
*/
|
||||
type DecorateRouter = {
|
||||
/**
|
||||
* Invalidate the full router
|
||||
* @see https://trpc.io/docs/v10/useContext#query-invalidation
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidate(input?: undefined, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedProcedureUtilsRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = DecorateRouter & { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? DecorateQueryProcedure<TRoot, $Value> : $Value extends AnyMutationProcedure ? DecorateMutationProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : never : never };
|
||||
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> & DecorateMutationProcedure<any, any>;
|
||||
type CreateReactUtils<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
||||
type CreateQueryUtils<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
declare const getQueryType: (utilName: keyof AnyDecoratedProcedure) => QueryType;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(context: TRPCContextState<AnyRouter, TSSRContext>): ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createQueryUtilsProxy<TRouter extends AnyRouter>(context: TRPCQueryUtils<TRouter>): CreateQueryUtils<TRouter>;
|
||||
//#endregion
|
||||
//#region src/shared/proxy/useQueriesProxy.d.ts
|
||||
type GetQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(input: inferProcedureInput<TProcedure>, opts?: TrpcQueryOptionsForUseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>) => TrpcQueryOptionsForUseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueriesProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? GetQueryOptions<TRoot, $Value> : $Value extends RouterRecord ? UseQueriesProcedureRecord<TRoot, $Value> : never : never };
|
||||
type GetSuspenseQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(input: inferProcedureInput<TProcedure>, opts?: TrpcQueryOptionsForUseSuspenseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>) => TrpcQueryOptionsForUseSuspenseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseSuspenseQueriesProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? GetSuspenseQueryOptions<TRoot, $Value> : $Value extends RouterRecord ? UseSuspenseQueriesProcedureRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* Create proxy for `useQueries` options
|
||||
* @internal
|
||||
*/
|
||||
declare function createUseQueries<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>): UseQueriesProcedureRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
||||
//#endregion
|
||||
//#region src/shared/queryClient.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type CreateTRPCReactQueryClientConfig = {
|
||||
queryClient?: QueryClient;
|
||||
queryClientConfig?: never;
|
||||
} | {
|
||||
queryClientConfig?: QueryClientConfig;
|
||||
queryClient?: never;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare const getQueryClient: (config: CreateTRPCReactQueryClientConfig) => QueryClient;
|
||||
//# sourceMappingURL=queryClient.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/mutationLike.d.ts
|
||||
/**
|
||||
* Use to describe a mutation route which matches a given mutation procedure's interface
|
||||
*/
|
||||
type MutationLike<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
useMutation: (opts?: InferMutationOptions<TRoot, TProcedure>) => InferMutationResult<TRoot, TProcedure>;
|
||||
};
|
||||
/**
|
||||
* Use to unwrap a MutationLike's input
|
||||
*/
|
||||
type InferMutationLikeInput<TMutationLike extends MutationLike<any, any>> = TMutationLike extends MutationLike<any, infer $Procedure> ? inferProcedureInput<$Procedure> : never;
|
||||
/**
|
||||
* Use to unwrap a MutationLike's data output
|
||||
*/
|
||||
type InferMutationLikeData<TMutationLike extends MutationLike<any, any>> = TMutationLike extends MutationLike<infer TRoot, infer TProcedure> ? inferTransformedProcedureOutput<TRoot, TProcedure> : never;
|
||||
//# sourceMappingURL=mutationLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/queryLike.d.ts
|
||||
/**
|
||||
* Use to request a query route which matches a given query procedure's interface
|
||||
*/
|
||||
type QueryLike<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
useQuery: (variables: inferProcedureInput<TProcedure>, opts?: InferQueryOptions<TRoot, TProcedure, any>) => InferQueryResult<TRoot, TProcedure>;
|
||||
useSuspenseQuery: (variables: inferProcedureInput<TProcedure>, opts?: InferQueryOptions<TRoot, TProcedure, any>) => UseTRPCSuspenseQueryResult<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRoot>>;
|
||||
};
|
||||
/**
|
||||
* Use to unwrap a QueryLike's input
|
||||
*/
|
||||
type InferQueryLikeInput<TQueryLike> = TQueryLike extends DecoratedQuery<infer $Def> ? $Def['input'] : TQueryLike extends QueryLike<any, infer TProcedure> ? inferProcedureInput<TProcedure> : never;
|
||||
/**
|
||||
* Use to unwrap a QueryLike's data output
|
||||
*/
|
||||
type InferQueryLikeData<TQueryLike> = TQueryLike extends DecoratedQuery<infer $Def> ? $Def['output'] : TQueryLike extends QueryLike<infer TRoot, infer TProcedure> ? inferTransformedProcedureOutput<TRoot, TProcedure> : never;
|
||||
//# sourceMappingURL=queryLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/routerLike.d.ts
|
||||
/**
|
||||
* Use to describe a route path which matches a given route's interface
|
||||
*/
|
||||
type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
type RouterLikeInner<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? QueryLike<TRoot, $Value> : $Value extends AnyMutationProcedure ? MutationLike<TRoot, $Value> : $Value extends RouterRecord ? RouterLikeInner<TRoot, $Value> : never : never };
|
||||
//# sourceMappingURL=routerLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/utilsLike.d.ts
|
||||
/**
|
||||
* Use to describe a Utils/Context path which matches the given route's interface
|
||||
*/
|
||||
type UtilsLike<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
//# sourceMappingURL=utilsLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/internals/getClientArgs.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function getClientArgs<TOptions>(queryKey: TRPCQueryKey, opts: TOptions, infiniteParams?: {
|
||||
pageParam: any;
|
||||
direction: 'forward' | 'backward';
|
||||
}): readonly [string, unknown, any];
|
||||
//# sourceMappingURL=getClientArgs.d.ts.map
|
||||
//#endregion
|
||||
//#region src/internals/useQueries.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueryOptionsForUseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = DistributiveOmit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueryOptionsForUseSuspenseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = DistributiveOmit<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TrpcQueryOptionsForUseQueries<TOutput, TData, TError> = DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TrpcQueryOptionsForUseSuspenseQueries<TOutput, TData, TError> = DistributiveOmit<UseTRPCSuspenseQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare type QueriesResults<TQueriesOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[]> = { [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, any> ? UseTRPCQueryResult<unknown extends TData ? TQueryFnData : TData, TError> : never };
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare type SuspenseQueriesResults<TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>[]> = [{ [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, any, infer TData, any> ? unknown extends TData ? TQueryFnData : TData : never }, { [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, infer TError, infer TData, any> ? UseSuspenseQueryResult<unknown extends TData ? TQueryFnData : TData, TError> : never }];
|
||||
type GetOptions<TQueryOptions> = TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any> ? TQueryOptions : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type QueriesOptions<TQueriesOptions extends any[], TResult extends any[] = []> = TQueriesOptions extends [] ? [] : TQueriesOptions extends [infer Head] ? [...TResult, GetOptions<Head>] : TQueriesOptions extends [infer Head, ...infer Tail] ? QueriesOptions<Tail, [...TResult, GetOptions<Head>]> : unknown[] extends TQueriesOptions ? TQueriesOptions : TQueriesOptions extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptionsForUseQueries[];
|
||||
type GetSuspenseOptions<TQueryOptions> = TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any> ? TQueryOptions : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type SuspenseQueriesOptions<TQueriesOptions extends any[], TResult extends any[] = []> = TQueriesOptions extends [] ? [] : TQueriesOptions extends [infer Head] ? [...TResult, GetSuspenseOptions<Head>] : TQueriesOptions extends [infer Head, ...infer Tail] ? SuspenseQueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]> : unknown[] extends TQueriesOptions ? TQueriesOptions : TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptionsForUseSuspenseQueries<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptionsForUseSuspenseQueries[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TRPCUseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[], TCombinedResult = QueriesResults<TQueryOptions>>(queriesCallback: (t: UseQueriesProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => readonly [...QueriesOptions<TQueryOptions>], options?: {
|
||||
combine?: (results: QueriesResults<TQueryOptions>) => TCombinedResult;
|
||||
}) => TCombinedResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TRPCUseSuspenseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>[]>(queriesCallback: (t: UseSuspenseQueriesProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => readonly [...SuspenseQueriesOptions<TQueryOptions>]) => SuspenseQueriesResults<TQueryOptions>;
|
||||
//#endregion
|
||||
//#region src/createTRPCReact.d.ts
|
||||
type ResolverDef = {
|
||||
input: any;
|
||||
output: any;
|
||||
transformer: boolean;
|
||||
errorShape: any;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface ProcedureUseQuery<TDef extends ResolverDef> {
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'] | SkipToken, opts: DefinedUseTRPCQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>, TDef['output']>): DefinedUseTRPCQueryResult<TData, TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>>;
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'] | SkipToken, opts?: UseTRPCQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<TDef>, TDef['output']>): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (input: TDef['input'] | SkipToken, opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>) => void;
|
||||
/**
|
||||
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
||||
*/
|
||||
type CursorInput = {
|
||||
cursor?: any;
|
||||
} | void;
|
||||
type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
|
||||
type InfiniteInput<TInput> = Omit<TInput, ReservedInfiniteQueryKeys> | SkipToken;
|
||||
type inferCursorType<TInput> = TInput extends {
|
||||
cursor?: any;
|
||||
} ? TInput['cursor'] : unknown;
|
||||
type makeInfiniteQueryOptions<TCursor, TOptions> = Omit<TOptions, 'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'> & TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: TCursor;
|
||||
};
|
||||
type trpcInfiniteData<TDef extends ResolverDef> = Simplify<InfiniteData<TDef['output'], inferCursorType<TDef['input']>>>;
|
||||
interface useTRPCInfiniteQuery<TDef extends ResolverDef> {
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, DefinedInitialDataInfiniteOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts?: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UndefinedInitialDataInfiniteOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts?: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UseInfiniteQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = (input: InfiniteInput<TDef['input']>, opts: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UseSuspenseInfiniteQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>, trpcInfiniteData<TDef>, any, inferCursorType<TDef['input']>>>) => [trpcInfiniteData<TDef>, TRPCHookResult & UseSuspenseInfiniteQueryResult<trpcInfiniteData<TDef>, TRPCClientErrorLike<TDef>>];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> = TDef['input'] extends CursorInput ? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useInfiniteQuery
|
||||
*/
|
||||
useInfiniteQuery: useTRPCInfiniteQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery
|
||||
*/
|
||||
useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;
|
||||
usePrefetchInfiniteQuery: (input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken, opts: TRPCFetchInfiniteQueryOptions<TDef['input'], TDef['output'], TRPCClientErrorLike<TDef>>) => void;
|
||||
} : object;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useQuery
|
||||
*/
|
||||
useQuery: ProcedureUseQuery<TDef>;
|
||||
usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
|
||||
*/
|
||||
useSuspenseQuery: <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'], opts?: UseTRPCSuspenseQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<TDef>>) => [TData, UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult];
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedQuery<TDef extends ResolverDef> = MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;
|
||||
type DecoratedMutation<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useMutation
|
||||
*/
|
||||
useMutation: <TContext = unknown>(opts?: UseTRPCMutationOptions<TDef['input'], TRPCClientErrorLike<TDef>, TDef['output'], TContext>) => UseTRPCMutationResult<TDef['output'], TRPCClientErrorLike<TDef>, TDef['input'], TContext>;
|
||||
};
|
||||
interface ProcedureUseSubscription<TDef extends ResolverDef> {
|
||||
(input: TDef['input'], opts?: UseTRPCSubscriptionOptions<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>): TRPCSubscriptionResult<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
||||
(input: TDef['input'] | SkipToken, opts?: Omit<UseTRPCSubscriptionOptions<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>, 'enabled'>): TRPCSubscriptionResult<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecorateProcedure<TType extends ProcedureType, TDef extends ResolverDef> = TType extends 'query' ? DecoratedQuery<TDef> : TType extends 'mutation' ? DecoratedMutation<TDef> : TType extends 'subscription' ? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/subscriptions
|
||||
*/
|
||||
useSubscription: ProcedureUseSubscription<TDef>;
|
||||
} : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
|
||||
input: inferProcedureInput<$Value>;
|
||||
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
||||
transformer: TRoot['transformer'];
|
||||
errorShape: TRoot['errorShape'];
|
||||
}> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
||||
/**
|
||||
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
||||
*
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
Provider: TRPCProvider<TRouter, TSSRContext>;
|
||||
createClient: typeof createTRPCClient<TRouter>;
|
||||
useQueries: TRPCUseQueries<TRouter>;
|
||||
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
||||
};
|
||||
type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<CreateTRPCReactBase<TRouter, TSSRContext>, DecorateRouterRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
||||
declare function createTRPCReact<TRouter extends AnyRouter, TSSRContext = unknown>(opts?: CreateTRPCReactOptions<TRouter>): CreateTRPCReact<TRouter, TSSRContext>;
|
||||
//#endregion
|
||||
//#region src/internals/getQueryKey.d.ts
|
||||
type QueryType = 'any' | 'infinite' | 'query';
|
||||
type TRPCQueryKey = [readonly string[], {
|
||||
input?: unknown;
|
||||
type?: Exclude<QueryType, 'any'>;
|
||||
}?];
|
||||
type TRPCMutationKey = [readonly string[]];
|
||||
type ProcedureOrRouter = DecoratedMutation<any> | DecoratedQuery<any> | DecorateRouterRecord<any, any>;
|
||||
/**
|
||||
* To allow easy interactions with groups of related queries, such as
|
||||
* invalidating all queries of a router, we use an array as the path when
|
||||
* storing in tanstack query.
|
||||
**/
|
||||
|
||||
type GetInfiniteQueryInput<TProcedureInput, TInputWithoutCursorAndDirection = Omit<TProcedureInput, 'cursor' | 'direction'>> = keyof TInputWithoutCursorAndDirection extends never ? undefined : DeepPartial<TInputWithoutCursorAndDirection> | undefined;
|
||||
/** @internal */
|
||||
type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
||||
cursor?: any;
|
||||
} ? GetInfiniteQueryInput<TProcedureInput> : DeepPartial<TProcedureInput> | undefined;
|
||||
type GetParams<TProcedureOrRouter extends ProcedureOrRouter> = TProcedureOrRouter extends DecoratedQuery<infer $Def> ? [input?: GetQueryProcedureInput<$Def['input']>, type?: QueryType] : [];
|
||||
/**
|
||||
* Method to extract the query key for a procedure
|
||||
* @param procedureOrRouter - procedure or AnyRouter
|
||||
* @param input - input to procedureOrRouter
|
||||
* @param type - defaults to `any`
|
||||
* @see https://trpc.io/docs/v11/getQueryKey
|
||||
*/
|
||||
declare function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(procedureOrRouter: TProcedureOrRouter, ..._params: GetParams<TProcedureOrRouter>): TRPCQueryKey;
|
||||
type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [string[], {
|
||||
input?: GetQueryProcedureInput<TInput>;
|
||||
type: TType;
|
||||
}?];
|
||||
/**
|
||||
* Method to extract the mutation key for a procedure
|
||||
* @param procedure - procedure
|
||||
* @see https://trpc.io/docs/v11/getQueryKey#mutations
|
||||
*/
|
||||
declare function getMutationKey<TProcedure extends DecoratedMutation<any>>(procedure: TProcedure): TRPCMutationKey;
|
||||
//#endregion
|
||||
export { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReact, CreateTRPCReactBase, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createTRPCReact, createUseQueries, getClientArgs, getMutationKey, getQueryClient, getQueryKey, getQueryType, inferReactQueryProcedureOptions };
|
||||
//# sourceMappingURL=getQueryKey.d-C_PnqPni.d.cts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+892
@@ -0,0 +1,892 @@
|
||||
import * as _trpc_client1 from "@trpc/client";
|
||||
import { CreateTRPCClientOptions, TRPCClient, TRPCClientError, TRPCClientErrorLike, TRPCRequestOptions, TRPCUntypedClient, createTRPCClient } from "@trpc/client";
|
||||
import { CancelOptions, DataTag, DefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InfiniteQueryObserverSuccessResult, InitialDataFunction, InvalidateOptions, InvalidateQueryFilters, MutationOptions, Query, QueryClient, QueryClientConfig, QueryFilters, QueryKey, QueryObserverSuccessResult, QueryOptions, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, SkipToken, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UnusedSkipTokenInfiniteOptions, UnusedSkipTokenOptions, Updater, UseBaseQueryOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query";
|
||||
import { AnyClientTypes, AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, DistributiveOmit, MaybePromise, ProcedureType, ProtectedIntersection, RouterRecord, Simplify, coerceAsyncIterableToArray, inferAsyncIterableYield, inferProcedureInput, inferProcedureOutput, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
|
||||
import * as React$1 from "react";
|
||||
import { JSX, ReactNode } from "react";
|
||||
|
||||
//#region src/internals/context.d.ts
|
||||
interface TRPCUseUtilsOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCRequestOptions;
|
||||
}
|
||||
interface TRPCFetchQueryOptions<TOutput, TError> extends DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'>, TRPCUseUtilsOptions {}
|
||||
type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, TRPCQueryKey, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCUseUtilsOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
/** @internal */
|
||||
type SSRState = 'mounted' | 'mounting' | 'prepass' | false;
|
||||
interface TRPCContextPropsBase<TRouter extends AnyRouter, TSSRContext> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The SSR context when server-side rendering
|
||||
* @default null
|
||||
*/
|
||||
ssrContext?: TSSRContext | null;
|
||||
/**
|
||||
* State of SSR hydration.
|
||||
* - `false` if not using SSR.
|
||||
* - `prepass` when doing a prepass to fetch queries' data
|
||||
* - `mounting` before TRPCProvider has been rendered on the client
|
||||
* - `mounted` when the TRPCProvider has been rendered on the client
|
||||
* @default false
|
||||
*/
|
||||
ssrState?: SSRState;
|
||||
/**
|
||||
* @deprecated pass abortOnUnmount to `createTRPCReact` instead
|
||||
* Abort loading query calls when unmounting a component - usually when navigating to a new page
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedTRPCContextProps<TRouter extends AnyRouter, TSSRContext> = TRPCContextPropsBase<TRouter, TSSRContext> & {
|
||||
client: TRPCClient<TRouter>;
|
||||
};
|
||||
interface TRPCContextProps<TRouter extends AnyRouter, TSSRContext> extends TRPCContextPropsBase<TRouter, TSSRContext> {
|
||||
/**
|
||||
* The react-query `QueryClient`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
declare const contextProps: (keyof TRPCContextPropsBase<any, any>)[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface TRPCContextState<TRouter extends AnyRouter, TSSRContext = undefined> extends Required<TRPCContextProps<TRouter, TSSRContext>>, TRPCQueryUtils<TRouter> {}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts?: UndefinedTRPCQueryOptionsIn<unknown, unknown, TRPCClientError<AnyClientTypes>>): UndefinedTRPCQueryOptionsOut<unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
queryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: DefinedTRPCQueryOptionsIn<unknown, unknown, TRPCClientError<AnyClientTypes>>): DefinedTRPCQueryOptionsOut<unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: UndefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>): UndefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
infiniteQueryOptions(path: readonly string[],
|
||||
// <-- look into if needed
|
||||
queryKey: TRPCQueryKey, opts: DefinedTRPCInfiniteQueryOptionsIn<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>): DefinedTRPCInfiniteQueryOptionsOut<unknown, unknown, unknown, TRPCClientError<AnyClientTypes>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<InfiniteData<unknown, unknown>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
||||
*/
|
||||
prefetchQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfiniteQuery: (queryKey: TRPCQueryKey, opts?: TRPCFetchInfiniteQueryOptions<unknown, unknown, TRPCClientError<TRouter>>) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureQueryData: (queryKey: TRPCQueryKey, opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>) => Promise<unknown>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidateQueries: (queryKey: TRPCQueryKey, filters?: InvalidateQueryFilters<TRPCQueryKey>, options?: InvalidateOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
resetQueries: (queryKey: TRPCQueryKey, filters?: QueryFilters<TRPCQueryKey>, options?: ResetOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetchQueries: (queryKey: TRPCQueryKey, filters?: RefetchQueryFilters<TRPCQueryKey>, options?: RefetchOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
|
||||
*/
|
||||
cancelQuery: (queryKey: TRPCQueryKey, options?: CancelOptions) => Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueryData: (queryKey: TRPCQueryKey, updater: Updater<unknown, unknown>, options?: SetDataOptions) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
|
||||
*/
|
||||
setQueriesData: (queryKey: TRPCQueryKey, filters: QueryFilters, updater: Updater<unknown, unknown>, options?: SetDataOptions) => [QueryKey, unknown][];
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getQueryData: (queryKey: TRPCQueryKey) => unknown;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteQueryData: (queryKey: TRPCQueryKey, updater: Updater<InfiniteData<unknown> | undefined, InfiniteData<unknown> | undefined>, options?: SetDataOptions) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteQueryData: (queryKey: TRPCQueryKey) => InfiniteData<unknown> | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
|
||||
*/
|
||||
setMutationDefaults: (mutationKey: TRPCMutationKey, options: MutationOptions | ((args: {
|
||||
canonicalMutationFn: (input: unknown) => Promise<unknown>;
|
||||
}) => MutationOptions)) => void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
|
||||
*/
|
||||
getMutationDefaults: (mutationKey: TRPCMutationKey) => MutationOptions | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
|
||||
*/
|
||||
isMutating: (filters: {
|
||||
mutationKey: TRPCMutationKey;
|
||||
}) => number;
|
||||
}
|
||||
declare const TRPCContext: React$1.Context<any>;
|
||||
//#endregion
|
||||
//#region src/shared/hooks/types.d.ts
|
||||
type OutputWithCursor<TData, TCursor = any> = {
|
||||
cursor: TCursor | null;
|
||||
data: TData;
|
||||
};
|
||||
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
||||
/**
|
||||
* Opt out of SSR for this query by passing `ssr: false`
|
||||
*/
|
||||
ssr?: boolean;
|
||||
/**
|
||||
* Opt out or into aborting request on unmount
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
interface TRPCUseQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
interface UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError> extends DistributiveOmit<UseSuspenseQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError> extends DistributiveOmit<FetchQueryOptions<TOutput, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {}
|
||||
/** @internal **/
|
||||
interface DefinedUseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData = TOutput> extends DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData>, 'queryKey'> {
|
||||
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
|
||||
}
|
||||
interface TRPCQueryOptions<TData, TError> extends DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>, TRPCUseQueryBaseOptions {
|
||||
queryKey: TRPCQueryKey;
|
||||
}
|
||||
type ExtractCursorType<TInput> = TInput extends {
|
||||
cursor?: any;
|
||||
} ? TInput['cursor'] : unknown;
|
||||
interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError> extends DistributiveOmit<UseSuspenseInfiniteQueryOptions<TOutput, TError, TOutput, any, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'>, TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
interface UseTRPCMutationOptions<TInput, TError, TOutput, TContext = unknown> extends UseMutationOptions<TOutput, TError, TInput, TContext>, TRPCUseQueryBaseOptions {}
|
||||
interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
||||
/**
|
||||
* @deprecated
|
||||
* use a `skipToken` from `@tanstack/react-query` instead
|
||||
* this will be removed in v12
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Called when the subscription is started
|
||||
*/
|
||||
onStarted?: () => void;
|
||||
/**
|
||||
* Called when new data is received
|
||||
*/
|
||||
onData?: (data: TOutput) => void;
|
||||
/**
|
||||
* Called when an **unrecoverable error** occurs and the subscription is closed
|
||||
*/
|
||||
onError?: (err: TError) => void;
|
||||
/**
|
||||
* Called when the subscription is completed on the server
|
||||
*/
|
||||
onComplete?: () => void;
|
||||
}
|
||||
interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'idle' | 'connecting' | 'pending' | 'error';
|
||||
data: undefined | TOutput;
|
||||
error: null | TError;
|
||||
/**
|
||||
* Reset the subscription
|
||||
*/
|
||||
reset: () => void;
|
||||
}
|
||||
interface TRPCSubscriptionIdleResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, null> {
|
||||
status: 'idle';
|
||||
data: undefined;
|
||||
error: null;
|
||||
}
|
||||
interface TRPCSubscriptionConnectingResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'connecting';
|
||||
data: undefined | TOutput;
|
||||
error: TError | null;
|
||||
}
|
||||
interface TRPCSubscriptionPendingResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
||||
status: 'pending';
|
||||
data: TOutput | undefined;
|
||||
error: null;
|
||||
}
|
||||
interface TRPCSubscriptionErrorResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'error';
|
||||
data: TOutput | undefined;
|
||||
error: TError;
|
||||
}
|
||||
type TRPCSubscriptionResult<TOutput, TError> = TRPCSubscriptionIdleResult<TOutput> | TRPCSubscriptionConnectingResult<TOutput, TError> | TRPCSubscriptionErrorResult<TOutput, TError> | TRPCSubscriptionPendingResult<TOutput>;
|
||||
interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext> extends Omit<TRPCContextProps<TRouter, TSSRContext>, 'client'> {
|
||||
children: ReactNode;
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (props: TRPCProviderProps<TRouter, TSSRContext>) => JSX.Element;
|
||||
type CreateClient<TRouter extends AnyRouter> = (opts: CreateTRPCClientOptions<TRouter>) => TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCQueryResult<TData, TError> = TRPCHookResult & UseQueryResult<coerceAsyncIterableToArray<TData>, TError>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DefinedUseTRPCQueryResult<TData, TError> = DefinedUseQueryResult<TData, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCQuerySuccessResult<TData, TError> = QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCSuspenseQueryResult<TData, TError> = [TData, UseSuspenseQueryResult<TData, TError> & TRPCHookResult];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult & UseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> = InfiniteQueryObserverSuccessResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, UseSuspenseInfiniteQueryResult<InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TError> & TRPCHookResult];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseTRPCMutationResult<TData, TError, TVariables, TContext> = TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
|
||||
interface TRPCHookResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/types.d.ts
|
||||
interface TRPCQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
interface TRPCQueryOptionsResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
type TRPCOptionOverrides = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
||||
type TRPCInfiniteOptionOverrides = TRPCOptionOverrides | 'initialPageParam';
|
||||
/**
|
||||
* QueryOptions API helpers
|
||||
*/
|
||||
interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>, TError>;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCOptionOverrides>, TRPCQueryBaseOptions {}
|
||||
interface UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
/**
|
||||
* InifiniteQueryOptions helpers
|
||||
*/
|
||||
interface UndefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UndefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface DefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface DefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, TRPCInfiniteOptionOverrides>, TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface UseMutationOverride {
|
||||
onSuccess: (opts: {
|
||||
/**
|
||||
* Calls the original function that was defined in the query's `onSuccess` option
|
||||
*/
|
||||
originalFn: () => MaybePromise<void>;
|
||||
queryClient: QueryClient;
|
||||
/**
|
||||
* Meta data passed in from the `useMutation()` hook
|
||||
*/
|
||||
meta: Record<string, unknown>;
|
||||
}) => MaybePromise<void>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
||||
/**
|
||||
* Override behaviors of the built-in hooks
|
||||
*/
|
||||
overrides?: {
|
||||
useMutation?: Partial<UseMutationOverride>;
|
||||
};
|
||||
/**
|
||||
* Abort all queries when unmounting
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
/**
|
||||
* Override the default context provider
|
||||
* @default undefined
|
||||
*/
|
||||
context?: React.Context<any>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/shared/hooks/createHooksInternal.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createRootHooks<TRouter extends AnyRouter, TSSRContext = unknown>(config?: CreateTRPCReactOptions<TRouter>): {
|
||||
Provider: TRPCProvider<TRouter, TSSRContext>;
|
||||
createClient: (opts: _trpc_client1.CreateTRPCClientOptions<TRouter>) => _trpc_client1.TRPCClient<TRouter>;
|
||||
useContext: () => TRPCContextState<TRouter, TSSRContext>;
|
||||
useUtils: () => TRPCContextState<TRouter, TSSRContext>;
|
||||
useQuery: (path: readonly string[], input: unknown, opts?: UseTRPCQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCQueryResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
usePrefetchQuery: (path: string[], input: unknown, opts?: UseTRPCPrefetchQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => void;
|
||||
useSuspenseQuery: (path: readonly string[], input: unknown, opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseQueryResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
useQueries: TRPCUseQueries<TRouter>;
|
||||
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
||||
useMutation: (path: readonly string[], opts?: UseTRPCMutationOptions<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>) => UseTRPCMutationResult<unknown, TRPCClientErrorLike<TRouter>, unknown, unknown>;
|
||||
useSubscription: (path: readonly string[], input: unknown, opts: UseTRPCSubscriptionOptions<unknown, TRPCClientErrorLike<TRouter>>) => TRPCSubscriptionResult<unknown, TRPCClientErrorLike<TRouter>>;
|
||||
useInfiniteQuery: (path: readonly string[], input: unknown, opts: UseTRPCInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>;
|
||||
usePrefetchInfiniteQuery: (path: string[], input: unknown, opts: UseTRPCPrefetchInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => void;
|
||||
useSuspenseInfiniteQuery: (path: readonly string[], input: unknown, opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, TRPCClientErrorLike<TRouter>>) => UseTRPCSuspenseInfiniteQueryResult<unknown, TRPCClientErrorLike<TRouter>, unknown>;
|
||||
};
|
||||
/**
|
||||
* Infer the type of a `createReactQueryHooks` function
|
||||
* @internal
|
||||
*/
|
||||
type CreateReactQueryHooks<TRouter extends AnyRouter, TSSRContext = unknown> = ReturnType<typeof createRootHooks<TRouter, TSSRContext>>;
|
||||
//# sourceMappingURL=createHooksInternal.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/proxy/decorationProxy.d.ts
|
||||
/**
|
||||
* Create proxy for decorating procedures
|
||||
* @internal
|
||||
*/
|
||||
declare function createReactDecoration<TRouter extends AnyRouter, TSSRContext = unknown>(hooks: CreateReactQueryHooks<TRouter, TSSRContext>): unknown;
|
||||
//# sourceMappingURL=decorationProxy.d.ts.map
|
||||
//#endregion
|
||||
//#region src/utils/inferReactQueryProcedure.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TData = inferTransformedProcedureOutput<TRoot, TProcedure>> = Omit<UseTRPCQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, TData>, 'select' | 'queryFn'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferMutationOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TMeta = unknown> = UseTRPCMutationOptions<inferProcedureInput<TProcedure>, TRPCClientErrorLike<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure>, TMeta>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferQueryResult<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = UseTRPCQueryResult<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type InferMutationResult<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TContext = unknown> = UseTRPCMutationResult<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, inferProcedureInput<TProcedure>, TContext>;
|
||||
type inferReactQueryProcedureOptionsInner<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? InferQueryOptions<TRoot, $Value> : $Value extends AnyMutationProcedure ? InferMutationOptions<TRoot, $Value> : $Value extends RouterRecord ? inferReactQueryProcedureOptionsInner<TRoot, $Value> : never : never };
|
||||
type inferReactQueryProcedureOptions<TRouter extends AnyRouter> = inferReactQueryProcedureOptionsInner<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
//#endregion
|
||||
//#region src/shared/proxy/utilsProxy.d.ts
|
||||
type DecorateQueryProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts: DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientError<TRoot>>): UndefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts: DefinedTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): DefinedTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure>, opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>, TData = TQueryFnData>(input: inferProcedureInput<TProcedure> | SkipToken, opts?: UndefinedTRPCInfiniteQueryOptionsIn<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>): UndefinedTRPCInfiniteQueryOptionsOut<inferProcedureInput<TProcedure>, TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery
|
||||
*/
|
||||
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureData(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientError<TRoot>>): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
||||
*/
|
||||
invalidate(input?: DeepPartial<inferProcedureInput<TProcedure>>, filters?: Omit<InvalidateQueryFilters, 'predicate'> & {
|
||||
predicate?: (query: Query<inferProcedureOutput<TProcedure>, TRPCClientError<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure>, QueryKeyKnown<inferProcedureInput<TProcedure>, inferProcedureInput<TProcedure> extends {
|
||||
cursor?: any;
|
||||
} | void ? 'infinite' : 'query'>>) => boolean;
|
||||
}, options?: InvalidateOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetch(input?: inferProcedureInput<TProcedure>, filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries
|
||||
*/
|
||||
cancel(input?: inferProcedureInput<TProcedure>, options?: CancelOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
reset(input?: inferProcedureInput<TProcedure>, options?: ResetOptions): Promise<void>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>, updater: Updater<inferTransformedProcedureOutput<TRoot, TProcedure> | undefined, inferTransformedProcedureOutput<TRoot, TProcedure> | undefined>, options?: SetDataOptions): void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueriesData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>, filters: QueryFilters, updater: Updater<inferTransformedProcedureOutput<TRoot, TProcedure> | undefined, inferTransformedProcedureOutput<TRoot, TProcedure> | undefined>, options?: SetDataOptions): [QueryKey, inferTransformedProcedureOutput<TRoot, TProcedure>];
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteData(input: inferProcedureInput<TProcedure>, updater: Updater<InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined, InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined>, options?: SetDataOptions): void;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getData(input?: inferProcedureInput<TProcedure>): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined;
|
||||
};
|
||||
type DecorateMutationProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyMutationProcedure> = {
|
||||
setMutationDefaults<TMeta = unknown>(options: InferMutationOptions<TRoot, TProcedure, TMeta> | ((args: {
|
||||
canonicalMutationFn: NonNullable<InferMutationOptions<TRoot, TProcedure>['mutationFn']>;
|
||||
}) => InferMutationOptions<TRoot, TProcedure, TMeta>)): void;
|
||||
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
||||
isMutating(): number;
|
||||
};
|
||||
/**
|
||||
* this is the type that is used to add in procedures that can be used on
|
||||
* an entire router
|
||||
*/
|
||||
type DecorateRouter = {
|
||||
/**
|
||||
* Invalidate the full router
|
||||
* @see https://trpc.io/docs/v10/useContext#query-invalidation
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidate(input?: undefined, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedProcedureUtilsRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = DecorateRouter & { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? DecorateQueryProcedure<TRoot, $Value> : $Value extends AnyMutationProcedure ? DecorateMutationProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : never : never };
|
||||
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> & DecorateMutationProcedure<any, any>;
|
||||
type CreateReactUtils<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
||||
type CreateQueryUtils<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
declare const getQueryType: (utilName: keyof AnyDecoratedProcedure) => QueryType;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(context: TRPCContextState<AnyRouter, TSSRContext>): ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function createQueryUtilsProxy<TRouter extends AnyRouter>(context: TRPCQueryUtils<TRouter>): CreateQueryUtils<TRouter>;
|
||||
//#endregion
|
||||
//#region src/shared/proxy/useQueriesProxy.d.ts
|
||||
type GetQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(input: inferProcedureInput<TProcedure>, opts?: TrpcQueryOptionsForUseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>) => TrpcQueryOptionsForUseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueriesProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? GetQueryOptions<TRoot, $Value> : $Value extends RouterRecord ? UseQueriesProcedureRecord<TRoot, $Value> : never : never };
|
||||
type GetSuspenseQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(input: inferProcedureInput<TProcedure>, opts?: TrpcQueryOptionsForUseSuspenseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>) => TrpcQueryOptionsForUseSuspenseQueries<inferTransformedProcedureOutput<TRoot, TProcedure>, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseSuspenseQueriesProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? GetSuspenseQueryOptions<TRoot, $Value> : $Value extends RouterRecord ? UseSuspenseQueriesProcedureRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* Create proxy for `useQueries` options
|
||||
* @internal
|
||||
*/
|
||||
declare function createUseQueries<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>): UseQueriesProcedureRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
||||
//#endregion
|
||||
//#region src/shared/queryClient.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type CreateTRPCReactQueryClientConfig = {
|
||||
queryClient?: QueryClient;
|
||||
queryClientConfig?: never;
|
||||
} | {
|
||||
queryClientConfig?: QueryClientConfig;
|
||||
queryClient?: never;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare const getQueryClient: (config: CreateTRPCReactQueryClientConfig) => QueryClient;
|
||||
//# sourceMappingURL=queryClient.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/mutationLike.d.ts
|
||||
/**
|
||||
* Use to describe a mutation route which matches a given mutation procedure's interface
|
||||
*/
|
||||
type MutationLike<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
useMutation: (opts?: InferMutationOptions<TRoot, TProcedure>) => InferMutationResult<TRoot, TProcedure>;
|
||||
};
|
||||
/**
|
||||
* Use to unwrap a MutationLike's input
|
||||
*/
|
||||
type InferMutationLikeInput<TMutationLike extends MutationLike<any, any>> = TMutationLike extends MutationLike<any, infer $Procedure> ? inferProcedureInput<$Procedure> : never;
|
||||
/**
|
||||
* Use to unwrap a MutationLike's data output
|
||||
*/
|
||||
type InferMutationLikeData<TMutationLike extends MutationLike<any, any>> = TMutationLike extends MutationLike<infer TRoot, infer TProcedure> ? inferTransformedProcedureOutput<TRoot, TProcedure> : never;
|
||||
//# sourceMappingURL=mutationLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/queryLike.d.ts
|
||||
/**
|
||||
* Use to request a query route which matches a given query procedure's interface
|
||||
*/
|
||||
type QueryLike<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
useQuery: (variables: inferProcedureInput<TProcedure>, opts?: InferQueryOptions<TRoot, TProcedure, any>) => InferQueryResult<TRoot, TProcedure>;
|
||||
useSuspenseQuery: (variables: inferProcedureInput<TProcedure>, opts?: InferQueryOptions<TRoot, TProcedure, any>) => UseTRPCSuspenseQueryResult<inferProcedureOutput<TProcedure>, TRPCClientErrorLike<TRoot>>;
|
||||
};
|
||||
/**
|
||||
* Use to unwrap a QueryLike's input
|
||||
*/
|
||||
type InferQueryLikeInput<TQueryLike> = TQueryLike extends DecoratedQuery<infer $Def> ? $Def['input'] : TQueryLike extends QueryLike<any, infer TProcedure> ? inferProcedureInput<TProcedure> : never;
|
||||
/**
|
||||
* Use to unwrap a QueryLike's data output
|
||||
*/
|
||||
type InferQueryLikeData<TQueryLike> = TQueryLike extends DecoratedQuery<infer $Def> ? $Def['output'] : TQueryLike extends QueryLike<infer TRoot, infer TProcedure> ? inferTransformedProcedureOutput<TRoot, TProcedure> : never;
|
||||
//# sourceMappingURL=queryLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/routerLike.d.ts
|
||||
/**
|
||||
* Use to describe a route path which matches a given route's interface
|
||||
*/
|
||||
type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
type RouterLikeInner<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? QueryLike<TRoot, $Value> : $Value extends AnyMutationProcedure ? MutationLike<TRoot, $Value> : $Value extends RouterRecord ? RouterLikeInner<TRoot, $Value> : never : never };
|
||||
//# sourceMappingURL=routerLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/shared/polymorphism/utilsLike.d.ts
|
||||
/**
|
||||
* Use to describe a Utils/Context path which matches the given route's interface
|
||||
*/
|
||||
type UtilsLike<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
||||
//# sourceMappingURL=utilsLike.d.ts.map
|
||||
//#endregion
|
||||
//#region src/internals/getClientArgs.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function getClientArgs<TOptions>(queryKey: TRPCQueryKey, opts: TOptions, infiniteParams?: {
|
||||
pageParam: any;
|
||||
direction: 'forward' | 'backward';
|
||||
}): readonly [string, unknown, any];
|
||||
//# sourceMappingURL=getClientArgs.d.ts.map
|
||||
//#endregion
|
||||
//#region src/internals/useQueries.d.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueryOptionsForUseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = DistributiveOmit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type UseQueryOptionsForUseSuspenseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = DistributiveOmit<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TrpcQueryOptionsForUseQueries<TOutput, TData, TError> = DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TrpcQueryOptionsForUseSuspenseQueries<TOutput, TData, TError> = DistributiveOmit<UseTRPCSuspenseQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare type QueriesResults<TQueriesOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[]> = { [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, any> ? UseTRPCQueryResult<unknown extends TData ? TQueryFnData : TData, TError> : never };
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare type SuspenseQueriesResults<TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>[]> = [{ [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, any, infer TData, any> ? unknown extends TData ? TQueryFnData : TData : never }, { [TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, infer TError, infer TData, any> ? UseSuspenseQueryResult<unknown extends TData ? TQueryFnData : TData, TError> : never }];
|
||||
type GetOptions<TQueryOptions> = TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any> ? TQueryOptions : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type QueriesOptions<TQueriesOptions extends any[], TResult extends any[] = []> = TQueriesOptions extends [] ? [] : TQueriesOptions extends [infer Head] ? [...TResult, GetOptions<Head>] : TQueriesOptions extends [infer Head, ...infer Tail] ? QueriesOptions<Tail, [...TResult, GetOptions<Head>]> : unknown[] extends TQueriesOptions ? TQueriesOptions : TQueriesOptions extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptionsForUseQueries[];
|
||||
type GetSuspenseOptions<TQueryOptions> = TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any> ? TQueryOptions : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type SuspenseQueriesOptions<TQueriesOptions extends any[], TResult extends any[] = []> = TQueriesOptions extends [] ? [] : TQueriesOptions extends [infer Head] ? [...TResult, GetSuspenseOptions<Head>] : TQueriesOptions extends [infer Head, ...infer Tail] ? SuspenseQueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]> : unknown[] extends TQueriesOptions ? TQueriesOptions : TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptionsForUseSuspenseQueries<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptionsForUseSuspenseQueries[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TRPCUseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[], TCombinedResult = QueriesResults<TQueryOptions>>(queriesCallback: (t: UseQueriesProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => readonly [...QueriesOptions<TQueryOptions>], options?: {
|
||||
combine?: (results: QueriesResults<TQueryOptions>) => TCombinedResult;
|
||||
}) => TCombinedResult;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type TRPCUseSuspenseQueries<TRouter extends AnyRouter> = <TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>[]>(queriesCallback: (t: UseSuspenseQueriesProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => readonly [...SuspenseQueriesOptions<TQueryOptions>]) => SuspenseQueriesResults<TQueryOptions>;
|
||||
//#endregion
|
||||
//#region src/createTRPCReact.d.ts
|
||||
type ResolverDef = {
|
||||
input: any;
|
||||
output: any;
|
||||
transformer: boolean;
|
||||
errorShape: any;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface ProcedureUseQuery<TDef extends ResolverDef> {
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'] | SkipToken, opts: DefinedUseTRPCQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>, TDef['output']>): DefinedUseTRPCQueryResult<TData, TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>>;
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'] | SkipToken, opts?: UseTRPCQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<TDef>, TDef['output']>): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (input: TDef['input'] | SkipToken, opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>) => void;
|
||||
/**
|
||||
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
||||
*/
|
||||
type CursorInput = {
|
||||
cursor?: any;
|
||||
} | void;
|
||||
type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
|
||||
type InfiniteInput<TInput> = Omit<TInput, ReservedInfiniteQueryKeys> | SkipToken;
|
||||
type inferCursorType<TInput> = TInput extends {
|
||||
cursor?: any;
|
||||
} ? TInput['cursor'] : unknown;
|
||||
type makeInfiniteQueryOptions<TCursor, TOptions> = Omit<TOptions, 'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'> & TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: TCursor;
|
||||
};
|
||||
type trpcInfiniteData<TDef extends ResolverDef> = Simplify<InfiniteData<TDef['output'], inferCursorType<TDef['input']>>>;
|
||||
interface useTRPCInfiniteQuery<TDef extends ResolverDef> {
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, DefinedInitialDataInfiniteOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts?: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UndefinedInitialDataInfiniteOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
<TData = trpcInfiniteData<TDef>>(input: InfiniteInput<TDef['input']>, opts?: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UseInfiniteQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>, TData, any, inferCursorType<TDef['input']>>>): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = (input: InfiniteInput<TDef['input']>, opts: makeInfiniteQueryOptions<inferCursorType<TDef['input']>, UseSuspenseInfiniteQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>, trpcInfiniteData<TDef>, any, inferCursorType<TDef['input']>>>) => [trpcInfiniteData<TDef>, TRPCHookResult & UseSuspenseInfiniteQueryResult<trpcInfiniteData<TDef>, TRPCClientErrorLike<TDef>>];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> = TDef['input'] extends CursorInput ? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useInfiniteQuery
|
||||
*/
|
||||
useInfiniteQuery: useTRPCInfiniteQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery
|
||||
*/
|
||||
useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;
|
||||
usePrefetchInfiniteQuery: (input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken, opts: TRPCFetchInfiniteQueryOptions<TDef['input'], TDef['output'], TRPCClientErrorLike<TDef>>) => void;
|
||||
} : object;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useQuery
|
||||
*/
|
||||
useQuery: ProcedureUseQuery<TDef>;
|
||||
usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
|
||||
*/
|
||||
useSuspenseQuery: <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(input: TDef['input'], opts?: UseTRPCSuspenseQueryOptions<TQueryFnData, TData, TRPCClientErrorLike<TDef>>) => [TData, UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult];
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedQuery<TDef extends ResolverDef> = MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;
|
||||
type DecoratedMutation<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useMutation
|
||||
*/
|
||||
useMutation: <TContext = unknown>(opts?: UseTRPCMutationOptions<TDef['input'], TRPCClientErrorLike<TDef>, TDef['output'], TContext>) => UseTRPCMutationResult<TDef['output'], TRPCClientErrorLike<TDef>, TDef['input'], TContext>;
|
||||
};
|
||||
interface ProcedureUseSubscription<TDef extends ResolverDef> {
|
||||
(input: TDef['input'], opts?: UseTRPCSubscriptionOptions<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>): TRPCSubscriptionResult<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
||||
(input: TDef['input'] | SkipToken, opts?: Omit<UseTRPCSubscriptionOptions<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>, 'enabled'>): TRPCSubscriptionResult<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecorateProcedure<TType extends ProcedureType, TDef extends ResolverDef> = TType extends 'query' ? DecoratedQuery<TDef> : TType extends 'mutation' ? DecoratedMutation<TDef> : TType extends 'subscription' ? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/subscriptions
|
||||
*/
|
||||
useSubscription: ProcedureUseSubscription<TDef>;
|
||||
} : never;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
|
||||
input: inferProcedureInput<$Value>;
|
||||
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
||||
transformer: TRoot['transformer'];
|
||||
errorShape: TRoot['errorShape'];
|
||||
}> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
||||
/**
|
||||
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
||||
*
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
Provider: TRPCProvider<TRouter, TSSRContext>;
|
||||
createClient: typeof createTRPCClient<TRouter>;
|
||||
useQueries: TRPCUseQueries<TRouter>;
|
||||
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
||||
};
|
||||
type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<CreateTRPCReactBase<TRouter, TSSRContext>, DecorateRouterRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
||||
declare function createTRPCReact<TRouter extends AnyRouter, TSSRContext = unknown>(opts?: CreateTRPCReactOptions<TRouter>): CreateTRPCReact<TRouter, TSSRContext>;
|
||||
//#endregion
|
||||
//#region src/internals/getQueryKey.d.ts
|
||||
type QueryType = 'any' | 'infinite' | 'query';
|
||||
type TRPCQueryKey = [readonly string[], {
|
||||
input?: unknown;
|
||||
type?: Exclude<QueryType, 'any'>;
|
||||
}?];
|
||||
type TRPCMutationKey = [readonly string[]];
|
||||
type ProcedureOrRouter = DecoratedMutation<any> | DecoratedQuery<any> | DecorateRouterRecord<any, any>;
|
||||
/**
|
||||
* To allow easy interactions with groups of related queries, such as
|
||||
* invalidating all queries of a router, we use an array as the path when
|
||||
* storing in tanstack query.
|
||||
**/
|
||||
|
||||
type GetInfiniteQueryInput<TProcedureInput, TInputWithoutCursorAndDirection = Omit<TProcedureInput, 'cursor' | 'direction'>> = keyof TInputWithoutCursorAndDirection extends never ? undefined : DeepPartial<TInputWithoutCursorAndDirection> | undefined;
|
||||
/** @internal */
|
||||
type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
||||
cursor?: any;
|
||||
} ? GetInfiniteQueryInput<TProcedureInput> : DeepPartial<TProcedureInput> | undefined;
|
||||
type GetParams<TProcedureOrRouter extends ProcedureOrRouter> = TProcedureOrRouter extends DecoratedQuery<infer $Def> ? [input?: GetQueryProcedureInput<$Def['input']>, type?: QueryType] : [];
|
||||
/**
|
||||
* Method to extract the query key for a procedure
|
||||
* @param procedureOrRouter - procedure or AnyRouter
|
||||
* @param input - input to procedureOrRouter
|
||||
* @param type - defaults to `any`
|
||||
* @see https://trpc.io/docs/v11/getQueryKey
|
||||
*/
|
||||
declare function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(procedureOrRouter: TProcedureOrRouter, ..._params: GetParams<TProcedureOrRouter>): TRPCQueryKey;
|
||||
type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [string[], {
|
||||
input?: GetQueryProcedureInput<TInput>;
|
||||
type: TType;
|
||||
}?];
|
||||
/**
|
||||
* Method to extract the mutation key for a procedure
|
||||
* @param procedure - procedure
|
||||
* @see https://trpc.io/docs/v11/getQueryKey#mutations
|
||||
*/
|
||||
declare function getMutationKey<TProcedure extends DecoratedMutation<any>>(procedure: TProcedure): TRPCMutationKey;
|
||||
//#endregion
|
||||
export { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReact, CreateTRPCReactBase, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createTRPCReact, createUseQueries, getClientArgs, getMutationKey, getQueryClient, getQueryKey, getQueryType, inferReactQueryProcedureOptions };
|
||||
//# sourceMappingURL=getQueryKey.d-CruH3ncI.d.mts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+47
@@ -0,0 +1,47 @@
|
||||
const require_getQueryKey = require('./getQueryKey-PyKLS56S.cjs');
|
||||
const require_shared = require('./shared-Dt4RsQVp.cjs');
|
||||
const __trpc_server_unstable_core_do_not_import = require_getQueryKey.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
||||
const react = require_getQueryKey.__toESM(require("react"));
|
||||
|
||||
//#region src/createTRPCReact.tsx
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createHooksInternal(trpc) {
|
||||
const proxy = require_shared.createReactDecoration(trpc);
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
|
||||
if (key === "useContext" || key === "useUtils") return () => {
|
||||
const context = trpc.useUtils();
|
||||
return react.useMemo(() => {
|
||||
return require_shared.createReactQueryUtils(context);
|
||||
}, [context]);
|
||||
};
|
||||
if (trpc.hasOwnProperty(key)) return trpc[key];
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
function createTRPCReact(opts) {
|
||||
const hooks = require_shared.createRootHooks(opts);
|
||||
const proxy = createHooksInternal(hooks);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/createTRPCQueryUtils.tsx
|
||||
function createTRPCQueryUtils(opts) {
|
||||
const utils = require_shared.createUtilityFunctions(opts);
|
||||
return require_shared.createQueryUtilsProxy(utils);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.createTRPCQueryUtils = createTRPCQueryUtils;
|
||||
exports.createTRPCReact = createTRPCReact;
|
||||
exports.getMutationKey = require_getQueryKey.getMutationKey;
|
||||
exports.getQueryKey = require_getQueryKey.getQueryKey;
|
||||
var __trpc_client = require("@trpc/client");
|
||||
Object.keys(__trpc_client).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
||||
enumerable: true,
|
||||
get: function () { return __trpc_client[k]; }
|
||||
});
|
||||
});
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { CreateQueryUtils, CreateTRPCReact, CreateTRPCReactBase, createTRPCReact, getMutationKey, getQueryKey, inferReactQueryProcedureOptions } from "./getQueryKey.d-C_PnqPni.cjs";
|
||||
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
||||
import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
export * from "@trpc/client";
|
||||
|
||||
//#region src/utils/createUtilityFunctions.d.ts
|
||||
interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The `QueryClient` from `react-query`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
/**
|
||||
* Creates a set of utility functions that can be used to interact with `react-query`
|
||||
* @param opts the `TRPCClient` and `QueryClient` to use
|
||||
* @returns a set of utility functions that can be used to interact with `react-query`
|
||||
* @internal
|
||||
*/
|
||||
//#endregion
|
||||
//#region src/createTRPCQueryUtils.d.ts
|
||||
declare function createTRPCQueryUtils<TRouter extends AnyRouter>(opts: CreateQueryUtilsOptions<TRouter>): CreateQueryUtils<TRouter>;
|
||||
//# sourceMappingURL=createTRPCQueryUtils.d.ts.map
|
||||
|
||||
//#endregion
|
||||
export { CreateTRPCReact, CreateTRPCReactBase, createTRPCQueryUtils, createTRPCReact, getMutationKey, getQueryKey, inferReactQueryProcedureOptions };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAqBiB,wCAAwC;;;AAAzD;EAAwC,MAAA,EAI9B,UAJ8B,CAInB,OAJmB,CAAA,GAIR,iBAJQ,CAIU,OAJV,CAAA;EAAA;;;EAIpB,WAA8B,EAInC,WAJmC;;;AAIxB;;;;ACxB1B;;;iBAAgB,qCAAqC,iBAC7C,wBAAwB,WAAQ,iBAAA"}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { CreateQueryUtils, CreateTRPCReact, CreateTRPCReactBase, createTRPCReact, getMutationKey, getQueryKey, inferReactQueryProcedureOptions } from "./getQueryKey.d-CruH3ncI.mjs";
|
||||
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
||||
export * from "@trpc/client";
|
||||
|
||||
//#region src/utils/createUtilityFunctions.d.ts
|
||||
interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The `QueryClient` from `react-query`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
/**
|
||||
* Creates a set of utility functions that can be used to interact with `react-query`
|
||||
* @param opts the `TRPCClient` and `QueryClient` to use
|
||||
* @returns a set of utility functions that can be used to interact with `react-query`
|
||||
* @internal
|
||||
*/
|
||||
//#endregion
|
||||
//#region src/createTRPCQueryUtils.d.ts
|
||||
declare function createTRPCQueryUtils<TRouter extends AnyRouter>(opts: CreateQueryUtilsOptions<TRouter>): CreateQueryUtils<TRouter>;
|
||||
//# sourceMappingURL=createTRPCQueryUtils.d.ts.map
|
||||
|
||||
//#endregion
|
||||
export { CreateTRPCReact, CreateTRPCReactBase, createTRPCQueryUtils, createTRPCReact, getMutationKey, getQueryKey, inferReactQueryProcedureOptions };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAqBiB,wCAAwC;;;AAAzD;EAAwC,MAAA,EAI9B,UAJ8B,CAInB,OAJmB,CAAA,GAIR,iBAJQ,CAIU,OAJV,CAAA;EAAA;;;EAIpB,WAA8B,EAInC,WAJmC;;;AAIxB;;;;ACxB1B;;;iBAAgB,qCAAqC,iBAC7C,wBAAwB,WAAQ,iBAAA"}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import { getMutationKey, getQueryKey } from "./getQueryKey-BY58RNzP.mjs";
|
||||
import { createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUtilityFunctions } from "./shared-JtnEvJvB.mjs";
|
||||
import { createFlatProxy } from "@trpc/server/unstable-core-do-not-import";
|
||||
import * as React from "react";
|
||||
|
||||
export * from "@trpc/client"
|
||||
|
||||
//#region src/createTRPCReact.tsx
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createHooksInternal(trpc) {
|
||||
const proxy = createReactDecoration(trpc);
|
||||
return createFlatProxy((key) => {
|
||||
if (key === "useContext" || key === "useUtils") return () => {
|
||||
const context = trpc.useUtils();
|
||||
return React.useMemo(() => {
|
||||
return createReactQueryUtils(context);
|
||||
}, [context]);
|
||||
};
|
||||
if (trpc.hasOwnProperty(key)) return trpc[key];
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
function createTRPCReact(opts) {
|
||||
const hooks = createRootHooks(opts);
|
||||
const proxy = createHooksInternal(hooks);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/createTRPCQueryUtils.tsx
|
||||
function createTRPCQueryUtils(opts) {
|
||||
const utils = createUtilityFunctions(opts);
|
||||
return createQueryUtilsProxy(utils);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { createTRPCQueryUtils, createTRPCReact, getMutationKey, getQueryKey };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+69
@@ -0,0 +1,69 @@
|
||||
const require_getQueryKey = require('./getQueryKey-PyKLS56S.cjs');
|
||||
const __tanstack_react_query = require_getQueryKey.__toESM(require("@tanstack/react-query"));
|
||||
const __trpc_server_unstable_core_do_not_import = require_getQueryKey.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
||||
const react = require_getQueryKey.__toESM(require("react"));
|
||||
const react_jsx_runtime = require_getQueryKey.__toESM(require("react/jsx-runtime"));
|
||||
|
||||
//#region src/rsc.tsx
|
||||
var import_objectSpread2 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2());
|
||||
const HELPERS = ["prefetch", "prefetchInfinite"];
|
||||
/**
|
||||
* @note This requires `@tanstack/react-query@^5.49.0`
|
||||
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
||||
* set to your data transformer in your `QueryClient` factory.
|
||||
* @example
|
||||
* ```ts
|
||||
* export const createQueryClient = () =>
|
||||
* new QueryClient({
|
||||
* defaultOptions: {
|
||||
* dehydrate: {
|
||||
* serializeData: transformer.serialize,
|
||||
* },
|
||||
* hydrate: {
|
||||
* deserializeData: transformer.deserialize,
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
function createHydrationHelpers(caller, getQueryClient) {
|
||||
const wrappedProxy = (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)(async (opts) => {
|
||||
const path = [...opts.path];
|
||||
const args = [...opts.args];
|
||||
const proc = path.reduce((acc, key) => HELPERS.includes(key) ? acc : acc[key], caller);
|
||||
const input = args[0];
|
||||
const promise = proc(input);
|
||||
const helper = path.pop();
|
||||
if (helper === "prefetch") {
|
||||
const args1 = args[1];
|
||||
return getQueryClient().prefetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey: require_getQueryKey.getQueryKeyInternal(path, input, "query"),
|
||||
queryFn: () => promise
|
||||
}));
|
||||
}
|
||||
if (helper === "prefetchInfinite") {
|
||||
var _args1$initialCursor;
|
||||
const args1 = args[1];
|
||||
return getQueryClient().prefetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey: require_getQueryKey.getQueryKeyInternal(path, input, "infinite"),
|
||||
queryFn: () => promise,
|
||||
initialPageParam: (_args1$initialCursor = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor !== void 0 ? _args1$initialCursor : null
|
||||
}));
|
||||
}
|
||||
return promise;
|
||||
});
|
||||
function HydrateClient(props) {
|
||||
const dehydratedState = (0, __tanstack_react_query.dehydrate)(getQueryClient());
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__tanstack_react_query.HydrationBoundary, {
|
||||
state: dehydratedState,
|
||||
children: props.children
|
||||
});
|
||||
}
|
||||
return {
|
||||
trpc: wrappedProxy,
|
||||
HydrateClient
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.createHydrationHelpers = createHydrationHelpers;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import { TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from "./getQueryKey.d-C_PnqPni.cjs";
|
||||
import { TRPCClientError } from "@trpc/client";
|
||||
import { AnyProcedure, AnyRootTypes, AnyRouter, RouterCaller, RouterRecord, TypeError, inferProcedureInput, inferProcedureOutput, inferRouterRootTypes } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import * as React from "react";
|
||||
import { inferTransformedProcedureOutput as inferTransformedProcedureOutput$1 } from "@trpc/server";
|
||||
|
||||
//#region src/rsc.d.ts
|
||||
type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
(input: inferProcedureInput<TProcedure>): Promise<inferProcedureOutput<TProcedure>>;
|
||||
prefetch: (input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput$1<TRoot, TProcedure>, TRPCClientError<TRoot>>) => Promise<void>;
|
||||
prefetchInfinite: (input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput$1<TRoot, TProcedure>, TRPCClientError<TRoot>>) => Promise<void>;
|
||||
};
|
||||
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never };
|
||||
type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>>;
|
||||
/**
|
||||
* @note This requires `@tanstack/react-query@^5.49.0`
|
||||
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
||||
* set to your data transformer in your `QueryClient` factory.
|
||||
* @example
|
||||
* ```ts
|
||||
* export const createQueryClient = () =>
|
||||
* new QueryClient({
|
||||
* defaultOptions: {
|
||||
* dehydrate: {
|
||||
* serializeData: transformer.serialize,
|
||||
* },
|
||||
* hydrate: {
|
||||
* deserializeData: transformer.deserialize,
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
declare function createHydrationHelpers<TRouter extends AnyRouter>(caller: AnyRouter extends TRouter ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'> : Caller<TRouter>, getQueryClient: () => QueryClient): {
|
||||
/***
|
||||
* Wrapped caller with prefetch helpers
|
||||
* Can be used as a regular [server-side caller](https://trpc.io/docs/server/server-side-calls)
|
||||
* or using prefetch helpers to put the promise into the QueryClient cache
|
||||
* @example
|
||||
* ```ts
|
||||
* const data = await trpc.post.get("postId");
|
||||
*
|
||||
* // or
|
||||
* void trpc.post.get.prefetch("postId");
|
||||
* ```
|
||||
*/
|
||||
trpc: DecorateRouterRecord<inferRouterRootTypes<TRouter>, TRouter["_def"]["record"]>;
|
||||
/**
|
||||
* HoC to hydrate the query client for a client component
|
||||
* to pick up the prefetched promise and skip an initial
|
||||
* client-side fetch.
|
||||
* @example
|
||||
* ```tsx
|
||||
* // MyRSC.tsx
|
||||
* const MyRSC = ({ params }) => {
|
||||
* void trpc.post.get.prefetch(params.postId);
|
||||
*
|
||||
* return (
|
||||
* <HydrateClient>
|
||||
* <MyCC postId={params.postId} />
|
||||
* </HydrateClient>
|
||||
* );
|
||||
* };
|
||||
*
|
||||
* // MyCC.tsx
|
||||
* "use client"
|
||||
* const MyCC = ({ postId }) => {
|
||||
* const { data: post } = trpc.post.get.useQuery(postId);
|
||||
* return <div>{post.title}</div>;
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
HydrateClient: (props: {
|
||||
children: React.ReactNode;
|
||||
}) => React.JSX.Element;
|
||||
};
|
||||
//#endregion
|
||||
export { createHydrationHelpers };
|
||||
//# sourceMappingURL=rsc.d.cts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"rsc.d.cts","names":[],"sources":["../src/rsc.tsx"],"sourcesContent":[],"mappings":";;;;;;;;KAiCK,gCACW,iCACK;EAFhB,CAAA,KAAA,EAKM,mBALW,CAKS,UALT,CAAA,CAAA,EAMjB,OANiB,CAMT,oBANS,CAMY,UANZ,CAAA,CAAA;EAAA,QAAA,EAAA,CAAA,KAAA,EAQX,mBARW,CAQS,UART,CAAA,EAAA,IAAA,CAAA,EASX,qBATW,CAUhB,iCAVgB,CAUgB,KAVhB,EAUuB,UAVvB,CAAA,EAWhB,eAXgB,CAWA,KAXA,CAAA,CAAA,EAAA,GAaf,OAbe,CAAA,IAAA,CAAA;EAAA,gBACN,EAAA,CAAA,KAAA,EAcL,mBAdK,CAce,UAdf,CAAA,EAAA,IAAA,CAAA,EAeL,6BAfK,CAgBV,mBAhBU,CAgBU,UAhBV,CAAA,EAiBV,iCAjBU,CAiBsB,KAjBtB,EAiB6B,UAjB7B,CAAA,EAkBV,eAlBU,CAkBM,KAlBN,CAAA,CAAA,EAAA,GAoBT,OApBS,CAAA,IAAA,CAAA;CAAY;KAuBvB,oBAnB0B,CAAA,cAoBf,YApBe,EAAA,gBAqBb,YArBa,CAAA,GAAA,WAApB,MAuBM,OAvBN,GAuBgB,OAvBhB,CAuBwB,IAvBxB,CAAA,SAAA,KAAA,OAAA,GAwBL,MAxBK,SAwBU,YAxBV,GAyBH,iBAzBG,CAyBe,KAzBf,EAyBsB,MAzBtB,CAAA,GA0BH,MA1BG,SA0BY,YA1BZ,GA2BD,oBA3BC,CA2BoB,KA3BpB,EA2B2B,MA3B3B,CAAA,GAAA,KAAA,GAAA,KAAA,EAAmB;KAgCzB,MA/BQ,CAAA,gBA+Be,SA/Bf,CAAA,GA+B4B,UA/B5B,CAgCX,YAhCW,CAgCE,oBAhCF,CAgCuB,OAhCvB,CAAA,EAgCiC,OAhCjC,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;AAUF,iBA6CK,sBA7CL,CAAA,gBA6C4C,SA7C5C,CAAA,CAAA,MAAA,EA8CD,SA9CC,SA8CiB,OA9CjB,GA+CL,SA/CK,CAAA,6DAAA,CAAA,GAgDL,MAhDK,CAgDE,OAhDF,CAAA,EAAA,cAAA,EAAA,GAAA,GAiDa,WAjDb,CAAA,EAAA;EAA6B;AAK1B;AAAA;;;;;;;;;;EASiB,IAAE,sBAAA,qBAAA,CAmCE,OAnCF,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA;EAAM;;;;;;AAET;AAAA;;;;;;;;AAKqB;AAwBnD;;;;;;;;;EAImC,aAAA,EAAA,CAAA,KAAA,EAAA;cA+CS,KAAA,CAAM;QAAW,KAAA,CAAA,GAAA,CAAA"}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import { TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from "./getQueryKey.d-CruH3ncI.mjs";
|
||||
import { TRPCClientError } from "@trpc/client";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { AnyProcedure, AnyRootTypes, AnyRouter, RouterCaller, RouterRecord, TypeError, inferProcedureInput, inferProcedureOutput, inferRouterRootTypes } from "@trpc/server/unstable-core-do-not-import";
|
||||
import * as React from "react";
|
||||
import { inferTransformedProcedureOutput as inferTransformedProcedureOutput$1 } from "@trpc/server";
|
||||
|
||||
//#region src/rsc.d.ts
|
||||
type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = {
|
||||
(input: inferProcedureInput<TProcedure>): Promise<inferProcedureOutput<TProcedure>>;
|
||||
prefetch: (input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferTransformedProcedureOutput$1<TRoot, TProcedure>, TRPCClientError<TRoot>>) => Promise<void>;
|
||||
prefetchInfinite: (input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, inferTransformedProcedureOutput$1<TRoot, TProcedure>, TRPCClientError<TRoot>>) => Promise<void>;
|
||||
};
|
||||
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never };
|
||||
type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>>;
|
||||
/**
|
||||
* @note This requires `@tanstack/react-query@^5.49.0`
|
||||
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
||||
* set to your data transformer in your `QueryClient` factory.
|
||||
* @example
|
||||
* ```ts
|
||||
* export const createQueryClient = () =>
|
||||
* new QueryClient({
|
||||
* defaultOptions: {
|
||||
* dehydrate: {
|
||||
* serializeData: transformer.serialize,
|
||||
* },
|
||||
* hydrate: {
|
||||
* deserializeData: transformer.deserialize,
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
declare function createHydrationHelpers<TRouter extends AnyRouter>(caller: AnyRouter extends TRouter ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'> : Caller<TRouter>, getQueryClient: () => QueryClient): {
|
||||
/***
|
||||
* Wrapped caller with prefetch helpers
|
||||
* Can be used as a regular [server-side caller](https://trpc.io/docs/server/server-side-calls)
|
||||
* or using prefetch helpers to put the promise into the QueryClient cache
|
||||
* @example
|
||||
* ```ts
|
||||
* const data = await trpc.post.get("postId");
|
||||
*
|
||||
* // or
|
||||
* void trpc.post.get.prefetch("postId");
|
||||
* ```
|
||||
*/
|
||||
trpc: DecorateRouterRecord<inferRouterRootTypes<TRouter>, TRouter["_def"]["record"]>;
|
||||
/**
|
||||
* HoC to hydrate the query client for a client component
|
||||
* to pick up the prefetched promise and skip an initial
|
||||
* client-side fetch.
|
||||
* @example
|
||||
* ```tsx
|
||||
* // MyRSC.tsx
|
||||
* const MyRSC = ({ params }) => {
|
||||
* void trpc.post.get.prefetch(params.postId);
|
||||
*
|
||||
* return (
|
||||
* <HydrateClient>
|
||||
* <MyCC postId={params.postId} />
|
||||
* </HydrateClient>
|
||||
* );
|
||||
* };
|
||||
*
|
||||
* // MyCC.tsx
|
||||
* "use client"
|
||||
* const MyCC = ({ postId }) => {
|
||||
* const { data: post } = trpc.post.get.useQuery(postId);
|
||||
* return <div>{post.title}</div>;
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
HydrateClient: (props: {
|
||||
children: React.ReactNode;
|
||||
}) => React.JSX.Element;
|
||||
};
|
||||
//#endregion
|
||||
export { createHydrationHelpers };
|
||||
//# sourceMappingURL=rsc.d.mts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"rsc.d.mts","names":[],"sources":["../src/rsc.tsx"],"sourcesContent":[],"mappings":";;;;;;;;KAiCK,gCACW,iCACK;EAFhB,CAAA,KAAA,EAKM,mBALW,CAKS,UALT,CAAA,CAAA,EAMjB,OANiB,CAMT,oBANS,CAMY,UANZ,CAAA,CAAA;EAAA,QAAA,EAAA,CAAA,KAAA,EAQX,mBARW,CAQS,UART,CAAA,EAAA,IAAA,CAAA,EASX,qBATW,CAUhB,iCAVgB,CAUgB,KAVhB,EAUuB,UAVvB,CAAA,EAWhB,eAXgB,CAWA,KAXA,CAAA,CAAA,EAAA,GAaf,OAbe,CAAA,IAAA,CAAA;EAAA,gBACN,EAAA,CAAA,KAAA,EAcL,mBAdK,CAce,UAdf,CAAA,EAAA,IAAA,CAAA,EAeL,6BAfK,CAgBV,mBAhBU,CAgBU,UAhBV,CAAA,EAiBV,iCAjBU,CAiBsB,KAjBtB,EAiB6B,UAjB7B,CAAA,EAkBV,eAlBU,CAkBM,KAlBN,CAAA,CAAA,EAAA,GAoBT,OApBS,CAAA,IAAA,CAAA;CAAY;KAuBvB,oBAnB0B,CAAA,cAoBf,YApBe,EAAA,gBAqBb,YArBa,CAAA,GAAA,WAApB,MAuBM,OAvBN,GAuBgB,OAvBhB,CAuBwB,IAvBxB,CAAA,SAAA,KAAA,OAAA,GAwBL,MAxBK,SAwBU,YAxBV,GAyBH,iBAzBG,CAyBe,KAzBf,EAyBsB,MAzBtB,CAAA,GA0BH,MA1BG,SA0BY,YA1BZ,GA2BD,oBA3BC,CA2BoB,KA3BpB,EA2B2B,MA3B3B,CAAA,GAAA,KAAA,GAAA,KAAA,EAAmB;KAgCzB,MA/BQ,CAAA,gBA+Be,SA/Bf,CAAA,GA+B4B,UA/B5B,CAgCX,YAhCW,CAgCE,oBAhCF,CAgCuB,OAhCvB,CAAA,EAgCiC,OAhCjC,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;AAUF,iBA6CK,sBA7CL,CAAA,gBA6C4C,SA7C5C,CAAA,CAAA,MAAA,EA8CD,SA9CC,SA8CiB,OA9CjB,GA+CL,SA/CK,CAAA,6DAAA,CAAA,GAgDL,MAhDK,CAgDE,OAhDF,CAAA,EAAA,cAAA,EAAA,GAAA,GAiDa,WAjDb,CAAA,EAAA;EAA6B;AAK1B;AAAA;;;;;;;;;;EASiB,IAAE,sBAAA,qBAAA,CAmCE,OAnCF,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA;EAAM;;;;;;AAET;AAAA;;;;;;;;AAKqB;AAwBnD;;;;;;;;;EAImC,aAAA,EAAA,CAAA,KAAA,EAAA;cA+CS,KAAA,CAAM;QAAW,KAAA,CAAA,GAAA,CAAA"}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
import { __toESM, getQueryKeyInternal, require_objectSpread2 } from "./getQueryKey-BY58RNzP.mjs";
|
||||
import { HydrationBoundary, dehydrate } from "@tanstack/react-query";
|
||||
import { createRecursiveProxy } from "@trpc/server/unstable-core-do-not-import";
|
||||
import "react";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
|
||||
//#region src/rsc.tsx
|
||||
var import_objectSpread2 = __toESM(require_objectSpread2());
|
||||
const HELPERS = ["prefetch", "prefetchInfinite"];
|
||||
/**
|
||||
* @note This requires `@tanstack/react-query@^5.49.0`
|
||||
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
||||
* set to your data transformer in your `QueryClient` factory.
|
||||
* @example
|
||||
* ```ts
|
||||
* export const createQueryClient = () =>
|
||||
* new QueryClient({
|
||||
* defaultOptions: {
|
||||
* dehydrate: {
|
||||
* serializeData: transformer.serialize,
|
||||
* },
|
||||
* hydrate: {
|
||||
* deserializeData: transformer.deserialize,
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
function createHydrationHelpers(caller, getQueryClient) {
|
||||
const wrappedProxy = createRecursiveProxy(async (opts) => {
|
||||
const path = [...opts.path];
|
||||
const args = [...opts.args];
|
||||
const proc = path.reduce((acc, key) => HELPERS.includes(key) ? acc : acc[key], caller);
|
||||
const input = args[0];
|
||||
const promise = proc(input);
|
||||
const helper = path.pop();
|
||||
if (helper === "prefetch") {
|
||||
const args1 = args[1];
|
||||
return getQueryClient().prefetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey: getQueryKeyInternal(path, input, "query"),
|
||||
queryFn: () => promise
|
||||
}));
|
||||
}
|
||||
if (helper === "prefetchInfinite") {
|
||||
var _args1$initialCursor;
|
||||
const args1 = args[1];
|
||||
return getQueryClient().prefetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey: getQueryKeyInternal(path, input, "infinite"),
|
||||
queryFn: () => promise,
|
||||
initialPageParam: (_args1$initialCursor = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor !== void 0 ? _args1$initialCursor : null
|
||||
}));
|
||||
}
|
||||
return promise;
|
||||
});
|
||||
function HydrateClient(props) {
|
||||
const dehydratedState = dehydrate(getQueryClient());
|
||||
return /* @__PURE__ */ jsx(HydrationBoundary, {
|
||||
state: dehydratedState,
|
||||
children: props.children
|
||||
});
|
||||
}
|
||||
return {
|
||||
trpc: wrappedProxy,
|
||||
HydrateClient
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { createHydrationHelpers };
|
||||
//# sourceMappingURL=rsc.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+129
@@ -0,0 +1,129 @@
|
||||
const require_getQueryKey = require('../getQueryKey-PyKLS56S.cjs');
|
||||
const require_shared = require('../shared-Dt4RsQVp.cjs');
|
||||
const __trpc_client = require_getQueryKey.__toESM(require("@trpc/client"));
|
||||
const __tanstack_react_query = require_getQueryKey.__toESM(require("@tanstack/react-query"));
|
||||
const __trpc_server_unstable_core_do_not_import = require_getQueryKey.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
||||
const __trpc_client_unstable_internals = require_getQueryKey.__toESM(require("@trpc/client/unstable-internals"));
|
||||
|
||||
//#region src/server/ssgProxy.ts
|
||||
var import_objectSpread2 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2(), 1);
|
||||
var import_objectWithoutProperties = require_getQueryKey.__toESM(require_getQueryKey.require_objectWithoutProperties(), 1);
|
||||
const _excluded = ["promise"];
|
||||
/**
|
||||
* Create functions you can use for server-side rendering / static generation
|
||||
* @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
||||
*/
|
||||
function createServerSideHelpers(opts) {
|
||||
const queryClient = require_shared.getQueryClient(opts);
|
||||
const transformer = (0, __trpc_client_unstable_internals.getTransformer)(opts.transformer);
|
||||
const resolvedOpts = (() => {
|
||||
if ("router" in opts) {
|
||||
const { ctx, router } = opts;
|
||||
return {
|
||||
serialize: (obj) => transformer.output.serialize(obj),
|
||||
query: (queryOpts) => {
|
||||
return (0, __trpc_server_unstable_core_do_not_import.callProcedure)({
|
||||
router,
|
||||
path: queryOpts.path,
|
||||
getRawInput: async () => queryOpts.input,
|
||||
ctx,
|
||||
type: "query",
|
||||
signal: void 0,
|
||||
batchIndex: 0
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
const { client } = opts;
|
||||
const untypedClient = client instanceof __trpc_client.TRPCUntypedClient ? client : (0, __trpc_client.getUntypedClient)(client);
|
||||
return {
|
||||
query: (queryOpts) => untypedClient.query(queryOpts.path, queryOpts.input),
|
||||
serialize: (obj) => transformer.output.serialize(obj)
|
||||
};
|
||||
})();
|
||||
function _dehydrate(opts$1 = { shouldDehydrateQuery(query) {
|
||||
if (query.state.status === "pending") return false;
|
||||
return true;
|
||||
} }) {
|
||||
const before = (0, __trpc_server_unstable_core_do_not_import.run)(() => {
|
||||
const dehydrated = (0, __tanstack_react_query.dehydrate)(queryClient, opts$1);
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, dehydrated), {}, { queries: dehydrated.queries.map((query) => {
|
||||
if (query.promise) {
|
||||
const { promise: _ } = query, rest = (0, import_objectWithoutProperties.default)(query, _excluded);
|
||||
return rest;
|
||||
}
|
||||
return query;
|
||||
}) });
|
||||
});
|
||||
const after = resolvedOpts.serialize(before);
|
||||
return after;
|
||||
}
|
||||
const proxy = (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((opts$1) => {
|
||||
const args = opts$1.args;
|
||||
const input = args[0];
|
||||
const arrayPath = [...opts$1.path];
|
||||
const utilName = arrayPath.pop();
|
||||
const queryFn = () => resolvedOpts.query({
|
||||
path: arrayPath.join("."),
|
||||
input
|
||||
});
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(arrayPath, input, require_shared.getQueryType(utilName));
|
||||
const helperMap = {
|
||||
queryOptions: () => {
|
||||
const args1 = args[1];
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
});
|
||||
},
|
||||
infiniteQueryOptions: () => {
|
||||
const args1 = args[1];
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
});
|
||||
},
|
||||
fetch: () => {
|
||||
const args1 = args[1];
|
||||
return queryClient.fetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
}));
|
||||
},
|
||||
fetchInfinite: () => {
|
||||
var _args1$initialCursor;
|
||||
const args1 = args[1];
|
||||
return queryClient.fetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: (_args1$initialCursor = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor !== void 0 ? _args1$initialCursor : null
|
||||
}));
|
||||
},
|
||||
prefetch: () => {
|
||||
const args1 = args[1];
|
||||
return queryClient.prefetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
}));
|
||||
},
|
||||
prefetchInfinite: () => {
|
||||
var _args1$initialCursor2;
|
||||
const args1 = args[1];
|
||||
return queryClient.prefetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: (_args1$initialCursor2 = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor2 !== void 0 ? _args1$initialCursor2 : null
|
||||
}));
|
||||
}
|
||||
};
|
||||
return helperMap[utilName]();
|
||||
});
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
|
||||
if (key === "queryClient") return queryClient;
|
||||
if (key === "dehydrate") return _dehydrate;
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.createServerSideHelpers = createServerSideHelpers;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { CreateTRPCReactQueryClientConfig, DecorateQueryProcedure } from "../getQueryKey.d-C_PnqPni.cjs";
|
||||
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
||||
import { AnyQueryProcedure, AnyRootTypes, AnyRouter, ProtectedIntersection, RouterRecord, inferClientTypes, inferRouterContext } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { DehydrateOptions, DehydratedState, QueryClient } from "@tanstack/react-query";
|
||||
import { TransformerOptions } from "@trpc/client/unstable-internals";
|
||||
|
||||
//#region src/server/ssgProxy.d.ts
|
||||
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
||||
router: TRouter;
|
||||
ctx: inferRouterContext<TRouter>;
|
||||
} & TransformerOptions<inferClientTypes<TRouter>>;
|
||||
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> = CreateTRPCReactQueryClientConfig & (CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
||||
type SSGFns = 'queryOptions' | 'infiniteQueryOptions' | 'fetch' | 'fetchInfinite' | 'prefetch' | 'prefetchInfinite';
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedProcedureSSGRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns> : $Value extends RouterRecord ? DecoratedProcedureSSGRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* Create functions you can use for server-side rendering / static generation
|
||||
* @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
||||
*/
|
||||
declare function createServerSideHelpers<TRouter extends AnyRouter>(opts: CreateServerSideHelpersOptions<TRouter>): ProtectedIntersection<{
|
||||
queryClient: QueryClient;
|
||||
dehydrate: (opts?: DehydrateOptions) => DehydratedState;
|
||||
}, DecoratedProcedureSSGRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>>;
|
||||
//#endregion
|
||||
export { createServerSideHelpers };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/server/ssgProxy.ts"],"sourcesContent":[],"mappings":";;;;;;;KAsCK,yCAAyC;EAAzC,MAAA,EACK,OADL;EAAwB,GAAA,EAEtB,kBAFsB,CAEH,OAFG,CAAA;CAAA,GAGzB,kBAH0C,CAGvB,gBAHuB,CAGN,OAHM,CAAA,CAAA;UAKpC,wBAJA,CAAA,gBAIyC,SAJzC,CAAA,CAAA;EAAO,MACS,EAIhB,UAJgB,CAIL,OAJK,CAAA,GAIM,iBAJN,CAIwB,OAJxB,CAAA;;KAOrB,8BANmC,CAAA,gBAMY,SANZ,CAAA,GAOtC,gCAPsC,GAAA,CAQnC,wBARmC,CAQV,OARU,CAAA,GAQC,wBARD,CAQ0B,OAR1B,CAAA,CAAA;KAUnC,MAAA,GAVkB,cAAA,GAAA,sBAAA,GAAA,OAAA,GAAA,eAAA,GAAA,UAAA,GAAA,kBAAA;;AAAD;AAAA;KAqBjB,2BAnB6B,CAAA,cAoBlB,YApBkB,EAAA,gBAqBhB,YArBgB,CAAA,GAAA,WAAiB,MAuBlC,OAvBkC,GAuBxB,OAvBwB,CAuBhB,IAvBgB,CAAA,SAAA,KAAA,OAAA,GAwB7C,MAxB6C,SAwB9B,iBAxB8B,GAyB3C,IAzB2C,CAyBtC,sBAzBsC,CAyBf,KAzBe,EAyBR,MAzBQ,CAAA,EAyBC,MAzBD,CAAA,GA0B3C,MA1B2C,SA0B5B,YA1B4B,GA2BzC,2BA3ByC,CA2Bb,KA3Ba,EA2BN,MA3BM,CAAA,GAAA,KAAA,GAAA,KAAA,EAAS;;;;AACX;AAG5C,iBAkCW,uBAlCmB,CAAA,gBAkCqB,SAlCrB,CAAA,CAAA,IAAA,EAmC3B,8BAnC2B,CAmCI,OAnCJ,CAAA,CAAA,EAmCY,qBAnCZ,CAAA;EAAA,WAAA,EA0GhB,WA1GgB;EAAA,SAAiB,EAAA,CAAA,IAAA,CAAA,EA2G3B,gBA3G2B,EAAA,GA2GN,eA3GM;CAAS,6BAC3D,CA0G2D,OA1G3D,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA"}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { CreateTRPCReactQueryClientConfig, DecorateQueryProcedure } from "../getQueryKey.d-CruH3ncI.mjs";
|
||||
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
||||
import { DehydrateOptions, DehydratedState, QueryClient } from "@tanstack/react-query";
|
||||
import { AnyQueryProcedure, AnyRootTypes, AnyRouter, ProtectedIntersection, RouterRecord, inferClientTypes, inferRouterContext } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { TransformerOptions } from "@trpc/client/unstable-internals";
|
||||
|
||||
//#region src/server/ssgProxy.d.ts
|
||||
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
||||
router: TRouter;
|
||||
ctx: inferRouterContext<TRouter>;
|
||||
} & TransformerOptions<inferClientTypes<TRouter>>;
|
||||
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> = CreateTRPCReactQueryClientConfig & (CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
||||
type SSGFns = 'queryOptions' | 'infiniteQueryOptions' | 'fetch' | 'fetchInfinite' | 'prefetch' | 'prefetchInfinite';
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedProcedureSSGRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns> : $Value extends RouterRecord ? DecoratedProcedureSSGRecord<TRoot, $Value> : never : never };
|
||||
/**
|
||||
* Create functions you can use for server-side rendering / static generation
|
||||
* @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
||||
*/
|
||||
declare function createServerSideHelpers<TRouter extends AnyRouter>(opts: CreateServerSideHelpersOptions<TRouter>): ProtectedIntersection<{
|
||||
queryClient: QueryClient;
|
||||
dehydrate: (opts?: DehydrateOptions) => DehydratedState;
|
||||
}, DecoratedProcedureSSGRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>>;
|
||||
//#endregion
|
||||
export { createServerSideHelpers };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/server/ssgProxy.ts"],"sourcesContent":[],"mappings":";;;;;;;KAsCK,yCAAyC;EAAzC,MAAA,EACK,OADL;EAAwB,GAAA,EAEtB,kBAFsB,CAEH,OAFG,CAAA;CAAA,GAGzB,kBAH0C,CAGvB,gBAHuB,CAGN,OAHM,CAAA,CAAA;UAKpC,wBAJA,CAAA,gBAIyC,SAJzC,CAAA,CAAA;EAAO,MACS,EAIhB,UAJgB,CAIL,OAJK,CAAA,GAIM,iBAJN,CAIwB,OAJxB,CAAA;;KAOrB,8BANmC,CAAA,gBAMY,SANZ,CAAA,GAOtC,gCAPsC,GAAA,CAQnC,wBARmC,CAQV,OARU,CAAA,GAQC,wBARD,CAQ0B,OAR1B,CAAA,CAAA;KAUnC,MAAA,GAVkB,cAAA,GAAA,sBAAA,GAAA,OAAA,GAAA,eAAA,GAAA,UAAA,GAAA,kBAAA;;AAAD;AAAA;KAqBjB,2BAnB6B,CAAA,cAoBlB,YApBkB,EAAA,gBAqBhB,YArBgB,CAAA,GAAA,WAAiB,MAuBlC,OAvBkC,GAuBxB,OAvBwB,CAuBhB,IAvBgB,CAAA,SAAA,KAAA,OAAA,GAwB7C,MAxB6C,SAwB9B,iBAxB8B,GAyB3C,IAzB2C,CAyBtC,sBAzBsC,CAyBf,KAzBe,EAyBR,MAzBQ,CAAA,EAyBC,MAzBD,CAAA,GA0B3C,MA1B2C,SA0B5B,YA1B4B,GA2BzC,2BA3ByC,CA2Bb,KA3Ba,EA2BN,MA3BM,CAAA,GAAA,KAAA,GAAA,KAAA,EAAS;;;;AACX;AAG5C,iBAkCW,uBAlCmB,CAAA,gBAkCqB,SAlCrB,CAAA,CAAA,IAAA,EAmC3B,8BAnC2B,CAmCI,OAnCJ,CAAA,CAAA,EAmCY,qBAnCZ,CAAA;EAAA,WAAA,EA0GhB,WA1GgB;EAAA,SAAiB,EAAA,CAAA,IAAA,CAAA,EA2G3B,gBA3G2B,EAAA,GA2GN,eA3GM;CAAS,6BAC3D,CA0G2D,OA1G3D,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA"}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
import { __toESM, getQueryKeyInternal, require_objectSpread2, require_objectWithoutProperties } from "../getQueryKey-BY58RNzP.mjs";
|
||||
import { getQueryClient, getQueryType } from "../shared-JtnEvJvB.mjs";
|
||||
import { TRPCUntypedClient, getUntypedClient } from "@trpc/client";
|
||||
import { dehydrate } from "@tanstack/react-query";
|
||||
import { callProcedure, createFlatProxy, createRecursiveProxy, run } from "@trpc/server/unstable-core-do-not-import";
|
||||
import { getTransformer } from "@trpc/client/unstable-internals";
|
||||
|
||||
//#region src/server/ssgProxy.ts
|
||||
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
||||
var import_objectWithoutProperties = __toESM(require_objectWithoutProperties(), 1);
|
||||
const _excluded = ["promise"];
|
||||
/**
|
||||
* Create functions you can use for server-side rendering / static generation
|
||||
* @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
||||
*/
|
||||
function createServerSideHelpers(opts) {
|
||||
const queryClient = getQueryClient(opts);
|
||||
const transformer = getTransformer(opts.transformer);
|
||||
const resolvedOpts = (() => {
|
||||
if ("router" in opts) {
|
||||
const { ctx, router } = opts;
|
||||
return {
|
||||
serialize: (obj) => transformer.output.serialize(obj),
|
||||
query: (queryOpts) => {
|
||||
return callProcedure({
|
||||
router,
|
||||
path: queryOpts.path,
|
||||
getRawInput: async () => queryOpts.input,
|
||||
ctx,
|
||||
type: "query",
|
||||
signal: void 0,
|
||||
batchIndex: 0
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
const { client } = opts;
|
||||
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
return {
|
||||
query: (queryOpts) => untypedClient.query(queryOpts.path, queryOpts.input),
|
||||
serialize: (obj) => transformer.output.serialize(obj)
|
||||
};
|
||||
})();
|
||||
function _dehydrate(opts$1 = { shouldDehydrateQuery(query) {
|
||||
if (query.state.status === "pending") return false;
|
||||
return true;
|
||||
} }) {
|
||||
const before = run(() => {
|
||||
const dehydrated = dehydrate(queryClient, opts$1);
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, dehydrated), {}, { queries: dehydrated.queries.map((query) => {
|
||||
if (query.promise) {
|
||||
const { promise: _ } = query, rest = (0, import_objectWithoutProperties.default)(query, _excluded);
|
||||
return rest;
|
||||
}
|
||||
return query;
|
||||
}) });
|
||||
});
|
||||
const after = resolvedOpts.serialize(before);
|
||||
return after;
|
||||
}
|
||||
const proxy = createRecursiveProxy((opts$1) => {
|
||||
const args = opts$1.args;
|
||||
const input = args[0];
|
||||
const arrayPath = [...opts$1.path];
|
||||
const utilName = arrayPath.pop();
|
||||
const queryFn = () => resolvedOpts.query({
|
||||
path: arrayPath.join("."),
|
||||
input
|
||||
});
|
||||
const queryKey = getQueryKeyInternal(arrayPath, input, getQueryType(utilName));
|
||||
const helperMap = {
|
||||
queryOptions: () => {
|
||||
const args1 = args[1];
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
});
|
||||
},
|
||||
infiniteQueryOptions: () => {
|
||||
const args1 = args[1];
|
||||
return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
});
|
||||
},
|
||||
fetch: () => {
|
||||
const args1 = args[1];
|
||||
return queryClient.fetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
}));
|
||||
},
|
||||
fetchInfinite: () => {
|
||||
var _args1$initialCursor;
|
||||
const args1 = args[1];
|
||||
return queryClient.fetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: (_args1$initialCursor = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor !== void 0 ? _args1$initialCursor : null
|
||||
}));
|
||||
},
|
||||
prefetch: () => {
|
||||
const args1 = args[1];
|
||||
return queryClient.prefetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn
|
||||
}));
|
||||
},
|
||||
prefetchInfinite: () => {
|
||||
var _args1$initialCursor2;
|
||||
const args1 = args[1];
|
||||
return queryClient.prefetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, args1), {}, {
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: (_args1$initialCursor2 = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor2 !== void 0 ? _args1$initialCursor2 : null
|
||||
}));
|
||||
}
|
||||
};
|
||||
return helperMap[utilName]();
|
||||
});
|
||||
return createFlatProxy((key) => {
|
||||
if (key === "queryClient") return queryClient;
|
||||
if (key === "dehydrate") return _dehydrate;
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { createServerSideHelpers };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+834
@@ -0,0 +1,834 @@
|
||||
const require_getQueryKey = require('./getQueryKey-PyKLS56S.cjs');
|
||||
const __trpc_client = require_getQueryKey.__toESM(require("@trpc/client"));
|
||||
const __tanstack_react_query = require_getQueryKey.__toESM(require("@tanstack/react-query"));
|
||||
const __trpc_server_unstable_core_do_not_import = require_getQueryKey.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
||||
const react = require_getQueryKey.__toESM(require("react"));
|
||||
const react_jsx_runtime = require_getQueryKey.__toESM(require("react/jsx-runtime"));
|
||||
|
||||
//#region src/shared/proxy/decorationProxy.ts
|
||||
/**
|
||||
* Create proxy for decorating procedures
|
||||
* @internal
|
||||
*/
|
||||
function createReactDecoration(hooks) {
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)(({ path, args }) => {
|
||||
var _rest$;
|
||||
const pathCopy = [...path];
|
||||
const lastArg = pathCopy.pop();
|
||||
if (lastArg === "useMutation") return hooks[lastArg](pathCopy, ...args);
|
||||
if (lastArg === "_def") return { path: pathCopy };
|
||||
const [input, ...rest] = args;
|
||||
const opts = (_rest$ = rest[0]) !== null && _rest$ !== void 0 ? _rest$ : {};
|
||||
return hooks[lastArg](pathCopy, input, opts);
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/context.tsx
|
||||
var _React$createContext;
|
||||
const contextProps = [
|
||||
"client",
|
||||
"ssrContext",
|
||||
"ssrState",
|
||||
"abortOnUnmount"
|
||||
];
|
||||
const TRPCContext = (_React$createContext = react.createContext) === null || _React$createContext === void 0 ? void 0 : _React$createContext.call(react, null);
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/proxy/utilsProxy.ts
|
||||
const getQueryType = (utilName) => {
|
||||
switch (utilName) {
|
||||
case "queryOptions":
|
||||
case "fetch":
|
||||
case "ensureData":
|
||||
case "prefetch":
|
||||
case "getData":
|
||||
case "setData":
|
||||
case "setQueriesData": return "query";
|
||||
case "infiniteQueryOptions":
|
||||
case "fetchInfinite":
|
||||
case "prefetchInfinite":
|
||||
case "getInfiniteData":
|
||||
case "setInfiniteData": return "infinite";
|
||||
case "setMutationDefaults":
|
||||
case "getMutationDefaults":
|
||||
case "isMutating":
|
||||
case "cancel":
|
||||
case "invalidate":
|
||||
case "refetch":
|
||||
case "reset": return "any";
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createRecursiveUtilsProxy(context) {
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((opts) => {
|
||||
const path = [...opts.path];
|
||||
const utilName = path.pop();
|
||||
const args = [...opts.args];
|
||||
const input = args.shift();
|
||||
const queryType = getQueryType(utilName);
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, queryType);
|
||||
const contextMap = {
|
||||
infiniteQueryOptions: () => context.infiniteQueryOptions(path, queryKey, args[0]),
|
||||
queryOptions: () => context.queryOptions(path, queryKey, ...args),
|
||||
fetch: () => context.fetchQuery(queryKey, ...args),
|
||||
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
||||
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
||||
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
|
||||
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
||||
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
||||
reset: () => context.resetQueries(queryKey, ...args),
|
||||
refetch: () => context.refetchQueries(queryKey, ...args),
|
||||
cancel: () => context.cancelQuery(queryKey, ...args),
|
||||
setData: () => {
|
||||
context.setQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
setQueriesData: () => context.setQueriesData(queryKey, args[0], args[1], args[2]),
|
||||
setInfiniteData: () => {
|
||||
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
getData: () => context.getQueryData(queryKey),
|
||||
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
||||
setMutationDefaults: () => context.setMutationDefaults(require_getQueryKey.getMutationKeyInternal(path), input),
|
||||
getMutationDefaults: () => context.getMutationDefaults(require_getQueryKey.getMutationKeyInternal(path)),
|
||||
isMutating: () => context.isMutating({ mutationKey: require_getQueryKey.getMutationKeyInternal(path) })
|
||||
};
|
||||
return contextMap[utilName]();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createReactQueryUtils(context) {
|
||||
const clientProxy = (0, __trpc_client.createTRPCClientProxy)(context.client);
|
||||
const proxy = createRecursiveUtilsProxy(context);
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
|
||||
const contextName = key;
|
||||
if (contextName === "client") return clientProxy;
|
||||
if (contextProps.includes(contextName)) return context[contextName];
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createQueryUtilsProxy(context) {
|
||||
return createRecursiveUtilsProxy(context);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/proxy/useQueriesProxy.ts
|
||||
var import_objectSpread2$3 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2(), 1);
|
||||
/**
|
||||
* Create proxy for `useQueries` options
|
||||
* @internal
|
||||
*/
|
||||
function createUseQueries(client) {
|
||||
const untypedClient = client instanceof __trpc_client.TRPCUntypedClient ? client : (0, __trpc_client.getUntypedClient)(client);
|
||||
return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((opts) => {
|
||||
const arrayPath = opts.path;
|
||||
const dotPath = arrayPath.join(".");
|
||||
const [input, _opts] = opts.args;
|
||||
const options = (0, import_objectSpread2$3.default)({
|
||||
queryKey: require_getQueryKey.getQueryKeyInternal(arrayPath, input, "query"),
|
||||
queryFn: () => {
|
||||
return untypedClient.query(dotPath, input, _opts === null || _opts === void 0 ? void 0 : _opts.trpc);
|
||||
}
|
||||
}, _opts);
|
||||
return options;
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/getClientArgs.ts
|
||||
var import_objectSpread2$2 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2(), 1);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getClientArgs(queryKey, opts, infiniteParams) {
|
||||
var _queryKey$;
|
||||
const path = queryKey[0];
|
||||
let input = (_queryKey$ = queryKey[1]) === null || _queryKey$ === void 0 ? void 0 : _queryKey$.input;
|
||||
if (infiniteParams) {
|
||||
var _input;
|
||||
input = (0, import_objectSpread2$2.default)((0, import_objectSpread2$2.default)((0, import_objectSpread2$2.default)({}, (_input = input) !== null && _input !== void 0 ? _input : {}), infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {}), {}, { direction: infiniteParams.direction });
|
||||
}
|
||||
return [
|
||||
path.join("."),
|
||||
input,
|
||||
opts === null || opts === void 0 ? void 0 : opts.trpc
|
||||
];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js
|
||||
var require_asyncIterator = require_getQueryKey.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
||||
function _asyncIterator$1(r) {
|
||||
var n, t, o, e = 2;
|
||||
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
||||
if (t && null != (n = r[t])) return n.call(r);
|
||||
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
||||
t = "@@asyncIterator", o = "@@iterator";
|
||||
}
|
||||
throw new TypeError("Object is not async iterable");
|
||||
}
|
||||
function AsyncFromSyncIterator(r) {
|
||||
function AsyncFromSyncIteratorContinuation(r$1) {
|
||||
if (Object(r$1) !== r$1) return Promise.reject(new TypeError(r$1 + " is not an object."));
|
||||
var n = r$1.done;
|
||||
return Promise.resolve(r$1.value).then(function(r$2) {
|
||||
return {
|
||||
value: r$2,
|
||||
done: n
|
||||
};
|
||||
});
|
||||
}
|
||||
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
||||
this.s = r$1, this.n = r$1.next;
|
||||
}, AsyncFromSyncIterator.prototype = {
|
||||
s: null,
|
||||
n: null,
|
||||
next: function next() {
|
||||
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
||||
},
|
||||
"return": function _return(r$1) {
|
||||
var n = this.s["return"];
|
||||
return void 0 === n ? Promise.resolve({
|
||||
value: r$1,
|
||||
done: !0
|
||||
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
||||
},
|
||||
"throw": function _throw(r$1) {
|
||||
var n = this.s["return"];
|
||||
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
||||
}
|
||||
}, new AsyncFromSyncIterator(r);
|
||||
}
|
||||
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/trpcResult.ts
|
||||
var import_asyncIterator = require_getQueryKey.__toESM(require_asyncIterator(), 1);
|
||||
function createTRPCOptionsResult(value) {
|
||||
const path = value.path.join(".");
|
||||
return { path };
|
||||
}
|
||||
/**
|
||||
* Makes a stable reference of the `trpc` prop
|
||||
*/
|
||||
function useHookResult(value) {
|
||||
const result = createTRPCOptionsResult(value);
|
||||
return react.useMemo(() => result, [result]);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
||||
const queryCache = queryClient.getQueryCache();
|
||||
const query = queryCache.build(queryClient, { queryKey });
|
||||
query.setState({
|
||||
data: [],
|
||||
status: "success"
|
||||
});
|
||||
const aggregate = [];
|
||||
var _iteratorAbruptCompletion = false;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError;
|
||||
try {
|
||||
for (var _iterator = (0, import_asyncIterator.default)(asyncIterable), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
||||
const value = _step.value;
|
||||
{
|
||||
aggregate.push(value);
|
||||
query.setState({ data: [...aggregate] });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
||||
} finally {
|
||||
if (_didIteratorError) throw _iteratorError;
|
||||
}
|
||||
}
|
||||
return aggregate;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/createUtilityFunctions.ts
|
||||
var import_objectSpread2$1 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2(), 1);
|
||||
/**
|
||||
* Creates a set of utility functions that can be used to interact with `react-query`
|
||||
* @param opts the `TRPCClient` and `QueryClient` to use
|
||||
* @returns a set of utility functions that can be used to interact with `react-query`
|
||||
* @internal
|
||||
*/
|
||||
function createUtilityFunctions(opts) {
|
||||
const { client, queryClient } = opts;
|
||||
const untypedClient = client instanceof __trpc_client.TRPCUntypedClient ? client : (0, __trpc_client.getUntypedClient)(client);
|
||||
return {
|
||||
infiniteQueryOptions: (path, queryKey, opts$1) => {
|
||||
var _queryKey$, _ref;
|
||||
const inputIsSkipToken = ((_queryKey$ = queryKey[1]) === null || _queryKey$ === void 0 ? void 0 : _queryKey$.input) === __tanstack_react_query.skipToken;
|
||||
const queryFn = async (queryFnContext) => {
|
||||
var _opts$trpc;
|
||||
const actualOpts = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, { trpc: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.trpc), (opts$1 === null || opts$1 === void 0 || (_opts$trpc = opts$1.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
||||
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts, {
|
||||
direction: queryFnContext.direction,
|
||||
pageParam: queryFnContext.pageParam
|
||||
}));
|
||||
return result;
|
||||
};
|
||||
return Object.assign((0, __tanstack_react_query.infiniteQueryOptions)((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
initialData: opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialData,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? __tanstack_react_query.skipToken : queryFn,
|
||||
initialPageParam: (_ref = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _ref !== void 0 ? _ref : null
|
||||
})), { trpc: createTRPCOptionsResult({ path }) });
|
||||
},
|
||||
queryOptions: (path, queryKey, opts$1) => {
|
||||
var _queryKey$2;
|
||||
const inputIsSkipToken = ((_queryKey$2 = queryKey[1]) === null || _queryKey$2 === void 0 ? void 0 : _queryKey$2.input) === __tanstack_react_query.skipToken;
|
||||
const queryFn = async (queryFnContext) => {
|
||||
var _opts$trpc2;
|
||||
const actualOpts = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, { trpc: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.trpc), (opts$1 === null || opts$1 === void 0 || (_opts$trpc2 = opts$1.trpc) === null || _opts$trpc2 === void 0 ? void 0 : _opts$trpc2.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
||||
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts));
|
||||
if ((0, __trpc_server_unstable_core_do_not_import.isAsyncIterable)(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
||||
return result;
|
||||
};
|
||||
return Object.assign((0, __tanstack_react_query.queryOptions)((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
initialData: opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialData,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? __tanstack_react_query.skipToken : queryFn
|
||||
})), { trpc: createTRPCOptionsResult({ path }) });
|
||||
},
|
||||
fetchQuery: (queryKey, opts$1) => {
|
||||
return queryClient.fetchQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
fetchInfiniteQuery: (queryKey, opts$1) => {
|
||||
var _opts$initialCursor;
|
||||
return queryClient.fetchInfiniteQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(...getClientArgs(queryKey, opts$1, {
|
||||
pageParam,
|
||||
direction
|
||||
}));
|
||||
},
|
||||
initialPageParam: (_opts$initialCursor = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _opts$initialCursor !== void 0 ? _opts$initialCursor : null
|
||||
}));
|
||||
},
|
||||
prefetchQuery: (queryKey, opts$1) => {
|
||||
return queryClient.prefetchQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
prefetchInfiniteQuery: (queryKey, opts$1) => {
|
||||
var _opts$initialCursor2;
|
||||
return queryClient.prefetchInfiniteQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(...getClientArgs(queryKey, opts$1, {
|
||||
pageParam,
|
||||
direction
|
||||
}));
|
||||
},
|
||||
initialPageParam: (_opts$initialCursor2 = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _opts$initialCursor2 !== void 0 ? _opts$initialCursor2 : null
|
||||
}));
|
||||
},
|
||||
ensureQueryData: (queryKey, opts$1) => {
|
||||
return queryClient.ensureQueryData((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
invalidateQueries: (queryKey, filters, options) => {
|
||||
return queryClient.invalidateQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
resetQueries: (queryKey, filters, options) => {
|
||||
return queryClient.resetQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
refetchQueries: (queryKey, filters, options) => {
|
||||
return queryClient.refetchQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
cancelQuery: (queryKey, options) => {
|
||||
return queryClient.cancelQueries({ queryKey }, options);
|
||||
},
|
||||
setQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater, options);
|
||||
},
|
||||
setQueriesData: (queryKey, filters, updater, options) => {
|
||||
return queryClient.setQueriesData((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), updater, options);
|
||||
},
|
||||
getQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
setInfiniteQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater, options);
|
||||
},
|
||||
getInfiniteQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
setMutationDefaults: (mutationKey, options) => {
|
||||
const path = mutationKey[0];
|
||||
const canonicalMutationFn = (input) => {
|
||||
return untypedClient.mutation(...getClientArgs([path, { input }], opts));
|
||||
};
|
||||
return queryClient.setMutationDefaults(mutationKey, typeof options === "function" ? options({ canonicalMutationFn }) : options);
|
||||
},
|
||||
getMutationDefaults: (mutationKey) => {
|
||||
return queryClient.getMutationDefaults(mutationKey);
|
||||
},
|
||||
isMutating: (filters) => {
|
||||
return queryClient.isMutating((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { exact: true }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/hooks/createHooksInternal.tsx
|
||||
var import_objectSpread2 = require_getQueryKey.__toESM(require_getQueryKey.require_objectSpread2());
|
||||
const trackResult = (result, onTrackResult) => {
|
||||
const trackedResult = new Proxy(result, { get(target, prop) {
|
||||
onTrackResult(prop);
|
||||
return target[prop];
|
||||
} });
|
||||
return trackedResult;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createRootHooks(config) {
|
||||
var _config$overrides$use, _config$overrides, _config$context;
|
||||
const mutationSuccessOverride = (_config$overrides$use = config === null || config === void 0 || (_config$overrides = config.overrides) === null || _config$overrides === void 0 || (_config$overrides = _config$overrides.useMutation) === null || _config$overrides === void 0 ? void 0 : _config$overrides.onSuccess) !== null && _config$overrides$use !== void 0 ? _config$overrides$use : (options) => options.originalFn();
|
||||
const Context = (_config$context = config === null || config === void 0 ? void 0 : config.context) !== null && _config$context !== void 0 ? _config$context : TRPCContext;
|
||||
const createClient = __trpc_client.createTRPCClient;
|
||||
const TRPCProvider = (props) => {
|
||||
var _props$ssrState;
|
||||
const { abortOnUnmount = false, queryClient, ssrContext } = props;
|
||||
const [ssrState, setSSRState] = react.useState((_props$ssrState = props.ssrState) !== null && _props$ssrState !== void 0 ? _props$ssrState : false);
|
||||
const client = props.client instanceof __trpc_client.TRPCUntypedClient ? props.client : (0, __trpc_client.getUntypedClient)(props.client);
|
||||
const fns = react.useMemo(() => createUtilityFunctions({
|
||||
client,
|
||||
queryClient
|
||||
}), [client, queryClient]);
|
||||
const contextValue = react.useMemo(() => (0, import_objectSpread2.default)({
|
||||
abortOnUnmount,
|
||||
queryClient,
|
||||
client,
|
||||
ssrContext: ssrContext !== null && ssrContext !== void 0 ? ssrContext : null,
|
||||
ssrState
|
||||
}, fns), [
|
||||
abortOnUnmount,
|
||||
client,
|
||||
fns,
|
||||
queryClient,
|
||||
ssrContext,
|
||||
ssrState
|
||||
]);
|
||||
react.useEffect(() => {
|
||||
setSSRState((state) => state ? "mounted" : false);
|
||||
}, []);
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Context.Provider, {
|
||||
value: contextValue,
|
||||
children: props.children
|
||||
});
|
||||
};
|
||||
function useContext() {
|
||||
const context = react.useContext(Context);
|
||||
if (!context) throw new Error("Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?");
|
||||
return context;
|
||||
}
|
||||
/**
|
||||
* Hack to make sure errors return `status`='error` when doing SSR
|
||||
* @see https://github.com/trpc/trpc/pull/1645
|
||||
*/
|
||||
function useSSRQueryOptionsIfNeeded(queryKey, opts) {
|
||||
var _queryClient$getQuery;
|
||||
const { queryClient, ssrState } = useContext();
|
||||
return ssrState && ssrState !== "mounted" && ((_queryClient$getQuery = queryClient.getQueryCache().find({ queryKey })) === null || _queryClient$getQuery === void 0 ? void 0 : _queryClient$getQuery.state.status) === "error" ? (0, import_objectSpread2.default)({ retryOnMount: false }, opts) : opts;
|
||||
}
|
||||
function useQuery(path, input, opts) {
|
||||
var _opts$trpc, _opts$enabled, _ref, _opts$trpc$abortOnUnm, _opts$trpc2;
|
||||
const context = useContext();
|
||||
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === __tanstack_react_query.skipToken;
|
||||
if (typeof window === "undefined" && ssrState === "prepass" && (opts === null || opts === void 0 || (_opts$trpc = opts.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.ssr) !== false && ((_opts$enabled = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled !== void 0 ? _opts$enabled : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchQuery(queryKey, opts);
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_ref = (_opts$trpc$abortOnUnm = opts === null || opts === void 0 || (_opts$trpc2 = opts.trpc) === null || _opts$trpc2 === void 0 ? void 0 : _opts$trpc2.abortOnUnmount) !== null && _opts$trpc$abortOnUnm !== void 0 ? _opts$trpc$abortOnUnm : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref !== void 0 ? _ref : abortOnUnmount;
|
||||
const hook = (0, __tanstack_react_query.useQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, {
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : async (queryFunctionContext) => {
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
const result = await client.query(...getClientArgs(queryKey, actualOpts));
|
||||
if ((0, __trpc_server_unstable_core_do_not_import.isAsyncIterable)(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
||||
return result;
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
function usePrefetchQuery(path, input, opts) {
|
||||
var _ref2, _opts$trpc$abortOnUnm2, _opts$trpc3;
|
||||
const context = useContext();
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
|
||||
const isInputSkipToken = input === __tanstack_react_query.skipToken;
|
||||
const shouldAbortOnUnmount = (_ref2 = (_opts$trpc$abortOnUnm2 = opts === null || opts === void 0 || (_opts$trpc3 = opts.trpc) === null || _opts$trpc3 === void 0 ? void 0 : _opts$trpc3.abortOnUnmount) !== null && _opts$trpc$abortOnUnm2 !== void 0 ? _opts$trpc$abortOnUnm2 : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref2 !== void 0 ? _ref2 : context.abortOnUnmount;
|
||||
(0, __tanstack_react_query.usePrefetchQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
const actualOpts = { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts === null || opts === void 0 ? void 0 : opts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) };
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
}
|
||||
}));
|
||||
}
|
||||
function useSuspenseQuery(path, input, opts) {
|
||||
var _ref3, _opts$trpc$abortOnUnm3, _opts$trpc4;
|
||||
const context = useContext();
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
|
||||
const shouldAbortOnUnmount = (_ref3 = (_opts$trpc$abortOnUnm3 = opts === null || opts === void 0 || (_opts$trpc4 = opts.trpc) === null || _opts$trpc4 === void 0 ? void 0 : _opts$trpc4.abortOnUnmount) !== null && _opts$trpc$abortOnUnm3 !== void 0 ? _opts$trpc$abortOnUnm3 : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref3 !== void 0 ? _ref3 : context.abortOnUnmount;
|
||||
const hook = (0, __tanstack_react_query.useSuspenseQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
queryKey,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts === null || opts === void 0 ? void 0 : opts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
}
|
||||
}), context.queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return [hook.data, hook];
|
||||
}
|
||||
function useMutation(path, opts) {
|
||||
const { client, queryClient } = useContext();
|
||||
const mutationKey = require_getQueryKey.getMutationKeyInternal(path);
|
||||
const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
|
||||
const hook = (0, __tanstack_react_query.useMutation)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
mutationKey,
|
||||
mutationFn: (input) => {
|
||||
return client.mutation(...getClientArgs([path, { input }], opts));
|
||||
},
|
||||
onSuccess(...args) {
|
||||
var _ref4, _opts$meta;
|
||||
const originalFn = () => {
|
||||
var _opts$onSuccess, _opts$onSuccess2, _defaultOpts$onSucces;
|
||||
return (_opts$onSuccess = opts === null || opts === void 0 || (_opts$onSuccess2 = opts.onSuccess) === null || _opts$onSuccess2 === void 0 ? void 0 : _opts$onSuccess2.call(opts, ...args)) !== null && _opts$onSuccess !== void 0 ? _opts$onSuccess : defaultOpts === null || defaultOpts === void 0 || (_defaultOpts$onSucces = defaultOpts.onSuccess) === null || _defaultOpts$onSucces === void 0 ? void 0 : _defaultOpts$onSucces.call(defaultOpts, ...args);
|
||||
};
|
||||
return mutationSuccessOverride({
|
||||
originalFn,
|
||||
queryClient,
|
||||
meta: (_ref4 = (_opts$meta = opts === null || opts === void 0 ? void 0 : opts.meta) !== null && _opts$meta !== void 0 ? _opts$meta : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.meta) !== null && _ref4 !== void 0 ? _ref4 : {}
|
||||
});
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
const initialStateIdle = {
|
||||
data: void 0,
|
||||
error: null,
|
||||
status: "idle"
|
||||
};
|
||||
const initialStateConnecting = {
|
||||
data: void 0,
|
||||
error: null,
|
||||
status: "connecting"
|
||||
};
|
||||
/* istanbul ignore next -- @preserve */
|
||||
function useSubscription(path, input, opts) {
|
||||
var _opts$enabled2;
|
||||
const enabled = (_opts$enabled2 = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled2 !== void 0 ? _opts$enabled2 : input !== __tanstack_react_query.skipToken;
|
||||
const queryKey = (0, __tanstack_react_query.hashKey)(require_getQueryKey.getQueryKeyInternal(path, input, "any"));
|
||||
const { client } = useContext();
|
||||
const optsRef = react.useRef(opts);
|
||||
react.useEffect(() => {
|
||||
optsRef.current = opts;
|
||||
});
|
||||
const [trackedProps] = react.useState(new Set([]));
|
||||
const addTrackedProp = react.useCallback((key) => {
|
||||
trackedProps.add(key);
|
||||
}, [trackedProps]);
|
||||
const currentSubscriptionRef = react.useRef(null);
|
||||
const updateState = react.useCallback((callback) => {
|
||||
const prev = resultRef.current;
|
||||
const next = resultRef.current = callback(prev);
|
||||
let shouldUpdate = false;
|
||||
for (const key of trackedProps) if (prev[key] !== next[key]) {
|
||||
shouldUpdate = true;
|
||||
break;
|
||||
}
|
||||
if (shouldUpdate) setState(trackResult(next, addTrackedProp));
|
||||
}, [addTrackedProp, trackedProps]);
|
||||
const reset = react.useCallback(() => {
|
||||
var _currentSubscriptionR;
|
||||
(_currentSubscriptionR = currentSubscriptionRef.current) === null || _currentSubscriptionR === void 0 || _currentSubscriptionR.unsubscribe();
|
||||
if (!enabled) {
|
||||
updateState(() => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateIdle), {}, { reset }));
|
||||
return;
|
||||
}
|
||||
updateState(() => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateConnecting), {}, { reset }));
|
||||
const subscription = client.subscription(path.join("."), input !== null && input !== void 0 ? input : void 0, {
|
||||
onStarted: () => {
|
||||
var _optsRef$current$onSt, _optsRef$current;
|
||||
(_optsRef$current$onSt = (_optsRef$current = optsRef.current).onStarted) === null || _optsRef$current$onSt === void 0 || _optsRef$current$onSt.call(_optsRef$current);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "pending",
|
||||
error: null
|
||||
}));
|
||||
},
|
||||
onData: (data) => {
|
||||
var _optsRef$current$onDa, _optsRef$current2;
|
||||
(_optsRef$current$onDa = (_optsRef$current2 = optsRef.current).onData) === null || _optsRef$current$onDa === void 0 || _optsRef$current$onDa.call(_optsRef$current2, data);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "pending",
|
||||
data,
|
||||
error: null
|
||||
}));
|
||||
},
|
||||
onError: (error) => {
|
||||
var _optsRef$current$onEr, _optsRef$current3;
|
||||
(_optsRef$current$onEr = (_optsRef$current3 = optsRef.current).onError) === null || _optsRef$current$onEr === void 0 || _optsRef$current$onEr.call(_optsRef$current3, error);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "error",
|
||||
error
|
||||
}));
|
||||
},
|
||||
onConnectionStateChange: (result) => {
|
||||
updateState((prev) => {
|
||||
switch (result.state) {
|
||||
case "idle": return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: result.state,
|
||||
error: null,
|
||||
data: void 0
|
||||
});
|
||||
case "connecting": return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
error: result.error,
|
||||
status: result.state
|
||||
});
|
||||
case "pending": return prev;
|
||||
}
|
||||
});
|
||||
},
|
||||
onComplete: () => {
|
||||
var _optsRef$current$onCo, _optsRef$current4;
|
||||
(_optsRef$current$onCo = (_optsRef$current4 = optsRef.current).onComplete) === null || _optsRef$current$onCo === void 0 || _optsRef$current$onCo.call(_optsRef$current4);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "idle",
|
||||
error: null,
|
||||
data: void 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
currentSubscriptionRef.current = subscription;
|
||||
}, [
|
||||
client,
|
||||
queryKey,
|
||||
enabled,
|
||||
updateState
|
||||
]);
|
||||
react.useEffect(() => {
|
||||
reset();
|
||||
return () => {
|
||||
var _currentSubscriptionR2;
|
||||
(_currentSubscriptionR2 = currentSubscriptionRef.current) === null || _currentSubscriptionR2 === void 0 || _currentSubscriptionR2.unsubscribe();
|
||||
};
|
||||
}, [reset]);
|
||||
const resultRef = react.useRef(enabled ? (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateConnecting), {}, { reset }) : (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateIdle), {}, { reset }));
|
||||
const [state, setState] = react.useState(trackResult(resultRef.current, addTrackedProp));
|
||||
return state;
|
||||
}
|
||||
function useInfiniteQuery(path, input, opts) {
|
||||
var _opts$trpc5, _opts$enabled3, _opts$trpc$abortOnUnm4, _opts$trpc6, _opts$initialCursor;
|
||||
const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount } = useContext();
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === __tanstack_react_query.skipToken;
|
||||
if (typeof window === "undefined" && ssrState === "prepass" && (opts === null || opts === void 0 || (_opts$trpc5 = opts.trpc) === null || _opts$trpc5 === void 0 ? void 0 : _opts$trpc5.ssr) !== false && ((_opts$enabled3 = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled3 !== void 0 ? _opts$enabled3 : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchInfiniteQuery(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm4 = opts === null || opts === void 0 || (_opts$trpc6 = opts.trpc) === null || _opts$trpc6 === void 0 ? void 0 : _opts$trpc6.abortOnUnmount) !== null && _opts$trpc$abortOnUnm4 !== void 0 ? _opts$trpc$abortOnUnm4 : abortOnUnmount;
|
||||
const hook = (0, __tanstack_react_query.useInfiniteQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, {
|
||||
initialPageParam: (_opts$initialCursor = opts.initialCursor) !== null && _opts$initialCursor !== void 0 ? _opts$initialCursor : null,
|
||||
persister: opts.persister,
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
var _queryFunctionContext;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
return client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext = queryFunctionContext.pageParam) !== null && _queryFunctionContext !== void 0 ? _queryFunctionContext : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
function usePrefetchInfiniteQuery(path, input, opts) {
|
||||
var _opts$trpc$abortOnUnm5, _opts$trpc7, _opts$initialCursor2;
|
||||
const context = useContext();
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === __tanstack_react_query.skipToken;
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm5 = opts === null || opts === void 0 || (_opts$trpc7 = opts.trpc) === null || _opts$trpc7 === void 0 ? void 0 : _opts$trpc7.abortOnUnmount) !== null && _opts$trpc$abortOnUnm5 !== void 0 ? _opts$trpc$abortOnUnm5 : context.abortOnUnmount;
|
||||
(0, __tanstack_react_query.usePrefetchInfiniteQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
initialPageParam: (_opts$initialCursor2 = opts.initialCursor) !== null && _opts$initialCursor2 !== void 0 ? _opts$initialCursor2 : null,
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
var _queryFunctionContext2;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext2 = queryFunctionContext.pageParam) !== null && _queryFunctionContext2 !== void 0 ? _queryFunctionContext2 : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
function useSuspenseInfiniteQuery(path, input, opts) {
|
||||
var _opts$trpc$abortOnUnm6, _opts$trpc8, _opts$initialCursor3;
|
||||
const context = useContext();
|
||||
const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm6 = opts === null || opts === void 0 || (_opts$trpc8 = opts.trpc) === null || _opts$trpc8 === void 0 ? void 0 : _opts$trpc8.abortOnUnmount) !== null && _opts$trpc$abortOnUnm6 !== void 0 ? _opts$trpc$abortOnUnm6 : context.abortOnUnmount;
|
||||
const hook = (0, __tanstack_react_query.useSuspenseInfiniteQuery)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
initialPageParam: (_opts$initialCursor3 = opts.initialCursor) !== null && _opts$initialCursor3 !== void 0 ? _opts$initialCursor3 : null,
|
||||
queryKey,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
var _queryFunctionContext3;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext3 = queryFunctionContext.pageParam) !== null && _queryFunctionContext3 !== void 0 ? _queryFunctionContext3 : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}), context.queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return [hook.data, hook];
|
||||
}
|
||||
const useQueries = (queriesCallback, options) => {
|
||||
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
||||
const proxy = createUseQueries(client);
|
||||
const queries = queriesCallback(proxy);
|
||||
if (typeof window === "undefined" && ssrState === "prepass") for (const query of queries) {
|
||||
var _queryOption$trpc;
|
||||
const queryOption = query;
|
||||
if (((_queryOption$trpc = queryOption.trpc) === null || _queryOption$trpc === void 0 ? void 0 : _queryOption$trpc.ssr) !== false && !queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })) prefetchQuery(queryOption.queryKey, queryOption);
|
||||
}
|
||||
return (0, __tanstack_react_query.useQueries)({
|
||||
queries: queries.map((query) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, query), {}, { queryKey: query.queryKey })),
|
||||
combine: options === null || options === void 0 ? void 0 : options.combine
|
||||
}, queryClient);
|
||||
};
|
||||
const useSuspenseQueries = (queriesCallback) => {
|
||||
const { queryClient, client } = useContext();
|
||||
const proxy = createUseQueries(client);
|
||||
const queries = queriesCallback(proxy);
|
||||
const hook = (0, __tanstack_react_query.useSuspenseQueries)({ queries: queries.map((query) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, query), {}, {
|
||||
queryFn: query.queryFn,
|
||||
queryKey: query.queryKey
|
||||
})) }, queryClient);
|
||||
return [hook.map((h) => h.data), hook];
|
||||
};
|
||||
return {
|
||||
Provider: TRPCProvider,
|
||||
createClient,
|
||||
useContext,
|
||||
useUtils: useContext,
|
||||
useQuery,
|
||||
usePrefetchQuery,
|
||||
useSuspenseQuery,
|
||||
useQueries,
|
||||
useSuspenseQueries,
|
||||
useMutation,
|
||||
useSubscription,
|
||||
useInfiniteQuery,
|
||||
usePrefetchInfiniteQuery,
|
||||
useSuspenseInfiniteQuery
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/queryClient.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const getQueryClient = (config) => {
|
||||
var _config$queryClient;
|
||||
return (_config$queryClient = config.queryClient) !== null && _config$queryClient !== void 0 ? _config$queryClient : new __tanstack_react_query.QueryClient(config.queryClientConfig);
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'TRPCContext', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return TRPCContext;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'contextProps', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return contextProps;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createQueryUtilsProxy', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createQueryUtilsProxy;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createReactDecoration', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createReactDecoration;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createReactQueryUtils', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createReactQueryUtils;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createRootHooks', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createRootHooks;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createUseQueries', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createUseQueries;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createUtilityFunctions', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createUtilityFunctions;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getClientArgs', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getClientArgs;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getQueryClient', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getQueryClient;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getQueryType', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getQueryType;
|
||||
}
|
||||
});
|
||||
+772
@@ -0,0 +1,772 @@
|
||||
import { __commonJS, __toESM, getMutationKeyInternal, getQueryKeyInternal, require_objectSpread2 } from "./getQueryKey-BY58RNzP.mjs";
|
||||
import { TRPCUntypedClient, createTRPCClient, createTRPCClientProxy, getUntypedClient } from "@trpc/client";
|
||||
import { QueryClient, hashKey, infiniteQueryOptions, queryOptions, skipToken, useInfiniteQuery, useMutation, usePrefetchInfiniteQuery, usePrefetchQuery, useQueries, useQuery, useSuspenseInfiniteQuery, useSuspenseQueries, useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { createFlatProxy, createRecursiveProxy, isAsyncIterable } from "@trpc/server/unstable-core-do-not-import";
|
||||
import * as React$2 from "react";
|
||||
import * as React$1 from "react";
|
||||
import * as React from "react";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
|
||||
//#region src/shared/proxy/decorationProxy.ts
|
||||
/**
|
||||
* Create proxy for decorating procedures
|
||||
* @internal
|
||||
*/
|
||||
function createReactDecoration(hooks) {
|
||||
return createRecursiveProxy(({ path, args }) => {
|
||||
var _rest$;
|
||||
const pathCopy = [...path];
|
||||
const lastArg = pathCopy.pop();
|
||||
if (lastArg === "useMutation") return hooks[lastArg](pathCopy, ...args);
|
||||
if (lastArg === "_def") return { path: pathCopy };
|
||||
const [input, ...rest] = args;
|
||||
const opts = (_rest$ = rest[0]) !== null && _rest$ !== void 0 ? _rest$ : {};
|
||||
return hooks[lastArg](pathCopy, input, opts);
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/context.tsx
|
||||
var _React$createContext;
|
||||
const contextProps = [
|
||||
"client",
|
||||
"ssrContext",
|
||||
"ssrState",
|
||||
"abortOnUnmount"
|
||||
];
|
||||
const TRPCContext = (_React$createContext = React$2.createContext) === null || _React$createContext === void 0 ? void 0 : _React$createContext.call(React$2, null);
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/proxy/utilsProxy.ts
|
||||
const getQueryType = (utilName) => {
|
||||
switch (utilName) {
|
||||
case "queryOptions":
|
||||
case "fetch":
|
||||
case "ensureData":
|
||||
case "prefetch":
|
||||
case "getData":
|
||||
case "setData":
|
||||
case "setQueriesData": return "query";
|
||||
case "infiniteQueryOptions":
|
||||
case "fetchInfinite":
|
||||
case "prefetchInfinite":
|
||||
case "getInfiniteData":
|
||||
case "setInfiniteData": return "infinite";
|
||||
case "setMutationDefaults":
|
||||
case "getMutationDefaults":
|
||||
case "isMutating":
|
||||
case "cancel":
|
||||
case "invalidate":
|
||||
case "refetch":
|
||||
case "reset": return "any";
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createRecursiveUtilsProxy(context) {
|
||||
return createRecursiveProxy((opts) => {
|
||||
const path = [...opts.path];
|
||||
const utilName = path.pop();
|
||||
const args = [...opts.args];
|
||||
const input = args.shift();
|
||||
const queryType = getQueryType(utilName);
|
||||
const queryKey = getQueryKeyInternal(path, input, queryType);
|
||||
const contextMap = {
|
||||
infiniteQueryOptions: () => context.infiniteQueryOptions(path, queryKey, args[0]),
|
||||
queryOptions: () => context.queryOptions(path, queryKey, ...args),
|
||||
fetch: () => context.fetchQuery(queryKey, ...args),
|
||||
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
||||
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
||||
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
|
||||
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
||||
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
||||
reset: () => context.resetQueries(queryKey, ...args),
|
||||
refetch: () => context.refetchQueries(queryKey, ...args),
|
||||
cancel: () => context.cancelQuery(queryKey, ...args),
|
||||
setData: () => {
|
||||
context.setQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
setQueriesData: () => context.setQueriesData(queryKey, args[0], args[1], args[2]),
|
||||
setInfiniteData: () => {
|
||||
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
getData: () => context.getQueryData(queryKey),
|
||||
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
||||
setMutationDefaults: () => context.setMutationDefaults(getMutationKeyInternal(path), input),
|
||||
getMutationDefaults: () => context.getMutationDefaults(getMutationKeyInternal(path)),
|
||||
isMutating: () => context.isMutating({ mutationKey: getMutationKeyInternal(path) })
|
||||
};
|
||||
return contextMap[utilName]();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createReactQueryUtils(context) {
|
||||
const clientProxy = createTRPCClientProxy(context.client);
|
||||
const proxy = createRecursiveUtilsProxy(context);
|
||||
return createFlatProxy((key) => {
|
||||
const contextName = key;
|
||||
if (contextName === "client") return clientProxy;
|
||||
if (contextProps.includes(contextName)) return context[contextName];
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createQueryUtilsProxy(context) {
|
||||
return createRecursiveUtilsProxy(context);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/proxy/useQueriesProxy.ts
|
||||
var import_objectSpread2$3 = __toESM(require_objectSpread2(), 1);
|
||||
/**
|
||||
* Create proxy for `useQueries` options
|
||||
* @internal
|
||||
*/
|
||||
function createUseQueries(client) {
|
||||
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
return createRecursiveProxy((opts) => {
|
||||
const arrayPath = opts.path;
|
||||
const dotPath = arrayPath.join(".");
|
||||
const [input, _opts] = opts.args;
|
||||
const options = (0, import_objectSpread2$3.default)({
|
||||
queryKey: getQueryKeyInternal(arrayPath, input, "query"),
|
||||
queryFn: () => {
|
||||
return untypedClient.query(dotPath, input, _opts === null || _opts === void 0 ? void 0 : _opts.trpc);
|
||||
}
|
||||
}, _opts);
|
||||
return options;
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/getClientArgs.ts
|
||||
var import_objectSpread2$2 = __toESM(require_objectSpread2(), 1);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getClientArgs(queryKey, opts, infiniteParams) {
|
||||
var _queryKey$;
|
||||
const path = queryKey[0];
|
||||
let input = (_queryKey$ = queryKey[1]) === null || _queryKey$ === void 0 ? void 0 : _queryKey$.input;
|
||||
if (infiniteParams) {
|
||||
var _input;
|
||||
input = (0, import_objectSpread2$2.default)((0, import_objectSpread2$2.default)((0, import_objectSpread2$2.default)({}, (_input = input) !== null && _input !== void 0 ? _input : {}), infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {}), {}, { direction: infiniteParams.direction });
|
||||
}
|
||||
return [
|
||||
path.join("."),
|
||||
input,
|
||||
opts === null || opts === void 0 ? void 0 : opts.trpc
|
||||
];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js
|
||||
var require_asyncIterator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
||||
function _asyncIterator$1(r) {
|
||||
var n, t, o, e = 2;
|
||||
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
||||
if (t && null != (n = r[t])) return n.call(r);
|
||||
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
||||
t = "@@asyncIterator", o = "@@iterator";
|
||||
}
|
||||
throw new TypeError("Object is not async iterable");
|
||||
}
|
||||
function AsyncFromSyncIterator(r) {
|
||||
function AsyncFromSyncIteratorContinuation(r$1) {
|
||||
if (Object(r$1) !== r$1) return Promise.reject(new TypeError(r$1 + " is not an object."));
|
||||
var n = r$1.done;
|
||||
return Promise.resolve(r$1.value).then(function(r$2) {
|
||||
return {
|
||||
value: r$2,
|
||||
done: n
|
||||
};
|
||||
});
|
||||
}
|
||||
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
||||
this.s = r$1, this.n = r$1.next;
|
||||
}, AsyncFromSyncIterator.prototype = {
|
||||
s: null,
|
||||
n: null,
|
||||
next: function next() {
|
||||
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
||||
},
|
||||
"return": function _return(r$1) {
|
||||
var n = this.s["return"];
|
||||
return void 0 === n ? Promise.resolve({
|
||||
value: r$1,
|
||||
done: !0
|
||||
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
||||
},
|
||||
"throw": function _throw(r$1) {
|
||||
var n = this.s["return"];
|
||||
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
||||
}
|
||||
}, new AsyncFromSyncIterator(r);
|
||||
}
|
||||
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
} });
|
||||
|
||||
//#endregion
|
||||
//#region src/internals/trpcResult.ts
|
||||
var import_asyncIterator = __toESM(require_asyncIterator(), 1);
|
||||
function createTRPCOptionsResult(value) {
|
||||
const path = value.path.join(".");
|
||||
return { path };
|
||||
}
|
||||
/**
|
||||
* Makes a stable reference of the `trpc` prop
|
||||
*/
|
||||
function useHookResult(value) {
|
||||
const result = createTRPCOptionsResult(value);
|
||||
return React$1.useMemo(() => result, [result]);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
||||
const queryCache = queryClient.getQueryCache();
|
||||
const query = queryCache.build(queryClient, { queryKey });
|
||||
query.setState({
|
||||
data: [],
|
||||
status: "success"
|
||||
});
|
||||
const aggregate = [];
|
||||
var _iteratorAbruptCompletion = false;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError;
|
||||
try {
|
||||
for (var _iterator = (0, import_asyncIterator.default)(asyncIterable), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
||||
const value = _step.value;
|
||||
{
|
||||
aggregate.push(value);
|
||||
query.setState({ data: [...aggregate] });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
||||
} finally {
|
||||
if (_didIteratorError) throw _iteratorError;
|
||||
}
|
||||
}
|
||||
return aggregate;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/createUtilityFunctions.ts
|
||||
var import_objectSpread2$1 = __toESM(require_objectSpread2(), 1);
|
||||
/**
|
||||
* Creates a set of utility functions that can be used to interact with `react-query`
|
||||
* @param opts the `TRPCClient` and `QueryClient` to use
|
||||
* @returns a set of utility functions that can be used to interact with `react-query`
|
||||
* @internal
|
||||
*/
|
||||
function createUtilityFunctions(opts) {
|
||||
const { client, queryClient } = opts;
|
||||
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
return {
|
||||
infiniteQueryOptions: (path, queryKey, opts$1) => {
|
||||
var _queryKey$, _ref;
|
||||
const inputIsSkipToken = ((_queryKey$ = queryKey[1]) === null || _queryKey$ === void 0 ? void 0 : _queryKey$.input) === skipToken;
|
||||
const queryFn = async (queryFnContext) => {
|
||||
var _opts$trpc;
|
||||
const actualOpts = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, { trpc: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.trpc), (opts$1 === null || opts$1 === void 0 || (_opts$trpc = opts$1.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
||||
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts, {
|
||||
direction: queryFnContext.direction,
|
||||
pageParam: queryFnContext.pageParam
|
||||
}));
|
||||
return result;
|
||||
};
|
||||
return Object.assign(infiniteQueryOptions((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
initialData: opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialData,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
||||
initialPageParam: (_ref = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _ref !== void 0 ? _ref : null
|
||||
})), { trpc: createTRPCOptionsResult({ path }) });
|
||||
},
|
||||
queryOptions: (path, queryKey, opts$1) => {
|
||||
var _queryKey$2;
|
||||
const inputIsSkipToken = ((_queryKey$2 = queryKey[1]) === null || _queryKey$2 === void 0 ? void 0 : _queryKey$2.input) === skipToken;
|
||||
const queryFn = async (queryFnContext) => {
|
||||
var _opts$trpc2;
|
||||
const actualOpts = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, { trpc: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.trpc), (opts$1 === null || opts$1 === void 0 || (_opts$trpc2 = opts$1.trpc) === null || _opts$trpc2 === void 0 ? void 0 : _opts$trpc2.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
||||
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts));
|
||||
if (isAsyncIterable(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
||||
return result;
|
||||
};
|
||||
return Object.assign(queryOptions((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
initialData: opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialData,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? skipToken : queryFn
|
||||
})), { trpc: createTRPCOptionsResult({ path }) });
|
||||
},
|
||||
fetchQuery: (queryKey, opts$1) => {
|
||||
return queryClient.fetchQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
fetchInfiniteQuery: (queryKey, opts$1) => {
|
||||
var _opts$initialCursor;
|
||||
return queryClient.fetchInfiniteQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(...getClientArgs(queryKey, opts$1, {
|
||||
pageParam,
|
||||
direction
|
||||
}));
|
||||
},
|
||||
initialPageParam: (_opts$initialCursor = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _opts$initialCursor !== void 0 ? _opts$initialCursor : null
|
||||
}));
|
||||
},
|
||||
prefetchQuery: (queryKey, opts$1) => {
|
||||
return queryClient.prefetchQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
prefetchInfiniteQuery: (queryKey, opts$1) => {
|
||||
var _opts$initialCursor2;
|
||||
return queryClient.prefetchInfiniteQuery((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(...getClientArgs(queryKey, opts$1, {
|
||||
pageParam,
|
||||
direction
|
||||
}));
|
||||
},
|
||||
initialPageParam: (_opts$initialCursor2 = opts$1 === null || opts$1 === void 0 ? void 0 : opts$1.initialCursor) !== null && _opts$initialCursor2 !== void 0 ? _opts$initialCursor2 : null
|
||||
}));
|
||||
},
|
||||
ensureQueryData: (queryKey, opts$1) => {
|
||||
return queryClient.ensureQueryData((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts$1), {}, {
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
|
||||
}));
|
||||
},
|
||||
invalidateQueries: (queryKey, filters, options) => {
|
||||
return queryClient.invalidateQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
resetQueries: (queryKey, filters, options) => {
|
||||
return queryClient.resetQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
refetchQueries: (queryKey, filters, options) => {
|
||||
return queryClient.refetchQueries((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), options);
|
||||
},
|
||||
cancelQuery: (queryKey, options) => {
|
||||
return queryClient.cancelQueries({ queryKey }, options);
|
||||
},
|
||||
setQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater, options);
|
||||
},
|
||||
setQueriesData: (queryKey, filters, updater, options) => {
|
||||
return queryClient.setQueriesData((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { queryKey }), updater, options);
|
||||
},
|
||||
getQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
setInfiniteQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater, options);
|
||||
},
|
||||
getInfiniteQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
setMutationDefaults: (mutationKey, options) => {
|
||||
const path = mutationKey[0];
|
||||
const canonicalMutationFn = (input) => {
|
||||
return untypedClient.mutation(...getClientArgs([path, { input }], opts));
|
||||
};
|
||||
return queryClient.setMutationDefaults(mutationKey, typeof options === "function" ? options({ canonicalMutationFn }) : options);
|
||||
},
|
||||
getMutationDefaults: (mutationKey) => {
|
||||
return queryClient.getMutationDefaults(mutationKey);
|
||||
},
|
||||
isMutating: (filters) => {
|
||||
return queryClient.isMutating((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, filters), {}, { exact: true }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/hooks/createHooksInternal.tsx
|
||||
var import_objectSpread2 = __toESM(require_objectSpread2());
|
||||
const trackResult = (result, onTrackResult) => {
|
||||
const trackedResult = new Proxy(result, { get(target, prop) {
|
||||
onTrackResult(prop);
|
||||
return target[prop];
|
||||
} });
|
||||
return trackedResult;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createRootHooks(config) {
|
||||
var _config$overrides$use, _config$overrides, _config$context;
|
||||
const mutationSuccessOverride = (_config$overrides$use = config === null || config === void 0 || (_config$overrides = config.overrides) === null || _config$overrides === void 0 || (_config$overrides = _config$overrides.useMutation) === null || _config$overrides === void 0 ? void 0 : _config$overrides.onSuccess) !== null && _config$overrides$use !== void 0 ? _config$overrides$use : (options) => options.originalFn();
|
||||
const Context = (_config$context = config === null || config === void 0 ? void 0 : config.context) !== null && _config$context !== void 0 ? _config$context : TRPCContext;
|
||||
const createClient = createTRPCClient;
|
||||
const TRPCProvider = (props) => {
|
||||
var _props$ssrState;
|
||||
const { abortOnUnmount = false, queryClient, ssrContext } = props;
|
||||
const [ssrState, setSSRState] = React.useState((_props$ssrState = props.ssrState) !== null && _props$ssrState !== void 0 ? _props$ssrState : false);
|
||||
const client = props.client instanceof TRPCUntypedClient ? props.client : getUntypedClient(props.client);
|
||||
const fns = React.useMemo(() => createUtilityFunctions({
|
||||
client,
|
||||
queryClient
|
||||
}), [client, queryClient]);
|
||||
const contextValue = React.useMemo(() => (0, import_objectSpread2.default)({
|
||||
abortOnUnmount,
|
||||
queryClient,
|
||||
client,
|
||||
ssrContext: ssrContext !== null && ssrContext !== void 0 ? ssrContext : null,
|
||||
ssrState
|
||||
}, fns), [
|
||||
abortOnUnmount,
|
||||
client,
|
||||
fns,
|
||||
queryClient,
|
||||
ssrContext,
|
||||
ssrState
|
||||
]);
|
||||
React.useEffect(() => {
|
||||
setSSRState((state) => state ? "mounted" : false);
|
||||
}, []);
|
||||
return /* @__PURE__ */ jsx(Context.Provider, {
|
||||
value: contextValue,
|
||||
children: props.children
|
||||
});
|
||||
};
|
||||
function useContext() {
|
||||
const context = React.useContext(Context);
|
||||
if (!context) throw new Error("Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?");
|
||||
return context;
|
||||
}
|
||||
/**
|
||||
* Hack to make sure errors return `status`='error` when doing SSR
|
||||
* @see https://github.com/trpc/trpc/pull/1645
|
||||
*/
|
||||
function useSSRQueryOptionsIfNeeded(queryKey, opts) {
|
||||
var _queryClient$getQuery;
|
||||
const { queryClient, ssrState } = useContext();
|
||||
return ssrState && ssrState !== "mounted" && ((_queryClient$getQuery = queryClient.getQueryCache().find({ queryKey })) === null || _queryClient$getQuery === void 0 ? void 0 : _queryClient$getQuery.state.status) === "error" ? (0, import_objectSpread2.default)({ retryOnMount: false }, opts) : opts;
|
||||
}
|
||||
function useQuery$1(path, input, opts) {
|
||||
var _opts$trpc, _opts$enabled, _ref, _opts$trpc$abortOnUnm, _opts$trpc2;
|
||||
const context = useContext();
|
||||
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
|
||||
const queryKey = getQueryKeyInternal(path, input, "query");
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === skipToken;
|
||||
if (typeof window === "undefined" && ssrState === "prepass" && (opts === null || opts === void 0 || (_opts$trpc = opts.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.ssr) !== false && ((_opts$enabled = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled !== void 0 ? _opts$enabled : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchQuery(queryKey, opts);
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_ref = (_opts$trpc$abortOnUnm = opts === null || opts === void 0 || (_opts$trpc2 = opts.trpc) === null || _opts$trpc2 === void 0 ? void 0 : _opts$trpc2.abortOnUnmount) !== null && _opts$trpc$abortOnUnm !== void 0 ? _opts$trpc$abortOnUnm : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref !== void 0 ? _ref : abortOnUnmount;
|
||||
const hook = useQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, {
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : async (queryFunctionContext) => {
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
const result = await client.query(...getClientArgs(queryKey, actualOpts));
|
||||
if (isAsyncIterable(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
||||
return result;
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
function usePrefetchQuery$1(path, input, opts) {
|
||||
var _ref2, _opts$trpc$abortOnUnm2, _opts$trpc3;
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, "query");
|
||||
const isInputSkipToken = input === skipToken;
|
||||
const shouldAbortOnUnmount = (_ref2 = (_opts$trpc$abortOnUnm2 = opts === null || opts === void 0 || (_opts$trpc3 = opts.trpc) === null || _opts$trpc3 === void 0 ? void 0 : _opts$trpc3.abortOnUnmount) !== null && _opts$trpc$abortOnUnm2 !== void 0 ? _opts$trpc$abortOnUnm2 : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref2 !== void 0 ? _ref2 : context.abortOnUnmount;
|
||||
usePrefetchQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
const actualOpts = { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts === null || opts === void 0 ? void 0 : opts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) };
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
}
|
||||
}));
|
||||
}
|
||||
function useSuspenseQuery$1(path, input, opts) {
|
||||
var _ref3, _opts$trpc$abortOnUnm3, _opts$trpc4;
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, "query");
|
||||
const shouldAbortOnUnmount = (_ref3 = (_opts$trpc$abortOnUnm3 = opts === null || opts === void 0 || (_opts$trpc4 = opts.trpc) === null || _opts$trpc4 === void 0 ? void 0 : _opts$trpc4.abortOnUnmount) !== null && _opts$trpc$abortOnUnm3 !== void 0 ? _opts$trpc$abortOnUnm3 : config === null || config === void 0 ? void 0 : config.abortOnUnmount) !== null && _ref3 !== void 0 ? _ref3 : context.abortOnUnmount;
|
||||
const hook = useSuspenseQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
queryKey,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts === null || opts === void 0 ? void 0 : opts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
}
|
||||
}), context.queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return [hook.data, hook];
|
||||
}
|
||||
function useMutation$1(path, opts) {
|
||||
const { client, queryClient } = useContext();
|
||||
const mutationKey = getMutationKeyInternal(path);
|
||||
const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
|
||||
const hook = useMutation((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
mutationKey,
|
||||
mutationFn: (input) => {
|
||||
return client.mutation(...getClientArgs([path, { input }], opts));
|
||||
},
|
||||
onSuccess(...args) {
|
||||
var _ref4, _opts$meta;
|
||||
const originalFn = () => {
|
||||
var _opts$onSuccess, _opts$onSuccess2, _defaultOpts$onSucces;
|
||||
return (_opts$onSuccess = opts === null || opts === void 0 || (_opts$onSuccess2 = opts.onSuccess) === null || _opts$onSuccess2 === void 0 ? void 0 : _opts$onSuccess2.call(opts, ...args)) !== null && _opts$onSuccess !== void 0 ? _opts$onSuccess : defaultOpts === null || defaultOpts === void 0 || (_defaultOpts$onSucces = defaultOpts.onSuccess) === null || _defaultOpts$onSucces === void 0 ? void 0 : _defaultOpts$onSucces.call(defaultOpts, ...args);
|
||||
};
|
||||
return mutationSuccessOverride({
|
||||
originalFn,
|
||||
queryClient,
|
||||
meta: (_ref4 = (_opts$meta = opts === null || opts === void 0 ? void 0 : opts.meta) !== null && _opts$meta !== void 0 ? _opts$meta : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.meta) !== null && _ref4 !== void 0 ? _ref4 : {}
|
||||
});
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
const initialStateIdle = {
|
||||
data: void 0,
|
||||
error: null,
|
||||
status: "idle"
|
||||
};
|
||||
const initialStateConnecting = {
|
||||
data: void 0,
|
||||
error: null,
|
||||
status: "connecting"
|
||||
};
|
||||
/* istanbul ignore next -- @preserve */
|
||||
function useSubscription(path, input, opts) {
|
||||
var _opts$enabled2;
|
||||
const enabled = (_opts$enabled2 = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled2 !== void 0 ? _opts$enabled2 : input !== skipToken;
|
||||
const queryKey = hashKey(getQueryKeyInternal(path, input, "any"));
|
||||
const { client } = useContext();
|
||||
const optsRef = React.useRef(opts);
|
||||
React.useEffect(() => {
|
||||
optsRef.current = opts;
|
||||
});
|
||||
const [trackedProps] = React.useState(new Set([]));
|
||||
const addTrackedProp = React.useCallback((key) => {
|
||||
trackedProps.add(key);
|
||||
}, [trackedProps]);
|
||||
const currentSubscriptionRef = React.useRef(null);
|
||||
const updateState = React.useCallback((callback) => {
|
||||
const prev = resultRef.current;
|
||||
const next = resultRef.current = callback(prev);
|
||||
let shouldUpdate = false;
|
||||
for (const key of trackedProps) if (prev[key] !== next[key]) {
|
||||
shouldUpdate = true;
|
||||
break;
|
||||
}
|
||||
if (shouldUpdate) setState(trackResult(next, addTrackedProp));
|
||||
}, [addTrackedProp, trackedProps]);
|
||||
const reset = React.useCallback(() => {
|
||||
var _currentSubscriptionR;
|
||||
(_currentSubscriptionR = currentSubscriptionRef.current) === null || _currentSubscriptionR === void 0 || _currentSubscriptionR.unsubscribe();
|
||||
if (!enabled) {
|
||||
updateState(() => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateIdle), {}, { reset }));
|
||||
return;
|
||||
}
|
||||
updateState(() => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateConnecting), {}, { reset }));
|
||||
const subscription = client.subscription(path.join("."), input !== null && input !== void 0 ? input : void 0, {
|
||||
onStarted: () => {
|
||||
var _optsRef$current$onSt, _optsRef$current;
|
||||
(_optsRef$current$onSt = (_optsRef$current = optsRef.current).onStarted) === null || _optsRef$current$onSt === void 0 || _optsRef$current$onSt.call(_optsRef$current);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "pending",
|
||||
error: null
|
||||
}));
|
||||
},
|
||||
onData: (data) => {
|
||||
var _optsRef$current$onDa, _optsRef$current2;
|
||||
(_optsRef$current$onDa = (_optsRef$current2 = optsRef.current).onData) === null || _optsRef$current$onDa === void 0 || _optsRef$current$onDa.call(_optsRef$current2, data);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "pending",
|
||||
data,
|
||||
error: null
|
||||
}));
|
||||
},
|
||||
onError: (error) => {
|
||||
var _optsRef$current$onEr, _optsRef$current3;
|
||||
(_optsRef$current$onEr = (_optsRef$current3 = optsRef.current).onError) === null || _optsRef$current$onEr === void 0 || _optsRef$current$onEr.call(_optsRef$current3, error);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "error",
|
||||
error
|
||||
}));
|
||||
},
|
||||
onConnectionStateChange: (result) => {
|
||||
updateState((prev) => {
|
||||
switch (result.state) {
|
||||
case "idle": return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: result.state,
|
||||
error: null,
|
||||
data: void 0
|
||||
});
|
||||
case "connecting": return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
error: result.error,
|
||||
status: result.state
|
||||
});
|
||||
case "pending": return prev;
|
||||
}
|
||||
});
|
||||
},
|
||||
onComplete: () => {
|
||||
var _optsRef$current$onCo, _optsRef$current4;
|
||||
(_optsRef$current$onCo = (_optsRef$current4 = optsRef.current).onComplete) === null || _optsRef$current$onCo === void 0 || _optsRef$current$onCo.call(_optsRef$current4);
|
||||
updateState((prev) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, prev), {}, {
|
||||
status: "idle",
|
||||
error: null,
|
||||
data: void 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
currentSubscriptionRef.current = subscription;
|
||||
}, [
|
||||
client,
|
||||
queryKey,
|
||||
enabled,
|
||||
updateState
|
||||
]);
|
||||
React.useEffect(() => {
|
||||
reset();
|
||||
return () => {
|
||||
var _currentSubscriptionR2;
|
||||
(_currentSubscriptionR2 = currentSubscriptionRef.current) === null || _currentSubscriptionR2 === void 0 || _currentSubscriptionR2.unsubscribe();
|
||||
};
|
||||
}, [reset]);
|
||||
const resultRef = React.useRef(enabled ? (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateConnecting), {}, { reset }) : (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, initialStateIdle), {}, { reset }));
|
||||
const [state, setState] = React.useState(trackResult(resultRef.current, addTrackedProp));
|
||||
return state;
|
||||
}
|
||||
function useInfiniteQuery$1(path, input, opts) {
|
||||
var _opts$trpc5, _opts$enabled3, _opts$trpc$abortOnUnm4, _opts$trpc6, _opts$initialCursor;
|
||||
const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount } = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === skipToken;
|
||||
if (typeof window === "undefined" && ssrState === "prepass" && (opts === null || opts === void 0 || (_opts$trpc5 = opts.trpc) === null || _opts$trpc5 === void 0 ? void 0 : _opts$trpc5.ssr) !== false && ((_opts$enabled3 = opts === null || opts === void 0 ? void 0 : opts.enabled) !== null && _opts$enabled3 !== void 0 ? _opts$enabled3 : defaultOpts === null || defaultOpts === void 0 ? void 0 : defaultOpts.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchInfiniteQuery(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm4 = opts === null || opts === void 0 || (_opts$trpc6 = opts.trpc) === null || _opts$trpc6 === void 0 ? void 0 : _opts$trpc6.abortOnUnmount) !== null && _opts$trpc$abortOnUnm4 !== void 0 ? _opts$trpc$abortOnUnm4 : abortOnUnmount;
|
||||
const hook = useInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, {
|
||||
initialPageParam: (_opts$initialCursor = opts.initialCursor) !== null && _opts$initialCursor !== void 0 ? _opts$initialCursor : null,
|
||||
persister: opts.persister,
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
var _queryFunctionContext;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }) });
|
||||
return client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext = queryFunctionContext.pageParam) !== null && _queryFunctionContext !== void 0 ? _queryFunctionContext : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}), queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return hook;
|
||||
}
|
||||
function usePrefetchInfiniteQuery$1(path, input, opts) {
|
||||
var _opts$trpc$abortOnUnm5, _opts$trpc7, _opts$initialCursor2;
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
const isInputSkipToken = input === skipToken;
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm5 = opts === null || opts === void 0 || (_opts$trpc7 = opts.trpc) === null || _opts$trpc7 === void 0 ? void 0 : _opts$trpc7.abortOnUnmount) !== null && _opts$trpc$abortOnUnm5 !== void 0 ? _opts$trpc$abortOnUnm5 : context.abortOnUnmount;
|
||||
usePrefetchInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
initialPageParam: (_opts$initialCursor2 = opts.initialCursor) !== null && _opts$initialCursor2 !== void 0 ? _opts$initialCursor2 : null,
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
|
||||
var _queryFunctionContext2;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext2 = queryFunctionContext.pageParam) !== null && _queryFunctionContext2 !== void 0 ? _queryFunctionContext2 : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
function useSuspenseInfiniteQuery$1(path, input, opts) {
|
||||
var _opts$trpc$abortOnUnm6, _opts$trpc8, _opts$initialCursor3;
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, "infinite");
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, defaultOpts), opts));
|
||||
const shouldAbortOnUnmount = (_opts$trpc$abortOnUnm6 = opts === null || opts === void 0 || (_opts$trpc8 = opts.trpc) === null || _opts$trpc8 === void 0 ? void 0 : _opts$trpc8.abortOnUnmount) !== null && _opts$trpc$abortOnUnm6 !== void 0 ? _opts$trpc$abortOnUnm6 : context.abortOnUnmount;
|
||||
const hook = useSuspenseInfiniteQuery((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, {
|
||||
initialPageParam: (_opts$initialCursor3 = opts.initialCursor) !== null && _opts$initialCursor3 !== void 0 ? _opts$initialCursor3 : null,
|
||||
queryKey,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
var _queryFunctionContext3;
|
||||
const actualOpts = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts), {}, { trpc: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, ssrOpts === null || ssrOpts === void 0 ? void 0 : ssrOpts.trpc), shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}) });
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: (_queryFunctionContext3 = queryFunctionContext.pageParam) !== null && _queryFunctionContext3 !== void 0 ? _queryFunctionContext3 : opts.initialCursor,
|
||||
direction: queryFunctionContext.direction
|
||||
}));
|
||||
}
|
||||
}), context.queryClient);
|
||||
hook.trpc = useHookResult({ path });
|
||||
return [hook.data, hook];
|
||||
}
|
||||
const useQueries$1 = (queriesCallback, options) => {
|
||||
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
||||
const proxy = createUseQueries(client);
|
||||
const queries = queriesCallback(proxy);
|
||||
if (typeof window === "undefined" && ssrState === "prepass") for (const query of queries) {
|
||||
var _queryOption$trpc;
|
||||
const queryOption = query;
|
||||
if (((_queryOption$trpc = queryOption.trpc) === null || _queryOption$trpc === void 0 ? void 0 : _queryOption$trpc.ssr) !== false && !queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })) prefetchQuery(queryOption.queryKey, queryOption);
|
||||
}
|
||||
return useQueries({
|
||||
queries: queries.map((query) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, query), {}, { queryKey: query.queryKey })),
|
||||
combine: options === null || options === void 0 ? void 0 : options.combine
|
||||
}, queryClient);
|
||||
};
|
||||
const useSuspenseQueries$1 = (queriesCallback) => {
|
||||
const { queryClient, client } = useContext();
|
||||
const proxy = createUseQueries(client);
|
||||
const queries = queriesCallback(proxy);
|
||||
const hook = useSuspenseQueries({ queries: queries.map((query) => (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, query), {}, {
|
||||
queryFn: query.queryFn,
|
||||
queryKey: query.queryKey
|
||||
})) }, queryClient);
|
||||
return [hook.map((h) => h.data), hook];
|
||||
};
|
||||
return {
|
||||
Provider: TRPCProvider,
|
||||
createClient,
|
||||
useContext,
|
||||
useUtils: useContext,
|
||||
useQuery: useQuery$1,
|
||||
usePrefetchQuery: usePrefetchQuery$1,
|
||||
useSuspenseQuery: useSuspenseQuery$1,
|
||||
useQueries: useQueries$1,
|
||||
useSuspenseQueries: useSuspenseQueries$1,
|
||||
useMutation: useMutation$1,
|
||||
useSubscription,
|
||||
useInfiniteQuery: useInfiniteQuery$1,
|
||||
usePrefetchInfiniteQuery: usePrefetchInfiniteQuery$1,
|
||||
useSuspenseInfiniteQuery: useSuspenseInfiniteQuery$1
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/shared/queryClient.ts
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const getQueryClient = (config) => {
|
||||
var _config$queryClient;
|
||||
return (_config$queryClient = config.queryClient) !== null && _config$queryClient !== void 0 ? _config$queryClient : new QueryClient(config.queryClientConfig);
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { TRPCContext, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, createUtilityFunctions, getClientArgs, getQueryClient, getQueryType };
|
||||
//# sourceMappingURL=shared-JtnEvJvB.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+13
@@ -0,0 +1,13 @@
|
||||
require('../getQueryKey-PyKLS56S.cjs');
|
||||
const require_shared = require('../shared-Dt4RsQVp.cjs');
|
||||
|
||||
exports.TRPCContext = require_shared.TRPCContext;
|
||||
exports.contextProps = require_shared.contextProps;
|
||||
exports.createQueryUtilsProxy = require_shared.createQueryUtilsProxy;
|
||||
exports.createReactDecoration = require_shared.createReactDecoration;
|
||||
exports.createReactQueryUtils = require_shared.createReactQueryUtils;
|
||||
exports.createRootHooks = require_shared.createRootHooks;
|
||||
exports.createUseQueries = require_shared.createUseQueries;
|
||||
exports.getClientArgs = require_shared.getClientArgs;
|
||||
exports.getQueryClient = require_shared.getQueryClient;
|
||||
exports.getQueryType = require_shared.getQueryType;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType } from "../getQueryKey.d-C_PnqPni.cjs";
|
||||
export { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType } from "../getQueryKey.d-CruH3ncI.mjs";
|
||||
export { CreateClient, CreateQueryUtils, CreateReactUtils, CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig, DecorateProcedure, DecorateQueryProcedure, DecorateRouterRecord, DecoratedProcedureUtilsRecord, DecoratedTRPCContextProps, DefinedTRPCInfiniteQueryOptionsIn, DefinedTRPCInfiniteQueryOptionsOut, DefinedTRPCQueryOptionsIn, DefinedTRPCQueryOptionsOut, DefinedUseTRPCQueryOptions, DefinedUseTRPCQueryResult, ExtractCursorType, InferMutationLikeData, InferMutationLikeInput, InferQueryLikeData, InferQueryLikeInput, MutationLike, OutputWithCursor, QueryLike, RouterLike, RouterLikeInner, SSRState, TRPCContext, TRPCContextProps, TRPCContextPropsBase, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCHookResult, TRPCProvider, TRPCProviderProps, TRPCQueryBaseOptions, TRPCQueryOptions, TRPCQueryOptionsResult, TRPCQueryUtils, TRPCReactRequestOptions, TRPCSubscriptionBaseResult, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, TRPCUseQueries, TRPCUseQueryBaseOptions, TRPCUseSuspenseQueries, UndefinedTRPCInfiniteQueryOptionsIn, UndefinedTRPCInfiniteQueryOptionsOut, UndefinedTRPCQueryOptionsIn, UndefinedTRPCQueryOptionsOut, UnusedSkipTokenTRPCInfiniteQueryOptionsIn, UnusedSkipTokenTRPCInfiniteQueryOptionsOut, UnusedSkipTokenTRPCQueryOptionsIn, UnusedSkipTokenTRPCQueryOptionsOut, UseMutationOverride, UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCInfiniteQueryOptions, UseTRPCInfiniteQueryResult, UseTRPCInfiniteQuerySuccessResult, UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCPrefetchInfiniteQueryOptions, UseTRPCPrefetchQueryOptions, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCQuerySuccessResult, UseTRPCSubscriptionOptions, UseTRPCSuspenseInfiniteQueryOptions, UseTRPCSuspenseInfiniteQueryResult, UseTRPCSuspenseQueryOptions, UseTRPCSuspenseQueryResult, UtilsLike, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType };
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import "../getQueryKey-BY58RNzP.mjs";
|
||||
import { TRPCContext, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType } from "../shared-JtnEvJvB.mjs";
|
||||
|
||||
export { TRPCContext, contextProps, createQueryUtilsProxy, createReactDecoration, createReactQueryUtils, createRootHooks, createUseQueries, getClientArgs, getQueryClient, getQueryType };
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"name": "@trpc/react-query",
|
||||
"type": "module",
|
||||
"version": "11.17.0",
|
||||
"description": "The tRPC React library",
|
||||
"author": "KATT",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.cts",
|
||||
"homepage": "https://trpc.io",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/trpc/trpc.git",
|
||||
"directory": "packages/react"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsdown",
|
||||
"dev": "tsdown --watch",
|
||||
"lint": "eslint --cache src",
|
||||
"typecheck": "tsc --noEmit --preserveWatchOutput --pretty"
|
||||
},
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.cts",
|
||||
"default": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"./rsc": {
|
||||
"import": {
|
||||
"types": "./dist/rsc.d.mts",
|
||||
"default": "./dist/rsc.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/rsc.d.cts",
|
||||
"default": "./dist/rsc.cjs"
|
||||
}
|
||||
},
|
||||
"./server": {
|
||||
"import": {
|
||||
"types": "./dist/server/index.d.mts",
|
||||
"default": "./dist/server/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/server/index.d.cts",
|
||||
"default": "./dist/server/index.cjs"
|
||||
}
|
||||
},
|
||||
"./shared": {
|
||||
"import": {
|
||||
"types": "./dist/shared/index.d.mts",
|
||||
"default": "./dist/shared/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/shared/index.d.cts",
|
||||
"default": "./dist/shared/index.cjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"README.md",
|
||||
"package.json",
|
||||
"rsc",
|
||||
"server",
|
||||
"shared",
|
||||
"!**/*.test.*",
|
||||
"!**/__tests__"
|
||||
],
|
||||
"eslintConfig": {
|
||||
"rules": {
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
"@trpc/react-query"
|
||||
]
|
||||
}
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@tanstack/react-query": "^5.80.3",
|
||||
"@trpc/client": "11.17.0",
|
||||
"@trpc/server": "11.17.0",
|
||||
"react": ">=18.2.0",
|
||||
"typescript": ">=5.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tanstack/query-sync-storage-persister": "^5.80.2",
|
||||
"@tanstack/react-query": "^5.80.3",
|
||||
"@tanstack/react-query-persist-client": "^5.80.3",
|
||||
"@testing-library/dom": "^10.0.0",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.1.0",
|
||||
"@testing-library/user-event": "^14.4.3",
|
||||
"@trpc/client": "11.17.0",
|
||||
"@trpc/server": "11.17.0",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.13.5",
|
||||
"@types/react": "^19.1.0",
|
||||
"eslint": "^9.26.0",
|
||||
"express": "^5.0.0",
|
||||
"next": "^15.3.8",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"tsdown": "0.12.7",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.9.2",
|
||||
"zod": "npm:zod@^3.0.0",
|
||||
"zod-form-data": "npm:zod-form-data@^2.0.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"funding": [
|
||||
"https://trpc.io/sponsor"
|
||||
],
|
||||
"gitHead": "23c723cfeaf07da28a52a5c35c3dcccf96a47578"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"main":"../dist/rsc.cjs","module":"../dist/rsc.mjs","types":"../dist/rsc.d.cts"}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"main":"../dist/server/index.cjs","module":"../dist/server/index.mjs","types":"../dist/server/index.d.cts"}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"main":"../dist/shared/index.cjs","module":"../dist/shared/index.mjs","types":"../dist/shared/index.d.cts"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
||||
import { createQueryUtilsProxy } from './shared';
|
||||
import type { CreateQueryUtilsOptions } from './utils/createUtilityFunctions';
|
||||
import { createUtilityFunctions } from './utils/createUtilityFunctions';
|
||||
|
||||
export function createTRPCQueryUtils<TRouter extends AnyRouter>(
|
||||
opts: CreateQueryUtilsOptions<TRouter>,
|
||||
) {
|
||||
const utils = createUtilityFunctions(opts);
|
||||
return createQueryUtilsProxy<TRouter>(utils);
|
||||
}
|
||||
+518
@@ -0,0 +1,518 @@
|
||||
import type {
|
||||
DefinedInitialDataInfiniteOptions,
|
||||
DefinedUseInfiniteQueryResult,
|
||||
InfiniteData,
|
||||
SkipToken,
|
||||
UndefinedInitialDataInfiniteOptions,
|
||||
UseInfiniteQueryOptions,
|
||||
UseInfiniteQueryResult,
|
||||
UseSuspenseInfiniteQueryOptions,
|
||||
UseSuspenseInfiniteQueryResult,
|
||||
UseSuspenseQueryResult,
|
||||
} from '@tanstack/react-query';
|
||||
import type { createTRPCClient, TRPCClientErrorLike } from '@trpc/client';
|
||||
import type {
|
||||
AnyProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
inferAsyncIterableYield,
|
||||
inferProcedureInput,
|
||||
inferTransformedProcedureOutput,
|
||||
ProcedureType,
|
||||
ProtectedIntersection,
|
||||
RouterRecord,
|
||||
Simplify,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';
|
||||
import * as React from 'react';
|
||||
import type {
|
||||
TRPCUseQueries,
|
||||
TRPCUseSuspenseQueries,
|
||||
} from './internals/useQueries';
|
||||
import type {
|
||||
CreateReactUtils,
|
||||
TRPCFetchInfiniteQueryOptions,
|
||||
TRPCFetchQueryOptions,
|
||||
} from './shared';
|
||||
import { createReactDecoration, createReactQueryUtils } from './shared';
|
||||
import type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';
|
||||
import { createRootHooks } from './shared/hooks/createHooksInternal';
|
||||
import type {
|
||||
DefinedUseTRPCQueryOptions,
|
||||
DefinedUseTRPCQueryResult,
|
||||
TRPCHookResult,
|
||||
TRPCProvider,
|
||||
TRPCSubscriptionResult,
|
||||
TRPCUseQueryBaseOptions,
|
||||
UseTRPCMutationOptions,
|
||||
UseTRPCMutationResult,
|
||||
UseTRPCQueryOptions,
|
||||
UseTRPCQueryResult,
|
||||
UseTRPCSubscriptionOptions,
|
||||
UseTRPCSuspenseQueryOptions,
|
||||
} from './shared/hooks/types';
|
||||
import type { CreateTRPCReactOptions } from './shared/types';
|
||||
|
||||
type ResolverDef = {
|
||||
input: any;
|
||||
output: any;
|
||||
transformer: boolean;
|
||||
errorShape: any;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface ProcedureUseQuery<TDef extends ResolverDef> {
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
|
||||
input: TDef['input'] | SkipToken,
|
||||
opts: DefinedUseTRPCQueryOptions<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>,
|
||||
TDef['output']
|
||||
>,
|
||||
): DefinedUseTRPCQueryResult<
|
||||
TData,
|
||||
TRPCClientErrorLike<{
|
||||
errorShape: TDef['errorShape'];
|
||||
transformer: TDef['transformer'];
|
||||
}>
|
||||
>;
|
||||
|
||||
<TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(
|
||||
input: TDef['input'] | SkipToken,
|
||||
opts?: UseTRPCQueryOptions<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientErrorLike<TDef>,
|
||||
TDef['output']
|
||||
>,
|
||||
): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (
|
||||
input: TDef['input'] | SkipToken,
|
||||
opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
||||
*/
|
||||
type CursorInput = {
|
||||
cursor?: any;
|
||||
} | void;
|
||||
|
||||
type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
|
||||
type InfiniteInput<TInput> =
|
||||
| Omit<TInput, ReservedInfiniteQueryKeys>
|
||||
| SkipToken;
|
||||
|
||||
type inferCursorType<TInput> = TInput extends { cursor?: any }
|
||||
? TInput['cursor']
|
||||
: unknown;
|
||||
|
||||
type makeInfiniteQueryOptions<TCursor, TOptions> = Omit<
|
||||
TOptions,
|
||||
'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'
|
||||
> &
|
||||
TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: TCursor;
|
||||
};
|
||||
|
||||
type trpcInfiniteData<TDef extends ResolverDef> = Simplify<
|
||||
InfiniteData<TDef['output'], inferCursorType<TDef['input']>>
|
||||
>;
|
||||
// references from react-query
|
||||
// 1st
|
||||
// declare function useInfiniteQuery<
|
||||
// TQueryFnData,
|
||||
// TError = DefaultError,
|
||||
// TData = InfiniteData<TQueryFnData>,
|
||||
// TQueryKey extends QueryKey = QueryKey,
|
||||
// TPageParam = unknown,
|
||||
// >(
|
||||
// options: DefinedInitialDataInfiniteOptions<
|
||||
// TQueryFnData,
|
||||
// TError,
|
||||
// TData,
|
||||
// TQueryKey,
|
||||
// TPageParam
|
||||
// >,
|
||||
// queryClient?: QueryClient,
|
||||
// ): DefinedUseInfiniteQueryResult<TData, TError>;
|
||||
// 2nd
|
||||
// declare function useInfiniteQuery<
|
||||
// TQueryFnData,
|
||||
// TError = DefaultError,
|
||||
// TData = InfiniteData<TQueryFnData>,
|
||||
// TQueryKey extends QueryKey = QueryKey,
|
||||
// TPageParam = unknown,
|
||||
// >(
|
||||
// options: UndefinedInitialDataInfiniteOptions<
|
||||
// TQueryFnData,
|
||||
// TError,
|
||||
// TData,
|
||||
// TQueryKey,
|
||||
// TPageParam
|
||||
// >,
|
||||
// queryClient?: QueryClient,
|
||||
// ): UseInfiniteQueryResult<TData, TError>;
|
||||
// 3rd
|
||||
// declare function useInfiniteQuery<
|
||||
// TQueryFnData,
|
||||
// TError = DefaultError,
|
||||
// TData = InfiniteData<TQueryFnData>,
|
||||
// TQueryKey extends QueryKey = QueryKey,
|
||||
// TPageParam = unknown,
|
||||
// >(
|
||||
// options: UseInfiniteQueryOptions<
|
||||
// TQueryFnData,
|
||||
// TError,
|
||||
// TData,
|
||||
// TQueryFnData,
|
||||
// TQueryKey,
|
||||
// TPageParam
|
||||
// >,
|
||||
// queryClient?: QueryClient,
|
||||
// ): UseInfiniteQueryResult<TData, TError>;
|
||||
|
||||
export interface useTRPCInfiniteQuery<TDef extends ResolverDef> {
|
||||
// 1st
|
||||
<TData = trpcInfiniteData<TDef>>(
|
||||
input: InfiniteInput<TDef['input']>,
|
||||
opts: makeInfiniteQueryOptions<
|
||||
inferCursorType<TDef['input']>,
|
||||
DefinedInitialDataInfiniteOptions<
|
||||
// TQueryFnData,
|
||||
TDef['output'],
|
||||
// TError,
|
||||
TRPCClientErrorLike<TDef>,
|
||||
// TData,
|
||||
TData,
|
||||
// TQueryKey,
|
||||
any,
|
||||
// TPageParam
|
||||
inferCursorType<TDef['input']>
|
||||
>
|
||||
>,
|
||||
): TRPCHookResult &
|
||||
DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
|
||||
// 2nd
|
||||
<TData = trpcInfiniteData<TDef>>(
|
||||
input: InfiniteInput<TDef['input']>,
|
||||
opts?: makeInfiniteQueryOptions<
|
||||
inferCursorType<TDef['input']>,
|
||||
UndefinedInitialDataInfiniteOptions<
|
||||
// TQueryFnData,
|
||||
TDef['output'],
|
||||
// TError,
|
||||
TRPCClientErrorLike<TDef>,
|
||||
// TData,
|
||||
TData,
|
||||
// TQueryKey,
|
||||
any,
|
||||
// TPageParam
|
||||
inferCursorType<TDef['input']>
|
||||
>
|
||||
>,
|
||||
): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
|
||||
// 3rd:
|
||||
<TData = trpcInfiniteData<TDef>>(
|
||||
input: InfiniteInput<TDef['input']>,
|
||||
opts?: makeInfiniteQueryOptions<
|
||||
inferCursorType<TDef['input']>,
|
||||
UseInfiniteQueryOptions<
|
||||
// TQueryFnData,
|
||||
TDef['output'],
|
||||
// TError,
|
||||
TRPCClientErrorLike<TDef>,
|
||||
// TData,
|
||||
TData,
|
||||
// TQueryKey,
|
||||
any,
|
||||
// TPageParam
|
||||
inferCursorType<TDef['input']>
|
||||
>
|
||||
>,
|
||||
): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
||||
}
|
||||
|
||||
// references from react-query
|
||||
// declare function useSuspenseInfiniteQuery<
|
||||
// TQueryFnData,
|
||||
// TError = DefaultError,
|
||||
// TData = InfiniteData<TQueryFnData>,
|
||||
// TQueryKey extends QueryKey = QueryKey,
|
||||
// TPageParam = unknown,
|
||||
// >(
|
||||
// options: UseSuspenseInfiniteQueryOptions<
|
||||
// TQueryFnData,
|
||||
// TError,
|
||||
// TData,
|
||||
// TQueryFnData,
|
||||
// TQueryKey,
|
||||
// TPageParam
|
||||
// >,
|
||||
// queryClient?: QueryClient,
|
||||
// ): UseSuspenseInfiniteQueryResult<TData, TError>;
|
||||
|
||||
export type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = (
|
||||
input: InfiniteInput<TDef['input']>,
|
||||
opts: makeInfiniteQueryOptions<
|
||||
inferCursorType<TDef['input']>,
|
||||
UseSuspenseInfiniteQueryOptions<
|
||||
// TQueryFnData,
|
||||
TDef['output'],
|
||||
// TError,
|
||||
TRPCClientErrorLike<TDef>,
|
||||
// TData,
|
||||
trpcInfiniteData<TDef>,
|
||||
// TQueryKey,
|
||||
any,
|
||||
// TPageParam
|
||||
inferCursorType<TDef['input']>
|
||||
>
|
||||
>,
|
||||
) => [
|
||||
trpcInfiniteData<TDef>,
|
||||
TRPCHookResult &
|
||||
UseSuspenseInfiniteQueryResult<
|
||||
trpcInfiniteData<TDef>,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>,
|
||||
];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
||||
TDef['input'] extends CursorInput
|
||||
? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useInfiniteQuery
|
||||
*/
|
||||
useInfiniteQuery: useTRPCInfiniteQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery
|
||||
*/
|
||||
useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;
|
||||
|
||||
usePrefetchInfiniteQuery: (
|
||||
input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,
|
||||
opts: TRPCFetchInfiniteQueryOptions<
|
||||
TDef['input'],
|
||||
TDef['output'],
|
||||
TRPCClientErrorLike<TDef>
|
||||
>,
|
||||
) => void;
|
||||
}
|
||||
: object;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useQuery
|
||||
*/
|
||||
useQuery: ProcedureUseQuery<TDef>;
|
||||
usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
|
||||
*/
|
||||
useSuspenseQuery: <
|
||||
TQueryFnData extends TDef['output'] = TDef['output'],
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: TDef['input'],
|
||||
opts?: UseTRPCSuspenseQueryOptions<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>,
|
||||
) => [
|
||||
TData,
|
||||
UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult,
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecoratedQuery<TDef extends ResolverDef> =
|
||||
MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;
|
||||
|
||||
export type DecoratedMutation<TDef extends ResolverDef> = {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useMutation
|
||||
*/
|
||||
useMutation: <TContext = unknown>(
|
||||
opts?: UseTRPCMutationOptions<
|
||||
TDef['input'],
|
||||
TRPCClientErrorLike<TDef>,
|
||||
TDef['output'],
|
||||
TContext
|
||||
>,
|
||||
) => UseTRPCMutationResult<
|
||||
TDef['output'],
|
||||
TRPCClientErrorLike<TDef>,
|
||||
TDef['input'],
|
||||
TContext
|
||||
>;
|
||||
};
|
||||
|
||||
interface ProcedureUseSubscription<TDef extends ResolverDef> {
|
||||
// Without skip token
|
||||
(
|
||||
input: TDef['input'],
|
||||
opts?: UseTRPCSubscriptionOptions<
|
||||
inferAsyncIterableYield<TDef['output']>,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>,
|
||||
): TRPCSubscriptionResult<
|
||||
inferAsyncIterableYield<TDef['output']>,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>;
|
||||
|
||||
// With skip token
|
||||
(
|
||||
input: TDef['input'] | SkipToken,
|
||||
opts?: Omit<
|
||||
UseTRPCSubscriptionOptions<
|
||||
inferAsyncIterableYield<TDef['output']>,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>,
|
||||
'enabled'
|
||||
>,
|
||||
): TRPCSubscriptionResult<
|
||||
inferAsyncIterableYield<TDef['output']>,
|
||||
TRPCClientErrorLike<TDef>
|
||||
>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecorateProcedure<
|
||||
TType extends ProcedureType,
|
||||
TDef extends ResolverDef,
|
||||
> = TType extends 'query'
|
||||
? DecoratedQuery<TDef>
|
||||
: TType extends 'mutation'
|
||||
? DecoratedMutation<TDef>
|
||||
: TType extends 'subscription'
|
||||
? {
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/subscriptions
|
||||
*/
|
||||
useSubscription: ProcedureUseSubscription<TDef>;
|
||||
}
|
||||
: never;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecorateRouterRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyProcedure
|
||||
? DecorateProcedure<
|
||||
$Value['_def']['type'],
|
||||
{
|
||||
input: inferProcedureInput<$Value>;
|
||||
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
||||
transformer: TRoot['transformer'];
|
||||
errorShape: TRoot['errorShape'];
|
||||
}
|
||||
>
|
||||
: $Value extends RouterRecord
|
||||
? DecorateRouterRecord<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
||||
/**
|
||||
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
||||
*
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
/**
|
||||
* @see https://trpc.io/docs/v11/client/react/useUtils
|
||||
*/
|
||||
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
||||
Provider: TRPCProvider<TRouter, TSSRContext>;
|
||||
createClient: typeof createTRPCClient<TRouter>;
|
||||
useQueries: TRPCUseQueries<TRouter>;
|
||||
useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
|
||||
};
|
||||
|
||||
export type CreateTRPCReact<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext,
|
||||
> = ProtectedIntersection<
|
||||
CreateTRPCReactBase<TRouter, TSSRContext>,
|
||||
DecorateRouterRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createHooksInternal<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = unknown,
|
||||
>(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {
|
||||
type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext>;
|
||||
|
||||
const proxy = createReactDecoration<TRouter, TSSRContext>(
|
||||
trpc,
|
||||
) as DecorateRouterRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>;
|
||||
return createFlatProxy<CreateHooksInternal>((key) => {
|
||||
if (key === 'useContext' || key === 'useUtils') {
|
||||
return () => {
|
||||
const context = trpc.useUtils();
|
||||
// create a stable reference of the utils context
|
||||
return React.useMemo(() => {
|
||||
return (createReactQueryUtils as any)(context);
|
||||
}, [context]);
|
||||
};
|
||||
}
|
||||
|
||||
if (trpc.hasOwnProperty(key)) {
|
||||
return (trpc as any)[key];
|
||||
}
|
||||
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
|
||||
export function createTRPCReact<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = unknown,
|
||||
>(
|
||||
opts?: CreateTRPCReactOptions<TRouter>,
|
||||
): CreateTRPCReact<TRouter, TSSRContext> {
|
||||
const hooks = createRootHooks<TRouter, TSSRContext>(opts);
|
||||
const proxy = createHooksInternal<TRouter, TSSRContext>(hooks);
|
||||
|
||||
return proxy as any;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
export * from '@trpc/client';
|
||||
|
||||
export { getQueryKey, getMutationKey } from './internals/getQueryKey';
|
||||
export {
|
||||
createTRPCReact,
|
||||
type CreateTRPCReact,
|
||||
type CreateTRPCReactBase,
|
||||
} from './createTRPCReact';
|
||||
export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure';
|
||||
export { createTRPCQueryUtils } from './createTRPCQueryUtils';
|
||||
+350
@@ -0,0 +1,350 @@
|
||||
import type {
|
||||
CancelOptions,
|
||||
FetchInfiniteQueryOptions,
|
||||
FetchQueryOptions,
|
||||
InfiniteData,
|
||||
InvalidateOptions,
|
||||
InvalidateQueryFilters,
|
||||
MutationOptions,
|
||||
QueryClient,
|
||||
QueryFilters,
|
||||
QueryKey,
|
||||
RefetchOptions,
|
||||
RefetchQueryFilters,
|
||||
ResetOptions,
|
||||
SetDataOptions,
|
||||
Updater,
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
TRPCClient,
|
||||
TRPCClientError,
|
||||
TRPCRequestOptions,
|
||||
TRPCUntypedClient,
|
||||
} from '@trpc/client';
|
||||
import type {
|
||||
AnyClientTypes,
|
||||
AnyRouter,
|
||||
DistributiveOmit,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import * as React from 'react';
|
||||
import type {
|
||||
DefinedTRPCInfiniteQueryOptionsIn,
|
||||
DefinedTRPCInfiniteQueryOptionsOut,
|
||||
DefinedTRPCQueryOptionsIn,
|
||||
DefinedTRPCQueryOptionsOut,
|
||||
ExtractCursorType,
|
||||
UndefinedTRPCInfiniteQueryOptionsIn,
|
||||
UndefinedTRPCInfiniteQueryOptionsOut,
|
||||
UndefinedTRPCQueryOptionsIn,
|
||||
UndefinedTRPCQueryOptionsOut,
|
||||
} from '../shared';
|
||||
import type { TRPCMutationKey, TRPCQueryKey } from './getQueryKey';
|
||||
|
||||
interface TRPCUseUtilsOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCRequestOptions;
|
||||
}
|
||||
export interface TRPCFetchQueryOptions<TOutput, TError>
|
||||
extends DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'>,
|
||||
TRPCUseUtilsOptions {
|
||||
//
|
||||
}
|
||||
|
||||
export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
||||
DistributiveOmit<
|
||||
FetchInfiniteQueryOptions<
|
||||
TOutput,
|
||||
TError,
|
||||
TOutput,
|
||||
TRPCQueryKey,
|
||||
ExtractCursorType<TInput>
|
||||
>,
|
||||
'queryKey' | 'initialPageParam'
|
||||
> &
|
||||
TRPCUseUtilsOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export type SSRState = 'mounted' | 'mounting' | 'prepass' | false;
|
||||
|
||||
export interface TRPCContextPropsBase<TRouter extends AnyRouter, TSSRContext> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The SSR context when server-side rendering
|
||||
* @default null
|
||||
*/
|
||||
ssrContext?: TSSRContext | null;
|
||||
/**
|
||||
* State of SSR hydration.
|
||||
* - `false` if not using SSR.
|
||||
* - `prepass` when doing a prepass to fetch queries' data
|
||||
* - `mounting` before TRPCProvider has been rendered on the client
|
||||
* - `mounted` when the TRPCProvider has been rendered on the client
|
||||
* @default false
|
||||
*/
|
||||
ssrState?: SSRState;
|
||||
/**
|
||||
* @deprecated pass abortOnUnmount to `createTRPCReact` instead
|
||||
* Abort loading query calls when unmounting a component - usually when navigating to a new page
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecoratedTRPCContextProps<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext,
|
||||
> = TRPCContextPropsBase<TRouter, TSSRContext> & {
|
||||
client: TRPCClient<TRouter>;
|
||||
};
|
||||
|
||||
export interface TRPCContextProps<TRouter extends AnyRouter, TSSRContext>
|
||||
extends TRPCContextPropsBase<TRouter, TSSRContext> {
|
||||
/**
|
||||
* The react-query `QueryClient`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
|
||||
export const contextProps: (keyof TRPCContextPropsBase<any, any>)[] = [
|
||||
'client',
|
||||
'ssrContext',
|
||||
'ssrState',
|
||||
'abortOnUnmount',
|
||||
];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface TRPCContextState<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = undefined,
|
||||
> extends Required<TRPCContextProps<TRouter, TSSRContext>>,
|
||||
TRPCQueryUtils<TRouter> {}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions(
|
||||
path: readonly string[], // <-- look into if needed
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: UndefinedTRPCQueryOptionsIn<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>,
|
||||
): UndefinedTRPCQueryOptionsOut<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>;
|
||||
queryOptions(
|
||||
path: readonly string[], // <-- look into if needed
|
||||
queryKey: TRPCQueryKey,
|
||||
opts: DefinedTRPCQueryOptionsIn<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>,
|
||||
): DefinedTRPCQueryOptionsOut<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions(
|
||||
path: readonly string[], // <-- look into if needed
|
||||
queryKey: TRPCQueryKey,
|
||||
opts: UndefinedTRPCInfiniteQueryOptionsIn<
|
||||
unknown,
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>,
|
||||
): UndefinedTRPCInfiniteQueryOptionsOut<
|
||||
unknown,
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>;
|
||||
infiniteQueryOptions(
|
||||
path: readonly string[], // <-- look into if needed
|
||||
queryKey: TRPCQueryKey,
|
||||
opts: DefinedTRPCInfiniteQueryOptionsIn<
|
||||
unknown,
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>,
|
||||
): DefinedTRPCInfiniteQueryOptionsOut<
|
||||
unknown,
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetchQuery: (
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>,
|
||||
) => Promise<unknown>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfiniteQuery: (
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: TRPCFetchInfiniteQueryOptions<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<TRouter>
|
||||
>,
|
||||
) => Promise<InfiniteData<unknown, unknown>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
||||
*/
|
||||
prefetchQuery: (
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfiniteQuery: (
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: TRPCFetchInfiniteQueryOptions<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<TRouter>
|
||||
>,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureQueryData: (
|
||||
queryKey: TRPCQueryKey,
|
||||
opts?: TRPCFetchQueryOptions<unknown, TRPCClientError<TRouter>>,
|
||||
) => Promise<unknown>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidateQueries: (
|
||||
queryKey: TRPCQueryKey,
|
||||
filters?: InvalidateQueryFilters<TRPCQueryKey>,
|
||||
options?: InvalidateOptions,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
resetQueries: (
|
||||
queryKey: TRPCQueryKey,
|
||||
filters?: QueryFilters<TRPCQueryKey>,
|
||||
options?: ResetOptions,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetchQueries: (
|
||||
queryKey: TRPCQueryKey,
|
||||
filters?: RefetchQueryFilters<TRPCQueryKey>,
|
||||
options?: RefetchOptions,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation
|
||||
*/
|
||||
cancelQuery: (
|
||||
queryKey: TRPCQueryKey,
|
||||
options?: CancelOptions,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueryData: (
|
||||
queryKey: TRPCQueryKey,
|
||||
updater: Updater<unknown, unknown>,
|
||||
options?: SetDataOptions,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata
|
||||
*/
|
||||
setQueriesData: (
|
||||
queryKey: TRPCQueryKey,
|
||||
filters: QueryFilters,
|
||||
updater: Updater<unknown, unknown>,
|
||||
options?: SetDataOptions,
|
||||
) => [QueryKey, unknown][];
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getQueryData: (queryKey: TRPCQueryKey) => unknown;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteQueryData: (
|
||||
queryKey: TRPCQueryKey,
|
||||
updater: Updater<
|
||||
InfiniteData<unknown> | undefined,
|
||||
InfiniteData<unknown> | undefined
|
||||
>,
|
||||
options?: SetDataOptions,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteQueryData: (
|
||||
queryKey: TRPCQueryKey,
|
||||
) => InfiniteData<unknown> | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
|
||||
*/
|
||||
setMutationDefaults: (
|
||||
mutationKey: TRPCMutationKey,
|
||||
options:
|
||||
| MutationOptions
|
||||
| ((args: {
|
||||
canonicalMutationFn: (input: unknown) => Promise<unknown>;
|
||||
}) => MutationOptions),
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
|
||||
*/
|
||||
getMutationDefaults: (
|
||||
mutationKey: TRPCMutationKey,
|
||||
) => MutationOptions | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
|
||||
*/
|
||||
isMutating: (filters: { mutationKey: TRPCMutationKey }) => number;
|
||||
}
|
||||
export const TRPCContext = React.createContext?.(null as any);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import type { TRPCQueryKey } from './getQueryKey';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function getClientArgs<TOptions>(
|
||||
queryKey: TRPCQueryKey,
|
||||
opts: TOptions,
|
||||
infiniteParams?: {
|
||||
pageParam: any;
|
||||
direction: 'forward' | 'backward';
|
||||
},
|
||||
) {
|
||||
const path = queryKey[0];
|
||||
let input = queryKey[1]?.input;
|
||||
if (infiniteParams) {
|
||||
input = {
|
||||
...(input ?? {}),
|
||||
...(infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {}),
|
||||
direction: infiniteParams.direction,
|
||||
};
|
||||
}
|
||||
return [path.join('.'), input, (opts as any)?.trpc] as const;
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
import { skipToken } from '@tanstack/react-query';
|
||||
import {
|
||||
isObject,
|
||||
type DeepPartial,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { DecoratedMutation, DecoratedQuery } from '../createTRPCReact';
|
||||
import type { DecorateRouterRecord } from '../shared';
|
||||
|
||||
export type QueryType = 'any' | 'infinite' | 'query';
|
||||
|
||||
export type TRPCQueryKey = [
|
||||
readonly string[],
|
||||
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?,
|
||||
];
|
||||
|
||||
export type TRPCMutationKey = [readonly string[]]; // = [TRPCQueryKey[0]]
|
||||
|
||||
type ProcedureOrRouter =
|
||||
| DecoratedMutation<any>
|
||||
| DecoratedQuery<any>
|
||||
| DecorateRouterRecord<any, any>;
|
||||
|
||||
/**
|
||||
* To allow easy interactions with groups of related queries, such as
|
||||
* invalidating all queries of a router, we use an array as the path when
|
||||
* storing in tanstack query.
|
||||
**/
|
||||
export function getQueryKeyInternal(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
type: QueryType,
|
||||
): TRPCQueryKey {
|
||||
// Construct a query key that is easy to destructure and flexible for
|
||||
// partial selecting etc.
|
||||
// https://github.com/trpc/trpc/issues/3128
|
||||
|
||||
// some parts of the path may be dot-separated, split them up
|
||||
const splitPath = path.flatMap((part) => part.split('.'));
|
||||
|
||||
if (!input && (!type || type === 'any')) {
|
||||
// this matches also all mutations (see `getMutationKeyInternal`)
|
||||
|
||||
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
||||
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
||||
return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);
|
||||
}
|
||||
|
||||
if (
|
||||
type === 'infinite' &&
|
||||
isObject(input) &&
|
||||
('direction' in input || 'cursor' in input)
|
||||
) {
|
||||
const {
|
||||
cursor: _,
|
||||
direction: __,
|
||||
...inputWithoutCursorAndDirection
|
||||
} = input;
|
||||
return [
|
||||
splitPath,
|
||||
{
|
||||
input: inputWithoutCursorAndDirection,
|
||||
type: 'infinite',
|
||||
},
|
||||
];
|
||||
}
|
||||
return [
|
||||
splitPath,
|
||||
{
|
||||
...(typeof input !== 'undefined' &&
|
||||
input !== skipToken && { input: input }),
|
||||
...(type && type !== 'any' && { type: type }),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function getMutationKeyInternal(path: readonly string[]) {
|
||||
return getQueryKeyInternal(path, undefined, 'any') as TRPCMutationKey;
|
||||
}
|
||||
|
||||
type GetInfiniteQueryInput<
|
||||
TProcedureInput,
|
||||
TInputWithoutCursorAndDirection = Omit<
|
||||
TProcedureInput,
|
||||
'cursor' | 'direction'
|
||||
>,
|
||||
> = keyof TInputWithoutCursorAndDirection extends never
|
||||
? undefined
|
||||
: DeepPartial<TInputWithoutCursorAndDirection> | undefined;
|
||||
|
||||
/** @internal */
|
||||
export type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
||||
cursor?: any;
|
||||
}
|
||||
? GetInfiniteQueryInput<TProcedureInput>
|
||||
: DeepPartial<TProcedureInput> | undefined;
|
||||
|
||||
type GetParams<TProcedureOrRouter extends ProcedureOrRouter> =
|
||||
TProcedureOrRouter extends DecoratedQuery<infer $Def>
|
||||
? [input?: GetQueryProcedureInput<$Def['input']>, type?: QueryType]
|
||||
: [];
|
||||
|
||||
/**
|
||||
* Method to extract the query key for a procedure
|
||||
* @param procedureOrRouter - procedure or AnyRouter
|
||||
* @param input - input to procedureOrRouter
|
||||
* @param type - defaults to `any`
|
||||
* @see https://trpc.io/docs/v11/getQueryKey
|
||||
*/
|
||||
export function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(
|
||||
procedureOrRouter: TProcedureOrRouter,
|
||||
..._params: GetParams<TProcedureOrRouter>
|
||||
) {
|
||||
const [input, type] = _params;
|
||||
|
||||
// @ts-expect-error - we don't expose _def on the type layer
|
||||
const path = procedureOrRouter._def().path as string[];
|
||||
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
||||
return queryKey;
|
||||
}
|
||||
|
||||
// TODO: look over if we can't use a single type
|
||||
export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
||||
string[],
|
||||
{ input?: GetQueryProcedureInput<TInput>; type: TType }?,
|
||||
];
|
||||
|
||||
/**
|
||||
* Method to extract the mutation key for a procedure
|
||||
* @param procedure - procedure
|
||||
* @see https://trpc.io/docs/v11/getQueryKey#mutations
|
||||
*/
|
||||
export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
|
||||
procedure: TProcedure,
|
||||
) {
|
||||
// @ts-expect-error - we don't expose _def on the type layer
|
||||
const path = procedure._def().path as string[];
|
||||
return getMutationKeyInternal(path);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import * as React from 'react';
|
||||
import type { TRPCQueryOptionsResult } from '../shared';
|
||||
import type { TRPCHookResult } from '../shared/hooks/types';
|
||||
import type { TRPCQueryKey } from './getQueryKey';
|
||||
|
||||
export function createTRPCOptionsResult(value: {
|
||||
path: readonly string[];
|
||||
}): TRPCQueryOptionsResult['trpc'] {
|
||||
const path = value.path.join('.');
|
||||
|
||||
return {
|
||||
path,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a stable reference of the `trpc` prop
|
||||
*/
|
||||
export function useHookResult(value: {
|
||||
path: readonly string[];
|
||||
}): TRPCHookResult['trpc'] {
|
||||
const result = createTRPCOptionsResult(value);
|
||||
return React.useMemo(() => result, [result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export async function buildQueryFromAsyncIterable(
|
||||
asyncIterable: AsyncIterable<unknown>,
|
||||
queryClient: QueryClient,
|
||||
queryKey: TRPCQueryKey,
|
||||
) {
|
||||
const queryCache = queryClient.getQueryCache();
|
||||
|
||||
const query = queryCache.build(queryClient, {
|
||||
queryKey,
|
||||
});
|
||||
|
||||
query.setState({
|
||||
data: [],
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
const aggregate: unknown[] = [];
|
||||
for await (const value of asyncIterable) {
|
||||
aggregate.push(value);
|
||||
|
||||
query.setState({
|
||||
data: [...aggregate],
|
||||
});
|
||||
}
|
||||
return aggregate;
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
import type {
|
||||
QueryKey,
|
||||
UseQueryOptions,
|
||||
UseSuspenseQueryOptions,
|
||||
UseSuspenseQueryResult,
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
AnyRouter,
|
||||
DistributiveOmit,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type {
|
||||
UseQueriesProcedureRecord,
|
||||
UseSuspenseQueriesProcedureRecord,
|
||||
UseTRPCQueryOptions,
|
||||
UseTRPCQueryResult,
|
||||
UseTRPCSuspenseQueryOptions,
|
||||
} from '../shared';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseQueryOptionsForUseQueries<
|
||||
TQueryFnData = unknown,
|
||||
TError = unknown,
|
||||
TData = TQueryFnData,
|
||||
TQueryKey extends QueryKey = QueryKey,
|
||||
> = DistributiveOmit<
|
||||
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
||||
'queryKey'
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseQueryOptionsForUseSuspenseQueries<
|
||||
TQueryFnData = unknown,
|
||||
TError = unknown,
|
||||
TData = TQueryFnData,
|
||||
TQueryKey extends QueryKey = QueryKey,
|
||||
> = DistributiveOmit<
|
||||
UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
||||
'queryKey'
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type TrpcQueryOptionsForUseQueries<TOutput, TData, TError> =
|
||||
DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type TrpcQueryOptionsForUseSuspenseQueries<TOutput, TData, TError> =
|
||||
DistributiveOmit<
|
||||
UseTRPCSuspenseQueryOptions<TOutput, TData, TError>,
|
||||
'queryKey'
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare type QueriesResults<
|
||||
TQueriesOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[],
|
||||
> = {
|
||||
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseQueries<
|
||||
infer TQueryFnData,
|
||||
infer TError,
|
||||
infer TData,
|
||||
any
|
||||
>
|
||||
? UseTRPCQueryResult<unknown extends TData ? TQueryFnData : TData, TError>
|
||||
: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare type SuspenseQueriesResults<
|
||||
TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any
|
||||
>[],
|
||||
> = [
|
||||
{
|
||||
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<
|
||||
infer TQueryFnData,
|
||||
any,
|
||||
infer TData,
|
||||
any
|
||||
>
|
||||
? unknown extends TData
|
||||
? TQueryFnData
|
||||
: TData
|
||||
: never;
|
||||
},
|
||||
{
|
||||
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<
|
||||
infer TQueryFnData,
|
||||
infer TError,
|
||||
infer TData,
|
||||
any
|
||||
>
|
||||
? UseSuspenseQueryResult<
|
||||
unknown extends TData ? TQueryFnData : TData,
|
||||
TError
|
||||
>
|
||||
: never;
|
||||
},
|
||||
];
|
||||
|
||||
type GetOptions<TQueryOptions> =
|
||||
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>
|
||||
? TQueryOptions
|
||||
: never;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type QueriesOptions<
|
||||
TQueriesOptions extends any[],
|
||||
TResult extends any[] = [],
|
||||
> = TQueriesOptions extends []
|
||||
? []
|
||||
: TQueriesOptions extends [infer Head]
|
||||
? [...TResult, GetOptions<Head>]
|
||||
: TQueriesOptions extends [infer Head, ...infer Tail]
|
||||
? QueriesOptions<Tail, [...TResult, GetOptions<Head>]>
|
||||
: unknown[] extends TQueriesOptions
|
||||
? TQueriesOptions
|
||||
: TQueriesOptions extends UseQueryOptionsForUseQueries<
|
||||
infer TQueryFnData,
|
||||
infer TError,
|
||||
infer TData,
|
||||
infer TQueryKey
|
||||
>[]
|
||||
? UseQueryOptionsForUseQueries<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
TData,
|
||||
TQueryKey
|
||||
>[]
|
||||
: UseQueryOptionsForUseQueries[];
|
||||
|
||||
type GetSuspenseOptions<TQueryOptions> =
|
||||
TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>
|
||||
? TQueryOptions
|
||||
: never;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type SuspenseQueriesOptions<
|
||||
TQueriesOptions extends any[],
|
||||
TResult extends any[] = [],
|
||||
> = TQueriesOptions extends []
|
||||
? []
|
||||
: TQueriesOptions extends [infer Head]
|
||||
? [...TResult, GetSuspenseOptions<Head>]
|
||||
: TQueriesOptions extends [infer Head, ...infer Tail]
|
||||
? SuspenseQueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]>
|
||||
: unknown[] extends TQueriesOptions
|
||||
? TQueriesOptions
|
||||
: TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
|
||||
infer TQueryFnData,
|
||||
infer TError,
|
||||
infer TData,
|
||||
infer TQueryKey
|
||||
>[]
|
||||
? UseQueryOptionsForUseSuspenseQueries<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
TData,
|
||||
TQueryKey
|
||||
>[]
|
||||
: UseQueryOptionsForUseSuspenseQueries[];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type TRPCUseQueries<TRouter extends AnyRouter> = <
|
||||
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[],
|
||||
TCombinedResult = QueriesResults<TQueryOptions>,
|
||||
>(
|
||||
queriesCallback: (
|
||||
t: UseQueriesProcedureRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>,
|
||||
) => readonly [...QueriesOptions<TQueryOptions>],
|
||||
options?: {
|
||||
combine?: (results: QueriesResults<TQueryOptions>) => TCombinedResult;
|
||||
},
|
||||
) => TCombinedResult;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type TRPCUseSuspenseQueries<TRouter extends AnyRouter> = <
|
||||
TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any
|
||||
>[],
|
||||
>(
|
||||
queriesCallback: (
|
||||
t: UseSuspenseQueriesProcedureRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>,
|
||||
) => readonly [...SuspenseQueriesOptions<TQueryOptions>],
|
||||
) => SuspenseQueriesResults<TQueryOptions>;
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/// <reference types="react/canary" />
|
||||
|
||||
import {
|
||||
dehydrate,
|
||||
HydrationBoundary,
|
||||
type QueryClient,
|
||||
} from '@tanstack/react-query';
|
||||
import type { TRPCClientError } from '@trpc/client';
|
||||
import type { inferTransformedProcedureOutput } from '@trpc/server';
|
||||
import {
|
||||
createRecursiveProxy,
|
||||
type AnyRouter,
|
||||
type inferProcedureInput,
|
||||
type RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type {
|
||||
AnyProcedure,
|
||||
AnyRootTypes,
|
||||
inferProcedureOutput,
|
||||
inferRouterRootTypes,
|
||||
Maybe,
|
||||
RouterCaller,
|
||||
TypeError,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import * as React from 'react';
|
||||
import { getQueryKeyInternal } from './internals/getQueryKey';
|
||||
import type {
|
||||
TRPCFetchInfiniteQueryOptions,
|
||||
TRPCFetchQueryOptions,
|
||||
} from './shared';
|
||||
|
||||
const HELPERS = ['prefetch', 'prefetchInfinite'];
|
||||
|
||||
type DecorateProcedure<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
> = {
|
||||
(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
): Promise<inferProcedureOutput<TProcedure>>;
|
||||
prefetch: (
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchQueryOptions<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
) => Promise<void>;
|
||||
prefetchInfinite: (
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchInfiniteQueryOptions<
|
||||
inferProcedureInput<TProcedure>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
) => Promise<void>;
|
||||
};
|
||||
|
||||
type DecorateRouterRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyProcedure
|
||||
? DecorateProcedure<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? DecorateRouterRecord<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
type Caller<TRouter extends AnyRouter> = ReturnType<
|
||||
RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>
|
||||
>;
|
||||
|
||||
// ts-prune-ignore-next
|
||||
/**
|
||||
* @note This requires `@tanstack/react-query@^5.49.0`
|
||||
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
||||
* set to your data transformer in your `QueryClient` factory.
|
||||
* @example
|
||||
* ```ts
|
||||
* export const createQueryClient = () =>
|
||||
* new QueryClient({
|
||||
* defaultOptions: {
|
||||
* dehydrate: {
|
||||
* serializeData: transformer.serialize,
|
||||
* },
|
||||
* hydrate: {
|
||||
* deserializeData: transformer.deserialize,
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function createHydrationHelpers<TRouter extends AnyRouter>(
|
||||
caller: AnyRouter extends TRouter
|
||||
? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'>
|
||||
: Caller<TRouter>,
|
||||
getQueryClient: () => QueryClient,
|
||||
) {
|
||||
type RootTypes = inferRouterRootTypes<TRouter>;
|
||||
|
||||
const wrappedProxy = createRecursiveProxy<
|
||||
DecorateRouterRecord<RootTypes, TRouter['_def']['record']>
|
||||
>(async (opts) => {
|
||||
const path = [...opts.path];
|
||||
const args = [...opts.args];
|
||||
const proc = path.reduce(
|
||||
(acc, key) =>
|
||||
// @ts-expect-error - ??
|
||||
HELPERS.includes(key) ? acc : acc[key],
|
||||
caller,
|
||||
) as unknown as DecorateProcedure<RootTypes, AnyProcedure>;
|
||||
|
||||
const input = args[0];
|
||||
const promise = proc(input);
|
||||
|
||||
const helper = path.pop();
|
||||
if (helper === 'prefetch') {
|
||||
const args1 = args[1] as Maybe<
|
||||
TRPCFetchInfiniteQueryOptions<any, any, any>
|
||||
>;
|
||||
|
||||
return getQueryClient().prefetchQuery({
|
||||
...args1,
|
||||
queryKey: getQueryKeyInternal(path, input, 'query'),
|
||||
queryFn: () => promise,
|
||||
});
|
||||
}
|
||||
if (helper === 'prefetchInfinite') {
|
||||
const args1 = args[1] as Maybe<
|
||||
TRPCFetchInfiniteQueryOptions<any, any, any>
|
||||
>;
|
||||
|
||||
return getQueryClient().prefetchInfiniteQuery({
|
||||
...args1,
|
||||
queryKey: getQueryKeyInternal(path, input, 'infinite'),
|
||||
queryFn: () => promise,
|
||||
initialPageParam: args1?.initialCursor ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
return promise;
|
||||
});
|
||||
|
||||
function HydrateClient(props: { children: React.ReactNode }) {
|
||||
const dehydratedState = dehydrate(getQueryClient());
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydratedState}>
|
||||
{props.children}
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
/***
|
||||
* Wrapped caller with prefetch helpers
|
||||
* Can be used as a regular [server-side caller](https://trpc.io/docs/server/server-side-calls)
|
||||
* or using prefetch helpers to put the promise into the QueryClient cache
|
||||
* @example
|
||||
* ```ts
|
||||
* const data = await trpc.post.get("postId");
|
||||
*
|
||||
* // or
|
||||
* void trpc.post.get.prefetch("postId");
|
||||
* ```
|
||||
*/
|
||||
trpc: wrappedProxy,
|
||||
/**
|
||||
* HoC to hydrate the query client for a client component
|
||||
* to pick up the prefetched promise and skip an initial
|
||||
* client-side fetch.
|
||||
* @example
|
||||
* ```tsx
|
||||
* // MyRSC.tsx
|
||||
* const MyRSC = ({ params }) => {
|
||||
* void trpc.post.get.prefetch(params.postId);
|
||||
*
|
||||
* return (
|
||||
* <HydrateClient>
|
||||
* <MyCC postId={params.postId} />
|
||||
* </HydrateClient>
|
||||
* );
|
||||
* };
|
||||
*
|
||||
* // MyCC.tsx
|
||||
* "use client"
|
||||
* const MyCC = ({ postId }) => {
|
||||
* const { data: post } = trpc.post.get.useQuery(postId);
|
||||
* return <div>{post.title}</div>;
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
HydrateClient,
|
||||
};
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { createServerSideHelpers } from './ssgProxy';
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
import type {
|
||||
DehydratedState,
|
||||
DehydrateOptions,
|
||||
QueryClient,
|
||||
} from '@tanstack/react-query';
|
||||
import { dehydrate } from '@tanstack/react-query';
|
||||
import type { TRPCClient } from '@trpc/client';
|
||||
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
||||
import type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';
|
||||
import {
|
||||
getTransformer,
|
||||
type TransformerOptions,
|
||||
} from '@trpc/client/unstable-internals';
|
||||
import type {
|
||||
AnyQueryProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
inferClientTypes,
|
||||
inferRouterContext,
|
||||
Maybe,
|
||||
ProtectedIntersection,
|
||||
RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import {
|
||||
callProcedure,
|
||||
createFlatProxy,
|
||||
createRecursiveProxy,
|
||||
run,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import { getQueryKeyInternal } from '../internals/getQueryKey';
|
||||
import type {
|
||||
CreateTRPCReactQueryClientConfig,
|
||||
DecorateQueryProcedure,
|
||||
TRPCFetchInfiniteQueryOptions,
|
||||
TRPCFetchQueryOptions,
|
||||
} from '../shared';
|
||||
import { getQueryClient, getQueryType } from '../shared';
|
||||
|
||||
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
||||
router: TRouter;
|
||||
ctx: inferRouterContext<TRouter>;
|
||||
} & TransformerOptions<inferClientTypes<TRouter>>;
|
||||
|
||||
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
|
||||
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> =
|
||||
CreateTRPCReactQueryClientConfig &
|
||||
(CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
||||
|
||||
type SSGFns =
|
||||
| 'queryOptions'
|
||||
| 'infiniteQueryOptions'
|
||||
| 'fetch'
|
||||
| 'fetchInfinite'
|
||||
| 'prefetch'
|
||||
| 'prefetchInfinite';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type DecoratedProcedureSSGRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns>
|
||||
: $Value extends RouterRecord
|
||||
? DecoratedProcedureSSGRecord<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
type AnyDecoratedProcedure = Pick<DecorateQueryProcedure<any, any>, SSGFns>;
|
||||
|
||||
/**
|
||||
* Create functions you can use for server-side rendering / static generation
|
||||
* @see https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
||||
*/
|
||||
export function createServerSideHelpers<TRouter extends AnyRouter>(
|
||||
opts: CreateServerSideHelpersOptions<TRouter>,
|
||||
) {
|
||||
const queryClient = getQueryClient(opts);
|
||||
const transformer = getTransformer(
|
||||
(opts as CoercedTransformerParameters).transformer,
|
||||
);
|
||||
|
||||
const resolvedOpts: {
|
||||
serialize: (obj: unknown) => any;
|
||||
query: (queryOpts: { path: string; input: unknown }) => Promise<unknown>;
|
||||
} = (() => {
|
||||
if ('router' in opts) {
|
||||
const { ctx, router } = opts;
|
||||
return {
|
||||
serialize: (obj) => transformer.output.serialize(obj),
|
||||
query: (queryOpts) => {
|
||||
return callProcedure({
|
||||
router,
|
||||
path: queryOpts.path,
|
||||
getRawInput: async () => queryOpts.input,
|
||||
ctx,
|
||||
type: 'query',
|
||||
signal: undefined,
|
||||
batchIndex: 0,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const { client } = opts;
|
||||
const untypedClient =
|
||||
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
|
||||
return {
|
||||
query: (queryOpts) =>
|
||||
untypedClient.query(queryOpts.path, queryOpts.input),
|
||||
serialize: (obj) => transformer.output.serialize(obj),
|
||||
};
|
||||
})();
|
||||
|
||||
function _dehydrate(
|
||||
opts: DehydrateOptions = {
|
||||
shouldDehydrateQuery(query) {
|
||||
if (query.state.status === 'pending') {
|
||||
return false;
|
||||
}
|
||||
// makes sure to serialize errors
|
||||
return true;
|
||||
},
|
||||
},
|
||||
): DehydratedState {
|
||||
const before = run(() => {
|
||||
const dehydrated = dehydrate(queryClient, opts);
|
||||
|
||||
return {
|
||||
...dehydrated,
|
||||
queries: dehydrated.queries.map((query) => {
|
||||
if (query.promise) {
|
||||
const { promise: _, ...rest } = query;
|
||||
return rest;
|
||||
}
|
||||
return query;
|
||||
}),
|
||||
};
|
||||
});
|
||||
const after = resolvedOpts.serialize(before);
|
||||
return after;
|
||||
}
|
||||
|
||||
type CreateSSGHelpers = ProtectedIntersection<
|
||||
{
|
||||
queryClient: QueryClient;
|
||||
dehydrate: (opts?: DehydrateOptions) => DehydratedState;
|
||||
},
|
||||
DecoratedProcedureSSGRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>
|
||||
>;
|
||||
const proxy = createRecursiveProxy<CreateSSGHelpers>((opts) => {
|
||||
const args = opts.args;
|
||||
const input = args[0];
|
||||
const arrayPath = [...opts.path];
|
||||
const utilName = arrayPath.pop() as keyof AnyDecoratedProcedure;
|
||||
|
||||
const queryFn = () =>
|
||||
resolvedOpts.query({ path: arrayPath.join('.'), input });
|
||||
|
||||
const queryKey = getQueryKeyInternal(
|
||||
arrayPath,
|
||||
input,
|
||||
getQueryType(utilName),
|
||||
);
|
||||
|
||||
const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
||||
queryOptions: () => {
|
||||
const args1 = args[1] as Maybe<any>;
|
||||
return { ...args1, queryKey, queryFn };
|
||||
},
|
||||
infiniteQueryOptions: () => {
|
||||
const args1 = args[1] as Maybe<any>;
|
||||
return { ...args1, queryKey, queryFn };
|
||||
},
|
||||
fetch: () => {
|
||||
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
|
||||
return queryClient.fetchQuery({ ...args1, queryKey, queryFn });
|
||||
},
|
||||
fetchInfinite: () => {
|
||||
const args1 = args[1] as Maybe<
|
||||
TRPCFetchInfiniteQueryOptions<any, any, any>
|
||||
>;
|
||||
return queryClient.fetchInfiniteQuery({
|
||||
...args1,
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: args1?.initialCursor ?? null,
|
||||
});
|
||||
},
|
||||
prefetch: () => {
|
||||
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
|
||||
return queryClient.prefetchQuery({ ...args1, queryKey, queryFn });
|
||||
},
|
||||
prefetchInfinite: () => {
|
||||
const args1 = args[1] as Maybe<
|
||||
TRPCFetchInfiniteQueryOptions<any, any, any>
|
||||
>;
|
||||
return queryClient.prefetchInfiniteQuery({
|
||||
...args1,
|
||||
queryKey,
|
||||
queryFn,
|
||||
initialPageParam: args1?.initialCursor ?? null,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
return helperMap[utilName]();
|
||||
});
|
||||
return createFlatProxy<CreateSSGHelpers>((key) => {
|
||||
if (key === 'queryClient') return queryClient;
|
||||
if (key === 'dehydrate') return _dehydrate;
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
+779
@@ -0,0 +1,779 @@
|
||||
// TODO: Look into fixing react-compiler support
|
||||
/* eslint-disable react-hooks/react-compiler */
|
||||
import {
|
||||
useInfiniteQuery as __useInfiniteQuery,
|
||||
useMutation as __useMutation,
|
||||
usePrefetchInfiniteQuery as __usePrefetchInfiniteQuery,
|
||||
useQueries as __useQueries,
|
||||
useQuery as __useQuery,
|
||||
useSuspenseInfiniteQuery as __useSuspenseInfiniteQuery,
|
||||
useSuspenseQueries as __useSuspenseQueries,
|
||||
useSuspenseQuery as __useSuspenseQuery,
|
||||
usePrefetchQuery as _usePrefetchQuery,
|
||||
hashKey,
|
||||
skipToken,
|
||||
} from '@tanstack/react-query';
|
||||
import type { TRPCClientErrorLike } from '@trpc/client';
|
||||
import {
|
||||
createTRPCClient,
|
||||
getUntypedClient,
|
||||
TRPCUntypedClient,
|
||||
} from '@trpc/client';
|
||||
import type { Unsubscribable } from '@trpc/server/observable';
|
||||
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
||||
import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
||||
import * as React from 'react';
|
||||
import type { SSRState, TRPCContextState } from '../../internals/context';
|
||||
import { TRPCContext } from '../../internals/context';
|
||||
import { getClientArgs } from '../../internals/getClientArgs';
|
||||
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
||||
import {
|
||||
getMutationKeyInternal,
|
||||
getQueryKeyInternal,
|
||||
} from '../../internals/getQueryKey';
|
||||
import {
|
||||
buildQueryFromAsyncIterable,
|
||||
useHookResult,
|
||||
} from '../../internals/trpcResult';
|
||||
import type {
|
||||
TRPCUseQueries,
|
||||
TRPCUseSuspenseQueries,
|
||||
} from '../../internals/useQueries';
|
||||
import { createUtilityFunctions } from '../../utils/createUtilityFunctions';
|
||||
import { createUseQueries } from '../proxy/useQueriesProxy';
|
||||
import type { CreateTRPCReactOptions, UseMutationOverride } from '../types';
|
||||
import type {
|
||||
TRPCProvider,
|
||||
TRPCQueryOptions,
|
||||
TRPCSubscriptionConnectingResult,
|
||||
TRPCSubscriptionIdleResult,
|
||||
TRPCSubscriptionResult,
|
||||
UseTRPCInfiniteQueryOptions,
|
||||
UseTRPCInfiniteQueryResult,
|
||||
UseTRPCMutationOptions,
|
||||
UseTRPCMutationResult,
|
||||
UseTRPCPrefetchInfiniteQueryOptions,
|
||||
UseTRPCPrefetchQueryOptions,
|
||||
UseTRPCQueryOptions,
|
||||
UseTRPCQueryResult,
|
||||
UseTRPCSubscriptionOptions,
|
||||
UseTRPCSuspenseInfiniteQueryOptions,
|
||||
UseTRPCSuspenseInfiniteQueryResult,
|
||||
UseTRPCSuspenseQueryOptions,
|
||||
UseTRPCSuspenseQueryResult,
|
||||
} from './types';
|
||||
|
||||
const trackResult = <T extends object>(
|
||||
result: T,
|
||||
onTrackResult: (key: keyof T) => void,
|
||||
): T => {
|
||||
const trackedResult = new Proxy(result, {
|
||||
get(target, prop) {
|
||||
onTrackResult(prop as keyof T);
|
||||
return target[prop as keyof T];
|
||||
},
|
||||
});
|
||||
|
||||
return trackedResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createRootHooks<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = unknown,
|
||||
>(config?: CreateTRPCReactOptions<TRouter>) {
|
||||
const mutationSuccessOverride: UseMutationOverride['onSuccess'] =
|
||||
config?.overrides?.useMutation?.onSuccess ??
|
||||
((options) => options.originalFn());
|
||||
|
||||
type TError = TRPCClientErrorLike<TRouter>;
|
||||
|
||||
type ProviderContext = TRPCContextState<TRouter, TSSRContext>;
|
||||
|
||||
const Context = (config?.context ??
|
||||
TRPCContext) as React.Context<ProviderContext>;
|
||||
|
||||
const createClient = createTRPCClient<TRouter>;
|
||||
|
||||
const TRPCProvider: TRPCProvider<TRouter, TSSRContext> = (props) => {
|
||||
const { abortOnUnmount = false, queryClient, ssrContext } = props;
|
||||
const [ssrState, setSSRState] = React.useState<SSRState>(
|
||||
props.ssrState ?? false,
|
||||
);
|
||||
|
||||
const client: TRPCUntypedClient<TRouter> =
|
||||
props.client instanceof TRPCUntypedClient
|
||||
? props.client
|
||||
: getUntypedClient(props.client);
|
||||
|
||||
const fns = React.useMemo(
|
||||
() =>
|
||||
createUtilityFunctions({
|
||||
client,
|
||||
queryClient,
|
||||
}),
|
||||
[client, queryClient],
|
||||
);
|
||||
|
||||
const contextValue = React.useMemo<ProviderContext>(
|
||||
() => ({
|
||||
abortOnUnmount,
|
||||
queryClient,
|
||||
client,
|
||||
ssrContext: ssrContext ?? null,
|
||||
ssrState,
|
||||
...fns,
|
||||
}),
|
||||
[abortOnUnmount, client, fns, queryClient, ssrContext, ssrState],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
// Only updating state to `mounted` if we are using SSR.
|
||||
// This makes it so we don't have an unnecessary re-render when opting out of SSR.
|
||||
setSSRState((state) => (state ? 'mounted' : false));
|
||||
}, []);
|
||||
return (
|
||||
<Context.Provider value={contextValue}>{props.children}</Context.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
function useContext() {
|
||||
const context = React.useContext(Context);
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?',
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hack to make sure errors return `status`='error` when doing SSR
|
||||
* @see https://github.com/trpc/trpc/pull/1645
|
||||
*/
|
||||
function useSSRQueryOptionsIfNeeded<
|
||||
TOptions extends { retryOnMount?: boolean } | undefined,
|
||||
>(queryKey: TRPCQueryKey, opts: TOptions): TOptions {
|
||||
const { queryClient, ssrState } = useContext();
|
||||
return ssrState &&
|
||||
ssrState !== 'mounted' &&
|
||||
queryClient.getQueryCache().find({ queryKey })?.state.status === 'error'
|
||||
? {
|
||||
retryOnMount: false,
|
||||
...opts,
|
||||
}
|
||||
: opts;
|
||||
}
|
||||
|
||||
function useQuery(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
opts?: UseTRPCQueryOptions<unknown, unknown, TError>,
|
||||
): UseTRPCQueryResult<unknown, TError> {
|
||||
const context = useContext();
|
||||
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } =
|
||||
context;
|
||||
const queryKey = getQueryKeyInternal(path, input, 'query');
|
||||
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
|
||||
const isInputSkipToken = input === skipToken;
|
||||
|
||||
if (
|
||||
typeof window === 'undefined' &&
|
||||
ssrState === 'prepass' &&
|
||||
opts?.trpc?.ssr !== false &&
|
||||
(opts?.enabled ?? defaultOpts?.enabled) !== false &&
|
||||
!isInputSkipToken &&
|
||||
!queryClient.getQueryCache().find({ queryKey })
|
||||
) {
|
||||
void prefetchQuery(queryKey, opts as any);
|
||||
}
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
|
||||
...defaultOpts,
|
||||
...opts,
|
||||
});
|
||||
|
||||
const shouldAbortOnUnmount =
|
||||
opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
|
||||
|
||||
const hook = __useQuery(
|
||||
{
|
||||
...ssrOpts,
|
||||
queryKey: queryKey as any,
|
||||
queryFn: isInputSkipToken
|
||||
? input
|
||||
: async (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
...ssrOpts,
|
||||
trpc: {
|
||||
...ssrOpts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: { signal: null }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await client.query(
|
||||
...getClientArgs(queryKey, actualOpts),
|
||||
);
|
||||
|
||||
if (isAsyncIterable(result)) {
|
||||
return buildQueryFromAsyncIterable(
|
||||
result,
|
||||
queryClient,
|
||||
queryKey,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
},
|
||||
queryClient,
|
||||
) as UseTRPCQueryResult<unknown, TError>;
|
||||
|
||||
hook.trpc = useHookResult({
|
||||
path,
|
||||
});
|
||||
|
||||
return hook;
|
||||
}
|
||||
|
||||
function usePrefetchQuery(
|
||||
path: string[],
|
||||
input: unknown,
|
||||
opts?: UseTRPCPrefetchQueryOptions<unknown, unknown, TError>,
|
||||
): void {
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, 'query');
|
||||
|
||||
const isInputSkipToken = input === skipToken;
|
||||
|
||||
const shouldAbortOnUnmount =
|
||||
opts?.trpc?.abortOnUnmount ??
|
||||
config?.abortOnUnmount ??
|
||||
context.abortOnUnmount;
|
||||
|
||||
_usePrefetchQuery({
|
||||
...opts,
|
||||
queryKey: queryKey as any,
|
||||
queryFn: isInputSkipToken
|
||||
? input
|
||||
: (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
trpc: {
|
||||
...opts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function useSuspenseQuery(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
opts?: UseTRPCSuspenseQueryOptions<unknown, unknown, TError>,
|
||||
): UseTRPCSuspenseQueryResult<unknown, TError> {
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, 'query');
|
||||
|
||||
const shouldAbortOnUnmount =
|
||||
opts?.trpc?.abortOnUnmount ??
|
||||
config?.abortOnUnmount ??
|
||||
context.abortOnUnmount;
|
||||
|
||||
const hook = __useSuspenseQuery(
|
||||
{
|
||||
...opts,
|
||||
queryKey: queryKey as any,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
...opts,
|
||||
trpc: {
|
||||
...opts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: { signal: null }),
|
||||
},
|
||||
};
|
||||
|
||||
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
||||
},
|
||||
},
|
||||
context.queryClient,
|
||||
) as UseTRPCQueryResult<unknown, TError>;
|
||||
|
||||
hook.trpc = useHookResult({
|
||||
path,
|
||||
});
|
||||
|
||||
return [hook.data, hook as any];
|
||||
}
|
||||
|
||||
function useMutation(
|
||||
path: readonly string[],
|
||||
opts?: UseTRPCMutationOptions<unknown, TError, unknown, unknown>,
|
||||
): UseTRPCMutationResult<unknown, TError, unknown, unknown> {
|
||||
const { client, queryClient } = useContext();
|
||||
|
||||
const mutationKey = getMutationKeyInternal(path);
|
||||
|
||||
const defaultOpts = queryClient.defaultMutationOptions(
|
||||
queryClient.getMutationDefaults(mutationKey),
|
||||
);
|
||||
|
||||
const hook = __useMutation(
|
||||
{
|
||||
...opts,
|
||||
mutationKey: mutationKey,
|
||||
mutationFn: (input) => {
|
||||
return client.mutation(...getClientArgs([path, { input }], opts));
|
||||
},
|
||||
onSuccess(...args) {
|
||||
const originalFn = () =>
|
||||
opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
|
||||
|
||||
return mutationSuccessOverride({
|
||||
originalFn,
|
||||
queryClient,
|
||||
meta: opts?.meta ?? defaultOpts?.meta ?? {},
|
||||
});
|
||||
},
|
||||
},
|
||||
queryClient,
|
||||
) as UseTRPCMutationResult<unknown, TError, unknown, unknown>;
|
||||
|
||||
hook.trpc = useHookResult({
|
||||
path,
|
||||
});
|
||||
|
||||
return hook;
|
||||
}
|
||||
const initialStateIdle: Omit<TRPCSubscriptionIdleResult<unknown>, 'reset'> = {
|
||||
data: undefined,
|
||||
error: null,
|
||||
status: 'idle',
|
||||
};
|
||||
|
||||
const initialStateConnecting: Omit<
|
||||
TRPCSubscriptionConnectingResult<unknown, TError>,
|
||||
'reset'
|
||||
> = {
|
||||
data: undefined,
|
||||
error: null,
|
||||
status: 'connecting',
|
||||
};
|
||||
|
||||
/* istanbul ignore next -- @preserve */
|
||||
function useSubscription(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
opts: UseTRPCSubscriptionOptions<unknown, TError>,
|
||||
) {
|
||||
const enabled = opts?.enabled ?? input !== skipToken;
|
||||
const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
|
||||
const { client } = useContext();
|
||||
|
||||
const optsRef = React.useRef<typeof opts>(opts);
|
||||
React.useEffect(() => {
|
||||
optsRef.current = opts;
|
||||
});
|
||||
|
||||
type $Result = TRPCSubscriptionResult<unknown, TError>;
|
||||
|
||||
const [trackedProps] = React.useState(new Set<keyof $Result>([]));
|
||||
|
||||
const addTrackedProp = React.useCallback(
|
||||
(key: keyof $Result) => {
|
||||
trackedProps.add(key);
|
||||
},
|
||||
[trackedProps],
|
||||
);
|
||||
|
||||
const currentSubscriptionRef = React.useRef<Unsubscribable>(null);
|
||||
|
||||
const updateState = React.useCallback(
|
||||
(callback: (prevState: $Result) => $Result) => {
|
||||
const prev = resultRef.current;
|
||||
const next = (resultRef.current = callback(prev));
|
||||
|
||||
let shouldUpdate = false;
|
||||
for (const key of trackedProps) {
|
||||
if (prev[key] !== next[key]) {
|
||||
shouldUpdate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldUpdate) {
|
||||
setState(trackResult(next, addTrackedProp));
|
||||
}
|
||||
},
|
||||
[addTrackedProp, trackedProps],
|
||||
);
|
||||
|
||||
const reset = React.useCallback((): void => {
|
||||
// unsubscribe from the previous subscription
|
||||
currentSubscriptionRef.current?.unsubscribe();
|
||||
|
||||
if (!enabled) {
|
||||
updateState(() => ({ ...initialStateIdle, reset }));
|
||||
return;
|
||||
}
|
||||
updateState(() => ({ ...initialStateConnecting, reset }));
|
||||
const subscription = client.subscription(
|
||||
path.join('.'),
|
||||
input ?? undefined,
|
||||
{
|
||||
onStarted: () => {
|
||||
optsRef.current.onStarted?.();
|
||||
updateState((prev) => ({
|
||||
...prev,
|
||||
status: 'pending',
|
||||
error: null,
|
||||
}));
|
||||
},
|
||||
onData: (data) => {
|
||||
optsRef.current.onData?.(data);
|
||||
updateState((prev) => ({
|
||||
...prev,
|
||||
status: 'pending',
|
||||
data,
|
||||
error: null,
|
||||
}));
|
||||
},
|
||||
onError: (error) => {
|
||||
optsRef.current.onError?.(error);
|
||||
updateState((prev) => ({
|
||||
...prev,
|
||||
status: 'error',
|
||||
error,
|
||||
}));
|
||||
},
|
||||
onConnectionStateChange: (result) => {
|
||||
updateState((prev) => {
|
||||
switch (result.state) {
|
||||
case 'idle':
|
||||
return {
|
||||
...prev,
|
||||
status: result.state,
|
||||
error: null,
|
||||
data: undefined,
|
||||
};
|
||||
case 'connecting':
|
||||
return {
|
||||
...prev,
|
||||
error: result.error,
|
||||
status: result.state,
|
||||
};
|
||||
|
||||
case 'pending':
|
||||
// handled when data is / onStarted
|
||||
return prev;
|
||||
}
|
||||
});
|
||||
},
|
||||
onComplete: () => {
|
||||
optsRef.current.onComplete?.();
|
||||
|
||||
// In the case of WebSockets, the connection might not be idle so `onConnectionStateChange` will not be called until the connection is closed.
|
||||
// In this case, we need to set the state to idle manually.
|
||||
updateState((prev) => ({
|
||||
...prev,
|
||||
status: 'idle',
|
||||
error: null,
|
||||
data: undefined,
|
||||
}));
|
||||
|
||||
// (We might want to add a `connectionState` to the state to track the connection state separately)
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
currentSubscriptionRef.current = subscription;
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [client, queryKey, enabled, updateState]);
|
||||
React.useEffect(() => {
|
||||
reset();
|
||||
|
||||
return () => {
|
||||
currentSubscriptionRef.current?.unsubscribe();
|
||||
};
|
||||
}, [reset]);
|
||||
|
||||
const resultRef = React.useRef<$Result>(
|
||||
enabled
|
||||
? { ...initialStateConnecting, reset }
|
||||
: { ...initialStateIdle, reset },
|
||||
);
|
||||
|
||||
const [state, setState] = React.useState<$Result>(
|
||||
trackResult(resultRef.current, addTrackedProp),
|
||||
);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
function useInfiniteQuery(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
opts: UseTRPCInfiniteQueryOptions<unknown, unknown, TError>,
|
||||
): UseTRPCInfiniteQueryResult<unknown, TError, unknown> {
|
||||
const {
|
||||
client,
|
||||
ssrState,
|
||||
prefetchInfiniteQuery,
|
||||
queryClient,
|
||||
abortOnUnmount,
|
||||
} = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, 'infinite');
|
||||
|
||||
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
||||
|
||||
const isInputSkipToken = input === skipToken;
|
||||
|
||||
if (
|
||||
typeof window === 'undefined' &&
|
||||
ssrState === 'prepass' &&
|
||||
opts?.trpc?.ssr !== false &&
|
||||
(opts?.enabled ?? defaultOpts?.enabled) !== false &&
|
||||
!isInputSkipToken &&
|
||||
!queryClient.getQueryCache().find({ queryKey })
|
||||
) {
|
||||
void prefetchInfiniteQuery(queryKey, { ...defaultOpts, ...opts } as any);
|
||||
}
|
||||
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
|
||||
...defaultOpts,
|
||||
...opts,
|
||||
});
|
||||
|
||||
// request option should take priority over global
|
||||
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
|
||||
|
||||
const hook = __useInfiniteQuery(
|
||||
{
|
||||
...ssrOpts,
|
||||
initialPageParam: opts.initialCursor ?? null,
|
||||
persister: opts.persister,
|
||||
queryKey: queryKey as any,
|
||||
queryFn: isInputSkipToken
|
||||
? input
|
||||
: (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
...ssrOpts,
|
||||
trpc: {
|
||||
...ssrOpts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: { signal: null }),
|
||||
},
|
||||
};
|
||||
|
||||
return client.query(
|
||||
...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam:
|
||||
queryFunctionContext.pageParam ?? opts.initialCursor,
|
||||
direction: queryFunctionContext.direction,
|
||||
}),
|
||||
);
|
||||
},
|
||||
},
|
||||
queryClient,
|
||||
) as UseTRPCInfiniteQueryResult<unknown, TError, unknown>;
|
||||
|
||||
hook.trpc = useHookResult({
|
||||
path,
|
||||
});
|
||||
return hook;
|
||||
}
|
||||
|
||||
function usePrefetchInfiniteQuery(
|
||||
path: string[],
|
||||
input: unknown,
|
||||
opts: UseTRPCPrefetchInfiniteQueryOptions<unknown, unknown, TError>,
|
||||
): void {
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, 'infinite');
|
||||
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
|
||||
const isInputSkipToken = input === skipToken;
|
||||
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
|
||||
...defaultOpts,
|
||||
...opts,
|
||||
});
|
||||
|
||||
// request option should take priority over global
|
||||
const shouldAbortOnUnmount =
|
||||
opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
|
||||
|
||||
__usePrefetchInfiniteQuery({
|
||||
...opts,
|
||||
initialPageParam: opts.initialCursor ?? null,
|
||||
queryKey,
|
||||
queryFn: isInputSkipToken
|
||||
? input
|
||||
: (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
...ssrOpts,
|
||||
trpc: {
|
||||
...ssrOpts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
|
||||
return context.client.query(
|
||||
...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
|
||||
direction: queryFunctionContext.direction,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function useSuspenseInfiniteQuery(
|
||||
path: readonly string[],
|
||||
input: unknown,
|
||||
opts: UseTRPCSuspenseInfiniteQueryOptions<unknown, unknown, TError>,
|
||||
): UseTRPCSuspenseInfiniteQueryResult<unknown, TError, unknown> {
|
||||
const context = useContext();
|
||||
const queryKey = getQueryKeyInternal(path, input, 'infinite');
|
||||
|
||||
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
||||
|
||||
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
|
||||
...defaultOpts,
|
||||
...opts,
|
||||
});
|
||||
|
||||
// request option should take priority over global
|
||||
const shouldAbortOnUnmount =
|
||||
opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
|
||||
|
||||
const hook = __useSuspenseInfiniteQuery(
|
||||
{
|
||||
...opts,
|
||||
initialPageParam: opts.initialCursor ?? null,
|
||||
queryKey,
|
||||
queryFn: (queryFunctionContext) => {
|
||||
const actualOpts = {
|
||||
...ssrOpts,
|
||||
trpc: {
|
||||
...ssrOpts?.trpc,
|
||||
...(shouldAbortOnUnmount
|
||||
? { signal: queryFunctionContext.signal }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
|
||||
return context.client.query(
|
||||
...getClientArgs(queryKey, actualOpts, {
|
||||
pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
|
||||
direction: queryFunctionContext.direction,
|
||||
}),
|
||||
);
|
||||
},
|
||||
},
|
||||
context.queryClient,
|
||||
) as UseTRPCInfiniteQueryResult<unknown, TError, unknown>;
|
||||
|
||||
hook.trpc = useHookResult({
|
||||
path,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return [hook.data!, hook as any];
|
||||
}
|
||||
|
||||
const useQueries: TRPCUseQueries<TRouter> = (queriesCallback, options) => {
|
||||
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
||||
|
||||
const proxy = createUseQueries(client);
|
||||
|
||||
const queries = queriesCallback(proxy);
|
||||
|
||||
if (typeof window === 'undefined' && ssrState === 'prepass') {
|
||||
for (const query of queries) {
|
||||
const queryOption = query as TRPCQueryOptions<any, any>;
|
||||
if (
|
||||
queryOption.trpc?.ssr !== false &&
|
||||
!queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })
|
||||
) {
|
||||
void prefetchQuery(queryOption.queryKey, queryOption as any);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return __useQueries(
|
||||
{
|
||||
queries: queries.map((query) => ({
|
||||
...query,
|
||||
queryKey: (query as TRPCQueryOptions<any, any>).queryKey,
|
||||
})),
|
||||
combine: options?.combine as any,
|
||||
},
|
||||
queryClient,
|
||||
);
|
||||
};
|
||||
|
||||
const useSuspenseQueries: TRPCUseSuspenseQueries<TRouter> = (
|
||||
queriesCallback,
|
||||
) => {
|
||||
const { queryClient, client } = useContext();
|
||||
|
||||
const proxy = createUseQueries(client);
|
||||
|
||||
const queries = queriesCallback(proxy);
|
||||
|
||||
const hook = __useSuspenseQueries(
|
||||
{
|
||||
queries: queries.map((query) => ({
|
||||
...query,
|
||||
queryFn: query.queryFn,
|
||||
queryKey: (query as TRPCQueryOptions<any, any>).queryKey,
|
||||
})),
|
||||
},
|
||||
queryClient,
|
||||
);
|
||||
|
||||
return [hook.map((h) => h.data), hook] as any;
|
||||
};
|
||||
|
||||
return {
|
||||
Provider: TRPCProvider,
|
||||
createClient,
|
||||
useContext,
|
||||
useUtils: useContext,
|
||||
useQuery,
|
||||
usePrefetchQuery,
|
||||
useSuspenseQuery,
|
||||
useQueries,
|
||||
useSuspenseQueries,
|
||||
useMutation,
|
||||
useSubscription,
|
||||
useInfiniteQuery,
|
||||
usePrefetchInfiniteQuery,
|
||||
useSuspenseInfiniteQuery,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer the type of a `createReactQueryHooks` function
|
||||
* @internal
|
||||
*/
|
||||
export type CreateReactQueryHooks<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = unknown,
|
||||
> = ReturnType<typeof createRootHooks<TRouter, TSSRContext>>;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// NOTE: This indirection is only needed to break a circular-reference.
|
||||
// After removal of `hooks/deprecated/createHooksInternal` file,
|
||||
// `hooks/createHooksInternal` can be swapped for all `createRootHooks` imports.
|
||||
export { createRootHooks } from './createHooksInternal';
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
import type {
|
||||
DefinedUseQueryResult,
|
||||
FetchInfiniteQueryOptions,
|
||||
FetchQueryOptions,
|
||||
InfiniteData,
|
||||
InfiniteQueryObserverSuccessResult,
|
||||
InitialDataFunction,
|
||||
QueryObserverSuccessResult,
|
||||
QueryOptions,
|
||||
UseBaseQueryOptions,
|
||||
UseInfiniteQueryOptions,
|
||||
UseInfiniteQueryResult,
|
||||
UseMutationOptions,
|
||||
UseMutationResult,
|
||||
UseQueryResult,
|
||||
UseSuspenseInfiniteQueryOptions,
|
||||
UseSuspenseInfiniteQueryResult,
|
||||
UseSuspenseQueryOptions,
|
||||
UseSuspenseQueryResult,
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
CreateTRPCClientOptions,
|
||||
TRPCClient,
|
||||
TRPCRequestOptions,
|
||||
TRPCUntypedClient,
|
||||
} from '@trpc/client';
|
||||
import type {
|
||||
AnyRouter,
|
||||
coerceAsyncIterableToArray,
|
||||
DistributiveOmit,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { JSX, ReactNode } from 'react';
|
||||
import type { TRPCContextProps } from '../../internals/context';
|
||||
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
||||
|
||||
export type OutputWithCursor<TData, TCursor = any> = {
|
||||
cursor: TCursor | null;
|
||||
data: TData;
|
||||
};
|
||||
|
||||
export interface TRPCReactRequestOptions
|
||||
// For RQ, we use their internal AbortSignals instead of letting the user pass their own
|
||||
extends Omit<TRPCRequestOptions, 'signal'> {
|
||||
/**
|
||||
* Opt out of SSR for this query by passing `ssr: false`
|
||||
*/
|
||||
ssr?: boolean;
|
||||
/**
|
||||
* Opt out or into aborting request on unmount
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
}
|
||||
|
||||
export interface TRPCUseQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
|
||||
export interface UseTRPCQueryOptions<
|
||||
TOutput,
|
||||
TData,
|
||||
TError,
|
||||
TQueryOptsData = TOutput,
|
||||
> extends DistributiveOmit<
|
||||
UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, any>,
|
||||
'queryKey'
|
||||
>,
|
||||
TRPCUseQueryBaseOptions {}
|
||||
|
||||
export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError>
|
||||
extends DistributiveOmit<
|
||||
UseSuspenseQueryOptions<TOutput, TError, TData, any>,
|
||||
'queryKey'
|
||||
>,
|
||||
TRPCUseQueryBaseOptions {}
|
||||
|
||||
export interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError>
|
||||
extends DistributiveOmit<
|
||||
FetchQueryOptions<TOutput, TError, TData, any>,
|
||||
'queryKey'
|
||||
>,
|
||||
TRPCUseQueryBaseOptions {}
|
||||
|
||||
/** @internal **/
|
||||
export interface DefinedUseTRPCQueryOptions<
|
||||
TOutput,
|
||||
TData,
|
||||
TError,
|
||||
TQueryOptsData = TOutput,
|
||||
> extends DistributiveOmit<
|
||||
UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData>,
|
||||
'queryKey'
|
||||
> {
|
||||
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
|
||||
}
|
||||
|
||||
export interface TRPCQueryOptions<TData, TError>
|
||||
extends DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>,
|
||||
TRPCUseQueryBaseOptions {
|
||||
queryKey: TRPCQueryKey;
|
||||
}
|
||||
|
||||
export type ExtractCursorType<TInput> = TInput extends { cursor?: any }
|
||||
? TInput['cursor']
|
||||
: unknown;
|
||||
|
||||
export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError>
|
||||
extends DistributiveOmit<
|
||||
UseInfiniteQueryOptions<
|
||||
TOutput,
|
||||
TError,
|
||||
TOutput,
|
||||
any,
|
||||
ExtractCursorType<TInput>
|
||||
>,
|
||||
'queryKey' | 'initialPageParam'
|
||||
>,
|
||||
TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
|
||||
export type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
||||
DistributiveOmit<
|
||||
FetchInfiniteQueryOptions<
|
||||
TOutput,
|
||||
TError,
|
||||
TOutput,
|
||||
any,
|
||||
ExtractCursorType<TInput>
|
||||
>,
|
||||
'queryKey' | 'initialPageParam'
|
||||
> &
|
||||
TRPCUseQueryBaseOptions & {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
};
|
||||
|
||||
export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError>
|
||||
extends DistributiveOmit<
|
||||
UseSuspenseInfiniteQueryOptions<
|
||||
TOutput,
|
||||
TError,
|
||||
TOutput,
|
||||
any,
|
||||
ExtractCursorType<TInput>
|
||||
>,
|
||||
'queryKey' | 'initialPageParam'
|
||||
>,
|
||||
TRPCUseQueryBaseOptions {
|
||||
initialCursor?: ExtractCursorType<TInput>;
|
||||
}
|
||||
|
||||
export interface UseTRPCMutationOptions<
|
||||
TInput,
|
||||
TError,
|
||||
TOutput,
|
||||
TContext = unknown,
|
||||
> extends UseMutationOptions<TOutput, TError, TInput, TContext>,
|
||||
TRPCUseQueryBaseOptions {}
|
||||
|
||||
export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
||||
/**
|
||||
* @deprecated
|
||||
* use a `skipToken` from `@tanstack/react-query` instead
|
||||
* this will be removed in v12
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Called when the subscription is started
|
||||
*/
|
||||
onStarted?: () => void;
|
||||
/**
|
||||
* Called when new data is received
|
||||
*/
|
||||
onData?: (data: TOutput) => void;
|
||||
/**
|
||||
* Called when an **unrecoverable error** occurs and the subscription is closed
|
||||
*/
|
||||
onError?: (err: TError) => void;
|
||||
/**
|
||||
* Called when the subscription is completed on the server
|
||||
*/
|
||||
onComplete?: () => void;
|
||||
}
|
||||
|
||||
export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'idle' | 'connecting' | 'pending' | 'error';
|
||||
data: undefined | TOutput;
|
||||
error: null | TError;
|
||||
/**
|
||||
* Reset the subscription
|
||||
*/
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
export interface TRPCSubscriptionIdleResult<TOutput>
|
||||
extends TRPCSubscriptionBaseResult<TOutput, null> {
|
||||
status: 'idle';
|
||||
data: undefined;
|
||||
error: null;
|
||||
}
|
||||
|
||||
export interface TRPCSubscriptionConnectingResult<TOutput, TError>
|
||||
extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'connecting';
|
||||
data: undefined | TOutput;
|
||||
error: TError | null;
|
||||
}
|
||||
|
||||
export interface TRPCSubscriptionPendingResult<TOutput>
|
||||
extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
||||
status: 'pending';
|
||||
data: TOutput | undefined;
|
||||
error: null;
|
||||
}
|
||||
|
||||
export interface TRPCSubscriptionErrorResult<TOutput, TError>
|
||||
extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
||||
status: 'error';
|
||||
data: TOutput | undefined;
|
||||
error: TError;
|
||||
}
|
||||
|
||||
export type TRPCSubscriptionResult<TOutput, TError> =
|
||||
| TRPCSubscriptionIdleResult<TOutput>
|
||||
| TRPCSubscriptionConnectingResult<TOutput, TError>
|
||||
| TRPCSubscriptionErrorResult<TOutput, TError>
|
||||
| TRPCSubscriptionPendingResult<TOutput>;
|
||||
|
||||
export interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext>
|
||||
extends Omit<TRPCContextProps<TRouter, TSSRContext>, 'client'> {
|
||||
children: ReactNode;
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
}
|
||||
|
||||
export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (
|
||||
props: TRPCProviderProps<TRouter, TSSRContext>,
|
||||
) => JSX.Element;
|
||||
|
||||
export type CreateClient<TRouter extends AnyRouter> = (
|
||||
opts: CreateTRPCClientOptions<TRouter>,
|
||||
) => TRPCUntypedClient<TRouter>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCQueryResult<TData, TError> = TRPCHookResult &
|
||||
UseQueryResult<coerceAsyncIterableToArray<TData>, TError>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DefinedUseTRPCQueryResult<TData, TError> = DefinedUseQueryResult<
|
||||
TData,
|
||||
TError
|
||||
> &
|
||||
TRPCHookResult;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCQuerySuccessResult<TData, TError> =
|
||||
QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCSuspenseQueryResult<TData, TError> = [
|
||||
TData,
|
||||
UseSuspenseQueryResult<TData, TError> & TRPCHookResult,
|
||||
];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult &
|
||||
UseInfiniteQueryResult<
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TError
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> =
|
||||
InfiniteQueryObserverSuccessResult<
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TError
|
||||
> &
|
||||
TRPCHookResult;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
UseSuspenseInfiniteQueryResult<
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TError
|
||||
> &
|
||||
TRPCHookResult,
|
||||
];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> =
|
||||
TRPCHookResult & UseMutationResult<TData, TError, TVariables, TContext>;
|
||||
|
||||
export interface TRPCHookResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
export * from './proxy/decorationProxy';
|
||||
export * from './proxy/utilsProxy';
|
||||
export * from './proxy/useQueriesProxy';
|
||||
export type {
|
||||
DecorateRouterRecord,
|
||||
DecorateProcedure,
|
||||
} from '../createTRPCReact';
|
||||
export type {
|
||||
TRPCUseQueries,
|
||||
TRPCUseSuspenseQueries,
|
||||
} from '../internals/useQueries';
|
||||
export * from './hooks/createRootHooks';
|
||||
export * from './queryClient';
|
||||
export * from './types';
|
||||
export * from './hooks/types';
|
||||
export * from './polymorphism';
|
||||
|
||||
export {
|
||||
/**
|
||||
* @deprecated this is an internal function
|
||||
*/
|
||||
getClientArgs,
|
||||
} from '../internals/getClientArgs';
|
||||
|
||||
export {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
TRPCContext,
|
||||
} from './../internals/context';
|
||||
|
||||
export * from '../internals/context';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from './mutationLike';
|
||||
export * from './queryLike';
|
||||
export * from './routerLike';
|
||||
export * from './utilsLike';
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import type {
|
||||
AnyProcedure,
|
||||
AnyRootTypes,
|
||||
inferProcedureInput,
|
||||
inferTransformedProcedureOutput,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type {
|
||||
InferMutationOptions,
|
||||
InferMutationResult,
|
||||
} from '../../utils/inferReactQueryProcedure';
|
||||
|
||||
/**
|
||||
* Use to describe a mutation route which matches a given mutation procedure's interface
|
||||
*/
|
||||
export type MutationLike<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
> = {
|
||||
useMutation: (
|
||||
opts?: InferMutationOptions<TRoot, TProcedure>,
|
||||
) => InferMutationResult<TRoot, TProcedure>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Use to unwrap a MutationLike's input
|
||||
*/
|
||||
export type InferMutationLikeInput<
|
||||
TMutationLike extends MutationLike<any, any>,
|
||||
> =
|
||||
TMutationLike extends MutationLike<any, infer $Procedure>
|
||||
? inferProcedureInput<$Procedure>
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Use to unwrap a MutationLike's data output
|
||||
*/
|
||||
export type InferMutationLikeData<
|
||||
TMutationLike extends MutationLike<any, any>,
|
||||
> =
|
||||
TMutationLike extends MutationLike<infer TRoot, infer TProcedure>
|
||||
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
||||
: never;
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import type { TRPCClientErrorLike } from '@trpc/client';
|
||||
import type {
|
||||
AnyProcedure,
|
||||
AnyRootTypes,
|
||||
inferProcedureInput,
|
||||
inferProcedureOutput,
|
||||
inferTransformedProcedureOutput,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { DecoratedQuery } from '../../createTRPCReact';
|
||||
import type {
|
||||
InferQueryOptions,
|
||||
InferQueryResult,
|
||||
} from '../../utils/inferReactQueryProcedure';
|
||||
import type { UseTRPCSuspenseQueryResult } from '../hooks/types';
|
||||
|
||||
/**
|
||||
* Use to request a query route which matches a given query procedure's interface
|
||||
*/
|
||||
export type QueryLike<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
> = {
|
||||
useQuery: (
|
||||
variables: inferProcedureInput<TProcedure>,
|
||||
opts?: InferQueryOptions<TRoot, TProcedure, any>,
|
||||
) => InferQueryResult<TRoot, TProcedure>;
|
||||
|
||||
useSuspenseQuery: (
|
||||
variables: inferProcedureInput<TProcedure>,
|
||||
opts?: InferQueryOptions<TRoot, TProcedure, any>,
|
||||
) => UseTRPCSuspenseQueryResult<
|
||||
inferProcedureOutput<TProcedure>,
|
||||
TRPCClientErrorLike<TRoot>
|
||||
>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Use to unwrap a QueryLike's input
|
||||
*/
|
||||
export type InferQueryLikeInput<TQueryLike> =
|
||||
TQueryLike extends DecoratedQuery<infer $Def>
|
||||
? $Def['input']
|
||||
: TQueryLike extends QueryLike<any, infer TProcedure>
|
||||
? inferProcedureInput<TProcedure>
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Use to unwrap a QueryLike's data output
|
||||
*/
|
||||
export type InferQueryLikeData<TQueryLike> =
|
||||
TQueryLike extends DecoratedQuery<infer $Def>
|
||||
? $Def['output']
|
||||
: TQueryLike extends QueryLike<infer TRoot, infer TProcedure>
|
||||
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
||||
: never;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import type {
|
||||
AnyMutationProcedure,
|
||||
AnyQueryProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { MutationLike } from './mutationLike';
|
||||
import type { QueryLike } from './queryLike';
|
||||
|
||||
/**
|
||||
* Use to describe a route path which matches a given route's interface
|
||||
*/
|
||||
export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>;
|
||||
export type RouterLikeInner<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? QueryLike<TRoot, $Value>
|
||||
: $Value extends AnyMutationProcedure
|
||||
? MutationLike<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? RouterLikeInner<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Use to describe a route path which matches a given route's interface
|
||||
// */
|
||||
// export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
||||
// TRouter['_def']['_config']['$types'],
|
||||
// TRouter['_def']['procedures']
|
||||
// >;
|
||||
// export type RouterLikeInner<
|
||||
// TRoot extends AnyRootTypes,
|
||||
// TRecord extends RouterRecord,
|
||||
// > = DecorateRouterRecord<TRoot, TRecord>;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { DecoratedProcedureUtilsRecord } from '../proxy/utilsProxy';
|
||||
|
||||
/**
|
||||
* Use to describe a Utils/Context path which matches the given route's interface
|
||||
*/
|
||||
export type UtilsLike<TRouter extends AnyRouter> =
|
||||
DecoratedProcedureUtilsRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>;
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
||||
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { CreateReactQueryHooks } from '../hooks/createHooksInternal';
|
||||
|
||||
/**
|
||||
* Create proxy for decorating procedures
|
||||
* @internal
|
||||
*/
|
||||
export function createReactDecoration<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext = unknown,
|
||||
>(hooks: CreateReactQueryHooks<TRouter, TSSRContext>) {
|
||||
return createRecursiveProxy(({ path, args }) => {
|
||||
const pathCopy = [...path];
|
||||
|
||||
// The last arg is for instance `.useMutation` or `.useQuery()`
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const lastArg = pathCopy.pop()!;
|
||||
|
||||
if (lastArg === 'useMutation') {
|
||||
return (hooks as any)[lastArg](pathCopy, ...args);
|
||||
}
|
||||
|
||||
if (lastArg === '_def') {
|
||||
return {
|
||||
path: pathCopy,
|
||||
};
|
||||
}
|
||||
|
||||
const [input, ...rest] = args;
|
||||
const opts = rest[0] ?? {};
|
||||
|
||||
return (hooks as any)[lastArg](pathCopy, input, opts);
|
||||
});
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
import type { QueryOptions } from '@tanstack/react-query';
|
||||
import type { TRPCClient } from '@trpc/client';
|
||||
import {
|
||||
getUntypedClient,
|
||||
TRPCUntypedClient,
|
||||
type TRPCClientError,
|
||||
} from '@trpc/client';
|
||||
import type {
|
||||
AnyProcedure,
|
||||
AnyQueryProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
inferProcedureInput,
|
||||
inferTransformedProcedureOutput,
|
||||
RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
||||
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
||||
import type {
|
||||
TrpcQueryOptionsForUseQueries,
|
||||
TrpcQueryOptionsForUseSuspenseQueries,
|
||||
} from '../../internals/useQueries';
|
||||
import type { TRPCUseQueryBaseOptions } from '../hooks/types';
|
||||
|
||||
type GetQueryOptions<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TrpcQueryOptionsForUseQueries<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
) => TrpcQueryOptionsForUseQueries<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseQueriesProcedureRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? GetQueryOptions<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? UseQueriesProcedureRecord<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
type GetSuspenseQueryOptions<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyQueryProcedure,
|
||||
> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TrpcQueryOptionsForUseSuspenseQueries<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
) => TrpcQueryOptionsForUseSuspenseQueries<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type UseSuspenseQueriesProcedureRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? GetSuspenseQueryOptions<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? UseSuspenseQueriesProcedureRecord<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create proxy for `useQueries` options
|
||||
* @internal
|
||||
*/
|
||||
export function createUseQueries<TRouter extends AnyRouter>(
|
||||
client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>,
|
||||
) {
|
||||
const untypedClient: TRPCUntypedClient<TRouter> =
|
||||
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
|
||||
return createRecursiveProxy<
|
||||
UseQueriesProcedureRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>
|
||||
>((opts) => {
|
||||
const arrayPath = opts.path;
|
||||
const dotPath = arrayPath.join('.');
|
||||
const [input, _opts] = opts.args as [
|
||||
unknown,
|
||||
Partial<QueryOptions> & TRPCUseQueryBaseOptions,
|
||||
];
|
||||
|
||||
const options: QueryOptions = {
|
||||
queryKey: getQueryKeyInternal(arrayPath, input, 'query'),
|
||||
queryFn: () => {
|
||||
return untypedClient.query(dotPath, input, _opts?.trpc);
|
||||
},
|
||||
..._opts,
|
||||
};
|
||||
|
||||
return options;
|
||||
});
|
||||
}
|
||||
+553
@@ -0,0 +1,553 @@
|
||||
import type {
|
||||
CancelOptions,
|
||||
InfiniteData,
|
||||
InvalidateOptions,
|
||||
InvalidateQueryFilters,
|
||||
Query,
|
||||
QueryFilters,
|
||||
QueryKey,
|
||||
RefetchOptions,
|
||||
RefetchQueryFilters,
|
||||
ResetOptions,
|
||||
SetDataOptions,
|
||||
SkipToken,
|
||||
Updater,
|
||||
} from '@tanstack/react-query';
|
||||
import type { TRPCClientError } from '@trpc/client';
|
||||
import { createTRPCClientProxy } from '@trpc/client';
|
||||
import type {
|
||||
AnyMutationProcedure,
|
||||
AnyQueryProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
DeepPartial,
|
||||
inferProcedureInput,
|
||||
inferProcedureOutput,
|
||||
inferTransformedProcedureOutput,
|
||||
ProtectedIntersection,
|
||||
RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import {
|
||||
createFlatProxy,
|
||||
createRecursiveProxy,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type {
|
||||
DecoratedTRPCContextProps,
|
||||
TRPCContextState,
|
||||
TRPCFetchInfiniteQueryOptions,
|
||||
TRPCFetchQueryOptions,
|
||||
TRPCQueryUtils,
|
||||
} from '../../internals/context';
|
||||
import { contextProps } from '../../internals/context';
|
||||
import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
|
||||
import {
|
||||
getMutationKeyInternal,
|
||||
getQueryKeyInternal,
|
||||
} from '../../internals/getQueryKey';
|
||||
import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
|
||||
import type { ExtractCursorType } from '../hooks/types';
|
||||
import type {
|
||||
DefinedTRPCInfiniteQueryOptionsIn,
|
||||
DefinedTRPCInfiniteQueryOptionsOut,
|
||||
DefinedTRPCQueryOptionsIn,
|
||||
DefinedTRPCQueryOptionsOut,
|
||||
UndefinedTRPCInfiniteQueryOptionsIn,
|
||||
UndefinedTRPCInfiniteQueryOptionsOut,
|
||||
UndefinedTRPCQueryOptionsIn,
|
||||
UndefinedTRPCQueryOptionsOut,
|
||||
UnusedSkipTokenTRPCInfiniteQueryOptionsIn,
|
||||
UnusedSkipTokenTRPCInfiniteQueryOptionsOut,
|
||||
UnusedSkipTokenTRPCQueryOptionsIn,
|
||||
UnusedSkipTokenTRPCQueryOptionsOut,
|
||||
} from '../types';
|
||||
|
||||
export type DecorateQueryProcedure<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyQueryProcedure,
|
||||
> = {
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure> | SkipToken,
|
||||
opts: DefinedTRPCQueryOptionsIn<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure> | SkipToken,
|
||||
opts?: UnusedSkipTokenTRPCQueryOptionsIn<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): UnusedSkipTokenTRPCQueryOptionsOut<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
||||
*/
|
||||
queryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure> | SkipToken,
|
||||
opts?: UndefinedTRPCQueryOptionsIn<
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): UndefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure> | SkipToken,
|
||||
opts: DefinedTRPCInfiniteQueryOptionsIn<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): DefinedTRPCInfiniteQueryOptionsOut<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
/**
|
||||
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
||||
*/
|
||||
infiniteQueryOptions<
|
||||
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TData = TQueryFnData,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure> | SkipToken,
|
||||
opts?: UndefinedTRPCInfiniteQueryOptionsIn<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): UndefinedTRPCInfiniteQueryOptionsOut<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TRPCClientError<TRoot>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
||||
*/
|
||||
fetch(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchQueryOptions<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
||||
*/
|
||||
fetchInfinite(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchInfiniteQueryOptions<
|
||||
inferProcedureInput<TProcedure>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): Promise<
|
||||
InfiniteData<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
||||
>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchquery
|
||||
*/
|
||||
prefetch(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchQueryOptions<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
||||
*/
|
||||
prefetchInfinite(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchInfiniteQueryOptions<
|
||||
inferProcedureInput<TProcedure>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
||||
*/
|
||||
ensureData(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
opts?: TRPCFetchQueryOptions<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientError<TRoot>
|
||||
>,
|
||||
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
||||
*/
|
||||
invalidate(
|
||||
input?: DeepPartial<inferProcedureInput<TProcedure>>,
|
||||
filters?: Omit<InvalidateQueryFilters, 'predicate'> & {
|
||||
predicate?: (
|
||||
query: Query<
|
||||
inferProcedureOutput<TProcedure>,
|
||||
TRPCClientError<TRoot>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
QueryKeyKnown<
|
||||
inferProcedureInput<TProcedure>,
|
||||
inferProcedureInput<TProcedure> extends { cursor?: any } | void
|
||||
? 'infinite'
|
||||
: 'query'
|
||||
>
|
||||
>,
|
||||
) => boolean;
|
||||
},
|
||||
options?: InvalidateOptions,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries
|
||||
*/
|
||||
refetch(
|
||||
input?: inferProcedureInput<TProcedure>,
|
||||
filters?: RefetchQueryFilters,
|
||||
options?: RefetchOptions,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientcancelqueries
|
||||
*/
|
||||
cancel(
|
||||
input?: inferProcedureInput<TProcedure>,
|
||||
options?: CancelOptions,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries
|
||||
*/
|
||||
reset(
|
||||
input?: inferProcedureInput<TProcedure>,
|
||||
options?: ResetOptions,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
updater: Updater<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined
|
||||
>,
|
||||
options?: SetDataOptions,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setQueriesData(
|
||||
/**
|
||||
* The input of the procedure
|
||||
*/
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
filters: QueryFilters,
|
||||
updater: Updater<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined
|
||||
>,
|
||||
options?: SetDataOptions,
|
||||
): [QueryKey, inferTransformedProcedureOutput<TRoot, TProcedure>];
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata
|
||||
*/
|
||||
setInfiniteData(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
updater: Updater<
|
||||
| InfiniteData<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
||||
>
|
||||
| undefined,
|
||||
| InfiniteData<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
||||
>
|
||||
| undefined
|
||||
>,
|
||||
options?: SetDataOptions,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getData(
|
||||
input?: inferProcedureInput<TProcedure>,
|
||||
): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
||||
*/
|
||||
getInfiniteData(
|
||||
input?: inferProcedureInput<TProcedure>,
|
||||
):
|
||||
| InfiniteData<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
||||
>
|
||||
| undefined;
|
||||
};
|
||||
|
||||
type DecorateMutationProcedure<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyMutationProcedure,
|
||||
> = {
|
||||
setMutationDefaults<TMeta = unknown>(
|
||||
options:
|
||||
| InferMutationOptions<TRoot, TProcedure, TMeta>
|
||||
| ((args: {
|
||||
canonicalMutationFn: NonNullable<
|
||||
InferMutationOptions<TRoot, TProcedure>['mutationFn']
|
||||
>;
|
||||
}) => InferMutationOptions<TRoot, TProcedure, TMeta>),
|
||||
): void;
|
||||
|
||||
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
||||
|
||||
isMutating(): number;
|
||||
};
|
||||
|
||||
/**
|
||||
* this is the type that is used to add in procedures that can be used on
|
||||
* an entire router
|
||||
*/
|
||||
type DecorateRouter = {
|
||||
/**
|
||||
* Invalidate the full router
|
||||
* @see https://trpc.io/docs/v10/useContext#query-invalidation
|
||||
* @see https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
||||
*/
|
||||
invalidate(
|
||||
input?: undefined,
|
||||
filters?: InvalidateQueryFilters,
|
||||
options?: InvalidateOptions,
|
||||
): Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type DecoratedProcedureUtilsRecord<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = DecorateRouter & {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? DecorateQueryProcedure<TRoot, $Value>
|
||||
: $Value extends AnyMutationProcedure
|
||||
? DecorateMutationProcedure<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter
|
||||
: never
|
||||
: never;
|
||||
}; // Add functions that should be available at utils root
|
||||
|
||||
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> &
|
||||
DecorateMutationProcedure<any, any>;
|
||||
|
||||
export type CreateReactUtils<
|
||||
TRouter extends AnyRouter,
|
||||
TSSRContext,
|
||||
> = ProtectedIntersection<
|
||||
DecoratedTRPCContextProps<TRouter, TSSRContext>,
|
||||
DecoratedProcedureUtilsRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>
|
||||
>;
|
||||
|
||||
export type CreateQueryUtils<TRouter extends AnyRouter> =
|
||||
DecoratedProcedureUtilsRecord<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>;
|
||||
|
||||
export const getQueryType = (
|
||||
utilName: keyof AnyDecoratedProcedure,
|
||||
): QueryType => {
|
||||
switch (utilName) {
|
||||
case 'queryOptions':
|
||||
case 'fetch':
|
||||
case 'ensureData':
|
||||
case 'prefetch':
|
||||
case 'getData':
|
||||
case 'setData':
|
||||
case 'setQueriesData':
|
||||
return 'query';
|
||||
|
||||
case 'infiniteQueryOptions':
|
||||
case 'fetchInfinite':
|
||||
case 'prefetchInfinite':
|
||||
case 'getInfiniteData':
|
||||
case 'setInfiniteData':
|
||||
return 'infinite';
|
||||
|
||||
case 'setMutationDefaults':
|
||||
case 'getMutationDefaults':
|
||||
case 'isMutating':
|
||||
case 'cancel':
|
||||
case 'invalidate':
|
||||
case 'refetch':
|
||||
case 'reset':
|
||||
return 'any';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
||||
context: TRPCQueryUtils<TRouter>,
|
||||
) {
|
||||
return createRecursiveProxy<CreateQueryUtils<TRouter>>((opts) => {
|
||||
const path = [...opts.path];
|
||||
const utilName = path.pop() as keyof AnyDecoratedProcedure;
|
||||
const args = [...opts.args] as Parameters<
|
||||
AnyDecoratedProcedure[typeof utilName]
|
||||
>;
|
||||
const input = args.shift(); // args can now be spread when input removed
|
||||
const queryType = getQueryType(utilName);
|
||||
const queryKey = getQueryKeyInternal(path, input, queryType);
|
||||
|
||||
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
||||
infiniteQueryOptions: () =>
|
||||
context.infiniteQueryOptions(path, queryKey, args[0]),
|
||||
queryOptions: () => context.queryOptions(path, queryKey, ...args),
|
||||
/**
|
||||
* DecorateQueryProcedure
|
||||
*/
|
||||
fetch: () => context.fetchQuery(queryKey, ...args),
|
||||
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
||||
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
||||
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
|
||||
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
||||
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
||||
reset: () => context.resetQueries(queryKey, ...args),
|
||||
refetch: () => context.refetchQueries(queryKey, ...args),
|
||||
cancel: () => context.cancelQuery(queryKey, ...args),
|
||||
setData: () => {
|
||||
context.setQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
setQueriesData: () =>
|
||||
context.setQueriesData(queryKey, args[0], args[1], args[2]),
|
||||
setInfiniteData: () => {
|
||||
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
||||
},
|
||||
getData: () => context.getQueryData(queryKey),
|
||||
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
||||
/**
|
||||
* DecorateMutationProcedure
|
||||
*/
|
||||
setMutationDefaults: () =>
|
||||
context.setMutationDefaults(getMutationKeyInternal(path), input),
|
||||
getMutationDefaults: () =>
|
||||
context.getMutationDefaults(getMutationKeyInternal(path)),
|
||||
isMutating: () =>
|
||||
context.isMutating({ mutationKey: getMutationKeyInternal(path) }),
|
||||
};
|
||||
|
||||
return contextMap[utilName]();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
|
||||
context: TRPCContextState<AnyRouter, TSSRContext>,
|
||||
) {
|
||||
type CreateReactUtilsReturnType = CreateReactUtils<TRouter, TSSRContext>;
|
||||
|
||||
const clientProxy = createTRPCClientProxy(context.client);
|
||||
|
||||
const proxy = createRecursiveUtilsProxy(
|
||||
context,
|
||||
) as CreateReactUtilsReturnType;
|
||||
|
||||
return createFlatProxy<CreateReactUtilsReturnType>((key) => {
|
||||
const contextName = key as (typeof contextProps)[number];
|
||||
if (contextName === 'client') {
|
||||
return clientProxy;
|
||||
}
|
||||
if (contextProps.includes(contextName)) {
|
||||
return context[contextName];
|
||||
}
|
||||
|
||||
return proxy[key];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createQueryUtilsProxy<TRouter extends AnyRouter>(
|
||||
context: TRPCQueryUtils<TRouter>,
|
||||
): CreateQueryUtils<TRouter> {
|
||||
return createRecursiveUtilsProxy(context);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import type { QueryClientConfig } from '@tanstack/react-query';
|
||||
import { QueryClient } from '@tanstack/react-query';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type CreateTRPCReactQueryClientConfig =
|
||||
| {
|
||||
queryClient?: QueryClient;
|
||||
queryClientConfig?: never;
|
||||
}
|
||||
| {
|
||||
queryClientConfig?: QueryClientConfig;
|
||||
queryClient?: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const getQueryClient = (config: CreateTRPCReactQueryClientConfig) =>
|
||||
config.queryClient ?? new QueryClient(config.queryClientConfig);
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
import type {
|
||||
DataTag,
|
||||
DefinedInitialDataInfiniteOptions,
|
||||
DefinedInitialDataOptions,
|
||||
InfiniteData,
|
||||
QueryClient,
|
||||
UndefinedInitialDataInfiniteOptions,
|
||||
UndefinedInitialDataOptions,
|
||||
UnusedSkipTokenInfiniteOptions,
|
||||
UnusedSkipTokenOptions,
|
||||
} from '@tanstack/react-query';
|
||||
import type {
|
||||
AnyRouter,
|
||||
coerceAsyncIterableToArray,
|
||||
DistributiveOmit,
|
||||
MaybePromise,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
||||
import type { ExtractCursorType, TRPCReactRequestOptions } from './hooks/types';
|
||||
|
||||
export interface TRPCQueryBaseOptions {
|
||||
/**
|
||||
* tRPC-related options
|
||||
*/
|
||||
trpc?: TRPCReactRequestOptions;
|
||||
}
|
||||
|
||||
export interface TRPCQueryOptionsResult {
|
||||
trpc: {
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
|
||||
type TRPCOptionOverrides = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
||||
type TRPCInfiniteOptionOverrides = TRPCOptionOverrides | 'initialPageParam';
|
||||
|
||||
/**
|
||||
* QueryOptions API helpers
|
||||
*/
|
||||
export interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
||||
extends DistributiveOmit<
|
||||
UndefinedInitialDataOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TData>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {}
|
||||
|
||||
export interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError>
|
||||
extends UndefinedInitialDataOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TOutput>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
|
||||
export interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
||||
extends DistributiveOmit<
|
||||
DefinedInitialDataOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TData>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {}
|
||||
|
||||
export interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError>
|
||||
extends DefinedInitialDataOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TData>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>, TError>;
|
||||
}
|
||||
|
||||
export interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
||||
extends DistributiveOmit<
|
||||
UnusedSkipTokenOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TData>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {}
|
||||
|
||||
export interface UnusedSkipTokenTRPCQueryOptionsOut<
|
||||
TQueryFnData,
|
||||
TOutput,
|
||||
TError,
|
||||
> extends UnusedSkipTokenOptions<
|
||||
coerceAsyncIterableToArray<TQueryFnData>,
|
||||
TError,
|
||||
coerceAsyncIterableToArray<TOutput>,
|
||||
TRPCQueryKey
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
||||
}
|
||||
|
||||
/**
|
||||
* InifiniteQueryOptions helpers
|
||||
*/
|
||||
export interface UndefinedTRPCInfiniteQueryOptionsIn<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
UndefinedInitialDataInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
TRPCInfiniteOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
export interface UndefinedTRPCInfiniteQueryOptionsOut<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
UndefinedInitialDataInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
'initialPageParam'
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
export interface DefinedTRPCInfiniteQueryOptionsIn<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
DefinedInitialDataInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
TRPCInfiniteOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
export interface DefinedTRPCInfiniteQueryOptionsOut<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
DefinedInitialDataInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
'initialPageParam'
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
UnusedSkipTokenInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
TRPCInfiniteOptionOverrides
|
||||
>,
|
||||
TRPCQueryBaseOptions {
|
||||
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
||||
TInput,
|
||||
TQueryFnData,
|
||||
TData,
|
||||
TError,
|
||||
> extends DistributiveOmit<
|
||||
UnusedSkipTokenInfiniteOptions<
|
||||
TQueryFnData,
|
||||
TError,
|
||||
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
||||
TRPCQueryKey,
|
||||
NonNullable<ExtractCursorType<TInput>> | null
|
||||
>,
|
||||
'initialPageParam'
|
||||
>,
|
||||
TRPCQueryOptionsResult {
|
||||
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
||||
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface UseMutationOverride {
|
||||
onSuccess: (opts: {
|
||||
/**
|
||||
* Calls the original function that was defined in the query's `onSuccess` option
|
||||
*/
|
||||
originalFn: () => MaybePromise<void>;
|
||||
queryClient: QueryClient;
|
||||
/**
|
||||
* Meta data passed in from the `useMutation()` hook
|
||||
*/
|
||||
meta: Record<string, unknown>;
|
||||
}) => MaybePromise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
||||
/**
|
||||
* Override behaviors of the built-in hooks
|
||||
*/
|
||||
overrides?: {
|
||||
useMutation?: Partial<UseMutationOverride>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abort all queries when unmounting
|
||||
* @default false
|
||||
*/
|
||||
abortOnUnmount?: boolean;
|
||||
|
||||
/**
|
||||
* Override the default context provider
|
||||
* @default undefined
|
||||
*/
|
||||
context?: React.Context<any>;
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
import type { QueryFunctionContext } from '@tanstack/react-query';
|
||||
import {
|
||||
infiniteQueryOptions,
|
||||
queryOptions,
|
||||
skipToken,
|
||||
type QueryClient,
|
||||
} from '@tanstack/react-query';
|
||||
import type { TRPCClient, TRPCClientError } from '@trpc/client';
|
||||
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
||||
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
||||
import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
||||
import type { AnyClientTypes } from '@trpc/server/unstable-core-do-not-import/clientish/inferrable';
|
||||
import { getClientArgs } from '../internals/getClientArgs';
|
||||
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
||||
import {
|
||||
buildQueryFromAsyncIterable,
|
||||
createTRPCOptionsResult,
|
||||
} from '../internals/trpcResult';
|
||||
import type { DefinedTRPCQueryOptionsOut } from '../shared';
|
||||
import { type TRPCQueryUtils } from '../shared';
|
||||
|
||||
export interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
||||
/**
|
||||
* The `TRPCClient`
|
||||
*/
|
||||
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
||||
/**
|
||||
* The `QueryClient` from `react-query`
|
||||
*/
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a set of utility functions that can be used to interact with `react-query`
|
||||
* @param opts the `TRPCClient` and `QueryClient` to use
|
||||
* @returns a set of utility functions that can be used to interact with `react-query`
|
||||
* @internal
|
||||
*/
|
||||
export function createUtilityFunctions<TRouter extends AnyRouter>(
|
||||
opts: CreateQueryUtilsOptions<TRouter>,
|
||||
): TRPCQueryUtils<TRouter> {
|
||||
const { client, queryClient } = opts;
|
||||
const untypedClient =
|
||||
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
||||
|
||||
return {
|
||||
infiniteQueryOptions: (path, queryKey, opts) => {
|
||||
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
||||
|
||||
const queryFn = async (
|
||||
queryFnContext: QueryFunctionContext<TRPCQueryKey, unknown>,
|
||||
): Promise<unknown> => {
|
||||
const actualOpts = {
|
||||
...opts,
|
||||
trpc: {
|
||||
...opts?.trpc,
|
||||
...(opts?.trpc?.abortOnUnmount
|
||||
? { signal: queryFnContext.signal }
|
||||
: { signal: null }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await untypedClient.query(
|
||||
...getClientArgs(queryKey, actualOpts, {
|
||||
direction: queryFnContext.direction,
|
||||
pageParam: queryFnContext.pageParam,
|
||||
}),
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return Object.assign(
|
||||
infiniteQueryOptions({
|
||||
...opts,
|
||||
initialData: opts?.initialData as any,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
||||
initialPageParam: (opts?.initialCursor as any) ?? null,
|
||||
}),
|
||||
{ trpc: createTRPCOptionsResult({ path }) },
|
||||
);
|
||||
},
|
||||
|
||||
queryOptions: (path, queryKey, opts) => {
|
||||
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
||||
|
||||
const queryFn = async (
|
||||
queryFnContext: QueryFunctionContext<TRPCQueryKey>,
|
||||
): Promise<unknown> => {
|
||||
const actualOpts = {
|
||||
...opts,
|
||||
trpc: {
|
||||
...opts?.trpc,
|
||||
...(opts?.trpc?.abortOnUnmount
|
||||
? { signal: queryFnContext.signal }
|
||||
: { signal: null }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await untypedClient.query(
|
||||
...getClientArgs(queryKey, actualOpts),
|
||||
);
|
||||
|
||||
if (isAsyncIterable(result)) {
|
||||
return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return Object.assign(
|
||||
queryOptions({
|
||||
...opts,
|
||||
initialData: opts?.initialData,
|
||||
queryKey,
|
||||
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
||||
}),
|
||||
{ trpc: createTRPCOptionsResult({ path }) },
|
||||
) as DefinedTRPCQueryOptionsOut<
|
||||
unknown,
|
||||
unknown,
|
||||
TRPCClientError<AnyClientTypes>
|
||||
>;
|
||||
},
|
||||
|
||||
fetchQuery: (queryKey, opts) => {
|
||||
return queryClient.fetchQuery({
|
||||
...opts,
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
|
||||
});
|
||||
},
|
||||
|
||||
fetchInfiniteQuery: (queryKey, opts) => {
|
||||
return queryClient.fetchInfiniteQuery({
|
||||
...opts,
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(
|
||||
...getClientArgs(queryKey, opts, { pageParam, direction }),
|
||||
);
|
||||
},
|
||||
initialPageParam: opts?.initialCursor ?? null,
|
||||
});
|
||||
},
|
||||
|
||||
prefetchQuery: (queryKey, opts) => {
|
||||
return queryClient.prefetchQuery({
|
||||
...opts,
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
|
||||
});
|
||||
},
|
||||
|
||||
prefetchInfiniteQuery: (queryKey, opts) => {
|
||||
return queryClient.prefetchInfiniteQuery({
|
||||
...opts,
|
||||
queryKey,
|
||||
queryFn: ({ pageParam, direction }) => {
|
||||
return untypedClient.query(
|
||||
...getClientArgs(queryKey, opts, { pageParam, direction }),
|
||||
);
|
||||
},
|
||||
initialPageParam: opts?.initialCursor ?? null,
|
||||
});
|
||||
},
|
||||
|
||||
ensureQueryData: (queryKey, opts) => {
|
||||
return queryClient.ensureQueryData({
|
||||
...opts,
|
||||
queryKey,
|
||||
queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts)),
|
||||
});
|
||||
},
|
||||
|
||||
invalidateQueries: (queryKey, filters, options) => {
|
||||
return queryClient.invalidateQueries(
|
||||
{
|
||||
...filters,
|
||||
queryKey,
|
||||
},
|
||||
options,
|
||||
);
|
||||
},
|
||||
resetQueries: (queryKey, filters, options) => {
|
||||
return queryClient.resetQueries(
|
||||
{
|
||||
...filters,
|
||||
queryKey,
|
||||
},
|
||||
options,
|
||||
);
|
||||
},
|
||||
|
||||
refetchQueries: (queryKey, filters, options) => {
|
||||
return queryClient.refetchQueries(
|
||||
{
|
||||
...filters,
|
||||
queryKey,
|
||||
},
|
||||
options,
|
||||
);
|
||||
},
|
||||
|
||||
cancelQuery: (queryKey, options) => {
|
||||
return queryClient.cancelQueries(
|
||||
{
|
||||
queryKey,
|
||||
},
|
||||
options,
|
||||
);
|
||||
},
|
||||
|
||||
setQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater as any, options);
|
||||
},
|
||||
|
||||
// eslint-disable-next-line max-params
|
||||
setQueriesData: (queryKey, filters, updater, options) => {
|
||||
return queryClient.setQueriesData(
|
||||
{
|
||||
...filters,
|
||||
queryKey,
|
||||
},
|
||||
updater,
|
||||
options,
|
||||
);
|
||||
},
|
||||
|
||||
getQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
|
||||
setInfiniteQueryData: (queryKey, updater, options) => {
|
||||
return queryClient.setQueryData(queryKey, updater as any, options);
|
||||
},
|
||||
|
||||
getInfiniteQueryData: (queryKey) => {
|
||||
return queryClient.getQueryData(queryKey);
|
||||
},
|
||||
|
||||
setMutationDefaults: (mutationKey, options) => {
|
||||
const path = mutationKey[0];
|
||||
const canonicalMutationFn = (input: unknown) => {
|
||||
return untypedClient.mutation(
|
||||
...getClientArgs([path, { input }], opts),
|
||||
);
|
||||
};
|
||||
return queryClient.setMutationDefaults(
|
||||
mutationKey,
|
||||
typeof options === 'function'
|
||||
? options({ canonicalMutationFn })
|
||||
: options,
|
||||
);
|
||||
},
|
||||
|
||||
getMutationDefaults: (mutationKey) => {
|
||||
return queryClient.getMutationDefaults(mutationKey);
|
||||
},
|
||||
|
||||
isMutating: (filters) => {
|
||||
return queryClient.isMutating({
|
||||
...filters,
|
||||
exact: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
import type { TRPCClientErrorLike } from '@trpc/client';
|
||||
import type {
|
||||
AnyMutationProcedure,
|
||||
AnyProcedure,
|
||||
AnyQueryProcedure,
|
||||
AnyRootTypes,
|
||||
AnyRouter,
|
||||
inferProcedureInput,
|
||||
inferTransformedProcedureOutput,
|
||||
RouterRecord,
|
||||
} from '@trpc/server/unstable-core-do-not-import';
|
||||
import type {
|
||||
UseTRPCMutationOptions,
|
||||
UseTRPCMutationResult,
|
||||
UseTRPCQueryOptions,
|
||||
UseTRPCQueryResult,
|
||||
} from '../shared';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InferQueryOptions<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
TData = inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
> = Omit<
|
||||
UseTRPCQueryOptions<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientErrorLike<TRoot>,
|
||||
TData
|
||||
>,
|
||||
'select' | 'queryFn'
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InferMutationOptions<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
TMeta = unknown,
|
||||
> = UseTRPCMutationOptions<
|
||||
inferProcedureInput<TProcedure>,
|
||||
TRPCClientErrorLike<TRoot>,
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TMeta
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InferQueryResult<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
> = UseTRPCQueryResult<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientErrorLike<TRoot>
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InferMutationResult<
|
||||
TRoot extends AnyRootTypes,
|
||||
TProcedure extends AnyProcedure,
|
||||
TContext = unknown,
|
||||
> = UseTRPCMutationResult<
|
||||
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
||||
TRPCClientErrorLike<TRoot>,
|
||||
inferProcedureInput<TProcedure>,
|
||||
TContext
|
||||
>;
|
||||
|
||||
type inferReactQueryProcedureOptionsInner<
|
||||
TRoot extends AnyRootTypes,
|
||||
TRecord extends RouterRecord,
|
||||
> = {
|
||||
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
||||
? $Value extends AnyQueryProcedure
|
||||
? InferQueryOptions<TRoot, $Value>
|
||||
: $Value extends AnyMutationProcedure
|
||||
? InferMutationOptions<TRoot, $Value>
|
||||
: $Value extends RouterRecord
|
||||
? inferReactQueryProcedureOptionsInner<TRoot, $Value>
|
||||
: never
|
||||
: never;
|
||||
};
|
||||
|
||||
export type inferReactQueryProcedureOptions<TRouter extends AnyRouter> =
|
||||
inferReactQueryProcedureOptionsInner<
|
||||
TRouter['_def']['_config']['$types'],
|
||||
TRouter['_def']['record']
|
||||
>;
|
||||
Reference in New Issue
Block a user