@bluelibs/runner 3.0.0 → 3.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.
- package/README.md +103 -2
- package/dist/define.d.ts +3 -3
- package/dist/define.js +39 -14
- package/dist/define.js.map +1 -1
- package/dist/defs.d.ts +59 -44
- package/dist/defs.js +3 -1
- package/dist/defs.js.map +1 -1
- package/dist/errors.d.ts +5 -5
- package/dist/errors.js +6 -5
- package/dist/errors.js.map +1 -1
- package/dist/globals/globalEvents.d.ts +11 -11
- package/dist/globals/globalMiddleware.d.ts +1 -1
- package/dist/globals/globalResources.d.ts +3 -3
- package/dist/globals/middleware/cache.middleware.d.ts +2 -2
- package/dist/globals/middleware/cache.middleware.js.map +1 -1
- package/dist/globals/resources/queue.resource.d.ts +2 -2
- package/dist/globals/resources/queue.resource.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/models/DependencyProcessor.d.ts +4 -4
- package/dist/models/DependencyProcessor.js +2 -2
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/models/EventManager.d.ts +5 -5
- package/dist/models/EventManager.js.map +1 -1
- package/dist/models/Logger.d.ts +1 -1
- package/dist/models/Logger.js +29 -27
- package/dist/models/Logger.js.map +1 -1
- package/dist/models/OverrideManager.d.ts +2 -2
- package/dist/models/OverrideManager.js.map +1 -1
- package/dist/models/ResourceInitializer.js +3 -1
- package/dist/models/ResourceInitializer.js.map +1 -1
- package/dist/models/Store.d.ts +8 -8
- package/dist/models/Store.js.map +1 -1
- package/dist/models/StoreConstants.d.ts +2 -2
- package/dist/models/StoreRegistry.d.ts +8 -8
- package/dist/models/StoreRegistry.js.map +1 -1
- package/dist/models/StoreValidator.d.ts +2 -2
- package/dist/models/StoreValidator.js +1 -1
- package/dist/models/StoreValidator.js.map +1 -1
- package/dist/models/TaskRunner.d.ts +1 -1
- package/dist/tools/getCallerFile.d.ts +9 -1
- package/dist/tools/getCallerFile.js +41 -0
- package/dist/tools/getCallerFile.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/models/EventManager.test.ts +48 -46
- package/src/__tests__/run.anonymous.test.ts +679 -0
- package/src/__tests__/run.middleware.test.ts +146 -0
- package/src/__tests__/run.test.ts +1 -1
- package/src/__tests__/tools/getCallerFile.test.ts +117 -2
- package/src/__tests__/typesafety.test.ts +17 -2
- package/src/define.ts +47 -22
- package/src/defs.ts +76 -89
- package/src/errors.ts +13 -10
- package/src/globals/middleware/cache.middleware.ts +1 -1
- package/src/globals/resources/queue.resource.ts +1 -1
- package/src/models/DependencyProcessor.ts +7 -10
- package/src/models/EventManager.ts +25 -14
- package/src/models/Logger.ts +51 -39
- package/src/models/OverrideManager.ts +3 -3
- package/src/models/ResourceInitializer.ts +3 -1
- package/src/models/Store.ts +2 -2
- package/src/models/StoreRegistry.ts +27 -16
- package/src/models/StoreValidator.ts +13 -8
- package/src/models/TaskRunner.ts +1 -1
- package/src/tools/getCallerFile.ts +54 -2
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ const createUser = task({
|
|
|
63
63
|
const app = resource({
|
|
64
64
|
id: "app",
|
|
65
65
|
// Here you make the system aware of resources, tasks, middleware, and events.
|
|
66
|
-
register: [server, createUser],
|
|
66
|
+
register: [server.with({ port: 3000 }), createUser],
|
|
67
67
|
dependencies: { server, createUser },
|
|
68
68
|
init: async (_, { server, createUser }) => {
|
|
69
69
|
server.app.post("/users", async (req, res) => {
|
|
@@ -74,7 +74,7 @@ const app = resource({
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// That's it. No webpack configs, no decorators, no XML.
|
|
77
|
-
const { dispose } = await run(app
|
|
77
|
+
const { dispose } = await run(app);
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
## The Big Four: Your New Building Blocks
|
|
@@ -1670,6 +1670,107 @@ async function processBatch(items: any[]) {
|
|
|
1670
1670
|
- **Ignoring disposal**: Always dispose semaphores to prevent memory leaks
|
|
1671
1671
|
- **Wrong permit count**: Too few = slow, too many = defeats the purpose
|
|
1672
1672
|
|
|
1673
|
+
## Anonymous IDs: Because Naming Things Is Hard
|
|
1674
|
+
|
|
1675
|
+
One of our favorite quality-of-life features: **anonymous IDs**. Instead of manually naming every component, the framework can generate unique symbol-based identifiers based on your file path and variable name. It's like having a really good naming assistant who never gets tired.
|
|
1676
|
+
|
|
1677
|
+
### How Anonymous IDs Work
|
|
1678
|
+
|
|
1679
|
+
When you omit the `id` property, the framework generates a unique symbol based on file path. Takes up until first 'src' or 'node_modules' and generates based on the paths.
|
|
1680
|
+
|
|
1681
|
+
```typescript
|
|
1682
|
+
// In src/services/email.ts
|
|
1683
|
+
const emailService = resource({
|
|
1684
|
+
// Generated ID: Symbol('services.email.resource')
|
|
1685
|
+
init: async () => new EmailService(),
|
|
1686
|
+
});
|
|
1687
|
+
|
|
1688
|
+
// In src/tasks/user.ts
|
|
1689
|
+
const createUser = task({
|
|
1690
|
+
// Generated ID: Symbol('tasks.user.task')
|
|
1691
|
+
dependencies: { emailService },
|
|
1692
|
+
run: async (userData, { emailService }) => {
|
|
1693
|
+
// Business logic
|
|
1694
|
+
},
|
|
1695
|
+
});
|
|
1696
|
+
```
|
|
1697
|
+
|
|
1698
|
+
### Benefits of Anonymous IDs
|
|
1699
|
+
|
|
1700
|
+
1. **Less Bikeshedding**: No more debates about naming conventions
|
|
1701
|
+
2. **Automatic Uniqueness**: Guaranteed collision-free identifiers
|
|
1702
|
+
3. **Faster Prototyping**: Just write code, framework handles the rest
|
|
1703
|
+
4. **Refactor-Friendly**: Rename files/variables and IDs update automatically
|
|
1704
|
+
5. **Stack Trace Integration**: Error messages include helpful file locations
|
|
1705
|
+
|
|
1706
|
+
### When to Use Manual vs Anonymous IDs
|
|
1707
|
+
|
|
1708
|
+
| Use Case | Recommendation | Reason |
|
|
1709
|
+
| ----------------------- | -------------- | --------------------------------------- |
|
|
1710
|
+
| Internal tasks | Anonymous | No external references needed |
|
|
1711
|
+
| Event definitions | Manual | Need predictable names for listeners |
|
|
1712
|
+
| Public APIs | Manual | External modules need stable references |
|
|
1713
|
+
| Middleware | Manual | Often reused across projects |
|
|
1714
|
+
| Configuration resources | Anonymous | Usually internal infrastructure |
|
|
1715
|
+
| Test doubles/mocks | Anonymous | One-off usage in tests |
|
|
1716
|
+
| Cross-module services | Manual | Multiple files depend on them |
|
|
1717
|
+
|
|
1718
|
+
### Anonymous ID Examples by Pattern
|
|
1719
|
+
|
|
1720
|
+
```typescript
|
|
1721
|
+
// ✅ Great for anonymous IDs
|
|
1722
|
+
const database = resource({
|
|
1723
|
+
init: async () => new Database(),
|
|
1724
|
+
dispose: async (db) => db.close(),
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
const processPayment = task({
|
|
1728
|
+
dependencies: { database },
|
|
1729
|
+
run: async (payment, { database }) => {
|
|
1730
|
+
// Internal business logic
|
|
1731
|
+
},
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
// ✅ Better with manual IDs
|
|
1735
|
+
const paymentProcessed = event<{ paymentId: string }>({
|
|
1736
|
+
id: "app.events.paymentProcessed", // Other modules listen to this
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1739
|
+
const authMiddleware = middleware({
|
|
1740
|
+
id: "app.middleware.auth", // Reused across multiple tasks
|
|
1741
|
+
run: async ({ task, next }) => {
|
|
1742
|
+
// Auth logic
|
|
1743
|
+
},
|
|
1744
|
+
});
|
|
1745
|
+
|
|
1746
|
+
// ✅ Mixed approach - totally fine!
|
|
1747
|
+
const app = resource({
|
|
1748
|
+
id: "app", // Main entry point gets manual ID
|
|
1749
|
+
register: [
|
|
1750
|
+
database, // Anonymous
|
|
1751
|
+
processPayment, // Anonymous
|
|
1752
|
+
paymentProcessed, // Manual
|
|
1753
|
+
authMiddleware, // Manual
|
|
1754
|
+
],
|
|
1755
|
+
});
|
|
1756
|
+
```
|
|
1757
|
+
|
|
1758
|
+
### Debugging with Anonymous IDs
|
|
1759
|
+
|
|
1760
|
+
Anonymous IDs show up clearly in error messages and logs:
|
|
1761
|
+
|
|
1762
|
+
```typescript
|
|
1763
|
+
// Error message example:
|
|
1764
|
+
// TaskRunError: Task failed at Symbol('tasks.payment.task')
|
|
1765
|
+
// at file:///project/src/tasks/payment.ts:15:23
|
|
1766
|
+
|
|
1767
|
+
// Logging with context:
|
|
1768
|
+
logger.info("Processing payment", {
|
|
1769
|
+
taskId: processPayment.definition.id, // Symbol('tasks.payment.task')
|
|
1770
|
+
file: "src/tasks/payment.ts",
|
|
1771
|
+
});
|
|
1772
|
+
```
|
|
1773
|
+
|
|
1673
1774
|
## Why Choose BlueLibs Runner?
|
|
1674
1775
|
|
|
1675
1776
|
### What You Get
|
package/dist/define.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITask, ITaskDefinition, IResource, IResourceWithConfig, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyMapType, DependencyValuesType, IMiddleware,
|
|
1
|
+
import { ITask, ITaskDefinition, IResource, IResourceWithConfig, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyMapType, DependencyValuesType, IMiddleware, IEvent, RegisterableItems } from "./defs";
|
|
2
2
|
export declare function defineTask<Input = undefined, Output extends Promise<any> = any, Deps extends DependencyMapType = any, TOn extends "*" | IEventDefinition | undefined = undefined>(taskConfig: ITaskDefinition<Input, Output, Deps, TOn>): ITask<Input, Output, Deps, TOn>;
|
|
3
3
|
export declare function defineResource<TConfig = void, TValue = any, TDeps extends DependencyMapType = {}, TPrivate = any>(constConfig: IResourceDefinition<TConfig, TValue, TDeps, TPrivate>): IResource<TConfig, TValue, TDeps, TPrivate>;
|
|
4
4
|
/**
|
|
@@ -10,7 +10,7 @@ export declare function defineResource<TConfig = void, TValue = any, TDeps exten
|
|
|
10
10
|
export declare function defineIndex<T extends Record<string, RegisterableItems>, D extends {
|
|
11
11
|
[K in keyof T]: T[K] extends IResourceWithConfig<any, any, any> ? T[K]["resource"] : T[K];
|
|
12
12
|
} & DependencyMapType>(items: T): IResource<void, DependencyValuesType<D>, D>;
|
|
13
|
-
export declare function defineEvent<TPayload =
|
|
13
|
+
export declare function defineEvent<TPayload = void>(config: IEventDefinition<TPayload>): IEvent<TPayload>;
|
|
14
14
|
export type MiddlewareEverywhereOptions = {
|
|
15
15
|
/**
|
|
16
16
|
* Enable this for tasks. Default is true.
|
|
@@ -25,5 +25,5 @@ export declare function defineMiddleware<TConfig extends Record<string, any>, TD
|
|
|
25
25
|
export declare function isTask(definition: any): definition is ITask;
|
|
26
26
|
export declare function isResource(definition: any): definition is IResource;
|
|
27
27
|
export declare function isResourceWithConfig(definition: any): definition is IResourceWithConfig;
|
|
28
|
-
export declare function isEvent(definition: any): definition is
|
|
28
|
+
export declare function isEvent(definition: any): definition is IEvent;
|
|
29
29
|
export declare function isMiddleware(definition: any): definition is IMiddleware;
|
package/dist/define.js
CHANGED
|
@@ -16,10 +16,12 @@ const getCallerFile_1 = require("./tools/getCallerFile");
|
|
|
16
16
|
// Helper function to get the caller file
|
|
17
17
|
function defineTask(taskConfig) {
|
|
18
18
|
const filePath = (0, getCallerFile_1.getCallerFile)();
|
|
19
|
+
const isAnonymous = !Boolean(taskConfig.id);
|
|
20
|
+
const id = taskConfig.id || (0, getCallerFile_1.generateCallerIdFromFile)(filePath, "task");
|
|
19
21
|
return {
|
|
20
22
|
[defs_1.symbols.task]: true,
|
|
21
23
|
[defs_1.symbols.filePath]: filePath,
|
|
22
|
-
id
|
|
24
|
+
id,
|
|
23
25
|
dependencies: taskConfig.dependencies || {},
|
|
24
26
|
middleware: taskConfig.middleware || [],
|
|
25
27
|
run: taskConfig.run,
|
|
@@ -28,19 +30,25 @@ function defineTask(taskConfig) {
|
|
|
28
30
|
events: {
|
|
29
31
|
beforeRun: {
|
|
30
32
|
...defineEvent({
|
|
31
|
-
id:
|
|
33
|
+
id: isAnonymous
|
|
34
|
+
? Symbol(`anonymous-task.events.beforeRun`)
|
|
35
|
+
: `${id}.events.beforeRun`,
|
|
32
36
|
}),
|
|
33
37
|
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
34
38
|
},
|
|
35
39
|
afterRun: {
|
|
36
40
|
...defineEvent({
|
|
37
|
-
id:
|
|
41
|
+
id: isAnonymous
|
|
42
|
+
? Symbol(`anonymous-task.events.afterRun`)
|
|
43
|
+
: `${id}.events.afterRun`,
|
|
38
44
|
}),
|
|
39
45
|
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
40
46
|
},
|
|
41
47
|
onError: {
|
|
42
48
|
...defineEvent({
|
|
43
|
-
id:
|
|
49
|
+
id: isAnonymous
|
|
50
|
+
? Symbol(`anonymous-task.events.onError`)
|
|
51
|
+
: `${id}.events.onError`,
|
|
44
52
|
}),
|
|
45
53
|
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
46
54
|
},
|
|
@@ -50,11 +58,16 @@ function defineTask(taskConfig) {
|
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
function defineResource(constConfig) {
|
|
53
|
-
|
|
61
|
+
// The symbolFilePath might already come from defineIndex() for example
|
|
62
|
+
const filePath = constConfig[defs_1.symbolFilePath] || (0, getCallerFile_1.getCallerFile)();
|
|
63
|
+
const isIndexResource = constConfig[defs_1.symbolIndexResource] || false;
|
|
64
|
+
const isAnonymous = !Boolean(constConfig.id);
|
|
65
|
+
const id = constConfig.id ||
|
|
66
|
+
(0, getCallerFile_1.generateCallerIdFromFile)(filePath, isIndexResource ? "index" : "resource");
|
|
54
67
|
return {
|
|
55
68
|
[defs_1.symbols.resource]: true,
|
|
56
69
|
[defs_1.symbols.filePath]: filePath,
|
|
57
|
-
id
|
|
70
|
+
id,
|
|
58
71
|
dependencies: constConfig.dependencies,
|
|
59
72
|
dispose: constConfig.dispose,
|
|
60
73
|
register: constConfig.register || [],
|
|
@@ -72,19 +85,25 @@ function defineResource(constConfig) {
|
|
|
72
85
|
events: {
|
|
73
86
|
beforeInit: {
|
|
74
87
|
...defineEvent({
|
|
75
|
-
id:
|
|
88
|
+
id: isAnonymous
|
|
89
|
+
? Symbol(`anonymous-resource.events.beforeInit`)
|
|
90
|
+
: `${id}.events.beforeInit`,
|
|
76
91
|
}),
|
|
77
92
|
[defs_1.symbols.filePath]: filePath,
|
|
78
93
|
},
|
|
79
94
|
afterInit: {
|
|
80
95
|
...defineEvent({
|
|
81
|
-
id:
|
|
96
|
+
id: isAnonymous
|
|
97
|
+
? Symbol(`anonymous-resource.events.afterInit`)
|
|
98
|
+
: `${id}.events.afterInit`,
|
|
82
99
|
}),
|
|
83
100
|
[defs_1.symbols.filePath]: filePath,
|
|
84
101
|
},
|
|
85
102
|
onError: {
|
|
86
103
|
...defineEvent({
|
|
87
|
-
id:
|
|
104
|
+
id: isAnonymous
|
|
105
|
+
? Symbol(`anonymous-resource.events.onError`)
|
|
106
|
+
: `${id}.events.onError`,
|
|
88
107
|
}),
|
|
89
108
|
[defs_1.symbols.filePath]: filePath,
|
|
90
109
|
},
|
|
@@ -112,27 +131,33 @@ function defineIndex(items) {
|
|
|
112
131
|
dependencies[key] = item;
|
|
113
132
|
}
|
|
114
133
|
}
|
|
134
|
+
const callerFilePath = (0, getCallerFile_1.getCallerFile)();
|
|
115
135
|
return defineResource({
|
|
116
|
-
id: `index.${Math.random().toString(36).slice(2)}`,
|
|
117
136
|
register,
|
|
118
137
|
dependencies,
|
|
119
138
|
async init(_, deps) {
|
|
120
139
|
return deps;
|
|
121
140
|
},
|
|
141
|
+
[defs_1.symbols.filePath]: callerFilePath,
|
|
142
|
+
[defs_1.symbols.indexResource]: true,
|
|
122
143
|
});
|
|
123
144
|
}
|
|
124
145
|
function defineEvent(config) {
|
|
146
|
+
const callerFilePath = (0, getCallerFile_1.getCallerFile)();
|
|
125
147
|
return {
|
|
126
|
-
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
127
|
-
[defs_1.symbolEvent]: true,
|
|
128
148
|
...config,
|
|
149
|
+
id: config.id || (0, getCallerFile_1.generateCallerIdFromFile)(callerFilePath, "event"),
|
|
150
|
+
[defs_1.symbols.filePath]: callerFilePath,
|
|
151
|
+
[defs_1.symbolEvent]: true, // This is a workaround
|
|
129
152
|
};
|
|
130
153
|
}
|
|
131
154
|
function defineMiddleware(middlewareDef) {
|
|
155
|
+
const filePath = (0, getCallerFile_1.getCallerFile)();
|
|
132
156
|
const object = {
|
|
133
|
-
[defs_1.symbols.filePath]:
|
|
157
|
+
[defs_1.symbols.filePath]: filePath,
|
|
134
158
|
[defs_1.symbols.middleware]: true,
|
|
135
159
|
config: {},
|
|
160
|
+
id: middlewareDef.id || (0, getCallerFile_1.generateCallerIdFromFile)(filePath, "middleware"),
|
|
136
161
|
...middlewareDef,
|
|
137
162
|
dependencies: middlewareDef.dependencies || {},
|
|
138
163
|
};
|
|
@@ -155,7 +180,7 @@ function defineMiddleware(middlewareDef) {
|
|
|
155
180
|
[defs_1.symbols.middlewareEverywhereTasks]: tasks,
|
|
156
181
|
[defs_1.symbols.middlewareEverywhereResources]: resources,
|
|
157
182
|
everywhere() {
|
|
158
|
-
throw errors_1.Errors.middlewareAlreadyGlobal(
|
|
183
|
+
throw errors_1.Errors.middlewareAlreadyGlobal(object.id);
|
|
159
184
|
},
|
|
160
185
|
};
|
|
161
186
|
},
|
package/dist/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;AAwBA,gCAiDC;AAED,wCA+DC;AAQD,kCAgCC;AAED,kCAUC;AAaD,4CAyCC;AAED,wBAEC;AAED,gCAEC;AAED,oDAIC;AAED,0BAEC;AAED,oCAEC;AA1QD,iCAkBgB;AAChB,qCAAkC;AAClC,yDAAgF;AAEhF,yCAAyC;AAEzC,SAAgB,UAAU,CAMxB,UAAqD;IAErD,MAAM,QAAQ,GAAG,IAA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AClD,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;YAEnD,OAAO;gBACL,GAAG,MAAM;gBACT,CAAC,cAAO,CAAC,yBAAyB,CAAC,EAAE,KAAK;gBAC1C,CAAC,cAAO,CAAC,6BAA6B,CAAC,EAAE,SAAS;gBAClD,UAAU;oBACR,MAAM,eAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAClD,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,MAAM,CAAC,UAAe;IACpC,OAAO,UAAU,IAAI,UAAU,CAAC,cAAO,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,UAAU,CAAC,UAAe;IACxC,OAAO,UAAU,IAAI,UAAU,CAAC,cAAO,CAAC,QAAQ,CAAC,CAAC;AACpD,CAAC;AAED,SAAgB,oBAAoB,CAClC,UAAe;IAEf,OAAO,UAAU,IAAI,UAAU,CAAC,cAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9D,CAAC;AAED,SAAgB,OAAO,CAAC,UAAe;IACrC,OAAO,UAAU,IAAI,UAAU,CAAC,cAAO,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC;AAED,SAAgB,YAAY,CAAC,UAAe;IAC1C,OAAO,UAAU,IAAI,UAAU,CAAC,cAAO,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/defs.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MiddlewareEverywhereOptions } from "./define";
|
|
1
2
|
export { ICacheInstance } from "./globals/middleware/cache.middleware";
|
|
2
3
|
export declare const symbolTask: unique symbol;
|
|
3
4
|
export declare const symbolResource: unique symbol;
|
|
@@ -11,10 +12,12 @@ export declare const symbolMiddlewareEverywhereResources: unique symbol;
|
|
|
11
12
|
export declare const symbolFilePath: unique symbol;
|
|
12
13
|
export declare const symbolDispose: unique symbol;
|
|
13
14
|
export declare const symbolStore: unique symbol;
|
|
15
|
+
export declare const symbolIndexResource: unique symbol;
|
|
14
16
|
export declare const symbols: {
|
|
15
17
|
task: symbol;
|
|
16
18
|
resource: symbol;
|
|
17
19
|
resourceWithConfig: symbol;
|
|
20
|
+
indexResource: symbol;
|
|
18
21
|
event: symbol;
|
|
19
22
|
middleware: symbol;
|
|
20
23
|
middlewareEverywhereTasks: symbol;
|
|
@@ -40,22 +43,31 @@ export type DependencyMapType = Record<string, ITask<any, any, any, any> | IReso
|
|
|
40
43
|
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer D> ? I : never;
|
|
41
44
|
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer D> ? O : never;
|
|
42
45
|
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer D> ? V : never;
|
|
43
|
-
type ExtractEventParams<T> = T extends
|
|
46
|
+
type ExtractEventParams<T> = T extends IEvent<infer P> ? P : never;
|
|
47
|
+
/**
|
|
48
|
+
* This represents a task dependency function that can be called with or without parameters.
|
|
49
|
+
*/
|
|
44
50
|
type TaskDependency<I, O> = (...args: I extends null | void ? [] : [I]) => O;
|
|
51
|
+
/**
|
|
52
|
+
* This represents the resource's value type.
|
|
53
|
+
*/
|
|
45
54
|
type ResourceDependency<V> = V;
|
|
46
|
-
|
|
55
|
+
/**
|
|
56
|
+
* This represents an event emission function that can be called with or without parameters.
|
|
57
|
+
*/
|
|
58
|
+
type EventDependency<P> = P extends void ? (() => Promise<void>) & ((input?: Record<string, never>) => Promise<void>) : (input: P) => Promise<void>;
|
|
47
59
|
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<ExtractEventParams<T>> : never;
|
|
48
60
|
export type DependencyValuesType<T extends DependencyMapType> = {
|
|
49
61
|
[K in keyof T]: DependencyValueType<T[K]>;
|
|
50
62
|
};
|
|
51
63
|
export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<void, any, any, any> | IResource<{
|
|
52
64
|
[K in any]?: any;
|
|
53
|
-
}, any, any, any> |
|
|
65
|
+
}, any, any, any> | ITask<any, any, any, any> | IMiddleware<any> | IEvent<any>;
|
|
54
66
|
export type MiddlewareAttachments = IMiddleware<void> | IMiddleware<{
|
|
55
67
|
[K in any]?: any;
|
|
56
68
|
}> | IMiddlewareConfigured<any>;
|
|
57
69
|
export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> {
|
|
58
|
-
id
|
|
70
|
+
id?: string | symbol;
|
|
59
71
|
dependencies?: TDependencies | (() => TDependencies);
|
|
60
72
|
middleware?: MiddlewareAttachments[];
|
|
61
73
|
/**
|
|
@@ -68,7 +80,7 @@ export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = an
|
|
|
68
80
|
*/
|
|
69
81
|
listenerOrder?: number;
|
|
70
82
|
meta?: ITaskMeta;
|
|
71
|
-
run: (input: TOn extends undefined ? TInput :
|
|
83
|
+
run: (input: TOn extends undefined ? TInput : IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => TOutput;
|
|
72
84
|
}
|
|
73
85
|
export type BeforeRunEventPayload<TInput> = {
|
|
74
86
|
input: TInput;
|
|
@@ -96,6 +108,7 @@ export type AfterInitEventPayload<TConfig, TValue> = {
|
|
|
96
108
|
* This is the response after the definition has been prepared. TODO: better naming?
|
|
97
109
|
*/
|
|
98
110
|
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> {
|
|
111
|
+
id: string | symbol;
|
|
99
112
|
dependencies: TDependencies | (() => TDependencies);
|
|
100
113
|
computedDependencies?: DependencyValuesType<TDependencies>;
|
|
101
114
|
middleware: MiddlewareAttachments[];
|
|
@@ -103,13 +116,13 @@ export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDepend
|
|
|
103
116
|
* These events are automatically populated after the task has been defined.
|
|
104
117
|
*/
|
|
105
118
|
events: {
|
|
106
|
-
beforeRun:
|
|
107
|
-
afterRun:
|
|
108
|
-
onError:
|
|
119
|
+
beforeRun: IEvent<BeforeRunEventPayload<TInput>>;
|
|
120
|
+
afterRun: IEvent<AfterRunEventPayload<TInput, TOutput>>;
|
|
121
|
+
onError: IEvent<OnErrorEventPayload>;
|
|
109
122
|
};
|
|
110
123
|
}
|
|
111
124
|
export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any> {
|
|
112
|
-
id
|
|
125
|
+
id?: string | symbol;
|
|
113
126
|
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
114
127
|
register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
115
128
|
init?: (this: any, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<TValue>;
|
|
@@ -126,17 +139,26 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
|
|
|
126
139
|
overrides?: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
|
|
127
140
|
middleware?: MiddlewareAttachments[];
|
|
128
141
|
context?: () => TContext;
|
|
142
|
+
/**
|
|
143
|
+
* This is optional and used from an index resource to get the correct caller.
|
|
144
|
+
*/
|
|
145
|
+
[symbolFilePath]?: string;
|
|
146
|
+
/**
|
|
147
|
+
* This is used internally when creating index resources.
|
|
148
|
+
*/
|
|
149
|
+
[symbolIndexResource]?: boolean;
|
|
129
150
|
}
|
|
130
151
|
export interface IResource<TConfig = void, TValue = any, TDependencies extends DependencyMapType = any, TContext = any> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext> {
|
|
152
|
+
id: string | symbol;
|
|
131
153
|
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
|
|
132
154
|
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
133
155
|
/**
|
|
134
156
|
* These events are automatically populated after the task has been defined.
|
|
135
157
|
*/
|
|
136
158
|
events: {
|
|
137
|
-
beforeInit:
|
|
138
|
-
afterInit:
|
|
139
|
-
onError:
|
|
159
|
+
beforeInit: IEvent<BeforeInitEventPayload<TConfig>>;
|
|
160
|
+
afterInit: IEvent<AfterInitEventPayload<TConfig, TValue>>;
|
|
161
|
+
onError: IEvent<OnErrorEventPayload>;
|
|
140
162
|
};
|
|
141
163
|
overrides: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
|
|
142
164
|
middleware: MiddlewareAttachments[];
|
|
@@ -146,8 +168,27 @@ export interface IResourceWithConfig<TConfig = any, TValue = any, TDependencies
|
|
|
146
168
|
resource: IResource<TConfig, TValue, TDependencies>;
|
|
147
169
|
config: TConfig;
|
|
148
170
|
}
|
|
149
|
-
export
|
|
150
|
-
|
|
171
|
+
export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
172
|
+
export interface IEventDefinition<TPayload = void> {
|
|
173
|
+
id?: string | symbol;
|
|
174
|
+
meta?: IEventMeta;
|
|
175
|
+
}
|
|
176
|
+
export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
177
|
+
id: string | symbol;
|
|
178
|
+
/**
|
|
179
|
+
* 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.
|
|
180
|
+
*/
|
|
181
|
+
[symbolEvent]: true;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* This represents the object that is passed to event handlers
|
|
185
|
+
*/
|
|
186
|
+
export interface IEventEmission<TPayload = any> {
|
|
187
|
+
/**
|
|
188
|
+
* The ID of the event. This is the same as the event's ID.
|
|
189
|
+
* This is useful for global event listeners.
|
|
190
|
+
*/
|
|
191
|
+
id: string | symbol;
|
|
151
192
|
/**
|
|
152
193
|
* The data that the event carries. It can be anything.
|
|
153
194
|
*/
|
|
@@ -159,23 +200,10 @@ export interface IEvent<TPayload = any> {
|
|
|
159
200
|
/**
|
|
160
201
|
* The source of the event. This can be useful for debugging.
|
|
161
202
|
*/
|
|
162
|
-
source: string;
|
|
163
|
-
}
|
|
164
|
-
export type EventHandlerType<T = any> = (event: IEvent<T>) => any | Promise<any>;
|
|
165
|
-
export interface IEventDefinitionConfig<TPayload = void> {
|
|
166
|
-
id: string;
|
|
167
|
-
meta?: IEventMeta;
|
|
168
|
-
}
|
|
169
|
-
export interface IEventDefinition<TPayload = void> {
|
|
170
|
-
id: string;
|
|
171
|
-
/**
|
|
172
|
-
* 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.
|
|
173
|
-
*/
|
|
174
|
-
[symbolEvent]: true;
|
|
175
|
-
meta?: IEventMeta;
|
|
203
|
+
source: string | symbol;
|
|
176
204
|
}
|
|
177
205
|
export interface IMiddlewareDefinition<TConfig = any, TDependencies extends DependencyMapType = any> {
|
|
178
|
-
id
|
|
206
|
+
id?: string | symbol;
|
|
179
207
|
dependencies?: TDependencies | (() => TDependencies);
|
|
180
208
|
run: (input: IMiddlewareExecutionInput, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
181
209
|
meta?: IMiddlewareMeta;
|
|
@@ -185,8 +213,9 @@ export interface IMiddleware<TConfig = any, TDependencies extends DependencyMapT
|
|
|
185
213
|
[symbolMiddlewareConfigured]?: boolean;
|
|
186
214
|
[symbolMiddlewareEverywhereTasks]?: boolean;
|
|
187
215
|
[symbolMiddlewareEverywhereResources]?: boolean;
|
|
216
|
+
id: string | symbol;
|
|
188
217
|
dependencies: TDependencies | (() => TDependencies);
|
|
189
|
-
everywhere(): IMiddleware<TConfig, TDependencies>;
|
|
218
|
+
everywhere(config?: MiddlewareEverywhereOptions): IMiddleware<TConfig, TDependencies>;
|
|
190
219
|
config: TConfig;
|
|
191
220
|
with: (config: TConfig) => IMiddlewareConfigured<TConfig, TDependencies>;
|
|
192
221
|
}
|
|
@@ -208,17 +237,3 @@ export interface IMiddlewareExecutionInput<TTaskInput = any, TResourceConfig = a
|
|
|
208
237
|
};
|
|
209
238
|
next: (taskInputOrResourceConfig?: TTaskInput | TResourceConfig) => Promise<any>;
|
|
210
239
|
}
|
|
211
|
-
export interface IHookDefinition<D extends DependencyMapType = {}, T = any, B extends boolean = false> {
|
|
212
|
-
event: "*" | IEventDefinition<T>;
|
|
213
|
-
/**
|
|
214
|
-
* The higher the number, the higher the priority.
|
|
215
|
-
* We recommend using numbers between -1000 and 1000.
|
|
216
|
-
*/
|
|
217
|
-
order?: number;
|
|
218
|
-
/**
|
|
219
|
-
* These are hooks that run before any resource instantiation.
|
|
220
|
-
* @param event
|
|
221
|
-
*/
|
|
222
|
-
early?: B;
|
|
223
|
-
run: (event: IEvent<T>, dependencies: T extends true ? void : DependencyValuesType<D>) => Promise<void> | void;
|
|
224
|
-
}
|
package/dist/defs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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
4
|
exports.symbolTask = Symbol("runner.task");
|
|
5
5
|
exports.symbolResource = Symbol("runner.resource");
|
|
6
6
|
exports.symbolResourceWithConfig = Symbol("runner.resourceWithConfig");
|
|
@@ -13,10 +13,12 @@ exports.symbolMiddlewareEverywhereResources = Symbol("runner.middlewareGlobalRes
|
|
|
13
13
|
exports.symbolFilePath = Symbol("runner.filePath");
|
|
14
14
|
exports.symbolDispose = Symbol("runner.dispose");
|
|
15
15
|
exports.symbolStore = Symbol("runner.store");
|
|
16
|
+
exports.symbolIndexResource = Symbol("runner.indexResource");
|
|
16
17
|
exports.symbols = {
|
|
17
18
|
task: exports.symbolTask,
|
|
18
19
|
resource: exports.symbolResource,
|
|
19
20
|
resourceWithConfig: exports.symbolResourceWithConfig,
|
|
21
|
+
indexResource: exports.symbolIndexResource,
|
|
20
22
|
event: exports.symbolEvent,
|
|
21
23
|
middleware: exports.symbolMiddleware,
|
|
22
24
|
middlewareEverywhereTasks: exports.symbolMiddlewareEverywhereTasks,
|
package/dist/defs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AAKa,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;AAEW,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1D,QAAA,aAAa,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACxD,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAEpD,QAAA,mBAAmB,GAAkB,MAAM,CACtD,sBAAsB,CACvB,CAAC;AAEW,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"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const Errors: {
|
|
2
|
-
duplicateRegistration: (type: string, id: string) => Error;
|
|
3
|
-
dependencyNotFound: (key: string) => Error;
|
|
2
|
+
duplicateRegistration: (type: string, id: string | symbol) => Error;
|
|
3
|
+
dependencyNotFound: (key: string | symbol) => Error;
|
|
4
4
|
unknownItemType: (item: any) => Error;
|
|
5
5
|
circularDependencies: (cycles: string[]) => Error;
|
|
6
|
-
eventNotFound: (id: string) => Error;
|
|
7
|
-
middlewareAlreadyGlobal: (id: string) => Error;
|
|
8
|
-
locked: (what: string) => Error;
|
|
6
|
+
eventNotFound: (id: string | symbol) => Error;
|
|
7
|
+
middlewareAlreadyGlobal: (id: string | symbol) => Error;
|
|
8
|
+
locked: (what: string | symbol) => Error;
|
|
9
9
|
storeAlreadyInitialized: () => Error;
|
|
10
10
|
};
|
package/dist/errors.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Errors = void 0;
|
|
4
4
|
exports.Errors = {
|
|
5
|
-
duplicateRegistration: (type, id) => new Error(`${type} "${id}" already registered`),
|
|
6
|
-
dependencyNotFound: (key) => new Error(`Dependency ${key} not found. Did you forget to register it through a resource?`),
|
|
5
|
+
duplicateRegistration: (type, id) => new Error(`${type} "${id.toString()}" already registered`),
|
|
6
|
+
dependencyNotFound: (key) => new Error(`Dependency ${key.toString()} not found. Did you forget to register it through a resource?`),
|
|
7
7
|
unknownItemType: (item) => new Error(`Unknown item type: ${item}`),
|
|
8
8
|
circularDependencies: (cycles) => new Error(`Circular dependencies detected: ${cycles.join(", ")}`),
|
|
9
|
-
eventNotFound: (id) => new Error(`Event "${id}" not found. Did you forget to register it?`),
|
|
10
|
-
middlewareAlreadyGlobal: (id) => new Error("Cannot call .everywhere() on an already global middleware: " +
|
|
11
|
-
|
|
9
|
+
eventNotFound: (id) => new Error(`Event "${id.toString()}" not found. Did you forget to register it?`),
|
|
10
|
+
middlewareAlreadyGlobal: (id) => new Error("Cannot call .everywhere() on an already global middleware: " +
|
|
11
|
+
id.toString),
|
|
12
|
+
locked: (what) => new Error(`Cannot modify the ${what.toString()} when it is locked.`),
|
|
12
13
|
storeAlreadyInitialized: () => new Error("Store already initialized. Cannot reinitialize."),
|
|
13
14
|
};
|
|
14
15
|
//# 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":";;;AAEa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,CAAC,IAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,CAAC,IAAY,EAAE,EAAmB,EAAE,EAAE,CAC3D,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAE5D,kBAAkB,EAAE,CAAC,GAAoB,EAAE,EAAE,CAC3C,IAAI,KAAK,CACP,cAAc,GAAG,CAAC,QAAQ,EAAE,+DAA+D,CAC5F;IAEH,eAAe,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC;IAEvE,oBAAoB,EAAE,CAAC,MAAgB,EAAE,EAAE,CACzC,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAEnE,aAAa,EAAE,CAAC,EAAmB,EAAE,EAAE,CACrC,IAAI,KAAK,CACP,UAAU,EAAE,CAAC,QAAQ,EAAE,6CAA6C,CACrE;IAEH,uBAAuB,EAAE,CAAC,EAAmB,EAAE,EAAE,CAC/C,IAAI,KAAK,CACP,6DAA6D;QAC3D,EAAE,CAAC,QAAQ,CACd;IAEH,MAAM,EAAE,CAAC,IAAqB,EAAE,EAAE,CAChC,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IAEtE,uBAAuB,EAAE,GAAG,EAAE,CAC5B,IAAI,KAAK,CAAC,iDAAiD,CAAC;CAC/D,CAAC"}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { ITask, IResource } from "../defs";
|
|
1
|
+
import { ITask, IResource, IEvent } from "../defs";
|
|
2
2
|
import { ILog } from "../models/Logger";
|
|
3
3
|
export declare const globalEvents: {
|
|
4
|
-
beforeInit:
|
|
5
|
-
afterInit:
|
|
6
|
-
log:
|
|
4
|
+
beforeInit: IEvent<void>;
|
|
5
|
+
afterInit: IEvent<void>;
|
|
6
|
+
log: IEvent<ILog>;
|
|
7
7
|
tasks: {
|
|
8
|
-
beforeRun:
|
|
8
|
+
beforeRun: IEvent<{
|
|
9
9
|
task: ITask<any, any, any>;
|
|
10
10
|
input: any;
|
|
11
11
|
}>;
|
|
12
|
-
afterRun:
|
|
12
|
+
afterRun: IEvent<{
|
|
13
13
|
task: ITask<any, any, any>;
|
|
14
14
|
input: any;
|
|
15
15
|
output: any;
|
|
16
16
|
setOutput: (newOutput: any) => void;
|
|
17
17
|
}>;
|
|
18
|
-
onError:
|
|
18
|
+
onError: IEvent<{
|
|
19
19
|
error: any;
|
|
20
20
|
suppress: () => void;
|
|
21
21
|
task: ITask<any, any, any>;
|
|
22
22
|
}>;
|
|
23
23
|
};
|
|
24
24
|
resources: {
|
|
25
|
-
beforeInit:
|
|
25
|
+
beforeInit: IEvent<{
|
|
26
26
|
resource: IResource<any, any, any>;
|
|
27
27
|
config: any;
|
|
28
28
|
}>;
|
|
29
|
-
afterInit:
|
|
29
|
+
afterInit: IEvent<{
|
|
30
30
|
resource: IResource<any, any, any>;
|
|
31
31
|
config: any;
|
|
32
32
|
value: any;
|
|
33
33
|
}>;
|
|
34
|
-
onError:
|
|
34
|
+
onError: IEvent<{
|
|
35
35
|
error: Error;
|
|
36
36
|
suppress: () => void;
|
|
37
37
|
resource: IResource<any, any, any>;
|
|
38
38
|
}>;
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
export declare const globalEventsArray:
|
|
41
|
+
export declare const globalEventsArray: IEvent<void>[];
|
|
@@ -12,7 +12,7 @@ export declare const globalMiddlewares: {
|
|
|
12
12
|
defaultOptions?: any;
|
|
13
13
|
async?: boolean;
|
|
14
14
|
}, {
|
|
15
|
-
map: Map<string, import("./middleware/cache.middleware").ICacheInstance>;
|
|
15
|
+
map: Map<string | symbol, import("./middleware/cache.middleware").ICacheInstance>;
|
|
16
16
|
cacheFactoryTask: (...args: [] | [any]) => Promise<import("./middleware/cache.middleware").ICacheInstance>;
|
|
17
17
|
async: boolean | undefined;
|
|
18
18
|
defaultOptions: any;
|