Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobiletto-base

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobiletto-base - npm Package Compare versions

Comparing version 2.0.35 to 2.1.0

81

lib/cjs/functions.js

@@ -25,3 +25,4 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
mobiletto_common_1.logger.verbose(`mirrorDir: mirroring dir: ${sourcePath}`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`mirrorDir: mirroring dir: ${sourcePath}`);
const listing = yield source.list(sourcePath, { recursive: false, visitor });

@@ -59,3 +60,4 @@ for (const obj of listing) {

else {
mobiletto_common_1.logger.warn(`list(${path}): unrecognized cached value (${cached})`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`list(${path}): unrecognized cached value (${cached})`);
}

@@ -85,5 +87,7 @@ }

cache.set(path, results).then(() => {
mobiletto_common_1.logger.debug(`list(${path}) cached ${results ? results.length : `unknown? ${JSON.stringify(results)}`} results`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`list(${path}) cached ${results ? results.length : `unknown? ${JSON.stringify(results)}`} results`);
}, (err) => {
mobiletto_common_1.logger.error(`list(${path}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`list(${path}) error: ${err}`);
});

@@ -96,5 +100,7 @@ }

cache.set(path, e).then(() => {
mobiletto_common_1.logger.debug(`list(${path}) cached error ${e}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`list(${path}) cached error ${e}`);
}, (err) => {
mobiletto_common_1.logger.error(`list(${path}) error ${err} caching MobilettoNotFoundError`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`list(${path}) error ${err} caching MobilettoNotFoundError`);
});

@@ -129,5 +135,7 @@ }

cache.set(path, meta).then(() => {
mobiletto_common_1.logger.debug(`metadata(${path}) cached meta = ${JSON.stringify(meta)}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`metadata(${path}) cached meta = ${JSON.stringify(meta)}`);
}, (err) => {
mobiletto_common_1.logger.error(`metadata(${path}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`metadata(${path}) error: ${err}`);
});

@@ -176,3 +184,4 @@ }

catch (e) {
mobiletto_common_1.logger.info(`safeReadFile(${path}) ${e}`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`safeReadFile(${path}) ${e}`);
return Buffer.from("");

@@ -182,6 +191,8 @@ }

write: (client) => (path, data) => __awaiter(void 0, void 0, void 0, function* () {
mobiletto_common_1.logger.debug(`util.write(${path}) starting ...`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`util.write(${path}) starting ...`);
const p = path.startsWith("/") ? path.substring(1) : path;
if (p !== path) {
mobiletto_common_1.logger.debug(`util.write(${path}) removed leading /`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`util.write(${path}) removed leading /`);
}

@@ -191,3 +202,4 @@ // noinspection JSUnresolvedFunction

yield client.flush();
mobiletto_common_1.logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`);
return bytesWritten;

@@ -202,3 +214,4 @@ }),

mirror: (client) => (source, clientPath = "", sourcePath = "") => __awaiter(void 0, void 0, void 0, function* () {
mobiletto_common_1.logger.info(`mirror: starting, sourcePath=${sourcePath} -> clientPath=${clientPath}`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`mirror: starting, sourcePath=${sourcePath} -> clientPath=${clientPath}`);
const results = {

@@ -210,5 +223,7 @@ success: 0,

if (obj.type && obj.type === mobiletto_common_1.M_FILE) {
mobiletto_common_1.logger.verbose(`mirror: mirroring file: ${obj.name}`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`mirror: mirroring file: ${obj.name}`);
const tempPath = `${util_js_1.MOBILETTO_TMP}/mobiletto_${(0, shasum_1.default)(JSON.stringify(obj))}.${(0, mobiletto_common_1.rand)(10)}`;
mobiletto_common_1.logger.debug(`mirror: writing ${obj.name} to temp file ${tempPath} ...`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`mirror: writing ${obj.name} to temp file ${tempPath} ...`);
const destName = obj.name.startsWith(sourcePath) ? obj.name.substring(sourcePath.length) : obj.name;

@@ -233,3 +248,4 @@ const destFullPath = (clientPath.endsWith("/") ? clientPath : clientPath + "/") +

if (destMeta && destMeta.size && destMeta.size && destMeta.size === srcSize) {
mobiletto_common_1.logger.info(`mirror: dest object (${destFullPath}) has same size (${srcSize}) as src object ${sourcePath}, not copying`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`mirror: dest object (${destFullPath}) has same size (${srcSize}) as src object ${sourcePath}, not copying`);
return;

@@ -252,3 +268,4 @@ }

}
mobiletto_common_1.logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`);
});

