@fraym/streams 0.1.9 → 0.2.1
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 +3 -35
- package/dist/client/client.js +3 -3
- package/dist/client/event.d.ts +4 -3
- package/dist/client/event.js +14 -5
- 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 +23 -50
- package/dist/client/snapshot.d.ts +2 -3
- package/dist/client/snapshot.js +9 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,6 +37,9 @@ await client.publish("topic", [
|
|
|
37
37
|
tenantId: "tenantId",
|
|
38
38
|
payload: {
|
|
39
39
|
key: "value",
|
|
40
|
+
object: {
|
|
41
|
+
key: "objectKeyValue"
|
|
42
|
+
},
|
|
40
43
|
},
|
|
41
44
|
// set `broadcast` to true if you want all subscribers of a group to process the event.
|
|
42
45
|
// set to false (or remove) if you want this event to be handled only once by a group of subscribers.
|
|
@@ -135,38 +138,3 @@ You won't lose any data if you don't. Use it for your peace of mind.
|
|
|
135
138
|
```typescript
|
|
136
139
|
client.close();
|
|
137
140
|
```
|
|
138
|
-
|
|
139
|
-
## Development
|
|
140
|
-
|
|
141
|
-
You'll need the following apps for a smooth development experience:
|
|
142
|
-
|
|
143
|
-
- minikube
|
|
144
|
-
- lens
|
|
145
|
-
- okteto
|
|
146
|
-
- helm
|
|
147
|
-
|
|
148
|
-
### Running the dev environment
|
|
149
|
-
|
|
150
|
-
- Start minikube if not already done:
|
|
151
|
-
|
|
152
|
-
```shell
|
|
153
|
-
minikube start
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
- add mongodb and minio to your lokal kubernetes
|
|
157
|
-
- use Makefiles in `./.dev/*`
|
|
158
|
-
- copy `.env.build` to `.env.build.local`
|
|
159
|
-
- add your personal access token (needs read access for private fraym org repositories)
|
|
160
|
-
- deploy the app to your cluster
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
make init
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
- start okteto
|
|
167
|
-
|
|
168
|
-
```
|
|
169
|
-
make dev
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
- connect your IDE to that okteto instance
|
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/event.d.ts
CHANGED
|
@@ -16,10 +16,11 @@ export interface BaseEvent {
|
|
|
16
16
|
causationId?: string;
|
|
17
17
|
reason?: string;
|
|
18
18
|
}
|
|
19
|
-
export type EventData =
|
|
19
|
+
export type EventData = any | GdprEventData;
|
|
20
20
|
export interface GdprEventData {
|
|
21
|
-
value:
|
|
22
|
-
gdprDefault:
|
|
21
|
+
value: any;
|
|
22
|
+
gdprDefault: any;
|
|
23
23
|
}
|
|
24
|
+
export declare const isGdprEventData: (value: EventData) => value is GdprEventData;
|
|
24
25
|
export type HandlerFunc = (event: SubscriptionEvent) => Promise<void>;
|
|
25
26
|
export declare const getSubscriptionEvent: (eventEnvelope: PublishEventEnvelope) => SubscriptionEvent | null;
|
package/dist/client/event.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSubscriptionEvent = void 0;
|
|
3
|
+
exports.getSubscriptionEvent = exports.isGdprEventData = void 0;
|
|
4
|
+
const isGdprEventData = (value) => {
|
|
5
|
+
return (value &&
|
|
6
|
+
typeof value === "object" &&
|
|
7
|
+
Object.keys(value).length == 2 &&
|
|
8
|
+
value.hasOwnProperty("value") &&
|
|
9
|
+
value.hasOwnProperty("gdprDefault"));
|
|
10
|
+
};
|
|
11
|
+
exports.isGdprEventData = isGdprEventData;
|
|
4
12
|
const getSubscriptionEvent = (eventEnvelope) => {
|
|
5
|
-
var _a;
|
|
6
13
|
const event = eventEnvelope.event;
|
|
7
14
|
if (!event) {
|
|
8
15
|
return null;
|
|
@@ -13,12 +20,14 @@ const getSubscriptionEvent = (eventEnvelope) => {
|
|
|
13
20
|
const data = event.payload[key];
|
|
14
21
|
if (data.metadata && data.metadata.gdpr) {
|
|
15
22
|
payload[key] = {
|
|
16
|
-
value: data.value,
|
|
17
|
-
gdprDefault:
|
|
23
|
+
value: JSON.parse(data.value),
|
|
24
|
+
gdprDefault: data.metadata.gdpr.default
|
|
25
|
+
? JSON.parse(data.metadata.gdpr.default)
|
|
26
|
+
: "",
|
|
18
27
|
};
|
|
19
28
|
}
|
|
20
29
|
else {
|
|
21
|
-
payload[key] = data.value;
|
|
30
|
+
payload[key] = JSON.parse(data.value);
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
}
|
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,68 +1,41 @@
|
|
|
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,
|
|
6
|
-
const publishActionId = (0, uuid_1.v4)();
|
|
7
|
-
stream.write(newPublishRequest(publishActionId, topic, events));
|
|
4
|
+
const event_1 = require("./event");
|
|
5
|
+
const sendPublish = async (topic, events, serviceClient) => {
|
|
8
6
|
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();
|
|
7
|
+
serviceClient.publish({
|
|
8
|
+
events: events.map(getEventEnvelopeFromPublishedEvent),
|
|
9
|
+
topic,
|
|
10
|
+
}, error => {
|
|
11
|
+
if (error) {
|
|
12
|
+
reject(error.message);
|
|
20
13
|
return;
|
|
21
14
|
}
|
|
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);
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
31
17
|
});
|
|
32
18
|
};
|
|
33
19
|
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
20
|
const getEventEnvelopeFromPublishedEvent = (event) => {
|
|
47
21
|
var _a, _b, _c, _d, _e, _f;
|
|
48
22
|
const payload = {};
|
|
49
23
|
for (const key in event.payload) {
|
|
50
24
|
const currentData = event.payload[key];
|
|
51
|
-
payload[key] =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
$case: "gdpr",
|
|
60
|
-
gdpr: {
|
|
61
|
-
default: currentData.gdprDefault,
|
|
62
|
-
id: "",
|
|
63
|
-
},
|
|
25
|
+
payload[key] = (0, event_1.isGdprEventData)(currentData)
|
|
26
|
+
? {
|
|
27
|
+
value: JSON.stringify(currentData.value),
|
|
28
|
+
metadata: {
|
|
29
|
+
$case: "gdpr",
|
|
30
|
+
gdpr: {
|
|
31
|
+
default: JSON.stringify(currentData.gdprDefault),
|
|
32
|
+
id: "",
|
|
64
33
|
},
|
|
65
|
-
}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
value: JSON.stringify(currentData),
|
|
38
|
+
};
|
|
66
39
|
}
|
|
67
40
|
return {
|
|
68
41
|
broadcast: (_a = event.broadcast) !== null && _a !== void 0 ? _a : false,
|
|
@@ -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.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"homepage": "https://github.com/fraym/streams-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -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": "^7.0.0-alpha.1",
|
|
28
28
|
"@grpc/grpc-js": "^1.8.7",
|
|
29
29
|
"ts-node": "^10.9.1",
|
|
30
30
|
"uuid": "^9.0.0"
|