@heliyos/heliyos-api-core 1.0.28 → 1.0.29

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.
Files changed (2) hide show
  1. package/dist/mongoose.js +41 -18
  2. package/package.json +1 -1
package/dist/mongoose.js CHANGED
@@ -57,18 +57,16 @@ class MongoConnectionManager {
57
57
  return {
58
58
  maxPoolSize: parseInt(process.env.MONGO_MAX_POOL_SIZE || "10", 10),
59
59
  minPoolSize: parseInt(process.env.MONGO_MIN_POOL_SIZE || "1", 10),
60
- socketTimeoutMS: 30000,
60
+ socketTimeoutMS: 45000,
61
61
  connectTimeoutMS: 30000,
62
62
  serverSelectionTimeoutMS: 30000,
63
- heartbeatFrequencyMS: 10000,
63
+ heartbeatFrequencyMS: 30000,
64
64
  retryWrites: true,
65
65
  retryReads: true,
66
- directConnection: false,
67
- maxConnecting: 2,
68
- minHeartbeatFrequencyMS: 500,
69
- // Add these recommended settings
70
- autoCreate: false, // Disable automatic index creation
71
- autoIndex: false, // Disable automatic index creation
66
+ maxConnecting: 1,
67
+ minHeartbeatFrequencyMS: 2000,
68
+ // Add monitoring capability
69
+ monitorCommands: true,
72
70
  };
73
71
  }
74
72
  static getInstance() {
@@ -129,15 +127,40 @@ function initializeDatabase() {
129
127
  }
130
128
  mongoose_1.default.Query.prototype.paginate = function () {
131
129
  return __awaiter(this, arguments, void 0, function* (page = 1, limit = 10) {
132
- const offset = (page - 1) * limit;
133
- const countQuery = this.model.find().merge(this);
134
- const [total, data] = yield Promise.all([
135
- countQuery.countDocuments(),
136
- this.skip(offset).limit(limit),
137
- ]);
138
- return {
139
- data,
140
- meta: { page, limit, offset, count: total },
141
- };
130
+ var _a;
131
+ try {
132
+ const offset = (page - 1) * limit;
133
+ const startTime = Date.now();
134
+ const [result] = yield this.facet({
135
+ metadata: [{ $count: "total" }],
136
+ data: [{ $skip: offset }, { $limit: limit }],
137
+ });
138
+ const endTime = Date.now();
139
+ logger_1.logger.debug("Pagination query time:", {
140
+ duration: endTime - startTime,
141
+ page,
142
+ limit,
143
+ });
144
+ const total = ((_a = result.metadata[0]) === null || _a === void 0 ? void 0 : _a.total) || 0;
145
+ const data = result.data;
146
+ return {
147
+ data,
148
+ meta: {
149
+ page,
150
+ limit,
151
+ offset,
152
+ count: total,
153
+ },
154
+ };
155
+ }
156
+ catch (error) {
157
+ logger_1.logger.error("Pagination error:", {
158
+ error,
159
+ query: this.getQuery(),
160
+ page,
161
+ limit,
162
+ });
163
+ throw error;
164
+ }
142
165
  });
143
166
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliyos/heliyos-api-core",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {