@orpc/pinia-colada 2.0.0-beta.48 → 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.
Files changed (47) hide show
  1. package/README.md +4 -4
  2. package/dist/contract-utils.d.ts +35 -0
  3. package/dist/contract-utils.js +42 -0
  4. package/dist/index.d.ts +13 -0
  5. package/dist/index.js +7 -0
  6. package/dist/key.d.ts +36 -0
  7. package/dist/key.js +45 -0
  8. package/dist/live-query.js +34 -0
  9. package/dist/meta.d.ts +42 -0
  10. package/dist/meta.js +53 -0
  11. package/dist/plugin.d.ts +39 -0
  12. package/dist/plugin.js +19 -0
  13. package/dist/procedure-utils.d.ts +187 -0
  14. package/dist/procedure-utils.js +383 -0
  15. package/dist/router-utils.d.ts +62 -0
  16. package/dist/router-utils.js +54 -0
  17. package/dist/shared-utils.d.ts +13 -0
  18. package/dist/shared-utils.js +23 -0
  19. package/dist/ssr.d.ts +22 -0
  20. package/dist/ssr.js +22 -0
  21. package/dist/stream-query.d.ts +33 -0
  22. package/dist/stream-query.js +47 -0
  23. package/dist/types.d.ts +80 -0
  24. package/dist/types.js +9 -0
  25. package/package.json +31 -33
  26. package/dist/contract-utils.d.mts +0 -35
  27. package/dist/contract-utils.mjs +0 -23
  28. package/dist/index.d.mts +0 -19
  29. package/dist/index.mjs +0 -11
  30. package/dist/key.d.mts +0 -57
  31. package/dist/key.mjs +0 -29
  32. package/dist/live-query.d.mts +0 -7
  33. package/dist/live-query.mjs +0 -24
  34. package/dist/meta.d.mts +0 -55
  35. package/dist/meta.mjs +0 -37
  36. package/dist/plugin.d.mts +0 -46
  37. package/dist/plugin.mjs +0 -25
  38. package/dist/procedure-utils.d.mts +0 -245
  39. package/dist/procedure-utils.mjs +0 -394
  40. package/dist/router-utils.d.mts +0 -57
  41. package/dist/router-utils.mjs +0 -51
  42. package/dist/shared-utils.d.mts +0 -13
  43. package/dist/shared-utils.mjs +0 -17
  44. package/dist/stream-query.d.mts +0 -30
  45. package/dist/stream-query.mjs +0 -45
  46. package/dist/types.d.mts +0 -125
  47. package/dist/types.mjs +0 -2
