Skip to content

Commit bef742a

Browse files
ThomasAribartThomas Aribart
authored andcommitted
Merge pull request #163 from castore-dev/return-initialEventTimestamp-in-listAggregateIds-method
feature: return initialEventTimestamp in listAggregateIds method
2 parents 662d40b + 43e51eb commit bef742a

28 files changed

Lines changed: 335 additions & 147 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Install Node Dependencies
2+
description: Install dependencies using yarn
3+
inputs:
4+
typescript-version:
5+
description: TS version to use
6+
default: 'default'
7+
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Use Node.js
12+
uses: actions/setup-node@v3
13+
with:
14+
node-version: ${{ env.NODE_VERSION }}
15+
16+
- name: Get yarn cache directory path
17+
id: yarn-cache-dir-path
18+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
19+
shell: bash
20+
21+
- name: Sync yarn cache
22+
uses: actions/cache@v3
23+
with:
24+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
25+
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-yarn-
28+
29+
- name: Sync node_modules cache
30+
id: sync-node-modules-cache
31+
uses: actions/cache@v3
32+
with:
33+
path: '**/node_modules'
34+
key: ${{ runner.os }}-modules-${{ inputs.typescript-version }}-${{ hashFiles('./yarn.lock') }}
35+
36+
- name: Install node_modules
37+
run: if [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn install --immutable; fi
38+
shell: bash
39+
40+
- name: Override TS with specified version
41+
run: if [ '${{ inputs.typescript-version }}' != 'default' ] && [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn add --dev typescript@${{ inputs.typescript-version }}; fi
42+
shell: bash
43+
44+
- name: Sync packages cache
45+
id: sync-packages-cache
46+
uses: actions/cache@v3
47+
with:
48+
path: |
49+
node_modules/@castore/**/dist
50+
key: ts-${{ inputs.typescript-version }}-${{ hashFiles('./packages/**') }}-${{ hashFiles('./demo/**') }}
51+
52+
- name: Package
53+
run: if [ '${{ steps.sync-packages-cache.outputs.cache-hit }}' != 'true' ]; then yarn package; fi
54+
shell: bash

.github/workflows/draft-or-update-next-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
env:
1010
CI: true
11-
NODE_VERSION: 16
11+
NODE_VERSION: 18
1212

1313
jobs:
1414
prepare-deployment:

.github/workflows/label-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
env:
1212
CI: true
13-
NODE_VERSION: 16
13+
NODE_VERSION: 18
1414

1515
defaults:
1616
run:

.github/workflows/test-pr.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
env:
1212
CI: true
13-
NODE_VERSION: 16
13+
NODE_VERSION: 18
1414

1515
defaults:
1616
run:
@@ -21,6 +21,24 @@ jobs:
2121
name: 🏗 Build Project
2222
runs-on: ubuntu-latest
2323
timeout-minutes: 30
24+
strategy:
25+
matrix:
26+
typescript-version:
27+
['default', '~4.6.4', '~4.7.4', '~4.8.3', '~4.9.5', '~5.0.4']
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
33+
- name: Install node_modules & package
34+
uses: ./.github/actions/install-node-modules-and-package
35+
with:
36+
typescript-version: ${{ matrix.typescript-version }}
37+
38+
get-affected-packages:
39+
name: 🔎 Get affected packages
40+
runs-on: ubuntu-latest
41+
timeout-minutes: 30
2442
outputs:
2543
affected-packages: ${{ steps.get-affected-packages-paths.outputs.affected-packages }}
2644
steps:
@@ -30,36 +48,34 @@ jobs:
3048
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
3149
fetch-depth: 0
3250

33-
- name: Install node_modules
34-
uses: ./.github/actions/install-node-modules
35-
36-
- name: Package
37-
uses: ./.github/actions/package
38-
3951
- name: Get affected packages paths
4052
id: get-affected-packages-paths
4153
uses: ./.github/actions/get-affected-packages-paths
4254
with:
4355
base-branch: ${{ github.base_ref }}
4456

4557
library-lint-and-tests:
46-
name: 🎯 Run Tests
47-
needs: build
58+
name: 🎯 Run tests
59+
needs: [build, get-affected-packages]
4860
runs-on: ubuntu-latest
49-
if: join(fromJson(needs.build.outputs.affected-packages)) != ''
61+
if: join(fromJson(needs.get-affected-packages.outputs.affected-packages)) != ''
5062
timeout-minutes: 30
5163
strategy:
5264
fail-fast: false
5365
matrix:
54-
AFFECTED_LIB: ${{ fromJson(needs.build.outputs.affected-packages) }}
66+
affected-package: ${{ fromJson(needs.get-affected-packages.outputs.affected-packages) }}
67+
typescript-version:
68+
['default', '~4.6.4', '~4.7.4', '~4.8.3', '~4.9.5', '~5.0.4']
5569
steps:
5670
- uses: actions/checkout@v3
5771
with:
5872
ref: ${{ github.event.pull_request.head.sha }}
73+
5974
- name: Run tests
6075
uses: ./.github/actions/lint-and-tests
6176
with:
62-
path: ${{ matrix.AFFECTED_LIB }}
77+
path: ${{ matrix.affected-package }}
78+
typescript-version: ${{ matrix.typescript-version }}
6379

6480
validate-pr:
6581
name: ✅ Validate the PR
@@ -73,6 +89,7 @@ jobs:
7389
echo "build failed"
7490
exit 1
7591
fi
92+
7693
- name: Validate tests
7794
run: |
7895
if [[ ${{ needs.library-lint-and-tests.result }} = "failure" ]]; then

packages/core/src/eventStorageAdapter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export type ListAggregateIdsOptions = {
2323
};
2424

2525
export type ListAggregateIdsOutput = {
26-
aggregateIds: string[];
26+
aggregateIds: {
27+
aggregateId: string;
28+
initialEventTimestamp: string;
29+
}[];
2730
nextPageToken?: string;
2831
};
2932

packages/core/src/messaging/message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { EventDetail } from '~/event/eventDetail';
44
export type AggregateExistsMessage<EVENT_STORE_ID extends string = string> = {
55
eventStoreId: EVENT_STORE_ID;
66
aggregateId: string;
7+
initialEventTimestamp: string;
78
};
89

910
export type NotificationMessage<

packages/event-storage-adapter-dynamodb/src/legacyAdapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export class LegacyDynamoDBEventStorageAdapter implements EventStorageAdapter {
399399
}
400400

401401
const {
402-
Items: unmarshalledInitialEvents = [],
402+
Items: marshalledInitialEvents = [],
403403
LastEvaluatedKey: lastEvaluatedKey,
404404
} = await this.dynamoDBClient.send(
405405
new QueryCommand(aggregateIdsQueryCommandInput),
@@ -414,12 +414,12 @@ export class LegacyDynamoDBEventStorageAdapter implements EventStorageAdapter {
414414
};
415415

416416
return {
417-
aggregateIds: unmarshalledInitialEvents
417+
aggregateIds: marshalledInitialEvents
418418
.map(item => unmarshall(item))
419419
.map(item => {
420-
const { aggregateId } = item as Pick<EventDetail, 'aggregateId'>;
420+
const { aggregateId, timestamp } = item as EventDetail;
421421

422-
return aggregateId;
422+
return { aggregateId, initialEventTimestamp: timestamp };
423423
}),
424424
...(lastEvaluatedKey !== undefined
425425
? { nextPageToken: JSON.stringify(parsedNextPageToken) }

packages/event-storage-adapter-dynamodb/src/legacyAdapter.unit.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ describe('LegacyDynamoDBEventStorageAdapter', () => {
302302
const secondAggregateIdMock = 'my-second-aggregate-id';
303303
const queryCommandOutputMock: QueryCommandOutput = {
304304
Items: [
305-
marshall({ aggregateId }),
306-
marshall({ aggregateId: secondAggregateIdMock }),
305+
marshall({ aggregateId, timestamp: timestampA }),
306+
marshall({
307+
aggregateId: secondAggregateIdMock,
308+
timestamp: timestampB,
309+
}),
307310
],
308311
$metadata: {},
309312
};
@@ -326,7 +329,13 @@ describe('LegacyDynamoDBEventStorageAdapter', () => {
326329
});
327330

328331
// We have to serialize / deserialize because DynamoDB numbers are not regular numbers
329-
expect(aggregateIds).toMatchObject([aggregateId, secondAggregateIdMock]);
332+
expect(aggregateIds).toMatchObject([
333+
{ aggregateId, initialEventTimestamp: timestampA },
334+
{
335+
aggregateId: secondAggregateIdMock,
336+
initialEventTimestamp: timestampB,
337+
},
338+
]);
330339
});
331340

332341
it('adds limit option', async () => {

packages/event-storage-adapter-dynamodb/src/singleTableAdapter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class DynamoDBSingleTableEventStorageAdapter
414414
}
415415

416416
const {
417-
Items: unmarshalledInitialEvents = [],
417+
Items: marshalledInitialEvents = [],
418418
LastEvaluatedKey: lastEvaluatedKey,
419419
} = await this.dynamoDBClient.send(
420420
new QueryCommand(aggregateIdsQueryCommandInput),
@@ -429,12 +429,15 @@ export class DynamoDBSingleTableEventStorageAdapter
429429
};
430430

431431
return {
432-
aggregateIds: unmarshalledInitialEvents
432+
aggregateIds: marshalledInitialEvents
433433
.map(item => unmarshall(item))
434434
.map(item => {
435-
const { aggregateId } = item as Pick<EventDetail, 'aggregateId'>;
435+
const { aggregateId, timestamp } = item as EventDetail;
436436

437-
return unprefixAggregateId(eventStoreId, aggregateId);
437+
return {
438+
aggregateId: unprefixAggregateId(eventStoreId, aggregateId),
439+
initialEventTimestamp: timestamp,
440+
};
438441
}),
439442
...(lastEvaluatedKey !== undefined
440443
? { nextPageToken: JSON.stringify(parsedNextPageToken) }

packages/event-storage-adapter-dynamodb/src/singleTableAdapter.unit.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ describe('DynamoDBEventStorageAdapter', () => {
294294
const secondAggregateIdMock = 'my-second-aggregate-id';
295295
const queryCommandOutputMock: QueryCommandOutput = {
296296
Items: [
297-
marshall({ aggregateId: prefixedAggregateId }),
297+
marshall({ aggregateId: prefixedAggregateId, timestamp: timestampA }),
298298
marshall({
299299
aggregateId: prefixAggregateId(eventStoreId, secondAggregateIdMock),
300+
timestamp: timestampB,
300301
}),
301302
],
302303
$metadata: {},
@@ -323,7 +324,13 @@ describe('DynamoDBEventStorageAdapter', () => {
323324
});
324325

325326
// We have to serialize / deserialize because DynamoDB numbers are not regular numbers
326-
expect(aggregateIds).toMatchObject([aggregateId, secondAggregateIdMock]);
327+
expect(aggregateIds).toMatchObject([
328+
{ aggregateId, initialEventTimestamp: timestampA },
329+
{
330+
aggregateId: secondAggregateIdMock,
331+
initialEventTimestamp: timestampB,
332+
},
333+
]);
327334
});
328335

329336
it('adds limit option', async () => {

0 commit comments

Comments
 (0)