@mini2/core 2.0.0 → 2.0.1-beta.2

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 (34) hide show
  1. package/Readme.MD +177 -0
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +4 -3
  4. package/dist/app.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces/config.interface.d.ts +12 -0
  10. package/dist/interfaces/config.interface.d.ts.map +1 -1
  11. package/dist/local-test-server/index.d.ts +2 -0
  12. package/dist/local-test-server/index.d.ts.map +1 -0
  13. package/dist/local-test-server/index.js +23 -0
  14. package/dist/local-test-server/index.js.map +1 -0
  15. package/dist/local-test-server/local-test-controller.d.ts +7 -0
  16. package/dist/local-test-server/local-test-controller.d.ts.map +1 -0
  17. package/dist/local-test-server/local-test-controller.js +71 -0
  18. package/dist/local-test-server/local-test-controller.js.map +1 -0
  19. package/dist/notations/controller/index.d.ts +7 -5
  20. package/dist/notations/controller/index.d.ts.map +1 -1
  21. package/dist/notations/controller/index.js +31 -10
  22. package/dist/notations/controller/index.js.map +1 -1
  23. package/dist/notations/controller/rest.types.d.ts +19 -0
  24. package/dist/notations/controller/rest.types.d.ts.map +1 -1
  25. package/dist/swagger.d.ts +6 -12
  26. package/dist/swagger.d.ts.map +1 -1
  27. package/dist/swagger.js +180 -24
  28. package/dist/swagger.js.map +1 -1
  29. package/dist/utils/infer-schema.d.ts +5 -0
  30. package/dist/utils/infer-schema.d.ts.map +1 -0
  31. package/dist/utils/infer-schema.js +47 -0
  32. package/dist/utils/infer-schema.js.map +1 -0
  33. package/local-test-server/Local Test Server.postman_collection.json +163 -0
  34. package/package.json +1 -1
package/Readme.MD CHANGED
@@ -6,10 +6,14 @@
6
6
 
7
7
  - 🚀 **Decorator-Based Routing**: Easy route definition with decorators like `@get`, `@post`
8
8
  - 📝 **Automatic Swagger Documentation**: API documentation generated automatically
9
+ - 🧪 **Example-Driven OpenAPI**: Generate request/response schemas and examples from `RouteOptions.examples`
10
+ - 🧰 **Postman-Friendly Metadata**: Attach `@preRequestScript` / `@testScript` to operations via OpenAPI vendor extensions
9
11
  - 🔧 **Dependency Injection**: Powerful DI container based on InversifyJS
10
12
  - 🛡️ **Security Middlewares**: Authentication, authorization, and validation
13
+ - 🔒 **Swagger Basic Auth**: Optionally protect Swagger UI and JSON spec endpoints with Basic Authentication
11
14
  - 📦 **Full TypeScript Support**: Type-safe API development
12
15
  - 🎯 **Response Builder**: Consistent API responses
16
+ - 🧭 **Autoload Controllers/Injectables**: Optional filesystem-based autoload to discover modules automatically
13
17
  - ⚡ **Quick Setup**: Minimal configuration required
14
18
 
15
19
  ## 📦 Installation
@@ -264,6 +268,43 @@ async downloadFile(@req() req: Request, @res() res: Response) {
264
268
  }
