@@ -17,18 +17,18 @@ import {Transform, TransformOptions} from 'stream';
1717
1818import { Bytes , Mutation } from './mutation' ;
1919
20- export type Value = string | number | boolean | Uint8Array ;
20+ export type Value = string | number | boolean | Uint8Array ;
2121
2222export interface Chunk {
2323 rowContents : Value ;
2424 commitRow : boolean ;
2525 resetRow : boolean ;
26- rowKey ?: string | Uint8Array ;
26+ rowKey ?: string | Uint8Array ;
2727 familyName ?: { value : string } ;
28- qualifier ?: Qualifier | { value : Value } ;
29- timestampMicros ?: number | Long ;
28+ qualifier ?: Qualifier | { value : Value } ;
29+ timestampMicros ?: number | Long ;
3030 labels ?: string [ ] ;
31- value ?: string | Buffer ;
31+ value ?: string | Buffer ;
3232 valueSize ?: number ;
3333}
3434export interface Data {
@@ -39,9 +39,9 @@ interface Family {
3939 [ qualifier : string ] : Qualifier [ ] ;
4040}
4141export interface Qualifier {
42- value ?: string | Buffer ;
42+ value ?: string | Buffer ;
4343 labels ?: string [ ] ;
44- timestamp ?: number | Long ;
44+ timestamp ?: number | Long ;
4545 size ?: number ;
4646}
4747export interface Row {
@@ -50,7 +50,7 @@ export interface Row {
5050}
5151export interface TransformErrorProps {
5252 message : string ;
53- chunk : Chunk | null ;
53+ chunk : Chunk | null ;
5454}
5555
5656class TransformError extends Error {
@@ -88,7 +88,7 @@ export class ChunkTransformer extends Transform {
8888 qualifiers ?: Qualifier [ ] ;
8989 qualifier ?: Qualifier ;
9090 constructor ( options : TransformOptions = { } ) {
91- options . objectMode = true ; // forcing object mode
91+ options . objectMode = true ; // forcing object mode
9292 super ( options ) ;
9393 this . options = options ;
9494 this . _destroyed = false ;
@@ -103,10 +103,12 @@ export class ChunkTransformer extends Transform {
103103 */
104104 _flush ( cb : Function ) : void {
105105 if ( typeof this . row ! . key !== 'undefined' ) {
106- this . destroy ( new TransformError ( {
107- message : 'Response ended with pending row without commit' ,
108- chunk : null ,
109- } ) ) ;
106+ this . destroy (
107+ new TransformError ( {
108+ message : 'Response ended with pending row without commit' ,
109+ chunk : null ,
110+ } )
111+ ) ;
110112 return ;
111113 }
112114 cb ( ) ;
@@ -149,10 +151,12 @@ export class ChunkTransformer extends Transform {
149151 }
150152 }
151153 if ( data . lastScannedRowKey && data . lastScannedRowKey . length > 0 ) {
152- this . lastRowKey =
153- Mutation . convertFromBytes ( data . lastScannedRowKey as Bytes , {
154- userOptions : this . options ,
155- } ) ;
154+ this . lastRowKey = Mutation . convertFromBytes (
155+ data . lastScannedRowKey as Bytes ,
156+ {
157+ userOptions : this . options ,
158+ }
159+ ) ;
156160 }
157161 next ( ) ;
158162 }
@@ -200,10 +204,12 @@ export class ChunkTransformer extends Transform {
200204 */
201205 validateValueSizeAndCommitRow ( chunk : Chunk ) : void {
202206 if ( chunk . valueSize ! > 0 && chunk . commitRow ) {
203- this . destroy ( new TransformError ( {
204- message : 'A row cannot be have a value size and be a commit row' ,
205- chunk,
206- } ) ) ;
207+ this . destroy (
208+ new TransformError ( {
209+ message : 'A row cannot be have a value size and be a commit row' ,
210+ chunk,
211+ } )
212+ ) ;
207213 }
208214 }
209215
@@ -213,14 +219,19 @@ export class ChunkTransformer extends Transform {
213219 * @param {chunk } chunk chunk to validate for resetrow
214220 */
215221 validateResetRow ( chunk : Chunk ) : void {
216- const containsData = ( chunk . rowKey && chunk . rowKey . length !== 0 ) ||
217- chunk . familyName || chunk . qualifier ||
218- ( chunk . value && chunk . value . length !== 0 ) || chunk . timestampMicros ! > 0 ;
222+ const containsData =
223+ ( chunk . rowKey && chunk . rowKey . length !== 0 ) ||
224+ chunk . familyName ||
225+ chunk . qualifier ||
226+ ( chunk . value && chunk . value . length !== 0 ) ||
227+ chunk . timestampMicros ! > 0 ;
219228 if ( chunk . resetRow && containsData ) {
220- this . destroy ( new TransformError ( {
221- message : 'A reset should have no data' ,
222- chunk,
223- } ) ) ;
229+ this . destroy (
230+ new TransformError ( {
231+ message : 'A reset should have no data' ,
232+ chunk,
233+ } )
234+ ) ;
224235 }
225236 }
226237
@@ -230,16 +241,18 @@ export class ChunkTransformer extends Transform {
230241 * @param {chunk } chunk chunk to validate
231242 * @param {newRowKey } newRowKey newRowKey of the new row
232243 */
233- validateNewRow ( chunk : Chunk , newRowKey : string | Buffer ) : void {
244+ validateNewRow ( chunk : Chunk , newRowKey : string | Buffer ) : void {
234245 const row = this . row ;
235246 const lastRowKey = this . lastRowKey ;
236- let errorMessage : string | undefined ;
247+ let errorMessage : string | undefined ;
237248
238249 if ( typeof row ! . key !== 'undefined' ) {
239250 errorMessage = 'A new row cannot have existing state' ;
240251 } else if (
241- typeof chunk . rowKey === 'undefined' || chunk . rowKey . length === 0 ||
242- newRowKey . length === 0 ) {
252+ typeof chunk . rowKey === 'undefined' ||
253+ chunk . rowKey . length === 0 ||
254+ newRowKey . length === 0
255+ ) {
243256 errorMessage = 'A row key must be set' ;
244257 } else if ( chunk . resetRow ) {
245258 errorMessage = 'A new row cannot be reset' ;
@@ -269,21 +282,31 @@ export class ChunkTransformer extends Transform {
269282 userOptions : this . options ,
270283 } ) ;
271284 const oldRowKey = row ! . key || '' ;
272- if ( newRowKey && chunk . rowKey && ( newRowKey as string ) . length !== 0 &&
273- newRowKey . toString ( ) !== oldRowKey . toString ( ) ) {
274- this . destroy ( new TransformError ( {
275- message : 'A commit is required between row keys' ,
276- chunk,
277- } ) ) ;
285+ if (
286+ newRowKey &&
287+ chunk . rowKey &&
288+ ( newRowKey as string ) . length !== 0 &&
289+ newRowKey . toString ( ) !== oldRowKey . toString ( )
290+ ) {
291+ this . destroy (
292+ new TransformError ( {
293+ message : 'A commit is required between row keys' ,
294+ chunk,
295+ } )
296+ ) ;
278297 return ;
279298 }
280299 }
281- if ( chunk . familyName &&
282- ( chunk . qualifier === null || chunk . qualifier === undefined ) ) {
283- this . destroy ( new TransformError ( {
284- message : 'A qualifier must be specified' ,
285- chunk,
286- } ) ) ;
300+ if (
301+ chunk . familyName &&
302+ ( chunk . qualifier === null || chunk . qualifier === undefined )
303+ ) {
304+ this . destroy (
305+ new TransformError ( {
306+ message : 'A qualifier must be specified' ,
307+ chunk,
308+ } )
309+ ) ;
287310 return ;
288311 }
289312 this . validateResetRow ( chunk ) ;
@@ -335,11 +358,13 @@ export class ChunkTransformer extends Transform {
335358 row ! . key = newRowKey ;
336359 row ! . data = { } as Data ;
337360 this . family = row ! . data ! [ chunk . familyName . value ] = { } as Family ;
338- const qualifierName =
339- Mutation . convertFromBytes ( chunk . qualifier . value as Bytes , {
340- userOptions : this . options ,
341- } ) ;
342- this . qualifiers = this . family [ qualifierName as { } as string ] = [ ] ;
361+ const qualifierName = Mutation . convertFromBytes (
362+ chunk . qualifier . value as Bytes ,
363+ {
364+ userOptions : this . options ,
365+ }
366+ ) ;
367+ this . qualifiers = this . family [ ( qualifierName as { } ) as string ] = [ ] ;
343368 this . qualifier = {
344369 value : Mutation . convertFromBytes ( chunk . value ! as Bytes , {
345370 userOptions : this . options ,
@@ -366,15 +391,17 @@ export class ChunkTransformer extends Transform {
366391 const row = this . row ;
367392 if ( chunk . familyName ) {
368393 this . family = row ! . data ! [ chunk . familyName . value ] =
369- row ! . data ! [ chunk . familyName . value ] || { } ;
394+ row ! . data ! [ chunk . familyName . value ] || { } ;
370395 }
371396 if ( chunk . qualifier ) {
372- const qualifierName =
373- Mutation . convertFromBytes ( chunk . qualifier . value as Bytes , {
374- userOptions : this . options ,
375- } ) as string ;
397+ const qualifierName = Mutation . convertFromBytes (
398+ chunk . qualifier . value as Bytes ,
399+ {
400+ userOptions : this . options ,
401+ }
402+ ) as string ;
376403 this . qualifiers = this . family ! [ qualifierName ] =
377- this . family ! [ qualifierName ] || [ ] ;
404+ this . family ! [ qualifierName ] || [ ] ;
378405 }
379406 this . qualifier = {
380407 value : Mutation . convertFromBytes ( chunk . value ! as Bytes , {
@@ -398,13 +425,17 @@ export class ChunkTransformer extends Transform {
398425 if ( chunk . resetRow ) {
399426 return this . reset ( ) ;
400427 }
401- const chunkQualifierValue =
402- Mutation . convertFromBytes ( chunk . value ! as Bytes , {
403- userOptions : this . options ,
404- } ) ;
428+ const chunkQualifierValue = Mutation . convertFromBytes (
429+ chunk . value ! as Bytes ,
430+ {
431+ userOptions : this . options ,
432+ }
433+ ) ;
405434
406- if ( chunkQualifierValue instanceof Buffer &&
407- this . qualifier ! . value instanceof Buffer ) {
435+ if (
436+ chunkQualifierValue instanceof Buffer &&
437+ this . qualifier ! . value instanceof Buffer
438+ ) {
408439 this . qualifier ! . value = Buffer . concat ( [
409440 this . qualifier ! . value ,
410441 chunkQualifierValue ,
0 commit comments