BaseSlugCollection

api/base. BaseSlugCollection

BaseSlugCollection is an abstract superclass for use by entities that have a slug.
It provides an API where the user can provide either a slug or docID (or document-specifying object).
Note it does not define a constructor; subclasses should invoke super(type, schema) to get the
BaseCollection constructor.

Constructor

new BaseSlugCollection()

Source:

Extends

Methods

assertAllDefined(names)

Source:
Inherited From:

Verifies that the list of passed instances are all members of this collection.

Parameters:
Name Type Description
names

Should be a list of docs and/or docIDs.

Throws:

If instances is not an array, or if any instance is not in this collection.

Type
Meteor.Error

assertDefined(name)

Source:
Inherited From:

Verifies that the passed object is one of this collection's instances.

Parameters:
Name Type Description
name String | List

Should be a defined ID or doc in this collection.

Throws:

If not defined.

Type
Meteor.Error

assertValidRoleForMethod(userId)

Source:
Inherited From:

Default implementation of assertValidRoleForMethod. Asserts that userId is logged in as an Admin or Advisor.
This is used in the define, update, and removeIt Meteor methods associated with each class.

Parameters:
Name Type Description
userId

The userId of the logged in user. Can be null or undefined

Throws:

If there is no logged in user, or the user is not an Admin or Advisor.

Type
Meteor.Error

checkIntegrity() → {array}

Source:
Inherited From:

Define the default integrity checker for all applications.
Returns an array with a string indicating that this method is not overridden.

Returns:

An array containing a string indicating the use of the default integrity checker.

Type
array

count() → {Number}

Source:
Inherited From:

Returns the number of documents in this collection.

Returns:

The number of elements in this collection.

Type
Number

dumpAll() → {Object}

Source:
Inherited From:

Returns an object with two fields: name and contents.
Name is the name of this collection.
Contents is an array of objects suitable for passing to the restore() method.

Returns:

An object representing the contents of this collection.

Type
Object

dumpOne(docID) → {Object}

Source:
Inherited From:

Returns an object representing the definition of docID in a format appropriate to the restoreOne function.
Must be overridden by each collection.

Parameters:
Name Type Description
docID

A docID from this collection.

Returns:

An object representing this document.

Type
Object

find(selector, options) → {Mongo.Cursor}

Source:
Inherited From:
See:

Runs find on this collection.

Parameters:
Name Type Description
selector Object

A MongoDB selector.

options Object

MongoDB options.

Returns:
Type
Mongo.Cursor

findDoc(name) → {Object}

Source:
Inherited From:

A stricter form of findOne, in that it throws an exception if the entity isn't found in the collection.

Parameters:
Name Type Description
name String | Object

Either the docID, or an object selector, or the 'name' field value.

Throws:

If the document cannot be found.

Type
Meteor.Error
Returns:

The document associated with name.

Type
Object

findDocBySlug(slug) → {Object}

Source:

Returns the instance associated with the passed slug.

Parameters:
Name Type Description
slug String

The slug (string or docID).

Throws:

If the slug cannot be found, or is not associated with an instance in this collection.

Type
Meteor.Error
Returns:

The document representing the instance.

Type
Object

findIdBySlug(slug) → {String}

Source:

Return the docID of the instance associated with this slug.

Parameters:
Name Type Description
slug String

The slug (string or docID).

Throws:

If the slug cannot be found, or is not associated with an instance in this collection.

Type
Meteor.Error
Returns:

The docID.

Type
String

findIdsBySlugs(slugs) → {Array}

Source:

Returns a list of docIDs associated with the instances associated with the list of slugs.

Parameters:
Name Type Description
slugs Array

A list or collection of slugs.

Throws:

If the slug cannot be found, or is not associated with an instance in this collection.

Type
Meteor.Error
Returns:

A list of docIDs.

Type
Array

findOne(selector, options) → {Mongo.Cursor}

Source:
Inherited From:
See:

Runs findOne on this collection.

Parameters:
Name Type Description
selector Object

