@milaboratories/pl-client 2.17.7 → 2.17.9

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 (276) 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 +280 -349
  92. package/dist/core/websocket_stream.cjs.map +1 -1
  93. package/dist/core/websocket_stream.js +278 -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 +8 -8
  193. package/src/core/errors.ts +1 -1
  194. package/src/core/transaction.ts +123 -133
  195. package/src/core/websocket_stream.ts +10 -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.cjs +0 -61
  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.cjs.map +0 -1
  198. 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
  199. 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
  200. package/dist/core/PromiseTracker.d.ts.map +0 -1
  201. package/dist/core/StatefulPromise.d.ts +0 -39
  202. package/dist/core/StatefulPromise.d.ts.map +0 -1
  203. package/dist/core/abstract_stream.d.ts.map +0 -1
  204. package/dist/core/advisory_locks.d.ts +0 -10
  205. package/dist/core/advisory_locks.d.ts.map +0 -1
  206. package/dist/core/auth.d.ts.map +0 -1
  207. package/dist/core/cache.d.ts.map +0 -1
  208. package/dist/core/client.d.ts.map +0 -1
  209. package/dist/core/config.d.ts.map +0 -1
  210. package/dist/core/default_client.d.ts.map +0 -1
  211. package/dist/core/driver.d.ts.map +0 -1
  212. package/dist/core/error_resource.d.ts +0 -6
  213. package/dist/core/error_resource.d.ts.map +0 -1
  214. package/dist/core/errors.d.ts.map +0 -1
  215. package/dist/core/final.d.ts.map +0 -1
  216. package/dist/core/ll_client.d.ts.map +0 -1
  217. package/dist/core/ll_transaction.d.ts.map +0 -1
  218. package/dist/core/stat.d.ts.map +0 -1
  219. package/dist/core/transaction.d.ts.map +0 -1
  220. package/dist/core/type_conversion.d.ts +0 -8
  221. package/dist/core/type_conversion.d.ts.map +0 -1
  222. package/dist/core/types.d.ts.map +0 -1
  223. package/dist/core/unauth_client.d.ts.map +0 -1
  224. package/dist/core/websocket_stream.d.ts +0 -67
  225. package/dist/core/websocket_stream.d.ts.map +0 -1
  226. package/dist/core/wire.d.ts.map +0 -1
  227. package/dist/helpers/pl.d.ts.map +0 -1
  228. package/dist/helpers/poll.d.ts.map +0 -1
  229. package/dist/helpers/retry_strategy.d.ts +0 -24
  230. package/dist/helpers/retry_strategy.d.ts.map +0 -1
  231. package/dist/helpers/state_helpers.d.ts +0 -3
  232. package/dist/helpers/state_helpers.d.ts.map +0 -1
  233. package/dist/helpers/tx_helpers.d.ts.map +0 -1
  234. package/dist/index.cjs.map +0 -1
  235. package/dist/index.d.ts.map +0 -1
  236. package/dist/index.js.map +0 -1
  237. package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
  238. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
  239. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
  240. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
  241. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
  242. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
  243. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
  244. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
  245. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
  246. package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
  247. package/dist/proto-grpc/google/api/http.d.ts +0 -456
  248. package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
  249. package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
  250. package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
  251. package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
  252. package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
  253. package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
  254. package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
  255. package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
  256. package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
  257. package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
  258. package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
  259. package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
  260. package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
  261. package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
  262. package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
  263. package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
  264. package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
  265. package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
  266. package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
  267. package/dist/proto-rest/index.d.ts.map +0 -1
  268. package/dist/proto-rest/plapi.d.ts.map +0 -1
  269. package/dist/test/tcp-proxy.d.ts.map +0 -1
  270. package/dist/test/test_config.d.ts.map +0 -1
  271. package/dist/util/branding.d.ts +0 -7
  272. package/dist/util/branding.d.ts.map +0 -1
  273. package/dist/util/pl.d.ts +0 -9
  274. package/dist/util/pl.d.ts.map +0 -1
  275. package/dist/util/util.d.ts +0 -2
  276. package/dist/util/util.d.ts.map +0 -1
