Reference Source
public class | source

DataStore

Extends:

Loggable → DataStore

DataStore class.

Example:

	API:
		->constructor()
		
		// DATA ADAPTERS MANAGEMENT
		->add_adapter(arg_adapter):boolean
		->remove_adapter(arg_adapter):boolean
		->suspend_adapter(arg_adapter):boolean
		->resume_adapter(arg_adapter):boolean
		
		// DATA COLLECTIONS MANAGEMENT
		->get_collection(arg_model_name):DataCollection - get a data collection for a model.
		->add_collection(arg_collection):boolean - add a data collection.
		->remove_collection(arg_collection):boolean - remove a data collection.

		// WRAPPERS FOR DATA COLLECTIONS OPERATIONS
		->create_record(arg_collection_name, arg_record_id, arg_record_datas):Promise(DataRecord) - create a new data record.
		->delete_record(arg_collection_name, arg_record_id):Promise(boolean) - delete an existing data record.
		->update_record(arg_collection_name, arg_record_id, arg_record_datas):Promise(DataRecord) - update an existing data record.
		->has_record(arg_collection_name, arg_record_id):Promise(boolean) - test if a data record exists with an id.
		
		->find_one_record(arg_collection_name, arg_record_id):Promise(DataRecord) - find an existing data record with an id.
		->find_records(arg_collection_name, arg_query):Promise(DataRecordArray) - find existing data records with a query.
		->find_all_records(arg_collection_name):Promise(DataRecordArray) - find all xisting data records.


	USAGE ON BROWSER:
		var memory_cache = new CacheAdapterNodeCache( {ttl:5000, check_period:2000} )
		var cache_manager = new CacheManager([memory_cache])

		var rest_settings = {...}
		var models_settings = {...}
		var rest_adapter = new DataAdapterRest(rest_settings, models_settings)
		var ds = new DataStore(cache_manager, [rest_adapter])
		ds.set_tenant('my tenant')
		ds.set_credentials('*', app.get_credentials())
		ds.set_credentials('cars', {token:'...'} )
		
		var cars = ds.get_collection('cars')
		var car_12 = cars.find_one_record('12')

		or

		var car_13 = ds.find_one_record('cars', '13')
		
		var car_14 = ds.create_record('cars', '14', { engine:'gazol', color:'red' } )
Each application on the browser has credentials for one tenant.

Constructor Summary

Public Constructor
public

constructor(arg_cache_manager: CacheManager, arg_data_adapters: array): nothing

Data store class is the main interface between datas consumers (views) and producers (adapters).

Member Summary

Public Members
public

Class type flag.

Private Members
private

_adapters: array

Datas adapters array.

private

CacheManager instance.

private

Adapter collections map.

Method Summary

Public Methods
public

Add a data adapter.

public

Add a data collection.

public

create_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise

Create a data collection record.

public

delete_record(arg_collection_name: string, arg_record_id: string): Promise

Delete a data collection record.

public

find_all_records(arg_collection_name: string): Promise

Find all existing data records.

public

find_one_record(arg_collection_name: string, arg_record_id: string): Promise

Find an existing data record with an id.

public

find_records(arg_collection_name: string, arg_query: DataQuery): Promise

Find existing data records with a query.

public

Get a data collection for a model.

public

has_record(arg_collection_name: string, arg_record_id: string): Promise

Update a data collection record.

public

Remove a data adapter.

public

Remove a data collection.

public

Resume a data adapter.

public

Suspend a data adapter.

public

update_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise

Update a data collection record.

Private Methods
private

_emit(arg_event: string, arg_datas: any): nothing

Emit on event.

Inherited Summary

From class Loggable
public

Log context.

public

Class type flag.

public

Trace is enabled for this flag.

private

Logger manager instance (default undefined)

public

debug(args: string | array): nothing

Trace DEBUG formatted message.

public

disable_trace(): nothing

Disable traces.

public

enable_trace(): nothing

Enable traces.

public

enter_group(arg_group: string): nothing

Trace INFO message on "enter trace group".

public

error(args: string | array): nothing

Trace ERROR formatted message.

public

Define get class name method for non Instance classes.

public

Get instance context.

public

Get logger manager.

public

Define get instance name method for non Instance classes.

public

Get trace flag.

public

info(args: string | array): nothing

Trace INFO formatted message.

public

leave_group(arg_group: string): nothing

Trace INFO message on "leave trace group".

public

separate_level_1(): nothing

