Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit ede8bca

Browse files
fix: deps
1 parent 9186be9 commit ede8bca

File tree

5 files changed

+298
-328
lines changed

5 files changed

+298
-328
lines changed

src/adapter/file/localFile.persistence.plugin.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
transformToNDJson,
1010
writablePushToArray,
1111
_pipeline,
12-
_ensureDir,
13-
_pathExists,
12+
fs2,
1413
} from '@naturalcycles/nodejs-lib'
1514
import { DBSaveBatchOperation } from '../../db.model'
1615
import { FileDBPersistencePlugin } from './file.db.model'
@@ -50,11 +49,11 @@ export class LocalFilePersistencePlugin implements FileDBPersistencePlugin {
5049
}
5150

5251
async loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]> {
53-
await _ensureDir(this.cfg.storagePath)
52+
await fs2.ensureDirAsync(this.cfg.storagePath)
5453
const ext = `ndjson${this.cfg.gzip ? '.gz' : ''}`
5554
const filePath = `${this.cfg.storagePath}/${table}.${ext}`
5655

57-
if (!(await _pathExists(filePath))) return []
56+
if (!(await fs2.pathExistsAsync(filePath))) return []
5857

5958
const transformUnzip = this.cfg.gzip ? [createUnzip()] : []
6059

@@ -76,7 +75,7 @@ export class LocalFilePersistencePlugin implements FileDBPersistencePlugin {
7675
}
7776

7877
async saveFile<ROW extends ObjectWithId>(table: string, rows: ROW[]): Promise<void> {
79-
await _ensureDir(this.cfg.storagePath)
78+
await fs2.ensureDirAsync(this.cfg.storagePath)
8079
const ext = `ndjson${this.cfg.gzip ? '.gz' : ''}`
8180
const filePath = `${this.cfg.storagePath}/${table}.${ext}`
8281
const transformZip = this.cfg.gzip ? [createGzip()] : []

src/adapter/inmemory/inMemory.db.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import {
2525
transformToNDJson,
2626
writablePushToArray,
2727
_pipeline,
28-
_emptyDir,
29-
_ensureDir,
3028
dimGrey,
3129
yellow,
30+
fs2,
3231
} from '@naturalcycles/nodejs-lib'
3332
import { CommonDB, DBIncrement, DBPatch, DBTransaction, queryInMemory } from '../..'
3433
import {
@@ -283,7 +282,7 @@ export class InMemoryDB implements CommonDB {
283282

284283
const started = Date.now()
285284

286-
await _emptyDir(persistentStoragePath)
285+
await fs2.emptyDirAsync(persistentStoragePath)
287286

288287
const transformZip = persistZip ? [createGzip()] : []
289288
let tables = 0
@@ -318,7 +317,7 @@ export class InMemoryDB implements CommonDB {
318317

319318
const started = Date.now()
320319

321-
await _ensureDir(persistentStoragePath)
320+
await fs2.ensureDirAsync(persistentStoragePath)
322321

323322
this.data = {} // empty it in the beginning!
324323

src/pipeline/dbPipelineBackup.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ import {
2020
transformTap,
2121
transformToNDJson,
2222
_pipeline,
23-
_ensureDirSync,
24-
_pathExistsSync,
25-
_ensureFileSync,
26-
_writeJson,
2723
boldWhite,
2824
dimWhite,
2925
grey,
3026
yellow,
27+
fs2,
3128
} from '@naturalcycles/nodejs-lib'
3229
import { CommonDB } from '../common.db'
3330
import { DBQuery } from '../index'
@@ -180,7 +177,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
180177

181178
console.log(`>> ${dimWhite('dbPipelineBackup')} started in ${grey(outputDirPath)}...`)
182179

183-
_ensureDirSync(outputDirPath)
180+
fs2.ensureDir(outputDirPath)
184181

185182
tables ||= await db.getTables()
186183

@@ -213,20 +210,20 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
213210
const filePath = `${outputDirPath}/${table}.ndjson` + (gzip ? '.gz' : '')
214211
const schemaFilePath = `${outputDirPath}/${table}.schema.json`
215212

216-
if (protectFromOverwrite && _pathExistsSync(filePath)) {
213+
if (protectFromOverwrite && fs2.pathExists(filePath)) {
217214
throw new AppError(`dbPipelineBackup: output file exists: ${filePath}`)
218215
}
219216

220217
const started = Date.now()
221218
let rows = 0
222219

223-
_ensureFileSync(filePath)
220+
fs2.ensureFile(filePath)
224221

225222
// console.log(`>> ${grey(filePath)} started...`)
226223

227224
if (emitSchemaFromDB) {
228225
const schema = await db.getTableSchema(table)
229-
await _writeJson(schemaFilePath, schema, { spaces: 2 })
226+
await fs2.writeJsonAsync(schemaFilePath, schema, { spaces: 2 })
230227
console.log(`>> ${grey(schemaFilePath)} saved (generated from DB)`)
231228
}
232229

src/pipeline/dbPipelineRestore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ import {
2525
transformTap,
2626
writableForEach,
2727
_pipeline,
28-
_ensureDirSync,
29-
_readJson,
3028
boldWhite,
3129
dimWhite,
3230
grey,
3331
yellow,
32+
fs2,
3433
} from '@naturalcycles/nodejs-lib'
3534
import { CommonDB } from '../common.db'
3635
import { CommonDBSaveOptions } from '../index'
@@ -145,7 +144,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
145144
`>> ${dimWhite('dbPipelineRestore')} started in ${grey(inputDirPath)}...${sinceUpdatedStr}`,
146145
)
147146

148-
_ensureDirSync(inputDirPath)
147+
fs2.ensureDir(inputDirPath)
149148

150149
const tablesToGzip = new Set<string>()
151150
const sizeByTable: Record<string, number> = {}
@@ -185,7 +184,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
185184
return
186185
}
187186

188-
const schema = await _readJson<JsonSchemaObject<any>>(schemaFilePath)
187+
const schema = await fs2.readJsonAsync<JsonSchemaObject<any>>(schemaFilePath)
189188
await db.createTable(table, schema, { dropIfExists: true })
190189
})
191190
}

0 commit comments

Comments
 (0)