Skip to content

Commit 01a4729

Browse files
authored
feat!: Rename Object Store and related APIs to KV Store (#476)
1 parent 1ce77fa commit 01a4729

File tree

35 files changed

+735
-696
lines changed

35 files changed

+735
-696
lines changed

.github/workflows/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defaults:
1010
run:
1111
shell: bash
1212
env:
13-
viceroy_version: 0.3.5
13+
viceroy_version: 0.4.4
1414
wasm-tools_version: 1.0.28
1515

1616
jobs:
@@ -129,7 +129,7 @@ jobs:
129129
matrix:
130130
include:
131131
- crate: viceroy
132-
version: 0.3.5 # Note: workflow-level env vars can't be used in matrix definitions
132+
version: 0.4.4 # Note: workflow-level env vars can't be used in matrix definitions
133133
options: ""
134134
- crate: wasm-tools
135135
version: 1.0.28 # Note: workflow-level env vars can't be used in matrix definitions
@@ -237,7 +237,7 @@ jobs:
237237
- log
238238
- missing-backend
239239
- multiple-set-cookie
240-
- object-store
240+
- kv-store
241241
- random
242242
- react-byob
243243
- regex
@@ -391,7 +391,7 @@ jobs:
391391
- 'geoip'
392392
- 'hello-world'
393393
- 'multiple-set-cookie'
394-
- 'object-store'
394+
- 'kv-store'
395395
- 'react-byob'
396396
- 'request-clone'
397397
- 'request-headers'

documentation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ This command generates static content into the `build` directory and can be serv
3030
$ yarn deploy
3131
```
3232

33-
This command will run `yarn build` and then will upload the website to Fastly Object Store and deploy the application to Fastly Compute@Edge.
33+
This command will run `yarn build` and then will upload the website to Fastly KV Store and deploy the application to Fastly Compute@Edge.

documentation/app/fastly.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ service_id = "1B3wrEgiLdTaCjsmK5Jq25"
1313

1414
[local_server]
1515

16-
[local_server.object_store]
16+
[local_server.kv_stores]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# `KVStore()`
8+
9+
The **`KVStore` constructor** lets you connect your Compute@Edge application to a Fastly KV store.
10+
11+
A Fastly KV store is a persistent, globally consistent key-value store. See [Data stores for Fastly services](https://developer.fastly.com/learning/concepts/kv-stores/#kv-stores) for initialization and usage details.
12+
13+
>**Note**: Can only be used when processing requests, not during build-time initialization.
14+
15+
## Syntax
16+
17+
```js
18+
new KVStore(name)
19+
```
20+
21+
> **Note:** `KVStore()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).
22+
23+
### Parameters
24+
25+
- `name` _: string_
26+
- The Fastly KV store which should be associated with this KVStore instance
27+
28+
### Return value
29+
30+
A new `KVStore` object.
31+
32+
### Exceptions
33+
34+
- `TypeError`
35+
- Thrown if no KV Store exists with the provided name
36+
- Thrown if the provided name is longer than 255 in length
37+
- Thrown if the provided name is an empty string
38+
- Thrown if the provided name does not start with an ascii alphabetical character
39+
- Thrown if the provided name contains control characters `(\u0000-\u001F)`
40+
41+
## Examples
42+
43+
In this example we connect to an KV Store named `'files'` and save an entry to the store under the key `'hello'` and then read back the value and return it to the client.
44+
45+
```js
46+
/// <reference types="@fastly/js-compute" />
47+
48+
import { KVStore } from "fastly:kv-store";
49+
50+
async function app(event) {
51+
const files = new KVStore('files')
52+
53+
await files.put('hello', 'world')
54+
55+
const entry = await files.get('hello')
56+
57+
return new Response(await entry.text())
58+
}
59+
60+
addEventListener("fetch", (event) => event.respondWith(app(event)))
61+
62+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# KVStore.prototype.get
8+
9+
**get**(): `string`
10+
11+
Gets the value associated with the key `key` in the KV store.
12+
13+
## Syntax
14+
15+
```js
16+
get(key)
17+
```
18+
19+
### Parameters
20+
21+
- `key` _: string_
22+
- The key to retrieve from within the KV-store.
23+
24+
### Return value
25+
26+
If the key does not exist in the KV store, this returns a `Promise` which resolves with `null`.
27+
28+
If the key does exist in the KV store, this returns a `Promise` which resolves with an `KVStoreEntry`.
29+
30+
## Description
31+
32+
Send the given message, converted to a string, to this KVStore instance's endpoint.
33+
34+
The `get()` method requires its `this` value to be a [`KVStore`](../KVStore.mdx) object.
35+
36+
If the `this` value does not inherit from `KVStore.prototype`, a [`TypeError`](../../../globals/TypeError/TypeError.mdx) is thrown.
37+
38+
### Exceptions
39+
40+
- `TypeError`
41+
- If the provided `key`:
42+
- Is any of the strings `""`, `"."`, or `".."`
43+
- Starts with the string `".well-known/acme-challenge/"`
44+
- Contains any of the characters `"#?*[]\n\r"`
45+
- Is longer than 1024 characters
46+
47+
## Examples
48+
49+
In this example we connect to an KV Store named `'files'` and save an entry to the store under the key `'hello'` and then read back the value and return it to the client.
50+
51+
```js
52+
/// <reference types="@fastly/js-compute" />
53+
54+
import { KVStore } from "fastly:kv-store";
55+
56+
async function app(event) {
57+
const files = new KVStore('files')
58+
59+
await files.put('hello', 'world')
60+
61+
const entry = await files.get('hello')
62+
63+
return new Response(await entry.text())
64+
}
65+
66+
addEventListener("fetch", (event) => event.respondWith(app(event)))
67+
68+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# KVStore.prototype.put
8+
9+
The **`put()`** method stores a `value` into the KV store under a `key`.
10+
11+
> **Note**: KV stores are eventually consistent, this means that the updated contents associated with the key `key` may not be available to read from all edge locations immediately and some edge locations may continue returning the previous contents associated with the key.
12+
13+
## Syntax
14+
15+
```js
16+
put(key, value)
17+
```
18+
19+
### Parameters
20+
21+
- `key` _: string_
22+
- The key to store the supplied value under within the KV store.
23+
- `value` _: ArrayBuffer | TypedArray | DataView| ReadableStream | URLSearchParams | String | string literal_
24+
- The value to store within the KV store.
25+
26+
### Return value
27+
28+
Returns a `Promise` which resolves with `undefined` when the provided `value` has been written into the KV store.
29+
30+
## Description
31+
32+
Stores the supplied `value` into the KV store under the supplied `key`.
33+
34+
The `put()` method requires its `this` value to be a [`KVStore`](../KVStore.mdx) object.
35+
36+
If the `this` value does not inherit from `KVStore.prototype`, a [`TypeError`](../../../globals/TypeError/TypeError.mdx) is thrown.
37+
38+
### Exceptions
39+
40+
- `TypeError`
41+
- If the provided `key`:
42+
- Is any of the strings `""`, `"."`, or `".."`
43+
- Starts with the string `".well-known/acme-challenge/"`
44+
- Contains any of the characters `"#?*[]\n\r"`
45+
- Is longer than 1024 characters
46+
47+
## Examples
48+
49+
In this example we connect to an KV Store named `'files'` and save an entry to the store under the key `'hello'` and then read back the value and return it to the client.
50+
51+
```js
52+
/// <reference types="@fastly/js-compute" />
53+
54+
import { KVStore } from "fastly:kv-store";
55+
56+
async function app(event) {
57+
const files = new KVStore('files')
58+
59+
await files.put('hello', 'world')
60+
61+
const entry = await files.put('hello')
62+
63+
return new Response(await entry.text())
64+
}
65+
66+
addEventListener("fetch", (event) => event.respondWith(app(event)))
67+
68+
```

documentation/docs/fastly:object-store/ObjectStore/ObjectStore.mdx

-62
This file was deleted.

documentation/docs/fastly:object-store/ObjectStore/prototype/get.mdx

-68
This file was deleted.

0 commit comments

Comments
 (0)