mobiletto 1.1.5 → 1.1.8
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 +2 -2
- package/drivers/b2/index.js +11 -7
- package/drivers/s3/index.js +4 -2
- package/index.js +8 -4
- package/package.json +1 -1
- package/test/api.spec.js +6 -3
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ Mobiletto was designed to solve this problem. By coding your app to mobiletto's
|
|
|
32
32
|
change storage providers and know that your app's storage layer will behave identically.
|
|
33
33
|
|
|
34
34
|
### Extensive testing
|
|
35
|
-
All drivers are tested for identical behavior with
|
|
36
|
-
Each
|
|
35
|
+
All drivers are tested for identical behavior with 60+ tests for each driver.
|
|
36
|
+
Each test actually runs *four times* with every (2x2) combination of:
|
|
37
37
|
* Encryption: both enabled and disabled
|
|
38
38
|
* Redis cache: both enabled and disabled
|
|
39
39
|
|
package/drivers/b2/index.js
CHANGED
|
@@ -26,6 +26,7 @@ class StorageClient {
|
|
|
26
26
|
absoluteMinimumPartSize
|
|
27
27
|
recommendedPartSize
|
|
28
28
|
configuredPartSize
|
|
29
|
+
normalizeRegex
|
|
29
30
|
constructor(keyId, appKey, opts) {
|
|
30
31
|
if (!keyId || !appKey || !opts.bucket) throw new MobilettoError(`b2.StorageClient: key, secret and opts.bucket are required`)
|
|
31
32
|
this.b2 = new B2({
|
|
@@ -36,6 +37,7 @@ class StorageClient {
|
|
|
36
37
|
this.configuredPartSize = opts.partSize ? opts.partSize : -1
|
|
37
38
|
this.bucket = opts.bucket
|
|
38
39
|
this.delimiter = opts.delimiter || '/'
|
|
40
|
+
this.normalizeRegex = new RegExp(`${this.delimiter}{2,}`, 'g')
|
|
39
41
|
this.prefix = opts.prefix
|
|
40
42
|
? opts.prefix.endsWith(this.delimiter)
|
|
41
43
|
? opts.prefix
|
|
@@ -67,10 +69,12 @@ class StorageClient {
|
|
|
67
69
|
|
|
68
70
|
testConfig = async () => await this.b2_list('', false, null, {max: 1})
|
|
69
71
|
|
|
70
|
-
normalizePath = (path) =>
|
|
71
|
-
path.startsWith(this.prefix)
|
|
72
|
+
normalizePath = (path) => {
|
|
73
|
+
const p = (path.startsWith(this.prefix)
|
|
72
74
|
? path
|
|
73
|
-
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path)
|
|
75
|
+
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path))
|
|
76
|
+
return p.replaceAll(this.normalizeRegex, this.delimiter)
|
|
77
|
+
}
|
|
74
78
|
denormalizePath = (path) => {
|
|
75
79
|
const norm = path.startsWith(this.prefix) ? path.substring(this.prefix.length) : path
|
|
76
80
|
return norm.startsWith(this.delimiter) ? norm.substring(1) : norm
|
|
@@ -91,7 +95,7 @@ class StorageClient {
|
|
|
91
95
|
name: this.denormalizePath(f.fileName),
|
|
92
96
|
size: f.contentLength,
|
|
93
97
|
type: this.b2type(f),
|
|
94
|
-
|
|
98
|
+
b2id: f.fileId
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -135,7 +139,7 @@ class StorageClient {
|
|
|
135
139
|
const list = await this.processList(pth, response, visitor)
|
|
136
140
|
if (!optsDir && !firstResult && list.length > 0) {
|
|
137
141
|
firstResult = list[0]
|
|
138
|
-
if (list[0].name.endsWith(
|
|
142
|
+
if (list[0].name.endsWith(this.delimiter)) {
|
|
139
143
|
dirDiscovered = true
|
|
140
144
|
} else if (!dirDiscovered && list.length > 1 && list[1].name.startsWith(list[0].name)) {
|
|
141
145
|
files.push(list[0])
|
|
@@ -266,7 +270,7 @@ class StorageClient {
|
|
|
266
270
|
try {
|
|
267
271
|
const stream = await this.b2.downloadFileById({
|
|
268
272
|
bucketId: this.bucket,
|
|
269
|
-
fileId: meta.
|
|
273
|
+
fileId: meta.b2id,
|
|
270
274
|
responseType: 'stream'
|
|
271
275
|
})
|
|
272
276
|
return await readStream(stream.data, callback, endCallback)
|
|
@@ -344,7 +348,7 @@ class StorageClient {
|
|
|
344
348
|
const response = await this.b2.listFileVersions({
|
|
345
349
|
bucketId: this.bucket,
|
|
346
350
|
startFileName: normPath,
|
|
347
|
-
startFileId: meta.
|
|
351
|
+
startFileId: meta.b2id,
|
|
348
352
|
prefix: this.prefix,
|
|
349
353
|
delimiter: this.delimiter,
|
|
350
354
|
maxFileCount: 1000
|
package/drivers/s3/index.js
CHANGED
|
@@ -28,12 +28,14 @@ class StorageClient {
|
|
|
28
28
|
bucket
|
|
29
29
|
prefix
|
|
30
30
|
delimiter
|
|
31
|
+
normalizeRegex
|
|
31
32
|
constructor(key, secret, opts) {
|
|
32
33
|
if (!key || !secret || !opts || !opts.bucket) {
|
|
33
34
|
throw new MobilettoError('s3.StorageClient: key, secret, and opts.bucket are required')
|
|
34
35
|
}
|
|
35
36
|
this.bucket = opts.bucket
|
|
36
37
|
const delim = this.delimiter = opts.delimiter || DEFAULT_DELIMITER
|
|
38
|
+
this.normalizeRegex = new RegExp(`${this.delimiter}{2,}`, 'g')
|
|
37
39
|
this.prefix = opts.prefix || DEFAULT_PREFIX
|
|
38
40
|
? opts.prefix.endsWith(delim)
|
|
39
41
|
? opts.prefix
|
|
@@ -64,7 +66,7 @@ class StorageClient {
|
|
|
64
66
|
try {
|
|
65
67
|
return await this._list(path, recursive, visitor)
|
|
66
68
|
} catch (e) {
|
|
67
|
-
if (e instanceof MobilettoNotFoundError && !recursive && path.includes(
|
|
69
|
+
if (e instanceof MobilettoNotFoundError && !recursive && path.includes(this.delimiter)) {
|
|
68
70
|
// are we trying to list a single file?
|
|
69
71
|
const objects = await this._list(dirname(path), false)
|
|
70
72
|
const found = objects.find(o => o.name === path)
|
|
@@ -151,7 +153,7 @@ class StorageClient {
|
|
|
151
153
|
const p = (path.startsWith(this.prefix)
|
|
152
154
|
? path
|
|
153
155
|
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path))
|
|
154
|
-
return p.replaceAll(
|
|
156
|
+
return p.replaceAll(this.normalizeRegex, this.delimiter)
|
|
155
157
|
}
|
|
156
158
|
denormalizeKey = (key) => {
|
|
157
159
|
return key.startsWith(this.prefix)
|
package/index.js
CHANGED
|
@@ -37,8 +37,8 @@ function MobilettoError (message, err) {
|
|
|
37
37
|
// noinspection JSUnusedGlobalSymbols
|
|
38
38
|
this.stack = (new Error(this.message)).stack
|
|
39
39
|
}
|
|
40
|
+
MobilettoError.prototype.toString = () => JSON.stringify(this)
|
|
40
41
|
}
|
|
41
|
-
MobilettoError.prototype.toString = () => JSON.stringify(this)
|
|
42
42
|
|
|
43
43
|
// adapted from https://stackoverflow.com/a/27724419
|
|
44
44
|
function MobilettoNotFoundError (message) {
|
|
@@ -50,8 +50,8 @@ function MobilettoNotFoundError (message) {
|
|
|
50
50
|
// noinspection JSUnusedGlobalSymbols
|
|
51
51
|
this.stack = (new Error(this.message)).stack
|
|
52
52
|
}
|
|
53
|
+
MobilettoNotFoundError.prototype.toString = () => JSON.stringify(this)
|
|
53
54
|
}
|
|
54
|
-
MobilettoNotFoundError.prototype.toString = () => JSON.stringify(this)
|
|
55
55
|
|
|
56
56
|
const reader = (chunks) => (chunk) => { if (chunk) { chunks.push(chunk) } }
|
|
57
57
|
|
|
@@ -209,10 +209,14 @@ const UTILITY_FUNCTIONS = {
|
|
|
209
209
|
},
|
|
210
210
|
write: (client) => async (path, data) => {
|
|
211
211
|
logger.debug(`util.write(${path}) starting ...`)
|
|
212
|
+
const p = path.startsWith(this.delimiter) ? path.substring(1) : path
|
|
213
|
+
if (p !== path) {
|
|
214
|
+
logger.debug(`util.write(${path}) removed leading ${this.delimiter}`)
|
|
215
|
+
}
|
|
212
216
|
// noinspection JSUnresolvedFunction
|
|
213
|
-
const bytesWritten = await client.driver_write(
|
|
217
|
+
const bytesWritten = await client.driver_write(p, data)
|
|
214
218
|
await client.flush()
|
|
215
|
-
logger.debug(`util.write(${
|
|
219
|
+
logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`)
|
|
216
220
|
return bytesWritten
|
|
217
221
|
},
|
|
218
222
|
writeFile: (client) => async (path, data) => {
|
package/package.json
CHANGED
package/test/api.spec.js
CHANGED
|
@@ -119,14 +119,17 @@ const REDIS_DISABLED = {
|
|
|
119
119
|
return newConfig
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
|
|
122
123
|
const redisTests = () => [REDIS_ENABLED, REDIS_DISABLED]
|
|
124
|
+
// const redisTests = () => [REDIS_ENABLED]
|
|
125
|
+
// const redisTests = () => [REDIS_DISABLED]
|
|
123
126
|
|
|
124
127
|
for (const redisSetup of redisTests()) {
|
|
125
128
|
if (!redisSetup.enabled) continue
|
|
126
129
|
|
|
127
130
|
for (const driverName of DRIVER_NAMES) {
|
|
128
131
|
// For testing single drivers
|
|
129
|
-
if (driverName !== 'b2') continue
|
|
132
|
+
// if (driverName !== 'b2') continue
|
|
130
133
|
|
|
131
134
|
const driverTest = `${driverName} [${redisSetup.name}]`
|
|
132
135
|
const config = redisSetup.config(DRIVER_CONFIG[driverName])
|
|
@@ -284,8 +287,8 @@ for (const driverName of DRIVER_NAMES) {
|
|
|
284
287
|
|
|
285
288
|
for (const encryption of encryptionTests()) {
|
|
286
289
|
const encDesc = encryption ? '(with encryption)' : '(without encryption)'
|
|
287
|
-
|
|
288
|
-
const mirrorDriver = 'local' // for hard-coding the mirror driver
|
|
290
|
+
const mirrorDriver = pickAnotherDriver(driverName)
|
|
291
|
+
// const mirrorDriver = 'local' // for hard-coding the mirror driver
|
|
289
292
|
const mirrorConfig = DRIVER_CONFIG[mirrorDriver]
|
|
290
293
|
const mirrorDest = `mirrorDest_${rand(5)}/`
|
|
291
294
|
describe(`${driverTest} - ${encDesc} write files in a new dir, read metadata, mirror to another place (${mirrorDriver}), verify mirror, recursively delete from both`, () => {
|