@ethersphere/bee-js 5.0.0 → 6.0.0-pre.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 +9 -1
- package/dist/index.browser.js +33 -0
- package/dist/index.browser.js.map +7 -0
- package/dist/src/bee-debug.js +624 -0
- package/dist/{mjs → src}/bee.js +243 -340
- package/dist/{mjs → src}/chunk/bmt.js +0 -0
- package/dist/{mjs → src}/chunk/cac.js +0 -0
- package/dist/{mjs → src}/chunk/serialize.js +0 -0
- package/dist/{mjs → src}/chunk/signer.js +13 -47
- package/dist/{mjs → src}/chunk/soc.js +31 -71
- package/dist/{mjs → src}/chunk/span.js +1 -1
- package/dist/{mjs → src}/feed/identifier.js +0 -0
- package/dist/src/feed/index.js +92 -0
- package/dist/src/feed/json.js +27 -0
- package/dist/src/feed/retrievable.js +67 -0
- package/dist/{mjs → src}/feed/topic.js +0 -0
- package/dist/{mjs → src}/feed/type.js +0 -0
- package/dist/{mjs → src}/index.js +1 -2
- package/dist/src/modules/bytes.js +59 -0
- package/dist/src/modules/bzz.js +122 -0
- package/dist/src/modules/chunk.js +45 -0
- package/dist/src/modules/debug/balance.js +57 -0
- package/dist/src/modules/debug/chequebook.js +150 -0
- package/dist/src/modules/debug/chunk.js +35 -0
- package/dist/src/modules/debug/connectivity.js +45 -0
- package/dist/src/modules/debug/settlements.js +29 -0
- package/dist/src/modules/debug/stamps.js +64 -0
- package/dist/src/modules/debug/states.js +46 -0
- package/dist/src/modules/debug/status.js +134 -0
- package/dist/src/modules/debug/tag.js +16 -0
- package/dist/src/modules/debug/transactions.js +69 -0
- package/dist/src/modules/feed.js +67 -0
- package/dist/src/modules/pinning.js +60 -0
- package/dist/src/modules/pss.js +40 -0
- package/dist/src/modules/soc.js +31 -0
- package/dist/src/modules/status.js +12 -0
- package/dist/src/modules/stewardship.js +24 -0
- package/dist/src/modules/tag.js +77 -0
- package/dist/{mjs → src}/types/debug.js +0 -0
- package/dist/{mjs → src}/types/index.js +0 -0
- package/dist/{mjs → src}/utils/bytes.js +3 -2
- package/dist/src/utils/collection-browser.js +19 -0
- package/dist/src/utils/collection-node.js +74 -0
- package/dist/src/utils/collection.js +64 -0
- package/dist/src/utils/data.browser.js +72 -0
- package/dist/src/utils/data.js +42 -0
- package/dist/{mjs → src}/utils/error.js +0 -0
- package/dist/{mjs → src}/utils/eth.js +32 -68
- package/dist/{mjs → src}/utils/expose.js +1 -1
- package/dist/src/utils/file.js +36 -0
- package/dist/{mjs → src}/utils/hash.js +0 -0
- package/dist/{mjs → src}/utils/headers.js +4 -4
- package/dist/{mjs → src}/utils/hex.js +0 -0
- package/dist/src/utils/http.js +162 -0
- package/dist/{mjs → src}/utils/merge.js +2 -2
- package/dist/{mjs → src}/utils/pss.js +0 -0
- package/dist/{mjs → src}/utils/reference.js +0 -0
- package/dist/src/utils/sleep.js +8 -0
- package/dist/{mjs → src}/utils/stamps.js +0 -0
- package/dist/{mjs → src}/utils/stream.js +3 -3
- package/dist/{mjs → src}/utils/tar.js +0 -0
- package/dist/{mjs → src}/utils/type.js +12 -13
- package/dist/{mjs → src}/utils/uint64.js +0 -0
- package/dist/{mjs → src}/utils/url.js +0 -0
- package/dist/types/chunk/bmt.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +1 -1
- package/dist/types/chunk/span.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/modules/bzz.d.ts +1 -1
- package/dist/types/types/index.d.ts +8 -8
- package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
- package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
- package/dist/types/utils/error.d.ts +1 -1
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/expose.d.ts +7 -4
- package/dist/types/utils/hash.d.ts +1 -1
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +3 -3
- package/dist/types/utils/stream.d.ts +1 -1
- package/dist/types/utils/uint64.d.ts +1 -1
- package/package.json +44 -59
- package/dist/cjs/bee-debug.js +0 -642
- package/dist/cjs/bee.js +0 -983
- package/dist/cjs/chunk/bmt.js +0 -55
- package/dist/cjs/chunk/cac.js +0 -56
- package/dist/cjs/chunk/serialize.js +0 -19
- package/dist/cjs/chunk/signer.js +0 -137
- package/dist/cjs/chunk/soc.js +0 -176
- package/dist/cjs/chunk/span.js +0 -29
- package/dist/cjs/feed/identifier.js +0 -35
- package/dist/cjs/feed/index.js +0 -132
- package/dist/cjs/feed/json.js +0 -41
- package/dist/cjs/feed/retrievable.js +0 -72
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/index.js +0 -39
- package/dist/cjs/modules/bytes.js +0 -74
- package/dist/cjs/modules/bzz.js +0 -131
- package/dist/cjs/modules/chunk.js +0 -58
- package/dist/cjs/modules/debug/balance.js +0 -77
- package/dist/cjs/modules/debug/chequebook.js +0 -167
- package/dist/cjs/modules/debug/chunk.js +0 -51
- package/dist/cjs/modules/debug/connectivity.js +0 -75
- package/dist/cjs/modules/debug/settlements.js +0 -45
- package/dist/cjs/modules/debug/stamps.js +0 -89
- package/dist/cjs/modules/debug/states.js +0 -64
- package/dist/cjs/modules/debug/status.js +0 -153
- package/dist/cjs/modules/debug/tag.js +0 -30
- package/dist/cjs/modules/debug/transactions.js +0 -81
- package/dist/cjs/modules/feed.js +0 -76
- package/dist/cjs/modules/pinning.js +0 -80
- package/dist/cjs/modules/pss.js +0 -55
- package/dist/cjs/modules/soc.js +0 -40
- package/dist/cjs/modules/status.js +0 -26
- package/dist/cjs/modules/stewardship.js +0 -41
- package/dist/cjs/modules/tag.js +0 -96
- package/dist/cjs/package.json +0 -8
- package/dist/cjs/types/debug.js +0 -10
- package/dist/cjs/types/index.js +0 -51
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/cjs/utils/bytes.js +0 -121
- package/dist/cjs/utils/collection.browser.js +0 -36
- package/dist/cjs/utils/collection.js +0 -70
- package/dist/cjs/utils/collection.node.js +0 -115
- package/dist/cjs/utils/data.browser.js +0 -74
- package/dist/cjs/utils/data.js +0 -58
- package/dist/cjs/utils/error.js +0 -50
- package/dist/cjs/utils/eth.js +0 -211
- package/dist/cjs/utils/expose.js +0 -44
- package/dist/cjs/utils/file.js +0 -49
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/headers.js +0 -59
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/http.js +0 -172
- package/dist/cjs/utils/merge.js +0 -34
- package/dist/cjs/utils/pss.js +0 -18
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/cjs/utils/sleep.js +0 -23
- package/dist/cjs/utils/stamps.js +0 -17
- package/dist/cjs/utils/stream.js +0 -146
- package/dist/cjs/utils/tar.js +0 -25
- package/dist/cjs/utils/type.js +0 -426
- package/dist/cjs/utils/uint64.js +0 -29
- package/dist/cjs/utils/url.js +0 -56
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -60
- package/dist/index.browser.min.js.map +0 -1
- package/dist/mjs/bee-debug.js +0 -744
- package/dist/mjs/feed/index.js +0 -134
- package/dist/mjs/feed/json.js +0 -63
- package/dist/mjs/feed/retrievable.js +0 -105
- package/dist/mjs/modules/bytes.js +0 -96
- package/dist/mjs/modules/bzz.js +0 -160
- package/dist/mjs/modules/chunk.js +0 -80
- package/dist/mjs/modules/debug/balance.js +0 -97
- package/dist/mjs/modules/debug/chequebook.js +0 -198
- package/dist/mjs/modules/debug/chunk.js +0 -71
- package/dist/mjs/modules/debug/connectivity.js +0 -89
- package/dist/mjs/modules/debug/settlements.js +0 -65
- package/dist/mjs/modules/debug/stamps.js +0 -108
- package/dist/mjs/modules/debug/states.js +0 -84
- package/dist/mjs/modules/debug/status.js +0 -182
- package/dist/mjs/modules/debug/tag.js +0 -50
- package/dist/mjs/modules/debug/transactions.js +0 -103
- package/dist/mjs/modules/feed.js +0 -101
- package/dist/mjs/modules/pinning.js +0 -100
- package/dist/mjs/modules/pss.js +0 -74
- package/dist/mjs/modules/soc.js +0 -64
- package/dist/mjs/modules/status.js +0 -46
- package/dist/mjs/modules/stewardship.js +0 -60
- package/dist/mjs/modules/tag.js +0 -119
- package/dist/mjs/package.json +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/mjs/utils/collection.browser.js +0 -56
- package/dist/mjs/utils/collection.js +0 -98
- package/dist/mjs/utils/collection.node.js +0 -169
- package/dist/mjs/utils/data.browser.js +0 -108
- package/dist/mjs/utils/data.js +0 -78
- package/dist/mjs/utils/file.js +0 -70
- package/dist/mjs/utils/http.js +0 -208
- package/dist/mjs/utils/sleep.js +0 -43
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/utils/type.js
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const error_1 = require("./error");
|
|
6
|
-
const file_1 = require("./file");
|
|
7
|
-
const hex_1 = require("./hex");
|
|
8
|
-
const stream_1 = require("./stream");
|
|
9
|
-
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
10
|
-
function isUint8Array(obj) {
|
|
11
|
-
return obj instanceof Uint8Array;
|
|
12
|
-
}
|
|
13
|
-
exports.isUint8Array = isUint8Array;
|
|
14
|
-
function isInteger(value) {
|
|
15
|
-
return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
|
|
16
|
-
(typeof value === 'number' &&
|
|
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
|
-
/**
|
|
27
|
-
* Generally it is discouraged to use `object` type, but in this case I think
|
|
28
|
-
* it is best to do so as it is possible to easily convert from `object`to other
|
|
29
|
-
* types, which will be usually the case after asserting that the object is
|
|
30
|
-
* strictly object. With for example Record<string, unknown> you have to first
|
|
31
|
-
* cast it to `unknown` which I think bit defeat the purpose.
|
|
32
|
-
*
|
|
33
|
-
* @param value
|
|
34
|
-
*/
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
36
|
-
function isStrictlyObject(value) {
|
|
37
|
-
return isObject(value) && !Array.isArray(value);
|
|
38
|
-
}
|
|
39
|
-
exports.isStrictlyObject = isStrictlyObject;
|
|
40
|
-
/**
|
|
41
|
-
* Asserts if object is Error
|
|
42
|
-
*
|
|
43
|
-
* @param e
|
|
44
|
-
*/
|
|
45
|
-
function isError(e) {
|
|
46
|
-
return e instanceof Error;
|
|
47
|
-
}
|
|
48
|
-
exports.isError = isError;
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
50
|
-
function assertStrictlyObject(value, name = 'value') {
|
|
51
|
-
if (!isStrictlyObject(value)) {
|
|
52
|
-
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.assertStrictlyObject = assertStrictlyObject;
|
|
56
|
-
function assertBoolean(value, name = 'value') {
|
|
57
|
-
if (value !== true && value !== false)
|
|
58
|
-
throw new TypeError(`${name} is not boolean`);
|
|
59
|
-
}
|
|
60
|
-
exports.assertBoolean = assertBoolean;
|
|
61
|
-
function assertInteger(value, name = 'value') {
|
|
62
|
-
if (!isInteger(value))
|
|
63
|
-
throw new TypeError(`${name} is not integer`);
|
|
64
|
-
}
|
|
65
|
-
exports.assertInteger = assertInteger;
|
|
66
|
-
function assertNonNegativeInteger(value, name = 'Value') {
|
|
67
|
-
assertInteger(value, name);
|
|
68
|
-
if (Number(value) < 0)
|
|
69
|
-
throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
70
|
-
}
|
|
71
|
-
exports.assertNonNegativeInteger = assertNonNegativeInteger;
|
|
72
|
-
function assertPositiveInteger(value, name = 'Value') {
|
|
73
|
-
assertInteger(value, name);
|
|
74
|
-
if (Number(value) <= 0)
|
|
75
|
-
throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
|
|
76
|
-
}
|
|
77
|
-
exports.assertPositiveInteger = assertPositiveInteger;
|
|
78
|
-
function assertReference(value) {
|
|
79
|
-
try {
|
|
80
|
-
(0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
(0, hex_1.assertHexString)(value, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.assertReference = assertReference;
|
|
87
|
-
function assertReferenceOrEns(value) {
|
|
88
|
-
if (typeof value !== 'string') {
|
|
89
|
-
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
90
|
-
}
|
|
91
|
-
if ((0, hex_1.isHexString)(value)) {
|
|
92
|
-
assertReference(value);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* a.asdf - VALID
|
|
97
|
-
* test.eth - VALID
|
|
98
|
-
* ADAM.ETH - VALID
|
|
99
|
-
* ADAM UHLIR.ETH - INVALID
|
|
100
|
-
* test.whatever.eth - VALID
|
|
101
|
-
* -adg.ets - INVALID
|
|
102
|
-
* adg-.ets - INVALID
|
|
103
|
-
* as-a.com - VALID
|
|
104
|
-
* ethswarm.org - VALID
|
|
105
|
-
* http://asdf.asf - INVALID
|
|
106
|
-
* řš+ýí.šě+ř.čě - VALID
|
|
107
|
-
* tsg.asg?asg - INVALID
|
|
108
|
-
* tsg.asg:1599 - INVALID
|
|
109
|
-
* ethswarm.something- - INVALID
|
|
110
|
-
* ethswarm.-something - INVALID
|
|
111
|
-
* ethswarm.some-thing - VALID
|
|
112
|
-
*
|
|
113
|
-
* 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
|
|
114
|
-
*
|
|
115
|
-
* This part matches 2-63 character string that does not start or end with -
|
|
116
|
-
* [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
|
|
117
|
-
*
|
|
118
|
-
* For 1 character long string we use the part after |
|
|
119
|
-
* [^-.\/?:\s] <regexp2>
|
|
120
|
-
*
|
|
121
|
-
* This is terminated in a group with . character an repeated at least once
|
|
122
|
-
* (<regexp1>|<regexp2>\.)+
|
|
123
|
-
*
|
|
124
|
-
* This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
|
|
125
|
-
* ^(<regexp1>|<regexp2>\.)+<regexp1>$
|
|
126
|
-
*/
|
|
127
|
-
const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
|
|
128
|
-
// We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
129
|
-
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
130
|
-
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
131
|
-
if (!DOMAIN_REGEX.test(value)) {
|
|
132
|
-
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.assertReferenceOrEns = assertReferenceOrEns;
|
|
136
|
-
/**
|
|
137
|
-
* Function that mainly converts Swarm CID into hex encoded Swarm Reference
|
|
138
|
-
*
|
|
139
|
-
* @param value
|
|
140
|
-
* @param expectedCidType
|
|
141
|
-
*/
|
|
142
|
-
function makeReferenceOrEns(value, expectedCidType) {
|
|
143
|
-
var _a;
|
|
144
|
-
if (typeof value !== 'string') {
|
|
145
|
-
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
const result = (0, swarm_cid_1.decodeCid)(value);
|
|
149
|
-
if (result.type !== expectedCidType) {
|
|
150
|
-
throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
|
|
151
|
-
}
|
|
152
|
-
return result.reference;
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
if (e instanceof error_1.BeeError)
|
|
156
|
-
throw e;
|
|
157
|
-
}
|
|
158
|
-
assertReferenceOrEns(value);
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
exports.makeReferenceOrEns = makeReferenceOrEns;
|
|
162
|
-
/**
|
|
163
|
-
* Function that adds getter which converts the reference into CID base32 encoded string.
|
|
164
|
-
* @param result
|
|
165
|
-
* @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
|
|
166
|
-
*/
|
|
167
|
-
function addCidConversionFunction(result, cidType) {
|
|
168
|
-
return Object.assign(Object.assign({}, result), { cid() {
|
|
169
|
-
return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
|
|
170
|
-
} });
|
|
171
|
-
}
|
|
172
|
-
exports.addCidConversionFunction = addCidConversionFunction;
|
|
173
|
-
function assertAddress(value) {
|
|
174
|
-
(0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
|
|
175
|
-
}
|
|
176
|
-
exports.assertAddress = assertAddress;
|
|
177
|
-
function assertBatchId(value) {
|
|
178
|
-
(0, hex_1.assertHexString)(value, types_1.BATCH_ID_HEX_LENGTH, 'BatchId');
|
|
179
|
-
}
|
|
180
|
-
exports.assertBatchId = assertBatchId;
|
|
181
|
-
function assertRequestOptions(value, name = 'RequestOptions') {
|
|
182
|
-
if (value === undefined) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (!isStrictlyObject(value)) {
|
|
186
|
-
throw new TypeError(`${name} has to be an object!`);
|
|
187
|
-
}
|
|
188
|
-
const options = value;
|
|
189
|
-
if (options.retry) {
|
|
190
|
-
assertNonNegativeInteger(options.retry, `${name}.retry`);
|
|
191
|
-
}
|
|
192
|
-
if (options.timeout) {
|
|
193
|
-
assertNonNegativeInteger(options.timeout, `${name}.timeout`);
|
|
194
|
-
}
|
|
195
|
-
if (options.fetch && typeof options.fetch !== 'function') {
|
|
196
|
-
throw new TypeError(`${name}.fetch has to be a function or undefined!`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.assertRequestOptions = assertRequestOptions;
|
|
200
|
-
function assertUploadOptions(value, name = 'UploadOptions') {
|
|
201
|
-
if (!isStrictlyObject(value)) {
|
|
202
|
-
throw new TypeError(`${name} has to be an object!`);
|
|
203
|
-
}
|
|
204
|
-
assertRequestOptions(value, name);
|
|
205
|
-
const options = value;
|
|
206
|
-
if (options.pin && typeof options.pin !== 'boolean') {
|
|
207
|
-
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
|
|
208
|
-
}
|
|
209
|
-
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
210
|
-
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
|
|
211
|
-
}
|
|
212
|
-
if (options.tag) {
|
|
213
|
-
if (typeof options.tag !== 'number') {
|
|
214
|
-
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
215
|
-
}
|
|
216
|
-
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.assertUploadOptions = assertUploadOptions;
|
|
220
|
-
function assertFileUploadOptions(value) {
|
|
221
|
-
assertUploadOptions(value, 'FileUploadOptions');
|
|
222
|
-
const options = value;
|
|
223
|
-
if (options.size) {
|
|
224
|
-
if (typeof options.size !== 'number') {
|
|
225
|
-
throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
|
|
226
|
-
}
|
|
227
|
-
assertNonNegativeInteger(options.size, 'options.size');
|
|
228
|
-
}
|
|
229
|
-
if (options.contentType && typeof options.contentType !== 'string') {
|
|
230
|
-
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.assertFileUploadOptions = assertFileUploadOptions;
|
|
234
|
-
function assertCollectionUploadOptions(value) {
|
|
235
|
-
assertUploadOptions(value, 'CollectionUploadOptions');
|
|
236
|
-
const options = value;
|
|
237
|
-
if (options.indexDocument && typeof options.indexDocument !== 'string') {
|
|
238
|
-
throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
239
|
-
}
|
|
240
|
-
if (options.errorDocument && typeof options.errorDocument !== 'string') {
|
|
241
|
-
throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
exports.assertCollectionUploadOptions = assertCollectionUploadOptions;
|
|
245
|
-
function isTag(value) {
|
|
246
|
-
if (!isStrictlyObject(value)) {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
const tag = value;
|
|
250
|
-
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
251
|
-
const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
|
|
252
|
-
if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
exports.isTag = isTag;
|
|
258
|
-
function assertTag(value) {
|
|
259
|
-
if (!isStrictlyObject(value)) {
|
|
260
|
-
throw new TypeError('Tag is not an object!');
|
|
261
|
-
}
|
|
262
|
-
const tag = value;
|
|
263
|
-
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
264
|
-
for (const numberProperty of numberProperties) {
|
|
265
|
-
if (!tag[numberProperty]) {
|
|
266
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
|
|
267
|
-
}
|
|
268
|
-
if (typeof tag[numberProperty] !== 'number') {
|
|
269
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (!tag.startedAt) {
|
|
273
|
-
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
274
|
-
}
|
|
275
|
-
if (typeof tag.startedAt !== 'string') {
|
|
276
|
-
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
exports.assertTag = assertTag;
|
|
280
|
-
function assertAddressPrefix(value) {
|
|
281
|
-
(0, hex_1.assertHexString)(value, undefined, 'AddressPrefix');
|
|
282
|
-
if (value.length > types_1.PSS_TARGET_HEX_LENGTH_MAX) {
|
|
283
|
-
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);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
exports.assertAddressPrefix = assertAddressPrefix;
|
|
287
|
-
function assertPssMessageHandler(value) {
|
|
288
|
-
if (!isStrictlyObject(value)) {
|
|
289
|
-
throw new TypeError('PssMessageHandler has to be object!');
|
|
290
|
-
}
|
|
291
|
-
const handler = value;
|
|
292
|
-
if (typeof handler.onMessage !== 'function') {
|
|
293
|
-
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
294
|
-
}
|
|
295
|
-
if (typeof handler.onError !== 'function') {
|
|
296
|
-
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.assertPssMessageHandler = assertPssMessageHandler;
|
|
300
|
-
function assertPublicKey(value) {
|
|
301
|
-
(0, hex_1.assertHexString)(value, types_1.PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
302
|
-
}
|
|
303
|
-
exports.assertPublicKey = assertPublicKey;
|
|
304
|
-
function assertPostageBatchOptions(value) {
|
|
305
|
-
if (value === undefined) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
assertStrictlyObject(value);
|
|
309
|
-
const options = value;
|
|
310
|
-
assertRequestOptions(options, 'PostageBatchOptions');
|
|
311
|
-
if (options === null || options === void 0 ? void 0 : options.gasPrice) {
|
|
312
|
-
assertNonNegativeInteger(options.gasPrice);
|
|
313
|
-
}
|
|
314
|
-
if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
|
|
315
|
-
assertBoolean(options.immutableFlag);
|
|
316
|
-
}
|
|
317
|
-
if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
|
|
318
|
-
assertBoolean(options.waitForUsable);
|
|
319
|
-
}
|
|
320
|
-
if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
|
|
321
|
-
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
exports.assertPostageBatchOptions = assertPostageBatchOptions;
|
|
325
|
-
function assertCashoutOptions(value) {
|
|
326
|
-
if (value === undefined) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
assertStrictlyObject(value);
|
|
330
|
-
const options = value;
|
|
331
|
-
assertRequestOptions(options, 'PostageBatchOptions');
|
|
332
|
-
if (options === null || options === void 0 ? void 0 : options.gasLimit) {
|
|
333
|
-
assertNonNegativeInteger(options.gasLimit);
|
|
334
|
-
}
|
|
335
|
-
if (options === null || options === void 0 ? void 0 : options.gasPrice) {
|
|
336
|
-
assertNonNegativeInteger(options.gasPrice);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
exports.assertCashoutOptions = assertCashoutOptions;
|
|
340
|
-
/**
|
|
341
|
-
* Check whether the given parameter is valid data to upload
|
|
342
|
-
* @param value
|
|
343
|
-
* @throws TypeError if not valid
|
|
344
|
-
*/
|
|
345
|
-
function assertData(value) {
|
|
346
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
347
|
-
throw new TypeError('Data must be either string or Uint8Array!');
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
exports.assertData = assertData;
|
|
351
|
-
/**
|
|
352
|
-
* Check whether the given parameter is a correct file representation to file upload.
|
|
353
|
-
* @param value
|
|
354
|
-
* @throws TypeError if not valid
|
|
355
|
-
*/
|
|
356
|
-
function assertFileData(value) {
|
|
357
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(0, file_1.isFile)(value) && !(0, stream_1.isReadable)(value)) {
|
|
358
|
-
throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
exports.assertFileData = assertFileData;
|
|
362
|
-
/**
|
|
363
|
-
* Checks whether optional options for AllTags query are valid
|
|
364
|
-
* @param options
|
|
365
|
-
*/
|
|
366
|
-
function assertAllTagsOptions(entry) {
|
|
367
|
-
if (entry !== undefined && !isStrictlyObject(entry)) {
|
|
368
|
-
throw new TypeError('options has to be an object or undefined!');
|
|
369
|
-
}
|
|
370
|
-
assertRequestOptions(entry, 'AllTagsOptions');
|
|
371
|
-
const options = entry;
|
|
372
|
-
if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
|
|
373
|
-
if (typeof options.limit !== 'number') {
|
|
374
|
-
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
375
|
-
}
|
|
376
|
-
if (options.limit < types_1.TAGS_LIMIT_MIN) {
|
|
377
|
-
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at least ${types_1.TAGS_LIMIT_MIN}`, options.limit);
|
|
378
|
-
}
|
|
379
|
-
if (options.limit > types_1.TAGS_LIMIT_MAX) {
|
|
380
|
-
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
|
|
384
|
-
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
exports.assertAllTagsOptions = assertAllTagsOptions;
|
|
388
|
-
/**
|
|
389
|
-
* Utility functions that return Tag UID
|
|
390
|
-
* @param tagUid
|
|
391
|
-
*/
|
|
392
|
-
function makeTagUid(tagUid) {
|
|
393
|
-
if (tagUid === undefined || tagUid === null) {
|
|
394
|
-
throw new TypeError('TagUid was expected but got undefined or null instead!');
|
|
395
|
-
}
|
|
396
|
-
if (isTag(tagUid)) {
|
|
397
|
-
return tagUid.uid;
|
|
398
|
-
}
|
|
399
|
-
else if (typeof tagUid === 'number') {
|
|
400
|
-
assertNonNegativeInteger(tagUid, 'UID');
|
|
401
|
-
return tagUid;
|
|
402
|
-
}
|
|
403
|
-
else if (typeof tagUid === 'string') {
|
|
404
|
-
const int = parseInt(tagUid);
|
|
405
|
-
if (isNaN(int)) {
|
|
406
|
-
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
407
|
-
}
|
|
408
|
-
if (int < 0) {
|
|
409
|
-
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
410
|
-
}
|
|
411
|
-
return int;
|
|
412
|
-
}
|
|
413
|
-
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
414
|
-
}
|
|
415
|
-
exports.makeTagUid = makeTagUid;
|
|
416
|
-
function assertTransactionHash(transactionHash) {
|
|
417
|
-
if (typeof transactionHash !== 'string') {
|
|
418
|
-
throw new TypeError('TransactionHash has to be a string!');
|
|
419
|
-
}
|
|
420
|
-
(0, hex_1.assertPrefixedHexString)(transactionHash, 'TransactionHash');
|
|
421
|
-
// Hash is 64 long + '0x' prefix = 66
|
|
422
|
-
if (transactionHash.length !== 66) {
|
|
423
|
-
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
exports.assertTransactionHash = assertTransactionHash;
|
package/dist/cjs/utils/uint64.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readUint64BigEndian = exports.writeUint64BigEndian = exports.writeUint64LittleEndian = void 0;
|
|
4
|
-
const bytes_1 = require("./bytes");
|
|
5
|
-
// TODO handle bigger values than 32 bit
|
|
6
|
-
// For now it's good enough because we only use these functions
|
|
7
|
-
// sequential feed indexes.
|
|
8
|
-
function writeUint64LittleEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
|
|
9
|
-
const dataView = new DataView(bytes.buffer);
|
|
10
|
-
const valueLower32 = value & 0xffffffff;
|
|
11
|
-
const littleEndian = true;
|
|
12
|
-
dataView.setUint32(0, valueLower32, littleEndian);
|
|
13
|
-
dataView.setUint32(4, 0, littleEndian);
|
|
14
|
-
return bytes;
|
|
15
|
-
}
|
|
16
|
-
exports.writeUint64LittleEndian = writeUint64LittleEndian;
|
|
17
|
-
function writeUint64BigEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
|
|
18
|
-
const dataView = new DataView(bytes.buffer);
|
|
19
|
-
const valueLower32 = value & 0xffffffff;
|
|
20
|
-
dataView.setUint32(0, 0);
|
|
21
|
-
dataView.setUint32(4, valueLower32);
|
|
22
|
-
return bytes;
|
|
23
|
-
}
|
|
24
|
-
exports.writeUint64BigEndian = writeUint64BigEndian;
|
|
25
|
-
function readUint64BigEndian(bytes) {
|
|
26
|
-
const dataView = new DataView(bytes.buffer);
|
|
27
|
-
return dataView.getUint32(4);
|
|
28
|
-
}
|
|
29
|
-
exports.readUint64BigEndian = readUint64BigEndian;
|
package/dist/cjs/utils/url.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stripLastSlash = exports.assertBeeUrl = exports.isValidBeeUrl = void 0;
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
const type_1 = require("./type");
|
|
6
|
-
function isNodeJsError(e) {
|
|
7
|
-
return (0, type_1.isObject)(e) && typeof e.code === 'string';
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Validates that passed string is valid URL of Bee.
|
|
11
|
-
* We support only HTTP and HTTPS protocols.
|
|
12
|
-
*
|
|
13
|
-
* @param url
|
|
14
|
-
*/
|
|
15
|
-
function isValidBeeUrl(url) {
|
|
16
|
-
try {
|
|
17
|
-
if (typeof url !== 'string') {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const urlObject = new URL(url);
|
|
21
|
-
// There can be wide range of protocols passed.
|
|
22
|
-
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:';
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
// URL constructor throws TypeError if not valid URL
|
|
26
|
-
// TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
|
|
27
|
-
if (e instanceof TypeError || (isNodeJsError(e) && e.code === 'ERR_INVALID_URL')) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
throw e;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.isValidBeeUrl = isValidBeeUrl;
|
|
34
|
-
/**
|
|
35
|
-
* Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
|
|
36
|
-
* We support only HTTP and HTTPS protocols.
|
|
37
|
-
* @param url
|
|
38
|
-
* @throws BeeArgumentError if non valid URL
|
|
39
|
-
*/
|
|
40
|
-
function assertBeeUrl(url) {
|
|
41
|
-
if (!isValidBeeUrl(url)) {
|
|
42
|
-
throw new error_1.BeeArgumentError('URL is not valid!', url);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.assertBeeUrl = assertBeeUrl;
|
|
46
|
-
/**
|
|
47
|
-
* Removes trailing slash out of the given string.
|
|
48
|
-
* @param url
|
|
49
|
-
*/
|
|
50
|
-
function stripLastSlash(url) {
|
|
51
|
-
if (url.endsWith('/')) {
|
|
52
|
-
return url.slice(0, -1);
|
|
53
|
-
}
|
|
54
|
-
return url;
|
|
55
|
-
}
|
|
56
|
-
exports.stripLastSlash = stripLastSlash;
|