tsdkarc 1.1.2 → 1.1.4
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 +5 -2
- package/esm/index.d.ts +20 -0
- package/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/index.d.ts +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
[](https://www.npmjs.com/package/tsdkarc) [](https://bundlejs.com/?q=tsdkarc&treeshake=%5B%
|
|
11
|
+
[](https://www.npmjs.com/package/tsdkarc) [](https://bundlejs.com/?q=tsdkarc&treeshake=%5B%7Bdefault,defineModule%7D%5D&config=%7B%22esbuild%22:%7B%22external%22:%5B%22react%22,%22react-dom%22,%22react/jsx-runtime%22%5D%7D%7D)  [](https://github.com/suhaotian/tsdkarc/pulls) [](https://github.com/suhaotian/tsdkarc/blob/main/LICENSE) [](https://www.jsdocs.io/package/tsdkarc) 
|
|
12
12
|
|
|
13
13
|
## Why `TsdkArc`
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ npm install tsdkarc
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
import start, { defineModule } from "tsdkarc";
|
|
27
|
+
import start, { defineModule, type InferContextBy } from "tsdkarc";
|
|
28
28
|
|
|
29
29
|
interface ConfigSlice {
|
|
30
30
|
config: { port: number; env: string };
|
|
@@ -50,6 +50,9 @@ const configModule = defineModule<ConfigSlice>()({
|
|
|
50
50
|
},
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
// get type from module
|
|
54
|
+
type ConfigModuleCtx = InferContextBy<typeof configModule>; // same as `ConfigSlice`
|
|
55
|
+
|
|
53
56
|
// Run
|
|
54
57
|
(async () => {
|
|
55
58
|
const app = await start([serverModule], {
|
package/esm/index.d.ts
CHANGED
|
@@ -101,6 +101,26 @@ export interface Module<S extends object, Sl extends object = S> {
|
|
|
101
101
|
/** Called immediately after this module's own shutdown(). */
|
|
102
102
|
afterShutdown?(ctx: ContextWriter<S, Sl>): Promise<void> | void;
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
|
|
106
|
+
type AContext = {
|
|
107
|
+
value: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const moduleA = defineModule<AContext>()({
|
|
111
|
+
name: "A",
|
|
112
|
+
modules: [] as const,
|
|
113
|
+
boot: () => ({ value: "module:A" }),
|
|
114
|
+
async shutdown(ctx) {
|
|
115
|
+
console.log(`shutdown ${ctx.value}`);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
// Get context type by module
|
|
119
|
+
type AContext2 = InferContextBy<typeof moduleA> // same as above `AContext`
|
|
120
|
+
*/
|
|
121
|
+
export type InferContextBy<M> = M extends Module<infer Full, any> ? {
|
|
122
|
+
[K in keyof Full]: Full[K];
|
|
123
|
+
} : never;
|
|
104
124
|
/**
|
|
105
125
|
* Define a module with full context inferred from its dependency tuple.
|
|
106
126
|
*
|
|
@@ -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":"ad7ff3da49348197466e1ab9192dab71348ba1cdd4dc9b8651f395b124638399","signature":"f3ba15776feda5eea32b5d3bc2c88a6c52b95121c7bc273f817e6085cb438456"},{"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
|
@@ -101,6 +101,26 @@ export interface Module<S extends object, Sl extends object = S> {
|
|
|
101
101
|
/** Called immediately after this module's own shutdown(). */
|
|
102
102
|
afterShutdown?(ctx: ContextWriter<S, Sl>): Promise<void> | void;
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
|
|
106
|
+
type AContext = {
|
|
107
|
+
value: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const moduleA = defineModule<AContext>()({
|
|
111
|
+
name: "A",
|
|
112
|
+
modules: [] as const,
|
|
113
|
+
boot: () => ({ value: "module:A" }),
|
|
114
|
+
async shutdown(ctx) {
|
|
115
|
+
console.log(`shutdown ${ctx.value}`);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
// Get context type by module
|
|
119
|
+
type AContext2 = InferContextBy<typeof moduleA> // same as above `AContext`
|
|
120
|
+
*/
|
|
121
|
+
export type InferContextBy<M> = M extends Module<infer Full, any> ? {
|
|
122
|
+
[K in keyof Full]: Full[K];
|
|
123
|
+
} : never;
|
|
104
124
|
/**
|
|
105
125
|
* Define a module with full context inferred from its dependency tuple.
|
|
106
126
|
*
|
package/package.json
CHANGED