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