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