A JavaScript abstraction on top of distributed/cloud DBs that exposes a simple state persistence API.
You can initialize the lib with your Adobe I/O Runtime (a.k.a OpenWhisk) credentials.
Alternatively, you can bring your own cloud db keys. As of now we only support Azure Cosmos but AWS Dynamo is the next on the todo list and will soon be available.
npm install @adobe/aio-lib-state
const stateLib = require('@adobe/aio-lib-state')
// init
// init sdk using OpenWhisk credentials
const state = await stateLib.init({ ow: { namespace, auth } })
// init when env vars __OW_AUTH and __OW_NAMESPACE are set (e.g. when running in an OpenWhisk action)
const state = await stateLib.init()
// or if you want to use your own cloud DB account
const state = await stateLib.init({ cosmos: { endpoint, masterKey, databaseId, containerId, partitionKey } })
// get
const value = await state.get('key')
// put
await state.put('key', 'value')
await state.put('key', { anObject: 'value' }, { ttl: -1 }) // -1 for no expiry, defaults to 86400 (24 hours)
// delete
await state.delete('key')
goto
API
Apply when init with OW credentials (and not own cloud DB credentials):
- Max state value size:
2MB
- Max state key size:
1024 bytes
- Max total state size:
10 GB
- Token expiry (need to re-init after expiry):
1 hour
- Consistency:
Session Consistency (CosmosDB)
- Namespace max length:
49 characters
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.