event-store-adapter-js 2.0.20 → 2.0.21-snapshot.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ class DefaultKeyResolver {
18
18
  if (aggregateId === undefined || aggregateId === null) {
19
19
  throw new Error(`aggregateId is undefined or null: ${aggregateId}`);
20
20
  }
21
- const hash = this.hashString(aggregateId.asString);
21
+ const hash = this.hashString(aggregateId.asString());
22
22
  const remainder = hash % shardCount;
23
23
  return `${aggregateId.typeName}-${remainder}`;
24
24
  }
@@ -47,7 +47,7 @@ class EventStoreForDynamoDB {
47
47
  "#seq_nr": "seq_nr",
48
48
  },
49
49
  ExpressionAttributeValues: {
50
- ":aid": { S: id.asString },
50
+ ":aid": { S: id.asString() },
51
51
  ":seq_nr": { N: sequenceNumber.toString() },
52
52
  },
53
53
  };
@@ -82,7 +82,7 @@ class EventStoreForDynamoDB {
82
82
  "#seq_nr": "seq_nr",
83
83
  },
84
84
  ExpressionAttributeValues: {
85
- ":aid": { S: id.asString },
85
+ ":aid": { S: id.asString() },
86
86
  ":seq_nr": { N: "0" },
87
87
  },
88
88
  Limit: 1,
