wip: remove all generic caused by prisma doesn't support by default

This commit is contained in:
Supan Adit Pratama 2024-10-26 21:35:16 +07:00
parent a1576273bd
commit 4d5ac919be
27 changed files with 257 additions and 150 deletions

View File

@ -26,6 +26,10 @@
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Todo
- [] Create custom generic for Prisma ORM Support [#5273](https://github.com/prisma/prisma/issues/5273)
## Project setup
```bash

View File

@ -0,0 +1,3 @@
import { SkeletonCRUDController } from '@autocrud/skeleton';
export class PrismaCRUDController extends SkeletonCRUDController {}

View File

@ -0,0 +1,11 @@
import { BatchDeleteProcess } from '@autocrud/skeleton/processes/batch/delete.process';
export abstract class PrismaBatchDeleteProcess implements BatchDeleteProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { BatchUpdateProcess } from '@autocrud/skeleton/processes/batch/update.process';
export abstract class PrismaBatchUpdateProcess implements BatchUpdateProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,18 @@
import { CreateProcess } from '@autocrud/skeleton/processes/create.process';
import { Prisma, PrismaClient } from '@prisma/client';
export abstract class PrismaCreateProcess implements CreateProcess {
constructor(private readonly prisma: PrismaClient) {}
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
process(): T {
this.prisma['asd'].create({
data,
});
}
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -0,0 +1,12 @@
import { DeleteProcess } from '@autocrud/skeleton/processes/delete.process';
import { Prisma } from '@prisma/client';
export abstract class PrismaDeleteProcess implements DeleteProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { ListProcess } from '@autocrud/skeleton/processes/list.process';
export abstract class PrismaListProcess implements ListProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { PaginationProcess } from '@autocrud/skeleton/processes/pagination.process';
export abstract class PrismaPaginationProcess implements PaginationProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,13 @@
import { PartialBatchUpdateProcess } from '@autocrud/skeleton/processes/partial/batch/update.process';
export abstract class PrismaPartialBatchUpdateProcess
implements PartialBatchUpdateProcess
{
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,13 @@
import { PartialUpdateProcess } from '@autocrud/skeleton/processes/partial/update.process';
export abstract class PrismaPartialUpdateProcess
implements PartialUpdateProcess
{
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { ReadProcess } from '@autocrud/skeleton/processes/read.process';
export abstract class PrismaReadProcess implements ReadProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { UpdateProcess } from '@autocrud/skeleton/processes/update.process';
export abstract class PrismaUpdateProcess implements UpdateProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,14 +1,13 @@
import { IPaginationEntity } from '@autocrud/skeleton/entities/pagination.entity';
export interface ISkeletonCRUDController<T, E> {
create(): Promise<T>;
readSelected(id: E): Promise<T>;
readPagination(): Promise<IPaginationEntity<T>>;
readEntire(): Promise<T[]>;
updatePartial(): Promise<T>;
updatePartialBatch(): Promise<T[]>;
updateEntire(): Promise<T>;
updateEntireBatch(): Promise<T[]>;
deleteSelected(): Promise<T>;
deleteBatch(): Promise<T[]>;
export interface ISkeletonCRUDController {
create();
readSelected(id);
readPagination();
readEntire();
updatePartial();
updatePartialBatch();
updateEntire();
updateEntireBatch();
deleteSelected();
deleteBatch();
}

View File

@ -1,10 +1,10 @@
export interface ISkeletonProcess<T, R> {
initialization(): T;
before(): T;
begin(): T;
process(): T;
end(): T;
after(): T;
export interface ISkeletonProcess {
initialization();
before();
begin();
process();
end();
after();
result(): R;
result();
}

View File

@ -1,13 +1,11 @@
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class BatchDeleteProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class BatchDeleteProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,13 +1,11 @@
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class BatchUpdateProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class BatchUpdateProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class CreateProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class CreateProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class DeleteProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class DeleteProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class ListProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class ListProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class PaginationProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class PaginationProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,13 +1,11 @@
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class PartialBatchUpdateProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class PartialBatchUpdateProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -0,0 +1,11 @@
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class PartialUpdateProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class ReadProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class ReadProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,11 +1,11 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class UpdateProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
export abstract class UpdateProcess implements ISkeletonProcess {
abstract initialization();
abstract before();
abstract begin();
abstract process();
abstract end();
abstract after();
abstract result();
}

View File

@ -1,91 +1,67 @@
import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common';
import { IPaginationEntity } from './entities/pagination.entity';
import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface';
import { BatchDeleteProcess } from './processes/batch/delete.process';
import { BatchUpdateProcess } from './processes/batch/update.process';
import { CreateProcess } from './processes/create.process';
import { DeleteProcess } from './processes/delete.process';
import { ListProcess } from './processes/list.process';
import { PaginationProcess } from './processes/pagination.process';
import { PartialBatchUpdateProcess } from './processes/partial/batch/update.process';
import { ReadProcess } from './processes/read.process';
import { UpdateProcess } from './processes/update.process';
export class SkeletonCRUDController<
T,
E,
CP extends CreateProcess<T, T>,
RSP extends ReadProcess<T, T>,
RPP extends PaginationProcess<T, IPaginationEntity<T>>,
REP extends ListProcess<T, T[]>,
UPP extends UpdateProcess<T, T>,
UBP extends PartialBatchUpdateProcess<T, T[]>,
UEP extends UpdateProcess<T, T>,
UEBP extends BatchUpdateProcess<T, T[]>,
DP extends DeleteProcess<T, T>,
DBP extends BatchDeleteProcess<T, T[]>,
> implements ISkeletonCRUDController<T, E>
{
export class SkeletonCRUDController implements ISkeletonCRUDController {
constructor(
private readonly createProcess: CP,
private readonly readProcess: RSP,
private readonly readPaginationProcess: RPP,
private readonly readEntireProcess: REP,
private readonly updatePartialProcess: UPP,
private readonly updateBatchProcess: UBP,
private readonly updateEntireProcess: UEP,
private readonly updateEntireBatchProcess: UEBP,
private readonly deleteProcess: DP,
private readonly deleteBatchProcess: DBP,
private readonly createProcess,
private readonly readProcess,
private readonly readPaginationProcess,
private readonly readEntireProcess,
private readonly updatePartialProcess,
private readonly updateBatchProcess,
private readonly updateEntireProcess,
private readonly updateEntireBatchProcess,
private readonly deleteProcess,
private readonly deleteBatchProcess,
) {}
@Post()
async create(): Promise<T> {
async create() {
return this.createProcess.result();
}
@Get(':id')
async readSelected(@Param('id') id: E): Promise<T> {
async readSelected(@Param('id') id) {
return this.readProcess.result();
}
@Get()
async readPagination(): Promise<IPaginationEntity<T>> {
async readPagination() {
return this.readPaginationProcess.result();
}
@Get('list')
async readEntire(): Promise<T[]> {
async readEntire() {
return this.readEntireProcess.result();
}
@Patch()
async updatePartial(): Promise<T> {
async updatePartial() {
return this.updatePartialProcess.result();
}
@Patch('batch')
async updatePartialBatch(): Promise<T[]> {
async updatePartialBatch() {
return this.updateBatchProcess.result();
}
@Put()
async updateEntire(): Promise<T> {
async updateEntire() {
return this.updateEntireProcess.result();
}
@Put('batch')
async updateEntireBatch(): Promise<T[]> {
async updateEntireBatch() {
return this.updateEntireBatchProcess.result();
}
@Delete()
async deleteSelected(): Promise<T> {
async deleteSelected() {
return this.deleteProcess.result();
}
@Delete('batch')
async deleteBatch(): Promise<T[]> {
async deleteBatch() {
return this.deleteBatchProcess.result();
}
}

View File

@ -1,12 +1,9 @@
import { SkeletonCRUDController } from '@autocrud/skeleton';
import { PrismaCRUDController } from '@autocrud/prisma/prisma-crud.controller';
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
@Controller('hello')
export class AppController extends SkeletonCRUDController {
constructor(private readonly appService: AppService) {
super();
}
export class AppController extends PrismaCRUDController {
constructor() {}
// Read(): void {
// console.log(this.appService.getHello());

View File

@ -1,9 +1,10 @@
import { PrismaModule } from '@autocrud/prisma';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [],
imports: [PrismaModule],
controllers: [AppController],
providers: [AppService],
})