@trpc/client 10.0.0-alpha.38 → 10.0.0-alpha.40
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.
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import type { AnyRouter } from '@trpc/server';
|
|
1
|
+
import type { AnyRouter, OmitNeverKeys, Procedure, ProcedureArgs, ProcedureRouterRecord, inferProcedureOutput } from '@trpc/server';
|
|
2
2
|
import { TRPCClient as Client } from './internals/TRPCClient';
|
|
3
|
+
declare type Resolver<TProcedure extends Procedure<any>> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferProcedureOutput<TProcedure>>;
|
|
4
|
+
declare type DecorateProcedure<TProcedure extends Procedure<any>> = OmitNeverKeys<{
|
|
5
|
+
query: TProcedure extends {
|
|
6
|
+
_query: true;
|
|
7
|
+
} ? Resolver<TProcedure> : never;
|
|
8
|
+
mutate: TProcedure extends {
|
|
9
|
+
_mutation: true;
|
|
10
|
+
} ? Resolver<TProcedure> : never;
|
|
11
|
+
subscribe: TProcedure extends {
|
|
12
|
+
_subscription: true;
|
|
13
|
+
} ? Resolver<TProcedure> : never;
|
|
14
|
+
}>;
|
|
15
|
+
declare type assertProcedure<T> = T extends Procedure<any> ? T : never;
|
|
3
16
|
/**
|
|
4
17
|
* @internal
|
|
5
18
|
*/
|
|
6
|
-
|
|
7
|
-
[
|
|
19
|
+
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
20
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : DecorateProcedure<assertProcedure<TProcedures[TKey]>>;
|
|
8
21
|
};
|
|
9
|
-
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>):
|
|
22
|
+
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): DecoratedProcedureRecord<TRouter["_def"]["record"]>;
|
|
23
|
+
export {};
|
|
10
24
|
//# sourceMappingURL=createTRPCClientProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,aAAa,EACb,qBAAqB,EAErB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE9D,aAAK,QAAQ,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAAI,CACjD,GAAG,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KACvC,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;AAE/C,aAAK,iBAAiB,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC;IACxE,KAAK,EAAE,UAAU,SAAS;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;IAE1E,MAAM,EAAE,UAAU,SAAS;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;IAE9E,SAAS,EAAE,UAAU,SAAS;QAAE,aAAa,EAAE,IAAI,CAAA;KAAE,GACjD,QAAQ,CAAC,UAAU,CAAC,GACpB,KAAK,CAAC;CACX,CAAC,CAAC;AAEH,aAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/D;;GAEG;AACH,aAAK,wBAAwB,CAAC,WAAW,SAAS,qBAAqB,IAAI;KACxE,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,SAAS,GAC5D,wBAAwB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC7D,iBAAiB,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;CAC1D,CAAC;AAQF,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,uDAWxB"}
|
package/dist/index.js
CHANGED
|
@@ -416,6 +416,11 @@ function createTRPCClient(opts) {
|
|
|
416
416
|
return client;
|
|
417
417
|
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
418
418
|
|
|
419
|
+
var clientCallTypeMap = {
|
|
420
|
+
query: 'query',
|
|
421
|
+
mutate: 'mutation',
|
|
422
|
+
subscribe: 'subscription'
|
|
423
|
+
};
|
|
419
424
|
function createTRPCClientProxy(client) {
|
|
420
425
|
var proxy = shared.createProxy(function (_ref) {
|
|
421
426
|
var _ref2;
|
|
@@ -425,14 +430,10 @@ function createTRPCClientProxy(client) {
|
|
|
425
430
|
|
|
426
431
|
var pathCopy = _toConsumableArray__default["default"](path);
|
|
427
432
|
|
|
428
|
-
var
|
|
429
|
-
|
|
430
|
-
if (type === 'mutate') {
|
|
431
|
-
type = 'mutation';
|
|
432
|
-
}
|
|
433
|
-
|
|
433
|
+
var clientCallType = pathCopy.pop();
|
|
434
|
+
var procedureType = clientCallTypeMap[clientCallType];
|
|
434
435
|
var fullPath = pathCopy.join('.');
|
|
435
|
-
return (_ref2 = client)[
|
|
436
|
+
return (_ref2 = client)[procedureType].apply(_ref2, [fullPath].concat(_toConsumableArray__default["default"](args)));
|
|
436
437
|
});
|
|
437
438
|
return proxy;
|
|
438
439
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -408,6 +408,11 @@ function createTRPCClient(opts) {
|
|
|
408
408
|
return client;
|
|
409
409
|
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
410
410
|
|
|
411
|
+
var clientCallTypeMap = {
|
|
412
|
+
query: 'query',
|
|
413
|
+
mutate: 'mutation',
|
|
414
|
+
subscribe: 'subscription'
|
|
415
|
+
};
|
|
411
416
|
function createTRPCClientProxy(client) {
|
|
412
417
|
var proxy = createProxy(function (_ref) {
|
|
413
418
|
var _ref2;
|
|
@@ -417,14 +422,10 @@ function createTRPCClientProxy(client) {
|
|
|
417
422
|
|
|
418
423
|
var pathCopy = _toConsumableArray(path);
|
|
419
424
|
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
if (type === 'mutate') {
|
|
423
|
-
type = 'mutation';
|
|
424
|
-
}
|
|
425
|
-
|
|
425
|
+
var clientCallType = pathCopy.pop();
|
|
426
|
+
var procedureType = clientCallTypeMap[clientCallType];
|
|
426
427
|
var fullPath = pathCopy.join('.');
|
|
427
|
-
return (_ref2 = client)[
|
|
428
|
+
return (_ref2 = client)[procedureType].apply(_ref2, [fullPath].concat(_toConsumableArray(args)));
|
|
428
429
|
});
|
|
429
430
|
return proxy;
|
|
430
431
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.40",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"@babel/runtime": "^7.9.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@trpc/server": "10.0.0-alpha.
|
|
70
|
+
"@trpc/server": "10.0.0-alpha.40"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@trpc/server": "10.0.0-alpha.
|
|
73
|
+
"@trpc/server": "10.0.0-alpha.40"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "2af7a0070f3bc01b81fe6f14f591e77c549520a7"
|
|
79
79
|
}
|
|
@@ -1,17 +1,47 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
AnyRouter,
|
|
6
|
+
OmitNeverKeys,
|
|
7
|
+
Procedure,
|
|
8
|
+
ProcedureArgs,
|
|
9
|
+
ProcedureRouterRecord,
|
|
10
|
+
ProcedureType,
|
|
11
|
+
inferProcedureOutput,
|
|
12
|
+
} from '@trpc/server';
|
|
5
13
|
import { createProxy } from '@trpc/server/shared';
|
|
6
14
|
import { TRPCClient as Client } from './internals/TRPCClient';
|
|
7
15
|
|
|
16
|
+
type Resolver<TProcedure extends Procedure<any>> = (
|
|
17
|
+
...args: ProcedureArgs<TProcedure['_def']>
|
|
18
|
+
) => Promise<inferProcedureOutput<TProcedure>>;
|
|
19
|
+
|
|
20
|
+
type DecorateProcedure<TProcedure extends Procedure<any>> = OmitNeverKeys<{
|
|
21
|
+
query: TProcedure extends { _query: true } ? Resolver<TProcedure> : never;
|
|
22
|
+
|
|
23
|
+
mutate: TProcedure extends { _mutation: true } ? Resolver<TProcedure> : never;
|
|
24
|
+
|
|
25
|
+
subscribe: TProcedure extends { _subscription: true }
|
|
26
|
+
? Resolver<TProcedure>
|
|
27
|
+
: never;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
type assertProcedure<T> = T extends Procedure<any> ? T : never;
|
|
31
|
+
|
|
8
32
|
/**
|
|
9
33
|
* @internal
|
|
10
34
|
*/
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
?
|
|
14
|
-
:
|
|
35
|
+
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
36
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
37
|
+
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
38
|
+
: DecorateProcedure<assertProcedure<TProcedures[TKey]>>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const clientCallTypeMap: Record<keyof DecorateProcedure<any>, ProcedureType> = {
|
|
42
|
+
query: 'query',
|
|
43
|
+
mutate: 'mutation',
|
|
44
|
+
subscribe: 'subscription',
|
|
15
45
|
};
|
|
16
46
|
|
|
17
47
|
export function createTRPCClientProxy<TRouter extends AnyRouter>(
|
|
@@ -19,12 +49,11 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
|
|
|
19
49
|
) {
|
|
20
50
|
const proxy = createProxy(({ path, args }) => {
|
|
21
51
|
const pathCopy = [...path];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
52
|
+
const clientCallType = pathCopy.pop()! as keyof DecorateProcedure<any>;
|
|
53
|
+
const procedureType = clientCallTypeMap[clientCallType];
|
|
54
|
+
|
|
26
55
|
const fullPath = pathCopy.join('.');
|
|
27
|
-
return (client as any)[
|
|
56
|
+
return (client as any)[procedureType](fullPath, ...args);
|
|
28
57
|
});
|
|
29
|
-
return proxy as
|
|
58
|
+
return proxy as DecoratedProcedureRecord<TRouter['_def']['record']>;
|
|
30
59
|
}
|