Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 54c7cbb

Browse files
committed
Renaming progressCb parameter to onProgress
1 parent 7aa59d8 commit 54c7cbb

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ This will create empty migration with next version in line.
204204

205205
## API
206206

207-
### `migrate(path, {toVersion, ignoreLock, repoOptions, progressCb, isDryRun}) -> Promise<void>`
207+
### `migrate(path, {toVersion, ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`
208208

209209
Executes forward migration to specific version or if not specified to the latest version.
210210

@@ -215,10 +215,10 @@ Executes forward migration to specific version or if not specified to the latest
215215
* `options.toVersion` (int, optional) - version to which the repo should be migrated to. If left out the version of latest migration is used.
216216
* `options.ignoreLock` (bool, optional) - if true won't lock the repo for applying the migrations. Use with caution.
217217
* `options.repoOptions` (object, optional) - options that are passed to migrations, that use them to correctly construct datastore. Options are same like for IPFSRepo.
218-
* `options.progressCb` (function, optional) - callback that is called after finishing execution of each migration to report progress.
218+
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
219219
* `options.isDryRun` (bool, optional) - flag that indicates if it is a dry run that should imitate running migration without actually any change.
220220

221-
#### `progressCb(migration, counter, totalMigrations)`
221+
#### `onProgress(migration, counter, totalMigrations)`
222222

223223
Signature of the progress callback.
224224

@@ -227,7 +227,7 @@ Signature of the progress callback.
227227
* `counter` (int) - current number of migration in the planned migrations streak.
228228
* `totalMigrations` (int) - total count of migrations that are planned to be run.
229229

230-
### `revert(path, toVersion, {ignoreLock, options, progressCb, isDryRun}) -> Promise<void>`
230+
### `revert(path, toVersion, {ignoreLock, options, onProgress, isDryRun}) -> Promise<void>`
231231

232232
Executes backward migration to specific version.
233233

@@ -238,7 +238,7 @@ Executes backward migration to specific version.
238238
* `options` (object, optional) - options for the reversion
239239
* `options.ignoreLock` (bool, optional) - if true won't lock the repo for applying the migrations. Use with caution.
240240
* `options.options` (object, optional) - options that are passed to migrations, that use them to correctly construct datastore. Options are same like for IPFSRepo.
241-
* `options.progressCb` (function, optional) - callback that is called after finishing execution of each migration to report progress.
241+
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
242242
* `options.isDryRun` (bool, optional) - flag that indicates if it is a dry run that should imitate running migration without actually any change.
243243

244244
### `getLatestMigrationVersion() -> int`

