@trpc/client 11.0.0-rc.413 → 11.0.0-rc.419

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.
Files changed (46) hide show
  1. package/dist/bundle-analysis.json +55 -40
  2. package/dist/createTRPCClient.d.ts.map +1 -1
  3. package/dist/createTRPCClient.js +9 -9
  4. package/dist/createTRPCClient.mjs +10 -10
  5. package/dist/index.js +2 -0
  6. package/dist/index.mjs +1 -0
  7. package/dist/internals/TRPCUntypedClient.d.ts +3 -1
  8. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  9. package/dist/internals/TRPCUntypedClient.js +3 -1
  10. package/dist/internals/TRPCUntypedClient.mjs +3 -1
  11. package/dist/internals/dataLoader.d.ts.map +1 -1
  12. package/dist/links/httpBatchLink.d.ts.map +1 -1
  13. package/dist/links/httpBatchLink.js +3 -2
  14. package/dist/links/httpBatchLink.mjs +3 -2
  15. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  16. package/dist/links/httpBatchStreamLink.js +5 -6
  17. package/dist/links/httpBatchStreamLink.mjs +5 -6
  18. package/dist/links/httpLink.d.ts +2 -2
  19. package/dist/links/httpLink.d.ts.map +1 -1
  20. package/dist/links/httpLink.js +3 -0
  21. package/dist/links/httpLink.mjs +3 -0
  22. package/dist/links/httpSubscriptionLink.d.ts +19 -0
  23. package/dist/links/httpSubscriptionLink.d.ts.map +1 -0
  24. package/dist/links/httpSubscriptionLink.js +87 -0
  25. package/dist/links/httpSubscriptionLink.mjs +85 -0
  26. package/dist/links/internals/contentTypes.d.ts +3 -3
  27. package/dist/links/internals/contentTypes.d.ts.map +1 -1
  28. package/dist/links/internals/httpUtils.d.ts +4 -4
  29. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  30. package/dist/links/internals/httpUtils.js +6 -7
  31. package/dist/links/internals/httpUtils.mjs +6 -7
  32. package/dist/links/loggerLink.d.ts +0 -1
  33. package/dist/links/loggerLink.d.ts.map +1 -1
  34. package/dist/links/wsLink.d.ts +4 -4
  35. package/dist/links/wsLink.d.ts.map +1 -1
  36. package/dist/links.d.ts +1 -0
  37. package/dist/links.d.ts.map +1 -1
  38. package/package.json +4 -4
  39. package/src/createTRPCClient.ts +11 -8
  40. package/src/internals/TRPCUntypedClient.ts +4 -2
  41. package/src/links/httpBatchLink.ts +8 -5
  42. package/src/links/httpBatchStreamLink.ts +10 -7
  43. package/src/links/httpLink.ts +8 -2
  44. package/src/links/httpSubscriptionLink.ts +121 -0
  45. package/src/links/internals/httpUtils.ts +10 -11
  46. package/src/links.ts +1 -0
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var observable = require('@trpc/server/observable');
4
+ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
+ var TRPCClientError = require('../TRPCClientError.js');
6
+ var transformer = require('../internals/transformer.js');
7
+ var httpUtils = require('./internals/httpUtils.js');
8
+
9
+ /**
10
+ * Get the result of a value or function that returns a value
11
+ */ const resultOf = (value)=>{
12
+ return typeof value === 'function' ? value() : value;
13
+ };
14
+ /**
15
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
16
+ */ function unstable_httpSubscriptionLink(opts) {
17
+ const transformer$1 = transformer.getTransformer(opts.transformer);
18
+ return ()=>{
19
+ return ({ op })=>{
20
+ return observable.observable((observer)=>{
21
+ const { type , path , input } = op;
22
+ /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
23
+ throw new Error('httpSubscriptionLink only supports subscriptions');
24
+ }
25
+ let eventSource = null;
26
+ let unsubscribed = false;
27
+ unstableCoreDoNotImport.run(async ()=>{
28
+ const url = httpUtils.getUrl({
29
+ transformer: transformer$1,
30
+ url: await resultOf(opts.url),
31
+ input,
32
+ path,
33
+ type,
34
+ AbortController: null
35
+ });
36
+ /* istanbul ignore if -- @preserve */ if (unsubscribed) {
37
+ // already unsubscribed - rare race condition
38
+ return;
39
+ }
40
+ eventSource = new EventSource(url, opts.eventSourceOptions);
41
+ const onStarted = ()=>{
42
+ observer.next({
43
+ result: {
44
+ type: 'started'
45
+ },
46
+ context: {
47
+ eventSource
48
+ }
49
+ });
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
+ eventSource.removeEventListener('open', onStarted);
52
+ };
53
+ // console.log('starting', new Date());
54
+ eventSource.addEventListener('open', onStarted);
55
+ const iterable = unstableCoreDoNotImport.sseStreamConsumer({
56
+ from: eventSource,
57
+ deserialize: transformer$1.input.deserialize
58
+ });
59
+ for await (const chunk of iterable){
60
+ // if the `sse({})`-helper is used, we always have an `id` field
61
+ const data = 'id' in chunk ? chunk : chunk.data;
62
+ observer.next({
63
+ result: {
64
+ data
65
+ }
66
+ });
67
+ }
68
+ observer.next({
69
+ result: {
70
+ type: 'stopped'
71
+ }
72
+ });
73
+ observer.complete();
74
+ }).catch((error)=>{
75
+ observer.error(TRPCClientError.TRPCClientError.from(error));
76
+ });
77
+ return ()=>{
78
+ observer.complete();
79
+ eventSource?.close();
80
+ unsubscribed = true;
81
+ };
82
+ });
83
+ };
84
+ };
85
+ }
86
+
87
+ exports.unstable_httpSubscriptionLink = unstable_httpSubscriptionLink;
@@ -0,0 +1,85 @@
1
+ import { observable } from '@trpc/server/observable';
2
+ import { run, sseStreamConsumer } from '@trpc/server/unstable-core-do-not-import';
3
+ import { TRPCClientError } from '../TRPCClientError.mjs';
4
+ import { getTransformer } from '../internals/transformer.mjs';
5
+ import { getUrl } from './internals/httpUtils.mjs';
6
+
7
+ /**
8
+ * Get the result of a value or function that returns a value
9
+ */ const resultOf = (value)=>{
10
+ return typeof value === 'function' ? value() : value;
11
+ };
12
+ /**
13
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
14
+ */ function unstable_httpSubscriptionLink(opts) {
15
+ const transformer = getTransformer(opts.transformer);
16
+ return ()=>{
17
+ return ({ op })=>{
18
+ return observable((observer)=>{
19
+ const { type , path , input } = op;
20
+ /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
21
+ throw new Error('httpSubscriptionLink only supports subscriptions');
22
+ }
23
+ let eventSource = null;
24
+ let unsubscribed = false;
25
+ run(async ()=>{
26
+ const url = getUrl({
27
+ transformer,
28
+ url: await resultOf(opts.url),
29
+ input,
30
+ path,
31
+ type,
32
+ AbortController: null
33
+ });
34
+ /* istanbul ignore if -- @preserve */ if (unsubscribed) {
35
+ // already unsubscribed - rare race condition
36
+ return;
37
+ }
38
+ eventSource = new EventSource(url, opts.eventSourceOptions);
39
+ const onStarted = ()=>{
40
+ observer.next({
41
+ result: {
42
+ type: 'started'
43
+ },
44
+ context: {
45
+ eventSource
46
+ }
47
+ });
48
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
+ eventSource.removeEventListener('open', onStarted);
50
+ };
51
+ // console.log('starting', new Date());
52
+ eventSource.addEventListener('open', onStarted);
53
+ const iterable = sseStreamConsumer({
54
+ from: eventSource,
55
+ deserialize: transformer.input.deserialize
56
+ });
57
+ for await (const chunk of iterable){
58
+ // if the `sse({})`-helper is used, we always have an `id` field
59
+ const data = 'id' in chunk ? chunk : chunk.data;
60
+ observer.next({
61
+ result: {
62
+ data
63
+ }
64
+ });
65
+ }
66
+ observer.next({
67
+ result: {
68
+ type: 'stopped'
69
+ }
70
+ });
71
+ observer.complete();
72
+ }).catch((error)=>{
73
+ observer.error(TRPCClientError.from(error));
74
+ });
75
+ return ()=>{
76
+ observer.complete();
77
+ eventSource?.close();
78
+ unsubscribed = true;
79
+ };
80
+ });
81
+ };
82
+ };
83
+ }
84
+
85
+ export { unstable_httpSubscriptionLink };
@@ -1,4 +1,4 @@
1
- export declare function isOctetType(input: unknown): boolean;
2
- export declare function isFormData(input: unknown): boolean;
3
- export declare function isNonJsonSerializable(input: unknown): boolean;
1
+ export declare function isOctetType(input: unknown): input is Uint8Array | Blob;
2
+ export declare function isFormData(input: unknown): input is FormData;
3
+ export declare function isNonJsonSerializable(input: unknown): input is Uint8Array | Blob | FormData;
4
4
  //# sourceMappingURL=contentTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contentTypes.d.ts","sourceRoot":"","sources":["../../../src/links/internals/contentTypes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,WAMzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,WAExC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,WAEnD"}