@@ -260,5 +277,7 @@ })

const reader = fs_1.default.createReadStream(tempPath, { fd });
mobiletto_common_1.logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`);
yield client.write(destFullPath, reader);
mobiletto_common_1.logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`);
results.success++;

@@ -268,3 +287,4 @@ resolve(destFullPath);

.catch((e) => {
mobiletto_common_1.logger.warn(`mirror: error copying file: ${e}`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`mirror: error copying file: ${e}`);
results.errors++;

@@ -276,7 +296,9 @@ reject(e);

catch (e) {
mobiletto_common_1.logger.warn(`mirror: error copying file: ${e}`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`mirror: error copying file: ${e}`);
results.errors++;
}
finally {
mobiletto_common_1.logger.verbose(`mirror: file mirrored successfully: ${obj.name}`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`mirror: file mirrored successfully: ${obj.name}`);
fs_1.default.rmSync(tempPath, { force: true });

@@ -311,3 +333,4 @@ }

if (!enabled) {
mobiletto_common_1.logger.info(`getCache: client.redisConfig.enabled === false, disabling cache`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`getCache: client.redisConfig.enabled === false, disabling cache`);
client.cache = cache_js_1.DISABLED_CACHE;

@@ -320,3 +343,4 @@ return client.cache;

if (!client.id) {
mobiletto_common_1.logger.warn(`getCache: client.id not set; all nameless connections will share one cache`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`getCache: client.id not set; all nameless connections will share one cache`);
client.cache = (0, redis_js_1.getRedis)("~nameless~", host, port, prefix);

@@ -340,3 +364,4 @@ }

if (typeof client[`driver_${func}`] !== "undefined") {
mobiletto_common_1.logger.warn(`utilityFunctionConflict: driver_${func} has already been added`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`utilityFunctionConflict: driver_${func} has already been added`);
return false;

@@ -361,3 +386,4 @@ }

client[writeFunc] = () => __awaiter(void 0, void 0, void 0, function* () {
mobiletto_common_1.logger.warn(`${writeFunc} not supported in readOnly mode`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`${writeFunc} not supported in readOnly mode`);
return false;

@@ -371,3 +397,4 @@ });

const addCacheFunctions = (client) => addClientFunctions(client, CACHE_FUNCTIONS, (client, func) => {
mobiletto_common_1.logger.warn(`addCacheFunctions: ${func} already exists on client${client.id ? `(client.id=${client.id})` : ""}, not re-adding`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`addCacheFunctions: ${func} already exists on client${client.id ? `(client.id=${client.id})` : ""}, not re-adding`);
return false;

@@ -374,0 +401,0 @@ });

@@ -33,3 +33,4 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
mobiletto_common_1.logger.info(`mobiletto: connecting with driver ${driverPath}`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`mobiletto: connecting with driver ${driverPath}`);
let driver;

@@ -62,3 +63,4 @@ if (typeof driverPath === "string") {

const message = `mobiletto(${driverPath}) error initializing driver: ${e}`;
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -72,3 +74,4 @@ }

const message = `mobiletto(${driverPath}) error testing connection: ${e}`;
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -78,3 +81,4 @@ }

const message = `mobiletto(${driverPath}) error: test API call failed`;
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -94,3 +98,4 @@ }

if (!encryption) {
mobiletto_common_1.logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption not enabled)`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption not enabled)`);
return (0, functions_js_1.addUtilityFunctions)((0, functions_js_1.addCacheFunctions)(client), readOnly);

@@ -103,3 +108,4 @@ }

const message = `mobiletto(${driverPath}) invalid encryption key`;
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -110,3 +116,4 @@ }

const message = `mobiletto(${driverPath}) invalid encryption IV`;
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -188,5 +195,7 @@ }

cache.set(path, finalMeta).then(() => {
mobiletto_common_1.logger.debug(`_metadata(${path}) cached meta = ${JSON.stringify(finalMeta)}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`_metadata(${path}) cached meta = ${JSON.stringify(finalMeta)}`);
}, (err) => {
mobiletto_common_1.logger.error(`_metadata(${path}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`_metadata(${path}) error: ${err}`);
});

@@ -206,3 +215,4 @@ }

if (!bytesRead) {
mobiletto_common_1.logger.warn(`${logPrefix} returned no data`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`${logPrefix} returned no data`);
resolve("null");

@@ -223,3 +233,4 @@ }

