@milaboratories/pl-client 2.17.7 → 2.17.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +43 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/core/PromiseTracker.cjs +33 -33
- package/dist/core/PromiseTracker.cjs.map +1 -1
- package/dist/core/PromiseTracker.d.ts +10 -7
- package/dist/core/PromiseTracker.js +33 -31
- package/dist/core/PromiseTracker.js.map +1 -1
- package/dist/core/StatefulPromise.cjs +60 -61
- package/dist/core/StatefulPromise.cjs.map +1 -1
- package/dist/core/StatefulPromise.js +60 -60
- package/dist/core/StatefulPromise.js.map +1 -1
- package/dist/core/abstract_stream.d.ts +18 -15
- package/dist/core/advisory_locks.cjs +42 -49
- package/dist/core/advisory_locks.cjs.map +1 -1
- package/dist/core/advisory_locks.js +42 -48
- package/dist/core/advisory_locks.js.map +1 -1
- package/dist/core/auth.cjs +10 -15
- package/dist/core/auth.cjs.map +1 -1
- package/dist/core/auth.d.ts +7 -3
- package/dist/core/auth.js +10 -13
- package/dist/core/auth.js.map +1 -1
- package/dist/core/cache.d.ts +11 -7
- package/dist/core/client.cjs +255 -306
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +72 -68
- package/dist/core/client.js +253 -285
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.cjs +81 -99
- package/dist/core/config.cjs.map +1 -1
- package/dist/core/config.d.ts +93 -90
- package/dist/core/config.js +81 -98
- package/dist/core/config.js.map +1 -1
- package/dist/core/default_client.cjs +84 -125
- package/dist/core/default_client.cjs.map +1 -1
- package/dist/core/default_client.d.ts +9 -6
- package/dist/core/default_client.js +78 -103
- package/dist/core/default_client.js.map +1 -1
- package/dist/core/driver.cjs +12 -16
- package/dist/core/driver.cjs.map +1 -1
- package/dist/core/driver.d.ts +18 -14
- package/dist/core/driver.js +12 -15
- package/dist/core/driver.js.map +1 -1
- package/dist/core/error_resource.cjs +5 -4
- package/dist/core/error_resource.cjs.map +1 -1
- package/dist/core/error_resource.js +5 -3
- package/dist/core/error_resource.js.map +1 -1
- package/dist/core/errors.cjs +104 -140
- package/dist/core/errors.cjs.map +1 -1
- package/dist/core/errors.d.ts +34 -30
- package/dist/core/errors.js +102 -137
- package/dist/core/errors.js.map +1 -1
- package/dist/core/final.cjs +63 -89
- package/dist/core/final.cjs.map +1 -1
- package/dist/core/final.d.ts +8 -4
- package/dist/core/final.js +63 -87
- package/dist/core/final.js.map +1 -1
- package/dist/core/ll_client.cjs +416 -521
- package/dist/core/ll_client.cjs.map +1 -1
- package/dist/core/ll_client.d.ts +100 -97
- package/dist/core/ll_client.js +415 -519
- package/dist/core/ll_client.js.map +1 -1
- package/dist/core/ll_transaction.cjs +206 -240
- package/dist/core/ll_transaction.cjs.map +1 -1
- package/dist/core/ll_transaction.d.ts +50 -52
- package/dist/core/ll_transaction.js +205 -238
- package/dist/core/ll_transaction.js.map +1 -1
- package/dist/core/stat.cjs +64 -63
- package/dist/core/stat.cjs.map +1 -1
- package/dist/core/stat.d.ts +35 -36
- package/dist/core/stat.js +64 -62
- package/dist/core/stat.js.map +1 -1
- package/dist/core/transaction.cjs +613 -650
- package/dist/core/transaction.cjs.map +1 -1
- package/dist/core/transaction.d.ts +165 -162
- package/dist/core/transaction.js +612 -648
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/type_conversion.cjs +62 -83
- package/dist/core/type_conversion.cjs.map +1 -1
- package/dist/core/type_conversion.js +61 -81
- package/dist/core/type_conversion.js.map +1 -1
- package/dist/core/types.cjs +56 -86
- package/dist/core/types.cjs.map +1 -1
- package/dist/core/types.d.ts +63 -62
- package/dist/core/types.js +54 -83
- package/dist/core/types.js.map +1 -1
- package/dist/core/unauth_client.cjs +35 -41
- package/dist/core/unauth_client.cjs.map +1 -1
- package/dist/core/unauth_client.d.ts +18 -14
- package/dist/core/unauth_client.js +34 -39
- package/dist/core/unauth_client.js.map +1 -1
- package/dist/core/websocket_stream.cjs +277 -349
- package/dist/core/websocket_stream.cjs.map +1 -1
- package/dist/core/websocket_stream.js +275 -347
- package/dist/core/websocket_stream.js.map +1 -1
- package/dist/core/wire.d.ts +21 -17
- package/dist/helpers/pl.cjs +71 -73
- package/dist/helpers/pl.cjs.map +1 -1
- package/dist/helpers/pl.d.ts +40 -41
- package/dist/helpers/pl.js +66 -46
- package/dist/helpers/pl.js.map +1 -1
- package/dist/helpers/poll.cjs +99 -134
- package/dist/helpers/poll.cjs.map +1 -1
- package/dist/helpers/poll.d.ts +37 -34
- package/dist/helpers/poll.js +97 -113
- package/dist/helpers/poll.js.map +1 -1
- package/dist/helpers/retry_strategy.cjs +82 -87
- package/dist/helpers/retry_strategy.cjs.map +1 -1
- package/dist/helpers/retry_strategy.js +83 -86
- package/dist/helpers/retry_strategy.js.map +1 -1
- package/dist/helpers/tx_helpers.cjs +21 -20
- package/dist/helpers/tx_helpers.cjs.map +1 -1
- package/dist/helpers/tx_helpers.d.ts +11 -7
- package/dist/helpers/tx_helpers.js +20 -18
- package/dist/helpers/tx_helpers.js.map +1 -1
- package/dist/index.cjs +117 -106
- package/dist/index.d.ts +17 -17
- package/dist/index.js +17 -19
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs +72 -66
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts +35 -37
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js +71 -64
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12611 -12866
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +226 -226
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +281 -330
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +225 -224
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +2640 -4294
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js +12608 -12706
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1230 -1089
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +393 -420
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1228 -1083
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +142 -143
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +62 -64
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +140 -141
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +572 -487
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +125 -228
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +572 -485
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.cjs +131 -146
- package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts +78 -84
- package/dist/proto-grpc/google/protobuf/any.js +130 -144
- package/dist/proto-grpc/google/protobuf/any.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
- package/dist/proto-grpc/google/protobuf/duration.js +91 -98
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
- package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
- package/dist/proto-grpc/google/rpc/code.cjs +223 -238
- package/dist/proto-grpc/google/rpc/code.cjs.map +1 -1
- package/dist/proto-grpc/google/rpc/code.d.ts +209 -206
- package/dist/proto-grpc/google/rpc/code.js +221 -237
- package/dist/proto-grpc/google/rpc/code.js.map +1 -1
- package/dist/proto-rest/index.cjs +67 -66
- package/dist/proto-rest/index.cjs.map +1 -1
- package/dist/proto-rest/index.d.ts +24 -18
- package/dist/proto-rest/index.js +61 -65
- package/dist/proto-rest/index.js.map +1 -1
- package/dist/proto-rest/plapi.d.ts +1400 -1477
- package/dist/test/tcp-proxy.cjs +100 -126
- package/dist/test/tcp-proxy.cjs.map +1 -1
- package/dist/test/tcp-proxy.d.ts +17 -13
- package/dist/test/tcp-proxy.js +97 -104
- package/dist/test/tcp-proxy.js.map +1 -1
- package/dist/test/test_config.cjs +145 -194
- package/dist/test/test_config.cjs.map +1 -1
- package/dist/test/test_config.d.ts +34 -30
- package/dist/test/test_config.js +138 -166
- package/dist/test/test_config.js.map +1 -1
- package/dist/util/pl.cjs +4 -3
- package/dist/util/pl.cjs.map +1 -1
- package/dist/util/pl.js +4 -2
- package/dist/util/pl.js.map +1 -1
- package/dist/util/util.cjs +7 -10
- package/dist/util/util.cjs.map +1 -1
- package/dist/util/util.js +7 -9
- package/dist/util/util.js.map +1 -1
- package/package.json +8 -8
- package/src/core/transaction.ts +123 -133
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -61
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -58
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
- package/dist/core/PromiseTracker.d.ts.map +0 -1
- package/dist/core/StatefulPromise.d.ts +0 -39
- package/dist/core/StatefulPromise.d.ts.map +0 -1
- package/dist/core/abstract_stream.d.ts.map +0 -1
- package/dist/core/advisory_locks.d.ts +0 -10
- package/dist/core/advisory_locks.d.ts.map +0 -1
- package/dist/core/auth.d.ts.map +0 -1
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/default_client.d.ts.map +0 -1
- package/dist/core/driver.d.ts.map +0 -1
- package/dist/core/error_resource.d.ts +0 -6
- package/dist/core/error_resource.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/final.d.ts.map +0 -1
- package/dist/core/ll_client.d.ts.map +0 -1
- package/dist/core/ll_transaction.d.ts.map +0 -1
- package/dist/core/stat.d.ts.map +0 -1
- package/dist/core/transaction.d.ts.map +0 -1
- package/dist/core/type_conversion.d.ts +0 -8
- package/dist/core/type_conversion.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/unauth_client.d.ts.map +0 -1
- package/dist/core/websocket_stream.d.ts +0 -67
- package/dist/core/websocket_stream.d.ts.map +0 -1
- package/dist/core/wire.d.ts.map +0 -1
- package/dist/helpers/pl.d.ts.map +0 -1
- package/dist/helpers/poll.d.ts.map +0 -1
- package/dist/helpers/retry_strategy.d.ts +0 -24
- package/dist/helpers/retry_strategy.d.ts.map +0 -1
- package/dist/helpers/state_helpers.d.ts +0 -3
- package/dist/helpers/state_helpers.d.ts.map +0 -1
- package/dist/helpers/tx_helpers.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
- package/dist/proto-grpc/google/api/http.d.ts +0 -456
- package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
- package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
- package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
- package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
- package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
- package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-rest/index.d.ts.map +0 -1
- package/dist/proto-rest/plapi.d.ts.map +0 -1
- package/dist/test/tcp-proxy.d.ts.map +0 -1
- package/dist/test/test_config.d.ts.map +0 -1
- package/dist/util/branding.d.ts +0 -7
- package/dist/util/branding.d.ts.map +0 -1
- package/dist/util/pl.d.ts +0 -9
- package/dist/util/pl.d.ts.map +0 -1
- package/dist/util/util.d.ts +0 -2
- package/dist/util/util.d.ts.map +0 -1
|
@@ -1,120 +1,95 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
1
|
+
import { plAddressToConfig } from "./config.js";
|
|
2
|
+
import { inferAuthRefreshTime } from "./auth.js";
|
|
3
|
+
import { PlClient } from "./client.js";
|
|
4
|
+
import { UnauthenticatedPlClient } from "./unauth_client.js";
|
|
5
|
+
import { notEmpty } from "@milaboratories/ts-helpers";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import canonicalize from "canonicalize";
|
|
9
|
+
import YAML from "yaml";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path from "node:path";
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
const CONFIG_FILE_USER_JSON = path.join(os.homedir(), ".pl.json");
|
|
15
|
-
const CONFIG_FILE_LOCAL_YAML = "pl.yaml";
|
|
16
|
-
const CONFIG_FILE_USER_YAML = path.join(os.homedir(), ".pl.yaml");
|
|
13
|
+
//#region src/core/default_client.ts
|
|
17
14
|
const CONF_FILE_SEQUENCE = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
"pl.json",
|
|
16
|
+
"pl.yaml",
|
|
17
|
+
path.join(os.homedir(), ".pl.json"),
|
|
18
|
+
path.join(os.homedir(), ".pl.yaml")
|
|
22
19
|
];
|
|
23
20
|
const AUTH_DATA_FILE = ".pl_auth.json";
|
|
24
21
|
const FILE_CONFIG_OVERRIDE_FIELDS = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
"grpcProxy",
|
|
23
|
+
"httpProxy",
|
|
24
|
+
"user",
|
|
25
|
+
"password",
|
|
26
|
+
"alternativeRoot",
|
|
27
|
+
"defaultROTransactionTimeout",
|
|
28
|
+
"defaultRWTransactionTimeout",
|
|
29
|
+
"defaultRequestTimeout",
|
|
30
|
+
"authTTLSeconds",
|
|
31
|
+
"authMaxRefreshSeconds"
|
|
35
32
|
];
|
|
36
33
|
function tryGetFileConfig() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
else
|
|
43
|
-
return [YAML.parse(fileContent), confPath];
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
34
|
+
for (const confPath of CONF_FILE_SEQUENCE) if (fs.existsSync(confPath)) {
|
|
35
|
+
const fileContent = fs.readFileSync(confPath, { encoding: "utf-8" });
|
|
36
|
+
if (confPath.endsWith("json")) return [JSON.parse(fileContent), confPath];
|
|
37
|
+
else return [YAML.parse(fileContent), confPath];
|
|
38
|
+
}
|
|
46
39
|
}
|
|
47
40
|
function saveAuthInfoCallback(confHash, authMaxRefreshSeconds) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
return (newAuthInfo) => {
|
|
42
|
+
fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
|
|
43
|
+
confHash,
|
|
44
|
+
authInformation: newAuthInfo,
|
|
45
|
+
expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds)
|
|
46
|
+
})), "utf8");
|
|
47
|
+
};
|
|
55
48
|
}
|
|
56
49
|
const cleanAuthInfoCallback = () => {
|
|
57
|
-
|
|
50
|
+
fs.rmSync(AUTH_DATA_FILE);
|
|
58
51
|
};
|
|
59
52
|
/** Uses default algorithm to construct a pl client from the environment */
|
|
60
53
|
async function defaultPlClient() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
authInformation = await client.login(config.user, config.password);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// No authorization is required
|
|
102
|
-
authInformation = {};
|
|
103
|
-
}
|
|
104
|
-
// saving cache
|
|
105
|
-
fs__default.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
|
|
106
|
-
confHash,
|
|
107
|
-
authInformation,
|
|
108
|
-
expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),
|
|
109
|
-
})), "utf8");
|
|
110
|
-
}
|
|
111
|
-
return await PlClient.init(config, {
|
|
112
|
-
authInformation,
|
|
113
|
-
onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),
|
|
114
|
-
onUpdateError: cleanAuthInfoCallback,
|
|
115
|
-
onAuthError: cleanAuthInfoCallback,
|
|
116
|
-
});
|
|
54
|
+
let config = void 0;
|
|
55
|
+
if (process.env.PL_ADDRESS !== void 0) config = plAddressToConfig(process.env.PL_ADDRESS);
|
|
56
|
+
else {
|
|
57
|
+
const fromFile = tryGetFileConfig();
|
|
58
|
+
if (fromFile !== void 0) {
|
|
59
|
+
const [fileConfig, configPath] = fromFile;
|
|
60
|
+
config = plAddressToConfig(notEmpty(fileConfig.address, `no pl address in file: ${configPath}`));
|
|
61
|
+
for (const field of FILE_CONFIG_OVERRIDE_FIELDS) if (fileConfig[field] !== void 0) config[field] = fileConfig[field];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (config === void 0) throw new Error("Can't find configuration to create default platform client.");
|
|
65
|
+
if (process.env.PL_USER !== void 0) config.user = process.env.PL_USER;
|
|
66
|
+
if (process.env.PL_PASSWORD !== void 0) config.user = process.env.PL_PASSWORD;
|
|
67
|
+
const confHash = createHash("sha256").update(Buffer.from(canonicalize(config))).digest("base64");
|
|
68
|
+
let authInformation = void 0;
|
|
69
|
+
if (fs.existsSync(AUTH_DATA_FILE)) {
|
|
70
|
+
const cache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
|
|
71
|
+
if (cache.confHash === confHash && cache.expiration > Date.now()) authInformation = cache.authInformation;
|
|
72
|
+
}
|
|
73
|
+
if (authInformation === void 0) {
|
|
74
|
+
const client = await UnauthenticatedPlClient.build(config);
|
|
75
|
+
if (await client.requireAuth()) {
|
|
76
|
+
if (config.user === void 0 || config.password === void 0) throw new Error(`No auth information for found to authenticate with PL server.`);
|
|
77
|
+
authInformation = await client.login(config.user, config.password);
|
|
78
|
+
} else authInformation = {};
|
|
79
|
+
fs.writeFileSync(AUTH_DATA_FILE, Buffer.from(JSON.stringify({
|
|
80
|
+
confHash,
|
|
81
|
+
authInformation,
|
|
82
|
+
expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds)
|
|
83
|
+
})), "utf8");
|
|
84
|
+
}
|
|
85
|
+
return await PlClient.init(config, {
|
|
86
|
+
authInformation,
|
|
87
|
+
onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),
|
|
88
|
+
onUpdateError: cleanAuthInfoCallback,
|
|
89
|
+
onAuthError: cleanAuthInfoCallback
|
|
90
|
+
});
|
|
117
91
|
}
|
|
118
92
|
|
|
93
|
+
//#endregion
|
|
119
94
|
export { defaultPlClient, tryGetFileConfig };
|
|
120
|
-
//# sourceMappingURL=default_client.js.map
|
|
95
|
+
//# sourceMappingURL=default_client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default_client.js","sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"
|
|
1
|
+
{"version":3,"file":"default_client.js","names":[],"sources":["../../src/core/default_client.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { AuthInformation, PlClientConfig } from \"./config\";\nimport { plAddressToConfig } from \"./config\";\nimport canonicalize from \"canonicalize\";\nimport YAML from \"yaml\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { UnauthenticatedPlClient } from \"./unauth_client\";\nimport { PlClient } from \"./client\";\nimport { createHash } from \"node:crypto\";\nimport { inferAuthRefreshTime } from \"./auth\";\n\nconst CONFIG_FILE_LOCAL_JSON = \"pl.json\";\nconst CONFIG_FILE_USER_JSON = path.join(os.homedir(), \".pl.json\");\nconst CONFIG_FILE_LOCAL_YAML = \"pl.yaml\";\nconst CONFIG_FILE_USER_YAML = path.join(os.homedir(), \".pl.yaml\");\nconst CONF_FILE_SEQUENCE = [\n CONFIG_FILE_LOCAL_JSON,\n CONFIG_FILE_LOCAL_YAML,\n CONFIG_FILE_USER_JSON,\n CONFIG_FILE_USER_YAML,\n];\n\nconst AUTH_DATA_FILE = \".pl_auth.json\";\n\ntype FileConfigOverrideFields =\n | \"grpcProxy\"\n | \"httpProxy\"\n | \"user\"\n | \"password\"\n | \"alternativeRoot\"\n | \"defaultROTransactionTimeout\"\n | \"defaultRWTransactionTimeout\"\n | \"defaultRequestTimeout\"\n | \"authTTLSeconds\"\n | \"authMaxRefreshSeconds\";\nconst FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [\n \"grpcProxy\",\n \"httpProxy\",\n \"user\",\n \"password\",\n \"alternativeRoot\",\n \"defaultROTransactionTimeout\",\n \"defaultRWTransactionTimeout\",\n \"defaultRequestTimeout\",\n \"authTTLSeconds\",\n \"authMaxRefreshSeconds\",\n];\n\ntype PlConfigFile = {\n address: string;\n} & Partial<Pick<PlClientConfig, FileConfigOverrideFields>>;\n\ninterface AuthCache {\n /** To check if config changed */\n confHash: string;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nexport function tryGetFileConfig(): [PlConfigFile, string] | undefined {\n for (const confPath of CONF_FILE_SEQUENCE)\n if (fs.existsSync(confPath)) {\n const fileContent = fs.readFileSync(confPath, { encoding: \"utf-8\" });\n if (confPath.endsWith(\"json\")) return [JSON.parse(fileContent) as PlConfigFile, confPath];\n else return [YAML.parse(fileContent) as PlConfigFile, confPath];\n }\n return undefined;\n}\n\nfunction saveAuthInfoCallback(\n confHash: string,\n authMaxRefreshSeconds: number,\n): (newAuthInfo: AuthInformation) => void {\n return (newAuthInfo) => {\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation: newAuthInfo,\n expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n fs.rmSync(AUTH_DATA_FILE);\n};\n\n/** Uses default algorithm to construct a pl client from the environment */\nexport async function defaultPlClient(): Promise<PlClient> {\n let config: PlClientConfig | undefined = undefined;\n if (process.env.PL_ADDRESS !== undefined) {\n config = plAddressToConfig(process.env.PL_ADDRESS);\n } else {\n const fromFile = tryGetFileConfig();\n if (fromFile !== undefined) {\n const [fileConfig, configPath] = fromFile;\n const address = notEmpty(fileConfig.address, `no pl address in file: ${configPath}`);\n config = plAddressToConfig(address);\n // applying overrides\n for (const field of FILE_CONFIG_OVERRIDE_FIELDS)\n if (fileConfig[field] !== undefined) (config as any)[field] = fileConfig[field];\n }\n }\n\n if (config === undefined)\n throw new Error(\"Can't find configuration to create default platform client.\");\n\n if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;\n\n if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;\n\n const confHash = createHash(\"sha256\")\n .update(Buffer.from(canonicalize(config)!))\n .digest(\"base64\");\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover auth information from cache\n if (fs.existsSync(AUTH_DATA_FILE)) {\n const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: \"utf-8\" }));\n if (cache.confHash === confHash && cache.expiration > Date.now())\n authInformation = cache.authInformation;\n }\n\n if (authInformation === undefined) {\n const client = await UnauthenticatedPlClient.build(config);\n\n if (await client.requireAuth()) {\n if (config.user === undefined || config.password === undefined)\n throw new Error(`No auth information for found to authenticate with PL server.`);\n authInformation = await client.login(config.user, config.password);\n } else {\n // No authorization is required\n authInformation = {};\n }\n\n // saving cache\n fs.writeFileSync(\n AUTH_DATA_FILE,\n Buffer.from(\n JSON.stringify({\n confHash,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),\n } as AuthCache),\n ),\n \"utf8\",\n );\n }\n\n return await PlClient.init(config, {\n authInformation,\n onUpdate: (_newAuthInfo) => saveAuthInfoCallback(confHash, config.authMaxRefreshSeconds),\n onUpdateError: cleanAuthInfoCallback,\n onAuthError: cleanAuthInfoCallback,\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAM,qBAAqB;CAJI;CAEA;CADD,KAAK,KAAK,GAAG,SAAS,EAAE,WAAW;CAEnC,KAAK,KAAK,GAAG,SAAS,EAAE,WAAW;CAMhE;AAED,MAAM,iBAAiB;AAavB,MAAM,8BAA0D;CAC9D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAaD,SAAgB,mBAAuD;AACrE,MAAK,MAAM,YAAY,mBACrB,KAAI,GAAG,WAAW,SAAS,EAAE;EAC3B,MAAM,cAAc,GAAG,aAAa,UAAU,EAAE,UAAU,SAAS,CAAC;AACpE,MAAI,SAAS,SAAS,OAAO,CAAE,QAAO,CAAC,KAAK,MAAM,YAAY,EAAkB,SAAS;MACpF,QAAO,CAAC,KAAK,MAAM,YAAY,EAAkB,SAAS;;;AAKrE,SAAS,qBACP,UACA,uBACwC;AACxC,SAAQ,gBAAgB;AACtB,KAAG,cACD,gBACA,OAAO,KACL,KAAK,UAAU;GACb;GACA,iBAAiB;GACjB,YAAY,qBAAqB,aAAa,sBAAsB;GACrE,CAAc,CAChB,EACD,OACD;;;AAIL,MAAM,8BAA8B;AAClC,IAAG,OAAO,eAAe;;;AAI3B,eAAsB,kBAAqC;CACzD,IAAI,SAAqC;AACzC,KAAI,QAAQ,IAAI,eAAe,OAC7B,UAAS,kBAAkB,QAAQ,IAAI,WAAW;MAC7C;EACL,MAAM,WAAW,kBAAkB;AACnC,MAAI,aAAa,QAAW;GAC1B,MAAM,CAAC,YAAY,cAAc;AAEjC,YAAS,kBADO,SAAS,WAAW,SAAS,0BAA0B,aAAa,CACjD;AAEnC,QAAK,MAAM,SAAS,4BAClB,KAAI,WAAW,WAAW,OAAW,CAAC,OAAe,SAAS,WAAW;;;AAI/E,KAAI,WAAW,OACb,OAAM,IAAI,MAAM,8DAA8D;AAEhF,KAAI,QAAQ,IAAI,YAAY,OAAW,QAAO,OAAO,QAAQ,IAAI;AAEjE,KAAI,QAAQ,IAAI,gBAAgB,OAAW,QAAO,OAAO,QAAQ,IAAI;CAErE,MAAM,WAAW,WAAW,SAAS,CAClC,OAAO,OAAO,KAAK,aAAa,OAAO,CAAE,CAAC,CAC1C,OAAO,SAAS;CAEnB,IAAI,kBAA+C;AAGnD,KAAI,GAAG,WAAW,eAAe,EAAE;EACjC,MAAM,QAAmB,KAAK,MAAM,GAAG,aAAa,gBAAgB,EAAE,UAAU,SAAS,CAAC,CAAC;AAC3F,MAAI,MAAM,aAAa,YAAY,MAAM,aAAa,KAAK,KAAK,CAC9D,mBAAkB,MAAM;;AAG5B,KAAI,oBAAoB,QAAW;EACjC,MAAM,SAAS,MAAM,wBAAwB,MAAM,OAAO;AAE1D,MAAI,MAAM,OAAO,aAAa,EAAE;AAC9B,OAAI,OAAO,SAAS,UAAa,OAAO,aAAa,OACnD,OAAM,IAAI,MAAM,gEAAgE;AAClF,qBAAkB,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,SAAS;QAGlE,mBAAkB,EAAE;AAItB,KAAG,cACD,gBACA,OAAO,KACL,KAAK,UAAU;GACb;GACA;GACA,YAAY,qBAAqB,iBAAiB,OAAO,sBAAsB;GAChF,CAAc,CAChB,EACD,OACD;;AAGH,QAAO,MAAM,SAAS,KAAK,QAAQ;EACjC;EACA,WAAW,iBAAiB,qBAAqB,UAAU,OAAO,sBAAsB;EACxF,eAAe;EACf,aAAa;EACd,CAAC"}
|
package/dist/core/driver.cjs
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
// for every RPC call. It is necessary for the platform core
|
|
5
|
-
// to proxy the call to the proper controller.
|
|
2
|
+
//#region src/core/driver.ts
|
|
6
3
|
function addRTypeToMetadata(rType, options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
options = options ?? {};
|
|
5
|
+
options.meta = options.meta ?? {};
|
|
6
|
+
options.meta["resourceType"] = `${rType.name}:${rType.version}`;
|
|
7
|
+
return options;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
11
|
+
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
12
|
+
* RPC proxy.
|
|
13
|
+
*/
|
|
17
14
|
function createRTypeRoutingHeader(rType) {
|
|
18
|
-
|
|
19
|
-
resourceType: `${rType.name}:${rType.version}`,
|
|
20
|
-
};
|
|
15
|
+
return { resourceType: `${rType.name}:${rType.version}` };
|
|
21
16
|
}
|
|
22
17
|
|
|
18
|
+
//#endregion
|
|
23
19
|
exports.addRTypeToMetadata = addRTypeToMetadata;
|
|
24
20
|
exports.createRTypeRoutingHeader = createRTypeRoutingHeader;
|
|
25
|
-
//# sourceMappingURL=driver.cjs.map
|
|
21
|
+
//# sourceMappingURL=driver.cjs.map
|
package/dist/core/driver.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.cjs","sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"driver.cjs","names":[],"sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"mappings":";;AAuBA,SAAgB,mBAAmB,OAAqB,SAAsB;AAC5E,WAAU,WAAW,EAAE;AACvB,SAAQ,OAAO,QAAQ,QAAQ,EAAE;AACjC,SAAQ,KAAK,kBAAkB,GAAG,MAAM,KAAK,GAAG,MAAM;AAEtD,QAAO;;;;;;;AAQT,SAAgB,yBAAyB,OAA6C;AACpF,QAAO,EACL,cAAc,GAAG,MAAM,KAAK,GAAG,MAAM,WACtC"}
|
package/dist/core/driver.d.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { ResourceType } from "./types.js";
|
|
2
|
+
import { WireClientProviderFactory } from "./wire.js";
|
|
3
|
+
import { PlClient } from "./client.js";
|
|
4
|
+
import { RpcOptions } from "@protobuf-ts/runtime-rpc";
|
|
5
|
+
import { Dispatcher } from "undici";
|
|
6
|
+
|
|
7
|
+
//#region src/core/driver.d.ts
|
|
6
8
|
/** Drivers must implement this interface */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
interface PlDriver {
|
|
10
|
+
close(): void;
|
|
9
11
|
}
|
|
10
12
|
/** Definition to use driver via {@link PlClient} */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
interface PlDriverDefinition<Drv extends PlDriver> {
|
|
14
|
+
/** Used as key to only once instantiate specific drivers */
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** Initialization routine, will be executed only once for each driver in a specific client */
|
|
17
|
+
init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
declare function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions): RpcOptions;
|
|
18
20
|
/**
|
|
19
21
|
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
20
22
|
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
21
23
|
* RPC proxy.
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
declare function createRTypeRoutingHeader(rType: ResourceType): Record<string, string>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { PlDriver, PlDriverDefinition, addRTypeToMetadata, createRTypeRoutingHeader };
|
|
24
28
|
//# sourceMappingURL=driver.d.ts.map
|
package/dist/core/driver.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
// for every RPC call. It is necessary for the platform core
|
|
3
|
-
// to proxy the call to the proper controller.
|
|
1
|
+
//#region src/core/driver.ts
|
|
4
2
|
function addRTypeToMetadata(rType, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
options = options ?? {};
|
|
4
|
+
options.meta = options.meta ?? {};
|
|
5
|
+
options.meta["resourceType"] = `${rType.name}:${rType.version}`;
|
|
6
|
+
return options;
|
|
9
7
|
}
|
|
10
8
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
10
|
+
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
11
|
+
* RPC proxy.
|
|
12
|
+
*/
|
|
15
13
|
function createRTypeRoutingHeader(rType) {
|
|
16
|
-
|
|
17
|
-
resourceType: `${rType.name}:${rType.version}`,
|
|
18
|
-
};
|
|
14
|
+
return { resourceType: `${rType.name}:${rType.version}` };
|
|
19
15
|
}
|
|
20
16
|
|
|
17
|
+
//#endregion
|
|
21
18
|
export { addRTypeToMetadata, createRTypeRoutingHeader };
|
|
22
|
-
//# sourceMappingURL=driver.js.map
|
|
19
|
+
//# sourceMappingURL=driver.js.map
|
package/dist/core/driver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"driver.js","names":[],"sources":["../../src/core/driver.ts"],"sourcesContent":["import type { PlClient } from \"./client\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { Dispatcher } from \"undici\";\nimport type { ResourceType } from \"./types\";\nimport type { WireClientProviderFactory } from \"./wire\";\n\n/** Drivers must implement this interface */\nexport interface PlDriver {\n close(): void;\n}\n\n/** Definition to use driver via {@link PlClient} */\nexport interface PlDriverDefinition<Drv extends PlDriver> {\n /** Used as key to only once instantiate specific drivers */\n readonly name: string;\n\n /** Initialization routine, will be executed only once for each driver in a specific client */\n init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;\n}\n\n// addRTypeToMetadata adds a metadata with resource type\n// for every RPC call. It is necessary for the platform core\n// to proxy the call to the proper controller.\nexport function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {\n options = options ?? {};\n options.meta = options.meta ?? {};\n options.meta[\"resourceType\"] = `${rType.name}:${rType.version}`;\n\n return options;\n}\n\n/**\n * addRTypeToHeaders adds a header that helps to route request to the right resource and controller.\n * Without this header, API router on server side cannot route request to proper controller in internal\n * RPC proxy.\n */\nexport function createRTypeRoutingHeader(rType: ResourceType): Record<string, string> {\n return {\n resourceType: `${rType.name}:${rType.version}`,\n };\n}\n"],"mappings":";AAuBA,SAAgB,mBAAmB,OAAqB,SAAsB;AAC5E,WAAU,WAAW,EAAE;AACvB,SAAQ,OAAO,QAAQ,QAAQ,EAAE;AACjC,SAAQ,KAAK,kBAAkB,GAAG,MAAM,KAAK,GAAG,MAAM;AAEtD,QAAO;;;;;;;AAQT,SAAgB,yBAAyB,OAA6C;AACpF,QAAO,EACL,cAAc,GAAG,MAAM,KAAK,GAAG,MAAM,WACtC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
2
|
+
//#region src/core/error_resource.ts
|
|
3
3
|
const ErrorResourceType = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
name: "json/resourceError",
|
|
5
|
+
version: "1"
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
//#endregion
|
|
8
9
|
exports.ErrorResourceType = ErrorResourceType;
|
|
9
|
-
//# sourceMappingURL=error_resource.cjs.map
|
|
10
|
+
//# sourceMappingURL=error_resource.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_resource.cjs","sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"
|
|
1
|
+
{"version":3,"file":"error_resource.cjs","names":[],"sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"mappings":";;AAMA,MAAa,oBAAkC;CAC7C,MAAM;CACN,SAAS;CACV"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
//#region src/core/error_resource.ts
|
|
1
2
|
const ErrorResourceType = {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
name: "json/resourceError",
|
|
4
|
+
version: "1"
|
|
4
5
|
};
|
|
5
6
|
|
|
7
|
+
//#endregion
|
|
6
8
|
export { ErrorResourceType };
|
|
7
|
-
//# sourceMappingURL=error_resource.js.map
|
|
9
|
+
//# sourceMappingURL=error_resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_resource.js","sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"
|
|
1
|
+
{"version":3,"file":"error_resource.js","names":[],"sources":["../../src/core/error_resource.ts"],"sourcesContent":["import type { ResourceType } from \"./types\";\n\nexport type ErrorResourceData = {\n message: string;\n};\n\nexport const ErrorResourceType: ResourceType = {\n name: \"json/resourceError\",\n version: \"1\",\n};\n"],"mappings":";AAMA,MAAa,oBAAkC;CAC7C,MAAM;CACN,SAAS;CACV"}
|