@mysten/sui 2.39.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +169 -0
- package/README.md +5 -188
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/bcs.mjs +49 -22
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/effects.mjs +49 -20
- package/dist/bcs/effects.mjs.map +1 -1
- package/dist/bcs/index.d.mts +1441 -624
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/bcs/index.mjs +2 -1
- package/dist/bcs/index.mjs.map +1 -1
- package/dist/bcs/transactions.d.mts +1059 -0
- package/dist/bcs/transactions.d.mts.map +1 -0
- package/dist/bcs/transactions.mjs +33 -14
- package/dist/bcs/transactions.mjs.map +1 -1
- package/dist/bcs/types.d.mts +6 -1
- package/dist/bcs/types.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +4 -4
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +55 -4
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +98 -1
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/errors.mjs +11 -1
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/index.d.mts +5 -3
- package/dist/client/index.mjs +6 -3
- package/dist/client/mvr.d.mts +12 -2
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/mvr.mjs +34 -13
- package/dist/client/mvr.mjs.map +1 -1
- package/dist/client/query-filters.mjs +80 -76
- package/dist/client/query-filters.mjs.map +1 -1
- package/dist/client/stream/adapter.d.mts +102 -0
- package/dist/client/stream/adapter.d.mts.map +1 -0
- package/dist/client/stream/errors.d.mts +14 -0
- package/dist/client/stream/errors.d.mts.map +1 -0
- package/dist/client/stream/errors.mjs +25 -0
- package/dist/client/stream/errors.mjs.map +1 -0
- package/dist/client/stream/filter.mjs +18 -0
- package/dist/client/stream/filter.mjs.map +1 -0
- package/dist/client/stream/follow.mjs +48 -0
- package/dist/client/stream/follow.mjs.map +1 -0
- package/dist/client/stream/index.d.mts +4 -0
- package/dist/client/stream/pager.mjs +123 -0
- package/dist/client/stream/pager.mjs.map +1 -0
- package/dist/client/stream/plan.mjs +79 -0
- package/dist/client/stream/plan.mjs.map +1 -0
- package/dist/client/stream/position.d.mts +30 -0
- package/dist/client/stream/position.d.mts.map +1 -0
- package/dist/client/stream/position.mjs +121 -0
- package/dist/client/stream/position.mjs.map +1 -0
- package/dist/client/stream/run.d.mts +2 -0
- package/dist/client/stream/run.mjs +99 -0
- package/dist/client/stream/run.mjs.map +1 -0
- package/dist/client/stream/session.mjs +205 -0
- package/dist/client/stream/session.mjs.map +1 -0
- package/dist/client/stream/status.mjs +47 -0
- package/dist/client/stream/status.mjs.map +1 -0
- package/dist/client/stream/token.mjs +80 -0
- package/dist/client/stream/token.mjs.map +1 -0
- package/dist/client/transaction-data.d.mts +17 -0
- package/dist/client/transaction-data.d.mts.map +1 -0
- package/dist/client/transaction-data.mjs +472 -0
- package/dist/client/transaction-data.mjs.map +1 -0
- package/dist/client/transaction-resolver.mjs +102 -58
- package/dist/client/transaction-resolver.mjs.map +1 -1
- package/dist/client/types.d.mts +560 -240
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts +2 -2
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +91 -30
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/index.d.mts +1 -1
- package/dist/cryptography/keypair.d.mts +1 -1
- package/dist/cryptography/publickey.d.mts +11 -0
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +12 -1
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +8 -8
- package/dist/cryptography/signature.mjs +18 -7
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/graphql/client.d.mts +51 -35
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +125 -69
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +14 -9
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +294 -118
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/errors.d.mts +20 -0
- package/dist/graphql/errors.d.mts.map +1 -0
- package/dist/graphql/errors.mjs +19 -0
- package/dist/graphql/errors.mjs.map +1 -0
- package/dist/graphql/filters.mjs +32 -0
- package/dist/graphql/filters.mjs.map +1 -0
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +1216 -208
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +820 -11
- package/dist/graphql/index.d.mts +2 -1
- package/dist/graphql/index.mjs +2 -1
- package/dist/graphql/sse-parser.mjs +82 -0
- package/dist/graphql/sse-parser.mjs.map +1 -0
- package/dist/graphql/stream/families.mjs +306 -0
- package/dist/graphql/stream/families.mjs.map +1 -0
- package/dist/graphql/stream/index.mjs +38 -0
- package/dist/graphql/stream/index.mjs.map +1 -0
- package/dist/graphql/stream/live.mjs +60 -0
- package/dist/graphql/stream/live.mjs.map +1 -0
- package/dist/graphql/stream/page.mjs +38 -0
- package/dist/graphql/stream/page.mjs.map +1 -0
- package/dist/graphql/stream/query.mjs +47 -0
- package/dist/graphql/stream/query.mjs.map +1 -0
- package/dist/graphql/subscribe.mjs +70 -0
- package/dist/graphql/subscribe.mjs.map +1 -0
- package/dist/grpc/client.d.mts +31 -27
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +42 -46
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +13 -6
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +254 -166
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/filters.mjs +44 -34
- package/dist/grpc/filters.mjs.map +1 -1
- package/dist/grpc/grpc-web-pull.mjs +245 -0
- package/dist/grpc/grpc-web-pull.mjs.map +1 -0
- package/dist/grpc/index.d.mts +2 -1
- package/dist/grpc/index.mjs +1 -1
- package/dist/grpc/network-error.mjs +31 -0
- package/dist/grpc/network-error.mjs.map +1 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs +306 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs.map +1 -0
- package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts +176 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs +175 -0
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +2 -2
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +111 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs +46 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +24 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs +25 -7
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/object.mjs +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts +111 -9
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs +63 -19
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +5 -5
- package/dist/grpc/proto/sui/rpc/v2/signature.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +5 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs +4 -0
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +20 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs +30 -13
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +20 -14
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs +8 -5
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +11 -5
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs +6 -0
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +6 -2
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +7 -7
- package/dist/grpc/proto/types.mjs +3 -2
- package/dist/grpc/pull-call.d.mts +20 -0
- package/dist/grpc/pull-call.d.mts.map +1 -0
- package/dist/grpc/pull-call.mjs +28 -0
- package/dist/grpc/pull-call.mjs.map +1 -0
- package/dist/grpc/stream/call.mjs +238 -0
- package/dist/grpc/stream/call.mjs.map +1 -0
- package/dist/grpc/stream/families.d.mts +26 -0
- package/dist/grpc/stream/families.d.mts.map +1 -0
- package/dist/grpc/stream/families.mjs +145 -0
- package/dist/grpc/stream/families.mjs.map +1 -0
- package/dist/grpc/stream/index.d.mts +41 -0
- package/dist/grpc/stream/index.d.mts.map +1 -0
- package/dist/grpc/stream/index.mjs +127 -0
- package/dist/grpc/stream/index.mjs.map +1 -0
- package/dist/grpc/stream/live.mjs +31 -0
- package/dist/grpc/stream/live.mjs.map +1 -0
- package/dist/grpc/stream/page.mjs +120 -0
- package/dist/grpc/stream/page.mjs.map +1 -0
- package/dist/grpc/stream-types.d.mts +28 -0
- package/dist/grpc/stream-types.d.mts.map +1 -0
- package/dist/grpc/transport.d.mts +8 -3
- package/dist/grpc/transport.d.mts.map +1 -1
- package/dist/grpc/transport.mjs +88 -45
- package/dist/grpc/transport.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +34 -12
- package/dist/jsonRpc/index.d.mts.map +1 -0
- package/dist/jsonRpc/index.mjs +39 -5
- package/dist/jsonRpc/index.mjs.map +1 -0
- package/dist/jsonRpc/types.d.mts +420 -0
- package/dist/jsonRpc/types.d.mts.map +1 -0
- package/dist/keypairs/passkey/keypair.d.mts +1 -1
- package/dist/multisig/publickey.d.mts +12 -4
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +5 -5
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.d.mts +1 -1
- package/dist/transactions/ObjectCache.d.mts +1 -1
- package/dist/transactions/ObjectCache.mjs +5 -5
- package/dist/transactions/ObjectCache.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +10 -9
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +17 -6
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +2 -0
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/internal.mjs +2 -1
- package/dist/transactions/data/internal.mjs.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +2 -2
- package/dist/transactions/executor/serial.d.mts +1 -1
- package/dist/transactions/executor/serial.mjs +2 -2
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/transactions/index.d.mts +3 -2
- package/dist/transactions/index.mjs +4 -3
- package/dist/transactions/intents/AllowanceBalance.mjs +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +1 -1
- package/dist/transactions/resolve.d.mts +6 -0
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/transactions/restricted-move-calls.d.mts +25 -0
- package/dist/transactions/restricted-move-calls.d.mts.map +1 -0
- package/dist/transactions/restricted-move-calls.mjs +47 -0
- package/dist/transactions/restricted-move-calls.mjs.map +1 -0
- package/dist/transactions/serializer.d.mts +1 -4
- package/dist/transactions/serializer.d.mts.map +1 -1
- package/dist/transactions/serializer.mjs +1 -44
- package/dist/transactions/serializer.mjs.map +1 -1
- package/dist/transactions/utils.d.mts +0 -1
- package/dist/transactions/utils.d.mts.map +1 -1
- package/dist/transactions/utils.mjs.map +1 -1
- package/dist/utils/abort.mjs +89 -0
- package/dist/utils/abort.mjs.map +1 -0
- package/dist/utils/coin-reservation.mjs +1 -4
- package/dist/utils/coin-reservation.mjs.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/sui-types.mjs +1 -1
- package/dist/verify/index.d.mts +2 -2
- package/dist/verify/verify.d.mts +74 -24
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +128 -42
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/publickey.mjs +15 -20
- package/dist/zklogin/publickey.mjs.map +1 -1
- package/docs/bcs.md +2 -2
- package/docs/clients/core.md +19 -18
- package/docs/clients/executing.md +53 -8
- package/docs/clients/graphql.md +81 -11
- package/docs/clients/grpc.md +31 -15
- package/docs/clients/index.md +8 -7
- package/docs/clients/querying.md +134 -30
- package/docs/clients/streaming.md +324 -0
- package/docs/cryptography/index.md +85 -58
- package/docs/llms-index.md +4 -2
- package/docs/migrations/sui-2.0/dapp-kit.md +3 -2
- package/docs/migrations/sui-2.0/json-rpc-migration.md +106 -79
- package/docs/migrations/sui-3.0/index.md +247 -0
- package/docs/plugins.md +10 -10
- package/docs/sdk-building.md +3 -4
- package/docs/transactions/coins-and-balances.md +6 -11
- package/docs/transactions/reference.md +36 -1
- package/package.json +4 -5
- package/src/bcs/bcs.ts +80 -41
- package/src/bcs/effects.ts +61 -25
- package/src/bcs/index.ts +2 -0
- package/src/bcs/transactions.ts +36 -17
- package/src/bcs/types.ts +10 -4
- package/src/client/core-resolver.ts +3 -5
- package/src/client/core.ts +180 -8
- package/src/client/errors.ts +12 -0
- package/src/client/index.ts +4 -2
- package/src/client/mvr.ts +37 -10
- package/src/client/query-filters.ts +151 -97
- package/src/client/stream/adapter.ts +110 -0
- package/src/client/stream/errors.ts +40 -0
- package/src/client/stream/filter.ts +17 -0
- package/src/client/stream/follow.ts +63 -0
- package/src/client/stream/index.ts +9 -0
- package/src/client/stream/pager.ts +158 -0
- package/src/client/stream/plan.ts +147 -0
- package/src/client/stream/position.ts +143 -0
- package/src/client/stream/run.ts +147 -0
- package/src/client/stream/session.ts +259 -0
- package/src/client/stream/status.ts +44 -0
- package/src/client/stream/token.ts +104 -0
- package/src/client/transaction-data.ts +610 -0
- package/src/client/transaction-resolver.ts +158 -69
- package/src/client/types.ts +530 -115
- package/src/client/utils.ts +146 -61
- package/src/cryptography/publickey.ts +12 -1
- package/src/cryptography/signature.ts +6 -3
- package/src/graphql/client.ts +204 -135
- package/src/graphql/core.ts +446 -139
- package/src/graphql/errors.ts +24 -0
- package/src/graphql/filters.ts +48 -0
- package/src/graphql/generated/queries.ts +1455 -277
- package/src/graphql/generated/schema.graphql +282 -9
- package/src/graphql/generated/tada-env.ts +933 -4
- package/src/graphql/queries/checkpoints.graphql +34 -0
- package/src/graphql/queries/getDynamicFields.graphql +1 -0
- package/src/graphql/queries/listEvents.graphql +16 -24
- package/src/graphql/queries/streams.graphql +212 -0
- package/src/graphql/queries/transactions.graphql +71 -28
- package/src/graphql/queries/verifySignature.graphql +17 -0
- package/src/graphql/sse-parser.ts +99 -0
- package/src/graphql/stream/families.ts +515 -0
- package/src/graphql/stream/index.ts +55 -0
- package/src/graphql/stream/live.ts +70 -0
- package/src/graphql/stream/page.ts +47 -0
- package/src/graphql/stream/query.ts +52 -0
- package/src/graphql/subscribe.ts +83 -0
- package/src/grpc/client.ts +81 -79
- package/src/grpc/core.ts +388 -274
- package/src/grpc/filters.ts +59 -60
- package/src/grpc/grpc-web-pull.ts +360 -0
- package/src/grpc/index.ts +5 -0
- package/src/grpc/network-error.ts +33 -0
- package/src/grpc/proto/sui/rpc/v2/error_reason.ts +175 -0
- package/src/grpc/proto/sui/rpc/v2/ledger_service.ts +145 -0
- package/src/grpc/proto/sui/rpc/v2/move_package_service.ts +43 -1
- package/src/grpc/proto/sui/rpc/v2/query_options.ts +132 -8
- package/src/grpc/proto/sui/rpc/v2/signature.ts +4 -4
- package/src/grpc/proto/sui/rpc/v2/signature_scheme.ts +4 -0
- package/src/grpc/proto/sui/rpc/v2/signature_verification_service.ts +30 -0
- package/src/grpc/proto/sui/rpc/v2/subscription_service.client.ts +16 -10
- package/src/grpc/proto/sui/rpc/v2/transaction.ts +6 -0
- package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +5 -1
- package/src/grpc/pull-call.ts +54 -0
- package/src/grpc/stream/call.ts +317 -0
- package/src/grpc/stream/families.ts +228 -0
- package/src/grpc/stream/index.ts +182 -0
- package/src/grpc/stream/live.ts +33 -0
- package/src/grpc/stream/page.ts +161 -0
- package/src/grpc/stream-types.ts +33 -0
- package/src/grpc/transport.ts +116 -59
- package/src/jsonRpc/index.ts +60 -17
- package/src/jsonRpc/types.ts +421 -0
- package/src/multisig/publickey.ts +19 -7
- package/src/transactions/ObjectCache.ts +6 -6
- package/src/transactions/Transaction.ts +30 -6
- package/src/transactions/data/internal.ts +2 -0
- package/src/transactions/executor/serial.ts +2 -2
- package/src/transactions/index.ts +8 -1
- package/src/transactions/resolve.ts +6 -0
- package/src/transactions/restricted-move-calls.ts +87 -0
- package/src/transactions/serializer.ts +0 -70
- package/src/transactions/utils.ts +0 -37
- package/src/utils/abort.ts +101 -0
- package/src/verify/index.ts +1 -0
- package/src/verify/verify.ts +190 -62
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +18 -34
- package/dist/client/core-resolver.d.mts +0 -9
- package/dist/client/core-resolver.d.mts.map +0 -1
- package/dist/jsonRpc/client.d.mts +0 -507
- package/dist/jsonRpc/client.d.mts.map +0 -1
- package/dist/jsonRpc/client.mjs +0 -868
- package/dist/jsonRpc/client.mjs.map +0 -1
- package/dist/jsonRpc/core.d.mts +0 -168
- package/dist/jsonRpc/core.d.mts.map +0 -1
- package/dist/jsonRpc/core.mjs +0 -1054
- package/dist/jsonRpc/core.mjs.map +0 -1
- package/dist/jsonRpc/errors.d.mts +0 -27
- package/dist/jsonRpc/errors.d.mts.map +0 -1
- package/dist/jsonRpc/errors.mjs +0 -50
- package/dist/jsonRpc/errors.mjs.map +0 -1
- package/dist/jsonRpc/http-transport.d.mts +0 -62
- package/dist/jsonRpc/http-transport.d.mts.map +0 -1
- package/dist/jsonRpc/http-transport.mjs +0 -60
- package/dist/jsonRpc/http-transport.mjs.map +0 -1
- package/dist/jsonRpc/network.d.mts +0 -9
- package/dist/jsonRpc/network.d.mts.map +0 -1
- package/dist/jsonRpc/network.mjs +0 -18
- package/dist/jsonRpc/network.mjs.map +0 -1
- package/dist/jsonRpc/types/chain.d.mts +0 -169
- package/dist/jsonRpc/types/chain.d.mts.map +0 -1
- package/dist/jsonRpc/types/changes.d.mts +0 -48
- package/dist/jsonRpc/types/changes.d.mts.map +0 -1
- package/dist/jsonRpc/types/coins.d.mts +0 -15
- package/dist/jsonRpc/types/coins.d.mts.map +0 -1
- package/dist/jsonRpc/types/common.d.mts +0 -9
- package/dist/jsonRpc/types/common.d.mts.map +0 -1
- package/dist/jsonRpc/types/generated.d.mts +0 -1976
- package/dist/jsonRpc/types/generated.d.mts.map +0 -1
- package/dist/jsonRpc/types/index.d.mts +0 -6
- package/dist/jsonRpc/types/params.d.mts +0 -898
- package/dist/jsonRpc/types/params.d.mts.map +0 -1
- package/src/graphql/generated/tsconfig.tada.json +0 -11
- package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -15
- package/src/jsonRpc/client.ts +0 -1252
- package/src/jsonRpc/core.ts +0 -1557
- package/src/jsonRpc/errors.ts +0 -57
- package/src/jsonRpc/http-transport.ts +0 -118
- package/src/jsonRpc/network.ts +0 -21
- package/src/jsonRpc/types/chain.ts +0 -190
- package/src/jsonRpc/types/changes.ts +0 -35
- package/src/jsonRpc/types/coins.ts +0 -14
- package/src/jsonRpc/types/common.ts +0 -8
- package/src/jsonRpc/types/generated.ts +0 -2165
- package/src/jsonRpc/types/index.ts +0 -9
- package/src/jsonRpc/types/params.ts +0 -908
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-filters.mjs","names":[],"sources":["../../src/client/query-filters.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type { SuiClientTypes } from './types.js';\n\nexport interface ResolvedPagination {\n\tdescending: boolean;\n\tafter: string | undefined;\n\tbefore: string | undefined;\n\tlimit: number;\n}\n\n/**\n * Default page size applied when `limit` is omitted, so every transport\n * requests the same page size instead of falling back to differing server\n * defaults.\n */\nconst DEFAULT_PAGE_SIZE = 50;\n\n/**\n * Validates pagination bounds and resolves the traversal direction.\n *\n * `after` and `before` are exclusive ledger-position bounds. Until every\n * transport can combine bounds freely, a query accepts at most one bound, and\n * the bound must match the traversal direction (`after` implies ascending,\n * `before` implies descending).\n */\nexport function resolvePagination(options: {\n\tafter?: string | null;\n\tbefore?: string | null;\n\torder?: 'ascending' | 'descending';\n\tlimit?: number;\n}): ResolvedPagination {\n\tif (options.after != null && options.before != null) {\n\t\tthrow new Error('Only one of `after` or `before` may be provided');\n\t}\n\n\tconst descending = options.order ? options.order === 'descending' : options.before != null;\n\n\tif (options.after != null && descending) {\n\t\tthrow new Error('`after` can not be combined with descending queries');\n\t}\n\n\tif (options.before != null && !descending) {\n\t\tthrow new Error('`before` can not be combined with ascending queries');\n\t}\n\n\treturn {\n\t\tdescending,\n\t\tafter: options.after ?? undefined,\n\t\tbefore: options.before ?? undefined,\n\t\tlimit: options.limit ?? DEFAULT_PAGE_SIZE,\n\t};\n}\n\nexport type ResolvedTransactionFilter =\n\t| { $kind: 'sender'; sender: string }\n\t| { $kind: 'function'; package: string; module?: string; function?: string };\n\n/**\n * Validates that a transaction query's filter supports pagination bounds.\n *\n * Function filters can only be paginated when fully qualified, since JSON-RPC\n * rejects cursors on package- or module-level `MoveFunction` filters.\n */\nexport function validateTransactionQuery(\n\tfilter: ResolvedTransactionFilter | undefined,\n\tpagination: ResolvedPagination,\n): void {\n\tif (\n\t\tfilter?.$kind === 'function' &&\n\t\t(pagination.after != null || pagination.before != null) &&\n\t\t(!filter.module || !filter.function)\n\t) {\n\t\tthrow new Error(\n\t\t\t'Paginating transactions filtered by function requires a fully qualified `package::module::function`',\n\t\t);\n\t}\n}\n\nexport type ResolvedEventFilter =\n\t| { $kind: 'sender'; sender: string }\n\t| { $kind: 'emitModule'; package: string; module: string }\n\t| { $kind: 'eventTypeModule'; package: string; module: string }\n\t| { $kind: 'eventType'; eventType: string };\n\n/**\n * Validates a transaction filter and resolves any MVR names it contains.\n *\n * Every transport resolves filters through this function so that validation\n * errors and MVR handling are identical across clients.\n */\nexport async function resolveTransactionFilter(\n\tmvr: SuiClientTypes.MvrMethods,\n\tfilter: SuiClientTypes.TransactionFilter,\n\tsignal?: AbortSignal,\n): Promise<ResolvedTransactionFilter> {\n\tassertSinglePredicate(filter, ['sender', 'function'], 'transaction');\n\n\tif (filter.sender != null) {\n\t\treturn { $kind: 'sender', sender: normalizeSuiAddress(filter.sender) };\n\t}\n\n\tconst [pkg, module, fn, ...rest] = filter.function!.split('::');\n\n\tif (!pkg || rest.length > 0 || module === '' || fn === '') {\n\t\tthrow new Error(\n\t\t\t`Invalid function filter \"${filter.function}\": expected \"package\", \"package::module\", or \"package::module::function\"`,\n\t\t);\n\t}\n\n\treturn {\n\t\t$kind: 'function',\n\t\tpackage: normalizeSuiAddress((await mvr.resolvePackage({ package: pkg, signal })).package),\n\t\tmodule,\n\t\tfunction: fn,\n\t};\n}\n\n/**\n * Validates an event filter and resolves any MVR names it contains.\n *\n * `emitModule` must name a module (`package::module`), and `eventType` must be\n * at least module-qualified (`package::module` or a full type). Every transport\n * resolves filters through this function so that validation errors and MVR\n * handling are identical across clients.\n */\nexport async function resolveEventFilter(\n\tmvr: SuiClientTypes.MvrMethods,\n\tfilter: SuiClientTypes.EventFilter,\n\tsignal?: AbortSignal,\n): Promise<ResolvedEventFilter> {\n\tassertSinglePredicate(filter, ['sender', 'emitModule', 'eventType'], 'event');\n\n\tif (filter.sender != null) {\n\t\treturn { $kind: 'sender', sender: normalizeSuiAddress(filter.sender) };\n\t}\n\n\tif (filter.emitModule != null) {\n\t\tconst [pkg, module, ...rest] = filter.emitModule.split('::');\n\n\t\tif (!pkg || !module || rest.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid emitModule filter \"${filter.emitModule}\": expected \"package::module\"`,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\t$kind: 'emitModule',\n\t\t\tpackage: normalizeSuiAddress((await mvr.resolvePackage({ package: pkg, signal })).package),\n\t\t\tmodule,\n\t\t};\n\t}\n\n\tconst eventType = filter.eventType!;\n\tconst segments = eventType.split('::');\n\n\tif (segments.length === 2 && segments.every((segment) => segment !== '')) {\n\t\treturn {\n\t\t\t$kind: 'eventTypeModule',\n\t\t\tpackage: normalizeSuiAddress(\n\t\t\t\t(await mvr.resolvePackage({ package: segments[0], signal })).package,\n\t\t\t),\n\t\t\tmodule: segments[1],\n\t\t};\n\t}\n\n\tif (segments.length < 3 || segments.some((segment) => segment === '')) {\n\t\tthrow new Error(\n\t\t\t`Invalid eventType filter \"${eventType}\": expected \"package::module\" or a fully qualified type name`,\n\t\t);\n\t}\n\n\treturn {\n\t\t$kind: 'eventType',\n\t\teventType: (await mvr.resolveType({ type: eventType, signal })).type,\n\t};\n}\n\nfunction assertSinglePredicate(\n\tfilter: Record<string, unknown>,\n\tpredicates: string[],\n\tkind: string,\n): void {\n\tconst present = predicates.filter((predicate) => filter[predicate] != null);\n\n\tif (present.length !== 1) {\n\t\tthrow new Error(\n\t\t\t`A ${kind} filter must specify exactly one of ${predicates.join(', ')}${\n\t\t\t\tpresent.length ? ` (got ${present.join(', ')})` : ''\n\t\t\t}`,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,oBAAoB;;;;;;;;;AAU1B,SAAgB,kBAAkB,SAKX;AACtB,KAAI,QAAQ,SAAS,QAAQ,QAAQ,UAAU,KAC9C,OAAM,IAAI,MAAM,kDAAkD;CAGnE,MAAM,aAAa,QAAQ,QAAQ,QAAQ,UAAU,eAAe,QAAQ,UAAU;AAEtF,KAAI,QAAQ,SAAS,QAAQ,WAC5B,OAAM,IAAI,MAAM,sDAAsD;AAGvE,KAAI,QAAQ,UAAU,QAAQ,CAAC,WAC9B,OAAM,IAAI,MAAM,sDAAsD;AAGvE,QAAO;EACN;EACA,OAAO,QAAQ,SAAS;EACxB,QAAQ,QAAQ,UAAU;EAC1B,OAAO,QAAQ,SAAS;EACxB;;;;;;;;AAaF,SAAgB,yBACf,QACA,YACO;AACP,KACC,QAAQ,UAAU,eACjB,WAAW,SAAS,QAAQ,WAAW,UAAU,UACjD,CAAC,OAAO,UAAU,CAAC,OAAO,UAE3B,OAAM,IAAI,MACT,sGACA;;;;;;;;AAgBH,eAAsB,yBACrB,KACA,QACA,QACqC;AACrC,uBAAsB,QAAQ,CAAC,UAAU,WAAW,EAAE,cAAc;AAEpE,KAAI,OAAO,UAAU,KACpB,QAAO;EAAE,OAAO;EAAU,QAAQ,oBAAoB,OAAO,OAAO;EAAE;CAGvE,MAAM,CAAC,KAAK,QAAQ,IAAI,GAAG,QAAQ,OAAO,SAAU,MAAM,KAAK;AAE/D,KAAI,CAAC,OAAO,KAAK,SAAS,KAAK,WAAW,MAAM,OAAO,GACtD,OAAM,IAAI,MACT,4BAA4B,OAAO,SAAS,0EAC5C;AAGF,QAAO;EACN,OAAO;EACP,SAAS,qBAAqB,MAAM,IAAI,eAAe;GAAE,SAAS;GAAK;GAAQ,CAAC,EAAE,QAAQ;EAC1F;EACA,UAAU;EACV;;;;;;;;;;AAWF,eAAsB,mBACrB,KACA,QACA,QAC+B;AAC/B,uBAAsB,QAAQ;EAAC;EAAU;EAAc;EAAY,EAAE,QAAQ;AAE7E,KAAI,OAAO,UAAU,KACpB,QAAO;EAAE,OAAO;EAAU,QAAQ,oBAAoB,OAAO,OAAO;EAAE;AAGvE,KAAI,OAAO,cAAc,MAAM;EAC9B,MAAM,CAAC,KAAK,QAAQ,GAAG,QAAQ,OAAO,WAAW,MAAM,KAAK;AAE5D,MAAI,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,EACpC,OAAM,IAAI,MACT,8BAA8B,OAAO,WAAW,+BAChD;AAGF,SAAO;GACN,OAAO;GACP,SAAS,qBAAqB,MAAM,IAAI,eAAe;IAAE,SAAS;IAAK;IAAQ,CAAC,EAAE,QAAQ;GAC1F;GACA;;CAGF,MAAM,YAAY,OAAO;CACzB,MAAM,WAAW,UAAU,MAAM,KAAK;AAEtC,KAAI,SAAS,WAAW,KAAK,SAAS,OAAO,YAAY,YAAY,GAAG,CACvE,QAAO;EACN,OAAO;EACP,SAAS,qBACP,MAAM,IAAI,eAAe;GAAE,SAAS,SAAS;GAAI;GAAQ,CAAC,EAAE,QAC7D;EACD,QAAQ,SAAS;EACjB;AAGF,KAAI,SAAS,SAAS,KAAK,SAAS,MAAM,YAAY,YAAY,GAAG,CACpE,OAAM,IAAI,MACT,6BAA6B,UAAU,8DACvC;AAGF,QAAO;EACN,OAAO;EACP,YAAY,MAAM,IAAI,YAAY;GAAE,MAAM;GAAW;GAAQ,CAAC,EAAE;EAChE;;AAGF,SAAS,sBACR,QACA,YACA,MACO;CACP,MAAM,UAAU,WAAW,QAAQ,cAAc,OAAO,cAAc,KAAK;AAE3E,KAAI,QAAQ,WAAW,EACtB,OAAM,IAAI,MACT,KAAK,KAAK,sCAAsC,WAAW,KAAK,KAAK,GACpE,QAAQ,SAAS,SAAS,QAAQ,KAAK,KAAK,CAAC,KAAK,KAEnD"}
|
|
1
|
+
{"version":3,"file":"query-filters.mjs","names":[],"sources":["../../src/client/query-filters.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type { SuiClientTypes } from './types.js';\n\nexport interface ResolvedPagination {\n\tdescending: boolean;\n\tafter: string | undefined;\n\tbefore: string | undefined;\n\tlimit: number;\n}\n\n/**\n * Default page size applied when `limit` is omitted, so every transport\n * requests the same page size instead of falling back to differing server\n * defaults.\n */\nconst DEFAULT_PAGE_SIZE = 50;\n\n/**\n * Resolves pagination bounds and the traversal direction.\n *\n * `after` and `before` are exclusive, order-independent ledger-position bounds\n * that can be combined to read a window. Without an explicit `order`, queries\n * bounded only by `before` read in descending order, and every other query\n * reads in ascending order.\n */\nexport function resolvePagination(options: {\n\tafter?: string | null;\n\tbefore?: string | null;\n\torder?: SuiClientTypes.Order;\n\tlimit?: number;\n}): ResolvedPagination {\n\tconst descending = options.order\n\t\t? options.order === 'descending'\n\t\t: options.before != null && options.after == null;\n\n\treturn {\n\t\tdescending,\n\t\tafter: options.after ?? undefined,\n\t\tbefore: options.before ?? undefined,\n\t\tlimit: options.limit ?? DEFAULT_PAGE_SIZE,\n\t};\n}\n\nexport interface ResolvedCheckpointRange {\n\t/** Inclusive lower checkpoint bound. */\n\tstart?: bigint;\n\t/** Exclusive upper checkpoint bound. */\n\tend?: bigint;\n}\n\n/**\n * Validates `startCheckpoint`/`endCheckpoint` and converts them to bigints, so\n * every transport rejects the same ranges.\n */\nexport function resolveCheckpointRange(options: {\n\tstartCheckpoint?: SuiClientTypes.CheckpointNumber;\n\tendCheckpoint?: SuiClientTypes.CheckpointNumber;\n}): ResolvedCheckpointRange {\n\tconst start =\n\t\toptions.startCheckpoint == null\n\t\t\t? undefined\n\t\t\t: parseCheckpointNumber(options.startCheckpoint, 'startCheckpoint');\n\tconst end =\n\t\toptions.endCheckpoint == null\n\t\t\t? undefined\n\t\t\t: parseCheckpointNumber(options.endCheckpoint, 'endCheckpoint');\n\n\tif (start != null && end != null && end < start) {\n\t\tthrow new Error('`endCheckpoint` must be greater than or equal to `startCheckpoint`');\n\t}\n\n\treturn { start, end };\n}\n\n/**\n * Validates a checkpoint sequence number and converts it to a bigint. Values\n * are capped at `Number.MAX_SAFE_INTEGER` because GraphQL represents\n * checkpoints as `UInt53`.\n */\nexport function parseCheckpointNumber(\n\tvalue: SuiClientTypes.CheckpointNumber,\n\tlabel: string,\n): bigint {\n\tconst valid =\n\t\ttypeof value === 'bigint'\n\t\t\t? value >= 0n && value <= BigInt(Number.MAX_SAFE_INTEGER)\n\t\t\t: typeof value === 'number'\n\t\t\t\t? Number.isSafeInteger(value) && value >= 0\n\t\t\t\t: /^\\d+$/.test(value) && BigInt(value) <= BigInt(Number.MAX_SAFE_INTEGER);\n\n\tif (!valid) {\n\t\tthrow new Error(`Invalid ${label} \"${value}\": expected a non-negative integer`);\n\t}\n\n\treturn BigInt(value);\n}\n\n/** A validated transaction filter with addresses normalized and MVR names resolved. */\nexport interface ResolvedTransactionFilter {\n\tsender?: string;\n\taffectedAddress?: string;\n\taffectedObject?: string;\n\t/** A normalized Move path: `0x…`, `0x…::module`, or `0x…::module::function`. */\n\tfunction?: string;\n}\n\n/** A validated event filter with addresses normalized and MVR names resolved. */\nexport interface ResolvedEventFilter {\n\tsender?: string;\n\t/** `0x…` or `0x…::module`. */\n\temitModule?: string;\n\t/** `0x…`, `0x…::module`, or a fully qualified type name. */\n\teventType?: string;\n}\n\n/**\n * Validates a transaction filter and resolves any MVR names it contains.\n *\n * Every transport resolves filters through this function so that validation\n * errors and MVR handling are identical across clients.\n */\nexport async function resolveTransactionFilter(\n\tmvr: SuiClientTypes.MvrMethods,\n\tfilter: SuiClientTypes.TransactionFilter,\n\tsignal?: AbortSignal,\n): Promise<ResolvedTransactionFilter> {\n\tvalidateTransactionFilter(filter);\n\n\tconst resolved: ResolvedTransactionFilter = {};\n\n\tif (filter.sender != null) {\n\t\tresolved.sender = normalizeSuiAddress(filter.sender);\n\t}\n\n\tif (filter.affectedAddress != null) {\n\t\tresolved.affectedAddress = normalizeSuiAddress(filter.affectedAddress);\n\t}\n\n\tif (filter.affectedObject != null) {\n\t\tresolved.affectedObject = normalizeSuiAddress(filter.affectedObject);\n\t}\n\n\tif (filter.function != null) {\n\t\tresolved.function = await resolvePackagePath(mvr, filter.function, signal);\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Validates an event filter and resolves any MVR names it contains.\n *\n * Every transport resolves filters through this function so that validation\n * errors and MVR handling are identical across clients.\n */\nexport async function resolveEventFilter(\n\tmvr: SuiClientTypes.MvrMethods,\n\tfilter: SuiClientTypes.EventFilter,\n\tsignal?: AbortSignal,\n): Promise<ResolvedEventFilter> {\n\tvalidateEventFilter(filter);\n\n\tconst resolved: ResolvedEventFilter = {};\n\n\tif (filter.sender != null) {\n\t\tresolved.sender = normalizeSuiAddress(filter.sender);\n\t}\n\n\tif (filter.emitModule != null) {\n\t\tresolved.emitModule = await resolvePackagePath(mvr, filter.emitModule, signal);\n\t}\n\n\tif (filter.eventType != null) {\n\t\tconst eventType = filter.eventType;\n\n\t\tif (eventType.split('::').length <= 2) {\n\t\t\tresolved.eventType = await resolvePackagePath(mvr, eventType, signal);\n\t\t} else {\n\t\t\tresolved.eventType = (await mvr.resolveType({ type: eventType, signal })).type;\n\t\t}\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Checks a transaction filter's shape without resolving MVR names, throwing a plain `Error`.\n * Addresses are not checked, so a malformed one reaches the server.\n */\nexport function validateTransactionFilter(filter: SuiClientTypes.TransactionFilter) {\n\tassertAtMostOne(filter, ['affectedAddress', 'affectedObject', 'function'], 'A transaction');\n\n\tif (filter.function != null) {\n\t\tconst [pkg, module, fn, ...rest] = filter.function.split('::');\n\n\t\tif (!pkg || rest.length > 0 || module === '' || fn === '') {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid function filter \"${filter.function}\": expected \"package\", \"package::module\", or \"package::module::function\"`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Checks an event filter's shape like `validateTransactionFilter`. */\nexport function validateEventFilter(filter: SuiClientTypes.EventFilter) {\n\tassertAtMostOne(filter, ['emitModule', 'eventType'], 'An event');\n\n\tif (filter.emitModule != null) {\n\t\tconst segments = filter.emitModule.split('::');\n\n\t\tif (segments.length > 2 || segments.some((segment) => segment === '')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid emitModule filter \"${filter.emitModule}\": expected \"package\" or \"package::module\"`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (filter.eventType != null && filter.eventType.split('::').some((segment) => segment === '')) {\n\t\tthrow new Error(\n\t\t\t`Invalid eventType filter \"${filter.eventType}\": expected \"package\", \"package::module\", or a fully qualified type name`,\n\t\t);\n\t}\n}\n\n/** Resolves the package segment of a `package[::module[::name]]` path, keeping the rest. */\nasync function resolvePackagePath(\n\tmvr: SuiClientTypes.MvrMethods,\n\tpath: string,\n\tsignal?: AbortSignal,\n): Promise<string> {\n\tconst [pkg, ...rest] = path.split('::');\n\tconst resolved = normalizeSuiAddress(\n\t\t(await mvr.resolvePackage({ package: pkg, signal })).package,\n\t);\n\treturn [resolved, ...rest].join('::');\n}\n\nfunction assertAtMostOne(filter: Record<string, unknown>, predicates: string[], subject: string) {\n\tconst present = predicates.filter((predicate) => filter[predicate] != null);\n\n\tif (present.length > 1) {\n\t\tthrow new Error(\n\t\t\t`${subject} filter may specify at most one of ${predicates.join(', ')} (got ${present.join(', ')})`,\n\t\t);\n\t}\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { SuiClientTypes } from "../types.mjs";
|
|
2
|
+
import { StreamPosition } from "./position.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/client/stream/adapter.d.ts
|
|
5
|
+
type StreamFamily = 'checkpoints' | 'transactions' | 'events';
|
|
6
|
+
/** Append-only: the transport tag is part of every token. */
|
|
7
|
+
type StreamTransport = 'grpc' | 'graphql';
|
|
8
|
+
/** A checkpoint start (inclusive), or a position the stream continues after. */
|
|
9
|
+
type Bound = {
|
|
10
|
+
checkpoint: bigint;
|
|
11
|
+
} | {
|
|
12
|
+
position: StreamPosition;
|
|
13
|
+
};
|
|
14
|
+
/** One page of a range: checkpoints `[range.start, range.end)`, after the start-side cursor. */
|
|
15
|
+
interface PageRequest {
|
|
16
|
+
range: {
|
|
17
|
+
start?: bigint;
|
|
18
|
+
end?: bigint;
|
|
19
|
+
};
|
|
20
|
+
/** Ascending: continue after this cursor. */
|
|
21
|
+
after?: Uint8Array;
|
|
22
|
+
/** Descending: continue before this cursor. */
|
|
23
|
+
before?: Uint8Array;
|
|
24
|
+
order: SuiClientTypes.Order;
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/** An item, or without one, a resume point the server reported mid-page. */
|
|
28
|
+
interface PageItem<Item> {
|
|
29
|
+
position: StreamPosition;
|
|
30
|
+
item?: Item;
|
|
31
|
+
}
|
|
32
|
+
/** What a page reports once its items are read. */
|
|
33
|
+
interface PageEnd {
|
|
34
|
+
/** `cursor` continues the scan; `position` is that point, where the server reports it. */
|
|
35
|
+
next: {
|
|
36
|
+
more: boolean;
|
|
37
|
+
cursor?: Uint8Array;
|
|
38
|
+
position?: StreamPosition;
|
|
39
|
+
};
|
|
40
|
+
/** Ascending, on the last page: every match through this checkpoint has been read. */
|
|
41
|
+
covered?: bigint;
|
|
42
|
+
/** A descending read without a low end stopped at this oldest retained checkpoint. */
|
|
43
|
+
retainedFrom?: bigint;
|
|
44
|
+
/** The server has not indexed what this page needs yet; the pass waits and reads again. */
|
|
45
|
+
notIndexed?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** A page's items and resume points in traversal order, as they arrive, then its end. */
|
|
48
|
+
type Page<Item> = AsyncIterator<PageItem<Item>, PageEnd, undefined>;
|
|
49
|
+
type LiveEvent<Item> = {
|
|
50
|
+
$kind: 'Item';
|
|
51
|
+
position: StreamPosition;
|
|
52
|
+
item: Item;
|
|
53
|
+
} | {
|
|
54
|
+
$kind: 'Progress';
|
|
55
|
+
position: StreamPosition;
|
|
56
|
+
};
|
|
57
|
+
interface LiveSubscription<Item> extends AsyncIterable<LiveEvent<Item>> {
|
|
58
|
+
/** While enabled, events are buffered ahead of the consumer during a gap replay. */
|
|
59
|
+
readAhead?(enabled: boolean): void;
|
|
60
|
+
}
|
|
61
|
+
/** Stream item frames without the token, which the core adds. */
|
|
62
|
+
type ItemFrame = SuiClientTypes.StreamCheckpoint<any> | SuiClientTypes.StreamTransaction<any> | SuiClientTypes.StreamEvent;
|
|
63
|
+
interface LedgerStreamAdapter<Item, Frame extends {
|
|
64
|
+
resumeToken: string;
|
|
65
|
+
} = ItemFrame> {
|
|
66
|
+
readonly transport: StreamTransport;
|
|
67
|
+
readonly family: StreamFamily;
|
|
68
|
+
/**
|
|
69
|
+
* `fromTip`: subscriptions start at the live tip, so the core pages history first and replays
|
|
70
|
+
* the gap up to the feed's first frame; every live position has a checkpoint.
|
|
71
|
+
* `resume`: `subscribe(from)` backfills after `from` on the server, then goes live.
|
|
72
|
+
*/
|
|
73
|
+
readonly live: 'fromTip' | 'resume';
|
|
74
|
+
/** `resume` only: whether `subscribe(from)` can backfill from `from`; if not, the core pages first. */
|
|
75
|
+
canResume?(from: Bound): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Resolves names in the filter; the returned filter is hashed into every token. An adapter that
|
|
78
|
+
* reads the indexed tip with the chain identity returns it, and planning uses it.
|
|
79
|
+
*/
|
|
80
|
+
initialize(signal: AbortSignal): Promise<{
|
|
81
|
+
chain: string;
|
|
82
|
+
filter: unknown;
|
|
83
|
+
indexedTip?: bigint;
|
|
84
|
+
}>;
|
|
85
|
+
/** The highest checkpoint that pages can read. */
|
|
86
|
+
indexedTip(signal: AbortSignal): Promise<bigint>;
|
|
87
|
+
/** One request, opened on the first read. The core always reads or closes it. */
|
|
88
|
+
fetchPage(request: PageRequest): Page<Item>;
|
|
89
|
+
/**
|
|
90
|
+
* A live subscription (`from` is used only by `resume` adapters). An adapter whose feed can stay
|
|
91
|
+
* quiet after it opens calls `onOpen` then, for the `Connected` status.
|
|
92
|
+
*/
|
|
93
|
+
subscribe(from: Bound | undefined, signal: AbortSignal, onOpen: () => void): LiveSubscription<Item>;
|
|
94
|
+
mapItem(item: Item): Omit<Frame, 'resumeToken'>;
|
|
95
|
+
/** Why retrying may get past `error`, or `undefined` when it cannot. */
|
|
96
|
+
retryReason(error: unknown): SuiClientTypes.RetryReason | undefined;
|
|
97
|
+
}
|
|
98
|
+
/** An adapter whose item type is known only to itself. */
|
|
99
|
+
type AnyLedgerStreamAdapter = LedgerStreamAdapter<any, any>;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { AnyLedgerStreamAdapter, Bound, ItemFrame, LedgerStreamAdapter, LiveEvent, LiveSubscription, Page, PageEnd, PageItem, PageRequest, StreamFamily, StreamTransport };
|
|
102
|
+
//# sourceMappingURL=adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../../../src/client/stream/adapter.ts"],"mappings":";;;;KAaY,YAAA;AAGZ;AAAA,KAAY,eAAA;;KAGA,KAAA;EAAU,UAAA;AAAA;EAAyB,QAAA,EAAU,cAAA;AAAA;;UAGxC,WAAA;EAChB,KAAA;IAAS,KAAA;IAAgB,GAAA;EAAA;EADT;EAGhB,KAAA,GAAQ,UAAA;;EAER,MAAA,GAAS,UAAA;EACT,KAAA,EAAO,cAAA,CAAe,KAAA;EACtB,MAAA,EAAQ,WAAA;AAAA;;UAIQ,QAAA;EAChB,QAAA,EAAU,cAAA;EACV,IAAA,GAAO,IAAA;AAAA;;UAIS,OAAA;EAZhB;EAcA,IAAA;IAAQ,IAAA;IAAe,MAAA,GAAS,UAAA;IAAY,QAAA,GAAW,cAAA;EAAA;EAZ/C;EAcR,OAAA;EAdmB;EAgBnB,YAAA;EAZwB;EAcxB,UAAA;AAAA;;KAIW,IAAA,SAAa,aAAA,CAAc,QAAA,CAAS,IAAA,GAAO,OAAA;AAAA,KAE3C,SAAA;EACP,KAAA;EAAe,QAAA,EAAU,cAAA;EAAgB,IAAA,EAAM,IAAA;AAAA;EAC/C,KAAA;EAAmB,QAAA,EAAU,cAAA;AAAA;AAAA,UAEjB,gBAAA,eAA+B,aAAA,CAAc,SAAA,CAAU,IAAA;EAhBvE;EAkBA,SAAA,EAAW,OAAA;AAAA;;KAIA,SAAA,GACT,cAAA,CAAe,gBAAA,QACf,cAAA,CAAe,iBAAA,QACf,cAAA,CAAe,WAAA;AAAA,UAMD,mBAAA;EAA0C,WAAA;AAAA,IAAwB,SAAA;EAAA,SACzE,SAAA,EAAW,eAAA;EAAA,SACX,MAAA,EAAQ,YAAA;EAvBF;;;;;EAAA,SA6BN,IAAA;EA7B4B;EA+BrC,SAAA,EAAW,IAAA,EAAM,KAAA;EA/BD;;;;EAqChB,UAAA,CAAW,MAAA,EAAQ,WAAA,GAAc,OAAA;IAAU,KAAA;IAAe,MAAA;IAAiB,UAAA;EAAA;EAnCvD;EAqCpB,UAAA,CAAW,MAAA,EAAQ,WAAA,GAAc,OAAA;EApCkB;EAsCnD,SAAA,CAAU,OAAA,EAAS,WAAA,GAAc,IAAA,CAAK,IAAA;EArCS;;;;EA0C/C,SAAA,CACC,IAAA,EAAM,KAAA,cACN,MAAA,EAAQ,WAAA,EACR,MAAA,eACE,gBAAA,CAAiB,IAAA;EAEpB,OAAA,CAAQ,IAAA,EAAM,IAAA,GAAO,IAAA,CAAK,KAAA;EAjDmB;EAmD7C,WAAA,CAAY,KAAA,YAAiB,cAAA,CAAe,WAAA;AAAA;;KAIjC,sBAAA,GAAyB,mBAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SuiClientError } from "../errors.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/client/stream/errors.d.ts
|
|
4
|
+
type SuiStreamErrorCode = /** An invalid option or bound. Never retried. */'InvalidOptions' /** Not a resume token, an unsupported version, or a non-canonical encoding. */ | 'InvalidToken' /** A token from another transport, chain, family or filter, or a changed order. */ | 'IncompatibleToken' /** The history the stream needs has been pruned by the server. */ | 'HistoryUnavailable' /** The server broke a documented invariant. */ | 'Protocol' /** The live feed kept ending without progress until the retry budget ran out. */ | 'Disconnected';
|
|
5
|
+
/** A ledger stream failure that is not a transport error. */
|
|
6
|
+
declare class SuiStreamError extends SuiClientError {
|
|
7
|
+
readonly code: SuiStreamErrorCode;
|
|
8
|
+
constructor(code: SuiStreamErrorCode, message: string, options?: {
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SuiStreamError, SuiStreamErrorCode };
|
|
14
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../../src/client/stream/errors.ts"],"mappings":";;;KAKY,kBAAA,gRAeZ;;cAAa,cAAA,SAAuB,cAAA;EAAA,SAC1B,IAAA,EAAM,kBAAA;cAEH,IAAA,EAAM,kBAAA,EAAoB,OAAA,UAAiB,OAAA;IAAY,KAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SuiClientError } from "../errors.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/client/stream/errors.ts
|
|
4
|
+
/** A ledger stream failure that is not a transport error. */
|
|
5
|
+
var SuiStreamError = class extends SuiClientError {
|
|
6
|
+
constructor(code, message, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = "SuiStreamError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Internal: a live feed ended. Feeds never complete, so the core reconnects. Never escapes the
|
|
14
|
+
* stream: an exhausted budget throws `Disconnected` instead.
|
|
15
|
+
*/
|
|
16
|
+
var StreamDisconnected = class extends Error {
|
|
17
|
+
constructor(message = "Live feed ended") {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "StreamDisconnected";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { StreamDisconnected, SuiStreamError };
|
|
25
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../src/client/stream/errors.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SuiClientError } from '../errors.js';\n\nexport type SuiStreamErrorCode =\n\t/** An invalid option or bound. Never retried. */\n\t| 'InvalidOptions'\n\t/** Not a resume token, an unsupported version, or a non-canonical encoding. */\n\t| 'InvalidToken'\n\t/** A token from another transport, chain, family or filter, or a changed order. */\n\t| 'IncompatibleToken'\n\t/** The history the stream needs has been pruned by the server. */\n\t| 'HistoryUnavailable'\n\t/** The server broke a documented invariant. */\n\t| 'Protocol'\n\t/** The live feed kept ending without progress until the retry budget ran out. */\n\t| 'Disconnected';\n\n/** A ledger stream failure that is not a transport error. */\nexport class SuiStreamError extends SuiClientError {\n\treadonly code: SuiStreamErrorCode;\n\n\tconstructor(code: SuiStreamErrorCode, message: string, options?: { cause?: unknown }) {\n\t\tsuper(message, options);\n\t\tthis.name = 'SuiStreamError';\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * Internal: a live feed ended. Feeds never complete, so the core reconnects. Never escapes the\n * stream: an exhausted budget throws `Disconnected` instead.\n */\nexport class StreamDisconnected extends Error {\n\tconstructor(message = 'Live feed ended') {\n\t\tsuper(message);\n\t\tthis.name = 'StreamDisconnected';\n\t}\n}\n"],"mappings":";;;;AAoBA,IAAa,iBAAb,cAAoC,eAAe;CAGlD,YAAY,MAA0B,SAAiB,SAA+B;AACrF,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;;AAQd,IAAa,qBAAb,cAAwC,MAAM;CAC7C,YAAY,UAAU,mBAAmB;AACxC,QAAM,QAAQ;AACd,OAAK,OAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SuiStreamError } from "./errors.mjs";
|
|
2
|
+
import { validateEventFilter, validateTransactionFilter } from "../query-filters.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/client/stream/filter.ts
|
|
5
|
+
/** Rejects an invalid `filter` with `InvalidOptions` before any request, as the list methods do. */
|
|
6
|
+
function validateStreamFilter(request) {
|
|
7
|
+
if (request.family === "checkpoints" || !request.options.filter) return;
|
|
8
|
+
try {
|
|
9
|
+
if (request.family === "transactions") validateTransactionFilter(request.options.filter);
|
|
10
|
+
else validateEventFilter(request.options.filter);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
throw new SuiStreamError("InvalidOptions", error.message, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { validateStreamFilter };
|
|
18
|
+
//# sourceMappingURL=filter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.mjs","names":[],"sources":["../../../src/client/stream/filter.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { LedgerStreamRequest } from '../core.js';\nimport { validateEventFilter, validateTransactionFilter } from '../query-filters.js';\nimport { SuiStreamError } from './errors.js';\n\n/** Rejects an invalid `filter` with `InvalidOptions` before any request, as the list methods do. */\nexport function validateStreamFilter(request: LedgerStreamRequest): void {\n\tif (request.family === 'checkpoints' || !request.options.filter) return;\n\ttry {\n\t\tif (request.family === 'transactions') validateTransactionFilter(request.options.filter);\n\t\telse validateEventFilter(request.options.filter);\n\t} catch (error) {\n\t\tthrow new SuiStreamError('InvalidOptions', (error as Error).message, { cause: error });\n\t}\n}\n"],"mappings":";;;;;AAQA,SAAgB,qBAAqB,SAAoC;AACxE,KAAI,QAAQ,WAAW,iBAAiB,CAAC,QAAQ,QAAQ,OAAQ;AACjE,KAAI;AACH,MAAI,QAAQ,WAAW,eAAgB,2BAA0B,QAAQ,QAAQ,OAAO;MACnF,qBAAoB,QAAQ,QAAQ,OAAO;UACxC,OAAO;AACf,QAAM,IAAI,eAAe,kBAAmB,MAAgB,SAAS,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SuiStreamError } from "./errors.mjs";
|
|
2
|
+
import { linkedAbortController } from "../../utils/abort.mjs";
|
|
3
|
+
import { boundaryPosition, insideCheckpoint } from "./position.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/client/stream/follow.ts
|
|
6
|
+
/**
|
|
7
|
+
* The live handoff, rerun on every reconnect. A `resume` adapter subscribes after the resume point
|
|
8
|
+
* and the server backfills from there. A `fromTip` adapter's subscription starts at the live tip,
|
|
9
|
+
* so the core pages history to the indexed tip first, then replays the gap up to the feed's first
|
|
10
|
+
* frame before delivering the feed. The pager and the feed never commit at the same time.
|
|
11
|
+
*/
|
|
12
|
+
async function* followLive(session, adapter) {
|
|
13
|
+
const start = session.start;
|
|
14
|
+
const fromTip = adapter.live === "fromTip";
|
|
15
|
+
if (start && (fromTip || adapter.canResume?.(start) === false)) yield* session.replay(void 0);
|
|
16
|
+
if (!session.committed && start && "checkpoint" in start) yield* session.baseline(boundaryPosition(start.checkpoint));
|
|
17
|
+
const attempt = linkedAbortController(session.signal);
|
|
18
|
+
let feed;
|
|
19
|
+
try {
|
|
20
|
+
session.subscribing();
|
|
21
|
+
const subscription = adapter.subscribe(session.start, attempt.controller.signal, () => session.connected());
|
|
22
|
+
feed = session.openFeed(subscription);
|
|
23
|
+
if (fromTip && start) {
|
|
24
|
+
const { position } = await feed.first();
|
|
25
|
+
const { checkpoint } = position;
|
|
26
|
+
if (checkpoint === null) throw new SuiStreamError("Protocol", "Live frame is missing its checkpoint");
|
|
27
|
+
const end = adapter.family !== "checkpoints" && insideCheckpoint(position) ? checkpoint + 1n : checkpoint;
|
|
28
|
+
const next = session.nextUncovered;
|
|
29
|
+
if (next === null || next < end) {
|
|
30
|
+
subscription.readAhead?.(true);
|
|
31
|
+
try {
|
|
32
|
+
yield* session.replay(end);
|
|
33
|
+
} finally {
|
|
34
|
+
subscription.readAhead?.(false);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return yield* session.deliver(feed);
|
|
39
|
+
} finally {
|
|
40
|
+
attempt.controller.abort();
|
|
41
|
+
attempt.dispose();
|
|
42
|
+
await feed?.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { followLive };
|
|
48
|
+
//# sourceMappingURL=follow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follow.mjs","names":[],"sources":["../../../src/client/stream/follow.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { linkedAbortController } from '../../utils/abort.js';\nimport type { CoreFrame, LedgerStreamAdapter } from './adapter.js';\nimport { SuiStreamError } from './errors.js';\nimport { boundaryPosition, insideCheckpoint } from './position.js';\nimport type { LiveFeed, StreamSession } from './session.js';\n\n/**\n * The live handoff, rerun on every reconnect. A `resume` adapter subscribes after the resume point\n * and the server backfills from there. A `fromTip` adapter's subscription starts at the live tip,\n * so the core pages history to the indexed tip first, then replays the gap up to the feed's first\n * frame before delivering the feed. The pager and the feed never commit at the same time.\n */\nexport async function* followLive<Item, Frame extends { resumeToken: string }>(\n\tsession: StreamSession<Item, Frame>,\n\tadapter: LedgerStreamAdapter<Item, Frame>,\n): AsyncGenerator<CoreFrame<Frame>, never> {\n\tconst start = session.start;\n\tconst fromTip = adapter.live === 'fromTip';\n\tif (start && (fromTip || adapter.canResume?.(start) === false)) yield* session.replay(undefined);\n\t// A token exists before the first match.\n\tif (!session.committed && start && 'checkpoint' in start) {\n\t\tyield* session.baseline(boundaryPosition(start.checkpoint));\n\t}\n\n\t// Closing must not wait for a quiet subscription's pending read: abort it first.\n\tconst attempt = linkedAbortController(session.signal);\n\tlet feed: LiveFeed<Item> | undefined;\n\ttry {\n\t\tsession.subscribing();\n\t\tconst subscription = adapter.subscribe(session.start, attempt.controller.signal, () =>\n\t\t\tsession.connected(),\n\t\t);\n\t\tfeed = session.openFeed(subscription);\n\t\tif (fromTip && start) {\n\t\t\tconst { position } = await feed.first();\n\t\t\tconst { checkpoint } = position;\n\t\t\tif (checkpoint === null) {\n\t\t\t\tthrow new SuiStreamError('Protocol', 'Live frame is missing its checkpoint');\n\t\t\t}\n\t\t\t// The gap ends at the feed's first frame. Replaying through a frame inside a checkpoint\n\t\t\t// overlaps the feed, and the session drops what it repeats.\n\t\t\tconst inside = adapter.family !== 'checkpoints' && insideCheckpoint(position);\n\t\t\tconst end = inside ? checkpoint + 1n : checkpoint;\n\t\t\tconst next = session.nextUncovered;\n\t\t\tif (next === null || next < end) {\n\t\t\t\tsubscription.readAhead?.(true);\n\t\t\t\ttry {\n\t\t\t\t\tyield* session.replay(end);\n\t\t\t\t} finally {\n\t\t\t\t\tsubscription.readAhead?.(false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn yield* session.deliver(feed);\n\t} finally {\n\t\tattempt.controller.abort();\n\t\tattempt.dispose();\n\t\tawait feed?.close();\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAeA,gBAAuB,WACtB,SACA,SAC0C;CAC1C,MAAM,QAAQ,QAAQ;CACtB,MAAM,UAAU,QAAQ,SAAS;AACjC,KAAI,UAAU,WAAW,QAAQ,YAAY,MAAM,KAAK,OAAQ,QAAO,QAAQ,OAAO,OAAU;AAEhG,KAAI,CAAC,QAAQ,aAAa,SAAS,gBAAgB,MAClD,QAAO,QAAQ,SAAS,iBAAiB,MAAM,WAAW,CAAC;CAI5D,MAAM,UAAU,sBAAsB,QAAQ,OAAO;CACrD,IAAI;AACJ,KAAI;AACH,UAAQ,aAAa;EACrB,MAAM,eAAe,QAAQ,UAAU,QAAQ,OAAO,QAAQ,WAAW,cACxE,QAAQ,WAAW,CACnB;AACD,SAAO,QAAQ,SAAS,aAAa;AACrC,MAAI,WAAW,OAAO;GACrB,MAAM,EAAE,aAAa,MAAM,KAAK,OAAO;GACvC,MAAM,EAAE,eAAe;AACvB,OAAI,eAAe,KAClB,OAAM,IAAI,eAAe,YAAY,uCAAuC;GAK7E,MAAM,MADS,QAAQ,WAAW,iBAAiB,iBAAiB,SAAS,GACxD,aAAa,KAAK;GACvC,MAAM,OAAO,QAAQ;AACrB,OAAI,SAAS,QAAQ,OAAO,KAAK;AAChC,iBAAa,YAAY,KAAK;AAC9B,QAAI;AACH,YAAO,QAAQ,OAAO,IAAI;cACjB;AACT,kBAAa,YAAY,MAAM;;;;AAIlC,SAAO,OAAO,QAAQ,QAAQ,KAAK;WAC1B;AACT,UAAQ,WAAW,OAAO;AAC1B,UAAQ,SAAS;AACjB,QAAM,MAAM,OAAO"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StreamPosition } from "./position.mjs";
|
|
2
|
+
import { AnyLedgerStreamAdapter, Bound, ItemFrame, LedgerStreamAdapter, LiveEvent, LiveSubscription, Page, PageEnd, PageItem, PageRequest, StreamFamily, StreamTransport } from "./adapter.mjs";
|
|
3
|
+
import { SuiStreamError, SuiStreamErrorCode } from "./errors.mjs";
|
|
4
|
+
import "./run.mjs";
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { SuiStreamError } from "./errors.mjs";
|
|
2
|
+
import { boundaryPosition, insideCheckpoint, progressPosition } from "./position.mjs";
|
|
3
|
+
import { sameBytes } from "./token.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/client/stream/pager.ts
|
|
6
|
+
/** The request that reads everything after `start` and before `end`. */
|
|
7
|
+
function passRequest(start, end, order, family) {
|
|
8
|
+
const ascending = order === "ascending";
|
|
9
|
+
const request = {
|
|
10
|
+
range: {},
|
|
11
|
+
order
|
|
12
|
+
};
|
|
13
|
+
if (start && "checkpoint" in start) if (ascending) request.range.start = start.checkpoint;
|
|
14
|
+
else request.range.end = start.checkpoint + 1n;
|
|
15
|
+
else if (start) {
|
|
16
|
+
const { checkpoint, cursor } = start.position;
|
|
17
|
+
const whole = family === "checkpoints" && start.position.kind === "Item";
|
|
18
|
+
const inside = !whole && insideCheckpoint(start.position);
|
|
19
|
+
if (cursor && (checkpoint === null || inside)) if (ascending) request.after = cursor;
|
|
20
|
+
else request.before = cursor;
|
|
21
|
+
if (checkpoint !== null) if (ascending) request.range.start = whole ? checkpoint + 1n : checkpoint;
|
|
22
|
+
else request.range.end = inside ? checkpoint + 1n : checkpoint;
|
|
23
|
+
}
|
|
24
|
+
if (end !== void 0) if (ascending) request.range.end = end;
|
|
25
|
+
else request.range.start = end + 1n;
|
|
26
|
+
return request;
|
|
27
|
+
}
|
|
28
|
+
async function* readPages(adapter, pass) {
|
|
29
|
+
const { order, end, signal } = pass;
|
|
30
|
+
const ascending = order === "ascending";
|
|
31
|
+
const request = {
|
|
32
|
+
...passRequest(pass.start, end, order, adapter.family),
|
|
33
|
+
signal
|
|
34
|
+
};
|
|
35
|
+
let placed = !pass.start || "checkpoint" in pass.start || pass.start.position.checkpoint !== null;
|
|
36
|
+
while (true) {
|
|
37
|
+
const page = adapter.fetchPage({
|
|
38
|
+
...request,
|
|
39
|
+
range: { ...request.range }
|
|
40
|
+
});
|
|
41
|
+
let empty = true;
|
|
42
|
+
let pageEnd;
|
|
43
|
+
try {
|
|
44
|
+
let read = await page.next();
|
|
45
|
+
for (; !read.done; read = await page.next()) {
|
|
46
|
+
const { position, item } = read.value;
|
|
47
|
+
placed = position.checkpoint !== null;
|
|
48
|
+
if (item === void 0) {
|
|
49
|
+
yield {
|
|
50
|
+
$kind: "Progress",
|
|
51
|
+
position
|
|
52
|
+
};
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
empty = false;
|
|
56
|
+
yield {
|
|
57
|
+
$kind: "Item",
|
|
58
|
+
position,
|
|
59
|
+
item
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
pageEnd = read.value;
|
|
63
|
+
} finally {
|
|
64
|
+
await page.return?.();
|
|
65
|
+
}
|
|
66
|
+
if (pageEnd.notIndexed) return {
|
|
67
|
+
complete: false,
|
|
68
|
+
retentionLimit: false
|
|
69
|
+
};
|
|
70
|
+
const { more, cursor } = pageEnd.next;
|
|
71
|
+
if (more) {
|
|
72
|
+
if (!cursor) throw protocol("Page has more items but no cursor");
|
|
73
|
+
const sent = ascending ? request.after : request.before;
|
|
74
|
+
if (sent && sameBytes(sent, cursor)) throw protocol("Pagination did not advance");
|
|
75
|
+
const position = pageEnd.next.position ?? (empty ? progressPosition(cursor) : void 0);
|
|
76
|
+
if (position) {
|
|
77
|
+
placed = position.checkpoint !== null;
|
|
78
|
+
yield {
|
|
79
|
+
$kind: "Progress",
|
|
80
|
+
position
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (ascending) request.after = cursor;
|
|
84
|
+
else request.before = cursor;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!ascending) {
|
|
88
|
+
if (end !== void 0) yield {
|
|
89
|
+
$kind: "Progress",
|
|
90
|
+
position: boundaryPosition(end + 1n)
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
complete: true,
|
|
94
|
+
retentionLimit: end === void 0 && (pageEnd.retainedFrom ?? 0n) > 0n
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const { covered } = pageEnd;
|
|
98
|
+
const boundary = boundaryAfter(covered, request.range);
|
|
99
|
+
if (boundary !== void 0 && placed) yield {
|
|
100
|
+
$kind: "Progress",
|
|
101
|
+
position: boundaryPosition(boundary)
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
complete: end === void 0 || covered === void 0 || covered >= end - 1n,
|
|
105
|
+
retentionLimit: false
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** The boundary after what an exhausted ascending read covered, within its range. */
|
|
110
|
+
function boundaryAfter(covered, { start, end }) {
|
|
111
|
+
let boundary = covered === void 0 ? end : covered + 1n;
|
|
112
|
+
if (boundary === void 0) return void 0;
|
|
113
|
+
if (end !== void 0 && boundary > end) boundary = end;
|
|
114
|
+
if (start !== void 0 && boundary < start) boundary = start;
|
|
115
|
+
return boundary;
|
|
116
|
+
}
|
|
117
|
+
function protocol(message) {
|
|
118
|
+
return new SuiStreamError("Protocol", message);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { passRequest, readPages };
|
|
123
|
+
//# sourceMappingURL=pager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pager.mjs","names":[],"sources":["../../../src/client/stream/pager.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * The shared pager. Every paged read is one pass of it: finite ranges, polling, and history before\n * a live handoff. A pass reads pages from its start until the server reports no more, then commits\n * the boundary after what the server covered, so a quiet range still moves its resume point. A\n * pass is complete once the index has reached its end; otherwise the caller waits and reads again.\n */\n\nimport type { SuiClientTypes } from '../types.js';\nimport type {\n\tBound,\n\tLedgerStreamAdapter,\n\tLiveEvent,\n\tPageEnd,\n\tPageRequest,\n\tStreamFamily,\n} from './adapter.js';\nimport { SuiStreamError } from './errors.js';\nimport { boundaryPosition, insideCheckpoint, progressPosition } from './position.js';\nimport { sameBytes } from './token.js';\n\ninterface Pass {\n\tstart?: Bound;\n\t/** Exclusive checkpoint end in traversal order. */\n\tend?: bigint;\n\torder: SuiClientTypes.Order;\n\tsignal: AbortSignal;\n}\n\n/**\n * `complete: false`: the index has not reached the end yet. `retentionLimit`: a read toward\n * genesis stopped at the oldest retained checkpoint.\n */\ninterface PassResult {\n\tcomplete: boolean;\n\tretentionLimit: boolean;\n}\n\n/** The request that reads everything after `start` and before `end`. */\nexport function passRequest(\n\tstart: Bound | undefined,\n\tend: bigint | undefined,\n\torder: SuiClientTypes.Order,\n\tfamily: StreamFamily,\n): Omit<PageRequest, 'signal'> {\n\tconst ascending = order === 'ascending';\n\tconst request: Omit<PageRequest, 'signal'> = { range: {}, order };\n\tif (start && 'checkpoint' in start) {\n\t\tif (ascending) request.range.start = start.checkpoint;\n\t\telse request.range.end = start.checkpoint + 1n;\n\t} else if (start) {\n\t\tconst { checkpoint, cursor } = start.position;\n\t\t// A delivered checkpoint and a plain boundary resume by checkpoint; anything inside a\n\t\t// checkpoint resumes by its cursor.\n\t\tconst whole = family === 'checkpoints' && start.position.kind === 'Item';\n\t\tconst inside = !whole && insideCheckpoint(start.position);\n\t\tif (cursor && (checkpoint === null || inside)) {\n\t\t\tif (ascending) request.after = cursor;\n\t\t\telse request.before = cursor;\n\t\t}\n\t\tif (checkpoint !== null) {\n\t\t\tif (ascending) request.range.start = whole ? checkpoint + 1n : checkpoint;\n\t\t\telse request.range.end = inside ? checkpoint + 1n : checkpoint;\n\t\t}\n\t}\n\tif (end !== undefined) {\n\t\tif (ascending) request.range.end = end;\n\t\telse request.range.start = end + 1n;\n\t}\n\treturn request;\n}\n\nexport async function* readPages<Item>(\n\tadapter: LedgerStreamAdapter<Item, any>,\n\tpass: Pass,\n): AsyncGenerator<LiveEvent<Item>, PassResult> {\n\tconst { order, end, signal } = pass;\n\tconst ascending = order === 'ascending';\n\tconst request: PageRequest = {\n\t\t...passRequest(pass.start, end, order, adapter.family),\n\t\tsignal,\n\t};\n\n\t// A boundary from what a replica has covered can sit behind a cursor without a checkpoint,\n\t// whose place is unknown, so it is committed only after a position with a checkpoint.\n\tlet placed = !pass.start || 'checkpoint' in pass.start || pass.start.position.checkpoint !== null;\n\twhile (true) {\n\t\tconst page = adapter.fetchPage({ ...request, range: { ...request.range } });\n\t\tlet empty = true;\n\t\tlet pageEnd: PageEnd;\n\t\ttry {\n\t\t\tlet read = await page.next();\n\t\t\tfor (; !read.done; read = await page.next()) {\n\t\t\t\tconst { position, item } = read.value;\n\t\t\t\tplaced = position.checkpoint !== null;\n\t\t\t\tif (item === undefined) {\n\t\t\t\t\tyield { $kind: 'Progress', position };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tempty = false;\n\t\t\t\tyield { $kind: 'Item', position, item };\n\t\t\t}\n\t\t\tpageEnd = read.value;\n\t\t} finally {\n\t\t\tawait page.return?.();\n\t\t}\n\t\tif (pageEnd.notIndexed) return { complete: false, retentionLimit: false };\n\n\t\tconst { more, cursor } = pageEnd.next;\n\t\tif (more) {\n\t\t\tif (!cursor) throw protocol('Page has more items but no cursor');\n\t\t\tconst sent = ascending ? request.after : request.before;\n\t\t\tif (sent && sameBytes(sent, cursor)) throw protocol('Pagination did not advance');\n\t\t\t// A page end that reports where the scan stopped, or an empty page, moves the resume point,\n\t\t\t// so sparse filters save their place.\n\t\t\tconst position = pageEnd.next.position ?? (empty ? progressPosition(cursor) : undefined);\n\t\t\tif (position) {\n\t\t\t\tplaced = position.checkpoint !== null;\n\t\t\t\tyield { $kind: 'Progress', position };\n\t\t\t}\n\t\t\tif (ascending) request.after = cursor;\n\t\t\telse request.before = cursor;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!ascending) {\n\t\t\t// Covered down to the end, so a finished range resumes as empty.\n\t\t\tif (end !== undefined) yield { $kind: 'Progress', position: boundaryPosition(end + 1n) };\n\t\t\tconst retentionLimit = end === undefined && (pageEnd.retainedFrom ?? 0n) > 0n;\n\t\t\treturn { complete: true, retentionLimit };\n\t\t}\n\n\t\tconst { covered } = pageEnd;\n\t\tconst boundary = boundaryAfter(covered, request.range);\n\t\tif (boundary !== undefined && placed) {\n\t\t\tyield { $kind: 'Progress', position: boundaryPosition(boundary) };\n\t\t}\n\t\treturn {\n\t\t\tcomplete: end === undefined || covered === undefined || covered >= end - 1n,\n\t\t\tretentionLimit: false,\n\t\t};\n\t}\n}\n\n/** The boundary after what an exhausted ascending read covered, within its range. */\nfunction boundaryAfter(covered: bigint | undefined, { start, end }: PageRequest['range']) {\n\tlet boundary = covered === undefined ? end : covered + 1n;\n\tif (boundary === undefined) return undefined;\n\tif (end !== undefined && boundary > end) boundary = end;\n\tif (start !== undefined && boundary < start) boundary = start;\n\treturn boundary;\n}\n\nfunction protocol(message: string) {\n\treturn new SuiStreamError('Protocol', message);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SuiStreamError } from "./errors.mjs";
|
|
2
|
+
import { parseCheckpointNumber } from "../query-filters.mjs";
|
|
3
|
+
import { decodeToken, filterHash, sameBytes } from "./token.mjs";
|
|
4
|
+
import { passRequest } from "./pager.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/client/stream/plan.ts
|
|
7
|
+
/** Milliseconds between polls when `pollInterval` isn't set. */
|
|
8
|
+
const DEFAULT_POLL_INTERVAL = 1e3;
|
|
9
|
+
/**
|
|
10
|
+
* Checks every option that needs no network, so a failing or retrying request can never hide an
|
|
11
|
+
* option or token error.
|
|
12
|
+
*/
|
|
13
|
+
function validateOptions(options, adapter) {
|
|
14
|
+
const token = options.start?.resumeToken !== void 0 ? decodeToken(options.start.resumeToken) : void 0;
|
|
15
|
+
if (token && (token.transport !== adapter.transport || token.family !== adapter.family)) throw incompatibleToken();
|
|
16
|
+
const order = options.order ?? token?.order ?? "ascending";
|
|
17
|
+
if (token && token.order !== order) throw new SuiStreamError("IncompatibleToken", "A resume token cannot change traversal order");
|
|
18
|
+
if (options.end && options.end.checkpoint === void 0) throw new SuiStreamError("InvalidOptions", "end must be a checkpoint");
|
|
19
|
+
const follow = options.follow ?? (order === "ascending" && !options.end);
|
|
20
|
+
if (follow && (order === "descending" || options.end)) throw new SuiStreamError("InvalidOptions", "Following requires ascending order without an end bound");
|
|
21
|
+
if (!follow && order === "ascending" && !options.start) throw new SuiStreamError("InvalidOptions", "Ascending finite streams require a start");
|
|
22
|
+
const pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
23
|
+
if (!(pollInterval > 0)) throw new SuiStreamError("InvalidOptions", "pollInterval must be a positive number");
|
|
24
|
+
const startCheckpoint = checkpointOption(options.start?.checkpoint, "start");
|
|
25
|
+
const end = checkpointOption(options.end?.checkpoint, "end");
|
|
26
|
+
if (startCheckpoint !== void 0 && end !== void 0) {
|
|
27
|
+
if (order === "ascending" ? startCheckpoint > end : startCheckpoint < end) throw new SuiStreamError("InvalidOptions", "Stream start and end bounds are reversed");
|
|
28
|
+
}
|
|
29
|
+
let completion = "checkpointBound";
|
|
30
|
+
if (end === void 0) completion = order === "ascending" ? "indexedTip" : "genesis";
|
|
31
|
+
return {
|
|
32
|
+
mode: !follow ? "finite" : options.delivery === "poll" ? "poll" : "follow",
|
|
33
|
+
order,
|
|
34
|
+
pollInterval,
|
|
35
|
+
token,
|
|
36
|
+
start: token ? { position: token.position } : startCheckpoint !== void 0 ? { checkpoint: startCheckpoint } : void 0,
|
|
37
|
+
end,
|
|
38
|
+
completion
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks the token against the stream's identity and fills in what depends on the indexed tip,
|
|
43
|
+
* reading it at most once.
|
|
44
|
+
*/
|
|
45
|
+
async function planStream(plan, identity, adapter, readIndexedTip) {
|
|
46
|
+
const { token, order, mode } = plan;
|
|
47
|
+
if (token && (token.chain !== identity.chain || !sameBytes(token.filter, filterHash(identity.filter)))) throw incompatibleToken();
|
|
48
|
+
const anchorsAtLiveTip = mode === "follow" && adapter.live === "fromTip";
|
|
49
|
+
const needsStart = !plan.start && !anchorsAtLiveTip;
|
|
50
|
+
const needsEnd = mode === "finite" && order === "ascending" && plan.end === void 0;
|
|
51
|
+
if (!needsStart && !needsEnd) return plan;
|
|
52
|
+
const tip = await readIndexedTip();
|
|
53
|
+
return {
|
|
54
|
+
...plan,
|
|
55
|
+
start: needsStart ? { checkpoint: order === "ascending" ? tip + 1n : tip } : plan.start,
|
|
56
|
+
end: needsEnd ? tip + 1n : plan.end
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Whether a finite stream's bounds leave nothing to read. */
|
|
60
|
+
function isEmptyRange(plan, family) {
|
|
61
|
+
if (plan.mode !== "finite" || !plan.start) return false;
|
|
62
|
+
const { range } = passRequest(plan.start, plan.end, plan.order, family);
|
|
63
|
+
return range.start !== void 0 && range.end !== void 0 && range.start >= range.end;
|
|
64
|
+
}
|
|
65
|
+
function incompatibleToken() {
|
|
66
|
+
return new SuiStreamError("IncompatibleToken", "Resume token belongs to a different transport, chain, stream family or filter");
|
|
67
|
+
}
|
|
68
|
+
function checkpointOption(value, label) {
|
|
69
|
+
if (value === void 0) return void 0;
|
|
70
|
+
try {
|
|
71
|
+
return parseCheckpointNumber(value, label);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new SuiStreamError("InvalidOptions", error.message, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { DEFAULT_POLL_INTERVAL, isEmptyRange, planStream, validateOptions };
|
|
79
|
+
//# sourceMappingURL=plan.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.mjs","names":[],"sources":["../../../src/client/stream/plan.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { parseCheckpointNumber } from '../query-filters.js';\nimport type { SuiClientTypes } from '../types.js';\nimport type { Bound, LedgerStreamAdapter } from './adapter.js';\nimport { SuiStreamError } from './errors.js';\nimport { passRequest } from './pager.js';\nimport { decodeToken, filterHash, sameBytes, type StreamToken } from './token.js';\n\n/** Milliseconds between polls when `pollInterval` isn't set. */\nexport const DEFAULT_POLL_INTERVAL = 1000;\n\n/** finite: read to the end. poll: read to the tip repeatedly. follow: the live handoff. */\ntype StreamMode = 'finite' | 'poll' | 'follow';\n\nexport interface StreamPlan {\n\tmode: StreamMode;\n\torder: SuiClientTypes.Order;\n\tpollInterval: number;\n\ttoken?: StreamToken;\n\t/** Where the stream starts; undefined for a fresh follow at the live tip. */\n\tstart?: Bound;\n\t/** The exclusive checkpoint end of a finite stream, in traversal order. */\n\tend?: bigint;\n\t/** Why a finite stream completes, unless it stops at the retention limit. */\n\tcompletion: SuiClientTypes.StreamCompletionFrame['reason'];\n}\n\ntype Adapter = Pick<LedgerStreamAdapter<unknown, any>, 'transport' | 'family' | 'live'>;\n\n/**\n * Checks every option that needs no network, so a failing or retrying request can never hide an\n * option or token error.\n */\nexport function validateOptions(\n\toptions: SuiClientTypes.StreamOptions<SuiClientTypes.StreamFrameOptions>,\n\tadapter: Adapter,\n): StreamPlan {\n\tconst token =\n\t\toptions.start?.resumeToken !== undefined ? decodeToken(options.start.resumeToken) : undefined;\n\tif (token && (token.transport !== adapter.transport || token.family !== adapter.family)) {\n\t\tthrow incompatibleToken();\n\t}\n\tconst order = options.order ?? token?.order ?? 'ascending';\n\tif (token && token.order !== order) {\n\t\tthrow new SuiStreamError('IncompatibleToken', 'A resume token cannot change traversal order');\n\t}\n\tif (options.end && options.end.checkpoint === undefined) {\n\t\tthrow new SuiStreamError('InvalidOptions', 'end must be a checkpoint');\n\t}\n\n\tconst follow = options.follow ?? (order === 'ascending' && !options.end);\n\tif (follow && (order === 'descending' || options.end)) {\n\t\tthrow new SuiStreamError(\n\t\t\t'InvalidOptions',\n\t\t\t'Following requires ascending order without an end bound',\n\t\t);\n\t}\n\tif (!follow && order === 'ascending' && !options.start) {\n\t\tthrow new SuiStreamError('InvalidOptions', 'Ascending finite streams require a start');\n\t}\n\tconst pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;\n\tif (!(pollInterval > 0)) {\n\t\tthrow new SuiStreamError('InvalidOptions', 'pollInterval must be a positive number');\n\t}\n\n\tconst startCheckpoint = checkpointOption(options.start?.checkpoint, 'start');\n\tconst end = checkpointOption(options.end?.checkpoint, 'end');\n\tif (startCheckpoint !== undefined && end !== undefined) {\n\t\tif (order === 'ascending' ? startCheckpoint > end : startCheckpoint < end) {\n\t\t\tthrow new SuiStreamError('InvalidOptions', 'Stream start and end bounds are reversed');\n\t\t}\n\t}\n\n\tlet completion: StreamPlan['completion'] = 'checkpointBound';\n\tif (end === undefined) completion = order === 'ascending' ? 'indexedTip' : 'genesis';\n\treturn {\n\t\tmode: !follow ? 'finite' : options.delivery === 'poll' ? 'poll' : 'follow',\n\t\torder,\n\t\tpollInterval,\n\t\ttoken,\n\t\tstart: token\n\t\t\t? { position: token.position }\n\t\t\t: startCheckpoint !== undefined\n\t\t\t\t? { checkpoint: startCheckpoint }\n\t\t\t\t: undefined,\n\t\tend,\n\t\tcompletion,\n\t};\n}\n\n/**\n * Checks the token against the stream's identity and fills in what depends on the indexed tip,\n * reading it at most once.\n */\nexport async function planStream(\n\tplan: StreamPlan,\n\tidentity: { chain: string; filter: unknown },\n\tadapter: Adapter,\n\treadIndexedTip: () => Promise<bigint>,\n): Promise<StreamPlan> {\n\tconst { token, order, mode } = plan;\n\tif (\n\t\ttoken &&\n\t\t(token.chain !== identity.chain || !sameBytes(token.filter, filterHash(identity.filter)))\n\t) {\n\t\tthrow incompatibleToken();\n\t}\n\tconst anchorsAtLiveTip = mode === 'follow' && adapter.live === 'fromTip';\n\tconst needsStart = !plan.start && !anchorsAtLiveTip;\n\tconst needsEnd = mode === 'finite' && order === 'ascending' && plan.end === undefined;\n\tif (!needsStart && !needsEnd) return plan;\n\n\tconst tip = await readIndexedTip();\n\treturn {\n\t\t...plan,\n\t\tstart: needsStart ? { checkpoint: order === 'ascending' ? tip + 1n : tip } : plan.start,\n\t\tend: needsEnd ? tip + 1n : plan.end,\n\t};\n}\n\n/** Whether a finite stream's bounds leave nothing to read. */\nexport function isEmptyRange(plan: StreamPlan, family: Adapter['family']): boolean {\n\tif (plan.mode !== 'finite' || !plan.start) return false;\n\tconst { range } = passRequest(plan.start, plan.end, plan.order, family);\n\treturn range.start !== undefined && range.end !== undefined && range.start >= range.end;\n}\n\nfunction incompatibleToken() {\n\treturn new SuiStreamError(\n\t\t'IncompatibleToken',\n\t\t'Resume token belongs to a different transport, chain, stream family or filter',\n\t);\n}\n\nfunction checkpointOption(\n\tvalue: SuiClientTypes.CheckpointNumber | undefined,\n\tlabel: string,\n): bigint | undefined {\n\tif (value === undefined) return undefined;\n\ttry {\n\t\treturn parseCheckpointNumber(value, label);\n\t} catch (error) {\n\t\tthrow new SuiStreamError('InvalidOptions', (error as Error).message, { cause: error });\n\t}\n}\n"],"mappings":";;;;;;;AAWA,MAAa,wBAAwB;;;;;AAwBrC,SAAgB,gBACf,SACA,SACa;CACb,MAAM,QACL,QAAQ,OAAO,gBAAgB,SAAY,YAAY,QAAQ,MAAM,YAAY,GAAG;AACrF,KAAI,UAAU,MAAM,cAAc,QAAQ,aAAa,MAAM,WAAW,QAAQ,QAC/E,OAAM,mBAAmB;CAE1B,MAAM,QAAQ,QAAQ,SAAS,OAAO,SAAS;AAC/C,KAAI,SAAS,MAAM,UAAU,MAC5B,OAAM,IAAI,eAAe,qBAAqB,+CAA+C;AAE9F,KAAI,QAAQ,OAAO,QAAQ,IAAI,eAAe,OAC7C,OAAM,IAAI,eAAe,kBAAkB,2BAA2B;CAGvE,MAAM,SAAS,QAAQ,WAAW,UAAU,eAAe,CAAC,QAAQ;AACpE,KAAI,WAAW,UAAU,gBAAgB,QAAQ,KAChD,OAAM,IAAI,eACT,kBACA,0DACA;AAEF,KAAI,CAAC,UAAU,UAAU,eAAe,CAAC,QAAQ,MAChD,OAAM,IAAI,eAAe,kBAAkB,2CAA2C;CAEvF,MAAM,eAAe,QAAQ,gBAAgB;AAC7C,KAAI,EAAE,eAAe,GACpB,OAAM,IAAI,eAAe,kBAAkB,yCAAyC;CAGrF,MAAM,kBAAkB,iBAAiB,QAAQ,OAAO,YAAY,QAAQ;CAC5E,MAAM,MAAM,iBAAiB,QAAQ,KAAK,YAAY,MAAM;AAC5D,KAAI,oBAAoB,UAAa,QAAQ,QAC5C;MAAI,UAAU,cAAc,kBAAkB,MAAM,kBAAkB,IACrE,OAAM,IAAI,eAAe,kBAAkB,2CAA2C;;CAIxF,IAAI,aAAuC;AAC3C,KAAI,QAAQ,OAAW,cAAa,UAAU,cAAc,eAAe;AAC3E,QAAO;EACN,MAAM,CAAC,SAAS,WAAW,QAAQ,aAAa,SAAS,SAAS;EAClE;EACA;EACA;EACA,OAAO,QACJ,EAAE,UAAU,MAAM,UAAU,GAC5B,oBAAoB,SACnB,EAAE,YAAY,iBAAiB,GAC/B;EACJ;EACA;EACA;;;;;;AAOF,eAAsB,WACrB,MACA,UACA,SACA,gBACsB;CACtB,MAAM,EAAE,OAAO,OAAO,SAAS;AAC/B,KACC,UACC,MAAM,UAAU,SAAS,SAAS,CAAC,UAAU,MAAM,QAAQ,WAAW,SAAS,OAAO,CAAC,EAExF,OAAM,mBAAmB;CAE1B,MAAM,mBAAmB,SAAS,YAAY,QAAQ,SAAS;CAC/D,MAAM,aAAa,CAAC,KAAK,SAAS,CAAC;CACnC,MAAM,WAAW,SAAS,YAAY,UAAU,eAAe,KAAK,QAAQ;AAC5E,KAAI,CAAC,cAAc,CAAC,SAAU,QAAO;CAErC,MAAM,MAAM,MAAM,gBAAgB;AAClC,QAAO;EACN,GAAG;EACH,OAAO,aAAa,EAAE,YAAY,UAAU,cAAc,MAAM,KAAK,KAAK,GAAG,KAAK;EAClF,KAAK,WAAW,MAAM,KAAK,KAAK;EAChC;;;AAIF,SAAgB,aAAa,MAAkB,QAAoC;AAClF,KAAI,KAAK,SAAS,YAAY,CAAC,KAAK,MAAO,QAAO;CAClD,MAAM,EAAE,UAAU,YAAY,KAAK,OAAO,KAAK,KAAK,KAAK,OAAO,OAAO;AACvE,QAAO,MAAM,UAAU,UAAa,MAAM,QAAQ,UAAa,MAAM,SAAS,MAAM;;AAGrF,SAAS,oBAAoB;AAC5B,QAAO,IAAI,eACV,qBACA,gFACA;;AAGF,SAAS,iBACR,OACA,OACqB;AACrB,KAAI,UAAU,OAAW,QAAO;AAChC,KAAI;AACH,SAAO,sBAAsB,OAAO,MAAM;UAClC,OAAO;AACf,QAAM,IAAI,eAAe,kBAAmB,MAAgB,SAAS,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "./adapter.mjs";
|
|
2
|
+
import "@mysten/bcs";
|
|
3
|
+
|
|
4
|
+
//#region src/client/stream/position.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Stream positions, shared by every transport. Adapters build positions from what the server
|
|
7
|
+
* reports and turn them back into request cursors; cursors themselves are never parsed or compared.
|
|
8
|
+
*
|
|
9
|
+
* - `Item`: a delivered item in `checkpoint`. Its place within the checkpoint is
|
|
10
|
+
* `transactionIndex`/`eventIndex` where reported, else only `itemId` identifies it.
|
|
11
|
+
* - `Boundary`: just before `checkpoint`, or with `transactionIndex`, just before that key within
|
|
12
|
+
* it (resumed by its cursor).
|
|
13
|
+
* - `Progress`: a cursor the server reported without a checkpoint (GraphQL only).
|
|
14
|
+
*
|
|
15
|
+
* `nextUncovered` is the first checkpoint not known to be delivered at the position, in ascending
|
|
16
|
+
* order: every matching item before it was delivered. Null makes no claim.
|
|
17
|
+
*/
|
|
18
|
+
interface StreamPosition {
|
|
19
|
+
kind: 'Item' | 'Boundary' | 'Progress';
|
|
20
|
+
cursor: Uint8Array | null;
|
|
21
|
+
/** Null only for `Progress`. */
|
|
22
|
+
checkpoint: bigint | null;
|
|
23
|
+
transactionIndex: bigint | null;
|
|
24
|
+
eventIndex: number | null;
|
|
25
|
+
itemId: string | null;
|
|
26
|
+
nextUncovered: bigint | null;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { StreamPosition };
|
|
30
|
+
//# sourceMappingURL=position.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.d.mts","names":[],"sources":["../../../src/client/stream/position.ts"],"mappings":";;;;;;;AAoBA;;;;;;;;;;UAAiB,cAAA;EAChB,IAAA;EACA,MAAA,EAAQ,UAAA;EAMK;EAJb,UAAA;EACA,gBAAA;EACA,UAAA;EACA,MAAA;EACA,aAAA;AAAA"}
|