@ethersphere/bee-js 2.1.0 → 3.2.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 +3 -3
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +5 -1
- package/dist/src/bee.d.ts +23 -46
- package/dist/src/modules/chunk.d.ts +2 -10
- package/dist/src/modules/debug/status.d.ts +10 -4
- package/dist/src/types/debug.d.ts +19 -0
- package/dist/src/types/index.d.ts +31 -2
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/error.d.ts +21 -2
- package/dist/src/utils/expose.d.ts +1 -0
- package/dist/src/utils/http.d.ts +7 -9
- package/dist/src/utils/stamps.d.ts +12 -0
- package/dist/src/utils/type.d.ts +6 -0
- package/package.json +28 -27
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -109
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CHANGELOG.md +0 -520
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -85
- package/src/bee-debug.ts +0 -601
- package/src/bee.ts +0 -1087
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -217
- package/src/feed/json.ts +0 -33
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -70
- package/src/modules/bzz.ts +0 -179
- package/src/modules/chunk.ts +0 -69
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -175
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -96
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -105
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -49
- package/src/modules/soc.ts +0 -40
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -32
- package/src/modules/tag.ts +0 -83
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -561
- package/src/types/ky-universal/common.d.ts +0 -17
- package/src/types/ky-universal/hooks.d.ts +0 -103
- package/src/types/ky-universal/index.d.ts +0 -125
- package/src/types/ky-universal/options.d.ts +0 -235
- package/src/types/ky-universal/response.d.ts +0 -38
- package/src/types/ky-universal/retry.d.ts +0 -39
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -68
- package/src/utils/data.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -48
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/http.ts +0 -141
- package/src/utils/merge.ts +0 -34
- package/src/utils/pss.ts +0 -16
- package/src/utils/stream.ts +0 -146
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -394
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -272
- package/test/integration/bee-class.spec.ts +0 -648
- package/test/integration/bee-debug-class.spec.ts +0 -114
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -265
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/debug/transactions.spec.ts +0 -10
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -105
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/tests-setup.ts +0 -94
- package/test/unit/assertions.ts +0 -460
- package/test/unit/bee-class.spec.ts +0 -976
- package/test/unit/bee-debug-class.spec.ts +0 -435
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -151
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/stream.spec.ts +0 -30
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -426
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
package/src/utils/type.ts
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address,
|
|
3
|
-
ADDRESS_HEX_LENGTH,
|
|
4
|
-
AddressPrefix,
|
|
5
|
-
AllTagsOptions,
|
|
6
|
-
BATCH_ID_HEX_LENGTH,
|
|
7
|
-
BatchId,
|
|
8
|
-
CollectionUploadOptions,
|
|
9
|
-
ENCRYPTED_REFERENCE_HEX_LENGTH,
|
|
10
|
-
FileUploadOptions,
|
|
11
|
-
NumberString,
|
|
12
|
-
PssMessageHandler,
|
|
13
|
-
PUBKEY_HEX_LENGTH,
|
|
14
|
-
PublicKey,
|
|
15
|
-
Readable,
|
|
16
|
-
Reference,
|
|
17
|
-
REFERENCE_HEX_LENGTH,
|
|
18
|
-
Tag,
|
|
19
|
-
TAGS_LIMIT_MAX,
|
|
20
|
-
TAGS_LIMIT_MIN,
|
|
21
|
-
PSS_TARGET_HEX_LENGTH_MAX,
|
|
22
|
-
UploadOptions,
|
|
23
|
-
TransactionHash,
|
|
24
|
-
RequestOptions,
|
|
25
|
-
PostageBatchOptions,
|
|
26
|
-
CashoutOptions,
|
|
27
|
-
} from '../types'
|
|
28
|
-
import { BeeArgumentError } from './error'
|
|
29
|
-
import { isFile } from './file'
|
|
30
|
-
import { assertHexString, assertPrefixedHexString } from './hex'
|
|
31
|
-
import { isReadable } from './stream'
|
|
32
|
-
|
|
33
|
-
export function isUint8Array(obj: unknown): obj is Uint8Array {
|
|
34
|
-
return obj instanceof Uint8Array
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function isInteger(value: unknown): value is number | NumberString {
|
|
38
|
-
return (
|
|
39
|
-
(typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
|
|
40
|
-
(typeof value === 'number' &&
|
|
41
|
-
value > Number.MIN_SAFE_INTEGER &&
|
|
42
|
-
value < Number.MAX_SAFE_INTEGER &&
|
|
43
|
-
Number.isInteger(value))
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
48
|
-
return value !== null && typeof value === 'object'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Generally it is discouraged to use `object` type, but in this case I think
|
|
53
|
-
* it is best to do so as it is possible to easily convert from `object`to other
|
|
54
|
-
* types, which will be usually the case after asserting that the object is
|
|
55
|
-
* strictly object. With for example Record<string, unknown> you have to first
|
|
56
|
-
* cast it to `unknown` which I think bit defeat the purpose.
|
|
57
|
-
*
|
|
58
|
-
* @param value
|
|
59
|
-
*/
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
61
|
-
export function isStrictlyObject(value: unknown): value is object {
|
|
62
|
-
return isObject(value) && !Array.isArray(value)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
66
|
-
export function assertStrictlyObject(value: unknown, name = 'value'): asserts value is object {
|
|
67
|
-
if (!isStrictlyObject(value)) {
|
|
68
|
-
throw new TypeError(`${name} has to be an object that is not null nor array!`)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function assertBoolean(value: unknown, name = 'value'): asserts value is boolean {
|
|
73
|
-
if (value !== true && value !== false) throw new TypeError(`${name} is not boolean`)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function assertInteger(value: unknown, name = 'value'): asserts value is number | NumberString {
|
|
77
|
-
if (!isInteger(value)) throw new TypeError(`${name} is not integer`)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function assertNonNegativeInteger(value: unknown, name = 'Value'): asserts value is number | NumberString {
|
|
81
|
-
assertInteger(value, name)
|
|
82
|
-
|
|
83
|
-
if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function assertReference(value: unknown): asserts value is Reference {
|
|
87
|
-
try {
|
|
88
|
-
assertHexString(value, REFERENCE_HEX_LENGTH)
|
|
89
|
-
} catch (e) {
|
|
90
|
-
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function assertAddress(value: unknown): asserts value is Address {
|
|
95
|
-
assertHexString(value, ADDRESS_HEX_LENGTH, 'Address')
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function assertBatchId(value: unknown): asserts value is BatchId {
|
|
99
|
-
assertHexString(value, BATCH_ID_HEX_LENGTH, 'BatchId')
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function assertRequestOptions(value: unknown, name = 'RequestOptions'): asserts value is RequestOptions {
|
|
103
|
-
if (value === undefined) {
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!isStrictlyObject(value)) {
|
|
108
|
-
throw new TypeError(`${name} has to be an object!`)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const options = value as RequestOptions
|
|
112
|
-
|
|
113
|
-
if (options.retry) {
|
|
114
|
-
assertNonNegativeInteger(options.retry, `${name}.retry`)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (options.timeout) {
|
|
118
|
-
assertNonNegativeInteger(options.timeout, `${name}.timeout`)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (options.fetch && typeof options.fetch !== 'function') {
|
|
122
|
-
throw new TypeError(`${name}.fetch has to be a function or undefined!`)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function assertUploadOptions(value: unknown, name = 'UploadOptions'): asserts value is UploadOptions {
|
|
127
|
-
if (!isStrictlyObject(value)) {
|
|
128
|
-
throw new TypeError(`${name} has to be an object!`)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
assertRequestOptions(value, name)
|
|
132
|
-
|
|
133
|
-
const options = value as UploadOptions
|
|
134
|
-
|
|
135
|
-
if (options.pin && typeof options.pin !== 'boolean') {
|
|
136
|
-
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
140
|
-
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (options.tag) {
|
|
144
|
-
if (typeof options.tag !== 'number') {
|
|
145
|
-
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
assertNonNegativeInteger(options.tag, 'options.tag')
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function assertFileUploadOptions(value: unknown): asserts value is FileUploadOptions {
|
|
153
|
-
assertUploadOptions(value, 'FileUploadOptions')
|
|
154
|
-
|
|
155
|
-
const options = value as FileUploadOptions
|
|
156
|
-
|
|
157
|
-
if (options.size) {
|
|
158
|
-
if (typeof options.size !== 'number') {
|
|
159
|
-
throw new TypeError('tag property in FileUploadOptions has to be number or undefined!')
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
assertNonNegativeInteger(options.size, 'options.size')
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (options.contentType && typeof options.contentType !== 'string') {
|
|
166
|
-
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!')
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function assertCollectionUploadOptions(value: unknown): asserts value is CollectionUploadOptions {
|
|
171
|
-
assertUploadOptions(value, 'CollectionUploadOptions')
|
|
172
|
-
|
|
173
|
-
const options = value as CollectionUploadOptions
|
|
174
|
-
|
|
175
|
-
if (options.indexDocument && typeof options.indexDocument !== 'string') {
|
|
176
|
-
throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (options.errorDocument && typeof options.errorDocument !== 'string') {
|
|
180
|
-
throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!')
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function isTag(value: unknown): value is Tag {
|
|
185
|
-
if (!isStrictlyObject(value)) {
|
|
186
|
-
return false
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const tag = value as Record<string, unknown>
|
|
190
|
-
|
|
191
|
-
const numberProperties = ['total', 'processed', 'synced', 'uid']
|
|
192
|
-
const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number')
|
|
193
|
-
|
|
194
|
-
if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
|
|
195
|
-
return false
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return true
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function assertTag(value: unknown): asserts value is Tag {
|
|
202
|
-
if (!isStrictlyObject(value)) {
|
|
203
|
-
throw new TypeError('Tag is not an object!')
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const tag = value as Record<string, unknown>
|
|
207
|
-
|
|
208
|
-
const numberProperties = ['total', 'processed', 'synced', 'uid']
|
|
209
|
-
for (const numberProperty of numberProperties) {
|
|
210
|
-
if (!tag[numberProperty]) {
|
|
211
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (typeof tag[numberProperty] !== 'number') {
|
|
215
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (!tag.startedAt) {
|
|
220
|
-
throw new TypeError("Tag's property 'startedAt' has to be specified!")
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (typeof tag.startedAt !== 'string') {
|
|
224
|
-
throw new TypeError("Tag's property 'startedAt' has to be string!")
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export function assertAddressPrefix(value: unknown): asserts value is AddressPrefix {
|
|
229
|
-
assertHexString(value, undefined, 'AddressPrefix')
|
|
230
|
-
|
|
231
|
-
if (value.length > PSS_TARGET_HEX_LENGTH_MAX) {
|
|
232
|
-
throw new BeeArgumentError(
|
|
233
|
-
`AddressPrefix must have length of ${PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`,
|
|
234
|
-
value,
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function assertPssMessageHandler(value: unknown): asserts value is PssMessageHandler {
|
|
240
|
-
if (!isStrictlyObject(value)) {
|
|
241
|
-
throw new TypeError('PssMessageHandler has to be object!')
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const handler = value as unknown as PssMessageHandler
|
|
245
|
-
|
|
246
|
-
if (typeof handler.onMessage !== 'function') {
|
|
247
|
-
throw new TypeError('onMessage property of PssMessageHandler has to be function!')
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (typeof handler.onError !== 'function') {
|
|
251
|
-
throw new TypeError('onError property of PssMessageHandler has to be function!')
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export function assertPublicKey(value: unknown): asserts value is PublicKey {
|
|
256
|
-
assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey')
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export function assertPostageBatchOptions(value: unknown): asserts value is PostageBatchOptions {
|
|
260
|
-
if (value === undefined) {
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
assertStrictlyObject(value)
|
|
265
|
-
|
|
266
|
-
const options = value as PostageBatchOptions
|
|
267
|
-
assertRequestOptions(options, 'PostageBatchOptions')
|
|
268
|
-
|
|
269
|
-
if (options?.gasPrice) {
|
|
270
|
-
assertNonNegativeInteger(options.gasPrice)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (options?.immutableFlag !== undefined) {
|
|
274
|
-
assertBoolean(options.immutableFlag)
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function assertCashoutOptions(value: unknown): asserts value is CashoutOptions {
|
|
279
|
-
if (value === undefined) {
|
|
280
|
-
return
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
assertStrictlyObject(value)
|
|
284
|
-
|
|
285
|
-
const options = value as CashoutOptions
|
|
286
|
-
assertRequestOptions(options, 'PostageBatchOptions')
|
|
287
|
-
|
|
288
|
-
if (options?.gasLimit) {
|
|
289
|
-
assertNonNegativeInteger(options.gasLimit)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (options?.gasPrice) {
|
|
293
|
-
assertNonNegativeInteger(options.gasPrice)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Check whether the given parameter is valid data to upload
|
|
299
|
-
* @param value
|
|
300
|
-
* @throws TypeError if not valid
|
|
301
|
-
*/
|
|
302
|
-
export function assertData(value: unknown): asserts value is string | Uint8Array {
|
|
303
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
304
|
-
throw new TypeError('Data must be either string or Uint8Array!')
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Check whether the given parameter is a correct file representation to file upload.
|
|
310
|
-
* @param value
|
|
311
|
-
* @throws TypeError if not valid
|
|
312
|
-
*/
|
|
313
|
-
export function assertFileData(value: unknown): asserts value is string | Uint8Array | Readable | File {
|
|
314
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !isFile(value) && !isReadable(value)) {
|
|
315
|
-
throw new TypeError('Data must be either string, Readable, Uint8Array or File!')
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Checks whether optional options for AllTags query are valid
|
|
321
|
-
* @param options
|
|
322
|
-
*/
|
|
323
|
-
export function assertAllTagsOptions(entry: unknown): asserts entry is AllTagsOptions {
|
|
324
|
-
if (entry !== undefined && !isStrictlyObject(entry)) {
|
|
325
|
-
throw new TypeError('options has to be an object or undefined!')
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
assertRequestOptions(entry, 'AllTagsOptions')
|
|
329
|
-
|
|
330
|
-
const options = entry as AllTagsOptions
|
|
331
|
-
|
|
332
|
-
if (options?.limit !== undefined) {
|
|
333
|
-
if (typeof options.limit !== 'number') {
|
|
334
|
-
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!')
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (options.limit < TAGS_LIMIT_MIN) {
|
|
338
|
-
throw new BeeArgumentError(`AllTagsOptions.limit has to be at least ${TAGS_LIMIT_MIN}`, options.limit)
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (options.limit > TAGS_LIMIT_MAX) {
|
|
342
|
-
throw new BeeArgumentError(`AllTagsOptions.limit has to be at most ${TAGS_LIMIT_MAX}`, options.limit)
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (options?.offset !== undefined) {
|
|
347
|
-
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset')
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Utility functions that return Tag UID
|
|
353
|
-
* @param tagUid
|
|
354
|
-
*/
|
|
355
|
-
export function makeTagUid(tagUid: number | Tag | string | null | undefined): number {
|
|
356
|
-
if (tagUid === undefined || tagUid === null) {
|
|
357
|
-
throw new TypeError('TagUid was expected but got undefined or null instead!')
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (isTag(tagUid)) {
|
|
361
|
-
return tagUid.uid
|
|
362
|
-
} else if (typeof tagUid === 'number') {
|
|
363
|
-
assertNonNegativeInteger(tagUid, 'UID')
|
|
364
|
-
|
|
365
|
-
return tagUid
|
|
366
|
-
} else if (typeof tagUid === 'string') {
|
|
367
|
-
const int = parseInt(tagUid)
|
|
368
|
-
|
|
369
|
-
if (isNaN(int)) {
|
|
370
|
-
throw new TypeError('Passed tagUid string is not valid integer!')
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (int < 0) {
|
|
374
|
-
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return int
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
throw new TypeError('tagUid has to be either Tag or a number (UID)!')
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export function assertTransactionHash(transactionHash: unknown): asserts transactionHash is TransactionHash {
|
|
384
|
-
if (typeof transactionHash !== 'string') {
|
|
385
|
-
throw new TypeError('TransactionHash has to be a string!')
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
assertPrefixedHexString(transactionHash, 'TransactionHash')
|
|
389
|
-
|
|
390
|
-
// Hash is 64 long + '0x' prefix = 66
|
|
391
|
-
if (transactionHash.length !== 66) {
|
|
392
|
-
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)')
|
|
393
|
-
}
|
|
394
|
-
}
|
package/src/utils/uint64.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Bytes, makeBytes } from './bytes'
|
|
2
|
-
|
|
3
|
-
// TODO handle bigger values than 32 bit
|
|
4
|
-
// For now it's good enough because we only use these functions
|
|
5
|
-
// sequential feed indexes.
|
|
6
|
-
export function writeUint64LittleEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
|
|
7
|
-
const dataView = new DataView(bytes.buffer)
|
|
8
|
-
const valueLower32 = value & 0xffffffff
|
|
9
|
-
const littleEndian = true
|
|
10
|
-
|
|
11
|
-
dataView.setUint32(0, valueLower32, littleEndian)
|
|
12
|
-
dataView.setUint32(4, 0, littleEndian)
|
|
13
|
-
|
|
14
|
-
return bytes
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function writeUint64BigEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
|
|
18
|
-
const dataView = new DataView(bytes.buffer)
|
|
19
|
-
const valueLower32 = value & 0xffffffff
|
|
20
|
-
|
|
21
|
-
dataView.setUint32(0, 0)
|
|
22
|
-
dataView.setUint32(4, valueLower32)
|
|
23
|
-
|
|
24
|
-
return bytes
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function readUint64BigEndian(bytes: Bytes<8>): number {
|
|
28
|
-
const dataView = new DataView(bytes.buffer)
|
|
29
|
-
|
|
30
|
-
return dataView.getUint32(4)
|
|
31
|
-
}
|
package/src/utils/url.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BeeArgumentError } from './error'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validates that passed string is valid URL of Bee.
|
|
5
|
-
* We support only HTTP and HTTPS protocols.
|
|
6
|
-
*
|
|
7
|
-
* @param url
|
|
8
|
-
*/
|
|
9
|
-
export function isValidBeeUrl(url: unknown): url is URL {
|
|
10
|
-
try {
|
|
11
|
-
if (typeof url !== 'string') {
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const urlObject = new URL(url)
|
|
16
|
-
|
|
17
|
-
// There can be wide range of protocols passed.
|
|
18
|
-
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:'
|
|
19
|
-
} catch (e) {
|
|
20
|
-
// URL constructor throws TypeError if not valid URL
|
|
21
|
-
// TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
|
|
22
|
-
if (e instanceof TypeError || (e.code && e.code === 'ERR_INVALID_URL')) {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throw e
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
|
|
32
|
-
* We support only HTTP and HTTPS protocols.
|
|
33
|
-
* @param url
|
|
34
|
-
* @throws BeeArgumentError if non valid URL
|
|
35
|
-
*/
|
|
36
|
-
export function assertBeeUrl(url: unknown): asserts url is URL {
|
|
37
|
-
if (!isValidBeeUrl(url)) {
|
|
38
|
-
throw new BeeArgumentError('URL is not valid!', url)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Removes trailing slash out of the given string.
|
|
44
|
-
* @param url
|
|
45
|
-
*/
|
|
46
|
-
export function stripLastSlash(url: string): string {
|
|
47
|
-
if (url.endsWith('/')) {
|
|
48
|
-
return url.slice(0, -1)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return url
|
|
52
|
-
}
|
package/test/bee.sh
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
echoerr() { if [[ $QUIET -ne 1 ]] ; then echo "$@" 1>&2; fi }
|
|
4
|
-
|
|
5
|
-
usage() {
|
|
6
|
-
cat << USAGE >&2
|
|
7
|
-
USAGE:
|
|
8
|
-
$ bee.sh [COMMAND] [PARAMETERS]
|
|
9
|
-
COMMANDS:
|
|
10
|
-
start create Bee cluster with the given parameters
|
|
11
|
-
stop stop Bee cluster
|
|
12
|
-
PARAMETERS:
|
|
13
|
-
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
|
|
14
|
-
--workers=number all Bee nodes in the test environment. Default is 4.
|
|
15
|
-
--port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
|
|
16
|
-
1. 1633:1635
|
|
17
|
-
2. 11633:11635
|
|
18
|
-
3. 21633:21635 (...)
|
|
19
|
-
number represents the nodes number to map from. Default is 4.
|
|
20
|
-
--password=string password for Bee client(s).
|
|
21
|
-
--version=x.y.z used version of Bee client.
|
|
22
|
-
USAGE
|
|
23
|
-
exit 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
stop() {
|
|
27
|
-
echo "Stop following containers:"
|
|
28
|
-
docker container stop $QUEEN_CONTAINER_NAME;
|
|
29
|
-
WORKER_NAMES=`docker container ls -f name="$WORKER_CONTAINER_NAME*" --format "{{.Names}}"`
|
|
30
|
-
for WORKER_NAME in $WORKER_NAMES; do
|
|
31
|
-
docker container stop "$WORKER_NAME"
|
|
32
|
-
done
|
|
33
|
-
|
|
34
|
-
trap - SIGINT
|
|
35
|
-
exit 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fetch_queen_underlay_addr() {
|
|
39
|
-
if [[ ! -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then return; fi
|
|
40
|
-
|
|
41
|
-
while : ; do
|
|
42
|
-
QUEEN_UNDERLAY_ADDRESS=$(curl -s localhost:1635/addresses | python -mjson.tool 2>&1 | grep "/ip4/" | awk '!/127.0.0.1/' | xargs)
|
|
43
|
-
if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then
|
|
44
|
-
echo "Waiting for the Queen initialization..."
|
|
45
|
-
sleep 5
|
|
46
|
-
else
|
|
47
|
-
break;
|
|
48
|
-
fi
|
|
49
|
-
done
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
log_queen() {
|
|
53
|
-
trap stop SIGINT
|
|
54
|
-
docker logs --tail 25 -f $QUEEN_CONTAINER_NAME
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Init variables
|
|
58
|
-
EPHEMERAL=false
|
|
59
|
-
WORKERS=4
|
|
60
|
-
QUEEN_CONTAINER_NAME="bee-queen-test"
|
|
61
|
-
WORKER_CONTAINER_NAME="bee-worker-test"
|
|
62
|
-
QUEEN_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$QUEEN_CONTAINER_NAME`
|
|
63
|
-
BEE_VERSION="latest"
|
|
64
|
-
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
|
|
65
|
-
BEE_PASSWORD="password"
|
|
66
|
-
QUEEN_BOOTNODE=""
|
|
67
|
-
PORT_MAPS=2
|
|
68
|
-
|
|
69
|
-
# Decide script action
|
|
70
|
-
case "$1" in
|
|
71
|
-
start)
|
|
72
|
-
shift 1
|
|
73
|
-
;;
|
|
74
|
-
stop)
|
|
75
|
-
stop
|
|
76
|
-
;;
|
|
77
|
-
*)
|
|
78
|
-
echoerr "Unknown command: $1"
|
|
79
|
-
usage
|
|
80
|
-
;;
|
|
81
|
-
esac
|
|
82
|
-
|
|
83
|
-
# Alter variables from flags
|
|
84
|
-
while [ $# -gt 0 ]
|
|
85
|
-
do
|
|
86
|
-
case "$1" in
|
|
87
|
-
--ephemeral)
|
|
88
|
-
EPHEMERAL=true
|
|
89
|
-
shift 1
|
|
90
|
-
;;
|
|
91
|
-
--workers=*)
|
|
92
|
-
WORKERS=${1#*=}
|
|
93
|
-
shift 1
|
|
94
|
-
;;
|
|
95
|
-
--password=*)
|
|
96
|
-
BEE_PASSWORD="${1#*=}"
|
|
97
|
-
shift 1
|
|
98
|
-
;;
|
|
99
|
-
--version=*)
|
|
100
|
-
BEE_VERSION="${1#*=}"
|
|
101
|
-
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
|
|
102
|
-
shift 1
|
|
103
|
-
;;
|
|
104
|
-
--port-maps=*)
|
|
105
|
-
PORT_MAPS="${1#*=}"
|
|
106
|
-
shift 1
|
|
107
|
-
;;
|
|
108
|
-
--help)
|
|
109
|
-
usage
|
|
110
|
-
;;
|
|
111
|
-
*)
|
|
112
|
-
echoerr "Unknown argument: $1"
|
|
113
|
-
usage
|
|
114
|
-
;;
|
|
115
|
-
esac
|
|
116
|
-
done
|
|
117
|
-
|
|
118
|
-
if $EPHEMERAL ; then
|
|
119
|
-
EXTRA_DOCKER_PARAMS=" --rm"
|
|
120
|
-
fi
|
|
121
|
-
|
|
122
|
-
# Start Bee Queen
|
|
123
|
-
if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
|
|
124
|
-
EXTRA_QUEEN_PARAMS=""
|
|
125
|
-
if [ $PORT_MAPS -ge 1 ] ; then
|
|
126
|
-
EXTRA_QUEEN_PARAMS=" -p 127.0.0.1:1633-1635:1633-1635"
|
|
127
|
-
fi
|
|
128
|
-
|
|
129
|
-
echo "start Bee Queen process"
|
|
130
|
-
docker run \
|
|
131
|
-
-d \
|
|
132
|
-
--name $QUEEN_CONTAINER_NAME \
|
|
133
|
-
$EXTRA_DOCKER_PARAMS \
|
|
134
|
-
$EXTRA_QUEEN_PARAMS \
|
|
135
|
-
$BEE_IMAGE \
|
|
136
|
-
start \
|
|
137
|
-
--password $BEE_PASSWORD \
|
|
138
|
-
--bootnode=$QUEEN_BOOTNODE \
|
|
139
|
-
--swap-enable=false \
|
|
140
|
-
--debug-api-enable \
|
|
141
|
-
--verbosity=4 \
|
|
142
|
-
--welcome-message="You have found the queen of the beehive..." \
|
|
143
|
-
--cors-allowed-origins="*" \
|
|
144
|
-
--payment-tolerance=2147483647
|
|
145
|
-
else
|
|
146
|
-
docker start "$QUEEN_CONTAINER_IN_DOCKER"
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
# Start Bee workers
|
|
150
|
-
for i in $(seq 1 1 $WORKERS); do
|
|
151
|
-
WORKER_NAME="$WORKER_CONTAINER_NAME-$i"
|
|
152
|
-
WORKER_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$WORKER_NAME`
|
|
153
|
-
if [ -z "$WORKER_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
|
|
154
|
-
# fetch queen underlay address
|
|
155
|
-
fetch_queen_underlay_addr
|
|
156
|
-
|
|
157
|
-
# construct additional params
|
|
158
|
-
EXTRA_WORKER_PARAMS=""
|
|
159
|
-
if [ $PORT_MAPS -gt $i ] ; then
|
|
160
|
-
PORT_START=$((1633+(10000*$i)))
|
|
161
|
-
PORT_END=$(($PORT_START + 2))
|
|
162
|
-
EXTRA_WORKER_PARAMS=" -p 127.0.0.1:$PORT_START-$PORT_END:1633-1635"
|
|
163
|
-
fi
|
|
164
|
-
|
|
165
|
-
# run docker container
|
|
166
|
-
echo "start Bee worker $i process"
|
|
167
|
-
docker run \
|
|
168
|
-
-d \
|
|
169
|
-
--name $WORKER_NAME \
|
|
170
|
-
$EXTRA_DOCKER_PARAMS \
|
|
171
|
-
$EXTRA_WORKER_PARAMS \
|
|
172
|
-
$BEE_IMAGE \
|
|
173
|
-
start \
|
|
174
|
-
--password $BEE_PASSWORD \
|
|
175
|
-
--bootnode="$QUEEN_UNDERLAY_ADDRESS" \
|
|
176
|
-
--swap-enable=false \
|
|
177
|
-
--debug-api-enable \
|
|
178
|
-
--welcome-message="I'm just Bee worker ${i} in the beehive." \
|
|
179
|
-
--cors-allowed-origins="*" \
|
|
180
|
-
--payment-tolerance=2147483647
|
|
181
|
-
else
|
|
182
|
-
docker start "$WORKER_CONTAINER_IN_DOCKER"
|
|
183
|
-
fi
|
|
184
|
-
done
|
|
185
|
-
|
|
186
|
-
# log Bee Queen
|
|
187
|
-
log_queen
|
package/test/data/1.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1
|
package/test/data/2.txt
DELETED
|
File without changes
|
package/test/data/empty
DELETED
|
File without changes
|
package/test/data/sub/3.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
3
|
package/test/data/sub//303/251
DELETED
|
File without changes
|
|
File without changes
|