@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/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 { DynamicModule, Global, Provider } from '@nestjs/common'
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
- export class KeqModule extends ConfigurableModuleClass {
61
- /**
62
- * Register the module with synchronous options
63
- * @param options - Configuration options including middlewares
64
- * @returns DynamicModule with KeqRequest provider
65
- */
66
- static register(options: typeof OPTIONS_TYPE): DynamicModule {
67
- const mo = super.register(options)
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()
@@ -1 +0,0 @@
1
- export * from './keq-module-options.js'