Interface: IDataStore
An interface for persisting data.
Remarks
This interface saves activity results as well as saves and retrieves arbitrary key-value items that activities can use.
The underlying persistence provider of the store must
be previously set in the activity's Session
before use. The
implementation of the store is not provided by the @m2c2kit/core library.
Example
import { LocalDatabase } from "@m2c2kit/db";
...
const db: IDataStore = new LocalDatabase();
session.dataStore = db;
session.initialize();
Methods
clearItemsByActivityPublishUuid()
clearItemsByActivityPublishUuid(
activityPublishUuid
):Promise
<void
>
Deletes all items.
Parameters
• activityPublishUuid: string
Returns
Promise
<void
>
Source
deleteItem()
deleteItem(
key
):Promise
<void
>
Deletes an item by its key.
Parameters
• key: string
Returns
Promise
<void
>
Source
getItem()
getItem<
T
>(key
):Promise
<T
>
Gets the value of an item by its key.
Type parameters
• T extends undefined
| null
| string
| number
| boolean
| object
Parameters
• key: string
Returns
Promise
<T
>
Source
itemExists()
itemExists(
key
):Promise
<boolean
>
Determines if the key exists.
Parameters
• key: string
Returns
Promise
<boolean
>
Source
itemsKeysByActivityPublishUuid()
itemsKeysByActivityPublishUuid(
activityPublishUuid
):Promise
<string
[]>
Returns keys of all items.
Parameters
• activityPublishUuid: string
Returns
Promise
<string
[]>
Source
saveActivityResults()
saveActivityResults(
ev
):Promise
<string
>
Saves activity results in the data store.
Parameters
• ev: ActivityResultsEvent
Returns
Promise
<string
>
Source
setItem()
setItem(
key
,value
,activityPublishUuid
):Promise
<string
>
Sets the value of an item. The key will be saved to the store as provided; if namespacing or other formatting is desired, it must be done before calling this method. activityId can be used by the store for indexing.
Parameters
• key: string
• value: undefined
| null
| string
| number
| boolean
| object
• activityPublishUuid: string
Returns
Promise
<string
>