blixify-server 0.3.26 → 0.3.28

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 +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,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAgB3D,UAAU,SAAU,GAAG,SAIrB;IAEF,aAAa,YACF,GAAG,QACN,QAAQ,GAAG,QAAQ,GAAG,QAAQ,OAC/B,GAAG,UACA;QACN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AQ,GAAG,CAAC;;mBAwCtC;IAEF,mBAAmB,CAAC,GAAG,EAAE,GAAG;IAiT5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA+ZlC;IAEF,IAAI,YAiFF;CACH"}
@@ -824,7 +824,7 @@ 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, _4, _5, _6, _7, _8, _9;
827
+ var _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
828
828
  try {
829
829
  //INFO : Security Checker
830
830
  const validBaseConfig = (0, QueryModel_1.checkBaseConfig)(this.config, req);
@@ -835,26 +835,35 @@ class MongoWrapper {
835
835
  let queryFilter = {};
836
836
  // INFO : Step 1 - Query
837
837
  queryFilter = handleParseQueryFilter(queryList);
838
- if (unionCollections && Array.isArray(unionCollections) && unionCollections.length > 0) {
838
+ if (unionCollections &&
839
+ Array.isArray(unionCollections) &&
840
+ unionCollections.length > 0) {
839
841
  if (aggregate) {
840
- res.status(400).json({ err: "Union operations cannot be combined with aggregate" });
842
+ res.status(400).json({
843
+ err: "Union operations cannot be combined with aggregate",
844
+ });
841
845
  return;
842
846
  }
843
847
  const sort = (_v = req.body.sort) !== null && _v !== void 0 ? _v : { date: -1 };
844
848
  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;
849
+ const skip = (_y = (_x = req.body.cursor) !== null && _x !== void 0 ? _x : req.body.skip) !== null && _y !== void 0 ? _y : 0;
846
850
  const pipeline = [];
847
851
  // Build unionWith pipeline
848
852
  unionCollections.forEach((collectionConfig, index) => {
849
853
  const projectStage = {
850
- $project: Object.assign({ _id: 1 }, collectionConfig.projection)
854
+ $project: Object.assign({ _id: 1 }, collectionConfig.projection),
851
855
  };
852
- // Handle dynamic source field
856
+ // INFO: sourceLogic can be a string literal or a MongoDB expression object
853
857
  if (collectionConfig.sourceLogic) {
854
- projectStage.$project.source = collectionConfig.sourceLogic;
858
+ projectStage.$project.source =
859
+ typeof collectionConfig.sourceLogic === "string"
860
+ ? { $literal: collectionConfig.sourceLogic }
861
+ : collectionConfig.sourceLogic;
855
862
  }
856
863
  else {
857
- projectStage.$project.source = { $literal: collectionConfig.source };
864
+ projectStage.$project.source = {
865
+ $literal: collectionConfig.source,
866
+ };
858
867
  }
859
868
  if (index === 0) {
860
869
  if (queryList && queryList.length > 0) {
@@ -864,8 +873,13 @@ class MongoWrapper {
864
873
  const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
865
874
  pipeline.push({ $match: collectionQueryFilter });
866
875
  }
867
- else if (collectionConfig.match) {
868
- pipeline.push({ $match: collectionConfig.match });
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
+ });
869
883
  }
870
884
  pipeline.push(projectStage);
871
885
  }
@@ -875,15 +889,20 @@ class MongoWrapper {
875
889
  const collectionQueryFilter = handleParseQueryFilter(collectionConfig.query);
876
890
  unionPipeline.push({ $match: collectionQueryFilter });
877
891
  }
878
- else if (collectionConfig.match) {
879
- unionPipeline.push({ $match: collectionConfig.match });
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
+ });
880
899
  }
881
900
  unionPipeline.push(projectStage);
882
901
  const unionStage = {
883
902
  $unionWith: {
884
903
  coll: collectionConfig.collection,
885
- pipeline: unionPipeline
886
- }
904
+ pipeline: unionPipeline,
905
+ },
887
906
  };
888
907
  pipeline.push(unionStage);
889
908
  }
@@ -893,7 +912,8 @@ class MongoWrapper {
893
912
  if (Array.isArray(sort)) {
894
913
  sort.forEach((sortItem) => {
895
914
  if (sortItem.sortId) {
896
- sortStage.$sort[sortItem.sortId] = sortItem.type === "asc" ? 1 : -1;
915
+ sortStage.$sort[sortItem.sortId] =
916
+ sortItem.type === "asc" ? 1 : -1;
897
917
  }
898
918
  });
899
919
  }
@@ -920,8 +940,10 @@ class MongoWrapper {
920
940
  return stageKey !== "$skip" && stageKey !== "$limit";
921
941
  });
922
942
  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;
943
+ const countResult = yield mongoCollection
944
+ .aggregate(countPipeline)
945
+ .toArray();
946
+ const count = ((_z = countResult[0]) === null || _z === void 0 ? void 0 : _z.total) || 0;
925
947
  let validOpsConfig = true;
926
948
  dataList.map((eachData) => {
927
949
  if (!(0, QueryModel_1.checkOpsConfig)(this.config, "read", req, eachData)) {
@@ -936,17 +958,17 @@ class MongoWrapper {
936
958
  data: dataList,
937
959
  count,
938
960
  };
939
- if ((_z = req.body) === null || _z === void 0 ? void 0 : _z.stopRes)
961
+ if ((_0 = req.body) === null || _0 === void 0 ? void 0 : _0.stopRes)
940
962
  return resBody;
941
963
  res.send(resBody);
942
964
  return;
943
965
  }
944
966
  if (aggregate) {
945
967
  const dataList = [];
946
- const queryId = (_0 = aggregate.queryId) !== null && _0 !== void 0 ? _0 : "";
947
- const dateId = (_1 = aggregate.dateId) !== null && _1 !== void 0 ? _1 : "baseUpdatedAt";
968
+ const queryId = (_1 = aggregate.queryId) !== null && _1 !== void 0 ? _1 : "";
969
+ const dateId = (_2 = aggregate.dateId) !== null && _2 !== void 0 ? _2 : "baseUpdatedAt";
948
970
  const timezone = aggregate.timezone || "Asia/Kuala_Lumpur";
949
- const dateRanges = (_2 = aggregate.range) !== null && _2 !== void 0 ? _2 : [
971
+ const dateRanges = (_3 = aggregate.range) !== null && _3 !== void 0 ? _3 : [
950
972
  (0, moment_timezone_1.default)().tz(timezone).format("DD/MM/YYYY HH:mm:ss"),
951
973
  ];
952
974
  for (const dateRange of dateRanges) {
@@ -1089,8 +1111,8 @@ class MongoWrapper {
1089
1111
  if (aggregate.groupId)
1090
1112
  value = result;
1091
1113
  else {
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 : [];
1114
+ value = (_5 = (_4 = result[0]) === null || _4 === void 0 ? void 0 : _4.value) !== null && _5 !== void 0 ? _5 : 0;
1115
+ ids = (_7 = (_6 = result[0]) === null || _6 === void 0 ? void 0 : _6.ids) !== null && _7 !== void 0 ? _7 : [];
1094
1116
  }
1095
1117
  dataList.push({
1096
1118
  _id: id,
@@ -1101,7 +1123,7 @@ class MongoWrapper {
1101
1123
  const resBody = {
1102
1124
  data: dataList,
1103
1125
  };
1104
- if ((_7 = req.body) === null || _7 === void 0 ? void 0 : _7.stopRes)
1126
+ if ((_8 = req.body) === null || _8 === void 0 ? void 0 : _8.stopRes)
1105
1127
  return resBody;
1106
1128
  res.send(resBody);
1107
1129
  }
@@ -1119,7 +1141,7 @@ class MongoWrapper {
1119
1141
  mongoCollection.aggregate(pipeline).toArray(),
1120
1142
  mongoCollection.aggregate(countPipeline).toArray(),
1121
1143
  ]);
1122
- const count = ((_8 = countResult[0]) === null || _8 === void 0 ? void 0 : _8.total) || 0;
1144
+ const count = ((_9 = countResult[0]) === null || _9 === void 0 ? void 0 : _9.total) || 0;
1123
1145
  //INFO : Security Checker
1124
1146
  let validOpsConfig = true;
1125
1147
  if (dataList.length > 0) {
@@ -1137,7 +1159,7 @@ class MongoWrapper {
1137
1159
  data: dataList,
1138
1160
  count,
1139
1161
  };
1140
- if ((_9 = req.body) === null || _9 === void 0 ? void 0 : _9.stopRes)
1162
+ if ((_10 = req.body) === null || _10 === void 0 ? void 0 : _10.stopRes)
1141
1163
  return resBody;
1142
1164
  res.send(resBody);
1143
1165
  }
@@ -1260,7 +1282,8 @@ class MongoWrapper {
1260
1282
  };
1261
1283
  if (condition && condition.length > 0) {
1262
1284
  condition.forEach((cond) => {
1263
- lookupStage.$lookup.let[`local_${cond.fromColumnId}`] = `$${cond.fromColumnId}`;
1285
+ lookupStage.$lookup.let[`local_${cond.fromColumnId}`] =
1286
+ `$${cond.fromColumnId}`;
1264
1287
  });
1265
1288
  const matchStage = {
1266
1289
  $match: { $expr: { $and: [] } },
@@ -1339,7 +1362,8 @@ class MongoWrapper {
1339
1362
  },
1340
1363
  });
1341
1364
  referenceSpaceLabel.forEach((field) => {
1342
- addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] = `$${defaultReferenceAs}.${field}`;
1365
+ addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] =
1366
+ `$${defaultReferenceAs}.${field}`;
1343
1367
  });
1344
1368
  }
1345
1369
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.3.26",
3
+ "version": "0.3.28",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,