OIH Standard Library
Table of Contents
Actions
Upsert Object
Lookup Object (at most 1)
Lookup Objects (Plural)
Delete Object
For implementing Delete action in most cases you need to extend from DeleteById
or DeleteByUniqueCriteria
classes.
If you need completely custom behaviour you can extend from Delete
class and override process and deleteObject method,
in this case following OIH standard is your responsibility.
Delete By ID
Note:
- Its your responsibility to ensure that deleteObject deletes only 1 object. This implementation assume that
id
is unique for objectType
. - If
deleteObject
method is returning null
empty object would be emitted. You can indicate with null
that object hasn`t been deleted or found.
- Create Action
- Create class that extends DeleteById class
- Override
deleteObject()
methods. Example below. - Optional override
getType
and getId
methods. Default implementation expects objectType
to be present in input configuration and id
in input message. - Create instance of your class and pass
logger
to constructor. const myDeleteByIDImpl = new MyDeleteByIdImpl(logger);
- Export
myDeleteByIDImpl.process(msg, cfg, snapshot)
as process method. Example below.
Example of Usage
Works in sailor > 2.4.2
Delete Action
const { DeleteById } = require('@elastic.io/oih-standard-library/lib/actions/delete');
class MyDeleteByIDImpl extends DeleteById {
async deleteObject(id, cfg, msg) {
const deletedID = await deleteObjectInAPI(id, cfg, msg);
return deletedID;
}
}
async function process(msg, cfg, snapshot = {}) {
const deleteAction = new MyDeleteByIDImpl(this.logger);
return deleteAction.process(msg, cfg, snapshot);
}
module.exports.process = process;
Delete By Unique Criteria
Note:
- If more than 1 object was found with same uniqueCriteria, error would be thrown by this implementation
- If
deleteObject
method is returning null
empty object would be emitted. You can indicate with null
that object hasn`t been deleted or found.
- Create Action
- Create class that extends DeleteById class
- Override
findObjectByCriteria
and deleteObject()
methods. Example below. - Optional override
getType
and getCriteria
methods. Default implementation expects objectType
to be present in input configuration. For unique criteria: uniqueCriteria
field name in input configuration and value in input message. - Create instance of your class and pass
logger
to constructor. const myDeleteByCriteriaImpl = new MyDeleteByCriteriaImpl(logger);
- Export
myDeleteByCriteriaImpl.process(msg, cfg, snapshot)
as process method. Example below.
Example of Usage
Works in sailor > 2.4.2
Delete Action
const { DeleteByUniqueCriteria } = require('@elastic.io/oih-standard-library/lib/actions/delete');
class MyDeleteByCriteriaImpl extends DeleteByUniqueCriteria {
async findObjectByUniqueCriteria(criteria, type, cfg, msg) {
const object = await findObjectInAPI(criteria, type, cfg, msg);
const numberOfObjects = object.count;
return {
object,
numberOfObjects
}
}
async deleteObject(object, cfg, msg) {
const deletedID = await deleteObjectInAPI(object, cfg, msg);
return deletedID;
}
}
async function process(msg, cfg, snapshot = {}) {
const deleteAction = new MyDeleteByCriteriaImpl(this.logger);
return deleteAction.process(msg, cfg, snapshot);
}
module.exports.process = process;
Triggers
Get New and Updated Objects Polling
Webhooks