@orpc/tanstack-query 2.0.0-beta.48 → 2.0.0-beta.49

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.
Files changed (54) hide show
  1. package/README.md +4 -4
  2. package/dist/contract-utils.d.ts +37 -0
  3. package/dist/contract-utils.js +42 -0
  4. package/dist/index.d.ts +16 -0
  5. package/dist/index.js +10 -0
  6. package/dist/key.d.ts +50 -0
  7. package/dist/key.js +50 -0
  8. package/dist/live-query.d.ts +4 -0
  9. package/dist/live-query.js +36 -0
  10. package/dist/meta.d.ts +42 -0
  11. package/dist/meta.js +55 -0
  12. package/dist/plugin.d.ts +51 -0
  13. package/dist/plugin.js +25 -0
  14. package/dist/procedure-utils.d.ts +167 -0
  15. package/dist/procedure-utils.js +411 -0
  16. package/dist/router-utils.d.ts +67 -0
  17. package/dist/router-utils.js +69 -0
  18. package/dist/shared-utils.d.ts +11 -0
  19. package/dist/shared-utils.js +19 -0
  20. package/dist/ssr.d.ts +37 -0
  21. package/dist/ssr.js +45 -0
  22. package/dist/stream-query.d.ts +38 -0
  23. package/dist/stream-query.js +52 -0
  24. package/dist/structural-sharing.d.ts +14 -0
  25. package/dist/structural-sharing.js +160 -0
  26. package/dist/types.d.ts +87 -0
  27. package/dist/types.js +7 -0
  28. package/package.json +39 -41
  29. package/dist/contract-utils.d.mts +0 -35
  30. package/dist/contract-utils.mjs +0 -23
  31. package/dist/index.d.mts +0 -16
  32. package/dist/index.mjs +0 -10
  33. package/dist/key.d.mts +0 -62
  34. package/dist/key.mjs +0 -30
  35. package/dist/live-query.d.mts +0 -6
  36. package/dist/live-query.mjs +0 -16
  37. package/dist/meta.d.mts +0 -55
  38. package/dist/meta.mjs +0 -37
  39. package/dist/plugin.d.mts +0 -51
  40. package/dist/plugin.mjs +0 -25
  41. package/dist/procedure-utils.d.mts +0 -232
  42. package/dist/procedure-utils.mjs +0 -406
  43. package/dist/router-utils.d.mts +0 -57
  44. package/dist/router-utils.mjs +0 -51
  45. package/dist/shared-utils.d.mts +0 -11
  46. package/dist/shared-utils.mjs +0 -17
  47. package/dist/ssr.d.mts +0 -38
  48. package/dist/ssr.mjs +0 -57
  49. package/dist/stream-query.d.mts +0 -30
  50. package/dist/stream-query.mjs +0 -58
  51. package/dist/structural-sharing.d.mts +0 -14
  52. package/dist/structural-sharing.mjs +0 -140
  53. package/dist/types.d.mts +0 -138
  54. package/dist/types.mjs +0 -2
