@bluelibs/runner 3.3.0 → 3.3.2
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/dist/define.js +24 -23
- package/dist/define.js.map +1 -1
- package/dist/defs/core.d.ts +144 -0
- package/dist/defs/core.js +6 -0
- package/dist/defs/core.js.map +1 -0
- package/dist/defs/symbols.d.ts +42 -0
- package/dist/defs/symbols.js +45 -0
- package/dist/defs/symbols.js.map +1 -0
- package/dist/defs/tags.d.ts +70 -0
- package/dist/defs/tags.js +6 -0
- package/dist/defs/tags.js.map +1 -0
- package/dist/defs.d.ts +11 -18
- package/dist/defs.js +16 -19
- package/dist/defs.js.map +1 -1
- package/dist/models/StoreTypes.d.ts +2 -2
- package/dist/types/dependencies.d.ts +47 -18
- package/dist/types/event.d.ts +49 -0
- package/dist/types/event.js +4 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/index.d.ts +4 -10
- package/dist/types/index.js +8 -7
- package/dist/types/index.js.map +1 -1
- package/dist/types/metadata.d.ts +75 -0
- package/dist/types/metadata.js +3 -0
- package/dist/types/metadata.js.map +1 -0
- package/dist/types/middleware.d.ts +43 -18
- package/dist/types/middleware.js +0 -3
- package/dist/types/middleware.js.map +1 -1
- package/dist/types/resource.d.ts +96 -0
- package/dist/types/resource.js +3 -0
- package/dist/types/resource.js.map +1 -0
- package/dist/types/symbols.d.ts +17 -0
- package/dist/types/symbols.js +18 -3
- package/dist/types/symbols.js.map +1 -1
- package/dist/types/task.d.ts +68 -0
- package/dist/types/task.js +3 -0
- package/dist/types/task.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/models/EventManager.test.ts +39 -6
- package/src/__tests__/tools/getCallerFile.test.ts +9 -11
- package/src/define.ts +31 -24
- package/src/defs.ts +11 -19
- package/src/models/StoreTypes.ts +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DependencyMapType, DependencyValuesType, IEventDefinition, IResource, ITask, IMiddleware } from "../defs";
|
|
1
|
+
import { DependencyMapType, DependencyValuesType, IEventDefinition, IResource, ITask, IMiddleware, IEvent } from "../defs";
|
|
2
2
|
export type ResourceStoreElementType<C = any, V = any, D extends DependencyMapType = {}, TContext = any> = {
|
|
3
3
|
resource: IResource<C, V, D>;
|
|
4
4
|
computedDependencies?: DependencyValuesType<D>;
|
|
@@ -17,5 +17,5 @@ export type MiddlewareStoreElementType<TDeps extends DependencyMapType = any> =
|
|
|
17
17
|
computedDependencies: DependencyValuesType<TDeps>;
|
|
18
18
|
};
|
|
19
19
|
export type EventStoreElementType = {
|
|
20
|
-
event:
|
|
20
|
+
event: IEvent<any>;
|
|
21
21
|
};
|
|
@@ -1,21 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type ExtractResourceValue<T> = T extends
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A mapping of dependency keys to Runner definitions. Used in `dependencies`
|
|
3
|
+
* for tasks and resources. Values are later transformed into the actual
|
|
4
|
+
* callable/value shape by `DependencyValuesType`.
|
|
5
|
+
*/
|
|
6
|
+
export type DependencyMapType = Record<string, any>;
|
|
7
|
+
type ExtractTaskInput<T> = T extends {
|
|
8
|
+
run: (...args: any[]) => any;
|
|
9
|
+
} ? any : never;
|
|
10
|
+
type ExtractTaskOutput<T> = T extends {
|
|
11
|
+
run: (...args: any[]) => infer R;
|
|
12
|
+
} ? R : never;
|
|
13
|
+
type ExtractResourceValue<T> = T extends {
|
|
14
|
+
init?: (...args: any[]) => Promise<infer V>;
|
|
15
|
+
} ? V : T extends {
|
|
16
|
+
init?: (...args: any[]) => infer V;
|
|
17
|
+
} ? V : any;
|
|
18
|
+
type ExtractEventParams<T> = T extends {
|
|
19
|
+
id: any;
|
|
20
|
+
} ? any : never;
|
|
21
|
+
/**
|
|
22
|
+
* Task dependencies transform into callable functions: call with the task input
|
|
23
|
+
* and you receive the task output.
|
|
24
|
+
*/
|
|
25
|
+
export type TaskDependency<I, O> = (...args: I extends null | void ? [] : [I]) => O;
|
|
26
|
+
/**
|
|
27
|
+
* Resource dependencies resolve to the resource's value directly.
|
|
28
|
+
*/
|
|
29
|
+
export type ResourceDependency<V> = V;
|
|
30
|
+
/**
|
|
31
|
+
* Event dependencies resolve to an emitter function. If the payload type is
|
|
32
|
+
* `void`, the function can be called with zero args (or an empty object).
|
|
33
|
+
*/
|
|
34
|
+
export type EventDependency<P> = P extends void ? (() => Promise<void>) & ((input?: Record<string, never>) => Promise<void>) : (input: P) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Transforms a dependency definition into the usable shape inside `run`/`init`:
|
|
37
|
+
* - Task -> callable function
|
|
38
|
+
* - Resource -> resolved value
|
|
39
|
+
* - Event -> emit function
|
|
40
|
+
*/
|
|
41
|
+
export type DependencyValueType<T> = T extends {
|
|
42
|
+
run: (...args: any[]) => any;
|
|
43
|
+
} ? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends {
|
|
44
|
+
init?: (...args: any[]) => any;
|
|
45
|
+
} ? ResourceDependency<ExtractResourceValue<T>> : T extends {
|
|
46
|
+
id: any;
|
|
47
|
+
} ? EventDependency<ExtractEventParams<T>> : any;
|
|
19
48
|
export type DependencyValuesType<T extends DependencyMapType> = {
|
|
20
49
|
[K in keyof T]: DependencyValueType<T[K]>;
|
|
21
50
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { symbolEvent } from './symbols';
|
|
2
|
+
import type { IEventMeta } from './metadata';
|
|
3
|
+
export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
4
|
+
export interface IEventDefinition<TPayload = void> {
|
|
5
|
+
/** Stable identifier. Omit to get an anonymous id. */
|
|
6
|
+
id?: string | symbol;
|
|
7
|
+
meta?: IEventMeta;
|
|
8
|
+
}
|
|
9
|
+
export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
10
|
+
id: string | symbol;
|
|
11
|
+
/**
|
|
12
|
+
* We use this event to discriminate between resources with just 'id' and 'events' as they collide. This is a workaround, should be redone using classes and instanceof.
|
|
13
|
+
*/
|
|
14
|
+
[symbolEvent]: true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This represents the object that is passed to event handlers
|
|
18
|
+
*/
|
|
19
|
+
export interface IEventEmission<TPayload = any> {
|
|
20
|
+
/**
|
|
21
|
+
* The ID of the event. This is the same as the event's ID.
|
|
22
|
+
* This is useful for global event listeners.
|
|
23
|
+
*/
|
|
24
|
+
id: string | symbol;
|
|
25
|
+
/**
|
|
26
|
+
* The data that the event carries. It can be anything.
|
|
27
|
+
*/
|
|
28
|
+
data: TPayload;
|
|
29
|
+
/**
|
|
30
|
+
* The timestamp when the event was created.
|
|
31
|
+
*/
|
|
32
|
+
timestamp: Date;
|
|
33
|
+
/**
|
|
34
|
+
* The source of the event. This can be useful for debugging.
|
|
35
|
+
*/
|
|
36
|
+
source: string | symbol;
|
|
37
|
+
/**
|
|
38
|
+
* Metadata associated with the event definition.
|
|
39
|
+
*/
|
|
40
|
+
meta: IEventMeta;
|
|
41
|
+
/**
|
|
42
|
+
* Stops propagation to remaining event listeners.
|
|
43
|
+
*/
|
|
44
|
+
stopPropagation(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if propagation has been stopped.
|
|
47
|
+
*/
|
|
48
|
+
isPropagationStopped(): boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;AAAA,uCAAwC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
export * from './symbols';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './utilities';
|
|
2
|
+
export * from './metadata';
|
|
4
3
|
export * from './dependencies';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './tasks';
|
|
7
|
-
export * from './resources';
|
|
4
|
+
export * from './event';
|
|
8
5
|
export * from './middleware';
|
|
9
|
-
export * from './
|
|
10
|
-
|
|
11
|
-
export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<void, any, any, any> | IResource<{
|
|
12
|
-
[K in any]?: any;
|
|
13
|
-
}, any, any, any> | ITaskDefinition<any, any, any, any> | IMiddlewareDefinition<any> | IEventDefinition<any>;
|
|
6
|
+
export * from './task';
|
|
7
|
+
export * from './resource';
|
|
14
8
|
export { ICacheInstance } from "../globals/middleware/cache.middleware";
|
package/dist/types/index.js
CHANGED
|
@@ -14,14 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//
|
|
17
|
+
// Symbols
|
|
18
18
|
__exportStar(require("./symbols"), exports);
|
|
19
|
-
|
|
20
|
-
__exportStar(require("./
|
|
19
|
+
// Metadata and tagging system
|
|
20
|
+
__exportStar(require("./metadata"), exports);
|
|
21
|
+
// Dependencies
|
|
21
22
|
__exportStar(require("./dependencies"), exports);
|
|
22
|
-
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./resources"), exports);
|
|
23
|
+
// Core types
|
|
24
|
+
__exportStar(require("./event"), exports);
|
|
25
25
|
__exportStar(require("./middleware"), exports);
|
|
26
|
-
__exportStar(require("./
|
|
26
|
+
__exportStar(require("./task"), exports);
|
|
27
|
+
__exportStar(require("./resource"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,UAAU;AACV,4CAA0B;AAE1B,8BAA8B;AAC9B,6CAA2B;AAE3B,eAAe;AACf,iDAA+B;AAE/B,aAAa;AACb,0CAAwB;AACxB,+CAA6B;AAC7B,yCAAuB;AACvB,6CAA2B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface ITagDefinition<TConfig = void> {
|
|
2
|
+
id: string | symbol;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* A configured instance of a tag as produced by `ITag.with()`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ITagWithConfig<TConfig = void> {
|
|
8
|
+
id: string | symbol;
|
|
9
|
+
/** The tag definition used to produce this configured instance. */
|
|
10
|
+
tag: ITag<TConfig>;
|
|
11
|
+
/** The configuration captured for this tag instance. */
|
|
12
|
+
config: TConfig;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A tag definition (builder). Use `.with(config)` to obtain configured instances,
|
|
16
|
+
* and `.extract(tags)` to find either a configured instance or the bare tag in a list.
|
|
17
|
+
*/
|
|
18
|
+
export interface ITag<TConfig = void> extends ITagDefinition<TConfig> {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a configured instance of the tag.
|
|
21
|
+
*/
|
|
22
|
+
with(config: TConfig): ITagWithConfig<TConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts either a configured instance or the bare tag from a list of tags
|
|
25
|
+
* or from a taggable object (`{ meta: { tags?: [] } }`).
|
|
26
|
+
*/
|
|
27
|
+
extract(target: TagType[] | ITaggable): ExtractedTagResult<TConfig> | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Restrict bare tags to those whose config can be omitted (void or optional object),
|
|
31
|
+
* mirroring the same principle used for resources in `RegisterableItems`.
|
|
32
|
+
* Required-config tags must appear as configured instances.
|
|
33
|
+
*/
|
|
34
|
+
export type TagType = string | ITag<void> | ITag<{
|
|
35
|
+
[K in any]?: any;
|
|
36
|
+
}> | ITagWithConfig<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Conditional result type for `ITag.extract`:
|
|
39
|
+
* - For void config → just the identifier
|
|
40
|
+
* - For optional object config → identifier with optional config
|
|
41
|
+
* - For required config → identifier with required config
|
|
42
|
+
*/
|
|
43
|
+
export type ExtractedTagResult<TConfig> = {} extends TConfig ? {
|
|
44
|
+
id: string | symbol;
|
|
45
|
+
config?: TConfig;
|
|
46
|
+
} : {
|
|
47
|
+
id: string | symbol;
|
|
48
|
+
config: TConfig;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Any object that can carry tags via metadata. This mirrors how tasks,
|
|
52
|
+
* resources, events, and middleware expose `meta.tags`.
|
|
53
|
+
*/
|
|
54
|
+
export interface ITaggable {
|
|
55
|
+
meta?: {
|
|
56
|
+
tags?: TagType[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
61
|
+
* Useful for docs, filtering and middleware decisions.
|
|
62
|
+
*/
|
|
63
|
+
export interface IMeta {
|
|
64
|
+
title?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
tags?: TagType[];
|
|
67
|
+
}
|
|
68
|
+
export interface ITaskMeta extends IMeta {
|
|
69
|
+
}
|
|
70
|
+
export interface IResourceMeta extends IMeta {
|
|
71
|
+
}
|
|
72
|
+
export interface IEventMeta extends IMeta {
|
|
73
|
+
}
|
|
74
|
+
export interface IMiddlewareMeta extends IMeta {
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/types/metadata.ts"],"names":[],"mappings":""}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { symbolMiddleware, symbolMiddlewareConfigured, symbolMiddlewareEverywhereTasks, symbolMiddlewareEverywhereResources } from './symbols';
|
|
2
|
-
import type { IMiddlewareMeta } from './
|
|
3
|
-
import type { DependencyMapType, DependencyValuesType } from './
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
next: (taskInputOrResourceConfig?: TTaskInput | TResourceConfig) => Promise<any>;
|
|
15
|
-
}
|
|
1
|
+
import type { symbolMiddleware, symbolMiddlewareConfigured, symbolMiddlewareEverywhereTasks, symbolMiddlewareEverywhereResources } from './symbols';
|
|
2
|
+
import type { IMiddlewareMeta } from './metadata';
|
|
3
|
+
import type { DependencyMapType, DependencyValuesType } from './dependencies';
|
|
4
|
+
export type MiddlewareEverywhereOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Enable this for tasks. Default is true.
|
|
7
|
+
*/
|
|
8
|
+
tasks?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Enable this for resources. Default is true.
|
|
11
|
+
*/
|
|
12
|
+
resources?: boolean;
|
|
13
|
+
};
|
|
16
14
|
export interface IMiddlewareDefinition<TConfig = any, TDependencies extends DependencyMapType = any> {
|
|
17
|
-
id
|
|
18
|
-
|
|
15
|
+
/** Stable identifier. Omit to get an anonymous id. */
|
|
16
|
+
id?: string | symbol;
|
|
17
|
+
/** Static or lazy dependency map. */
|
|
18
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
19
|
+
/**
|
|
20
|
+
* The middleware body, called with task/resource execution input.
|
|
21
|
+
*/
|
|
19
22
|
run: (input: IMiddlewareExecutionInput, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
20
23
|
meta?: IMiddlewareMeta;
|
|
21
24
|
}
|
|
@@ -24,9 +27,15 @@ export interface IMiddleware<TConfig = any, TDependencies extends DependencyMapT
|
|
|
24
27
|
[symbolMiddlewareConfigured]?: boolean;
|
|
25
28
|
[symbolMiddlewareEverywhereTasks]?: boolean;
|
|
26
29
|
[symbolMiddlewareEverywhereResources]?: boolean;
|
|
30
|
+
id: string | symbol;
|
|
27
31
|
dependencies: TDependencies | (() => TDependencies);
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Attach this middleware globally. Use options to scope to tasks/resources.
|
|
34
|
+
*/
|
|
35
|
+
everywhere(config?: MiddlewareEverywhereOptions): IMiddleware<TConfig, TDependencies>;
|
|
36
|
+
/** Current configuration object (empty by default). */
|
|
29
37
|
config: TConfig;
|
|
38
|
+
/** Configure the middleware and return a marked, configured instance. */
|
|
30
39
|
with: (config: TConfig) => IMiddlewareConfigured<TConfig, TDependencies>;
|
|
31
40
|
}
|
|
32
41
|
export interface IMiddlewareConfigured<TConfig = any, TDependencies extends DependencyMapType = any> extends IMiddleware<TConfig, TDependencies> {
|
|
@@ -36,3 +45,19 @@ export interface IMiddlewareDefinitionConfigured<C extends Record<string, any> =
|
|
|
36
45
|
middleware: IMiddleware<C>;
|
|
37
46
|
config?: C;
|
|
38
47
|
}
|
|
48
|
+
export interface IMiddlewareExecutionInput<TTaskInput = any, TResourceConfig = any> {
|
|
49
|
+
/** Task hook: present when wrapping a task run. */
|
|
50
|
+
task?: {
|
|
51
|
+
definition: any;
|
|
52
|
+
input: TTaskInput;
|
|
53
|
+
};
|
|
54
|
+
/** Resource hook: present when wrapping init/dispose. */
|
|
55
|
+
resource?: {
|
|
56
|
+
definition: any;
|
|
57
|
+
config: TResourceConfig;
|
|
58
|
+
};
|
|
59
|
+
next: (taskInputOrResourceConfig?: TTaskInput | TResourceConfig) => Promise<any>;
|
|
60
|
+
}
|
|
61
|
+
export type MiddlewareAttachments = IMiddleware<void> | IMiddleware<{
|
|
62
|
+
[K in any]?: any;
|
|
63
|
+
}> | IMiddlewareConfigured<any>;
|
package/dist/types/middleware.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/types/middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/types/middleware.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { symbolFilePath, symbolIndexResource } from './symbols';
|
|
2
|
+
import type { IResourceMeta } from './metadata';
|
|
3
|
+
import type { DependencyMapType, DependencyValuesType } from './dependencies';
|
|
4
|
+
import type { IEvent } from './event';
|
|
5
|
+
import type { MiddlewareAttachments } from './middleware';
|
|
6
|
+
export type BeforeInitEventPayload<TConfig> = {
|
|
7
|
+
config: TConfig;
|
|
8
|
+
};
|
|
9
|
+
export type AfterInitEventPayload<TConfig, TValue> = {
|
|
10
|
+
config: TConfig;
|
|
11
|
+
value: TValue;
|
|
12
|
+
};
|
|
13
|
+
export type OnErrorEventPayloadResource = {
|
|
14
|
+
error: any;
|
|
15
|
+
/**
|
|
16
|
+
* This function can be called to suppress the error from being thrown.
|
|
17
|
+
*/
|
|
18
|
+
suppress(): void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Anything you can put inside a resource's `register: []`.
|
|
22
|
+
* - Resources (with or without `.with()`)
|
|
23
|
+
* - Tasks
|
|
24
|
+
* - Middleware
|
|
25
|
+
* - Events
|
|
26
|
+
*/
|
|
27
|
+
export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<void, any, any, any> | IResource<{
|
|
28
|
+
[K in any]?: any;
|
|
29
|
+
}, any, any, any> | any | any | any;
|
|
30
|
+
export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any> {
|
|
31
|
+
/** Stable identifier. Omit to get an anonymous id. */
|
|
32
|
+
id?: string | symbol;
|
|
33
|
+
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
34
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
35
|
+
/**
|
|
36
|
+
* Register other registerables (resources/tasks/middleware/events). Accepts a
|
|
37
|
+
* static array or a function of `config` to support dynamic wiring.
|
|
38
|
+
*/
|
|
39
|
+
register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
40
|
+
/**
|
|
41
|
+
* Initialize and return the resource value. Called once during boot.
|
|
42
|
+
*/
|
|
43
|
+
init?: (this: any, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<TValue>;
|
|
44
|
+
/**
|
|
45
|
+
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
46
|
+
*
|
|
47
|
+
* @param value The value of the resource (undefined if no init method)
|
|
48
|
+
* @param config The configuration it received
|
|
49
|
+
* @param dependencies The dependencies it needed
|
|
50
|
+
* @returns Promise<void>
|
|
51
|
+
*/
|
|
52
|
+
dispose?: (this: any, value: TValue, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
|
|
53
|
+
meta?: IResourceMeta;
|
|
54
|
+
/**
|
|
55
|
+
* Safe overrides to swap behavior while preserving identities. See
|
|
56
|
+
* README: Overrides.
|
|
57
|
+
*/
|
|
58
|
+
overrides?: Array<IResource | any | any | IResourceWithConfig>;
|
|
59
|
+
/** Middleware applied around init/dispose. */
|
|
60
|
+
middleware?: MiddlewareAttachments[];
|
|
61
|
+
/**
|
|
62
|
+
* Create a private, mutable context shared between `init` and `dispose`.
|
|
63
|
+
*/
|
|
64
|
+
context?: () => TContext;
|
|
65
|
+
/**
|
|
66
|
+
* This is optional and used from an index resource to get the correct caller.
|
|
67
|
+
*/
|
|
68
|
+
[symbolFilePath]?: string;
|
|
69
|
+
/**
|
|
70
|
+
* This is used internally when creating index resources.
|
|
71
|
+
*/
|
|
72
|
+
[symbolIndexResource]?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface IResource<TConfig = void, TValue = any, TDependencies extends DependencyMapType = any, TContext = any> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext> {
|
|
75
|
+
id: string | symbol;
|
|
76
|
+
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
|
|
77
|
+
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
78
|
+
/**
|
|
79
|
+
* These events are automatically populated after the task has been defined.
|
|
80
|
+
*/
|
|
81
|
+
events: {
|
|
82
|
+
beforeInit: IEvent<BeforeInitEventPayload<TConfig>>;
|
|
83
|
+
afterInit: IEvent<AfterInitEventPayload<TConfig, TValue>>;
|
|
84
|
+
onError: IEvent<OnErrorEventPayloadResource>;
|
|
85
|
+
};
|
|
86
|
+
overrides: Array<IResource | any | any | IResourceWithConfig>;
|
|
87
|
+
middleware: MiddlewareAttachments[];
|
|
88
|
+
}
|
|
89
|
+
export interface IResourceWithConfig<TConfig = any, TValue = any, TDependencies extends DependencyMapType = any> {
|
|
90
|
+
/** The id of the underlying resource. */
|
|
91
|
+
id: string;
|
|
92
|
+
/** The underlying resource definition. */
|
|
93
|
+
resource: IResource<TConfig, TValue, TDependencies>;
|
|
94
|
+
/** The configuration captured by `.with(config)`. */
|
|
95
|
+
config: TConfig;
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/types/resource.ts"],"names":[],"mappings":""}
|
package/dist/types/symbols.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal brand symbols used to tag created objects at runtime and help with
|
|
3
|
+
* type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
|
|
4
|
+
* helpers instead of touching these directly.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
1
7
|
export declare const symbolTask: unique symbol;
|
|
2
8
|
export declare const symbolResource: unique symbol;
|
|
3
9
|
export declare const symbolResourceWithConfig: unique symbol;
|
|
@@ -7,13 +13,24 @@ export declare const symbolMiddlewareConfigured: unique symbol;
|
|
|
7
13
|
export declare const symbolMiddlewareGlobal: unique symbol;
|
|
8
14
|
export declare const symbolMiddlewareEverywhereTasks: unique symbol;
|
|
9
15
|
export declare const symbolMiddlewareEverywhereResources: unique symbol;
|
|
16
|
+
/** @internal Path to aid anonymous id generation and error messages */
|
|
10
17
|
export declare const symbolFilePath: unique symbol;
|
|
18
|
+
/** @internal Marks disposable instances */
|
|
11
19
|
export declare const symbolDispose: unique symbol;
|
|
20
|
+
/** @internal Link to internal Store */
|
|
12
21
|
export declare const symbolStore: unique symbol;
|
|
22
|
+
/** @internal Brand used by index() resources */
|
|
23
|
+
export declare const symbolIndexResource: unique symbol;
|
|
24
|
+
/**
|
|
25
|
+
* Convenience bag of internal symbols. Intended for framework internals;
|
|
26
|
+
* consumers should not rely on this shape.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
13
29
|
export declare const symbols: {
|
|
14
30
|
task: symbol;
|
|
15
31
|
resource: symbol;
|
|
16
32
|
resourceWithConfig: symbol;
|
|
33
|
+
indexResource: symbol;
|
|
17
34
|
event: symbol;
|
|
18
35
|
middleware: symbol;
|
|
19
36
|
middlewareEverywhereTasks: symbol;
|
package/dist/types/symbols.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Layer 1: Foundation - Symbols and Constants
|
|
3
|
-
// No dependencies
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.symbols = exports.symbolStore = exports.symbolDispose = exports.symbolFilePath = exports.symbolMiddlewareEverywhereResources = exports.symbolMiddlewareEverywhereTasks = exports.symbolMiddlewareGlobal = exports.symbolMiddlewareConfigured = exports.symbolMiddleware = exports.symbolEvent = exports.symbolResourceWithConfig = exports.symbolResource = exports.symbolTask = void 0;
|
|
3
|
+
exports.symbols = exports.symbolIndexResource = exports.symbolStore = exports.symbolDispose = exports.symbolFilePath = exports.symbolMiddlewareEverywhereResources = exports.symbolMiddlewareEverywhereTasks = exports.symbolMiddlewareGlobal = exports.symbolMiddlewareConfigured = exports.symbolMiddleware = exports.symbolEvent = exports.symbolResourceWithConfig = exports.symbolResource = exports.symbolTask = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Internal brand symbols used to tag created objects at runtime and help with
|
|
6
|
+
* type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
|
|
7
|
+
* helpers instead of touching these directly.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
6
10
|
exports.symbolTask = Symbol("runner.task");
|
|
7
11
|
exports.symbolResource = Symbol("runner.resource");
|
|
8
12
|
exports.symbolResourceWithConfig = Symbol("runner.resourceWithConfig");
|
|
@@ -12,13 +16,24 @@ exports.symbolMiddlewareConfigured = Symbol("runner.middlewareConfigured");
|
|
|
12
16
|
exports.symbolMiddlewareGlobal = Symbol("runner.middlewareGlobal");
|
|
13
17
|
exports.symbolMiddlewareEverywhereTasks = Symbol("runner.middlewareGlobalTasks");
|
|
14
18
|
exports.symbolMiddlewareEverywhereResources = Symbol("runner.middlewareGlobalResources");
|
|
19
|
+
/** @internal Path to aid anonymous id generation and error messages */
|
|
15
20
|
exports.symbolFilePath = Symbol("runner.filePath");
|
|
21
|
+
/** @internal Marks disposable instances */
|
|
16
22
|
exports.symbolDispose = Symbol("runner.dispose");
|
|
23
|
+
/** @internal Link to internal Store */
|
|
17
24
|
exports.symbolStore = Symbol("runner.store");
|
|
25
|
+
/** @internal Brand used by index() resources */
|
|
26
|
+
exports.symbolIndexResource = Symbol("runner.indexResource");
|
|
27
|
+
/**
|
|
28
|
+
* Convenience bag of internal symbols. Intended for framework internals;
|
|
29
|
+
* consumers should not rely on this shape.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
18
32
|
exports.symbols = {
|
|
19
33
|
task: exports.symbolTask,
|
|
20
34
|
resource: exports.symbolResource,
|
|
21
35
|
resourceWithConfig: exports.symbolResourceWithConfig,
|
|
36
|
+
indexResource: exports.symbolIndexResource,
|
|
22
37
|
event: exports.symbolEvent,
|
|
23
38
|
middleware: exports.symbolMiddleware,
|
|
24
39
|
middlewareEverywhereTasks: exports.symbolMiddlewareEverywhereTasks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/types/symbols.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/types/symbols.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,UAAU,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAClD,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1D,QAAA,wBAAwB,GAAkB,MAAM,CAC3D,2BAA2B,CAC5B,CAAC;AACW,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AACpD,QAAA,gBAAgB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC9D,QAAA,0BAA0B,GAAkB,MAAM,CAC7D,6BAA6B,CAC9B,CAAC;AACW,QAAA,sBAAsB,GAAkB,MAAM,CACzD,yBAAyB,CAC1B,CAAC;AACW,QAAA,+BAA+B,GAAkB,MAAM,CAClE,8BAA8B,CAC/B,CAAC;AACW,QAAA,mCAAmC,GAAkB,MAAM,CACtE,kCAAkC,CACnC,CAAC;AAEF,uEAAuE;AAC1D,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACvE,2CAA2C;AAC9B,QAAA,aAAa,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACrE,uCAAuC;AAC1B,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAEjE,gDAAgD;AACnC,QAAA,mBAAmB,GAAkB,MAAM,CACtD,sBAAsB,CACvB,CAAC;AAEF;;;;GAIG;AACU,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,kBAAU;IAChB,QAAQ,EAAE,sBAAc;IACxB,kBAAkB,EAAE,gCAAwB;IAC5C,aAAa,EAAE,2BAAmB;IAClC,KAAK,EAAE,mBAAW;IAClB,UAAU,EAAE,wBAAgB;IAC5B,yBAAyB,EAAE,uCAA+B;IAC1D,6BAA6B,EAAE,2CAAmC;IAClE,QAAQ,EAAE,sBAAc;IACxB,OAAO,EAAE,qBAAa;IACtB,KAAK,EAAE,mBAAW;CACnB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ITaskMeta } from './metadata';
|
|
2
|
+
import type { DependencyMapType, DependencyValuesType } from './dependencies';
|
|
3
|
+
import type { IEventDefinition, IEvent, IEventEmission } from './event';
|
|
4
|
+
import type { MiddlewareAttachments } from './middleware';
|
|
5
|
+
export type BeforeRunEventPayload<TInput> = {
|
|
6
|
+
input: TInput;
|
|
7
|
+
};
|
|
8
|
+
export type AfterRunEventPayload<TInput, TOutput> = {
|
|
9
|
+
input: TInput;
|
|
10
|
+
output: TOutput extends Promise<infer U> ? U : TOutput;
|
|
11
|
+
setOutput(newOutput: TOutput extends Promise<infer U> ? U : TOutput): void;
|
|
12
|
+
};
|
|
13
|
+
export type OnErrorEventPayload = {
|
|
14
|
+
error: any;
|
|
15
|
+
/**
|
|
16
|
+
* This function can be called to suppress the error from being thrown.
|
|
17
|
+
*/
|
|
18
|
+
suppress(): void;
|
|
19
|
+
};
|
|
20
|
+
type ExtractEventParams<T> = T extends IEventDefinition<infer P> ? P : never;
|
|
21
|
+
export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> {
|
|
22
|
+
/**
|
|
23
|
+
* Stable identifier. If omitted, an anonymous id is generated from file path
|
|
24
|
+
* (see README: Anonymous IDs).
|
|
25
|
+
*/
|
|
26
|
+
id?: string | symbol;
|
|
27
|
+
/**
|
|
28
|
+
* Access other tasks/resources/events. Can be an object or a function when
|
|
29
|
+
* you need late or config‑dependent resolution.
|
|
30
|
+
*/
|
|
31
|
+
dependencies?: TDependencies | (() => TDependencies);
|
|
32
|
+
/** Middleware applied around task execution. */
|
|
33
|
+
middleware?: MiddlewareAttachments[];
|
|
34
|
+
/**
|
|
35
|
+
* Listen to events in a simple way
|
|
36
|
+
*/
|
|
37
|
+
on?: TOn;
|
|
38
|
+
/**
|
|
39
|
+
* This makes sense only when `on` is specified to provide the order of the execution.
|
|
40
|
+
* The event with the lowest order will be executed first.
|
|
41
|
+
*/
|
|
42
|
+
listenerOrder?: number;
|
|
43
|
+
/** Optional metadata used for docs, filtering and tooling. */
|
|
44
|
+
meta?: ITaskMeta;
|
|
45
|
+
/**
|
|
46
|
+
* The task body. If `on` is set, the input is an `IEventEmission`. Otherwise,
|
|
47
|
+
* it's the declared input type.
|
|
48
|
+
*/
|
|
49
|
+
run: (input: TOn extends undefined ? TInput : IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => TOutput;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This is the response after the definition has been prepared. TODO: better naming?
|
|
53
|
+
*/
|
|
54
|
+
export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> extends ITaskDefinition<TInput, TOutput, TDependencies, TOn> {
|
|
55
|
+
id: string | symbol;
|
|
56
|
+
dependencies: TDependencies | (() => TDependencies);
|
|
57
|
+
computedDependencies?: DependencyValuesType<TDependencies>;
|
|
58
|
+
middleware: MiddlewareAttachments[];
|
|
59
|
+
/**
|
|
60
|
+
* These events are automatically populated after the task has been defined.
|
|
61
|
+
*/
|
|
62
|
+
events: {
|
|
63
|
+
beforeRun: IEvent<BeforeRunEventPayload<TInput>>;
|
|
64
|
+
afterRun: IEvent<AfterRunEventPayload<TInput, TOutput>>;
|
|
65
|
+
onError: IEvent<OnErrorEventPayload>;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.js","sourceRoot":"","sources":["../../src/types/task.ts"],"names":[],"mappings":""}
|