@graffy/index-watcher
v0.14.8-beta.1
Published
Watch provider for the index pattern:
Downloads
42
Readme
Graffy Index Watcher
Watch provider for the index pattern:
{
users: { userId: { ... }, ... },
users$: {
encodedParameters: page({
[indexKey]: link('/users/userId'),
...
}),
...
}
}
Here, users$ is an index into the users collection.
While it is straightforward to create a watch provider (change stream) for the users
tree, it is not as easy to create one for the users$
tree, especially when arbitrary filtering parameters are supported. IndexWatcher can help craft an index change stream using the entity change stream and an indexing function:
store.use(
'/users$',
IndexWatcher(
'/users', // Entity path prefix
{ country: true, createTime: true }, // Entity sub-query
(user, params) => {
// Indexing function
if (params.country !== user.country) return; // Exclude from index.
return [user.createTime]; // An array of index keys.
},
),
);
This assumes:
- Index and entity trees with the same structure as above
See Graffy documentation for more.