@fraym/projections 0.10.1 → 0.11.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 CHANGED
@@ -85,19 +85,90 @@ await managementClient.remove(["YourProjection"]);
85
85
  const list = await managementClient.getAll();
86
86
  ```
87
87
 
88
- ### Get a single projection element
88
+ ### Authorization
89
89
 
90
- The name of `YourProjection` has to equal your projection name in your schema (also in casing).
91
- The `id` has to match the id of the projection element that you want to get.
90
+ All delivery client functions make use of the `AuthData` object.
91
+ This data is used to check access for the desired action.
92
+
93
+ You can add the `FRAYM_AUTH_OWNER` scope in case you are performing an action that is no subject to restrictions.
94
+
95
+ Fields:
96
+
97
+ - `tenantId`: Id of the tenant to use
98
+ - `scopes`: Slice of scopes to use for the action
99
+ - `data`: Data that is used in directives like `@filterFromJwtData`
100
+
101
+ ### Upsert data in projection
102
+
103
+ In general you upsert data by publishing events on the event stream.
104
+ There are cases where you want to improve performance and get detailed validation output. In these cases you can use the client to directly upsert data. Do not worry, this is still event based under the hood.
92
105
 
93
106
  ```typescript
94
- const data = await deliveryClient.getData("tenantId", "YourProjection", "id");
107
+ const response = await client.upsertData<{ fieldName: string }>(
108
+ "ProjectionName",
109
+ authData,
110
+ "dataId",
111
+ {
112
+ fieldName: "value",
113
+ }
114
+ );
115
+ ```
116
+
117
+ The response contains the following fields:
118
+
119
+ In case of no validation errors:
120
+
121
+ - `data`: The new data after your upsert action
122
+
123
+ In case of validation errors:
124
+
125
+ - `validationErrors`: List of global validation errors that are not related to a single field
126
+ - `fieldValidationErrors`: Validation errors mapped by the name of the field that they relate to
127
+
128
+ ### Delete data from projection
129
+
130
+ In general you delete data by publishing events on the event stream.
131
+ There are cases where you want to improve performance and get detailed validation output. In these cases you can use the client to directly delete data. Do not worry, this is still event based under the hood.
132
+
133
+ Delete by Id:
134
+
135
+ ```go
136
+ const numberOfDeletedEntries = await client.deleteDataById("ProjectionName", authData, "dataId")
137
+ ```
138
+
139
+ Delete by filter:
140
+
141
+ ```go
142
+ const numberOfDeletedEntries = client.deleteDataByFilter("ProjectionName", authData, filter)
143
+ ```
144
+
145
+ ### Get a single projection element
146
+
147
+ A filter could look like this:
148
+
149
+ ```go
150
+ const filter := {
151
+ fields: {
152
+ fieldName: {
153
+ operation: "equals",
154
+ type: "Int",
155
+ value: 123,
156
+ },
157
+ },
158
+ }
95
159
  ```
96
160
 
97
- You can specify a fourth parameter if you want to return a empty dataset instead of getting an error when querying a non existing element:
161
+ The name of `YourProjection` has to equal your projection name in your schema (also in casing).
162
+ The `id` has to match the id of the projection element that you want to get.
98
163
 
99
164
  ```typescript
100
- const data = await deliveryClient.getData("tenantId", "YourProjection", "id", true);
165
+ const data = await deliveryClient.getData(
166
+ "YourProjection",
167
+ authData,
168
+ "id",
169
+ filter,
170
+ returnEmptyDataIfNotFound
171
+ );
101
172
  ```
102
173
 
103
174
  ### Get (paginated / filtered) data
@@ -107,29 +178,42 @@ The name of `YourProjection` has to equal your type name in your schema (also in
107
178
  No pagination:
108
179
 
109
180
  ```typescript
110
- const data = await deliveryClient.getDataList("tenantId", "YourProjection");
181
+ const dataList = await deliveryClient.getDataList("YourProjection", authData);
111
182
  ```
112
183
 
184
+ The dataList response contains the following fields:
185
+
186
+ - `limit`: The pagination limit
187
+ - `page`: The pagination page
188
+ - `total`: The total amount of elements matching the given filter
189
+ - `data`: The selected data
190
+
113
191
  With pagination:
114
192
 
115
193
  ```typescript
116
194
  const limit = 50; // elements to query per page
117
195
  const page = 1; // number of the page you want to select, first page starts at: 1
118
- const data = await deliveryClient.getDataList("tenantId", "YourProjection", limit, page);
196
+ const dataList = await deliveryClient.getDataList("YourProjection", authData, limit, page);
119
197
  ```
120
198
 
121
199
  With filter:
122
200
 
123
201
  ```typescript
124
- const data = await deliveryClient.getDataList("tenantId", "YourProjection", undefined, undefined, {
125
- fields: {
126
- fieldName: {
127
- operation: "equals",
128
- type: "Int",
129
- value: 123,
202
+ const dataList = await deliveryClient.getDataList(
203
+ "YourProjection",
204
+ authData,
205
+ undefined,
206
+ undefined,
207
+ {
208
+ fields: {
209
+ fieldName: {
210
+ operation: "equals",
211
+ type: "Int",
212
+ value: 123,
213
+ },
130
214
  },
131
- },
132
- });
215
+ }
216
+ );
133
217
  ```
134
218
 
135
219
  All `Filter`s are evaluated by:
@@ -176,9 +260,9 @@ With order:
176
260
  All order definitions are prioritized in the order that they are defined (the first definition is prioritized over the second).
177
261
 
178
262
  ```typescript
179
- const data = await client.getDataList(
180
- "tenantId",
263
+ const dataList = await client.getDataList(
181
264
  "YourProjection",
265
+ authData,
182
266
  undefined,
183
267
  undefined,
184
268
  undefined,
@@ -5,6 +5,7 @@ import { Order } from "./order";
5
5
  export interface GetProjectionDataList<T extends {}> {
6
6
  limit: number;
7
7
  page: number;
8
+ total: number;
8
9
  data: T[];
9
10
  }
10
11
  export declare const getProjectionDataList: <T extends {}>(projection: string, auth: AuthData, limit: number, page: number, filter: Filter, order: Order[], serviceClient: DeliveryServiceClient) => Promise<GetProjectionDataList<T> | null>;
@@ -30,6 +30,7 @@ const getProjectionDataList = async (projection, auth, limit, page, filter, orde
30
30
  resolve({
31
31
  limit: response.limit,
32
32
  page: response.page,
33
+ total: response.total,
33
34
  data,
34
35
  });
35
36
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.10.1",
3
+ "version": "0.11.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.14",
30
+ "@fraym/projections-proto": "^1.0.0-alpha.15",
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",