typespeed 2.3.6 → 2.4.2

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 (258) hide show
  1. package/app/src/config-development.json +3 -2
  2. package/app/src/test-socket.class.ts +56 -0
  3. package/app/src/views/socket.html +23 -0
  4. package/dist/introduction/decorator/example-import.class.js +17 -0
  5. package/dist/introduction/decorator/main-app.js +14 -0
  6. package/dist/introduction/decorator/main-decorator.js +127 -0
  7. package/dist/introduction/decorator/main-import.js +1 -0
  8. package/dist/introduction/decorator/main-reflect.js +38 -0
  9. package/dist/introduction/web-services/db-init.js +33 -0
  10. package/dist/introduction/web-services/db-singleton.js +49 -0
  11. package/dist/introduction/web-services/http-if.js +12 -0
  12. package/dist/introduction/web-services/http-init.js +7 -0
  13. package/dist/introduction/web-services/http-router.js +23 -0
  14. package/dist/{database.decorator.js → src/database.decorator.js} +2 -4
  15. package/dist/{default → src/default}/express-server.class.js +20 -5
  16. package/dist/{default → src/default}/rabbitmq.class.js +3 -3
  17. package/dist/{default → src/default}/redis.class.js +1 -1
  18. package/dist/src/default/socket-io.class.js +64 -0
  19. package/dist/{typespeed.js → src/typespeed.js} +6 -3
  20. package/dist/typespeed.d.ts +19 -1
  21. package/package.json +8 -8
  22. package/src/database.decorator.ts +2 -4
  23. package/src/default/express-server.class.ts +18 -7
  24. package/src/default/rabbitmq.class.ts +3 -3
  25. package/src/default/redis.class.ts +1 -1
  26. package/src/default/socket-io.class.ts +68 -0
  27. package/src/factory/server-factory.class.ts +1 -1
  28. package/src/typespeed.d.ts +19 -1
  29. package/src/typespeed.ts +7 -4
  30. package/test/socket.test.ts +60 -0
  31. package/tsconfig.json +2 -1
  32. package/app/node_modules/.package-lock.json +0 -134
  33. package/app/node_modules/@types/body-parser/LICENSE +0 -21
  34. package/app/node_modules/@types/body-parser/README.md +0 -16
  35. package/app/node_modules/@types/body-parser/index.d.ts +0 -107
  36. package/app/node_modules/@types/body-parser/package.json +0 -58
  37. package/app/node_modules/@types/connect/LICENSE +0 -21
  38. package/app/node_modules/@types/connect/README.md +0 -16
  39. package/app/node_modules/@types/connect/index.d.ts +0 -93
  40. package/app/node_modules/@types/connect/package.json +0 -32
  41. package/app/node_modules/@types/express/LICENSE +0 -21
  42. package/app/node_modules/@types/express/README.md +0 -16
  43. package/app/node_modules/@types/express/index.d.ts +0 -136
  44. package/app/node_modules/@types/express/package.json +0 -45
  45. package/app/node_modules/@types/express-serve-static-core/LICENSE +0 -21
  46. package/app/node_modules/@types/express-serve-static-core/README.md +0 -16
  47. package/app/node_modules/@types/express-serve-static-core/index.d.ts +0 -1281
  48. package/app/node_modules/@types/express-serve-static-core/package.json +0 -55
  49. package/app/node_modules/@types/mime/LICENSE +0 -21
  50. package/app/node_modules/@types/mime/Mime.d.ts +0 -10
  51. package/app/node_modules/@types/mime/README.md +0 -16
  52. package/app/node_modules/@types/mime/index.d.ts +0 -35
  53. package/app/node_modules/@types/mime/lite.d.ts +0 -7
  54. package/app/node_modules/@types/mime/package.json +0 -29
  55. package/app/node_modules/@types/node/LICENSE +0 -21
  56. package/app/node_modules/@types/node/README.md +0 -16
  57. package/app/node_modules/@types/node/assert/strict.d.ts +0 -8
  58. package/app/node_modules/@types/node/assert.d.ts +0 -961
  59. package/app/node_modules/@types/node/async_hooks.d.ts +0 -518
  60. package/app/node_modules/@types/node/buffer.d.ts +0 -2323
  61. package/app/node_modules/@types/node/child_process.d.ts +0 -1399
  62. package/app/node_modules/@types/node/cluster.d.ts +0 -410
  63. package/app/node_modules/@types/node/console.d.ts +0 -412
  64. package/app/node_modules/@types/node/constants.d.ts +0 -18
  65. package/app/node_modules/@types/node/crypto.d.ts +0 -3973
  66. package/app/node_modules/@types/node/dgram.d.ts +0 -545
  67. package/app/node_modules/@types/node/diagnostics_channel.d.ts +0 -192
  68. package/app/node_modules/@types/node/dns/promises.d.ts +0 -370
  69. package/app/node_modules/@types/node/dns.d.ts +0 -660
  70. package/app/node_modules/@types/node/dom-events.d.ts +0 -126
  71. package/app/node_modules/@types/node/domain.d.ts +0 -170
  72. package/app/node_modules/@types/node/events.d.ts +0 -682
  73. package/app/node_modules/@types/node/fs/promises.d.ts +0 -1159
  74. package/app/node_modules/@types/node/fs.d.ts +0 -3976
  75. package/app/node_modules/@types/node/globals.d.ts +0 -303
  76. package/app/node_modules/@types/node/globals.global.d.ts +0 -1
  77. package/app/node_modules/@types/node/http.d.ts +0 -1714
  78. package/app/node_modules/@types/node/http2.d.ts +0 -2133
  79. package/app/node_modules/@types/node/https.d.ts +0 -542
  80. package/app/node_modules/@types/node/index.d.ts +0 -134
  81. package/app/node_modules/@types/node/inspector.d.ts +0 -2741
  82. package/app/node_modules/@types/node/module.d.ts +0 -115
  83. package/app/node_modules/@types/node/net.d.ts +0 -883
  84. package/app/node_modules/@types/node/os.d.ts +0 -473
  85. package/app/node_modules/@types/node/package.json +0 -237
  86. package/app/node_modules/@types/node/path.d.ts +0 -191
  87. package/app/node_modules/@types/node/perf_hooks.d.ts +0 -625
  88. package/app/node_modules/@types/node/process.d.ts +0 -1488
  89. package/app/node_modules/@types/node/punycode.d.ts +0 -117
  90. package/app/node_modules/@types/node/querystring.d.ts +0 -131
  91. package/app/node_modules/@types/node/readline/promises.d.ts +0 -143
  92. package/app/node_modules/@types/node/readline.d.ts +0 -653
  93. package/app/node_modules/@types/node/repl.d.ts +0 -424
  94. package/app/node_modules/@types/node/stream/consumers.d.ts +0 -12
  95. package/app/node_modules/@types/node/stream/promises.d.ts +0 -42
  96. package/app/node_modules/@types/node/stream/web.d.ts +0 -330
  97. package/app/node_modules/@types/node/stream.d.ts +0 -1440
  98. package/app/node_modules/@types/node/string_decoder.d.ts +0 -67
  99. package/app/node_modules/@types/node/test.d.ts +0 -783
  100. package/app/node_modules/@types/node/timers/promises.d.ts +0 -93
  101. package/app/node_modules/@types/node/timers.d.ts +0 -101
  102. package/app/node_modules/@types/node/tls.d.ts +0 -1111
  103. package/app/node_modules/@types/node/trace_events.d.ts +0 -171
  104. package/app/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  105. package/app/node_modules/@types/node/ts4.8/assert.d.ts +0 -961
  106. package/app/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -518
  107. package/app/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2323
  108. package/app/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1399
  109. package/app/node_modules/@types/node/ts4.8/cluster.d.ts +0 -410
  110. package/app/node_modules/@types/node/ts4.8/console.d.ts +0 -412
  111. package/app/node_modules/@types/node/ts4.8/constants.d.ts +0 -18
  112. package/app/node_modules/@types/node/ts4.8/crypto.d.ts +0 -3972
  113. package/app/node_modules/@types/node/ts4.8/dgram.d.ts +0 -545
  114. package/app/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -192
  115. package/app/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -370
  116. package/app/node_modules/@types/node/ts4.8/dns.d.ts +0 -660
  117. package/app/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -126
  118. package/app/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  119. package/app/node_modules/@types/node/ts4.8/events.d.ts +0 -682
  120. package/app/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1138
  121. package/app/node_modules/@types/node/ts4.8/fs.d.ts +0 -3875
  122. package/app/node_modules/@types/node/ts4.8/globals.d.ts +0 -302
  123. package/app/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  124. package/app/node_modules/@types/node/ts4.8/http.d.ts +0 -1651
  125. package/app/node_modules/@types/node/ts4.8/http2.d.ts +0 -2133
  126. package/app/node_modules/@types/node/ts4.8/https.d.ts +0 -542
  127. package/app/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  128. package/app/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2741
  129. package/app/node_modules/@types/node/ts4.8/module.d.ts +0 -115
  130. package/app/node_modules/@types/node/ts4.8/net.d.ts +0 -883
  131. package/app/node_modules/@types/node/ts4.8/os.d.ts +0 -473
  132. package/app/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  133. package/app/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -625
  134. package/app/node_modules/@types/node/ts4.8/process.d.ts +0 -1488
  135. package/app/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  136. package/app/node_modules/@types/node/ts4.8/querystring.d.ts +0 -131
  137. package/app/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -143
  138. package/app/node_modules/@types/node/ts4.8/readline.d.ts +0 -653
  139. package/app/node_modules/@types/node/ts4.8/repl.d.ts +0 -424
  140. package/app/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  141. package/app/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -42
  142. package/app/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -330
  143. package/app/node_modules/@types/node/ts4.8/stream.d.ts +0 -1440
  144. package/app/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  145. package/app/node_modules/@types/node/ts4.8/test.d.ts +0 -784
  146. package/app/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  147. package/app/node_modules/@types/node/ts4.8/timers.d.ts +0 -94
  148. package/app/node_modules/@types/node/ts4.8/tls.d.ts +0 -1111
  149. package/app/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -171
  150. package/app/node_modules/@types/node/ts4.8/tty.d.ts +0 -206
  151. package/app/node_modules/@types/node/ts4.8/url.d.ts +0 -902
  152. package/app/node_modules/@types/node/ts4.8/util.d.ts +0 -2017
  153. package/app/node_modules/@types/node/ts4.8/v8.d.ts +0 -541
  154. package/app/node_modules/@types/node/ts4.8/vm.d.ts +0 -644
  155. package/app/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
  156. package/app/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -695
  157. package/app/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  158. package/app/node_modules/@types/node/tty.d.ts +0 -206
  159. package/app/node_modules/@types/node/url.d.ts +0 -902
  160. package/app/node_modules/@types/node/util.d.ts +0 -2017
  161. package/app/node_modules/@types/node/v8.d.ts +0 -541
  162. package/app/node_modules/@types/node/vm.d.ts +0 -644
  163. package/app/node_modules/@types/node/wasi.d.ts +0 -158
  164. package/app/node_modules/@types/node/worker_threads.d.ts +0 -695
  165. package/app/node_modules/@types/node/zlib.d.ts +0 -517
  166. package/app/node_modules/@types/qs/LICENSE +0 -21
  167. package/app/node_modules/@types/qs/README.md +0 -16
  168. package/app/node_modules/@types/qs/index.d.ts +0 -62
  169. package/app/node_modules/@types/qs/package.json +0 -65
  170. package/app/node_modules/@types/range-parser/LICENSE +0 -21
  171. package/app/node_modules/@types/range-parser/README.md +0 -55
  172. package/app/node_modules/@types/range-parser/index.d.ts +0 -35
  173. package/app/node_modules/@types/range-parser/package.json +0 -25
  174. package/app/node_modules/@types/send/LICENSE +0 -21
  175. package/app/node_modules/@types/send/README.md +0 -16
  176. package/app/node_modules/@types/send/index.d.ts +0 -231
  177. package/app/node_modules/@types/send/package.json +0 -33
  178. package/app/node_modules/@types/serve-static/LICENSE +0 -21
  179. package/app/node_modules/@types/serve-static/README.md +0 -16
  180. package/app/node_modules/@types/serve-static/index.d.ts +0 -113
  181. package/app/node_modules/@types/serve-static/package.json +0 -38
  182. package/app/node_modules/colors/LICENSE +0 -25
  183. package/app/node_modules/colors/README.md +0 -221
  184. package/app/node_modules/colors/examples/normal-usage.js +0 -82
  185. package/app/node_modules/colors/examples/safe-string.js +0 -79
  186. package/app/node_modules/colors/index.d.ts +0 -136
  187. package/app/node_modules/colors/lib/colors.js +0 -211
  188. package/app/node_modules/colors/lib/custom/trap.js +0 -46
  189. package/app/node_modules/colors/lib/custom/zalgo.js +0 -110
  190. package/app/node_modules/colors/lib/extendStringPrototype.js +0 -110
  191. package/app/node_modules/colors/lib/index.js +0 -13
  192. package/app/node_modules/colors/lib/maps/america.js +0 -10
  193. package/app/node_modules/colors/lib/maps/rainbow.js +0 -12
  194. package/app/node_modules/colors/lib/maps/random.js +0 -11
  195. package/app/node_modules/colors/lib/maps/zebra.js +0 -5
  196. package/app/node_modules/colors/lib/styles.js +0 -95
  197. package/app/node_modules/colors/lib/system/has-flag.js +0 -35
  198. package/app/node_modules/colors/lib/system/supports-colors.js +0 -151
  199. package/app/node_modules/colors/package.json +0 -45
  200. package/app/node_modules/colors/safe.d.ts +0 -48
  201. package/app/node_modules/colors/safe.js +0 -10
  202. package/app/node_modules/colors/themes/generic-logging.js +0 -12
  203. package/app/node_modules/dateformat/LICENSE +0 -20
  204. package/app/node_modules/dateformat/Readme.md +0 -204
  205. package/app/node_modules/dateformat/lib/dateformat.js +0 -1
  206. package/app/node_modules/dateformat/package.json +0 -38
  207. package/app/node_modules/mkdirp/CHANGELOG.md +0 -15
  208. package/app/node_modules/mkdirp/LICENSE +0 -21
  209. package/app/node_modules/mkdirp/bin/cmd.js +0 -68
  210. package/app/node_modules/mkdirp/index.js +0 -31
  211. package/app/node_modules/mkdirp/lib/find-made.js +0 -29
  212. package/app/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
  213. package/app/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
  214. package/app/node_modules/mkdirp/lib/opts-arg.js +0 -23
  215. package/app/node_modules/mkdirp/lib/path-arg.js +0 -29
  216. package/app/node_modules/mkdirp/lib/use-native.js +0 -10
  217. package/app/node_modules/mkdirp/package.json +0 -44
  218. package/app/node_modules/mkdirp/readme.markdown +0 -266
  219. package/app/node_modules/tinytim/.travis.yml +0 -5
  220. package/app/node_modules/tinytim/README.md +0 -212
  221. package/app/node_modules/tinytim/index.js +0 -1
  222. package/app/node_modules/tinytim/lib/index.js +0 -55
  223. package/app/node_modules/tinytim/lib/tinytim.js +0 -50
  224. package/app/node_modules/tinytim/package.json +0 -24
  225. package/app/node_modules/tinytim/test/files/html.tim +0 -1
  226. package/app/node_modules/tinytim/test/files/string.tim +0 -1
  227. package/app/node_modules/tinytim/test/files/string2.tim +0 -1
  228. package/app/node_modules/tinytim/test/render-file-replace.js +0 -39
  229. package/app/node_modules/tinytim/test/render-replace.js +0 -94
  230. package/app/node_modules/tinytim/test/tim-replace.js +0 -95
  231. package/app/node_modules/tracer/README.md +0 -747
  232. package/app/node_modules/tracer/lib/color_console.js +0 -15
  233. package/app/node_modules/tracer/lib/console.js +0 -165
  234. package/app/node_modules/tracer/lib/dailyfile.js +0 -92
  235. package/app/node_modules/tracer/lib/index.js +0 -10
  236. package/app/node_modules/tracer/lib/settings.js +0 -25
  237. package/app/node_modules/tracer/lib/utils.js +0 -58
  238. package/app/node_modules/tracer/package.json +0 -53
  239. package/app/node_modules/tracer/types/index.d.ts +0 -189
  240. package/dist/scaffold/templates/front-page.class.ts.tpl +0 -12
  241. package/dist/scaffold/templates/main.ts.tpl +0 -13
  242. package/dist/scaffold/templates/nodemon.json.tpl +0 -7
  243. package/dist/scaffold/templates/package.json.tpl +0 -16
  244. package/dist/scaffold/templates/tsconfig.json.tpl +0 -20
  245. /package/dist/{core.decorator.js → src/core.decorator.js} +0 -0
  246. /package/dist/{default → src/default}/default-authentication.class.js +0 -0
  247. /package/dist/{default → src/default}/log-default.class.js +0 -0
  248. /package/dist/{default → src/default}/node-cache.class.js +0 -0
  249. /package/dist/{default → src/default}/pages/404.html +0 -0
  250. /package/dist/{default → src/default}/pages/500.html +0 -0
  251. /package/dist/{default → src/default}/read-write-db.class.js +0 -0
  252. /package/dist/{factory → src/factory}/authentication-factory.class.js +0 -0
  253. /package/dist/{factory → src/factory}/cache-factory.class.js +0 -0
  254. /package/dist/{factory → src/factory}/data-source-factory.class.js +0 -0
  255. /package/dist/{factory → src/factory}/log-factory.class.js +0 -0
  256. /package/dist/{factory → src/factory}/server-factory.class.js +0 -0
  257. /package/dist/{route.decorator.js → src/route.decorator.js} +0 -0
  258. /package/dist/{scaffold → src/scaffold}/command.js +0 -0
