@milaboratories/pl-client 2.17.6 → 2.17.8

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 (274) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +43 -0
  2. package/dist/_virtual/_rolldown/runtime.js +18 -0
  3. package/dist/core/PromiseTracker.cjs +33 -33
  4. package/dist/core/PromiseTracker.cjs.map +1 -1
  5. package/dist/core/PromiseTracker.d.ts +10 -7
  6. package/dist/core/PromiseTracker.js +33 -31
  7. package/dist/core/PromiseTracker.js.map +1 -1
  8. package/dist/core/StatefulPromise.cjs +60 -61
  9. package/dist/core/StatefulPromise.cjs.map +1 -1
  10. package/dist/core/StatefulPromise.js +60 -60
  11. package/dist/core/StatefulPromise.js.map +1 -1
  12. package/dist/core/abstract_stream.d.ts +18 -15
  13. package/dist/core/advisory_locks.cjs +42 -49
  14. package/dist/core/advisory_locks.cjs.map +1 -1
  15. package/dist/core/advisory_locks.js +42 -48
  16. package/dist/core/advisory_locks.js.map +1 -1
  17. package/dist/core/auth.cjs +10 -15
  18. package/dist/core/auth.cjs.map +1 -1
  19. package/dist/core/auth.d.ts +7 -3
  20. package/dist/core/auth.js +10 -13
  21. package/dist/core/auth.js.map +1 -1
  22. package/dist/core/cache.d.ts +11 -7
  23. package/dist/core/client.cjs +255 -306
  24. package/dist/core/client.cjs.map +1 -1
  25. package/dist/core/client.d.ts +72 -68
  26. package/dist/core/client.js +253 -285
  27. package/dist/core/client.js.map +1 -1
  28. package/dist/core/config.cjs +81 -99
  29. package/dist/core/config.cjs.map +1 -1
  30. package/dist/core/config.d.ts +93 -90
  31. package/dist/core/config.js +81 -98
  32. package/dist/core/config.js.map +1 -1
  33. package/dist/core/default_client.cjs +84 -125
  34. package/dist/core/default_client.cjs.map +1 -1
  35. package/dist/core/default_client.d.ts +9 -6
  36. package/dist/core/default_client.js +78 -103
  37. package/dist/core/default_client.js.map +1 -1
  38. package/dist/core/driver.cjs +12 -16
  39. package/dist/core/driver.cjs.map +1 -1
  40. package/dist/core/driver.d.ts +18 -14
  41. package/dist/core/driver.js +12 -15
  42. package/dist/core/driver.js.map +1 -1
  43. package/dist/core/error_resource.cjs +5 -4
  44. package/dist/core/error_resource.cjs.map +1 -1
  45. package/dist/core/error_resource.js +5 -3
  46. package/dist/core/error_resource.js.map +1 -1
  47. package/dist/core/errors.cjs +104 -140
  48. package/dist/core/errors.cjs.map +1 -1
  49. package/dist/core/errors.d.ts +34 -30
  50. package/dist/core/errors.js +102 -137
  51. package/dist/core/errors.js.map +1 -1
  52. package/dist/core/final.cjs +63 -89
  53. package/dist/core/final.cjs.map +1 -1
  54. package/dist/core/final.d.ts +8 -4
  55. package/dist/core/final.js +63 -87
  56. package/dist/core/final.js.map +1 -1
  57. package/dist/core/ll_client.cjs +416 -521
  58. package/dist/core/ll_client.cjs.map +1 -1
  59. package/dist/core/ll_client.d.ts +100 -97
  60. package/dist/core/ll_client.js +415 -519
  61. package/dist/core/ll_client.js.map +1 -1
  62. package/dist/core/ll_transaction.cjs +206 -240
  63. package/dist/core/ll_transaction.cjs.map +1 -1
  64. package/dist/core/ll_transaction.d.ts +50 -52
  65. package/dist/core/ll_transaction.js +205 -238
  66. package/dist/core/ll_transaction.js.map +1 -1
  67. package/dist/core/stat.cjs +64 -63
  68. package/dist/core/stat.cjs.map +1 -1
  69. package/dist/core/stat.d.ts +35 -36
  70. package/dist/core/stat.js +64 -62
  71. package/dist/core/stat.js.map +1 -1
  72. package/dist/core/transaction.cjs +613 -650
  73. package/dist/core/transaction.cjs.map +1 -1
  74. package/dist/core/transaction.d.ts +165 -162
  75. package/dist/core/transaction.js +612 -648
  76. package/dist/core/transaction.js.map +1 -1
  77. package/dist/core/type_conversion.cjs +62 -83
  78. package/dist/core/type_conversion.cjs.map +1 -1
  79. package/dist/core/type_conversion.js +61 -81
  80. package/dist/core/type_conversion.js.map +1 -1
  81. package/dist/core/types.cjs +56 -86
  82. package/dist/core/types.cjs.map +1 -1
  83. package/dist/core/types.d.ts +63 -62
  84. package/dist/core/types.js +54 -83
  85. package/dist/core/types.js.map +1 -1
  86. package/dist/core/unauth_client.cjs +35 -41
  87. package/dist/core/unauth_client.cjs.map +1 -1
  88. package/dist/core/unauth_client.d.ts +18 -14
  89. package/dist/core/unauth_client.js +34 -39
  90. package/dist/core/unauth_client.js.map +1 -1
  91. package/dist/core/websocket_stream.cjs +277 -349
  92. package/dist/core/websocket_stream.cjs.map +1 -1
  93. package/dist/core/websocket_stream.js +275 -347
  94. package/dist/core/websocket_stream.js.map +1 -1
  95. package/dist/core/wire.d.ts +21 -17
  96. package/dist/helpers/pl.cjs +71 -73
  97. package/dist/helpers/pl.cjs.map +1 -1
  98. package/dist/helpers/pl.d.ts +40 -41
  99. package/dist/helpers/pl.js +66 -46
  100. package/dist/helpers/pl.js.map +1 -1
  101. package/dist/helpers/poll.cjs +99 -134
  102. package/dist/helpers/poll.cjs.map +1 -1
  103. package/dist/helpers/poll.d.ts +37 -34
  104. package/dist/helpers/poll.js +97 -113
  105. package/dist/helpers/poll.js.map +1 -1
  106. package/dist/helpers/retry_strategy.cjs +82 -87
  107. package/dist/helpers/retry_strategy.cjs.map +1 -1
  108. package/dist/helpers/retry_strategy.js +83 -86
  109. package/dist/helpers/retry_strategy.js.map +1 -1
  110. package/dist/helpers/tx_helpers.cjs +21 -20
  111. package/dist/helpers/tx_helpers.cjs.map +1 -1
  112. package/dist/helpers/tx_helpers.d.ts +11 -7
  113. package/dist/helpers/tx_helpers.js +20 -18
  114. package/dist/helpers/tx_helpers.js.map +1 -1
  115. package/dist/index.cjs +117 -106
  116. package/dist/index.d.ts +17 -17
  117. package/dist/index.js +17 -19
  118. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs +72 -66
  119. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -1
  120. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts +35 -37
  121. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js +71 -64
  122. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -1
  123. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12611 -12866
  124. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -1
  125. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +226 -226
  126. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -1
  127. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +281 -330
  128. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +225 -224
  129. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -1
  130. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +2640 -4294
  131. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js +12608 -12706
  132. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -1
  133. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1230 -1089
  134. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -1
  135. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +393 -420
  136. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1228 -1083
  137. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -1
  138. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +142 -143
  139. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -1
  140. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +62 -64
  141. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +140 -141
  142. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -1
  143. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +572 -487
  144. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -1
  145. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +125 -228
  146. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +572 -485
  147. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -1
  148. package/dist/proto-grpc/google/protobuf/any.cjs +131 -146
  149. package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -1
  150. package/dist/proto-grpc/google/protobuf/any.d.ts +78 -84
  151. package/dist/proto-grpc/google/protobuf/any.js +130 -144
  152. package/dist/proto-grpc/google/protobuf/any.js.map +1 -1
  153. package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
  154. package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
  155. package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
  156. package/dist/proto-grpc/google/protobuf/duration.js +91 -98
  157. package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
  158. package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
  159. package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
  160. package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
  161. package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
  162. package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
  163. package/dist/proto-grpc/google/rpc/code.cjs +223 -238
  164. package/dist/proto-grpc/google/rpc/code.cjs.map +1 -1
  165. package/dist/proto-grpc/google/rpc/code.d.ts +209 -206
  166. package/dist/proto-grpc/google/rpc/code.js +221 -237
  167. package/dist/proto-grpc/google/rpc/code.js.map +1 -1
  168. package/dist/proto-rest/index.cjs +67 -66
  169. package/dist/proto-rest/index.cjs.map +1 -1
  170. package/dist/proto-rest/index.d.ts +24 -18
  171. package/dist/proto-rest/index.js +61 -65
  172. package/dist/proto-rest/index.js.map +1 -1
  173. package/dist/proto-rest/plapi.d.ts +1400 -1477
  174. package/dist/test/tcp-proxy.cjs +100 -126
  175. package/dist/test/tcp-proxy.cjs.map +1 -1
  176. package/dist/test/tcp-proxy.d.ts +17 -13
  177. package/dist/test/tcp-proxy.js +97 -104
  178. package/dist/test/tcp-proxy.js.map +1 -1
  179. package/dist/test/test_config.cjs +145 -194
  180. package/dist/test/test_config.cjs.map +1 -1
  181. package/dist/test/test_config.d.ts +34 -30
  182. package/dist/test/test_config.js +138 -166
  183. package/dist/test/test_config.js.map +1 -1
  184. package/dist/util/pl.cjs +4 -3
  185. package/dist/util/pl.cjs.map +1 -1
  186. package/dist/util/pl.js +4 -2
  187. package/dist/util/pl.js.map +1 -1
  188. package/dist/util/util.cjs +7 -10
  189. package/dist/util/util.cjs.map +1 -1
  190. package/dist/util/util.js +7 -9
  191. package/dist/util/util.js.map +1 -1
  192. package/package.json +10 -10
  193. package/src/core/transaction.ts +123 -133
  194. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -61
  195. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
  196. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -58
  197. package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
  198. package/dist/core/PromiseTracker.d.ts.map +0 -1
  199. package/dist/core/StatefulPromise.d.ts +0 -39
  200. package/dist/core/StatefulPromise.d.ts.map +0 -1
  201. package/dist/core/abstract_stream.d.ts.map +0 -1
  202. package/dist/core/advisory_locks.d.ts +0 -10
  203. package/dist/core/advisory_locks.d.ts.map +0 -1
  204. package/dist/core/auth.d.ts.map +0 -1
  205. package/dist/core/cache.d.ts.map +0 -1
  206. package/dist/core/client.d.ts.map +0 -1
  207. package/dist/core/config.d.ts.map +0 -1
  208. package/dist/core/default_client.d.ts.map +0 -1
  209. package/dist/core/driver.d.ts.map +0 -1
  210. package/dist/core/error_resource.d.ts +0 -6
  211. package/dist/core/error_resource.d.ts.map +0 -1
  212. package/dist/core/errors.d.ts.map +0 -1
  213. package/dist/core/final.d.ts.map +0 -1
  214. package/dist/core/ll_client.d.ts.map +0 -1
  215. package/dist/core/ll_transaction.d.ts.map +0 -1
  216. package/dist/core/stat.d.ts.map +0 -1
  217. package/dist/core/transaction.d.ts.map +0 -1
  218. package/dist/core/type_conversion.d.ts +0 -8
  219. package/dist/core/type_conversion.d.ts.map +0 -1
  220. package/dist/core/types.d.ts.map +0 -1
  221. package/dist/core/unauth_client.d.ts.map +0 -1
  222. package/dist/core/websocket_stream.d.ts +0 -67
  223. package/dist/core/websocket_stream.d.ts.map +0 -1
  224. package/dist/core/wire.d.ts.map +0 -1
  225. package/dist/helpers/pl.d.ts.map +0 -1
  226. package/dist/helpers/poll.d.ts.map +0 -1
  227. package/dist/helpers/retry_strategy.d.ts +0 -24
  228. package/dist/helpers/retry_strategy.d.ts.map +0 -1
  229. package/dist/helpers/state_helpers.d.ts +0 -3
  230. package/dist/helpers/state_helpers.d.ts.map +0 -1
  231. package/dist/helpers/tx_helpers.d.ts.map +0 -1
  232. package/dist/index.cjs.map +0 -1
  233. package/dist/index.d.ts.map +0 -1
  234. package/dist/index.js.map +0 -1
  235. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
  236. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
  237. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
  238. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
  239. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
  240. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
  241. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
  242. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
  243. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
  244. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
  245. package/dist/proto-grpc/google/api/http.d.ts +0 -456
  246. package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
  247. package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
  248. package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
  249. package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
  250. package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
  251. package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
  252. package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
  253. package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
  254. package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
  255. package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
  256. package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
  257. package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
  258. package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
  259. package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
  260. package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
  261. package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
  262. package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
  263. package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
  264. package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
  265. package/dist/proto-rest/index.d.ts.map +0 -1
  266. package/dist/proto-rest/plapi.d.ts.map +0 -1
  267. package/dist/test/tcp-proxy.d.ts.map +0 -1
  268. package/dist/test/test_config.d.ts.map +0 -1
  269. package/dist/util/branding.d.ts +0 -7
  270. package/dist/util/branding.d.ts.map +0 -1
  271. package/dist/util/pl.d.ts +0 -9
  272. package/dist/util/pl.d.ts.map +0 -1
  273. package/dist/util/util.d.ts +0 -2
  274. package/dist/util/util.d.ts.map +0 -1
