File
Blob: src/workerd/io/actor-storage.c++
| 1 | // Copyright (c) 2022-2023 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | #include "actor-storage.h" |
| 6 | |
| 7 | #include <workerd/io/actor-storage.capnp.h> |
| 8 | #include <workerd/jsg/exception.h> |
| 9 | |
| 10 | namespace workerd { |
| 11 | void ActorStorageLimits::checkMaxKeySize(kj::StringPtr key) { |
| 12 | // It's tempting to put the key in this message, but that key could be surprisingly large so let's |
| 13 | // return a simple message. |
| 14 | JSG_REQUIRE(key.size() <= MAX_KEY_SIZE, RangeError, |
| 15 | kj::str("Keys cannot be larger than ", MAX_KEY_SIZE, " bytes. ", "A key of size ", key.size(), |
| 16 | " was provided.")); |
| 17 | } |
| 18 | |
| 19 | void ActorStorageLimits::checkMaxValueSize(kj::StringPtr, kj::ArrayPtr<const kj::byte> value) { |
| 20 | // It's tempting to put the key in this message, but that key could be surprisingly large so let's |
| 21 | // return a simple message. |
| 22 | JSG_REQUIRE(value.size() <= ENFORCED_MAX_VALUE_SIZE, RangeError, |
| 23 | kj::str("Values cannot be larger than ", ADVERTISED_MAX_VALUE_SIZE, " bytes. ", |
| 24 | "A value of size ", value.size(), " was provided.")); |
| 25 | } |
| 26 | |
| 27 | void ActorStorageLimits::checkMaxPairsCount(size_t count) { |
| 28 | JSG_REQUIRE(count <= rpc::ActorStorage::MAX_KEYS, RangeError, |
| 29 | kj::str("Maximum number of key value pairs is ", rpc::ActorStorage::MAX_KEYS, ". ", count, |
| 30 | " pairs were provided.")); |
| 31 | } |
| 32 | |
| 33 | } // namespace workerd |