@@ -15,7 +15,13 @@ import {
15
15
} from './algebraic_value.ts' ;
16
16
import BinaryReader from './binary_reader.ts' ;
17
17
import BinaryWriter from './binary_writer.ts' ;
18
- import * as ws from './client_api/index.ts' ;
18
+ import { BsatnRowList } from './client_api/bsatn_row_list_type.ts' ;
19
+ import { ClientMessage } from './client_api/client_message_type.ts' ;
20
+ import { DatabaseUpdate } from './client_api/database_update_type.ts' ;
21
+ import { QueryUpdate } from './client_api/query_update_type.ts' ;
22
+ import { ServerMessage } from './client_api/server_message_type.ts' ;
23
+ import { TableUpdate as RawTableUpdate } from './client_api/table_update_type.ts' ;
24
+ import type * as clientApi from './client_api/index.ts' ;
19
25
import { ClientCache } from './client_cache.ts' ;
20
26
import { DbConnectionBuilder } from './db_connection_builder.ts' ;
21
27
import { type DbContext } from './db_context.ts' ;
@@ -41,7 +47,7 @@ import {
41
47
TableCache ,
42
48
type Operation ,
43
49
type PendingCallback ,
44
- type TableUpdate ,
50
+ type TableUpdate as CacheTableUpdate ,
45
51
} from './table_cache.ts' ;
46
52
import { deepEqual , toPascalCase } from './utils.ts' ;
47
53
import { WebsocketDecompressAdapter } from './websocket_decompress_adapter.ts' ;
@@ -53,7 +59,7 @@ import {
53
59
type SubscribeEvent ,
54
60
} from './subscription_builder_impl.ts' ;
55
61
import { stdbLogger } from './logger.ts' ;
56
- import type { ReducerRuntimeTypeInfo } from './spacetime_module.ts' ;
62
+ import { type ReducerRuntimeTypeInfo } from './spacetime_module.ts' ;
57
63
import { fromByteArray } from 'base64-js' ;
58
64
59
65
export {
@@ -274,7 +280,7 @@ export class DbConnectionImpl<
274
280
emitter : handleEmitter ,
275
281
} ) ;
276
282
this . #sendMessage(
277
- ws . ClientMessage . SubscribeMulti ( {
283
+ ClientMessage . SubscribeMulti ( {
278
284
queryStrings : querySql ,
279
285
queryId : { id : queryId } ,
280
286
// The TypeScript SDK doesn't currently track `request_id`s,
@@ -287,7 +293,7 @@ export class DbConnectionImpl<
287
293
288
294
unregisterSubscription ( queryId : number ) : void {
289
295
this . #sendMessage(
290
- ws . ClientMessage . UnsubscribeMulti ( {
296
+ ClientMessage . UnsubscribeMulti ( {
291
297
queryId : { id : queryId } ,
292
298
// The TypeScript SDK doesn't currently track `request_id`s,
293
299
// so always use 0.
@@ -298,12 +304,12 @@ export class DbConnectionImpl<
298
304
299
305
// This function is async because we decompress the message async
300
306
async #processParsedMessage(
301
- message : ws . ServerMessage
307
+ message : ServerMessage
302
308
) : Promise < Message | undefined > {
303
309
const parseRowList = (
304
310
type : 'insert' | 'delete' ,
305
311
tableName : string ,
306
- rowList : ws . BsatnRowList
312
+ rowList : BsatnRowList
307
313
) : Operation [ ] => {
308
314
const buffer = rowList . rowsData ;
309
315
const reader = new BinaryReader ( buffer ) ;
@@ -340,15 +346,15 @@ export class DbConnectionImpl<
340
346
} ;
341
347
342
348
const parseTableUpdate = async (
343
- rawTableUpdate : ws . TableUpdate
344
- ) : Promise < TableUpdate > => {
349
+ rawTableUpdate : RawTableUpdate
350
+ ) : Promise < CacheTableUpdate > => {
345
351
const tableName = rawTableUpdate . tableName ;
346
352
let operations : Operation [ ] = [ ] ;
347
353
for ( const update of rawTableUpdate . updates ) {
348
- let decompressed : ws . QueryUpdate ;
354
+ let decompressed : QueryUpdate ;
349
355
if ( update . tag === 'Gzip' ) {
350
356
const decompressedBuffer = await decompress ( update . value , 'gzip' ) ;
351
- decompressed = ws . QueryUpdate . deserialize (
357
+ decompressed = QueryUpdate . deserialize (
352
358
new BinaryReader ( decompressedBuffer )
353
359
) ;
354
360
} else if ( update . tag === 'Brotli' ) {
@@ -372,9 +378,9 @@ export class DbConnectionImpl<
372
378
} ;
373
379
374
380
const parseDatabaseUpdate = async (
375
- dbUpdate : ws . DatabaseUpdate
376
- ) : Promise < TableUpdate [ ] > => {
377
- const tableUpdates : TableUpdate [ ] = [ ] ;
381
+ dbUpdate : DatabaseUpdate
382
+ ) : Promise < CacheTableUpdate [ ] > => {
383
+ const tableUpdates : CacheTableUpdate [ ] = [ ] ;
378
384
for ( const rawTableUpdate of dbUpdate . tables ) {
379
385
tableUpdates . push ( await parseTableUpdate ( rawTableUpdate ) ) ;
380
386
}
@@ -412,7 +418,7 @@ export class DbConnectionImpl<
412
418
const args = txUpdate . reducerCall . args ;
413
419
const energyQuantaUsed = txUpdate . energyQuantaUsed ;
414
420
415
- let tableUpdates : TableUpdate [ ] ;
421
+ let tableUpdates : CacheTableUpdate [ ] ;
416
422
let errMessage = '' ;
417
423
switch ( txUpdate . status . tag ) {
418
424
case 'Committed' :
@@ -512,11 +518,11 @@ export class DbConnectionImpl<
512
518
}
513
519
}
514
520
515
- #sendMessage( message : ws . ClientMessage ) : void {
521
+ #sendMessage( message : ClientMessage ) : void {
516
522
this . wsPromise . then ( wsResolved => {
517
523
if ( wsResolved ) {
518
524
const writer = new BinaryWriter ( 1024 ) ;
519
- ws . ClientMessage . serialize ( writer , message ) ;
525
+ ClientMessage . serialize ( writer , message ) ;
520
526
const encoded = writer . getBuffer ( ) ;
521
527
wsResolved . send ( encoded ) ;
522
528
}
@@ -531,7 +537,7 @@ export class DbConnectionImpl<
531
537
}
532
538
533
539
#applyTableUpdates(
534
- tableUpdates : TableUpdate [ ] ,
540
+ tableUpdates : CacheTableUpdate [ ] ,
535
541
eventContext : EventContextInterface
536
542
) : PendingCallback [ ] {
537
543
let pendingCallbacks : PendingCallback [ ] = [ ] ;
@@ -549,7 +555,7 @@ export class DbConnectionImpl<
549
555
}
550
556
551
557
async #processMessage( data : Uint8Array ) : Promise < void > {
552
- const serverMessage = parseValue ( ws . ServerMessage , data ) ;
558
+ const serverMessage = parseValue ( ServerMessage , data ) ;
553
559
const message = await this . #processParsedMessage( serverMessage ) ;
554
560
if ( ! message ) {
555
561
return ;
@@ -803,7 +809,7 @@ export class DbConnectionImpl<
803
809
argsBuffer : Uint8Array ,
804
810
flags : CallReducerFlags
805
811
) : void {
806
- const message = ws . ClientMessage . CallReducer ( {
812
+ const message = ClientMessage . CallReducer ( {
807
813
reducer : reducerName ,
808
814
args : argsBuffer ,
809
815
// The TypeScript SDK doesn't currently track `request_id`s,
0 commit comments