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