@mini2/core 1.1.0 β 1.1.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.
- package/Readme.MD +128 -7
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +1 -0
- package/dist/app.js.map +1 -1
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +2 -1
- package/dist/container.js.map +1 -1
- package/dist/interfaces/repository.interface.d.ts +5 -10
- package/dist/interfaces/repository.interface.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/Readme.MD
CHANGED
|
@@ -756,15 +756,84 @@ const result = sum(5, 3); // 8
|
|
|
756
756
|
|
|
757
757
|
### π Swagger Integration
|
|
758
758
|
|
|
759
|
-
|
|
759
|
+
@mini2/core automatically generates comprehensive API documentation using Swagger/OpenAPI 3.0 specification based on your decorators and DTOs.
|
|
760
|
+
|
|
761
|
+
#### **π API Documentation Endpoints**
|
|
762
|
+
|
|
763
|
+
When your application starts, Swagger documentation is automatically available at:
|
|
764
|
+
|
|
765
|
+
```typescript
|
|
766
|
+
// Interactive Swagger UI - Test your API directly in browser
|
|
767
|
+
http://localhost:3000/api-docs
|
|
768
|
+
|
|
769
|
+
// Raw OpenAPI JSON specification - For tools, imports, etc.
|
|
770
|
+
http://localhost:3000/api-docs.json
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
#### **π§ Automatic Documentation Features**
|
|
774
|
+
|
|
775
|
+
- **Route Discovery**: All `@controller` and HTTP method decorators are automatically documented
|
|
776
|
+
- **Request/Response Schemas**: DTO classes with `class-validator` decorators generate JSON schemas
|
|
777
|
+
- **Security Requirements**: `@authenticated` and `@authorized` decorators add security info
|
|
778
|
+
- **Parameter Documentation**: Path parameters, query parameters, and request bodies are documented
|
|
779
|
+
- **HTTP Status Codes**: Response codes from `ResponseBuilder` and exceptions are included
|
|
780
|
+
|
|
781
|
+
#### **π Example Generated Documentation**
|
|
782
|
+
|
|
783
|
+
For this controller:
|
|
784
|
+
|
|
785
|
+
```typescript
|
|
786
|
+
@controller('/api/users')
|
|
787
|
+
export class UserController {
|
|
788
|
+
@get('/:id')
|
|
789
|
+
@authenticated()
|
|
790
|
+
@authorized(['user:read'])
|
|
791
|
+
@validate({ params: UserParamsDto })
|
|
792
|
+
async getUser(@req() req: Request) {
|
|
793
|
+
const id = req.params.id;
|
|
794
|
+
const user = await this.userService.findById(id);
|
|
795
|
+
return new ResponseBuilder().ok(user);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
@post('/')
|
|
799
|
+
@validate({ body: CreateUserDto })
|
|
800
|
+
async createUser(@req() req: Request) {
|
|
801
|
+
const userData = req.body;
|
|
802
|
+
const user = await this.userService.create(userData);
|
|
803
|
+
return new ResponseBuilder().created(user);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
Swagger will automatically generate:
|
|
809
|
+
|
|
810
|
+
- **GET /api/users/{id}** - Requires authentication and authorization
|
|
811
|
+
- **POST /api/users** - With CreateUserDto schema for request body
|
|
812
|
+
- Parameter definitions, security requirements, and response schemas
|
|
813
|
+
|
|
814
|
+
#### **π― DTO-Based Schema Generation**
|
|
815
|
+
|
|
816
|
+
Class-validator decorators automatically create OpenAPI schemas:
|
|
760
817
|
|
|
761
818
|
```typescript
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
819
|
+
export class CreateUserDto {
|
|
820
|
+
@IsEmail()
|
|
821
|
+
email: string;
|
|
822
|
+
|
|
823
|
+
@IsString()
|
|
824
|
+
@MinLength(2)
|
|
825
|
+
name: string;
|
|
826
|
+
|
|
827
|
+
@IsOptional()
|
|
828
|
+
@IsNumber()
|
|
829
|
+
@Min(0)
|
|
830
|
+
age?: number;
|
|
831
|
+
}
|
|
765
832
|
```
|
|
766
833
|
|
|
767
|
-
|
|
834
|
+
#### **βοΈ Swagger Configuration**
|
|
835
|
+
|
|
836
|
+
Default configuration is applied automatically, but you can customize it:
|
|
768
837
|
|
|
769
838
|
```typescript
|
|
770
839
|
const swaggerOptions = {
|
|
@@ -772,11 +841,63 @@ const swaggerOptions = {
|
|
|
772
841
|
description: `API documentation for ${config.applicationName}`,
|
|
773
842
|
version: '1.0.0',
|
|
774
843
|
servers: [{ url: `http://${config.host}:${config.port}` }],
|
|
775
|
-
docsPath: '/api-docs',
|
|
776
|
-
jsonPath: '/api-docs.json',
|
|
844
|
+
docsPath: '/api-docs', // Swagger UI endpoint
|
|
845
|
+
jsonPath: '/api-docs.json', // OpenAPI JSON endpoint
|
|
846
|
+
components: {
|
|
847
|
+
securitySchemes: {
|
|
848
|
+
bearerAuth: {
|
|
849
|
+
type: 'http',
|
|
850
|
+
scheme: 'bearer',
|
|
851
|
+
bearerFormat: 'JWT',
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
},
|
|
777
855
|
};
|
|
778
856
|
```
|
|
779
857
|
|
|
858
|
+
#### **π Security Documentation**
|
|
859
|
+
|
|
860
|
+
Security decorators automatically add authentication requirements:
|
|
861
|
+
|
|
862
|
+
```typescript
|
|
863
|
+
@get('/profile')
|
|
864
|
+
@authenticated()
|
|
865
|
+
@authorized(['user:profile'])
|
|
866
|
+
async getProfile(@req() req: Request) {
|
|
867
|
+
// Swagger will show:
|
|
868
|
+
// - π Authentication required
|
|
869
|
+
// - π‘οΈ Requires 'user:profile' permission
|
|
870
|
+
// - 401 Unauthorized response possible
|
|
871
|
+
// - 403 Forbidden response possible
|
|
872
|
+
}
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
#### **π Response Documentation**
|
|
876
|
+
|
|
877
|
+
ResponseBuilder methods automatically document response types:
|
|
878
|
+
|
|
879
|
+
```typescript
|
|
880
|
+
@post('/users')
|
|
881
|
+
async createUser(@req() req: Request) {
|
|
882
|
+
const user = await this.userService.create(req.body);
|
|
883
|
+
|
|
884
|
+
// Swagger documents:
|
|
885
|
+
// - 201 Created status
|
|
886
|
+
// - User object schema in response body
|
|
887
|
+
// - Location header if set
|
|
888
|
+
return new ResponseBuilder()
|
|
889
|
+
.created(user)
|
|
890
|
+
.setHeader('Location', `/users/${user.id}`);
|
|
891
|
+
}
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
#### **π Production Usage**
|
|
895
|
+
|
|
896
|
+
- Swagger UI is automatically available in all environments
|
|
897
|
+
- For production, consider disabling Swagger UI and keeping only JSON endpoint
|
|
898
|
+
- OpenAPI JSON can be used with external documentation tools
|
|
899
|
+
- All validation errors are automatically documented with examples
|
|
900
|
+
|
|
780
901
|
### π TypeScript Support
|
|
781
902
|
|
|
782
903
|
Full TypeScript support with type-safe API development:
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD,OAAO,EAAE,SAAS,EAA2B,MAAM,WAAW,CAAC;AAI/D,cACM,GAAI,YAAW,IAAI;IAIyB,OAAO,CAAC,WAAW;IAHpE,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;gBAEoC,WAAW,EAAE,GAAG,EAAE;IAKrE,IAAI,CAAC,MAAM,EAAE,OAAO;IA0BpB,SAAS;CAGf;AAED,eAAe,GAAG,CAAC"}
|
package/dist/app.js
CHANGED
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,oDAA4B;AAG5B,iCAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,oDAA4B;AAG5B,iCAAkC;AAClC,yCAA+D;AAC/D,uCAA+C;AAC/C,mCAAqC;AAErC,IACM,GAAG,GADT,MACM,GAAG;IAIR,YAAyD,WAAkB;QAAlB,gBAAW,GAAX,WAAW,CAAO;QAC1E,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAe;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACjC,OAAO,CAAC,GAAG,CAAC,6BAA6B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QACH,MAAM,kBAAkB,GAAG,IAAI,4BAAkB,CAAC;YACjD,KAAK,EAAE,MAAM,CAAC,eAAe;YAC7B,WAAW,EAAE,yBAAyB,MAAM,CAAC,eAAe,EAAE;YAC9D,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE;gBACR;oBACC,GAAG,EAAE,UAAU,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE;oBAC3C,WAAW,EAAE,oBAAoB;iBACjC;aACD;YACD,QAAQ,EAAE,WAAW;YACrB,QAAQ,EAAE,gBAAgB;SAC1B,CAAC,CAAC;QACH,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACzD,kBAAkB,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAA,eAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,SAAS;QACd,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC1B,CAAC;CACD,CAAA;AAtCK,GAAG;IADR,IAAA,sBAAU,GAAE;IAKC,WAAA,IAAA,uBAAW,EAAC,kBAAU,CAAC,WAAW,CAAC,CAAA;;GAJ3C,GAAG,CAsCR;AAED,kBAAe,GAAG,CAAC"}
|
package/dist/container.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAKtC,QAAA,MAAM,SAAS,WAAkB,CAAC;AAGlC,eAAe,SAAS,CAAC"}
|
package/dist/container.js
CHANGED
|
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const inversify_1 = require("inversify");
|
|
7
7
|
const app_1 = __importDefault(require("./app"));
|
|
8
|
+
const types_1 = require("./types");
|
|
8
9
|
const container = new inversify_1.Container();
|
|
9
|
-
container.bind(app_1.default).
|
|
10
|
+
container.bind(types_1.MINI_TYPES.IApp).to(app_1.default).inSingletonScope();
|
|
10
11
|
exports.default = container;
|
|
11
12
|
//# sourceMappingURL=container.js.map
|
package/dist/container.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsC;AACtC,gDAAwB;AAExB,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;AAClC,SAAS,CAAC,IAAI,CAAC,aAAG,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsC;AACtC,gDAAwB;AAExB,mCAAqC;AAErC,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;AAClC,SAAS,CAAC,IAAI,CAAO,kBAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,aAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAEjE,kBAAe,SAAS,CAAC"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
export interface TimestampFields {
|
|
2
|
-
id: string;
|
|
3
|
-
createdAt: Date;
|
|
4
|
-
updatedAt: Date;
|
|
5
|
-
}
|
|
6
1
|
export interface IRepository<IdentifierType, ModelType> {
|
|
7
|
-
findAll(): Promise<
|
|
8
|
-
findById(id: IdentifierType): Promise<
|
|
9
|
-
create(item: ModelType): Promise<ModelType
|
|
10
|
-
update(id: IdentifierType, item: Partial<ModelType>): Promise<ModelType
|
|
2
|
+
findAll(): Promise<ModelType[]>;
|
|
3
|
+
findById(id: IdentifierType): Promise<ModelType | null>;
|
|
4
|
+
create(item: ModelType): Promise<ModelType>;
|
|
5
|
+
update(id: IdentifierType, item: Partial<ModelType>): Promise<ModelType>;
|
|
11
6
|
delete(id: IdentifierType): Promise<void>;
|
|
12
|
-
findPaginated(query: Partial<ModelType>, page: number, limit: number): Promise<
|
|
7
|
+
findPaginated(query: Partial<ModelType>, page: number, limit: number): Promise<ModelType[]>;
|
|
13
8
|
}
|
|
14
9
|
//# sourceMappingURL=repository.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.interface.d.ts","sourceRoot":"","sources":["../../interfaces/repository.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"repository.interface.d.ts","sourceRoot":"","sources":["../../interfaces/repository.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,WAAW,CAAC,cAAc,EAAE,SAAS;IACrD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACzE,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,aAAa,CACZ,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CACxB"}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;CACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"description": "Mini Express Framework - Lightweight and modular Express.js framework with TypeScript support",
|
|
27
27
|
"name": "@mini2/core",
|
|
28
|
-
"version": "1.1.
|
|
28
|
+
"version": "1.1.2",
|
|
29
29
|
"author": "Mustafa Γolakoglu <mustafacolakoglu94@gmail.com> (https://github.com/mustafa-colakoglu)",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"class-transformer": "^0.5.1",
|