@ar.io/sdk 3.12.0-alpha.1 → 3.12.0-beta.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/bundles/web.bundle.min.js +170 -167
- package/lib/cjs/common/index.js +2 -0
- package/lib/cjs/common/wayfinder/gateways/network.js +48 -0
- package/lib/cjs/common/wayfinder/gateways/simple-cache.js +35 -0
- package/lib/cjs/common/wayfinder/gateways/static.js +13 -0
- package/lib/cjs/common/wayfinder/index.js +47 -0
- package/lib/cjs/common/wayfinder/routing/strategies/ping.js +72 -0
- package/lib/cjs/common/wayfinder/routing/strategies/random.js +13 -0
- package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +42 -0
- package/lib/cjs/common/wayfinder/routing/strategies/static.js +29 -0
- package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +139 -0
- package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +50 -0
- package/lib/cjs/common/wayfinder/verification/trusted.js +106 -0
- package/lib/cjs/common/wayfinder/wayfinder.js +735 -0
- package/lib/cjs/types/wayfinder.js +3 -0
- package/lib/cjs/utils/json.js +0 -1
- package/lib/cjs/utils/url.js +3 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/index.js +2 -0
- package/lib/esm/common/wayfinder/gateways/network.js +44 -0
- package/lib/esm/common/wayfinder/gateways/simple-cache.js +31 -0
- package/lib/esm/common/wayfinder/gateways/static.js +9 -0
- package/lib/esm/common/wayfinder/index.js +31 -0
- package/lib/esm/common/wayfinder/routing/strategies/ping.js +68 -0
- package/lib/esm/common/wayfinder/routing/strategies/random.js +9 -0
- package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +38 -0
- package/lib/esm/common/wayfinder/routing/strategies/static.js +25 -0
- package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +130 -0
- package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +46 -0
- package/lib/esm/common/wayfinder/verification/trusted.js +102 -0
- package/lib/esm/common/wayfinder/wayfinder.js +723 -0
- package/lib/esm/types/wayfinder.js +2 -0
- package/lib/esm/utils/json.js +0 -1
- package/lib/esm/utils/url.js +3 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/wayfinder/gateways/network.d.ts +33 -0
- package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +31 -0
- package/lib/types/common/wayfinder/gateways/static.d.ts +23 -0
- package/lib/types/common/wayfinder/index.d.ts +26 -0
- package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +27 -0
- package/lib/types/common/wayfinder/routing/strategies/random.d.ts +21 -0
- package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +29 -0
- package/lib/types/common/wayfinder/routing/strategies/static.d.ts +29 -0
- package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +31 -0
- package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +27 -0
- package/lib/types/common/wayfinder/verification/trusted.d.ts +51 -0
- package/lib/types/common/wayfinder/wayfinder.d.ts +299 -0
- package/lib/types/types/wayfinder.d.ts +66 -0
- package/lib/types/utils/json.d.ts +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/lib/cjs/types/ant.test.js +0 -150
- package/lib/cjs/types/token.test.js +0 -83
- package/lib/cjs/utils/ant.test.js +0 -111
- package/lib/cjs/utils/b64.test.js +0 -72
- package/lib/cjs/utils/url.test.js +0 -24
- package/lib/cjs/utils/utils.test.js +0 -194
- package/lib/esm/types/ant.test.js +0 -148
- package/lib/esm/types/token.test.js +0 -81
- package/lib/esm/utils/ant.test.js +0 -109
- package/lib/esm/utils/b64.test.js +0 -70
- package/lib/esm/utils/url.test.js +0 -19
- package/lib/esm/utils/utils.test.js +0 -192
- package/lib/types/types/ant.test.d.ts +0 -1
- package/lib/types/types/token.test.d.ts +0 -1
- package/lib/types/utils/ant.test.d.ts +0 -1
- package/lib/types/utils/b64.test.d.ts +0 -1
- package/lib/types/utils/url.test.d.ts +0 -1
- package/lib/types/utils/utils.test.d.ts +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Readable } from 'stream';
|
|
17
|
+
export interface RoutingStrategy {
|
|
18
|
+
selectGateway: ({ gateways }: {
|
|
19
|
+
gateways: URL[];
|
|
20
|
+
}) => Promise<URL>;
|
|
21
|
+
}
|
|
22
|
+
export interface GatewaysProvider {
|
|
23
|
+
getGateways: () => Promise<URL[]>;
|
|
24
|
+
}
|
|
25
|
+
export interface DataVerificationStrategy {
|
|
26
|
+
/**
|
|
27
|
+
* Verifies the provided data for a given txId
|
|
28
|
+
*
|
|
29
|
+
* Depending on the implementation, the hash can be the computed data root of a transaction, the digest of the data, or some other hash of the data.
|
|
30
|
+
*
|
|
31
|
+
* The interface is intended to be vague in order to support various degrees of verification.
|
|
32
|
+
*
|
|
33
|
+
* @param data - The data to verify
|
|
34
|
+
* @param txId - The txId of the data
|
|
35
|
+
* @returns the hash of the data
|
|
36
|
+
*/
|
|
37
|
+
verifyData: ({ data, txId, }: {
|
|
38
|
+
data: Buffer | Readable | ReadableStream;
|
|
39
|
+
txId: string;
|
|
40
|
+
}) => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface DataHashProvider {
|
|
43
|
+
/**
|
|
44
|
+
* Returns a hash for the provided txId using the specified algorithm.
|
|
45
|
+
*
|
|
46
|
+
* @param txId - The txId of the data
|
|
47
|
+
* @returns the hash of the data
|
|
48
|
+
*/
|
|
49
|
+
getHash: ({ txId, }: {
|
|
50
|
+
txId: string;
|
|
51
|
+
}) => Promise<{
|
|
52
|
+
hash: string;
|
|
53
|
+
algorithm: 'sha256';
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
export interface DataRootProvider {
|
|
57
|
+
/**
|
|
58
|
+
* Returns the data root for the provided txId
|
|
59
|
+
*
|
|
60
|
+
* @param txId - The txId of the data
|
|
61
|
+
* @returns the data root of the data
|
|
62
|
+
*/
|
|
63
|
+
getDataRoot: ({ txId }: {
|
|
64
|
+
txId: string;
|
|
65
|
+
}) => Promise<string>;
|
|
66
|
+
}
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "3.12.0-
|
|
3
|
+
"version": "3.12.0-beta.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
|
|
73
73
|
"test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
|
|
74
74
|
"test:web": "yarn build:esm && yarn link && cd ./tests/e2e/web && yarn && yarn test",
|
|
75
|
-
"test:unit": "node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
|
|
75
|
+
"test:unit": "c8 node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
|
|
76
76
|
"test:link": "yarn build && yarn link",
|
|
77
77
|
"test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
|
|
78
78
|
"test:integration": "yarn build:esm && yarn link && cd ./tests/integration && yarn && yarn test",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
100
100
|
"@typescript-eslint/parser": "^6.4.0",
|
|
101
101
|
"arconnect": "^1.0.3",
|
|
102
|
+
"c8": "^10.1.3",
|
|
102
103
|
"dotenv": "^16.4.5",
|
|
103
104
|
"dotenv-cli": "^7.4.2",
|
|
104
105
|
"esbuild": "^0.25.2",
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const ant_js_1 = require("./ant.js");
|
|
7
|
-
const stub_arweave_address = 'valid-address'.padEnd(43, '1');
|
|
8
|
-
const stub_eth_address = '0x8B5f221c8837d862b818799e6b19cc23CE23B0E5';
|
|
9
|
-
(0, node_test_1.describe)('ANT Schemas', () => {
|
|
10
|
-
(0, node_test_1.it)('should validate AntStateSchema', () => {
|
|
11
|
-
const validState = {
|
|
12
|
-
Name: 'TestToken',
|
|
13
|
-
Ticker: 'TST',
|
|
14
|
-
Description: 'Test description',
|
|
15
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
16
|
-
Denomination: 0,
|
|
17
|
-
Owner: stub_arweave_address,
|
|
18
|
-
Controllers: [stub_arweave_address],
|
|
19
|
-
Records: {
|
|
20
|
-
record1: {
|
|
21
|
-
transactionId: stub_arweave_address,
|
|
22
|
-
ttlSeconds: 3600,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
Balances: {
|
|
26
|
-
[stub_arweave_address]: 1,
|
|
27
|
-
},
|
|
28
|
-
Logo: stub_arweave_address,
|
|
29
|
-
TotalSupply: 1,
|
|
30
|
-
Initialized: true,
|
|
31
|
-
};
|
|
32
|
-
const invalidState = {
|
|
33
|
-
Name: 'TestToken',
|
|
34
|
-
Ticker: 'TST',
|
|
35
|
-
Description: 'Test description',
|
|
36
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
37
|
-
Denomination: 0,
|
|
38
|
-
Owner: stub_arweave_address,
|
|
39
|
-
Controllers: [stub_arweave_address],
|
|
40
|
-
Records: {
|
|
41
|
-
record1: {
|
|
42
|
-
transactionId: 'invalid-id',
|
|
43
|
-
ttlSeconds: '3600',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
Balances: {
|
|
47
|
-
[stub_arweave_address]: 1,
|
|
48
|
-
},
|
|
49
|
-
Logo: stub_arweave_address,
|
|
50
|
-
TotalSupply: -1,
|
|
51
|
-
Initialized: true,
|
|
52
|
-
};
|
|
53
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntStateSchema.parse(validState));
|
|
54
|
-
node_assert_1.strict.throws(() => ant_js_1.AntStateSchema.parse(invalidState), zod_1.z.ZodError);
|
|
55
|
-
});
|
|
56
|
-
(0, node_test_1.it)('should validate AntStateSchema with ETH address', () => {
|
|
57
|
-
const validState = {
|
|
58
|
-
Name: 'TestToken',
|
|
59
|
-
Ticker: 'TST',
|
|
60
|
-
Description: 'Test description',
|
|
61
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
62
|
-
Denomination: 0,
|
|
63
|
-
Owner: stub_eth_address,
|
|
64
|
-
Controllers: [stub_eth_address],
|
|
65
|
-
Records: {
|
|
66
|
-
record1: {
|
|
67
|
-
transactionId: stub_arweave_address,
|
|
68
|
-
ttlSeconds: 3600,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
Balances: {
|
|
72
|
-
[stub_eth_address]: 1,
|
|
73
|
-
},
|
|
74
|
-
Logo: stub_arweave_address,
|
|
75
|
-
TotalSupply: 1,
|
|
76
|
-
Initialized: true,
|
|
77
|
-
};
|
|
78
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntStateSchema.parse(validState));
|
|
79
|
-
});
|
|
80
|
-
(0, node_test_1.it)('should validate AntInfoSchema', () => {
|
|
81
|
-
const validInfo = {
|
|
82
|
-
Name: 'TestToken',
|
|
83
|
-
Owner: stub_arweave_address,
|
|
84
|
-
Ticker: 'TST',
|
|
85
|
-
Description: 'Test description',
|
|
86
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
87
|
-
['Total-Supply']: '1',
|
|
88
|
-
Logo: stub_arweave_address,
|
|
89
|
-
Denomination: '0',
|
|
90
|
-
Handlers: ant_js_1.AntHandlerNames,
|
|
91
|
-
};
|
|
92
|
-
const invalidInfo = {
|
|
93
|
-
Name: 'TestToken',
|
|
94
|
-
Owner: stub_arweave_address,
|
|
95
|
-
Ticker: 'TST',
|
|
96
|
-
['Total-Supply']: 1000,
|
|
97
|
-
Logo: stub_arweave_address,
|
|
98
|
-
Denomination: '1',
|
|
99
|
-
Handlers: ant_js_1.AntHandlerNames,
|
|
100
|
-
};
|
|
101
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntInfoSchema.parse(validInfo));
|
|
102
|
-
node_assert_1.strict.throws(() => ant_js_1.AntInfoSchema.parse(invalidInfo), zod_1.z.ZodError);
|
|
103
|
-
});
|
|
104
|
-
(0, node_test_1.it)('should validate isAoANTState', () => {
|
|
105
|
-
const validState = {
|
|
106
|
-
Name: 'TestToken',
|
|
107
|
-
Ticker: 'TST',
|
|
108
|
-
Description: 'Test description',
|
|
109
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
110
|
-
Denomination: 0,
|
|
111
|
-
Owner: stub_arweave_address,
|
|
112
|
-
Controllers: [stub_arweave_address],
|
|
113
|
-
Records: {
|
|
114
|
-
record1: {
|
|
115
|
-
transactionId: stub_arweave_address,
|
|
116
|
-
ttlSeconds: 3600,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
Balances: {
|
|
120
|
-
[stub_arweave_address]: 1,
|
|
121
|
-
},
|
|
122
|
-
Logo: stub_arweave_address,
|
|
123
|
-
TotalSupply: 0,
|
|
124
|
-
Initialized: true,
|
|
125
|
-
};
|
|
126
|
-
const invalidState = {
|
|
127
|
-
Name: 'TestToken',
|
|
128
|
-
Ticker: 'TST',
|
|
129
|
-
Description: 'Test description',
|
|
130
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
131
|
-
Denomination: 0,
|
|
132
|
-
Owner: stub_arweave_address,
|
|
133
|
-
Controllers: [stub_arweave_address],
|
|
134
|
-
Records: {
|
|
135
|
-
record1: {
|
|
136
|
-
transactionId: 'invalid-id',
|
|
137
|
-
ttlSeconds: '3600',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
Balances: {
|
|
141
|
-
[stub_arweave_address]: 1,
|
|
142
|
-
},
|
|
143
|
-
Logo: stub_arweave_address,
|
|
144
|
-
TotalSupply: -1,
|
|
145
|
-
Initialized: true,
|
|
146
|
-
};
|
|
147
|
-
node_assert_1.strict.strictEqual((0, ant_js_1.isAoANTState)(validState), true);
|
|
148
|
-
node_assert_1.strict.strictEqual((0, ant_js_1.isAoANTState)(invalidState), false);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const token_js_1 = require("./token.js");
|
|
6
|
-
(0, node_test_1.describe)('ARIOToken', () => {
|
|
7
|
-
(0, node_test_1.it)('should throw an error on invalid input', () => {
|
|
8
|
-
node_assert_1.strict.throws(() => new token_js_1.ARIOToken(-1));
|
|
9
|
-
});
|
|
10
|
-
(0, node_test_1.it)('should round at 6 decimal places', () => {
|
|
11
|
-
const token = new token_js_1.ARIOToken(1.123456789);
|
|
12
|
-
node_assert_1.strict.strictEqual(token.valueOf(), 1.123457);
|
|
13
|
-
});
|
|
14
|
-
(0, node_test_1.it)('should convert to mARIOToken', () => {
|
|
15
|
-
const token = new token_js_1.ARIOToken(1);
|
|
16
|
-
const mToken = token.toMARIO();
|
|
17
|
-
node_assert_1.strict.strictEqual(mToken.valueOf(), 1000000);
|
|
18
|
-
});
|
|
19
|
-
(0, node_test_1.it)('should print as a string', () => {
|
|
20
|
-
const token = new token_js_1.ARIOToken(1);
|
|
21
|
-
node_assert_1.strict.strictEqual(`${token}`, '1');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
(0, node_test_1.describe)('mARIOToken', () => {
|
|
25
|
-
(0, node_test_1.it)('should multiply by a number', () => {
|
|
26
|
-
const token = new token_js_1.mARIOToken(1);
|
|
27
|
-
const result = token.multiply(2);
|
|
28
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
29
|
-
});
|
|
30
|
-
(0, node_test_1.it)('should multiply by another mARIOToken', () => {
|
|
31
|
-
const token = new token_js_1.mARIOToken(1);
|
|
32
|
-
const result = token.multiply(new token_js_1.mARIOToken(2));
|
|
33
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
34
|
-
});
|
|
35
|
-
(0, node_test_1.it)('should divide by a number', () => {
|
|
36
|
-
const token = new token_js_1.mARIOToken(2);
|
|
37
|
-
const result = token.divide(2);
|
|
38
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
39
|
-
});
|
|
40
|
-
(0, node_test_1.it)('should divide by another mARIOToken', () => {
|
|
41
|
-
const token = new token_js_1.mARIOToken(2);
|
|
42
|
-
const result = token.divide(new token_js_1.mARIOToken(2));
|
|
43
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
44
|
-
});
|
|
45
|
-
(0, node_test_1.it)('should throw an error on division by zero', () => {
|
|
46
|
-
const token = new token_js_1.mARIOToken(2);
|
|
47
|
-
node_assert_1.strict.throws(() => token.divide(0));
|
|
48
|
-
});
|
|
49
|
-
(0, node_test_1.it)('should round down on multiplication of a number', () => {
|
|
50
|
-
const token = new token_js_1.mARIOToken(1);
|
|
51
|
-
const result = token.multiply(1.5);
|
|
52
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
53
|
-
});
|
|
54
|
-
(0, node_test_1.it)('should round down on division with a number', () => {
|
|
55
|
-
const token = new token_js_1.mARIOToken(2);
|
|
56
|
-
const result = token.divide(3);
|
|
57
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 0);
|
|
58
|
-
});
|
|
59
|
-
(0, node_test_1.it)('should round down on division with another mARIOToken', () => {
|
|
60
|
-
const token = new token_js_1.mARIOToken(2);
|
|
61
|
-
const result = token.divide(new token_js_1.mARIOToken(3));
|
|
62
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 0);
|
|
63
|
-
});
|
|
64
|
-
(0, node_test_1.it)('should add', () => {
|
|
65
|
-
const token = new token_js_1.mARIOToken(1);
|
|
66
|
-
const result = token.plus(new token_js_1.mARIOToken(1));
|
|
67
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
68
|
-
});
|
|
69
|
-
(0, node_test_1.it)('should subtract', () => {
|
|
70
|
-
const token = new token_js_1.mARIOToken(2);
|
|
71
|
-
const result = token.minus(new token_js_1.mARIOToken(1));
|
|
72
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
73
|
-
});
|
|
74
|
-
(0, node_test_1.it)('should convert to ARIO', () => {
|
|
75
|
-
const token = new token_js_1.mARIOToken(1000000);
|
|
76
|
-
const result = token.toARIO();
|
|
77
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
78
|
-
});
|
|
79
|
-
(0, node_test_1.it)('should print as a string', () => {
|
|
80
|
-
const token = new token_js_1.mARIOToken(1);
|
|
81
|
-
node_assert_1.strict.strictEqual(`${token}`, '1');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const ant_js_1 = require("./ant.js");
|
|
6
|
-
(0, node_test_1.describe)('sortANTRecordsByPriority', () => {
|
|
7
|
-
(0, node_test_1.it)('should sort records by priority and then lexicographically', () => {
|
|
8
|
-
const records = {
|
|
9
|
-
undername01: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
|
|
10
|
-
undername1: { priority: 1, transactionId: 'test', ttlSeconds: 1 },
|
|
11
|
-
undername11: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
|
|
12
|
-
undername2: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
|
|
13
|
-
undername3: { priority: 3, transactionId: 'test', ttlSeconds: 1 }, // colliding priorities default to lexicographic sorting
|
|
14
|
-
undername4: { priority: 3, transactionId: 'test', ttlSeconds: 1 },
|
|
15
|
-
undername5: { priority: 100, transactionId: 'test', ttlSeconds: 1 }, // priority does not represent the index or position of the record, just the order of resolution relative to other records
|
|
16
|
-
noPriority: { transactionId: 'test', ttlSeconds: 1 },
|
|
17
|
-
noPriority01: { transactionId: 'test', ttlSeconds: 1 },
|
|
18
|
-
noPriority1: { transactionId: 'test', ttlSeconds: 1 },
|
|
19
|
-
noPriority11: { transactionId: 'test', ttlSeconds: 1 },
|
|
20
|
-
'@': { transactionId: 'test', ttlSeconds: 1 }, // always first, even if no priority
|
|
21
|
-
};
|
|
22
|
-
const sorted = (0, ant_js_1.sortANTRecords)(records);
|
|
23
|
-
node_assert_1.strict.deepStrictEqual(sorted, {
|
|
24
|
-
'@': { transactionId: 'test', ttlSeconds: 1, index: 0 }, // always first, even if no priority
|
|
25
|
-
undername01: {
|
|
26
|
-
priority: 1,
|
|
27
|
-
transactionId: 'test',
|
|
28
|
-
ttlSeconds: 1,
|
|
29
|
-
index: 1,
|
|
30
|
-
},
|
|
31
|
-
undername1: {
|
|
32
|
-
priority: 1,
|
|
33
|
-
transactionId: 'test',
|
|
34
|
-
ttlSeconds: 1,
|
|
35
|
-
index: 2,
|
|
36
|
-
},
|
|
37
|
-
undername11: {
|
|
38
|
-
priority: 1,
|
|
39
|
-
transactionId: 'test',
|
|
40
|
-
ttlSeconds: 1,
|
|
41
|
-
index: 3,
|
|
42
|
-
},
|
|
43
|
-
undername2: {
|
|
44
|
-
priority: 2,
|
|
45
|
-
transactionId: 'test',
|
|
46
|
-
ttlSeconds: 1,
|
|
47
|
-
index: 4,
|
|
48
|
-
},
|
|
49
|
-
undername3: {
|
|
50
|
-
priority: 3,
|
|
51
|
-
transactionId: 'test',
|
|
52
|
-
ttlSeconds: 1,
|
|
53
|
-
index: 5,
|
|
54
|
-
},
|
|
55
|
-
undername4: {
|
|
56
|
-
priority: 3,
|
|
57
|
-
transactionId: 'test',
|
|
58
|
-
ttlSeconds: 1,
|
|
59
|
-
index: 6,
|
|
60
|
-
},
|
|
61
|
-
undername5: {
|
|
62
|
-
priority: 100,
|
|
63
|
-
transactionId: 'test',
|
|
64
|
-
ttlSeconds: 1,
|
|
65
|
-
index: 7,
|
|
66
|
-
},
|
|
67
|
-
noPriority: { transactionId: 'test', ttlSeconds: 1, index: 8 },
|
|
68
|
-
noPriority01: { transactionId: 'test', ttlSeconds: 1, index: 9 },
|
|
69
|
-
noPriority1: { transactionId: 'test', ttlSeconds: 1, index: 10 },
|
|
70
|
-
noPriority11: { transactionId: 'test', ttlSeconds: 1, index: 11 },
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
(0, node_test_1.it)('should always return @ as the first, regardless of priority', () => {
|
|
74
|
-
const scenarios = [
|
|
75
|
-
{
|
|
76
|
-
records: {
|
|
77
|
-
'@': { priority: 5, transactionId: 'test', ttlSeconds: 1 }, // priorities set on '@' are ignored, they are always first
|
|
78
|
-
undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
|
|
79
|
-
},
|
|
80
|
-
expected: {
|
|
81
|
-
'@': { priority: 5, transactionId: 'test', ttlSeconds: 1, index: 0 },
|
|
82
|
-
undername1: {
|
|
83
|
-
priority: 2,
|
|
84
|
-
transactionId: 'test',
|
|
85
|
-
ttlSeconds: 1,
|
|
86
|
-
index: 1,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
records: {
|
|
92
|
-
'@': { transactionId: 'test', ttlSeconds: 1 }, // priority 0 is missing, but '@' is always first
|
|
93
|
-
undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
|
|
94
|
-
},
|
|
95
|
-
expected: {
|
|
96
|
-
'@': { transactionId: 'test', ttlSeconds: 1, index: 0 },
|
|
97
|
-
undername1: {
|
|
98
|
-
priority: 2,
|
|
99
|
-
transactionId: 'test',
|
|
100
|
-
ttlSeconds: 1,
|
|
101
|
-
index: 1,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
for (const scenario of scenarios) {
|
|
107
|
-
const sorted = (0, ant_js_1.sortANTRecords)(scenario.records);
|
|
108
|
-
node_assert_1.strict.deepStrictEqual(sorted, scenario.expected);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const base64_js_1 = require("./base64.js");
|
|
6
|
-
(0, node_test_1.describe)('b64utils', () => {
|
|
7
|
-
(0, node_test_1.it)('should convert various strings to base64url and back', () => {
|
|
8
|
-
const testStrings = [
|
|
9
|
-
'Hello, World!',
|
|
10
|
-
'Test123!@#',
|
|
11
|
-
'Base64URLEncoding',
|
|
12
|
-
'Special_Chars+/',
|
|
13
|
-
'',
|
|
14
|
-
'A',
|
|
15
|
-
'1234567890',
|
|
16
|
-
];
|
|
17
|
-
for (const str of testStrings) {
|
|
18
|
-
const encoded = (0, base64_js_1.toB64Url)(Buffer.from(str));
|
|
19
|
-
const decoded = (0, base64_js_1.fromB64Url)(encoded);
|
|
20
|
-
node_assert_1.strict.deepStrictEqual(decoded, Buffer.from(str), `Failed for string: ${str}`);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
(0, node_test_1.it)('should convert various buffers to base64url and back', () => {
|
|
24
|
-
const testBuffers = [
|
|
25
|
-
Buffer.from('Hello, World!'),
|
|
26
|
-
Buffer.from([0, 1, 2, 3, 4, 5]),
|
|
27
|
-
Buffer.from('Test123!@#'),
|
|
28
|
-
Buffer.from('Base64URLEncoding'),
|
|
29
|
-
Buffer.from('Special_Chars+/'),
|
|
30
|
-
Buffer.alloc(0),
|
|
31
|
-
Buffer.from('A'),
|
|
32
|
-
Buffer.from('1234567890'),
|
|
33
|
-
];
|
|
34
|
-
for (const buf of testBuffers) {
|
|
35
|
-
const encoded = (0, base64_js_1.toB64Url)(buf);
|
|
36
|
-
const decoded = (0, base64_js_1.fromB64Url)(encoded);
|
|
37
|
-
node_assert_1.strict.deepStrictEqual(decoded, buf, `Failed for buffer: ${buf.toString()}`);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
(0, node_test_1.it)('should handle edge cases for base64url conversion', () => {
|
|
41
|
-
const edgeCases = [
|
|
42
|
-
'',
|
|
43
|
-
'A',
|
|
44
|
-
'AA',
|
|
45
|
-
'AAA',
|
|
46
|
-
'====',
|
|
47
|
-
'===',
|
|
48
|
-
'==',
|
|
49
|
-
'=',
|
|
50
|
-
'A===',
|
|
51
|
-
'AA==',
|
|
52
|
-
'AAA=',
|
|
53
|
-
];
|
|
54
|
-
for (const testCase of edgeCases) {
|
|
55
|
-
const encoded = (0, base64_js_1.toB64Url)(Buffer.from(testCase));
|
|
56
|
-
const decoded = Buffer.from((0, base64_js_1.fromB64Url)(encoded)).toString();
|
|
57
|
-
node_assert_1.strict.strictEqual(decoded, testCase, `Failed for edge case: ${testCase}`);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
(0, node_test_1.it)('should generate random text', () => {
|
|
61
|
-
const randomText = (0, base64_js_1.getRandomText)();
|
|
62
|
-
const randomText2 = (0, base64_js_1.getRandomText)();
|
|
63
|
-
node_assert_1.strict.strictEqual(randomText.length, 32);
|
|
64
|
-
node_assert_1.strict.strictEqual(randomText2.length, 32);
|
|
65
|
-
node_assert_1.strict.notStrictEqual(randomText, randomText2);
|
|
66
|
-
const smallRandomText = (0, base64_js_1.getRandomText)(16);
|
|
67
|
-
const smallRandomText2 = (0, base64_js_1.getRandomText)(16);
|
|
68
|
-
node_assert_1.strict.strictEqual(smallRandomText.length, 16);
|
|
69
|
-
node_assert_1.strict.strictEqual(smallRandomText2.length, 16);
|
|
70
|
-
node_assert_1.strict.notStrictEqual(smallRandomText, smallRandomText2);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,24 +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
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
-
const node_test_1 = require("node:test");
|
|
8
|
-
const url_js_1 = require("./url.js");
|
|
9
|
-
(0, node_test_1.test)('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
|
|
10
|
-
const result = (0, url_js_1.urlWithSearchParams)({
|
|
11
|
-
baseUrl: 'https://example.com',
|
|
12
|
-
params: {
|
|
13
|
-
number: 1,
|
|
14
|
-
string: 'string',
|
|
15
|
-
boolean: true,
|
|
16
|
-
empty: '',
|
|
17
|
-
zero: 0,
|
|
18
|
-
false: false,
|
|
19
|
-
null: null,
|
|
20
|
-
undef: undefined,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
node_assert_1.default.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
|
|
24
|
-
});
|