@dignetwork/dig-sdk 0.0.1-alpha.4 → 0.0.1-alpha.41
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/DataIntegrityTree/DataIntegrityTree.d.ts +160 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.js +672 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts +6 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataLayerError.js +17 -0
- package/dist/DataIntegrityTree/index.d.ts +2 -0
- package/dist/DataIntegrityTree/index.d.ts.map +1 -0
- package/dist/DataIntegrityTree/index.js +17 -0
- package/dist/DigNetwork/ContentServer.d.ts +5 -1
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +28 -13
- package/dist/DigNetwork/DigNetwork.d.ts +1 -0
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +74 -50
- package/dist/DigNetwork/DigPeer.d.ts +5 -1
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +51 -16
- package/dist/DigNetwork/PropagationServer.d.ts +7 -1
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +100 -68
- package/dist/blockchain/DataStore.d.ts +2 -2
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +9 -5
- package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.d.ts +8 -1
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +39 -7
- package/dist/blockchain/ServerCoin.d.ts +11 -3
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +30 -17
- package/dist/blockchain/Wallet.d.ts +1 -1
- package/dist/blockchain/Wallet.d.ts.map +1 -1
- package/dist/blockchain/Wallet.js +1 -1
- package/dist/blockchain/coins.d.ts +1 -1
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +4 -9
- package/dist/utils/directoryUtils.d.ts +1 -7
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +30 -11
- package/package.json +3 -3
package/dist/utils/config.js
CHANGED
|
@@ -49,9 +49,7 @@ const createInitialConfig = () => {
|
|
|
49
49
|
};
|
|
50
50
|
exports.createInitialConfig = createInitialConfig;
|
|
51
51
|
const setRemote = (remote) => {
|
|
52
|
-
|
|
53
|
-
throw new Error("Config file not found.");
|
|
54
|
-
}
|
|
52
|
+
(0, exports.ensureDigConfig)("");
|
|
55
53
|
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
56
54
|
config.remote = remote;
|
|
57
55
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
@@ -59,9 +57,7 @@ const setRemote = (remote) => {
|
|
|
59
57
|
};
|
|
60
58
|
exports.setRemote = setRemote;
|
|
61
59
|
const setActiveStore = (storeId) => {
|
|
62
|
-
|
|
63
|
-
throw new Error("Config file not found.");
|
|
64
|
-
}
|
|
60
|
+
(0, exports.ensureDigConfig)("");
|
|
65
61
|
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
66
62
|
config.active_store = storeId;
|
|
67
63
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
@@ -151,9 +147,7 @@ exports.getActiveStoreId = getActiveStoreId;
|
|
|
151
147
|
* @throws Will throw an error if the config file does not exist or cannot be parsed.
|
|
152
148
|
*/
|
|
153
149
|
const loadDigConfig = (baseDir) => {
|
|
154
|
-
|
|
155
|
-
throw new Error(`Configuration file not found at ${exports.CONFIG_FILE_PATH}`);
|
|
156
|
-
}
|
|
150
|
+
(0, exports.ensureDigConfig)("");
|
|
157
151
|
try {
|
|
158
152
|
const configContent = fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8");
|
|
159
153
|
const config = JSON.parse(configContent);
|
|
@@ -173,6 +167,7 @@ exports.loadDigConfig = loadDigConfig;
|
|
|
173
167
|
*/
|
|
174
168
|
const ensureDigConfig = (baseDir) => {
|
|
175
169
|
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
170
|
+
fs.mkdirSync(exports.DIG_FOLDER_PATH, { recursive: true });
|
|
176
171
|
const defaultConfig = { deploy_dir: "./dist" };
|
|
177
172
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4), "utf-8");
|
|
178
173
|
console.log(`Created new dig.config.json at ${exports.CONFIG_FILE_PATH}`);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { DataIntegrityTree } from "
|
|
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
|
-
*/
|
|
1
|
+
import { DataIntegrityTree } from "../DataIntegrityTree";
|
|
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":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA+BzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA4Cd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
|
|
@@ -27,15 +27,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.calculateFolderSize = exports.addDirectory = void 0;
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
30
|
const path = __importStar(require("path"));
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
32
|
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// Custom concurrency handler
|
|
34
|
+
const limitConcurrency = async (concurrencyLimit, tasks) => {
|
|
35
|
+
const executing = [];
|
|
36
|
+
for (const task of tasks) {
|
|
37
|
+
const p = task();
|
|
38
|
+
// Add the new task to the executing array
|
|
39
|
+
executing.push(p);
|
|
40
|
+
// When a task completes, remove it from the executing array
|
|
41
|
+
const cleanup = p.finally(() => {
|
|
42
|
+
executing.splice(executing.indexOf(cleanup), 1);
|
|
43
|
+
});
|
|
44
|
+
// Once the limit is reached, wait for one to complete
|
|
45
|
+
if (executing.length >= concurrencyLimit) {
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
47
|
+
await Promise.race(executing);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Wait for all remaining tasks to complete
|
|
51
|
+
return Promise.all(executing);
|
|
52
|
+
};
|
|
39
53
|
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
40
54
|
const ig = (0, ignore_1.default)();
|
|
41
55
|
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
@@ -45,6 +59,7 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
45
59
|
ig.add(gitignoreContent);
|
|
46
60
|
}
|
|
47
61
|
const files = fs.readdirSync(dirPath);
|
|
62
|
+
const tasks = [];
|
|
48
63
|
for (const file of files) {
|
|
49
64
|
const filePath = path.join(dirPath, file);
|
|
50
65
|
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
@@ -54,18 +69,22 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
54
69
|
}
|
|
55
70
|
const stat = fs.statSync(filePath);
|
|
56
71
|
if (stat.isDirectory()) {
|
|
57
|
-
|
|
72
|
+
// Recursively process the directory
|
|
73
|
+
tasks.push(() => (0, exports.addDirectory)(datalayer, filePath, baseDir));
|
|
58
74
|
}
|
|
59
75
|
else {
|
|
60
|
-
|
|
76
|
+
// Add a task for each file to be processed
|
|
77
|
+
tasks.push(() => new Promise((resolve, reject) => {
|
|
61
78
|
const stream = fs.createReadStream(filePath);
|
|
62
79
|
datalayer
|
|
63
80
|
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
64
|
-
.then(resolve)
|
|
81
|
+
.then(() => resolve())
|
|
65
82
|
.catch(reject);
|
|
66
|
-
});
|
|
83
|
+
}));
|
|
67
84
|
}
|
|
68
85
|
}
|
|
86
|
+
// Run tasks with limited concurrency (set the concurrency limit as needed)
|
|
87
|
+
await limitConcurrency(10, tasks); // Adjust 10 based on your system limits
|
|
69
88
|
};
|
|
70
89
|
exports.addDirectory = addDirectory;
|
|
71
90
|
/**
|
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.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dignetwork/
|
|
28
|
+
"@dignetwork/datalayer-driver": "^0.1.24",
|
|
29
29
|
"bip39": "^3.1.0",
|
|
30
30
|
"chia-bls": "^1.0.2",
|
|
31
31
|
"chia-config-loader": "^1.0.1",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"chia-wallet": "^1.0.18",
|
|
35
35
|
"cli-progress": "^3.12.0",
|
|
36
36
|
"crypto-js": "^4.2.0",
|
|
37
|
-
"datalayer-driver": "^0.1.21",
|
|
38
37
|
"fs-extra": "^11.2.0",
|
|
39
38
|
"ignore": "^5.3.2",
|
|
40
39
|
"inquirer": "^10.1.8",
|
|
@@ -42,6 +41,7 @@
|
|
|
42
41
|
"merkletreejs": "^0.4.0",
|
|
43
42
|
"nanospinner": "^1.1.0",
|
|
44
43
|
"nconf": "^0.12.1",
|
|
44
|
+
"p-limit": "^6.1.0",
|
|
45
45
|
"superagent": "^10.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|