Skip to content

Commit 4a2e48c

Browse files
authored
Merge pull request #114 from dolittle/22.2.0-sam
Sam: Projection read model copies to MongoDB
2 parents 3d78d77 + 6e18b63 commit 4a2e48c

File tree

77 files changed

+1612
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1612
-202
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
'@typescript-eslint/unified-signatures': 'off',
1414
'import/no-extraneous-dependencies': 'off',
1515
'eol-last': 'error',
16-
'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0 }],
16+
'no-multiple-empty-lines': ['error', {'max': 1, 'maxEOF': 0 }],
1717
'header/header': [
1818
2,
1919
'line',
@@ -61,7 +61,7 @@ module.exports = {
6161
'MethodDefinition[accessibility!="private"][value.type="FunctionExpression"]:not(MethodDefinition[value.type="TSEmptyBodyFunctionExpression"] + MethodDefinition[value.type="FunctionExpression"])',
6262
]
6363
}],
64-
64+
6565
'jsdoc/require-returns': ['error', {
6666
'contexts': [
6767
'ArrowFunctionExpression',

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: TypeScript Library CI/CD
22

33
env:
4-
PRERELEASE_BRANCHES: legolas, gimli # Comma separated list of prerelease branch names. 'alpha,rc, ...'
4+
PRERELEASE_BRANCHES: legolas, gimli, sam # Comma separated list of prerelease branch names. 'alpha,rc, ...'
55

66
on:
77
push:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ Samples/**/data
6565
Source/**/Distribution
6666
Samples/**/Distribution
6767
Source/**/README.md
68+
69+
.idea

Samples/Container/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "container",
33
"private": true,
4-
"version": "22.1.0",
4+
"version": "22.2.0-sam.5",
55
"main": "index.js",
66
"author": "Dolittle",
77
"license": "MIT",
@@ -12,10 +12,10 @@
1212
"build": "tsc -p ./tsconfig.json"
1313
},
1414
"dependencies": {
15-
"@dolittle/sdk": "22.1.0",
16-
"@dolittle/sdk.artifacts": "22.1.0",
17-
"@dolittle/sdk.events": "22.1.0",
18-
"@dolittle/sdk.events.handling": "22.1.0",
15+
"@dolittle/sdk": "22.2.0-sam.5",
16+
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
17+
"@dolittle/sdk.events": "22.2.0-sam.5",
18+
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
1919
"inversify": "^6.0.1",
2020
"reflect-metadata": "^0.1.13",
2121
"winston": "^3.3.4"

Samples/ExpressJS/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "expressjs",
33
"private": true,
4-
"version": "22.1.0",
4+
"version": "22.2.0-sam.5",
55
"main": "index.js",
66
"author": "Dolittle",
77
"license": "MIT",
@@ -12,11 +12,11 @@
1212
"build": "tsc -b ./tsconfig.json"
1313
},
1414
"dependencies": {
15-
"@dolittle/sdk": "22.1.0",
16-
"@dolittle/sdk.artifacts": "22.1.0",
17-
"@dolittle/sdk.events": "22.1.0",
18-
"@dolittle/sdk.events.handling": "22.1.0",
19-
"@dolittle/sdk.extensions.express": "22.1.0",
15+
"@dolittle/sdk": "22.2.0-sam.5",
16+
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
17+
"@dolittle/sdk.events": "22.2.0-sam.5",
18+
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
19+
"@dolittle/sdk.extensions.express": "22.2.0-sam.5",
2020
"body-parser": "^1.19.1",
2121
"express": "^4.17.2",
2222
"winston": "^3.4.0"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
module.exports = {
5+
extends: '../../.eslintrc.js',
6+
rules: {
7+
'no-restricted-globals': 'off',
8+
'@typescript-eslint/naming-convention' : 'off',
9+
'jsdoc/require-jsdoc': 'off',
10+
}
11+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import { convertToMongoDB, copyProjectionToMongoDB, on, projection, MongoDBConversion, ProjectionContext } from '@dolittle/sdk.projections';
5+
6+
import { DishPrepared } from './DishPrepared';
7+
8+
@projection('98f9db66-b6ca-4e5f-9fc3-638626c9ecfa')
9+
@copyProjectionToMongoDB()
10+
export class DishCounter {
11+
12+
name: string = 'Unknown';
13+
14+
numberOfTimesPrepared: number = 0;
15+
16+
@convertToMongoDB(MongoDBConversion.Date)
17+
lastPrepared: Date = new Date(0);
18+
19+
@on(DishPrepared, _ => _.keyFromProperty('Dish'))
20+
on(event: DishPrepared, projectionContext: ProjectionContext) {
21+
this.name = event.Dish;
22+
this.numberOfTimesPrepared ++;
23+
this.lastPrepared = projectionContext.eventContext.occurred.toJSDate();
24+
}
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import { eventType } from '@dolittle/sdk.events';
5+
6+
@eventType('1844473f-d714-4327-8b7f-5b3c2bdfc26a')
7+
export class DishPrepared {
8+
constructor(readonly Dish: string, readonly Chef: string) {}
9+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
// Sample code for the tutorial at https://dolittle.io/docs/tutorials/projections/
5+
6+
import { DolittleClient } from '@dolittle/sdk';
7+
import { TenantId } from '@dolittle/sdk.execution';
8+
import { setTimeout } from 'timers/promises';
9+
import { DateTime } from 'luxon';
10+
11+
import { DishCounter } from './DishCounter';
12+
import { DishPrepared } from './DishPrepared';
13+
14+
(async () => {
15+
const client = await DolittleClient
16+
.setup()
17+
.connect();
18+
19+
const eventStore = client.eventStore.forTenant(TenantId.development);
20+
21+
await eventStore.commit(new DishPrepared('Bean Blaster Taco', 'Mr. Taco'), 'Dolittle Tacos');
22+
await eventStore.commit(new DishPrepared('Bean Blaster Taco', 'Mrs. Tex Mex'), 'Dolittle Tacos');
23+
await eventStore.commit(new DishPrepared('Avocado Artillery Tortilla', 'Mr. Taco'), 'Dolittle Tacos');
24+
await eventStore.commit(new DishPrepared('Chili Canon Wrap', 'Mrs. Tex Mex'), 'Dolittle Tacos');
25+
26+
await setTimeout(1000);
27+
28+
const db = await client.resources.forTenant(TenantId.development).mongoDB.getDatabase();
29+
const dishCounterCollection = db.collection(DishCounter);
30+
31+
for (const { name, numberOfTimesPrepared, lastPrepared } of await dishCounterCollection.find().toArray()) {
32+
client.logger.info(`The kitchen has prepared ${name} ${numberOfTimesPrepared} times. The last time was ${lastPrepared}`);
33+
}
34+
35+
const dishesPreparedToday = await dishCounterCollection.find({ lastPrepared: { $gte: DateTime.utc().startOf('day').toJSDate(), $lte: DateTime.utc().endOf('day').toJSDate() }}).toArray();
36+
for (const { name } of await dishCounterCollection.find().toArray()) {
37+
client.logger.info(`The kitchen has prepared ${name} today`);
38+
}
39+
})();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "mongodb-projections",
3+
"private": true,
4+
"version": "22.2.0-sam.5",
5+
"main": "index.js",
6+
"author": "Dolittle",
7+
"license": "MIT",
8+
"scripts": {
9+
"watch": "nodemon --watch **/*.ts --exec 'ts-node' index.ts",
10+
"start": "ts-node index.ts",
11+
"test": "mocha",
12+
"build": "tsc -p ./tsconfig.json"
13+
},
14+
"dependencies": {
15+
"@dolittle/sdk": "22.2.0-sam.5",
16+
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
17+
"@dolittle/sdk.events": "22.2.0-sam.5",
18+
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
19+
"inversify": "^6.0.1",
20+
"reflect-metadata": "^0.1.13",
21+
"winston": "^3.3.4"
22+
},
23+
"devDependencies": {
24+
"nodemon": "^2.0.4",
25+
"ts-node": "^8.10.1"
26+
}
27+
}

0 commit comments

Comments
 (0)