265
269
  ```
266
270
 
271
+ #### **@body() / @query() / @params() / @headers()**
272
+
273
+ Inject validated/normalized request data into method parameters. When validation is enabled via `@validate(...)`, these decorators prefer the validated instance (class-transformer + class-validator) and fall back to raw Express data.
274
+
275
+ ```typescript
276
+ @put('/:id')
277
+ @validate({
278
+ params: IdParamsDto,
279
+ query: SearchQueryDto,
280
+ body: UpdateDto,
281
+ headers: MyHeadersDto,
282
+ })
283
+ async update(
284
+ @params() params: IdParamsDto,
285
+ @query() query: SearchQueryDto,
286
+ @body() body: UpdateDto,
287
+ @headers() headers: MyHeadersDto,
288
+ ) {
289
+ return new ResponseBuilder().ok({ params, query, body, headers });
290
+ }
291
+ ```
292
+
293
+ #### **@next()**
294
+
295
+ Injects Express `next` into your handler (useful for `next(err)` patterns when you want to delegate error handling).
296
+
297
+ ```typescript
298
+ @get('/health')
299
+ health(@next() next: NextFunction) {
300
+ try {
301
+ // ...
302
+ } catch (e) {
303
+ next(e);
304
+ }
305
+ }
306
+ ```
307
+
267
308
  ### 🛡️ Security Decorators
268
309
 
269
310
  #### **@authenticated()**
@@ -314,6 +355,16 @@ async getReports(@req() req: Request) {
314
355
  - Uses OR logic: user needs ANY of the specified permissions
315
356
  - Throws `ForbiddenException` if insufficient permissions
316
357
 
358
+ #### **Default Header-Based Auth (for local/test setups)**
359
+
360
+ The built-in `authenticatedMiddleware` and `authorizedMiddleware` support a simple header-based flow that is convenient for local development and tests:
361
+
362
+ - `x-authenticated`: `"true" | "1" | "yes" | "y"` (required for authenticated routes)
363
+ - `x-user-id`: user identifier (optional)
364
+ - `x-user-permissions`: comma-separated permissions (optional, e.g. `"admin,reader"`)
365
+
366
+ If authentication fails, an `UnauthorizedException` is thrown; if authorization fails, a `ForbiddenException` is thrown.
367
+
317
368
  ### ✅ Validation Decorators
318
369
 
319
370
  #### **@validate(options: ValidationOptions)**
@@ -340,6 +391,7 @@ async createUser(@req() req: Request) {
340
391
  - `body`: DTO class for request body validation
341
392
  - `params`: DTO class for URL parameters validation
342
393
  - `query`: DTO class for query parameters validation
394
+ - `headers`: DTO class for header validation
343
395
 
344
396
  **Example DTO Classes:**
345
397
 
@@ -604,6 +656,16 @@ async createUser(@req() req: Request) {
604
656
  - `body` - Request body validation
605
657
  - `params` - URL parameters validation
606
658
  - `query` - Query parameters validation
659
+ - `headers` - Request header validation
660
+
661
+ **Advanced options (via `@validate`)**
662
+
663
+ Each validation entry can be configured with:
664
+
665
+ - `transformOptions`: class-transformer options
666
+ - `validatorOptions`: class-validator options
667
+ - `logging`: debug logs for source/transformed payloads
668
+ - `customHttpError`: override the default 400 response with a custom `HttpException`
607
669
 
608
670
  #### **authenticatedMiddleware**
609
671
 
@@ -855,6 +917,58 @@ const swaggerOptions = {
855
917
  };
856
918
  ```
857
919
 
920
+ #### **🧪 Example-Driven OpenAPI (Schemas + Examples)**
921
+
922
+ You can provide concrete request/response examples per route. If `examples` are present, Swagger generation prefers them to:
923
+
924
+ - Build request body schemas and attach `example`
925
+ - Generate path/query/header parameters (with examples when available)
926
+ - Generate **all response status codes** with `example` and `examples.default` for compatibility
927
+
928
+ Example (simplified):
929
+
930
+ ```typescript
931
+ @post('/create', 'Create', {
932
+ examples: [{
933
+ request: {
934
+ body: { title: 'Test Item', order: 1 },
935
+ params: { id: '123' },
936
+ query: { page: 1 },
937
+ headers: { 'x-echo': 'hello' },
938
+ },
939
+ response: {
940
+ 201: { description: 'Created', data: { ok: true } },
941
+ 400: { description: 'Validation error', data: { error: 'Validation failed' } },
942
+ },
943
+ }],
944
+ })
945
+ create() { /* ... */ }
946
+ ```
947
+
948
+ #### **🧰 Postman Scripts via OpenAPI Vendor Extensions**
949
+
950
+ Attach Postman-compatible scripts to a route:
951
+
952
+ - `@preRequestScript(script: string)` → `x-postman-prerequest`
953
+ - `@testScript(script: string)` → `x-postman-test`
954
+
955
+ Swagger/OpenAPI will include them as vendor extensions on the operation, and also as a combined `x-postman-events` list (when present). This is useful for tooling that can import OpenAPI and preserve Postman behaviors.
956
+
957
+ #### **🔒 Protect Swagger with Basic Auth**
958
+
959
+ To protect Swagger UI and the raw OpenAPI JSON spec, set `swaggerBasicAuth` in `IConfig`:
960
+
961
+ ```typescript
962
+ await app.init({
963
+ host: 'localhost',
964
+ port: 3000,
965
+ applicationName: 'Protected API',
966
+ swaggerBasicAuth: { username: 'admin', password: 'secret123' },
967
+ });
968
+ ```
969
+
970
+ This will protect both `docsPath` and `jsonPath` endpoints (defaults: `/api-docs` and `/api-docs.json`).
971
+
858
972
  #### **🔐 Security Documentation**
