@ethersphere/bee-js 8.3.1 → 9.0.2
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 +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +142 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +216 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
package/dist/cjs/utils/type.js
CHANGED
|
@@ -1,331 +1,159 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
26
|
+
exports.makeTagUid = exports.prepareAllTagsOptions = exports.assertFileData = exports.assertData = exports.prepareTransactionOptions = exports.preparePostageBatchOptions = exports.prepareGsocMessageHandler = exports.preparePssMessageHandler = exports.isTag = exports.prepareCollectionUploadOptions = exports.prepareFileUploadOptions = exports.prepareRedundantUploadOptions = exports.prepareUploadOptions = exports.prepareDownloadOptions = exports.prepareBeeRequestOptions = exports.asNumberString = exports.isReadable = void 0;
|
|
27
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
28
|
+
const stream = __importStar(require("stream"));
|
|
5
29
|
const types_1 = require("../types");
|
|
6
|
-
const cid_1 = require("./cid");
|
|
7
|
-
const error_1 = require("./error");
|
|
8
30
|
const file_1 = require("./file");
|
|
9
|
-
const
|
|
10
|
-
function isReadable(
|
|
11
|
-
return typeof
|
|
31
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
32
|
+
function isReadable(value) {
|
|
33
|
+
return typeof stream.Readable !== 'undefined' && value instanceof stream.Readable;
|
|
12
34
|
}
|
|
13
35
|
exports.isReadable = isReadable;
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
value > Number.MIN_SAFE_INTEGER &&
|
|
18
|
-
value < Number.MAX_SAFE_INTEGER &&
|
|
19
|
-
Number.isInteger(value)));
|
|
20
|
-
}
|
|
21
|
-
exports.isInteger = isInteger;
|
|
22
|
-
function isObject(value) {
|
|
23
|
-
return value !== null && typeof value === 'object';
|
|
24
|
-
}
|
|
25
|
-
exports.isObject = isObject;
|
|
26
|
-
function isStrictlyObject(value) {
|
|
27
|
-
return isObject(value) && !Array.isArray(value);
|
|
28
|
-
}
|
|
29
|
-
exports.isStrictlyObject = isStrictlyObject;
|
|
30
|
-
/**
|
|
31
|
-
* Asserts if object is Error
|
|
32
|
-
*
|
|
33
|
-
* @param e
|
|
34
|
-
*/
|
|
35
|
-
function isError(e) {
|
|
36
|
-
return e instanceof Error;
|
|
37
|
-
}
|
|
38
|
-
exports.isError = isError;
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
40
|
-
function assertStrictlyObject(value, name = 'value') {
|
|
41
|
-
if (!isStrictlyObject(value)) {
|
|
42
|
-
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
36
|
+
function asNumberString(value, options) {
|
|
37
|
+
if (typeof value === 'bigint') {
|
|
38
|
+
value = value.toString();
|
|
43
39
|
}
|
|
40
|
+
return cafe_utility_1.Types.asIntegerString(value, options);
|
|
44
41
|
}
|
|
45
|
-
exports.
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
throw new TypeError(`${name} is not boolean`);
|
|
49
|
-
}
|
|
50
|
-
exports.assertBoolean = assertBoolean;
|
|
51
|
-
function assertInteger(value, name = 'value') {
|
|
52
|
-
if (!isInteger(value))
|
|
53
|
-
throw new TypeError(`${name} is not integer`);
|
|
54
|
-
}
|
|
55
|
-
exports.assertInteger = assertInteger;
|
|
56
|
-
function assertNonNegativeInteger(value, name = 'Value') {
|
|
57
|
-
assertInteger(value, name);
|
|
58
|
-
if (Number(value) < 0)
|
|
59
|
-
throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
60
|
-
}
|
|
61
|
-
exports.assertNonNegativeInteger = assertNonNegativeInteger;
|
|
62
|
-
function assertPositiveInteger(value, name = 'Value') {
|
|
63
|
-
assertInteger(value, name);
|
|
64
|
-
if (Number(value) <= 0)
|
|
65
|
-
throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
|
|
66
|
-
}
|
|
67
|
-
exports.assertPositiveInteger = assertPositiveInteger;
|
|
68
|
-
function assertReference(value) {
|
|
69
|
-
try {
|
|
70
|
-
(0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
(0, hex_1.assertHexString)(value, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.assertReference = assertReference;
|
|
77
|
-
function assertReferenceOrEns(value) {
|
|
78
|
-
if (typeof value !== 'string') {
|
|
79
|
-
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
80
|
-
}
|
|
81
|
-
if ((0, hex_1.isHexString)(value)) {
|
|
82
|
-
assertReference(value);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* a.asdf - VALID
|
|
87
|
-
* test.eth - VALID
|
|
88
|
-
* ADAM.ETH - VALID
|
|
89
|
-
* ADAM UHLIR.ETH - INVALID
|
|
90
|
-
* test.whatever.eth - VALID
|
|
91
|
-
* -adg.ets - INVALID
|
|
92
|
-
* adg-.ets - INVALID
|
|
93
|
-
* as-a.com - VALID
|
|
94
|
-
* ethswarm.org - VALID
|
|
95
|
-
* http://asdf.asf - INVALID
|
|
96
|
-
* řš+ýí.šě+ř.čě - VALID
|
|
97
|
-
* tsg.asg?asg - INVALID
|
|
98
|
-
* tsg.asg:1599 - INVALID
|
|
99
|
-
* ethswarm.something- - INVALID
|
|
100
|
-
* ethswarm.-something - INVALID
|
|
101
|
-
* ethswarm.some-thing - VALID
|
|
102
|
-
*
|
|
103
|
-
* The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
|
|
104
|
-
*
|
|
105
|
-
* This part matches 2-63 character string that does not start or end with -
|
|
106
|
-
* [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
|
|
107
|
-
*
|
|
108
|
-
* For 1 character long string we use the part after |
|
|
109
|
-
* [^-.\/?:\s] <regexp2>
|
|
110
|
-
*
|
|
111
|
-
* This is terminated in a group with . character an repeated at least once
|
|
112
|
-
* (<regexp1>|<regexp2>\.)+
|
|
113
|
-
*
|
|
114
|
-
* This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
|
|
115
|
-
* ^(<regexp1>|<regexp2>\.)+<regexp1>$
|
|
116
|
-
*/
|
|
117
|
-
const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
|
|
118
|
-
// We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
119
|
-
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
120
|
-
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
121
|
-
if (!DOMAIN_REGEX.test(value)) {
|
|
122
|
-
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.assertReferenceOrEns = assertReferenceOrEns;
|
|
126
|
-
/**
|
|
127
|
-
* Function that mainly converts Swarm CID into hex encoded Swarm Reference
|
|
128
|
-
*
|
|
129
|
-
* @param value
|
|
130
|
-
* @param expectedCidType
|
|
131
|
-
*/
|
|
132
|
-
function makeReferenceOrEns(value, expectedCidType) {
|
|
133
|
-
if (typeof value !== 'string') {
|
|
134
|
-
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const result = (0, cid_1.convertCidToReference)(value);
|
|
138
|
-
if (result.type !== expectedCidType) {
|
|
139
|
-
throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
|
|
140
|
-
}
|
|
141
|
-
return result.reference;
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
if (e instanceof error_1.BeeError)
|
|
145
|
-
throw e;
|
|
146
|
-
}
|
|
147
|
-
assertReferenceOrEns(value);
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
exports.makeReferenceOrEns = makeReferenceOrEns;
|
|
151
|
-
/**
|
|
152
|
-
* Function that adds getter which converts the reference into CID base32 encoded string.
|
|
153
|
-
* @param result
|
|
154
|
-
* @param cidType feed or manifest
|
|
155
|
-
*/
|
|
156
|
-
function addCidConversionFunction(result, cidType) {
|
|
42
|
+
exports.asNumberString = asNumberString;
|
|
43
|
+
function prepareBeeRequestOptions(value) {
|
|
44
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'BeeRequestOptions' });
|
|
157
45
|
return {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
},
|
|
46
|
+
baseURL: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'baseURL' }), object.baseURL),
|
|
47
|
+
timeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'timeout', min: 0 }), object.timeout),
|
|
48
|
+
headers: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asStringMap(x, { name: 'headers' }), object.headers),
|
|
49
|
+
onRequest: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asFunction(x, { name: 'onRequest' }), object.onRequest),
|
|
50
|
+
httpAgent: object.httpAgent,
|
|
51
|
+
httpsAgent: object.httpsAgent,
|
|
52
|
+
endlesslyRetry: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'endlesslyRetry' }), object.endlesslyRetry),
|
|
162
53
|
};
|
|
163
54
|
}
|
|
164
|
-
exports.
|
|
165
|
-
function
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
55
|
+
exports.prepareBeeRequestOptions = prepareBeeRequestOptions;
|
|
56
|
+
function prepareDownloadOptions(value) {
|
|
57
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'DownloadOptions' });
|
|
58
|
+
return {
|
|
59
|
+
redundancyStrategy: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyStrategy' }), object.redundancyStrategy),
|
|
60
|
+
fallback: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'fallback' }), object.fallback),
|
|
61
|
+
timeoutMs: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'timeoutMs', min: 0 }), object.timeoutMs),
|
|
62
|
+
actPublisher: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.PublicKey(x), object.actPublisher),
|
|
63
|
+
actHistoryAddress: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.Reference(x), object.actHistoryAddress),
|
|
64
|
+
actTimestamp: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asNumber(x, { name: 'actTimestamp' }), object.actTimestamp),
|
|
65
|
+
};
|
|
171
66
|
}
|
|
172
|
-
exports.
|
|
173
|
-
function
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
67
|
+
exports.prepareDownloadOptions = prepareDownloadOptions;
|
|
68
|
+
function prepareUploadOptions(value, name = 'UploadOptions') {
|
|
69
|
+
const object = cafe_utility_1.Types.asObject(value, { name });
|
|
70
|
+
return {
|
|
71
|
+
act: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'act' }), object.act),
|
|
72
|
+
actHistoryAddress: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.Reference(x), object.actHistoryAddress),
|
|
73
|
+
deferred: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'deferred' }), object.deferred),
|
|
74
|
+
encrypt: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'encrypt' }), object.encrypt),
|
|
75
|
+
pin: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'pin' }), object.pin),
|
|
76
|
+
tag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'tag', min: 0 }), object.tag),
|
|
77
|
+
};
|
|
184
78
|
}
|
|
185
|
-
exports.
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
|
|
194
|
-
}
|
|
195
|
-
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
196
|
-
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
|
|
197
|
-
}
|
|
198
|
-
if (options.tag) {
|
|
199
|
-
if (typeof options.tag !== 'number') {
|
|
200
|
-
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
201
|
-
}
|
|
202
|
-
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
203
|
-
}
|
|
79
|
+
exports.prepareUploadOptions = prepareUploadOptions;
|
|
80
|
+
function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
|
|
81
|
+
const uploadOptions = prepareUploadOptions(value, name);
|
|
82
|
+
const object = cafe_utility_1.Types.asObject(value, { name });
|
|
83
|
+
return {
|
|
84
|
+
...uploadOptions,
|
|
85
|
+
redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
|
|
86
|
+
};
|
|
204
87
|
}
|
|
205
|
-
exports.
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
if (options.contentType && typeof options.contentType !== 'string') {
|
|
216
|
-
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
|
|
217
|
-
}
|
|
88
|
+
exports.prepareRedundantUploadOptions = prepareRedundantUploadOptions;
|
|
89
|
+
function prepareFileUploadOptions(value) {
|
|
90
|
+
const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
|
|
91
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'FileUploadOptions' });
|
|
92
|
+
return {
|
|
93
|
+
...uploadOptions,
|
|
94
|
+
size: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'size', min: 0 }), object.size),
|
|
95
|
+
contentType: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'contentType' }), object.contentType),
|
|
96
|
+
redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
|
|
97
|
+
};
|
|
218
98
|
}
|
|
219
|
-
exports.
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
99
|
+
exports.prepareFileUploadOptions = prepareFileUploadOptions;
|
|
100
|
+
function prepareCollectionUploadOptions(value) {
|
|
101
|
+
const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
|
|
102
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'CollectionUploadOptions' });
|
|
103
|
+
return {
|
|
104
|
+
...uploadOptions,
|
|
105
|
+
errorDocument: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'errorDocument' }), object.errorDocument),
|
|
106
|
+
indexDocument: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'indexDocument' }), object.indexDocument),
|
|
107
|
+
redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
|
|
108
|
+
};
|
|
229
109
|
}
|
|
230
|
-
exports.
|
|
110
|
+
exports.prepareCollectionUploadOptions = prepareCollectionUploadOptions;
|
|
231
111
|
function isTag(value) {
|
|
232
|
-
|
|
112
|
+
try {
|
|
113
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'Tag' });
|
|
114
|
+
cafe_utility_1.Types.asInteger(object.uid, { name: 'Tag.uid' });
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
233
118
|
return false;
|
|
234
119
|
}
|
|
235
|
-
return Boolean(value.uid);
|
|
236
120
|
}
|
|
237
121
|
exports.isTag = isTag;
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
for (const numberProperty of numberProperties) {
|
|
245
|
-
if (!tag[numberProperty]) {
|
|
246
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
|
|
247
|
-
}
|
|
248
|
-
if (typeof tag[numberProperty] !== 'number') {
|
|
249
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (!tag.startedAt) {
|
|
253
|
-
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
254
|
-
}
|
|
255
|
-
if (typeof tag.startedAt !== 'string') {
|
|
256
|
-
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
exports.assertTag = assertTag;
|
|
260
|
-
function assertAddressPrefix(value) {
|
|
261
|
-
(0, hex_1.assertHexString)(value, undefined, 'AddressPrefix');
|
|
262
|
-
if (value.length > types_1.PSS_TARGET_HEX_LENGTH_MAX) {
|
|
263
|
-
throw new error_1.BeeArgumentError(`AddressPrefix must have length of ${types_1.PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
exports.assertAddressPrefix = assertAddressPrefix;
|
|
267
|
-
function assertPssMessageHandler(value) {
|
|
268
|
-
if (!isStrictlyObject(value)) {
|
|
269
|
-
throw new TypeError('PssMessageHandler has to be object!');
|
|
270
|
-
}
|
|
271
|
-
const handler = value;
|
|
272
|
-
if (typeof handler.onMessage !== 'function') {
|
|
273
|
-
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
274
|
-
}
|
|
275
|
-
if (typeof handler.onError !== 'function') {
|
|
276
|
-
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
exports.assertPssMessageHandler = assertPssMessageHandler;
|
|
280
|
-
function assertPublicKey(value) {
|
|
281
|
-
(0, hex_1.assertHexString)(value, types_1.PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
122
|
+
function preparePssMessageHandler(value) {
|
|
123
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'PssMessageHandler' });
|
|
124
|
+
return {
|
|
125
|
+
onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
|
|
126
|
+
onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
|
|
127
|
+
};
|
|
282
128
|
}
|
|
283
|
-
exports.
|
|
284
|
-
function
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
assertRequestOptions(options, 'PostageBatchOptions');
|
|
291
|
-
if (options?.gasPrice) {
|
|
292
|
-
assertNonNegativeInteger(options.gasPrice);
|
|
293
|
-
}
|
|
294
|
-
if (options?.immutableFlag !== undefined) {
|
|
295
|
-
assertBoolean(options.immutableFlag);
|
|
296
|
-
}
|
|
297
|
-
if (options?.waitForUsable !== undefined) {
|
|
298
|
-
assertBoolean(options.waitForUsable);
|
|
299
|
-
}
|
|
300
|
-
if (options?.waitForUsableTimeout !== undefined) {
|
|
301
|
-
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
302
|
-
}
|
|
129
|
+
exports.preparePssMessageHandler = preparePssMessageHandler;
|
|
130
|
+
function prepareGsocMessageHandler(value) {
|
|
131
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'GsocMessageHandler' });
|
|
132
|
+
return {
|
|
133
|
+
onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
|
|
134
|
+
onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
|
|
135
|
+
};
|
|
303
136
|
}
|
|
304
|
-
exports.
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
if (options?.gasPrice) {
|
|
315
|
-
assertNonNegativeInteger(options.gasPrice, name);
|
|
316
|
-
}
|
|
137
|
+
exports.prepareGsocMessageHandler = prepareGsocMessageHandler;
|
|
138
|
+
function preparePostageBatchOptions(value) {
|
|
139
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'PostageBatchOptions' });
|
|
140
|
+
return {
|
|
141
|
+
gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice' }), object.gasPrice),
|
|
142
|
+
immutableFlag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'immutableFlag' }), object.immutableFlag),
|
|
143
|
+
label: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'label' }), object.label),
|
|
144
|
+
waitForUsable: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'waitForUsable' }), object.waitForUsable),
|
|
145
|
+
waitForUsableTimeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'waitForUsableTimeout', min: 0 }), object.waitForUsableTimeout),
|
|
146
|
+
};
|
|
317
147
|
}
|
|
318
|
-
exports.
|
|
319
|
-
function
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
assertRequestOptions(options, 'CashoutOptions');
|
|
326
|
-
assertTransactionOptions(options, 'CashoutOptions');
|
|
148
|
+
exports.preparePostageBatchOptions = preparePostageBatchOptions;
|
|
149
|
+
function prepareTransactionOptions(value, name = 'TransactionOptions') {
|
|
150
|
+
const object = cafe_utility_1.Types.asObject(value, { name });
|
|
151
|
+
return {
|
|
152
|
+
gasLimit: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasLimit', min: 0n }), object.gasLimit),
|
|
153
|
+
gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice', min: 0n }), object.gasPrice),
|
|
154
|
+
};
|
|
327
155
|
}
|
|
328
|
-
exports.
|
|
156
|
+
exports.prepareTransactionOptions = prepareTransactionOptions;
|
|
329
157
|
/**
|
|
330
158
|
* Check whether the given parameter is valid data to upload
|
|
331
159
|
* @param value
|
|
@@ -352,64 +180,28 @@ exports.assertFileData = assertFileData;
|
|
|
352
180
|
* Checks whether optional options for AllTags query are valid
|
|
353
181
|
* @param options
|
|
354
182
|
*/
|
|
355
|
-
function
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (options?.limit !== undefined) {
|
|
362
|
-
if (typeof options.limit !== 'number') {
|
|
363
|
-
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
364
|
-
}
|
|
365
|
-
if (options.limit < types_1.TAGS_LIMIT_MIN) {
|
|
366
|
-
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at least ${types_1.TAGS_LIMIT_MIN}`, options.limit);
|
|
367
|
-
}
|
|
368
|
-
if (options.limit > types_1.TAGS_LIMIT_MAX) {
|
|
369
|
-
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (options?.offset !== undefined) {
|
|
373
|
-
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
374
|
-
}
|
|
183
|
+
function prepareAllTagsOptions(value) {
|
|
184
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'AllTagsOptions' });
|
|
185
|
+
return {
|
|
186
|
+
limit: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'limit', min: types_1.TAGS_LIMIT_MIN, max: types_1.TAGS_LIMIT_MAX }), object.limit),
|
|
187
|
+
offset: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'offset', min: 0 }), object.offset),
|
|
188
|
+
};
|
|
375
189
|
}
|
|
376
|
-
exports.
|
|
190
|
+
exports.prepareAllTagsOptions = prepareAllTagsOptions;
|
|
377
191
|
/**
|
|
378
192
|
* Utility functions that return Tag UID
|
|
379
193
|
* @param tagUid
|
|
380
194
|
*/
|
|
381
195
|
function makeTagUid(tagUid) {
|
|
382
196
|
if (tagUid === undefined || tagUid === null) {
|
|
383
|
-
throw new TypeError(
|
|
197
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
384
198
|
}
|
|
385
199
|
if (isTag(tagUid)) {
|
|
386
200
|
return tagUid.uid;
|
|
387
201
|
}
|
|
388
|
-
else if (typeof tagUid === 'number') {
|
|
389
|
-
|
|
390
|
-
return tagUid;
|
|
391
|
-
}
|
|
392
|
-
else if (typeof tagUid === 'string') {
|
|
393
|
-
const int = parseInt(tagUid);
|
|
394
|
-
if (isNaN(int)) {
|
|
395
|
-
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
396
|
-
}
|
|
397
|
-
if (int < 0) {
|
|
398
|
-
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
399
|
-
}
|
|
400
|
-
return int;
|
|
202
|
+
else if (typeof tagUid === 'number' || typeof tagUid === 'string') {
|
|
203
|
+
return cafe_utility_1.Types.asNumber(tagUid, { name: 'tagUid', min: 0 });
|
|
401
204
|
}
|
|
402
|
-
throw new TypeError(
|
|
205
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
403
206
|
}
|
|
404
207
|
exports.makeTagUid = makeTagUid;
|
|
405
|
-
function assertTransactionHash(transactionHash) {
|
|
406
|
-
if (typeof transactionHash !== 'string') {
|
|
407
|
-
throw new TypeError('TransactionHash has to be a string!');
|
|
408
|
-
}
|
|
409
|
-
(0, hex_1.assertPrefixedHexString)(transactionHash, 'TransactionHash');
|
|
410
|
-
// Hash is 64 long + '0x' prefix = 66
|
|
411
|
-
if (transactionHash.length !== 66) {
|
|
412
|
-
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
exports.assertTransactionHash = assertTransactionHash;
|