@trpc/client 11.0.0-rc.370 → 11.0.0-rc.374

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 (47) hide show
  1. package/dist/bundle-analysis.json +60 -106
  2. package/dist/index.js +0 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/internals/dataLoader.d.ts +3 -4
  5. package/dist/internals/dataLoader.d.ts.map +1 -1
  6. package/dist/internals/dataLoader.js +14 -13
  7. package/dist/internals/dataLoader.mjs +14 -13
  8. package/dist/links/httpBatchLink.d.ts +6 -1
  9. package/dist/links/httpBatchLink.d.ts.map +1 -1
  10. package/dist/links/httpBatchLink.js +95 -30
  11. package/dist/links/httpBatchLink.mjs +96 -31
  12. package/dist/links/httpBatchStreamLink.d.ts +9 -6
  13. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  14. package/dist/links/httpBatchStreamLink.js +132 -34
  15. package/dist/links/httpBatchStreamLink.mjs +132 -34
  16. package/dist/links/httpLink.d.ts +4 -7
  17. package/dist/links/httpLink.d.ts.map +1 -1
  18. package/dist/links/httpLink.js +72 -46
  19. package/dist/links/httpLink.mjs +74 -47
  20. package/dist/links/internals/httpUtils.d.ts +2 -4
  21. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  22. package/dist/links/internals/httpUtils.js +4 -32
  23. package/dist/links/internals/httpUtils.mjs +4 -32
  24. package/package.json +4 -4
  25. package/src/internals/dataLoader.ts +21 -19
  26. package/src/links/httpBatchLink.ts +132 -46
  27. package/src/links/httpBatchStreamLink.ts +173 -48
  28. package/src/links/httpLink.ts +100 -60
  29. package/src/links/internals/httpUtils.ts +5 -41
  30. package/dist/links/internals/createHTTPBatchLink.d.ts +0 -20
  31. package/dist/links/internals/createHTTPBatchLink.d.ts.map +0 -1
  32. package/dist/links/internals/createHTTPBatchLink.js +0 -85
  33. package/dist/links/internals/createHTTPBatchLink.mjs +0 -83
  34. package/dist/links/internals/getTextDecoder.d.ts +0 -3
  35. package/dist/links/internals/getTextDecoder.d.ts.map +0 -1
  36. package/dist/links/internals/getTextDecoder.js +0 -16
  37. package/dist/links/internals/getTextDecoder.mjs +0 -14
  38. package/dist/links/internals/parseJSONStream.d.ts +0 -39
  39. package/dist/links/internals/parseJSONStream.d.ts.map +0 -1
  40. package/dist/links/internals/parseJSONStream.js +0 -118
  41. package/dist/links/internals/parseJSONStream.mjs +0 -115
  42. package/dist/links/internals/streamingUtils.d.ts +0 -7
  43. package/dist/links/internals/streamingUtils.d.ts.map +0 -1
  44. package/src/links/internals/createHTTPBatchLink.ts +0 -133
  45. package/src/links/internals/getTextDecoder.ts +0 -19
  46. package/src/links/internals/parseJSONStream.ts +0 -166
  47. package/src/links/internals/streamingUtils.ts +0 -6
@@ -4,60 +4,86 @@ var observable = require('@trpc/server/observable');
4
4
  var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
5
  var TRPCClientError = require('../TRPCClientError.js');
6
6
  var httpUtils = require('./internals/httpUtils.js');
7
+ var contentTypes = require('./internals/contentTypes.js');
7
8
 
