dynamic-record
Version:
A bare minimum Javascript implementation of the Active Record pattern
60 lines (59 loc) • 2.04 kB
TypeScript
import { ModelConstructor } from "./DynamicRecord";
export declare abstract class DynamicCollection<DataObject extends object> extends Array {
/**
* **(DEPRECATED - Use `createCollection()` instead)**
*
* Creates a new DynamicCollection instance.
*
* DynamicCollection is an extension of the native Array object thus
* implementing all of Array's methods and properties.
*
* @name DynamicCollection
* @constructor
* @extends Array
* @param {DynamicRecord.Model} Model The Model constructor to use for
* this collection
*/
constructor(Model: ModelConstructor, ...data: DataObject[]);
/**
* Returns a native array of data objects
*
* @name data
* @memberOf DynamicCollection
* @type Array
*/
get data(): Array<DataObject>;
/**
* Converts an array of objects into a DynamicCollection. If an element in
* the array is not an object, it will be skipped.
*
* @method fromArray
* @memberOf DynamicCollection
* @static
* @param {Array} array Array to be converted into a DynamicCollection
* @return {DynamicCollection}
*/
static fromArray<DataObject extends object>(arr: Array<DataObject>, Model: ModelConstructor): void;
/**
* Save all the model instances in the DynamicCollection.
*
* Simply calls all the individual model's `save()` method.
*
* @method saveAll
* @memberOf DynamicCollection
* @instance
* @return {Promise} - Return promise of this DynamicCollection instance
*/
saveAll(): Promise<DynamicCollection<DataObject>>;
/**
* Destroy all the model instances in the DynamicCollection.
*
* Simply calls all the individual model's `destroy()` method.
*
* @method dropAll
* @memberOf DynamicCollection
* @instance
* @return {Promise} - Return promise of this DynamicCollection instance
*/
dropAll(): Promise<DynamicCollection<DataObject>>;
}