@upcoming/bee-js 12.0.0 → 12.2.3
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/cjs/bee.js +11 -6
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/modules/feed.js +1 -1
- package/dist/cjs/modules/status.js +1 -0
- package/dist/cjs/utils/http.js +92 -52
- package/dist/cjs/utils/tar.browser.js +55 -7
- package/dist/cjs/utils/tar.js +48 -7
- package/dist/cjs/utils/tokens.js +12 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +12 -7
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/feed.js +3 -1
- package/dist/mjs/modules/status.js +2 -1
- package/dist/mjs/utils/http.js +97 -59
- package/dist/mjs/utils/tar.browser.js +66 -8
- package/dist/mjs/utils/tar.js +59 -8
- package/dist/mjs/utils/tokens.js +12 -0
- package/dist/types/bee.d.ts +3 -3
- package/dist/types/index.d.ts +1 -3
- package/dist/types/utils/http.d.ts +18 -3
- 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/tokens.d.ts +4 -0
- package/package.json +10 -7
- package/dist/cjs/bee-dev.js +0 -78
- package/dist/mjs/bee-dev.js +0 -98
- package/dist/types/bee-dev.d.ts +0 -5
package/dist/mjs/bee.js
CHANGED
|
@@ -284,8 +284,8 @@ export class Bee {
|
|
|
284
284
|
const fileName = name ?? data.name;
|
|
285
285
|
const contentType = data.type;
|
|
286
286
|
const fileOptions = {
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
...options,
|
|
288
|
+
contentType
|
|
289
289
|
};
|
|
290
290
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
291
291
|
} else {
|
|
@@ -1602,10 +1602,16 @@ export class Bee {
|
|
|
1602
1602
|
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
|
|
1603
1603
|
const targetAmount = duration.isZero() ? currentAmount * multiplier : (currentAmount + additionalAmount) * multiplier;
|
|
1604
1604
|
const amountDelta = targetAmount - currentAmount;
|
|
1605
|
-
|
|
1605
|
+
let transactionId;
|
|
1606
|
+
if (amountDelta > 0n) {
|
|
1607
|
+
transactionId = await this.topUpBatch(batch.batchID, amountDelta, requestOptions);
|
|
1608
|
+
}
|
|
1606
1609
|
if (depthDelta > 0) {
|
|
1607
1610
|
return this.diluteBatch(batch.batchID, depth, requestOptions);
|
|
1608
1611
|
}
|
|
1612
|
+
if (!transactionId) {
|
|
1613
|
+
throw new Error('Nothing to extend, both size and duration are already sufficient');
|
|
1614
|
+
}
|
|
1609
1615
|
return transactionId;
|
|
1610
1616
|
}
|
|
1611
1617
|
/**
|
|
@@ -1733,16 +1739,15 @@ export class Bee {
|
|
|
1733
1739
|
/**
|
|
1734
1740
|
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1735
1741
|
*
|
|
1736
|
-
* @param
|
|
1742
|
+
* @param depth Depth of the postage batch to top up.
|
|
1737
1743
|
* @param bzz The amount of BZZ to spend on the top-up.
|
|
1738
1744
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1739
1745
|
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
|
|
1740
1746
|
*/
|
|
1741
|
-
async calculateTopUpForBzz(
|
|
1742
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1747
|
+
async calculateTopUpForBzz(depth, bzz, requestOptions) {
|
|
1743
1748
|
const chainState = await this.getChainState(requestOptions);
|
|
1744
1749
|
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1745
|
-
const amount = bzz.toPLURBigInt() / 2n ** BigInt(
|
|
1750
|
+
const amount = bzz.toPLURBigInt() / 2n ** BigInt(depth);
|
|
1746
1751
|
const duration = getStampDuration(amount, chainState.currentPrice, blockTime);
|
|
1747
1752
|
return {
|
|
1748
1753
|
amount,
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Bee } from "./bee.js";
|
|
2
|
-
import { BeeDev } from "./bee-dev.js";
|
|
3
2
|
import { Stamper } from "./stamper/stamper.js";
|
|
4
3
|
export { MerkleTree } from 'cafe-utility';
|
|
5
4
|
export { MantarayNode } from "./manifest/manifest.js";
|
|
@@ -13,4 +12,4 @@ export * as Utils from "./utils/expose.js";
|
|
|
13
12
|
export { Size } from "./utils/size.js";
|
|
14
13
|
export * from "./utils/tokens.js";
|
|
15
14
|
export * from "./utils/typed-bytes.js";
|
|
16
|
-
export { Bee,
|
|
15
|
+
export { Bee, Stamper };
|
package/dist/mjs/modules/feed.js
CHANGED
|
@@ -57,7 +57,9 @@ export async function fetchLatestFeedUpdate(requestOptions, owner, topic, option
|
|
|
57
57
|
const response = await http(requestOptions, {
|
|
58
58
|
responseType: 'arraybuffer',
|
|
59
59
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
60
|
-
params:
|
|
60
|
+
params: {
|
|
61
|
+
...options
|
|
62
|
+
}
|
|
61
63
|
});
|
|
62
64
|
return {
|
|
63
65
|
payload: new Bytes(response.data),
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Dates, Objects, Strings, System } from 'cafe-utility';
|
|
1
|
+
import { Objects, Strings, System } from 'cafe-utility';
|
|
3
2
|
import _debug from 'debug';
|
|
4
3
|
import { BeeResponseError } from "../index.js";
|
|
5
4
|
const debug = _debug('bee-js:http');
|
|
6
|
-
const {
|
|
7
|
-
AxiosError
|
|
8
|
-
} = axios;
|
|
9
5
|
const MAX_FAILED_ATTEMPTS = 100000;
|
|
10
6
|
const DELAY_FAST = 200;
|
|
11
7
|
const DELAY_SLOW = 1000;
|
|
12
|
-
const
|
|
13
|
-
const ABORT_ERROR_MESSAGE = 'Request aborted';
|
|
8
|
+
const FAST_RETRY_COUNT = 300;
|
|
14
9
|
export const DEFAULT_HTTP_CONFIG = {
|
|
15
10
|
headers: {
|
|
16
11
|
accept: 'application/json, text/plain, */*'
|
|
17
|
-
},
|
|
18
|
-
maxBodyLength: Infinity,
|
|
19
|
-
maxContentLength: Infinity
|
|
20
|
-
};
|
|
21
|
-
function throwIfAborted(signal, config, responseData, responseStatus) {
|
|
22
|
-
if (signal?.aborted) {
|
|
23
|
-
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', ABORT_ERROR_MESSAGE, responseData, responseStatus, 'ERR_CANCELED');
|
|
24
12
|
}
|
|
25
|
-
}
|
|
13
|
+
};
|
|
26
14
|
/**
|
|
27
15
|
* Main function to make HTTP requests.
|
|
28
16
|
* @param options User defined settings
|
|
@@ -32,68 +20,118 @@ export async function http(options, config) {
|
|
|
32
20
|
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
33
21
|
if (options.signal) {
|
|
34
22
|
requestConfig.signal = options.signal;
|
|
35
|
-
throwIfAborted(options.signal, config);
|
|
36
23
|
}
|
|
37
|
-
|
|
24
|
+
attachBody(requestConfig);
|
|
38
25
|
if (requestConfig.params) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const value = requestConfig.params[key];
|
|
42
|
-
if (value === undefined) {
|
|
43
|
-
delete requestConfig.params[key];
|
|
44
|
-
}
|
|
26
|
+
for (const k of Object.keys(requestConfig.params)) {
|
|
27
|
+
if (requestConfig.params[k] === undefined) delete requestConfig.params[k];
|
|
45
28
|
}
|
|
46
29
|
}
|
|
30
|
+
const url = buildUrl(requestConfig);
|
|
31
|
+
const method = (requestConfig.method || 'GET').toUpperCase();
|
|
32
|
+
requestConfig.method = method;
|
|
33
|
+
options.onRequest?.({
|
|
34
|
+
method,
|
|
35
|
+
url,
|
|
36
|
+
headers: {
|
|
37
|
+
...requestConfig.headers
|
|
38
|
+
},
|
|
39
|
+
params: requestConfig.params
|
|
40
|
+
});
|
|
47
41
|
let failedAttempts = 0;
|
|
48
42
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
49
|
-
throwIfAborted(options.signal, config);
|
|
50
43
|
try {
|
|
51
|
-
debug(`${
|
|
52
|
-
headers:
|
|
53
|
-
...requestConfig.headers
|
|
54
|
-
},
|
|
44
|
+
debug(`${method} ${url}`, {
|
|
45
|
+
headers: requestConfig.headers,
|
|
55
46
|
params: requestConfig.params
|
|
56
47
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
48
|
+
const res = await fetch(url, requestConfig);
|
|
49
|
+
if (!res.ok) await throwHttpError(method, url, res, requestConfig.responseType);
|
|
50
|
+
return toBeeResponse(res, requestConfig.responseType);
|
|
60
51
|
} catch (e) {
|
|
61
|
-
if (e instanceof
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
if (e.code === 'ECONNABORTED' && options.endlesslyRetry) {
|
|
68
|
-
failedAttempts++;
|
|
69
|
-
await System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
|
|
70
|
-
} else {
|
|
71
|
-
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.response?.statusText);
|
|
72
|
-
}
|
|
52
|
+
if (e instanceof BeeResponseError) throw e;
|
|
53
|
+
const err = e;
|
|
54
|
+
if (err.name === 'TimeoutError' && options.endlesslyRetry) {
|
|
55
|
+
failedAttempts++;
|
|
56
|
+
await System.sleepMillis(failedAttempts < FAST_RETRY_COUNT ? DELAY_FAST : DELAY_SLOW);
|
|
73
57
|
} else {
|
|
74
|
-
throw
|
|
58
|
+
throw toBeeError(err, method, url);
|
|
75
59
|
}
|
|
76
60
|
}
|
|
77
61
|
}
|
|
78
62
|
throw Error('Max number of failed attempts reached');
|
|
79
63
|
}
|
|
80
|
-
function
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
64
|
+
function attachBody(config) {
|
|
65
|
+
if (config.data === undefined) return;
|
|
66
|
+
const data = config.data;
|
|
67
|
+
const isJsonShape = data !== null && typeof data === 'object' && data.constructor === Object || Array.isArray(data);
|
|
68
|
+
if (isJsonShape) {
|
|
69
|
+
config.body = JSON.stringify(data);
|
|
70
|
+
config.headers = {
|
|
71
|
+
'content-type': 'application/json',
|
|
72
|
+
...config.headers
|
|
73
|
+
};
|
|
74
|
+
} else {
|
|
75
|
+
config.body = data;
|
|
76
|
+
config.duplex = 'half';
|
|
77
|
+
const ct = data instanceof Blob && data.type ? data.type : 'application/octet-stream';
|
|
78
|
+
config.headers = {
|
|
79
|
+
'content-type': ct,
|
|
80
|
+
...config.headers
|
|
81
|
+
};
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
async function throwHttpError(method, url, res, responseType) {
|
|
85
|
+
const errBody = await toBeeResponse(res, responseType).catch(() => ({
|
|
86
|
+
data: undefined
|
|
87
|
+
}));
|
|
88
|
+
const bodyMsg = typeof errBody.data === 'string' ? errBody.data : JSON.stringify(errBody.data);
|
|
89
|
+
const message = bodyMsg && bodyMsg !== 'undefined' ? `${res.statusText}: ${bodyMsg}` : res.statusText;
|
|
90
|
+
throw new BeeResponseError(method, url, message, errBody.data, res.status, res.statusText);
|
|
91
|
+
}
|
|
92
|
+
function toBeeError(err, method, url) {
|
|
93
|
+
if (err.name === 'AbortError') {
|
|
94
|
+
return new BeeResponseError(method, url, 'Request aborted', undefined, undefined, 'ERR_CANCELED');
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const cause = err.cause;
|
|
97
|
+
const message = cause?.message ? `${err.message}: ${cause.message}` : err.message;
|
|
98
|
+
return new BeeResponseError(method, url, message);
|
|
99
|
+
}
|
|
100
|
+
export async function toBeeResponse(res, responseType = 'json') {
|
|
101
|
+
let data;
|
|
102
|
+
switch (responseType) {
|
|
103
|
+
case 'arraybuffer':
|
|
104
|
+
data = await res.arrayBuffer();
|
|
105
|
+
break;
|
|
106
|
+
case 'text':
|
|
107
|
+
data = await res.text();
|
|
108
|
+
break;
|
|
109
|
+
case 'blob':
|
|
110
|
+
data = await res.blob();
|
|
111
|
+
break;
|
|
112
|
+
case 'stream':
|
|
113
|
+
data = res.body;
|
|
114
|
+
break;
|
|
115
|
+
case 'json':
|
|
116
|
+
default:
|
|
117
|
+
{
|
|
118
|
+
const text = await res.text();
|
|
119
|
+
data = text ? JSON.parse(text) : null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
data: data,
|
|
124
|
+
status: res.status,
|
|
125
|
+
statusText: res.statusText,
|
|
126
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
127
|
+
raw: res
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function buildUrl(config) {
|
|
131
|
+
let url = Strings.joinUrl([config.baseURL ?? '', config.url ?? '']);
|
|
132
|
+
if (config.params) {
|
|
133
|
+
const qs = new URLSearchParams(Object.entries(config.params).filter(([, v]) => v !== undefined).map(([k, v]) => [k, String(v)])).toString();
|
|
134
|
+
if (qs) url += `?${qs}`;
|
|
98
135
|
}
|
|
136
|
+
return url;
|
|
99
137
|
}
|
|
@@ -12,10 +12,20 @@ export class TarStream {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
beginFile(path, size) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const {
|
|
16
|
+
name,
|
|
17
|
+
prefix,
|
|
18
|
+
longLink
|
|
19
|
+
} = splitPath(path);
|
|
20
|
+
if (longLink) {
|
|
21
|
+
const encoder = new TextEncoder();
|
|
22
|
+
const pathData = encoder.encode(path + '\0');
|
|
23
|
+
this.pieces.push(createLongLinkHeader(pathData.length));
|
|
24
|
+
this.pieces.push(pathData);
|
|
25
|
+
const padding = pathData.length % 512 === 0 ? 0 : 512 - pathData.length % 512;
|
|
26
|
+
if (padding > 0) this.pieces.push(new Uint8Array(padding));
|
|
17
27
|
}
|
|
18
|
-
const header = createHeader(
|
|
28
|
+
const header = createHeader(name, prefix, size);
|
|
19
29
|
this.pieces.push(header);
|
|
20
30
|
this.currentFileSize = 0;
|
|
21
31
|
}
|
|
@@ -33,7 +43,55 @@ export class TarStream {
|
|
|
33
43
|
this.pieces.push(createEndOfArchive());
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
|
-
function
|
|
46
|
+
function splitPath(path) {
|
|
47
|
+
if (path.length <= 100) return {
|
|
48
|
+
name: path,
|
|
49
|
+
prefix: '',
|
|
50
|
+
longLink: false
|
|
51
|
+
};
|
|
52
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
53
|
+
if (path[i] === '/') {
|
|
54
|
+
const name = path.substring(i + 1);
|
|
55
|
+
const prefix = path.substring(0, i);
|
|
56
|
+
if (name.length <= 100 && prefix.length <= 155) return {
|
|
57
|
+
name,
|
|
58
|
+
prefix,
|
|
59
|
+
longLink: false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Filename itself is > 100 chars or path > 255 chars — use GNU LongLink
|
|
64
|
+
const lastSlash = path.lastIndexOf('/');
|
|
65
|
+
const truncatedName = (lastSlash >= 0 ? path.substring(lastSlash + 1) : path).slice(0, 100);
|
|
66
|
+
return {
|
|
67
|
+
name: truncatedName,
|
|
68
|
+
prefix: '',
|
|
69
|
+
longLink: true
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function createLongLinkHeader(size) {
|
|
73
|
+
const encoder = new TextEncoder();
|
|
74
|
+
function writeToBuffer(str, offset, length) {
|
|
75
|
+
const bytes = encoder.encode(str);
|
|
76
|
+
header.set(bytes.slice(0, length), offset);
|
|
77
|
+
}
|
|
78
|
+
const header = new Uint8Array(512);
|
|
79
|
+
header.fill(0);
|
|
80
|
+
writeToBuffer('././@LongLink', 0, 100);
|
|
81
|
+
writeToBuffer('0000644\0', 100, 8);
|
|
82
|
+
writeToBuffer('0000000\0', 108, 8);
|
|
83
|
+
writeToBuffer('0000000\0', 116, 8);
|
|
84
|
+
writeToBuffer(size.toString(8).padStart(11, '0') + '\0', 124, 12);
|
|
85
|
+
writeToBuffer('00000000000\0', 136, 12);
|
|
86
|
+
writeToBuffer(' ', 148, 8);
|
|
87
|
+
writeToBuffer('L', 156, 1);
|
|
88
|
+
writeToBuffer('ustar\0\0', 257, 8);
|
|
89
|
+
let checksum = 0;
|
|
90
|
+
for (let i = 0; i < 512; i++) checksum += header[i];
|
|
91
|
+
writeToBuffer(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8);
|
|
92
|
+
return header;
|
|
93
|
+
}
|
|
94
|
+
function createHeader(name, prefix, size) {
|
|
37
95
|
const encoder = new TextEncoder();
|
|
38
96
|
function writeToBuffer(str, offset, length) {
|
|
39
97
|
const bytes = encoder.encode(str);
|
|
@@ -43,7 +101,7 @@ function createHeader(path, size) {
|
|
|
43
101
|
const header = new Uint8Array(512);
|
|
44
102
|
header.fill(0, 0, 512);
|
|
45
103
|
// File name, truncated to 100 characters if necessary
|
|
46
|
-
writeToBuffer(
|
|
104
|
+
writeToBuffer(name.slice(0, 100).padEnd(100, '\0'), 0, 100);
|
|
47
105
|
// File mode (octal) and null-terminated
|
|
48
106
|
writeToBuffer('0000777\0', 100, 8);
|
|
49
107
|
// UID and GID (octal) and null-terminated
|
|
@@ -60,11 +118,11 @@ function createHeader(path, size) {
|
|
|
60
118
|
writeToBuffer('0', 156, 1);
|
|
61
119
|
// USTAR magic and version
|
|
62
120
|
writeToBuffer('ustar\0\0', 257, 8);
|
|
121
|
+
// UStar prefix field (offset 345, 155 bytes) — used when path > 100 but fits split
|
|
122
|
+
if (prefix) writeToBuffer(prefix.slice(0, 155).padEnd(155, '\0'), 345, 155);
|
|
63
123
|
// Calculate checksum
|
|
64
124
|
let checksum = 0;
|
|
65
|
-
for (let i = 0; i < 512; i++)
|
|
66
|
-
checksum += header[i];
|
|
67
|
-
}
|
|
125
|
+
for (let i = 0; i < 512; i++) checksum += header[i];
|
|
68
126
|
writeToBuffer(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8);
|
|
69
127
|
return header;
|
|
70
128
|
}
|
package/dist/mjs/utils/tar.js
CHANGED
|
@@ -5,10 +5,19 @@ export class TarStream {
|
|
|
5
5
|
this.currentFileSize = 0;
|
|
6
6
|
}
|
|
7
7
|
beginFile(path, size) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const {
|
|
9
|
+
name,
|
|
10
|
+
prefix,
|
|
11
|
+
longLink
|
|
12
|
+
} = splitPath(path);
|
|
13
|
+
if (longLink) {
|
|
14
|
+
const pathData = Buffer.from(path + '\0');
|
|
15
|
+
this.output.write(createLongLinkHeader(pathData.length));
|
|
16
|
+
this.output.write(pathData);
|
|
17
|
+
const padding = pathData.length % 512 === 0 ? 0 : 512 - pathData.length % 512;
|
|
18
|
+
if (padding > 0) this.output.write(Buffer.alloc(padding, 0));
|
|
10
19
|
}
|
|
11
|
-
const header = createHeader(
|
|
20
|
+
const header = createHeader(name, prefix, size);
|
|
12
21
|
this.output.write(header);
|
|
13
22
|
this.currentFileSize = 0;
|
|
14
23
|
}
|
|
@@ -39,11 +48,53 @@ export class TarStream {
|
|
|
39
48
|
});
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
|
-
function
|
|
51
|
+
function splitPath(path) {
|
|
52
|
+
if (path.length <= 100) return {
|
|
53
|
+
name: path,
|
|
54
|
+
prefix: '',
|
|
55
|
+
longLink: false
|
|
56
|
+
};
|
|
57
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
58
|
+
if (path[i] === '/') {
|
|
59
|
+
const name = path.substring(i + 1);
|
|
60
|
+
const prefix = path.substring(0, i);
|
|
61
|
+
if (name.length <= 100 && prefix.length <= 155) return {
|
|
62
|
+
name,
|
|
63
|
+
prefix,
|
|
64
|
+
longLink: false
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Filename itself is > 100 chars or path > 255 chars — use GNU LongLink
|
|
69
|
+
const lastSlash = path.lastIndexOf('/');
|
|
70
|
+
const truncatedName = (lastSlash >= 0 ? path.substring(lastSlash + 1) : path).slice(0, 100);
|
|
71
|
+
return {
|
|
72
|
+
name: truncatedName,
|
|
73
|
+
prefix: '',
|
|
74
|
+
longLink: true
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createLongLinkHeader(size) {
|
|
78
|
+
const header = Buffer.alloc(512, 0);
|
|
79
|
+
header.write('././@LongLink', 0, 100);
|
|
80
|
+
header.write('0000644\0', 100, 8);
|
|
81
|
+
header.write('0000000\0', 108, 8);
|
|
82
|
+
header.write('0000000\0', 116, 8);
|
|
83
|
+
header.write(size.toString(8).padStart(11, '0') + '\0', 124, 12);
|
|
84
|
+
header.write('00000000000\0', 136, 12);
|
|
85
|
+
header.write(' ', 148, 8);
|
|
86
|
+
header.write('L', 156, 1);
|
|
87
|
+
header.write('ustar\0\0', 257, 8);
|
|
88
|
+
let checksum = 0;
|
|
89
|
+
for (let i = 0; i < 512; i++) checksum += header[i];
|
|
90
|
+
header.write(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8);
|
|
91
|
+
return header;
|
|
92
|
+
}
|
|
93
|
+
function createHeader(name, prefix, size) {
|
|
43
94
|
// Initialize header with zeros
|
|
44
95
|
const header = Buffer.alloc(512, 0);
|
|
45
96
|
// File name, truncated to 100 characters if necessary
|
|
46
|
-
header.write(
|
|
97
|
+
header.write(name.slice(0, 100).padEnd(100, '\0'), 0, 100);
|
|
47
98
|
// File mode (octal) and null-terminated
|
|
48
99
|
header.write('0000777\0', 100, 8);
|
|
49
100
|
// UID and GID (octal) and null-terminated
|
|
@@ -60,11 +111,11 @@ function createHeader(path, size) {
|
|
|
60
111
|
header.write('0', 156, 1);
|
|
61
112
|
// USTAR magic and version
|
|
62
113
|
header.write('ustar\0\0', 257, 8);
|
|
114
|
+
// UStar prefix field (offset 345, 155 bytes) — used when path > 100 but fits split
|
|
115
|
+
if (prefix) header.write(prefix.slice(0, 155).padEnd(155, '\0'), 345, 155);
|
|
63
116
|
// Calculate checksum
|
|
64
117
|
let checksum = 0;
|
|
65
|
-
for (let i = 0; i < 512; i++)
|
|
66
|
-
checksum += header[i];
|
|
67
|
-
}
|
|
118
|
+
for (let i = 0; i < 512; i++) checksum += header[i];
|
|
68
119
|
header.write(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8);
|
|
69
120
|
return header;
|
|
70
121
|
}
|
package/dist/mjs/utils/tokens.js
CHANGED
|
@@ -9,6 +9,9 @@ export class BZZ {
|
|
|
9
9
|
static fromPLUR(plur) {
|
|
10
10
|
return new BZZ(new FixedPointNumber(plur, BZZ.DIGITS));
|
|
11
11
|
}
|
|
12
|
+
static fromFloat(float) {
|
|
13
|
+
return new BZZ(FixedPointNumber.fromFloat(float, BZZ.DIGITS));
|
|
14
|
+
}
|
|
12
15
|
toPLURString() {
|
|
13
16
|
return this.state.toString();
|
|
14
17
|
}
|
|
@@ -18,6 +21,9 @@ export class BZZ {
|
|
|
18
21
|
toDecimalString() {
|
|
19
22
|
return this.state.toDecimalString();
|
|
20
23
|
}
|
|
24
|
+
toFloat() {
|
|
25
|
+
return this.state.toFloat();
|
|
26
|
+
}
|
|
21
27
|
toSignificantDigits(digits) {
|
|
22
28
|
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
|
|
23
29
|
}
|
|
@@ -78,6 +84,9 @@ export class DAI {
|
|
|
78
84
|
static fromWei(wei) {
|
|
79
85
|
return new DAI(new FixedPointNumber(wei, DAI.DIGITS));
|
|
80
86
|
}
|
|
87
|
+
static fromFloat(float) {
|
|
88
|
+
return new DAI(FixedPointNumber.fromFloat(float, DAI.DIGITS));
|
|
89
|
+
}
|
|
81
90
|
toWeiString() {
|
|
82
91
|
return this.state.toString();
|
|
83
92
|
}
|
|
@@ -90,6 +99,9 @@ export class DAI {
|
|
|
90
99
|
toSignificantDigits(digits) {
|
|
91
100
|
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
|
|
92
101
|
}
|
|
102
|
+
toFloat() {
|
|
103
|
+
return this.state.toFloat();
|
|
104
|
+
}
|
|
93
105
|
/**
|
|
94
106
|
* Does not mutate the current DAI instance.
|
|
95
107
|
*
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -1074,7 +1074,7 @@ export declare class Bee {
|
|
|
1074
1074
|
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1075
1075
|
* @returns
|
|
1076
1076
|
*/
|
|
1077
|
-
extendStorage(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
|
|
1077
|
+
extendStorage(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<TransactionId | BatchId>;
|
|
1078
1078
|
/**
|
|
1079
1079
|
* Extends the storage size of a postage batch by increasing its depth.
|
|
1080
1080
|
*
|
|
@@ -1157,12 +1157,12 @@ export declare class Bee {
|
|
|
1157
1157
|
/**
|
|
1158
1158
|
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1159
1159
|
*
|
|
1160
|
-
* @param
|
|
1160
|
+
* @param depth Depth of the postage batch to top up.
|
|
1161
1161
|
* @param bzz The amount of BZZ to spend on the top-up.
|
|
1162
1162
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1163
1163
|
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
|
|
1164
1164
|
*/
|
|
1165
|
-
calculateTopUpForBzz(
|
|
1165
|
+
calculateTopUpForBzz(depth: number, bzz: BZZ, requestOptions?: BeeRequestOptions): Promise<{
|
|
1166
1166
|
amount: bigint;
|
|
1167
1167
|
duration: Duration;
|
|
1168
1168
|
}>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Bee } from './bee';
|
|
2
|
-
import { BeeDev } from './bee-dev';
|
|
3
2
|
import { Stamper } from './stamper/stamper';
|
|
4
3
|
export { MerkleTree } from 'cafe-utility';
|
|
5
4
|
export type { Chunk } from './chunk/cac';
|
|
@@ -16,12 +15,11 @@ export { Size } from './utils/size';
|
|
|
16
15
|
export * from './utils/tokens';
|
|
17
16
|
export * from './utils/typed-bytes';
|
|
18
17
|
export type { UploadProgress } from './utils/upload-progress';
|
|
19
|
-
export { Bee,
|
|
18
|
+
export { Bee, Stamper };
|
|
20
19
|
declare global {
|
|
21
20
|
interface Window {
|
|
22
21
|
BeeJs: {
|
|
23
22
|
Bee: typeof import('./bee').Bee;
|
|
24
|
-
BeeDev: typeof import('./bee-dev').BeeDev;
|
|
25
23
|
Stamper: typeof import('./stamper/stamper').Stamper;
|
|
26
24
|
Utils: typeof import('./utils/expose');
|
|
27
25
|
Duration: typeof import('./utils/duration').Duration;
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
1
|
import { BeeRequestOptions } from '../index';
|
|
3
|
-
export declare const DEFAULT_HTTP_CONFIG:
|
|
2
|
+
export declare const DEFAULT_HTTP_CONFIG: BeeRequestConfig;
|
|
3
|
+
export type BeeResponseType = 'json' | 'arraybuffer' | 'text' | 'blob' | 'stream';
|
|
4
|
+
export interface BeeResponse<T> {
|
|
5
|
+
data: T;
|
|
6
|
+
status: number;
|
|
7
|
+
statusText: string;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
raw: Response;
|
|
10
|
+
}
|
|
11
|
+
export interface BeeRequestConfig extends RequestInit {
|
|
12
|
+
url?: string;
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
params?: Record<string, unknown>;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
responseType?: BeeResponseType;
|
|
17
|
+
}
|
|
4
18
|
/**
|
|
5
19
|
* Main function to make HTTP requests.
|
|
6
20
|
* @param options User defined settings
|
|
7
21
|
* @param config Internal settings and/or Bee settings
|
|
8
22
|
*/
|
|
9
|
-
export declare function http<T>(options: BeeRequestOptions, config:
|
|
23
|
+
export declare function http<T>(options: BeeRequestOptions, config: BeeRequestConfig): Promise<BeeResponse<T>>;
|
|
24
|
+
export declare function toBeeResponse<T>(res: Response, responseType?: BeeResponseType): Promise<BeeResponse<T>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
|
|
2
2
|
import { BatchId } from './typed-bytes';
|
|
3
|
-
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("
|
|
3
|
+
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("./http").BeeResponse<unknown>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
|
|
2
2
|
import { BatchId } from './typed-bytes';
|
|
3
|
-
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("
|
|
3
|
+
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("./http").BeeResponse<unknown>>;
|
|
@@ -5,9 +5,11 @@ export declare class BZZ {
|
|
|
5
5
|
private constructor();
|
|
6
6
|
static fromDecimalString(string: string): BZZ;
|
|
7
7
|
static fromPLUR(plur: NumberString | string | bigint): BZZ;
|
|
8
|
+
static fromFloat(float: number): BZZ;
|
|
8
9
|
toPLURString(): string;
|
|
9
10
|
toPLURBigInt(): bigint;
|
|
10
11
|
toDecimalString(): string;
|
|
12
|
+
toFloat(): number;
|
|
11
13
|
toSignificantDigits(digits: number): string;
|
|
12
14
|
/**
|
|
13
15
|
* Does not mutate the current BZZ instance.
|
|
@@ -43,10 +45,12 @@ export declare class DAI {
|
|
|
43
45
|
private constructor();
|
|
44
46
|
static fromDecimalString(string: string): DAI;
|
|
45
47
|
static fromWei(wei: NumberString | string | bigint): DAI;
|
|
48
|
+
static fromFloat(float: number): DAI;
|
|
46
49
|
toWeiString(): string;
|
|
47
50
|
toWeiBigInt(): bigint;
|
|
48
51
|
toDecimalString(): string;
|
|
49
52
|
toSignificantDigits(digits: number): string;
|
|
53
|
+
toFloat(): number;
|
|
50
54
|
/**
|
|
51
55
|
* Does not mutate the current DAI instance.
|
|
52
56
|
*
|