@fastly/js-compute
Advanced tools
Changelog
0.5.1 (2022-08-31)
type: "module"
from the @fastly/js-compute package.json file as the package still uses require
Changelog
0.5.0 (2022-08-30)
This release adds support for Fastly Object-store, which is globally consistent key-value storage accessible across the Fastly Network. This makes it possible for your Fastly Compute application to read and write from Object-stores.
We've added two classes, ObjectStore
, and ObjectStoreEntry
. ObjectStore
is used to interact with a particular Object-store and ObjectStoreEntry
is a particular value within an Object-store. We've made ObjectStoreEntry
have a similar API as Response
to make it simpler to read and write from Object-stores. I.e. ObjectStoreEntry
has a body
property which is a ReadableStream
and has arrayBuffer
/json
/text
methods - just like Response
.
The way to use these classes is best shown with an example:
async function app(event) {
// Create a connection the the Object-store named 'example-store'
const store = new ObjectStore('example-store')
// Create or update the 'hello' key with the contents 'world'
await store.put('hello', 'world')
// Retrieve the contents of the 'hello' key
// Note: Object-stores are eventually consistent, this means that the updated contents associated may not be available to read from all
// Fastly edge locations immediately and some edge locations may continue returning the previous contents associated with the key.
const hello = await store.get('hello')
// Read the contents of the `hello` key into a string
const hellotext = await hello.text()
return new Response(hellotext)
}
addEventListener("fetch", event => {
event.respondWith(app(event))
})
btoa
and atob
global functionsThese two functions enable you to encode to (btoa) and decode from (atob) Base64 strings. They follow the same specification as the atob
and btoa
functions that exist in web-browsers.
addEventListener("fetch", event => {
event.respondWith(new Response(atob(btoa('hello from fastly'))))
})
Previously our console methods only supported a single argument and would convert the argument to a string via String(argument)
, this unfortunately made it difficult to log out complex objects such as Request objects or similar.
We've updated our console methods and they now support any number of arguments. As well as supporting any number of arguments, we've also changed the implementation to have better support for logging out complex objects.
This is a before and after example of what happens when logging a Request with our console methods.
Before:
const request = new Request('https://www.fastly.com', {body:'I am the body', method: 'POST'});
console.log(request); // outputs `[object Object]`.
After:
const request = new Request('https://www.fastly.com', {body:'I am the body', method: 'POST'});
console.log(request); // outputs `Request: {method: POST, url: https://www.fastly.com/, version: 2, headers: {}, body: null, bodyUsed: false}`.
Changelog
0.3.0 (2022-06-29)
console.trace
methodconsole.debug
Changelog
0.2.5 (2022-04-20)
Changelog
0.2.4 (2022-02-09)
Changelog
0.2.2 (2022-02-03)
queueMicrotask
global functionstructuredClone
global functionlocation
global object as an instance of WorkerLocation
FetchEvent#waitUntil
Changelog
0.2.1 (2021-11-10)
0.2.2
(Which includes fixes to geoip, a way to get environment variables, improves debugging of exceptions in the request handler, and other updates)Env
namespace for accessing Fastly Compute environment variables.Changelog
0.2.0 (2021-08-31)
base
argument in URL
constructorChangelog
0.1.0 (2021-07-28)
js-compute-runtime
CLI for bundling JavaScript applications