@@ -1,292 +1,260 @@
1
- import { LLPlClient } from './ll_client.js';
2
- import { toGlobalResourceId, PlTransaction, TxCommitConflict } from './transaction.js';
3
- import { createHash } from 'node:crypto';
4
- import { NullResourceId, isNullResourceId, ensureResourceIdNotNull } from './types.js';
5
- import { ClientRoot } from '../helpers/pl.js';
6
- import { assertNever, createRetryState, nextRetryStateOrError } from '@milaboratories/ts-helpers';
7
- import { MaintenanceAPI_Ping_Response_Compression } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js';
8
- import * as tp from 'node:timers/promises';
9
- import { LRUCache } from 'lru-cache';
10
- import { DefaultFinalResourceDataPredicate } from './final.js';
11
- import { initialTxStat, addStat } from './stat.js';
12
- import { advisoryLock } from './advisory_locks.js';
13
- import { plAddressToConfig } from './config.js';
1
+ import { NullResourceId, ensureResourceIdNotNull, isNullResourceId } from "./types.js";
2
+ import { MaintenanceAPI_Ping_Response_Compression } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js";
3
+ import { addStat, initialTxStat } from "./stat.js";
4
+ import { PlTransaction, TxCommitConflict, toGlobalResourceId } from "./transaction.js";
5
+ import { ClientRoot } from "../helpers/pl.js";
6
+ import { plAddressToConfig } from "./config.js";
7
+ import { LLPlClient } from "./ll_client.js";
8
+ import { DefaultFinalResourceDataPredicate } from "./final.js";
9
+ import { advisoryLock } from "./advisory_locks.js";
10
+ import { assertNever, createRetryState, nextRetryStateOrError } from "@milaboratories/ts-helpers";
11
+ import { createHash } from "node:crypto";
12
+ import * as tp from "node:timers/promises";
13
+ import { LRUCache } from "lru-cache";
14
14
 
15
- const defaultTxOps = {
16
- sync: false,
17
- };
15
+ //#region src/core/client.ts
16
+ const defaultTxOps = { sync: false };
18
17
  const AnonymousClientRoot = "AnonymousRoot";
19
18
  function alternativeRootFieldName(alternativeRoot) {
20
- return `alternative_root_${alternativeRoot}`;
19
+ return `alternative_root_${alternativeRoot}`;
21
20
  }
22
21
  /** Client to access core PL API. */
