Package Exports
- resolve-readmodel-memory
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (resolve-readmodel-memory) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
resolve-readmodel-memory 
This package is a resolve-query
adapter for storing a read model in memory. The adapter is based on key/value ES6 Map
interface and does not have binary dependencies.
The store interface is implemented using the resolve-readmodel-memory
adapter and provides segregated read and write access:
- Read access is used to retrieve data from a store (for example, by a graphql resolver). The package provides the
hget(key, field)
asynchronous method to get the value associated with thefield
from the hash stored at thekey
. - Projection functions use Write access to update data. The following asynchronous methods are available:
hset(key, field, value)
- sets thevalue
associated with thefield
in the hash stored atkey
;del(key)
- deletes the hash stored at thekey
. Does nothing if thekey
does not exist.
Usage
import createMemoryAdapter from 'resolve-readmodel-memory';
import { createReadModel } from 'resolve-query';
const adapter = createMemoryAdapter();
const testEventStore = {
subscribeByEventType: (_, handler) => Promise.resolve(
handler({ type: 'TestEvent', text: 'One' }),
handler({ type: 'TestEvent', text: 'Two' })
)
};
const executeReadModel = createReadModel(
eventStore: testEventStore,
adapter,
projection: {
Init: async (store) => {
await store.hset('Test', 'myField', { changeCount: 0, text: 'Initial' })
},
TestEvent: async (store, event) => {
const value = await store.hget('Test', 'myField');
const newValue = {
changeCount: value.changeCount + 1,
text: event.text
};
await store.hset('Test', 'myField', newValue);
}
}
)
const store = await executeReadModel();
const value = store.hget('Test', 'myField');
console.log(value)