@avleon/core 0.0.46 → 0.0.49

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 (142) hide show
  1. package/License +21 -21
  2. package/README.md +666 -666
  3. package/dist/chunk-9hOWP6kD.cjs +64 -0
  4. package/dist/chunk-DORXReHP.js +37 -0
  5. package/dist/index-CWUcfHYp.d.ts +1283 -0
  6. package/dist/index-CzAzauXZ.d.cts +1282 -0
  7. package/dist/index.cjs +3194 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.js +3022 -79
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib-Bk8hUm06.cjs +7847 -0
  12. package/dist/lib-Bk8hUm06.cjs.map +1 -0
  13. package/dist/lib-CvDxBMkR.js +7843 -0
  14. package/dist/lib-CvDxBMkR.js.map +1 -0
  15. package/package.json +41 -103
  16. package/dist/application.test.d.ts +0 -1
  17. package/dist/application.test.js +0 -15
  18. package/dist/authentication.d.ts +0 -13
  19. package/dist/authentication.js +0 -16
  20. package/dist/cache.d.ts +0 -12
  21. package/dist/cache.js +0 -78
  22. package/dist/cache.test.d.ts +0 -1
  23. package/dist/cache.test.js +0 -36
  24. package/dist/collection.d.ts +0 -43
  25. package/dist/collection.js +0 -231
  26. package/dist/collection.test.d.ts +0 -1
  27. package/dist/collection.test.js +0 -59
  28. package/dist/config.d.ts +0 -18
  29. package/dist/config.js +0 -58
  30. package/dist/config.test.d.ts +0 -1
  31. package/dist/config.test.js +0 -40
  32. package/dist/constants.d.ts +0 -1
  33. package/dist/constants.js +0 -4
  34. package/dist/container.d.ts +0 -30
  35. package/dist/container.js +0 -55
  36. package/dist/controller.d.ts +0 -50
  37. package/dist/controller.js +0 -71
  38. package/dist/controller.test.d.ts +0 -1
  39. package/dist/controller.test.js +0 -97
  40. package/dist/core/application.d.ts +0 -74
  41. package/dist/core/application.js +0 -424
  42. package/dist/core/router.d.ts +0 -44
  43. package/dist/core/router.js +0 -520
  44. package/dist/core/testing.d.ts +0 -21
  45. package/dist/core/testing.js +0 -104
  46. package/dist/core/types.d.ts +0 -67
  47. package/dist/core/types.js +0 -2
  48. package/dist/decorators.d.ts +0 -15
  49. package/dist/decorators.js +0 -41
  50. package/dist/environment-variables.d.ts +0 -49
  51. package/dist/environment-variables.js +0 -130
  52. package/dist/environment-variables.test.d.ts +0 -1
  53. package/dist/environment-variables.test.js +0 -70
  54. package/dist/event-dispatcher.d.ts +0 -22
  55. package/dist/event-dispatcher.js +0 -97
  56. package/dist/event-subscriber.d.ts +0 -14
  57. package/dist/event-subscriber.js +0 -87
  58. package/dist/exceptions/http-exceptions.d.ts +0 -50
  59. package/dist/exceptions/http-exceptions.js +0 -85
  60. package/dist/exceptions/index.d.ts +0 -1
  61. package/dist/exceptions/index.js +0 -17
  62. package/dist/exceptions/system-exception.d.ts +0 -22
  63. package/dist/exceptions/system-exception.js +0 -26
  64. package/dist/file-storage.d.ts +0 -69
  65. package/dist/file-storage.js +0 -323
  66. package/dist/file-storage.test.d.ts +0 -1
  67. package/dist/file-storage.test.js +0 -117
  68. package/dist/helpers.d.ts +0 -11
  69. package/dist/helpers.js +0 -27
  70. package/dist/helpers.test.d.ts +0 -1
  71. package/dist/helpers.test.js +0 -95
  72. package/dist/index.d.ts +0 -57
  73. package/dist/interfaces/avleon-application.d.ts +0 -75
  74. package/dist/interfaces/avleon-application.js +0 -2
  75. package/dist/kenx-provider.d.ts +0 -7
  76. package/dist/kenx-provider.js +0 -44
  77. package/dist/kenx-provider.test.d.ts +0 -1
  78. package/dist/kenx-provider.test.js +0 -36
  79. package/dist/logger.d.ts +0 -12
  80. package/dist/logger.js +0 -87
  81. package/dist/logger.test.d.ts +0 -1
  82. package/dist/logger.test.js +0 -42
  83. package/dist/map-types.d.ts +0 -17
  84. package/dist/map-types.js +0 -89
  85. package/dist/middleware.d.ts +0 -34
  86. package/dist/middleware.js +0 -73
  87. package/dist/middleware.test.d.ts +0 -1
  88. package/dist/middleware.test.js +0 -121
  89. package/dist/multipart.d.ts +0 -17
  90. package/dist/multipart.js +0 -70
  91. package/dist/multipart.test.d.ts +0 -1
  92. package/dist/multipart.test.js +0 -87
  93. package/dist/openapi.d.ts +0 -410
  94. package/dist/openapi.js +0 -59
  95. package/dist/openapi.test.d.ts +0 -1
  96. package/dist/openapi.test.js +0 -111
  97. package/dist/params.d.ts +0 -17
  98. package/dist/params.js +0 -64
  99. package/dist/params.test.d.ts +0 -1
  100. package/dist/params.test.js +0 -83
  101. package/dist/queue.d.ts +0 -29
  102. package/dist/queue.js +0 -84
  103. package/dist/response.d.ts +0 -16
  104. package/dist/response.js +0 -56
  105. package/dist/results.d.ts +0 -20
  106. package/dist/results.js +0 -32
  107. package/dist/route-methods.d.ts +0 -25
  108. package/dist/route-methods.js +0 -60
  109. package/dist/route-methods.test.d.ts +0 -1
  110. package/dist/route-methods.test.js +0 -129
  111. package/dist/swagger-schema.d.ts +0 -37
  112. package/dist/swagger-schema.js +0 -454
  113. package/dist/swagger-schema.test.d.ts +0 -1
  114. package/dist/swagger-schema.test.js +0 -125
  115. package/dist/types/app-builder.interface.d.ts +0 -15
  116. package/dist/types/app-builder.interface.js +0 -8
  117. package/dist/types/application.interface.d.ts +0 -8
  118. package/dist/types/application.interface.js +0 -2
  119. package/dist/utils/common-utils.d.ts +0 -17
  120. package/dist/utils/common-utils.js +0 -108
  121. package/dist/utils/di-utils.d.ts +0 -1
  122. package/dist/utils/di-utils.js +0 -22
  123. package/dist/utils/hash.d.ts +0 -2
  124. package/dist/utils/hash.js +0 -11
  125. package/dist/utils/index.d.ts +0 -2
  126. package/dist/utils/index.js +0 -18
  127. package/dist/utils/object-utils.d.ts +0 -11
  128. package/dist/utils/object-utils.js +0 -198
  129. package/dist/utils/optional-require.d.ts +0 -8
  130. package/dist/utils/optional-require.js +0 -70
  131. package/dist/utils/validation-utils.d.ts +0 -13
  132. package/dist/utils/validation-utils.js +0 -119
  133. package/dist/validation.d.ts +0 -39
  134. package/dist/validation.js +0 -108
  135. package/dist/validation.test.d.ts +0 -1
  136. package/dist/validation.test.js +0 -61
  137. package/dist/validator-extend.d.ts +0 -7
  138. package/dist/validator-extend.js +0 -28
  139. package/dist/websocket.d.ts +0 -10
  140. package/dist/websocket.js +0 -21
  141. package/dist/websocket.test.d.ts +0 -1
  142. package/dist/websocket.test.js +0 -27
