@dooboostore/simple-boot-http-server 1.0.14

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.
Files changed (74) hide show
  1. package/README.MD +269 -0
  2. package/SimpleBootHttpServer.d.ts +16 -0
  3. package/SimpleBootHttpServer.js +313 -0
  4. package/codes/HttpHeaders.d.ts +42 -0
  5. package/codes/HttpHeaders.js +43 -0
  6. package/codes/HttpMethod.d.ts +12 -0
  7. package/codes/HttpMethod.js +13 -0
  8. package/codes/HttpStatus.d.ts +20 -0
  9. package/codes/HttpStatus.js +21 -0
  10. package/codes/Mimes.d.ts +28 -0
  11. package/codes/Mimes.js +29 -0
  12. package/decorators/MethodMapping.d.ts +74 -0
  13. package/decorators/MethodMapping.js +198 -0
  14. package/endpoints/CrossDomainHeaderEndPoint.d.ts +16 -0
  15. package/endpoints/CrossDomainHeaderEndPoint.js +37 -0
  16. package/endpoints/EndPoint.d.ts +7 -0
  17. package/endpoints/EndPoint.js +2 -0
  18. package/endpoints/HeaderEndPoint.d.ts +12 -0
  19. package/endpoints/HeaderEndPoint.js +26 -0
  20. package/errors/BadRequestError.d.ts +8 -0
  21. package/errors/BadRequestError.js +8 -0
  22. package/errors/ForbiddenError.d.ts +8 -0
  23. package/errors/ForbiddenError.js +8 -0
  24. package/errors/HttpError.d.ts +12 -0
  25. package/errors/HttpError.js +8 -0
  26. package/errors/InternalServerError.d.ts +8 -0
  27. package/errors/InternalServerError.js +8 -0
  28. package/errors/NotFoundError.d.ts +8 -0
  29. package/errors/NotFoundError.js +8 -0
  30. package/errors/UnauthorizedError.d.ts +8 -0
  31. package/errors/UnauthorizedError.js +8 -0
  32. package/filters/CacheFilter.d.ts +45 -0
  33. package/filters/CacheFilter.js +145 -0
  34. package/filters/Filter.d.ts +17 -0
  35. package/filters/Filter.js +2 -0
  36. package/filters/HttpStatusFilter.d.ts +20 -0
  37. package/filters/HttpStatusFilter.js +31 -0
  38. package/filters/OpenApi3Filter.d.ts +142 -0
  39. package/filters/OpenApi3Filter.js +57 -0
  40. package/filters/ResourceFilter.d.ts +24 -0
  41. package/filters/ResourceFilter.js +72 -0
  42. package/filters/ThrowFilter.d.ts +19 -0
  43. package/filters/ThrowFilter.js +34 -0
  44. package/inject/InjectSituationType.d.ts +4 -0
  45. package/inject/InjectSituationType.js +5 -0
  46. package/lifecycle/OnInit.d.ts +5 -0
  47. package/lifecycle/OnInit.js +2 -0
  48. package/models/RequestResponse.d.ts +107 -0
  49. package/models/RequestResponse.js +467 -0
  50. package/models/datas/HeaderData.d.ts +10 -0
  51. package/models/datas/HeaderData.js +7 -0
  52. package/models/datas/MultipartData.d.ts +14 -0
  53. package/models/datas/MultipartData.js +2 -0
  54. package/models/datas/ReqHeader.d.ts +69 -0
  55. package/models/datas/ReqHeader.js +3 -0
  56. package/models/datas/Resource.d.ts +11 -0
  57. package/models/datas/Resource.js +55 -0
  58. package/models/datas/body/ReqFormUrlBody.d.ts +4 -0
  59. package/models/datas/body/ReqFormUrlBody.js +3 -0
  60. package/models/datas/body/ReqJsonBody.d.ts +4 -0
  61. package/models/datas/body/ReqJsonBody.js +3 -0
  62. package/models/datas/body/ReqMultipartFormBody.d.ts +6 -0
  63. package/models/datas/body/ReqMultipartFormBody.js +6 -0
  64. package/models/method/patch/PatchJson.d.ts +8 -0
  65. package/models/method/patch/PatchJson.js +11 -0
  66. package/option/HttpServerOption.d.ts +85 -0
  67. package/option/HttpServerOption.js +35 -0
  68. package/package.json +83 -0
  69. package/resolvers/Resolver.d.ts +5 -0
  70. package/resolvers/Resolver.js +2 -0
  71. package/resolvers/ResourceResorver.d.ts +6 -0
  72. package/resolvers/ResourceResorver.js +18 -0
  73. package/session/SessionManager.d.ts +57 -0
  74. package/session/SessionManager.js +108 -0
