@orpc/tanstack-query 2.0.0-beta.5 → 2.0.0-beta.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ import { CompositeRouterUtilsPlugin } from "./plugin.js";
2
+ import { ProcedureUtils, isProcedureUtilsOptions, mergeProcedureUtilsOptions } from "./procedure-utils.js";
3
+ import { SharedUtils } from "./shared-utils.js";
4
+ import { bindMethods, isNonPrimitive, pick, toArray } from "@orpc/shared";
5
+ import { RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
6
+ // src/router-utils.ts
7
+ /**
8
+ * Creates TanStack Query utils from a client, exposing query/mutation
9
+ * option builders for every procedure in the router.
10
+ *
11
+ * @remarks
12
+ * **Note**: Both client-side and server-side clients are supported.
13
+ *
14
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
15
+ */
16
+ function createRouterUtils(client, options = {}) {
17
+ const plugin = new CompositeRouterUtilsPlugin(options.plugins);
18
+ options = plugin.init(options);
19
+ return createRouterUtilsInternal(client, options, plugin);
20
+ }
21
+ function createRouterUtilsInternal(client, options, plugin) {
22
+ const path = toArray(options.path);
23
+ const utils = typeof client === "function" && (options.scoped === void 0 || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(path, client, plugin.initProcedureOptions(path, mergeProcedureUtilsOptions(pick(options, [
24
+ "prefix",
25
+ "serializer",
26
+ "queryInterceptors",
27
+ "streamedInterceptors",
28
+ "liveInterceptors",
29
+ "infiniteInterceptors",
30
+ "mutationInterceptors"
31
+ ]), options.scoped ?? {}))), { unbound: ["call"] }) : bindMethods(new SharedUtils(path, options));
32
+ const cache = /* @__PURE__ */ new Map();
33
+ return new Proxy(utils, { get(target, prop) {
34
+ const value = Reflect.get(target, prop);
35
+ if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) return value ?? Reflect.get(Object.prototype, prop);
36
+ const nextClient = Reflect.get(client, prop);
37
+ if (typeof prop !== "string" || !isNonPrimitive(nextClient)) return value;
38
+ let result = cache.get(prop);
39
+ if (result === void 0) {
40
+ const nextUtils = createRouterUtilsInternal(nextClient, {
41
+ ...options,
42
+ path: [...path, prop],
43
+ scoped: options.scoped?.[prop]
44
+ }, plugin);
45
+ result = typeof value !== "function" ? nextUtils : new Proxy(value, { get(target, prop) {
46
+ if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) return Reflect.get(target, prop);
47
+ return Reflect.get(nextUtils, prop);
48
+ } });
49
+ cache.set(prop, result);
50
+ }
51
+ return result;
52
+ } });
53
+ }
54
+ export { createRouterUtils };
@@ -0,0 +1,11 @@
1
+ import { OperationKey, OperationKeyBaseOptions, OperationKeyOptions } from "./key.js";
2
+ import { OperationType } from "./types.js";
3
+ export declare class SharedUtils<TInput> {
4
+ protected readonly path: string[];
5
+ protected readonly options: OperationKeyBaseOptions;
6
+ constructor(path: string[], options: OperationKeyBaseOptions);
7
+ /**
8
+ * Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
9
+ */
10
+ key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions>): OperationKey<TType, TInput>;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { generateOperationKey } from "./key.js";
2
+ // src/shared-utils.ts
3
+ var SharedUtils = class {
4
+ path;
5
+ options;
6
+ constructor(path, options) {
7
+ this.path = path;
8
+ this.options = options;
9
+ }
10
+ /**
11
+ * Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
12
+ */
13
+ key(options = {}) {
14
+ return generateOperationKey(this.path, {
15
+ ...options,
16
+ prefix: this.options.prefix,
17
+ serializer: this.options.serializer
18
+ });
19
+ }
20
+ };
21
+ export { SharedUtils };
package/dist/ssr.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { RouterUtilsPlugin } from "./plugin.js";
2
+ import { ProcedureUtilsOptions } from "./procedure-utils.js";
3
+ import { Public } from "@orpc/shared";
4
+ import { AnyNestedClient, InferClientContext, InferClientError, RPCJsonSerialization, RPCJsonSerializer } from "@orpc/client";
5
+ /**
6
+ * Creates `dehydrate` and `hydrate` query client defaults that preserve oRPC types.
7
+ *
8
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#custom-serializers | TanStack Query Integration - Custom Serializers}
9
+ */
10
+ export declare function createHydrationOptions(serializer?: Public<RPCJsonSerializer>): {
11
+ dehydrate: {
12
+ serializeData: (data: unknown) => RPCJsonSerialization;
13
+ };
14
+ hydrate: {
15
+ deserializeData: (data: RPCJsonSerialization) => unknown;
16
+ };
17
+ };
18
+ export interface StreamQuerySSRUtilsPluginOptions {
19
+ /**
20
+ * Whether utils run on the server, where streamed and live queries settle at their first data.
21
+ * Defaults to TanStack Query's `environmentManager.isServer()`.
22
+ */
23
+ isServer?: boolean | undefined;
24
+ }
25
+ /**
26
+ * Router utils plugin for SSR of streamed and live queries: sets `.streamedOptions` and `.liveOptions` defaults
27
+ * so they settle at their first data on the server, and reopen their stream on mount in the browser.
28
+ *
29
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-and-live-queries | TanStack Query Integration - Streamed and Live Queries}
30
+ */
31
+ export declare class StreamQuerySSRUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
32
+ private readonly options;
33
+ readonly name = "~stream-query-ssr";
34
+ constructor(options?: StreamQuerySSRUtilsPluginOptions);
35
+ initProcedureOptions(_path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
36
+ }
package/dist/ssr.js ADDED
@@ -0,0 +1,47 @@
1
+ import { mergeProcedureUtilsOptions } from "./procedure-utils.js";
2
+ import { RPCJsonSerializer } from "@orpc/client";
3
+ import { environmentManager } from "@tanstack/query-core";
4
+ // src/ssr.ts
5
+ /**
6
+ * Creates `dehydrate` and `hydrate` query client defaults that preserve oRPC types.
7
+ *
8
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#custom-serializers | TanStack Query Integration - Custom Serializers}
9
+ */
10
+ function createHydrationOptions(serializer = new RPCJsonSerializer()) {
11
+ return {
12
+ dehydrate: { serializeData(data) {
13
+ const { json, meta } = serializer.serializeJson(data);
14
+ return {
15
+ json,
16
+ meta
17
+ };
18
+ } },
19
+ hydrate: { deserializeData(data) {
20
+ return serializer.deserializeJson(data);
21
+ } }
22
+ };
23
+ }
24
+ /**
25
+ * Router utils plugin for SSR of streamed and live queries: sets `.streamedOptions` and `.liveOptions` defaults
26
+ * so they settle at their first data on the server, and reopen their stream on mount in the browser.
27
+ *
28
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-and-live-queries | TanStack Query Integration - Streamed and Live Queries}
29
+ */
30
+ var StreamQuerySSRUtilsPlugin = class {
31
+ options;
32
+ name = "~stream-query-ssr";
33
+ constructor(options = {}) {
34
+ this.options = options;
35
+ }
36
+ initProcedureOptions(_path, options) {
37
+ const defaults = this.options.isServer ?? environmentManager.isServer() ? {
38
+ settleOnFirstData: true,
39
+ refetchOnMount: false
40
+ } : { refetchOnMount: "always" };
41
+ return mergeProcedureUtilsOptions({
42
+ streamedOptions: defaults,
43
+ liveOptions: defaults
44
+ }, options);
45
+ }
46
+ };
47
+ export { StreamQuerySSRUtilsPlugin, createHydrationOptions };
@@ -0,0 +1,32 @@
1
+ import "@orpc/shared";
2
+ import "@tanstack/query-core";
3
+ export interface SerializableStreamedQueryOptions {
4
+ /**
5
+ * What a fetch does with existing data once its stream connects.
6
+ * Until then the data stays, so a query with data never returns to `pending`.
7
+ *
8
+ * - `'reset'`: the data becomes `[]`, then each chunk is appended.
9
+ * - `'append'`: the data is kept (trimmed to `maxChunks`), and each chunk is appended.
10
+ *
11
+ * @default 'reset'
12
+ */
13
+ refetchMode?: "append" | "reset" | undefined;
14
+ /**
15
+ * Limits the number of data chunks stored in the query result.
16
+ * Older chunks are removed when the limit is reached.
17
+ *
18
+ * @default Number.POSITIVE_INFINITY (unlimited)
19
+ */
20
+ maxChunks?: number | undefined;
21
+ }
22
+ export interface SettleOnFirstDataOptions {
23
+ /**
24
+ * Settles the fetch at its first data (streamed: when the stream connects; live: on the first event)
25
+ * instead of following the stream to its end. The stream is closed and the data kept.
26
+ * Use it only where nothing watches the stream, such as server rendering:
27
+ * a refetch while a query is mounted would also settle, closing its stream.
28
+ *
29
+ * @default false
30
+ */
31
+ settleOnFirstData?: boolean | undefined;
32
+ }
@@ -0,0 +1,38 @@
1
+ import { listenAbort, takeLast, throwIfAborted } from "@orpc/shared";
2
+ // src/stream-query.ts
3
+ /**
4
+ * A variant of `streamedQuery` where:
5
+ * - Options are serializable
6
+ * - The output is predictable
7
+ */
8
+ function serializableStreamedQuery(queryFn, { refetchMode = "reset", maxChunks = Number.POSITIVE_INFINITY, settleOnFirstData = false } = {}) {
9
+ return async (context) => {
10
+ const { client, queryKey, signal } = context;
11
+ const unlisten = listenAbort(signal, () => client.getQueryCache().find({
12
+ queryKey,
13
+ exact: true
14
+ })?.invalidate());
15
+ try {
16
+ const stream = await queryFn(context);
17
+ if (signal.aborted) {
18
+ await stream[Symbol.asyncIterator]().return?.();
19
+ throw signal.reason;
20
+ }
21
+ let data = client.setQueryData(queryKey, (current) => refetchMode === "append" && current ? takeLast(current, maxChunks) : []);
22
+ if (settleOnFirstData) {
23
+ await stream[Symbol.asyncIterator]().return?.();
24
+ return data;
25
+ }
26
+ for await (const chunk of stream) {
27
+ throwIfAborted(signal);
28
+ data = client.setQueryData(queryKey, (current) => takeLast([...current ?? [], chunk], maxChunks));
29
+ }
30
+ const cached = client.getQueryData(queryKey);
31
+ if (cached === void 0) return data;
32
+ return Array.isArray(cached) ? takeLast(cached, maxChunks) : cached;
33
+ } finally {
34
+ unlisten();
35
+ }
36
+ };
37
+ }
38
+ export { serializableStreamedQuery };
@@ -0,0 +1,14 @@
1
+ import { Public } from "@orpc/shared";
2
+ import { RPCJsonSerializer } from "@orpc/client";
3
+ export type StructuralSharing = <T>(oldData: unknown, newData: T) => T;
4
+ /**
5
+ * Creates a `structuralSharing` function that works like TanStack Query's default, but also keeps
6
+ * the previous reference for equal `Date`, `URL`, `Map` and `Set` values, which oRPC's serializer
7
+ * recreates on every response, and for custom types that serialize the same with a type-aware
8
+ * serializer like `RPCJsonSerializer`.
9
+ *
10
+ * Used by default in `.queryOptions`, `.liveOptions` and `.infiniteOptions`, pass `structuralSharing: false` to opt out.
11
+ *
12
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#structural-sharing | TanStack Query Integration - Structural Sharing}
13
+ */
14
+ export declare function createStructuralSharing(serializer?: Public<RPCJsonSerializer>): StructuralSharing;
@@ -0,0 +1,105 @@
1
+ import { setOwn, stringifyJSON } from "@orpc/shared";
2
+ // src/structural-sharing.ts
3
+ /**
4
+ * Creates a `structuralSharing` function that works like TanStack Query's default, but also keeps
5
+ * the previous reference for equal `Date`, `URL`, `Map` and `Set` values, which oRPC's serializer
6
+ * recreates on every response, and for custom types that serialize the same with a type-aware
7
+ * serializer like `RPCJsonSerializer`.
8
+ *
9
+ * Used by default in `.queryOptions`, `.liveOptions` and `.infiniteOptions`, pass `structuralSharing: false` to opt out.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#structural-sharing | TanStack Query Integration - Structural Sharing}
12
+ */
13
+ function createStructuralSharing(serializer) {
14
+ return (oldData, newData) => replaceEqualDeep(oldData, newData, 0, serializer);
15
+ }
16
+ function replaceEqualDeep(a, b, depth, serializer) {
17
+ if (Object.is(a, b)) return a;
18
+ if (depth > 500 || typeof a !== "object" || typeof b !== "object" || a === null || b === null) return b;
19
+ const proto = Object.getPrototypeOf(a);
20
+ if (proto !== Object.getPrototypeOf(b)) return b;
21
+ if ((proto === Date.prototype || proto === URL.prototype || proto === Set.prototype || proto === Map.prototype) && !hasOwnEnumerableKey(a) && !hasOwnEnumerableKey(b)) return replaceEqualBuiltIn(a, b, proto, depth, serializer);
22
+ if (Array.isArray(a)) return isPlainArray(a) && isPlainArray(b) ? replaceEqualArray(a, b, depth, serializer) : b;
23
+ if (proto === Object.prototype || proto === null || !proto.constructor) return replaceEqualObject(a, b, proto, depth, serializer);
24
+ return replaceEqualSerialized(a, b, depth, serializer);
25
+ }
26
+ function replaceEqualArray(a, b, depth, serializer) {
27
+ let copy;
28
+ for (let i = 0; i < b.length; i++) {
29
+ let value = b[i];
30
+ if (i < a.length) {
31
+ const aValue = a[i];
32
+ if (typeof aValue === "object" && typeof value === "object") value = replaceEqualDeep(aValue, value, depth + 1, serializer);
33
+ if (copy === void 0 && Object.is(value, aValue)) continue;
34
+ }
35
+ copy ??= copyArrayPrefix(a, i);
36
+ copy.push(value);
37
+ }
38
+ return copy ?? (a.length === b.length ? a : copyArrayPrefix(a, b.length));
39
+ }
40
+ function copyArrayPrefix(a, end) {
41
+ const copy = [];
42
+ for (let i = 0; i < end; i++) copy.push(a[i]);
43
+ return copy;
44
+ }
45
+ function replaceEqualObject(a, b, proto, depth, serializer) {
46
+ const bKeys = Object.keys(b);
47
+ let copy;
48
+ for (let i = 0; i < bKeys.length; i++) {
49
+ const key = bKeys[i];
50
+ let value = b[key];
51
+ if (Object.hasOwn(a, key)) {
52
+ const aValue = a[key];
53
+ if (typeof aValue === "object" && typeof value === "object") value = replaceEqualDeep(aValue, value, depth + 1, serializer);
54
+ if (copy === void 0 && Object.is(value, aValue)) continue;
55
+ }
56
+ copy ??= copyObjectPrefix(a, bKeys, i, proto);
57
+ assign(copy, key, value);
58
+ }
59
+ return copy ?? (Object.keys(a).length === bKeys.length ? a : copyObjectPrefix(a, bKeys, bKeys.length, proto));
60
+ }
61
+ function copyObjectPrefix(a, keys, end, proto) {
62
+ const copy = proto === Object.prototype ? {} : Object.create(proto);
63
+ for (let i = 0; i < end; i++) assign(copy, keys[i], a[keys[i]]);
64
+ return copy;
65
+ }
66
+ function assign(object, key, value) {
67
+ if (key === "__proto__") setOwn(object, key, value);
68
+ else object[key] = value;
69
+ }
70
+ function replaceEqualBuiltIn(a, b, proto, depth, serializer) {
71
+ if (proto === Date.prototype) return Object.is(a.getTime(), b.getTime()) ? a : b;
72
+ if (proto === URL.prototype) return a.href === b.href ? a : b;
73
+ if (a.size !== b.size) return b;
74
+ if (proto === Set.prototype) {
75
+ const aValues = a.values();
76
+ for (const bValue of b.values()) {
77
+ const aValue = aValues.next().value;
78
+ if (!Object.is(replaceEqualDeep(aValue, bValue, depth + 1, serializer), aValue)) return b;
79
+ }
80
+ return a;
81
+ }
82
+ const aKeys = a.keys();
83
+ const aValues = a.values();
84
+ const bValues = b.values();
85
+ for (const bKey of b.keys()) {
86
+ const aKey = aKeys.next().value;
87
+ const aValue = aValues.next().value;
88
+ if (!Object.is(replaceEqualDeep(aKey, bKey, depth + 1, serializer), aKey) || !Object.is(replaceEqualDeep(aValue, bValues.next().value, depth + 1, serializer), aValue)) return b;
89
+ }
90
+ return a;
91
+ }
92
+ function replaceEqualSerialized(a, b, depth, serializer) {
93
+ const aSerialized = serializer?.serializeJson(a);
94
+ if (!aSerialized?.meta?.length) return b;
95
+ const bSerialized = serializer.serializeJson(b);
96
+ return stringifyJSON(aSerialized.meta) === stringifyJSON(bSerialized.meta) && Object.is(replaceEqualDeep(aSerialized.json, bSerialized.json, depth + 1, serializer), aSerialized.json) ? a : b;
97
+ }
98
+ function hasOwnEnumerableKey(value) {
99
+ for (const key in value) if (Object.hasOwn(value, key)) return true;
100
+ return false;
101
+ }
102
+ function isPlainArray(value) {
103
+ return value.length === Object.keys(value).length;
104
+ }
105
+ export { createStructuralSharing };
@@ -0,0 +1,107 @@
1
+ import { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from "./stream-query.js";
2
+ import { ClientContext } from "@orpc/client";
3
+ import { DataTag, InfiniteData, InfiniteQueryObserverOptions, MutationObserverOptions, QueryFunction, QueryKey, QueryObserverOptions, SkipToken } from "@tanstack/query-core";
4
+ export type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
5
+ export type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
6
+ export type OperationType = "query" | "streamed" | "live" | "infinite" | "mutation";
7
+ /**
8
+ * The symbol under which TanStack Query utils attach operation details
9
+ * (key and operation type) to the client context.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
12
+ */
13
+ export declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
14
+ /**
15
+ * A client context automatically populated by TanStack Query utils,
16
+ * exposing the operation key and type of the calling operation.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
19
+ */
20
+ export interface OperationContext {
21
+ [OPERATION_CONTEXT_SYMBOL]?: {
22
+ key: QueryKey;
23
+ type: OperationType;
24
+ };
25
+ }
26
+ export type QueryKeyOptions<TInput> = (undefined extends TInput ? {
27
+ input?: TInput | SkipToken;
28
+ } : {
29
+ input: TInput | SkipToken;
30
+ }) | {
31
+ queryKey: QueryKey;
32
+ };
33
+ export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = (undefined extends TInput ? {
34
+ input?: TInput | SkipToken;
35
+ } : {
36
+ input: TInput | SkipToken;
37
+ }) & ({} extends TClientContext ? {
38
+ context?: TClientContext | undefined;
39
+ } : {
40
+ context: TClientContext;
41
+ }) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, "queryKey" | "_defaulted" | "_optimisticResults"> & {
42
+ queryKey?: QueryKey | undefined;
43
+ initialData?: TInitialData;
44
+ };
45
+ /**
46
+ * Rest parameters of `.queryOptions`: optional when input and context are.
47
+ * Cheaper than `MaybeOptionalOptions<QueryOptionsIn<...>>`.
48
+ */
49
+ export type QueryOptionsInRest<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = undefined extends TInput ? {} extends TClientContext ? [options?: QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>];
50
+ export type QueryOptionsOut<TOutput, TError, TSelectData, TInitialData> = Pick<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, DataTag<QueryKey, TOutput, TError>>, "queryKey" | "throwOnError" | "select" | "retryDelay"> & (undefined extends TInitialData ? object : {
51
+ initialData: TInitialData;
52
+ }) & {
53
+ queryFn: QueryFunction<TOutput, DataTag<QueryKey, TOutput, TError>>;
54
+ };
55
+ export type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
56
+ input?: TInput | SkipToken;
57
+ } : {
58
+ input: TInput | SkipToken;
59
+ }) & {
60
+ queryFnOptions?: SerializableStreamedQueryOptions | undefined;
61
+ }) | {
62
+ queryKey: QueryKey;
63
+ };
64
+ export type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & {
65
+ queryFnOptions?: SerializableStreamedQueryOptions | undefined;
66
+ } & SettleOnFirstDataOptions;
67
+ /**
68
+ * Rest parameters of `.streamedOptions`: optional when input and context are.
69
+ * Cheaper than `MaybeOptionalOptions<StreamedOptionsIn<...>>`.
70
+ */
71
+ export type StreamedOptionsInRest<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = undefined extends TInput ? {} extends TClientContext ? [options?: StreamedOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: StreamedOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: StreamedOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>];
72
+ export type StreamedOptionsOut<TOutput, TError, TSelectData, TInitialData> = QueryOptionsOut<TOutput, TError, TSelectData, TInitialData>;
73
+ export type LiveOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & SettleOnFirstDataOptions;
74
+ /**
75
+ * Rest parameters of `.liveOptions`: optional when input and context are.
76
+ * Cheaper than `MaybeOptionalOptions<LiveOptionsIn<...>>`.
77
+ */
78
+ export type LiveOptionsInRest<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = undefined extends TInput ? {} extends TClientContext ? [options?: LiveOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: LiveOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>] : [options: LiveOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData>];
79
+ export type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, any, TPageParam, any>, "input" | "initialPageParam"> | {
80
+ queryKey: QueryKey;
81
+ };
82
+ export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
83
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
84
+ initialData?: TInitialData;
85
+ queryKey?: QueryKey | undefined;
86
+ } & ({} extends TClientContext ? {
87
+ context?: TClientContext | undefined;
88
+ } : {
89
+ context: TClientContext;
90
+ }) & Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, "queryKey" | "_defaulted" | "_optimisticResults">;
91
+ export type InfiniteOptionsOut<TOutput, TError, TSelectData, TPageParam, TInitialData> = Pick<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>, "queryKey" | "select" | "throwOnError" | "retryDelay" | "initialPageParam" | "getNextPageParam" | "getPreviousPageParam"> & (undefined extends TInitialData ? object : {
92
+ initialData: TInitialData;
93
+ }) & {
94
+ queryFn: QueryFunction<TOutput, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>;
95
+ };
96
+ export type MutationKeyOptions = Pick<MutationOptionsIn<any, any, any, any, any>, "mutationKey">;
97
+ export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = ({} extends TClientContext ? {
98
+ context?: TClientContext | undefined;
99
+ } : {
100
+ context: TClientContext;
101
+ }) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
102
+ /**
103
+ * Rest parameters of `.mutationOptions`: optional when context is.
104
+ * Cheaper than `MaybeOptionalOptions<MutationOptionsIn<...>>`.
105
+ */
106
+ export type MutationOptionsInRest<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = {} extends TClientContext ? [options?: MutationOptionsIn<TClientContext, TInput, TOutput, TError, TMutationContext>] : [options: MutationOptionsIn<TClientContext, TInput, TOutput, TError, TMutationContext>];
107
+ export type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/types.ts
2
+ /**
3
+ * The symbol under which TanStack Query utils attach operation details
4
+ * (key and operation type) to the client context.
5
+ *
6
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
7
+ */
8
+ const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_TANSTACK_QUERY_OPERATION_CONTEXT");
9
+ export { OPERATION_CONTEXT_SYMBOL };
package/package.json CHANGED
@@ -1,53 +1,65 @@
1
1
  {
2
2
  "name": "@orpc/tanstack-query",
3
- "type": "module",
4
- "version": "2.0.0-beta.5",
5
- "license": "MIT",
3
+ "version": "2.0.0-beta.51",
4
+ "description": "TanStack Query integration for oRPC: typesafe queries, mutations, streaming, and SSR for React, Vue, Solid, Svelte, and Angular",
5
+ "keywords": [
6
+ "angular-query",
7
+ "mutation",
8
+ "orpc",
9
+ "query",
10
+ "react-query",
11
+ "solid-query",
12
+ "ssr",
13
+ "svelte-query",
14
+ "tanstack-query",
15
+ "typesafe",
16
+ "typescript",
17
+ "vue-query"
18
+ ],
6
19
  "homepage": "https://orpc.dev",
20
+ "license": "MIT",
7
21
  "repository": {
8
22
  "type": "git",
9
23
  "url": "git+https://github.com/middleapi/orpc.git",
10
24
  "directory": "packages/tanstack-query"
11
25
  },
12
- "keywords": [
13
- "orpc",
14
- "tanstack query"
26
+ "funding": [
27
+ "https://github.com/sponsors/dinwwwh",
28
+ "https://opencollective.com/middleapi"
15
29
  ],
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "type": "module",
16
34
  "sideEffects": false,
17
35
  "exports": {
18
36
  "./package.json": "./package.json",
19
37
  ".": {
20
- "types": "./dist/index.d.mts",
21
- "import": "./dist/index.mjs",
22
- "default": "./dist/index.mjs"
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
23
41
  }
24
42
  },
25
- "files": [
26
- "dist"
27
- ],
28
- "peerDependencies": {
29
- "@tanstack/query-core": ">=5.80.2"
30
- },
31
43
  "dependencies": {
32
- "@orpc/client": "2.0.0-beta.5",
33
- "@orpc/shared": "2.0.0-beta.5",
34
- "@orpc/openapi": "2.0.0-beta.5",
35
- "@orpc/contract": "2.0.0-beta.5"
44
+ "@orpc/client": "2.0.0-beta.51",
45
+ "@orpc/contract": "2.0.0-beta.51",
46
+ "@orpc/openapi": "2.0.0-beta.51",
47
+ "@orpc/shared": "2.0.0-beta.51"
36
48
  },
37
49
  "devDependencies": {
38
- "@angular/core": "^22.0.1",
39
- "@tanstack/angular-query-experimental": "^5.101.0",
40
- "@tanstack/query-core": "^5.101.0",
41
- "@tanstack/react-query": "^5.101.0",
42
- "@tanstack/solid-query": "^5.101.0",
43
- "@tanstack/svelte-query": "^6.1.34",
44
- "@tanstack/vue-query": "^5.101.0",
45
- "svelte": "^5.56.3",
46
- "vue": "^3.5.38",
47
- "zod": "^4.4.3"
50
+ "@angular/core": "^22.2.4",
51
+ "@tanstack/angular-query-experimental": "^5.105.3",
52
+ "@tanstack/query-core": "^5.105.3",
53
+ "@tanstack/react-query": "^5.105.3",
54
+ "@tanstack/solid-query": "^5.105.3",
55
+ "@tanstack/svelte-query": "^6.3.9",
56
+ "@tanstack/vue-query": "^5.105.3",
57
+ "svelte": "^5.57.3",
58
+ "vue": "^3.5.44",
59
+ "zod": "^4.6.7"
60
+ },
61
+ "peerDependencies": {
62
+ "@tanstack/query-core": ">=5.105.0"
48
63
  },
49
- "scripts": {
50
- "build": "unbuild",
51
- "type:check": "tsc -b"
52
- }
64
+ "scripts": {}
53
65
  }