Loki/Sylvie encrypted persistence adapter class for indexedDb. This class fulfills abstract adapter interface which can be applied to other storage methods. Utilizes the included SylvieCatalog app/key/value database for actual database persistence. IndexedDb storage is provided per-domain, so we implement app/key/value database to allow separate contexts for separate apps within a domain.

Example

var idbAdapter = new CryptedIndexedDBAdapter('finance', {
secret: "pass"
});

Hierarchy

  • CryptedIndexedDBAdapter

Implements

Constructors

Properties

#secret: string
app: string
idbAdapter: IndexedDBAdapter
isAsync: true
mode: "normal"
options: Partial<CryptedIndexedDBAdapterOptions>

Methods

  • Changes the password of a database and re-encrypts the database with the new password.

    Memberof

    CryptedIndexedDBAdapter

    Returns

    A promise that resolves when the password has been changed.

    Throws

    If the adapter is not open.

    Example

    await adapter.changePassword("mydb", "newpassword");
    // The database "mydb" is now encrypted with the password "newpassword".
    // The old password will no longer work.

    Parameters

    • dbname: string
    • newPassword: string

      The new password to encrypt the database with.

    Returns Promise<void>

  • Removes all database partitions and pages with the base filename passed in. This utility method does not (yet) guarantee async deletions will be completed before returning

    Memberof

    SylvieIndexedAdapter

    Parameters

    • dbname: any

      the base filename which container, partitions, or pages are derived

    Returns void

  • Retrieves object array of catalog entries for current app.

    Example

    idbAdapter.getDatabaseList(function(result) {
    // result is array of string names for that appcontext ('finance')
    result.forEach(function(str) {
    console.log(str);
    });
    });

    Memberof

    SylvieIndexedAdapter

    Parameters

    • callback: ((_: string[] | Error) => void)

      should accept array of database names in the catalog for current app.

        • (_: string[] | Error): void
        • Parameters

          • _: string[] | Error

          Returns void

    Returns void

  • Retrieves a serialized db string from the catalog.

    Example

    // LOAD
    var idbAdapter = new SylvieIndexedAdapter('finance');
    var db = new loki('test', { adapter: idbAdapter });
    db.loadDatabase(function(result) {
    console.log('done');
    });

    Parameters

    • dbname: string

      the name of the database to retrieve.

    • callback: ((serialized: string) => void)

      callback should accept string param containing serialized db string.

        • (serialized: string): void
        • Parameters

          • serialized: string

          Returns void

    Returns void

  • Retrieves a serialized db string from the catalog, returns a promise to a string of the serialized database.

    Returns

    A promise to a string of the serialized database.

    Example

    const db = new Sylvie(TEST_DB_NAME, {
    adapter: new CryptedIndexedDBAdapter();
    });
    await db.loadDatabaseAsync({});
    // db is now ready to use
    // you can also chain the promises
    await db.loadDatabaseAsync({}).then(() => {
    // db is now ready to use
    });
    // or use async await syntax
    await db.loadDatabaseAsync({});
    // db is now ready to use

    Memberof

    CryptedIndexedDBAdapter

    Throws

    If the database is not found.

    Throws

    If the database is not decrypted successfully.

    Throws

    If the database is not deserialized successfully.

    Parameters

    • dbname: string

    Returns Promise<string>

  • Saves a serialized db to the catalog.

    Example

    // SAVE : will save App/Key/Val as 'finance'/'test'/{serializedDb}
    var idbAdapter = new SylvieIndexedAdapter('finance');
    var db = new loki('test', { adapter: idbAdapter });
    var coll = db.addCollection('testColl');
    coll.insert({test: 'val'});
    db.saveDatabase(); // could pass callback if needed for async complete

    Parameters

    • dbname: string

      the name to give the serialized database within the catalog.

    • dbstring: string

      the serialized db string to save.

    • Optional callback: PersistenceAdapterCallback

      (Optional) callback passed obj.success with true or false

    Returns void

  • Sets a password for use on future load and save of the database. Note that this does not re-encrypt the database with the new password. Use changePassword() for that.

    Example

    const db = new Sylvie(TEST_DB_NAME, {
    adapter: new CryptedIndexedDBAdapter();
    });

    adapter.usePassword("newpassword");

    await newDb.loadDatabaseAsync({});

    Parameters

    • secret: string

    Returns void

Generated using TypeDoc