Reference Source
public class | source

DataAdapter

Extends:

Loggable → DataAdapter

DataAdapter class.

Example:

	API:
		->constructor(arg_database, arg_models_schemas)
		
		->suspend()
		->resume()

		->add_model_schema(arg_model_schema)
		->remove_model_schema(arg_model_name)
		->get_model_schema(arg_model_name):TopologyRuntimeModelSchema

		->get_collection(arg_model_name):DataCollection

		->load_database(arg_topology_database)
		->load_model(arg_model_schema)
		->unload_model(arg_model_name)
		->load_associations()

 	->new_record(arg_model_name, arg_record_datas, arg_record_id):DataRecord - create a new data record instance, not saved.
 	->delete_record(arg_model_name, arg_record_id):Promise(boolean) - delete an existing data record.
		->update_record(arg_model_name, arg_record_datas, arg_record_id):Promise(DataRecord) - update an existing data record.
		->has_record(arg_model_name, arg_record_id):Promise(boolean) - test if a data record exists with an id.
		
		->find_one_record(arg_model_name, arg_record_id):Promise(DataRecord) - find an existing data record with an id.
		->find_or_create_record(arg_model_name, arg_record_id):Promise(DataRecord) - find an existing data record with an id.
		->find_records(arg_model_name, arg_query):Promise(DataRecordArray) - find existing data records with a query.
		->find_all_records(arg_model_name):Promise(DataRecordArray) - find all xisting data records.

	PRIVATE:
		->_emit(arg_event, arg_datas=undefined):nothing


	USAGE ON BROWSER:
		see DataStore

Constructor Summary

Public Constructor
public

constructor(arg_cache_manager: CacheManager, arg_database: TopologyRuntimeDatabase, arg_models_schemas: object): nothing

DataAdapter class is responsible to manage one source of records for many model.

Member Summary

Public Members
public

Database promise.

public

Class type flag.

Private Members
private

CacheManager instance.

private

Adapter collections map.

private

Adapter includes map.

private

Adapter roles map.

private

_topology_database: TopologyRuntimeDatabase

Topology database instance.

private

Topology models array.

private

Topology models map.

Method Summary

Public Methods
public

add_model_schema(arg_model_schema: TopologyRuntimeModelSchema): Promise

Add a model schema.

public

create_record(arg_model_name: string, arg_record_datas: object): Promise

Create a new data record.

public

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

Delete an existing data record.

public

find_all_records(arg_model_name: string): Promise

Find all existing data records.

public

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

Find an existing data record with an id.

public

find_or_create_record(arg_model_name: string, arg_record_datas: object, arg_record_id: string): Promise

Find an existing data record with an id or create it with given datas.

public

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

Find existing data records corresponding to the given query.

public

Get a collection for a registered model schema.

public

get_model_schema(arg_model_name: string): TopologyRuntimeModelSchema

Get a registered model schema.

public

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

Test if a data record exists with an id.

public

Load associations between models.

public

load_database(arg_topology_database: TopologyRuntimeDatabase): Promise

Load adapter topology database.

public

load_model(arg_model_schema: TopologyRuntimeModelSchema): Promise

Load model.

public

new_record(arg_model_name: string, arg_record_datas: object, arg_record_id: string): Promise

Create a new data record instance, not saved.

public

remove_model_schema(arg_model_name: string): Promise

Remove a model schema.

public

Resume adapter work.

public

Suspend adapter work.

public

unload_model(arg_model_name: string): Promise

Unload model.

public

update_record(arg_model_name: string, arg_record_datas: object): Promise

Update an existing data 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_database: TopologyRuntimeDatabase, arg_models_schemas: object): nothing source

DataAdapter class is responsible to manage one source of records for many model. DataAdapter instances are managed by a DataStore instance.

Override:

Loggable#constructor

Params:

NameTypeAttributeDescription
arg_cache_manager CacheManager

cache manager instance.

