Skip to content

Commit e5c28aa

Browse files
authored
Merge pull request #43 from dolittle/projections-api
Projections api
2 parents 0613d4f + 94b33e4 commit e5c28aa

140 files changed

Lines changed: 2036 additions & 284 deletions

File tree

Some content is hidden

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

Samples/Advanced/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"build": "tsc -p ./tsconfig.json"
1212
},
1313
"dependencies": {
14-
"@dolittle/sdk": "13.0.0",
15-
"@dolittle/sdk.artifacts": "13.0.0",
16-
"@dolittle/sdk.events": "13.0.0",
17-
"@dolittle/sdk.events.handling": "13.0.0"
14+
"@dolittle/sdk": "14.2.0",
15+
"@dolittle/sdk.artifacts": "14.2.0",
16+
"@dolittle/sdk.events": "14.2.0",
17+
"@dolittle/sdk.events.handling": "14.2.0"
1818
},
1919
"devDependencies": {
2020
"nodemon": "^2.0.4",

Samples/Tutorials/Aggregates/Kitchen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DishPrepared } from './DishPrepared';
88

99
@aggregateRoot('e5b17be9-4873-4526-99a1-76a5c31c0dad')
1010
export class Kitchen extends AggregateRoot {
11-
private _counter: number = 0;
11+
private _counter = 0;
1212

1313
constructor(eventSourceId: EventSourceId) {
1414
super(eventSourceId);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
10+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
export class Chef {
6+
constructor(
7+
public name: string = '',
8+
public dishes: string[] = []
9+
) { }
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
import { eventType } from '@dolittle/sdk.events';
6+
7+
@eventType('b3a31696-4cfd-4225-8b7e-72d1c02d93d5')
8+
export class ChefFired {
9+
constructor(readonly Chef: string) {}
10+
}
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
import { Chef } from './Chef';
6+
7+
export class Chefs {
8+
constructor(
9+
public chefArray: Chef[] = []
10+
) {}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
import { eventType } from '@dolittle/sdk.events';
6+
7+
@eventType('1844473f-d714-4327-8b7f-5b3c2bdfc26a')
8+
export class DishPrepared {
9+
constructor(readonly Dish: string, readonly Chef: string) {}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
import { EventContext } from '@dolittle/sdk.events';
6+
import { on, projection } from '@dolittle/sdk.projections';
7+
import { DishPrepared } from './DishPrepared';
8+
9+
@projection('5b22e60e-f8db-494e-af5c-e8728acb2470')
10+
export class Menu {
11+
dishes: string[] = [];
12+
13+
@on(DishPrepared, _ => _.keyFromEventSource())
14+
on(event: DishPrepared, ctx: EventContext) {
15+
if (!this.dishes.includes(event.Dish)) {
16+
this.dishes.push(event.Dish);
17+
}
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
describe('when nothing', () => {
5+
it('should be fine', () => true.should.be.true);
6+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/
4+
5+
import { Client } from '@dolittle/sdk';
6+
import { TenantId } from '@dolittle/sdk.execution';
7+
import { projection, ProjectionResult } from '@dolittle/sdk.projections';
8+
import { Menu } from './Menu';
9+
import { Chef } from './Chef';
10+
import { ChefFired } from './ChefFired';
11+
import { DishPrepared } from './DishPrepared';
12+
13+
const client = Client
14+
.forMicroservice('f39b1f61-d360-4675-b859-53c05c87c0e6')
15+
.withEventTypes(eventTypes => {
16+
eventTypes.register(DishPrepared);
17+
eventTypes.register(ChefFired);
18+
})
19+
.withProjections(projections => {
20+
// projections.createProjection('4a4c5b13-d4dd-4665-a9df-27b8e9b2054c')
21+
// .forReadModel(Chef)
22+
// .on(DishPrepared, _ => _.keyFromProperty('Chef'), (chef, event, ctx) => {
23+
// console.log(`Handling event ${JSON.stringify(event)} and read model ${JSON.stringify(chef)}`);
24+
// chef.name = event.Chef;
25+
// chef.dishes.push(event.Dish);
26+
// return chef;
27+
// });
28+
// .on(ChefFired, _ => _.keyFromProperty('Chef'), (chef, event, ctx) => {
29+
// console.log(`Firing ${chef.name}`);
30+
// return ProjectionResult.delete;
31+
// });
32+
projections.register(Menu);
33+
})
34+
.build();
35+
36+
const beanBlaster = new DishPrepared('Bean Blaster Taco', 'Mr. Taco');
37+
const avocadoArtillery = new DishPrepared('Avocado Artillery Tortilla', 'Mr. Taco');
38+
const chiliCannon = new DishPrepared('Chili Cannon Wrap', 'Ms. TexMex');
39+
const mrTacoFired = new ChefFired('Mr. Taco');
40+
41+
console.log('starting comit');
42+
client.eventStore
43+
.forTenant(TenantId.development)
44+
.commit(beanBlaster, 'bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9');
45+
client.eventStore
46+
.forTenant(TenantId.development)
47+
.commit(avocadoArtillery, 'bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9');
48+
client.eventStore
49+
.forTenant(TenantId.development)
50+
.commit(chiliCannon, 'bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9');
51+
52+
client.eventStore
53+
.forTenant(TenantId.development)
54+
.commit(mrTacoFired, 'bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9');
55+
console.log('done comitng');

0 commit comments

Comments
 (0)