@fraym/projections 0.4.1 → 0.6.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
@@ -168,6 +168,26 @@ Avaliable options for the filter type `Int` and `Float`:
168
168
  - `lessThanOrEqual`
169
169
  - `greaterThanOrEqual`
170
170
 
171
+ With order:
172
+
173
+ All order definitions are prioritized in the order that they are defined (the first definition is prioritized over the second).
174
+
175
+ ```typescript
176
+ const data = await client.getDataList(
177
+ "tenantId",
178
+ "YourProjection",
179
+ undefined,
180
+ undefined,
181
+ undefined,
182
+ [
183
+ {
184
+ field: "fieldName",
185
+ descending: true, // omit this value for asc order
186
+ },
187
+ ]
188
+ );
189
+ ```
190
+
171
191
  ### Gracefully close the clients
172
192
 
173
193
  You won't lose any data if you don't. Use it for your peace of mind.
@@ -206,7 +206,9 @@ const getValueString = (v) => {
206
206
  };
207
207
  const migrateSchemas = async (definitions, serverAddress, namespace) => {
208
208
  const managementClient = await (0, client_1.newManagementClient)({ serverAddress });
209
- let existingProjections = (await managementClient.getAll()).filter(projectionName => !projectionName.startsWith("Crud") && projectionName.startsWith(namespace));
209
+ let existingProjections = (await managementClient.getAll()).filter(projectionName => !projectionName.startsWith("Crud") &&
210
+ !projectionName.startsWith("Fraym") &&
211
+ projectionName.startsWith(namespace));
210
212
  let createSchema = "";
211
213
  let updateSchema = "";
212
214
  const projectionsToCreate = [];
@@ -1,9 +1,10 @@
1
1
  import { ClientConfig } from "../config/config";
2
- import { GetProjectionData } from "./getData";
3
- import { Filter, GetProjectionDataList } from "./getDataList";
2
+ import { Filter } from "./filter";
3
+ import { GetProjectionDataList } from "./getDataList";
4
+ import { Order } from "./order";
4
5
  export interface DeliveryClient {
5
- getData: (tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<GetProjectionData | null>;
6
- getDataList: (tenantId: string, type: string, limit?: number, page?: number, filter?: Filter) => Promise<GetProjectionDataList | null>;
6
+ getData: <T extends {}>(tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<T | null>;
7
+ getDataList: <T extends {}>(tenantId: string, type: string, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetProjectionDataList<T> | null>;
7
8
  close: () => Promise<void>;
8
9
  }
9
10
  export declare const newDeliveryClient: (config?: ClientConfig) => Promise<DeliveryClient>;
@@ -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, filter = { fields: {}, and: [], or: [] }) => {
20
- return await (0, getDataList_1.getProjectionDataList)(tenantId, projection, limit, page, filter, serviceClient);
19
+ const getDataList = async (tenantId, projection, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }, order = []) => {
20
+ return await (0, getDataList_1.getProjectionDataList)(tenantId, projection, limit, page, filter, order, serviceClient);
21
21
  };
22
22
  const close = async () => {
23
23
  serviceClient.close();
@@ -0,0 +1,12 @@
1
+ import { DataFilter } from "@fraym/projections-proto";
2
+ export interface Filter {
3
+ fields: Record<string, FieldFilter>;
4
+ and: Filter[];
5
+ or: Filter[];
6
+ }
7
+ export interface FieldFilter {
8
+ type: string;
9
+ operation: string;
10
+ value: any;
11
+ }
12
+ export declare const getProtobufDataFilter: (filter: Filter) => DataFilter;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProtobufDataFilter = void 0;
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 => (0, exports.getProtobufDataFilter)(and)),
24
+ or: filter.or.map(or => (0, exports.getProtobufDataFilter)(or)),
25
+ };
26
+ };
27
+ exports.getProtobufDataFilter = getProtobufDataFilter;
@@ -1,3 +1,2 @@
1
1
  import { DeliveryServiceClient } from "@fraym/projections-proto";
2
- export declare type GetProjectionData = Record<string, any>;
3
- export declare const getProjectionData: (tenantId: string, projection: string, dataId: string, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient) => Promise<GetProjectionData | null>;
2
+ export declare const getProjectionData: <T extends {}>(tenantId: string, projection: string, dataId: string, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient) => Promise<T | null>;
@@ -11,6 +11,7 @@ const getProjectionData = async (tenantId, projection, dataId, returnEmptyDataIf
11
11
  page: 0,
12
12
  returnEmptyDataIfNotFound,
13
13
  filter: { fields: {}, and: [], or: [] },
14
+ order: [],
14
15
  }, (error, response) => {
15
16
  if (error) {
16
17
  reject(error.message);
@@ -1,17 +1,9 @@
1
1
  import { DeliveryServiceClient } from "@fraym/projections-proto";
2
- export interface GetProjectionDataList {
2
+ import { Filter } from "./filter";
3
+ import { Order } from "./order";
4
+ export interface GetProjectionDataList<T extends {}> {
3
5
  limit: number;
4
6
  page: number;
5
- data: Record<string, any>[];
7
+ data: T[];
6
8
  }
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>;
9
+ export declare const getProjectionDataList: <T extends {}>(tenantId: string, projection: string, limit: number, page: number, filter: Filter, order: Order[], serviceClient: DeliveryServiceClient) => Promise<GetProjectionDataList<T> | null>;
@@ -1,30 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProjectionDataList = void 0;
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) => {
4
+ const filter_1 = require("./filter");
5
+ const order_1 = require("./order");
6
+ const getProjectionDataList = async (tenantId, projection, limit, page, filter, order, serviceClient) => {
28
7
  return new Promise((resolve, reject) => {
29
8
  serviceClient.getData({
30
9
  tenantId,
@@ -33,7 +12,8 @@ const getProjectionDataList = async (tenantId, projection, limit, page, filter,
33
12
  limit,
34
13
  page,
35
14
  returnEmptyDataIfNotFound: false,
36
- filter: getProtobufDataFilter(filter),
15
+ filter: (0, filter_1.getProtobufDataFilter)(filter),
16
+ order: (0, order_1.getProtobufDataOrder)(order),
37
17
  }, (error, response) => {
38
18
  if (error) {
39
19
  reject(error.message);
@@ -0,0 +1,6 @@
1
+ import { DataOrder } from "@fraym/projections-proto";
2
+ export interface Order {
3
+ field: string;
4
+ descending?: boolean;
5
+ }
6
+ export declare const getProtobufDataOrder: (order: Order[]) => DataOrder[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProtobufDataOrder = void 0;
4
+ const getProtobufDataOrder = (order) => {
5
+ return order.map(o => {
6
+ var _a;
7
+ return ({
8
+ field: o.field,
9
+ descending: (_a = o.descending) !== null && _a !== void 0 ? _a : false,
10
+ });
11
+ });
12
+ };
13
+ exports.getProtobufDataOrder = getProtobufDataOrder;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./management/client";
2
2
  export * from "./delivery/client";
3
- export { Filter, FieldFilter } from "./delivery/getDataList";
3
+ export { Filter, FieldFilter } from "./delivery/filter";
4
+ export { Order } from "./delivery/order";
4
5
  export { ClientConfig } from "./config/config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/projections-nodejs",
6
6
  "repository": {
@@ -27,10 +27,10 @@
27
27
  "projections": "dist/cmd/projections.js"
28
28
  },
29
29
  "dependencies": {
30
- "@fraym/projections-proto": "^1.0.0-alpha.11",
30
+ "@fraym/projections-proto": "^1.0.0-alpha.12",
31
31
  "@graphql-tools/graphql-file-loader": "^7.5.11",
32
32
  "@graphql-tools/load": "^7.8.6",
33
- "@grpc/grpc-js": "1.7.2",
33
+ "@grpc/grpc-js": "^1.8.7",
34
34
  "dotenv": "^16.0.3",
35
35
  "graphql": "^16.6.0",
36
36
  "yargs": "^17.6.2"