@keq-request/nestjs 5.0.0-beta.8 → 5.0.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/.turbo/turbo-build.log +19 -19
- package/CHANGELOG.md +140 -0
- package/__tests__/keq-module.spec.ts +203 -0
- package/dist/index.d.mts +99 -50
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +99 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +206 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -39
- package/dist/index.mjs.map +1 -1
- package/jest.config.cts +12 -2
- package/package.json +11 -3
- package/src/constants.ts +3 -0
- package/src/decorators/inject-keq-consumer.decorator.ts +26 -0
- package/src/index.ts +5 -1
- package/src/interfaces/index.ts +9 -0
- package/src/interfaces/keq-middleware-consumer.interface.ts +30 -0
- package/src/{types/keq-module-options.ts → interfaces/keq-module-options.interface.ts} +2 -1
- package/src/interfaces/keq-nest-middleware.interface.ts +6 -0
- package/src/keq-consumer.ts +34 -0
- package/src/keq-middleware-collector.ts +150 -0
- package/src/keq-middleware-consumer.ts +33 -0
- package/src/keq.module.ts +10 -83
- package/src/keq.module-definition.ts +0 -11
- package/src/types/index.ts +0 -1
package/src/keq.module.ts
CHANGED
|
@@ -1,87 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { Global, Module } from '@nestjs/common'
|
|
2
2
|
import { KeqRequest } from 'keq'
|
|
3
|
-
import {
|
|
4
|
-
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE } from './keq.module-definition.js'
|
|
5
|
-
import { KeqModuleOptions } from './types/index.js'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Provider that creates and configures a KeqRequest instance
|
|
10
|
-
* Applies any middlewares defined in the module options
|
|
11
|
-
*/
|
|
12
|
-
const requestProvider: Provider = {
|
|
13
|
-
provide: KeqRequest,
|
|
14
|
-
useFactory: (config: KeqModuleOptions) => {
|
|
15
|
-
const request = new KeqRequest()
|
|
16
|
-
|
|
17
|
-
if (config.middlewares) {
|
|
18
|
-
for (const middleware of config.middlewares) {
|
|
19
|
-
request.use(middleware)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
3
|
+
import { KeqMiddlewareConsumer } from './keq-middleware-consumer.js'
|
|
22
4
|
|
|
23
|
-
return request
|
|
24
|
-
},
|
|
25
|
-
inject: [MODULE_OPTIONS_TOKEN],
|
|
26
|
-
}
|
|
27
5
|
|
|
28
|
-
/**
|
|
29
|
-
* KeqModule - Dynamic module for integrating Keq HTTP client with NestJS
|
|
30
|
-
*
|
|
31
|
-
* This module is global, so KeqRequest can be injected anywhere in your application
|
|
32
|
-
* without needing to import the module in every feature module.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // Synchronous registration
|
|
37
|
-
* KeqModule.register({
|
|
38
|
-
* middlewares: [...]
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* // Asynchronous registration
|
|
42
|
-
* KeqModule.registerAsync({
|
|
43
|
-
* imports: [ConfigModule],
|
|
44
|
-
* useFactory: (config: ConfigService) => ({
|
|
45
|
-
* middlewares: [...]
|
|
46
|
-
* }),
|
|
47
|
-
* inject: [ConfigService]
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* // Inject in service
|
|
51
|
-
* class UserService {
|
|
52
|
-
* constructor(private readonly keqRequest: KeqRequest) {}
|
|
53
|
-
* async getUser(id: string) {
|
|
54
|
-
* return await this.keqRequest.get(`/users/${id}`).resolveWith('json')
|
|
55
|
-
* }
|
|
56
|
-
* }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
6
|
@Global()
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
mo.providers!.push(requestProvider)
|
|
69
|
-
mo.global = true
|
|
70
|
-
|
|
71
|
-
return mo
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Register the module with asynchronous options
|
|
76
|
-
* Useful when you need to inject dependencies like ConfigService
|
|
77
|
-
* @param options - Async configuration options
|
|
78
|
-
* @returns DynamicModule with KeqRequest provider
|
|
79
|
-
*/
|
|
80
|
-
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {
|
|
81
|
-
const mo = super.registerAsync(options)
|
|
82
|
-
mo.providers!.push(requestProvider)
|
|
83
|
-
mo.global = true
|
|
84
|
-
|
|
85
|
-
return mo
|
|
86
|
-
}
|
|
87
|
-
}
|
|
7
|
+
@Module({
|
|
8
|
+
providers: [
|
|
9
|
+
{ provide: KeqRequest, useFactory: () => new KeqRequest() },
|
|
10
|
+
KeqMiddlewareConsumer,
|
|
11
|
+
],
|
|
12
|
+
exports: [KeqRequest, KeqMiddlewareConsumer],
|
|
13
|
+
})
|
|
14
|
+
export class KeqModule {}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ConfigurableModuleBuilder } from '@nestjs/common'
|
|
3
|
-
import { KeqModuleOptions } from './types/keq-module-options'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const {
|
|
7
|
-
ConfigurableModuleClass,
|
|
8
|
-
MODULE_OPTIONS_TOKEN,
|
|
9
|
-
OPTIONS_TYPE,
|
|
10
|
-
ASYNC_OPTIONS_TYPE,
|
|
11
|
-
} = new ConfigurableModuleBuilder<KeqModuleOptions>().build()
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './keq-module-options.js'
|