@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.
- package/dist/Application-DtWDHXr1.d.ts +2110 -0
- package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
- package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
- package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
- package/dist/EventManager-CmIoLt7r.d.ts +207 -0
- package/dist/Gate-CNkBYf8m.d.ts +268 -0
- package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
- package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
- package/dist/LogManager-7mxnkaPM.d.ts +256 -0
- package/dist/MailManager-DpMvYiP9.d.ts +292 -0
- package/dist/Scheduler-BstvSca7.d.ts +469 -0
- package/dist/StorageManager-oZTHqaza.d.ts +337 -0
- package/dist/api-token-JOif2CtG.d.ts +1792 -0
- package/dist/app-key-CsBfRC_Q.d.ts +214 -0
- package/dist/auth/index.d.ts +418 -0
- package/dist/auth/index.js +6742 -0
- package/dist/authorization/index.d.ts +129 -0
- package/dist/authorization/index.js +621 -0
- package/dist/broadcasting/index.d.ts +233 -0
- package/dist/broadcasting/index.js +907 -0
- package/dist/cache/index.d.ts +233 -0
- package/dist/cache/index.js +817 -0
- package/dist/encryption/index.d.ts +222 -0
- package/dist/encryption/index.js +602 -0
- package/dist/events/index.d.ts +155 -0
- package/dist/events/index.js +330 -0
- package/dist/health/index.d.ts +185 -0
- package/dist/health/index.js +379 -0
- package/dist/i18n/index.d.ts +101 -0
- package/dist/i18n/index.js +597 -0
- package/dist/index-9_Jzj5jo.d.ts +7 -0
- package/dist/index.d.ts +2628 -619
- package/dist/index.js +22229 -3116
- package/dist/lambda/index.d.ts +156 -0
- package/dist/lambda/index.js +91 -0
- package/dist/logging/index.d.ts +50 -0
- package/dist/logging/index.js +557 -0
- package/dist/mail/index.d.ts +288 -0
- package/dist/mail/index.js +695 -0
- package/dist/mcp/index.d.ts +139 -0
- package/dist/mcp/index.js +382 -0
- package/dist/notifications/index.d.ts +271 -0
- package/dist/notifications/index.js +741 -0
- package/dist/queue/index.d.ts +423 -0
- package/dist/queue/index.js +958 -0
- package/dist/runtime/index.d.ts +93 -0
- package/dist/runtime/index.js +834 -0
- package/dist/scheduling/index.d.ts +41 -0
- package/dist/scheduling/index.js +836 -0
- package/dist/storage/index.d.ts +196 -0
- package/dist/storage/index.js +832 -0
- package/dist/vite/index.js +203 -3
- package/package.json +93 -6
- package/dist/chunk-FK2XQSBF.js +0 -160
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as hono_aws_lambda from 'hono/aws-lambda';
|
|
2
|
+
export { APIGatewayProxyResult, LambdaEvent } from 'hono/aws-lambda';
|
|
3
|
+
import { A as Application } from '../Application-DtWDHXr1.js';
|
|
4
|
+
import { S as Scheduler } from '../Scheduler-BstvSca7.js';
|
|
5
|
+
import { C as ConsoleKernel } from '../ConsoleKernel-CqCVrdZs.js';
|
|
6
|
+
import 'hono';
|
|
7
|
+
import '../api-token-JOif2CtG.js';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import '../EventManager-CmIoLt7r.js';
|
|
10
|
+
import '../CacheManager-BkvHEOZX.js';
|
|
11
|
+
import '../MailManager-DpMvYiP9.js';
|
|
12
|
+
import '../LogManager-7mxnkaPM.js';
|
|
13
|
+
import '../I18nManager-Dtgzsf5n.js';
|
|
14
|
+
import '../BroadcastManager-AkIWUGJo.js';
|
|
15
|
+
import '../index-9_Jzj5jo.js';
|
|
16
|
+
import '../app-key-CsBfRC_Q.js';
|
|
17
|
+
import '../StorageManager-oZTHqaza.js';
|
|
18
|
+
import '../HealthManager-DUyMIzsZ.js';
|
|
19
|
+
import '../Gate-CNkBYf8m.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* SQS event record from AWS Lambda.
|
|
23
|
+
*/
|
|
24
|
+
interface SqsRecord {
|
|
25
|
+
messageId: string;
|
|
26
|
+
receiptHandle: string;
|
|
27
|
+
body: string;
|
|
28
|
+
attributes: Record<string, string>;
|
|
29
|
+
messageAttributes: Record<string, unknown>;
|
|
30
|
+
md5OfBody: string;
|
|
31
|
+
eventSource: string;
|
|
32
|
+
eventSourceARN: string;
|
|
33
|
+
awsRegion: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* SQS event payload from AWS Lambda.
|
|
37
|
+
*/
|
|
38
|
+
interface SqsEvent {
|
|
39
|
+
Records: SqsRecord[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* SQS batch item failure for partial batch response.
|
|
43
|
+
*/
|
|
44
|
+
interface SqsBatchItemFailure {
|
|
45
|
+
itemIdentifier: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* SQS batch response with partial failures.
|
|
49
|
+
*/
|
|
50
|
+
interface SqsBatchResponse {
|
|
51
|
+
batchItemFailures: SqsBatchItemFailure[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create an AWS Lambda handler from a booted Guren application.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import app from './src/app'
|
|
59
|
+
* import { createLambdaHandler } from '@guren/server/lambda'
|
|
60
|
+
*
|
|
61
|
+
* await app.boot()
|
|
62
|
+
* export const handler = createLambdaHandler(app)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function createLambdaHandler(app: Application): <L extends hono_aws_lambda.LambdaEvent>(event: L, lambdaContext?: hono_aws_lambda.LambdaContext) => Promise<hono_aws_lambda.APIGatewayProxyResult & (L extends {
|
|
66
|
+
multiValueHeaders: Record<string, string[]>;
|
|
67
|
+
} ? {
|
|
68
|
+
headers?: undefined;
|
|
69
|
+
multiValueHeaders: Record<string, string[]>;
|
|
70
|
+
} : {
|
|
71
|
+
headers: Record<string, string>;
|
|
72
|
+
multiValueHeaders?: undefined;
|
|
73
|
+
})>;
|
|
74
|
+
/**
|
|
75
|
+
* Create an AWS Lambda handler for processing SQS queue jobs.
|
|
76
|
+
*
|
|
77
|
+
* Supports partial batch failure reporting — only failed messages
|
|
78
|
+
* are returned to SQS for retry, while successful ones are deleted.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import app from './src/app'
|
|
83
|
+
* import { createSqsHandler } from '@guren/server/lambda'
|
|
84
|
+
*
|
|
85
|
+
* await app.boot()
|
|
86
|
+
* export const queue = createSqsHandler()
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function createSqsHandler(): (event: SqsEvent) => Promise<SqsBatchResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Create an AWS Lambda handler for running scheduled tasks via EventBridge.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { createScheduleHandler } from '@guren/server/lambda'
|
|
96
|
+
* import { scheduler } from './src/scheduler'
|
|
97
|
+
*
|
|
98
|
+
* export const schedule = createScheduleHandler(scheduler)
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function createScheduleHandler(scheduler: Scheduler): () => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Console command event payload for Lambda.
|
|
104
|
+
*/
|
|
105
|
+
interface ConsoleEvent {
|
|
106
|
+
/**
|
|
107
|
+
* Command string to execute (e.g. "db:migrate", "users:create john@example.com --admin").
|
|
108
|
+
*/
|
|
109
|
+
command: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Console command result from Lambda.
|
|
113
|
+
*/
|
|
114
|
+
interface ConsoleResult {
|
|
115
|
+
exitCode: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create an AWS Lambda handler for running console commands.
|
|
119
|
+
*
|
|
120
|
+
* Invoke via AWS CLI, SDK, or EventBridge with a JSON payload:
|
|
121
|
+
* `{ "command": "db:migrate" }`
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* import { createConsoleHandler } from '@guren/server/lambda'
|
|
126
|
+
* import { kernel } from './src/console'
|
|
127
|
+
*
|
|
128
|
+
* export const console = createConsoleHandler(kernel)
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function createConsoleHandler(kernel: ConsoleKernel): (event: ConsoleEvent) => Promise<ConsoleResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Detect if the current process is running inside AWS Lambda.
|
|
134
|
+
*
|
|
135
|
+
* Checks for the `AWS_LAMBDA_FUNCTION_NAME` environment variable,
|
|
136
|
+
* which AWS sets automatically in all Lambda runtimes.
|
|
137
|
+
*/
|
|
138
|
+
declare function isLambda(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get Lambda environment metadata, or null if not running on Lambda.
|
|
141
|
+
*/
|
|
142
|
+
declare function getLambdaContext(): LambdaRuntimeContext | null;
|
|
143
|
+
/**
|
|
144
|
+
* Lambda runtime context metadata.
|
|
145
|
+
*/
|
|
146
|
+
interface LambdaRuntimeContext {
|
|
147
|
+
functionName: string;
|
|
148
|
+
functionVersion: string;
|
|
149
|
+
memorySize: number;
|
|
150
|
+
region: string;
|
|
151
|
+
logGroup?: string;
|
|
152
|
+
logStream?: string;
|
|
153
|
+
tmpDir: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { type ConsoleEvent, type ConsoleResult, type LambdaRuntimeContext, type SqsBatchItemFailure, type SqsBatchResponse, type SqsEvent, type SqsRecord, createConsoleHandler, createLambdaHandler, createScheduleHandler, createSqsHandler, getLambdaContext, isLambda };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/lambda/index.ts
|
|
2
|
+
import { handle } from "hono/aws-lambda";
|
|
3
|
+
|
|
4
|
+
// src/queue/Job.ts
|
|
5
|
+
import { randomBytes } from "crypto";
|
|
6
|
+
var jobRegistry = /* @__PURE__ */ new Map();
|
|
7
|
+
function getJob(name) {
|
|
8
|
+
return jobRegistry.get(name);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/lambda/index.ts
|
|
12
|
+
function createLambdaHandler(app) {
|
|
13
|
+
return handle(app.hono);
|
|
14
|
+
}
|
|
15
|
+
function createSqsHandler() {
|
|
16
|
+
return async (event) => {
|
|
17
|
+
const failures = [];
|
|
18
|
+
const results = await Promise.allSettled(
|
|
19
|
+
event.Records.map(async (record) => {
|
|
20
|
+
const job = deserializeSqsJob(record.body);
|
|
21
|
+
const JobClass = getJob(job.name);
|
|
22
|
+
if (!JobClass) {
|
|
23
|
+
throw new Error(`Job class not found: ${job.name}`);
|
|
24
|
+
}
|
|
25
|
+
const instance = new JobClass();
|
|
26
|
+
job.attempts++;
|
|
27
|
+
try {
|
|
28
|
+
await instance.handle(job.payload);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (job.attempts >= job.maxAttempts && instance.failed) {
|
|
31
|
+
try {
|
|
32
|
+
await instance.failed(job.payload, error);
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
for (let i = 0; i < results.length; i++) {
|
|
41
|
+
if (results[i].status === "rejected") {
|
|
42
|
+
failures.push({ itemIdentifier: event.Records[i].messageId });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { batchItemFailures: failures };
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function createScheduleHandler(scheduler) {
|
|
49
|
+
return async () => {
|
|
50
|
+
await scheduler.runDueTasks();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createConsoleHandler(kernel) {
|
|
54
|
+
return async (event) => {
|
|
55
|
+
const argv = event.command.split(/\s+/).filter(Boolean);
|
|
56
|
+
const exitCode = await kernel.handle(argv);
|
|
57
|
+
return { exitCode };
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function isLambda() {
|
|
61
|
+
return typeof process !== "undefined" && !!process.env?.AWS_LAMBDA_FUNCTION_NAME;
|
|
62
|
+
}
|
|
63
|
+
function getLambdaContext() {
|
|
64
|
+
if (!isLambda()) return null;
|
|
65
|
+
return {
|
|
66
|
+
functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
|
|
67
|
+
functionVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION ?? "$LATEST",
|
|
68
|
+
memorySize: parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE ?? "128", 10),
|
|
69
|
+
region: process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION ?? "us-east-1",
|
|
70
|
+
logGroup: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
|
|
71
|
+
logStream: process.env.AWS_LAMBDA_LOG_STREAM_NAME,
|
|
72
|
+
tmpDir: "/tmp"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function deserializeSqsJob(body) {
|
|
76
|
+
const raw = JSON.parse(body);
|
|
77
|
+
return {
|
|
78
|
+
...raw,
|
|
79
|
+
availableAt: new Date(raw.availableAt),
|
|
80
|
+
createdAt: new Date(raw.createdAt),
|
|
81
|
+
reservedAt: raw.reservedAt ? new Date(raw.reservedAt) : null
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
createConsoleHandler,
|
|
86
|
+
createLambdaHandler,
|
|
87
|
+
createScheduleHandler,
|
|
88
|
+
createSqsHandler,
|
|
89
|
+
getLambdaContext,
|
|
90
|
+
isLambda
|
|
91
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { b as LogChannel, C as ConsoleChannelConfig, g as LogEntry, F as FileChannelConfig, D as DailyFileChannelConfig } from '../LogManager-7mxnkaPM.js';
|
|
2
|
+
export { a as LOG_LEVEL_PRIORITY, c as LogChannelConfig, d as LogChannelFactory, e as LogConfig, f as LogContext, h as LogFormatter, i as LogLevel, L as LogManager, j as Logger, k as LoggerOptions, S as StackChannelConfig, l as createLogManager, m as filterSensitiveData, n as getLogManager, s as setLogManager } from '../LogManager-7mxnkaPM.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Console log channel.
|
|
6
|
+
*/
|
|
7
|
+
declare class ConsoleChannel implements LogChannel {
|
|
8
|
+
private readonly config;
|
|
9
|
+
private readonly minLevel;
|
|
10
|
+
constructor(config: ConsoleChannelConfig);
|
|
11
|
+
log(entry: LogEntry): void;
|
|
12
|
+
private format;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* File log channel.
|
|
17
|
+
*/
|
|
18
|
+
declare class FileChannel implements LogChannel {
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly minLevel;
|
|
21
|
+
private initialized;
|
|
22
|
+
constructor(config: FileChannelConfig);
|
|
23
|
+
log(entry: LogEntry): void;
|
|
24
|
+
private write;
|
|
25
|
+
private ensureDirectory;
|
|
26
|
+
private format;
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Daily rotating file log channel.
|
|
32
|
+
*/
|
|
33
|
+
declare class DailyFileChannel implements LogChannel {
|
|
34
|
+
private readonly config;
|
|
35
|
+
private readonly minLevel;
|
|
36
|
+
private currentDate;
|
|
37
|
+
private currentFilePath;
|
|
38
|
+
constructor(config: DailyFileChannelConfig);
|
|
39
|
+
log(entry: LogEntry): void;
|
|
40
|
+
private write;
|
|
41
|
+
private rotate;
|
|
42
|
+
private getFilePath;
|
|
43
|
+
private getDateString;
|
|
44
|
+
private ensureDirectory;
|
|
45
|
+
private cleanup;
|
|
46
|
+
private format;
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ConsoleChannel, ConsoleChannelConfig, DailyFileChannel, DailyFileChannelConfig, FileChannel, FileChannelConfig, LogChannel, LogEntry };
|