@abtnode/core 1.17.7-beta-20251225-073259-cb6ecf68 → 1.17.7-beta-20251229-085620-84f09930

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 (41) hide show
  1. package/lib/blocklet/manager/disk.js +150 -36
  2. package/lib/blocklet/manager/ensure-blocklet-running.js +1 -1
  3. package/lib/blocklet/manager/helper/blue-green-start-blocklet.js +1 -1
  4. package/lib/blocklet/manager/helper/install-application-from-general.js +2 -3
  5. package/lib/blocklet/manager/helper/install-component-from-url.js +7 -4
  6. package/lib/blocklet/migration-dist/migration.cjs +5 -4
  7. package/lib/blocklet/passport/index.js +10 -3
  8. package/lib/blocklet/project/index.js +7 -2
  9. package/lib/blocklet/security/index.js +2 -2
  10. package/lib/cert.js +6 -3
  11. package/lib/event/index.js +98 -87
  12. package/lib/event/util.js +7 -13
  13. package/lib/index.js +18 -27
  14. package/lib/migrations/1.17.7-beta-2025122601-settings-authentication.js +19 -0
  15. package/lib/migrations/1.5.0-site.js +3 -7
  16. package/lib/migrations/1.5.15-site.js +3 -7
  17. package/lib/monitor/blocklet-runtime-monitor.js +37 -5
  18. package/lib/monitor/node-runtime-monitor.js +4 -4
  19. package/lib/router/helper.js +525 -452
  20. package/lib/router/index.js +280 -104
  21. package/lib/router/manager.js +14 -28
  22. package/lib/states/audit-log.js +6 -3
  23. package/lib/states/blocklet-child.js +93 -1
  24. package/lib/states/blocklet-extras.js +1 -1
  25. package/lib/states/blocklet.js +429 -197
  26. package/lib/states/node.js +0 -10
  27. package/lib/states/site.js +87 -4
  28. package/lib/team/manager.js +2 -21
  29. package/lib/util/blocklet.js +71 -37
  30. package/lib/util/get-accessible-external-node-ip.js +21 -6
  31. package/lib/util/index.js +3 -3
  32. package/lib/util/ip.js +15 -1
  33. package/lib/util/launcher.js +11 -11
  34. package/lib/util/ready.js +2 -9
  35. package/lib/util/reset-node.js +6 -5
  36. package/lib/validators/router.js +0 -3
  37. package/lib/webhook/sender/api/index.js +5 -0
  38. package/package.json +35 -37
  39. package/lib/migrations/1.0.36-snapshot.js +0 -10
  40. package/lib/migrations/1.1.9-snapshot.js +0 -7
  41. package/lib/states/routing-snapshot.js +0 -146
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- const { BlockletStatus } = require('@blocklet/constant');
2
+ const { Sequelize } = require('sequelize');
3
+ const { BlockletStatus, BLOCKLET_INTERFACE_TYPE_SERVICE } = require('@blocklet/constant');
3
4
  const BaseState = require('./base');
4
5
 
5
6
  /**
@@ -247,6 +248,97 @@ class BlockletChildState extends BaseState {
247
248
  const [, [updated]] = await this.update({ parentBlockletId, childDid }, { $set: updates });
248
249
  return updated;
249
250
  }
251
+
252
+ /**
253
+ * Get aggregated status counts using efficient SQL GROUP BY
254
+ * This avoids loading all children into memory for counting
255
+ * @returns {Promise<{total: number, counts: Object}>} - Total count and counts by status
256
+ */
257
+ async getStatusCounts() {
258
+ try {
259
+ // Use raw SQL for efficient GROUP BY COUNT aggregation
260
+ // This is O(1) memory vs O(n) for loading all records
261
+ const results = await this.query(`
262
+ SELECT status, COUNT(*) as count
263
+ FROM blocklet_children
264
+ GROUP BY status
265
+ `);
266
+
267
+ const counts = {};
268
+ let total = 0;
269
+
270
+ for (const row of results) {
271
+ const { status, count: countStr } = row;
272
+ const count = parseInt(countStr, 10);
273
+ counts[status] = count;
274
+ total += count;
275
+ }
276
+
277
+ return { total, counts };
278
+ } catch (error) {
279
+ // Fallback: return empty counts on error
280
+ return { total: 0, counts: {} };
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Get count of children by status value
286
+ * @param {number} status - The status value to count
287
+ * @returns {Promise<number>} - Count of children with the given status
288
+ */
289
+ countByStatus(status) {
290
+ return this.count({ status });
291
+ }
292
+
293
+ /**
294
+ * Get all port-related data from all children (optimized for _getOccupiedPorts)
295
+ * Only fetches necessary fields to minimize memory usage
296
+ * @returns {Promise<Array<{ports: Object, greenPorts: Object, meta: Object}>>}
297
+ */
298
+ async getAllPorts() {
299
+ const results = await this.model.findAll({
300
+ attributes: ['ports', 'greenPorts', 'meta'],
301
+ raw: true,
302
+ });
303
+ return results;
304
+ }
305
+
306
+ /**
307
+ * Get children that have SERVICE type interfaces (optimized for getServices)
308
+ * Uses database-level JSON filtering to reduce data transfer
309
+ * Works with both SQLite and PostgreSQL
310
+ * @returns {Promise<Array<{meta: Object, ports: Object, greenPorts: Object, greenStatus: number}>>}
311
+ */
312
+ async getChildrenWithServiceInterfaces() {
313
+ const dialect = this.model.sequelize.getDialect();
314
+
315
+ let condition;
316
+
317
+ if (dialect === 'postgres') {
318
+ // PostgreSQL: Use jsonb_array_elements to check interface types
319
+ condition = Sequelize.literal(`
320
+ EXISTS (
321
+ SELECT 1 FROM jsonb_array_elements(meta->'interfaces') AS iface
322
+ WHERE iface->>'type' = '${BLOCKLET_INTERFACE_TYPE_SERVICE}'
323
+ )
324
+ `);
325
+ } else {
326
+ // SQLite: Use json_each and json_extract for interface type check
327
+ condition = Sequelize.literal(`
328
+ EXISTS (
329
+ SELECT 1 FROM json_each(json_extract(meta, '$.interfaces'))
330
+ WHERE json_extract(value, '$.type') = '${BLOCKLET_INTERFACE_TYPE_SERVICE}'
331
+ )
332
+ `);
333
+ }
334
+
335
+ const results = await this.model.findAll({
336
+ attributes: ['meta', 'ports', 'greenPorts', 'greenStatus'],
337
+ where: condition,
338
+ });
339
+
340
+ return results.map((x) => x.toJSON());
341
+ }
250
342
  }
251
343
 
252
344
  module.exports = BlockletChildState;
@@ -349,7 +349,7 @@ class BlockletExtrasState extends BaseState {
349
349
  }
350
350
 
351
351
  getWafDisabledBlocklets() {
352
- return super.find({ where: { 'settings.gateway.wafPolicy.enabled': false } });
352
+ return super.find({ where: { 'settings.gateway.wafPolicy.enabled': false } }, { did: 1 });
353
353
  }
354
354
  }
355
355