mobiletto 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -137,16 +137,18 @@ This code would run the same if the driver were `local`.
137
137
  await s3.writeFile(path, bufferOrString) // returns count of bytes written
138
138
 
139
139
  // Delete a file
140
- // Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
140
+ // Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
141
+ // Always returns a value or throws an error.
142
+ // Return value may be a single string of the file removed, or an array of all files removed (driver-dependent)
141
143
  const quiet = true
142
- local.remove(path, {quiet}) // returns true upon success
143
- s3.remove(path, {quiet}) // returns true upon success
144
+ local.remove(path, {quiet}) // returns single path removed
145
+ s3.remove(path, {quiet}) // returns single path removed
144
146
 
145
147
  // Recursively delete a directory and do it quietly (do not report errors)
146
148
  const recursive = true
147
149
  const quiet = true
148
- local.remove(path, {recursive, quiet})
149
- s3.remove(path, {recursive, quiet})
150
+ local.remove(path, {recursive, quiet}) // returns paths removed
151
+ s3.remove(path, {recursive, quiet}) // returns array containing all paths removed
150
152
 
151
153
  ## Metadata
152
154
  The `metadata` command returns metadata about a single filesystem entry.
@@ -288,4 +290,5 @@ The object that the storageClient function returns must define these functions:
288
290
  async write (path, generatorOrReadableStream)
289
291
 
290
292
  // Remove a file, or recursively delete a directory
293
+ // returns a string of a single path removed, or an array of multiple paths removed
291
294
  async remove (path, recursive = false, quiet = false)
@@ -253,7 +253,7 @@ class StorageClient {
253
253
  throw new MobilettoError(`remove(${path}) error: ${err}`, err)
254
254
  }
255
255
  }
256
- return Promise.resolve(true)
256
+ return path
257
257
  }
258
258
  }
259
259
 
@@ -137,6 +137,11 @@ class StorageClient {
137
137
  : this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path))
138
138
  return p.replaceAll(/\/{2,}/g, '/')
139
139
  }
140
+ denormalizeKey = (key) => {
141
+ return key.startsWith(this.prefix)
142
+ ? key.substring(this.prefix.length)
143
+ : key
144
+ }
140
145
 
141
146
  s3error (err, key, path, method) {
142
147
  return (err instanceof MobilettoError || err instanceof MobilettoNotFoundError)
@@ -217,6 +222,7 @@ class StorageClient {
217
222
 
218
223
  async remove (path, recursive, quiet) {
219
224
  if (recursive) {
225
+ const removed = []
220
226
  let objects = await this._list(path, true, null, { MaxKeys: DELETE_OBJECTS_MAX_KEYS })
221
227
  while (objects && objects.length > 0) {
222
228
  const Delete = {
@@ -240,6 +246,9 @@ class StorageClient {
240
246
  if (!quiet && response.Errors && response.Errors.length > 0) {
241
247
  throw new MobilettoError(`remove(${path}): DeleteObjectsCommand returned Errors: ${JSON.stringify(response.Errors)}`)
242
248
  }
249
+ if (response.Deleted) {
250
+ removed.push(...response.Deleted.map(del => this.denormalizeKey(del.Key)))
251
+ }
243
252
  try {
244
253
  objects = await this._list(path, true, null, {MaxKeys: DELETE_OBJECTS_MAX_KEYS})
245
254
  } catch (e) {
@@ -249,6 +258,7 @@ class StorageClient {
249
258
  objects = null
250
259
  }
251
260
  }
261
+ return removed
252
262
  } else {
253
263
  const Key = this.normalizeKey(path)
254
264
  const bucketParams = {
@@ -272,8 +282,8 @@ class StorageClient {
272
282
  } catch (err) {
273
283
  throw this.s3error(err, Key, path, 'remove')
274
284
  }
285
+ return path
275
286
  }
276
- return true
277
287
  }
278
288
  }
279
289
 
package/index.js CHANGED
@@ -405,6 +405,7 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
405
405
  await client.write(metaPath(path), stringGenerator(JSON.stringify(meta), enc)())
406
406
  return bytesRead
407
407
  },
408
+ // todo: remove should return an array of the paths that were actually removed
408
409
  remove: async (path, options) => {
409
410
  const recursive = options === true || (options && options.recursive) || false
410
411
  const quiet = (options && options.quiet) || false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A storage abstraction layer",
5
5
  "main": "index.js",
6
6
  "author": "Jonathan Cobb",
@@ -155,7 +155,7 @@ for (const driverName of DRIVER_NAMES) {
155
155
  })
156
156
  it("should delete the file we just wrote", async () => {
157
157
  const removed = await fixture.api.remove(fixture.name)
158
- expect(removed).to.be.true
158
+ expect(!!removed).to.be.true
159
159
  })
160
160
  it("loading metadata on the file we wrote now fails", async () => {
161
161
  await assertMetaFail(fixture.api, fixture.name)
@@ -205,7 +205,7 @@ for (const driverName of DRIVER_NAMES) {
205
205
  })
206
206
  it("should fail to delete the file we did not write", async () => {
207
207
  const removed = await fixture.api.remove(fixture.name)
208
- expect(removed).to.be.false
208
+ expect(!!removed).to.be.false
209
209
  })
210
210
  })
211
211
  }
@@ -238,7 +238,7 @@ for (const driverName of DRIVER_NAMES) {
238
238
  })
239
239
  it("should delete the encrypted file we just wrote", async () => {
240
240
  const removed = await fixture.api.remove(fixture.name)
241
- expect(removed).to.be.true
241
+ expect(!!removed).to.be.true
242
242
  })
243
243
  it("loading metadata on the encrypted file we wrote now fails", async () => {
244
244
  await assertMetaFail(fixture.api, fixture.name)
@@ -327,12 +327,12 @@ for (const driverName of DRIVER_NAMES) {
327
327
  it("should recursively delete the mirrored data", async () => {
328
328
  const recursive = true
329
329
  const removed = await fixture.mirrorApi.remove(mirrorDest, {recursive})
330
- expect(removed).to.be.true
330
+ expect(!!removed).to.be.true
331
331
  })
332
332
  it("should recursively delete the directory and file we just created", async () => {
333
333
  const recursive = true
334
334
  const removed = await fixture.api.remove(randomParent, {recursive})
335
- expect(removed).to.be.true
335
+ expect(!!removed).to.be.true
336
336
  })
337
337
  it("loading metadata on the file we wrote now fails", async () => {
338
338
  await assertMetaFail(fixture.api, fixture.name)