@fraym/projections 0.13.0 → 0.14.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 CHANGED
@@ -126,6 +126,17 @@ Fields:
126
126
  - `scopes`: Slice of scopes to use for the action
127
127
  - `data`: Data that is used in directives like `@filterFromJwtData`
128
128
 
129
+ ### Event Metadata
130
+
131
+ You can specify the correlation and causation IDs for the upsert and delete functions. The `eventMetadata` parameter is optional for all these functions and has the following structure:
132
+
133
+ ```typescript
134
+ const eventMetadata = {
135
+ correlationId: "some-correlation-id",
136
+ causationId: "some-causation-id",
137
+ };
138
+ ```
139
+
129
140
  ### Upsert data in projection
130
141
 
131
142
  In general you upsert data by publishing events on the event stream.
@@ -138,7 +149,8 @@ const response = await client.upsertData<{ fieldName: string }>(
138
149
  "dataId",
139
150
  {
140
151
  fieldName: "value",
141
- }
152
+ },
153
+ eventMetadata
142
154
  );
143
155
  ```
144
156
 
@@ -161,13 +173,13 @@ There are cases where you want to improve performance and get detailed validatio
161
173
  Delete by Id:
162
174
 
163
175
  ```go
164
- const numberOfDeletedEntries = await client.deleteDataById("ProjectionName", authData, "dataId")
176
+ const numberOfDeletedEntries = await client.deleteDataById("ProjectionName", authData, "dataId", eventMetadata)
165
177
  ```
166
178
 
167
179
  Delete by filter:
168
180
 
169
181
  ```go
170
- const numberOfDeletedEntries = client.deleteDataByFilter("ProjectionName", authData, filter)
182
+ const numberOfDeletedEntries = client.deleteDataByFilter("ProjectionName", authData, filter, eventMetadata)
171
183
  ```
172
184
 
173
185
  ### Get a single projection element
@@ -199,7 +211,7 @@ const data = await deliveryClient.getData(
199
211
  );
200
212
  ```
201
213
 
202
- ### Get (paginated / filtered) data
214
+ ### Get (paginated / filtered / ordered) data
203
215
 
204
216
  The name of `YourProjection` has to equal your type name in your schema (also in casing).
205
217
 
@@ -4,12 +4,13 @@ import { GetProjectionDataList } from "./getDataList";
4
4
  import { Order } from "./order";
5
5
  import { AuthData } from "./auth";
6
6
  import { UpsertResponse } from "./upsert";
