firebase-tools 10.9.2 → 11.1.0

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 (181) hide show
  1. package/README.md +15 -9
  2. package/lib/accountImporter.js +92 -93
  3. package/lib/api.js +77 -218
  4. package/lib/apiv2.js +5 -4
  5. package/lib/appdistribution/client.js +16 -25
  6. package/lib/auth.js +69 -47
  7. package/lib/bin/firebase.js +42 -47
  8. package/lib/checkValidTargetFilters.js +13 -12
  9. package/lib/commands/appdistribution-distribute.js +2 -1
  10. package/lib/commands/appdistribution-testers-add.js +2 -1
  11. package/lib/commands/appdistribution-testers-remove.js +2 -1
  12. package/lib/commands/apps-android-sha-create.js +2 -1
  13. package/lib/commands/apps-android-sha-delete.js +2 -1
  14. package/lib/commands/apps-android-sha-list.js +2 -1
  15. package/lib/commands/apps-create.js +2 -1
  16. package/lib/commands/apps-list.js +2 -1
  17. package/lib/commands/apps-sdkconfig.js +8 -3
  18. package/lib/commands/auth-export.js +2 -1
  19. package/lib/commands/auth-import.js +7 -10
  20. package/lib/commands/crashlytics-symbols-upload.js +2 -1
  21. package/lib/commands/database-get.js +4 -3
  22. package/lib/commands/database-instances-create.js +2 -1
  23. package/lib/commands/database-instances-list.js +3 -3
  24. package/lib/commands/database-profile.js +2 -1
  25. package/lib/commands/database-push.js +2 -1
  26. package/lib/commands/database-remove.js +2 -1
  27. package/lib/commands/database-rules-canary.js +2 -1
  28. package/lib/commands/database-rules-get.js +2 -1
  29. package/lib/commands/database-rules-list.js +2 -1
  30. package/lib/commands/database-rules-release.js +2 -1
  31. package/lib/commands/database-rules-stage.js +2 -1
  32. package/lib/commands/database-set.js +2 -1
  33. package/lib/commands/database-settings-get.js +2 -1
  34. package/lib/commands/database-settings-set.js +2 -1
  35. package/lib/commands/database-update.js +2 -1
  36. package/lib/commands/deploy.js +23 -21
  37. package/lib/commands/emulators-exec.js +2 -1
  38. package/lib/commands/emulators-export.js +2 -1
  39. package/lib/commands/emulators-start.js +2 -1
  40. package/lib/commands/experimental-functions-shell.js +10 -8
  41. package/lib/commands/ext-configure.js +56 -120
  42. package/lib/commands/ext-dev-deprecate.js +2 -1
  43. package/lib/commands/ext-dev-emulators-exec.js +13 -7
  44. package/lib/commands/ext-dev-emulators-start.js +12 -27
  45. package/lib/commands/ext-dev-extension-delete.js +2 -1
  46. package/lib/commands/ext-dev-init.js +2 -1
  47. package/lib/commands/ext-dev-list.js +2 -1
  48. package/lib/commands/ext-dev-publish.js +2 -1
  49. package/lib/commands/ext-dev-register.js +2 -1
  50. package/lib/commands/ext-dev-undeprecate.js +2 -1
  51. package/lib/commands/ext-dev-unpublish.js +2 -1
  52. package/lib/commands/ext-dev-usage.js +2 -1
  53. package/lib/commands/ext-export.js +2 -1
  54. package/lib/commands/ext-info.js +2 -1
  55. package/lib/commands/ext-install.js +14 -198
  56. package/lib/commands/ext-list.js +2 -1
  57. package/lib/commands/ext-sources-create.js +2 -1
  58. package/lib/commands/ext-uninstall.js +9 -92
  59. package/lib/commands/ext-update.js +67 -225
  60. package/lib/commands/ext.js +2 -1
  61. package/lib/commands/firestore-delete.js +2 -1
  62. package/lib/commands/firestore-indexes-list.js +2 -1
  63. package/lib/commands/functions-config-clone.js +4 -3
  64. package/lib/commands/functions-config-export.js +2 -1
  65. package/lib/commands/functions-config-get.js +2 -1
  66. package/lib/commands/functions-config-set.js +2 -1
  67. package/lib/commands/functions-config-unset.js +2 -1
  68. package/lib/commands/functions-delete.js +2 -1
  69. package/lib/commands/functions-deletegcfartifacts.js +2 -1
  70. package/lib/commands/functions-list.js +2 -1
  71. package/lib/commands/functions-log.js +2 -1
  72. package/lib/commands/functions-secrets-access.js +2 -1
  73. package/lib/commands/functions-secrets-destroy.js +2 -1
  74. package/lib/commands/functions-secrets-get.js +2 -1
  75. package/lib/commands/functions-secrets-prune.js +2 -1
  76. package/lib/commands/functions-secrets-set.js +2 -1
  77. package/lib/commands/functions-shell.js +12 -10
  78. package/lib/commands/help.js +2 -1
  79. package/lib/commands/hosting-channel-create.js +2 -1
  80. package/lib/commands/hosting-channel-delete.js +2 -1
  81. package/lib/commands/hosting-channel-deploy.js +2 -1
  82. package/lib/commands/hosting-channel-list.js +2 -1
  83. package/lib/commands/hosting-channel-open.js +2 -1
  84. package/lib/commands/hosting-clone.js +2 -1
  85. package/lib/commands/hosting-disable.js +2 -1
  86. package/lib/commands/hosting-sites-create.js +2 -1
  87. package/lib/commands/hosting-sites-delete.js +2 -1
  88. package/lib/commands/hosting-sites-get.js +2 -1
  89. package/lib/commands/hosting-sites-list.js +2 -1
  90. package/lib/commands/index.js +23 -13
  91. package/lib/commands/init.js +47 -43
  92. package/lib/commands/login-add.js +2 -1
  93. package/lib/commands/login-ci.js +2 -1
  94. package/lib/commands/login-list.js +2 -1
  95. package/lib/commands/login-use.js +2 -1
  96. package/lib/commands/login.js +2 -1
  97. package/lib/commands/logout.js +2 -1
  98. package/lib/commands/open.js +2 -1
  99. package/lib/commands/projects-addfirebase.js +2 -1
  100. package/lib/commands/projects-create.js +2 -1
  101. package/lib/commands/projects-list.js +2 -1
  102. package/lib/commands/remoteconfig-get.js +2 -1
  103. package/lib/commands/remoteconfig-rollback.js +2 -1
  104. package/lib/commands/remoteconfig-versions-list.js +2 -1
  105. package/lib/commands/serve.js +29 -27
  106. package/lib/commands/setup-emulators-database.js +2 -1
  107. package/lib/commands/setup-emulators-firestore.js +2 -1
  108. package/lib/commands/setup-emulators-pubsub.js +2 -1
  109. package/lib/commands/setup-emulators-storage.js +2 -1
  110. package/lib/commands/setup-emulators-ui.js +2 -1
  111. package/lib/commands/target-apply.js +2 -1
  112. package/lib/commands/target-clear.js +2 -1
  113. package/lib/commands/target-remove.js +2 -1
  114. package/lib/commands/target.js +2 -1
  115. package/lib/commands/use.js +54 -52
  116. package/lib/config.js +3 -3
  117. package/lib/deploy/database/deploy.js +3 -2
  118. package/lib/deploy/database/index.js +8 -5
  119. package/lib/deploy/database/prepare.js +22 -19
  120. package/lib/deploy/database/release.js +12 -9
  121. package/lib/deploy/firestore/prepare.js +2 -2
  122. package/lib/deploy/functions/build.js +32 -20
  123. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
  124. package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
  125. package/lib/deploy/functions/services/database.js +14 -0
  126. package/lib/deploy/functions/services/index.js +14 -0
  127. package/lib/deploy/index.js +3 -3
  128. package/lib/deploy/lifecycleHooks.js +23 -20
  129. package/lib/deploy/remoteconfig/functions.js +18 -14
  130. package/lib/deploy/remoteconfig/prepare.js +2 -2
  131. package/lib/emulator/auth/apiSpec.js +14 -46
  132. package/lib/emulator/auth/operations.js +6 -29
  133. package/lib/emulator/auth/state.js +2 -25
  134. package/lib/emulator/commandUtils.js +1 -1
  135. package/lib/emulator/controller.js +3 -3
  136. package/lib/emulator/databaseEmulator.js +9 -7
  137. package/lib/emulator/downloadableEmulators.js +6 -6
  138. package/lib/emulator/extensionsEmulator.js +7 -3
  139. package/lib/emulator/firestoreEmulator.js +10 -12
  140. package/lib/emulator/functionsEmulator.js +39 -42
  141. package/lib/emulator/hubClient.js +11 -22
  142. package/lib/emulator/hubExport.js +26 -16
  143. package/lib/emulator/portUtils.js +2 -0
  144. package/lib/emulator/storage/crc.js +3 -0
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/errorOut.js +2 -2
  147. package/lib/extensions/extensionsHelper.js +4 -5
  148. package/lib/extensions/manifest.js +5 -11
  149. package/lib/firebaseConfigValidate.js +1 -1
  150. package/lib/firestore/checkDatabaseType.js +4 -5
  151. package/lib/firestore/indexes.js +17 -34
  152. package/lib/functions/events/v2.js +7 -1
  153. package/lib/functionsConfigClone.js +43 -41
  154. package/lib/gcp/cloudfunctionsv2.js +17 -2
  155. package/lib/gcp/iam.js +1 -1
  156. package/lib/gcp/index.js +10 -10
  157. package/lib/gcp/runtimeconfig.js +45 -47
  158. package/lib/gcp/storage.js +2 -4
  159. package/lib/hosting/cloudRunProxy.js +19 -15
  160. package/lib/index.js +29 -28
  161. package/lib/init/features/database.js +11 -5
  162. package/lib/init/features/functions/index.js +1 -1
  163. package/lib/init/features/functions/javascript.js +23 -20
  164. package/lib/init/features/functions/npm-dependencies.js +17 -14
  165. package/lib/init/features/functions/typescript.js +27 -24
  166. package/lib/init/features/hosting/github.js +5 -4
  167. package/lib/loadCJSON.js +9 -6
  168. package/lib/logError.js +15 -12
  169. package/lib/management/apps.js +47 -43
  170. package/lib/management/database.js +33 -31
  171. package/lib/management/projects.js +13 -7
  172. package/lib/parseBoltRules.js +15 -14
  173. package/lib/profileReport.js +503 -511
  174. package/lib/profiler.js +4 -4
  175. package/lib/requireAuth.js +0 -1
  176. package/lib/responseToError.js +8 -5
  177. package/lib/rtdb.js +31 -29
  178. package/lib/scopes.js +9 -9
  179. package/npm-shrinkwrap.json +1485 -670
  180. package/package.json +21 -22
  181. package/standalone/package.json +1 -1
