@fraym/streams 0.7.2 → 0.8.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.
@@ -16,6 +16,7 @@ export interface Client {
16
16
  subscribe: (topics?: string[], ignoreUnhandledEvents?: boolean) => Subscription;
17
17
  invalidateGdprData: (tenantId: string, topic: string, gdprId: string) => Promise<void>;
18
18
  introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string) => Promise<void>;
19
+ createStreamSnapshot: (tenantId: string, topic: string, stream: string, lastSnapshottedEventId: string, snapshotEvent: PublishEvent) => Promise<void>;
19
20
  close: () => void;
20
21
  }
21
22
  export declare const newClient: (config: ClientConfig) => Promise<Client>;
@@ -78,6 +78,10 @@ const newClient = async (config) => {
78
78
  invalidateGdprData: async (tenantId, topic, gdprId) => {
79
79
  return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
80
80
  },
81
+ createStreamSnapshot: async (tenantId, topic, stream, idOfLastEventThatGotSnapshotted, snapshotEvent) => {
82
+ console.log("aaa");
83
+ return await (0, stream_1.createStreamSnapshot)(tenantId, topic, stream, idOfLastEventThatGotSnapshotted, snapshotEvent, serviceClient);
84
+ },
81
85
  close: () => {
82
86
  closeFunctions.forEach(close => close());
83
87
  },
@@ -1,3 +1,4 @@
1
1
  import { PublishEvent } from "./event";
2
- import { ServiceClient } from "@fraym/proto/freym/streams/management";
2
+ import { PublishEvent as ProtobufPublishEvent, ServiceClient } from "@fraym/proto/freym/streams/management";
3
3
  export declare const sendPublish: (topic: string, events: PublishEvent[], serviceClient: ServiceClient) => Promise<void>;
4
+ export declare const getProtobufPublishEventFromPublishedEvent: (event: PublishEvent) => ProtobufPublishEvent;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendPublish = void 0;
3
+ exports.getProtobufPublishEventFromPublishedEvent = exports.sendPublish = void 0;
4
4
  const event_1 = require("./event");
5
5
  const util_1 = require("./util");
6
6
  const sendPublish = async (topic, events, serviceClient) => {
7
7
  return (0, util_1.retry)(() => new Promise((resolve, reject) => {
8
8
  serviceClient.publish({
9
- events: events.map(getProtobufPublishEventFromPublishedEvent),
9
+ events: events.map(exports.getProtobufPublishEventFromPublishedEvent),
10
10
  topic,
11
11
  }, error => {
12
12
  if (error) {
@@ -53,3 +53,4 @@ const getProtobufPublishEventFromPublishedEvent = (event) => {
53
53
  payload,
54
54
  };
55
55
  };
56
+ exports.getProtobufPublishEventFromPublishedEvent = getProtobufPublishEventFromPublishedEvent;
@@ -1,6 +1,7 @@
1
- import { HandlerFunc } from "./event";
1
+ import { HandlerFunc, PublishEvent } from "./event";
2
2
  import { ServiceClient } from "@fraym/proto/freym/streams/management";
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>;
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>;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStreamEmpty = exports.getStreamAfterEvent = exports.getStream = void 0;
3
+ exports.createStreamSnapshot = exports.isStreamEmpty = exports.getStreamAfterEvent = exports.getStream = void 0;
4
4
  const event_1 = require("./event");
5
5
  const util_1 = require("./util");
6
+ const publish_1 = require("./publish");
6
7
  const getStream = async (topic, tenantId, stream, perPage, handler, stopLoadingMore, serviceClient) => {
7
8
  let page = 0;
8
9
  while (true) {
@@ -92,3 +93,22 @@ const isStreamEmpty = async (topic, tenantId, stream, serviceClient) => {
92
93
  });
93
94
  };
94
95
  exports.isStreamEmpty = isStreamEmpty;
96
+ const createStreamSnapshot = async (tenantId, topic, stream, lastSnapshottedEventId, snapshotEvent, serviceClient) => {
97
+ console.log("creating snapshot", tenantId, topic, stream, lastSnapshottedEventId);
98
+ return new Promise((resolve, reject) => {
99
+ serviceClient.createStreamSnapshot({
100
+ topic,
101
+ stream,
102
+ tenantId,
103
+ lastSnapshottedEventId,
104
+ snapshotEvent: (0, publish_1.getProtobufPublishEventFromPublishedEvent)(snapshotEvent),
105
+ }, error => {
106
+ if (error) {
107
+ reject(error);
108
+ return;
109
+ }
110
+ resolve();
111
+ });
112
+ });
113
+ };
114
+ exports.createStreamSnapshot = createStreamSnapshot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/streams",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/fraym/streams-nodejs",
6
6
  "repository": {
@@ -26,8 +26,8 @@
26
26
  "main": "dist/index.js",
27
27
  "types": "dist/index.d.ts",
28
28
  "dependencies": {
29
- "@fraym/proto": "^0.14.0",
30
- "@grpc/grpc-js": "^1.10.0",
29
+ "@fraym/proto": "^0.18.1",
30
+ "@grpc/grpc-js": "^1.11.1",
31
31
  "uuid": "^9.0.1"
32
32
  },
33
33
  "devDependencies": {