0.1.31 • Published 7 years ago

mongo-assets v0.1.31

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

Class

MongoAssets

constructor()

config: *

db: *

client: *

initialize(config: Object, config.endpoint: String): Promise

Initialize the instance, connecting it to the database.

NameTypeAttributeDescription
configObjecta valid config object
config.endpointString'mongodb://user:pass@host:port/db'

connect(args: object, args.endpoint: string): Promise

Create a connection to the mongo database, setting this.db as an instance.

NameTypeAttributeDescription
argsobject
args.endpointstring

disconnect(args: Object): {"success": boolean}

Disconnect the instance from the database.

NameTypeAttributeDescription
argsObjectthe argument object

createAsset(args: Object, args.type: String, args.user: Object, args.asset: Object, args.relate: Boolean, args.assoc_method: Boolean, args.role: Object): Promise

Insert an asset, associating it to the user role

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe type of asset (this determines the document collection)
args.userObjectthe current user, this determines the roles, team.
args.assetObjectthe "asset", the document.
args.relateBooleanindicator to relate the asset to the user's role, default true.
args.assoc_methodBooleanthe method to relate with - currently supports 'reference', 'clone', default 'clone';
args.roleObjectassociate the asset to a specific role the user belongs to, default the user's user role.

createAssets(args: Object, args.type: String, args.user: Object, args.assets: Object|Array, args.relate: Boolean, args.assoc_method: String, args.role: Object): Promise

Insert an array of assets, associating it to the user role

NameTypeAttributeDescription
argsObjectthe argument object.
args.typeStringthe type of asset ( this determines the document collection)
args.userObjectthe current user, this determines the roles, team.
args.assetsObjectArraya single, or array of "assets", the documents.
args.relateBooleanindicator to relate the asset to the user's role, default true.
args.assoc_methodStringthe association method to use, default 'clone'.
args.roleObjectassociate the asset to a specific role the user belongs to, default the user's user role.

updateAsset(args: Object, args.type: String, args.asset: Object, args.assoc_method: String): Promise

Update Asset

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe asset type.
args.assetObjectthe asset.
args.assoc_methodStringthe association method to use; if not provided the store default is used, failing that defaults to "clone"

deleteAsset(args: Object, args.type: String, args.asset: Object, args.recycle: Boolean): Promise

Delete an asset, disassociating it from all related items.

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe asset type
args.assetObjectthe asset
args.recycleBooleanmove the asset to the recycle colection, default false.

deleteAssets(args: Object, args.type: String, args.assets: Array, args.asset: Object): Promise

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe asset type.
args.assetsArrayan array of assets.
args.assetObjecta single asset to remove, for convenience.

dropAssetType(args: Object, args.type: String): Promise

Drop an asset type entirely, removing all associates.

NameTypeAttributeDescription
argsObject
args.typeString

assetCollectionExists(args: Object, args.type: String): Promise

Check for the existence of an asset collection.

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe type of asset to check for

associate(args: Object, args.target: Object, args.source: Object, args.relationship: String, args.assoc_method: String, args.withTree: Boolean, args.returnOnly: String): Promise

Associate Assets.

NameTypeAttributeDescription
argsObjectthe argument object.
args.targetObjectthe target asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }}
args.sourceObjectthe source asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }}
args.relationshipStringrelationship type, 'target' (target receives a relationship to the source), 'source' (source recieves a relationship to the target), or "peer" (both receive a relationship), default 'target'.
args.assoc_methodStringthe assocation method, supported are 'clone', 'reference', default : clone.
args.withTreeBooleanDEPRECATING... Include all subtrees in the association. By default we ONLY associate the top level elements which are not arrays or objects - argue true to associate the entire subtree. This is a safetu precaution.
args.returnOnlyStringwhat to return, 'peer' returns both as { target: , source: }, 'target' returns only the target, 'source' returns only the source. Default is 'source'.

disassociate(args: Object, args.target: Object, args.source: Object, args.relationship: String, args.assoc_method: String, args.withTree: Boolean, args.returnOnly: String): Promise

Disassociate Assets.

NameTypeAttributeDescription
argsObjectthe argument object.
args.targetObjectthe target asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }}
args.sourceObjectthe source asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }}
args.relationshipStringrelationship type, 'target' (target removes a relationship to the source), 'source' (source removes a relationship to the target), or "peer" (both remove a relationship)
args.assoc_methodStringthe assocation method, supported are 'clone', 'reference', default : clone.
args.withTreeBooleanDEPRECATING... Include all subtrees in the association. By default we ONLY associate the top level elements which are not arrays or objects - argue true to associate the entire subtree. This is a safetu precaution.
args.returnOnlyStringwhat to return, 'peer' returns both as { target: , source: }, 'target' returns only the target, 'source' returns only the source. Default is 'source'.

