@ethersphere/bee-js 8.3.1 → 9.0.2
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 +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +142 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +216 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
package/dist/mjs/utils/type.js
CHANGED
|
@@ -1,288 +1,216 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { BeeArgumentError, BeeError } from "./error.js";
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import * as stream from 'stream';
|
|
3
|
+
import { TAGS_LIMIT_MAX, TAGS_LIMIT_MIN } from "../types/index.js";
|
|
5
4
|
import { isFile } from "./file.js";
|
|
6
|
-
import {
|
|
7
|
-
export function isReadable(
|
|
8
|
-
return typeof Readable !== 'undefined' &&
|
|
5
|
+
import { PublicKey, Reference } from "./typed-bytes.js";
|
|
6
|
+
export function isReadable(value) {
|
|
7
|
+
return typeof stream.Readable !== 'undefined' && value instanceof stream.Readable;
|
|
9
8
|
}
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export function isObject(value) {
|
|
14
|
-
return value !== null && typeof value === 'object';
|
|
15
|
-
}
|
|
16
|
-
export function isStrictlyObject(value) {
|
|
17
|
-
return isObject(value) && !Array.isArray(value);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Asserts if object is Error
|
|
21
|
-
*
|
|
22
|
-
* @param e
|
|
23
|
-
*/
|
|
24
|
-
export function isError(e) {
|
|
25
|
-
return e instanceof Error;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
28
|
-
export function assertStrictlyObject(value, name = 'value') {
|
|
29
|
-
if (!isStrictlyObject(value)) {
|
|
30
|
-
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export function assertBoolean(value, name = 'value') {
|
|
34
|
-
if (value !== true && value !== false) throw new TypeError(`${name} is not boolean`);
|
|
35
|
-
}
|
|
36
|
-
export function assertInteger(value, name = 'value') {
|
|
37
|
-
if (!isInteger(value)) throw new TypeError(`${name} is not integer`);
|
|
38
|
-
}
|
|
39
|
-
export function assertNonNegativeInteger(value, name = 'Value') {
|
|
40
|
-
assertInteger(value, name);
|
|
41
|
-
if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
42
|
-
}
|
|
43
|
-
export function assertPositiveInteger(value, name = 'Value') {
|
|
44
|
-
assertInteger(value, name);
|
|
45
|
-
if (Number(value) <= 0) throw new BeeArgumentError(`${name} has to be bigger then zero`, value);
|
|
46
|
-
}
|
|
47
|
-
export function assertReference(value) {
|
|
48
|
-
try {
|
|
49
|
-
assertHexString(value, REFERENCE_HEX_LENGTH);
|
|
50
|
-
} catch (e) {
|
|
51
|
-
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export function assertReferenceOrEns(value) {
|
|
55
|
-
if (typeof value !== 'string') {
|
|
56
|
-
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
57
|
-
}
|
|
58
|
-
if (isHexString(value)) {
|
|
59
|
-
assertReference(value);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* a.asdf - VALID
|
|
64
|
-
* test.eth - VALID
|
|
65
|
-
* ADAM.ETH - VALID
|
|
66
|
-
* ADAM UHLIR.ETH - INVALID
|
|
67
|
-
* test.whatever.eth - VALID
|
|
68
|
-
* -adg.ets - INVALID
|
|
69
|
-
* adg-.ets - INVALID
|
|
70
|
-
* as-a.com - VALID
|
|
71
|
-
* ethswarm.org - VALID
|
|
72
|
-
* http://asdf.asf - INVALID
|
|
73
|
-
* řš+ýí.šě+ř.čě - VALID
|
|
74
|
-
* tsg.asg?asg - INVALID
|
|
75
|
-
* tsg.asg:1599 - INVALID
|
|
76
|
-
* ethswarm.something- - INVALID
|
|
77
|
-
* ethswarm.-something - INVALID
|
|
78
|
-
* ethswarm.some-thing - VALID
|
|
79
|
-
*
|
|
80
|
-
* The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
|
|
81
|
-
*
|
|
82
|
-
* This part matches 2-63 character string that does not start or end with -
|
|
83
|
-
* [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
|
|
84
|
-
*
|
|
85
|
-
* For 1 character long string we use the part after |
|
|
86
|
-
* [^-.\/?:\s] <regexp2>
|
|
87
|
-
*
|
|
88
|
-
* This is terminated in a group with . character an repeated at least once
|
|
89
|
-
* (<regexp1>|<regexp2>\.)+
|
|
90
|
-
*
|
|
91
|
-
* This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
|
|
92
|
-
* ^(<regexp1>|<regexp2>\.)+<regexp1>$
|
|
93
|
-
*/
|
|
94
|
-
const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
|
|
95
|
-
// We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
96
|
-
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
97
|
-
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
98
|
-
if (!DOMAIN_REGEX.test(value)) {
|
|
99
|
-
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
9
|
+
export function asNumberString(value, options) {
|
|
10
|
+
if (typeof value === 'bigint') {
|
|
11
|
+
value = value.toString();
|
|
100
12
|
}
|
|
13
|
+
return Types.asIntegerString(value, options);
|
|
101
14
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* @param expectedCidType
|
|
107
|
-
*/
|
|
108
|
-
export function makeReferenceOrEns(value, expectedCidType) {
|
|
109
|
-
if (typeof value !== 'string') {
|
|
110
|
-
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
const result = convertCidToReference(value);
|
|
114
|
-
if (result.type !== expectedCidType) {
|
|
115
|
-
throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
|
|
116
|
-
}
|
|
117
|
-
return result.reference;
|
|
118
|
-
} catch (e) {
|
|
119
|
-
if (e instanceof BeeError) throw e;
|
|
120
|
-
}
|
|
121
|
-
assertReferenceOrEns(value);
|
|
122
|
-
return value;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Function that adds getter which converts the reference into CID base32 encoded string.
|
|
126
|
-
* @param result
|
|
127
|
-
* @param cidType feed or manifest
|
|
128
|
-
*/
|
|
129
|
-
export function addCidConversionFunction(result, cidType) {
|
|
15
|
+
export function prepareBeeRequestOptions(value) {
|
|
16
|
+
const object = Types.asObject(value, {
|
|
17
|
+
name: 'BeeRequestOptions'
|
|
18
|
+
});
|
|
130
19
|
return {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
20
|
+
baseURL: Types.asOptional(x => Types.asString(x, {
|
|
21
|
+
name: 'baseURL'
|
|
22
|
+
}), object.baseURL),
|
|
23
|
+
timeout: Types.asOptional(x => Types.asInteger(x, {
|
|
24
|
+
name: 'timeout',
|
|
25
|
+
min: 0
|
|
26
|
+
}), object.timeout),
|
|
27
|
+
headers: Types.asOptional(x => Types.asStringMap(x, {
|
|
28
|
+
name: 'headers'
|
|
29
|
+
}), object.headers),
|
|
30
|
+
onRequest: Types.asOptional(x => Types.asFunction(x, {
|
|
31
|
+
name: 'onRequest'
|
|
32
|
+
}), object.onRequest),
|
|
33
|
+
httpAgent: object.httpAgent,
|
|
34
|
+
httpsAgent: object.httpsAgent,
|
|
35
|
+
endlesslyRetry: Types.asOptional(x => Types.asBoolean(x, {
|
|
36
|
+
name: 'endlesslyRetry'
|
|
37
|
+
}), object.endlesslyRetry)
|
|
135
38
|
};
|
|
136
39
|
}
|
|
137
|
-
export function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
40
|
+
export function prepareDownloadOptions(value) {
|
|
41
|
+
const object = Types.asObject(value, {
|
|
42
|
+
name: 'DownloadOptions'
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
redundancyStrategy: Types.asOptional(x => Types.asInteger(x, {
|
|
46
|
+
name: 'redundancyStrategy'
|
|
47
|
+
}), object.redundancyStrategy),
|
|
48
|
+
fallback: Types.asOptional(x => Types.asBoolean(x, {
|
|
49
|
+
name: 'fallback'
|
|
50
|
+
}), object.fallback),
|
|
51
|
+
timeoutMs: Types.asOptional(x => Types.asInteger(x, {
|
|
52
|
+
name: 'timeoutMs',
|
|
53
|
+
min: 0
|
|
54
|
+
}), object.timeoutMs),
|
|
55
|
+
actPublisher: Types.asOptional(x => new PublicKey(x), object.actPublisher),
|
|
56
|
+
actHistoryAddress: Types.asOptional(x => new Reference(x), object.actHistoryAddress),
|
|
57
|
+
actTimestamp: Types.asOptional(x => Types.asNumber(x, {
|
|
58
|
+
name: 'actTimestamp'
|
|
59
|
+
}), object.actTimestamp)
|
|
60
|
+
};
|
|
142
61
|
}
|
|
143
|
-
export function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
62
|
+
export function prepareUploadOptions(value, name = 'UploadOptions') {
|
|
63
|
+
const object = Types.asObject(value, {
|
|
64
|
+
name
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
act: Types.asOptional(x => Types.asBoolean(x, {
|
|
68
|
+
name: 'act'
|
|
69
|
+
}), object.act),
|
|
70
|
+
actHistoryAddress: Types.asOptional(x => new Reference(x), object.actHistoryAddress),
|
|
71
|
+
deferred: Types.asOptional(x => Types.asBoolean(x, {
|
|
72
|
+
name: 'deferred'
|
|
73
|
+
}), object.deferred),
|
|
74
|
+
encrypt: Types.asOptional(x => Types.asBoolean(x, {
|
|
75
|
+
name: 'encrypt'
|
|
76
|
+
}), object.encrypt),
|
|
77
|
+
pin: Types.asOptional(x => Types.asBoolean(x, {
|
|
78
|
+
name: 'pin'
|
|
79
|
+
}), object.pin),
|
|
80
|
+
tag: Types.asOptional(x => Types.asInteger(x, {
|
|
81
|
+
name: 'tag',
|
|
82
|
+
min: 0
|
|
83
|
+
}), object.tag)
|
|
84
|
+
};
|
|
154
85
|
}
|
|
155
|
-
export function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
if (options.tag) {
|
|
168
|
-
if (typeof options.tag !== 'number') {
|
|
169
|
-
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
170
|
-
}
|
|
171
|
-
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
172
|
-
}
|
|
86
|
+
export function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
|
|
87
|
+
const uploadOptions = prepareUploadOptions(value, name);
|
|
88
|
+
const object = Types.asObject(value, {
|
|
89
|
+
name
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
...uploadOptions,
|
|
93
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
94
|
+
name: 'redundancyLevel',
|
|
95
|
+
min: 0
|
|
96
|
+
}), object.redundancyLevel)
|
|
97
|
+
};
|
|
173
98
|
}
|
|
174
|
-
export function
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
99
|
+
export function prepareFileUploadOptions(value) {
|
|
100
|
+
const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
|
|
101
|
+
const object = Types.asObject(value, {
|
|
102
|
+
name: 'FileUploadOptions'
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
...uploadOptions,
|
|
106
|
+
size: Types.asOptional(x => Types.asInteger(x, {
|
|
107
|
+
name: 'size',
|
|
108
|
+
min: 0
|
|
109
|
+
}), object.size),
|
|
110
|
+
contentType: Types.asOptional(x => Types.asString(x, {
|
|
111
|
+
name: 'contentType'
|
|
112
|
+
}), object.contentType),
|
|
113
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
114
|
+
name: 'redundancyLevel',
|
|
115
|
+
min: 0
|
|
116
|
+
}), object.redundancyLevel)
|
|
117
|
+
};
|
|
186
118
|
}
|
|
187
|
-
export function
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
119
|
+
export function prepareCollectionUploadOptions(value) {
|
|
120
|
+
const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
|
|
121
|
+
const object = Types.asObject(value, {
|
|
122
|
+
name: 'CollectionUploadOptions'
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
...uploadOptions,
|
|
126
|
+
errorDocument: Types.asOptional(x => Types.asString(x, {
|
|
127
|
+
name: 'errorDocument'
|
|
128
|
+
}), object.errorDocument),
|
|
129
|
+
indexDocument: Types.asOptional(x => Types.asString(x, {
|
|
130
|
+
name: 'indexDocument'
|
|
131
|
+
}), object.indexDocument),
|
|
132
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
133
|
+
name: 'redundancyLevel',
|
|
134
|
+
min: 0
|
|
135
|
+
}), object.redundancyLevel)
|
|
136
|
+
};
|
|
196
137
|
}
|
|
197
138
|
export function isTag(value) {
|
|
198
|
-
|
|
139
|
+
try {
|
|
140
|
+
const object = Types.asObject(value, {
|
|
141
|
+
name: 'Tag'
|
|
142
|
+
});
|
|
143
|
+
Types.asInteger(object.uid, {
|
|
144
|
+
name: 'Tag.uid'
|
|
145
|
+
});
|
|
146
|
+
return true;
|
|
147
|
+
} catch {
|
|
199
148
|
return false;
|
|
200
149
|
}
|
|
201
|
-
return Boolean(value.uid);
|
|
202
|
-
}
|
|
203
|
-
export function assertTag(value) {
|
|
204
|
-
if (!isStrictlyObject(value)) {
|
|
205
|
-
throw new TypeError('Tag is not an object!');
|
|
206
|
-
}
|
|
207
|
-
const tag = value;
|
|
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
|
-
if (typeof tag[numberProperty] !== 'number') {
|
|
214
|
-
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (!tag.startedAt) {
|
|
218
|
-
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
219
|
-
}
|
|
220
|
-
if (typeof tag.startedAt !== 'string') {
|
|
221
|
-
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
222
|
-
}
|
|
223
150
|
}
|
|
224
|
-
export function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
237
|
-
}
|
|
238
|
-
if (typeof handler.onError !== 'function') {
|
|
239
|
-
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
export function assertPublicKey(value) {
|
|
243
|
-
assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
151
|
+
export function preparePssMessageHandler(value) {
|
|
152
|
+
const object = Types.asObject(value, {
|
|
153
|
+
name: 'PssMessageHandler'
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
onMessage: Types.asFunction(object.onMessage, {
|
|
157
|
+
name: 'onMessage'
|
|
158
|
+
}),
|
|
159
|
+
onError: Types.asFunction(object.onError, {
|
|
160
|
+
name: 'onError'
|
|
161
|
+
})
|
|
162
|
+
};
|
|
244
163
|
}
|
|
245
|
-
export function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
if (options?.waitForUsable !== undefined) {
|
|
259
|
-
assertBoolean(options.waitForUsable);
|
|
260
|
-
}
|
|
261
|
-
if (options?.waitForUsableTimeout !== undefined) {
|
|
262
|
-
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
263
|
-
}
|
|
164
|
+
export function prepareGsocMessageHandler(value) {
|
|
165
|
+
const object = Types.asObject(value, {
|
|
166
|
+
name: 'GsocMessageHandler'
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
onMessage: Types.asFunction(object.onMessage, {
|
|
170
|
+
name: 'onMessage'
|
|
171
|
+
}),
|
|
172
|
+
onError: Types.asFunction(object.onError, {
|
|
173
|
+
name: 'onError'
|
|
174
|
+
})
|
|
175
|
+
};
|
|
264
176
|
}
|
|
265
|
-
export function
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
177
|
+
export function preparePostageBatchOptions(value) {
|
|
178
|
+
const object = Types.asObject(value, {
|
|
179
|
+
name: 'PostageBatchOptions'
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
gasPrice: Types.asOptional(x => asNumberString(x, {
|
|
183
|
+
name: 'gasPrice'
|
|
184
|
+
}), object.gasPrice),
|
|
185
|
+
immutableFlag: Types.asOptional(x => Types.asBoolean(x, {
|
|
186
|
+
name: 'immutableFlag'
|
|
187
|
+
}), object.immutableFlag),
|
|
188
|
+
label: Types.asOptional(x => Types.asString(x, {
|
|
189
|
+
name: 'label'
|
|
190
|
+
}), object.label),
|
|
191
|
+
waitForUsable: Types.asOptional(x => Types.asBoolean(x, {
|
|
192
|
+
name: 'waitForUsable'
|
|
193
|
+
}), object.waitForUsable),
|
|
194
|
+
waitForUsableTimeout: Types.asOptional(x => Types.asInteger(x, {
|
|
195
|
+
name: 'waitForUsableTimeout',
|
|
196
|
+
min: 0
|
|
197
|
+
}), object.waitForUsableTimeout)
|
|
198
|
+
};
|
|
277
199
|
}
|
|
278
|
-
export function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
200
|
+
export function prepareTransactionOptions(value, name = 'TransactionOptions') {
|
|
201
|
+
const object = Types.asObject(value, {
|
|
202
|
+
name
|
|
203
|
+
});
|
|
204
|
+
return {
|
|
205
|
+
gasLimit: Types.asOptional(x => asNumberString(x, {
|
|
206
|
+
name: 'gasLimit',
|
|
207
|
+
min: 0n
|
|
208
|
+
}), object.gasLimit),
|
|
209
|
+
gasPrice: Types.asOptional(x => asNumberString(x, {
|
|
210
|
+
name: 'gasPrice',
|
|
211
|
+
min: 0n
|
|
212
|
+
}), object.gasPrice)
|
|
213
|
+
};
|
|
286
214
|
}
|
|
287
215
|
/**
|
|
288
216
|
* Check whether the given parameter is valid data to upload
|
|
@@ -308,26 +236,21 @@ export function assertFileData(value) {
|
|
|
308
236
|
* Checks whether optional options for AllTags query are valid
|
|
309
237
|
* @param options
|
|
310
238
|
*/
|
|
311
|
-
export function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (options?.offset !== undefined) {
|
|
329
|
-
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
330
|
-
}
|
|
239
|
+
export function prepareAllTagsOptions(value) {
|
|
240
|
+
const object = Types.asObject(value, {
|
|
241
|
+
name: 'AllTagsOptions'
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
limit: Types.asOptional(x => Types.asInteger(x, {
|
|
245
|
+
name: 'limit',
|
|
246
|
+
min: TAGS_LIMIT_MIN,
|
|
247
|
+
max: TAGS_LIMIT_MAX
|
|
248
|
+
}), object.limit),
|
|
249
|
+
offset: Types.asOptional(x => Types.asInteger(x, {
|
|
250
|
+
name: 'offset',
|
|
251
|
+
min: 0
|
|
252
|
+
}), object.offset)
|
|
253
|
+
};
|
|
331
254
|
}
|
|
332
255
|
/**
|
|
333
256
|
* Utility functions that return Tag UID
|
|
@@ -335,32 +258,15 @@ export function assertAllTagsOptions(entry) {
|
|
|
335
258
|
*/
|
|
336
259
|
export function makeTagUid(tagUid) {
|
|
337
260
|
if (tagUid === undefined || tagUid === null) {
|
|
338
|
-
throw new TypeError(
|
|
261
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
339
262
|
}
|
|
340
263
|
if (isTag(tagUid)) {
|
|
341
264
|
return tagUid.uid;
|
|
342
|
-
} else if (typeof tagUid === 'number') {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (isNaN(int)) {
|
|
348
|
-
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
349
|
-
}
|
|
350
|
-
if (int < 0) {
|
|
351
|
-
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
352
|
-
}
|
|
353
|
-
return int;
|
|
354
|
-
}
|
|
355
|
-
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
356
|
-
}
|
|
357
|
-
export function assertTransactionHash(transactionHash) {
|
|
358
|
-
if (typeof transactionHash !== 'string') {
|
|
359
|
-
throw new TypeError('TransactionHash has to be a string!');
|
|
360
|
-
}
|
|
361
|
-
assertPrefixedHexString(transactionHash, 'TransactionHash');
|
|
362
|
-
// Hash is 64 long + '0x' prefix = 66
|
|
363
|
-
if (transactionHash.length !== 66) {
|
|
364
|
-
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
265
|
+
} else if (typeof tagUid === 'number' || typeof tagUid === 'string') {
|
|
266
|
+
return Types.asNumber(tagUid, {
|
|
267
|
+
name: 'tagUid',
|
|
268
|
+
min: 0
|
|
269
|
+
});
|
|
365
270
|
}
|
|
271
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
366
272
|
}
|