@orpc/vue-colada 0.0.0-next.b42ba03 → 0.0.0-next.b825e0c

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,72 +2,62 @@
2
2
  import { serializeRPCJson } from "@orpc/server/standard";
3
3
  function buildKey(path, options) {
4
4
  return [
5
+ "__ORPC__",
5
6
  ...path,
6
7
  ...options?.input !== void 0 ? [{ input: JSON.stringify(serializeRPCJson(options.input)) }] : []
7
8
  ];
8
9
  }
9
10
 
10
- // src/general-utils.ts
11
- function createGeneralUtils(path) {
12
- return {
13
- key(options) {
14
- return buildKey(path, options);
15
- }
16
- };
17
- }
18
-
19
- // src/procedure-utils.ts
20
- import { computed } from "vue";
21
-
22
- // ../shared/src/object.ts
23
- function isObject(value) {
24
- if (!value || typeof value !== "object") {
25
- return false;
26
- }
27
- const proto = Object.getPrototypeOf(value);
28
- return proto === Object.prototype || proto === null;
29
- }
30
-
31
11
  // src/utils.ts
32
12
  import { isRef } from "vue";
33
- function unrefDeep(value) {
13
+ function deepUnref(value) {
34
14
  if (isRef(value)) {
35
- return unrefDeep(value.value);
15
+ return deepUnref(value.value);
36
16
  }
37
17
  if (Array.isArray(value)) {
38
- return value.map(unrefDeep);
18
+ return value.map(deepUnref);
39
19
  }
40
- if (isObject(value)) {
20
+ if (value && typeof value === "object") {
41
21
  return Object.keys(value).reduce((acc, key) => {
42
- acc[key] = unrefDeep(value[key]);
22
+ acc[key] = deepUnref(value[key]);
43
23
  return acc;
44
24
  }, {});
45
25
  }
46
26
  return value;
47
27
  }
48
28
 
49
- // src/procedure-utils.ts
29
+ // src/utils-general.ts
30
+ function createGeneralUtils(path) {
31
+ return {
32
+ key(options) {
33
+ return buildKey(path, deepUnref(options));
34
+ }
35
+ };
36
+ }
37
+
38
+ // src/utils-procedure.ts
39
+ import { computed } from "vue";
50
40
  function createProcedureUtils(client, path) {
51
41
  return {
52
- call: client,
53
- queryOptions(...[{ input, context, ...rest } = {}]) {
42
+ queryOptions(...[options]) {
43
+ const input = options?.input;
54
44
  return {
55
- key: computed(() => buildKey(path, { input: unrefDeep(input) })),
56
- query: ({ signal }) => client(unrefDeep(input), { signal, context: unrefDeep(context) }),
57
- ...rest
45
+ key: computed(() => buildKey(path, { input: deepUnref(input) })),
46
+ query: ({ signal }) => client(deepUnref(input), { signal, context: deepUnref(options?.context) }),
47
+ ...options
58
48
  };
59
49
  },
60
- mutationOptions(...[{ context, ...rest } = {}]) {
50
+ mutationOptions(...[options]) {
61
51
  return {
62
52
  key: (input) => buildKey(path, { input }),
63
- mutation: (input) => client(input, { context: unrefDeep(context) }),
64
- ...rest
53
+ mutation: (input, _) => client(input, { context: deepUnref(options?.context) }),
54
+ ...options
65
55
  };
66
56
  }
67
57
  };
68
58
  }
69
59
 
70
- // src/router-utils.ts
60
+ // src/utils-router.ts
71
61
  function createRouterUtils(client, path = []) {
72
62
  const generalUtils = createGeneralUtils(path);
73
63
  const procedureUtils = createProcedureUtils(client, path);
@@ -1,8 +1,8 @@
1
- import { createRouterUtils } from './router-utils';
2
- export * from './general-utils';
1
+ import { createRouterUtils } from './utils-router';
3
2
  export * from './key';
4
- export * from './procedure-utils';
5
- export * from './router-utils';
6
3
  export * from './types';
4
+ export * from './utils-general';
5
+ export * from './utils-procedure';
6
+ export * from './utils-router';
7
7
  export declare const createORPCVueColadaUtils: typeof createRouterUtils;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1,24 +1,27 @@
1
1
  import type { AnyFunction, SetOptional } from '@orpc/shared';
2
2
  import type { UseMutationOptions, UseQueryOptions } from '@pinia/colada';
3
3
  import type { MaybeRef } from 'vue';
4
- export type MaybeRefDeep<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
5
- [K in keyof T]: MaybeRefDeep<T[K]>;
4
+ export type MaybeDeepRef<T> = MaybeRef<T extends AnyFunction ? T : T extends object ? {
5
+ [K in keyof T]: MaybeDeepRef<T[K]>;
6
6
  } : T>;
7
7
  export type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
8
- export type QueryOptionsIn<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TInput ? {
9
- input?: MaybeRefDeep<TInput>;
8
+ export type InferCursor<T> = T extends {
9
+ cursor?: any;
10
+ } ? T['cursor'] : never;
11
+ export type QueryOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TInput ? {
12
+ input?: MaybeDeepRef<TInput>;
10
13
  } : {
11
- input: MaybeRefDeep<TInput>;
14
+ input: MaybeDeepRef<TInput>;
12
15
  }) & (undefined extends TClientContext ? {
13
- context?: MaybeRefDeep<TClientContext>;
16
+ context?: MaybeDeepRef<TClientContext>;
14
17
  } : {
15
- context: MaybeRefDeep<TClientContext>;
18
+ context: MaybeDeepRef<TClientContext>;
16
19
  }) & SetOptional<UseQueryOptions<TOutput, TError>, 'key' | 'query'>;
17
20
  export type QueryOptions<TOutput, TError extends Error> = UseQueryOptions<TOutput, TError>;
18
- export type MutationOptionsIn<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
19
- context?: MaybeRefDeep<TClientContext>;
21
+ export type MutationOptionsExtra<TClientContext, TInput, TOutput, TError extends Error> = (undefined extends TClientContext ? {
22
+ context?: MaybeDeepRef<TClientContext>;
20
23
  } : {
21
- context: MaybeRefDeep<TClientContext>;
24
+ context: MaybeDeepRef<TClientContext>;
22
25
  }) & SetOptional<UseMutationOptions<TOutput, TInput, TError>, 'mutation'>;
23
26
  export type MutationOptions<TInput, TOutput, TError extends Error> = UseMutationOptions<TOutput, TInput, TError>;
24
27
  //# sourceMappingURL=types.d.ts.map
@@ -1,7 +1,11 @@
1
1
  import type { EntryKey } from '@pinia/colada';
2
2
  import type { BuildKeyOptions } from './key';
3
+ import type { MaybeDeepRef } from './types';
4
+ /**
5
+ * Utils at any level (procedure or router)
6
+ */
3
7
  export interface GeneralUtils<TInput> {
4
- key(options?: BuildKeyOptions<TInput>): EntryKey;
8
+ key(options?: MaybeDeepRef<BuildKeyOptions<TInput>>): EntryKey;
5
9
  }
6
10
  export declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
7
- //# sourceMappingURL=general-utils.d.ts.map
11
+ //# sourceMappingURL=utils-general.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Client } from '@orpc/contract';
2
+ import type { MutationOptions, MutationOptionsExtra, QueryOptions, QueryOptionsExtra } from './types';
3
+ /**
4
+ * Utils at procedure level
5
+ */
6
+ export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
7
+ queryOptions<U extends QueryOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TInput & TClientContext ? [] : never)): QueryOptions<TOutput, TError>;
8
+ mutationOptions<U extends MutationOptionsExtra<TClientContext, TInput, TOutput, TError>>(...opt: [options: U] | (undefined extends TClientContext ? [] : never)): MutationOptions<TInput, TOutput, TError>;
9
+ }
10
+ export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
11
+ //# sourceMappingURL=utils-procedure.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import type { Client, NestedClient } from '@orpc/contract';
2
- import { type GeneralUtils } from './general-utils';
3
- import { type ProcedureUtils } from './procedure-utils';
2
+ import { type GeneralUtils } from './utils-general';
3
+ import { type ProcedureUtils } from './utils-procedure';
4
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
5
  [K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
6
6
  } & GeneralUtils<unknown>;
7
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
8
+ * @param client - The client create form `@orpc/client`
9
+ * @param path - The base path for query key
10
10
  */
11
11
  export declare function createRouterUtils<T extends NestedClient<any>>(client: T, path?: string[]): RouterUtils<T>;
12
- //# sourceMappingURL=router-utils.d.ts.map
12
+ //# sourceMappingURL=utils-router.d.ts.map
@@ -1,7 +1,7 @@
1
+ import type { AnyFunction } from '@orpc/shared';
1
2
  import type { Ref } from 'vue';
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]>;
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]>;
5
5
  } : T;