7
+ import { EventMetadata } from "./eventMetadata";
7
8
  export interface DeliveryClient {
8
9
  getData: <T extends {}>(projection: string, authData: AuthData, id: string, filter?: Filter, returnEmptyDataIfNotFound?: boolean) => Promise<T | null>;
9
10
  getDataList: <T extends {}>(projection: string, authData: AuthData, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetProjectionDataList<T> | null>;
10
- upsertData: <T extends {}>(projection: string, authData: AuthData, dataId: string, payload: T) => Promise<UpsertResponse<T>>;
11
- deleteDataById: (projection: string, authData: AuthData, dataId: string) => Promise<number>;
12
- deleteDataByFilter: (projection: string, authData: AuthData, filter?: Filter) => Promise<number>;
11
+ upsertData: <T extends {}>(projection: string, authData: AuthData, dataId: string, payload: Record<string, any>, eventMetadata?: EventMetadata) => Promise<UpsertResponse<T>>;
12
+ deleteDataById: (projection: string, authData: AuthData, dataId: string, eventMetadata?: EventMetadata) => Promise<number>;
13
+ deleteDataByFilter: (projection: string, authData: AuthData, filter?: Filter, eventMetadata?: EventMetadata) => Promise<number>;
13
14
  close: () => Promise<void>;
14
15
  }
15
16
  export declare const newDeliveryClient: (config?: DeliveryClientConfig) => Promise<DeliveryClient>;
@@ -21,14 +21,14 @@ const newDeliveryClient = async (config) => {
21
21
  const getDataList = async (projection, auth, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }, order = []) => {
22
22
  return await (0, getDataList_1.getProjectionDataList)(projection, auth, limit, page, filter, order, serviceClient);
23
23
  };
24
- const upsertData = async (projection, authData, dataId, payload) => {
25
- return (0, upsert_1.upsertProjectionData)(projection, authData, dataId, payload, serviceClient);
24
+ const upsertData = async (projection, authData, dataId, payload, eventMetadata = { causationId: "", correlationId: "" }) => {
25
+ return (0, upsert_1.upsertProjectionData)(projection, authData, dataId, payload, eventMetadata, serviceClient);
26
26
  };
27
- const deleteDataById = async (projection, authData, dataId) => {
28
- return (0, delete_1.deleteProjectionData)(projection, authData, dataId, { fields: {}, and: [], or: [] }, serviceClient);
27
+ const deleteDataById = async (projection, authData, dataId, eventMetadata = { causationId: "", correlationId: "" }) => {
28
+ return (0, delete_1.deleteProjectionData)(projection, authData, dataId, { fields: {}, and: [], or: [] }, eventMetadata, serviceClient);
29
29
  };
30
- const deleteDataByFilter = async (projection, authData, filter = { fields: {}, and: [], or: [] }) => {
31
- return (0, delete_1.deleteProjectionData)(projection, authData, "", filter, serviceClient);
30
+ const deleteDataByFilter = async (projection, authData, filter = { fields: {}, and: [], or: [] }, eventMetadata = { causationId: "", correlationId: "" }) => {
31
+ return (0, delete_1.deleteProjectionData)(projection, authData, "", filter, eventMetadata, serviceClient);
32
32
  };
33
33
  const close = async () => {
34
34
  serviceClient.close();
@@ -1,4 +1,5 @@
1
1
  import { DeliveryServiceClient } from "@fraym/projections-proto";
2
2
  import { AuthData } from "./auth";
3
+ import { EventMetadata } from "./eventMetadata";
3
4
  import { Filter } from "./filter";
4
- export declare const deleteProjectionData: (projection: string, auth: AuthData, dataId: string, filter: Filter, serviceClient: DeliveryServiceClient) => Promise<number>;
5
+ export declare const deleteProjectionData: (projection: string, auth: AuthData, dataId: string, filter: Filter, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<number>;
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteProjectionData = void 0;
4
4
  const auth_1 = require("./auth");
5
5
  const filter_1 = require("./filter");
6
- const deleteProjectionData = async (projection, auth, dataId, filter, serviceClient) => {
6
+ const deleteProjectionData = async (projection, auth, dataId, filter, eventMetadata, serviceClient) => {
7
7
  return new Promise((resolve, reject) => {
8
8
  serviceClient.deleteData({
9
9
  projection,
10
10
  auth: (0, auth_1.getProtobufAuthData)(auth),
11
11
  dataId,
12
12
  filter: (0, filter_1.getProtobufDataFilter)(filter),
13
+ eventMetadata,
13
14
  }, (error, response) => {
14
15
  if (error) {
15
16
  reject(error.message);
@@ -0,0 +1,4 @@
1
+ export interface EventMetadata {
2
+ correlationId: string;
3
+ causationId: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,10 @@
1
1
  import { DeliveryServiceClient } from "@fraym/projections-proto";
2
2
  import { AuthData } from "./auth";
3
+ import { EventMetadata } from "./eventMetadata";
3
4
  export type UpsertResponse<T extends {}> = UpsertSuccessResponse<T> | UpsertValidationResponse;
4
5
  export interface UpsertSuccessResponse<T extends {}> {
5
6
  data: T;
7
+ id: string;
6
8
  }
7
9
  export interface UpsertValidationResponse {
8
10
  validationErrors: string[];
@@ -10,4 +12,4 @@ export interface UpsertValidationResponse {
10
12
  }
11
13
  export declare const isUpsertSuccessResponse: <T extends {}>(response: UpsertResponse<T>) => response is UpsertSuccessResponse<T>;
12
14
  export declare const isUpsertValidationResponse: <T extends {}>(response: UpsertResponse<T>) => response is UpsertValidationResponse;
13
- export declare const upsertProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, payload: T, serviceClient: DeliveryServiceClient) => Promise<UpsertResponse<T>>;
15
+ export declare const upsertProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, payload: Record<string, any>, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<UpsertResponse<T>>;
@@ -10,13 +10,14 @@ const isUpsertValidationResponse = (response) => {
10
10
  return !response.hasOwnProperty("data");
11
11
  };
12
12
  exports.isUpsertValidationResponse = isUpsertValidationResponse;
13
- const upsertProjectionData = async (projection, auth, dataId, payload, serviceClient) => {
13
+ const upsertProjectionData = async (projection, auth, dataId, payload, eventMetadata, serviceClient) => {
14
14
  return new Promise((resolve, reject) => {
15
15
  serviceClient.upsertData({
16
16
  projection,
17
17
  auth: (0, auth_1.getProtobufAuthData)(auth),
18
18
  dataId,
19
19
  payload,
20
+ eventMetadata,
20
21
  }, (error, response) => {
21
22
  if (error) {
22
23
  reject(error.message);
@@ -35,6 +36,7 @@ const upsertProjectionData = async (projection, auth, dataId, payload, serviceCl
35
36
  }
36
37
  resolve({
37
38
  data,
39
+ id: response.id,
38
40
  });
39
41
  });
40
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/projections-nodejs",
6
6
  "repository": {
@@ -27,10 +27,10 @@
27
27
  "projections": "dist/cmd/projections.js"
28
28
  },
29
29
  "dependencies": {
30
- "@fraym/projections-proto": "^1.0.0-alpha.15",
30
+ "@fraym/projections-proto": "^1.0.0-alpha.17",
31
31
  "@graphql-tools/graphql-file-loader": "^7.5.16",
32
32
  "@graphql-tools/load": "^7.8.13",
33
- "@grpc/grpc-js": "^1.8.12",
33
+ "@grpc/grpc-js": "^1.8.13",
34
34
  "dotenv": "^16.0.3",
35
35
  "graphql": "^16.6.0",
36
36
  "yargs": "^17.7.1"
@@ -38,9 +38,9 @@
38
38
  "devDependencies": {
39
39
  "@becklyn/prettier": "^1.0.2",
40
40
  "@types/uuid": "^9.0.1",
41
- "@types/yargs": "^17.0.22",
42
- "prettier": "^2.8.4",
43
- "typescript": "^5.0.2",
41
+ "@types/yargs": "^17.0.24",
42
+ "prettier": "^2.8.7",
43
+ "typescript": "^5.0.3",
44
44
  "uuid": "^9.0.0"
45
45
  },
46
46
  "prettier": "@becklyn/prettier"