@fraym/projections 0.2.0 → 0.3.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 +53 -0
- package/dist/cmd/projections.js +2 -1
- package/dist/delivery/client.d.ts +2 -2
- package/dist/delivery/client.js +2 -2
- package/dist/delivery/getData.js +1 -0
- package/dist/delivery/getDataList.d.ts +11 -1
- package/dist/delivery/getDataList.js +25 -1
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -112,6 +112,59 @@ const page = 1; // number of the page you want to select, first page starts at:
|
|
|
112
112
|
const data = await deliveryClient.getDataList("tenantId", "YourProjection", limit, page);
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
With filter:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const data = await deliveryClient.getDataList("tenantId", "YourProjection", undefined, undefined, {
|
|
119
|
+
fields: {
|
|
120
|
+
fieldName: {
|
|
121
|
+
operation: "equals",
|
|
122
|
+
type: "Int",
|
|
123
|
+
value: 123,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
All `Filter`s are evaluated by:
|
|
130
|
+
|
|
131
|
+
- checking that all field filters match
|
|
132
|
+
- checking that all `and` filters match
|
|
133
|
+
- checking that one of the `or` filters match
|
|
134
|
+
|
|
135
|
+
Avaliable types:
|
|
136
|
+
|
|
137
|
+
- `String`
|
|
138
|
+
- `ID`
|
|
139
|
+
- `DateTime`
|
|
140
|
+
- `Int`
|
|
141
|
+
- `Float`
|
|
142
|
+
- `Boolean`
|
|
143
|
+
|
|
144
|
+
Avaliable operators for all types:
|
|
145
|
+
|
|
146
|
+
- `equals`
|
|
147
|
+
- `notEquals`
|
|
148
|
+
|
|
149
|
+
Avaliable options for the filter type `DateTime`:
|
|
150
|
+
|
|
151
|
+
- `inArray`
|
|
152
|
+
- `notInArray`
|
|
153
|
+
- `after`
|
|
154
|
+
- `before`
|
|
155
|
+
|
|
156
|
+
Avaliable options for the filter type `String` and `ID`:
|
|
157
|
+
|
|
158
|
+
- `inArray`
|
|
159
|
+
- `notInArray`
|
|
160
|
+
|
|
161
|
+
Avaliable options for the filter type `Int` and `Float`:
|
|
162
|
+
|
|
163
|
+
- `lessThan`
|
|
164
|
+
- `greaterThan`
|
|
165
|
+
- `lessThanOrEqual`
|
|
166
|
+
- `greaterThanOrEqual`
|
|
167
|
+
|
|
115
168
|
### Gracefully close the clients
|
|
116
169
|
|
|
117
170
|
You won't lose any data if you don't. Use it for your peace of mind.
|
package/dist/cmd/projections.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ClientConfig } from "../config/config";
|
|
2
2
|
import { GetProjectionData } from "./getData";
|
|
3
|
-
import { GetProjectionDataList } from "./getDataList";
|
|
3
|
+
import { Filter, GetProjectionDataList } from "./getDataList";
|
|
4
4
|
export interface DeliveryClient {
|
|
5
5
|
getData: (tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<GetProjectionData | null>;
|
|
6
|
-
getDataList: (tenantId: string, type: string, limit?: number, page?: number) => Promise<GetProjectionDataList | null>;
|
|
6
|
+
getDataList: (tenantId: string, type: string, limit?: number, page?: number, filter?: Filter) => Promise<GetProjectionDataList | null>;
|
|
7
7
|
close: () => Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
export declare const newDeliveryClient: (config?: ClientConfig) => Promise<DeliveryClient>;
|
package/dist/delivery/client.js
CHANGED
|
@@ -16,8 +16,8 @@ const newDeliveryClient = async (config) => {
|
|
|
16
16
|
const getData = async (tenantId, projection, id, returnEmptyDataIfNotFound = false) => {
|
|
17
17
|
return await (0, getData_1.getProjectionData)(tenantId, projection, id, returnEmptyDataIfNotFound, serviceClient);
|
|
18
18
|
};
|
|
19
|
-
const getDataList = async (tenantId, projection, limit = 0, page = 1) => {
|
|
20
|
-
return await (0, getDataList_1.getProjectionDataList)(tenantId, projection, limit, page, serviceClient);
|
|
19
|
+
const getDataList = async (tenantId, projection, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }) => {
|
|
20
|
+
return await (0, getDataList_1.getProjectionDataList)(tenantId, projection, limit, page, filter, serviceClient);
|
|
21
21
|
};
|
|
22
22
|
const close = async () => {
|
|
23
23
|
serviceClient.close();
|
package/dist/delivery/getData.js
CHANGED
|
@@ -4,4 +4,14 @@ export interface GetProjectionDataList {
|
|
|
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 getProjectionDataList: (tenantId: string, projection: string, limit: number, page: number, filter: Filter, serviceClient: DeliveryServiceClient) => Promise<GetProjectionDataList | null>;
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProjectionDataList = 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 getProjectionDataList = async (tenantId, projection, limit, page, filter, serviceClient) => {
|
|
5
28
|
return new Promise((resolve, reject) => {
|
|
6
29
|
serviceClient.getData({
|
|
7
30
|
tenantId,
|
|
@@ -10,6 +33,7 @@ const getProjectionDataList = async (tenantId, projection, limit, page, serviceC
|
|
|
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/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/projections",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.11",
|
|
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",
|