Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam: Projection read model copies to MongoDB #114

Merged
merged 47 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5e7af65
Create Sam prerelease
jakhog Feb 1, 2022
c78ff4b
Fix an import
jakhog Feb 1, 2022
d092edd
Make concepts and builder API
jakhog Feb 1, 2022
f315493
Upgrade to prerelease contracts
jakhog Feb 1, 2022
85fea19
Implement sending the copies in the Projection arguments.
jakhog Feb 1, 2022
259ceb9
Provide defaults for no copies.
jakhog Feb 1, 2022
a038110
Implement the builder for creating MongoDB copies
jakhog Feb 1, 2022
705c811
Use builder api in Projection sample for testing.
jakhog Feb 1, 2022
90effc8
Fix import
jakhog Feb 1, 2022
51526d5
There are no default conversions for JS, so these make no sense.
jakhog Feb 1, 2022
353f8d3
Change builder API method names, and don't register a projection with…
jakhog Feb 1, 2022
560f69a
Merge pull request #115 from dolittle/builder-api
jakhog Feb 1, 2022
579a7e7
"Update packages and workspace dependencies to 22.2.0-sam.0"
github-actions[bot] Feb 1, 2022
0339808
Move things to Copies in Builders
jakhog Feb 1, 2022
dbe1844
Implement the copyProjectionToMongoDB decorator
jakhog Feb 1, 2022
1950ab8
Implement property conversion
jakhog Feb 1, 2022
295e692
Test with Projection sample
jakhog Feb 1, 2022
e3ef286
Merge pull request #116 from dolittle/copy-decorators
woksin Feb 2, 2022
8ed7d26
"Update packages and workspace dependencies to 22.2.0-sam.1"
github-actions[bot] Feb 2, 2022
a83c85b
Add overload to get collection from type to MongoDB Db class.
jakhog Feb 3, 2022
ce1a1f8
Call the function properly so this is passed along.
jakhog Feb 3, 2022
69d750f
Merge pull request #117 from dolittle/extend-mongodb-db
jakhog Feb 3, 2022
b2b9c08
"Update packages and workspace dependencies to 22.2.0-sam.2"
github-actions[bot] Feb 3, 2022
950f8f9
Update contracts
jakhog Feb 4, 2022
3756b08
Implement new registration arguments structure.
jakhog Feb 4, 2022
c06805e
Fix decorators
jakhog Feb 4, 2022
6d9d4e5
Fix explicit builder
jakhog Feb 4, 2022
c3ab6f7
Fix class builder
jakhog Feb 4, 2022
d159e4f
Fix sample
jakhog Feb 4, 2022
cfff501
Merge pull request #118 from dolittle/new-contracts-structure
woksin Feb 7, 2022
4e5e303
"Update packages and workspace dependencies to 22.2.0-sam.3"
github-actions[bot] Feb 7, 2022
d05bb43
Add validation for collection names
jakhog Feb 8, 2022
ab87bfb
Validate collection names
jakhog Feb 8, 2022
ec4b053
Upgrade contracts
jakhog Feb 8, 2022
a2df752
Add newly introduced conversion types
jakhog Feb 8, 2022
53640cd
Add some specs for ProjectionClassBuilder copy to MongoDB decorators
jakhog Feb 8, 2022
839f6e4
Remove a NBSP
jakhog Feb 8, 2022
e862f96
Add specs for ProjectionBuilderForReadModel for MongoDB copies
jakhog Feb 8, 2022
298d700
Ignore .idea files
jakhog Feb 8, 2022
68410e8
Merge pull request #119 from dolittle/validate-collection-name
woksin Feb 9, 2022
edb6138
"Update packages and workspace dependencies to 22.2.0-sam.4"
github-actions[bot] Feb 9, 2022
e25e533
Upgrade contracts
jakhog Feb 9, 2022
85d9d4b
Reset Projections tutorial
jakhog Feb 9, 2022
ad27172
Add MongoDBProjections sample
jakhog Feb 9, 2022
8058a1c
Ignore property name rule for new sample
jakhog Feb 9, 2022
b18ec56
Merge pull request #120 from dolittle/fix-samples
jakhog Feb 9, 2022
6e18b63
"Update packages and workspace dependencies to 22.2.0-sam.5"
github-actions[bot] Feb 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
'@typescript-eslint/unified-signatures': 'off',
'import/no-extraneous-dependencies': 'off',
'eol-last': 'error',
'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0 }],
'no-multiple-empty-lines': ['error', {'max': 1, 'maxEOF': 0 }],
'header/header': [
2,
'line',
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = {
'MethodDefinition[accessibility!="private"][value.type="FunctionExpression"]:not(MethodDefinition[value.type="TSEmptyBodyFunctionExpression"] + MethodDefinition[value.type="FunctionExpression"])',
]
}],

