@node-red/editor-client 3.0.2 → 3.1.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.
- package/locales/de/editor.json +2 -0
- package/locales/de/infotips.json +0 -0
- package/locales/de/jsonata.json +0 -0
- package/locales/en-US/editor.json +37 -6
- package/locales/en-US/infotips.json +0 -0
- package/locales/en-US/jsonata.json +0 -0
- package/locales/fr/editor.json +1238 -0
- package/locales/fr/infotips.json +23 -0
- package/locales/fr/jsonata.json +274 -0
- package/locales/ja/editor.json +48 -9
- package/locales/ko/editor.json +233 -31
- package/locales/ko/infotips.json +0 -0
- package/locales/ko/jsonata.json +0 -0
- package/locales/pt-BR/editor.json +1208 -0
- package/locales/pt-BR/infotips.json +23 -0
- package/locales/pt-BR/jsonata.json +274 -0
- package/locales/ru/editor.json +2 -0
- package/locales/ru/infotips.json +0 -0
- package/locales/ru/jsonata.json +0 -0
- package/locales/zh-CN/editor.json +1175 -1049
- package/locales/zh-TW/editor.json +3 -0
- package/package.json +1 -1
- package/public/red/about +140 -0
- package/public/red/red.js +2699 -1397
- package/public/red/red.min.js +4 -3
- package/public/red/style.min.css +1 -1
- package/public/red/tours/3.0/images/context-menu.png +0 -0
- package/public/red/tours/3.0/welcome.js +155 -0
- package/public/red/tours/images/context-menu.png +0 -0
- package/public/red/tours/images/global-env-vars.png +0 -0
- package/public/red/tours/images/hiding-flows.png +0 -0
- package/public/red/tours/images/locking-flows.png +0 -0
- package/public/red/tours/images/mermaid.png +0 -0
- package/public/red/tours/images/node-help.png +0 -0
- package/public/red/tours/images/tab-changes.png +0 -0
- package/public/red/tours/welcome.js +111 -94
- package/public/types/node/assert/strict.d.ts +11 -0
- package/public/types/node/assert.d.ts +898 -64
- package/public/types/node/async_hooks.d.ts +362 -94
- package/public/types/node/buffer.d.ts +2158 -14
- package/public/types/node/child_process.d.ts +1109 -257
- package/public/types/node/cluster.d.ts +349 -200
- package/public/types/node/console.d.ts +313 -43
- package/public/types/node/crypto.d.ts +3329 -656
- package/public/types/node/dgram.d.ts +459 -58
- package/public/types/node/diagnostics_channel.d.ts +155 -0
- package/public/types/node/dns/promises.d.ts +371 -0
- package/public/types/node/dns.d.ts +532 -265
- package/public/types/node/domain.d.ts +159 -16
- package/public/types/node/events.d.ts +589 -30
- package/public/types/node/fs/promises.d.ts +1097 -0
- package/public/types/node/fs.d.ts +2484 -958
- package/public/types/node/globals.d.ts +43 -503
- package/public/types/node/http.d.ts +1156 -145
- package/public/types/node/http2.d.ts +1610 -470
- package/public/types/node/https.d.ts +462 -72
- package/public/types/node/module.d.ts +72 -13
- package/public/types/node/net.d.ts +663 -131
- package/public/types/node/os.d.ts +238 -25
- package/public/types/node/path.d.ts +57 -23
- package/public/types/node/perf_hooks.d.ts +424 -112
- package/public/types/node/process.d.ts +1261 -193
- package/public/types/node/querystring.d.ts +107 -7
- package/public/types/node/readline.d.ts +443 -74
- package/public/types/node/stream/consumers.d.ts +15 -0
- package/public/types/node/stream/promises.d.ts +45 -0
- package/public/types/node/stream/web.d.ts +395 -0
- package/public/types/node/stream.d.ts +1081 -177
- package/public/types/node/string_decoder.d.ts +57 -0
- package/public/types/node/test.d.ts +193 -0
- package/public/types/node/timers/promises.d.ts +96 -0
- package/public/types/node/timers.d.ts +87 -12
- package/public/types/node/tls.d.ts +457 -222
- package/public/types/node/trace_events.d.ts +107 -10
- package/public/types/node/tty.d.ts +158 -23
- package/public/types/node/url.d.ts +734 -28
- package/public/types/node/util.d.ts +1542 -164
- package/public/types/node/v8.d.ts +261 -73
- package/public/types/node/vm.d.ts +384 -32
- package/public/types/node/wasi.d.ts +92 -23
- package/public/types/node/worker_threads.d.ts +531 -123
- package/public/types/node/zlib.d.ts +216 -63
- package/public/types/node-red/func.d.ts +3 -0
- package/public/vendor/jquery/css/base/images/ui-icons_444444_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_555555_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777620_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777777_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_cc0000_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_ffffff_256x240.png +0 -0
- package/public/vendor/jquery/css/base/jquery-ui.min.css +4 -4
- package/public/vendor/mermaid/mermaid.min.js +1284 -0
- package/public/vendor/monaco/dist/{ade705761eb7e702770d.ttf → 7064e66c3890a12c47b4.ttf} +0 -0
- package/public/vendor/monaco/dist/css.worker.js +1 -1
- package/public/vendor/monaco/dist/css.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/editor.js +1 -1
- package/public/vendor/monaco/dist/editor.js.LICENSE.txt +5 -1
- package/public/vendor/monaco/dist/editor.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/json.worker.js +1 -1
- package/public/vendor/monaco/dist/json.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/locale/cs.js +319 -71
- package/public/vendor/monaco/dist/locale/de.js +323 -75
- package/public/vendor/monaco/dist/locale/es.js +318 -70
- package/public/vendor/monaco/dist/locale/fr.js +327 -79
- package/public/vendor/monaco/dist/locale/it.js +325 -77
- package/public/vendor/monaco/dist/locale/ja.js +337 -89
- package/public/vendor/monaco/dist/locale/ko.js +324 -76
- package/public/vendor/monaco/dist/locale/pl.js +322 -74
- package/public/vendor/monaco/dist/locale/pt-br.js +321 -73
- package/public/vendor/monaco/dist/locale/qps-ploc.js +1580 -1332
- package/public/vendor/monaco/dist/locale/ru.js +324 -76
- package/public/vendor/monaco/dist/locale/tr.js +326 -78
- package/public/vendor/monaco/dist/locale/zh-hans.js +328 -80
- package/public/vendor/monaco/dist/locale/zh-hant.js +321 -73
- package/public/vendor/monaco/dist/theme/forge.json +236 -0
- package/public/vendor/monaco/dist/theme/github-dark.json +348 -0
- package/public/vendor/monaco/dist/theme/github-light.json +348 -0
- package/public/vendor/monaco/dist/theme/nord.json +93 -0
- package/public/vendor/monaco/dist/ts.worker.js +1 -1
- package/public/vendor/monaco/dist/ts.worker.js.LICENSE.txt +14 -6
- package/public/vendor/vendor.js +9 -15
- /package/public/red/tours/{images → 3.0/images}/continuous-search.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/debug-path-tooltip.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-quick-add.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-slice.gif +0 -0
- /package/public/red/tours/{images → 3.0/images}/split-wire-with-links.gif +0 -0
|
@@ -2,18 +2,49 @@
|
|
|
2
2
|
/* NOTE: Do not edit directly! This file is generated using `npm run update-types` in https://github.com/Steve-Mcl/monaco-editor-esm-i18n */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
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/v16.9.0/lib/async_hooks.js)
|
|
6
13
|
*/
|
|
7
14
|
declare module 'async_hooks' {
|
|
8
15
|
/**
|
|
9
|
-
*
|
|
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.
|
|
10
45
|
*/
|
|
11
46
|
function executionAsyncId(): number;
|
|
12
|
-
|
|
13
47
|
/**
|
|
14
|
-
* The resource representing the current execution.
|
|
15
|
-
* Useful to store data within the resource.
|
|
16
|
-
*
|
|
17
48
|
* Resource objects returned by `executionAsyncResource()` are most often internal
|
|
18
49
|
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
|
19
50
|
* on the object is likely to crash your application and should be avoided.
|
|
@@ -21,14 +52,70 @@ declare module 'async_hooks' {
|
|
|
21
52
|
* Using `executionAsyncResource()` in the top-level execution context will
|
|
22
53
|
* return an empty object as there is no handle or request object to use,
|
|
23
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.
|
|
24
96
|
*/
|
|
25
97
|
function executionAsyncResource(): object;
|
|
26
|
-
|
|
27
98
|
/**
|
|
28
|
-
*
|
|
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.
|
|
29
117
|
*/
|
|
30
118
|
function triggerAsyncId(): number;
|
|
31
|
-
|
|
32
119
|
interface HookCallbacks {
|
|
33
120
|
/**
|
|
34
121
|
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
|
@@ -38,73 +125,133 @@ declare module 'async_hooks' {
|
|
|
38
125
|
* @param resource reference to the resource representing the async operation, needs to be released during destroy
|
|
39
126
|
*/
|
|
40
127
|
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
|
41
|
-
|
|
42
128
|
/**
|
|
43
129
|
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
|
44
130
|
* The before callback is called just before said callback is executed.
|
|
45
131
|
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
|
46
132
|
*/
|
|
47
133
|
before?(asyncId: number): void;
|
|
48
|
-
|
|
49
134
|
/**
|
|
50
135
|
* Called immediately after the callback specified in before is completed.
|
|
51
136
|
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
|
52
137
|
*/
|
|
53
138
|
after?(asyncId: number): void;
|
|
54
|
-
|
|
55
139
|
/**
|
|
56
140
|
* Called when a promise has resolve() called. This may not be in the same execution id
|
|
57
141
|
* as the promise itself.
|
|
58
142
|
* @param asyncId the unique id for the promise that was resolve()d.
|
|
59
143
|
*/
|
|
60
144
|
promiseResolve?(asyncId: number): void;
|
|
61
|
-
|
|
62
145
|
/**
|
|
63
146
|
* Called after the resource corresponding to asyncId is destroyed
|
|
64
147
|
* @param asyncId a unique ID for the async resource
|
|
65
148
|
*/
|
|
66
149
|
destroy?(asyncId: number): void;
|
|
67
150
|
}
|
|
68
|
-
|
|
69
151
|
interface AsyncHook {
|
|
70
152
|
/**
|
|
71
153
|
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
|
72
154
|
*/
|
|
73
155
|
enable(): this;
|
|
74
|
-
|
|
75
156
|
/**
|
|
76
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.
|
|
77
158
|
*/
|
|
78
159
|
disable(): this;
|
|
79
160
|
}
|
|
80
|
-
|
|
81
161
|
/**
|
|
82
|
-
* Registers functions to be called for different lifetime events of each async
|
|
83
|
-
*
|
|
84
|
-
*
|
|
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
|
|
85
202
|
*/
|
|
86
|
-
function createHook(
|
|
87
|
-
|
|
203
|
+
function createHook(callbacks: HookCallbacks): AsyncHook;
|
|
88
204
|
interface AsyncResourceOptions {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
requireManualDestroy?: boolean | undefined;
|
|
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;
|
|
103
218
|
}
|
|
104
|
-
|
|
105
219
|
/**
|
|
106
|
-
* The class AsyncResource
|
|
107
|
-
* Using this users can easily trigger the lifetime events of their
|
|
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
|
+
* ```
|
|
108
255
|
*/
|
|
109
256
|
class AsyncResource {
|
|
110
257
|
/**
|
|
@@ -114,115 +261,236 @@ declare module 'async_hooks' {
|
|
|
114
261
|
* @param type The type of async event.
|
|
115
262
|
* @param triggerAsyncId The ID of the execution context that created
|
|
116
263
|
* this async event (default: `executionAsyncId()`), or an
|
|
117
|
-
* AsyncResourceOptions object (since
|
|
264
|
+
* AsyncResourceOptions object (since v9.3.0)
|
|
118
265
|
*/
|
|
119
|
-
constructor(type: string, triggerAsyncId?: number|AsyncResourceOptions);
|
|
120
|
-
|
|
266
|
+
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
|
121
267
|
/**
|
|
122
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
|
|
123
273
|
* @param fn The function to bind to the current execution context.
|
|
124
274
|
* @param type An optional name to associate with the underlying `AsyncResource`.
|
|
125
275
|
*/
|
|
126
|
-
static bind<Func extends (...args: any[]) => any>(
|
|
127
|
-
|
|
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
|
+
};
|
|
128
283
|
/**
|
|
129
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
|
|
130
289
|
* @param fn The function to bind to the current `AsyncResource`.
|
|
131
290
|
*/
|
|
132
|
-
bind<Func extends (...args: any[]) => any>(
|
|
133
|
-
|
|
291
|
+
bind<Func extends (...args: any[]) => any>(
|
|
292
|
+
fn: Func
|
|
293
|
+
): Func & {
|
|
294
|
+
asyncResource: AsyncResource;
|
|
295
|
+
};
|
|
134
296
|
/**
|
|
135
|
-
* Call the provided function with the provided arguments in the
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @param fn The function to call in the execution context of this
|
|
141
|
-
* async resource.
|
|
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.
|
|
142
303
|
* @param thisArg The receiver to be used for the function call.
|
|
143
304
|
* @param args Optional arguments to pass to the function.
|
|
144
305
|
*/
|
|
145
306
|
runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;
|
|
146
|
-
|
|
147
307
|
/**
|
|
148
|
-
* Call
|
|
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`.
|
|
149
313
|
*/
|
|
150
314
|
emitDestroy(): this;
|
|
151
|
-
|
|
152
315
|
/**
|
|
153
|
-
* @return
|
|
316
|
+
* @return The unique `asyncId` assigned to the resource.
|
|
154
317
|
*/
|
|
155
318
|
asyncId(): number;
|
|
156
|
-
|
|
157
319
|
/**
|
|
158
|
-
*
|
|
320
|
+
*
|
|
321
|
+
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
|
159
322
|
*/
|
|
160
323
|
triggerAsyncId(): number;
|
|
161
324
|
}
|
|
162
|
-
|
|
163
325
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
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 data.
|
|
371
|
+
* @since v13.10.0, v12.17.0
|
|
166
372
|
*/
|
|
167
373
|
class AsyncLocalStorage<T> {
|
|
168
374
|
/**
|
|
169
|
-
*
|
|
170
|
-
* to `asyncLocalStorage.getStore()` will return `undefined` until
|
|
171
|
-
* `asyncLocalStorage.run()` is called again.
|
|
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.
|
|
172
377
|
*
|
|
173
378
|
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
|
174
379
|
* instance will be exited.
|
|
175
380
|
*
|
|
176
|
-
* Calling `asyncLocalStorage.disable()` is required before the
|
|
177
|
-
* `asyncLocalStorage` can be garbage collected. This does not apply to stores
|
|
381
|
+
* Calling `asyncLocalStorage.disable()` is required before the`asyncLocalStorage` can be garbage collected. This does not apply to stores
|
|
178
382
|
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
|
179
383
|
* along with the corresponding async resources.
|
|
180
384
|
*
|
|
181
|
-
*
|
|
385
|
+
* Use this method when the `asyncLocalStorage` is not in use anymore
|
|
182
386
|
* in the current process.
|
|
387
|
+
* @since v13.10.0, v12.17.0
|
|
388
|
+
* @experimental
|
|
183
389
|
*/
|
|
184
390
|
disable(): void;
|
|
185
|
-
|
|
186
391
|
/**
|
|
187
|
-
*
|
|
188
|
-
* asynchronous context initialized by
|
|
189
|
-
*
|
|
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
|
|
190
397
|
*/
|
|
191
398
|
getStore(): T | undefined;
|
|
192
|
-
|
|
193
399
|
/**
|
|
194
|
-
*
|
|
400
|
+
* Runs a function synchronously within a context and returns its
|
|
195
401
|
* return value. The store is not accessible outside of the callback function or
|
|
196
402
|
* the asynchronous operations created within the callback.
|
|
197
403
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
404
|
+
* The optional `args` are passed to the callback function.
|
|
405
|
+
*
|
|
406
|
+
* If the callback function throws an error, the error is thrown by `run()` too.
|
|
407
|
+
* The stacktrace is not impacted by this call and the context is exited.
|
|
408
|
+
*
|
|
409
|
+
* Example:
|
|
200
410
|
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
411
|
+
* ```js
|
|
412
|
+
* const store = { id: 2 };
|
|
413
|
+
* try {
|
|
414
|
+
* asyncLocalStorage.run(store, () => {
|
|
415
|
+
* asyncLocalStorage.getStore(); // Returns the store object
|
|
416
|
+
* throw new Error();
|
|
417
|
+
* });
|
|
418
|
+
* } catch (e) {
|
|
419
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
420
|
+
* // The error will be caught here
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
* @since v13.10.0, v12.17.0
|
|
203
424
|
*/
|
|
204
|
-
|
|
205
|
-
run<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R;
|
|
206
|
-
|
|
425
|
+
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
|
207
426
|
/**
|
|
208
|
-
*
|
|
209
|
-
* return value. The store is not accessible within the callback function or
|
|
210
|
-
* asynchronous operations created within the callback.
|
|
427
|
+
* Runs a function synchronously outside of a context and returns its
|
|
428
|
+
* return value. The store is not accessible within the callback function or
|
|
429
|
+
* the asynchronous operations created within the callback. Any `getStore()`call done within the callback function will always return `undefined`.
|
|
430
|
+
*
|
|
431
|
+
* The optional `args` are passed to the callback function.
|
|
432
|
+
*
|
|
433
|
+
* If the callback function throws an error, the error is thrown by `exit()` too.
|
|
434
|
+
* The stacktrace is not impacted by this call and the context is re-entered.
|
|
211
435
|
*
|
|
212
|
-
*
|
|
213
|
-
* callback function.
|
|
436
|
+
* Example:
|
|
214
437
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
438
|
+
* ```js
|
|
439
|
+
* // Within a call to run
|
|
440
|
+
* try {
|
|
441
|
+
* asyncLocalStorage.getStore(); // Returns the store object or value
|
|
442
|
+
* asyncLocalStorage.exit(() => {
|
|
443
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
444
|
+
* throw new Error();
|
|
445
|
+
* });
|
|
446
|
+
* } catch (e) {
|
|
447
|
+
* asyncLocalStorage.getStore(); // Returns the same object or value
|
|
448
|
+
* // The error will be caught here
|
|
449
|
+
* }
|
|
450
|
+
* ```
|
|
451
|
+
* @since v13.10.0, v12.17.0
|
|
452
|
+
* @experimental
|
|
218
453
|
*/
|
|
219
|
-
|
|
220
|
-
exit<R>(callback: (...args: any[]) => R, ...args: any[]): R;
|
|
221
|
-
|
|
454
|
+
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
|
|
222
455
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
456
|
+
* Transitions into the context for the remainder of the current
|
|
457
|
+
* synchronous execution and then persists the store through any following
|
|
458
|
+
* asynchronous calls.
|
|
459
|
+
*
|
|
460
|
+
* Example:
|
|
461
|
+
*
|
|
462
|
+
* ```js
|
|
463
|
+
* const store = { id: 1 };
|
|
464
|
+
* // Replaces previous store with the given store object
|
|
465
|
+
* asyncLocalStorage.enterWith(store);
|
|
466
|
+
* asyncLocalStorage.getStore(); // Returns the store object
|
|
467
|
+
* someAsyncOperation(() => {
|
|
468
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
469
|
+
* });
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* This transition will continue for the _entire_ synchronous execution.
|
|
473
|
+
* This means that if, for example, the context is entered within an event
|
|
474
|
+
* handler subsequent event handlers will also run within that context unless
|
|
475
|
+
* specifically bound to another context with an `AsyncResource`. That is why`run()` should be preferred over `enterWith()` unless there are strong reasons
|
|
476
|
+
* to use the latter method.
|
|
477
|
+
*
|
|
478
|
+
* ```js
|
|
479
|
+
* const store = { id: 1 };
|
|
480
|
+
*
|
|
481
|
+
* emitter.on('my-event', () => {
|
|
482
|
+
* asyncLocalStorage.enterWith(store);
|
|
483
|
+
* });
|
|
484
|
+
* emitter.on('my-event', () => {
|
|
485
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
486
|
+
* });
|
|
487
|
+
*
|
|
488
|
+
* asyncLocalStorage.getStore(); // Returns undefined
|
|
489
|
+
* emitter.emit('my-event');
|
|
490
|
+
* asyncLocalStorage.getStore(); // Returns the same object
|
|
491
|
+
* ```
|
|
492
|
+
* @since v13.11.0, v12.17.0
|
|
493
|
+
* @experimental
|
|
226
494
|
*/
|
|
227
495
|
enterWith(store: T): void;
|
|
228
496
|
}
|