@@ -1,41 +1,24 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var Table = require("cli-table");
4
- var fs = require("fs");
5
- var _ = require("lodash");
6
- var readline = require("readline");
7
- var { FirebaseError } = require("./error");
8
- const { logger } = require("./logger");
9
- var DATA_LINE_REGEX = /^data: /;
10
- var BANDWIDTH_NOTE = "NOTE: The numbers reported here are only estimates of the data" +
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProfileReport = exports.extractReadableIndex = exports.formatBytes = exports.formatNumber = exports.pathString = exports.extractJSON = void 0;
4
+ const clc = require("cli-color");
5
+ const Table = require("cli-table");
6
+ const fs = require("fs");
7
+ const _ = require("lodash");
8
+ const readline = require("readline");
9
+ const error_1 = require("./error");
10
+ const logger_1 = require("./logger");
11
+ const DATA_LINE_REGEX = /^data: /;
12
+ const BANDWIDTH_NOTE = "NOTE: The numbers reported here are only estimates of the data" +
11
13
  " payloads from read operations. They are NOT a valid measure of your bandwidth bill.";
12
- var SPEED_NOTE = "NOTE: Speeds are reported at millisecond resolution and" +
14
+ const SPEED_NOTE = "NOTE: Speeds are reported at millisecond resolution and" +
13
15
  " are not the latencies that clients will see. Pending times" +
14
16
  " are also reported at millisecond resolution. They approximate" +
15
17
  " the interval of time between the instant a request is received" +
16
18
  " and the instant it executes.";
