@fraym/streams 0.1.3 → 0.1.5
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/README.md +1 -1
- package/dist/client/event.js +1 -1
- package/dist/client/handler.js +21 -8
- package/dist/client/publish.js +1 -1
- package/dist/client/snapshot.js +18 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# streams-nodejs
|
|
2
2
|
|
|
3
|
-
Client implementation in javascript for the event streaming service [streams](https://github.com/fraym
|
|
3
|
+
Client implementation in javascript for the event streaming service [streams](https://github.com/fraym/streams).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
package/dist/client/event.js
CHANGED
|
@@ -27,7 +27,7 @@ const getSubscriptionEvent = (eventEnvelope) => {
|
|
|
27
27
|
topic: eventEnvelope.topic,
|
|
28
28
|
tenantId: eventEnvelope.tenantId,
|
|
29
29
|
payload,
|
|
30
|
-
raisedAt: new Date(event.raisedAt),
|
|
30
|
+
raisedAt: new Date(event.raisedAt / 1000000),
|
|
31
31
|
stream: event.stream || undefined,
|
|
32
32
|
type: event.type || undefined,
|
|
33
33
|
causationId: event.causationId || undefined,
|
package/dist/client/handler.js
CHANGED
|
@@ -34,19 +34,20 @@ const initEventHandler = (stream) => {
|
|
|
34
34
|
};
|
|
35
35
|
exports.initEventHandler = initEventHandler;
|
|
36
36
|
const handleEvent = (event, handler, stream) => {
|
|
37
|
+
stream.write(newEventReceivedRequest(event.tenantId, event.topic, event.id));
|
|
37
38
|
handler(event)
|
|
38
39
|
.then(() => {
|
|
39
|
-
stream.write(
|
|
40
|
+
stream.write(newEventHandledRequest(event.tenantId, event.topic, event.id));
|
|
40
41
|
})
|
|
41
42
|
.catch(e => {
|
|
42
|
-
stream.write(
|
|
43
|
+
stream.write(newEventNotHandledRequest(event.tenantId, event.topic, event.id, e));
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
|
-
const
|
|
46
|
+
const newEventReceivedRequest = (tenantId, topic, eventId) => {
|
|
46
47
|
return {
|
|
47
48
|
payload: {
|
|
48
|
-
$case: "
|
|
49
|
-
|
|
49
|
+
$case: "eventReceived",
|
|
50
|
+
eventReceived: {
|
|
50
51
|
eventId,
|
|
51
52
|
tenantId,
|
|
52
53
|
topic,
|
|
@@ -54,11 +55,23 @@ const newEventAckRequest = (tenantId, topic, eventId) => {
|
|
|
54
55
|
},
|
|
55
56
|
};
|
|
56
57
|
};
|
|
57
|
-
const
|
|
58
|
+
const newEventHandledRequest = (tenantId, topic, eventId) => {
|
|
58
59
|
return {
|
|
59
60
|
payload: {
|
|
60
|
-
$case: "
|
|
61
|
-
|
|
61
|
+
$case: "eventHandled",
|
|
62
|
+
eventHandled: {
|
|
63
|
+
eventId,
|
|
64
|
+
tenantId,
|
|
65
|
+
topic,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const newEventNotHandledRequest = (tenantId, topic, eventId, reason) => {
|
|
71
|
+
return {
|
|
72
|
+
payload: {
|
|
73
|
+
$case: "eventNotHandled",
|
|
74
|
+
eventNotHandled: {
|
|
62
75
|
eventId,
|
|
63
76
|
tenantId,
|
|
64
77
|
topic,
|
package/dist/client/publish.js
CHANGED
|
@@ -75,7 +75,7 @@ const getEventEnvelopeFromPublishedEvent = (event) => {
|
|
|
75
75
|
correlationId: (_e = event.correlationId) !== null && _e !== void 0 ? _e : "",
|
|
76
76
|
causationId: (_f = event.causationId) !== null && _f !== void 0 ? _f : "",
|
|
77
77
|
payload,
|
|
78
|
-
raisedAt:
|
|
78
|
+
raisedAt: 0,
|
|
79
79
|
},
|
|
80
80
|
};
|
|
81
81
|
};
|
package/dist/client/snapshot.js
CHANGED
|
@@ -6,19 +6,32 @@ const sendSnapshot = async (topic, toTime, config, stream) => {
|
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
7
7
|
const timeout = setTimeout(() => {
|
|
8
8
|
stream.off("data", fn);
|
|
9
|
-
reject("did not receive snapshot
|
|
9
|
+
reject("did not receive snapshot started in configured timeout range");
|
|
10
10
|
}, config.ackTimeout);
|
|
11
11
|
const fn = (data) => {
|
|
12
|
-
var _a, _b;
|
|
13
|
-
if (((_a = data.data) === null || _a === void 0 ? void 0 : _a.$case) === "
|
|
12
|
+
var _a, _b, _c, _d;
|
|
13
|
+
if (((_a = data.data) === null || _a === void 0 ? void 0 : _a.$case) === "snapshotNotStarted" &&
|
|
14
|
+
data.data.snapshotNotStarted.topic === topic) {
|
|
14
15
|
clearTimeout(timeout);
|
|
15
16
|
stream.off("data", fn);
|
|
16
|
-
reject(`did receive snapshot not
|
|
17
|
+
reject(`did receive snapshot not started message, reason: ${data.data.snapshotNotStarted.reason}`);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
if (((_b = data.data) === null || _b === void 0 ? void 0 : _b.$case) === "
|
|
20
|
+
if (((_b = data.data) === null || _b === void 0 ? void 0 : _b.$case) === "snapshotNotFinished" &&
|
|
21
|
+
data.data.snapshotNotFinished.topic === topic) {
|
|
20
22
|
clearTimeout(timeout);
|
|
21
23
|
stream.off("data", fn);
|
|
24
|
+
reject(`did receive snapshot not finished message, reason: ${data.data.snapshotNotFinished.reason}`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (((_c = data.data) === null || _c === void 0 ? void 0 : _c.$case) === "snapshotStarted" &&
|
|
28
|
+
data.data.snapshotStarted.topic === topic) {
|
|
29
|
+
clearTimeout(timeout);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (((_d = data.data) === null || _d === void 0 ? void 0 : _d.$case) === "snapshotFinished" &&
|
|
33
|
+
data.data.snapshotFinished.topic === topic) {
|
|
34
|
+
stream.off("data", fn);
|
|
22
35
|
resolve();
|
|
23
36
|
return;
|
|
24
37
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/streams",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
|
-
"homepage": "https://github.com/fraym
|
|
5
|
+
"homepage": "https://github.com/fraym/streams-nodejs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/fraym
|
|
8
|
+
"url": "git+https://github.com/fraym/streams-nodejs.git"
|
|
9
9
|
},
|
|
10
10
|
"description": "nodejs client implementation for our event streaming service",
|
|
11
11
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"types": "dist/index.d.ts",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@fraym/streams-proto": "^
|
|
27
|
+
"@fraym/streams-proto": "^6.0.0-alpha.8",
|
|
28
28
|
"@grpc/grpc-js": "^1.7.2",
|
|
29
29
|
"uuid": "^9.0.0"
|
|
30
30
|
},
|