@@ -122,8 +122,8 @@ class EventStoreForDynamoDB {
122
122
  persistEventAndSnapshot(event, aggregate) {
123
123
  var _a, _b;
124
124
  return __awaiter(this, void 0, void 0, function* () {
125
- if (event.aggregateId.asString !== aggregate.id.asString) {
126
- throw new Error(`aggregateId mismatch: expected ${event.aggregateId.asString}, got ${aggregate.id.asString}`);
125
+ if (event.aggregateId.asString() !== aggregate.id.asString()) {
126
+ throw new Error(`aggregateId mismatch: expected ${event.aggregateId.asString()}, got ${aggregate.id.asString()}`);
127
127
  }
128
128
  (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`persistEventAndSnapshot(${JSON.stringify(event)}, ${JSON.stringify(aggregate)}): start`);
129
129
  if (event.isCreated) {
@@ -204,7 +204,7 @@ class EventStoreForDynamoDB {
204
204
  Item: {
205
205
  pkey: { S: pkey },
206
206
  skey: { S: skey },
207
- aid: { S: event.aggregateId.asString },
207
+ aid: { S: event.aggregateId.asString() },
208
208
  seq_nr: { N: event.sequenceNumber.toString() },
209
209
  payload: { B: payload },
210
210
  occurred_at: { N: event.occurredAt.getUTCMilliseconds().toString() },
@@ -226,7 +226,7 @@ class EventStoreForDynamoDB {
226
226
  pkey: { S: pkey },
227
227
  skey: { S: skey },
228
228
  payload: { B: payload },
229
- aid: { S: event.aggregateId.asString },
229
+ aid: { S: event.aggregateId.asString() },
230
230
  seq_nr: { N: sequenceNumber.toString() },
231
231
  version: { N: "1" },
232
232
  ttl: { N: "0" },
@@ -306,7 +306,7 @@ class EventStoreForDynamoDB {
306
306
  "#aid": "aid",
307
307
  },
308
308
  ExpressionAttributeValues: {
309
- ":aid": { S: aggregateId.asString },
309
+ ":aid": { S: aggregateId.asString() },
310
310
  },
311
311
  Select: "COUNT",
312
312
  };
@@ -321,7 +321,7 @@ class EventStoreForDynamoDB {
321
321
  "#seq_nr": "seq_nr",
322
322
  };
323
323
  const values = {
324
- ":aid": { S: aggregateId.asString },
324
+ ":aid": { S: aggregateId.asString() },
325
325
  ":seq_nr": { N: "0" },
326
326
  };
327
327
  const request = {
@@ -13,10 +13,10 @@ exports.EventStoreForMemory = void 0;
13
13
  class EventStoreForMemory {
14
14
  constructor(events = new Map(), snapshots = new Map()) {
15
15
  this.events = new Map(Array.from(events).map(([key, values]) => {
16
- return [key.asString, values];
16
+ return [key.asString(), values];
17
17
  }));
18
18
  this.snapshots = new Map(Array.from(snapshots).map(([key, value]) => {
19
- return [key.asString, value];
19
+ return [key.asString(), value];
20
20
  }));
21
21
  }
22
22
  persistEvent(event, version) {
@@ -24,16 +24,16 @@ class EventStoreForMemory {
24
24
  if (event.isCreated) {
25
25
  throw new Error("event is created");
26
26
  }
27
- const aggregateIdString = event.aggregateId.asString;
27
+ const aggregateIdString = event.aggregateId.asString();
28
28
  const snapshot = this.snapshots.get(aggregateIdString);
29
29
  if (snapshot === undefined) {
30
30
  throw new Error("snapshot is undefined");
31
31
  }
32
- if (snapshot.id.asString !== event.aggregateId.asString) {
32
+ if (snapshot.id.asString() !== event.aggregateId.asString()) {
33
33
  throw new Error("aggregateId mismatch: snapshot.id = " +
34
- snapshot.id.asString +
34
+ snapshot.id.asString() +
35
35
  ", event.aggregateId = " +
36
- event.aggregateId.asString);
36
+ event.aggregateId.asString());
37
37
  }
38
38
  if (snapshot.version !== version) {
39
39
  throw new Error("version mismatch");
@@ -52,10 +52,10 @@ class EventStoreForMemory {
52
52
  persistEventAndSnapshot(event, aggregate) {
53
53
  var _a, _b;
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
- if (event.aggregateId.asString !== aggregate.id.asString) {
56
- throw new Error(`aggregateId mismatch: expected ${event.aggregateId.asString}, got ${aggregate.id.asString}`);
55
+ if (event.aggregateId.asString() !== aggregate.id.asString()) {
56
+ throw new Error(`aggregateId mismatch: expected ${event.aggregateId.asString()}, got ${aggregate.id.asString()}`);
57
57
  }
58
- const aggregateIdString = event.aggregateId.asString;
58
+ const aggregateIdString = event.aggregateId.asString();
59
59
  const events = (_a = this.events.get(aggregateIdString)) !== null && _a !== void 0 ? _a : [];
60
60
  const snapshot = (_b = this.snapshots.get(aggregateIdString)) !== null && _b !== void 0 ? _b : aggregate;
61
61
  let newVersion = 1;
@@ -74,7 +74,7 @@ class EventStoreForMemory {
74
74
  }
75
75
  getEventsByIdSinceSequenceNumber(id, sequenceNumber) {
76
76
  return __awaiter(this, void 0, void 0, function* () {
77
- const aggregateIdString = id.asString;
77
+ const aggregateIdString = id.asString();
78
78
  const events = this.events.get(aggregateIdString);
79
79
  if (events === undefined) {
80
80
  throw new Error("events is undefined");
@@ -84,7 +84,7 @@ class EventStoreForMemory {
84
84
  }
85
85
  getLatestSnapshotById(id) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
- const aggregateIdString = id.asString;
87
+ const aggregateIdString = id.asString();
88
88
  return this.snapshots.get(aggregateIdString);
89
89
  });
90
90
  }
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  interface AggregateId {
2
2
  typeName: string;
3
3
  value: string;
4
- asString: string;
4
+ asString: () => string;
5
5
  }
6
6
  interface Aggregate<This extends Aggregate<This, AID>, AID extends AggregateId> {
7
7
  typeName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "event-store-adapter-js",
3
- "version": "2.0.20",
3
+ "version": "2.0.21-snapshot.2",
4
4
  "description": "This library is designed to turn DynamoDB into an Event Store for Event Sourcing.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@ class DefaultKeyResolver<AID extends AggregateId> implements KeyResolver<AID> {
18
18
  if (aggregateId === undefined || aggregateId === null) {
19
19
  throw new Error(`aggregateId is undefined or null: ${aggregateId}`);
20
20
  }
21
- const hash = this.hashString(aggregateId.asString);
21
+ const hash = this.hashString(aggregateId.asString());
22
22
  const remainder = hash % shardCount;
23
23
  return `${aggregateId.typeName}-${remainder}`;
24
24
  }
@@ -76,7 +76,7 @@ class EventStoreForDynamoDB<
76
76
  "#seq_nr": "seq_nr",
77
77
  },
78
78
  ExpressionAttributeValues: {
79
- ":aid": { S: id.asString },
79
+ ":aid": { S: id.asString() },
80
80
  ":seq_nr": { N: sequenceNumber.toString() },
81
81
  },
82
82
  };
@@ -119,7 +119,7 @@ class EventStoreForDynamoDB<
119
119
  "#seq_nr": "seq_nr",
120
120
  },
121
121
  ExpressionAttributeValues: {
122
- ":aid": { S: id.asString },
122
+ ":aid": { S: id.asString() },
123
123
  ":seq_nr": { N: "0" },
124
124
  },
125
125
  Limit: 1,
@@ -165,9 +165,9 @@ class EventStoreForDynamoDB<
165
165
  }
166
166
 
167
167
  async persistEventAndSnapshot(event: E, aggregate: A): Promise<void> {
168
- if (event.aggregateId.asString !== aggregate.id.asString) {
168
+ if (event.aggregateId.asString() !== aggregate.id.asString()) {
169
169
  throw new Error(
170
- `aggregateId mismatch: expected ${event.aggregateId.asString}, got ${aggregate.id.asString}`,
170
+ `aggregateId mismatch: expected ${event.aggregateId.asString()}, got ${aggregate.id.asString()}`,
171
171
  );
172
172
  }
173
173
  this.logger?.debug(
@@ -364,7 +364,7 @@ class EventStoreForDynamoDB<
364
364
  Item: {
365
365
  pkey: { S: pkey },
366
366
  skey: { S: skey },
367
- aid: { S: event.aggregateId.asString },
367
+ aid: { S: event.aggregateId.asString() },
368
368
  seq_nr: { N: event.sequenceNumber.toString() },
369
369
  payload: { B: payload },
370
370
  occurred_at: { N: event.occurredAt.getUTCMilliseconds().toString() },
@@ -397,7 +397,7 @@ class EventStoreForDynamoDB<
397
397
  pkey: { S: pkey },
398
398
  skey: { S: skey },
399
399
  payload: { B: payload },
400
- aid: { S: event.aggregateId.asString },
400
+ aid: { S: event.aggregateId.asString() },
401
401
  seq_nr: { N: sequenceNumber.toString() },
402
402
  version: { N: "1" },
403
403
  ttl: { N: "0" },
@@ -510,7 +510,7 @@ class EventStoreForDynamoDB<
510
510
  "#aid": "aid",
511
511
  },
512
512
  ExpressionAttributeValues: {
513
- ":aid": { S: aggregateId.asString },
513
+ ":aid": { S: aggregateId.asString() },
514
514
  },
515
515
  Select: "COUNT",
516
516
  };
@@ -526,7 +526,7 @@ class EventStoreForDynamoDB<
526
526
  "#seq_nr": "seq_nr",
527
527
  };
528
528
  const values = {
529
- ":aid": { S: aggregateId.asString },
529
+ ":aid": { S: aggregateId.asString() },
530
530
  ":seq_nr": { N: "0" },
531
531
  };
532
532
  const request: QueryCommandInput = {
@@ -16,12 +16,12 @@ class EventStoreForMemory<
16
16
  ) {
17
17
  this.events = new Map(
18
18
  Array.from(events).map(([key, values]) => {
19
- return [key.asString, values];
19
+ return [key.asString(), values];
20
20
  }),
21
21
  );
22
22
  this.snapshots = new Map(
23
23
  Array.from(snapshots).map(([key, value]) => {
24
- return [key.asString, value];
24
+ return [key.asString(), value];
25
25
  }),
26
26
  );
27
27
  }
@@ -30,17 +30,17 @@ class EventStoreForMemory<
30
30
  if (event.isCreated) {
31
31
  throw new Error("event is created");
32
32
  }
33
- const aggregateIdString = event.aggregateId.asString;
33
+ const aggregateIdString = event.aggregateId.asString();
34
34
  const snapshot = this.snapshots.get(aggregateIdString);
35
35
  if (snapshot === undefined) {
36
36
  throw new Error("snapshot is undefined");
37
37
  }
38
- if (snapshot.id.asString !== event.aggregateId.asString) {
38
+ if (snapshot.id.asString() !== event.aggregateId.asString()) {
39
39
  throw new Error(
40
40
  "aggregateId mismatch: snapshot.id = " +
41
- snapshot.id.asString +
41
+ snapshot.id.asString() +
42
42
  ", event.aggregateId = " +
43
- event.aggregateId.asString,
43
+ event.aggregateId.asString(),
44
44
  );
45
45
  }
46
46
  if (snapshot.version !== version) {
@@ -58,12 +58,12 @@ class EventStoreForMemory<
58
58
  }
59
59
 
60
60
  async persistEventAndSnapshot(event: E, aggregate: A): Promise<void> {
61
- if (event.aggregateId.asString !== aggregate.id.asString) {
61
+ if (event.aggregateId.asString() !== aggregate.id.asString()) {
62
62
  throw new Error(
63
- `aggregateId mismatch: expected ${event.aggregateId.asString}, got ${aggregate.id.asString}`,
63
+ `aggregateId mismatch: expected ${event.aggregateId.asString()}, got ${aggregate.id.asString()}`,
64
64
  );
65
65
  }
66
- const aggregateIdString = event.aggregateId.asString;
66
+ const aggregateIdString = event.aggregateId.asString();
67
67
  const events = this.events.get(aggregateIdString) ?? [];
68
68
  const snapshot = this.snapshots.get(aggregateIdString) ?? aggregate;
69
69
 
@@ -85,7 +85,7 @@ class EventStoreForMemory<
85
85
  id: AID,
86
86
  sequenceNumber: number,
87
87
  ): Promise<E[]> {
88
- const aggregateIdString = id.asString;
88
+ const aggregateIdString = id.asString();
89
89
  const events = this.events.get(aggregateIdString);
90
90
  if (events === undefined) {
91
91
  throw new Error("events is undefined");
@@ -94,7 +94,7 @@ class EventStoreForMemory<
94
94
  }
95
95
 
96
96
  async getLatestSnapshotById(id: AID): Promise<A | undefined> {
97
- const aggregateIdString = id.asString;
97
+ const aggregateIdString = id.asString();
98
98
  return this.snapshots.get(aggregateIdString);
99
99
  }
100
100
  }
@@ -4,7 +4,7 @@ class UserAccountId implements AggregateId {
4
4
  public readonly typeName = "user-account";
5
5
  constructor(public readonly value: string) {}
6
6
 
7
- get asString(): string {
7
+ asString(): string {
8
8
  return `${this.typeName}-${this.value}`;
9
9
  }
10
10
  }
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  interface AggregateId {
2
2
  typeName: string;
3
3
  value: string;
4
- asString: string;
4
+ asString: () => string;
5
5
  }
6
6
 
7
7
  interface Aggregate<