API Docs for: 0.8.0
Show:

BaseObjectService Class

Provides functionality to perform CRUD operations on collections. It also allows for plugins to register for events in order to interact with objects as they are being processed. This makes it possible to add, remove, or modify fields before they are passed to the entity that triggered the operation.

Constructor

BaseObjectService

(
  • context
)

Parameters:

  • context Object
    • type String

Methods

_emit

(
  • event
  • data
  • cb
)
protected

Parameters:

  • event String
  • data Object
  • cb Function

_get

(
  • id
  • [options]
  • cb
)
protected

Parameters:

  • id String
  • [options] Object optional
  • cb Function

_retrieveOnUpdateAndMerge

(
  • dto
  • options
  • cb
)
private

When an ID is available in the DTO the function attempts to retrieve the existing object. If it is not available a new object is created. The merge event is then called. After the merge is complete the callback is executed with the merged object.

Parameters:

  • dto Object
  • options Object
    • [isCreate] Boolean optional
  • cb Function

add

(
  • dto
  • [options]
  • cb
)

Attempts to persist the DTO as an add. The function executes a series of events:

  1. The format event is fired
  2. When an ID is provided the object is retrieved from the database otherwise a new object is created.
  3. The merge event is triggered
  4. The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error.
  5. The beforeSave event is triggered
  6. The object is persisted
  7. The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

consolidateValidationResults

(
  • results
)
Array static

Inspects the raw set of validation results to ensure that plugins that don't follow proper procedure have their results excluded.

Parameters:

  • results Array

Returns:

Array:

count

(
  • [options]
  • cb
)

Executes a count of resources against the persistence layer. The function will callback with an array of results.

Parameters:

  • [options] Object optional
    • [where] Object optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the number of results that match the specified query

deleteById

(
  • id
  • options
  • cb
)

Deletes an object by ID

Parameters:

  • id String
  • options Object
  • cb Function

deleteSingle

(
  • [options]
  • cb
)

Deletes a single item based on the specified query in the options

Parameters:

  • [options] Object optional

    See BaseObjectService#getSingle

    • [where] Object optional
  • cb Function

get

(
  • id
  • [options]
  • cb
)

Retrieves a resource by ID. The function will callback with the object that was found or NULL if no object could be found. The function will trigger the "get" event.

Parameters:

  • id String
  • [options] Object optional
  • cb Function

    (Error, object|null) A callback that takes two parameters. The first is an error, if occurred. The second is the object with the specified ID

getAll

(
  • [options]
  • cb
)

Executes a query for resources against the persistence layer. The function will callback with an array of results. The function will trigger the "getAll" event. Also note that there is hard limit on the number of results the returned.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [limit] Integer optional
    • [offset] Integer optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is an array representing the results of the query.

getAllWithCount

(
  • [options]
  • cb
)

Executes a query for resources against the persistence layer. The function will callback with an object that contains a total count and an array of results. The function will trigger the "getAll" event. Also note that there is hard limit on the number of results the returned.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [limit] Integer optional
    • [offset] Integer optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is an object representing the results of the query.

getContentSanitizationRules

() Object static

The sanitization rules that apply to Pages, Articles, and other fields that are allowed to have HTML

Returns:

Object:

getContext

(
  • [data]
)
Object

Retrieves a context object to be passed to event listeners

Parameters:

  • [data] String | Object | Number | Boolean optional

Returns:

Object:

getDate

(
  • dateStr
)
Date static

Parses an ISO date string. When an invalid date string is pass a NULL value is returned.

Parameters:

  • dateStr String

Returns:

Date:

getDefaultSanitizationRules

() Object static

Retrieves the default sanitization rules for string fields.

Returns:

Object:

getIdWhere

(
  • dto
)
Object

Creates the where clause that creates a lookup by the key that indicates uniqueness for the collection

Parameters:

  • dto Object

Returns:

Object:

getLimit

(
  • limit
)
Integer static

Determines the maximum number of results that can be returned for a query. The specified limit must be a positive integer. The result will be the minimum of the MAX_RESULTS constant and the specified limit.

Parameters:

  • limit Integer

Returns:

Integer:

getPagedResult

(
  • dataArray
  • total
  • [limit]
  • [offset]
)
static

Builds a paged result object

Parameters:

  • dataArray Array

    The array of items to return

  • total Integer

    The total number of items available in the collection

  • [limit] Integer optional

    The maximum number of items to return

  • [offset] Integer optional

    The number of items skipped

getSingle

(
  • [options]
  • cb
)

Retrieves a single resource by the specified query. The function will callback with the object that was found or NULL if no object could be found. The function will trigger the "getAll" event.

Parameters:

  • [options] Object optional
    • [select] Object optional
    • [where] Object optional
    • [order] Array optional
    • [offset] Integer optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

getType

() String