package/dist/openapi.d.ts DELETED
@@ -1,410 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export interface InfoObject {
8
- title: string;
9
- description?: string;
10
- termsOfService?: string;
11
- contact?: ContactObject;
12
- license?: LicenseObject;
13
- version: string;
14
- }
15
- export interface ContactObject {
16
- name?: string;
17
- url?: string;
18
- email?: string;
19
- }
20
- export interface LicenseObject {
21
- name: string;
22
- url?: string;
23
- }
24
- export interface ServerObject {
25
- url: string;
26
- description?: string;
27
- variables?: {
28
- [variable: string]: ServerVariableObject;
29
- };
30
- }
31
- export interface ServerVariableObject {
32
- enum?: string[];
33
- default: string;
34
- description?: string;
35
- }
36
- export type OpenApiUiOptions = {
37
- logo?: any;
38
- theme?: any;
39
- provider?: "default" | "scalar";
40
- ui?: "default" | "scalar";
41
- openapi?: string;
42
- uiConfig?: any;
43
- configuration?: any;
44
- routePrefix?: string;
45
- info?: InfoObject;
46
- servers?: ServerObject[];
47
- paths?: PathsObject<any>;
48
- components?: ComponentsObject;
49
- security?: SecurityRequirementObject[];
50
- tags?: TagObject[];
51
- externalDocs?: any;
52
- "x-express-openapi-additional-middleware"?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
53
- "x-express-openapi-validation-strict"?: boolean;
54
- };
55
- export interface PathsObject<T extends {} = {}, P extends {} = {}> {
56
- [pattern: string]: (PathItemObject<T> & P) | undefined;
57
- }
58
- declare enum HttpMethods {
59
- GET = "get",
60
- PUT = "put",
61
- POST = "post",
62
- DELETE = "delete",
63
- OPTIONS = "options",
64
- HEAD = "head",
65
- PATCH = "patch",
66
- TRACE = "trace"
67
- }
68
- export type PathItemObject<T extends {} = {}> = {
69
- $ref?: string;
70
- summary?: string;
71
- description?: string;
72
- servers?: ServerObject[];
73
- parameters?: (ReferenceObject | ParameterObject)[];
74
- } & {
75
- [method in HttpMethods]?: OperationObject<T>;
76
- };
77
- export type OperationObject<T extends {} = {}> = {
78
- tags?: string[];
79
- summary?: string;
80
- description?: string;
81
- externalDocs?: ExternalDocumentationObject;
82
- operationId?: string;
83
- parameters?: (ReferenceObject | ParameterObject)[];
84
- requestBody?: ReferenceObject | RequestBodyObject;
85
- responses: ResponsesObject;
86
- callbacks?: {
87
- [callback: string]: ReferenceObject | CallbackObject;
88
- };
89
- deprecated?: boolean;
90
- security?: SecurityRequirementObject[];
91
- servers?: ServerObject[];
92
- } & T;
93
- export interface ExternalDocumentationObject {
94
- description?: string;
95
- url: string;
96
- }
97
- export interface ParameterObject extends ParameterBaseObject {
98
- name: string;
99
- in: string;
100
- }
101
- export interface HeaderObject extends ParameterBaseObject {
102
- }
103
- export interface ParameterBaseObject {
104
- description?: string;
105
- required?: boolean;
106
- deprecated?: boolean;
107
- allowEmptyValue?: boolean;
108
- style?: string;
109
- explode?: boolean;
110
- allowReserved?: boolean;
111
- schema?: ReferenceObject | SchemaObject;
112
- example?: any;
113
- examples?: {
114
- [media: string]: ReferenceObject | ExampleObject;
115
- };
116
- content?: {
117
- [media: string]: MediaTypeObject;
118
- };
119
- }
120
- export type NonArraySchemaObjectType = "boolean" | "object" | "number" | "string" | "integer";
121
- export type ArraySchemaObjectType = "array";
122
- export type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
123
- export interface ArraySchemaObject extends BaseSchemaObject {
124
- type: ArraySchemaObjectType;
125
- items: ReferenceObject | SchemaObject;
126
- }
127
- export interface NonArraySchemaObject extends BaseSchemaObject {
128
- type?: NonArraySchemaObjectType;
129
- }
130
- export interface BaseSchemaObject {
131
- title?: string;
132
- description?: string;
133
- format?: string;
134
- default?: any;
135
- multipleOf?: number;
136
- maximum?: number;
137
- exclusiveMaximum?: boolean;
138
- minimum?: number;
139
- exclusiveMinimum?: boolean;
140
- maxLength?: number;
141
- minLength?: number;
142
- pattern?: string;
143
- additionalProperties?: boolean | ReferenceObject | SchemaObject;
144
- maxItems?: number;
145
- minItems?: number;
146
- uniqueItems?: boolean;
147
- maxProperties?: number;
148
- minProperties?: number;
149
- required?: string[];
150
- enum?: any[];
151
- properties?: {
152
- [name: string]: ReferenceObject | SchemaObject;
153
- };
154
- allOf?: (ReferenceObject | SchemaObject)[];
155
- oneOf?: (ReferenceObject | SchemaObject)[];
156
- anyOf?: (ReferenceObject | SchemaObject)[];
157
- not?: ReferenceObject | SchemaObject;
158
- nullable?: boolean;
159
- discriminator?: DiscriminatorObject;
160
- readOnly?: boolean;
161
- writeOnly?: boolean;
162
- xml?: XMLObject;
163
- externalDocs?: ExternalDocumentationObject;
164
- example?: any;
165
- deprecated?: boolean;
166
- }
167
- export interface DiscriminatorObject {
168
- propertyName: string;
169
- mapping?: {
170
- [value: string]: string;
171
- };
172
- }
173
- export interface XMLObject {
174
- name?: string;
175
- namespace?: string;
176
- prefix?: string;
177
- attribute?: boolean;
178
- wrapped?: boolean;
179
- }
180
- export interface ReferenceObject {
181
- $ref: string;
182
- }
183
- export interface ExampleObject {
184
- summary?: string;
185
- description?: string;
186
- value?: any;
187
- externalValue?: string;
188
- }
189
- export interface MediaTypeObject {
190
- schema?: ReferenceObject | SchemaObject;
191
- example?: any;
192
- examples?: {
193
- [media: string]: ReferenceObject | ExampleObject;
194
- };
195
- encoding?: {
196
- [media: string]: EncodingObject;
197
- };
198
- }
199
- export interface EncodingObject {
200
- contentType?: string;
201
- headers?: {
202
- [header: string]: ReferenceObject | HeaderObject;
203
- };
204
- style?: string;
205
- explode?: boolean;
206
- allowReserved?: boolean;
207
- }
208
- export interface RequestBodyObject {
209
- description?: string;
210
- content: {
211
- [media: string]: MediaTypeObject;
212
- };
213
- required?: boolean;
214
- }
215
- export interface ResponsesObject {
216
- [code: string]: ReferenceObject | ResponseObject;
217
- }
218
- export interface ResponseObject {
219
- description: string;
220
- headers?: {
221
- [header: string]: ReferenceObject | HeaderObject;
222
- };
223
- content?: {
224
- [media: string]: MediaTypeObject;
225
- };
226
- links?: {
227
- [link: string]: ReferenceObject | LinkObject;
228
- };
229
- }
230
- export interface LinkObject {
231
- operationRef?: string;
232
- operationId?: string;
233
- parameters?: {
234
- [parameter: string]: any;
235
- };
236
- requestBody?: any;
237
- description?: string;
238
- server?: ServerObject;
239
- }
240
- export interface CallbackObject {
241
- [url: string]: PathItemObject;
242
- }
243
- export interface SecurityRequirementObject {
244
- [name: string]: string[];
245
- }
246
- export interface ComponentsObject {
247
- schemas?: {
248
- [key: string]: ReferenceObject | SchemaObject;
249
- };
250
- responses?: {
251
- [key: string]: ReferenceObject | ResponseObject;
252
- };
253
- parameters?: {
254
- [key: string]: ReferenceObject | ParameterObject;
255
- };
256
- examples?: {
257
- [key: string]: ReferenceObject | ExampleObject;
258
- };
259
- requestBodies?: {
260
- [key: string]: ReferenceObject | RequestBodyObject;
261
- };
262
- headers?: {
263
- [key: string]: ReferenceObject | HeaderObject;
264
- };
265
- securitySchemes?: {
266
- [key: string]: ReferenceObject | SecuritySchemeObject;
267
- };
268
- links?: {
269
- [key: string]: ReferenceObject | LinkObject;
270
- };
271
- callbacks?: {
272
- [key: string]: ReferenceObject | CallbackObject;
273
- };
274
- }
275
- export type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
276
- export interface HttpSecurityScheme {
277
- type: "http";
278
- description?: string;
279
- scheme: string;
280
- bearerFormat?: string;
281
- }
282
- export interface ApiKeySecurityScheme {
283
- type: "apiKey";
284
- description?: string;
285
- name: string;
286
- in: string;
287
- }
288
- export interface OAuth2SecurityScheme {
289
- type: "oauth2";
290
- description?: string;
291
- flows: {
292
- implicit?: {
293
- authorizationUrl: string;
294
- refreshUrl?: string;
295
- scopes: {
296
- [scope: string]: string;
297
- };
298
- };
299
- password?: {
300
- tokenUrl: string;
301
- refreshUrl?: string;
302
- scopes: {
303
- [scope: string]: string;
304
- };
305
- };
306
- clientCredentials?: {
307
- tokenUrl: string;
308
- refreshUrl?: string;
309
- scopes: {
310
- [scope: string]: string;
311
- };
312
- };
313
- authorizationCode?: {
314
- authorizationUrl: string;
315
- tokenUrl: string;
316
- refreshUrl?: string;
317
- scopes: {
318
- [scope: string]: string;
319
- };
320
- };
321
- };
322
- }
323
- export interface OpenIdSecurityScheme {
324
- type: "openIdConnect";
325
- description?: string;
326
- openIdConnectUrl: string;
327
- }
328
- export interface TagObject {
329
- name: string;
330
- description?: string;
331
- externalDocs?: ExternalDocumentationObject;
332
- }
333
- export type ParamSchema = {
334
- type?: "string" | "number" | "integer" | "boolean" | "array";
335
- description?: string;
336
- example?: any;
337
- required?: boolean;
338
- deprecated?: boolean;
339
- enum?: any[];
340
- format?: string;
341
- default?: any;
342
- minimum?: number;
343
- maximum?: number;
344
- minLength?: number;
345
- maxLength?: number;
346
- pattern?: string;
347
- };
348
- export type ParamsSchemaMap = Record<string, ParamSchema>;
349
- export type RequestBodyOptions = {
350
- description?: string;
351
- required?: boolean;
352
- content?: {
353
- [media: string]: MediaTypeObject;
354
- };
355
- schema?: SchemaObject | ReferenceObject;
356
- example?: any;
357
- examples?: Record<string, ExampleObject>;
358
- };
359
- export type ResponseBodyOptions = {
360
- description?: string;
361
- type?: NonArraySchemaObjectType | ArraySchemaObjectType;
362
- properties?: {
363
- [name: string]: ReferenceObject | SchemaObject;
364
- };
365
- items?: ReferenceObject | SchemaObject;
366
- required?: string[];
367
- schema?: SchemaObject | ReferenceObject;
368
- example?: any;
369
- examples?: Record<string, ExampleObject>;
370
- content?: {
371
- [media: string]: MediaTypeObject;
372
- };
373
- } & Partial<BaseSchemaObject>;
374
- export type ResponsesOptions = {
375
- [statusCode: number]: ResponseBodyOptions | ResponseObject;
376
- };
377
- export type OpenApiOptions = {
378
- exclude?: boolean;
379
- deprecated?: boolean;
380
- tags?: readonly string[];
381
- description?: string;
382
- summary?: string;
383
- operationId?: string;
384
- security?: SecurityRequirementObject[];
385
- externalDocs?: ExternalDocumentationObject;
386
- components?: ComponentsObject;
387
- /** Path parameters e.g. /:id → { id: { type: "string", example: "abc-123" } } */
388
- params?: ParamsSchemaMap;
389
- /** Query string parameters e.g. ?page=1 → { page: { type: "integer", example: 1 } } */
390
- query?: ParamsSchemaMap;
391
- /** Request headers */
392
- headers?: ParamsSchemaMap;
393
- /** Request body */
394
- requestBody?: RequestBodyOptions;
395
- /** Responses keyed by HTTP status code */
396
- response?: ResponsesOptions;
397
- /** @deprecated use requestBody instead */
398
- responseBody?: any;
399
- };
400
- /**
401
- * Normalize a flat ParamsSchemaMap into a valid JSON Schema object
402
- * that Fastify/AJV can validate against.
403
- *
404
- * Input: { id: { type: "string", example: "abc-123" } }
405
- * Output: { type: "object", properties: { id: { type: "string", example: "abc-123" } } }
406
- */
407
- export declare function normalizeParamsToJsonSchema(params: ParamsSchemaMap, requiredKeys?: string[]): SchemaObject;
408
- export declare function OpenApiSchema(): ClassDecorator;
409
- export declare function OpenApi(options: OpenApiOptions): MethodDecorator & ClassDecorator & PropertyDecorator;
410
- export {};
package/dist/openapi.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeParamsToJsonSchema = normalizeParamsToJsonSchema;
4
- exports.OpenApiSchema = OpenApiSchema;
5
- exports.OpenApi = OpenApi;
6
- var HttpMethods;
7
- (function (HttpMethods) {
8
- HttpMethods["GET"] = "get";
9
- HttpMethods["PUT"] = "put";
10
- HttpMethods["POST"] = "post";
11
- HttpMethods["DELETE"] = "delete";
12
- HttpMethods["OPTIONS"] = "options";
13
- HttpMethods["HEAD"] = "head";
14
- HttpMethods["PATCH"] = "patch";
15
- HttpMethods["TRACE"] = "trace";
16
- })(HttpMethods || (HttpMethods = {}));
17
- /**
18
- * Normalize a flat ParamsSchemaMap into a valid JSON Schema object
19
- * that Fastify/AJV can validate against.
20
- *
21
- * Input: { id: { type: "string", example: "abc-123" } }
22
- * Output: { type: "object", properties: { id: { type: "string", example: "abc-123" } } }
23
- */
24
- function normalizeParamsToJsonSchema(params, requiredKeys = []) {
25
- const properties = {};
26
- for (const [key, val] of Object.entries(params)) {
27
- properties[key] = {
28
- type: "string", // sensible default
29
- ...val,
30
- };
31
- }
32
- const schema = {
33
- type: "object",
34
- properties,
35
- };
36
- if (requiredKeys.length > 0) {
37
- schema.required = requiredKeys;
38
- }
39
- return schema;
40
- }
41
- function OpenApiSchema() {
42
- return function (target) {
43
- Reflect.defineMetadata("openapi:schema", true, target);
44
- };
45
- }
46
- function OpenApi(options) {
47
- return function (target, propertyKey, descriptor) {
48
- if (typeof target === "function" && !propertyKey) {
49
- Reflect.defineMetadata("controller:openapi", options, target);
50
- }
51
- else if (descriptor) {
52
- // ✅ Store options as-is — router's buildRouteSchema handles normalization
53
- Reflect.defineMetadata("route:openapi", options, target, propertyKey);
54
- }
55
- else if (propertyKey) {
56
- Reflect.defineMetadata("property:openapi", options, target, propertyKey);
57
- }
58
- };
59
- }
@@ -1 +0,0 @@
1
- import 'reflect-metadata';
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- require("reflect-metadata");
13
- const openapi_1 = require("./openapi");
14
- describe('OpenApi Decorator', () => {
15
- it('should define metadata on class', () => {
16
- let TestController = class TestController {
17
- };
18
- TestController = __decorate([
19
- (0, openapi_1.OpenApi)({ description: 'Test Controller' })
20
- ], TestController);
21
- const metadata = Reflect.getMetadata('controller:openapi', TestController);
22
- expect(metadata).toEqual({ description: 'Test Controller' });
23
- });
24
- it('should define metadata on method', () => {
25
- class TestController {
26
- testMethod() { }
27
- }
28
- __decorate([
29
- (0, openapi_1.OpenApi)({ description: 'Test Route' }),
30
- __metadata("design:type", Function),
31
- __metadata("design:paramtypes", []),
32
- __metadata("design:returntype", void 0)
33
- ], TestController.prototype, "testMethod", null);
34
- const metadata = Reflect.getMetadata('route:openapi', TestController.prototype, 'testMethod');
35
- expect(metadata).toEqual({ description: 'Test Route' });
36
- });
37
- it('should define metadata on property', () => {
38
- class TestController {
39
- constructor() {
40
- this.testProperty = '';
41
- }
42
- }
43
- __decorate([
44
- (0, openapi_1.OpenApi)({ description: 'Test Property' }),
45
- __metadata("design:type", String)
46
- ], TestController.prototype, "testProperty", void 0);
47
- const metadata = Reflect.getMetadata('property:openapi', TestController.prototype, 'testProperty');
48
- expect(metadata).toEqual({ description: 'Test Property' });
49
- });
50
- });
51
- describe('Type Definitions', () => {
52
- it('InfoObject should allow optional description', () => {
53
- const info = {
54
- title: 'API',
55
- version: '1.0.0',
56
- description: 'API Description',
57
- };
58
- expect(info.description).toBe('API Description');
59
- });
60
- it('ContactObject should allow optional fields', () => {
61
- const contact = {
62
- name: 'John Doe',
63
- email: 'john@example.com',
64
- };
65
- expect(contact.name).toBe('John Doe');
66
- expect(contact.email).toBe('john@example.com');
67
- });
68
- it('LicenseObject should require name', () => {
69
- const license = {
70
- name: 'MIT',
71
- };
72
- expect(license.name).toBe('MIT');
73
- });
74
- it('ServerObject should allow variables', () => {
75
- var _a;
76
- const server = {
77
- url: 'https://api.example.com',
78
- variables: {
79
- version: {
80
- default: 'v1',
81
- enum: ['v1', 'v2'],
82
- },
83
- },
84
- };
85
- expect((_a = server.variables) === null || _a === void 0 ? void 0 : _a.version.default).toBe('v1');
86
- });
87
- it('SchemaObject should allow array and non-array types', () => {
88
- const arraySchema = {
89
- type: 'array',
90
- items: { type: 'string' },
91
- };
92
- expect(arraySchema.type).toBe('array');
93
- const nonArraySchema = {
94
- type: 'string',
95
- };
96
- expect(nonArraySchema.type).toBe('string');
97
- });
98
- it('ComponentsObject should allow schemas and responses', () => {
99
- var _a, _b;
100
- const components = {
101
- schemas: {
102
- User: { type: 'object' },
103
- },
104
- responses: {
105
- NotFound: { description: 'Not found' },
106
- },
107
- };
108
- expect((_a = components.schemas) === null || _a === void 0 ? void 0 : _a.User).toBeDefined();
109
- expect(((_b = components.responses) === null || _b === void 0 ? void 0 : _b.NotFound).description).toBe('Not found');
110
- });
111
- });
package/dist/params.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- type ParameterOptions = {
8
- required?: boolean;
9
- validate?: boolean;
10
- type?: any;
11
- };
12
- export declare const Param: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
13
- export declare const Query: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
14
- export declare const Body: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
15
- export declare const Header: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
16
- export declare const AuthUser: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
17
- export {};
package/dist/params.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- /**
3
- * @copyright 2024
4
- * @author Tareq Hossain
5
- * @email xtrinsic96@gmail.com
6
- * @url https://github.com/xtareq
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AuthUser = exports.Header = exports.Body = exports.Query = exports.Param = void 0;
10
- const container_1 = require("./container");
11
- const helpers_1 = require("./helpers");
12
- const swagger_schema_1 = require("./swagger-schema");
13
- function createParamDecorator(type) {
14
- return function (key, options = {}) {
15
- return function (target, propertyKey, parameterIndex) {
16
- var _a, _b, _c, _d;
17
- let metaKey;
18
- switch (type) {
19
- case "route:param":
20
- metaKey = container_1.PARAM_META_KEY;
21
- break;
22
- case "route:query":
23
- metaKey = container_1.QUERY_META_KEY;
24
- break;
25
- case "route:body":
26
- metaKey = container_1.REQUEST_BODY_META_KEY;
27
- break;
28
- case "route:user":
29
- metaKey = container_1.REQUEST_USER_META_KEY;
30
- break;
31
- case "route:header":
32
- metaKey = container_1.REQUEST_HEADER_META_KEY;
33
- break;
34
- default:
35
- throw new Error(`Unknown param decorator type: ${String(type)}`);
36
- }
37
- const existingParams = Reflect.getMetadata(metaKey, target, propertyKey) || [];
38
- // Get parameter names (fallback safe)
39
- const functionSource = target[propertyKey].toString();
40
- const paramNames = ((_b = (_a = functionSource.match(/\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split(",").map((n) => n.trim())) || [];
41
- const parameterTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
42
- const paramDataType = parameterTypes[parameterIndex];
43
- existingParams.push({
44
- index: parameterIndex,
45
- key: typeof key === "string" ? key : "all",
46
- name: paramNames[parameterIndex],
47
- required: (_c = options.required) !== null && _c !== void 0 ? _c : true,
48
- validate: (_d = options.validate) !== null && _d !== void 0 ? _d : true,
49
- dataType: (0, helpers_1.getDataType)(paramDataType),
50
- validatorClass: (0, helpers_1.isClassValidatorClass)(paramDataType),
51
- schema: (0, helpers_1.isClassValidatorClass)(paramDataType)
52
- ? (0, swagger_schema_1.generateClassSchema)(paramDataType)
53
- : null,
54
- type,
55
- });
56
- Reflect.defineMetadata(metaKey, existingParams, target, propertyKey);
57
- };
58
- };
59
- }
60
- exports.Param = createParamDecorator("route:param");
61
- exports.Query = createParamDecorator("route:query");
62
- exports.Body = createParamDecorator("route:body");
63
- exports.Header = createParamDecorator("route:header");
64
- exports.AuthUser = createParamDecorator("route:user");
@@ -1 +0,0 @@
1
- import "reflect-metadata";