
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@onehat/data
Advanced tools
@onehat/data A robust ORM for Javascript. Can CRUD, search, sort, filter, paginate your data. Integrates with many front- and back-end storage mediums.
npm i @onehat/data
Comprehensive unit tests can be found in ./cypress/integration. These are an excellent source of code examples. Comprehensive API documentation can be found in ./docs.
For every type of Entity you will use (e.g. Users or Animals or Invoices), define a Schema. A Schema determines the various Properties that each Entity will have, as well as the medium where the Entities will be stored.
const Users = {
name: 'Users',
model: {
idProperty: 'id',
displayProperty: 'username',
properties: [
{ name: 'id', type: 'int', },
{ name: 'username', type: 'string', }, // explicitly set property type
{ name: 'password', }, // type: 'string' is assumed, if not explicitly set
{ name: 'first_name', },
{ name: 'last_name', },
{ name: 'email', allowNull: false, }, // make it a required field
{ name: 'last_login', type: 'datetime', defaultValue: 'now', }, // give it a default value.
],
sorters: [
{
name: 'last_name',
direction: 'ASC',
},
{
name: 'first_name',
direction: 'ASC',
},
],
},
repository: 'memory', // Repository type. Can be string name or config object
};
export default Users;
Every Property must have a unique name. All other attributes are optional. Common Property attributes include:
Other Property attributes exist and can be found in the API.
The easiest way to create one or more Repositories is to use the global oneHatData singleton object. Each schema will have a bound repository of the same name (e.g. "Users", or "Groups").
import oneHatData from '@onehat/data';
import Groups from './Groups';
import Users from './Users';
oneHatData
.createSchemas([
Groups,
Users,
])
.createBoundRepositories()
.then(() => {
setIsReady(true);
const UsersRepository = oneHatData.getRepository('Users');
// Do something with your data
});
Once you have a Repository initialized, you can start adding data to it. Data is manipulated asynchronously, so you may optionally wait for it to complete.
const UsersRepository = oneHatData.getRepository('Users');
// 1. Add an Entity
const userEntity = await UsersRepository.add({
username: 'ajones',
password: '12345',
first_name: 'Alice',
last_name: 'Jones',
email: 'alice@example.com',
});
// 2. Edit an Entity
// Use assignment to change the value of a particular Property.
userEntity.password = 'mypass';
// Or you can be more verbose about it
userEntity.getProperty('password').setValue('mypass');
// 3. Delete an Entity
userEntity.delete();
// Or delete it from the Repository
await UsersRepository.delete(userEntity);
There are lots of filtering and sorting methods available on Repositories.
// Add a single filter
UsersRepository.filter('first_name', 'Alice');
const foundEntities = UsersRepository.entities;
// Or search by an id or function
const myEntity = UsersRepository.getById(1);
const results = UsersRepository.getBy((entity) => {
return entity.id > 2;
});
// Sort the entities by a particular Property
UsersRepository.sort('last_name', 'DESC');
const sortedEntities = UsersRepository.entities;
Repositories, Entities, and Properties emit many different kinds of events.
// The 'change' event, emitted from an Entity, is relayed through the Repository and becomes 'entity_change'
UsersRepository.on('entity_change', (entity) => {
console.log('changed entity');
});
userEntity.first_name = 'Joe';
// prints 'changed entity' to console
// The 'changeData' event is fired from the Repository after multiple Entities are loaded at once
UsersRepository.on('changeData', (entities) => {
console.log('entities changed');
});
UsersRepository.load([
{ email: 'alice@example.com' },
{ email: 'bob@example.com' },
{ email: 'charlie@example.com' },
]);
// prints 'entities changed' to console
FAQs
JS data modeling package with adapters for many storage mediums.
We found that @onehat/data demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.