@easel-sh/cli 0.1.0-alpha.5 → 0.1.0-alpha.7
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/handler-wrapper.d.ts.map +1 -1
- package/dist/handler-wrapper.js +22 -2
- package/dist/handler-wrapper.js.map +1 -1
- package/dist/handler-wrapper.test.d.ts +2 -0
- package/dist/handler-wrapper.test.d.ts.map +1 -0
- package/dist/handler-wrapper.test.js +53 -0
- package/dist/handler-wrapper.test.js.map +1 -0
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-wrapper.d.ts","sourceRoot":"","sources":["../src/handler-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"handler-wrapper.d.ts","sourceRoot":"","sources":["../src/handler-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAkRlE"}
|
package/dist/handler-wrapper.js
CHANGED
|
@@ -77,6 +77,16 @@ module.exports.handler = async (event, _context) => {
|
|
|
77
77
|
body: bodyBuffer && bodyBuffer.length > 0 ? bodyBuffer : undefined,
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
const requestDetails = {
|
|
81
|
+
method: method,
|
|
82
|
+
url: requestUrl,
|
|
83
|
+
path: url.pathname,
|
|
84
|
+
query: queryParams,
|
|
85
|
+
headers: normalizedHeaders,
|
|
86
|
+
bodyLength: bodyBuffer ? bodyBuffer.length : 0,
|
|
87
|
+
};
|
|
88
|
+
console.log("[handler] reconstructed request:", JSON.stringify(requestDetails));
|
|
89
|
+
|
|
80
90
|
// Vercel: named method export (e.g. export function GET(request) { ... })
|
|
81
91
|
if (HTTP_METHODS.includes(method) && typeof mod[method] === "function") {
|
|
82
92
|
const response = await Promise.resolve(mod[method](webRequest));
|
|
@@ -153,8 +163,18 @@ module.exports.handler = async (event, _context) => {
|
|
|
153
163
|
query: queryParams,
|
|
154
164
|
}
|
|
155
165
|
);
|
|
156
|
-
Object.defineProperty(req, "body", {
|
|
157
|
-
|
|
166
|
+
Object.defineProperty(req, "body", {
|
|
167
|
+
get: getParsedBody,
|
|
168
|
+
set: function (val) { _bodyParsed = val; },
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: true,
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(req, "cookies", {
|
|
173
|
+
get: getCookies,
|
|
174
|
+
set: function (val) { cookiesObj = val; },
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true,
|
|
177
|
+
});
|
|
158
178
|
|
|
159
179
|
let statusCode = 200;
|
|
160
180
|
const headers = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-wrapper.js","sourceRoot":"","sources":["../src/handler-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB;IACxD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3E,OAAO;;;;;;;;;;iCAUwB,WAAW
|
|
1
|
+
{"version":3,"file":"handler-wrapper.js","sourceRoot":"","sources":["../src/handler-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB;IACxD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3E,OAAO;;;;;;;;;;iCAUwB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqQ3C,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-wrapper.test.d.ts","sourceRoot":"","sources":["../src/handler-wrapper.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
6
|
+
import { generateHandlerWrapper } from "./handler-wrapper.js";
|
|
7
|
+
describe("handler-wrapper", () => {
|
|
8
|
+
let tmpDir;
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "handler-wrapper-test-"));
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
15
|
+
});
|
|
16
|
+
it("allows assigning to req.cookies without throwing (Node-style handler)", async () => {
|
|
17
|
+
const wrapperCode = generateHandlerWrapper("index.mjs");
|
|
18
|
+
fs.writeFileSync(path.join(tmpDir, "handler.js"), wrapperCode, "utf8");
|
|
19
|
+
fs.writeFileSync(path.join(tmpDir, "index.mjs"), `export default function (req, res) {
|
|
20
|
+
req.cookies = {};
|
|
21
|
+
res.end("ok");
|
|
22
|
+
}`, "utf8");
|
|
23
|
+
const handler = require(path.join(tmpDir, "handler.js")).handler;
|
|
24
|
+
const mockEvent = {
|
|
25
|
+
requestContext: { http: { method: "GET" } },
|
|
26
|
+
headers: { host: "localhost" },
|
|
27
|
+
rawPath: "/",
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(mockEvent, {});
|
|
30
|
+
expect(result).toBeDefined();
|
|
31
|
+
expect(result.statusCode).toBe(200);
|
|
32
|
+
expect(result.body).toBe("ok");
|
|
33
|
+
});
|
|
34
|
+
it("allows assigning to req.body without throwing (Node-style handler)", async () => {
|
|
35
|
+
const wrapperCode = generateHandlerWrapper("index.mjs");
|
|
36
|
+
fs.writeFileSync(path.join(tmpDir, "handler.js"), wrapperCode, "utf8");
|
|
37
|
+
fs.writeFileSync(path.join(tmpDir, "index.mjs"), `export default function (req, res) {
|
|
38
|
+
req.body = {};
|
|
39
|
+
res.end("ok");
|
|
40
|
+
}`, "utf8");
|
|
41
|
+
const handler = require(path.join(tmpDir, "handler.js")).handler;
|
|
42
|
+
const mockEvent = {
|
|
43
|
+
requestContext: { http: { method: "GET" } },
|
|
44
|
+
headers: { host: "localhost" },
|
|
45
|
+
rawPath: "/",
|
|
46
|
+
};
|
|
47
|
+
const result = await handler(mockEvent, {});
|
|
48
|
+
expect(result).toBeDefined();
|
|
49
|
+
expect(result.statusCode).toBe(200);
|
|
50
|
+
expect(result.body).toBe("ok");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=handler-wrapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-wrapper.test.js","sourceRoot":"","sources":["../src/handler-wrapper.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAA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": "@easel-sh/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"cli": "./dist/cli.js"
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc",
|
|
16
|
-
"dev": "tsc --watch"
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest run"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"yargs": "^17.7.2"
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/node": "^20.10.0",
|
|
23
24
|
"@types/yargs": "^17.0.32",
|
|
24
|
-
"typescript": "^5.3.3"
|
|
25
|
+
"typescript": "^5.3.3",
|
|
26
|
+
"vitest": "^2.0.0"
|
|
25
27
|
}
|
|
26
28
|
}
|