const message = `${logPrefix} error fetching _metadata: ${err}`;
mobiletto_common_1.logger.warn(message);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(message);
if (job.data.mobilettoJobID &&

@@ -235,3 +246,4 @@ typeof META_ERR_HANDLERS[job.data.mobilettoJobID] === "function") {

const message = `${logPrefix} error reading file: ${err}`;
mobiletto_common_1.logger.warn(message);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(message);
reject(message);

@@ -249,3 +261,4 @@ });

const message = "metaLoadQueue: redis is required but not enabled";
mobiletto_common_1.logger.error(message);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(message);
throw new mobiletto_common_1.MobilettoError(message);

@@ -270,3 +283,4 @@ }

events.on("completed", ({ jobId, returnvalue }) => {
mobiletto_common_1.logger.info(`${jobName} completed job ${jobId} with result: ${returnvalue}`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`${jobName} completed job ${jobId} with result: ${returnvalue}`);
if (META_HANDLERS[jobId]) {

@@ -277,3 +291,4 @@ META_HANDLERS[jobId](JSON.parse(returnvalue));

events.on("failed", ({ jobId, failedReason }) => {
mobiletto_common_1.logger.info(`${jobName} failed job ${jobId} with result: ${failedReason}`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`${jobName} failed job ${jobId} with result: ${failedReason}`);
if (META_ERR_HANDLERS[jobId]) {

@@ -302,3 +317,4 @@ META_ERR_HANDLERS[jobId](failedReason);

META_ERR_HANDLERS[mobilettoJobID] = (failedReason) => {
mobiletto_common_1.logger.error(`_loadMeta(${dirent}): error: ${failedReason}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`_loadMeta(${dirent}): error: ${failedReason}`);
};

@@ -319,7 +335,10 @@ for (const entry of entries) {

const quiet = true;
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing df=${df}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing df=${df}`);
yield client.remove(df, recursive, quiet);
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing encryptPath(path)=${encryptPath(path)}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing encryptPath(path)=${encryptPath(path)}`);
yield client.remove(encryptPath(path), recursive, quiet);
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing metaPath(path)=${metaPath(path)}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`removeDirentFile(${path}) removing metaPath(path)=${metaPath(path)}`);
yield client.remove(metaPath(path), recursive, quiet);

@@ -351,5 +370,7 @@ });

cache.set(cacheKey, thing).then(() => {
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -370,6 +391,8 @@ }

}
mobiletto_common_1.logger.debug(`tryParentDirForSingleFile(${p}) found ${found.name}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`tryParentDirForSingleFile(${p}) found ${found.name}`);
return cacheAndReturn([found]);
}
mobiletto_common_1.logger.debug(`tryParentDirForSingleFile(${p}) nothing found! e=${e}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`tryParentDirForSingleFile(${p}) nothing found! e=${e}`);
throw e ? new mobiletto_common_1.MobilettoNotFoundError(p) : e;

@@ -418,5 +441,7 @@ });

cache.set(cacheKey, entries).then(() => {
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -434,5 +459,7 @@ }

cache.set(cacheKey, entries).then(() => {
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -508,3 +535,4 @@ }

remove: (path, options, quiet) => __awaiter(this, void 0, void 0, function* () {
mobiletto_common_1.logger.debug(`enc.remove(${path}) starting`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`enc.remove(${path}) starting`);
const recursive = options === true || (options && options.recursive) || false;

@@ -524,3 +552,4 @@ quiet || (quiet = (options && typeof options !== "boolean" && options.quiet) || false);

if (quiet) {
mobiletto_common_1.logger.warn(`list(${path}): error listing files for recursive deletion: ${e}`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`list(${path}): error listing files for recursive deletion: ${e}`);
}

@@ -578,3 +607,4 @@ else {

};
mobiletto_common_1.logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption enabled)`);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption enabled)`);
return (0, functions_js_1.addUtilityFunctions)((0, functions_js_1.addCacheFunctions)(encClient), readOnly);

@@ -581,0 +611,0 @@ });

@@ -53,3 +53,4 @@ "use strict";

catch (e) {
mobiletto_common_1.logger.warn(`disconnect: error disconnecting from redis(${this.name}) ${e}`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`disconnect: error disconnecting from redis(${this.name}) ${e}`);
}

@@ -70,3 +71,4 @@ };

catch (e) {
mobiletto_common_1.logger.warn(`redis(${this.name}) doRedisAsync(${func}) ${e} (returning default value: ${defaultValue})`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`redis(${this.name}) doRedisAsync(${func}) ${e} (returning default value: ${defaultValue})`);
return defaultValue;

@@ -80,3 +82,4 @@ }

catch (e) {
mobiletto_common_1.logger.warn(`redis(${this.name}) doRedis(${func}) ${e} (returning default value: ${defaultValue})`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`redis(${this.name}) doRedis(${func}) ${e} (returning default value: ${defaultValue})`);
return defaultValue;

@@ -87,5 +90,7 @@ }

this.counters.get++;
mobiletto_common_1.logger.trace(`redis(${this.name}) get(${key}) starting`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`redis(${this.name}) get(${key}) starting`);
const val = yield this.doRedis((r) => r.get(this.pfx(key)), null);
mobiletto_common_1.logger.trace(`redis(${this.name}) get(${key}) found value: ${val}`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`redis(${this.name}) get(${key}) found value: ${val}`);
if (val) {

@@ -101,3 +106,4 @@ this.counters.hit++;

const message = `${new Date()}: ${this}`;
mobiletto_common_1.logger.info(message);
if (mobiletto_common_1.logger.isInfoEnabled())
mobiletto_common_1.logger.info(message);
}

@@ -108,5 +114,7 @@ return val ? JSON.parse(val) : null;

this.counters.set++;
mobiletto_common_1.logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) starting`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) starting`);
yield this.doRedisAsync((r) => r.set(this.pfx(key), JSON.stringify(val), "EX", expirationMillis / 1000));
mobiletto_common_1.logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) finished`);
if (mobiletto_common_1.logger.isTraceEnabled())
mobiletto_common_1.logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) finished`);
});

@@ -180,3 +188,4 @@ this.del = (key) => __awaiter(this, void 0, void 0, function* () {

catch (e) {
mobiletto_common_1.logger.warn(`redis(${this.name}) set(${key}) error: ${e}`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`redis(${this.name}) set(${key}) error: ${e}`);
}

@@ -201,3 +210,4 @@ }

catch (e) {
mobiletto_common_1.logger.error(`redis(${name}) error connecting to redis, using fallback LRU for scoped caches: ${e}`);
if (mobiletto_common_1.logger.isErrorEnabled())
mobiletto_common_1.logger.error(`redis(${name}) error connecting to redis, using fallback LRU for scoped caches: ${e}`);
this.redis = null;

@@ -207,3 +217,4 @@ }

else {
mobiletto_common_1.logger.warn(`redis(${name}) no host or port provided, using fallback LRU for scoped caches`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`redis(${name}) no host or port provided, using fallback LRU for scoped caches`);
this.redis = null;

@@ -216,6 +227,8 @@ }

.then(() => {
mobiletto_common_1.logger.debug(`redis(${name}) successfully flushed`);
if (mobiletto_common_1.logger.isDebugEnabled())
mobiletto_common_1.logger.debug(`redis(${name}) successfully flushed`);
})
.catch((e) => {
mobiletto_common_1.logger.warn(`redis(${name}) error flushing: ${e}, disabling redis`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`redis(${name}) error flushing: ${e}, disabling redis`);
this.redis = null;

@@ -222,0 +235,0 @@ });

@@ -37,3 +37,4 @@ "use strict";

if (exports.ALL_DRIVERS[name]) {
mobiletto_common_1.logger.warn(`registerDriver(${name}): driver already registered, not re-registering`);
if (mobiletto_common_1.logger.isWarningEnabled())
mobiletto_common_1.logger.warn(`registerDriver(${name}): driver already registered, not re-registering`);
}

@@ -40,0 +41,0 @@ else {

@@ -19,3 +19,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

return __awaiter(this, void 0, void 0, function* () {
logger.verbose(`mirrorDir: mirroring dir: ${sourcePath}`);
if (logger.isTraceEnabled())
logger.trace(`mirrorDir: mirroring dir: ${sourcePath}`);
const listing = yield source.list(sourcePath, { recursive: false, visitor });

@@ -52,3 +53,4 @@ for (const obj of listing) {

else {
logger.warn(`list(${path}): unrecognized cached value (${cached})`);
if (logger.isWarningEnabled())
logger.warn(`list(${path}): unrecognized cached value (${cached})`);
}

@@ -78,5 +80,7 @@ }

cache.set(path, results).then(() => {
logger.debug(`list(${path}) cached ${results ? results.length : `unknown? ${JSON.stringify(results)}`} results`);
if (logger.isDebugEnabled())
logger.debug(`list(${path}) cached ${results ? results.length : `unknown? ${JSON.stringify(results)}`} results`);
}, (err) => {
logger.error(`list(${path}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`list(${path}) error: ${err}`);
});

