@trpc/server 11.0.0-rc.584 → 11.0.0-rc.587

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 +1 @@
1
- {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,CAWjB"}
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,CAqBjB"}
@@ -1,17 +1,35 @@
1
1
  'use strict';
2
2
 
3
- var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
3
+ var utils = require('../unstable-core-do-not-import/utils.js');
4
4
  require('../unstable-core-do-not-import/rootConfig.js');
5
+ var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
5
6
 
7
+ /**
8
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import type { AnyTRPCRouter } from '@trpc/server'
13
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
14
+ * ```
15
+ */ // eslint-disable-next-line no-restricted-imports
6
16
  function createExpressMiddleware(opts) {
7
17
  return (req, res)=>{
8
- const path = req.path.slice(1);
9
- nodeHTTPRequestHandler.nodeHTTPRequestHandler({
10
- ...opts,
18
+ let path = '';
19
+ void utils.run(async ()=>{
20
+ path = req.path.slice(1);
21
+ await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
22
+ ...opts,
23
+ req,
24
+ res,
25
+ path
26
+ });
27
+ }).catch(nodeHTTPRequestHandler.internal_exceptionHandler({
11
28
  req,
12
29
  res,
13
- path
14
- });
30
+ path,
31
+ ...opts
32
+ }));
15
33
  };
16
34
  }
17
35
 
@@ -1,15 +1,33 @@
1
- import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
1
+ import { run } from '../unstable-core-do-not-import/utils.mjs';
2
2
  import '../unstable-core-do-not-import/rootConfig.mjs';
3
+ import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
3
4
 
5
+ /**
6
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { AnyTRPCRouter } from '@trpc/server'
11
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
12
+ * ```
13
+ */ // eslint-disable-next-line no-restricted-imports
4
14
  function createExpressMiddleware(opts) {
5
15
  return (req, res)=>{
6
- const path = req.path.slice(1);
7
- nodeHTTPRequestHandler({
8
- ...opts,
16
+ let path = '';
17
+ void run(async ()=>{
18
+ path = req.path.slice(1);
19
+ await nodeHTTPRequestHandler({
20
+ ...opts,
21
+ req,
22
+ res,
23
+ path
24
+ });
25
+ }).catch(internal_exceptionHandler({
9
26
  req,
10
27
  res,
11
- path
12
- });
28
+ path,
29
+ ...opts
30
+ }));
13
31
  };
14
32
  }
15
33
 
