IafItemSvc
Use the IafItemSvc API to create and manage item service resources in the Item Service.
addRelatedToItem#
Adds RelatedCollection class objects to a NamedCompositeItem, which is a collection of varied NamedUserItem classes, including collection classes.
| Parameter | Required | Type | Description |
|---|---|---|---|
| compId | Yes | String | The NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| userItems | Yes | RelatedCollection | Pass the array of RelatedCollection objects you want to add |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To add RelatedItem objects to a specific NamedCompositeItem version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. |
Promise<Page<RelatedCollection>> - A Page object with RelatedCollection objects
//Add tipversions of related collections to tip version of composite itemlet relatedCollections = [ { _userItemId: '5dcab6acfa877736bb1c5311' }, { _userItemId: '5dcab6acfa877736bb1c5313' }, { _userItemId: '5dcab6adfa877736bb1c5317' } ];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx);
// Add particular versions of related collections to tip version of composite itemlet relatedCollections = [ { _userItemId: '5dcbbd24f16c872134947df2', _userItemVersionId: '5dcbbd28f16c872134947dfb' }, { _userItemId: '5dcbbd24f16c872134947df4', _userItemVersionId: '5dcbbd28f16c872134947dfa' }];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx);
// Add related collections to particular version of composite itemlet relatedCollections = [ { _userItemId: '5dcbbd24f16c872134947df2', _userItemVersionId: '5dcbbd28f16c872134947dfb' }, { _userItemId: '5dcbbd24f16c872134947df4', // considers tip version }];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx, {userItemVersionId: "45cab6acfa877736bb1c5323"});addRelations#
Creates a new relationship between an item in one NamedUserCollection that you define as a parent with one or more items in another NamedUserCollection that you define as the child item or items.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The parent NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| relationships | Yes | Array<Relationship> | Pass a Relationship object that defines the relationship |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To create a relationship between related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create a relationship in the tip version, do not pass an options parameter. |
Promise<String> - Ok: 204 response
// Add children to tip version of parentlet relationShips = [ { _relatedFromId: container._id, // The parent item's id _relatedToIds: relatedToIds, // The child item ids _relatedUserItemDbId: childUserCollection._id // The child item collection id }];
let relations = await IafItemSvc.addRelations(parentCollection._id, relationShip);
// Add children to specific version of parent
let relationShips = [ { _relatedFromId: container._id, // The parent id _relatedToIds: relatedToIds, // The child item ids _relatedUserItemVersionId: childUserCollection._versions[2]._id, //The particular version of the collection that contains the new child item or items. _relatedUserItemDbId: userCollection._id // The child item collection id }];
let relations = await IafItemSvc.addRelations(parentCollection._id, relationShips, {"userItemVersionId":"5dafd77d6f2d3a4dcc55f90a"});addRelationsBulk#
Bulk creates new relationships between RelatedItems in one NamedUserCollection that you want to define as a parent with one or more RelatedItems in another NamedUserCollection that you want to define as the child item or items. To do this, pass an array of Relationship objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The named user collection id of the item you want to define as the parent. Pass either the _userItemId or the MongoDB ObjectId. |
| body | Yes | Array<Relationship> | The array of relationship objects. Do not pass an array that totals more than 10 MB in memory. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | UserCollectionBulkOperationOptions | To relate a specific version of items, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To relate items in the tip version, do not pass an options parameter. |
Promise<String> - Ok: 204 response
let parentCollection = "6336c490017d84b0a506e45d";
let relationShips = [ { “_relatedUserItemDbId”: "6336c490017d84b0a506e438", “_relatedFromId”: “6336c490017d84b0a506e439” “_relatedToIds”: [“6336c490017d84b0a506e43a”], “_relatedUserType”: “example_col”, “_userType”: “example_rel”, }, { “_relatedUserItemDbId”: "6336c490017d84b0a506e43b", “_relatedFromId”: “6336c490017d84b0a506e43c” “_relatedToIds”: ["65afd19364353a4dcc55f53c", "5dafd1936f2d3a4dcc55f8fa"], “_relatedUserType”: “example_col”, “_userType”: “example_rel_2”, }];
await IafItemSvc.addRelationsBulk(parentCollection, relationShips);aggregateReadings#
Execute an aggregation query on Reading objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | Pass either a NamedTelemetryCollection's ObjectId or _userItemId. |
| aggregations | Yes | Array | Array of aggregation stages |
| ctx | Yes | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | Yes | ItemsvcOptions | If you want to lookup in a specific collection version rather than the tip version, pass a ItemsvcOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter. |
Promise<Object> - Aggregation results
let aggs = [ { "$match": { "$and": [ { "_tsMetadata.type": { "$exists": true } } ] } }, { "$setWindowFields": { "partitionBy": "$_tsMetadata.type", "sortBy": { "_ts": 1 }, "output": { "averageValWitinMins": { "$avg": "$val", "window": { "range": [ -30, 30 ], "unit": "second" } } } } } ];
const readingAgg = await IafItemSvc.aggregateReadings(container._id, aggs, ctx, options);
//Sample response{ "_list": [ { "val": 871, "_tsMetadata": { "_sourceId": "7939bdd1-de6e-4247-93f7-9e0c9c09537a", "type": "37e51a11-ac60-424f-8f51-4a9e4bcad0fd" }, "_id": "645bca63f8b8a87c0f075cea", "averageValWitinMins": 696, "_ts": "Wed May 10 22:16:26 IST 2023" } ]}createIndex#
Creates indexes for a NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| body | Yes | Array<Index> | Pass an array of Index objects you define |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To create indexes for a specific collection version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. To create indexes in the tip version, do not pass an options parameter. |
Promise<Page<JSON>> - The NamedUserCollection's database indexes you create
let indexes = [ { "key": { "dtCategory": "text", "dtType": "text" }, "options": { "name": "dtCategory_dtType_full_text", "default_language": "english" } }];
let res = await IafItemSvc.createIndex(userCollection._id, indexes, ctx);createNamedUserItems#
Creates a NamedUserItem class object in the Item Service from the NamedUserItem you define.
| Parameter | Required | Type | Description |
|---|---|---|---|
| namedUserItems | Yes | Array<NamedUserItem> | Pass an array of JSON objects with the NamedUserItem properties and values you want to define the named user item. |
| itemClassName | Yes | ItemClass | Enter one of the following item classes as a string: NamedUserCollection, NamedFileCollection, NamedTelemetryCollection, UserConfig, Script, NamedCompositeItem. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemSvcOptions | To make the action transactional, pass a ItemSvcOptions object with a "transactional" property and set its value to true. |
Promise<Page<NamedUserItem>> - Created NamedUserItem objects in a Page object
const telementaryCollection = await IafItemSvc.createNamedUserItems( [ { _name: "Named Telemetry Collection", _shortName: "telementary_coll", _description: "Named Telemetry Collection to store sensor and points data", _namespaces: project._namespaces, _userType: "ref_app_telementary_collection", }, ], "NamedTelemetryCollection", ctx );createNamedUserItemVersion#
Creates a NamedUserItemVersion class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| userItemId | Yes | String | The NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| version | Yes | NamedUserItemVersion | Pass a NamedUserItemVersion object with properties and values you define |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<NamedUserItemVersion> - The creted NamedUserItemVersion object
const version = { _userAttributes: { folderName: "Warranty Docs" }};
const newVersion = await IafItemSvc.createNamedUserItemVersion(item._id, version);createPermissions#
Creates an array of Permission class objects for NamedUserItem class objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| permissions | Yes | Array<Permission> | Pass an array of Permission objects you define |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<CreatePermissionsResponse> - A CreatePermissionsResponse object with an array of successful permissions and an array of failed permissions
// Permissions with mandatory fieldslet permissions = [{ _actions: [ IafPermission.PermConst.Action.Read, IafPermission.PermConst.Action.Share, IafPermission.PermConst.Action.Delete], _namespace: "ProjA_HEpftR8X", _resourceDesc:{ _irn: IafPermission.NamedUserItemIrnAll }, _user:{ _id: "75b2a3d6-a3e8-498d-99dc-23538bc9a389", // Either user or usergroup id, specify respective _type _type: IafPermission.PermConst.UserType.User // Either user or usergroup, specify respective _id }}];
let result = IafItemSvc.createPermissions(permissions, ctx);
// Permissions with criteria.let permissions = [{ _actions: [IafPermission.PermConst.Action.Read, IafPermission.PermConst.Action.Share, IafPermission.PermConst.Action.Delete], _namespace: "ProjA_HEpftR8X", _resourceDesc:{ _irn": IafPermission.NamedUserItemIrnAll, _criteria: { _userType: "Project_Setup_Config" } }, _user:{ _id: "6336c490017d84b0a506e44d", // Either user or usergroup id, specify respective _type _type: IafItemSvc.PermConst.UserType.User // Either user or usergroup, specify respective _id }}];
let result = IafItemSvc.createPermissions(permissions, ctx);createRelatedItems#
Creates RelatedItem class objects in a NamedUserCollection. RelatedItems are items in NamedUserCollections that have the potential to relate to other items. If the total memory of the items you want to relate exeeds 1 MB or you want to relate more that 100 items, use the createRelatedItemsBulk method.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the MongoDB ObjectId or _userItemId. |
| body | Yes | Array<RelatedItem> | Pass an array RelatedItem objects you want to create. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | UserCollectionOptions | If you want to create RelatedItems in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter. |
Promise<Array<RelatedItem>> - An array of RelatedItem objects that each contain an _id property
// Create RelatedItems with the current version of NamedUserCollectionlet relatedItems = [ { "source_index": "accounts-4", "source_id": 2038 }, { "source_index": "accounts-2", "source_id": 2036 }];
let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);
// Create RelatedItems as a specific version of NamedUserCollectionlet options = {userItemVersionId: "5dafd1936f2d3a4dcc55f8fb"}let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx, options);
//Create related items with relationshiplet relatedItems = [ { "source_index": "accounts-4", "source_id": 2038, "_relationships":{ "_relatedUserItemDbId": "5cee7fee6505d6286dbca469", "_relatedUserItemVersionId": "5cee80c1fa298d0d3e34e23b", // Optional, if its not given tip version of _relatedUserItemDbId would be taken "_relatedToIds": [ "5cee7fe8c27e69cd0209ef46", "5cee7fe8c27e69cd0209ef47", "5cee7fe8c27e69cd0209ef48" ] } }];
let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);createRelatedItemsBulk#
Bulk creates RelatedItems in a NamedUserCollection. RelatedItems are items in NamedUserCollection that have the potential to relate to other items. Use this method instead of the createRelatedItems() method if the total memory of the items you want to create exeeds 1 MB or you want to create more that 100 items, use the createRelatedItemsBulk method.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| body | Yes | Array<RelatedItem> | Pass an array RelatedItem objects you want to create. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | UserCollectionBulkOperationOptions | If you want create related items in a specific collection version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter. |
JSON - A JSON object with "_createdCount" and "_uris" properties for each related item
// Bulk create related items with the current version of named user collectionlet relatedItems = [ { "source_index": "accounts-4", "source_id": 2038 }, { "source_index": "accounts-2", "source_id": 2036 }];
let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);
// Bulk create related items to a specific version of named user collectionlet options = {userItemVersionId: "5dafd1936f2d3a4dcc55f8fb"}let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx, options);
//Create related items with relationshiplet relatedItems = [ { "source_index": "accounts-4", "source_id": 2038, "_relationships":{ "_relatedUserItemDbId": "5cee7fee6505d6286dbca469", "_relatedUserItemVersionId": "5cee80c1fa298d0d3e34e23b", // Optional, if its not given tip version of _relatedUserItemDbId would be taken "_relatedToIds": [ "5cee7fe8c27e69cd0209ef46", "5cee7fe8c27e69cd0209ef47", "5cee7fe8c27e69cd0209ef48" ] } }];
let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);createRelatedReadingItems#
Creates Reading class objects as related Readings.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id, which can be either a MongoDB ObjectId or _userItemId. |
| readings | Yes | Array<Readings> | Array of Reading objects |
| ctx | Yes | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | Yes | ItemsvcOptions | If you want to lookup in a specific NamedUserCollection version rather than the tip version, pass a ItemsvcOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter. |
Promise<Page<Readings>> - A promise with a page of created Readings
await IafItemSvc.createRelatedReadingItems(collection._id, readingsArray, ctx, undefined);createTelemetryConfig#
Posts a TelemetryConfig to the Item Service when you pass your TelemetryConfig definition.
| Parameter | Required | Type | Description |
|---|---|---|---|
| telemetryConfig | Yes | undefined | |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemSvcOptions | To make the action transactional, pass a ItemSvcOptions object with a "transactional" property and set its value to true. |
| TelemetryConfig | Yes | TelemetryConfig | Pass a TelemetryConfig object with your bindings criteria. |
Promise<Page<TelemetryConfig>> - Returns the created TelemetryConfig objects in a Page object
const telemConfig = await IafItemSvc.createTelemetryConfig({ _namespaces: [ "lnt_bkJUK1W3" ], _shortName: "telconfig", _name: "Project A Telemetry Config", _userType: "telemetry_config", _configData: { _normalizationScript: { _userType: "telemetry_parser_script" }, _bindings: { collectionDesc: { _userItemId: "lnt_sensors__MogUhzsHhY" }, query: { "sensor_type": "co2" } } } }, ctx, undefined);deleteNamedUserItem#
Deletes a NamedUserItem by when you pass its id
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The NamedUserItem's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<String> - Ok: 204 response
const deletedItem = IafItemSvc.deleteNamedUserItem(item._id, ctx, undefined);deleteNamedUserItemVersion#
Deletes a NamedUserItemVersion.
| Parameter | Required | Type | Description |
|---|---|---|---|
| userItemId | Yes | String | The NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| versionId | Yes | String | The NamedUserItem's _version property value |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<String> - 204 response {ok:204}
await IafItemSvc.deleteNamedUserItemVersion(item._id, item.versions[3]._id);deletePermission#
Deletes a Permission class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The Permission object's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
const res = await IafItemSvc.deletePermission(permisssion._id, ctx);deleteRelatedItem#
Deletes a RelatedItem when you pass its id and the id of its related NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| itemId | Yes | String | The RelatedItem's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To delete a related item from a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To delete items in the tip version, do not pass an options parameter. |
Promise<String> - Ok: 204 response
await IafItemSvc.deleteRelatedItem(collection._id, item._id, ctx, undefined);deleteRelatedItems#
Deletes more than one RelatedItem in a NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The named user collection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| relatedItemIds | Yes | Array<String> | Pass an array of the RelatedItems' ids. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | UserCollectionOptions | To delete related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To delete items in the tip version, do not pass an options parameter. |
Promise<String> - Ok: 204 response
await IafItemSvc.deleteRelatedItems(collection._id, relatedItemIdsToDel, ctx);deleteRelatedItemsBulk#
Bulk deletes RelatedItems in an NamedUserCollection that match a query you pass. Lookup related items by userItemVersionId or tip version id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | RelatedItemCriteria | Filter criteria |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | UserCollectionBulkOperationOptions | It contains options such as userItemVersionId |
Promise<String> - ok: 204 response
// Delete RelatedItems by criteria from tip versionawait IafItemSvc.deleteRelatedItemsBulk(userCollectionId, {query:{"assetType": "door", "floor": 2}}, ctx, options);
// Delete RelatedItems by criteria from specific versionlet options = {userItemVersionId:"5dafd1936f2d3a4dcc55f8fa"};let relatedItems = await IafItemSvc.deleteRelatedItemsBulk(userCollectionId, {query:{"assetType": "door", "floor": 2}}, ctx, options);deleteRelationInItem#
Deletes a RelatedCollection relationship between a NamedCompositeItem and a NamedUserItem.
| Parameter | Required | Type | Description |
|---|---|---|---|
| compId | Yes | String | The NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| relatedCollectionId | Yes | String | The RelatedCollection's id |
| ctx | Yes | Cts | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To delete a specific RelatedCollection version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. |
Promise<String> - ok: 204 response
deleteRelations#
Deletes relationships for multiple parent RelatedItems in the same NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The id or _userItemId of the NamedUserCollection that contains the parent RelatedItem. |
| body | Yes | Array<RelationShip> | An array of the Relationship objects you want to delete. Each relationship object must contain the following properties: "_relatedFromId", "_relatedToIds", and "_relatedUserItemDbId" or "_relatedUserItemId". |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To delete a specific version of relationship rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. |
Promise<String> - ok: 204 response
let body = [ { "_relatedFromId": "4553e105026300398e2d6533", "_relatedToIds": ["5323e106786312398e2d653e"], "_relatedUserItemDbId": "6333e105026300398e2d653e", "_relatedUserItemVersionId": "8763e109456300398e2d623a" }, { "_relatedFromId": "6854e1657842596e2d6647", "_relatedToIds": ["9468e3645825555e9d693e"], "_relatedUserItemDbId": "6478e986545723548e2d687e", "_relatedUserItemVersionId": "3212e325415654879e2d973a" }];
await IafItemSvc.deleteRelations("6336c490017d84b0a506e43f", body);deleteTelemetryConfig#
Deletes a TelemetryConfig in the Item Service when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The TelemetryConfig's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<String> - Ok: 204 response
await IafItemSvc.deleteTelemetryConfig(id);dropIndex#
Removes a text Index by the name property.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| body | Yes | Object | An object with the name as the property and the index name as the value |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To remove a text Index for a specific version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. |
Promise<String> - Ok:204 response
//Drop index for tip versionlet body = { name: "dtCategory_dtType_full_text" };await IafItemSvc.dropIndex(userCollection._id, body, ctx );
//Drop index for specific version versionlet options = { userItemVersionId: "5dafd1936f2d3a4dcc55f8fa" };let body = {name: "dtCategory_dtType_full_text"};await IafItemSvc.dropIndex(userCollection._id, body, ctx, options);getAllNamedUserItems#
Gets all NamedUserItem class objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Pass an object that contains your simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require. |
Promise<Array<NamedUserItem>> - An array of all the NamedUserItem objects
await IafItemSvc.getAllNamedUserItems({ query: { _userType: "example_colection" }}, ctx, undefined);getIndexes#
Gets all indexes for a NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection id. Pass either the _userItemId or the MongoDB ObjectId. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To get the indexes of a specific NamedUserCollection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get indexes in the tip version, do not pass an options parameter. |
Promise<Page<JSON>> - The NamedUserCollection's database indexes
await IafItemSvc.getIndexes(collection._id);getInverseRelations#
Gets the inverse relationships in a NamedUserCollection when you pass a simple query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection id of the parent item. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | RelationShipCriteria | Pass an object that contains a simple query |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To get the inverse relationships between related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get inverse relationships in the tip version, do not pass an options parameter. |
Promise<Page<RelationShip>> -
let criteria = {"query":{"_relatedUserType": "file_container"}}
await IafItemSvc.getInverseRelations(parentCollection._id, criteria);getNamedUserItem#
Gets a NamedUserItem when you pass its id
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The NamedUserItem's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
const fileCollection = await IafItemSvc.getNamedUserItem(collection._id, ctx);getNamedUserItems#
Gets NamedUserItems with criteria you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Pass an object that contains your simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require. |
Promise<Page<NamedUserItem>> - A Page object with the NamedUserItem objects that match your query.
let query = { _usertype: "ref_app_telementary_collection", _name: "Named Telemetry Collection" };
const options = { project: {_userType: 1, _itemClass: 1}, sort: {_name: 1}, // -1 for descending order page: {_offset: 10, _pageSize: 20}};
let items = await IafItemSvc.getNamedUserItems({query}, context, options);getNamedUserItemVersion#
Gets a NamedUserItemVersion.
| Parameter | Required | Type | Description |
|---|---|---|---|
| userItemId | Yes | String | The NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| versionId | Yes | String | The NamedUserItem's "_version" property value |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<NamedUserItemVersion> - The user item version as a NamedUserItemVersion object
const version = await IafItemSvc.getNamedUserItemVersion(item._id, item.versions[3]._id);getNamedUserItemVersions#
Gets named user item versions based on a query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| userItemId | Yes | String | The user item's id. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | NamedUserItemVersionCriteria | Pass an object that contains your simple query |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with any of the following options as parameters: project, sort, page, and pagedRes. |
Promise<Page<NamedUserItemVersion>> - A Page object with a NamedUserItemVersion object
const criteria = { query: { _userAttributes.fileId: "6336c490017d84b0a506e450" }};
const versions = await IafItemSvc.getNamedUserItemVersions(item._id, criteria);getPermissions#
Gets permissions for File Service resources.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | PermissionCriteria | Pass a PermissionCriteria object that contains your simple query |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<Page<Permission>> - A promise with a Page object that contains the Permission objects that match your query
criteria = { _userType: "Project_Setup_Config"};
const permissions = await IafItemSvc.getPermissions(criteria, ctx);getRelatedInItem#
Gets the RelatedCollection class objects in a NamedCompositeItem.
| Parameter | Required | Type | Description |
|---|---|---|---|
| compId | Yes | String | The NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | RelatedCollectionCriteria | Pass an object that contains your simple query |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To get RelatedCollection class objects in a specific NamedCompositeItem version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. |
Promise<Page<RelatedCollection>> - RelatedCollection objects
//Get related collections from tip versionlet res1 = await IafItemSvc.getRelatedInItem(compItem._id, {}, ctx);
//Get related collections from specific versionlet res1 = await IafItemSvc.getRelatedInItem(compItem._id, {}, ctx, {userItemVersionId: "45cab6acfa877736bb1c5323"});getRelatedItem#
Get a RelatedItem in a NamedUserCollection when you pass the RelatedItem's id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| itemId | Yes | String | The RelatedItem's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To get a related item in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get items in the tip version, do not pass an options parameter. |
const relatedItem = await getRelatedItem(collection._id, item._id, ctx, undefined);getRelatedItems#
Gets the RelatedItems in a NamedUserCollection that match a query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | RelatedItemCriteria | Pass an object containing a simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | RelatedItemCriteriaOptions | Pass a RelatedItemCriteriaOptions object to set options, such as userItemVersionId, page, sort, pagedRes and project. |
Promise<Page<RelatedItem>> - The RelatedItem objects that match your query
let criteria = { query: { assetType: "door", floor: 2 }};
let options = { project:{ type: 1, floor: 1 }, sort: { floor: -1 }, page: { _pageSize: 2, _offset: 2 }};
// Get related items by criteria from tip versionlet relatedItems = await IafItemSvc.getRelatedItems(userCollectionId, criteria, ctx, options);
// Get related items by criteria from specific versionconst versiondedOptions = { ...options, userItemVersionId: versionId };let relatedItems = await IafItemSvc.getRelatedItems(userCollectionId, criteria, ctx, versiondedOptions);getRelatedItemUpdateLogs#
Gets update logs for a RelatedItem in a NamedUserCollection
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| itemId | Yes | String | The RelatedItem's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<Array<JSON>> - An array of the RelatedItem's update logs, which are JSON objects
await IafItemSvc.getRelatedItemUpdateLogs(userCollection._id, item._id);getRelatedReadingItems#
Gets all Reading class objects in a NamedTelemetryCollection or readings that match a query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | Pass either a NamedTelemetryCollection's ObjectId or _userItemId. |
| criteria | Yes | RelatedItemCriteria | Pass a RelatedItemCriteria object to filter for readings. |
| ctx | Yes | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | Yes | RelatedItemCriteriaOptions | Pass a RelatedItemCriteriaOptions object to use response options, such as userItemVersionId, page, sort and project. |
Promise<Page<Readings>> - A page of Reading objects
// Get readings by criteria from tip versionlet criteria = {query:{"$and": [{"_tsMetadata._telItemId": "61af69934e46196f8532bf13"},{"_ts": {"$gte":"2021-12-01T00:00:00.000Z"}}]}let options = {page: {_pageSize: 300, _offset: 0}, sort: {floor: 1}, project: {assetType: 1}}
const relatedItems = await IafItemSvc.getRelatedReadingItems( collection._id, criteria, ctx, options);getRelations#
Gets relationships in a NamedUserCollection with a query you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection id of the parent item. Pass either the _userItemId or the MongoDB ObjectId. |
| criteria | Yes | RelationshipCriteria | Pass an object that contains a simple query |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | RelationshipCriteriaOptions | To relate a specific version of items, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get relationships in the tip version, do not pass an options parameter. |
Promise<Page<RelationShip>> -
let criteria = {"query":{"_relatedUserType": "file_container"}}
await IafItemSvc.getRelations(parentCollection._id, criteria);getScriptContentUrlByCriteria#
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Pass an object that contains your simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
String - Script url that can be used in dynamic import
getTelemetryConfig#
Gets a TelemetryConfig by id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The TelemetryConfig's id |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
const telemConfig = await IafItemSvc.getTelemetryConfig(id);getTelemetryConfigs#
Gets TelemetryConfigs that match the criteria you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | TelemetryConfig | Pass a TelemetryConfig object that contains your simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | TelemetryConfigCriteriaOptions | Pass a TelemetryConfigCriteriaOptions object with the project, sort, page, and pagedRes options you require. |
Promise<Page<TelemetryConfig>> - A Page object with the TelemetryConfig objects that match your query.
getTelemetryProcessingErrors#
Gets telemetry processing errors.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | JSONObject | Pass an object that contains your simple query. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require. |
Promise<Page<TelemetryProcessingError>> - A Page object with the TelemetryProcessingError objects that match your query.
let criteria = { query: { _timestamp:{ "$gt": 1690788364587 } }};
let options = { project: {_exception: 1, _message: 1}, sort: {_timestamp: 1}, // -1 for descending order page: {_offset: 10, _pageSize: 20}};
const errors = await getTelemetryProcessingErrors(criteria, options);getUpdateLogs#
Gets a NamedUserCollection's update logs.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<Array<JSON>> - An array of update logs
getUpdateLogs(collection._id);ItemClass#
Item class constants
Type: string
searchRelatedItems#
Searches for related items with relationships with either a FindWithRelatedQuery, FindInCollectionsQuery, or DistinctRelatedItemFieldQuery.
| Parameter | Required | Type | Description |
|---|---|---|---|
| body | Yes | CustomRelatedItemQuery | Pass one of the following custom query types: FindWithRelatedQuery, FindInCollectionsQuery, DistinctRelatedItemFieldQuery. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
CustomRelatedItemQueryResponse - An array of RelatedItemQueryResponse objects, which contain the matching versions and parent related items, and strings detailing the time taken to execute the query.
Please refer {@link CustomRelatedItemQuery} for inputsupdateNamedUserItem#
Updates a NamedUserItem class object
| Parameter | Required | Type | Description |
|---|---|---|---|
| item | Yes | NamedUserItem | Pass your updated NamedUserItem object |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<String> - Response string 'Ok: 204'
item._name = “Named User Collection Example”;
const updatedItem = IafItemSvc.updateNamedUserItem(item, {"transactional": true});updateNamedUserItemVersion#
Updates the attributes of a particular NamedUserItemVersion class object
| Parameter | Required | Type | Description |
|---|---|---|---|
| userItemId | Yes | String | The NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId. |
| versionId | Yes | String | Pass the NamedUserItemVersion's id. |
| version | Yes | NamedUserItemVersion | Pass a NamedUserItemVersion object that contains the properties you want to update with their updated values. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
Promise<NamedUserItemVersion> - The updated user item version as a NamedUserItemVersion object
const version = { "_userAttributes": { "folderName": "Warranty Docs" }};
const updatedVersion = await IafItemSvc.updateNamedUserItemVersion(item._id, item.versions[3]._id, version, ctx, options);updatePermissions#
Updates Permission class objects for Item Service resources such as the following NamedUserItem classes: Script, UserConfig, NamedUserCollection, and NamedCompositeItem. If a permission doesn't exist, this method creates the permission. To check if a permission exists or not, the method checks one of the following fields of a permission object: _resourceDesc, _namespace, _user.
| Parameter | Required | Type | Description |
|---|---|---|---|
| permissions | Yes | Array<Permission> | Pass an array of updated Permission objects with the properties and the updated values |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
Promise<CreatePermissionsResponse> - A promise with a CreatePermissionsResponse object with an array of successful permissions and an array of failed permissions
updateRelatedItem#
Updates a RelatedItem in a NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| itemId | Yes | String | The RelatedItem's id |
| body | Yes | RelatedItem | Pass a RelatedItem object with the properties and values you want to update |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To update a related item in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To update a relationship in the tip version, do not pass an options parameter. |
Promise<RelatedItem> - Updated related item
const userCollectionId = collection._id;const relatedItemUpdate = {"_name": "new_name"};
await IafItemSvc.updateRelatedItem(userCollectionId, relatedItemId, relatedItemUpdate);updateRelatedItems#
Updates multiple RelatedItems in a NamedUserCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId. |
| items | Yes | Array<RelatedItem> | Pass an array of RelatedItem objects with an "_id" property and the properties and values you want to update |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage |
| options | No | UserCollectionOptions | To update related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To update related items in the tip version, do not pass an options parameter. |
Promise<String> - Ok: 204 response
const updatedRelatedItems = relatedItems.map(item => { item._userType = updated_rel_item_ut; return item;});
await IafItemSvc.updateRelatedItem(container._id, updatedRelatedItems);updateRelatedItemsBulk#
Updates RelatedItems in bulk. You can look up RelatedItems by userItemVersionId or the tip version by default.
| Parameter | Required | Type | Description |
|---|---|---|---|
| cid | Yes | String | The NamedUserCollection's id or _userItemId |
| items | Yes | Array<RelatedItem> | The updated array of RelatedItems. This update array replaces the existing array. The max request body must be 10MB or less. |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | UserCollectionBulkOperationOptions | It contains options such as userItemVersionId |
Promise<String> - ok: 204 response
updateTelemetryConfig#
Updates a telemetry config in the item service when you pass your updated TelemetryConfig object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| telemetryConfig | Yes | undefined | |
| ctx | No | Ctx | Context, such as authorization token requirements, namespaces, or session storage. |
| options | No | ItemsvcOptions | To make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true. |
| item | Yes | TelemetryConfig | Pass your updated TelemetryConfig object. |
const updatedTelemConfig = await IafItemSvc.updateTelemetryConfig({ _namespaces: [ "lnt_bkJUK1W3" ], _shortName: "telconfig", _name: "Project A Telemetry Config", _userType: "telemetry_config", _configData: { _normalizationScript: { _userType: "telemetry_parser_script" }, _bindings: { collectionDesc: { _userItemId: "lnt_sensors__MogUhzsHhY" }, query: { "sensor_type": "co2" } } }});