@milaboratories/pl-client 2.16.26 → 2.16.28

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.
Files changed (212) hide show
  1. package/README.md +2 -1
  2. package/dist/core/PromiseTracker.cjs +1 -3
  3. package/dist/core/PromiseTracker.cjs.map +1 -1
  4. package/dist/core/PromiseTracker.d.ts.map +1 -1
  5. package/dist/core/PromiseTracker.js +1 -3
  6. package/dist/core/PromiseTracker.js.map +1 -1
  7. package/dist/core/StatefulPromise.cjs +4 -4
  8. package/dist/core/StatefulPromise.cjs.map +1 -1
  9. package/dist/core/StatefulPromise.d.ts +1 -1
  10. package/dist/core/StatefulPromise.d.ts.map +1 -1
  11. package/dist/core/StatefulPromise.js +4 -4
  12. package/dist/core/StatefulPromise.js.map +1 -1
  13. package/dist/core/advisory_locks.cjs +1 -1
  14. package/dist/core/advisory_locks.cjs.map +1 -1
  15. package/dist/core/advisory_locks.js +1 -1
  16. package/dist/core/advisory_locks.js.map +1 -1
  17. package/dist/core/auth.cjs.map +1 -1
  18. package/dist/core/auth.d.ts +1 -1
  19. package/dist/core/auth.js.map +1 -1
  20. package/dist/core/cache.d.ts +1 -1
  21. package/dist/core/client.cjs +14 -14
  22. package/dist/core/client.cjs.map +1 -1
  23. package/dist/core/client.d.ts +11 -11
  24. package/dist/core/client.d.ts.map +1 -1
  25. package/dist/core/client.js +14 -14
  26. package/dist/core/client.js.map +1 -1
  27. package/dist/core/config.cjs +39 -39
  28. package/dist/core/config.cjs.map +1 -1
  29. package/dist/core/config.d.ts +5 -5
  30. package/dist/core/config.js +39 -39
  31. package/dist/core/config.js.map +1 -1
  32. package/dist/core/default_client.cjs +23 -23
  33. package/dist/core/default_client.cjs.map +1 -1
  34. package/dist/core/default_client.d.ts +3 -3
  35. package/dist/core/default_client.js +23 -23
  36. package/dist/core/default_client.js.map +1 -1
  37. package/dist/core/driver.cjs +1 -1
  38. package/dist/core/driver.cjs.map +1 -1
  39. package/dist/core/driver.d.ts +5 -5
  40. package/dist/core/driver.js +1 -1
  41. package/dist/core/driver.js.map +1 -1
  42. package/dist/core/error_resource.cjs +2 -2
  43. package/dist/core/error_resource.cjs.map +1 -1
  44. package/dist/core/error_resource.d.ts +1 -1
  45. package/dist/core/error_resource.js +2 -2
  46. package/dist/core/error_resource.js.map +1 -1
  47. package/dist/core/errors.cjs +24 -24
  48. package/dist/core/errors.cjs.map +1 -1
  49. package/dist/core/errors.d.ts +1 -1
  50. package/dist/core/errors.d.ts.map +1 -1
  51. package/dist/core/errors.js +24 -24
  52. package/dist/core/errors.js.map +1 -1
  53. package/dist/core/final.cjs +43 -43
  54. package/dist/core/final.cjs.map +1 -1
  55. package/dist/core/final.d.ts +3 -3
  56. package/dist/core/final.d.ts.map +1 -1
  57. package/dist/core/final.js +43 -43
  58. package/dist/core/final.js.map +1 -1
  59. package/dist/core/ll_client.cjs +50 -43
  60. package/dist/core/ll_client.cjs.map +1 -1
  61. package/dist/core/ll_client.d.ts +9 -9
  62. package/dist/core/ll_client.d.ts.map +1 -1
  63. package/dist/core/ll_client.js +50 -43
  64. package/dist/core/ll_client.js.map +1 -1
  65. package/dist/core/ll_transaction.cjs +9 -9
  66. package/dist/core/ll_transaction.cjs.map +1 -1
  67. package/dist/core/ll_transaction.d.ts +7 -7
  68. package/dist/core/ll_transaction.d.ts.map +1 -1
  69. package/dist/core/ll_transaction.js +9 -9
  70. package/dist/core/ll_transaction.js.map +1 -1
  71. package/dist/core/stat.cjs.map +1 -1
  72. package/dist/core/stat.d.ts +1 -1
  73. package/dist/core/stat.js.map +1 -1
  74. package/dist/core/transaction.cjs +46 -46
  75. package/dist/core/transaction.cjs.map +1 -1
  76. package/dist/core/transaction.d.ts +7 -7
  77. package/dist/core/transaction.d.ts.map +1 -1
  78. package/dist/core/transaction.js +46 -46
  79. package/dist/core/transaction.js.map +1 -1
  80. package/dist/core/type_conversion.cjs +22 -22
  81. package/dist/core/type_conversion.cjs.map +1 -1
  82. package/dist/core/type_conversion.d.ts +3 -3
  83. package/dist/core/type_conversion.d.ts.map +1 -1
  84. package/dist/core/type_conversion.js +22 -22
  85. package/dist/core/type_conversion.js.map +1 -1
  86. package/dist/core/types.cjs +25 -25
  87. package/dist/core/types.cjs.map +1 -1
  88. package/dist/core/types.d.ts +7 -7
  89. package/dist/core/types.js +25 -25
  90. package/dist/core/types.js.map +1 -1
  91. package/dist/core/unauth_client.cjs +6 -4
  92. package/dist/core/unauth_client.cjs.map +1 -1
  93. package/dist/core/unauth_client.d.ts +4 -4
  94. package/dist/core/unauth_client.d.ts.map +1 -1
  95. package/dist/core/unauth_client.js +6 -4
  96. package/dist/core/unauth_client.js.map +1 -1
  97. package/dist/core/websocket_stream.cjs +22 -20
  98. package/dist/core/websocket_stream.cjs.map +1 -1
  99. package/dist/core/websocket_stream.d.ts +3 -3
  100. package/dist/core/websocket_stream.d.ts.map +1 -1
  101. package/dist/core/websocket_stream.js +22 -20
  102. package/dist/core/websocket_stream.js.map +1 -1
  103. package/dist/core/wire.d.ts +6 -6
  104. package/dist/core/wire.d.ts.map +1 -1
  105. package/dist/helpers/pl.cjs +19 -19
  106. package/dist/helpers/pl.cjs.map +1 -1
  107. package/dist/helpers/pl.d.ts +2 -2
  108. package/dist/helpers/pl.js +19 -19
  109. package/dist/helpers/pl.js.map +1 -1
  110. package/dist/helpers/poll.cjs +6 -6
  111. package/dist/helpers/poll.cjs.map +1 -1
  112. package/dist/helpers/poll.d.ts +4 -4
  113. package/dist/helpers/poll.d.ts.map +1 -1
  114. package/dist/helpers/poll.js +6 -6
  115. package/dist/helpers/poll.js.map +1 -1
  116. package/dist/helpers/retry_strategy.cjs +1 -1
  117. package/dist/helpers/retry_strategy.cjs.map +1 -1
  118. package/dist/helpers/retry_strategy.d.ts.map +1 -1
  119. package/dist/helpers/retry_strategy.js +1 -1
  120. package/dist/helpers/retry_strategy.js.map +1 -1
  121. package/dist/helpers/state_helpers.d.ts +2 -2
  122. package/dist/helpers/tx_helpers.cjs +2 -2
  123. package/dist/helpers/tx_helpers.cjs.map +1 -1
  124. package/dist/helpers/tx_helpers.d.ts +2 -2
  125. package/dist/helpers/tx_helpers.d.ts.map +1 -1
  126. package/dist/helpers/tx_helpers.js +2 -2
  127. package/dist/helpers/tx_helpers.js.map +1 -1
  128. package/dist/index.d.ts +16 -16
  129. package/dist/proto-grpc/google/protobuf/struct.d.ts +1 -1
  130. package/dist/proto-grpc/google/protobuf/struct.d.ts.map +1 -1
  131. package/dist/proto-rest/index.cjs +4 -5
  132. package/dist/proto-rest/index.cjs.map +1 -1
  133. package/dist/proto-rest/index.d.ts +4 -4
  134. package/dist/proto-rest/index.d.ts.map +1 -1
  135. package/dist/proto-rest/index.js +4 -5
  136. package/dist/proto-rest/index.js.map +1 -1
  137. package/dist/proto-rest/plapi.d.ts.map +1 -1
  138. package/dist/test/tcp-proxy.cjs +11 -10
  139. package/dist/test/tcp-proxy.cjs.map +1 -1
  140. package/dist/test/tcp-proxy.d.ts +1 -1
  141. package/dist/test/tcp-proxy.d.ts.map +1 -1
  142. package/dist/test/tcp-proxy.js +11 -10
  143. package/dist/test/tcp-proxy.js.map +1 -1
  144. package/dist/test/test_config.cjs +21 -17
  145. package/dist/test/test_config.cjs.map +1 -1
  146. package/dist/test/test_config.d.ts +6 -6
  147. package/dist/test/test_config.d.ts.map +1 -1
  148. package/dist/test/test_config.js +21 -17
  149. package/dist/test/test_config.js.map +1 -1
  150. package/dist/util/pl.cjs +1 -1
  151. package/dist/util/pl.cjs.map +1 -1
  152. package/dist/util/pl.js +1 -1
  153. package/dist/util/pl.js.map +1 -1
  154. package/dist/util/util.cjs +1 -1
  155. package/dist/util/util.cjs.map +1 -1
  156. package/dist/util/util.js +1 -1
  157. package/dist/util/util.js.map +1 -1
  158. package/package.json +23 -23
  159. package/src/core/PromiseTracker.ts +3 -4
  160. package/src/core/StatefulPromise.ts +17 -8
  161. package/src/core/abstract_stream.ts +3 -4
  162. package/src/core/advisory_locks.ts +1 -1
  163. package/src/core/auth.ts +2 -2
  164. package/src/core/cache.ts +1 -1
  165. package/src/core/client.test.ts +25 -21
  166. package/src/core/client.ts +54 -45
  167. package/src/core/config.test.ts +44 -44
  168. package/src/core/config.ts +49 -49
  169. package/src/core/connectivity.test.ts +69 -63
  170. package/src/core/default_client.ts +46 -46
  171. package/src/core/driver.ts +6 -6
  172. package/src/core/error.test.ts +5 -5
  173. package/src/core/error_resource.ts +3 -3
  174. package/src/core/errors.ts +39 -31
  175. package/src/core/final.ts +48 -55
  176. package/src/core/ll_client.test.ts +53 -36
  177. package/src/core/ll_client.ts +125 -81
  178. package/src/core/ll_transaction.test.ts +75 -49
  179. package/src/core/ll_transaction.ts +37 -35
  180. package/src/core/stat.ts +1 -1
  181. package/src/core/transaction.test.ts +65 -65
  182. package/src/core/transaction.ts +91 -84
  183. package/src/core/type_conversion.ts +30 -31
  184. package/src/core/types.test.ts +6 -6
  185. package/src/core/types.ts +35 -35
  186. package/src/core/unauth_client.test.ts +18 -14
  187. package/src/core/unauth_client.ts +14 -12
  188. package/src/core/websocket_stream.test.ts +52 -52
  189. package/src/core/websocket_stream.ts +41 -37
  190. package/src/core/wire.ts +10 -8
  191. package/src/helpers/pl.ts +22 -22
  192. package/src/helpers/poll.ts +13 -27
  193. package/src/helpers/retry_strategy.ts +2 -4
  194. package/src/helpers/rich_resource_types.test.ts +2 -2
  195. package/src/helpers/state_helpers.ts +3 -3
  196. package/src/helpers/tx_helpers.ts +9 -7
  197. package/src/index.ts +16 -16
  198. package/src/proto-grpc/google/protobuf/struct.ts +1 -1
  199. package/src/proto-rest/index.ts +17 -18
  200. package/src/proto-rest/plapi.ts +1472 -1472
  201. package/src/test/tcp-proxy.ts +55 -54
  202. package/src/test/test_config.test.ts +3 -3
  203. package/src/test/test_config.ts +51 -46
  204. package/src/util/pl.ts +1 -1
  205. package/src/util/util.test.ts +5 -5
  206. package/src/util/util.ts +1 -1
  207. package/dist/helpers/rich_resource_types.d.ts +0 -2
  208. package/dist/helpers/rich_resource_types.d.ts.map +0 -1
  209. package/dist/helpers/smart_accessors.d.ts +0 -2
  210. package/dist/helpers/smart_accessors.d.ts.map +0 -1
  211. package/src/helpers/rich_resource_types.ts +0 -84
  212. package/src/helpers/smart_accessors.ts +0 -146
@@ -1,37 +1,45 @@
1
- import { PlatformClient as GrpcPlApiClient } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client';
2
- import type { ClientOptions, Interceptor } from '@grpc/grpc-js';
1
+ import { PlatformClient as GrpcPlApiClient } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client";
2
+ import type { ClientOptions, Interceptor } from "@grpc/grpc-js";
3
3
  import {
4
4
  ChannelCredentials,
5
5
  InterceptingCall,
6
6
  status as GrpcStatus,
7
7
  compressionAlgorithms,
8
- } from '@grpc/grpc-js';
8
+ } from "@grpc/grpc-js";
9
9
  import type {
10
10
  AuthInformation,
11
11
  AuthOps,
12
12
  PlClientConfig,
13
13
  PlConnectionStatus,
14
14
  PlConnectionStatusListener,
15
- } from './config';
16
- import { plAddressToConfig, type wireProtocol, SUPPORTED_WIRE_PROTOCOLS } from './config';
17
- import type { GrpcOptions } from '@protobuf-ts/grpc-transport';
18
- import { GrpcTransport } from '@protobuf-ts/grpc-transport';
19
- import { LLPlTransaction } from './ll_transaction';
20
- import { parsePlJwt } from '../util/pl';
21
- import { type Dispatcher, interceptors } from 'undici';
22
- import type { Middleware } from 'openapi-fetch';
23
- import { inferAuthRefreshTime } from './auth';
24
- import { defaultHttpDispatcher } from '@milaboratories/pl-http';
25
- import type { WireClientProvider, WireClientProviderFactory, WireConnection } from './wire';
26
- import { parseHttpAuth } from '@milaboratories/pl-model-common';
27
- import type * as grpcTypes from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
28
- import { type PlApiPaths, type PlRestClientType, createClient, parseResponseError } from '../proto-rest';
29
- import { notEmpty, retry, withTimeout, type RetryOptions } from '@milaboratories/ts-helpers';
30
- import { Code } from '../proto-grpc/google/rpc/code';
31
- import { WebSocketBiDiStream } from './websocket_stream';
32
- import { TxAPI_ClientMessage, TxAPI_ServerMessage } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
33
- import type { MiLogger } from '@milaboratories/ts-helpers';
34
- import { isAbortedError } from './errors';
15
+ } from "./config";
16
+ import { plAddressToConfig, type wireProtocol, SUPPORTED_WIRE_PROTOCOLS } from "./config";
17
+ import type { GrpcOptions } from "@protobuf-ts/grpc-transport";
18
+ import { GrpcTransport } from "@protobuf-ts/grpc-transport";
19
+ import { LLPlTransaction } from "./ll_transaction";
20
+ import { parsePlJwt } from "../util/pl";
21
+ import { type Dispatcher, interceptors } from "undici";
22
+ import type { Middleware } from "openapi-fetch";
23
+ import { inferAuthRefreshTime } from "./auth";
24
+ import { defaultHttpDispatcher } from "@milaboratories/pl-http";
25
+ import type { WireClientProvider, WireClientProviderFactory, WireConnection } from "./wire";
26
+ import { parseHttpAuth } from "@milaboratories/pl-model-common";
27
+ import type * as grpcTypes from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api";
28
+ import {
29
+ type PlApiPaths,
30
+ type PlRestClientType,
31
+ createClient,
32
+ parseResponseError,
33
+ } from "../proto-rest";
34
+ import { notEmpty, retry, withTimeout, type RetryOptions } from "@milaboratories/ts-helpers";
35
+ import { Code } from "../proto-grpc/google/rpc/code";
36
+ import { WebSocketBiDiStream } from "./websocket_stream";
37
+ import {
38
+ TxAPI_ClientMessage,
39
+ TxAPI_ServerMessage,
40
+ } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api";
41
+ import type { MiLogger } from "@milaboratories/ts-helpers";
42
+ import { isAbortedError } from "./errors";
35
43
 
