@ethersphere/bee-js 13.0.0-upcoming.gcfb9756 → 13.0.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/README.md +104 -103
- package/dist/cjs/api/bytes.js +3 -4
- package/dist/cjs/api/bzz.js +5 -6
- package/dist/cjs/api/chunk.js +3 -3
- package/dist/cjs/api/envelope.js +3 -2
- package/dist/cjs/api/feed.js +4 -5
- package/dist/cjs/api/pin.js +2 -2
- package/dist/cjs/api/soc.js +2 -2
- package/dist/cjs/bee.js +18 -19
- package/dist/cjs/chunk/soc.js +21 -63
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +17 -19
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +97 -333
- package/dist/cjs/modules/balance.js +3 -3
- package/dist/cjs/modules/cheque.js +4 -4
- package/dist/cjs/modules/chunk.js +8 -8
- package/dist/cjs/modules/collection.js +6 -6
- package/dist/cjs/modules/connectivity.js +3 -3
- package/dist/cjs/modules/data.js +6 -6
- package/dist/cjs/modules/feed.js +10 -10
- package/dist/cjs/modules/file.js +3 -3
- package/dist/cjs/modules/grantee.js +9 -9
- package/dist/cjs/modules/messaging.js +15 -17
- package/dist/cjs/modules/pin.js +6 -6
- package/dist/cjs/modules/settlement.js +2 -2
- package/dist/cjs/modules/soc.js +3 -3
- package/dist/cjs/modules/stamp.js +7 -7
- package/dist/cjs/modules/tag.js +2 -2
- package/dist/cjs/modules/transaction.js +4 -4
- package/dist/cjs/modules/wallet.js +3 -3
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +3 -1
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/cjs/utils/type.js +2 -2
- package/dist/codemod/index.js +141 -0
- package/dist/codemod/transforms/v13.js +524 -0
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/bytes.js +1 -2
- package/dist/mjs/api/bzz.js +1 -2
- package/dist/mjs/api/chunk.js +1 -1
- package/dist/mjs/api/envelope.js +3 -2
- package/dist/mjs/api/feed.js +1 -2
- package/dist/mjs/api/pin.js +1 -1
- package/dist/mjs/api/soc.js +1 -1
- package/dist/mjs/bee.js +13 -14
- package/dist/mjs/chunk/soc.js +11 -49
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +6 -8
- package/dist/mjs/feed/retrievable.js +1 -1
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +95 -339
- package/dist/mjs/modules/balance.js +1 -1
- package/dist/mjs/modules/cheque.js +1 -1
- package/dist/mjs/modules/chunk.js +1 -1
- package/dist/mjs/modules/collection.js +1 -1
- package/dist/mjs/modules/connectivity.js +1 -1
- package/dist/mjs/modules/data.js +3 -3
- package/dist/mjs/modules/feed.js +1 -1
- package/dist/mjs/modules/file.js +1 -1
- package/dist/mjs/modules/grantee.js +1 -1
- package/dist/mjs/modules/messaging.js +3 -5
- package/dist/mjs/modules/pin.js +1 -1
- package/dist/mjs/modules/settlement.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/stamp.js +1 -1
- package/dist/mjs/modules/tag.js +1 -1
- package/dist/mjs/modules/transaction.js +1 -1
- package/dist/mjs/modules/wallet.js +1 -1
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/http.js +6 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/mjs/utils/type.js +2 -2
- package/dist/types/api/balance.d.ts +1 -1
- package/dist/types/api/batches.d.ts +1 -1
- package/dist/types/api/bytes.d.ts +3 -3
- package/dist/types/api/bzz.d.ts +1 -2
- package/dist/types/api/chequebook.d.ts +1 -1
- package/dist/types/api/chunk.d.ts +1 -1
- package/dist/types/api/connectivity.d.ts +1 -1
- package/dist/types/api/consumed.d.ts +1 -1
- package/dist/types/api/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +1 -2
- package/dist/types/api/grantee.d.ts +1 -1
- package/dist/types/api/pin.d.ts +1 -1
- package/dist/types/api/pss.d.ts +1 -1
- package/dist/types/api/settlement.d.ts +1 -1
- package/dist/types/api/soc.d.ts +1 -1
- package/dist/types/api/stake.d.ts +1 -1
- package/dist/types/api/stamp.d.ts +1 -1
- package/dist/types/api/stewardship.d.ts +1 -1
- package/dist/types/api/tag.d.ts +1 -1
- package/dist/types/api/transaction.d.ts +1 -1
- package/dist/types/api/wallet.d.ts +1 -1
- package/dist/types/bee.d.ts +11 -13
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -3
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +24 -33
- package/dist/types/modules/balance.d.ts +1 -1
- package/dist/types/modules/cheque.d.ts +1 -1
- package/dist/types/modules/chequebook.d.ts +1 -1
- package/dist/types/modules/chunk.d.ts +1 -2
- package/dist/types/modules/collection.d.ts +2 -2
- package/dist/types/modules/connectivity.d.ts +1 -1
- package/dist/types/modules/context.d.ts +1 -1
- package/dist/types/modules/data.d.ts +3 -3
- package/dist/types/modules/feed.d.ts +1 -1
- package/dist/types/modules/file.d.ts +1 -2
- package/dist/types/modules/grantee.d.ts +1 -1
- package/dist/types/modules/messaging.d.ts +1 -2
- package/dist/types/modules/pin.d.ts +1 -1
- package/dist/types/modules/settlement.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/stake.d.ts +1 -1
- package/dist/types/modules/stamp.d.ts +1 -1
- package/dist/types/modules/storage.d.ts +1 -1
- package/dist/types/modules/tag.d.ts +1 -1
- package/dist/types/modules/transaction.d.ts +1 -1
- package/dist/types/modules/wallet.d.ts +1 -1
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +2 -11
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -1
- package/package.json +7 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
package/dist/mjs/modules/soc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EthAddress, PrivateKey } from '@ethersphere/core-sdk';
|
|
1
2
|
import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "../chunk/soc.js";
|
|
2
|
-
import { EthAddress, PrivateKey } from "../utils/typed-bytes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Single owner chunk (SOC) reader/writer operations.
|
|
5
5
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BatchId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { System } from 'cafe-utility';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "../types/index.js";
|
|
@@ -5,7 +6,6 @@ import { BeeArgumentError, BeeError } from "../utils/error.js";
|
|
|
5
6
|
import { PostageBatchOptionsSchema } from "../utils/schema.js";
|
|
6
7
|
import { getStampDuration } from "../utils/stamps.js";
|
|
7
8
|
import { asNumberString } from "../utils/type.js";
|
|
8
|
-
import { BatchId } from "../utils/typed-bytes.js";
|
|
9
9
|
import * as stampApi from "../api/stamp.js";
|
|
10
10
|
import * as batchesApi from "../api/batches.js";
|
|
11
11
|
/**
|
package/dist/mjs/modules/tag.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import * as api from "../api/tag.js";
|
|
2
3
|
import { AllTagsOptionsSchema } from "../utils/schema.js";
|
|
3
4
|
import { makeTagUid } from "../utils/type.js";
|
|
4
|
-
import { Reference } from "../utils/typed-bytes.js";
|
|
5
5
|
/**
|
|
6
6
|
* Tag operations for tracking upload and synchronization progress.
|
|
7
7
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { asNumberString } from "../utils/type.js";
|
|
2
|
-
import { TransactionId } from "../utils/typed-bytes.js";
|
|
3
3
|
import * as api from "../api/transaction.js";
|
|
4
4
|
/**
|
|
5
5
|
* Pending transaction operations for the Bee node's `/transactions` queue.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { EthAddress, TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { BZZ } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
|
-
import { EthAddress, TransactionId } from "../../utils/typed-bytes.js";
|
|
5
5
|
const ChequeSchema = z.object({
|
|
6
6
|
beneficiary: z.string().transform(s => new EthAddress(s)),
|
|
7
7
|
chequebook: z.string().transform(s => new EthAddress(s)),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Binary } from 'cafe-utility';
|
|
2
1
|
import { z } from 'zod';
|
|
2
|
+
import { hexToUint8Array } from '@ethersphere/core-sdk';
|
|
3
3
|
export const PostEnvelopeBodyResponse = z.object({
|
|
4
|
-
issuer: z.string().transform(s =>
|
|
5
|
-
index: z.string().transform(s =>
|
|
6
|
-
timestamp: z.string().transform(s =>
|
|
7
|
-
signature: z.string().transform(s =>
|
|
4
|
+
issuer: z.string().transform(s => hexToUint8Array(s)),
|
|
5
|
+
index: z.string().transform(s => hexToUint8Array(s)),
|
|
6
|
+
timestamp: z.string().transform(s => hexToUint8Array(s)),
|
|
7
|
+
signature: z.string().transform(s => hexToUint8Array(s))
|
|
8
8
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { PublicKey, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import { PublicKey, Reference } from "../../utils/typed-bytes.js";
|
|
3
3
|
export const GetGranteesBodyResponse = z.array(z.string().transform(s => new PublicKey(s)));
|
|
4
4
|
export const GranteesResultBodyResponse = z.object({
|
|
5
5
|
ref: z.string().transform(s => new Reference(s)),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
|
-
import { TransactionId } from "../../utils/typed-bytes.js";
|
|
5
5
|
export const GetStakeResponse = z.object({
|
|
6
6
|
stakedAmount: z.string().transform(s => BZZ.fromPLUR(asNumberString(s, {
|
|
7
7
|
name: 'stakedAmount'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { BatchId, EthAddress } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { asNumberString } from "../../utils/type.js";
|
|
3
|
-
import { BatchId, EthAddress } from "../../utils/typed-bytes.js";
|
|
4
4
|
export const RawPostageBatchSchema = z.object({
|
|
5
5
|
batchID: z.string(),
|
|
6
6
|
utilization: z.number(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
3
4
|
import { asNumberString } from "../../utils/type.js";
|
|
4
|
-
import { TransactionId } from "../../utils/typed-bytes.js";
|
|
5
5
|
import { normalizeCurrentPrice } from "../../utils/workaround.js";
|
|
6
6
|
export const GetReserveStateResponse = z.object({
|
|
7
7
|
commitment: z.number(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { asNumberString } from "../../utils/type.js";
|
|
3
|
-
import { TransactionId } from "../../utils/typed-bytes.js";
|
|
4
4
|
const TransactionInfoSchema = z.object({
|
|
5
5
|
transactionHash: z.string().transform(s => new TransactionId(s)),
|
|
6
6
|
to: z.string(),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AsyncQueue,
|
|
1
|
+
import { AsyncQueue, Strings } from 'cafe-utility';
|
|
2
2
|
import { NULL_ADDRESS } from "../index.js";
|
|
3
3
|
import { MantarayNode } from "../manifest/manifest.js";
|
|
4
4
|
import { totalChunks } from "./chunk-size.js";
|
|
5
5
|
import { makeFilePath } from "./collection.js";
|
|
6
6
|
import { mimes } from "./mime.js";
|
|
7
|
-
import { BatchId } from
|
|
7
|
+
import { BatchId, ChunkSplitter } from '@ethersphere/core-sdk';
|
|
8
8
|
export async function hashDirectory(_dir) {
|
|
9
9
|
throw new Error('Hashing directories is not supported in browsers!');
|
|
10
10
|
}
|
|
@@ -23,24 +23,30 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
|
|
|
23
23
|
total += totalChunks(file.size);
|
|
24
24
|
}
|
|
25
25
|
postageBatchId = new BatchId(postageBatchId);
|
|
26
|
-
async function
|
|
27
|
-
|
|
26
|
+
async function uploadAndTrack(chunk) {
|
|
27
|
+
if (signal?.aborted) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
|
|
32
|
+
onUploadProgress?.({
|
|
33
|
+
total,
|
|
34
|
+
processed: ++processed
|
|
35
|
+
});
|
|
36
|
+
} catch (err) {
|
|
28
37
|
if (signal?.aborted) {
|
|
29
38
|
return;
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function onBatch(batch) {
|
|
44
|
+
for (const {
|
|
45
|
+
chunk
|
|
46
|
+
} of batch) {
|
|
47
|
+
await queue.enqueue(async () => uploadAndTrack(chunk));
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
44
50
|
}
|
|
45
51
|
const mantaray = new MantarayNode();
|
|
46
52
|
for (const file of files) {
|
|
@@ -48,7 +54,7 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
|
|
|
48
54
|
throw new Error('Request aborted');
|
|
49
55
|
}
|
|
50
56
|
const rootChunk = await new Promise((resolve, reject) => {
|
|
51
|
-
const tree = new
|
|
57
|
+
const tree = new ChunkSplitter(onBatch);
|
|
52
58
|
let offset = 0;
|
|
53
59
|
const reader = new FileReader();
|
|
54
60
|
reader.onerror = () => {
|
|
@@ -60,7 +66,11 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
|
|
|
60
66
|
return;
|
|
61
67
|
}
|
|
62
68
|
if (offset >= file.size) {
|
|
69
|
+
// ChunkSplitter's onBatch only sees chunks once they're referenced
|
|
70
|
+
// by a parent - the root chunk returned by finalize() is never
|
|
71
|
+
// passed to it, so it has to be uploaded here explicitly.
|
|
63
72
|
const rootChunk = await tree.finalize();
|
|
73
|
+
await queue.enqueue(async () => uploadAndTrack(rootChunk));
|
|
64
74
|
resolve(rootChunk);
|
|
65
75
|
return;
|
|
66
76
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AsyncQueue,
|
|
1
|
+
import { AsyncQueue, Strings } from 'cafe-utility';
|
|
2
2
|
import { createReadStream } from 'fs';
|
|
3
3
|
import { NULL_ADDRESS } from "../index.js";
|
|
4
4
|
import { MantarayNode } from "../manifest/manifest.js";
|
|
5
5
|
import { totalChunks } from "./chunk-size.js";
|
|
6
6
|
import { makeCollectionFromFS } from "./collection.node.js";
|
|
7
7
|
import { mimes } from "./mime.js";
|
|
8
|
-
import { BatchId } from
|
|
8
|
+
import { BatchId, ChunkSplitter } from '@ethersphere/core-sdk';
|
|
9
9
|
export async function hashDirectory(dir) {
|
|
10
10
|
const files = await makeCollectionFromFS(dir);
|
|
11
11
|
const mantaray = new MantarayNode();
|
|
12
12
|
for (const file of files) {
|
|
13
|
-
const tree = new
|
|
13
|
+
const tree = new ChunkSplitter(ChunkSplitter.NOOP);
|
|
14
14
|
if (!file.fsPath) {
|
|
15
15
|
throw Error('File does not have fsPath, which should never happen in node. Please report this issue.');
|
|
16
16
|
}
|
|
@@ -40,26 +40,36 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
|
|
|
40
40
|
total += totalChunks(file.size);
|
|
41
41
|
}
|
|
42
42
|
let hasIndexHtml = false;
|
|
43
|
-
async function
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
processed: ++processed
|
|
49
|
-
});
|
|
43
|
+
async function uploadAndTrack(chunk) {
|
|
44
|
+
await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
|
|
45
|
+
onUploadProgress?.({
|
|
46
|
+
total,
|
|
47
|
+
processed: ++processed
|
|
50
48
|
});
|
|
51
49
|
}
|
|
50
|
+
async function onBatch(batch) {
|
|
51
|
+
for (const {
|
|
52
|
+
chunk
|
|
53
|
+
} of batch) {
|
|
54
|
+
await queue.enqueue(async () => uploadAndTrack(chunk));
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
52
58
|
const mantaray = new MantarayNode();
|
|
53
59
|
for (const file of files) {
|
|
54
60
|
if (!file.fsPath) {
|
|
55
61
|
throw Error('File does not have fsPath, which should never happen in node. Please report this issue.');
|
|
56
62
|
}
|
|
57
63
|
const readStream = createReadStream(file.fsPath);
|
|
58
|
-
const tree = new
|
|
64
|
+
const tree = new ChunkSplitter(onBatch);
|
|
59
65
|
for await (const data of readStream) {
|
|
60
66
|
await tree.append(data);
|
|
61
67
|
}
|
|
68
|
+
// ChunkSplitter's onBatch only sees chunks once they're referenced by a
|
|
69
|
+
// parent - the root chunk returned by finalize() is never passed to it,
|
|
70
|
+
// so it has to be uploaded here explicitly.
|
|
62
71
|
const rootChunk = await tree.finalize();
|
|
72
|
+
await queue.enqueue(async () => uploadAndTrack(rootChunk));
|
|
63
73
|
await queue.drain();
|
|
64
74
|
const {
|
|
65
75
|
filename,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BatchId, Topic } from
|
|
1
|
+
import { BatchId, Topic } from '@ethersphere/core-sdk';
|
|
2
2
|
export const SWARM_GATEWAY_URL = 'https://api.gateway.ethswarm.org';
|
|
3
3
|
export const NULL_STAMP = new BatchId('0000000000000000000000000000000000000000000000000000000000000000');
|
|
4
4
|
export const NULL_TOPIC = new Topic('0000000000000000000000000000000000000000000000000000000000000000');
|
package/dist/mjs/utils/expose.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getCollectionSize, makeCollectionFromFileList } from "./collection.js";
|
|
2
2
|
export { getFolderSize } from "./collection.node.js";
|
|
3
3
|
export { makeMaxTarget } from "./pss.js";
|
|
4
|
-
export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from
|
|
4
|
+
export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from '@ethersphere/core-sdk';
|
|
5
5
|
export { convertEnvelopeToMarshaledStamp, getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, mapPostageBatch, unmapPostageBatch } from "./stamps.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { BatchId, PublicKey, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { BeeError } from "./error.js";
|
|
3
4
|
import { convertEnvelopeToMarshaledStamp } from "./stamps.js";
|
|
4
|
-
import { BatchId, PublicKey, Reference } from "./typed-bytes.js";
|
|
5
5
|
export function readFileHeaders(headers) {
|
|
6
6
|
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
7
7
|
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -17,7 +17,12 @@ export const DEFAULT_HTTP_CONFIG = {
|
|
|
17
17
|
* @param config Internal settings and/or Bee settings
|
|
18
18
|
*/
|
|
19
19
|
export async function http(options, config) {
|
|
20
|
-
const
|
|
20
|
+
const rawData = config.data;
|
|
21
|
+
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, {
|
|
22
|
+
...config,
|
|
23
|
+
data: undefined
|
|
24
|
+
}, options);
|
|
25
|
+
requestConfig.data = rawData;
|
|
21
26
|
if (options.signal) {
|
|
22
27
|
requestConfig.signal = options.signal;
|
|
23
28
|
}
|
package/dist/mjs/utils/pss.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { PeerAddress } from '@ethersphere/core-sdk';
|
|
1
2
|
import { PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
2
|
-
import { PeerAddress } from "./typed-bytes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Utility function that for given strings/reference takes the most specific
|
|
5
5
|
* target that Bee node will except.
|
package/dist/mjs/utils/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { PublicKey, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { TAGS_LIMIT_MAX, TAGS_LIMIT_MIN } from "../types/index.js";
|
|
3
|
-
import { PublicKey, Reference } from "./typed-bytes.js";
|
|
4
4
|
export { HexStringSchema } from "./hex-schema.js";
|
|
5
5
|
const fnField = z.any().refine(v => z.function().safeParse(v).success, 'expected a function');
|
|
6
6
|
const integerStringField = z.any().transform(v => {
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -1,76 +1,10 @@
|
|
|
1
|
-
import { Binary } from 'cafe-utility';
|
|
2
|
-
import { capacityBreakpoints } from "../types/index.js";
|
|
3
|
-
import { Bytes, parseSizeToBytes } from "./bytes.js";
|
|
4
1
|
import { Duration } from "./duration.js";
|
|
5
2
|
import { Size } from "./size.js";
|
|
6
3
|
import { BZZ } from "./tokens.js";
|
|
7
4
|
import { asNumberString } from "./type.js";
|
|
8
|
-
import { BatchId } from "./typed-bytes.js";
|
|
9
5
|
import { normalizeBatchTTL } from "./workaround.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
13
|
-
*
|
|
14
|
-
* For smaller depths (up to 20), this may provide less accurate results.
|
|
15
|
-
*
|
|
16
|
-
* @returns {number} A number between 0 and 1 representing the usage of the postage batch.
|
|
17
|
-
*/
|
|
18
|
-
export function getStampUsage(utilization, depth, bucketDepth) {
|
|
19
|
-
return utilization / Math.pow(2, depth - bucketDepth);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
|
|
23
|
-
*
|
|
24
|
-
* For smaller depths (up to 22), this may provide less accurate results.
|
|
25
|
-
*
|
|
26
|
-
* @returns {number} The maximum theoretical size of the postage batch in bytes.
|
|
27
|
-
*/
|
|
28
|
-
export function getStampTheoreticalBytes(depth) {
|
|
29
|
-
return 4096 * 2 ** depth;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
33
|
-
* Optimised for encrypted, medium erasure coding
|
|
34
|
-
*/
|
|
35
|
-
const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
|
|
36
|
-
/**
|
|
37
|
-
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
38
|
-
*
|
|
39
|
-
* Below 22 depth the effective size is 0
|
|
40
|
-
* Above 34 it's always > 99%
|
|
41
|
-
*
|
|
42
|
-
* @returns {number} The effective size of the postage batch in bytes.
|
|
43
|
-
*/
|
|
44
|
-
export function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
|
|
45
|
-
if (depth < 17) {
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
if (encryption !== undefined && erasureCodeLevel !== undefined) {
|
|
49
|
-
const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
|
|
50
|
-
const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
|
|
51
|
-
const entry = breakpoints.find(item => item.batchDepth === depth);
|
|
52
|
-
if (entry?.effectiveVolume) {
|
|
53
|
-
return parseSizeToBytes(entry.effectiveVolume);
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
57
|
-
if (depth === d) {
|
|
58
|
-
return size;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
if (breakpoint) {
|
|
62
|
-
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
66
|
-
}
|
|
67
|
-
export function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
68
|
-
const map = new Map();
|
|
69
|
-
for (let i = 17; i < 35; i++) {
|
|
70
|
-
map.set(i, getStampEffectiveBytes(i, encryption, erasureCodeLevel));
|
|
71
|
-
}
|
|
72
|
-
return map;
|
|
73
|
-
}
|
|
6
|
+
import { BatchId, convertEnvelopeToMarshaledStamp as coreConvertEnvelopeToMarshaledStamp, getDepthForSize as coreGetDepthForSize, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, marshalStamp as coreMarshalStamp } from '@ethersphere/core-sdk';
|
|
7
|
+
export { getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage };
|
|
74
8
|
/**
|
|
75
9
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
76
10
|
*/
|
|
@@ -105,41 +39,13 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
|
105
39
|
* @returns
|
|
106
40
|
*/
|
|
107
41
|
export function getDepthForSize(size, encryption, erasureCodeLevel) {
|
|
108
|
-
|
|
109
|
-
const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
|
|
110
|
-
const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
|
|
111
|
-
const entry = breakpoints.find(item => {
|
|
112
|
-
return size.toBytes() <= parseSizeToBytes(item.effectiveVolume);
|
|
113
|
-
});
|
|
114
|
-
if (entry?.effectiveVolume) {
|
|
115
|
-
return entry.batchDepth;
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
119
|
-
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
120
|
-
return depth;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return 35;
|
|
42
|
+
return coreGetDepthForSize(size.toBytes(), encryption, erasureCodeLevel);
|
|
125
43
|
}
|
|
126
44
|
export function convertEnvelopeToMarshaledStamp(envelope) {
|
|
127
|
-
return
|
|
45
|
+
return coreConvertEnvelopeToMarshaledStamp(envelope);
|
|
128
46
|
}
|
|
129
47
|
export function marshalStamp(signature, batchId, timestamp, index) {
|
|
130
|
-
|
|
131
|
-
throw Error('invalid signature length');
|
|
132
|
-
}
|
|
133
|
-
if (batchId.length !== 32) {
|
|
134
|
-
throw Error('invalid batch ID length');
|
|
135
|
-
}
|
|
136
|
-
if (timestamp.length !== 8) {
|
|
137
|
-
throw Error('invalid timestamp length');
|
|
138
|
-
}
|
|
139
|
-
if (index.length !== 8) {
|
|
140
|
-
throw Error('invalid index length');
|
|
141
|
-
}
|
|
142
|
-
return new Bytes(Binary.concatBytes(batchId, index, timestamp, signature));
|
|
48
|
+
return coreMarshalStamp(signature, batchId, timestamp, index);
|
|
143
49
|
}
|
|
144
50
|
export function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
145
51
|
const batchTTL = normalizeBatchTTL(raw.batchTTL);
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -28,8 +28,8 @@ export function isTag(value) {
|
|
|
28
28
|
* @throws TypeError if not valid
|
|
29
29
|
*/
|
|
30
30
|
export function assertData(value) {
|
|
31
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
32
|
-
throw new TypeError('Data must be either string or
|
|
31
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(value instanceof Blob) && !isReadable(value)) {
|
|
32
|
+
throw new TypeError('Data must be either string, Uint8Array, Blob or Readable!');
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { BatchId, Bytes, Reference } from '@ethersphere/core-sdk';
|
|
2
|
+
import { Readable } from 'stream';
|
|
1
3
|
import type { BeeRequestOptions, DownloadOptions, RedundantUploadOptions, ReferenceInformation } from '../types';
|
|
2
4
|
import { UploadResult } from '../types';
|
|
3
|
-
import { Bytes } from '../utils/bytes';
|
|
4
5
|
import { ResourceLocator } from '../utils/resource-locator';
|
|
5
|
-
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
6
6
|
/**
|
|
7
7
|
* Raw HTTP calls for the `/bytes` endpoint.
|
|
8
8
|
*/
|
|
9
|
-
export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array, postageBatchId: BatchId, options?: RedundantUploadOptions): Promise<UploadResult>;
|
|
9
|
+
export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array | Blob | Readable, postageBatchId: BatchId, options?: RedundantUploadOptions): Promise<UploadResult>;
|
|
10
10
|
export declare function head(requestOptions: BeeRequestOptions, reference: Reference): Promise<ReferenceInformation>;
|
|
11
11
|
export declare function download(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<Bytes>;
|
|
12
12
|
export declare function downloadReadable(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<ReadableStream<Uint8Array>>;
|
package/dist/types/api/bzz.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { BatchId, Bytes, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import { Readable } from 'stream';
|
|
2
3
|
import { BeeRequestOptions, Collection, CollectionUploadOptions, DownloadOptions, FileData, FileUploadOptions, UploadResult } from '../types';
|
|
3
|
-
import { Bytes } from '../utils/bytes';
|
|
4
4
|
import { ResourceLocator } from '../utils/resource-locator';
|
|
5
|
-
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
6
5
|
/**
|
|
7
6
|
* Raw HTTP calls for the `/bzz` endpoint.
|
|
8
7
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { PeerAddress, TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, ChequebookAddressResponse, ChequebookBalanceResponse, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, TransactionOptions } from '../types';
|
|
2
|
-
import { PeerAddress, TransactionId } from '../utils/typed-bytes';
|
|
3
3
|
/**
|
|
4
4
|
* Raw HTTP calls for the `/chequebook` endpoint (chequebook + cheque operations).
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BatchId, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, DownloadOptions, EnvelopeWithBatchId, UploadOptions, UploadResult } from '../types';
|
|
2
|
-
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
3
3
|
/**
|
|
4
4
|
* Raw HTTP calls for the `/chunks` endpoint.
|
|
5
5
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { PeerAddress } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, Peer, PingResponse, RemovePeerResponse, Topology } from '../types';
|
|
2
3
|
import { NodeAddresses } from '../types/debug';
|
|
3
|
-
import { PeerAddress } from '../utils/typed-bytes';
|
|
4
4
|
/**
|
|
5
5
|
* Raw HTTP calls for the connectivity endpoints (`/addresses`, `/peers`, `/topology`, `/blocklist`, `/pingpong`, etc.).
|
|
6
6
|
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import { BatchId, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, EnvelopeWithBatchId } from '../types';
|
|
2
|
-
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
3
3
|
export declare function postEnvelope(requestOptions: BeeRequestOptions, postageBatchId: BatchId, reference: Reference): Promise<EnvelopeWithBatchId>;
|
package/dist/types/api/feed.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { BatchId, Bytes, EthAddress, FeedIndex, Reference, Topic } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, UploadOptions } from '../types';
|
|
2
|
-
import { Bytes } from '../utils/bytes';
|
|
3
|
-
import { BatchId, EthAddress, FeedIndex, Reference, Topic } from '../utils/typed-bytes';
|
|
4
3
|
/**
|
|
5
4
|
* Raw HTTP calls for the `/feeds` endpoint.
|
|
6
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BatchId, PublicKey, Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, GetGranteesResult, GranteesResult } from '../types';
|
|
2
|
-
import { BatchId, PublicKey, Reference } from '../utils/typed-bytes';
|
|
3
3
|
/** Creates grantees for a postage batch. */
|
|
4
4
|
export declare function createGrantees(requestOptions: BeeRequestOptions, batchId: BatchId, publicKeys: PublicKey[]): Promise<GranteesResult>;
|
|
5
5
|
/** Retrieves the grantees for a given reference. */
|
package/dist/types/api/pin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Reference } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, Pin as PinData } from '../types';
|
|
2
|
-
import { Reference } from '../utils/typed-bytes';
|
|
3
3
|
/** Pins local data with the given reference. */
|
|
4
4
|
export declare function pin(requestOptions: BeeRequestOptions, reference: Reference): Promise<void>;
|
|
5
5
|
/** Unpins local data with the given reference. */
|
package/dist/types/api/pss.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BatchId, PublicKey, Topic } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions } from '../types';
|
|
2
|
-
import { BatchId, PublicKey, Topic } from '../utils/typed-bytes';
|
|
3
3
|
/**
|
|
4
4
|
* Sends a message with the Postal Service for Swarm through the `POST /pss/send` endpoint.
|
|
5
5
|
*/
|
package/dist/types/api/soc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BatchId, EthAddress, Identifier, Signature } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
|
|
2
|
-
import { BatchId, EthAddress, Identifier, Signature } from '../utils/typed-bytes';
|
|
3
3
|
/**
|
|
4
4
|
* Raw HTTP calls for the `/soc` endpoint.
|
|
5
5
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { TransactionId } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, TransactionOptions } from '../types';
|
|
2
3
|
import { BZZ } from '../utils/tokens';
|
|
3
|
-
import { TransactionId } from '../utils/typed-bytes';
|
|
4
4
|
/**
|
|
5
5
|
* Raw HTTP calls for the `/stake` endpoint.
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BatchId } from '@ethersphere/core-sdk';
|
|
1
2
|
import type { BeeRequestOptions, NumberString, PostageBatch, PostageBatchBuckets, RedundancyLevel } from '../types';
|
|
2
|
-
import { BatchId } from '../utils/typed-bytes';
|
|
3
3
|
/**
|
|
4
4
|
* Raw HTTP calls for the `/stamps` endpoint.
|
|
5
5
|
*/
|