@bluelibs/runner 4.7.0 → 4.8.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 (49) hide show
  1. package/AI.md +88 -95
  2. package/README.md +205 -144
  3. package/dist/browser/index.cjs +738 -486
  4. package/dist/browser/index.cjs.map +1 -1
  5. package/dist/browser/index.mjs +735 -486
  6. package/dist/browser/index.mjs.map +1 -1
  7. package/dist/define.d.ts +1 -1
  8. package/dist/definers/builders/asyncContext.d.ts +11 -0
  9. package/dist/definers/builders/error.d.ts +13 -0
  10. package/dist/definers/builders/middleware.d.ts +3 -3
  11. package/dist/definers/defineAsyncContext.d.ts +15 -0
  12. package/dist/definers/defineError.d.ts +26 -0
  13. package/dist/definers/tools.d.ts +6 -0
  14. package/dist/edge/index.cjs +738 -486
  15. package/dist/edge/index.cjs.map +1 -1
  16. package/dist/edge/index.mjs +735 -486
  17. package/dist/edge/index.mjs.map +1 -1
  18. package/dist/errors.d.ts +60 -102
  19. package/dist/globals/debug.d.ts +10 -0
  20. package/dist/globals/globalMiddleware.d.ts +3 -3
  21. package/dist/globals/middleware/requireContext.middleware.d.ts +2 -2
  22. package/dist/globals/resources/tunnel/protocol.d.ts +8 -1
  23. package/dist/globals/resources/tunnel/serializer.d.ts +1 -1
  24. package/dist/globals/types.d.ts +1 -0
  25. package/dist/http-client.d.ts +4 -0
  26. package/dist/http-fetch-tunnel.resource.d.ts +11 -0
  27. package/dist/index.d.ts +14 -5
  28. package/dist/models/Store.d.ts +6 -2
  29. package/dist/models/StoreRegistry.d.ts +6 -0
  30. package/dist/node/exposure/httpResponse.d.ts +1 -1
  31. package/dist/node/exposure/requestContext.d.ts +1 -1
  32. package/dist/node/{mixed-http-client.node.d.ts → http-mixed-client.d.ts} +1 -1
  33. package/dist/node/http-smart-client.model.d.ts +2 -0
  34. package/dist/node/node.cjs +914 -531
  35. package/dist/node/node.cjs.map +1 -1
  36. package/dist/node/node.mjs +911 -531
  37. package/dist/node/node.mjs.map +1 -1
  38. package/dist/types/asyncContext.d.ts +39 -0
  39. package/dist/types/error.d.ts +34 -0
  40. package/dist/types/runner.d.ts +13 -0
  41. package/dist/types/symbols.d.ts +6 -0
  42. package/dist/types/utilities.d.ts +6 -4
  43. package/dist/universal/index.cjs +738 -486
  44. package/dist/universal/index.cjs.map +1 -1
  45. package/dist/universal/index.mjs +735 -486
  46. package/dist/universal/index.mjs.map +1 -1
  47. package/dist/utils/detectRunnerMode.d.ts +9 -0
  48. package/package.json +1 -1
  49. package/dist/context.d.ts +0 -31
@@ -0,0 +1,39 @@
1
+ import type { ITaskMiddlewareConfigured } from "defs";
2
+ export declare const ASYNC_CONTEXT_TYPES_LOADED: true;
3
+ import { symbolAsyncContext } from "./symbols";
4
+ import type { IValidationSchema, IOptionalDependency } from "./utilities";
5
+ export interface IAsyncContextDefinition<T> {
6
+ id: string;
7
+ serialize?(data: T): string;
8
+ parse?(data: string): T;
9
+ /**
10
+ * When provided, context values will be validated when provide() is called.
11
+ */
12
+ configSchema?: IValidationSchema<T>;
13
+ }
14
+ /**
15
+ * The generic AsyncContext object returned by `defineAsyncContext`.
16
+ */
17
+ export interface IAsyncContext<T> {
18
+ /** unique symbol used as key in the AsyncLocalStorage map */
19
+ readonly id: string;
20
+ /** Brand marker for registration and runtime checks */
21
+ [symbolAsyncContext]: true;
22
+ /** Retrieve the current context value or throw */
23
+ use(): T;
24
+ /**
25
+ * Provide a value for this context during the lifetime of `fn()`
26
+ */
27
+ provide<R>(value: T, fn: () => Promise<R> | R): Promise<R> | R;
28
+ /**
29
+ * Generates a middleware that guarantees the context exists (and optionally
30
+ * enforces that certain keys are present on the context object).
31
+ */
32
+ require<K extends keyof T = never>(keys?: K[]): ITaskMiddlewareConfigured<{
33
+ context: IAsyncContext<T>;
34
+ }>;
35
+ serialize(data: T): string;
36
+ parse(data: string): T;
37
+ /** Return an optional dependency wrapper for this context */
38
+ optional(): IOptionalDependency<IAsyncContext<T>>;
39
+ }
@@ -0,0 +1,34 @@
1
+ import { symbolError } from "./symbols";
2
+ import type { IOptionalDependency } from "./utilities";
3
+ import type { IValidationSchema } from "./utilities";
4
+ export declare const ERROR_TYPES_LOADED: true;
5
+ export interface IErrorDefinition<TData extends DefaultErrorType = DefaultErrorType> {
6
+ id: string;
7
+ serialize?: (data: TData) => string;
8
+ parse?: (data: string) => TData;
9
+ format?: (data: TData) => string;
10
+ /**
11
+ * Validate error data on throw(). If provided, data is parsed first.
12
+ */
13
+ dataSchema?: IValidationSchema<TData>;
14
+ }
15
+ export interface IErrorDefinitionFinal<TData extends DefaultErrorType> extends IErrorDefinition<TData> {
16
+ format: (data: TData) => string;
17
+ }
18
+ export type DefaultErrorType = Record<string, unknown>;
19
+ /**
20
+ * Runtime helper returned by defineError()/r.error().
21
+ * Contains helpers to throw typed errors and perform type-safe checks.
22
+ */
23
+ export interface IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> {
24
+ /** Unique id for registration and DI */
25
+ id: string;
26
+ /** Throw a typed error with the given data */
27
+ throw(data: TData): never;
28
+ /** Type guard for checking if an unknown error is this error */
29
+ is(error: unknown): boolean;
30
+ /** Brand symbol for runtime detection */
31
+ [symbolError]: true;
32
+ /** Return an optional dependency wrapper for this error */
33
+ optional(): IOptionalDependency<IErrorHelper<TData>>;
34
+ }
@@ -52,4 +52,17 @@ export type RunOptions = {
52
52
  * you don't have event deadlocks to improve event emission performance.
53
53
  */
54
54
  runtimeCycleDetection?: boolean;
55
+ /**
56
+ * Specify in which mode to run "dev", "prod" or "test".
57
+ * If inside Node this is automatically detected from the NODE_ENV environment variable if not provided.
58
+ */
59
+ mode?: RunnerMode;
55
60
  };
61
+ /**
62
+ * The mode in which the runner is operating
63
+ */
64
+ export declare enum RunnerMode {
65
+ TEST = "test",
66
+ DEV = "dev",
67
+ PROD = "prod"
68
+ }
@@ -10,6 +10,8 @@ export declare const symbolPhantomTask: unique symbol;
10
10
  export declare const symbolResource: unique symbol;
11
11
  export declare const symbolResourceWithConfig: unique symbol;
12
12
  export declare const symbolEvent: unique symbol;
13
+ /** @internal Marks an error helper definition */
14
+ export declare const symbolError: unique symbol;
13
15
  export declare const symbolMiddleware: unique symbol;
14
16
  /** New brands for separated middleware kinds */
15
17
  export declare const symbolTaskMiddleware: unique symbol;
@@ -17,6 +19,8 @@ export declare const symbolResourceMiddleware: unique symbol;
17
19
  export declare const symbolMiddlewareConfigured: unique symbol;
18
20
  /** Marks a task that has been patched by a tunnel. Value is the local side mode. */
19
21
  export declare const symbolTunneledTask: unique symbol;
22
+ /** Records which tunnel resource owns the task patching (exclusivity). */
23
+ export declare const symbolTunneledBy: unique symbol;
20
24
  /** @internal Marks hook definitions (event listeners without middleware) */
21
25
  export declare const symbolHook: unique symbol;
22
26
  /** @internal Marks a tag definition */
@@ -26,3 +30,5 @@ export declare const symbolTagConfigured: unique symbol;
26
30
  export declare const symbolOptionalDependency: unique symbol;
27
31
  /** @internal Path to aid anonymous id generation and error messages */
28
32
  export declare const symbolFilePath: unique symbol;
33
+ /** @internal Marks an async context definition */
34
+ export declare const symbolAsyncContext: unique symbol;
@@ -6,6 +6,8 @@ import { IHook } from "./hook";
6
6
  import { IEvent, IEventDefinition } from "./event";
7
7
  import { ITag } from "./tag";
8
8
  import { symbolOptionalDependency } from "./symbols";
9
+ import { IErrorHelper } from "./error";
10
+ import type { IAsyncContext } from "./asyncContext";
9
11
  export * from "./symbols";
10
12
  /**
11
13
  * Generic validation schema interface that can be implemented by any validation library.
@@ -49,7 +51,7 @@ export type OverridableElements = IResource<any, any, any, any, any> | ITask<any
49
51
  * for tasks and resources. Values are later transformed into the actual
50
52
  * callable/value shape by `DependencyValuesType`.
51
53
  */
52
- export type DependencyMapType = Record<string, ITask<any, any, any, any, any, any> | IResource<any, any, any, any, any, any, any> | IEvent<any> | IOptionalDependency<ITask<any, any, any, any, any, any>> | IOptionalDependency<IResource<any, any, any, any, any, any, any>> | IOptionalDependency<IEvent<any>>>;
54
+ export type DependencyMapType = Record<string, ITask<any, any, any, any, any, any> | IResource<any, any, any, any, any, any, any> | IEvent<any> | IErrorHelper<any> | IAsyncContext<any> | IOptionalDependency<ITask<any, any, any, any, any, any>> | IOptionalDependency<IResource<any, any, any, any, any, any, any>> | IOptionalDependency<IEvent<any>> | IOptionalDependency<IErrorHelper<any>> | IOptionalDependency<IAsyncContext<any>>>;
53
55
  /** Wrapper type marking a dependency as optional at wiring time */
54
56
  export interface IOptionalDependency<T> {
55
57
  /** The wrapped dependency definition */
@@ -86,7 +88,7 @@ type EventDependency<P> = P extends void ? (() => Promise<void>) & ((input?: Rec
86
88
  * - Resource -> resolved value
87
89
  * - Event -> emit function
88
90
  */
89
- export type DependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IOptionalDependency<infer U> ? DependencyValueType<U> | undefined : never;
91
+ export type DependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IErrorHelper<any> ? T : T extends IAsyncContext<any> ? T : T extends IOptionalDependency<infer U> ? DependencyValueType<U> | undefined : never;
90
92
  export type DependencyValuesType<T extends DependencyMapType> = {
91
93
  [K in keyof T]: DependencyValueType<T[K]>;
92
94
  };
@@ -95,7 +97,7 @@ export type TaskDependencyWithIntercept<TInput, TOutput> = TaskDependency<TInput
95
97
  intercept: (middleware: TaskLocalInterceptor<TInput, TOutput>) => void;
96
98
  };
97
99
  /** Resource-context dependency typing where tasks expose intercept() */
98
- export type ResourceDependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependencyWithIntercept<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IOptionalDependency<infer U> ? ResourceDependencyValueType<U> | undefined : never;
100
+ export type ResourceDependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependencyWithIntercept<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IErrorHelper<any> ? T : T extends IAsyncContext<any> ? T : T extends IOptionalDependency<infer U> ? ResourceDependencyValueType<U> | undefined : never;
99
101
  export type ResourceDependencyValuesType<T extends DependencyMapType> = {
100
102
  [K in keyof T]: ResourceDependencyValueType<T[K]>;
101
103
  };
@@ -108,4 +110,4 @@ export type ResourceDependencyValuesType<T extends DependencyMapType> = {
108
110
  */
109
111
  export type RegisterableItems = IResourceWithConfig<any, any, any, any, any, any, any> | IResource<void, any, any, any, any, any, any> | IResource<{
110
112
  [K in any]?: any;
111
- }, any, any, any, any, any, any> | ITask<any, any, any, any, any, any> | IHook<any, any> | ITaskMiddleware<any, any, any, any> | IResourceMiddleware<any, any, any, any> | IEvent<any> | ITag<any, any, any>;
113
+ }, any, any, any, any, any, any> | ITask<any, any, any, any, any, any> | IHook<any, any> | ITaskMiddleware<any, any, any, any> | IResourceMiddleware<any, any, any, any> | IEvent<any> | IAsyncContext<any> | IErrorHelper<any> | ITag<any, any, any>;