@shelby-protocol/sdk 0.3.1 → 0.4.0
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/browser/index.d.ts +9 -9
- package/dist/browser/index.mjs +1068 -589
- package/dist/core/clients/ShelbyBlobClient.d.ts +155 -40
- package/dist/core/clients/ShelbyBlobClient.mjs +314 -112
- package/dist/core/clients/ShelbyClient.d.ts +27 -4
- package/dist/core/clients/ShelbyClient.mjs +869 -551
- package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
- package/dist/core/clients/ShelbyMetadataClient.d.ts +38 -6
- package/dist/core/clients/ShelbyMetadataClient.mjs +95 -13
- package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +42 -0
- package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +62 -7
- package/dist/core/clients/ShelbyPlacementGroupClient.mjs +10 -7
- package/dist/core/clients/ShelbyRPCClient.d.ts +55 -66
- package/dist/core/clients/ShelbyRPCClient.mjs +344 -360
- package/dist/core/clients/index.d.ts +3 -2
- package/dist/core/clients/index.mjs +933 -551
- package/dist/core/clients/utils.mjs +1 -1
- package/dist/core/commitments.d.ts +12 -1
- package/dist/core/commitments.mjs +7 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.mjs +1 -1
- package/dist/core/erasure/constants.d.ts +16 -1
- package/dist/core/erasure/constants.mjs +15 -1
- package/dist/core/erasure/index.d.ts +1 -1
- package/dist/core/erasure/index.mjs +15 -1
- package/dist/core/errors.d.ts +20 -1
- package/dist/core/errors.mjs +29 -0
- package/dist/core/index.d.ts +9 -9
- package/dist/core/index.mjs +1068 -589
- package/dist/core/operations/generated/sdk.d.ts +798 -42
- package/dist/core/operations/generated/sdk.mjs +93 -9
- package/dist/core/operations/index.d.ts +1 -1
- package/dist/core/operations/index.mjs +94 -10
- package/dist/core/rpc-responses.d.ts +1 -57
- package/dist/core/rpc-responses.mjs +1 -21
- package/dist/core/sp/chunk_proof.d.ts +23 -0
- package/dist/core/sp/chunk_proof.mjs +113 -0
- package/dist/core/sp/index.d.ts +3 -0
- package/dist/core/sp/index.mjs +402 -0
- package/dist/core/sp/sp_write_client.d.ts +53 -0
- package/dist/core/sp/sp_write_client.mjs +302 -0
- package/dist/core/types/blobs.d.ts +24 -5
- package/dist/core/types/blobs.mjs +24 -0
- package/dist/core/types/index.d.ts +2 -2
- package/dist/core/types/index.mjs +46 -2
- package/dist/core/types/payments.mjs +1 -1
- package/dist/core/types/storage_providers.d.ts +32 -6
- package/dist/core/types/storage_providers.mjs +22 -0
- package/dist/gen/rpc_server_pb.d.ts +295 -0
- package/dist/gen/rpc_server_pb.mjs +28 -0
- package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
- package/dist/node/clients/ShelbyNodeClient.mjs +869 -551
- package/dist/node/clients/index.d.ts +1 -0
- package/dist/node/clients/index.mjs +867 -551
- package/dist/node/index.d.ts +9 -9
- package/dist/node/index.mjs +1068 -589
- package/dist/node/parallel/commitment_worker.mjs +36 -249
- package/dist/node/parallel/commitment_worker_pool.mjs +56 -3
- package/dist/node/parallel/coverage_flush.d.ts +16 -0
- package/dist/node/parallel/coverage_flush.mjs +43 -0
- package/dist/node/parallel/default_commitment_worker_pool.mjs +56 -3
- package/dist/node/parallel/index.d.ts +1 -0
- package/dist/node/parallel/index.mjs +72 -4
- package/dist/node/parallel/parallel_commitments.mjs +56 -3
- package/dist/node/parallel/worker_pool.mjs +56 -3
- package/package.json +11 -4
|
@@ -205,6 +205,35 @@ import fs from "fs";
|
|
|
205
205
|
import path from "path";
|
|
206
206
|
import { fileURLToPath } from "url";
|
|
207
207
|
import { Worker } from "worker_threads";
|
|
208
|
+
|
|
209
|
+
// src/node/parallel/coverage_flush.ts
|
|
210
|
+
import { takeCoverage } from "v8";
|
|
211
|
+
var FLUSH_REQUEST = "__shelby_cov_flush_request__";
|
|
212
|
+
var FLUSH_ACK = "__shelby_cov_flush_ack__";
|
|
213
|
+
var coverageEnabled = () => Boolean(process.env.NODE_V8_COVERAGE);
|
|
214
|
+
var isType = (msg, type) => typeof msg === "object" && msg !== null && msg.type === type;
|
|
215
|
+
function flushWorkerCoverage(worker, timeoutMs = 2e3) {
|
|
216
|
+
if (!coverageEnabled()) return Promise.resolve();
|
|
217
|
+
return new Promise((resolve) => {
|
|
218
|
+
const onMessage = (msg) => {
|
|
219
|
+
if (isType(msg, FLUSH_ACK)) finish();
|
|
220
|
+
};
|
|
221
|
+
const finish = () => {
|
|
222
|
+
clearTimeout(timer);
|
|
223
|
+
worker.off("message", onMessage);
|
|
224
|
+
resolve();
|
|
225
|
+
};
|
|
226
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
227
|
+
worker.on("message", onMessage);
|
|
228
|
+
try {
|
|
229
|
+
worker.postMessage({ type: FLUSH_REQUEST });
|
|
230
|
+
} catch {
|
|
231
|
+
finish();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/node/parallel/worker_pool.ts
|
|
208
237
|
var WorkerPool = class {
|
|
209
238
|
workers = [];
|
|
210
239
|
queue = [];
|
|
@@ -241,6 +270,29 @@ var WorkerPool = class {
|
|
|
241
270
|
const dir = path.dirname(currentPath);
|
|
242
271
|
const ext = path.extname(currentPath);
|
|
243
272
|
const workerExt = ext === ".mjs" ? ".mjs" : ext === ".js" ? ".js" : ".ts";
|
|
273
|
+
if (workerExt === ".ts") {
|
|
274
|
+
const srcSegment = `${path.sep}src${path.sep}`;
|
|
275
|
+
const srcIdx = currentPath.indexOf(srcSegment);
|
|
276
|
+
if (srcIdx !== -1) {
|
|
277
|
+
const packageRoot = currentPath.slice(0, srcIdx);
|
|
278
|
+
const relFromSrc = path.relative(path.join(packageRoot, "src"), dir);
|
|
279
|
+
return path.join(
|
|
280
|
+
packageRoot,
|
|
281
|
+
"dist",
|
|
282
|
+
"workers",
|
|
283
|
+
relFromSrc,
|
|
284
|
+
`${scriptName}.js`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let workerPath = path.join(dir, `${scriptName}${workerExt}`);
|
|
289
|
+
if (fs.existsSync(workerPath)) {
|
|
290
|
+
return workerPath;
|
|
291
|
+
}
|
|
292
|
+
workerPath = path.join(dir, "workers", `${scriptName}${workerExt}`);
|
|
293
|
+
if (fs.existsSync(workerPath)) {
|
|
294
|
+
return workerPath;
|
|
295
|
+
}
|
|
244
296
|
return path.join(dir, `${scriptName}${workerExt}`);
|
|
245
297
|
}
|
|
246
298
|
initialize() {
|
|
@@ -412,9 +464,10 @@ var WorkerPool = class {
|
|
|
412
464
|
for (const waiter of waiters) {
|
|
413
465
|
waiter.reject(terminationError);
|
|
414
466
|
}
|
|
415
|
-
const terminatePromises = this.workers.map((workerWrapper) => {
|
|
416
|
-
|
|
417
|
-
|
|
467
|
+
const terminatePromises = this.workers.map(async (workerWrapper) => {
|
|
468
|
+
const worker = workerWrapper.worker;
|
|
469
|
+
await flushWorkerCoverage(worker);
|
|
470
|
+
await new Promise((resolve) => {
|
|
418
471
|
let resolved = false;
|
|
419
472
|
const doResolve = () => {
|
|
420
473
|
if (!resolved) {
|
|
@@ -3,6 +3,35 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { Worker } from "worker_threads";
|
|
6
|
+
|
|
7
|
+
// src/node/parallel/coverage_flush.ts
|
|
8
|
+
import { takeCoverage } from "v8";
|
|
9
|
+
var FLUSH_REQUEST = "__shelby_cov_flush_request__";
|
|
10
|
+
var FLUSH_ACK = "__shelby_cov_flush_ack__";
|
|
11
|
+
var coverageEnabled = () => Boolean(process.env.NODE_V8_COVERAGE);
|
|
12
|
+
var isType = (msg, type) => typeof msg === "object" && msg !== null && msg.type === type;
|
|
13
|
+
function flushWorkerCoverage(worker, timeoutMs = 2e3) {
|
|
14
|
+
if (!coverageEnabled()) return Promise.resolve();
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const onMessage = (msg) => {
|
|
17
|
+
if (isType(msg, FLUSH_ACK)) finish();
|
|
18
|
+
};
|
|
19
|
+
const finish = () => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
worker.off("message", onMessage);
|
|
22
|
+
resolve();
|
|
23
|
+
};
|
|
24
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
25
|
+
worker.on("message", onMessage);
|
|
26
|
+
try {
|
|
27
|
+
worker.postMessage({ type: FLUSH_REQUEST });
|
|
28
|
+
} catch {
|
|
29
|
+
finish();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/node/parallel/worker_pool.ts
|
|
6
35
|
var WorkerPool = class {
|
|
7
36
|
workers = [];
|
|
8
37
|
queue = [];
|
|
@@ -39,6 +68,29 @@ var WorkerPool = class {
|
|
|
39
68
|
const dir = path.dirname(currentPath);
|
|
40
69
|
const ext = path.extname(currentPath);
|
|
41
70
|
const workerExt = ext === ".mjs" ? ".mjs" : ext === ".js" ? ".js" : ".ts";
|
|
71
|
+
if (workerExt === ".ts") {
|
|
72
|
+
const srcSegment = `${path.sep}src${path.sep}`;
|
|
73
|
+
const srcIdx = currentPath.indexOf(srcSegment);
|
|
74
|
+
if (srcIdx !== -1) {
|
|
75
|
+
const packageRoot = currentPath.slice(0, srcIdx);
|
|
76
|
+
const relFromSrc = path.relative(path.join(packageRoot, "src"), dir);
|
|
77
|
+
return path.join(
|
|
78
|
+
packageRoot,
|
|
79
|
+
"dist",
|
|
80
|
+
"workers",
|
|
81
|
+
relFromSrc,
|
|
82
|
+
`${scriptName}.js`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let workerPath = path.join(dir, `${scriptName}${workerExt}`);
|
|
87
|
+
if (fs.existsSync(workerPath)) {
|
|
88
|
+
return workerPath;
|
|
89
|
+
}
|
|
90
|
+
workerPath = path.join(dir, "workers", `${scriptName}${workerExt}`);
|
|
91
|
+
if (fs.existsSync(workerPath)) {
|
|
92
|
+
return workerPath;
|
|
93
|
+
}
|
|
42
94
|
return path.join(dir, `${scriptName}${workerExt}`);
|
|
43
95
|
}
|
|
44
96
|
initialize() {
|
|
@@ -210,9 +262,10 @@ var WorkerPool = class {
|
|
|
210
262
|
for (const waiter of waiters) {
|
|
211
263
|
waiter.reject(terminationError);
|
|
212
264
|
}
|
|
213
|
-
const terminatePromises = this.workers.map((workerWrapper) => {
|
|
214
|
-
|
|
215
|
-
|
|
265
|
+
const terminatePromises = this.workers.map(async (workerWrapper) => {
|
|
266
|
+
const worker = workerWrapper.worker;
|
|
267
|
+
await flushWorkerCoverage(worker);
|
|
268
|
+
await new Promise((resolve) => {
|
|
216
269
|
let resolved = false;
|
|
217
270
|
const doResolve = () => {
|
|
218
271
|
if (!resolved) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelby-protocol/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -18,19 +18,24 @@
|
|
|
18
18
|
"types": "./dist/node/parallel/index.d.ts",
|
|
19
19
|
"import": "./dist/node/parallel/index.mjs"
|
|
20
20
|
},
|
|
21
|
+
"./sp": {
|
|
22
|
+
"types": "./dist/core/sp/index.d.ts",
|
|
23
|
+
"import": "./dist/core/sp/index.mjs"
|
|
24
|
+
},
|
|
21
25
|
"./browser": {
|
|
22
26
|
"types": "./dist/browser/index.d.ts",
|
|
23
27
|
"import": "./dist/browser/index.mjs"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"dependencies": {
|
|
31
|
+
"@bufbuild/protobuf": "^2.8.0",
|
|
27
32
|
"graphql": "^16.11.0",
|
|
28
33
|
"graphql-request": "^7.2.0",
|
|
29
34
|
"graphql-tag": "^2.12.6",
|
|
30
35
|
"p-limit": "7.1.1",
|
|
31
36
|
"zod": "^3.24.3",
|
|
32
|
-
"@shelby-protocol/
|
|
33
|
-
"@shelby-protocol/
|
|
37
|
+
"@shelby-protocol/reed-solomon": "0.0.1",
|
|
38
|
+
"@shelby-protocol/clay-codes": "0.0.2"
|
|
34
39
|
},
|
|
35
40
|
"devDependencies": {
|
|
36
41
|
"@aptos-labs/ts-sdk": "5.2.1",
|
|
@@ -53,12 +58,14 @@
|
|
|
53
58
|
"scripts": {
|
|
54
59
|
"lint": "biome check .",
|
|
55
60
|
"fmt": "biome check . --write",
|
|
56
|
-
"generate": "graphql-codegen",
|
|
61
|
+
"generate": "graphql-codegen && (cd ../.. && pnpm exec buf generate --template buf.gen.server.yaml --path proto/rpc_server.proto)",
|
|
57
62
|
"generate:watch": "graphql-codegen --watch",
|
|
63
|
+
"generate:schema": "node scripts/dump-schema.mjs",
|
|
58
64
|
"verify:config": "tsx scripts/verify-config.ts",
|
|
59
65
|
"build": "tsc --noEmit && (rimraf dist; tsup) && pnpm run verify:config",
|
|
60
66
|
"test": "vitest dev",
|
|
61
67
|
"test:once": "pnpm run build && vitest run",
|
|
68
|
+
"test:integration": "vitest run --config vitest.integration.config.ts --reporter=verbose",
|
|
62
69
|
"benchmark:erasure": "tsx benchmark/erasure.ts"
|
|
63
70
|
}
|
|
64
71
|
}
|