From f939e516b39e27ee0763cb17fefaff6d669dd64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 7 Sep 2024 03:08:09 +0200 Subject: [PATCH] File structure refactoring --- src/{Layers/express => Express}/ExpressApp.ts | 2 +- src/{Layers/express => Express}/ExpressNodeHTTPServer.ts | 2 +- src/{Layers/express/tests.ts => Express/example.ts} | 0 src/{Layers/express => Express}/index.ts | 0 src/{Layers => }/JSONWebToken.ts | 2 +- src/Layers/index.ts | 4 ---- src/{Layers => }/OpenAIClient.ts | 2 +- src/{Layers => }/PrismaStudioRoute.ts | 0 src/{Layers/trpc => TRPC}/TRPCBuilder.ts | 0 src/{Layers/trpc => TRPC}/TRPCContext.ts | 0 src/{Layers/trpc => TRPC}/TRPCContextCreator.ts | 0 src/{Layers/trpc => TRPC}/TRPCExpressRoute.ts | 4 ++-- src/{Layers/trpc => TRPC}/TRPCRouter.ts | 0 src/{Layers/trpc => TRPC}/TRPCWebSocketServer.ts | 4 ++-- src/{Layers/trpc => TRPC}/createTRCPErrorMapper.ts | 0 src/{Layers/trpc/tests.ts => TRPC/example.ts} | 7 +++---- src/{Layers/trpc => TRPC}/importTRPCServer.ts | 2 +- src/{Layers/trpc => TRPC}/index.ts | 0 src/{Layers/trpc => TRPC}/middlewares.ts | 0 src/index.ts | 4 +++- tsup.config.ts | 2 +- 21 files changed, 16 insertions(+), 19 deletions(-) rename src/{Layers/express => Express}/ExpressApp.ts (93%) rename src/{Layers/express => Express}/ExpressNodeHTTPServer.ts (98%) rename src/{Layers/express/tests.ts => Express/example.ts} (100%) rename src/{Layers/express => Express}/index.ts (100%) rename src/{Layers => }/JSONWebToken.ts (97%) delete mode 100644 src/Layers/index.ts rename src/{Layers => }/OpenAIClient.ts (98%) rename src/{Layers => }/PrismaStudioRoute.ts (100%) rename src/{Layers/trpc => TRPC}/TRPCBuilder.ts (100%) rename src/{Layers/trpc => TRPC}/TRPCContext.ts (100%) rename src/{Layers/trpc => TRPC}/TRPCContextCreator.ts (100%) rename src/{Layers/trpc => TRPC}/TRPCExpressRoute.ts (91%) rename src/{Layers/trpc => TRPC}/TRPCRouter.ts (100%) rename src/{Layers/trpc => TRPC}/TRPCWebSocketServer.ts (96%) rename src/{Layers/trpc => TRPC}/createTRCPErrorMapper.ts (100%) rename src/{Layers/trpc/tests.ts => TRPC/example.ts} (86%) rename src/{Layers/trpc => TRPC}/importTRPCServer.ts (80%) rename src/{Layers/trpc => TRPC}/index.ts (100%) rename src/{Layers/trpc => TRPC}/middlewares.ts (100%) diff --git a/src/Layers/express/ExpressApp.ts b/src/Express/ExpressApp.ts similarity index 93% rename from src/Layers/express/ExpressApp.ts rename to src/Express/ExpressApp.ts index 8b6fdbe..af91481 100644 --- a/src/Layers/express/ExpressApp.ts +++ b/src/Express/ExpressApp.ts @@ -1,6 +1,6 @@ import { Config, Context, Effect, Layer } from "effect" import type { Express } from "express" -import { ImportError } from "../../ImportError" +import { ImportError } from "../ImportError" export class ExpressApp extends Context.Tag("ExpressApp")() {} diff --git a/src/Layers/express/ExpressNodeHTTPServer.ts b/src/Express/ExpressNodeHTTPServer.ts similarity index 98% rename from src/Layers/express/ExpressNodeHTTPServer.ts rename to src/Express/ExpressNodeHTTPServer.ts index d56f1cb..25ff95f 100644 --- a/src/Layers/express/ExpressNodeHTTPServer.ts +++ b/src/Express/ExpressNodeHTTPServer.ts @@ -1,7 +1,7 @@ import { Config, Context, Effect, Layer, Match } from "effect" import type { Server } from "node:http" import type { AddressInfo } from "node:net" -import { ImportError } from "../../ImportError" +import { ImportError } from "../ImportError" import { ExpressApp } from "./ExpressApp" diff --git a/src/Layers/express/tests.ts b/src/Express/example.ts similarity index 100% rename from src/Layers/express/tests.ts rename to src/Express/example.ts diff --git a/src/Layers/express/index.ts b/src/Express/index.ts similarity index 100% rename from src/Layers/express/index.ts rename to src/Express/index.ts diff --git a/src/Layers/JSONWebToken.ts b/src/JSONWebToken.ts similarity index 97% rename from src/Layers/JSONWebToken.ts rename to src/JSONWebToken.ts index f9f76c1..f088049 100644 --- a/src/Layers/JSONWebToken.ts +++ b/src/JSONWebToken.ts @@ -1,6 +1,6 @@ import { Context, Effect, Layer } from "effect" import type * as JWT from "jsonwebtoken" -import { ImportError } from "../ImportError" +import { ImportError } from "./ImportError" export class JSONWebToken extends Context.Tag("JSONWebToken")() {} diff --git a/src/Layers/PrismaStudioRoute.ts b/src/PrismaStudioRoute.ts similarity index 100% rename from src/Layers/PrismaStudioRoute.ts rename to src/PrismaStudioRoute.ts diff --git a/src/Layers/trpc/TRPCBuilder.ts b/src/TRPC/TRPCBuilder.ts similarity index 100% rename from src/Layers/trpc/TRPCBuilder.ts rename to src/TRPC/TRPCBuilder.ts diff --git a/src/Layers/trpc/TRPCContext.ts b/src/TRPC/TRPCContext.ts similarity index 100% rename from src/Layers/trpc/TRPCContext.ts rename to src/TRPC/TRPCContext.ts diff --git a/src/Layers/trpc/TRPCContextCreator.ts b/src/TRPC/TRPCContextCreator.ts similarity index 100% rename from src/Layers/trpc/TRPCContextCreator.ts rename to src/TRPC/TRPCContextCreator.ts diff --git a/src/Layers/trpc/TRPCExpressRoute.ts b/src/TRPC/TRPCExpressRoute.ts similarity index 91% rename from src/Layers/trpc/TRPCExpressRoute.ts rename to src/TRPC/TRPCExpressRoute.ts index 62cca46..411ecd5 100644 --- a/src/Layers/trpc/TRPCExpressRoute.ts +++ b/src/TRPC/TRPCExpressRoute.ts @@ -1,7 +1,7 @@ import type { AnyRouter } from "@trpc/server" import { Config, Context, Effect, Layer } from "effect" -import { ImportError } from "../../ImportError" -import { ExpressApp } from "../express" +import { ExpressApp } from "../Express" +import { ImportError } from "../ImportError" import { TRPCUnknownContextCreator } from "./TRPCContextCreator" diff --git a/src/Layers/trpc/TRPCRouter.ts b/src/TRPC/TRPCRouter.ts similarity index 100% rename from src/Layers/trpc/TRPCRouter.ts rename to src/TRPC/TRPCRouter.ts diff --git a/src/Layers/trpc/TRPCWebSocketServer.ts b/src/TRPC/TRPCWebSocketServer.ts similarity index 96% rename from src/Layers/trpc/TRPCWebSocketServer.ts rename to src/TRPC/TRPCWebSocketServer.ts index 19eb7be..9a95b0e 100644 --- a/src/Layers/trpc/TRPCWebSocketServer.ts +++ b/src/TRPC/TRPCWebSocketServer.ts @@ -2,8 +2,8 @@ import type { AnyRouter } from "@trpc/server" import type { applyWSSHandler } from "@trpc/server/adapters/ws" import { Config, Context, Effect, Layer } from "effect" import type ws from "ws" -import { ImportError } from "../../ImportError" -import { ExpressNodeHTTPServer } from "../express" +import { ExpressNodeHTTPServer } from "../Express" +import { ImportError } from "../ImportError" import { TRPCUnknownContextCreator } from "./TRPCContextCreator" diff --git a/src/Layers/trpc/createTRCPErrorMapper.ts b/src/TRPC/createTRCPErrorMapper.ts similarity index 100% rename from src/Layers/trpc/createTRCPErrorMapper.ts rename to src/TRPC/createTRCPErrorMapper.ts diff --git a/src/Layers/trpc/tests.ts b/src/TRPC/example.ts similarity index 86% rename from src/Layers/trpc/tests.ts rename to src/TRPC/example.ts index 3f2dd92..6052a5a 100644 --- a/src/Layers/trpc/tests.ts +++ b/src/TRPC/example.ts @@ -1,7 +1,6 @@ import { Config, Effect, Layer } from "effect" import * as TRPC from "." -import { JSONWebToken } from ".." -import { ExpressApp, ExpressNodeHTTPServer } from "../express" +import { Express, JSONWebToken } from ".." // Context available to the router procedures @@ -40,10 +39,10 @@ const ServerLive = Layer.empty.pipe( Layer.provideMerge(TRPCBuilderLive), Layer.provideMerge(TRPCContextCreatorLive), - Layer.provideMerge(ExpressNodeHTTPServer.ExpressNodeHTTPServerLive({ + Layer.provideMerge(Express.ExpressNodeHTTPServer.ExpressNodeHTTPServerLive({ port: Config.succeed(3000) })), - Layer.provideMerge(ExpressApp.ExpressAppLive()) + Layer.provideMerge(Express.ExpressApp.ExpressAppLive()) ) await Effect.gen(function*() { diff --git a/src/Layers/trpc/importTRPCServer.ts b/src/TRPC/importTRPCServer.ts similarity index 80% rename from src/Layers/trpc/importTRPCServer.ts rename to src/TRPC/importTRPCServer.ts index 26a5ea1..6377caa 100644 --- a/src/Layers/trpc/importTRPCServer.ts +++ b/src/TRPC/importTRPCServer.ts @@ -1,5 +1,5 @@ import { Effect } from "effect" -import { ImportError } from "../../ImportError" +import { ImportError } from "../ImportError" export const importTRPCServer = Effect.tryPromise({ diff --git a/src/Layers/trpc/index.ts b/src/TRPC/index.ts similarity index 100% rename from src/Layers/trpc/index.ts rename to src/TRPC/index.ts diff --git a/src/Layers/trpc/middlewares.ts b/src/TRPC/middlewares.ts similarity index 100% rename from src/Layers/trpc/middlewares.ts rename to src/TRPC/middlewares.ts diff --git a/src/index.ts b/src/index.ts index f18793d..f729f79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,6 @@ +export * as Express from "./Express" export * from "./ImportError" -export * as Layers from "./Layers" +export * as JSONWebToken from "./JSONWebToken" +export * as OpenAIClient from "./OpenAIClient" export * as Schema from "./Schema" export * as Types from "./Types" diff --git a/tsup.config.ts b/tsup.config.ts index 3ea8c21..12938ba 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig({ "./src/Schema/TanStackForm/index.ts", "./src/Types/index.ts", ], - format: ["esm", "cjs"], + format: ["esm"], skipNodeModulesBundle: true, dts: true, splitting: true,