@fraym/projections 0.13.0 → 0.14.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/README.md +15 -3
- package/dist/delivery/client.d.ts +4 -3
- package/dist/delivery/client.js +6 -6
- package/dist/delivery/delete.d.ts +2 -1
- package/dist/delivery/delete.js +2 -1
- package/dist/delivery/eventMetadata.d.ts +4 -0
- package/dist/delivery/eventMetadata.js +2 -0
- package/dist/delivery/upsert.d.ts +2 -1
- package/dist/delivery/upsert.js +2 -1
- package/package.json +2 -2
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
|
|
@@ -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: T, 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>;
|
package/dist/delivery/client.js
CHANGED
|
@@ -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>;
|
package/dist/delivery/delete.js
CHANGED
|
@@ -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);
|
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
@@ -10,4 +11,4 @@ export interface UpsertValidationResponse {
|
|
|
10
11
|
}
|
|
11
12
|
export declare const isUpsertSuccessResponse: <T extends {}>(response: UpsertResponse<T>) => response is UpsertSuccessResponse<T>;
|
|
12
13
|
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>>;
|
|
14
|
+
export declare const upsertProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, payload: T, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<UpsertResponse<T>>;
|
package/dist/delivery/upsert.js
CHANGED
|
@@ -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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/projections",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"homepage": "https://github.com/fraym/projections-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"projections": "dist/cmd/projections.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@fraym/projections-proto": "^1.0.0-alpha.
|
|
30
|
+
"@fraym/projections-proto": "^1.0.0-alpha.16",
|
|
31
31
|
"@graphql-tools/graphql-file-loader": "^7.5.16",
|
|
32
32
|
"@graphql-tools/load": "^7.8.13",
|
|
33
33
|
"@grpc/grpc-js": "^1.8.12",
|