859
973
 
860
974
  Security decorators automatically add authentication requirements:
@@ -898,6 +1012,36 @@ async createUser(@req() req: Request) {
898
1012
  - OpenAPI JSON can be used with external documentation tools
899
1013
  - All validation errors are automatically documented with examples
900
1014
 
1015
+ ### 🧭 Autoload (Filesystem Discovery)
1016
+
1017
+ The framework can automatically discover and load controllers/injectables from a directory (useful for local dev, tests, and modular apps).
1018
+
1019
+ ```typescript
1020
+ await app.init(
1021
+ { host: 'localhost', port: 3000, applicationName: 'My API' },
1022
+ {
1023
+ autoload: true,
1024
+ workingDirectory: __dirname,
1025
+ extensions: ['.ts', '.mts', '.cts'],
1026
+ patterns: ['**/*.(ts|js)'],
1027
+ logging: true,
1028
+ }
1029
+ );
1030
+ ```
1031
+
1032
+ Notes:
1033
+
1034
+ - Files starting with `//mini-dont-auto-load` are skipped.
1035
+ - In production you typically point `workingDirectory` to your compiled output (e.g. `dist`).
1036
+
1037
+ ### 🧪 Local Test Server + Postman Collection
1038
+
1039
+ This repo includes a runnable demo server and an example Postman collection to quickly validate Swagger generation, examples, and Postman script extensions:
1040
+
1041
+ - `local-test-server/index.ts`: starts the server with autoload enabled
1042
+ - `local-test-server/local-test-controller.ts`: demonstrates `examples`, `@preRequestScript`, and `@testScript`
1043
+ - `local-test-server/Local Test Server.postman_collection.json`: ready-to-import collection
1044
+
901
1045
  ### 📝 TypeScript Support
902
1046
 
903
1047
  Full TypeScript support with type-safe API development:
@@ -1016,6 +1160,39 @@ export class UserController {
1016
1160
  }
1017
1161
  ```
1018
1162
 
1163
+ ### 🔎 DI Auto Discovery (`autoBind` + `bindDiscovered`)
1164
+
1165
+ For modular apps, you can register bindings via decorators and then bind them in one shot.
1166
+
1167
+ ```typescript
1168
+ import { autoBind, bindDiscovered, MINI_TYPES } from '@mini2/core';
1169
+
1170
+ @autoBind(MINI_TYPES.IController, { scope: 'Transient', priority: 10 })
1171
+ @controller('/api/users')
1172
+ export class UserController extends Controller {}
1173
+
1174
+ // After loading modules (or using autoload), bind everything discovered:
1175
+ bindDiscovered();
1176
+ ```
1177
+
1178
+ Notes:
1179
+
1180
+ - Supported scopes: `Singleton`, `Transient`, `Request`
1181
+ - `priority` controls binding order (lower first)
1182
+
1183
+ ### 🧩 Custom Route Metadata (`@custom`)
1184
+
1185
+ If you want to attach arbitrary metadata to a route (e.g., for tooling), use `@custom(key, value)` which stores data in `RouteOptions.extraData`.
1186
+
1187
+ ```typescript
1188
+ @get('/reports')
1189
+ @custom('x-internal-owner', 'analytics')
1190
+ @custom('x-stability', 'beta')
1191
+ async reports() {
1192
+ return new ResponseBuilder().ok({ ok: true });
1193
+ }
1194
+ ```
1195
+
1019
1196
  ## 📋 Complete Export List
1020
1197
 
1021
1198
  ```typescript
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAmC,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAY,WAAW,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAKlD,OAAO,EAAmB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEnE,cACM,GAAI,YAAW,IAAI;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,MAAM,EAAG,MAAM,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAS;;IAOnC,eAAe,CAAC,sBAAsB,CAAC,EAAE,sBAAsB;IAQzD,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,sBAAsB,CAAC,EAAE,sBAAsB;IAI3E,oBAAoB,CAAC,MAAM,EAAE,OAAO;IA0BpC,MAAM;IAIA,SAAS,CAAC,oBAAoB,GAAE,OAAc;CAiBpD;AAED,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAmC,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAY,WAAW,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAKlD,OAAO,EAAmB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEnE,cACM,GAAI,YAAW,IAAI;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,MAAM,EAAG,MAAM,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAS;;IAOnC,eAAe,CAAC,sBAAsB,CAAC,EAAE,sBAAsB;IAQzD,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,sBAAsB,CAAC,EAAE,sBAAsB;IAI3E,oBAAoB,CAAC,MAAM,EAAE,OAAO;IA2BpC,MAAM;IAIA,SAAS,CAAC,oBAAoB,GAAE,OAAc;CAiBpD;AAED,eAAe,GAAG,CAAC"}
package/dist/app.js CHANGED
@@ -53,14 +53,15 @@ let App = class App {
53
53
  title: config.applicationName,
54
54
  description: `API documentation for ${config.applicationName}`,
55
55
  version: '1.0.0',
56
- servers: [
56
+ servers: config.swaggerServers ?? [
57
57
  {
58
58
  url: `http://${config.host}:${config.port}`,
59
59
  description: 'Development server',
60
60
  },
61
61
  ],
62
- docsPath: '/api-docs',
63
- jsonPath: '/api-docs.json',
62
+ docsPath: config.swaggerDocsPath ?? '/api-docs',
63
+ jsonPath: config.swaggerJsonPath ?? '/api-docs.json',
64
+ ...(config.swaggerBasicAuth && { basicAuth: config.swaggerBasicAuth }),
64
65
  });
65
66
  this.controllers = container_1.container.getAll(types_1.MINI_TYPES.IController);
66
67
  swaggerIntegration.generateSwaggerSpec(this.controllers);
package/dist/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA4E;AAE5E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AAC,CAAC;QACzD,kBAAkB,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAA,oBAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IACD,MAAM;QACL,OAAO,IAAI,CAAC,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,uBAAgC,IAAI;QACnD,IAAI,oBAAoB,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CACX,CAAC,KAAc,EAAE,IAAa,EAAE,GAAa,EAAE,KAAmB,EAAE,EAAE;gBACrE,IAAI,KAAK,YAAY,wBAAa,EAAE,CAAC;oBACpC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBAChD,CAAC;qBAAM,CAAC;oBACP,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;oBAC1C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBACpB,OAAO,EAAE,CAAC;wBACV,OAAO,EAAE,mBAAmB;qBAC5B,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC,CACD,CAAC;QACH,CAAC;IACF,CAAC;CACD,CAAA;AAxEK,GAAG;IADR,IAAA,sBAAU,GAAE;;GACP,GAAG,CAwER;AAED,kBAAe,GAAG,CAAC"}
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from './notations/controller/middlewares/authorized.middleware';
18
18
  export * from './notations/controller/middlewares/validation.middleware';
19
19
  export * from './utils/array-unify';
20
20
  export * from './utils/math';
21
+ export * from './utils/infer-schema';
21
22
  export * from './expections/http.expection';
22
23
  export { default as HttpException } from './expections/http.expection';
23
24
  export * from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"A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QAAQ,EAAE,CAAC;AACpB,QAAA,MAAM,QAAQ,iBAAW,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,OAAO,EAAE,GAAG,EAAE,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,CAAC;AAGtB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2DAA2D,CAAC;AAC1E,cAAc,+BAA+B,CAAC;AAG9C,cAAc,6DAA6D,CAAC;AAC5E,cAAc,0DAA0D,CAAC;AACzE,cAAc,0DAA0D,CAAC;AAGzE,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AAGrC,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAGvE,cAAc,SAAS,CAAC;AAGxB,cAAc,oBAAoB,CAAC;AAGnC,cAAc,aAAa,CAAC;AAG5B,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -41,6 +41,7 @@ __exportStar(require("./notations/controller/middlewares/validation.middleware")
41
41
  // Utils
42
42
  __exportStar(require("./utils/array-unify"), exports);
43
43
  __exportStar(require("./utils/math"), exports);
44
+ __exportStar(require("./utils/infer-schema"), exports);
44
45
  // Exceptions
45
46
  __exportStar(require("./expections/http.expection"), exports);
46
47
  var http_expection_1 = require("./expections/http.expection");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AAaf,cAbF,aAAG,CAaE;AAZZ,2CAAkD;AAOzC,0FAPA,qBAAS,OAOA;AACT,yFARW,oBAAQ,OAQX;AANjB,mCAAqC;AAW5B,2FAXA,kBAAU,OAWA;AAVnB,yBAAyB;AAEzB,mCAAmC;AACnC,4CAA0B;AAG1B,MAAM,QAAQ,GAA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CAAC,CAAC,EAAE,CAAC,aAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC"}
@@ -1,6 +1,18 @@
1
+ export interface ISwaggerServer {
2
+ url: string;
3
+ description: string;
4
+ }
5
+ export interface ISwaggerBasicAuth {
6
+ username: string;
7
+ password: string;
8
+ }
1
9
  export interface IConfig {
2
10
  host: string;
3
11
  port: number;
4
12
  applicationName: string;
13
+ swaggerDocsPath?: string;
14
+ swaggerJsonPath?: string;
15
+ swaggerServers?: ISwaggerServer[];
16
+ swaggerBasicAuth?: ISwaggerBasicAuth;
5
17
  }
6
18
  //# sourceMappingURL=config.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.interface.d.ts","sourceRoot":"","sources":["../../interfaces/config.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;CACxB"}
1
+ {"version":3,"file":"config.interface.d.ts","sourceRoot":"","sources":["../../interfaces/config.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;CACrC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../local-test-server/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const app_1 = __importDefault(require("../app"));
7
+ const app = new app_1.default();
8
+ app
9
+ .init({
10
+ host: 'localhost',
11
+ port: 3000,
12
+ applicationName: 'Local Test Server',
13
+ }, {
14
+ autoload: true,
15
+ workingDirectory: __dirname,
16
+ extensions: ['.ts', '.mts', '.cts'],
17
+ patterns: ['**/*.(ts|js)'],
18
+ logging: true,
19
+ })
20
+ .then(() => {
21
+ console.log('Local Test Server is running on port 3000');
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../local-test-server/index.ts"],"names":[],"mappings":";;;;;AAAA,iDAAyB;AAEzB,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAC;AACtB,GAAG;KACD,IAAI,CACJ;IACC,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,eAAe,EAAE,mBAAmB;CACpC,EACD;IACC,QAAQ,EAAE,IAAI;IACd,gBAAgB,EAAE,SAAS;IAC3B,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACnC,QAAQ,EAAE,CAAC,cAAc,CAAC;IAC1B,OAAO,EAAE,IAAI;CACb,CACD;KACA,IAAI,CAAC,GAAG,EAAE;IACV,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Response } from 'express';
2
+ import { Controller } from '../notations';
3
+ export declare class LocalTestController extends Controller {
4
+ constructor();
5
+ root(res: Response): void;
6
+ }
7
+ //# sourceMappingURL=local-test-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-test-controller.d.ts","sourceRoot":"","sources":["../../local-test-server/local-test-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAEN,UAAU,EAKV,MAAM,cAAc,CAAC;AAEtB,qBACa,mBAAoB,SAAQ,UAAU;;IAoC3C,IAAI,CAAQ,GAAG,EAAE,QAAQ,GAAG,IAAI;CAOvC"}
@@ -0,0 +1,71 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LocalTestController = void 0;
16
+ const notations_1 = require("../notations");
17
+ let LocalTestController = class LocalTestController extends notations_1.Controller {
18
+ constructor() {
19
+ super();
20
+ }
21
+ root(res) {
22
+ res.setHeader('x-handler', 'root');
23
+ res.json({
24
+ ok: true,
25
+ route: 'GET /local-test',
26
+ });
27
+ }
28
+ };
29
+ exports.LocalTestController = LocalTestController;
30
+ __decorate([
31
+ (0, notations_1.get)('/', 'Root GET', {
32
+ examples: [
33
+ {
34
+ request: {
35
+ body: {
36
+ name: 'John Doe',
37
+ },
38
+ },
39
+ response: {
40
+ 200: {
41
+ description: 'OK',
42
+ data: {
43
+ name: 'John Doe',
44
+ },
45
+ },
46
+ 404: {
47
+ description: 'Not Found',
48
+ data: {
49
+ message: 'Not Found',
50
+ },
51
+ },
52
+ },
53
+ },
54
+ ],
55
+ }),
56
+ (0, notations_1.preRequestScript)(`
57
+ console.log('Pre-request script');
58
+ `),
59
+ (0, notations_1.testScript)(`
60
+ console.log('Test script');
61
+ `),
62
+ __param(0, (0, notations_1.res)()),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [Object]),
65
+ __metadata("design:returntype", void 0)
66
+ ], LocalTestController.prototype, "root", null);
67
+ exports.LocalTestController = LocalTestController = __decorate([
68
+ (0, notations_1.controller)('/local-test', 'Local Test Controller', 'Local Test Module'),
69
+ __metadata("design:paramtypes", [])
70
+ ], LocalTestController);
71
+ //# sourceMappingURL=local-test-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-test-controller.js","sourceRoot":"","sources":["../../local-test-server/local-test-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,4CAOsB;AAGf,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,sBAAU;IAClD;QACC,KAAK,EAAE,CAAC;IACT,CAAC;IAiCM,IAAI,CAAQ,GAAa;QAC/B,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACnC,GAAG,CAAC,IAAI,CAAC;YACR,EAAE,EAAE,IAAI;YACR,KAAK,EAAE,iBAAiB;SACxB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA3CY,kDAAmB;AAoCxB;IA/BN,IAAA,eAAG,EAAC,GAAG,EAAE,UAAU,EAAE;QACrB,QAAQ,EAAE;YACT;gBACC,OAAO,EAAE;oBACR,IAAI,EAAE;wBACL,IAAI,EAAE,UAAU;qBAChB;iBACD;gBACD,QAAQ,EAAE;oBACT,GAAG,EAAE;wBACJ,WAAW,EAAE,IAAI;wBACjB,IAAI,EAAE;4BACL,IAAI,EAAE,UAAU;yBAChB;qBACD;oBACD,GAAG,EAAE;wBACJ,WAAW,EAAE,WAAW;wBACxB,IAAI,EAAE;4BACL,OAAO,EAAE,WAAW;yBACpB;qBACD;iBACD;aACD;SACD;KACD,CAAC;IACD,IAAA,4BAAgB,EAAC;;KAEd,CAAC;IACJ,IAAA,sBAAU,EAAC;;KAER,CAAC;IACQ,WAAA,IAAA,eAAG,GAAE,CAAA;;;;+CAMjB;8BA1CW,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,aAAa,EAAE,uBAAuB,EAAE,mBAAmB,CAAC;;GAC3D,mBAAmB,CA2C/B"}
@@ -37,12 +37,14 @@ export declare function controller(path: string, name?: string, moduleName?: str
37
37
  new (...args: any[]): Controller;
38
38
  }>(constructor: T) => void | T;
39
39
  export declare function httpMethod(newOptions: RouteOptions): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
40
- export declare function get(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
41
- export declare function post(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
42
- export declare function put(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
43
- export declare function del(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
44
- export declare function patch(path: string, name?: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
40
+ export declare function get(path: string, name?: string, options?: Omit<RouteOptions, 'path' | 'method' | 'name'>): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
41
+ export declare function post(path: string, name?: string, options?: Omit<RouteOptions, 'path' | 'method' | 'name'>): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
42
+ export declare function put(path: string, name?: string, options?: Omit<RouteOptions, 'path' | 'method' | 'name'>): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
43
+ export declare function del(path: string, name?: string, options?: Omit<RouteOptions, 'path' | 'method' | 'name'>): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
44
+ export declare function patch(path: string, name?: string, options?: Omit<RouteOptions, 'path' | 'method' | 'name'>): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
45
45
  export declare function validate(options: IValidation | IValidation[]): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
46
+ export declare function preRequestScript(script: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
47
+ export declare function testScript(script: string): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
46
48
  export declare function authenticated(value?: boolean): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
47
49
  export declare function authorized(value: string | string[]): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
48
50
  export declare function middleware(mw: RequestHandler, isPre?: boolean, order?: number): (target: any, propertyKey: string, _descriptor: PropertyDescriptor) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../notations/controller/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,OAAO,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAIX,OAAO,EACP,cAAc,EACd,MAAM,SAAS,CAAC;AAGjB,OAA6B,EAC5B,WAAW,EACX,MAAM,qCAAqC,CAAC;AAK7C,OAAO,EACN,WAAW,EACX,2BAA2B,EAE3B,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,MAAM,cAAc,CAAC;AAEtB,qBAAa,UAAW,YAAW,WAAW;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,gBAAgB,CAAC;;IAiBnC,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe;IAOvD,mBAAmB,IAAI,gBAAgB;CAGvC;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAC,OAAO;IAMt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B,IAAI,KACX,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,UAIpC;AACD,wBAAgB,IAAI,KACX,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,UAIpC;AACD,wBAAgB,KAAK,KACZ,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,UAIpC;AACD,wBAAgB,MAAM,KACb,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,UAIpC;AACD,wBAAgB,OAAO,KACd,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,UAIpC;AACD,wBAAgB,yBAAyB,CACxC,kBAAkB,EAAE,WAAW,GAC7B,OAAO,CAgIT;AACD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,mBAQhE"}
@@ -12,6 +12,8 @@ exports.put = put;
12
12
  exports.del = del;
13
13
  exports.patch = patch;
14
14
  exports.validate = validate;
15
+ exports.preRequestScript = preRequestScript;
16
+ exports.testScript = testScript;
15
17
  exports.authenticated = authenticated;
16
18
  exports.authorized = authorized;
17
19
  exports.middleware = middleware;
@@ -178,6 +180,9 @@ function httpMethod(newOptions) {
178
180
  : existingOptions.authenticated;
179
181
  const otherHttpMiddlewares = (0, array_unify_1.arrayUnify)((newOptions.otherHttpMiddlewares ?? []).concat(existingOptions.otherHttpMiddlewares ?? []));
180
182
  const name = newOptions.name ?? existingOptions.name;
183
+ const examples = (0, array_unify_1.arrayUnify)((newOptions.examples ?? []).concat(existingOptions.examples ?? []));
184
+ const preRequestScript = newOptions.preRequestScript ?? existingOptions.preRequestScript;
185
+ const testScript = newOptions.testScript ?? existingOptions.testScript;
181
186
  const extraData = existingOptions.extraData ?? new Map();
182
187
  if (newOptions.extraData) {
183
188
  const newOptionsExtraData = newOptions.extraData;
@@ -224,6 +229,12 @@ function httpMethod(newOptions) {
224
229
  mergedOptions.otherHttpMiddlewares = otherHttpMiddlewares;
225
230
  if (name !== undefined)
226
231
  mergedOptions.name = name;
232
+ if (examples.length)
233
+ mergedOptions.examples = examples;
234
+ if (preRequestScript !== undefined)
235
+ mergedOptions.preRequestScript = preRequestScript;
236
+ if (testScript !== undefined)
237
+ mergedOptions.testScript = testScript;
227
238
  if (extraData && extraData.size > 0)
228
239
  mergedOptions.extraData = extraData;
229
240
  // NOT: method/param dekoratör metadataları **prototype** üzerinde tutuluyor
@@ -247,26 +258,36 @@ function httpMethod(newOptions) {
247
258
  };
248
259
  }
249
260
  /* HTTP method sugar */
250
- function get(path, name) {
251
- return httpMethod({ path, method: 'get', name: name ?? path });
261
+ function get(path, name, options) {
262
+ return httpMethod({ path, method: 'get', name: name ?? path, ...options });
252
263
  }
253
- function post(path, name) {
254
- return httpMethod({ path, method: 'post', name: name ?? path });
264
+ function post(path, name, options) {
265
+ return httpMethod({ path, method: 'post', name: name ?? path, ...options });
255
266
  }
256
- function put(path, name) {
257
- return httpMethod({ path, method: 'put', name: name ?? path });
267
+ function put(path, name, options) {
268
+ return httpMethod({ path, method: 'put', name: name ?? path, ...options });
258
269
  }
259
- function del(path, name) {
260
- return httpMethod({ path, method: 'delete', name: name ?? path });
270
+ function del(path, name, options) {
271
+ return httpMethod({ path, method: 'delete', name: name ?? path, ...options });
261
272
  }
262
- function patch(path, name) {
263
- return httpMethod({ path, method: 'patch', name: name ?? path });
273
+ function patch(path, name, options) {
274
+ return httpMethod({ path, method: 'patch', name: name ?? path, ...options });
264
275
  }
265
276
  function validate(options) {
266
277
  return httpMethod({
267
278
  validations: Array.isArray(options) ? options : [options],
268
279
  });
269
280
  }
281
+ function preRequestScript(script) {
282
+ return httpMethod({
283
+ preRequestScript: script,
284
+ });
285
+ }
286
+ function testScript(script) {
287
+ return httpMethod({
288
+ testScript: script,
289
+ });
290
+ }
270
291
  function authenticated(value = true) {
271
292
  return httpMethod({ authenticated: value });
272
293
  }