@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
package/src/client/mvr.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
parseStructTag,
|
|
12
12
|
} from '../utils/sui-types.js';
|
|
13
13
|
import type { ClientCache } from './cache.js';
|
|
14
|
+
import { httpStatusReason, SuiClientError } from './errors.js';
|
|
14
15
|
import type { TransactionDataBuilder } from '../transactions/TransactionData.js';
|
|
15
16
|
import { PACKAGE_VERSION } from '../version.js';
|
|
16
17
|
import type { SuiClientTypes } from './types.js';
|
|
@@ -30,6 +31,21 @@ export interface MvrClientOptions {
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/** An MVR request that failed or got an error response. */
|
|
35
|
+
export class MvrRequestError extends SuiClientError {
|
|
36
|
+
/** Why repeating the same request may succeed; undefined when it can't. */
|
|
37
|
+
readonly reason?: SuiClientTypes.RetryReason;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
message: string,
|
|
41
|
+
options: { reason?: SuiClientTypes.RetryReason; cause?: unknown } = {},
|
|
42
|
+
) {
|
|
43
|
+
super(message, { cause: options.cause });
|
|
44
|
+
this.name = 'MvrRequestError';
|
|
45
|
+
this.reason = options.reason;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
export class MvrClient implements SuiClientTypes.MvrMethods {
|
|
34
50
|
#cache: ClientCache;
|
|
35
51
|
#url?: string;
|
|
@@ -166,21 +182,32 @@ export class MvrClient implements SuiClientTypes.MvrMethods {
|
|
|
166
182
|
throw new Error('MVR Api URL is not set for the current client');
|
|
167
183
|
}
|
|
168
184
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
let response: Response;
|
|
186
|
+
try {
|
|
187
|
+
response = await fetch(`${this.#url}${url}`, {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
headers: {
|
|
190
|
+
'Content-Type': 'application/json',
|
|
191
|
+
...MVR_API_HEADER,
|
|
192
|
+
},
|
|
193
|
+
body: JSON.stringify(body),
|
|
194
|
+
});
|
|
195
|
+
} catch (cause) {
|
|
196
|
+
throw new MvrRequestError('MVR request failed', { cause, reason: 'Unavailable' });
|
|
197
|
+
}
|
|
177
198
|
|
|
178
199
|
if (!response.ok) {
|
|
179
200
|
const errorBody = await response.json().catch(() => ({}));
|
|
180
|
-
throw new
|
|
201
|
+
throw new MvrRequestError(`Failed to resolve types: ${errorBody?.message}`, {
|
|
202
|
+
reason: httpStatusReason(response.status),
|
|
203
|
+
});
|
|
181
204
|
}
|
|
182
205
|
|
|
183
|
-
|
|
206
|
+
try {
|
|
207
|
+
return await response.json();
|
|
208
|
+
} catch (cause) {
|
|
209
|
+
throw new MvrRequestError('MVR response could not be read', { cause, reason: 'Unavailable' });
|
|
210
|
+
}
|
|
184
211
|
}
|
|
185
212
|
|
|
186
213
|
async resolvePackage({
|
|
@@ -19,32 +19,22 @@ export interface ResolvedPagination {
|
|
|
19
19
|
const DEFAULT_PAGE_SIZE = 50;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Resolves pagination bounds and the traversal direction.
|
|
23
23
|
*
|
|
24
|
-
* `after` and `before` are exclusive ledger-position bounds
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* `after` and `before` are exclusive, order-independent ledger-position bounds
|
|
25
|
+
* that can be combined to read a window. Without an explicit `order`, queries
|
|
26
|
+
* bounded only by `before` read in descending order, and every other query
|
|
27
|
+
* reads in ascending order.
|
|
28
28
|
*/
|
|
29
29
|
export function resolvePagination(options: {
|
|
30
30
|
after?: string | null;
|
|
31
31
|
before?: string | null;
|
|
32
|
-
order?:
|
|
32
|
+
order?: SuiClientTypes.Order;
|
|
33
33
|
limit?: number;
|
|
34
34
|
}): ResolvedPagination {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const descending = options.order ? options.order === 'descending' : options.before != null;
|
|
40
|
-
|
|
41
|
-
if (options.after != null && descending) {
|
|
42
|
-
throw new Error('`after` can not be combined with descending queries');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (options.before != null && !descending) {
|
|
46
|
-
throw new Error('`before` can not be combined with ascending queries');
|
|
47
|
-
}
|
|
35
|
+
const descending = options.order
|
|
36
|
+
? options.order === 'descending'
|
|
37
|
+
: options.before != null && options.after == null;
|
|
48
38
|
|
|
49
39
|
return {
|
|
50
40
|
descending,
|
|
@@ -54,36 +44,77 @@ export function resolvePagination(options: {
|
|
|
54
44
|
};
|
|
55
45
|
}
|
|
56
46
|
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
export interface ResolvedCheckpointRange {
|
|
48
|
+
/** Inclusive lower checkpoint bound. */
|
|
49
|
+
start?: bigint;
|
|
50
|
+
/** Exclusive upper checkpoint bound. */
|
|
51
|
+
end?: bigint;
|
|
52
|
+
}
|
|
60
53
|
|
|
61
54
|
/**
|
|
62
|
-
* Validates
|
|
63
|
-
*
|
|
64
|
-
* Function filters can only be paginated when fully qualified, since JSON-RPC
|
|
65
|
-
* rejects cursors on package- or module-level `MoveFunction` filters.
|
|
55
|
+
* Validates `startCheckpoint`/`endCheckpoint` and converts them to bigints, so
|
|
56
|
+
* every transport rejects the same ranges.
|
|
66
57
|
*/
|
|
67
|
-
export function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
):
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
58
|
+
export function resolveCheckpointRange(options: {
|
|
59
|
+
startCheckpoint?: SuiClientTypes.CheckpointNumber;
|
|
60
|
+
endCheckpoint?: SuiClientTypes.CheckpointNumber;
|
|
61
|
+
}): ResolvedCheckpointRange {
|
|
62
|
+
const start =
|
|
63
|
+
options.startCheckpoint == null
|
|
64
|
+
? undefined
|
|
65
|
+
: parseCheckpointNumber(options.startCheckpoint, 'startCheckpoint');
|
|
66
|
+
const end =
|
|
67
|
+
options.endCheckpoint == null
|
|
68
|
+
? undefined
|
|
69
|
+
: parseCheckpointNumber(options.endCheckpoint, 'endCheckpoint');
|
|
70
|
+
|
|
71
|
+
if (start != null && end != null && end < start) {
|
|
72
|
+
throw new Error('`endCheckpoint` must be greater than or equal to `startCheckpoint`');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { start, end };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Validates a checkpoint sequence number and converts it to a bigint. Values
|
|
80
|
+
* are capped at `Number.MAX_SAFE_INTEGER` because GraphQL represents
|
|
81
|
+
* checkpoints as `UInt53`.
|
|
82
|
+
*/
|
|
83
|
+
export function parseCheckpointNumber(
|
|
84
|
+
value: SuiClientTypes.CheckpointNumber,
|
|
85
|
+
label: string,
|
|
86
|
+
): bigint {
|
|
87
|
+
const valid =
|
|
88
|
+
typeof value === 'bigint'
|
|
89
|
+
? value >= 0n && value <= BigInt(Number.MAX_SAFE_INTEGER)
|
|
90
|
+
: typeof value === 'number'
|
|
91
|
+
? Number.isSafeInteger(value) && value >= 0
|
|
92
|
+
: /^\d+$/.test(value) && BigInt(value) <= BigInt(Number.MAX_SAFE_INTEGER);
|
|
93
|
+
|
|
94
|
+
if (!valid) {
|
|
95
|
+
throw new Error(`Invalid ${label} "${value}": expected a non-negative integer`);
|
|
79
96
|
}
|
|
97
|
+
|
|
98
|
+
return BigInt(value);
|
|
80
99
|
}
|
|
81
100
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
/** A validated transaction filter with addresses normalized and MVR names resolved. */
|
|
102
|
+
export interface ResolvedTransactionFilter {
|
|
103
|
+
sender?: string;
|
|
104
|
+
affectedAddress?: string;
|
|
105
|
+
affectedObject?: string;
|
|
106
|
+
/** A normalized Move path: `0x…`, `0x…::module`, or `0x…::module::function`. */
|
|
107
|
+
function?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A validated event filter with addresses normalized and MVR names resolved. */
|
|
111
|
+
export interface ResolvedEventFilter {
|
|
112
|
+
sender?: string;
|
|
113
|
+
/** `0x…` or `0x…::module`. */
|
|
114
|
+
emitModule?: string;
|
|
115
|
+
/** `0x…`, `0x…::module`, or a fully qualified type name. */
|
|
116
|
+
eventType?: string;
|
|
117
|
+
}
|
|
87
118
|
|
|
88
119
|
/**
|
|
89
120
|
* Validates a transaction filter and resolves any MVR names it contains.
|
|
@@ -96,100 +127,123 @@ export async function resolveTransactionFilter(
|
|
|
96
127
|
filter: SuiClientTypes.TransactionFilter,
|
|
97
128
|
signal?: AbortSignal,
|
|
98
129
|
): Promise<ResolvedTransactionFilter> {
|
|
99
|
-
|
|
130
|
+
validateTransactionFilter(filter);
|
|
131
|
+
|
|
132
|
+
const resolved: ResolvedTransactionFilter = {};
|
|
100
133
|
|
|
101
134
|
if (filter.sender != null) {
|
|
102
|
-
|
|
135
|
+
resolved.sender = normalizeSuiAddress(filter.sender);
|
|
103
136
|
}
|
|
104
137
|
|
|
105
|
-
|
|
138
|
+
if (filter.affectedAddress != null) {
|
|
139
|
+
resolved.affectedAddress = normalizeSuiAddress(filter.affectedAddress);
|
|
140
|
+
}
|
|
106
141
|
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
`Invalid function filter "${filter.function}": expected "package", "package::module", or "package::module::function"`,
|
|
110
|
-
);
|
|
142
|
+
if (filter.affectedObject != null) {
|
|
143
|
+
resolved.affectedObject = normalizeSuiAddress(filter.affectedObject);
|
|
111
144
|
}
|
|
112
145
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
146
|
+
if (filter.function != null) {
|
|
147
|
+
resolved.function = await resolvePackagePath(mvr, filter.function, signal);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return resolved;
|
|
119
151
|
}
|
|
120
152
|
|
|
121
153
|
/**
|
|
122
154
|
* Validates an event filter and resolves any MVR names it contains.
|
|
123
155
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* resolves filters through this function so that validation errors and MVR
|
|
127
|
-
* handling are identical across clients.
|
|
156
|
+
* Every transport resolves filters through this function so that validation
|
|
157
|
+
* errors and MVR handling are identical across clients.
|
|
128
158
|
*/
|
|
129
159
|
export async function resolveEventFilter(
|
|
130
160
|
mvr: SuiClientTypes.MvrMethods,
|
|
131
161
|
filter: SuiClientTypes.EventFilter,
|
|
132
162
|
signal?: AbortSignal,
|
|
133
163
|
): Promise<ResolvedEventFilter> {
|
|
134
|
-
|
|
164
|
+
validateEventFilter(filter);
|
|
165
|
+
|
|
166
|
+
const resolved: ResolvedEventFilter = {};
|
|
135
167
|
|
|
136
168
|
if (filter.sender != null) {
|
|
137
|
-
|
|
169
|
+
resolved.sender = normalizeSuiAddress(filter.sender);
|
|
138
170
|
}
|
|
139
171
|
|
|
140
172
|
if (filter.emitModule != null) {
|
|
141
|
-
|
|
173
|
+
resolved.emitModule = await resolvePackagePath(mvr, filter.emitModule, signal);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (filter.eventType != null) {
|
|
177
|
+
const eventType = filter.eventType;
|
|
178
|
+
|
|
179
|
+
if (eventType.split('::').length <= 2) {
|
|
180
|
+
resolved.eventType = await resolvePackagePath(mvr, eventType, signal);
|
|
181
|
+
} else {
|
|
182
|
+
resolved.eventType = (await mvr.resolveType({ type: eventType, signal })).type;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return resolved;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Checks a transaction filter's shape without resolving MVR names, throwing a plain `Error`.
|
|
191
|
+
* Addresses are not checked, so a malformed one reaches the server.
|
|
192
|
+
*/
|
|
193
|
+
export function validateTransactionFilter(filter: SuiClientTypes.TransactionFilter) {
|
|
194
|
+
assertAtMostOne(filter, ['affectedAddress', 'affectedObject', 'function'], 'A transaction');
|
|
195
|
+
|
|
196
|
+
if (filter.function != null) {
|
|
197
|
+
const [pkg, module, fn, ...rest] = filter.function.split('::');
|
|
142
198
|
|
|
143
|
-
if (!pkg ||
|
|
199
|
+
if (!pkg || rest.length > 0 || module === '' || fn === '') {
|
|
144
200
|
throw new Error(
|
|
145
|
-
`Invalid
|
|
201
|
+
`Invalid function filter "${filter.function}": expected "package", "package::module", or "package::module::function"`,
|
|
146
202
|
);
|
|
147
203
|
}
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
$kind: 'emitModule',
|
|
151
|
-
package: normalizeSuiAddress((await mvr.resolvePackage({ package: pkg, signal })).package),
|
|
152
|
-
module,
|
|
153
|
-
};
|
|
154
204
|
}
|
|
205
|
+
}
|
|
155
206
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
/** Checks an event filter's shape like `validateTransactionFilter`. */
|
|
208
|
+
export function validateEventFilter(filter: SuiClientTypes.EventFilter) {
|
|
209
|
+
assertAtMostOne(filter, ['emitModule', 'eventType'], 'An event');
|
|
210
|
+
|
|
211
|
+
if (filter.emitModule != null) {
|
|
212
|
+
const segments = filter.emitModule.split('::');
|
|
213
|
+
|
|
214
|
+
if (segments.length > 2 || segments.some((segment) => segment === '')) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Invalid emitModule filter "${filter.emitModule}": expected "package" or "package::module"`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
167
219
|
}
|
|
168
220
|
|
|
169
|
-
if (
|
|
221
|
+
if (filter.eventType != null && filter.eventType.split('::').some((segment) => segment === '')) {
|
|
170
222
|
throw new Error(
|
|
171
|
-
`Invalid eventType filter "${eventType}": expected "package::module" or a fully qualified type name`,
|
|
223
|
+
`Invalid eventType filter "${filter.eventType}": expected "package", "package::module", or a fully qualified type name`,
|
|
172
224
|
);
|
|
173
225
|
}
|
|
226
|
+
}
|
|
174
227
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
228
|
+
/** Resolves the package segment of a `package[::module[::name]]` path, keeping the rest. */
|
|
229
|
+
async function resolvePackagePath(
|
|
230
|
+
mvr: SuiClientTypes.MvrMethods,
|
|
231
|
+
path: string,
|
|
232
|
+
signal?: AbortSignal,
|
|
233
|
+
): Promise<string> {
|
|
234
|
+
const [pkg, ...rest] = path.split('::');
|
|
235
|
+
const resolved = normalizeSuiAddress(
|
|
236
|
+
(await mvr.resolvePackage({ package: pkg, signal })).package,
|
|
237
|
+
);
|
|
238
|
+
return [resolved, ...rest].join('::');
|
|
179
239
|
}
|
|
180
240
|
|
|
181
|
-
function
|
|
182
|
-
filter: Record<string, unknown>,
|
|
183
|
-
predicates: string[],
|
|
184
|
-
kind: string,
|
|
185
|
-
): void {
|
|
241
|
+
function assertAtMostOne(filter: Record<string, unknown>, predicates: string[], subject: string) {
|
|
186
242
|
const present = predicates.filter((predicate) => filter[predicate] != null);
|
|
187
243
|
|
|
188
|
-
if (present.length
|
|
244
|
+
if (present.length > 1) {
|
|
189
245
|
throw new Error(
|
|
190
|
-
|
|
191
|
-
present.length ? ` (got ${present.join(', ')})` : ''
|
|
192
|
-
}`,
|
|
246
|
+
`${subject} filter may specify at most one of ${predicates.join(', ')} (got ${present.join(', ')})`,
|
|
193
247
|
);
|
|
194
248
|
}
|
|
195
249
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal contract between the ledger stream core and a transport. The core owns tokens,
|
|
6
|
+
* planning, paging, the live handoff, retries, deduplication and statuses so they match across
|
|
7
|
+
* transports. An adapter reads one page at a time, opens subscriptions, builds positions from what
|
|
8
|
+
* its server reports, and says which failures are worth retrying.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { SuiClientTypes } from '../types.js';
|
|
12
|
+
import type { StreamPosition } from './position.js';
|
|
13
|
+
|
|
14
|
+
export type StreamFamily = 'checkpoints' | 'transactions' | 'events';
|
|
15
|
+
|
|
16
|
+
/** Append-only: the transport tag is part of every token. */
|
|
17
|
+
export type StreamTransport = 'grpc' | 'graphql';
|
|
18
|
+
|
|
19
|
+
/** A checkpoint start (inclusive), or a position the stream continues after. */
|
|
20
|
+
export type Bound = { checkpoint: bigint } | { position: StreamPosition };
|
|
21
|
+
|
|
22
|
+
/** One page of a range: checkpoints `[range.start, range.end)`, after the start-side cursor. */
|
|
23
|
+
export interface PageRequest {
|
|
24
|
+
range: { start?: bigint; end?: bigint };
|
|
25
|
+
/** Ascending: continue after this cursor. */
|
|
26
|
+
after?: Uint8Array;
|
|
27
|
+
/** Descending: continue before this cursor. */
|
|
28
|
+
before?: Uint8Array;
|
|
29
|
+
order: SuiClientTypes.Order;
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** An item, or without one, a resume point the server reported mid-page. */
|
|
34
|
+
export interface PageItem<Item> {
|
|
35
|
+
position: StreamPosition;
|
|
36
|
+
item?: Item;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What a page reports once its items are read. */
|
|
40
|
+
export interface PageEnd {
|
|
41
|
+
/** `cursor` continues the scan; `position` is that point, where the server reports it. */
|
|
42
|
+
next: { more: boolean; cursor?: Uint8Array; position?: StreamPosition };
|
|
43
|
+
/** Ascending, on the last page: every match through this checkpoint has been read. */
|
|
44
|
+
covered?: bigint;
|
|
45
|
+
/** A descending read without a low end stopped at this oldest retained checkpoint. */
|
|
46
|
+
retainedFrom?: bigint;
|
|
47
|
+
/** The server has not indexed what this page needs yet; the pass waits and reads again. */
|
|
48
|
+
notIndexed?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A page's items and resume points in traversal order, as they arrive, then its end. */
|
|
52
|
+
export type Page<Item> = AsyncIterator<PageItem<Item>, PageEnd, undefined>;
|
|
53
|
+
|
|
54
|
+
export type LiveEvent<Item> =
|
|
55
|
+
| { $kind: 'Item'; position: StreamPosition; item: Item }
|
|
56
|
+
| { $kind: 'Progress'; position: StreamPosition };
|
|
57
|
+
|
|
58
|
+
export interface LiveSubscription<Item> extends AsyncIterable<LiveEvent<Item>> {
|
|
59
|
+
/** While enabled, events are buffered ahead of the consumer during a gap replay. */
|
|
60
|
+
readAhead?(enabled: boolean): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Stream item frames without the token, which the core adds. */
|
|
64
|
+
export type ItemFrame =
|
|
65
|
+
| SuiClientTypes.StreamCheckpoint<any>
|
|
66
|
+
| SuiClientTypes.StreamTransaction<any>
|
|
67
|
+
| SuiClientTypes.StreamEvent;
|
|
68
|
+
|
|
69
|
+
/** Everything the core can yield. */
|
|
70
|
+
export type CoreFrame<Frame> =
|
|
71
|
+
Frame | SuiClientTypes.StreamProgressFrame | SuiClientTypes.StreamCompletionFrame;
|
|
72
|
+
|
|
73
|
+
export interface LedgerStreamAdapter<Item, Frame extends { resumeToken: string } = ItemFrame> {
|
|
74
|
+
readonly transport: StreamTransport;
|
|
75
|
+
readonly family: StreamFamily;
|
|
76
|
+
/**
|
|
77
|
+
* `fromTip`: subscriptions start at the live tip, so the core pages history first and replays
|
|
78
|
+
* the gap up to the feed's first frame; every live position has a checkpoint.
|
|
79
|
+
* `resume`: `subscribe(from)` backfills after `from` on the server, then goes live.
|
|
80
|
+
*/
|
|
81
|
+
readonly live: 'fromTip' | 'resume';
|
|
82
|
+
/** `resume` only: whether `subscribe(from)` can backfill from `from`; if not, the core pages first. */
|
|
83
|
+
canResume?(from: Bound): boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Resolves names in the filter; the returned filter is hashed into every token. An adapter that
|
|
87
|
+
* reads the indexed tip with the chain identity returns it, and planning uses it.
|
|
88
|
+
*/
|
|
89
|
+
initialize(signal: AbortSignal): Promise<{ chain: string; filter: unknown; indexedTip?: bigint }>;
|
|
90
|
+
/** The highest checkpoint that pages can read. */
|
|
91
|
+
indexedTip(signal: AbortSignal): Promise<bigint>;
|
|
92
|
+
/** One request, opened on the first read. The core always reads or closes it. */
|
|
93
|
+
fetchPage(request: PageRequest): Page<Item>;
|
|
94
|
+
/**
|
|
95
|
+
* A live subscription (`from` is used only by `resume` adapters). An adapter whose feed can stay
|
|
96
|
+
* quiet after it opens calls `onOpen` then, for the `Connected` status.
|
|
97
|
+
*/
|
|
98
|
+
subscribe(
|
|
99
|
+
from: Bound | undefined,
|
|
100
|
+
signal: AbortSignal,
|
|
101
|
+
onOpen: () => void,
|
|
102
|
+
): LiveSubscription<Item>;
|
|
103
|
+
|
|
104
|
+
mapItem(item: Item): Omit<Frame, 'resumeToken'>;
|
|
105
|
+
/** Why retrying may get past `error`, or `undefined` when it cannot. */
|
|
106
|
+
retryReason(error: unknown): SuiClientTypes.RetryReason | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** An adapter whose item type is known only to itself. */
|
|
110
|
+
export type AnyLedgerStreamAdapter = LedgerStreamAdapter<any, any>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SuiClientError } from '../errors.js';
|
|
5
|
+
|
|
6
|
+
export type SuiStreamErrorCode =
|
|
7
|
+
/** An invalid option or bound. Never retried. */
|
|
8
|
+
| 'InvalidOptions'
|
|
9
|
+
/** Not a resume token, an unsupported version, or a non-canonical encoding. */
|
|
10
|
+
| 'InvalidToken'
|
|
11
|
+
/** A token from another transport, chain, family or filter, or a changed order. */
|
|
12
|
+
| 'IncompatibleToken'
|
|
13
|
+
/** The history the stream needs has been pruned by the server. */
|
|
14
|
+
| 'HistoryUnavailable'
|
|
15
|
+
/** The server broke a documented invariant. */
|
|
16
|
+
| 'Protocol'
|
|
17
|
+
/** The live feed kept ending without progress until the retry budget ran out. */
|
|
18
|
+
| 'Disconnected';
|
|
19
|
+
|
|
20
|
+
/** A ledger stream failure that is not a transport error. */
|
|
21
|
+
export class SuiStreamError extends SuiClientError {
|
|
22
|
+
readonly code: SuiStreamErrorCode;
|
|
23
|
+
|
|
24
|
+
constructor(code: SuiStreamErrorCode, message: string, options?: { cause?: unknown }) {
|
|
25
|
+
super(message, options);
|
|
26
|
+
this.name = 'SuiStreamError';
|
|
27
|
+
this.code = code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Internal: a live feed ended. Feeds never complete, so the core reconnects. Never escapes the
|
|
33
|
+
* stream: an exhausted budget throws `Disconnected` instead.
|
|
34
|
+
*/
|
|
35
|
+
export class StreamDisconnected extends Error {
|
|
36
|
+
constructor(message = 'Live feed ended') {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'StreamDisconnected';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { LedgerStreamRequest } from '../core.js';
|
|
5
|
+
import { validateEventFilter, validateTransactionFilter } from '../query-filters.js';
|
|
6
|
+
import { SuiStreamError } from './errors.js';
|
|
7
|
+
|
|
8
|
+
/** Rejects an invalid `filter` with `InvalidOptions` before any request, as the list methods do. */
|
|
9
|
+
export function validateStreamFilter(request: LedgerStreamRequest): void {
|
|
10
|
+
if (request.family === 'checkpoints' || !request.options.filter) return;
|
|
11
|
+
try {
|
|
12
|
+
if (request.family === 'transactions') validateTransactionFilter(request.options.filter);
|
|
13
|
+
else validateEventFilter(request.options.filter);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new SuiStreamError('InvalidOptions', (error as Error).message, { cause: error });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { linkedAbortController } from '../../utils/abort.js';
|
|
5
|
+
import type { CoreFrame, LedgerStreamAdapter } from './adapter.js';
|
|
6
|
+
import { SuiStreamError } from './errors.js';
|
|
7
|
+
import { boundaryPosition, insideCheckpoint } from './position.js';
|
|
8
|
+
import type { LiveFeed, StreamSession } from './session.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The live handoff, rerun on every reconnect. A `resume` adapter subscribes after the resume point
|
|
12
|
+
* and the server backfills from there. A `fromTip` adapter's subscription starts at the live tip,
|
|
13
|
+
* so the core pages history to the indexed tip first, then replays the gap up to the feed's first
|
|
14
|
+
* frame before delivering the feed. The pager and the feed never commit at the same time.
|
|
15
|
+
*/
|
|
16
|
+
export async function* followLive<Item, Frame extends { resumeToken: string }>(
|
|
17
|
+
session: StreamSession<Item, Frame>,
|
|
18
|
+
adapter: LedgerStreamAdapter<Item, Frame>,
|
|
19
|
+
): AsyncGenerator<CoreFrame<Frame>, never> {
|
|
20
|
+
const start = session.start;
|
|
21
|
+
const fromTip = adapter.live === 'fromTip';
|
|
22
|
+
if (start && (fromTip || adapter.canResume?.(start) === false)) yield* session.replay(undefined);
|
|
23
|
+
// A token exists before the first match.
|
|
24
|
+
if (!session.committed && start && 'checkpoint' in start) {
|
|
25
|
+
yield* session.baseline(boundaryPosition(start.checkpoint));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Closing must not wait for a quiet subscription's pending read: abort it first.
|
|
29
|
+
const attempt = linkedAbortController(session.signal);
|
|
30
|
+
let feed: LiveFeed<Item> | undefined;
|
|
31
|
+
try {
|
|
32
|
+
session.subscribing();
|
|
33
|
+
const subscription = adapter.subscribe(session.start, attempt.controller.signal, () =>
|
|
34
|
+
session.connected(),
|
|
35
|
+
);
|
|
36
|
+
feed = session.openFeed(subscription);
|
|
37
|
+
if (fromTip && start) {
|
|
38
|
+
const { position } = await feed.first();
|
|
39
|
+
const { checkpoint } = position;
|
|
40
|
+
if (checkpoint === null) {
|
|
41
|
+
throw new SuiStreamError('Protocol', 'Live frame is missing its checkpoint');
|
|
42
|
+
}
|
|
43
|
+
// The gap ends at the feed's first frame. Replaying through a frame inside a checkpoint
|
|
44
|
+
// overlaps the feed, and the session drops what it repeats.
|
|
45
|
+
const inside = adapter.family !== 'checkpoints' && insideCheckpoint(position);
|
|
46
|
+
const end = inside ? checkpoint + 1n : checkpoint;
|
|
47
|
+
const next = session.nextUncovered;
|
|
48
|
+
if (next === null || next < end) {
|
|
49
|
+
subscription.readAhead?.(true);
|
|
50
|
+
try {
|
|
51
|
+
yield* session.replay(end);
|
|
52
|
+
} finally {
|
|
53
|
+
subscription.readAhead?.(false);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return yield* session.deliver(feed);
|
|
58
|
+
} finally {
|
|
59
|
+
attempt.controller.abort();
|
|
60
|
+
attempt.dispose();
|
|
61
|
+
await feed?.close();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Internal barrel for transports. Only `SuiStreamError` is public (from `@mysten/sui/client`).
|
|
5
|
+
export type * from './adapter.js';
|
|
6
|
+
export { StreamDisconnected, SuiStreamError } from './errors.js';
|
|
7
|
+
export type { SuiStreamErrorCode } from './errors.js';
|
|
8
|
+
export { createLedgerStream } from './run.js';
|
|
9
|
+
export * from './position.js';
|