blixify-server 0.3.25 → 0.3.26

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.
@@ -48,10 +48,10 @@ export declare class MongoWrapper {
48
48
  } | undefined>;
49
49
  handleBuildPipeline(req: any): any[];
50
50
  initList: (req: any, res: any) => Promise<{
51
- data: any[];
52
- } | {
53
51
  data: any;
54
52
  count: any;
53
+ } | {
54
+ data: any[];
55
55
  } | undefined>;
56
56
  init: () => any;
57
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AA6JD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,SAAM;IACX,WAAW,EAAE,GAAG,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAM;IAC7B,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACzC,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,KAAK,CA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H,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqGtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAsJ5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAwCtC;IAEF,mBAAmB,CAAC,GAAG,EAAE,GAAG;IAmT5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBAkYlC;IAEF,IAAI,YAkFF;CACH"}
@@ -824,23 +824,129 @@ class MongoWrapper {
824
824
  }
825
825
  });
826
826
  this.initList = (req, res) => __awaiter(this, void 0, void 0, function* () {
827
- var _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
827
+ var _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
828
828
  try {
829
829
  //INFO : Security Checker
830
830
  const validBaseConfig = (0, QueryModel_1.checkBaseConfig)(this.config, req);
831
831
  if (validBaseConfig) {
832
832
  const aggregate = req.body.aggregate;
833
- const queryList = (_t = req.body.query) !== null && _t !== void 0 ? _t : [];
833
+ const unionCollections = (_t = req.body.unionCollections) !== null && _t !== void 0 ? _t : [];
834
+ const queryList = (_u = req.body.query) !== null && _u !== void 0 ? _u : [];
834
835
  let queryFilter = {};
835
836
  // INFO : Step 1 - Query
836
837
  queryFilter = handleParseQueryFilter(queryList);
838
+ if (unionCollections && Array.isArray(unionCollections) && unionCollections.length > 0) {
839
+ if (aggregate) {
840
+ res.status(400).json({ err: "Union operations cannot be combined with aggregate" });
841
+ return;
842
+ }
843
+ const sort = (_v = req.body.sort) !== null && _v !== void 0 ? _v : { date: -1 };
844
+ const limit = (_w = req.body.limit) !== null && _w !== void 0 ? _w : 50;
845
+ const skip = (_x = req.body.skip) !== null && _x !== void 0 ? _x : 0;
846
+ const pipeline = [];
847
+ // Build unionWith pipeline
848
+ unionCollections.forEach((collectionConfig, index) => {
849
+ const projectStage = {
850
+ $project: Object.assign({ _id: 1 }, collectionConfig.projection)
851
+ };
852
+ // Handle dynamic source field
853
+ if (collectionConfig.sourceLogic) {
854
+ projectStage.$project.source = collectionConfig.sourceLogic;
855
+ }
856
+ else {
857
+ projectStage.$project.source = { $literal: collectionConfig.source };
858
+ }
859
+ if (index === 0) {
860
+ if (queryList && queryList.length > 0) {
861
+ pipeline.push({ $match: queryFilter });
862
+ }
863
+ if (collectionConfig.query && collectionConfig.query.length > 0) {
864
+ const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
865
+ pipeline.push({ $match: collectionQueryFilter });
866
+ }
867
+ else if (collectionConfig.match) {
868
+ pipeline.push({ $match: collectionConfig.match });
869
+ }
870
+ pipeline.push(projectStage);
871
+ }
872
+ else {
873
+ const unionPipeline = [];
874
+ if (collectionConfig.query && collectionConfig.query.length > 0) {
875
+ const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
876
+ unionPipeline.push({ $match: collectionQueryFilter });
877
+ }
878
+ else if (collectionConfig.match) {
879
+ unionPipeline.push({ $match: collectionConfig.match });
880
+ }
881
+ unionPipeline.push(projectStage);
882
+ const unionStage = {
883
+ $unionWith: {
884
+ coll: collectionConfig.collection,
885
+ pipeline: unionPipeline
886
+ }
887
+ };
888
+ pipeline.push(unionStage);
889
+ }
890
+ });
891
+ if (sort) {
892
+ const sortStage = { $sort: {} };
893
+ if (Array.isArray(sort)) {
894
+ sort.forEach((sortItem) => {
895
+ if (sortItem.sortId) {
896
+ sortStage.$sort[sortItem.sortId] = sortItem.type === "asc" ? 1 : -1;
897
+ }
898
+ });
899
+ }
900
+ else if (sort.sortId && sort.type) {
901
+ sortStage.$sort[sort.sortId] = sort.type === "asc" ? 1 : -1;
902
+ }
903
+ else {
904
+ sortStage.$sort = sort;
905
+ }
906
+ pipeline.push(sortStage);
907
+ }
908
+ if (skip > 0) {
909
+ pipeline.push({ $skip: skip });
910
+ }
911
+ if (limit > 0) {
912
+ pipeline.push({ $limit: limit });
913
+ }
914
+ const mongoCollection = this.mongoDB
915
+ .db(this.tableId)
916
+ .collection(this.collection);
917
+ const dataList = yield mongoCollection.aggregate(pipeline).toArray();
918
+ const countPipeline = pipeline.filter((stage) => {
919
+ const stageKey = Object.keys(stage)[0];
920
+ return stageKey !== "$skip" && stageKey !== "$limit";
921
+ });
922
+ countPipeline.push({ $count: "total" });
923
+ const countResult = yield mongoCollection.aggregate(countPipeline).toArray();
924
+ const count = ((_y = countResult[0]) === null || _y === void 0 ? void 0 : _y.total) || 0;
925
+ let validOpsConfig = true;
926
+ dataList.map((eachData) => {
927
+ if (!(0, QueryModel_1.checkOpsConfig)(this.config, "read", req, eachData)) {
928
+ validOpsConfig = false;
929
+ }
930
+ });
931
+ if (!validBaseConfig || !validOpsConfig) {
932
+ res.status(400).json({ err: "Invalid Security Configuration" });
933
+ return;
934
+ }
935
+ const resBody = {
936
+ data: dataList,
937
+ count,
938
+ };
939
+ if ((_z = req.body) === null || _z === void 0 ? void 0 : _z.stopRes)
940
+ return resBody;
941
+ res.send(resBody);
942
+ return;
943
+ }
837
944
  if (aggregate) {
838
- // INFO : Step 2 - Aggregate
839
945
  const dataList = [];
840
- const queryId = (_u = aggregate.queryId) !== null && _u !== void 0 ? _u : "";
841
- const dateId = (_v = aggregate.dateId) !== null && _v !== void 0 ? _v : "baseUpdatedAt";
946
+ const queryId = (_0 = aggregate.queryId) !== null && _0 !== void 0 ? _0 : "";
947
+ const dateId = (_1 = aggregate.dateId) !== null && _1 !== void 0 ? _1 : "baseUpdatedAt";
842
948
  const timezone = aggregate.timezone || "Asia/Kuala_Lumpur";
843
- const dateRanges = (_w = aggregate.range) !== null && _w !== void 0 ? _w : [
949
+ const dateRanges = (_2 = aggregate.range) !== null && _2 !== void 0 ? _2 : [
844
950
  (0, moment_timezone_1.default)().tz(timezone).format("DD/MM/YYYY HH:mm:ss"),
845
951
  ];
846
952
  for (const dateRange of dateRanges) {
@@ -886,7 +992,6 @@ class MongoWrapper {
886
992
  const id = isDuration
887
993
  ? dateRange
888
994
  : `Begining until ${(0, moment_timezone_1.default)(startDate, "DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY")}`;
889
- //INFO : Check for Unwinding
890
995
  let unwindUnique = false;
891
996
  if (aggregate.unwind && aggregate.unwind.length > 0) {
892
997
  aggregate.unwind.map((eachUnwind, index) => {
@@ -984,8 +1089,8 @@ class MongoWrapper {
984
1089
  if (aggregate.groupId)
985
1090
  value = result;
986
1091
  else {
987
- value = (_y = (_x = result[0]) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0;
988
- ids = (_0 = (_z = result[0]) === null || _z === void 0 ? void 0 : _z.ids) !== null && _0 !== void 0 ? _0 : [];
1092
+ value = (_4 = (_3 = result[0]) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 0;
1093
+ ids = (_6 = (_5 = result[0]) === null || _5 === void 0 ? void 0 : _5.ids) !== null && _6 !== void 0 ? _6 : [];
989
1094
  }
990
1095
  dataList.push({
991
1096
  _id: id,
@@ -996,7 +1101,7 @@ class MongoWrapper {
996
1101
  const resBody = {
997
1102
  data: dataList,
998
1103
  };
999
- if ((_1 = req.body) === null || _1 === void 0 ? void 0 : _1.stopRes)
1104
+ if ((_7 = req.body) === null || _7 === void 0 ? void 0 : _7.stopRes)
1000
1105
  return resBody;
1001
1106
  res.send(resBody);
1002
1107
  }
@@ -1005,7 +1110,6 @@ class MongoWrapper {
1005
1110
  .db(this.tableId)
1006
1111
  .collection(this.collection);
1007
1112
  const pipeline = this.handleBuildPipeline(req);
1008
- // Create countPipeline by removing $skip and $limit stages
1009
1113
  const countPipeline = pipeline.filter((stage) => {
1010
1114
  const stageKey = Object.keys(stage)[0];
1011
1115
  return stageKey !== "$skip" && stageKey !== "$limit";
@@ -1015,7 +1119,7 @@ class MongoWrapper {
1015
1119
  mongoCollection.aggregate(pipeline).toArray(),
1016
1120
  mongoCollection.aggregate(countPipeline).toArray(),
1017
1121
  ]);
1018
- const count = ((_2 = countResult[0]) === null || _2 === void 0 ? void 0 : _2.total) || 0;
1122
+ const count = ((_8 = countResult[0]) === null || _8 === void 0 ? void 0 : _8.total) || 0;
1019
1123
  //INFO : Security Checker
1020
1124
  let validOpsConfig = true;
1021
1125
  if (dataList.length > 0) {
@@ -1033,7 +1137,7 @@ class MongoWrapper {
1033
1137
  data: dataList,
1034
1138
  count,
1035
1139
  };
1036
- if ((_3 = req.body) === null || _3 === void 0 ? void 0 : _3.stopRes)
1140
+ if ((_9 = req.body) === null || _9 === void 0 ? void 0 : _9.stopRes)
1037
1141
  return resBody;
1038
1142
  res.send(resBody);
1039
1143
  }
@@ -1109,6 +1213,7 @@ class MongoWrapper {
1109
1213
  /**
1110
1214
  * @Input
1111
1215
  * query - Query interface (Optional)
1216
+ * unionCollections - Array of collection configs with source and projection (Optional)
1112
1217
  * cursor - any (Optional)
1113
1218
  * limit - number (Optional)
1114
1219
  * sort - Array Sort or Sort interface (Optional)
@@ -1 +1 @@
1
- {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/apis/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAE7B,mBAAmB,UAAiB,MAAM,qBAExC;IACF,UAAU,WAAkB,MAAM,qBAEhC;IACF,SAAS,WAAkB,MAAM,qBAE/B;IACF,aAAa,aAAoB,MAAM,sBAErC;gBAIA,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EACvD,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC/C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC9C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;IAQvD;;;;OAIG;IACH,IAAI,UAG8C,GAAG,OAAO,GAAG,SAAS,GAAG;CA8B5E"}
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/apis/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAE7B,mBAAmB,UAAiB,MAAM,qBAExC;IACF,UAAU,WAAkB,MAAM,qBAEhC;IACF,SAAS,WAAkB,MAAM,qBAE/B;IACF,aAAa,aAAoB,MAAM,sBAErC;gBAIA,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EACvD,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC/C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC9C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;IAQvD;;;;OAIG;IACH,IAAI,UAG8C,GAAG,OAAO,GAAG,SAAS,GAAG;CAgC5E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,