@milaboratories/pl-client 2.17.7 → 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.
- package/dist/_virtual/_rolldown/runtime.cjs +43 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/core/PromiseTracker.cjs +33 -33
- package/dist/core/PromiseTracker.cjs.map +1 -1
- package/dist/core/PromiseTracker.d.ts +10 -7
- package/dist/core/PromiseTracker.js +33 -31
- package/dist/core/PromiseTracker.js.map +1 -1
- package/dist/core/StatefulPromise.cjs +60 -61
- package/dist/core/StatefulPromise.cjs.map +1 -1
- package/dist/core/StatefulPromise.js +60 -60
- package/dist/core/StatefulPromise.js.map +1 -1
- package/dist/core/abstract_stream.d.ts +18 -15
- package/dist/core/advisory_locks.cjs +42 -49
- package/dist/core/advisory_locks.cjs.map +1 -1
- package/dist/core/advisory_locks.js +42 -48
- package/dist/core/advisory_locks.js.map +1 -1
- package/dist/core/auth.cjs +10 -15
- package/dist/core/auth.cjs.map +1 -1
- package/dist/core/auth.d.ts +7 -3
- package/dist/core/auth.js +10 -13
- package/dist/core/auth.js.map +1 -1
- package/dist/core/cache.d.ts +11 -7
- package/dist/core/client.cjs +255 -306
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +72 -68
- package/dist/core/client.js +253 -285
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.cjs +81 -99
- package/dist/core/config.cjs.map +1 -1
- package/dist/core/config.d.ts +93 -90
- package/dist/core/config.js +81 -98
- package/dist/core/config.js.map +1 -1
- package/dist/core/default_client.cjs +84 -125
- package/dist/core/default_client.cjs.map +1 -1
- package/dist/core/default_client.d.ts +9 -6
- package/dist/core/default_client.js +78 -103
- package/dist/core/default_client.js.map +1 -1
- package/dist/core/driver.cjs +12 -16
- package/dist/core/driver.cjs.map +1 -1
- package/dist/core/driver.d.ts +18 -14
- package/dist/core/driver.js +12 -15
- package/dist/core/driver.js.map +1 -1
- package/dist/core/error_resource.cjs +5 -4
- package/dist/core/error_resource.cjs.map +1 -1
- package/dist/core/error_resource.js +5 -3
- package/dist/core/error_resource.js.map +1 -1
- package/dist/core/errors.cjs +104 -140
- package/dist/core/errors.cjs.map +1 -1
- package/dist/core/errors.d.ts +34 -30
- package/dist/core/errors.js +102 -137
- package/dist/core/errors.js.map +1 -1
- package/dist/core/final.cjs +63 -89
- package/dist/core/final.cjs.map +1 -1
- package/dist/core/final.d.ts +8 -4
- package/dist/core/final.js +63 -87
- package/dist/core/final.js.map +1 -1
- package/dist/core/ll_client.cjs +416 -521
- package/dist/core/ll_client.cjs.map +1 -1
- package/dist/core/ll_client.d.ts +100 -97
- package/dist/core/ll_client.js +415 -519
- package/dist/core/ll_client.js.map +1 -1
- package/dist/core/ll_transaction.cjs +206 -240
- package/dist/core/ll_transaction.cjs.map +1 -1
- package/dist/core/ll_transaction.d.ts +50 -52
- package/dist/core/ll_transaction.js +205 -238
- package/dist/core/ll_transaction.js.map +1 -1
- package/dist/core/stat.cjs +64 -63
- package/dist/core/stat.cjs.map +1 -1
- package/dist/core/stat.d.ts +35 -36
- package/dist/core/stat.js +64 -62
- package/dist/core/stat.js.map +1 -1
- package/dist/core/transaction.cjs +613 -650
- package/dist/core/transaction.cjs.map +1 -1
- package/dist/core/transaction.d.ts +165 -162
- package/dist/core/transaction.js +612 -648
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/type_conversion.cjs +62 -83
- package/dist/core/type_conversion.cjs.map +1 -1
- package/dist/core/type_conversion.js +61 -81
- package/dist/core/type_conversion.js.map +1 -1
- package/dist/core/types.cjs +56 -86
- package/dist/core/types.cjs.map +1 -1
- package/dist/core/types.d.ts +63 -62
- package/dist/core/types.js +54 -83
- package/dist/core/types.js.map +1 -1
- package/dist/core/unauth_client.cjs +35 -41
- package/dist/core/unauth_client.cjs.map +1 -1
- package/dist/core/unauth_client.d.ts +18 -14
- package/dist/core/unauth_client.js +34 -39
- package/dist/core/unauth_client.js.map +1 -1
- package/dist/core/websocket_stream.cjs +277 -349
- package/dist/core/websocket_stream.cjs.map +1 -1
- package/dist/core/websocket_stream.js +275 -347
- package/dist/core/websocket_stream.js.map +1 -1
- package/dist/core/wire.d.ts +21 -17
- package/dist/helpers/pl.cjs +71 -73
- package/dist/helpers/pl.cjs.map +1 -1
- package/dist/helpers/pl.d.ts +40 -41
- package/dist/helpers/pl.js +66 -46
- package/dist/helpers/pl.js.map +1 -1
- package/dist/helpers/poll.cjs +99 -134
- package/dist/helpers/poll.cjs.map +1 -1
- package/dist/helpers/poll.d.ts +37 -34
- package/dist/helpers/poll.js +97 -113
- package/dist/helpers/poll.js.map +1 -1
- package/dist/helpers/retry_strategy.cjs +82 -87
- package/dist/helpers/retry_strategy.cjs.map +1 -1
- package/dist/helpers/retry_strategy.js +83 -86
- package/dist/helpers/retry_strategy.js.map +1 -1
- package/dist/helpers/tx_helpers.cjs +21 -20
- package/dist/helpers/tx_helpers.cjs.map +1 -1
- package/dist/helpers/tx_helpers.d.ts +11 -7
- package/dist/helpers/tx_helpers.js +20 -18
- package/dist/helpers/tx_helpers.js.map +1 -1
- package/dist/index.cjs +117 -106
- package/dist/index.d.ts +17 -17
- package/dist/index.js +17 -19
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs +72 -66
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts +35 -37
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js +71 -64
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12611 -12866
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +226 -226
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +281 -330
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +225 -224
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +2640 -4294
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js +12608 -12706
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1230 -1089
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +393 -420
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1228 -1083
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +142 -143
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +62 -64
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +140 -141
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +572 -487
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +125 -228
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +572 -485
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.cjs +131 -146
- package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts +78 -84
- package/dist/proto-grpc/google/protobuf/any.js +130 -144
- package/dist/proto-grpc/google/protobuf/any.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
- package/dist/proto-grpc/google/protobuf/duration.js +91 -98
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
- package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
- package/dist/proto-grpc/google/rpc/code.cjs +223 -238
- package/dist/proto-grpc/google/rpc/code.cjs.map +1 -1
- package/dist/proto-grpc/google/rpc/code.d.ts +209 -206
- package/dist/proto-grpc/google/rpc/code.js +221 -237
- package/dist/proto-grpc/google/rpc/code.js.map +1 -1
- package/dist/proto-rest/index.cjs +67 -66
- package/dist/proto-rest/index.cjs.map +1 -1
- package/dist/proto-rest/index.d.ts +24 -18
- package/dist/proto-rest/index.js +61 -65
- package/dist/proto-rest/index.js.map +1 -1
- package/dist/proto-rest/plapi.d.ts +1400 -1477
- package/dist/test/tcp-proxy.cjs +100 -126
- package/dist/test/tcp-proxy.cjs.map +1 -1
- package/dist/test/tcp-proxy.d.ts +17 -13
- package/dist/test/tcp-proxy.js +97 -104
- package/dist/test/tcp-proxy.js.map +1 -1
- package/dist/test/test_config.cjs +145 -194
- package/dist/test/test_config.cjs.map +1 -1
- package/dist/test/test_config.d.ts +34 -30
- package/dist/test/test_config.js +138 -166
- package/dist/test/test_config.js.map +1 -1
- package/dist/util/pl.cjs +4 -3
- package/dist/util/pl.cjs.map +1 -1
- package/dist/util/pl.js +4 -2
- package/dist/util/pl.js.map +1 -1
- package/dist/util/util.cjs +7 -10
- package/dist/util/util.cjs.map +1 -1
- package/dist/util/util.js +7 -9
- package/dist/util/util.js.map +1 -1
- package/package.json +8 -8
- package/src/core/transaction.ts +123 -133
- 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
- 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
- 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
- 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
- package/dist/core/PromiseTracker.d.ts.map +0 -1
- package/dist/core/StatefulPromise.d.ts +0 -39
- package/dist/core/StatefulPromise.d.ts.map +0 -1
- package/dist/core/abstract_stream.d.ts.map +0 -1
- package/dist/core/advisory_locks.d.ts +0 -10
- package/dist/core/advisory_locks.d.ts.map +0 -1
- package/dist/core/auth.d.ts.map +0 -1
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/default_client.d.ts.map +0 -1
- package/dist/core/driver.d.ts.map +0 -1
- package/dist/core/error_resource.d.ts +0 -6
- package/dist/core/error_resource.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/final.d.ts.map +0 -1
- package/dist/core/ll_client.d.ts.map +0 -1
- package/dist/core/ll_transaction.d.ts.map +0 -1
- package/dist/core/stat.d.ts.map +0 -1
- package/dist/core/transaction.d.ts.map +0 -1
- package/dist/core/type_conversion.d.ts +0 -8
- package/dist/core/type_conversion.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/unauth_client.d.ts.map +0 -1
- package/dist/core/websocket_stream.d.ts +0 -67
- package/dist/core/websocket_stream.d.ts.map +0 -1
- package/dist/core/wire.d.ts.map +0 -1
- package/dist/helpers/pl.d.ts.map +0 -1
- package/dist/helpers/poll.d.ts.map +0 -1
- package/dist/helpers/retry_strategy.d.ts +0 -24
- package/dist/helpers/retry_strategy.d.ts.map +0 -1
- package/dist/helpers/state_helpers.d.ts +0 -3
- package/dist/helpers/state_helpers.d.ts.map +0 -1
- package/dist/helpers/tx_helpers.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
- package/dist/proto-grpc/google/api/http.d.ts +0 -456
- package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
- package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
- package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
- package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
- package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
- package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-rest/index.d.ts.map +0 -1
- package/dist/proto-rest/plapi.d.ts.map +0 -1
- package/dist/test/tcp-proxy.d.ts.map +0 -1
- package/dist/test/test_config.d.ts.map +0 -1
- package/dist/util/branding.d.ts +0 -7
- package/dist/util/branding.d.ts.map +0 -1
- package/dist/util/pl.d.ts +0 -9
- package/dist/util/pl.d.ts.map +0 -1
- package/dist/util/util.d.ts +0 -2
- package/dist/util/util.d.ts.map +0 -1
package/dist/core/client.js
CHANGED
|
@@ -1,292 +1,260 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ClientRoot } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
15
|
+
//#region src/core/client.ts
|
|
16
|
+
const defaultTxOps = { sync: false };
|
|
18
17
|
const AnonymousClientRoot = "AnonymousRoot";
|
|
19
18
|
function alternativeRootFieldName(alternativeRoot) {
|
|
20
|
-
|
|
19
|
+
return `alternative_root_${alternativeRoot}`;
|
|
21
20
|
}
|
|
22
21
|
/** Client to access core PL API. */
|
|
23
|
-
class PlClient {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|