blixify-server 0.3.25 → 0.3.27

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;IAiT5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA+ZlC;IAEF,IAAI,YAiFF;CACH"}
@@ -824,23 +824,151 @@ 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 &&
839
+ Array.isArray(unionCollections) &&
840
+ unionCollections.length > 0) {
841
+ if (aggregate) {
842
+ res.status(400).json({
843
+ err: "Union operations cannot be combined with aggregate",
844
+ });
845
+ return;
846
+ }
847
+ const sort = (_v = req.body.sort) !== null && _v !== void 0 ? _v : { date: -1 };
848
+ const limit = (_w = req.body.limit) !== null && _w !== void 0 ? _w : 50;
849
+ const skip = (_x = req.body.skip) !== null && _x !== void 0 ? _x : 0;
850
+ const pipeline = [];
851
+ // Build unionWith pipeline
852
+ unionCollections.forEach((collectionConfig, index) => {
853
+ const projectStage = {
854
+ $project: Object.assign({ _id: 1 }, collectionConfig.projection),
855
+ };
856
+ // INFO: sourceLogic can be a string literal or a MongoDB expression object
857
+ if (collectionConfig.sourceLogic) {
858
+ projectStage.$project.source =
859
+ typeof collectionConfig.sourceLogic === "string"
860
+ ? { $literal: collectionConfig.sourceLogic }
861
+ : collectionConfig.sourceLogic;
862
+ }
863
+ else {
864
+ projectStage.$project.source = {
865
+ $literal: collectionConfig.source,
866
+ };
867
+ }
868
+ if (index === 0) {
869
+ if (queryList && queryList.length > 0) {
870
+ pipeline.push({ $match: queryFilter });
871
+ }
872
+ if (collectionConfig.query && collectionConfig.query.length > 0) {
873
+ const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
874
+ pipeline.push({ $match: collectionQueryFilter });
875
+ }
876
+ // INFO: addFields must be before $project so computed fields are available for sorting
877
+ if (collectionConfig.addFields) {
878
+ pipeline.push({ $addFields: collectionConfig.addFields });
879
+ // INFO: also include addFields keys in projection so they survive the $project stage
880
+ Object.keys(collectionConfig.addFields).forEach((key) => {
881
+ projectStage.$project[key] = 1;
882
+ });
883
+ }
884
+ pipeline.push(projectStage);
885
+ }
886
+ else {
887
+ const unionPipeline = [];
888
+ if (collectionConfig.query && collectionConfig.query.length > 0) {
889
+ const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
890
+ unionPipeline.push({ $match: collectionQueryFilter });
891
+ }
892
+ // INFO: addFields must be before $project so computed fields are available for sorting
893
+ if (collectionConfig.addFields) {
894
+ unionPipeline.push({ $addFields: collectionConfig.addFields });
895
+ // INFO: also include addFields keys in projection so they survive the $project stage
896
+ Object.keys(collectionConfig.addFields).forEach((key) => {
897
+ projectStage.$project[key] = 1;
898
+ });
899
+ }
900
+ unionPipeline.push(projectStage);
901
+ const unionStage = {
902
+ $unionWith: {
903
+ coll: collectionConfig.collection,
904
+ pipeline: unionPipeline,
905
+ },
906
+ };
907
+ pipeline.push(unionStage);
908
+ }
909
+ });
910
+ if (sort) {
911
+ const sortStage = { $sort: {} };
912
+ if (Array.isArray(sort)) {
913
+ sort.forEach((sortItem) => {
914
+ if (sortItem.sortId) {
915
+ sortStage.$sort[sortItem.sortId] =
916
+ sortItem.type === "asc" ? 1 : -1;
917
+ }
918
+ });
919
+ }
920
+ else if (sort.sortId && sort.type) {
921
+ sortStage.$sort[sort.sortId] = sort.type === "asc" ? 1 : -1;
922
+ }
923
+ else {
924
+ sortStage.$sort = sort;
925
+ }
926
+ pipeline.push(sortStage);
927
+ }
928
+ if (skip > 0) {
929
+ pipeline.push({ $skip: skip });
930
+ }
931
+ if (limit > 0) {
932
+ pipeline.push({ $limit: limit });
933
+ }
934
+ const mongoCollection = this.mongoDB
935
+ .db(this.tableId)
936
+ .collection(this.collection);
937
+ const dataList = yield mongoCollection.aggregate(pipeline).toArray();
938
+ const countPipeline = pipeline.filter((stage) => {
939
+ const stageKey = Object.keys(stage)[0];
940
+ return stageKey !== "$skip" && stageKey !== "$limit";
941
+ });
942
+ countPipeline.push({ $count: "total" });
943
+ const countResult = yield mongoCollection
944
+ .aggregate(countPipeline)
945
+ .toArray();
946
+ const count = ((_y = countResult[0]) === null || _y === void 0 ? void 0 : _y.total) || 0;
947
+ let validOpsConfig = true;
948
+ dataList.map((eachData) => {
949
+ if (!(0, QueryModel_1.checkOpsConfig)(this.config, "read", req, eachData)) {
950
+ validOpsConfig = false;
951
+ }
952
+ });
953
+ if (!validBaseConfig || !validOpsConfig) {
954
+ res.status(400).json({ err: "Invalid Security Configuration" });
955
+ return;
956
+ }
957
+ const resBody = {
958
+ data: dataList,
959
+ count,
960
+ };
961
+ if ((_z = req.body) === null || _z === void 0 ? void 0 : _z.stopRes)
962
+ return resBody;
963
+ res.send(resBody);
964
+ return;
965
+ }
837
966
  if (aggregate) {
838
- // INFO : Step 2 - Aggregate
839
967
  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";
968
+ const queryId = (_0 = aggregate.queryId) !== null && _0 !== void 0 ? _0 : "";
969
+ const dateId = (_1 = aggregate.dateId) !== null && _1 !== void 0 ? _1 : "baseUpdatedAt";
842
970
  const timezone = aggregate.timezone || "Asia/Kuala_Lumpur";
843
- const dateRanges = (_w = aggregate.range) !== null && _w !== void 0 ? _w : [
971
+ const dateRanges = (_2 = aggregate.range) !== null && _2 !== void 0 ? _2 : [
844
972
  (0, moment_timezone_1.default)().tz(timezone).format("DD/MM/YYYY HH:mm:ss"),
845
973
  ];
846
974
  for (const dateRange of dateRanges) {
@@ -886,7 +1014,6 @@ class MongoWrapper {
886
1014
  const id = isDuration
887
1015
  ? dateRange
888
1016
  : `Begining until ${(0, moment_timezone_1.default)(startDate, "DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY")}`;
889
- //INFO : Check for Unwinding
890
1017
  let unwindUnique = false;
891
1018
  if (aggregate.unwind && aggregate.unwind.length > 0) {
892
1019
  aggregate.unwind.map((eachUnwind, index) => {
@@ -984,8 +1111,8 @@ class MongoWrapper {
984
1111
  if (aggregate.groupId)
985
1112
  value = result;
986
1113
  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 : [];
1114
+ value = (_4 = (_3 = result[0]) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 0;
1115
+ ids = (_6 = (_5 = result[0]) === null || _5 === void 0 ? void 0 : _5.ids) !== null && _6 !== void 0 ? _6 : [];
989
1116
  }
990
1117
  dataList.push({
991
1118
  _id: id,
@@ -996,7 +1123,7 @@ class MongoWrapper {
996
1123
  const resBody = {
997
1124
  data: dataList,
998
1125
  };
999
- if ((_1 = req.body) === null || _1 === void 0 ? void 0 : _1.stopRes)
1126
+ if ((_7 = req.body) === null || _7 === void 0 ? void 0 : _7.stopRes)
1000
1127
  return resBody;
1001
1128
  res.send(resBody);
1002
1129
  }
@@ -1005,7 +1132,6 @@ class MongoWrapper {
1005
1132
  .db(this.tableId)
1006
1133
  .collection(this.collection);
1007
1134
  const pipeline = this.handleBuildPipeline(req);
1008
- // Create countPipeline by removing $skip and $limit stages
1009
1135
  const countPipeline = pipeline.filter((stage) => {
1010
1136
  const stageKey = Object.keys(stage)[0];
1011
1137
  return stageKey !== "$skip" && stageKey !== "$limit";
@@ -1015,7 +1141,7 @@ class MongoWrapper {
1015
1141
  mongoCollection.aggregate(pipeline).toArray(),
1016
1142
  mongoCollection.aggregate(countPipeline).toArray(),
1017
1143
  ]);
1018
- const count = ((_2 = countResult[0]) === null || _2 === void 0 ? void 0 : _2.total) || 0;
1144
+ const count = ((_8 = countResult[0]) === null || _8 === void 0 ? void 0 : _8.total) || 0;
1019
1145
  //INFO : Security Checker
1020
1146
  let validOpsConfig = true;
1021
1147
  if (dataList.length > 0) {
@@ -1033,7 +1159,7 @@ class MongoWrapper {
1033
1159
  data: dataList,
1034
1160
  count,
1035
1161
  };
1036
- if ((_3 = req.body) === null || _3 === void 0 ? void 0 : _3.stopRes)
1162
+ if ((_9 = req.body) === null || _9 === void 0 ? void 0 : _9.stopRes)
1037
1163
  return resBody;
1038
1164
  res.send(resBody);
1039
1165
  }
@@ -1109,6 +1235,7 @@ class MongoWrapper {
1109
1235
  /**
1110
1236
  * @Input
1111
1237
  * query - Query interface (Optional)
1238
+ * unionCollections - Array of collection configs with source and projection (Optional)
1112
1239
  * cursor - any (Optional)
1113
1240
  * limit - number (Optional)
1114
1241
  * sort - Array Sort or Sort interface (Optional)
@@ -1155,7 +1282,8 @@ class MongoWrapper {
1155
1282
  };
1156
1283
  if (condition && condition.length > 0) {
1157
1284
  condition.forEach((cond) => {
1158
- lookupStage.$lookup.let[`local_${cond.fromColumnId}`] = `$${cond.fromColumnId}`;
1285
+ lookupStage.$lookup.let[`local_${cond.fromColumnId}`] =
1286
+ `$${cond.fromColumnId}`;
1159
1287
  });
1160
1288
  const matchStage = {
1161
1289
  $match: { $expr: { $and: [] } },
@@ -1234,7 +1362,8 @@ class MongoWrapper {
1234
1362
  },
1235
1363
  });
1236
1364
  referenceSpaceLabel.forEach((field) => {
1237
- addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] = `$${defaultReferenceAs}.${field}`;
1365
+ addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] =
1366
+ `$${defaultReferenceAs}.${field}`;
1238
1367
  });
1239
1368
  }
1240
1369
  else {
@@ -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.27",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,