1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.isNode = isNode;
|
9 | exports.isRelationship = isRelationship;
|
10 | exports.isUnboundRelationship = isUnboundRelationship;
|
11 | exports.isPath = isPath;
|
12 | exports.isPathSegment = isPathSegment;
|
13 | exports.PathSegment = exports.Path = exports.UnboundRelationship = exports.Relationship = exports.Node = void 0;
|
14 |
|
15 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
16 |
|
17 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var IDENTIFIER_PROPERTY_ATTRIBUTES = {
|
38 | value: true,
|
39 | enumerable: false,
|
40 | configurable: false,
|
41 | writable: false
|
42 | };
|
43 | var NODE_IDENTIFIER_PROPERTY = '__isNode__';
|
44 | var RELATIONSHIP_IDENTIFIER_PROPERTY = '__isRelationship__';
|
45 | var UNBOUND_RELATIONSHIP_IDENTIFIER_PROPERTY = '__isUnboundRelationship__';
|
46 | var PATH_IDENTIFIER_PROPERTY = '__isPath__';
|
47 | var PATH_SEGMENT_IDENTIFIER_PROPERTY = '__isPathSegment__';
|
48 |
|
49 | function hasIdentifierProperty(obj, property) {
|
50 | return (obj && obj[property]) === true;
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var Node =
|
58 |
|
59 | function () {
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | function Node(identity, labels, properties) {
|
68 | (0, _classCallCheck2["default"])(this, Node);
|
69 |
|
70 | |
71 |
|
72 |
|
73 |
|
74 | this.identity = identity;
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 | this.labels = labels;
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 | this.properties = properties;
|
87 | }
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 | (0, _createClass2["default"])(Node, [{
|
94 | key: "toString",
|
95 | value: function toString() {
|
96 | var s = '(' + this.identity;
|
97 |
|
98 | for (var i = 0; i < this.labels.length; i++) {
|
99 | s += ':' + this.labels[i];
|
100 | }
|
101 |
|
102 | var keys = Object.keys(this.properties);
|
103 |
|
104 | if (keys.length > 0) {
|
105 | s += ' {';
|
106 |
|
107 | for (var _i = 0; _i < keys.length; _i++) {
|
108 | if (_i > 0) s += ',';
|
109 | s += keys[_i] + ':' + JSON.stringify(this.properties[keys[_i]]);
|
110 | }
|
111 |
|
112 | s += '}';
|
113 | }
|
114 |
|
115 | s += ')';
|
116 | return s;
|
117 | }
|
118 | }]);
|
119 | return Node;
|
120 | }();
|
121 |
|
122 | exports.Node = Node;
|
123 | Object.defineProperty(Node.prototype, NODE_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function isNode(obj) {
|
131 | return hasIdentifierProperty(obj, NODE_IDENTIFIER_PROPERTY);
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | var Relationship =
|
139 |
|
140 | function () {
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | function Relationship(identity, start, end, type, properties) {
|
151 | (0, _classCallCheck2["default"])(this, Relationship);
|
152 |
|
153 | |
154 |
|
155 |
|
156 |
|
157 | this.identity = identity;
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 | this.start = start;
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 | this.end = end;
|
170 | |
171 |
|
172 |
|
173 |
|
174 |
|
175 | this.type = type;
|
176 | |
177 |
|
178 |
|
179 |
|
180 |
|
181 | this.properties = properties;
|
182 | }
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 | (0, _createClass2["default"])(Relationship, [{
|
189 | key: "toString",
|
190 | value: function toString() {
|
191 | var s = '(' + this.start + ')-[:' + this.type;
|
192 | var keys = Object.keys(this.properties);
|
193 |
|
194 | if (keys.length > 0) {
|
195 | s += ' {';
|
196 |
|
197 | for (var i = 0; i < keys.length; i++) {
|
198 | if (i > 0) s += ',';
|
199 | s += keys[i] + ':' + JSON.stringify(this.properties[keys[i]]);
|
200 | }
|
201 |
|
202 | s += '}';
|
203 | }
|
204 |
|
205 | s += ']->(' + this.end + ')';
|
206 | return s;
|
207 | }
|
208 | }]);
|
209 | return Relationship;
|
210 | }();
|
211 |
|
212 | exports.Relationship = Relationship;
|
213 | Object.defineProperty(Relationship.prototype, RELATIONSHIP_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | function isRelationship(obj) {
|
221 | return hasIdentifierProperty(obj, RELATIONSHIP_IDENTIFIER_PROPERTY);
|
222 | }
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | var UnboundRelationship =
|
230 |
|
231 | function () {
|
232 | |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | function UnboundRelationship(identity, type, properties) {
|
240 | (0, _classCallCheck2["default"])(this, UnboundRelationship);
|
241 |
|
242 | |
243 |
|
244 |
|
245 |
|
246 | this.identity = identity;
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 | this.type = type;
|
253 | |
254 |
|
255 |
|
256 |
|
257 |
|
258 | this.properties = properties;
|
259 | }
|
260 | |
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | (0, _createClass2["default"])(UnboundRelationship, [{
|
271 | key: "bind",
|
272 | value: function bind(start, end) {
|
273 | return new Relationship(this.identity, start, end, this.type, this.properties);
|
274 | }
|
275 | |
276 |
|
277 |
|
278 |
|
279 | }, {
|
280 | key: "toString",
|
281 | value: function toString() {
|
282 | var s = '-[:' + this.type;
|
283 | var keys = Object.keys(this.properties);
|
284 |
|
285 | if (keys.length > 0) {
|
286 | s += ' {';
|
287 |
|
288 | for (var i = 0; i < keys.length; i++) {
|
289 | if (i > 0) s += ',';
|
290 | s += keys[i] + ':' + JSON.stringify(this.properties[keys[i]]);
|
291 | }
|
292 |
|
293 | s += '}';
|
294 | }
|
295 |
|
296 | s += ']->';
|
297 | return s;
|
298 | }
|
299 | }]);
|
300 | return UnboundRelationship;
|
301 | }();
|
302 |
|
303 | exports.UnboundRelationship = UnboundRelationship;
|
304 | Object.defineProperty(UnboundRelationship.prototype, UNBOUND_RELATIONSHIP_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | function isUnboundRelationship(obj) {
|
312 | return hasIdentifierProperty(obj, UNBOUNT_RELATIONSHIP_IDENTIFIER_PROPERTY);
|
313 | }
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | var PathSegment =
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | function PathSegment(start, rel, end) {
|
328 | (0, _classCallCheck2["default"])(this, PathSegment);
|
329 |
|
330 | |
331 |
|
332 |
|
333 |
|
334 | this.start = start;
|
335 | |
336 |
|
337 |
|
338 |
|
339 |
|
340 | this.relationship = rel;
|
341 | |
342 |
|
343 |
|
344 |
|
345 |
|
346 | this.end = end;
|
347 | };
|
348 |
|
349 | exports.PathSegment = PathSegment;
|
350 | Object.defineProperty(PathSegment.prototype, PATH_SEGMENT_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 | function isPathSegment(obj) {
|
358 | return hasIdentifierProperty(obj, PATH_SEGMENT_IDENTIFIER_PROPERTY);
|
359 | }
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 | var Path =
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | function Path(start, end, segments) {
|
374 | (0, _classCallCheck2["default"])(this, Path);
|
375 |
|
376 | |
377 |
|
378 |
|
379 |
|
380 | this.start = start;
|
381 | |
382 |
|
383 |
|
384 |
|
385 |
|
386 | this.end = end;
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 | this.segments = segments;
|
393 | |
394 |
|
395 |
|
396 |
|
397 |
|
398 | this.length = segments.length;
|
399 | };
|
400 |
|
401 | exports.Path = Path;
|
402 | Object.defineProperty(Path.prototype, PATH_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 | function isPath(obj) {
|
410 | return hasIdentifierProperty(obj, PATH_IDENTIFIER_PROPERTY);
|
411 | } |
\ | No newline at end of file |