@eventualize/types 1.0.0 → 2.0.0
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.
- package/package.json +17 -3
- package/src/DelayStrategy.ts +0 -23
- package/src/EvDbContinuousFetchOptions.ts +0 -22
- package/src/EvDbEvent.ts +0 -15
- package/src/EvDbMessage.ts +0 -105
- package/src/EvDbMessageFilter.ts +0 -86
- package/src/EvDbMessagesProducer.ts +0 -5
- package/src/EvDbSnapshotCursor.ts +0 -91
- package/src/EvDbStoredSnapshotData.ts +0 -106
- package/src/EvDbStoredSnapshotResult.ts +0 -44
- package/src/EvDbStoredSnapshotResultBase.ts +0 -11
- package/src/EvDbStreamAddress.ts +0 -10
- package/src/EvDbStreamCursor.ts +0 -52
- package/src/EvDbViewAddress.ts +0 -26
- package/src/IEvDbChangeStream.ts +0 -92
- package/src/IEvDbEventMetadata.ts +0 -32
- package/src/IEvDbEventPayload.ts +0 -8
- package/src/IEvDbEventsSet.ts +0 -10
- package/src/IEvDbStorageAdmin.ts +0 -35
- package/src/IEvDbStorageSnapshotAdapter.ts +0 -29
- package/src/IEvDbStorageStreamAdapter.ts +0 -43
- package/src/IEvDbStreamStore.ts +0 -22
- package/src/IEvDbStreamStoreData.ts +0 -27
- package/src/IEvDbView.ts +0 -18
- package/src/IEvDbViewAppliesSet.ts +0 -8
- package/src/IEvDbViewStore.ts +0 -38
- package/src/OCCException.ts +0 -34
- package/src/StreamStoreAffected.ts +0 -20
- package/src/primitiveTypes.ts +0 -7
- package/tsconfig.json +0 -15
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventualize/types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/outsidenote/eventualize-js",
|
|
8
|
+
"directory": "packages/types"
|
|
9
|
+
},
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
7
12
|
"exports": {
|
|
@@ -9,7 +14,13 @@
|
|
|
9
14
|
"import": "./dist/index.js",
|
|
10
15
|
"types": "./dist/index.d.ts"
|
|
11
16
|
},
|
|
12
|
-
"./*":
|
|
17
|
+
"./*": {
|
|
18
|
+
"import": "./dist/*.js",
|
|
19
|
+
"types": "./dist/*.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
13
24
|
},
|
|
14
25
|
"scripts": {
|
|
15
26
|
"build": "tsc --build",
|
|
@@ -23,5 +34,8 @@
|
|
|
23
34
|
"@prisma/client": "^7.1.0",
|
|
24
35
|
"dotenv": "^17.2.3",
|
|
25
36
|
"prisma": "^7.1.0"
|
|
26
|
-
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
]
|
|
27
41
|
}
|
package/src/DelayStrategy.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export default class DelayStrategy {
|
|
2
|
-
startDuration: number; // milliseconds
|
|
3
|
-
incrementalLogic: (lastDelay: number, attempt: number) => number;
|
|
4
|
-
|
|
5
|
-
constructor(init?: Partial<DelayStrategy>) {
|
|
6
|
-
this.startDuration = init?.startDuration ?? 200; // 200 ms default
|
|
7
|
-
this.incrementalLogic = init?.incrementalLogic ?? this.defaultNextDelay.bind(this);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
private defaultNextDelay(lastDelay: number, attempt: number): number {
|
|
11
|
-
if (attempt <= 5) {
|
|
12
|
-
return this.startDuration;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// When lastDelay == 0 → return 50ms
|
|
16
|
-
if (lastDelay === 0) {
|
|
17
|
-
return 50;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Exponential growth: double the last delay
|
|
21
|
-
return lastDelay * 2;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import DelayStrategy from "./DelayStrategy.js";
|
|
2
|
-
|
|
3
|
-
export default class EvDbContinuousFetchOptions {
|
|
4
|
-
private static readonly MAX_DELAY_SEC = 3;
|
|
5
|
-
|
|
6
|
-
static readonly CompleteIfEmpty = new EvDbContinuousFetchOptions({
|
|
7
|
-
completeWhenEmpty: true
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
static readonly ContinueWhenEmpty = new EvDbContinuousFetchOptions();
|
|
11
|
-
|
|
12
|
-
completeWhenEmpty: boolean;
|
|
13
|
-
delayWhenEmpty: DelayStrategy;
|
|
14
|
-
maxDelayWhenEmpty: number; // milliseconds
|
|
15
|
-
|
|
16
|
-
constructor(init?: Partial<EvDbContinuousFetchOptions>) {
|
|
17
|
-
this.completeWhenEmpty = init?.completeWhenEmpty ?? false;
|
|
18
|
-
this.delayWhenEmpty = init?.delayWhenEmpty ?? new DelayStrategy();
|
|
19
|
-
this.maxDelayWhenEmpty = init?.maxDelayWhenEmpty
|
|
20
|
-
?? EvDbContinuousFetchOptions.MAX_DELAY_SEC * 1000;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/EvDbEvent.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import EvDbStreamCursor from "./EvDbStreamCursor.js";
|
|
2
|
-
import IEvDbEventMetadata from "./IEvDbEventMetadata.js";
|
|
3
|
-
import IEvDbEventPayload from "./IEvDbEventPayload.js";
|
|
4
|
-
|
|
5
|
-
export default class EvDbEvent implements IEvDbEventMetadata {
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
8
|
-
public readonly eventType: string,
|
|
9
|
-
public readonly streamCursor: EvDbStreamCursor,
|
|
10
|
-
public readonly payload: IEvDbEventPayload,
|
|
11
|
-
public readonly capturedAt: Date = new Date(Date.now()),
|
|
12
|
-
public readonly capturedBy: string = 'N/A',
|
|
13
|
-
public readonly storedAt?: Date,
|
|
14
|
-
) { }
|
|
15
|
-
}
|
package/src/EvDbMessage.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import EvDbEvent from "./EvDbEvent.js";
|
|
2
|
-
import EvDbStreamCursor from "./EvDbStreamCursor.js";
|
|
3
|
-
import IEvDbEventPayload, { IEvDbPayloadData } from "./IEvDbEventPayload.js";
|
|
4
|
-
|
|
5
|
-
export default class EvDbMessage {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
public static readonly Empty: EvDbMessage = EvDbMessage.createWithId(
|
|
9
|
-
'',
|
|
10
|
-
'',
|
|
11
|
-
'',
|
|
12
|
-
'',
|
|
13
|
-
'',
|
|
14
|
-
'',
|
|
15
|
-
new Date(0),
|
|
16
|
-
'',
|
|
17
|
-
{} as EvDbStreamCursor,
|
|
18
|
-
undefined
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
private constructor(
|
|
22
|
-
public readonly id: string,
|
|
23
|
-
public readonly eventType: string,
|
|
24
|
-
public readonly channel: string,
|
|
25
|
-
public readonly shardName: string,
|
|
26
|
-
public readonly messageType: string,
|
|
27
|
-
public readonly serializeType: string,
|
|
28
|
-
public readonly capturedAt: Date,
|
|
29
|
-
public readonly capturedBy: string,
|
|
30
|
-
public readonly streamCursor: EvDbStreamCursor,
|
|
31
|
-
public readonly payload: IEvDbPayloadData,
|
|
32
|
-
public readonly storedAt?: Date
|
|
33
|
-
) { }
|
|
34
|
-
|
|
35
|
-
public static createWithId(
|
|
36
|
-
id: string,
|
|
37
|
-
eventType: string,
|
|
38
|
-
channel: string,
|
|
39
|
-
shardName: string,
|
|
40
|
-
messageType: string,
|
|
41
|
-
serializeType: string,
|
|
42
|
-
capturedAt: Date,
|
|
43
|
-
capturedBy: string,
|
|
44
|
-
streamCursor: EvDbStreamCursor,
|
|
45
|
-
payload: any
|
|
46
|
-
): EvDbMessage {
|
|
47
|
-
return new EvDbMessage(
|
|
48
|
-
id,
|
|
49
|
-
eventType,
|
|
50
|
-
channel,
|
|
51
|
-
shardName,
|
|
52
|
-
messageType,
|
|
53
|
-
serializeType,
|
|
54
|
-
capturedAt,
|
|
55
|
-
capturedBy,
|
|
56
|
-
streamCursor,
|
|
57
|
-
payload
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static create(
|
|
62
|
-
eventType: string,
|
|
63
|
-
channel: string,
|
|
64
|
-
shardName: string,
|
|
65
|
-
messageType: string,
|
|
66
|
-
serializeType: string,
|
|
67
|
-
capturedAt: Date,
|
|
68
|
-
capturedBy: string,
|
|
69
|
-
streamCursor: EvDbStreamCursor,
|
|
70
|
-
payload: any
|
|
71
|
-
): EvDbMessage {
|
|
72
|
-
return new EvDbMessage(
|
|
73
|
-
crypto.randomUUID(),
|
|
74
|
-
eventType,
|
|
75
|
-
channel,
|
|
76
|
-
shardName,
|
|
77
|
-
messageType,
|
|
78
|
-
serializeType,
|
|
79
|
-
capturedAt,
|
|
80
|
-
capturedBy,
|
|
81
|
-
streamCursor,
|
|
82
|
-
payload
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public static createFromEvent(
|
|
87
|
-
event: EvDbEvent,
|
|
88
|
-
payload: IEvDbEventPayload,
|
|
89
|
-
channel: string = 'default',
|
|
90
|
-
serializeType: string = 'json'
|
|
91
|
-
): EvDbMessage {
|
|
92
|
-
return new EvDbMessage(
|
|
93
|
-
crypto.randomUUID(),
|
|
94
|
-
event.eventType,
|
|
95
|
-
channel,
|
|
96
|
-
'default',
|
|
97
|
-
payload.payloadType,
|
|
98
|
-
serializeType,
|
|
99
|
-
event.capturedAt,
|
|
100
|
-
event.capturedBy,
|
|
101
|
-
event.streamCursor,
|
|
102
|
-
payload
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/EvDbMessageFilter.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { EvDbChannelName, EvDbMessageTypeName } from "../../types/src/primitiveTypes.js";
|
|
2
|
-
|
|
3
|
-
export default class EvDbMessageFilter {
|
|
4
|
-
public readonly since: Date;
|
|
5
|
-
public readonly channels: ReadonlyArray<EvDbChannelName>;
|
|
6
|
-
public readonly messageTypes: ReadonlyArray<EvDbMessageTypeName>;
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
since: Date = new Date(0),
|
|
10
|
-
channels: ReadonlyArray<EvDbChannelName> = [],
|
|
11
|
-
messageTypes: ReadonlyArray<EvDbMessageTypeName> = []
|
|
12
|
-
) {
|
|
13
|
-
this.since = since;
|
|
14
|
-
this.channels = channels;
|
|
15
|
-
this.messageTypes = messageTypes;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a filter with the specified since date
|
|
20
|
-
*/
|
|
21
|
-
public static create(since: Date): EvDbMessageFilter {
|
|
22
|
-
return new EvDbMessageFilter(since);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates a filter from a Date
|
|
27
|
-
*/
|
|
28
|
-
public static fromDate(date: Date): EvDbMessageFilter {
|
|
29
|
-
return new EvDbMessageFilter(date);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a filter from a channel name
|
|
34
|
-
*/
|
|
35
|
-
public static fromChannel(channel: EvDbChannelName): EvDbMessageFilter {
|
|
36
|
-
return new EvDbMessageFilter(new Date(0), [channel]);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a filter from a message type name
|
|
41
|
-
*/
|
|
42
|
-
public static fromMessageType(messageType: EvDbMessageTypeName): EvDbMessageFilter {
|
|
43
|
-
return new EvDbMessageFilter(new Date(0), [], [messageType]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Adds a channel to the filter
|
|
48
|
-
* Restrict the messages to those that match the specified channels.
|
|
49
|
-
* Ignore this property if you want to get all messages.
|
|
50
|
-
*/
|
|
51
|
-
public addChannel(channel: EvDbChannelName): EvDbMessageFilter {
|
|
52
|
-
return new EvDbMessageFilter(
|
|
53
|
-
this.since,
|
|
54
|
-
[...this.channels, channel],
|
|
55
|
-
this.messageTypes
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Adds a message type to the filter
|
|
61
|
-
* Restrict the messages to those that match the specified message-types.
|
|
62
|
-
* Ignore this property if you want to get all messages.
|
|
63
|
-
*/
|
|
64
|
-
public addMessageType(messageType: EvDbMessageTypeName): EvDbMessageFilter {
|
|
65
|
-
return new EvDbMessageFilter(
|
|
66
|
-
this.since,
|
|
67
|
-
this.channels,
|
|
68
|
-
[...this.messageTypes, messageType]
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Creates a new filter with updated properties (similar to C# 'with' expression)
|
|
74
|
-
*/
|
|
75
|
-
public with(updates: {
|
|
76
|
-
since?: Date;
|
|
77
|
-
channels?: ReadonlyArray<EvDbChannelName>;
|
|
78
|
-
messageTypes?: ReadonlyArray<EvDbMessageTypeName>;
|
|
79
|
-
}): EvDbMessageFilter {
|
|
80
|
-
return new EvDbMessageFilter(
|
|
81
|
-
updates.since ?? this.since,
|
|
82
|
-
updates.channels ?? this.channels,
|
|
83
|
-
updates.messageTypes ?? this.messageTypes
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "./EvDbStreamAddress.js";
|
|
2
|
-
import EvDbViewAddress from "@eventualize/types/EvDbViewAddress";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default class EvDbSnapshotCursor {
|
|
6
|
-
readonly streamType: string;
|
|
7
|
-
readonly streamId: string;
|
|
8
|
-
readonly viewName: string;
|
|
9
|
-
readonly offset: number;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
streamType: string,
|
|
13
|
-
streamId: string,
|
|
14
|
-
viewName: string,
|
|
15
|
-
offset: number = 0
|
|
16
|
-
) {
|
|
17
|
-
this.streamType = streamType;
|
|
18
|
-
this.streamId = streamId;
|
|
19
|
-
this.viewName = viewName;
|
|
20
|
-
this.offset = offset;
|
|
21
|
-
|
|
22
|
-
Object.freeze(this); // mimic C# record struct immutability
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Equivalent to: public static readonly EvDbSnapshotCursor Empty
|
|
26
|
-
static readonly Empty = new EvDbSnapshotCursor("N/A", "N/A", "N/A", 0);
|
|
27
|
-
|
|
28
|
-
// Alternative constructor: (EvDbStreamAddress, viewName, offset)
|
|
29
|
-
static fromStreamAddress(
|
|
30
|
-
address: EvDbStreamAddress,
|
|
31
|
-
viewName: string,
|
|
32
|
-
offset: number = 0
|
|
33
|
-
): EvDbSnapshotCursor {
|
|
34
|
-
return new EvDbSnapshotCursor(address.streamType, address.streamId, viewName, offset);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// --------------------------
|
|
38
|
-
// Equality helpers
|
|
39
|
-
// --------------------------
|
|
40
|
-
|
|
41
|
-
private equalsViewAddress(address: EvDbViewAddress): boolean {
|
|
42
|
-
return (
|
|
43
|
-
this.streamType === address.streamType &&
|
|
44
|
-
this.streamId === address.streamId &&
|
|
45
|
-
this.viewName === address.viewName
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private equalsStreamAddress(address: EvDbStreamAddress): boolean {
|
|
50
|
-
return (
|
|
51
|
-
this.streamType === address.streamType &&
|
|
52
|
-
this.streamId === address.streamId
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// C# operator == equivalents
|
|
57
|
-
equalsAddress(address: any): boolean {
|
|
58
|
-
if ("viewName" in address) return this.equalsViewAddress(address);
|
|
59
|
-
return this.equalsStreamAddress(address);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// --------------------------
|
|
63
|
-
// "Implicit cast" equivalents
|
|
64
|
-
// --------------------------
|
|
65
|
-
|
|
66
|
-
toStreamAddress(): { streamType: string; streamId: string } {
|
|
67
|
-
return new EvDbStreamAddress(this.streamType, this.streamId);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
toViewAddress(): { streamType: string; streamId: string; viewName: string } {
|
|
71
|
-
return new EvDbViewAddress(
|
|
72
|
-
new EvDbStreamAddress(this.streamType, this.streamId),
|
|
73
|
-
this.viewName
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// --------------------------
|
|
78
|
-
// toString & filter string
|
|
79
|
-
// --------------------------
|
|
80
|
-
|
|
81
|
-
toString(): string {
|
|
82
|
-
// Format: Type:Id:View:000_000_000_000
|
|
83
|
-
const formattedOffset = this.offset.toString().padStart(12, "0");
|
|
84
|
-
return `${this.streamType}:${this.streamId}:${this.viewName}:${formattedOffset}`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
toFilterString(): string {
|
|
88
|
-
// Format without offset: Type:Id:View:
|
|
89
|
-
return `${this.streamType}:${this.streamId}:${this.viewName}:`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "./EvDbStreamAddress.js";
|
|
2
|
-
import { EvDbStoredSnapshotResultRaw } from "./EvDbStoredSnapshotResult";
|
|
3
|
-
import EvDbViewAddress from "./EvDbViewAddress";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Base class equivalent
|
|
8
|
-
export abstract class EvDbStoredSnapshotDataBase {
|
|
9
|
-
constructor(
|
|
10
|
-
public readonly id: string,
|
|
11
|
-
public readonly streamType: string,
|
|
12
|
-
public readonly streamId: string,
|
|
13
|
-
public readonly viewName: string,
|
|
14
|
-
public readonly offset: number,
|
|
15
|
-
public readonly storeOffset: number,
|
|
16
|
-
public readonly storedAt: Date = new Date()
|
|
17
|
-
) { }
|
|
18
|
-
|
|
19
|
-
toStreamAddress(): EvDbStreamAddress {
|
|
20
|
-
return new EvDbStreamAddress(this.streamType, this.streamId);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class EvDbStoredSnapshotData extends EvDbStoredSnapshotDataBase {
|
|
25
|
-
readonly state: any;
|
|
26
|
-
|
|
27
|
-
// Primary constructor equivalent
|
|
28
|
-
constructor(
|
|
29
|
-
id: string,
|
|
30
|
-
streamType: string,
|
|
31
|
-
streamId: string,
|
|
32
|
-
viewName: string,
|
|
33
|
-
offset: number,
|
|
34
|
-
storeOffset: number,
|
|
35
|
-
state: any
|
|
36
|
-
) {
|
|
37
|
-
super(id, streamType, streamId, viewName, offset, storeOffset);
|
|
38
|
-
this.state = state;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Secondary constructor (overload)
|
|
42
|
-
static fromAddress(
|
|
43
|
-
address: EvDbViewAddress,
|
|
44
|
-
offset: number,
|
|
45
|
-
storeOffset: number,
|
|
46
|
-
state: any
|
|
47
|
-
): EvDbStoredSnapshotData {
|
|
48
|
-
return new EvDbStoredSnapshotData(
|
|
49
|
-
crypto.randomUUID(),
|
|
50
|
-
address.streamType,
|
|
51
|
-
address.streamId,
|
|
52
|
-
address.viewName,
|
|
53
|
-
offset,
|
|
54
|
-
storeOffset,
|
|
55
|
-
state
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// ------------------------------------------------------------------------------------
|
|
60
|
-
// Equality helpers (TypeScript cannot overload ==, so explicit methods are used)
|
|
61
|
-
// ------------------------------------------------------------------------------------
|
|
62
|
-
|
|
63
|
-
private isEquals(obj: EvDbStoredSnapshotResultRaw): boolean {
|
|
64
|
-
if (this.offset !== obj.offset) return false;
|
|
65
|
-
|
|
66
|
-
// Compare any references (same as C# byte[] reference equality)
|
|
67
|
-
if (this.state !== obj.state) return false;
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
equalsSnapshotResult(result: EvDbStoredSnapshotResultRaw): boolean {
|
|
73
|
-
return this.isEquals(result);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// TODO: is this needed?
|
|
77
|
-
// equalsSnapshotCursor(cursor: EvDbSnapshotCursor): boolean {
|
|
78
|
-
// return this.isEquals(cursor);
|
|
79
|
-
// }
|
|
80
|
-
|
|
81
|
-
equalsStreamAddress(address: EvDbStreamAddress): boolean {
|
|
82
|
-
return (
|
|
83
|
-
this.streamType === address.streamType &&
|
|
84
|
-
this.streamId === address.streamId
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
equalsViewAddress(address: EvDbViewAddress): boolean {
|
|
89
|
-
return (
|
|
90
|
-
this.streamType === address.streamType &&
|
|
91
|
-
this.streamId === address.streamId &&
|
|
92
|
-
this.viewName === address.viewName
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ------------------------------------------------------------------------------------
|
|
97
|
-
// Casting Overload (implicit operator in C# → explicit method in TS)
|
|
98
|
-
// ------------------------------------------------------------------------------------
|
|
99
|
-
toSnapshotResult(): EvDbStoredSnapshotResultRaw {
|
|
100
|
-
return {
|
|
101
|
-
offset: this.offset,
|
|
102
|
-
storedAt: this.storedAt,
|
|
103
|
-
state: this.state
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import EvDbStoredSnapshotResultBase from "./EvDbStoredSnapshotResultBase.js"
|
|
2
|
-
|
|
3
|
-
export class EvDbStoredSnapshotResultRaw extends EvDbStoredSnapshotResultBase {
|
|
4
|
-
public readonly state: any;
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
offset: number,
|
|
8
|
-
storedAt: Date | undefined,
|
|
9
|
-
state: any
|
|
10
|
-
) {
|
|
11
|
-
super(offset, storedAt);
|
|
12
|
-
this.state = state;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static readonly Empty = new EvDbStoredSnapshotResultRaw(
|
|
16
|
-
0,
|
|
17
|
-
undefined,
|
|
18
|
-
undefined
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export class EvDbStoredSnapshotResult<TState>
|
|
24
|
-
extends EvDbStoredSnapshotResultBase
|
|
25
|
-
{
|
|
26
|
-
public readonly state: TState;
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
offset: number,
|
|
30
|
-
storedAt: Date | undefined,
|
|
31
|
-
state: TState
|
|
32
|
-
) {
|
|
33
|
-
super(offset, storedAt);
|
|
34
|
-
this.state = state;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static getEmptyState<TState>(): EvDbStoredSnapshotResult<TState> {
|
|
38
|
-
return new EvDbStoredSnapshotResult<TState>(
|
|
39
|
-
0,
|
|
40
|
-
undefined,
|
|
41
|
-
undefined as unknown as TState
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default class EvDbStoredSnapshotResultBase {
|
|
2
|
-
public readonly offset: number;
|
|
3
|
-
public readonly storedAt: Date | undefined;
|
|
4
|
-
|
|
5
|
-
protected constructor(offset: number, storedAt: Date | undefined) {
|
|
6
|
-
this.offset = offset;
|
|
7
|
-
this.storedAt = storedAt;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
static readonly None = new EvDbStoredSnapshotResultBase(0, undefined);
|
|
11
|
-
}
|
package/src/EvDbStreamAddress.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import EvDbStreamCursor from "./EvDbStreamCursor.js";
|
|
2
|
-
|
|
3
|
-
export default class EvDbStreamAddress {
|
|
4
|
-
constructor(public readonly streamType: string, public readonly streamId: string) { }
|
|
5
|
-
|
|
6
|
-
equals(other: EvDbStreamCursor): boolean {
|
|
7
|
-
return this.streamType === other.streamType &&
|
|
8
|
-
this.streamId === other.streamId;
|
|
9
|
-
}
|
|
10
|
-
}
|
package/src/EvDbStreamCursor.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "./EvDbStreamAddress.js";
|
|
2
|
-
|
|
3
|
-
export default class EvDbStreamCursor extends EvDbStreamAddress {
|
|
4
|
-
public readonly offset: number;
|
|
5
|
-
|
|
6
|
-
constructor(streamType: string, streamId: string, offset: number);
|
|
7
|
-
constructor(streamAddress: EvDbStreamAddress, offset: number);
|
|
8
|
-
|
|
9
|
-
constructor(streamTypeOrAddress: string | EvDbStreamAddress, streamIdOrOffset: string | number, offset?: number) {
|
|
10
|
-
if (typeof streamTypeOrAddress === 'string' && typeof streamIdOrOffset === 'string' && (!offset || typeof offset === 'number')) {
|
|
11
|
-
const streamType = streamTypeOrAddress;
|
|
12
|
-
const streamId = streamIdOrOffset;
|
|
13
|
-
super(streamType, streamId);
|
|
14
|
-
this.offset = offset ?? 0;
|
|
15
|
-
} else if (streamTypeOrAddress instanceof EvDbStreamAddress && (!streamIdOrOffset || typeof streamIdOrOffset === 'number')) {
|
|
16
|
-
const streamType = streamTypeOrAddress.streamType;
|
|
17
|
-
const streamId = streamTypeOrAddress.streamId;
|
|
18
|
-
super(streamType, streamId);
|
|
19
|
-
this.offset = streamIdOrOffset as number ?? 0;
|
|
20
|
-
} else {
|
|
21
|
-
throw new Error('Invalid constructor arguments for EvDbStreamCursor');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Checks if cursor matches the given stream type
|
|
27
|
-
*/
|
|
28
|
-
equals(other: EvDbStreamCursor): boolean {
|
|
29
|
-
return this.streamType === other.streamType &&
|
|
30
|
-
this.streamId === other.streamId &&
|
|
31
|
-
this.offset === other.offset;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public isEqualsStreamType(streamType: string): boolean {
|
|
35
|
-
return this.streamType === streamType;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Checks if cursor matches the given stream address
|
|
40
|
-
*/
|
|
41
|
-
public isEqualsAddress(address: EvDbStreamAddress): boolean {
|
|
42
|
-
return this.streamType === address.streamType &&
|
|
43
|
-
this.streamId === address.streamId;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts cursor to stream address
|
|
48
|
-
*/
|
|
49
|
-
public toStreamAddress(): EvDbStreamAddress {
|
|
50
|
-
return new EvDbStreamAddress(this.streamType, this.streamId);
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/EvDbViewAddress.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "@eventualize/types/EvDbStreamAddress";
|
|
2
|
-
|
|
3
|
-
export default class EvDbViewAddress extends EvDbStreamAddress {
|
|
4
|
-
public readonly viewName: string;
|
|
5
|
-
constructor(streamAddressOrType: EvDbStreamAddress | string, viewNameOrStreamId: string, viewName?: string) {
|
|
6
|
-
if (streamAddressOrType instanceof EvDbStreamAddress &&
|
|
7
|
-
typeof viewNameOrStreamId === "string" &&
|
|
8
|
-
!viewName
|
|
9
|
-
) {
|
|
10
|
-
const streamAddress = streamAddressOrType as EvDbStreamAddress;
|
|
11
|
-
super(streamAddress.streamType, streamAddress.streamId);
|
|
12
|
-
this.viewName = viewNameOrStreamId;
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (typeof streamAddressOrType === 'string' &&
|
|
16
|
-
typeof viewNameOrStreamId === 'string' &&
|
|
17
|
-
typeof viewName === 'string'
|
|
18
|
-
) {
|
|
19
|
-
super(streamAddressOrType, viewNameOrStreamId);
|
|
20
|
-
this.viewName = viewName;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
throw new Error('Unsupported set or arguments')
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/IEvDbChangeStream.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { EvDbShardName } from "./primitiveTypes.js";
|
|
2
|
-
import EvDbMessageFilter from "./EvDbMessageFilter.js";
|
|
3
|
-
import EvDbContinuousFetchOptions from "./EvDbContinuousFetchOptions.js";
|
|
4
|
-
import EvDbMessage from "./EvDbMessage.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default interface IEvDbChangeStream {
|
|
9
|
-
/**
|
|
10
|
-
* Gets stream of stored messages.
|
|
11
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
12
|
-
* @param options - Options for the continuous fetch.
|
|
13
|
-
* @returns Stream of messages
|
|
14
|
-
*/
|
|
15
|
-
getFromOutbox(
|
|
16
|
-
filter: EvDbMessageFilter,
|
|
17
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
18
|
-
): Promise<AsyncIterable<EvDbMessage>>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Gets stream of stored messages.
|
|
22
|
-
* @param shard - The shard (table/collection) of the messages
|
|
23
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
24
|
-
* @param options - Options for the continuous fetch.
|
|
25
|
-
* @param cancellation - The cancellation.
|
|
26
|
-
* @returns Stream of messages
|
|
27
|
-
*/
|
|
28
|
-
getFromOutboxAsync(
|
|
29
|
-
shard: EvDbShardName,
|
|
30
|
-
filter: EvDbMessageFilter,
|
|
31
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
32
|
-
cancellation?: AbortSignal
|
|
33
|
-
): AsyncIterable<EvDbMessage>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Gets stored messages.
|
|
37
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
38
|
-
* @param options - Options for the continuous fetch.
|
|
39
|
-
* @param cancellation - The cancellation.
|
|
40
|
-
* @returns Stream of messages
|
|
41
|
-
*/
|
|
42
|
-
getRecordsFromOutboxAsync(
|
|
43
|
-
filter: EvDbMessageFilter,
|
|
44
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
45
|
-
cancellation?: AbortSignal
|
|
46
|
-
): AsyncIterable<EvDbMessage>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Gets stream of stored messages.
|
|
50
|
-
* @param shard - The shard (table/collection) of the messages
|
|
51
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
52
|
-
* @param options - Options for the continuous fetch.
|
|
53
|
-
* @param cancellation - The cancellation.
|
|
54
|
-
* @returns Stream of messages
|
|
55
|
-
*/
|
|
56
|
-
getRecordsFromOutboxAsync(
|
|
57
|
-
shard: EvDbShardName,
|
|
58
|
-
filter: EvDbMessageFilter,
|
|
59
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
60
|
-
cancellation?: AbortSignal
|
|
61
|
-
): AsyncIterable<EvDbMessage>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Subscribe to a stream of stored messages into via Dataflow Block.
|
|
65
|
-
* You can control the concurrency and back pressure of the Dataflow Block to control how many messages will be processed in parallel and BoundedCapacity.
|
|
66
|
-
* Complete the Dataflow Block when the stream is completed or cancelled.
|
|
67
|
-
* @param handler - The subscription handler
|
|
68
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
69
|
-
* @param options - Options for the continuous fetch.
|
|
70
|
-
*/
|
|
71
|
-
subscribeToMessageAsync(
|
|
72
|
-
handler: (message: EvDbMessage) => Promise<void>,
|
|
73
|
-
filter: EvDbMessageFilter,
|
|
74
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
75
|
-
): Promise<void>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Subscribe to a stream of stored messages into via Dataflow Block.
|
|
79
|
-
* You can control the concurrency and back pressure of the Dataflow Block to control how many messages will be processed in parallel and BoundedCapacity.
|
|
80
|
-
* Complete the Dataflow Block when the stream is completed or cancelled.
|
|
81
|
-
* @param handler - The subscription handler
|
|
82
|
-
* @param shard - The shard (table/collection) of the messages
|
|
83
|
-
* @param filter - filtering options use `EvDbMessageFilter.Builder` for the filter creation.
|
|
84
|
-
* @param options - Options for the continuous fetch.
|
|
85
|
-
*/
|
|
86
|
-
subscribeToMessageAsync(
|
|
87
|
-
handler: (message: EvDbMessage) => Promise<void>,
|
|
88
|
-
shard: EvDbShardName,
|
|
89
|
-
filter: EvDbMessageFilter,
|
|
90
|
-
options?: EvDbContinuousFetchOptions | null,
|
|
91
|
-
): Promise<void>;
|
|
92
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import EvDbStreamCursor from "./EvDbStreamCursor.js";
|
|
2
|
-
|
|
3
|
-
export default interface IEvDbEventMetadata {
|
|
4
|
-
/**
|
|
5
|
-
* The full address of the stream including the offset
|
|
6
|
-
*/
|
|
7
|
-
readonly streamCursor: EvDbStreamCursor;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The type of the event
|
|
11
|
-
*/
|
|
12
|
-
readonly eventType: string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The time of capturing the event (client side time)
|
|
16
|
-
*/
|
|
17
|
-
readonly capturedAt: Date;
|
|
18
|
-
|
|
19
|
-
readonly storedAt?: Date | null;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The user that captured the event
|
|
23
|
-
*/
|
|
24
|
-
readonly capturedBy: string;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Json format of the Trace (Open Telemetry) propagated context at the persistent time.
|
|
28
|
-
* The value will be null if the Trace is null when persisting the record or before persistent.
|
|
29
|
-
*/
|
|
30
|
-
// TODO: implement telemetry context
|
|
31
|
-
// readonly telemetryContext: EvDbTelemetryContextName;
|
|
32
|
-
}
|
package/src/IEvDbEventPayload.ts
DELETED
package/src/IEvDbEventsSet.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import IEvDbEventPayload from "./IEvDbEventPayload.js";
|
|
2
|
-
import IEvDbEventMetadata from "./IEvDbEventMetadata.js";
|
|
3
|
-
|
|
4
|
-
type EvDbStreamEventHandler = (event: IEvDbEventPayload, capturedBy?: string) => Promise<IEvDbEventMetadata>
|
|
5
|
-
|
|
6
|
-
type EvDbStreamEventHandlersMap<TEvents extends IEvDbEventPayload> = Partial<{
|
|
7
|
-
[E in TEvents as `apply${E['payloadType']}`]: EvDbStreamEventHandler;
|
|
8
|
-
}>;
|
|
9
|
-
|
|
10
|
-
export default EvDbStreamEventHandlersMap;
|
package/src/IEvDbStorageAdmin.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for EvDb storage administration
|
|
3
|
-
* Handles environment setup and teardown operations
|
|
4
|
-
*/
|
|
5
|
-
export default interface IEvDbStorageAdmin {
|
|
6
|
-
/**
|
|
7
|
-
* Create the database environment (tables, indexes, etc.)
|
|
8
|
-
*/
|
|
9
|
-
createEnvironmentAsync(): Promise<void>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Destroy the database environment (drop tables, schema, etc.)
|
|
13
|
-
*/
|
|
14
|
-
destroyEnvironmentAsync(): Promise<void>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Clear environment data (delete from tables, etc.)
|
|
18
|
-
*/
|
|
19
|
-
clearEnvironmentAsync(): Promise<void>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Dispose of resources synchronously (if applicable)
|
|
23
|
-
*/
|
|
24
|
-
dispose?(): void;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Dispose of resources asynchronously
|
|
28
|
-
*/
|
|
29
|
-
disposeAsync(): Promise<void>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Close the connection to the store
|
|
33
|
-
*/
|
|
34
|
-
close(): Promise<void>;
|
|
35
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EvDbStoredSnapshotResultRaw } from "./EvDbStoredSnapshotResult.js";
|
|
2
|
-
import { EvDbStoredSnapshotData } from "./EvDbStoredSnapshotData.js";
|
|
3
|
-
import EvDbViewAddress from "./EvDbViewAddress.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Adapter for storing and retrieving view snapshots
|
|
7
|
-
*/
|
|
8
|
-
export default interface IEvDbStorageSnapshotAdapter {
|
|
9
|
-
/**
|
|
10
|
-
* Gets the latest stored view snapshot or an empty snapshot if none exists.
|
|
11
|
-
* @param viewAddress The view address
|
|
12
|
-
* @param signal Optional AbortSignal for cancellation
|
|
13
|
-
* @returns The stored snapshot result
|
|
14
|
-
*/
|
|
15
|
-
getSnapshotAsync(viewAddress: EvDbViewAddress): Promise<EvDbStoredSnapshotResultRaw>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Stores the view's state as a snapshot.
|
|
19
|
-
* @param snapshotData Snapshot data and metadata
|
|
20
|
-
* @param signal Optional AbortSignal for cancellation
|
|
21
|
-
*/
|
|
22
|
-
storeSnapshotAsync(snapshotData: EvDbStoredSnapshotData): Promise<void>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Close the storage adapter connection
|
|
26
|
-
* @returns Promise of void
|
|
27
|
-
*/
|
|
28
|
-
close(): Promise<void>
|
|
29
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import EvDbStreamCursor from "./EvDbStreamCursor.js";
|
|
2
|
-
import EvDbEvent from "./EvDbEvent.js";
|
|
3
|
-
import EvDbMessage from "./EvDbMessage.js";
|
|
4
|
-
import EvDbStreamAddress from "./EvDbStreamAddress";
|
|
5
|
-
import StreamStoreAffected from "./StreamStoreAffected.js";
|
|
6
|
-
import IEvDbChangeStream from "./IEvDbChangeStream.js";
|
|
7
|
-
|
|
8
|
-
export default interface IEvDbStorageStreamAdapter extends IEvDbChangeStream {
|
|
9
|
-
/**
|
|
10
|
-
* Gets stored events.
|
|
11
|
-
* @param streamCursor - The streamCursor.
|
|
12
|
-
* @returns Async iterable of EvDbEvent
|
|
13
|
-
*/
|
|
14
|
-
getEventsAsync(streamCursor: EvDbStreamCursor): AsyncGenerator<EvDbEvent, void, undefined>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets last stored event's offset.
|
|
18
|
-
* Used when getting a stream that has no views.
|
|
19
|
-
* In this case the last offset fetched from the events rather than views.
|
|
20
|
-
* @param address - The stream address
|
|
21
|
-
* @returns Promise resolving to the last offset
|
|
22
|
-
*/
|
|
23
|
-
getLastOffsetAsync(
|
|
24
|
-
address: EvDbStreamAddress,
|
|
25
|
-
): Promise<number>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Saves the pending events to the stream
|
|
29
|
-
* @param events - The events to save
|
|
30
|
-
* @param messages - The messages to save.
|
|
31
|
-
* @returns Promise resolving to count of added events
|
|
32
|
-
*/
|
|
33
|
-
storeStreamAsync(
|
|
34
|
-
events: ReadonlyArray<EvDbEvent>,
|
|
35
|
-
messages: ReadonlyArray<EvDbMessage>,
|
|
36
|
-
): Promise<StreamStoreAffected>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Close the storage adapter connection
|
|
40
|
-
* @returns Promise of void
|
|
41
|
-
*/
|
|
42
|
-
close(): Promise<void>
|
|
43
|
-
}
|
package/src/IEvDbStreamStore.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "./EvDbStreamAddress.js";
|
|
2
|
-
import StreamStoreAffected from "./StreamStoreAffected.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default interface IEvDbStreamStore {
|
|
7
|
-
/** The offset of the last event that was stored */
|
|
8
|
-
readonly storedOffset: number;
|
|
9
|
-
|
|
10
|
-
/** The stream's address */
|
|
11
|
-
readonly streamAddress: EvDbStreamAddress;
|
|
12
|
-
|
|
13
|
-
/** Number of events that were not stored yet */
|
|
14
|
-
readonly countOfPendingEvents: number;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Saves pending events into the injected storage.
|
|
18
|
-
* @param signal Optional AbortSignal to cancel the operation
|
|
19
|
-
* @returns Count of added events
|
|
20
|
-
*/
|
|
21
|
-
store(signal?: AbortSignal): Promise<StreamStoreAffected>;
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import EvDbStreamAddress from "./EvDbStreamAddress.js";
|
|
2
|
-
import IEvDbView from "./IEvDbView.js";
|
|
3
|
-
import EvDbEvent from "./EvDbEvent.js";
|
|
4
|
-
import EvDbMessage from "./EvDbMessage.js";
|
|
5
|
-
|
|
6
|
-
type ImmutableIEvDbView = Readonly<IEvDbView>;
|
|
7
|
-
export type ImmutableIEvDbViewMap = Readonly<Record<string, ImmutableIEvDbView>>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default interface IEvDbStreamStoreData {
|
|
11
|
-
/** Serialization options (optional) */
|
|
12
|
-
options?: Record<string, any>; // JsonSerializerOptions equivalent in TS
|
|
13
|
-
|
|
14
|
-
/** Views (unspecialized) */
|
|
15
|
-
getViews: () => ImmutableIEvDbViewMap;
|
|
16
|
-
|
|
17
|
-
getView(viewName: string): ImmutableIEvDbView | undefined;
|
|
18
|
-
|
|
19
|
-
/** Unspecialized events */
|
|
20
|
-
getEvents: () => ReadonlyArray<EvDbEvent>;
|
|
21
|
-
|
|
22
|
-
/** Unspecialized notifications */
|
|
23
|
-
getMessages: () => ReadonlyArray<EvDbMessage>;
|
|
24
|
-
|
|
25
|
-
/** Stream address (uniqueness) */
|
|
26
|
-
streamAddress: EvDbStreamAddress;
|
|
27
|
-
}
|
package/src/IEvDbView.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import EvDbViewAddress from "./EvDbViewAddress.js";
|
|
2
|
-
|
|
3
|
-
export default interface IEvDbView {
|
|
4
|
-
/**
|
|
5
|
-
* Gets the offset of the last folded event (in-memory).
|
|
6
|
-
*/
|
|
7
|
-
readonly memoryOffset: number;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Gets the name of the view.
|
|
11
|
-
*/
|
|
12
|
-
readonly address: EvDbViewAddress;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The offset of the last snapshot that was stored.
|
|
16
|
-
*/
|
|
17
|
-
readonly storeOffset: number;
|
|
18
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import IEvDbEventPayload from "./IEvDbEventPayload.js";
|
|
2
|
-
import IEvDbEventMetadata from "./IEvDbEventMetadata.js";
|
|
3
|
-
|
|
4
|
-
type IEvDbViewAppliesSet<Tstate, TEvents extends IEvDbEventPayload> = {
|
|
5
|
-
[E in TEvents as `apply${E['payloadType']}`]: (oldState: Tstate, newEvent: E, eventMetadata: IEvDbEventMetadata) => Tstate;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export default IEvDbViewAppliesSet;
|
package/src/IEvDbViewStore.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import IEvDbView from "./IEvDbView.js";
|
|
2
|
-
import EvDbEvent from "./EvDbEvent.js";
|
|
3
|
-
import { EvDbStoredSnapshotData } from "./EvDbStoredSnapshotData.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/// View store contract.
|
|
7
|
-
export default interface IEvDbViewStore extends IEvDbView {
|
|
8
|
-
/**
|
|
9
|
-
* Indication whether the snapshot should be saved.
|
|
10
|
-
* Useful for offset gaps, time since last save, or reacting to specific events.
|
|
11
|
-
*/
|
|
12
|
-
shouldStoreSnapshot(
|
|
13
|
-
offsetGapFromLastSave: number,
|
|
14
|
-
durationSinceLastSaveMs: number // TimeSpan → milliseconds
|
|
15
|
-
): boolean;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Apply event to the aggregate/view.
|
|
19
|
-
*/
|
|
20
|
-
applyEvent(e: EvDbEvent): void;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get the snapshot data.
|
|
24
|
-
*/
|
|
25
|
-
getSnapshotData(): EvDbStoredSnapshotData;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Save snapshot data.
|
|
29
|
-
*/
|
|
30
|
-
store(): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface IEvDbViewStoreGeneric<TState> extends IEvDbViewStore {
|
|
34
|
-
/**
|
|
35
|
-
* Get the current state of the view.
|
|
36
|
-
*/
|
|
37
|
-
state: TState;
|
|
38
|
-
}
|
package/src/OCCException.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import EvDbSnapshotCursor from "@eventualize/types/EvDbSnapshotCursor";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Optimistic Concurrency Collisions Exception
|
|
5
|
-
*/
|
|
6
|
-
export default class OCCException extends Error {
|
|
7
|
-
constructor();
|
|
8
|
-
/** @deprecated Shouldn't be used directly; used by the serialization */
|
|
9
|
-
constructor(message: string);
|
|
10
|
-
constructor(cursor: EvDbSnapshotCursor);
|
|
11
|
-
constructor(cursor: EvDbSnapshotCursor, innerException: Error);
|
|
12
|
-
constructor(arg1?: string | EvDbSnapshotCursor, arg2?: Error) {
|
|
13
|
-
if (typeof arg1 === "string") {
|
|
14
|
-
// Obsolete constructor
|
|
15
|
-
super(arg1);
|
|
16
|
-
} else if (arg1 instanceof EvDbSnapshotCursor) {
|
|
17
|
-
super(arg1.toString());
|
|
18
|
-
if (arg2) {
|
|
19
|
-
// Attach inner exception as a property (TypeScript does not have built-in inner exceptions)
|
|
20
|
-
(this as any).innerException = arg2;
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
super(); // parameterless constructor
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Set the prototype explicitly (needed for extending built-in Error in TypeScript)
|
|
27
|
-
Object.setPrototypeOf(this, OCCException.prototype);
|
|
28
|
-
|
|
29
|
-
this.name = "OCCException";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Optional inner exception for chaining */
|
|
33
|
-
public innerException?: Error;
|
|
34
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Indicate how many events and messages were affected.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
type EvDbOutboxShardName = string;
|
|
6
|
-
|
|
7
|
-
export default class StreamStoreAffected {
|
|
8
|
-
public readonly numEvents: number;
|
|
9
|
-
public readonly numMessages: ReadonlyMap<EvDbOutboxShardName, number> | undefined;
|
|
10
|
-
|
|
11
|
-
public static readonly Empty = new StreamStoreAffected(0, new Map());
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
numEvents: number,
|
|
15
|
-
numMessages: ReadonlyMap<EvDbOutboxShardName, number> | undefined
|
|
16
|
-
) {
|
|
17
|
-
this.numEvents = numEvents;
|
|
18
|
-
this.numMessages = numMessages;
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/primitiveTypes.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type EvDbShardName = string;
|
|
2
|
-
export type EvDbChannelName = string;
|
|
3
|
-
export type EvDbMessageTypeName = string;
|
|
4
|
-
export type EvDbEventTypeName = string;
|
|
5
|
-
export type EvDbStreamTypeName = string;
|
|
6
|
-
export type EvDbStreamId = string;
|
|
7
|
-
export type EvDbStreamType = string;
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"module": "es2020",
|
|
8
|
-
"target": "es2020",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|