@@ -1 +1 @@
1
- {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,cAAc,EACd,eAAe,CAChB,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAI5E,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAC5D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GACrE,cAAc,CAmChB"}
1
+ {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,cAAc,EACd,eAAe,CAChB,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAC5D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GACrE,cAAc,CAkChB"}
@@ -15,9 +15,9 @@ var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
15
15
  * ```
16
16
  */ // @trpc/server
17
17
  function createNextApiHandler(opts) {
18
- let path = '';
19
- const handler = (req, res)=>{
20
- try {
18
+ return async (req, res)=>{
19
+ let path = '';
20
+ await utils.run(async ()=>{
21
21
  path = utils.run(()=>{
22
22
  if (typeof req.query['trpc'] === 'string') {
23
23
  return req.query['trpc'];
@@ -30,22 +30,19 @@ function createNextApiHandler(opts) {
30
30
  code: 'INTERNAL_SERVER_ERROR'
31
31
  });
32
32
  });
33
- nodeHTTPRequestHandler.nodeHTTPRequestHandler({
33
+ await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
34
34
  ...opts,
35
35
  req,
36
36
  res,
37
37
  path
38
38
  });
39
- } catch (cause) {
40
- nodeHTTPRequestHandler.internal_exceptionHandler({
41
- req,
42
- res,
43
- path,
44
- ...opts
45
- })(cause);
46
- }
39
+ }).catch(nodeHTTPRequestHandler.internal_exceptionHandler({
40
+ req,
41
+ res,
42
+ path,
43
+ ...opts
44
+ }));
47
45
  };
48
- return handler;
49
46
  }
50
47
 
51
48
  exports.createNextApiHandler = createNextApiHandler;
@@ -13,9 +13,9 @@ import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/n
13
13
  * ```
14
14
  */ // @trpc/server
15
15
  function createNextApiHandler(opts) {
16
- let path = '';
17
- const handler = (req, res)=>{
18
- try {
16
+ return async (req, res)=>{
17
+ let path = '';
18
+ await run(async ()=>{
19
19
  path = run(()=>{
20
20
  if (typeof req.query['trpc'] === 'string') {
21
21
  return req.query['trpc'];
@@ -28,22 +28,19 @@ function createNextApiHandler(opts) {
28
28
  code: 'INTERNAL_SERVER_ERROR'
29
29
  });
30
30
  });
31
- nodeHTTPRequestHandler({
31
+ await nodeHTTPRequestHandler({
32
32
  ...opts,
33
33
  req,
34
34
  res,
35
35
  path
36
36
  });
37
- } catch (cause) {
38
- internal_exceptionHandler({
39
- req,
40
- res,
41
- path,
42
- ...opts
43
- })(cause);
44
- }
37
+ }).catch(internal_exceptionHandler({
38
+ req,
39
+ res,
40
+ path,
41
+ ...opts
42
+ }));
45
43
  };
46
- return handler;
47
44
  }
48
45
 
49
46
  export { createNextApiHandler };
@@ -13,5 +13,8 @@ import type { NodeHTTPRequest, NodeHTTPRequestHandlerOptions, NodeHTTPResponse }
13
13
  * @internal
14
14
  */
15
15
  export declare function internal_exceptionHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>): (cause: unknown) => void;
16
- export declare function nodeHTTPRequestHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>): void;
16
+ /**
17
+ * @remark the promise never rejects
18
+ */
19
+ export declare function nodeHTTPRequestHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
17
20
  //# sourceMappingURL=nodeHTTPRequestHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAM5B,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,WAClD,OAAO,UA6BvB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QA8ElE"}
1
+ {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAM5B,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,WAClD,OAAO,UA6BvB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAoFlE"}
@@ -46,73 +46,80 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
46
46
  res.end(JSON.stringify(transformed));
47
47
  };
48
48
  }
49
- function nodeHTTPRequestHandler(opts) {
50
- const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
51
- return handleViaMiddleware(opts.req, opts.res, (err)=>{
52
- utils.run(async ()=>{
53
- const req = incomingMessageToRequest.incomingMessageToRequest(opts.req, {
54
- maxBodySize: opts.maxBodySize ?? null
55
- });
56
- // Build tRPC dependencies
57
- const createContext = async (innerOpts)=>{
58
- return await opts.createContext?.({
59
- ...opts,
60
- ...innerOpts
49
+ /**
50
+ * @remark the promise never rejects
51
+ */ async function nodeHTTPRequestHandler(opts) {
52
+ return new Promise((resolve)=>{
53
+ const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
54
+ opts.res.once('finish', ()=>{
55
+ resolve();
56
+ });
57
+ return handleViaMiddleware(opts.req, opts.res, (err)=>{
58
+ utils.run(async ()=>{
59
+ const req = incomingMessageToRequest.incomingMessageToRequest(opts.req, {
60
+ maxBodySize: opts.maxBodySize ?? null
61
61
  });
62
- };
63
- const response = await resolveResponse.resolveResponse({
64
- ...opts,
65
- req,
66
- error: err ? TRPCError.getTRPCErrorFromUnknown(err) : null,
67
- createContext,
68
- onError (o) {
69
- opts?.onError?.({
70
- ...o,
71
- req: opts.req
72
- });
73
- }
74
- });
75
- const { res } = opts;
76
- if (res.statusCode === 200) {
77
- // if the status code is set, we assume that it's been manually overridden
78
- res.statusCode = response.status;
79
- }
80
- for (const [key, value] of response.headers){
81
- res.setHeader(key, value);
82
- }
83
- if (response.body) {
84
- const reader = response.body.getReader();
85
- const onAbort = ()=>{
86
- // cancelling the reader will cause the whole stream to be cancelled
87
- reader.cancel().catch(()=>{
88
- // console.error('reader.cancel() error', err);
62
+ // Build tRPC dependencies
63
+ const createContext = async (innerOpts)=>{
64
+ return await opts.createContext?.({
65
+ ...opts,
66
+ ...innerOpts
89
67
  });
90
68
  };
91
- req.signal.addEventListener('abort', onAbort, {
92
- once: true
93
- });
94
- while(true){
95
- const { done , value: value1 } = await reader.read();
96
- if (done) {
97
- break;
98
- }
99
- if (!res.writable) {
100
- break;
69
+ const response = await resolveResponse.resolveResponse({
70
+ ...opts,
71
+ req,
72
+ error: err ? TRPCError.getTRPCErrorFromUnknown(err) : null,
73
+ createContext,
74
+ onError (o) {
75
+ opts?.onError?.({
76
+ ...o,
77
+ req: opts.req
78
+ });
101
79
  }
102
- if (res.write(value1) === false) {
103
- await new Promise((resolve)=>{
104
- res.once('drain', resolve);
80
+ });
81
+ const { res } = opts;
82
+ if (res.statusCode === 200) {
83
+ // if the status code is set, we assume that it's been manually overridden
84
+ res.statusCode = response.status;
85
+ }
86
+ for (const [key, value] of response.headers){
87
+ res.setHeader(key, value);
88
+ }
89
+ if (response.body) {
90
+ const reader = response.body.getReader();
91
+ const onAbort = ()=>{
92
+ // cancelling the reader will cause the whole stream to be cancelled
93
+ reader.cancel().catch(()=>{
94
+ // console.error('reader.cancel() error', err);
105
95
  });
96
+ };
97
+ req.signal.addEventListener('abort', onAbort, {
98
+ once: true
99
+ });
100
+ while(true){
101
+ const { done , value: value1 } = await reader.read();
102
+ if (done) {
103
+ break;
104
+ }
105
+ if (!res.writable) {
106
+ break;
107
+ }
108
+ if (res.write(value1) === false) {
109
+ await new Promise((resolve)=>{
110
+ res.once('drain', resolve);
111
+ });
112
+ }
113
+ // useful for debugging chunked responses:
114
+ // console.log('wrote', Buffer.from(value).toString());
115
+ // IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
116
+ res.flush?.();
106
117
  }
107
- // useful for debugging chunked responses:
108
- // console.log('wrote', Buffer.from(value).toString());
109
- // IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
110
- res.flush?.();
118
+ req.signal.removeEventListener('abort', onAbort);
111
119
  }
112
- req.signal.removeEventListener('abort', onAbort);
113
- }
114
- res.end();
115
- }).catch(internal_exceptionHandler(opts));
120
+ res.end();
121
+ }).catch(internal_exceptionHandler(opts));
122
+ });
116
123
  });
117
124
  }
118
125
 
@@ -44,73 +44,80 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
44
44
  res.end(JSON.stringify(transformed));
45
45
  };
46
46
  }
47
- function nodeHTTPRequestHandler(opts) {
48
- const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
49
- return handleViaMiddleware(opts.req, opts.res, (err)=>{
50
- run(async ()=>{
51
- const req = incomingMessageToRequest(opts.req, {
52
- maxBodySize: opts.maxBodySize ?? null
53
- });
54
- // Build tRPC dependencies
55
- const createContext = async (innerOpts)=>{
56
- return await opts.createContext?.({
57
- ...opts,
58
- ...innerOpts
47
+ /**
48
+ * @remark the promise never rejects
49
+ */ async function nodeHTTPRequestHandler(opts) {
50
+ return new Promise((resolve)=>{
51
+ const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
52
+ opts.res.once('finish', ()=>{
53
+ resolve();
54
+ });
55
+ return handleViaMiddleware(opts.req, opts.res, (err)=>{
56
+ run(async ()=>{
57
+ const req = incomingMessageToRequest(opts.req, {
58
+ maxBodySize: opts.maxBodySize ?? null
59
59
  });
60
- };
61
- const response = await resolveResponse({
62
- ...opts,
63
- req,
64
- error: err ? getTRPCErrorFromUnknown(err) : null,
65
- createContext,
66
- onError (o) {
67
- opts?.onError?.({
68
- ...o,
69
- req: opts.req
70
- });
71
- }
72
- });
73
- const { res } = opts;
74
- if (res.statusCode === 200) {
75
- // if the status code is set, we assume that it's been manually overridden
76
- res.statusCode = response.status;
77
- }
78
- for (const [key, value] of response.headers){
79
- res.setHeader(key, value);
80
- }
81
- if (response.body) {
82
- const reader = response.body.getReader();
83
- const onAbort = ()=>{
84
- // cancelling the reader will cause the whole stream to be cancelled
85
- reader.cancel().catch(()=>{
86
- // console.error('reader.cancel() error', err);
60
+ // Build tRPC dependencies
61
+ const createContext = async (innerOpts)=>{
62
+ return await opts.createContext?.({
63
+ ...opts,
64
+ ...innerOpts
87
65
  });
88
66
  };
89
- req.signal.addEventListener('abort', onAbort, {
90
- once: true
91
- });
92
- while(true){
93
- const { done , value: value1 } = await reader.read();
94
- if (done) {
95
- break;
96
- }
97
- if (!res.writable) {
98
- break;
67
+ const response = await resolveResponse({
68
+ ...opts,
69
+ req,
70
+ error: err ? getTRPCErrorFromUnknown(err) : null,
71
+ createContext,
72
+ onError (o) {
73
+ opts?.onError?.({
74
+ ...o,
75
+ req: opts.req
76
+ });
99
77
  }
100
- if (res.write(value1) === false) {
101
- await new Promise((resolve)=>{
102
- res.once('drain', resolve);
78
+ });
79
+ const { res } = opts;
80
+ if (res.statusCode === 200) {
81
+ // if the status code is set, we assume that it's been manually overridden
82
+ res.statusCode = response.status;
83
+ }
84
+ for (const [key, value] of response.headers){
85
+ res.setHeader(key, value);
86
+ }
87
+ if (response.body) {
88
+ const reader = response.body.getReader();
89
+ const onAbort = ()=>{
90
+ // cancelling the reader will cause the whole stream to be cancelled
91
+ reader.cancel().catch(()=>{
92
+ // console.error('reader.cancel() error', err);
103
93
  });
94
+ };
95
+ req.signal.addEventListener('abort', onAbort, {
96
+ once: true
97
+ });
98
+ while(true){
99
+ const { done , value: value1 } = await reader.read();
100
+ if (done) {
101
+ break;
102
+ }
103
+ if (!res.writable) {
104
+ break;
105
+ }
106
+ if (res.write(value1) === false) {
107
+ await new Promise((resolve)=>{
108
+ res.once('drain', resolve);
109
+ });
110
+ }
111
+ // useful for debugging chunked responses:
112
+ // console.log('wrote', Buffer.from(value).toString());
113
+ // IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
114
+ res.flush?.();
104
115
  }
105
- // useful for debugging chunked responses:
106
- // console.log('wrote', Buffer.from(value).toString());
107
- // IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
108
- res.flush?.();
116
+ req.signal.removeEventListener('abort', onAbort);
109
117
  }
110
- req.signal.removeEventListener('abort', onAbort);
111
- }
112
- res.end();
113
- }).catch(internal_exceptionHandler(opts));
118
+ res.end();
119
+ }).catch(internal_exceptionHandler(opts));
120
+ });
114
121
  });
115
122
  }
116
123
 
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,IAAI,CAAC,eAAe,CA6BtB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,wEAGxC"}
1
+ {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,IAAI,CAAC,eAAe,CAyBtB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,wEAGxC"}
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var http = require('node:http');
4
+ var utils = require('../unstable-core-do-not-import/utils.js');
4
5
  var toURL = require('../unstable-core-do-not-import/http/toURL.js');
5
6
  require('../unstable-core-do-not-import/rootConfig.js');
6
7
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
@@ -10,25 +11,23 @@ var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
10
11
  */ function createHTTPHandler(opts) {
11
12
  return (req, res)=>{
12
13
  let path = '';
13
- try {
14
+ utils.run(async ()=>{
14
15
  const url = toURL.toURL(req.url);
15
16
  // get procedure path and remove the leading slash
16
17
  // /procedure -> procedure
17
18
  path = url.pathname.slice(1);
18
- nodeHTTPRequestHandler.nodeHTTPRequestHandler({
19
+ await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
19
20
  ...opts,
20
21
  req,
21
22
  res,
22
23
  path
23
24
  });
24
- } catch (cause) {
25
- nodeHTTPRequestHandler.internal_exceptionHandler({
26
- req,
27
- res,
28
- path,
29
- ...opts
30
- })(cause);
31
- }
25
+ }).catch(nodeHTTPRequestHandler.internal_exceptionHandler({
26
+ req,
27
+ res,
28
+ path,
29
+ ...opts
30
+ }));
32
31
  };
33
32
  }
34
33
  function createHTTPServer(opts) {
@@ -1,4 +1,5 @@
1
1
  import http from 'node:http';
2
+ import { run } from '../unstable-core-do-not-import/utils.mjs';
2
3
  import { toURL } from '../unstable-core-do-not-import/http/toURL.mjs';
3
4
  import '../unstable-core-do-not-import/rootConfig.mjs';
4
5
  import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
@@ -8,25 +9,23 @@ import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/n
8
9
  */ function createHTTPHandler(opts) {
9
10
  return (req, res)=>{
10
11
  let path = '';
11
- try {
12
+ run(async ()=>{
12
13
  const url = toURL(req.url);
13
14
  // get procedure path and remove the leading slash
14
15
  // /procedure -> procedure
15
16
  path = url.pathname.slice(1);
16
- nodeHTTPRequestHandler({
17
+ await nodeHTTPRequestHandler({
17
18
  ...opts,
18
19
  req,
19
20
  res,
20
21
  path
21
22
  });
22
- } catch (cause) {
23
- internal_exceptionHandler({
24
- req,
25
- res,
26
- path,
27
- ...opts
28
- })(cause);
29
- }
23
+ }).catch(internal_exceptionHandler({
24
+ req,
25
+ res,
26
+ path,
27
+ ...opts
28
+ }));
30
29
  };
31
30
  }
32
31
  function createHTTPServer(opts) {