viem 2.57.14 → 2.57.16
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 +58 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +5 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/fillTransaction.js +2 -0
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/getFilterChanges.js +1 -0
- package/_cjs/actions/public/getFilterChanges.js.map +1 -1
- package/_cjs/actions/public/getFilterLogs.js +1 -0
- package/_cjs/actions/public/getFilterLogs.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +20 -8
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +10 -3
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -0
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -2
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/hashKeyChain.js +4 -4
- package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/turkchain.js +26 -0
- package/_cjs/chains/definitions/turkchain.js.map +1 -0
- package/_cjs/chains/definitions/zksync.js +1 -1
- package/_cjs/chains/definitions/zksync.js.map +1 -1
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/transports/fallback.js +5 -0
- package/_cjs/clients/transports/fallback.js.map +1 -1
- package/_cjs/errors/node.js +10 -4
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/typedData.js +4 -2
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +85 -12
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Gateway.js +195 -0
- package/_cjs/tempo/Gateway.js.map +1 -0
- package/_cjs/tempo/GatewayDecorator.js +168 -0
- package/_cjs/tempo/GatewayDecorator.js.map +1 -0
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/actions/ai.js +69 -0
- package/_cjs/tempo/actions/ai.js.map +1 -0
- package/_cjs/tempo/actions/bucket.js +85 -0
- package/_cjs/tempo/actions/bucket.js.map +1 -0
- package/_cjs/tempo/actions/compute.js +165 -0
- package/_cjs/tempo/actions/compute.js.map +1 -0
- package/_cjs/tempo/actions/gateway.js +8 -0
- package/_cjs/tempo/actions/gateway.js.map +1 -0
- package/_cjs/tempo/actions/index.js +6 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/kv.js +44 -0
- package/_cjs/tempo/actions/kv.js.map +1 -0
- package/_cjs/tempo/chainConfig.js +4 -12
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +4 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/ndjson.js +43 -0
- package/_cjs/tempo/internal/ndjson.js.map +1 -0
- package/_cjs/tempo/internal/relay/feePayer.js +18 -5
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +57 -7
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +27 -6
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +27 -4
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
- package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_cjs/utils/buildRequest.js +4 -0
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_cjs/utils/ccip.js +134 -28
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/ccipTunnel.js +5 -1
- package/_cjs/utils/ccipTunnel.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/hash/toSignatureHash.js +10 -1
- package/_cjs/utils/hash/toSignatureHash.js.map +1 -1
- package/_cjs/utils/internal/http.js +79 -0
- package/_cjs/utils/internal/http.js.map +1 -0
- package/_cjs/utils/nonceManager.js.map +1 -1
- package/_cjs/utils/rpc/http.js +9 -76
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/rpc/socket.js +20 -9
- package/_cjs/utils/rpc/socket.js.map +1 -1
- package/_cjs/utils/transaction/assertRequest.js +2 -2
- package/_cjs/utils/transaction/assertRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +2 -2
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +21 -7
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/typedData.js +19 -6
- package/_cjs/utils/typedData.js.map +1 -1
- package/_cjs/zksync/actions/finalizeWithdrawal.js +4 -2
- package/_cjs/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_cjs/zksync/actions/isWithdrawalFinalized.js +4 -5
- package/_cjs/zksync/actions/isWithdrawalFinalized.js.map +1 -1
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +10 -5
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +2 -0
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/getFilterChanges.js +1 -0
- package/_esm/actions/public/getFilterChanges.js.map +1 -1
- package/_esm/actions/public/getFilterLogs.js +1 -0
- package/_esm/actions/public/getFilterLogs.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +5 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +28 -8
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +15 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +11 -2
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +6 -2
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +59 -8
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/hashKeyChain.js +4 -4
- package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/turkchain.js +23 -0
- package/_esm/chains/definitions/turkchain.js.map +1 -0
- package/_esm/chains/definitions/zksync.js +1 -1
- package/_esm/chains/definitions/zksync.js.map +1 -1
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/transports/fallback.js +8 -0
- package/_esm/clients/transports/fallback.js.map +1 -1
- package/_esm/errors/node.js +10 -4
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/typedData.js +5 -2
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Account.js +122 -11
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Gateway.js +294 -0
- package/_esm/tempo/Gateway.js.map +1 -0
- package/_esm/tempo/GatewayDecorator.js +207 -0
- package/_esm/tempo/GatewayDecorator.js.map +1 -0
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/actions/ai.js +132 -0
- package/_esm/tempo/actions/ai.js.map +1 -0
- package/_esm/tempo/actions/bucket.js +181 -0
- package/_esm/tempo/actions/bucket.js.map +1 -0
- package/_esm/tempo/actions/compute.js +424 -0
- package/_esm/tempo/actions/compute.js.map +1 -0
- package/_esm/tempo/actions/gateway.js +22 -0
- package/_esm/tempo/actions/gateway.js.map +1 -0
- package/_esm/tempo/actions/index.js +10 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/kv.js +124 -0
- package/_esm/tempo/actions/kv.js.map +1 -0
- package/_esm/tempo/chainConfig.js +13 -15
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +9 -0
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/ndjson.js +45 -0
- package/_esm/tempo/internal/ndjson.js.map +1 -0
- package/_esm/tempo/internal/relay/feePayer.js +24 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +69 -7
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +34 -6
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +43 -10
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/verifyAuthorization.js +15 -4
- package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_esm/utils/buildRequest.js +6 -0
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_esm/utils/ccip.js +163 -31
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/ccipTunnel.js +5 -1
- package/_esm/utils/ccipTunnel.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/hash/toSignatureHash.js +11 -1
- package/_esm/utils/hash/toSignatureHash.js.map +1 -1
- package/_esm/utils/internal/http.js +83 -0
- package/_esm/utils/internal/http.js.map +1 -0
- package/_esm/utils/nonceManager.js.map +1 -1
- package/_esm/utils/rpc/http.js +12 -78
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/rpc/socket.js +24 -9
- package/_esm/utils/rpc/socket.js.map +1 -1
- package/_esm/utils/transaction/assertRequest.js +2 -2
- package/_esm/utils/transaction/assertRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +2 -2
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +24 -7
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/typedData.js +25 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_esm/zksync/actions/finalizeWithdrawal.js +5 -2
- package/_esm/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_esm/zksync/actions/isWithdrawalFinalized.js +5 -5
- package/_esm/zksync/actions/isWithdrawalFinalized.js.map +1 -1
- package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts +6 -2
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts +7 -2
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
- package/_types/chains/definitions/turkchain.d.ts +53 -0
- package/_types/chains/definitions/turkchain.d.ts.map +1 -0
- package/_types/chains/definitions/zksync.d.ts +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -0
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/transports/fallback.d.ts.map +1 -1
- package/_types/errors/node.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +77 -4
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Gateway.d.ts +337 -0
- package/_types/tempo/Gateway.d.ts.map +1 -0
- package/_types/tempo/GatewayDecorator.d.ts +635 -0
- package/_types/tempo/GatewayDecorator.d.ts.map +1 -0
- package/_types/tempo/Relay.d.ts +1 -1
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +2 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/ai.d.ts +145 -0
- package/_types/tempo/actions/ai.d.ts.map +1 -0
- package/_types/tempo/actions/bucket.d.ts +210 -0
- package/_types/tempo/actions/bucket.d.ts.map +1 -0
- package/_types/tempo/actions/compute.d.ts +628 -0
- package/_types/tempo/actions/compute.d.ts.map +1 -0
- package/_types/tempo/actions/gateway.d.ts +25 -0
- package/_types/tempo/actions/gateway.d.ts.map +1 -0
- package/_types/tempo/actions/index.d.ts +10 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/kv.d.ts +167 -0
- package/_types/tempo/actions/kv.d.ts.map +1 -0
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +11 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/ndjson.d.ts +9 -0
- package/_types/tempo/internal/ndjson.d.ts.map +1 -0
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/utils.d.ts +8 -8
- package/_types/utils/abi/decodeEventLog.d.ts +13 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +24 -4
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/ccipTunnel.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/hash/toSignatureHash.d.ts +1 -1
- package/_types/utils/hash/toSignatureHash.d.ts.map +1 -1
- package/_types/utils/internal/http.d.ts +16 -0
- package/_types/utils/internal/http.d.ts.map +1 -0
- package/_types/utils/nonceManager.d.ts +15 -1
- package/_types/utils/nonceManager.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/rpc/socket.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
- package/actions/public/estimateGas.ts +12 -5
- package/actions/public/fillTransaction.ts +2 -0
- package/actions/public/getFilterChanges.ts +1 -0
- package/actions/public/getFilterLogs.ts +1 -0
- package/actions/public/watchBlockNumber.ts +11 -2
- package/actions/public/watchBlocks.ts +46 -14
- package/actions/public/watchContractEvent.ts +22 -4
- package/actions/public/watchEvent.ts +17 -1
- package/actions/wallet/prepareTransactionRequest.ts +6 -2
- package/actions/wallet/sendTransaction.ts +9 -3
- package/actions/wallet/sendTransactionSync.ts +74 -12
- package/chains/definitions/hashKeyChain.ts +4 -4
- package/chains/definitions/hashkeyChainTestnet.ts +4 -4
- package/chains/definitions/turkchain.ts +23 -0
- package/chains/definitions/zksync.ts +1 -1
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +6 -0
- package/clients/transports/fallback.ts +11 -0
- package/errors/node.ts +11 -5
- package/errors/typedData.ts +5 -2
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +5 -1
- package/tempo/Account.ts +202 -16
- package/tempo/Gateway.ts +477 -0
- package/tempo/GatewayDecorator.ts +909 -0
- package/tempo/Relay.ts +1 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/actions/ai.ts +250 -0
- package/tempo/actions/bucket.ts +324 -0
- package/tempo/actions/compute.ts +894 -0
- package/tempo/actions/gateway.ts +33 -0
- package/tempo/actions/index.ts +10 -0
- package/tempo/actions/kv.ts +229 -0
- package/tempo/chainConfig.ts +13 -15
- package/tempo/index.ts +12 -0
- package/tempo/internal/ndjson.ts +51 -0
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/utils/abi/decodeEventLog.ts +97 -10
- package/utils/abi/getAbiItem.ts +35 -5
- package/utils/abi/parseEventLogs.ts +48 -11
- package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
- package/utils/authorization/verifyAuthorization.ts +12 -7
- package/utils/buildRequest.ts +4 -0
- package/utils/ccip.ts +199 -33
- package/utils/ccipTunnel.ts +5 -1
- package/utils/ens/localBatchGatewayRequest.ts +82 -4
- package/utils/hash/toSignatureHash.ts +12 -2
- package/utils/internal/http.ts +92 -0
- package/utils/nonceManager.ts +16 -1
- package/utils/rpc/http.ts +12 -86
- package/utils/rpc/socket.ts +28 -15
- package/utils/transaction/assertRequest.ts +2 -2
- package/utils/transaction/assertTransaction.ts +2 -2
- package/utils/transaction/parseTransaction.ts +32 -7
- package/utils/typedData.ts +31 -8
- package/zksync/actions/finalizeWithdrawal.ts +5 -2
- package/zksync/actions/isWithdrawalFinalized.ts +5 -5
package/tempo/Relay.ts
CHANGED
|
@@ -450,7 +450,7 @@ export declare namespace feePayer {
|
|
|
450
450
|
url?: string | undefined
|
|
451
451
|
/** Only `true` authorizes sponsorship. Rejected fills fall back to sender-paid transactions. */
|
|
452
452
|
validate?: Sponsorship.Validate | undefined
|
|
453
|
-
/** Longest on-chain validity, in seconds, of a returned fee-payer signature. Fills without `validBefore` receive one; `eth_signRawTransaction` requires one. @default 3600 */
|
|
453
|
+
/** Longest on-chain validity, in seconds, of a returned fee-payer signature. Fills without `validBefore` receive one; `eth_signRawTransaction` requires one. Expiring nonce transactions are capped at `Transaction.expiringNonceMaxExpiry`. @default 3600 */
|
|
454
454
|
validity?: number | undefined
|
|
455
455
|
}
|
|
456
456
|
/** Result of a sponsorship policy check. */
|
package/tempo/Transaction.ts
CHANGED
|
@@ -207,6 +207,9 @@ export type TransactionSerializedFeePayer = `0x78${string}`
|
|
|
207
207
|
|
|
208
208
|
export type TransactionType = viem_TransactionType | 'tempo'
|
|
209
209
|
|
|
210
|
+
/** Longest distance, in seconds, between now and an expiring nonce transaction's `validBefore`. */
|
|
211
|
+
export const expiringNonceMaxExpiry = 300
|
|
212
|
+
|
|
210
213
|
export function getType(
|
|
211
214
|
transaction: Record<string, unknown>,
|
|
212
215
|
): Transaction['type'] {
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import * as Gateway from '../Gateway.js'
|
|
2
|
+
import * as Ndjson from '../internal/ndjson.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Embeds text with a Gateway model. Paid per request.
|
|
6
|
+
*
|
|
7
|
+
* @experimental
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
12
|
+
*
|
|
13
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
14
|
+
*
|
|
15
|
+
* const { embeddings } = await Actions.ai.embed(gateway, {
|
|
16
|
+
* input: ['hello world'],
|
|
17
|
+
* model: '@cf/baai/bge-m3',
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param gateway - Gateway connection.
|
|
22
|
+
* @param parameters - Parameters.
|
|
23
|
+
* @returns The embeddings and their shape.
|
|
24
|
+
*/
|
|
25
|
+
export async function embed(
|
|
26
|
+
gateway: Gateway.Gateway,
|
|
27
|
+
parameters: embed.Parameters,
|
|
28
|
+
): Promise<embed.ReturnValue> {
|
|
29
|
+
const { input, model, signal } = parameters
|
|
30
|
+
const response = await Gateway.request(gateway, {
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
input: typeof input === 'string' ? [input] : input,
|
|
33
|
+
model,
|
|
34
|
+
}),
|
|
35
|
+
path: '/ai/embed',
|
|
36
|
+
signal,
|
|
37
|
+
})
|
|
38
|
+
return (await response.json()) as embed.ReturnValue
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare namespace embed {
|
|
42
|
+
type Parameters = {
|
|
43
|
+
/** Text or texts to embed. */
|
|
44
|
+
input: string | readonly string[]
|
|
45
|
+
/** Embedding model. See `Gateway.getCapabilities`. */
|
|
46
|
+
model: string
|
|
47
|
+
/** Signal to abort the request. */
|
|
48
|
+
signal?: AbortSignal | undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnValue = {
|
|
52
|
+
/** One embedding per input. */
|
|
53
|
+
embeddings: readonly (readonly number[])[]
|
|
54
|
+
/** Shape of `embeddings`. */
|
|
55
|
+
shape: readonly number[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type ErrorType = Gateway.request.ErrorType
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Generates text with a Gateway model. Paid per request.
|
|
63
|
+
*
|
|
64
|
+
* Pass either `prompt` or `messages`.
|
|
65
|
+
*
|
|
66
|
+
* @experimental
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
71
|
+
*
|
|
72
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
73
|
+
*
|
|
74
|
+
* const { text } = await Actions.ai.generateText(gateway, {
|
|
75
|
+
* model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast',
|
|
76
|
+
* prompt: 'Describe this app in one sentence.',
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param gateway - Gateway connection.
|
|
81
|
+
* @param parameters - Parameters.
|
|
82
|
+
* @returns The generated text and token usage.
|
|
83
|
+
*/
|
|
84
|
+
export async function generateText(
|
|
85
|
+
gateway: Gateway.Gateway,
|
|
86
|
+
parameters: generateText.Parameters,
|
|
87
|
+
): Promise<generateText.ReturnValue> {
|
|
88
|
+
const { maxOutputTokens, messages, model, prompt, signal } = parameters
|
|
89
|
+
const response = await Gateway.request(gateway, {
|
|
90
|
+
body: JSON.stringify({ maxOutputTokens, messages, model, prompt }),
|
|
91
|
+
path: '/ai/generate',
|
|
92
|
+
signal,
|
|
93
|
+
})
|
|
94
|
+
type Body = {
|
|
95
|
+
text: string
|
|
96
|
+
usage: {
|
|
97
|
+
completion_tokens?: number | undefined
|
|
98
|
+
prompt_tokens?: number | undefined
|
|
99
|
+
total_tokens?: number | undefined
|
|
100
|
+
} | null
|
|
101
|
+
}
|
|
102
|
+
const { text, usage } = (await response.json()) as Body
|
|
103
|
+
return {
|
|
104
|
+
text,
|
|
105
|
+
usage: usage
|
|
106
|
+
? {
|
|
107
|
+
inputTokens: usage.prompt_tokens,
|
|
108
|
+
outputTokens: usage.completion_tokens,
|
|
109
|
+
totalTokens: usage.total_tokens,
|
|
110
|
+
}
|
|
111
|
+
: undefined,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export declare namespace generateText {
|
|
116
|
+
type Message = {
|
|
117
|
+
/** Message text. */
|
|
118
|
+
content: string
|
|
119
|
+
/** Message author. */
|
|
120
|
+
role: 'assistant' | 'system' | 'user'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type Parameters = {
|
|
124
|
+
/**
|
|
125
|
+
* Maximum generated tokens. The request reserves their cost and refunds
|
|
126
|
+
* what is not generated.
|
|
127
|
+
*/
|
|
128
|
+
maxOutputTokens?: number | undefined
|
|
129
|
+
/** Generation model. See `Gateway.getCapabilities`. */
|
|
130
|
+
model: string
|
|
131
|
+
/** Signal to abort the request. */
|
|
132
|
+
signal?: AbortSignal | undefined
|
|
133
|
+
} & (
|
|
134
|
+
| {
|
|
135
|
+
/** Conversation to continue. */
|
|
136
|
+
messages: readonly Message[]
|
|
137
|
+
prompt?: undefined
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
messages?: undefined
|
|
141
|
+
/** Prompt to complete. */
|
|
142
|
+
prompt: string
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
type ReturnValue = {
|
|
147
|
+
/** Generated text. */
|
|
148
|
+
text: string
|
|
149
|
+
/** Token usage, when the model reports it. */
|
|
150
|
+
usage:
|
|
151
|
+
| {
|
|
152
|
+
/** Prompt tokens. */
|
|
153
|
+
inputTokens: number | undefined
|
|
154
|
+
/** Generated tokens. */
|
|
155
|
+
outputTokens: number | undefined
|
|
156
|
+
/** Total tokens. */
|
|
157
|
+
totalTokens: number | undefined
|
|
158
|
+
}
|
|
159
|
+
| undefined
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type ErrorType = Gateway.request.ErrorType
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Generates text with a Gateway model and yields it as it is produced. Paid
|
|
167
|
+
* per request.
|
|
168
|
+
*
|
|
169
|
+
* @experimental
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
174
|
+
*
|
|
175
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
176
|
+
*
|
|
177
|
+
* for await (const event of Actions.ai.streamText(gateway, {
|
|
178
|
+
* model: '@cf/zai-org/glm-5.3',
|
|
179
|
+
* prompt: 'Write a haiku about Tempo.',
|
|
180
|
+
* })) {
|
|
181
|
+
* if (event.type === 'text') process.stdout.write(event.delta)
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @param gateway - Gateway connection.
|
|
186
|
+
* @param parameters - Parameters.
|
|
187
|
+
* @returns Text and reasoning deltas, then usage.
|
|
188
|
+
*/
|
|
189
|
+
export async function* streamText(
|
|
190
|
+
gateway: Gateway.Gateway,
|
|
191
|
+
parameters: streamText.Parameters,
|
|
192
|
+
): AsyncGenerator<streamText.Event> {
|
|
193
|
+
const { maxOutputTokens, messages, model, prompt, signal } = parameters
|
|
194
|
+
const response = await Gateway.request(gateway, {
|
|
195
|
+
body: JSON.stringify({
|
|
196
|
+
maxOutputTokens,
|
|
197
|
+
messages,
|
|
198
|
+
model,
|
|
199
|
+
prompt,
|
|
200
|
+
stream: true,
|
|
201
|
+
}),
|
|
202
|
+
path: '/ai/generate',
|
|
203
|
+
signal,
|
|
204
|
+
})
|
|
205
|
+
type Raw =
|
|
206
|
+
| { delta: string; type: 'reasoning' | 'text' }
|
|
207
|
+
| {
|
|
208
|
+
type: 'done'
|
|
209
|
+
usage: {
|
|
210
|
+
completion_tokens?: number | undefined
|
|
211
|
+
prompt_tokens?: number | undefined
|
|
212
|
+
total_tokens?: number | undefined
|
|
213
|
+
} | null
|
|
214
|
+
}
|
|
215
|
+
for await (const event of Ndjson.read<Raw>(response)) {
|
|
216
|
+
if (event.type !== 'done') {
|
|
217
|
+
yield event
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
yield {
|
|
221
|
+
type: 'done',
|
|
222
|
+
usage: event.usage
|
|
223
|
+
? {
|
|
224
|
+
inputTokens: event.usage.prompt_tokens,
|
|
225
|
+
outputTokens: event.usage.completion_tokens,
|
|
226
|
+
totalTokens: event.usage.total_tokens,
|
|
227
|
+
}
|
|
228
|
+
: undefined,
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export declare namespace streamText {
|
|
234
|
+
type Parameters = generateText.Parameters
|
|
235
|
+
|
|
236
|
+
type Event =
|
|
237
|
+
| {
|
|
238
|
+
/** Text produced since the previous event. */
|
|
239
|
+
delta: string
|
|
240
|
+
/** `text` for the answer, `reasoning` for the model's reasoning. */
|
|
241
|
+
type: 'reasoning' | 'text'
|
|
242
|
+
}
|
|
243
|
+
| {
|
|
244
|
+
type: 'done'
|
|
245
|
+
/** Token usage, when the model reports it. */
|
|
246
|
+
usage: generateText.ReturnValue['usage']
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
type ErrorType = Gateway.request.ErrorType
|
|
250
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import * as Gateway from '../Gateway.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metadata of an object in a Gateway bucket.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export type Metadata = {
|
|
9
|
+
/** Content type. */
|
|
10
|
+
contentType: string | null
|
|
11
|
+
/** Entity tag. */
|
|
12
|
+
etag: string
|
|
13
|
+
/** Expiry as a Unix timestamp in milliseconds. */
|
|
14
|
+
expiresAt: number
|
|
15
|
+
/** Object key. */
|
|
16
|
+
key: string
|
|
17
|
+
/** Size in bytes. */
|
|
18
|
+
size: number
|
|
19
|
+
/** Upload time as a Unix timestamp in milliseconds. */
|
|
20
|
+
uploadedAt: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Deletes an object from the app's bucket. Paid per request.
|
|
25
|
+
*
|
|
26
|
+
* @experimental
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
31
|
+
*
|
|
32
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
33
|
+
*
|
|
34
|
+
* await Actions.bucket.delete(gateway, { key: 'notes/today.txt' })
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param gateway - Gateway connection.
|
|
38
|
+
* @param parameters - Parameters.
|
|
39
|
+
* @returns Whether the request succeeded.
|
|
40
|
+
*/
|
|
41
|
+
// biome-ignore lint/correctness/noUnusedVariables: exported as delete
|
|
42
|
+
async function delete_(
|
|
43
|
+
gateway: Gateway.Gateway,
|
|
44
|
+
parameters: delete_.Parameters,
|
|
45
|
+
): Promise<delete_.ReturnValue> {
|
|
46
|
+
const { key, signal } = parameters
|
|
47
|
+
const response = await Gateway.request(gateway, {
|
|
48
|
+
body: JSON.stringify({ key }),
|
|
49
|
+
path: '/bucket/delete',
|
|
50
|
+
signal,
|
|
51
|
+
})
|
|
52
|
+
return (await response.json()) as delete_.ReturnValue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare namespace delete_ {
|
|
56
|
+
type Parameters = {
|
|
57
|
+
/** Object key. */
|
|
58
|
+
key: string
|
|
59
|
+
/** Signal to abort the request. */
|
|
60
|
+
signal?: AbortSignal | undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type ReturnValue = {
|
|
64
|
+
/** Whether the request succeeded. */
|
|
65
|
+
deleted: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type ErrorType = Gateway.request.ErrorType
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { delete_ as delete }
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reads an object from the app's bucket as a stream. Returns `null` when the
|
|
75
|
+
* object does not exist or expired. Paid per request.
|
|
76
|
+
*
|
|
77
|
+
* @experimental
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
82
|
+
*
|
|
83
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
84
|
+
*
|
|
85
|
+
* const object = await Actions.bucket.get(gateway, { key: 'notes/today.txt' })
|
|
86
|
+
* const text = object ? await new Response(object.body).text() : null
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param gateway - Gateway connection.
|
|
90
|
+
* @param parameters - Parameters.
|
|
91
|
+
* @returns The object body and metadata, or `null`.
|
|
92
|
+
*/
|
|
93
|
+
export async function get(
|
|
94
|
+
gateway: Gateway.Gateway,
|
|
95
|
+
parameters: get.Parameters,
|
|
96
|
+
): Promise<get.ReturnValue> {
|
|
97
|
+
const { key, signal } = parameters
|
|
98
|
+
const response = await Gateway.request(gateway, {
|
|
99
|
+
body: JSON.stringify({ key }),
|
|
100
|
+
path: '/bucket/get',
|
|
101
|
+
signal,
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
if (error instanceof Gateway.RequestError && error.code === 'not_found')
|
|
104
|
+
return null
|
|
105
|
+
throw error
|
|
106
|
+
})
|
|
107
|
+
if (!response?.body) return null
|
|
108
|
+
|
|
109
|
+
const { headers } = response
|
|
110
|
+
return {
|
|
111
|
+
body: response.body,
|
|
112
|
+
contentType: headers.get('content-type'),
|
|
113
|
+
etag: headers.get('etag'),
|
|
114
|
+
expiresAt: Number(headers.get('gateway-expires-at')),
|
|
115
|
+
key,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare namespace get {
|
|
120
|
+
type Parameters = {
|
|
121
|
+
/** Object key. */
|
|
122
|
+
key: string
|
|
123
|
+
/** Signal to abort the request. */
|
|
124
|
+
signal?: AbortSignal | undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type ReturnValue = {
|
|
128
|
+
/** Object bytes. */
|
|
129
|
+
body: ReadableStream<Uint8Array>
|
|
130
|
+
/** Content type. */
|
|
131
|
+
contentType: string | null
|
|
132
|
+
/** Entity tag. */
|
|
133
|
+
etag: string | null
|
|
134
|
+
/** Expiry as a Unix timestamp in milliseconds. */
|
|
135
|
+
expiresAt: number
|
|
136
|
+
/** Object key. */
|
|
137
|
+
key: string
|
|
138
|
+
} | null
|
|
139
|
+
|
|
140
|
+
type ErrorType = Gateway.request.ErrorType
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Reads the metadata of an object in the app's bucket. Returns `null` when the
|
|
145
|
+
* object does not exist or expired. Paid per request.
|
|
146
|
+
*
|
|
147
|
+
* @experimental
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
152
|
+
*
|
|
153
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
154
|
+
*
|
|
155
|
+
* const metadata = await Actions.bucket.head(gateway, { key: 'notes/today.txt' })
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param gateway - Gateway connection.
|
|
159
|
+
* @param parameters - Parameters.
|
|
160
|
+
* @returns The object metadata, or `null`.
|
|
161
|
+
*/
|
|
162
|
+
export async function head(
|
|
163
|
+
gateway: Gateway.Gateway,
|
|
164
|
+
parameters: head.Parameters,
|
|
165
|
+
): Promise<head.ReturnValue> {
|
|
166
|
+
const { key, signal } = parameters
|
|
167
|
+
const response = await Gateway.request(gateway, {
|
|
168
|
+
body: JSON.stringify({ key }),
|
|
169
|
+
path: '/bucket/head',
|
|
170
|
+
signal,
|
|
171
|
+
})
|
|
172
|
+
return (await response.json()) as head.ReturnValue
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export declare namespace head {
|
|
176
|
+
type Parameters = {
|
|
177
|
+
/** Object key. */
|
|
178
|
+
key: string
|
|
179
|
+
/** Signal to abort the request. */
|
|
180
|
+
signal?: AbortSignal | undefined
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type ReturnValue = Metadata | null
|
|
184
|
+
|
|
185
|
+
type ErrorType = Gateway.request.ErrorType
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Lists objects in the app's bucket by key prefix. Paid per request.
|
|
190
|
+
*
|
|
191
|
+
* @experimental
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
196
|
+
*
|
|
197
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
198
|
+
*
|
|
199
|
+
* const { cursor, objects } = await Actions.bucket.list(gateway, {
|
|
200
|
+
* prefix: 'notes/',
|
|
201
|
+
* })
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @param gateway - Gateway connection.
|
|
205
|
+
* @param parameters - Parameters.
|
|
206
|
+
* @returns A page of object metadata and the next cursor.
|
|
207
|
+
*/
|
|
208
|
+
export async function list(
|
|
209
|
+
gateway: Gateway.Gateway,
|
|
210
|
+
parameters: list.Parameters = {},
|
|
211
|
+
): Promise<list.ReturnValue> {
|
|
212
|
+
const { cursor, limit, prefix, signal } = parameters
|
|
213
|
+
const response = await Gateway.request(gateway, {
|
|
214
|
+
body: JSON.stringify({ cursor, limit, prefix }),
|
|
215
|
+
path: '/bucket/list',
|
|
216
|
+
signal,
|
|
217
|
+
})
|
|
218
|
+
return (await response.json()) as list.ReturnValue
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export declare namespace list {
|
|
222
|
+
type Parameters = {
|
|
223
|
+
/** Cursor from a previous page. */
|
|
224
|
+
cursor?: string | undefined
|
|
225
|
+
/** Maximum objects per page. */
|
|
226
|
+
limit?: number | undefined
|
|
227
|
+
/** Key prefix. */
|
|
228
|
+
prefix?: string | undefined
|
|
229
|
+
/** Signal to abort the request. */
|
|
230
|
+
signal?: AbortSignal | undefined
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
type ReturnValue = {
|
|
234
|
+
/** Cursor of the next page, or `null` on the last page. */
|
|
235
|
+
cursor: string | null
|
|
236
|
+
/** Objects on this page. */
|
|
237
|
+
objects: readonly Metadata[]
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
type ErrorType = Gateway.request.ErrorType
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Writes an object to the app's bucket for a retention period. Paid per
|
|
245
|
+
* request.
|
|
246
|
+
*
|
|
247
|
+
* @experimental
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
252
|
+
*
|
|
253
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
254
|
+
*
|
|
255
|
+
* const metadata = await Actions.bucket.put(gateway, {
|
|
256
|
+
* key: 'notes/today.txt',
|
|
257
|
+
* retention: 86_400,
|
|
258
|
+
* value: new Blob(['hello'], { type: 'text/plain' }),
|
|
259
|
+
* })
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param gateway - Gateway connection.
|
|
263
|
+
* @param parameters - Parameters.
|
|
264
|
+
* @returns The object metadata.
|
|
265
|
+
*/
|
|
266
|
+
export async function put(
|
|
267
|
+
gateway: Gateway.Gateway,
|
|
268
|
+
parameters: put.Parameters,
|
|
269
|
+
): Promise<put.ReturnValue> {
|
|
270
|
+
const { key, retention, signal, value } = parameters
|
|
271
|
+
const body =
|
|
272
|
+
typeof value === 'string' ? new TextEncoder().encode(value) : value
|
|
273
|
+
const size = isBlob(body) ? body.size : body.byteLength
|
|
274
|
+
const contentType =
|
|
275
|
+
parameters.contentType ??
|
|
276
|
+
(typeof value === 'string' ? 'text/plain;charset=utf-8' : undefined) ??
|
|
277
|
+
(isBlob(value) && value.type ? value.type : undefined) ??
|
|
278
|
+
'application/octet-stream'
|
|
279
|
+
const response = await Gateway.request(gateway, {
|
|
280
|
+
body: body as BodyInit,
|
|
281
|
+
headers: {
|
|
282
|
+
'content-type': contentType,
|
|
283
|
+
'gateway-key': key,
|
|
284
|
+
'gateway-retention': String(retention),
|
|
285
|
+
'gateway-size': String(size),
|
|
286
|
+
},
|
|
287
|
+
path: '/bucket/put',
|
|
288
|
+
signal,
|
|
289
|
+
})
|
|
290
|
+
return (await response.json()) as put.ReturnValue
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export declare namespace put {
|
|
294
|
+
type Parameters = {
|
|
295
|
+
/**
|
|
296
|
+
* Content type.
|
|
297
|
+
*
|
|
298
|
+
* @default The Blob's type, `text/plain;charset=utf-8` for strings, or `application/octet-stream`.
|
|
299
|
+
*/
|
|
300
|
+
contentType?: string | undefined
|
|
301
|
+
/** Object key. */
|
|
302
|
+
key: string
|
|
303
|
+
/** Retention in seconds. The object expires afterwards. */
|
|
304
|
+
retention: number
|
|
305
|
+
/** Signal to abort the request. */
|
|
306
|
+
signal?: AbortSignal | undefined
|
|
307
|
+
/** Object bytes. */
|
|
308
|
+
value: Blob | Uint8Array | ArrayBuffer | string
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
type ReturnValue = Metadata
|
|
312
|
+
|
|
313
|
+
type ErrorType = Gateway.request.ErrorType
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Detects a `Blob` without `instanceof`, so ones from another realm count. */
|
|
317
|
+
function isBlob(value: unknown): value is Blob {
|
|
318
|
+
return (
|
|
319
|
+
typeof value === 'object' &&
|
|
320
|
+
value !== null &&
|
|
321
|
+
typeof (value as Blob).arrayBuffer === 'function' &&
|
|
322
|
+
typeof (value as Blob).size === 'number'
|
|
323
|
+
)
|
|
324
|
+
}
|