@orpc/tanstack-query 2.0.0-beta.22 → 2.0.0-beta.24
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/README.md +4 -1
- package/dist/index.d.mts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.mjs +22 -19
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
44
44
|
|
|
45
45
|
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
46
|
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api).
|
|
47
48
|
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
48
49
|
|
|
49
50
|
**Framework & ecosystem integrations**
|
|
@@ -114,6 +115,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
114
115
|
</tr>
|
|
115
116
|
<tr>
|
|
116
117
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
118
|
+
<td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
117
119
|
</tr>
|
|
118
120
|
</table>
|
|
119
121
|
|
|
@@ -139,8 +141,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
139
141
|
<td align="center"><a href="https://github.com/mr-kelly?ref=orpc" target="_blank" rel="noopener" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
140
142
|
</tr>
|
|
141
143
|
<tr>
|
|
144
|
+
<td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
142
145
|
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
143
|
-
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=
|
|
146
|
+
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
144
147
|
</tr>
|
|
145
148
|
</table>
|
|
146
149
|
|
package/dist/index.d.mts
CHANGED
|
@@ -33,7 +33,19 @@ declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey ext
|
|
|
33
33
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
34
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
35
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
36
|
+
/**
|
|
37
|
+
* The symbol under which TanStack Query utils attach operation details
|
|
38
|
+
* (key and operation type) to the client context.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
41
|
+
*/
|
|
36
42
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
43
|
+
/**
|
|
44
|
+
* A client context automatically populated by TanStack Query utils,
|
|
45
|
+
* exposing the operation key and type of the calling operation.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
48
|
+
*/
|
|
37
49
|
interface OperationContext {
|
|
38
50
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
39
51
|
key: QueryKey;
|
|
@@ -331,6 +343,12 @@ declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements R
|
|
|
331
343
|
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
332
344
|
}
|
|
333
345
|
|
|
346
|
+
/**
|
|
347
|
+
* The utils shape derived from a client: procedure clients map to procedure
|
|
348
|
+
* utils, and routers map recursively to nested utils.
|
|
349
|
+
*
|
|
350
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
351
|
+
*/
|
|
334
352
|
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
335
353
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
336
354
|
} & Public<SharedUtils<unknown>>;
|
|
@@ -376,9 +394,13 @@ interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPref
|
|
|
376
394
|
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
377
395
|
}
|
|
378
396
|
/**
|
|
379
|
-
*
|
|
397
|
+
* Creates TanStack Query utils from a client, exposing query/mutation
|
|
398
|
+
* option builders for every procedure in the router.
|
|
380
399
|
*
|
|
381
|
-
* @
|
|
400
|
+
* @remarks
|
|
401
|
+
* **Note**: Both client-side and server-side clients are supported.
|
|
402
|
+
*
|
|
403
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
382
404
|
*/
|
|
383
405
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
384
406
|
|
|
@@ -387,6 +409,16 @@ interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
|
387
409
|
}
|
|
388
410
|
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
389
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Creates a factory that builds TanStack Query utils directly from a contract,
|
|
414
|
+
* using the given contract client factory. Useful for scaling large projects
|
|
415
|
+
* where each part only needs a slice of the router.
|
|
416
|
+
*
|
|
417
|
+
* @remarks
|
|
418
|
+
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
419
|
+
*
|
|
420
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects#tanstack-query-integration | Scaling Large Projects - TanStack Query Integration}
|
|
421
|
+
*/
|
|
390
422
|
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
391
423
|
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
392
424
|
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
@@ -407,7 +439,7 @@ interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema
|
|
|
407
439
|
*
|
|
408
440
|
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
409
441
|
*
|
|
410
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin
|
|
442
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
411
443
|
*/
|
|
412
444
|
declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
413
445
|
declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
@@ -423,7 +455,7 @@ declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
|
423
455
|
* The contract shape must match the client the utils are created from,
|
|
424
456
|
* so pass the root router contract when utils paths start from the root.
|
|
425
457
|
*
|
|
426
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin
|
|
458
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
427
459
|
*/
|
|
428
460
|
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
429
461
|
private readonly contract;
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,19 @@ declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey ext
|
|
|
33
33
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
34
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
35
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
36
|
+
/**
|
|
37
|
+
* The symbol under which TanStack Query utils attach operation details
|
|
38
|
+
* (key and operation type) to the client context.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
41
|
+
*/
|
|
36
42
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
43
|
+
/**
|
|
44
|
+
* A client context automatically populated by TanStack Query utils,
|
|
45
|
+
* exposing the operation key and type of the calling operation.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
48
|
+
*/
|
|
37
49
|
interface OperationContext {
|
|
38
50
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
39
51
|
key: QueryKey;
|
|
@@ -331,6 +343,12 @@ declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements R
|
|
|
331
343
|
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
332
344
|
}
|
|
333
345
|
|
|
346
|
+
/**
|
|
347
|
+
* The utils shape derived from a client: procedure clients map to procedure
|
|
348
|
+
* utils, and routers map recursively to nested utils.
|
|
349
|
+
*
|
|
350
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
351
|
+
*/
|
|
334
352
|
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
335
353
|
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
336
354
|
} & Public<SharedUtils<unknown>>;
|
|
@@ -376,9 +394,13 @@ interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPref
|
|
|
376
394
|
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
377
395
|
}
|
|
378
396
|
/**
|
|
379
|
-
*
|
|
397
|
+
* Creates TanStack Query utils from a client, exposing query/mutation
|
|
398
|
+
* option builders for every procedure in the router.
|
|
380
399
|
*
|
|
381
|
-
* @
|
|
400
|
+
* @remarks
|
|
401
|
+
* **Note**: Both client-side and server-side clients are supported.
|
|
402
|
+
*
|
|
403
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
382
404
|
*/
|
|
383
405
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
384
406
|
|
|
@@ -387,6 +409,16 @@ interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
|
387
409
|
}
|
|
388
410
|
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
389
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Creates a factory that builds TanStack Query utils directly from a contract,
|
|
414
|
+
* using the given contract client factory. Useful for scaling large projects
|
|
415
|
+
* where each part only needs a slice of the router.
|
|
416
|
+
*
|
|
417
|
+
* @remarks
|
|
418
|
+
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
419
|
+
*
|
|
420
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects#tanstack-query-integration | Scaling Large Projects - TanStack Query Integration}
|
|
421
|
+
*/
|
|
390
422
|
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
391
423
|
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
392
424
|
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
@@ -407,7 +439,7 @@ interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema
|
|
|
407
439
|
*
|
|
408
440
|
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
409
441
|
*
|
|
410
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin
|
|
442
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
411
443
|
*/
|
|
412
444
|
declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
413
445
|
declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
@@ -423,7 +455,7 @@ declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
|
423
455
|
* The contract shape must match the client the utils are created from,
|
|
424
456
|
* so pass the root router contract when utils paths start from the root.
|
|
425
457
|
*
|
|
426
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin
|
|
458
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
427
459
|
*/
|
|
428
460
|
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
429
461
|
private readonly contract;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveBasePathMeta, getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
2
|
-
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, toArray, isAsyncIteratorObject, isTypescriptObject, bindMethods,
|
|
2
|
+
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, toArray, isAsyncIteratorObject, isTypescriptObject, bindMethods, get } from '@orpc/shared';
|
|
3
3
|
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
4
4
|
import { skipToken } from '@tanstack/query-core';
|
|
5
5
|
|
|
@@ -528,30 +528,33 @@ function createRouterUtilsInternal(client, options, plugin) {
|
|
|
528
528
|
},
|
|
529
529
|
options.scoped ?? {}
|
|
530
530
|
))
|
|
531
|
-
)) : bindMethods(new SharedUtils(path, options));
|
|
531
|
+
), { unbound: ["call"] }) : bindMethods(new SharedUtils(path, options));
|
|
532
|
+
const cache = /* @__PURE__ */ new Map();
|
|
532
533
|
const recursive = new Proxy(utils, {
|
|
533
534
|
get(target, prop) {
|
|
534
|
-
const value =
|
|
535
|
-
const nextClient = client
|
|
535
|
+
const value = Reflect.get(target, prop);
|
|
536
|
+
const nextClient = Reflect.get(client, prop);
|
|
536
537
|
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop) || !isTypescriptObject(nextClient)) {
|
|
537
538
|
return value;
|
|
538
539
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
540
|
+
let result = cache.get(prop);
|
|
541
|
+
if (result === void 0) {
|
|
542
|
+
const nextUtils = createRouterUtilsInternal(nextClient, {
|
|
543
|
+
...options,
|
|
544
|
+
path: [...path, prop],
|
|
545
|
+
scoped: options.scoped?.[prop]
|
|
546
|
+
}, plugin);
|
|
547
|
+
result = typeof value !== "function" ? nextUtils : new Proxy(value, {
|
|
548
|
+
get(target2, prop2) {
|
|
549
|
+
if (typeof prop2 !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop2)) {
|
|
550
|
+
return Reflect.get(target2, prop2);
|
|
551
|
+
}
|
|
552
|
+
return Reflect.get(nextUtils, prop2);
|
|
551
553
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
554
|
+
});
|
|
555
|
+
cache.set(prop, result);
|
|
556
|
+
}
|
|
557
|
+
return result;
|
|
555
558
|
}
|
|
556
559
|
});
|
|
557
560
|
return recursive;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.24",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"@tanstack/query-core": ">=5.80.2"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@orpc/
|
|
33
|
-
"@orpc/
|
|
34
|
-
"@orpc/shared": "2.0.0-beta.
|
|
35
|
-
"@orpc/
|
|
32
|
+
"@orpc/openapi": "2.0.0-beta.24",
|
|
33
|
+
"@orpc/client": "2.0.0-beta.24",
|
|
34
|
+
"@orpc/shared": "2.0.0-beta.24",
|
|
35
|
+
"@orpc/contract": "2.0.0-beta.24"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@angular/core": "^22.0
|
|
38
|
+
"@angular/core": "^22.1.0",
|
|
39
39
|
"@tanstack/angular-query-experimental": "^5.101.4",
|
|
40
40
|
"@tanstack/query-core": "^5.101.4",
|
|
41
41
|
"@tanstack/react-query": "^5.101.4",
|