Retrieves the object type supported by the service

Returns:

String:

The object type supported

listeners

(
  • event
)
Array static

Returns a list of the listeners for the specified event

Parameters:

  • event String

Returns:

Array:

notFound

(
  • [message]
)
Error deprecated static

Defined in include/service/base_object_service.js:774

Deprecated: Will be removed in 1.0

Creates a new Error representative of the inability to locate the requested resource

Parameters:

  • [message] String optional

Returns:

Error:

on

(
  • event
  • listener
)
static

Registers a listener for the specified event.

Parameters:

  • event String
  • listener Function

Returns:

:

once

(
  • event
  • listener
)
static

Registers a listener to fire a single time for the specfied event

Parameters:

  • event String
  • listener Function

Returns:

:

parseBoolean

(
  • val
)
Boolean static

Extracts a boolean value from the provided value. Null or undefined values will return false. Strings of '1' or 'true' (case sensitive) will return TRUE. All other values will return false.

Parameters:

  • val String | Boolean

Returns:

Boolean:

removeAllListeners

(
  • event
)
static

Removes all listeners for the specified event

Parameters:

  • event String

Returns:

:

removeListener

(
  • event
  • listener
)
static

Removes the listener from the specified event

Parameters:

  • event String
  • listener Function

Returns:

:

sanitize

(
  • value
  • [config]
)
String static

Strips HTML formatting from a string value

Parameters:

  • value String
  • [config] Object optional

Returns:

String:

save

(
  • dto
  • [options]
  • cb
)

Attempts to persist the DTO. The function executes a series of events:

  1. The format event is fired
  2. When an ID is provided the object is retrieved from the database otherwise a new object is created.
  3. The merge event is triggered
  4. The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error.
  5. The beforeSave event is triggered
  6. The object is persisted
  7. The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
    • [isCreate] Boolean optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

setDefaultSanitizationRules

(
  • rules
)
static

Sets a system-wide override for the default set of sanitization rules. The function will throw if a non-object is passed. NULL can be used to reset any override that is put into place.

Parameters:

  • rules Object

setDefaultSanitizationRules

(
  • rules
)
static

Sets a system-wide override for the set of sanitization rules for content. The function will throw if a non-object is passed. NULL can be used to reset any override that is put into place.

Parameters:

  • rules Object

setMaxListeners

(
  • n
)
EventEmitter static

Sets the maximum number of listeners for the emitter

Parameters:

  • n Integer

Returns:

EventEmitter:

update

(
  • dto
  • [options]
  • cb
)

Attempts to persist the DTO as an update. The function executes a series of events:

  1. The format event is fired
  2. When an ID is provided the object is retrieved from the database otherwise a new object is created.
  3. The merge event is triggered
  4. The validate event is triggered. If validation errors are detected the process halts and the function calls back with an error.
  5. The beforeSave event is triggered
  6. The object is persisted
  7. The afterSave event is triggered

Parameters:

  • dto Object
  • [options] Object optional
  • cb Function

    A callback that takes two parameters. The first is an error, if occurred. The second is the object that matches the specified query

validationError

(
  • validationFailures
)
Error static

Creates a new Error representative of a validation error

Parameters:

  • validationFailures Array | String

Returns:

Error:

validationFailure

(
  • field
  • message
  • [code]
)
static

Creates a properly formed validation failure

Parameters:

  • field String
  • message String
  • [code] String optional

Properties

AFTER_DELETE

String static

The event that is triggered when the delete function is called and after the delete operation has completed successfully.

AFTER_SAVE

String static

The event that is triggered when a DTO is passed to the save function and after the save operation has completed successfully.

BEFORE_COUNT

String static

The event that is triggered before the count query is executed

BEFORE_DELETE

String static

The event that is triggered when the delete function is called.

BEFORE_GET

String static

The event that is triggered before the query is executed to retrieve an item by ID

BEFORE_GET_ALL

String static

The event that is triggered before the query is executed to retrieve results

BEFORE_SAVE

String static

The event that is triggered when a DTO is passed to the save function and aftr the validate event has completed. When validation failures occur this event will not fire.

ContentSanitizationRulesOverride

Object | Null static

dao

DAO

An instance of DAO to be used to interact with the persistence layer

DefaultSanitizationRulesOverride

Object | Null static

FORMAT

String static

The event that is triggered when a DTO is passed to the save function

GET_ALL

String static

The event that is triggered when retrieving a resource by ID

GET_ALL

String static

The event that is triggered when querying for one or more resources

MAX_RESULTS

Integer private static

The maximum allowed number of results allowed to be returned when using the paging wrapper

MERGE

String static

The event that is triggered when a DTO is passed to the save function and after the format event has completed

type

String

Represents the name of the collection to interact with

VALIDATE

String static

The event that is triggered when a DTO is passed to the save function and after the merge event has completed