@mysten/sui 2.39.1 → 3.0.0
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/CHANGELOG.md +160 -0
- package/README.md +5 -188
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/bcs.mjs +49 -22
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/effects.mjs +49 -20
- package/dist/bcs/effects.mjs.map +1 -1
- package/dist/bcs/index.d.mts +1441 -624
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/bcs/index.mjs +2 -1
- package/dist/bcs/index.mjs.map +1 -1
- package/dist/bcs/transactions.d.mts +1059 -0
- package/dist/bcs/transactions.d.mts.map +1 -0
- package/dist/bcs/transactions.mjs +33 -14
- package/dist/bcs/transactions.mjs.map +1 -1
- package/dist/bcs/types.d.mts +6 -1
- package/dist/bcs/types.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +4 -4
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +55 -4
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +98 -1
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/errors.mjs +11 -1
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/index.d.mts +4 -2
- package/dist/client/index.mjs +5 -2
- package/dist/client/mvr.d.mts +12 -2
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/mvr.mjs +34 -13
- package/dist/client/mvr.mjs.map +1 -1
- package/dist/client/query-filters.mjs +80 -76
- package/dist/client/query-filters.mjs.map +1 -1
- package/dist/client/stream/adapter.d.mts +102 -0
- package/dist/client/stream/adapter.d.mts.map +1 -0
- package/dist/client/stream/errors.d.mts +14 -0
- package/dist/client/stream/errors.d.mts.map +1 -0
- package/dist/client/stream/errors.mjs +25 -0
- package/dist/client/stream/errors.mjs.map +1 -0
- package/dist/client/stream/filter.mjs +18 -0
- package/dist/client/stream/filter.mjs.map +1 -0
- package/dist/client/stream/follow.mjs +48 -0
- package/dist/client/stream/follow.mjs.map +1 -0
- package/dist/client/stream/index.d.mts +4 -0
- package/dist/client/stream/pager.mjs +123 -0
- package/dist/client/stream/pager.mjs.map +1 -0
- package/dist/client/stream/plan.mjs +79 -0
- package/dist/client/stream/plan.mjs.map +1 -0
- package/dist/client/stream/position.d.mts +30 -0
- package/dist/client/stream/position.d.mts.map +1 -0
- package/dist/client/stream/position.mjs +121 -0
- package/dist/client/stream/position.mjs.map +1 -0
- package/dist/client/stream/run.d.mts +2 -0
- package/dist/client/stream/run.mjs +99 -0
- package/dist/client/stream/run.mjs.map +1 -0
- package/dist/client/stream/session.mjs +205 -0
- package/dist/client/stream/session.mjs.map +1 -0
- package/dist/client/stream/status.mjs +47 -0
- package/dist/client/stream/status.mjs.map +1 -0
- package/dist/client/stream/token.mjs +80 -0
- package/dist/client/stream/token.mjs.map +1 -0
- package/dist/client/transaction-data.d.mts +12 -0
- package/dist/client/transaction-data.d.mts.map +1 -0
- package/dist/client/transaction-data.mjs +469 -0
- package/dist/client/transaction-data.mjs.map +1 -0
- package/dist/client/transaction-resolver.mjs +102 -58
- package/dist/client/transaction-resolver.mjs.map +1 -1
- package/dist/client/types.d.mts +560 -240
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts +3 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +91 -26
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/index.d.mts +1 -1
- package/dist/cryptography/keypair.d.mts +1 -1
- package/dist/cryptography/publickey.d.mts +11 -0
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +12 -1
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +2 -2
- package/dist/cryptography/signature.mjs +18 -7
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/graphql/client.d.mts +51 -35
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +125 -69
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +14 -9
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +293 -117
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/errors.d.mts +20 -0
- package/dist/graphql/errors.d.mts.map +1 -0
- package/dist/graphql/errors.mjs +19 -0
- package/dist/graphql/errors.mjs.map +1 -0
- package/dist/graphql/filters.mjs +32 -0
- package/dist/graphql/filters.mjs.map +1 -0
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +1216 -208
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +820 -11
- package/dist/graphql/index.d.mts +2 -1
- package/dist/graphql/index.mjs +2 -1
- package/dist/graphql/sse-parser.mjs +82 -0
- package/dist/graphql/sse-parser.mjs.map +1 -0
- package/dist/graphql/stream/families.mjs +306 -0
- package/dist/graphql/stream/families.mjs.map +1 -0
- package/dist/graphql/stream/index.mjs +38 -0
- package/dist/graphql/stream/index.mjs.map +1 -0
- package/dist/graphql/stream/live.mjs +60 -0
- package/dist/graphql/stream/live.mjs.map +1 -0
- package/dist/graphql/stream/page.mjs +38 -0
- package/dist/graphql/stream/page.mjs.map +1 -0
- package/dist/graphql/stream/query.mjs +47 -0
- package/dist/graphql/stream/query.mjs.map +1 -0
- package/dist/graphql/subscribe.mjs +70 -0
- package/dist/graphql/subscribe.mjs.map +1 -0
- package/dist/grpc/client.d.mts +31 -27
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +42 -46
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +13 -6
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +254 -166
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/filters.mjs +44 -34
- package/dist/grpc/filters.mjs.map +1 -1
- package/dist/grpc/grpc-web-pull.mjs +245 -0
- package/dist/grpc/grpc-web-pull.mjs.map +1 -0
- package/dist/grpc/index.d.mts +2 -1
- package/dist/grpc/index.mjs +1 -1
- package/dist/grpc/network-error.mjs +31 -0
- package/dist/grpc/network-error.mjs.map +1 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs +306 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs.map +1 -0
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts +176 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs +175 -0
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +2 -2
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +111 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs +46 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +24 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs +25 -7
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/object.mjs +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts +111 -9
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs +63 -19
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +5 -5
- package/dist/grpc/proto/sui/rpc/v2/signature.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +5 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs +4 -0
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +20 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs +30 -13
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +16 -10
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs +8 -5
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +11 -5
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs +6 -0
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +6 -2
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +7 -7
- package/dist/grpc/proto/types.mjs +3 -2
- package/dist/grpc/pull-call.d.mts +20 -0
- package/dist/grpc/pull-call.d.mts.map +1 -0
- package/dist/grpc/pull-call.mjs +28 -0
- package/dist/grpc/pull-call.mjs.map +1 -0
- package/dist/grpc/stream/call.mjs +238 -0
- package/dist/grpc/stream/call.mjs.map +1 -0
- package/dist/grpc/stream/families.d.mts +26 -0
- package/dist/grpc/stream/families.d.mts.map +1 -0
- package/dist/grpc/stream/families.mjs +145 -0
- package/dist/grpc/stream/families.mjs.map +1 -0
- package/dist/grpc/stream/index.d.mts +41 -0
- package/dist/grpc/stream/index.d.mts.map +1 -0
- package/dist/grpc/stream/index.mjs +127 -0
- package/dist/grpc/stream/index.mjs.map +1 -0
- package/dist/grpc/stream/live.mjs +31 -0
- package/dist/grpc/stream/live.mjs.map +1 -0
- package/dist/grpc/stream/page.mjs +120 -0
- package/dist/grpc/stream/page.mjs.map +1 -0
- package/dist/grpc/stream-types.d.mts +28 -0
- package/dist/grpc/stream-types.d.mts.map +1 -0
- package/dist/grpc/transport.d.mts +8 -3
- package/dist/grpc/transport.d.mts.map +1 -1
- package/dist/grpc/transport.mjs +88 -45
- package/dist/grpc/transport.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +34 -12
- package/dist/jsonRpc/index.d.mts.map +1 -0
- package/dist/jsonRpc/index.mjs +39 -5
- package/dist/jsonRpc/index.mjs.map +1 -0
- package/dist/jsonRpc/types.d.mts +420 -0
- package/dist/jsonRpc/types.d.mts.map +1 -0
- package/dist/keypairs/passkey/keypair.d.mts +1 -1
- package/dist/multisig/publickey.d.mts +12 -4
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +5 -5
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.d.mts +1 -1
- package/dist/transactions/ObjectCache.d.mts +1 -1
- package/dist/transactions/ObjectCache.mjs +5 -5
- package/dist/transactions/ObjectCache.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +11 -10
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +17 -6
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +135 -133
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/internal.mjs +2 -1
- package/dist/transactions/data/internal.mjs.map +1 -1
- package/dist/transactions/data/v1.d.mts +239 -239
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +2 -2
- package/dist/transactions/executor/serial.d.mts +1 -1
- package/dist/transactions/executor/serial.mjs +2 -2
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/transactions/index.d.mts +3 -2
- package/dist/transactions/index.mjs +4 -3
- package/dist/transactions/intents/AllowanceBalance.mjs +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +1 -1
- package/dist/transactions/resolve.d.mts +6 -0
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/transactions/restricted-move-calls.d.mts +25 -0
- package/dist/transactions/restricted-move-calls.d.mts.map +1 -0
- package/dist/transactions/restricted-move-calls.mjs +47 -0
- package/dist/transactions/restricted-move-calls.mjs.map +1 -0
- package/dist/transactions/serializer.d.mts +1 -4
- package/dist/transactions/serializer.d.mts.map +1 -1
- package/dist/transactions/serializer.mjs +1 -44
- package/dist/transactions/serializer.mjs.map +1 -1
- package/dist/transactions/utils.d.mts +0 -1
- package/dist/transactions/utils.d.mts.map +1 -1
- package/dist/transactions/utils.mjs.map +1 -1
- package/dist/utils/abort.mjs +89 -0
- package/dist/utils/abort.mjs.map +1 -0
- package/dist/utils/coin-reservation.mjs +1 -4
- package/dist/utils/coin-reservation.mjs.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/sui-types.mjs +1 -1
- package/dist/verify/index.d.mts +2 -2
- package/dist/verify/verify.d.mts +74 -24
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +128 -42
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/publickey.mjs +15 -20
- package/dist/zklogin/publickey.mjs.map +1 -1
- package/docs/bcs.md +2 -2
- package/docs/clients/core.md +19 -18
- package/docs/clients/executing.md +53 -8
- package/docs/clients/graphql.md +81 -11
- package/docs/clients/grpc.md +31 -15
- package/docs/clients/index.md +8 -7
- package/docs/clients/querying.md +134 -30
- package/docs/clients/streaming.md +324 -0
- package/docs/cryptography/index.md +85 -58
- package/docs/llms-index.md +4 -2
- package/docs/migrations/sui-2.0/dapp-kit.md +3 -2
- package/docs/migrations/sui-2.0/json-rpc-migration.md +106 -79
- package/docs/migrations/sui-3.0/index.md +250 -0
- package/docs/plugins.md +10 -10
- package/docs/sdk-building.md +3 -4
- package/docs/transactions/coins-and-balances.md +6 -11
- package/docs/transactions/reference.md +36 -1
- package/package.json +2 -3
- package/src/bcs/bcs.ts +80 -41
- package/src/bcs/effects.ts +61 -25
- package/src/bcs/index.ts +2 -0
- package/src/bcs/transactions.ts +36 -17
- package/src/bcs/types.ts +10 -4
- package/src/client/core-resolver.ts +3 -5
- package/src/client/core.ts +180 -8
- package/src/client/errors.ts +12 -0
- package/src/client/index.ts +4 -1
- package/src/client/mvr.ts +37 -10
- package/src/client/query-filters.ts +151 -97
- package/src/client/stream/adapter.ts +110 -0
- package/src/client/stream/errors.ts +40 -0
- package/src/client/stream/filter.ts +17 -0
- package/src/client/stream/follow.ts +63 -0
- package/src/client/stream/index.ts +9 -0
- package/src/client/stream/pager.ts +158 -0
- package/src/client/stream/plan.ts +147 -0
- package/src/client/stream/position.ts +143 -0
- package/src/client/stream/run.ts +147 -0
- package/src/client/stream/session.ts +259 -0
- package/src/client/stream/status.ts +44 -0
- package/src/client/stream/token.ts +104 -0
- package/src/client/transaction-data.ts +587 -0
- package/src/client/transaction-resolver.ts +158 -69
- package/src/client/types.ts +530 -115
- package/src/client/utils.ts +147 -50
- package/src/cryptography/publickey.ts +12 -1
- package/src/cryptography/signature.ts +6 -3
- package/src/graphql/client.ts +204 -135
- package/src/graphql/core.ts +446 -139
- package/src/graphql/errors.ts +24 -0
- package/src/graphql/filters.ts +48 -0
- package/src/graphql/generated/queries.ts +1455 -277
- package/src/graphql/generated/schema.graphql +282 -9
- package/src/graphql/generated/tada-env.ts +933 -4
- package/src/graphql/queries/checkpoints.graphql +34 -0
- package/src/graphql/queries/getDynamicFields.graphql +1 -0
- package/src/graphql/queries/listEvents.graphql +16 -24
- package/src/graphql/queries/streams.graphql +212 -0
- package/src/graphql/queries/transactions.graphql +71 -28
- package/src/graphql/queries/verifySignature.graphql +17 -0
- package/src/graphql/sse-parser.ts +99 -0
- package/src/graphql/stream/families.ts +515 -0
- package/src/graphql/stream/index.ts +55 -0
- package/src/graphql/stream/live.ts +70 -0
- package/src/graphql/stream/page.ts +47 -0
- package/src/graphql/stream/query.ts +52 -0
- package/src/graphql/subscribe.ts +83 -0
- package/src/grpc/client.ts +81 -79
- package/src/grpc/core.ts +388 -274
- package/src/grpc/filters.ts +59 -60
- package/src/grpc/grpc-web-pull.ts +360 -0
- package/src/grpc/index.ts +5 -0
- package/src/grpc/network-error.ts +33 -0
- package/src/grpc/proto/sui/rpc/v2/error_reason.ts +175 -0
- package/src/grpc/proto/sui/rpc/v2/ledger_service.ts +145 -0
- package/src/grpc/proto/sui/rpc/v2/move_package_service.ts +43 -1
- package/src/grpc/proto/sui/rpc/v2/query_options.ts +132 -8
- package/src/grpc/proto/sui/rpc/v2/signature.ts +4 -4
- package/src/grpc/proto/sui/rpc/v2/signature_scheme.ts +4 -0
- package/src/grpc/proto/sui/rpc/v2/signature_verification_service.ts +30 -0
- package/src/grpc/proto/sui/rpc/v2/subscription_service.client.ts +16 -10
- package/src/grpc/proto/sui/rpc/v2/transaction.ts +6 -0
- package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +5 -1
- package/src/grpc/pull-call.ts +54 -0
- package/src/grpc/stream/call.ts +317 -0
- package/src/grpc/stream/families.ts +228 -0
- package/src/grpc/stream/index.ts +182 -0
- package/src/grpc/stream/live.ts +33 -0
- package/src/grpc/stream/page.ts +161 -0
- package/src/grpc/stream-types.ts +33 -0
- package/src/grpc/transport.ts +116 -59
- package/src/jsonRpc/index.ts +60 -17
- package/src/jsonRpc/types.ts +421 -0
- package/src/multisig/publickey.ts +19 -7
- package/src/transactions/ObjectCache.ts +6 -6
- package/src/transactions/Transaction.ts +30 -6
- package/src/transactions/data/internal.ts +2 -0
- package/src/transactions/executor/serial.ts +2 -2
- package/src/transactions/index.ts +8 -1
- package/src/transactions/resolve.ts +6 -0
- package/src/transactions/restricted-move-calls.ts +87 -0
- package/src/transactions/serializer.ts +0 -70
- package/src/transactions/utils.ts +0 -37
- package/src/utils/abort.ts +101 -0
- package/src/verify/index.ts +1 -0
- package/src/verify/verify.ts +190 -62
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +18 -34
- package/dist/client/core-resolver.d.mts +0 -9
- package/dist/client/core-resolver.d.mts.map +0 -1
- package/dist/jsonRpc/client.d.mts +0 -507
- package/dist/jsonRpc/client.d.mts.map +0 -1
- package/dist/jsonRpc/client.mjs +0 -868
- package/dist/jsonRpc/client.mjs.map +0 -1
- package/dist/jsonRpc/core.d.mts +0 -168
- package/dist/jsonRpc/core.d.mts.map +0 -1
- package/dist/jsonRpc/core.mjs +0 -1054
- package/dist/jsonRpc/core.mjs.map +0 -1
- package/dist/jsonRpc/errors.d.mts +0 -27
- package/dist/jsonRpc/errors.d.mts.map +0 -1
- package/dist/jsonRpc/errors.mjs +0 -50
- package/dist/jsonRpc/errors.mjs.map +0 -1
- package/dist/jsonRpc/http-transport.d.mts +0 -62
- package/dist/jsonRpc/http-transport.d.mts.map +0 -1
- package/dist/jsonRpc/http-transport.mjs +0 -60
- package/dist/jsonRpc/http-transport.mjs.map +0 -1
- package/dist/jsonRpc/network.d.mts +0 -9
- package/dist/jsonRpc/network.d.mts.map +0 -1
- package/dist/jsonRpc/network.mjs +0 -18
- package/dist/jsonRpc/network.mjs.map +0 -1
- package/dist/jsonRpc/types/chain.d.mts +0 -169
- package/dist/jsonRpc/types/chain.d.mts.map +0 -1
- package/dist/jsonRpc/types/changes.d.mts +0 -48
- package/dist/jsonRpc/types/changes.d.mts.map +0 -1
- package/dist/jsonRpc/types/coins.d.mts +0 -15
- package/dist/jsonRpc/types/coins.d.mts.map +0 -1
- package/dist/jsonRpc/types/common.d.mts +0 -9
- package/dist/jsonRpc/types/common.d.mts.map +0 -1
- package/dist/jsonRpc/types/generated.d.mts +0 -1976
- package/dist/jsonRpc/types/generated.d.mts.map +0 -1
- package/dist/jsonRpc/types/index.d.mts +0 -6
- package/dist/jsonRpc/types/params.d.mts +0 -898
- package/dist/jsonRpc/types/params.d.mts.map +0 -1
- package/src/graphql/generated/tsconfig.tada.json +0 -11
- package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -15
- package/src/jsonRpc/client.ts +0 -1252
- package/src/jsonRpc/core.ts +0 -1557
- package/src/jsonRpc/errors.ts +0 -57
- package/src/jsonRpc/http-transport.ts +0 -118
- package/src/jsonRpc/network.ts +0 -21
- package/src/jsonRpc/types/chain.ts +0 -190
- package/src/jsonRpc/types/changes.ts +0 -35
- package/src/jsonRpc/types/coins.ts +0 -14
- package/src/jsonRpc/types/common.ts +0 -8
- package/src/jsonRpc/types/generated.ts +0 -2165
- package/src/jsonRpc/types/index.ts +0 -9
- package/src/jsonRpc/types/params.ts +0 -908
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { cancelQuietly } from "../client/utils.mjs";
|
|
2
|
+
import { markNonRetryable } from "./pull-call.mjs";
|
|
3
|
+
import { abortRpcError, toNetworkRpcError } from "./network-error.mjs";
|
|
4
|
+
import { RpcError } from "@protobuf-ts/runtime-rpc";
|
|
5
|
+
import { GrpcStatusCode, GrpcWebFrame, createGrpcWebRequestBody, createGrpcWebRequestHeader, readGrpcWebResponseHeader, readGrpcWebResponseTrailer } from "@protobuf-ts/grpcweb-transport";
|
|
6
|
+
|
|
7
|
+
//#region src/grpc/grpc-web-pull.ts
|
|
8
|
+
const MAX_RESPONSE_MESSAGE_BYTES = 128 * 1024 * 1024;
|
|
9
|
+
const code = (status) => GrpcStatusCode[status];
|
|
10
|
+
/** Splits a binary gRPC-web response body into frames: `push` chunks, then `next` until `undefined`. */
|
|
11
|
+
var GrpcWebFrameDecoder = class {
|
|
12
|
+
#maxFrameBytes;
|
|
13
|
+
#chunks = [];
|
|
14
|
+
#length = 0;
|
|
15
|
+
constructor(maxFrameBytes) {
|
|
16
|
+
this.#maxFrameBytes = maxFrameBytes;
|
|
17
|
+
}
|
|
18
|
+
/** Bytes received but not yet returned as a frame. */
|
|
19
|
+
get buffered() {
|
|
20
|
+
return this.#length;
|
|
21
|
+
}
|
|
22
|
+
push(chunk) {
|
|
23
|
+
if (chunk.length === 0) return;
|
|
24
|
+
this.#chunks.push(chunk);
|
|
25
|
+
this.#length += chunk.length;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The next complete frame, or `undefined` until more bytes arrive. An oversized frame is
|
|
29
|
+
* rejected as soon as its 5-byte prefix arrives.
|
|
30
|
+
*/
|
|
31
|
+
next() {
|
|
32
|
+
if (this.#length < 5) return void 0;
|
|
33
|
+
const prefix = this.#peek(5);
|
|
34
|
+
const flag = prefix[0];
|
|
35
|
+
if (flag !== GrpcWebFrame.DATA && flag !== GrpcWebFrame.TRAILER) throw markNonRetryable(new RpcError(`unsupported grpc-web frame ${flag}`, code(GrpcStatusCode.INTERNAL)));
|
|
36
|
+
const length = new DataView(prefix.buffer, prefix.byteOffset, 5).getUint32(1);
|
|
37
|
+
if (length > this.#maxFrameBytes) throw markNonRetryable(new RpcError(`grpc-web frame of ${length} bytes exceeds the ${this.#maxFrameBytes} byte limit`, code(GrpcStatusCode.RESOURCE_EXHAUSTED)));
|
|
38
|
+
if (this.#length < 5 + length) return void 0;
|
|
39
|
+
const payload = this.#take(5 + length).subarray(5);
|
|
40
|
+
if (flag === GrpcWebFrame.DATA) return {
|
|
41
|
+
type: "data",
|
|
42
|
+
data: payload
|
|
43
|
+
};
|
|
44
|
+
const [statusCode, detail, meta] = readGrpcWebResponseTrailer(payload);
|
|
45
|
+
return {
|
|
46
|
+
type: "trailer",
|
|
47
|
+
status: {
|
|
48
|
+
code: code(statusCode),
|
|
49
|
+
detail: detail ?? code(statusCode)
|
|
50
|
+
},
|
|
51
|
+
meta
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The buffered bytes from the start, joining chunks only when the first holds fewer than `n`. */
|
|
55
|
+
#peek(n) {
|
|
56
|
+
if (this.#chunks[0].length < n) {
|
|
57
|
+
const joined = new Uint8Array(this.#length);
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (const chunk of this.#chunks) {
|
|
60
|
+
joined.set(chunk, offset);
|
|
61
|
+
offset += chunk.length;
|
|
62
|
+
}
|
|
63
|
+
this.#chunks = [joined];
|
|
64
|
+
}
|
|
65
|
+
return this.#chunks[0];
|
|
66
|
+
}
|
|
67
|
+
#take(n) {
|
|
68
|
+
const first = this.#peek(n);
|
|
69
|
+
this.#length -= n;
|
|
70
|
+
if (first.length === n) this.#chunks.shift();
|
|
71
|
+
else this.#chunks[0] = first.subarray(n);
|
|
72
|
+
return first.subarray(0, n);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const DONE = {
|
|
76
|
+
done: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A gRPC-web server-streaming call whose body is read only while the consumer waits on
|
|
81
|
+
* `responses.next()`. It has a single consumer: `responses.next()` must not be called concurrently.
|
|
82
|
+
*
|
|
83
|
+
* An abort, `return()` or failure can land during any await, so every await is followed by
|
|
84
|
+
* `#throwIfFailed()` and `#isOpen()`, and the first failure is sticky.
|
|
85
|
+
*/
|
|
86
|
+
var GrpcWebPullCall = class {
|
|
87
|
+
#method;
|
|
88
|
+
#options;
|
|
89
|
+
#normalizeError;
|
|
90
|
+
#userSignal;
|
|
91
|
+
#controller = new AbortController();
|
|
92
|
+
#onUserAbort = () => this.#controller.abort(this.#userSignal.reason);
|
|
93
|
+
#opened;
|
|
94
|
+
#state = "open";
|
|
95
|
+
#failure;
|
|
96
|
+
#reader;
|
|
97
|
+
#decoder;
|
|
98
|
+
#headerStatus;
|
|
99
|
+
#eof = false;
|
|
100
|
+
constructor(method, input, call) {
|
|
101
|
+
this.#method = method;
|
|
102
|
+
this.#options = call.options;
|
|
103
|
+
this.#normalizeError = call.normalizeError;
|
|
104
|
+
this.#userSignal = call.options.abort;
|
|
105
|
+
this.#controller.signal.addEventListener("abort", () => this.#fail(this.#controller.signal.reason), { once: true });
|
|
106
|
+
if (this.#userSignal?.aborted) this.#controller.abort(this.#userSignal.reason);
|
|
107
|
+
else this.#userSignal?.addEventListener("abort", this.#onUserAbort, { once: true });
|
|
108
|
+
this.#opened = this.#open(input, call.url);
|
|
109
|
+
this.#opened.catch((error) => this.#fail(error));
|
|
110
|
+
this.responses = {
|
|
111
|
+
[Symbol.asyncIterator]() {
|
|
112
|
+
return this;
|
|
113
|
+
},
|
|
114
|
+
next: () => this.#pull(),
|
|
115
|
+
return: async () => {
|
|
116
|
+
this.#cancel();
|
|
117
|
+
return DONE;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
#isOpen() {
|
|
122
|
+
return this.#state === "open";
|
|
123
|
+
}
|
|
124
|
+
#throwIfFailed() {
|
|
125
|
+
if (this.#state === "failed") throw this.#failure;
|
|
126
|
+
}
|
|
127
|
+
async #open(input, url) {
|
|
128
|
+
const body = createGrpcWebRequestBody(this.#method.I.toBinary(this.#method.I.create(input), this.#options.binaryOptions), "binary");
|
|
129
|
+
const headers = createGrpcWebRequestHeader(new globalThis.Headers(), "binary", this.#options.timeout, this.#options.meta);
|
|
130
|
+
if (!this.#isOpen()) return;
|
|
131
|
+
const fetch = this.#options.fetch ?? globalThis.fetch;
|
|
132
|
+
let response;
|
|
133
|
+
try {
|
|
134
|
+
response = await fetch(url, {
|
|
135
|
+
...this.#options.fetchInit,
|
|
136
|
+
method: "POST",
|
|
137
|
+
headers,
|
|
138
|
+
body,
|
|
139
|
+
signal: this.#controller.signal
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw toNetworkRpcError(error, this.#controller.signal);
|
|
143
|
+
}
|
|
144
|
+
if (!this.#isOpen()) return cancelQuietly(response.body);
|
|
145
|
+
try {
|
|
146
|
+
const [statusCode, detail, meta] = readGrpcWebResponseHeader(response);
|
|
147
|
+
if (statusCode !== void 0 && statusCode !== GrpcStatusCode.OK) throw new RpcError(detail ?? code(statusCode), code(statusCode), meta);
|
|
148
|
+
if (statusCode !== void 0) this.#headerStatus = {
|
|
149
|
+
code: "OK",
|
|
150
|
+
detail: detail ?? "OK"
|
|
151
|
+
};
|
|
152
|
+
if (!response.body) {
|
|
153
|
+
this.#eof = true;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const type = response.headers.get("content-type");
|
|
157
|
+
if (type !== "application/grpc-web" && type !== "application/grpc-web+proto") throw markNonRetryable(new RpcError(`unexpected response content type: ${type}`, code(GrpcStatusCode.INTERNAL)));
|
|
158
|
+
this.#reader = response.body.getReader();
|
|
159
|
+
} catch (error) {
|
|
160
|
+
cancelQuietly(response.body);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
this.#decoder = new GrpcWebFrameDecoder(MAX_RESPONSE_MESSAGE_BYTES);
|
|
164
|
+
}
|
|
165
|
+
async #pull() {
|
|
166
|
+
try {
|
|
167
|
+
if (!this.#decoder && !this.#eof) await this.#opened;
|
|
168
|
+
for (;;) {
|
|
169
|
+
this.#throwIfFailed();
|
|
170
|
+
if (!this.#isOpen()) return DONE;
|
|
171
|
+
const frame = this.#decoder?.next();
|
|
172
|
+
if (frame?.type === "data") return {
|
|
173
|
+
done: false,
|
|
174
|
+
value: this.#method.O.fromBinary(frame.data, this.#options.binaryOptions)
|
|
175
|
+
};
|
|
176
|
+
if (frame) return this.#finish(frame.status, frame.meta);
|
|
177
|
+
if (this.#eof) {
|
|
178
|
+
if (this.#decoder?.buffered || !this.#headerStatus) throw new RpcError("response ended before its status", code(GrpcStatusCode.UNAVAILABLE));
|
|
179
|
+
return this.#finish(this.#headerStatus, {});
|
|
180
|
+
}
|
|
181
|
+
const result = await this.#read();
|
|
182
|
+
this.#throwIfFailed();
|
|
183
|
+
if (!this.#isOpen()) return DONE;
|
|
184
|
+
if (result.done) this.#eof = true;
|
|
185
|
+
else this.#decoder.push(result.value);
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (this.#state === "cancelled") return DONE;
|
|
189
|
+
this.#fail(error);
|
|
190
|
+
throw this.#failure;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async #read() {
|
|
194
|
+
try {
|
|
195
|
+
return await this.#reader.read();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
throw toNetworkRpcError(error, this.#controller.signal);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
#finish(status, meta) {
|
|
201
|
+
if (status.code !== "OK") throw new RpcError(status.detail, status.code, meta);
|
|
202
|
+
this.#state = "done";
|
|
203
|
+
this.#release();
|
|
204
|
+
return DONE;
|
|
205
|
+
}
|
|
206
|
+
/** Fails the call with `reason`, unless it already ended. */
|
|
207
|
+
#fail(reason) {
|
|
208
|
+
if (!this.#isOpen()) return;
|
|
209
|
+
this.#failure = this.#toError(reason);
|
|
210
|
+
this.#settle("failed", this.#failure);
|
|
211
|
+
}
|
|
212
|
+
#cancel() {
|
|
213
|
+
if (!this.#isOpen()) return;
|
|
214
|
+
const error = new RpcError("stream cancelled by consumer", code(GrpcStatusCode.CANCELLED));
|
|
215
|
+
error.methodName = this.#method.name;
|
|
216
|
+
error.serviceName = this.#method.service.typeName;
|
|
217
|
+
this.#settle("cancelled", error);
|
|
218
|
+
}
|
|
219
|
+
#settle(state, error) {
|
|
220
|
+
this.#state = state;
|
|
221
|
+
this.#release();
|
|
222
|
+
this.#controller.abort(error);
|
|
223
|
+
}
|
|
224
|
+
/** Drops the body and any bytes buffered from it, so an ended call retains neither. */
|
|
225
|
+
#release() {
|
|
226
|
+
this.#userSignal?.removeEventListener("abort", this.#onUserAbort);
|
|
227
|
+
cancelQuietly(this.#reader);
|
|
228
|
+
this.#reader = void 0;
|
|
229
|
+
this.#decoder = void 0;
|
|
230
|
+
}
|
|
231
|
+
#toError(reason) {
|
|
232
|
+
let error;
|
|
233
|
+
if (reason instanceof RpcError && reason !== this.#controller.signal.reason) error = reason;
|
|
234
|
+
else if (this.#controller.signal.aborted) error = abortRpcError(reason);
|
|
235
|
+
else error = markNonRetryable(new RpcError(reason instanceof Error ? reason.message : String(reason), code(GrpcStatusCode.INTERNAL)));
|
|
236
|
+
error.methodName = this.#method.name;
|
|
237
|
+
error.serviceName = this.#method.service.typeName;
|
|
238
|
+
this.#normalizeError(error, this.#userSignal);
|
|
239
|
+
return error;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { GrpcWebPullCall };
|
|
245
|
+
//# sourceMappingURL=grpc-web-pull.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-web-pull.mjs","names":["#maxFrameBytes","#length","#chunks","#peek","#take","#method","#options","#normalizeError","#userSignal","#controller","#onUserAbort","#opened","#fail","#open","#pull","#cancel","#state","#failure","#isOpen","#headerStatus","#eof","#reader","#decoder","#throwIfFailed","#finish","#read","#release","#toError","#settle"],"sources":["../../src/grpc/grpc-web-pull.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/*\n * An on-demand reader for binary gRPC-web server streams. Request construction and header/trailer\n * parsing use the public helpers of `@protobuf-ts/grpcweb-transport`. Frame extraction and call\n * settlement are adapted from `@protobuf-ts/grpcweb-transport` 2.11.1 (`grpc-web-format.ts`,\n * `grpc-web-transport.ts`), Copyright (c) Timo Stamm, licensed under the Apache License, Version\n * 2.0: https://github.com/timostamm/protobuf-ts\n *\n * Unlike upstream, the body is read only while the consumer waits for a message, and frame sizes\n * are checked before their payload is buffered.\n */\n\nimport {\n\tcreateGrpcWebRequestBody,\n\tcreateGrpcWebRequestHeader,\n\tGrpcStatusCode,\n\tGrpcWebFrame,\n\treadGrpcWebResponseHeader,\n\treadGrpcWebResponseTrailer,\n} from '@protobuf-ts/grpcweb-transport';\nimport type { GrpcWebOptions } from '@protobuf-ts/grpcweb-transport';\nimport { RpcError } from '@protobuf-ts/runtime-rpc';\nimport type { MethodInfo, RpcMetadata, RpcStatus } from '@protobuf-ts/runtime-rpc';\n\nimport { cancelQuietly } from '../client/utils.js';\nimport { abortRpcError, toNetworkRpcError } from './network-error.js';\nimport { markNonRetryable } from './pull-call.js';\nimport type { ServerStreamingIterableCall } from './pull-call.js';\n\n// Matches the limit sui's Rust client sets for checkpoint reads.\nexport const MAX_RESPONSE_MESSAGE_BYTES = 128 * 1024 * 1024;\n\nconst code = (status: GrpcStatusCode) => GrpcStatusCode[status];\n\nexport type GrpcWebResponseFrame =\n\t{ type: 'data'; data: Uint8Array } | { type: 'trailer'; status: RpcStatus; meta: RpcMetadata };\n\n/** Splits a binary gRPC-web response body into frames: `push` chunks, then `next` until `undefined`. */\nexport class GrpcWebFrameDecoder {\n\treadonly #maxFrameBytes: number;\n\t#chunks: Uint8Array[] = [];\n\t#length = 0;\n\n\tconstructor(maxFrameBytes: number) {\n\t\tthis.#maxFrameBytes = maxFrameBytes;\n\t}\n\n\t/** Bytes received but not yet returned as a frame. */\n\tget buffered(): number {\n\t\treturn this.#length;\n\t}\n\n\tpush(chunk: Uint8Array): void {\n\t\tif (chunk.length === 0) return;\n\t\tthis.#chunks.push(chunk);\n\t\tthis.#length += chunk.length;\n\t}\n\n\t/**\n\t * The next complete frame, or `undefined` until more bytes arrive. An oversized frame is\n\t * rejected as soon as its 5-byte prefix arrives.\n\t */\n\tnext(): GrpcWebResponseFrame | undefined {\n\t\tif (this.#length < 5) return undefined;\n\t\tconst prefix = this.#peek(5);\n\t\tconst flag = prefix[0];\n\t\tif (flag !== GrpcWebFrame.DATA && flag !== GrpcWebFrame.TRAILER) {\n\t\t\tthrow markNonRetryable(\n\t\t\t\tnew RpcError(`unsupported grpc-web frame ${flag}`, code(GrpcStatusCode.INTERNAL)),\n\t\t\t);\n\t\t}\n\t\tconst length = new DataView(prefix.buffer, prefix.byteOffset, 5).getUint32(1);\n\t\tif (length > this.#maxFrameBytes) {\n\t\t\t// The server would send the same frame again on retry.\n\t\t\tthrow markNonRetryable(\n\t\t\t\tnew RpcError(\n\t\t\t\t\t`grpc-web frame of ${length} bytes exceeds the ${this.#maxFrameBytes} byte limit`,\n\t\t\t\t\tcode(GrpcStatusCode.RESOURCE_EXHAUSTED),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (this.#length < 5 + length) return undefined;\n\t\tconst payload = this.#take(5 + length).subarray(5);\n\t\tif (flag === GrpcWebFrame.DATA) return { type: 'data', data: payload };\n\t\tconst [statusCode, detail, meta] = readGrpcWebResponseTrailer(payload);\n\t\treturn {\n\t\t\ttype: 'trailer',\n\t\t\tstatus: { code: code(statusCode), detail: detail ?? code(statusCode) },\n\t\t\tmeta,\n\t\t};\n\t}\n\n\t/** The buffered bytes from the start, joining chunks only when the first holds fewer than `n`. */\n\t#peek(n: number): Uint8Array {\n\t\tif (this.#chunks[0].length < n) {\n\t\t\tconst joined = new Uint8Array(this.#length);\n\t\t\tlet offset = 0;\n\t\t\tfor (const chunk of this.#chunks) {\n\t\t\t\tjoined.set(chunk, offset);\n\t\t\t\toffset += chunk.length;\n\t\t\t}\n\t\t\tthis.#chunks = [joined];\n\t\t}\n\t\treturn this.#chunks[0];\n\t}\n\n\t#take(n: number): Uint8Array {\n\t\tconst first = this.#peek(n);\n\t\tthis.#length -= n;\n\t\tif (first.length === n) this.#chunks.shift();\n\t\telse this.#chunks[0] = first.subarray(n);\n\t\treturn first.subarray(0, n);\n\t}\n}\n\nexport interface GrpcWebPullCallOptions {\n\t/** Options already merged with the transport's defaults. */\n\toptions: GrpcWebOptions;\n\turl: string;\n\t/** Applied to every error the call surfaces, except a consumer's own cancellation. */\n\tnormalizeError: (error: RpcError, signal: AbortSignal | undefined) => void;\n}\n\nconst DONE = { done: true, value: undefined } as const;\n\ntype State = 'open' | 'done' | 'failed' | 'cancelled';\n\n/**\n * A gRPC-web server-streaming call whose body is read only while the consumer waits on\n * `responses.next()`. It has a single consumer: `responses.next()` must not be called concurrently.\n *\n * An abort, `return()` or failure can land during any await, so every await is followed by\n * `#throwIfFailed()` and `#isOpen()`, and the first failure is sticky.\n */\nexport class GrpcWebPullCall<\n\tI extends object,\n\tO extends object,\n> implements ServerStreamingIterableCall<O> {\n\treadonly responses: AsyncIterableIterator<O>;\n\n\treadonly #method: MethodInfo<I, O>;\n\treadonly #options: GrpcWebOptions;\n\treadonly #normalizeError: GrpcWebPullCallOptions['normalizeError'];\n\treadonly #userSignal: AbortSignal | undefined;\n\t// Aborted by the caller's signal, by `return()` and on failure, so the request is released even\n\t// when nothing is pulling.\n\treadonly #controller = new AbortController();\n\treadonly #onUserAbort = () => this.#controller.abort(this.#userSignal!.reason);\n\treadonly #opened: Promise<void>;\n\n\t#state: State = 'open';\n\t#failure: RpcError | undefined;\n\t#reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n\t#decoder: GrpcWebFrameDecoder | undefined;\n\t// Set by a trailers-only response, whose status arrives in the HTTP headers.\n\t#headerStatus: RpcStatus | undefined;\n\t#eof = false;\n\n\tconstructor(method: MethodInfo<I, O>, input: I, call: GrpcWebPullCallOptions) {\n\t\tthis.#method = method;\n\t\tthis.#options = call.options;\n\t\tthis.#normalizeError = call.normalizeError;\n\t\tthis.#userSignal = call.options.abort;\n\n\t\t// Registered before an already-aborted caller signal is applied, so that abort fails the call.\n\t\tthis.#controller.signal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => this.#fail(this.#controller.signal.reason),\n\t\t\t{ once: true },\n\t\t);\n\t\tif (this.#userSignal?.aborted) this.#controller.abort(this.#userSignal.reason);\n\t\telse this.#userSignal?.addEventListener('abort', this.#onUserAbort, { once: true });\n\n\t\tthis.#opened = this.#open(input, call.url);\n\t\tthis.#opened.catch((error: unknown) => this.#fail(error));\n\n\t\tthis.responses = {\n\t\t\t[Symbol.asyncIterator]() {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t\tnext: () => this.#pull(),\n\t\t\treturn: async () => {\n\t\t\t\tthis.#cancel();\n\t\t\t\treturn DONE;\n\t\t\t},\n\t\t};\n\t}\n\n\t// Methods, not `this.#state` comparisons, so TypeScript does not keep a narrowing across awaits.\n\t#isOpen(): boolean {\n\t\treturn this.#state === 'open';\n\t}\n\n\t#throwIfFailed(): void {\n\t\tif (this.#state === 'failed') throw this.#failure;\n\t}\n\n\tasync #open(input: I, url: string): Promise<void> {\n\t\tconst body = createGrpcWebRequestBody(\n\t\t\t// protobuf-ts's encoder requires every oneof to be set; create() fills unset ones so requests\n\t\t\t// built before a oneof was added still send.\n\t\t\tthis.#method.I.toBinary(this.#method.I.create(input), this.#options.binaryOptions),\n\t\t\t'binary',\n\t\t) as BodyInit;\n\t\tconst headers = createGrpcWebRequestHeader(\n\t\t\tnew globalThis.Headers(),\n\t\t\t'binary',\n\t\t\tthis.#options.timeout,\n\t\t\tthis.#options.meta,\n\t\t);\n\t\tif (!this.#isOpen()) return;\n\n\t\tconst fetch = this.#options.fetch ?? globalThis.fetch;\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\t...this.#options.fetchInit,\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders,\n\t\t\t\tbody,\n\t\t\t\tsignal: this.#controller.signal,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow toNetworkRpcError(error, this.#controller.signal);\n\t\t}\n\n\t\t// A response that arrives after the call ended still holds a connection until its body is\n\t\t// cancelled.\n\t\tif (!this.#isOpen()) return cancelQuietly(response.body);\n\n\t\ttry {\n\t\t\tconst [statusCode, detail, meta] = readGrpcWebResponseHeader(response);\n\t\t\tif (statusCode !== undefined && statusCode !== GrpcStatusCode.OK) {\n\t\t\t\tthrow new RpcError(detail ?? code(statusCode), code(statusCode), meta);\n\t\t\t}\n\t\t\tif (statusCode !== undefined) this.#headerStatus = { code: 'OK', detail: detail ?? 'OK' };\n\t\t\tif (!response.body) {\n\t\t\t\tthis.#eof = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst type = response.headers.get('content-type');\n\t\t\tif (type !== 'application/grpc-web' && type !== 'application/grpc-web+proto') {\n\t\t\t\tthrow markNonRetryable(\n\t\t\t\t\tnew RpcError(`unexpected response content type: ${type}`, code(GrpcStatusCode.INTERNAL)),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.#reader = response.body.getReader();\n\t\t} catch (error) {\n\t\t\tcancelQuietly(response.body);\n\t\t\tthrow error;\n\t\t}\n\t\tthis.#decoder = new GrpcWebFrameDecoder(MAX_RESPONSE_MESSAGE_BYTES);\n\t}\n\n\tasync #pull(): Promise<IteratorResult<O, undefined>> {\n\t\ttry {\n\t\t\tif (!this.#decoder && !this.#eof) await this.#opened;\n\t\t\tfor (;;) {\n\t\t\t\tthis.#throwIfFailed();\n\t\t\t\tif (!this.#isOpen()) return DONE;\n\n\t\t\t\tconst frame = this.#decoder?.next();\n\t\t\t\tif (frame?.type === 'data') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: this.#method.O.fromBinary(frame.data, this.#options.binaryOptions),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (frame) return this.#finish(frame.status, frame.meta);\n\t\t\t\tif (this.#eof) {\n\t\t\t\t\t// A proxy can end a dropped stream cleanly, mid-frame or before the status.\n\t\t\t\t\tif (this.#decoder?.buffered || !this.#headerStatus) {\n\t\t\t\t\t\tthrow new RpcError(\n\t\t\t\t\t\t\t'response ended before its status',\n\t\t\t\t\t\t\tcode(GrpcStatusCode.UNAVAILABLE),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn this.#finish(this.#headerStatus, {});\n\t\t\t\t}\n\n\t\t\t\tconst result = await this.#read();\n\t\t\t\tthis.#throwIfFailed();\n\t\t\t\tif (!this.#isOpen()) return DONE;\n\t\t\t\tif (result.done) this.#eof = true;\n\t\t\t\telse this.#decoder!.push(result.value);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (this.#state === 'cancelled') return DONE;\n\t\t\tthis.#fail(error);\n\t\t\tthrow this.#failure;\n\t\t}\n\t}\n\n\tasync #read() {\n\t\ttry {\n\t\t\treturn await this.#reader!.read();\n\t\t} catch (error) {\n\t\t\tthrow toNetworkRpcError(error, this.#controller.signal);\n\t\t}\n\t}\n\n\t#finish(status: RpcStatus, meta: RpcMetadata): IteratorResult<O, undefined> {\n\t\tif (status.code !== 'OK') throw new RpcError(status.detail, status.code, meta);\n\t\tthis.#state = 'done';\n\t\tthis.#release();\n\t\treturn DONE;\n\t}\n\n\t/** Fails the call with `reason`, unless it already ended. */\n\t#fail(reason: unknown): void {\n\t\tif (!this.#isOpen()) return;\n\t\tthis.#failure = this.#toError(reason);\n\t\tthis.#settle('failed', this.#failure);\n\t}\n\n\t#cancel(): void {\n\t\tif (!this.#isOpen()) return;\n\t\tconst error = new RpcError('stream cancelled by consumer', code(GrpcStatusCode.CANCELLED));\n\t\terror.methodName = this.#method.name;\n\t\terror.serviceName = this.#method.service.typeName;\n\t\tthis.#settle('cancelled', error);\n\t}\n\n\t#settle(state: 'failed' | 'cancelled', error: RpcError): void {\n\t\tthis.#state = state;\n\t\tthis.#release();\n\t\tthis.#controller.abort(error);\n\t}\n\n\t/** Drops the body and any bytes buffered from it, so an ended call retains neither. */\n\t#release(): void {\n\t\tthis.#userSignal?.removeEventListener('abort', this.#onUserAbort);\n\t\tcancelQuietly(this.#reader);\n\t\tthis.#reader = undefined;\n\t\tthis.#decoder = undefined;\n\t}\n\n\t#toError(reason: unknown): RpcError {\n\t\tlet error: RpcError;\n\t\tif (reason instanceof RpcError && reason !== this.#controller.signal.reason) error = reason;\n\t\telse if (this.#controller.signal.aborted) {\n\t\t\t// Coded from the caller's abort reason by `normalizeError`.\n\t\t\terror = abortRpcError(reason);\n\t\t} else {\n\t\t\t// A request that can't be serialized or a response that can't be decoded fails every attempt.\n\t\t\terror = markNonRetryable(\n\t\t\t\tnew RpcError(\n\t\t\t\t\treason instanceof Error ? reason.message : String(reason),\n\t\t\t\t\tcode(GrpcStatusCode.INTERNAL),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\terror.methodName = this.#method.name;\n\t\terror.serviceName = this.#method.service.typeName;\n\t\tthis.#normalizeError(error, this.#userSignal);\n\t\treturn error;\n\t}\n}\n"],"mappings":";;;;;;;AAgCA,MAAa,6BAA6B,MAAM,OAAO;AAEvD,MAAM,QAAQ,WAA2B,eAAe;;AAMxD,IAAa,sBAAb,MAAiC;CAChC,CAASA;CACT,UAAwB,EAAE;CAC1B,UAAU;CAEV,YAAY,eAAuB;AAClC,QAAKA,gBAAiB;;;CAIvB,IAAI,WAAmB;AACtB,SAAO,MAAKC;;CAGb,KAAK,OAAyB;AAC7B,MAAI,MAAM,WAAW,EAAG;AACxB,QAAKC,OAAQ,KAAK,MAAM;AACxB,QAAKD,UAAW,MAAM;;;;;;CAOvB,OAAyC;AACxC,MAAI,MAAKA,SAAU,EAAG,QAAO;EAC7B,MAAM,SAAS,MAAKE,KAAM,EAAE;EAC5B,MAAM,OAAO,OAAO;AACpB,MAAI,SAAS,aAAa,QAAQ,SAAS,aAAa,QACvD,OAAM,iBACL,IAAI,SAAS,8BAA8B,QAAQ,KAAK,eAAe,SAAS,CAAC,CACjF;EAEF,MAAM,SAAS,IAAI,SAAS,OAAO,QAAQ,OAAO,YAAY,EAAE,CAAC,UAAU,EAAE;AA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,kBAAkB,YAAY,WAAW,MAAKb,WAAY,OAAO,OAAQ,SAAQ;WAC5E,MAAKA,WAAY,OAAO,QAEhC,SAAQ,cAAc,OAAO;MAG7B,SAAQ,iBACP,IAAI,SACH,kBAAkB,QAAQ,OAAO,UAAU,OAAO,OAAO,EACzD,KAAK,eAAe,SAAS,CAC7B,CACD;AAEF,QAAM,aAAa,MAAKJ,OAAQ;AAChC,QAAM,cAAc,MAAKA,OAAQ,QAAQ;AACzC,QAAKE,eAAgB,OAAO,MAAKC,WAAY;AAC7C,SAAO"}
|
package/dist/grpc/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { GrpcCoreClient, GrpcCoreClientOptions, parseGrpcSimulateTransactionResponse, parseGrpcTransactionResponse } from "./core.mjs";
|
|
2
|
+
import { GrpcStreamCheckpointsOptions, GrpcStreamEventsOptions, GrpcStreamTransactionsOptions } from "./stream-types.mjs";
|
|
2
3
|
import { GrpcExecuteTransactionOptions, GrpcGetTransactionOptions, GrpcSignAndExecuteTransactionOptions, GrpcSimulateTransactionInclude, GrpcSimulateTransactionOptions, GrpcSimulateTransactionProtoJson, GrpcSimulateTransactionResult, GrpcTransactionInclude, GrpcTransactionProtoJson, GrpcTransactionResult, GrpcWaitForTransactionOptions, SuiGrpcClient, SuiGrpcClientOptions, isSuiGrpcClient } from "./client.mjs";
|
|
3
4
|
import { GrpcWebFetchTransport } from "./transport.mjs";
|
|
4
5
|
import { types_d_exports } from "./proto/types.mjs";
|
|
5
6
|
import { RpcError, RpcTransport } from "@protobuf-ts/runtime-rpc";
|
|
6
7
|
import { GrpcStatusCode, GrpcWebOptions } from "@protobuf-ts/grpcweb-transport";
|
|
7
|
-
export { GrpcCoreClient, type GrpcCoreClientOptions, type GrpcExecuteTransactionOptions, type GrpcGetTransactionOptions, type GrpcSignAndExecuteTransactionOptions, type GrpcSimulateTransactionInclude, type GrpcSimulateTransactionOptions, type GrpcSimulateTransactionProtoJson, type GrpcSimulateTransactionResult, GrpcStatusCode, type GrpcTransactionInclude, type GrpcTransactionProtoJson, type GrpcTransactionResult, types_d_exports as GrpcTypes, type GrpcWaitForTransactionOptions, GrpcWebFetchTransport, type GrpcWebOptions, RpcError, type RpcTransport, SuiGrpcClient, type SuiGrpcClientOptions, isSuiGrpcClient, parseGrpcSimulateTransactionResponse, parseGrpcTransactionResponse };
|
|
8
|
+
export { GrpcCoreClient, type GrpcCoreClientOptions, type GrpcExecuteTransactionOptions, type GrpcGetTransactionOptions, type GrpcSignAndExecuteTransactionOptions, type GrpcSimulateTransactionInclude, type GrpcSimulateTransactionOptions, type GrpcSimulateTransactionProtoJson, type GrpcSimulateTransactionResult, GrpcStatusCode, type GrpcStreamCheckpointsOptions, type GrpcStreamEventsOptions, type GrpcStreamTransactionsOptions, type GrpcTransactionInclude, type GrpcTransactionProtoJson, type GrpcTransactionResult, types_d_exports as GrpcTypes, type GrpcWaitForTransactionOptions, GrpcWebFetchTransport, type GrpcWebOptions, RpcError, type RpcTransport, SuiGrpcClient, type SuiGrpcClientOptions, isSuiGrpcClient, parseGrpcSimulateTransactionResponse, parseGrpcTransactionResponse };
|
package/dist/grpc/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GrpcWebFetchTransport } from "./transport.mjs";
|
|
2
1
|
import { GrpcCoreClient, parseGrpcSimulateTransactionResponse, parseGrpcTransactionResponse } from "./core.mjs";
|
|
2
|
+
import { GrpcWebFetchTransport } from "./transport.mjs";
|
|
3
3
|
import { SuiGrpcClient, isSuiGrpcClient } from "./client.mjs";
|
|
4
4
|
import { types_exports } from "./proto/types.mjs";
|
|
5
5
|
import { RpcError } from "@protobuf-ts/runtime-rpc";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RpcError } from "@protobuf-ts/runtime-rpc";
|
|
2
|
+
|
|
3
|
+
//#region src/grpc/network-error.ts
|
|
4
|
+
/**
|
|
5
|
+
* Codes a network failure of a gRPC-web fetch or body read (a `TypeError`, as fetch reports it)
|
|
6
|
+
* as `UNAVAILABLE` instead of upstream's `INTERNAL`. Other errors, and failures after `signal`
|
|
7
|
+
* aborts, are returned unchanged.
|
|
8
|
+
*/
|
|
9
|
+
function toNetworkRpcError(error, signal) {
|
|
10
|
+
if (signal?.aborted || !(error instanceof TypeError)) return error;
|
|
11
|
+
return new RpcError(error.message, "UNAVAILABLE");
|
|
12
|
+
}
|
|
13
|
+
/** Errors whose message is already plain text, so it is not percent-decoded again. */
|
|
14
|
+
const plainMessageErrors = /* @__PURE__ */ new WeakSet();
|
|
15
|
+
/**
|
|
16
|
+
* The error for a call the caller aborted. Its message is the caller's own text, which was never
|
|
17
|
+
* percent-encoded on the wire. The code is applied from the reason later.
|
|
18
|
+
*/
|
|
19
|
+
function abortRpcError(reason) {
|
|
20
|
+
const error = reason instanceof RpcError ? reason : new RpcError(abortMessage(reason), "CANCELLED");
|
|
21
|
+
plainMessageErrors.add(error);
|
|
22
|
+
return error;
|
|
23
|
+
}
|
|
24
|
+
function abortMessage(reason) {
|
|
25
|
+
if (typeof reason === "string") return reason;
|
|
26
|
+
return reason instanceof Error ? reason.message : "The operation was aborted";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { abortRpcError, plainMessageErrors, toNetworkRpcError };
|
|
31
|
+
//# sourceMappingURL=network-error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-error.mjs","names":[],"sources":["../../src/grpc/network-error.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { RpcError } from '@protobuf-ts/runtime-rpc';\n\n/**\n * Codes a network failure of a gRPC-web fetch or body read (a `TypeError`, as fetch reports it)\n * as `UNAVAILABLE` instead of upstream's `INTERNAL`. Other errors, and failures after `signal`\n * aborts, are returned unchanged.\n */\nexport function toNetworkRpcError(error: unknown, signal: AbortSignal | null | undefined): unknown {\n\tif (signal?.aborted || !(error instanceof TypeError)) return error;\n\treturn new RpcError(error.message, 'UNAVAILABLE');\n}\n\n/** Errors whose message is already plain text, so it is not percent-decoded again. */\nexport const plainMessageErrors = new WeakSet<RpcError>();\n\n/**\n * The error for a call the caller aborted. Its message is the caller's own text, which was never\n * percent-encoded on the wire. The code is applied from the reason later.\n */\nexport function abortRpcError(reason: unknown): RpcError {\n\tconst error =\n\t\treason instanceof RpcError ? reason : new RpcError(abortMessage(reason), 'CANCELLED');\n\tplainMessageErrors.add(error);\n\treturn error;\n}\n\nfunction abortMessage(reason: unknown): string {\n\tif (typeof reason === 'string') return reason;\n\treturn reason instanceof Error ? reason.message : 'The operation was aborted';\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,kBAAkB,OAAgB,QAAiD;AAClG,KAAI,QAAQ,WAAW,EAAE,iBAAiB,WAAY,QAAO;AAC7D,QAAO,IAAI,SAAS,MAAM,SAAS,cAAc;;;AAIlD,MAAa,qCAAqB,IAAI,SAAmB;;;;;AAMzD,SAAgB,cAAc,QAA2B;CACxD,MAAM,QACL,kBAAkB,WAAW,SAAS,IAAI,SAAS,aAAa,OAAO,EAAE,YAAY;AACtF,oBAAmB,IAAI,MAAM;AAC7B,QAAO;;AAGR,SAAS,aAAa,QAAyB;AAC9C,KAAI,OAAO,WAAW,SAAU,QAAO;AACvC,QAAO,kBAAkB,QAAQ,OAAO,UAAU"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { Duration } from "../protobuf/duration.mjs";
|
|
2
|
+
import { MessageType } from "@protobuf-ts/runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/grpc/proto/google/rpc/error_details.ts
|
|
5
|
+
var ErrorInfo$Type = class extends MessageType {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("google.rpc.ErrorInfo", [
|
|
8
|
+
{
|
|
9
|
+
no: 1,
|
|
10
|
+
name: "reason",
|
|
11
|
+
kind: "scalar",
|
|
12
|
+
T: 9
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
no: 2,
|
|
16
|
+
name: "domain",
|
|
17
|
+
kind: "scalar",
|
|
18
|
+
T: 9
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
no: 3,
|
|
22
|
+
name: "metadata",
|
|
23
|
+
kind: "map",
|
|
24
|
+
K: 9,
|
|
25
|
+
V: {
|
|
26
|
+
kind: "scalar",
|
|
27
|
+
T: 9
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @generated MessageType for protobuf message google.rpc.ErrorInfo
|
|
35
|
+
*/
|
|
36
|
+
const ErrorInfo = new ErrorInfo$Type();
|
|
37
|
+
var RetryInfo$Type = class extends MessageType {
|
|
38
|
+
constructor() {
|
|
39
|
+
super("google.rpc.RetryInfo", [{
|
|
40
|
+
no: 1,
|
|
41
|
+
name: "retry_delay",
|
|
42
|
+
kind: "message",
|
|
43
|
+
T: () => Duration
|
|
44
|
+
}]);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @generated MessageType for protobuf message google.rpc.RetryInfo
|
|
49
|
+
*/
|
|
50
|
+
const RetryInfo = new RetryInfo$Type();
|
|
51
|
+
var DebugInfo$Type = class extends MessageType {
|
|
52
|
+
constructor() {
|
|
53
|
+
super("google.rpc.DebugInfo", [{
|
|
54
|
+
no: 1,
|
|
55
|
+
name: "stack_entries",
|
|
56
|
+
kind: "scalar",
|
|
57
|
+
repeat: 2,
|
|
58
|
+
T: 9
|
|
59
|
+
}, {
|
|
60
|
+
no: 2,
|
|
61
|
+
name: "detail",
|
|
62
|
+
kind: "scalar",
|
|
63
|
+
T: 9
|
|
64
|
+
}]);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @generated MessageType for protobuf message google.rpc.DebugInfo
|
|
69
|
+
*/
|
|
70
|
+
const DebugInfo = new DebugInfo$Type();
|
|
71
|
+
var QuotaFailure$Type = class extends MessageType {
|
|
72
|
+
constructor() {
|
|
73
|
+
super("google.rpc.QuotaFailure", [{
|
|
74
|
+
no: 1,
|
|
75
|
+
name: "violations",
|
|
76
|
+
kind: "message",
|
|
77
|
+
repeat: 2,
|
|
78
|
+
T: () => QuotaFailure_Violation
|
|
79
|
+
}]);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* @generated MessageType for protobuf message google.rpc.QuotaFailure
|
|
84
|
+
*/
|
|
85
|
+
const QuotaFailure = new QuotaFailure$Type();
|
|
86
|
+
var QuotaFailure_Violation$Type = class extends MessageType {
|
|
87
|
+
constructor() {
|
|
88
|
+
super("google.rpc.QuotaFailure.Violation", [{
|
|
89
|
+
no: 1,
|
|
90
|
+
name: "subject",
|
|
91
|
+
kind: "scalar",
|
|
92
|
+
T: 9
|
|
93
|
+
}, {
|
|
94
|
+
no: 2,
|
|
95
|
+
name: "description",
|
|
96
|
+
kind: "scalar",
|
|
97
|
+
T: 9
|
|
98
|
+
}]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* @generated MessageType for protobuf message google.rpc.QuotaFailure.Violation
|
|
103
|
+
*/
|
|
104
|
+
const QuotaFailure_Violation = new QuotaFailure_Violation$Type();
|
|
105
|
+
var PreconditionFailure$Type = class extends MessageType {
|
|
106
|
+
constructor() {
|
|
107
|
+
super("google.rpc.PreconditionFailure", [{
|
|
108
|
+
no: 1,
|
|
109
|
+
name: "violations",
|
|
110
|
+
kind: "message",
|
|
111
|
+
repeat: 2,
|
|
112
|
+
T: () => PreconditionFailure_Violation
|
|
113
|
+
}]);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* @generated MessageType for protobuf message google.rpc.PreconditionFailure
|
|
118
|
+
*/
|
|
119
|
+
const PreconditionFailure = new PreconditionFailure$Type();
|
|
120
|
+
var PreconditionFailure_Violation$Type = class extends MessageType {
|
|
121
|
+
constructor() {
|
|
122
|
+
super("google.rpc.PreconditionFailure.Violation", [
|
|
123
|
+
{
|
|
124
|
+
no: 1,
|
|
125
|
+
name: "type",
|
|
126
|
+
kind: "scalar",
|
|
127
|
+
T: 9
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
no: 2,
|
|
131
|
+
name: "subject",
|
|
132
|
+
kind: "scalar",
|
|
133
|
+
T: 9
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
no: 3,
|
|
137
|
+
name: "description",
|
|
138
|
+
kind: "scalar",
|
|
139
|
+
T: 9
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* @generated MessageType for protobuf message google.rpc.PreconditionFailure.Violation
|
|
146
|
+
*/
|
|
147
|
+
const PreconditionFailure_Violation = new PreconditionFailure_Violation$Type();
|
|
148
|
+
var BadRequest$Type = class extends MessageType {
|
|
149
|
+
constructor() {
|
|
150
|
+
super("google.rpc.BadRequest", [{
|
|
151
|
+
no: 1,
|
|
152
|
+
name: "field_violations",
|
|
153
|
+
kind: "message",
|
|
154
|
+
repeat: 2,
|
|
155
|
+
T: () => BadRequest_FieldViolation
|
|
156
|
+
}]);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* @generated MessageType for protobuf message google.rpc.BadRequest
|
|
161
|
+
*/
|
|
162
|
+
const BadRequest = new BadRequest$Type();
|
|
163
|
+
var BadRequest_FieldViolation$Type = class extends MessageType {
|
|
164
|
+
constructor() {
|
|
165
|
+
super("google.rpc.BadRequest.FieldViolation", [
|
|
166
|
+
{
|
|
167
|
+
no: 1,
|
|
168
|
+
name: "field",
|
|
169
|
+
kind: "scalar",
|
|
170
|
+
T: 9
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
no: 2,
|
|
174
|
+
name: "description",
|
|
175
|
+
kind: "scalar",
|
|
176
|
+
T: 9
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
no: 3,
|
|
180
|
+
name: "reason",
|
|
181
|
+
kind: "scalar",
|
|
182
|
+
T: 9
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
no: 4,
|
|
186
|
+
name: "localized_message",
|
|
187
|
+
kind: "message",
|
|
188
|
+
T: () => LocalizedMessage
|
|
189
|
+
}
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* @generated MessageType for protobuf message google.rpc.BadRequest.FieldViolation
|
|
195
|
+
*/
|
|
196
|
+
const BadRequest_FieldViolation = new BadRequest_FieldViolation$Type();
|
|
197
|
+
var RequestInfo$Type = class extends MessageType {
|
|
198
|
+
constructor() {
|
|
199
|
+
super("google.rpc.RequestInfo", [{
|
|
200
|
+
no: 1,
|
|
201
|
+
name: "request_id",
|
|
202
|
+
kind: "scalar",
|
|
203
|
+
T: 9
|
|
204
|
+
}, {
|
|
205
|
+
no: 2,
|
|
206
|
+
name: "serving_data",
|
|
207
|
+
kind: "scalar",
|
|
208
|
+
T: 9
|
|
209
|
+
}]);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @generated MessageType for protobuf message google.rpc.RequestInfo
|
|
214
|
+
*/
|
|
215
|
+
const RequestInfo = new RequestInfo$Type();
|
|
216
|
+
var ResourceInfo$Type = class extends MessageType {
|
|
217
|
+
constructor() {
|
|
218
|
+
super("google.rpc.ResourceInfo", [
|
|
219
|
+
{
|
|
220
|
+
no: 1,
|
|
221
|
+
name: "resource_type",
|
|
222
|
+
kind: "scalar",
|
|
223
|
+
T: 9
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
no: 2,
|
|
227
|
+
name: "resource_name",
|
|
228
|
+
kind: "scalar",
|
|
229
|
+
T: 9
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
no: 3,
|
|
233
|
+
name: "owner",
|
|
234
|
+
kind: "scalar",
|
|
235
|
+
T: 9
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
no: 4,
|
|
239
|
+
name: "description",
|
|
240
|
+
kind: "scalar",
|
|
241
|
+
T: 9
|
|
242
|
+
}
|
|
243
|
+
]);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* @generated MessageType for protobuf message google.rpc.ResourceInfo
|
|
248
|
+
*/
|
|
249
|
+
const ResourceInfo = new ResourceInfo$Type();
|
|
250
|
+
var Help$Type = class extends MessageType {
|
|
251
|
+
constructor() {
|
|
252
|
+
super("google.rpc.Help", [{
|
|
253
|
+
no: 1,
|
|
254
|
+
name: "links",
|
|
255
|
+
kind: "message",
|
|
256
|
+
repeat: 2,
|
|
257
|
+
T: () => Help_Link
|
|
258
|
+
}]);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* @generated MessageType for protobuf message google.rpc.Help
|
|
263
|
+
*/
|
|
264
|
+
const Help = new Help$Type();
|
|
265
|
+
var Help_Link$Type = class extends MessageType {
|
|
266
|
+
constructor() {
|
|
267
|
+
super("google.rpc.Help.Link", [{
|
|
268
|
+
no: 1,
|
|
269
|
+
name: "description",
|
|
270
|
+
kind: "scalar",
|
|
271
|
+
T: 9
|
|
272
|
+
}, {
|
|
273
|
+
no: 2,
|
|
274
|
+
name: "url",
|
|
275
|
+
kind: "scalar",
|
|
276
|
+
T: 9
|
|
277
|
+
}]);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* @generated MessageType for protobuf message google.rpc.Help.Link
|
|
282
|
+
*/
|
|
283
|
+
const Help_Link = new Help_Link$Type();
|
|
284
|
+
var LocalizedMessage$Type = class extends MessageType {
|
|
285
|
+
constructor() {
|
|
286
|
+
super("google.rpc.LocalizedMessage", [{
|
|
287
|
+
no: 1,
|
|
288
|
+
name: "locale",
|
|
289
|
+
kind: "scalar",
|
|
290
|
+
T: 9
|
|
291
|
+
}, {
|
|
292
|
+
no: 2,
|
|
293
|
+
name: "message",
|
|
294
|
+
kind: "scalar",
|
|
295
|
+
T: 9
|
|
296
|
+
}]);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* @generated MessageType for protobuf message google.rpc.LocalizedMessage
|
|
301
|
+
*/
|
|
302
|
+
const LocalizedMessage = new LocalizedMessage$Type();
|
|
303
|
+
|
|
304
|
+
//#endregion
|
|
305
|
+
export { ErrorInfo };
|
|
306
|
+
//# sourceMappingURL=error_details.mjs.map
|