event-store-adapter-js 2.0.18-snapshot.1 → 2.0.18

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.
@@ -2,13 +2,13 @@ import { Aggregate, AggregateId, Event, EventSerializer, SnapshotSerializer } fr
2
2
  declare class JsonEventSerializer<AID extends AggregateId, E extends Event<AID>> implements EventSerializer<AID, E> {
3
3
  private encoder;
4
4
  private decoder;
5
- deserialize(bytes: Uint8Array, converter: (json: string) => E): E;
5
+ deserialize(bytes: Uint8Array, converter: (json: any) => E): E;
6
6
  serialize(event: E): Uint8Array;
7
7
  }
8
8
  declare class JsonSnapshotSerializer<AID extends AggregateId, A extends Aggregate<A, AID>> implements SnapshotSerializer<AID, A> {
9
9
  private encoder;
10
10
  private decoder;
11
- deserialize(bytes: Uint8Array, converter: (json: string) => A): A;
11
+ deserialize(bytes: Uint8Array, converter: (json: any) => A): A;
12
12
  serialize(aggregate: A): Uint8Array;
13
13
  }
14
14
  export { JsonEventSerializer, JsonSnapshotSerializer };
@@ -6,9 +6,11 @@ class JsonEventSerializer {
6
6
  this.encoder = new TextEncoder();
7
7
  this.decoder = new TextDecoder();
8
8
  }
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
  deserialize(bytes, converter) {
10
11
  const jsonString = this.decoder.decode(bytes);
11
- return converter(jsonString);
12
+ const json = JSON.parse(jsonString);
13
+ return converter(json);
12
14
  }