@@ -1,110 +1,93 @@
1
+ //#region src/core/config.ts
1
2
  const SUPPORTED_WIRE_PROTOCOLS = ["grpc", "rest"];
2
- const DEFAULT_REQUEST_TIMEOUT = 5_000;
3
- const DEFAULT_RO_TX_TIMEOUT = 300_000;
4
- const DEFAULT_RW_TX_TIMEOUT = 60_000;
5
- const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;
6
- const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;
7
- const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb
3
+ const DEFAULT_REQUEST_TIMEOUT = 5e3;
4
+ const DEFAULT_RO_TX_TIMEOUT = 3e5;
5
+ const DEFAULT_RW_TX_TIMEOUT = 6e4;
6
+ const DEFAULT_TOKEN_TTL_SECONDS = 744 * 60 * 60;
7
+ const DEFAULT_AUTH_MAX_REFRESH = 288 * 60 * 60;
8
+ const DEFAULT_MAX_CACHE_BYTES = 128e6;
8
9
  const DEFAULT_RETRY_BACKOFF_ALGORITHM = "exponential";
9
- const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries
10
- const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure
11
- const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round
12
- const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms
13
- const DEFAULT_RETRY_JITTER = 0.3; // 30%
10
+ const DEFAULT_RETRY_MAX_ATTEMPTS = 21;
11
+ const DEFAULT_RETRY_INITIAL_DELAY = 20;
12
+ const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5;
13
+ const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50;
14
+ const DEFAULT_RETRY_JITTER = .3;
14
15
  const DefaultRetryOptions = {
15
- type: "exponentialBackoff",
16
- maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
17
- initialDelay: DEFAULT_RETRY_INITIAL_DELAY,
18
- backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
19
- jitter: DEFAULT_RETRY_JITTER,
16
+ type: "exponentialBackoff",
17
+ maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
18
+ initialDelay: DEFAULT_RETRY_INITIAL_DELAY,
19
+ backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
20
+ jitter: DEFAULT_RETRY_JITTER
20
21
  };
