Sylvie: The main database class

Implements

SylvieEventEmitter

Hierarchy

Constructors

Properties

ENV: string
addListener: (<F>(eventName: string | string[], listener: F) => F) = ...

Type declaration

    • <F>(eventName: string | string[], listener: F): F
    • Alias of LokiEventEmitter.prototype.on addListener(eventName, listener) - adds a listener to the queue of callbacks associated to an event

      Returns

      the index of the callback in the array of listeners for a particular event

      Memberof

      LokiEventEmitter

      Type Parameters

      • F extends ((...args: any[]) => any)

      Parameters

      • eventName: string | string[]

        the name(s) of the event(s) to listen to

      • listener: F

        callback function of listener to attach

      Returns F

asyncListeners: boolean = false

Prop

boolean determines whether or not the callbacks associated with each event should happen in an async fashion or not Default is false, which means events are synchronous

Memberof

LokiEventEmitter

autosave: boolean
autosaveHandle: any
autosaveInterval: number
collections: Collection<Partial<CollectionDocument>>[]
databaseVersion: number
engineVersion: number
events: {
    [eventName: string]: ((...args: any[]) => any)[];
} = {}

Prop

a hashmap, with each property being an array of callbacks

Memberof

LokiEventEmitter

Type declaration

  • [eventName: string]: ((...args: any[]) => any)[]
filename: string
ignoreAutosave: boolean
isIncremental: boolean
name: string
options?: Partial<ConfigOptions & ConstructorOptions>
persistenceMethod: any
save: any
throttledCallbacks: any[]
throttledSavePending: boolean
throttledSaves: boolean
toJson: ((options?: Partial<ConfigOptions>) => any)

Type declaration

verbose: boolean
Collection: typeof Collection
Comparators: {
    aeq: ((prop1: any, prop2: any) => boolean);
    gt: ((prop1: any, prop2: any, equal: any) => any);
    lt: ((prop1: any, prop2: any, equal: any) => any);
}

Type declaration

  • aeq: ((prop1: any, prop2: any) => boolean)
      • (prop1: any, prop2: any): boolean
      • Parameters

        • prop1: any
        • prop2: any

        Returns boolean

  • gt: ((prop1: any, prop2: any, equal: any) => any)
      • (prop1: any, prop2: any, equal: any): any
      • Parameters

        • prop1: any
        • prop2: any
        • equal: any

        Returns any

  • lt: ((prop1: any, prop2: any, equal: any) => any)
      • (prop1: any, prop2: any, equal: any): any
      • Parameters

        • prop1: any
        • prop2: any
        • equal: any

        Returns any

DynamicView: typeof DynamicView
KeyValueStore: (() => void)

Type declaration

    • (): void
    • Returns void

LokiFsAdapter: typeof FsAdapter
LokiLocalStorageAdapter: typeof LocalStorageAdapter
LokiMemoryAdapter: typeof MemoryAdapter
LokiOps: {
    $aeq: ((a: any, b: any) => boolean);
    $and: (<T>(a: any, b: any, record: T) => boolean);
    $between: ((a: any, vals: [number, number]) => boolean);
    $contains: ((a: any, b: any) => boolean);
    $containsAny: ((a: any, b: any) => boolean);
    $containsNone: ((a: any, b: any) => boolean);
    $containsString: ((a: any, b: any) => boolean);
    $definedin: ((a: any, b: any) => boolean);
    $dteq: ((a: any, b: any) => boolean);
    $elemMatch: ((a: any, b: any) => boolean);
    $eq: ((a: any, b: any) => boolean);
    $exists: ((a: any, b: any) => boolean);
    $finite: ((a: any, b: any) => boolean);
    $gt: ((a: any, b: any) => boolean);
    $gte: ((a: any, b: any) => boolean);
    $in: ((a: any, b: any) => boolean);
    $inSet: ((a: any, b: any) => any);
    $jbetween: ((a: any, vals: [number, number]) => boolean);
    $jgt: ((a: any, b: any) => boolean);
    $jgte: ((a: any, b: any) => boolean);
    $jlt: ((a: any, b: any) => boolean);
    $jlte: ((a: any, b: any) => boolean);
    $keyin: ((a: any, b: any) => boolean);
    $len: (<T>(a: any, b: any, record: T) => any);
    $lt: ((a: any, b: any) => boolean);
    $lte: ((a: any, b: any) => boolean);
    $ne: ((a: any, b: any) => boolean);
    $nin: ((a: any, b: any) => boolean);
    $nkeyin: ((a: any, b: any) => boolean);
    $not: (<T>(a: any, b: any, record: T) => boolean);
    $or: (<T>(a: any, b: any, record: T) => boolean);
    $regex: ((a: any, b: any) => any);
    $size: (<T>(a: any, b: any, record: T) => any);
    $type: (<T>(a: any, b: any, record: T) => any);
    $undefinedin: ((a: any, b: any) => boolean);
    $where: ((a: any, b: any) => boolean);
}