@@ -0,0 +1,38 @@
1
+ import type { Promisable } from '@orpc/shared';
2
+ import type { QueryFunction, QueryFunctionContext, QueryKey } from '@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
+ }
33
+ /**
34
+ * A variant of `streamedQuery` where:
35
+ * - Options are serializable
36
+ * - The output is predictable
37
+ */
38
+ export declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>, { refetchMode, maxChunks, settleOnFirstData, }?: SerializableStreamedQueryOptions & SettleOnFirstDataOptions): QueryFunction<TQueryFnData[], TQueryKey>;
@@ -0,0 +1,52 @@
1
+ import { throwIfAborted } from '@orpc/shared';
2
+ /**
3
+ * A variant of `streamedQuery` where:
4
+ * - Options are serializable
5
+ * - The output is predictable
6
+ */
7
+ export function serializableStreamedQuery(queryFn, { refetchMode = 'reset', maxChunks = Number.POSITIVE_INFINITY, settleOnFirstData = false, } = {}) {
8
+ return async (context) => {
9
+ const { client, queryKey, signal } = context;
10
+ // a stream cut short (cancelled, or its last observer left) reopens when observed again;
11
+ // marked at abort, so the writes of a fetch that replaces this one clear it
12
+ const markStale = () => client.getQueryCache().find({ queryKey, exact: true })?.invalidate();
13
+ if (signal.aborted) {
14
+ markStale();
15
+ }
16
+ signal.addEventListener('abort', markStale, { once: true });
17
+ try {
18
+ const stream = await queryFn(context);
19
+ // close without reading, so a generator the query no longer wants never starts
20
+ if (signal.aborted) {
21
+ await stream[Symbol.asyncIterator]().return?.();
22
+ throw signal.reason;
23
+ }
24
+ let data = client.setQueryData(queryKey, (current) => refetchMode === 'append' && current ? limitArraySize(current, maxChunks) : []);
25
+ if (settleOnFirstData) {
26
+ await stream[Symbol.asyncIterator]().return?.();
27
+ return data;
28
+ }
29
+ for await (const chunk of stream) {
30
+ throwIfAborted(signal);
31
+ // read the cache, so writes made during the stream are kept
32
+ data = client.setQueryData(queryKey, (current = []) => limitArraySize([...current, chunk], maxChunks));
33
+ }
34
+ // the returned data is written again, so return the cache to keep later writes
35
+ const cached = client.getQueryData(queryKey);
36
+ if (cached === undefined) {
37
+ return data;
38
+ }
39
+ // only an array is trimmed; another value written after the stream (e.g. `null`) is kept as is
40
+ return Array.isArray(cached) ? limitArraySize(cached, maxChunks) : cached;
41
+ }
42
+ finally {
43
+ signal.removeEventListener('abort', markStale);
44
+ }
45
+ };
46
+ }
47
+ function limitArraySize(items, maxSize) {
48
+ if (items.length <= maxSize) {
49
+ return items;
50
+ }
51
+ return items.slice(items.length - maxSize);
52
+ }
@@ -0,0 +1,14 @@
1
+ import type { RPCJsonSerializer } from '@orpc/client';
2
+ import type { Public } from '@orpc/shared';
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,160 @@
1
+ import { setOwn, stringifyJSON } from '@orpc/shared';
2
+ /**
3
+ * Creates a `structuralSharing` function that works like TanStack Query's default, but also keeps
4
+ * the previous reference for equal `Date`, `URL`, `Map` and `Set` values, which oRPC's serializer
5
+ * recreates on every response, and for custom types that serialize the same with a type-aware
6
+ * serializer like `RPCJsonSerializer`.
7
+ *
8
+ * Used by default in `.queryOptions`, `.liveOptions` and `.infiniteOptions`, pass `structuralSharing: false` to opt out.
9
+ *
10
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#structural-sharing | TanStack Query Integration - Structural Sharing}
11
+ */
12
+ export function createStructuralSharing(serializer) {
13
+ return (oldData, newData) => replaceEqualDeep(oldData, newData, 0, serializer);
14
+ }
15
+ function replaceEqualDeep(a, b, depth, serializer) {
16
+ if (Object.is(a, b)) {
17
+ return a;
18
+ }
19
+ if (depth > 500 || typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
20
+ return b;
21
+ }
22
+ const proto = Object.getPrototypeOf(a);
23
+ if (proto !== Object.getPrototypeOf(b)) {
24
+ return b;
25
+ }
26
+ if ((proto === Date.prototype ||
27
+ proto === URL.prototype ||
28
+ proto === Set.prototype ||
29
+ proto === Map.prototype) &&
30
+ !hasOwnEnumerableKey(a) &&
31
+ !hasOwnEnumerableKey(b)) {
32
+ return replaceEqualBuiltIn(a, b, proto, depth, serializer);
33
+ }
34
+ if (Array.isArray(a)) {
35
+ return isPlainArray(a) && isPlainArray(b) ? replaceEqualArray(a, b, depth, serializer) : b;
36
+ }
37
+ // same rule as isPlainObject, but reusing the prototype read above is about 15% faster
38
+ if (proto === Object.prototype || proto === null || !proto.constructor) {
39
+ return replaceEqualObject(a, b, proto, depth, serializer);
40
+ }
41
+ return replaceEqualSerialized(a, b, depth, serializer);
42
+ }
43
+ function replaceEqualArray(a, b, depth, serializer) {
44
+ let copy;
45
+ for (let i = 0; i < b.length; i++) {
46
+ let value = b[i];
47
+ if (i < a.length) {
48
+ const aValue = a[i];
49
+ if (typeof aValue === 'object' && typeof value === 'object') {
50
+ value = replaceEqualDeep(aValue, value, depth + 1, serializer);
51
+ }
52
+ if (copy === undefined && Object.is(value, aValue)) {
53
+ continue;
54
+ }
55
+ }
56
+ copy ??= copyArrayPrefix(a, i);
57
+ copy.push(value);
58
+ }
59
+ return copy ?? (a.length === b.length ? a : copyArrayPrefix(a, b.length));
60
+ }
61
+ function copyArrayPrefix(a, end) {
62
+ const copy = [];
63
+ for (let i = 0; i < end; i++) {
64
+ copy.push(a[i]);
65
+ }
66
+ return copy;
67
+ }
68
+ function replaceEqualObject(a, b, proto, depth, serializer) {
69
+ const bKeys = Object.keys(b);
70
+ let copy;
71
+ for (let i = 0; i < bKeys.length; i++) {
72
+ const key = bKeys[i];
73
+ let value = b[key];
74
+ if (Object.hasOwn(a, key)) {
75
+ const aValue = a[key];
76
+ if (typeof aValue === 'object' && typeof value === 'object') {
77
+ value = replaceEqualDeep(aValue, value, depth + 1, serializer);
78
+ }
79
+ if (copy === undefined && Object.is(value, aValue)) {
80
+ continue;
81
+ }
82
+ }
83
+ copy ??= copyObjectPrefix(a, bKeys, i, proto);
84
+ assign(copy, key, value);
85
+ }
86
+ return (copy ??
87
+ (Object.keys(a).length === bKeys.length ? a : copyObjectPrefix(a, bKeys, bKeys.length, proto)));
88
+ }
89
+ function copyObjectPrefix(a, keys, end, proto) {
90
+ const copy = proto === Object.prototype ? {} : Object.create(proto);
91
+ for (let i = 0; i < end; i++) {
92
+ assign(copy, keys[i], a[keys[i]]);
93
+ }
94
+ return copy;
95
+ }
96
+ function assign(object, key, value) {
97
+ // same as always calling setOwn, but a plain assignment keeps the copy loops about 30% faster
98
+ if (key === '__proto__') {
99
+ setOwn(object, key, value);
100
+ }
101
+ else {
102
+ object[key] = value;
103
+ }
104
+ }
105
+ function replaceEqualBuiltIn(a, b, proto, depth, serializer) {
106
+ if (proto === Date.prototype) {
107
+ return Object.is(a.getTime(), b.getTime()) ? a : b;
108
+ }
109
+ if (proto === URL.prototype) {
110
+ return a.href === b.href ? a : b;
111
+ }
112
+ if (a.size !== b.size) {
113
+ return b;
114
+ }
115
+ if (proto === Set.prototype) {
116
+ const aValues = a.values();
117
+ for (const bValue of b.values()) {
118
+ const aValue = aValues.next().value;
119
+ if (!Object.is(replaceEqualDeep(aValue, bValue, depth + 1, serializer), aValue)) {
120
+ return b;
121
+ }
122
+ }
123
+ return a;
124
+ }
125
+ const aKeys = a.keys();
126
+ const aValues = a.values();
127
+ const bValues = b.values();
128
+ for (const bKey of b.keys()) {
129
+ const aKey = aKeys.next().value;
130
+ const aValue = aValues.next().value;
131
+ if (!Object.is(replaceEqualDeep(aKey, bKey, depth + 1, serializer), aKey) ||
132
+ !Object.is(replaceEqualDeep(aValue, bValues.next().value, depth + 1, serializer), aValue)) {
133
+ return b;
134
+ }
135
+ }
136
+ return a;
137
+ }
138
+ function replaceEqualSerialized(a, b, depth, serializer) {
139
+ const aSerialized = serializer?.serializeJson(a);
140
+ if (!aSerialized?.meta?.length) {
141
+ return b;
142
+ }
143
+ const bSerialized = serializer.serializeJson(b);
144
+ return stringifyJSON(aSerialized.meta) === stringifyJSON(bSerialized.meta) &&
145
+ Object.is(replaceEqualDeep(aSerialized.json, bSerialized.json, depth + 1, serializer), aSerialized.json)
146
+ ? a
147
+ : b;
148
+ }
149
+ function hasOwnEnumerableKey(value) {
150
+ // for...in avoids the array allocation of Object.keys, which matters on this hot path
151
+ for (const key in value) {
152
+ if (Object.hasOwn(value, key)) {
153
+ return true;
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+ function isPlainArray(value) {
159
+ return value.length === Object.keys(value).length;
160
+ }
@@ -0,0 +1,87 @@
1
+ import type { ClientContext } from '@orpc/client';
2
+ import type { DataTag, InfiniteData, InfiniteQueryObserverOptions, MutationObserverOptions, QueryFunction, QueryKey, QueryObserverOptions, SkipToken } from '@tanstack/query-core';
3
+ import type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query.ts';
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
+ }) & (object 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
+ 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 : {
46
+ initialData: TInitialData;
47
+ }) & {
48
+ queryFn: QueryFunction<TOutput, DataTag<QueryKey, TOutput, TError>>;
49
+ };
50
+ export type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
51
+ input?: TInput | SkipToken;
52
+ } : {
53
+ input: TInput | SkipToken;
54
+ }) & {
55
+ queryFnOptions?: SerializableStreamedQueryOptions | undefined;
56
+ }) | {
57
+ queryKey: QueryKey;
58
+ };
59
+ export type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & {
60
+ queryFnOptions?: SerializableStreamedQueryOptions | undefined;
61
+ } & SettleOnFirstDataOptions;
62
+ export type StreamedOptionsOut<TOutput, TError, TSelectData, TInitialData> = QueryOptionsOut<TOutput, TError, TSelectData, TInitialData>;
63
+ export type LiveOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & SettleOnFirstDataOptions;
64
+ export type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
65
+ queryKey: QueryKey;
66
+ };
67
+ export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
68
+ input: ((pageParam: TPageParam) => TInput) | SkipToken;
69
+ initialData?: TInitialData;
70
+ queryKey?: QueryKey | undefined;
71
+ } & (object extends TClientContext ? {
72
+ context?: TClientContext | undefined;
73
+ } : {
74
+ context: TClientContext;
75
+ }) & Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | '_defaulted' | '_optimisticResults'>;
76
+ 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 : {
77
+ initialData: TInitialData;
78
+ }) & {
79
+ queryFn: QueryFunction<TOutput, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>;
80
+ };
81
+ export type MutationKeyOptions = Pick<MutationOptionsIn<any, any, any, any, any>, 'mutationKey'>;
82
+ export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (object extends TClientContext ? {
83
+ context?: TClientContext | undefined;
84
+ } : {
85
+ context: TClientContext;
86
+ }) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
87
+ export type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The symbol under which TanStack Query utils attach operation details
3
+ * (key and operation type) to the client context.
4
+ *
5
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
6
+ */
7
+ export const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for('ORPC_TANSTACK_QUERY_OPERATION_CONTEXT');
package/package.json CHANGED
@@ -1,67 +1,65 @@
1
1
  {
2
2
  "name": "@orpc/tanstack-query",
3
- "type": "module",
4
- "version": "2.0.0-beta.48",
3
+ "version": "2.0.0-beta.49",
5
4
  "description": "TanStack Query integration for oRPC: typesafe queries, mutations, streaming, and SSR for React, Vue, Solid, Svelte, and Angular",
6
- "license": "MIT",
7
- "funding": [
8
- "https://github.com/sponsors/dinwwwh",
9
- "https://opencollective.com/middleapi"
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"
10
18
  ],
11
19
  "homepage": "https://orpc.dev",
20
+ "license": "MIT",
12
21
  "repository": {
13
22
  "type": "git",
14
23
  "url": "git+https://github.com/middleapi/orpc.git",
15
24
  "directory": "packages/tanstack-query"
16
25
  },
17
- "keywords": [
18
- "orpc",
19
- "tanstack-query",
20
- "react-query",
21
- "vue-query",
22
- "solid-query",
23
- "svelte-query",
24
- "angular-query",
25
- "query",
26
- "mutation",
27
- "ssr",
28
- "typescript",
29
- "typesafe"
26
+ "funding": [
27
+ "https://github.com/sponsors/dinwwwh",
28
+ "https://opencollective.com/middleapi"
30
29
  ],
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "type": "module",
31
34
  "sideEffects": false,
32
35
  "exports": {
33
36
  "./package.json": "./package.json",
34
37
  ".": {
35
- "types": "./dist/index.d.mts",
36
- "import": "./dist/index.mjs",
37
- "default": "./dist/index.mjs"
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
38
41
  }
39
42
  },
40
- "files": [
41
- "dist"
42
- ],
43
- "peerDependencies": {
44
- "@tanstack/query-core": ">=5.89.0"
45
- },
46
43
  "dependencies": {
47
- "@orpc/client": "2.0.0-beta.48",
48
- "@orpc/contract": "2.0.0-beta.48",
49
- "@orpc/openapi": "2.0.0-beta.48",
50
- "@orpc/shared": "2.0.0-beta.48"
44
+ "@orpc/client": "2.0.0-beta.49",
45
+ "@orpc/contract": "2.0.0-beta.49",
46
+ "@orpc/openapi": "2.0.0-beta.49",
47
+ "@orpc/shared": "2.0.0-beta.49"
51
48
  },
52
49
  "devDependencies": {
53
50
  "@angular/core": "^22.2.4",
54
- "@tanstack/angular-query-experimental": "^5.105.0",
55
- "@tanstack/query-core": "^5.105.0",
56
- "@tanstack/react-query": "^5.105.0",
57
- "@tanstack/solid-query": "^5.105.0",
58
- "@tanstack/svelte-query": "^6.3.6",
59
- "@tanstack/vue-query": "^5.105.0",
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",
60
57
  "svelte": "^5.57.3",
61
58
  "vue": "^3.5.44",
62
59
  "zod": "^4.6.7"
63
60
  },
64
- "scripts": {
65
- "type:check": "tsc -b"
66
- }
61
+ "peerDependencies": {
62
+ "@tanstack/query-core": ">=5.105.0"
63
+ },
64
+ "scripts": {}
67
65
  }
@@ -1,35 +0,0 @@
1
- import type { ClientContext } from "@orpc/client";
2
- import type { ContractClientFactory, RouterContract, RouterContractClient } from "@orpc/contract";
3
- import type { ContractJsonifiedClientFactory, JsonifiedClient } from "@orpc/openapi";
4
- import type { RouterUtils, RouterUtilsOptions } from "./router-utils.mjs";
5
- export interface ContractUtilsFactory<TClientContext extends ClientContext> {
6
- <T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
7
- }
8
- export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, "path"> {}
9
- /**
10
- * Creates a factory that builds TanStack Query utils directly from a contract,
11
- * using the given contract client factory. Useful for scaling large projects
12
- * where each part only needs a slice of the router.
13
- *
14
- * @remarks
15
- * **Note**: The contract must define a `path` meta matching its position in the root router contract.
16
- *
17
- * @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
18
- */
19
- export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
20
- export interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
21
- <T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
22
- }
23
- export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, "path"> {}
24
- /**
25
- * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
26
- * such as clients using OpenAPI Link.
27
- *
28
- * @remarks
29
- * Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
30
- *
31
- * **Note**: The contract must define a `path` meta matching its position in the root router contract.
32
- *
33
- * @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
34
- */
35
- export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
@@ -1,23 +0,0 @@
1
- import { resolveBasePathMeta } from "@orpc/contract";
2
- import { get } from "@orpc/shared";
3
- import { createRouterUtils } from "./router-utils.mjs";
4
-
5
- export function createContractUtilsFactory(clientFactory, options) {
6
- const factory = (contract) => {
7
- const client = clientFactory(contract);
8
- const path = resolveBasePathMeta(contract);
9
- if (path === undefined) {
10
- throw new TypeError("ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
11
- }
12
- return createRouterUtils(client, {
13
- ...options,
14
- path,
15
- scoped: get(options.scoped, path)
16
- });
17
- };
18
- return factory;
19
- }
20
-
21
- export function createContractJsonifiedUtilsFactory(clientFactory, options) {
22
- return createContractUtilsFactory(clientFactory, options);
23
- }
package/dist/index.d.mts DELETED
@@ -1,16 +0,0 @@
1
- export * from "./contract-utils.mjs";
2
- export type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.mjs";
3
- export * from "./meta.mjs";
4
- export type { RouterUtilsPlugin } from "./plugin.mjs";
5
- export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
6
- export type { ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions } from "./procedure-utils.mjs";
7
- export * from "./router-utils.mjs";
8
- export { createRouterUtils as createTanstackQueryUtils } from "./router-utils.mjs";
9
- export { SharedUtils } from "./shared-utils.mjs";
10
- export * from "./ssr.mjs";
11
- export type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
12
- export * from "./structural-sharing.mjs";
13
- export * from "./types.mjs";
14
- export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, type OperationContext as TanstackQueryOperationContext } from "./types.mjs";
15
- export type { AnyNestedClient } from "@orpc/client";
16
- export type { Public } from "@orpc/shared";
package/dist/index.mjs DELETED
@@ -1,10 +0,0 @@
1
- export * from "./contract-utils.mjs";
2
- export * from "./meta.mjs";
3
- export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
4
- export * from "./router-utils.mjs";
5
- export { createRouterUtils as createTanstackQueryUtils } from "./router-utils.mjs";
6
- export { SharedUtils } from "./shared-utils.mjs";
7
- export * from "./ssr.mjs";
8
- export * from "./structural-sharing.mjs";
9
- export * from "./types.mjs";
10
- export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from "./types.mjs";
package/dist/key.d.mts DELETED
@@ -1,62 +0,0 @@
1
- import type { PartialDeep, Public } from "@orpc/shared";
2
- import type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
3
- import type { OperationType } from "./types.mjs";
4
- import { RPCJsonSerializer } from "@orpc/client";
5
- export interface OperationKeyPrefixOptions {
6
- /**
7
- * Prepended as the first element of the key when present.
8
- * Use this to avoid key conflicts when multiple router utils share the same client.
9
- */
10
- prefix?: string | undefined;
11
- }
12
- export interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
13
- /**
14
- * Serializes inputs into JSON-compatible values when building keys,
15
- * and compares custom types in structural sharing.
16
- * Pass the serializer your link uses so custom types are supported.
17
- *
18
- * @default new RPCJsonSerializer()
19
- */
20
- serializer?: Public<RPCJsonSerializer> | undefined;
21
- }
22
- export type OperationKeyOptions<
23
- TType extends OperationType,
24
- TInput
25
- > = OperationKeyBaseOptions & {
26
- type?: TType | undefined;
27
- input?: (TType extends "mutation" ? never : PartialDeep<TInput>) | undefined;
28
- fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
29
- };
30
- type OperationKeyContent<
31
- TType extends OperationType,
32
- TInput
33
- > = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
34
- /**
35
- * Set in place of `input` when the operation is disabled with `skipToken`,
36
- * because query key hashers drop symbols.
37
- */
38
- skipToken?: TType extends "mutation" ? never : true;
39
- /**
40
- * Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
41
- * so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
42
- * Keyed by path (not a list) so partial keys still match.
43
- */
44
- inputMeta?: Record<string, string[]> | undefined;
45
- };
46
- export type OperationKey<
47
- TType extends OperationType,
48
- TInput
49
- > = [path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>];
50
- /**
51
- * Generate a TanStack Query key for a procedure.
52
- *
53
- * The input is serialized to JSON-compatible values, so keys hash and partially match
54
- * by value, including types like `Date`, `Set`, `Map` and custom serializer types.
55
- *
56
- * @see {@link https://orpc.dev/docs/integrations/tanstack-query#key-serializer | TanStack Query Integration - Key Serializer}
57
- */
58
- export declare function generateOperationKey<
59
- TType extends OperationType,
60
- TInput
61
- >(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
62
- export {};
package/dist/key.mjs DELETED
@@ -1,30 +0,0 @@
1
- import { RPCJsonSerializer } from "@orpc/client";
2
- import { stringifyJSON } from "@orpc/shared";
3
- import { skipToken } from "@tanstack/query-core";
4
- const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
5
-
6
- export function generateOperationKey(path, options = {}) {
7
- return [
8
- ...options.prefix !== undefined ? [options.prefix] : [],
9
- path,
10
- {
11
- ...options.input === skipToken ? { skipToken: true } : options.input !== undefined ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
12
- ...options.type !== undefined ? { type: options.type } : {},
13
- ...options.fnOptions !== undefined ? { fnOptions: options.fnOptions } : {}
14
- }
15
- ];
16
- }
17
- function serializeInput(serializer, input) {
18
- const { json, meta } = serializer.serializeJson(input);
19
- if (!meta?.length) {
20
- return { input: json };
21
- }
22
- const inputMeta = {};
23
- for (const [type, ...segments] of meta) {
24
- (inputMeta[stringifyJSON(segments)] ??= []).push(type);
25
- }
26
- return {
27
- input: json,
28
- inputMeta
29
- };
30
- }
@@ -1,6 +0,0 @@
1
- import type { Promisable } from "@orpc/shared";
2
- import type { QueryFunction, QueryFunctionContext, QueryKey } from "@tanstack/query-core";
3
- export declare function liveQuery<
4
- TQueryFnData = unknown,
5
- TQueryKey extends QueryKey = QueryKey
6
- >(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>): QueryFunction<TQueryFnData, TQueryKey>;