Skip to content

Commit 623f893

Browse files
committed
populate resultAvailableAfter during transaction#run
1 parent ed03624 commit 623f893

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ node_modules
1010
.idea
1111
docs/build
1212
.npmrc
13+
*.iml

src/v1/internal/stream-observer.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
2019
import Record from "../record";
2120

2221
/**
@@ -44,6 +43,7 @@ class StreamObserver {
4443
this._errorTransformer = errorTransformer;
4544
this._observer = null;
4645
this._conn = null;
46+
this._meta = {};
4747
}
4848

4949
/**
@@ -83,6 +83,20 @@ class StreamObserver {
8383
this._tail = meta;
8484
}
8585
}
86+
this._copyMetadataOnCompletion( meta );
87+
}
88+
89+
_copyMetadataOnCompletion(meta) {
90+
for (var key in meta) {
91+
if (meta.hasOwnProperty(key)) {
92+
this._meta[key] = meta[key];
93+
}
94+
}
95+
}
96+
97+
serverMetadata() {
98+
const serverMeta = {server: this._conn.server};
99+
return Object.assign({}, this._meta, serverMeta);
86100
}
87101

88102
resolveConnection(conn) {

src/v1/session.js

+2-24
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Session {
7171
}
7272

7373
_run(statement, parameters, statementRunner) {
74-
const streamObserver = new _RunObserver(this._onRunFailure());
74+
const streamObserver = new StreamObserver(this._onRunFailure());
7575
const connectionHolder = this._connectionHolderWithMode(this._mode);
7676
if (!this._hasTx) {
7777
connectionHolder.initializeConnection();
@@ -86,7 +86,7 @@ class Session {
8686
'session with an open transaction; either run from within the ' +
8787
'transaction or use a different session.'));
8888
}
89-
return new Result(streamObserver, statement, parameters, () => streamObserver.meta(), connectionHolder);
89+
return new Result(streamObserver, statement, parameters, () => streamObserver.serverMetadata(), connectionHolder);
9090
}
9191

9292
/**
@@ -217,28 +217,6 @@ class Session {
217217
}
218218
}
219219

220-
/** Internal stream observer used for transactional results*/
221-
class _RunObserver extends StreamObserver {
222-
constructor(onError) {
223-
super(onError);
224-
this._meta = {};
225-
}
226-
227-
onCompleted(meta) {
228-
super.onCompleted(meta);
229-
for(var key in meta){
230-
if(meta.hasOwnProperty(key)){
231-
this._meta[key]=meta[key];
232-
}
233-
}
234-
}
235-
236-
meta() {
237-
const serverMeta = {server: this._conn.server};
238-
return Object.assign({}, this._meta, serverMeta);
239-
}
240-
}
241-
242220
function _createTransactionExecutor(config) {
243221
const maxRetryTimeMs = (config && config.maxTransactionRetryTime) ? config.maxTransactionRetryTime : null;
244222
return new TransactionExecutor(maxRetryTimeMs);

src/v1/transaction.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ class _TransactionStreamObserver extends StreamObserver {
153153
const bookmark = meta.bookmark;
154154
this._tx._onBookmark(bookmark);
155155
}
156-
157-
serverMeta() {
158-
const serverMeta = {server: this._conn.server};
159-
return serverMeta;
160-
}
161156
}
162157

163158
/** internal state machine of the transaction*/
@@ -179,7 +174,7 @@ let _states = {
179174
conn.sync();
180175
}).catch(error => observer.onError(error));
181176

182-
return _newRunResult(observer, statement, parameters, () => observer.serverMeta());
177+
return _newRunResult(observer, statement, parameters, () => observer.serverMetadata());
183178
}
184179
},
185180

test/v1/transaction.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ describe('transaction', () => {
6161
}).catch(console.log);
6262
});
6363

64+
it('should populate resultAvailableAfter for transaction#run', done => {
65+
const tx = session.beginTransaction();
66+
tx.run("CREATE (:TXNode1)").then(result => {
67+
tx.commit().then(() => {
68+
expect(result.summary.resultAvailableAfter).toBeDefined();
69+
expect(result.summary.resultAvailableAfter.toInt()).not.toBeLessThan(0);
70+
done();
71+
}).catch(console.log);
72+
}).catch(console.log);
73+
});
74+
6475
it('should handle interactive session', done => {
6576
const tx = session.beginTransaction();
6677
tx.run("RETURN 'foo' AS res").then(result => {

0 commit comments

Comments
 (0)