21
22
  function parseInt(s) {
22
- if (!s)
23
- return undefined;
24
- const num = Number(s);
25
- if (Number.isNaN(num))
26
- throw new Error(`Can't parse number: ${s}`);
27
- return num;
23
+ if (!s) return void 0;
24
+ const num = Number(s);
25
+ if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);
26
+ return num;
28
27
  }
29
28
  /** Parses pl url and creates a config object that can be passed to
30
- * {@link PlClient} of {@link UnauthenticatedPlClient}. */
29
+ * {@link PlClient} of {@link UnauthenticatedPlClient}. */
31
30
  function plAddressToConfig(address, overrides = {}) {
32
- if (address.indexOf("://") === -1)
33
- // non-url address
34
- return {
35
- hostAndPort: address,
36
- ssl: false,
37
- defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,
38
- defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,
39
- defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,
40
- authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
41
- authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
42
- txDelay: 0,
43
- forceSync: false,
44
- maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,
45
- retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,
46
- retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
47
- retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,
48
- retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
49
- retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
50
- retryJitter: DEFAULT_RETRY_JITTER,
51
- ...overrides,
52
- };
53
- const url = new URL(address);
54
- if (url.protocol !== "https:" &&
55
- url.protocol !== "http:" &&
56
- url.protocol !== "grpc:" &&
57
- url.protocol !== "tls:")
58
- throw new Error(`Unexpected URL schema: ${url.protocol}`);
59
- if (url.pathname !== "/" && url.pathname !== "")
60
- throw new Error(`Unexpected URL path: ${url.pathname}`);
61
- let port = url.port;
62
- if (!port) {
63
- switch (url.protocol) {
64
- case "http:":
65
- port = "80";
66
- break;
67
- case "https:":
68
- port = "443";
69
- break;
70
- default:
71
- throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);
72
- }
73
- }
74
- return {
75
- hostAndPort: `${url.hostname}:${port}`,
76
- alternativeRoot: url.searchParams.get("alternative-root") ?? undefined,
77
- ssl: url.protocol === "https:" || url.protocol === "tls:",
78
- wireProtocol: url.searchParams.get("wire-protocol") ?? undefined,
79
- defaultRequestTimeout: parseInt(url.searchParams.get("request-timeout")) ?? DEFAULT_REQUEST_TIMEOUT,
80
- defaultROTransactionTimeout: parseInt(url.searchParams.get("ro-tx-timeout")) ??
81
- parseInt(url.searchParams.get("tx-timeout")) ??
82
- DEFAULT_RO_TX_TIMEOUT,
83
- defaultRWTransactionTimeout: parseInt(url.searchParams.get("rw-tx-timeout")) ??
84
- parseInt(url.searchParams.get("tx-timeout")) ??
85
- DEFAULT_RW_TX_TIMEOUT,
86
- authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
87
- authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
88
- grpcProxy: url.searchParams.get("grpc-proxy") ?? undefined,
89
- httpProxy: url.searchParams.get("http-proxy") ?? undefined,
90
- user: url.username === "" ? undefined : url.username,
91
- password: url.password === "" ? undefined : url.password,
92
- txDelay: parseInt(url.searchParams.get("tx-delay")) ?? 0,
93
- forceSync: Boolean(url.searchParams.get("force-sync")),
94
- maxCacheBytes: parseInt(url.searchParams.get("max-cache-bytes")) ?? DEFAULT_MAX_CACHE_BYTES,
95
- retryBackoffAlgorithm: (url.searchParams.get("retry-backoff-algorithm") ??
96
- DEFAULT_RETRY_BACKOFF_ALGORITHM),
97
- retryMaxAttempts: parseInt(url.searchParams.get("retry-max-attempts")) ?? DEFAULT_RETRY_MAX_ATTEMPTS,
98
- retryInitialDelay: parseInt(url.searchParams.get("retry-initial-delay")) ?? DEFAULT_RETRY_INITIAL_DELAY,
99
- retryExponentialBackoffMultiplier: parseInt(url.searchParams.get("retry-exp-backoff-multiplier")) ??
100
- DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
101
- retryLinearBackoffStep: parseInt(url.searchParams.get("retry-linear-backoff-step")) ??
102
- DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
103
- retryJitter: parseInt(url.searchParams.get("retry-backoff-jitter")) ?? DEFAULT_RETRY_JITTER,
104
- ...overrides,
105
- };
31
+ if (address.indexOf("://") === -1) return {
32
+ hostAndPort: address,
33
+ ssl: false,
34
+ defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,
35
+ defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,
36
+ defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,
37
+ authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
38
+ authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
39
+ txDelay: 0,
40
+ forceSync: false,
41
+ maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,
42
+ retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,
43
+ retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
44
+ retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,
45
+ retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
46
+ retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
47
+ retryJitter: DEFAULT_RETRY_JITTER,
48
+ ...overrides
49
+ };
50
+ const url = new URL(address);
51
+ if (url.protocol !== "https:" && url.protocol !== "http:" && url.protocol !== "grpc:" && url.protocol !== "tls:") throw new Error(`Unexpected URL schema: ${url.protocol}`);
52
+ if (url.pathname !== "/" && url.pathname !== "") throw new Error(`Unexpected URL path: ${url.pathname}`);
53
+ let port = url.port;
54
+ if (!port) switch (url.protocol) {
55
+ case "http:":
56
+ port = "80";
57
+ break;
58
+ case "https:":
59
+ port = "443";
60
+ break;
61
+ default: throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);
62
+ }
63
+ return {
64
+ hostAndPort: `${url.hostname}:${port}`,
65
+ alternativeRoot: url.searchParams.get("alternative-root") ?? void 0,
66
+ ssl: url.protocol === "https:" || url.protocol === "tls:",
67
+ wireProtocol: url.searchParams.get("wire-protocol") ?? void 0,
68
+ defaultRequestTimeout: parseInt(url.searchParams.get("request-timeout")) ?? DEFAULT_REQUEST_TIMEOUT,
69
+ defaultROTransactionTimeout: parseInt(url.searchParams.get("ro-tx-timeout")) ?? parseInt(url.searchParams.get("tx-timeout")) ?? DEFAULT_RO_TX_TIMEOUT,
70
+ defaultRWTransactionTimeout: parseInt(url.searchParams.get("rw-tx-timeout")) ?? parseInt(url.searchParams.get("tx-timeout")) ?? DEFAULT_RW_TX_TIMEOUT,
71
+ authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
72
+ authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
73
+ grpcProxy: url.searchParams.get("grpc-proxy") ?? void 0,
74
+ httpProxy: url.searchParams.get("http-proxy") ?? void 0,
75
+ user: url.username === "" ? void 0 : url.username,
76
+ password: url.password === "" ? void 0 : url.password,
77
+ txDelay: parseInt(url.searchParams.get("tx-delay")) ?? 0,
78
+ forceSync: Boolean(url.searchParams.get("force-sync")),
79
+ maxCacheBytes: parseInt(url.searchParams.get("max-cache-bytes")) ?? DEFAULT_MAX_CACHE_BYTES,
80
+ retryBackoffAlgorithm: url.searchParams.get("retry-backoff-algorithm") ?? DEFAULT_RETRY_BACKOFF_ALGORITHM,
81
+ retryMaxAttempts: parseInt(url.searchParams.get("retry-max-attempts")) ?? DEFAULT_RETRY_MAX_ATTEMPTS,
82
+ retryInitialDelay: parseInt(url.searchParams.get("retry-initial-delay")) ?? DEFAULT_RETRY_INITIAL_DELAY,
83
+ retryExponentialBackoffMultiplier: parseInt(url.searchParams.get("retry-exp-backoff-multiplier")) ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
84
+ retryLinearBackoffStep: parseInt(url.searchParams.get("retry-linear-backoff-step")) ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
85
+ retryJitter: parseInt(url.searchParams.get("retry-backoff-jitter")) ?? DEFAULT_RETRY_JITTER,
86
+ ...overrides
87
+ };
106
88
  }
