@ethersphere/bee-js 8.3.0 → 9.0.1
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/tar-writer.js +4 -0
- package/dist/cjs/utils/tar.browser.js +1 -1
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +141 -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/tar-writer.js +3 -0
- package/dist/mjs/utils/tar.browser.js +1 -1
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +215 -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,215 @@
|
|
|
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
|
+
deferred: Types.asOptional(x => Types.asBoolean(x, {
|
|
71
|
+
name: 'deferred'
|
|
72
|
+
}), object.deferred),
|
|
73
|
+
encrypt: Types.asOptional(x => Types.asBoolean(x, {
|
|
74
|
+
name: 'encrypt'
|
|
75
|
+
}), object.encrypt),
|
|
76
|
+
pin: Types.asOptional(x => Types.asBoolean(x, {
|
|
77
|
+
name: 'pin'
|
|
78
|
+
}), object.pin),
|
|
79
|
+
tag: Types.asOptional(x => Types.asInteger(x, {
|
|
80
|
+
name: 'tag',
|
|
81
|
+
min: 0
|
|
82
|
+
}), object.tag)
|
|
83
|
+
};
|
|
154
84
|
}
|
|
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
|
-
}
|
|
85
|
+
export function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
|
|
86
|
+
const uploadOptions = prepareUploadOptions(value, name);
|
|
87
|
+
const object = Types.asObject(value, {
|
|
88
|
+
name
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
...uploadOptions,
|
|
92
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
93
|
+
name: 'redundancyLevel',
|
|
94
|
+
min: 0
|
|
95
|
+
}), object.redundancyLevel)
|
|
96
|
+
};
|
|
173
97
|
}
|
|
174
|
-
export function
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
98
|
+
export function prepareFileUploadOptions(value) {
|
|
99
|
+
const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
|
|
100
|
+
const object = Types.asObject(value, {
|
|
101
|
+
name: 'FileUploadOptions'
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
...uploadOptions,
|
|
105
|
+
size: Types.asOptional(x => Types.asInteger(x, {
|
|
106
|
+
name: 'size',
|
|
107
|
+
min: 0
|
|
108
|
+
}), object.size),
|
|
109
|
+
contentType: Types.asOptional(x => Types.asString(x, {
|
|
110
|
+
name: 'contentType'
|
|
111
|
+
}), object.contentType),
|
|
112
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
113
|
+
name: 'redundancyLevel',
|
|
114
|
+
min: 0
|
|
115
|
+
}), object.redundancyLevel)
|
|
116
|
+
};
|
|
186
117
|
}
|
|
187
|
-
export function
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
118
|
+
export function prepareCollectionUploadOptions(value) {
|
|
119
|
+
const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
|
|
120
|
+
const object = Types.asObject(value, {
|
|
121
|
+
name: 'CollectionUploadOptions'
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
...uploadOptions,
|
|
125
|
+
errorDocument: Types.asOptional(x => Types.asString(x, {
|
|
126
|
+
name: 'errorDocument'
|
|
127
|
+
}), object.errorDocument),
|
|
128
|
+
indexDocument: Types.asOptional(x => Types.asString(x, {
|
|
129
|
+
name: 'indexDocument'
|
|
130
|
+
}), object.indexDocument),
|
|
131
|
+
redundancyLevel: Types.asOptional(x => Types.asInteger(x, {
|
|
132
|
+
name: 'redundancyLevel',
|
|
133
|
+
min: 0
|
|
134
|
+
}), object.redundancyLevel)
|
|
135
|
+
};
|
|
196
136
|
}
|
|
197
137
|
export function isTag(value) {
|
|
198
|
-
|
|
138
|
+
try {
|
|
139
|
+
const object = Types.asObject(value, {
|
|
140
|
+
name: 'Tag'
|
|
141
|
+
});
|
|
142
|
+
Types.asInteger(object.uid, {
|
|
143
|
+
name: 'Tag.uid'
|
|
144
|
+
});
|
|
145
|
+
return true;
|
|
146
|
+
} catch {
|
|
199
147
|
return false;
|
|
200
148
|
}
|
|
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
149
|
}
|
|
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');
|
|
150
|
+
export function preparePssMessageHandler(value) {
|
|
151
|
+
const object = Types.asObject(value, {
|
|
152
|
+
name: 'PssMessageHandler'
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
onMessage: Types.asFunction(object.onMessage, {
|
|
156
|
+
name: 'onMessage'
|
|
157
|
+
}),
|
|
158
|
+
onError: Types.asFunction(object.onError, {
|
|
159
|
+
name: 'onError'
|
|
160
|
+
})
|
|
161
|
+
};
|
|
244
162
|
}
|
|
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
|
-
}
|
|
163
|
+
export function prepareGsocMessageHandler(value) {
|
|
164
|
+
const object = Types.asObject(value, {
|
|
165
|
+
name: 'GsocMessageHandler'
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
onMessage: Types.asFunction(object.onMessage, {
|
|
169
|
+
name: 'onMessage'
|
|
170
|
+
}),
|
|
171
|
+
onError: Types.asFunction(object.onError, {
|
|
172
|
+
name: 'onError'
|
|
173
|
+
})
|
|
174
|
+
};
|
|
264
175
|
}
|
|
265
|
-
export function
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
176
|
+
export function preparePostageBatchOptions(value) {
|
|
177
|
+
const object = Types.asObject(value, {
|
|
178
|
+
name: 'PostageBatchOptions'
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
gasPrice: Types.asOptional(x => asNumberString(x, {
|
|
182
|
+
name: 'gasPrice'
|
|
183
|
+
}), object.gasPrice),
|
|
184
|
+
immutableFlag: Types.asOptional(x => Types.asBoolean(x, {
|
|
185
|
+
name: 'immutableFlag'
|
|
186
|
+
}), object.immutableFlag),
|
|
187
|
+
label: Types.asOptional(x => Types.asString(x, {
|
|
188
|
+
name: 'label'
|
|
189
|
+
}), object.label),
|
|
190
|
+
waitForUsable: Types.asOptional(x => Types.asBoolean(x, {
|
|
191
|
+
name: 'waitForUsable'
|
|
192
|
+
}), object.waitForUsable),
|
|
193
|
+
waitForUsableTimeout: Types.asOptional(x => Types.asInteger(x, {
|
|
194
|
+
name: 'waitForUsableTimeout',
|
|
195
|
+
min: 0
|
|
196
|
+
}), object.waitForUsableTimeout)
|
|
197
|
+
};
|
|
277
198
|
}
|
|
278
|
-
export function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
199
|
+
export function prepareTransactionOptions(value, name = 'TransactionOptions') {
|
|
200
|
+
const object = Types.asObject(value, {
|
|
201
|
+
name
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
gasLimit: Types.asOptional(x => asNumberString(x, {
|
|
205
|
+
name: 'gasLimit',
|
|
206
|
+
min: 0n
|
|
207
|
+
}), object.gasLimit),
|
|
208
|
+
gasPrice: Types.asOptional(x => asNumberString(x, {
|
|
209
|
+
name: 'gasPrice',
|
|
210
|
+
min: 0n
|
|
211
|
+
}), object.gasPrice)
|
|
212
|
+
};
|
|
286
213
|
}
|
|
287
214
|
/**
|
|
288
215
|
* Check whether the given parameter is valid data to upload
|
|
@@ -308,26 +235,21 @@ export function assertFileData(value) {
|
|
|
308
235
|
* Checks whether optional options for AllTags query are valid
|
|
309
236
|
* @param options
|
|
310
237
|
*/
|
|
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
|
-
}
|
|
238
|
+
export function prepareAllTagsOptions(value) {
|
|
239
|
+
const object = Types.asObject(value, {
|
|
240
|
+
name: 'AllTagsOptions'
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
limit: Types.asOptional(x => Types.asInteger(x, {
|
|
244
|
+
name: 'limit',
|
|
245
|
+
min: TAGS_LIMIT_MIN,
|
|
246
|
+
max: TAGS_LIMIT_MAX
|
|
247
|
+
}), object.limit),
|
|
248
|
+
offset: Types.asOptional(x => Types.asInteger(x, {
|
|
249
|
+
name: 'offset',
|
|
250
|
+
min: 0
|
|
251
|
+
}), object.offset)
|
|
252
|
+
};
|
|
331
253
|
}
|
|
332
254
|
/**
|
|
333
255
|
* Utility functions that return Tag UID
|
|
@@ -335,32 +257,15 @@ export function assertAllTagsOptions(entry) {
|
|
|
335
257
|
*/
|
|
336
258
|
export function makeTagUid(tagUid) {
|
|
337
259
|
if (tagUid === undefined || tagUid === null) {
|
|
338
|
-
throw new TypeError(
|
|
260
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
339
261
|
}
|
|
340
262
|
if (isTag(tagUid)) {
|
|
341
263
|
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)');
|
|
264
|
+
} else if (typeof tagUid === 'number' || typeof tagUid === 'string') {
|
|
265
|
+
return Types.asNumber(tagUid, {
|
|
266
|
+
name: 'tagUid',
|
|
267
|
+
min: 0
|
|
268
|
+
});
|
|
365
269
|
}
|
|
270
|
+
throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
|
|
366
271
|
}
|