Class

BaseResource

(abstract) BaseResource

Representation of a ORM Resource in AdminBro. Visually resource is a list item in the sidebar. Each resource has many records and many properties.

Analogy is REST resource.

It is an abstract class and all database adapters should implement extend it implement following methods:

Methods

# abstract static isAdapterFor(rawResource) → {Boolean}

Checks if given adapter supports resource provided by the user

Parameters:
Name Type Description
rawResource any

resource provided in AdminBroOptions#resources array

View Source admin-bro/src/backend/adapters/base-resource.ts, line 46

if given adapter supports this resource - returns true

Boolean

# assignDecorator(Decorator, admin, optionsopt)

Assigns given decorator to the Resource. Than it will be available under resource.decorate() method

Parameters:
Name Type Attributes Description
Decorator BaseDecorator
admin AdminBro

current instance of AdminBro

options ResourceOptions <optional>

View Source admin-bro/src/backend/adapters/base-resource.ts, line 229

# build(params) → {BaseRecord}

Builds new Record of given Resource.

Each Record is an representation of the resource item. Before it can be saved, it has to be instantiated.

Parameters:
Name Type Description
params Record.<string, any>

View Source admin-bro/src/backend/adapters/base-resource.ts, line 183

BaseRecord

# async abstract count(filter) → {Promise.<Number>}

Returns number of elements for given resource by including filters

Parameters:
Name Type Description
filter Filter

represents what data should be included

View Source admin-bro/src/backend/adapters/base-resource.ts, line 113

Promise.<Number>

# async abstract create(params) → {Promise.<Object>}

Creates new record

Parameters:
Name Type Description
params Record.<string, any>

View Source admin-bro/src/backend/adapters/base-resource.ts, line 195

If there are validation errors it should be thrown

created record converted to raw Object which can be used to initiate new BaseRecord instance

Promise.<Object>

# abstract databaseName() → {String}

The name of the database to which resource belongs. When resource is a mongoose model it should be database name of the mongo database.

Visually, by default, all resources are nested in sidebar under their database names.

View Source admin-bro/src/backend/adapters/base-resource.ts, line 57

database name

String

# databaseType() → {String}

Returns type of the database. It is used to compute sidebar icon for given resource. Default: 'database'

View Source admin-bro/src/backend/adapters/base-resource.ts, line 65

String

# decorate() → {BaseDecorator|null}

Gets decorator object for given resource

View Source admin-bro/src/backend/adapters/base-resource.ts, line 236

BaseDecorator | null

# async abstract delete(id)

Delete given record by id

Parameters:
Name Type Description
id String | Number

id of the Record

View Source admin-bro/src/backend/adapters/base-resource.ts, line 218

If there are validation errors it should be thrown

# async abstract find(filters, options) → {Promise.<Array.<BaseRecord>>}

Returns actual records for given resource

Parameters:
Name Type Attributes Description
filters Filter

what data should be included

options Object
limit Number <optional>

how many records should be taken

offset Number <optional>

offset

sort Object <optional>

sort

sort.sortBy Number <optional>

sortable field

sort.direction Number <optional>

either asc or desc

View Source admin-bro/src/backend/adapters/base-resource.ts, line 135

list of records

Promise.<Array.<BaseRecord>>
Example
// filters example
{
   name: 'Tom',
   createdAt: { from: '2019-01-01', to: '2019-01-18' }
}

# async findMany(list) → {Promise.<Array.<BaseRecord>>}

Finds many records based on the resource ids

Parameters:
Name Type Description
list Array.<string>

of ids to find

View Source admin-bro/src/backend/adapters/base-resource.ts, line 171

records

Promise.<Array.<BaseRecord>>

# async abstract findOne(id) → {Promise.<BaseRecord>}

Finds one Record in the Resource by its id

Parameters:
Name Type Description
id String

uniq id of the Resource Record

View Source admin-bro/src/backend/adapters/base-resource.ts, line 161

record

Promise.<BaseRecord>

# abstract id() → {String}

Each resource has to have uniq id which will be put to an URL of AdminBro routes. For instance in Router path for the new form is /resources/{resourceId}/new

View Source admin-bro/src/backend/adapters/base-resource.ts, line 85

uniq resource id

String

# abstract name() → {String}

Return name of the resource. It could be a table name in SQL database, or collection name in mongoDB.

Visually it will be shown as the name of the resource in the UI.

View Source admin-bro/src/backend/adapters/base-resource.ts, line 76

String

# async populate(records, property) → {Promise.<Array.<BaseRecord>>}

Populates records with references for given property.

Example: Let say resource Article has property user_id and it is a reference to User resource. When you call this User.populate([...articleRecords], userIdProperty) it should populate articleRecords with corresponding users. So after that invoking articleRecord.populated['user_id'] will return the user Record

Parameters:
Name Type Description
records Array.<BaseRecord>

all records which should be populated

property BaseProperty

property which is a reference to this Resource

View Source admin-bro/src/backend/adapters/base-resource.ts, line 151

populated records

Promise.<Array.<BaseRecord>>

# abstract properties() → {Array.<BaseProperty>}

returns array of all properties which belongs to resource

View Source admin-bro/src/backend/adapters/base-resource.ts, line 93

Array.<BaseProperty>

# abstract property(path) → {BaseProperty}

returns property object for given field

Parameters:
Name Type Description
path String

path/name of the property. Take a look at BaseProperty to learn more about property paths.

View Source admin-bro/src/backend/adapters/base-resource.ts, line 104

BaseProperty

# async abstract update(id, params) → {Promise.<Object>}

Updates an object

Parameters:
Name Type Description
id String

uniq id of the Resource Record

params Record.<string, any>

View Source admin-bro/src/backend/adapters/base-resource.ts, line 208

If there are validation errors it should be thrown

created record converted to raw Object which can be used to initiate new BaseRecord instance

Promise.<Object>