107
89
  const AnonymousAuthInformation = {};
108
90
 
91
+ //#endregion
109
92
  export { AnonymousAuthInformation, DEFAULT_AUTH_MAX_REFRESH, DEFAULT_MAX_CACHE_BYTES, DEFAULT_REQUEST_TIMEOUT, DEFAULT_RETRY_BACKOFF_ALGORITHM, DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY, DEFAULT_RETRY_JITTER, DEFAULT_RETRY_LINEAR_BACKOFF_STEP, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RO_TX_TIMEOUT, DEFAULT_RW_TX_TIMEOUT, DEFAULT_TOKEN_TTL_SECONDS, DefaultRetryOptions, SUPPORTED_WIRE_PROTOCOLS, plAddressToConfig };
110
- //# sourceMappingURL=config.js.map
93
+ //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from \"@milaboratories/pl-http\";\nimport type { ExponentialBackoffRetryOptions } from \"@milaboratories/ts-helpers\";\n\nexport const SUPPORTED_WIRE_PROTOCOLS = [\"grpc\", \"rest\"] as const;\nexport type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** Type of wire connection (protocol server uses for communication) */\n wireProtocol?: wireProtocol;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: \"exponential\" | \"linear\";\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = \"exponential\";\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: \"exponentialBackoff\",\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | \"ssl\"\n | \"defaultRequestTimeout\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"httpProxy\"\n | \"grpcProxy\"\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf(\"://\") === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== \"https:\" &&\n url.protocol !== \"http:\" &&\n url.protocol !== \"grpc:\" &&\n url.protocol !== \"tls:\"\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== \"/\" && url.pathname !== \"\")\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case \"http:\":\n port = \"80\";\n break;\n case \"https:\":\n port = \"443\";\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get(\"alternative-root\") ?? undefined,\n ssl: url.protocol === \"https:\" || url.protocol === \"tls:\",\n\n wireProtocol: (url.searchParams.get(\"wire-protocol\") as wireProtocol) ?? undefined,\n\n defaultRequestTimeout:\n parseInt(url.searchParams.get(\"request-timeout\")) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get(\"ro-tx-timeout\")) ??\n parseInt(url.searchParams.get(\"tx-timeout\")) ??\n DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get(\"rw-tx-timeout\")) ??\n parseInt(url.searchParams.get(\"tx-timeout\")) ??\n DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get(\"grpc-proxy\") ?? undefined,\n httpProxy: url.searchParams.get(\"http-proxy\") ?? undefined,\n user: url.username === \"\" ? undefined : url.username,\n password: url.password === \"\" ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get(\"tx-delay\")) ?? 0,\n forceSync: Boolean(url.searchParams.get(\"force-sync\")),\n\n maxCacheBytes: parseInt(url.searchParams.get(\"max-cache-bytes\")) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get(\"retry-backoff-algorithm\") ??\n DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get(\"retry-max-attempts\")) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get(\"retry-initial-delay\")) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get(\"retry-exp-backoff-multiplier\")) ??\n DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get(\"retry-linear-backoff-step\")) ??\n DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get(\"retry-backoff-jitter\")) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = \"OK\" | \"Disconnected\" | \"Unauthenticated\";\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus)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AG,CAAC,QAAQ,KAAK,EAAE,GAAG,SAAS,GAAG,GAAG,CAAC,QAAQ;AACxD,QAAA,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QACxD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAEtD,QAAA,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,uBAAuB;QAE3F,qBAAqB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,yBAAyB,CAAC;AACrE,YAAA,+BAA+B,CAAQ;AACzC,QAAA,gBAAgB,EACd,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,0BAA0B;AACpF,QAAA,iBAAiB,EACf,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,2BAA2B;QACtF,iCAAiC,EAC/B,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;YAC9D,4CAA4C;QAC9C,sBAAsB,EACpB,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;YAC3D,iCAAiC;AACnC,QAAA,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,oBAAoB;AAE3F,QAAA,GAAG,SAAS;KACb;AACH;AAWO,MAAM,wBAAwB,GAAoB;;;;"}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from \"@milaboratories/pl-http\";\nimport type { ExponentialBackoffRetryOptions } from \"@milaboratories/ts-helpers\";\n\nexport const SUPPORTED_WIRE_PROTOCOLS = [\"grpc\", \"rest\"] as const;\nexport type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** Type of wire connection (protocol server uses for communication) */\n wireProtocol?: wireProtocol;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: \"exponential\" | \"linear\";\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = \"exponential\";\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: \"exponentialBackoff\",\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | \"ssl\"\n | \"defaultRequestTimeout\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"httpProxy\"\n | \"grpcProxy\"\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf(\"://\") === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== \"https:\" &&\n url.protocol !== \"http:\" &&\n url.protocol !== \"grpc:\" &&\n url.protocol !== \"tls:\"\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== \"/\" && url.pathname !== \"\")\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case \"http:\":\n port = \"80\";\n break;\n case \"https:\":\n port = \"443\";\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get(\"alternative-root\") ?? undefined,\n ssl: url.protocol === \"https:\" || url.protocol === \"tls:\",\n\n wireProtocol: (url.searchParams.get(\"wire-protocol\") as wireProtocol) ?? undefined,\n\n defaultRequestTimeout:\n parseInt(url.searchParams.get(\"request-timeout\")) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get(\"ro-tx-timeout\")) ??\n parseInt(url.searchParams.get(\"tx-timeout\")) ??\n DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get(\"rw-tx-timeout\")) ??\n parseInt(url.searchParams.get(\"tx-timeout\")) ??\n DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get(\"grpc-proxy\") ?? undefined,\n httpProxy: url.searchParams.get(\"http-proxy\") ?? undefined,\n user: url.username === \"\" ? undefined : url.username,\n password: url.password === \"\" ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get(\"tx-delay\")) ?? 0,\n forceSync: Boolean(url.searchParams.get(\"force-sync\")),\n\n maxCacheBytes: parseInt(url.searchParams.get(\"max-cache-bytes\")) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get(\"retry-backoff-algorithm\") ??\n DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get(\"retry-max-attempts\")) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get(\"retry-initial-delay\")) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get(\"retry-exp-backoff-multiplier\")) ??\n DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get(\"retry-linear-backoff-step\")) ??\n DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get(\"retry-backoff-jitter\")) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = \"OK\" | \"Disconnected\" | \"Unauthenticated\";\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus) => void;\n"],"mappings":";AAGA,MAAa,2BAA2B,CAAC,QAAQ,OAAO;AAsFxD,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;AACrC,MAAa,4BAA4B,MAAU,KAAK;AACxD,MAAa,2BAA2B,MAAU,KAAK;AAEvD,MAAa,0BAA0B;AAEvC,MAAa,kCAAkC;AAC/C,MAAa,6BAA6B;AAC1C,MAAa,8BAA8B;AAC3C,MAAa,+CAA+C;AAC5D,MAAa,oCAAoC;AACjD,MAAa,uBAAuB;AAEpC,MAAa,sBAAsD;CACjE,MAAM;CACN,aAAa;CACb,cAAc;CACd,mBAAmB;CACnB,QAAQ;CACT;AAcD,SAAS,SAAS,GAAkD;AAClE,KAAI,CAAC,EAAG,QAAO;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,aAAa,IAAI,gBAAgB,CAAC,IAC/C,SAAS,IAAI,aAAa,IAAI,aAAa,CAAC,IAC5C;EACF,gBAAgB;EAChB,uBAAuB;EACvB,WAAW,IAAI,aAAa,IAAI,aAAa,IAAI;EACjD,WAAW,IAAI,aAAa,IAAI,aAAa,IAAI;EACjD,MAAM,IAAI,aAAa,KAAK,SAAY,IAAI;EAC5C,UAAU,IAAI,aAAa,KAAK,SAAY,IAAI;EAChD,SAAS,SAAS,IAAI,aAAa,IAAI,WAAW,CAAC,IAAI;EACvD,WAAW,QAAQ,IAAI,aAAa,IAAI,aAAa,CAAC;EAEtD,eAAe,SAAS,IAAI,aAAa,IAAI,kBAAkB,CAAC,IAAI;EAEpE,uBAAwB,IAAI,aAAa,IAAI,0BAA0B,IACrE;EACF,kBACE,SAAS,IAAI,aAAa,IAAI,qBAAqB,CAAC,IAAI;EAC1D,mBACE,SAAS,IAAI,aAAa,IAAI,sBAAsB,CAAC,IAAI;EAC3D,mCACE,SAAS,IAAI,aAAa,IAAI,+BAA+B,CAAC,IAC9D;EACF,wBACE,SAAS,IAAI,aAAa,IAAI,4BAA4B,CAAC,IAC3D;EACF,aAAa,SAAS,IAAI,aAAa,IAAI,uBAAuB,CAAC,IAAI;EAEvE,GAAG;EACJ;;AAYH,MAAa,2BAA4C,EAAE"}
@@ -1,143 +1,102 @@
1
- 'use strict';
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_config = require('./config.cjs');
3
+ const require_auth = require('./auth.cjs');
4
+ const require_client = require('./client.cjs');
5
+ const require_unauth_client = require('./unauth_client.cjs');
6
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
7
+ let node_crypto = require("node:crypto");
8
+ let node_fs = require("node:fs");
9
+ node_fs = require_runtime.__toESM(node_fs);
10
+ let canonicalize = require("canonicalize");
11
+ canonicalize = require_runtime.__toESM(canonicalize);
12
+ let yaml = require("yaml");
13
+ yaml = require_runtime.__toESM(yaml);
14
+ let node_os = require("node:os");
15
+ node_os = require_runtime.__toESM(node_os);
16
+ let node_path = require("node:path");
17
+ node_path = require_runtime.__toESM(node_path);
2
18
 
