@vectorx/functions-framework 0.1.0
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 +141 -0
- package/bin/rcb-ff.js +149 -0
- package/lib/async-context.js +61 -0
- package/lib/config.js +10 -0
- package/lib/constants.js +10 -0
- package/lib/error.js +47 -0
- package/lib/framework.js +195 -0
- package/lib/function-loader.js +63 -0
- package/lib/function-registry.js +20 -0
- package/lib/function-wrapper.js +113 -0
- package/lib/index.js +23 -0
- package/lib/logger.js +160 -0
- package/lib/middlewares/index.js +19 -0
- package/lib/middlewares/middle-apm-injection.js +37 -0
- package/lib/middlewares/middle-async-context.js +27 -0
- package/lib/middlewares/middle-common-logger.js +67 -0
- package/lib/middlewares/middle-context-injection.js +33 -0
- package/lib/middlewares/middle-event-id.js +20 -0
- package/lib/middlewares/middle-function-route.js +26 -0
- package/lib/middlewares/middle-logs-request.js +48 -0
- package/lib/middlewares/middle-open-gw-request.js +29 -0
- package/lib/request.js +162 -0
- package/lib/router.js +51 -0
- package/lib/server.js +67 -0
- package/lib/sse.js +176 -0
- package/lib/types.js +2 -0
- package/lib/unified-responder.js +64 -0
- package/lib/user-logger.js +54 -0
- package/lib/utils/apm.config.js +7 -0
- package/lib/utils/apm.js +140 -0
- package/lib/utils/common.js +5 -0
- package/lib/utils/console-intercept.js +58 -0
- package/lib/utils/error-stack.js +30 -0
- package/lib/utils/helper.js +88 -0
- package/lib/utils/machineId.js +72 -0
- package/package.json +75 -0
- package/types/async-context.d.ts +17 -0
- package/types/config.d.ts +1 -0
- package/types/constants.d.ts +2 -0
- package/types/error.d.ts +20 -0
- package/types/framework.d.ts +29 -0
- package/types/function-loader.d.ts +26 -0
- package/types/function-registry.d.ts +4 -0
- package/types/function-wrapper.d.ts +3 -0
- package/types/index.d.ts +7 -0
- package/types/logger.d.ts +62 -0
- package/types/middlewares/index.d.ts +8 -0
- package/types/middlewares/middle-apm-injection.d.ts +2 -0
- package/types/middlewares/middle-async-context.d.ts +2 -0
- package/types/middlewares/middle-common-logger.d.ts +2 -0
- package/types/middlewares/middle-context-injection.d.ts +4 -0
- package/types/middlewares/middle-event-id.d.ts +2 -0
- package/types/middlewares/middle-function-route.d.ts +4 -0
- package/types/middlewares/middle-logs-request.d.ts +3 -0
- package/types/middlewares/middle-open-gw-request.d.ts +2 -0
- package/types/request.d.ts +46 -0
- package/types/router.d.ts +15 -0
- package/types/server.d.ts +32 -0
- package/types/sse.d.ts +23 -0
- package/types/types.d.ts +18 -0
- package/types/unified-responder.d.ts +15 -0
- package/types/user-logger.d.ts +5 -0
- package/types/utils/apm.config.d.ts +6 -0
- package/types/utils/apm.d.ts +21 -0
- package/types/utils/common.d.ts +2 -0
- package/types/utils/console-intercept.d.ts +6 -0
- package/types/utils/error-stack.d.ts +5 -0
- package/types/utils/helper.d.ts +7 -0
- package/types/utils/machineId.d.ts +2 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context, Next } from "koa";
|
|
2
|
+
import type { FrameworkOptions } from "../framework";
|
|
3
|
+
import type { ProjectConfig } from "../function-loader";
|
|
4
|
+
export declare function contextInjectionMiddleware(frameworkOptions: FrameworkOptions, projectConfig: ProjectConfig): (ctx: Context, next: Next) => Promise<void>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context, Next } from "koa";
|
|
2
|
+
import type { ProjectConfig } from "../function-loader";
|
|
3
|
+
import { type Router } from "../router";
|
|
4
|
+
export declare function functionRouteMiddleware(router: Router, projectConfig: ProjectConfig): (ctx: Context, next: Next) => Promise<any>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
export interface IRequestConfig {
|
|
3
|
+
timeout?: number;
|
|
4
|
+
timeoutMsg?: string;
|
|
5
|
+
restrictedMethods?: Array<IRequestMethod>;
|
|
6
|
+
defaultHeaders?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export type IRequestMethod = "get" | "post" | "put" | "upload" | "download";
|
|
9
|
+
export interface IRequestOptions {
|
|
10
|
+
url?: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
data?: any;
|
|
13
|
+
responseType?: string;
|
|
14
|
+
withCredentials?: boolean;
|
|
15
|
+
body?: any;
|
|
16
|
+
method?: string;
|
|
17
|
+
file?: File;
|
|
18
|
+
name?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface IFetchOptions {
|
|
21
|
+
url: string;
|
|
22
|
+
headers?: HeadersInit;
|
|
23
|
+
body?: any;
|
|
24
|
+
method?: string;
|
|
25
|
+
enableAbort?: boolean;
|
|
26
|
+
stream?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface ResponseObject<T = any> {
|
|
29
|
+
data?: T;
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}
|
|
33
|
+
export declare class Request implements IAbstractRequest {
|
|
34
|
+
private readonly timeout;
|
|
35
|
+
private readonly timeoutMsg;
|
|
36
|
+
private readonly restrictedMethods;
|
|
37
|
+
private readonly defaultHeaders;
|
|
38
|
+
constructor(config?: IRequestConfig);
|
|
39
|
+
get<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
|
|
40
|
+
post<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
|
|
41
|
+
put<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
|
|
42
|
+
upload<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
|
|
43
|
+
download(options: IRequestOptions): Promise<unknown>;
|
|
44
|
+
protected request(options: IRequestOptions, enableAbort?: boolean): Promise<ResponseObject>;
|
|
45
|
+
fetch(options: IFetchOptions): Promise<ResponseObject>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CloudFunctionConfig, RouteConfig } from "./function-loader";
|
|
2
|
+
export declare class Router {
|
|
3
|
+
private routes;
|
|
4
|
+
private router;
|
|
5
|
+
constructor(config: CloudFunctionConfig);
|
|
6
|
+
private addRoute;
|
|
7
|
+
findRoute(path: string): RouteConfig | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function routeFunction(router: Router | undefined, path: string): {
|
|
10
|
+
routeDefinition: RouteConfig;
|
|
11
|
+
handleFunction: Function;
|
|
12
|
+
} | {
|
|
13
|
+
routeDefinition?: undefined;
|
|
14
|
+
handleFunction?: undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import type { FrameworkOptions } from "./framework";
|
|
3
|
+
import type { ProjectConfig } from "./function-loader";
|
|
4
|
+
import type { functionsLogger } from "./logger";
|
|
5
|
+
import type { Request } from "./request";
|
|
6
|
+
import type { Router } from "./router";
|
|
7
|
+
declare module "koa" {
|
|
8
|
+
interface DefaultState {
|
|
9
|
+
isTimeout?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface Application {
|
|
12
|
+
routers: Map<string, Router>;
|
|
13
|
+
}
|
|
14
|
+
interface Context {
|
|
15
|
+
rawBody?: any;
|
|
16
|
+
extendedContext?: any;
|
|
17
|
+
httpContext?: any;
|
|
18
|
+
sse?: () => any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export interface RcbContext {
|
|
22
|
+
ctxId: string;
|
|
23
|
+
eventID: string;
|
|
24
|
+
eventType: string;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
httpContext: any;
|
|
27
|
+
request: Request;
|
|
28
|
+
logger: typeof functionsLogger;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
sse: () => any;
|
|
31
|
+
}
|
|
32
|
+
export declare function createServer(options: FrameworkOptions, router: Router, projectConfig: ProjectConfig): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
package/types/sse.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import * as util from "util";
|
|
3
|
+
import type { Context } from "koa";
|
|
4
|
+
export interface SSEMessage {
|
|
5
|
+
id?: string;
|
|
6
|
+
event?: string;
|
|
7
|
+
data: any;
|
|
8
|
+
retry?: number;
|
|
9
|
+
comment?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ServerSentEvent extends EventEmitter {
|
|
12
|
+
private ctx;
|
|
13
|
+
private stream;
|
|
14
|
+
private closed;
|
|
15
|
+
private encoder;
|
|
16
|
+
constructor(ctx: Context);
|
|
17
|
+
setEncoder(encoder: util.TextEncoder): void;
|
|
18
|
+
emitMessage(event: string, data: any): boolean;
|
|
19
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
20
|
+
send(event: SSEMessage | SSEMessage[] | string | Buffer): boolean;
|
|
21
|
+
end(msg?: SSEMessage | SSEMessage[] | string | Buffer): void;
|
|
22
|
+
get isClosed(): boolean;
|
|
23
|
+
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface RcbContext {
|
|
2
|
+
httpContext?: {
|
|
3
|
+
url: string;
|
|
4
|
+
};
|
|
5
|
+
request: (options: {
|
|
6
|
+
method: string;
|
|
7
|
+
url: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
body?: string;
|
|
10
|
+
stream?: boolean;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
data: any;
|
|
14
|
+
header?: Headers;
|
|
15
|
+
}>;
|
|
16
|
+
getBaseUrl: () => string;
|
|
17
|
+
eventID: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context } from "koa";
|
|
2
|
+
import { type AppError } from "./error";
|
|
3
|
+
export interface ResponseBody {
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
data?: any;
|
|
7
|
+
stack?: string;
|
|
8
|
+
requestId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IntegrationResponse {
|
|
11
|
+
statusCode: number;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
body: any;
|
|
14
|
+
}
|
|
15
|
+
export declare function sendResponse(ctx: Context, data?: any, error?: AppError, errStatusCode?: number, withStack?: boolean): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare function takeUserCodeLogs(): import("./logger").IUserCodeLogItem[];
|
|
2
|
+
declare function pushUserCodeLogs(log: any): void;
|
|
3
|
+
declare function addUserCodeLog(log: any): void;
|
|
4
|
+
declare function getUserCodeLogs(): import("./logger").IUserCodeLogItem[];
|
|
5
|
+
export { takeUserCodeLogs, pushUserCodeLogs, addUserCodeLog, getUserCodeLogs };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IMeasurementItem {
|
|
2
|
+
measurement_name: string;
|
|
3
|
+
measurement_data: Record<string, any>;
|
|
4
|
+
sequence: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ApmReporter {
|
|
7
|
+
seq: number;
|
|
8
|
+
private apmContext;
|
|
9
|
+
private reportQueue;
|
|
10
|
+
private timer;
|
|
11
|
+
constructor();
|
|
12
|
+
getSequence(): {
|
|
13
|
+
context_sdkSeqId: number;
|
|
14
|
+
context_sdkSessionId: string;
|
|
15
|
+
context_pageSessionId: string;
|
|
16
|
+
clientTime: number;
|
|
17
|
+
};
|
|
18
|
+
report(measurement_name: string, measurement_data?: IMeasurementItem["measurement_data"]): void;
|
|
19
|
+
private batchReport;
|
|
20
|
+
private _request;
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare function getCaller(belowFn?: any, index?: number): string;
|
|
2
|
+
declare function formatCallSite(stackTrace: any): string;
|
|
3
|
+
declare function getStackTraces(belowFn?: any): any[];
|
|
4
|
+
declare function truncateContent(content: any): any;
|
|
5
|
+
export { getCaller, formatCallSite, getStackTraces, truncateContent };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function deepFreeze<T>(obj: T): T;
|
|
2
|
+
export declare function isPlainObject(obj: any): boolean;
|
|
3
|
+
export declare function isFormData(val: any): boolean;
|
|
4
|
+
export declare function toQueryString(data: Record<string, any>): string;
|
|
5
|
+
export declare function obj2StrRecord(obj: object): Record<string, string>;
|
|
6
|
+
export declare function formatUrl(PROTOCOL: string, url: string, query: Record<string, any>): string;
|
|
7
|
+
export declare function getDependencyVersion(packageName: any, searchPath: any): any;
|