updateAssociations(args: Object, args.type: String, args.asset: Object): Promise

Update all associations of an argued asset.

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe asset type.
args.assetObjectthe asset

dropAssociations(args: Object, args.type: String, args.asset: Object): Promise

Drop all assocations from the asset and update associates, this orphans the asset (useful prior to deletion of an asset)

NameTypeAttributeDescription
argsObjectthe argument objet
args.typeStringthe asset type
args.assetObjectthe asset

gatherAssets(args: Object, args.user: Object, args.type: String, args.types: Array): Promise

Gather assets associated to argued roles.

NameTypeAttributeDescription
argsObjectthen argument object
args.userObjectthe user.
args.typeStringthe asset type.
args.typesArrayan array of asset types to gather.

getAssociates(args: Object, args.assetType: String, args.assocs: Array, args.exclude: Array): Promise

Retrieve the associates in their full form.

NameTypeAttributeDescription
argsObjectthe argument object.
args.assetTypeStringthe type of asset.
args.assocsArrayan array of assets either in their full form (clone) or reference form.
args.excludeArrayan array of ids to exclude from the return

getAssociatedRoles(args: Object, args.type: String, args.asset: Object): Promise

Gain the roles assocated to an argued asset.

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe argument type
args.assetObjectthe asset to gain roles from.

shareAssets(args: Object, args.user: Object, args.type: String, args.asset: Object, args.assets: Object, args.role: Object, args.roles: Object, args.assoc_method: String): Promise

Share assets to argued roles.

NameTypeAttributeDescription
argsObjectthe argument object
args.userObjectthe user
args.typeStringthe asset type.
args.assetObjectthe asset
args.assetsObjectan array of assets to share
args.roleObjectthe target role
args.rolesObjectan array of target roles
args.assoc_methodString

_isRealObject(obj: Object): Boolean

Test a variable to be an object

NameTypeAttributeDescription
objObjectthe object to test

defaultrole(user: Object): Object

Get the default role for an argued user.

NameTypeAttributeDescription
userObject

handleError(method: String, err: Error, options: Object): {"success": *, "errored": boolean, "message": string}

Error handler.

NameTypeAttributeDescription
methodString
errError
optionsObject

splitAsset(args: *): *

NameTypeAttributeDescription
args*nullable: undefined

_findAssetChunks(root: *, key: *, chunks: *, itr: *, id: *): {"root": *, "chunks": *, "paged": *, "pages": *, "frag": *}

NameTypeAttributeDescription
root*nullable: undefined
key*nullable: undefined
chunks*nullable: undefined
itr*nullable: undefined
id*nullable: undefined

create(args: object, args.collection: string, args.documents: array): *

Insert one or many documents

NameTypeAttributeDescription
argsobject
args.collectionstringthe collection to insert the document into.
args.documentsarraythe document being inserted.

findOne(args: Object, args.collection: String, args.frag: Object): Promise

Find One asset.

NameTypeAttributeDescription
argsObjectthe argument object
args.collectionStringthe collection
args.fragObjectthe search fragment.

find(args: object, args.collection: string, args.documents: object|array, args.ql: function, args.fuse: boolean, args.debug: boolean): *

NameTypeAttributeDescription
argsobject
args.collectionstringthe collection which the saught document resides.
args.documentsobjectarraythe document partial , or array of partials to seek for, otherwise all documents in the collection are returned.
args.qlfunctiondirty as, "graphQL" reducer argument.
args.fusebooleanfor QL queries, if a single root is provided eg '{module}' or '{module.something}' then an object is returned rather than an array, fusing all items on that key.
args.debugbooleanflag true to see operation manifest.

distinct(args: Object, args.collection: String, args.attribute: String): Array

NameTypeAttributeDescription
argsObjectthe argument object
args.collectionStringthe subject collection.
args.attributeStringthe attribute to return a unique list for.

findAsset(args: Object, args.type: String, args.frag: Object): Object

Retrieve an asset.

NameTypeAttributeDescription
argsObjectthe argument Object
args.typeStringthe cannonical type of asset
args.fragObjectthe search shim/document frag.

findAssets(args: object, args.user: object, args.role: object|array, args.userrole: boolean, args.type: string): *