@@ -1,518 +0,0 @@
1
- /**
2
- * The `async_hooks` module provides an API to track asynchronous resources. It
3
- * can be accessed using:
4
- *
5
- * ```js
6
- * import async_hooks from 'async_hooks';
7
- * ```
8
- * @experimental
9
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/async_hooks.js)
10
- */
11
- declare module 'async_hooks' {
12
- /**
13
- * ```js
14
- * import { executionAsyncId } from 'async_hooks';
15
- *
16
- * console.log(executionAsyncId()); // 1 - bootstrap
17
- * fs.open(path, 'r', (err, fd) => {
18
- * console.log(executionAsyncId()); // 6 - open()
19
- * });
20
- * ```
21
- *
22
- * The ID returned from `executionAsyncId()` is related to execution timing, not
23
- * causality (which is covered by `triggerAsyncId()`):
24
- *
25
- * ```js
26
- * const server = net.createServer((conn) => {
27
- * // Returns the ID of the server, not of the new connection, because the
28
- * // callback runs in the execution scope of the server's MakeCallback().
29
- * async_hooks.executionAsyncId();
30
- *
31
- * }).listen(port, () => {
32
- * // Returns the ID of a TickObject (process.nextTick()) because all
33
- * // callbacks passed to .listen() are wrapped in a nextTick().
34
- * async_hooks.executionAsyncId();
35
- * });
36
- * ```
37
- *
38
- * Promise contexts may not get precise `executionAsyncIds` by default.
39
- * See the section on `promise execution tracking`.
40
- * @since v8.1.0
41
- * @return The `asyncId` of the current execution context. Useful to track when something calls.
42
- */
43
- function executionAsyncId(): number;
44
- /**
45
- * Resource objects returned by `executionAsyncResource()` are most often internal
46
- * Node.js handle objects with undocumented APIs. Using any functions or properties
47
- * on the object is likely to crash your application and should be avoided.
48
- *
49
- * Using `executionAsyncResource()` in the top-level execution context will
50
- * return an empty object as there is no handle or request object to use,
51
- * but having an object representing the top-level can be helpful.
52
- *
53
- * ```js
54
- * import { open } from 'fs';
55
- * import { executionAsyncId, executionAsyncResource } from 'async_hooks';
56
- *
57
- * console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
58
- * open(new URL(import.meta.url), 'r', (err, fd) => {
59
- * console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
60
- * });
61
- * ```
62
- *
63
- * This can be used to implement continuation local storage without the
64
- * use of a tracking `Map` to store the metadata:
65
- *
66
- * ```js
67
- * import { createServer } from 'http';
68
- * import {
69
- * executionAsyncId,
70
- * executionAsyncResource,
71
- * createHook
72
- * } from 'async_hooks';
73
- * const sym = Symbol('state'); // Private symbol to avoid pollution
74
- *
75
- * createHook({
76
- * init(asyncId, type, triggerAsyncId, resource) {
77
- * const cr = executionAsyncResource();
78
- * if (cr) {
79
- * resource[sym] = cr[sym];
80
- * }
81
- * }
82
- * }).enable();
83
- *
84
- * const server = createServer((req, res) => {
85
- * executionAsyncResource()[sym] = { state: req.url };
86
- * setTimeout(function() {
87
- * res.end(JSON.stringify(executionAsyncResource()[sym]));
88
- * }, 100);
89
- * }).listen(3000);
90
- * ```
91
- * @since v13.9.0, v12.17.0
92
- * @return The resource representing the current execution. Useful to store data within the resource.
93
- */
94
- function executionAsyncResource(): object;
95
- /**
96
- * ```js
97
- * const server = net.createServer((conn) => {
98
- * // The resource that caused (or triggered) this callback to be called
99
- * // was that of the new connection. Thus the return value of triggerAsyncId()
100
- * // is the asyncId of "conn".
101
- * async_hooks.triggerAsyncId();
102
- *
103
- * }).listen(port, () => {
104
- * // Even though all callbacks passed to .listen() are wrapped in a nextTick()
105
- * // the callback itself exists because the call to the server's .listen()
106
- * // was made. So the return value would be the ID of the server.
107
- * async_hooks.triggerAsyncId();
108
- * });
109
- * ```
110
- *
111
- * Promise contexts may not get valid `triggerAsyncId`s by default. See
112
- * the section on `promise execution tracking`.
113
- * @return The ID of the resource responsible for calling the callback that is currently being executed.
114
- */
115
- function triggerAsyncId(): number;
116
- interface HookCallbacks {
117
- /**
118
- * Called when a class is constructed that has the possibility to emit an asynchronous event.
119
- * @param asyncId a unique ID for the async resource
120
- * @param type the type of the async resource
121
- * @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
122
- * @param resource reference to the resource representing the async operation, needs to be released during destroy
123
- */
124
- init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
125
- /**
126
- * When an asynchronous operation is initiated or completes a callback is called to notify the user.
127
- * The before callback is called just before said callback is executed.
128
- * @param asyncId the unique identifier assigned to the resource about to execute the callback.
129
- */
130
- before?(asyncId: number): void;
131
- /**
132
- * Called immediately after the callback specified in before is completed.
133
- * @param asyncId the unique identifier assigned to the resource which has executed the callback.
134
- */
135
- after?(asyncId: number): void;
136
- /**
137
- * Called when a promise has resolve() called. This may not be in the same execution id
138
- * as the promise itself.
139
- * @param asyncId the unique id for the promise that was resolve()d.
140
- */
141
- promiseResolve?(asyncId: number): void;
142
- /**
143
- * Called after the resource corresponding to asyncId is destroyed
144
- * @param asyncId a unique ID for the async resource
145
- */
146
- destroy?(asyncId: number): void;
147
- }
148
- interface AsyncHook {
149
- /**
150
- * Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
151
- */
152
- enable(): this;
153
- /**
154
- * Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
155
- */
156
- disable(): this;
157
- }
158
- /**
159
- * Registers functions to be called for different lifetime events of each async
160
- * operation.
161
- *
162
- * The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
163
- * respective asynchronous event during a resource's lifetime.
164
- *
165
- * All callbacks are optional. For example, if only resource cleanup needs to
166
- * be tracked, then only the `destroy` callback needs to be passed. The
167
- * specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
168
- *
169
- * ```js
170
- * import { createHook } from 'async_hooks';
171
- *
172
- * const asyncHook = createHook({
173
- * init(asyncId, type, triggerAsyncId, resource) { },
174
- * destroy(asyncId) { }
175
- * });
176
- * ```
177
- *
178
- * The callbacks will be inherited via the prototype chain:
179
- *
180
- * ```js
181
- * class MyAsyncCallbacks {
182
- * init(asyncId, type, triggerAsyncId, resource) { }
183
- * destroy(asyncId) {}
184
- * }
185
- *
186
- * class MyAddedCallbacks extends MyAsyncCallbacks {
187
- * before(asyncId) { }
188
- * after(asyncId) { }
189
- * }
190
- *
191
- * const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
192
- * ```
193
- *
194
- * Because promises are asynchronous resources whose lifecycle is tracked
195
- * via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
196
- * @since v8.1.0
197
- * @param callbacks The `Hook Callbacks` to register
198
- * @return Instance used for disabling and enabling hooks
199
- */
200
- function createHook(callbacks: HookCallbacks): AsyncHook;
201
- interface AsyncResourceOptions {
202
- /**
203
- * The ID of the execution context that created this async event.
204
- * @default executionAsyncId()
205
- */
206
- triggerAsyncId?: number | undefined;
207
- /**
208
- * Disables automatic `emitDestroy` when the object is garbage collected.
209
- * This usually does not need to be set (even if `emitDestroy` is called
210
- * manually), unless the resource's `asyncId` is retrieved and the
211
- * sensitive API's `emitDestroy` is called with it.
212
- * @default false
213
- */
214
- requireManualDestroy?: boolean | undefined;
215
- }
216
- /**
217
- * The class `AsyncResource` is designed to be extended by the embedder's async
218
- * resources. Using this, users can easily trigger the lifetime events of their
219
- * own resources.
220
- *
221
- * The `init` hook will trigger when an `AsyncResource` is instantiated.
222
- *
223
- * The following is an overview of the `AsyncResource` API.
224
- *
225
- * ```js
226
- * import { AsyncResource, executionAsyncId } from 'async_hooks';
227
- *
228
- * // AsyncResource() is meant to be extended. Instantiating a
229
- * // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
230
- * // async_hook.executionAsyncId() is used.
231
- * const asyncResource = new AsyncResource(
232
- * type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }
233
- * );
234
- *
235
- * // Run a function in the execution context of the resource. This will
236
- * // * establish the context of the resource
237
- * // * trigger the AsyncHooks before callbacks
238
- * // * call the provided function `fn` with the supplied arguments
239
- * // * trigger the AsyncHooks after callbacks
240
- * // * restore the original execution context
241
- * asyncResource.runInAsyncScope(fn, thisArg, ...args);
242
- *
243
- * // Call AsyncHooks destroy callbacks.
244
- * asyncResource.emitDestroy();
245
- *
246
- * // Return the unique ID assigned to the AsyncResource instance.
247
- * asyncResource.asyncId();
248
- *
249
- * // Return the trigger ID for the AsyncResource instance.
250
- * asyncResource.triggerAsyncId();
251
- * ```
252
- */
253
- class AsyncResource {
254
- /**
255
- * AsyncResource() is meant to be extended. Instantiating a
256
- * new AsyncResource() also triggers init. If triggerAsyncId is omitted then
257
- * async_hook.executionAsyncId() is used.
258
- * @param type The type of async event.
259
- * @param triggerAsyncId The ID of the execution context that created
260
- * this async event (default: `executionAsyncId()`), or an
261
- * AsyncResourceOptions object (since v9.3.0)
262
- */
263
- constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
264
- /**
265
- * Binds the given function to the current execution context.
266
- *
267
- * The returned function will have an `asyncResource` property referencing
268
- * the `AsyncResource` to which the function is bound.
269
- * @since v14.8.0, v12.19.0
270
- * @param fn The function to bind to the current execution context.
271
- * @param type An optional name to associate with the underlying `AsyncResource`.
272
- */
273
- static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
274
- fn: Func,
275
- type?: string,
276
- thisArg?: ThisArg
277
- ): Func & {
278
- asyncResource: AsyncResource;
279
- };
280
- /**
281
- * Binds the given function to execute to this `AsyncResource`'s scope.
282
- *
283
- * The returned function will have an `asyncResource` property referencing
284
- * the `AsyncResource` to which the function is bound.
285
- * @since v14.8.0, v12.19.0
286
- * @param fn The function to bind to the current `AsyncResource`.
287
- */
288
- bind<Func extends (...args: any[]) => any>(
289
- fn: Func
290
- ): Func & {
291
- asyncResource: AsyncResource;
292
- };
293
- /**
294
- * Call the provided function with the provided arguments in the execution context
295
- * of the async resource. This will establish the context, trigger the AsyncHooks
296
- * before callbacks, call the function, trigger the AsyncHooks after callbacks, and
297
- * then restore the original execution context.
298
- * @since v9.6.0
299
- * @param fn The function to call in the execution context of this async resource.
300
- * @param thisArg The receiver to be used for the function call.
301
- * @param args Optional arguments to pass to the function.
302
- */
303
- runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;
304
- /**
305
- * Call all `destroy` hooks. This should only ever be called once. An error will
306
- * be thrown if it is called more than once. This **must** be manually called. If
307
- * the resource is left to be collected by the GC then the `destroy` hooks will
308
- * never be called.
309
- * @return A reference to `asyncResource`.
310
- */
311
- emitDestroy(): this;
312
- /**
313
- * @return The unique `asyncId` assigned to the resource.
314
- */
315
- asyncId(): number;
316
- /**
317
- *
318
- * @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
319
- */
320
- triggerAsyncId(): number;
321
- }
322
- /**
323
- * This class creates stores that stay coherent through asynchronous operations.
324
- *
325
- * While you can create your own implementation on top of the `async_hooks` module,`AsyncLocalStorage` should be preferred as it is a performant and memory safe
326
- * implementation that involves significant optimizations that are non-obvious to
327
- * implement.
328
- *
329
- * The following example uses `AsyncLocalStorage` to build a simple logger
330
- * that assigns IDs to incoming HTTP requests and includes them in messages
331
- * logged within each request.
332
- *
333
- * ```js
334
- * import http from 'http';
335
- * import { AsyncLocalStorage } from 'async_hooks';
336
- *
337
- * const asyncLocalStorage = new AsyncLocalStorage();
338
- *
339
- * function logWithId(msg) {
340
- * const id = asyncLocalStorage.getStore();
341
- * console.log(`${id !== undefined ? id : '-'}:`, msg);
342
- * }
343
- *
344
- * let idSeq = 0;
345
- * http.createServer((req, res) => {
346
- * asyncLocalStorage.run(idSeq++, () => {
347
- * logWithId('start');
348
- * // Imagine any chain of async operations here
349
- * setImmediate(() => {
350
- * logWithId('finish');
351
- * res.end();
352
- * });
353
- * });
354
- * }).listen(8080);
355
- *
356
- * http.get('http://localhost:8080');
357
- * http.get('http://localhost:8080');
358
- * // Prints:
359
- * // 0: start
360
- * // 1: start
361
- * // 0: finish
362
- * // 1: finish
363
- * ```
364
- *
365
- * Each instance of `AsyncLocalStorage` maintains an independent storage context.
366
- * Multiple instances can safely exist simultaneously without risk of interfering
367
- * with each other's data.
368
- * @since v13.10.0, v12.17.0
369
- */
370
- class AsyncLocalStorage<T> {
371
- /**
372
- * Binds the given function to the current execution context.
373
- * @since v18.16.0
374
- * @param fn The function to bind to the current execution context.
375
- * @returns A new function that calls `fn` within the captured execution context.
376
- */
377
- static bind<Func extends (...args: any[]) => any>(fn: Func): Func & {
378
- asyncResource: AsyncResource;
379
- };
380
- /**
381
- * Captures the current execution context and returns a function that accepts a function as an argument.
382
- * Whenever the returned function is called, it calls the function passed to it within the captured context.
383
- * @since v18.16.0
384
- */
385
- static snapshot(): (<R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R) & {
386
- asyncResource: AsyncResource;
387
- };
388
- /**
389
- * Disables the instance of `AsyncLocalStorage`. All subsequent calls
390
- * to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
391
- *
392
- * When calling `asyncLocalStorage.disable()`, all current contexts linked to the
393
- * instance will be exited.
394
- *
395
- * Calling `asyncLocalStorage.disable()` is required before the`asyncLocalStorage` can be garbage collected. This does not apply to stores
396
- * provided by the `asyncLocalStorage`, as those objects are garbage collected
397
- * along with the corresponding async resources.
398
- *
399
- * Use this method when the `asyncLocalStorage` is not in use anymore
400
- * in the current process.
401
- * @since v13.10.0, v12.17.0
402
- * @experimental
403
- */
404
- disable(): void;
405
- /**
406
- * Returns the current store.
407
- * If called outside of an asynchronous context initialized by
408
- * calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
409
- * returns `undefined`.
410
- * @since v13.10.0, v12.17.0
411
- */
412
- getStore(): T | undefined;
413
- /**
414
- * Runs a function synchronously within a context and returns its
415
- * return value. The store is not accessible outside of the callback function.
416
- * The store is accessible to any asynchronous operations created within the
417
- * callback.
418
- *
419
- * The optional `args` are passed to the callback function.
420
- *
421
- * If the callback function throws an error, the error is thrown by `run()` too.
422
- * The stacktrace is not impacted by this call and the context is exited.
423
- *
424
- * Example:
425
- *
426
- * ```js
427
- * const store = { id: 2 };
428
- * try {
429
- * asyncLocalStorage.run(store, () => {
430
- * asyncLocalStorage.getStore(); // Returns the store object
431
- * setTimeout(() => {
432
- * asyncLocalStorage.getStore(); // Returns the store object
433
- * }, 200);
434
- * throw new Error();
435
- * });
436
- * } catch (e) {
437
- * asyncLocalStorage.getStore(); // Returns undefined
438
- * // The error will be caught here
439
- * }
440
- * ```
441
- * @since v13.10.0, v12.17.0
442
- */
443
- run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
444
- /**
445
- * Runs a function synchronously outside of a context and returns its
446
- * return value. The store is not accessible within the callback function or
447
- * the asynchronous operations created within the callback. Any `getStore()`call done within the callback function will always return `undefined`.
448
- *
449
- * The optional `args` are passed to the callback function.
450
- *
451
- * If the callback function throws an error, the error is thrown by `exit()` too.
452
- * The stacktrace is not impacted by this call and the context is re-entered.
453
- *
454
- * Example:
455
- *
456
- * ```js
457
- * // Within a call to run
458
- * try {
459
- * asyncLocalStorage.getStore(); // Returns the store object or value
460
- * asyncLocalStorage.exit(() => {
461
- * asyncLocalStorage.getStore(); // Returns undefined
462
- * throw new Error();
463
- * });
464
- * } catch (e) {
465
- * asyncLocalStorage.getStore(); // Returns the same object or value
466
- * // The error will be caught here
467
- * }
468
- * ```
469
- * @since v13.10.0, v12.17.0
470
- * @experimental
471
- */
472
- exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
473
- /**
474
- * Transitions into the context for the remainder of the current
475
- * synchronous execution and then persists the store through any following
476
- * asynchronous calls.
477
- *
478
- * Example:
479
- *
480
- * ```js
481
- * const store = { id: 1 };
482
- * // Replaces previous store with the given store object
483
- * asyncLocalStorage.enterWith(store);
484
- * asyncLocalStorage.getStore(); // Returns the store object
485
- * someAsyncOperation(() => {
486
- * asyncLocalStorage.getStore(); // Returns the same object
487
- * });
488
- * ```
489
- *
490
- * This transition will continue for the _entire_ synchronous execution.
491
- * This means that if, for example, the context is entered within an event
492
- * handler subsequent event handlers will also run within that context unless
493
- * specifically bound to another context with an `AsyncResource`. That is why`run()` should be preferred over `enterWith()` unless there are strong reasons
494
- * to use the latter method.
495
- *
496
- * ```js
497
- * const store = { id: 1 };
498
- *
499
- * emitter.on('my-event', () => {
500
- * asyncLocalStorage.enterWith(store);
501
- * });
502
- * emitter.on('my-event', () => {
503
- * asyncLocalStorage.getStore(); // Returns the same object
504
- * });
505
- *
506
- * asyncLocalStorage.getStore(); // Returns undefined
507
- * emitter.emit('my-event');
508
- * asyncLocalStorage.getStore(); // Returns the same object
509
- * ```
510
- * @since v13.11.0, v12.17.0
511
- * @experimental
512
- */
513
- enterWith(store: T): void;
514
- }
515
- }
516
- declare module 'node:async_hooks' {
517
- export * from 'async_hooks';
518
- }