@orpc/svelte-query 0.0.0-next.fcb9d5a → 0.0.0-next.fd6982a
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/index.d.mts +26 -17
- package/dist/index.d.ts +26 -17
- package/dist/index.mjs +40 -11
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
7
|
-
type?: TType;
|
|
8
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
9
|
-
}
|
|
10
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
2
|
+
import { OperationType, BuildKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { BuildKeyOptions, OperationType as KeyType, buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, CreateQueryOptions, QueryFunctionContext, experimental_streamedQuery, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
|
|
5
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Utils at any level (procedure or router)
|
|
@@ -18,14 +13,14 @@ interface GeneralUtils<TInput> {
|
|
|
18
13
|
*
|
|
19
14
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
20
15
|
*/
|
|
21
|
-
key<UType extends
|
|
16
|
+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
22
17
|
}
|
|
23
18
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
24
19
|
|
|
25
20
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
-
input?: TInput;
|
|
21
|
+
input?: TInput | SkipToken;
|
|
27
22
|
} : {
|
|
28
|
-
input: TInput;
|
|
23
|
+
input: TInput | SkipToken;
|
|
29
24
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
25
|
context?: TClientContext;
|
|
31
26
|
} : {
|
|
@@ -34,10 +29,16 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
34
29
|
interface QueryOptionsBase<TOutput, TError> {
|
|
35
30
|
queryKey: QueryKey;
|
|
36
31
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
37
|
-
|
|
32
|
+
throwOnError?(error: TError): boolean;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
}
|
|
35
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
36
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
37
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
|
|
38
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
38
39
|
}
|
|
39
40
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
|
40
|
-
input: (pageParam: TPageParam) => TInput;
|
|
41
|
+
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
41
42
|
} & (Record<never, never> extends TClientContext ? {
|
|
42
43
|
context?: TClientContext;
|
|
43
44
|
} : {
|
|
@@ -46,7 +47,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
46
47
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
47
48
|
queryKey: QueryKey;
|
|
48
49
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
49
|
-
|
|
50
|
+
throwOnError?(error: TError): boolean;
|
|
51
|
+
enabled: boolean;
|
|
50
52
|
}
|
|
51
53
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
52
54
|
context?: TClientContext;
|
|
@@ -68,6 +70,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
68
70
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
69
71
|
*/
|
|
70
72
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
73
|
+
/**
|
|
74
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
|
75
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
78
|
+
*/
|
|
79
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
71
80
|
/**
|
|
72
81
|
* Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
|
|
73
82
|
*
|
|
@@ -100,5 +109,5 @@ interface CreateRouterUtilsOptions {
|
|
|
100
109
|
*/
|
|
101
110
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
102
111
|
|
|
103
|
-
export {
|
|
104
|
-
export type {
|
|
112
|
+
export { createGeneralUtils, createRouterUtils as createORPCSvelteQueryUtils, createProcedureUtils, createRouterUtils };
|
|
113
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface BuildKeyOptions<TType extends KeyType, TInput> {
|
|
7
|
-
type?: TType;
|
|
8
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
9
|
-
}
|
|
10
|
-
declare function buildKey<TType extends KeyType, TInput>(path: string[], options?: BuildKeyOptions<TType, TInput>): QueryKey;
|
|
2
|
+
import { OperationType, BuildKeyOptions } from '@orpc/tanstack-query';
|
|
3
|
+
export { BuildKeyOptions, OperationType as KeyType, buildKey } from '@orpc/tanstack-query';
|
|
4
|
+
import { QueryKey, SkipToken, CreateQueryOptions, QueryFunctionContext, experimental_streamedQuery, CreateInfiniteQueryOptions, CreateMutationOptions, InfiniteData } from '@tanstack/svelte-query';
|
|
5
|
+
import { SetOptional, MaybeOptionalOptions } from '@orpc/shared';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Utils at any level (procedure or router)
|
|
@@ -18,14 +13,14 @@ interface GeneralUtils<TInput> {
|
|
|
18
13
|
*
|
|
19
14
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
20
15
|
*/
|
|
21
|
-
key<UType extends
|
|
16
|
+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
|
|
22
17
|
}
|
|
23
18
|
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
24
19
|
|
|
25
20
|
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = (undefined extends TInput ? {
|
|
26
|
-
input?: TInput;
|
|
21
|
+
input?: TInput | SkipToken;
|
|
27
22
|
} : {
|
|
28
|
-
input: TInput;
|
|
23
|
+
input: TInput | SkipToken;
|
|
29
24
|
}) & (Record<never, never> extends TClientContext ? {
|
|
30
25
|
context?: TClientContext;
|
|
31
26
|
} : {
|
|
@@ -34,10 +29,16 @@ type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TErro
|
|
|
34
29
|
interface QueryOptionsBase<TOutput, TError> {
|
|
35
30
|
queryKey: QueryKey;
|
|
36
31
|
queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
|
|
37
|
-
|
|
32
|
+
throwOnError?(error: TError): boolean;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
}
|
|
35
|
+
type experimental_StreamedQueryOptions = Omit<Parameters<typeof experimental_streamedQuery>[0], 'queryFn'>;
|
|
36
|
+
type experimental_InferStreamedOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
37
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & experimental_StreamedQueryOptions;
|
|
38
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
38
39
|
}
|
|
39
40
|
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
|
40
|
-
input: (pageParam: TPageParam) => TInput;
|
|
41
|
+
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
41
42
|
} & (Record<never, never> extends TClientContext ? {
|
|
42
43
|
context?: TClientContext;
|
|
43
44
|
} : {
|
|
@@ -46,7 +47,8 @@ type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TE
|
|
|
46
47
|
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
47
48
|
queryKey: QueryKey;
|
|
48
49
|
queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
|
|
49
|
-
|
|
50
|
+
throwOnError?(error: TError): boolean;
|
|
51
|
+
enabled: boolean;
|
|
50
52
|
}
|
|
51
53
|
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
52
54
|
context?: TClientContext;
|
|
@@ -68,6 +70,13 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
68
70
|
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-options-utility Tanstack Query Options Utility Docs}
|
|
69
71
|
*/
|
|
70
72
|
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
73
|
+
/**
|
|
74
|
+
* Generate [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) options used for useQuery/prefetchQuery/...
|
|
75
|
+
* Built on top of [steamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#streamed-query-options-utility Tanstack Streamed Query Options Utility Docs}
|
|
78
|
+
*/
|
|
79
|
+
experimental_streamedOptions<U, USelectData = experimental_InferStreamedOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_InferStreamedOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_InferStreamedOutput<TOutput>, TError>, keyof U>>;
|
|
71
80
|
/**
|
|
72
81
|
* Generate options used for createInfiniteQuery/prefetchInfiniteQuery/...
|
|
73
82
|
*
|
|
@@ -100,5 +109,5 @@ interface CreateRouterUtilsOptions {
|
|
|
100
109
|
*/
|
|
101
110
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
102
111
|
|
|
103
|
-
export {
|
|
104
|
-
export type {
|
|
112
|
+
export { createGeneralUtils, createRouterUtils as createORPCSvelteQueryUtils, createProcedureUtils, createRouterUtils };
|
|
113
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, ProcedureUtils, QueryOptionsBase, QueryOptionsIn, RouterUtils, experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
...withInput,
|
|
6
|
-
...withType
|
|
7
|
-
}];
|
|
8
|
-
}
|
|
1
|
+
import { buildKey } from '@orpc/tanstack-query';
|
|
2
|
+
export { buildKey } from '@orpc/tanstack-query';
|
|
3
|
+
import { isAsyncIteratorObject } from '@orpc/shared';
|
|
4
|
+
import { skipToken, experimental_streamedQuery } from '@tanstack/svelte-query';
|
|
9
5
|
|
|
10
6
|
function createGeneralUtils(path) {
|
|
11
7
|
return {
|
|
@@ -21,16 +17,49 @@ function createProcedureUtils(client, options) {
|
|
|
21
17
|
queryOptions(...[optionsIn = {}]) {
|
|
22
18
|
return {
|
|
23
19
|
queryKey: buildKey(options.path, { type: "query", input: optionsIn.input }),
|
|
24
|
-
queryFn: ({ signal }) =>
|
|
20
|
+
queryFn: ({ signal }) => {
|
|
21
|
+
if (optionsIn.input === skipToken) {
|
|
22
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
23
|
+
}
|
|
24
|
+
return client(optionsIn.input, { signal, context: optionsIn.context });
|
|
25
|
+
},
|
|
26
|
+
enabled: optionsIn.input !== skipToken,
|
|
27
|
+
...optionsIn
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
experimental_streamedOptions(...[optionsIn = {}]) {
|
|
31
|
+
return {
|
|
32
|
+
enabled: optionsIn.input !== skipToken,
|
|
33
|
+
queryKey: buildKey(options.path, { type: "streamed", input: optionsIn.input }),
|
|
34
|
+
queryFn: experimental_streamedQuery({
|
|
35
|
+
...optionsIn,
|
|
36
|
+
queryFn: async ({ signal }) => {
|
|
37
|
+
if (optionsIn.input === skipToken) {
|
|
38
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
39
|
+
}
|
|
40
|
+
const output = await client(optionsIn.input, { signal, context: optionsIn.context });
|
|
41
|
+
if (!isAsyncIteratorObject(output)) {
|
|
42
|
+
throw new Error("streamedQuery requires an event iterator output");
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
25
47
|
...optionsIn
|
|
26
48
|
};
|
|
27
49
|
},
|
|
28
50
|
infiniteOptions(optionsIn) {
|
|
29
51
|
return {
|
|
30
|
-
queryKey: buildKey(options.path, {
|
|
52
|
+
queryKey: buildKey(options.path, {
|
|
53
|
+
type: "infinite",
|
|
54
|
+
input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
|
|
55
|
+
}),
|
|
31
56
|
queryFn: ({ pageParam, signal }) => {
|
|
57
|
+
if (optionsIn.input === skipToken) {
|
|
58
|
+
throw new Error("queryFn should not be called with skipToken used as input");
|
|
59
|
+
}
|
|
32
60
|
return client(optionsIn.input(pageParam), { signal, context: optionsIn.context });
|
|
33
61
|
},
|
|
62
|
+
enabled: optionsIn.input !== skipToken,
|
|
34
63
|
...optionsIn
|
|
35
64
|
};
|
|
36
65
|
},
|
|
@@ -71,4 +100,4 @@ function createRouterUtils(client, options = {}) {
|
|
|
71
100
|
return recursive;
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
export {
|
|
103
|
+
export { createGeneralUtils, createRouterUtils as createORPCSvelteQueryUtils, createProcedureUtils, createRouterUtils };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/svelte-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.fd6982a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,14 +29,15 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@tanstack/svelte-query": ">=5.55.0",
|
|
31
31
|
"svelte": ">=4.2.0",
|
|
32
|
-
"@orpc/client": "0.0.0-next.
|
|
32
|
+
"@orpc/client": "0.0.0-next.fd6982a"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@orpc/shared": "0.0.0-next.
|
|
35
|
+
"@orpc/shared": "0.0.0-next.fd6982a",
|
|
36
|
+
"@orpc/tanstack-query": "0.0.0-next.fd6982a"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@tanstack/
|
|
39
|
-
"zod": "^3.
|
|
39
|
+
"@tanstack/svelte-query": "^5.77.2",
|
|
40
|
+
"zod": "^3.25.11"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "unbuild",
|