![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
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.
The npm package friendly receives a total of 0 weekly downloads. As such, friendly popularity was classified as not popular.
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.