@ethersphere/bee-js 3.3.3 → 4.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/LICENSE +24 -22
- package/README.md +0 -8
- package/dist/cjs/bee.js +71 -18
- package/dist/cjs/feed/identifier.js +35 -0
- package/dist/cjs/feed/index.js +34 -90
- package/dist/cjs/feed/retrievable.js +72 -0
- package/dist/cjs/modules/debug/status.js +3 -3
- package/dist/cjs/modules/feed.js +3 -3
- package/dist/cjs/types/index.js +2 -1
- package/dist/cjs/utils/bytes.js +15 -1
- package/dist/cjs/utils/data.browser.js +6 -10
- package/dist/cjs/utils/data.js +4 -6
- package/dist/cjs/utils/reference.js +36 -0
- package/dist/cjs/utils/type.js +36 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +77 -19
- package/dist/mjs/chunk/cac.js +1 -1
- package/dist/mjs/feed/identifier.js +35 -0
- package/dist/mjs/feed/index.js +39 -94
- package/dist/mjs/feed/retrievable.js +105 -0
- package/dist/mjs/modules/debug/status.js +3 -3
- package/dist/mjs/modules/feed.js +1 -1
- package/dist/mjs/types/index.js +1 -0
- package/dist/mjs/utils/bytes.js +15 -0
- package/dist/mjs/utils/data.browser.js +0 -1
- package/dist/mjs/utils/data.js +4 -5
- package/dist/mjs/utils/reference.js +32 -0
- package/dist/mjs/utils/type.js +38 -1
- package/dist/types/bee.d.ts +49 -19
- package/dist/types/chunk/cac.d.ts +4 -5
- package/dist/types/chunk/soc.d.ts +4 -4
- package/dist/types/feed/identifier.d.ts +4 -0
- package/dist/types/feed/index.d.ts +9 -16
- package/dist/types/feed/retrievable.d.ts +5 -0
- package/dist/types/modules/bytes.d.ts +3 -3
- package/dist/types/modules/bzz.d.ts +3 -3
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/status.d.ts +3 -3
- package/dist/types/modules/feed.d.ts +12 -1
- package/dist/types/modules/stewardship.d.ts +3 -3
- package/dist/types/types/debug.d.ts +20 -3
- package/dist/types/types/index.d.ts +11 -2
- package/dist/types/utils/bytes.d.ts +7 -0
- package/dist/types/utils/data.browser.d.ts +0 -1
- package/dist/types/utils/data.d.ts +2 -2
- package/dist/types/utils/reference.d.ts +2 -0
- package/dist/types/utils/type.d.ts +2 -1
- package/package.json +33 -33
|
@@ -8,13 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.prepareWebsocketData = exports.prepareData = void 0;
|
|
16
13
|
const stream_1 = require("./stream");
|
|
17
|
-
const cross_blob_1 = __importDefault(require("cross-blob"));
|
|
18
14
|
/**
|
|
19
15
|
* Validates input and converts to Uint8Array
|
|
20
16
|
*
|
|
@@ -23,11 +19,11 @@ const cross_blob_1 = __importDefault(require("cross-blob"));
|
|
|
23
19
|
function prepareData(data) {
|
|
24
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
21
|
if (typeof data === 'string')
|
|
26
|
-
return new
|
|
22
|
+
return new Blob([data], { type: 'text/plain' });
|
|
27
23
|
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
28
|
-
return new
|
|
24
|
+
return new Blob([data], { type: 'application/octet-stream' });
|
|
29
25
|
}
|
|
30
|
-
if (data instanceof
|
|
26
|
+
if (data instanceof Blob) {
|
|
31
27
|
return data;
|
|
32
28
|
}
|
|
33
29
|
// Currently it is not possible to stream requests from browsers
|
|
@@ -41,7 +37,7 @@ function prepareData(data) {
|
|
|
41
37
|
buffers.push(d);
|
|
42
38
|
});
|
|
43
39
|
data.on('end', () => {
|
|
44
|
-
resolve(new
|
|
40
|
+
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
45
41
|
});
|
|
46
42
|
});
|
|
47
43
|
}
|
|
@@ -57,7 +53,7 @@ function prepareData(data) {
|
|
|
57
53
|
buffers.push(value);
|
|
58
54
|
}
|
|
59
55
|
} while (!done);
|
|
60
|
-
resolve(new
|
|
56
|
+
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
61
57
|
}));
|
|
62
58
|
}
|
|
63
59
|
throw new TypeError('unknown data type');
|
|
@@ -70,7 +66,7 @@ function prepareWebsocketData(data) {
|
|
|
70
66
|
return new TextEncoder().encode(data);
|
|
71
67
|
if (data instanceof ArrayBuffer)
|
|
72
68
|
return new Uint8Array(data);
|
|
73
|
-
if (data instanceof
|
|
69
|
+
if (data instanceof Blob)
|
|
74
70
|
return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
75
71
|
throw new TypeError('unknown websocket data type');
|
|
76
72
|
});
|
package/dist/cjs/utils/data.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.prepareWebsocketData = exports.prepareData = void 0;
|
|
16
|
-
const
|
|
16
|
+
const fetch_blob_1 = __importDefault(require("fetch-blob"));
|
|
17
17
|
const stream_1 = require("./stream");
|
|
18
18
|
/**
|
|
19
19
|
* Prepare data for valid input for node-fetch.
|
|
@@ -26,11 +26,11 @@ const stream_1 = require("./stream");
|
|
|
26
26
|
function prepareData(data) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
if (typeof data === 'string')
|
|
29
|
-
return new
|
|
29
|
+
return new fetch_blob_1.default([data], { type: 'text/plain' });
|
|
30
30
|
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
31
|
-
return new
|
|
31
|
+
return new fetch_blob_1.default([data], { type: 'application/octet-stream' });
|
|
32
32
|
}
|
|
33
|
-
if (data instanceof
|
|
33
|
+
if (data instanceof fetch_blob_1.default || (0, stream_1.isNodeReadable)(data))
|
|
34
34
|
return data;
|
|
35
35
|
if ((0, stream_1.isReadableStream)(data)) {
|
|
36
36
|
return (0, stream_1.readableWebToNode)(data);
|
|
@@ -50,8 +50,6 @@ function prepareWebsocketData(data) {
|
|
|
50
50
|
return new Uint8Array(data);
|
|
51
51
|
if (data instanceof ArrayBuffer)
|
|
52
52
|
return new Uint8Array(data);
|
|
53
|
-
if (data instanceof cross_blob_1.default)
|
|
54
|
-
return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
55
53
|
if (isBufferArray(data))
|
|
56
54
|
return new Uint8Array(Buffer.concat(data));
|
|
57
55
|
throw new TypeError('unknown websocket data type');
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBytesReference = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
const hex_1 = require("./hex");
|
|
7
|
+
function makeBytesReference(reference, offset = 0) {
|
|
8
|
+
if (typeof reference === 'string') {
|
|
9
|
+
if (offset) {
|
|
10
|
+
throw new Error('Offset property can be set only for UintArray reference!');
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
// Non-encrypted chunk hex string reference
|
|
14
|
+
const hexReference = (0, hex_1.makeHexString)(reference, types_1.REFERENCE_HEX_LENGTH);
|
|
15
|
+
return (0, hex_1.hexToBytes)(hexReference);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
if (!(e instanceof TypeError)) {
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
// Encrypted chunk hex string reference
|
|
22
|
+
const hexReference = (0, hex_1.makeHexString)(reference, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
23
|
+
return (0, hex_1.hexToBytes)(hexReference);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (reference instanceof Uint8Array) {
|
|
27
|
+
if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
|
|
28
|
+
return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH);
|
|
29
|
+
}
|
|
30
|
+
else if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH)) {
|
|
31
|
+
return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
throw new TypeError('invalid chunk reference');
|
|
35
|
+
}
|
|
36
|
+
exports.makeBytesReference = makeBytesReference;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
3
|
+
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReferenceOrEns = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
const file_1 = require("./file");
|
|
@@ -77,6 +77,41 @@ function assertReference(value) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
exports.assertReference = assertReference;
|
|
80
|
+
function assertReferenceOrEns(value) {
|
|
81
|
+
if (typeof value !== 'string') {
|
|
82
|
+
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
83
|
+
}
|
|
84
|
+
if ((0, hex_1.isHexString)(value)) {
|
|
85
|
+
assertReference(value);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* a.asdf - VALID
|
|
90
|
+
* test.eth - VALID
|
|
91
|
+
* ADAM.ETH - VALID
|
|
92
|
+
* ADAM UHLIR.ETH - INVALID
|
|
93
|
+
* test.whatever.eth - VALID
|
|
94
|
+
* -adg.ets - INVALID
|
|
95
|
+
* adg-.ets - INVALID
|
|
96
|
+
* as-a.com - VALID
|
|
97
|
+
* ethswarm.org - VALID
|
|
98
|
+
* http://asdf.asf - INVALID
|
|
99
|
+
* řš+ýí.šě+ř.čě - VALID
|
|
100
|
+
* tsg.asg?asg - INVALID
|
|
101
|
+
* tsg.asg:1599 - INVALID
|
|
102
|
+
* ethswarm.something- - INVALID
|
|
103
|
+
* ethswarm.-something - INVALID
|
|
104
|
+
* ethswarm.some-thing - VALID
|
|
105
|
+
*/
|
|
106
|
+
const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/;
|
|
107
|
+
// We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
108
|
+
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
109
|
+
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
110
|
+
if (!DOMAIN_REGEX.test(value)) {
|
|
111
|
+
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.assertReferenceOrEns = assertReferenceOrEns;
|
|
80
115
|
function assertAddress(value) {
|
|
81
116
|
(0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
|
|
82
117
|
}
|