@fraym/projections 0.16.0 → 0.18.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.
@@ -1,4 +1,4 @@
1
- import { AuthData as PbAuthData } from "@fraym/projections-proto";
1
+ import { AuthData as PbAuthData } from "@fraym/proto/freym/projections/delivery";
2
2
  export interface AuthData {
3
3
  tenantId: string;
4
4
  scopes: string[];
@@ -8,7 +8,9 @@ import { EventMetadata } from "./eventMetadata";
8
8
  import { Wait } from "./wait";
9
9
  export interface DeliveryClient {
10
10
  getData: <T extends {}>(projection: string, authData: AuthData, id: string, filter?: Filter, returnEmptyDataIfNotFound?: boolean, wait?: Wait) => Promise<T | null>;
11
+ getViewData: <T extends {}>(view: string, authData: AuthData, filter?: Filter) => Promise<T | null>;
11
12
  getDataList: <T extends {}>(projection: string, authData: AuthData, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetProjectionDataList<T> | null>;
13
+ getViewDataList: <T extends {}>(view: string, authData: AuthData, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetProjectionDataList<T> | null>;
12
14
  upsertData: <T extends {}>(projection: string, authData: AuthData, dataId: string, payload: Record<string, any>, eventMetadata?: EventMetadata) => Promise<UpsertResponse<T>>;
13
15
  deleteDataById: (projection: string, authData: AuthData, dataId: string, eventMetadata?: EventMetadata) => Promise<number>;
14
16
  deleteDataByFilter: (projection: string, authData: AuthData, filter?: Filter, eventMetadata?: EventMetadata) => Promise<number>;
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.newDeliveryClient = void 0;
4
- const projections_proto_1 = require("@fraym/projections-proto");
4
+ const delivery_1 = require("@fraym/proto/freym/projections/delivery");
5
5
  const grpc_js_1 = require("@grpc/grpc-js");
6
6
  const config_1 = require("../config/config");
7
7
  const getData_1 = require("./getData");
8
8
  const getDataList_1 = require("./getDataList");
9
9
  const upsert_1 = require("./upsert");
10
10
  const delete_1 = require("./delete");
11
+ const getViewData_1 = require("./getViewData");
12
+ const getViewDataList_1 = require("./getViewDataList");
11
13
  const newDeliveryClient = async (config) => {
12
14
  config = (0, config_1.useDeliveryConfigDefaults)(config);
13
- const serviceClient = new projections_proto_1.DeliveryServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
15
+ const serviceClient = new delivery_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
14
16
  "grpc.keepalive_time_ms": config.keepaliveInterval,
15
17
  "grpc.keepalive_timeout_ms": config.keepaliveTimeout,
16
18
  "grpc.keepalive_permit_without_calls": 1,
@@ -18,9 +20,15 @@ const newDeliveryClient = async (config) => {
18
20
  const getData = async (projection, auth, id, filter = { fields: {}, and: [], or: [] }, returnEmptyDataIfNotFound = false, wait) => {
19
21
  return await (0, getData_1.getProjectionData)(projection, auth, id, filter, returnEmptyDataIfNotFound, serviceClient, wait);
20
22
  };
23
+ const getViewData = async (view, auth, filter = { fields: {}, and: [], or: [] }) => {
24
+ return await (0, getViewData_1.getViewData)(view, auth, filter, serviceClient);
25
+ };
21
26
  const getDataList = async (projection, auth, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }, order = []) => {
22
27
  return await (0, getDataList_1.getProjectionDataList)(projection, auth, limit, page, filter, order, serviceClient);
23
28
  };
29
+ const getViewDataList = async (view, auth, limit = 0, page = 1, filter = { fields: {}, and: [], or: [] }, order = []) => {
30
+ return await (0, getViewDataList_1.getViewDataList)(view, auth, limit, page, filter, order, serviceClient);
31
+ };
24
32
  const upsertData = async (projection, authData, dataId, payload, eventMetadata = { causationId: "", correlationId: "" }) => {
25
33
  return (0, upsert_1.upsertProjectionData)(projection, authData, dataId, payload, eventMetadata, serviceClient);
26
34
  };
@@ -35,7 +43,9 @@ const newDeliveryClient = async (config) => {
35
43
  };
36
44
  return {
37
45
  getData,
46
+ getViewData,
38
47
  getDataList,
48
+ getViewDataList,
39
49
  upsertData,
40
50
  deleteDataById,
41
51
  deleteDataByFilter,
@@ -1,5 +1,5 @@
1
- import { DeliveryServiceClient } from "@fraym/projections-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
2
  import { AuthData } from "./auth";
3
3
  import { EventMetadata } from "./eventMetadata";
4
4
  import { Filter } from "./filter";
5
- export declare const deleteProjectionData: (projection: string, auth: AuthData, dataId: string, filter: Filter, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<number>;
5
+ export declare const deleteProjectionData: (projection: string, auth: AuthData, dataId: string, filter: Filter, eventMetadata: EventMetadata, serviceClient: ServiceClient) => Promise<number>;
@@ -16,7 +16,7 @@ const deleteProjectionData = async (projection, auth, dataId, filter, eventMetad
16
16
  reject(error.message);
17
17
  return;
18
18
  }
19
- resolve(response.numberOfDeletedEntries);
19
+ resolve(parseInt(response.numberOfDeletedEntries, 10));
20
20
  });
21
21
  });
22
22
  };
@@ -1,4 +1,4 @@
1
- import { DataFilter } from "@fraym/projections-proto";
1
+ import { DataFilter } from "@fraym/proto/freym/projections/delivery";
2
2
  export interface Filter {
3
3
  fields: Record<string, FieldFilter>;
4
4
  and: Filter[];
@@ -1,5 +1,5 @@
1
- import { DeliveryServiceClient } from "@fraym/projections-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
2
  import { AuthData } from "./auth";
3
3
  import { Filter } from "./filter";
4
4
  import { Wait } from "./wait";
5
- export declare const getProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, filter: Filter, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient, wait?: Wait) => Promise<T | null>;
5
+ export declare const getProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, filter: Filter, returnEmptyDataIfNotFound: boolean, serviceClient: ServiceClient, wait?: Wait) => Promise<T | null>;
@@ -13,13 +13,14 @@ const getProjectionData = async (projection, auth, dataId, filter, returnEmptyDa
13
13
  filter: (0, filter_1.getProtobufDataFilter)(filter),
14
14
  returnEmptyDataIfNotFound,
15
15
  wait: (0, wait_1.getProtobufDataWait)(wait),
16
+ useStrongConsistency: false,
16
17
  }, (error, response) => {
17
18
  if (error) {
18
19
  reject(error.message);
19
20
  return;
20
21
  }
21
22
  const result = response.result;
22
- if (!result) {
23
+ if (!result || !result.data || Object.keys(result.data).length === 0) {
23
24
  resolve(null);
24
25
  return;
25
26
  }
@@ -1,4 +1,4 @@
1
- import { DeliveryServiceClient } from "@fraym/projections-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
2
  import { AuthData } from "./auth";
3
3
  import { Filter } from "./filter";
4
4
  import { Order } from "./order";
@@ -8,4 +8,4 @@ export interface GetProjectionDataList<T extends {}> {
8
8
  total: number;
9
9
  data: T[];
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>;
11
+ export declare const getProjectionDataList: <T extends {}>(projection: string, auth: AuthData, limit: number, page: number, filter: Filter, order: Order[], serviceClient: ServiceClient) => Promise<GetProjectionDataList<T> | null>;
@@ -9,10 +9,11 @@ const getProjectionDataList = async (projection, auth, limit, page, filter, orde
9
9
  serviceClient.getDataList({
10
10
  projection,
11
11
  auth: (0, auth_1.getProtobufAuthData)(auth),
12
- limit,
13
- page,
12
+ limit: limit.toString(),
13
+ page: page.toString(),
14
14
  filter: (0, filter_1.getProtobufDataFilter)(filter),
15
15
  order: (0, order_1.getProtobufDataOrder)(order),
16
+ useStrongConsistency: false,
16
17
  }, (error, response) => {
17
18
  if (error) {
18
19
  reject(error.message);
@@ -28,9 +29,9 @@ const getProjectionDataList = async (projection, auth, limit, page, filter, orde
28
29
  data.push(dataRecord);
29
30
  }
30
31
  resolve({
31
- limit: response.limit,
32
- page: response.page,
33
- total: response.total,
32
+ limit: parseInt(response.limit, 10),
33
+ page: parseInt(response.page, 10),
34
+ total: parseInt(response.total, 10),
34
35
  data,
35
36
  });
36
37
  });
@@ -0,0 +1,4 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
+ import { AuthData } from "./auth";
3
+ import { Filter } from "./filter";
4
+ export declare const getViewData: <T extends {}>(view: string, auth: AuthData, filter: Filter, serviceClient: ServiceClient) => Promise<T | null>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getViewData = void 0;
4
+ const auth_1 = require("./auth");
5
+ const filter_1 = require("./filter");
6
+ const getViewData = async (view, auth, filter, serviceClient) => {
7
+ return new Promise((resolve, reject) => {
8
+ serviceClient.getViewData({
9
+ view,
10
+ auth: (0, auth_1.getProtobufAuthData)(auth),
11
+ filter: (0, filter_1.getProtobufDataFilter)(filter),
12
+ useStrongConsistency: false,
13
+ }, (error, response) => {
14
+ if (error) {
15
+ reject(error.message);
16
+ return;
17
+ }
18
+ const result = response.result;
19
+ if (!result || !result.data || Object.keys(result.data).length === 0) {
20
+ resolve(null);
21
+ return;
22
+ }
23
+ const data = {};
24
+ for (const key in result.data) {
25
+ data[key] = JSON.parse(result.data[key]);
26
+ }
27
+ resolve(data);
28
+ });
29
+ });
30
+ };
31
+ exports.getViewData = getViewData;
@@ -0,0 +1,11 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
+ import { AuthData } from "./auth";
3
+ import { Filter } from "./filter";
4
+ import { Order } from "./order";
5
+ export interface GetViewDataList<T extends {}> {
6
+ limit: number;
7
+ page: number;
8
+ total: number;
9
+ data: T[];
10
+ }
11
+ export declare const getViewDataList: <T extends {}>(view: string, auth: AuthData, limit: number, page: number, filter: Filter, order: Order[], serviceClient: ServiceClient) => Promise<GetViewDataList<T> | null>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getViewDataList = void 0;
4
+ const auth_1 = require("./auth");
5
+ const filter_1 = require("./filter");
6
+ const order_1 = require("./order");
7
+ const getViewDataList = async (view, auth, limit, page, filter, order, serviceClient) => {
8
+ return new Promise((resolve, reject) => {
9
+ serviceClient.getViewDataList({
10
+ view,
11
+ auth: (0, auth_1.getProtobufAuthData)(auth),
12
+ limit: limit.toString(),
13
+ page: page.toString(),
14
+ filter: (0, filter_1.getProtobufDataFilter)(filter),
15
+ order: (0, order_1.getProtobufDataOrder)(order),
16
+ useStrongConsistency: false,
17
+ }, (error, response) => {
18
+ if (error) {
19
+ reject(error.message);
20
+ return;
21
+ }
22
+ const data = [];
23
+ for (const result of response.result) {
24
+ const dataRecord = {};
25
+ const resultData = result.data;
26
+ for (const key in resultData) {
27
+ dataRecord[key] = JSON.parse(resultData[key]);
28
+ }
29
+ data.push(dataRecord);
30
+ }
31
+ resolve({
32
+ limit: parseInt(response.limit, 10),
33
+ page: parseInt(response.page, 10),
34
+ total: parseInt(response.total, 10),
35
+ data,
36
+ });
37
+ });
38
+ });
39
+ };
40
+ exports.getViewDataList = getViewDataList;
@@ -1,4 +1,4 @@
1
- import { DataOrder } from "@fraym/projections-proto";
1
+ import { DataOrder } from "@fraym/proto/freym/projections/delivery";
2
2
  export interface Order {
3
3
  field: string;
4
4
  descending?: boolean;
@@ -1,4 +1,4 @@
1
- import { DeliveryServiceClient } from "@fraym/projections-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/projections/delivery";
2
2
  import { AuthData } from "./auth";
3
3
  import { EventMetadata } from "./eventMetadata";
4
4
  export type UpsertResponse<T extends {}> = UpsertSuccessResponse<T> | UpsertValidationResponse;
@@ -12,4 +12,4 @@ export interface UpsertValidationResponse {
12
12
  }
13
13
  export declare const isUpsertSuccessResponse: <T extends {}>(response: UpsertResponse<T>) => response is UpsertSuccessResponse<T>;
14
14
  export declare const isUpsertValidationResponse: <T extends {}>(response: UpsertResponse<T>) => response is UpsertValidationResponse;
15
- export declare const upsertProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, payload: Record<string, any>, eventMetadata: EventMetadata, serviceClient: DeliveryServiceClient) => Promise<UpsertResponse<T>>;
15
+ export declare const upsertProjectionData: <T extends {}>(projection: string, auth: AuthData, dataId: string, payload: Record<string, any>, eventMetadata: EventMetadata, serviceClient: ServiceClient) => Promise<UpsertResponse<T>>;
@@ -1,4 +1,4 @@
1
- import { DataWait } from "@fraym/projections-proto";
1
+ import { DataWait } from "@fraym/proto/freym/projections/delivery";
2
2
  import { Filter } from "./filter";
3
3
  export interface Wait {
4
4
  timeout?: number;
@@ -9,7 +9,7 @@ const getProtobufDataWait = (wait) => {
9
9
  }
10
10
  return {
11
11
  conditionFilter: (0, filter_1.getProtobufDataFilter)(wait.conditionFilter),
12
- timeout: (_a = wait.timeout) !== null && _a !== void 0 ? _a : 0,
12
+ timeout: ((_a = wait.timeout) !== null && _a !== void 0 ? _a : 0).toString(),
13
13
  };
14
14
  };
15
15
  exports.getProtobufDataWait = getProtobufDataWait;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/fraym/projections-nodejs",
6
6
  "repository": {
@@ -20,24 +20,27 @@
20
20
  "files": [
21
21
  "dist/**/*"
22
22
  ],
23
+ "engines": {
24
+ "node": ">=16"
25
+ },
23
26
  "main": "dist/index.js",
24
27
  "types": "dist/index.d.ts",
25
28
  "dependencies": {
26
- "@fraym/projections-proto": "^1.0.0",
29
+ "@fraym/proto": "^0.25.0",
27
30
  "@graphql-tools/graphql-file-loader": "^7.5.17",
28
31
  "@graphql-tools/load": "^7.8.14",
29
- "@grpc/grpc-js": "^1.8.18",
30
- "dotenv": "^16.3.1",
31
- "graphql": "^16.7.1",
32
+ "@grpc/grpc-js": "^1.11.3",
33
+ "dotenv": "^16.4.5",
34
+ "graphql": "^16.9.0",
32
35
  "yargs": "^17.7.2"
33
36
  },
34
37
  "devDependencies": {
35
38
  "@becklyn/prettier": "^1.0.2",
36
- "@types/uuid": "^9.0.2",
37
- "@types/yargs": "^17.0.24",
39
+ "@types/uuid": "^9.0.8",
40
+ "@types/yargs": "^17.0.33",
38
41
  "prettier": "^2.8.8",
39
- "typescript": "^5.1.6",
40
- "uuid": "^9.0.0"
42
+ "typescript": "^5.6.2",
43
+ "uuid": "^9.0.1"
41
44
  },
42
45
  "prettier": "@becklyn/prettier"
43
46
  }