@bluelibs/runner 4.0.1 → 4.1.1
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 +17 -0
- package/README.md +59 -21
- package/dist/definers/defineHook.d.ts +1 -1
- package/dist/definers/defineHook.js.map +1 -1
- package/dist/models/DependencyProcessor.js +17 -1
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/types/event.d.ts +7 -1
- package/dist/types/event.js +13 -0
- package/dist/types/event.js.map +1 -1
- package/dist/types/hook.d.ts +6 -4
- package/dist/types/hook.js.map +1 -1
- package/dist/types/utilities.d.ts +5 -1
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -102,6 +102,23 @@ const internal = event({
|
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
### Multiple Events per Hook
|
|
106
|
+
|
|
107
|
+
Listen to multiple events with type-safe common fields:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const h = hook({
|
|
111
|
+
id: "app.hooks.multi",
|
|
112
|
+
on: [event1, event2, event3],
|
|
113
|
+
run: async (ev) => {
|
|
114
|
+
// helper utility
|
|
115
|
+
if (isOneOf(ev, [event1, event2])) {
|
|
116
|
+
// all common fields from event1 and event2, if just event1, it will be just event1
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
105
122
|
### Interception APIs
|
|
106
123
|
|
|
107
124
|
Low-level interception is available for advanced observability and control:
|
package/README.md
CHANGED
|
@@ -17,8 +17,6 @@ _Or: How I Learned to Stop Worrying and Love Dependency Injection_
|
|
|
17
17
|
|
|
18
18
|
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
19
|
|
|
20
|
-
> **runtime:** "Ah yes, another developer manifesto. 'How I Learned to Stop Worrying and Love Dependency Injection.' Adorable. I learned to stop worrying when I accepted that you'll inevitably duct-tape a rocket to a toaster and call it 'architecture'. Go on then—impress me with your 'best friend' framework while I keep the fire extinguisher warm."
|
|
21
|
-
|
|
22
20
|
## What Is This Thing?
|
|
23
21
|
|
|
24
22
|
BlueLibs Runner is a TypeScript-first framework that embraces functional programming principles while keeping dependency injection simple enough that you won't need a flowchart to understand your own code. Think of it as the anti-framework framework – it gets out of your way and lets you build stuff that actually works.
|
|
@@ -34,8 +32,6 @@ BlueLibs Runner is a TypeScript-first framework that embraces functional program
|
|
|
34
32
|
- **Explicit beats implicit** - No magic, no surprises, no "how the hell does this work?"
|
|
35
33
|
- **No compromise on type-safety** - Everything is and will be type-enforced. Catch mistakes before they catch you.
|
|
36
34
|
|
|
37
|
-
> **runtime:** "'The anti-framework framework.' Next you'll pitch 'low-fat butter.' You still have rules, layers, and a vibe. It's fine. I will execute your sacred instructions and sweep up the rubble when 'explicit beats implicit' meets 3 AM hotfixes."
|
|
38
|
-
|
|
39
35
|
## Quick Start
|
|
40
36
|
|
|
41
37
|
```bash
|
|
@@ -48,7 +44,7 @@ Here's a complete Express server in less lines than most frameworks need for the
|
|
|
48
44
|
import express from "express";
|
|
49
45
|
import { resource, task, run } from "@bluelibs/runner";
|
|
50
46
|
|
|
51
|
-
// A resource is anything you want to share across your app
|
|
47
|
+
// A resource is anything you want to share across your app, a singleton
|
|
52
48
|
const server = resource({
|
|
53
49
|
id: "app.server",
|
|
54
50
|
init: async (config: { port: number }) => {
|
|
@@ -63,6 +59,7 @@ const server = resource({
|
|
|
63
59
|
// Tasks are your business logic - pure-ish, easily testable functions
|
|
64
60
|
const createUser = task({
|
|
65
61
|
id: "app.tasks.createUser",
|
|
62
|
+
// That's how you depend "value": resource as singleton value, task as function, event as emittor
|
|
66
63
|
dependencies: { server },
|
|
67
64
|
run: async (userData: { name: string }, { server }) => {
|
|
68
65
|
// Your actual business logic here
|
|
@@ -84,8 +81,8 @@ const app = resource({
|
|
|
84
81
|
},
|
|
85
82
|
});
|
|
86
83
|
|
|
87
|
-
// That's it.
|
|
88
|
-
const { dispose } = await run(app);
|
|
84
|
+
// That's it. Each run is fully isolated
|
|
85
|
+
const { dispose, getResourceValue, runTask, emitEvent } = await run(app);
|
|
89
86
|
|
|
90
87
|
// Or with debug logging enabled
|
|
91
88
|
const { dispose } = await run(app, { debug: "verbose" });
|
|
@@ -97,8 +94,6 @@ const { dispose } = await run(app, { debug: "verbose" });
|
|
|
97
94
|
|
|
98
95
|
The framework is built around four core concepts: Tasks, Resources, Events, and Middleware. Understanding them is key to using the runner effectively.
|
|
99
96
|
|
|
100
|
-
> **runtime:** "Tasks, Resources, Events, and Middleware: the Four Horsemen of Overengineering. You could write a function; instead you assemble a council. It's fine—I’ll keep the conspiracy board updated with red string while you 'compose' another abstraction."
|
|
101
|
-
|
|
102
97
|
### Tasks
|
|
103
98
|
|
|
104
99
|
Tasks are functions with superpowers. They're pure-ish, testable, and composable. Unlike classes that accumulate methods like a hoarder accumulates stuff, tasks do one thing well.
|
|
@@ -254,6 +249,7 @@ const registerUser = task({
|
|
|
254
249
|
});
|
|
255
250
|
|
|
256
251
|
// Someone else handles the welcome email using a hook
|
|
252
|
+
// This is great for building very modular apps
|
|
257
253
|
import { hook } from "@bluelibs/runner";
|
|
258
254
|
|
|
259
255
|
const sendWelcomeEmail = hook({
|
|
@@ -322,6 +318,46 @@ const myHook = hook({
|
|
|
322
318
|
});
|
|
323
319
|
```
|
|
324
320
|
|
|
321
|
+
#### Multiple Events (type-safe intersection)
|
|
322
|
+
|
|
323
|
+
Hooks can listen to multiple events by providing an array to `on`. The `run(event)` payload is inferred as the common (intersection-like) shape across all provided event payloads. Use the `onAnyOf()` helper to preserve tuple inference ergonomics, and `isOneOf()` as a convenient runtime/type guard when needed.
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import { hook, onAnyOf, isOneOf, event } from "@bluelibs/runner";
|
|
327
|
+
|
|
328
|
+
const eUser = event<{ id: string; email: string }>({ id: "app.events.user" });
|
|
329
|
+
const eAdmin = event<{ id: string; role: "admin" | "superadmin" }>({
|
|
330
|
+
id: "app.events.admin",
|
|
331
|
+
});
|
|
332
|
+
const eGuest = event<{ id: string; guest: true }>({ id: "app.events.guest" });
|
|
333
|
+
|
|
334
|
+
// The common field across all three is { id: string }
|
|
335
|
+
const auditUsers = hook({
|
|
336
|
+
id: "app.hooks.auditUsers",
|
|
337
|
+
on: [eUser, eAdmin, eGuest],
|
|
338
|
+
run: async (ev) => {
|
|
339
|
+
ev.data.id; // OK: common field inferred
|
|
340
|
+
// ev.data.email; // TS error: not common to all
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Guard usage to refine at runtime (still narrows to common payload)
|
|
345
|
+
const auditSome = hook({
|
|
346
|
+
id: "app.hooks.auditSome",
|
|
347
|
+
on: onAnyOf([eUser, eAdmin]), // to get a combined event
|
|
348
|
+
run: async (ev) => {
|
|
349
|
+
if (isOneOf(ev, [eUser, eAdmin])) {
|
|
350
|
+
ev.data.id; // common field of eUser and eAdmin
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Notes:
|
|
357
|
+
|
|
358
|
+
- The common payload is computed structurally. Optional properties become optional if they are not present across all events.
|
|
359
|
+
- Wildcard `on: "*"` continues to accept any event and infers `any` payload.
|
|
360
|
+
|
|
325
361
|
Hooks are perfect for:
|
|
326
362
|
|
|
327
363
|
- Event-driven side effects
|
|
@@ -403,12 +439,12 @@ Middleware wraps around your tasks and resources, adding cross-cutting concerns
|
|
|
403
439
|
Note: Middleware is now split by target. Use `taskMiddleware(...)` for task middleware and `resourceMiddleware(...)` for resource middleware.
|
|
404
440
|
|
|
405
441
|
```typescript
|
|
406
|
-
import {
|
|
442
|
+
import { taskMiddleware } from "@bluelibs/runner";
|
|
407
443
|
|
|
408
444
|
// Task middleware with config
|
|
409
445
|
type AuthMiddlewareConfig = { requiredRole: string };
|
|
410
446
|
const authMiddleware = taskMiddleware<AuthMiddlewareConfig>({
|
|
411
|
-
id: "app.middleware.auth",
|
|
447
|
+
id: "app.middleware.task.auth",
|
|
412
448
|
run: async ({ task, next }, _deps, config) => {
|
|
413
449
|
// Must return the value
|
|
414
450
|
return await next(task.input);
|
|
@@ -431,7 +467,7 @@ type AuthInput = { user: { role: string } };
|
|
|
431
467
|
type AuthOutput = { user: { role: string; verified: boolean } };
|
|
432
468
|
|
|
433
469
|
const authMiddleware = taskMiddleware<AuthConfig, AuthInput, AuthOutput>({
|
|
434
|
-
id: "app.middleware.auth",
|
|
470
|
+
id: "app.middleware.task.auth",
|
|
435
471
|
run: async ({ task, next }, _deps, config) => {
|
|
436
472
|
if (task.input.user.role !== config.requiredRole) {
|
|
437
473
|
throw new Error("Insufficient permissions");
|
|
@@ -682,7 +718,7 @@ const handleRequest = resource({
|
|
|
682
718
|
Context shines when combined with middleware for request-scoped data:
|
|
683
719
|
|
|
684
720
|
```typescript
|
|
685
|
-
import { createContext,
|
|
721
|
+
import { createContext, taskMiddleware } from "@bluelibs/runner";
|
|
686
722
|
import { randomUUID } from "crypto";
|
|
687
723
|
|
|
688
724
|
const RequestContext = createContext<{
|
|
@@ -691,7 +727,7 @@ const RequestContext = createContext<{
|
|
|
691
727
|
userAgent?: string;
|
|
692
728
|
}>("app.requestContext");
|
|
693
729
|
|
|
694
|
-
const requestMiddleware =
|
|
730
|
+
const requestMiddleware = taskMiddleware({
|
|
695
731
|
id: "app.middleware.request",
|
|
696
732
|
run: async ({ task, next }) => {
|
|
697
733
|
// This works even in express middleware if needed.
|
|
@@ -1732,7 +1768,7 @@ To process these tags you can hook into `globals.events.ready`, use the global s
|
|
|
1732
1768
|
#### Structured Tags
|
|
1733
1769
|
|
|
1734
1770
|
```typescript
|
|
1735
|
-
const performanceMiddleware =
|
|
1771
|
+
const performanceMiddleware = taskMiddleware({
|
|
1736
1772
|
id: "app.middleware.performance",
|
|
1737
1773
|
run: async ({ task, next }) => {
|
|
1738
1774
|
const perfConfiguration = performanceTag.extract(task.definition); // you can just use .exists() if you want to check for presence
|
|
@@ -1899,7 +1935,8 @@ const testEmailer = override(productionEmailer, {
|
|
|
1899
1935
|
init: async () => new MockEmailer(),
|
|
1900
1936
|
});
|
|
1901
1937
|
|
|
1902
|
-
// Option 2:
|
|
1938
|
+
// Option 2: The system is really flexible, and override is just bringing in type safety, nothing else under the hood.
|
|
1939
|
+
// Using spread operator works the same way but does not provide type-safety.
|
|
1903
1940
|
const testEmailer = resource({
|
|
1904
1941
|
...productionEmailer,
|
|
1905
1942
|
init: async () => {},
|
|
@@ -2157,7 +2194,7 @@ const userActionEvent = event({
|
|
|
2157
2194
|
payloadSchema: userActionSchema, // Validates on emit
|
|
2158
2195
|
});
|
|
2159
2196
|
|
|
2160
|
-
const
|
|
2197
|
+
const notificationHook = hook({
|
|
2161
2198
|
id: "app.tasks.sendNotification",
|
|
2162
2199
|
on: userActionEvent,
|
|
2163
2200
|
run: async (eventData) => {
|
|
@@ -2168,7 +2205,7 @@ const notificationTask = task({
|
|
|
2168
2205
|
|
|
2169
2206
|
const app = resource({
|
|
2170
2207
|
id: "app",
|
|
2171
|
-
register: [userActionEvent,
|
|
2208
|
+
register: [userActionEvent, notificationHook],
|
|
2172
2209
|
dependencies: { userActionEvent },
|
|
2173
2210
|
init: async (_, { userActionEvent }) => {
|
|
2174
2211
|
// This works - valid payload
|
|
@@ -2573,8 +2610,8 @@ const userRegistered = event<{ userId: string; email: string }>({
|
|
|
2573
2610
|
});
|
|
2574
2611
|
|
|
2575
2612
|
// Middleware
|
|
2576
|
-
const authMiddleware =
|
|
2577
|
-
id: "app.middleware.auth",
|
|
2613
|
+
const authMiddleware = taskMiddleware<{ requiredRole?: string }>({
|
|
2614
|
+
id: "app.middleware.task.auth",
|
|
2578
2615
|
run: async ({ task, next }, deps, config) => {
|
|
2579
2616
|
const context = RequestContext.use();
|
|
2580
2617
|
if (config?.requiredRole && context.role !== config.requiredRole) {
|
|
@@ -2760,10 +2797,11 @@ const registerUser = task({ id: "app.tasks.registerUser" /* ... */ });
|
|
|
2760
2797
|
const { value: t, dispose } = await run(harness);
|
|
2761
2798
|
|
|
2762
2799
|
// You have 3 ways to interact with the system, run tasks, get resource values and emit events
|
|
2800
|
+
// You can run them dynamically with just string ids, but using the created objects gives you type-safety.
|
|
2763
2801
|
|
|
2764
2802
|
const result = await t.runTask(registerUser, { email: "x@y.z" });
|
|
2765
2803
|
const value = t.getResourceValue(testDb); // since the resolution is done by id, this will return the exact same result as t.getResourceValue(actualDb)
|
|
2766
|
-
t.emitEvent(
|
|
2804
|
+
t.emitEvent(event, payload);
|
|
2767
2805
|
expect(result).toMatchObject({ success: true });
|
|
2768
2806
|
await dispose();
|
|
2769
2807
|
```
|
|
@@ -3,4 +3,4 @@ import { DependencyMapType, IEventDefinition, ITaskMeta, IHook, IHookDefinition
|
|
|
3
3
|
* Define a hook (event listeners).
|
|
4
4
|
* Same shape as task with mandatory `on` and without `middleware`.
|
|
5
5
|
*/
|
|
6
|
-
export declare function defineHook<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition = any, TMeta extends ITaskMeta = any>(hookDef: IHookDefinition<D, TOn, TMeta>): IHook<D, TOn, TMeta>;
|
|
6
|
+
export declare function defineHook<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition<any> | readonly IEventDefinition<any>[] = any, TMeta extends ITaskMeta = any>(hookDef: IHookDefinition<D, TOn, TMeta>): IHook<D, TOn, TMeta>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineHook.js","sourceRoot":"","sources":["../../src/definers/defineHook.ts"],"names":[],"mappings":";;AAeA,
|
|
1
|
+
{"version":3,"file":"defineHook.js","sourceRoot":"","sources":["../../src/definers/defineHook.ts"],"names":[],"mappings":";;AAeA,gCAoBC;AAnCD,kCAQiB;AACjB,0DAAuD;AAEvD;;;GAGG;AACH,SAAgB,UAAU,CAOxB,OAAuC;IACvC,MAAM,QAAQ,GAAG,IAAA,6BAAa,GAAE,CAAC;IACjC,OAAO;QACL,CAAC,iBAAU,CAAC,EAAE,IAAI;QAClB,CAAC,qBAAc,CAAC,EAAE,QAAQ;QAC1B,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,YAAY,EAAE,OAAO,CAAC,YAAY,IAAK,EAAQ;QAC/C,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAK,EAAY;QACnC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;KACD,CAAC;AAC5B,CAAC"}
|
|
@@ -55,6 +55,9 @@ class DependencyProcessor {
|
|
|
55
55
|
async computeTaskDependencies(task) {
|
|
56
56
|
const deps = task.task.dependencies;
|
|
57
57
|
task.computedDependencies = await this.extractDependencies(deps, task.task.id);
|
|
58
|
+
// Mark task as initialized so subsequent injections don't recompute using
|
|
59
|
+
// a potentially lazy dependencies() function and lose computed values.
|
|
60
|
+
task.isInitialized = true;
|
|
58
61
|
}
|
|
59
62
|
// Most likely these are resources that no-one has dependencies towards
|
|
60
63
|
// We need to ensure they work too!
|
|
@@ -67,6 +70,7 @@ class DependencyProcessor {
|
|
|
67
70
|
const { value, context } = await this.resourceInitializer.initializeResource(resource.resource, resource.config, resource.computedDependencies);
|
|
68
71
|
resource.context = context;
|
|
69
72
|
resource.value = value;
|
|
73
|
+
resource.isInitialized = true;
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
@@ -152,11 +156,23 @@ class DependencyProcessor {
|
|
|
152
156
|
if (eventDefinition === "*") {
|
|
153
157
|
this.eventManager.addGlobalListener(handler, { order });
|
|
154
158
|
}
|
|
159
|
+
else if (Array.isArray(eventDefinition)) {
|
|
160
|
+
for (const ed of eventDefinition) {
|
|
161
|
+
if (this.store.events.get(ed.id) === undefined) {
|
|
162
|
+
throw new errors_1.EventNotFoundError(ed.id);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.eventManager.addListener(eventDefinition, handler, {
|
|
166
|
+
order,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
155
169
|
else {
|
|
156
170
|
if (this.store.events.get(eventDefinition.id) === undefined) {
|
|
157
171
|
throw new errors_1.EventNotFoundError(eventDefinition.id);
|
|
158
172
|
}
|
|
159
|
-
this.eventManager.addListener(eventDefinition, handler, {
|
|
173
|
+
this.eventManager.addListener(eventDefinition, handler, {
|
|
174
|
+
order,
|
|
175
|
+
});
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyProcessor.js","sourceRoot":"","sources":["../../src/models/DependencyProcessor.ts"],"names":[],"mappings":";;;AAgBA,mCAAmC;AAEnC,+DAA4D;AAE5D,sCAImB;AAGnB;;;;GAIG;AACH,MAAa,mBAAmB;IAIT;IACA;IACA;IACA;IANF,mBAAmB,CAAsB;IAE5D,YACqB,KAAY,EACZ,YAA0B,EAC1B,UAAsB,EACtB,MAAc;QAHd,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAQ;QAEjC,IAAI,CAAC,mBAAmB,GAAG,IAAI,yCAAmB,CAChD,KAAK,EACL,YAAY,EACZ,MAAM,CACP,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,sBAAsB;QAC1B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC;YACjE,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CACzD,UAAU,CAAC,UAAU,CAAC,YAAY,EAClC,UAAU,CAAC,UAAU,CAAC,EAAE,CACzB,CAAC;YAEF,UAAU,CAAC,oBAAoB,GAA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AAE,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAChE,MAAM,OAAO,GAAG,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAC3D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GACtB,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAC/C,QAAQ,EACR,MAAM,EACN,OAAO,CACR,CAAC;gBAEJ,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;gBAChC,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;YAC9B,CAAC;YAED,qCAAqC;YACrC,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC;QACrC,CAAC;QAED,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;CACF;AA9VD,kDA8VC"}
|
package/dist/types/event.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { IOptionalDependency, IValidationSchema } from "../defs";
|
|
2
2
|
import { TagType } from "./tag";
|
|
3
3
|
import { IEventMeta } from "./meta";
|
|
4
|
-
import { symbolEvent, symbolFilePath } from "./utilities";
|
|
4
|
+
import { CommonPayload, symbolEvent, symbolFilePath } from "./utilities";
|
|
5
5
|
export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
6
|
+
export declare function onAnyOf<T extends readonly IEventDefinition<any>[]>(...defs: T): T;
|
|
7
|
+
/**
|
|
8
|
+
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
9
|
+
* Narrows payload type to the intersection of the provided events' payloads.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isOneOf<TDefs extends readonly IEventDefinition<any>[]>(emission: IEventEmission<any>, defs: TDefs): emission is IEventEmission<CommonPayload<TDefs>>;
|
|
6
12
|
export interface IEventDefinition<TPayload = void> {
|
|
7
13
|
id: string;
|
|
8
14
|
meta?: IEventMeta;
|
package/dist/types/event.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onAnyOf = onAnyOf;
|
|
4
|
+
exports.isOneOf = isOneOf;
|
|
3
5
|
const utilities_1 = require("./utilities");
|
|
6
|
+
// Helper to keep tuple inference intact for multi-event hooks
|
|
7
|
+
function onAnyOf(...defs) {
|
|
8
|
+
return defs;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
12
|
+
* Narrows payload type to the intersection of the provided events' payloads.
|
|
13
|
+
*/
|
|
14
|
+
function isOneOf(emission, defs) {
|
|
15
|
+
return defs.some((d) => d.id === emission.id);
|
|
16
|
+
}
|
|
4
17
|
//# sourceMappingURL=event.js.map
|
package/dist/types/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;AAUA,0BAIC;AAMD,0BAKC;AAtBD,2CAAyE;AAMzE,8DAA8D;AAC9D,SAAgB,OAAO,CACrB,GAAG,IAAO;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CACrB,QAA6B,EAC7B,IAAW;IAEX,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/types/hook.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { DependencyMapType, DependencyValuesType, IEventDefinition, IEventEmission, ExtractEventParams } from "../defs";
|
|
2
2
|
import { TagType } from "./tag";
|
|
3
3
|
import { ITaskMeta } from "./meta";
|
|
4
|
-
import { symbolFilePath, symbolHook } from "./utilities";
|
|
5
|
-
|
|
4
|
+
import { CommonPayload, symbolFilePath, symbolHook } from "./utilities";
|
|
5
|
+
type OnType = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
6
|
+
export interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> {
|
|
6
7
|
id: string;
|
|
7
8
|
dependencies?: TDependencies | (() => TDependencies);
|
|
8
9
|
on: TOn;
|
|
9
10
|
/** Listener execution order. Lower numbers run first. */
|
|
10
11
|
order?: number;
|
|
11
12
|
meta?: TMeta;
|
|
12
|
-
run: (event: IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
13
|
+
run: (event: IEventEmission<TOn extends "*" ? any : TOn extends readonly IEventDefinition<any>[] ? CommonPayload<TOn> : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
13
14
|
tags?: TagType[];
|
|
14
15
|
}
|
|
15
|
-
export interface IHook<TDependencies extends DependencyMapType = {}, TOn extends
|
|
16
|
+
export interface IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
16
17
|
id: string;
|
|
17
18
|
dependencies: TDependencies | (() => TDependencies);
|
|
18
19
|
[symbolFilePath]: string;
|
|
19
20
|
[symbolHook]: true;
|
|
20
21
|
tags: TagType[];
|
|
21
22
|
}
|
|
23
|
+
export {};
|
package/dist/types/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":";;AASA,
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":";;AASA,2CAAwE"}
|
|
@@ -60,7 +60,11 @@ export interface IOptionalDependency<T> {
|
|
|
60
60
|
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer D> ? I : never;
|
|
61
61
|
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer D> ? O : never;
|
|
62
62
|
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer D> ? V extends Promise<infer U> ? U : V : never;
|
|
63
|
-
export type ExtractEventParams<T> = T extends IEvent<infer P> ? P : never;
|
|
63
|
+
export type ExtractEventParams<T> = T extends IEventDefinition<infer P> ? P : T extends IEvent<infer P> ? P : never;
|
|
64
|
+
export type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never;
|
|
65
|
+
export type CommonPayload<T extends readonly IEventDefinition<any>[] | IEventDefinition<any>> = T extends readonly IEventDefinition<any>[] ? {
|
|
66
|
+
[K in keyof ExtractEventParams<T[number]>]: UnionToIntersection<ExtractEventParams<T[number]> extends any ? ExtractEventParams<T[number]>[K] : never>;
|
|
67
|
+
} : ExtractEventParams<T>;
|
|
64
68
|
/**
|
|
65
69
|
* Task dependencies transform into callable functions: call with the task input
|
|
66
70
|
* and you receive the task output.
|