@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9

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 (54) hide show
  1. package/dist/Application-DtWDHXr1.d.ts +2110 -0
  2. package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
  3. package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
  4. package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
  5. package/dist/EventManager-CmIoLt7r.d.ts +207 -0
  6. package/dist/Gate-CNkBYf8m.d.ts +268 -0
  7. package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
  8. package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
  9. package/dist/LogManager-7mxnkaPM.d.ts +256 -0
  10. package/dist/MailManager-DpMvYiP9.d.ts +292 -0
  11. package/dist/Scheduler-BstvSca7.d.ts +469 -0
  12. package/dist/StorageManager-oZTHqaza.d.ts +337 -0
  13. package/dist/api-token-JOif2CtG.d.ts +1792 -0
  14. package/dist/app-key-CsBfRC_Q.d.ts +214 -0
  15. package/dist/auth/index.d.ts +418 -0
  16. package/dist/auth/index.js +6742 -0
  17. package/dist/authorization/index.d.ts +129 -0
  18. package/dist/authorization/index.js +621 -0
  19. package/dist/broadcasting/index.d.ts +233 -0
  20. package/dist/broadcasting/index.js +907 -0
  21. package/dist/cache/index.d.ts +233 -0
  22. package/dist/cache/index.js +817 -0
  23. package/dist/encryption/index.d.ts +222 -0
  24. package/dist/encryption/index.js +602 -0
  25. package/dist/events/index.d.ts +155 -0
  26. package/dist/events/index.js +330 -0
  27. package/dist/health/index.d.ts +185 -0
  28. package/dist/health/index.js +379 -0
  29. package/dist/i18n/index.d.ts +101 -0
  30. package/dist/i18n/index.js +597 -0
  31. package/dist/index-9_Jzj5jo.d.ts +7 -0
  32. package/dist/index.d.ts +2628 -619
  33. package/dist/index.js +22229 -3116
  34. package/dist/lambda/index.d.ts +156 -0
  35. package/dist/lambda/index.js +91 -0
  36. package/dist/logging/index.d.ts +50 -0
  37. package/dist/logging/index.js +557 -0
  38. package/dist/mail/index.d.ts +288 -0
  39. package/dist/mail/index.js +695 -0
  40. package/dist/mcp/index.d.ts +139 -0
  41. package/dist/mcp/index.js +382 -0
  42. package/dist/notifications/index.d.ts +271 -0
  43. package/dist/notifications/index.js +741 -0
  44. package/dist/queue/index.d.ts +423 -0
  45. package/dist/queue/index.js +958 -0
  46. package/dist/runtime/index.d.ts +93 -0
  47. package/dist/runtime/index.js +834 -0
  48. package/dist/scheduling/index.d.ts +41 -0
  49. package/dist/scheduling/index.js +836 -0
  50. package/dist/storage/index.d.ts +196 -0
  51. package/dist/storage/index.js +832 -0
  52. package/dist/vite/index.js +203 -3
  53. package/package.json +93 -6
  54. package/dist/chunk-FK2XQSBF.js +0 -160