@@ -89,5 +93,7 @@ }

cache.set(path, e).then(() => {
logger.debug(`list(${path}) cached error ${e}`);
if (logger.isDebugEnabled())
logger.debug(`list(${path}) cached error ${e}`);
}, (err) => {
logger.error(`list(${path}) error ${err} caching MobilettoNotFoundError`);
if (logger.isErrorEnabled())
logger.error(`list(${path}) error ${err} caching MobilettoNotFoundError`);
});

@@ -122,5 +128,7 @@ }

cache.set(path, meta).then(() => {
logger.debug(`metadata(${path}) cached meta = ${JSON.stringify(meta)}`);
if (logger.isDebugEnabled())
logger.debug(`metadata(${path}) cached meta = ${JSON.stringify(meta)}`);
}, (err) => {
logger.error(`metadata(${path}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`metadata(${path}) error: ${err}`);
});

@@ -169,3 +177,4 @@ }

catch (e) {
logger.info(`safeReadFile(${path}) ${e}`);
if (logger.isInfoEnabled())
logger.info(`safeReadFile(${path}) ${e}`);
return Buffer.from("");

@@ -175,6 +184,8 @@ }

write: (client) => (path, data) => __awaiter(void 0, void 0, void 0, function* () {
logger.debug(`util.write(${path}) starting ...`);
if (logger.isDebugEnabled())
logger.debug(`util.write(${path}) starting ...`);
const p = path.startsWith("/") ? path.substring(1) : path;
if (p !== path) {
logger.debug(`util.write(${path}) removed leading /`);
if (logger.isDebugEnabled())
logger.debug(`util.write(${path}) removed leading /`);
}

@@ -184,3 +195,4 @@ // noinspection JSUnresolvedFunction

yield client.flush();
logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`);
if (logger.isDebugEnabled())
logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`);
return bytesWritten;

@@ -195,3 +207,4 @@ }),

mirror: (client) => (source, clientPath = "", sourcePath = "") => __awaiter(void 0, void 0, void 0, function* () {
logger.info(`mirror: starting, sourcePath=${sourcePath} -> clientPath=${clientPath}`);
if (logger.isInfoEnabled())
logger.info(`mirror: starting, sourcePath=${sourcePath} -> clientPath=${clientPath}`);
const results = {

@@ -203,5 +216,7 @@ success: 0,

if (obj.type && obj.type === M_FILE) {
logger.verbose(`mirror: mirroring file: ${obj.name}`);
if (logger.isTraceEnabled())
logger.trace(`mirror: mirroring file: ${obj.name}`);
const tempPath = `${MOBILETTO_TMP}/mobiletto_${shasum(JSON.stringify(obj))}.${rand(10)}`;
logger.debug(`mirror: writing ${obj.name} to temp file ${tempPath} ...`);
if (logger.isDebugEnabled())
logger.debug(`mirror: writing ${obj.name} to temp file ${tempPath} ...`);
const destName = obj.name.startsWith(sourcePath) ? obj.name.substring(sourcePath.length) : obj.name;

@@ -226,3 +241,4 @@ const destFullPath = (clientPath.endsWith("/") ? clientPath : clientPath + "/") +

if (destMeta && destMeta.size && destMeta.size && destMeta.size === srcSize) {
logger.info(`mirror: dest object (${destFullPath}) has same size (${srcSize}) as src object ${sourcePath}, not copying`);
if (logger.isInfoEnabled())
logger.info(`mirror: dest object (${destFullPath}) has same size (${srcSize}) as src object ${sourcePath}, not copying`);
return;

@@ -245,3 +261,4 @@ }

}
logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`);
if (logger.isDebugEnabled())
logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`);
});

@@ -253,5 +270,7 @@ })

const reader = fs.createReadStream(tempPath, { fd });
logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`);
if (logger.isDebugEnabled())
logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`);
yield client.write(destFullPath, reader);
logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`);
if (logger.isDebugEnabled())
logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`);
results.success++;

@@ -261,3 +280,4 @@ resolve(destFullPath);

.catch((e) => {
logger.warn(`mirror: error copying file: ${e}`);
if (logger.isWarningEnabled())
logger.warn(`mirror: error copying file: ${e}`);
results.errors++;

@@ -269,7 +289,9 @@ reject(e);

catch (e) {
logger.warn(`mirror: error copying file: ${e}`);
if (logger.isWarningEnabled())
logger.warn(`mirror: error copying file: ${e}`);
results.errors++;
}
finally {
logger.verbose(`mirror: file mirrored successfully: ${obj.name}`);
if (logger.isTraceEnabled())
logger.trace(`mirror: file mirrored successfully: ${obj.name}`);
fs.rmSync(tempPath, { force: true });

@@ -304,3 +326,4 @@ }

if (!enabled) {
logger.info(`getCache: client.redisConfig.enabled === false, disabling cache`);
if (logger.isInfoEnabled())
logger.info(`getCache: client.redisConfig.enabled === false, disabling cache`);
client.cache = DISABLED_CACHE;

@@ -313,3 +336,4 @@ return client.cache;

if (!client.id) {
logger.warn(`getCache: client.id not set; all nameless connections will share one cache`);
if (logger.isWarningEnabled())
logger.warn(`getCache: client.id not set; all nameless connections will share one cache`);
client.cache = getRedis("~nameless~", host, port, prefix);

@@ -333,3 +357,4 @@ }

if (typeof client[`driver_${func}`] !== "undefined") {
logger.warn(`utilityFunctionConflict: driver_${func} has already been added`);
if (logger.isWarningEnabled())
logger.warn(`utilityFunctionConflict: driver_${func} has already been added`);
return false;

@@ -354,3 +379,4 @@ }

client[writeFunc] = () => __awaiter(void 0, void 0, void 0, function* () {
logger.warn(`${writeFunc} not supported in readOnly mode`);
if (logger.isWarningEnabled())
logger.warn(`${writeFunc} not supported in readOnly mode`);
return false;

@@ -363,3 +389,4 @@ });

export const addCacheFunctions = (client) => addClientFunctions(client, CACHE_FUNCTIONS, (client, func) => {
logger.warn(`addCacheFunctions: ${func} already exists on client${client.id ? `(client.id=${client.id})` : ""}, not re-adding`);
if (logger.isWarningEnabled())
logger.warn(`addCacheFunctions: ${func} already exists on client${client.id ? `(client.id=${client.id})` : ""}, not re-adding`);
return false;

@@ -366,0 +393,0 @@ });

@@ -27,3 +27,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

return __awaiter(this, void 0, void 0, function* () {
logger.info(`mobiletto: connecting with driver ${driverPath}`);
if (logger.isInfoEnabled())
logger.info(`mobiletto: connecting with driver ${driverPath}`);
let driver;

@@ -56,3 +57,4 @@ if (typeof driverPath === "string") {

const message = `mobiletto(${driverPath}) error initializing driver: ${e}`;
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -66,3 +68,4 @@ }

const message = `mobiletto(${driverPath}) error testing connection: ${e}`;
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -72,3 +75,4 @@ }

const message = `mobiletto(${driverPath}) error: test API call failed`;
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -88,3 +92,4 @@ }

if (!encryption) {
logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption not enabled)`);
if (logger.isInfoEnabled())
logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption not enabled)`);
return addUtilityFunctions(addCacheFunctions(client), readOnly);

@@ -97,3 +102,4 @@ }

const message = `mobiletto(${driverPath}) invalid encryption key`;
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -104,3 +110,4 @@ }

const message = `mobiletto(${driverPath}) invalid encryption IV`;
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -182,5 +189,7 @@ }

cache.set(path, finalMeta).then(() => {
logger.debug(`_metadata(${path}) cached meta = ${JSON.stringify(finalMeta)}`);
if (logger.isDebugEnabled())
logger.debug(`_metadata(${path}) cached meta = ${JSON.stringify(finalMeta)}`);
}, (err) => {
logger.error(`_metadata(${path}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`_metadata(${path}) error: ${err}`);
});

