@dignetwork/dig-sdk 0.0.1-alpha.11 → 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":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;
|
|
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"}
|
|
@@ -29,30 +29,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.calculateFolderSize = exports.addDirectory = void 0;
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
|
-
const util_1 = require("util");
|
|
33
32
|
const ignore_1 = __importDefault(require("ignore"));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
40
|
-
/**
|
|
41
|
-
* Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
|
|
42
|
-
* @param datalayer - The DataStoreManager instance.
|
|
43
|
-
* @param dirPath - The directory path.
|
|
44
|
-
* @param baseDir - The base directory for relative paths.
|
|
45
|
-
*/
|
|
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
|
+
}
|
|
46
38
|
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
39
|
+
const limit = await loadPLimit(); // Dynamically load p-limit and get the default export
|
|
47
40
|
const ig = (0, ignore_1.default)();
|
|
48
41
|
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
49
42
|
// Load .gitignore rules if the file exists
|
|
50
43
|
if (fs.existsSync(gitignorePath)) {
|
|
51
|
-
const gitignoreContent =
|
|
44
|
+
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
52
45
|
ig.add(gitignoreContent);
|
|
53
46
|
}
|
|
54
|
-
const files =
|
|
55
|
-
// Process each file or directory
|
|
47
|
+
const files = fs.readdirSync(dirPath);
|
|
56
48
|
await Promise.all(files.map(async (file) => {
|
|
57
49
|
const filePath = path.join(dirPath, file);
|
|
58
50
|
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
@@ -60,14 +52,13 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
60
52
|
if (file === ".dig" || file === ".git" || ig.ignores(relativePath)) {
|
|
61
53
|
return;
|
|
62
54
|
}
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
return (0, exports.addDirectory)(datalayer, filePath, baseDir);
|
|
55
|
+
const stat = fs.statSync(filePath);
|
|
56
|
+
if (stat.isDirectory()) {
|
|
57
|
+
await (0, exports.addDirectory)(datalayer, filePath, baseDir);
|
|
67
58
|
}
|
|
68
59
|
else {
|
|
69
|
-
//
|
|
70
|
-
return limit(() => new Promise((resolve, reject) => {
|
|
60
|
+
// Use the dynamically loaded p-limit to limit concurrent file processing
|
|
61
|
+
return limit(10)(() => new Promise((resolve, reject) => {
|
|
71
62
|
const stream = fs.createReadStream(filePath);
|
|
72
63
|
datalayer
|
|
73
64
|
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|