@ethersphere/bee-js 5.0.0 → 6.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/index.browser.js +33 -0
- package/dist/index.browser.js.map +7 -0
- package/dist/src/bee-debug.js +624 -0
- package/dist/{mjs → src}/bee.js +243 -340
- package/dist/{mjs → src}/chunk/bmt.js +0 -0
- package/dist/{mjs → src}/chunk/cac.js +0 -0
- package/dist/{mjs → src}/chunk/serialize.js +0 -0
- package/dist/{mjs → src}/chunk/signer.js +13 -47
- package/dist/{mjs → src}/chunk/soc.js +31 -71
- package/dist/{mjs → src}/chunk/span.js +1 -1
- package/dist/{mjs → src}/feed/identifier.js +0 -0
- package/dist/src/feed/index.js +92 -0
- package/dist/src/feed/json.js +27 -0
- package/dist/src/feed/retrievable.js +67 -0
- package/dist/{mjs → src}/feed/topic.js +0 -0
- package/dist/{mjs → src}/feed/type.js +0 -0
- package/dist/{mjs → src}/index.js +1 -2
- package/dist/src/modules/bytes.js +59 -0
- package/dist/src/modules/bzz.js +122 -0
- package/dist/src/modules/chunk.js +45 -0
- package/dist/src/modules/debug/balance.js +57 -0
- package/dist/src/modules/debug/chequebook.js +150 -0
- package/dist/src/modules/debug/chunk.js +35 -0
- package/dist/src/modules/debug/connectivity.js +45 -0
- package/dist/src/modules/debug/settlements.js +29 -0
- package/dist/src/modules/debug/stamps.js +64 -0
- package/dist/src/modules/debug/states.js +46 -0
- package/dist/src/modules/debug/status.js +134 -0
- package/dist/src/modules/debug/tag.js +16 -0
- package/dist/src/modules/debug/transactions.js +69 -0
- package/dist/src/modules/feed.js +67 -0
- package/dist/src/modules/pinning.js +60 -0
- package/dist/src/modules/pss.js +40 -0
- package/dist/src/modules/soc.js +31 -0
- package/dist/src/modules/status.js +12 -0
- package/dist/src/modules/stewardship.js +24 -0
- package/dist/src/modules/tag.js +77 -0
- package/dist/{mjs → src}/types/debug.js +0 -0
- package/dist/{mjs → src}/types/index.js +0 -0
- package/dist/{mjs → src}/utils/bytes.js +3 -2
- package/dist/src/utils/collection-browser.js +19 -0
- package/dist/src/utils/collection-node.js +74 -0
- package/dist/src/utils/collection.js +64 -0
- package/dist/src/utils/data.browser.js +72 -0
- package/dist/src/utils/data.js +42 -0
- package/dist/{mjs → src}/utils/error.js +0 -0
- package/dist/{mjs → src}/utils/eth.js +32 -68
- package/dist/{mjs → src}/utils/expose.js +1 -1
- package/dist/src/utils/file.js +36 -0
- package/dist/{mjs → src}/utils/hash.js +0 -0
- package/dist/{mjs → src}/utils/headers.js +4 -4
- package/dist/{mjs → src}/utils/hex.js +0 -0
- package/dist/src/utils/http.js +162 -0
- package/dist/{mjs → src}/utils/merge.js +2 -2
- package/dist/{mjs → src}/utils/pss.js +0 -0
- package/dist/{mjs → src}/utils/reference.js +0 -0
- package/dist/src/utils/sleep.js +8 -0
- package/dist/{mjs → src}/utils/stamps.js +0 -0
- package/dist/{mjs → src}/utils/stream.js +3 -3
- package/dist/{mjs → src}/utils/tar.js +0 -0
- package/dist/{mjs → src}/utils/type.js +12 -13
- package/dist/{mjs → src}/utils/uint64.js +0 -0
- package/dist/{mjs → src}/utils/url.js +0 -0
- package/dist/types/chunk/bmt.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +1 -1
- package/dist/types/chunk/span.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/modules/bzz.d.ts +1 -1
- package/dist/types/types/index.d.ts +8 -8
- package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
- package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
- package/dist/types/utils/error.d.ts +1 -1
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/expose.d.ts +7 -4
- package/dist/types/utils/hash.d.ts +1 -1
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +3 -3
- package/dist/types/utils/stream.d.ts +1 -1
- package/dist/types/utils/uint64.d.ts +1 -1
- package/package.json +44 -59
- package/dist/cjs/bee-debug.js +0 -642
- package/dist/cjs/bee.js +0 -983
- package/dist/cjs/chunk/bmt.js +0 -55
- package/dist/cjs/chunk/cac.js +0 -56
- package/dist/cjs/chunk/serialize.js +0 -19
- package/dist/cjs/chunk/signer.js +0 -137
- package/dist/cjs/chunk/soc.js +0 -176
- package/dist/cjs/chunk/span.js +0 -29
- package/dist/cjs/feed/identifier.js +0 -35
- package/dist/cjs/feed/index.js +0 -132
- package/dist/cjs/feed/json.js +0 -41
- package/dist/cjs/feed/retrievable.js +0 -72
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/index.js +0 -39
- package/dist/cjs/modules/bytes.js +0 -74
- package/dist/cjs/modules/bzz.js +0 -131
- package/dist/cjs/modules/chunk.js +0 -58
- package/dist/cjs/modules/debug/balance.js +0 -77
- package/dist/cjs/modules/debug/chequebook.js +0 -167
- package/dist/cjs/modules/debug/chunk.js +0 -51
- package/dist/cjs/modules/debug/connectivity.js +0 -75
- package/dist/cjs/modules/debug/settlements.js +0 -45
- package/dist/cjs/modules/debug/stamps.js +0 -89
- package/dist/cjs/modules/debug/states.js +0 -64
- package/dist/cjs/modules/debug/status.js +0 -153
- package/dist/cjs/modules/debug/tag.js +0 -30
- package/dist/cjs/modules/debug/transactions.js +0 -81
- package/dist/cjs/modules/feed.js +0 -76
- package/dist/cjs/modules/pinning.js +0 -80
- package/dist/cjs/modules/pss.js +0 -55
- package/dist/cjs/modules/soc.js +0 -40
- package/dist/cjs/modules/status.js +0 -26
- package/dist/cjs/modules/stewardship.js +0 -41
- package/dist/cjs/modules/tag.js +0 -96
- package/dist/cjs/package.json +0 -8
- package/dist/cjs/types/debug.js +0 -10
- package/dist/cjs/types/index.js +0 -51
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/cjs/utils/bytes.js +0 -121
- package/dist/cjs/utils/collection.browser.js +0 -36
- package/dist/cjs/utils/collection.js +0 -70
- package/dist/cjs/utils/collection.node.js +0 -115
- package/dist/cjs/utils/data.browser.js +0 -74
- package/dist/cjs/utils/data.js +0 -58
- package/dist/cjs/utils/error.js +0 -50
- package/dist/cjs/utils/eth.js +0 -211
- package/dist/cjs/utils/expose.js +0 -44
- package/dist/cjs/utils/file.js +0 -49
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/headers.js +0 -59
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/http.js +0 -172
- package/dist/cjs/utils/merge.js +0 -34
- package/dist/cjs/utils/pss.js +0 -18
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/cjs/utils/sleep.js +0 -23
- package/dist/cjs/utils/stamps.js +0 -17
- package/dist/cjs/utils/stream.js +0 -146
- package/dist/cjs/utils/tar.js +0 -25
- package/dist/cjs/utils/type.js +0 -426
- package/dist/cjs/utils/uint64.js +0 -29
- package/dist/cjs/utils/url.js +0 -56
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -60
- package/dist/index.browser.min.js.map +0 -1
- package/dist/mjs/bee-debug.js +0 -744
- package/dist/mjs/feed/index.js +0 -134
- package/dist/mjs/feed/json.js +0 -63
- package/dist/mjs/feed/retrievable.js +0 -105
- package/dist/mjs/modules/bytes.js +0 -96
- package/dist/mjs/modules/bzz.js +0 -160
- package/dist/mjs/modules/chunk.js +0 -80
- package/dist/mjs/modules/debug/balance.js +0 -97
- package/dist/mjs/modules/debug/chequebook.js +0 -198
- package/dist/mjs/modules/debug/chunk.js +0 -71
- package/dist/mjs/modules/debug/connectivity.js +0 -89
- package/dist/mjs/modules/debug/settlements.js +0 -65
- package/dist/mjs/modules/debug/stamps.js +0 -108
- package/dist/mjs/modules/debug/states.js +0 -84
- package/dist/mjs/modules/debug/status.js +0 -182
- package/dist/mjs/modules/debug/tag.js +0 -50
- package/dist/mjs/modules/debug/transactions.js +0 -103
- package/dist/mjs/modules/feed.js +0 -101
- package/dist/mjs/modules/pinning.js +0 -100
- package/dist/mjs/modules/pss.js +0 -74
- package/dist/mjs/modules/soc.js +0 -64
- package/dist/mjs/modules/status.js +0 -46
- package/dist/mjs/modules/stewardship.js +0 -60
- package/dist/mjs/modules/tag.js +0 -119
- package/dist/mjs/package.json +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/mjs/utils/collection.browser.js +0 -56
- package/dist/mjs/utils/collection.js +0 -98
- package/dist/mjs/utils/collection.node.js +0 -169
- package/dist/mjs/utils/data.browser.js +0 -108
- package/dist/mjs/utils/data.js +0 -78
- package/dist/mjs/utils/file.js +0 -70
- package/dist/mjs/utils/http.js +0 -208
- package/dist/mjs/utils/sleep.js +0 -43
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/utils/http.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.makeDefaultKy = exports.http = exports.filterHeaders = exports.wrapResponseClosure = exports.wrapRequestClosure = void 0;
|
|
27
|
-
const error_1 = require("./error");
|
|
28
|
-
const ky_universal_1 = __importDefault(require("ky-universal"));
|
|
29
|
-
const stream_1 = require("./stream");
|
|
30
|
-
const merge_1 = require("./merge");
|
|
31
|
-
const type_1 = require("./type");
|
|
32
|
-
const DEFAULT_KY_CONFIG = {
|
|
33
|
-
headers: {
|
|
34
|
-
accept: 'application/json, text/plain, */*',
|
|
35
|
-
'user-agent': `bee-js`,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
function isHttpError(e) {
|
|
39
|
-
return (0, type_1.isObject)(e) && typeof e.response !== 'undefined';
|
|
40
|
-
}
|
|
41
|
-
function isHttpRequestError(e) {
|
|
42
|
-
return (0, type_1.isObject)(e) && typeof e.request !== 'undefined';
|
|
43
|
-
}
|
|
44
|
-
function headersToObject(header) {
|
|
45
|
-
return [...header.entries()].reduce((obj, [key, val]) => {
|
|
46
|
-
obj[key] = val;
|
|
47
|
-
return obj;
|
|
48
|
-
}, {});
|
|
49
|
-
}
|
|
50
|
-
function wrapRequest(request) {
|
|
51
|
-
return {
|
|
52
|
-
url: request.url,
|
|
53
|
-
method: request.method.toUpperCase(),
|
|
54
|
-
headers: headersToObject(request.headers),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function wrapRequestClosure(cb) {
|
|
58
|
-
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
yield cb(wrapRequest(request));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
exports.wrapRequestClosure = wrapRequestClosure;
|
|
63
|
-
function wrapResponseClosure(cb) {
|
|
64
|
-
return (request, options, response) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
yield cb({
|
|
66
|
-
headers: headersToObject(response.headers),
|
|
67
|
-
status: response.status,
|
|
68
|
-
statusText: response.statusText,
|
|
69
|
-
request: wrapRequest(request),
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
exports.wrapResponseClosure = wrapResponseClosure;
|
|
74
|
-
/**
|
|
75
|
-
* Filters out entries that has undefined value from headers object.
|
|
76
|
-
* Modifies the original object!
|
|
77
|
-
*
|
|
78
|
-
* @param obj
|
|
79
|
-
*/
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
81
|
-
function filterHeaders(obj) {
|
|
82
|
-
if (obj === undefined) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
(0, type_1.isStrictlyObject)(obj);
|
|
86
|
-
const typedObj = obj;
|
|
87
|
-
for (const key in typedObj) {
|
|
88
|
-
if (typedObj[key] === undefined) {
|
|
89
|
-
delete typedObj[key];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (Object.keys(typedObj).length === 0) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
return typedObj;
|
|
96
|
-
}
|
|
97
|
-
exports.filterHeaders = filterHeaders;
|
|
98
|
-
/**
|
|
99
|
-
* Main utility function to make HTTP requests.
|
|
100
|
-
* @param ky
|
|
101
|
-
* @param config
|
|
102
|
-
*/
|
|
103
|
-
function http(ky, config) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
try {
|
|
106
|
-
const { path, responseType } = config, kyConfig = __rest(config, ["path", "responseType"]);
|
|
107
|
-
const response = (yield ky(path, Object.assign(Object.assign({}, kyConfig), { searchParams: filterHeaders(kyConfig.searchParams) })));
|
|
108
|
-
switch (responseType) {
|
|
109
|
-
case 'stream':
|
|
110
|
-
if (!response.body) {
|
|
111
|
-
throw new error_1.BeeError('Response was expected to get data but did not get any!');
|
|
112
|
-
}
|
|
113
|
-
response.data = (0, stream_1.normalizeToReadableStream)(response.body);
|
|
114
|
-
break;
|
|
115
|
-
case 'arraybuffer':
|
|
116
|
-
response.data = (yield response.arrayBuffer());
|
|
117
|
-
break;
|
|
118
|
-
case 'json':
|
|
119
|
-
try {
|
|
120
|
-
response.data = (yield response.json());
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
throw new error_1.BeeNotAJsonError();
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
break; // If responseType is not set, then no data are expected
|
|
128
|
-
}
|
|
129
|
-
return response;
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
// Passthrough thrown errors
|
|
133
|
-
if (e instanceof error_1.BeeNotAJsonError) {
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
if (isHttpError(e)) {
|
|
137
|
-
let message;
|
|
138
|
-
// We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
|
|
139
|
-
// to the user in the BeeResponseError, for further analysis.
|
|
140
|
-
const body = yield e.response.text();
|
|
141
|
-
try {
|
|
142
|
-
// The response can be Bee's JSON with structure `{code, message}` lets try to parse it
|
|
143
|
-
message = JSON.parse(body).message;
|
|
144
|
-
}
|
|
145
|
-
catch (e) { }
|
|
146
|
-
if (message) {
|
|
147
|
-
throw new error_1.BeeResponseError(e.response.status, e.response, body, config, `${e.response.statusText}: ${message}`);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new error_1.BeeResponseError(e.response.status, e.response, body, config, e.response.statusText);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else if (isHttpRequestError(e)) {
|
|
154
|
-
throw new error_1.BeeRequestError(e.message, config);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
|
|
158
|
-
// message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
|
|
159
|
-
// expose the underlying problem.
|
|
160
|
-
if (e.cause) {
|
|
161
|
-
throw new error_1.BeeError(e.cause.message);
|
|
162
|
-
}
|
|
163
|
-
throw new error_1.BeeError(e.message);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
exports.http = http;
|
|
169
|
-
function makeDefaultKy(kyConfig) {
|
|
170
|
-
return ky_universal_1.default.create((0, merge_1.deepMerge)(DEFAULT_KY_CONFIG, kyConfig));
|
|
171
|
-
}
|
|
172
|
-
exports.makeDefaultKy = makeDefaultKy;
|
package/dist/cjs/utils/merge.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepMerge = void 0;
|
|
4
|
-
const type_1 = require("./type");
|
|
5
|
-
/**
|
|
6
|
-
* Function that deep merges objects
|
|
7
|
-
*
|
|
8
|
-
* @copyright https://github.com/sindresorhus/ky/blob/b3c9e88fa49d50150dbb6e6b771b4af56cb40c98/source/utils/merge.ts
|
|
9
|
-
* @licence MIT
|
|
10
|
-
* @param sources
|
|
11
|
-
*/
|
|
12
|
-
function deepMerge(...sources) {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
let returnValue = {};
|
|
15
|
-
for (const source of sources) {
|
|
16
|
-
if (Array.isArray(source)) {
|
|
17
|
-
if (!Array.isArray(returnValue)) {
|
|
18
|
-
returnValue = [];
|
|
19
|
-
}
|
|
20
|
-
returnValue = [...returnValue, ...source];
|
|
21
|
-
}
|
|
22
|
-
else if ((0, type_1.isObject)(source)) {
|
|
23
|
-
// eslint-disable-next-line prefer-const
|
|
24
|
-
for (let [key, value] of Object.entries(source)) {
|
|
25
|
-
if ((0, type_1.isObject)(value) && key in returnValue) {
|
|
26
|
-
value = deepMerge(returnValue[key], value);
|
|
27
|
-
}
|
|
28
|
-
returnValue = Object.assign(Object.assign({}, returnValue), { [key]: value });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return returnValue;
|
|
33
|
-
}
|
|
34
|
-
exports.deepMerge = deepMerge;
|
package/dist/cjs/utils/pss.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMaxTarget = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
/**
|
|
6
|
-
* Utility function that for given strings/reference takes the most specific
|
|
7
|
-
* target that Bee node will except.
|
|
8
|
-
*
|
|
9
|
-
* @param target is a non-prefixed hex string Bee address
|
|
10
|
-
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
|
|
11
|
-
*/
|
|
12
|
-
function makeMaxTarget(target) {
|
|
13
|
-
if (typeof target !== 'string') {
|
|
14
|
-
throw new TypeError('target has to be an string!');
|
|
15
|
-
}
|
|
16
|
-
return target.slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
|
|
17
|
-
}
|
|
18
|
-
exports.makeMaxTarget = makeMaxTarget;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeBytesReference = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const bytes_1 = require("./bytes");
|
|
6
|
-
const hex_1 = require("./hex");
|
|
7
|
-
function makeBytesReference(reference, offset = 0) {
|
|
8
|
-
if (typeof reference === 'string') {
|
|
9
|
-
if (offset) {
|
|
10
|
-
throw new Error('Offset property can be set only for UintArray reference!');
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
// Non-encrypted chunk hex string reference
|
|
14
|
-
const hexReference = (0, hex_1.makeHexString)(reference, types_1.REFERENCE_HEX_LENGTH);
|
|
15
|
-
return (0, hex_1.hexToBytes)(hexReference);
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
if (!(e instanceof TypeError)) {
|
|
19
|
-
throw e;
|
|
20
|
-
}
|
|
21
|
-
// Encrypted chunk hex string reference
|
|
22
|
-
const hexReference = (0, hex_1.makeHexString)(reference, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
23
|
-
return (0, hex_1.hexToBytes)(hexReference);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else if (reference instanceof Uint8Array) {
|
|
27
|
-
if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
|
|
28
|
-
return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH);
|
|
29
|
-
}
|
|
30
|
-
else if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH)) {
|
|
31
|
-
return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
throw new TypeError('invalid chunk reference');
|
|
35
|
-
}
|
|
36
|
-
exports.makeBytesReference = makeBytesReference;
|
package/dist/cjs/utils/sleep.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.sleep = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* Sleep for N miliseconds
|
|
15
|
-
*
|
|
16
|
-
* @param ms Number of miliseconds to sleep
|
|
17
|
-
*/
|
|
18
|
-
function sleep(ms) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.sleep = sleep;
|
package/dist/cjs/utils/stamps.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStampUsage = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
6
|
-
*
|
|
7
|
-
* Be aware for small depths (17, 18) this does not provide that much information as the provided set of distinct values
|
|
8
|
-
* is small.
|
|
9
|
-
*
|
|
10
|
-
* @param utilization
|
|
11
|
-
* @param depth
|
|
12
|
-
* @param bucketDepth
|
|
13
|
-
*/
|
|
14
|
-
function getStampUsage({ utilization, depth, bucketDepth }) {
|
|
15
|
-
return utilization / Math.pow(2, depth - bucketDepth);
|
|
16
|
-
}
|
|
17
|
-
exports.getStampUsage = getStampUsage;
|
package/dist/cjs/utils/stream.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeToReadableStream = exports.readableWebToNode = exports.readableNodeToWeb = exports.isNodeReadable = exports.isReadableStream = exports.isReadable = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const type_1 = require("./type");
|
|
6
|
-
const web_streams_polyfill_1 = require("web-streams-polyfill");
|
|
7
|
-
const NodeReadable = stream_1.Readable || class {
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Validates if passed object is either browser's ReadableStream
|
|
11
|
-
* or Node's Readable.
|
|
12
|
-
*
|
|
13
|
-
* @param entry
|
|
14
|
-
*/
|
|
15
|
-
function isReadable(entry) {
|
|
16
|
-
return isReadableStream(entry) || isNodeReadable(entry);
|
|
17
|
-
}
|
|
18
|
-
exports.isReadable = isReadable;
|
|
19
|
-
function isReadableStream(entry) {
|
|
20
|
-
if (!(0, type_1.isStrictlyObject)(entry)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
const browserReadable = entry;
|
|
24
|
-
if (typeof browserReadable.getReader === 'function' &&
|
|
25
|
-
browserReadable.locked !== undefined &&
|
|
26
|
-
typeof browserReadable.cancel === 'function' &&
|
|
27
|
-
typeof browserReadable.pipeTo === 'function' &&
|
|
28
|
-
typeof browserReadable.pipeThrough === 'function') {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
exports.isReadableStream = isReadableStream;
|
|
34
|
-
function isNodeReadable(entry) {
|
|
35
|
-
if (!(0, type_1.isStrictlyObject)(entry)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
const nodeReadable = entry;
|
|
39
|
-
if (typeof nodeReadable.pipe === 'function' && nodeReadable.readable && typeof nodeReadable._read === 'function') {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
exports.isNodeReadable = isNodeReadable;
|
|
45
|
-
/**
|
|
46
|
-
* Function that converts Node's Readable into WHATWG ReadableStream
|
|
47
|
-
*
|
|
48
|
-
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
49
|
-
* Because it uses forked web-streams-polyfill that are outdated.
|
|
50
|
-
*
|
|
51
|
-
* @author https://github.com/gwicke
|
|
52
|
-
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
53
|
-
* @param nodeStream
|
|
54
|
-
*/
|
|
55
|
-
function readableNodeToWeb(nodeStream) {
|
|
56
|
-
return new web_streams_polyfill_1.ReadableStream({
|
|
57
|
-
start(controller) {
|
|
58
|
-
nodeStream.pause();
|
|
59
|
-
nodeStream.on('data', chunk => {
|
|
60
|
-
if (Buffer.isBuffer(chunk)) {
|
|
61
|
-
controller.enqueue(new Uint8Array(chunk.buffer));
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
controller.enqueue(chunk);
|
|
65
|
-
}
|
|
66
|
-
nodeStream.pause();
|
|
67
|
-
});
|
|
68
|
-
nodeStream.on('end', () => controller.close());
|
|
69
|
-
nodeStream.on('error', e => controller.error(e));
|
|
70
|
-
},
|
|
71
|
-
pull() {
|
|
72
|
-
nodeStream.resume();
|
|
73
|
-
},
|
|
74
|
-
cancel() {
|
|
75
|
-
nodeStream.pause();
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
exports.readableNodeToWeb = readableNodeToWeb;
|
|
80
|
-
/**
|
|
81
|
-
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
82
|
-
* Because it uses forked web-streams-polyfill that are outdated.
|
|
83
|
-
*
|
|
84
|
-
* @author https://github.com/gwicke
|
|
85
|
-
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
86
|
-
*/
|
|
87
|
-
class NodeReadableWrapper extends NodeReadable {
|
|
88
|
-
constructor(webStream, options) {
|
|
89
|
-
super(options);
|
|
90
|
-
this._webStream = webStream;
|
|
91
|
-
this._reader = webStream.getReader();
|
|
92
|
-
this._reading = false;
|
|
93
|
-
}
|
|
94
|
-
_read() {
|
|
95
|
-
if (this._reading) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
this._reading = true;
|
|
99
|
-
const doRead = () => {
|
|
100
|
-
this._reader.read().then(res => {
|
|
101
|
-
if (res.done) {
|
|
102
|
-
this.push(null);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (this.push(res.value)) {
|
|
106
|
-
return doRead();
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
this._reading = false;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
doRead();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Function that converts WHATWG ReadableStream into Node's Readable
|
|
118
|
-
*
|
|
119
|
-
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
120
|
-
* Because it uses forked web-streams-polyfill that is outdated.
|
|
121
|
-
*
|
|
122
|
-
* **Warning!**
|
|
123
|
-
* If you want to use this function in browser you have to polyfill `stream` package with your bundler.
|
|
124
|
-
*
|
|
125
|
-
* @author https://github.com/gwicke
|
|
126
|
-
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
127
|
-
* @param webStream
|
|
128
|
-
* @param options
|
|
129
|
-
*/
|
|
130
|
-
function readableWebToNode(webStream, options) {
|
|
131
|
-
if (!stream_1.Readable) {
|
|
132
|
-
throw new Error("The Node's Readable is not available! If you are running this in browser you have to polyfill 'stream' package!");
|
|
133
|
-
}
|
|
134
|
-
return new NodeReadableWrapper(webStream, options);
|
|
135
|
-
}
|
|
136
|
-
exports.readableWebToNode = readableWebToNode;
|
|
137
|
-
function normalizeToReadableStream(stream) {
|
|
138
|
-
if (isNodeReadable(stream)) {
|
|
139
|
-
return readableNodeToWeb(stream);
|
|
140
|
-
}
|
|
141
|
-
else if (isReadableStream(stream)) {
|
|
142
|
-
return stream;
|
|
143
|
-
}
|
|
144
|
-
throw new TypeError('Passed stream is not Node Readable nor ReadableStream!');
|
|
145
|
-
}
|
|
146
|
-
exports.normalizeToReadableStream = normalizeToReadableStream;
|
package/dist/cjs/utils/tar.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.makeTar = void 0;
|
|
7
|
-
const tar_js_1 = __importDefault(require("tar-js"));
|
|
8
|
-
// converts a string to utf8 Uint8Array and returns it as a string-like
|
|
9
|
-
// object that `tar.append` accepts as path
|
|
10
|
-
function fixUnicodePath(path) {
|
|
11
|
-
const codes = new TextEncoder().encode(path);
|
|
12
|
-
return {
|
|
13
|
-
length: codes.length,
|
|
14
|
-
charCodeAt: index => codes[index],
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function makeTar(data) {
|
|
18
|
-
const tar = new tar_js_1.default();
|
|
19
|
-
for (const entry of data) {
|
|
20
|
-
const path = fixUnicodePath(entry.path);
|
|
21
|
-
tar.append(path, entry.data);
|
|
22
|
-
}
|
|
23
|
-
return tar.out;
|
|
24
|
-
}
|
|
25
|
-
exports.makeTar = makeTar;
|