mongo-assets v0.1.31
Class
MongoAssets
constructor()
config: *
db: *
client: *
initialize(config: Object, config.endpoint: String): Promise
Initialize the instance, connecting it to the database.
Name | Type | Attribute | Description |
---|---|---|---|
config | Object | a valid config object | |
config.endpoint | String | '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.
Name | Type | Attribute | Description |
---|---|---|---|
args | object | ||
args.endpoint | string |
disconnect(args: Object): {"success": boolean}
Disconnect the instance from the database.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the 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
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the type of asset (this determines the document collection) | |
args.user | Object | the current user, this determines the roles, team. | |
args.asset | Object | the "asset", the document. | |
args.relate | Boolean | indicator to relate the asset to the user's role, default true. | |
args.assoc_method | Boolean | the method to relate with - currently supports 'reference', 'clone', default 'clone'; | |
args.role | Object | associate 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
Name | Type | Attribute | Description | |
---|---|---|---|---|
args | Object | the argument object. | ||
args.type | String | the type of asset ( this determines the document collection) | ||
args.user | Object | the current user, this determines the roles, team. | ||
args.assets | Object | Array | a single, or array of "assets", the documents. | |
args.relate | Boolean | indicator to relate the asset to the user's role, default true. | ||
args.assoc_method | String | the association method to use, default 'clone'. | ||
args.role | Object | associate 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
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the asset type. | |
args.asset | Object | the asset. | |
args.assoc_method | String | the 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the asset type | |
args.asset | Object | the asset | |
args.recycle | Boolean | move the asset to the recycle colection, default false. |
deleteAssets(args: Object, args.type: String, args.assets: Array, args.asset: Object): Promise
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the asset type. | |
args.assets | Array | an array of assets. | |
args.asset | Object | a single asset to remove, for convenience. |
dropAssetType(args: Object, args.type: String): Promise
Drop an asset type entirely, removing all associates.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | ||
args.type | String |
assetCollectionExists(args: Object, args.type: String): Promise
Check for the existence of an asset collection.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object. | |
args.target | Object | the target asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }} | |
args.source | Object | the source asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }} | |
args.relationship | String | relationship 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_method | String | the assocation method, supported are 'clone', 'reference', default : clone. | |
args.withTree | Boolean | DEPRECATING... 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.returnOnly | String | what 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object. | |
args.target | Object | the target asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }} | |
args.source | Object | the source asset { type: { ...object} } , eg { user: { firstname: 'bren' .... }} | |
args.relationship | String | relationship 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_method | String | the assocation method, supported are 'clone', 'reference', default : clone. | |
args.withTree | Boolean | DEPRECATING... 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.returnOnly | String | what 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the asset type. | |
args.asset | Object | the 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)
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument objet | |
args.type | String | the asset type | |
args.asset | Object | the asset |
gatherAssets(args: Object, args.user: Object, args.type: String, args.types: Array): Promise
Gather assets associated to argued roles.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | then argument object | |
args.user | Object | the user. | |
args.type | String | the asset type. | |
args.types | Array | an 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object. | |
args.assetType | String | the type of asset. | |
args.assocs | Array | an array of assets either in their full form (clone) or reference form. | |
args.exclude | Array | an 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.type | String | the argument type | |
args.asset | Object | the 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.user | Object | the user | |
args.type | String | the asset type. | |
args.asset | Object | the asset | |
args.assets | Object | an array of assets to share | |
args.role | Object | the target role | |
args.roles | Object | an array of target roles | |
args.assoc_method | String |
_isRealObject(obj: Object): Boolean
Test a variable to be an object
Name | Type | Attribute | Description |
---|---|---|---|
obj | Object | the object to test |
defaultrole(user: Object): Object
Get the default role for an argued user.
Name | Type | Attribute | Description |
---|---|---|---|
user | Object |
handleError(method: String, err: Error, options: Object): {"success": *, "errored": boolean, "message": string}
Error handler.
Name | Type | Attribute | Description |
---|---|---|---|
method | String | ||
err | Error | ||
options | Object |
splitAsset(args: *): *
Name | Type | Attribute | Description |
---|---|---|---|
args | * | nullable: undefined |
_findAssetChunks(root: *, key: *, chunks: *, itr: *, id: *): {"root": *, "chunks": *, "paged": *, "pages": *, "frag": *}
Name | Type | Attribute | Description |
---|---|---|---|
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
Name | Type | Attribute | Description |
---|---|---|---|
args | object | ||
args.collection | string | the collection to insert the document into. | |
args.documents | array | the document being inserted. |
findOne(args: Object, args.collection: String, args.frag: Object): Promise
Find One asset.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.collection | String | the collection | |
args.frag | Object | the search fragment. |
find(args: object, args.collection: string, args.documents: object|array, args.ql: function, args.fuse: boolean, args.debug: boolean): *
Name | Type | Attribute | Description | |
---|---|---|---|---|
args | object | |||
args.collection | string | the collection which the saught document resides. | ||
args.documents | object | array | the document partial , or array of partials to seek for, otherwise all documents in the collection are returned. | |
args.ql | function | dirty as, "graphQL" reducer argument. | ||
args.fuse | boolean | for 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.debug | boolean | flag true to see operation manifest. |
distinct(args: Object, args.collection: String, args.attribute: String): Array
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object | |
args.collection | String | the subject collection. | |
args.attribute | String | the attribute to return a unique list for. |
findAsset(args: Object, args.type: String, args.frag: Object): Object
Retrieve an asset.
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument Object | |
args.type | String | the cannonical type of asset | |
args.frag | Object | the 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.
Name | Type | Attribute | Description | |
---|---|---|---|---|
args | object | the argument object | ||
args.user | object | the user object | ||
args.role | object | array | use a provided role or array of roles, otherwise all roles of the user will be returned. | |
args.userrole | boolean | when provided as true, only assets associated to the user will be returned. | ||
args.type | string | the type of asset to retrieve. |
getAssetPartial(args: object, args.type: string, args.asset: object, args.nest: string, args.page: integer, args.pages: array): *
Name | Type | Attribute | Description |
---|---|---|---|
args | object | the argument object | |
args.type | string | the type of asset | |
args.asset | object | the asset. | |
args.nest | string | ||
args.page | integer | the page number | |
args.pages | array | the page range. |
findAssociatedRoles(args: object, args.type: string, args.asset: object): *
Retrieve roles that are associated to a given asset.
Name | Type | Attribute | Description |
---|---|---|---|
args | object | the argument object. | |
args.type | string | the type of asset being saught | |
args.asset | object | the asset. |
updateOne(args: object, args.collection: string, args.document: object, args.ops: object): Promise
Update a document
Name | Type | Attribute | Description |
---|---|---|---|
args | object | ||
args.collection | string | the collection which the saught document resides. | |
args.document | object | the document | |
args.ops | object | an 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
Name | Type | Attribute | Description |
---|---|---|---|
args | object | ||
args.collection | string | The collection to remove the document from | |
args.document | object | The 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
Name | Type | Attribute | Description |
---|---|---|---|
args | object | ||
args.collection | string | The collection to remove the document from | |
args.frag | object | The document being removed, we enforce. | |
args.documents | array | an array of documents scheduled for deleteion. |
deleteOneAsset(args: *): *
Name | Type | Attribute | Description |
---|---|---|---|
args | * | nullable: undefined |
releaseAssets(args: object): *
Release assets from a relationship, effective "un-sharing" them.
Name | Type | Attribute | Description |
---|---|---|---|
args | object | the 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.
Name | Type | Attribute | Description |
---|---|---|---|
args | object | the argument object. | |
args.type | string | the type of asset to release/unshare | |
args.target | object | the document to unrelease the share - normally a role. | |
args.targetType | string | the type of target, default 'role' |
assetToAssoc(method: String, type: String, asset: Object): Promise
Get the association representation of an asset.
Name | Type | Attribute | Description |
---|---|---|---|
method | String | the assoc_method , supported is 'clone', 'reference'. | |
type | String | the cannoncial type of the asset. | |
asset | Object | the asset |
assocToAsset(asset: Object): Promise
Gain the actual asset from an association method.
Name | Type | Attribute | Description |
---|---|---|---|
asset | Object | the 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)
Name | Type | Attribute | Description | |
---|---|---|---|---|
args | Object | the argument object | ||
args.type | String | the asset type | ||
args.role | Object | Array | the role(s) to perform reassociation upon. | |
args.method | String | the method to reassociate with. |
decouple_associates(o: *): *
Strip an objects out of arrays and objects, leaving just the attributes.
Name | Type | Attribute | Description |
---|---|---|---|
o | * | nullable: undefined |
parseQL(ql: *): *
Name | Type | Attribute | Description |
---|---|---|---|
ql | * | nullable: undefined |
idify(doc: *): *
Takes a document with a string typed _id, returns it with an ObjectId.
Name | Type | Attribute | Description |
---|---|---|---|
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
Name | Type | Attribute | Description |
---|---|---|---|
args | Object | the argument object. | |
args.key | String | the class variable to attach the instance to, default 'db'. | |
args.initialize | Boolean | Initialize the MongoAssets instance upon class declaration, default false. | |
args.config | Object | a configuration object, required if initializing via the decorator, otherwise argue your config to myClass.db.initialize() | |
args.config.endpoint | String | a mongo database URI. |
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago