@milaboratories/pl-client 2.16.8 → 2.16.10
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/__external/.pnpm/{@rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.7.0_typescript@5.6.3 → @rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3}/__external/tslib/tslib.es6.cjs +2 -2
- package/dist/__external/.pnpm/{@rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.7.0_typescript@5.6.3 → @rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3}/__external/tslib/tslib.es6.cjs.map +1 -1
- package/dist/__external/.pnpm/{@rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.7.0_typescript@5.6.3 → @rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3}/__external/tslib/tslib.es6.js +2 -2
- package/dist/__external/.pnpm/{@rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.7.0_typescript@5.6.3 → @rollup_plugin-typescript@12.1.4_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3}/__external/tslib/tslib.es6.js.map +1 -1
- package/dist/core/abstract_stream.d.ts +18 -0
- package/dist/core/abstract_stream.d.ts.map +1 -0
- package/dist/core/client.cjs +6 -6
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +3 -3
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +6 -6
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.cjs +3 -0
- package/dist/core/config.cjs.map +1 -1
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +3 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/driver.cjs +11 -0
- package/dist/core/driver.cjs.map +1 -1
- package/dist/core/driver.d.ts +8 -2
- package/dist/core/driver.d.ts.map +1 -1
- package/dist/core/driver.js +11 -1
- package/dist/core/driver.js.map +1 -1
- package/dist/core/errors.cjs +9 -0
- package/dist/core/errors.cjs.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/ll_client.cjs +194 -39
- package/dist/core/ll_client.cjs.map +1 -1
- package/dist/core/ll_client.d.ts +36 -15
- package/dist/core/ll_client.d.ts.map +1 -1
- package/dist/core/ll_client.js +195 -40
- package/dist/core/ll_client.js.map +1 -1
- package/dist/core/ll_transaction.cjs.map +1 -1
- package/dist/core/ll_transaction.d.ts +3 -3
- package/dist/core/ll_transaction.d.ts.map +1 -1
- package/dist/core/ll_transaction.js.map +1 -1
- package/dist/core/transaction.cjs +2 -2
- package/dist/core/transaction.cjs.map +1 -1
- package/dist/core/transaction.js +2 -2
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/type_conversion.cjs +2 -2
- package/dist/core/type_conversion.cjs.map +1 -1
- package/dist/core/type_conversion.d.ts +2 -2
- package/dist/core/type_conversion.d.ts.map +1 -1
- package/dist/core/type_conversion.js +2 -2
- package/dist/core/type_conversion.js.map +1 -1
- package/dist/core/unauth_client.cjs +4 -8
- package/dist/core/unauth_client.cjs.map +1 -1
- package/dist/core/unauth_client.d.ts +1 -1
- package/dist/core/unauth_client.d.ts.map +1 -1
- package/dist/core/unauth_client.js +4 -8
- package/dist/core/unauth_client.js.map +1 -1
- package/dist/core/wire.d.ts +34 -0
- package/dist/core/wire.d.ts.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/googleapis/googleapis/google/rpc/status.d.ts +4 -2
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +25 -25
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.js +25 -25
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +73 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/google/api/http.d.ts +28 -32
- package/dist/proto-grpc/google/api/http.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/any.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/any.js.map +1 -0
- package/dist/{proto → proto-grpc}/google/protobuf/descriptor.d.ts +6 -152
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -0
- package/dist/proto-grpc/google/protobuf/empty.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/struct.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -0
- package/dist/{proto → proto-grpc}/google/protobuf/wrappers.d.ts +0 -27
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +1 -0
- package/dist/proto-grpc/google/rpc/code.cjs +240 -0
- package/dist/proto-grpc/google/rpc/code.cjs.map +1 -0
- package/dist/proto-grpc/google/rpc/code.d.ts +219 -0
- package/dist/proto-grpc/google/rpc/code.d.ts.map +1 -0
- package/dist/proto-grpc/google/rpc/code.js +240 -0
- package/dist/proto-grpc/google/rpc/code.js.map +1 -0
- package/dist/proto-grpc/google/rpc/error_details.d.ts +654 -0
- package/dist/proto-grpc/google/rpc/error_details.d.ts.map +1 -0
- package/dist/proto-grpc/google/rpc/http.d.ts +121 -0
- package/dist/proto-grpc/google/rpc/http.d.ts.map +1 -0
- package/dist/proto-grpc/google/rpc/status.d.ts +55 -0
- package/dist/proto-grpc/google/rpc/status.d.ts.map +1 -0
- package/dist/proto-rest/index.cjs +64 -0
- package/dist/proto-rest/index.cjs.map +1 -0
- package/dist/proto-rest/index.d.ts +23 -0
- package/dist/proto-rest/index.d.ts.map +1 -0
- package/dist/proto-rest/index.js +61 -0
- package/dist/proto-rest/index.js.map +1 -0
- package/dist/proto-rest/plapi.d.ts +1488 -0
- package/dist/proto-rest/plapi.d.ts.map +1 -0
- package/package.json +8 -5
- package/src/core/abstract_stream.ts +25 -0
- package/src/core/client.ts +8 -8
- package/src/core/config.ts +9 -0
- package/src/core/driver.ts +13 -2
- package/src/core/errors.ts +7 -1
- package/src/core/ll_client.test.ts +1 -1
- package/src/core/ll_client.ts +212 -42
- package/src/core/ll_transaction.test.ts +1 -1
- package/src/core/ll_transaction.ts +4 -4
- package/src/core/transaction.ts +1 -1
- package/src/core/type_conversion.ts +3 -3
- package/src/core/unauth_client.test.ts +6 -0
- package/src/core/unauth_client.ts +8 -12
- package/src/core/wire.ts +40 -0
- package/src/index.ts +3 -1
- package/src/{proto → proto-grpc}/github.com/googleapis/googleapis/google/rpc/status.ts +5 -3
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.ts +25 -25
- package/src/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.ts +209 -0
- package/src/{proto → proto-grpc}/google/api/http.ts +29 -33
- package/src/{proto → proto-grpc}/google/protobuf/descriptor.ts +11 -221
- package/src/{proto → proto-grpc}/google/protobuf/wrappers.ts +4 -38
- package/src/proto-grpc/google/rpc/code.ts +236 -0
- package/src/proto-grpc/google/rpc/error_details.ts +1386 -0
- package/src/proto-grpc/google/rpc/http.ts +307 -0
- package/src/proto-grpc/google/rpc/status.ts +127 -0
- package/src/proto-rest/index.ts +83 -0
- package/src/proto-rest/plapi.ts +1488 -0
- package/dist/core/grpc.d.ts +0 -16
- package/dist/core/grpc.d.ts.map +0 -1
- package/dist/core/http.d.ts +0 -2
- package/dist/core/http.d.ts.map +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.cjs.map +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +0 -40
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -116
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -46
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -170
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +0 -51
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -176
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +0 -131
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -320
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +0 -1
- package/dist/proto/google/api/http.d.ts.map +0 -1
- package/dist/proto/google/protobuf/any.cjs.map +0 -1
- package/dist/proto/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto/google/protobuf/any.js.map +0 -1
- package/dist/proto/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.cjs.map +0 -1
- package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.js.map +0 -1
- package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.cjs.map +0 -1
- package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
- package/src/core/grpc.ts +0 -17
- package/src/core/http.ts +0 -178
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.ts +0 -45
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.ts +0 -313
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.ts +0 -51
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.ts +0 -406
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.ts +0 -59
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.ts +0 -489
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.ts +0 -148
- package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.ts +0 -719
- /package/dist/{proto → proto-grpc}/github.com/googleapis/googleapis/google/rpc/status.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/googleapis/googleapis/google/rpc/status.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/any.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/any.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/any.js +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.js +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/empty.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/struct.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.js +0 -0
- /package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api.client.ts +0 -0
- /package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/api_types.ts +0 -0
- /package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/base_types.ts +0 -0
- /package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/import.ts +0 -0
- /package/src/{proto → proto-grpc}/github.com/milaboratory/pl/plapi/plapiproto/resource_types.ts +0 -0
- /package/src/{proto → proto-grpc}/google/protobuf/any.ts +0 -0
- /package/src/{proto → proto-grpc}/google/protobuf/duration.ts +0 -0
- /package/src/{proto → proto-grpc}/google/protobuf/empty.ts +0 -0
- /package/src/{proto → proto-grpc}/google/protobuf/struct.ts +0 -0
- /package/src/{proto → proto-grpc}/google/protobuf/timestamp.ts +0 -0
package/src/core/ll_client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlatformClient } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api.client';
|
|
1
|
+
import { PlatformClient as GrpcPlApiClient } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client';
|
|
2
2
|
import type { ClientOptions, Interceptor } from '@grpc/grpc-js';
|
|
3
3
|
import {
|
|
4
4
|
ChannelCredentials,
|
|
@@ -13,26 +13,31 @@ import type {
|
|
|
13
13
|
PlConnectionStatus,
|
|
14
14
|
PlConnectionStatusListener,
|
|
15
15
|
} from './config';
|
|
16
|
-
import { plAddressToConfig } from './config';
|
|
16
|
+
import { plAddressToConfig, type wireProtocol, SUPPORTED_WIRE_PROTOCOLS } from './config';
|
|
17
17
|
import type { GrpcOptions } from '@protobuf-ts/grpc-transport';
|
|
18
18
|
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
19
19
|
import { LLPlTransaction } from './ll_transaction';
|
|
20
20
|
import { parsePlJwt } from '../util/pl';
|
|
21
|
-
import type
|
|
21
|
+
import { type Dispatcher, interceptors } from 'undici';
|
|
22
|
+
import type { Middleware } from 'openapi-fetch';
|
|
22
23
|
import { inferAuthRefreshTime } from './auth';
|
|
23
24
|
import { defaultHttpDispatcher } from '@milaboratories/pl-http';
|
|
24
|
-
import type {
|
|
25
|
+
import type { WireClientProvider, WireClientProviderFactory, WireConnection } from './wire';
|
|
25
26
|
import { parseHttpAuth } from '@milaboratories/pl-model-common';
|
|
27
|
+
import type * as grpcTypes from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
28
|
+
import { type PlApiPaths, type PlRestClientType, createClient, parseResponseError } from '../proto-rest';
|
|
29
|
+
import { notEmpty } from '@milaboratories/ts-helpers';
|
|
30
|
+
import { Code } from '../proto-grpc/google/rpc/code';
|
|
26
31
|
|
|
27
32
|
export interface PlCallOps {
|
|
28
33
|
timeout?: number;
|
|
29
34
|
abortSignal?: AbortSignal;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
class
|
|
37
|
+
class WireClientProviderImpl<Client> implements WireClientProvider<Client> {
|
|
33
38
|
private client: Client | undefined = undefined;
|
|
34
39
|
|
|
35
|
-
constructor(private readonly
|
|
40
|
+
constructor(private readonly wireOpts: () => WireConnection, private readonly clientConstructor: (wireOpts: WireConnection) => Client) {}
|
|
36
41
|
|
|
37
42
|
public reset(): void {
|
|
38
43
|
this.client = undefined;
|
|
@@ -40,13 +45,13 @@ class GrpcClientProviderImpl<Client> implements GrpcClientProvider<Client> {
|
|
|
40
45
|
|
|
41
46
|
public get(): Client {
|
|
42
47
|
if (this.client === undefined)
|
|
43
|
-
this.client = this.clientConstructor(this.
|
|
48
|
+
this.client = this.clientConstructor(this.wireOpts());
|
|
44
49
|
return this.client;
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/** Abstract out low level networking and authorization details */
|
|
49
|
-
export class LLPlClient implements
|
|
54
|
+
export class LLPlClient implements WireClientProviderFactory {
|
|
50
55
|
public readonly conf: PlClientConfig;
|
|
51
56
|
|
|
52
57
|
/** Initial authorization information */
|
|
@@ -63,11 +68,15 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
63
68
|
private _status: PlConnectionStatus = 'OK';
|
|
64
69
|
private readonly statusListener?: PlConnectionStatusListener;
|
|
65
70
|
|
|
66
|
-
private
|
|
67
|
-
private
|
|
68
|
-
private readonly providers: WeakRef<GrpcClientProviderImpl<any>>[] = [];
|
|
71
|
+
private _wireProto: wireProtocol | undefined = undefined;
|
|
72
|
+
private _wireConn!: WireConnection;
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
private readonly _restInterceptors: Dispatcher.DispatcherComposeInterceptor[];
|
|
75
|
+
private readonly _restMiddlewares: Middleware[];
|
|
76
|
+
private readonly _grpcInterceptors: Interceptor[];
|
|
77
|
+
private readonly providers: WeakRef<WireClientProviderImpl<any>>[] = [];
|
|
78
|
+
|
|
79
|
+
public readonly clientProvider: WireClientProvider<PlRestClientType | GrpcPlApiClient>;
|
|
71
80
|
|
|
72
81
|
public readonly httpDispatcher: Dispatcher;
|
|
73
82
|
|
|
@@ -83,45 +92,87 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
83
92
|
? plAddressToConfig(configOrAddress)
|
|
84
93
|
: configOrAddress;
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const { auth, statusListener, shouldUseGzip } = ops;
|
|
95
|
+
const { auth, statusListener } = ops;
|
|
89
96
|
|
|
90
97
|
if (auth !== undefined) {
|
|
91
98
|
this.refreshTimestamp = inferAuthRefreshTime(
|
|
92
99
|
auth.authInformation,
|
|
93
100
|
this.conf.authMaxRefreshSeconds,
|
|
94
101
|
);
|
|
95
|
-
this.grpcInterceptors.push(this.createAuthInterceptor());
|
|
96
102
|
this.authInformation = auth.authInformation;
|
|
97
103
|
this.onAuthUpdate = auth.onUpdate;
|
|
98
104
|
this.onAuthRefreshProblem = auth.onUpdateError;
|
|
99
105
|
this.onAuthError = auth.onAuthError;
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
this.
|
|
108
|
+
this._restInterceptors = [];
|
|
109
|
+
this._restMiddlewares = [];
|
|
110
|
+
this._grpcInterceptors = [];
|
|
103
111
|
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
if (auth !== undefined) {
|
|
113
|
+
this._restInterceptors.push(this.createRestAuthInterceptor());
|
|
114
|
+
this._grpcInterceptors.push(this.createGrpcAuthInterceptor());
|
|
115
|
+
}
|
|
116
|
+
this._restInterceptors.push(interceptors.retry({ statusCodes: [] })); // Handle errors with openapi-fetch middleware.
|
|
117
|
+
this._restMiddlewares.push(this.createRestErrorMiddleware());
|
|
118
|
+
this._grpcInterceptors.push(this.createGrpcErrorInterceptor());
|
|
106
119
|
|
|
107
120
|
this.httpDispatcher = defaultHttpDispatcher(this.conf.httpProxy);
|
|
108
121
|
|
|
122
|
+
this.initWireConnection();
|
|
123
|
+
|
|
109
124
|
if (statusListener !== undefined) {
|
|
110
125
|
this.statusListener = statusListener;
|
|
111
126
|
statusListener(this._status);
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
this.
|
|
129
|
+
this.clientProvider = this.createWireClientProvider((wireConn) => {
|
|
130
|
+
if (wireConn.type === 'grpc') {
|
|
131
|
+
return new GrpcPlApiClient(wireConn.Transport);
|
|
132
|
+
} else {
|
|
133
|
+
return createClient<PlApiPaths>({
|
|
134
|
+
hostAndPort: wireConn.Config.hostAndPort,
|
|
135
|
+
ssl: wireConn.Config.ssl,
|
|
136
|
+
dispatcher: wireConn.Dispatcher,
|
|
137
|
+
middlewares: wireConn.Middlewares,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private initWireConnection() {
|
|
144
|
+
if (this._wireProto === undefined) {
|
|
145
|
+
// TODO: implement automatic server mode detection
|
|
146
|
+
this._wireProto = this.conf.wireProtocol ?? 'grpc';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
switch (this._wireProto) {
|
|
150
|
+
case 'rest':
|
|
151
|
+
this.initRestConnection();
|
|
152
|
+
return;
|
|
153
|
+
case 'grpc':
|
|
154
|
+
this.initGrpcConnection(this.ops.shouldUseGzip ?? false);
|
|
155
|
+
return;
|
|
156
|
+
default:
|
|
157
|
+
((v: never) => {
|
|
158
|
+
throw new Error(`Unsupported wire protocol '${v as string}'. Use one of: ${SUPPORTED_WIRE_PROTOCOLS.join(', ')}`);
|
|
159
|
+
})(this._wireProto);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private initRestConnection(): void {
|
|
164
|
+
const dispatcher = defaultHttpDispatcher(this.conf.httpProxy, this._restInterceptors);
|
|
165
|
+
this._replaceWireConnection({ type: 'rest', Config: this.conf, Dispatcher: dispatcher, Middlewares: this._restMiddlewares });
|
|
115
166
|
}
|
|
116
167
|
|
|
117
168
|
/**
|
|
118
|
-
* Initializes (or reinitializes) _grpcTransport
|
|
169
|
+
* Initializes (or reinitializes) _grpcTransport
|
|
119
170
|
* @param gzip - whether to enable gzip compression
|
|
120
171
|
*/
|
|
121
|
-
private
|
|
172
|
+
private initGrpcConnection(gzip: boolean) {
|
|
122
173
|
const clientOptions: ClientOptions = {
|
|
123
174
|
'grpc.keepalive_time_ms': 30_000, // 30 seconds
|
|
124
|
-
'interceptors': this.
|
|
175
|
+
'interceptors': this._grpcInterceptors,
|
|
125
176
|
};
|
|
126
177
|
|
|
127
178
|
if (gzip) clientOptions['grpc.default_compression_algorithm'] = compressionAlgorithms.gzip;
|
|
@@ -161,9 +212,12 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
161
212
|
delete process.env.grpc_proxy;
|
|
162
213
|
}
|
|
163
214
|
|
|
164
|
-
|
|
215
|
+
this._replaceWireConnection({ type: 'grpc', Transport: new GrpcTransport(grpcOptions) });
|
|
216
|
+
}
|
|
165
217
|
|
|
166
|
-
|
|
218
|
+
private _replaceWireConnection(newConn: WireConnection): void {
|
|
219
|
+
const oldConn = this._wireConn;
|
|
220
|
+
this._wireConn = newConn;
|
|
167
221
|
|
|
168
222
|
// Reset all providers to let them reinitialize their clients
|
|
169
223
|
for (let i = 0; i < this.providers.length; i++) {
|
|
@@ -177,7 +231,7 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
177
231
|
}
|
|
178
232
|
}
|
|
179
233
|
|
|
180
|
-
if (
|
|
234
|
+
if (oldConn !== undefined && oldConn.type === 'grpc') oldConn.Transport.close();
|
|
181
235
|
}
|
|
182
236
|
|
|
183
237
|
private providerCleanupCounter = 0;
|
|
@@ -187,7 +241,7 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
187
241
|
*
|
|
188
242
|
* @param clientConstructor - a factory function that creates a grpc client
|
|
189
243
|
*/
|
|
190
|
-
public
|
|
244
|
+
public createWireClientProvider<Client>(clientConstructor: (transport: WireConnection) => Client): WireClientProvider<Client> {
|
|
191
245
|
// We need to cleanup providers periodically to avoid memory leaks.
|
|
192
246
|
// This is a simple heuristic to avoid memory leaks.
|
|
193
247
|
// We could use a more sophisticated algorithm, but this is good enough for now.
|
|
@@ -203,13 +257,13 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
203
257
|
this.providerCleanupCounter = 0;
|
|
204
258
|
}
|
|
205
259
|
|
|
206
|
-
const provider = new
|
|
260
|
+
const provider = new WireClientProviderImpl<Client>(() => this._wireConn, clientConstructor);
|
|
207
261
|
this.providers.push(new WeakRef(provider));
|
|
208
262
|
return provider;
|
|
209
263
|
}
|
|
210
264
|
|
|
211
|
-
public get
|
|
212
|
-
return this.
|
|
265
|
+
public get wireConnection(): WireConnection {
|
|
266
|
+
return this._wireConn;
|
|
213
267
|
}
|
|
214
268
|
|
|
215
269
|
/** Returns true if client is authenticated. Even with anonymous auth information
|
|
@@ -256,13 +310,8 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
256
310
|
this.authRefreshInProgress = true;
|
|
257
311
|
void (async () => {
|
|
258
312
|
try {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
seconds: BigInt(this.conf.authTTLSeconds),
|
|
262
|
-
nanos: 0,
|
|
263
|
-
},
|
|
264
|
-
}).response;
|
|
265
|
-
this.authInformation = { jwtToken: response.token };
|
|
313
|
+
const token = await this.getJwtToken(BigInt(this.conf.authTTLSeconds));
|
|
314
|
+
this.authInformation = { jwtToken: token };
|
|
266
315
|
this.refreshTimestamp = inferAuthRefreshTime(
|
|
267
316
|
this.authInformation,
|
|
268
317
|
this.conf.authMaxRefreshSeconds,
|
|
@@ -276,8 +325,45 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
276
325
|
})();
|
|
277
326
|
}
|
|
278
327
|
|
|
279
|
-
/**
|
|
280
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Creates middleware that parses error responses and handles them centrally.
|
|
330
|
+
* This middleware runs before openapi-fetch parses the response, so we need to
|
|
331
|
+
* manually parse the response body for error responses.
|
|
332
|
+
*/
|
|
333
|
+
private createRestErrorMiddleware(): Middleware {
|
|
334
|
+
return {
|
|
335
|
+
onResponse: async ({ request: _request, response, options: _options }) => {
|
|
336
|
+
const { body: body, ...resOptions } = response;
|
|
337
|
+
|
|
338
|
+
if ([502, 503, 504].includes(response.status)) {
|
|
339
|
+
// Service unavailable, bad gateway, gateway timeout
|
|
340
|
+
this.updateStatus('Disconnected');
|
|
341
|
+
return new Response(body, { ...resOptions, status: response.status });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const respErr = await parseResponseError(response);
|
|
345
|
+
if (!respErr.error) {
|
|
346
|
+
// No error: nice!
|
|
347
|
+
return new Response(respErr.origBody ?? body, { ...resOptions, status: response.status });
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (typeof respErr.error === 'string') {
|
|
351
|
+
// Non-standard error or normal response: let later middleware to deal wit it.
|
|
352
|
+
return new Response(respErr.error, { ...resOptions, status: response.status });
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (respErr.error.code === Code.UNAUTHENTICATED) {
|
|
356
|
+
this.updateStatus('Unauthenticated');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Let later middleware to deal with standard gRPC error.
|
|
360
|
+
return new Response(respErr.origBody, { ...resOptions, status: response.status });
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Detects certain errors and update client status accordingly when using GRPC wire connection */
|
|
366
|
+
private createGrpcErrorInterceptor(): Interceptor {
|
|
281
367
|
return (options, nextCall) => {
|
|
282
368
|
return new InterceptingCall(nextCall(options), {
|
|
283
369
|
start: (metadata, listener, next) => {
|
|
@@ -297,8 +383,22 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
297
383
|
};
|
|
298
384
|
}
|
|
299
385
|
|
|
386
|
+
private createRestAuthInterceptor(): Dispatcher.DispatcherComposeInterceptor {
|
|
387
|
+
return (dispatch) => {
|
|
388
|
+
return (options, handler) => {
|
|
389
|
+
if (this.authInformation?.jwtToken !== undefined) {
|
|
390
|
+
// TODO: check this magic really works and gets called
|
|
391
|
+
options.headers = { ...options.headers, authorization: 'Bearer ' + this.authInformation.jwtToken };
|
|
392
|
+
this.refreshAuthInformationIfNeeded();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return dispatch(options, handler);
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
300
400
|
/** Injects authentication information if needed */
|
|
301
|
-
private
|
|
401
|
+
private createGrpcAuthInterceptor(): Interceptor {
|
|
302
402
|
return (options, nextCall) => {
|
|
303
403
|
return new InterceptingCall(nextCall(options), {
|
|
304
404
|
start: (metadata, listener, next) => {
|
|
@@ -314,11 +414,77 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
314
414
|
};
|
|
315
415
|
}
|
|
316
416
|
|
|
417
|
+
public async getJwtToken(ttlSeconds: bigint, options?: { authorization?: string }): Promise<string> {
|
|
418
|
+
const cl = this.clientProvider.get();
|
|
419
|
+
|
|
420
|
+
if (cl instanceof GrpcPlApiClient) {
|
|
421
|
+
const meta: Record<string, string> = {};
|
|
422
|
+
if (options?.authorization) meta.authorization = options.authorization;
|
|
423
|
+
return (await cl.getJWTToken({ expiration: { seconds: ttlSeconds, nanos: 0 } }, { meta }).response).token;
|
|
424
|
+
} else {
|
|
425
|
+
const headers: Record<string, string> = {};
|
|
426
|
+
if (options?.authorization) headers.authorization = options.authorization;
|
|
427
|
+
const resp = cl.POST('/v1/auth/jwt-token', {
|
|
428
|
+
body: { expiration: `${ttlSeconds}s` },
|
|
429
|
+
headers,
|
|
430
|
+
});
|
|
431
|
+
return notEmpty((await resp).data).token;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
public async ping(): Promise<grpcTypes.MaintenanceAPI_Ping_Response> {
|
|
436
|
+
const cl = this.clientProvider.get();
|
|
437
|
+
if (cl instanceof GrpcPlApiClient) {
|
|
438
|
+
return (await cl.ping({})).response;
|
|
439
|
+
} else {
|
|
440
|
+
return notEmpty((await cl.GET('/v1/ping')).data);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
public async license(): Promise<grpcTypes.MaintenanceAPI_License_Response> {
|
|
445
|
+
const cl = this.clientProvider.get();
|
|
446
|
+
if (cl instanceof GrpcPlApiClient) {
|
|
447
|
+
return (await cl.license({})).response;
|
|
448
|
+
} else {
|
|
449
|
+
const resp = notEmpty((await cl.GET('/v1/license')).data);
|
|
450
|
+
return {
|
|
451
|
+
status: resp.status,
|
|
452
|
+
isOk: resp.isOk,
|
|
453
|
+
responseBody: Uint8Array.from(Buffer.from(resp.responseBody)),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
public async authMethods(): Promise<grpcTypes.AuthAPI_ListMethods_Response> {
|
|
459
|
+
const cl = this.clientProvider.get();
|
|
460
|
+
if (cl instanceof GrpcPlApiClient) {
|
|
461
|
+
return (await cl.authMethods({})).response;
|
|
462
|
+
} else {
|
|
463
|
+
return notEmpty((await cl.GET('/v1/auth/methods')).data);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
public async txSync(txId: bigint): Promise<void> {
|
|
468
|
+
const cl = this.clientProvider.get();
|
|
469
|
+
if (cl instanceof GrpcPlApiClient) {
|
|
470
|
+
await cl.txSync({ txId: BigInt(txId) });
|
|
471
|
+
} else {
|
|
472
|
+
(await cl.POST('/v1/tx-sync', { body: { txId: txId.toString() } }));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
317
476
|
createTx(rw: boolean, ops: PlCallOps = {}): LLPlTransaction {
|
|
318
477
|
return new LLPlTransaction((abortSignal) => {
|
|
319
478
|
let totalAbortSignal = abortSignal;
|
|
320
479
|
if (ops.abortSignal) totalAbortSignal = AbortSignal.any([totalAbortSignal, ops.abortSignal]);
|
|
321
|
-
|
|
480
|
+
|
|
481
|
+
const cl = this.clientProvider.get();
|
|
482
|
+
if (!(cl instanceof GrpcPlApiClient)) {
|
|
483
|
+
// TODO: add WebSockets
|
|
484
|
+
throw new Error('tx is not supported for REST client');
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return cl.tx({
|
|
322
488
|
abort: totalAbortSignal,
|
|
323
489
|
timeout: ops.timeout
|
|
324
490
|
?? (rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout),
|
|
@@ -328,7 +494,11 @@ export class LLPlClient implements GrpcClientProviderFactory {
|
|
|
328
494
|
|
|
329
495
|
/** Closes underlying transport */
|
|
330
496
|
public async close() {
|
|
331
|
-
this.
|
|
497
|
+
if (this.wireConnection.type === 'grpc') {
|
|
498
|
+
this.wireConnection.Transport.close();
|
|
499
|
+
} else {
|
|
500
|
+
// TODO: close all WS connections
|
|
501
|
+
}
|
|
332
502
|
await this.httpDispatcher.destroy();
|
|
333
503
|
}
|
|
334
504
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getTestLLClient } from '../test/test_config';
|
|
2
|
-
import { TxAPI_Open_Request_WritableTx } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
2
|
+
import { TxAPI_Open_Request_WritableTx } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
3
3
|
import { createLocalResourceId } from './types';
|
|
4
4
|
import { test, expect } from 'vitest';
|
|
5
5
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
TxAPI_ClientMessage,
|
|
3
3
|
TxAPI_ServerMessage,
|
|
4
|
-
} from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
5
|
-
import type {
|
|
4
|
+
} from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
5
|
+
import type { BiDiStream } from './abstract_stream';
|
|
6
6
|
import Denque from 'denque';
|
|
7
|
-
import type { Status } from '../proto/github.com/googleapis/googleapis/google/rpc/status';
|
|
7
|
+
import type { Status } from '../proto-grpc/github.com/googleapis/googleapis/google/rpc/status';
|
|
8
8
|
import {
|
|
9
9
|
PlErrorCodeNotFound,
|
|
10
10
|
RecoverablePlError,
|
|
@@ -17,7 +17,7 @@ export type ClientMessageRequest = TxAPI_ClientMessage['request'];
|
|
|
17
17
|
|
|
18
18
|
export type ServerMessageResponse = TxAPI_ServerMessage['response'];
|
|
19
19
|
|
|
20
|
-
type TxStream =
|
|
20
|
+
type TxStream = BiDiStream<TxAPI_ClientMessage, TxAPI_ServerMessage>;
|
|
21
21
|
|
|
22
22
|
export type OneOfKind<T extends { oneofKind: unknown }, Kind extends T['oneofKind']> = Extract<
|
|
23
23
|
T,
|
package/src/core/transaction.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type {
|
|
|
25
25
|
OneOfKind,
|
|
26
26
|
ServerMessageResponse,
|
|
27
27
|
} from './ll_transaction';
|
|
28
|
-
import { TxAPI_Open_Request_WritableTx } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
28
|
+
import { TxAPI_Open_Request_WritableTx } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
29
29
|
import type { NonUndefined } from 'utility-types';
|
|
30
30
|
import { toBytes } from '../util/util';
|
|
31
31
|
import { fieldTypeToProto, protoToField, protoToResource } from './type_conversion';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Field,
|
|
3
|
-
Resource } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api_types';
|
|
3
|
+
Resource } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types';
|
|
4
4
|
import {
|
|
5
5
|
Field_ValueStatus,
|
|
6
6
|
Resource_Kind,
|
|
7
|
-
} from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api_types';
|
|
8
|
-
import { FieldType as GrpcFieldType } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/base_types';
|
|
7
|
+
} from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types';
|
|
8
|
+
import { FieldType as GrpcFieldType } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types';
|
|
9
9
|
import type {
|
|
10
10
|
FieldData,
|
|
11
11
|
FieldStatus,
|
|
@@ -9,6 +9,12 @@ test('ping test', async () => {
|
|
|
9
9
|
expect(response).toHaveProperty('coreVersion');
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
test('get auth methods', async () => {
|
|
13
|
+
const client = new UnauthenticatedPlClient(getTestConfig().address);
|
|
14
|
+
const response = await client.authMethods();
|
|
15
|
+
expect(response).toHaveProperty('methods');
|
|
16
|
+
});
|
|
17
|
+
|
|
12
18
|
test('wrong login', async () => {
|
|
13
19
|
const testConfig = getTestConfig();
|
|
14
20
|
if (testConfig.test_user === undefined || testConfig.test_password === undefined) {
|
|
@@ -2,7 +2,7 @@ import type { AuthInformation, PlClientConfig } from './config';
|
|
|
2
2
|
import type {
|
|
3
3
|
AuthAPI_ListMethods_Response,
|
|
4
4
|
MaintenanceAPI_Ping_Response,
|
|
5
|
-
} from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
5
|
+
} from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
6
6
|
import { LLPlClient } from './ll_client';
|
|
7
7
|
import { notEmpty } from '@milaboratories/ts-helpers';
|
|
8
8
|
import { UnauthenticatedError } from './errors';
|
|
@@ -16,11 +16,11 @@ export class UnauthenticatedPlClient {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
public async ping(): Promise<MaintenanceAPI_Ping_Response> {
|
|
19
|
-
return
|
|
19
|
+
return await this.ll.ping();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
public async authMethods(): Promise<AuthAPI_ListMethods_Response> {
|
|
23
|
-
return
|
|
23
|
+
return await this.ll.authMethods();
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public async requireAuth(): Promise<boolean> {
|
|
@@ -29,15 +29,11 @@ export class UnauthenticatedPlClient {
|
|
|
29
29
|
|
|
30
30
|
public async login(user: string, password: string): Promise<AuthInformation> {
|
|
31
31
|
try {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
).response;
|
|
40
|
-
const jwtToken = notEmpty(response.token);
|
|
32
|
+
const token = await this.ll.getJwtToken(
|
|
33
|
+
BigInt(this.ll.conf.authTTLSeconds),
|
|
34
|
+
{ authorization: 'Basic ' + Buffer.from(user + ':' + password).toString('base64') },
|
|
35
|
+
);
|
|
36
|
+
const jwtToken = notEmpty(token);
|
|
41
37
|
if (jwtToken === '') throw new Error('empty token');
|
|
42
38
|
return { jwtToken };
|
|
43
39
|
} catch (e: any) {
|
package/src/core/wire.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
2
|
+
import type { Dispatcher } from 'undici';
|
|
3
|
+
import type { PlClientConfig, wireProtocol } from './config';
|
|
4
|
+
import type { Middleware } from 'openapi-fetch';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for the HTTP client to properly reach the PL server API when
|
|
8
|
+
* it works in WebSocket + REST mode.
|
|
9
|
+
*/
|
|
10
|
+
export type RestConnection = {
|
|
11
|
+
type: 'rest';
|
|
12
|
+
Config: PlClientConfig;
|
|
13
|
+
Dispatcher: Dispatcher;
|
|
14
|
+
Middlewares: Middleware[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type GrpcConnection = {
|
|
18
|
+
type: 'grpc';
|
|
19
|
+
Transport: GrpcTransport;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type WireConnection = RestConnection | GrpcConnection;
|
|
23
|
+
// type compatibility check: types used in WireConnection should match known wire protocols.
|
|
24
|
+
const _ct: Extract<WireConnection, { type: string }>['type'] = 'rest' as wireProtocol;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A provider for a wire (gRPC, HTTP, etc.) client.
|
|
28
|
+
* The client is created on demand, and is reset when the transport is reset.
|
|
29
|
+
* This is useful for cases where the client is used in a loop, and the transport is reset after each iteration.
|
|
30
|
+
*/
|
|
31
|
+
export interface WireClientProvider<Client> {
|
|
32
|
+
get(): Client;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A factory for wire client providers.
|
|
37
|
+
*/
|
|
38
|
+
export interface WireClientProviderFactory {
|
|
39
|
+
createWireClientProvider<Client>(clientConstructor: (transport: WireConnection) => Client): WireClientProvider<Client>;
|
|
40
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,8 +9,10 @@ export * from './core/default_client';
|
|
|
9
9
|
export * from './core/unauth_client';
|
|
10
10
|
export * from './core/auth';
|
|
11
11
|
export * from './core/final';
|
|
12
|
-
export * from './core/
|
|
12
|
+
export * from './core/wire';
|
|
13
13
|
export * from './helpers/tx_helpers';
|
|
14
14
|
export * from './helpers/poll';
|
|
15
15
|
|
|
16
16
|
export * as TestHelpers from './test/test_config';
|
|
17
|
+
|
|
18
|
+
export * as RestAPI from './proto-rest';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @generated from protobuf file "github.com/googleapis/googleapis/google/rpc/status.proto" (package "google.rpc", syntax proto3)
|
|
3
3
|
// tslint:disable
|
|
4
4
|
//
|
|
5
|
-
// Copyright
|
|
5
|
+
// Copyright 2025 Google LLC
|
|
6
6
|
//
|
|
7
7
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
8
|
// you may not use this file except in compliance with the License.
|
|
@@ -39,7 +39,8 @@ import { Any } from "../../../../../google/protobuf/any";
|
|
|
39
39
|
*/
|
|
40
40
|
export interface Status {
|
|
41
41
|
/**
|
|
42
|
-
* The status code, which should be an enum value of
|
|
42
|
+
* The status code, which should be an enum value of
|
|
43
|
+
* [google.rpc.Code][google.rpc.Code].
|
|
43
44
|
*
|
|
44
45
|
* @generated from protobuf field: int32 code = 1
|
|
45
46
|
*/
|
|
@@ -47,7 +48,8 @@ export interface Status {
|
|
|
47
48
|
/**
|
|
48
49
|
* A developer-facing error message, which should be in English. Any
|
|
49
50
|
* user-facing error message should be localized and sent in the
|
|
50
|
-
* [google.rpc.Status.details][google.rpc.Status.details] field, or localized
|
|
51
|
+
* [google.rpc.Status.details][google.rpc.Status.details] field, or localized
|
|
52
|
+
* by the client.
|
|
51
53
|
*
|
|
52
54
|
* @generated from protobuf field: string message = 2
|
|
53
55
|
*/
|