@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/dist/core/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/core/client.ts"],"sourcesContent":["import type { AuthOps, PlClientConfig, PlConnectionStatusListener } from './config';\nimport type { PlCallOps } from './ll_client';\nimport { LLPlClient } from './ll_client';\nimport type { AnyResourceRef } from './transaction';\nimport { PlTransaction, toGlobalResourceId, TxCommitConflict } from './transaction';\nimport { createHash } from 'node:crypto';\nimport type { OptionalResourceId, ResourceId } from './types';\nimport { ensureResourceIdNotNull, isNullResourceId, NullResourceId } from './types';\nimport { ClientRoot } from '../helpers/pl';\nimport type { RetryOptions } from '@milaboratories/ts-helpers';\nimport { assertNever, createRetryState, nextRetryStateOrError } from '@milaboratories/ts-helpers';\nimport type { PlDriver, PlDriverDefinition } from './driver';\nimport type { MaintenanceAPI_Ping_Response, MaintenanceAPI_License_Response } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';\nimport { MaintenanceAPI_Ping_Response_Compression } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';\nimport * as tp from 'node:timers/promises';\nimport type { Dispatcher } from 'undici';\nimport { LRUCache } from 'lru-cache';\nimport type { ResourceDataCacheRecord } from './cache';\nimport type { FinalResourceDataPredicate } from './final';\nimport { DefaultFinalResourceDataPredicate } from './final';\nimport type { AllTxStat, TxStat } from './stat';\nimport { addStat, initialTxStat } from './stat';\nimport type { GrpcTransport } from '@protobuf-ts/grpc-transport';\nimport { advisoryLock } from './advisory_locks';\n\nexport type TxOps = PlCallOps & {\n sync?: boolean;\n retryOptions?: RetryOptions;\n name?: string;\n lockId?: string;\n};\n\nconst defaultTxOps = {\n sync: false,\n};\n\nconst AnonymousClientRoot = 'AnonymousRoot';\n\nfunction alternativeRootFieldName(alternativeRoot: string): string {\n return `alternative_root_${alternativeRoot}`;\n}\n\n/** Client to access core PL API. */\nexport class PlClient {\n private readonly drivers = new Map<string, PlDriver>();\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n private readonly txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n private readonly forceSync: boolean;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n private readonly defaultRetryOptions: RetryOptions;\n\n private readonly buildLLPlClient: (shouldUseGzip: boolean) => LLPlClient;\n private _ll: LLPlClient;\n /** Stores client root (this abstraction is intended for future implementation of the security model) */\n private _clientRoot: OptionalResourceId = NullResourceId;\n\n private _serverInfo: MaintenanceAPI_Ping_Response | undefined = undefined;\n\n private _txCommittedStat: TxStat = initialTxStat();\n private _txConflictStat: TxStat = initialTxStat();\n private _txErrorStat: TxStat = initialTxStat();\n\n //\n // Caching\n //\n\n /** This function determines whether resource data can be cached */\n public readonly finalPredicate: FinalResourceDataPredicate;\n\n /** Resource data cache, to minimize redundant data rereading from remote db */\n private readonly resourceDataCache: LRUCache<ResourceId, ResourceDataCacheRecord>;\n\n private constructor(\n configOrAddress: PlClientConfig | string,\n auth: AuthOps,\n ops: {\n statusListener?: PlConnectionStatusListener;\n finalPredicate?: FinalResourceDataPredicate;\n } = {},\n ) {\n // Will reinitialize client after getting available feature from server.\n this.buildLLPlClient = (shouldUseGzip: boolean) => {\n return new LLPlClient(configOrAddress, { auth, ...ops, shouldUseGzip });\n };\n this._ll = this.buildLLPlClient(false);\n const conf = this._ll.conf;\n this.txDelay = conf.txDelay;\n this.forceSync = conf.forceSync;\n this.finalPredicate = ops.finalPredicate ?? DefaultFinalResourceDataPredicate;\n this.resourceDataCache = new LRUCache({\n maxSize: conf.maxCacheBytes,\n sizeCalculation: (v) => (v.basicData.data?.length ?? 0) + 64,\n });\n switch (conf.retryBackoffAlgorithm) {\n case 'exponential':\n this.defaultRetryOptions = {\n type: 'exponentialBackoff',\n initialDelay: conf.retryInitialDelay,\n maxAttempts: conf.retryMaxAttempts,\n backoffMultiplier: conf.retryExponentialBackoffMultiplier,\n jitter: conf.retryJitter,\n };\n break;\n case 'linear':\n this.defaultRetryOptions = {\n type: 'linearBackoff',\n initialDelay: conf.retryInitialDelay,\n maxAttempts: conf.retryMaxAttempts,\n backoffStep: conf.retryLinearBackoffStep,\n jitter: conf.retryJitter,\n };\n break;\n default:\n assertNever(conf.retryBackoffAlgorithm);\n }\n }\n\n public get txCommittedStat(): TxStat {\n return { ...this._txCommittedStat };\n }\n\n public get txConflictStat(): TxStat {\n return { ...this._txConflictStat };\n }\n\n public get txErrorStat(): TxStat {\n return { ...this._txErrorStat };\n }\n\n public get txTotalStat(): TxStat {\n return addStat(addStat(this._txCommittedStat, this._txConflictStat), this._txErrorStat);\n }\n\n public get allTxStat(): AllTxStat {\n return {\n committed: this.txCommittedStat,\n conflict: this.txConflictStat,\n error: this.txErrorStat,\n };\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return (await this._ll.grpcPl.get().ping({})).response;\n }\n\n public async license(): Promise<MaintenanceAPI_License_Response> {\n return (await this._ll.grpcPl.get().license({})).response;\n }\n\n public get conf(): PlClientConfig {\n return this._ll.conf;\n }\n\n public get httpDispatcher(): Dispatcher {\n return this._ll.httpDispatcher;\n }\n\n public get grpcTransport(): GrpcTransport {\n return this._ll.grpcTransport;\n }\n\n private get initialized() {\n return !isNullResourceId(this._clientRoot);\n }\n\n private checkInitialized() {\n if (!this.initialized) throw new Error('Client not initialized');\n }\n\n public get clientRoot(): ResourceId {\n this.checkInitialized();\n return ensureResourceIdNotNull(this._clientRoot);\n }\n\n public get serverInfo(): MaintenanceAPI_Ping_Response {\n this.checkInitialized();\n return this._serverInfo!;\n }\n\n /** Currently implements custom logic to emulate future behaviour with single root. */\n public async init() {\n if (this.initialized) throw new Error('Already initialized');\n\n // calculating reproducible root name from the username\n const user = this._ll.authUser;\n const mainRootName\n = user === null ? AnonymousClientRoot : createHash('sha256').update(user).digest('hex');\n\n this._serverInfo = await this.ping();\n if (this._serverInfo.compression === MaintenanceAPI_Ping_Response_Compression.GZIP) {\n await this._ll.close();\n this._ll = this.buildLLPlClient(true);\n }\n\n this._clientRoot = await this._withTx('initialization', true, NullResourceId, async (tx) => {\n let mainRoot: AnyResourceRef;\n\n if (await tx.checkResourceNameExists(mainRootName))\n mainRoot = await tx.getResourceByName(mainRootName);\n else {\n mainRoot = tx.createRoot(ClientRoot);\n tx.setResourceName(mainRootName, mainRoot);\n }\n\n if (this.conf.alternativeRoot === undefined) {\n await tx.commit();\n return await toGlobalResourceId(mainRoot);\n } else {\n const aFId = {\n resourceId: mainRoot,\n fieldName: alternativeRootFieldName(this.conf.alternativeRoot),\n };\n\n const altRoot = tx.createEphemeral(ClientRoot);\n tx.lock(altRoot);\n tx.createField(aFId, 'Dynamic');\n tx.setField(aFId, altRoot);\n await tx.commit();\n\n return await altRoot.globalId;\n }\n });\n }\n\n /** Returns true if field existed */\n public async deleteAlternativeRoot(alternativeRootName: string): Promise<boolean> {\n this.checkInitialized();\n if (this._ll.conf.alternativeRoot !== undefined)\n throw new Error('Initialized with alternative root.');\n return await this.withWriteTx('delete-alternative-root', async (tx) => {\n const fId = {\n resourceId: tx.clientRoot,\n fieldName: alternativeRootFieldName(alternativeRootName),\n };\n const exists = tx.fieldExists(fId);\n tx.removeField(fId);\n await tx.commit();\n return await exists;\n });\n }\n\n private async _withTx<T>(\n name: string,\n writable: boolean,\n clientRoot: OptionalResourceId,\n body: (tx: PlTransaction) => Promise<T>,\n ops?: TxOps,\n ): Promise<T> {\n // for exponential / linear backoff\n let retryState = createRetryState(ops?.retryOptions ?? this.defaultRetryOptions);\n\n while (true) {\n const release = ops?.lockId ? await advisoryLock(ops.lockId) : () => {};\n\n try {\n // opening low-level tx\n const llTx = this._ll.createTx(writable, ops);\n // wrapping it into high-level tx (this also asynchronously sends initialization message)\n const tx = new PlTransaction(\n llTx,\n name,\n writable,\n clientRoot,\n this.finalPredicate,\n this.resourceDataCache,\n );\n\n let ok = false;\n let result: T | undefined = undefined;\n let txId;\n\n try {\n // executing transaction body\n result = await body(tx);\n // collecting stat\n this._txCommittedStat = addStat(this._txCommittedStat, tx.stat);\n ok = true;\n } catch (e: unknown) {\n // the only recoverable\n if (e instanceof TxCommitConflict) {\n // ignoring\n // collecting stat\n this._txConflictStat = addStat(this._txConflictStat, tx.stat);\n } else {\n // collecting stat\n this._txErrorStat = addStat(this._txErrorStat, tx.stat);\n throw e;\n }\n } finally {\n // close underlying grpc stream, if not yet done\n\n // even though we can skip two lines below for read-only transactions,\n // we don't do it to simplify reasoning about what is going on in\n // concurrent code, especially in significant latency situations\n await tx.complete();\n await tx.await();\n\n txId = await tx.getGlobalTxId();\n }\n\n if (ok) {\n // syncing on transaction if requested\n if (ops?.sync === undefined ? this.forceSync : ops?.sync)\n await this._ll.grpcPl.get().txSync({ txId });\n\n // introducing artificial delay, if requested\n if (writable && this.txDelay > 0)\n await tp.setTimeout(this.txDelay, undefined, { signal: ops?.abortSignal });\n\n return result!;\n }\n } finally {\n release();\n }\n\n // we only get here after TxCommitConflict error,\n // all other errors terminate this loop instantly\n\n await tp.setTimeout(retryState.nextDelay, undefined, { signal: ops?.abortSignal });\n retryState = nextRetryStateOrError(retryState);\n }\n }\n\n private async withTx<T>(\n name: string,\n writable: boolean,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n this.checkInitialized();\n return await this._withTx(name, writable, this.clientRoot, body, { ...ops, ...defaultTxOps });\n }\n\n public async withWriteTx<T>(\n name: string,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n return await this.withTx(name, true, body, { ...ops, ...defaultTxOps });\n }\n\n public async withReadTx<T>(\n name: string,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n return await this.withTx(name, false, body, { ...ops, ...defaultTxOps });\n }\n\n public getDriver<Drv extends PlDriver>(definition: PlDriverDefinition<Drv>): Drv {\n const attached = this.drivers.get(definition.name);\n if (attached !== undefined) return attached as Drv;\n const driver = definition.init(this, this._ll, this.httpDispatcher);\n this.drivers.set(definition.name, driver);\n return driver;\n }\n\n /** Closes underlying transport */\n public async close() {\n await this._ll.close();\n }\n\n public static async init(\n configOrAddress: PlClientConfig | string,\n auth: AuthOps,\n ops: {\n statusListener?: PlConnectionStatusListener;\n } = {},\n ) {\n const pl = new PlClient(configOrAddress, auth, ops);\n await pl.init();\n return pl;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,YAAY,GAAG;AACnB,IAAA,IAAI,EAAE,KAAK;CACZ;AAED,MAAM,mBAAmB,GAAG,eAAe;AAE3C,SAAS,wBAAwB,CAAC,eAAuB,EAAA;IACvD,OAAO,CAAA,iBAAA,EAAoB,eAAe,CAAA,CAAE;AAC9C;AAEA;MACa,QAAQ,CAAA;AACF,IAAA,OAAO,GAAG,IAAI,GAAG,EAAoB;AAEtD;AACkF;AACjE,IAAA,OAAO;;AAGP,IAAA,SAAS;;AAGT,IAAA,mBAAmB;AAEnB,IAAA,eAAe;AACxB,IAAA,GAAG;;IAEH,WAAW,GAAuB,cAAc;IAEhD,WAAW,GAA6C,SAAS;IAEjE,gBAAgB,GAAW,aAAa,EAAE;IAC1C,eAAe,GAAW,aAAa,EAAE;IACzC,YAAY,GAAW,aAAa,EAAE;;;;;AAO9B,IAAA,cAAc;;AAGb,IAAA,iBAAiB;AAElC,IAAA,WAAA,CACE,eAAwC,EACxC,IAAa,EACb,MAGI,EAAE,EAAA;;AAGN,QAAA,IAAI,CAAC,eAAe,GAAG,CAAC,aAAsB,KAAI;AAChD,YAAA,OAAO,IA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|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/core/client.ts"],"sourcesContent":["import type { AuthOps, PlClientConfig, PlConnectionStatusListener } from './config';\nimport type { PlCallOps } from './ll_client';\nimport { LLPlClient } from './ll_client';\nimport type { AnyResourceRef } from './transaction';\nimport { PlTransaction, toGlobalResourceId, TxCommitConflict } from './transaction';\nimport { createHash } from 'node:crypto';\nimport type { OptionalResourceId, ResourceId } from './types';\nimport { ensureResourceIdNotNull, isNullResourceId, NullResourceId } from './types';\nimport { ClientRoot } from '../helpers/pl';\nimport type { RetryOptions } from '@milaboratories/ts-helpers';\nimport { assertNever, createRetryState, nextRetryStateOrError } from '@milaboratories/ts-helpers';\nimport type { PlDriver, PlDriverDefinition } from './driver';\nimport type { MaintenanceAPI_Ping_Response, MaintenanceAPI_License_Response } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';\nimport { MaintenanceAPI_Ping_Response_Compression } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';\nimport * as tp from 'node:timers/promises';\nimport type { Dispatcher } from 'undici';\nimport { LRUCache } from 'lru-cache';\nimport type { ResourceDataCacheRecord } from './cache';\nimport type { FinalResourceDataPredicate } from './final';\nimport { DefaultFinalResourceDataPredicate } from './final';\nimport type { AllTxStat, TxStat } from './stat';\nimport { addStat, initialTxStat } from './stat';\nimport type { WireConnection } from './wire';\nimport { advisoryLock } from './advisory_locks';\n\nexport type TxOps = PlCallOps & {\n sync?: boolean;\n retryOptions?: RetryOptions;\n name?: string;\n lockId?: string;\n};\n\nconst defaultTxOps = {\n sync: false,\n};\n\nconst AnonymousClientRoot = 'AnonymousRoot';\n\nfunction alternativeRootFieldName(alternativeRoot: string): string {\n return `alternative_root_${alternativeRoot}`;\n}\n\n/** Client to access core PL API. */\nexport class PlClient {\n private readonly drivers = new Map<string, PlDriver>();\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n private readonly txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n private readonly forceSync: boolean;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n private readonly defaultRetryOptions: RetryOptions;\n\n private readonly buildLLPlClient: (shouldUseGzip: boolean) => LLPlClient;\n private _ll: LLPlClient;\n /** Stores client root (this abstraction is intended for future implementation of the security model) */\n private _clientRoot: OptionalResourceId = NullResourceId;\n\n private _serverInfo: MaintenanceAPI_Ping_Response | undefined = undefined;\n\n private _txCommittedStat: TxStat = initialTxStat();\n private _txConflictStat: TxStat = initialTxStat();\n private _txErrorStat: TxStat = initialTxStat();\n\n //\n // Caching\n //\n\n /** This function determines whether resource data can be cached */\n public readonly finalPredicate: FinalResourceDataPredicate;\n\n /** Resource data cache, to minimize redundant data rereading from remote db */\n private readonly resourceDataCache: LRUCache<ResourceId, ResourceDataCacheRecord>;\n\n private constructor(\n configOrAddress: PlClientConfig | string,\n auth: AuthOps,\n ops: {\n statusListener?: PlConnectionStatusListener;\n finalPredicate?: FinalResourceDataPredicate;\n } = {},\n ) {\n // Will reinitialize client after getting available feature from server.\n this.buildLLPlClient = (shouldUseGzip: boolean) => {\n return new LLPlClient(configOrAddress, { auth, ...ops, shouldUseGzip });\n };\n this._ll = this.buildLLPlClient(false);\n const conf = this._ll.conf;\n this.txDelay = conf.txDelay;\n this.forceSync = conf.forceSync;\n this.finalPredicate = ops.finalPredicate ?? DefaultFinalResourceDataPredicate;\n this.resourceDataCache = new LRUCache({\n maxSize: conf.maxCacheBytes,\n sizeCalculation: (v) => (v.basicData.data?.length ?? 0) + 64,\n });\n switch (conf.retryBackoffAlgorithm) {\n case 'exponential':\n this.defaultRetryOptions = {\n type: 'exponentialBackoff',\n initialDelay: conf.retryInitialDelay,\n maxAttempts: conf.retryMaxAttempts,\n backoffMultiplier: conf.retryExponentialBackoffMultiplier,\n jitter: conf.retryJitter,\n };\n break;\n case 'linear':\n this.defaultRetryOptions = {\n type: 'linearBackoff',\n initialDelay: conf.retryInitialDelay,\n maxAttempts: conf.retryMaxAttempts,\n backoffStep: conf.retryLinearBackoffStep,\n jitter: conf.retryJitter,\n };\n break;\n default:\n assertNever(conf.retryBackoffAlgorithm);\n }\n }\n\n public get txCommittedStat(): TxStat {\n return { ...this._txCommittedStat };\n }\n\n public get txConflictStat(): TxStat {\n return { ...this._txConflictStat };\n }\n\n public get txErrorStat(): TxStat {\n return { ...this._txErrorStat };\n }\n\n public get txTotalStat(): TxStat {\n return addStat(addStat(this._txCommittedStat, this._txConflictStat), this._txErrorStat);\n }\n\n public get allTxStat(): AllTxStat {\n return {\n committed: this.txCommittedStat,\n conflict: this.txConflictStat,\n error: this.txErrorStat,\n };\n }\n\n public async ping(): Promise<MaintenanceAPI_Ping_Response> {\n return await this._ll.ping();\n }\n\n public async license(): Promise<MaintenanceAPI_License_Response> {\n return await this._ll.license();\n }\n\n public get conf(): PlClientConfig {\n return this._ll.conf;\n }\n\n public get httpDispatcher(): Dispatcher {\n return this._ll.httpDispatcher;\n }\n\n public get connectionOpts(): WireConnection {\n return this._ll.wireConnection;\n }\n\n private get initialized() {\n return !isNullResourceId(this._clientRoot);\n }\n\n private checkInitialized() {\n if (!this.initialized) throw new Error('Client not initialized');\n }\n\n public get clientRoot(): ResourceId {\n this.checkInitialized();\n return ensureResourceIdNotNull(this._clientRoot);\n }\n\n public get serverInfo(): MaintenanceAPI_Ping_Response {\n this.checkInitialized();\n return this._serverInfo!;\n }\n\n /** Currently implements custom logic to emulate future behaviour with single root. */\n public async init() {\n if (this.initialized) throw new Error('Already initialized');\n\n // calculating reproducible root name from the username\n const user = this._ll.authUser;\n const mainRootName\n = user === null ? AnonymousClientRoot : createHash('sha256').update(user).digest('hex');\n\n this._serverInfo = await this.ping();\n if (this._serverInfo.compression === MaintenanceAPI_Ping_Response_Compression.GZIP) {\n await this._ll.close();\n this._ll = this.buildLLPlClient(true);\n }\n\n this._clientRoot = await this._withTx('initialization', true, NullResourceId, async (tx) => {\n let mainRoot: AnyResourceRef;\n\n if (await tx.checkResourceNameExists(mainRootName))\n mainRoot = await tx.getResourceByName(mainRootName);\n else {\n mainRoot = tx.createRoot(ClientRoot);\n tx.setResourceName(mainRootName, mainRoot);\n }\n\n if (this.conf.alternativeRoot === undefined) {\n await tx.commit();\n return await toGlobalResourceId(mainRoot);\n } else {\n const aFId = {\n resourceId: mainRoot,\n fieldName: alternativeRootFieldName(this.conf.alternativeRoot),\n };\n\n const altRoot = tx.createEphemeral(ClientRoot);\n tx.lock(altRoot);\n tx.createField(aFId, 'Dynamic');\n tx.setField(aFId, altRoot);\n await tx.commit();\n\n return await altRoot.globalId;\n }\n });\n }\n\n /** Returns true if field existed */\n public async deleteAlternativeRoot(alternativeRootName: string): Promise<boolean> {\n this.checkInitialized();\n if (this._ll.conf.alternativeRoot !== undefined)\n throw new Error('Initialized with alternative root.');\n return await this.withWriteTx('delete-alternative-root', async (tx) => {\n const fId = {\n resourceId: tx.clientRoot,\n fieldName: alternativeRootFieldName(alternativeRootName),\n };\n const exists = tx.fieldExists(fId);\n tx.removeField(fId);\n await tx.commit();\n return await exists;\n });\n }\n\n private async _withTx<T>(\n name: string,\n writable: boolean,\n clientRoot: OptionalResourceId,\n body: (tx: PlTransaction) => Promise<T>,\n ops?: TxOps,\n ): Promise<T> {\n // for exponential / linear backoff\n let retryState = createRetryState(ops?.retryOptions ?? this.defaultRetryOptions);\n\n while (true) {\n const release = ops?.lockId ? await advisoryLock(ops.lockId) : () => {};\n\n try {\n // opening low-level tx\n const llTx = this._ll.createTx(writable, ops);\n // wrapping it into high-level tx (this also asynchronously sends initialization message)\n const tx = new PlTransaction(\n llTx,\n name,\n writable,\n clientRoot,\n this.finalPredicate,\n this.resourceDataCache,\n );\n\n let ok = false;\n let result: T | undefined = undefined;\n let txId;\n\n try {\n // executing transaction body\n result = await body(tx);\n // collecting stat\n this._txCommittedStat = addStat(this._txCommittedStat, tx.stat);\n ok = true;\n } catch (e: unknown) {\n // the only recoverable\n if (e instanceof TxCommitConflict) {\n // ignoring\n // collecting stat\n this._txConflictStat = addStat(this._txConflictStat, tx.stat);\n } else {\n // collecting stat\n this._txErrorStat = addStat(this._txErrorStat, tx.stat);\n throw e;\n }\n } finally {\n // close underlying grpc stream, if not yet done\n\n // even though we can skip two lines below for read-only transactions,\n // we don't do it to simplify reasoning about what is going on in\n // concurrent code, especially in significant latency situations\n await tx.complete();\n await tx.await();\n\n txId = await tx.getGlobalTxId();\n }\n\n if (ok) {\n // syncing on transaction if requested\n if (ops?.sync === undefined ? this.forceSync : ops?.sync)\n await this._ll.txSync(txId);\n\n // introducing artificial delay, if requested\n if (writable && this.txDelay > 0)\n await tp.setTimeout(this.txDelay, undefined, { signal: ops?.abortSignal });\n\n return result!;\n }\n } finally {\n release();\n }\n\n // we only get here after TxCommitConflict error,\n // all other errors terminate this loop instantly\n\n await tp.setTimeout(retryState.nextDelay, undefined, { signal: ops?.abortSignal });\n retryState = nextRetryStateOrError(retryState);\n }\n }\n\n private async withTx<T>(\n name: string,\n writable: boolean,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n this.checkInitialized();\n return await this._withTx(name, writable, this.clientRoot, body, { ...ops, ...defaultTxOps });\n }\n\n public async withWriteTx<T>(\n name: string,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n return await this.withTx(name, true, body, { ...ops, ...defaultTxOps });\n }\n\n public async withReadTx<T>(\n name: string,\n body: (tx: PlTransaction) => Promise<T>,\n ops: Partial<TxOps> = {},\n ): Promise<T> {\n return await this.withTx(name, false, body, { ...ops, ...defaultTxOps });\n }\n\n public getDriver<Drv extends PlDriver>(definition: PlDriverDefinition<Drv>): Drv {\n const attached = this.drivers.get(definition.name);\n if (attached !== undefined) return attached as Drv;\n const driver = definition.init(this, this._ll, this.httpDispatcher);\n this.drivers.set(definition.name, driver);\n return driver;\n }\n\n /** Closes underlying transport */\n public async close() {\n await this._ll.close();\n }\n\n public static async init(\n configOrAddress: PlClientConfig | string,\n auth: AuthOps,\n ops: {\n statusListener?: PlConnectionStatusListener;\n } = {},\n ) {\n const pl = new PlClient(configOrAddress, auth, ops);\n await pl.init();\n return pl;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,YAAY,GAAG;AACnB,IAAA,IAAI,EAAE,KAAK;CACZ;AAED,MAAM,mBAAmB,GAAG,eAAe;AAE3C,SAAS,wBAAwB,CAAC,eAAuB,EAAA;IACvD,OAAO,CAAA,iBAAA,EAAoB,eAAe,CAAA,CAAE;AAC9C;AAEA;MACa,QAAQ,CAAA;AACF,IAAA,OAAO,GAAG,IAAI,GAAG,EAAoB;AAEtD;AACkF;AACjE,IAAA,OAAO;;AAGP,IAAA,SAAS;;AAGT,IAAA,mBAAmB;AAEnB,IAAA,eAAe;AACxB,IAAA,GAAG;;IAEH,WAAW,GAAuB,cAAc;IAEhD,WAAW,GAA6C,SAAS;IAEjE,gBAAgB,GAAW,aAAa,EAAE;IAC1C,eAAe,GAAW,aAAa,EAAE;IACzC,YAAY,GAAW,aAAa,EAAE;;;;;AAO9B,IAAA,cAAc;;AAGb,IAAA,iBAAiB;AAElC,IAAA,WAAA,CACE,eAAwC,EACxC,IAAa,EACb,MAGI,EAAE,EAAA;;AAGN,QAAA,IAAI,CAAC,eAAe,GAAG,CAAC,aAAsB,KAAI;AAChD,YAAA,OAAO,IAAI,UAAU,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,GAAG,GAAG,EAAE,aAAa,EAAE,CAAC;AACzE,QAAA,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;AACtC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI;AAC1B,QAAA,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO;AAC3B,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS;QAC/B,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC,cAAc,I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AAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QAClD,IAAI,QAAQ,KAAK,SAAS;AAAE,YAAA,OAAO,QAAe;AAClD,QAAA,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC;QACnE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;AACzC,QAAA,OAAO,MAAM;IACf;;AAGO,IAAA,MAAM,KAAK,GAAA;AAChB,QAAA,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;IACxB;IAEO,aAAa,IAAI,CACtB,eAAwC,EACxC,IAAa,EACb,GAAA,GAEI,EAAE,EAAA;QAEN,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,eAAe,EAAE,IAAI,EAAE,GAAG,CAAC;AACnD,QAAA,MAAM,EAAE,CAAC,IAAI,EAAE;AACf,QAAA,OAAO,EAAE;IACX;AACD;;;;"}
|
package/dist/core/config.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const SUPPORTED_WIRE_PROTOCOLS = ['grpc', 'rest'];
|
|
3
4
|
const DEFAULT_REQUEST_TIMEOUT = 5_000;
|
|
4
5
|
const DEFAULT_RO_TX_TIMEOUT = 300_000;
|
|
5
6
|
const DEFAULT_RW_TX_TIMEOUT = 60_000;
|
|
@@ -76,6 +77,7 @@ function plAddressToConfig(address, overrides = {}) {
|
|
|
76
77
|
hostAndPort: `${url.hostname}:${port}`,
|
|
77
78
|
alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,
|
|
78
79
|
ssl: url.protocol === 'https:' || url.protocol === 'tls:',
|
|
80
|
+
wireProtocol: url.searchParams.get('wire-protocol') ?? undefined,
|
|
79
81
|
defaultRequestTimeout: parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,
|
|
80
82
|
defaultROTransactionTimeout: parseInt(url.searchParams.get('ro-tx-timeout'))
|
|
81
83
|
?? parseInt(url.searchParams.get('tx-timeout'))
|
|
@@ -120,5 +122,6 @@ exports.DEFAULT_RO_TX_TIMEOUT = DEFAULT_RO_TX_TIMEOUT;
|
|
|
120
122
|
exports.DEFAULT_RW_TX_TIMEOUT = DEFAULT_RW_TX_TIMEOUT;
|
|
121
123
|
exports.DEFAULT_TOKEN_TTL_SECONDS = DEFAULT_TOKEN_TTL_SECONDS;
|
|
122
124
|
exports.DefaultRetryOptions = DefaultRetryOptions;
|
|
125
|
+
exports.SUPPORTED_WIRE_PROTOCOLS = SUPPORTED_WIRE_PROTOCOLS;
|
|
123
126
|
exports.plAddressToConfig = plAddressToConfig;
|
|
124
127
|
//# sourceMappingURL=config.cjs.map
|
package/dist/core/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from '@milaboratories/pl-http';\nimport type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: 'exponential' | 'linear';\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = 'exponential';\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: 'exponentialBackoff',\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | 'ssl'\n | 'defaultRequestTimeout'\n | 'defaultROTransactionTimeout'\n | 'defaultRWTransactionTimeout'\n | 'httpProxy'\n | 'grpcProxy'\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf('://') === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== 'https:'\n && url.protocol !== 'http:'\n && url.protocol !== 'grpc:'\n && url.protocol !== 'tls:'\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== '/' && url.pathname !== '')\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case 'http:':\n port = '80';\n break;\n case 'https:':\n port = '443';\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,\n ssl: url.protocol === 'https:' || url.protocol === 'tls:',\n defaultRequestTimeout:\n parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get('ro-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get('rw-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,\n httpProxy: url.searchParams.get('http-proxy') ?? undefined,\n user: url.username === '' ? undefined : url.username,\n password: url.password === '' ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get('tx-delay')) ?? 0,\n forceSync: Boolean(url.searchParams.get('force-sync')),\n\n maxCacheBytes: parseInt(url.searchParams.get('max-cache-bytes')) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get('retry-backoff-algorithm')\n ?? DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get('retry-max-attempts')) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get('retry-initial-delay')) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get('retry-exp-backoff-multiplier'))\n ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get('retry-linear-backoff-step'))\n ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get('retry-backoff-jitter')) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = 'OK' | 'Disconnected' | 'Unauthenticated';\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus) => void;\n"],"names":[],"mappings":";;AAmFO,MAAM,uBAAuB,GA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AY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAEtD,QAAA,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,uBAAuB;QAE3F,qBAAqB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,yBAAyB;AACjE,eAAA,+BAA+B,CAAQ;AAC5C,QAAA,gBAAgB,EACd,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,0BAA0B;AACpF,QAAA,iBAAiB,EACf,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,2BAA2B;QACtF,iCAAiC,EAC/B,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,8BAA8B,CAAC;eAC1D,4CAA4C;QACjD,sBAAsB,EACpB,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,2BAA2B,CAAC;eACvD,iCAAiC;AACtC,QAAA,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,oBAAoB;AAE3F,QAAA,GAAG,SAAS;KACb;AACH;AAWO,MAAM,wBAAwB,GAAoB;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"config.cjs","sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from '@milaboratories/pl-http';\nimport type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';\n\nexport const SUPPORTED_WIRE_PROTOCOLS = ['grpc', 'rest'] as const;\nexport type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** Type of wire connection (protocol server uses for communication) */\n wireProtocol?: wireProtocol;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: 'exponential' | 'linear';\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = 'exponential';\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: 'exponentialBackoff',\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | 'ssl'\n | 'defaultRequestTimeout'\n | 'defaultROTransactionTimeout'\n | 'defaultRWTransactionTimeout'\n | 'httpProxy'\n | 'grpcProxy'\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf('://') === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== 'https:'\n && url.protocol !== 'http:'\n && url.protocol !== 'grpc:'\n && url.protocol !== 'tls:'\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== '/' && url.pathname !== '')\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case 'http:':\n port = '80';\n break;\n case 'https:':\n port = '443';\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,\n ssl: url.protocol === 'https:' || url.protocol === 'tls:',\n\n wireProtocol: url.searchParams.get('wire-protocol') as wireProtocol ?? undefined,\n\n defaultRequestTimeout:\n parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get('ro-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get('rw-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,\n httpProxy: url.searchParams.get('http-proxy') ?? undefined,\n user: url.username === '' ? undefined : url.username,\n password: url.password === '' ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get('tx-delay')) ?? 0,\n forceSync: Boolean(url.searchParams.get('force-sync')),\n\n maxCacheBytes: parseInt(url.searchParams.get('max-cache-bytes')) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get('retry-backoff-algorithm')\n ?? DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get('retry-max-attempts')) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get('retry-initial-delay')) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get('retry-exp-backoff-multiplier'))\n ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get('retry-linear-backoff-step'))\n ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get('retry-backoff-jitter')) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = 'OK' | 'Disconnected' | 'Unauthenticated';\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus) => void;\n"],"names":[],"mappings":";;MAGa,wBAAwB,GAAG,CAAC,MAAM,EAAE,MAAM;AAsFhD,MAAM,uBAAuB,GAAG;AAChC,MAAM,qBAAqB,GAAG;AAC9B,MAAM,qBAAqB,GAAG;AAC9B,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;AACjD,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;AAEhD,MAAM,uBAAuB,GAAG,YAAY;AAE5C,MAAM,+BAA+B,GAAG;AACxC,MAAM,0BAA0B,GAAG,GAAG;AACtC,MAAM,2BAA2B,GAAG,GAAG;AACvC,MAAM,4CAA4C,GAAG,IAAI;AACzD,MAAM,iCAAiC,GAAG,GAAG;AAC7C,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,mBAAmB,GAAmC;AACjE,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,WAAW,EAAE,0BAA0B;AACvC,IAAA,YAAY,EAAE,2BAA2B;AACzC,IAAA,iBAAiB,EAAE,4CAA4C;AAC/D,IAAA,MAAM,EAAE,oBAAoB;;AAe9B,SAAS,QAAQ,CAAC,CAA4B,EAAA;AAC5C,IAAA,IAAI,CAAC,CAAC;AAAE,QAAA,OAAO,SAAS;AACxB,IAA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AAC,2BAA2B,CAAC;eACvD,iCAAiC;AACtC,QAAA,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,oBAAoB;AAE3F,QAAA,GAAG,SAAS;KACb;AACH;AAWO,MAAM,wBAAwB,GAAoB;;;;;;;;;;;;;;;;;;;"}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ProxySettings } from '@milaboratories/pl-http';
|
|
2
2
|
import type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';
|
|
3
|
+
export declare const SUPPORTED_WIRE_PROTOCOLS: readonly ["grpc", "rest"];
|
|
4
|
+
export type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];
|
|
3
5
|
/** Base configuration structure for PL client */
|
|
4
6
|
export interface PlClientConfig {
|
|
5
7
|
/** Port and host of remote pl server */
|
|
6
8
|
hostAndPort: string;
|
|
9
|
+
/** Type of wire connection (protocol server uses for communication) */
|
|
10
|
+
wireProtocol?: wireProtocol;
|
|
7
11
|
/** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a
|
|
8
12
|
* client root. */
|
|
9
13
|
alternativeRoot?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAEjF,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB;sBACkB;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;8BAC0B;IAI1B,GAAG,EAAE,OAAO,CAAC;IAEb,4EAA4E;IAC5E,qBAAqB,EAAE,MAAM,CAAC;IAE9B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,GAC7B,6BAA6B,GAC7B,WAAW,GACX,WAAW,CACd,CACF,CAAC;AASF;0DAC0D;AAC1D,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,iBAAsB,GAChC,cAAc,CAiGhB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,wBAAwB,EAAE,eAAoB,CAAC;AAE5D,kEAAkE;AAClE,MAAM,WAAW,OAAO;IACtB,wCAAwC;IACxC,eAAe,EAAE,eAAe,CAAC;IACjC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACvD,oFAAoF;IACpF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACnD;AAED,yBAAyB;AACzB,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE3E,wEAAwE;AACxE,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC"}
|
package/dist/core/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const SUPPORTED_WIRE_PROTOCOLS = ['grpc', 'rest'];
|
|
1
2
|
const DEFAULT_REQUEST_TIMEOUT = 5_000;
|
|
2
3
|
const DEFAULT_RO_TX_TIMEOUT = 300_000;
|
|
3
4
|
const DEFAULT_RW_TX_TIMEOUT = 60_000;
|
|
@@ -74,6 +75,7 @@ function plAddressToConfig(address, overrides = {}) {
|
|
|
74
75
|
hostAndPort: `${url.hostname}:${port}`,
|
|
75
76
|
alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,
|
|
76
77
|
ssl: url.protocol === 'https:' || url.protocol === 'tls:',
|
|
78
|
+
wireProtocol: url.searchParams.get('wire-protocol') ?? undefined,
|
|
77
79
|
defaultRequestTimeout: parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,
|
|
78
80
|
defaultROTransactionTimeout: parseInt(url.searchParams.get('ro-tx-timeout'))
|
|
79
81
|
?? parseInt(url.searchParams.get('tx-timeout'))
|
|
@@ -104,5 +106,5 @@ function plAddressToConfig(address, overrides = {}) {
|
|
|
104
106
|
}
|
|
105
107
|
const AnonymousAuthInformation = {};
|
|
106
108
|
|
|
107
|
-
export { AnonymousAuthInformation, DEFAULT_AUTH_MAX_REFRESH, DEFAULT_MAX_CACHE_BYTES, DEFAULT_REQUEST_TIMEOUT, DEFAULT_RETRY_BACKOFF_ALGORITHM, DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY, DEFAULT_RETRY_JITTER, DEFAULT_RETRY_LINEAR_BACKOFF_STEP, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RO_TX_TIMEOUT, DEFAULT_RW_TX_TIMEOUT, DEFAULT_TOKEN_TTL_SECONDS, DefaultRetryOptions, plAddressToConfig };
|
|
109
|
+
export { AnonymousAuthInformation, DEFAULT_AUTH_MAX_REFRESH, DEFAULT_MAX_CACHE_BYTES, DEFAULT_REQUEST_TIMEOUT, DEFAULT_RETRY_BACKOFF_ALGORITHM, DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY, DEFAULT_RETRY_JITTER, DEFAULT_RETRY_LINEAR_BACKOFF_STEP, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RO_TX_TIMEOUT, DEFAULT_RW_TX_TIMEOUT, DEFAULT_TOKEN_TTL_SECONDS, DefaultRetryOptions, SUPPORTED_WIRE_PROTOCOLS, plAddressToConfig };
|
|
108
110
|
//# sourceMappingURL=config.js.map
|
package/dist/core/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from '@milaboratories/pl-http';\nimport type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: 'exponential' | 'linear';\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = 'exponential';\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: 'exponentialBackoff',\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | 'ssl'\n | 'defaultRequestTimeout'\n | 'defaultROTransactionTimeout'\n | 'defaultRWTransactionTimeout'\n | 'httpProxy'\n | 'grpcProxy'\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf('://') === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== 'https:'\n && url.protocol !== 'http:'\n && url.protocol !== 'grpc:'\n && url.protocol !== 'tls:'\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== '/' && url.pathname !== '')\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case 'http:':\n port = '80';\n break;\n case 'https:':\n port = '443';\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,\n ssl: url.protocol === 'https:' || url.protocol === 'tls:',\n defaultRequestTimeout:\n parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get('ro-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get('rw-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,\n httpProxy: url.searchParams.get('http-proxy') ?? undefined,\n user: url.username === '' ? undefined : url.username,\n password: url.password === '' ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get('tx-delay')) ?? 0,\n forceSync: Boolean(url.searchParams.get('force-sync')),\n\n maxCacheBytes: parseInt(url.searchParams.get('max-cache-bytes')) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get('retry-backoff-algorithm')\n ?? DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get('retry-max-attempts')) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get('retry-initial-delay')) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get('retry-exp-backoff-multiplier'))\n ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get('retry-linear-backoff-step'))\n ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get('retry-backoff-jitter')) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = 'OK' | 'Disconnected' | 'Unauthenticated';\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus) => void;\n"],"names":[],"mappings":"AAmFO,MAAM,uBAAuB,GAAG;AAChC,MAAM,qBAAqB,GAAG;AAC9B,MAAM,qBAAqB,GAAG;AAC9B,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;AACjD,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;AAEhD,MAAM,uBAAuB,GAAG,YAAY;AAE5C,MAAM,+BAA+B,GAAG;AACxC,MAAM,0BAA0B,GAAG,GAAG;AACtC,MAAM,2BAA2B,GAAG,GAAG;AACvC,MAAM,4CAA4C,GAAG,IAAI;AACzD,MAAM,iCAAiC,GAAG,GAAG;AAC7C,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,mBAAmB,GAAmC;AACjE,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,WAAW,EAAE,0BAA0B;AACvC,IAAA,YAAY,EAAE,2BAA2B;AACzC,IAAA,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eAC1D,4CAA4C;QACjD,sBAAsB,EACpB,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,2BAA2B,CAAC;eACvD,iCAAiC;AACtC,QAAA,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,oBAAoB;AAE3F,QAAA,GAAG,SAAS;KACb;AACH;AAWO,MAAM,wBAAwB,GAAoB;;;;"}
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../src/core/config.ts"],"sourcesContent":["import type { ProxySettings } from '@milaboratories/pl-http';\nimport type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';\n\nexport const SUPPORTED_WIRE_PROTOCOLS = ['grpc', 'rest'] as const;\nexport type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];\n\n/** Base configuration structure for PL client */\nexport interface PlClientConfig {\n /** Port and host of remote pl server */\n hostAndPort: string;\n\n /** Type of wire connection (protocol server uses for communication) */\n wireProtocol?: wireProtocol;\n\n /** If set, client will expose a nested object under a field with name `alternative_root_${alternativeRoot}` as a\n * client root. */\n alternativeRoot?: string;\n\n /** If true, client will establish tls connection to the server, using default\n * CA of node instance. */\n // Not implementing custom ssl validation logic for now.\n // Implementing it in a correct way is really nontrivial thing,\n // real use-cases should be considered.\n ssl: boolean;\n\n /** Default timeout in milliseconds for unary calls, like ping and login. */\n defaultRequestTimeout: number;\n\n /** Default timeout in milliseconds for read-write transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultRWTransactionTimeout: number;\n /** Default timeout in milliseconds for read-only transaction, should be\n * adjusted for long round-trip or low bandwidth connections. */\n defaultROTransactionTimeout: number;\n\n /** Controls what TTL will be requested from the server, when new JWT token\n * is requested. */\n authTTLSeconds: number;\n /** If token is older than this time, it will be refreshed regardless of its\n * expiration time. */\n authMaxRefreshSeconds: number;\n\n /** Proxy server config to use for pl connection. */\n grpcProxy?: string | ProxySettings;\n /** Proxy server config to use for http connections of pl drivers, like file\n * downloading. */\n httpProxy?: string | ProxySettings;\n\n /** Username extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n user?: string;\n /** Password extracted from pl URL. Ignored by {@link PlClient}, picked up by {@link defaultPlClient}. */\n password?: string;\n\n /** Artificial delay introduced after write transactions completion, to\n * somewhat throttle the load on pl. Delay introduced after sync, if requested. */\n txDelay: number;\n\n /** Last resort measure to solve complicated race conditions in pl. */\n forceSync: boolean;\n\n /** Maximal number of bytes of resource state to cache */\n maxCacheBytes: number;\n\n //\n // Retry\n //\n\n /**\n * What type of backoff strategy to use in transaction retries\n * (pl uses optimistic transaction model with regular retries in write transactions)\n */\n retryBackoffAlgorithm: 'exponential' | 'linear';\n\n /** Maximal number of attempts in */\n retryMaxAttempts: number;\n\n /** Delay after first failed attempt, in ms. */\n retryInitialDelay: number;\n\n /** Each time delay will be multiplied by this number (1.5 means plus on 50% each attempt) */\n retryExponentialBackoffMultiplier: number;\n\n /** [used only for ] This value will be added to the delay from the previous step, in ms */\n retryLinearBackoffStep: number;\n\n /** Value from 0 to 1, determine level of randomness to introduce to the backoff delays sequence. (0 meaning no randomness) */\n retryJitter: number;\n}\n\nexport const DEFAULT_REQUEST_TIMEOUT = 5_000;\nexport const DEFAULT_RO_TX_TIMEOUT = 300_000;\nexport const DEFAULT_RW_TX_TIMEOUT = 60_000;\nexport const DEFAULT_TOKEN_TTL_SECONDS = 31 * 24 * 60 * 60;\nexport const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;\n\nexport const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb\n\nexport const DEFAULT_RETRY_BACKOFF_ALGORITHM = 'exponential';\nexport const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries\nexport const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure\nexport const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round\nexport const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms\nexport const DEFAULT_RETRY_JITTER = 0.3; // 30%\n\nexport const DefaultRetryOptions: ExponentialBackoffRetryOptions = {\n type: 'exponentialBackoff',\n maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n initialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n jitter: DEFAULT_RETRY_JITTER,\n};\n\ntype PlConfigOverrides = Partial<\n Pick<\n PlClientConfig,\n | 'ssl'\n | 'defaultRequestTimeout'\n | 'defaultROTransactionTimeout'\n | 'defaultRWTransactionTimeout'\n | 'httpProxy'\n | 'grpcProxy'\n >\n>;\n\nfunction parseInt(s: string | null | undefined): number | undefined {\n if (!s) return undefined;\n const num = Number(s);\n if (Number.isNaN(num)) throw new Error(`Can't parse number: ${s}`);\n return num;\n}\n\n/** Parses pl url and creates a config object that can be passed to\n * {@link PlClient} of {@link UnauthenticatedPlClient}. */\nexport function plAddressToConfig(\n address: string,\n overrides: PlConfigOverrides = {},\n): PlClientConfig {\n if (address.indexOf('://') === -1)\n // non-url address\n return {\n hostAndPort: address,\n ssl: false,\n defaultRequestTimeout: DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout: DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout: DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n txDelay: 0,\n forceSync: false,\n\n maxCacheBytes: DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: DEFAULT_RETRY_BACKOFF_ALGORITHM,\n retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay: DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep: DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n\n const url = new URL(address);\n\n if (\n url.protocol !== 'https:'\n && url.protocol !== 'http:'\n && url.protocol !== 'grpc:'\n && url.protocol !== 'tls:'\n )\n throw new Error(`Unexpected URL schema: ${url.protocol}`);\n\n if (url.pathname !== '/' && url.pathname !== '')\n throw new Error(`Unexpected URL path: ${url.pathname}`);\n\n let port = url.port;\n if (!port) {\n switch (url.protocol) {\n case 'http:':\n port = '80';\n break;\n case 'https:':\n port = '443';\n break;\n default:\n throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);\n }\n }\n\n return {\n hostAndPort: `${url.hostname}:${port}`,\n alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,\n ssl: url.protocol === 'https:' || url.protocol === 'tls:',\n\n wireProtocol: url.searchParams.get('wire-protocol') as wireProtocol ?? undefined,\n\n defaultRequestTimeout:\n parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,\n defaultROTransactionTimeout:\n parseInt(url.searchParams.get('ro-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RO_TX_TIMEOUT,\n defaultRWTransactionTimeout:\n parseInt(url.searchParams.get('rw-tx-timeout'))\n ?? parseInt(url.searchParams.get('tx-timeout'))\n ?? DEFAULT_RW_TX_TIMEOUT,\n authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,\n authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,\n grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,\n httpProxy: url.searchParams.get('http-proxy') ?? undefined,\n user: url.username === '' ? undefined : url.username,\n password: url.password === '' ? undefined : url.password,\n txDelay: parseInt(url.searchParams.get('tx-delay')) ?? 0,\n forceSync: Boolean(url.searchParams.get('force-sync')),\n\n maxCacheBytes: parseInt(url.searchParams.get('max-cache-bytes')) ?? DEFAULT_MAX_CACHE_BYTES,\n\n retryBackoffAlgorithm: (url.searchParams.get('retry-backoff-algorithm')\n ?? DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,\n retryMaxAttempts:\n parseInt(url.searchParams.get('retry-max-attempts')) ?? DEFAULT_RETRY_MAX_ATTEMPTS,\n retryInitialDelay:\n parseInt(url.searchParams.get('retry-initial-delay')) ?? DEFAULT_RETRY_INITIAL_DELAY,\n retryExponentialBackoffMultiplier:\n parseInt(url.searchParams.get('retry-exp-backoff-multiplier'))\n ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,\n retryLinearBackoffStep:\n parseInt(url.searchParams.get('retry-linear-backoff-step'))\n ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,\n retryJitter: parseInt(url.searchParams.get('retry-backoff-jitter')) ?? DEFAULT_RETRY_JITTER,\n\n ...overrides,\n };\n}\n\n/**\n * Authorization data / JWT Token.\n * Absent JWT Token tells the client to connect as anonymous user.\n */\nexport interface AuthInformation {\n /** Absent token means anonymous access */\n jwtToken?: string;\n}\n\nexport const AnonymousAuthInformation: AuthInformation = {};\n\n/** Authorization related settings to pass to {@link PlClient}. */\nexport interface AuthOps {\n /** Initial authorization information */\n authInformation: AuthInformation;\n /** Will be executed after successful authorization information refresh */\n readonly onUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n readonly onAuthError?: () => void;\n /** Will be executed if error encountered during token update */\n readonly onUpdateError?: (error: unknown) => void;\n}\n\n/** Connection status. */\nexport type PlConnectionStatus = 'OK' | 'Disconnected' | 'Unauthenticated';\n\n/** Listener that will be called each time connection status changes. */\nexport type PlConnectionStatusListener = (status: PlConnectionStatus) => void;\n"],"names":[],"mappings":"MAGa,wBAAwB,GAAG,CAAC,MAAM,EAAE,MAAM;AAsFhD,MAAM,uBAAuB,GAAG;AAChC,MAAM,qBAAqB,GAAG;AAC9B,MAAM,qBAA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,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAEtD,QAAA,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,uBAAuB;QAE3F,qBAAqB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,yBAAyB;AACjE,eAAA,+BAA+B,CAAQ;AAC5C,QAAA,gBAAgB,EACd,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,0BAA0B;AACpF,QAAA,iBAAiB,EACf,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,2BAA2B;QACtF,iCAAiC,EAC/B,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,8BAA8B,CAAC;eAC1D,4CAA4C;QACjD,sBAAsB,EACpB,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,2BAA2B,CAAC;eACvD,iCAAiC;AACtC,QAAA,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,oBAAoB;AAE3F,QAAA,GAAG,SAAS;KACb;AACH;AAWO,MAAM,wBAAwB,GAAoB;;;;"}
|
package/dist/core/driver.cjs
CHANGED
|
@@ -9,6 +9,17 @@ function addRTypeToMetadata(rType, options) {
|
|
|
9
9
|
options.meta['resourceType'] = `${rType.name}:${rType.version}`;
|
|
10
10
|
return options;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
14
|
+
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
15
|
+
* RPC proxy.
|
|
16
|
+
*/
|
|
17
|
+
function createRTypeRoutingHeader(rType) {
|
|
18
|
+
return {
|
|
19
|
+
resourcetype: `${rType.name}:${rType.version}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
12
22
|
|
|
13
23
|
exports.addRTypeToMetadata = addRTypeToMetadata;
|
|
24
|
+
exports.createRTypeRoutingHeader = createRTypeRoutingHeader;
|
|
14
25
|
//# 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 {
|
|
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"],"names":[],"mappings":";;AAoBA;AACA;AACA;AACM,SAAU,kBAAkB,CAAC,KAAmB,EAAE,OAAoB,EAAA;AAC1E,IAAA,OAAO,GAAG,OAAO,IAAI,EAAE;IACvB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE;AACjC,IAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAA,EAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,EAAE;AAE/D,IAAA,OAAO,OAAO;AAChB;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,KAAmB,EAAA;IAC1D,OAAO;QACL,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,CAAA,CAAE;KAC/C;AACH;;;;;"}
|
package/dist/core/driver.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { PlClient } from './client';
|
|
|
2
2
|
import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
|
|
3
3
|
import type { Dispatcher } from 'undici';
|
|
4
4
|
import type { ResourceType } from './types';
|
|
5
|
-
import type {
|
|
5
|
+
import type { WireClientProviderFactory } from './wire';
|
|
6
6
|
/** Drivers must implement this interface */
|
|
7
7
|
export interface PlDriver {
|
|
8
8
|
close(): void;
|
|
@@ -12,7 +12,13 @@ export interface PlDriverDefinition<Drv extends PlDriver> {
|
|
|
12
12
|
/** Used as key to only once instantiate specific drivers */
|
|
13
13
|
readonly name: string;
|
|
14
14
|
/** Initialization routine, will be executed only once for each driver in a specific client */
|
|
15
|
-
init(pl: PlClient,
|
|
15
|
+
init(pl: PlClient, wireClientFactory: WireClientProviderFactory, httpDispatcher: Dispatcher): Drv;
|
|
16
16
|
}
|
|
17
17
|
export declare function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions): RpcOptions;
|
|
18
|
+
/**
|
|
19
|
+
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
20
|
+
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
21
|
+
* RPC proxy.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRTypeRoutingHeader(rType: ResourceType): Record<string, string>;
|
|
18
24
|
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/core/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AAExD,4CAA4C;AAC5C,MAAM,WAAW,QAAQ;IACvB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,oDAAoD;AACpD,MAAM,WAAW,kBAAkB,CAAC,GAAG,SAAS,QAAQ;IACtD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/core/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AAExD,4CAA4C;AAC5C,MAAM,WAAW,QAAQ;IACvB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,oDAAoD;AACpD,MAAM,WAAW,kBAAkB,CAAC,GAAG,SAAS,QAAQ;IACtD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,cAAc,EAAE,UAAU,GAAG,GAAG,CAAC;CACnG;AAKD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU,cAM3E;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpF"}
|
package/dist/core/driver.js
CHANGED
|
@@ -7,6 +7,16 @@ function addRTypeToMetadata(rType, options) {
|
|
|
7
7
|
options.meta['resourceType'] = `${rType.name}:${rType.version}`;
|
|
8
8
|
return options;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* addRTypeToHeaders adds a header that helps to route request to the right resource and controller.
|
|
12
|
+
* Without this header, API router on server side cannot route request to proper controller in internal
|
|
13
|
+
* RPC proxy.
|
|
14
|
+
*/
|
|
15
|
+
function createRTypeRoutingHeader(rType) {
|
|
16
|
+
return {
|
|
17
|
+
resourcetype: `${rType.name}:${rType.version}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
10
20
|
|
|
11
|
-
export { addRTypeToMetadata };
|
|
21
|
+
export { addRTypeToMetadata, createRTypeRoutingHeader };
|
|
12
22
|
//# 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 {
|
|
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"],"names":[],"mappings":"AAoBA;AACA;AACA;AACM,SAAU,kBAAkB,CAAC,KAAmB,EAAE,OAAoB,EAAA;AAC1E,IAAA,OAAO,GAAG,OAAO,IAAI,EAAE;IACvB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE;AACjC,IAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAA,EAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,EAAE;AAE/D,IAAA,OAAO,OAAO;AAChB;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,KAAmB,EAAA;IAC1D,OAAO;QACL,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA,CAAA,EAAI,KAAK,CAAC,OAAO,CAAA,CAAE;KAC/C;AACH;;;;"}
|
package/dist/core/errors.cjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
4
|
+
var code = require('../proto-grpc/google/rpc/code.cjs');
|
|
4
5
|
|
|
5
6
|
function isConnectionProblem(err, nested = false) {
|
|
6
7
|
if (err instanceof DisconnectedError)
|
|
7
8
|
return true;
|
|
8
9
|
if (err.name == 'RpcError' && err.code == 'UNAVAILABLE')
|
|
9
10
|
return true;
|
|
11
|
+
if (err.code == code.Code.UNAVAILABLE)
|
|
12
|
+
return true;
|
|
10
13
|
if (err.cause !== undefined && !nested)
|
|
11
14
|
// nested limits the depth of search
|
|
12
15
|
return isConnectionProblem(err.cause, true);
|
|
@@ -17,6 +20,8 @@ function isUnauthenticated(err, nested = false) {
|
|
|
17
20
|
return true;
|
|
18
21
|
if (err.name == 'RpcError' && err.code == 'UNAUTHENTICATED')
|
|
19
22
|
return true;
|
|
23
|
+
if (err.code == code.Code.UNAUTHENTICATED)
|
|
24
|
+
return true;
|
|
20
25
|
if (err.cause !== undefined && !nested)
|
|
21
26
|
// nested limits the depth of search
|
|
22
27
|
return isUnauthenticated(err.cause, true);
|
|
@@ -27,9 +32,13 @@ function isTimeoutOrCancelError(err, nested = false) {
|
|
|
27
32
|
return true;
|
|
28
33
|
if (err.code == 'ABORT_ERR')
|
|
29
34
|
return true;
|
|
35
|
+
if (err.code == code.Code.ABORTED)
|
|
36
|
+
return true;
|
|
30
37
|
if (err.name == 'RpcError'
|
|
31
38
|
&& (err.code == 'CANCELLED' || err.code == 'DEADLINE_EXCEEDED'))
|
|
32
39
|
return true;
|
|
40
|
+
if (err.code == code.Code.CANCELLED || err.code == code.Code.DEADLINE_EXCEEDED)
|
|
41
|
+
return true;
|
|
33
42
|
if (err.cause !== undefined && !nested)
|
|
34
43
|
// nested limits the depth of search
|
|
35
44
|
return isTimeoutOrCancelError(err.cause, true);
|
package/dist/core/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sources":["../../src/core/errors.ts"],"sourcesContent":["import type { Status } from '../proto/github.com/googleapis/googleapis/google/rpc/status';\nimport { Aborted } from '@milaboratories/ts-helpers';\n\nexport function isConnectionProblem(err: unknown, nested: boolean = false): boolean {\n if (err instanceof DisconnectedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAVAILABLE') return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isConnectionProblem((err as any).cause, true);\n return false;\n}\n\nexport function isUnauthenticated(err: unknown, nested: boolean = false): boolean {\n if (err instanceof UnauthenticatedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAUTHENTICATED') return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isUnauthenticated((err as any).cause, true);\n return false;\n}\n\nexport function isTimeoutOrCancelError(err: unknown, nested: boolean = false): boolean {\n if (err instanceof Aborted || (err as any).name == 'AbortError') return true;\n if ((err as any).code == 'ABORT_ERR') return true;\n if (\n (err as any).name == 'RpcError'\n && ((err as any).code == 'CANCELLED' || (err as any).code == 'DEADLINE_EXCEEDED')\n )\n return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isTimeoutOrCancelError((err as any).cause, true);\n return false;\n}\n\nexport const PlErrorCodeNotFound = 5;\n\nexport class PlError extends Error {\n name = 'PlError';\n constructor(public readonly status: Status) {\n super(`code=${status.code} ${status.message}`);\n }\n}\n\nexport function throwPlNotFoundError(message: string): never {\n throw new RecoverablePlError({ code: PlErrorCodeNotFound, message, details: [] });\n}\n\nexport class RecoverablePlError extends PlError {\n name = 'RecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport class UnrecoverablePlError extends PlError {\n name = 'UnrecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport function isNotFoundError(err: unknown, nested: boolean = false): boolean {\n if ((err as any).name == 'RpcError' && (err as any).code == 'NOT_FOUND') return true;\n if ((err as any).cause !== undefined && !nested) return isNotFoundError((err as any).cause, true);\n return err instanceof RecoverablePlError && err.status.code === PlErrorCodeNotFound;\n}\n\nexport class UnauthenticatedError extends Error {\n name = 'UnauthenticatedError';\n constructor(message: string) {\n super('LoginFailed: ' + message);\n }\n}\n\nexport class DisconnectedError extends Error {\n name = 'DisconnectedError';\n constructor(message: string) {\n super('Disconnected: ' + message);\n }\n}\n\nexport function rethrowMeaningfulError(error: any, wrapIfUnknown: boolean = false): never {\n if (isUnauthenticated(error)) throw new UnauthenticatedError(error.message);\n if (isConnectionProblem(error)) throw new DisconnectedError(error.message);\n if (isTimeoutOrCancelError(error)) throw new Aborted(error);\n if (wrapIfUnknown) throw new Error(error.message, { cause: error });\n else throw error;\n}\n"],"names":["Aborted"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.cjs","sources":["../../src/core/errors.ts"],"sourcesContent":["import type { Status } from '../proto-grpc/github.com/googleapis/googleapis/google/rpc/status';\nimport { Aborted } from '@milaboratories/ts-helpers';\nimport { Code } from '../proto-grpc/google/rpc/code';\n\nexport function isConnectionProblem(err: unknown, nested: boolean = false): boolean {\n if (err instanceof DisconnectedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAVAILABLE') return true;\n if ((err as any).code == Code.UNAVAILABLE) return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isConnectionProblem((err as any).cause, true);\n return false;\n}\n\nexport function isUnauthenticated(err: unknown, nested: boolean = false): boolean {\n if (err instanceof UnauthenticatedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAUTHENTICATED') return true;\n if ((err as any).code == Code.UNAUTHENTICATED) return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isUnauthenticated((err as any).cause, true);\n return false;\n}\n\nexport function isTimeoutOrCancelError(err: unknown, nested: boolean = false): boolean {\n if (err instanceof Aborted || (err as any).name == 'AbortError') return true;\n if ((err as any).code == 'ABORT_ERR') return true;\n if ((err as any).code == Code.ABORTED) return true;\n if (\n (err as any).name == 'RpcError'\n && ((err as any).code == 'CANCELLED' || (err as any).code == 'DEADLINE_EXCEEDED')\n )\n return true;\n if ((err as any).code == Code.CANCELLED || (err as any).code == Code.DEADLINE_EXCEEDED)\n return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isTimeoutOrCancelError((err as any).cause, true);\n return false;\n}\n\nexport const PlErrorCodeNotFound = 5;\n\nexport class PlError extends Error {\n name = 'PlError';\n constructor(public readonly status: Status) {\n super(`code=${status.code} ${status.message}`);\n }\n}\n\nexport function throwPlNotFoundError(message: string): never {\n throw new RecoverablePlError({ code: PlErrorCodeNotFound, message, details: [] });\n}\n\nexport class RecoverablePlError extends PlError {\n name = 'RecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport class UnrecoverablePlError extends PlError {\n name = 'UnrecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport function isNotFoundError(err: unknown, nested: boolean = false): boolean {\n if ((err as any).name == 'RpcError' && (err as any).code == 'NOT_FOUND') return true;\n if ((err as any).cause !== undefined && !nested) return isNotFoundError((err as any).cause, true);\n return err instanceof RecoverablePlError && err.status.code === PlErrorCodeNotFound;\n}\n\nexport class UnauthenticatedError extends Error {\n name = 'UnauthenticatedError';\n constructor(message: string) {\n super('LoginFailed: ' + message);\n }\n}\n\nexport class DisconnectedError extends Error {\n name = 'DisconnectedError';\n constructor(message: string) {\n super('Disconnected: ' + message);\n }\n}\n\nexport function rethrowMeaningfulError(error: any, wrapIfUnknown: boolean = false): never {\n if (isUnauthenticated(error)) throw new UnauthenticatedError(error.message);\n if (isConnectionProblem(error)) throw new DisconnectedError(error.message);\n if (isTimeoutOrCancelError(error)) throw new Aborted(error);\n if (wrapIfUnknown) throw new Error(error.message, { cause: error });\n else throw error;\n}\n"],"names":["Code","Aborted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@
|
|
|
1
|
-
import type { Status } from '../proto/github.com/googleapis/googleapis/google/rpc/status';
|
|
1
|
+
import type { Status } from '../proto-grpc/github.com/googleapis/googleapis/google/rpc/status';
|
|
2
2
|
export declare function isConnectionProblem(err: unknown, nested?: boolean): boolean;
|
|
3
3
|
export declare function isUnauthenticated(err: unknown, nested?: boolean): boolean;
|
|
4
4
|
export declare function isTimeoutOrCancelError(err: unknown, nested?: boolean): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kEAAkE,CAAC;AAI/F,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,OAAe,GAAG,OAAO,CAQlF;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,OAAe,GAAG,OAAO,CAQhF;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,OAAe,GAAG,OAAO,CAerF;AAED,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,qBAAa,OAAQ,SAAQ,KAAK;aAEJ,MAAM,EAAE,MAAM;IAD1C,IAAI,SAAa;gBACW,MAAM,EAAE,MAAM;CAG3C;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE3D;AAED,qBAAa,kBAAmB,SAAQ,OAAO;IAC7C,IAAI,SAAwB;gBAChB,MAAM,EAAE,MAAM;CAG3B;AAED,qBAAa,oBAAqB,SAAQ,OAAO;IAC/C,IAAI,SAA0B;gBAClB,MAAM,EAAE,MAAM;CAG3B;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,OAAe,GAAG,OAAO,CAI9E;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,IAAI,SAA0B;gBAClB,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,IAAI,SAAuB;gBACf,OAAO,EAAE,MAAM;CAG5B;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,GAAE,OAAe,GAAG,KAAK,CAMxF"}
|
package/dist/core/errors.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Aborted } from '@milaboratories/ts-helpers';
|
|
2
|
+
import { Code } from '../proto-grpc/google/rpc/code.js';
|
|
2
3
|
|
|
3
4
|
function isConnectionProblem(err, nested = false) {
|
|
4
5
|
if (err instanceof DisconnectedError)
|
|
5
6
|
return true;
|
|
6
7
|
if (err.name == 'RpcError' && err.code == 'UNAVAILABLE')
|
|
7
8
|
return true;
|
|
9
|
+
if (err.code == Code.UNAVAILABLE)
|
|
10
|
+
return true;
|
|
8
11
|
if (err.cause !== undefined && !nested)
|
|
9
12
|
// nested limits the depth of search
|
|
10
13
|
return isConnectionProblem(err.cause, true);
|
|
@@ -15,6 +18,8 @@ function isUnauthenticated(err, nested = false) {
|
|
|
15
18
|
return true;
|
|
16
19
|
if (err.name == 'RpcError' && err.code == 'UNAUTHENTICATED')
|
|
17
20
|
return true;
|
|
21
|
+
if (err.code == Code.UNAUTHENTICATED)
|
|
22
|
+
return true;
|
|
18
23
|
if (err.cause !== undefined && !nested)
|
|
19
24
|
// nested limits the depth of search
|
|
20
25
|
return isUnauthenticated(err.cause, true);
|
|
@@ -25,9 +30,13 @@ function isTimeoutOrCancelError(err, nested = false) {
|
|
|
25
30
|
return true;
|
|
26
31
|
if (err.code == 'ABORT_ERR')
|
|
27
32
|
return true;
|
|
33
|
+
if (err.code == Code.ABORTED)
|
|
34
|
+
return true;
|
|
28
35
|
if (err.name == 'RpcError'
|
|
29
36
|
&& (err.code == 'CANCELLED' || err.code == 'DEADLINE_EXCEEDED'))
|
|
30
37
|
return true;
|
|
38
|
+
if (err.code == Code.CANCELLED || err.code == Code.DEADLINE_EXCEEDED)
|
|
39
|
+
return true;
|
|
31
40
|
if (err.cause !== undefined && !nested)
|
|
32
41
|
// nested limits the depth of search
|
|
33
42
|
return isTimeoutOrCancelError(err.cause, true);
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sources":["../../src/core/errors.ts"],"sourcesContent":["import type { Status } from '../proto/github.com/googleapis/googleapis/google/rpc/status';\nimport { Aborted } from '@milaboratories/ts-helpers';\n\nexport function isConnectionProblem(err: unknown, nested: boolean = false): boolean {\n if (err instanceof DisconnectedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAVAILABLE') return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isConnectionProblem((err as any).cause, true);\n return false;\n}\n\nexport function isUnauthenticated(err: unknown, nested: boolean = false): boolean {\n if (err instanceof UnauthenticatedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAUTHENTICATED') return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isUnauthenticated((err as any).cause, true);\n return false;\n}\n\nexport function isTimeoutOrCancelError(err: unknown, nested: boolean = false): boolean {\n if (err instanceof Aborted || (err as any).name == 'AbortError') return true;\n if ((err as any).code == 'ABORT_ERR') return true;\n if (\n (err as any).name == 'RpcError'\n && ((err as any).code == 'CANCELLED' || (err as any).code == 'DEADLINE_EXCEEDED')\n )\n return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isTimeoutOrCancelError((err as any).cause, true);\n return false;\n}\n\nexport const PlErrorCodeNotFound = 5;\n\nexport class PlError extends Error {\n name = 'PlError';\n constructor(public readonly status: Status) {\n super(`code=${status.code} ${status.message}`);\n }\n}\n\nexport function throwPlNotFoundError(message: string): never {\n throw new RecoverablePlError({ code: PlErrorCodeNotFound, message, details: [] });\n}\n\nexport class RecoverablePlError extends PlError {\n name = 'RecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport class UnrecoverablePlError extends PlError {\n name = 'UnrecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport function isNotFoundError(err: unknown, nested: boolean = false): boolean {\n if ((err as any).name == 'RpcError' && (err as any).code == 'NOT_FOUND') return true;\n if ((err as any).cause !== undefined && !nested) return isNotFoundError((err as any).cause, true);\n return err instanceof RecoverablePlError && err.status.code === PlErrorCodeNotFound;\n}\n\nexport class UnauthenticatedError extends Error {\n name = 'UnauthenticatedError';\n constructor(message: string) {\n super('LoginFailed: ' + message);\n }\n}\n\nexport class DisconnectedError extends Error {\n name = 'DisconnectedError';\n constructor(message: string) {\n super('Disconnected: ' + message);\n }\n}\n\nexport function rethrowMeaningfulError(error: any, wrapIfUnknown: boolean = false): never {\n if (isUnauthenticated(error)) throw new UnauthenticatedError(error.message);\n if (isConnectionProblem(error)) throw new DisconnectedError(error.message);\n if (isTimeoutOrCancelError(error)) throw new Aborted(error);\n if (wrapIfUnknown) throw new Error(error.message, { cause: error });\n else throw error;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../../src/core/errors.ts"],"sourcesContent":["import type { Status } from '../proto-grpc/github.com/googleapis/googleapis/google/rpc/status';\nimport { Aborted } from '@milaboratories/ts-helpers';\nimport { Code } from '../proto-grpc/google/rpc/code';\n\nexport function isConnectionProblem(err: unknown, nested: boolean = false): boolean {\n if (err instanceof DisconnectedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAVAILABLE') return true;\n if ((err as any).code == Code.UNAVAILABLE) return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isConnectionProblem((err as any).cause, true);\n return false;\n}\n\nexport function isUnauthenticated(err: unknown, nested: boolean = false): boolean {\n if (err instanceof UnauthenticatedError) return true;\n if ((err as any).name == 'RpcError' && (err as any).code == 'UNAUTHENTICATED') return true;\n if ((err as any).code == Code.UNAUTHENTICATED) return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isUnauthenticated((err as any).cause, true);\n return false;\n}\n\nexport function isTimeoutOrCancelError(err: unknown, nested: boolean = false): boolean {\n if (err instanceof Aborted || (err as any).name == 'AbortError') return true;\n if ((err as any).code == 'ABORT_ERR') return true;\n if ((err as any).code == Code.ABORTED) return true;\n if (\n (err as any).name == 'RpcError'\n && ((err as any).code == 'CANCELLED' || (err as any).code == 'DEADLINE_EXCEEDED')\n )\n return true;\n if ((err as any).code == Code.CANCELLED || (err as any).code == Code.DEADLINE_EXCEEDED)\n return true;\n if ((err as any).cause !== undefined && !nested)\n // nested limits the depth of search\n return isTimeoutOrCancelError((err as any).cause, true);\n return false;\n}\n\nexport const PlErrorCodeNotFound = 5;\n\nexport class PlError extends Error {\n name = 'PlError';\n constructor(public readonly status: Status) {\n super(`code=${status.code} ${status.message}`);\n }\n}\n\nexport function throwPlNotFoundError(message: string): never {\n throw new RecoverablePlError({ code: PlErrorCodeNotFound, message, details: [] });\n}\n\nexport class RecoverablePlError extends PlError {\n name = 'RecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport class UnrecoverablePlError extends PlError {\n name = 'UnrecoverablePlError';\n constructor(status: Status) {\n super(status);\n }\n}\n\nexport function isNotFoundError(err: unknown, nested: boolean = false): boolean {\n if ((err as any).name == 'RpcError' && (err as any).code == 'NOT_FOUND') return true;\n if ((err as any).cause !== undefined && !nested) return isNotFoundError((err as any).cause, true);\n return err instanceof RecoverablePlError && err.status.code === PlErrorCodeNotFound;\n}\n\nexport class UnauthenticatedError extends Error {\n name = 'UnauthenticatedError';\n constructor(message: string) {\n super('LoginFailed: ' + message);\n }\n}\n\nexport class DisconnectedError extends Error {\n name = 'DisconnectedError';\n constructor(message: string) {\n super('Disconnected: ' + message);\n }\n}\n\nexport function rethrowMeaningfulError(error: any, wrapIfUnknown: boolean = false): never {\n if (isUnauthenticated(error)) throw new UnauthenticatedError(error.message);\n if (isConnectionProblem(error)) throw new DisconnectedError(error.message);\n if (isTimeoutOrCancelError(error)) throw new Aborted(error);\n if (wrapIfUnknown) throw new Error(error.message, { cause: error });\n else throw error;\n}\n"],"names":[],"mappings":";;;SAIgB,mBAAmB,CAAC,GAAY,EAAE,SAAkB,KAAK,EAAA;IACvE,IAAI,GAAG,YAAY,iBAAiB;AAAE,QAAA,OAAO,IAAI;IACjD,IAAK,GAAW,CAAC,IAAI,IAAI,UAAU,IAAK,GAAW,CAAC,IAAI,IAAI,aAAa;AAAE,QAAA,OAAO,IAAI;AACtF,IAAA,IAAK,GAAW,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW;AAAE,QAAA,OAAO,IAAI;AACtD,IAAA,IAAK,GAAW,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM;;QAE7C,OAAO,mBAAmB,CAAE,GAAW,CAAC,KAAK,EAAE,IAAI,CAAC;AACtD,IAAA,OAAO,KAAK;AACd;SAEgB,iBAAiB,CAAC,GAAY,EAAE,SAAkB,KAAK,EAAA;IACrE,IAAI,GAAG,YAAY,oBAAoB;AAAE,QAAA,OAAO,IAAI;IACpD,IAAK,GAAW,CAAC,IAAI,IAAI,UAAU,IAAK,GAAW,CAAC,IAAI,IAAI,iBAAiB;AAAE,QAAA,OAAO,IAAI;AAC1F,IAAA,IAAK,GAAW,CAAC,IAAI,IAAI,IAAI,CAAC,eAAe;AAAE,QAAA,OAAO,IAAI;AAC1D,IAAA,IAAK,GAAW,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM;;QAE7C,OAAO,iBAAiB,CAAE,GAAW,CAAC,KAAK,EAAE,IAAI,CAAC;AACpD,IAAA,OAAO,KAAK;AACd;SAEgB,sBAAsB,CAAC,GAAY,EAAE,SAAkB,KAAK,EAAA;IAC1E,IAAI,GAAG,YAAY,OAAO,IAAK,GAA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