Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Aggregation utility for objects like in MongoDB
npm install aggio --save # Put latest version in your package.json
import { aggio, createDB, DB } from 'aggio';
describe('aggio', () => {
const Antonio = { name: 'Antonio' };
const Rafaela = { name: 'Rafaela' };
const users = [Antonio, Rafaela];
test('$matchOne', () => {
const sut = aggio(users, [{ $matchOne: { name: /ant/i } }]);
expect(sut).toMatchObject(Antonio);
});
test('$match with $sort', () => {
const sut = aggio(users, [{ $match: { name: { $exists: true } } }, { $sort: { name: 1 } }]);
expect(sut).toMatchObject([{ name: 'Antonio' }, { name: 'Rafaela' }]);
});
test('$keyBy with $sort', () => {
const sut = aggio<{ name: string }>(users, [
{ $keyBy: { name: { $exists: true } } },
{ $sort: { name: -1 } }, //
{ $matchOne: {} },
]);
expect(sut).toMatchObject({
Antonio,
Rafaela,
});
});
test('$groupBy with $sort and $update', () => {
const sut = aggio<{ name: string; age?: number }>(
[
...users,
{
name: 'Antonio',
age: 55,
},
],
[
{
$update: {
$match: { age: { $exists: false } },
$inc: { age: 20 },
},
},
{ $sort: { name: -1, age: -1 } },
{
$groupBy: { name: { $exists: true } },
},
{ $matchOne: {} },
]
);
expect(sut).toEqual({
Antonio: [
{
_id: expect.any(String),
age: 55,
name: 'Antonio',
},
{
_id: expect.any(String),
age: 20,
name: 'Antonio',
},
],
Rafaela: [
{
_id: expect.any(String),
age: 20,
name: 'Rafaela',
},
],
});
});
});
describe('DB', () => {
let db: DB<{ name: string }>;
beforeEach(async () => {
db = createDB();
});
test('db.insert', async () => {
const sut = db.insert(users);
expect(sut).toEqual([
{
_id: expect.any(String),
name: 'Antonio',
},
{
_id: expect.any(String),
name: 'Rafaela',
},
]);
});
test('db.update', async () => {
db.insert(users);
const sut = db.update({ name: /ant/i }, { $inc: { age: 1 } });
expect(sut).toEqual({
numAffected: 1,
updated: expect.objectContaining({
...Antonio,
age: 1,
}),
upsert: false,
});
});
test('db.count', async () => {
db.insert(users);
const sut = db.count({ name: /ant/i });
expect(sut).toEqual(1);
});
test('db.find', async () => {
db.insert(users);
const sut = db.find({ name: /ant/i }).exec();
expect(sut).toEqual([expect.objectContaining(Antonio)]);
});
test('db.findOne', async () => {
db.insert(users);
const sut = db.findOne({ name: /ant/i }).exec();
expect(sut).toMatchObject(Antonio);
});
test('db.remove', async () => {
db.insert(users);
const sut = db.remove({ name: /ant/i });
expect(sut).toEqual(1);
});
});
See License
FAQs
In memory database with subset of MongoDB's API and plenty fast.
The npm package aggio receives a total of 69 weekly downloads. As such, aggio popularity was classified as not popular.
We found that aggio 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.