Retrieve assets for a given user/roles.

NameTypeAttributeDescription
argsobjectthe argument object
args.userobjectthe user object
args.roleobjectarrayuse a provided role or array of roles, otherwise all roles of the user will be returned.
args.userrolebooleanwhen provided as true, only assets associated to the user will be returned.
args.typestringthe type of asset to retrieve.

getAssetPartial(args: object, args.type: string, args.asset: object, args.nest: string, args.page: integer, args.pages: array): *

NameTypeAttributeDescription
argsobjectthe argument object
args.typestringthe type of asset
args.assetobjectthe asset.
args.neststring
args.pageintegerthe page number
args.pagesarraythe page range.

findAssociatedRoles(args: object, args.type: string, args.asset: object): *

Retrieve roles that are associated to a given asset.

NameTypeAttributeDescription
argsobjectthe argument object.
args.typestringthe type of asset being saught
args.assetobjectthe asset.

updateOne(args: object, args.collection: string, args.document: object, args.ops: object): Promise

Update a document

NameTypeAttributeDescription
argsobject
args.collectionstringthe collection which the saught document resides.
args.documentobjectthe document
args.opsobjectan object of special $ ops, eg, $push, $set etc.. default is null and when null the args.document is used as the update, otherwise this is used.

deleteOne(args: object, args.collection: string, args.document: object): object

Deletes a document

NameTypeAttributeDescription
argsobject
args.collectionstringThe collection to remove the document from
args.documentobjectThe document being removed, we enforce the id be present for data sanity.

delete(args: object, args.collection: string, args.frag: object, args.documents: array): object

Deletes multiple documents

NameTypeAttributeDescription
argsobject
args.collectionstringThe collection to remove the document from
args.fragobjectThe document being removed, we enforce.
args.documentsarrayan array of documents scheduled for deleteion.

deleteOneAsset(args: *): *

NameTypeAttributeDescription
args*nullable: undefined

releaseAssets(args: object): *

Release assets from a relationship, effective "un-sharing" them.

NameTypeAttributeDescription
argsobjectthe argument object.

releaseAssetType(args: object, args.type: string, args.target: object, args.targetType: string): *

Release an entire assetType from a relationship, effectively unsharing that type.

NameTypeAttributeDescription
argsobjectthe argument object.
args.typestringthe type of asset to release/unshare
args.targetobjectthe document to unrelease the share - normally a role.
args.targetTypestringthe type of target, default 'role'

assetToAssoc(method: String, type: String, asset: Object): Promise

Get the association representation of an asset.

NameTypeAttributeDescription
methodStringthe assoc_method , supported is 'clone', 'reference'.
typeStringthe cannoncial type of the asset.
assetObjectthe asset

assocToAsset(asset: Object): Promise

Gain the actual asset from an association method.

NameTypeAttributeDescription
assetObjectthe asset it its association form.

reassociate(args: Object, args.type: String, args.role: Object|Array, args.method: String): Array

Change the association method of related assets to a role(s)

NameTypeAttributeDescription
argsObjectthe argument object
args.typeStringthe asset type
args.roleObjectArraythe role(s) to perform reassociation upon.
args.methodStringthe method to reassociate with.

decouple_associates(o: *): *

Strip an objects out of arrays and objects, leaving just the attributes.

NameTypeAttributeDescription
o*nullable: undefined

parseQL(ql: *): *

NameTypeAttributeDescription
ql*nullable: undefined

idify(doc: *): *

Takes a document with a string typed _id, returns it with an ObjectId.

NameTypeAttributeDescription
doc*nullable: undefined

Function

withMongoAssets(args: Object, args.key: String, args.initialize: Boolean, args.config: Object, args.config.endpoint: String): *

Decorate a class with an instance of Mongo Assets

NameTypeAttributeDescription
argsObjectthe argument object.
args.keyStringthe class variable to attach the instance to, default 'db'.
args.initializeBooleanInitialize the MongoAssets instance upon class declaration, default false.
args.configObjecta configuration object, required if initializing via the decorator, otherwise argue your config to myClass.db.initialize()
args.config.endpointStringa mongo database URI.
0.1.31

7 years ago

0.1.30

7 years ago

0.1.5

7 years ago

0.1.3

7 years ago

0.1.27

7 years ago

0.1.26

7 years ago

0.1.25

7 years ago

0.1.24

7 years ago

0.1.23

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.55555

7 years ago

0.1.4

7 years ago

0.1.0

7 years ago