3
- var fs = require('node:fs');
4
- var config = require('./config.cjs');
5
- var canonicalize = require('canonicalize');
6
- var YAML = require('yaml');
7
- var os = require('node:os');
8
- var path = require('node:path');
9
- var tsHelpers = require('@milaboratories/ts-helpers');
10
- var unauth_client = require('./unauth_client.cjs');
11
- var client = require('./client.cjs');
12
- var node_crypto = require('node:crypto');
13
- var auth = require('./auth.cjs');
14
-
15
- function _interopNamespaceDefault(e) {
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- }
28
- n.default = e;
29
- return Object.freeze(n);
30
- }
31
-
32
- var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
33
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
34
-
35
- const CONFIG_FILE_LOCAL_JSON = "pl.json";
36
- const CONFIG_FILE_USER_JSON = path__namespace.join(os__namespace.homedir(), ".pl.json");
37
- const CONFIG_FILE_LOCAL_YAML = "pl.yaml";
38
- const CONFIG_FILE_USER_YAML = path__namespace.join(os__namespace.homedir(), ".pl.yaml");
19
+ //#region src/core/default_client.ts
39
20
  const CONF_FILE_SEQUENCE = [
40
- CONFIG_FILE_LOCAL_JSON,
41
- CONFIG_FILE_LOCAL_YAML,
42
- CONFIG_FILE_USER_JSON,
43
- CONFIG_FILE_USER_YAML,
21
+ "pl.json",
22
+ "pl.yaml",
23
+ node_path.join(node_os.homedir(), ".pl.json"),
24
+ node_path.join(node_os.homedir(), ".pl.yaml")
44
25
  ];
