@fraym/streams 0.10.6 → 0.30.0-alpha.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.
- package/dist/client/allEvents.d.ts +2 -1
- package/dist/client/allEvents.d.ts.map +1 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +6 -6
- package/dist/client/config.d.ts +2 -0
- package/dist/client/config.d.ts.map +1 -0
- package/dist/client/config.js +4 -4
- package/dist/client/event.d.ts +4 -1
- package/dist/client/event.d.ts.map +1 -0
- package/dist/client/event.js +20 -15
- package/dist/client/getEvent.d.ts +2 -1
- package/dist/client/getEvent.d.ts.map +1 -0
- package/dist/client/getLastEvent.d.ts +2 -1
- package/dist/client/getLastEvent.d.ts.map +1 -0
- package/dist/client/getLastEvent.js +1 -1
- package/dist/client/getLastEventByTypes.d.ts +2 -1
- package/dist/client/getLastEventByTypes.d.ts.map +1 -0
- package/dist/client/getLastEventByTypes.js +1 -1
- package/dist/client/introduceGdpr.d.ts +2 -1
- package/dist/client/introduceGdpr.d.ts.map +1 -0
- package/dist/client/invalidateGdpr.d.ts +2 -1
- package/dist/client/invalidateGdpr.d.ts.map +1 -0
- package/dist/client/publish.d.ts +4 -3
- package/dist/client/publish.d.ts.map +1 -0
- package/dist/client/publish.js +12 -11
- package/dist/client/stream.d.ts +5 -4
- package/dist/client/stream.d.ts.map +1 -0
- package/dist/client/stream.js +31 -20
- package/dist/client/subscribe.d.ts +2 -1
- package/dist/client/subscribe.d.ts.map +1 -0
- package/dist/client/subscribe.js +7 -7
- package/dist/client/util.d.ts +2 -1
- package/dist/client/util.d.ts.map +1 -0
- package/dist/client/util.js +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/package.json +11 -19
- package/README.md +0 -140
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { HandlerFunc } from "./event";
|
|
3
3
|
import { StopLoadingMoreFunc } from "./util";
|
|
4
4
|
export declare const getAllEvents: (tenantId: string, topic: string, types: string[], perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
5
5
|
export declare const getAllEventsAfterEvent: (tenantId: string, topic: string, types: string[], eventId: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, serviceClient: ServiceClient) => Promise<void>;
|
|
6
|
+
//# sourceMappingURL=allEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allEvents.d.ts","sourceRoot":"","sources":["../../client/allEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,WAAW,EAA2C,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAS,MAAM,QAAQ,CAAC;AAEpD,eAAO,MAAM,YAAY,aACX,MAAM,SACT,MAAM,SACN,MAAM,EAAE,WACN,MAAM,WACN,WAAW,mBACH,mBAAmB,iBACrB,aAAa,KAC7B,OAAO,CAAC,IAAI,CAkCd,CAAC;AAkCF,eAAO,MAAM,sBAAsB,aACrB,MAAM,SACT,MAAM,SACN,MAAM,EAAE,WACN,MAAM,WACN,MAAM,WACN,WAAW,mBACH,mBAAmB,iBACrB,aAAa,KAC7B,OAAO,CAAC,IAAI,CA8Bd,CAAC"}
|
package/dist/client/client.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../client/client.ts"],"names":[],"mappings":"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"}
|
package/dist/client/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.newClient = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_freym_streams_management_1 = require("@fraym/proto/dist/index.freym.streams.management");
|
|
5
5
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
6
6
|
const allEvents_1 = require("./allEvents");
|
|
7
7
|
const config_1 = require("./config");
|
|
@@ -15,7 +15,7 @@ const stream_1 = require("./stream");
|
|
|
15
15
|
const subscribe_1 = require("./subscribe");
|
|
16
16
|
const newClient = async (config) => {
|
|
17
17
|
config = (0, config_1.useConfigDefaults)(config);
|
|
18
|
-
const serviceClient = new
|
|
18
|
+
const serviceClient = new index_freym_streams_management_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
|
|
19
19
|
"grpc.keepalive_time_ms": config.keepaliveInterval,
|
|
20
20
|
"grpc.keepalive_timeout_ms": config.keepaliveTimeout,
|
|
21
21
|
"grpc.keepalive_permit_without_calls": 1,
|
|
@@ -48,7 +48,7 @@ const newClient = async (config) => {
|
|
|
48
48
|
}
|
|
49
49
|
return await (0, stream_1.getStream)(topic, tenantId, stream, perPage, async (event) => {
|
|
50
50
|
callback(event);
|
|
51
|
-
}, lastEventCheck, serviceClient);
|
|
51
|
+
}, lastEventCheck, config.deploymentId ?? null, serviceClient);
|
|
52
52
|
},
|
|
53
53
|
forEachAfterEvent: async (eventId, callback) => {
|
|
54
54
|
const lastEventCheck = await getLastEventCheck(tenantId, topic);
|
|
@@ -57,7 +57,7 @@ const newClient = async (config) => {
|
|
|
57
57
|
}
|
|
58
58
|
return await (0, stream_1.getStreamAfterEvent)(topic, tenantId, stream, eventId, perPage, async (event) => {
|
|
59
59
|
callback(event);
|
|
60
|
-
}, lastEventCheck, serviceClient);
|
|
60
|
+
}, lastEventCheck, config.deploymentId ?? null, serviceClient);
|
|
61
61
|
},
|
|
62
62
|
isEmpty: async () => {
|
|
63
63
|
return (0, stream_1.isStreamEmpty)(topic, tenantId, stream, serviceClient);
|
|
@@ -89,7 +89,7 @@ const newClient = async (config) => {
|
|
|
89
89
|
await (0, allEvents_1.getAllEventsAfterEvent)(tenantId, topic, includedEventTypes, eventId, perPage, handler, lastEventCheck, serviceClient);
|
|
90
90
|
},
|
|
91
91
|
publish: async (topic, events) => {
|
|
92
|
-
return await (0, publish_1.sendPublish)(topic, events, serviceClient);
|
|
92
|
+
return await (0, publish_1.sendPublish)(topic, events, config.deploymentId ?? null, serviceClient);
|
|
93
93
|
},
|
|
94
94
|
getStreamItarator: async (topic, tenantId, stream, perPage) => {
|
|
95
95
|
return await getStreamIterator(topic, tenantId, stream, perPage);
|
|
@@ -109,7 +109,7 @@ const newClient = async (config) => {
|
|
|
109
109
|
return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
|
|
110
110
|
},
|
|
111
111
|
createStreamSnapshot: async (tenantId, topic, stream, idOfLastEventThatGotSnapshotted, snapshotEvent) => {
|
|
112
|
-
return await (0, stream_1.createStreamSnapshot)(tenantId, topic, stream, idOfLastEventThatGotSnapshotted, snapshotEvent, serviceClient);
|
|
112
|
+
return await (0, stream_1.createStreamSnapshot)(tenantId, topic, stream, idOfLastEventThatGotSnapshotted, snapshotEvent, config.deploymentId ?? null, serviceClient);
|
|
113
113
|
},
|
|
114
114
|
close: () => {
|
|
115
115
|
closeFunctions.forEach(close => close());
|
package/dist/client/config.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export interface ClientConfig {
|
|
2
2
|
serverAddress: string;
|
|
3
3
|
groupId: string;
|
|
4
|
+
deploymentId?: number | null;
|
|
4
5
|
ackTimeout?: number;
|
|
5
6
|
keepaliveInterval?: number;
|
|
6
7
|
keepaliveTimeout?: number;
|
|
7
8
|
}
|
|
8
9
|
export declare const useConfigDefaults: (config: ClientConfig) => Required<ClientConfig>;
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAEzB,aAAa,EAAE,MAAM,CAAC;IAEtB,OAAO,EAAE,MAAM,CAAC;IAEhB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,iBAAiB,WAAY,YAAY,KAAG,QAAQ,CAAC,YAAY,CAS7E,CAAC"}
|
package/dist/client/config.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useConfigDefaults = void 0;
|
|
4
4
|
const useConfigDefaults = (config) => {
|
|
5
|
-
var _a, _b, _c;
|
|
6
5
|
return {
|
|
7
6
|
serverAddress: config.serverAddress,
|
|
8
7
|
groupId: config.groupId,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
deploymentId: config.deploymentId || null,
|
|
9
|
+
ackTimeout: config.ackTimeout ?? 1000,
|
|
10
|
+
keepaliveTimeout: config.keepaliveTimeout ?? 3 * 1000,
|
|
11
|
+
keepaliveInterval: config.keepaliveInterval ?? 40 * 1000,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
exports.useConfigDefaults = useConfigDefaults;
|
package/dist/client/event.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Event } from "@fraym/proto/freym
|
|
1
|
+
import { Event } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
export interface SubscriptionEvent extends BaseEvent {
|
|
3
3
|
topic: string;
|
|
4
4
|
raisedAt: Date;
|
|
5
5
|
orderSerial?: number;
|
|
6
|
+
deploymentId?: number;
|
|
6
7
|
}
|
|
7
8
|
export interface PublishEvent extends BaseEvent {
|
|
8
9
|
broadcast?: boolean;
|
|
@@ -16,6 +17,7 @@ export interface BaseEvent {
|
|
|
16
17
|
correlationId?: string;
|
|
17
18
|
causationId?: string;
|
|
18
19
|
reason?: string;
|
|
20
|
+
userId?: string;
|
|
19
21
|
}
|
|
20
22
|
export type EventData = any | GdprEventData;
|
|
21
23
|
export interface GdprEventData {
|
|
@@ -27,3 +29,4 @@ export interface GdprEventData {
|
|
|
27
29
|
export declare const isGdprEventData: (value: EventData) => value is GdprEventData;
|
|
28
30
|
export type HandlerFunc = (event: SubscriptionEvent) => Promise<void>;
|
|
29
31
|
export declare const getSubscriptionEvent: (event: Event) => SubscriptionEvent | null;
|
|
32
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../client/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kDAAkD,CAAC;AAEzE,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,aAAa,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,GAAG,CAAC;IAEX,WAAW,EAAE,GAAG,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,eAAe,UAAW,SAAS,KAAG,KAAK,IAAI,aAQ3D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,UAAW,KAAK,KAAG,iBAAiB,GAAG,IAwCvE,CAAC"}
|
package/dist/client/event.js
CHANGED
|
@@ -5,26 +5,27 @@ const isGdprEventData = (value) => {
|
|
|
5
5
|
return (value &&
|
|
6
6
|
typeof value === "object" &&
|
|
7
7
|
Object.keys(value).length == 2 &&
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Object.prototype.hasOwnProperty.call(value, "value") &&
|
|
9
|
+
Object.prototype.hasOwnProperty.call(value, "gdprDefault"));
|
|
10
10
|
};
|
|
11
11
|
exports.isGdprEventData = isGdprEventData;
|
|
12
12
|
const getSubscriptionEvent = (event) => {
|
|
13
13
|
const payload = {};
|
|
14
14
|
for (const key in event.payload) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const data = event.payload[key];
|
|
16
|
+
if (data === undefined) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (data.gdpr) {
|
|
20
|
+
payload[key] = {
|
|
21
|
+
id: data.gdpr.id,
|
|
22
|
+
value: JSON.parse(data.value),
|
|
23
|
+
gdprDefault: data.gdpr.default ? JSON.parse(data.gdpr.default) : "",
|
|
24
|
+
isInvalidated: data.gdpr.isInvalidated,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
payload[key] = JSON.parse(data.value);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
return {
|
|
@@ -39,6 +40,10 @@ const getSubscriptionEvent = (event) => {
|
|
|
39
40
|
correlationId: event.metadata ? event.metadata.correlationId : undefined,
|
|
40
41
|
reason: event.reason || undefined,
|
|
41
42
|
orderSerial: event.metadata ? parseInt(event.metadata.orderSerial) : undefined,
|
|
43
|
+
deploymentId: event.metadata && event.metadata.deploymentId
|
|
44
|
+
? parseInt(event.metadata.deploymentId)
|
|
45
|
+
: undefined,
|
|
46
|
+
userId: event.metadata ? event.metadata.userId || undefined : undefined,
|
|
42
47
|
};
|
|
43
48
|
};
|
|
44
49
|
exports.getSubscriptionEvent = getSubscriptionEvent;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { SubscriptionEvent } from "./event";
|
|
3
3
|
export declare const getEvent: (tenantId: string, topic: string, eventId: string, serviceClient: ServiceClient) => Promise<SubscriptionEvent>;
|
|
4
|
+
//# sourceMappingURL=getEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEvent.d.ts","sourceRoot":"","sources":["../../client/getEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAwB,MAAM,SAAS,CAAC;AAGlE,eAAO,MAAM,QAAQ,aACP,MAAM,SACT,MAAM,WACJ,MAAM,iBACA,aAAa,+BA4B/B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { SubscriptionEvent } from "./event";
|
|
3
3
|
export declare const getLastEvent: (tenantId: string, topic: string, serviceClient: ServiceClient) => Promise<SubscriptionEvent | null>;
|
|
4
|
+
//# sourceMappingURL=getLastEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLastEvent.d.ts","sourceRoot":"","sources":["../../client/getLastEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAwB,MAAM,SAAS,CAAC;AAGlE,eAAO,MAAM,YAAY,aACX,MAAM,SACT,MAAM,iBACE,aAAa,sCAgC/B,CAAC"}
|
|
@@ -9,7 +9,7 @@ const getLastEvent = async (tenantId, topic, serviceClient) => {
|
|
|
9
9
|
tenantId,
|
|
10
10
|
topic,
|
|
11
11
|
}, (error, response) => {
|
|
12
|
-
if (error
|
|
12
|
+
if (error?.details.includes("unable to find last event")) {
|
|
13
13
|
resolve(null);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { SubscriptionEvent } from "./event";
|
|
3
3
|
export declare const getLastEventByTypes: (tenantId: string, topic: string, types: string[], serviceClient: ServiceClient) => Promise<SubscriptionEvent | null>;
|
|
4
|
+
//# sourceMappingURL=getLastEventByTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLastEventByTypes.d.ts","sourceRoot":"","sources":["../../client/getLastEventByTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAwB,MAAM,SAAS,CAAC;AAGlE,eAAO,MAAM,mBAAmB,aAClB,MAAM,SACT,MAAM,SACN,MAAM,EAAE,iBACA,aAAa,sCAiC/B,CAAC"}
|
|
@@ -10,7 +10,7 @@ const getLastEventByTypes = async (tenantId, topic, types, serviceClient) => {
|
|
|
10
10
|
topic,
|
|
11
11
|
types,
|
|
12
12
|
}, (error, response) => {
|
|
13
|
-
if (error
|
|
13
|
+
if (error?.details.includes("unable to find last event by types")) {
|
|
14
14
|
resolve(null);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
export declare const introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
|
|
3
|
+
//# sourceMappingURL=introduceGdpr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introduceGdpr.d.ts","sourceRoot":"","sources":["../../client/introduceGdpr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAGjF,eAAO,MAAM,yBAAyB,aACxB,MAAM,gBACF,MAAM,SACb,MAAM,WACJ,MAAM,aACJ,MAAM,iBACF,aAAa,kBAwB/B,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
export declare const sendInvalidateGdpr: (tenantId: string, topic: string, gdprId: string, serviceClient: ServiceClient) => Promise<void>;
|
|
3
|
+
//# sourceMappingURL=invalidateGdpr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidateGdpr.d.ts","sourceRoot":"","sources":["../../client/invalidateGdpr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAGjF,eAAO,MAAM,kBAAkB,aACjB,MAAM,SACT,MAAM,UACL,MAAM,iBACC,aAAa,kBAsB/B,CAAC"}
|
package/dist/client/publish.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PublishEvent as ProtobufPublishEvent, ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { PublishEvent as ProtobufPublishEvent, ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { PublishEvent } from "./event";
|
|
3
|
-
export declare const sendPublish: (topic: string, events: PublishEvent[], serviceClient: ServiceClient) => Promise<void>;
|
|
4
|
-
export declare const getProtobufPublishEventFromPublishedEvent: (event: PublishEvent) => ProtobufPublishEvent;
|
|
3
|
+
export declare const sendPublish: (topic: string, events: PublishEvent[], deploymentId: number | null, serviceClient: ServiceClient) => Promise<void>;
|
|
4
|
+
export declare const getProtobufPublishEventFromPublishedEvent: (event: PublishEvent, deploymentId: number | null) => ProtobufPublishEvent;
|
|
5
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../client/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,IAAI,oBAAoB,EACpC,aAAa,EAChB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAmB,MAAM,SAAS,CAAC;AAGxD,eAAO,MAAM,WAAW,UACb,MAAM,UACL,YAAY,EAAE,gBACR,MAAM,GAAG,IAAI,iBACZ,aAAa,kBAuB/B,CAAC;AAEF,eAAO,MAAM,yCAAyC,UAC3C,YAAY,gBACL,MAAM,GAAG,IAAI,KAC5B,oBAuCF,CAAC"}
|
package/dist/client/publish.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getProtobufPublishEventFromPublishedEvent = exports.sendPublish = void 0;
|
|
4
4
|
const event_1 = require("./event");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
-
const sendPublish = async (topic, events, serviceClient) => {
|
|
6
|
+
const sendPublish = async (topic, events, deploymentId, serviceClient) => {
|
|
7
7
|
return (0, util_1.retry)(() => new Promise((resolve, reject) => {
|
|
8
8
|
serviceClient.publish({
|
|
9
|
-
events: events.map(exports.getProtobufPublishEventFromPublishedEvent),
|
|
9
|
+
events: events.map(event => (0, exports.getProtobufPublishEventFromPublishedEvent)(event, deploymentId)),
|
|
10
10
|
topic,
|
|
11
11
|
}, error => {
|
|
12
12
|
if (error) {
|
|
@@ -18,8 +18,7 @@ const sendPublish = async (topic, events, serviceClient) => {
|
|
|
18
18
|
}));
|
|
19
19
|
};
|
|
20
20
|
exports.sendPublish = sendPublish;
|
|
21
|
-
const getProtobufPublishEventFromPublishedEvent = (event) => {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
21
|
+
const getProtobufPublishEventFromPublishedEvent = (event, deploymentId) => {
|
|
23
22
|
const payload = {};
|
|
24
23
|
for (const key in event.payload) {
|
|
25
24
|
const currentData = event.payload[key];
|
|
@@ -28,7 +27,7 @@ const getProtobufPublishEventFromPublishedEvent = (event) => {
|
|
|
28
27
|
value: JSON.stringify(currentData.value),
|
|
29
28
|
gdpr: {
|
|
30
29
|
default: JSON.stringify(currentData.gdprDefault),
|
|
31
|
-
id:
|
|
30
|
+
id: currentData.id ?? "",
|
|
32
31
|
isInvalidated: false,
|
|
33
32
|
},
|
|
34
33
|
}
|
|
@@ -40,17 +39,19 @@ const getProtobufPublishEventFromPublishedEvent = (event) => {
|
|
|
40
39
|
return {
|
|
41
40
|
id: event.id,
|
|
42
41
|
metadata: {
|
|
43
|
-
causationId:
|
|
44
|
-
correlationId:
|
|
42
|
+
causationId: event.causationId ?? "",
|
|
43
|
+
correlationId: event.correlationId ?? "",
|
|
45
44
|
orderSerial: "0",
|
|
45
|
+
deploymentId: deploymentId?.toString() ?? "",
|
|
46
|
+
userId: event.userId ?? "",
|
|
46
47
|
},
|
|
47
48
|
options: {
|
|
48
|
-
broadcast:
|
|
49
|
+
broadcast: event.broadcast ?? false,
|
|
49
50
|
},
|
|
50
|
-
reason:
|
|
51
|
-
stream:
|
|
51
|
+
reason: event.reason ?? "",
|
|
52
|
+
stream: event.stream ?? "",
|
|
52
53
|
tenantId: event.tenantId,
|
|
53
|
-
type:
|
|
54
|
+
type: event.type ?? "",
|
|
54
55
|
payload,
|
|
55
56
|
};
|
|
56
57
|
};
|
package/dist/client/stream.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ServiceClient } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { HandlerFunc, PublishEvent } from "./event";
|
|
3
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>;
|
|
4
|
+
export declare const getStream: (topic: string, tenantId: string, stream: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, deploymentId: number | null, serviceClient: ServiceClient) => Promise<void>;
|
|
5
|
+
export declare const getStreamAfterEvent: (topic: string, tenantId: string, stream: string, eventId: string, perPage: number, handler: HandlerFunc, stopLoadingMore: StopLoadingMoreFunc, deploymentId: number | null, serviceClient: ServiceClient) => Promise<void>;
|
|
6
6
|
export declare const isStreamEmpty: (topic: string, tenantId: string, stream: string, serviceClient: ServiceClient) => Promise<boolean>;
|
|
7
|
-
export declare const createStreamSnapshot: (tenantId: string, topic: string, stream: string, lastSnapshottedEventId: string, snapshotEvent: PublishEvent, serviceClient: ServiceClient) => Promise<void>;
|
|
7
|
+
export declare const createStreamSnapshot: (tenantId: string, topic: string, stream: string, lastSnapshottedEventId: string, snapshotEvent: PublishEvent, deploymentId: number | null, serviceClient: ServiceClient) => Promise<void>;
|
|
8
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../client/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,YAAY,EAA2C,MAAM,SAAS,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAS,MAAM,QAAQ,CAAC;AAEpD,eAAO,MAAM,SAAS,UACX,MAAM,YACH,MAAM,UACR,MAAM,WACL,MAAM,WACN,WAAW,mBACH,mBAAmB,gBACtB,MAAM,GAAG,IAAI,iBACZ,aAAa,KAC7B,OAAO,CAAC,IAAI,CAsDd,CAAC;AAoCF,eAAO,MAAM,mBAAmB,UACrB,MAAM,YACH,MAAM,UACR,MAAM,WACL,MAAM,WACN,MAAM,WACN,WAAW,mBACH,mBAAmB,gBACtB,MAAM,GAAG,IAAI,iBACZ,aAAa,KAC7B,OAAO,CAAC,IAAI,CA+Bd,CAAC;AAsCF,eAAO,MAAM,aAAa,UACf,MAAM,YACH,MAAM,UACR,MAAM,iBACC,aAAa,KAC7B,OAAO,CAAC,OAAO,CAkBjB,CAAC;AAEF,eAAO,MAAM,oBAAoB,aACnB,MAAM,SACT,MAAM,UACL,MAAM,0BACU,MAAM,iBACf,YAAY,gBACb,MAAM,GAAG,IAAI,iBACZ,aAAa,KAC7B,OAAO,CAAC,IAAI,CAuBd,CAAC"}
|
package/dist/client/stream.js
CHANGED
|
@@ -4,19 +4,32 @@ exports.createStreamSnapshot = exports.isStreamEmpty = exports.getStreamAfterEve
|
|
|
4
4
|
const event_1 = require("./event");
|
|
5
5
|
const publish_1 = require("./publish");
|
|
6
6
|
const util_1 = require("./util");
|
|
7
|
-
const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
8
|
-
let
|
|
9
|
-
let
|
|
7
|
+
const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingMore, deploymentId, serviceClient) => {
|
|
8
|
+
let lastEventId = null;
|
|
9
|
+
let possibleSnapshotEventId = null;
|
|
10
|
+
let events = [];
|
|
10
11
|
while (true) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (!lastEventId) {
|
|
13
|
+
events = await getStreamPage(topic, tenantId, stream, perPage, 0, deploymentId, serviceClient);
|
|
14
|
+
if (events.length > 0) {
|
|
15
|
+
possibleSnapshotEventId = events[0].id;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
events = await getStreamPageAfterEvent(topic, tenantId, stream, lastEventId, perPage, 0, deploymentId, serviceClient);
|
|
20
|
+
}
|
|
14
21
|
let lastEvent = null;
|
|
15
|
-
for (const eventData of
|
|
22
|
+
for (const eventData of events) {
|
|
16
23
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
17
24
|
if (event) {
|
|
25
|
+
if (lastEventId != null && possibleSnapshotEventId) {
|
|
26
|
+
if (event.id === possibleSnapshotEventId) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
18
30
|
await handler(event);
|
|
19
31
|
lastEvent = event;
|
|
32
|
+
lastEventId = event.id;
|
|
20
33
|
}
|
|
21
34
|
}
|
|
22
35
|
if (stopLoadingMore(lastEvent)) {
|
|
@@ -25,7 +38,7 @@ const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingM
|
|
|
25
38
|
}
|
|
26
39
|
};
|
|
27
40
|
exports.getStream = getStream;
|
|
28
|
-
const getStreamPage = async (topic, tenantId, stream, perPage, page,
|
|
41
|
+
const getStreamPage = async (topic, tenantId, stream, perPage, page, deploymentId, serviceClient) => {
|
|
29
42
|
return (0, util_1.retry)(() => new Promise((resolve, reject) => {
|
|
30
43
|
serviceClient.paginateStream({
|
|
31
44
|
stream,
|
|
@@ -33,25 +46,23 @@ const getStreamPage = async (topic, tenantId, stream, perPage, page, snapshotEve
|
|
|
33
46
|
topic,
|
|
34
47
|
page: page.toString(),
|
|
35
48
|
perPage: perPage.toString(),
|
|
36
|
-
|
|
49
|
+
deploymentId: deploymentId?.toString() ?? "",
|
|
37
50
|
}, async (error, data) => {
|
|
38
51
|
if (error) {
|
|
39
52
|
reject(error);
|
|
40
53
|
return;
|
|
41
54
|
}
|
|
42
|
-
resolve(data);
|
|
55
|
+
resolve(data.events);
|
|
43
56
|
});
|
|
44
57
|
}));
|
|
45
58
|
};
|
|
46
|
-
const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, handler, stopLoadingMore, serviceClient) => {
|
|
59
|
+
const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, handler, stopLoadingMore, deploymentId, serviceClient) => {
|
|
47
60
|
let page = 0;
|
|
48
|
-
let snapshotEventId = null;
|
|
49
61
|
while (true) {
|
|
50
|
-
const
|
|
51
|
-
snapshotEventId = response.snapshotEventId;
|
|
62
|
+
const events = await getStreamPageAfterEvent(topic, tenantId, stream, eventId, perPage, page, deploymentId, serviceClient);
|
|
52
63
|
page++;
|
|
53
64
|
let lastEvent = null;
|
|
54
|
-
for (const eventData of
|
|
65
|
+
for (const eventData of events) {
|
|
55
66
|
const event = (0, event_1.getSubscriptionEvent)(eventData);
|
|
56
67
|
if (event) {
|
|
57
68
|
await handler(event);
|
|
@@ -64,7 +75,7 @@ const getStreamAfterEvent = async (topic, tenantId, stream, eventId, perPage, ha
|
|
|
64
75
|
}
|
|
65
76
|
};
|
|
66
77
|
exports.getStreamAfterEvent = getStreamAfterEvent;
|
|
67
|
-
const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage, page,
|
|
78
|
+
const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage, page, deploymentId, serviceClient) => {
|
|
68
79
|
return (0, util_1.retry)(() => new Promise((resolve, reject) => {
|
|
69
80
|
serviceClient.paginateStreamAfterEventId({
|
|
70
81
|
stream,
|
|
@@ -73,13 +84,13 @@ const getStreamPageAfterEvent = async (topic, tenantId, stream, eventId, perPage
|
|
|
73
84
|
eventId,
|
|
74
85
|
page: page.toString(),
|
|
75
86
|
perPage: perPage.toString(),
|
|
76
|
-
|
|
87
|
+
deploymentId: deploymentId?.toString() ?? "",
|
|
77
88
|
}, async (error, data) => {
|
|
78
89
|
if (error) {
|
|
79
90
|
reject(error);
|
|
80
91
|
return;
|
|
81
92
|
}
|
|
82
|
-
resolve(data);
|
|
93
|
+
resolve(data.events);
|
|
83
94
|
});
|
|
84
95
|
}));
|
|
85
96
|
};
|
|
@@ -99,14 +110,14 @@ const isStreamEmpty = async (topic, tenantId, stream, serviceClient) => {
|
|
|
99
110
|
});
|
|
100
111
|
};
|
|
101
112
|
exports.isStreamEmpty = isStreamEmpty;
|
|
102
|
-
const createStreamSnapshot = async (tenantId, topic, stream, lastSnapshottedEventId, snapshotEvent, serviceClient) => {
|
|
113
|
+
const createStreamSnapshot = async (tenantId, topic, stream, lastSnapshottedEventId, snapshotEvent, deploymentId, serviceClient) => {
|
|
103
114
|
return new Promise((resolve, reject) => {
|
|
104
115
|
serviceClient.createStreamSnapshot({
|
|
105
116
|
topic,
|
|
106
117
|
stream,
|
|
107
118
|
tenantId,
|
|
108
119
|
lastSnapshottedEventId,
|
|
109
|
-
snapshotEvent: (0, publish_1.getProtobufPublishEventFromPublishedEvent)(snapshotEvent),
|
|
120
|
+
snapshotEvent: (0, publish_1.getProtobufPublishEventFromPublishedEvent)(snapshotEvent, deploymentId),
|
|
110
121
|
}, error => {
|
|
111
122
|
if (error) {
|
|
112
123
|
reject(error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceClient, SubscribeRequest, SubscribeResponse } from "@fraym/proto/freym
|
|
1
|
+
import { ServiceClient, SubscribeRequest, SubscribeResponse } from "@fraym/proto/dist/index.freym.streams.management";
|
|
2
2
|
import { ClientDuplexStream } from "@grpc/grpc-js";
|
|
3
3
|
import { ClientConfig } from "./config";
|
|
4
4
|
import { HandlerFunc } from "./event";
|
|
@@ -11,3 +11,4 @@ export interface Subscription {
|
|
|
11
11
|
export type Stream = ClientDuplexStream<SubscribeRequest, SubscribeResponse>;
|
|
12
12
|
export declare const newSubscription: (topics: string[], ignoreUnhandledEvents: boolean, config: ClientConfig, serviceClient: ServiceClient) => Subscription;
|
|
13
13
|
export declare const initStream: (topics: string[], config: ClientConfig, stream: Stream) => Promise<Stream>;
|
|
14
|
+
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../client/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACpB,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,WAAW,EAAwB,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,YAAY;IACzB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACzD,qBAAqB,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACtD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;AAE7E,eAAO,MAAM,eAAe,WAChB,MAAM,EAAE,yBACO,OAAO,UACtB,YAAY,iBACL,aAAa,KAC7B,YAoHF,CAAC;AAEF,eAAO,MAAM,UAAU,WACX,MAAM,EAAE,UACR,YAAY,UACZ,MAAM,KACf,OAAO,CAAC,MAAM,CA8BhB,CAAC"}
|
package/dist/client/subscribe.js
CHANGED
|
@@ -26,6 +26,7 @@ const newSubscription = (topics, ignoreUnhandledEvents, config, serviceClient) =
|
|
|
26
26
|
}
|
|
27
27
|
rebuildConnection(newStream, retries - 1);
|
|
28
28
|
});
|
|
29
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
29
30
|
newStream.on("error", (err) => {
|
|
30
31
|
if (closed) {
|
|
31
32
|
return;
|
|
@@ -37,10 +38,9 @@ const newSubscription = (topics, ignoreUnhandledEvents, config, serviceClient) =
|
|
|
37
38
|
rebuildConnection(newStream, retries - 1);
|
|
38
39
|
});
|
|
39
40
|
const dataFn = async (data) => {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
41
41
|
if (!data.payload ||
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
data.payload?.$case === "panic" ||
|
|
43
|
+
data.payload?.$case === "subscribed") {
|
|
44
44
|
newStream.cancel();
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
@@ -48,7 +48,7 @@ const newSubscription = (topics, ignoreUnhandledEvents, config, serviceClient) =
|
|
|
48
48
|
if (!event) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const currentHandlers =
|
|
51
|
+
const currentHandlers = typeHandlerMap[event.type ?? ""] ?? [];
|
|
52
52
|
currentHandlers.push(...globalHandlers);
|
|
53
53
|
if (currentHandlers.length === 0) {
|
|
54
54
|
if (ignoreUnhandledEvents) {
|
|
@@ -108,14 +108,14 @@ const initStream = async (topics, config, stream) => {
|
|
|
108
108
|
metadata: {
|
|
109
109
|
group: config.groupId,
|
|
110
110
|
subscriberId: (0, uuid_1.v4)(),
|
|
111
|
+
deploymentId: config.deploymentId?.toString() ?? "",
|
|
111
112
|
},
|
|
112
113
|
topics,
|
|
113
114
|
},
|
|
114
115
|
},
|
|
115
116
|
});
|
|
116
117
|
stream.once("data", (data) => {
|
|
117
|
-
|
|
118
|
-
if (((_a = data.payload) === null || _a === void 0 ? void 0 : _a.$case) !== "subscribed") {
|
|
118
|
+
if (data.payload?.$case !== "subscribed") {
|
|
119
119
|
reject("connection to streams service was not initialized correctly");
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
@@ -135,7 +135,7 @@ const newHandledRequest = (tenantId, topic, error) => {
|
|
|
135
135
|
handled: {
|
|
136
136
|
tenantId,
|
|
137
137
|
topic,
|
|
138
|
-
error: error
|
|
138
|
+
error: error ?? "",
|
|
139
139
|
},
|
|
140
140
|
},
|
|
141
141
|
};
|
package/dist/client/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SubscriptionEvent } from "client/event";
|
|
2
2
|
export declare const sleep: (delay: number) => Promise<void>;
|
|
3
|
-
export declare const retry: <T
|
|
3
|
+
export declare const retry: <T>(fn: () => Promise<T>, pause?: number, retries?: number) => Promise<T>;
|
|
4
4
|
export type StopLoadingMoreFunc = (lastEvent: SubscriptionEvent | null) => boolean;
|
|
5
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../client/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,eAAO,MAAM,KAAK,UAAW,MAAM,kBAG7B,CAAC;AAEP,eAAO,MAAM,KAAK,GAAU,CAAC,MACrB,MAAM,OAAO,CAAC,CAAC,CAAC,UACb,MAAM,YACJ,MAAM,KAChB,OAAO,CAAC,CAAC,CAaX,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI,KAAK,OAAO,CAAC"}
|
package/dist/client/util.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.sleep = sleep;
|
|
|
9
9
|
const retry = async (fn, pause = 100, retries = 50) => {
|
|
10
10
|
try {
|
|
11
11
|
return await fn();
|
|
12
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
12
13
|
}
|
|
13
14
|
catch (err) {
|
|
14
15
|
if (retries === 0 || (err && err.code && err.code === constants_1.Status.UNKNOWN)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from "./client/client";
|
|
2
|
-
export { HandlerFunc, PublishEvent, SubscriptionEvent, BaseEvent, EventData, GdprEventData, } from "./client/event";
|
|
3
|
-
export { ClientConfig } from "./client/config";
|
|
2
|
+
export type { HandlerFunc, PublishEvent, SubscriptionEvent, BaseEvent, EventData, GdprEventData, } from "./client/event";
|
|
3
|
+
export type { ClientConfig } from "./client/config";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,YAAY,EACR,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,aAAa,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/streams",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0-alpha.18",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"homepage": "https://github.com/fraym/
|
|
5
|
+
"homepage": "https://github.com/fraym/freym-api",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/fraym/
|
|
8
|
+
"url": "git+https://github.com/fraym/freym-api.git"
|
|
9
9
|
},
|
|
10
|
-
"description": "
|
|
10
|
+
"description": "JS client implementation for Freyms streams service",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"build": "npm run clean && tsc",
|
|
16
|
-
"clean": "rm -rf dist",
|
|
17
|
-
"prepublishOnly": "npm test && npm run lint && npm run build",
|
|
18
|
-
"preversion": "npm run lint"
|
|
12
|
+
"build": "rm -rf dist && tsc",
|
|
13
|
+
"lint": "eslint && prettier --check \"**/*.{ts,tsx,json,scss,css}\"",
|
|
14
|
+
"fix": "eslint --fix && prettier --write \"**/*.{ts,tsx,json,scss,css}\""
|
|
19
15
|
},
|
|
20
16
|
"files": [
|
|
21
17
|
"dist/**/*"
|
|
22
18
|
],
|
|
23
19
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
20
|
+
"node": ">=20"
|
|
25
21
|
},
|
|
26
22
|
"main": "dist/index.js",
|
|
27
23
|
"types": "dist/index.d.ts",
|
|
28
24
|
"dependencies": {
|
|
29
|
-
"@fraym/proto": "^0.
|
|
30
|
-
"@grpc/grpc-js": "^1.12.
|
|
25
|
+
"@fraym/proto": "^0.30.0-alpha.18",
|
|
26
|
+
"@grpc/grpc-js": "^1.12.5",
|
|
31
27
|
"uuid": "^11.0.5"
|
|
32
28
|
},
|
|
33
29
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@types/uuid": "^10.0.0",
|
|
36
|
-
"prettier": "^3.5.0",
|
|
37
|
-
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "^5.7.3"
|
|
30
|
+
"@types/uuid": "^10.0.0"
|
|
39
31
|
},
|
|
40
32
|
"prettier": "@becklyn/prettier"
|
|
41
33
|
}
|
package/README.md
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# streams-nodejs
|
|
2
|
-
|
|
3
|
-
Client implementation in javascript for the event streaming service [streams](https://github.com/fraym/streams).
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
npm i @fraym/streams
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### Create the client
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
const client = await newClient({
|
|
17
|
-
serverAddress: "127.0.0.1:9000",
|
|
18
|
-
groupId: "your-services-group-identifier",
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Publish events
|
|
23
|
-
|
|
24
|
-
Events are published in a transactional manner:
|
|
25
|
-
|
|
26
|
-
- you can publish a set of events in a transaction
|
|
27
|
-
- if one event in your set cannot be published no event will be published
|
|
28
|
-
- as soon as all events are published they appear in their streams
|
|
29
|
-
|
|
30
|
-
You can only publish events of one topic per transaction.
|
|
31
|
-
Most of the fields of an event are optional. You do not have to use or specify them, but you can use them if you want to.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
await client.publish("topic", [
|
|
35
|
-
{
|
|
36
|
-
id: uuid(),
|
|
37
|
-
tenantId: "tenantId",
|
|
38
|
-
payload: {
|
|
39
|
-
key: "value",
|
|
40
|
-
object: {
|
|
41
|
-
key: "objectKeyValue"
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
// set `broadcast` to true if you want all subscribers of a group to process the event.
|
|
45
|
-
// set to false (or remove) if you want this event to be handled only once by a group of subscribers.
|
|
46
|
-
broadcast: false,
|
|
47
|
-
type: "event-type",
|
|
48
|
-
stream: "stream-name",
|
|
49
|
-
correlationId: uuid(),
|
|
50
|
-
causationId: uuid(),
|
|
51
|
-
reason: "the reason why this event was triggered",
|
|
52
|
-
},
|
|
53
|
-
]);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Get events of a stream
|
|
57
|
-
|
|
58
|
-
If you want to get all events that belong to a given stream you can do this by calling `getStream``:
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
const streamEvents = await client.getStream("tenantId", "stream");
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Register event handlers for event subscriptions
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
// this handler is called for events of all types
|
|
68
|
-
client.useEventHandlerForAllEventTypes(async (event: SubscriptionEvent) => {
|
|
69
|
-
// @todo: handle the event in this callback
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// this handler is only called for events of the given type "event-type"
|
|
73
|
-
client.useEventHandler("event-type", async (event: SubscriptionEvent) => {
|
|
74
|
-
// @todo: handle the event in this callback
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Subscribe to events
|
|
79
|
-
|
|
80
|
-
You can subscribe to events of all topics by not providing any parameters to the subscribe function:
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
await client.subscribe();
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
You can subscribe to events of a given set of topics by specifying the `includedTopics` list:
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
await client.subscribe(["topic-1", "topic-2"]);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
You can subscribe to all events except of a given set of topics by specifying the `excludedTopics` list:
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
await client.subscribe([], ["topic-1", "topic-2"]);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
One client instance is only able to subscribe once. If you try to subscribe twice you will get an error.
|
|
99
|
-
|
|
100
|
-
### Get all events for a given topic filter
|
|
101
|
-
|
|
102
|
-
The `getAllEvents` function uses the same topic filter parameters as described for the [subscribe](#subscribe-to-events) function
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
await client.getAllEvents(async (event: SubscriptionEvent) => {
|
|
106
|
-
// @todo: handle the event in this callback
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### Invalidate gdpr data
|
|
111
|
-
|
|
112
|
-
You will not need to use this if you use our GDPR service.
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
await client.invalidateGdprData("tenantId", "topic-1", "grprId");
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Create a snapshot of a topic
|
|
119
|
-
|
|
120
|
-
A snapshot moves events from the "fast access" database to a "long time storage".
|
|
121
|
-
The long time storage will have slower access time.
|
|
122
|
-
Use this if you have topics that have a lot of old events which are not queried regularly.
|
|
123
|
-
|
|
124
|
-
Creating a snapshot will only affect performance. You will not lose any of your events.
|
|
125
|
-
|
|
126
|
-
Snapshots can be used to clean up your "fast access" event database and therefore increase performance on new events.
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
await client.createSnapshot("topic-1", new Date());
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
The second parameter is a date. All events that are older than that date will be moved to the snapshot.
|
|
133
|
-
|
|
134
|
-
### Gracefully close the client
|
|
135
|
-
|
|
136
|
-
You won't lose any data if you don't. Use it for your peace of mind.
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
client.close();
|
|
140
|
-
```
|