'jsdoc/require-returns': ['error', {
'contexts': [
'ArrowFunctionExpression',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: TypeScript Library CI/CD

env:
PRERELEASE_BRANCHES: legolas, gimli # Comma separated list of prerelease branch names. 'alpha,rc, ...'
PRERELEASE_BRANCHES: legolas, gimli, sam # Comma separated list of prerelease branch names. 'alpha,rc, ...'

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ Samples/**/data
Source/**/Distribution
Samples/**/Distribution
Source/**/README.md

.idea
10 changes: 5 additions & 5 deletions Samples/Container/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "container",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,10 +12,10 @@
"build": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0",
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
"inversify": "^6.0.1",
"reflect-metadata": "^0.1.13",
"winston": "^3.3.4"
Expand Down
12 changes: 6 additions & 6 deletions Samples/ExpressJS/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "expressjs",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,11 +12,11 @@
"build": "tsc -b ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0",
"@dolittle/sdk.extensions.express": "22.1.0",
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
"@dolittle/sdk.extensions.express": "22.2.0-sam.5",
"body-parser": "^1.19.1",
"express": "^4.17.2",
"winston": "^3.4.0"
Expand Down
11 changes: 11 additions & 0 deletions Samples/MongoDBProjections/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

module.exports = {
extends: '../../.eslintrc.js',
rules: {
'no-restricted-globals': 'off',
'@typescript-eslint/naming-convention' : 'off',
'jsdoc/require-jsdoc': 'off',
}
};
25 changes: 25 additions & 0 deletions Samples/MongoDBProjections/DishCounter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import { convertToMongoDB, copyProjectionToMongoDB, on, projection, MongoDBConversion, ProjectionContext } from '@dolittle/sdk.projections';

import { DishPrepared } from './DishPrepared';

@projection('98f9db66-b6ca-4e5f-9fc3-638626c9ecfa')
@copyProjectionToMongoDB()
export class DishCounter {

name: string = 'Unknown';

numberOfTimesPrepared: number = 0;

@convertToMongoDB(MongoDBConversion.Date)
lastPrepared: Date = new Date(0);

@on(DishPrepared, _ => _.keyFromProperty('Dish'))
on(event: DishPrepared, projectionContext: ProjectionContext) {
this.name = event.Dish;
this.numberOfTimesPrepared ++;
this.lastPrepared = projectionContext.eventContext.occurred.toJSDate();
}
}
9 changes: 9 additions & 0 deletions Samples/MongoDBProjections/DishPrepared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import { eventType } from '@dolittle/sdk.events';

@eventType('1844473f-d714-4327-8b7f-5b3c2bdfc26a')
export class DishPrepared {
constructor(readonly Dish: string, readonly Chef: string) {}
}
39 changes: 39 additions & 0 deletions Samples/MongoDBProjections/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// Sample code for the tutorial at https://dolittle.io/docs/tutorials/projections/

import { DolittleClient } from '@dolittle/sdk';
import { TenantId } from '@dolittle/sdk.execution';
import { setTimeout } from 'timers/promises';
import { DateTime } from 'luxon';

import { DishCounter } from './DishCounter';
import { DishPrepared } from './DishPrepared';

(async () => {
const client = await DolittleClient
.setup()
.connect();

const eventStore = client.eventStore.forTenant(TenantId.development);

await eventStore.commit(new DishPrepared('Bean Blaster Taco', 'Mr. Taco'), 'Dolittle Tacos');
await eventStore.commit(new DishPrepared('Bean Blaster Taco', 'Mrs. Tex Mex'), 'Dolittle Tacos');
await eventStore.commit(new DishPrepared('Avocado Artillery Tortilla', 'Mr. Taco'), 'Dolittle Tacos');
await eventStore.commit(new DishPrepared('Chili Canon Wrap', 'Mrs. Tex Mex'), 'Dolittle Tacos');

await setTimeout(1000);

const db = await client.resources.forTenant(TenantId.development).mongoDB.getDatabase();
const dishCounterCollection = db.collection(DishCounter);

for (const { name, numberOfTimesPrepared, lastPrepared } of await dishCounterCollection.find().toArray()) {
client.logger.info(`The kitchen has prepared ${name} ${numberOfTimesPrepared} times. The last time was ${lastPrepared}`);
}

const dishesPreparedToday = await dishCounterCollection.find({ lastPrepared: { $gte: DateTime.utc().startOf('day').toJSDate(), $lte: DateTime.utc().endOf('day').toJSDate() }}).toArray();
for (const { name } of await dishCounterCollection.find().toArray()) {
client.logger.info(`The kitchen has prepared ${name} today`);
}
})();
27 changes: 27 additions & 0 deletions Samples/MongoDBProjections/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "mongodb-projections",
"private": true,
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
"scripts": {
"watch": "nodemon --watch **/*.ts --exec 'ts-node' index.ts",
"start": "ts-node index.ts",
"test": "mocha",
"build": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
"inversify": "^6.0.1",
"reflect-metadata": "^0.1.13",
"winston": "^3.3.4"
},
"devDependencies": {
"nodemon": "^2.0.4",
"ts-node": "^8.10.1"
}
}
16 changes: 16 additions & 0 deletions Samples/MongoDBProjections/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"sourceRoot": "../",
"inlineSourceMap": true,
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "Distribution"
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "Distribution"],
"references": [
{ "path": "../../Source/sdk" }
]
}
12 changes: 6 additions & 6 deletions Samples/Tutorials/Aggregates/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "samples.aggregates",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,11 +12,11 @@
"build": "tsc -b ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.aggregates": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0"
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.aggregates": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5"
},
"devDependencies": {
"nodemon": "^2.0.4",
Expand Down
10 changes: 5 additions & 5 deletions Samples/Tutorials/Embeddings/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "embeddings",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,10 +12,10 @@
"build": "tsc -b ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0"
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5"
},
"devDependencies": {
"nodemon": "^2.0.4",
Expand Down
12 changes: 6 additions & 6 deletions Samples/Tutorials/EventHorizon/Consumer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eventhorizon-consumer",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,11 +12,11 @@
"build": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.eventhorizon": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0"
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.eventhorizon": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5"
},
"devDependencies": {
"nodemon": "^2.0.4",
Expand Down
12 changes: 6 additions & 6 deletions Samples/Tutorials/EventHorizon/Producer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eventhorizon-producer",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,11 +12,11 @@
"build": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.eventhorizon": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0"
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.eventhorizon": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5"
},
"devDependencies": {
"nodemon": "^2.0.4",
Expand Down
10 changes: 5 additions & 5 deletions Samples/Tutorials/GettingStarted/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kitchen",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,10 +12,10 @@
"build": "tsc -b ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0",
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5",
"winston": "3.3.2"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions Samples/Tutorials/Projections/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "projections",
"private": true,
"version": "22.1.0",
"version": "22.2.0-sam.5",
"main": "index.js",
"author": "Dolittle",
"license": "MIT",
Expand All @@ -12,10 +12,10 @@
"build": "tsc -b ./tsconfig.json"
},
"dependencies": {
"@dolittle/sdk": "22.1.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.events.handling": "22.1.0"
"@dolittle/sdk": "22.2.0-sam.5",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.events.handling": "22.2.0-sam.5"
},
"devDependencies": {
"nodemon": "^2.0.4",
Expand Down
14 changes: 7 additions & 7 deletions Source/aggregates/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dolittle/sdk.aggregates",
"version": "22.1.0",
"version": "22.2.0-sam.5",
"description": "Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.",
"keywords": [
"Dolittle",
Expand Down Expand Up @@ -46,12 +46,12 @@
"dependencies": {
"@dolittle/concepts": "6.0.0",
"@dolittle/rudiments": "6.0.0",
"@dolittle/sdk.artifacts": "22.1.0",
"@dolittle/sdk.events": "22.1.0",
"@dolittle/sdk.execution": "22.1.0",
"@dolittle/sdk.protobuf": "22.1.0",
"@dolittle/sdk.resilience": "22.1.0",
"@dolittle/sdk.services": "22.1.0",
"@dolittle/sdk.artifacts": "22.2.0-sam.5",
"@dolittle/sdk.events": "22.2.0-sam.5",
"@dolittle/sdk.execution": "22.2.0-sam.5",
"@dolittle/sdk.protobuf": "22.2.0-sam.5",
"@dolittle/sdk.resilience": "22.2.0-sam.5",
"@dolittle/sdk.services": "22.2.0-sam.5",
"@dolittle/types": "6.0.0",
"winston": "3.3.2"
},
Expand Down
Loading