@mysten/sui 2.39.1 → 3.0.1
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 +169 -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 +5 -3
- package/dist/client/index.mjs +6 -3
- 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 +17 -0
- package/dist/client/transaction-data.d.mts.map +1 -0
- package/dist/client/transaction-data.mjs +472 -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 +2 -2
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +91 -30
- 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 +8 -8
- 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 +294 -118
- 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/forking/v1alpha/forking_service.client.d.mts +4 -4
- 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/name_service.client.d.mts +4 -4
- 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 +20 -14
- 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 +10 -9
- 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 +2 -0
- 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/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 +247 -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 +4 -5
- 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 -2
- 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 +610 -0
- package/src/client/transaction-resolver.ts +158 -69
- package/src/client/types.ts +530 -115
- package/src/client/utils.ts +146 -61
- 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
package/src/grpc/filters.ts
CHANGED
|
@@ -2,67 +2,66 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { ResolvedEventFilter, ResolvedTransactionFilter } from '../client/query-filters.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
EventFilter,
|
|
7
|
+
EventLiteral,
|
|
8
|
+
TransactionFilter,
|
|
9
|
+
TransactionLiteral,
|
|
10
|
+
} from './proto/sui/rpc/v2/filter.js';
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Converts a resolved transaction filter into a single-term gRPC DNF filter (every predicate
|
|
14
|
+
* ANDed), or `undefined` when the filter matches everything.
|
|
15
|
+
*/
|
|
16
|
+
export function toGrpcTransactionFilter(
|
|
17
|
+
filter: ResolvedTransactionFilter | undefined,
|
|
18
|
+
): TransactionFilter | undefined {
|
|
19
|
+
const predicates: TransactionLiteral['predicate'][] = [];
|
|
20
|
+
|
|
21
|
+
if (filter?.sender != null) {
|
|
22
|
+
predicates.push({ oneofKind: 'sender', sender: { address: filter.sender } });
|
|
23
|
+
}
|
|
24
|
+
if (filter?.affectedAddress != null) {
|
|
25
|
+
predicates.push({
|
|
26
|
+
oneofKind: 'affectedAddress',
|
|
27
|
+
affectedAddress: { address: filter.affectedAddress },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (filter?.affectedObject != null) {
|
|
31
|
+
predicates.push({
|
|
32
|
+
oneofKind: 'affectedObject',
|
|
33
|
+
affectedObject: { objectId: filter.affectedObject },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (filter?.function != null) {
|
|
37
|
+
predicates.push({ oneofKind: 'moveCall', moveCall: { function: filter.function } });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return predicates.length
|
|
41
|
+
? { terms: [{ literals: predicates.map((predicate) => ({ negated: false, predicate })) }] }
|
|
42
|
+
: undefined;
|
|
32
43
|
}
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
eventType: {
|
|
57
|
-
eventType:
|
|
58
|
-
filter.$kind === 'eventTypeModule'
|
|
59
|
-
? `${filter.package}::${filter.module}`
|
|
60
|
-
: filter.eventType,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
};
|
|
45
|
+
/**
|
|
46
|
+
* Converts a resolved event filter into a single-term gRPC DNF filter (every predicate
|
|
47
|
+
* ANDed), or `undefined` when the filter matches everything.
|
|
48
|
+
*/
|
|
49
|
+
export function toGrpcEventFilter(
|
|
50
|
+
filter: ResolvedEventFilter | undefined,
|
|
51
|
+
): EventFilter | undefined {
|
|
52
|
+
const predicates: EventLiteral['predicate'][] = [];
|
|
53
|
+
|
|
54
|
+
if (filter?.sender != null) {
|
|
55
|
+
predicates.push({ oneofKind: 'sender', sender: { address: filter.sender } });
|
|
56
|
+
}
|
|
57
|
+
if (filter?.emitModule != null) {
|
|
58
|
+
predicates.push({ oneofKind: 'emitModule', emitModule: { module: filter.emitModule } });
|
|
59
|
+
}
|
|
60
|
+
if (filter?.eventType != null) {
|
|
61
|
+
predicates.push({ oneofKind: 'eventType', eventType: { eventType: filter.eventType } });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return predicates.length
|
|
65
|
+
? { terms: [{ literals: predicates.map((predicate) => ({ negated: false, predicate })) }] }
|
|
66
|
+
: undefined;
|
|
68
67
|
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* An on-demand reader for binary gRPC-web server streams. Request construction and header/trailer
|
|
6
|
+
* parsing use the public helpers of `@protobuf-ts/grpcweb-transport`. Frame extraction and call
|
|
7
|
+
* settlement are adapted from `@protobuf-ts/grpcweb-transport` 2.11.1 (`grpc-web-format.ts`,
|
|
8
|
+
* `grpc-web-transport.ts`), Copyright (c) Timo Stamm, licensed under the Apache License, Version
|
|
9
|
+
* 2.0: https://github.com/timostamm/protobuf-ts
|
|
10
|
+
*
|
|
11
|
+
* Unlike upstream, the body is read only while the consumer waits for a message, and frame sizes
|
|
12
|
+
* are checked before their payload is buffered.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
createGrpcWebRequestBody,
|
|
17
|
+
createGrpcWebRequestHeader,
|
|
18
|
+
GrpcStatusCode,
|
|
19
|
+
GrpcWebFrame,
|
|
20
|
+
readGrpcWebResponseHeader,
|
|
21
|
+
readGrpcWebResponseTrailer,
|
|
22
|
+
} from '@protobuf-ts/grpcweb-transport';
|
|
23
|
+
import type { GrpcWebOptions } from '@protobuf-ts/grpcweb-transport';
|
|
24
|
+
import { RpcError } from '@protobuf-ts/runtime-rpc';
|
|
25
|
+
import type { MethodInfo, RpcMetadata, RpcStatus } from '@protobuf-ts/runtime-rpc';
|
|
26
|
+
|
|
27
|
+
import { cancelQuietly } from '../client/utils.js';
|
|
28
|
+
import { abortRpcError, toNetworkRpcError } from './network-error.js';
|
|
29
|
+
import { markNonRetryable } from './pull-call.js';
|
|
30
|
+
import type { ServerStreamingIterableCall } from './pull-call.js';
|
|
31
|
+
|
|
32
|
+
// Matches the limit sui's Rust client sets for checkpoint reads.
|
|
33
|
+
export const MAX_RESPONSE_MESSAGE_BYTES = 128 * 1024 * 1024;
|
|
34
|
+
|
|
35
|
+
const code = (status: GrpcStatusCode) => GrpcStatusCode[status];
|
|
36
|
+
|
|
37
|
+
export type GrpcWebResponseFrame =
|
|
38
|
+
{ type: 'data'; data: Uint8Array } | { type: 'trailer'; status: RpcStatus; meta: RpcMetadata };
|
|
39
|
+
|
|
40
|
+
/** Splits a binary gRPC-web response body into frames: `push` chunks, then `next` until `undefined`. */
|
|
41
|
+
export class GrpcWebFrameDecoder {
|
|
42
|
+
readonly #maxFrameBytes: number;
|
|
43
|
+
#chunks: Uint8Array[] = [];
|
|
44
|
+
#length = 0;
|
|
45
|
+
|
|
46
|
+
constructor(maxFrameBytes: number) {
|
|
47
|
+
this.#maxFrameBytes = maxFrameBytes;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Bytes received but not yet returned as a frame. */
|
|
51
|
+
get buffered(): number {
|
|
52
|
+
return this.#length;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
push(chunk: Uint8Array): void {
|
|
56
|
+
if (chunk.length === 0) return;
|
|
57
|
+
this.#chunks.push(chunk);
|
|
58
|
+
this.#length += chunk.length;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The next complete frame, or `undefined` until more bytes arrive. An oversized frame is
|
|
63
|
+
* rejected as soon as its 5-byte prefix arrives.
|
|
64
|
+
*/
|
|
65
|
+
next(): GrpcWebResponseFrame | undefined {
|
|
66
|
+
if (this.#length < 5) return undefined;
|
|
67
|
+
const prefix = this.#peek(5);
|
|
68
|
+
const flag = prefix[0];
|
|
69
|
+
if (flag !== GrpcWebFrame.DATA && flag !== GrpcWebFrame.TRAILER) {
|
|
70
|
+
throw markNonRetryable(
|
|
71
|
+
new RpcError(`unsupported grpc-web frame ${flag}`, code(GrpcStatusCode.INTERNAL)),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const length = new DataView(prefix.buffer, prefix.byteOffset, 5).getUint32(1);
|
|
75
|
+
if (length > this.#maxFrameBytes) {
|
|
76
|
+
// The server would send the same frame again on retry.
|
|
77
|
+
throw markNonRetryable(
|
|
78
|
+
new RpcError(
|
|
79
|
+
`grpc-web frame of ${length} bytes exceeds the ${this.#maxFrameBytes} byte limit`,
|
|
80
|
+
code(GrpcStatusCode.RESOURCE_EXHAUSTED),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (this.#length < 5 + length) return undefined;
|
|
85
|
+
const payload = this.#take(5 + length).subarray(5);
|
|
86
|
+
if (flag === GrpcWebFrame.DATA) return { type: 'data', data: payload };
|
|
87
|
+
const [statusCode, detail, meta] = readGrpcWebResponseTrailer(payload);
|
|
88
|
+
return {
|
|
89
|
+
type: 'trailer',
|
|
90
|
+
status: { code: code(statusCode), detail: detail ?? code(statusCode) },
|
|
91
|
+
meta,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The buffered bytes from the start, joining chunks only when the first holds fewer than `n`. */
|
|
96
|
+
#peek(n: number): Uint8Array {
|
|
97
|
+
if (this.#chunks[0].length < n) {
|
|
98
|
+
const joined = new Uint8Array(this.#length);
|
|
99
|
+
let offset = 0;
|
|
100
|
+
for (const chunk of this.#chunks) {
|
|
101
|
+
joined.set(chunk, offset);
|
|
102
|
+
offset += chunk.length;
|
|
103
|
+
}
|
|
104
|
+
this.#chunks = [joined];
|
|
105
|
+
}
|
|
106
|
+
return this.#chunks[0];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#take(n: number): Uint8Array {
|
|
110
|
+
const first = this.#peek(n);
|
|
111
|
+
this.#length -= n;
|
|
112
|
+
if (first.length === n) this.#chunks.shift();
|
|
113
|
+
else this.#chunks[0] = first.subarray(n);
|
|
114
|
+
return first.subarray(0, n);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface GrpcWebPullCallOptions {
|
|
119
|
+
/** Options already merged with the transport's defaults. */
|
|
120
|
+
options: GrpcWebOptions;
|
|
121
|
+
url: string;
|
|
122
|
+
/** Applied to every error the call surfaces, except a consumer's own cancellation. */
|
|
123
|
+
normalizeError: (error: RpcError, signal: AbortSignal | undefined) => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const DONE = { done: true, value: undefined } as const;
|
|
127
|
+
|
|
128
|
+
type State = 'open' | 'done' | 'failed' | 'cancelled';
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A gRPC-web server-streaming call whose body is read only while the consumer waits on
|
|
132
|
+
* `responses.next()`. It has a single consumer: `responses.next()` must not be called concurrently.
|
|
133
|
+
*
|
|
134
|
+
* An abort, `return()` or failure can land during any await, so every await is followed by
|
|
135
|
+
* `#throwIfFailed()` and `#isOpen()`, and the first failure is sticky.
|
|
136
|
+
*/
|
|
137
|
+
export class GrpcWebPullCall<
|
|
138
|
+
I extends object,
|
|
139
|
+
O extends object,
|
|
140
|
+
> implements ServerStreamingIterableCall<O> {
|
|
141
|
+
readonly responses: AsyncIterableIterator<O>;
|
|
142
|
+
|
|
143
|
+
readonly #method: MethodInfo<I, O>;
|
|
144
|
+
readonly #options: GrpcWebOptions;
|
|
145
|
+
readonly #normalizeError: GrpcWebPullCallOptions['normalizeError'];
|
|
146
|
+
readonly #userSignal: AbortSignal | undefined;
|
|
147
|
+
// Aborted by the caller's signal, by `return()` and on failure, so the request is released even
|
|
148
|
+
// when nothing is pulling.
|
|
149
|
+
readonly #controller = new AbortController();
|
|
150
|
+
readonly #onUserAbort = () => this.#controller.abort(this.#userSignal!.reason);
|
|
151
|
+
readonly #opened: Promise<void>;
|
|
152
|
+
|
|
153
|
+
#state: State = 'open';
|
|
154
|
+
#failure: RpcError | undefined;
|
|
155
|
+
#reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
156
|
+
#decoder: GrpcWebFrameDecoder | undefined;
|
|
157
|
+
// Set by a trailers-only response, whose status arrives in the HTTP headers.
|
|
158
|
+
#headerStatus: RpcStatus | undefined;
|
|
159
|
+
#eof = false;
|
|
160
|
+
|
|
161
|
+
constructor(method: MethodInfo<I, O>, input: I, call: GrpcWebPullCallOptions) {
|
|
162
|
+
this.#method = method;
|
|
163
|
+
this.#options = call.options;
|
|
164
|
+
this.#normalizeError = call.normalizeError;
|
|
165
|
+
this.#userSignal = call.options.abort;
|
|
166
|
+
|
|
167
|
+
// Registered before an already-aborted caller signal is applied, so that abort fails the call.
|
|
168
|
+
this.#controller.signal.addEventListener(
|
|
169
|
+
'abort',
|
|
170
|
+
() => this.#fail(this.#controller.signal.reason),
|
|
171
|
+
{ once: true },
|
|
172
|
+
);
|
|
173
|
+
if (this.#userSignal?.aborted) this.#controller.abort(this.#userSignal.reason);
|
|
174
|
+
else this.#userSignal?.addEventListener('abort', this.#onUserAbort, { once: true });
|
|
175
|
+
|
|
176
|
+
this.#opened = this.#open(input, call.url);
|
|
177
|
+
this.#opened.catch((error: unknown) => this.#fail(error));
|
|
178
|
+
|
|
179
|
+
this.responses = {
|
|
180
|
+
[Symbol.asyncIterator]() {
|
|
181
|
+
return this;
|
|
182
|
+
},
|
|
183
|
+
next: () => this.#pull(),
|
|
184
|
+
return: async () => {
|
|
185
|
+
this.#cancel();
|
|
186
|
+
return DONE;
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Methods, not `this.#state` comparisons, so TypeScript does not keep a narrowing across awaits.
|
|
192
|
+
#isOpen(): boolean {
|
|
193
|
+
return this.#state === 'open';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#throwIfFailed(): void {
|
|
197
|
+
if (this.#state === 'failed') throw this.#failure;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async #open(input: I, url: string): Promise<void> {
|
|
201
|
+
const body = createGrpcWebRequestBody(
|
|
202
|
+
// protobuf-ts's encoder requires every oneof to be set; create() fills unset ones so requests
|
|
203
|
+
// built before a oneof was added still send.
|
|
204
|
+
this.#method.I.toBinary(this.#method.I.create(input), this.#options.binaryOptions),
|
|
205
|
+
'binary',
|
|
206
|
+
) as BodyInit;
|
|
207
|
+
const headers = createGrpcWebRequestHeader(
|
|
208
|
+
new globalThis.Headers(),
|
|
209
|
+
'binary',
|
|
210
|
+
this.#options.timeout,
|
|
211
|
+
this.#options.meta,
|
|
212
|
+
);
|
|
213
|
+
if (!this.#isOpen()) return;
|
|
214
|
+
|
|
215
|
+
const fetch = this.#options.fetch ?? globalThis.fetch;
|
|
216
|
+
let response: Response;
|
|
217
|
+
try {
|
|
218
|
+
response = await fetch(url, {
|
|
219
|
+
...this.#options.fetchInit,
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers,
|
|
222
|
+
body,
|
|
223
|
+
signal: this.#controller.signal,
|
|
224
|
+
});
|
|
225
|
+
} catch (error) {
|
|
226
|
+
throw toNetworkRpcError(error, this.#controller.signal);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// A response that arrives after the call ended still holds a connection until its body is
|
|
230
|
+
// cancelled.
|
|
231
|
+
if (!this.#isOpen()) return cancelQuietly(response.body);
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const [statusCode, detail, meta] = readGrpcWebResponseHeader(response);
|
|
235
|
+
if (statusCode !== undefined && statusCode !== GrpcStatusCode.OK) {
|
|
236
|
+
throw new RpcError(detail ?? code(statusCode), code(statusCode), meta);
|
|
237
|
+
}
|
|
238
|
+
if (statusCode !== undefined) this.#headerStatus = { code: 'OK', detail: detail ?? 'OK' };
|
|
239
|
+
if (!response.body) {
|
|
240
|
+
this.#eof = true;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const type = response.headers.get('content-type');
|
|
244
|
+
if (type !== 'application/grpc-web' && type !== 'application/grpc-web+proto') {
|
|
245
|
+
throw markNonRetryable(
|
|
246
|
+
new RpcError(`unexpected response content type: ${type}`, code(GrpcStatusCode.INTERNAL)),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
this.#reader = response.body.getReader();
|
|
250
|
+
} catch (error) {
|
|
251
|
+
cancelQuietly(response.body);
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
this.#decoder = new GrpcWebFrameDecoder(MAX_RESPONSE_MESSAGE_BYTES);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async #pull(): Promise<IteratorResult<O, undefined>> {
|
|
258
|
+
try {
|
|
259
|
+
if (!this.#decoder && !this.#eof) await this.#opened;
|
|
260
|
+
for (;;) {
|
|
261
|
+
this.#throwIfFailed();
|
|
262
|
+
if (!this.#isOpen()) return DONE;
|
|
263
|
+
|
|
264
|
+
const frame = this.#decoder?.next();
|
|
265
|
+
if (frame?.type === 'data') {
|
|
266
|
+
return {
|
|
267
|
+
done: false,
|
|
268
|
+
value: this.#method.O.fromBinary(frame.data, this.#options.binaryOptions),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (frame) return this.#finish(frame.status, frame.meta);
|
|
272
|
+
if (this.#eof) {
|
|
273
|
+
// A proxy can end a dropped stream cleanly, mid-frame or before the status.
|
|
274
|
+
if (this.#decoder?.buffered || !this.#headerStatus) {
|
|
275
|
+
throw new RpcError(
|
|
276
|
+
'response ended before its status',
|
|
277
|
+
code(GrpcStatusCode.UNAVAILABLE),
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return this.#finish(this.#headerStatus, {});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const result = await this.#read();
|
|
284
|
+
this.#throwIfFailed();
|
|
285
|
+
if (!this.#isOpen()) return DONE;
|
|
286
|
+
if (result.done) this.#eof = true;
|
|
287
|
+
else this.#decoder!.push(result.value);
|
|
288
|
+
}
|
|
289
|
+
} catch (error) {
|
|
290
|
+
if (this.#state === 'cancelled') return DONE;
|
|
291
|
+
this.#fail(error);
|
|
292
|
+
throw this.#failure;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async #read() {
|
|
297
|
+
try {
|
|
298
|
+
return await this.#reader!.read();
|
|
299
|
+
} catch (error) {
|
|
300
|
+
throw toNetworkRpcError(error, this.#controller.signal);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
#finish(status: RpcStatus, meta: RpcMetadata): IteratorResult<O, undefined> {
|
|
305
|
+
if (status.code !== 'OK') throw new RpcError(status.detail, status.code, meta);
|
|
306
|
+
this.#state = 'done';
|
|
307
|
+
this.#release();
|
|
308
|
+
return DONE;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Fails the call with `reason`, unless it already ended. */
|
|
312
|
+
#fail(reason: unknown): void {
|
|
313
|
+
if (!this.#isOpen()) return;
|
|
314
|
+
this.#failure = this.#toError(reason);
|
|
315
|
+
this.#settle('failed', this.#failure);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
#cancel(): void {
|
|
319
|
+
if (!this.#isOpen()) return;
|
|
320
|
+
const error = new RpcError('stream cancelled by consumer', code(GrpcStatusCode.CANCELLED));
|
|
321
|
+
error.methodName = this.#method.name;
|
|
322
|
+
error.serviceName = this.#method.service.typeName;
|
|
323
|
+
this.#settle('cancelled', error);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#settle(state: 'failed' | 'cancelled', error: RpcError): void {
|
|
327
|
+
this.#state = state;
|
|
328
|
+
this.#release();
|
|
329
|
+
this.#controller.abort(error);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Drops the body and any bytes buffered from it, so an ended call retains neither. */
|
|
333
|
+
#release(): void {
|
|
334
|
+
this.#userSignal?.removeEventListener('abort', this.#onUserAbort);
|
|
335
|
+
cancelQuietly(this.#reader);
|
|
336
|
+
this.#reader = undefined;
|
|
337
|
+
this.#decoder = undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
#toError(reason: unknown): RpcError {
|
|
341
|
+
let error: RpcError;
|
|
342
|
+
if (reason instanceof RpcError && reason !== this.#controller.signal.reason) error = reason;
|
|
343
|
+
else if (this.#controller.signal.aborted) {
|
|
344
|
+
// Coded from the caller's abort reason by `normalizeError`.
|
|
345
|
+
error = abortRpcError(reason);
|
|
346
|
+
} else {
|
|
347
|
+
// A request that can't be serialized or a response that can't be decoded fails every attempt.
|
|
348
|
+
error = markNonRetryable(
|
|
349
|
+
new RpcError(
|
|
350
|
+
reason instanceof Error ? reason.message : String(reason),
|
|
351
|
+
code(GrpcStatusCode.INTERNAL),
|
|
352
|
+
),
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
error.methodName = this.#method.name;
|
|
356
|
+
error.serviceName = this.#method.service.typeName;
|
|
357
|
+
this.#normalizeError(error, this.#userSignal);
|
|
358
|
+
return error;
|
|
359
|
+
}
|
|
360
|
+
}
|
package/src/grpc/index.ts
CHANGED
|
@@ -22,6 +22,11 @@ export type {
|
|
|
22
22
|
SuiGrpcClientOptions,
|
|
23
23
|
} from './client.js';
|
|
24
24
|
export type { GrpcCoreClientOptions } from './core.js';
|
|
25
|
+
export type {
|
|
26
|
+
GrpcStreamCheckpointsOptions,
|
|
27
|
+
GrpcStreamEventsOptions,
|
|
28
|
+
GrpcStreamTransactionsOptions,
|
|
29
|
+
} from './stream-types.js';
|
|
25
30
|
|
|
26
31
|
// Subclasses `@protobuf-ts/grpcweb-transport`'s transport to fix its error handling.
|
|
27
32
|
export { GrpcWebFetchTransport } from './transport.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { RpcError } from '@protobuf-ts/runtime-rpc';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Codes a network failure of a gRPC-web fetch or body read (a `TypeError`, as fetch reports it)
|
|
8
|
+
* as `UNAVAILABLE` instead of upstream's `INTERNAL`. Other errors, and failures after `signal`
|
|
9
|
+
* aborts, are returned unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export function toNetworkRpcError(error: unknown, signal: AbortSignal | null | undefined): unknown {
|
|
12
|
+
if (signal?.aborted || !(error instanceof TypeError)) return error;
|
|
13
|
+
return new RpcError(error.message, 'UNAVAILABLE');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Errors whose message is already plain text, so it is not percent-decoded again. */
|
|
17
|
+
export const plainMessageErrors = new WeakSet<RpcError>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The error for a call the caller aborted. Its message is the caller's own text, which was never
|
|
21
|
+
* percent-encoded on the wire. The code is applied from the reason later.
|
|
22
|
+
*/
|
|
23
|
+
export function abortRpcError(reason: unknown): RpcError {
|
|
24
|
+
const error =
|
|
25
|
+
reason instanceof RpcError ? reason : new RpcError(abortMessage(reason), 'CANCELLED');
|
|
26
|
+
plainMessageErrors.add(error);
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function abortMessage(reason: unknown): string {
|
|
31
|
+
if (typeof reason === 'string') return reason;
|
|
32
|
+
return reason instanceof Error ? reason.message : 'The operation was aborted';
|
|
33
|
+
}
|