@xtr-dev/rondevu-server 0.5.1 → 0.5.6

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/src/index.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { serve } from '@hono/node-server';
2
2
  import { createApp } from './app.ts';
3
- import { loadConfig } from './config.ts';
4
- import { SQLiteStorage } from './storage/sqlite.ts';
3
+ import { loadConfig, runCleanup } from './config.ts';
4
+ import { createStorage } from './storage/factory.ts';
5
5
  import { Storage } from './storage/types.ts';
6
6
 
7
- /**
8
- * Main entry point for the standalone Node.js server
9
- */
10
7
  async function main() {
11
8
  const config = loadConfig();
12
9
 
@@ -14,32 +11,30 @@ async function main() {
14
11
  console.log('Configuration:', {
15
12
  port: config.port,
16
13
  storageType: config.storageType,
17
- storagePath: config.storagePath,
14
+ storagePath: config.storageType === 'sqlite' ? config.storagePath : undefined,
15
+ databaseUrl: config.databaseUrl ? '[configured]' : undefined,
16
+ dbPoolSize: ['mysql', 'postgres'].includes(config.storageType) ? config.dbPoolSize : undefined,
18
17
  offerDefaultTtl: `${config.offerDefaultTtl}ms`,
19
- offerMaxTtl: `${config.offerMaxTtl}ms`,
20
- offerMinTtl: `${config.offerMinTtl}ms`,
21
18
  cleanupInterval: `${config.cleanupInterval}ms`,
22
- maxOffersPerRequest: config.maxOffersPerRequest,
23
- corsOrigins: config.corsOrigins,
24
19
  version: config.version,
25
20
  });
26
21
 
27
- let storage: Storage;
28
-
29
- if (config.storageType === 'sqlite') {
30
- storage = new SQLiteStorage(config.storagePath);
31
- console.log('Using SQLite storage');
32
- } else {
33
- throw new Error('Unsupported storage type');
34
- }
22
+ const storage: Storage = await createStorage({
23
+ type: config.storageType,
24
+ masterEncryptionKey: config.masterEncryptionKey,
25
+ sqlitePath: config.storagePath,
26
+ connectionString: config.databaseUrl,
27
+ poolSize: config.dbPoolSize,
28
+ });
29
+ console.log(`Using ${config.storageType} storage`);
35
30
 
36
- // Start periodic cleanup of expired offers
37
- const cleanupInterval = setInterval(async () => {
31
+ // Periodic cleanup
32
+ const cleanupTimer = setInterval(async () => {
38
33
  try {
39
- const now = Date.now();
40
- const deleted = await storage.deleteExpiredOffers(now);
41
- if (deleted > 0) {
42
- console.log(`Cleanup: Deleted ${deleted} expired offer(s)`);
34
+ const result = await runCleanup(storage, Date.now());
35
+ const total = result.offers + result.credentials + result.rateLimits + result.nonces;
36
+ if (total > 0) {
37
+ console.log(`Cleanup: ${result.offers} offers, ${result.credentials} credentials, ${result.rateLimits} rate limits, ${result.nonces} nonces`);
43
38
  }
44
39
  } catch (err) {
45
40
  console.error('Cleanup error:', err);
@@ -59,7 +54,7 @@ async function main() {
59
54
  // Graceful shutdown handler
60
55
  const shutdown = async () => {
61
56
  console.log('\nShutting down gracefully...');
62
- clearInterval(cleanupInterval);
57
+ clearInterval(cleanupTimer);
63
58
  await storage.close();
64
59
  process.exit(0);
65
60
  };