@@ -1,245 +0,0 @@
1
- import type { Client, ClientContext } from "@orpc/client";
2
- import type { Interceptor, MaybeOptionalOptions, PromiseWithError } from "@orpc/shared";
3
- import type { _EmptyObject, EntryKeyTagged, UseInfiniteQueryData, UseInfiniteQueryFnContext } from "@pinia/colada";
4
- import type { OperationKeyBaseOptions } from "./key.mjs";
5
- import type { InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext } from "./types.mjs";
6
- import { SharedUtils } from "./shared-utils.mjs";
7
- export interface ProcedureUtilsQueryInterceptorOptions<
8
- TClientContext extends ClientContext,
9
- TInput
10
- > {
11
- path: string[];
12
- context: TClientContext & OperationContext;
13
- input: TInput;
14
- fnContext: UseQueryFnContext;
15
- }
16
- export type ProcedureUtilsQueryInterceptor<
17
- TClientContext extends ClientContext,
18
- TInput,
19
- TOutput,
20
- TError
21
- > = Interceptor<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
22
- export interface ProcedureUtilsStreamedInterceptorOptions<
23
- TClientContext extends ClientContext,
24
- TInput
25
- > extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {}
26
- export type ProcedureUtilsStreamedInterceptor<
27
- TClientContext extends ClientContext,
28
- TInput,
29
- TOutput,
30
- TError
31
- > = Interceptor<ProcedureUtilsStreamedInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferStreamedQueryOutput<TOutput>, TError>>;
32
- export interface ProcedureUtilsLiveInterceptorOptions<
33
- TClientContext extends ClientContext,
34
- TInput
35
- > extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {}
36
- export type ProcedureUtilsLiveInterceptor<
37
- TClientContext extends ClientContext,
38
- TInput,
39
- TOutput,
40
- TError
41
- > = Interceptor<ProcedureUtilsLiveInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferLiveQueryOutput<TOutput>, TError>>;
42
- export interface ProcedureUtilsInfiniteInterceptorOptions<
43
- TClientContext extends ClientContext,
44
- TInput
45
- > {
46
- path: string[];
47
- context: TClientContext & OperationContext;
48
- input: TInput;
49
- fnContext: UseInfiniteQueryFnContext<any, any, any, any>;
50
- }
51
- export type ProcedureUtilsInfiniteInterceptor<
52
- TClientContext extends ClientContext,
53
- TInput,
54
- TOutput,
55
- TError
56
- > = Interceptor<ProcedureUtilsInfiniteInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
57
- export interface ProcedureUtilsMutationInterceptorOptions<
58
- TClientContext extends ClientContext,
59
- TInput
60
- > {
61
- path: string[];
62
- context: TClientContext & OperationContext;
63
- input: TInput;
64
- fnContext: UseMutationFnContext;
65
- }
66
- export type ProcedureUtilsMutationInterceptor<
67
- TClientContext extends ClientContext,
68
- TInput,
69
- TOutput,
70
- TError
71
- > = Interceptor<ProcedureUtilsMutationInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
72
- /**
73
- * Can be partial options for spread-merged options,
74
- * or a function that receives per-call options and returns overridden this.options.
75
- */
76
- export type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
77
- export interface ProcedureUtilsOptions<
78
- TClientContext extends ClientContext,
79
- TInput,
80
- TOutput,
81
- TError
82
- > extends OperationKeyBaseOptions {
83
- /**
84
- * Key options modifier for .queryKey and .queryOptions
85
- * Can be partial options or a function that receives per-call options and returns override this.options.
86
- */
87
- queryKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>> | undefined;
88
- /**
89
- * Interceptors that intercept query inside .queryOptions, guaranteed to be executed.
90
- */
91
- queryInterceptors?: ProcedureUtilsQueryInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
92
- /**
93
- * Options modifier for .queryOptions
94
- * Can be partial options or a function that receives per-call options and returns override this.options.
95
- */
96
- queryOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, TOutput, TError, TOutput | undefined>> | undefined;
97
- /**
98
- * Key options modifier for .streamedKey and .streamedOptions
99
- * Can be partial options or a function that receives per-call options and returns override this.options.
100
- */
101
- streamedKey?: ProcedureUtilsModifier<StreamedKeyOptions<TInput>> | undefined;
102
- /**
103
- * Interceptors that intercept query inside .streamedOptions, guaranteed to be executed.
104
- */
105
- streamedInterceptors?: ProcedureUtilsStreamedInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
106
- /**
107
- * Options modifier for .streamedOptions
108
- * Can be partial options or a function that receives per-call options and returns override this.options.
109
- */
110
- streamedOptions?: ProcedureUtilsModifier<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, InferStreamedQueryOutput<TOutput> | undefined>> | undefined;
111
- /**
112
- * Key options modifier for .liveKey and .liveOptions
113
- * Can be partial options or a function that receives per-call options and returns override this.options.
114
- */
115
- liveKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>> | undefined;
116
- /**
117
- * Interceptors that intercept query inside .liveOptions, guaranteed to be executed.
118
- */
119
- liveInterceptors?: ProcedureUtilsLiveInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
120
- /**
121
- * Options modifier for .liveOptions
122
- * Can be partial options or a function that receives per-call options and returns override this.options.
123
- */
124
- liveOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, InferLiveQueryOutput<TOutput> | undefined>> | undefined;
125
- /**
126
- * Key options modifier for .infiniteKey and .infiniteOptions
127
- * Can be partial options or a function that receives per-call options and returns override this.options.
128
- */
129
- infiniteKey?: ProcedureUtilsModifier<InfiniteKeyOptions<TInput, unknown>> | undefined;
130
- /**
131
- * Interceptors that intercept query inside .infiniteOptions, guaranteed to be executed.
132
- */
133
- infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
134
- /**
135
- * Options modifier for .infiniteOptions
136
- * Can be partial options or a function that receives per-call options and returns override this.options.
137
- */
138
- infiniteOptions?: ProcedureUtilsModifier<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, UseInfiniteQueryData<TOutput, unknown> | undefined>> | undefined;
139
- /**
140
- * Key options modifier for .mutationKey and .mutationOptions
141
- * Can be partial options or a function that receives per-call options and returns override this.options.
142
- */
143
- mutationKey?: ProcedureUtilsModifier<MutationKeyOptions<TInput>> | undefined;
144
- /**
145
- * Interceptors that intercept mutation inside .mutationOptions, guaranteed to be executed.
146
- */
147
- mutationInterceptors?: ProcedureUtilsMutationInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
148
- /**
149
- * Options modifier for .mutationOptions
150
- * Can be partial options or a function that receives per-call options and returns override this.options.
151
- */
152
- mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, Record<any, any>>> | undefined;
153
- }
154
- export declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
155
- /**
156
- * Merge two procedure utils options where `override` takes priority.
157
- * A key explicitly set to `undefined` in `override` resets the base value.
158
- * When both sides define a key, interceptors are concatenated (base ones run first) and
159
- * modifiers are combined so that, for object values, per-call options beat `override`,
160
- * which beats `base`. A function modifier receives the merged options and its result wins.
161
- */
162
- export declare function mergeProcedureUtilsOptions<
163
- TClientContext extends ClientContext,
164
- TInput,
165
- TOutput,
166
- TError
167
- >(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
168
- export declare class ProcedureUtils<
169
- TClientContext extends ClientContext,
170
- TInput,
171
- TOutput,
172
- TError
173
- > extends SharedUtils<TInput> {
174
- protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
175
- /**
176
- * Calling corresponding procedure client
177
- *
178
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#calling-procedure-clients | Pinia Colada Integration - Calling Procedure Clients}
179
- */
180
- call: Client<TClientContext, TInput, TOutput, TError>;
181
- constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
182
- /**
183
- * Generate a **full matching** key for useQuery/...
184
- *
185
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
186
- */
187
- queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): EntryKeyTagged<TOutput, TError>;
188
- /**
189
- * Generate options used for useQuery/...
190
- *
191
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#query-options-utility | Pinia Colada Integration - Query Options Utility}
192
- */
193
- queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, UInitialData>>;
194
- /**
195
- * Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/pinia-colada#streamed-query-options-utility).
196
- *
197
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
198
- */
199
- streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): EntryKeyTagged<InferStreamedQueryOutput<TOutput>, TError>;
200
- /**
201
- * Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
202
- * The resulting data is an array of chunks, and each new chunk is appended as it arrives.
203
- * Works with `useQuery` and any other API that accepts query options.
204
- */
205
- streamedOptions<UInitialData extends InferStreamedQueryOutput<TOutput> | undefined = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, UInitialData>>;
206
- /**
207
- * Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/pinia-colada#live-query-options-utility).
208
- *
209
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
210
- */
211
- liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): EntryKeyTagged<InferLiveQueryOutput<TOutput>, TError>;
212
- /**
213
- * Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
214
- * Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
215
- * Works with `useQuery` and any other API that accepts query options.
216
- */
217
- liveOptions<UInitialData extends InferLiveQueryOutput<TOutput> | undefined = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, UInitialData>>;
218
- /**
219
- * Generate a **full matching** key for useInfiniteQuery/...
220
- *
221
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
222
- */
223
- infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): EntryKeyTagged<UseInfiniteQueryData<TOutput, UPageParam>, TError>;
224
- /**
225
- * Generate options used for useInfiniteQuery/...
226
- *
227
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#infinite-query-options-utility | Pinia Colada Integration - Infinite Query Options Utility}
228
- */
229
- infiniteOptions<
230
- UPageParam,
231
- UInitialData extends UseInfiniteQueryData<TOutput, UPageParam> | undefined = undefined
232
- >(optionsIn: InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, UPageParam, UInitialData>): NoInfer<InfiniteOptionsOut<TOutput, TError, UPageParam, UInitialData>>;
233
- /**
234
- * Generate a **full matching** key for useMutation/...
235
- *
236
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
237
- */
238
- mutationKey(...rest: MaybeOptionalOptions<MutationKeyOptions<TInput>>): MutationOptionsOut<TInput, TOutput, TError, _EmptyObject>["key"];
239
- /**
240
- * Generate options used for useMutation/...
241
- *
242
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#mutation-options | Pinia Colada Integration - Mutation Options}
243
- */
244
- mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
245
- }
@@ -1,394 +0,0 @@
1
- import { intercept, isAsyncIteratorObject, isTypescriptObject, resolveMaybeOptionalOptions } from "@orpc/shared";
2
- import { liveQuery } from "./live-query.mjs";
3
- import { SharedUtils } from "./shared-utils.mjs";
4
- import { serializableStreamedQuery } from "./stream-query.mjs";
5
- import { OPERATION_CONTEXT_SYMBOL } from "./types.mjs";
6
- const PROCEDURE_UTILS_INTERCEPTOR_KEYS = [
7
- "queryInterceptors",
8
- "streamedInterceptors",
9
- "liveInterceptors",
10
- "infiniteInterceptors",
11
- "mutationInterceptors"
12
- ];
13
- const PROCEDURE_UTILS_MODIFIER_KEYS = [
14
- "queryKey",
15
- "queryOptions",
16
- "streamedKey",
17
- "streamedOptions",
18
- "liveKey",
19
- "liveOptions",
20
- "infiniteKey",
21
- "infiniteOptions",
22
- "mutationKey",
23
- "mutationOptions"
24
- ];
25
- export function isProcedureUtilsOptions(value) {
26
- if (!isTypescriptObject(value)) {
27
- return false;
28
- }
29
- for (const key of Object.keys(value)) {
30
- if (value[key] === undefined) {
31
- continue;
32
- }
33
- if (key === "prefix") {
34
- if (typeof value[key] !== "string") {
35
- return false;
36
- }
37
- } else if (key === "serializer") {
38
- if (!isTypescriptObject(value[key]) || typeof value[key].serializeJson !== "function") {
39
- return false;
40
- }
41
- } else if (PROCEDURE_UTILS_INTERCEPTOR_KEYS.includes(key)) {
42
- if (!Array.isArray(value[key]) || value[key].some((i) => typeof i !== "function")) {
43
- return false;
44
- }
45
- } else if (PROCEDURE_UTILS_MODIFIER_KEYS.includes(key)) {
46
- if (!isTypescriptObject(value[key])) {
47
- return false;
48
- }
49
- }
50
- }
51
- return true;
52
- }
53
- function mergeProcedureUtilsModifier(base, override) {
54
- if (typeof override !== "function") {
55
- if (typeof base !== "function") {
56
- return {
57
- ...base,
58
- ...override
59
- };
60
- }
61
- return (options) => base({
62
- ...override,
63
- ...options
64
- });
65
- }
66
- const applyBase = typeof base === "function" ? base : (options) => ({
67
- ...base,
68
- ...options
69
- });
70
- return (options) => override(applyBase(options));
71
- }
72
-
73
- export function mergeProcedureUtilsOptions(base, override) {
74
- const merged = {
75
- ...base,
76
- ...override
77
- };
78
- for (const key of PROCEDURE_UTILS_INTERCEPTOR_KEYS) {
79
- const baseValue = base[key];
80
- const overrideValue = override[key];
81
- if (baseValue && overrideValue) {
82
- merged[key] = [...baseValue, ...overrideValue];
83
- }
84
- }
85
- for (const key of PROCEDURE_UTILS_MODIFIER_KEYS) {
86
- const baseValue = base[key];
87
- const overrideValue = override[key];
88
- if (baseValue && overrideValue) {
89
- merged[key] = mergeProcedureUtilsModifier(baseValue, overrideValue);
90
- }
91
- }
92
- return merged;
93
- }
94
- export class ProcedureUtils extends SharedUtils {
95
-
96
- call;
97
- constructor(path, client, options = {}) {
98
- super(path, options);
99
- this.call = client;
100
- }
101
-
102
- queryKey(...rest) {
103
- let optionsIn = resolveMaybeOptionalOptions(rest);
104
- if (typeof this.options.queryKey === "function") {
105
- optionsIn = this.options.queryKey(optionsIn);
106
- } else if (this.options.queryKey) {
107
- optionsIn = {
108
- ...this.options.queryKey,
109
- ...optionsIn
110
- };
111
- }
112
- const key = optionsIn.key ?? this.key({
113
- type: "query",
114
- input: optionsIn.input
115
- });
116
- return key;
117
- }
118
-
119
- queryOptions(...rest) {
120
- let optionsIn = resolveMaybeOptionalOptions(rest);
121
- if (typeof this.options.queryOptions === "function") {
122
- optionsIn = this.options.queryOptions(optionsIn);
123
- } else if (this.options.queryOptions) {
124
- optionsIn = {
125
- ...this.options.queryOptions,
126
- ...optionsIn
127
- };
128
- }
129
- const { input, context, key: _keyIn, query: queryIn, ...restOptions } = optionsIn;
130
- const key = this.queryKey(optionsIn);
131
- return {
132
- ...restOptions,
133
- key,
134
- query: (fnContext) => {
135
- return intercept(this.options.queryInterceptors, {
136
- path: this.path,
137
- context: {
138
- [OPERATION_CONTEXT_SYMBOL]: {
139
- key,
140
- type: "query"
141
- },
142
- ...context
143
- },
144
- input,
145
- fnContext
146
- }, ({ context, input, fnContext }) => {
147
- if (queryIn) {
148
- return queryIn(fnContext);
149
- }
150
- return this.call(input, {
151
- signal: fnContext.signal,
152
- context
153
- });
154
- });
155
- }
156
- };
157
- }
158
-
159
- streamedKey(...rest) {
160
- let optionsIn = resolveMaybeOptionalOptions(rest);
161
- if (typeof this.options.streamedKey === "function") {
162
- optionsIn = this.options.streamedKey(optionsIn);
163
- } else if (this.options.streamedKey) {
164
- optionsIn = {
165
- ...this.options.streamedKey,
166
- ...optionsIn
167
- };
168
- }
169
- const key = optionsIn.key ?? this.key({
170
- type: "streamed",
171
- input: optionsIn.input,
172
- fnOptions: optionsIn.fnOptions
173
- });
174
- return key;
175
- }
176
-
177
- streamedOptions(...rest) {
178
- let optionsIn = resolveMaybeOptionalOptions(rest);
179
- if (typeof this.options.streamedOptions === "function") {
180
- optionsIn = this.options.streamedOptions(optionsIn);
181
- } else if (this.options.streamedOptions) {
182
- optionsIn = {
183
- ...this.options.streamedOptions,
184
- ...optionsIn
185
- };
186
- }
187
- const { input, context, key: _keyIn, query: queryIn, fnOptions, ...restOptions } = optionsIn;
188
- const key = this.streamedKey(optionsIn);
189
- return {
190
- ...restOptions,
191
- key,
192
- query: (fnContext) => {
193
- return intercept(this.options.streamedInterceptors, {
194
- path: this.path,
195
- context: {
196
- [OPERATION_CONTEXT_SYMBOL]: {
197
- key,
198
- type: "streamed"
199
- },
200
- ...context
201
- },
202
- input,
203
- fnContext
204
- }, ({ context, input, fnContext }) => {
205
- if (queryIn) {
206
- return queryIn(fnContext);
207
- }
208
- return serializableStreamedQuery(async (queryContext) => {
209
- const output = await this.call(input, {
210
- signal: queryContext.signal,
211
- context
212
- });
213
- if (!isAsyncIteratorObject(output)) {
214
- throw new Error("streamedQuery requires an AsyncIteratorObject output");
215
- }
216
- return output;
217
- }, fnOptions)(fnContext);
218
- });
219
- }
220
- };
221
- }
222
-
223
- liveKey(...rest) {
224
- let optionsIn = resolveMaybeOptionalOptions(rest);
225
- if (typeof this.options.liveKey === "function") {
226
- optionsIn = this.options.liveKey(optionsIn);
227
- } else if (this.options.liveKey) {
228
- optionsIn = {
229
- ...this.options.liveKey,
230
- ...optionsIn
231
- };
232
- }
233
- const key = optionsIn.key ?? this.key({
234
- type: "live",
235
- input: optionsIn.input
236
- });
237
- return key;
238
- }
239
-
240
- liveOptions(...rest) {
241
- let optionsIn = resolveMaybeOptionalOptions(rest);
242
- if (typeof this.options.liveOptions === "function") {
243
- optionsIn = this.options.liveOptions(optionsIn);
244
- } else if (this.options.liveOptions) {
245
- optionsIn = {
246
- ...this.options.liveOptions,
247
- ...optionsIn
248
- };
249
- }
250
- const { input, context, key: _keyIn, query: queryIn, ...restOptions } = optionsIn;
251
- const key = this.liveKey(optionsIn);
252
- return {
253
- ...restOptions,
254
- key,
255
- query: (fnContext) => {
256
- return intercept(this.options.liveInterceptors, {
257
- path: this.path,
258
- context: {
259
- [OPERATION_CONTEXT_SYMBOL]: {
260
- key,
261
- type: "live"
262
- },
263
- ...context
264
- },
265
- input,
266
- fnContext
267
- }, ({ context, input, fnContext }) => {
268
- if (queryIn) {
269
- return queryIn(fnContext);
270
- }
271
- return liveQuery(async (queryContext) => {
272
- const output = await this.call(input, {
273
- signal: queryContext.signal,
274
- context
275
- });
276
- if (!isAsyncIteratorObject(output)) {
277
- throw new Error("liveQuery requires an AsyncIteratorObject output");
278
- }
279
- return output;
280
- })(fnContext);
281
- });
282
- }
283
- };
284
- }
285
-
286
- infiniteKey(optionsIn) {
287
- if (typeof this.options.infiniteKey === "function") {
288
- optionsIn = this.options.infiniteKey(optionsIn);
289
- } else if (this.options.infiniteKey) {
290
- optionsIn = {
291
- ...this.options.infiniteKey,
292
- ...optionsIn
293
- };
294
- }
295
- const key = optionsIn.key ?? this.key({
296
- type: "infinite",
297
- input: optionsIn.input(typeof optionsIn.initialPageParam === "function" ? optionsIn.initialPageParam() : optionsIn.initialPageParam)
298
- });
299
- return key;
300
- }
301
-
302
- infiniteOptions(optionsIn) {
303
- if (typeof this.options.infiniteOptions === "function") {
304
- optionsIn = this.options.infiniteOptions(optionsIn);
305
- } else if (this.options.infiniteOptions) {
306
- optionsIn = {
307
- ...this.options.infiniteOptions,
308
- ...optionsIn
309
- };
310
- }
311
- const { input, context, key: _keyIn, query: queryIn, ...restOptions } = optionsIn;
312
- const key = this.infiniteKey(optionsIn);
313
- return {
314
- ...restOptions,
315
- key,
316
- query: (fnContext) => {
317
- return intercept(this.options.infiniteInterceptors, {
318
- path: this.path,
319
- context: {
320
- [OPERATION_CONTEXT_SYMBOL]: {
321
- key,
322
- type: "infinite"
323
- },
324
- ...context
325
- },
326
- input: input(fnContext.pageParam),
327
- fnContext
328
- }, ({ context, input, fnContext }) => {
329
- if (queryIn) {
330
- return queryIn(fnContext);
331
- }
332
- return this.call(input, {
333
- signal: fnContext.signal,
334
- context
335
- });
336
- });
337
- }
338
- };
339
- }
340
-
341
- mutationKey(...rest) {
342
- let optionsIn = resolveMaybeOptionalOptions(rest);
343
- if (typeof this.options.mutationKey === "function") {
344
- optionsIn = this.options.mutationKey(optionsIn);
345
- } else if (this.options.mutationKey) {
346
- optionsIn = {
347
- ...this.options.mutationKey,
348
- ...optionsIn
349
- };
350
- }
351
- const key = optionsIn.key ?? ((input) => this.key({
352
- type: "mutation",
353
- input
354
- }));
355
- return key;
356
- }
357
-
358
- mutationOptions(...rest) {
359
- let optionsIn = resolveMaybeOptionalOptions(rest);
360
- if (typeof this.options.mutationOptions === "function") {
361
- optionsIn = this.options.mutationOptions(optionsIn);
362
- } else if (this.options.mutationOptions) {
363
- optionsIn = {
364
- ...this.options.mutationOptions,
365
- ...optionsIn
366
- };
367
- }
368
- const { context, key: _keyIn, mutation: mutationIn, ...restOptions } = optionsIn;
369
- const key = this.mutationKey(optionsIn);
370
- return {
371
- ...restOptions,
372
- key,
373
- mutation: (input, fnContext) => {
374
- return intercept(this.options.mutationInterceptors, {
375
- path: this.path,
376
- context: {
377
- [OPERATION_CONTEXT_SYMBOL]: {
378
- key: typeof key === "function" ? key(input) : key,
379
- type: "mutation"
380
- },
381
- ...context
382
- },
383
- input,
384
- fnContext
385
- }, ({ context, input, fnContext }) => {
386
- if (mutationIn) {
387
- return mutationIn(input, fnContext);
388
- }
389
- return this.call(input, { context });
390
- });
391
- }
392
- };
393
- }
394
- }
@@ -1,57 +0,0 @@
1
- import type { AnyNestedClient, Client, InferClientContext, InferClientError } from "@orpc/client";
2
- import type { Public } from "@orpc/shared";
3
- import type { OperationKeyBaseOptions } from "./key.mjs";
4
- import type { RouterUtilsPlugin } from "./plugin.mjs";
5
- import type { ProcedureUtilsInfiniteInterceptor, ProcedureUtilsLiveInterceptor, ProcedureUtilsMutationInterceptor, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsStreamedInterceptor } from "./procedure-utils.mjs";
6
- import { ProcedureUtils } from "./procedure-utils.mjs";
7
- import { SharedUtils } from "./shared-utils.mjs";
8
- /**
9
- * The utils shape derived from a client: procedure clients map to procedure
10
- * utils, and routers map recursively to nested utils.
11
- *
12
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada | Pinia Colada Integration}
13
- */
14
- export type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : { [K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never } & Public<SharedUtils<unknown>>;
15
- export type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : { [K in keyof T]?: (T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never) | undefined };
16
- export interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyBaseOptions {
17
- /**
18
- * Interceptors that intercept query inside .queryOptions
19
- */
20
- queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
21
- /**
22
- * Interceptors that intercept query inside .streamedOptions
23
- */
24
- streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
25
- /**
26
- * Interceptors that intercept query inside .liveOptions
27
- */
28
- liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
29
- /**
30
- * Interceptors that intercept query inside .infiniteOptions
31
- */
32
- infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
33
- /**
34
- * Interceptors that intercept mutation inside .mutationOptions
35
- */
36
- mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
37
- /**
38
- * Per-procedure options following the shape of the router.
39
- * Allows fine-grained configuration of individual procedure utils
40
- * without affecting the rest of the router.
41
- */
42
- scoped?: RouterUtilsScoped<T> | undefined;
43
- /**
44
- * Plugins to extend router utils behavior.
45
- */
46
- plugins?: RouterUtilsPlugin<T>[] | undefined;
47
- }
48
- /**
49
- * Creates Pinia Colada utils from a client, exposing query/mutation
50
- * option builders for every procedure in the router.
51
- *
52
- * @remarks
53
- * **Note**: Both client-side and server-side clients are supported.
54
- *
55
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada | Pinia Colada Integration}
56
- */
57
- export declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;