@orpc/tanstack-query 2.0.0-beta.49 → 2.0.0-beta.50
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.
- package/dist/contract-utils.d.ts +9 -11
- package/dist/contract-utils.js +38 -38
- package/dist/index.d.ts +14 -16
- package/dist/index.js +8 -10
- package/dist/key.d.ts +32 -41
- package/dist/key.js +38 -42
- package/dist/live-query.js +29 -35
- package/dist/meta.d.ts +15 -15
- package/dist/meta.js +49 -51
- package/dist/plugin.d.ts +38 -45
- package/dist/plugin.js +19 -25
- package/dist/procedure-utils.d.ts +138 -141
- package/dist/procedure-utils.js +362 -402
- package/dist/router-utils.d.ts +45 -50
- package/dist/router-utils.js +50 -65
- package/dist/shared-utils.d.ts +10 -10
- package/dist/shared-utils.js +21 -19
- package/dist/ssr.d.ts +20 -21
- package/dist/ssr.js +44 -42
- package/dist/stream-query.d.ts +29 -35
- package/dist/stream-query.js +36 -50
- package/dist/structural-sharing.d.ts +3 -3
- package/dist/structural-sharing.js +83 -138
- package/dist/types.d.ts +41 -41
- package/dist/types.js +8 -6
- package/package.json +5 -5
- package/dist/live-query.d.ts +0 -4
package/dist/contract-utils.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { RouterUtils, RouterUtilsOptions } from "./router-utils.js";
|
|
2
|
+
import { ContractClientFactory, RouterContract, RouterContractClient } from "@orpc/contract";
|
|
3
|
+
import { ClientContext } from "@orpc/client";
|
|
4
|
+
import { ContractJsonifiedClientFactory, JsonifiedClient } from "@orpc/openapi";
|
|
5
5
|
export interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
6
|
+
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
9
7
|
}
|
|
8
|
+
export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, "path"> {}
|
|
10
9
|
/**
|
|
11
10
|
* Creates a factory that builds TanStack Query utils directly from a contract,
|
|
12
11
|
* using the given contract client factory. Useful for scaling large projects
|
|
@@ -19,10 +18,9 @@ export interface ContractUtilsFactoryOptions<TClientContext extends ClientContex
|
|
|
19
18
|
*/
|
|
20
19
|
export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
21
20
|
export interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
21
|
+
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
25
22
|
}
|
|
23
|
+
export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, "path"> {}
|
|
26
24
|
/**
|
|
27
25
|
* Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
|
|
28
26
|
* such as clients using OpenAPI Link.
|
|
@@ -34,4 +32,4 @@ export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends Cli
|
|
|
34
32
|
*
|
|
35
33
|
* @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
|
|
36
34
|
*/
|
|
37
|
-
export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
35
|
+
export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
package/dist/contract-utils.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createRouterUtils } from "./router-utils.js";
|
|
2
|
+
import { resolveBasePathMeta } from "@orpc/contract";
|
|
3
|
+
import { get } from "@orpc/shared";
|
|
4
|
+
// src/contract-utils.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
return factory;
|
|
6
|
+
* Creates a factory that builds TanStack Query utils directly from a contract,
|
|
7
|
+
* using the given contract client factory. Useful for scaling large projects
|
|
8
|
+
* where each part only needs a slice of the router.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
|
|
14
|
+
*/
|
|
15
|
+
function createContractUtilsFactory(clientFactory, options) {
|
|
16
|
+
const factory = (contract) => {
|
|
17
|
+
const client = clientFactory(contract);
|
|
18
|
+
const path = resolveBasePathMeta(contract);
|
|
19
|
+
if (path === void 0) throw new TypeError("ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
|
|
20
|
+
return createRouterUtils(client, {
|
|
21
|
+
...options,
|
|
22
|
+
path,
|
|
23
|
+
scoped: get(options.scoped, path)
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return factory;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
* Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
|
|
30
|
+
* such as clients using OpenAPI Link.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
|
|
34
|
+
*
|
|
35
|
+
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
|
|
38
|
+
*/
|
|
39
|
+
function createContractJsonifiedUtilsFactory(clientFactory, options) {
|
|
40
|
+
return createContractUtilsFactory(clientFactory, options);
|
|
42
41
|
}
|
|
42
|
+
export { createContractJsonifiedUtilsFactory, createContractUtilsFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, type OperationContext as TanstackQueryOperationContext,
|
|
15
|
-
export type { AnyNestedClient } from '@orpc/client';
|
|
16
|
-
export type { Public } from '@orpc/shared';
|
|
1
|
+
import { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
|
|
2
|
+
import { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.js";
|
|
3
|
+
import { ContractOptionsUtilsPlugin, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, getTanstackQueryMeta, tanstackQuery } from "./meta.js";
|
|
4
|
+
import { RouterUtilsPlugin } from "./plugin.js";
|
|
5
|
+
import { ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
6
|
+
import { RouterUtils, RouterUtilsOptions, RouterUtilsScoped, createRouterUtils } from "./router-utils.js";
|
|
7
|
+
import { SharedUtils } from "./shared-utils.js";
|
|
8
|
+
import { StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions, createHydrationOptions } from "./ssr.js";
|
|
9
|
+
import { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from "./stream-query.js";
|
|
10
|
+
import { StructuralSharing, createStructuralSharing } from "./structural-sharing.js";
|
|
11
|
+
import { InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, OperationType, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut } from "./types.js";
|
|
12
|
+
import { Public } from "@orpc/shared";
|
|
13
|
+
import { AnyNestedClient } from "@orpc/client";
|
|
14
|
+
export { type AnyNestedClient, ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractOptionsUtilsPlugin, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, type OperationKey, type OperationKeyBaseOptions, type OperationKeyOptions, type OperationKeyPrefixOptions, OperationType, ProcedureUtils, type ProcedureUtilsInfiniteInterceptor, type ProcedureUtilsInfiniteInterceptorOptions, type ProcedureUtilsLiveInterceptor, type ProcedureUtilsLiveInterceptorOptions, type ProcedureUtilsModifier, type ProcedureUtilsMutationInterceptor, type ProcedureUtilsMutationInterceptorOptions, type ProcedureUtilsOptions, type ProcedureUtilsQueryInterceptor, type ProcedureUtilsQueryInterceptorOptions, type ProcedureUtilsStreamedInterceptor, type ProcedureUtilsStreamedInterceptorOptions, type Public, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, type RouterUtilsPlugin, RouterUtilsScoped, type SerializableStreamedQueryOptions, type SettleOnFirstDataOptions, SharedUtils, StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, StructuralSharing, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, type OperationContext as TanstackQueryOperationContext, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createHydrationOptions, createRouterUtils, createStructuralSharing, createRouterUtils as createTanstackQueryUtils, getTanstackQueryMeta, mergeProcedureUtilsOptions, tanstackQuery };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from './types.js';
|
|
10
|
-
export { OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, } from './types.js';
|
|
1
|
+
export { createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
|
|
2
|
+
export { ContractOptionsUtilsPlugin, getTanstackQueryMeta, tanstackQuery } from "./meta.js";
|
|
3
|
+
export { ProcedureUtils, mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
4
|
+
export { createRouterUtils, createRouterUtils as createTanstackQueryUtils } from "./router-utils.js";
|
|
5
|
+
export { SharedUtils } from "./shared-utils.js";
|
|
6
|
+
export { StreamQuerySSRUtilsPlugin, createHydrationOptions } from "./ssr.js";
|
|
7
|
+
export { createStructuralSharing } from "./structural-sharing.js";
|
|
8
|
+
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from "./types.js";
|
package/dist/key.d.ts
CHANGED
|
@@ -1,50 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { SerializableStreamedQueryOptions } from "./stream-query.js";
|
|
2
|
+
import { OperationType } from "./types.js";
|
|
3
|
+
import { PartialDeep, Public } from "@orpc/shared";
|
|
4
|
+
import { RPCJsonSerializer } from "@orpc/client";
|
|
5
5
|
export interface OperationKeyPrefixOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
}
|
|
12
12
|
export interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
}
|
|
22
22
|
export type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyBaseOptions & {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
type?: TType | undefined;
|
|
24
|
+
input?: (TType extends "mutation" ? never : PartialDeep<TInput>) | undefined;
|
|
25
|
+
fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
|
|
26
26
|
};
|
|
27
27
|
type OperationKeyContent<TType extends OperationType, TInput> = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Set in place of `input` when the operation is disabled with `skipToken`,
|
|
30
|
+
* because query key hashers drop symbols.
|
|
31
|
+
*/
|
|
32
|
+
skipToken?: TType extends "mutation" ? never : true;
|
|
33
|
+
/**
|
|
34
|
+
* Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
|
|
35
|
+
* so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
|
|
36
|
+
* Keyed by path (not a list) so partial keys still match.
|
|
37
|
+
*/
|
|
38
|
+
inputMeta?: Record<string, string[]> | undefined;
|
|
39
39
|
};
|
|
40
40
|
export type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>];
|
|
41
|
-
|
|
42
|
-
* Generate a TanStack Query key for a procedure.
|
|
43
|
-
*
|
|
44
|
-
* The input is serialized to JSON-compatible values, so keys hash and partially match
|
|
45
|
-
* by value, including types like `Date`, `Set`, `Map` and custom serializer types.
|
|
46
|
-
*
|
|
47
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#key-serializer | TanStack Query Integration - Key Serializer}
|
|
48
|
-
*/
|
|
49
|
-
export declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
50
|
-
export {};
|
|
41
|
+
export {};
|
package/dist/key.js
CHANGED
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { skipToken } from
|
|
1
|
+
import { stringifyJSON } from "@orpc/shared";
|
|
2
|
+
import { RPCJsonSerializer } from "@orpc/client";
|
|
3
|
+
import { skipToken } from "@tanstack/query-core";
|
|
4
|
+
// src/key.ts
|
|
4
5
|
const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
...(options.type !== undefined ? { type: options.type } : {}),
|
|
24
|
-
...streamedKeyOptions(options.fnOptions),
|
|
25
|
-
},
|
|
26
|
-
];
|
|
7
|
+
* Generate a TanStack Query key for a procedure.
|
|
8
|
+
*
|
|
9
|
+
* The input is serialized to JSON-compatible values, so keys hash and partially match
|
|
10
|
+
* by value, including types like `Date`, `Set`, `Map` and custom serializer types.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#key-serializer | TanStack Query Integration - Key Serializer}
|
|
13
|
+
*/
|
|
14
|
+
function generateOperationKey(path, options = {}) {
|
|
15
|
+
return [
|
|
16
|
+
...options.prefix !== void 0 ? [options.prefix] : [],
|
|
17
|
+
path,
|
|
18
|
+
{
|
|
19
|
+
...options.input === skipToken ? { skipToken: true } : options.input !== void 0 ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
|
|
20
|
+
...options.type !== void 0 ? { type: options.type } : {},
|
|
21
|
+
...streamedKeyOptions(options.fnOptions)
|
|
22
|
+
}
|
|
23
|
+
];
|
|
27
24
|
}
|
|
28
25
|
function serializeInput(serializer, input) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return { input: json, inputMeta };
|
|
26
|
+
const { json, meta } = serializer.serializeJson(input);
|
|
27
|
+
if (!meta?.length) return { input: json };
|
|
28
|
+
const inputMeta = {};
|
|
29
|
+
for (const [type, ...segments] of meta) (inputMeta[stringifyJSON(segments)] ??= []).push(type);
|
|
30
|
+
return {
|
|
31
|
+
input: json,
|
|
32
|
+
inputMeta
|
|
33
|
+
};
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
* Leaves out default streamed options, so passing a default gives the same key as omitting it.
|
|
37
|
+
*/
|
|
43
38
|
function streamedKeyOptions(options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
const { refetchMode, maxChunks } = options ?? {};
|
|
40
|
+
const fnOptions = {
|
|
41
|
+
...refetchMode !== void 0 && refetchMode !== "reset" ? { refetchMode } : {},
|
|
42
|
+
...maxChunks !== void 0 && maxChunks !== Number.POSITIVE_INFINITY ? { maxChunks } : {}
|
|
43
|
+
};
|
|
44
|
+
return Object.keys(fnOptions).length > 0 ? { fnOptions } : {};
|
|
50
45
|
}
|
|
46
|
+
export { generateOperationKey };
|
package/dist/live-query.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
import { stringifyJSON, throwIfAborted } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return last.chunk;
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
signal.removeEventListener('abort', markStale);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
1
|
+
import { listenAbort, stringifyJSON, throwIfAborted } from "@orpc/shared";
|
|
2
|
+
// src/live-query.ts
|
|
3
|
+
function liveQuery(queryFn, { settleOnFirstData = false } = {}) {
|
|
4
|
+
return async (context) => {
|
|
5
|
+
const { client, queryKey, signal } = context;
|
|
6
|
+
const unlisten = listenAbort(signal, () => client.getQueryCache().find({
|
|
7
|
+
queryKey,
|
|
8
|
+
exact: true
|
|
9
|
+
})?.invalidate());
|
|
10
|
+
try {
|
|
11
|
+
const stream = await queryFn(context);
|
|
12
|
+
if (signal.aborted) {
|
|
13
|
+
await stream[Symbol.asyncIterator]().return?.();
|
|
14
|
+
throw signal.reason;
|
|
15
|
+
}
|
|
16
|
+
let last;
|
|
17
|
+
for await (const chunk of stream) {
|
|
18
|
+
throwIfAborted(signal);
|
|
19
|
+
last = { chunk };
|
|
20
|
+
client.setQueryData(queryKey, chunk);
|
|
21
|
+
if (settleOnFirstData) break;
|
|
22
|
+
}
|
|
23
|
+
if (!last) throw new TypeError(`Live query for ${stringifyJSON(queryKey)} did not yield any data. Ensure the query function returns an AsyncIterable with at least one chunk.`);
|
|
24
|
+
return last.chunk;
|
|
25
|
+
} finally {
|
|
26
|
+
unlisten();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
36
29
|
}
|
|
30
|
+
export { liveQuery };
|
package/dist/meta.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { OperationKeyBaseOptions } from "./key.js";
|
|
2
|
+
import { RouterUtilsPlugin } from "./plugin.js";
|
|
3
|
+
import { ProcedureUtilsOptions } from "./procedure-utils.js";
|
|
4
|
+
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, Meta, MetaPlugin, ORPCErrorFromErrorMap, RouterContract } from "@orpc/contract";
|
|
5
|
+
import { ThrowableError } from "@orpc/shared";
|
|
6
|
+
import { AnyNestedClient, ClientContext, InferClientContext, InferClientError } from "@orpc/client";
|
|
7
7
|
export type TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
|
|
8
8
|
export interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
9
|
-
|
|
9
|
+
name: "~tanstack-query";
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
@@ -20,9 +20,9 @@ export interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutput
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
22
22
|
export declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"~orpc": {
|
|
24
|
+
meta: Meta;
|
|
25
|
+
};
|
|
26
26
|
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
27
27
|
/**
|
|
28
28
|
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
@@ -35,8 +35,8 @@ export declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
|
35
35
|
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
36
36
|
*/
|
|
37
37
|
export declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
38
|
+
private readonly contract;
|
|
39
|
+
readonly name = "~contract-options";
|
|
40
|
+
constructor(contract: RouterContract);
|
|
41
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
42
|
+
}
|
package/dist/meta.js
CHANGED
|
@@ -1,55 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
2
|
+
import { ProcedureContract, getRouterContract } from "@orpc/contract";
|
|
3
|
+
// src/meta.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
6
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
7
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
8
|
+
* resets the value from earlier applications instead of merging.
|
|
9
|
+
*
|
|
10
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
13
|
+
*/
|
|
14
|
+
function tanstackQuery(options) {
|
|
15
|
+
return {
|
|
16
|
+
name: "~tanstack-query",
|
|
17
|
+
init(meta) {
|
|
18
|
+
const current = meta["~tanstack-query"];
|
|
19
|
+
return {
|
|
20
|
+
...meta,
|
|
21
|
+
"~tanstack-query": current ? mergeProcedureUtilsOptions(current, options) : options
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
function getTanstackQueryMeta(procedureOrLazy) {
|
|
27
|
+
return procedureOrLazy["~orpc"].meta["~tanstack-query"];
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return mergeProcedureUtilsOptions(base, options);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
30
|
+
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
31
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
32
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
33
|
+
*
|
|
34
|
+
* The contract shape must match the client the utils are created from,
|
|
35
|
+
* so pass the root router contract when utils paths start from the root.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
38
|
+
*/
|
|
39
|
+
var ContractOptionsUtilsPlugin = class {
|
|
40
|
+
contract;
|
|
41
|
+
name = "~contract-options";
|
|
42
|
+
constructor(contract) {
|
|
43
|
+
this.contract = contract;
|
|
44
|
+
}
|
|
45
|
+
initProcedureOptions(path, options) {
|
|
46
|
+
const procedure = getRouterContract(this.contract, path);
|
|
47
|
+
if (!(procedure instanceof ProcedureContract)) return options;
|
|
48
|
+
const base = getTanstackQueryMeta(procedure);
|
|
49
|
+
if (!base) return options;
|
|
50
|
+
return mergeProcedureUtilsOptions(base, options);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export { ContractOptionsUtilsPlugin, getTanstackQueryMeta, tanstackQuery };
|