17
- var COLLAPSE_THRESHOLD = 25;
18
- var COLLAPSE_WILDCARD = ["$wildcard"];
19
- var ProfileReport = function (tmpFile, outStream, options) {
20
- this.tempFile = tmpFile;
21
- this.output = outStream;
22
- this.options = options;
23
- this.state = {
24
- outband: {},
25
- inband: {},
26
- writeSpeed: {},
27
- broadcastSpeed: {},
28
- readSpeed: {},
29
- connectSpeed: {},
30
- disconnectSpeed: {},
31
- unlistenSpeed: {},
32
- unindexed: {},
33
- startTime: 0,
34
- endTime: 0,
35
- opCount: 0,
36
- };
37
- };
38
- ProfileReport.extractJSON = function (line, input) {
19
+ const COLLAPSE_THRESHOLD = 25;
20
+ const COLLAPSE_WILDCARD = ["$wildcard"];
21
+ function extractJSON(line, input) {
39
22
  if (!input && !DATA_LINE_REGEX.test(line)) {
40
23
  return null;
41
24
  }
@@ -48,536 +31,545 @@ ProfileReport.extractJSON = function (line, input) {
48
31
  catch (e) {
49
32
  return null;
50
33
  }
51
- };
52
- ProfileReport.pathString = function (path) {
53
- return "/" + (path ? path.join("/") : "");
54
- };
55
- ProfileReport.formatNumber = function (num) {
56
- var parts = num.toFixed(2).split(".");
34
+ }
35
+ exports.extractJSON = extractJSON;
36
+ function pathString(path) {
37
+ return `/${path ? path.join("/") : ""}`;
38
+ }
39
+ exports.pathString = pathString;
40
+ function formatNumber(num) {
41
+ const parts = num.toFixed(2).split(".");
57
42
  parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
58
43
  if (+parts[1] === 0) {
59
44
  return parts[0];
60
45
  }
61
46
  return parts.join(".");
62
- };
63
- ProfileReport.formatBytes = function (bytes) {
64
- var threshold = 1000;
47
+ }
48
+ exports.formatNumber = formatNumber;
49
+ function formatBytes(bytes) {
50
+ const threshold = 1000;
65
51
  if (Math.round(bytes) < threshold) {
66
52
  return bytes + " B";
67
53
  }
68
- var units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
69
- var u = -1;
70
- var formattedBytes = bytes;
54
+ const units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
55
+ let u = -1;
56
+ let formattedBytes = bytes;
71
57
  do {
72
58
  formattedBytes /= threshold;
73
59
  u++;
74
60
  } while (Math.abs(formattedBytes) >= threshold && u < units.length - 1);
75
- return ProfileReport.formatNumber(formattedBytes) + " " + units[u];
76
- };
77
- ProfileReport.extractReadableIndex = function (query) {
61
+ return formatNumber(formattedBytes) + " " + units[u];
62
+ }
63
+ exports.formatBytes = formatBytes;
64
+ function extractReadableIndex(query) {
78
65
  if (_.has(query, "orderBy")) {
79
66
  return query.orderBy;
80
67
  }
81
- var indexPath = _.get(query, "index.path");
68
+ const indexPath = _.get(query, "index.path");
82
69
  if (indexPath) {
83
- return ProfileReport.pathString(indexPath);
70
+ return pathString(indexPath);
84
71
  }
85
72
  return ".value";
86
- };
87
- ProfileReport.prototype.collectUnindexed = function (data, path) {
88
- if (!data.unIndexed) {
89
- return;
90
- }
91
- if (!_.has(this.state.unindexed, path)) {
92
- this.state.unindexed[path] = {};
93
- }
94
- var pathNode = this.state.unindexed[path];
95
- var query = data.querySet[0];
96
- var index = JSON.stringify(query.index);
97
- if (!_.has(pathNode, index)) {
98
- pathNode[index] = {
99
- times: 0,
100
- query: query,
73
+ }
74
+ exports.extractReadableIndex = extractReadableIndex;
75
+ class ProfileReport {
76
+ constructor(tmpFile, outStream, options = {}) {
77
+ this.tempFile = tmpFile;
78
+ this.output = outStream;
79
+ this.options = options;
80
+ this.state = {
81
+ outband: {},
82
+ inband: {},
83
+ writeSpeed: {},
84
+ broadcastSpeed: {},
85
+ readSpeed: {},
86
+ connectSpeed: {},
87
+ disconnectSpeed: {},
88
+ unlistenSpeed: {},
89
+ unindexed: {},
90
+ startTime: 0,
91
+ endTime: 0,
92
+ opCount: 0,
101
93
  };
102
94
  }
103
- var indexNode = pathNode[index];
104
- indexNode.times += 1;
105
- };
106
- ProfileReport.prototype.collectSpeedUnpathed = function (data, opStats) {
107
- if (Object.keys(opStats).length === 0) {
108
- opStats.times = 0;
109
- opStats.millis = 0;
110
- opStats.pendingCount = 0;
111
- opStats.pendingTime = 0;
112
- opStats.rejected = 0;
113
- }
114
- opStats.times += 1;
115
- if (data.hasOwnProperty("millis")) {
116
- opStats.millis += data.millis;
117
- }
118
- if (data.hasOwnProperty("pendingTime")) {
119
- opStats.pendingCount++;
120
- opStats.pendingTime += data.pendingTime;
121
- }
122
- if (data.allowed === false) {
123
- opStats.rejected += 1;
124
- }
125
- };
126
- ProfileReport.prototype.collectSpeed = function (data, path, opType) {
127
- if (!_.has(opType, path)) {
128
- opType[path] = {
129
- times: 0,
130
- millis: 0,
131
- pendingCount: 0,
132
- pendingTime: 0,
133
- rejected: 0,
134
- };
95
+ collectUnindexed(data, path) {
96
+ if (!data.unIndexed) {
97
+ return;
98
+ }
99
+ if (!_.has(this.state.unindexed, path)) {
100
+ this.state.unindexed[path] = {};
101
+ }
102
+ const pathNode = this.state.unindexed[path];
103
+ const query = data.querySet[0];
104
+ const index = JSON.stringify(query.index);
105
+ if (!_.has(pathNode, index)) {
106
+ pathNode[index] = {
107
+ times: 0,
108
+ query: query,
109
+ };
110
+ }
111
+ const indexNode = pathNode[index];
112
+ indexNode.times += 1;
113
+ }
114
+ collectSpeedUnpathed(data, opStats) {
115
+ if (Object.keys(opStats).length === 0) {
116
+ opStats.times = 0;
117
+ opStats.millis = 0;
118
+ opStats.pendingCount = 0;
119
+ opStats.pendingTime = 0;
120
+ opStats.rejected = 0;
121
+ }
122
+ opStats.times += 1;
123
+ if (data.hasOwnProperty("millis")) {
124
+ opStats.millis += data.millis;
125
+ }
126
+ if (data.hasOwnProperty("pendingTime")) {
127
+ opStats.pendingCount++;
128
+ opStats.pendingTime += data.pendingTime;
129
+ }
130
+ if (data.allowed === false) {
131
+ opStats.rejected += 1;
132
+ }
133
+ }
134
+ collectSpeed(data, path, opType) {
135
+ if (!_.has(opType, path)) {
136
+ opType[path] = {
137
+ times: 0,
138
+ millis: 0,
139
+ pendingCount: 0,
140
+ pendingTime: 0,
141
+ rejected: 0,
142
+ };
143
+ }
144
+ const node = opType[path];
145
+ node.times += 1;
146
+ if (data.hasOwnProperty("millis")) {
147
+ node.millis += data.millis;
148
+ }
149
+ if (data.hasOwnProperty("pendingTime")) {
150
+ node.pendingCount++;
151
+ node.pendingTime += data.pendingTime;
152
+ }
153
+ if (data.allowed === false) {
154
+ node.rejected += 1;
155
+ }
135
156
  }
136
- var node = opType[path];
137
- node.times += 1;
138
- if (data.hasOwnProperty("millis")) {
139
- node.millis += data.millis;
157
+ collectBandwidth(bytes, path, direction) {
158
+ if (!_.has(direction, path)) {
159
+ direction[path] = {
160
+ times: 0,
161
+ bytes: 0,
162
+ };
163
+ }
164
+ const node = direction[path];
165
+ node.times += 1;
166
+ node.bytes += bytes;
140
167
  }
141
- if (data.hasOwnProperty("pendingTime")) {
142
- node.pendingCount++;
143
- node.pendingTime += data.pendingTime;
168
+ collectRead(data, path, bytes) {
169
+ this.collectSpeed(data, path, this.state.readSpeed);
170
+ this.collectBandwidth(bytes, path, this.state.outband);
144
171
  }
145
- if (data.allowed === false) {
146
- node.rejected += 1;
172
+ collectBroadcast(data, path, bytes) {
173
+ this.collectSpeed(data, path, this.state.broadcastSpeed);
174
+ this.collectBandwidth(bytes, path, this.state.outband);
147
175
  }
148
- };
149
- ProfileReport.prototype.collectBandwidth = function (bytes, path, direction) {
150
- if (!_.has(direction, path)) {
151
- direction[path] = {
152
- times: 0,
153
- bytes: 0,
154
- };
176
+ collectUnlisten(data, path) {
177
+ this.collectSpeed(data, path, this.state.unlistenSpeed);
178
+ }
179
+ collectConnect(data) {
180
+ this.collectSpeedUnpathed(data, this.state.connectSpeed);
181
+ }
182
+ collectDisconnect(data) {
183
+ this.collectSpeedUnpathed(data, this.state.disconnectSpeed);
184
+ }
185
+ collectWrite(data, path, bytes) {
186
+ this.collectSpeed(data, path, this.state.writeSpeed);
187
+ this.collectBandwidth(bytes, path, this.state.inband);
188
+ }
189
+ processOperation(data) {
190
+ if (!this.state.startTime) {
191
+ this.state.startTime = data.timestamp;
192
+ }
193
+ this.state.endTime = data.timestamp;
194
+ const path = pathString(data.path);
195
+ this.state.opCount++;
196
+ switch (data.name) {
197
+ case "concurrent-connect":
198
+ this.collectConnect(data);
199
+ break;
200
+ case "concurrent-disconnect":
201
+ this.collectDisconnect(data);
202
+ break;
203
+ case "realtime-read":
204
+ this.collectRead(data, path, data.bytes);
205
+ break;
206
+ case "realtime-write":
207
+ this.collectWrite(data, path, data.bytes);
208
+ break;
209
+ case "realtime-transaction":
210
+ this.collectWrite(data, path, data.bytes);
211
+ break;
212
+ case "realtime-update":
213
+ this.collectWrite(data, path, data.bytes);
214
+ break;
215
+ case "listener-listen":
216
+ this.collectRead(data, path, data.bytes);
217
+ this.collectUnindexed(data, path);
218
+ break;
219
+ case "listener-broadcast":
220
+ this.collectBroadcast(data, path, data.bytes);
221
+ break;
222
+ case "listener-unlisten":
223
+ this.collectUnlisten(data, path);
224
+ break;
225
+ case "rest-read":
226
+ this.collectRead(data, path, data.bytes);
227
+ break;
228
+ case "rest-write":
229
+ this.collectWrite(data, path, data.bytes);
230
+ break;
231
+ case "rest-update":
232
+ this.collectWrite(data, path, data.bytes);
233
+ break;
234
+ default:
235
+ break;
236
+ }
155
237
  }
156
- var node = direction[path];
157
- node.times += 1;
158
- node.bytes += bytes;
159
- };
160
- ProfileReport.prototype.collectRead = function (data, path, bytes) {
161
- this.collectSpeed(data, path, this.state.readSpeed);
162
- this.collectBandwidth(bytes, path, this.state.outband);
163
- };
164
- ProfileReport.prototype.collectBroadcast = function (data, path, bytes) {
165
- this.collectSpeed(data, path, this.state.broadcastSpeed);
166
- this.collectBandwidth(bytes, path, this.state.outband);
167
- };
168
- ProfileReport.prototype.collectUnlisten = function (data, path) {
169
- this.collectSpeed(data, path, this.state.unlistenSpeed);
170
- };
171
- ProfileReport.prototype.collectConnect = function (data) {
172
- this.collectSpeedUnpathed(data, this.state.connectSpeed);
173
- };
174
- ProfileReport.prototype.collectDisconnect = function (data) {
175
- this.collectSpeedUnpathed(data, this.state.disconnectSpeed);
176
- };
177
- ProfileReport.prototype.collectWrite = function (data, path, bytes) {
178
- this.collectSpeed(data, path, this.state.writeSpeed);
179
- this.collectBandwidth(bytes, path, this.state.inband);
180
- };
181
- ProfileReport.prototype.processOperation = function (data) {
182
- if (!this.state.startTime) {
183
- this.state.startTime = data.timestamp;
184
- }
185
- this.state.endTime = data.timestamp;
186
- var path = ProfileReport.pathString(data.path);
187
- this.state.opCount++;
188
- switch (data.name) {
189
- case "concurrent-connect":
190
- this.collectConnect(data);
191
- break;
192
- case "concurrent-disconnect":
193
- this.collectDisconnect(data);
194
- break;
195
- case "realtime-read":
196
- this.collectRead(data, path, data.bytes);
197
- break;
198
- case "realtime-write":
199
- this.collectWrite(data, path, data.bytes);
200
- break;
201
- case "realtime-transaction":
202
- this.collectWrite(data, path, data.bytes);
203
- break;
204
- case "realtime-update":
205
- this.collectWrite(data, path, data.bytes);
206
- break;
207
- case "listener-listen":
208
- this.collectRead(data, path, data.bytes);
209
- this.collectUnindexed(data, path);
210
- break;
211
- case "listener-broadcast":
212
- this.collectBroadcast(data, path, data.bytes);
213
- break;
214
- case "listener-unlisten":
215
- this.collectUnlisten(data, path);
216
- break;
217
- case "rest-read":
218
- this.collectRead(data, path, data.bytes);
219
- break;
220
- case "rest-write":
221
- this.collectWrite(data, path, data.bytes);
222
- break;
223
- case "rest-update":
224
- this.collectWrite(data, path, data.bytes);
225
- break;
226
- default:
227
- break;
228
- }
229
- };
230
- ProfileReport.prototype.collapsePaths = function (pathedObject, combiner, pathIndex) {
231
- if (!this.options.collapse) {
232
- return pathedObject;
233
- }
234
- if (_.isUndefined(pathIndex)) {
235
- pathIndex = 1;
236
- }
237
- var allSegments = _.keys(pathedObject).map(function (path) {
238
- return path.split("/").filter(function (s) {
239
- return s !== "";
238
+ collapsePaths(pathedObject, combiner, pathIndex = 1) {
239
+ if (!this.options.collapse) {
240
+ return pathedObject;
241
+ }
242
+ const allSegments = _.keys(pathedObject).map((path) => {
243
+ return path.split("/").filter((s) => {
244
+ return s !== "";
245
+ });
240
246
  });
241
- });
242
- var pathSegments = allSegments.filter(function (segments) {
243
- return segments.length > pathIndex;
244
- });
245
- var otherSegments = allSegments.filter(function (segments) {
246
- return segments.length <= pathIndex;
247
- });
248
- if (pathSegments.length === 0) {
249
- return pathedObject;
250
- }
251
- var prefixes = {};
252
- pathSegments.forEach(function (segments) {
253
- var prefixPath = ProfileReport.pathString(segments.slice(0, pathIndex));
254
- var prefixCount = _.get(prefixes, prefixPath, new Set());
255
- prefixes[prefixPath] = prefixCount.add(segments[pathIndex]);
256
- });
257
- var collapsedObject = {};
258
- pathSegments.forEach(function (segments) {
259
- var prefix = segments.slice(0, pathIndex);
260
- var prefixPath = ProfileReport.pathString(prefix);
261
- var prefixCount = _.get(prefixes, prefixPath);
262
- var originalPath = ProfileReport.pathString(segments);
263
- if (prefixCount.size >= COLLAPSE_THRESHOLD) {
264
- var tail = segments.slice(pathIndex + 1);
265
- var collapsedPath = ProfileReport.pathString(prefix.concat(COLLAPSE_WILDCARD).concat(tail));
266
- var currentValue = collapsedObject[collapsedPath];
267
- if (currentValue) {
268
- collapsedObject[collapsedPath] = combiner(currentValue, pathedObject[originalPath]);
247
+ const pathSegments = allSegments.filter((segments) => {
248
+ return segments.length > pathIndex;
249
+ });
250
+ const otherSegments = allSegments.filter((segments) => {
251
+ return segments.length <= pathIndex;
252
+ });
253
+ if (pathSegments.length === 0) {
254
+ return pathedObject;
255
+ }
256
+ const prefixes = {};
257
+ pathSegments.forEach((segments) => {
258
+ const prefixPath = pathString(segments.slice(0, pathIndex));
259
+ const prefixCount = _.get(prefixes, prefixPath, new Set());
260
+ prefixes[prefixPath] = prefixCount.add(segments[pathIndex]);
261
+ });
262
+ const collapsedObject = {};
263
+ pathSegments.forEach((segments) => {
264
+ const prefix = segments.slice(0, pathIndex);
265
+ const prefixPath = pathString(prefix);
266
+ const prefixCount = _.get(prefixes, prefixPath);
267
+ const originalPath = pathString(segments);
268
+ if (prefixCount.size >= COLLAPSE_THRESHOLD) {
269
+ const tail = segments.slice(pathIndex + 1);
270
+ const collapsedPath = pathString(prefix.concat(COLLAPSE_WILDCARD).concat(tail));
271
+ const currentValue = collapsedObject[collapsedPath];
272
+ if (currentValue) {
273
+ collapsedObject[collapsedPath] = combiner(currentValue, pathedObject[originalPath]);
274
+ }
275
+ else {
276
+ collapsedObject[collapsedPath] = pathedObject[originalPath];
277
+ }
269
278
  }
270
279
  else {
271
- collapsedObject[collapsedPath] = pathedObject[originalPath];
280
+ collapsedObject[originalPath] = pathedObject[originalPath];
272
281
  }
273
- }
274
- else {
282
+ });
283
+ otherSegments.forEach((segments) => {
284
+ const originalPath = pathString(segments);
275
285
  collapsedObject[originalPath] = pathedObject[originalPath];
276
- }
277
- });
278
- otherSegments.forEach(function (segments) {
279
- var originalPath = ProfileReport.pathString(segments);
280
- collapsedObject[originalPath] = pathedObject[originalPath];
281
- });
282
- return this.collapsePaths(collapsedObject, combiner, pathIndex + 1);
283
- };
284
- ProfileReport.prototype.renderUnindexedData = function () {
285
- var table = new Table({
286
- head: ["Path", "Index", "Count"],
287
- style: {
288
- head: this.options.isFile ? [] : ["yellow"],
289
- border: this.options.isFile ? [] : ["grey"],
290
- },
291
- });
292
- var unindexed = this.collapsePaths(this.state.unindexed, function (u1, u2) {
293
- _.mergeWith(u1, u2, function (p1, p2) {
286
+ });
287
+ return this.collapsePaths(collapsedObject, combiner, pathIndex + 1);
288
+ }
289
+ renderUnindexedData() {
290
+ const table = new Table({
291
+ head: ["Path", "Index", "Count"],
292
+ style: {
293
+ head: this.options.isFile ? [] : ["yellow"],
294
+ border: this.options.isFile ? [] : ["grey"],
295
+ },
296
+ });
297
+ const unindexed = this.collapsePaths(this.state.unindexed, (u1, u2) => {
298
+ _.mergeWith(u1, u2, (p1, p2) => {
299
+ return {
300
+ times: p1.times + p2.times,
301
+ query: p1.query,
302
+ };
303
+ });
304
+ });
305
+ const paths = _.keys(unindexed);
306
+ paths.forEach((path) => {
307
+ const indices = _.keys(unindexed[path]);
308
+ indices.forEach((index) => {
309
+ const data = unindexed[path][index];
310
+ const row = [path, extractReadableIndex(data.query), formatNumber(data.times)];
311
+ table.push(row);
312
+ });
313
+ });
314
+ return table;
315
+ }
316
+ renderBandwidth(pureData) {
317
+ const table = new Table({
318
+ head: ["Path", "Total", "Count", "Average"],
319
+ style: {
320
+ head: this.options.isFile ? [] : ["yellow"],
321
+ border: this.options.isFile ? [] : ["grey"],
322
+ },
323
+ });
324
+ const data = this.collapsePaths(pureData, (b1, b2) => {
294
325
  return {
295
- times: p1.times + p2.times,
296
- query: p1.query,
326
+ bytes: b1.bytes + b2.bytes,
327
+ times: b1.times + b2.times,
297
328
  };
298
329
  });
299
- });
300
- var paths = _.keys(unindexed);
301
- paths.forEach(function (path) {
302
- var indices = _.keys(unindexed[path]);
303
- indices.forEach(function (index) {
304
- var data = unindexed[path][index];
305
- var row = [
330
+ const paths = _.orderBy(_.keys(data), [(p) => data[p].bytes], ["desc"]);
331
+ paths.forEach((path) => {
332
+ const bandwidth = data[path];
333
+ const row = [
306
334
  path,
307
- ProfileReport.extractReadableIndex(data.query),
308
- ProfileReport.formatNumber(data.times),
335
+ formatBytes(bandwidth.bytes),
336
+ formatNumber(bandwidth.times),
337
+ formatBytes(bandwidth.bytes / bandwidth.times),
309
338
  ];
310
339
  table.push(row);
311
340
  });
312
- });
313
- return table;
314
- };
315
- ProfileReport.prototype.renderBandwidth = function (pureData) {
316
- var table = new Table({
317
- head: ["Path", "Total", "Count", "Average"],
318
- style: {
319
- head: this.options.isFile ? [] : ["yellow"],
320
- border: this.options.isFile ? [] : ["grey"],
321
- },
322
- });
323
- var data = this.collapsePaths(pureData, function (b1, b2) {
324
- return {
325
- bytes: b1.bytes + b2.bytes,
326
- times: b1.times + b2.times,
327
- };
328
- });
329
- var paths = _.keys(data);
330
- paths = _.orderBy(paths, function (path) {
331
- var bandwidth = data[path];
332
- return bandwidth.bytes;
333
- }, ["desc"]);
334
- paths.forEach(function (path) {
335
- var bandwidth = data[path];
336
- var row = [
337
- path,
338
- ProfileReport.formatBytes(bandwidth.bytes),
339
- ProfileReport.formatNumber(bandwidth.times),
340
- ProfileReport.formatBytes(bandwidth.bytes / bandwidth.times),
341
- ];
342
- table.push(row);
343
- });
344
- return table;
345
- };
346
- ProfileReport.prototype.renderOutgoingBandwidth = function () {
347
- return this.renderBandwidth(this.state.outband);
348
- };
349
- ProfileReport.prototype.renderIncomingBandwidth = function () {
350
- return this.renderBandwidth(this.state.inband);
351
- };
352
- ProfileReport.prototype.renderUnpathedOperationSpeed = function (speedData, hasSecurity) {
353
- var head = ["Count", "Average Execution Speed", "Average Pending Time"];
354
- if (hasSecurity) {
355
- head.push("Permission Denied");
356
- }
357
- var table = new Table({
358
- head: head,
359
- style: {
360
- head: this.options.isFile ? [] : ["yellow"],
361
- border: this.options.isFile ? [] : ["grey"],
362
- },
363
- });
364
- if (Object.keys(speedData).length > 0) {
365
- var row = [
366
- speedData.times,
367
- ProfileReport.formatNumber(speedData.millis / speedData.times) + " ms",
368
- ProfileReport.formatNumber(speedData.pendingCount === 0 ? 0 : speedData.pendingTime / speedData.pendingCount) + " ms",
369
- ];
341
+ return table;
342
+ }
343
+ renderOutgoingBandwidth() {
344
+ return this.renderBandwidth(this.state.outband);
345
+ }
346
+ renderIncomingBandwidth() {
347
+ return this.renderBandwidth(this.state.inband);
348
+ }
349
+ renderUnpathedOperationSpeed(speedData, hasSecurity = false) {
350
+ const head = ["Count", "Average Execution Speed", "Average Pending Time"];
370
351
  if (hasSecurity) {
371
- row.push(ProfileReport.formatNumber(speedData.rejected));
352
+ head.push("Permission Denied");
372
353
  }
373
- table.push(row);
374
- }
375
- return table;
376
- };
377
- ProfileReport.prototype.renderOperationSpeed = function (pureData, hasSecurity) {
378
- var head = ["Path", "Count", "Average Execution Speed", "Average Pending Time"];
379
- if (hasSecurity) {
380
- head.push("Permission Denied");
381
- }
382
- var table = new Table({
383
- head: head,
384
- style: {
385
- head: this.options.isFile ? [] : ["yellow"],
386
- border: this.options.isFile ? [] : ["grey"],
387
- },
388
- });
389
- var data = this.collapsePaths(pureData, function (s1, s2) {
390
- return {
391
- times: s1.times + s2.times,
392
- millis: s1.millis + s2.millis,
393
- pendingCount: s1.pendingCount + s2.pendingCount,
394
- pendingTime: s1.pendingTime + s2.pendingTime,
395
- rejected: s1.rejected + s2.rejected,
396
- };
397
- });
398
- var paths = _.keys(data);
399
- paths = _.orderBy(paths, function (path) {
400
- var speed = data[path];
401
- return speed.millis / speed.times;
402
- }, ["desc"]);
403
- paths.forEach(function (path) {
404
- var speed = data[path];
405
- var row = [
406
- path,
407
- speed.times,
408
- ProfileReport.formatNumber(speed.millis / speed.times) + " ms",
409
- ProfileReport.formatNumber(speed.pendingCount === 0 ? 0 : speed.pendingTime / speed.pendingCount) + " ms",
410
- ];
354
+ const table = new Table({
355
+ head: head,
356
+ style: {
357
+ head: this.options.isFile ? [] : ["yellow"],
358
+ border: this.options.isFile ? [] : ["grey"],
359
+ },
360
+ });
361
+ if (Object.keys(speedData).length > 0) {
362
+ const row = [
363
+ speedData.times,
364
+ formatNumber(speedData.millis / speedData.times) + " ms",
365
+ formatNumber(speedData.pendingCount === 0 ? 0 : speedData.pendingTime / speedData.pendingCount) + " ms",
366
+ ];
367
+ if (hasSecurity) {
368
+ row.push(formatNumber(speedData.rejected));
369
+ }
370
+ table.push(row);
371
+ }
372
+ return table;
373
+ }
374
+ renderOperationSpeed(pureData, hasSecurity = false) {
375
+ const head = ["Path", "Count", "Average Execution Speed", "Average Pending Time"];
411
376
  if (hasSecurity) {
412
- row.push(ProfileReport.formatNumber(speed.rejected));
377
+ head.push("Permission Denied");
413
378
  }
414
- table.push(row);
415
- });
416
- return table;
417
- };
418
- ProfileReport.prototype.renderReadSpeed = function () {
419
- return this.renderOperationSpeed(this.state.readSpeed, true);
420
- };
421
- ProfileReport.prototype.renderWriteSpeed = function () {
422
- return this.renderOperationSpeed(this.state.writeSpeed, true);
423
- };
424
- ProfileReport.prototype.renderBroadcastSpeed = function () {
425
- return this.renderOperationSpeed(this.state.broadcastSpeed, false);
426
- };
427
- ProfileReport.prototype.renderConnectSpeed = function () {
428
- return this.renderUnpathedOperationSpeed(this.state.connectSpeed, false);
429
- };
430
- ProfileReport.prototype.renderDisconnectSpeed = function () {
431
- return this.renderUnpathedOperationSpeed(this.state.disconnectSpeed, false);
432
- };
433
- ProfileReport.prototype.renderUnlistenSpeed = function () {
434
- return this.renderOperationSpeed(this.state.unlistenSpeed, false);
435
- };
436
- ProfileReport.prototype.parse = function (onLine, onClose) {
437
- var isFile = this.options.isFile;
438
- var tmpFile = this.tempFile;
439
- var outStream = this.output;
440
- var isInput = this.options.isInput;
441
- return new Promise(function (resolve, reject) {
442
- var rl = readline.createInterface({
443
- input: fs.createReadStream(tmpFile),
379
+ const table = new Table({
380
+ head: head,
381
+ style: {
382
+ head: this.options.isFile ? [] : ["yellow"],
383
+ border: this.options.isFile ? [] : ["grey"],
384
+ },
444
385
  });
445
- var errored = false;
446
- rl.on("line", function (line) {
447
- var data = ProfileReport.extractJSON(line, isInput);
448
- if (!data) {
449
- return;
450
- }
451
- onLine(data);
386
+ const data = this.collapsePaths(pureData, (s1, s2) => {
387
+ return {
388
+ times: s1.times + s2.times,
389
+ millis: s1.millis + s2.millis,
390
+ pendingCount: s1.pendingCount + s2.pendingCount,
391
+ pendingTime: s1.pendingTime + s2.pendingTime,
392
+ rejected: s1.rejected + s2.rejected,
393
+ };
452
394
  });
453
- rl.on("close", function () {
454
- if (errored) {
455
- reject(new FirebaseError("There was an error creating the report."));
395
+ let paths = _.keys(data);
396
+ paths = _.orderBy(paths, (path) => {
397
+ const speed = data[path];
398
+ return speed.millis / speed.times;
399
+ }, ["desc"]);
400
+ paths.forEach((path) => {
401
+ const speed = data[path];
402
+ const row = [
403
+ path,
404
+ speed.times,
405
+ formatNumber(speed.millis / speed.times) + " ms",
406
+ formatNumber(speed.pendingCount === 0 ? 0 : speed.pendingTime / speed.pendingCount) + " ms",
407
+ ];
408
+ if (hasSecurity) {
409
+ row.push(formatNumber(speed.rejected));
456
410
  }
457
- else {
458
- var result = onClose();
459
- if (isFile) {
460
- outStream.on("finish", function () {
461
- resolve(result);
462
- });
463
- outStream.end();
411
+ table.push(row);
412
+ });
413
+ return table;
414
+ }
415
+ renderReadSpeed() {
416
+ return this.renderOperationSpeed(this.state.readSpeed, true);
417
+ }
418
+ renderWriteSpeed() {
419
+ return this.renderOperationSpeed(this.state.writeSpeed, true);
420
+ }
421
+ renderBroadcastSpeed() {
422
+ return this.renderOperationSpeed(this.state.broadcastSpeed, false);
423
+ }
424
+ renderConnectSpeed() {
425
+ return this.renderUnpathedOperationSpeed(this.state.connectSpeed, false);
426
+ }
427
+ renderDisconnectSpeed() {
428
+ return this.renderUnpathedOperationSpeed(this.state.disconnectSpeed, false);
429
+ }
430
+ renderUnlistenSpeed() {
431
+ return this.renderOperationSpeed(this.state.unlistenSpeed, false);
432
+ }
433
+ async parse(onLine, onClose) {
434
+ const isFile = this.options.isFile;
435
+ const tmpFile = this.tempFile;
436
+ const outStream = this.output;
437
+ const isInput = this.options.isInput;
438
+ return new Promise((resolve, reject) => {
439
+ const rl = readline.createInterface({
440
+ input: fs.createReadStream(tmpFile),
441
+ });
442
+ let errored = false;
443
+ rl.on("line", (line) => {
444
+ const data = extractJSON(line, isInput);
445
+ if (!data) {
446
+ return;
447
+ }
448
+ onLine(data);
449
+ });
450
+ rl.on("close", () => {
451
+ if (errored) {
452
+ reject(new error_1.FirebaseError("There was an error creating the report."));
464
453
  }
465
454
  else {
466
- resolve(result);
455
+ const result = onClose();
456
+ if (isFile) {
457
+ outStream.on("finish", () => {
458
+ resolve(result);
459
+ });
460
+ outStream.end();
461
+ }
462
+ else {
463
+ resolve(result);
464
+ }
467
465
  }
468
- }
469
- });
470
- rl.on("error", function () {
471
- reject();
472
- });
473
- outStream.on("error", function () {
474
- errored = true;
475
- rl.close();
466
+ });
467
+ rl.on("error", () => {
468
+ reject();
469
+ });
470
+ outStream.on("error", () => {
471
+ errored = true;
472
+ rl.close();
473
+ });
476
474
  });
477
- });
478
- };
479
- ProfileReport.prototype.write = function (data) {
480
- if (this.options.isFile) {
481
- this.output.write(data);
482
- }
483
- else {
484
- logger.info(data);
485
- }
486
- };
487
- ProfileReport.prototype.generate = function () {
488
- if (this.options.format === "TXT") {
489
- return this.generateText();
490
- }
491
- else if (this.options.format === "RAW") {
492
- return this.generateRaw();
493
- }
494
- else if (this.options.format === "JSON") {
495
- return this.generateJson();
496
- }
497
- throw new FirebaseError('Invalid report format expected "TXT", "JSON", or "RAW"', {
498
- exit: 1,
499
- });
500
- };
501
- ProfileReport.prototype.generateRaw = function () {
502
- return this.parse(this.writeRaw.bind(this), function () {
503
- return null;
504
- });
505
- };
506
- ProfileReport.prototype.writeRaw = function (data) {
507
- this.write(JSON.stringify(data) + "\n");
508
- };
509
- ProfileReport.prototype.generateText = function () {
510
- return this.parse(this.processOperation.bind(this), this.outputText.bind(this));
511
- };
512
- ProfileReport.prototype.outputText = function () {
513
- var totalTime = this.state.endTime - this.state.startTime;
514
- var isFile = this.options.isFile;
515
- var write = this.write.bind(this);
516
- var writeTitle = function (title) {
517
- if (isFile) {
518
- write(title + "\n");
475
+ }
476
+ write(data) {
477
+ if (this.options.isFile) {
478
+ this.output.write(data);
519
479
  }
520
480
  else {
521
- write(clc.bold.yellow(title) + "\n");
481
+ logger_1.logger.info(data);
522
482
  }
523
- };
524
- var writeTable = function (title, table) {
525
- writeTitle(title);
526
- write(table.toString() + "\n");
527
- };
528
- writeTitle("Report operations collected from " +
529
- new Date(this.state.startTime).toISOString() +
530
- " over " +
531
- totalTime +
532
- " ms.");
533
- writeTitle("Speed Report\n");
534
- write(SPEED_NOTE + "\n\n");
535
- writeTable("Read Speed", this.renderReadSpeed());
536
- writeTable("Write Speed", this.renderWriteSpeed());
537
- writeTable("Broadcast Speed", this.renderBroadcastSpeed());
538
- writeTable("Connect Speed", this.renderConnectSpeed());
539
- writeTable("Disconnect Speed", this.renderDisconnectSpeed());
540
- writeTable("Unlisten Speed", this.renderUnlistenSpeed());
541
- writeTitle("Bandwidth Report\n");
542
- write(BANDWIDTH_NOTE + "\n\n");
543
- writeTable("Downloaded Bytes", this.renderOutgoingBandwidth());
544
- writeTable("Uploaded Bytes", this.renderIncomingBandwidth());
545
- writeTable("Unindexed Queries", this.renderUnindexedData());
546
- };
547
- ProfileReport.prototype.generateJson = function () {
548
- return this.parse(this.processOperation.bind(this), this.outputJson.bind(this));
549
- };
550
- ProfileReport.prototype.outputJson = function () {
551
- var totalTime = this.state.endTime - this.state.startTime;
552
- var tableToJson = function (table, note) {
553
- var json = {
554
- legend: table.options.head,
555
- data: [],
556
- };
557
- if (note) {
558
- json.note = note;
483
+ }
484
+ generate() {
485
+ if (this.options.format === "TXT") {
486
+ return this.generateText();
487
+ }
488
+ else if (this.options.format === "RAW") {
489
+ return this.generateRaw();
490
+ }
491
+ else if (this.options.format === "JSON") {
492
+ return this.generateJson();
559
493
  }
560
- table.forEach(function (row) {
561
- json.data.push(row);
494
+ throw new error_1.FirebaseError('Invalid report format expected "TXT", "JSON", or "RAW"');
495
+ }
496
+ generateRaw() {
497
+ return this.parse(this.writeRaw.bind(this), () => {
498
+ return null;
562
499
  });
500
+ }
501
+ writeRaw(data) {
502
+ this.write(JSON.stringify(data) + "\n");
503
+ }
504
+ generateText() {
505
+ return this.parse(this.processOperation.bind(this), this.outputText.bind(this));
506
+ }
507
+ outputText() {
508
+ const totalTime = this.state.endTime - this.state.startTime;
509
+ const isFile = this.options.isFile;
510
+ const write = this.write.bind(this);
511
+ const writeTitle = (title) => {
512
+ if (isFile) {
513
+ write(title + "\n");
514
+ }
515
+ else {
516
+ write(clc.bold.yellow(title) + "\n");
517
+ }
518
+ };
519
+ const writeTable = (title, table) => {
520
+ writeTitle(title);
521
+ write(table.toString() + "\n");
522
+ };
523
+ writeTitle(`Report operations collected from ${new Date(this.state.startTime).toISOString()} over ${totalTime} ms.`);
524
+ writeTitle("Speed Report\n");
525
+ write(SPEED_NOTE + "\n\n");
526
+ writeTable("Read Speed", this.renderReadSpeed());
527
+ writeTable("Write Speed", this.renderWriteSpeed());
528
+ writeTable("Broadcast Speed", this.renderBroadcastSpeed());
529
+ writeTable("Connect Speed", this.renderConnectSpeed());
530
+ writeTable("Disconnect Speed", this.renderDisconnectSpeed());
531
+ writeTable("Unlisten Speed", this.renderUnlistenSpeed());
532
+ writeTitle("Bandwidth Report\n");
533
+ write(BANDWIDTH_NOTE + "\n\n");
534
+ writeTable("Downloaded Bytes", this.renderOutgoingBandwidth());
535
+ writeTable("Uploaded Bytes", this.renderIncomingBandwidth());
536
+ writeTable("Unindexed Queries", this.renderUnindexedData());
537
+ }
538
+ generateJson() {
539
+ return this.parse(this.processOperation.bind(this), this.outputJson.bind(this));
540
+ }
541
+ outputJson() {
542
+ const totalTime = this.state.endTime - this.state.startTime;
543
+ const tableToJson = (table, note) => {
544
+ const json = {
545
+ legend: table.options.head,
546
+ data: [],
547
+ };
548
+ if (note) {
549
+ json.note = note;
550
+ }
551
+ table.forEach((row) => {
552
+ json.data.push(row);
553
+ });
554
+ return json;
555
+ };
556
+ const json = {
557
+ totalTime: totalTime,
558
+ readSpeed: tableToJson(this.renderReadSpeed(), SPEED_NOTE),
559
+ writeSpeed: tableToJson(this.renderWriteSpeed(), SPEED_NOTE),
560
+ broadcastSpeed: tableToJson(this.renderBroadcastSpeed(), SPEED_NOTE),
561
+ connectSpeed: tableToJson(this.renderConnectSpeed(), SPEED_NOTE),
562
+ disconnectSpeed: tableToJson(this.renderDisconnectSpeed(), SPEED_NOTE),
563
+ unlistenSpeed: tableToJson(this.renderUnlistenSpeed(), SPEED_NOTE),
564
+ downloadedBytes: tableToJson(this.renderOutgoingBandwidth(), BANDWIDTH_NOTE),
565
+ uploadedBytes: tableToJson(this.renderIncomingBandwidth(), BANDWIDTH_NOTE),
566
+ unindexedQueries: tableToJson(this.renderUnindexedData()),
567
+ };
568
+ this.write(JSON.stringify(json, null, 2));
569
+ if (this.options.isFile) {
570
+ return this.output.path;
571
+ }
563
572
  return json;
564
- };
565
- var json = {
566
- totalTime: totalTime,
567
- readSpeed: tableToJson(this.renderReadSpeed(), SPEED_NOTE),
568
- writeSpeed: tableToJson(this.renderWriteSpeed(), SPEED_NOTE),
569
- broadcastSpeed: tableToJson(this.renderBroadcastSpeed(), SPEED_NOTE),
570
- connectSpeed: tableToJson(this.renderConnectSpeed(), SPEED_NOTE),
571
- disconnectSpeed: tableToJson(this.renderDisconnectSpeed(), SPEED_NOTE),
572
- unlistenSpeed: tableToJson(this.renderUnlistenSpeed(), SPEED_NOTE),
573
- downloadedBytes: tableToJson(this.renderOutgoingBandwidth(), BANDWIDTH_NOTE),
574
- uploadedBytes: tableToJson(this.renderIncomingBandwidth(), BANDWIDTH_NOTE),
575
- unindexedQueries: tableToJson(this.renderUnindexedData()),
576
- };
577
- this.write(JSON.stringify(json, null, 2));
578
- if (this.options.isFile) {
579
- return this.output.path;
580
- }
581
- return json;
582
- };
583
- module.exports = ProfileReport;
573
+ }
574
+ }
575
+ exports.ProfileReport = ProfileReport;