UNPKG

forerunnerdb

Version:

A NoSQL document store database for browsers and Node.js.

1,471 lines (1,309 loc) 149 kB
/** * Creates an always-sorted multi-key bucket that allows ForerunnerDB to * know the index that a document will occupy in an array with minimal * processing, speeding up things like sorted views. * @param {Object} orderBy An order object. * @class */ declare class ActiveBucket { /** * Creates an always-sorted multi-key bucket that allows ForerunnerDB to * know the index that a document will occupy in an array with minimal * processing, speeding up things like sorted views. * @param {Object} orderBy An order object. * @class */ constructor(orderBy: Object); /** * Quicksorts a single document into the passed array and * returns the index that the document should occupy. * @param {Object} obj The document to calculate index for. * @param {Array} arr The array the document index will be * calculated for. * @param {String} item The string key representation of the * document whose index is being calculated. * @param {Function} fn The comparison function that is used * to determine if a document is sorted below or above the * document we are calculating the index for. * @returns {Number} The index the document should occupy. */ qs(obj: Object, arr: Array, item: String, fn: (() => any)): Number; /** * Calculates the sort position of an item against another item. * @param {Object} sorter An object or instance that contains * sortAsc and sortDesc methods. * @param {Object} obj The document to compare. * @param {String} a The first key to compare. * @param {String} b The second key to compare. * @returns {Number} Either 1 for sort a after b or -1 to sort * a before b. * @private */ private _sortFunc(sorter: Object, obj: Object, a: String, b: String): Number; /** * Inserts a document into the active bucket. * @param {Object} obj The document to insert. * @returns {Number} The index the document now occupies. */ insert(obj: Object): Number; /** * Removes a document from the active bucket. * @param {Object} obj The document to remove. * @returns {boolean} True if the document was removed * successfully or false if it wasn't found in the active * bucket. */ remove(obj: Object): boolean; /** * Get the index that the passed document currently occupies * or the index it will occupy if added to the active bucket. * @param {Object} obj The document to get the index for. * @returns {Number} The index. */ index(obj: Object): Number; /** * The key that represents the passed document. * @param {Object} obj The document to get the key for. * @returns {String} The document key. */ documentKey(obj: Object): String; /** * Get the number of documents currently indexed in the active * bucket instance. * @returns {Number} The number of documents. */ count(): Number; } /** * Provides angular scope updating functionality to ForerunnerDB. Allows * collections and views to provide data to angular and to automatically * update angular when data in ForerunnerDB changes. * @class Angular */ declare class Angular { /** * Provides angular scope updating functionality to ForerunnerDB. Allows * collections and views to provide data to angular and to automatically * update angular when data in ForerunnerDB changes. * @class Angular */ constructor(); /** * Extends the Collection class with new binding capabilities. * @extends Collection * @param {Collection} Module The Collection class module. * @private */ private static extendCollection(Module: Collection): void; /** * Extends the View class with new binding capabilities. * @extends View * @param {View} Module The View class module. * @private */ private static extendView(Module: View): void; /** * Extends the Overview class with new binding capabilities. * @extends Overview * @param {Overview} Module The Overview class module. * @private */ private static extendOverview(Module: Overview): void; } /** * Provides data-binding functionality to ForerunnerDB. Allows collections * and views to link to selectors and automatically generate DOM elements * from jsViews (jsRender) templates. * @class AutoBind */ declare class AutoBind { /** * Provides data-binding functionality to ForerunnerDB. Allows collections * and views to link to selectors and automatically generate DOM elements * from jsViews (jsRender) templates. * @class AutoBind */ constructor(); /** * Extends the Collection class with new binding capabilities. * @extends Collection * @param {Collection} Module The Collection class module. * @private */ private static extendCollection(Module: Collection): void; /** * Extends the View class with new binding capabilities. * @extends View * @param {View} Module The View class module. * @private */ private static extendView(Module: View): void; /** * Extends the Overview class with new binding capabilities. * @extends Overview * @param {Overview} Module The Overview class module. * @private */ private static extendOverview(Module: Overview): void; /** * Extends the Document class with new binding capabilities. * @extends Document * @param {Document} Module The Document class module. * @private */ private static extendDocument(Module: Document): void; } /** * Creates a new collection. Collections store multiple documents and * handle CRUD against those documents. * @constructor * @class */ declare class Collection { /** * Creates a new collection. Collections store multiple documents and * handle CRUD against those documents. * @constructor * @class */ constructor(); /** * Creates a link to the DOM between the collection data and the elements * in the passed output selector. When new elements are needed or changes * occur the passed templateSelector is used to get the template that is * output to the DOM. * @func link * @memberof Collection * @param scope * @param varName * @param {Object=} options Optional extra options. * @see unlink */ static link(scope: any, varName: any, options?: Object): void; /** * Checks if the instance is data-bound to any DOM elements. * @func isLinked * @memberof Collection * @returns {Boolean} True if linked, false if not. */ static isLinked(): Boolean; /** * Removes a link to the DOM between the collection data and the elements * in the passed output selector that was created using the link() method. * @func unlink * @memberof Collection * @param outputTargetSelector * @param templateSelector */ static unlink(outputTargetSelector: any, templateSelector: any): void; /** * Creates a new collection. Collections store multiple documents and * handle CRUD against those documents. */ init(): void; /** * Adds a job id to the async queue to signal to other parts * of the application that some async work is currently being * done. * @param {String} key The id of the async job. * @private */ private _asyncPending(key: String): void; /** * Removes a job id from the async queue to signal to other * parts of the application that some async work has been * completed. If no further async jobs exist on the queue then * the "ready" event is emitted from this collection instance. * @param {String} key The id of the async job. * @private */ private _asyncComplete(key: String): void; /** * Get the data array that represents the collection's data. * This data is returned by reference and should not be altered outside * of the provided CRUD functionality of the collection as doing so * may cause unstable index behaviour within the collection. * @returns {Array} */ data(): Array; /** * Drops a collection and all it's stored data from the database. * @param {Function=} callback A callback method to call once the * operation has completed. * @returns {boolean} True on success, false on failure. */ drop(callback?: (() => any)): boolean; /** * Gets / sets the primary key for this collection. * @param {String=} keyName The name of the primary key. * @returns {*} */ primaryKey(keyName?: String): any; /** * Handles insert events and routes changes to binds and views as required. * @param {Array} inserted An array of inserted documents. * @param {Array} failed An array of documents that failed to insert. * @private */ private _onInsert(inserted: Array, failed: Array): void; /** * Handles update events and routes changes to binds and views as required. * @param {Array} items An array of updated documents. * @private */ private _onUpdate(items: Array): void; /** * Handles remove events and routes changes to binds and views as required. * @param {Array} items An array of removed documents. * @private */ private _onRemove(items: Array): void; /** * Handles any change to the collection by updating the * lastChange timestamp on the collection's metaData. This * only happens if the changeTimestamp option is enabled * on the collection (it is disabled by default). * @private */ private _onChange(): void; /** * Sets the collection's data to the array / documents passed. If any * data already exists in the collection it will be removed before the * new data is set via the remove() method, and the remove event will * fire as well. * @name setData * @method Collection.setData * @param {Array|Object} data The array of documents or a single document * that will be set as the collections data. */ static setData(data: (Array|Object)): void; /** * Drops and rebuilds the primary key index for all documents * in the collection. * @param {Object=} options An optional options object. * @private */ private rebuildPrimaryKeyIndex(options?: Object): void; /** * Checks for a primary key on the document and assigns one if none * currently exists. * @param {Object} obj The object to check a primary key against. * @private */ private ensurePrimaryKey(obj: Object): void; /** * Clears all data from the collection. * @returns {Collection} */ truncate(): Collection; /** * Inserts a new document or updates an existing document in a * collection depending on if a matching primary key exists in * the collection already or not. * * If the document contains a primary key field (based on the * collections's primary key) then the database will search for * an existing document with a matching id. If a matching * document is found, the document will be updated. Any keys that * match keys on the existing document will be overwritten with * new data. Any keys that do not currently exist on the document * will be added to the document. * * If the document does not contain an id or the id passed does * not match an existing document, an insert is performed instead. * If no id is present a new primary key id is provided for the * document and the document is inserted. * * @param {Object} obj The document object to upsert or an array * containing documents to upsert. * @param {Function=} callback Optional callback method. * @returns {Object} An object containing two keys, "op" contains * either "insert" or "update" depending on the type of operation * that was performed and "result" contains the return data from * the operation used. */ upsert(obj: Object, callback?: (() => any)): Object; /** * Executes a method against each document that matches query and returns an * array of documents that may have been modified by the method. * @param {Object} query The query object. * @param {Function} func The method that each document is passed to. If this method * returns false for a particular document it is excluded from the results. * @param {Object=} options Optional options object. * @returns {Array} */ filter(query: Object, func: (() => any), options?: Object): Array; /** * Executes a method against each document that matches query and then executes * an update based on the return data of the method. * @param {Object} query The query object. * @param {Function} func The method that each document is passed to. If this method * returns false for a particular document it is excluded from the update. * @param {Object=} options Optional options object passed to the initial find call. * @returns {Array} */ filterUpdate(query: Object, func: (() => any), options?: Object): Array; /** * Modifies an existing document or documents in a collection. * This will update all matches for 'query' with the data held * in 'update'. It will not overwrite the matched documents * with the update document. * * @param {Object} query The query that must be matched for a * document to be operated on. * @param {Object} update The object containing updated * key/values. Any keys that match keys on the existing document * will be overwritten with this data. Any keys that do not * currently exist on the document will be added to the document. * @param {Object=} options An options object. * @param {Function=} callback The callback method to call when * the update is complete. * @returns {Array} The items that were updated. */ update(query: Object, update: Object, options?: Object, callback?: (() => any)): Array; /** * Handles the update operation that was initiated by a call to update(). * @param {Object} query The query that must be matched for a * document to be operated on. * @param {Object} update The object containing updated * key/values. Any keys that match keys on the existing document * will be overwritten with this data. Any keys that do not * currently exist on the document will be added to the document. * @param {Object=} options An options object. * @param {Function=} callback The callback method to call when * the update is complete. * @returns {Array} The items that were updated. * @private */ private _handleUpdate(query: Object, update: Object, options?: Object, callback?: (() => any)): Array; /** * Replaces an existing object with data from the new object without * breaking data references. It does this by removing existing keys * from the base object and then adding the passed object's keys to * the existing base object, thereby maintaining any references to * the existing base object but effectively replacing the object with * the new one. * @param {Object} currentObj The base object to alter. * @param {Object} newObj The new object to overwrite the existing one * with. * @returns {*} Chain. * @private */ private _replaceObj(currentObj: Object, newObj: Object): any; /** * Helper method to update a document via it's id. * @param {String} id The id of the document. * @param {Object} update The object containing the key/values to * update to. * @param {Object=} options An options object. * @param {Function=} callback The callback method to call when * the update is complete. * @returns {Object} The document that was updated or undefined * if no document was updated. */ updateById(id: String, update: Object, options?: Object, callback?: (() => any)): Object; /** * Internal method for document updating. * @param {Object} doc The document to update. * @param {Object} update The object with key/value pairs to update * the document with. * @param {Object} query The query object that we need to match to * perform an update. * @param {Object} options An options object. * @param {String} path The current recursive path. * @param {String} opType The type of update operation to perform, * if none is specified default is to set new data against matching * fields. * @returns {Boolean} True if the document was updated with new / * changed data or false if it was not updated because the data was * the same. * @private */ private updateObject(doc: Object, update: Object, query: Object, options: Object, path: String, opType: String): Boolean; /** * Determines if the passed key has an array positional mark * (a dollar at the end of its name). * @param {String} key The key to check. * @returns {Boolean} True if it is a positional or false if not. * @private */ private _isPositionalKey(key: String): Boolean; /** * Removes any documents from the collection that match the search * query key/values. * @param {Object=} query The query identifying the documents to remove. If no * query object is passed, all documents will be removed from the collection. * @param {Object=} options An options object. * @param {Function=} callback A callback method. * @returns {Array} An array of the documents that were removed. */ remove(query?: Object, options?: Object, callback?: (() => any)): Array; /** * Helper method that removes a document that matches the given id. * @param {String} id The id of the document to remove. * @returns {Object} The document that was removed or undefined if * nothing was removed. */ removeById(id: String): Object; /** * Processes a deferred action queue. * @param {String} type The queue name to process. * @param {Function} callback A method to call when the queue has processed. * @param {Object=} resultObj A temp object to hold results in. */ processQueue(type: String, callback: (() => any), resultObj?: Object): void; /** * Checks if any CRUD operations have been deferred and are still waiting to * be processed. * @returns {Boolean} True if there are still deferred CRUD operations to process * or false if all queues are clear. */ isProcessingQueue(): Boolean; /** * Inserts a document or array of documents into the collection. * @param {Object|Array} data Either a document object or array of document * @param {Number=} index Optional index to insert the record at. * @param {Collection.insertCallback=} callback Optional callback called * once the insert is complete. */ insert(data: (Object|Array), index?: Number, callback?: Collection.insertCallback): void; /** * The insert operation's callback. * @name Collection.insertCallback * @callback Collection.insertCallback * @param {Object} result The result object will contain two arrays (inserted * and failed) which represent the documents that did get inserted and those * that didn't for some reason (usually index violation). Failed items also * contain a reason. Inspect the failed array for further information. * * A third field called "deferred" is a boolean value to indicate if the * insert operation was deferred across more than one CPU cycle (to avoid * blocking the main thread). */ type insertCallback = (result: Object) => void; /** * Inserts a document or array of documents into the collection. * @param {Object|Array} data Either a document object or array of document * @param {Number=} index Optional index to insert the record at. * @param {Collection.insertCallback=} callback Optional callback called * once the insert is complete. */ _insertHandle(data: (Object|Array), index?: Number, callback?: Collection.insertCallback): void; /** * Internal method to insert a document into the collection. Will * check for index violations before allowing the document to be inserted. * @param {Object} doc The document to insert after passing index violation * tests. * @param {Number=} index Optional index to insert the document at. * @returns {Boolean|Object} True on success, false if no document passed, * or an object containing details about an index violation if one occurred. * @private */ private _insert(doc: Object, index?: Number): (Boolean|Object); /** * Inserts a document into the internal collection data array at * Inserts a document into the internal collection data array at * the specified index. * @param {Number} index The index to insert at. * @param {Object} doc The document to insert. * @private */ private _dataInsertAtIndex(index: Number, doc: Object): void; /** * Removes a document from the internal collection data array at * the specified index. * @param {Number} index The index to remove from. * @private */ private _dataRemoveAtIndex(index: Number): void; /** * Replaces all data in the collection's internal data array with * the passed array of data. * @param {Array} data The array of data to replace existing data with. * @private */ private _dataReplace(data: Array): void; /** * Inserts a document into the collection indexes. * @param {Object} doc The document to insert. * @private */ private _insertIntoIndexes(doc: Object): void; /** * Removes a document from the collection indexes. * @param {Object} doc The document to remove. * @private */ private _removeFromIndexes(doc: Object): void; /** * Updates collection index data for the passed document. * @param {Object} oldDoc The old document as it was before the update (must be * actual reference to original document). * @param {Object} newDoc The document as it now is after the update. * @private */ private _updateIndexes(oldDoc: Object, newDoc: Object): void; /** * Rebuild collection indexes. * @private */ private _rebuildIndexes(): void; /** * Uses the passed query to generate a new collection with results * matching the query parameters. * * @param {Object} query The query object to generate the subset with. * @param {Object=} options An options object. * @returns {*} */ subset(query: Object, options?: Object): any; /** * Checks if the collection is a subset of the passed collection. * @param {Collection} collection The collection to test against. * @returns {Boolean} True if the passed collection is the parent of * the current collection. */ isSubsetOf(collection: Collection): Boolean; /** * Find the distinct values for a specified field across a single collection and * returns the results in an array. * @param {String} key The field path to return distinct values for e.g. "person.name". * @param {Object=} query The query to use to filter the documents used to return values from. * @param {Object=} options The query options to use when running the query. * @returns {Array} */ distinct(key: String, query?: Object, options?: Object): Array; /** * Helper method to find a document by it's id. * @param {String} id The id of the document. * @param {Object=} options The options object, allowed keys are sort and limit. * @returns {Array} The items that were updated. */ findById(id: String, options?: Object): Array; /** * Finds all documents that contain the passed string or search object * regardless of where the string might occur within the document. This * will match strings from the start, middle or end of the document's * string (partial match). * @param {String} search The string to search for. Case sensitive. * @param {Object=} options A standard find() options object. * @returns {Array} An array of documents that matched the search string. */ peek(search: String, options?: Object): Array; /** * Provides a query plan / operations log for a query. * @param {Object} query The query to execute. * @param {Object=} options Optional options object. * @returns {Object} The query plan. */ explain(query: Object, options?: Object): Object; /** * Generates an options object with default values or adds default * values to a passed object if those values are not currently set * to anything. * @param {Object=} obj Optional options object to modify. * @returns {Object} The options object. */ options(obj?: Object): Object; /** * Queries the collection based on the query object passed. * @param {Object} query The query key/values that a document must match in * order for it to be returned in the result array. * @param {Object=} options An optional options object. * @param {Function=} callback !! DO NOT USE, THIS IS NON-OPERATIONAL !! * Optional callback. If specified the find process * will not return a value and will assume that you wish to operate under an * async mode. This will break up large find requests into smaller chunks and * process them in a non-blocking fashion allowing large datasets to be queried * without causing the browser UI to pause. Results from this type of operation * will be passed back to the callback once completed. * * @returns {Array} The results array from the find operation, containing all * documents that matched the query. */ find(query: Object, options?: Object, callback?: (() => any)): Array; /** * Returns one document that satisfies the specified query criteria. If multiple * documents satisfy the query, this method returns the first document to match * the query. * @returns {*} */ findOne(): any; /** * Gets the index in the collection data array of the first item matched by * the passed query object. * @param {Object} query The query to run to find the item to return the index of. * @param {Object=} options An options object. * @returns {Number} */ indexOf(query: Object, options?: Object): Number; /** * Returns the index of the document identified by the passed item's primary key. * @param {*} itemLookup The document whose primary key should be used to lookup * or the id to lookup. * @param {Object=} options An options object. * @returns {Number} The index the item with the matching primary key is occupying. */ indexOfDocById(itemLookup: any, options?: Object): Number; /** * Removes a document from the collection by it's index in the collection's * data array. * @param {Number} index The index of the document to remove. * @returns {Object} The document that has been removed or false if none was * removed. */ removeByIndex(index: Number): Object; /** * Gets / sets the collection transform options. * @param {Object} obj A collection transform options object. * @returns {*} */ transform(obj: Object): any; /** * Transforms data using the set transformIn method. * @param {Object} data The data to transform. * @returns {*} */ transformIn(data: Object): any; /** * Transforms data using the set transformOut method. * @param {Object} data The data to transform. * @returns {*} */ transformOut(data: Object): any; /** * Sorts an array of documents by the given sort path. * @param {*} sortObj The keys and orders the array objects should be sorted by. * @param {Array} arr The array of documents to sort. * @returns {Array} */ sort(sortObj: any, arr: Array): Array; /** * Groups an array of documents into multiple array fields, named by the value * of the given group path. * @param {*} groupObj The key path the array objects should be grouped by. * @param {Array} arr The array of documents to group. * @returns {Object} */ group(groupObj: any, arr: Array): Object; /** * Sorts array by individual sort path. * @param {String} key The path to sort by. * @param {Array} arr The array of objects to sort. * @returns {Array|*} * @private */ private _sort(key: String, arr: Array): (Array|any); /** * Internal method that takes a search query and options and * returns an object containing details about the query which * can be used to optimise the search. * * @param {Object} query The search query to analyse. * @param {Object} options The query options object. * @param {Operation} op The instance of the Operation class that * this operation is using to track things like performance and steps * taken etc. * @returns {Object} * @private */ private _analyseQuery(query: Object, options: Object, op: Operation): Object; /** * Checks if the passed query references a source object (such * as a collection) by name. * @param {Object} query The query object to scan. * @param {String} sourceName The source name to scan for in the query. * @param {String=} path The path to scan from. * @returns {*} * @private */ private _queryReferencesSource(query: Object, sourceName: String, path?: String): any; /** * Returns the number of documents currently in the collection. * @returns {Number} */ count(): Number; /** * Finds sub-documents from the collection's documents. * @param {Object} match The query object to use when matching * parent documents from which the sub-documents are queried. * @param {String} path The path string used to identify the * key in which sub-documents are stored in parent documents. * @param {Object=} subDocQuery The query to use when matching * which sub-documents to return. * @param {Object=} subDocOptions The options object to use * when querying for sub-documents. * @returns {*} */ findSub(match: Object, path: String, subDocQuery?: Object, subDocOptions?: Object): any; /** * Finds the first sub-document from the collection's documents * that matches the subDocQuery parameter. * @param {Object} match The query object to use when matching * parent documents from which the sub-documents are queried. * @param {String} path The path string used to identify the * key in which sub-documents are stored in parent documents. * @param {Object=} subDocQuery The query to use when matching * which sub-documents to return. * @param {Object=} subDocOptions The options object to use * when querying for sub-documents. * @returns {Object} */ findSubOne(match: Object, path: String, subDocQuery?: Object, subDocOptions?: Object): Object; /** * Checks that the passed document will not violate any index rules if * inserted into the collection. * @param {Object} doc The document to check indexes against. * @returns {Boolean} Either false (no violation occurred) or true if * a violation was detected. */ insertIndexViolation(doc: Object): Boolean; /** * Creates an index on the specified keys. * @param {Object} keys The object containing keys to index. * @param {Object} options An options object. * @returns {*} */ ensureIndex(keys: Object, options: Object): any; /** * Gets an index by it's name. * @param {String} name The name of the index to retreive. * @returns {*} */ index(name: String): any; /** * Gets the last reporting operation's details such as run time. * @returns {Object} */ lastOp(): Object; /** * Generates a difference object that contains insert, update and remove arrays * representing the operations to execute to make this collection have the same * data as the one passed. * @param {Collection} collection The collection to diff against. * @returns {{}} */ diff(collection: Collection): Object; /** * Adds a data source to collate data from and specifies the * key name to collate data to. * @func collateAdd * @memberof Collection * @param {Collection} collection The collection to collate data from. * @param {String=} keyName Optional name of the key to collate data to. * If none is provided the record CRUD is operated on the root collection * data. */ static collateAdd(collection: Collection, keyName?: String): void; /** * Creates a condition handler that will react to changes in data on the * collection. * @example Create a condition handler that reacts when data changes. * var coll = db.collection('test'), * condition = coll.when({_id: 'test1', val: 1}) * .then(function () { * console.log('Condition met!'); * }) * .else(function () { * console.log('Condition un-met'); * }); * * coll.insert({_id: 'test1', val: 1}); * * @see Condition * @param {Object} query The query that will trigger the condition's then() * callback. * @returns {Condition} */ when(query: Object): Condition; /** * Creates a grid and assigns the collection as its data source. * @func grid * @memberof Collection * @param {String} selector jQuery selector of grid output target. * @param {String} template The table template to use when rendering the grid. * @param {Object=} options The options object to apply to the grid. * @returns {*} */ static grid(selector: String, template: String, options?: Object): any; /** * Removes a grid safely from the DOM. Must be called when grid is * no longer required / is being removed from DOM otherwise references * will stick around and cause memory leaks. * @func unGrid * @memberof Collection * @param {String} selector jQuery selector of grid output target. * @param {String} template The table template to use when rendering the grid. * @param {Object=} options The options object to apply to the grid. * @returns {*} */ static unGrid(selector: String, template: String, options?: Object): any; /** * Adds a grid to the internal grid lookup. * @func _addGrid * @memberof Collection * @param {Grid} grid The grid to add. * @returns {Collection} * @private */ private static _addGrid(grid: Grid): Collection; /** * Removes a grid from the internal grid lookup. * @func _removeGrid * @memberof Collection * @param {Grid} grid The grid to remove. * @returns {Collection} * @private */ private static _removeGrid(grid: Grid): Collection; /** * Creates a pie chart from the collection. * @type {Overload} */ pieChart: Overload; /** * Creates a line chart from the collection. * @type {Overload} */ lineChart: Overload; /** * Creates an area chart from the collection. * @type {Overload} */ areaChart: Overload; /** * Creates a column chart from the collection. * @type {Overload} */ columnChart: Overload; /** * Creates a bar chart from the collection. * @type {Overload} */ barChart: Overload; /** * Creates a stacked bar chart from the collection. * @type {Overload} */ stackedBarChart: Overload; /** * Removes a chart from the page by it's selector. * @memberof Collection * @param {String} selector The chart selector. */ dropChart(selector: String): void; /** * Sync with this collection on the server-side. * @name sync * @method Collection.sync * @param {Function} callback The callback method to call once * the connection to the server has been established. */ static sync(callback: (() => any)): void; /** * Disconnects an existing connection to a sync server. * @returns {boolean} True if a connection existed, false * if no connection existed. */ unSync(): boolean; /** * Drop collection and persistent storage. * @name drop * @method Collection.drop */ static drop(): void; /** * Saves an entire collection's data to persistent storage. * @param {Function=} callback The method to call when the save function * has completed. */ save(callback?: (() => any)): void; /** * Loads an entire collection's data from persistent storage. * @param {Function=} callback The method to call when the load function * has completed. */ load(callback?: (() => any)): void; /** * Get the ODM instance for this collection. * @returns {Odm} */ odm(): Odm; /** * Adds a view to the internal view lookup. * @param {View} view The view to add. * @returns {Collection} * @private */ private _addOldView(view: View): Collection; /** * Removes a view from the internal view lookup. * @param {View} view The view to remove. * @returns {Collection} * @private */ private _removeOldView(view: View): Collection; /** * Gets the data that represents this collection for easy storage using * a third-party method / plugin instead of using the standard persistent * storage system. * @param {Function} callback The method to call with the data response. */ saveCustom(callback: (() => any)): void; /** * Loads custom data loaded by a third-party plugin into the collection. * @param {Object} myData Data object previously saved by using saveCustom() * @param {Function} callback A callback method to receive notification when * data has loaded. */ loadCustom(myData: Object, callback: (() => any)): void; /** * Creates a view and assigns the collection as its data source. * @param {String} name The name of the new view. * @param {Object} query The query to apply to the new view. * @param {Object} options The options object to apply to the view. * @returns {*} */ view(name: String, query: Object, options: Object): any; /** * Adds a view to the internal view lookup. * @param {View} view The view to add. * @returns {Collection} * @private */ private _addView: any; /** * Removes a view from the internal view lookup. * @param {View} view The view to remove. * @returns {Collection} * @private */ private _removeView: any; } /** * Creates a new collection group. Collection groups allow single operations to be * propagated to multiple collections at once. CRUD operations against a collection * group are in fed to the group's collections. Useful when separating out slightly * different data into multiple collections but querying as one collection. * @constructor */ declare class CollectionGroup { /** * Creates a new collection group. Collection groups allow single operations to be * propagated to multiple collections at once. CRUD operations against a collection * group are in fed to the group's collections. Useful when separating out slightly * different data into multiple collections but querying as one collection. * @constructor */ constructor(); /** * Gets / sets the primary key for this collection group. * @param {String=} keyName The name of the primary key. * @returns {*} */ primaryKey(keyName?: String): any; /** * Helper method that removes a document that matches the given id. * @param {String} id The id of the document to remove. */ removeById(id: String): void; /** * Uses the passed query to generate a new collection with results * matching the query parameters. * * @param query * @param options * @returns {*} */ subset(query: any, options: any): any; /** * Drops a collection group from the database. * @returns {boolean} True on success, false on failure. */ drop(): boolean; /** * Adds a view to the internal view lookup. * @param {View} view The view to add. * @returns {Collection} * @private */ private _addOldView(view: View): Collection; /** * Removes a view from the internal view lookup. * @param {View} view The view to remove. * @returns {Collection} * @private */ private _removeOldView(view: View): Collection; } /** * The condition class monitors a data source and updates it's internal * state depending on clauses that it has been given. When all clauses * are satisfied the then() callback is fired. If conditions were met * but data changed that made them un-met, the else() callback is fired. * @class * @constructor */ declare class Condition { /** * The condition class monitors a data source and updates it's internal * state depending on clauses that it has been given. When all clauses * are satisfied the then() callback is fired. If conditions were met * but data changed that made them un-met, the else() callback is fired. * @class * @constructor */ constructor(); /** * Class constructor calls this init method. * This allows the constructor to be overridden by other modules because * they can override the init method with their own. * @param {Collection|View} dataSource The condition's data source. * @param {String} id The id to assign to the new Condition. * @param {Object} clause The query clause. */ init(dataSource: (Collection|View), id: String, clause: Object): void; /** * Adds a new clause to the condition. * @param {Object} clause The query clause to add to the condition. * @returns {Condition} */ and(clause: Object): Condition; /** * Starts the condition so that changes to data will call callback * methods according to clauses being met. * @param {*} initialState Initial state of condition. * @returns {Condition} */ start(initialState: any): Condition; /** * Updates the internal status of all the clauses against the underlying * data source. * @private */ private _updateStates(): void; /** * Stops the condition so that callbacks will no longer fire. * @returns {Condition} */ stop(): Condition; /** * Drops the condition and removes it from memory. * @returns {Condition} */ drop(): Condition; } /** * Creates a new ForerunnerDB instance. Core instances handle the lifecycle of * multiple database instances. * @constructor */ declare class Core { /** * Creates a new ForerunnerDB instance. Core instances handle the lifecycle of * multiple database instances. * @constructor */ constructor(); /** * Returns the number of instantiated ForerunnerDB objects. * @returns {Number} The number of instantiated instances. */ instantiatedCount(): Number; /** * Get all instances as an array or a single ForerunnerDB instance * by it's array index. * @param {Number=} index Optional index of instance to get. * @returns {Array|Object} Array of instances or a single instance. */ instances(index?: Number): (Array|Object); /** * Get all instances as an array of instance names or a single ForerunnerDB * instance by it's name. * @param {String=} name Optional name of instance to get. * @returns {Array|Object} Array of instance names or a single instance. */ namedInstances(name?: String): (Array|Object); /** * Checks if a module has been loaded into the database. * @func moduleLoaded * @memberof Core * @param {String} moduleName The name of the module to check for. * @returns {Boolean} True if the module is loaded, false if not. */ static moduleLoaded(moduleName: String): Boolean; /** * Checks version against the string passed and if it matches (or partially matches) * then the callback is called. * @param {String} val The version to check against. * @param {Function} callback The callback to call if match is true. * @returns {Boolean} */ version(val: String, callback: (() => any)): Boolean; /** * Checks if the database is running on a client (browser) or * a server (node.js). * @returns {Boolean} Returns true if running on a browser. */ isClient(): Boolean; /** * Checks if the database is running on a client (browser) or * a server (node.js). * @returns {Boolean} Returns true if running on a server. */ isServer(): Boolean; /** * Added to provide an error message for users who have not seen * the new instantiation breaking change warning and try to get * a collection directly from the core instance. */ collection(): void; /** * Gets a database instance by name. * @memberof Core * @param {String=} name Optional name of the database. If none is provided * a random name is assigned. * @returns {Db} */ db(name?: String): Db; /** * Returns an array of databases that ForerunnerDB currently has. * @memberof Core * @param {String|RegExp=} search The optional search string or regular expression to use * to match collection names against. * @returns {Array} An array of objects containing details of each database * that ForerunnerDB is currently managing and it's child entities. */ databases(search: (String|RegExp)): Array; /** * Override the Core init to instantiate the plugin. * @returns {*} */ init(): any; } /** * Creates a new ForerunnerDB database instance. * @constructor */ declare class Db { /** * Creates a new ForerunnerDB database instance. * @constructor */ constructor(); /** * Get a collection with no name (generates a random name). If the * collection does not already exist then one is created for that * name automatically. * @name collection * @method Db.collection * @func collection * @memberof Db * @returns {Collection} */ static collection(): Collection; /** * Determine if a collection with the passed name already exists. * @memberof Db * @param {String} viewName The name of the collection to check for. * @returns {boolean} */ collectionExists(viewName: String): boolean; /** * Returns an array of collections the DB currently has. * @memberof Db * @param {String|RegExp=} search The optional search string or * regular expression to use to match collection names against. * @returns {Array} An array of objects containing details of each * collection the database is currently managing. */ collections(search: (String|RegExp)): Array; /** * Creates a new collectionGroup instance or returns an existing * instance if one already exists with the passed name. * @func collectionGroup * @memberOf Db * @param {String} name The name of the instance. * @returns {*} */ static collectionGroup(name: String): any; /** * Returns an array of collection groups the DB currently has. * @returns {Array} An array of objects containing details of each collection group * the database is currently managing. */ collectionGroups(): Array; /** * Checks if a module has been loaded into the database. * @func moduleLoaded * @memberof Db * @param {String} moduleName The name of the module to check for. * @returns {Boolean} True if the module is loaded, false if not. */ static moduleLoaded(moduleName: String): Boolean; /** * Checks version against the string passed and if it matches (or partially matches) * then the callback is called. * @param {String} val The version to check against. * @param {Function} callback The callback to call if match is true. * @returns {Boolean} */ version(val: String, callback: (() => any)): Boolean; /** * Returns true if ForerunnerDB is running on a client browser. * @returns {boolean} */ isClient(): boolean; /** * Returns true if ForerunnerDB is running on a server. * @returns {boolean} */ isServer(): boolean; /** * Converts a normal javascript array of objects into a DB collection. * @param {Array} arr An array of objects. * @returns {Collection} A new collection instance with the data set to the * array passed. */ arrayToCollection(arr: Array): Collection; /** * Emits an event by name with the given data. * @param {String} event The name of the event to emit. * @param {*=} data The data to emit with the event. * @returns {*} */ peek(event: String, data?: any): any; /** * Find all documents across all collections in the database that match the passed * string or search object and return them in an object where each key is the name * of the collection that the document was matched in. * @param search String or search object. * @returns {Object} */ peekCat(search: any): Object; /** * Drops the database. * @func drop * @memberof Db */ static drop(): void; /** * Creates a new document instance or returns an existing * instance if one already exists with the passed name. * @func document * @memberOf Db * @param {String} name The name of the instance. * @returns {*} */ static document(name: String): any; /** * Returns an array of documents the DB currently has. * @func documents * @memberof Db * @returns {Array} An array of objects containing details of each document * the database is currently managing. */ static documents(): Array; /** * Determine if a grid with the passed name already exists. * @func gridExist