@node-red/editor-client 2.0.4 → 2.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.
Files changed (77) hide show
  1. package/locales/en-US/editor.json +37 -7
  2. package/locales/ko/editor.json +1 -1
  3. package/package.json +2 -2
  4. package/public/red/about +109 -0
  5. package/public/red/images/node-red-256.svg +1 -0
  6. package/public/red/keymap.json +13 -2
  7. package/public/red/red.js +6122 -3663
  8. package/public/red/red.min.js +1 -1
  9. package/public/red/style.min.css +2 -2
  10. package/public/red/tours/first-flow.js +80 -0
  11. package/public/red/tours/welcome.js +135 -0
  12. package/public/tours/first-flow.js +82 -0
  13. package/public/types/node/assert.d.ts +127 -0
  14. package/public/types/node/async_hooks.d.ts +229 -0
  15. package/public/types/node/buffer.d.ts +25 -1
  16. package/public/types/node/child_process.d.ts +514 -6
  17. package/public/types/node/cluster.d.ts +265 -0
  18. package/public/types/node/console.d.ts +136 -1
  19. package/public/types/node/crypto.d.ts +1189 -1
  20. package/public/types/node/dgram.d.ts +144 -1
  21. package/public/types/node/dns.d.ts +383 -10
  22. package/public/types/node/domain.d.ts +27 -1
  23. package/public/types/node/events.d.ts +81 -1
  24. package/public/types/node/fs.d.ts +2273 -1
  25. package/public/types/node/globals.d.ts +616 -1
  26. package/public/types/node/http.d.ts +489 -1
  27. package/public/types/node/http2.d.ts +961 -0
  28. package/public/types/node/https.d.ts +142 -0
  29. package/public/types/node/module.d.ts +55 -0
  30. package/public/types/node/net.d.ts +296 -1
  31. package/public/types/node/os.d.ts +242 -1
  32. package/public/types/node/path.d.ts +156 -1
  33. package/public/types/node/perf_hooks.d.ts +274 -0
  34. package/public/types/node/process.d.ts +412 -1
  35. package/public/types/node/querystring.d.ts +31 -1
  36. package/public/types/node/readline.d.ts +173 -0
  37. package/public/types/node/stream.d.ts +358 -0
  38. package/public/types/node/string_decoder.d.ts +10 -0
  39. package/public/types/node/timers.d.ts +19 -0
  40. package/public/types/node/tls.d.ts +783 -0
  41. package/public/types/node/trace_events.d.ts +64 -0
  42. package/public/types/node/tty.d.ts +69 -0
  43. package/public/types/node/url.d.ts +119 -1
  44. package/public/types/node/util.d.ts +210 -0
  45. package/public/types/node/v8.d.ts +190 -0
  46. package/public/types/node/vm.d.ts +155 -0
  47. package/public/types/node/wasi.d.ts +89 -0
  48. package/public/types/node/worker_threads.d.ts +241 -0
  49. package/public/types/node/zlib.d.ts +364 -0
  50. package/public/types/node-red/func.d.ts +1 -1
  51. package/public/types/node-red/util.d.ts +1 -1
  52. package/public/vendor/ace/worker-jsonata.js +1 -1
  53. package/public/vendor/monaco/dist/ThirdPartyNotices.txt +192 -192
  54. package/public/vendor/monaco/dist/css.worker.js +1 -1
  55. package/public/vendor/monaco/dist/editor.js +2 -2
  56. package/public/vendor/monaco/dist/editor.worker.js +1 -1
  57. package/public/vendor/monaco/dist/html.worker.js +1 -1
  58. package/public/vendor/monaco/dist/json.worker.js +1 -1
  59. package/public/vendor/monaco/dist/locale/cs.js +44 -10
  60. package/public/vendor/monaco/dist/locale/de.js +46 -12
  61. package/public/vendor/monaco/dist/locale/es.js +46 -12
  62. package/public/vendor/monaco/dist/locale/fr.js +43 -9
  63. package/public/vendor/monaco/dist/locale/it.js +45 -11
  64. package/public/vendor/monaco/dist/locale/ja.js +45 -11
  65. package/public/vendor/monaco/dist/locale/ko.js +44 -10
  66. package/public/vendor/monaco/dist/locale/pl.js +42 -8
  67. package/public/vendor/monaco/dist/locale/pt-br.js +49 -15
  68. package/public/vendor/monaco/dist/locale/qps-ploc.js +1445 -0
  69. package/public/vendor/monaco/dist/locale/ru.js +48 -14
  70. package/public/vendor/monaco/dist/locale/tr.js +49 -15
  71. package/public/vendor/monaco/dist/locale/zh-hans.js +48 -14
  72. package/public/vendor/monaco/dist/locale/zh-hant.js +45 -11
  73. package/public/vendor/monaco/dist/theme/monoindustrial.json +228 -0
  74. package/public/vendor/monaco/dist/theme/solarized-dark.json +1082 -0
  75. package/public/vendor/monaco/dist/ts.worker.js +2 -2
  76. package/public/vendor/vendor.js +4 -4
  77. package/templates/index.mst +5 -1
