Reference Source
import WLJSONStore from 'react-native-ibm-mobilefirst-jsonstore'
public class | source

WLJSONStore

This class is the public WLJSONStore API for React-Native applications.

Method Summary

Public Methods
public

async changePassword(username: string, oldPassword: string, newPassword: string, pbkdf2Iterations: number): Promise<string, JSON>

Change the password for the given user.

public

Locks access to all the collections until the init method is called.

public

Commit a transaction.

public

async destroy(username: string): Promise<string, JSON>

Permanently deletes all data for all users, clears security artifacts, and removes accessors.

public

Returns an array of objects with information about all the stores in the device.

public

async openCollections(collections: array, options: JSONStoreInitOptions): Promise<string, JSON>

Provides access to the collections that are inside the store, and creates them if they do not already exist.

public

Roll back a transaction.

public

setAnalyticsEnabled(isAnalyticsEnabled: boolean)

Enable or disable the collection of analytic data for JSONStore.

public

Start a transaction.

Public Methods

public async changePassword(username: string, oldPassword: string, newPassword: string, pbkdf2Iterations: number): Promise<string, JSON> source

Change the password for the given user.

Params:

NameTypeAttributeDescription
username string

The user name.

oldPassword string

The old password.

newPassword string

The new password.

pbkdf2Iterations number
  • optional

The number of iterations used by the Password-Based Key Derivation Function 2 algorithm used to secure the password.

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async closeAll(): Promise<string, JSON> source

Locks access to all the collections until the init method is called.

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async commitTransaction(): Promise<string, JSON> source

Commit a transaction.

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async destroy(username: string): Promise<string, JSON> source

Permanently deletes all data for all users, clears security artifacts, and removes accessors.

Params:

NameTypeAttributeDescription
username string
  • optional

The user name.

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async getFileInfo(): Promise<Array, JSON> source

Returns an array of objects with information about all the stores in the device.

Return:

Promise<Array, JSON>

This function returns an Array of JSON Objects in case of success, representing the details of the JSONStore info, and it returns a JSON in case of any error

Example:

- This is how a sample response will look like:
[
 {
     encrypted:false,
     fileSize:7168,
     username:"com.worklight.jsonstore"
 }
]

public async openCollections(collections: array, options: JSONStoreInitOptions): Promise<string, JSON> source

Provides access to the collections that are inside the store, and creates them if they do not already exist.

Params:

NameTypeAttributeDescription
collections array

An array of collection definitions (JSONStoreCollection objects) that are to be initialized (either reopened or created).

options JSONStoreInitOptions
  • optional

An object of class JSONStoreInitOptions. This is a specific set of options to initialize the collection with (such as security credentials).

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async rollbackTransaction(): Promise<boolean, JSON> source

Roll back a transaction.

Return:

Promise<boolean, JSON>

This returns a boolean value on completion - true for success, false for failure.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public setAnalyticsEnabled(isAnalyticsEnabled: boolean) source

Enable or disable the collection of analytic data for JSONStore.

Params:

NameTypeAttributeDescription
isAnalyticsEnabled boolean

ture: to collect Analytics data, false: otherwise

public async startTransaction(): Promise<string, JSON> source

Start a transaction.

Return:

Promise<string, JSON>

This returns an empty string on success, and a JSON in case of any error.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}