1- function version ( ) {
1+ import { decodeActorId , defaultActorIdCodec , encodeActorId } from "./actor-id" ;
2+
3+ export type Message = {
4+ epoch : number ;
5+ channelId : number ;
6+ sourceId : number ;
7+ sourceSeq : number ;
8+ schemaId : number ;
9+ qos ?: number ;
10+ payload : number ;
11+ } ;
12+
13+ export type AeronConfig = {
14+ channel : string ;
15+ streamId : number ;
16+ aeronDirectory : string ;
17+ } ;
18+
19+ export function version ( ) : string {
220 return "0.1.0" ;
321}
422
5- const actorId = require ( "./actor-id" ) ;
6-
723const FNV_OFFSET_BASIS = 0xcbf29ce484222325n ;
824const FNV_PRIME = 0x100000001b3n ;
925const FNV_MASK = 0xffffffffffffffffn ;
1026
11- function fnv1a64Hex ( input ) {
27+ export function fnv1a64Hex ( input : string ) : string {
1228 let hash = FNV_OFFSET_BASIS ;
1329 const bytes = Buffer . from ( input , "utf8" ) ;
1430 for ( const b of bytes ) {
@@ -18,7 +34,7 @@ function fnv1a64Hex(input) {
1834 return hash . toString ( 16 ) . padStart ( 16 , "0" ) ;
1935}
2036
21- function processMessages ( messages ) {
37+ export function processMessages ( messages : Message [ ] ) {
2238 messages . sort ( ( a , b ) => {
2339 if ( a . epoch !== b . epoch ) return a . epoch - b . epoch ;
2440 if ( a . channelId !== b . channelId ) return a . channelId - b . channelId ;
@@ -29,9 +45,9 @@ function processMessages(messages) {
2945 return a . sourceSeq - b . sourceSeq ;
3046 } ) ;
3147
32- const results = [ ] ;
48+ const results : { epoch : number ; state : number ; hash : string } [ ] = [ ] ;
3349 let state = 0 ;
34- let currentEpoch = null ;
50+ let currentEpoch : number | null = null ;
3551
3652 for ( const message of messages ) {
3753 if ( currentEpoch === null ) {
@@ -59,16 +75,14 @@ function processMessages(messages) {
5975 return results ;
6076}
6177
62- class InMemoryTransport {
63- constructor ( ) {
64- this . queue = [ ] ;
65- }
78+ export class InMemoryTransport {
79+ private queue : Message [ ] = [ ] ;
6680
67- send ( message ) {
81+ send ( message : Message ) {
6882 this . queue . push ( message ) ;
6983 }
7084
71- poll ( max ) {
85+ poll ( max : number ) {
7286 if ( ! max || this . queue . length === 0 ) {
7387 return [ ] ;
7488 }
@@ -81,10 +95,8 @@ class InMemoryTransport {
8195 }
8296}
8397
84- class AeronTransport {
85- constructor ( config ) {
86- this . config = config ;
87- }
98+ export class AeronTransport {
99+ constructor ( public readonly config : AeronConfig ) { }
88100
89101 send ( ) {
90102 throw new Error ( "Aeron transport not linked" ) ;
@@ -97,13 +109,4 @@ class AeronTransport {
97109 close ( ) { }
98110}
99111
100- module . exports = {
101- version,
102- fnv1a64Hex,
103- processMessages,
104- InMemoryTransport,
105- AeronTransport,
106- defaultActorIdCodec : actorId . defaultActorIdCodec ,
107- encodeActorId : actorId . encodeActorId ,
108- decodeActorId : actorId . decodeActorId
109- } ;
112+ export { defaultActorIdCodec , encodeActorId , decodeActorId } ;
0 commit comments