@ethersphere/bee-js 3.2.0 → 3.3.2-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/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +55 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +137 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +211 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +21 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +146 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +12 -11
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +609 -0
- package/dist/mjs/bee.js +944 -0
- package/dist/mjs/chunk/bmt.js +56 -0
- package/dist/mjs/chunk/cac.js +52 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +131 -0
- package/dist/mjs/chunk/soc.js +139 -0
- package/dist/mjs/chunk/span.js +28 -0
- package/dist/mjs/feed/index.js +145 -0
- package/dist/mjs/feed/json.js +27 -0
- package/dist/mjs/feed/topic.js +21 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +59 -0
- package/dist/mjs/modules/bzz.js +122 -0
- package/dist/mjs/modules/chunk.js +45 -0
- package/dist/mjs/modules/debug/balance.js +57 -0
- package/dist/mjs/modules/debug/chequebook.js +150 -0
- package/dist/mjs/modules/debug/chunk.js +35 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +29 -0
- package/dist/mjs/modules/debug/stamps.js +64 -0
- package/dist/mjs/modules/debug/states.js +31 -0
- package/dist/mjs/modules/debug/status.js +134 -0
- package/dist/mjs/modules/debug/tag.js +16 -0
- package/dist/mjs/modules/debug/transactions.js +63 -0
- package/dist/mjs/modules/feed.js +67 -0
- package/dist/mjs/modules/pinning.js +66 -0
- package/dist/mjs/modules/pss.js +40 -0
- package/dist/mjs/modules/soc.js +31 -0
- package/dist/mjs/modules/status.js +12 -0
- package/dist/mjs/modules/stewardship.js +24 -0
- package/dist/mjs/modules/tag.js +77 -0
- package/dist/mjs/package.json +8 -0
- package/dist/mjs/types/debug.js +7 -0
- package/dist/mjs/types/index.js +37 -0
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +101 -0
- package/dist/mjs/utils/collection.browser.js +19 -0
- package/dist/mjs/utils/collection.js +64 -0
- package/dist/mjs/utils/collection.node.js +74 -0
- package/dist/mjs/utils/data.browser.js +73 -0
- package/dist/mjs/utils/data.js +43 -0
- package/dist/mjs/utils/error.js +56 -0
- package/dist/mjs/utils/eth.js +199 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +36 -0
- package/dist/mjs/utils/hash.js +17 -0
- package/dist/mjs/utils/headers.js +58 -0
- package/dist/mjs/utils/hex.js +154 -0
- package/dist/mjs/utils/http.js +155 -0
- package/dist/mjs/utils/merge.js +36 -0
- package/dist/mjs/utils/pss.js +16 -0
- package/dist/mjs/utils/stamps.js +17 -0
- package/dist/mjs/utils/stream.js +156 -0
- package/dist/mjs/utils/tar.js +21 -0
- package/dist/mjs/utils/type.js +336 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +57 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +8 -0
- package/dist/{src → types}/types/index.d.ts +3 -2
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +11 -8
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +55 -36
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -24
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
2
|
+
import { BeeArgumentError } from "./error.js";
|
|
3
|
+
import { isFile } from "./file.js";
|
|
4
|
+
import { assertHexString, assertPrefixedHexString } from "./hex.js";
|
|
5
|
+
import { isReadable } from "./stream.js";
|
|
6
|
+
export function isUint8Array(obj) {
|
|
7
|
+
return obj instanceof Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export function isInteger(value) {
|
|
10
|
+
return typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value) || typeof value === 'number' && value > Number.MIN_SAFE_INTEGER && value < Number.MAX_SAFE_INTEGER && Number.isInteger(value);
|
|
11
|
+
}
|
|
12
|
+
export function isObject(value) {
|
|
13
|
+
return value !== null && typeof value === 'object';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generally it is discouraged to use `object` type, but in this case I think
|
|
17
|
+
* it is best to do so as it is possible to easily convert from `object`to other
|
|
18
|
+
* types, which will be usually the case after asserting that the object is
|
|
19
|
+
* strictly object. With for example Record<string, unknown> you have to first
|
|
20
|
+
* cast it to `unknown` which I think bit defeat the purpose.
|
|
21
|
+
*
|
|
22
|
+
* @param value
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
25
|
+
|
|
26
|
+
export function isStrictlyObject(value) {
|
|
27
|
+
return isObject(value) && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Asserts if object is Error
|
|
31
|
+
*
|
|
32
|
+
* @param e
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export function isError(e) {
|
|
36
|
+
return e instanceof Error;
|
|
37
|
+
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
38
|
+
|
|
39
|
+
export function assertStrictlyObject(value, name = 'value') {
|
|
40
|
+
if (!isStrictlyObject(value)) {
|
|
41
|
+
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function assertBoolean(value, name = 'value') {
|
|
45
|
+
if (value !== true && value !== false) throw new TypeError(`${name} is not boolean`);
|
|
46
|
+
}
|
|
47
|
+
export function assertInteger(value, name = 'value') {
|
|
48
|
+
if (!isInteger(value)) throw new TypeError(`${name} is not integer`);
|
|
49
|
+
}
|
|
50
|
+
export function assertNonNegativeInteger(value, name = 'Value') {
|
|
51
|
+
assertInteger(value, name);
|
|
52
|
+
if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
53
|
+
}
|
|
54
|
+
export function assertReference(value) {
|
|
55
|
+
try {
|
|
56
|
+
assertHexString(value, REFERENCE_HEX_LENGTH);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function assertAddress(value) {
|
|
62
|
+
assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
|
|
63
|
+
}
|
|
64
|
+
export function assertBatchId(value) {
|
|
65
|
+
assertHexString(value, BATCH_ID_HEX_LENGTH, 'BatchId');
|
|
66
|
+
}
|
|
67
|
+
export function assertRequestOptions(value, name = 'RequestOptions') {
|
|
68
|
+
if (value === undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!isStrictlyObject(value)) {
|
|
73
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const options = value;
|
|
77
|
+
|
|
78
|
+
if (options.retry) {
|
|
79
|
+
assertNonNegativeInteger(options.retry, `${name}.retry`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (options.timeout) {
|
|
83
|
+
assertNonNegativeInteger(options.timeout, `${name}.timeout`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (options.fetch && typeof options.fetch !== 'function') {
|
|
87
|
+
throw new TypeError(`${name}.fetch has to be a function or undefined!`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function assertUploadOptions(value, name = 'UploadOptions') {
|
|
91
|
+
if (!isStrictlyObject(value)) {
|
|
92
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
assertRequestOptions(value, name);
|
|
96
|
+
const options = value;
|
|
97
|
+
|
|
98
|
+
if (options.pin && typeof options.pin !== 'boolean') {
|
|
99
|
+
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
103
|
+
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (options.tag) {
|
|
107
|
+
if (typeof options.tag !== 'number') {
|
|
108
|
+
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function assertFileUploadOptions(value) {
|
|
115
|
+
assertUploadOptions(value, 'FileUploadOptions');
|
|
116
|
+
const options = value;
|
|
117
|
+
|
|
118
|
+
if (options.size) {
|
|
119
|
+
if (typeof options.size !== 'number') {
|
|
120
|
+
throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
assertNonNegativeInteger(options.size, 'options.size');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (options.contentType && typeof options.contentType !== 'string') {
|
|
127
|
+
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function assertCollectionUploadOptions(value) {
|
|
131
|
+
assertUploadOptions(value, 'CollectionUploadOptions');
|
|
132
|
+
const options = value;
|
|
133
|
+
|
|
134
|
+
if (options.indexDocument && typeof options.indexDocument !== 'string') {
|
|
135
|
+
throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (options.errorDocument && typeof options.errorDocument !== 'string') {
|
|
139
|
+
throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function isTag(value) {
|
|
143
|
+
if (!isStrictlyObject(value)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const tag = value;
|
|
148
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
149
|
+
const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
|
|
150
|
+
|
|
151
|
+
if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
export function assertTag(value) {
|
|
158
|
+
if (!isStrictlyObject(value)) {
|
|
159
|
+
throw new TypeError('Tag is not an object!');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const tag = value;
|
|
163
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
164
|
+
|
|
165
|
+
for (const numberProperty of numberProperties) {
|
|
166
|
+
if (!tag[numberProperty]) {
|
|
167
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof tag[numberProperty] !== 'number') {
|
|
171
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!tag.startedAt) {
|
|
176
|
+
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (typeof tag.startedAt !== 'string') {
|
|
180
|
+
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export function assertAddressPrefix(value) {
|
|
184
|
+
assertHexString(value, undefined, 'AddressPrefix');
|
|
185
|
+
|
|
186
|
+
if (value.length > PSS_TARGET_HEX_LENGTH_MAX) {
|
|
187
|
+
throw new BeeArgumentError(`AddressPrefix must have length of ${PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function assertPssMessageHandler(value) {
|
|
191
|
+
if (!isStrictlyObject(value)) {
|
|
192
|
+
throw new TypeError('PssMessageHandler has to be object!');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const handler = value;
|
|
196
|
+
|
|
197
|
+
if (typeof handler.onMessage !== 'function') {
|
|
198
|
+
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (typeof handler.onError !== 'function') {
|
|
202
|
+
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export function assertPublicKey(value) {
|
|
206
|
+
assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
207
|
+
}
|
|
208
|
+
export function assertPostageBatchOptions(value) {
|
|
209
|
+
if (value === undefined) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
assertStrictlyObject(value);
|
|
214
|
+
const options = value;
|
|
215
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
216
|
+
|
|
217
|
+
if (options?.gasPrice) {
|
|
218
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (options?.immutableFlag !== undefined) {
|
|
222
|
+
assertBoolean(options.immutableFlag);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export function assertCashoutOptions(value) {
|
|
226
|
+
if (value === undefined) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
assertStrictlyObject(value);
|
|
231
|
+
const options = value;
|
|
232
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
233
|
+
|
|
234
|
+
if (options?.gasLimit) {
|
|
235
|
+
assertNonNegativeInteger(options.gasLimit);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (options?.gasPrice) {
|
|
239
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Check whether the given parameter is valid data to upload
|
|
244
|
+
* @param value
|
|
245
|
+
* @throws TypeError if not valid
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
export function assertData(value) {
|
|
249
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
250
|
+
throw new TypeError('Data must be either string or Uint8Array!');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Check whether the given parameter is a correct file representation to file upload.
|
|
255
|
+
* @param value
|
|
256
|
+
* @throws TypeError if not valid
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
export function assertFileData(value) {
|
|
260
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !isFile(value) && !isReadable(value)) {
|
|
261
|
+
throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Checks whether optional options for AllTags query are valid
|
|
266
|
+
* @param options
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
export function assertAllTagsOptions(entry) {
|
|
270
|
+
if (entry !== undefined && !isStrictlyObject(entry)) {
|
|
271
|
+
throw new TypeError('options has to be an object or undefined!');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
assertRequestOptions(entry, 'AllTagsOptions');
|
|
275
|
+
const options = entry;
|
|
276
|
+
|
|
277
|
+
if (options?.limit !== undefined) {
|
|
278
|
+
if (typeof options.limit !== 'number') {
|
|
279
|
+
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (options.limit < TAGS_LIMIT_MIN) {
|
|
283
|
+
throw new BeeArgumentError(`AllTagsOptions.limit has to be at least ${TAGS_LIMIT_MIN}`, options.limit);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (options.limit > TAGS_LIMIT_MAX) {
|
|
287
|
+
throw new BeeArgumentError(`AllTagsOptions.limit has to be at most ${TAGS_LIMIT_MAX}`, options.limit);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (options?.offset !== undefined) {
|
|
292
|
+
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Utility functions that return Tag UID
|
|
297
|
+
* @param tagUid
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
export function makeTagUid(tagUid) {
|
|
301
|
+
if (tagUid === undefined || tagUid === null) {
|
|
302
|
+
throw new TypeError('TagUid was expected but got undefined or null instead!');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (isTag(tagUid)) {
|
|
306
|
+
return tagUid.uid;
|
|
307
|
+
} else if (typeof tagUid === 'number') {
|
|
308
|
+
assertNonNegativeInteger(tagUid, 'UID');
|
|
309
|
+
return tagUid;
|
|
310
|
+
} else if (typeof tagUid === 'string') {
|
|
311
|
+
const int = parseInt(tagUid);
|
|
312
|
+
|
|
313
|
+
if (isNaN(int)) {
|
|
314
|
+
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (int < 0) {
|
|
318
|
+
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return int;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
325
|
+
}
|
|
326
|
+
export function assertTransactionHash(transactionHash) {
|
|
327
|
+
if (typeof transactionHash !== 'string') {
|
|
328
|
+
throw new TypeError('TransactionHash has to be a string!');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
assertPrefixedHexString(transactionHash, 'TransactionHash'); // Hash is 64 long + '0x' prefix = 66
|
|
332
|
+
|
|
333
|
+
if (transactionHash.length !== 66) {
|
|
334
|
+
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeBytes } from "./bytes.js"; // TODO handle bigger values than 32 bit
|
|
2
|
+
// For now it's good enough because we only use these functions
|
|
3
|
+
// sequential feed indexes.
|
|
4
|
+
|
|
5
|
+
export function writeUint64LittleEndian(value, bytes = makeBytes(8)) {
|
|
6
|
+
const dataView = new DataView(bytes.buffer);
|
|
7
|
+
const valueLower32 = value & 0xffffffff;
|
|
8
|
+
const littleEndian = true;
|
|
9
|
+
dataView.setUint32(0, valueLower32, littleEndian);
|
|
10
|
+
dataView.setUint32(4, 0, littleEndian);
|
|
11
|
+
return bytes;
|
|
12
|
+
}
|
|
13
|
+
export function writeUint64BigEndian(value, bytes = makeBytes(8)) {
|
|
14
|
+
const dataView = new DataView(bytes.buffer);
|
|
15
|
+
const valueLower32 = value & 0xffffffff;
|
|
16
|
+
dataView.setUint32(0, 0);
|
|
17
|
+
dataView.setUint32(4, valueLower32);
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
export function readUint64BigEndian(bytes) {
|
|
21
|
+
const dataView = new DataView(bytes.buffer);
|
|
22
|
+
return dataView.getUint32(4);
|
|
23
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BeeArgumentError } from "./error.js";
|
|
2
|
+
import { isObject } from "./type.js";
|
|
3
|
+
|
|
4
|
+
function isNodeJsError(e) {
|
|
5
|
+
return isObject(e) && typeof e.code === 'string';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Validates that passed string is valid URL of Bee.
|
|
9
|
+
* We support only HTTP and HTTPS protocols.
|
|
10
|
+
*
|
|
11
|
+
* @param url
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function isValidBeeUrl(url) {
|
|
16
|
+
try {
|
|
17
|
+
if (typeof url !== 'string') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const urlObject = new URL(url); // There can be wide range of protocols passed.
|
|
22
|
+
|
|
23
|
+
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:';
|
|
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
|
+
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
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
|
+
|
|
41
|
+
export function assertBeeUrl(url) {
|
|
42
|
+
if (!isValidBeeUrl(url)) {
|
|
43
|
+
throw new BeeArgumentError('URL is not valid!', url);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Removes trailing slash out of the given string.
|
|
48
|
+
* @param url
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export function stripLastSlash(url) {
|
|
52
|
+
if (url.endsWith('/')) {
|
|
53
|
+
return url.slice(0, -1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, DebugPostageBatch, TransactionInfo, TransactionHash, NodeInfo } from './types';
|
|
1
|
+
import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, DebugPostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions } from './types';
|
|
2
2
|
import { BatchId, BeeOptions, CashoutOptions, PostageBatchOptions, RequestOptions, Tag } from './types';
|
|
3
3
|
export declare class BeeDebug {
|
|
4
4
|
/**
|
|
@@ -125,8 +125,54 @@ export declare class BeeDebug {
|
|
|
125
125
|
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
126
126
|
*
|
|
127
127
|
* @returns true if the Bee node version is supported
|
|
128
|
+
* @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
|
|
128
129
|
*/
|
|
129
130
|
isSupportedVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
131
|
+
/**
|
|
132
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
133
|
+
*
|
|
134
|
+
* Be aware that this is the most strict version check and most probably
|
|
135
|
+
* you will want to use more relaxed API-versions based checks like
|
|
136
|
+
* `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
|
|
137
|
+
* based on your use-case.
|
|
138
|
+
*
|
|
139
|
+
* @param options
|
|
140
|
+
*/
|
|
141
|
+
isSupportedExactVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
142
|
+
/**
|
|
143
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
144
|
+
*
|
|
145
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
146
|
+
* and want to make sure about compatibility.
|
|
147
|
+
*
|
|
148
|
+
* @param options
|
|
149
|
+
*/
|
|
150
|
+
isSupportedMainApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
151
|
+
/**
|
|
152
|
+
* Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
|
|
153
|
+
*
|
|
154
|
+
* This is useful if you are not using `Bee` class in your application and want to make sure
|
|
155
|
+
* about compatibility.
|
|
156
|
+
*
|
|
157
|
+
* @param options
|
|
158
|
+
*/
|
|
159
|
+
isSupportedDebugApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
|
|
163
|
+
*
|
|
164
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
165
|
+
*
|
|
166
|
+
* @param options
|
|
167
|
+
*/
|
|
168
|
+
isSupportedApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
169
|
+
/**
|
|
170
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
171
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
172
|
+
*
|
|
173
|
+
* @param options
|
|
174
|
+
*/
|
|
175
|
+
getVersions(options?: RequestOptions): Promise<BeeVersions> | never;
|
|
130
176
|
/**
|
|
131
177
|
* Get reserve state
|
|
132
178
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Health, NodeInfo } from '../../types/debug';
|
|
2
|
+
import { Ky } from '../../types';
|
|
3
|
+
import { BeeVersions } from '../../types/debug';
|
|
4
|
+
export declare const SUPPORTED_BEE_VERSION_EXACT = "1.4.3-1213e063";
|
|
5
|
+
export declare const SUPPORTED_API_VERSION = "2.0.0";
|
|
6
|
+
export declare const SUPPORTED_DEBUG_API_VERSION = "1.2.1";
|
|
7
|
+
export declare const SUPPORTED_BEE_VERSION: string;
|
|
8
|
+
/**
|
|
9
|
+
* Get health of node
|
|
10
|
+
*
|
|
11
|
+
* @param ky Ky debug instance
|
|
12
|
+
*/
|
|
13
|
+
export declare function getHealth(ky: Ky): Promise<Health>;
|
|
14
|
+
/**
|
|
15
|
+
* Get information about Bee node
|
|
16
|
+
*
|
|
17
|
+
* @param ky Ky debug instance
|
|
18
|
+
*/
|
|
19
|
+
export declare function getNodeInfo(ky: Ky): Promise<NodeInfo>;
|
|
20
|
+
/**
|
|
21
|
+
* Connects to a node and checks if it is a supported Bee version by the bee-js
|
|
22
|
+
*
|
|
23
|
+
* @param ky Ky debug instance
|
|
24
|
+
*
|
|
25
|
+
* @returns true if the Bee node version is supported
|
|
26
|
+
* @deprecated Use `isSupportedExactVersion` instead
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSupportedVersion(ky: Ky): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
31
|
+
*
|
|
32
|
+
* Be aware that this is the most strict version check and most probably
|
|
33
|
+
* you will want to use more relaxed API-versions based checks like
|
|
34
|
+
* `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion`
|
|
35
|
+
* based on your use-case.
|
|
36
|
+
*
|
|
37
|
+
* @param ky
|
|
38
|
+
*/
|
|
39
|
+
export declare function isSupportedExactVersion(ky: Ky): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
42
|
+
*
|
|
43
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
44
|
+
* and want to make sure about compatibility.
|
|
45
|
+
*
|
|
46
|
+
* @param ky
|
|
47
|
+
*/
|
|
48
|
+
export declare function isSupportedMainApiVersion(ky: Ky): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
|
|
51
|
+
*
|
|
52
|
+
* This is useful if you are not using `Bee` class in your application and want to make sure
|
|
53
|
+
* about compatibility.
|
|
54
|
+
*
|
|
55
|
+
* @param ky
|
|
56
|
+
*/
|
|
57
|
+
export declare function isSupportedDebugApiVersion(ky: Ky): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
|
|
60
|
+
*
|
|
61
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
62
|
+
*
|
|
63
|
+
* @param ky
|
|
64
|
+
*/
|
|
65
|
+
export declare function isSupportedApiVersion(ky: Ky): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
68
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
69
|
+
*
|
|
70
|
+
* @param ky
|
|
71
|
+
*/
|
|
72
|
+
export declare function getVersions(ky: Ky): Promise<BeeVersions>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -121,6 +121,14 @@ export interface Health {
|
|
|
121
121
|
apiVersion: string;
|
|
122
122
|
debugApiVersion: string;
|
|
123
123
|
}
|
|
124
|
+
export interface BeeVersions {
|
|
125
|
+
supportedBeeVersion: string;
|
|
126
|
+
supportedBeeApiVersion: string;
|
|
127
|
+
supportedBeeDebugApiVersion: string;
|
|
128
|
+
beeVersion: string;
|
|
129
|
+
beeApiVersion: string;
|
|
130
|
+
beeDebugApiVersion: string;
|
|
131
|
+
}
|
|
124
132
|
export declare enum BeeModes {
|
|
125
133
|
FULL = "full",
|
|
126
134
|
LIGHT = "light",
|
|
@@ -10,8 +10,8 @@ import type { HexString } from '../utils/hex';
|
|
|
10
10
|
import type ky from 'ky-universal';
|
|
11
11
|
import type { Readable as NativeReadable } from 'stream';
|
|
12
12
|
import type { Readable as CompatibilityReadable } from 'readable-stream';
|
|
13
|
-
import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill
|
|
14
|
-
import { Options as KyOptions } from 'ky-
|
|
13
|
+
import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill';
|
|
14
|
+
import { Options as KyOptions } from './ky-options';
|
|
15
15
|
export * from './debug';
|
|
16
16
|
export declare type Ky = typeof ky;
|
|
17
17
|
export interface Dictionary<T> {
|
|
@@ -362,6 +362,7 @@ export interface FeedWriter extends FeedReader {
|
|
|
362
362
|
* Interface for downloading single owner chunks
|
|
363
363
|
*/
|
|
364
364
|
export interface SOCReader {
|
|
365
|
+
readonly owner: HexEthAddress;
|
|
365
366
|
/**
|
|
366
367
|
* Downloads a single owner chunk
|
|
367
368
|
*
|