@vectorx/functions-framework 0.5.1 → 0.6.2
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/lib/function-wrapper.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -22,7 +55,31 @@ const wrapEventFunction = (execute, projectConfig) => {
|
|
|
22
55
|
var _a;
|
|
23
56
|
let event;
|
|
24
57
|
if (ctx.request.files) {
|
|
25
|
-
|
|
58
|
+
const filesWithBuffer = {};
|
|
59
|
+
const fs = yield Promise.resolve().then(() => __importStar(require("fs")));
|
|
60
|
+
for (const [key, fileOrFiles] of Object.entries(ctx.request.files)) {
|
|
61
|
+
const files = Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles];
|
|
62
|
+
const processedFiles = yield Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (file && typeof file === "object" && (file.filepath || file.path)) {
|
|
64
|
+
const filePath = file.filepath || file.path;
|
|
65
|
+
try {
|
|
66
|
+
const buffer = fs.readFileSync(filePath);
|
|
67
|
+
try {
|
|
68
|
+
fs.unlinkSync(filePath);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
}
|
|
72
|
+
return Object.assign(Object.assign({}, file), { buffer });
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return file;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return file;
|
|
79
|
+
})));
|
|
80
|
+
filesWithBuffer[key] = Array.isArray(fileOrFiles) ? processedFiles : processedFiles[0];
|
|
81
|
+
}
|
|
82
|
+
event = Object.assign(Object.assign({}, filesWithBuffer), ctx.request.body);
|
|
26
83
|
}
|
|
27
84
|
else if (ctx.request.body) {
|
|
28
85
|
event = ctx.request.body;
|
|
@@ -83,7 +140,6 @@ const wrapEventFunction = (execute, projectConfig) => {
|
|
|
83
140
|
result = yield execute(event, context);
|
|
84
141
|
}
|
|
85
142
|
catch (e) {
|
|
86
|
-
console.log("============>>>>>>>>>> function wrapper error ", e);
|
|
87
143
|
ctx.state.error = e;
|
|
88
144
|
if (hasSwitchSSEMode) {
|
|
89
145
|
const sse = (_a = ctx.sse) === null || _a === void 0 ? void 0 : _a.call(ctx);
|
|
@@ -93,9 +149,7 @@ const wrapEventFunction = (execute, projectConfig) => {
|
|
|
93
149
|
data: e.message,
|
|
94
150
|
comment: "uncaught-exception-from-user-code",
|
|
95
151
|
};
|
|
96
|
-
console.log("============>>>>>>>>>> errorEvent ", errorEvent);
|
|
97
152
|
sse.emit("error", errorEvent);
|
|
98
|
-
console.log("============>>>>>>>>>> sse.end(errorEvent) ");
|
|
99
153
|
sse.end(errorEvent);
|
|
100
154
|
}
|
|
101
155
|
}
|
|
@@ -25,6 +25,7 @@ function apmMiddleware() {
|
|
|
25
25
|
kit_agent_desc: agentInfo.desc,
|
|
26
26
|
kit_agent_id: agentInfo.agentId,
|
|
27
27
|
kit_agent_version: agentInfo.version,
|
|
28
|
+
kit_agent_name: agentInfo.name,
|
|
28
29
|
context_artifactVersion: kitInfo.agentRuntimeVersion,
|
|
29
30
|
kit_agent_runtime_version: kitInfo.agentRuntimeVersion,
|
|
30
31
|
kit_function_framework_version: kitInfo.functionsFrameworkVersion,
|
package/lib/request.js
CHANGED
|
@@ -150,9 +150,8 @@ class Request {
|
|
|
150
150
|
clearTimeout(timer);
|
|
151
151
|
return Promise.reject(x);
|
|
152
152
|
});
|
|
153
|
-
console.log("=== res ===", res);
|
|
154
153
|
const ret = {
|
|
155
|
-
data: stream ? (res.body ? stream_1.Readable.toWeb(res.body) : res.body) : res.json(),
|
|
154
|
+
data: stream ? (res.body ? stream_1.Readable.toWeb(res.body) : res.body) : yield res.json(),
|
|
156
155
|
statusCode: res.status,
|
|
157
156
|
header: res.headers,
|
|
158
157
|
};
|
package/lib/server.js
CHANGED
|
@@ -16,7 +16,6 @@ exports.createServer = createServer;
|
|
|
16
16
|
const http_1 = __importDefault(require("http"));
|
|
17
17
|
const koa_1 = __importDefault(require("koa"));
|
|
18
18
|
const koa_body_1 = require("koa-body");
|
|
19
|
-
const raw_body_1 = __importDefault(require("raw-body"));
|
|
20
19
|
const error_1 = require("./error");
|
|
21
20
|
const middlewares_1 = require("./middlewares");
|
|
22
21
|
const unified_responder_1 = require("./unified-responder");
|
|
@@ -45,20 +44,33 @@ function createServer(options, router, projectConfig) {
|
|
|
45
44
|
app.use((0, koa_body_1.koaBody)({
|
|
46
45
|
multipart: true,
|
|
47
46
|
patchKoa: true,
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
formidable: {
|
|
48
|
+
maxFileSize: 50 * 1024 * 1024,
|
|
49
|
+
enabledPlugins: ["octetstream", "json", "multipart"],
|
|
50
|
+
keepExtensions: true,
|
|
51
|
+
filter: ({ originalFilename }) => {
|
|
52
|
+
return !!originalFilename;
|
|
53
|
+
},
|
|
50
54
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!(ctx.request.files || ctx.request.body || ctx.state.isTimeout)) {
|
|
55
|
+
onError: (err, ctx) => {
|
|
56
|
+
var _a;
|
|
54
57
|
try {
|
|
55
|
-
ctx.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const h = ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.headers) || {};
|
|
59
|
+
console.error("[koa-body][error]", {
|
|
60
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
61
|
+
name: err === null || err === void 0 ? void 0 : err.name,
|
|
62
|
+
code: err === null || err === void 0 ? void 0 : err.code,
|
|
63
|
+
status: err === null || err === void 0 ? void 0 : err.status,
|
|
64
|
+
headers: {
|
|
65
|
+
"content-type": h["content-type"],
|
|
66
|
+
"content-length": h["content-length"],
|
|
67
|
+
"transfer-encoding": h["transfer-encoding"],
|
|
68
|
+
},
|
|
69
|
+
});
|
|
59
70
|
}
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
catch (_) { }
|
|
72
|
+
return (0, unified_responder_1.sendResponse)(ctx, undefined, (0, error_1.newBadRequestErr)(err), 400);
|
|
73
|
+
},
|
|
62
74
|
}));
|
|
63
75
|
app.use((0, middlewares_1.openGwRequestMiddleware)(projectConfig.agentId));
|
|
64
76
|
app.use((0, middlewares_1.functionRouteMiddleware)(router, projectConfig));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/functions-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "VectorX Functions Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=18.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@vectorx/ai-types": "0.
|
|
28
|
+
"@vectorx/ai-types": "0.5.2",
|
|
29
29
|
"async_hooks": "^1.0.0",
|
|
30
30
|
"chalk": "4",
|
|
31
31
|
"commander": "^12.1.0",
|