13
15
  serialize(event) {
14
16
  const jsonString = JSON.stringify({
@@ -24,9 +26,11 @@ class JsonSnapshotSerializer {
24
26
  this.encoder = new TextEncoder();
25
27
  this.decoder = new TextDecoder();
26
28
  }
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
30
  deserialize(bytes, converter) {
28
31
  const jsonString = this.decoder.decode(bytes);
29
- return converter(jsonString);
32
+ const obj = JSON.parse(jsonString);
33
+ return converter(obj);
30
34
  }
31
35
  serialize(aggregate) {
32
36
  const jsonString = JSON.stringify({
package/dist/types.d.ts CHANGED
@@ -25,11 +25,11 @@ interface KeyResolver<AID extends AggregateId> {
25
25
  }
26
26
  interface EventSerializer<AID extends AggregateId, E extends Event<AID>> {
27
27
  serialize(event: E): Uint8Array;
28
- deserialize(bytes: Uint8Array, converter: (json: string) => E): E;
28
+ deserialize(bytes: Uint8Array, converter: (json: any) => E): E;
29
29
  }
30
30
  interface SnapshotSerializer<AID extends AggregateId, A extends Aggregate<A, AID>> {
31
31
  serialize(aggregate: A): Uint8Array;
32
- deserialize(bytes: Uint8Array, converter: (json: string) => A): A;
32
+ deserialize(bytes: Uint8Array, converter: (json: any) => A): A;
33
33
  }
34
34
  export interface Logger {
35
35
  trace?: (...content: any[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "event-store-adapter-js",
3
- "version": "2.0.18-snapshot.1",
3
+ "version": "2.0.18",
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",
@@ -12,9 +12,11 @@ class JsonEventSerializer<AID extends AggregateId, E extends Event<AID>>
12
12
  private encoder = new TextEncoder();
13
13
  private decoder = new TextDecoder();
14
14
 
15
- deserialize(bytes: Uint8Array, converter: (json: string) => E): E {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ deserialize(bytes: Uint8Array, converter: (json: any) => E): E {
16
17
  const jsonString = this.decoder.decode(bytes);
17
- return converter(jsonString);
18
+ const json = JSON.parse(jsonString);
19
+ return converter(json);
18
20
  }
19
21
 
20
22
  serialize(event: E): Uint8Array {
@@ -33,9 +35,11 @@ class JsonSnapshotSerializer<
33
35
  {
34
36
  private encoder = new TextEncoder();
35
37
  private decoder = new TextDecoder();
36
- deserialize(bytes: Uint8Array, converter: (json: string) => A): A {
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ deserialize(bytes: Uint8Array, converter: (json: any) => A): A {
37
40
  const jsonString = this.decoder.decode(bytes);
38
- return converter(jsonString);
41
+ const obj = JSON.parse(jsonString);
42
+ return converter(obj);
39
43
  }
40
44
 
41
45
  serialize(aggregate: A): Uint8Array {
@@ -28,30 +28,28 @@ class UserAccountRenamed implements UserAccountEvent {
28
28
  ) {}
29
29
  }
30
30
 
31
- function convertJSONtoUserAccountEvent(jsonString: string): UserAccountEvent {
32
- const obj = JSON.parse(jsonString);
33
- const aggregateId = convertJSONToUserAccountId(
34
- JSON.stringify(obj.data.aggregateId),
35
- );
36
- switch (obj.type) {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ function convertJSONtoUserAccountEvent(json: any): UserAccountEvent {
33
+ const aggregateId = convertJSONToUserAccountId(json.data.aggregateId);
34
+ switch (json.type) {
37
35
  case "UserAccountCreated":
38
36
  return new UserAccountCreated(
39
- obj.data.id,
37
+ json.data.id,
40
38
  aggregateId,
41
- obj.data.name,
42
- obj.data.sequenceNumber,
43
- obj.data.occurredAt,
39
+ json.data.name,
40
+ json.data.sequenceNumber,
41
+ json.data.occurredAt,
44
42
  );
45
43
  case "UserAccountRenamed":
46
44
  return new UserAccountRenamed(
47
- obj.data.id,
45
+ json.data.id,
48
46
  aggregateId,
49
- obj.data.name,
50
- obj.data.sequenceNumber,
51
- obj.data.occurredAt,
47
+ json.data.name,
48
+ json.data.sequenceNumber,
49
+ json.data.occurredAt,
52
50
  );
53
51
  default:
54
- throw new Error(`Unknown type: ${obj.type}`);
52
+ throw new Error(`Unknown type: ${json.type}`);
55
53
  }
56
54
  }
57
55
 
@@ -9,9 +9,9 @@ class UserAccountId implements AggregateId {
9
9
  }
10
10
  }
11
11
 
12
- function convertJSONToUserAccountId(jsonString: string): UserAccountId {
13
- const obj = JSON.parse(jsonString);
14
- return new UserAccountId(obj.value);
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ function convertJSONToUserAccountId(json: any): UserAccountId {
14
+ return new UserAccountId(json.value);
15
15
  }
16
16
 
17
17
  export { UserAccountId, convertJSONToUserAccountId };
@@ -93,14 +93,14 @@ class UserAccount implements Aggregate<UserAccount, UserAccountId> {
93
93
  }
94
94
  }
95
95
 
96
- function convertJSONToUserAccount(jsonString: string): UserAccount {
97
- const obj = JSON.parse(jsonString);
98
- const id = convertJSONToUserAccountId(JSON.stringify(obj.data.id));
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ function convertJSONToUserAccount(json: any): UserAccount {
98
+ const id = convertJSONToUserAccountId(json.data.id);
99
99
  return new UserAccount(
100
100
  id,
101
- obj.data.name,
102
- obj.data.sequenceNumber,
103
- obj.data.version,
101
+ json.data.name,
102
+ json.data.sequenceNumber,
103
+ json.data.version,
104
104
  );
105
105
  }
106
106
 
package/src/types.ts CHANGED
@@ -33,8 +33,8 @@ interface KeyResolver<AID extends AggregateId> {
33
33
 
34
34
  interface EventSerializer<AID extends AggregateId, E extends Event<AID>> {
35
35
  serialize(event: E): Uint8Array;
36
-
37
- deserialize(bytes: Uint8Array, converter: (json: string) => E): E;
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ deserialize(bytes: Uint8Array, converter: (json: any) => E): E;
38
38
  }
39
39
 
40
40
  interface SnapshotSerializer<
@@ -42,8 +42,8 @@ interface SnapshotSerializer<
42
42
  A extends Aggregate<A, AID>,
43
43
  > {
44
44
  serialize(aggregate: A): Uint8Array;
45
-
46
- deserialize(bytes: Uint8Array, converter: (json: string) => A): A;
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ deserialize(bytes: Uint8Array, converter: (json: any) => A): A;
47
47
  }
48
48
 
49
49
  export interface Logger {