@bluelibs/runner 4.5.5 → 4.5.6
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/AI.md +47 -8
- package/README.md +3 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -11,8 +11,8 @@ npm install @bluelibs/runner
|
|
|
11
11
|
- Auto‑detects platform at runtime. In browsers, `exit()` is unsupported and throws. Env reads use `globalThis.__ENV__`, `process.env`, or `globalThis.env`.
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { setPlatform,
|
|
15
|
-
setPlatform(new
|
|
14
|
+
import { setPlatform, PlatformAdapter } from "@bluelibs/runner/platform";
|
|
15
|
+
setPlatform(new PlatformAdapter("browser"));
|
|
16
16
|
//
|
|
17
17
|
globalThis.__ENV__ = { API_URL: "https://example.test" };
|
|
18
18
|
```
|
|
@@ -184,11 +184,9 @@ import { globals, task } from "@bluelibs/runner";
|
|
|
184
184
|
|
|
185
185
|
const critical = task({
|
|
186
186
|
id: "app.tasks.critical",
|
|
187
|
-
|
|
188
|
-
tags:
|
|
189
|
-
|
|
190
|
-
],
|
|
191
|
-
},
|
|
187
|
+
tags: [
|
|
188
|
+
globals.tags.debug.with({ logTaskInput: true, logTaskOutput: true }),
|
|
189
|
+
],
|
|
192
190
|
run: async () => "ok",
|
|
193
191
|
});
|
|
194
192
|
```
|
|
@@ -202,7 +200,7 @@ const logsExtension = resource({
|
|
|
202
200
|
id: "app.logs",
|
|
203
201
|
dependencies: { logger: globals.resources.logger },
|
|
204
202
|
init: async (_, { logger }) => {
|
|
205
|
-
logger.info("test", {
|
|
203
|
+
logger.info("test", { example: 123 }); // "trace", "debug", "info", "warn", "error", "critical"
|
|
206
204
|
const sublogger = logger.with({
|
|
207
205
|
source: "app.logs",
|
|
208
206
|
context: {},
|
|
@@ -214,6 +212,47 @@ const logsExtension = resource({
|
|
|
214
212
|
});
|
|
215
213
|
```
|
|
216
214
|
|
|
215
|
+
## AWS Lambda
|
|
216
|
+
|
|
217
|
+
- Cache the runner between warm invocations; do not dispose on each call.
|
|
218
|
+
- Disable shutdown hooks (`shutdownHooks: false`) and enable the error boundary.
|
|
219
|
+
- Provide a request-scoped context per invocation via `createContext`.
|
|
220
|
+
- Parse API Gateway v1/v2 events (handle `requestContext.http.method`/`rawPath` and `httpMethod`/`path`) and base64 bodies.
|
|
221
|
+
- Optionally set `context.callbackWaitsForEmptyEventLoop = false` when using long‑lived connections.
|
|
222
|
+
|
|
223
|
+
Example outline:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
// bootstrap.ts
|
|
227
|
+
import { resource, task, run, createContext } from "@bluelibs/runner";
|
|
228
|
+
export const RequestCtx: any = createContext("app.http.request");
|
|
229
|
+
// define resources & tasks...
|
|
230
|
+
let rrPromise: Promise<any> | null = null;
|
|
231
|
+
export async function getRunner() {
|
|
232
|
+
if (!rrPromise) {
|
|
233
|
+
rrPromise = run(app, { shutdownHooks: false, errorBoundary: true });
|
|
234
|
+
}
|
|
235
|
+
return rrPromise;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// handler.ts
|
|
239
|
+
export const handler = async (event: any, context: any) => {
|
|
240
|
+
const rr: any = await getRunner();
|
|
241
|
+
const method = event?.requestContext?.http?.method ?? event?.httpMethod ?? "GET";
|
|
242
|
+
const path = event?.rawPath || event?.path || "/";
|
|
243
|
+
const rawBody = event?.body
|
|
244
|
+
? event.isBase64Encoded
|
|
245
|
+
? Buffer.from(event.body, "base64").toString("utf8")
|
|
246
|
+
: event.body
|
|
247
|
+
: undefined;
|
|
248
|
+
const body = rawBody ? JSON.parse(rawBody) : undefined;
|
|
249
|
+
|
|
250
|
+
return RequestCtx.provide({ requestId: context?.awsRequestId ?? "local", method, path }, async () => {
|
|
251
|
+
// route and call rr.runTask(...)
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
```
|
|
255
|
+
|
|
217
256
|
## Middleware (global or local)
|
|
218
257
|
|
|
219
258
|
Middleware now supports type contracts with `<Config, Input, Output>` signature:
|
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ _Or: How I Learned to Stop Worrying and Love Dependency Injection_
|
|
|
19
19
|
| [Migrate from 3.x.x to 4.x.x](https://github.com/bluelibs/runner/blob/main/readmes/MIGRATION.md) | Guide | Step-by-step upgrade from v3 to v4 |
|
|
20
20
|
| [Runner Lore](https://github.com/bluelibs/runner/blob/main/readmes) | Docs | Design notes, deep dives, and context |
|
|
21
21
|
| [Example: Express + OpenAPI + SQLite](https://github.com/bluelibs/runner/tree/main/examples/express-openapi-sqlite) | Example | Full Express + OpenAPI + SQLite demo |
|
|
22
|
+
| [Example: Fastify + MikroORM + PostgreSQL](https://github.com/bluelibs/runner/tree/main/examples/fastify-mikroorm) | Example | Full Fastify + MikroORM + PostgreSQL demo |
|
|
22
23
|
| [OpenAI Runner Chatbot](https://chatgpt.com/g/g-68b756abec648191aa43eaa1ea7a7945-runner?model=gpt-5-thinking) | Chatbot | Ask questions interactively, or feed README.md to your own AI |
|
|
23
24
|
|
|
24
25
|
Welcome to BlueLibs Runner, where we've taken the chaos of modern application architecture and turned it into something that won't make you question your life choices at 3am. This isn't just another framework – it's your new best friend who actually understands that code should be readable, testable, and not require a PhD in abstract nonsense to maintain.
|
|
@@ -94,8 +95,6 @@ const { dispose, getResourceValue, runTask, emitEvent } = await run(app);
|
|
|
94
95
|
const { dispose } = await run(app, { debug: "verbose" });
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
> **runtime:** "'Less lines than Hello World.' Incredible. All you had to do was externalize 90% of the work into `express`, Node, and me. But please, bask in the brevity. I’ll be over here negotiating a peace treaty between your dependency tree and reality."
|
|
98
|
-
|
|
99
98
|
### Platform & Async Context
|
|
100
99
|
|
|
101
100
|
Runner auto-detects the platform and adapts behavior at runtime. The only feature present only in Node.js is the use of `AsyncLocalStorage` for managing async context.
|
|
@@ -142,8 +141,6 @@ Look, we get it. You could turn every function into a task, but that's like usin
|
|
|
142
141
|
|
|
143
142
|
Think of tasks as the "main characters" in your application story, not every single line of dialogue.
|
|
144
143
|
|
|
145
|
-
> **runtime:** "'Pure-ish.' Like diet chaos. Zero calories, full aftertaste. You stapled dependencies to a function and called it virtuous. It's fine. I’ll keep the receipts while you roleplay purity with side effects in a trench coat."
|
|
146
|
-
|
|
147
144
|
### Resources
|
|
148
145
|
|
|
149
146
|
Resources are the singletons, the services, configs, and connections that live throughout your app's lifecycle. They initialize once and stick around until cleanup time. They have to be registered (via `register: []`) only once before they can be used.
|
|
@@ -235,8 +232,6 @@ const dbResource = resource({
|
|
|
235
232
|
});
|
|
236
233
|
```
|
|
237
234
|
|
|
238
|
-
> **runtime:** "Singletons: global variables with a nicer haircut. You ban globals, then create 'resources' that live forever and hold the keys to everything. At least there's a `dispose()`. I’ll believe you use it when I stop finding zombie sockets haunting the process."
|
|
239
|
-
|
|
240
235
|
### Events
|
|
241
236
|
|
|
242
237
|
Events let different parts of your app talk to each other without tight coupling. It's like having a really good office messenger who never forgets anything.
|
|
@@ -579,7 +574,7 @@ const loggedTask = task({
|
|
|
579
574
|
});
|
|
580
575
|
```
|
|
581
576
|
|
|
582
|
-
> **runtime:** "Ah, the onion pattern. A matryoshka doll made of promises. Every peel reveals… another logger. Another tracer. Another 'just a tiny wrapper'.
|
|
577
|
+
> **runtime:** "Ah, the onion pattern. A matryoshka doll made of promises. Every peel reveals… another logger. Another tracer. Another 'just a tiny wrapper'."
|
|
583
578
|
|
|
584
579
|
### Tags
|
|
585
580
|
|
|
@@ -3205,6 +3200,7 @@ This is part of the [BlueLibs](https://www.bluelibs.com) ecosystem. We're not tr
|
|
|
3205
3200
|
- [GitHub Repository](https://github.com/bluelibs/runner) - ⭐ if you find this useful
|
|
3206
3201
|
- [Documentation](https://bluelibs.github.io/runner/) - When you need the full details
|
|
3207
3202
|
- [Issues](https://github.com/bluelibs/runner/issues) - When something breaks (or you want to make it better)
|
|
3203
|
+
- [Contributing](./CONTRIBUTING.md) - How to file great issues and PRs
|
|
3208
3204
|
|
|
3209
3205
|
_P.S. - Yes, we know there are 47 other JavaScript frameworks. This one's still different._
|
|
3210
3206
|
|