Skip to content

Commit

Permalink
Feature/Read model adapters config (#873)
Browse files Browse the repository at this point in the history
Implement invert read model adapter passing for application with default adapter for local/cloud development
  • Loading branch information
IhostVlad authored Nov 21, 2018
1 parent 12eac8b commit a54b03c
Show file tree
Hide file tree
Showing 36 changed files with 238 additions and 172 deletions.
3 changes: 2 additions & 1 deletion examples/hacker-news/config.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const appConfig = {
{
name: 'HackerNews',
projection: 'common/read-models/hacker-news.projection.js',
resolvers: 'common/read-models/hacker-news.resolvers.js'
resolvers: 'common/read-models/hacker-news.resolvers.js',
adapterName: 'default'
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions examples/hacker-news/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const devConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
HackerNews: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
jwtCookie: {
name: 'jwt',
maxAge: 31536000000
Expand Down
7 changes: 4 additions & 3 deletions examples/hacker-news/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const prodConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'production',
readModelAdapters: {
HackerNews: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
jwtCookie: {
name: 'jwt',
maxAge: 31536000000
Expand Down
7 changes: 4 additions & 3 deletions examples/hacker-news/config.test-functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const testFunctionalConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
HackerNews: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
jwtCookie: {
name: 'jwt',
maxAge: 31536000000
Expand Down
3 changes: 2 additions & 1 deletion examples/hello-world/config.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const appConfig = {
{
name: 'read-model-name',
projection: 'common/read-models/read-model-name.projection.js',
resolvers: 'common/read-models/read-model-name.resolvers.js'
resolvers: 'common/read-models/read-model-name.resolvers.js',
adapterName: 'default'
}
],
viewModels: [
Expand Down
7 changes: 4 additions & 3 deletions examples/hello-world/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const devConfig = {
staticDir: 'static',
distDir: 'dist',

readModelAdapters: {
'read-model-name': {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {
Expand Down
7 changes: 4 additions & 3 deletions examples/hello-world/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const prodConfig = {
staticDir: 'static',
distDir: 'dist',

readModelAdapters: {
'read-model-name': {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {
Expand Down
7 changes: 4 additions & 3 deletions examples/hello-world/config.test_functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const testFunctionalConfig = {
staticDir: 'static',
distDir: 'dist',

readModelAdapters: {
'read-model-name': {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {
Expand Down
3 changes: 2 additions & 1 deletion examples/shopping-list-advanced/config.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const appConfig = {
{
name: 'ShoppingLists',
projection: 'domain/read-models/shopping_lists.projection.js',
resolvers: 'domain/read-models/shopping_lists.resolvers.js'
resolvers: 'domain/read-models/shopping_lists.resolvers.js',
adapterName: 'default'
}
],
jwtCookie: {
Expand Down
7 changes: 4 additions & 3 deletions examples/shopping-list-advanced/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const devConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default devConfig
7 changes: 4 additions & 3 deletions examples/shopping-list-advanced/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const prodConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'production',
readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default prodConfig
7 changes: 4 additions & 3 deletions examples/shopping-list-advanced/config.test_functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const testFunctionalConfig = {
polyfills: ['@babel/polyfill'],
mode: 'development',

readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {}
Expand Down
3 changes: 2 additions & 1 deletion examples/shopping-list/config.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const appConfig = {
{
name: 'ShoppingLists',
projection: 'common/read-models/shopping_lists.projection.js',
resolvers: 'common/read-models/shopping_lists.resolvers.js'
resolvers: 'common/read-models/shopping_lists.resolvers.js',
adapterName: 'default'
}
],
apiHandlers: [
Expand Down
7 changes: 4 additions & 3 deletions examples/shopping-list/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const devConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default devConfig
7 changes: 4 additions & 3 deletions examples/shopping-list/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const prodConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'production',
readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default prodConfig
7 changes: 4 additions & 3 deletions examples/shopping-list/config.test_functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const testFunctionalConfig = {
polyfills: ['@babel/polyfill'],
mode: 'development',

readModelAdapters: {
ShoppingLists: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {}
Expand Down
3 changes: 2 additions & 1 deletion examples/with-saga/config.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const appConfig = {
{
name: 'default',
projection: 'common/read-models/default.projection.js',
resolvers: 'common/read-models/default.resolvers.js'
resolvers: 'common/read-models/default.resolvers.js',
adapterName: 'default'
}
],
viewModels: [
Expand Down
7 changes: 4 additions & 3 deletions examples/with-saga/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const devConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
default: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default devConfig
7 changes: 4 additions & 3 deletions examples/with-saga/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const prodConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'production',
readModelAdapters: {
default: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
}
]
}

export default prodConfig
7 changes: 4 additions & 3 deletions examples/with-saga/config.test_functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const testFunctionalConfig = {
port: 3000,
polyfills: ['@babel/polyfill'],
mode: 'development',
readModelAdapters: {
default: {
readModelAdapters: [
{
name: 'default',
module: 'resolve-readmodel-memory',
options: {}
}
},
],
storageAdapter: {
module: 'resolve-storage-lite',
options: {}
Expand Down
1 change: 1 addition & 0 deletions packages/core/resolve-query/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const modelTypes = {
export const errors = {
duplicateName: 'A read/view name is not unique',
modelNotFound: 'A read/view model is not defined',
missingAdapter: 'Read model adapter not found',
disposed: 'A query is disposed'
}
15 changes: 13 additions & 2 deletions packages/core/resolve-query/src/query/create-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const createQuery = (
getDeserializer,
dispose,
getExecutors,
{ eventStore, viewModels, readModels, snapshotAdapter }
{
eventStore,
viewModels,
readModels,
snapshotAdapter,
readModelAdaptersCreators
}
) => {
const repository = {
executors: new Map(),
Expand All @@ -26,7 +32,12 @@ const createQuery = (
getExecutor
}

initReadModels({ ...repository, eventStore, readModels, snapshotAdapter })
initReadModels({
...repository,
eventStore,
readModels,
readModelAdaptersCreators
})
initViewModels({ ...repository, eventStore, viewModels, snapshotAdapter })
checkInitErrors(repository)

Expand Down
16 changes: 15 additions & 1 deletion packages/core/resolve-query/src/query/init-read-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ const initReadModels = ({
executorTypes,
errorMessages,
eventStore,
readModelAdaptersCreators,
readModels
}) => {
for (const readModel of readModels) {
if (executors.has(readModel.name)) {
errorMessages.push(`${errors.duplicateName} ${readModel}`)
}

const adapterCreator = readModelAdaptersCreators.find(
({ name }) => name === readModel.adapterName
)
if (adapterCreator == null) {
throw new Error(
`${errors.missingAdapter} ${readModel.name}: ${readModel.adapterName}`
)
}

const adapter = adapterCreator.factory({
metaName: `__ResolveMeta__${readModel.name}`
})

const executor = createReadModel({
projection: readModel.projection,
resolvers: readModel.resolvers,
adapter: readModel.adapter(),
adapter,
eventStore
})

Expand Down
5 changes: 3 additions & 2 deletions packages/core/resolve-runtime/src/cloud_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import mainHandler from './handlers/main_handler'
const initResolve = async (
{
snapshotAdapter: createSnapshotAdapter,
storageAdapter: createStorageAdapter
storageAdapter: createStorageAdapter,
readModelAdapters: readModelAdaptersCreators
},
resolve
) => {
const storageAdapter = createStorageAdapter()
const eventStore = createEventStore({ storage: storageAdapter })
const { aggregates, readModels, viewModels } = resolve

const snapshotAdapter = createSnapshotAdapter()

const executeCommand = createCommandExecutor({
Expand All @@ -35,6 +35,7 @@ const initResolve = async (
eventStore,
viewModels,
readModels,
readModelAdaptersCreators,
snapshotAdapter
})

Expand Down
Loading

0 comments on commit a54b03c

Please sign in to comment.