45
26
  const AUTH_DATA_FILE = ".pl_auth.json";
46
27
  const FILE_CONFIG_OVERRIDE_FIELDS = [
47
- "grpcProxy",
48
- "httpProxy",
49
- "user",
50
- "password",
51
- "alternativeRoot",
52
- "defaultROTransactionTimeout",
53
- "defaultRWTransactionTimeout",
54
- "defaultRequestTimeout",
55
- "authTTLSeconds",
56
- "authMaxRefreshSeconds",
28
+ "grpcProxy",
29
+ "httpProxy",
30
+ "user",
31
+ "password",
32
+ "alternativeRoot",
33
+ "defaultROTransactionTimeout",
34
+ "defaultRWTransactionTimeout",
35
+ "defaultRequestTimeout",
36
+ "authTTLSeconds",
37
+ "authMaxRefreshSeconds"
57
38
  ];
58
39
  function tryGetFileConfig() {
59
- for (const confPath of CONF_FILE_SEQUENCE)
60
- if (fs.existsSync(confPath)) {
61
- const fileContent = fs.readFileSync(confPath, { encoding: "utf-8" });
62
- if (confPath.endsWith("json"))
63
- return [JSON.parse(fileContent), confPath];
64
- else
65
- return [YAML.parse(fileContent), confPath];
66
- }
67
- return undefined;
40
+ for (const confPath of CONF_FILE_SEQUENCE) if (node_fs.default.existsSync(confPath)) {
41
+ const fileContent = node_fs.default.readFileSync(confPath, { encoding: "utf-8" });
42
+ if (confPath.endsWith("json")) return [JSON.parse(fileContent), confPath];
43
+ else return [yaml.default.parse(fileContent), confPath];
44
+ }
68
45
  }