36
44
  export interface PlCallOps {
37
45
  timeout?: number;
@@ -41,15 +49,17 @@ export interface PlCallOps {
41
49
  class WireClientProviderImpl<Client> implements WireClientProvider<Client> {
42
50
  private client: Client | undefined = undefined;
43
51
 
44
- constructor(private readonly wireOpts: () => WireConnection, private readonly clientConstructor: (wireOpts: WireConnection) => Client) {}
52
+ constructor(
53
+ private readonly wireOpts: () => WireConnection,
54
+ private readonly clientConstructor: (wireOpts: WireConnection) => Client,
55
+ ) {}
45
56
 
46
57
  public reset(): void {
47
58
  this.client = undefined;
48
59
  }
49
60
 
50
61
  public get(): Client {
51
- if (this.client === undefined)
52
- this.client = this.clientConstructor(this.wireOpts());
62
+ if (this.client === undefined) this.client = this.clientConstructor(this.wireOpts());
53
63
  return this.client;
54
64
  }
55
65
  }
@@ -67,10 +77,10 @@ export class LLPlClient implements WireClientProviderFactory {
67
77
  /** Threshold after which auth info refresh is required */
68
78
  private refreshTimestamp?: number;
69
79
 
70
- private _status: PlConnectionStatus = 'OK';
80
+ private _status: PlConnectionStatus = "OK";
71
81
  private readonly statusListener?: PlConnectionStatusListener;
72
82
 
73
- private _wireProto: wireProtocol = 'grpc';
83
+ private _wireProto: wireProtocol = "grpc";
74
84
  private _wireConn!: WireConnection;
75
85
 
76
86
  private readonly _restInterceptors: Dispatcher.DispatcherComposeInterceptor[];
@@ -92,7 +102,8 @@ export class LLPlClient implements WireClientProviderFactory {
92
102
  useAutoDetectWireProtocol?: boolean;
93
103
  } = {},
94
104
  ) {
95
- const conf = typeof configOrAddress === 'string' ? plAddressToConfig(configOrAddress) : configOrAddress;
105
+ const conf =
106
+ typeof configOrAddress === "string" ? plAddressToConfig(configOrAddress) : configOrAddress;
96
107
 
97
108
  const pl = new LLPlClient(conf, ops);
98
109
 
@@ -150,7 +161,7 @@ export class LLPlClient implements WireClientProviderFactory {
150
161
  }
151
162
 
152
163
  this.clientProvider = this.createWireClientProvider((wireConn) => {
153
- if (wireConn.type === 'grpc') {
164
+ if (wireConn.type === "grpc") {
154
165
  return new GrpcPlApiClient(wireConn.Transport);
155
166
  } else {
156
167
  return createClient<PlApiPaths>({
@@ -165,22 +176,29 @@ export class LLPlClient implements WireClientProviderFactory {
165
176
 
166
177
  private initWireConnection(protocol: wireProtocol) {
167
178
  switch (protocol) {
168
- case 'rest':
179
+ case "rest":
169
180
  this.initRestConnection();
170
181
  return;
171
- case 'grpc':
182
+ case "grpc":
172
183
  this.initGrpcConnection(this.ops.shouldUseGzip ?? false);
173
184
  return;
174
185
  default:
175
186
  ((v: never) => {
176
- throw new Error(`Unsupported wire protocol '${v as string}'. Use one of: ${SUPPORTED_WIRE_PROTOCOLS.join(', ')}`);
187
+ throw new Error(
188
+ `Unsupported wire protocol '${v as string}'. Use one of: ${SUPPORTED_WIRE_PROTOCOLS.join(", ")}`,
189
+ );
177
190
  })(protocol);
178
191
  }
179
192
  }
180
193
 
181
194
  private initRestConnection(): void {
182
195
  const dispatcher = defaultHttpDispatcher(this.conf.grpcProxy, this._restInterceptors);
183
- this._replaceWireConnection({ type: 'rest', Config: this.conf, Dispatcher: dispatcher, Middlewares: this._restMiddlewares });
196
+ this._replaceWireConnection({
197
+ type: "rest",
198
+ Config: this.conf,
199
+ Dispatcher: dispatcher,
200
+ Middlewares: this._restMiddlewares,
201
+ });
184
202
  }
185
203
 
186
204
  /**
@@ -189,12 +207,12 @@ export class LLPlClient implements WireClientProviderFactory {
189
207
  */
190
208
  private initGrpcConnection(gzip: boolean) {
191
209
  const clientOptions: ClientOptions = {
192
- 'grpc.keepalive_time_ms': 30_000, // 30 seconds
193
- 'grpc.service_config_disable_resolution': 1, // Disable DNS TXT lookups for service config
194
- 'interceptors': this._grpcInterceptors,
210
+ "grpc.keepalive_time_ms": 30_000, // 30 seconds
211
+ "grpc.service_config_disable_resolution": 1, // Disable DNS TXT lookups for service config
212
+ interceptors: this._grpcInterceptors,
195
213
  };
196
214
 
197
- if (gzip) clientOptions['grpc.default_compression_algorithm'] = compressionAlgorithms.gzip;
215
+ if (gzip) clientOptions["grpc.default_compression_algorithm"] = compressionAlgorithms.gzip;
198
216
 
199
217
  //
200
218
  // Leaving it here for now
@@ -212,15 +230,14 @@ export class LLPlClient implements WireClientProviderFactory {
212
230
  clientOptions,
213
231
  };
214
232
 
215
- const grpcProxy = typeof this.conf.grpcProxy === 'string'
216
- ? { url: this.conf.grpcProxy }
217
- : this.conf.grpcProxy;
233
+ const grpcProxy =
234
+ typeof this.conf.grpcProxy === "string" ? { url: this.conf.grpcProxy } : this.conf.grpcProxy;
218
235
 
219
236
  if (grpcProxy?.url) {
220
237
  const url = new URL(grpcProxy.url);
221
238
  if (grpcProxy.auth) {
222
239
  const parsed = parseHttpAuth(grpcProxy.auth);
223
- if (parsed.scheme !== 'Basic') {
240
+ if (parsed.scheme !== "Basic") {
224
241
  throw new Error(`Unsupported auth scheme: ${parsed.scheme as string}.`);
225
242
  }
226
243
  url.username = parsed.username;
@@ -231,7 +248,7 @@ export class LLPlClient implements WireClientProviderFactory {
231
248
  delete process.env.grpc_proxy;
232
249
  }
233
250
 
234
- this._replaceWireConnection({ type: 'grpc', Transport: new GrpcTransport(grpcOptions) });
251
+ this._replaceWireConnection({ type: "grpc", Transport: new GrpcTransport(grpcOptions) });
235
252
  }
236
253
 
237
254
  private _replaceWireConnection(newConn: WireConnection): void {
@@ -251,7 +268,7 @@ export class LLPlClient implements WireClientProviderFactory {
251
268
  }
252
269
  }
253
270
 
254
- if (oldConn !== undefined && oldConn.type === 'grpc') oldConn.Transport.close();
271
+ if (oldConn !== undefined && oldConn.type === "grpc") oldConn.Transport.close();
255
272
  }
256
273
 
257
274
  private providerCleanupCounter = 0;
@@ -261,7 +278,9 @@ export class LLPlClient implements WireClientProviderFactory {
261
278
  *
262
279
  * @param clientConstructor - a factory function that creates a grpc client
263
280
  */
264
- public createWireClientProvider<Client>(clientConstructor: (transport: WireConnection) => Client): WireClientProvider<Client> {
281
+ public createWireClientProvider<Client>(
282
+ clientConstructor: (transport: WireConnection) => Client,
283
+ ): WireClientProvider<Client> {
265
284
  // We need to cleanup providers periodically to avoid memory leaks.
266
285
  // This is a simple heuristic to avoid memory leaks.
267
286
  // We could use a more sophisticated algorithm, but this is good enough for now.
@@ -299,7 +318,7 @@ export class LLPlClient implements WireClientProviderFactory {
299
318
 
300
319
  /** null means anonymous connection */
301
320
  public get authUser(): string | null {
302
- if (!this.authenticated) throw new Error('Client is not authenticated');
321
+ if (!this.authenticated) throw new Error("Client is not authenticated");
303
322
  if (this.authInformation?.jwtToken)
304
323
  return parsePlJwt(this.authInformation?.jwtToken).user.login;
305
324
  else return null;
@@ -323,10 +342,10 @@ export class LLPlClient implements WireClientProviderFactory {
323
342
 
324
343
  private refreshAuthInformationIfNeeded(): void {
325
344
  if (
326
- this.refreshTimestamp === undefined
327
- || Date.now() < this.refreshTimestamp
328
- || this.authRefreshInProgress
329
- || this._status === 'Unauthenticated'
345
+ this.refreshTimestamp === undefined ||
346
+ Date.now() < this.refreshTimestamp ||
347
+ this.authRefreshInProgress ||
348
+ this._status === "Unauthenticated"
330
349
  )
331
350
  return;
332
351
 
@@ -357,11 +376,11 @@ export class LLPlClient implements WireClientProviderFactory {
357
376
  private createRestErrorMiddleware(): Middleware {
358
377
  return {
359
378
  onResponse: async ({ request: _request, response, options: _options }) => {
360
- const { body: body, ...resOptions } = response;
379
+ const { body, ...resOptions } = response;
361
380
 
362
381
  if ([502, 503, 504].includes(response.status)) {
363
382
  // Service unavailable, bad gateway, gateway timeout
364
- this.updateStatus('Disconnected');
383
+ this.updateStatus("Disconnected");
365
384
  return new Response(body, { ...resOptions, status: response.status });
366
385
  }
367
386
 
@@ -371,13 +390,13 @@ export class LLPlClient implements WireClientProviderFactory {
371
390
  return new Response(respErr.origBody ?? body, { ...resOptions, status: response.status });
372
391
  }
373
392
 
374
- if (typeof respErr.error === 'string') {
393
+ if (typeof respErr.error === "string") {
375
394
  // Non-standard error or normal response: let later middleware to deal wit it.
376
395
  return new Response(respErr.error, { ...resOptions, status: response.status });
377
396
  }
378
397
 
379
398
  if (respErr.error.code === Code.UNAUTHENTICATED) {
380
- this.updateStatus('Unauthenticated');
399
+ this.updateStatus("Unauthenticated");
381
400
  }
382
401
 
383
402
  // Let later middleware to deal with standard gRPC error.
@@ -395,10 +414,10 @@ export class LLPlClient implements WireClientProviderFactory {
395
414
  onReceiveStatus: (status, next) => {
396
415
  if (status.code == GrpcStatus.UNAUTHENTICATED)
397
416
  // (!!!) don't change to "==="
398
- this.updateStatus('Unauthenticated');
417
+ this.updateStatus("Unauthenticated");
399
418
  if (status.code == GrpcStatus.UNAVAILABLE)
400
419
  // (!!!) don't change to "==="
401
- this.updateStatus('Disconnected');
420
+ this.updateStatus("Disconnected");
402
421
  next(status);
403
422
  },
404
423
  });
@@ -412,7 +431,10 @@ export class LLPlClient implements WireClientProviderFactory {
412
431
  return (options, handler) => {
413
432
  if (this.authInformation?.jwtToken !== undefined) {
414
433
  // TODO: check this magic really works and gets called
415
- options.headers = { ...options.headers, authorization: 'Bearer ' + this.authInformation.jwtToken };
434
+ options.headers = {
435
+ ...options.headers,
436
+ authorization: "Bearer " + this.authInformation.jwtToken,
437
+ };
416
438
  this.refreshAuthInformationIfNeeded();
417
439
  }
418
440
 
@@ -427,7 +449,7 @@ export class LLPlClient implements WireClientProviderFactory {
427
449
  return new InterceptingCall(nextCall(options), {
428
450
  start: (metadata, listener, next) => {
429
451
  if (this.authInformation?.jwtToken !== undefined) {
430
- metadata.set('authorization', 'Bearer ' + this.authInformation.jwtToken);
452
+ metadata.set("authorization", "Bearer " + this.authInformation.jwtToken);
431
453
  this.refreshAuthInformationIfNeeded();
432
454
  next(metadata, listener);
433
455
  } else {
@@ -438,21 +460,26 @@ export class LLPlClient implements WireClientProviderFactory {
438
460
  };
439
461
  }
440
462
 
441
- public async getJwtToken(ttlSeconds: bigint, options?: { authorization?: string }): Promise<string> {
463
+ public async getJwtToken(
464
+ ttlSeconds: bigint,
465
+ options?: { authorization?: string },
466
+ ): Promise<string> {
442
467
  const cl = this.clientProvider.get();
443
468
 
444
469
  if (cl instanceof GrpcPlApiClient) {
445
470
  const meta: Record<string, string> = {};
446
471
  if (options?.authorization) meta.authorization = options.authorization;
447
- return (await cl.getJWTToken({ expiration: { seconds: ttlSeconds, nanos: 0 } }, { meta }).response).token;
472
+ return (
473
+ await cl.getJWTToken({ expiration: { seconds: ttlSeconds, nanos: 0 } }, { meta }).response
474
+ ).token;
448
475
  } else {
449
476
  const headers: Record<string, string> = {};
450
477
  if (options?.authorization) headers.authorization = options.authorization;
451
- const resp = cl.POST('/v1/auth/jwt-token', {
478
+ const resp = cl.POST("/v1/auth/jwt-token", {
452
479
  body: { expiration: `${ttlSeconds}s` },
453
480
  headers,
454
481
  });
455
- return notEmpty((await resp).data, 'REST: empty response for JWT token request').token;
482
+ return notEmpty((await resp).data, "REST: empty response for JWT token request").token;
456
483
  }
457
484
  }
458
485
 
@@ -461,7 +488,7 @@ export class LLPlClient implements WireClientProviderFactory {
461
488
  if (cl instanceof GrpcPlApiClient) {
462
489
  return (await cl.ping({})).response;
463
490
  } else {
464
- return notEmpty((await cl.GET('/v1/ping')).data, 'REST: empty response for ping request');
491
+ return notEmpty((await cl.GET("/v1/ping")).data, "REST: empty response for ping request");
465
492
  }
466
493
  }
467
494
 
@@ -485,7 +512,7 @@ export class LLPlClient implements WireClientProviderFactory {
485
512
  const pingTimeoutFactor = 1.3;
486
513
  const maxPingTimeoutMs = 3_000;
487
514
  const retryOptions: RetryOptions = {
488
- type: 'exponentialBackoff',
515
+ type: "exponentialBackoff",
489
516
  maxAttempts: 30,
490
517
  initialDelay: 30,
491
518
  backoffMultiplier: 1.3,
@@ -500,7 +527,9 @@ export class LLPlClient implements WireClientProviderFactory {
500
527
  retryOptions,
501
528
  (e: unknown) => {
502
529
  if (isAbortedError(e)) {
503
- this.ops.logger?.info(`Wire proto autodetect: ping timed out after ${pingTimeoutMs}ms: attempt=${attempt}, wire=${this._wireProto}`);
530
+ this.ops.logger?.info(
531
+ `Wire proto autodetect: ping timed out after ${pingTimeoutMs}ms: attempt=${attempt}, wire=${this._wireProto}`,
532
+ );
504
533
 
505
534
  if (attempt % 2 === 0) {
506
535
  // We have 2 wire protocols to check. Increase timeout each 2 attempts.
@@ -510,15 +539,20 @@ export class LLPlClient implements WireClientProviderFactory {
510
539
  );
511
540
  }
512
541
  } else {
513
- this.ops.logger?.info(`Wire proto autodetect: ping failed: attempt=${attempt}, wire=${this._wireProto}, err=${String(e)}`);
542
+ this.ops.logger?.info(
543
+ `Wire proto autodetect: ping failed: attempt=${attempt}, wire=${this._wireProto}, err=${String(e)}`,
544
+ );
514
545
  }
515
546
 
516
547
  attempt++;
517
- const protocol = this._wireProto === 'grpc' ? 'rest' : 'grpc';
518
- this.ops.logger?.info(`Wire protocol autodetect next attempt: will try wire '${protocol}' with timeout ${pingTimeoutMs}ms`);
548
+ const protocol = this._wireProto === "grpc" ? "rest" : "grpc";
549
+ this.ops.logger?.info(
550
+ `Wire protocol autodetect next attempt: will try wire '${protocol}' with timeout ${pingTimeoutMs}ms`,
551
+ );
519
552
  this.initWireConnection(protocol);
520
553
  return true;
521
- });
554
+ },
555
+ );
522
556
  }
523
557
 
524
558
  public async license(): Promise<grpcTypes.MaintenanceAPI_License_Response> {
@@ -526,7 +560,10 @@ export class LLPlClient implements WireClientProviderFactory {
526
560
  if (cl instanceof GrpcPlApiClient) {
527
561
  return (await cl.license({})).response;
528
562
  } else {
529
- const resp = notEmpty((await cl.GET('/v1/license')).data, 'REST: empty response for license request');
563
+ const resp = notEmpty(
564
+ (await cl.GET("/v1/license")).data,
565
+ "REST: empty response for license request",
566
+ );
530
567
  return {
531
568
  status: resp.status,
532
569
  isOk: resp.isOk,
@@ -540,7 +577,10 @@ export class LLPlClient implements WireClientProviderFactory {
540
577
  if (cl instanceof GrpcPlApiClient) {
541
578
  return (await cl.authMethods({})).response;
542
579
  } else {
543
- return notEmpty((await cl.GET('/v1/auth/methods')).data, 'REST: empty response for auth methods request');
580
+ return notEmpty(
581
+ (await cl.GET("/v1/auth/methods")).data,
582
+ "REST: empty response for auth methods request",
583
+ );
544
584
  }
545
585
  }
546
586
 
@@ -549,7 +589,7 @@ export class LLPlClient implements WireClientProviderFactory {
549
589
  if (cl instanceof GrpcPlApiClient) {
550
590
  await cl.txSync({ txId: BigInt(txId) });
551
591
  } else {
552
- (await cl.POST('/v1/tx-sync', { body: { txId: txId.toString() } }));
592
+ await cl.POST("/v1/tx-sync", { body: { txId: txId.toString() } });
553
593
  }
554
594
  }
555
595
 
@@ -558,7 +598,9 @@ export class LLPlClient implements WireClientProviderFactory {
558
598
  let totalAbortSignal = abortSignal;
559
599
  if (ops.abortSignal) totalAbortSignal = AbortSignal.any([totalAbortSignal, ops.abortSignal]);
560
600
 
561
- const timeout = ops.timeout ?? (rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout);
601
+ const timeout =
602
+ ops.timeout ??
603
+ (rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout);
562
604
 
563
605
  const cl = this.clientProvider.get();
564
606
  if (cl instanceof GrpcPlApiClient) {
@@ -569,7 +611,7 @@ export class LLPlClient implements WireClientProviderFactory {
569
611
  }
570
612
 
571
613
  const wireConn = this.wireConnection;
572
- if (wireConn.type === 'rest') {
614
+ if (wireConn.type === "rest") {
573
615
  // For REST/WebSocket protocol, timeout needs to be converted to AbortSignal
574
616
  if (timeout !== undefined) {
575
617
  totalAbortSignal = AbortSignal.any([totalAbortSignal, AbortSignal.timeout(timeout)]);
@@ -582,7 +624,8 @@ export class LLPlClient implements WireClientProviderFactory {
582
624
  ? `wss://${this.conf.hostAndPort}/v1/ws/tx`
583
625
  : `ws://${this.conf.hostAndPort}/v1/ws/tx`;
584
626
 
585
- return new WebSocketBiDiStream(wsUrl,
627
+ return new WebSocketBiDiStream(
628
+ wsUrl,
586
629
  (msg) => TxAPI_ClientMessage.toBinary(msg),
587
630
  (data) => TxAPI_ServerMessage.fromBinary(new Uint8Array(data)),
588
631
  {
@@ -590,11 +633,12 @@ export class LLPlClient implements WireClientProviderFactory {
590
633
  jwtToken: this.authInformation?.jwtToken,
591
634
  dispatcher: wireConn.Dispatcher,
592
635
 
593
- onComplete: async (stream) => stream.requests.send({
594
- // Ask server to gracefully close the stream on its side, if not done yet.
595
- requestId: 0,
596
- request: { oneofKind: 'streamClose', streamClose: {} },
597
- }),
636
+ onComplete: async (stream) =>
637
+ stream.requests.send({
638
+ // Ask server to gracefully close the stream on its side, if not done yet.
639
+ requestId: 0,
640
+ request: { oneofKind: "streamClose", streamClose: {} },
641
+ }),
598
642
  },
599
643
  );
600
644
  }
@@ -605,7 +649,7 @@ export class LLPlClient implements WireClientProviderFactory {
605
649
 
606
650
  /** Closes underlying transport */
607
651
  public async close() {
608
- if (this.wireConnection.type === 'grpc') {
652
+ if (this.wireConnection.type === "grpc") {
609
653
  this.wireConnection.Transport.close();
610
654
  } else {
611
655
  // TODO: close all WS connections