@ethersphere/bee-js 9.7.0 → 9.8.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/cjs/bee.js +2 -1
- package/dist/cjs/manifest/manifest.js +17 -0
- package/dist/cjs/utils/chunk-stream.js +15 -3
- package/dist/cjs/utils/http.js +7 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +2 -1
- package/dist/mjs/manifest/manifest.js +17 -0
- package/dist/mjs/utils/chunk-stream.js +14 -3
- package/dist/mjs/utils/http.js +9 -1
- package/dist/types/bee.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/package.json +5 -3
package/dist/mjs/bee.js
CHANGED
|
@@ -695,7 +695,8 @@ export class Bee {
|
|
|
695
695
|
for (let i = 0n; i < 0xffffn; i++) {
|
|
696
696
|
const signer = new PrivateKey(Binary.numberToUint256(start + i, 'BE'));
|
|
697
697
|
const socAddress = makeSOCAddress(identifier, signer.publicKey().address());
|
|
698
|
-
|
|
698
|
+
// TODO: test the significance of the hardcoded 256
|
|
699
|
+
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array());
|
|
699
700
|
if (actualProximity <= 256 - proximity) {
|
|
700
701
|
return signer;
|
|
701
702
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Binary, MerkleTree, Optional, Uint8ArrayReader } from 'cafe-utility';
|
|
2
|
+
import _debug from 'debug';
|
|
2
3
|
import { NULL_ADDRESS } from "../index.js";
|
|
3
4
|
import { Reference } from "../utils/typed-bytes.js";
|
|
5
|
+
const debug = _debug('bee-js:manifest');
|
|
4
6
|
const ENCODER = new TextEncoder();
|
|
5
7
|
const DECODER = new TextDecoder();
|
|
6
8
|
const TYPE_VALUE = 2;
|
|
@@ -60,6 +62,11 @@ export class Fork {
|
|
|
60
62
|
data.push(new Uint8Array(30 - this.prefix.length));
|
|
61
63
|
}
|
|
62
64
|
data.push(this.node.selfAddress);
|
|
65
|
+
debug('marshalling fork', {
|
|
66
|
+
prefixLength: this.prefix.length,
|
|
67
|
+
prefix: DECODER.decode(this.prefix),
|
|
68
|
+
address: Binary.uint8ArrayToHex(this.node.selfAddress)
|
|
69
|
+
});
|
|
63
70
|
if (this.node.metadata) {
|
|
64
71
|
const metadataBytes = Binary.padEndToMultiple(new Uint8Array([0x00, 0x00, ...ENCODER.encode(JSON.stringify(this.node.metadata))]), 32, 0x0a);
|
|
65
72
|
const metadataLengthBytes = Binary.numberToUint16(metadataBytes.length - 2, 'BE');
|
|
@@ -74,6 +81,12 @@ export class Fork {
|
|
|
74
81
|
const prefix = reader.read(prefixLength);
|
|
75
82
|
reader.read(30 - prefixLength);
|
|
76
83
|
const selfAddress = reader.read(addressLength);
|
|
84
|
+
debug('unmarshalling fork', {
|
|
85
|
+
prefixLength,
|
|
86
|
+
prefix: DECODER.decode(prefix),
|
|
87
|
+
addressLength,
|
|
88
|
+
address: Binary.uint8ArrayToHex(selfAddress)
|
|
89
|
+
});
|
|
77
90
|
let metadata = undefined;
|
|
78
91
|
if (isType(type, TYPE_WITH_METADATA)) {
|
|
79
92
|
const metadataLength = Binary.uint16ToNumber(reader.read(2), 'BE');
|
|
@@ -232,6 +245,10 @@ export class MantarayNode {
|
|
|
232
245
|
addFork(path, reference, metadata) {
|
|
233
246
|
this.selfAddress = null;
|
|
234
247
|
path = path instanceof Uint8Array ? path : ENCODER.encode(path);
|
|
248
|
+
debug('adding fork', {
|
|
249
|
+
path: DECODER.decode(path),
|
|
250
|
+
reference: new Reference(reference).represent()
|
|
251
|
+
});
|
|
235
252
|
// TODO: this should not be ignored
|
|
236
253
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
237
254
|
let tip = this;
|
|
@@ -39,6 +39,7 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
|
|
|
39
39
|
for (const file of files) {
|
|
40
40
|
total += totalChunks(file.size);
|
|
41
41
|
}
|
|
42
|
+
let hasIndexHtml = false;
|
|
42
43
|
async function onChunk(chunk) {
|
|
43
44
|
await queue.enqueue(async () => {
|
|
44
45
|
await bee.uploadChunk(postageBatchId, chunk.build(), options, requestOptions);
|
|
@@ -69,10 +70,20 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
|
|
|
69
70
|
Filename: filename
|
|
70
71
|
});
|
|
71
72
|
if (file.path === 'index.html') {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
hasIndexHtml = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (hasIndexHtml || options?.indexDocument || options?.errorDocument) {
|
|
77
|
+
const metadata = {};
|
|
78
|
+
if (options?.indexDocument) {
|
|
79
|
+
metadata['website-index-document'] = options.indexDocument;
|
|
80
|
+
} else if (hasIndexHtml) {
|
|
81
|
+
metadata['website-index-document'] = 'index.html';
|
|
82
|
+
}
|
|
83
|
+
if (options?.errorDocument) {
|
|
84
|
+
metadata['website-error-document'] = options.errorDocument;
|
|
75
85
|
}
|
|
86
|
+
mantaray.addFork('/', NULL_ADDRESS, metadata);
|
|
76
87
|
}
|
|
77
88
|
return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
78
89
|
}
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { Dates, Objects, Strings, System } from 'cafe-utility';
|
|
3
|
+
import _debug from 'debug';
|
|
3
4
|
import { BeeResponseError } from "../index.js";
|
|
5
|
+
const debug = _debug('bee-js:http');
|
|
4
6
|
const {
|
|
5
7
|
AxiosError
|
|
6
8
|
} = axios;
|
|
@@ -37,6 +39,12 @@ export async function http(options, config) {
|
|
|
37
39
|
let failedAttempts = 0;
|
|
38
40
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
39
41
|
try {
|
|
42
|
+
debug(`${requestConfig.method || 'get'} ${Strings.joinUrl([requestConfig.baseURL, requestConfig.url])}`, {
|
|
43
|
+
headers: {
|
|
44
|
+
...requestConfig.headers
|
|
45
|
+
},
|
|
46
|
+
params: requestConfig.params
|
|
47
|
+
});
|
|
40
48
|
maybeRunOnRequestHook(options, requestConfig);
|
|
41
49
|
const response = await axios(requestConfig);
|
|
42
50
|
return response;
|
|
@@ -59,7 +67,7 @@ function maybeRunOnRequestHook(options, requestConfig) {
|
|
|
59
67
|
if (options.onRequest) {
|
|
60
68
|
options.onRequest({
|
|
61
69
|
method: requestConfig.method || 'GET',
|
|
62
|
-
url: Strings.joinUrl(requestConfig.baseURL, requestConfig.url),
|
|
70
|
+
url: Strings.joinUrl([requestConfig.baseURL, requestConfig.url]),
|
|
63
71
|
headers: {
|
|
64
72
|
...requestConfig.headers
|
|
65
73
|
},
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ export declare class Bee {
|
|
|
193
193
|
*/
|
|
194
194
|
uploadFiles(postageBatchId: BatchId | Uint8Array | string, fileList: FileList | File[], options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
195
195
|
hashDirectory(dir: string): Promise<Reference>;
|
|
196
|
-
streamDirectory(postageBatchId: BatchId | Uint8Array | string, dir: string, onUploadProgress?: (progress: UploadProgress) => void, options?:
|
|
196
|
+
streamDirectory(postageBatchId: BatchId | Uint8Array | string, dir: string, onUploadProgress?: (progress: UploadProgress) => void, options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
197
197
|
streamFiles(postageBatchId: BatchId | Uint8Array | string, files: File[] | FileList, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
198
198
|
/**
|
|
199
199
|
* Upload Collection that you can assembly yourself.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Bee, BeeRequestOptions, UploadOptions, UploadResult } from '..';
|
|
1
|
+
import { Bee, BeeRequestOptions, CollectionUploadOptions, UploadOptions, UploadResult } from '..';
|
|
2
2
|
import { BatchId } from './typed-bytes';
|
|
3
3
|
import { UploadProgress } from './upload-progress';
|
|
4
4
|
export declare function hashDirectory(dir: string): Promise<import("./typed-bytes").Reference>;
|
|
5
|
-
export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?:
|
|
5
|
+
export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
6
6
|
export declare function streamFiles(_bee: Bee, _files: File[] | FileList, _postageBatchId: BatchId, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethersphere/bee-js",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.8.0",
|
|
4
4
|
"description": "Javascript client for Bee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bee",
|
|
@@ -55,14 +55,15 @@
|
|
|
55
55
|
"build:node": "tsc -p tsconfig.json && tsc -p tsconfig-mjs.json && ./build-fixup && babel --plugins \"babel-plugin-add-import-extension\" --out-dir dist/mjs/ dist/mjs/",
|
|
56
56
|
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
|
|
57
57
|
"build:browser": "webpack --progress",
|
|
58
|
-
"test": "jest --config=jest.config.ts --runInBand --verbose",
|
|
58
|
+
"test": "jest --config=jest.config.ts --runInBand --verbose --forceExit",
|
|
59
59
|
"check": "tsc --project tsconfig.test.json",
|
|
60
60
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
61
61
|
"depcheck": "depcheck ."
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"axios": "^0.30.0",
|
|
65
|
-
"cafe-utility": "^
|
|
65
|
+
"cafe-utility": "^31.0.0",
|
|
66
|
+
"debug": "^4.4.1",
|
|
66
67
|
"isomorphic-ws": "^4.0.1",
|
|
67
68
|
"semver": "^7.3.5",
|
|
68
69
|
"ws": "^8.7.0"
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"@commitlint/config-conventional": "^17.4.2",
|
|
79
80
|
"@jest/types": "^29.6.3",
|
|
80
81
|
"@naholyr/cross-env": "^1.0.0",
|
|
82
|
+
"@types/debug": "^4.1.12",
|
|
81
83
|
"@types/jest": "^29.5.13",
|
|
82
84
|
"@types/node": "^18.11.11",
|
|
83
85
|
"@types/semver": "^7.3.9",
|