@vectorx/functions-framework 0.0.0-beta-20260108133839 → 0.0.0-beta-20260320063305
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/README.md +29 -1
- package/bin/rcb-ff.js +53 -1
- package/lib/config.js +2 -5
- package/lib/constants.js +1 -0
- package/lib/error.js +12 -4
- package/lib/framework.js +91 -31
- package/lib/function-loader.js +6 -2
- package/lib/function-registry.js +8 -0
- package/lib/function-wrapper.js +102 -9
- package/lib/index.js +1 -0
- package/lib/middlewares/index.js +3 -1
- package/lib/middlewares/middle-common-logger.js +3 -2
- package/lib/middlewares/middle-env-vars-injection.js +65 -0
- package/lib/middlewares/middle-open-gw-request.js +8 -1
- package/lib/request.js +6 -2
- package/lib/router.js +6 -0
- package/lib/server.js +19 -1
- package/lib/sse.js +8 -2
- package/lib/telemetry/langfuse.js +5 -3
- package/lib/utils/apm.config.js +2 -1
- package/lib/utils/console-intercept.js +1 -2
- package/lib/utils/helper.js +8 -6
- package/lib/wss.js +305 -0
- package/package.json +9 -6
- package/types/framework.d.ts +5 -0
- package/types/function-registry.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/middlewares/index.d.ts +1 -0
- package/types/middlewares/middle-env-vars-injection.d.ts +2 -0
- package/types/middlewares/middle-open-gw-request.d.ts +4 -1
- package/types/router.d.ts +4 -4
- package/types/server.d.ts +14 -0
- package/types/wss.d.ts +56 -0
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export declare function buildFnId(fnName: string, functionName: string): string;
|
|
2
2
|
export declare function registerFunction(fnName: string, fn: Function): void;
|
|
3
3
|
export declare function getRegisteredFunction(fnId: string): Function | undefined;
|
|
4
|
+
export declare function getAllRegisteredFunctions(): Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
userFunction: Function;
|
|
7
|
+
}>;
|
|
4
8
|
export declare function clearRegistry(): void;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { asyncContextMiddleware } from "./middle-async-context";
|
|
2
2
|
export { contextInjectionMiddleware } from "./middle-context-injection";
|
|
3
|
+
export { envVarsInjectionMiddleware } from "./middle-env-vars-injection";
|
|
3
4
|
export { eventIdMiddleware } from "./middle-event-id";
|
|
4
5
|
export { functionRouteMiddleware } from "./middle-function-route";
|
|
5
6
|
export { loggerMiddleware } from "./middle-common-logger";
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { Context, Next } from "koa";
|
|
2
|
-
export
|
|
2
|
+
export type OpenGwRequestMiddlewareOptions = {
|
|
3
|
+
mode?: "agent" | "fun";
|
|
4
|
+
};
|
|
5
|
+
export declare function openGwRequestMiddleware(agentId?: string, options?: OpenGwRequestMiddlewareOptions): (ctx: Context, next: Next) => Promise<void>;
|
package/types/router.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import type { CloudFunctionConfig, RouteConfig } from "./function-loader";
|
|
|
2
2
|
export declare class Router {
|
|
3
3
|
private routes;
|
|
4
4
|
private router;
|
|
5
|
-
constructor(config
|
|
5
|
+
constructor(config?: CloudFunctionConfig);
|
|
6
6
|
private addRoute;
|
|
7
7
|
findRoute(path: string): RouteConfig | null;
|
|
8
8
|
}
|
|
9
9
|
export declare function routeFunction(router: Router | undefined, path: string): {
|
|
10
|
-
routeDefinition: RouteConfig;
|
|
11
|
-
handleFunction: Function;
|
|
12
|
-
} | {
|
|
13
10
|
routeDefinition?: undefined;
|
|
14
11
|
handleFunction?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
routeDefinition: RouteConfig;
|
|
14
|
+
handleFunction: Function;
|
|
15
15
|
};
|
package/types/server.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { ProjectConfig } from "./function-loader";
|
|
|
4
4
|
import type { functionsLogger } from "./logger";
|
|
5
5
|
import type { Request } from "./request";
|
|
6
6
|
import type { Router } from "./router";
|
|
7
|
+
import type { VectorxWebSocket } from "./wss";
|
|
7
8
|
declare module "koa" {
|
|
8
9
|
interface DefaultState {
|
|
9
10
|
isTimeout?: boolean;
|
|
@@ -24,10 +25,23 @@ export interface RcbContext {
|
|
|
24
25
|
eventID: string;
|
|
25
26
|
eventType: string;
|
|
26
27
|
timestamp: number;
|
|
28
|
+
headers: Record<string, any>;
|
|
29
|
+
httpMethod: string;
|
|
30
|
+
path: string;
|
|
31
|
+
url: string;
|
|
32
|
+
query: Record<string, any>;
|
|
33
|
+
cookies: Record<string, string>;
|
|
34
|
+
trigger: "online" | "ide_debug" | "console_debug";
|
|
27
35
|
httpContext: any;
|
|
28
36
|
request: Request;
|
|
29
37
|
logger: typeof functionsLogger;
|
|
30
38
|
baseUrl: string;
|
|
39
|
+
set: (field: string, value: any) => void;
|
|
40
|
+
remove: (field: string) => void;
|
|
41
|
+
status: (code: number) => void;
|
|
42
|
+
setCookie: (name: string, value: string, options?: any) => void;
|
|
43
|
+
clearCookie: (name: string, options?: any) => void;
|
|
31
44
|
sse: () => any;
|
|
45
|
+
ws?: VectorxWebSocket;
|
|
32
46
|
}
|
|
33
47
|
export declare function createServer(options: FrameworkOptions, router: Router, projectConfig: ProjectConfig): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
package/types/wss.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as events from "events";
|
|
2
|
+
import * as http from "http";
|
|
3
|
+
import type Koa from "koa";
|
|
4
|
+
import type { WebSocket as RawWebSocket } from "ws";
|
|
5
|
+
import type { FrameworkOptions } from "./framework";
|
|
6
|
+
import type { ProjectConfig } from "./function-loader";
|
|
7
|
+
import type { Router } from "./router";
|
|
8
|
+
export interface WsEventContext {
|
|
9
|
+
ctxId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WsOpenEvent {
|
|
12
|
+
ctx: WsEventContext;
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WsErrorEvent {
|
|
16
|
+
ctx: WsEventContext;
|
|
17
|
+
type: string;
|
|
18
|
+
message: string;
|
|
19
|
+
error: any;
|
|
20
|
+
}
|
|
21
|
+
export interface WsCloseEvent {
|
|
22
|
+
ctx: WsEventContext;
|
|
23
|
+
type: string;
|
|
24
|
+
code: number;
|
|
25
|
+
reason: string;
|
|
26
|
+
wasClean: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface WsMessageEvent {
|
|
29
|
+
ctx: WsEventContext;
|
|
30
|
+
type: string;
|
|
31
|
+
data: any;
|
|
32
|
+
}
|
|
33
|
+
export interface HandleUpgradeResult {
|
|
34
|
+
allowWebSocket: boolean;
|
|
35
|
+
statusCode?: number;
|
|
36
|
+
body?: string;
|
|
37
|
+
contentType?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface WsUpgradeContext {
|
|
40
|
+
ctxId: string;
|
|
41
|
+
eventID: string;
|
|
42
|
+
eventType: "websocket.upgrade";
|
|
43
|
+
timestamp: string;
|
|
44
|
+
httpContext: {
|
|
45
|
+
url: string | undefined;
|
|
46
|
+
httpMethod: string | undefined;
|
|
47
|
+
headers: http.IncomingHttpHeaders;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare class VectorxWebSocket extends events.EventEmitter {
|
|
51
|
+
private ws;
|
|
52
|
+
constructor(ws: RawWebSocket, eventCtx: WsEventContext);
|
|
53
|
+
send(buf: any): void;
|
|
54
|
+
close(code?: number, reason?: string): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function createWebSocketServer(httpServer: http.Server, koaApp: Koa, router: Router, options: FrameworkOptions, projectConfig: ProjectConfig): void;
|