@orpc/vue-query 0.0.0-next.fd1db03 → 0.0.0-next.ff5907c

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.js CHANGED
@@ -2,76 +2,76 @@
2
2
  function buildKey(path, options) {
3
3
  const withInput = options?.input !== void 0 ? { input: options?.input } : {};
4
4
  const withType = options?.type !== void 0 ? { type: options?.type } : {};
5
- return [
6
- "__ORPC__",
7
- path,
8
- {
9
- ...withInput,
10
- ...withType
5
+ return [path, {
6
+ ...withInput,
7
+ ...withType
8
+ }];
9
+ }
10
+
11
+ // src/general-utils.ts
12
+ function createGeneralUtils(path) {
13
+ return {
14
+ key(options) {
15
+ return buildKey(path, options);
11
16
  }
12
- ];
17
+ };
13
18
  }
14
19
 
20
+ // src/procedure-utils.ts
21
+ import { computed } from "vue";
22
+
15
23
  // src/utils.ts
24
+ import { isObject } from "@orpc/shared";
16
25
  import { isRef } from "vue";
17
- function deepUnref(value) {
26
+ function unrefDeep(value) {
18
27
  if (isRef(value)) {
19
- return deepUnref(value.value);
28
+ return unrefDeep(value.value);
20
29
  }
21
30
  if (Array.isArray(value)) {
22
- return value.map(deepUnref);
31
+ return value.map(unrefDeep);
23
32
  }
24
- if (value && typeof value === "object") {
33
+ if (isObject(value)) {
25
34
  return Object.keys(value).reduce((acc, key) => {
26
- acc[key] = deepUnref(value[key]);
35
+ acc[key] = unrefDeep(value[key]);
27
36
  return acc;
28
37
  }, {});
29
38
  }
30
39
  return value;
31
40
  }
32
41
 
33
- // src/utils-general.ts
34
- function createGeneralUtils(path) {
35
- return {
36
- key(options) {
37
- return buildKey(path, deepUnref(options));
38
- }
39
- };
40
- }
41
-
42
- // src/utils-procedure.ts
43
- import { computed } from "vue";
42
+ // src/procedure-utils.ts
44
43
  function createProcedureUtils(client, path) {
45
44
  return {
46
- queryOptions(...[options]) {
47
- const input = options?.input;
45
+ call: client,
46
+ queryOptions(...[{ input, context, ...rest } = {}]) {
48
47
  return {
49
- queryKey: computed(() => buildKey(path, { type: "query", input: deepUnref(input) })),
50
- queryFn: ({ signal }) => client(deepUnref(input), { signal, context: deepUnref(options?.context) }),
51
- ...options
48
+ queryKey: computed(() => buildKey(path, { type: "query", input: unrefDeep(input) })),
49
+ queryFn: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
50
+ ...rest
52
51
  };
53
52
  },
54
- infiniteOptions(options) {
55
- const input = options.input;
53
+ infiniteOptions({ input, context, ...rest }) {
56
54
  return {
57
- queryKey: computed(() => buildKey(path, { type: "infinite", input: deepUnref(input) })),
55
+ queryKey: computed(() => {
56
+ return buildKey(path, { type: "infinite", input: unrefDeep(input(unrefDeep(rest.initialPageParam))) });
57
+ }),
58
58
  queryFn: ({ pageParam, signal }) => {
59
- return client({ ...deepUnref(input), cursor: pageParam }, { signal, context: deepUnref(options.context) });
59
+ return client(unrefDeep(input(pageParam)), { signal, context: unrefDeep(context) });
60
60
  },
61
- ...options
61
+ ...rest
62
62
  };
63
63
  },
64
- mutationOptions(...[options]) {
64
+ mutationOptions(...[{ context, ...rest } = {}]) {
65
65
  return {
66
66
  mutationKey: buildKey(path, { type: "mutation" }),
67
- mutationFn: (input) => client(input, { context: deepUnref(options?.context) }),
68
- ...options
67
+ mutationFn: (input) => client(input, { context: unrefDeep(context) }),
68
+ ...rest
69
69
  };
70
70
  }
71
71
  };
72
72
  }
73
73
 
74
- // src/utils-router.ts
74
+ // src/router-utils.ts
75
75
  function createRouterUtils(client, path = []) {
76
76
  const generalUtils = createGeneralUtils(path);
77
77
  const procedureUtils = createProcedureUtils(client, path);
@@ -0,0 +1,7 @@
1
+ import type { QueryKey } from '@tanstack/vue-query';
2
+ import type { BuildKeyOptions, KeyType } from './key';
3
+ export interface GeneralUtils<TInput> {
4
+ key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey;
5
+ }
6
+ export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
7
+ //# sourceMappingURL=general-utils.d.ts.map
@@ -1,8 +1,8 @@
1
- import { createRouterUtils } from './utils-router';
1
+ import { createRouterUtils } from './router-utils';
2
+ export * from './general-utils';
2
3
  export * from './key';
4
+ export * from './procedure-utils';
5
+ export * from './router-utils';
3
6
  export * from './types';
4
- export * from './utils-general';
5
- export * from './utils-procedure';
6
- export * from './utils-router';
7
7
  export declare const createORPCVueQueryUtils: typeof createRouterUtils;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { Client, ClientContext } from '@orpc/client';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
3
+ import type { InfiniteData } from '@tanstack/vue-query';
4
+ import type { InfiniteOptionsBase, InfiniteOptionsIn, MutationOptionsBase, MutationOptionsIn, QueryOptionsBase, QueryOptionsIn } from './types';
5
+ export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
6
+ call: Client<TClientContext, TInput, TOutput, TError>;
7
+ queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & QueryOptionsBase<TOutput, TError>>;
8
+ infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>;
9
+ mutationOptions<U>(...rest: MaybeOptionalOptions<U & MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>;
10
+ }
11
+ export declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
12
+ //# sourceMappingURL=procedure-utils.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { Client, NestedClient } from '@orpc/client';
2
+ import { type GeneralUtils } from './general-utils';
3
+ import { type ProcedureUtils } from './procedure-utils';
4
+ export type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
5
+ [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
6
+ } & GeneralUtils<unknown>;
7
+ /**
8
+ * @param client - Any kind of oRPC clients: `createRouterClient`, `createORPCClient`, ...
9
+ * @param path - The base path for query key, when it it will be prefix to all keys
10
+ */
11
+ export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
+ //# sourceMappingURL=router-utils.d.ts.map
@@ -1,43 +1,58 @@
1
+ import type { ClientContext } from '@orpc/client';
1
2
  import type { AnyFunction, SetOptional } from '@orpc/shared';
2
- import type { DefaultError, MutationObserverOptions, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
3
- import type { MaybeRef, MaybeRefOrGetter } from 'vue';
4
- export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
5
- [K in keyof T]: MaybeDeepRef<T[K]>;
3
+ import type { Enabled, MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query';
4
+ import type { ComputedRef, MaybeRef, MaybeRefOrGetter } from 'vue';
5
+ /**
6
+ * Since `@tanstack/vue-query` is not exporting the type `MaybeRefDeep` we need to copy it from the source code.
7
+ * https://github.com/TanStack/query/blob/7ff544e12e79388e513b1cd886aeb946f80f0153/packages/vue-query/src/types.ts#L19C1-L27C2
8
+ */
9
+ export type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
10
+ [Property in keyof T]: MaybeRefDeep<T[Property]>;
6
11
  } : T>;
7
- export type NonUndefinedGuard<T> = T extends undefined ? never : T;
8
- export type InferCursor<T> = T extends {
9
- cursor?: any;
10
- } ? T['cursor'] : never;
11
- export type QueryOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
12
- input?: MaybeDeepRef<TInput>;
12
+ export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData> = (undefined extends TInput ? {
13
+ input?: MaybeRefDeep<TInput>;
13
14
  } : {
14
- input: MaybeDeepRef<TInput>;
15
- }) & (undefined extends TClientContext ? {
16
- context?: MaybeDeepRef<TClientContext>;
15
+ input: MaybeRefDeep<TInput>;
16
+ }) & (Record<never, never> extends TClientContext ? {
17
+ context?: MaybeRefDeep<TClientContext>;
17
18
  } : {
18
- context: MaybeDeepRef<TClientContext>;
19
- }) & SetOptional<{
20
- [P in keyof QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>]: P extends 'enabled' ? MaybeRefOrGetter<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]> : MaybeDeepRef<QueryObserverOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey>[P]>;
21
- }, 'queryKey'> & {
22
- shallow?: MaybeRef<boolean>;
23
- initialData?: NonUndefinedGuard<TOutput> | (() => NonUndefinedGuard<TOutput>) | undefined;
19
+ context: MaybeRefDeep<TClientContext>;
20
+ }) & {
21
+ [P in keyof Omit<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>, 'queryKey' | 'enabled'>]: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>;
22
+ } & {
23
+ enabled?: MaybeRefOrGetter<Enabled<TOutput, TError, TSelectData>>;
24
+ queryKey?: MaybeRefDeep<QueryKey>;
25
+ shallow?: boolean;
24
26
  };
25
- export type InfiniteOptions<TInput, TOutput, TClientContext, TSelectData> = (undefined extends TInput ? {
26
- input?: MaybeDeepRef<Omit<TInput, 'cursor'>>;
27
- } : {
28
- input: MaybeDeepRef<Omit<TInput, 'cursor'>>;
29
- }) & (undefined extends TClientContext ? {
30
- context?: MaybeDeepRef<TClientContext>;
27
+ export interface QueryOptionsBase<TOutput, TError extends Error> {
28
+ queryKey: ComputedRef<QueryKey>;
29
+ queryFn(ctx: QueryFunctionContext): Promise<TOutput>;
30
+ retry?(failureCount: number, error: TError): boolean;
31
+ }
32
+ export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error, TSelectData, TPageParam> = {
33
+ input: (pageParam: TPageParam) => MaybeRefDeep<TInput>;
34
+ } & (Record<never, never> extends TClientContext ? {
35
+ context?: MaybeRefDeep<TClientContext>;
31
36
  } : {
32
- context: MaybeDeepRef<TClientContext>;
33
- }) & SetOptional<UseInfiniteQueryOptions<TOutput, DefaultError, TSelectData, TOutput, QueryKey, InferCursor<TInput>>, 'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)>;
34
- export type MutationOptions<TInput, TOutput, TClientContext> = (undefined extends TClientContext ? {
35
- context?: MaybeDeepRef<TClientContext>;
37
+ context: MaybeRefDeep<TClientContext>;
38
+ }) & SetOptional<UseInfiniteQueryOptions<TOutput, TError, TSelectData, TOutput, QueryKey, TPageParam>, 'queryKey'>;
39
+ export interface InfiniteOptionsBase<TOutput, TError extends Error, TPageParam> {
40
+ queryKey: ComputedRef<QueryKey>;
41
+ queryFn(ctx: QueryFunctionContext<QueryKey, TPageParam>): Promise<TOutput>;
42
+ retry?(failureCount: number, error: TError): boolean;
43
+ }
44
+ export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> = (Record<never, never> extends TClientContext ? {
45
+ context?: TClientContext;
36
46
  } : {
37
- context: MaybeDeepRef<TClientContext>;
47
+ context: TClientContext;
38
48
  }) & {
39
- [P in keyof MutationObserverOptions<TOutput, DefaultError, TInput, unknown>]: MaybeDeepRef<MutationObserverOptions<TOutput, DefaultError, TInput, unknown>[P]>;
49
+ [P in keyof MutationObserverOptions<TOutput, TError, TInput>]: MaybeRefDeep<MutationObserverOptions<TOutput, TError, TInput>[P]>;
40
50
  } & {
41
51
  shallow?: MaybeRef<boolean>;
42
52
  };
53
+ export interface MutationOptionsBase<TInput, TOutput, TError extends Error> {
54
+ mutationKey: QueryKey;
55
+ mutationFn(input: TInput): Promise<TOutput>;
56
+ retry?(failureCount: number, error: TError): boolean;
57
+ }
43
58
  //# sourceMappingURL=types.d.ts.map
@@ -1,7 +1,7 @@
1
- import type { AnyFunction } from '@orpc/shared';
2
1
  import type { Ref } from 'vue';
3
- export type DeepUnref<T> = T extends Ref<infer U> ? DeepUnref<U> : T extends AnyFunction ? T : T extends object ? {
4
- [K in keyof T]: DeepUnref<T[K]>;
2
+ import { type AnyFunction } from '@orpc/shared';
3
+ export type UnrefDeep<T> = T extends Ref<infer U> ? UnrefDeep<U> : T extends AnyFunction ? T : T extends object ? {
4
+ [K in keyof T]: UnrefDeep<T[K]>;
5
5
  } : T;
6
- export declare function deepUnref<T>(value: T): DeepUnref<T>;
6
+ export declare function unrefDeep<T>(value: T): UnrefDeep<T>;
7
7
  //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-query",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fd1db03",
4
+ "version": "0.0.0-next.ff5907c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,9 +34,10 @@
34
34
  "peerDependencies": {
35
35
  "@tanstack/vue-query": ">=5.50.0",
36
36
  "vue": ">=3.3.0",
37
- "@orpc/client": "0.0.0-next.fd1db03",
38
- "@orpc/server": "0.0.0-next.fd1db03",
39
- "@orpc/contract": "0.0.0-next.fd1db03"
37
+ "@orpc/client": "0.0.0-next.ff5907c"
38
+ },
39
+ "dependencies": {
40
+ "@orpc/shared": "0.0.0-next.ff5907c"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
@@ -1,11 +0,0 @@
1
- import type { QueryKey } from '@tanstack/vue-query';
2
- import type { BuildKeyOptions, KeyType } from './key';
3
- import type { MaybeDeepRef } from './types';
4
- /**
5
- * Utils at any level (procedure or router)
6
- */
7
- export interface GeneralUtils<TInput> {
8
- key: <UType extends KeyType = undefined>(options?: MaybeDeepRef<BuildKeyOptions<UType, TInput>>) => QueryKey;
9
- }
10
- export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
11
- //# sourceMappingURL=utils-general.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { ProcedureClient } from '@orpc/server';
2
- import type { IsEqual } from '@orpc/shared';
3
- import type { QueryFunctionContext, QueryKey } from '@tanstack/vue-query';
4
- import type { ComputedRef } from 'vue';
5
- import type { InferCursor, InfiniteOptions, MutationOptions, QueryOptions } from './types';
6
- /**
7
- * Utils at procedure level
8
- */
9
- export interface ProcedureUtils<TInput, TOutput, TClientContext> {
10
- queryOptions: <U extends QueryOptions<TInput, TOutput, TClientContext, any>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)) => IsEqual<U, QueryOptions<TInput, TOutput, TClientContext, any>> extends true ? {
11
- queryKey: ComputedRef<QueryKey>;
12
- queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
13
- } : Omit<{
14
- queryKey: ComputedRef<QueryKey>;
15
- queryFn: (ctx: QueryFunctionContext) => Promise<TOutput>;
16
- }, keyof U> & U;
17
- infiniteOptions: <U extends InfiniteOptions<TInput, TOutput, TClientContext, any>>(options: U) => Omit<{
18
- queryKey: ComputedRef<QueryKey>;
19
- queryFn: (ctx: QueryFunctionContext<QueryKey, InferCursor<TInput>>) => Promise<TOutput>;
20
- initialPageParam: undefined;
21
- }, keyof U> & U;
22
- mutationOptions: <U extends MutationOptions<TInput, TOutput, TClientContext>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)) => IsEqual<U, MutationOptions<TInput, TOutput, TClientContext>> extends true ? {
23
- mutationKey: QueryKey;
24
- mutationFn: (input: TInput) => Promise<TOutput>;
25
- } : Omit<{
26
- mutationKey: QueryKey;
27
- mutationFn: (input: TInput) => Promise<TOutput>;
28
- }, keyof U> & U;
29
- }
30
- export declare function createProcedureUtils<TInput, TOutput, TClientContext>(client: ProcedureClient<TInput, TOutput, TClientContext>, path: string[]): ProcedureUtils<TInput, TOutput, TClientContext>;
31
- //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ProcedureClient, RouterClient } from '@orpc/server';
2
- import { type GeneralUtils } from './utils-general';
3
- import { type ProcedureUtils } from './utils-procedure';
4
- export type RouterUtils<T extends RouterClient<any, any>> = T extends ProcedureClient<infer TInput, infer TOutput, infer TClientContext> ? ProcedureUtils<TInput, TOutput, TClientContext> & GeneralUtils<TInput> : {
5
- [K in keyof T]: T[K] extends RouterClient<any, any> ? RouterUtils<T[K]> : never;
6
- } & GeneralUtils<unknown>;
7
- /**
8
- * @param client - The client create form `@orpc/client`
9
- * @param path - The base path for query key
10
- */
11
- export declare function createRouterUtils<T extends RouterClient<any, any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=utils-router.d.ts.map