69
46
  function saveAuthInfoCallback(confHash, authMaxRefreshSeconds) {
70
- return (newAuthInfo) => {
71
- fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
72
- confHash,
73
- authInformation: newAuthInfo,
74
- expiration: auth.inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),
75
- })), "utf8");
76
- };
47
+ return (newAuthInfo) => {
48
+ node_fs.default.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
49
+ confHash,
50
+ authInformation: newAuthInfo,
51
+ expiration: require_auth.inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds)
52
+ })), "utf8");
53
+ };
77
54
  }
78
55
  const cleanAuthInfoCallback = () => {
79
- fs.rmSync(AUTH_DATA_FILE);
56
+ node_fs.default.rmSync(AUTH_DATA_FILE);
80
57
  };
81
58
  /** Uses default algorithm to construct a pl client from the environment */
82
59
  async function defaultPlClient() {
83
- let config$1 = undefined;
84
- if (process.env.PL_ADDRESS !== undefined) {
85
- config$1 = config.plAddressToConfig(process.env.PL_ADDRESS);
86
- }
87
- else {
88
- const fromFile = tryGetFileConfig();
89
- if (fromFile !== undefined) {
90
- const [fileConfig, configPath] = fromFile;
91
- const address = tsHelpers.notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);
92
- config$1 = config.plAddressToConfig(address);
93
- // applying overrides
94
- for (const field of FILE_CONFIG_OVERRIDE_FIELDS)
95
- if (fileConfig[field] !== undefined)
96
- config$1[field] = fileConfig[field];
97
- }
98
- }
99
- if (config$1 === undefined)
100
- throw new Error("Can't find configuration to create default platform client.");
101
- if (process.env.PL_USER !== undefined)
102
- config$1.user = process.env.PL_USER;
103
- if (process.env.PL_PASSWORD !== undefined)
104
- config$1.user = process.env.PL_PASSWORD;
105
- const confHash = node_crypto.createHash("sha256")
106
- .update(Buffer.from(canonicalize(config$1)))
107
- .digest("base64");
108
- let authInformation = undefined;
109
- // try recover auth information from cache
110
- if (fs.existsSync(AUTH_DATA_FILE)) {
111
- const cache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
112
- if (cache.confHash === confHash && cache.expiration > Date.now())
113
- authInformation = cache.authInformation;
114
- }
115
- if (authInformation === undefined) {
116
- const client = await unauth_client.UnauthenticatedPlClient.build(config$1);
117
- if (await client.requireAuth()) {
118
- if (config$1.user === undefined || config$1.password === undefined)
119
- throw new Error(`No auth information for found to authenticate with PL server.`);
120
- authInformation = await client.login(config$1.user, config$1.password);
121
- }
122
- else {
123
- // No authorization is required
124
- authInformation = {};
125
- }
126
- // saving cache
127
- fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
128
- confHash,
129
- authInformation,
130
- expiration: auth.inferAuthRefreshTime(authInformation, config$1.authMaxRefreshSeconds),
131
- })), "utf8");
132
- }
133
- return await client.PlClient.init(config$1, {
134
- authInformation,
135
- onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config$1.authMaxRefreshSeconds),
136
- onUpdateError: cleanAuthInfoCallback,
137
- onAuthError: cleanAuthInfoCallback,
138
- });
60
+ let config = void 0;
61
+ if (process.env.PL_ADDRESS !== void 0) config = require_config.plAddressToConfig(process.env.PL_ADDRESS);
62
+ else {
63
+ const fromFile = tryGetFileConfig();
64
+ if (fromFile !== void 0) {
65
+ const [fileConfig, configPath] = fromFile;
66
+ config = require_config.plAddressToConfig((0, _milaboratories_ts_helpers.notEmpty)(fileConfig.address, `no pl address in file: ${configPath}`));
67
+ for (const field of FILE_CONFIG_OVERRIDE_FIELDS) if (fileConfig[field] !== void 0) config[field] = fileConfig[field];
68
+ }
69
+ }
70
+ if (config === void 0) throw new Error("Can't find configuration to create default platform client.");
71
+ if (process.env.PL_USER !== void 0) config.user = process.env.PL_USER;
72
+ if (process.env.PL_PASSWORD !== void 0) config.user = process.env.PL_PASSWORD;
73
+ const confHash = (0, node_crypto.createHash)("sha256").update(Buffer.from((0, canonicalize.default)(config))).digest("base64");
74
+ let authInformation = void 0;
75
+ if (node_fs.default.existsSync(AUTH_DATA_FILE)) {
76
+ const cache = JSON.parse(node_fs.default.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
77
+ if (cache.confHash === confHash && cache.expiration > Date.now()) authInformation = cache.authInformation;
78
+ }
79
+ if (authInformation === void 0) {
80
+ const client = await require_unauth_client.UnauthenticatedPlClient.build(config);
81
+ if (await client.requireAuth()) {
82
+ if (config.user === void 0 || config.password === void 0) throw new Error(`No auth information for found to authenticate with PL server.`);
83
+ authInformation = await client.login(config.user, config.password);
84
+ } else authInformation = {};
85
+ node_fs.default.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
86
+ confHash,
87
+ authInformation,
88
+ expiration: require_auth.inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds)
89
+ })), "utf8");
90
+ }
91
+ return await require_client.PlClient.init(config, {
92
+ authInformation,
93
+ onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),
94
+ onUpdateError: cleanAuthInfoCallback,
95
+ onAuthError: cleanAuthInfoCallback
96
+ });
139
97
  }
