Skip to content

Commit 18a3a71

Browse files
authored
Merge pull request #142 from castore-dev/create-http-event-storage-adapter
feature: add HTTP event storage adapter
2 parents 80d0bba + 44acacc commit 18a3a71

34 files changed

Lines changed: 1702 additions & 56 deletions

.github/workflows/release-to-npm.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
with:
4343
token: ${{ secrets.NPM_TOKEN }}
4444
package: ./packages/event-storage-adapter-redux/package.json
45+
- uses: JS-DevTools/npm-publish@v2
46+
with:
47+
token: ${{ secrets.NPM_TOKEN }}
48+
package: ./packages/event-storage-adapter-http/package.json
4549
- uses: JS-DevTools/npm-publish@v2
4650
with:
4751
token: ${{ secrets.NPM_TOKEN }}

castore.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
"path": "packages/event-storage-adapter-dynamodb",
4242
"name": "🔌 DynamoDB"
4343
},
44+
{
45+
"path": "packages/event-storage-adapter-http",
46+
"name": "🔌 HTTP"
47+
},
4448
{
4549
"path": "packages/event-storage-adapter-redux",
4650
"name": "🔌 Redux"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { EventDetail } from '@castore/core';
2+
3+
import { pokemonsEventStore } from '~/libs/eventStores/pokemons';
4+
import { applyConsoleMiddleware } from '~/libs/middlewares/console';
5+
6+
import { Input, inputSchema } from './schema';
7+
8+
export const getPokemonEvents = async (
9+
event: Input,
10+
): Promise<{ events: EventDetail[] }> => {
11+
const {
12+
queryStringParameters: { aggregateId },
13+
} = event;
14+
15+
return pokemonsEventStore.getEvents(aggregateId);
16+
};
17+
18+
export const main = applyConsoleMiddleware(getPokemonEvents, { inputSchema });
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { AWS } from '@serverless/typescript';
2+
3+
export const getPokemonEvents: Exclude<AWS['functions'], undefined>[string] = {
4+
handler: 'functions/getPokemonEvents/handler.main',
5+
events: [
6+
{
7+
httpApi: {
8+
method: 'GET',
9+
path: '/events',
10+
},
11+
},
12+
],
13+
};

demo/implementation/functions/logPokemonEvents/schema.ts renamed to demo/implementation/functions/getPokemonEvents/schema.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import { uuidSchema } from '~/libs/schemas/uuid';
55
export const inputSchema = {
66
type: 'object',
77
properties: {
8-
pokemonId: uuidSchema,
8+
queryStringParameters: {
9+
type: 'object',
10+
properties: {
11+
aggregateId: uuidSchema,
12+
},
13+
required: ['aggregateId'],
14+
additionalProperties: false,
15+
},
916
},
10-
required: ['pokemonId'],
11-
additionalProperties: false,
17+
required: ['queryStringParameters'],
1218
} as const;
1319

1420
export type Input = FromSchema<typeof inputSchema>;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { catchPokemon } from './catchPokemon';
2+
import { getPokemonEvents } from './getPokemonEvents';
23
import { levelUpPokemon } from './levelUpPokemon';
3-
import { logPokemonEvents } from './logPokemonEvents';
4-
import { logPokemonIds } from './logPokemonIds';
4+
import { listPokemonAggregateIds } from './listPokemonAggregateIds/';
55
import { startPokemonGame } from './startPokemonGame';
66
import { wildPokemonAppear } from './wildPokemonAppear';
77

88
export const functions = {
99
catchPokemon,
10+
getPokemonEvents,
1011
levelUpPokemon,
11-
logPokemonEvents,
12-
logPokemonIds,
12+
listPokemonAggregateIds,
1313
startPokemonGame,
1414
wildPokemonAppear,
1515
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ListAggregateIdsOutput } from '@castore/core';
2+
3+
import { pokemonsEventStore } from '~/libs/eventStores/pokemons';
4+
import { applyConsoleMiddleware } from '~/libs/middlewares/console';
5+
6+
export const listPokemonAggregateIds =
7+
async (): Promise<ListAggregateIdsOutput> => {
8+
const { aggregateIds } = await pokemonsEventStore.listAggregateIds();
9+
10+
return { aggregateIds };
11+
};
12+
13+
export const main = applyConsoleMiddleware(listPokemonAggregateIds);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { AWS } from '@serverless/typescript';
2+
3+
export const listPokemonAggregateIds: Exclude<
4+
AWS['functions'],
5+
undefined
6+
>[string] = {
7+
handler: 'functions/listPokemonAggregateIds/handler.main',
8+
events: [
9+
{
10+
httpApi: {
11+
method: 'GET',
12+
path: '/aggregateIds',
13+
},
14+
},
15+
],
16+
};

demo/implementation/functions/logPokemonEvents/handler.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

demo/implementation/functions/logPokemonEvents/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)