@@ -0,0 +1,80 @@
1
+ export default {
2
+ steps: [
3
+ {
4
+ title: "Create your first flow",
5
+ width: 400,
6
+ description: 'This tutorial will guide you through creating your first flow',
7
+ nextButton: 'start'
8
+ },
9
+ {
10
+ element: "#red-ui-workspace .red-ui-tab-button.red-ui-tabs-add",
11
+ description: 'To add a new tab, click the <i class="fa fa-plus"></i> button',
12
+ wait: {
13
+ type: "dom-event",
14
+ event: "click",
15
+ element: "#red-ui-workspace .red-ui-tab-button.red-ui-tabs-add a"
16
+ },
17
+ },
18
+ {
19
+ element: '.red-ui-palette-node[data-palette-type="inject"]',
20
+ direction: 'right',
21
+ description: 'The palette lists all of the nodes available to use. Drag a new Inject node into the workspace.',
22
+ fallback: 'inset-bottom-right',
23
+ wait: {
24
+ type: "nr-event",
25
+ event: "nodes:add",
26
+ filter: function(event) {
27
+ if (event.type === "inject") {
28
+ this.injectNode = event;
29
+ return true;
30
+ }
31
+ return false
32
+ }
33
+ },
34
+ complete: function() {
35
+ $('.red-ui-palette-node[data-palette-type="inject"]').css("z-index","auto");
36
+ }
37
+ },
38
+ {
39
+ element: '.red-ui-palette-node[data-palette-type="debug"]',
40
+ direction: 'right',
41
+ description: 'Next, drag a new Debug node into the workspace.',
42
+ fallback: 'inset-bottom-right',
43
+ wait: {
44
+ type: "nr-event",
45
+ event: "nodes:add",
46
+ filter: function(event) {
47
+ if (event.type === "debug") {
48
+ this.debugNode = event;
49
+ return true;
50
+ }
51
+ return false
52
+ }
53
+ },
54
+ complete: function() {
55
+ $('.red-ui-palette-node[data-palette-type="debug"]').css("z-index","auto");
56
+ },
57
+ },
58
+ {
59
+ element: function() { return $("#"+this.injectNode.id+" .red-ui-flow-port") },
60
+ description: 'Add a wire from the output of the Inject node to the input of the Debug node',
61
+ fallback: 'inset-bottom-right',
62
+ wait: {
63
+ type: "nr-event",
64
+ event: "links:add",
65
+ filter: function(event) {
66
+ return event.source.id === this.injectNode.id && event.target.id === this.debugNode.id;
67
+ }
68
+ },
69
+ },
70
+ {
71
+ element: "#red-ui-header-button-deploy",
72
+ description: 'Deploy your changes so the flow is active in the runtime',
73
+ width: 200,
74
+ wait: {
75
+ type: "dom-event",
76
+ event: "click"
77
+ },
78
+ }
79
+ ]
80
+ }
@@ -0,0 +1,135 @@
1
+ export default {
2
+ version: "2.1.0",
3
+ steps: [
4
+ {
5
+ titleIcon: "fa fa-map-o",
6
+ title: { "en-US": "Welcome to Node-RED 2.1!" },
7
+ description: { "en-US": "Let's take a moment to discover the new features in this release." }
8
+ },
9
+ {
10
+ title: { "en-US": "A new Tour Guide" },
11
+ description: { "en-US": "<p>First, as you've already found, we now have this tour of new features. We'll only show the tour the first time you open the editor for each new version of Node-RED.</p>"+
12
+ "<p>You can choose not to see this tour in the future by disabling it under the View tab of User Settings.</p>" }
13
+ },
14
+ {
15
+ title: { "en-US": "New Edit menu" },
16
+ prepare() {
17
+ $("#red-ui-header-button-sidemenu").trigger("click");
18
+ $("#menu-item-edit-menu").parent().addClass("open")
19
+ },
20
+ complete() {
21
+ $("#menu-item-edit-menu").parent().removeClass("open")
22
+ },
23
+ element: "#menu-item-edit-menu-submenu",
24
+ interactive: false,
25
+ direction: "left",
26
+ description: { "en-US": "<p>The main menu has been updated with a new 'Edit' section. This includes all of the familar options, like cut/paste and undo/redo.</p>"+
27
+ "<p>The menu now displays keyboard shortcuts for the options.</p>" }
28
+
29
+ },
30
+ {
31
+ title: { "en-US": "Arranging nodes" },
32
+ prepare() {
33
+ $("#red-ui-header-button-sidemenu").trigger("click");
34
+ $("#menu-item-arrange-menu").parent().addClass("open")
35
+ },
36
+ complete() {
37
+ $("#menu-item-arrange-menu").parent().removeClass("open")
38
+ },
39
+ element: "#menu-item-arrange-menu-submenu",
40
+ interactive: false,
41
+ direction: "left",
42
+ description: { "en-US": "<p>The new 'Arrange' section of the menu provides new options to help arrange your nodes. You can align them to a common edge, spread them out evenly or change their order.</p>" },
43
+ },
44
+ {
45
+ title: { "en-US": "Hiding tabs" },
46
+ element: "#red-ui-workspace-tabs > li.active",
47
+ description: { "en-US": '<p>Tabs can now be hidden by clicking their <i class="fa fa-times"></i> icon.</p><p>The Info Sidebar will still list all of your tabs, and tell you which ones are currently hidden.' },
48
+ interactive: false,
49
+ prepare() {
50
+ $("#red-ui-workspace-tabs > li.active .red-ui-tab-close").css("display","block");
51
+ },
52
+ complete() {
53
+ $("#red-ui-workspace-tabs > li.active .red-ui-tab-close").css("display","");
54
+ }
55
+ },
56
+ {
57
+ title: { "en-US": "Tab menu" },
58
+ element: "#red-ui-workspace-tabs-menu",
59
+ description: { "en-US": '<p>The new tab menu also provides lots of new options for your tabs.</p>' },
60
+ interactive: false,
61
+ direction: "left",
62
+ prepare() {
63
+ $("#red-ui-workspace > .red-ui-tabs > .red-ui-tabs-menu a").trigger("click");
64
+ },
65
+ complete() {
66
+ $(document).trigger("click");
67
+ }
68
+ },
69
+ {
70
+ title: { "en-US": "Flow and Group level environment variables" },
71
+ element: "#red-ui-workspace-tabs > li.active",
72
+ interactive: false,
73
+ description: { "en-US": "<p>Flows and Groups can now have their own environment variables that can be referenced by nodes inside them.</p>" },
74
+ },
75
+ {
76
+ prepare(done) {
77
+ RED.editor.editFlow(RED.nodes.workspace(RED.workspaces.active()),"editor-tab-envProperties");
78
+ setTimeout(done,700);
79
+ },
80
+ element: "#red-ui-tab-editor-tab-envProperties-link-button",
81
+ description: { "en-US": "<p>Their edit dialogs have a new Environment Variables section.</p>" },
82
+ },
83
+ {
84
+ element: ".node-input-env-container-row",
85
+ direction: "left",
86
+ description: { "en-US": '<p>The environment variables are listed in this table and new ones can be added by clicking the <i class="fa fa-plus"></i> button.</p>' },
87
+ complete(done) {
88
+ $("#node-dialog-cancel").trigger("click");
89
+ setTimeout(done,500);
90
+ }
91
+ },
92
+
93
+ {
94
+ title: {"en-US":"Link Call node added"},
95
+ prepare(done) {
96
+ $('[data-palette-type="link call"]')[0].scrollIntoView({block:"center"})
97
+ setTimeout(done,100);
98
+ },
99
+ element: '[data-palette-type="link call"]',
100
+ direction: "right",
101
+ description: { "en-US": '<p>The <code>Link Call</code> node lets you call another flow that begins with a <code>Link In</code> node and get the result back when the message reaches a <code>Link Out</code> node.</p>' },
102
+ },
103
+
104
+ {
105
+ title: {"en-US":"File nodes renamed"},
106
+ prepare(done) {
107
+ $('[data-palette-type="file"]')[0].scrollIntoView({block:"center"})
108
+ setTimeout(done,100);
109
+ },
110
+ element: '[data-palette-type="file"]',
111
+ direction: "right",
112
+ description: { "en-US": '<p>The file nodes have been renamed to make it clearer which node does what.</p>' },
113
+ },
114
+ {
115
+ title: {"en-US":"Deep copy option on Change node"},
116
+ prepare(done) {
117
+ var def = RED.nodes.getType('change')
118
+ RED.editor.edit({id:"test",type:"change",rules:[{t:'set',p:'payload',pt:'msg', tot:'msg',to:"anotherProperty"}],_def:def, _:def._})
119
+ setTimeout(done,700);
120
+ },
121
+ complete(done) {
122
+ $("#node-dialog-cancel").trigger("click");
123
+ setTimeout(done,500);
124
+ },
125
+ element: function() {
126
+ return $(".node-input-rule-property-deepCopy").next()
127
+ },
128
+ description: { "en-US": '<p>The Set rule has a new option to create a deep copy of the value. This ensures a complete copy is made, rather than using a reference.</p>' },
129
+ },
130
+ {
131
+ title: { "en-US": "And that's not all..." },
132
+ description: { "en-US": "<p>There are many more smaller changes, including:</p><ul><li>Auto-complete suggestions in the <code>msg</code> TypedInput.</li><li>Support for <code>msg.resetTimeout</code> in the <code>Join</code> node.</li><li>Pushing messages to the front of the queue in the <code>Delay</code> node's rate limiting mode.</li><li>An optional second output on the <code>Delay</code> node for rate limited messages.</li></ul>" }
133
+ }
134
+ ]
135
+ }
@@ -0,0 +1,82 @@
1
+ export default {
2
+ steps: [
3
+ {
4
+ title: "Create your first flow",
5
+ fullscreen: true,
6
+ direction: "inset",
7
+ width: 400,
8
+ description: 'This tutorial will guide you through creating your first flow',
9
+ nextButton: 'start'
10
+ },
11
+ {
12
+ element: "#red-ui-workspace .red-ui-tab-button.red-ui-tabs-add",
13
+ description: 'To add a new tab, click the <i class="fa fa-plus"></i> button',
14
+ wait: {
15
+ type: "dom-event",
16
+ event: "click",
17
+ element: "#red-ui-workspace .red-ui-tab-button.red-ui-tabs-add a"
18
+ },
19
+ },
20
+ {
21
+ element: '.red-ui-palette-node[data-palette-type="inject"]',
22
+ direction: 'right',
23
+ description: 'The palette lists all of the nodes available to use. Drag a new Inject node into the workspace.',
24
+ fallback: 'inset-bottom-right',
25
+ wait: {
26
+ type: "nr-event",
27
+ event: "nodes:add",
28
+ filter: function(event) {
29
+ if (event.type === "inject") {
30
+ this.injectNode = event;
31
+ return true;
32
+ }
33
+ return false
34
+ }
35
+ },
36
+ complete: function() {
37
+ $('.red-ui-palette-node[data-palette-type="inject"]').css("z-index","auto");
38
+ }
39
+ },
40
+ {
41
+ element: '.red-ui-palette-node[data-palette-type="debug"]',
42
+ direction: 'right',
43
+ description: 'Next, drag a new Debug node into the workspace.',
44
+ fallback: 'inset-bottom-right',
45
+ wait: {
46
+ type: "nr-event",
47
+ event: "nodes:add",
48
+ filter: function(event) {
49
+ if (event.type === "debug") {
50
+ this.debugNode = event;
51
+ return true;
52
+ }
53
+ return false
54
+ }
55
+ },
56
+ complete: function() {
57
+ $('.red-ui-palette-node[data-palette-type="debug"]').css("z-index","auto");
58
+ },
59
+ },
60
+ {
61
+ element: function() { return $("#"+this.injectNode.id+" .red-ui-flow-port") },
62
+ description: 'Add a wire from the output of the Inject node to the input of the Debug node',
63
+ fallback: 'inset-bottom-right',
64
+ wait: {
65
+ type: "nr-event",
66
+ event: "links:add",
67
+ filter: function(event) {
68
+ return event.source.id === this.injectNode.id && event.target.id === this.debugNode.id;
69
+ }
70
+ },
71
+ },
72
+ {
73
+ element: "#red-ui-header-button-deploy",
74
+ description: 'Deploy your changes so the flow is active in the runtime',
75
+ width: 200,
76
+ wait: {
77
+ type: "dom-event",
78
+ event: "click"
79
+ },
80
+ }
81
+ ]
82
+ }
@@ -0,0 +1,127 @@
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
+ declare module 'assert' {
5
+ /** An alias of `assert.ok()`. */
6
+ function assert(value: any, message?: string | Error): asserts value;
7
+ namespace assert {
8
+ class AssertionError extends Error {
9
+ actual: any;
10
+ expected: any;
11
+ operator: string;
12
+ generatedMessage: boolean;
13
+ code: 'ERR_ASSERTION';
14
+
15
+ constructor(options?: {
16
+ /** If provided, the error message is set to this value. */
17
+ message?: string | undefined;
18
+ /** The `actual` property on the error instance. */
19
+ actual?: any;
20
+ /** The `expected` property on the error instance. */
21
+ expected?: any;
22
+ /** The `operator` property on the error instance. */
23
+ operator?: string | undefined;
24
+ /** If provided, the generated stack trace omits frames before this function. */
25
+ // tslint:disable-next-line:ban-types
26
+ stackStartFn?: Function | undefined;
27
+ });
28
+ }
29
+
30
+ class CallTracker {
31
+ calls(exact?: number): () => void;
32
+ calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
33
+ report(): CallTrackerReportInformation[];
34
+ verify(): void;
35
+ }
36
+ interface CallTrackerReportInformation {
37
+ message: string;
38
+ /** The actual number of times the function was called. */
39
+ actual: number;
40
+ /** The number of times the function was expected to be called. */
41
+ expected: number;
42
+ /** The name of the function that is wrapped. */
43
+ operator: string;
44
+ /** A stack trace of the function. */
45
+ stack: object;
46
+ }
47
+
48
+ type AssertPredicate = RegExp | (new () => object) | ((thrown: any) => boolean) | object | Error;
49
+
50
+ function fail(message?: string | Error): never;
51
+ /** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
52
+ function fail(
53
+ actual: any,
54
+ expected: any,
55
+ message?: string | Error,
56
+ operator?: string,
57
+ // tslint:disable-next-line:ban-types
58
+ stackStartFn?: Function,
59
+ ): never;
60
+ function ok(value: any, message?: string | Error): asserts value;
61
+ /** @deprecated since v9.9.0 - use strictEqual() instead. */
62
+ function equal(actual: any, expected: any, message?: string | Error): void;
63
+ /** @deprecated since v9.9.0 - use notStrictEqual() instead. */
64
+ function notEqual(actual: any, expected: any, message?: string | Error): void;
65
+ /** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
66
+ function deepEqual(actual: any, expected: any, message?: string | Error): void;
67
+ /** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
68
+ function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
69
+ function strictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
70
+ function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
71
+ function deepStrictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
72
+ function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
73
+
74
+ function throws(block: () => any, message?: string | Error): void;
75
+ function throws(block: () => any, error: AssertPredicate, message?: string | Error): void;
76
+ function doesNotThrow(block: () => any, message?: string | Error): void;
77
+ function doesNotThrow(block: () => any, error: AssertPredicate, message?: string | Error): void;
78
+
79
+ function ifError(value: any): asserts value is null | undefined;
80
+
81
+ function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
82
+ function rejects(
83
+ block: (() => Promise<any>) | Promise<any>,
84
+ error: AssertPredicate,
85
+ message?: string | Error,
86
+ ): Promise<void>;
87
+ function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
88
+ function doesNotReject(
89
+ block: (() => Promise<any>) | Promise<any>,
90
+ error: AssertPredicate,
91
+ message?: string | Error,
92
+ ): Promise<void>;
93
+
94
+ function match(value: string, regExp: RegExp, message?: string | Error): void;
95
+ function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
96
+
97
+ const strict: Omit<
98
+ typeof assert,
99
+ | 'equal'
100
+ | 'notEqual'
101
+ | 'deepEqual'
102
+ | 'notDeepEqual'
103
+ | 'ok'
104
+ | 'strictEqual'
105
+ | 'deepStrictEqual'
106
+ | 'ifError'
107
+ | 'strict'
108
+ > & {
109
+ (value: any, message?: string | Error): asserts value;
110
+ equal: typeof strictEqual;
111
+ notEqual: typeof notStrictEqual;
112
+ deepEqual: typeof deepStrictEqual;
113
+ notDeepEqual: typeof notDeepStrictEqual;
114
+
115
+ // Mapped types and assertion functions are incompatible?
116
+ // TS2775: Assertions require every name in the call target
117
+ // to be declared with an explicit type annotation.
118
+ ok: typeof ok;
119
+ strictEqual: typeof strictEqual;
120
+ deepStrictEqual: typeof deepStrictEqual;
121
+ ifError: typeof ifError;
122
+ strict: typeof strict;
123
+ };
124
+ }
125
+
126
+ export = assert;
127
+ }
@@ -0,0 +1,229 @@
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
+ * Async Hooks module: https://nodejs.org/api/async_hooks.html
6
+ */
7
+ declare module 'async_hooks' {
8
+ /**
9
+ * Returns the asyncId of the current execution context.
10
+ */
11
+ function executionAsyncId(): number;
12
+
13
+ /**
14
+ * The resource representing the current execution.
15
+ * Useful to store data within the resource.
16
+ *
17
+ * Resource objects returned by `executionAsyncResource()` are most often internal
18
+ * Node.js handle objects with undocumented APIs. Using any functions or properties
19
+ * on the object is likely to crash your application and should be avoided.
20
+ *
21
+ * Using `executionAsyncResource()` in the top-level execution context will
22
+ * return an empty object as there is no handle or request object to use,
23
+ * but having an object representing the top-level can be helpful.
24
+ */
25
+ function executionAsyncResource(): object;
26
+
27
+ /**
28
+ * Returns the ID of the resource responsible for calling the callback that is currently being executed.
29
+ */
30
+ function triggerAsyncId(): number;
31
+
32
+ interface HookCallbacks {
33
+ /**
34
+ * Called when a class is constructed that has the possibility to emit an asynchronous event.
35
+ * @param asyncId a unique ID for the async resource
36
+ * @param type the type of the async resource
37
+ * @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
38
+ * @param resource reference to the resource representing the async operation, needs to be released during destroy
39
+ */
40
+ init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
41
+
42
+ /**
43
+ * When an asynchronous operation is initiated or completes a callback is called to notify the user.
44
+ * The before callback is called just before said callback is executed.
45
+ * @param asyncId the unique identifier assigned to the resource about to execute the callback.
46
+ */
47
+ before?(asyncId: number): void;
48
+
49
+ /**
50
+ * Called immediately after the callback specified in before is completed.
51
+ * @param asyncId the unique identifier assigned to the resource which has executed the callback.
52
+ */
53
+ after?(asyncId: number): void;
54
+
55
+ /**
56
+ * Called when a promise has resolve() called. This may not be in the same execution id
57
+ * as the promise itself.
58
+ * @param asyncId the unique id for the promise that was resolve()d.
59
+ */
60
+ promiseResolve?(asyncId: number): void;
61
+
62
+ /**
63
+ * Called after the resource corresponding to asyncId is destroyed
64
+ * @param asyncId a unique ID for the async resource
65
+ */
66
+ destroy?(asyncId: number): void;
67
+ }
68
+
69
+ interface AsyncHook {
70
+ /**
71
+ * Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
72
+ */
73
+ enable(): this;
74
+
75
+ /**
76
+ * 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
+ */
78
+ disable(): this;
79
+ }
80
+
81
+ /**
82
+ * Registers functions to be called for different lifetime events of each async operation.
83
+ * @param options the callbacks to register
84
+ * @return an AsyncHooks instance used for disabling and enabling hooks
85
+ */
86
+ function createHook(options: HookCallbacks): AsyncHook;
87
+
88
+ interface AsyncResourceOptions {
89
+ /**
90
+ * The ID of the execution context that created this async event.
91
+ * @default executionAsyncId()
92
+ */
93
+ triggerAsyncId?: number | undefined;
94
+
95
+ /**
96
+ * Disables automatic `emitDestroy` when the object is garbage collected.
97
+ * This usually does not need to be set (even if `emitDestroy` is called
98
+ * manually), unless the resource's `asyncId` is retrieved and the
99
+ * sensitive API's `emitDestroy` is called with it.
100
+ * @default false
101
+ */
102
+ requireManualDestroy?: boolean | undefined;
103
+ }
104
+
105
+ /**
106
+ * The class AsyncResource was designed to be extended by the embedder's async resources.
107
+ * Using this users can easily trigger the lifetime events of their own resources.
108
+ */
109
+ class AsyncResource {
110
+ /**
111
+ * AsyncResource() is meant to be extended. Instantiating a
112
+ * new AsyncResource() also triggers init. If triggerAsyncId is omitted then
113
+ * async_hook.executionAsyncId() is used.
114
+ * @param type The type of async event.
115
+ * @param triggerAsyncId The ID of the execution context that created
116
+ * this async event (default: `executionAsyncId()`), or an
117
+ * AsyncResourceOptions object (since 9.3)
118
+ */
119
+ constructor(type: string, triggerAsyncId?: number|AsyncResourceOptions);
120
+
121
+ /**
122
+ * Binds the given function to the current execution context.
123
+ * @param fn The function to bind to the current execution context.
124
+ * @param type An optional name to associate with the underlying `AsyncResource`.
125
+ */
126
+ static bind<Func extends (...args: any[]) => any>(fn: Func, type?: string): Func & { asyncResource: AsyncResource };
127
+
128
+ /**
129
+ * Binds the given function to execute to this `AsyncResource`'s scope.
130
+ * @param fn The function to bind to the current `AsyncResource`.
131
+ */
132
+ bind<Func extends (...args: any[]) => any>(fn: Func): Func & { asyncResource: AsyncResource };
133
+
134
+ /**
135
+ * Call the provided function with the provided arguments in the
136
+ * execution context of the async resource. This will establish the
137
+ * context, trigger the AsyncHooks before callbacks, call the function,
138
+ * trigger the AsyncHooks after callbacks, and then restore the original
139
+ * execution context.
140
+ * @param fn The function to call in the execution context of this
141
+ * async resource.
142
+ * @param thisArg The receiver to be used for the function call.
143
+ * @param args Optional arguments to pass to the function.
144
+ */
145
+ runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;
146
+
147
+ /**
148
+ * Call AsyncHooks destroy callbacks.
149
+ */
150
+ emitDestroy(): this;
151
+
152
+ /**
153
+ * @return the unique ID assigned to this AsyncResource instance.
154
+ */
155
+ asyncId(): number;
156
+
157
+ /**
158
+ * @return the trigger ID for this AsyncResource instance.
159
+ */
160
+ triggerAsyncId(): number;
161
+ }
162
+
163
+ /**
164
+ * When having multiple instances of `AsyncLocalStorage`, they are independent
165
+ * from each other. It is safe to instantiate this class multiple times.
166
+ */
167
+ class AsyncLocalStorage<T> {
168
+ /**
169
+ * This method disables the instance of `AsyncLocalStorage`. All subsequent calls
170
+ * to `asyncLocalStorage.getStore()` will return `undefined` until
171
+ * `asyncLocalStorage.run()` is called again.
172
+ *
173
+ * When calling `asyncLocalStorage.disable()`, all current contexts linked to the
174
+ * instance will be exited.
175
+ *
176
+ * Calling `asyncLocalStorage.disable()` is required before the
177
+ * `asyncLocalStorage` can be garbage collected. This does not apply to stores
178
+ * provided by the `asyncLocalStorage`, as those objects are garbage collected
179
+ * along with the corresponding async resources.
180
+ *
181
+ * This method is to be used when the `asyncLocalStorage` is not in use anymore
182
+ * in the current process.
183
+ */
184
+ disable(): void;
185
+
186
+ /**
187
+ * This method returns the current store. If this method is called outside of an
188
+ * asynchronous context initialized by calling `asyncLocalStorage.run`, it will
189
+ * return `undefined`.
190
+ */
191
+ getStore(): T | undefined;
192
+
193
+ /**
194
+ * This methods runs a function synchronously within a context and return its
195
+ * return value. The store is not accessible outside of the callback function or
196
+ * the asynchronous operations created within the callback.
197
+ *
198
+ * Optionally, arguments can be passed to the function. They will be passed to the
199
+ * callback function.
200
+ *
201
+ * I the callback function throws an error, it will be thrown by `run` too. The
202
+ * stacktrace will not be impacted by this call and the context will be exited.
203
+ */
204
+ // TODO: Apply generic vararg once available
205
+ run<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R;
206
+
207
+ /**
208
+ * This methods runs a function synchronously outside of a context and return its
209
+ * return value. The store is not accessible within the callback function or the
210
+ * asynchronous operations created within the callback.
211
+ *
212
+ * Optionally, arguments can be passed to the function. They will be passed to the
213
+ * callback function.
214
+ *
215
+ * If the callback function throws an error, it will be thrown by `exit` too. The
216
+ * stacktrace will not be impacted by this call and the context will be
217
+ * re-entered.
218
+ */
219
+ // TODO: Apply generic vararg once available
220
+ exit<R>(callback: (...args: any[]) => R, ...args: any[]): R;
221
+
222
+ /**
223
+ * Calling `asyncLocalStorage.enterWith(store)` will transition into the context
224
+ * for the remainder of the current synchronous execution and will persist
225
+ * through any following asynchronous calls.
226
+ */
227
+ enterWith(store: T): void;
228
+ }
229
+ }