1
+ {"version":3,"file":"contentTypes.d.ts","sourceRoot":"","sources":["../../../src/links/internals/contentTypes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,8BAMzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,qBAExC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,yCAEnD"}
@@ -1,11 +1,11 @@
1
- import type { AnyRootTypes, CombinedDataTransformer, ProcedureType, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
1
+ import type { AnyClientTypes, CombinedDataTransformer, ProcedureType, TRPCAcceptHeader, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
2
2
  import type { AbortControllerEsque, AbortControllerInstanceEsque, FetchEsque, RequestInitEsque, ResponseEsque } from '../../internals/types';
3
3
  import type { TransformerOptions } from '../../unstable-internals';
4
4
  import type { HTTPHeaders, PromiseAndCancel } from '../types';
5
5
  /**
6
6
  * @internal
7
7
  */
8
- export type HTTPLinkBaseOptions<TRoot extends Pick<AnyRootTypes, 'transformer'>> = {
8
+ export type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
9
9
  url: string | URL;
10
10
  /**
11
11
  * Add ponyfill for fetch
@@ -29,7 +29,7 @@ export interface ResolvedHTTPLinkOptions {
29
29
  transformer: CombinedDataTransformer;
30
30
  methodOverride?: 'POST';
31
31
  }
32
- export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions<AnyRootTypes>): ResolvedHTTPLinkOptions;
32
+ export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions<AnyClientTypes>): ResolvedHTTPLinkOptions;
33
33
  export interface HTTPResult {
34
34
  json: TRPCResponse;
35
35
  meta: {
@@ -52,7 +52,7 @@ export type HTTPBaseRequestOptions = GetInputOptions & ResolvedHTTPLinkOptions &
52
52
  type GetUrl = (opts: HTTPBaseRequestOptions) => string;
53
53
  type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
54
54
  export type ContentOptions = {
55
- trpcAcceptHeader?: 'application/jsonl';
55
+ trpcAcceptHeader?: TRPCAcceptHeader;
56
56
  contentTypeHeader?: string;
57
57
  getUrl: GetUrl;
58
58
  getBody: GetBody;
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,YAAY,EACb,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC5B,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,IAC7C;IACF,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC9C;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MA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,MAAM,EAAE,MAiBpB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAMrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,sBAAsB,GAAG;IAC7B,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,KACE,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAElC,eAAO,MAAM,iBAAiB,EAAE,SAO/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAC7C,sBAAsB,GAAG;IACvB,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,CAAC;AAEJ,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,EACxB,EAAE,CAAC,EAAE,4BAA4B,GAAG,IAAI,0BA4BzC;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CA8B9B"}
@@ -7,7 +7,7 @@ var transformer = require('../../internals/transformer.js');
7
7
 
8
8
  function resolveHTTPLinkOptions(opts) {
9
9
  return {
10
- url: opts.url.toString().replace(/\/$/, ''),
10
+ url: opts.url.toString(),
11
11
  fetch: opts.fetch,
12
12
  AbortController: getAbortController.getAbortController(opts.AbortController),
13
13
  transformer: transformer.getTransformer(opts.transformer),
@@ -25,18 +25,20 @@ function arrayToDict(array) {
25
25
  }
26
26
  const METHOD = {
27
27
  query: 'GET',
28
- mutation: 'POST'
28
+ mutation: 'POST',
29
+ subscription: 'PATCH'
29
30
  };
30
31
  function getInput(opts) {
31
32
  return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
32
33
  }
33
34
  const getUrl = (opts)=>{
34
- let url = opts.url + '/' + opts.path;
35
+ const base = opts.url.replace(/\/$/, ''); // Remove any trailing slashes
36
+ let url = base + '/' + opts.path;
35
37
  const queryParts = [];
36
38
  if ('inputs' in opts) {
37
39
  queryParts.push('batch=1');
38
40
  }
39
- if (opts.type === 'query') {
41
+ if (opts.type === 'query' || opts.type === 'subscription') {
40
42
  const input = getInput(opts);
41
43
  if (input !== undefined && opts.methodOverride !== 'POST') {
42
44
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
@@ -73,9 +75,6 @@ async function fetchHTTPResponse(opts, ac) {
73
75
  }
74
76
  return heads;
75
77
  })();
76
- /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
77
- throw new Error('Subscriptions should use wsLink');
78
- }
79
78
  const headers = {
80
79
  ...opts.contentTypeHeader ? {
81
80
  'content-type': opts.contentTypeHeader
@@ -5,7 +5,7 @@ import { getTransformer } from '../../internals/transformer.mjs';
5
5
 
6
6
  function resolveHTTPLinkOptions(opts) {
7
7
  return {
8
- url: opts.url.toString().replace(/\/$/, ''),
8
+ url: opts.url.toString(),
9
9
  fetch: opts.fetch,
10
10
  AbortController: getAbortController(opts.AbortController),
11
11
  transformer: getTransformer(opts.transformer),
@@ -23,18 +23,20 @@ function arrayToDict(array) {
23
23
  }
24
24
  const METHOD = {
25
25
  query: 'GET',
26
- mutation: 'POST'
26
+ mutation: 'POST',
27
+ subscription: 'PATCH'
27
28
  };
28
29
  function getInput(opts) {
29
30
  return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
30
31
  }
31
32
  const getUrl = (opts)=>{
32
- let url = opts.url + '/' + opts.path;
33
+ const base = opts.url.replace(/\/$/, ''); // Remove any trailing slashes
34
+ let url = base + '/' + opts.path;
33
35
  const queryParts = [];
34
36
  if ('inputs' in opts) {
35
37
  queryParts.push('batch=1');
36
38
  }
37
- if (opts.type === 'query') {
39
+ if (opts.type === 'query' || opts.type === 'subscription') {
38
40
  const input = getInput(opts);
39
41
  if (input !== undefined && opts.methodOverride !== 'POST') {
40
42
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
@@ -71,9 +73,6 @@ async function fetchHTTPResponse(opts, ac) {
71
73
  }
72
74
  return heads;
73
75
  })();
74
- /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
75
- throw new Error('Subscriptions should use wsLink');
76
- }
77
76
  const headers = {
78
77
  ...opts.contentTypeHeader ? {
79
78
  'content-type': opts.contentTypeHeader
@@ -1,4 +1,3 @@
1
- /// <reference lib="dom.iterable" />
2
1
  import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
3
2
  import type { TRPCClientError } from '../TRPCClientError';
4
3
  import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,KAAK,eAAe,CAAC,OAAO,SAAS,SAAS,IAC1C;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;CACrE,GACD,CAAC,SAAS,GAAG;IACX,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC,CAAC;AACP,KAAK,SAAS,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1C,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,KAC3B,OAAO,CAAC;AAEb,KAAK,mBAAmB,CAAC,OAAO,SAA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E,OAAO,CAAC;CACvB;AAoID;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CAgDnB"}
@@ -52,14 +52,14 @@ export declare function createWSClient(opts: WebSocketClientOptions): {
52
52
  readonly connection: ({
53
53
  id: number;
54
54
  } & ({
55
- state: 'open';
55
+ state: "open";
56
56
  ws: WebSocket;
57
57
  } | {
58
- state: 'closed';
58
+ state: "closed";
59
59
  ws: WebSocket;
60
60
  } | {
61
- state: 'connecting';
62
- ws?: WebSocket | undefined;
61
+ state: "connecting";
62
+ ws?: WebSocket;
63
63
  })) | null;
64
64
  };
65
65
  export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
@@ -1 +1 @@
1
- {"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EAMZ,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAInD,KAAK,gBAAgB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,IAAI,mBAAmB,CAC7E,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,CAC1B,CAAC;AAEF,KAAK,kBAAkB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,IAAI,QAAQ,CACpE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAClC,eAAe,CAAC,OAAO,CAAC,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;AAOD,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB;;kBAgSpC,SAAS,wDAA0B,aAAa;;YAhP/D,MAAM;;eAGC,MAAM;YACT,SAAS;;eAGN,QAAQ;YACX,SAAS;;eAGN,YAAY;aACd,SAAS;;EAoSrB;AACD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI;IAC5D,MAAM,EAAE,mBAAmB,CAAC;CAC7B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AASlD;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,SAAS,EAC9C,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CA8CnB"}
package/dist/links.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from './links/httpLink';
6
6
  export * from './links/loggerLink';
7
7
  export * from './links/splitLink';
8
8
  export * from './links/wsLink';
9
+ export * from './links/httpSubscriptionLink';
9
10
  //# sourceMappingURL=links.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "11.0.0-rc.413+87f0cbc94",
3
+ "version": "11.0.0-rc.419+343b6de2e",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -76,10 +76,10 @@
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "11.0.0-rc.413+87f0cbc94"
79
+ "@trpc/server": "11.0.0-rc.419+343b6de2e"
80
80
  },
81
81
  "devDependencies": {
82
- "@trpc/server": "11.0.0-rc.413+87f0cbc94",
82
+ "@trpc/server": "11.0.0-rc.419+343b6de2e",
83
83
  "@types/isomorphic-fetch": "^0.0.39",
84
84
  "@types/node": "^20.10.0",
85
85
  "eslint": "^8.56.0",
@@ -96,5 +96,5 @@
96
96
  "funding": [
97
97
  "https://trpc.io/sponsor"
98
98
  ],
99
- "gitHead": "87f0cbc948c7b3a1a642cf9dde710bcabec7bc0c"
99
+ "gitHead": "343b6de2ea719347bffe8332f37589c66c323349"
100
100
  }
@@ -126,6 +126,16 @@ export type CreateTRPCClient<TRouter extends AnyRouter> =
126
126
  export function createTRPCClientProxy<TRouter extends AnyRouter>(
127
127
  client: TRPCUntypedClient<TRouter>,
128
128
  ): CreateTRPCClient<TRouter> {
129
+ const proxy = createRecursiveProxy<CreateTRPCClient<TRouter>>(
130
+ ({ path, args }) => {
131
+ const pathCopy = [...path];
132
+ const procedureType = clientCallTypeToProcedureType(pathCopy.pop()!);
133
+
134
+ const fullPath = pathCopy.join('.');
135
+
136
+ return (client as any)[procedureType](fullPath, ...args);
137
+ },
138
+ );
129
139
  return createFlatProxy<CreateTRPCClient<TRouter>>((key) => {
130
140
  if (client.hasOwnProperty(key)) {
131
141
  return (client as any)[key as any];
@@ -133,14 +143,7 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
133
143
  if (key === '__untypedClient') {
134
144
  return client;
135
145
  }
136
- return createRecursiveProxy(({ path, args }) => {
137
- const pathCopy = [key, ...path];
138
- const procedureType = clientCallTypeToProcedureType(pathCopy.pop()!);
139
-
140
- const fullPath = pathCopy.join('.');
141
-
142
- return (client as any)[procedureType](fullPath, ...args);
143
- });
146
+ return proxy[key];
144
147
  });
145
148
  }
146
149
 
@@ -27,7 +27,7 @@ export interface TRPCRequestOptions {
27
27
  }
28
28
 
29
29
  export interface TRPCSubscriptionObserver<TValue, TError> {
30
- onStarted: () => void;
30
+ onStarted: (opts: { context: OperationContext | undefined }) => void;
31
31
  onData: (value: TValue) => void;
32
32
  onError: (err: TError) => void;
33
33
  onStopped: () => void;
@@ -148,7 +148,9 @@ export class TRPCUntypedClient<TRouter extends AnyRouter> {
148
148
  return observable$.subscribe({
149
149
  next(envelope) {
150
150
  if (envelope.result.type === 'started') {
151
- opts.onStarted?.();
151
+ opts.onStarted?.({
152
+ context: envelope.context,
153
+ });
152
154
  } else if (envelope.result.type === 'stopped') {
153
155
  opts.onStopped?.();
154
156
  } else {
@@ -86,14 +86,17 @@ export function httpBatchLink<TRouter extends AnyRouter>(
86
86
  };
87
87
 
88
88
  const query = dataLoader(batchLoader('query'));
89
- const mutation = dataLoader<Operation, HTTPResult>(batchLoader('mutation'));
90
- const subscription = dataLoader<Operation, HTTPResult>(
91
- batchLoader('subscription'),
92
- );
89
+ const mutation = dataLoader(batchLoader('mutation'));
93
90
 
94
- const loaders = { query, subscription, mutation };
91
+ const loaders = { query, mutation };
95
92
  return ({ op }) => {
96
93
  return observable((observer) => {
94
+ /* istanbul ignore if -- @preserve */
95
+ if (op.type === 'subscription') {
96
+ throw new Error(
97
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
98
+ );
99
+ }
97
100
  const loader = loaders[op.type];
98
101
  const { promise, cancel } = loader.load(op);
99
102
 
@@ -95,13 +95,11 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
95
95
 
96
96
  return {
97
97
  promise: responsePromise.then(async (res) => {
98
- if (!res.body) {
99
- throw new Error('Received response without body');
100
- }
101
98
  const [head] = await jsonlStreamConsumer<
102
99
  Record<string, Promise<any>>
103
100
  >({
104
- from: res.body,
101
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
102
+ from: res.body!,
105
103
  deserialize: resolvedOpts.transformer.output.deserialize,
106
104
  // onError: console.error,
107
105
  formatError(opts) {
@@ -114,7 +112,7 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
114
112
 
115
113
  const promises = Object.keys(batchOps).map(
116
114
  async (key): Promise<HTTPResult> => {
117
- let json: TRPCResponse = await head[key];
115
+ let json: TRPCResponse = await Promise.resolve(head[key]);
118
116
 
119
117
  if ('result' in json) {
120
118
  /**
@@ -149,11 +147,16 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
149
147
 
150
148
  const query = dataLoader(batchLoader('query'));
151
149
  const mutation = dataLoader(batchLoader('mutation'));
152
- const subscription = dataLoader(batchLoader('subscription'));
153
150
 
154
- const loaders = { query, subscription, mutation };
151
+ const loaders = { query, mutation };
155
152
  return ({ op }) => {
156
153
  return observable((observer) => {
154
+ /* istanbul ignore if -- @preserve */
155
+ if (op.type === 'subscription') {
156
+ throw new Error(
157
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
158
+ );
159
+ }
157
160
  const loader = loaders[op.type];
158
161
  const { promise, cancel } = loader.load(op);
159
162
 
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import type {
3
- AnyRootTypes,
3
+ AnyClientTypes,
4
4
  AnyRouter,
5
5
  } from '@trpc/server/unstable-core-do-not-import';
6
6
  import { transformResult } from '@trpc/server/unstable-core-do-not-import';
@@ -25,7 +25,7 @@ import {
25
25
  type TRPCLink,
26
26
  } from './types';
27
27
 
28
- export type HTTPLinkOptions<TRoot extends AnyRootTypes> =
28
+ export type HTTPLinkOptions<TRoot extends AnyClientTypes> =
29
29
  HTTPLinkBaseOptions<TRoot> & {
30
30
  /**
31
31
  * Headers to be set on outgoing requests or a callback that of said headers
@@ -80,6 +80,12 @@ export function httpLink<TRouter extends AnyRouter = AnyRouter>(
80
80
  return ({ op }) => {
81
81
  return observable((observer) => {
82
82
  const { path, input, type } = op;
83
+ /* istanbul ignore if -- @preserve */
84
+ if (type === 'subscription') {
85
+ throw new Error(
86
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
87
+ );
88
+ }
83
89
 
84
90
  const request = universalRequester({
85
91
  ...resolvedOpts,