realm
Version:
Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores
83 lines • 3.26 kB
JavaScript
"use strict";
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
Object.defineProperty(exports, "__esModule", { value: true });
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const file_system_1 = require("../file-system");
const debug_1 = require("../../debug");
const binding_1 = require("../binding");
const debug = (0, debug_1.extendDebug)("fs");
(0, file_system_1.inject)({
isAbsolutePath(path) {
return (0, node_path_1.isAbsolute)(path);
},
joinPaths(...segments) {
return (0, node_path_1.join)(...segments);
},
removeFile(path) {
debug("removeFile", path);
if ((0, node_fs_1.existsSync)(path)) {
(0, node_fs_1.unlinkSync)(path);
}
},
removeDirectory(path) {
debug("removeDirectory", path);
(0, node_fs_1.rmSync)(path, { recursive: true, force: true });
},
ensureDirectoryForFile(path) {
const parentPath = (0, node_path_1.dirname)(path);
(0, node_fs_1.mkdirSync)(parentPath, { recursive: true });
},
setDefaultDirectoryPath(path) {
debug("setDefaultDirectoryPath", path);
return binding_1.binding.JsPlatformHelpers.setDefaultRealmFileDirectory(path);
},
getDefaultDirectoryPath() {
return binding_1.binding.JsPlatformHelpers.defaultRealmFileDirectory();
},
exists(path) {
debug("exists", path);
return (0, node_fs_1.existsSync)(path);
},
copyBundledRealmFiles() {
throw new Error("Realm for Node does not support this method.");
},
/*
readDirectory(path) {
return readdirSync(path, { encoding: "utf8", withFileTypes: true });
},
*/
removeRealmFilesFromDirectory(path) {
debug("removeRealmFilesFromDirectory", path);
for (const dirent of (0, node_fs_1.readdirSync)(path, { encoding: "utf8", withFileTypes: true })) {
const direntPath = (0, node_path_1.join)(path, dirent.name);
if (dirent.isDirectory() && dirent.name.endsWith(".realm.management")) {
(0, node_fs_1.rmSync)(direntPath, { recursive: true, force: true });
}
else if (dirent.name.endsWith(".realm") ||
dirent.name.endsWith(".realm.note") ||
dirent.name.endsWith(".realm.lock") ||
dirent.name.endsWith(".realm.fresh.lock") ||
dirent.name.endsWith(".realm.log")) {
(0, node_fs_1.rmSync)(direntPath, { force: true });
}
}
},
});
//# sourceMappingURL=fs.js.map