arg_database TopologyRuntimeDatabase

topology database.

arg_models_schemas object

topology models schemas array.

Return:

nothing

Public Members

public database_promise: Promise source

Database promise.

public is_data_adapter: boolean source

Class type flag.

Private Members

private _cache_manager: CacheManager source

CacheManager instance.

private _collections: object source

Adapter collections map.

private _includes: object source

Adapter includes map.

private _roles: object source

Adapter roles map.

private _topology_database: TopologyRuntimeDatabase source

Topology database instance.

private _topology_models_array: array source

Topology models array.

private _topology_models_map: object source

Topology models map.

Public Methods

public add_model_schema(arg_model_schema: TopologyRuntimeModelSchema): Promise source

Add a model schema.

Params:

NameTypeAttributeDescription
arg_model_schema TopologyRuntimeModelSchema

topology model schema.

Return:

Promise

Promise(boolean)

public create_record(arg_model_name: string, arg_record_datas: object): Promise source

Create a new data record.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_datas object

new record attributes.

Return:

Promise

Promise(boolean)

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

Delete an existing data record.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_id string

new record unique id (optional).

Return:

Promise

Promise(boolean)

public find_all_records(arg_model_name: string): Promise source

Find all existing data records.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

Return:

Promise

Promise(DataRecordArray)

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

Find an existing data record with an id.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_id string

new record unique id.

Return:

Promise

Promise(DataRecord)

public find_or_create_record(arg_model_name: string, arg_record_datas: object, arg_record_id: string): Promise source

Find an existing data record with an id or create it with given datas.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_datas object

new record attributes.

arg_record_id string

new record unique id.

Return:

Promise

Promise(DataRecord)

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

Find existing data records corresponding to the given query.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_query DataQuery

data query instance.

Return:

Promise

Promise(DataRecordArray)

public get_collection(arg_model_name: string): DataCollection source

Get a collection for a registered model schema.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

Return:

DataCollection

model collection instance.

public get_model_schema(arg_model_name: string): TopologyRuntimeModelSchema source

Get a registered model schema.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

Return:

TopologyRuntimeModelSchema

model schema.

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

Test if a data record exists with an id.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_id string

new record unique id.

Return:

Promise

Promise(boolean)

public load_associations(): Promise source

Load associations between models.

Return:

Promise

Promise(boolean)

public load_database(arg_topology_database: TopologyRuntimeDatabase): Promise source

Load adapter topology database.

Params:

NameTypeAttributeDescription
arg_topology_database TopologyRuntimeDatabase

topology database.

Return:

Promise

Promise(boolean)

public load_model(arg_model_schema: TopologyRuntimeModelSchema): Promise source

Load model.

Params:

NameTypeAttributeDescription
arg_model_schema TopologyRuntimeModelSchema

topology model schema.

Return:

Promise

Promise(boolean)

public new_record(arg_model_name: string, arg_record_datas: object, arg_record_id: string): Promise source

Create a new data record instance, not saved.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_datas object

new record attributes.

arg_record_id string

new record unique id (optional).

Return:

Promise

Promise(DataRecord)

public remove_model_schema(arg_model_name: string): Promise source

Remove a model schema.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

Return:

Promise

Promise(boolean)

public resume(): Promise source

Resume adapter work.

Return:

Promise

Promise(boolean) with true: resume is success, false for failure

public suspend(): Promise source

Suspend adapter work.

Return:

Promise

Promise(boolean) with true: suspend is success, false for failure

public unload_model(arg_model_name: string): Promise source

Unload model.

Params:

NameTypeAttributeDescription
arg_model_name string

model name.

Return:

Promise

Promise(boolean)

public update_record(arg_model_name: string, arg_record_datas: object): Promise source

Update an existing data record.

Params:

NameTypeAttributeDescription
arg_model_name string

topology model name.

arg_record_datas object

new record attributes.

Return:

Promise

Promise(boolean)

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