From 719142e6f51b1d041cef570568571c94dc4f4e10 Mon Sep 17 00:00:00 2001
From: William Mosquera
Date: Wed, 29 May 2024 15:33:28 -0500
Subject: [PATCH] refactor path.win32 normalitation
---
package-lock.json | 54 +++++++++++++++++++++++++----------------------
src/index.js | 15 +++++++------
2 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 8ad697b..d815dad 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -45,9 +45,9 @@
"optional": true
},
"node_modules/@mongodb-js/saslprep": {
- "version": "1.1.5",
- "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.5.tgz",
- "integrity": "sha512-XLNOMH66KhJzUJNwT/qlMnS4WsNDWD5ASdyaSH3EtK+F4r/CFGa3jT4GNi4mfOitGvWXtdLgQJkQjxSVrio+jA==",
+ "version": "1.1.7",
+ "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.7.tgz",
+ "integrity": "sha512-dCHW/oEX0KJ4NjDULBo3JiOaK5+6axtpBbS+ao2ZInoAL9/YRQLhXzSNAFz7hP4nzLkIqsfYAK/PDE3+XHny0Q==",
"dependencies": {
"sparse-bitfield": "^3.0.3"
}
@@ -91,9 +91,9 @@
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA=="
},
"node_modules/@types/whatwg-url": {
- "version": "11.0.4",
- "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.4.tgz",
- "integrity": "sha512-lXCmTWSHJvf0TRSO58nm978b8HJ/EdsSsEKLd3ODHFjo+3VGAyyTp4v50nWvwtzBxSMQrVOK7tcuN0zGPLICMw==",
+ "version": "11.0.5",
+ "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz",
+ "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==",
"dependencies": {
"@types/webidl-conversions": "*"
}
@@ -159,6 +159,7 @@
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz",
"integrity": "sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==",
+ "deprecated": "This package is no longer supported.",
"optional": true,
"dependencies": {
"delegates": "^1.0.0",
@@ -222,9 +223,9 @@
}
},
"node_modules/bson": {
- "version": "6.6.0",
- "resolved": "https://registry.npmjs.org/bson/-/bson-6.6.0.tgz",
- "integrity": "sha512-BVINv2SgcMjL4oYbBuCQTpE3/VKOSxrOA8Cj/wQP7izSzlBGVomdm+TcUd0Pzy0ytLSSDweCKQ6X3f5veM5LQA==",
+ "version": "6.7.0",
+ "resolved": "https://registry.npmjs.org/bson/-/bson-6.7.0.tgz",
+ "integrity": "sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ==",
"engines": {
"node": ">=16.20.1"
}
@@ -464,6 +465,7 @@
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz",
"integrity": "sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==",
+ "deprecated": "This package is no longer supported.",
"optional": true,
"dependencies": {
"aproba": "^1.0.3 || ^2.0.0",
@@ -488,6 +490,7 @@
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
+ "deprecated": "Glob versions prior to v9 are no longer supported",
"optional": true,
"dependencies": {
"fs.realpath": "^1.0.0",
@@ -617,6 +620,7 @@
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
+ "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.",
"optional": true,
"dependencies": {
"once": "^1.3.0",
@@ -676,6 +680,7 @@
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
+ "optional": true,
"dependencies": {
"yallist": "^4.0.0"
},
@@ -851,12 +856,12 @@
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
},
"node_modules/mongodb": {
- "version": "6.5.0",
- "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.5.0.tgz",
- "integrity": "sha512-Fozq68InT+JKABGLqctgtb8P56pRrJFkbhW0ux+x1mdHeyinor8oNzJqwLjV/t5X5nJGfTlluxfyMnOXNggIUA==",
+ "version": "6.7.0",
+ "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz",
+ "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==",
"dependencies": {
"@mongodb-js/saslprep": "^1.1.5",
- "bson": "^6.4.0",
+ "bson": "^6.7.0",
"mongodb-connection-string-url": "^3.0.0"
},
"engines": {
@@ -896,9 +901,9 @@
}
},
"node_modules/mongodb-connection-string-url": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.0.tgz",
- "integrity": "sha512-t1Vf+m1I5hC2M5RJx/7AtxgABy1cZmIPQRMXw+gEIPn/cZNF3Oiy+l0UIypUwVB5trcWHq3crg2g3uAR9aAwsQ==",
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.1.tgz",
+ "integrity": "sha512-XqMGwRX0Lgn05TDB4PyG2h2kKO/FfWJyCzYQbIhXUxz7ETt0I/FqHjUeqj37irJ+Dl1ZtU82uYyj14u2XsZKfg==",
"dependencies": {
"@types/whatwg-url": "^11.0.2",
"whatwg-url": "^13.0.0"
@@ -925,9 +930,9 @@
}
},
"node_modules/node-abi": {
- "version": "3.58.0",
- "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.58.0.tgz",
- "integrity": "sha512-pXY1jnGf5T7b8UNzWzIqf0EkX4bx/w8N2AvwlGnk2SYYA/kzDVPaH0Dh0UG4EwxBB5eKOIZKPr8VAHSHL1DPGg==",
+ "version": "3.62.0",
+ "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.62.0.tgz",
+ "integrity": "sha512-CPMcGa+y33xuL1E0TcNIu4YyaZCxnnvkVaEXrsosR3FxN+fV8xvb7Mzpb7IgKler10qeMkE6+Dp8qJhpzdq35g==",
"dependencies": {
"semver": "^7.3.5"
},
@@ -986,6 +991,7 @@
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz",
"integrity": "sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==",
+ "deprecated": "This package is no longer supported.",
"optional": true,
"dependencies": {
"are-we-there-yet": "^3.0.0",
@@ -1246,6 +1252,7 @@
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
+ "deprecated": "Rimraf versions prior to v4 are no longer supported",
"optional": true,
"dependencies": {
"glob": "^7.1.3"
@@ -1283,12 +1290,9 @@
"optional": true
},
"node_modules/semver": {
- "version": "7.6.0",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz",
- "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==",
- "dependencies": {
- "lru-cache": "^6.0.0"
- },
+ "version": "7.6.2",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz",
+ "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==",
"bin": {
"semver": "bin/semver.js"
},
diff --git a/src/index.js b/src/index.js
index e954588..7365e63 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,23 +2,28 @@ import { initialize } from "./cluster.js"
import { getMongoConnection, getPostgresConnection } from './db.js'
import cliProgress from 'cli-progress'
import { setTimeout } from 'node:timers/promises'
+import path from 'path'
+
const mongoDB = await getMongoConnection()
const postgresDB = await getPostgresConnection()
const ITEMS_PER_PAGE = 4000
const CLUSTER_SIZE = 99
-const TASK_FILE = new URL('./background-task.js', import.meta.url).pathname
+
+// Obtener la ruta absoluta y normalizarla usando path.win32 para compatibilidad con Windows
+let TASK_FILE = new URL('./background-task.js', import.meta.url).pathname
+if (process.platform === 'win32') {
+ TASK_FILE = path.win32.normalize(TASK_FILE.replace(/^\//, ''))
+}
// console.log(`there was ${await postgresDB.students.count()} items on Postgres, deleting all...`)
await postgresDB.students.deleteAll()
async function* getAllPagedData(itemsPerPage, page = 0) {
-
const data = mongoDB.students.find().skip(page).limit(itemsPerPage)
const items = await data.toArray()
if (!items.length) return
yield items
-
yield* getAllPagedData(itemsPerPage, page += itemsPerPage)
}
@@ -34,7 +39,7 @@ progress.start(total, 0);
let totalProcessed = 0
const cp = initialize(
{
- backgroundTaskFile: TASK_FILE,
+ backgroundTaskFile: TASK_FILE, // Usar la ruta corregida aquĆ
clusterSize: CLUSTER_SIZE,
amountToBeProcessed: total,
async onMessage(message) {
@@ -49,7 +54,6 @@ const cp = initialize(
console.log(`total on MongoDB ${total} and total on PostGres ${insertedOnSQLite}`)
console.log(`are the same? ${total === insertedOnSQLite ? 'yes' : 'no'}`)
process.exit()
-
}
}
)
@@ -58,4 +62,3 @@ await setTimeout(1000)
for await (const data of getAllPagedData(ITEMS_PER_PAGE)) {
cp.sendToChild(data)
}
-