140
98
 
99
+ //#endregion
141
100
  exports.defaultPlClient = defaultPlClient;
142
101
  exports.tryGetFileConfig = tryGetFileConfig;
143
- //# sourceMappingURL=default_client.cjs.map
102
+ //# sourceMappingURL=default_client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"default_client.cjs","sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"names":["path","os","inferAuthRefreshTime","config","plAddressToConfig","notEmpty","createHash","UnauthenticatedPlClient","PlClient"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,sBAAsB,GAAG,SAAS;AACxC,MAAM,qBAAqB,GAAGA,eAAI,CAAC,IAAI,CAACC,aAAE,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC;AACjE,MAAM,sBAAsB,GAAG,SAAS;AACxC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M,CAAC,qBAAqB,CAAC;AACxF,QAAA,aAAa,EAAE,qBAAqB;AACpC,QAAA,WAAW,EAAE,qBAAqB;AACnC,KAAA,CAAC;AACJ;;;;;"}
1
+ {"version":3,"file":"default_client.cjs","names":["path","os","fs","YAML","inferAuthRefreshTime","plAddressToConfig","UnauthenticatedPlClient","PlClient"],"sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,MAAM,qBAAqB;CAJI;CAEA;CADDA,UAAK,KAAKC,QAAG,SAAS,EAAE,WAAW;CAEnCD,UAAK,KAAKC,QAAG,SAAS,EAAE,WAAW;CAMhE;AAED,MAAM,iBAAiB;AAavB,MAAM,8BAA0D;CAC9D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAaD,SAAgB,mBAAuD;AACrE,MAAK,MAAM,YAAY,mBACrB,KAAIC,gBAAG,WAAW,SAAS,EAAE;EAC3B,MAAM,cAAcA,gBAAG,aAAa,UAAU,EAAE,UAAU,SAAS,CAAC;AACpE,MAAI,SAAS,SAAS,OA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AAM,OAAO;AAE1D,MAAI,MAAM,OAAO,aAAa,EAAE;AAC9B,OAAI,OAAO,SAAS,UAAa,OAAO,aAAa,OACnD,OAAM,IAAI,MAAM,gEAAgE;AAClF,qBAAkB,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,SAAS;QAGlE,mBAAkB,EAAE;AAItB,kBAAG,cACD,gBACA,OAAO,KACL,KAAK,UAAU;GACb;GACA;GACA,YAAYF,kCAAqB,iBAAiB,OAAO,sBAAsB;GAChF,CAAc,CAChB,EACD,OACD;;AAGH,QAAO,MAAMG,wBAAS,KAAK,QAAQ;EACjC;EACA,WAAW,iBAAiB,qBAAqB,UAAU,OAAO,sBAAsB;EACxF,eAAe;EACf,aAAa;EACd,CAAC"}
@@ -1,11 +1,14 @@
1
- import type { PlClientConfig } from "./config";
2
- import { PlClient } from "./client";
1
+ import { PlClientConfig } from "./config.js";
2
+ import { PlClient } from "./client.js";
3
+
4
+ //#region src/core/default_client.d.ts
3
5
  type FileConfigOverrideFields = "grpcProxy" | "httpProxy" | "user" | "password" | "alternativeRoot" | "defaultROTransactionTimeout" | "defaultRWTransactionTimeout" | "defaultRequestTimeout" | "authTTLSeconds" | "authMaxRefreshSeconds";
4
6
  type PlConfigFile = {
5
- address: string;
7
+ address: string;
6
8
  } & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;
7
- export declare function tryGetFileConfig(): [PlConfigFile, string] | undefined;
9
+ declare function tryGetFileConfig(): [PlConfigFile, string] | undefined;
8
10
  /** Uses default algorithm to construct a pl client from the environment */
9
- export declare function defaultPlClient(): Promise<PlClient>;
10
- export {};
11
+ declare function defaultPlClient(): Promise<PlClient>;
12
+ //#endregion
13
+ export { defaultPlClient, tryGetFileConfig };
11
14
  //# sourceMappingURL=default_client.d.ts.map