@fraym/streams 0.7.0 → 0.7.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.
- package/README.md +1 -1
- package/dist/client/allEvents.d.ts +3 -2
- package/dist/client/allEvents.js +14 -10
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.js +37 -19
- package/dist/client/event.js +1 -0
- package/dist/client/stream.d.ts +3 -2
- package/dist/client/stream.js +14 -10
- package/dist/client/util.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ A snapshot moves events from the "fast access" database to a "long time storage"
|
|
|
121
121
|
The long time storage will have slower access time.
|
|
122
122
|
Use this if you have topics that have a lot of old events which are not queried regularly.
|
|
123
123
|
|
|
124
|
-
Creating a snapshot will only affect performance. You will not
|
|
124
|
+
Creating a snapshot will only affect performance. You will not lose any of your events.
|
|
125
125
|
|
|
126
126
|
Snapshots can be used to clean up your "fast access" event database and therefore increase performance on new events.
|
|
127
127
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ServiceClient } from "@fraym/proto/freym/streams/management";
|
|
2
2
|
import { HandlerFunc } from "./event";
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
3
|
+
import { StopLoadingMoreFunc } from "./util";
|
|
4
|
+
export declare const getAllEvents: (tenantId: string, topic: string, types: string[], perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
5
|
+
export declare const getAllEventsAfterEvent: (tenantId: string, topic: string, types: string[], eventId: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
package/dist/client/allEvents.js
CHANGED
|
@@ -3,20 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAllEventsAfterEvent = exports.getAllEvents = void 0;
|
|
4
4
|
const event_1 = require("./event");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
-
const getAllEvents = async (tenantId, topic, types, perPage, handler, serviceClient) => {
|
|
6
|
+
const getAllEvents = async (tenantId, topic, types, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
7
7
|
let page = 0;
|
|
8
8
|
while (true) {
|
|
9
9
|
const events = await getEventPage(tenantId, topic, types, perPage, page, serviceClient);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
10
|
+
page++;
|
|
11
|
+
let lastEvent = null;
|
|
13
12
|
for (const eventData of events) {
|
|
14
13
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
15
14
|
if (event) {
|
|
16
15
|
await handler(event);
|
|
16
|
+
lastEvent = event;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
if (stopLoadingMore(lastEvent)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
exports.getAllEvents = getAllEvents;
|
|
@@ -37,20 +39,22 @@ const getEventPage = async (tenantId, topic, types, perPage, page, serviceClient
|
|
|
37
39
|
});
|
|
38
40
|
}));
|
|
39
41
|
};
|
|
40
|
-
const getAllEventsAfterEvent = async (tenantId, topic, types, eventId, perPage, handler, serviceClient) => {
|
|
42
|
+
const getAllEventsAfterEvent = async (tenantId, topic, types, eventId, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
41
43
|
let page = 0;
|
|
42
44
|
while (true) {
|
|
43
45
|
const events = await getEventPageAfterEvent(tenantId, topic, types, eventId, perPage, page, serviceClient);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
46
|
+
page++;
|
|
47
|
+
let lastEvent = null;
|
|
47
48
|
for (const eventData of events) {
|
|
48
49
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
49
50
|
if (event) {
|
|
50
51
|
await handler(event);
|
|
52
|
+
lastEvent = event;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
if (stopLoadingMore(lastEvent)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
};
|
|
56
60
|
exports.getAllEventsAfterEvent = getAllEventsAfterEvent;
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym/streams/management";
|
|
2
1
|
import { ClientConfig } from "./config";
|
|
3
2
|
import { HandlerFunc, PublishEvent, SubscriptionEvent } from "./event";
|
|
4
3
|
import { Subscription } from "./subscribe";
|
|
@@ -13,9 +12,10 @@ export interface Client {
|
|
|
13
12
|
iterateAllEventsAfterEvent: (tenantId: string, topic: string, includedEventTypes: string[], eventId: string, perPage: number, handler: HandlerFunc) => Promise<void>;
|
|
14
13
|
publish: (topic: string, events: PublishEvent[]) => Promise<void>;
|
|
15
14
|
getStreamItarator: (topic: string, tenantId: string, stream: string, perPage: number) => Promise<StreamIterator>;
|
|
15
|
+
getStreamIterator: (topic: string, tenantId: string, stream: string, perPage: number) => Promise<StreamIterator>;
|
|
16
16
|
subscribe: (topics?: string[], ignoreUnhandledEvents?: boolean) => Subscription;
|
|
17
17
|
invalidateGdprData: (tenantId: string, topic: string, gdprId: string) => Promise<void>;
|
|
18
|
-
introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string
|
|
18
|
+
introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string) => Promise<void>;
|
|
19
19
|
close: () => void;
|
|
20
20
|
}
|
|
21
21
|
export declare const newClient: (config: ClientConfig) => Promise<Client>;
|
package/dist/client/client.js
CHANGED
|
@@ -19,35 +19,53 @@ const newClient = async (config) => {
|
|
|
19
19
|
"grpc.keepalive_permit_without_calls": 1,
|
|
20
20
|
});
|
|
21
21
|
const closeFunctions = [];
|
|
22
|
+
const getStreamIterator = async (topic, tenantId, stream, perPage) => {
|
|
23
|
+
return {
|
|
24
|
+
forEach: async (callback) => {
|
|
25
|
+
const now = new Date(new Date().getTime() + 3000);
|
|
26
|
+
return await (0, stream_1.getStream)(topic, tenantId, stream, perPage, async (event) => {
|
|
27
|
+
callback(event);
|
|
28
|
+
}, (lastEvent) => {
|
|
29
|
+
return !lastEvent || lastEvent.raisedAt > now;
|
|
30
|
+
}, serviceClient);
|
|
31
|
+
},
|
|
32
|
+
forEachAfterEvent: async (eventId, callback) => {
|
|
33
|
+
const now = new Date(new Date().getTime() + 3000);
|
|
34
|
+
return await (0, stream_1.getStreamAfterEvent)(topic, tenantId, stream, eventId, perPage, async (event) => {
|
|
35
|
+
callback(event);
|
|
36
|
+
}, (lastEvent) => {
|
|
37
|
+
return !lastEvent || lastEvent.raisedAt > now;
|
|
38
|
+
}, serviceClient);
|
|
39
|
+
},
|
|
40
|
+
isEmpty: async () => {
|
|
41
|
+
return (0, stream_1.isStreamEmpty)(topic, tenantId, stream, serviceClient);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
22
45
|
return {
|
|
23
46
|
getEvent: async (tenantId, topic, eventId) => {
|
|
24
47
|
return await (0, getEvent_1.getEvent)(tenantId, topic, eventId, serviceClient);
|
|
25
48
|
},
|
|
26
49
|
iterateAllEvents: async (tenantId, topic, includedEventTypes, perPage, handler) => {
|
|
27
|
-
|
|
50
|
+
const now = new Date(new Date().getTime() + 3000);
|
|
51
|
+
await (0, allEvents_1.getAllEvents)(tenantId, topic, includedEventTypes, perPage, handler, (lastEvent) => {
|
|
52
|
+
return !lastEvent || lastEvent.raisedAt > now;
|
|
53
|
+
}, serviceClient);
|
|
28
54
|
},
|
|
29
55
|
iterateAllEventsAfterEvent: async (tenantId, topic, includedEventTypes, eventId, perPage, handler) => {
|
|
30
|
-
|
|
56
|
+
const now = new Date(new Date().getTime() + 3000);
|
|
57
|
+
await (0, allEvents_1.getAllEventsAfterEvent)(tenantId, topic, includedEventTypes, eventId, perPage, handler, (lastEvent) => {
|
|
58
|
+
return !lastEvent || lastEvent.raisedAt > now;
|
|
59
|
+
}, serviceClient);
|
|
31
60
|
},
|
|
32
61
|
publish: async (topic, events) => {
|
|
33
|
-
return (0, publish_1.sendPublish)(topic, events, serviceClient);
|
|
62
|
+
return await (0, publish_1.sendPublish)(topic, events, serviceClient);
|
|
34
63
|
},
|
|
35
64
|
getStreamItarator: async (topic, tenantId, stream, perPage) => {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, serviceClient);
|
|
41
|
-
},
|
|
42
|
-
forEachAfterEvent: async (eventId, callback) => {
|
|
43
|
-
return await (0, stream_1.getStreamAfterEvent)(topic, tenantId, stream, eventId, perPage, async (event) => {
|
|
44
|
-
callback(event);
|
|
45
|
-
}, serviceClient);
|
|
46
|
-
},
|
|
47
|
-
isEmpty: async () => {
|
|
48
|
-
return (0, stream_1.isStreamEmpty)(topic, tenantId, stream, serviceClient);
|
|
49
|
-
},
|
|
50
|
-
};
|
|
65
|
+
return await getStreamIterator(topic, tenantId, stream, perPage);
|
|
66
|
+
},
|
|
67
|
+
getStreamIterator: async (topic, tenantId, stream, perPage) => {
|
|
68
|
+
return await getStreamIterator(topic, tenantId, stream, perPage);
|
|
51
69
|
},
|
|
52
70
|
subscribe: (topics = [], ignoreUnhandledEvents = false) => {
|
|
53
71
|
const subscription = (0, subscribe_1.newSubscription)(topics, ignoreUnhandledEvents, config, serviceClient);
|
|
@@ -55,7 +73,7 @@ const newClient = async (config) => {
|
|
|
55
73
|
return subscription;
|
|
56
74
|
},
|
|
57
75
|
introduceGdprOnEventField: async (tenantId, defaultValue, topic, eventId, fieldName) => {
|
|
58
|
-
return (0, introduceGdpr_1.introduceGdprOnEventField)(tenantId, defaultValue, topic, eventId, fieldName, serviceClient);
|
|
76
|
+
return await (0, introduceGdpr_1.introduceGdprOnEventField)(tenantId, defaultValue, topic, eventId, fieldName, serviceClient);
|
|
59
77
|
},
|
|
60
78
|
invalidateGdprData: async (tenantId, topic, gdprId) => {
|
|
61
79
|
return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
|
package/dist/client/event.js
CHANGED
|
@@ -16,6 +16,7 @@ const getSubscriptionEvent = (event) => {
|
|
|
16
16
|
const data = event.payload[key];
|
|
17
17
|
if (data.gdpr) {
|
|
18
18
|
payload[key] = {
|
|
19
|
+
id: data.gdpr.id,
|
|
19
20
|
value: JSON.parse(data.value),
|
|
20
21
|
gdprDefault: data.gdpr.default ? JSON.parse(data.gdpr.default) : "",
|
|
21
22
|
isInvalidated: data.gdpr.isInvalidated,
|
package/dist/client/stream.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HandlerFunc } from "./event";
|
|
2
2
|
import { ServiceClient } from "@fraym/proto/freym/streams/management";
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
3
|
+
import { StopLoadingMoreFunc } from "./util";
|
|
4
|
+
export declare const getStream: (topic: string, tenantId: string, stream: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
5
|
+
export declare const getStreamAfterEvent: (topic: string, tenantId: string, stream: string, eventId: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
5
6
|
export declare const isStreamEmpty: (topic: string, tenantId: string, stream: string, serviceClient: ServiceClient) => Promise<boolean>;
|
package/dist/client/stream.js
CHANGED
|
@@ -3,20 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isStreamEmpty = exports.getStreamAfterEvent = exports.getStream = void 0;
|
|
4
4
|
const event_1 = require("./event");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
-
const getStream = async (topic, tenantId, stream, perPage, handler, serviceClient) => {
|
|
6
|
+
const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
7
7
|
let page = 0;
|
|
8
8
|
while (true) {
|
|
9
9
|
const events = await getStreamPage(topic, tenantId, stream, perPage, page, serviceClient);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
10
|
+
page++;
|
|
11
|
+
let lastEvent = null;
|
|
13
12
|
for (const eventData of events) {
|
|
14
13
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
15
14
|
if (event) {
|
|
16
15
|
await handler(event);
|
|
16
|
+
lastEvent = event;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
if (stopLoadingMore(lastEvent)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
exports.getStream = getStream;
|
|
@@ -37,20 +39,22 @@ const getStreamPage = async (topic, tenantId, stream, perPage, page, serviceClie
|
|
|
37
39
|
});
|
|
38
40
|
}));
|
|
39
41
|
};
|
|
40
|
-
const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, handler, serviceClient) => {
|
|
42
|
+
const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
41
43
|
let page = 0;
|
|
42
44
|
while (true) {
|
|
43
45
|
const events = await getStreamPageAfterEvent(topic, tenantId, stream, eventId, perPage, page, serviceClient);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
46
|
+
page++;
|
|
47
|
+
let lastEvent = null;
|
|
47
48
|
for (const eventData of events) {
|
|
48
49
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
49
50
|
if (event) {
|
|
50
51
|
await handler(event);
|
|
52
|
+
lastEvent = event;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
if (stopLoadingMore(lastEvent)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
};
|
|
56
60
|
exports.getStreamAfterEvent = getStreamAfterEvent;
|
package/dist/client/util.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { SubscriptionEvent } from "client/event";
|
|
1
2
|
export declare const sleep: (delay: number) => Promise<void>;
|
|
2
3
|
export declare const retry: <T extends unknown>(fn: () => Promise<T>, pause?: number, retries?: number) => Promise<T>;
|
|
4
|
+
export type StopLoadingMoreFunc = (lastEvent: SubscriptionEvent | null) => boolean;
|