@mysten/sui 2.39.0 → 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 +162 -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 +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 +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/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.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.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 +14 -13
- 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 +3 -4
- 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/dist/client/core.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.mjs","names":["bcs"],"sources":["../../src/client/core.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { TypeTagSerializer } from '../bcs/type-tag-serializer.js';\nimport type { TransactionPlugin } from '../transactions/index.js';\nimport { deriveDynamicFieldID } from '../utils/dynamic-fields.js';\nimport { normalizeStructTag, parseStructTag, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';\nimport { BaseClient } from './client.js';\nimport type { ClientWithExtensions, SuiClientTypes } from './types.js';\nimport { MvrClient } from './mvr.js';\nimport { bcs } from '../bcs/index.js';\n\nexport type ClientWithCoreApi = ClientWithExtensions<{\n\tcore: CoreClient;\n}>;\n\nexport interface CoreClientOptions extends SuiClientTypes.SuiClientOptions {\n\tbase: BaseClient;\n\tmvr?: SuiClientTypes.MvrOptions;\n}\n\nconst DEFAULT_MVR_URLS: Record<string, string> = {\n\tmainnet: 'https://mainnet.mvr.mystenlabs.com',\n\ttestnet: 'https://testnet.mvr.mystenlabs.com',\n};\n\nexport abstract class CoreClient extends BaseClient implements SuiClientTypes.TransportMethods {\n\tcore = this;\n\tmvr: SuiClientTypes.MvrMethods;\n\n\tconstructor(options: CoreClientOptions) {\n\t\tsuper(options);\n\n\t\tthis.mvr = new MvrClient({\n\t\t\tcache: this.cache.scope('core.mvr'),\n\t\t\turl: options.mvr?.url ?? DEFAULT_MVR_URLS[this.network],\n\t\t\tpageSize: options.mvr?.pageSize,\n\t\t\toverrides: options.mvr?.overrides,\n\t\t});\n\t}\n\n\tabstract getObjects<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetObjectsOptions<Include>,\n\t): Promise<SuiClientTypes.GetObjectsResponse<Include>>;\n\n\tasync getObject<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetObjectOptions<Include>,\n\t): Promise<SuiClientTypes.GetObjectResponse<Include>> {\n\t\tconst { objectId } = options;\n\t\tconst {\n\t\t\tobjects: [result],\n\t\t} = await this.getObjects({\n\t\t\tobjectIds: [objectId],\n\t\t\tsignal: options.signal,\n\t\t\tinclude: options.include,\n\t\t});\n\t\tif (result instanceof Error) {\n\t\t\tthrow result;\n\t\t}\n\t\treturn { object: result };\n\t}\n\n\tabstract listCoins(\n\t\toptions: SuiClientTypes.ListCoinsOptions,\n\t): Promise<SuiClientTypes.ListCoinsResponse>;\n\n\tabstract listOwnedObjects<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.ListOwnedObjectsOptions<Include>,\n\t): Promise<SuiClientTypes.ListOwnedObjectsResponse<Include>>;\n\n\tabstract getBalance(\n\t\toptions: SuiClientTypes.GetBalanceOptions,\n\t): Promise<SuiClientTypes.GetBalanceResponse>;\n\n\tabstract listBalances(\n\t\toptions: SuiClientTypes.ListBalancesOptions,\n\t): Promise<SuiClientTypes.ListBalancesResponse>;\n\n\tabstract getCoinMetadata(\n\t\toptions: SuiClientTypes.GetCoinMetadataOptions,\n\t): Promise<SuiClientTypes.GetCoinMetadataResponse>;\n\n\tabstract getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.GetTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>>;\n\n\tabstract executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.ExecuteTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>>;\n\n\tabstract simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(\n\t\toptions: SuiClientTypes.SimulateTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.SimulateTransactionResult<Include>>;\n\n\tabstract getReferenceGasPrice(\n\t\toptions?: SuiClientTypes.GetReferenceGasPriceOptions,\n\t): Promise<SuiClientTypes.GetReferenceGasPriceResponse>;\n\n\tabstract getCurrentSystemState(\n\t\toptions?: SuiClientTypes.GetCurrentSystemStateOptions,\n\t): Promise<SuiClientTypes.GetCurrentSystemStateResponse>;\n\n\tabstract getProtocolConfig(\n\t\toptions?: SuiClientTypes.GetProtocolConfigOptions,\n\t): Promise<SuiClientTypes.GetProtocolConfigResponse>;\n\n\tabstract getChainIdentifier(\n\t\toptions?: SuiClientTypes.GetChainIdentifierOptions,\n\t): Promise<SuiClientTypes.GetChainIdentifierResponse>;\n\n\tabstract listDynamicFields(\n\t\toptions: SuiClientTypes.ListDynamicFieldsOptions,\n\t): Promise<SuiClientTypes.ListDynamicFieldsResponse>;\n\n\tabstract listTransactions<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.ListTransactionsOptions<Include>,\n\t): Promise<SuiClientTypes.ListTransactionsResponse<Include>>;\n\n\tabstract listEvents(\n\t\toptions: SuiClientTypes.ListEventsOptions,\n\t): Promise<SuiClientTypes.ListEventsResponse>;\n\n\tabstract resolveTransactionPlugin(): TransactionPlugin;\n\n\tabstract verifyZkLoginSignature(\n\t\toptions: SuiClientTypes.VerifyZkLoginSignatureOptions,\n\t): Promise<SuiClientTypes.ZkLoginVerifyResponse>;\n\n\tabstract getMoveFunction(\n\t\toptions: SuiClientTypes.GetMoveFunctionOptions,\n\t): Promise<SuiClientTypes.GetMoveFunctionResponse>;\n\n\tabstract defaultNameServiceName(\n\t\toptions: SuiClientTypes.DefaultNameServiceNameOptions,\n\t): Promise<SuiClientTypes.DefaultNameServiceNameResponse>;\n\n\tabstract resolveNameServiceAddress(\n\t\toptions: SuiClientTypes.ResolveNameServiceAddressOptions,\n\t): Promise<SuiClientTypes.ResolveNameServiceAddressResponse>;\n\n\tasync getDynamicField(\n\t\toptions: SuiClientTypes.GetDynamicFieldOptions,\n\t): Promise<SuiClientTypes.GetDynamicFieldResponse> {\n\t\tconst normalizedNameType = TypeTagSerializer.parseFromStr(\n\t\t\t(\n\t\t\t\tawait this.core.mvr.resolveType({\n\t\t\t\t\ttype: options.name.type,\n\t\t\t\t\tsignal: options.signal,\n\t\t\t\t})\n\t\t\t).type,\n\t\t);\n\t\tconst fieldId = deriveDynamicFieldID(options.parentId, normalizedNameType, options.name.bcs);\n\t\tconst {\n\t\t\tobjects: [fieldObject],\n\t\t} = await this.getObjects({\n\t\t\tobjectIds: [fieldId],\n\t\t\tsignal: options.signal,\n\t\t\tinclude: {\n\t\t\t\tpreviousTransaction: true,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t});\n\n\t\tif (fieldObject instanceof Error) {\n\t\t\tthrow fieldObject;\n\t\t}\n\n\t\tconst fieldType = parseStructTag(fieldObject.type);\n\t\tconst content = await fieldObject.content;\n\n\t\tconst nameTypeParam = fieldType.typeParams[0];\n\t\tconst isDynamicObject =\n\t\t\ttypeof nameTypeParam !== 'string' &&\n\t\t\tnameTypeParam.module === 'dynamic_object_field' &&\n\t\t\tnameTypeParam.name === 'Wrapper';\n\n\t\tconst valueBcs = content.slice(SUI_ADDRESS_LENGTH + options.name.bcs.length);\n\n\t\tconst valueType =\n\t\t\ttypeof fieldType.typeParams[1] === 'string'\n\t\t\t\t? fieldType.typeParams[1]\n\t\t\t\t: normalizeStructTag(fieldType.typeParams[1]);\n\n\t\treturn {\n\t\t\tdynamicField: {\n\t\t\t\t$kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',\n\t\t\t\tfieldId: fieldObject.objectId,\n\t\t\t\tdigest: fieldObject.digest,\n\t\t\t\tversion: fieldObject.version,\n\t\t\t\ttype: fieldObject.type,\n\t\t\t\tpreviousTransaction: fieldObject.previousTransaction,\n\t\t\t\tname: {\n\t\t\t\t\ttype:\n\t\t\t\t\t\ttypeof nameTypeParam === 'string' ? nameTypeParam : normalizeStructTag(nameTypeParam),\n\t\t\t\t\tbcs: options.name.bcs,\n\t\t\t\t},\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: valueType,\n\t\t\t\t\tbcs: valueBcs,\n\t\t\t\t},\n\t\t\t\tchildId: isDynamicObject ? bcs.Address.parse(valueBcs) : undefined,\n\t\t\t} as SuiClientTypes.GetDynamicFieldResponse['dynamicField'],\n\t\t};\n\t}\n\n\tasync getDynamicObjectField<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetDynamicObjectFieldOptions<Include>,\n\t): Promise<SuiClientTypes.GetDynamicObjectFieldResponse<Include>> {\n\t\tconst resolvedNameType = (\n\t\t\tawait this.core.mvr.resolveType({\n\t\t\t\ttype: options.name.type,\n\t\t\t\tsignal: options.signal,\n\t\t\t})\n\t\t).type;\n\t\tconst wrappedType = `0x2::dynamic_object_field::Wrapper<${resolvedNameType}>`;\n\n\t\tconst { dynamicField } = await this.getDynamicField({\n\t\t\tparentId: options.parentId,\n\t\t\tname: {\n\t\t\t\ttype: wrappedType,\n\t\t\t\tbcs: options.name.bcs,\n\t\t\t},\n\t\t\tsignal: options.signal,\n\t\t});\n\n\t\tconst { object } = await this.getObject({\n\t\t\tobjectId: dynamicField.childId!,\n\t\t\tsignal: options.signal,\n\t\t\tinclude: options.include,\n\t\t});\n\n\t\treturn { object };\n\t}\n\n\tasync waitForTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.WaitForTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>> {\n\t\tconst { signal, timeout = 60 * 1000, pollSchedule, include } = options;\n\n\t\tconst digest =\n\t\t\t'result' in options && options.result\n\t\t\t\t? (options.result.Transaction ?? options.result.FailedTransaction)!.digest\n\t\t\t\t: options.digest;\n\n\t\tconst abortSignal = signal\n\t\t\t? AbortSignal.any([AbortSignal.timeout(timeout), signal])\n\t\t\t: AbortSignal.timeout(timeout);\n\n\t\tconst abortPromise = new Promise((_, reject) => {\n\t\t\tabortSignal.addEventListener('abort', () => reject(abortSignal.reason));\n\t\t});\n\n\t\tabortPromise.catch(() => {\n\t\t\t// Swallow unhandled rejections that might be thrown after early return\n\t\t});\n\n\t\t// Default schedule tuned to testnet measurements:\n\t\t// - Fullnode (gRPC/JSON-RPC): p50=130ms, p95=330ms\n\t\t// - GraphQL indexer: p50=1300ms, p95=1430ms\n\t\t// After schedule exhausted, repeats the last interval.\n\t\tconst schedule = pollSchedule ?? [0, 300, 600, 1500, 3500];\n\t\tconst t0 = Date.now();\n\t\tlet scheduleIndex = 0;\n\t\tconst lastInterval =\n\t\t\tschedule.length > 0\n\t\t\t\t? schedule[schedule.length - 1] - (schedule[schedule.length - 2] ?? 0)\n\t\t\t\t: 2_000;\n\n\t\twhile (true) {\n\t\t\tif (scheduleIndex < schedule.length) {\n\t\t\t\tconst remaining = t0 + schedule[scheduleIndex] - Date.now();\n\t\t\t\tscheduleIndex++;\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tnew Promise((resolve) => setTimeout(resolve, remaining)),\n\t\t\t\t\t\tabortPromise,\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tnew Promise((resolve) => setTimeout(resolve, lastInterval)),\n\t\t\t\t\tabortPromise,\n\t\t\t\t]);\n\t\t\t}\n\n\t\t\tabortSignal.throwIfAborted();\n\t\t\ttry {\n\t\t\t\treturn await this.getTransaction({\n\t\t\t\t\tdigest,\n\t\t\t\t\tinclude,\n\t\t\t\t\tsignal: abortSignal,\n\t\t\t\t});\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\tasync signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsigner,\n\t\tadditionalSignatures = [],\n\t\t...input\n\t}: SuiClientTypes.SignAndExecuteTransactionOptions<Include>): Promise<\n\t\tSuiClientTypes.TransactionResult<Include>\n\t> {\n\t\tlet transactionBytes;\n\n\t\tif (transaction instanceof Uint8Array) {\n\t\t\ttransactionBytes = transaction;\n\t\t} else {\n\t\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\t\ttransactionBytes = await transaction.build({ client: this });\n\t\t}\n\n\t\tconst { signature } = await signer.signTransaction(transactionBytes);\n\n\t\treturn this.executeTransaction({\n\t\t\ttransaction: transactionBytes,\n\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t...input,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAqBA,MAAM,mBAA2C;CAChD,SAAS;CACT,SAAS;CACT;AAED,IAAsB,aAAtB,cAAyC,WAAsD;CAI9F,YAAY,SAA4B;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AAK,KAAK;EACrB,IAAI,gBAAgB;EACpB,MAAM,eACL,SAAS,SAAS,IACf,SAAS,SAAS,SAAS,MAAM,SAAS,SAAS,SAAS,MAAM,KAClE;AAEJ,SAAO,MAAM;AACZ,OAAI,gBAAgB,SAAS,QAAQ;IACpC,MAAM,YAAY,KAAK,SAAS,iBAAiB,KAAK,KAAK;AAC3D;AACA,QAAI,YAAY,EACf,OAAM,QAAQ,KAAK,CAClB,IAAI,SAAS,YAAY,WAAW,SAAS,UAAU,CAAC,EACxD,aACA,CAAC;SAGH,OAAM,QAAQ,KAAK,CAClB,IAAI,SAAS,YAAY,WAAW,SAAS,aAAa,CAAC,EAC3D,aACA,CAAC;AAGH,eAAY,gBAAgB;AAC5B,OAAI;AACH,WAAO,MAAM,KAAK,eAAe;KAChC;KACA;KACA,QAAQ;KACR,CAAC;WACK;;;CAIV,MAAM,0BAAkF,EACvF,aACA,QACA,uBAAuB,EAAE,EACzB,GAAG,SAGF;EACD,IAAI;AAEJ,MAAI,uBAAuB,WAC1B,oBAAmB;OACb;AACN,eAAY,kBAAkB,OAAO,cAAc,CAAC;AACpD,sBAAmB,MAAM,YAAY,MAAM,EAAE,QAAQ,MAAM,CAAC;;EAG7D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,iBAAiB;AAEpE,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,WAAW,GAAG,qBAAqB;GAChD,GAAG;GACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"core.mjs","names":["bcs","#ledgerStream"],"sources":["../../src/client/core.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/utils';\n\nimport { TypeTagSerializer } from '../bcs/type-tag-serializer.js';\nimport type { TransactionPlugin } from '../transactions/index.js';\nimport {\n\tDEFAULT_RESTRICTED_MOVE_CALLS,\n\tvalidateRestrictedMoveCalls,\n} from '../transactions/restricted-move-calls.js';\nimport { deriveObjectID } from '../utils/derived-objects.js';\nimport { deriveDynamicFieldID } from '../utils/dynamic-fields.js';\nimport {\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n\tSUI_ADDRESS_LENGTH,\n} from '../utils/sui-types.js';\nimport { BaseClient } from './client.js';\nimport type { ClientWithExtensions, SuiClientTypes } from './types.js';\nimport { MvrClient } from './mvr.js';\nimport { bcs } from '../bcs/index.js';\nimport type { AnyLedgerStreamAdapter } from './stream/adapter.js';\nimport { SuiStreamError } from './stream/errors.js';\nimport { validateStreamFilter } from './stream/filter.js';\nimport { createLedgerStream } from './stream/run.js';\nimport { ObjectError } from './errors.js';\n\n/** The shared `0x2::address_alias::AddressAliasState`, the parent of every alias set. */\nconst ADDRESS_ALIAS_STATE_ID = '0xa';\nconst ADDRESS_ALIAS_KEY_TYPE = '0x2::address_alias::AliasKey';\n\n/** `0x2::address_alias::AddressAliases`: its ID and a `VecSet<address>`. */\nconst AddressAliasesBcs = bcs.struct('AddressAliases', {\n\tid: bcs.Address,\n\taliases: bcs.struct('VecSet<address>', { contents: bcs.vector(bcs.Address) }),\n});\n\n/** What `CoreClient.createLedgerStreamAdapter` is asked to stream. */\nexport type LedgerStreamRequest =\n\t| {\n\t\t\tfamily: 'checkpoints';\n\t\t\toptions: SuiClientTypes.StreamCheckpointsOptions<\n\t\t\t\tSuiClientTypes.StreamCheckpointInclude,\n\t\t\t\tStreamFrames\n\t\t\t>;\n\t }\n\t| {\n\t\t\tfamily: 'transactions';\n\t\t\toptions: SuiClientTypes.StreamTransactionsOptions<\n\t\t\t\tSuiClientTypes.TransactionInclude,\n\t\t\t\tStreamFrames\n\t\t\t>;\n\t }\n\t| { family: 'events'; options: SuiClientTypes.StreamEventsOptions<StreamFrames> };\ntype StreamFrames = SuiClientTypes.StreamFrameOptions;\n\nexport type ClientWithCoreApi = ClientWithExtensions<{\n\tcore: CoreClient;\n}>;\n\nexport interface CoreClientOptions extends SuiClientTypes.SuiClientOptions {\n\tbase: BaseClient;\n\tmvr?: SuiClientTypes.MvrOptions;\n\trestrictedMoveCalls?: readonly string[];\n}\n\nconst DEFAULT_MVR_URLS: Record<string, string> = {\n\tmainnet: 'https://mainnet.mvr.mystenlabs.com',\n\ttestnet: 'https://testnet.mvr.mystenlabs.com',\n};\n\nexport abstract class CoreClient extends BaseClient implements SuiClientTypes.TransportMethods {\n\tcore = this;\n\tmvr: SuiClientTypes.MvrMethods;\n\treadonly restrictedMoveCalls: readonly string[];\n\n\tconstructor(options: CoreClientOptions) {\n\t\tsuper(options);\n\n\t\tthis.restrictedMoveCalls = Object.freeze([\n\t\t\t...(options.restrictedMoveCalls ?? DEFAULT_RESTRICTED_MOVE_CALLS),\n\t\t]);\n\t\t// Validate entries now rather than on the first build.\n\t\tvalidateRestrictedMoveCalls(this.restrictedMoveCalls);\n\n\t\tthis.mvr = new MvrClient({\n\t\t\tcache: this.cache.scope('core.mvr'),\n\t\t\turl: options.mvr?.url ?? DEFAULT_MVR_URLS[this.network],\n\t\t\tpageSize: options.mvr?.pageSize,\n\t\t\toverrides: options.mvr?.overrides,\n\t\t});\n\t}\n\n\tabstract getObjects<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetObjectsOptions<Include>,\n\t): Promise<SuiClientTypes.GetObjectsResponse<Include>>;\n\n\tasync getObject<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetObjectOptions<Include>,\n\t): Promise<SuiClientTypes.GetObjectResponse<Include>> {\n\t\tconst { objectId } = options;\n\t\tconst {\n\t\t\tobjects: [result],\n\t\t} = await this.getObjects({\n\t\t\tobjectIds: [objectId],\n\t\t\tsignal: options.signal,\n\t\t\tinclude: options.include,\n\t\t});\n\t\tif (result instanceof Error) {\n\t\t\tthrow result;\n\t\t}\n\t\treturn { object: result };\n\t}\n\n\tabstract listCoins(\n\t\toptions: SuiClientTypes.ListCoinsOptions,\n\t): Promise<SuiClientTypes.ListCoinsResponse>;\n\n\tabstract listOwnedObjects<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.ListOwnedObjectsOptions<Include>,\n\t): Promise<SuiClientTypes.ListOwnedObjectsResponse<Include>>;\n\n\tabstract getBalance(\n\t\toptions: SuiClientTypes.GetBalanceOptions,\n\t): Promise<SuiClientTypes.GetBalanceResponse>;\n\n\tabstract listBalances(\n\t\toptions: SuiClientTypes.ListBalancesOptions,\n\t): Promise<SuiClientTypes.ListBalancesResponse>;\n\n\tabstract getCoinMetadata(\n\t\toptions: SuiClientTypes.GetCoinMetadataOptions,\n\t): Promise<SuiClientTypes.GetCoinMetadataResponse>;\n\n\tabstract getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.GetTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>>;\n\n\tabstract executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.ExecuteTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>>;\n\n\tabstract simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(\n\t\toptions: SuiClientTypes.SimulateTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.SimulateTransactionResult<Include>>;\n\n\tabstract getReferenceGasPrice(\n\t\toptions?: SuiClientTypes.GetReferenceGasPriceOptions,\n\t): Promise<SuiClientTypes.GetReferenceGasPriceResponse>;\n\n\tabstract getCurrentSystemState(\n\t\toptions?: SuiClientTypes.GetCurrentSystemStateOptions,\n\t): Promise<SuiClientTypes.GetCurrentSystemStateResponse>;\n\n\tabstract getProtocolConfig(\n\t\toptions?: SuiClientTypes.GetProtocolConfigOptions,\n\t): Promise<SuiClientTypes.GetProtocolConfigResponse>;\n\n\tabstract getChainIdentifier(\n\t\toptions?: SuiClientTypes.GetChainIdentifierOptions,\n\t): Promise<SuiClientTypes.GetChainIdentifierResponse>;\n\n\tabstract listDynamicFields<Include extends SuiClientTypes.DynamicFieldInclude = {}>(\n\t\toptions: SuiClientTypes.ListDynamicFieldsOptions<Include>,\n\t): Promise<SuiClientTypes.ListDynamicFieldsResponse<Include>>;\n\n\tabstract listTransactions<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.ListTransactionsOptions<Include>,\n\t): Promise<SuiClientTypes.ListTransactionsResponse<Include>>;\n\n\tabstract listEvents(\n\t\toptions: SuiClientTypes.ListEventsOptions,\n\t): Promise<SuiClientTypes.ListEventsResponse>;\n\n\tabstract listCheckpoints(\n\t\toptions: SuiClientTypes.ListCheckpointsOptions,\n\t): Promise<SuiClientTypes.ListCheckpointsResponse>;\n\n\tabstract resolveTransactionPlugin(): TransactionPlugin;\n\n\t/**\n\t * Verifies a personal message or transaction signature on the node; see the top-level\n\t * `client.verifySignature`. `valid: false` means invalid, malformed or not authorized for\n\t * `address`; network and protocol errors throw.\n\t */\n\tabstract verifySignature(\n\t\toptions: SuiClientTypes.VerifySignatureOptions,\n\t): Promise<SuiClientTypes.VerifySignatureResponse>;\n\n\t/**\n\t * @deprecated Use `verifySignature`. This method accepts signatures from the address's aliases,\n\t * like `verifySignature` does by default.\n\t */\n\tasync verifyZkLoginSignature({\n\t\tbytes,\n\t\tintentScope,\n\t\t...options\n\t}: SuiClientTypes.VerifyZkLoginSignatureOptions): Promise<SuiClientTypes.ZkLoginVerifyResponse> {\n\t\tconst message = fromBase64(bytes);\n\t\tconst { valid, reason } = await this.verifySignature({\n\t\t\t...options,\n\t\t\t...(intentScope === 'TransactionData'\n\t\t\t\t? { transaction: message }\n\t\t\t\t: { personalMessage: message }),\n\t\t});\n\t\treturn { success: valid, errors: reason ? [reason] : [] };\n\t}\n\n\tabstract getMoveFunction(\n\t\toptions: SuiClientTypes.GetMoveFunctionOptions,\n\t): Promise<SuiClientTypes.GetMoveFunctionResponse>;\n\n\tabstract defaultNameServiceName(\n\t\toptions: SuiClientTypes.DefaultNameServiceNameOptions,\n\t): Promise<SuiClientTypes.DefaultNameServiceNameResponse>;\n\n\tabstract resolveNameServiceAddress(\n\t\toptions: SuiClientTypes.ResolveNameServiceAddressOptions,\n\t): Promise<SuiClientTypes.ResolveNameServiceAddressResponse>;\n\n\t/**\n\t * Streams checkpoints in ledger order, resumable from any delivered frame's `resumeToken`.\n\t * Follows new checkpoints by default; see `SuiClientTypes.StreamOptions`.\n\t */\n\tstreamCheckpoints<\n\t\tInclude extends SuiClientTypes.StreamCheckpointInclude = {},\n\t\tFrames extends SuiClientTypes.StreamFrameOptions = {},\n\t>(\n\t\toptions: SuiClientTypes.StreamCheckpointsOptions<Include, Frames> = {},\n\t): AsyncGenerator<SuiClientTypes.StreamCheckpointFrame<Include, Frames>> {\n\t\treturn this.#ledgerStream({ family: 'checkpoints', options });\n\t}\n\n\t/** Streams transactions matching `filter` in ledger order. See `streamCheckpoints`. */\n\tstreamTransactions<\n\t\tInclude extends SuiClientTypes.TransactionInclude = {},\n\t\tFrames extends SuiClientTypes.StreamFrameOptions = {},\n\t>(\n\t\toptions: SuiClientTypes.StreamTransactionsOptions<Include, Frames> = {},\n\t): AsyncGenerator<SuiClientTypes.StreamTransactionFrame<Include, Frames>> {\n\t\treturn this.#ledgerStream({ family: 'transactions', options });\n\t}\n\n\t/** Streams events matching `filter` in ledger order. See `streamCheckpoints`. */\n\tstreamEvents<Frames extends SuiClientTypes.StreamFrameOptions = {}>(\n\t\toptions: SuiClientTypes.StreamEventsOptions<Frames> = {},\n\t): AsyncGenerator<SuiClientTypes.StreamEventFrame<Frames>> {\n\t\treturn this.#ledgerStream({ family: 'events', options });\n\t}\n\n\t/**\n\t * Returns the transport's stream adapter. Called on the stream's first `next()`; must not do I/O.\n\t * The default throws, for transports without stream support.\n\t * @internal\n\t */\n\tprotected createLedgerStreamAdapter(_request: LedgerStreamRequest): AnyLedgerStreamAdapter {\n\t\tthrow new SuiStreamError(\n\t\t\t'InvalidOptions',\n\t\t\t`${this.constructor.name} does not support ledger streams`,\n\t\t);\n\t}\n\n\t#ledgerStream<Result>(request: LedgerStreamRequest): AsyncGenerator<Result> {\n\t\treturn createLedgerStream(request.options, () => {\n\t\t\tvalidateStreamFilter(request);\n\t\t\treturn this.createLedgerStreamAdapter(request);\n\t\t}) as AsyncGenerator<Result>;\n\t}\n\n\t/**\n\t * The current alias set of `address`: the addresses whose signatures are accepted for it. An\n\t * address that never enabled aliases has none on chain and is only its own alias.\n\t */\n\tasync getAddressAliases(\n\t\toptions: SuiClientTypes.GetAddressAliasesOptions,\n\t): Promise<SuiClientTypes.GetAddressAliasesResponse> {\n\t\tconst address = normalizeSuiAddress(options.address);\n\t\tconst objectId = deriveObjectID(\n\t\t\tADDRESS_ALIAS_STATE_ID,\n\t\t\tADDRESS_ALIAS_KEY_TYPE,\n\t\t\tbcs.Address.serialize(address).toBytes(),\n\t\t);\n\t\tconst {\n\t\t\tobjects: [object],\n\t\t} = await this.getObjects({\n\t\t\tobjectIds: [objectId],\n\t\t\tsignal: options.signal,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (object instanceof ObjectError && object.reason === 'notFound') {\n\t\t\treturn {\n\t\t\t\taddressAliases: { address, enabled: false, aliases: [address], objectId },\n\t\t\t};\n\t\t}\n\t\tif (object instanceof Error) {\n\t\t\tthrow object;\n\t\t}\n\n\t\treturn {\n\t\t\taddressAliases: {\n\t\t\t\taddress,\n\t\t\t\tenabled: true,\n\t\t\t\taliases: AddressAliasesBcs.parse(object.content).aliases.contents,\n\t\t\t\tobjectId,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync getDynamicField(\n\t\toptions: SuiClientTypes.GetDynamicFieldOptions,\n\t): Promise<SuiClientTypes.GetDynamicFieldResponse> {\n\t\tconst normalizedNameType = TypeTagSerializer.parseFromStr(\n\t\t\t(\n\t\t\t\tawait this.core.mvr.resolveType({\n\t\t\t\t\ttype: options.name.type,\n\t\t\t\t\tsignal: options.signal,\n\t\t\t\t})\n\t\t\t).type,\n\t\t);\n\t\tconst fieldId = deriveDynamicFieldID(options.parentId, normalizedNameType, options.name.bcs);\n\t\tconst {\n\t\t\tobjects: [fieldObject],\n\t\t} = await this.getObjects({\n\t\t\tobjectIds: [fieldId],\n\t\t\tsignal: options.signal,\n\t\t\tinclude: {\n\t\t\t\tpreviousTransaction: true,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t});\n\n\t\tif (fieldObject instanceof Error) {\n\t\t\tthrow fieldObject;\n\t\t}\n\n\t\tconst fieldType = parseStructTag(fieldObject.type);\n\t\tconst content = await fieldObject.content;\n\n\t\tconst nameTypeParam = fieldType.typeParams[0];\n\t\tconst isDynamicObject =\n\t\t\ttypeof nameTypeParam !== 'string' &&\n\t\t\tnameTypeParam.module === 'dynamic_object_field' &&\n\t\t\tnameTypeParam.name === 'Wrapper';\n\n\t\tconst valueBcs = content.slice(SUI_ADDRESS_LENGTH + options.name.bcs.length);\n\n\t\tconst valueType =\n\t\t\ttypeof fieldType.typeParams[1] === 'string'\n\t\t\t\t? fieldType.typeParams[1]\n\t\t\t\t: normalizeStructTag(fieldType.typeParams[1]);\n\n\t\treturn {\n\t\t\tdynamicField: {\n\t\t\t\t$kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',\n\t\t\t\tfieldId: fieldObject.objectId,\n\t\t\t\tdigest: fieldObject.digest,\n\t\t\t\tversion: fieldObject.version,\n\t\t\t\ttype: fieldObject.type,\n\t\t\t\tpreviousTransaction: fieldObject.previousTransaction,\n\t\t\t\tname: {\n\t\t\t\t\ttype:\n\t\t\t\t\t\ttypeof nameTypeParam === 'string' ? nameTypeParam : normalizeStructTag(nameTypeParam),\n\t\t\t\t\tbcs: options.name.bcs,\n\t\t\t\t},\n\t\t\t\tvalueType,\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: valueType,\n\t\t\t\t\tbcs: valueBcs,\n\t\t\t\t},\n\t\t\t\tchildId: isDynamicObject ? bcs.Address.parse(valueBcs) : undefined,\n\t\t\t} as SuiClientTypes.GetDynamicFieldResponse['dynamicField'],\n\t\t};\n\t}\n\n\tasync getDynamicObjectField<Include extends SuiClientTypes.ObjectInclude = {}>(\n\t\toptions: SuiClientTypes.GetDynamicObjectFieldOptions<Include>,\n\t): Promise<SuiClientTypes.GetDynamicObjectFieldResponse<Include>> {\n\t\tconst resolvedNameType = (\n\t\t\tawait this.core.mvr.resolveType({\n\t\t\t\ttype: options.name.type,\n\t\t\t\tsignal: options.signal,\n\t\t\t})\n\t\t).type;\n\t\tconst wrappedType = `0x2::dynamic_object_field::Wrapper<${resolvedNameType}>`;\n\n\t\tconst { dynamicField } = await this.getDynamicField({\n\t\t\tparentId: options.parentId,\n\t\t\tname: {\n\t\t\t\ttype: wrappedType,\n\t\t\t\tbcs: options.name.bcs,\n\t\t\t},\n\t\t\tsignal: options.signal,\n\t\t});\n\n\t\tconst { object } = await this.getObject({\n\t\t\tobjectId: dynamicField.childId!,\n\t\t\tsignal: options.signal,\n\t\t\tinclude: options.include,\n\t\t});\n\n\t\treturn { object };\n\t}\n\n\tasync waitForTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\toptions: SuiClientTypes.WaitForTransactionOptions<Include>,\n\t): Promise<SuiClientTypes.TransactionResult<Include>> {\n\t\tconst { signal, timeout = 60 * 1000, pollSchedule, include } = options;\n\n\t\tconst digest =\n\t\t\t'result' in options && options.result\n\t\t\t\t? (options.result.Transaction ?? options.result.FailedTransaction)!.digest\n\t\t\t\t: options.digest;\n\n\t\tconst abortSignal = signal\n\t\t\t? AbortSignal.any([AbortSignal.timeout(timeout), signal])\n\t\t\t: AbortSignal.timeout(timeout);\n\n\t\tconst abortPromise = new Promise((_, reject) => {\n\t\t\tabortSignal.addEventListener('abort', () => reject(abortSignal.reason));\n\t\t});\n\n\t\tabortPromise.catch(() => {\n\t\t\t// Swallow unhandled rejections that might be thrown after early return\n\t\t});\n\n\t\t// Default schedule tuned to testnet measurements:\n\t\t// - Fullnode (gRPC): p50=130ms, p95=330ms\n\t\t// - GraphQL indexer: p50=1300ms, p95=1430ms\n\t\t// After schedule exhausted, repeats the last interval.\n\t\tconst schedule = pollSchedule ?? [0, 300, 600, 1500, 3500];\n\t\tconst t0 = Date.now();\n\t\tlet scheduleIndex = 0;\n\t\tconst lastInterval =\n\t\t\tschedule.length > 0\n\t\t\t\t? schedule[schedule.length - 1] - (schedule[schedule.length - 2] ?? 0)\n\t\t\t\t: 2_000;\n\n\t\twhile (true) {\n\t\t\tif (scheduleIndex < schedule.length) {\n\t\t\t\tconst remaining = t0 + schedule[scheduleIndex] - Date.now();\n\t\t\t\tscheduleIndex++;\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tnew Promise((resolve) => setTimeout(resolve, remaining)),\n\t\t\t\t\t\tabortPromise,\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tnew Promise((resolve) => setTimeout(resolve, lastInterval)),\n\t\t\t\t\tabortPromise,\n\t\t\t\t]);\n\t\t\t}\n\n\t\t\tabortSignal.throwIfAborted();\n\t\t\ttry {\n\t\t\t\treturn await this.getTransaction({\n\t\t\t\t\tdigest,\n\t\t\t\t\tinclude,\n\t\t\t\t\tsignal: abortSignal,\n\t\t\t\t});\n\t\t\t} catch {}\n\t\t}\n\t}\n\n\tasync signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsigner,\n\t\tadditionalSignatures = [],\n\t\t...input\n\t}: SuiClientTypes.SignAndExecuteTransactionOptions<Include>): Promise<\n\t\tSuiClientTypes.TransactionResult<Include>\n\t> {\n\t\tlet transactionBytes;\n\n\t\tif (transaction instanceof Uint8Array) {\n\t\t\ttransactionBytes = transaction;\n\t\t} else {\n\t\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\t\ttransactionBytes = await transaction.build({ client: this });\n\t\t}\n\n\t\tconst { signature } = await signer.signTransaction(transactionBytes);\n\n\t\treturn this.executeTransaction({\n\t\t\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ACzB,GAAG,SAGF;EACD,IAAI;AAEJ,MAAI,uBAAuB,WAC1B,oBAAmB;OACb;AACN,eAAY,kBAAkB,OAAO,cAAc,CAAC;AACpD,sBAAmB,MAAM,YAAY,MAAM,EAAE,QAAQ,MAAM,CAAC;;EAG7D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,iBAAiB;AAEpE,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,WAAW,GAAG,qBAAqB;GAChD,GAAG;GACH,CAAC"}
|
package/dist/client/errors.mjs
CHANGED
|
@@ -24,7 +24,17 @@ var TransactionError = class extends SuiClientError {
|
|
|
24
24
|
this.digest = digest;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* The retry reason for an HTTP error status: 429 is `RateLimited`, 503 is `Unavailable`, 408 and
|
|
29
|
+
* other 5xx except 501 are `ServerError`, and anything else is not retryable.
|
|
30
|
+
*/
|
|
31
|
+
function httpStatusReason(status) {
|
|
32
|
+
if (status === 429) return "RateLimited";
|
|
33
|
+
if (status === 503) return "Unavailable";
|
|
34
|
+
if (status === 501) return void 0;
|
|
35
|
+
if (status === 408 || status >= 500) return "ServerError";
|
|
36
|
+
}
|
|
27
37
|
|
|
28
38
|
//#endregion
|
|
29
|
-
export { ObjectError, SimulationError, SuiClientError, TransactionError };
|
|
39
|
+
export { ObjectError, SimulationError, SuiClientError, TransactionError, httpStatusReason };
|
|
30
40
|
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClientTypes } from './types.js';\n\nexport class SuiClientError extends Error {}\n\nexport class SimulationError extends SuiClientError {\n\texecutionError?: SuiClientTypes.ExecutionError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions?: { cause?: unknown; executionError?: SuiClientTypes.ExecutionError },\n\t) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.executionError = options?.executionError;\n\t}\n}\n\nexport type ObjectErrorReason = 'notFound' | 'deleted' | 'unknown';\n\nexport interface ObjectErrorOptions {\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treason: ObjectErrorReason;\n\t/** The requested object ID, when the lookup identifies one. */\n\tobjectId?: string;\n\t/** The original transport error or response. */\n\tcause?: unknown;\n}\n\n/** An error returned for an individual object lookup. */\nexport class ObjectError extends SuiClientError {\n\t/** The transport's error code. Use `reason` for transport-neutral handling. */\n\tcode: string;\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treadonly reason: ObjectErrorReason;\n\t/** The requested object ID, when the lookup identifies one. */\n\treadonly objectId?: string;\n\n\tconstructor(code: string, message: string, options?: ObjectErrorOptions) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.code = code;\n\t\tthis.reason = options?.reason ?? 'unknown';\n\t\tthis.objectId = options?.objectId;\n\t}\n}\n\nexport type TransactionErrorReason = 'notFound';\n\nconst TRANSACTION_ERROR_MESSAGES: Record<TransactionErrorReason, (digest: string) => string> = {\n\tnotFound: (digest) => `Transaction ${digest} not found`,\n};\n\n/** An error returned by a transaction lookup. */\nexport class TransactionError extends SuiClientError {\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treadonly reason: TransactionErrorReason;\n\t/** The requested transaction digest. */\n\treadonly digest: string;\n\n\tconstructor(reason: TransactionErrorReason, digest: string, options?: { cause?: unknown }) {\n\t\tsuper(TRANSACTION_ERROR_MESSAGES[reason](digest), options);\n\t\tthis.reason = reason;\n\t\tthis.digest = digest;\n\t}\n}\n"],"mappings":";AAKA,IAAa,iBAAb,cAAoC,MAAM;AAE1C,IAAa,kBAAb,cAAqC,eAAe;CAGnD,YACC,SACA,SACC;AACD,QAAM,SAAS,EAAE,OAAO,SAAS,OAAO,CAAC;AACzC,OAAK,iBAAiB,SAAS;;;;AAgBjC,IAAa,cAAb,cAAiC,eAAe;CAQ/C,YAAY,MAAc,SAAiB,SAA8B;AACxE,QAAM,SAAS,EAAE,OAAO,SAAS,OAAO,CAAC;AACzC,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,WAAW,SAAS;;;AAM3B,MAAM,6BAAyF,EAC9F,WAAW,WAAW,eAAe,OAAO,aAC5C;;AAGD,IAAa,mBAAb,cAAsC,eAAe;CAMpD,YAAY,QAAgC,QAAgB,SAA+B;AAC1F,QAAM,2BAA2B,QAAQ,OAAO,EAAE,QAAQ;AAC1D,OAAK,SAAS;AACd,OAAK,SAAS"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClientTypes } from './types.js';\n\nexport class SuiClientError extends Error {}\n\nexport class SimulationError extends SuiClientError {\n\texecutionError?: SuiClientTypes.ExecutionError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions?: { cause?: unknown; executionError?: SuiClientTypes.ExecutionError },\n\t) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.executionError = options?.executionError;\n\t}\n}\n\nexport type ObjectErrorReason = 'notFound' | 'deleted' | 'unknown';\n\nexport interface ObjectErrorOptions {\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treason: ObjectErrorReason;\n\t/** The requested object ID, when the lookup identifies one. */\n\tobjectId?: string;\n\t/** The original transport error or response. */\n\tcause?: unknown;\n}\n\n/** An error returned for an individual object lookup. */\nexport class ObjectError extends SuiClientError {\n\t/** The transport's error code. Use `reason` for transport-neutral handling. */\n\tcode: string;\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treadonly reason: ObjectErrorReason;\n\t/** The requested object ID, when the lookup identifies one. */\n\treadonly objectId?: string;\n\n\tconstructor(code: string, message: string, options?: ObjectErrorOptions) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.code = code;\n\t\tthis.reason = options?.reason ?? 'unknown';\n\t\tthis.objectId = options?.objectId;\n\t}\n}\n\nexport type TransactionErrorReason = 'notFound';\n\nconst TRANSACTION_ERROR_MESSAGES: Record<TransactionErrorReason, (digest: string) => string> = {\n\tnotFound: (digest) => `Transaction ${digest} not found`,\n};\n\n/** An error returned by a transaction lookup. */\nexport class TransactionError extends SuiClientError {\n\t/** A transport-neutral reason shared by all Core API clients. */\n\treadonly reason: TransactionErrorReason;\n\t/** The requested transaction digest. */\n\treadonly digest: string;\n\n\tconstructor(reason: TransactionErrorReason, digest: string, options?: { cause?: unknown }) {\n\t\tsuper(TRANSACTION_ERROR_MESSAGES[reason](digest), options);\n\t\tthis.reason = reason;\n\t\tthis.digest = digest;\n\t}\n}\n\n/**\n * The retry reason for an HTTP error status: 429 is `RateLimited`, 503 is `Unavailable`, 408 and\n * other 5xx except 501 are `ServerError`, and anything else is not retryable.\n */\nexport function httpStatusReason(status: number): SuiClientTypes.RetryReason | undefined {\n\tif (status === 429) return 'RateLimited';\n\tif (status === 503) return 'Unavailable';\n\tif (status === 501) return undefined;\n\tif (status === 408 || status >= 500) return 'ServerError';\n\treturn undefined;\n}\n"],"mappings":";AAKA,IAAa,iBAAb,cAAoC,MAAM;AAE1C,IAAa,kBAAb,cAAqC,eAAe;CAGnD,YACC,SACA,SACC;AACD,QAAM,SAAS,EAAE,OAAO,SAAS,OAAO,CAAC;AACzC,OAAK,iBAAiB,SAAS;;;;AAgBjC,IAAa,cAAb,cAAiC,eAAe;CAQ/C,YAAY,MAAc,SAAiB,SAA8B;AACxE,QAAM,SAAS,EAAE,OAAO,SAAS,OAAO,CAAC;AACzC,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,WAAW,SAAS;;;AAM3B,MAAM,6BAAyF,EAC9F,WAAW,WAAW,eAAe,OAAO,aAC5C;;AAGD,IAAa,mBAAb,cAAsC,eAAe;CAMpD,YAAY,QAAgC,QAAgB,SAA+B;AAC1F,QAAM,2BAA2B,QAAQ,OAAO,EAAE,QAAQ;AAC1D,OAAK,SAAS;AACd,OAAK,SAAS;;;;;;;AAQhB,SAAgB,iBAAiB,QAAwD;AACxF,KAAI,WAAW,IAAK,QAAO;AAC3B,KAAI,WAAW,IAAK,QAAO;AAC3B,KAAI,WAAW,IAAK,QAAO;AAC3B,KAAI,WAAW,OAAO,UAAU,IAAK,QAAO"}
|
package/dist/client/index.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ import { ClientWithExtensions, SuiClientRegistration, SuiClientTypes } from "./t
|
|
|
3
3
|
import { ClientWithCoreApi, CoreClient, CoreClientOptions } from "./core.mjs";
|
|
4
4
|
import { BaseClient } from "./client.mjs";
|
|
5
5
|
import { extractStatusFromEffectsBcs, formatMoveAbortMessage, parseTransactionBcs, parseTransactionEffectsBcs } from "./utils.mjs";
|
|
6
|
+
import { parseTransactionDataBcs } from "./transaction-data.mjs";
|
|
6
7
|
import { ObjectError, ObjectErrorOptions, ObjectErrorReason, SimulationError, SuiClientError, TransactionError, TransactionErrorReason } from "./errors.mjs";
|
|
7
|
-
import {
|
|
8
|
-
|
|
8
|
+
import { SuiStreamError, SuiStreamErrorCode } from "./stream/errors.mjs";
|
|
9
|
+
import { MvrRequestError, NamedPackagesOverrides } from "./mvr.mjs";
|
|
10
|
+
export { BaseClient, ClientCache, type ClientCacheOptions, type ClientWithCoreApi, type ClientWithExtensions, CoreClient, type CoreClientOptions, MvrRequestError, type NamedPackagesOverrides, ObjectError, type ObjectErrorOptions, type ObjectErrorReason, SimulationError, SuiClientError, type SuiClientRegistration, type SuiClientTypes, SuiStreamError, type SuiStreamErrorCode, TransactionError, type TransactionErrorReason, extractStatusFromEffectsBcs, formatMoveAbortMessage, parseTransactionBcs, parseTransactionDataBcs, parseTransactionEffectsBcs };
|
package/dist/client/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ClientCache } from "./cache.mjs";
|
|
2
2
|
import { BaseClient } from "./client.mjs";
|
|
3
|
+
import { ObjectError, SimulationError, SuiClientError, TransactionError } from "./errors.mjs";
|
|
4
|
+
import { MvrRequestError } from "./mvr.mjs";
|
|
5
|
+
import { SuiStreamError } from "./stream/errors.mjs";
|
|
3
6
|
import { CoreClient } from "./core.mjs";
|
|
4
7
|
import { extractStatusFromEffectsBcs, formatMoveAbortMessage, parseTransactionBcs, parseTransactionEffectsBcs } from "./utils.mjs";
|
|
5
|
-
import {
|
|
8
|
+
import { parseTransactionDataBcs } from "./transaction-data.mjs";
|
|
6
9
|
|
|
7
|
-
export { BaseClient, ClientCache, CoreClient, ObjectError, SimulationError, SuiClientError, TransactionError, extractStatusFromEffectsBcs, formatMoveAbortMessage, parseTransactionBcs, parseTransactionEffectsBcs };
|
|
10
|
+
export { BaseClient, ClientCache, CoreClient, MvrRequestError, ObjectError, SimulationError, SuiClientError, SuiStreamError, TransactionError, extractStatusFromEffectsBcs, formatMoveAbortMessage, parseTransactionBcs, parseTransactionDataBcs, parseTransactionEffectsBcs };
|
package/dist/client/mvr.d.mts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import "./types.mjs";
|
|
2
1
|
import "../transactions/TransactionData.mjs";
|
|
2
|
+
import { SuiClientTypes } from "./types.mjs";
|
|
3
|
+
import { SuiClientError } from "./errors.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/client/mvr.d.ts
|
|
6
|
+
/** An MVR request that failed or got an error response. */
|
|
7
|
+
declare class MvrRequestError extends SuiClientError {
|
|
8
|
+
/** Why repeating the same request may succeed; undefined when it can't. */
|
|
9
|
+
readonly reason?: SuiClientTypes.RetryReason;
|
|
10
|
+
constructor(message: string, options?: {
|
|
11
|
+
reason?: SuiClientTypes.RetryReason;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
5
15
|
type NamedPackagesOverrides = {
|
|
6
16
|
packages: Record<string, string>;
|
|
7
17
|
types: Record<string, string>;
|
|
8
18
|
};
|
|
9
19
|
//#endregion
|
|
10
|
-
export { NamedPackagesOverrides };
|
|
20
|
+
export { MvrRequestError, NamedPackagesOverrides };
|
|
11
21
|
//# sourceMappingURL=mvr.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvr.d.mts","names":[],"sources":["../../src/client/mvr.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mvr.d.mts","names":[],"sources":["../../src/client/mvr.ts"],"mappings":";;;;;;cAkCa,eAAA,SAAwB,cAAA;EAEH;EAAA,SAAxB,MAAA,GAAS,cAAA,CAAe,WAAA;cAGhC,OAAA,UACA,OAAA;IAAW,MAAA,GAAS,cAAA,CAAe,WAAA;IAAa,KAAA;EAAA;AAAA;AAAA,KAgatC,sBAAA;EACX,QAAA,EAAU,MAAA;EACV,KAAA,EAAO,MAAA;AAAA"}
|
package/dist/client/mvr.mjs
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { isValidNamedPackage } from "../utils/named-packages.mjs";
|
|
2
2
|
import { isValidSuiAddress, normalizeStructTag, normalizeSuiAddress, parseStructTag } from "../utils/sui-types.mjs";
|
|
3
3
|
import { isValidNamedType } from "../utils/move-registry.mjs";
|
|
4
|
+
import { SuiClientError, httpStatusReason } from "./errors.mjs";
|
|
4
5
|
import { PACKAGE_VERSION } from "../version.mjs";
|
|
5
6
|
import { DataLoader, chunk } from "@mysten/utils";
|
|
6
7
|
|
|
7
8
|
//#region src/client/mvr.ts
|
|
8
9
|
const NAME_SEPARATOR = "/";
|
|
9
10
|
const MVR_API_HEADER = { "Mvr-Source": `@mysten/sui@${PACKAGE_VERSION}` };
|
|
11
|
+
/** An MVR request that failed or got an error response. */
|
|
12
|
+
var MvrRequestError = class extends SuiClientError {
|
|
13
|
+
constructor(message, options = {}) {
|
|
14
|
+
super(message, { cause: options.cause });
|
|
15
|
+
this.name = "MvrRequestError";
|
|
16
|
+
this.reason = options.reason;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
10
19
|
var MvrClient = class {
|
|
11
20
|
#cache;
|
|
12
21
|
#url;
|
|
@@ -78,19 +87,31 @@ var MvrClient = class {
|
|
|
78
87
|
}
|
|
79
88
|
async #fetch(url, body) {
|
|
80
89
|
if (!this.#url) throw new Error("MVR Api URL is not set for the current client");
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
let response;
|
|
91
|
+
try {
|
|
92
|
+
response = await fetch(`${this.#url}${url}`, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
...MVR_API_HEADER
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify(body)
|
|
99
|
+
});
|
|
100
|
+
} catch (cause) {
|
|
101
|
+
throw new MvrRequestError("MVR request failed", {
|
|
102
|
+
cause,
|
|
103
|
+
reason: "Unavailable"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (!response.ok) throw new MvrRequestError(`Failed to resolve types: ${(await response.json().catch(() => ({})))?.message}`, { reason: httpStatusReason(response.status) });
|
|
107
|
+
try {
|
|
108
|
+
return await response.json();
|
|
109
|
+
} catch (cause) {
|
|
110
|
+
throw new MvrRequestError("MVR response could not be read", {
|
|
111
|
+
cause,
|
|
112
|
+
reason: "Unavailable"
|
|
113
|
+
});
|
|
92
114
|
}
|
|
93
|
-
return response.json();
|
|
94
115
|
}
|
|
95
116
|
async resolvePackage({ package: name, signal }) {
|
|
96
117
|
signal?.throwIfAborted();
|
|
@@ -273,5 +294,5 @@ function getNamesFromTypeList(types) {
|
|
|
273
294
|
}
|
|
274
295
|
|
|
275
296
|
//#endregion
|
|
276
|
-
export { MvrClient, findNamesInTransaction, hasMvrName, raceSignal, replaceNames };
|
|
297
|
+
export { MvrClient, MvrRequestError, findNamesInTransaction, hasMvrName, raceSignal, replaceNames };
|
|
277
298
|
//# sourceMappingURL=mvr.mjs.map
|
package/dist/client/mvr.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvr.mjs","names":["#cache","#url","#pageSize","#overrides","#mvrPackageDataLoader","#resolvePackages","#mvrTypeDataLoader","#resolveTypes","#fetch"],"sources":["../../src/client/mvr.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { chunk, DataLoader } from '@mysten/utils';\nimport { isValidNamedPackage, isValidNamedType } from '../utils/move-registry.js';\nimport type { StructTag } from '../utils/sui-types.js';\nimport {\n\tisValidSuiAddress,\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n} from '../utils/sui-types.js';\nimport type { ClientCache } from './cache.js';\nimport type { TransactionDataBuilder } from '../transactions/TransactionData.js';\nimport { PACKAGE_VERSION } from '../version.js';\nimport type { SuiClientTypes } from './types.js';\n\nconst NAME_SEPARATOR = '/';\nconst MVR_API_HEADER = {\n\t'Mvr-Source': `@mysten/sui@${PACKAGE_VERSION}`,\n};\n\nexport interface MvrClientOptions {\n\tcache: ClientCache;\n\turl?: string;\n\tpageSize?: number;\n\toverrides?: {\n\t\tpackages?: Record<string, string>;\n\t\ttypes?: Record<string, string>;\n\t};\n}\n\nexport class MvrClient implements SuiClientTypes.MvrMethods {\n\t#cache: ClientCache;\n\t#url?: string;\n\t#pageSize: number;\n\t#overrides: {\n\t\tpackages?: Record<string, string>;\n\t\ttypes?: Record<string, string>;\n\t};\n\n\tconstructor({ cache, url, pageSize = 50, overrides }: MvrClientOptions) {\n\t\tthis.#cache = cache;\n\t\tthis.#url = url;\n\t\tthis.#pageSize = pageSize;\n\t\tthis.#overrides = {\n\t\t\tpackages: overrides?.packages,\n\t\t\ttypes: overrides?.types,\n\t\t};\n\n\t\tvalidateOverrides(this.#overrides);\n\t}\n\n\tget #mvrPackageDataLoader() {\n\t\treturn this.#cache.readSync(['#mvrPackageDataLoader', this.#url ?? ''], () => {\n\t\t\tconst loader = new DataLoader<string, string>(async (packages) => {\n\t\t\t\tif (!this.#url) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`MVR Api URL is not set for the current client (resolving ${packages.join(', ')})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst resolved = await this.#resolvePackages(packages);\n\n\t\t\t\treturn packages.map(\n\t\t\t\t\t(pkg) => resolved[pkg] ?? new Error(`Failed to resolve package: ${pkg}`),\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst overrides = this.#overrides?.packages;\n\n\t\t\tif (overrides) {\n\t\t\t\tfor (const [pkg, id] of Object.entries(overrides)) {\n\t\t\t\t\tloader.prime(pkg, id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn loader;\n\t\t});\n\t}\n\n\tget #mvrTypeDataLoader() {\n\t\treturn this.#cache.readSync(['#mvrTypeDataLoader', this.#url ?? ''], () => {\n\t\t\tconst loader = new DataLoader<string, string>(async (types) => {\n\t\t\t\tif (!this.#url) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`MVR Api URL is not set for the current client (resolving ${types.join(', ')})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst resolved = await this.#resolveTypes(types);\n\n\t\t\t\treturn types.map((type) => resolved[type] ?? new Error(`Failed to resolve type: ${type}`));\n\t\t\t});\n\n\t\t\tconst overrides = this.#overrides?.types;\n\n\t\t\tif (overrides) {\n\t\t\t\tfor (const [type, id] of Object.entries(overrides)) {\n\t\t\t\t\tloader.prime(type, id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn loader;\n\t\t});\n\t}\n\n\tasync #resolvePackages(packages: readonly string[]) {\n\t\tif (packages.length === 0) return {};\n\n\t\tconst batches = chunk(packages, this.#pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst data = await this.#fetch<{ resolution: Record<string, { package_id: string }> }>(\n\t\t\t\t\t'/v1/resolution/bulk',\n\t\t\t\t\t{\n\t\t\t\t\t\tnames: batch,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const pkg of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst pkgData = data.resolution[pkg]?.package_id;\n\n\t\t\t\t\tif (!pkgData) continue;\n\n\t\t\t\t\tresults[pkg] = pkgData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n\n\tasync #resolveTypes(types: readonly string[]) {\n\t\tif (types.length === 0) return {};\n\n\t\tconst batches = chunk(types, this.#pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst data = await this.#fetch<{ resolution: Record<string, { type_tag: string }> }>(\n\t\t\t\t\t'/v1/struct-definition/bulk',\n\t\t\t\t\t{\n\t\t\t\t\t\ttypes: batch,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const type of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst typeData = data.resolution[type]?.type_tag;\n\t\t\t\t\tif (!typeData) continue;\n\n\t\t\t\t\tresults[type] = typeData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n\n\tasync #fetch<T>(url: string, body: Record<string, unknown>): Promise<T> {\n\t\tif (!this.#url) {\n\t\t\tthrow new Error('MVR Api URL is not set for the current client');\n\t\t}\n\n\t\tconst response = await fetch(`${this.#url}${url}`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t...MVR_API_HEADER,\n\t\t\t},\n\t\t\tbody: JSON.stringify(body),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\tthrow new Error(`Failed to resolve types: ${errorBody?.message}`);\n\t\t}\n\n\t\treturn response.json();\n\t}\n\n\tasync resolvePackage({\n\t\tpackage: name,\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolvePackageOptions): Promise<SuiClientTypes.MvrResolvePackageResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tif (!hasMvrName(name)) {\n\t\t\treturn {\n\t\t\t\tpackage: name,\n\t\t\t};\n\t\t}\n\t\tconst resolved = await raceSignal(this.#mvrPackageDataLoader.load(name), signal);\n\t\treturn {\n\t\t\tpackage: resolved,\n\t\t};\n\t}\n\n\tasync resolveType({\n\t\ttype,\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolveTypeOptions): Promise<SuiClientTypes.MvrResolveTypeResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tif (!hasMvrName(type)) {\n\t\t\treturn {\n\t\t\t\ttype,\n\t\t\t};\n\t\t}\n\n\t\tconst mvrTypes = [...extractMvrTypes(type)];\n\t\tconst resolvedTypes = await raceSignal(this.#mvrTypeDataLoader.loadMany(mvrTypes), signal);\n\n\t\tconst typeMap: Record<string, string> = {};\n\n\t\tfor (let i = 0; i < mvrTypes.length; i++) {\n\t\t\tconst resolvedType = resolvedTypes[i];\n\t\t\tif (resolvedType instanceof Error) {\n\t\t\t\tthrow resolvedType;\n\t\t\t}\n\t\t\ttypeMap[mvrTypes[i]] = resolvedType;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: replaceMvrNames(type, typeMap),\n\t\t};\n\t}\n\n\tasync resolve({\n\t\ttypes = [],\n\t\tpackages = [],\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolveOptions): Promise<SuiClientTypes.MvrResolveResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tconst mvrTypes = new Set<string>();\n\n\t\tfor (const type of types ?? []) {\n\t\t\textractMvrTypes(type, mvrTypes);\n\t\t}\n\n\t\tconst typesArray = [...mvrTypes];\n\t\tconst [resolvedTypes, resolvedPackages] = await raceSignal(\n\t\t\tPromise.all([\n\t\t\t\ttypesArray.length > 0 ? this.#mvrTypeDataLoader.loadMany(typesArray) : [],\n\t\t\t\tpackages.length > 0 ? this.#mvrPackageDataLoader.loadMany(packages) : [],\n\t\t\t]),\n\t\t\tsignal,\n\t\t);\n\n\t\tconst typeMap: Record<string, string> = {\n\t\t\t...this.#overrides?.types,\n\t\t};\n\n\t\tfor (const [i, type] of typesArray.entries()) {\n\t\t\tconst resolvedType = resolvedTypes[i];\n\t\t\tif (resolvedType instanceof Error) {\n\t\t\t\tthrow resolvedType;\n\t\t\t}\n\t\t\ttypeMap[type] = resolvedType;\n\t\t}\n\n\t\tconst replacedTypes: Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\ttype: string;\n\t\t\t}\n\t\t> = {};\n\n\t\tfor (const type of types ?? []) {\n\t\t\tconst resolvedType = replaceMvrNames(type, typeMap);\n\n\t\t\treplacedTypes[type] = {\n\t\t\t\ttype: resolvedType,\n\t\t\t};\n\t\t}\n\n\t\tconst replacedPackages: Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tpackage: string;\n\t\t\t}\n\t\t> = {};\n\n\t\tfor (const [i, pkg] of (packages ?? []).entries()) {\n\t\t\tconst resolvedPkg = this.#overrides?.packages?.[pkg] ?? resolvedPackages[i];\n\n\t\t\tif (resolvedPkg instanceof Error) {\n\t\t\t\tthrow resolvedPkg;\n\t\t\t}\n\n\t\t\treplacedPackages[pkg] = {\n\t\t\t\tpackage: resolvedPkg,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\ttypes: replacedTypes,\n\t\t\tpackages: replacedPackages,\n\t\t};\n\t}\n}\n\nfunction validateOverrides(overrides?: {\n\tpackages?: Record<string, string>;\n\ttypes?: Record<string, string>;\n}) {\n\tif (overrides?.packages) {\n\t\tfor (const [pkg, id] of Object.entries(overrides.packages)) {\n\t\t\tif (!isValidNamedPackage(pkg)) {\n\t\t\t\tthrow new Error(`Invalid package name: ${pkg}`);\n\t\t\t}\n\t\t\tif (!isValidSuiAddress(normalizeSuiAddress(id))) {\n\t\t\t\tthrow new Error(`Invalid package ID: ${id}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (overrides?.types) {\n\t\tfor (const [type, val] of Object.entries(overrides.types)) {\n\t\t\t// validate that types are first-level only.\n\t\t\tif (parseStructTag(type).typeParams.length > 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Type overrides must be first-level only. If you want to supply generic types, just pass each type individually.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst parsedValue = parseStructTag(val);\n\n\t\t\tif (!isValidSuiAddress(parsedValue.address)) {\n\t\t\t\tthrow new Error(`Invalid type: ${val}`);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Extracts all named types from a given type.\n */\nexport function extractMvrTypes(type: string | StructTag, types = new Set<string>()) {\n\tif (typeof type === 'string' && !hasMvrName(type)) return types;\n\n\tif (typeof type === 'string' && type.startsWith('vector<') && type.endsWith('>')) {\n\t\treturn extractMvrTypes(type.slice(7, -1), types);\n\t}\n\n\tconst tag = isStructTag(type) ? type : parseStructTag(type);\n\n\tif (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);\n\n\tfor (const param of tag.typeParams) {\n\t\textractMvrTypes(param, types);\n\t}\n\n\treturn types;\n}\n\n/**\n * Traverses a type, and replaces any found names with their resolved equivalents,\n * based on the supplied type cache.\n */\nfunction replaceMvrNames(tag: string | StructTag, typeCache: Record<string, string>): string {\n\tif (typeof tag === 'string' && !tag.includes('::')) {\n\t\treturn tag;\n\t}\n\n\tif (typeof tag === 'string' && tag.startsWith('vector<') && tag.endsWith('>')) {\n\t\treturn `vector<${replaceMvrNames(tag.slice(7, -1), typeCache)}>`;\n\t}\n\n\tconst type = isStructTag(tag) ? tag : parseStructTag(tag);\n\n\tconst typeTag = `${type.address}::${type.module}::${type.name}`;\n\tconst cacheHit = typeCache[typeTag];\n\n\treturn normalizeStructTag({\n\t\t...type,\n\t\taddress: cacheHit ? cacheHit.split('::')[0] : type.address,\n\t\ttypeParams: type.typeParams.map((param) => replaceMvrNames(param, typeCache)),\n\t});\n}\n\nexport function hasMvrName(nameOrType: string) {\n\treturn (\n\t\tnameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')\n\t);\n}\n\n/**\n * Races a promise against an optional AbortSignal. MVR resolution batches lookups\n * from independent callers into a single request via a shared DataLoader, so a\n * caller's signal cannot cancel the shared network request without affecting other\n * callers. Instead, this rejects the awaiting caller as soon as its signal aborts\n * (the underlying request continues in the background).\n *\n * The same isolation applies to any shared/cached request (e.g. `cache.read`).\n */\nexport function raceSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T> {\n\tif (!signal) {\n\t\treturn promise;\n\t}\n\n\t// An `abort` event is not replayed for listeners added after the fact, so a signal that was\n\t// already aborted would otherwise resolve normally.\n\tif (signal.aborted) {\n\t\treturn Promise.reject(signal.reason);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = () => reject(signal.reason);\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\n\t\tpromise.then(resolve, reject).finally(() => {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t});\n\t});\n}\n\nfunction isStructTag(type: string | StructTag): type is StructTag {\n\treturn (\n\t\ttypeof type === 'object' &&\n\t\t'address' in type &&\n\t\t'module' in type &&\n\t\t'name' in type &&\n\t\t'typeParams' in type\n\t);\n}\n\nexport type NamedPackagesOverrides = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tswitch (command.$kind) {\n\t\t\tcase 'MakeMoveVec':\n\t\t\t\tif (command.MakeMoveVec.type) {\n\t\t\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\t\t\ttypes.add(type);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'MoveCall':\n\t\t\t\tconst moveCall = command.MoveCall;\n\n\t\t\t\tconst pkg = moveCall.package.split('::')[0];\n\t\t\t\tif (hasMvrName(pkg)) {\n\t\t\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\t\t\tpackages.add(pkg);\n\t\t\t\t}\n\n\t\t\t\tgetNamesFromTypeList(moveCall.typeArguments ?? []).forEach((type) => {\n\t\t\t\t\ttypes.add(type);\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport function replaceNames(\n\tbuilder: TransactionDataBuilder,\n\tresolved: SuiClientTypes.MvrResolveResponse,\n) {\n\tfor (const command of builder.commands) {\n\t\t// Replacements for `MakeMoveVec` commands (that can include types)\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tif (!hasMvrName(command.MakeMoveVec.type)) continue;\n\t\t\tif (!resolved.types[command.MakeMoveVec.type])\n\t\t\t\tthrow new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);\n\t\t\tcommand.MakeMoveVec.type = resolved.types[command.MakeMoveVec.type].type;\n\t\t}\n\t\t// Replacements for `MoveCall` commands (that can include packages & types)\n\t\tconst tx = command.MoveCall;\n\t\tif (!tx) continue;\n\n\t\tconst nameParts = tx.package.split('::');\n\t\tconst name = nameParts[0];\n\n\t\tif (hasMvrName(name) && !resolved.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\t// Replace package name with address.\n\t\tif (hasMvrName(name)) {\n\t\t\tnameParts[0] = resolved.packages[name].package;\n\t\t\ttx.package = nameParts.join('::');\n\t\t}\n\n\t\tconst types = tx.typeArguments;\n\t\tif (!types) continue;\n\n\t\tfor (let i = 0; i < types.length; i++) {\n\t\t\tif (!hasMvrName(types[i])) continue;\n\n\t\t\tif (!resolved.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);\n\t\t\ttypes[i] = resolved.types[types[i]].type;\n\t\t}\n\n\t\ttx.typeArguments = types;\n\t}\n}\n\n/**\n * Returns a list of unique types that include a name\n * from the given list. This list is retrieved from the Transaction Data.\n */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (hasMvrName(type)) {\n\t\t\tif (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);\n\t\t\tnames.add(type);\n\t\t}\n\t}\n\treturn names;\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAAiB;AACvB,MAAM,iBAAiB,EACtB,cAAc,eAAe,mBAC7B;AAYD,IAAa,YAAb,MAA4D;CAC3D;CACA;CACA;CACA;CAKA,YAAY,EAAE,OAAO,KAAK,WAAW,IAAI,aAA+B;AACvE,QAAKA,QAAS;AACd,QAAKC,MAAO;AACZ,QAAKC,WAAY;AACjB,QAAKC,YAAa;GACjB,UAAU,WAAW;GACrB,OAAO,WAAW;GAClB;AAED,oBAAkB,MAAKA,UAAW;;CAGnC,KAAIC,uBAAwB;AAC3B,SAAO,MAAKJ,MAAO,SAAS,CAAC,yBAAyB,MAAKC,OAAQ,GAAG,QAAQ;GAC7E,MAAM,SAAS,IAAI,WAA2B,OAAO,aAAa;AACjE,QAAI,CAAC,MAAKA,IACT,OAAM,IAAI,MACT,4DAA4D,SAAS,KAAK,KAAK,CAAC,GAChF;IAEF,MAAM,WAAW,MAAM,MAAKI,gBAAiB,SAAS;AAEtD,WAAO,SAAS,KACd,QAAQ,SAAS,wBAAQ,IAAI,MAAM,8BAA8B,MAAM,CACxE;KACA;GACF,MAAM,YAAY,MAAKF,WAAY;AAEnC,O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,WAAW,KAAK,EAAE;AACrB,MAAI,CAAC,iBAAiB,KAAK,CAAE,OAAM,IAAI,MAAM,4BAA4B,OAAO;AAChF,QAAM,IAAI,KAAK;;AAGjB,QAAO"}
|
|
1
|
+
{"version":3,"file":"mvr.mjs","names":["#cache","#url","#pageSize","#overrides","#mvrPackageDataLoader","#resolvePackages","#mvrTypeDataLoader","#resolveTypes","#fetch"],"sources":["../../src/client/mvr.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { chunk, DataLoader } from '@mysten/utils';\nimport { isValidNamedPackage, isValidNamedType } from '../utils/move-registry.js';\nimport type { StructTag } from '../utils/sui-types.js';\nimport {\n\tisValidSuiAddress,\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n} from '../utils/sui-types.js';\nimport type { ClientCache } from './cache.js';\nimport { httpStatusReason, SuiClientError } from './errors.js';\nimport type { TransactionDataBuilder } from '../transactions/TransactionData.js';\nimport { PACKAGE_VERSION } from '../version.js';\nimport type { SuiClientTypes } from './types.js';\n\nconst NAME_SEPARATOR = '/';\nconst MVR_API_HEADER = {\n\t'Mvr-Source': `@mysten/sui@${PACKAGE_VERSION}`,\n};\n\nexport interface MvrClientOptions {\n\tcache: ClientCache;\n\turl?: string;\n\tpageSize?: number;\n\toverrides?: {\n\t\tpackages?: Record<string, string>;\n\t\ttypes?: Record<string, string>;\n\t};\n}\n\n/** An MVR request that failed or got an error response. */\nexport class MvrRequestError extends SuiClientError {\n\t/** Why repeating the same request may succeed; undefined when it can't. */\n\treadonly reason?: SuiClientTypes.RetryReason;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { reason?: SuiClientTypes.RetryReason; cause?: unknown } = {},\n\t) {\n\t\tsuper(message, { cause: options.cause });\n\t\tthis.name = 'MvrRequestError';\n\t\tthis.reason = options.reason;\n\t}\n}\n\nexport class MvrClient implements SuiClientTypes.MvrMethods {\n\t#cache: ClientCache;\n\t#url?: string;\n\t#pageSize: number;\n\t#overrides: {\n\t\tpackages?: Record<string, string>;\n\t\ttypes?: Record<string, string>;\n\t};\n\n\tconstructor({ cache, url, pageSize = 50, overrides }: MvrClientOptions) {\n\t\tthis.#cache = cache;\n\t\tthis.#url = url;\n\t\tthis.#pageSize = pageSize;\n\t\tthis.#overrides = {\n\t\t\tpackages: overrides?.packages,\n\t\t\ttypes: overrides?.types,\n\t\t};\n\n\t\tvalidateOverrides(this.#overrides);\n\t}\n\n\tget #mvrPackageDataLoader() {\n\t\treturn this.#cache.readSync(['#mvrPackageDataLoader', this.#url ?? ''], () => {\n\t\t\tconst loader = new DataLoader<string, string>(async (packages) => {\n\t\t\t\tif (!this.#url) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`MVR Api URL is not set for the current client (resolving ${packages.join(', ')})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst resolved = await this.#resolvePackages(packages);\n\n\t\t\t\treturn packages.map(\n\t\t\t\t\t(pkg) => resolved[pkg] ?? new Error(`Failed to resolve package: ${pkg}`),\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst overrides = this.#overrides?.packages;\n\n\t\t\tif (overrides) {\n\t\t\t\tfor (const [pkg, id] of Object.entries(overrides)) {\n\t\t\t\t\tloader.prime(pkg, id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn loader;\n\t\t});\n\t}\n\n\tget #mvrTypeDataLoader() {\n\t\treturn this.#cache.readSync(['#mvrTypeDataLoader', this.#url ?? ''], () => {\n\t\t\tconst loader = new DataLoader<string, string>(async (types) => {\n\t\t\t\tif (!this.#url) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`MVR Api URL is not set for the current client (resolving ${types.join(', ')})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst resolved = await this.#resolveTypes(types);\n\n\t\t\t\treturn types.map((type) => resolved[type] ?? new Error(`Failed to resolve type: ${type}`));\n\t\t\t});\n\n\t\t\tconst overrides = this.#overrides?.types;\n\n\t\t\tif (overrides) {\n\t\t\t\tfor (const [type, id] of Object.entries(overrides)) {\n\t\t\t\t\tloader.prime(type, id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn loader;\n\t\t});\n\t}\n\n\tasync #resolvePackages(packages: readonly string[]) {\n\t\tif (packages.length === 0) return {};\n\n\t\tconst batches = chunk(packages, this.#pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst data = await this.#fetch<{ resolution: Record<string, { package_id: string }> }>(\n\t\t\t\t\t'/v1/resolution/bulk',\n\t\t\t\t\t{\n\t\t\t\t\t\tnames: batch,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const pkg of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst pkgData = data.resolution[pkg]?.package_id;\n\n\t\t\t\t\tif (!pkgData) continue;\n\n\t\t\t\t\tresults[pkg] = pkgData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n\n\tasync #resolveTypes(types: readonly string[]) {\n\t\tif (types.length === 0) return {};\n\n\t\tconst batches = chunk(types, this.#pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst data = await this.#fetch<{ resolution: Record<string, { type_tag: string }> }>(\n\t\t\t\t\t'/v1/struct-definition/bulk',\n\t\t\t\t\t{\n\t\t\t\t\t\ttypes: batch,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const type of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst typeData = data.resolution[type]?.type_tag;\n\t\t\t\t\tif (!typeData) continue;\n\n\t\t\t\t\tresults[type] = typeData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n\n\tasync #fetch<T>(url: string, body: Record<string, unknown>): Promise<T> {\n\t\tif (!this.#url) {\n\t\t\tthrow new Error('MVR Api URL is not set for the current client');\n\t\t}\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${this.#url}${url}`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t...MVR_API_HEADER,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\tthrow new MvrRequestError('MVR request failed', { cause, reason: 'Unavailable' });\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\tthrow new MvrRequestError(`Failed to resolve types: ${errorBody?.message}`, {\n\t\t\t\treason: httpStatusReason(response.status),\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\treturn await response.json();\n\t\t} catch (cause) {\n\t\t\tthrow new MvrRequestError('MVR response could not be read', { cause, reason: 'Unavailable' });\n\t\t}\n\t}\n\n\tasync resolvePackage({\n\t\tpackage: name,\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolvePackageOptions): Promise<SuiClientTypes.MvrResolvePackageResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tif (!hasMvrName(name)) {\n\t\t\treturn {\n\t\t\t\tpackage: name,\n\t\t\t};\n\t\t}\n\t\tconst resolved = await raceSignal(this.#mvrPackageDataLoader.load(name), signal);\n\t\treturn {\n\t\t\tpackage: resolved,\n\t\t};\n\t}\n\n\tasync resolveType({\n\t\ttype,\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolveTypeOptions): Promise<SuiClientTypes.MvrResolveTypeResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tif (!hasMvrName(type)) {\n\t\t\treturn {\n\t\t\t\ttype,\n\t\t\t};\n\t\t}\n\n\t\tconst mvrTypes = [...extractMvrTypes(type)];\n\t\tconst resolvedTypes = await raceSignal(this.#mvrTypeDataLoader.loadMany(mvrTypes), signal);\n\n\t\tconst typeMap: Record<string, string> = {};\n\n\t\tfor (let i = 0; i < mvrTypes.length; i++) {\n\t\t\tconst resolvedType = resolvedTypes[i];\n\t\t\tif (resolvedType instanceof Error) {\n\t\t\t\tthrow resolvedType;\n\t\t\t}\n\t\t\ttypeMap[mvrTypes[i]] = resolvedType;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: replaceMvrNames(type, typeMap),\n\t\t};\n\t}\n\n\tasync resolve({\n\t\ttypes = [],\n\t\tpackages = [],\n\t\tsignal,\n\t}: SuiClientTypes.MvrResolveOptions): Promise<SuiClientTypes.MvrResolveResponse> {\n\t\tsignal?.throwIfAborted();\n\t\tconst mvrTypes = new Set<string>();\n\n\t\tfor (const type of types ?? []) {\n\t\t\textractMvrTypes(type, mvrTypes);\n\t\t}\n\n\t\tconst typesArray = [...mvrTypes];\n\t\tconst [resolvedTypes, resolvedPackages] = await raceSignal(\n\t\t\tPromise.all([\n\t\t\t\ttypesArray.length > 0 ? this.#mvrTypeDataLoader.loadMany(typesArray) : [],\n\t\t\t\tpackages.length > 0 ? this.#mvrPackageDataLoader.loadMany(packages) : [],\n\t\t\t]),\n\t\t\tsignal,\n\t\t);\n\n\t\tconst typeMap: Record<string, string> = {\n\t\t\t...this.#overrides?.types,\n\t\t};\n\n\t\tfor (const [i, type] of typesArray.entries()) {\n\t\t\tconst resolvedType = resolvedTypes[i];\n\t\t\tif (resolvedType instanceof Error) {\n\t\t\t\tthrow resolvedType;\n\t\t\t}\n\t\t\ttypeMap[type] = resolvedType;\n\t\t}\n\n\t\tconst replacedTypes: Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\ttype: string;\n\t\t\t}\n\t\t> = {};\n\n\t\tfor (const type of types ?? []) {\n\t\t\tconst resolvedType = replaceMvrNames(type, typeMap);\n\n\t\t\treplacedTypes[type] = {\n\t\t\t\ttype: resolvedType,\n\t\t\t};\n\t\t}\n\n\t\tconst replacedPackages: Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tpackage: string;\n\t\t\t}\n\t\t> = {};\n\n\t\tfor (const [i, pkg] of (packages ?? []).entries()) {\n\t\t\tconst resolvedPkg = this.#overrides?.packages?.[pkg] ?? resolvedPackages[i];\n\n\t\t\tif (resolvedPkg instanceof Error) {\n\t\t\t\tthrow resolvedPkg;\n\t\t\t}\n\n\t\t\treplacedPackages[pkg] = {\n\t\t\t\tpackage: resolvedPkg,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\ttypes: replacedTypes,\n\t\t\tpackages: replacedPackages,\n\t\t};\n\t}\n}\n\nfunction validateOverrides(overrides?: {\n\tpackages?: Record<string, string>;\n\ttypes?: Record<string, string>;\n}) {\n\tif (overrides?.packages) {\n\t\tfor (const [pkg, id] of Object.entries(overrides.packages)) {\n\t\t\tif (!isValidNamedPackage(pkg)) {\n\t\t\t\tthrow new Error(`Invalid package name: ${pkg}`);\n\t\t\t}\n\t\t\tif (!isValidSuiAddress(normalizeSuiAddress(id))) {\n\t\t\t\tthrow new Error(`Invalid package ID: ${id}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (overrides?.types) {\n\t\tfor (const [type, val] of Object.entries(overrides.types)) {\n\t\t\t// validate that types are first-level only.\n\t\t\tif (parseStructTag(type).typeParams.length > 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Type overrides must be first-level only. If you want to supply generic types, just pass each type individually.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst parsedValue = parseStructTag(val);\n\n\t\t\tif (!isValidSuiAddress(parsedValue.address)) {\n\t\t\t\tthrow new Error(`Invalid type: ${val}`);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Extracts all named types from a given type.\n */\nexport function extractMvrTypes(type: string | StructTag, types = new Set<string>()) {\n\tif (typeof type === 'string' && !hasMvrName(type)) return types;\n\n\tif (typeof type === 'string' && type.startsWith('vector<') && type.endsWith('>')) {\n\t\treturn extractMvrTypes(type.slice(7, -1), types);\n\t}\n\n\tconst tag = isStructTag(type) ? type : parseStructTag(type);\n\n\tif (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);\n\n\tfor (const param of tag.typeParams) {\n\t\textractMvrTypes(param, types);\n\t}\n\n\treturn types;\n}\n\n/**\n * Traverses a type, and replaces any found names with their resolved equivalents,\n * based on the supplied type cache.\n */\nfunction replaceMvrNames(tag: string | StructTag, typeCache: Record<string, string>): string {\n\tif (typeof tag === 'string' && !tag.includes('::')) {\n\t\treturn tag;\n\t}\n\n\tif (typeof tag === 'string' && tag.startsWith('vector<') && tag.endsWith('>')) {\n\t\treturn `vector<${replaceMvrNames(tag.slice(7, -1), typeCache)}>`;\n\t}\n\n\tconst type = isStructTag(tag) ? tag : parseStructTag(tag);\n\n\tconst typeTag = `${type.address}::${type.module}::${type.name}`;\n\tconst cacheHit = typeCache[typeTag];\n\n\treturn normalizeStructTag({\n\t\t...type,\n\t\taddress: cacheHit ? cacheHit.split('::')[0] : type.address,\n\t\ttypeParams: type.typeParams.map((param) => replaceMvrNames(param, typeCache)),\n\t});\n}\n\nexport function hasMvrName(nameOrType: string) {\n\treturn (\n\t\tnameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')\n\t);\n}\n\n/**\n * Races a promise against an optional AbortSignal. MVR resolution batches lookups\n * from independent callers into a single request via a shared DataLoader, so a\n * caller's signal cannot cancel the shared network request without affecting other\n * callers. Instead, this rejects the awaiting caller as soon as its signal aborts\n * (the underlying request continues in the background).\n *\n * The same isolation applies to any shared/cached request (e.g. `cache.read`).\n */\nexport function raceSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T> {\n\tif (!signal) {\n\t\treturn promise;\n\t}\n\n\t// An `abort` event is not replayed for listeners added after the fact, so a signal that was\n\t// already aborted would otherwise resolve normally.\n\tif (signal.aborted) {\n\t\treturn Promise.reject(signal.reason);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = () => reject(signal.reason);\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\n\t\tpromise.then(resolve, reject).finally(() => {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t});\n\t});\n}\n\nfunction isStructTag(type: string | StructTag): type is StructTag {\n\treturn (\n\t\ttypeof type === 'object' &&\n\t\t'address' in type &&\n\t\t'module' in type &&\n\t\t'name' in type &&\n\t\t'typeParams' in type\n\t);\n}\n\nexport type NamedPackagesOverrides = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tswitch (command.$kind) {\n\t\t\tcase 'MakeMoveVec':\n\t\t\t\tif (command.MakeMoveVec.type) {\n\t\t\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\t\t\ttypes.add(type);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'MoveCall':\n\t\t\t\tconst moveCall = command.MoveCall;\n\n\t\t\t\tconst pkg = moveCall.package.split('::')[0];\n\t\t\t\tif (hasMvrName(pkg)) {\n\t\t\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\t\t\tpackages.add(pkg);\n\t\t\t\t}\n\n\t\t\t\tgetNamesFromTypeList(moveCall.typeArguments ?? []).forEach((type) => {\n\t\t\t\t\ttypes.add(type);\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport function replaceNames(\n\tbuilder: TransactionDataBuilder,\n\tresolved: SuiClientTypes.MvrResolveResponse,\n) {\n\tfor (const command of builder.commands) {\n\t\t// Replacements for `MakeMoveVec` commands (that can include types)\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tif (!hasMvrName(command.MakeMoveVec.type)) continue;\n\t\t\tif (!resolved.types[command.MakeMoveVec.type])\n\t\t\t\tthrow new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);\n\t\t\tcommand.MakeMoveVec.type = resolved.types[command.MakeMoveVec.type].type;\n\t\t}\n\t\t// Replacements for `MoveCall` commands (that can include packages & types)\n\t\tconst tx = command.MoveCall;\n\t\tif (!tx) continue;\n\n\t\tconst nameParts = tx.package.split('::');\n\t\tconst name = nameParts[0];\n\n\t\tif (hasMvrName(name) && !resolved.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\t// Replace package name with address.\n\t\tif (hasMvrName(name)) {\n\t\t\tnameParts[0] = resolved.packages[name].package;\n\t\t\ttx.package = nameParts.join('::');\n\t\t}\n\n\t\tconst types = tx.typeArguments;\n\t\tif (!types) continue;\n\n\t\tfor (let i = 0; i < types.length; i++) {\n\t\t\tif (!hasMvrName(types[i])) continue;\n\n\t\t\tif (!resolved.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);\n\t\t\ttypes[i] = resolved.types[types[i]].type;\n\t\t}\n\n\t\ttx.typeArguments = types;\n\t}\n}\n\n/**\n * Returns a list of unique types that include a name\n * from the given list. This list is retrieved from the Transaction Data.\n */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (hasMvrName(type)) {\n\t\t\tif (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);\n\t\t\tnames.add(type);\n\t\t}\n\t}\n\treturn names;\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,iBAAiB;AACvB,MAAM,iBAAiB,EACtB,cAAc,eAAe,mBAC7B;;AAaD,IAA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PAGE_SIZE = 50;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Resolves pagination bounds and the traversal direction.
|
|
12
12
|
*
|
|
13
|
-
* `after` and `before` are exclusive ledger-position bounds
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* `after` and `before` are exclusive, order-independent ledger-position bounds
|
|
14
|
+
* that can be combined to read a window. Without an explicit `order`, queries
|
|
15
|
+
* bounded only by `before` read in descending order, and every other query
|
|
16
|
+
* reads in ascending order.
|
|
17
17
|
*/
|
|
18
18
|
function resolvePagination(options) {
|
|
19
|
-
if (options.after != null && options.before != null) throw new Error("Only one of `after` or `before` may be provided");
|
|
20
|
-
const descending = options.order ? options.order === "descending" : options.before != null;
|
|
21
|
-
if (options.after != null && descending) throw new Error("`after` can not be combined with descending queries");
|
|
22
|
-
if (options.before != null && !descending) throw new Error("`before` can not be combined with ascending queries");
|
|
23
19
|
return {
|
|
24
|
-
descending,
|
|
20
|
+
descending: options.order ? options.order === "descending" : options.before != null && options.after == null,
|
|
25
21
|
after: options.after ?? void 0,
|
|
26
22
|
before: options.before ?? void 0,
|
|
27
23
|
limit: options.limit ?? DEFAULT_PAGE_SIZE
|
|
28
24
|
};
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
|
-
* Validates
|
|
32
|
-
*
|
|
33
|
-
* Function filters can only be paginated when fully qualified, since JSON-RPC
|
|
34
|
-
* rejects cursors on package- or module-level `MoveFunction` filters.
|
|
27
|
+
* Validates `startCheckpoint`/`endCheckpoint` and converts them to bigints, so
|
|
28
|
+
* every transport rejects the same ranges.
|
|
35
29
|
*/
|
|
36
|
-
function
|
|
37
|
-
|
|
30
|
+
function resolveCheckpointRange(options) {
|
|
31
|
+
const start = options.startCheckpoint == null ? void 0 : parseCheckpointNumber(options.startCheckpoint, "startCheckpoint");
|
|
32
|
+
const end = options.endCheckpoint == null ? void 0 : parseCheckpointNumber(options.endCheckpoint, "endCheckpoint");
|
|
33
|
+
if (start != null && end != null && end < start) throw new Error("`endCheckpoint` must be greater than or equal to `startCheckpoint`");
|
|
34
|
+
return {
|
|
35
|
+
start,
|
|
36
|
+
end
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validates a checkpoint sequence number and converts it to a bigint. Values
|
|
41
|
+
* are capped at `Number.MAX_SAFE_INTEGER` because GraphQL represents
|
|
42
|
+
* checkpoints as `UInt53`.
|
|
43
|
+
*/
|
|
44
|
+
function parseCheckpointNumber(value, label) {
|
|
45
|
+
if (!(typeof value === "bigint" ? value >= 0n && value <= BigInt(Number.MAX_SAFE_INTEGER) : typeof value === "number" ? Number.isSafeInteger(value) && value >= 0 : /^\d+$/.test(value) && BigInt(value) <= BigInt(Number.MAX_SAFE_INTEGER))) throw new Error(`Invalid ${label} "${value}": expected a non-negative integer`);
|
|
46
|
+
return BigInt(value);
|
|
38
47
|
}
|
|
39
48
|
/**
|
|
40
49
|
* Validates a transaction filter and resolves any MVR names it contains.
|
|
@@ -43,77 +52,72 @@ function validateTransactionQuery(filter, pagination) {
|
|
|
43
52
|
* errors and MVR handling are identical across clients.
|
|
44
53
|
*/
|
|
45
54
|
async function resolveTransactionFilter(mvr, filter, signal) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
$kind: "function",
|
|
55
|
-
package: normalizeSuiAddress((await mvr.resolvePackage({
|
|
56
|
-
package: pkg,
|
|
57
|
-
signal
|
|
58
|
-
})).package),
|
|
59
|
-
module,
|
|
60
|
-
function: fn
|
|
61
|
-
};
|
|
55
|
+
validateTransactionFilter(filter);
|
|
56
|
+
const resolved = {};
|
|
57
|
+
if (filter.sender != null) resolved.sender = normalizeSuiAddress(filter.sender);
|
|
58
|
+
if (filter.affectedAddress != null) resolved.affectedAddress = normalizeSuiAddress(filter.affectedAddress);
|
|
59
|
+
if (filter.affectedObject != null) resolved.affectedObject = normalizeSuiAddress(filter.affectedObject);
|
|
60
|
+
if (filter.function != null) resolved.function = await resolvePackagePath(mvr, filter.function, signal);
|
|
61
|
+
return resolved;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Validates an event filter and resolves any MVR names it contains.
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* resolves filters through this function so that validation errors and MVR
|
|
69
|
-
* handling are identical across clients.
|
|
66
|
+
* Every transport resolves filters through this function so that validation
|
|
67
|
+
* errors and MVR handling are identical across clients.
|
|
70
68
|
*/
|
|
71
69
|
async function resolveEventFilter(mvr, filter, signal) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
if (filter.emitModule != null) {
|
|
82
|
-
const [pkg, module, ...rest] = filter.emitModule.split("::");
|
|
83
|
-
if (!pkg || !module || rest.length > 0) throw new Error(`Invalid emitModule filter "${filter.emitModule}": expected "package::module"`);
|
|
84
|
-
return {
|
|
85
|
-
$kind: "emitModule",
|
|
86
|
-
package: normalizeSuiAddress((await mvr.resolvePackage({
|
|
87
|
-
package: pkg,
|
|
88
|
-
signal
|
|
89
|
-
})).package),
|
|
90
|
-
module
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const eventType = filter.eventType;
|
|
94
|
-
const segments = eventType.split("::");
|
|
95
|
-
if (segments.length === 2 && segments.every((segment) => segment !== "")) return {
|
|
96
|
-
$kind: "eventTypeModule",
|
|
97
|
-
package: normalizeSuiAddress((await mvr.resolvePackage({
|
|
98
|
-
package: segments[0],
|
|
99
|
-
signal
|
|
100
|
-
})).package),
|
|
101
|
-
module: segments[1]
|
|
102
|
-
};
|
|
103
|
-
if (segments.length < 3 || segments.some((segment) => segment === "")) throw new Error(`Invalid eventType filter "${eventType}": expected "package::module" or a fully qualified type name`);
|
|
104
|
-
return {
|
|
105
|
-
$kind: "eventType",
|
|
106
|
-
eventType: (await mvr.resolveType({
|
|
70
|
+
validateEventFilter(filter);
|
|
71
|
+
const resolved = {};
|
|
72
|
+
if (filter.sender != null) resolved.sender = normalizeSuiAddress(filter.sender);
|
|
73
|
+
if (filter.emitModule != null) resolved.emitModule = await resolvePackagePath(mvr, filter.emitModule, signal);
|
|
74
|
+
if (filter.eventType != null) {
|
|
75
|
+
const eventType = filter.eventType;
|
|
76
|
+
if (eventType.split("::").length <= 2) resolved.eventType = await resolvePackagePath(mvr, eventType, signal);
|
|
77
|
+
else resolved.eventType = (await mvr.resolveType({
|
|
107
78
|
type: eventType,
|
|
108
79
|
signal
|
|
109
|
-
})).type
|
|
110
|
-
}
|
|
80
|
+
})).type;
|
|
81
|
+
}
|
|
82
|
+
return resolved;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks a transaction filter's shape without resolving MVR names, throwing a plain `Error`.
|
|
86
|
+
* Addresses are not checked, so a malformed one reaches the server.
|
|
87
|
+
*/
|
|
88
|
+
function validateTransactionFilter(filter) {
|
|
89
|
+
assertAtMostOne(filter, [
|
|
90
|
+
"affectedAddress",
|
|
91
|
+
"affectedObject",
|
|
92
|
+
"function"
|
|
93
|
+
], "A transaction");
|
|
94
|
+
if (filter.function != null) {
|
|
95
|
+
const [pkg, module, fn, ...rest] = filter.function.split("::");
|
|
96
|
+
if (!pkg || rest.length > 0 || module === "" || fn === "") throw new Error(`Invalid function filter "${filter.function}": expected "package", "package::module", or "package::module::function"`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Checks an event filter's shape like `validateTransactionFilter`. */
|
|
100
|
+
function validateEventFilter(filter) {
|
|
101
|
+
assertAtMostOne(filter, ["emitModule", "eventType"], "An event");
|
|
102
|
+
if (filter.emitModule != null) {
|
|
103
|
+
const segments = filter.emitModule.split("::");
|
|
104
|
+
if (segments.length > 2 || segments.some((segment) => segment === "")) throw new Error(`Invalid emitModule filter "${filter.emitModule}": expected "package" or "package::module"`);
|
|
105
|
+
}
|
|
106
|
+
if (filter.eventType != null && filter.eventType.split("::").some((segment) => segment === "")) throw new Error(`Invalid eventType filter "${filter.eventType}": expected "package", "package::module", or a fully qualified type name`);
|
|
107
|
+
}
|
|
108
|
+
/** Resolves the package segment of a `package[::module[::name]]` path, keeping the rest. */
|
|
109
|
+
async function resolvePackagePath(mvr, path, signal) {
|
|
110
|
+
const [pkg, ...rest] = path.split("::");
|
|
111
|
+
return [normalizeSuiAddress((await mvr.resolvePackage({
|
|
112
|
+
package: pkg,
|
|
113
|
+
signal
|
|
114
|
+
})).package), ...rest].join("::");
|
|
111
115
|
}
|
|
112
|
-
function
|
|
116
|
+
function assertAtMostOne(filter, predicates, subject) {
|
|
113
117
|
const present = predicates.filter((predicate) => filter[predicate] != null);
|
|
114
|
-
if (present.length
|
|
118
|
+
if (present.length > 1) throw new Error(`${subject} filter may specify at most one of ${predicates.join(", ")} (got ${present.join(", ")})`);
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
//#endregion
|
|
118
|
-
export { resolveEventFilter, resolvePagination, resolveTransactionFilter,
|
|
122
|
+
export { parseCheckpointNumber, resolveCheckpointRange, resolveEventFilter, resolvePagination, resolveTransactionFilter, validateEventFilter, validateTransactionFilter };
|
|
119
123
|
//# sourceMappingURL=query-filters.mjs.map
|