Type declaration

  • $aeq: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $and: (<T>(a: any, b: any, record: T) => boolean)
      • <T>(a: any, b: any, record: T): boolean
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns boolean

  • $between: ((a: any, vals: [number, number]) => boolean)
      • (a: any, vals: [number, number]): boolean
      • Parameters

        • a: any
        • vals: [number, number]

        Returns boolean

  • $contains: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $containsAny: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $containsNone: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $containsString: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $definedin: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $dteq: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $elemMatch: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $eq: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $exists: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $finite: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $gt: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $gte: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $in: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $inSet: ((a: any, b: any) => any)
      • (a: any, b: any): any
      • Parameters

        • a: any
        • b: any

        Returns any

  • $jbetween: ((a: any, vals: [number, number]) => boolean)
      • (a: any, vals: [number, number]): boolean
      • Parameters

        • a: any
        • vals: [number, number]

        Returns boolean

  • $jgt: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $jgte: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $jlt: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $jlte: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $keyin: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $len: (<T>(a: any, b: any, record: T) => any)
      • <T>(a: any, b: any, record: T): any
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns any

  • $lt: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $lte: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $ne: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $nin: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $nkeyin: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $not: (<T>(a: any, b: any, record: T) => boolean)
      • <T>(a: any, b: any, record: T): boolean
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns boolean

  • $or: (<T>(a: any, b: any, record: T) => boolean)
      • <T>(a: any, b: any, record: T): boolean
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns boolean

  • $regex: ((a: any, b: any) => any)
      • (a: any, b: any): any
      • Parameters

        • a: any
        • b: any

        Returns any

  • $size: (<T>(a: any, b: any, record: T) => any)
      • <T>(a: any, b: any, record: T): any
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns any

  • $type: (<T>(a: any, b: any, record: T) => any)
      • <T>(a: any, b: any, record: T): any
      • Type Parameters

        • T

        Parameters

        • a: any
        • b: any
        • record: T

        Returns any

  • $undefinedin: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • $where: ((a: any, b: any) => boolean)
      • (a: any, b: any): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

LokiPartitioningAdapter: ((adapter: any, options?: Partial<PartitioningAdapterOptions>) => void)

Type declaration

Resultset: typeof ResultSet
aeq: ((prop1: any, prop2: any) => boolean)

Type declaration

    • (prop1: any, prop2: any): boolean
    • Parameters

      • prop1: any
      • prop2: any

      Returns boolean

deepFreeze: ((obj: object) => void)

Type declaration

    • (obj: object): void
    • Parameters

      • obj: object

      Returns void

freeze: ((obj: object) => void)

Type declaration

    • (obj: object): void
    • Parameters

      • obj: object

      Returns void

gt: ((prop1: any, prop2: any, equal: any) => any)

Type declaration

    • (prop1: any, prop2: any, equal: any): any
    • Parameters

      • prop1: any
      • prop2: any
      • equal: any

      Returns any

lt: ((prop1: any, prop2: any, equal: any) => any)

Type declaration

    • (prop1: any, prop2: any, equal: any): any
    • Parameters

      • prop1: any
      • prop2: any
      • equal: any

      Returns any

persistenceAdapters: {
    fs: typeof FsAdapter;
    localStorage: typeof LocalStorageAdapter;
}

Type declaration

unFreeze: ((obj: object) => any)

Type declaration

    • (obj: object): any
    • Parameters

      • obj: object

      Returns any

