@orpc/pinia-colada 0.0.0
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/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/index.d.mts +422 -0
- package/dist/index.d.ts +422 -0
- package/dist/index.mjs +516 -0
- package/package.json +51 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
3
|
+
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
|
+
import { EntryKey, UseQueryOptions, UseMutationOptions, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada';
|
|
6
|
+
|
|
7
|
+
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
8
|
+
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
9
|
+
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
10
|
+
type UseMutationFnContext = Parameters<UseMutationOptions<any, any>['mutation']>[1];
|
|
11
|
+
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
12
|
+
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
13
|
+
interface OperationContext {
|
|
14
|
+
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
15
|
+
key: EntryKey;
|
|
16
|
+
type: OperationType;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
20
|
+
input?: TInput;
|
|
21
|
+
} : {
|
|
22
|
+
input: TInput;
|
|
23
|
+
}) | {
|
|
24
|
+
key: EntryKey;
|
|
25
|
+
};
|
|
26
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
|
27
|
+
input?: TInput;
|
|
28
|
+
} : {
|
|
29
|
+
input: TInput;
|
|
30
|
+
}) & (object extends TClientContext ? {
|
|
31
|
+
context?: TClientContext;
|
|
32
|
+
} : {
|
|
33
|
+
context: TClientContext;
|
|
34
|
+
}) & Omit<DefineQueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'> & Partial<Pick<DefineQueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>>;
|
|
35
|
+
type QueryOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = DefineQueryOptionsTagged<TOutput, TError, TInitialData>;
|
|
36
|
+
type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
|
|
37
|
+
input?: TInput;
|
|
38
|
+
} : {
|
|
39
|
+
input: TInput;
|
|
40
|
+
}) & {
|
|
41
|
+
fnOptions?: SerializableStreamedQueryOptions;
|
|
42
|
+
}) | {
|
|
43
|
+
key: EntryKey;
|
|
44
|
+
};
|
|
45
|
+
type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & {
|
|
46
|
+
fnOptions?: SerializableStreamedQueryOptions;
|
|
47
|
+
};
|
|
48
|
+
type StreamedOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsOut<TOutput, TError, TInitialData>;
|
|
49
|
+
type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
|
|
50
|
+
key: EntryKey;
|
|
51
|
+
};
|
|
52
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = {
|
|
53
|
+
input: (pageParam: TPageParam) => TInput;
|
|
54
|
+
} & (object extends TClientContext ? {
|
|
55
|
+
context?: TClientContext;
|
|
56
|
+
} : {
|
|
57
|
+
context: TClientContext;
|
|
58
|
+
}) & Omit<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, 'key' | 'query'> & Partial<Pick<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, 'key' | 'query'>>;
|
|
59
|
+
type InfiniteOptionsOut<TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = DefineInfiniteQueryOptionsTagged<TOutput, TError, TPageParam, TInitialData>;
|
|
60
|
+
type MutationKeyOptions<TInput> = Pick<MutationOptionsIn<any, TInput, any, any, any>, 'key'>;
|
|
61
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (object extends TClientContext ? {
|
|
62
|
+
context?: TClientContext;
|
|
63
|
+
} : {
|
|
64
|
+
context: TClientContext;
|
|
65
|
+
}) & Omit<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'> & Partial<Pick<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>>;
|
|
66
|
+
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = DefineMutationOptionsTagged<TOutput, TInput, TError, TMutationContext>;
|
|
67
|
+
|
|
68
|
+
interface SerializableStreamedQueryOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Determines how data is handled when the query is fetched again
|
|
71
|
+
*
|
|
72
|
+
* - `'reset'`: Clears existing data and returns the query to a pending state.
|
|
73
|
+
* - `'append'`: Adds new streamed chunks to the existing data.
|
|
74
|
+
* - `'replace'`: Buffers streamed data and replaces the cache after the stream completes.
|
|
75
|
+
*
|
|
76
|
+
* @default 'reset'
|
|
77
|
+
*/
|
|
78
|
+
refetchMode?: 'append' | 'reset' | 'replace';
|
|
79
|
+
/**
|
|
80
|
+
* Limits the number of data chunks stored in the query result.
|
|
81
|
+
* Older chunks are removed when the limit is reached.
|
|
82
|
+
*
|
|
83
|
+
* @default Number.POSITIVE_INFINITY (unlimited)
|
|
84
|
+
*/
|
|
85
|
+
maxChunks?: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A Pinia Colada query function that accumulates streamed chunks into an array,
|
|
89
|
+
* publishing each chunk to the cache entry as it arrives.
|
|
90
|
+
*
|
|
91
|
+
* Inspired by [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery) where:
|
|
92
|
+
* - Options are serializable
|
|
93
|
+
* - The output is predictable
|
|
94
|
+
*/
|
|
95
|
+
declare function serializableStreamedQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): (context: UseQueryFnContext) => Promise<T[]>;
|
|
96
|
+
|
|
97
|
+
interface OperationKeyPrefixOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Prepended as the first element of the key when present.
|
|
100
|
+
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
101
|
+
*/
|
|
102
|
+
prefix?: string;
|
|
103
|
+
}
|
|
104
|
+
type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyPrefixOptions & {
|
|
105
|
+
type?: TType;
|
|
106
|
+
input?: PartialDeep<TInput>;
|
|
107
|
+
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
108
|
+
};
|
|
109
|
+
type OperationKey<TType extends OperationType, TInput> = EntryKey & ([path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>]);
|
|
110
|
+
/**
|
|
111
|
+
* Generate a Pinia Colada entry key for a procedure.
|
|
112
|
+
*
|
|
113
|
+
* The input is serialized to JSON-compatible values because Pinia Colada
|
|
114
|
+
* requires entry keys to be serializable.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
117
|
+
*/
|
|
118
|
+
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
119
|
+
|
|
120
|
+
declare class SharedUtils<TInput> {
|
|
121
|
+
protected readonly path: string[];
|
|
122
|
+
protected readonly options: OperationKeyPrefixOptions;
|
|
123
|
+
constructor(path: string[], options: OperationKeyPrefixOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
128
|
+
*/
|
|
129
|
+
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>): OperationKey<TType, TInput>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
133
|
+
path: string[];
|
|
134
|
+
context: TClientContext & OperationContext;
|
|
135
|
+
input: TInput;
|
|
136
|
+
fnContext: UseQueryFnContext;
|
|
137
|
+
}
|
|
138
|
+
type ProcedureUtilsQueryInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
139
|
+
interface ProcedureUtilsStreamedInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
140
|
+
}
|
|
141
|
+
type ProcedureUtilsStreamedInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsStreamedInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferStreamedQueryOutput<TOutput>, TError>>;
|
|
142
|
+
interface ProcedureUtilsLiveInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
143
|
+
}
|
|
144
|
+
type ProcedureUtilsLiveInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsLiveInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferLiveQueryOutput<TOutput>, TError>>;
|
|
145
|
+
interface ProcedureUtilsInfiniteInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
146
|
+
path: string[];
|
|
147
|
+
context: TClientContext & OperationContext;
|
|
148
|
+
input: TInput;
|
|
149
|
+
fnContext: UseInfiniteQueryFnContext<any, any, any, any>;
|
|
150
|
+
}
|
|
151
|
+
type ProcedureUtilsInfiniteInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsInfiniteInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
152
|
+
interface ProcedureUtilsMutationInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
153
|
+
path: string[];
|
|
154
|
+
context: TClientContext & OperationContext;
|
|
155
|
+
input: TInput;
|
|
156
|
+
fnContext: UseMutationFnContext;
|
|
157
|
+
}
|
|
158
|
+
type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsMutationInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
159
|
+
/**
|
|
160
|
+
* Can be partial options for spread-merged options,
|
|
161
|
+
* or a function that receives per-call options and returns overridden this.options.
|
|
162
|
+
*/
|
|
163
|
+
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
164
|
+
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> extends OperationKeyPrefixOptions {
|
|
165
|
+
/**
|
|
166
|
+
* Key options modifier for .queryKey and .queryOptions
|
|
167
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
168
|
+
*/
|
|
169
|
+
queryKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
170
|
+
/**
|
|
171
|
+
* Interceptors that intercept query inside .queryOptions, guaranteed to be executed.
|
|
172
|
+
*/
|
|
173
|
+
queryInterceptors?: ProcedureUtilsQueryInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
174
|
+
/**
|
|
175
|
+
* Options modifier for .queryOptions
|
|
176
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
177
|
+
*/
|
|
178
|
+
queryOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, TOutput, TError, TOutput | undefined>>;
|
|
179
|
+
/**
|
|
180
|
+
* Key options modifier for .streamedKey and .streamedOptions
|
|
181
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
182
|
+
*/
|
|
183
|
+
streamedKey?: ProcedureUtilsModifier<StreamedKeyOptions<TInput>>;
|
|
184
|
+
/**
|
|
185
|
+
* Interceptors that intercept query inside .streamedOptions, guaranteed to be executed.
|
|
186
|
+
*/
|
|
187
|
+
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
188
|
+
/**
|
|
189
|
+
* Options modifier for .streamedOptions
|
|
190
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
191
|
+
*/
|
|
192
|
+
streamedOptions?: ProcedureUtilsModifier<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, InferStreamedQueryOutput<TOutput> | undefined>>;
|
|
193
|
+
/**
|
|
194
|
+
* Key options modifier for .liveKey and .liveOptions
|
|
195
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
196
|
+
*/
|
|
197
|
+
liveKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
198
|
+
/**
|
|
199
|
+
* Interceptors that intercept query inside .liveOptions, guaranteed to be executed.
|
|
200
|
+
*/
|
|
201
|
+
liveInterceptors?: ProcedureUtilsLiveInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
202
|
+
/**
|
|
203
|
+
* Options modifier for .liveOptions
|
|
204
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
205
|
+
*/
|
|
206
|
+
liveOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, InferLiveQueryOutput<TOutput> | undefined>>;
|
|
207
|
+
/**
|
|
208
|
+
* Key options modifier for .infiniteKey and .infiniteOptions
|
|
209
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
210
|
+
*/
|
|
211
|
+
infiniteKey?: ProcedureUtilsModifier<InfiniteKeyOptions<TInput, unknown>>;
|
|
212
|
+
/**
|
|
213
|
+
* Interceptors that intercept query inside .infiniteOptions, guaranteed to be executed.
|
|
214
|
+
*/
|
|
215
|
+
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
216
|
+
/**
|
|
217
|
+
* Options modifier for .infiniteOptions
|
|
218
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
219
|
+
*/
|
|
220
|
+
infiniteOptions?: ProcedureUtilsModifier<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, UseInfiniteQueryData<TOutput, unknown> | undefined>>;
|
|
221
|
+
/**
|
|
222
|
+
* Key options modifier for .mutationKey and .mutationOptions
|
|
223
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
224
|
+
*/
|
|
225
|
+
mutationKey?: ProcedureUtilsModifier<MutationKeyOptions<TInput>>;
|
|
226
|
+
/**
|
|
227
|
+
* Interceptors that intercept mutation inside .mutationOptions, guaranteed to be executed.
|
|
228
|
+
*/
|
|
229
|
+
mutationInterceptors?: ProcedureUtilsMutationInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
230
|
+
/**
|
|
231
|
+
* Options modifier for .mutationOptions
|
|
232
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
233
|
+
*/
|
|
234
|
+
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, Record<any, any>>>;
|
|
235
|
+
}
|
|
236
|
+
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
237
|
+
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
238
|
+
/**
|
|
239
|
+
* Calling corresponding procedure client
|
|
240
|
+
*
|
|
241
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#calling-procedure-clients Pinia Colada Calling Procedure Client Docs}
|
|
242
|
+
*/
|
|
243
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
244
|
+
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
245
|
+
/**
|
|
246
|
+
* Generate a **full matching** key for useQuery/...
|
|
247
|
+
*
|
|
248
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
249
|
+
*/
|
|
250
|
+
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): EntryKeyTagged<TOutput, TError>;
|
|
251
|
+
/**
|
|
252
|
+
* Generate options used for useQuery/...
|
|
253
|
+
*
|
|
254
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-options-utility Pinia Colada Query Options Utility Docs}
|
|
255
|
+
*/
|
|
256
|
+
queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, UInitialData>>;
|
|
257
|
+
/**
|
|
258
|
+
* Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/pinia-colada#streamed-query-options-utility).
|
|
259
|
+
*
|
|
260
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
261
|
+
*/
|
|
262
|
+
streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): EntryKeyTagged<InferStreamedQueryOutput<TOutput>, TError>;
|
|
263
|
+
/**
|
|
264
|
+
* Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
265
|
+
* The resulting data is an array of chunks, and each new chunk is appended as it arrives.
|
|
266
|
+
* Works with `useQuery` and any other API that accepts query options.
|
|
267
|
+
*/
|
|
268
|
+
streamedOptions<UInitialData extends InferStreamedQueryOutput<TOutput> | undefined = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, UInitialData>>;
|
|
269
|
+
/**
|
|
270
|
+
* Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/pinia-colada#live-query-options-utility).
|
|
271
|
+
*
|
|
272
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
273
|
+
*/
|
|
274
|
+
liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): EntryKeyTagged<InferLiveQueryOutput<TOutput>, TError>;
|
|
275
|
+
/**
|
|
276
|
+
* Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
277
|
+
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
278
|
+
* Works with `useQuery` and any other API that accepts query options.
|
|
279
|
+
*/
|
|
280
|
+
liveOptions<UInitialData extends InferLiveQueryOutput<TOutput> | undefined = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, UInitialData>>;
|
|
281
|
+
/**
|
|
282
|
+
* Generate a **full matching** key for useInfiniteQuery/...
|
|
283
|
+
*
|
|
284
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
285
|
+
*/
|
|
286
|
+
infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): EntryKeyTagged<UseInfiniteQueryData<TOutput, UPageParam>, TError>;
|
|
287
|
+
/**
|
|
288
|
+
* Generate options used for useInfiniteQuery/...
|
|
289
|
+
*
|
|
290
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#infinite-query-options-utility Pinia Colada Infinite Query Options Utility Docs}
|
|
291
|
+
*/
|
|
292
|
+
infiniteOptions<UPageParam, UInitialData extends UseInfiniteQueryData<TOutput, UPageParam> | undefined = undefined>(optionsIn: InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, UPageParam, UInitialData>): NoInfer<InfiniteOptionsOut<TOutput, TError, UPageParam, UInitialData>>;
|
|
293
|
+
/**
|
|
294
|
+
* Generate a **full matching** key for useMutation/...
|
|
295
|
+
*
|
|
296
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-mutation-key Pinia Colada Query/Mutation Key Docs}
|
|
297
|
+
*/
|
|
298
|
+
mutationKey(...rest: MaybeOptionalOptions<MutationKeyOptions<TInput>>): MutationOptionsOut<TInput, TOutput, TError, _EmptyObject>['key'];
|
|
299
|
+
/**
|
|
300
|
+
* Generate options used for useMutation/...
|
|
301
|
+
*
|
|
302
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#mutation-options Pinia Colada Mutation Options Docs}
|
|
303
|
+
*/
|
|
304
|
+
mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
308
|
+
/**
|
|
309
|
+
* Initializes the router utils plugin and returns updated router utils options.
|
|
310
|
+
* Called once per plugin instance during composition.
|
|
311
|
+
*
|
|
312
|
+
* This method allows plugins to wrap, extend, or transform router utils options,
|
|
313
|
+
* such as interceptors or configuration.
|
|
314
|
+
*
|
|
315
|
+
* @param options - The current router utils options from previous plugins or base configuration
|
|
316
|
+
* @returns Transformed router utils options with this plugin's modifications applied
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* init(options) {
|
|
321
|
+
* return {
|
|
322
|
+
* ...options,
|
|
323
|
+
* mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
|
|
324
|
+
* }
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
329
|
+
/**
|
|
330
|
+
* Initializes per-procedure router utils options and returns updated options.
|
|
331
|
+
* Called once per procedure utils instance during composition.
|
|
332
|
+
*
|
|
333
|
+
* This method allows plugins to customize merged procedure-specific defaults,
|
|
334
|
+
* such as query or mutation options, for the current path.
|
|
335
|
+
*
|
|
336
|
+
* @param path - The current procedure path
|
|
337
|
+
* @param options - The merged procedure utils options for the current procedure
|
|
338
|
+
* @returns Transformed procedure utils options with this plugin's modifications applied
|
|
339
|
+
*/
|
|
340
|
+
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
341
|
+
}
|
|
342
|
+
declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
343
|
+
protected readonly plugins: RouterUtilsPlugin<T>[];
|
|
344
|
+
readonly name = "~composite";
|
|
345
|
+
constructor(plugins?: RouterUtilsPlugin<T>[]);
|
|
346
|
+
init(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
347
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
351
|
+
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
352
|
+
} & Public<SharedUtils<unknown>>;
|
|
353
|
+
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
354
|
+
[K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never;
|
|
355
|
+
};
|
|
356
|
+
interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPrefixOptions {
|
|
357
|
+
/**
|
|
358
|
+
* Base path for all query keys.
|
|
359
|
+
*
|
|
360
|
+
* @internal
|
|
361
|
+
*/
|
|
362
|
+
path?: string[] | undefined;
|
|
363
|
+
/**
|
|
364
|
+
* Interceptors that intercept query inside .queryOptions
|
|
365
|
+
*/
|
|
366
|
+
queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
367
|
+
/**
|
|
368
|
+
* Interceptors that intercept query inside .streamedOptions
|
|
369
|
+
*/
|
|
370
|
+
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
371
|
+
/**
|
|
372
|
+
* Interceptors that intercept query inside .liveOptions
|
|
373
|
+
*/
|
|
374
|
+
liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
375
|
+
/**
|
|
376
|
+
* Interceptors that intercept query inside .infiniteOptions
|
|
377
|
+
*/
|
|
378
|
+
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
379
|
+
/**
|
|
380
|
+
* Interceptors that intercept mutation inside .mutationOptions
|
|
381
|
+
*/
|
|
382
|
+
mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
383
|
+
/**
|
|
384
|
+
* Per-procedure options following the shape of the router.
|
|
385
|
+
* Allows fine-grained configuration of individual procedure utils
|
|
386
|
+
* without affecting the rest of the router.
|
|
387
|
+
*/
|
|
388
|
+
scoped?: RouterUtilsScoped<T> | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Plugins to extend router utils behavior.
|
|
391
|
+
*/
|
|
392
|
+
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Create a router utils from a client.
|
|
396
|
+
*
|
|
397
|
+
* @info Both client-side and server-side clients are supported.
|
|
398
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada Pinia Colada Docs}
|
|
399
|
+
*/
|
|
400
|
+
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
401
|
+
|
|
402
|
+
interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
403
|
+
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
404
|
+
}
|
|
405
|
+
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
406
|
+
}
|
|
407
|
+
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
408
|
+
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
409
|
+
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
410
|
+
}
|
|
411
|
+
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
412
|
+
}
|
|
413
|
+
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* A Pinia Colada query function that publishes each streamed chunk to the
|
|
417
|
+
* cache entry as it arrives, replacing the previous value.
|
|
418
|
+
*/
|
|
419
|
+
declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>): (context: UseQueryFnContext) => Promise<T>;
|
|
420
|
+
|
|
421
|
+
export { CompositeRouterUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, liveQuery, serializableStreamedQuery };
|
|
422
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, OperationContext as PiniaColadaOperationContext, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext };
|