Creates a new instance of the persistence.
(optional) a persister component that loads and saves data from/to flat file.
Clears component state.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Closes component and frees used resources.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Configures component by passing configuration parameters.
configuration parameters to be set.
Creates a data item.
an item to be created.
(optional) callback function that receives created item or error.
Deletes data items that match to a given filter.
This method shall be called by a public deleteByFilter method from child class that receives FilterParams and converts them into a filter function.
(optional) transaction id to trace execution through call chain.
(optional) a filter function to filter items.
(optional) callback function that receives error or null for success.
Deleted a data item by it's unique id.
an id of the item to be deleted
(optional) callback function that receives deleted item or error.
Deletes multiple data items by their unique ids.
(optional) transaction id to trace execution through call chain.
ids of data items to be deleted.
(optional) callback function that receives error or null for success.
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public getListByFilter method from child class that receives FilterParams and converts them into a filter function.
(optional) transaction id to trace execution through call chain.
(optional) a filter function to filter items
(optional) sorting parameters
(optional) projection parameters (not used yet)
callback function that receives a data list or error.
Gets a list of data items retrieved by given unique ids.
(optional) transaction id to trace execution through call chain.
ids of data items to be retrieved
callback function that receives a data list or error.
Gets a data item by its unique id.
(optional) transaction id to trace execution through call chain.
an id of data item to be retrieved.
callback function that receives data item or error.
Gets a random item from items that match to a given filter.
This method shall be called by a public getOneRandom method from child class that receives FilterParams and converts them into a filter function.
(optional) transaction id to trace execution through call chain.
(optional) a filter function to filter items.
callback function that receives a random item or error.
Gets a page of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public getPageByFilter method from child class that receives FilterParams and converts them into a filter function.
(optional) transaction id to trace execution through call chain.
(optional) a filter function to filter items
(optional) paging parameters
(optional) sorting parameters
(optional) projection parameters (not used yet)
callback function that receives a data page or error.
Checks if the component is opened.
true if the component has been opened and false otherwise.
Opens the component.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Saves items to external data source using configured saver component.
(optional) transaction id to trace execution through call chain.
(optional) callback function that receives error or null for success.
Sets a data item. If the data item exists it updates it, otherwise it create a new data item.
a item to be set.
(optional) callback function that receives updated item or error.
Sets references to dependent components.
references to locate the component dependencies.
Updates a data item.
an item to be updated.
(optional) callback function that receives updated item or error.
Updates only few selected fields in a data item.
an id of data item to be updated.
a map with fields to be updated.
callback function that receives updated item or error.
Generated using TypeDoc
Abstract persistence component that stores data in flat files and implements a number of CRUD operations over data items with unique ids. The data items must implement IIdentifiable interface.
In basic scenarios child classes shall only override getPageByFilter, getListByFilter or deleteByFilter operations with specific filter function. All other operations can be used out of the box.
In complex scenarios child classes can implement additional operations by accessing cached items via this._items property and calling save method on updates.
JsonFilePersister
MemoryPersistence
Configuration parameters
References
*:logger:*:*:1.0
(optional) ILogger components to pass log messagesExamples
class MyFilePersistence extends IdentifiableFilePersistence<MyData, string> { public constructor(path?: string) { super(new JsonPersister(path)); } private composeFilter(filter: FilterParams): any { filter = filter || new FilterParams(); let name = filter.getAsNullableString("name"); return (item) => { if (name != null && item.name != name) return false; return true; }; } public getPageByFilter(correlationId: string, filter: FilterParams, paging: PagingParams, callback: (err: any, page: DataPage<MyData>) => void): void { super.getPageByFilter(correlationId, this.composeFilter(filter), paging, null, null, callback); } } let persistence = new MyFilePersistence("./data/data.json"); persistence.create("123", { id: "1", name: "ABC" }, (err, item) => { persistence.getPageByFilter( "123", FilterParams.fromTuples("name", "ABC"), null, (err, page) => { console.log(page.data); // Result: { id: "1", name: "ABC" } persistence.deleteById("123", "1", (err, item) => { ... }); } ) });