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