@fraym/crud 0.6.0 → 0.7.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# crud-nodejs
|
|
2
2
|
|
|
3
|
-
Client implementation in javascript for the CRUD service
|
|
3
|
+
Client implementation in javascript for the [CRUD service](https://github.com/fraym/crud).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -118,7 +118,13 @@ The `id` has to match the id of the data that you want to get.
|
|
|
118
118
|
const data = await client.getData("tenantId", "YourCrudType", "id");
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
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:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const data = await client.getData("tenantId", "YourCrudType", "id", true);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Get (paginated / filtered) data
|
|
122
128
|
|
|
123
129
|
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
124
130
|
|
|
@@ -136,6 +142,59 @@ const page = 1; // number of the page you want to select, first page starts at:
|
|
|
136
142
|
const data = await client.getDataList("tenantId", "YourCrudType", limit, page);
|
|
137
143
|
```
|
|
138
144
|
|
|
145
|
+
With filter:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const data = await client.getDataList("tenantId", "YourCrudType", undefined, undefined, {
|
|
149
|
+
fields: {
|
|
150
|
+
fieldName: {
|
|
151
|
+
operation: "equals",
|
|
152
|
+
type: "Int",
|
|
153
|
+
value: 123,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
All `Filter`s are evaluated by:
|
|
160
|
+
|
|
161
|
+
- checking that all field filters match
|
|
162
|
+
- checking that all `and` filters match
|
|
163
|
+
- checking that one of the `or` filters match
|
|
164
|
+
|
|
165
|
+
Avaliable types:
|
|
166
|
+
|
|
167
|
+
- `String`
|
|
168
|
+
- `ID`
|
|
169
|
+
- `DateTime`
|
|
170
|
+
- `Int`
|
|
171
|
+
- `Float`
|
|
172
|
+
- `Boolean`
|
|
173
|
+
|
|
174
|
+
Avaliable operators for all types:
|
|
175
|
+
|
|
176
|
+
- `equals`
|
|
177
|
+
- `notEquals`
|
|
178
|
+
|
|
179
|
+
Avaliable options for the filter type `DateTime`:
|
|
180
|
+
|
|
181
|
+
- `inArray`
|
|
182
|
+
- `notInArray`
|
|
183
|
+
- `after`
|
|
184
|
+
- `before`
|
|
185
|
+
|
|
186
|
+
Avaliable options for the filter type `String` and `ID`:
|
|
187
|
+
|
|
188
|
+
- `inArray`
|
|
189
|
+
- `notInArray`
|
|
190
|
+
|
|
191
|
+
Avaliable options for the filter type `Int` and `Float`:
|
|
192
|
+
|
|
193
|
+
- `lessThan`
|
|
194
|
+
- `greaterThan`
|
|
195
|
+
- `lessThanOrEqual`
|
|
196
|
+
- `greaterThanOrEqual`
|
|
197
|
+
|
|
139
198
|
### Gracefully close the clients
|
|
140
199
|
|
|
141
200
|
You won't lose any data if you don't. Use it for your peace of mind.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ClientConfig } from "../config/config";
|
|
2
2
|
import { CreatedCrudData } from "./create";
|
|
3
3
|
import { GetCrudData } from "./getData";
|
|
4
|
-
import { GetCrudDataList } from "./getDataList";
|
|
4
|
+
import { Filter, GetCrudDataList } from "./getDataList";
|
|
5
5
|
export interface DeliveryClient {
|
|
6
6
|
create: (tenantId: string, type: string, data: Record<string, any>) => Promise<CreatedCrudData>;
|
|
7
7
|
update: (tenantId: string, type: string, id: string, data: Record<string, any>) => Promise<void>;
|
|
8
8
|
delete: (tenantId: string, type: string, id: string) => Promise<void>;
|
|
9
9
|
getData: (tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<GetCrudData | null>;
|
|
10
|
-
getDataList: (tenantId: string, type: string, limit?: number, page?: number) => Promise<GetCrudDataList | null>;
|
|
10
|
+
getDataList: (tenantId: string, type: string, limit?: number, page?: number, filter?: Filter) => Promise<GetCrudDataList | null>;
|
|
11
11
|
close: () => Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export declare const newDeliveryClient: (config?: ClientConfig) => Promise<DeliveryClient>;
|
package/dist/delivery/client.js
CHANGED
|
@@ -28,8 +28,8 @@ const newDeliveryClient = async (config) => {
|
|
|
28
28
|
const getData = async (tenantId, type, id, returnEmptyDataIfNotFound = false) => {
|
|
29
29
|
return await (0, getData_1.getCrudData)(tenantId, type, id, returnEmptyDataIfNotFound, serviceClient);
|
|
30
30
|
};
|
|
31
|
-
const getDataList = async (tenantId, type, limit = 0, page = 1) => {
|
|
32
|
-
return await (0, getDataList_1.getCrudDataList)(tenantId, type, limit, page, serviceClient);
|
|
31
|
+
const getDataList = async (tenantId, type, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }) => {
|
|
32
|
+
return await (0, getDataList_1.getCrudDataList)(tenantId, type, limit, page, filter, serviceClient);
|
|
33
33
|
};
|
|
34
34
|
const close = async () => {
|
|
35
35
|
serviceClient.close();
|
package/dist/delivery/getData.js
CHANGED
|
@@ -4,4 +4,14 @@ export interface GetCrudDataList {
|
|
|
4
4
|
page: number;
|
|
5
5
|
data: Record<string, any>[];
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export interface Filter {
|
|
8
|
+
fields: Record<string, FieldFilter>;
|
|
9
|
+
and: Filter[];
|
|
10
|
+
or: Filter[];
|
|
11
|
+
}
|
|
12
|
+
export interface FieldFilter {
|
|
13
|
+
type: string;
|
|
14
|
+
operation: string;
|
|
15
|
+
value: any;
|
|
16
|
+
}
|
|
17
|
+
export declare const getCrudDataList: (tenantId: string, type: string, limit: number, page: number, filter: Filter, serviceClient: DeliveryServiceClient) => Promise<GetCrudDataList | null>;
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCrudDataList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const getProtobufDataFilter = (filter) => {
|
|
5
|
+
const fields = {};
|
|
6
|
+
for (const fieldName in filter.fields) {
|
|
7
|
+
const field = filter.fields[fieldName];
|
|
8
|
+
let value = "";
|
|
9
|
+
if (field.type === "String" && typeof field.value == "string") {
|
|
10
|
+
value = field.value;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
value = JSON.stringify(field.value);
|
|
14
|
+
}
|
|
15
|
+
fields[fieldName] = {
|
|
16
|
+
operation: field.operation,
|
|
17
|
+
type: field.type,
|
|
18
|
+
value,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
fields: fields,
|
|
23
|
+
and: filter.and.map(and => getProtobufDataFilter(and)),
|
|
24
|
+
or: filter.or.map(or => getProtobufDataFilter(or)),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getCrudDataList = async (tenantId, type, limit, page, filter, serviceClient) => {
|
|
5
28
|
return new Promise((resolve, reject) => {
|
|
6
29
|
serviceClient.getEntries({
|
|
7
30
|
tenantId,
|
|
@@ -10,6 +33,7 @@ const getCrudDataList = async (tenantId, type, limit, page, serviceClient) => {
|
|
|
10
33
|
limit,
|
|
11
34
|
page,
|
|
12
35
|
returnEmptyDataIfNotFound: false,
|
|
36
|
+
filter: getProtobufDataFilter(filter),
|
|
13
37
|
}, (error, response) => {
|
|
14
38
|
if (error) {
|
|
15
39
|
reject(error.message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/crud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.7",
|
|
31
31
|
"@graphql-tools/graphql-file-loader": "^7.5.11",
|
|
32
32
|
"@graphql-tools/load": "^7.8.6",
|
|
33
33
|
"@grpc/grpc-js": "^1.7.2",
|