@@ -0,0 +1,8 @@
1
+ import { HttpError } from './HttpError';
2
+ import { HttpStatus } from '../codes/HttpStatus';
3
+ export class NotFoundError extends HttpError {
4
+ constructor({ status = HttpStatus.NotFound, message = 'Not Found' } = {}) {
5
+ super({ status, message });
6
+ }
7
+ }
8
+ //# sourceMappingURL=NotFoundError.js.map
@@ -0,0 +1,8 @@
1
+ import { HttpError } from './HttpError';
2
+ export declare class UnauthorizedError extends HttpError {
3
+ constructor({ status, message }?: {
4
+ status?: number;
5
+ message?: string;
6
+ });
7
+ }
8
+ //# sourceMappingURL=UnauthorizedError.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { HttpError } from './HttpError';
2
+ import { HttpStatus } from '../codes/HttpStatus';
3
+ export class UnauthorizedError extends HttpError {
4
+ constructor({ status = HttpStatus.Unauthorized, message = 'Unauthorized' } = {}) {
5
+ super({ status, message });
6
+ }
7
+ }
8
+ //# sourceMappingURL=UnauthorizedError.js.map
@@ -0,0 +1,45 @@
1
+ import { Filter } from '../filters/Filter';
2
+ import { RequestResponse } from '../models/RequestResponse';
3
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
4
+ export type CacheFilterSessionType = {
5
+ key: string;
6
+ lifeTime: number;
7
+ isUpdate: boolean;
8
+ responseHeaders?: string[];
9
+ };
10
+ type KeyAndConfig = {
11
+ key: string;
12
+ lifeTime?: number;
13
+ responseHeaders?: string[];
14
+ };
15
+ export declare class CacheFilter implements Filter {
16
+ private config;
17
+ static readonly CARRIER_KEY_NAME = "_CARRIER_CACHE_FILTER_KEY_NAME";
18
+ private storage;
19
+ private cacheConfig;
20
+ constructor(config: {
21
+ config: {
22
+ cacheDir?: string;
23
+ lifeTime: number;
24
+ startUpClean?: boolean;
25
+ };
26
+ filter?: (rr: RequestResponse, app: SimpleBootHttpServer) => boolean;
27
+ key: (rr: RequestResponse, app: SimpleBootHttpServer) => KeyAndConfig;
28
+ });
29
+ onInit(app: SimpleBootHttpServer): Promise<void>;
30
+ proceedBefore({ rr, app, carrier }: {
31
+ rr: RequestResponse;
32
+ app: SimpleBootHttpServer;
33
+ carrier: Map<string, any>;
34
+ }): Promise<boolean>;
35
+ private deleteChunk;
36
+ private getChunk;
37
+ proceedAfter({ rr, app, carrier }: {
38
+ rr: RequestResponse;
39
+ app: SimpleBootHttpServer;
40
+ carrier: Map<string, any>;
41
+ }): Promise<boolean>;
42
+ private writeChunk;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=CacheFilter.d.ts.map
@@ -0,0 +1,145 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { FileUtils } from '@dooboostore/core-node/file/FileUtils';
11
+ import { ConvertUtils } from '@dooboostore/core-node/convert/ConvertUtils';
12
+ import { RandomUtils } from '@dooboostore/core/random/RandomUtils';
13
+ export class CacheFilter {
14
+ constructor(config) {
15
+ this.config = config;
16
+ this.storage = new Map();
17
+ if (config.config.cacheDir && config.config.startUpClean) {
18
+ FileUtils.deleteSync(config.config.cacheDir, { options: { recursive: true } });
19
+ }
20
+ }
21
+ onInit(app) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ });
24
+ }
25
+ proceedBefore({ rr, app, carrier }) {
26
+ var _a, _b, _c, _d, _e, _f, _g;
27
+ var _h, _j, _k;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const filter = (_b = (_a = this.config).filter) === null || _b === void 0 ? void 0 : _b.call(_a, rr, app);
30
+ if (!filter) {
31
+ return true;
32
+ }
33
+ if (this.config.config.cacheDir) {
34
+ FileUtils.mkdirSync(this.config.config.cacheDir, { recursive: true });
35
+ }
36
+ if (!this.cacheConfig && this.config.config.cacheDir) {
37
+ try {
38
+ this.cacheConfig = JSON.parse(ConvertUtils.toString(FileUtils.readSync([this.config.config.cacheDir, 'cacheConfig.json'], { option: { encoding: 'utf-8' } })));
39
+ }
40
+ catch (e) {
41
+ }
42
+ }
43
+ const date = new Date().toISOString();
44
+ (_c = this.cacheConfig) !== null && _c !== void 0 ? _c : (this.cacheConfig = {
45
+ createDate: date,
46
+ updateDate: date,
47
+ caches: {}
48
+ });
49
+ (_d = (_h = this.cacheConfig).createDate) !== null && _d !== void 0 ? _d : (_h.createDate = date);
50
+ (_e = (_j = this.cacheConfig).updateDate) !== null && _e !== void 0 ? _e : (_j.updateDate = date);
51
+ (_f = (_k = this.cacheConfig).caches) !== null && _f !== void 0 ? _f : (_k.caches = {});
52
+ const rkey = this.config.key(rr, app);
53
+ const sessionData = { key: rkey.key, lifeTime: (_g = rkey.lifeTime) !== null && _g !== void 0 ? _g : this.config.config.lifeTime, isUpdate: false, responseHeaders: rkey.responseHeaders };
54
+ const cache = this.cacheConfig.caches[sessionData.key];
55
+ if (cache) {
56
+ const existes = this.config.config.cacheDir ? FileUtils.existesSync(cache.path) : this.storage.has(cache.path);
57
+ const diffTime = Date.now() - cache.createTime;
58
+ if (!existes || diffTime > cache.lifeTime) {
59
+ delete this.cacheConfig[sessionData.key];
60
+ this.deleteChunk(cache.path);
61
+ sessionData.isUpdate = true;
62
+ }
63
+ else {
64
+ rr.resSetHeaders(Object.assign(Object.assign({}, cache.responseHeader), { cacheFilter: `true;remainTime=${cache.lifeTime - diffTime}` }));
65
+ try {
66
+ const chunk = this.getChunk(cache.path);
67
+ yield rr.resEnd(chunk);
68
+ }
69
+ catch (e) {
70
+ console.log('--------e', e);
71
+ }
72
+ }
73
+ }
74
+ else {
75
+ sessionData.isUpdate = true;
76
+ }
77
+ carrier.set(CacheFilter.CARRIER_KEY_NAME, sessionData);
78
+ return sessionData.isUpdate;
79
+ });
80
+ }
81
+ deleteChunk(path) {
82
+ if (this.config.config.cacheDir && FileUtils.existesSync(path)) {
83
+ FileUtils.deleteFileSync(path);
84
+ }
85
+ else if (this.storage.has(path)) {
86
+ this.storage.delete(path);
87
+ }
88
+ }
89
+ getChunk(path) {
90
+ return this.config.config.cacheDir ? FileUtils.readSync(path) : this.storage.get(path);
91
+ }
92
+ proceedAfter({ rr, app, carrier }) {
93
+ var _a, _b;
94
+ var _c;
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const sessionData = carrier.get(CacheFilter.CARRIER_KEY_NAME);
97
+ if (sessionData && sessionData.isUpdate) {
98
+ try {
99
+ if (this.config.config.cacheDir) {
100
+ FileUtils.mkdirSync([this.config.config.cacheDir, 'caches'], { recursive: true });
101
+ }
102
+ const resBody = rr.resBodyData();
103
+ if (!resBody) {
104
+ return true;
105
+ }
106
+ let p = undefined;
107
+ const destFileUUID = RandomUtils.uuid4();
108
+ p = this.writeChunk(destFileUUID, resBody);
109
+ const updateDateNow = Date.now();
110
+ const updateDate = new Date(updateDateNow).toISOString();
111
+ (_a = (_c = this.cacheConfig).createDate) !== null && _a !== void 0 ? _a : (_c.createDate = updateDate);
112
+ this.cacheConfig.updateDate = updateDate;
113
+ const responseHeaders = {};
114
+ (_b = sessionData.responseHeaders) === null || _b === void 0 ? void 0 : _b.map(it => it.toLowerCase()).forEach(it => {
115
+ responseHeaders[it] = rr.resHeader(it);
116
+ });
117
+ this.cacheConfig.caches[sessionData.key] = {
118
+ path: p,
119
+ createTime: updateDateNow,
120
+ lifeTime: sessionData.lifeTime,
121
+ responseHeader: responseHeaders
122
+ };
123
+ if (this.config.config.cacheDir) {
124
+ FileUtils.write(JSON.stringify(this.cacheConfig), { path: [this.config.config.cacheDir, 'cacheConfig.json'] });
125
+ }
126
+ }
127
+ catch (e) {
128
+ console.log('---', e);
129
+ }
130
+ }
131
+ return true;
132
+ });
133
+ }
134
+ writeChunk(destFileUUID, resBody) {
135
+ if (this.config.config.cacheDir) {
136
+ return FileUtils.write(resBody, { path: [this.config.config.cacheDir, 'caches', destFileUUID] });
137
+ }
138
+ else {
139
+ this.storage.set(destFileUUID, resBody);
140
+ return destFileUUID;
141
+ }
142
+ }
143
+ }
144
+ CacheFilter.CARRIER_KEY_NAME = '_CARRIER_CACHE_FILTER_KEY_NAME';
145
+ //# sourceMappingURL=CacheFilter.js.map
@@ -0,0 +1,17 @@
1
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
2
+ import { RequestResponse } from '../models/RequestResponse';
3
+ import { OnInit } from '../lifecycle/OnInit';
4
+ export interface Filter extends OnInit {
5
+ proceedBefore(data: {
6
+ rr: RequestResponse;
7
+ app: SimpleBootHttpServer;
8
+ carrier: Map<string, any>;
9
+ }): Promise<boolean>;
10
+ proceedAfter(data: {
11
+ rr: RequestResponse;
12
+ app: SimpleBootHttpServer;
13
+ before: boolean;
14
+ carrier: Map<string, any>;
15
+ }): Promise<boolean>;
16
+ }
17
+ //# sourceMappingURL=Filter.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Filter.js.map
@@ -0,0 +1,20 @@
1
+ import { Filter } from '../filters/Filter';
2
+ import { HttpStatus } from '../codes/HttpStatus';
3
+ import { RequestResponse } from '../models/RequestResponse';
4
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
5
+ export declare class HttpStatusFilter implements Filter {
6
+ private httpStatus;
7
+ constructor(httpStatus: HttpStatus | number);
8
+ proceedBefore({ rr, app }: {
9
+ rr: RequestResponse;
10
+ app: SimpleBootHttpServer;
11
+ carrier: Map<string, any>;
12
+ }): Promise<boolean>;
13
+ proceedAfter({ rr, app }: {
14
+ rr: RequestResponse;
15
+ app: SimpleBootHttpServer;
16
+ carrier: Map<string, any>;
17
+ }): Promise<boolean>;
18
+ onInit(app: SimpleBootHttpServer): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=HttpStatusFilter.d.ts.map
@@ -0,0 +1,31 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class HttpStatusFilter {
11
+ constructor(httpStatus) {
12
+ this.httpStatus = httpStatus;
13
+ }
14
+ proceedBefore({ rr, app }) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ rr.resStatusCode(this.httpStatus);
17
+ rr.resEnd();
18
+ return false;
19
+ });
20
+ }
21
+ proceedAfter({ rr, app }) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return true;
24
+ });
25
+ }
26
+ onInit(app) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ });
29
+ }
30
+ }
31
+ //# sourceMappingURL=HttpStatusFilter.js.map
@@ -0,0 +1,142 @@
1
+ import { Filter } from './Filter';
2
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
3
+ import { RequestResponse } from '../models/RequestResponse';
4
+ type MethodType = {
5
+ summary?: string;
6
+ description?: string;
7
+ operationId?: string;
8
+ parameters?: {
9
+ name: string;
10
+ in: string;
11
+ required: boolean;
12
+ schema: {
13
+ type: string;
14
+ format?: string;
15
+ items?: {
16
+ type: string;
17
+ format?: string;
18
+ };
19
+ };
20
+ }[];
21
+ responses: {
22
+ [code: string]: {
23
+ description: string;
24
+ content?: {
25
+ [type: string]: {
26
+ schema: {
27
+ type: string;
28
+ format?: string;
29
+ items?: {
30
+ type: string;
31
+ format?: string;
32
+ };
33
+ };
34
+ };
35
+ };
36
+ };
37
+ };
38
+ };
39
+ type PathType = {
40
+ [method: string]: MethodType;
41
+ };
42
+ type PathsType = {
43
+ [path: string]: PathType;
44
+ };
45
+ export type OpenApiType = {
46
+ openapi: string;
47
+ info?: {
48
+ title?: string;
49
+ description?: string;
50
+ contact?: {
51
+ name?: string;
52
+ email?: string;
53
+ };
54
+ };
55
+ servers?: {
56
+ url: string;
57
+ }[];
58
+ paths?: PathsType;
59
+ components?: {
60
+ schemas?: {
61
+ [key: string]: {
62
+ type: string;
63
+ required?: string[];
64
+ properties?: {
65
+ [key: string]: {
66
+ type: string;
67
+ format?: string;
68
+ items?: {
69
+ type: string;
70
+ format?: string;
71
+ };
72
+ };
73
+ };
74
+ };
75
+ };
76
+ securitySchemes?: {
77
+ [key: string]: {
78
+ type: string;
79
+ description?: string;
80
+ in?: string;
81
+ name?: string;
82
+ scheme?: string;
83
+ bearerFormat?: string;
84
+ flows?: {
85
+ [key: string]: {
86
+ authorizationUrl?: string;
87
+ tokenUrl?: string;
88
+ refreshUrl?: string;
89
+ scopes?: {
90
+ [key: string]: {
91
+ description?: string;
92
+ };
93
+ };
94
+ };
95
+ };
96
+ };
97
+ };
98
+ };
99
+ };
100
+ export type OpenApi3FilterConfig = {
101
+ info?: {
102
+ title?: string;
103
+ description?: string;
104
+ contact?: {
105
+ name?: string;
106
+ email?: string;
107
+ };
108
+ };
109
+ servers?: {
110
+ url: string;
111
+ }[];
112
+ };
113
+ export declare class OpenApi3Filter implements Filter {
114
+ config: {
115
+ path: string;
116
+ excludePath?: {
117
+ method: string;
118
+ path: string;
119
+ }[];
120
+ };
121
+ private openApiConfig;
122
+ constructor(config: {
123
+ path: string;
124
+ excludePath?: {
125
+ method: string;
126
+ path: string;
127
+ }[];
128
+ }, openApiConfig?: OpenApi3FilterConfig);
129
+ onInit(app: SimpleBootHttpServer): Promise<void>;
130
+ proceedBefore({ rr, app }: {
131
+ rr: RequestResponse;
132
+ app: SimpleBootHttpServer;
133
+ carrier: Map<string, any>;
134
+ }): Promise<boolean>;
135
+ proceedAfter({ rr, app }: {
136
+ rr: RequestResponse;
137
+ app: SimpleBootHttpServer;
138
+ carrier: Map<string, any>;
139
+ }): Promise<boolean>;
140
+ }
141
+ export {};
142
+ //# sourceMappingURL=OpenApi3Filter.d.ts.map
@@ -0,0 +1,57 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { HttpStatus } from '../codes/HttpStatus';
11
+ import { getUrlMappings } from '../decorators/MethodMapping';
12
+ const DefulatData = {
13
+ openapi: '3.0.1',
14
+ info: {
15
+ title: 'SimpleBootHttpServer OpenApi3',
16
+ description: 'SimpleBootHttpServer OpenApi3',
17
+ }
18
+ };
19
+ export class OpenApi3Filter {
20
+ constructor(config, openApiConfig) {
21
+ this.config = config;
22
+ this.openApiConfig = Object.assign(Object.assign({}, DefulatData), openApiConfig !== null && openApiConfig !== void 0 ? openApiConfig : {});
23
+ }
24
+ onInit(app) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ });
27
+ }
28
+ proceedBefore({ rr, app }) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ if (rr.reqUrl === this.config.path) {
31
+ const map = app.routerManager.routingMap();
32
+ const data = {
33
+ paths: {}
34
+ };
35
+ Object.entries(map).filter(([k, v]) => typeof v !== 'string').forEach(([k, v]) => {
36
+ var _a;
37
+ const method = data.paths[k] = {};
38
+ (_a = getUrlMappings(v)) === null || _a === void 0 ? void 0 : _a.forEach(it => {
39
+ method[it.config.method] = {
40
+ summary: it.propertyKey,
41
+ description: it.propertyKey
42
+ };
43
+ });
44
+ });
45
+ rr.resWriteJson(Object.assign(Object.assign({}, this.openApiConfig), data)).resStatusCode(HttpStatus.Ok).resEnd();
46
+ return false;
47
+ }
48
+ return true;
49
+ });
50
+ }
51
+ proceedAfter({ rr, app }) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return true;
54
+ });
55
+ }
56
+ }
57
+ //# sourceMappingURL=OpenApi3Filter.js.map
@@ -0,0 +1,24 @@
1
+ import { Filter } from '../filters/Filter';
2
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
3
+ import { RequestResponse } from '../models/RequestResponse';
4
+ export type RequestFilterType = string | RegExp | ((rr: RequestResponse, app: SimpleBootHttpServer) => boolean) | ((rr: RequestResponse, app: SimpleBootHttpServer) => Promise<boolean>);
5
+ export declare class ResourceFilter implements Filter {
6
+ private resourceDistPath;
7
+ private resourceRegex;
8
+ constructor(resourceDistPath: string, resourceRegex?: (RequestFilterType | {
9
+ request: RequestFilterType;
10
+ dist: string;
11
+ })[]);
12
+ onInit(app: SimpleBootHttpServer): Promise<void>;
13
+ proceedBefore({ rr, app }: {
14
+ rr: RequestResponse;
15
+ app: SimpleBootHttpServer;
16
+ carrier: Map<string, any>;
17
+ }): Promise<boolean>;
18
+ proceedAfter({ rr, app }: {
19
+ rr: RequestResponse;
20
+ app: SimpleBootHttpServer;
21
+ carrier: Map<string, any>;
22
+ }): Promise<boolean>;
23
+ }
24
+ //# sourceMappingURL=ResourceFilter.d.ts.map
@@ -0,0 +1,72 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fs from 'fs';
11
+ import path from 'path';
12
+ import mime from 'mime-types';
13
+ import { HttpHeaders } from '../codes/HttpHeaders';
14
+ import { HttpStatus } from '../codes/HttpStatus';
15
+ export class ResourceFilter {
16
+ constructor(resourceDistPath, resourceRegex = []) {
17
+ this.resourceDistPath = resourceDistPath;
18
+ this.resourceRegex = resourceRegex;
19
+ }
20
+ onInit(app) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ });
23
+ }
24
+ proceedBefore({ rr, app }) {
25
+ var _a;
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const url = ((_a = rr.reqUrlPathName) !== null && _a !== void 0 ? _a : '').replace(/\.\./g, '');
28
+ const urlObj = rr.reqUrlObject;
29
+ let sw = true;
30
+ const regExps = this.resourceRegex.filter(it => {
31
+ if (it instanceof RegExp) {
32
+ return it.test(url);
33
+ }
34
+ if (typeof it === 'string') {
35
+ return RegExp(it).test(url);
36
+ }
37
+ if (typeof it === 'function') {
38
+ return it(rr, app);
39
+ }
40
+ if (typeof it === 'object' && 'request' in it) {
41
+ if (typeof it.request === 'function') {
42
+ return it.request(rr, app);
43
+ }
44
+ return RegExp(it.request).test(url);
45
+ }
46
+ });
47
+ for (const it of regExps) {
48
+ const resourcePath = path.join(this.resourceDistPath, typeof it === 'object' && 'dist' in it ? it.dist : urlObj.pathname);
49
+ sw = false;
50
+ if (fs.existsSync(resourcePath)) {
51
+ rr.resStatusCode(HttpStatus.Ok);
52
+ rr.resSetHeader(HttpHeaders.ContentType, mime.lookup(resourcePath).toString());
53
+ yield rr.resEnd(fs.readFileSync(resourcePath));
54
+ break;
55
+ }
56
+ else {
57
+ rr.resStatusCode(HttpStatus.NotFound);
58
+ yield rr.resEnd();
59
+ break;
60
+ }
61
+ sw = false;
62
+ }
63
+ return sw;
64
+ });
65
+ }
66
+ proceedAfter({ rr, app }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ return true;
69
+ });
70
+ }
71
+ }
72
+ //# sourceMappingURL=ResourceFilter.js.map
@@ -0,0 +1,19 @@
1
+ import { Filter } from '../filters/Filter';
2
+ import { RequestResponse } from '../models/RequestResponse';
3
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
4
+ export declare class ThrowFilter implements Filter {
5
+ private error;
6
+ constructor(error: any);
7
+ onInit(app: SimpleBootHttpServer): Promise<void>;
8
+ proceedBefore({ rr, app }: {
9
+ rr: RequestResponse;
10
+ app: SimpleBootHttpServer;
11
+ carrier: Map<string, any>;
12
+ }): Promise<boolean>;
13
+ proceedAfter({ rr, app }: {
14
+ rr: RequestResponse;
15
+ app: SimpleBootHttpServer;
16
+ carrier: Map<string, any>;
17
+ }): Promise<boolean>;
18
+ }
19
+ //# sourceMappingURL=ThrowFilter.d.ts.map
@@ -0,0 +1,34 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class ThrowFilter {
11
+ constructor(error) {
12
+ this.error = error;
13
+ }
14
+ onInit(app) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ });
17
+ }
18
+ proceedBefore({ rr, app }) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return true;
21
+ });
22
+ }
23
+ proceedAfter({ rr, app }) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const sw = rr.resIsDone();
26
+ if (!sw) {
27
+ throw this.error;
28
+ }
29
+ ;
30
+ return false;
31
+ });
32
+ }
33
+ }
34
+ //# sourceMappingURL=ThrowFilter.js.map
@@ -0,0 +1,4 @@
1
+ export declare namespace InjectSituationType {
2
+ const TransactionManager: unique symbol;
3
+ }
4
+ //# sourceMappingURL=InjectSituationType.d.ts.map
@@ -0,0 +1,5 @@
1
+ export var InjectSituationType;
2
+ (function (InjectSituationType) {
3
+ InjectSituationType.TransactionManager = Symbol('TransactionManager');
4
+ })(InjectSituationType || (InjectSituationType = {}));
5
+ //# sourceMappingURL=InjectSituationType.js.map
@@ -0,0 +1,5 @@
1
+ import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
2
+ export interface OnInit {
3
+ onInit(app: SimpleBootHttpServer): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=OnInit.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=OnInit.js.map