Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A no-frills ORM that wraps your data and helps you compose objects. Define relationships between models, expand and collapse their properties, build streams and link data from multiple sources.
A no-frills ORM that wraps your data and helps you compose objects. Define relationships between models, expand and collapse their properties, build streams and link data from multiple sources.
You know the drill.
$ npm install friendly
For full documentation see the API DCOS.
Two primary methods, EXPAND and COLLAPSE. Both methods work on a single parent object or an array of parent objects with nested children. A child property can be a foreign key, an object with a foreign key, or an array of either.
It looks as easy as it sounds. Convert something like this.
Book: {
id: 120,
name: 'Code Complete 2',
author: 19237
}
Into this...
Book: {
id: 120,
name: 'Code Complete 2',
author: {
id: 19237,
name: 'Steve McConnel'
}
}
First configure your models for later use. Configuration takes a name, provider, children, and optional collapsables.
So given a Book model that has an id property with a nested author child, our configure method call would look like this:
var friendly = require('friendly');
friendly.createModel({
name: 'book',
key: 'id',
collapsables: 'title', // or ['title', 'publishedDate']
children: 'author', // or ['author', 'category']
provider: function(id){
// return a promise that finds the book
return findBooksByIdPromise(id);
}
});
Putting it all together and expanding/collapsing our book with authors would look like this:
var friendly = require('friendly');
friendly.createModel({
name: 'book',
key: 'id',
children: 'author',
provider: function(id){
// return a promise that finds the book
return findAuthorsByIdPromise(id);
}
});
friendly.createModel({
name: 'author',
key: 'id',
provider: function(id){
// return a promise that finds the author
return findBooksByIdPromise(id);
}
});
var exampleAuthor = {
id: '19237',
name: 'Steve McConnel'
};
var exampleBook = {
id: '203',
name: 'Code Complete 2',
author: '19237'
};
friendly.expand('book', exampleBook).then(function(expandedBook){
console.log(expandedBook);
/** prints
{
id: '203',
name: 'Code Complete 2',
author: {
id: '19237',
name: 'Steve McConnel'
}
}
*/
var collapsedBook = friendly.expand('book', expandedBook);
console.log(collapsedBook);
/** prints
{
id: '203',
name: 'Code Complete 2',
author: '19237'
}
*/
});
4 ways. Pay attention to how the author object changes in these examples. These are assuming you've created both a book and author model, and the author models key is set to 'id'.
// #1 - author as a primitive value
var book = {
id: '203',
name: 'Code Complete 2',
author: '19237'
};
// #2 - author as an object
var book = {
id: '203',
name: 'Code Complete 2',
author: {
id: '19237'
}
};
// #3 - multiple authors as an array of primitive values
var book = {
id: '203',
name: 'Code Complete 2',
author: ['19237', '2462']
};
// #4 - multiple authors as an object array of objects
id: '203',
name: 'Code Complete 2',
author: [
{ id: '19237' },
{ id: '2462' },
]
};
Expand/Collapse accepts an optional 'path' as it's third argument. Dot notation can also be used. This is essentially a utility function.
var object = {
inner: {
book: {
name: 'Code Complete 2',
author: '19237'
}
}
};
friendly.expand('book', object, 'inner.book').then(function(expandedBook){
console.log(expandedBook);
/** prints
{
inner: {
book: {
name: 'Code Complete 2',
author: {
id: '19237',
name: 'Steve McConnel'
}
}
}
}
*/
});
FAQs
A no-frills ORM that wraps your data and helps you compose objects. Define relationships between models, expand and collapse their properties, build streams and link data from multiple sources.
We found that friendly demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.