@fraym/streams 0.10.4 → 0.10.6
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/dist/client/client.js
CHANGED
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.newClient = void 0;
|
|
4
4
|
const management_1 = require("@fraym/proto/freym/streams/management");
|
|
5
5
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
6
|
+
const allEvents_1 = require("./allEvents");
|
|
6
7
|
const config_1 = require("./config");
|
|
7
8
|
const getEvent_1 = require("./getEvent");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const getLastEvent_1 = require("./getLastEvent");
|
|
10
|
+
const getLastEventByTypes_1 = require("./getLastEventByTypes");
|
|
10
11
|
const introduceGdpr_1 = require("./introduceGdpr");
|
|
11
12
|
const invalidateGdpr_1 = require("./invalidateGdpr");
|
|
13
|
+
const publish_1 = require("./publish");
|
|
12
14
|
const stream_1 = require("./stream");
|
|
13
15
|
const subscribe_1 = require("./subscribe");
|
|
14
|
-
const getLastEvent_1 = require("./getLastEvent");
|
|
15
|
-
const getLastEventByTypes_1 = require("./getLastEventByTypes");
|
|
16
16
|
const newClient = async (config) => {
|
|
17
17
|
config = (0, config_1.useConfigDefaults)(config);
|
|
18
18
|
const serviceClient = new management_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
|
package/dist/client/publish.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublishEvent } from "./event";
|
|
2
1
|
import { PublishEvent as ProtobufPublishEvent, ServiceClient } from "@fraym/proto/freym/streams/management";
|
|
2
|
+
import { PublishEvent } from "./event";
|
|
3
3
|
export declare const sendPublish: (topic: string, events: PublishEvent[], serviceClient: ServiceClient) => Promise<void>;
|
|
4
4
|
export declare const getProtobufPublishEventFromPublishedEvent: (event: PublishEvent) => ProtobufPublishEvent;
|
package/dist/client/stream.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HandlerFunc, PublishEvent } from "./event";
|
|
2
1
|
import { ServiceClient } from "@fraym/proto/freym/streams/management";
|
|
2
|
+
import { HandlerFunc, PublishEvent } from "./event";
|
|
3
3
|
import { StopLoadingMoreFunc } from "./util";
|
|
4
4
|
export declare const getStream: (topic: string, tenantId: string, stream: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
5
5
|
export declare const getStreamAfterEvent: (topic: string, tenantId: string, stream: string, eventId: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
package/dist/client/stream.js
CHANGED
|
@@ -2,34 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStreamSnapshot = exports.isStreamEmpty = exports.getStreamAfterEvent = exports.getStream = void 0;
|
|
4
4
|
const event_1 = require("./event");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
5
|
const publish_1 = require("./publish");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
7
|
const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let events = [];
|
|
8
|
+
let page = 0;
|
|
9
|
+
let snapshotEventId = null;
|
|
11
10
|
while (true) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
possibleSnapshotEventId = events[0].id;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
events = await getStreamPageAfterEvent(topic, tenantId, stream, lastEventId, perPage, 0, serviceClient);
|
|
20
|
-
}
|
|
11
|
+
const response = await getStreamPage(topic, tenantId, stream, perPage, page, snapshotEventId, serviceClient);
|
|
12
|
+
snapshotEventId = response.snapshotEventId;
|
|
13
|
+
page++;
|
|
21
14
|
let lastEvent = null;
|
|
22
|
-
for (const eventData of events) {
|
|
15
|
+
for (const eventData of response.events) {
|
|
23
16
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
24
17
|
if (event) {
|
|
25
|
-
if (lastEventId != null && possibleSnapshotEventId) {
|
|
26
|
-
if (event.id === possibleSnapshotEventId) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
18
|
await handler(event);
|
|
31
19
|
lastEvent = event;
|
|
32
|
-
lastEventId = event.id;
|
|
33
20
|
}
|
|
34
21
|
}
|
|
35
22
|
if (stopLoadingMore(lastEvent)) {
|
|
@@ -38,7 +25,7 @@ const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingM
|
|
|
38
25
|
}
|
|
39
26
|
};
|
|
40
27
|
exports.getStream = getStream;
|
|
41
|
-
const getStreamPage = async (topic, tenantId, stream, perPage, page, serviceClient) => {
|
|
28
|
+
const getStreamPage = async (topic, tenantId, stream, perPage, page, snapshotEventId, serviceClient) => {
|
|
42
29
|
return (0, util_1.retry)(() => new Promise((resolve, reject) => {
|
|
43
30
|
serviceClient.paginateStream({
|
|
44
31
|
stream,
|
|
@@ -46,22 +33,25 @@ const getStreamPage = async (topic, tenantId, stream, perPage, page, serviceClie
|
|
|
46
33
|
topic,
|
|
47
34
|
page: page.toString(),
|
|
48
35
|
perPage: perPage.toString(),
|
|
36
|
+
snapshotEventId: snapshotEventId !== null && snapshotEventId !== void 0 ? snapshotEventId : "",
|
|
49
37
|
}, async (error, data) => {
|
|
50
38
|
if (error) {
|
|
51
39
|
reject(error);
|
|
52
40
|
return;
|
|
53
41
|
}
|
|
54
|
-
resolve(data
|
|
42
|
+
resolve(data);
|
|
55
43
|
});
|
|
56
44
|
}));
|
|
57
45
|
};
|
|
58
46
|
const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
59
47
|
let page = 0;
|
|
48
|
+
let snapshotEventId = null;
|
|
60
49
|
while (true) {
|
|
61
|
-
const
|
|
50
|
+
const response = await getStreamPageAfterEvent(topic, tenantId, stream, eventId, perPage, page, snapshotEventId, serviceClient);
|
|
51
|
+
snapshotEventId = response.snapshotEventId;
|
|
62
52
|
page++;
|
|
63
53
|
let lastEvent = null;
|
|
64
|
-
for (const eventData of events) {
|
|
54
|
+
for (const eventData of response.events) {
|
|
65
55
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
66
56
|
if (event) {
|
|
67
57
|
await handler(event);
|
|
@@ -74,7 +64,7 @@ const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, ha
|
|
|
74
64
|
}
|
|
75
65
|
};
|
|
76
66
|
exports.getStreamAfterEvent = getStreamAfterEvent;
|
|
77
|
-
const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage, page, serviceClient) => {
|
|
67
|
+
const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage, page, snapshotEventId, serviceClient) => {
|
|
78
68
|
return (0, util_1.retry)(() => new Promise((resolve, reject) => {
|
|
79
69
|
serviceClient.paginateStreamAfterEventId({
|
|
80
70
|
stream,
|
|
@@ -83,12 +73,13 @@ const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage
|
|
|
83
73
|
eventId,
|
|
84
74
|
page: page.toString(),
|
|
85
75
|
perPage: perPage.toString(),
|
|
76
|
+
snapshotEventId: snapshotEventId !== null && snapshotEventId !== void 0 ? snapshotEventId : "",
|
|
86
77
|
}, async (error, data) => {
|
|
87
78
|
if (error) {
|
|
88
79
|
reject(error);
|
|
89
80
|
return;
|
|
90
81
|
}
|
|
91
|
-
resolve(data
|
|
82
|
+
resolve(data);
|
|
92
83
|
});
|
|
93
84
|
}));
|
|
94
85
|
};
|
|
@@ -109,7 +100,6 @@ const isStreamEmpty = async (topic, tenantId, stream, serviceClient) => {
|
|
|
109
100
|
};
|
|
110
101
|
exports.isStreamEmpty = isStreamEmpty;
|
|
111
102
|
const createStreamSnapshot = async (tenantId, topic, stream, lastSnapshottedEventId, snapshotEvent, serviceClient) => {
|
|
112
|
-
console.log("creating snapshot", tenantId, topic, stream, lastSnapshottedEventId);
|
|
113
103
|
return new Promise((resolve, reject) => {
|
|
114
104
|
serviceClient.createStreamSnapshot({
|
|
115
105
|
topic,
|
package/dist/client/subscribe.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initStream = exports.newSubscription = void 0;
|
|
4
|
-
const constants_1 = require("@grpc/grpc-js/build/src/constants");
|
|
5
4
|
const uuid_1 = require("uuid");
|
|
5
|
+
const constants_1 = require("@grpc/grpc-js/build/src/constants");
|
|
6
6
|
const event_1 = require("./event");
|
|
7
7
|
const newSubscription = (topics, ignoreUnhandledEvents, config, serviceClient) => {
|
|
8
8
|
let stream = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/streams",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/fraym/streams-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"main": "dist/index.js",
|
|
27
27
|
"types": "dist/index.d.ts",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@fraym/proto": "^0.
|
|
30
|
-
"@grpc/grpc-js": "^1.
|
|
31
|
-
"uuid": "^
|
|
29
|
+
"@fraym/proto": "^0.28.2",
|
|
30
|
+
"@grpc/grpc-js": "^1.12.6",
|
|
31
|
+
"uuid": "^11.0.5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@becklyn/prettier": "^1.
|
|
35
|
-
"@types/uuid": "^
|
|
36
|
-
"prettier": "^
|
|
34
|
+
"@becklyn/prettier": "^2.1.1",
|
|
35
|
+
"@types/uuid": "^10.0.0",
|
|
36
|
+
"prettier": "^3.5.0",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^5.7.3"
|
|
39
39
|
},
|
|
40
40
|
"prettier": "@becklyn/prettier"
|
|
41
41
|
}
|