@ethersphere/bee-js 2.0.0 → 3.1.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/CHANGELOG.md +91 -0
- package/README.md +2 -2
- 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 +38 -6
- package/dist/src/bee.d.ts +34 -46
- package/dist/src/modules/chunk.d.ts +2 -10
- package/dist/src/modules/debug/stamps.d.ts +2 -0
- package/dist/src/modules/debug/status.d.ts +10 -4
- package/dist/src/modules/stewardship.d.ts +1 -0
- package/dist/src/types/debug.d.ts +11 -0
- package/dist/src/types/index.d.ts +6 -7
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/expose.d.ts +1 -0
- package/dist/src/utils/stamps.d.ts +12 -0
- package/package.json +10 -8
- 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/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 -559
- package/src/bee.ts +0 -1070
- 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 -76
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -35
- 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 -18
- package/src/modules/tag.ts +0 -83
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -566
- 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 -631
- package/test/integration/bee-debug-class.spec.ts +0 -85
- 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 -97
- 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 -328
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-empty-function: 0 */
|
|
2
|
-
import { NumberString } from '../../../src/types'
|
|
3
|
-
import { isInteger } from '../../../src/utils/type'
|
|
4
|
-
|
|
5
|
-
describe('type', () => {
|
|
6
|
-
describe('isInteger', () => {
|
|
7
|
-
const wrongValues = [
|
|
8
|
-
() => {},
|
|
9
|
-
Number.MAX_SAFE_INTEGER + 1,
|
|
10
|
-
Number.MIN_SAFE_INTEGER - 1,
|
|
11
|
-
5.000000000000001,
|
|
12
|
-
false,
|
|
13
|
-
true,
|
|
14
|
-
Infinity,
|
|
15
|
-
NaN,
|
|
16
|
-
[1],
|
|
17
|
-
]
|
|
18
|
-
const correctValues = [5, 0, '10', 5.0000000000000001, '-1']
|
|
19
|
-
|
|
20
|
-
wrongValues.forEach((v: unknown | NumberString) =>
|
|
21
|
-
test(`should return false for value ${v}`, () => {
|
|
22
|
-
expect(isInteger(v)).toEqual(false)
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
correctValues.forEach((v: unknown | NumberString) =>
|
|
27
|
-
test(`should return true for value ${v}`, () => {
|
|
28
|
-
expect(isInteger(v)).toEqual(true)
|
|
29
|
-
}),
|
|
30
|
-
)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Bytes, makeBytes } from '../../../src/utils/bytes'
|
|
2
|
-
import { HexString, hexToBytes } from '../../../src/utils/hex'
|
|
3
|
-
import { readUint64BigEndian, writeUint64BigEndian, writeUint64LittleEndian } from '../../../src/utils/uint64'
|
|
4
|
-
|
|
5
|
-
describe('uint64', () => {
|
|
6
|
-
describe('little endian', () => {
|
|
7
|
-
test('zero', () => {
|
|
8
|
-
const uint64 = writeUint64LittleEndian(0)
|
|
9
|
-
const zero = makeBytes(8)
|
|
10
|
-
|
|
11
|
-
expect(uint64).toEqual(zero)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('one', () => {
|
|
15
|
-
const uint64 = writeUint64LittleEndian(1)
|
|
16
|
-
const one = hexToBytes('0100000000000000' as HexString)
|
|
17
|
-
|
|
18
|
-
expect(uint64).toEqual(one)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('deadbeef', () => {
|
|
22
|
-
const uint64 = writeUint64LittleEndian(0xdeadbeef)
|
|
23
|
-
const deadbeef = hexToBytes('efbeadde00000000' as HexString)
|
|
24
|
-
|
|
25
|
-
expect(uint64).toEqual(deadbeef)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('big endian', () => {
|
|
30
|
-
describe('write', () => {
|
|
31
|
-
test('zero', () => {
|
|
32
|
-
const uint64 = writeUint64BigEndian(0)
|
|
33
|
-
const zero = makeBytes(8)
|
|
34
|
-
|
|
35
|
-
expect(uint64).toEqual(zero)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('one', () => {
|
|
39
|
-
const uint64 = writeUint64BigEndian(1)
|
|
40
|
-
const one = hexToBytes('0000000000000001' as HexString)
|
|
41
|
-
|
|
42
|
-
expect(uint64).toEqual(one)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('deadbeef', () => {
|
|
46
|
-
const uint64 = writeUint64BigEndian(0xdeadbeef)
|
|
47
|
-
const deadbeef = hexToBytes('00000000deadbeef' as HexString)
|
|
48
|
-
|
|
49
|
-
expect(uint64).toEqual(deadbeef)
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
describe('read', () => {
|
|
54
|
-
test('zero', () => {
|
|
55
|
-
const zero = makeBytes(8)
|
|
56
|
-
const value = readUint64BigEndian(zero)
|
|
57
|
-
|
|
58
|
-
expect(value).toEqual(0)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('one', () => {
|
|
62
|
-
const one = hexToBytes('0000000000000001' as HexString) as Bytes<8>
|
|
63
|
-
const value = readUint64BigEndian(one)
|
|
64
|
-
|
|
65
|
-
expect(value).toEqual(1)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test('deadbeef', () => {
|
|
69
|
-
const deadbeef = hexToBytes('00000000deadbeef' as HexString) as Bytes<8>
|
|
70
|
-
const value = readUint64BigEndian(deadbeef)
|
|
71
|
-
|
|
72
|
-
expect(value).toEqual(0xdeadbeef)
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
describe('read and write', () => {
|
|
77
|
-
test('zero', () => {
|
|
78
|
-
const zero = makeBytes(8)
|
|
79
|
-
const num = readUint64BigEndian(zero)
|
|
80
|
-
const value = writeUint64BigEndian(num)
|
|
81
|
-
|
|
82
|
-
expect(value).toEqual(zero)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('one', () => {
|
|
86
|
-
const one = hexToBytes('0000000000000001' as HexString) as Bytes<8>
|
|
87
|
-
const num = readUint64BigEndian(one)
|
|
88
|
-
const value = writeUint64BigEndian(num)
|
|
89
|
-
|
|
90
|
-
expect(value).toEqual(one)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
test('deadbeef', () => {
|
|
94
|
-
const deadbeef = hexToBytes('00000000deadbeef' as HexString) as Bytes<8>
|
|
95
|
-
const num = readUint64BigEndian(deadbeef)
|
|
96
|
-
const value = writeUint64BigEndian(num)
|
|
97
|
-
|
|
98
|
-
expect(value).toEqual(deadbeef)
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
})
|
package/test/utils.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream'
|
|
2
|
-
import type { Ky, BeeGenericResponse, Reference, Address, BatchId } from '../src/types'
|
|
3
|
-
import { bytesToHex, HexString } from '../src/utils/hex'
|
|
4
|
-
import { deleteChunkFromLocalStorage } from '../src/modules/debug/chunk'
|
|
5
|
-
import { BeeResponseError } from '../src'
|
|
6
|
-
import { ChunkAddress } from '../src/chunk/cac'
|
|
7
|
-
import { assertBytes } from '../src/utils/bytes'
|
|
8
|
-
import ky from 'ky-universal'
|
|
9
|
-
import { ReadableStream } from 'web-streams-polyfill/ponyfill'
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
13
|
-
namespace jest {
|
|
14
|
-
interface Matchers<R> {
|
|
15
|
-
toBeHashReference(): R
|
|
16
|
-
toBeBeeResponse(expectedStatusCode: number): R
|
|
17
|
-
toBeOneOf(el: unknown[]): R
|
|
18
|
-
toBeType(type: string): R
|
|
19
|
-
toBeNumberString(): R
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Load common own Jest Matchers which can be used to check particular return values.
|
|
26
|
-
*/
|
|
27
|
-
export function commonMatchers(): void {
|
|
28
|
-
expect.extend({
|
|
29
|
-
toBeHashReference(received: string) {
|
|
30
|
-
const result = {
|
|
31
|
-
pass: false,
|
|
32
|
-
message: () => 'Given input is not a Swarm hash reference',
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof received === 'string' && /^[0-9a-fA-F]{64}$/.test(received)) {
|
|
36
|
-
result.pass = true
|
|
37
|
-
result.message = () => 'Given string is semantically valid Swarm hash reference'
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return result
|
|
41
|
-
},
|
|
42
|
-
toBeBeeResponse(received: BeeGenericResponse, expectedStatusCode: number) {
|
|
43
|
-
const result = {
|
|
44
|
-
pass: false,
|
|
45
|
-
message: () =>
|
|
46
|
-
`Bee response does not have status code ${expectedStatusCode}. Got: ${received.code}\nResponse message: ${received.message}`,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (received.code === expectedStatusCode) {
|
|
50
|
-
result.pass = true
|
|
51
|
-
result.message = () => 'Bee response meets with its requirements'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return result
|
|
55
|
-
},
|
|
56
|
-
toBeOneOf(received, argument) {
|
|
57
|
-
const validValues = Array.isArray(argument) ? argument : [argument]
|
|
58
|
-
let containsValidValue = false
|
|
59
|
-
|
|
60
|
-
for (const validValue of validValues) {
|
|
61
|
-
try {
|
|
62
|
-
expect(received).toEqual(validValue)
|
|
63
|
-
containsValidValue = true
|
|
64
|
-
// eslint-disable-next-line no-empty
|
|
65
|
-
} catch (e) {}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (containsValidValue) {
|
|
69
|
-
return {
|
|
70
|
-
message: () => `expected ${JSON.stringify(received)} not to be one of [${validValues.join(', ')}]`,
|
|
71
|
-
pass: true,
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
message: () => `expected ${JSON.stringify(received)} to be one of [${validValues.join(', ')}]`,
|
|
77
|
-
pass: false,
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
toBeType(received, argument) {
|
|
81
|
-
const initialType = typeof received
|
|
82
|
-
const isArray = Array.isArray(received) ? 'array' : initialType
|
|
83
|
-
const type = initialType === 'object' ? isArray : initialType
|
|
84
|
-
|
|
85
|
-
return type === argument
|
|
86
|
-
? {
|
|
87
|
-
message: () => `expected ${received} to be type ${argument}`,
|
|
88
|
-
pass: true,
|
|
89
|
-
}
|
|
90
|
-
: {
|
|
91
|
-
message: () => `expected ${received} to be type ${argument}`,
|
|
92
|
-
pass: false,
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
toBeNumberString(received) {
|
|
96
|
-
const message = () => `expected ${received} to be a number in a string type`
|
|
97
|
-
|
|
98
|
-
return /^-?(0|[1-9][0-9]*)$/g.test(received)
|
|
99
|
-
? {
|
|
100
|
-
message,
|
|
101
|
-
pass: true,
|
|
102
|
-
}
|
|
103
|
-
: {
|
|
104
|
-
message,
|
|
105
|
-
pass: false,
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Sleep for N miliseconds
|
|
113
|
-
*
|
|
114
|
-
* @param ms Number of miliseconds to sleep
|
|
115
|
-
*/
|
|
116
|
-
export async function sleep(ms: number): Promise<void> {
|
|
117
|
-
return new Promise<void>(resolve => setTimeout(() => resolve(), ms))
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function createRandomNodeReadable(totalSize: number, chunkSize = 1000): Readable {
|
|
121
|
-
if (totalSize % chunkSize !== 0) {
|
|
122
|
-
throw new Error(`totalSize ${totalSize} is not dividable without remainder by chunkSize ${chunkSize}`)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const stream = new Readable()
|
|
126
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
127
|
-
stream._read = (): void => {}
|
|
128
|
-
|
|
129
|
-
for (let i = 0; i < totalSize / chunkSize; i++) {
|
|
130
|
-
stream.push(randomByteArray(chunkSize))
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
stream.push(null)
|
|
134
|
-
|
|
135
|
-
return stream
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function createReadableStream(iterable: Iterable<Uint8Array>): ReadableStream {
|
|
139
|
-
const iter = iterable[Symbol.iterator]()
|
|
140
|
-
|
|
141
|
-
return new ReadableStream({
|
|
142
|
-
async pull(controller) {
|
|
143
|
-
const result = iter.next()
|
|
144
|
-
|
|
145
|
-
if (result.done) {
|
|
146
|
-
controller.close()
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
controller.enqueue(result.value)
|
|
152
|
-
},
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Lehmer random number generator with seed (minstd_rand in C++11)
|
|
158
|
-
* !!! Very fast but not well distributed pseudo-random function !!!
|
|
159
|
-
*
|
|
160
|
-
* @param seed Seed for the pseudo-random generator
|
|
161
|
-
*/
|
|
162
|
-
function lrng(seed: number): () => number {
|
|
163
|
-
return (): number => ((2 ** 31 - 1) & (seed = Math.imul(48271, seed))) / 2 ** 31
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Utility function for generating random Buffer
|
|
168
|
-
* !!! IT IS NOT CRYPTO SAFE !!!
|
|
169
|
-
* For that use `crypto.randomBytes()`
|
|
170
|
-
*
|
|
171
|
-
* @param length Number of bytes to generate
|
|
172
|
-
* @param seed Seed for the pseudo-random generator
|
|
173
|
-
*/
|
|
174
|
-
export function randomByteArray(length: number, seed = 500): Uint8Array {
|
|
175
|
-
const rand = lrng(seed)
|
|
176
|
-
const buf = new Uint8Array(length)
|
|
177
|
-
|
|
178
|
-
for (let i = 0; i < length; ++i) {
|
|
179
|
-
buf[i] = (rand() * 0xff) << 0
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return buf
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Returns a url for testing the Bee public API
|
|
187
|
-
*/
|
|
188
|
-
export function beeUrl(): string {
|
|
189
|
-
return process.env.BEE_API_URL || 'http://localhost:1633'
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function beeKy(): Ky {
|
|
193
|
-
return ky.create({ prefixUrl: beeUrl(), timeout: false })
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Returns a url of another peer for testing the Bee public API
|
|
198
|
-
*/
|
|
199
|
-
export function beePeerUrl(): string {
|
|
200
|
-
return process.env.BEE_PEER_API_URL || 'http://localhost:11633'
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function beePeerKy(): Ky {
|
|
204
|
-
return ky.create({ prefixUrl: beePeerUrl(), timeout: false })
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Helper function that create monster batch for all the tests.
|
|
209
|
-
* There is semaphore mechanism that allows only creation of one batch across all the
|
|
210
|
-
* parallel running tests that have to wait until it is created.
|
|
211
|
-
*/
|
|
212
|
-
export function getPostageBatch(url = beeDebugUrl()): BatchId {
|
|
213
|
-
let stamp: BatchId
|
|
214
|
-
|
|
215
|
-
switch (url) {
|
|
216
|
-
case beeDebugUrl():
|
|
217
|
-
stamp = process.env.BEE_POSTAGE as BatchId
|
|
218
|
-
break
|
|
219
|
-
case beePeerDebugUrl():
|
|
220
|
-
stamp = process.env.BEE_PEER_POSTAGE as BatchId
|
|
221
|
-
break
|
|
222
|
-
default:
|
|
223
|
-
throw new Error('Unknown URL ' + url)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (!stamp) {
|
|
227
|
-
throw new Error('There is no postage stamp configured for URL ' + url)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return stamp
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Returns a url for testing the Bee Debug API
|
|
235
|
-
*/
|
|
236
|
-
export function beeDebugUrl(): string {
|
|
237
|
-
return process.env.BEE_DEBUG_API_URL || 'http://localhost:1635'
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function beeDebugKy(): Ky {
|
|
241
|
-
return ky.create({ prefixUrl: beeDebugUrl() })
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Returns a url for testing the Bee Debug API
|
|
246
|
-
*/
|
|
247
|
-
export function beePeerDebugUrl(): string {
|
|
248
|
-
return process.env.BEE_PEER_DEBUG_API_URL || 'http://localhost:11635'
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function beePeerDebugKy(): Ky {
|
|
252
|
-
return ky.create({ prefixUrl: beePeerDebugUrl() })
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Try to delete a chunk from local storage, ignoring all errors
|
|
257
|
-
*
|
|
258
|
-
* @param address Swarm address of chunk
|
|
259
|
-
*/
|
|
260
|
-
export async function tryDeleteChunkFromLocalStorage(address: string | ChunkAddress): Promise<void> {
|
|
261
|
-
if (typeof address !== 'string') {
|
|
262
|
-
assertBytes(address, 32)
|
|
263
|
-
address = bytesToHex(address)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
try {
|
|
267
|
-
await deleteChunkFromLocalStorage(beeDebugKy(), address)
|
|
268
|
-
} catch (e) {
|
|
269
|
-
// ignore not found errors
|
|
270
|
-
if (e instanceof BeeResponseError && e.status === 404) {
|
|
271
|
-
return
|
|
272
|
-
}
|
|
273
|
-
throw e
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Formatting utility for displaying long strings like hexstrings.
|
|
279
|
-
*
|
|
280
|
-
* @param inputStr
|
|
281
|
-
* @param len
|
|
282
|
-
*/
|
|
283
|
-
export function shorten(inputStr: unknown, len = 17): string {
|
|
284
|
-
const str = typeof inputStr === 'string' ? inputStr : (inputStr as string).toString()
|
|
285
|
-
|
|
286
|
-
if (str.length <= len) {
|
|
287
|
-
return str
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return `${str.slice(0, 6)}...${str.slice(-6)} (length: ${str.length})`
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export const invalidReference = '0000000000000000000000000000000000000000000000000000000000000000' as Reference
|
|
294
|
-
|
|
295
|
-
export const okResponse: BeeGenericResponse = {
|
|
296
|
-
code: 200,
|
|
297
|
-
message: 'OK',
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export const createdResponse: BeeGenericResponse = {
|
|
301
|
-
code: 201,
|
|
302
|
-
message: 'Created',
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export const ERR_TIMEOUT = 40000
|
|
306
|
-
export const BIG_FILE_TIMEOUT = 100000
|
|
307
|
-
export const PSS_TIMEOUT = 120000
|
|
308
|
-
export const FEED_TIMEOUT = 120000
|
|
309
|
-
export const POSTAGE_BATCH_TIMEOUT = 40000
|
|
310
|
-
|
|
311
|
-
export const testChunkPayload = new Uint8Array([1, 2, 3])
|
|
312
|
-
// span is the payload length encoded as uint64 little endian
|
|
313
|
-
export const testChunkSpan = new Uint8Array([testChunkPayload.length, 0, 0, 0, 0, 0, 0, 0])
|
|
314
|
-
export const testChunkData = new Uint8Array([...testChunkSpan, ...testChunkPayload])
|
|
315
|
-
// the hash is hardcoded because we would need the bmt hasher otherwise
|
|
316
|
-
export const testChunkHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as Reference
|
|
317
|
-
export const testAddress = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as Address
|
|
318
|
-
export const testBatchId = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338' as BatchId
|
|
319
|
-
|
|
320
|
-
export const testJsonPayload = [{ some: 'object' }]
|
|
321
|
-
export const testJsonStringPayload = JSON.stringify(testJsonPayload)
|
|
322
|
-
export const testJsonHash = '872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa'
|
|
323
|
-
|
|
324
|
-
export const testIdentity = {
|
|
325
|
-
privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd' as HexString,
|
|
326
|
-
publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4' as HexString,
|
|
327
|
-
address: '8d3766440f0d7b949a5e32995d09619a7f86e632' as HexString,
|
|
328
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src"],
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"alwaysStrict": true,
|
|
5
|
-
"target": "ES6",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"moduleResolution": "node",
|
|
9
|
-
"module": "commonjs",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"experimentalDecorators": true,
|
|
13
|
-
"emitDecoratorMetadata": true,
|
|
14
|
-
"typeRoots": ["./src/types", "node_modules/@types"],
|
|
15
|
-
"rootDirs": ["src"],
|
|
16
|
-
"outDir": "dist"
|
|
17
|
-
},
|
|
18
|
-
}
|
package/tsconfig.test.json
DELETED
package/typedoc.json
DELETED
package/webpack.config.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import Path from 'path'
|
|
3
|
-
import { DefinePlugin, Configuration, WebpackPluginInstance, NormalModuleReplacementPlugin } from 'webpack'
|
|
4
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
5
|
-
import TerserPlugin from 'terser-webpack-plugin'
|
|
6
|
-
import PackageJson from './package.json'
|
|
7
|
-
import { getBrowserPathMapping } from './jest.config'
|
|
8
|
-
|
|
9
|
-
interface WebpackEnvParams {
|
|
10
|
-
target: 'web' | 'node'
|
|
11
|
-
debug: boolean
|
|
12
|
-
mode: 'production' | 'development'
|
|
13
|
-
fileName: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const base = async (env?: Partial<WebpackEnvParams>): Promise<Configuration> => {
|
|
17
|
-
const isProduction = env?.mode === 'production'
|
|
18
|
-
const isBrowser = env?.target === 'web'
|
|
19
|
-
const filename =
|
|
20
|
-
env?.fileName ||
|
|
21
|
-
['index', isBrowser ? '.browser' : null, isProduction ? '.min' : null, '.js'].filter(Boolean).join('')
|
|
22
|
-
const entry = Path.resolve(__dirname, 'src')
|
|
23
|
-
const path = Path.resolve(__dirname, 'dist')
|
|
24
|
-
const target = env?.target || 'web' // 'node' or 'web'
|
|
25
|
-
const plugins: WebpackPluginInstance[] = [
|
|
26
|
-
new DefinePlugin({
|
|
27
|
-
'process.env.ENV': env?.mode || 'development',
|
|
28
|
-
'process.env.IS_WEBPACK_BUILD': 'true',
|
|
29
|
-
}),
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
if (target === 'web') {
|
|
33
|
-
const browserPathMapping = await getBrowserPathMapping()
|
|
34
|
-
// eslint-disable-next-line guard-for-in
|
|
35
|
-
for (const nodeReference in browserPathMapping) {
|
|
36
|
-
plugins.push(
|
|
37
|
-
new NormalModuleReplacementPlugin(new RegExp(`\\${nodeReference}`), browserPathMapping[nodeReference]),
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
// change node modules to browser modules according to packageJson.browser mapping
|
|
41
|
-
// eslint-disable-next-line guard-for-in
|
|
42
|
-
const browserModuleMapping = PackageJson.browser as { [key: string]: string }
|
|
43
|
-
// eslint-disable-next-line guard-for-in
|
|
44
|
-
for (const nodeReference in browserModuleMapping) {
|
|
45
|
-
const browserReference: string = browserModuleMapping[nodeReference]
|
|
46
|
-
plugins.push(new NormalModuleReplacementPlugin(new RegExp(`^${nodeReference}$`), browserReference))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
bail: Boolean(isProduction),
|
|
52
|
-
mode: env?.mode || 'development',
|
|
53
|
-
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
|
|
54
|
-
entry,
|
|
55
|
-
output: {
|
|
56
|
-
path,
|
|
57
|
-
filename,
|
|
58
|
-
sourceMapFilename: filename + '.map',
|
|
59
|
-
library: 'BeeJs',
|
|
60
|
-
libraryTarget: 'umd',
|
|
61
|
-
globalObject: 'this',
|
|
62
|
-
},
|
|
63
|
-
module: {
|
|
64
|
-
rules: [
|
|
65
|
-
{
|
|
66
|
-
test: /\.(ts|js)$/,
|
|
67
|
-
// include: entry,
|
|
68
|
-
use: {
|
|
69
|
-
loader: 'babel-loader',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
resolve: {
|
|
75
|
-
extensions: ['.ts', '.js'],
|
|
76
|
-
fallback: {
|
|
77
|
-
path: false,
|
|
78
|
-
fs: false,
|
|
79
|
-
stream: false,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
optimization: {
|
|
83
|
-
minimize: isProduction,
|
|
84
|
-
minimizer: [
|
|
85
|
-
// This is only used in production mode
|
|
86
|
-
new TerserPlugin({
|
|
87
|
-
terserOptions: {
|
|
88
|
-
parse: {
|
|
89
|
-
// we want terser to parse ecma 8 code. However, we don't want it
|
|
90
|
-
// to apply any minfication steps that turns valid ecma 5 code
|
|
91
|
-
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
92
|
-
// sections only apply transformations that are ecma 5 safe
|
|
93
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
|
94
|
-
ecma: 2018,
|
|
95
|
-
},
|
|
96
|
-
compress: {
|
|
97
|
-
ecma: 5,
|
|
98
|
-
},
|
|
99
|
-
mangle: {
|
|
100
|
-
safari10: true,
|
|
101
|
-
},
|
|
102
|
-
output: {
|
|
103
|
-
ecma: 5,
|
|
104
|
-
comments: false,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
// Use multi-process parallel running to improve the build speed
|
|
108
|
-
// Default number of concurrent runs: os.cpus().length - 1
|
|
109
|
-
parallel: true,
|
|
110
|
-
}),
|
|
111
|
-
],
|
|
112
|
-
},
|
|
113
|
-
plugins,
|
|
114
|
-
target,
|
|
115
|
-
node: {
|
|
116
|
-
global: true,
|
|
117
|
-
__filename: 'mock',
|
|
118
|
-
__dirname: 'mock',
|
|
119
|
-
},
|
|
120
|
-
performance: {
|
|
121
|
-
hints: false,
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default async (env?: Partial<WebpackEnvParams>): Promise<Configuration> => {
|
|
127
|
-
// eslint-disable-next-line no-console
|
|
128
|
-
console.log('env', env)
|
|
129
|
-
|
|
130
|
-
if (env?.debug) {
|
|
131
|
-
const config = {
|
|
132
|
-
...(await base(env)),
|
|
133
|
-
plugins: [new BundleAnalyzerPlugin()],
|
|
134
|
-
profile: true,
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return config
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return base(env)
|
|
141
|
-
}
|