Commit af1fccaa authored by nanahira's avatar nanahira

move to nesties

parent 2eeb7974
import 'reflect-metadata';
export * from 'nesties';
export * from './src/crud-base';
export * from './src/bases';
export * from './src/decorators';
......
......@@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"lodash": "^4.17.21",
"nesties": "^1.0.1",
"typed-reflector": "^1.0.11"
},
"devDependencies": {
......@@ -35,8 +36,8 @@
"typescript": "^4.7.4"
},
"peerDependencies": {
"@nestjs/common": "^9.4.0",
"@nestjs/swagger": "^7.1.8",
"@nestjs/common": "^9.4.0 || ^10.0.0",
"@nestjs/swagger": "^7.1.8 || ^6.3.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"typeorm": "^0.3.16"
......@@ -1123,6 +1124,21 @@
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"peer": true
},
"node_modules/@nestjs/config": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-3.3.0.tgz",
"integrity": "sha512-pdGTp8m9d0ZCrjTpjkUbZx6gyf2IKf+7zlkrPNMsJzYZ4bFRRTpXrnj+556/5uiI6AfL5mMrJc2u7dB6bvM+VA==",
"peer": true,
"dependencies": {
"dotenv": "16.4.5",
"dotenv-expand": "10.0.0",
"lodash": "4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
"rxjs": "^7.1.0"
}
},
"node_modules/@nestjs/core": {
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-9.4.0.tgz",
......@@ -2656,9 +2672,21 @@
}
},
"node_modules/dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"peer": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dotenv-expand": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==",
"peer": true,
"engines": {
"node": ">=12"
......@@ -4821,6 +4849,16 @@
"node": ">= 0.6"
}
},
"node_modules/nesties": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/nesties/-/nesties-1.0.1.tgz",
"integrity": "sha512-WDc+/sEDGMnHmMD2lZSSxMqMsml0SxyxoDkQhfo5xd78xjQUcO1o4fOUfkPV4pSsTPdhqLO97E0OwPbKXuc7Gw==",
"peerDependencies": {
"@nestjs/common": "^9.4.0 || ^10.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/swagger": "^7.1.8 || ^6.3.0"
}
},
"node_modules/node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
......@@ -7583,6 +7621,17 @@
}
}
},
"@nestjs/config": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-3.3.0.tgz",
"integrity": "sha512-pdGTp8m9d0ZCrjTpjkUbZx6gyf2IKf+7zlkrPNMsJzYZ4bFRRTpXrnj+556/5uiI6AfL5mMrJc2u7dB6bvM+VA==",
"peer": true,
"requires": {
"dotenv": "16.4.5",
"dotenv-expand": "10.0.0",
"lodash": "4.17.21"
}
},
"@nestjs/core": {
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-9.4.0.tgz",
......@@ -8692,9 +8741,15 @@
}
},
"dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"peer": true
},
"dotenv-expand": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==",
"peer": true
},
"ee-first": {
......@@ -10330,6 +10385,12 @@
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
"devOptional": true
},
"nesties": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/nesties/-/nesties-1.0.1.tgz",
"integrity": "sha512-WDc+/sEDGMnHmMD2lZSSxMqMsml0SxyxoDkQhfo5xd78xjQUcO1o4fOUfkPV4pSsTPdhqLO97E0OwPbKXuc7Gw==",
"requires": {}
},
"node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
......
......@@ -69,6 +69,7 @@
},
"dependencies": {
"lodash": "^4.17.21",
"nesties": "^1.0.1",
"typed-reflector": "^1.0.11"
}
}
......@@ -3,12 +3,12 @@ import { Generated, SelectQueryBuilder } from 'typeorm';
import { applyQueryProperty } from '../utility';
import {
IntColumn,
MergePropertyDecorators,
NotChangeable,
NotWritable,
StringColumn,
} from '../decorators';
import { IsNotEmpty } from 'class-validator';
import { MergePropertyDecorators } from 'nesties';
export interface IdOptions {
description?: string;
......
......@@ -3,11 +3,7 @@ import { SelectQueryBuilder } from 'typeorm';
import { IsInt, IsPositive } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { reflector } from '../utility/metadata';
export interface PageSettingsWise {
pageCount: number;
recordsPerPage: number;
}
import { PageSettingsWise } from 'nesties';
export interface PageSettingsFactory {
getActualPageSettings(): PageSettingsWise;
......
import {
BlankReturnMessageDto,
ImportEntryDto,
PaginatedReturnMessageDto,
ReturnMessageDto,
} from './dto';
import { ImportEntryDto } from './dto';
import {
DeepPartial,
DeleteResult,
......@@ -23,6 +18,11 @@ import { ConsoleLogger } from '@nestjs/common';
import { camelCase } from 'typeorm/util/StringUtils';
import _ from 'lodash';
import { ClassType } from './utility/insert-field';
import {
BlankReturnMessageDto,
PaginatedReturnMessageDto,
ReturnMessageDto,
} from 'nesties';
export type EntityId<T extends { id: any }> = T['id'];
export interface RelationDef {
......
import { Expose } from 'class-transformer';
import { IsOptional } from 'class-validator';
import { Metadata } from '../utility/metadata';
import { MergePropertyDecorators } from './merge';
import { MergePropertyDecorators } from 'nesties';
export const NotWritable = () =>
MergePropertyDecorators([
......
export * from './access';
export * from './merge';
export * from './property';
export * from './restful';
export * from './pipes';
......
export function MergePropertyDecorators(
decs: PropertyDecorator[],
): PropertyDecorator {
return (obj, key) => {
for (const dec of decs) {
dec(obj, key);
}
};
}
export function MergeMethodDecorators(
decs: MethodDecorator[],
): MethodDecorator {
return (obj, key, descriptor) => {
for (const dec of decs) {
dec(obj, key, descriptor);
}
};
}
export function MergeClassDecorators(decs: ClassDecorator[]): ClassDecorator {
return (obj) => {
for (const dec of decs) {
dec(obj);
}
};
}
export function MergeParameterDecorators(
decs: ParameterDecorator[],
): ParameterDecorator {
return (obj, key, index) => {
for (const dec of decs) {
dec(obj, key, index);
}
};
}
......@@ -23,9 +23,3 @@ export const UpdatePipe = () =>
skipNullProperties: true,
skipUndefinedProperties: true,
});
export const DataPipe = () =>
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
});
import { ColumnCommonOptions } from 'typeorm/decorator/options/ColumnCommonOptions';
import { ApiProperty, ApiPropertyOptions } from '@nestjs/swagger';
import { ColumnWithLengthOptions } from 'typeorm/decorator/options/ColumnWithLengthOptions';
import { MergePropertyDecorators } from './merge';
import { MergePropertyDecorators } from 'nesties';
import { Column, Index } from 'typeorm';
import {
IsDate,
......
......@@ -9,14 +9,13 @@ import {
Post,
Query,
} from '@nestjs/common';
import { ImportDataDto, ImportEntryDto } from '../dto';
import {
BlankReturnMessageDto,
ImportDataDto,
ImportEntryDto,
MergeMethodDecorators,
PaginatedReturnMessageDto,
ReturnMessageDto,
} from '../dto';
import { MergeMethodDecorators } from './merge';
} from 'nesties';
import { ClassType } from '../utility/insert-field';
import {
ApiBadRequestResponse,
......
export * from './return-message';
export * from './import-entry';
import { ApiProperty } from '@nestjs/swagger';
import { HttpException } from '@nestjs/common';
import { PageSettingsWise } from '../bases/page-settings';
import {
AnyClass,
ClassOrArray,
getClassFromClassOrArray,
InsertField,
ParseType,
} from '../utility/insert-field';
export interface BlankReturnMessage {
statusCode: number;
message: string;
success: boolean;
}
export interface ReturnMessage<T> extends BlankReturnMessage {
data?: T;
}
export class BlankReturnMessageDto implements BlankReturnMessage {
@ApiProperty({ description: 'Return code', type: Number })
statusCode: number;
@ApiProperty({ description: 'Return message', type: String })
message: string;
@ApiProperty({ description: 'Whether success.', type: Boolean })
success: boolean;
constructor(statusCode: number, message?: string) {
this.statusCode = statusCode;
this.message = message || 'success';
this.success = statusCode < 400;
}
toException() {
return new HttpException(this, this.statusCode);
}
}
export class BlankPaginatedReturnMessageDto
extends BlankReturnMessageDto
implements PageSettingsWise
{
@ApiProperty({ description: 'Total record count.', type: Number })
total: number;
@ApiProperty({ description: 'Total page count.', type: Number })
totalPages: number;
@ApiProperty({ description: 'Current page.', type: Number })
pageCount: number;
@ApiProperty({ description: 'Records per page.', type: Number })
recordsPerPage: number;
constructor(
statusCode: number,
message: string,
total: number,
pageSettings: PageSettingsWise,
) {
super(statusCode, message);
this.total = total;
this.pageCount = pageSettings.pageCount;
this.recordsPerPage = pageSettings.recordsPerPage;
this.totalPages = Math.ceil(total / pageSettings.recordsPerPage);
}
}
export class GenericReturnMessageDto<T>
extends BlankReturnMessageDto
implements ReturnMessage<T>
{
data?: T;
constructor(statusCode: number, message?: string, data?: T) {
super(statusCode, message);
this.data = data;
}
}
export function ReturnMessageDto<T extends ClassOrArray>(
type: T,
): new (
statusCode: number,
message: string,
data: ParseType<T>,
) => GenericReturnMessageDto<ParseType<T>> {
return InsertField(
GenericReturnMessageDto,
{
data: {
type,
options: {
required: false,
description: 'Return data.',
},
},
},
`${getClassFromClassOrArray(type).name}ReturnMessageDto`,
);
}
export class GenericPaginatedReturnMessageDto<T>
extends BlankPaginatedReturnMessageDto
implements PageSettingsWise, ReturnMessage<T[]>
{
data: T[];
constructor(
statusCode: number,
message: string,
data: T[],
total: number,
pageSettings: PageSettingsWise,
) {
super(statusCode, message, total, pageSettings);
this.data = data;
}
}
export function PaginatedReturnMessageDto<T extends AnyClass>(
type: T,
): new (
statusCode: number,
message: string,
data: InstanceType<T>[],
total: number,
pageSettings: PageSettingsWise,
) => GenericPaginatedReturnMessageDto<InstanceType<T>> {
return InsertField(
GenericPaginatedReturnMessageDto,
{
data: {
type: [type],
options: {
required: false,
description: 'Return data.',
},
},
},
`${getClassFromClassOrArray(type).name}PaginatedReturnMessageDto`,
);
}
export class StringReturnMessageDto extends GenericReturnMessageDto<string> {
@ApiProperty({ description: 'Return data.', type: String, required: false })
data: string;
}
import { BlankReturnMessageDto } from '../dto';
import { ApiResponse } from '@nestjs/swagger';
export const ApiError = (status: number, description: string) =>
ApiResponse({ status, type: BlankReturnMessageDto, description });
export * from './query';
export * from './api-error';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment