@bluelibs/runner 4.2.2 → 4.4.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/AI.md +33 -4
- package/LICENSE.md +1 -1
- package/README.md +158 -206
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +23 -1
- package/dist/errors.js.map +1 -1
- package/dist/globals/resources/debug/executionTracker.middleware.js +18 -29
- package/dist/globals/resources/debug/executionTracker.middleware.js.map +1 -1
- package/dist/globals/resources/debug/globalEvent.hook.js +2 -2
- package/dist/globals/resources/debug/globalEvent.hook.js.map +1 -1
- package/dist/globals/resources/debug/hook.hook.js +3 -3
- package/dist/globals/resources/debug/hook.hook.js.map +1 -1
- package/dist/globals/resources/debug/middleware.hook.js +1 -1
- package/dist/globals/resources/debug/middleware.hook.js.map +1 -1
- package/dist/models/DependencyProcessor.d.ts +1 -1
- package/dist/models/DependencyProcessor.js +9 -6
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/models/EventManager.d.ts +6 -0
- package/dist/models/EventManager.js +124 -46
- package/dist/models/EventManager.js.map +1 -1
- package/dist/models/LogPrinter.js +45 -35
- package/dist/models/LogPrinter.js.map +1 -1
- package/dist/models/Logger.d.ts +1 -1
- package/dist/models/Logger.js +12 -4
- package/dist/models/Logger.js.map +1 -1
- package/dist/models/MiddlewareManager.js +17 -45
- package/dist/models/MiddlewareManager.js.map +1 -1
- package/dist/models/Store.d.ts +1 -0
- package/dist/models/Store.js +7 -0
- package/dist/models/Store.js.map +1 -1
- package/dist/models/StoreRegistry.d.ts +6 -1
- package/dist/models/StoreRegistry.js +48 -0
- package/dist/models/StoreRegistry.js.map +1 -1
- package/dist/models/TaskRunner.js +14 -1
- package/dist/models/TaskRunner.js.map +1 -1
- package/dist/models/UnhandledError.js +3 -1
- package/dist/models/UnhandledError.js.map +1 -1
- package/dist/processHooks.js.map +1 -1
- package/dist/run.js +12 -7
- package/dist/run.js.map +1 -1
- package/dist/types/runner.d.ts +11 -0
- package/package.json +6 -2
package/AI.md
CHANGED
|
@@ -10,6 +10,12 @@ npm install @bluelibs/runner
|
|
|
10
10
|
|
|
11
11
|
BlueLibs Runner is a **powerful and integrated** framework. It provides a comprehensive set of tools for building robust, testable, and maintainable applications by combining a predictable Dependency Injection (DI) container with a dynamic metadata and eventing system.
|
|
12
12
|
|
|
13
|
+
## Security & Compliance
|
|
14
|
+
|
|
15
|
+
- Guarantees: runtime circular-dependency failure, override precedence safety, event cycle detection, validation gates for inputs/outputs/config, error boundary + graceful shutdown, timeout/retry middleware, global-hook scoping via `excludeFromGlobalHooks`.
|
|
16
|
+
- Tests: see `src/__tests__/security/*` for security-focused tests that exercise the guarantees above.
|
|
17
|
+
- Policy: see `SECURITY.md` for reporting, supported versions, and CI checks (includes `npm audit` for prod deps).
|
|
18
|
+
|
|
13
19
|
## DI Container Guarantees
|
|
14
20
|
|
|
15
21
|
This is the foundation of trust for any DI framework.
|
|
@@ -24,7 +30,8 @@ This is the foundation of trust for any DI framework.
|
|
|
24
30
|
- **Resources**: Managed singletons (init/dispose).
|
|
25
31
|
- **Events**: Decoupled communication. Flow: `emit → validation → find & order hooks → run hooks (stoppable)`
|
|
26
32
|
- **Hooks**: Lightweight event listeners. Async and awaited by default.
|
|
27
|
-
- **Middleware**: Cross-cutting concerns. Async and awaited by default.
|
|
33
|
+
- **Middleware**: Cross-cutting concerns. Async and awaited by default. Optionally contract-enforcing for input/output.
|
|
34
|
+
- **Tags**: Metadata for organizing, filtering, enforcing input/output contracts to tasks or resources.
|
|
28
35
|
|
|
29
36
|
## Quick Start
|
|
30
37
|
|
|
@@ -100,6 +107,9 @@ const internal = event({
|
|
|
100
107
|
id: "app.events.internal",
|
|
101
108
|
tags: [globals.tags.excludeFromGlobalHooks],
|
|
102
109
|
});
|
|
110
|
+
|
|
111
|
+
// Performance: runtime event emission cycle detection
|
|
112
|
+
// run(app, { runtimeCycleDetection: true }) // To prevent deadlocks from happening.
|
|
103
113
|
```
|
|
104
114
|
|
|
105
115
|
### Multiple Events per Hook
|
|
@@ -231,8 +241,8 @@ const auth = taskMiddleware<
|
|
|
231
241
|
// of a resource and replaces it with a non-destructive update.
|
|
232
242
|
const softDelete = resourceMiddleware({
|
|
233
243
|
id: "app.middleware.softDelete",
|
|
234
|
-
run: async ({ next }) => {
|
|
235
|
-
const resourceInstance = await next(); // The original resource instance
|
|
244
|
+
run: async ({ resource, next }) => {
|
|
245
|
+
const resourceInstance = await next(resource.config); // The original resource instance
|
|
236
246
|
|
|
237
247
|
// This example assumes the resource has `update` and `delete` methods.
|
|
238
248
|
// A more robust implementation would check for their existence.
|
|
@@ -302,7 +312,12 @@ const globalTaskMiddleware = taskMiddleware({
|
|
|
302
312
|
// if you have dependencies as task, exclude them via everywhere filter.
|
|
303
313
|
});
|
|
304
314
|
|
|
305
|
-
//
|
|
315
|
+
// Global resource middleware (same everywhere semantics)
|
|
316
|
+
const globalResourceMiddleware = resourceMiddleware({
|
|
317
|
+
id: "...",
|
|
318
|
+
everywhere: true, // or: (resource) => boolean
|
|
319
|
+
run: async ({ next }) => next(),
|
|
320
|
+
});
|
|
306
321
|
```
|
|
307
322
|
|
|
308
323
|
## Context (request-scoped values)
|
|
@@ -598,6 +613,20 @@ export const cResource = resource({
|
|
|
598
613
|
|
|
599
614
|
## Validation (optional and library‑agnostic)
|
|
600
615
|
|
|
616
|
+
## Event Cycle Safety
|
|
617
|
+
|
|
618
|
+
To prevent event‑driven deadlocks, the runner detects cycles during emission:
|
|
619
|
+
|
|
620
|
+
- A cycle occurs when an event emits another event that eventually re‑emits the original event within the same emission chain (for example: `e1 -> e2 -> e1`).
|
|
621
|
+
- When a cycle is detected, an `EventCycleError` is thrown with a readable chain to help debugging.
|
|
622
|
+
- A hook re‑emitting the same event it currently handles is allowed only when the emission originates from the same hook instance (useful for idempotent/no‑op retries); other cases are blocked.
|
|
623
|
+
|
|
624
|
+
Guidance:
|
|
625
|
+
|
|
626
|
+
- Prefer one‑way flows; avoid mutual cross‑emits between hooks.
|
|
627
|
+
- Use `event.stopPropagation()` to short‑circuit handlers when appropriate.
|
|
628
|
+
- Use tags (for example, `globals.tags.excludeFromGlobalHooks`) to scope listeners and avoid unintended re‑entry via global hooks.
|
|
629
|
+
|
|
601
630
|
Interface any library can implement:
|
|
602
631
|
|
|
603
632
|
```ts
|
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2024-present Theodor Diaconu <theodor
|
|
1
|
+
Copyright (c) 2024-present Theodor Diaconu <theodor@bluelibs.com>
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -9,11 +9,17 @@ _Or: How I Learned to Stop Worrying and Love Dependency Injection_
|
|
|
9
9
|
<a href="https://github.com/bluelibs/runner" target="_blank"><img src="https://img.shields.io/badge/github-blue" alt="GitHub" /></a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
| Resource | Type | Notes |
|
|
13
|
+
| ------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------- |
|
|
14
|
+
| [Presentation Website](https://runner.bluelibs.com/) | Website | Overview, features, and highlights |
|
|
15
|
+
| [BlueLibs Runner GitHub](https://github.com/bluelibs/runner) | GitHub | Source code, issues, and releases |
|
|
16
|
+
| [BlueLibs Runner Dev](https://github.com/bluelibs/runner-dev) | GitHub | Development tools and CLI for BlueLibs Runner |
|
|
17
|
+
| [UX Friendly Docs](https://bluelibs.github.io/runner/) | Docs | Clean, navigable documentation |
|
|
18
|
+
| [AI Friendly Docs (<5000 tokens)](https://github.com/bluelibs/runner/blob/main/AI.md) | Docs | Short, token-friendly summary (<5000 tokens) |
|
|
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
|
+
| [Runner Lore](https://github.com/bluelibs/runner/blob/main/readmes) | Docs | Design notes, deep dives, and context |
|
|
21
|
+
| [Example: Express + OpenAPI + SQLite](https://github.com/bluelibs/runner/tree/main/examples/express-openapi-sqlite) | Example | Full Express + OpenAPI + SQLite demo |
|
|
22
|
+
| [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 |
|
|
17
23
|
|
|
18
24
|
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.
|
|
19
25
|
|
|
@@ -90,9 +96,9 @@ const { dispose } = await run(app, { debug: "verbose" });
|
|
|
90
96
|
|
|
91
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."
|
|
92
98
|
|
|
93
|
-
## The Big
|
|
99
|
+
## The Big Five
|
|
94
100
|
|
|
95
|
-
The framework is built around
|
|
101
|
+
The framework is built around five core concepts: Tasks, Resources, Events, Middleware, and Tags. Understanding them is key to using the runner effectively.
|
|
96
102
|
|
|
97
103
|
### Tasks
|
|
98
104
|
|
|
@@ -569,7 +575,149 @@ const loggedTask = task({
|
|
|
569
575
|
});
|
|
570
576
|
```
|
|
571
577
|
|
|
572
|
-
> **runtime:** "Ah, the onion pattern. A matryoshka doll made of promises. Every peel reveals… another logger. Another tracer. Another 'just a tiny wrapper'. I
|
|
578
|
+
> **runtime:** "Ah, the onion pattern. A matryoshka doll made of promises. Every peel reveals… another logger. Another tracer. Another 'just a tiny wrapper'. I'll keep unwrapping until we hit the single lonely `return` you were hiding like state secrets."
|
|
579
|
+
|
|
580
|
+
### Tags
|
|
581
|
+
|
|
582
|
+
Tags are metadata that can influence system behavior. Unlike meta properties, tags can be queried at runtime to build dynamic functionality. They can be simple strings or structured configuration objects.
|
|
583
|
+
|
|
584
|
+
#### Basic Usage
|
|
585
|
+
|
|
586
|
+
```typescript
|
|
587
|
+
import { tag, task, hook, globals } from "@bluelibs/runner";
|
|
588
|
+
|
|
589
|
+
// Simple string tags
|
|
590
|
+
const apiTask = task({
|
|
591
|
+
id: "app.tasks.getUserData",
|
|
592
|
+
tags: ["api", "public", "cacheable"],
|
|
593
|
+
run: async (userId) => getUserFromDatabase(userId),
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// Structured tags with configuration
|
|
597
|
+
const httpTag = tag<{ method: string; path: string }>({
|
|
598
|
+
id: "http.route",
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
const getUserTask = task({
|
|
602
|
+
id: "app.tasks.getUser",
|
|
603
|
+
tags: ["api", httpTag.with({ method: "GET", path: "/users/:id" })],
|
|
604
|
+
run: async ({ id }) => getUserFromDatabase(id),
|
|
605
|
+
});
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
#### Discovering Components by Tags
|
|
609
|
+
|
|
610
|
+
The core power of tags is runtime discovery. Use `store.getTasksWithTag()` to find components:
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
import { hook, globals } from "@bluelibs/runner";
|
|
614
|
+
|
|
615
|
+
// Auto-register HTTP routes based on tags
|
|
616
|
+
const routeRegistration = hook({
|
|
617
|
+
id: "app.hooks.registerRoutes",
|
|
618
|
+
on: globals.events.ready,
|
|
619
|
+
dependencies: {
|
|
620
|
+
store: globals.resources.store,
|
|
621
|
+
server: expressServer,
|
|
622
|
+
},
|
|
623
|
+
run: async (_, { store, server }) => {
|
|
624
|
+
// Find all tasks with HTTP tags
|
|
625
|
+
const apiTasks = store.getTasksWithTag(httpTag);
|
|
626
|
+
|
|
627
|
+
apiTasks.forEach((taskDef) => {
|
|
628
|
+
const config = httpTag.extract(taskDef);
|
|
629
|
+
if (!config) return;
|
|
630
|
+
|
|
631
|
+
const { method, path } = config;
|
|
632
|
+
server.app[method.toLowerCase()](path, async (req, res) => {
|
|
633
|
+
const result = await taskDef({ ...req.params, ...req.body });
|
|
634
|
+
res.json(result);
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// Also find by string tags
|
|
639
|
+
const cacheableTasks = store.getTasksWithTag("cacheable");
|
|
640
|
+
console.log(`Found ${cacheableTasks.length} cacheable tasks`);
|
|
641
|
+
},
|
|
642
|
+
});
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
#### Tag Extraction and Processing
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
// Check if a tag exists and extract its configuration
|
|
649
|
+
const performanceTag = tag<{ warnAboveMs: number }>({
|
|
650
|
+
id: "performance.monitor",
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
const performanceMiddleware = taskMiddleware({
|
|
654
|
+
id: "app.middleware.performance",
|
|
655
|
+
run: async ({ task, next }) => {
|
|
656
|
+
// Check if task has performance monitoring enabled
|
|
657
|
+
if (!performanceTag.exists(task.definition)) {
|
|
658
|
+
return next(task.input);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Extract the configuration
|
|
662
|
+
const config = performanceTag.extract(task.definition);
|
|
663
|
+
const startTime = Date.now();
|
|
664
|
+
|
|
665
|
+
try {
|
|
666
|
+
const result = await next(task.input);
|
|
667
|
+
const duration = Date.now() - startTime;
|
|
668
|
+
|
|
669
|
+
if (duration > config.warnAboveMs) {
|
|
670
|
+
console.warn(`Task ${task.definition.id} took ${duration}ms`);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return result;
|
|
674
|
+
} catch (error) {
|
|
675
|
+
const duration = Date.now() - startTime;
|
|
676
|
+
console.error(`Task failed after ${duration}ms`, error);
|
|
677
|
+
throw error;
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
});
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
#### System Tags
|
|
684
|
+
|
|
685
|
+
Built-in tags for framework behavior:
|
|
686
|
+
|
|
687
|
+
```typescript
|
|
688
|
+
import { globals } from "@bluelibs/runner";
|
|
689
|
+
|
|
690
|
+
const internalTask = task({
|
|
691
|
+
id: "app.internal.cleanup",
|
|
692
|
+
tags: [
|
|
693
|
+
globals.tags.system, // Excludes from debug logs
|
|
694
|
+
globals.tags.debug.with({ logTaskInput: true }), // Per-component debug config
|
|
695
|
+
],
|
|
696
|
+
run: async () => performCleanup(),
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
const internalEvent = event({
|
|
700
|
+
id: "app.events.internal",
|
|
701
|
+
tags: [globals.tags.excludeFromGlobalHooks], // Won't trigger wildcard listeners
|
|
702
|
+
});
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
#### Contract Tags
|
|
706
|
+
|
|
707
|
+
Enforce return value shapes at compile time:
|
|
708
|
+
|
|
709
|
+
```typescript
|
|
710
|
+
// Tags that enforce type contracts
|
|
711
|
+
const userContract = tag<void, void, { name: string }>({
|
|
712
|
+
id: "contract.user",
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
const profileTask = task({
|
|
716
|
+
id: "app.tasks.getProfile",
|
|
717
|
+
tags: [userContract], // Must return { name: string }
|
|
718
|
+
run: async () => ({ name: "Ada" }), // ✅ Satisfies contract
|
|
719
|
+
});
|
|
720
|
+
```
|
|
573
721
|
|
|
574
722
|
## run() and RunOptions
|
|
575
723
|
|
|
@@ -887,7 +1035,7 @@ const databaseResource = resource({
|
|
|
887
1035
|
},
|
|
888
1036
|
dispose: async (connection) => {
|
|
889
1037
|
await connection.close();
|
|
890
|
-
console.log("Database connection closed");
|
|
1038
|
+
// console.log("Database connection closed");
|
|
891
1039
|
},
|
|
892
1040
|
});
|
|
893
1041
|
|
|
@@ -1310,6 +1458,7 @@ const app = resource({
|
|
|
1310
1458
|
logger.trace("Very detailed trace"); // ❌ Hidden by default
|
|
1311
1459
|
|
|
1312
1460
|
logger.onLog(async (log) => {
|
|
1461
|
+
// Sub-loggers instantiated .with() share the same log listeners.
|
|
1313
1462
|
// Catch logs
|
|
1314
1463
|
})
|
|
1315
1464
|
},
|
|
@@ -1765,203 +1914,6 @@ const sendWelcomeEmail = task({
|
|
|
1765
1914
|
});
|
|
1766
1915
|
```
|
|
1767
1916
|
|
|
1768
|
-
### Tags
|
|
1769
|
-
|
|
1770
|
-
Tags are a way to describe your element, however, unlike meta, tags may influence behaviour in the system. They can be simple strings or sophisticated configuration objects that control component behavior. They have to be registered for it to work, to understand their ownership.
|
|
1771
|
-
|
|
1772
|
-
#### Tags with Configuration
|
|
1773
|
-
|
|
1774
|
-
For more sophisticated control, you can create structured tags that carry configuration:
|
|
1775
|
-
|
|
1776
|
-
```typescript
|
|
1777
|
-
import { tag } from "@bluelibs/runner";
|
|
1778
|
-
|
|
1779
|
-
// Define a reusable tag with configuration
|
|
1780
|
-
const performanceTag = tag<{ alertAboveMs: number; criticalAboveMs: number }>({
|
|
1781
|
-
id: "performance.monitoring",
|
|
1782
|
-
});
|
|
1783
|
-
|
|
1784
|
-
const rateLimitTag = tag<{ maxRequestsPerMinute: number; burstLimit?: number }>(
|
|
1785
|
-
{
|
|
1786
|
-
id: "rate.limit",
|
|
1787
|
-
},
|
|
1788
|
-
);
|
|
1789
|
-
|
|
1790
|
-
const cacheTag = tag<{ ttl: number; keyPattern?: string }>({
|
|
1791
|
-
id: "cache.strategy",
|
|
1792
|
-
});
|
|
1793
|
-
|
|
1794
|
-
// Use structured tags in your components
|
|
1795
|
-
const expensiveTask = task({
|
|
1796
|
-
id: "app.tasks.expensiveCalculation",
|
|
1797
|
-
tags: [
|
|
1798
|
-
"computation",
|
|
1799
|
-
"background",
|
|
1800
|
-
performanceTag.with({
|
|
1801
|
-
alertAboveMs: 5000,
|
|
1802
|
-
criticalAboveMs: 15000,
|
|
1803
|
-
}),
|
|
1804
|
-
cacheTag.with({
|
|
1805
|
-
ttl: 300000, // 5 minutes
|
|
1806
|
-
keyPattern: "calc-{userId}-{datasetId}",
|
|
1807
|
-
}),
|
|
1808
|
-
],
|
|
1809
|
-
run: async (input) => {
|
|
1810
|
-
// Heavy computation here
|
|
1811
|
-
},
|
|
1812
|
-
});
|
|
1813
|
-
|
|
1814
|
-
const apiEndpoint = task({
|
|
1815
|
-
id: "app.tasks.api.getUserProfile",
|
|
1816
|
-
tags: [
|
|
1817
|
-
"api",
|
|
1818
|
-
"public",
|
|
1819
|
-
rateLimitTag.with({
|
|
1820
|
-
maxRequestsPerMinute: 100,
|
|
1821
|
-
burstLimit: 20,
|
|
1822
|
-
}),
|
|
1823
|
-
cacheTag.with({ ttl: 60000 }), // 1 minute cache
|
|
1824
|
-
],
|
|
1825
|
-
run: async (userId) => {
|
|
1826
|
-
// API logic
|
|
1827
|
-
},
|
|
1828
|
-
});
|
|
1829
|
-
```
|
|
1830
|
-
|
|
1831
|
-
### Global Tags System
|
|
1832
|
-
|
|
1833
|
-
The framework now includes a sophisticated global tagging system for better component organization and control:
|
|
1834
|
-
|
|
1835
|
-
```typescript
|
|
1836
|
-
import { globals } from "@bluelibs/runner";
|
|
1837
|
-
|
|
1838
|
-
// System components (automatically excluded from debug logs)
|
|
1839
|
-
const internalTask = task({
|
|
1840
|
-
id: "app.tasks.internal",
|
|
1841
|
-
tags: [globals.tags.system], // Marks as system component
|
|
1842
|
-
run: async () => "internal work",
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
// Debug-specific configuration
|
|
1846
|
-
const debugTask = task({
|
|
1847
|
-
id: "app.tasks.debug",
|
|
1848
|
-
tags: [
|
|
1849
|
-
globals.tags.debug.with({
|
|
1850
|
-
logTaskInput: true,
|
|
1851
|
-
logTaskResult: true,
|
|
1852
|
-
}),
|
|
1853
|
-
],
|
|
1854
|
-
run: async (input) => processInput(input),
|
|
1855
|
-
});
|
|
1856
|
-
|
|
1857
|
-
// Events that should not be sent to global listeners
|
|
1858
|
-
const internalEvent = event({
|
|
1859
|
-
id: "app.events.internal",
|
|
1860
|
-
tags: [globals.tags.excludeFromGlobalHooks],
|
|
1861
|
-
});
|
|
1862
|
-
```
|
|
1863
|
-
|
|
1864
|
-
To process these tags you can hook into `globals.events.ready`, use the global store as dependency and use the `getTasksWithTag()` and `getResourcesWithTag()` functionality.
|
|
1865
|
-
|
|
1866
|
-
#### Structured Tags
|
|
1867
|
-
|
|
1868
|
-
```typescript
|
|
1869
|
-
const performanceMiddleware = taskMiddleware({
|
|
1870
|
-
id: "app.middleware.performance",
|
|
1871
|
-
run: async ({ task, next }) => {
|
|
1872
|
-
const perfConfiguration = performanceTag.extract(task.definition); // you can just use .exists() if you want to check for presence
|
|
1873
|
-
|
|
1874
|
-
if (perfConfiguration) {
|
|
1875
|
-
const startTime = Date.now();
|
|
1876
|
-
|
|
1877
|
-
try {
|
|
1878
|
-
const result = await next(task?.input);
|
|
1879
|
-
const duration = Date.now() - startTime;
|
|
1880
|
-
|
|
1881
|
-
if (duration > perfConfiguration.criticalAboveMs) {
|
|
1882
|
-
await alerting.critical(
|
|
1883
|
-
`Task ${task.definition.id} took ${duration}ms`,
|
|
1884
|
-
);
|
|
1885
|
-
} else if (duration > perfConfiguration.alertAboveMs) {
|
|
1886
|
-
await alerting.warn(`Task ${task.definition.id} took ${duration}ms`);
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
return result;
|
|
1890
|
-
} catch (error) {
|
|
1891
|
-
const duration = Date.now() - startTime;
|
|
1892
|
-
await alerting.error(
|
|
1893
|
-
`Task ${task.definition.id} failed after ${duration}ms`,
|
|
1894
|
-
error,
|
|
1895
|
-
);
|
|
1896
|
-
throw error;
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
return next(task?.input);
|
|
1901
|
-
},
|
|
1902
|
-
});
|
|
1903
|
-
```
|
|
1904
|
-
|
|
1905
|
-
#### Contract Tags
|
|
1906
|
-
|
|
1907
|
-
You can attach contracts to tags to enforce the shape of a task's returned value and a resource's `init()` value at compile time. Contracts are specified via the third generic of `defineTag<TConfig, TUnused, TOutput>`.
|
|
1908
|
-
|
|
1909
|
-
```typescript
|
|
1910
|
-
// A tag that enforces the returned value to include { name: string }
|
|
1911
|
-
const userContract = tag<void, void, { name: string }>({ id: "contract.user" });
|
|
1912
|
-
|
|
1913
|
-
// Another tag that enforces { age: number }
|
|
1914
|
-
const ageContract = tag<void, void, { age: number }>({ id: "contract.age" });
|
|
1915
|
-
|
|
1916
|
-
// Works with configured tags too
|
|
1917
|
-
const preferenceContract = tag<
|
|
1918
|
-
{ locale: string },
|
|
1919
|
-
void,
|
|
1920
|
-
{ preferredLocale: string }
|
|
1921
|
-
>({
|
|
1922
|
-
id: "contract.preferences",
|
|
1923
|
-
});
|
|
1924
|
-
```
|
|
1925
|
-
|
|
1926
|
-
The return value must return a union of all tags with return contracts.
|
|
1927
|
-
|
|
1928
|
-
```typescript
|
|
1929
|
-
// Task: the awaited return value must satisfy { name: string } & { age: number }
|
|
1930
|
-
const getProfile = task({
|
|
1931
|
-
id: "app.tasks.getProfile",
|
|
1932
|
-
tags: [userContract, ageContract, preferenceContract.with({ locale: "en" })],
|
|
1933
|
-
run: async () => {
|
|
1934
|
-
return { name: "Ada", age: 37, preferredLocale: "en" }; // OK
|
|
1935
|
-
},
|
|
1936
|
-
});
|
|
1937
|
-
|
|
1938
|
-
// Resource: init() return must satisfy the same intersection
|
|
1939
|
-
const profileService = resource({
|
|
1940
|
-
id: "app.resources.profileService",
|
|
1941
|
-
tags: [userContract, ageContract],
|
|
1942
|
-
init: async () => {
|
|
1943
|
-
return { name: "Ada", age: 37 }; // OK
|
|
1944
|
-
},
|
|
1945
|
-
});
|
|
1946
|
-
```
|
|
1947
|
-
|
|
1948
|
-
If the returned value does not satisfy the intersection, TypeScript surfaces a readable, verbose type error that includes what was expected and what was received.
|
|
1949
|
-
|
|
1950
|
-
```typescript
|
|
1951
|
-
const badTask = task({
|
|
1952
|
-
id: "app.tasks.bad",
|
|
1953
|
-
tags: [userContract, ageContract],
|
|
1954
|
-
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
1955
|
-
run: async () => ({ name: "Ada" }), // Missing { age: number }
|
|
1956
|
-
// Type error includes a helpful shape similar to:
|
|
1957
|
-
// ContractViolationError<
|
|
1958
|
-
// { message: "Value does not satisfy all tag contracts";
|
|
1959
|
-
// expected: { name: string } & { age: number };
|
|
1960
|
-
// received: { name: string } }
|
|
1961
|
-
// >
|
|
1962
|
-
});
|
|
1963
|
-
```
|
|
1964
|
-
|
|
1965
1917
|
### Extending Metadata: Custom Properties
|
|
1966
1918
|
|
|
1967
1919
|
For advanced use cases, you can extend the metadata interfaces to add your own properties:
|
package/dist/errors.d.ts
CHANGED
|
@@ -73,3 +73,18 @@ export declare class StoreAlreadyInitializedError extends RuntimeError {
|
|
|
73
73
|
export declare class ValidationError extends RuntimeError {
|
|
74
74
|
constructor(type: string, id: string, originalError: Error | string);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Error thrown when an event emission cycle is detected
|
|
78
|
+
*/
|
|
79
|
+
export declare class EventCycleError extends RuntimeError {
|
|
80
|
+
constructor(path: Array<{
|
|
81
|
+
id: string;
|
|
82
|
+
source: string;
|
|
83
|
+
}>);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Error thrown when a compile-time event emission cycle is detected
|
|
87
|
+
*/
|
|
88
|
+
export declare class EventEmissionCycleError extends RuntimeError {
|
|
89
|
+
constructor(cycles: string[]);
|
|
90
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.StoreAlreadyInitializedError = exports.LockedError = exports.TagNotFoundError = exports.MiddlewareNotRegisteredError = exports.ResourceNotFoundError = exports.EventNotFoundError = exports.CircularDependenciesError = exports.ContextError = exports.UnknownItemTypeError = exports.DependencyNotFoundError = exports.DuplicateRegistrationError = exports.RuntimeError = void 0;
|
|
3
|
+
exports.EventEmissionCycleError = exports.EventCycleError = exports.ValidationError = exports.StoreAlreadyInitializedError = exports.LockedError = exports.TagNotFoundError = exports.MiddlewareNotRegisteredError = exports.ResourceNotFoundError = exports.EventNotFoundError = exports.CircularDependenciesError = exports.ContextError = exports.UnknownItemTypeError = exports.DependencyNotFoundError = exports.DuplicateRegistrationError = exports.RuntimeError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Base error class for all BlueLibs Runner errors
|
|
6
6
|
*/
|
|
@@ -143,4 +143,26 @@ class ValidationError extends RuntimeError {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
exports.ValidationError = ValidationError;
|
|
146
|
+
/**
|
|
147
|
+
* Error thrown when an event emission cycle is detected
|
|
148
|
+
*/
|
|
149
|
+
class EventCycleError extends RuntimeError {
|
|
150
|
+
constructor(path) {
|
|
151
|
+
const chain = path.map((p) => `${p.id}←${p.source}`).join(" -> ");
|
|
152
|
+
super(`Event emission cycle detected:\n ${chain}\n\nBreak the cycle by changing hook logic (avoid mutual emits) or gate with conditions/tags.`);
|
|
153
|
+
this.name = "EventCycleError";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.EventCycleError = EventCycleError;
|
|
157
|
+
/**
|
|
158
|
+
* Error thrown when a compile-time event emission cycle is detected
|
|
159
|
+
*/
|
|
160
|
+
class EventEmissionCycleError extends RuntimeError {
|
|
161
|
+
constructor(cycles) {
|
|
162
|
+
const list = cycles.map((c) => ` • ${c}`).join("\n");
|
|
163
|
+
super(`Event emission cycles detected between hooks and events:\n${list}\n\nThis was detected at compile time (dry-run). Break the cycle by avoiding mutual emits between hooks or scoping hooks using tags.`);
|
|
164
|
+
this.name = "EventEmissionCycleError";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.EventEmissionCycleError = EventEmissionCycleError;
|
|
146
168
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED;;GAEG;AACH,MAAa,0BAA2B,SAAQ,YAAY;IAC1D,YAAY,IAAY,EAAE,EAAU;QAClC,KAAK,CACH,GAAG,IAAI,KAAK,EAAE,CAAC,QAAQ,EAAE,wIAAwI,CAClK,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAPD,gEAOC;AAED;;GAEG;AACH,MAAa,uBAAwB,SAAQ,YAAY;IACvD,YAAY,GAAW;QACrB,KAAK,CACH,cAAc,GAAG,CAAC,QAAQ,EAAE,+DAA+D,CAC5F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAPD,0DAOC;AAED;;GAEG;AACH,MAAa,oBAAqB,SAAQ,YAAY;IACpD,YAAY,IAAS;QACnB,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED;;GAEG;AACH,MAAa,yBAA0B,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AC,IAAI,CAAC,CAAC;QACtD,KAAK,CACH,6DAA6D,IAAI,sIAAsI,CACxM,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AARD,0DAQC"}
|
|
@@ -7,7 +7,7 @@ const globalResources_1 = require("../../globalResources");
|
|
|
7
7
|
const globalTags_1 = require("../../globalTags");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
exports.tasksTrackerMiddleware = (0, define_1.defineTaskMiddleware)({
|
|
10
|
-
id: "debug.middleware.
|
|
10
|
+
id: "globals.debug.middleware.task.executionTracker",
|
|
11
11
|
everywhere: (task) => !globalTags_1.globalTags.system.exists(task),
|
|
12
12
|
dependencies: {
|
|
13
13
|
logger: globalResources_1.globalResources.logger,
|
|
@@ -25,20 +25,14 @@ exports.tasksTrackerMiddleware = (0, define_1.defineTaskMiddleware)({
|
|
|
25
25
|
await logger.info(taskStartMessage, {
|
|
26
26
|
data: shouldShowData ? { input: task.input } : undefined,
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
await logger.error(error);
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
28
|
+
const result = await next(task.input);
|
|
29
|
+
const duration = Date.now() - start;
|
|
30
|
+
const taskCompleteMessage = `Task ${task.definition.id} completed in ${duration}ms`;
|
|
31
|
+
const shouldShowResult = debugConfig.logTaskOutput && result;
|
|
32
|
+
await logger.info(taskCompleteMessage, {
|
|
33
|
+
data: shouldShowResult ? { result } : undefined,
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
42
36
|
},
|
|
43
37
|
meta: {
|
|
44
38
|
title: "Execution Tracker",
|
|
@@ -47,7 +41,7 @@ exports.tasksTrackerMiddleware = (0, define_1.defineTaskMiddleware)({
|
|
|
47
41
|
tags: [globalTags_1.globalTags.system],
|
|
48
42
|
});
|
|
49
43
|
exports.resourcesTrackerMiddleware = (0, define_1.defineResourceMiddleware)({
|
|
50
|
-
id: "debug.middleware.
|
|
44
|
+
id: "globals.debug.middleware.resource.executionTracker",
|
|
51
45
|
dependencies: {
|
|
52
46
|
logger: globalResources_1.globalResources.logger,
|
|
53
47
|
debugConfig: debugConfig_resource_1.debugConfig,
|
|
@@ -66,19 +60,14 @@ exports.resourcesTrackerMiddleware = (0, define_1.defineResourceMiddleware)({
|
|
|
66
60
|
await logger.info(resourceStartMessage, {
|
|
67
61
|
data: shouldShowConfig ? { config: resource.config } : undefined,
|
|
68
62
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
63
|
+
const result = await next(resource.config);
|
|
64
|
+
const duration = Date.now() - start;
|
|
65
|
+
const resourceCompleteMessage = `Resource ${String(resource.definition.id)} initialized in ${duration}ms`;
|
|
66
|
+
const shouldShowResult = debugConfig.logResourceValue && result !== undefined;
|
|
67
|
+
await logger.info(resourceCompleteMessage, {
|
|
68
|
+
data: shouldShowResult ? { result } : undefined,
|
|
69
|
+
});
|
|
70
|
+
return result;
|
|
82
71
|
},
|
|
83
72
|
meta: {
|
|
84
73
|
title: "Execution Tracker",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executionTracker.middleware.js","sourceRoot":"","sources":["../../../../src/globals/resources/debug/executionTracker.middleware.ts"],"names":[],"mappings":";;;AAAA,4CAGyB;AAEzB,iEAAqD;AACrD,2DAAwD;AACxD,iDAA8C;AAC9C,mCAAoC;AAEvB,QAAA,sBAAsB,GAAG,IAAA,6BAAoB,EAAC;IACzD,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"executionTracker.middleware.js","s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