@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.
- 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 +280 -349
- package/dist/core/websocket_stream.cjs.map +1 -1
- package/dist/core/websocket_stream.js +278 -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/errors.ts +1 -1
- package/src/core/transaction.ts +123 -133
- package/src/core/websocket_stream.ts +10 -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.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/transaction.js
CHANGED
|
@@ -1,675 +1,639 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { PromiseTracker } from './PromiseTracker.js';
|
|
1
|
+
import { MaxTxId, createLocalResourceId, ensureResourceIdNotNull, extractBasicResourceData, isLocalResourceId, isNullResourceId } from "./types.js";
|
|
2
|
+
import { TxAPI_Open_Request_WritableTx } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js";
|
|
3
|
+
import { toBytes } from "../util/util.js";
|
|
4
|
+
import { isNotFoundError } from "./errors.js";
|
|
5
|
+
import { fieldTypeToProto, protoToField, protoToResource } from "./type_conversion.js";
|
|
6
|
+
import { initialTxStatWithoutTime } from "./stat.js";
|
|
7
|
+
import { ErrorResourceType } from "./error_resource.js";
|
|
8
|
+
import { PromiseTracker } from "./PromiseTracker.js";
|
|
9
|
+
import { JsonGzObject, JsonObject } from "../helpers/pl.js";
|
|
10
|
+
import { canonicalJsonBytes, canonicalJsonGzBytes, deepFreeze, notEmpty } from "@milaboratories/ts-helpers";
|
|
12
11
|
|
|
12
|
+
//#region src/core/transaction.ts
|
|
13
13
|
function isField(ref) {
|
|
14
|
-
|
|
14
|
+
return ref.hasOwnProperty("resourceId") && ref.hasOwnProperty("fieldName");
|
|
15
15
|
}
|
|
16
16
|
function isResource(ref) {
|
|
17
|
-
|
|
17
|
+
return typeof ref === "bigint" || ref.hasOwnProperty("globalId") && ref.hasOwnProperty("localId");
|
|
18
18
|
}
|
|
19
19
|
function isResourceId(ref) {
|
|
20
|
-
|
|
20
|
+
return typeof ref === "bigint" && !isLocalResourceId(ref) && !isNullResourceId(ref);
|
|
21
21
|
}
|
|
22
22
|
function isFieldRef(ref) {
|
|
23
|
-
|
|
23
|
+
return isResourceRef(ref.resourceId);
|
|
24
24
|
}
|
|
25
25
|
function isResourceRef(ref) {
|
|
26
|
-
|
|
26
|
+
return ref.hasOwnProperty("globalId") && ref.hasOwnProperty("localId");
|
|
27
27
|
}
|
|
28
28
|
function toFieldId(ref) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (isFieldRef(ref)) return {
|
|
30
|
+
resourceId: ref.resourceId.localId,
|
|
31
|
+
fieldName: ref.fieldName
|
|
32
|
+
};
|
|
33
|
+
else return ref;
|
|
33
34
|
}
|
|
34
35
|
async function toGlobalFieldId(ref) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (isFieldRef(ref)) return {
|
|
37
|
+
resourceId: await ref.resourceId.globalId,
|
|
38
|
+
fieldName: ref.fieldName
|
|
39
|
+
};
|
|
40
|
+
else return ref;
|
|
39
41
|
}
|
|
40
42
|
function toResourceId(ref) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
else
|
|
44
|
-
return ref;
|
|
43
|
+
if (isResourceRef(ref)) return ref.localId;
|
|
44
|
+
else return ref;
|
|
45
45
|
}
|
|
46
46
|
async function toGlobalResourceId(ref) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
return ref;
|
|
47
|
+
if (isResourceRef(ref)) return await ref.globalId;
|
|
48
|
+
else return ref;
|
|
51
49
|
}
|
|
52
50
|
function field(resourceId, fieldName) {
|
|
53
|
-
|
|
51
|
+
return {
|
|
52
|
+
resourceId,
|
|
53
|
+
fieldName
|
|
54
|
+
};
|
|
54
55
|
}
|
|
55
56
|
/** If transaction commit failed due to write conflicts */
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
57
|
+
var TxCommitConflict = class extends Error {
|
|
58
|
+
name = "TxCommitConflict";
|
|
59
|
+
};
|
|
59
60
|
async function notFoundToUndefined(cb) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw e;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Decorator that wraps the method's returned promise with this.track()
|
|
71
|
-
* This ensures that the promise will be awaited before the transaction is completed.
|
|
72
|
-
*/
|
|
73
|
-
function tracked(value, _context) {
|
|
74
|
-
return function (...args) {
|
|
75
|
-
return this.track(value.apply(this, args));
|
|
76
|
-
};
|
|
61
|
+
try {
|
|
62
|
+
return await cb();
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (isNotFoundError(e)) return void 0;
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
77
67
|
}
|
|
78
68
|
/**
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
if (this._completed)
|
|
647
|
-
return;
|
|
648
|
-
this._completed = true;
|
|
649
|
-
const completeResult = this.track(this.ll.complete());
|
|
650
|
-
await this.drainAndAwaitPendingOps();
|
|
651
|
-
await completeResult;
|
|
652
|
-
}
|
|
653
|
-
/** Await incoming message loop termination and throw
|
|
654
|
-
* any leftover errors if it was unsuccessful */
|
|
655
|
-
async await() {
|
|
656
|
-
await this.ll.await();
|
|
657
|
-
}
|
|
658
|
-
//
|
|
659
|
-
// Helpers
|
|
660
|
-
//
|
|
661
|
-
nextLocalResourceId(root) {
|
|
662
|
-
return createLocalResourceId(root, ++this.localResourceIdCounter, this.localTxId);
|
|
663
|
-
}
|
|
664
|
-
static localTxIdCounter = 0;
|
|
665
|
-
static nextLocalTxId() {
|
|
666
|
-
PlTransaction.localTxIdCounter++;
|
|
667
|
-
if (PlTransaction.localTxIdCounter === MaxTxId)
|
|
668
|
-
PlTransaction.localTxIdCounter = 1;
|
|
669
|
-
return PlTransaction.localTxIdCounter;
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
})();
|
|
69
|
+
* Each platform transaction has 3 stages:
|
|
70
|
+
* - initialization (txOpen message -> txInfo response)
|
|
71
|
+
* - communication (create resources, fields, references and so on)
|
|
72
|
+
* - finalization (txCommit or txDiscard message)
|
|
73
|
+
*
|
|
74
|
+
* This class encapsulates finalization stage and provides ready-to-communication transaction object.
|
|
75
|
+
* */
|
|
76
|
+
var PlTransaction = class PlTransaction {
|
|
77
|
+
globalTxId;
|
|
78
|
+
localTxId = PlTransaction.nextLocalTxId();
|
|
79
|
+
/** Used in caching */
|
|
80
|
+
txOpenTimestamp = Date.now();
|
|
81
|
+
localResourceIdCounter = 0;
|
|
82
|
+
/** Store logical tx open / closed state to prevent invalid sequence of requests.
|
|
83
|
+
* True means output stream was completed.
|
|
84
|
+
* Contract: there must be no async operations between setting this field to true and sending complete signal to stream. */
|
|
85
|
+
_completed = false;
|
|
86
|
+
globalTxIdWasAwaited = false;
|
|
87
|
+
pending = new PromiseTracker();
|
|
88
|
+
_startTime = Date.now();
|
|
89
|
+
_stat = initialTxStatWithoutTime();
|
|
90
|
+
get stat() {
|
|
91
|
+
return {
|
|
92
|
+
...this._stat,
|
|
93
|
+
timeMs: Date.now() - this._startTime
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
constructor(ll, name, writable, _clientRoot, finalPredicate, sharedResourceDataCache, enableFormattedErrors = false) {
|
|
97
|
+
this.ll = ll;
|
|
98
|
+
this.name = name;
|
|
99
|
+
this.writable = writable;
|
|
100
|
+
this._clientRoot = _clientRoot;
|
|
101
|
+
this.finalPredicate = finalPredicate;
|
|
102
|
+
this.sharedResourceDataCache = sharedResourceDataCache;
|
|
103
|
+
this.enableFormattedErrors = enableFormattedErrors;
|
|
104
|
+
this.globalTxId = this.sendSingleAndParse({
|
|
105
|
+
oneofKind: "txOpen",
|
|
106
|
+
txOpen: {
|
|
107
|
+
name,
|
|
108
|
+
enableFormattedErrors,
|
|
109
|
+
writable: writable ? TxAPI_Open_Request_WritableTx.WRITABLE : TxAPI_Open_Request_WritableTx.NOT_WRITABLE
|
|
110
|
+
}
|
|
111
|
+
}, (r) => notEmpty(r.txOpen.tx?.id));
|
|
112
|
+
this.track(this.globalTxId);
|
|
113
|
+
this.globalTxId.catch((err) => {
|
|
114
|
+
if (!this.globalTxIdWasAwaited) console.warn(err);
|
|
115
|
+
});
|
|
116
|
+
this._stat.txCount++;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Collect all pending promises for the transaction finalization.
|
|
120
|
+
*/
|
|
121
|
+
track(promiseOrCallback) {
|
|
122
|
+
return this.pending.track(promiseOrCallback);
|
|
123
|
+
}
|
|
124
|
+
async drainAndAwaitPendingOps() {
|
|
125
|
+
await this.pending.awaitAll();
|
|
126
|
+
}
|
|
127
|
+
sendSingleAndParse(r, parser) {
|
|
128
|
+
return this.pending.track(async () => {
|
|
129
|
+
const rawResponsePromise = this.ll.send(r, false);
|
|
130
|
+
this.pending.track(rawResponsePromise);
|
|
131
|
+
await this.drainAndAwaitPendingOps();
|
|
132
|
+
return parser(await rawResponsePromise);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
sendMultiAndParse(r, parser) {
|
|
136
|
+
return this.pending.track(async () => {
|
|
137
|
+
const rawResponsePromise = this.ll.send(r, true);
|
|
138
|
+
this.pending.track(rawResponsePromise);
|
|
139
|
+
await this.drainAndAwaitPendingOps();
|
|
140
|
+
return parser(await rawResponsePromise);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async sendVoidSync(r) {
|
|
144
|
+
await this.ll.send(r, false);
|
|
145
|
+
}
|
|
146
|
+
/** Requests sent with this method should never produce recoverable errors */
|
|
147
|
+
sendVoidAsync(r) {
|
|
148
|
+
this.track(this.sendVoidSync(r));
|
|
149
|
+
}
|
|
150
|
+
checkTxOpen() {
|
|
151
|
+
if (this._completed) throw new Error("Transaction already closed");
|
|
152
|
+
}
|
|
153
|
+
get completed() {
|
|
154
|
+
return this._completed;
|
|
155
|
+
}
|
|
156
|
+
/** Commit & closes transaction. {@link TxCommitConflict} is thrown on
|
|
157
|
+
* commit conflicts. */
|
|
158
|
+
async commit() {
|
|
159
|
+
this.checkTxOpen();
|
|
160
|
+
this._completed = true;
|
|
161
|
+
if (!this.writable) {
|
|
162
|
+
const completeResult = this.track(this.ll.complete());
|
|
163
|
+
await this.drainAndAwaitPendingOps();
|
|
164
|
+
await completeResult;
|
|
165
|
+
await this.ll.await();
|
|
166
|
+
} else {
|
|
167
|
+
const commitResponse = this.track(this.sendSingleAndParse({
|
|
168
|
+
oneofKind: "txCommit",
|
|
169
|
+
txCommit: {}
|
|
170
|
+
}, (r) => r.txCommit.success));
|
|
171
|
+
const completeResult = this.track(this.ll.complete());
|
|
172
|
+
await this.drainAndAwaitPendingOps();
|
|
173
|
+
if (!await commitResponse) throw new TxCommitConflict();
|
|
174
|
+
await completeResult;
|
|
175
|
+
await this.ll.await();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async discard() {
|
|
179
|
+
this.checkTxOpen();
|
|
180
|
+
this._completed = true;
|
|
181
|
+
const discardResponse = this.sendVoidSync({
|
|
182
|
+
oneofKind: "txDiscard",
|
|
183
|
+
txDiscard: {}
|
|
184
|
+
});
|
|
185
|
+
this.track(discardResponse);
|
|
186
|
+
const completeResult = this.track(this.ll.complete());
|
|
187
|
+
await this.drainAndAwaitPendingOps();
|
|
188
|
+
await discardResponse;
|
|
189
|
+
await completeResult;
|
|
190
|
+
await this.ll.await();
|
|
191
|
+
}
|
|
192
|
+
get clientRoot() {
|
|
193
|
+
return ensureResourceIdNotNull(this._clientRoot);
|
|
194
|
+
}
|
|
195
|
+
createSingleton(name, type, errorIfExists = false) {
|
|
196
|
+
const localId = this.nextLocalResourceId(false);
|
|
197
|
+
const globalId = this.sendSingleAndParse({
|
|
198
|
+
oneofKind: "resourceCreateSingleton",
|
|
199
|
+
resourceCreateSingleton: {
|
|
200
|
+
type,
|
|
201
|
+
id: localId,
|
|
202
|
+
data: Buffer.from(name),
|
|
203
|
+
errorIfExists
|
|
204
|
+
}
|
|
205
|
+
}, (r) => r.resourceCreateSingleton.resourceId);
|
|
206
|
+
this.track(globalId);
|
|
207
|
+
return {
|
|
208
|
+
globalId,
|
|
209
|
+
localId
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
getSingleton(name, loadFields = true) {
|
|
213
|
+
return this.sendSingleAndParse({
|
|
214
|
+
oneofKind: "resourceGetSingleton",
|
|
215
|
+
resourceGetSingleton: {
|
|
216
|
+
data: Buffer.from(name),
|
|
217
|
+
loadFields
|
|
218
|
+
}
|
|
219
|
+
}, (r) => protoToResource(notEmpty(r.resourceGetSingleton.resource)));
|
|
220
|
+
}
|
|
221
|
+
createResource(root, req, parser) {
|
|
222
|
+
const localId = this.nextLocalResourceId(root);
|
|
223
|
+
const globalId = this.sendSingleAndParse(req(localId), (r) => parser(r));
|
|
224
|
+
this.track(globalId);
|
|
225
|
+
return {
|
|
226
|
+
globalId,
|
|
227
|
+
localId
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
createRoot(type) {
|
|
231
|
+
this._stat.rootsCreated++;
|
|
232
|
+
return this.createResource(true, (localId) => ({
|
|
233
|
+
oneofKind: "resourceCreateRoot",
|
|
234
|
+
resourceCreateRoot: {
|
|
235
|
+
type,
|
|
236
|
+
id: localId
|
|
237
|
+
}
|
|
238
|
+
}), (r) => r.resourceCreateRoot.resourceId);
|
|
239
|
+
}
|
|
240
|
+
createStruct(type, data) {
|
|
241
|
+
this._stat.structsCreated++;
|
|
242
|
+
this._stat.structsCreatedDataBytes += data?.length ?? 0;
|
|
243
|
+
return this.createResource(false, (localId) => ({
|
|
244
|
+
oneofKind: "resourceCreateStruct",
|
|
245
|
+
resourceCreateStruct: {
|
|
246
|
+
type,
|
|
247
|
+
id: localId,
|
|
248
|
+
data: data === void 0 ? void 0 : typeof data === "string" ? Buffer.from(data) : data
|
|
249
|
+
}
|
|
250
|
+
}), (r) => r.resourceCreateStruct.resourceId);
|
|
251
|
+
}
|
|
252
|
+
createEphemeral(type, data) {
|
|
253
|
+
this._stat.ephemeralsCreated++;
|
|
254
|
+
this._stat.ephemeralsCreatedDataBytes += data?.length ?? 0;
|
|
255
|
+
return this.createResource(false, (localId) => ({
|
|
256
|
+
oneofKind: "resourceCreateEphemeral",
|
|
257
|
+
resourceCreateEphemeral: {
|
|
258
|
+
type,
|
|
259
|
+
id: localId,
|
|
260
|
+
data: data === void 0 ? void 0 : typeof data === "string" ? Buffer.from(data) : data
|
|
261
|
+
}
|
|
262
|
+
}), (r) => r.resourceCreateEphemeral.resourceId);
|
|
263
|
+
}
|
|
264
|
+
createValue(type, data, errorIfExists = false) {
|
|
265
|
+
this._stat.valuesCreated++;
|
|
266
|
+
this._stat.valuesCreatedDataBytes += data?.length ?? 0;
|
|
267
|
+
return this.createResource(false, (localId) => ({
|
|
268
|
+
oneofKind: "resourceCreateValue",
|
|
269
|
+
resourceCreateValue: {
|
|
270
|
+
type,
|
|
271
|
+
id: localId,
|
|
272
|
+
data: typeof data === "string" ? Buffer.from(data) : data,
|
|
273
|
+
errorIfExists
|
|
274
|
+
}
|
|
275
|
+
}), (r) => r.resourceCreateValue.resourceId);
|
|
276
|
+
}
|
|
277
|
+
createJsonValue(data) {
|
|
278
|
+
const jsonData = canonicalJsonBytes(data);
|
|
279
|
+
return this.createValue(JsonObject, jsonData, false);
|
|
280
|
+
}
|
|
281
|
+
createJsonGzValue(data, minSizeToGzip = 16384) {
|
|
282
|
+
const { data: jsonData, isGzipped } = canonicalJsonGzBytes(data, minSizeToGzip);
|
|
283
|
+
return this.createValue(isGzipped ? JsonGzObject : JsonObject, jsonData, false);
|
|
284
|
+
}
|
|
285
|
+
createError(message) {
|
|
286
|
+
return this.createValue(ErrorResourceType, JSON.stringify({ message }));
|
|
287
|
+
}
|
|
288
|
+
setResourceName(name, rId) {
|
|
289
|
+
this.sendVoidAsync({
|
|
290
|
+
oneofKind: "resourceNameSet",
|
|
291
|
+
resourceNameSet: {
|
|
292
|
+
resourceId: toResourceId(rId),
|
|
293
|
+
name
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
deleteResourceName(name) {
|
|
298
|
+
this.sendVoidAsync({
|
|
299
|
+
oneofKind: "resourceNameDelete",
|
|
300
|
+
resourceNameDelete: { name }
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
getResourceByName(name) {
|
|
304
|
+
return this.sendSingleAndParse({
|
|
305
|
+
oneofKind: "resourceNameGet",
|
|
306
|
+
resourceNameGet: { name }
|
|
307
|
+
}, (r) => ensureResourceIdNotNull(r.resourceNameGet.resourceId));
|
|
308
|
+
}
|
|
309
|
+
checkResourceNameExists(name) {
|
|
310
|
+
return this.sendSingleAndParse({
|
|
311
|
+
oneofKind: "resourceNameExists",
|
|
312
|
+
resourceNameExists: { name }
|
|
313
|
+
}, (r) => r.resourceNameExists.exists);
|
|
314
|
+
}
|
|
315
|
+
removeResource(rId) {
|
|
316
|
+
this.sendVoidAsync({
|
|
317
|
+
oneofKind: "resourceRemove",
|
|
318
|
+
resourceRemove: { id: rId }
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
resourceExists(rId) {
|
|
322
|
+
return this.sendSingleAndParse({
|
|
323
|
+
oneofKind: "resourceExists",
|
|
324
|
+
resourceExists: { resourceId: rId }
|
|
325
|
+
}, (r) => r.resourceExists.exists);
|
|
326
|
+
}
|
|
327
|
+
async getResourceData(rId, loadFields = true, ignoreCache = false) {
|
|
328
|
+
return this.track(async () => {
|
|
329
|
+
if (!ignoreCache && !isResourceRef(rId) && !isLocalResourceId(rId)) {
|
|
330
|
+
const fromCache = this.sharedResourceDataCache.get(rId);
|
|
331
|
+
if (fromCache && fromCache.cacheTxOpenTimestamp < this.txOpenTimestamp) {
|
|
332
|
+
if (!loadFields) {
|
|
333
|
+
this._stat.rGetDataCacheHits++;
|
|
334
|
+
this._stat.rGetDataCacheBytes += fromCache.basicData.data?.length ?? 0;
|
|
335
|
+
return fromCache.basicData;
|
|
336
|
+
} else if (fromCache.data) {
|
|
337
|
+
this._stat.rGetDataCacheHits++;
|
|
338
|
+
this._stat.rGetDataCacheBytes += fromCache.basicData.data?.length ?? 0;
|
|
339
|
+
this._stat.rGetDataCacheFields += fromCache.data.fields.length;
|
|
340
|
+
return fromCache.data;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const result = await this.sendSingleAndParse({
|
|
345
|
+
oneofKind: "resourceGet",
|
|
346
|
+
resourceGet: {
|
|
347
|
+
resourceId: toResourceId(rId),
|
|
348
|
+
loadFields
|
|
349
|
+
}
|
|
350
|
+
}, (r) => protoToResource(notEmpty(r.resourceGet.resource)));
|
|
351
|
+
this._stat.rGetDataNetRequests++;
|
|
352
|
+
this._stat.rGetDataNetBytes += result.data?.length ?? 0;
|
|
353
|
+
this._stat.rGetDataNetFields += result.fields.length;
|
|
354
|
+
if (!isResourceRef(rId) && !isLocalResourceId(rId) && this.finalPredicate(result)) {
|
|
355
|
+
deepFreeze(result);
|
|
356
|
+
const fromCache = this.sharedResourceDataCache.get(rId);
|
|
357
|
+
if (fromCache) {
|
|
358
|
+
if (loadFields && !fromCache.data) {
|
|
359
|
+
fromCache.data = result;
|
|
360
|
+
fromCache.cacheTxOpenTimestamp = this.txOpenTimestamp;
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
const basicData = extractBasicResourceData(result);
|
|
364
|
+
deepFreeze(basicData);
|
|
365
|
+
if (loadFields) this.sharedResourceDataCache.set(rId, {
|
|
366
|
+
basicData,
|
|
367
|
+
data: result,
|
|
368
|
+
cacheTxOpenTimestamp: this.txOpenTimestamp
|
|
369
|
+
});
|
|
370
|
+
else this.sharedResourceDataCache.set(rId, {
|
|
371
|
+
basicData,
|
|
372
|
+
data: void 0,
|
|
373
|
+
cacheTxOpenTimestamp: this.txOpenTimestamp
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return result;
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
async getResourceDataIfExists(rId, loadFields = true) {
|
|
381
|
+
return this.track(async () => {
|
|
382
|
+
const result = await notFoundToUndefined(async () => await this.getResourceData(rId, loadFields, true));
|
|
383
|
+
if (result === void 0 && !isResourceRef(rId) && !isLocalResourceId(rId)) this.sharedResourceDataCache.delete(rId);
|
|
384
|
+
return result;
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Inform platform that resource will not get any new input fields.
|
|
389
|
+
* This is required, when client creates resource without schema and wants
|
|
390
|
+
* controller to start calculations.
|
|
391
|
+
* Most controllers will not start calculations even when all inputs
|
|
392
|
+
* have their values, if inputs list is not locked.
|
|
393
|
+
*/
|
|
394
|
+
lockInputs(rId) {
|
|
395
|
+
this._stat.inputsLocked++;
|
|
396
|
+
this.sendVoidAsync({
|
|
397
|
+
oneofKind: "resourceLockInputs",
|
|
398
|
+
resourceLockInputs: { resourceId: toResourceId(rId) }
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Inform platform that resource will not get any new output fields.
|
|
403
|
+
* This is required for resource to pass deduplication.
|
|
404
|
+
*/
|
|
405
|
+
lockOutputs(rId) {
|
|
406
|
+
this._stat.outputsLocked++;
|
|
407
|
+
this.sendVoidAsync({
|
|
408
|
+
oneofKind: "resourceLockOutputs",
|
|
409
|
+
resourceLockOutputs: { resourceId: toResourceId(rId) }
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
lock(rID) {
|
|
413
|
+
this.lockInputs(rID);
|
|
414
|
+
this.lockOutputs(rID);
|
|
415
|
+
}
|
|
416
|
+
setResourceError(rId, ref) {
|
|
417
|
+
this.sendVoidAsync({
|
|
418
|
+
oneofKind: "resourceSetError",
|
|
419
|
+
resourceSetError: {
|
|
420
|
+
resourceId: toResourceId(rId),
|
|
421
|
+
errorResourceId: toResourceId(ref)
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
createField(fId, fieldType, value) {
|
|
426
|
+
this._stat.fieldsCreated++;
|
|
427
|
+
this.sendVoidAsync({
|
|
428
|
+
oneofKind: "fieldCreate",
|
|
429
|
+
fieldCreate: {
|
|
430
|
+
type: fieldTypeToProto(fieldType),
|
|
431
|
+
id: toFieldId(fId)
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
if (value !== void 0) this.setField(fId, value);
|
|
435
|
+
}
|
|
436
|
+
fieldExists(fId) {
|
|
437
|
+
return this.sendSingleAndParse({
|
|
438
|
+
oneofKind: "fieldExists",
|
|
439
|
+
fieldExists: { field: toFieldId(fId) }
|
|
440
|
+
}, (r) => r.fieldExists.exists);
|
|
441
|
+
}
|
|
442
|
+
setField(fId, ref) {
|
|
443
|
+
this._stat.fieldsSet++;
|
|
444
|
+
if (isResource(ref)) this.sendVoidAsync({
|
|
445
|
+
oneofKind: "fieldSet",
|
|
446
|
+
fieldSet: {
|
|
447
|
+
field: toFieldId(fId),
|
|
448
|
+
value: {
|
|
449
|
+
resourceId: toResourceId(ref),
|
|
450
|
+
fieldName: ""
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
else this.sendVoidAsync({
|
|
455
|
+
oneofKind: "fieldSet",
|
|
456
|
+
fieldSet: {
|
|
457
|
+
field: toFieldId(fId),
|
|
458
|
+
value: toFieldId(ref)
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
setFieldError(fId, ref) {
|
|
463
|
+
this._stat.fieldsSet++;
|
|
464
|
+
this.sendVoidAsync({
|
|
465
|
+
oneofKind: "fieldSetError",
|
|
466
|
+
fieldSetError: {
|
|
467
|
+
field: toFieldId(fId),
|
|
468
|
+
errResourceId: toResourceId(ref)
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
getField(fId) {
|
|
473
|
+
this._stat.fieldsGet++;
|
|
474
|
+
return this.sendSingleAndParse({
|
|
475
|
+
oneofKind: "fieldGet",
|
|
476
|
+
fieldGet: { field: toFieldId(fId) }
|
|
477
|
+
}, (r) => protoToField(notEmpty(r.fieldGet.field)));
|
|
478
|
+
}
|
|
479
|
+
async getFieldIfExists(fId) {
|
|
480
|
+
return this.track(notFoundToUndefined(async () => await this.getField(fId)));
|
|
481
|
+
}
|
|
482
|
+
resetField(fId) {
|
|
483
|
+
this.sendVoidAsync({
|
|
484
|
+
oneofKind: "fieldReset",
|
|
485
|
+
fieldReset: { field: toFieldId(fId) }
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
removeField(fId) {
|
|
489
|
+
this.sendVoidAsync({
|
|
490
|
+
oneofKind: "fieldRemove",
|
|
491
|
+
fieldRemove: { field: toFieldId(fId) }
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
async listKeyValues(rId) {
|
|
495
|
+
return this.track(async () => {
|
|
496
|
+
const result = await this.sendMultiAndParse({
|
|
497
|
+
oneofKind: "resourceKeyValueList",
|
|
498
|
+
resourceKeyValueList: {
|
|
499
|
+
resourceId: toResourceId(rId),
|
|
500
|
+
startFrom: "",
|
|
501
|
+
limit: 0
|
|
502
|
+
}
|
|
503
|
+
}, (r) => r.map((e) => e.resourceKeyValueList.record));
|
|
504
|
+
this._stat.kvListRequests++;
|
|
505
|
+
this._stat.kvListEntries += result.length;
|
|
506
|
+
for (const kv of result) this._stat.kvListBytes += kv.key.length + kv.value.length;
|
|
507
|
+
return result;
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async listKeyValuesString(rId) {
|
|
511
|
+
return this.track(async () => (await this.listKeyValues(rId)).map(({ key, value }) => ({
|
|
512
|
+
key,
|
|
513
|
+
value: Buffer.from(value).toString()
|
|
514
|
+
})));
|
|
515
|
+
}
|
|
516
|
+
async listKeyValuesIfResourceExists(rId) {
|
|
517
|
+
return this.track(notFoundToUndefined(async () => await this.listKeyValues(rId)));
|
|
518
|
+
}
|
|
519
|
+
async listKeyValuesStringIfResourceExists(rId) {
|
|
520
|
+
return this.track(notFoundToUndefined(async () => await this.listKeyValuesString(rId)));
|
|
521
|
+
}
|
|
522
|
+
setKValue(rId, key, value) {
|
|
523
|
+
this._stat.kvSetRequests++;
|
|
524
|
+
this._stat.kvSetBytes++;
|
|
525
|
+
this.sendVoidAsync({
|
|
526
|
+
oneofKind: "resourceKeyValueSet",
|
|
527
|
+
resourceKeyValueSet: {
|
|
528
|
+
resourceId: toResourceId(rId),
|
|
529
|
+
key,
|
|
530
|
+
value: toBytes(value)
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
deleteKValue(rId, key) {
|
|
535
|
+
this.sendVoidAsync({
|
|
536
|
+
oneofKind: "resourceKeyValueDelete",
|
|
537
|
+
resourceKeyValueDelete: {
|
|
538
|
+
resourceId: toResourceId(rId),
|
|
539
|
+
key
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
async getKValue(rId, key) {
|
|
544
|
+
return this.track(async () => {
|
|
545
|
+
const result = await this.sendSingleAndParse({
|
|
546
|
+
oneofKind: "resourceKeyValueGet",
|
|
547
|
+
resourceKeyValueGet: {
|
|
548
|
+
resourceId: toResourceId(rId),
|
|
549
|
+
key
|
|
550
|
+
}
|
|
551
|
+
}, (r) => r.resourceKeyValueGet.value);
|
|
552
|
+
this._stat.kvGetRequests++;
|
|
553
|
+
this._stat.kvGetBytes += result.length;
|
|
554
|
+
return result;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
async getKValueString(rId, key) {
|
|
558
|
+
return this.track(async () => Buffer.from(await this.getKValue(rId, key)).toString());
|
|
559
|
+
}
|
|
560
|
+
async getKValueJson(rId, key) {
|
|
561
|
+
return this.track(async () => JSON.parse(await this.getKValueString(rId, key)));
|
|
562
|
+
}
|
|
563
|
+
async getKValueIfExists(rId, key) {
|
|
564
|
+
return this.track(async () => {
|
|
565
|
+
const result = await this.sendSingleAndParse({
|
|
566
|
+
oneofKind: "resourceKeyValueGetIfExists",
|
|
567
|
+
resourceKeyValueGetIfExists: {
|
|
568
|
+
resourceId: toResourceId(rId),
|
|
569
|
+
key
|
|
570
|
+
}
|
|
571
|
+
}, (r) => r.resourceKeyValueGetIfExists.exists ? r.resourceKeyValueGetIfExists.value : void 0);
|
|
572
|
+
this._stat.kvGetRequests++;
|
|
573
|
+
this._stat.kvGetBytes += result?.length ?? 0;
|
|
574
|
+
return result;
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
async getKValueStringIfExists(rId, key) {
|
|
578
|
+
return this.track(async () => {
|
|
579
|
+
const data = await this.getKValueIfExists(rId, key);
|
|
580
|
+
return data === void 0 ? void 0 : Buffer.from(data).toString();
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
async getKValueJsonIfExists(rId, key) {
|
|
584
|
+
return this.track(async () => {
|
|
585
|
+
const str = await this.getKValueString(rId, key);
|
|
586
|
+
if (str === void 0) return void 0;
|
|
587
|
+
return JSON.parse(str);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/** Resolves existing or create first level resource from */
|
|
591
|
+
getFutureFieldValue(rId, fieldName, fieldType) {
|
|
592
|
+
const data = Buffer.from(JSON.stringify({
|
|
593
|
+
fieldName,
|
|
594
|
+
fieldType
|
|
595
|
+
}));
|
|
596
|
+
const getFieldResource = this.createEphemeral({
|
|
597
|
+
name: "json/getField",
|
|
598
|
+
version: "1"
|
|
599
|
+
}, data);
|
|
600
|
+
this.setField({
|
|
601
|
+
resourceId: getFieldResource,
|
|
602
|
+
fieldName: "resource"
|
|
603
|
+
}, rId);
|
|
604
|
+
return {
|
|
605
|
+
resourceId: getFieldResource,
|
|
606
|
+
fieldName: "result"
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
async getGlobalTxId() {
|
|
610
|
+
this.globalTxIdWasAwaited = true;
|
|
611
|
+
return await this.globalTxId;
|
|
612
|
+
}
|
|
613
|
+
/** Closes output event stream */
|
|
614
|
+
async complete() {
|
|
615
|
+
if (this._completed) return;
|
|
616
|
+
this._completed = true;
|
|
617
|
+
const completeResult = this.track(this.ll.complete());
|
|
618
|
+
await this.drainAndAwaitPendingOps();
|
|
619
|
+
await completeResult;
|
|
620
|
+
}
|
|
621
|
+
/** Await incoming message loop termination and throw
|
|
622
|
+
* any leftover errors if it was unsuccessful */
|
|
623
|
+
async await() {
|
|
624
|
+
await this.ll.await();
|
|
625
|
+
}
|
|
626
|
+
nextLocalResourceId(root) {
|
|
627
|
+
return createLocalResourceId(root, ++this.localResourceIdCounter, this.localTxId);
|
|
628
|
+
}
|
|
629
|
+
static localTxIdCounter = 0;
|
|
630
|
+
static nextLocalTxId() {
|
|
631
|
+
PlTransaction.localTxIdCounter++;
|
|
632
|
+
if (PlTransaction.localTxIdCounter === MaxTxId) PlTransaction.localTxIdCounter = 1;
|
|
633
|
+
return PlTransaction.localTxIdCounter;
|
|
634
|
+
}
|
|
635
|
+
};
|
|
673
636
|
|
|
637
|
+
//#endregion
|
|
674
638
|
export { PlTransaction, TxCommitConflict, field, isField, isFieldRef, isResource, isResourceId, isResourceRef, toFieldId, toGlobalFieldId, toGlobalResourceId, toResourceId };
|
|
675
|
-
//# sourceMappingURL=transaction.js.map
|
|
639
|
+
//# sourceMappingURL=transaction.js.map
|