@@ -19,11 +19,10 @@ import {
1919 createPaginationTestSuite ,
2020 createPredicatesTestSuite ,
2121 createProgressiveTestSuite ,
22- generateSeedData
23-
22+ generateSeedData ,
2423} from '../../db-collection-e2e/src/index'
25- import type { Client } from 'trailbase' ;
26- import type { SeedDataResult } from '../../db-collection-e2e/src/index' ;
24+ import type { Client } from 'trailbase'
25+ import type { SeedDataResult } from '../../db-collection-e2e/src/index'
2726import type { TrailBaseSyncMode } from '../src/trailbase'
2827import type {
2928 Comment ,
@@ -41,16 +40,21 @@ declare module 'vitest' {
4140
4241// / Decode a "url-safe" base64 string to bytes.
4342function urlSafeBase64Decode ( base64 : string ) : Uint8Array {
44- return Uint8Array . from ( atob ( base64 . replace ( / _ / g, "/" ) . replace ( / - / g, "+" ) ) , ( c ) => c . charCodeAt ( 0 ) ) ;
43+ return Uint8Array . from (
44+ atob ( base64 . replace ( / _ / g, '/' ) . replace ( / - / g, '+' ) ) ,
45+ ( c ) => c . charCodeAt ( 0 ) ,
46+ )
4547}
4648
4749// / Encode an arbitrary string input as a "url-safe" base64 string.
4850function urlSafeBase64Encode ( bytes : Uint8Array ) : string {
49- return btoa ( String . fromCharCode ( ...bytes ) ) . replace ( / \/ / g, "_" ) . replace ( / \+ / g, "-" ) ;
51+ return btoa ( String . fromCharCode ( ...bytes ) )
52+ . replace ( / \/ / g, '_' )
53+ . replace ( / \+ / g, '-' )
5054}
5155
5256function parseTrailBaseId ( id : string ) : string {
53- return uuidStringify ( urlSafeBase64Decode ( id ) ) ;
57+ return uuidStringify ( urlSafeBase64Decode ( id ) )
5458}
5559
5660function toTrailBaseId ( id : string ) : string {
@@ -141,15 +145,15 @@ function createCollectionsForSyncMode(
141145 id : parseTrailBaseId ,
142146 isActive : ( isActive ) => Boolean ( isActive ) ,
143147 createdAt : ( createdAt ) => new Date ( createdAt ) ,
144- metadata : ( m ) => m ? JSON . parse ( m ) : null ,
145- deletedAt : ( d ) => d ? new Date ( d ) : null ,
148+ metadata : ( m ) => ( m ? JSON . parse ( m ) : null ) ,
149+ deletedAt : ( d ) => ( d ? new Date ( d ) : null ) ,
146150 } ,
147151 serialize : {
148152 id : toTrailBaseId ,
149- isActive : ( a ) => a ? 1 : 0 ,
153+ isActive : ( a ) => ( a ? 1 : 0 ) ,
150154 createdAt : ( c ) => c . toISOString ( ) ,
151- metadata : ( m ) => m ? JSON . stringify ( m ) : null ,
152- deletedAt : ( d ) => d ? d . toISOString ( ) : null ,
155+ metadata : ( m ) => ( m ? JSON . stringify ( m ) : null ) ,
156+ deletedAt : ( d ) => ( d ? d . toISOString ( ) : null ) ,
153157 } ,
154158 } ) ,
155159 )
@@ -164,14 +168,14 @@ function createCollectionsForSyncMode(
164168 parse : {
165169 id : parseTrailBaseId ,
166170 largeViewCount : ( l ) => BigInt ( l ) ,
167- publishedAt : ( v ) => v ? new Date ( v ) : null ,
168- deletedAt : ( d ) => d ? new Date ( d ) : null ,
171+ publishedAt : ( v ) => ( v ? new Date ( v ) : null ) ,
172+ deletedAt : ( d ) => ( d ? new Date ( d ) : null ) ,
169173 } ,
170174 serialize : {
171175 id : toTrailBaseId ,
172176 largeViewCount : ( v ) => v . toString ( ) ,
173- publishedAt : ( v ) => v ? v . toISOString ( ) : null ,
174- deletedAt : ( d ) => d ? d . toISOString ( ) : null ,
177+ publishedAt : ( v ) => ( v ? v . toISOString ( ) : null ) ,
178+ deletedAt : ( d ) => ( d ? d . toISOString ( ) : null ) ,
175179 } ,
176180 } ) ,
177181 )
@@ -186,12 +190,12 @@ function createCollectionsForSyncMode(
186190 parse : {
187191 id : parseTrailBaseId ,
188192 createdAt : ( v ) => new Date ( v ) ,
189- deletedAt : ( d ) => d ? new Date ( d ) : null ,
193+ deletedAt : ( d ) => ( d ? new Date ( d ) : null ) ,
190194 } ,
191195 serialize : {
192196 id : toTrailBaseId ,
193197 createdAt : ( v ) => v . toISOString ( ) ,
194- deletedAt : ( d ) => d ? d . toISOString ( ) : null ,
198+ deletedAt : ( d ) => ( d ? d . toISOString ( ) : null ) ,
195199 } ,
196200 } ) ,
197201 )
@@ -239,10 +243,7 @@ async function initialCleanup(client: Client) {
239243 console . log ( `Cleanup complete` )
240244}
241245
242- async function setupInitialData (
243- client : Client ,
244- seedData : SeedDataResult ,
245- ) {
246+ async function setupInitialData ( client : Client , seedData : SeedDataResult ) {
246247 const usersRecordApi = client . records < UserRecord > ( `users_e2e` )
247248 const postsRecordApi = client . records < PostRecord > ( `posts_e2e` )
248249 const commentsRecordApi = client . records < CommentRecord > ( `comments_e2e` )
@@ -300,10 +301,10 @@ describe(`TrailBase Collection E2E Tests`, async () => {
300301 const client = initClient ( baseUrl )
301302
302303 // Wipe all pre-existing data, e.g. when using a persistent TB instance.
303- await initialCleanup ( client ) ;
304+ await initialCleanup ( client )
304305
305306 const seedData = generateSeedData ( )
306- await setupInitialData ( client , seedData ) ;
307+ await setupInitialData ( client , seedData )
307308
308309 async function getConfig ( ) : Promise < E2ETestConfig > {
309310 // Create collections with different sync modes
@@ -337,11 +338,13 @@ describe(`TrailBase Collection E2E Tests`, async () => {
337338 eagerCollections . posts . preload ( ) ,
338339 eagerCollections . comments . preload ( ) ,
339340 ] )
340- expect ( eagerCollections . posts . size ) . toEqual ( seedData . posts . length ) ;
341- expect ( eagerCollections . comments . size ) . toEqual ( seedData . comments . length ) ;
341+ expect ( eagerCollections . posts . size ) . toEqual ( seedData . posts . length )
342+ expect ( eagerCollections . comments . size ) . toEqual ( seedData . comments . length )
342343
343344 // NOTE: One of the tests deletes a user :/
344- expect ( eagerCollections . users . size ) . toBeGreaterThanOrEqual ( seedData . users . length - 1 ) ;
345+ expect ( eagerCollections . users . size ) . toBeGreaterThanOrEqual (
346+ seedData . users . length - 1 ,
347+ )
345348
346349 const usersRecordApi = client . records < UserRecord > ( `users_e2e` )
347350 const postsRecordApi = client . records < PostRecord > ( `posts_e2e` )
@@ -386,7 +389,7 @@ describe(`TrailBase Collection E2E Tests`, async () => {
386389 await postsRecordApi . create ( serializePost ( post ) )
387390 } ,
388391 } ,
389- setup : async ( ) => { } ,
392+ setup : async ( ) => { } ,
390393 teardown : async ( ) => {
391394 await Promise . all ( [
392395 eagerCollections . users . cleanup ( ) ,
0 commit comments