@@ -38,27 +38,27 @@ export const getDb = (props: DbProps = {}): DbMutable => {
3838 } ,
3939 } = props ;
4040 const parsedProps = {
41- pathname : getModulePath ( pathname ) ,
41+ pathname,
4242 backups : {
4343 onMigration,
44- pathname : getModulePath ( backupsPathname ) ,
44+ pathname : backupsPathname ,
4545 } ,
4646 } ;
4747 let db : Deno . Kv ;
4848
4949 const load = async ( ) => {
5050 try {
51- await Deno . stat ( parsedProps . backups . pathname ! ) ;
51+ await Deno . stat ( getModulePath ( backupsPathname ) ! ) ;
5252 } catch ( e ) {
53- await Deno . mkdir ( parsedProps . backups . pathname ! ) ;
53+ await Deno . mkdir ( getModulePath ( backupsPathname ) ! ) ;
5454 }
5555
5656 await $crypto . load ( ) ;
57- db = await Deno . openKv ( parsedProps . pathname ) ;
57+ db = await Deno . openKv ( getModulePath ( pathname ) ) ;
5858 } ;
5959
6060 const $checkDbNull = ( ) => {
61- if ( ! db ) console . error ( `Db '${ parsedProps . pathname } ' is closed!` ) ;
61+ if ( ! db ) console . error ( `Db '${ pathname } ' is closed!` ) ;
6262
6363 return Boolean ( db ) ;
6464 } ;
@@ -176,23 +176,20 @@ export const getDb = (props: DbProps = {}): DbMutable => {
176176 } ;
177177
178178 const backup = async ( name ?: string ) => {
179- const backupPathname = join (
180- parsedProps . backups . pathname ! ,
181- parsedProps . pathname ,
182- ) ;
179+ const backupPathname = join ( backupsPathname ! , pathname ) ;
183180
184181 const files = [ "" , "-shm" , "-wal" , DATABASE_PEPPER_FILE , DATABASE_KEY_FILE ] ;
185182
186183 for ( const file of files )
187184 try {
188185 await Deno . copyFile (
189- parsedProps . pathname + file ,
190- parsedProps . backups . pathname + file ,
186+ getModulePath ( pathname + file ) ,
187+ getModulePath ( backupPathname + file ) ,
191188 ) ;
192189 // deno-lint-ignore no-empty
193190 } catch ( _ ) { }
194191
195- const backupDb = await Deno . openKv ( parsedProps . backups . pathname ) ;
192+ const backupDb = await Deno . openKv ( getModulePath ( backupPathname ) ) ;
196193 //this removes 'shm' and 'wal' files and closes correctly the db
197194 backupDb . close ( ) ;
198195
@@ -202,14 +199,14 @@ export const getDb = (props: DbProps = {}): DbMutable => {
202199 : null ;
203200
204201 await compressFiles (
205- files . map ( ( file ) => parsedProps . backups . pathname + file ) ,
206- join ( parsedProps . backups . pathname ! , backupFilename + ".zip" ) ,
202+ files . map ( ( file ) => getModulePath ( backupPathname ) + file ) ,
203+ join ( getModulePath ( backupsPathname ) ! , backupFilename + ".zip" ) ,
207204 filePassword ,
208205 ) ;
209206
210207 for ( const file of files )
211208 try {
212- await Deno . remove ( parsedProps . backups . pathname + file ) ;
209+ await Deno . remove ( getModulePath ( backupPathname ) + file ) ;
213210 // deno-lint-ignore no-empty
214211 } catch ( _ ) { }
215212
@@ -218,7 +215,7 @@ export const getDb = (props: DbProps = {}): DbMutable => {
218215
219216 const files = [ ] ;
220217
221- for await ( const entry of walk ( parsedProps . backups . pathname ! , {
218+ for await ( const entry of walk ( getModulePath ( backupsPathname ) ! , {
222219 includeDirs : false ,
223220 } ) )
224221 files . push ( entry ) ;
@@ -232,7 +229,7 @@ export const getDb = (props: DbProps = {}): DbMutable => {
232229 }
233230
234231 const s3Client = getS3 ( s3 ) ;
235- await s3Client . syncPath ( backupsPathname , true ) ;
232+ await s3Client . syncPath ( getModulePath ( backupsPathname ) , true ) ;
236233
237234 const s3Files = await s3Client . getFiles ( ) ;
238235 s3Files . sort ( ( fileA , fileB ) => ( fileA . name > fileB . name ? - 1 : 1 ) ) ;
@@ -251,7 +248,7 @@ export const getDb = (props: DbProps = {}): DbMutable => {
251248
252249 const files : BackupFile [ ] = [ ] ;
253250
254- for await ( const { name, path } of walk ( parsedProps . backups . pathname ! , {
251+ for await ( const { name, path } of walk ( getModulePath ( backupsPathname ) ! , {
255252 includeDirs : false ,
256253 } ) ) {
257254 const { size } = await Deno . stat ( path ) ;
@@ -269,15 +266,15 @@ export const getDb = (props: DbProps = {}): DbMutable => {
269266 const s3Client = getS3 ( s3 ) ;
270267 return await s3Client . getObject ( name ) ;
271268 }
272- return await Deno . readFile ( join ( parsedProps . backups . pathname ! , name ) ) ;
269+ return await Deno . readFile ( join ( getModulePath ( backupsPathname ) ! , name ) ) ;
273270 } ;
274271
275272 const removeBackup = async ( name : string ) : Promise < void > => {
276273 if ( s3 ) {
277274 const s3Client = getS3 ( s3 ) ;
278275 return await s3Client . removeFiles ( name ) ;
279276 }
280- return await Deno . remove ( join ( parsedProps . backups . pathname ! , name ) ) ;
277+ return await Deno . remove ( join ( getModulePath ( backupsPathname ) ! , name ) ) ;
281278 } ;
282279
283280 const visualize = async ( ) => {
0 commit comments