@trpc/client 10.0.0-alpha.45 → 10.0.0-alpha.46
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/httpUtils-44781613.mjs +76 -0
- package/dist/httpUtils-801112a6.js +79 -0
- package/dist/index.js +226 -337
- package/dist/index.mjs +228 -333
- package/dist/internals/TRPCClient.d.ts +3 -1
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/internals/fetchHelpers.d.ts.map +1 -1
- package/dist/internals/retryDelay.d.ts.map +1 -1
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +182 -304
- package/dist/links/httpBatchLink.mjs +182 -304
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +30 -53
- package/dist/links/httpLink.mjs +30 -53
- package/dist/links/index.d.ts.map +1 -1
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/transformResult.d.ts.map +1 -1
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +89 -94
- package/dist/links/loggerLink.mjs +89 -89
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +248 -379
- package/dist/links/wsLink.mjs +248 -368
- package/dist/splitLink-695ae288.js +48 -0
- package/dist/splitLink-ad44a55d.mjs +45 -0
- package/dist/transformResult-106791d7.mjs +62 -0
- package/dist/transformResult-e15ccdf6.js +65 -0
- package/links/httpBatchLink/index.d.ts +1 -1
- package/links/httpBatchLink/index.js +1 -1
- package/links/httpLink/index.d.ts +1 -1
- package/links/httpLink/index.js +1 -1
- package/links/loggerLink/index.d.ts +1 -1
- package/links/loggerLink/index.js +1 -1
- package/links/splitLink/index.d.ts +1 -1
- package/links/splitLink/index.js +1 -1
- package/links/wsLink/index.d.ts +1 -1
- package/links/wsLink/index.js +1 -1
- package/package.json +7 -11
- package/src/internals/TRPCClient.ts +10 -9
- package/src/links/wsLink.ts +1 -1
- package/dist/httpUtils-089853f6.mjs +0 -99
- package/dist/httpUtils-a0169eef.js +0 -106
- package/dist/index.ts.js +0 -1
- package/dist/links/httpBatchLink.ts.js +0 -1
- package/dist/links/httpLink.ts.js +0 -1
- package/dist/links/loggerLink.ts.js +0 -1
- package/dist/links/splitLink.ts.js +0 -1
- package/dist/links/wsLink.ts.js +0 -1
- package/dist/splitLink-0202cd7b.mjs +0 -54
- package/dist/splitLink-23c5ce5c.js +0 -57
- package/dist/transformResult-06bec648.mjs +0 -108
- package/dist/transformResult-3ccc74ea.js +0 -122
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var observable = require('@trpc/server/observable');
|
|
4
|
+
|
|
5
|
+
/** @internal */ function createChain(opts) {
|
|
6
|
+
return observable.observable((observer)=>{
|
|
7
|
+
function execute(index = 0, op = opts.op) {
|
|
8
|
+
const next = opts.links[index];
|
|
9
|
+
if (!next) {
|
|
10
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
11
|
+
}
|
|
12
|
+
const subscription = next({
|
|
13
|
+
op,
|
|
14
|
+
next (nextOp) {
|
|
15
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
16
|
+
return nextObserver;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return subscription;
|
|
20
|
+
}
|
|
21
|
+
const obs$ = execute();
|
|
22
|
+
return obs$.subscribe(observer);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function asArray(value) {
|
|
27
|
+
return Array.isArray(value) ? value : [
|
|
28
|
+
value
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
function splitLink(opts) {
|
|
32
|
+
return (runtime)=>{
|
|
33
|
+
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
34
|
+
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
35
|
+
return (props)=>{
|
|
36
|
+
return observable.observable((observer)=>{
|
|
37
|
+
const links = opts.condition(props.op) ? yes : no;
|
|
38
|
+
return createChain({
|
|
39
|
+
op: props.op,
|
|
40
|
+
links
|
|
41
|
+
}).subscribe(observer);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.createChain = createChain;
|
|
48
|
+
exports.splitLink = splitLink;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { observable } from '@trpc/server/observable';
|
|
2
|
+
|
|
3
|
+
/** @internal */ function createChain(opts) {
|
|
4
|
+
return observable((observer)=>{
|
|
5
|
+
function execute(index = 0, op = opts.op) {
|
|
6
|
+
const next = opts.links[index];
|
|
7
|
+
if (!next) {
|
|
8
|
+
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
9
|
+
}
|
|
10
|
+
const subscription = next({
|
|
11
|
+
op,
|
|
12
|
+
next (nextOp) {
|
|
13
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
14
|
+
return nextObserver;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return subscription;
|
|
18
|
+
}
|
|
19
|
+
const obs$ = execute();
|
|
20
|
+
return obs$.subscribe(observer);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function asArray(value) {
|
|
25
|
+
return Array.isArray(value) ? value : [
|
|
26
|
+
value
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
function splitLink(opts) {
|
|
30
|
+
return (runtime)=>{
|
|
31
|
+
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
32
|
+
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
33
|
+
return (props)=>{
|
|
34
|
+
return observable((observer)=>{
|
|
35
|
+
const links = opts.condition(props.op) ? yes : no;
|
|
36
|
+
return createChain({
|
|
37
|
+
op: props.op,
|
|
38
|
+
links
|
|
39
|
+
}).subscribe(observer);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { createChain as c, splitLink as s };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
class TRPCClientError extends Error {
|
|
2
|
+
static from(cause, opts = {}) {
|
|
3
|
+
if (!(cause instanceof Error)) {
|
|
4
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
5
|
+
...opts,
|
|
6
|
+
cause: undefined,
|
|
7
|
+
result: cause
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
if (cause.name === 'TRPCClientError') {
|
|
11
|
+
return cause;
|
|
12
|
+
}
|
|
13
|
+
return new TRPCClientError(cause.message, {
|
|
14
|
+
...opts,
|
|
15
|
+
cause,
|
|
16
|
+
result: null
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
constructor(message, opts){
|
|
20
|
+
const cause = opts?.cause;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
23
|
+
super(message, {
|
|
24
|
+
cause
|
|
25
|
+
});
|
|
26
|
+
this.meta = opts?.meta;
|
|
27
|
+
this.cause = cause;
|
|
28
|
+
this.shape = opts?.result?.error;
|
|
29
|
+
this.data = opts?.result?.error.data;
|
|
30
|
+
this.name = 'TRPCClientError';
|
|
31
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// FIXME:
|
|
36
|
+
// - the generics here are probably unnecessary
|
|
37
|
+
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
38
|
+
/** @internal */ function transformResult(response, runtime) {
|
|
39
|
+
if ('error' in response) {
|
|
40
|
+
const error = runtime.transformer.deserialize(response.error);
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: {
|
|
44
|
+
...response,
|
|
45
|
+
error
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const result = {
|
|
50
|
+
...response.result,
|
|
51
|
+
...(!response.result.type || response.result.type === 'data') && {
|
|
52
|
+
type: 'data',
|
|
53
|
+
data: runtime.transformer.deserialize(response.result.data)
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
result
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { TRPCClientError as T, transformResult as t };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class TRPCClientError extends Error {
|
|
4
|
+
static from(cause, opts = {}) {
|
|
5
|
+
if (!(cause instanceof Error)) {
|
|
6
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
7
|
+
...opts,
|
|
8
|
+
cause: undefined,
|
|
9
|
+
result: cause
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
if (cause.name === 'TRPCClientError') {
|
|
13
|
+
return cause;
|
|
14
|
+
}
|
|
15
|
+
return new TRPCClientError(cause.message, {
|
|
16
|
+
...opts,
|
|
17
|
+
cause,
|
|
18
|
+
result: null
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
constructor(message, opts){
|
|
22
|
+
const cause = opts?.cause;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
25
|
+
super(message, {
|
|
26
|
+
cause
|
|
27
|
+
});
|
|
28
|
+
this.meta = opts?.meta;
|
|
29
|
+
this.cause = cause;
|
|
30
|
+
this.shape = opts?.result?.error;
|
|
31
|
+
this.data = opts?.result?.error.data;
|
|
32
|
+
this.name = 'TRPCClientError';
|
|
33
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// FIXME:
|
|
38
|
+
// - the generics here are probably unnecessary
|
|
39
|
+
// - the RPC-spec could probably be simplified to combine HTTP + WS
|
|
40
|
+
/** @internal */ function transformResult(response, runtime) {
|
|
41
|
+
if ('error' in response) {
|
|
42
|
+
const error = runtime.transformer.deserialize(response.error);
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
error: {
|
|
46
|
+
...response,
|
|
47
|
+
error
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const result = {
|
|
52
|
+
...response.result,
|
|
53
|
+
...(!response.result.type || response.result.type === 'data') && {
|
|
54
|
+
type: 'data',
|
|
55
|
+
data: runtime.transformer.deserialize(response.result.data)
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
result
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.TRPCClientError = TRPCClientError;
|
|
65
|
+
exports.transformResult = transformResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist
|
|
1
|
+
export * from '../../dist/links/httpBatchLink';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../dist
|
|
1
|
+
module.exports = require('../../dist/links/httpBatchLink');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist
|
|
1
|
+
export * from '../../dist/links/httpLink';
|
package/links/httpLink/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../dist
|
|
1
|
+
module.exports = require('../../dist/links/httpLink');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist
|
|
1
|
+
export * from '../../dist/links/loggerLink';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../dist
|
|
1
|
+
module.exports = require('../../dist/links/loggerLink');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist
|
|
1
|
+
export * from '../../dist/links/splitLink';
|
package/links/splitLink/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../dist
|
|
1
|
+
module.exports = require('../../dist/links/splitLink');
|
package/links/wsLink/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist
|
|
1
|
+
export * from '../../dist/links/wsLink';
|
package/links/wsLink/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../dist
|
|
1
|
+
module.exports = require('../../dist/links/wsLink');
|
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.46",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,26 +54,22 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"files": [
|
|
57
|
-
"README.md",
|
|
58
57
|
"dist",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
58
|
+
"src",
|
|
59
|
+
"README.md",
|
|
60
|
+
"links"
|
|
61
61
|
],
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "rollup -c",
|
|
64
63
|
"ts-watch": "tsc --project tsconfig.watch.json"
|
|
65
64
|
},
|
|
66
|
-
"dependencies": {
|
|
67
|
-
"@babel/runtime": "^7.9.0"
|
|
68
|
-
},
|
|
69
65
|
"peerDependencies": {
|
|
70
|
-
"@trpc/server": "10.0.0-alpha.
|
|
66
|
+
"@trpc/server": "10.0.0-alpha.46"
|
|
71
67
|
},
|
|
72
68
|
"devDependencies": {
|
|
73
|
-
"@trpc/server": "10.0.0-alpha.
|
|
69
|
+
"@trpc/server": "10.0.0-alpha.46"
|
|
74
70
|
},
|
|
75
71
|
"publishConfig": {
|
|
76
72
|
"access": "public"
|
|
77
73
|
},
|
|
78
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "1dc2d31cafc22c6303445aa33d526fbd848ca141"
|
|
79
75
|
}
|
|
@@ -32,10 +32,6 @@ type CancellablePromise<T = unknown> = Promise<T> & {
|
|
|
32
32
|
cancel: CancelFn;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
let idCounter = 0;
|
|
36
|
-
function getRequestId() {
|
|
37
|
-
return ++idCounter;
|
|
38
|
-
}
|
|
39
35
|
interface CreateTRPCClientBaseOptions {
|
|
40
36
|
/**
|
|
41
37
|
* Add ponyfill for fetch
|
|
@@ -79,7 +75,7 @@ export interface TRPCRequestOptions {
|
|
|
79
75
|
/**
|
|
80
76
|
* Pass additional context to links
|
|
81
77
|
*/
|
|
82
|
-
|
|
78
|
+
context?: OperationContext;
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
export interface TRPCSubscriptionObserver<TValue, TError> {
|
|
@@ -114,10 +110,15 @@ export type AssertLegacyDef<TRouter extends AnyRouter> =
|
|
|
114
110
|
export class TRPCClient<TRouter extends AnyRouter> {
|
|
115
111
|
private readonly links: OperationLink<TRouter>[];
|
|
116
112
|
public readonly runtime: TRPCClientRuntime;
|
|
113
|
+
private requestId: number;
|
|
114
|
+
private getRequestId() {
|
|
115
|
+
return ++this.requestId;
|
|
116
|
+
}
|
|
117
117
|
|
|
118
118
|
constructor(opts: CreateTRPCClientOptions<TRouter>) {
|
|
119
119
|
const _fetch = getFetch(opts?.fetch);
|
|
120
120
|
const AC = getAbortController(opts?.AbortController);
|
|
121
|
+
this.requestId = 0;
|
|
121
122
|
|
|
122
123
|
function getHeadersFn(): TRPCClientRuntime['headers'] {
|
|
123
124
|
if (opts.headers) {
|
|
@@ -171,7 +172,7 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
171
172
|
const chain$ = createChain<TRouter, TInput, TOutput>({
|
|
172
173
|
links: this.links as OperationLink<any, any, any>[],
|
|
173
174
|
op: {
|
|
174
|
-
id: getRequestId(),
|
|
175
|
+
id: this.getRequestId(),
|
|
175
176
|
type,
|
|
176
177
|
path,
|
|
177
178
|
input,
|
|
@@ -215,7 +216,7 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
215
216
|
TRPCRequestOptions?,
|
|
216
217
|
]
|
|
217
218
|
) {
|
|
218
|
-
const context = (args[1] as TRPCRequestOptions | undefined)?.
|
|
219
|
+
const context = (args[1] as TRPCRequestOptions | undefined)?.context;
|
|
219
220
|
return this.requestAsPromise<
|
|
220
221
|
inferHandlerInput<AssertType<TQueries, ProcedureRecord>[TPath]>,
|
|
221
222
|
inferProcedureOutput<TQueries[TPath]>
|
|
@@ -236,7 +237,7 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
236
237
|
TRPCRequestOptions?,
|
|
237
238
|
]
|
|
238
239
|
) {
|
|
239
|
-
const context = (args[1] as TRPCRequestOptions | undefined)?.
|
|
240
|
+
const context = (args[1] as TRPCRequestOptions | undefined)?.context;
|
|
240
241
|
return this.requestAsPromise<
|
|
241
242
|
inferHandlerInput<AssertType<TMutations, ProcedureRecord>[TPath]>,
|
|
242
243
|
inferProcedureOutput<TMutations[TPath]>
|
|
@@ -264,7 +265,7 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
264
265
|
type: 'subscription',
|
|
265
266
|
path,
|
|
266
267
|
input,
|
|
267
|
-
context: opts
|
|
268
|
+
context: opts?.context,
|
|
268
269
|
});
|
|
269
270
|
return observable$.subscribe({
|
|
270
271
|
next(envelope) {
|
package/src/links/wsLink.ts
CHANGED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
// https://github.com/trpc/trpc/pull/669
|
|
8
|
-
function arrayToDict(array) {
|
|
9
|
-
var dict = {};
|
|
10
|
-
|
|
11
|
-
for (var index = 0; index < array.length; index++) {
|
|
12
|
-
var element = array[index];
|
|
13
|
-
dict[index] = element;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return dict;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var METHOD = {
|
|
20
|
-
query: 'GET',
|
|
21
|
-
mutation: 'POST',
|
|
22
|
-
subscription: 'PATCH'
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function getInput(opts) {
|
|
26
|
-
return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map(function (_input) {
|
|
27
|
-
return opts.runtime.transformer.serialize(_input);
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getUrl(opts) {
|
|
32
|
-
var url = opts.url + '/' + opts.path;
|
|
33
|
-
var queryParts = [];
|
|
34
|
-
|
|
35
|
-
if ('inputs' in opts) {
|
|
36
|
-
queryParts.push('batch=1');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (opts.type === 'query') {
|
|
40
|
-
var input = getInput(opts);
|
|
41
|
-
|
|
42
|
-
if (input !== undefined) {
|
|
43
|
-
queryParts.push("input=".concat(encodeURIComponent(JSON.stringify(input))));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (queryParts.length) {
|
|
48
|
-
url += '?' + queryParts.join('&');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return url;
|
|
52
|
-
}
|
|
53
|
-
function getBody(opts) {
|
|
54
|
-
if (opts.type === 'query') {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var input = getInput(opts);
|
|
59
|
-
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
60
|
-
}
|
|
61
|
-
function httpRequest(opts) {
|
|
62
|
-
var type = opts.type,
|
|
63
|
-
runtime = opts.runtime;
|
|
64
|
-
var ac = runtime.AbortController ? new runtime.AbortController() : null;
|
|
65
|
-
var promise = new Promise(function (resolve, reject) {
|
|
66
|
-
var url = getUrl(opts);
|
|
67
|
-
var body = getBody(opts);
|
|
68
|
-
var meta = {};
|
|
69
|
-
Promise.resolve(runtime.headers()).then(function (headers) {
|
|
70
|
-
return runtime.fetch(url, {
|
|
71
|
-
method: METHOD[type],
|
|
72
|
-
signal: ac === null || ac === void 0 ? void 0 : ac.signal,
|
|
73
|
-
body: body,
|
|
74
|
-
headers: _objectSpread({
|
|
75
|
-
'content-type': 'application/json'
|
|
76
|
-
}, headers)
|
|
77
|
-
});
|
|
78
|
-
}).then(function (_res) {
|
|
79
|
-
meta.response = _res;
|
|
80
|
-
return _res.json();
|
|
81
|
-
}).then(function (json) {
|
|
82
|
-
resolve({
|
|
83
|
-
json: json,
|
|
84
|
-
meta: meta
|
|
85
|
-
});
|
|
86
|
-
}).catch(reject);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
var cancel = function cancel() {
|
|
90
|
-
ac === null || ac === void 0 ? void 0 : ac.abort();
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
promise: promise,
|
|
95
|
-
cancel: cancel
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export { getUrl as g, httpRequest as h };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
-
|
|
5
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
-
|
|
7
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
8
|
-
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
|
|
11
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
|
|
13
|
-
// https://github.com/trpc/trpc/pull/669
|
|
14
|
-
function arrayToDict(array) {
|
|
15
|
-
var dict = {};
|
|
16
|
-
|
|
17
|
-
for (var index = 0; index < array.length; index++) {
|
|
18
|
-
var element = array[index];
|
|
19
|
-
dict[index] = element;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return dict;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var METHOD = {
|
|
26
|
-
query: 'GET',
|
|
27
|
-
mutation: 'POST',
|
|
28
|
-
subscription: 'PATCH'
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function getInput(opts) {
|
|
32
|
-
return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map(function (_input) {
|
|
33
|
-
return opts.runtime.transformer.serialize(_input);
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getUrl(opts) {
|
|
38
|
-
var url = opts.url + '/' + opts.path;
|
|
39
|
-
var queryParts = [];
|
|
40
|
-
|
|
41
|
-
if ('inputs' in opts) {
|
|
42
|
-
queryParts.push('batch=1');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (opts.type === 'query') {
|
|
46
|
-
var input = getInput(opts);
|
|
47
|
-
|
|
48
|
-
if (input !== undefined) {
|
|
49
|
-
queryParts.push("input=".concat(encodeURIComponent(JSON.stringify(input))));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (queryParts.length) {
|
|
54
|
-
url += '?' + queryParts.join('&');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return url;
|
|
58
|
-
}
|
|
59
|
-
function getBody(opts) {
|
|
60
|
-
if (opts.type === 'query') {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
var input = getInput(opts);
|
|
65
|
-
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
66
|
-
}
|
|
67
|
-
function httpRequest(opts) {
|
|
68
|
-
var type = opts.type,
|
|
69
|
-
runtime = opts.runtime;
|
|
70
|
-
var ac = runtime.AbortController ? new runtime.AbortController() : null;
|
|
71
|
-
var promise = new Promise(function (resolve, reject) {
|
|
72
|
-
var url = getUrl(opts);
|
|
73
|
-
var body = getBody(opts);
|
|
74
|
-
var meta = {};
|
|
75
|
-
Promise.resolve(runtime.headers()).then(function (headers) {
|
|
76
|
-
return runtime.fetch(url, {
|
|
77
|
-
method: METHOD[type],
|
|
78
|
-
signal: ac === null || ac === void 0 ? void 0 : ac.signal,
|
|
79
|
-
body: body,
|
|
80
|
-
headers: _objectSpread({
|
|
81
|
-
'content-type': 'application/json'
|
|
82
|
-
}, headers)
|
|
83
|
-
});
|
|
84
|
-
}).then(function (_res) {
|
|
85
|
-
meta.response = _res;
|
|
86
|
-
return _res.json();
|
|
87
|
-
}).then(function (json) {
|
|
88
|
-
resolve({
|
|
89
|
-
json: json,
|
|
90
|
-
meta: meta
|
|
91
|
-
});
|
|
92
|
-
}).catch(reject);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
var cancel = function cancel() {
|
|
96
|
-
ac === null || ac === void 0 ? void 0 : ac.abort();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
promise: promise,
|
|
101
|
-
cancel: cancel
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.getUrl = getUrl;
|
|
106
|
-
exports.httpRequest = httpRequest;
|
package/dist/index.ts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/links/wsLink.ts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { observable } from '@trpc/server/observable';
|
|
2
|
-
|
|
3
|
-
/** @internal */
|
|
4
|
-
function createChain(opts) {
|
|
5
|
-
return observable(function (observer) {
|
|
6
|
-
function execute() {
|
|
7
|
-
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
8
|
-
var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : opts.op;
|
|
9
|
-
var next = opts.links[index];
|
|
10
|
-
|
|
11
|
-
if (!next) {
|
|
12
|
-
throw new Error('No more links to execute - did you forget to add an ending link?');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
var subscription = next({
|
|
16
|
-
op: op,
|
|
17
|
-
next: function next(nextOp) {
|
|
18
|
-
var nextObserver = execute(index + 1, nextOp);
|
|
19
|
-
return nextObserver;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return subscription;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var obs$ = execute();
|
|
26
|
-
return obs$.subscribe(observer);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function asArray(value) {
|
|
31
|
-
return Array.isArray(value) ? value : [value];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function splitLink(opts) {
|
|
35
|
-
return function (runtime) {
|
|
36
|
-
var yes = asArray(opts.true).map(function (link) {
|
|
37
|
-
return link(runtime);
|
|
38
|
-
});
|
|
39
|
-
var no = asArray(opts.false).map(function (link) {
|
|
40
|
-
return link(runtime);
|
|
41
|
-
});
|
|
42
|
-
return function (props) {
|
|
43
|
-
return observable(function (observer) {
|
|
44
|
-
var links = opts.condition(props.op) ? yes : no;
|
|
45
|
-
return createChain({
|
|
46
|
-
op: props.op,
|
|
47
|
-
links: links
|
|
48
|
-
}).subscribe(observer);
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { createChain as c, splitLink as s };
|