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"] = 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 _rxjs = require("rxjs");
|
15 |
|
16 | var _operators = require("rxjs/operators");
|
17 |
|
18 | var _resultRx = _interopRequireDefault(require("./result-rx"));
|
19 |
|
20 | var _neo4jDriverCore = require("neo4j-driver-core");
|
21 |
|
22 | var _transactionRx = _interopRequireDefault(require("./transaction-rx"));
|
23 |
|
24 | var _retryLogicRx = _interopRequireDefault(require("./internal/retry-logic-rx"));
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var _internal$constants = _neo4jDriverCore.internal.constants,
|
45 | ACCESS_MODE_READ = _internal$constants.ACCESS_MODE_READ,
|
46 | ACCESS_MODE_WRITE = _internal$constants.ACCESS_MODE_WRITE,
|
47 | TxConfig = _neo4jDriverCore.internal.txConfig.TxConfig;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | var RxSession = function () {
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function RxSession() {
|
61 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
62 | session = _ref.session,
|
63 | config = _ref.config;
|
64 |
|
65 | (0, _classCallCheck2["default"])(this, RxSession);
|
66 | this._session = session;
|
67 | this._retryLogic = _createRetryLogic(config);
|
68 | }
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | (0, _createClass2["default"])(RxSession, [{
|
82 | key: "run",
|
83 | value: function run(query, parameters, transactionConfig) {
|
84 | var _this = this;
|
85 |
|
86 | return new _resultRx["default"](new _rxjs.Observable(function (observer) {
|
87 | try {
|
88 | observer.next(_this._session.run(query, parameters, transactionConfig));
|
89 | observer.complete();
|
90 | } catch (err) {
|
91 | observer.error(err);
|
92 | }
|
93 |
|
94 | return function () {};
|
95 | }));
|
96 | }
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | }, {
|
106 | key: "beginTransaction",
|
107 | value: function beginTransaction(transactionConfig) {
|
108 | return this._beginTransaction(this._session._mode, transactionConfig);
|
109 | }
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | }, {
|
120 | key: "readTransaction",
|
121 | value: function readTransaction(work, transactionConfig) {
|
122 | return this._runTransaction(ACCESS_MODE_READ, work, transactionConfig);
|
123 | }
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | }, {
|
134 | key: "writeTransaction",
|
135 | value: function writeTransaction(work, transactionConfig) {
|
136 | return this._runTransaction(ACCESS_MODE_WRITE, work, transactionConfig);
|
137 | }
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | }, {
|
146 | key: "close",
|
147 | value: function close() {
|
148 | var _this2 = this;
|
149 |
|
150 | return new _rxjs.Observable(function (observer) {
|
151 | _this2._session.close().then(function () {
|
152 | observer.complete();
|
153 | })["catch"](function (err) {
|
154 | return observer.error(err);
|
155 | });
|
156 | });
|
157 | }
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | }, {
|
171 | key: "lastBookmark",
|
172 | value: function lastBookmark() {
|
173 | return this._session.lastBookmark();
|
174 | }
|
175 | |
176 |
|
177 |
|
178 |
|
179 | }, {
|
180 | key: "_beginTransaction",
|
181 | value: function _beginTransaction(accessMode, transactionConfig) {
|
182 | var _this3 = this;
|
183 |
|
184 | var txConfig = TxConfig.empty();
|
185 |
|
186 | if (transactionConfig) {
|
187 | txConfig = new TxConfig(transactionConfig);
|
188 | }
|
189 |
|
190 | return new _rxjs.Observable(function (observer) {
|
191 | try {
|
192 | observer.next(new _transactionRx["default"](_this3._session._beginTransaction(accessMode, txConfig)));
|
193 | observer.complete();
|
194 | } catch (err) {
|
195 | observer.error(err);
|
196 | }
|
197 |
|
198 | return function () {};
|
199 | });
|
200 | }
|
201 | |
202 |
|
203 |
|
204 |
|
205 | }, {
|
206 | key: "_runTransaction",
|
207 | value: function _runTransaction(accessMode, work, transactionConfig) {
|
208 | var txConfig = TxConfig.empty();
|
209 |
|
210 | if (transactionConfig) {
|
211 | txConfig = new TxConfig(transactionConfig);
|
212 | }
|
213 |
|
214 | return this._retryLogic.retry(this._beginTransaction(accessMode, transactionConfig).pipe((0, _operators.flatMap)(function (txc) {
|
215 | return (0, _rxjs.defer)(function () {
|
216 | try {
|
217 | return work(txc);
|
218 | } catch (err) {
|
219 | return (0, _rxjs.throwError)(err);
|
220 | }
|
221 | }).pipe((0, _operators.catchError)(function (err) {
|
222 | return txc.rollback().pipe((0, _operators.concat)((0, _rxjs.throwError)(err)));
|
223 | }), (0, _operators.concat)(txc.commit()));
|
224 | })));
|
225 | }
|
226 | }]);
|
227 | return RxSession;
|
228 | }();
|
229 |
|
230 | exports["default"] = RxSession;
|
231 |
|
232 | function _createRetryLogic(config) {
|
233 | var maxRetryTimeout = config && config.maxTransactionRetryTime ? config.maxTransactionRetryTime : null;
|
234 | return new _retryLogicRx["default"]({
|
235 | maxRetryTimeout: maxRetryTimeout
|
236 | });
|
237 | } |
\ | No newline at end of file |