c
Deno.AtomicOperation
An operation on a [`Deno.Kv`](./././~/Deno.Kv) that can be performed
atomically. Atomic operations do not auto-commit, and must be committed
explicitly by calling the `commit` method.
Atomic operations can be used to perform multiple mutations on the KV store
in a single atomic transaction. They can also be used to perform
conditional mutations by specifying one or more
[`Deno.AtomicCheck`](./././~/Deno.AtomicCheck)s that ensure that a mutation is only performed
if the key-value pair in the KV has a specific versionstamp. If any of the
checks fail, the entire operation will fail and no mutations will be made.
The ordering of mutations is guaranteed to be the same as the ordering of
the mutations specified in the operation. Checks are performed before any
mutations are performed. The ordering of checks is unobservable.
Atomic operations can be used to implement optimistic locking, where a
mutation is only performed if the key-value pair in the KV store has not
been modified since the last read. This can be done by specifying a check
that ensures that the versionstamp of the key-value pair matches the
versionstamp that was read. If the check fails, the mutation will not be
performed and the operation will fail. One can then retry the read-modify-
write operation in a loop until it succeeds.
The `commit` method of an atomic operation returns a value indicating
whether checks passed and mutations were performed. If the operation failed
because of a failed check, the return value will be a
[`Deno.KvCommitError`](./././~/Deno.KvCommitError) with an `ok: false` property. If the
operation failed for any other reason (storage error, invalid value, etc.),
an exception will be thrown. If the operation succeeded, the return value
will be a [`Deno.KvCommitResult`](./././~/Deno.KvCommitResult) object with a `ok: true` property
and the versionstamp of the value committed to KV.
c
Deno.Kv
A key-value database that can be used to store and retrieve data.
Data is stored as key-value pairs, where the key is a [`Deno.KvKey`](./././~/Deno.KvKey)
and the value is an arbitrary structured-serializable JavaScript value.
Keys are ordered lexicographically as described in the documentation for
[`Deno.KvKey`](./././~/Deno.KvKey). Keys are unique within a database, and the last
value set for a given key is the one that is returned when reading the
key. Keys can be deleted from the database, in which case they will no
longer be returned when reading keys.
Values can be any structured-serializable JavaScript value (objects,
arrays, strings, numbers, etc.). The special value [`Deno.KvU64`](./././~/Deno.KvU64)
can be used to store 64-bit unsigned integers in the database. This special
value can not be nested within other objects or arrays. In addition to the
regular database mutation operations, the unsigned 64-bit integer value
also supports `sum`, `max`, and `min` mutations.
Keys are versioned on write by assigning the key an ever-increasing
"versionstamp". The versionstamp represents the version of a key-value pair
in the database at some point in time, and can be used to perform
transactional operations on the database without requiring any locking.
This is enabled by atomic operations, which can have conditions that ensure
that the operation only succeeds if the versionstamp of the key-value pair
matches an expected versionstamp.
Keys have a maximum length of 2048 bytes after serialization. Values have a
maximum length of 64 KiB after serialization. Serialization of both keys
and values is somewhat opaque, but one can usually assume that the
serialization of any value is about the same length as the resulting string
of a JSON serialization of that same value. If theses limits are exceeded,
an exception will be thrown.
c
Deno.KvListIterator
An iterator over a range of data entries in a [`Deno.Kv`](./././~/Deno.Kv).
The cursor getter returns the cursor that can be used to resume the
iteration from the current position in the future.
c
Deno.KvU64
Wrapper type for 64-bit unsigned integers for use as values in a
[`Deno.Kv`](./././~/Deno.Kv).
f
Deno.cron
Create a cron job that will periodically execute the provided handler
callback based on the specified schedule.
```ts
Deno.cron("sample cron", "20 * * * *", () => {
console.log("cron job executed");
});
```
```ts
Deno.cron("sample cron", { hour: { every: 6 } }, () => {
console.log("cron job executed");
});
```
`schedule` can be a string in the Unix cron format or in JSON format
as specified by interface `CronSchedule`, where time is specified
using UTC time zone.
f
Deno.openKv
Open a new [`Deno.Kv`](./././~/Deno.Kv) connection to persist data.
When a path is provided, the database will be persisted to disk at that
path. Read and write access to the file is required.
When no path is provided, the database will be opened in a default path for
the current script. This location is persistent across script runs and is
keyed on the origin storage key (the same key that is used to determine
`localStorage` persistence). More information about the origin storage key
can be found in the Deno Manual.
I
Deno.AtomicCheck
A check to perform as part of a [`Deno.AtomicOperation`](./././~/Deno.AtomicOperation). The check
will fail if the versionstamp for the key-value pair in the KV store does
not match the given versionstamp. A check with a `null` versionstamp checks
that the key-value pair does not currently exist in the KV store.
I
Deno.CronSchedule
CronSchedule is the interface used for JSON format
cron `schedule`.
I
I
I
Deno.KvEntry
A versioned pair of key and value in a [`Deno.Kv`](./././~/Deno.Kv).
The `versionstamp` is a string that represents the current version of the
key-value pair. It can be used to perform atomic operations on the KV store
by passing it to the `check` method of a [`Deno.AtomicOperation`](./././~/Deno.AtomicOperation).
I
Deno.KvListOptions
Options for listing key-value pairs in a [`Deno.Kv`](./././~/Deno.Kv).
T
Deno.CronScheduleExpression
CronScheduleExpression is used as the type of `minute`, `hour`,
`dayOfMonth`, `month`, and `dayOfWeek` in `CronSchedule`.
T
Deno.KvConsistencyLevel
Consistency level of a KV operation.
- `strong` - This operation must be strongly-consistent.
- `eventual` - Eventually-consistent behavior is allowed.
T
Deno.KvEntryMaybe
An optional versioned pair of key and value in a [`Deno.Kv`](./././~/Deno.Kv).
This is the same as a `KvEntry`, but the `value` and `versionstamp`
fields may be `null` if no value exists for the given key in the KV store.
T
Deno.KvKey
A key to be persisted in a [`Deno.Kv`](./././~/Deno.Kv). A key is a sequence
of [`Deno.KvKeyPart`](./././~/Deno.KvKeyPart)s.
Keys are ordered lexicographically by their parts. The first part is the
most significant, and the last part is the least significant. The order of
the parts is determined by both the type and the value of the part. The
relative significance of the types can be found in documentation for the
[`Deno.KvKeyPart`](./././~/Deno.KvKeyPart) type.
Keys have a maximum size of 2048 bytes serialized. If the size of the key
exceeds this limit, an error will be thrown on the operation that this key
was passed to.
T
Deno.KvKeyPart
A single part of a [`Deno.KvKey`](./././~/Deno.KvKey). Parts are ordered
lexicographically, first by their type, and within a given type by their
value.
The ordering of types is as follows:
1. `Uint8Array`
2. `string`
3. `number`
4. `bigint`
5. `boolean`
Within a given type, the ordering is as follows:
- `Uint8Array` is ordered by the byte ordering of the array
- `string` is ordered by the byte ordering of the UTF-8 encoding of the
string
- `number` is ordered following this pattern: `-NaN`
< `-Infinity` < `-100.0` < `-1.0` < -`0.5` < `-0.0` < `0.0` < `0.5`
< `1.0` < `100.0` < `Infinity` < `NaN`
- `bigint` is ordered by mathematical ordering, with the largest negative
number being the least first value, and the largest positive number
being the last value
- `boolean` is ordered by `false` < `true`
This means that the part `1.0` (a number) is ordered before the part `2.0`
(also a number), but is greater than the part `0n` (a bigint), because
`1.0` is a number and `0n` is a bigint, and type ordering has precedence
over the ordering of values within a type.
T
Deno.KvListSelector
A selector that selects the range of data returned by a list operation on a
[`Deno.Kv`](./././~/Deno.Kv).
The selector can either be a prefix selector or a range selector. A prefix
selector selects all keys that start with the given prefix (optionally
starting at a given key). A range selector selects all keys that are
lexicographically between the given start and end keys.
T
Deno.KvMutation
A mutation to a key in a [`Deno.Kv`](./././~/Deno.Kv). A mutation is a
combination of a key, a value, and a type. The type determines how the
mutation is applied to the key.
- `set` - Sets the value of the key to the given value, overwriting any
existing value. Optionally an `expireIn` option can be specified to
set a time-to-live (TTL) for the key. The TTL is specified in
milliseconds, and the key will be deleted from the database at earliest
after the specified number of milliseconds have elapsed. Once the
specified duration has passed, the key may still be visible for some
additional time. If the `expireIn` option is not specified, the key will
not expire.
- `delete` - Deletes the key from the database. The mutation is a no-op if
the key does not exist.
- `sum` - Adds the given value to the existing value of the key. Both the
value specified in the mutation, and any existing value must be of type
`Deno.KvU64`. If the key does not exist, the value is set to the given
value (summed with 0). If the result of the sum overflows an unsigned
64-bit integer, the result is wrapped around.
- `max` - Sets the value of the key to the maximum of the existing value
and the given value. Both the value specified in the mutation, and any
existing value must be of type `Deno.KvU64`. If the key does not exist,
the value is set to the given value.
- `min` - Sets the value of the key to the minimum of the existing value
and the given value. Both the value specified in the mutation, and any
existing value must be of type `Deno.KvU64`. If the key does not exist,
the value is set to the given value.