Namespace: Revision

Revision

Common handler functions for managing revisions. These are typically attached to models as static or instance methods, see models/thing.js for examples.

Source:

Methods

(static) getDeleteAllRevisionsHandler(Model) → {function}

Get a function that lets us mark all revisions of a given object as deleted (they are not actually removed) and save the deletion metadata as a new revision.

Parameters:
Name Type Description
Model Model

the Model we want to attach the handler to

Source:
Returns:

function we can attach as an instance method via Model.define. See Revision~_deleteAllRevisions.

Type
function

(static) getFirstRevisionHandler(Model) → {function}

Get a function that lets us create the first revision of a given model. Does not save.

Parameters:
Name Type Description
Model Model

the Model we want to attach the handler to

Source:
Returns:

function we can attach as a static method to the Model via Model.createFirstRevision = fn. See Revision~_createFirstRevision.

Type
function

(static) getMultipleNotStaleOrDeletedHandler(Model) → {function}

Shortcut for a getAll/filter operation that returns objects matching a given list of IDs.

Parameters:
Name Type Description
Model Model

the table to filter

Source:
Returns:

function that returns a Query object for this Model

Type
function

(static) getNewRevisionHandler(Model) → {function}

Get a function that lets us create a new revision (including saving a copy of the current revision) for the given Model

Parameters:
Name Type Description
Model Model

the Model we need a handler for

Source:
Returns:

function that can be attached as an instance method to the Model via Model.define. See Revision~_newRevision.

Type
function

(static) getNotStaleOrDeletedFilterHandler(Model) → {function}

Shortcut for a filter operation that narrows a table to current revisions, commonly chained with other filters.

Parameters:
Name Type Description
Model Model

the table to filter

Source:
Returns:

function that returns a Query object for this Model

Type
function

(static) getNotStaleOrDeletedGetHandler(Model) → {function}

Get handler to .get() an object by its ID and reject with standardized error if it is an old or deleted revision.

Parameters:
Name Type Description
Model Model

the table to query with this handler

Source:
Returns:

function we can attach as a static method to the Model via Model.getNotStaleOrDeleted = fn. See Revision~_getNotStaleOrDeleted.

Type
function

(static) getSchema() → {Object}

Obtain a copy of the standard revision schema.

Source:
Returns:

object that can be assigned via Object.assign to the schema object for your Model

Type
Object

(async, inner) _createFirstRevision(user, optionsopt) → {Model}

Function obtained via Revision.getFirstRevisionHandler. Create (but don't save) the initial revision for an object of this Model. Asynchronously obtains UUID.

Parameters:
Name Type Attributes Description
user User

the user to associate with this revision

options Object <optional>

revision options

Properties
Name Type Description
tags Array.<String>

set of tags to associate with this revision

Source:
Returns:

first revision

Type
Model

(async, inner) _deleteAllRevisions(user, optionsopt) → {Model}

Function obtained via Revision.getDeleteAllRevisionsHandler. Creates and saves a new revision with deletion metadata as well.

Parameters:
Name Type Attributes Description
user User

the user we want to associate with this deletion action

options Object <optional>

revision options

Properties
Name Type Description
tags Array.<String>

set of tags to associate with the deletion revision. The first tag will always be 'delete', but you can specify, e.g., the method by which the deletion occurred.

Source:
Returns:

revision with deletion metadata

Type
Model

(inner) _filterNotStaleOrDeleted() → {Query}

Source:
Returns:

revisions that are not flagged as outdated or deleted

Type
Query

(async, inner) _getNotStaleOrDeleted(id, joinopt) → {Model}

Parameters:
Name Type Attributes Description
id String

the ID to look up

join Object <optional>

an object specifying a join to another table

Source:
Returns:

an object of the specified Model

Type
Model

(async, inner) _newRevision(user, optionsopt) → {Model}

Function obtained via Revision.getNewRevisionHandler. Save a copy of the current revision as an old revision and create (but do not save) a new revision object.

This:
  • model
Parameters:
Name Type Attributes Description
user User

the user to associate with this revision

options Object <optional>

revision options

Properties
Name Type Description
tags Array.<String>

set of tags to associate with this revision

Source:
Returns:

new revision of the given Model

Type
Model

(inner) getMultipleNotStaleOrDeleted(idArray) → {Query}

Parameters:
Name Type Description
idArray Array.<String>

an array of primary key IDs

Source:
Returns:

objects that are not flagged as outdated or deleted

Type
Query