@guren/plugin-lambda 0.6.0 → 0.7.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 +3 -3
- package/dist/{build-Dn_V0LNZ.js → build-Dc1x5-hH.js} +17 -32
- package/dist/cdk/index.js +2 -5
- package/dist/commands.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Installing registers a `lambda:build` command and scaffolds `src/lambda.ts` —
|
|
|
15
15
|
bunx guren lambda:build
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
`lambda:build` runs the deploy-runtime checks `guren doctor` reports (a warning, never a failure, on an in-memory session or OAuth store, a `
|
|
18
|
+
`lambda:build` runs the deploy-runtime checks `guren doctor` reports (a warning, never a failure, on an in-memory session or OAuth store, a Bun-only password hasher (`Argon2Hasher`, `hasher: 'argon2'`, or `new Hash({ algorithm: 'argon2' })`), or filesystem provider discovery), then your app's `build` script, then assembles a `.lambda/` directory:
|
|
19
19
|
|
|
20
20
|
| Path | Contents |
|
|
21
21
|
|------|----------|
|
|
@@ -55,13 +55,13 @@ new GurenLambdaApp(stack, 'App', {
|
|
|
55
55
|
})
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
HTTP API, queue worker with partial batch failures, EventBridge scheduling, and asset routing (`/
|
|
58
|
+
HTTP API, queue worker with partial batch failures, EventBridge scheduling, and asset routing (`/public/*`, where the built assets are served from, plus each root entry of `.lambda/assets`) come wired with the handler names `lambda:build` emits. Every sub-resource is exposed as a property for further customization.
|
|
59
59
|
|
|
60
60
|
## Things Lambda changes
|
|
61
61
|
|
|
62
62
|
- **Bundle time is production.** `bun build` inlines `process.env.NODE_ENV` when bundling; the build pins it to `"production"` so runtime configuration cannot accidentally ship a development bundle.
|
|
63
63
|
- **The filesystem is read-only** except `/tmp`. Sessions and cache need a store that survives invocations — `DatabaseSessionStore`, or Redis via `@guren/core/redis`.
|
|
64
|
-
- **Passwords hash with Node's scrypt.** The default hasher
|
|
64
|
+
- **Passwords hash with Node's scrypt.** The default hasher writes `node:crypto` scrypt on every runtime, so a column seeded under Bun verifies here. Argon2id rows, written by `hasher: 'argon2'` or by a release before scrypt became the default, do not.
|
|
65
65
|
- **Static assets belong on S3 + CloudFront**, not in the function. Point real asset URLs at the function's environment (`GUREN_INERTIA_ENTRY`, `GUREN_INERTIA_STYLES`) to override the baked same-origin defaults.
|
|
66
66
|
- **The database wants the RDS Data API.** `createAwsDataApiDatabase` from `@guren/core` connects to Aurora Serverless v2 over HTTP — no pool, no RDS Proxy, no VPC. Classic RDS works too with `createPostgresDatabase` plus RDS Proxy (`clientOptions: { prepare: false, max: 1 }`).
|
|
67
67
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { n as LAMBDA_HANDLER_MODULE, t as LAMBDA_HANDLER_EXPORTS } from "./handlers-Dtt3k5Ue.js";
|
|
2
2
|
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { DEV_ONLY_MODULES, assertOutputDirOutsideRoot, bundledRuntimeEnv, importSpecifier, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, unusedSqlClients } from "@guren/core/internal/deploy-build";
|
|
5
5
|
import { reportDeployRuntimeHazards } from "@guren/core/internal/deploy-check";
|
|
6
6
|
//#region src/build.ts
|
|
7
|
-
const MCP_UNAVAILABLE = "The MCP endpoint is unavailable on AWS Lambda — it generates files on disk.";
|
|
8
7
|
/**
|
|
9
8
|
* Why the dev-only modules in `DEV_ONLY_MODULES` cannot run here, each naming
|
|
10
9
|
* the Lambda-appropriate replacement. Keyed only on the kinds this platform
|
|
@@ -14,17 +13,15 @@ const MCP_UNAVAILABLE = "The MCP endpoint is unavailable on AWS Lambda — it ge
|
|
|
14
13
|
const UNAVAILABLE_ON_LAMBDA = {
|
|
15
14
|
sqlite: "bun:sqlite is unavailable on AWS Lambda — use createAwsDataApiDatabase() or createPostgresDatabase().",
|
|
16
15
|
vite: "The Vite dev server is unavailable on AWS Lambda — serve assets from S3/CloudFront.",
|
|
17
|
-
mcp:
|
|
16
|
+
mcp: "The Dev MCP endpoint and docs viewer (@guren/cli) are unavailable on AWS Lambda — they read and generate files on disk."
|
|
18
17
|
};
|
|
19
18
|
/**
|
|
20
19
|
* Stubs rather than externals: inlining a lazily-imported module hoists its
|
|
21
|
-
* static imports to the bundle top level, so an external reached that way
|
|
22
|
-
*
|
|
23
|
-
* `@guren/plugin-mcp` serves the endpoint here, so its transport must reach the
|
|
24
|
-
* bundle (RFC 0016 §7) — `stubbableDevOnlyModules` owns that split.
|
|
20
|
+
* static imports to the bundle top level, so an external reached that way fails
|
|
21
|
+
* at import time though no code path runs it.
|
|
25
22
|
*/
|
|
26
|
-
function devOnlyStubs(
|
|
27
|
-
return Object.fromEntries(
|
|
23
|
+
function devOnlyStubs() {
|
|
24
|
+
return Object.fromEntries(DEV_ONLY_MODULES.map((module) => [module.specifier, renderDevOnlyStub(module, UNAVAILABLE_ON_LAMBDA[module.kind])]));
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
27
|
* The dev-only stubs plus one per database client this app does not connect
|
|
@@ -33,32 +30,22 @@ function devOnlyStubs(mcpPlugin) {
|
|
|
33
30
|
* `@aws-sdk/client-rds-data` for a Postgres app really does replace drizzle's
|
|
34
31
|
* hoisted top-level import of it.
|
|
35
32
|
*/
|
|
36
|
-
function stubsFor(root, dialects
|
|
33
|
+
function stubsFor(root, dialects) {
|
|
37
34
|
const unused = unusedSqlClients({
|
|
38
35
|
root,
|
|
39
36
|
label: "Lambda build",
|
|
40
37
|
dialects
|
|
41
38
|
});
|
|
42
39
|
return {
|
|
43
|
-
...devOnlyStubs(
|
|
40
|
+
...devOnlyStubs(),
|
|
44
41
|
...Object.fromEntries(unused.map(({ module, message }) => [module.specifier, renderDevOnlyStub(module, message)]))
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Fallback for an MCP SDK subpath `DEV_ONLY_MODULES` does not name. It cannot
|
|
49
|
-
* know which names the importer destructures, so it throws on evaluation rather
|
|
50
|
-
* than handing back missing exports. Reachable only for an app that does *not*
|
|
51
|
-
* declare `@guren/plugin-mcp`, whose statically imported `server/index.js` and
|
|
52
|
-
* `types.js` it would otherwise stub shut — see `stubFilter`.
|
|
53
|
-
*/
|
|
54
|
-
const unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})\n`;
|
|
55
44
|
function escapeRegExp(value) {
|
|
56
45
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
57
46
|
}
|
|
58
|
-
function stubFilter(stubs
|
|
59
|
-
|
|
60
|
-
if (!mcpPlugin) terms.push(`${escapeRegExp(MCP_SDK_SUBPATH_PREFIX)}.+`);
|
|
61
|
-
return new RegExp(`^(?:${terms.join("|")})$`);
|
|
47
|
+
function stubFilter(stubs) {
|
|
48
|
+
return new RegExp(`^(?:${Object.keys(stubs).map(escapeRegExp).join("|")})$`);
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
51
|
* Assemble a deployable AWS Lambda directory (`.lambda/`) from a built Guren
|
|
@@ -89,19 +76,17 @@ async function buildLambdaOutput(options = {}) {
|
|
|
89
76
|
mkdirSync(funcDir, { recursive: true });
|
|
90
77
|
stageStaticAssets(publicDir, resolve(out, "assets"));
|
|
91
78
|
const env = buildLambdaEnvironment(assetEnv, ssrFile, ssrDir);
|
|
92
|
-
const
|
|
93
|
-
const bakedEnv = viteManifest ? {
|
|
79
|
+
const bakedEnv = {
|
|
94
80
|
...env,
|
|
95
|
-
|
|
96
|
-
}
|
|
81
|
+
...bundledRuntimeEnv(root, publicDir, "Lambda build")
|
|
82
|
+
};
|
|
97
83
|
const wrapperPath = resolve(out, `${LAMBDA_HANDLER_MODULE}.ts`);
|
|
98
84
|
writeFileSync(wrapperPath, renderHandlerModule({
|
|
99
85
|
out,
|
|
100
86
|
entrypoint,
|
|
101
87
|
env: bakedEnv
|
|
102
88
|
}));
|
|
103
|
-
|
|
104
|
-
await bundleHandler(wrapperPath, funcDir, stubsFor(root, options.databaseDialects, mcpPlugin), mcpPlugin);
|
|
89
|
+
await bundleHandler(wrapperPath, funcDir, stubsFor(root, options.databaseDialects));
|
|
105
90
|
writeFileSync(resolve(funcDir, "package.json"), `${JSON.stringify({ type: "module" }, null, 2)}\n`);
|
|
106
91
|
if (ssrFile) cpSync(ssrDir, resolve(funcDir, ".guren/ssr"), { recursive: true });
|
|
107
92
|
if (existsSync(migrationsDir)) cpSync(migrationsDir, resolve(funcDir, "db/migrations"), { recursive: true });
|
|
@@ -132,8 +117,8 @@ function renderHandlerModule(input) {
|
|
|
132
117
|
lines.push("");
|
|
133
118
|
return lines.join("\n");
|
|
134
119
|
}
|
|
135
|
-
async function bundleHandler(handlerEntry, funcDir, stubs
|
|
136
|
-
const filter = stubFilter(stubs
|
|
120
|
+
async function bundleHandler(handlerEntry, funcDir, stubs) {
|
|
121
|
+
const filter = stubFilter(stubs);
|
|
137
122
|
const result = await Bun.build({
|
|
138
123
|
entrypoints: [handlerEntry],
|
|
139
124
|
throw: false,
|
|
@@ -160,7 +145,7 @@ async function bundleHandler(handlerEntry, funcDir, stubs, mcpPlugin) {
|
|
|
160
145
|
filter: /.*/,
|
|
161
146
|
namespace: "guren-lambda-stub"
|
|
162
147
|
}, (args) => ({
|
|
163
|
-
contents: stubs[args.path]
|
|
148
|
+
contents: stubs[args.path],
|
|
164
149
|
loader: "js"
|
|
165
150
|
}));
|
|
166
151
|
}
|
package/dist/cdk/index.js
CHANGED
|
@@ -154,12 +154,9 @@ var GurenLambdaApp = class extends Construct {
|
|
|
154
154
|
eventType: cloudfront.FunctionEventType.VIEWER_RESPONSE
|
|
155
155
|
}]
|
|
156
156
|
};
|
|
157
|
-
const additionalBehaviors = {
|
|
158
|
-
"/assets/*": assetBehavior,
|
|
159
|
-
"/public/*": assetBehavior
|
|
160
|
-
};
|
|
157
|
+
const additionalBehaviors = { "/public/*": assetBehavior };
|
|
161
158
|
if (existsSync(props.assets.dir)) for (const entry of readdirSync(props.assets.dir, { withFileTypes: true })) {
|
|
162
|
-
if (entry.name === "
|
|
159
|
+
if (entry.name === "public") continue;
|
|
163
160
|
additionalBehaviors[entry.isDirectory() ? `/${entry.name}/*` : `/${entry.name}`] = assetBehavior;
|
|
164
161
|
}
|
|
165
162
|
this.distribution = new cloudfront.Distribution(this, "Distribution", {
|
package/dist/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as buildLambdaOutput } from "./build-
|
|
1
|
+
import { t as buildLambdaOutput } from "./build-Dc1x5-hH.js";
|
|
2
2
|
import { DATABASE_DIALECTS, parseDatabaseDialects } from "@guren/core/internal/deploy-build";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
var commands_default = { "lambda:build": defineCommand({
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as LAMBDA_HANDLER_MODULE, r as lambdaHandlerId, t as LAMBDA_HANDLER_EXPORTS } from "./handlers-Dtt3k5Ue.js";
|
|
2
|
-
import { t as buildLambdaOutput } from "./build-
|
|
2
|
+
import { t as buildLambdaOutput } from "./build-Dc1x5-hH.js";
|
|
3
3
|
import { definePlugin } from "@guren/core";
|
|
4
4
|
//#region src/session/dynamodb-store.ts
|
|
5
5
|
var DynamoDbSessionStore = class {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-lambda",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typecheck": "tsc --noEmit"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@guren/core": "^1.
|
|
56
|
+
"@guren/core": "^1.20.0",
|
|
57
57
|
"citty": "^0.1.6"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|