A MongoDB selector.

options Object

MongoDB options.

Returns:
Type
Mongo.Cursor

findSlugByID(docID) → {String}

Source:

Returns the slug name associated with this docID.

Parameters:
Name Type Description
docID

The docID

Throws:

If docID is not associated with this entity.

Type
Meteor.Error
Returns:

The slug name

Type
String

getCollectionName() → {string}

Source:
Inherited From:

Returns the collection name.

Returns:

The collection name as a string.

Type
string

getID(instance) → {String}

Source:

Returns the docID associated with instance, or throws an error if it cannot be found.
If instance is a docID, then it is returned unchanged. If instance is a slug, its corresponding docID is returned.
If instance is the value for the username field in this collection, then return that document's ID.
If instance is an object with an _id field, then that value is checked to see if it's in the collection.

Parameters:
Name Type Description
instance String

Either a valid docID or a valid slug string.

Throws:

If instance is not a docID or a slug.

Type
Meteor.Error
Returns:

The docID associated with instance.

Type
String

getIDs(instances) → {Array.<String>}

Source:

Returns the docIDs associated with instances, or throws an error if any cannot be found.
If an instance is a docID, then it is returned unchanged. If a slug, its corresponding docID is returned.
If nothing is passed, then an empty array is returned.

Parameters:
Name Type Description
instances Array.<String>

An array of valid docIDs, slugs, or a combination.

Throws:

If any instance is not a docID or a slug.

Type
Meteor.Error
Returns:

The docIDs associated with instances.

Type
Array.<String>

getPublicationName() → {String}

Source:
Inherited From:

Return the publication name.

Returns:

The publication name, as a string.

Type
String

getType() → {String}

Source:
Inherited From:

Return the type of this collection.

Returns:

The type, as a string.

Type
String

hasSlug(slug) → {boolean}

Source:

Returns true if the passed slug is associated with an entity of this type.

Parameters:
Name Type Description
slug String

Either the name of a slug or a slugID.

Returns:

True if the slug is in this collection.

Type
boolean

isDefined(instance) → {boolean}

Source:
Overrides:

Return true if instance is a docID or a slug for this entity.

Parameters:
Name Type Description
instance String

A docID or a slug.

Returns:

True if instance is a docID or slug for this entity.

Type
boolean

publish()

Source:
Inherited From:

Default publication method for entities.
It publishes the entire collection.

removeAll()

Source:
Inherited From:

Removes all elements of this collection.
This is implemented by mapping through all elements because mini-mongo does not implement the remove operation.
So this approach can be used on both client and server side.
removeAll should only used for testing purposes, so it doesn't need to be efficient.

Returns:

true

removeIt(instance)

Source:
Overrides:

Removes the passed instance from its collection.
Also removes the associated Slug.
Note that prior to calling this method, the subclass should do additional checks to see if any dependent
objects have been deleted.

Parameters:
Name Type Description
instance String

A docID or slug representing the instance.

Throws:

If the instance (and its associated slug) cannot be found.

Type
Meteor.Error

restoreAll(dumpObjects)

Source:
Inherited From:

Defines all the entities in the passed array of objects.

Parameters:
Name Type Description
dumpObjects

The array of objects representing the definition of a document in this collection.

restoreOne(dumpObject) → {String}

Source:
Inherited From:

Defines the entity represented by dumpObject.
Defaults to calling the define() method if it exists.

Parameters:
Name Type Description
dumpObject

An object representing one document in this collection.

Returns:

The docID of the newly created document.

Type
String

subscribe()

Source:
Inherited From:

Default subscription method for entities.
It subscribes to the entire collection.

toString() → {String}

Source:
Inherited From:

Returns a string representing all of the documents in this collection.

Returns:
Type
String

update(selector, modifier)

Source:
Inherited From:
See:

Runs a simplified version of update on this collection.

Parameters:
Name Type Description
selector Object

A MongoDB selector.

modifier Object

A MongoDB modifier

Returns:

true