@graffy/index-watcher

0.14.8-beta.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @graffy/index-watcher

Weekly Downloads

0

Version

0.14.8-beta.1

License

Apache-2.0

Unpacked Size

18.9 kB

Total Files

7

Last publish

Collaborators

  • aravindet