UNPKG

6.08 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.PathSegment = exports.Path = exports.UnboundRelationship = exports.Relationship = exports.Node = undefined;
7
8var _stringify = require("babel-runtime/core-js/json/stringify");
9
10var _stringify2 = _interopRequireDefault(_stringify);
11
12var _keys = require("babel-runtime/core-js/object/keys");
13
14var _keys2 = _interopRequireDefault(_keys);
15
16var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
17
18var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
19
20var _createClass2 = require("babel-runtime/helpers/createClass");
21
22var _createClass3 = _interopRequireDefault(_createClass2);
23
24var _integer = require("./integer");
25
26var _integer2 = _interopRequireDefault(_integer);
27
28function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
30/**
31 * Class for Node Type.
32 */
33var Node = function () {
34 /**
35 * @constructor
36 * @param {Integer} identity - Unique identity
37 * @param {Array<string>} labels - Array for all labels
38 * @param {Object} properties - Map with node properties
39 */
40 function Node(identity, labels, properties) {
41 (0, _classCallCheck3.default)(this, Node);
42
43 this.identity = identity;
44 this.labels = labels;
45 this.properties = properties;
46 }
47
48 (0, _createClass3.default)(Node, [{
49 key: "toString",
50 value: function toString() {
51 var s = "(" + this.identity;
52 for (var i = 0; i < this.labels.length; i++) {
53 s += ":" + this.labels[i];
54 }
55 var keys = (0, _keys2.default)(this.properties);
56 if (keys.length > 0) {
57 s += " {";
58 for (var _i = 0; _i < keys.length; _i++) {
59 if (_i > 0) s += ",";
60 s += keys[_i] + ":" + (0, _stringify2.default)(this.properties[keys[_i]]);
61 }
62 s += "}";
63 }
64 s += ")";
65 return s;
66 }
67 }]);
68 return Node;
69}();
70
71/**
72 * Class for Relationship Type.
73 */
74/**
75 * Copyright (c) 2002-2018 Neo4j Sweden AB [http://neo4j.com]
76 *
77 * This file is part of Neo4j.
78 *
79 * Licensed under the Apache License, Version 2.0 (the "License");
80 * you may not use this file except in compliance with the License.
81 * You may obtain a copy of the License at
82 *
83 * http://www.apache.org/licenses/LICENSE-2.0
84 *
85 * Unless required by applicable law or agreed to in writing, software
86 * distributed under the License is distributed on an "AS IS" BASIS,
87 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88 * See the License for the specific language governing permissions and
89 * limitations under the License.
90 */
91
92var Relationship = function () {
93 /**
94 * @constructor
95 * @param {Integer} identity - Unique identity
96 * @param {Integer} start - Identity of start Node
97 * @param {Integer} end - Identity of end Node
98 * @param {string} type - Relationship type
99 * @param {Object} properties - Map with relationship properties
100 */
101 function Relationship(identity, start, end, type, properties) {
102 (0, _classCallCheck3.default)(this, Relationship);
103
104 this.identity = identity;
105 this.start = start;
106 this.end = end;
107 this.type = type;
108 this.properties = properties;
109 }
110
111 (0, _createClass3.default)(Relationship, [{
112 key: "toString",
113 value: function toString() {
114 var s = "(" + this.start + ")-[:" + this.type;
115 var keys = (0, _keys2.default)(this.properties);
116 if (keys.length > 0) {
117 s += " {";
118 for (var i = 0; i < keys.length; i++) {
119 if (i > 0) s += ",";
120 s += keys[i] + ":" + (0, _stringify2.default)(this.properties[keys[i]]);
121 }
122 s += "}";
123 }
124 s += "]->(" + this.end + ")";
125 return s;
126 }
127 }]);
128 return Relationship;
129}();
130
131/**
132 * Class for UnboundRelationship Type.
133 * @access private
134 */
135
136
137var UnboundRelationship = function () {
138 /**
139 * @constructor
140 * @param {Integer} identity - Unique identity
141 * @param {string} type - Relationship type
142 * @param {Object} properties - Map with relationship properties
143 */
144 function UnboundRelationship(identity, type, properties) {
145 (0, _classCallCheck3.default)(this, UnboundRelationship);
146
147 this.identity = identity;
148 this.type = type;
149 this.properties = properties;
150 }
151
152 /**
153 * Bind relationship
154 * @param {Integer} start - Identity of start node
155 * @param {Integer} end - Identity of end node
156 * @return {Relationship} - Created relationship
157 */
158
159
160 (0, _createClass3.default)(UnboundRelationship, [{
161 key: "bind",
162 value: function bind(start, end) {
163 return new Relationship(this.identity, start, end, this.type, this.properties);
164 }
165 }, {
166 key: "toString",
167 value: function toString() {
168 var s = "-[:" + this.type;
169 var keys = (0, _keys2.default)(this.properties);
170 if (keys.length > 0) {
171 s += " {";
172 for (var i = 0; i < keys.length; i++) {
173 if (i > 0) s += ",";
174 s += keys[i] + ":" + (0, _stringify2.default)(this.properties[keys[i]]);
175 }
176 s += "}";
177 }
178 s += "]->";
179 return s;
180 }
181 }]);
182 return UnboundRelationship;
183}();
184
185/**
186 * Class for PathSegment Type.
187 */
188
189
190var PathSegment =
191/**
192 * @constructor
193 * @param {Node} start - start node
194 * @param {Relationship} rel - relationship that connects start and end node
195 * @param {Node} end - end node
196 */
197function PathSegment(start, rel, end) {
198 (0, _classCallCheck3.default)(this, PathSegment);
199
200 this.start = start;
201 this.relationship = rel;
202 this.end = end;
203};
204
205/**
206 * Class for Path Type.
207 */
208
209
210var Path =
211/**
212 * @constructor
213 * @param {Node} start - start node
214 * @param {Node} end - end node
215 * @param {Array<PathSegment>} segments - Array of Segments
216 */
217function Path(start, end, segments) {
218 (0, _classCallCheck3.default)(this, Path);
219
220 this.start = start;
221 this.end = end;
222 this.segments = segments;
223 this.length = segments.length;
224};
225
226exports.Node = Node;
227exports.Relationship = Relationship;
228exports.UnboundRelationship = UnboundRelationship;
229exports.Path = Path;
230exports.PathSegment = PathSegment;
\No newline at end of file