@maioradv/nestjs-core 1.0.1 → 1.0.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 +7 -0
- package/dist/decorators/api-response-with-rels.decorator.d.ts +16 -0
- package/dist/decorators/api-response-with-rels.decorator.js +58 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +17 -0
- package/dist/dto/clauses/index.d.ts +2 -0
- package/dist/dto/clauses/index.js +18 -0
- package/dist/dto/clauses/model.d.ts +12 -0
- package/dist/dto/clauses/model.js +2 -0
- package/dist/dto/clauses/standard-clauses.decorator.d.ts +5 -0
- package/dist/dto/clauses/standard-clauses.decorator.js +47 -0
- package/dist/dto/index.d.ts +3 -0
- package/dist/dto/index.js +19 -0
- package/dist/dto/pagination/cursor-meta.dto.d.ts +12 -0
- package/dist/dto/pagination/cursor-meta.dto.js +48 -0
- package/dist/dto/pagination/cursor-paginated.dto.d.ts +24 -0
- package/dist/dto/pagination/cursor-paginated.dto.js +71 -0
- package/dist/dto/pagination/cursor-query.dto.d.ts +11 -0
- package/dist/dto/pagination/cursor-query.dto.js +82 -0
- package/{lib/dto/pagination/index.ts → dist/dto/pagination/index.d.ts} +8 -16
- package/dist/dto/pagination/index.js +32 -0
- package/dist/dto/pagination/model.d.ts +6 -0
- package/dist/dto/pagination/model.js +2 -0
- package/dist/dto/pagination/paginated-meta.dto.d.ts +13 -0
- package/dist/dto/pagination/paginated-meta.dto.js +47 -0
- package/dist/dto/pagination/paginated-query.dto.d.ts +7 -0
- package/dist/dto/pagination/paginated-query.dto.js +55 -0
- package/dist/dto/pagination/paginated-response.decorator.d.ts +5 -0
- package/dist/dto/pagination/paginated-response.decorator.js +44 -0
- package/dist/dto/pagination/paginated.dto.d.ts +6 -0
- package/dist/dto/pagination/paginated.dto.js +31 -0
- package/dist/dto/pagination/pagination-params.decorator.d.ts +3 -0
- package/dist/dto/pagination/pagination-params.decorator.js +21 -0
- package/dist/dto/sorting/enums.d.ts +4 -0
- package/dist/dto/sorting/enums.js +8 -0
- package/dist/dto/sorting/index.d.ts +3 -0
- package/dist/dto/sorting/index.js +19 -0
- package/dist/dto/sorting/models.d.ts +25 -0
- package/dist/dto/sorting/models.js +46 -0
- package/dist/dto/sorting/sorting-params.decorator.d.ts +3 -0
- package/dist/dto/sorting/sorting-params.decorator.js +25 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +17 -0
- package/dist/errors/validation.error.d.ts +5 -0
- package/dist/errors/validation.error.js +11 -0
- package/dist/filters/all-exception.filter.d.ts +4 -0
- package/dist/filters/all-exception.filter.js +40 -0
- package/dist/filters/http-exception.filter.d.ts +4 -0
- package/dist/filters/http-exception.filter.js +39 -0
- package/dist/filters/index.d.ts +3 -0
- package/dist/filters/index.js +19 -0
- package/dist/filters/validation-exception.filter.d.ts +4 -0
- package/dist/filters/validation-exception.filter.js +27 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +17 -0
- package/dist/logger/logger-factory.d.ts +4 -0
- package/dist/logger/logger-factory.js +43 -0
- package/dist/utils/chunk.helper.d.ts +1 -0
- package/dist/utils/chunk.helper.js +5 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/path.helper.d.ts +2 -0
- package/dist/utils/path.helper.js +7 -0
- package/dist/utils/slug.helper.d.ts +8 -0
- package/dist/utils/slug.helper.js +23 -0
- package/dist/utils/storage.helper.d.ts +9 -0
- package/dist/utils/storage.helper.js +62 -0
- package/dist/utils/types.helper.d.ts +7 -0
- package/dist/utils/types.helper.js +2 -0
- package/package.json +12 -8
- package/index.ts +0 -1
- package/lib/decorators/api-response-with-rels.decorator.ts +0 -75
- package/lib/decorators/index.ts +0 -1
- package/lib/dto/clauses/index.ts +0 -2
- package/lib/dto/clauses/model.ts +0 -15
- package/lib/dto/clauses/standard-clauses.decorator.ts +0 -80
- package/lib/dto/index.ts +0 -3
- package/lib/dto/pagination/cursor-meta.dto.ts +0 -38
- package/lib/dto/pagination/cursor-paginated.dto.ts +0 -68
- package/lib/dto/pagination/cursor-query.dto.ts +0 -64
- package/lib/dto/pagination/model.ts +0 -7
- package/lib/dto/pagination/paginated-meta.dto.ts +0 -37
- package/lib/dto/pagination/paginated-query.dto.ts +0 -40
- package/lib/dto/pagination/paginated-response.decorator.ts +0 -49
- package/lib/dto/pagination/paginated.dto.ts +0 -15
- package/lib/dto/pagination/pagination-params.decorator.ts +0 -21
- package/lib/dto/sorting/enums.ts +0 -4
- package/lib/dto/sorting/index.ts +0 -3
- package/lib/dto/sorting/models.ts +0 -47
- package/lib/dto/sorting/sorting-params.decorator.ts +0 -35
- package/lib/errors/index.ts +0 -1
- package/lib/errors/validation.error.ts +0 -9
- package/lib/filters/all-exception.filter.ts +0 -33
- package/lib/filters/http-exception.filter.ts +0 -32
- package/lib/filters/index.ts +0 -3
- package/lib/filters/validation-exception.filter.ts +0 -21
- package/lib/index.ts +0 -6
- package/lib/logger/index.ts +0 -1
- package/lib/logger/logger-factory.ts +0 -42
- package/lib/utils/chunk.helper.ts +0 -4
- package/lib/utils/index.ts +0 -5
- package/lib/utils/path.helper.ts +0 -5
- package/lib/utils/slug.helper.ts +0 -22
- package/lib/utils/storage.helper.ts +0 -39
- package/lib/utils/types.helper.ts +0 -3
- package/tsconfig.json +0 -21
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { HttpStatus, Type, applyDecorators } from "@nestjs/common";
|
|
2
|
-
import { ApiExtraModels, ApiOkResponse, ApiResponseOptions, getSchemaPath } from "@nestjs/swagger";
|
|
3
|
-
import PaginatedMetaDto from "./paginated-meta.dto";
|
|
4
|
-
import PaginatedDto from "./paginated.dto";
|
|
5
|
-
import { RelationDefs, handleRelationsForSwagger } from "@/decorators";
|
|
6
|
-
|
|
7
|
-
const ApiPaginatedResponse = <TModel extends Type<any>>(
|
|
8
|
-
model: TModel,
|
|
9
|
-
relations?:RelationDefs,
|
|
10
|
-
options?: ApiResponseOptions,
|
|
11
|
-
) => {
|
|
12
|
-
const {properties,extraModels} = relations ? handleRelationsForSwagger(relations) : {properties:undefined,extraModels:[]}
|
|
13
|
-
return applyDecorators(
|
|
14
|
-
ApiExtraModels(PaginatedMetaDto, PaginatedDto, model, ...extraModels),
|
|
15
|
-
ApiOkResponse({
|
|
16
|
-
status:HttpStatus.OK,
|
|
17
|
-
description:`${model.name}s`,
|
|
18
|
-
schema: {
|
|
19
|
-
title: `Paginated${model.name}Dto`,
|
|
20
|
-
allOf: [
|
|
21
|
-
{ $ref: getSchemaPath(PaginatedDto) },
|
|
22
|
-
{
|
|
23
|
-
properties: {
|
|
24
|
-
data: {
|
|
25
|
-
|
|
26
|
-
type: 'array',
|
|
27
|
-
items: {
|
|
28
|
-
title:`${model.name}s`,
|
|
29
|
-
allOf:[
|
|
30
|
-
{ $ref: getSchemaPath(model) },
|
|
31
|
-
{
|
|
32
|
-
properties:properties
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
meta: {
|
|
38
|
-
$ref: getSchemaPath(PaginatedMetaDto)
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
...options
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default ApiPaginatedResponse
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ApiProperty } from "@nestjs/swagger";
|
|
2
|
-
import PaginatedMetaDto from "./paginated-meta.dto";
|
|
3
|
-
|
|
4
|
-
export default class PaginatedDto<T> {
|
|
5
|
-
@ApiProperty()
|
|
6
|
-
readonly data: T[];
|
|
7
|
-
|
|
8
|
-
@ApiProperty()
|
|
9
|
-
readonly meta: PaginatedMetaDto;
|
|
10
|
-
|
|
11
|
-
constructor(data: T[], meta: PaginatedMetaDto) {
|
|
12
|
-
this.data = data
|
|
13
|
-
this.meta = meta
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Type, applyDecorators } from "@nestjs/common";
|
|
2
|
-
import { ApiExtraModels, ApiQuery, getSchemaPath } from "@nestjs/swagger";
|
|
3
|
-
import PaginatedQueryDto from "./paginated-query.dto";
|
|
4
|
-
|
|
5
|
-
const ApiPaginationParams = <TModel extends Type<any>>() => {
|
|
6
|
-
return applyDecorators(
|
|
7
|
-
ApiExtraModels(PaginatedQueryDto),
|
|
8
|
-
ApiQuery({
|
|
9
|
-
required: false,
|
|
10
|
-
name: 'pagination',
|
|
11
|
-
style: 'deepObject',
|
|
12
|
-
explode: true,
|
|
13
|
-
type: 'object',
|
|
14
|
-
schema: {
|
|
15
|
-
$ref: getSchemaPath(PaginatedQueryDto),
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default ApiPaginationParams
|
package/lib/dto/sorting/enums.ts
DELETED
package/lib/dto/sorting/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { IsEnum, IsOptional } from 'class-validator';
|
|
2
|
-
import { Sorting } from '@/dto/sorting';
|
|
3
|
-
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
|
|
5
|
-
export class SortingDto implements DefaultSortingI {
|
|
6
|
-
@ApiPropertyOptional({enum: Sorting})
|
|
7
|
-
@IsEnum(Sorting)
|
|
8
|
-
@IsOptional()
|
|
9
|
-
id?: Sorting;
|
|
10
|
-
|
|
11
|
-
@ApiPropertyOptional({enum: Sorting})
|
|
12
|
-
@IsEnum(Sorting)
|
|
13
|
-
@IsOptional()
|
|
14
|
-
createdAt?: Sorting;
|
|
15
|
-
|
|
16
|
-
@ApiPropertyOptional({enum: Sorting})
|
|
17
|
-
@IsEnum(Sorting)
|
|
18
|
-
@IsOptional()
|
|
19
|
-
updatedAt?: Sorting;
|
|
20
|
-
|
|
21
|
-
get orderBy() {
|
|
22
|
-
return Object.entries(this).map(entry => {
|
|
23
|
-
return {[entry[0]]: entry[1]};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get orderByRDB() {
|
|
28
|
-
return Object.entries(this).map(entry => {
|
|
29
|
-
return {column:entry[0], order:entry[1]};
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface DefaultSortingI {
|
|
35
|
-
id?: Sorting;
|
|
36
|
-
createdAt?: Sorting;
|
|
37
|
-
updatedAt?: Sorting;
|
|
38
|
-
get orderBy();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface SortingQueryI<T extends SortingDto> {
|
|
42
|
-
sorting?:T
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type SortingFieldsOf<T, P extends keyof T = Exclude<keyof T,keyof DefaultSortingI | 'metafields' | 'translations'>> = {
|
|
46
|
-
[K in P]?: Sorting
|
|
47
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Type as TypeI, applyDecorators } from "@nestjs/common";
|
|
2
|
-
import { ApiExtraModels, ApiPropertyOptional, ApiQuery, getSchemaPath } from "@nestjs/swagger";
|
|
3
|
-
import { Transform, Type, plainToClass } from "class-transformer";
|
|
4
|
-
import { IsOptional, ValidateNested } from "class-validator";
|
|
5
|
-
|
|
6
|
-
export const ApiSortingParams = <TModel extends TypeI<any>>(
|
|
7
|
-
model: TModel,
|
|
8
|
-
) => {
|
|
9
|
-
return applyDecorators(
|
|
10
|
-
ApiExtraModels(model),
|
|
11
|
-
ApiQuery({
|
|
12
|
-
required: false,
|
|
13
|
-
name: 'sorting',
|
|
14
|
-
style: 'deepObject',
|
|
15
|
-
explode: true,
|
|
16
|
-
type: 'object',
|
|
17
|
-
example:'',
|
|
18
|
-
schema: {
|
|
19
|
-
$ref: getSchemaPath(model),
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const IsSortingObject = <TModel extends TypeI<any>>(
|
|
26
|
-
model: TModel,
|
|
27
|
-
) => {
|
|
28
|
-
return applyDecorators(
|
|
29
|
-
ApiPropertyOptional({type:model}),
|
|
30
|
-
ValidateNested(),
|
|
31
|
-
Transform(({value}) => plainToClass(model, JSON.parse(value))),
|
|
32
|
-
Type(() => model),
|
|
33
|
-
IsOptional()
|
|
34
|
-
);
|
|
35
|
-
};
|
package/lib/errors/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './validation.error'
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
export const VALIDATION_EXCEPTION_CODE = 'VALIDATION_ERROR'
|
|
4
|
-
|
|
5
|
-
export class ValidationException extends BadRequestException {
|
|
6
|
-
constructor(objectOrError?: any) {
|
|
7
|
-
super(objectOrError,VALIDATION_EXCEPTION_CODE);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, Catch, ArgumentsHost, HttpStatus } from '@nestjs/common';
|
|
2
|
-
import { GqlContextType } from '@nestjs/graphql';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
|
|
5
|
-
@Catch()
|
|
6
|
-
export class AllExceptionsFilter implements ExceptionFilter {
|
|
7
|
-
catch(exception: any, host: ArgumentsHost): void {
|
|
8
|
-
if(host.getType<GqlContextType>() === 'graphql') {
|
|
9
|
-
return exception;
|
|
10
|
-
}
|
|
11
|
-
const ctx = host.switchToHttp();
|
|
12
|
-
const response = ctx.getResponse<Response>();
|
|
13
|
-
const request = ctx.getRequest<Request>();
|
|
14
|
-
const status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
15
|
-
|
|
16
|
-
const data = process.env.NODE_ENV == 'development' ? {
|
|
17
|
-
statusCode: status,
|
|
18
|
-
method: request.method,
|
|
19
|
-
path: request.url,
|
|
20
|
-
type: exception.name,
|
|
21
|
-
code: exception.code,
|
|
22
|
-
message: exception.message ?? 'Internal Server Error',
|
|
23
|
-
stack: exception.stack?.split('\n')
|
|
24
|
-
} : {
|
|
25
|
-
statusCode: status,
|
|
26
|
-
message: 'Internal Server Error',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
response
|
|
30
|
-
.status(status)
|
|
31
|
-
.send(data);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
|
|
2
|
-
import { GqlContextType } from '@nestjs/graphql';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
|
|
5
|
-
@Catch(HttpException)
|
|
6
|
-
export class HttpExceptionFilter implements ExceptionFilter {
|
|
7
|
-
catch(exception: HttpException, host: ArgumentsHost) {
|
|
8
|
-
if(host.getType<GqlContextType>() === 'graphql') {
|
|
9
|
-
return exception;
|
|
10
|
-
}
|
|
11
|
-
const ctx = host.switchToHttp();
|
|
12
|
-
const response = ctx.getResponse<Response>();
|
|
13
|
-
const request = ctx.getRequest<Request>();
|
|
14
|
-
const status = exception.getStatus();
|
|
15
|
-
|
|
16
|
-
const data = process.env.NODE_ENV == 'development' ? {
|
|
17
|
-
statusCode: status,
|
|
18
|
-
method: request.method,
|
|
19
|
-
path: request.url,
|
|
20
|
-
type: exception.name,
|
|
21
|
-
message: exception.message,
|
|
22
|
-
stack: exception.stack?.split('\n')
|
|
23
|
-
} : {
|
|
24
|
-
statusCode: status,
|
|
25
|
-
message: exception.message,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
response
|
|
29
|
-
.status(status)
|
|
30
|
-
.send(data);
|
|
31
|
-
}
|
|
32
|
-
}
|
package/lib/filters/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, Catch, ArgumentsHost, HttpException, BadRequestException } from '@nestjs/common';
|
|
2
|
-
import { GqlContextType } from '@nestjs/graphql';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { ValidationException } from '../errors/validation.error';
|
|
5
|
-
|
|
6
|
-
@Catch(BadRequestException)
|
|
7
|
-
export class ValidationExceptionFilter implements ExceptionFilter {
|
|
8
|
-
catch(exception: BadRequestException, host: ArgumentsHost) {
|
|
9
|
-
if(host.getType<GqlContextType>() === 'graphql') {
|
|
10
|
-
return exception;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const ctx = host.switchToHttp();
|
|
14
|
-
const response = ctx.getResponse<Response>();
|
|
15
|
-
const status = exception.getStatus();
|
|
16
|
-
|
|
17
|
-
response
|
|
18
|
-
.status(status)
|
|
19
|
-
.send(exception['response']);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/lib/index.ts
DELETED
package/lib/logger/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './logger-factory'
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { LoggerService } from '@nestjs/common';
|
|
2
|
-
import { WinstonModule, WinstonModuleOptions, utilities } from 'nest-winston';
|
|
3
|
-
import { format, transports } from 'winston';
|
|
4
|
-
import DailyRotateFile from "winston-daily-rotate-file";
|
|
5
|
-
import { joinFromRoot } from '../utils';
|
|
6
|
-
|
|
7
|
-
export const LoggerFactory = (appName: string): LoggerService => {
|
|
8
|
-
return WinstonModule.createLogger(LoggerFactoryOptions(appName))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const LoggerFactoryOptions = (appName:string): WinstonModuleOptions => {
|
|
12
|
-
const relativePath = `../logs/${appName}`
|
|
13
|
-
return {
|
|
14
|
-
transports: [
|
|
15
|
-
new DailyRotateFile({
|
|
16
|
-
filename: joinFromRoot(relativePath,`%DATE%-error.log`),
|
|
17
|
-
level: 'error',
|
|
18
|
-
format: format.combine(format.timestamp({format:'YYYY-MM-DDTHH:mm:ssZZ'}), format.ms(), format.json()),
|
|
19
|
-
datePattern: 'YYYY-MM-DD',
|
|
20
|
-
zippedArchive: true,
|
|
21
|
-
maxFiles: '30d',
|
|
22
|
-
}),
|
|
23
|
-
new DailyRotateFile({
|
|
24
|
-
filename: joinFromRoot(relativePath,`%DATE%-combined.log`),
|
|
25
|
-
format: format.combine(format.timestamp({format:'YYYY-MM-DDTHH:mm:ssZZ'}), format.ms(), format.json()),
|
|
26
|
-
datePattern: 'YYYY-MM-DD',
|
|
27
|
-
zippedArchive: true,
|
|
28
|
-
maxFiles: '30d',
|
|
29
|
-
}),
|
|
30
|
-
new transports.Console({
|
|
31
|
-
format: format.combine(
|
|
32
|
-
format.timestamp(),
|
|
33
|
-
format.ms(),
|
|
34
|
-
utilities.format.nestLike(appName, {
|
|
35
|
-
colors: true,
|
|
36
|
-
prettyPrint: true,
|
|
37
|
-
}),
|
|
38
|
-
),
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
41
|
-
}
|
|
42
|
-
}
|
package/lib/utils/index.ts
DELETED
package/lib/utils/path.helper.ts
DELETED
package/lib/utils/slug.helper.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export default class Slugger {
|
|
2
|
-
private unique;
|
|
3
|
-
constructor(private readonly word: string) {}
|
|
4
|
-
|
|
5
|
-
public get(): string {
|
|
6
|
-
return this.word.trim().normalize("NFD").replace(/[\u0300-\u036f]/g, '').replace(/[^a-z0-9\s]/gi, '').replaceAll(' ','-').toLowerCase() + (this.unique ? '-'+this.randomString(5) : '')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public makeUnique() {
|
|
10
|
-
this.unique = true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
private randomString(length:number) {
|
|
14
|
-
let result = '';
|
|
15
|
-
const characters = 'abcdefghijklmnopqrstuvwxyz';
|
|
16
|
-
const charactersLength = characters.length;
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
|
-
import { join, dirname } from 'path';
|
|
4
|
-
import { EOL } from 'os';
|
|
5
|
-
|
|
6
|
-
export default class StorageHelper {
|
|
7
|
-
public rootPath = join(__dirname,'..','../../public')
|
|
8
|
-
|
|
9
|
-
public async read(path:string): Promise<string | Buffer> {
|
|
10
|
-
const realPath = join(this.rootPath,path)
|
|
11
|
-
const readFile = promisify(fs.readFile);
|
|
12
|
-
return await readFile(realPath, {});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public async write(path:string,data:string): Promise<void> {
|
|
16
|
-
const realPath = join(this.rootPath,path)
|
|
17
|
-
this.safeDirectory(realPath)
|
|
18
|
-
const writeFile = promisify(fs.writeFile);
|
|
19
|
-
return await writeFile(realPath, data, 'utf8');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public async append(path:string,data:string): Promise<void> {
|
|
23
|
-
const realPath = join(this.rootPath,path)
|
|
24
|
-
this.safeDirectory(realPath)
|
|
25
|
-
const appendFile = promisify(fs.appendFile);
|
|
26
|
-
return await appendFile(realPath, data + EOL);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public async delete(path:string): Promise<void> {
|
|
30
|
-
const realPath = join(this.rootPath,path)
|
|
31
|
-
const unlink = promisify(fs.unlink);
|
|
32
|
-
return fs.existsSync(realPath) ? await unlink(realPath) : null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private safeDirectory(path:string) {
|
|
36
|
-
const dirPath = dirname(path)
|
|
37
|
-
if(!fs.existsSync(dirPath)) fs.mkdirSync(dirPath,{recursive:true});
|
|
38
|
-
}
|
|
39
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"removeComments": true,
|
|
6
|
-
"noLib": false,
|
|
7
|
-
"emitDecoratorMetadata": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"target": "ES2021",
|
|
11
|
-
"sourceMap": false,
|
|
12
|
-
"outDir": "./dist",
|
|
13
|
-
"rootDir": "./lib",
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"paths": {
|
|
16
|
-
"@/*": ["./lib/*"],
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"include": ["lib/**/*"],
|
|
20
|
-
"exclude": ["node_modules", "**/*.spec.ts", "tests"]
|
|
21
|
-
}
|