23
- class PlClient {
24
- drivers = new Map();
25
- /** Artificial delay introduced after write transactions completion, to
26
- * somewhat throttle the load on pl. Delay introduced after sync, if requested. */
27
- txDelay;
28
- /** Last resort measure to solve complicated race conditions in pl. */
29
- forceSync;
30
- /** Last resort measure to solve complicated race conditions in pl. */
31
- defaultRetryOptions;
32
- buildLLPlClient;
33
- _ll;
34
- get ll() {
35
- if (this._ll === undefined) {
36
- throw new Error("LLPlClient not initialized");
37
- }
38
- return this._ll;
39
- }
40
- /** Stores client root (this abstraction is intended for future implementation of the security model) */
41
- _clientRoot = NullResourceId;
42
- _serverInfo = undefined;
43
- _txCommittedStat = initialTxStat();
44
- _txConflictStat = initialTxStat();
45
- _txErrorStat = initialTxStat();
46
- //
47
- // Caching
48
- //
49
- /** This function determines whether resource data can be cached */
50
- finalPredicate;
51
- /** Resource data cache, to minimize redundant data rereading from remote db */
52
- resourceDataCache;
53
- constructor(configOrAddress, auth, ops = {}) {
54
- const conf = typeof configOrAddress === "string" ? plAddressToConfig(configOrAddress) : configOrAddress;
55
- this.buildLLPlClient = async (shouldUseGzip, wireProtocol) => {
56
- if (wireProtocol)
57
- conf.wireProtocol = wireProtocol;
58
- return await LLPlClient.build(conf, { auth, ...ops, shouldUseGzip });
59
- };
60
- this.txDelay = conf.txDelay;
61
- this.forceSync = conf.forceSync;
62
- this.finalPredicate = ops.finalPredicate ?? DefaultFinalResourceDataPredicate;
63
- this.resourceDataCache = new LRUCache({
64
- maxSize: conf.maxCacheBytes,
65
- sizeCalculation: (v) => (v.basicData.data?.length ?? 0) + 64,
66
- });
67
- switch (conf.retryBackoffAlgorithm) {
68
- case "exponential":
69
- this.defaultRetryOptions = {
70
- type: "exponentialBackoff",
71
- initialDelay: conf.retryInitialDelay,
72
- maxAttempts: conf.retryMaxAttempts,
73
- backoffMultiplier: conf.retryExponentialBackoffMultiplier,
74
- jitter: conf.retryJitter,
75
- };
76
- break;
77
- case "linear":
78
- this.defaultRetryOptions = {
79
- type: "linearBackoff",
80
- initialDelay: conf.retryInitialDelay,
81
- maxAttempts: conf.retryMaxAttempts,
82
- backoffStep: conf.retryLinearBackoffStep,
83
- jitter: conf.retryJitter,
84
- };
85
- break;
86
- default:
87
- assertNever(conf.retryBackoffAlgorithm);
88
- }
89
- }
90
- get txCommittedStat() {
91
- return { ...this._txCommittedStat };
92
- }
93
- get txConflictStat() {
94
- return { ...this._txConflictStat };
95
- }
96
- get txErrorStat() {
97
- return { ...this._txErrorStat };
98
- }
99
- get txTotalStat() {
100
- return addStat(addStat(this._txCommittedStat, this._txConflictStat), this._txErrorStat);
101
- }
102
- get allTxStat() {
103
- return {
104
- committed: this.txCommittedStat,
105
- conflict: this.txConflictStat,
106
- error: this.txErrorStat,
107
- };
108
- }
109
- async ping() {
110
- return await this.ll.ping();
111
- }
112
- async license() {
113
- return await this.ll.license();
114
- }
115
- get conf() {
116
- return this.ll.conf;
117
- }
118
- get httpDispatcher() {
119
- return this.ll.httpDispatcher;
120
- }
121
- get connectionOpts() {
122
- return this.ll.wireConnection;
123
- }
124
- get initialized() {
125
- return !isNullResourceId(this._clientRoot);
126
- }
127
- checkInitialized() {
128
- if (!this.initialized)
129
- throw new Error("Client not initialized");
130
- }
131
- get clientRoot() {
132
- this.checkInitialized();
133
- return ensureResourceIdNotNull(this._clientRoot);
134
- }
135
- get serverInfo() {
136
- this.checkInitialized();
137
- return this._serverInfo;
138
- }
139
- /** Currently implements custom logic to emulate future behaviour with single root. */
140
- async init() {
141
- if (this.initialized)
142
- throw new Error("Already initialized");
143
- // Initial client is created without gzip to perform server ping and detect optimal wire protocol.
144
- // LLPlClient.build() internally calls detectOptimalWireProtocol() which starts with default 'grpc',
145
- // then retries with 'rest' if ping fails, alternating until a working protocol is found.
146
- // We save the detected wireProtocol here because if the server supports gzip compression,
147
- // we'll need to reinitialize the client with gzip enabled - passing the already-detected
148
- // wireProtocol avoids redundant protocol detection on reinit.
149
- this._ll = await this.buildLLPlClient(false);
150
- const wireProtocol = this._ll.wireProtocol;
151
- // calculating reproducible root name from the username
152
- const user = this._ll.authUser;
153
- const mainRootName = user === null ? AnonymousClientRoot : createHash("sha256").update(user).digest("hex");
154
- this._serverInfo = await this.ping();
155
- if (this._serverInfo.compression === MaintenanceAPI_Ping_Response_Compression.GZIP) {
156
- await this._ll.close();
157
- this._ll = await this.buildLLPlClient(true, wireProtocol);
158
- }
159
- this._clientRoot = await this._withTx("initialization", true, NullResourceId, async (tx) => {
160
- let mainRoot;
161
- if (await tx.checkResourceNameExists(mainRootName))
162
- mainRoot = await tx.getResourceByName(mainRootName);
163
- else {
164
- mainRoot = tx.createRoot(ClientRoot);
165
- tx.setResourceName(mainRootName, mainRoot);
166
- }
167
- if (this.conf.alternativeRoot === undefined) {
168
- await tx.commit();
169
- return await toGlobalResourceId(mainRoot);
170
- }
171
- else {
172
- const aFId = {
173
- resourceId: mainRoot,
174
- fieldName: alternativeRootFieldName(this.conf.alternativeRoot),
175
- };
176
- const altRoot = tx.createEphemeral(ClientRoot);
177
- tx.lock(altRoot);
178
- tx.createField(aFId, "Dynamic");
179
- tx.setField(aFId, altRoot);
180
- await tx.commit();
181
- return await altRoot.globalId;
182
- }
183
- });
184
- }
185
- /** Returns true if field existed */
186
- async deleteAlternativeRoot(alternativeRootName) {
187
- this.checkInitialized();
188
- if (this.ll.conf.alternativeRoot !== undefined)
189
- throw new Error("Initialized with alternative root.");
190
- return await this.withWriteTx("delete-alternative-root", async (tx) => {
191
- const fId = {
192
- resourceId: tx.clientRoot,
193
- fieldName: alternativeRootFieldName(alternativeRootName),
194
- };
195
- const exists = tx.fieldExists(fId);
196
- tx.removeField(fId);
197
- await tx.commit();
198
- return await exists;
199
- });
200
- }
201
- async _withTx(name, writable, clientRoot, body, ops) {
202
- // for exponential / linear backoff
203
- let retryState = createRetryState(ops?.retryOptions ?? this.defaultRetryOptions);
204
- while (true) {
205
- const release = ops?.lockId ? await advisoryLock(ops.lockId) : () => { };
206
- try {
207
- // opening low-level tx
208
- const llTx = this.ll.createTx(writable, ops);
209
- // wrapping it into high-level tx (this also asynchronously sends initialization message)
210
- const tx = new PlTransaction(llTx, name, writable, clientRoot, this.finalPredicate, this.resourceDataCache);
211
- let ok = false;
212
- let result = undefined;
213
- let txId;
214
- try {
215
- // executing transaction body
216
- result = await body(tx);
217
- // collecting stat
218
- this._txCommittedStat = addStat(this._txCommittedStat, tx.stat);
219
- ok = true;
220
- }
221
- catch (e) {
222
- // the only recoverable
223
- if (e instanceof TxCommitConflict) {
224
- // ignoring
225
- // collecting stat
226
- this._txConflictStat = addStat(this._txConflictStat, tx.stat);
227
- }
228
- else {
229
- // collecting stat
230
- this._txErrorStat = addStat(this._txErrorStat, tx.stat);
231
- throw e;
232
- }
233
- }
234
- finally {
235
- // close underlying grpc stream, if not yet done
236
- // even though we can skip two lines below for read-only transactions,
237
- // we don't do it to simplify reasoning about what is going on in
238
- // concurrent code, especially in significant latency situations
239
- await tx.complete();
240
- await tx.await();
241
- txId = await tx.getGlobalTxId();
242
- }
243
- if (ok) {
244
- // syncing on transaction if requested
245
- if (ops?.sync === undefined ? this.forceSync : ops?.sync)
246
- await this.ll.txSync(txId);
247
- // introducing artificial delay, if requested
248
- if (writable && this.txDelay > 0)
249
- await tp.setTimeout(this.txDelay, undefined, { signal: ops?.abortSignal });
250
- return result;
251
- }
252
- }
253
- finally {
254
- release();
255
- }
256
- // we only get here after TxCommitConflict error,
257
- // all other errors terminate this loop instantly
258
- await tp.setTimeout(retryState.nextDelay, undefined, { signal: ops?.abortSignal });
259
- retryState = nextRetryStateOrError(retryState);
260
- }
261
- }
262
- async withTx(name, writable, body, ops = {}) {
263
- this.checkInitialized();
264
- return await this._withTx(name, writable, this.clientRoot, body, { ...ops, ...defaultTxOps });
265
- }
266
- async withWriteTx(name, body, ops = {}) {
267
- return await this.withTx(name, true, body, { ...ops, ...defaultTxOps });
268
- }
269
- async withReadTx(name, body, ops = {}) {
270
- return await this.withTx(name, false, body, { ...ops, ...defaultTxOps });
271
- }
272
- getDriver(definition) {
273
- const attached = this.drivers.get(definition.name);
274
- if (attached !== undefined)
275
- return attached;
276
- const driver = definition.init(this, this.ll, this.httpDispatcher);
277
- this.drivers.set(definition.name, driver);
278
- return driver;
279
- }
280
- /** Closes underlying transport */
281
- async close() {
282
- await this.ll.close();
283
- }
284
- static async init(configOrAddress, auth, ops = {}) {
285
- const pl = new PlClient(configOrAddress, auth, ops);
286
- await pl.init();
287
- return pl;
288
- }
289
- }
22
+ var PlClient = class PlClient {
23
+ drivers = /* @__PURE__ */ new Map();
24
+ /** Artificial delay introduced after write transactions completion, to
25
+ * somewhat throttle the load on pl. Delay introduced after sync, if requested. */
26
+ txDelay;
27
+ /** Last resort measure to solve complicated race conditions in pl. */
28
+ forceSync;
29
+ /** Last resort measure to solve complicated race conditions in pl. */
30
+ defaultRetryOptions;
31
+ buildLLPlClient;
32
+ _ll;
33
+ get ll() {
34
+ if (this._ll === void 0) throw new Error("LLPlClient not initialized");
35
+ return this._ll;
36
+ }
37
+ /** Stores client root (this abstraction is intended for future implementation of the security model) */
38
+ _clientRoot = NullResourceId;
39
+ _serverInfo = void 0;
40
+ _txCommittedStat = initialTxStat();
41
+ _txConflictStat = initialTxStat();
42
+ _txErrorStat = initialTxStat();
43
+ /** This function determines whether resource data can be cached */
44
+ finalPredicate;
45
+ /** Resource data cache, to minimize redundant data rereading from remote db */
46
+ resourceDataCache;
47
+ constructor(configOrAddress, auth, ops = {}) {
48
+ const conf = typeof configOrAddress === "string" ? plAddressToConfig(configOrAddress) : configOrAddress;
49
+ this.buildLLPlClient = async (shouldUseGzip, wireProtocol) => {
50
+ if (wireProtocol) conf.wireProtocol = wireProtocol;
51
+ return await LLPlClient.build(conf, {
52
+ auth,
53
+ ...ops,
54
+ shouldUseGzip
55
+ });
56
+ };
57
+ this.txDelay = conf.txDelay;
58
+ this.forceSync = conf.forceSync;
59
+ this.finalPredicate = ops.finalPredicate ?? DefaultFinalResourceDataPredicate;
60
+ this.resourceDataCache = new LRUCache({
61
+ maxSize: conf.maxCacheBytes,
62
+ sizeCalculation: (v) => (v.basicData.data?.length ?? 0) + 64
63
+ });
64
+ switch (conf.retryBackoffAlgorithm) {
65
+ case "exponential":
66
+ this.defaultRetryOptions = {
67
+ type: "exponentialBackoff",
68
+ initialDelay: conf.retryInitialDelay,
69
+ maxAttempts: conf.retryMaxAttempts,
70
+ backoffMultiplier: conf.retryExponentialBackoffMultiplier,
71
+ jitter: conf.retryJitter
72
+ };
73
+ break;
74
+ case "linear":
75
+ this.defaultRetryOptions = {
76
+ type: "linearBackoff",
77
+ initialDelay: conf.retryInitialDelay,
78
+ maxAttempts: conf.retryMaxAttempts,
79
+ backoffStep: conf.retryLinearBackoffStep,
80
+ jitter: conf.retryJitter
81
+ };
82
+ break;
83
+ default: assertNever(conf.retryBackoffAlgorithm);
84
+ }
85
+ }
86
+ get txCommittedStat() {
87
+ return { ...this._txCommittedStat };
88
+ }
89
+ get txConflictStat() {
90
+ return { ...this._txConflictStat };
91
+ }
92
+ get txErrorStat() {
93
+ return { ...this._txErrorStat };
94
+ }
95
+ get txTotalStat() {
96
+ return addStat(addStat(this._txCommittedStat, this._txConflictStat), this._txErrorStat);
97
+ }
98
+ get allTxStat() {
99
+ return {
100
+ committed: this.txCommittedStat,
101
+ conflict: this.txConflictStat,
102
+ error: this.txErrorStat
103
+ };
104
+ }
105
+ async ping() {
106
+ return await this.ll.ping();
107
+ }
108
+ async license() {
109
+ return await this.ll.license();
110
+ }
111
+ get conf() {
112
+ return this.ll.conf;
113
+ }
114
+ get httpDispatcher() {
115
+ return this.ll.httpDispatcher;
116
+ }
117
+ get connectionOpts() {
118
+ return this.ll.wireConnection;
119
+ }
120
+ get initialized() {
121
+ return !isNullResourceId(this._clientRoot);
122
+ }
123
+ checkInitialized() {
124
+ if (!this.initialized) throw new Error("Client not initialized");
125
+ }
126
+ get clientRoot() {
127
+ this.checkInitialized();
128
+ return ensureResourceIdNotNull(this._clientRoot);
129
+ }
130
+ get serverInfo() {
131
+ this.checkInitialized();
132
+ return this._serverInfo;
133
+ }
134
+ /** Currently implements custom logic to emulate future behaviour with single root. */
135
+ async init() {
136
+ if (this.initialized) throw new Error("Already initialized");
137
+ this._ll = await this.buildLLPlClient(false);
138
+ const wireProtocol = this._ll.wireProtocol;
139
+ const user = this._ll.authUser;
140
+ const mainRootName = user === null ? AnonymousClientRoot : createHash("sha256").update(user).digest("hex");
141
+ this._serverInfo = await this.ping();
142
+ if (this._serverInfo.compression === MaintenanceAPI_Ping_Response_Compression.GZIP) {
143
+ await this._ll.close();
144
+ this._ll = await this.buildLLPlClient(true, wireProtocol);
145
+ }
146
+ this._clientRoot = await this._withTx("initialization", true, NullResourceId, async (tx) => {
147
+ let mainRoot;
148
+ if (await tx.checkResourceNameExists(mainRootName)) mainRoot = await tx.getResourceByName(mainRootName);
149
+ else {
150
+ mainRoot = tx.createRoot(ClientRoot);
151
+ tx.setResourceName(mainRootName, mainRoot);
152
+ }
153
+ if (this.conf.alternativeRoot === void 0) {
154
+ await tx.commit();
155
+ return await toGlobalResourceId(mainRoot);
156
+ } else {
157
+ const aFId = {
158
+ resourceId: mainRoot,
159
+ fieldName: alternativeRootFieldName(this.conf.alternativeRoot)
160
+ };
161
+ const altRoot = tx.createEphemeral(ClientRoot);
162
+ tx.lock(altRoot);
163
+ tx.createField(aFId, "Dynamic");
164
+ tx.setField(aFId, altRoot);
165
+ await tx.commit();
166
+ return await altRoot.globalId;
167
+ }
168
+ });
169
+ }
170
+ /** Returns true if field existed */
171
+ async deleteAlternativeRoot(alternativeRootName) {
172
+ this.checkInitialized();
173
+ if (this.ll.conf.alternativeRoot !== void 0) throw new Error("Initialized with alternative root.");
174
+ return await this.withWriteTx("delete-alternative-root", async (tx) => {
175
+ const fId = {
176
+ resourceId: tx.clientRoot,
177
+ fieldName: alternativeRootFieldName(alternativeRootName)
178
+ };
179
+ const exists = tx.fieldExists(fId);
180
+ tx.removeField(fId);
181
+ await tx.commit();
182
+ return await exists;
183
+ });
184
+ }
185
+ async _withTx(name, writable, clientRoot, body, ops) {
186
+ let retryState = createRetryState(ops?.retryOptions ?? this.defaultRetryOptions);
187
+ while (true) {
188
+ const release = ops?.lockId ? await advisoryLock(ops.lockId) : () => {};
189
+ try {
190
+ const tx = new PlTransaction(this.ll.createTx(writable, ops), name, writable, clientRoot, this.finalPredicate, this.resourceDataCache);
191
+ let ok = false;
192
+ let result = void 0;
193
+ let txId;
194
+ try {
195
+ result = await body(tx);
196
+ this._txCommittedStat = addStat(this._txCommittedStat, tx.stat);
197
+ ok = true;
198
+ } catch (e) {
199
+ if (e instanceof TxCommitConflict) this._txConflictStat = addStat(this._txConflictStat, tx.stat);
200
+ else {
201
+ this._txErrorStat = addStat(this._txErrorStat, tx.stat);
202
+ throw e;
203
+ }
204
+ } finally {
205
+ await tx.complete();
206
+ await tx.await();
207
+ txId = await tx.getGlobalTxId();
208
+ }
209
+ if (ok) {
210
+ if (ops?.sync === void 0 ? this.forceSync : ops?.sync) await this.ll.txSync(txId);
211
+ if (writable && this.txDelay > 0) await tp.setTimeout(this.txDelay, void 0, { signal: ops?.abortSignal });
212
+ return result;
213
+ }
214
+ } finally {
215
+ release();
216
+ }
217
+ await tp.setTimeout(retryState.nextDelay, void 0, { signal: ops?.abortSignal });
218
+ retryState = nextRetryStateOrError(retryState);
219
+ }
220
+ }
221
+ async withTx(name, writable, body, ops = {}) {
222
+ this.checkInitialized();
223
+ return await this._withTx(name, writable, this.clientRoot, body, {
224
+ ...ops,
225
+ ...defaultTxOps
226
+ });
227
+ }
228
+ async withWriteTx(name, body, ops = {}) {
229
+ return await this.withTx(name, true, body, {
230
+ ...ops,
231
+ ...defaultTxOps
232
+ });
233
+ }
234
+ async withReadTx(name, body, ops = {}) {
235
+ return await this.withTx(name, false, body, {
236
+ ...ops,
237
+ ...defaultTxOps
238
+ });
239
+ }
240
+ getDriver(definition) {
241
+ const attached = this.drivers.get(definition.name);
242
+ if (attached !== void 0) return attached;
243
+ const driver = definition.init(this, this.ll, this.httpDispatcher);
244
+ this.drivers.set(definition.name, driver);
245
+ return driver;
246
+ }
247
+ /** Closes underlying transport */
248
+ async close() {
249
+ await this.ll.close();
250
+ }
251
+ static async init(configOrAddress, auth, ops = {}) {
252
+ const pl = new PlClient(configOrAddress, auth, ops);
253
+ await pl.init();
254
+ return pl;
255
+ }
256
+ };
290
257
 
258
+ //#endregion
291
259
  export { PlClient };
292
- //# sourceMappingURL=client.js.map
260
+ //# sourceMappingURL=client.js.map