@dignetwork/dig-sdk 0.0.1-alpha.10 → 0.0.1-alpha.11

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 +1 @@
1
- {"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CAmCd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
1
+ {"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAUzD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA0Cd,CAAC;AAGF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
@@ -29,7 +29,14 @@ 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");
32
33
  const ignore_1 = __importDefault(require("ignore"));
34
+ const p_limit_1 = __importDefault(require("p-limit"));
35
+ const limit = (0, p_limit_1.default)(10); // Limit the concurrency to 10 (adjust based on your system's file descriptor limit)
36
+ // Promisify fs methods
37
+ const readdir = (0, util_1.promisify)(fs.readdir);
38
+ const stat = (0, util_1.promisify)(fs.stat);
39
+ const readFile = (0, util_1.promisify)(fs.readFile);
33
40
  /**
34
41
  * Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
35
42
  * @param datalayer - The DataStoreManager instance.
@@ -41,31 +48,34 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
41
48
  const gitignorePath = path.join(baseDir, ".gitignore");
42
49
  // Load .gitignore rules if the file exists
43
50
  if (fs.existsSync(gitignorePath)) {
44
- const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
51
+ const gitignoreContent = await readFile(gitignorePath, "utf-8");
45
52
  ig.add(gitignoreContent);
46
53
  }
47
- const files = fs.readdirSync(dirPath);
48
- for (const file of files) {
54
+ const files = await readdir(dirPath);
55
+ // Process each file or directory
56
+ await Promise.all(files.map(async (file) => {
49
57
  const filePath = path.join(dirPath, file);
50
58
  const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
51
59
  // Skip the .dig, .git folders and files or directories ignored by .gitignore
52
60
  if (file === ".dig" || file === ".git" || ig.ignores(relativePath)) {
53
- continue;
61
+ return;
54
62
  }
55
- const stat = fs.statSync(filePath);
56
- if (stat.isDirectory()) {
57
- await (0, exports.addDirectory)(datalayer, filePath, baseDir);
63
+ const fileStat = await stat(filePath);
64
+ if (fileStat.isDirectory()) {
65
+ // Recursively process the directory
66
+ return (0, exports.addDirectory)(datalayer, filePath, baseDir);
58
67
  }
59
68
  else {
60
- await new Promise((resolve, reject) => {
69
+ // Process the file with limited concurrency
70
+ return limit(() => new Promise((resolve, reject) => {
61
71
  const stream = fs.createReadStream(filePath);
62
72
  datalayer
63
73
  .upsertKey(stream, Buffer.from(relativePath).toString("hex"))
64
74
  .then(resolve)
65
75
  .catch(reject);
66
- });
76
+ }));
67
77
  }
68
- }
78
+ }));
69
79
  };
70
80
  exports.addDirectory = addDirectory;
71
81
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.11",
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": {