src/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function migrate ({ repoPath, to, dry, revertOk }) {
3434
const options = {
3535
toVersion: to,
3636
ignoreLock: false,
37-
progressCb: reportingClosure(dry ? 'loaded migration' : 'migrated to version'),
37+
onProgress: reportingClosure(dry ? 'loaded migration' : 'migrated to version'),
3838
isDryRun: dry
3939
}
4040

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ exports.getLatestMigrationVersion = getLatestMigrationVersion
4141
* @param {int?} options.toVersion - Version to which the repo should be migrated, if undefined repo will be migrated to the latest version.
4242
* @param {boolean?} options.ignoreLock - Won't lock the repo for applying the migrations. Use with caution.
4343
* @param {object?} options.repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
44-
* @param {function?} options.progressCb - Callback which will be called after each executed migration to report progress
44+
* @param {function?} options.onProgress - Callback which will be called after each executed migration to report progress
4545
* @param {boolean?} options.isDryRun - Allows to simulate the execution of the migrations without any effect.
4646
* @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose.
4747
* @returns {Promise<void>}
4848
*/
49-
async function migrate (path, {toVersion, ignoreLock=false, repoOptions, progressCb, isDryRun=false, migrations}) {
49+
async function migrate (path, {toVersion, ignoreLock=false, repoOptions, onProgress, isDryRun=false, migrations}) {
5050
migrations = migrations || defaultMigrations
5151

5252
if (!path) {
@@ -96,7 +96,7 @@ async function migrate (path, {toVersion, ignoreLock=false, repoOptions, progres
9696
e.message = `During migration to version ${migration.version} exception was raised: ${e.message}`
9797
throw e
9898
}
99-
typeof progressCb === 'function' && progressCb(migration, counter, totalMigrations) // Reports on migration process
99+
typeof onProgress === 'function' && onProgress(migration, counter, totalMigrations) // Reports on migration process
100100
log(`Migrating to version ${migration.version} finished`)
101101
}
102102

@@ -118,14 +118,14 @@ exports.migrate = migrate
118118
* @param {string} path - Path to initialized (!) JS-IPFS repo
119119
* @param {int} toVersion - Version to which the repo will be reverted.
120120
* @param {Object} options - Options for the reversion
121-
* @param {function?} options.progressCb - Callback which will be called after each reverted migration to report progress
121+
* @param {function?} options.onProgress - Callback which will be called after each reverted migration to report progress
122122
* @param {object?} options.repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
123-
* @param {boolean?} options.isDryRun - Allows to simulate the execution of the reversion without any effects. Make sense to utilize progressCb with this argument.
123+
* @param {boolean?} options.isDryRun - Allows to simulate the execution of the reversion without any effects. Make sense to utilize onProgress with this argument.
124124
* @param {boolean?} options.ignoreLock - Won't lock the repo for reverting the migrations. Use with caution.
125125
* @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose.
126126
* @returns {Promise<void>}
127127
*/
128-
async function revert (path, toVersion, {ignoreLock=false, repoOptions, progressCb, isDryRun=false, migrations}) {
128+
async function revert (path, toVersion, {ignoreLock=false, repoOptions, onProgress, isDryRun=false, migrations}) {
129129
migrations = migrations || defaultMigrations
130130

131131
if (!path) {
@@ -185,7 +185,7 @@ async function revert (path, toVersion, {ignoreLock=false, repoOptions, progress
185185
e.message = `During reversion to version ${migration.version} exception was raised: ${e.message}`
186186
throw e
187187
}
188-
typeof progressCb === 'function' && progressCb(migration, counter, totalMigrations) // Reports on migration process
188+
typeof onProgress === 'function' && onProgress(migration, counter, totalMigrations) // Reports on migration process
189189
log(`Reverting to version ${migration.version} finished`)
190190
}
191191

test/index.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ describe('index.js', () => {
239239

240240
it('should report progress when progress callback is supplied', async () => {
241241
const options = createOptions()
242-
options.progressCb = sinon.stub()
242+
options.onProgress = sinon.stub()
243243
getVersionStub.returns(4)
244244

245245
await expect(migrator.revert('/some/path', 2, options))
246246
.to.eventually.be.fulfilled()
247247

248-
expect(options.progressCb.getCall(0).calledWith(sinon.match.any, 1, 2)).to.be.true()
249-
expect(options.progressCb.getCall(1).calledWith(sinon.match.any, 2, 2)).to.be.true()
248+
expect(options.onProgress.getCall(0).calledWith(sinon.match.any, 1, 2)).to.be.true()
249+
expect(options.onProgress.getCall(1).calledWith(sinon.match.any, 2, 2)).to.be.true()
250250
})
251251

252252
it('should unlock repo when error is thrown', async () => {
@@ -364,14 +364,14 @@ describe('index.js', () => {
364364

365365
it('should report progress when progress callback is supplied', async () => {
366366
const options = createOptions(4)
367-
options.progressCb = sinon.stub()
367+
options.onProgress = sinon.stub()
368368
getVersionStub.returns(2)
369369

370370
await expect(migrator.migrate('/some/path', options))
371371
.to.eventually.be.fulfilled()
372372

373-
expect(options.progressCb.getCall(0).calledWith(sinon.match.any, 1, 2)).to.be.true()
374-
expect(options.progressCb.getCall(1).calledWith(sinon.match.any, 2, 2)).to.be.true()
373+
expect(options.onProgress.getCall(0).calledWith(sinon.match.any, 1, 2)).to.be.true()
374+
expect(options.onProgress.getCall(1).calledWith(sinon.match.any, 2, 2)).to.be.true()
375375
})
376376

377377
it('should unlock repo when error is thrown', async () => {

0 commit comments

Comments
 (0)