1717 * limitations under the License.
1818 */
1919
20+ import { ACCESS_MODE_READ } from './constants' ;
21+
2022// Signature bytes for each request message type
2123const INIT = 0x01 ; // 0000 0001 // INIT <user_agent> <authentication_token>
2224const ACK_FAILURE = 0x0E ; // 0000 1110 // ACK_FAILURE - unused
@@ -31,6 +33,8 @@ const BEGIN = 0x11; // 0001 0001 // BEGIN <metadata>
3133const COMMIT = 0x12 ; // 0001 0010 // COMMIT
3234const ROLLBACK = 0x13 ; // 0001 0011 // ROLLBACK
3335
36+ const READ_MODE = "r" ;
37+
3438export default class RequestMessage {
3539
3640 constructor ( signature , fields , toString ) {
@@ -90,10 +94,11 @@ export default class RequestMessage {
9094 * Create a new BEGIN message.
9195 * @param {Bookmark } bookmark the bookmark.
9296 * @param {TxConfig } txConfig the configuration.
97+ * @param {string } mode the access mode.
9398 * @return {RequestMessage } new BEGIN message.
9499 */
95- static begin ( bookmark , txConfig ) {
96- const metadata = buildTxMetadata ( bookmark , txConfig ) ;
100+ static begin ( bookmark , txConfig , mode ) {
101+ const metadata = buildTxMetadata ( bookmark , txConfig , mode ) ;
97102 return new RequestMessage ( BEGIN , [ metadata ] , ( ) => `BEGIN ${ JSON . stringify ( metadata ) } ` ) ;
98103 }
99104
@@ -119,10 +124,11 @@ export default class RequestMessage {
119124 * @param {object } parameters the statement parameters.
120125 * @param {Bookmark } bookmark the bookmark.
121126 * @param {TxConfig } txConfig the configuration.
127+ * @param {string } mode the access mode.
122128 * @return {RequestMessage } new RUN message with additional metadata.
123129 */
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 ) ;
126132 return new RequestMessage ( RUN , [ statement , parameters , metadata ] ,
127133 ( ) => `RUN ${ statement } ${ JSON . stringify ( parameters ) } ${ JSON . stringify ( metadata ) } ` ) ;
128134 }
@@ -140,9 +146,10 @@ export default class RequestMessage {
140146 * Create an object that represent transaction metadata.
141147 * @param {Bookmark } bookmark the bookmark.
142148 * @param {TxConfig } txConfig the configuration.
149+ * @param {string } mode the access mode.
143150 * @return {object } a metadata object.
144151 */
145- function buildTxMetadata ( bookmark , txConfig ) {
152+ function buildTxMetadata ( bookmark , txConfig , mode ) {
146153 const metadata = { } ;
147154 if ( ! bookmark . isEmpty ( ) ) {
148155 metadata [ 'bookmarks' ] = bookmark . values ( ) ;
@@ -153,6 +160,9 @@ function buildTxMetadata(bookmark, txConfig) {
153160 if ( txConfig . metadata ) {
154161 metadata [ 'tx_metadata' ] = txConfig . metadata ;
155162 }
163+ if ( mode === ACCESS_MODE_READ ) {
164+ metadata [ 'mode' ] = READ_MODE ;
165+ }
156166 return metadata ;
157167}
158168
0 commit comments