@@ -200,3 +209,4 @@ }

if (!bytesRead) {
logger.warn(`${logPrefix} returned no data`);
if (logger.isWarningEnabled())
logger.warn(`${logPrefix} returned no data`);
resolve("null");

@@ -217,3 +227,4 @@ }

const message = `${logPrefix} error fetching _metadata: ${err}`;
logger.warn(message);
if (logger.isWarningEnabled())
logger.warn(message);
if (job.data.mobilettoJobID &&

@@ -229,3 +240,4 @@ typeof META_ERR_HANDLERS[job.data.mobilettoJobID] === "function") {

const message = `${logPrefix} error reading file: ${err}`;
logger.warn(message);
if (logger.isWarningEnabled())
logger.warn(message);
reject(message);

@@ -243,3 +255,4 @@ });

const message = "metaLoadQueue: redis is required but not enabled";
logger.error(message);
if (logger.isErrorEnabled())
logger.error(message);
throw new MobilettoError(message);

@@ -264,3 +277,4 @@ }

events.on("completed", ({ jobId, returnvalue }) => {
logger.info(`${jobName} completed job ${jobId} with result: ${returnvalue}`);
if (logger.isInfoEnabled())
logger.info(`${jobName} completed job ${jobId} with result: ${returnvalue}`);
if (META_HANDLERS[jobId]) {

@@ -271,3 +285,4 @@ META_HANDLERS[jobId](JSON.parse(returnvalue));

events.on("failed", ({ jobId, failedReason }) => {
logger.info(`${jobName} failed job ${jobId} with result: ${failedReason}`);
if (logger.isInfoEnabled())
logger.info(`${jobName} failed job ${jobId} with result: ${failedReason}`);
if (META_ERR_HANDLERS[jobId]) {

@@ -296,3 +311,4 @@ META_ERR_HANDLERS[jobId](failedReason);

META_ERR_HANDLERS[mobilettoJobID] = (failedReason) => {
logger.error(`_loadMeta(${dirent}): error: ${failedReason}`);
if (logger.isErrorEnabled())
logger.error(`_loadMeta(${dirent}): error: ${failedReason}`);
};

@@ -313,7 +329,10 @@ for (const entry of entries) {

const quiet = true;
logger.debug(`removeDirentFile(${path}) removing df=${df}`);
if (logger.isDebugEnabled())
logger.debug(`removeDirentFile(${path}) removing df=${df}`);
yield client.remove(df, recursive, quiet);
logger.debug(`removeDirentFile(${path}) removing encryptPath(path)=${encryptPath(path)}`);
if (logger.isDebugEnabled())
logger.debug(`removeDirentFile(${path}) removing encryptPath(path)=${encryptPath(path)}`);
yield client.remove(encryptPath(path), recursive, quiet);
logger.debug(`removeDirentFile(${path}) removing metaPath(path)=${metaPath(path)}`);
if (logger.isDebugEnabled())
logger.debug(`removeDirentFile(${path}) removing metaPath(path)=${metaPath(path)}`);
yield client.remove(metaPath(path), recursive, quiet);

@@ -345,5 +364,7 @@ });

cache.set(cacheKey, thing).then(() => {
logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (logger.isDebugEnabled())
logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
logger.error(`enc_list(${p}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -364,6 +385,8 @@ }

}
logger.debug(`tryParentDirForSingleFile(${p}) found ${found.name}`);
if (logger.isDebugEnabled())
logger.debug(`tryParentDirForSingleFile(${p}) found ${found.name}`);
return cacheAndReturn([found]);
}
logger.debug(`tryParentDirForSingleFile(${p}) nothing found! e=${e}`);
if (logger.isDebugEnabled())
logger.debug(`tryParentDirForSingleFile(${p}) nothing found! e=${e}`);
throw e ? new MobilettoNotFoundError(p) : e;

@@ -412,5 +435,7 @@ });

cache.set(cacheKey, entries).then(() => {
logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (logger.isDebugEnabled())
logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
logger.error(`enc_list(${p}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -428,5 +453,7 @@ }

cache.set(cacheKey, entries).then(() => {
logger.debug(`enc_list: cached ${p} r=${recursive}`);
if (logger.isDebugEnabled())
logger.debug(`enc_list: cached ${p} r=${recursive}`);
}, (err) => {
logger.error(`enc_list(${p}) error: ${err}`);
if (logger.isErrorEnabled())
logger.error(`enc_list(${p}) error: ${err}`);
});

@@ -502,3 +529,4 @@ }

remove: (path, options, quiet) => __awaiter(this, void 0, void 0, function* () {
logger.debug(`enc.remove(${path}) starting`);
if (logger.isDebugEnabled())
logger.debug(`enc.remove(${path}) starting`);
const recursive = options === true || (options && options.recursive) || false;

@@ -518,3 +546,4 @@ quiet || (quiet = (options && typeof options !== "boolean" && options.quiet) || false);

if (quiet) {
logger.warn(`list(${path}): error listing files for recursive deletion: ${e}`);
if (logger.isWarningEnabled())
logger.warn(`list(${path}): error listing files for recursive deletion: ${e}`);
}

@@ -572,3 +601,4 @@ else {

};
logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption enabled)`);
if (logger.isInfoEnabled())
logger.info(`mobiletto: successfully connected using driver ${driverPath}, returning client (encryption enabled)`);
return addUtilityFunctions(addCacheFunctions(encClient), readOnly);

@@ -575,0 +605,0 @@ });

@@ -46,3 +46,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

catch (e) {
logger.warn(`disconnect: error disconnecting from redis(${this.name}) ${e}`);
if (logger.isWarningEnabled())
logger.warn(`disconnect: error disconnecting from redis(${this.name}) ${e}`);
}

@@ -63,3 +64,4 @@ };

catch (e) {
logger.warn(`redis(${this.name}) doRedisAsync(${func}) ${e} (returning default value: ${defaultValue})`);
if (logger.isWarningEnabled())
logger.warn(`redis(${this.name}) doRedisAsync(${func}) ${e} (returning default value: ${defaultValue})`);
return defaultValue;

@@ -73,3 +75,4 @@ }

catch (e) {
logger.warn(`redis(${this.name}) doRedis(${func}) ${e} (returning default value: ${defaultValue})`);
if (logger.isWarningEnabled())
logger.warn(`redis(${this.name}) doRedis(${func}) ${e} (returning default value: ${defaultValue})`);
return defaultValue;

@@ -80,5 +83,7 @@ }

this.counters.get++;
logger.trace(`redis(${this.name}) get(${key}) starting`);
if (logger.isTraceEnabled())
logger.trace(`redis(${this.name}) get(${key}) starting`);
const val = yield this.doRedis((r) => r.get(this.pfx(key)), null);
logger.trace(`redis(${this.name}) get(${key}) found value: ${val}`);
if (logger.isTraceEnabled())
logger.trace(`redis(${this.name}) get(${key}) found value: ${val}`);
if (val) {

@@ -94,3 +99,4 @@ this.counters.hit++;

const message = `${new Date()}: ${this}`;
logger.info(message);
if (logger.isInfoEnabled())
logger.info(message);
}

@@ -101,5 +107,7 @@ return val ? JSON.parse(val) : null;

this.counters.set++;
logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) starting`);
if (logger.isTraceEnabled())
logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) starting`);
yield this.doRedisAsync((r) => r.set(this.pfx(key), JSON.stringify(val), "EX", expirationMillis / 1000));
logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) finished`);
if (logger.isTraceEnabled())
logger.trace(`redis(${this.name}) set(${key}, ${val}, ${expirationMillis}) finished`);
});

@@ -173,3 +181,4 @@ this.del = (key) => __awaiter(this, void 0, void 0, function* () {

catch (e) {
logger.warn(`redis(${this.name}) set(${key}) error: ${e}`);
if (logger.isWarningEnabled())
logger.warn(`redis(${this.name}) set(${key}) error: ${e}`);
}

@@ -194,3 +203,4 @@ }

catch (e) {
logger.error(`redis(${name}) error connecting to redis, using fallback LRU for scoped caches: ${e}`);
if (logger.isErrorEnabled())
logger.error(`redis(${name}) error connecting to redis, using fallback LRU for scoped caches: ${e}`);
this.redis = null;

@@ -200,3 +210,4 @@ }

else {
logger.warn(`redis(${name}) no host or port provided, using fallback LRU for scoped caches`);
if (logger.isWarningEnabled())
logger.warn(`redis(${name}) no host or port provided, using fallback LRU for scoped caches`);
this.redis = null;

@@ -209,6 +220,8 @@ }

.then(() => {
logger.debug(`redis(${name}) successfully flushed`);
if (logger.isDebugEnabled())
logger.debug(`redis(${name}) successfully flushed`);
})
.catch((e) => {
logger.warn(`redis(${name}) error flushing: ${e}, disabling redis`);
if (logger.isWarningEnabled())
logger.warn(`redis(${name}) error flushing: ${e}, disabling redis`);
this.redis = null;

@@ -215,0 +228,0 @@ });

@@ -33,3 +33,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

if (ALL_DRIVERS[name]) {
logger.warn(`registerDriver(${name}): driver already registered, not re-registering`);
if (logger.isWarningEnabled())
logger.warn(`registerDriver(${name}): driver already registered, not re-registering`);
}

@@ -36,0 +37,0 @@ else {

{
"name": "mobiletto-base",
"version": "2.0.35",
"version": "2.1.0",
"type": "module",

@@ -57,3 +57,3 @@ "description": "A storage layer that presents a uniform interface to Amazon S3, Backblaze B2, local and other storage systems.",

"lru-cache": "^10.0.0",
"mobiletto-common": "^2.1.0",
"mobiletto-common": "^2.1.2",
"node-fetch-commonjs": "^3.3.1",

@@ -60,0 +60,0 @@ "node-redis-scan": "^1.3.6",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc