@bluelibs/runner 6.0.0 → 6.1.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.
Files changed (40) hide show
  1. package/dist/browser/index.cjs +452 -249
  2. package/dist/browser/index.cjs.map +1 -1
  3. package/dist/browser/index.mjs +452 -249
  4. package/dist/browser/index.mjs.map +1 -1
  5. package/dist/edge/index.cjs +452 -249
  6. package/dist/edge/index.cjs.map +1 -1
  7. package/dist/edge/index.mjs +452 -249
  8. package/dist/edge/index.mjs.map +1 -1
  9. package/dist/node/node.cjs +4047 -3842
  10. package/dist/node/node.cjs.map +1 -1
  11. package/dist/node/node.mjs +4047 -3842
  12. package/dist/node/node.mjs.map +1 -1
  13. package/dist/types/definers/assertDefinitionId.d.ts +1 -0
  14. package/dist/types/definers/builders/resource/index.d.ts +1 -3
  15. package/dist/types/definers/builders/resource/types.d.ts +0 -1
  16. package/dist/types/errors/domain-error-ids.d.ts +0 -2
  17. package/dist/types/errors/domain-runtime.errors.d.ts +0 -6
  18. package/dist/types/globals/globalResources.d.ts +4 -4
  19. package/dist/types/globals/middleware/keyBuilder.shared.d.ts +2 -0
  20. package/dist/types/globals/middleware/rateLimit.middleware.d.ts +8 -2
  21. package/dist/types/globals/middleware/temporal.middleware.d.ts +7 -26
  22. package/dist/types/globals/middleware/temporal.shared.d.ts +28 -0
  23. package/dist/types/models/Store.d.ts +1 -1
  24. package/dist/types/models/StoreRegistry.d.ts +3 -0
  25. package/dist/types/models/createFrameworkRootGateway.d.ts +3 -1
  26. package/dist/types/models/store-registry/CanonicalIdCompiler.d.ts +8 -0
  27. package/dist/types/models/store-registry/OwnerScope.d.ts +5 -0
  28. package/dist/types/models/store-registry/StoreRegistryWriter.d.ts +6 -3
  29. package/dist/types/models/store-registry/registerableKind.d.ts +19 -0
  30. package/dist/types/node/node.d.ts +2 -2
  31. package/dist/types/node/rpc-lanes/rpcLanes.resource.d.ts +1 -0
  32. package/dist/types/public.d.ts +10 -189
  33. package/dist/types/types/resource.d.ts +0 -9
  34. package/dist/types/types/subtree.d.ts +4 -2
  35. package/dist/universal/index.cjs +452 -249
  36. package/dist/universal/index.cjs.map +1 -1
  37. package/dist/universal/index.mjs +452 -249
  38. package/dist/universal/index.mjs.map +1 -1
  39. package/package.json +1 -1
  40. package/readmes/AI.md +21 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluelibs/runner",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "BlueLibs Runner",
5
5
  "sideEffects": false,
6
6
  "main": "dist/universal/index.cjs",
package/readmes/AI.md CHANGED
@@ -221,11 +221,13 @@ They are Runner's main composition and ownership unit: a resource can register c
221
221
  - `health(value, config, deps, context)` is an optional async probe used by `resources.health.getHealth(...)` and `runtime.getHealth(...)`.
222
222
  Return `{ status: "healthy" | "degraded" | "unhealthy", message?, details? }`.
223
223
  - Config-only resources can omit `.init()` — their resolved value is `undefined`; they are used purely for configuration access and registration.
224
- - `r.resource(id, { gateway: true })` prevents the resource from adding its own namespace segment.
225
- - Gateway resources cannot be passed directly to `run(...)`; wrap them in a non-gateway root resource first.
224
+ - User resources contribute their own ownership segment to canonical ids.
225
+ - The app resource passed to `run(...)` is a normal resource, so direct registrations compile as `app.tasks.x`, `app.events.x`, `app.middleware.task.x`, and so on.
226
+ - Child resources continue that chain, so nested registrations compile as `app.billing.tasks.x`.
227
+ - Only the internal synthetic framework root is transparent, and it does not appear in user-facing ids.
228
+ - `runtime-framework-root` is reserved for that internal framework root and cannot be used as a user resource id.
226
229
  - If you register something, you are a non-leaf resource.
227
230
  - Non-leaf resources cannot be forked.
228
- - Gateway resources cannot be forked with `.fork()` because multiple gateway instances would compile the same child canonical ids.
229
231
  - `.context(() => initialContext)` can hold mutable resource-local state used across lifecycle phases.
230
232
 
231
233
  Use the lifecycle intentionally:
@@ -401,17 +403,17 @@ const installer = r
401
403
 
402
404
  Runner ships with these resilience-focused built-ins.
403
405
 
404
- | Middleware | Config | Notes |
405
- | -------------- | ----------------------------------------- | ------------------------------------------------------------- |
406
- | cache | `{ ttl, max, ttlAutopurge, keyBuilder }` | requires `resources.cache`; Node exposes `redisCacheProvider` |
407
- | concurrency | `{ limit, key?, semaphore? }` | limits executions; share concurrency logic via `semaphore` |
408
- | circuitBreaker | `{ failureThreshold, resetTimeout }` | opens after failures, fails fast until recovery |
409
- | debounce | `{ ms }` | runs only after inactivity |
410
- | throttle | `{ ms }` | max once per `ms` |
411
- | fallback | `{ fallback }` | static value, function, or task fallback |
412
- | rateLimit | `{ windowMs, max }` | fixed-window limit per instance |
413
- | retry | `{ retries, stopRetryIf, delayStrategy }` | transient failures with configurable logic |
414
- | timeout | `{ ttl }` | aborts long-running executions via AbortController |
406
+ | Middleware | Config | Notes |
407
+ | -------------- | ----------------------------------------- | ------------------------------------------------------------------------ |
408
+ | cache | `{ ttl, max, ttlAutopurge, keyBuilder }` | backed by `resources.cache`; customize with `resources.cache.with(...)` |
409
+ | concurrency | `{ limit, key?, semaphore? }` | limits executions; share concurrency logic via `semaphore` |
410
+ | circuitBreaker | `{ failureThreshold, resetTimeout }` | opens after failures, fails fast until recovery |
411
+ | debounce | `{ ms, keyBuilder? }` | waits for inactivity, then runs once with the latest input for that key |
412
+ | throttle | `{ ms, keyBuilder? }` | runs immediately, then suppresses burst calls until the window ends |
413
+ | fallback | `{ fallback }` | static value, function, or task fallback |
414
+ | rateLimit | `{ windowMs, max, keyBuilder? }` | fixed-window admission limit per key, eg "50 per second" |
415
+ | retry | `{ retries, stopRetryIf, delayStrategy }` | transient failures with configurable logic |
416
+ | timeout | `{ ttl }` | rejects after the deadline and aborts cooperative work via `AbortSignal` |
415
417
 
416
418
  Resource: `middleware.resource.retry`, `middleware.resource.timeout` (same semantics).
417
419
  Non-resilience: `middleware.task.requireContext.with({ context })` — enforces async context.
@@ -421,10 +423,12 @@ Non-resilience: `middleware.task.requireContext.with({ context })` — enforces
421
423
  r.task("cached").middleware([middleware.task.cache.with({ ttl: 60_000 })]).run(...).build();
422
424
  r.task("fallback-retry").middleware([middleware.task.fallback.with({fallback:"default"}), middleware.task.retry.with({retries:3})]).run(...).build();
423
425
  r.task("ratelimit-concurrency").middleware([middleware.task.rateLimit.with({windowMs:60_000,max:10}), middleware.task.concurrency.with({limit:5})]).run(...).build();
426
+ r.task("ratelimit-ip").middleware([middleware.task.rateLimit.with({windowMs:1_000,max:50,keyBuilder:() => RequestContext.use().ip})]).run(...).build();
424
427
  ```
425
428
 
426
429
  **Order:** fallback (outermost) → timeout (inside retry if per-attempt budgets needed) → others.
427
- **Use:** rate-limit for admission, concurrency for in-flight, circuit-breaker for fail-fast, cache for idempotent reads, debounce/throttle for bursty calls.
430
+ **Use:** rate-limit for quotas like "50/s", concurrency for in-flight, circuit-breaker for fail-fast, cache for idempotent reads, debounce/throttle for burst shaping.
431
+ **Partitioning:** `rateLimit`, `debounce`, and `throttle` default to `taskId`; pass `keyBuilder(taskId, input)` to partition by async-context values, user ids, tenants, or similar keys.
428
432
 
429
433
  Built-in journal keys exist for middleware introspection:
430
434
 
@@ -548,12 +552,12 @@ Examples:
548
552
 
549
553
  ### Subtrees
550
554
 
551
- - `.subtree(policy)` and `.subtree((config) => policy)` can auto-attach middleware to nested tasks/resources.
555
+ - `.subtree(policy)`, `.subtree([policyA, policyB])`, and `.subtree((config) => policy | policy[])` can auto-attach middleware to nested tasks/resources.
552
556
  - Subtrees can validate contained definitions.
553
557
  - `subtree.validate` is generic for compiled subtree definitions and can be one function or an array.
554
558
  - Typed validation is also available on `tasks`, `resources`, `hooks`, `events`, `tags`, `taskMiddleware`, and `resourceMiddleware`.
555
559
  - Generic and typed validators both run when they match the same compiled definition.
556
- - Validators receive only the compiled definition. Use `subtree((config) => ({ ... }))` when the policy depends on resource config.
560
+ - Validators receive only the compiled definition. Use `subtree((config) => ({ ... }))` or `subtree((config) => [{ ... }, { ... }])` when the policy depends on resource config.
557
561
  - Use exported guards such as `isTask(...)` and `isResource(...)` inside `subtree.validate(...)` for cross-type checks.
558
562
  - Validators are return-based:
559
563
  - return `SubtreeViolation[]` for normal policy failures
@@ -565,7 +569,6 @@ Examples:
565
569
  - Forks clone identity, not structure.
566
570
  - If a resource declares `.register(...)`, it is non-leaf and `.fork()` is invalid.
567
571
  - Use `.fork(...)` when you need another instance of a leaf resource.
568
- - `.fork()` is not supported for gateway resources.
569
572
  - `.fork()` returns a built resource. You do not call `.build()` again.
570
573
  - Compose a distinct parent resource when you need a structural variant of a non-leaf resource.
571
574
  - Durable support is registered via `resources.durable`, while concrete durable backends use normal forks such as `resources.memoryWorkflow.fork("app-durable")`.