tsdkarc 1.0.0 → 1.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 +35 -11
- package/esm/index.d.ts +5 -1
- package/esm/index.js +22 -4
- package/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +22 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
# <a href="https://arc.tsdk.dev" align="center"><img src="./assets/logo.jpg" align="center" width="30px" height="30px" style="border-radius: 4px;margin-right:4px;" alt="TsdkArc: the Elegant, fully type-safe module
|
|
1
|
+
# <a href="https://arc.tsdk.dev" align="center"><img src="./assets/logo.jpg" align="center" width="30px" height="30px" style="border-radius: 4px;margin-right:4px;" alt="TsdkArc: the Elegant, fully type-safe module composable library" /></a> TsdkArc
|
|
2
2
|
|
|
3
3
|
<a href="https://arc.tsdk.dev">
|
|
4
|
-
<img src="./assets/banner.jpg" width="100%" style="border-radius: 24px" alt="TsdkArc: the Elegant, fully type-safe module
|
|
4
|
+
<img src="./assets/banner.jpg" width="100%" style="border-radius: 24px" alt="TsdkArc: the Elegant, fully type-safe module composable library" /></a>
|
|
5
5
|
|
|
6
|
-
<div align="center">The Elegant, Fully Type-safe Module
|
|
6
|
+
<div align="center">The Elegant, Fully Type-safe Module Composable Library.
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
## Why `TsdkArc`
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Your application codebases grow, the code become coupled and messy — hard to reuse, hard to share.
|
|
14
14
|
`TsdkArc` lets you compose modules like building blocks, nest them, and share them type safely across projects.
|
|
15
15
|
|
|
16
|
-
In **
|
|
16
|
+
In **tsdkarc**, Each module declares what it needs and what it provides. Then call `start([modules])` will resolves the full dependency graph, boots modules in order, and returns a typed context.
|
|
17
17
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
@@ -32,16 +32,33 @@ const configModule = defineModule<ConfigSlice>()({
|
|
|
32
32
|
name: "config",
|
|
33
33
|
modules: [],
|
|
34
34
|
boot(ctx) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
return {
|
|
36
|
+
config: {
|
|
37
|
+
env: process.env.NODE_ENV ?? "development",
|
|
38
|
+
port: Number(process.env.PORT) || 3000,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
// Or:
|
|
42
|
+
/*
|
|
43
|
+
ctx.set("config", {
|
|
44
|
+
env: process.env.NODE_ENV ?? "development",
|
|
45
|
+
port: Number(process.env.PORT) || 3000,
|
|
46
|
+
});
|
|
47
|
+
*/
|
|
39
48
|
},
|
|
40
49
|
});
|
|
41
50
|
|
|
42
51
|
// Run
|
|
43
52
|
(async () => {
|
|
44
|
-
const app = await start([
|
|
53
|
+
const app = await start([serverModule], {
|
|
54
|
+
afterBoot() {
|
|
55
|
+
console.log("The app is running");
|
|
56
|
+
},
|
|
57
|
+
onError(error, ctx, mod) {
|
|
58
|
+
console.log(`${mod.name} error`, error.message);
|
|
59
|
+
// throw error;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
45
62
|
console.log(app.ctx.config.port); // 3000
|
|
46
63
|
await app.stop();
|
|
47
64
|
})();
|
|
@@ -63,7 +80,7 @@ const configModule = defineModule<ConfigSlice>()({
|
|
|
63
80
|
defineModule<OwnSlice>()({
|
|
64
81
|
name: string,
|
|
65
82
|
modules: Module[],
|
|
66
|
-
boot?(ctx): void | Promise<void>,
|
|
83
|
+
boot?(ctx): OwnSlice | Promise<OwnSlice> | void | Promise<void>,
|
|
67
84
|
beforeBoot?(ctx): void | Promise<void>,
|
|
68
85
|
afterBoot?(ctx): void | Promise<void>,
|
|
69
86
|
shutdown?(ctx): void | Promise<void>,
|
|
@@ -76,6 +93,13 @@ start(modules: Module[], hooks?: {
|
|
|
76
93
|
afterBoot?(ctx): void | Promise<void>,
|
|
77
94
|
beforeShutdown?(ctx): void | Promise<void>,
|
|
78
95
|
afterShutdown?(ctx): void | Promise<void>,
|
|
96
|
+
|
|
97
|
+
beforeEachBoot?(ctx): void | Promise<void>,
|
|
98
|
+
afterEachBoot?(ctx): void | Promise<void>,
|
|
99
|
+
beforeEachShutdown?(ctx): void | Promise<void>,
|
|
100
|
+
afterEachShutdown?(ctx): void | Promise<void>,
|
|
101
|
+
|
|
102
|
+
onError?(error: Error, ctx, mod): void | Promise<void>,
|
|
79
103
|
}): Promise<{ ctx, stop() }>
|
|
80
104
|
```
|
|
81
105
|
|
package/esm/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
export type ContextWriter<S extends object, Sl extends object = S> = Readonly<S> & {
|
|
29
29
|
set<K extends Exclude<keyof Sl, "set">>(key: K, value: Sl[K]): void;
|
|
30
|
+
set(ctx: Sl): void;
|
|
30
31
|
};
|
|
31
32
|
/** Converts U1 | U2 | U3 into U1 & U2 & U3 via contravariance. */
|
|
32
33
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
@@ -75,6 +76,9 @@ export interface LifecycleHooks<S extends object = Record<never, never>> {
|
|
|
75
76
|
afterEachShutdown?(ctx: ContextWriter<S>,
|
|
76
77
|
/** The module that just finished shutting down. */
|
|
77
78
|
module: Module<any>): Promise<void> | void;
|
|
79
|
+
onError?(error: Error, ctx: ContextWriter<S>,
|
|
80
|
+
/** The module that just finished shutting down. */
|
|
81
|
+
module: Module<any>): Promise<void> | void;
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Module<S, Sl>
|
|
@@ -117,7 +121,7 @@ export declare function defineModule<OwnSlice extends object = Record<never, nev
|
|
|
117
121
|
name: string;
|
|
118
122
|
description?: string;
|
|
119
123
|
modules?: Deps;
|
|
120
|
-
boot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void
|
|
124
|
+
boot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void | OwnSlice | Promise<OwnSlice>;
|
|
121
125
|
shutdown?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
|
122
126
|
beforeBoot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
|
123
127
|
afterBoot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
package/esm/index.js
CHANGED
|
@@ -74,7 +74,7 @@ export function defineModule() {
|
|
|
74
74
|
export default function start(roots_1) {
|
|
75
75
|
return __awaiter(this, arguments, void 0, function* (roots, options = {}) {
|
|
76
76
|
var _a, _b, _c;
|
|
77
|
-
const { beforeBoot, afterBoot, beforeShutdown, afterShutdown, beforeEachBoot, afterEachBoot, beforeEachShutdown, afterEachShutdown, } = options;
|
|
77
|
+
const { beforeBoot, afterBoot, beforeShutdown, afterShutdown, beforeEachBoot, afterEachBoot, beforeEachShutdown, afterEachShutdown, onError, } = options;
|
|
78
78
|
const ctx = {};
|
|
79
79
|
const writer = makeWriter(ctx);
|
|
80
80
|
const modWriter = writer;
|
|
@@ -97,7 +97,13 @@ export default function start(roots_1) {
|
|
|
97
97
|
yield ((_c = mod.afterShutdown) === null || _c === void 0 ? void 0 : _c.call(mod, modWriter));
|
|
98
98
|
}
|
|
99
99
|
catch (err) {
|
|
100
|
-
|
|
100
|
+
const error = new Error(`Module "${mod.name}" stop failed: ${errorMessage(err)}`);
|
|
101
|
+
if (onError) {
|
|
102
|
+
yield (onError === null || onError === void 0 ? void 0 : onError(error, writer, mod));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
yield (afterShutdown === null || afterShutdown === void 0 ? void 0 : afterShutdown(writer));
|
|
@@ -108,7 +114,9 @@ export default function start(roots_1) {
|
|
|
108
114
|
try {
|
|
109
115
|
yield (beforeEachBoot === null || beforeEachBoot === void 0 ? void 0 : beforeEachBoot(writer, mod));
|
|
110
116
|
yield ((_a = mod.beforeBoot) === null || _a === void 0 ? void 0 : _a.call(mod, modWriter));
|
|
111
|
-
yield ((_b = mod.boot) === null || _b === void 0 ? void 0 : _b.call(mod, modWriter));
|
|
117
|
+
const modCtx = yield ((_b = mod.boot) === null || _b === void 0 ? void 0 : _b.call(mod, modWriter));
|
|
118
|
+
if (modCtx)
|
|
119
|
+
modWriter.set(modCtx);
|
|
112
120
|
yield (afterEachBoot === null || afterEachBoot === void 0 ? void 0 : afterEachBoot(writer, mod));
|
|
113
121
|
yield ((_c = mod.afterBoot) === null || _c === void 0 ? void 0 : _c.call(mod, modWriter));
|
|
114
122
|
booted.push(mod);
|
|
@@ -116,7 +124,13 @@ export default function start(roots_1) {
|
|
|
116
124
|
catch (err) {
|
|
117
125
|
stopped = true;
|
|
118
126
|
yield rollback(booted, modWriter);
|
|
119
|
-
|
|
127
|
+
const error = new Error(`Module "${mod.name}" boot failed: ${errorMessage(err)}`);
|
|
128
|
+
if (onError) {
|
|
129
|
+
yield (onError === null || onError === void 0 ? void 0 : onError(error, writer, mod));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
yield (afterBoot === null || afterBoot === void 0 ? void 0 : afterBoot(writer));
|
|
@@ -205,7 +219,11 @@ export function rollback(booted, modWriter) {
|
|
|
205
219
|
function makeWriter(ctx) {
|
|
206
220
|
return Object.assign(ctx, {
|
|
207
221
|
set(key, value) {
|
|
222
|
+
if (typeof key === "object") {
|
|
223
|
+
return Object.assign(ctx, key);
|
|
224
|
+
}
|
|
208
225
|
ctx[key] = value;
|
|
226
|
+
return ctx;
|
|
209
227
|
},
|
|
210
228
|
});
|
|
211
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/index.ts","../node_modules/@types/deep-eql/index.d.ts","../node_modules/assertion-error/index.d.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/estree/index.d.ts"],"fileIdsList":[[16,17]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"
|
|
1
|
+
{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/index.ts","../node_modules/@types/deep-eql/index.d.ts","../node_modules/assertion-error/index.d.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/estree/index.d.ts"],"fileIdsList":[[16,17]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"3d2cddd1ad972ba2b9c02c9027c7724a50ef0a1d83210807e2f0dcdb1317e270","signature":"aadedff0c250acaa6d24078a4cd8ad38abdd873d20e3475a09d9835523243086"},{"version":"427fe2004642504828c1476d0af4270e6ad4db6de78c0b5da3e4c5ca95052a99","impliedFormat":1},{"version":"2eeffcee5c1661ddca53353929558037b8cf305ffb86a803512982f99bcab50d","impliedFormat":99},{"version":"9afb4cb864d297e4092a79ee2871b5d3143ea14153f62ef0bb04ede25f432030","affectsGlobalScope":true,"impliedFormat":99},{"version":"151ff381ef9ff8da2da9b9663ebf657eac35c4c9a19183420c05728f31a6761d","impliedFormat":1}],"root":[15],"options":{"declaration":true,"downlevelIteration":true,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"module":5,"noImplicitAny":true,"outDir":"./","skipLibCheck":true,"strict":true,"strictPropertyInitialization":false,"target":2},"referencedMap":[[18,1]],"version":"5.9.3"}
|
package/lib/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
export type ContextWriter<S extends object, Sl extends object = S> = Readonly<S> & {
|
|
29
29
|
set<K extends Exclude<keyof Sl, "set">>(key: K, value: Sl[K]): void;
|
|
30
|
+
set(ctx: Sl): void;
|
|
30
31
|
};
|
|
31
32
|
/** Converts U1 | U2 | U3 into U1 & U2 & U3 via contravariance. */
|
|
32
33
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
@@ -75,6 +76,9 @@ export interface LifecycleHooks<S extends object = Record<never, never>> {
|
|
|
75
76
|
afterEachShutdown?(ctx: ContextWriter<S>,
|
|
76
77
|
/** The module that just finished shutting down. */
|
|
77
78
|
module: Module<any>): Promise<void> | void;
|
|
79
|
+
onError?(error: Error, ctx: ContextWriter<S>,
|
|
80
|
+
/** The module that just finished shutting down. */
|
|
81
|
+
module: Module<any>): Promise<void> | void;
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Module<S, Sl>
|
|
@@ -117,7 +121,7 @@ export declare function defineModule<OwnSlice extends object = Record<never, nev
|
|
|
117
121
|
name: string;
|
|
118
122
|
description?: string;
|
|
119
123
|
modules?: Deps;
|
|
120
|
-
boot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void
|
|
124
|
+
boot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void | OwnSlice | Promise<OwnSlice>;
|
|
121
125
|
shutdown?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
|
122
126
|
beforeBoot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
|
123
127
|
afterBoot?(ctx: ContextWriter<FullContext<Deps, OwnSlice>, OwnSlice>): Promise<void> | void;
|
package/lib/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function defineModule() {
|
|
|
81
81
|
function start(roots_1) {
|
|
82
82
|
return __awaiter(this, arguments, void 0, function* (roots, options = {}) {
|
|
83
83
|
var _a, _b, _c;
|
|
84
|
-
const { beforeBoot, afterBoot, beforeShutdown, afterShutdown, beforeEachBoot, afterEachBoot, beforeEachShutdown, afterEachShutdown, } = options;
|
|
84
|
+
const { beforeBoot, afterBoot, beforeShutdown, afterShutdown, beforeEachBoot, afterEachBoot, beforeEachShutdown, afterEachShutdown, onError, } = options;
|
|
85
85
|
const ctx = {};
|
|
86
86
|
const writer = makeWriter(ctx);
|
|
87
87
|
const modWriter = writer;
|
|
@@ -104,7 +104,13 @@ function start(roots_1) {
|
|
|
104
104
|
yield ((_c = mod.afterShutdown) === null || _c === void 0 ? void 0 : _c.call(mod, modWriter));
|
|
105
105
|
}
|
|
106
106
|
catch (err) {
|
|
107
|
-
|
|
107
|
+
const error = new Error(`Module "${mod.name}" stop failed: ${errorMessage(err)}`);
|
|
108
|
+
if (onError) {
|
|
109
|
+
yield (onError === null || onError === void 0 ? void 0 : onError(error, writer, mod));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
yield (afterShutdown === null || afterShutdown === void 0 ? void 0 : afterShutdown(writer));
|
|
@@ -115,7 +121,9 @@ function start(roots_1) {
|
|
|
115
121
|
try {
|
|
116
122
|
yield (beforeEachBoot === null || beforeEachBoot === void 0 ? void 0 : beforeEachBoot(writer, mod));
|
|
117
123
|
yield ((_a = mod.beforeBoot) === null || _a === void 0 ? void 0 : _a.call(mod, modWriter));
|
|
118
|
-
yield ((_b = mod.boot) === null || _b === void 0 ? void 0 : _b.call(mod, modWriter));
|
|
124
|
+
const modCtx = yield ((_b = mod.boot) === null || _b === void 0 ? void 0 : _b.call(mod, modWriter));
|
|
125
|
+
if (modCtx)
|
|
126
|
+
modWriter.set(modCtx);
|
|
119
127
|
yield (afterEachBoot === null || afterEachBoot === void 0 ? void 0 : afterEachBoot(writer, mod));
|
|
120
128
|
yield ((_c = mod.afterBoot) === null || _c === void 0 ? void 0 : _c.call(mod, modWriter));
|
|
121
129
|
booted.push(mod);
|
|
@@ -123,7 +131,13 @@ function start(roots_1) {
|
|
|
123
131
|
catch (err) {
|
|
124
132
|
stopped = true;
|
|
125
133
|
yield rollback(booted, modWriter);
|
|
126
|
-
|
|
134
|
+
const error = new Error(`Module "${mod.name}" boot failed: ${errorMessage(err)}`);
|
|
135
|
+
if (onError) {
|
|
136
|
+
yield (onError === null || onError === void 0 ? void 0 : onError(error, writer, mod));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
yield (afterBoot === null || afterBoot === void 0 ? void 0 : afterBoot(writer));
|
|
@@ -212,7 +226,11 @@ function rollback(booted, modWriter) {
|
|
|
212
226
|
function makeWriter(ctx) {
|
|
213
227
|
return Object.assign(ctx, {
|
|
214
228
|
set(key, value) {
|
|
229
|
+
if (typeof key === "object") {
|
|
230
|
+
return Object.assign(ctx, key);
|
|
231
|
+
}
|
|
215
232
|
ctx[key] = value;
|
|
233
|
+
return ctx;
|
|
216
234
|
},
|
|
217
235
|
});
|
|
218
236
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdkarc",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "TsdkArc is an elegant and fully type-safe module composable library",
|
|
5
5
|
"repository": "tsdk-monorepo/tsdkarc",
|
|
6
6
|
"bugs": "https://github.com/tsdk-monorepo/tsdkarc/issues",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://arc.tsdk.dev",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"module": "esm/index.js",
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"keywords": [
|
|
18
18
|
"typesafe",
|
|
19
19
|
"tsdk",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"module composable",
|
|
21
|
+
"dependency injection"
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT"
|
|
24
24
|
}
|