The healthstorage-odm serves the HS storage api. It provides a simple structure to use the interface efficiently and purposefully.
First install node.js.
npm install healthstorage-odm
// Using ES6 imports
import HealthStorageODM from 'healthstorage-odm';
This is the entry point of the odm.
Usable constants for schema creation in field types.
HealthStorag.STRING // string type
HealthStorag.NUMBER // number type
HealthStorag.INTEGER // integer type
HealthStorag.BOOLEAN // boolean type
HealthStorag.OBJECT // object type
HealthStorag.ARRAY // array type
HealthStorag.DATE // date type
// Calling static function create schema
HealthStorageODM.createSchema({
title: 'SampleSchema',
properties: {
id: {
type: HealthStorageODM.STRING
},
title: {
type: HealthStorageODM.STRING
},
color: {
type: HealthStorageODM.STRING
}
},
options: {
required: ['md']
}
})
// Calling static function in HealthStorageODM
HealthStorageODM.deleteSchemaById(id)
// By calling constructor with default options
const CLIENT = new HealthStorageODM();
// By calling static createClient
const CLIENT = HealthStorageODM.createClient({
serverUrl: 'https://your.server.url',
adapter: 'adpater'
});
The HsClient holds specific data for server connection, adapter and debugging. You can create muliple HsClients in your project to connect to different servers. In future use the used adapter could be anything we implement to build a bridge between systems. For now only the HsStorage is ready to use.
// By calling constructor with default
const CLIENT = new HealthStorageODM();
// By calling constructor with custom options
const CLIENT = new HealthStorageODM({
serverUrl: 'https://your.server.url',
adapter: 'adapter'
});
// By calling static createClient
const CLIENT = HealthStorageODM.createClient({
serverUrl: 'https://your.server.url',
adapter: 'adpater'
});
The HsModel provides functionallity to interact with the selected adapter. It is like a services between this two layers. The Model needs a schema and identifier to deal with. There are static function which you can call directly after initialize the model and model binded function which interacts with the model itself.
All models reference from md.id to _id and md.r to __v (id of model and version of model)
// Create a const which is holding the schema data
const SomeSchema = {
title: 'SomeSchema',
properties: {
title: {
type: HealthStorageODM.STRING
},
description: {
type: HealthStorageODM.STRING
},
price: {
type: HealthStorageODM.DOUBLE
},
online: {
type: HealthStorageODM.BOOLEAN
},
hits: {
type: HealthStorageODM.INTEGER
}
},
options: {
required: [md],
oId: '1a8a1956-fde7-486f-91b8-ce9a3d9b4be1', // uuid
id: '5cc6ae3e-bf8f-4be5-b6fb-5de55ca9fd8a' // uuid
}
}
// create the new model
const SomeModel = CLIENT.define('SomeModel', SomeSchema)
HsModel.ASC // ascending sort dir
HsModel.DESC // descending sort dir
HsModel.MD_ID // meta id sort field
HsModel.MD_REVISION // meta revision sort field
HsModel.MD_DATE // meta date sort field
HsModel.EQUAL // filter request equal
HsModel.NOT_EQUAL // filter request unequal
HsModel.CONTAINS // filter request contains
HsModel.NOT_CONTAIN // filter request not contains
HsModel.START_WITH // filter request string start with
HsModel.END_WITH // filter request string end with
HsModel.LOWER_THAN // filter request lower than
HsModel.LOWER_EQUAL_THAN // filter request lower equal than
HsModel.GREATER_THAN // filter request greater than
HsModel.GREATER_EQUAL_THAN // filter request greater equal than
HsModel.AND // filter request logical and for filter fields
HsModel.OR // filter request logical or for filter fields
/**
* Find one entry
* @param {Object} where key value pairs for filter
* @param {Object} opts logic, take, skip, sort
* @returns {Promise}
*
* Can also called without the filter param. In this case all entries for your request retruned
**/
SomeModel.find({
filter: {
take: 10,
skip: 0,
sort:[{
field: 'md.id',
dir: 'asc'
}],
filters: [{
'field': 'name',
'operator': HsModel.EQUAL,
'value': 'Username',
}]
}
})
/**
* Find one entry
* @param {Object} where key value pairs for filter
* @param {Object} opts logic, take, skip, sort
* @returns {Promise}
**/
SomeModel.findOne(
{
username: 'username',
email: 'email'
},
{
logic: HsModel.AND
}
)
/**
* Find one entry and update it with new data
* @param {Object} where key value pairs for filter
* @param {Object} data new data for update
* @param {Object} opts logic, take, skip, sort
* @returns {Promise}
**/
SomeModel.findOneAndUpdate(
{
username: 'username'
},
{
firstName: 'Karsten',
lastName: 'Grizzle'
}
{
logic: HsModel.AND
}
)
/**
* Find entry by its identifier
* @param {String} sdoId
* @returns {Promise}
**/
SomeModel.findById('013f6860-56c1-4299-b418-07ba4f13d16a')
/**
* Find blob for entry by its identifier
* @param {String} id
* @returns {Promise}
**/
SomeModel.findBlobById('013f6860-56c1-4299-b418-07ba4f13d16a')
/**
* Find blob file entry by its identifier
* @param {String} sdoId
* @param {String} blobId
* @returns {Promise}
**/
SomeModel.findBlobFileById('013f6860-56c1-4299-b418-07ba4f13d16a', '013f6860-56c1-4299-b418-07ba4f13d16b')
/**
* Create a new entry
* @param {Object} data
* @returns {Promise}
*/
SomeModel.create({
username: 'username',
email: 'email',
password: 'password'
})
/**
* Check if sdo changed since specified item
* @param {String} sdoId
* @param {Integer} r
* @returns {Promise}
*/
SomeModel.changedSinceByIdAndRevision('013f6860-56c1-4299-b418-07ba4f13d16a', 1)
/**
* Update sdo by identifiern and given data
* @param {String} sdoId
* @param {Object|HsModel} data
* @returns {Promise}
*/
SomeModel.updateById('013f6860-56c1-4299-b418-07ba4f13d16a', {
username: 'username',
email: 'email'
})
/**
* Coming soon
*/
SomeModel.toBeDefined()
/**
* Coming soon
*/
SomeModel.toBeDefined()
/**
* Update bulk list
* @param {Array} bulkList holds HsModels to update
* @returns {Promise}
*/
SomeModel.updateById(bulkList)
)
/**
* Coming soon
*/
SomeModel.toBeDefined()
/**
* Coming soon
*/
SomeModel.toBeDefined()
/**
* Lock entry by its identifier
* @param {String} id
* @returns {Promise}
*/
SomeModel.lockById('013f6860-56c1-4299-b418-07ba4f13d16a')
/**
* Unlock entry by its identifier and lockValueId
* @param {String} id
* @param {String} lockValueId
* @returns {Promise}
*/
SomeModel.unlockById('013f6860-56c1-4299-b418-07ba4f13d16a', '013f6860-56c1-4299-b418-07ba4f13d90k')
/**
* Get lock value on sdo by its identifier and lock value
* @param {String} id
* @param {String} lockValueId
* @returns {Promise}
*/
SomeModel.getLockDataById('013f6860-56c1-4299-b418-07ba4f13d16a', '013f6860-56c1-4299-b418-07ba4f13d90k')
/**
* Check if sdo is locked
* @param {String} id
* @param {String} lockValueId
* @returns {Promise}
*/
SomeModel.isLockedById('013f6860-56c1-4299-b418-07ba4f13d16a', '013f6860-56c1-4299-b418-07ba4f13d90k')
/**
* Check if sdo exists with lock State
* @param {String} id
* @param {Boolean} lockState
* @returns {Promise}
*/
SomeModel.existsInLockStateById('013f6860-56c1-4299-b418-07ba4f13d16a', true)
/**
* Delete entry by its identifier
* @param {String} id
* @returns {Promise}
*/
SomeModel.deleteById('013f6860-56c1-4299-b418-07ba4f13d16a')
/**
* Coming soon
*/
SomeModel.toBeDefined()
/**
* Get archive from entry (full arichve entries as array of object)
* @param {String} id
* @param {Integer} pageNo
* @param {Integer} pagesize
* @returns {Promise}
*/
SomeModel.getArchiveBySdoId('013f6860-56c1-4299-b418-07ba4f13d16a', 1, 15)
/**
* Get archive from entry (revison numbers as array)
* @param {String} id
* @returns {Promise}
*/
SomeModel.getRevisionsArchiveBySdoId('013f6860-56c1-4299-b418-07ba4f13d16a')
/**
* Create a new sod blob
* @param {Object} data needs to be form data
* @returns {Promise}
*/
SomeModel.createBlob(sdoBlobFormdata)
/**
* Save created model with its properties
* @return {Promise}
*/
SomeModel.save()
/**
* Update changed properties in model
* @return {Promise}
*/
SomeModel.update()
/**
* Destroy model itself
* @return {Promise}
*/
SomeModel.destroy()
/**
* Get attached File from model
* @return {Promise}
*/
SomeModel.destroy()
/**
* Archive model
* @return {Promise}
*/
SomeModel.archive()
/**
* Get archived revison numbers for model
* @return {Promise}
*/
SomeModel.getArchivedRevisions()
/**
* Get archived sdos mof model
* @param {Integer} pageNo
* @param {Integer} pageSize
* @return {Promise}
*/
SomeModel.getArchive(pageNo = 1, pageSize = 10)
/**
* Check model last change since
* @return {Promise}
*/
SomeModel.changedSince()
/**
* Lock model
* @return {Promise}
*/
SomeModel.lock()
/**
* Unlock model
* @return {Promise}
*/
SomeModel.unlock()
/**
* Get lock data for model
* @return {Promise}
*/
SomeModel.getLockData()
/**
* Check if model is locked
* @return {Promise}
*/
SomeModel.isLocked()
/**
* Check if model exists in specific lock state
* @param {String} lockState
* @return {Promise}
*/
SomeModel.isInLockState()
Open console in healthstorage-odm package and move to ./src/example/todo
. Type in npm install
and install dependencies.
Important: First install all dependencies.
We adapt an example app from todoMVC to demonstrate the HsOdm in an runnable environment.
Move to ./src/example/todo
. Type in npm start
to run webpack.
Enjoy.
We made an hsodm playground to demonstrate the HsOdm and see requests and response. Type in the schema id and owner id to interact with yout schema. You can add, edit, delete and search for entries.
Move to ./src/example/playground
. Type in npm start
to run webpack.
Enjoy.