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