96dc79cfe6
- Convert all require()/module.exports to import/export across 260+ files - Add "type": "module" to package.json to enable ESM by default - Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible - Convert eslint.config.js to ESM with sourceType: "module" - Replace __dirname/__filename with import.meta.dirname/import.meta.filename - Replace require.main === module with process.argv[1] === import.meta.filename - Remove 'use strict' directives (implicit in ESM) - Convert dynamic require() in switch statements to static import lookup maps (dns.js, domains.js, backupformats.js, backupsites.js, network.js) - Extract self-referencing exports.CONSTANT patterns into standalone const declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.) - Lazify SERVICES object in services.js to avoid circular dependency TDZ issues - Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests - Add _setMockApp() to ldapserver.js for ESM-safe test mocking - Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests - Convert backupupload.js to use dynamic imports so --check exits before loading the module graph (which requires BOX_ENV) - Update check-install to use ESM import for infra_version.js - Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations) - All 1315 tests passing Migration stats (AI-assisted using Cursor with Claude): - Wall clock time: ~3-4 hours - Assistant completions: ~80-100 - Estimated token usage: ~1-2M tokens Co-authored-by: Cursor <cursoragent@cursor.com>
169 lines
5.2 KiB
JavaScript
169 lines
5.2 KiB
JavaScript
import assert from 'node:assert';
|
|
import BoxError from '../boxerror.js';
|
|
|
|
// -------------------------------------------
|
|
// This file just describes the interface
|
|
//
|
|
// New backends can start from here
|
|
// -------------------------------------------
|
|
|
|
// Implementation note:
|
|
// retry logic for upload() comes from the syncer since it is stream based
|
|
// for the other API calls we leave it to the backend to retry. this allows
|
|
// them to tune the concurrency based on failures/rate limits accordingly
|
|
export {
|
|
getAvailableSize,
|
|
getStatus,
|
|
|
|
upload,
|
|
|
|
exists,
|
|
|
|
download,
|
|
copy,
|
|
copyDir,
|
|
|
|
listDir,
|
|
|
|
remove,
|
|
removeDir,
|
|
|
|
setup,
|
|
teardown,
|
|
cleanup,
|
|
|
|
verifyConfig,
|
|
removePrivateFields,
|
|
injectPrivateFields
|
|
};
|
|
|
|
function removePrivateFields(config) {
|
|
// in-place removal of tokens and api keys
|
|
return config;
|
|
}
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
function injectPrivateFields(newConfig, currentConfig) {
|
|
// in-place injection of tokens and api keys
|
|
}
|
|
|
|
async function getAvailableSize(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
return Number.POSITIVE_INFINITY;
|
|
}
|
|
|
|
async function getStatus(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
// Result: { state, message } . state is 'active' or 'inactive'
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'getStatus is not implemented');
|
|
}
|
|
|
|
async function upload(config, limits, backupFilePath) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof limits, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
|
|
// Result: { createStream(), finish() callback }
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'upload is not implemented');
|
|
}
|
|
|
|
async function exists(config, backupFilePath) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
|
|
// Result: boolean if exists or not
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'exists is not implemented');
|
|
}
|
|
|
|
async function download(config, backupFilePath) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof backupFilePath, 'string');
|
|
|
|
// Result: download stream
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'download is not implemented');
|
|
}
|
|
|
|
async function copy(config, oldFilePath, newFilePath, progressCallback) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof oldFilePath, 'string');
|
|
assert.strictEqual(typeof newFilePath, 'string');
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'copy is not implemented');
|
|
}
|
|
|
|
async function copyDir(config, limits, oldFilePath, newFilePath, progressCallback) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof limits, 'object');
|
|
assert.strictEqual(typeof oldFilePath, 'string');
|
|
assert.strictEqual(typeof newFilePath, 'string');
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'copy is not implemented');
|
|
}
|
|
|
|
async function listDir(config, dir, batchSize, marker) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof dir, 'string');
|
|
assert.strictEqual(typeof batchSize, 'number');
|
|
assert(typeof marker !== 'undefined');
|
|
|
|
// Result: array of { path, size }
|
|
// path is relative to the prefix/root and not the _dir_ being listed
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'listDir is not implemented');
|
|
}
|
|
|
|
async function remove(config, filename) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof filename, 'string');
|
|
|
|
// Result: none
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'remove is not implemented');
|
|
}
|
|
|
|
async function removeDir(config, limits, pathPrefix, progressCallback) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof limits, 'object');
|
|
assert.strictEqual(typeof pathPrefix, 'string');
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
|
|
|
// Result: none
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'removeDir is not implemented');
|
|
}
|
|
|
|
async function cleanup(config, progressCallback) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
assert.strictEqual(typeof progressCallback, 'function');
|
|
|
|
// Result: none
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'cleanup is not implemented');
|
|
}
|
|
|
|
async function verifyConfig({ id, provider, config }) {
|
|
assert.strictEqual(typeof id, 'string');
|
|
assert.strictEqual(typeof provider, 'string');
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'testConfig is not implemented');
|
|
}
|
|
|
|
async function setup(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'setup is not implemented');
|
|
}
|
|
|
|
async function teardown(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
// Result: none - first callback argument error if config does not pass the test
|
|
|
|
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'teardown is not implemented');
|
|
}
|