@abtnode/core 1.17.7-beta-20251227-001958-ea2ba3f5 → 1.17.7-beta-20251229-223813-e1e6c5e3
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.
- package/lib/blocklet/manager/disk.js +74 -32
- package/lib/blocklet/manager/ensure-blocklet-running.js +1 -1
- package/lib/blocklet/manager/helper/blue-green-start-blocklet.js +1 -1
- package/lib/blocklet/manager/helper/install-application-from-general.js +2 -3
- package/lib/blocklet/manager/helper/install-component-from-url.js +7 -4
- package/lib/blocklet/migration-dist/migration.cjs +5 -4
- package/lib/blocklet/passport/index.js +10 -3
- package/lib/blocklet/project/index.js +7 -2
- package/lib/blocklet/security/index.js +2 -2
- package/lib/cert.js +6 -3
- package/lib/event/index.js +98 -87
- package/lib/event/util.js +7 -13
- package/lib/index.js +15 -26
- package/lib/migrations/1.5.0-site.js +3 -7
- package/lib/migrations/1.5.15-site.js +3 -7
- package/lib/monitor/blocklet-runtime-monitor.js +37 -5
- package/lib/monitor/node-runtime-monitor.js +4 -4
- package/lib/router/helper.js +525 -452
- package/lib/router/index.js +280 -104
- package/lib/router/manager.js +14 -28
- package/lib/states/blocklet-child.js +93 -1
- package/lib/states/blocklet-extras.js +1 -1
- package/lib/states/blocklet.js +429 -197
- package/lib/states/node.js +0 -10
- package/lib/states/site.js +87 -4
- package/lib/team/manager.js +2 -21
- package/lib/util/blocklet.js +39 -19
- package/lib/util/get-accessible-external-node-ip.js +21 -6
- package/lib/util/index.js +3 -3
- package/lib/util/ip.js +15 -1
- package/lib/util/launcher.js +11 -11
- package/lib/util/ready.js +2 -9
- package/lib/util/reset-node.js +6 -5
- package/lib/validators/router.js +0 -3
- package/lib/webhook/sender/api/index.js +5 -0
- package/package.json +23 -25
- package/lib/migrations/1.0.36-snapshot.js +0 -10
- package/lib/migrations/1.1.9-snapshot.js +0 -7
- package/lib/states/routing-snapshot.js +0 -146
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
const {
|
|
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
|
|