Methods

  • autosaveClearFlags - resets dirty flags on all collections. Called from saveDatabase() after db is saved.

    Returns void

  • autosaveDirty - check whether any collections are 'dirty' meaning we need to save (entire) database

    Returns

    • true if database has changed since last autosave, false if not.

    Returns boolean

  • autosaveEnable - begin a javascript interval to periodically save the database.

    Parameters

    • Optional options: Record<string, any>

      not currently used (remove or allow overrides?)

    • Optional callback: (() => any)

      (Optional) user supplied async callback

        • (): any
        • Returns any

    Returns void

  • Emits the close event. In autosave scenarios, if the database is dirty, this will save and disable timer. Does not actually destroy the db.

    Parameters

    • callback: any

      (Optional) if supplied will be registered with close event before emitting.

    Returns void

  • Allows reconfiguring database options

    Parameters

    • options: any

      configuration options to apply to loki db object

    • initialConfig: any

      (internal) true is passed when loki ctor is invoking

    Returns void

  • Copies 'this' database into a new Loki instance. Object references are shared to make lightweight.

    Parameters

    • Optional options: {
          removeNonSerializable?: boolean;
      }

      apply or override collection level settings

      • Optional removeNonSerializable?: boolean

        nulls properties not safe for serialization.

    Returns default

  • Handles deleting a database from file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).

    Memberof

    Sylvie

    Parameters

    • Optional callback: ((_: Error | {
          success: true;
      } | {
          error: Error;
          success: false;
      }) => void)

      (Optional) user supplied async callback / error handler

        • (_: Error | {
              success: true;
          } | {
              error: Error;
              success: false;
          }): void
        • Parameters

          • _: Error | {
                success: true;
            } | {
                error: Error;
                success: false;
            }

          Returns void

    Returns void

  • Collection level utility function to deserializes a destructured collection.

    Returns

    an array of documents to attach to collection.data.

    Parameters

    • destructuredSource: any

      destructured representation of collection to inflate

    • Optional options: Partial<{
          delimited: boolean;
          delimiter: string;
          partitioned: boolean;
      }>

      used to describe format of destructuredSource input

    Returns any[]

  • Database level destructured JSON deserialization routine to minimize memory overhead. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.

    Returns

    An object representation of the deserialized database, not yet applied to 'this' db or document array

    Parameters

    • destructuredSource: any

      destructured json or array to deserialize from

    • Optional options: Partial<SerializationOptions>

      source format options

    Returns any

  • emit(eventName, data) - emits a particular event with the option of passing optional parameters which are going to be processed by the callback provided signatures match (i.e. if passing emit(event, arg0, arg1) the listener should take two parameters)

    Memberof

    LokiEventEmitter

    Parameters

    • eventName: string

      the name of the event

    • Optional data: unknown

      optional object passed with the event

    • Optional arg: any

    Returns void

  • (Changes API) : takes all the changes stored in each collection and creates a single array for the entire database. If an array of names of collections is passed then only the included collections will be tracked.

    Returns

    array of changes

    See

    private method createChange() in Collection

    Parameters

    • Optional arrayOfCollectionNames: string | string[]

    Returns ChangeOps[]

  • Returns a list of collections in the database.

    Returns

    array of objects containing 'name', 'type', and 'count' properties.

    Returns any[]

  • Handles manually loading from file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided). To avoid contention with any throttledSaves, we will drain the save queue first.

    If you are configured with autosave, you do not need to call this method yourself.

    Example

    db.loadDatabase({}, function(err) {
    if (err) {
    console.log("error : " + err);
    }
    else {
    console.log("database loaded.");
    }
    });

    Parameters

    • Optional options: {
          recursiveWait?: boolean;
          recursiveWaitLimit?: boolean;
          recursiveWaitLimitDelay?: boolean;
      }

      if throttling saves and loads, this controls how we drain save queue before loading

      • Optional recursiveWait?: boolean

        (default: true) wait recursively until no saves are queued

      • Optional recursiveWaitLimit?: boolean

        (default: false) limit our recursive waiting to a duration

      • Optional recursiveWaitLimitDelay?: boolean

        (default: 2000) cutoff in ms to stop recursively re-draining

    • Optional callback: ((_: Error | {
          success: true;
      } | {
          error: Error;
          success: false;
      }) => void)

      (Optional) user supplied async callback / error handler. Note on success, the callback param will be null or { success: true }, on error it will be typeof Error or { success: false, error: Error }

        • (_: Error | {
              success: true;
          } | {
              error: Error;
              success: false;
          }): void
        • Parameters

          • _: Error | {
                success: true;
            } | {
                error: Error;
                success: false;
            }

          Returns void

    Returns void

  • Parameters

    • Optional options: {
          recursiveWait?: boolean;
          recursiveWaitLimit?: boolean;
          recursiveWaitLimitDelay?: boolean;
      }
      • Optional recursiveWait?: boolean
      • Optional recursiveWaitLimit?: boolean
      • Optional recursiveWaitLimitDelay?: boolean

    Returns Promise<unknown>

  • Internal load logic, decoupled from throttling/contention logic

    Parameters

    • options: any

      not currently used (remove or allow overrides?)

    • Optional callback: ((_: Error | {
          success: true;
      } | {
          error: Error;
          success: false;
      }) => void)

      (Optional) user supplied async callback / error handler

        • (_: Error | {
              success: true;
          } | {
              error: Error;
              success: false;
          }): void
        • Parameters

          • _: Error | {
                success: true;
            } | {
                error: Error;
                success: false;
            }

          Returns void

    Returns void

  • Inflates a loki database from a JS object

    Parameters

    • dbObject: any

      a serialized loki database string

    • Optional options: {
          retainDirtyFlags?: boolean;
          throttledSaves?: boolean;
      }

      apply or override collection level settings

      • Optional retainDirtyFlags?: boolean

        whether collection dirty flags will be preserved

      • Optional throttledSaves?: boolean

    Returns void

  • on(eventName, listener) - adds a listener to the queue of callbacks associated to an event

    Returns

    the index of the callback in the array of listeners for a particular event

    Memberof

    LokiEventEmitter

    Type Parameters

    • F extends ((...args: any[]) => any)

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) to listen to

    • listener: F

      callback function of listener to attach

    Returns F

  • Removes a collection from the database.

    Parameters

    • collectionName: any

      name of collection to remove

    Returns void

  • removeListener() - removes the listener at position 'index' from the event 'eventName'

    Memberof

    LokiEventEmitter

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) which the listener is attached to

    • listener: ((...args: any[]) => any)

      the listener callback function to remove from emitter

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns void

  • Handles manually saving to file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).

    If you are configured with autosave, you do not need to call this method yourself.

    Memberof

    Sylvie

    Example

    db.saveDatabase(function(err) {
    if (err) {
    console.log("error : " + err);
    }
    else {
    console.log("database saved.");
    }
    });

    Parameters

    • Optional callback: ((_: Error | ResultType) => void)

      (Optional) user supplied async callback / error handler

    Returns void

  • (Changes API) - stringify changes for network transmission

    Returns

    string representation of the changes

    Parameters

    • Optional collectionNamesArray: any

    Returns string

  • Collection level utility method to serialize a collection in a 'destructured' format

    Returns

    A custom, restructured aggregation of independent serializations for a single collection.

    Parameters

    • options: any

      used to determine output of method

    Returns string | any[]

  • Database level destructured JSON serialization routine to allow alternate serialization methods. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.

    Returns

    A custom, restructured aggregation of independent serializations.

    Parameters

    Returns any

  • serializeReplacer - used to prevent certain properties from being serialized

    Parameters

    • key: any
    • value: any

    Returns any

  • Wait for throttledSaves to complete and invoke your callback when drained or duration is met.

    Parameters

    • callback: any

      callback to fire when save queue is drained, it is passed a sucess parameter value

    • Optional options: {
          recursiveWait?: boolean;
          recursiveWaitLimit?: boolean;
          recursiveWaitLimitDelay?: boolean;
          recursiveWaitLimitDuration?: number;
          started?: number;
      }

      configuration options

      • Optional recursiveWait?: boolean

        (default: true) if after queue is drained, another save was kicked off, wait for it

      • Optional recursiveWaitLimit?: boolean

        (default: false) limit our recursive waiting to a duration

      • Optional recursiveWaitLimitDelay?: boolean

        (default: 2000) cutoff in ms to stop recursively re-draining

      • Optional recursiveWaitLimitDuration?: number
      • Optional started?: number

    Returns void

Generated using TypeDoc