Last active
February 21, 2026 19:25
-
-
Save Hoyasumii/60bcd7e3b382e1426c95977a16128cad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** biome-ignore-all lint/correctness/noUnusedVariables: <a> */ | |
| /** biome-ignore-all lint/suspicious/noExplicitAny: <explanation> */ | |
| // biome-ignore-all lint/suspicious/noEmptyInterface: <:)> | |
| import type { UnpackedPostTagDTO } from "@/domain/dtos"; | |
| import type { IPostTag, IUnpackedPostTag } from "@/domain/types"; | |
| import type { IEntity } from "@caffeine/entity/types"; | |
| import type { t } from "@caffeine/models"; | |
| interface IWriter< | |
| EntityType extends IEntity<t.TSchema>, | |
| Keys extends string = never, | |
| > { | |
| create(data: IPostTag): Promise<IPostTag>; | |
| update(data: IPostTag): Promise<IPostTag>; | |
| delete(data: IPostTag): Promise<IPostTag>; | |
| } | |
| // Record<Keys, (args: EntityType) => Promise<EntityType | null>>; | |
| interface IPostTagWriter extends IWriter<IPostTag> { | |
| create(data: IPostTag): Promise<IPostTag>; | |
| update(data: IPostTag): Promise<IPostTag>; | |
| delete(data: IPostTag): Promise<IPostTag>; | |
| } | |
| class PostTagWriter implements IPostTagWriter { | |
| create(data: IPostTag): Promise<IPostTag> { | |
| throw new Error("Method not implemented."); | |
| } | |
| update(data: IPostTag): Promise<IPostTag> { | |
| throw new Error("Method not implemented."); | |
| } | |
| delete(data: IPostTag): Promise<IPostTag> { | |
| throw new Error("Method not implemented."); | |
| } | |
| } | |
| // a; | |
| type IReader< | |
| EntityType extends IEntity<t.TSchema>, | |
| Keys extends string = never, | |
| > = Record< | |
| Keys, | |
| <Args, Output = EntityType | null | EntityType[]>( | |
| args: Args, | |
| ) => Promise<Output> | |
| > & { count(): Promise<number> }; | |
| type IRepository< | |
| EntityType extends IEntity<t.TSchema>, | |
| WriterType extends IWriter<EntityType, never>, | |
| ReaderType extends IReader<EntityType, never>, | |
| > = WriterType & ReaderType; | |
| type IRepositoryTarget = "WRITE" | "READ"; | |
| type RepositoryStrategy< | |
| Target extends IRepositoryTarget, | |
| EntityType extends IEntity<t.TSchema>, | |
| WriterType extends IWriter<EntityType>, | |
| ReaderType extends IReader<EntityType>, | |
| > = Target extends "WRITE" ? WriterType : ReaderType; | |
| const RepositorySymbol = Symbol("repository"); | |
| const ServiceSymbol = Symbol("service"); | |
| interface IService< | |
| Action extends IRepositoryTarget, | |
| Args, | |
| OutputType, | |
| EntityType extends IEntity<t.TSchema>, | |
| WriterType extends IWriter<EntityType>, | |
| ReaderType extends IReader<EntityType>, | |
| ExtraServices extends Record< | |
| string, | |
| IService<any, any, any, any, any, any> | |
| > = never, | |
| > { | |
| readonly [RepositorySymbol]: RepositoryStrategy< | |
| Action, | |
| EntityType, | |
| WriterType, | |
| ReaderType | |
| >; | |
| readonly [ServiceSymbol]?: ExtraServices; | |
| run(args: Args): Promise<OutputType>; | |
| } | |
| type IServiceFactory< | |
| ServiceType extends IService< | |
| Action, | |
| Args, | |
| OutputType, | |
| EntityType, | |
| WriterType, | |
| ReaderType, | |
| ExtraServices | |
| >, | |
| Action extends IRepositoryTarget, | |
| Args, | |
| OutputType, | |
| EntityType extends IEntity<t.TSchema>, | |
| WriterType extends IWriter<EntityType>, | |
| ReaderType extends IReader<EntityType>, | |
| ExtraServices extends Record< | |
| string, | |
| IService<any, any, any, any, any, any> | |
| > = never, | |
| > = () => ServiceType; | |
| type IHttpMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; | |
| interface IMiddleware { | |
| action(request: Request): Promise<void>; | |
| } | |
| const MiddlewareSymbol = Symbol("middleware"); | |
| interface IController< | |
| ServiceType extends IService<any, any, any, any, any, any, any>, | |
| > { | |
| readonly [ServiceSymbol]: ServiceType; | |
| readonly [MiddlewareSymbol]?: IMiddleware[]; | |
| readonly method: IHttpMethods; | |
| readonly path: string; | |
| action(request: Request): Promise<Response>; | |
| } | |
| interface IRoute { | |
| readonly [MiddlewareSymbol]?: IMiddleware[]; | |
| readonly controllers: IController<any>[]; | |
| readonly path: string; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment