1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = exports.queryType = void 0;
|
9 |
|
10 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
11 |
|
12 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
13 |
|
14 | var _integer = require("./integer");
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var ResultSummary =
|
40 |
|
41 | function () {
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function ResultSummary(query, parameters, metadata) {
|
49 | (0, _classCallCheck2["default"])(this, ResultSummary);
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | this.query = {
|
57 | text: query,
|
58 | parameters: parameters
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | };
|
68 | this.queryType = metadata.type;
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | this.counters = new QueryStatistics(metadata.stats || {});
|
76 |
|
77 | this.updateStatistics = this.counters;
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | this.plan = metadata.plan || metadata.profile ? new Plan(metadata.plan || metadata.profile) : false;
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | this.profile = metadata.profile ? new ProfiledPlan(metadata.profile) : false;
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | this.notifications = this._buildNotifications(metadata.notifications);
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | this.server = new ServerInfo(metadata.server);
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | this.resultConsumedAfter = metadata.result_consumed_after;
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | this.resultAvailableAfter = metadata.result_available_after;
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | this.database = {
|
132 | name: metadata.db || null
|
133 | };
|
134 | }
|
135 |
|
136 | (0, _createClass2["default"])(ResultSummary, [{
|
137 | key: "_buildNotifications",
|
138 | value: function _buildNotifications(notifications) {
|
139 | if (!notifications) {
|
140 | return [];
|
141 | }
|
142 |
|
143 | return notifications.map(function (n) {
|
144 | return new Notification(n);
|
145 | });
|
146 | }
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 | }, {
|
153 | key: "hasPlan",
|
154 | value: function hasPlan() {
|
155 | return this.plan instanceof Plan;
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 | }, {
|
163 | key: "hasProfile",
|
164 | value: function hasProfile() {
|
165 | return this.profile instanceof ProfiledPlan;
|
166 | }
|
167 | }]);
|
168 | return ResultSummary;
|
169 | }();
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | var Plan =
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | function Plan(plan) {
|
183 | (0, _classCallCheck2["default"])(this, Plan);
|
184 | this.operatorType = plan.operatorType;
|
185 | this.identifiers = plan.identifiers;
|
186 | this.arguments = plan.args;
|
187 | this.children = plan.children ? plan.children.map(function (child) {
|
188 | return new Plan(child);
|
189 | }) : [];
|
190 | };
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | var ProfiledPlan =
|
198 |
|
199 | function () {
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 | function ProfiledPlan(profile) {
|
206 | (0, _classCallCheck2["default"])(this, ProfiledPlan);
|
207 | this.operatorType = profile.operatorType;
|
208 | this.identifiers = profile.identifiers;
|
209 | this.arguments = profile.args;
|
210 | this.dbHits = valueOrDefault('dbHits', profile);
|
211 | this.rows = valueOrDefault('rows', profile);
|
212 | this.pageCacheMisses = valueOrDefault('pageCacheMisses', profile);
|
213 | this.pageCacheHits = valueOrDefault('pageCacheHits', profile);
|
214 | this.pageCacheHitRatio = valueOrDefault('pageCacheHitRatio', profile);
|
215 | this.time = valueOrDefault('time', profile);
|
216 | this.children = profile.children ? profile.children.map(function (child) {
|
217 | return new ProfiledPlan(child);
|
218 | }) : [];
|
219 | }
|
220 |
|
221 | (0, _createClass2["default"])(ProfiledPlan, [{
|
222 | key: "hasPageCacheStats",
|
223 | value: function hasPageCacheStats() {
|
224 | return this.pageCacheMisses > 0 || this.pageCacheHits > 0 || this.pageCacheHitRatio > 0;
|
225 | }
|
226 | }]);
|
227 | return ProfiledPlan;
|
228 | }();
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | var QueryStatistics =
|
236 |
|
237 | function () {
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 | function QueryStatistics(statistics) {
|
244 | var _this = this;
|
245 |
|
246 | (0, _classCallCheck2["default"])(this, QueryStatistics);
|
247 | this._stats = {
|
248 | nodesCreated: 0,
|
249 | nodesDeleted: 0,
|
250 | relationshipsCreated: 0,
|
251 | relationshipsDeleted: 0,
|
252 | propertiesSet: 0,
|
253 | labelsAdded: 0,
|
254 | labelsRemoved: 0,
|
255 | indexesAdded: 0,
|
256 | indexesRemoved: 0,
|
257 | constraintsAdded: 0,
|
258 | constraintsRemoved: 0
|
259 | };
|
260 | this._systemUpdates = 0;
|
261 | Object.keys(statistics).forEach(function (index) {
|
262 |
|
263 | var camelCaseIndex = index.replace(/(-\w)/g, function (m) {
|
264 | return m[1].toUpperCase();
|
265 | });
|
266 |
|
267 | if (camelCaseIndex in _this._stats) {
|
268 | _this._stats[camelCaseIndex] = intValue(statistics[index]);
|
269 | } else if (camelCaseIndex === 'systemUpdates') {
|
270 | _this._systemUpdates = intValue(statistics[index]);
|
271 | }
|
272 | });
|
273 | this._stats = Object.freeze(this._stats);
|
274 | }
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | (0, _createClass2["default"])(QueryStatistics, [{
|
282 | key: "containsUpdates",
|
283 | value: function containsUpdates() {
|
284 | var _this2 = this;
|
285 |
|
286 | return Object.keys(this._stats).reduce(function (last, current) {
|
287 | return last + _this2._stats[current];
|
288 | }, 0) > 0;
|
289 | }
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 | }, {
|
296 | key: "updates",
|
297 | value: function updates() {
|
298 | return this._stats;
|
299 | }
|
300 | |
301 |
|
302 |
|
303 |
|
304 |
|
305 | }, {
|
306 | key: "containsSystemUpdates",
|
307 | value: function containsSystemUpdates() {
|
308 | return this._systemUpdates > 0;
|
309 | }
|
310 | |
311 |
|
312 |
|
313 |
|
314 | }, {
|
315 | key: "systemUpdates",
|
316 | value: function systemUpdates() {
|
317 | return this._systemUpdates;
|
318 | }
|
319 | }]);
|
320 | return QueryStatistics;
|
321 | }();
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | var Notification =
|
329 |
|
330 | function () {
|
331 | |
332 |
|
333 |
|
334 |
|
335 |
|
336 | function Notification(notification) {
|
337 | (0, _classCallCheck2["default"])(this, Notification);
|
338 | this.code = notification.code;
|
339 | this.title = notification.title;
|
340 | this.description = notification.description;
|
341 | this.severity = notification.severity;
|
342 | this.position = Notification._constructPosition(notification.position);
|
343 | }
|
344 |
|
345 | (0, _createClass2["default"])(Notification, null, [{
|
346 | key: "_constructPosition",
|
347 | value: function _constructPosition(pos) {
|
348 | if (!pos) {
|
349 | return {};
|
350 | }
|
351 |
|
352 | return {
|
353 | offset: intValue(pos.offset),
|
354 | line: intValue(pos.line),
|
355 | column: intValue(pos.column)
|
356 | };
|
357 | }
|
358 | }]);
|
359 | return Notification;
|
360 | }();
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | var ServerInfo =
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | function ServerInfo(serverMeta) {
|
374 | (0, _classCallCheck2["default"])(this, ServerInfo);
|
375 |
|
376 | if (serverMeta) {
|
377 | this.address = serverMeta.address;
|
378 | this.version = serverMeta.version;
|
379 | }
|
380 | };
|
381 |
|
382 | function intValue(value) {
|
383 | return (0, _integer.isInt)(value) ? value.toInt() : value;
|
384 | }
|
385 |
|
386 | function valueOrDefault(key, values) {
|
387 | var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
388 |
|
389 | if (key in values) {
|
390 | var value = values[key];
|
391 | return (0, _integer.isInt)(value) ? value.toInt() : value;
|
392 | } else {
|
393 | return defaultValue;
|
394 | }
|
395 | }
|
396 |
|
397 | var queryType = {
|
398 | READ_ONLY: 'r',
|
399 | READ_WRITE: 'rw',
|
400 | WRITE_ONLY: 'w',
|
401 | SCHEMA_WRITE: 's'
|
402 | };
|
403 | exports.queryType = queryType;
|
404 | var _default = ResultSummary;
|
405 | exports["default"] = _default; |
\ | No newline at end of file |