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