6
- export declare function unrefDeep<T>(value: T): UnrefDeep<T>;
6
+ export declare function deepUnref<T>(value: T): DeepUnref<T>;
7
7
  //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/vue-colada",
3
3
  "type": "module",
4
- "version": "0.0.0-next.b42ba03",
4
+ "version": "0.0.0-next.b825e0c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -33,15 +33,17 @@
33
33
  "dist"
34
34
  ],
35
35
  "peerDependencies": {
36
- "@pinia/colada": "^0.13.5",
36
+ "@pinia/colada": ">=0.13.1",
37
37
  "vue": ">=3.3.0",
38
- "@orpc/contract": "0.0.0-next.b42ba03",
39
- "@orpc/client": "0.0.0-next.b42ba03"
38
+ "@orpc/client": "0.0.0-next.b825e0c",
39
+ "@orpc/contract": "0.0.0-next.b825e0c"
40
40
  },
41
41
  "dependencies": {
42
- "@orpc/server": "0.0.0-next.b42ba03"
42
+ "@orpc/server": "0.0.0-next.b825e0c"
43
43
  },
44
44
  "devDependencies": {
45
+ "@pinia/colada": "^0.13.1",
46
+ "@vue/test-utils": "^2.4.6",
45
47
  "pinia": "^2.3.0"
46
48
  },
47
49
  "scripts": {
@@ -1,10 +0,0 @@
1
- import type { Client } from '@orpc/contract';
2
- import type { MaybeOptionalOptions } from '@orpc/shared';
3
- import type { MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn } from './types';
4
- export interface ProcedureUtils<TClientContext, TInput, TOutput, TError extends Error> {
5
- call: Client<TClientContext, TInput, TOutput, TError>;
6
- queryOptions(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError>>): QueryOptions<TOutput, TError>;
7
- mutationOptions(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError>>): MutationOptions<TInput, TOutput, TError>;
8
- }
9
- export declare function createProcedureUtils<TClientContext, TInput, TOutput, TError extends Error>(client: Client<TClientContext, TInput, TOutput, TError>, path: string[]): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
10
- //# sourceMappingURL=procedure-utils.d.ts.map