@shadow-library/fastify 0.0.5 → 0.0.6
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/cjs/module/fastify-router.d.ts +2 -2
- package/cjs/module/fastify-router.js +1 -1
- package/cjs/module/fastify.module.js +3 -2
- package/cjs/services/context.service.d.ts +1 -1
- package/cjs/services/context.service.js +5 -5
- package/esm/module/fastify-router.d.ts +2 -2
- package/esm/module/fastify-router.js +2 -2
- package/esm/module/fastify.module.js +3 -2
- package/esm/services/context.service.d.ts +1 -1
- package/esm/services/context.service.js +4 -4
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { type FastifyInstance } from 'fastify';
|
|
|
3
3
|
import { Chain as MockRequestChain, InjectOptions as MockRequestOptions, Response as MockResponse } from 'light-my-request';
|
|
4
4
|
import { JsonObject } from 'type-fest';
|
|
5
5
|
import { HttpRequest, HttpResponse, ServerMetadata } from '../interfaces/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { ContextService } from '../services/index.js';
|
|
7
7
|
import { type FastifyConfig } from './fastify-module.interface.js';
|
|
8
8
|
declare module 'fastify' {
|
|
9
9
|
interface FastifyRequest {
|
|
@@ -40,7 +40,7 @@ export declare class FastifyRouter extends Router {
|
|
|
40
40
|
private readonly instance;
|
|
41
41
|
private readonly context;
|
|
42
42
|
private readonly logger;
|
|
43
|
-
constructor(config: FastifyConfig, instance: FastifyInstance, context:
|
|
43
|
+
constructor(config: FastifyConfig, instance: FastifyInstance, context: ContextService);
|
|
44
44
|
getInstance(): FastifyInstance;
|
|
45
45
|
private registerRawBody;
|
|
46
46
|
private getRequestLogger;
|
|
@@ -212,5 +212,5 @@ exports.FastifyRouter = FastifyRouter = __decorate([
|
|
|
212
212
|
(0, app_1.Injectable)(),
|
|
213
213
|
__param(0, (0, app_1.Inject)(constants_1.FASTIFY_CONFIG)),
|
|
214
214
|
__param(1, (0, app_1.Inject)(constants_1.FASTIFY_INSTANCE)),
|
|
215
|
-
__metadata("design:paramtypes", [Object, Object, services_1.
|
|
215
|
+
__metadata("design:paramtypes", [Object, Object, services_1.ContextService])
|
|
216
216
|
], FastifyRouter);
|
|
@@ -7,6 +7,7 @@ const common_1 = require("@shadow-library/common");
|
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
8
8
|
const classes_1 = require("../classes/index.js");
|
|
9
9
|
const constants_1 = require("../constants.js");
|
|
10
|
+
const services_1 = require("../services/index.js");
|
|
10
11
|
const error_response_dto_1 = require("./error-response.dto.js");
|
|
11
12
|
const fastify_router_1 = require("./fastify-router.js");
|
|
12
13
|
const fastify_utils_1 = require("./fastify.utils.js");
|
|
@@ -30,11 +31,11 @@ class FastifyModule {
|
|
|
30
31
|
}
|
|
31
32
|
static forRootAsync(options) {
|
|
32
33
|
const imports = options.imports ?? [];
|
|
33
|
-
const providers = [{ token: app_1.Router, useClass: fastify_router_1.FastifyRouter }];
|
|
34
|
+
const providers = [{ token: app_1.Router, useClass: fastify_router_1.FastifyRouter }, services_1.ContextService];
|
|
34
35
|
providers.push({ token: constants_1.FASTIFY_CONFIG, useFactory: options.useFactory, inject: options.inject });
|
|
35
36
|
const fastifyFactory = (config) => (0, fastify_utils_1.createFastifyInstance)(config, options.fastifyFactory);
|
|
36
37
|
providers.push({ token: constants_1.FASTIFY_INSTANCE, useFactory: fastifyFactory, inject: [constants_1.FASTIFY_CONFIG] });
|
|
37
|
-
(0, app_1.Module)({ imports, providers, exports: [app_1.Router] })(FastifyModule);
|
|
38
|
+
(0, app_1.Module)({ imports, providers, exports: [app_1.Router, services_1.ContextService] })(FastifyModule);
|
|
38
39
|
return FastifyModule;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -6,14 +6,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.ContextService = void 0;
|
|
10
10
|
const async_hooks_1 = require("async_hooks");
|
|
11
11
|
const app_1 = require("@shadow-library/app");
|
|
12
12
|
const common_1 = require("@shadow-library/common");
|
|
13
13
|
const REQUEST = Symbol('request');
|
|
14
14
|
const RESPONSE = Symbol('response');
|
|
15
15
|
const RID = Symbol('rid');
|
|
16
|
-
let
|
|
16
|
+
let ContextService = class ContextService {
|
|
17
17
|
storage = new async_hooks_1.AsyncLocalStorage();
|
|
18
18
|
init() {
|
|
19
19
|
return async (req, res) => {
|
|
@@ -51,7 +51,7 @@ let Context = class Context {
|
|
|
51
51
|
return this.get(RID, true);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
54
|
+
exports.ContextService = ContextService;
|
|
55
|
+
exports.ContextService = ContextService = __decorate([
|
|
56
56
|
(0, app_1.Injectable)()
|
|
57
|
-
],
|
|
57
|
+
], ContextService);
|
|
@@ -3,7 +3,7 @@ import { type FastifyInstance } from 'fastify';
|
|
|
3
3
|
import { Chain as MockRequestChain, InjectOptions as MockRequestOptions, Response as MockResponse } from 'light-my-request';
|
|
4
4
|
import { JsonObject } from 'type-fest';
|
|
5
5
|
import { HttpRequest, HttpResponse, ServerMetadata } from '../interfaces/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { ContextService } from '../services/index.js';
|
|
7
7
|
import { type FastifyConfig } from './fastify-module.interface.js';
|
|
8
8
|
declare module 'fastify' {
|
|
9
9
|
interface FastifyRequest {
|
|
@@ -40,7 +40,7 @@ export declare class FastifyRouter extends Router {
|
|
|
40
40
|
private readonly instance;
|
|
41
41
|
private readonly context;
|
|
42
42
|
private readonly logger;
|
|
43
|
-
constructor(config: FastifyConfig, instance: FastifyInstance, context:
|
|
43
|
+
constructor(config: FastifyConfig, instance: FastifyInstance, context: ContextService);
|
|
44
44
|
getInstance(): FastifyInstance;
|
|
45
45
|
private registerRawBody;
|
|
46
46
|
private getRequestLogger;
|
|
@@ -16,7 +16,7 @@ import { InternalError, Logger, utils } from '@shadow-library/common';
|
|
|
16
16
|
import merge from 'deepmerge';
|
|
17
17
|
import { FASTIFY_CONFIG, FASTIFY_INSTANCE, HTTP_CONTROLLER_INPUTS, HTTP_CONTROLLER_TYPE, NAMESPACE } from '../constants.js';
|
|
18
18
|
import { HttpMethod } from '../decorators/index.js';
|
|
19
|
-
import {
|
|
19
|
+
import { ContextService } from '../services/index.js';
|
|
20
20
|
const httpMethods = Object.values(HttpMethod).filter(m => m !== HttpMethod.ALL);
|
|
21
21
|
let FastifyRouter = class FastifyRouter extends Router {
|
|
22
22
|
config;
|
|
@@ -205,6 +205,6 @@ FastifyRouter = __decorate([
|
|
|
205
205
|
Injectable(),
|
|
206
206
|
__param(0, Inject(FASTIFY_CONFIG)),
|
|
207
207
|
__param(1, Inject(FASTIFY_INSTANCE)),
|
|
208
|
-
__metadata("design:paramtypes", [Object, Object,
|
|
208
|
+
__metadata("design:paramtypes", [Object, Object, ContextService])
|
|
209
209
|
], FastifyRouter);
|
|
210
210
|
export { FastifyRouter };
|
|
@@ -4,6 +4,7 @@ import { utils } from '@shadow-library/common';
|
|
|
4
4
|
import { v4 as uuid } from 'uuid';
|
|
5
5
|
import { DefaultErrorHandler } from '../classes/index.js';
|
|
6
6
|
import { FASTIFY_CONFIG, FASTIFY_INSTANCE } from '../constants.js';
|
|
7
|
+
import { ContextService } from '../services/index.js';
|
|
7
8
|
import { ErrorResponseDto } from './error-response.dto.js';
|
|
8
9
|
import { FastifyRouter } from './fastify-router.js';
|
|
9
10
|
import { createFastifyInstance } from './fastify.utils.js';
|
|
@@ -27,11 +28,11 @@ export class FastifyModule {
|
|
|
27
28
|
}
|
|
28
29
|
static forRootAsync(options) {
|
|
29
30
|
const imports = options.imports ?? [];
|
|
30
|
-
const providers = [{ token: Router, useClass: FastifyRouter }];
|
|
31
|
+
const providers = [{ token: Router, useClass: FastifyRouter }, ContextService];
|
|
31
32
|
providers.push({ token: FASTIFY_CONFIG, useFactory: options.useFactory, inject: options.inject });
|
|
32
33
|
const fastifyFactory = (config) => createFastifyInstance(config, options.fastifyFactory);
|
|
33
34
|
providers.push({ token: FASTIFY_INSTANCE, useFactory: fastifyFactory, inject: [FASTIFY_CONFIG] });
|
|
34
|
-
Module({ imports, providers, exports: [Router] })(FastifyModule);
|
|
35
|
+
Module({ imports, providers, exports: [Router, ContextService] })(FastifyModule);
|
|
35
36
|
return FastifyModule;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -10,7 +10,7 @@ import { InternalError } from '@shadow-library/common';
|
|
|
10
10
|
const REQUEST = Symbol('request');
|
|
11
11
|
const RESPONSE = Symbol('response');
|
|
12
12
|
const RID = Symbol('rid');
|
|
13
|
-
let
|
|
13
|
+
let ContextService = class ContextService {
|
|
14
14
|
storage = new AsyncLocalStorage();
|
|
15
15
|
init() {
|
|
16
16
|
return async (req, res) => {
|
|
@@ -48,7 +48,7 @@ let Context = class Context {
|
|
|
48
48
|
return this.get(RID, true);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
ContextService = __decorate([
|
|
52
52
|
Injectable()
|
|
53
|
-
],
|
|
54
|
-
export {
|
|
53
|
+
], ContextService);
|
|
54
|
+
export { ContextService };
|
package/package.json
CHANGED