@dignetwork/dig-sdk 0.0.1-alpha.10 → 0.0.1-alpha.12
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.
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { DataIntegrityTree } from "../DataIntegrityTree";
|
|
2
|
-
/**
|
|
3
|
-
* Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
|
|
4
|
-
* @param datalayer - The DataStoreManager instance.
|
|
5
|
-
* @param dirPath - The directory path.
|
|
6
|
-
* @param baseDir - The base directory for relative paths.
|
|
7
|
-
*/
|
|
8
2
|
export declare const addDirectory: (datalayer: DataIntegrityTree, dirPath: string, baseDir?: string) => Promise<void>;
|
|
9
3
|
/**
|
|
10
4
|
* Calculate the total size of the DIG_FOLDER_PATH
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AASzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CAyCd,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
|
|
@@ -30,13 +30,13 @@ exports.calculateFolderSize = exports.addDirectory = void 0;
|
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
33
|
+
// Function to dynamically load p-limit since it's an ES module
|
|
34
|
+
async function loadPLimit() {
|
|
35
|
+
const { default: pLimit } = await Promise.resolve().then(() => __importStar(require('p-limit')));
|
|
36
|
+
return pLimit;
|
|
37
|
+
}
|
|
39
38
|
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
39
|
+
const limit = await loadPLimit(); // Dynamically load p-limit and get the default export
|
|
40
40
|
const ig = (0, ignore_1.default)();
|
|
41
41
|
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
42
42
|
// Load .gitignore rules if the file exists
|
|
@@ -45,27 +45,28 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
45
45
|
ig.add(gitignoreContent);
|
|
46
46
|
}
|
|
47
47
|
const files = fs.readdirSync(dirPath);
|
|
48
|
-
|
|
48
|
+
await Promise.all(files.map(async (file) => {
|
|
49
49
|
const filePath = path.join(dirPath, file);
|
|
50
50
|
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
51
51
|
// Skip the .dig, .git folders and files or directories ignored by .gitignore
|
|
52
52
|
if (file === ".dig" || file === ".git" || ig.ignores(relativePath)) {
|
|
53
|
-
|
|
53
|
+
return;
|
|
54
54
|
}
|
|
55
55
|
const stat = fs.statSync(filePath);
|
|
56
56
|
if (stat.isDirectory()) {
|
|
57
57
|
await (0, exports.addDirectory)(datalayer, filePath, baseDir);
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
|
|
60
|
+
// Use the dynamically loaded p-limit to limit concurrent file processing
|
|
61
|
+
return limit(10)(() => new Promise((resolve, reject) => {
|
|
61
62
|
const stream = fs.createReadStream(filePath);
|
|
62
63
|
datalayer
|
|
63
64
|
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
64
65
|
.then(resolve)
|
|
65
66
|
.catch(reject);
|
|
66
|
-
});
|
|
67
|
+
}));
|
|
67
68
|
}
|
|
68
|
-
}
|
|
69
|
+
}));
|
|
69
70
|
};
|
|
70
71
|
exports.addDirectory = addDirectory;
|
|
71
72
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"merkletreejs": "^0.4.0",
|
|
42
42
|
"nanospinner": "^1.1.0",
|
|
43
43
|
"nconf": "^0.12.1",
|
|
44
|
+
"p-limit": "^6.1.0",
|
|
44
45
|
"superagent": "^10.0.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|