Methods
(async) autoCreateNewEditionGroup(model, bookshelf, options)
Automatically create and sets a new Edition Group
if there is none selected, in the same transaction
- Source:
Parameters:
Name | Type | Description |
---|---|---|
model |
any
|
The ORM model of the Edition being edited/created |
bookshelf |
Bookshelf
|
The BookshelfJS ORM |
options |
any
|
Query options such as transacting object |
(async) castDiscardVote(transacting, importId, editorId) → {Promise.<boolean>}
This function casts a discard vote. In case of it has already been cast,
it raises an error. If the vote is decisive one (and the record is deleted),
it returns a Promise that resolves to true, else it returns an promise that
resolves to false.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
transacting |
Transaction
|
The knex Transacting object |
importId |
number
|
Id of the import |
editorId |
number
|
Id of the user casting the vote |
Returns:
- Type:
-
Promise.<boolean>
- Promise if records has been deleted or
Promise if the record is still present
(async) createEditionGroupForNewEdition(orm, transacting, aliasSetId, revisionId, authorCreditId, creditSection) → {string}
Create a new Edition Group for an Edition.
The Edition Group will be part of the same revision, and will have the same
alias set and author credit for that revision
Subsequent changes to the alias set or author credit for either entity will
only impact that entity's new revision.
Parameters:
Name | Type | Description |
---|---|---|
orm |
Bookshelf
|
The Bookshelf ORM |
transacting |
Transaction
|
The Bookshelf/Knex SQL transaction in progress |
aliasSetId |
number
|
string
|
The id of the new edition's alias set |
revisionId |
number
|
string
|
The id of the new edition's revision |
authorCreditId |
number
|
string
|
The id of the new edition's author credit |
creditSection |
boolean
|
The state of author credit section of the new edition |
Returns:
- Type:
-
string
BBID of the newly created Edition Group
createImportDataRecord()
IDs of all data sets which an entity can have.
- Source:
createNote(orm, content, editorId, revision, transacting) → {Object|null}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
Bookbrainz orm wrapper containing all models |
content |
string
|
Note content |
editorId |
string
|
Editor's Id |
revision |
Object
|
Revision object created using orm.Revision model |
transacting |
Transaction
|
The transaction model |
Returns:
- Type:
-
Object
|null
Returns the created Note object or returns null
(async) deleteOauthToken(editorId, service, orm)
Deletes the Oauth token with related data from the database
- Source:
Parameters:
Name | Type | Description |
---|---|---|
editorId |
number
|
Editor's id. |
service |
string
|
name of the service. |
orm |
object
|
the BookBrainz ORM, initialized during app setup |
formatDate(year, monthopt, dayopt) → {string}
Produce an ISO 8601-2004 formatted string for a date.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
year |
number
|
A calendar year. | |
month |
number
|
<optional> |
A calendar month. |
day |
number
|
<optional> |
A calendar day of month. |
Returns:
- Type:
-
string
The provided date formatted as an ISO 8601-2004 year or calendar date.
getAddedItems(oldSet, newSet, comparisonFunc) → {Array.<Item>}
Get any items in the new version of the set that aren't present in the old
version using a custom comparison function. The two arrays represent two
versions of a single set - one array is the set before a particular change
and the other is the same set after that change.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
oldSet |
Array.<Item>
|
The old array to compare |
newSet |
Array.<Item>
|
The new array to compare |
comparisonFunc |
function
|
Function to compare items from the two arrays |
Returns:
- Type:
-
Array.<Item>
- An array representing the difference of the two
arrays
getAdditionalEntityProps(entityData, entityType) → {Object}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
entityData |
Object
|
Object holding all data related to an entity |
entityType |
string
|
The type of the entity |
Returns:
- Type:
-
Object
- Returns all the additional entity specific data
getComparisonFunc(compareFields) → {function}
Returns a function which compares two object provided to it using the
comparison fields mentioned
- Source:
Parameters:
Name | Type | Description |
---|---|---|
compareFields |
Array.<string>
|
Comparison fields of two objects |
Returns:
- Type:
-
function
- Returns a comparison function
(async) getEditionGroupsCreditedToAuthor(bookshelf, authorBBID) → {Promise}
Fetches all the Edition Group entities credited to an Author (with Author Credits)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bookshelf |
Bookshelf
|
the Bookshelf instance, initialized during app setup |
authorBBID |
string
|
The target Author's BBID. |
Returns:
- Type:
-
Promise
The returned Promise returns the Edition Group BBID and default alias
(async) getEditionsCreditedToAuthor(bookshelf, authorBBID) → {Promise}
Fetches all the Edition entities credited to an Author (with Author Credits)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bookshelf |
Bookshelf
|
the Bookshelf instance, initialized during app setup |
authorBBID |
string
|
The target Author's BBID. |
Returns:
- Type:
-
Promise
The returned Promise returns the Edition BBID and default alias
(async) getEntity(orm, entityType, bbid, relations) → {Promise}
Fetches an entity with related data
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
entityType |
string
|
The entity model name. |
bbid |
string
|
The target entity's bbid. |
relations |
Array.<string>
|
Extra model relationships to fetch along with the entity |
Returns:
- Type:
-
Promise
A Promise that resolves to the entity in JSON format
getEntityModelByType(orm, type) → {object}
Retrieves the Bookshelf entity model with the given the model name
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
type |
string
|
Name or type of model |
Throws:
-
Throws a custom error if the param 'type' does not map to a model
- Type
-
Error
Returns:
- Type:
-
object
- Bookshelf model object with the type specified in the
single param
getEntityModels(orm) → {object}
Returns all entity models defined in bookbrainz-data-js
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
Returns:
- Type:
-
object
- Object mapping model name to the entity model
(async) getEntityParentAlias(orm, entityType, bbid) → {Promise}
Fetches an entity's last known default alias from its revision parent.
This is necessary to display the name of a 'deleted' entity
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
entityType |
string
|
The entity model name. |
bbid |
string
|
The target entity's bbid. |
Returns:
- Type:
-
Promise
The returned Promise returns the entity's
parent default alias
getEntitySetMetadataByType(entityType) → {Object}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
entityType |
string
|
Entity type string |
Returns:
- Type:
-
Object
- Returns entitySetMetadata (derivedSets)
(async) getOauthToken(editorId, service, orm) → {Promise}
Fetches the Oauth token with related data
- Source:
Parameters:
Name | Type | Description |
---|---|---|
editorId |
number
|
Editor's id. |
service |
string
|
Name of the service. |
orm |
object
|
the BookBrainz ORM, initialized during app setup |
Returns:
- Type:
-
Promise
A Promise that resolves to the oauth token in JSON format
(async) getRecentImportUtilData(transacting, limit, offset) → {Promise.<Object.<Array>>}
getRecentImportIdsByType -
- Source:
Parameters:
Name | Type | Description |
---|---|---|
transacting |
Transaction
|
Transaction object |
limit |
number
|
To limit the number of importIds fetched |
offset |
number
|
We offset the result by this value |
Returns:
- Type:
-
Promise.<Object.<Array>>
- Returns an object containing arrays of
importIds of various importTypes
getRemovedItems(oldSet, newSet, comparisonFunc) → {Array.<Item>}
Get any items in the old version of the set that aren't present in the new
version using a custom comparison function. The two arrays represent two
versions of a single set - one array is the set before a particular change
and the other is the same set after that change.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
oldSet |
Array.<Item>
|
The old array to compare |
newSet |
Array.<Item>
|
The new array to compare |
comparisonFunc |
function
|
Function to compare items from the two arrays |
Returns:
- Type:
-
Array.<Item>
- An array representing the difference of the two
arrays
getUnchangedItems(oldSet, newSet, comparisonFunc) → {Array.<Item>}
Get the intersection of two arrays of objects using a custom comparison
function. The two arrays represent two versions of a single set - one array
is the set before a particular change and the other is the same set after
that change.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
oldSet |
Array.<Item>
|
The old array to compare |
newSet |
Array.<Item>
|
The new array to compare |
comparisonFunc |
function
|
Function to compare items from the two arrays |
Returns:
- Type:
-
Array.<Item>
- An array representing the intersection of the two
arrays
incrementEditorEditCountById(orm, id, transacting) → {Promise}
Adds 1 to the edit count of the specified editor
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
the BookBrainz ORM, initialized during app setup |
id |
string
|
row ID of editor to be updated |
transacting |
Transaction
|
Bookshelf transaction object (must be in progress) |
Returns:
- Type:
-
Promise
- Resolves to the updated editor model
init(config) → {Object}
Initialize the database connection and models.
Parameters:
Name | Type | Description |
---|---|---|
config |
Knex.Config
|
A knex.js configuration object. |
Returns:
- Type:
-
Object
All data models.
isNullDate(date) → {boolean}
Determines wether a given date is empty or null, meaning no year month or day has been specified.
Accepts a {day, month, year} object or an ISO 8601-2004 string (±YYYYYY-MM-DD)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
date |
object
|
string
|
a {day, month, year} object or ISO 8601-2004 string (±YYYYYY-MM-DD) |
Returns:
- Type:
-
boolean
true if the date is empty/null
ISODateStringToObject(value) → {object}
Parse an ISO 8601-2004 string and return an object with separate day, month and year, if they exist.
If any of the values don't exist, the default is an empty string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
string
|
relationshipId number for initaial relationship |
Returns:
- Type:
-
object
a {day, month, year} object
(async) loadAuthorNames(orm, workBBIDs) → {Object}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
the BookBrainz ORM, initialized during app setup |
workBBIDs |
array
|
the array containing the BBIDs of the works contained in the edition |
Returns:
- Type:
-
Object
- Returns an array of objects containing the authorAlias, authorBBID of each work in an edition
parseDate(date) → {Array.<(number|null)>}
Split ISO 8601 calendar dates or years into a numerical array.
Parameters:
Name | Type | Description |
---|---|---|
date |
string
|
A date of the format 'YYYY', 'YYYY-MM', or 'YYYY-MM-DD'. |
Returns:
- Type:
-
Array.<(number|null)>
- Year, month, and day of month respectively.
(async) promiseProps(promiseObj) → {Object}
Replacement for Bluebird's Promise.props
Parameters:
Name | Type | Description |
---|---|---|
promiseObj |
Object
|
an object containing string keys and promises to be resolved as the values |
Returns:
- Type:
-
Object
an object containing the same keys, but resolved promises
(async) recursivelyGetAreaParentsWithNames(orm, areaId, checkAllLevels) → {Promise}
Recursively fetches an area's parents (with "has part" link)
Adapted from https://github.com/metabrainz/musicbrainz-server/blob/f79b6d0d2d4bd67254cc34426f17cf8eb21ec5bb/lib/MusicBrainz/Server/Data/Utils.pm#L255-L273
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup, or a Bookshelf instance | |
areaId |
string
|
The BBID (= MBID) of the area | |
checkAllLevels |
boolean
|
false | By default limits to the area types Country, Subdivision and City |
Returns:
- Type:
-
Promise
The returned Promise returns the entity's
parent default alias
(async) recursivelyGetRedirectBBID(orm, bbid, transacting) → {string}
Finds the bbid an entity redirects to, if any.
Do a recursive search in case the redirected bbid also redirects, etc.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
bbid |
string
|
The target entity's bbid. |
transacting |
any
|
Optional ORM transaction object |
Returns:
- Type:
-
string
The final bbid to redirect to
(async) saveOauthToken(editorId, service, accessToken, refreshToken, tokenExpiresTs, scopes, orm) → {Promise}
Saves the Oauth token with related data to the database
- Source:
Parameters:
Name | Type | Description |
---|---|---|
editorId |
number
|
Editor's id. |
service |
string
|
name of the service. |
accessToken |
string
|
access token. |
refreshToken |
string
|
refresh token. |
tokenExpiresTs |
number
|
token expiration timestamp. |
scopes |
Array.<string>
|
scopes. |
orm |
object
|
the BookBrainz ORM, initialized during app setup |
Returns:
- Type:
-
Promise
A Promise that resolves to the oauth token in JSON format
updateAnnotation(orm, transacting, oldAnnotation, newContent, revision) → {Promise.<Object>}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
Bookbrainz orm wrapper holding all models |
transacting |
Transaction
|
The present knex transacting object |
oldAnnotation |
Object
|
The old annotation object |
newContent |
string
|
New annotation to be set |
revision |
Object
|
The present revision object |
Returns:
- Type:
-
Promise.<Object>
- Returns Annotation object
updateDisambiguation(orm, transacting, oldDisambiguation, newComment) → {Promise.<Object>}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
The BookBrainz orm wrapper containing all models |
transacting |
Transaction
|
The current knex transaction object |
oldDisambiguation |
Object
|
The previous disambiguation object |
newComment |
string
|
The new disambiguation string |
Returns:
- Type:
-
Promise.<Object>
- Returns Promise holding Disambiguation object
(async) updateOauthToken(editorId, service, accessToken, refreshToken, tokenExpiresTs, orm) → {Promise}
Updates the Oauth token with related data in the database
- Source:
Parameters:
Name | Type | Description |
---|---|---|
editorId |
number
|
Editor's id. |
service |
string
|
name of the service. |
accessToken |
string
|
access token. |
refreshToken |
string
|
refresh token. |
tokenExpiresTs |
number
|
token expiration timestamp. |
orm |
object
|
the BookBrainz ORM, initialized during app setup |
Returns:
- Type:
-
Promise
A Promise that resolves to the oauth token in JSON format
updateRelationshipSets(orm, transacting, oldSet, newSetItems) → {Promise.<any>}
Takes an array of relationships that should be set for the entity, and
compares it to the currently set list of relationships to determine the
difference. Compiles a list of affected entity BBIDs from this difference,
and then updates the relationship sets for all affected entities, and returns
these. If no entities are affected (there are no changes), an empty object
is returned.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
ORM
|
an initialized instance of bookbrainz-data-js |
transacting |
Transaction
|
the current transaction |
oldSet |
any
|
the RelationshipSet object for the old entity data |
newSetItems |
Array.<Relationship>
|
the edited RelationshipSet for the entity |
Returns:
- Type:
-
Promise.<any>
a promise which resolves to a {BBID: RelationshipSet}
map