moritzraho / aio-lib-state

A JavaScript abstraction on top of distributed/cloud DBs that exposes a simple state persistence API.

Home Page:https://www.adobe.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version Downloads/week Build Status License Codecov Coverage

Adobe I/O Lib State

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.

Install

npm install @adobe/aio-lib-state

Use

  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')

Explore

goto API

Adobe I/O State Store Limitations (per user)

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

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

About

A JavaScript abstraction on top of distributed/cloud DBs that exposes a simple state persistence API.

https://www.adobe.io

License:Apache License 2.0


Languages

Language:JavaScript 100.0%