Trace INFO trace level 1 separator.

public

separate_level_2(): nothing

Trace INFO trace level 2 separator.

public

separate_level_3(): nothing

Trace INFO trace level 3 separator.

public

set_trace(arg_value: boolean): nothing

Set trace flag.

public

should_trace(arg_traces_cfg: object): boolean

Calculate should trace flag.

public

should_trace_class(arg_traces_cfg: object): boolean

Calculate should trace flag for classes.

public

should_trace_collection_item(arg_traces_cfg: object, arg_collection_name: string, arg_this_item_accessor: string): boolean

Calculate should trace flag for given collection of names or patterns.

public

should_trace_module(arg_traces_cfg: object): boolean

Calculate should trace flag for modules.

public

should_trace_name(arg_traces_cfg: object): boolean

Calculate should trace flag for instances names.

public

Toggle trace flag.

public

Update trace enabled flag.

public

warn(args: string | array): nothing

Trace WARN formatted message.

Public Constructors

public constructor(arg_cache_manager: CacheManager, arg_data_adapters: array): nothing source

Data store class is the main interface between datas consumers (views) and producers (adapters).

Override:

Loggable#constructor

Params:

NameTypeAttributeDescription
arg_cache_manager CacheManager

cache manager instance.

arg_data_adapters array

data adapters array.

Return:

nothing

Public Members

public is_data_store: boolean source

Class type flag.

Private Members

private _adapters: array source

Datas adapters array.

private _cache_manager: CacheManager source

CacheManager instance.

private _collections: object source

Adapter collections map.

Public Methods

public add_adapter(arg_adapter: DataAdapter): boolean source

Add a data adapter.

Params:

NameTypeAttributeDescription
arg_adapter DataAdapter

data adapter.

Return:

boolean

public add_collection(arg_collection: DataCollection): boolean source

Add a data collection.

Params:

NameTypeAttributeDescription
arg_collection DataCollection

data collection.

Return:

boolean

public create_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise source

Create a data collection record.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_record_id string

data record id.

arg_record_datas object

data record datas.

Return:

Promise

Promise of a DataRecord object.

public delete_record(arg_collection_name: string, arg_record_id: string): Promise source

Delete a data collection record.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_record_id string

data record id.

Return:

Promise

Promise of boolean success.

public find_all_records(arg_collection_name: string): Promise source

Find all existing data records.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

Return:

Promise

Promise of DataRecordArray.

public find_one_record(arg_collection_name: string, arg_record_id: string): Promise source

Find an existing data record with an id.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_record_id string

data record id.

Return:

Promise

Promise of DataRecord.

public find_records(arg_collection_name: string, arg_query: DataQuery): Promise source

Find existing data records with a query.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_query DataQuery

data query.

Return:

Promise

Promise of DataRecordArray.

public get_collection(arg_model_name: string): DataCollection | undefined source

Get a data collection for a model.

Params:

NameTypeAttributeDescription
arg_model_name string

data collection model name.

public has_record(arg_collection_name: string, arg_record_id: string): Promise source

Update a data collection record.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_record_id string

data record id.

Return:

Promise

Promise of boolean found:true, not found:false.

public remove_adapter(arg_adapter: DataAdapter): boolean source

Remove a data adapter.

Params:

NameTypeAttributeDescription
arg_adapter DataAdapter

data adapter.

Return:

boolean

public remove_collection(arg_collection: DataCollection): boolean source

Remove a data collection.

Params:

NameTypeAttributeDescription
arg_collection DataCollection

data collection.

Return:

boolean

public resume_adapter(arg_adapter: DataAdapter): boolean source

Resume a data adapter.

Params:

NameTypeAttributeDescription
arg_adapter DataAdapter

data adapter.

Return:

boolean

public suspend_adapter(arg_adapter: DataAdapter): boolean source

Suspend a data adapter.

Params:

NameTypeAttributeDescription
arg_adapter DataAdapter

data adapter.

Return:

boolean

public update_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise source

Update a data collection record.

Params:

NameTypeAttributeDescription
arg_collection_name string

data collection name.

arg_record_id string

data record id.

arg_record_datas object

data record datas.

Return:

Promise

Promise of boolean success.

Private Methods

private _emit(arg_event: string, arg_datas: any): nothing source

Emit on event.

Params:

NameTypeAttributeDescription
arg_event string

event name.

arg_datas any

event datas (optional, default:undefined).

Return:

nothing