@milaboratories/pl-client 2.5.10 → 2.6.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/dist/core/config.d.ts +9 -5
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/default_client.d.ts +1 -1
- package/dist/core/default_client.d.ts.map +1 -1
- package/dist/core/ll_client.d.ts +1 -1
- package/dist/core/ll_client.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +906 -902
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/client.ts +1 -1
- package/src/core/config.test.ts +14 -4
- package/src/core/config.ts +25 -7
- package/src/core/default_client.ts +4 -2
- package/src/core/ll_client.test.ts +3 -3
- package/src/core/ll_client.ts +5 -6
- package/src/core/ll_transaction.test.ts +4 -4
package/package.json
CHANGED
package/src/core/client.ts
CHANGED
|
@@ -216,7 +216,7 @@ export class PlClient {
|
|
|
216
216
|
|
|
217
217
|
while (true) {
|
|
218
218
|
// opening low-level tx
|
|
219
|
-
const llTx = this.ll.createTx(ops);
|
|
219
|
+
const llTx = this.ll.createTx(writable, ops);
|
|
220
220
|
// wrapping it into high-level tx (this also asynchronously sends initialization message)
|
|
221
221
|
const tx = new PlTransaction(
|
|
222
222
|
llTx,
|
package/src/core/config.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_RO_TX_TIMEOUT, DEFAULT_RW_TX_TIMEOUT, plAddressToConfig } from './config';
|
|
2
2
|
|
|
3
3
|
test('config form url no auth', () => {
|
|
4
4
|
const conf = plAddressToConfig('http://127.0.0.1:6345');
|
|
@@ -16,12 +16,22 @@ test('config form url with auth and special symbols', () => {
|
|
|
16
16
|
const conf = plAddressToConfig('http://user1:password232$@127.0.0.1:6345');
|
|
17
17
|
expect(conf.user).toEqual('user1');
|
|
18
18
|
expect(conf.password).toEqual('password232$');
|
|
19
|
-
expect(conf.
|
|
19
|
+
expect(conf.defaultROTransactionTimeout).toEqual(DEFAULT_RO_TX_TIMEOUT);
|
|
20
|
+
expect(conf.defaultRWTransactionTimeout).toEqual(DEFAULT_RW_TX_TIMEOUT);
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
test('config form url with auth and special symbols and
|
|
23
|
+
test('config form url with auth and special symbols and tx timeout', () => {
|
|
23
24
|
const conf = plAddressToConfig('http://user1:password232$@127.0.0.1:6345/?tx-timeout=11341');
|
|
24
25
|
expect(conf.user).toEqual('user1');
|
|
25
26
|
expect(conf.password).toEqual('password232$');
|
|
26
|
-
expect(conf.
|
|
27
|
+
expect(conf.defaultROTransactionTimeout).toEqual(11341);
|
|
28
|
+
expect(conf.defaultRWTransactionTimeout).toEqual(11341);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('config form url with auth and special symbols and ro tx timeout', () => {
|
|
32
|
+
const conf = plAddressToConfig('http://user1:password232$@127.0.0.1:6345/?ro-tx-timeout=11341');
|
|
33
|
+
expect(conf.user).toEqual('user1');
|
|
34
|
+
expect(conf.password).toEqual('password232$');
|
|
35
|
+
expect(conf.defaultROTransactionTimeout).toEqual(11341);
|
|
36
|
+
expect(conf.defaultRWTransactionTimeout).toEqual(DEFAULT_RW_TX_TIMEOUT);
|
|
27
37
|
});
|
package/src/core/config.ts
CHANGED
|
@@ -16,9 +16,13 @@ export interface PlClientConfig {
|
|
|
16
16
|
|
|
17
17
|
/** Default timeout in milliseconds for unary calls, like ping and login. */
|
|
18
18
|
defaultRequestTimeout: number;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
/** Default timeout in milliseconds for read-write transaction, should be
|
|
21
|
+
* adjusted for long round-trip or low bandwidth connections. */
|
|
22
|
+
defaultRWTransactionTimeout: number;
|
|
23
|
+
/** Default timeout in milliseconds for read-only transaction, should be
|
|
24
|
+
* adjusted for long round-trip or low bandwidth connections. */
|
|
25
|
+
defaultROTransactionTimeout: number;
|
|
22
26
|
|
|
23
27
|
/** Controls what TTL will be requested from the server, when new JWT token
|
|
24
28
|
* is requested. */
|
|
@@ -75,7 +79,8 @@ export interface PlClientConfig {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
export const DEFAULT_REQUEST_TIMEOUT = 5_000;
|
|
78
|
-
export const
|
|
82
|
+
export const DEFAULT_RO_TX_TIMEOUT = 300_000;
|
|
83
|
+
export const DEFAULT_RW_TX_TIMEOUT = 20_000;
|
|
79
84
|
export const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;
|
|
80
85
|
export const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;
|
|
81
86
|
|
|
@@ -91,7 +96,12 @@ export const DEFAULT_RETRY_JITTER = 0.3; // 30%
|
|
|
91
96
|
type PlConfigOverrides = Partial<
|
|
92
97
|
Pick<
|
|
93
98
|
PlClientConfig,
|
|
94
|
-
|
|
99
|
+
| 'ssl'
|
|
100
|
+
| 'defaultRequestTimeout'
|
|
101
|
+
| 'defaultROTransactionTimeout'
|
|
102
|
+
| 'defaultRWTransactionTimeout'
|
|
103
|
+
| 'httpProxy'
|
|
104
|
+
| 'grpcProxy'
|
|
95
105
|
>
|
|
96
106
|
>;
|
|
97
107
|
|
|
@@ -114,7 +124,8 @@ export function plAddressToConfig(
|
|
|
114
124
|
hostAndPort: address,
|
|
115
125
|
ssl: false,
|
|
116
126
|
defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,
|
|
117
|
-
|
|
127
|
+
defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,
|
|
128
|
+
defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,
|
|
118
129
|
authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
|
|
119
130
|
authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
|
|
120
131
|
txDelay: 0,
|
|
@@ -151,7 +162,14 @@ export function plAddressToConfig(
|
|
|
151
162
|
ssl: url.protocol === 'https:' || url.protocol === 'tls:',
|
|
152
163
|
defaultRequestTimeout:
|
|
153
164
|
parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,
|
|
154
|
-
|
|
165
|
+
defaultROTransactionTimeout:
|
|
166
|
+
parseInt(url.searchParams.get('ro-tx-timeout')) ??
|
|
167
|
+
parseInt(url.searchParams.get('tx-timeout')) ??
|
|
168
|
+
DEFAULT_RO_TX_TIMEOUT,
|
|
169
|
+
defaultRWTransactionTimeout:
|
|
170
|
+
parseInt(url.searchParams.get('rw-tx-timeout')) ??
|
|
171
|
+
parseInt(url.searchParams.get('tx-timeout')) ??
|
|
172
|
+
DEFAULT_RW_TX_TIMEOUT,
|
|
155
173
|
authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
|
|
156
174
|
authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
|
|
157
175
|
grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,
|
|
@@ -29,7 +29,8 @@ type FileConfigOverrideFields =
|
|
|
29
29
|
| 'user'
|
|
30
30
|
| 'password'
|
|
31
31
|
| 'alternativeRoot'
|
|
32
|
-
| '
|
|
32
|
+
| 'defaultROTransactionTimeout'
|
|
33
|
+
| 'defaultRWTransactionTimeout'
|
|
33
34
|
| 'defaultRequestTimeout'
|
|
34
35
|
| 'authTTLSeconds'
|
|
35
36
|
| 'authMaxRefreshSeconds';
|
|
@@ -39,7 +40,8 @@ const FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [
|
|
|
39
40
|
'user',
|
|
40
41
|
'password',
|
|
41
42
|
'alternativeRoot',
|
|
42
|
-
'
|
|
43
|
+
'defaultROTransactionTimeout',
|
|
44
|
+
'defaultRWTransactionTimeout',
|
|
43
45
|
'defaultRequestTimeout',
|
|
44
46
|
'authTTLSeconds',
|
|
45
47
|
'authMaxRefreshSeconds'
|
|
@@ -8,7 +8,7 @@ import { UnauthenticatedError } from './errors';
|
|
|
8
8
|
|
|
9
9
|
test('authenticated instance test', async () => {
|
|
10
10
|
const client = await getTestLLClient();
|
|
11
|
-
const tx = client.createTx();
|
|
11
|
+
const tx = client.createTx(true);
|
|
12
12
|
const response = await tx.send(
|
|
13
13
|
{
|
|
14
14
|
oneofKind: 'txOpen',
|
|
@@ -31,7 +31,7 @@ test('unauthenticated status change', async () => {
|
|
|
31
31
|
const client = new LLPlClient(cfg.address);
|
|
32
32
|
expect(client.status).toBe('OK');
|
|
33
33
|
|
|
34
|
-
const tx = client.createTx();
|
|
34
|
+
const tx = client.createTx(true);
|
|
35
35
|
|
|
36
36
|
await expect(async () => {
|
|
37
37
|
await tx.send(
|
|
@@ -67,7 +67,7 @@ test('automatic token update', async () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
for (let i = 0; i < 6; i++) {
|
|
70
|
-
const tx = client.createTx();
|
|
70
|
+
const tx = client.createTx(true);
|
|
71
71
|
const response = await tx.send(
|
|
72
72
|
{
|
|
73
73
|
oneofKind: 'txOpen',
|
package/src/core/ll_client.ts
CHANGED
|
@@ -229,17 +229,16 @@ export class LLPlClient {
|
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
createTx(ops: PlCallOps = {}): LLPlTransaction {
|
|
232
|
+
createTx(rw: boolean, ops: PlCallOps = {}): LLPlTransaction {
|
|
233
233
|
return new LLPlTransaction((abortSignal) => {
|
|
234
234
|
let totalAbortSignal = abortSignal;
|
|
235
235
|
if (ops.abortSignal)
|
|
236
|
-
|
|
237
|
-
// see this https://github.com/microsoft/TypeScript/issues/58026
|
|
238
|
-
// and this https://github.com/microsoft/TypeScript/pull/58211
|
|
239
|
-
totalAbortSignal = (AbortSignal as any).any([totalAbortSignal, ops.abortSignal]);
|
|
236
|
+
totalAbortSignal = AbortSignal.any([totalAbortSignal, ops.abortSignal]);
|
|
240
237
|
return this.grpcPl.tx({
|
|
241
238
|
abort: totalAbortSignal,
|
|
242
|
-
timeout:
|
|
239
|
+
timeout:
|
|
240
|
+
ops.timeout ??
|
|
241
|
+
(rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout)
|
|
243
242
|
});
|
|
244
243
|
});
|
|
245
244
|
}
|
|
@@ -7,7 +7,7 @@ import { Aborted } from '@milaboratories/ts-helpers';
|
|
|
7
7
|
|
|
8
8
|
test('transaction timeout test', async () => {
|
|
9
9
|
const client = await getTestLLClient();
|
|
10
|
-
const tx = client.createTx({ timeout: 500 });
|
|
10
|
+
const tx = client.createTx(true, { timeout: 500 });
|
|
11
11
|
|
|
12
12
|
await expect(async () => {
|
|
13
13
|
const response = await tx.send(
|
|
@@ -24,7 +24,7 @@ test('transaction timeout test', async () => {
|
|
|
24
24
|
|
|
25
25
|
test('check timeout error type (passive)', async () => {
|
|
26
26
|
const client = await getTestLLClient();
|
|
27
|
-
const tx = client.createTx({ timeout: 500 });
|
|
27
|
+
const tx = client.createTx(true, { timeout: 500 });
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
30
|
const response = await tx.send(
|
|
@@ -43,7 +43,7 @@ test('check timeout error type (passive)', async () => {
|
|
|
43
43
|
|
|
44
44
|
test('check timeout error type (active)', async () => {
|
|
45
45
|
const client = await getTestLLClient();
|
|
46
|
-
const tx = client.createTx({ timeout: 500 });
|
|
46
|
+
const tx = client.createTx(true, { timeout: 500 });
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
49
|
const openResponse = await tx.send(
|
|
@@ -98,7 +98,7 @@ test('check timeout error type (active)', async () => {
|
|
|
98
98
|
|
|
99
99
|
test('check is abort error (active)', async () => {
|
|
100
100
|
const client = await getTestLLClient();
|
|
101
|
-
const tx = client.createTx({ abortSignal: AbortSignal.timeout(100) });
|
|
101
|
+
const tx = client.createTx(true, { abortSignal: AbortSignal.timeout(100) });
|
|
102
102
|
|
|
103
103
|
try {
|
|
104
104
|
const openResponse = await tx.send(
|