@fraym/streams 0.1.8 → 0.2.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/dist/client/client.js +3 -3
- package/dist/client/init.d.ts +2 -2
- package/dist/client/init.js +1 -1
- package/dist/client/invalidateGdpr.d.ts +2 -3
- package/dist/client/invalidateGdpr.js +11 -41
- package/dist/client/publish.d.ts +2 -3
- package/dist/client/publish.js +9 -36
- package/dist/client/snapshot.d.ts +2 -3
- package/dist/client/snapshot.js +9 -44
- package/package.json +3 -3
package/dist/client/client.js
CHANGED
|
@@ -43,13 +43,13 @@ const newClient = async (config) => {
|
|
|
43
43
|
return await (0, subscribe_1.sendSubscribe)(includedTopics, excludedTopics, config, stream);
|
|
44
44
|
},
|
|
45
45
|
publish: async (topic, events) => {
|
|
46
|
-
return (0, publish_1.sendPublish)(topic, events,
|
|
46
|
+
return (0, publish_1.sendPublish)(topic, events, serviceClient);
|
|
47
47
|
},
|
|
48
48
|
invalidateGdprData: async (tenantId, topic, gdprId) => {
|
|
49
|
-
return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId,
|
|
49
|
+
return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
|
|
50
50
|
},
|
|
51
51
|
createSnapshot: async (topic, toTime) => {
|
|
52
|
-
return await (0, snapshot_1.sendSnapshot)(topic, toTime,
|
|
52
|
+
return await (0, snapshot_1.sendSnapshot)(topic, toTime, serviceClient);
|
|
53
53
|
},
|
|
54
54
|
close: () => {
|
|
55
55
|
stream.end();
|
package/dist/client/init.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientConfig } from "./config";
|
|
2
2
|
import { ClientDuplexStream } from "@grpc/grpc-js";
|
|
3
|
-
import {
|
|
4
|
-
export type Stream = ClientDuplexStream<
|
|
3
|
+
import { SubscribeRequest, ServiceClient, SubscribeResponse } from "@fraym/streams-proto";
|
|
4
|
+
export type Stream = ClientDuplexStream<SubscribeRequest, SubscribeResponse>;
|
|
5
5
|
export declare const initStream: (config: ClientConfig, serviceClient: ServiceClient) => Promise<Stream>;
|
package/dist/client/init.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initStream = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const initStream = async (config, serviceClient) => {
|
|
6
|
-
const stream = serviceClient.
|
|
6
|
+
const stream = serviceClient.subscribe();
|
|
7
7
|
stream.on("end", stream.end);
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
stream.once("data", (data) => {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const sendInvalidateGdpr: (tenantId: string, topic: string, gdprId: string, config: ClientConfig, stream: Stream) => Promise<void>;
|
|
1
|
+
import { ServiceClient } from "@fraym/streams-proto";
|
|
2
|
+
export declare const sendInvalidateGdpr: (tenantId: string, topic: string, gdprId: string, serviceClient: ServiceClient) => Promise<void>;
|
|
@@ -1,49 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendInvalidateGdpr = void 0;
|
|
4
|
-
const sendInvalidateGdpr = async (tenantId, topic, gdprId,
|
|
5
|
-
stream.write(newInvalidateGdprRequest(tenantId, topic, gdprId));
|
|
4
|
+
const sendInvalidateGdpr = async (tenantId, topic, gdprId, serviceClient) => {
|
|
6
5
|
return new Promise((resolve, reject) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (notAck.tenantId === tenantId &&
|
|
16
|
-
notAck.topic === topic &&
|
|
17
|
-
notAck.gdprId === gdprId) {
|
|
18
|
-
clearTimeout(timeout);
|
|
19
|
-
stream.off("data", fn);
|
|
20
|
-
reject(`did receive invalidate gdpr not ack message, reason: ${notAck.reason}`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
6
|
+
serviceClient.invalidateGdpr({
|
|
7
|
+
tenantId,
|
|
8
|
+
topic,
|
|
9
|
+
gdprId,
|
|
10
|
+
}, error => {
|
|
11
|
+
if (error) {
|
|
12
|
+
reject(error.message);
|
|
13
|
+
return;
|
|
23
14
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (ack.tenantId === tenantId && ack.topic === topic && ack.gdprId === gdprId) {
|
|
27
|
-
clearTimeout(timeout);
|
|
28
|
-
stream.off("data", fn);
|
|
29
|
-
resolve();
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
stream.on("data", fn);
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
35
17
|
});
|
|
36
18
|
};
|
|
37
19
|
exports.sendInvalidateGdpr = sendInvalidateGdpr;
|
|
38
|
-
const newInvalidateGdprRequest = (tenantId, topic, gdprId) => {
|
|
39
|
-
return {
|
|
40
|
-
payload: {
|
|
41
|
-
$case: "invalidateGdpr",
|
|
42
|
-
invalidateGdpr: {
|
|
43
|
-
tenantId,
|
|
44
|
-
topic,
|
|
45
|
-
gdprId,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
};
|
package/dist/client/publish.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Stream } from "./init";
|
|
2
|
-
import { ClientConfig } from "./config";
|
|
3
1
|
import { PublishEvent } from "./event";
|
|
4
|
-
|
|
2
|
+
import { ServiceClient } from "@fraym/streams-proto";
|
|
3
|
+
export declare const sendPublish: (topic: string, events: PublishEvent[], serviceClient: ServiceClient) => Promise<void>;
|
package/dist/client/publish.js
CHANGED
|
@@ -1,48 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendPublish = void 0;
|
|
4
|
-
const
|
|
5
|
-
const sendPublish = async (topic, events, config, stream) => {
|
|
6
|
-
const publishActionId = (0, uuid_1.v4)();
|
|
7
|
-
stream.write(newPublishRequest(publishActionId, topic, events));
|
|
4
|
+
const sendPublish = async (topic, events, serviceClient) => {
|
|
8
5
|
return new Promise((resolve, reject) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (((_a = data.data) === null || _a === void 0 ? void 0 : _a.$case) === "publishAck" &&
|
|
16
|
-
data.data.publishAck.publishActionId === publishActionId) {
|
|
17
|
-
clearTimeout(timeout);
|
|
18
|
-
stream.off("data", fn);
|
|
19
|
-
resolve();
|
|
6
|
+
serviceClient.publish({
|
|
7
|
+
events: events.map(getEventEnvelopeFromPublishedEvent),
|
|
8
|
+
topic,
|
|
9
|
+
}, error => {
|
|
10
|
+
if (error) {
|
|
11
|
+
reject(error.message);
|
|
20
12
|
return;
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
clearTimeout(timeout);
|
|
25
|
-
stream.off("data", fn);
|
|
26
|
-
reject(`did receive publish not ack message: ${data.data.publishNotAck.reason}`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
stream.on("data", fn);
|
|
14
|
+
resolve();
|
|
15
|
+
});
|
|
31
16
|
});
|
|
32
17
|
};
|
|
33
18
|
exports.sendPublish = sendPublish;
|
|
34
|
-
const newPublishRequest = (publishActionId, topic, events) => {
|
|
35
|
-
return {
|
|
36
|
-
payload: {
|
|
37
|
-
$case: "publish",
|
|
38
|
-
publish: {
|
|
39
|
-
topic,
|
|
40
|
-
publishActionId,
|
|
41
|
-
events: events.map(getEventEnvelopeFromPublishedEvent),
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
19
|
const getEventEnvelopeFromPublishedEvent = (event) => {
|
|
47
20
|
var _a, _b, _c, _d, _e, _f;
|
|
48
21
|
const payload = {};
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const sendSnapshot: (topic: string, toTime: Date, config: ClientConfig, stream: Stream) => Promise<void>;
|
|
1
|
+
import { ServiceClient } from "@fraym/streams-proto";
|
|
2
|
+
export declare const sendSnapshot: (topic: string, toTime: Date, serviceClient: ServiceClient) => Promise<void>;
|
package/dist/client/snapshot.js
CHANGED
|
@@ -1,53 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendSnapshot = void 0;
|
|
4
|
-
const sendSnapshot = async (topic, toTime,
|
|
5
|
-
stream.write(newSnapshotRequest(topic, toTime));
|
|
4
|
+
const sendSnapshot = async (topic, toTime, serviceClient) => {
|
|
6
5
|
return new Promise((resolve, reject) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (((_a = data.data) === null || _a === void 0 ? void 0 : _a.$case) === "snapshotNotStarted" &&
|
|
14
|
-
data.data.snapshotNotStarted.topic === topic) {
|
|
15
|
-
clearTimeout(timeout);
|
|
16
|
-
stream.off("data", fn);
|
|
17
|
-
reject(`did receive snapshot not started message, reason: ${data.data.snapshotNotStarted.reason}`);
|
|
6
|
+
serviceClient.snapshot({
|
|
7
|
+
topic,
|
|
8
|
+
toTime: toTime.toISOString(),
|
|
9
|
+
}, error => {
|
|
10
|
+
if (error) {
|
|
11
|
+
reject(error.message);
|
|
18
12
|
return;
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clearTimeout(timeout);
|
|
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);
|
|
35
|
-
resolve();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
stream.on("data", fn);
|
|
14
|
+
resolve();
|
|
15
|
+
});
|
|
40
16
|
});
|
|
41
17
|
};
|
|
42
18
|
exports.sendSnapshot = sendSnapshot;
|
|
43
|
-
const newSnapshotRequest = (topic, toTime) => {
|
|
44
|
-
return {
|
|
45
|
-
payload: {
|
|
46
|
-
$case: "snapshot",
|
|
47
|
-
snapshot: {
|
|
48
|
-
topic,
|
|
49
|
-
toTime: toTime.toISOString(),
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/streams",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"homepage": "https://github.com/fraym/streams-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"types": "dist/index.d.ts",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@fraym/streams-proto": "^
|
|
28
|
-
"@grpc/grpc-js": "1.8.7",
|
|
27
|
+
"@fraym/streams-proto": "^7.0.0-alpha.1",
|
|
28
|
+
"@grpc/grpc-js": "^1.8.7",
|
|
29
29
|
"ts-node": "^10.9.1",
|
|
30
30
|
"uuid": "^9.0.0"
|
|
31
31
|
},
|