@fraym/crud 0.16.2 → 0.17.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 +94 -27
- package/dist/delivery/auth.d.ts +7 -0
- package/dist/delivery/auth.js +15 -0
- package/dist/delivery/client.d.ts +10 -6
- package/dist/delivery/client.js +17 -13
- package/dist/delivery/create.d.ts +12 -3
- package/dist/delivery/create.js +25 -4
- package/dist/delivery/delete.d.ts +3 -1
- package/dist/delivery/delete.js +6 -4
- package/dist/delivery/eventMetadata.d.ts +4 -0
- package/dist/delivery/eventMetadata.js +2 -0
- package/dist/delivery/getData.d.ts +3 -1
- package/dist/delivery/getData.js +12 -12
- package/dist/delivery/getDataList.d.ts +3 -1
- package/dist/delivery/getDataList.js +5 -5
- package/dist/delivery/update.d.ts +13 -1
- package/dist/delivery/update.js +29 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -90,47 +90,86 @@ await managementClient.removeTypes(["YourCrudType"]);
|
|
|
90
90
|
const list = await managementClient.getAllTypes();
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
### Authorization
|
|
94
|
+
|
|
95
|
+
All delivery client functions make use of the `AuthData` object.
|
|
96
|
+
This data is used to check access for the desired action.
|
|
97
|
+
|
|
98
|
+
You can add the `FRAYM_AUTH_OWNER` scope in case you are performing an action that is no subject to restrictions.
|
|
99
|
+
|
|
100
|
+
Fields:
|
|
101
|
+
|
|
102
|
+
- `tenantId`: Id of the tenant to use
|
|
103
|
+
- `scopes`: Slice of scopes to use for the action
|
|
104
|
+
- `data`: Data that is used in directives like `@filterFromJwtData`
|
|
105
|
+
|
|
106
|
+
### Event Metadata
|
|
107
|
+
|
|
108
|
+
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:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const eventMetadata = {
|
|
112
|
+
correlationId: "some-correlation-id",
|
|
113
|
+
causationId: "some-causation-id",
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
93
117
|
### Create data
|
|
94
118
|
|
|
95
119
|
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
96
120
|
|
|
97
121
|
```typescript
|
|
98
|
-
const
|
|
122
|
+
const response = await client.create<any>("YourCrudType", authData, {
|
|
99
123
|
// values here
|
|
100
124
|
});
|
|
101
125
|
```
|
|
102
126
|
|
|
127
|
+
The response contains the following fields:
|
|
128
|
+
|
|
129
|
+
In case of no validation errors:
|
|
130
|
+
|
|
131
|
+
- `data`: The new data after your create action
|
|
132
|
+
|
|
133
|
+
In case of validation errors:
|
|
134
|
+
|
|
135
|
+
- `validationErrors`: List of global validation errors that are not related to a single field
|
|
136
|
+
- `fieldValidationErrors`: Validation errors mapped by the name of the field that they relate to
|
|
137
|
+
|
|
103
138
|
### Update data
|
|
104
139
|
|
|
105
140
|
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
106
|
-
The `id` has to match the id of the data that you want to update.
|
|
107
141
|
|
|
108
142
|
```typescript
|
|
109
|
-
await client.update("
|
|
143
|
+
const response = await client.update<any>("YourCrudType", authData, {
|
|
110
144
|
// values here
|
|
111
145
|
});
|
|
112
146
|
```
|
|
113
147
|
|
|
114
|
-
|
|
148
|
+
The response contains the following fields:
|
|
115
149
|
|
|
116
|
-
|
|
150
|
+
In case of no validation errors:
|
|
117
151
|
|
|
118
|
-
|
|
152
|
+
- `data`: The new data after your create action
|
|
119
153
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
154
|
+
In case of validation errors:
|
|
155
|
+
|
|
156
|
+
- `validationErrors`: List of global validation errors that are not related to a single field
|
|
157
|
+
- `fieldValidationErrors`: Validation errors mapped by the name of the field that they relate to
|
|
158
|
+
|
|
159
|
+
### Delete data
|
|
160
|
+
|
|
161
|
+
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
123
162
|
|
|
124
163
|
Delete data matching a specific ID:
|
|
125
164
|
|
|
126
165
|
```typescript
|
|
127
|
-
await client.
|
|
166
|
+
const numberOfDeletedEntries = await client.deleteDataById("YourCrudType", authData, "id");
|
|
128
167
|
```
|
|
129
168
|
|
|
130
169
|
Delete data matching a filter (see filter parameter for `getDataList` for details):
|
|
131
170
|
|
|
132
171
|
```typescript
|
|
133
|
-
await client.
|
|
172
|
+
const numberOfDeletedEntries = await client.deleteDataByFilter("YourCrudType", authData, {
|
|
134
173
|
fields: {
|
|
135
174
|
fieldName: {
|
|
136
175
|
operation: "equals",
|
|
@@ -143,17 +182,31 @@ await client.delete("tenantId", "YourCrudType", undefined, {
|
|
|
143
182
|
|
|
144
183
|
### Get a single data element
|
|
145
184
|
|
|
146
|
-
|
|
147
|
-
The `id` has to match the id of the data that you want to get.
|
|
185
|
+
A filter could look like this:
|
|
148
186
|
|
|
149
|
-
```
|
|
150
|
-
const
|
|
187
|
+
```go
|
|
188
|
+
const filter := {
|
|
189
|
+
fields: {
|
|
190
|
+
fieldName: {
|
|
191
|
+
operation: "equals",
|
|
192
|
+
type: "Int",
|
|
193
|
+
value: 123,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
}
|
|
151
197
|
```
|
|
152
198
|
|
|
153
|
-
|
|
199
|
+
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
200
|
+
The `id` has to match the id of the data that you want to get.
|
|
154
201
|
|
|
155
202
|
```typescript
|
|
156
|
-
const data = await client.getData(
|
|
203
|
+
const data = await client.getData(
|
|
204
|
+
"YourCrudType",
|
|
205
|
+
authData,
|
|
206
|
+
"id",
|
|
207
|
+
filter,
|
|
208
|
+
returnEmptyDataIfNotFound
|
|
209
|
+
);
|
|
157
210
|
```
|
|
158
211
|
|
|
159
212
|
### Get (paginated / filtered / ordered) data
|
|
@@ -163,21 +216,28 @@ The name of `YourCrudType` has to equal your type name in your schema (also in c
|
|
|
163
216
|
No pagination:
|
|
164
217
|
|
|
165
218
|
```typescript
|
|
166
|
-
const
|
|
219
|
+
const dataList = await client.getDataList("YourCrudType", authData);
|
|
167
220
|
```
|
|
168
221
|
|
|
222
|
+
The dataList response contains the following fields:
|
|
223
|
+
|
|
224
|
+
- `limit`: The pagination limit
|
|
225
|
+
- `page`: The pagination page
|
|
226
|
+
- `total`: The total amount of elements matching the given filter
|
|
227
|
+
- `data`: The selected data
|
|
228
|
+
|
|
169
229
|
With pagination:
|
|
170
230
|
|
|
171
231
|
```typescript
|
|
172
232
|
const limit = 50; // elements to query per page
|
|
173
233
|
const page = 1; // number of the page you want to select, first page starts at: 1
|
|
174
|
-
const
|
|
234
|
+
const dataList = await client.getDataList("YourCrudType", authData, limit, page);
|
|
175
235
|
```
|
|
176
236
|
|
|
177
237
|
With filter:
|
|
178
238
|
|
|
179
239
|
```typescript
|
|
180
|
-
const
|
|
240
|
+
const dataList = await client.getDataList("YourCrudType", authData, undefined, undefined, {
|
|
181
241
|
fields: {
|
|
182
242
|
fieldName: {
|
|
183
243
|
operation: "equals",
|
|
@@ -232,15 +292,22 @@ With order:
|
|
|
232
292
|
All order definitions are prioritized in the order that they are defined (the first definition is prioritized over the second).
|
|
233
293
|
|
|
234
294
|
```typescript
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
295
|
+
const dataList = await client.getDataList(
|
|
296
|
+
"YourCrudType",
|
|
297
|
+
authData,
|
|
298
|
+
undefined,
|
|
299
|
+
undefined,
|
|
300
|
+
undefined,
|
|
301
|
+
[
|
|
302
|
+
{
|
|
303
|
+
field: "fieldName",
|
|
304
|
+
descending: true, // omit this value for asc order
|
|
305
|
+
},
|
|
306
|
+
]
|
|
307
|
+
);
|
|
241
308
|
```
|
|
242
309
|
|
|
243
|
-
### Gracefully close the
|
|
310
|
+
### Gracefully close the client
|
|
244
311
|
|
|
245
312
|
You won't lose any data if you don't. Use it for your peace of mind.
|
|
246
313
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProtobufAuthData = void 0;
|
|
4
|
+
const getProtobufAuthData = (auth) => {
|
|
5
|
+
const data = {};
|
|
6
|
+
for (let key in auth.data) {
|
|
7
|
+
data[key] = JSON.stringify(auth.data[key]);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
tenantId: auth.tenantId,
|
|
11
|
+
scopes: auth.scopes,
|
|
12
|
+
data,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.getProtobufAuthData = getProtobufAuthData;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { DeliveryClientConfig } from "../config/config";
|
|
2
|
-
import {
|
|
2
|
+
import { CreateResponse } from "./create";
|
|
3
|
+
import { UpdateResponse } from "./update";
|
|
3
4
|
import { GetCrudDataList } from "./getDataList";
|
|
4
5
|
import { Filter } from "./filter";
|
|
5
6
|
import { Order } from "./order";
|
|
7
|
+
import { AuthData } from "./auth";
|
|
8
|
+
import { EventMetadata } from "./eventMetadata";
|
|
6
9
|
export interface DeliveryClient {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
getData: <T extends {}>(type: string, authData: AuthData, id: string, filter?: Filter, returnEmptyDataIfNotFound?: boolean) => Promise<T | null>;
|
|
11
|
+
getDataList: <T extends {}>(type: string, authData: AuthData, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetCrudDataList<T>>;
|
|
12
|
+
create: <T extends {}>(type: string, authData: AuthData, data: Record<string, any>, id?: string, eventMetadata?: EventMetadata) => Promise<CreateResponse<T>>;
|
|
13
|
+
update: <T extends {}>(type: string, authData: AuthData, id: string, data: Record<string, any>, eventMetadata?: EventMetadata) => Promise<UpdateResponse<T>>;
|
|
14
|
+
deleteDataById: (type: string, authData: AuthData, id: string, eventMetadata?: EventMetadata) => Promise<number>;
|
|
15
|
+
deleteDataByFilter: (type: string, authData: AuthData, filter?: Filter, eventMetadata?: EventMetadata) => Promise<number>;
|
|
12
16
|
close: () => Promise<void>;
|
|
13
17
|
}
|
|
14
18
|
export declare const newDeliveryClient: (config?: DeliveryClientConfig) => Promise<DeliveryClient>;
|
package/dist/delivery/client.js
CHANGED
|
@@ -16,30 +16,34 @@ const newDeliveryClient = async (config) => {
|
|
|
16
16
|
"grpc.keepalive_timeout_ms": config.keepaliveTimeout,
|
|
17
17
|
"grpc.keepalive_permit_without_calls": 1,
|
|
18
18
|
});
|
|
19
|
-
const
|
|
20
|
-
return await (0,
|
|
19
|
+
const getData = async (type, authData, id, filter = { fields: {}, and: [], or: [] }, returnEmptyDataIfNotFound = false) => {
|
|
20
|
+
return await (0, getData_1.getCrudData)(type, authData, id, filter, returnEmptyDataIfNotFound, serviceClient);
|
|
21
21
|
};
|
|
22
|
-
const
|
|
23
|
-
return await (0,
|
|
22
|
+
const getDataList = async (type, authData, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }, order = []) => {
|
|
23
|
+
return await (0, getDataList_1.getCrudDataList)(type, authData, limit, page, filter, order, serviceClient);
|
|
24
24
|
};
|
|
25
|
-
const
|
|
26
|
-
return await (0,
|
|
25
|
+
const create = async (type, authData, data, id = "", eventMetadata = { causationId: "", correlationId: "" }) => {
|
|
26
|
+
return await (0, create_1.createCrudData)(type, authData, data, id, eventMetadata, serviceClient);
|
|
27
27
|
};
|
|
28
|
-
const
|
|
29
|
-
return await (0,
|
|
28
|
+
const update = async (type, authData, id, data, eventMetadata = { causationId: "", correlationId: "" }) => {
|
|
29
|
+
return await (0, update_1.updateCrudData)(type, authData, id, data, eventMetadata, serviceClient);
|
|
30
30
|
};
|
|
31
|
-
const
|
|
32
|
-
return await (0,
|
|
31
|
+
const deleteDataById = async (type, authData, id, eventMetadata = { causationId: "", correlationId: "" }) => {
|
|
32
|
+
return await (0, delete_1.deleteCrudData)(type, authData, id, { fields: {}, and: [], or: [] }, eventMetadata, serviceClient);
|
|
33
|
+
};
|
|
34
|
+
const deleteDataByFilter = async (type, authData, filter = { fields: {}, and: [], or: [] }, eventMetadata = { causationId: "", correlationId: "" }) => {
|
|
35
|
+
return await (0, delete_1.deleteCrudData)(type, authData, "", filter, eventMetadata, serviceClient);
|
|
33
36
|
};
|
|
34
37
|
const close = async () => {
|
|
35
38
|
serviceClient.close();
|
|
36
39
|
};
|
|
37
40
|
return {
|
|
38
|
-
create,
|
|
39
|
-
update,
|
|
40
|
-
delete: deleter,
|
|
41
41
|
getData,
|
|
42
42
|
getDataList,
|
|
43
|
+
create,
|
|
44
|
+
update,
|
|
45
|
+
deleteDataById,
|
|
46
|
+
deleteDataByFilter,
|
|
43
47
|
close,
|
|
44
48
|
};
|
|
45
49
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { DeliveryServiceClient } from "@fraym/crud-proto";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { AuthData } from "./auth";
|
|
3
|
+
import { EventMetadata } from "./eventMetadata";
|
|
4
|
+
export type CreateResponse<T extends {}> = CreateSuccessResponse<T> | CreateValidationResponse;
|
|
5
|
+
export interface CreateSuccessResponse<T extends {}> {
|
|
6
|
+
data: T;
|
|
4
7
|
}
|
|
5
|
-
export
|
|
8
|
+
export interface CreateValidationResponse {
|
|
9
|
+
validationErrors: string[];
|
|
10
|
+
fieldValidationErrors: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare const isCreateSuccessResponse: <T extends {}>(response: CreateResponse<T>) => response is CreateSuccessResponse<T>;
|
|
13
|
+
export declare const isCreateValidationResponse: <T extends {}>(response: CreateResponse<T>) => response is CreateValidationResponse;
|
|
14
|
+
export declare const createCrudData: <T extends {}>(type: string, authData: AuthData, data: Record<string, any>, id: string, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<CreateResponse<T>>;
|
package/dist/delivery/create.js
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCrudData = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.createCrudData = exports.isCreateValidationResponse = exports.isCreateSuccessResponse = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const isCreateSuccessResponse = (response) => {
|
|
6
|
+
return response.hasOwnProperty("data");
|
|
7
|
+
};
|
|
8
|
+
exports.isCreateSuccessResponse = isCreateSuccessResponse;
|
|
9
|
+
const isCreateValidationResponse = (response) => {
|
|
10
|
+
return !response.hasOwnProperty("data");
|
|
11
|
+
};
|
|
12
|
+
exports.isCreateValidationResponse = isCreateValidationResponse;
|
|
13
|
+
const createCrudData = async (type, authData, data, id, eventMetadata, serviceClient) => {
|
|
5
14
|
const requestData = {};
|
|
6
15
|
for (const key in data) {
|
|
7
16
|
requestData[key] = JSON.stringify(data[key]);
|
|
8
17
|
}
|
|
9
18
|
return new Promise((resolve, reject) => {
|
|
10
19
|
serviceClient.createEntry({
|
|
11
|
-
tenantId,
|
|
12
20
|
type,
|
|
21
|
+
auth: (0, auth_1.getProtobufAuthData)(authData),
|
|
13
22
|
data: requestData,
|
|
14
23
|
id,
|
|
24
|
+
eventMetadata,
|
|
15
25
|
}, (error, response) => {
|
|
16
26
|
if (error) {
|
|
17
27
|
reject(error.message);
|
|
18
28
|
return;
|
|
19
29
|
}
|
|
30
|
+
if (response.validationErrors || response.fieldValidationErrors) {
|
|
31
|
+
resolve({
|
|
32
|
+
validationErrors: response.validationErrors,
|
|
33
|
+
fieldValidationErrors: response.fieldValidationErrors,
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const data = {};
|
|
38
|
+
for (const key in response.newData) {
|
|
39
|
+
data[key] = JSON.parse(response.newData[key]);
|
|
40
|
+
}
|
|
20
41
|
resolve({
|
|
21
|
-
|
|
42
|
+
data,
|
|
22
43
|
});
|
|
23
44
|
});
|
|
24
45
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { DeliveryServiceClient } from "@fraym/crud-proto";
|
|
2
|
+
import { AuthData } from "./auth";
|
|
3
|
+
import { EventMetadata } from "./eventMetadata";
|
|
2
4
|
import { Filter } from "./filter";
|
|
3
|
-
export declare const deleteCrudData: (
|
|
5
|
+
export declare const deleteCrudData: (type: string, authData: AuthData, id: string, filter: Filter, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<number>;
|
package/dist/delivery/delete.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteCrudData = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
4
5
|
const filter_1 = require("./filter");
|
|
5
|
-
const deleteCrudData = async (
|
|
6
|
+
const deleteCrudData = async (type, authData, id, filter, eventMetadata, serviceClient) => {
|
|
6
7
|
return new Promise((resolve, reject) => {
|
|
7
8
|
serviceClient.deleteEntries({
|
|
8
|
-
tenantId,
|
|
9
9
|
type,
|
|
10
|
+
auth: (0, auth_1.getProtobufAuthData)(authData),
|
|
10
11
|
id,
|
|
11
12
|
filter: (0, filter_1.getProtobufEntryFilter)(filter),
|
|
12
|
-
|
|
13
|
+
eventMetadata,
|
|
14
|
+
}, (error, response) => {
|
|
13
15
|
if (error) {
|
|
14
16
|
reject(error.message);
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
|
-
resolve();
|
|
19
|
+
resolve(response.numberOfDeletedEntries);
|
|
18
20
|
});
|
|
19
21
|
});
|
|
20
22
|
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { DeliveryServiceClient } from "@fraym/crud-proto";
|
|
2
|
-
|
|
2
|
+
import { AuthData } from "./auth";
|
|
3
|
+
import { Filter } from "./filter";
|
|
4
|
+
export declare const getCrudData: <T extends {}>(type: string, authData: AuthData, id: string, filter: Filter, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient) => Promise<T | null>;
|
package/dist/delivery/getData.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCrudData = void 0;
|
|
4
|
-
const
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const filter_1 = require("./filter");
|
|
6
|
+
const getCrudData = async (type, authData, id, filter, returnEmptyDataIfNotFound, serviceClient) => {
|
|
5
7
|
return new Promise((resolve, reject) => {
|
|
6
|
-
serviceClient.
|
|
7
|
-
tenantId,
|
|
8
|
+
serviceClient.getEntry({
|
|
8
9
|
type,
|
|
10
|
+
auth: (0, auth_1.getProtobufAuthData)(authData),
|
|
11
|
+
filter: (0, filter_1.getProtobufEntryFilter)(filter),
|
|
9
12
|
id,
|
|
10
|
-
limit: 0,
|
|
11
|
-
page: 0,
|
|
12
13
|
returnEmptyDataIfNotFound,
|
|
13
|
-
filter: { fields: {}, and: [], or: [] },
|
|
14
|
-
order: [],
|
|
15
14
|
}, (error, response) => {
|
|
16
15
|
if (error) {
|
|
17
16
|
reject(error.message);
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const result = response.result;
|
|
20
|
+
if (!result) {
|
|
21
|
+
resolve(null);
|
|
22
|
+
return;
|
|
22
23
|
}
|
|
23
24
|
const data = {};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
data[key] = JSON.parse(resultData[key]);
|
|
25
|
+
for (const key in result.data) {
|
|
26
|
+
data[key] = JSON.parse(result.data[key]);
|
|
27
27
|
}
|
|
28
28
|
resolve(data);
|
|
29
29
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DeliveryServiceClient } from "@fraym/crud-proto";
|
|
2
|
+
import { AuthData } from "./auth";
|
|
2
3
|
import { Filter } from "./filter";
|
|
3
4
|
import { Order } from "./order";
|
|
4
5
|
export interface GetCrudDataList<T extends {}> {
|
|
5
6
|
limit: number;
|
|
6
7
|
page: number;
|
|
8
|
+
total: number;
|
|
7
9
|
data: T[];
|
|
8
10
|
}
|
|
9
|
-
export declare const getCrudDataList: <T extends {}>(
|
|
11
|
+
export declare const getCrudDataList: <T extends {}>(type: string, authData: AuthData, limit: number, page: number, filter: Filter, order: Order[], serviceClient: DeliveryServiceClient) => Promise<GetCrudDataList<T>>;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCrudDataList = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
4
5
|
const filter_1 = require("./filter");
|
|
5
6
|
const order_1 = require("./order");
|
|
6
|
-
const getCrudDataList = async (
|
|
7
|
+
const getCrudDataList = async (type, authData, limit, page, filter, order, serviceClient) => {
|
|
7
8
|
return new Promise((resolve, reject) => {
|
|
8
|
-
serviceClient.
|
|
9
|
-
tenantId,
|
|
9
|
+
serviceClient.getEntryList({
|
|
10
10
|
type,
|
|
11
|
-
|
|
11
|
+
auth: (0, auth_1.getProtobufAuthData)(authData),
|
|
12
12
|
limit,
|
|
13
13
|
page,
|
|
14
|
-
returnEmptyDataIfNotFound: false,
|
|
15
14
|
filter: (0, filter_1.getProtobufEntryFilter)(filter),
|
|
16
15
|
order: (0, order_1.getProtobufEntryOrder)(order),
|
|
17
16
|
}, (error, response) => {
|
|
@@ -31,6 +30,7 @@ const getCrudDataList = async (tenantId, type, limit, page, filter, order, servi
|
|
|
31
30
|
resolve({
|
|
32
31
|
limit: response.limit,
|
|
33
32
|
page: response.page,
|
|
33
|
+
total: response.total,
|
|
34
34
|
data,
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import { DeliveryServiceClient } from "@fraym/crud-proto";
|
|
2
|
-
|
|
2
|
+
import { AuthData } from "./auth";
|
|
3
|
+
import { EventMetadata } from "./eventMetadata";
|
|
4
|
+
export type UpdateResponse<T extends {}> = UpdateSuccessResponse<T> | UpdateValidationResponse;
|
|
5
|
+
export interface UpdateSuccessResponse<T extends {}> {
|
|
6
|
+
data: T;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateValidationResponse {
|
|
9
|
+
validationErrors: string[];
|
|
10
|
+
fieldValidationErrors: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare const isUpdateSuccessResponse: <T extends {}>(response: UpdateResponse<T>) => response is UpdateSuccessResponse<T>;
|
|
13
|
+
export declare const isUpdateValidationResponse: <T extends {}>(response: UpdateResponse<T>) => response is UpdateValidationResponse;
|
|
14
|
+
export declare const updateCrudData: <T extends {}>(type: string, authData: AuthData, id: string, data: Record<string, any>, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<UpdateResponse<T>>;
|
package/dist/delivery/update.js
CHANGED
|
@@ -1,23 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateCrudData = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.updateCrudData = exports.isUpdateValidationResponse = exports.isUpdateSuccessResponse = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const isUpdateSuccessResponse = (response) => {
|
|
6
|
+
return response.hasOwnProperty("data");
|
|
7
|
+
};
|
|
8
|
+
exports.isUpdateSuccessResponse = isUpdateSuccessResponse;
|
|
9
|
+
const isUpdateValidationResponse = (response) => {
|
|
10
|
+
return !response.hasOwnProperty("data");
|
|
11
|
+
};
|
|
12
|
+
exports.isUpdateValidationResponse = isUpdateValidationResponse;
|
|
13
|
+
const updateCrudData = async (type, authData, id, data, eventMetadata, serviceClient) => {
|
|
5
14
|
const requestData = {};
|
|
6
15
|
for (const key in data) {
|
|
7
16
|
requestData[key] = JSON.stringify(data[key]);
|
|
8
17
|
}
|
|
9
18
|
return new Promise((resolve, reject) => {
|
|
10
19
|
serviceClient.updateEntry({
|
|
11
|
-
tenantId,
|
|
12
20
|
type,
|
|
13
|
-
|
|
21
|
+
auth: (0, auth_1.getProtobufAuthData)(authData),
|
|
14
22
|
data: requestData,
|
|
15
|
-
|
|
23
|
+
id,
|
|
24
|
+
eventMetadata,
|
|
25
|
+
}, (error, response) => {
|
|
16
26
|
if (error) {
|
|
17
27
|
reject(error.message);
|
|
18
28
|
return;
|
|
19
29
|
}
|
|
20
|
-
|
|
30
|
+
if (response.validationErrors || response.fieldValidationErrors) {
|
|
31
|
+
resolve({
|
|
32
|
+
validationErrors: response.validationErrors,
|
|
33
|
+
fieldValidationErrors: response.fieldValidationErrors,
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const data = {};
|
|
38
|
+
for (const key in response.newData) {
|
|
39
|
+
data[key] = JSON.parse(response.newData[key]);
|
|
40
|
+
}
|
|
41
|
+
resolve({
|
|
42
|
+
data,
|
|
43
|
+
});
|
|
21
44
|
});
|
|
22
45
|
});
|
|
23
46
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/crud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"homepage": "https://github.com/fraym/crud-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"crud": "dist/cmd/crud.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@fraym/crud-proto": "1.0.0-alpha.
|
|
30
|
+
"@fraym/crud-proto": "1.0.0-alpha.17",
|
|
31
31
|
"@graphql-tools/graphql-file-loader": "^7.5.14",
|
|
32
32
|
"@graphql-tools/load": "^7.8.9",
|
|
33
33
|
"@grpc/grpc-js": "^1.8.7",
|