@@ -0,0 +1,379 @@
1
+ // src/health/HealthCheck.ts
2
+ var HealthCheck = class {
3
+ /**
4
+ * Create a healthy result.
5
+ */
6
+ healthy(message, meta) {
7
+ return this.result("healthy", message, meta);
8
+ }
9
+ /**
10
+ * Create a degraded result.
11
+ */
12
+ degraded(message, meta) {
13
+ return this.result("degraded", message, meta);
14
+ }
15
+ /**
16
+ * Create an unhealthy result.
17
+ */
18
+ unhealthy(message, meta) {
19
+ return this.result("unhealthy", message, meta);
20
+ }
21
+ /**
22
+ * Create an unhealthy result from a caught error.
23
+ */
24
+ handleError(error, fallbackMessage) {
25
+ return this.unhealthy(
26
+ error instanceof Error ? error.message : fallbackMessage
27
+ );
28
+ }
29
+ /**
30
+ * Create a check result.
31
+ */
32
+ result(status, message, meta) {
33
+ const result = {
34
+ name: this.name,
35
+ status,
36
+ duration: 0
37
+ // Will be set by HealthManager
38
+ };
39
+ if (message !== void 0) {
40
+ result.message = message;
41
+ }
42
+ if (meta !== void 0) {
43
+ result.meta = meta;
44
+ }
45
+ return result;
46
+ }
47
+ };
48
+
49
+ // src/health/HealthManager.ts
50
+ var HealthManager = class {
51
+ checks = /* @__PURE__ */ new Map();
52
+ /**
53
+ * Register a health check.
54
+ */
55
+ register(check, options = {}) {
56
+ this.checks.set(check.name, {
57
+ check,
58
+ options: {
59
+ timeout: options.timeout ?? 5e3,
60
+ critical: options.critical ?? false
61
+ }
62
+ });
63
+ return this;
64
+ }
65
+ /**
66
+ * Unregister a health check.
67
+ */
68
+ unregister(name) {
69
+ this.checks.delete(name);
70
+ return this;
71
+ }
72
+ /**
73
+ * Get all registered check names.
74
+ */
75
+ getCheckNames() {
76
+ return Array.from(this.checks.keys());
77
+ }
78
+ /**
79
+ * Run all health checks.
80
+ */
81
+ async check() {
82
+ return this.runChecks(this.getCheckNames());
83
+ }
84
+ /**
85
+ * Run specific health checks.
86
+ */
87
+ async checkOnly(names) {
88
+ const validNames = names.filter((name) => this.checks.has(name));
89
+ return this.runChecks(validNames);
90
+ }
91
+ /**
92
+ * Get a specific check result.
93
+ */
94
+ async getCheck(name) {
95
+ const registered = this.checks.get(name);
96
+ if (!registered) {
97
+ return null;
98
+ }
99
+ return this.runCheck(registered);
100
+ }
101
+ /**
102
+ * Create middleware for health endpoints.
103
+ */
104
+ middleware(options = {}) {
105
+ return async (ctx, next) => {
106
+ const report = options.checks ? await this.checkOnly(options.checks) : await this.check();
107
+ const statusCode = report.status === "healthy" ? 200 : report.status === "degraded" ? 200 : 503;
108
+ if (options.detailed === false) {
109
+ ctx.status(statusCode);
110
+ ctx.json({
111
+ status: report.status,
112
+ timestamp: report.timestamp.toISOString()
113
+ });
114
+ } else {
115
+ ctx.status(statusCode);
116
+ ctx.json({
117
+ status: report.status,
118
+ timestamp: report.timestamp.toISOString(),
119
+ checks: report.checks.map((check) => ({
120
+ name: check.name,
121
+ status: check.status,
122
+ message: check.message,
123
+ duration: check.duration,
124
+ meta: check.meta
125
+ }))
126
+ });
127
+ }
128
+ };
129
+ }
130
+ /**
131
+ * Run the specified checks.
132
+ */
133
+ async runChecks(names) {
134
+ const results = [];
135
+ let overallStatus = "healthy";
136
+ await Promise.all(
137
+ names.map(async (name) => {
138
+ const registered = this.checks.get(name);
139
+ if (!registered) return;
140
+ const result = await this.runCheck(registered);
141
+ results.push(result);
142
+ if (result.status === "unhealthy") {
143
+ if (registered.options.critical) {
144
+ overallStatus = "unhealthy";
145
+ } else if (overallStatus !== "unhealthy") {
146
+ overallStatus = "degraded";
147
+ }
148
+ } else if (result.status === "degraded" && overallStatus === "healthy") {
149
+ overallStatus = "degraded";
150
+ }
151
+ })
152
+ );
153
+ results.sort((a, b) => a.name.localeCompare(b.name));
154
+ return {
155
+ status: overallStatus,
156
+ timestamp: /* @__PURE__ */ new Date(),
157
+ checks: results
158
+ };
159
+ }
160
+ /**
161
+ * Run a single check with timeout.
162
+ */
163
+ async runCheck(registered) {
164
+ const { check, options } = registered;
165
+ const start = performance.now();
166
+ try {
167
+ const result = await Promise.race([
168
+ check.check(),
169
+ this.timeoutPromise(options.timeout)
170
+ ]);
171
+ result.duration = Math.round(performance.now() - start);
172
+ return result;
173
+ } catch (error) {
174
+ const duration = Math.round(performance.now() - start);
175
+ return {
176
+ name: check.name,
177
+ status: "unhealthy",
178
+ message: error instanceof Error ? error.message : "Check failed with error",
179
+ duration
180
+ };
181
+ }
182
+ }
183
+ /**
184
+ * Create a timeout promise.
185
+ */
186
+ timeoutPromise(ms) {
187
+ return new Promise((_, reject) => {
188
+ setTimeout(() => {
189
+ reject(new Error(`Health check timed out after ${ms}ms`));
190
+ }, ms);
191
+ });
192
+ }
193
+ };
194
+ function createHealthManager() {
195
+ return new HealthManager();
196
+ }
197
+
198
+ // src/health/checks/DatabaseCheck.ts
199
+ var DatabaseCheck = class extends HealthCheck {
200
+ name;
201
+ db;
202
+ query;
203
+ constructor(db, options = {}) {
204
+ super();
205
+ this.db = db;
206
+ this.name = options.name ?? "database";
207
+ this.query = options.query ?? "SELECT 1";
208
+ }
209
+ async check() {
210
+ try {
211
+ await this.db.query(this.query);
212
+ return this.healthy("Database connection is healthy");
213
+ } catch (error) {
214
+ return this.handleError(error, "Database connection failed");
215
+ }
216
+ }
217
+ };
218
+
219
+ // src/health/checks/RedisCheck.ts
220
+ var RedisCheck = class extends HealthCheck {
221
+ name;
222
+ redis;
223
+ constructor(redis, options = {}) {
224
+ super();
225
+ this.redis = redis;
226
+ this.name = options.name ?? "redis";
227
+ }
228
+ async check() {
229
+ try {
230
+ const response = await this.redis.ping();
231
+ if (response === "PONG") {
232
+ return this.healthy("Redis connection is healthy");
233
+ }
234
+ return this.degraded(`Redis ping returned: ${response}`);
235
+ } catch (error) {
236
+ return this.handleError(error, "Redis connection failed");
237
+ }
238
+ }
239
+ };
240
+
241
+ // src/health/checks/CacheCheck.ts
242
+ var CacheCheck = class extends HealthCheck {
243
+ name;
244
+ cache;
245
+ testKey;
246
+ constructor(cache, options = {}) {
247
+ super();
248
+ this.cache = cache;
249
+ this.name = options.name ?? "cache";
250
+ this.testKey = options.testKey ?? "__health_check__";
251
+ }
252
+ async check() {
253
+ const testValue = `health_check_${Date.now()}`;
254
+ try {
255
+ await this.cache.put(this.testKey, testValue, 60);
256
+ const retrieved = await this.cache.get(this.testKey);
257
+ await this.cache.forget(this.testKey);
258
+ if (retrieved === testValue) {
259
+ return this.healthy("Cache is functioning correctly");
260
+ }
261
+ return this.degraded(
262
+ `Cache read/write mismatch: expected "${testValue}", got "${retrieved}"`
263
+ );
264
+ } catch (error) {
265
+ return this.handleError(error, "Cache operation failed");
266
+ }
267
+ }
268
+ };
269
+
270
+ // src/health/checks/StorageCheck.ts
271
+ var StorageCheck = class extends HealthCheck {
272
+ name;
273
+ storage;
274
+ testPath;
275
+ constructor(storage, options = {}) {
276
+ super();
277
+ this.storage = storage;
278
+ this.name = options.name ?? "storage";
279
+ this.testPath = options.testPath ?? "__health_check__.txt";
280
+ }
281
+ async check() {
282
+ const testContent = `health_check_${Date.now()}`;
283
+ try {
284
+ await this.storage.put(this.testPath, testContent);
285
+ const retrieved = await this.storage.get(this.testPath);
286
+ await this.storage.delete(this.testPath);
287
+ if (retrieved && retrieved.toString() === testContent) {
288
+ return this.healthy("Storage is functioning correctly");
289
+ }
290
+ return this.degraded("Storage read/write mismatch");
291
+ } catch (error) {
292
+ return this.handleError(error, "Storage operation failed");
293
+ }
294
+ }
295
+ };
296
+
297
+ // src/health/checks/MemoryCheck.ts
298
+ var MemoryCheck = class extends HealthCheck {
299
+ name;
300
+ thresholdMb;
301
+ criticalThresholdMb;
302
+ constructor(options = {}) {
303
+ super();
304
+ this.name = options.name ?? "memory";
305
+ this.thresholdMb = options.thresholdMb ?? 512;
306
+ this.criticalThresholdMb = options.criticalThresholdMb ?? 1024;
307
+ }
308
+ async check() {
309
+ const usage = process.memoryUsage();
310
+ const usedMb = Math.round(usage.heapUsed / 1024 / 1024);
311
+ const totalMb = Math.round(usage.heapTotal / 1024 / 1024);
312
+ const rssMb = Math.round(usage.rss / 1024 / 1024);
313
+ const meta = {
314
+ usedMb,
315
+ totalMb,
316
+ rssMb,
317
+ thresholdMb: this.thresholdMb,
318
+ criticalThresholdMb: this.criticalThresholdMb
319
+ };
320
+ if (usedMb >= this.criticalThresholdMb) {
321
+ return this.unhealthy(
322
+ `Memory usage critical: ${usedMb}MB (threshold: ${this.criticalThresholdMb}MB)`,
323
+ meta
324
+ );
325
+ }
326
+ if (usedMb >= this.thresholdMb) {
327
+ return this.degraded(
328
+ `Memory usage elevated: ${usedMb}MB (threshold: ${this.thresholdMb}MB)`,
329
+ meta
330
+ );
331
+ }
332
+ return this.healthy(`Memory usage normal: ${usedMb}MB`, meta);
333
+ }
334
+ };
335
+
336
+ // src/health/checks/CustomCheck.ts
337
+ var CustomCheck = class extends HealthCheck {
338
+ name;
339
+ callback;
340
+ constructor(name, callback) {
341
+ super();
342
+ this.name = name;
343
+ this.callback = callback;
344
+ }
345
+ async check() {
346
+ try {
347
+ const result = await this.callback();
348
+ switch (result.status) {
349
+ case "healthy":
350
+ return this.healthy(result.message, result.meta);
351
+ case "degraded":
352
+ return this.degraded(result.message, result.meta);
353
+ case "unhealthy":
354
+ return this.unhealthy(result.message, result.meta);
355
+ default:
356
+ return this.unhealthy("Unknown status returned from check");
357
+ }
358
+ } catch (error) {
359
+ return this.unhealthy(
360
+ error instanceof Error ? error.message : "Custom check failed"
361
+ );
362
+ }
363
+ }
364
+ };
365
+ function customCheck(name, callback) {
366
+ return new CustomCheck(name, callback);
367
+ }
368
+ export {
369
+ CacheCheck,
370
+ CustomCheck,
371
+ DatabaseCheck,
372
+ HealthCheck,
373
+ HealthManager,
374
+ MemoryCheck,
375
+ RedisCheck,
376
+ StorageCheck,
377
+ createHealthManager,
378
+ customCheck
379
+ };
@@ -0,0 +1,101 @@
1
+ import { P as PluralizationRule, T as TranslationLoader, c as TranslationMessages } from '../I18nManager-Dtgzsf5n.js';
2
+ export { a as I18nConfig, I as I18nManager, R as ReplacementValues, b as TranslationLoaderFactory, d as Translator, e as TranslatorOptions, f as createI18n, g as getI18n, s as setI18n, t, h as tc } from '../I18nManager-Dtgzsf5n.js';
3
+
4
+ /**
5
+ * Default pluralization rules for common languages.
6
+ *
7
+ * Returns the index of the plural form to use.
8
+ * Most languages use: 0 = one, 1 = other
9
+ * Some languages have more complex rules.
10
+ */
11
+ declare const pluralizationRules: Record<string, PluralizationRule>;
12
+ /**
13
+ * Get pluralization rule for a locale.
14
+ */
15
+ declare function getPluralizationRule(locale: string): PluralizationRule;
16
+ /**
17
+ * Select the appropriate plural form from a translation.
18
+ *
19
+ * Translation format: "singular|plural" or "one|few|many"
20
+ */
21
+ declare function selectPluralForm(translation: string, count: number, rule: PluralizationRule): string;
22
+
23
+ /**
24
+ * JSON file-based translation loader.
25
+ *
26
+ * Expected directory structure:
27
+ * path/
28
+ * en/
29
+ * messages.json
30
+ * validation.json
31
+ * ja/
32
+ * messages.json
33
+ * validation.json
34
+ */
35
+ declare class JsonLoader implements TranslationLoader {
36
+ private basePath;
37
+ private cache;
38
+ private useCache;
39
+ constructor(basePath: string, options?: {
40
+ cache?: boolean;
41
+ });
42
+ /**
43
+ * Load all translations for a locale.
44
+ */
45
+ load(locale: string): Promise<TranslationMessages>;
46
+ /**
47
+ * Load translations for a specific namespace.
48
+ */
49
+ loadNamespace(locale: string, namespace: string): Promise<TranslationMessages>;
50
+ /**
51
+ * Get available locales.
52
+ */
53
+ getAvailableLocales(): Promise<string[]>;
54
+ /**
55
+ * Clear the cache.
56
+ */
57
+ clearCache(): void;
58
+ /**
59
+ * Enable or disable caching.
60
+ */
61
+ setCaching(enabled: boolean): void;
62
+ }
63
+
64
+ /**
65
+ * In-memory translation loader.
66
+ * Useful for testing or when translations are bundled with the application.
67
+ */
68
+ declare class MemoryLoader implements TranslationLoader {
69
+ private messages;
70
+ constructor(messages?: Record<string, TranslationMessages>);
71
+ /**
72
+ * Load all translations for a locale.
73
+ */
74
+ load(locale: string): Promise<TranslationMessages>;
75
+ /**
76
+ * Load translations for a specific namespace.
77
+ */
78
+ loadNamespace(locale: string, namespace: string): Promise<TranslationMessages>;
79
+ /**
80
+ * Get available locales.
81
+ */
82
+ getAvailableLocales(): Promise<string[]>;
83
+ /**
84
+ * Add messages for a locale.
85
+ */
86
+ addMessages(locale: string, messages: TranslationMessages): void;
87
+ /**
88
+ * Set messages for a locale (replaces existing).
89
+ */
90
+ setMessages(locale: string, messages: TranslationMessages): void;
91
+ /**
92
+ * Remove messages for a locale.
93
+ */
94
+ removeLocale(locale: string): void;
95
+ /**
96
+ * Clear all messages.
97
+ */
98
+ clear(): void;
99
+ }
100
+
101
+ export { JsonLoader, MemoryLoader, PluralizationRule, TranslationLoader, TranslationMessages, getPluralizationRule, pluralizationRules, selectPluralForm };