8
- function httpLinkFactory(factoryOpts) {
9
- return (opts)=>{
10
- const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
11
- return ()=>({ op })=>observable.observable((observer)=>{
12
- const { path , input , type } = op;
13
- const { promise , cancel } = factoryOpts.requester({
14
- ...resolvedOpts,
15
- type,
16
- path,
17
- input,
18
- headers () {
19
- if (!opts.headers) {
20
- return {};
21
- }
22
- if (typeof opts.headers === 'function') {
23
- return opts.headers({
24
- op
25
- });
26
- }
27
- return opts.headers;
9
+ const universalRequester = (opts)=>{
10
+ const input = httpUtils.getInput(opts);
11
+ if (contentTypes.isFormData(input)) {
12
+ if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
13
+ throw new Error('FormData is only supported for mutations');
14
+ }
15
+ return httpUtils.httpRequest({
16
+ ...opts,
17
+ // The browser will set this automatically and include the boundary= in it
18
+ contentTypeHeader: undefined,
19
+ getUrl: httpUtils.getUrl,
20
+ getBody: ()=>input
21
+ });
22
+ }
23
+ if (contentTypes.isOctetType(input)) {
24
+ if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
25
+ throw new Error('Octet type input is only supported for mutations');
26
+ }
27
+ return httpUtils.httpRequest({
28
+ ...opts,
29
+ contentTypeHeader: 'application/octet-stream',
30
+ getUrl: httpUtils.getUrl,
31
+ getBody: ()=>input
32
+ });
33
+ }
34
+ return httpUtils.jsonHttpRequester(opts);
35
+ };
36
+ /**
37
+ * @link https://trpc.io/docs/client/links/httpLink
38
+ */ function httpLink(opts) {
39
+ const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
40
+ return ()=>{
41
+ return ({ op })=>{
42
+ return observable.observable((observer)=>{
43
+ const { path , input , type } = op;
44
+ const request = universalRequester({
45
+ ...resolvedOpts,
46
+ type,
47
+ path,
48
+ input,
49
+ headers () {
50
+ if (!opts.headers) {
51
+ return {};
28
52
  }
29
- });
30
- let meta = undefined;
31
- promise.then((res)=>{
32
- meta = res.meta;
33
- const transformed = unstableCoreDoNotImport.transformResult(res.json, resolvedOpts.transformer.output);
34
- if (!transformed.ok) {
35
- observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
36
- meta
37
- }));
38
- return;
53
+ if (typeof opts.headers === 'function') {
54
+ return opts.headers({
55
+ op
56
+ });
39
57
  }
40
- observer.next({
41
- context: res.meta,
42
- result: transformed.result
43
- });
44
- observer.complete();
45
- }).catch((cause)=>{
46
- observer.error(TRPCClientError.TRPCClientError.from(cause, {
58
+ return opts.headers;
59
+ }
60
+ });
61
+ let meta = undefined;
62
+ request.promise.then((res)=>{
63
+ meta = res.meta;
64
+ const transformed = unstableCoreDoNotImport.transformResult(res.json, resolvedOpts.transformer.output);
65
+ if (!transformed.ok) {
66
+ observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
47
67
  meta
48
68
  }));
69
+ return;
70
+ }
71
+ observer.next({
72
+ context: res.meta,
73
+ result: transformed.result
49
74
  });
50
- return ()=>{
51
- cancel();
52
- };
75
+ observer.complete();
76
+ }).catch((cause)=>{
77
+ observer.error(TRPCClientError.TRPCClientError.from(cause, {
78
+ meta
79
+ }));
53
80
  });
81
+ return ()=>{
82
+ request.cancel();
83
+ };
84
+ });
85
+ };
54
86
  };
55
87
  }
56
- /**
57
- * @link https://trpc.io/docs/v11/client/links/httpLink
58
- */ const httpLink = httpLinkFactory({
59
- requester: httpUtils.universalRequester
60
- });
61
88
 
62
89
  exports.httpLink = httpLink;
63
- exports.httpLinkFactory = httpLinkFactory;
@@ -1,60 +1,87 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import { transformResult } from '@trpc/server/unstable-core-do-not-import';
3
3
  import { TRPCClientError } from '../TRPCClientError.mjs';
4
- import { resolveHTTPLinkOptions, universalRequester } from './internals/httpUtils.mjs';
4
+ import { resolveHTTPLinkOptions, getInput, httpRequest, getUrl, jsonHttpRequester } from './internals/httpUtils.mjs';
5
+ import { isFormData, isOctetType } from './internals/contentTypes.mjs';
5
6
 
6
- function httpLinkFactory(factoryOpts) {
7
- return (opts)=>{
8
- const resolvedOpts = resolveHTTPLinkOptions(opts);
9
- return ()=>({ op })=>observable((observer)=>{
10
- const { path , input , type } = op;
11
- const { promise , cancel } = factoryOpts.requester({
12
- ...resolvedOpts,
13
- type,
14
- path,
15
- input,
16
- headers () {
17
- if (!opts.headers) {
18
- return {};
19
- }
20
- if (typeof opts.headers === 'function') {
21
- return opts.headers({
22
- op
23
- });
24
- }
25
- return opts.headers;
7
+ const universalRequester = (opts)=>{
8
+ const input = getInput(opts);
9
+ if (isFormData(input)) {
10
+ if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
11
+ throw new Error('FormData is only supported for mutations');
12
+ }
13
+ return httpRequest({
14
+ ...opts,
15
+ // The browser will set this automatically and include the boundary= in it
16
+ contentTypeHeader: undefined,
17
+ getUrl,
18
+ getBody: ()=>input
19
+ });
20
+ }
21
+ if (isOctetType(input)) {
22
+ if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
23
+ throw new Error('Octet type input is only supported for mutations');
24
+ }
25
+ return httpRequest({
26
+ ...opts,
27
+ contentTypeHeader: 'application/octet-stream',
28
+ getUrl,
29
+ getBody: ()=>input
30
+ });
31
+ }
32
+ return jsonHttpRequester(opts);
33
+ };
34
+ /**
35
+ * @link https://trpc.io/docs/client/links/httpLink
36
+ */ function httpLink(opts) {
37
+ const resolvedOpts = resolveHTTPLinkOptions(opts);
38
+ return ()=>{
39
+ return ({ op })=>{
40
+ return observable((observer)=>{
41
+ const { path , input , type } = op;
42
+ const request = universalRequester({
43
+ ...resolvedOpts,
44
+ type,
45
+ path,
46
+ input,
47
+ headers () {
48
+ if (!opts.headers) {
49
+ return {};
26
50
  }
27
- });
28
- let meta = undefined;
29
- promise.then((res)=>{
30
- meta = res.meta;
31
- const transformed = transformResult(res.json, resolvedOpts.transformer.output);
32
- if (!transformed.ok) {
33
- observer.error(TRPCClientError.from(transformed.error, {
34
- meta
35
- }));
36
- return;
51
+ if (typeof opts.headers === 'function') {
52
+ return opts.headers({
53
+ op
54
+ });
37
55
  }
38
- observer.next({
39
- context: res.meta,
40
- result: transformed.result
41
- });
42
- observer.complete();
43
- }).catch((cause)=>{
44
- observer.error(TRPCClientError.from(cause, {
56
+ return opts.headers;
57
+ }
58
+ });
59
+ let meta = undefined;
60
+ request.promise.then((res)=>{
61
+ meta = res.meta;
62
+ const transformed = transformResult(res.json, resolvedOpts.transformer.output);
63
+ if (!transformed.ok) {
64
+ observer.error(TRPCClientError.from(transformed.error, {
45
65
  meta
46
66
  }));
67
+ return;
68
+ }
69
+ observer.next({
70
+ context: res.meta,
71
+ result: transformed.result
47
72
  });
48
- return ()=>{
49
- cancel();
50
- };
73
+ observer.complete();
74
+ }).catch((cause)=>{
75
+ observer.error(TRPCClientError.from(cause, {
76
+ meta
77
+ }));
51
78
  });
79
+ return ()=>{
80
+ request.cancel();
81
+ };
82
+ });
83
+ };
52
84
  };
53
85
  }
54
- /**
55
- * @link https://trpc.io/docs/v11/client/links/httpLink
56
- */ const httpLink = httpLinkFactory({
57
- requester: universalRequester
58
- });
59
86
 
60
- export { httpLink, httpLinkFactory };
87
+ export { httpLink };
@@ -1,7 +1,6 @@
1
1
  import type { AnyRootTypes, CombinedDataTransformer, ProcedureType, 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
- import type { TextDecoderEsque } from '../internals/streamingUtils';
5
4
  import type { HTTPHeaders, PromiseAndCancel } from '../types';
6
5
  /**
7
6
  * @internal
@@ -45,6 +44,7 @@ type GetInputOptions = {
45
44
  } | {
46
45
  inputs: unknown[];
47
46
  });
47
+ export declare function getInput(opts: GetInputOptions): any;
48
48
  export type HTTPBaseRequestOptions = GetInputOptions & ResolvedHTTPLinkOptions & {
49
49
  type: ProcedureType;
50
50
  path: string;
@@ -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
- batchModeHeader?: 'stream';
55
+ trpcAcceptHeader?: 'application/jsonl';
56
56
  contentTypeHeader?: string;
57
57
  getUrl: GetUrl;
58
58
  getBody: GetBody;
@@ -63,10 +63,8 @@ export type Requester = (opts: HTTPBaseRequestOptions & {
63
63
  headers: () => HTTPHeaders | Promise<HTTPHeaders>;
64
64
  }) => PromiseAndCancel<HTTPResult>;
65
65
  export declare const jsonHttpRequester: Requester;
66
- export declare const universalRequester: Requester;
67
66
  export type HTTPRequestOptions = ContentOptions & HTTPBaseRequestOptions & {
68
67
  headers: () => HTTPHeaders | Promise<HTTPHeaders>;
69
- TextDecoder?: TextDecoderEsque;
70
68
  };
71
69
  export declare function fetchHTTPResponse(opts: HTTPRequestOptions, ac?: AbortControllerInstanceEsque | null): Promise<ResponseEsque>;
72
70
  export declare function httpRequest(opts: HTTPRequestOptions): PromiseAndCancel<HTTPResult>;
@@ -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,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG9D;;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,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,eAAe,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC7C,WAAW,EAAE,uBAAuB,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,CAAC,YAAY,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ACE,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,0BAgCzC;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CA8B9B"}
@@ -4,7 +4,6 @@ var getFetch = require('../../getFetch.js');
4
4
  var getAbortController = require('../../internals/getAbortController.js');
5
5
  var TRPCClientError = require('../../TRPCClientError.js');
6
6
  var transformer = require('../../internals/transformer.js');
7
- var contentTypes = require('./contentTypes.js');
8
7
 
9
8
  function resolveHTTPLinkOptions(opts) {
10
9
  return {
@@ -63,33 +62,6 @@ const jsonHttpRequester = (opts)=>{
63
62
  getBody
64
63
  });
65
64
  };
66
- const universalRequester = (opts)=>{
67
- const input = getInput(opts);
68
- if (contentTypes.isFormData(input)) {
69
- if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
70
- throw new Error('FormData is only supported for mutations');
71
- }
72
- return httpRequest({
73
- ...opts,
74
- // The browser will set this automatically and include the boundary= in it
75
- contentTypeHeader: undefined,
76
- getUrl,
77
- getBody: ()=>input
78
- });
79
- }
80
- if (contentTypes.isOctetType(input)) {
81
- if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
82
- throw new Error('Octet type input is only supported for mutations');
83
- }
84
- return httpRequest({
85
- ...opts,
86
- contentTypeHeader: 'application/octet-stream',
87
- getUrl,
88
- getBody: ()=>input
89
- });
90
- }
91
- return jsonHttpRequester(opts);
92
- };
93
65
  async function fetchHTTPResponse(opts, ac) {
94
66
  const url = opts.getUrl(opts);
95
67
  const body = opts.getBody(opts);
@@ -108,9 +80,9 @@ async function fetchHTTPResponse(opts, ac) {
108
80
  ...opts.contentTypeHeader ? {
109
81
  'content-type': opts.contentTypeHeader
110
82
  } : {},
111
- ...opts.batchModeHeader ? {
112
- 'trpc-batch-mode': opts.batchModeHeader
113
- } : {},
83
+ ...opts.trpcAcceptHeader ? {
84
+ 'trpc-accept': opts.trpcAcceptHeader
85
+ } : undefined,
114
86
  ...resolvedHeaders
115
87
  };
116
88
  return getFetch.getFetch(opts.fetch)(url, {
@@ -155,8 +127,8 @@ function httpRequest(opts) {
155
127
 
156
128
  exports.fetchHTTPResponse = fetchHTTPResponse;
157
129
  exports.getBody = getBody;
130
+ exports.getInput = getInput;
158
131
  exports.getUrl = getUrl;
159
132
  exports.httpRequest = httpRequest;
160
133
  exports.jsonHttpRequester = jsonHttpRequester;
161
134
  exports.resolveHTTPLinkOptions = resolveHTTPLinkOptions;
162
- exports.universalRequester = universalRequester;
@@ -2,7 +2,6 @@ import { getFetch } from '../../getFetch.mjs';
2
2
  import { getAbortController } from '../../internals/getAbortController.mjs';
3
3
  import { TRPCClientError } from '../../TRPCClientError.mjs';
4
4
  import { getTransformer } from '../../internals/transformer.mjs';
5
- import { isFormData, isOctetType } from './contentTypes.mjs';
6
5
 
7
6
  function resolveHTTPLinkOptions(opts) {
8
7
  return {
@@ -61,33 +60,6 @@ const jsonHttpRequester = (opts)=>{
61
60
  getBody
62
61
  });
63
62
  };
64
- const universalRequester = (opts)=>{
65
- const input = getInput(opts);
66
- if (isFormData(input)) {
67
- if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
68
- throw new Error('FormData is only supported for mutations');
69
- }
70
- return httpRequest({
71
- ...opts,
72
- // The browser will set this automatically and include the boundary= in it
73
- contentTypeHeader: undefined,
74
- getUrl,
75
- getBody: ()=>input
76
- });
77
- }
78
- if (isOctetType(input)) {
79
- if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {
80
- throw new Error('Octet type input is only supported for mutations');
81
- }
82
- return httpRequest({
83
- ...opts,
84
- contentTypeHeader: 'application/octet-stream',
85
- getUrl,
86
- getBody: ()=>input
87
- });
88
- }
89
- return jsonHttpRequester(opts);
90
- };
91
63
  async function fetchHTTPResponse(opts, ac) {
92
64
  const url = opts.getUrl(opts);
93
65
  const body = opts.getBody(opts);
@@ -106,9 +78,9 @@ async function fetchHTTPResponse(opts, ac) {
106
78
  ...opts.contentTypeHeader ? {
107
79
  'content-type': opts.contentTypeHeader
108
80
  } : {},
109
- ...opts.batchModeHeader ? {
110
- 'trpc-batch-mode': opts.batchModeHeader
111
- } : {},
81
+ ...opts.trpcAcceptHeader ? {
82
+ 'trpc-accept': opts.trpcAcceptHeader
83
+ } : undefined,
112
84
  ...resolvedHeaders
113
85
  };
114
86
  return getFetch(opts.fetch)(url, {
@@ -151,4 +123,4 @@ function httpRequest(opts) {
151
123
  };
152
124
  }
153
125
 
154
- export { fetchHTTPResponse, getBody, getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions, universalRequester };
126
+ export { fetchHTTPResponse, getBody, getInput, getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "11.0.0-rc.370+1a920ac81",
3
+ "version": "11.0.0-rc.374+5027209bc",
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.370+1a920ac81"
79
+ "@trpc/server": "11.0.0-rc.374+5027209bc"
80
80
  },
81
81
  "devDependencies": {
82
- "@trpc/server": "11.0.0-rc.370+1a920ac81",
82
+ "@trpc/server": "11.0.0-rc.374+5027209bc",
83
83
  "@types/isomorphic-fetch": "^0.0.39",
84
84
  "@types/node": "^20.10.0",
85
85
  "eslint": "^8.56.0",
@@ -95,5 +95,5 @@
95
95
  "funding": [
96
96
  "https://trpc.io/sponsor"
97
97
  ],
98
- "gitHead": "1a920ac8160dacfb6a49e6161f56208859168317"
98
+ "gitHead": "5027209bc300d299224ecef764adeac09b8cab8d"
99
99
  }
@@ -12,13 +12,10 @@ type Batch<TKey, TValue> = {
12
12
  items: BatchItem<TKey, TValue>[];
13
13
  cancel: CancelFn;
14
14
  };
15
- type BatchLoader<TKey, TValue> = {
15
+ export type BatchLoader<TKey, TValue> = {
16
16
  validate: (keys: TKey[]) => boolean;
17
- fetch: (
18
- keys: TKey[],
19
- unitResolver: (index: number, value: NonNullable<TValue>) => void,
20
- ) => {
21
- promise: Promise<TValue[]>;
17
+ fetch: (keys: TKey[]) => {
18
+ promise: Promise<TValue[] | Promise<TValue>[]>;
22
19
  cancel: CancelFn;
23
20
  };
24
21
  };
@@ -107,25 +104,30 @@ export function dataLoader<TKey, TValue>(
107
104
  for (const item of items) {
108
105
  item.batch = batch;
109
106
  }
110
- const unitResolver = (index: number, value: NonNullable<TValue>) => {
111
- const item = batch.items[index]!;
112
- item.resolve?.(value);
113
- item.batch = null;
114
- item.reject = null;
115
- item.resolve = null;
116
- };
117
107
  const { promise, cancel } = batchLoader.fetch(
118
108
  batch.items.map((_item) => _item.key),
119
- unitResolver,
120
109
  );
121
110
  batch.cancel = cancel;
122
111
 
123
112
  promise
124
- .then((result) => {
125
- for (let i = 0; i < result.length; i++) {
126
- const value = result[i]!;
127
- unitResolver(i, value);
128
- }
113
+ .then(async (result) => {
114
+ await Promise.all(
115
+ result.map(async (valueOrPromise, index) => {
116
+ const item = batch.items[index]!;
117
+ try {
118
+ const value = await Promise.resolve(valueOrPromise);
119
+
120
+ item.resolve?.(value);
121
+ } catch (cause) {
122
+ item.reject?.(cause as Error);
123
+ }
124
+
125
+ item.batch = null;
126
+ item.reject = null;
127
+ item.resolve = null;
128
+ }),
129
+ );
130
+
129
131
  for (const item of batch.items) {
130
132
  item.reject?.(new Error('Missing result'));
131
133
  item.batch = null;