Socket
Socket
Sign inDemoInstall

carp-streamer

Package Overview
Dependencies
153
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.1 to 0.9.2

dist/box.js

227

dist/app.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
};
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -35,44 +67,59 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
async synchronize(source, destination = '0', excludes = [], pretend = false) {
const callback = (error, result = { status: SyncResultStatus.UNKNOWN }) => {
this.emit(SyncEventType.SYNCHRONIZE, error, result.absolutePath, result.status);
};
const finder = await box_finder_1.default.create(this.client, destination, this.cacheConfig);
const stats = await statAsync(source);
if (!stats.isDirectory()) {
const { dir, base } = path_1.default.parse(source);
const entry = { path: source, dirent: createDirentFromStats(stats, base) };
this.emit(SyncEventType.ENTER, source);
this.q.push({ entry, rootPath: dir, finder, pretend, excludes }, callback);
this.emit(SyncEventType.ENTERED, 1);
synchronize(source, destination = '0', excludes = [], pretend = false) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const callback = (error, result = { status: SyncResultStatus.UNKNOWN }) => {
this.emit(SyncEventType.SYNCHRONIZE, error, result.absolutePath, result.status);
};
const finder = yield box_finder_1.default.create(this.client, destination, this.cacheConfig);
const stats = yield statAsync(source);
if (!stats.isDirectory()) {
const { dir, base } = path_1.default.parse(source);
const entry = { path: source, dirent: createDirentFromStats(stats, base) };
this.emit(SyncEventType.ENTER, source);
this.q.push({ entry, rootPath: dir, finder, pretend, excludes }, callback);
this.emit(SyncEventType.ENTERED, 1);
return this.q.drain();
}
let count = 0;
try {
for (var _b = __asyncValues(listDirectoryEntriesRecursively(source)), _c; _c = yield _b.next(), !_c.done;) {
const entry = _c.value;
this.emit(SyncEventType.ENTER, entry.path);
this.q.push({ entry, rootPath: source, finder, pretend, excludes }, callback);
count++;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
this.emit(SyncEventType.ENTERED, count);
return this.q.drain();
}
let count = 0;
for await (const entry of listDirectoryEntriesRecursively(source)) {
this.emit(SyncEventType.ENTER, entry.path);
this.q.push({ entry, rootPath: source, finder, pretend, excludes }, callback);
count++;
}
this.emit(SyncEventType.ENTERED, count);
return this.q.drain();
});
}
}
exports.Synchronizer = Synchronizer;
async function worker(task, done) {
const { entry: { path: absolutePath, dirent, error }, rootPath, finder, pretend, excludes } = task;
const relativePath = path_1.default.relative(rootPath, absolutePath);
if (error) {
return done(error, { status: SyncResultStatus.DENIED, absolutePath });
}
if (excludes.some(exclude => absolutePath.startsWith(exclude))) {
return done(null, { status: SyncResultStatus.EXCLUDED, absolutePath });
}
try {
const entry = Entry.create(rootPath, relativePath, finder, dirent);
const status = await entry.synchronize(pretend);
done(null, { status, absolutePath });
}
catch (error) {
done(error, { status: SyncResultStatus.FAILURE, absolutePath });
}
function worker(task, done) {
return __awaiter(this, void 0, void 0, function* () {
const { entry: { path: absolutePath, dirent, error }, rootPath, finder, pretend, excludes } = task;
const relativePath = path_1.default.relative(rootPath, absolutePath);
if (error) {
return done(error, { status: SyncResultStatus.DENIED, absolutePath });
}
if (excludes.some(exclude => absolutePath.startsWith(exclude))) {
return done(null, { status: SyncResultStatus.EXCLUDED, absolutePath });
}
try {
const entry = Entry.create(rootPath, relativePath, finder, dirent);
const status = yield entry.synchronize(pretend);
done(null, { status, absolutePath });
}
catch (error) {
done(error, { status: SyncResultStatus.FAILURE, absolutePath });
}
});
}

@@ -114,49 +161,53 @@ var SyncResultStatus;

class Directory extends Entry {
async synchronize(pretend = false) {
const remoteFolder = await this.finder.findFolderByPath(this.relativePath);
if (remoteFolder) {
return SyncResultStatus.SYNCHRONIZED;
}
else {
if (!pretend) {
await this.finder.createFolderUnlessItExists(this.relativePath);
synchronize(pretend = false) {
return __awaiter(this, void 0, void 0, function* () {
const remoteFolder = yield this.finder.findFolderByPath(this.relativePath);
if (remoteFolder) {
return SyncResultStatus.SYNCHRONIZED;
}
return SyncResultStatus.CREATED;
}
else {
if (!pretend) {
yield this.finder.createFolderUnlessItExists(this.relativePath);
}
return SyncResultStatus.CREATED;
}
});
}
}
class File extends Entry {
async synchronize(pretend = false) {
const stats = await statAsync(this.absolutePath);
const remoteFile = await this.finder.findFileByPath(this.relativePath);
if (!remoteFile) {
if (!pretend) {
const { dir, base } = path_1.default.parse(this.relativePath);
const folder = await this.finder.createFolderUnlessItExists(dir);
debug('Uploading `%s`...', this.relativePath);
await new Promise((resolve, reject) => {
const stream = this.createReadStream();
stream.once('error', reject);
this.finder.uploadFile(base, stream, stats, folder).then(resolve).catch(reject);
});
}
return SyncResultStatus.UPLOADED;
}
else {
const sha1 = await this.digest();
if (sha1 === remoteFile.sha1) {
return SyncResultStatus.SYNCHRONIZED;
}
else {
synchronize(pretend = false) {
return __awaiter(this, void 0, void 0, function* () {
const stats = yield statAsync(this.absolutePath);
const remoteFile = yield this.finder.findFileByPath(this.relativePath);
if (!remoteFile) {
if (!pretend) {
debug('Upgrading `%s`...', this.relativePath);
await new Promise((resolve, reject) => {
const { dir, base } = path_1.default.parse(this.relativePath);
const folder = yield this.finder.createFolderUnlessItExists(dir);
debug('Uploading `%s`...', this.relativePath);
yield new Promise((resolve, reject) => {
const stream = this.createReadStream();
stream.once('error', reject);
this.finder.uploadNewFileVersion(remoteFile, stream, stats).then(resolve).catch(reject);
this.finder.uploadFile(base, stream, stats, folder).then(resolve).catch(reject);
});
}
return SyncResultStatus.UPGRADED;
return SyncResultStatus.UPLOADED;
}
}
else {
const sha1 = yield this.digest();
if (sha1 === remoteFile.sha1) {
return SyncResultStatus.SYNCHRONIZED;
}
else {
if (!pretend) {
debug('Upgrading `%s`...', this.relativePath);
yield new Promise((resolve, reject) => {
const stream = this.createReadStream();
stream.once('error', reject);
this.finder.uploadNewFileVersion(remoteFile, stream, stats).then(resolve).catch(reject);
});
}
return SyncResultStatus.UPGRADED;
}
}
});
}

@@ -188,17 +239,19 @@ digest() {

}
async function* listDirectoryEntriesRecursively(root) {
try {
for (const dirent of await readdirAsync(root, { withFileTypes: true })) {
const entryPath = path_1.default.join(root, dirent.name);
yield ({ path: entryPath, dirent });
if (dirent.isDirectory()) {
yield* listDirectoryEntriesRecursively(entryPath);
function listDirectoryEntriesRecursively(root) {
return __asyncGenerator(this, arguments, function* listDirectoryEntriesRecursively_1() {
try {
for (const dirent of yield __await(readdirAsync(root, { withFileTypes: true }))) {
const entryPath = path_1.default.join(root, dirent.name);
yield yield __await(({ path: entryPath, dirent }));
if (dirent.isDirectory()) {
yield __await(yield* __asyncDelegator(__asyncValues(listDirectoryEntriesRecursively(entryPath))));
}
}
}
}
catch (error) {
debug('Oops! %s', error.message);
yield { path: root, error };
}
catch (error) {
debug('Oops! %s', error.message);
yield yield __await({ path: root, error });
}
});
}
//# sourceMappingURL=app.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
};
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -36,14 +68,16 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
static async create(client, folderId = '0', cacheConfig = { max: 100000000 }) {
const folders = proxyToTrapTooManyRequests(client.folders);
const current = await folders.get(folderId);
const cacheOptions = {
length: object_sizeof_1.default,
max: cacheConfig.max,
maxAge: cacheConfig.maxAge,
updateAgeOnGet: true
};
const cache = new lru_cache_1.default(cacheOptions);
const disableCachedResponsesValidation = Boolean(cacheConfig.disableCachedResponsesValidation);
return BoxFinder.new(client, current, cache, disableCachedResponsesValidation);
static create(client, folderId = '0', cacheConfig = { max: 100000000 }) {
return __awaiter(this, void 0, void 0, function* () {
const folders = proxyToTrapTooManyRequests(client.folders);
const current = yield folders.get(folderId);
const cacheOptions = {
length: object_sizeof_1.default,
max: cacheConfig.max,
maxAge: cacheConfig.maxAge,
updateAgeOnGet: true
};
const cache = new lru_cache_1.default(cacheOptions);
const disableCachedResponsesValidation = Boolean(cacheConfig.disableCachedResponsesValidation);
return BoxFinder.new(client, current, cache, disableCachedResponsesValidation);
});
}

@@ -53,32 +87,40 @@ static new(client, folder, cache, disableCachedResponsesValidation) {

}
static async createFolderByPath(folderPath, finder) {
if (folderPath.length === 0) {
return isFolder(finder.current) ? finder.current : await finder.folders.get(finder.current.id);
}
const folderName = lodash_1.default.first(folderPath) || '';
const subFolder = await finder.findFolderByName(folderName);
const folder = subFolder || await finder.createFolder(folderName);
return this.createFolderByPath(folderPath.slice(1), finder.new(folder));
static createFolderByPath(folderPath, finder) {
return __awaiter(this, void 0, void 0, function* () {
if (folderPath.length === 0) {
return isFolder(finder.current) ? finder.current : yield finder.folders.get(finder.current.id);
}
const folderName = lodash_1.default.first(folderPath) || '';
const subFolder = yield finder.findFolderByName(folderName);
const folder = subFolder || (yield finder.createFolder(folderName));
return this.createFolderByPath(folderPath.slice(1), finder.new(folder));
});
}
static async findFolderByPath(folderPath, finder) {
if (finder === undefined) {
return undefined;
}
if (folderPath.length === 0) {
return isFolder(finder.current) ? finder.current : await finder.folders.get(finder.current.id);
}
const folderName = lodash_1.default.first(folderPath) || '';
const subFolder = await finder.findFolderByName(folderName);
return BoxFinder.findFolderByPath(folderPath.slice(1), subFolder && finder.new(subFolder));
static findFolderByPath(folderPath, finder) {
return __awaiter(this, void 0, void 0, function* () {
if (finder === undefined) {
return undefined;
}
if (folderPath.length === 0) {
return isFolder(finder.current) ? finder.current : yield finder.folders.get(finder.current.id);
}
const folderName = lodash_1.default.first(folderPath) || '';
const subFolder = yield finder.findFolderByName(folderName);
return BoxFinder.findFolderByPath(folderPath.slice(1), subFolder && finder.new(subFolder));
});
}
async createFolderUnlessItExists(relativePath) {
const dirs = !relativePath ? [] : relativePath.split(path_1.default.sep);
const foundFolder = await BoxFinder.findFolderByPath(dirs, this);
return foundFolder || BoxFinder.createFolderByPath(dirs, this);
createFolderUnlessItExists(relativePath) {
return __awaiter(this, void 0, void 0, function* () {
const dirs = !relativePath ? [] : relativePath.split(path_1.default.sep);
const foundFolder = yield BoxFinder.findFolderByPath(dirs, this);
return foundFolder || BoxFinder.createFolderByPath(dirs, this);
});
}
async findFileByPath(relativePath) {
const { dir, base } = path_1.default.parse(relativePath);
const dirs = dir === '' ? [] : dir.split(path_1.default.sep);
const folder = await BoxFinder.findFolderByPath(dirs, this);
return folder && this.findFileByName(base, folder);
findFileByPath(relativePath) {
return __awaiter(this, void 0, void 0, function* () {
const { dir, base } = path_1.default.parse(relativePath);
const dirs = dir === '' ? [] : dir.split(path_1.default.sep);
const folder = yield BoxFinder.findFolderByPath(dirs, this);
return folder && this.findFileByName(base, folder);
});
}

@@ -90,64 +132,80 @@ findFolderByPath(relativePath) {

}
async uploadFile(name, content, stats, folder) {
const folderId = (folder || this.current).id;
const options = {
content_created_at: stats && toRFC3339String(stats.ctime),
content_modified_at: stats && toRFC3339String(stats.mtime),
};
try {
const result = await this.files.preflightUploadFile(folderId, { name, size: stats && stats.size });
debug('preflight Upload File: %o', result);
}
catch (error) {
debug('preflight error: %s', error.message);
if (!isResponseError(error) || error.statusCode !== 409) {
throw error;
uploadFile(name, content, stats, folder) {
return __awaiter(this, void 0, void 0, function* () {
const folderId = (folder || this.current).id;
const options = {
content_created_at: stats && toRFC3339String(stats.birthtime),
content_modified_at: stats && toRFC3339String(stats.mtime),
};
try {
const result = yield this.files.preflightUploadFile(folderId, { name, size: stats && stats.size });
debug('preflight Upload File: %o', result);
}
const item = findConflictItem(error);
if (item && isMiniFile(item)) {
debug('Found existing folder with that name: %s', item.name);
const finder = (folder ? this.new(folder) : this);
return finder.uploadNewFileVersion(item, content, stats);
catch (error) {
debug('preflight error: %s', error.message);
if (!isResponseError(error) || error.statusCode !== 409) {
throw error;
}
const item = findConflictItem(error);
if (item && isMiniFile(item)) {
debug('Found existing folder with that name: %s', item.name);
const finder = (folder ? this.new(folder) : this);
return finder.uploadNewFileVersion(item, content, stats);
}
else {
throw error;
}
}
debug('uploading %s...', name);
if (stats && (stats.size >= CHUNKED_UPLOAD_MINIMUM)) {
const chunkedUploader = yield this.files.getChunkedUploader(folderId, stats.size, name, content, { fileAttributes: options });
chunkedUploader
.on('error', error => {
debug('Uploading with ChunkedUploader failed. %o', error.error);
})
.on('chunkError', error => {
debug('Failed to upload chunk. %o', error);
})
.on('chunkUploaded', (data) => {
debug('chunk uploaded: %s', data.part.size);
})
.on('uploadComplete', (uploadFile) => {
debug('upload complete: %s', uploadFile.name);
});
return chunkedUploader.start().then(cacheItems(this.cache));
}
else {
throw error;
return this.files.uploadFile(folderId, name, content, options).then(cacheItems(this.cache));
}
}
debug('uploading %s...', name);
if (stats && (stats.size >= CHUNKED_UPLOAD_MINIMUM)) {
const chunkedUploader = await this.files.getChunkedUploader(folderId, stats.size, name, content, { fileAttributes: options });
chunkedUploader
.on('chunkUploaded', (data) => {
debug('chunk uploaded: %s', data.part.size);
})
.on('uploadComplete', (uploadFile) => {
debug('upload complete: %s', uploadFile.name);
});
return chunkedUploader.start().then(cacheItems(this.cache));
}
else {
return this.files.uploadFile(folderId, name, content, options).then(cacheItems(this.cache));
}
});
}
async uploadNewFileVersion(file, content, stats) {
const options = {
content_modified_at: stats && toRFC3339String(stats.mtime),
};
const fileData = { name: file.name, size: stats && stats.size };
const result = await this.files.preflightUploadNewFileVersion(file.id, fileData);
debug('preflight Upload New File Version: %o', result);
if (stats && (stats.size >= CHUNKED_UPLOAD_MINIMUM)) {
const chunkedUploader = await this.files.getNewVersionChunkedUploader(file.id, stats.size, content, { fileAttributes: options });
chunkedUploader
.on('chunkUploaded', (data) => {
debug('chunk uploaded: %s', data.part.size);
})
.on('uploadComplete', (uploadFile) => {
debug('upload complete: %s', uploadFile.name);
});
return chunkedUploader.start().then(cacheItems(this.cache));
}
else {
return this.files.uploadNewFileVersion(file.id, content, options).then(cacheItems(this.cache));
}
uploadNewFileVersion(file, content, stats) {
return __awaiter(this, void 0, void 0, function* () {
const options = {
content_modified_at: stats && toRFC3339String(stats.mtime),
};
const fileData = { name: file.name, size: stats && stats.size };
const result = yield this.files.preflightUploadNewFileVersion(file.id, fileData);
debug('preflight Upload New File Version: %o', result);
if (stats && (stats.size >= CHUNKED_UPLOAD_MINIMUM)) {
const chunkedUploader = yield this.files.getNewVersionChunkedUploader(file.id, stats.size, content, { fileAttributes: options });
chunkedUploader
.on('error', error => {
debug('Uploading with ChunkedUploader failed. %o', error.error);
})
.on('chunkError', error => {
debug('Failed to upload chunk. %o', error);
})
.on('chunkUploaded', (data) => {
debug('chunk uploaded: %s', data.part.size);
})
.on('uploadComplete', (uploadFile) => {
debug('upload complete: %s', uploadFile.name);
});
return chunkedUploader.start().then(cacheItems(this.cache));
}
else {
return this.files.uploadNewFileVersion(file.id, content, options).then(cacheItems(this.cache));
}
});
}

@@ -168,52 +226,69 @@ new(folder, cache = this.cache, disableCachedResponsesValidation = this.disableCachedResponsesValidation) {

}
async findItemByName(itemName, isItem, parentFolder = this.current) {
const filter = (item) => item.name.normalize() === itemName.normalize();
const cachedItem = lodash_1.default.first((this.cache.get(parentFolder.id) || []).filter(isItem).filter(filter));
if (cachedItem) {
debug('%s has hit the cache.', cachedItem.name);
return this.disableCachedResponsesValidation
? cachedItem
: this.fetchItemWithCondition(cachedItem).then(item => item && isItem(item) ? item : undefined);
}
else {
debug('%s was not found in the cache.', itemName);
}
for await (const item of this.fetchFolderItems(parentFolder)) {
if (isItem(item) && filter(item)) {
return item;
findItemByName(itemName, isItem, parentFolder = this.current) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const filter = (item) => item.name.normalize() === itemName.normalize();
const cachedItem = lodash_1.default.first((this.cache.get(parentFolder.id) || []).filter(isItem).filter(filter));
if (cachedItem) {
debug('%s has hit the cache.', cachedItem.name);
return this.disableCachedResponsesValidation
? cachedItem
: this.fetchItemWithCondition(cachedItem).then(item => item && isItem(item) ? item : undefined);
}
}
else {
debug('%s was not found in the cache.', itemName);
}
try {
for (var _b = __asyncValues(this.fetchFolderItems(parentFolder)), _c; _c = yield _b.next(), !_c.done;) {
const item = _c.value;
if (isItem(item) && filter(item)) {
return item;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
});
}
async *fetchFolderItems(parentFolder = this.current, marker) {
const parentFolderId = parentFolder.id;
const items = await this.folders.getItems(parentFolderId, { usemarker: true, marker });
const cachedItems = marker ? this.cache.get(parentFolderId) || [] : [];
this.cache.set(parentFolderId, cachedItems.concat(items.entries));
yield* items.entries;
if (items.next_marker) {
yield* this.fetchFolderItems(parentFolder, items.next_marker);
}
fetchFolderItems(parentFolder = this.current, marker) {
return __asyncGenerator(this, arguments, function* fetchFolderItems_1() {
const parentFolderId = parentFolder.id;
const items = yield __await(this.folders.getItems(parentFolderId, { usemarker: true, marker }));
const cachedItems = marker ? this.cache.get(parentFolderId) || [] : [];
this.cache.set(parentFolderId, cachedItems.concat(items.entries));
yield __await(yield* __asyncDelegator(__asyncValues(items.entries)));
if (items.next_marker) {
yield __await(yield* __asyncDelegator(__asyncValues(this.fetchFolderItems(parentFolder, items.next_marker))));
}
});
}
async fetchItemWithCondition(item, options) {
debug('condition get %s %s (etag: %s)', item.type, item.id, item.etag);
const basePath = url_1.default.resolve(isMiniFolder(item) ? '/folders/' : '/files/', item.id);
const params = {
headers: { 'IF-NONE-MATCH': item.etag },
qs: options,
};
return this.client.wrapWithDefaultHandler(this.client.get)(basePath, params)
.then(cacheItem(this.cache))
.catch(error => {
if (!isResponseError(error)) {
throw error;
}
debug('API Response Error: %s', error.message);
switch (error.statusCode) {
case 304:
return item;
case 404:
return undefined;
default:
fetchItemWithCondition(item, options) {
return __awaiter(this, void 0, void 0, function* () {
debug('condition get %s %s (etag: %s)', item.type, item.id, item.etag);
const basePath = url_1.default.resolve(isMiniFolder(item) ? '/folders/' : '/files/', item.id);
const params = {
headers: { 'IF-NONE-MATCH': item.etag },
qs: options,
};
return this.client.wrapWithDefaultHandler(this.client.get)(basePath, params)
.then(cacheItem(this.cache))
.catch(error => {
if (!isResponseError(error)) {
throw error;
}
}
debug('API Response Error: %s', error.message);
switch (error.statusCode) {
case 304:
return item;
case 404:
return undefined;
default:
throw error;
}
});
});

@@ -235,6 +310,6 @@ }

function makeRetriable(method, that, callback, retryTimes = config_1.INIT_RETRY_TIMES, delay = 0) {
return async (...args) => {
await util_2.sleep(delay);
return (...args) => __awaiter(this, void 0, void 0, function* () {
yield util_2.sleep(delay);
try {
return await Reflect.apply(method, that, args);
return yield Reflect.apply(method, that, args);
}

@@ -247,3 +322,3 @@ catch (error) {

}
};
});
}

@@ -264,3 +339,3 @@ function determineDelayTime(retryTimes, error) {

};
const retryIfFolderConflictError = async (error, method, that, args, retryTimes) => {
const retryIfFolderConflictError = (error, method, that, args, retryTimes) => __awaiter(this, void 0, void 0, function* () {
const [parentFolderId, folderName] = args;

@@ -283,3 +358,3 @@ debug(`Failed to create folder '%s' (parent folder id: %s).`, folderName, parentFolderId);

}
};
});
function proxyToTrapTooManyRequests(target) {

@@ -286,0 +361,0 @@ return new Proxy(target, {

#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -57,3 +72,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}).start('synchronizing...');
(async () => {
(() => __awaiter(this, void 0, void 0, function* () {
var e_1, _a;
try {

@@ -70,46 +86,57 @@ progressBar.total = 0;

.on(app_1.SyncEventType.ENTER, absolutePath => {
debug('found %s', absolutePath);
progressBar.total = progressBar.total + 1;
})
.on(app_1.SyncEventType.ENTERED, count => {
spinner.info(`${count} entries were found.`);
const timestamp = new Date().toISOString();
spinner.info(`${timestamp}\t${count} entries were found.`);
})
.on(app_1.SyncEventType.SYNCHRONIZE, (error, absolutePath, status) => {
const timestamp = new Date().toISOString();
switch (status) {
case app_1.SyncResultStatus.DENIED:
debug('%s: %s\n%s', error.name, error.message, error.stack);
spinner.warn(`Could not access '${absolutePath}'.`);
spinner.warn(`${timestamp}\tCould not access '${absolutePath}'.`);
break;
case app_1.SyncResultStatus.EXCLUDED:
spinner.info(`'${absolutePath}' has been excluded.`);
spinner.info(`${timestamp}\t'${absolutePath}' has been excluded.`);
break;
case app_1.SyncResultStatus.DOWNLOADED:
spinner.succeed(`'${absolutePath}' only exists remotely.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' only exists remotely.`);
break;
case app_1.SyncResultStatus.SYNCHRONIZED:
spinner.succeed(`'${absolutePath}' is synchronized.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is synchronized.`);
break;
case app_1.SyncResultStatus.UPLOADED:
spinner.succeed(`'${absolutePath}' is newly uploaded.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is newly uploaded.`);
break;
case app_1.SyncResultStatus.UPGRADED:
spinner.succeed(`A new version of '${absolutePath}' has been uploaded.`);
spinner.succeed(`${timestamp}\tA new version of '${absolutePath}' has been uploaded.`);
break;
case app_1.SyncResultStatus.CREATED:
spinner.succeed(`'${absolutePath}' is newly created.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is newly created.`);
break;
case app_1.SyncResultStatus.FAILURE:
debug('%s: %s\n%s', error.name, error.message, error.stack);
spinner.fail(`Failed to synchronize '${absolutePath}'. (${error.message})`);
debug('Failed to synchronize \'%s\' %o', absolutePath, error);
spinner.fail(`${timestamp}\tFailed to synchronize '${absolutePath}'.\t(${error.message})`);
break;
case app_1.SyncResultStatus.UNKNOWN:
default:
spinner.fail('unknown result status');
spinner.fail(`${timestamp}\t'${absolutePath}' is unknown result status: ${status}`);
}
progressBar.tick();
});
for await (const source of sources) {
const rootPath = path_1.default.resolve(process.cwd(), source);
await synchronizer.synchronize(rootPath, destination, excludes, pretend);
try {
for (var sources_1 = __asyncValues(sources), sources_1_1; sources_1_1 = yield sources_1.next(), !sources_1_1.done;) {
const source = sources_1_1.value;
const rootPath = path_1.default.resolve(process.cwd(), source);
yield synchronizer.synchronize(rootPath, destination, excludes, pretend);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (sources_1_1 && !sources_1_1.done && (_a = sources_1.return)) yield _a.call(sources_1);
}
finally { if (e_1) throw e_1.error; }
}
if (needProgress) {

@@ -131,3 +158,3 @@ console.error('Successful!');

}
})();
}))();
//# sourceMappingURL=index.js.map
{
"name": "carp-streamer",
"version": "0.9.1",
"version": "0.9.2",
"description": "carp-streamer is backup tool for files on local computer using Box Platform API.",

@@ -5,0 +5,0 @@ "bin": "dist/index.js",

@@ -112,3 +112,3 @@ import * as box from 'box-node-sdk';

const options = {
content_created_at: stats && toRFC3339String(stats.ctime),
content_created_at: stats && toRFC3339String(stats.birthtime),
content_modified_at: stats && toRFC3339String(stats.mtime),

@@ -137,2 +137,8 @@ };

chunkedUploader
.on('error', error => {
debug('Uploading with ChunkedUploader failed. %o', error.error);
})
.on('chunkError', error => {
debug('Failed to upload chunk. %o', error);
})
.on('chunkUploaded', (data: UploadPart) => {

@@ -161,2 +167,8 @@ debug('chunk uploaded: %s', data.part.size);

chunkedUploader
.on('error', error => {
debug('Uploading with ChunkedUploader failed. %o', error.error);
})
.on('chunkError', error => {
debug('Failed to upload chunk. %o', error);
})
.on('chunkUploaded', (data: UploadPart) => {

@@ -163,0 +175,0 @@ debug('chunk uploaded: %s', data.part.size);

@@ -74,39 +74,40 @@ #!/usr/bin/env node

.on(SyncEventType.ENTER, absolutePath => {
debug('found %s', absolutePath);
progressBar.total = progressBar.total + 1;
})
.on(SyncEventType.ENTERED, count => {
spinner.info(`${count} entries were found.`);
const timestamp = new Date().toISOString();
spinner.info(`${timestamp}\t${count} entries were found.`);
})
.on(SyncEventType.SYNCHRONIZE, (error, absolutePath, status: SyncResultStatus) => {
const timestamp = new Date().toISOString();
switch (status) {
case SyncResultStatus.DENIED:
debug('%s: %s\n%s', error.name, error.message, error.stack);
spinner.warn(`Could not access '${absolutePath}'.`);
spinner.warn(`${timestamp}\tCould not access '${absolutePath}'.`);
break;
case SyncResultStatus.EXCLUDED:
spinner.info(`'${absolutePath}' has been excluded.`);
spinner.info(`${timestamp}\t'${absolutePath}' has been excluded.`);
break;
case SyncResultStatus.DOWNLOADED:
spinner.succeed(`'${absolutePath}' only exists remotely.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' only exists remotely.`);
break;
case SyncResultStatus.SYNCHRONIZED:
spinner.succeed(`'${absolutePath}' is synchronized.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is synchronized.`);
break;
case SyncResultStatus.UPLOADED:
spinner.succeed(`'${absolutePath}' is newly uploaded.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is newly uploaded.`);
break;
case SyncResultStatus.UPGRADED:
spinner.succeed(`A new version of '${absolutePath}' has been uploaded.`);
spinner.succeed(`${timestamp}\tA new version of '${absolutePath}' has been uploaded.`);
break;
case SyncResultStatus.CREATED:
spinner.succeed(`'${absolutePath}' is newly created.`);
spinner.succeed(`${timestamp}\t'${absolutePath}' is newly created.`);
break;
case SyncResultStatus.FAILURE:
debug('%s: %s\n%s', error.name, error.message, error.stack);
spinner.fail(`Failed to synchronize '${absolutePath}'. (${error.message})`);
debug('Failed to synchronize \'%s\' %o', absolutePath, error);
spinner.fail(`${timestamp}\tFailed to synchronize '${absolutePath}'.\t(${error.message})`);
break;
case SyncResultStatus.UNKNOWN:
default:
spinner.fail('unknown result status');
spinner.fail(`${timestamp}\t'${absolutePath}' is unknown result status: ${status}`);
}

@@ -113,0 +114,0 @@ progressBar.tick();

{
"compilerOptions": {
/* Basic Options */
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"target": "es2016", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */

@@ -6,0 +6,0 @@ // "lib": [], /* Specify library files to be included in the compilation. */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc