mobiletto 1.0.21 → 1.0.24
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/index.js +14 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -66,7 +66,8 @@ const UTILITY_FUNCTIONS = {
|
|
|
66
66
|
cacheKey = shasum(path + ' ' + (opts ? JSON.stringify(opts) : '~'))
|
|
67
67
|
const results = client.listingCache.get(cacheKey)
|
|
68
68
|
if (results) {
|
|
69
|
-
return results
|
|
69
|
+
if (Array.isArray(results)) { return results }
|
|
70
|
+
throw results
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
const recursive = opts && opts.recursive ? opts.recursive : false
|
|
@@ -74,11 +75,18 @@ const UTILITY_FUNCTIONS = {
|
|
|
74
75
|
if (visitor && typeof visitor !== 'function') {
|
|
75
76
|
throw new MobilettoError(`list: visitor is not a function: ${typeof visitor}`)
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
client.listingCache
|
|
78
|
+
try {
|
|
79
|
+
const results = await client.driver_list(path, recursive, visitor)
|
|
80
|
+
if (client.listingCache) {
|
|
81
|
+
client.listingCache.set(cacheKey, results)
|
|
82
|
+
}
|
|
83
|
+
return results
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (client.listingCache && e instanceof MobilettoNotFoundError) {
|
|
86
|
+
client.listingCache.set(cacheKey, e)
|
|
87
|
+
}
|
|
88
|
+
throw e
|
|
80
89
|
}
|
|
81
|
-
return results
|
|
82
90
|
},
|
|
83
91
|
safeList: (client) => async (path, opts) => {
|
|
84
92
|
const recursive = opts && opts.recursive ? opts.recursive : false
|
|
@@ -203,7 +211,7 @@ async function mirrorDir (source, sourcePath, visitor) {
|
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
function addUtilityFunctions (client, readOnly = false, cacheSize = null) {
|
|
206
|
-
client.listingCache = cacheSize ? new LRU({ max: cacheSize }) : null
|
|
214
|
+
client.listingCache = cacheSize && cacheSize > 0 ? new LRU({ max: cacheSize }) : null
|
|
207
215
|
for (const func of Object.keys(UTILITY_FUNCTIONS)) {
|
|
208
216
|
client[`driver_${func}`] = client[func] // save previous function, we will need `list` at least
|
|
209
217
|
client[func] = UTILITY_FUNCTIONS[func](client)
|