Nested Collections is a collections manager that allows you to store items consisting of an id and a value. It supports a recursive structure where you can create descendant collections within a parent collection.
A key feature is the ability to retrieve all items from the entire hierarchy in a single flat array via the flat property, where each item is augmented with a collection path (e.g., parent:child:grandchild). It also supports event listening via onChange to react to any changes in the hierarchy.
const { NestedCollections } = require("@mocks-server/nested-collections");
const alerts = new NestedCollections("alerts");
alerts.set("root", "This alert is stored in the root collection");
const pluginsAlerts = alerts.collection("plugins");
pluginsAlerts.set("foo-alert-id", "This alert is stored in the plugins collection");
console.log(alerts.flat);
/*
[
{ id: 'root', value: '...', collection: 'alerts' },
{ id: 'foo-alert-id', value: '...', collection: 'alerts:plugins' }
]
*/