17
17
* limitations under the License.
18
18
*/
19
19
20
+ import { ACCESS_MODE_READ } from './constants' ;
21
+
20
22
// Signature bytes for each request message type
21
23
const INIT = 0x01 ; // 0000 0001 // INIT <user_agent> <authentication_token>
22
24
const ACK_FAILURE = 0x0E ; // 0000 1110 // ACK_FAILURE - unused
@@ -31,6 +33,8 @@ const BEGIN = 0x11; // 0001 0001 // BEGIN <metadata>
31
33
const COMMIT = 0x12 ; // 0001 0010 // COMMIT
32
34
const ROLLBACK = 0x13 ; // 0001 0011 // ROLLBACK
33
35
36
+ const READ_MODE = "r" ;
37
+
34
38
export default class RequestMessage {
35
39
36
40
constructor ( signature , fields , toString ) {
@@ -90,10 +94,11 @@ export default class RequestMessage {
90
94
* Create a new BEGIN message.
91
95
* @param {Bookmark } bookmark the bookmark.
92
96
* @param {TxConfig } txConfig the configuration.
97
+ * @param {string } mode the access mode.
93
98
* @return {RequestMessage } new BEGIN message.
94
99
*/
95
- static begin ( bookmark , txConfig ) {
96
- const metadata = buildTxMetadata ( bookmark , txConfig ) ;
100
+ static begin ( bookmark , txConfig , mode ) {
101
+ const metadata = buildTxMetadata ( bookmark , txConfig , mode ) ;
97
102
return new RequestMessage ( BEGIN , [ metadata ] , ( ) => `BEGIN ${ JSON . stringify ( metadata ) } ` ) ;
98
103
}
99
104
@@ -119,10 +124,11 @@ export default class RequestMessage {
119
124
* @param {object } parameters the statement parameters.
120
125
* @param {Bookmark } bookmark the bookmark.
121
126
* @param {TxConfig } txConfig the configuration.
127
+ * @param {string } mode the access mode.
122
128
* @return {RequestMessage } new RUN message with additional metadata.
123
129
*/
124
- static runWithMetadata ( statement , parameters , bookmark , txConfig ) {
125
- const metadata = buildTxMetadata ( bookmark , txConfig ) ;
130
+ static runWithMetadata ( statement , parameters , bookmark , txConfig , mode ) {
131
+ const metadata = buildTxMetadata ( bookmark , txConfig , mode ) ;
126
132
return new RequestMessage ( RUN , [ statement , parameters , metadata ] ,
127
133
( ) => `RUN ${ statement } ${ JSON . stringify ( parameters ) } ${ JSON . stringify ( metadata ) } ` ) ;
128
134
}
@@ -140,9 +146,10 @@ export default class RequestMessage {
140
146
* Create an object that represent transaction metadata.
141
147
* @param {Bookmark } bookmark the bookmark.
142
148
* @param {TxConfig } txConfig the configuration.
149
+ * @param {string } mode the access mode.
143
150
* @return {object } a metadata object.
144
151
*/
145
- function buildTxMetadata ( bookmark , txConfig ) {
152
+ function buildTxMetadata ( bookmark , txConfig , mode ) {
146
153
const metadata = { } ;
147
154
if ( ! bookmark . isEmpty ( ) ) {
148
155
metadata [ 'bookmarks' ] = bookmark . values ( ) ;
@@ -153,6 +160,9 @@ function buildTxMetadata(bookmark, txConfig) {
153
160
if ( txConfig . metadata ) {
154
161
metadata [ 'tx_metadata' ] = txConfig . metadata ;
155
162
}
163
+ if ( mode === ACCESS_MODE_READ ) {
164
+ metadata [ 'mode' ] = READ_MODE ;
165
+ }
156
166
return metadata ;
157
167
}
158
168
0 commit comments