From c14da85efd72a8156cd8ad631d43a6e0e2123289 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Tue, 20 Feb 2024 20:03:58 +0100 Subject: [PATCH 1/5] prep bun --- api/package.json | 5 +++-- api/tsconfig.json | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/api/package.json b/api/package.json index 0b51afc4..e16c271a 100644 --- a/api/package.json +++ b/api/package.json @@ -22,11 +22,12 @@ "test:run": "pnpm run test run --passWithNoTests", "testsuite": "pnpm circular && pnpm run test:run && pnpm lint", "dev": "NODE_ENV=development nodemon --signal SIGTERM --exec pnpm dev:vite", - "dev:compiled": "node -r source-map-support/register --inspect ./dist/main.js | ../scripts/humanlog.sh", - "dev:vite": "pnpm start:vite | ../scripts/humanlog.sh", + "dev:compiled": "bun --inspect ./dist/main.js | ../scripts/humanlog.sh", + "dev:vite": "pnpm start:bun | ../scripts/humanlog.sh", "start": "pnpm start:compiled", "start:compiled": "node -r source-map-support/register ./dist/main.js", "start:vite": "vite-node ./src/main.ts", + "start:bun": "bun ./src/main.ts", "ncu": "ncu", "extract:i18n": "formatjs extract './**/*.ts' --ignore './**/*.d.ts' --format src/i18n/extraction-formatter.cjs --id-interpolation-pattern '[sha512:contenthash:base64:6]' --out-file src/i18n/extracted/en.json" }, diff --git a/api/tsconfig.json b/api/tsconfig.json index e4ac2835..317be50d 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -1,5 +1,26 @@ { - "compilerOptions": {}, + "compilerOptions": { + "paths": { + "core/*": [ + "./src/core/*" + ], + "resources.js": [ + "./src/resources.js" + ], + "models.js": [ + "./src/models.js" + ], + "resources/*": [ + "./src/resources/*" + ], + "models/*": [ + "./src/models/*" + ], + "api/*": [ + "./src/*" + ] + }, + }, "extends": "../tsconfig.base.json", "references": [ { From 3c4b85f85e51e2c3d36a697fe10da02a2741bcc6 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Tue, 20 Feb 2024 20:05:05 +0100 Subject: [PATCH 2/5] Bundler --- api/tsconfig.src.json | 2 +- tsconfig.all2.json | 2 +- tsconfig.api.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/tsconfig.src.json b/api/tsconfig.src.json index fbf917c4..61a72697 100644 --- a/api/tsconfig.src.json +++ b/api/tsconfig.src.json @@ -9,7 +9,7 @@ "baseUrl": "./", "rootDir": "./src", // keep in here, cause madge can't detect it from extended tsconfig - "moduleResolution": "Node16", + "moduleResolution": "Bundler", "paths": { "core/*": [ "./src/core/*" diff --git a/tsconfig.all2.json b/tsconfig.all2.json index 342cf78e..6632fe18 100644 --- a/tsconfig.all2.json +++ b/tsconfig.all2.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "esModuleInterop": true, - "moduleResolution": "Node16", + "moduleResolution": "Bundler", "paths": { "api/*": [ "./api/src/*" diff --git a/tsconfig.api.json b/tsconfig.api.json index 2cab16cb..5c368156 100644 --- a/tsconfig.api.json +++ b/tsconfig.api.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "esModuleInterop": true, - "moduleResolution": "Node16" + "moduleResolution": "Bundler" }, "include": [ "api/src/**/*" From 2bac5f53464ede8d7a97ec42784faee82d7fccf2 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Tue, 20 Feb 2024 20:36:53 +0100 Subject: [PATCH 3/5] use bundler paths --- api/package.json | 2 +- api/src/Usecases.ts | 10 +++++----- api/src/Usecases/Blog.Controllers.ts | 10 +++++----- api/src/Usecases/HelloWorld.Controllers.ts | 8 ++++---- api/src/Usecases/Me.Controllers.ts | 6 +++--- api/src/Usecases/Operations.Controllers.ts | 6 +++--- api/src/Usecases/Users.Controllers.ts | 8 ++++---- api/src/_global.ext.ts | 6 +++--- api/src/api.ts | 14 +++++++------- api/src/config.ts | 4 ++-- api/src/lib/RequestEnv.ts | 10 +++++----- api/src/lib/matchFor.ts | 6 +++--- api/src/main.ts | 8 ++++---- api/src/middleware/Middlewares.ts | 2 +- api/src/middleware/RequestContextMiddleware.ts | 2 +- api/src/middleware/auth.ts | 2 +- api/src/middleware/events.ts | 6 +++--- api/src/middleware/health.ts | 2 +- api/src/middleware/index.ts | 12 ++++++------ api/src/middleware/internal/middlewares.ts | 4 ++-- api/src/migrate.ts | 2 +- api/src/models/Blog.ts | 2 +- api/src/models/roles.ts | 2 +- api/src/observability.ts | 2 +- api/src/resources.ts | 14 +++++++------- api/src/resources/Blog.ts | 8 ++++---- api/src/resources/Blog/CreatePost.ts | 4 ++-- api/src/resources/Blog/FindPost.ts | 6 +++--- api/src/resources/Blog/GetPosts.ts | 4 ++-- api/src/resources/Blog/PublishPost.ts | 4 ++-- api/src/resources/Events.ts | 2 +- api/src/resources/HelloWorld.ts | 2 +- api/src/resources/HelloWorld/Get.ts | 4 ++-- api/src/resources/Me.ts | 2 +- api/src/resources/Me/Get.ts | 4 ++-- api/src/resources/Operations.ts | 2 +- api/src/resources/Operations/Find.ts | 2 +- api/src/resources/Users.ts | 2 +- api/src/resources/Users/Index.ts | 6 +++--- api/src/resources/Views.ts | 4 ++-- api/src/resources/Views/PostView.ts | 6 +++--- api/src/resources/Views/UserView.ts | 4 ++-- api/src/resources/lib.ts | 6 +++--- api/src/resources/lib/operations.ts | 2 +- api/src/resources/lib/req.ts | 2 +- api/src/resources/lib/schema.ts | 2 +- api/src/resources/resolvers/UserResolver.ts | 6 +++--- api/src/routes.ts | 4 ++-- api/src/services.ts | 6 +++--- api/src/services/DBContext.ts | 4 ++-- api/src/services/DBContext/BlogPostRepo.ts | 6 +++--- api/src/services/DBContext/UserRepo.ts | 10 +++++----- api/src/services/Events.ts | 2 +- api/src/services/UserProfile.ts | 2 +- api/tsconfig.json | 8 ++++---- api/tsconfig.src.json | 8 ++++---- tsconfig.base.json | 5 ++++- 57 files changed, 146 insertions(+), 143 deletions(-) diff --git a/api/package.json b/api/package.json index e16c271a..af706ac0 100644 --- a/api/package.json +++ b/api/package.json @@ -24,7 +24,7 @@ "dev": "NODE_ENV=development nodemon --signal SIGTERM --exec pnpm dev:vite", "dev:compiled": "bun --inspect ./dist/main.js | ../scripts/humanlog.sh", "dev:vite": "pnpm start:bun | ../scripts/humanlog.sh", - "start": "pnpm start:compiled", + "start": "pnpm start:bun", "start:compiled": "node -r source-map-support/register ./dist/main.js", "start:vite": "vite-node ./src/main.ts", "start:bun": "bun ./src/main.ts", diff --git a/api/src/Usecases.ts b/api/src/Usecases.ts index 0c10a538..60691680 100644 --- a/api/src/Usecases.ts +++ b/api/src/Usecases.ts @@ -1,9 +1,9 @@ // codegen:start {preset: barrel, include: ./Usecases/*.ts, import: default} -import usecasesBlogControllers from "./Usecases/Blog.Controllers.js" -import usecasesHelloWorldControllers from "./Usecases/HelloWorld.Controllers.js" -import usecasesMeControllers from "./Usecases/Me.Controllers.js" -import usecasesOperationsControllers from "./Usecases/Operations.Controllers.js" -import usecasesUsersControllers from "./Usecases/Users.Controllers.js" +import usecasesBlogControllers from "./Usecases/Blog.Controllers" +import usecasesHelloWorldControllers from "./Usecases/HelloWorld.Controllers" +import usecasesMeControllers from "./Usecases/Me.Controllers" +import usecasesOperationsControllers from "./Usecases/Operations.Controllers" +import usecasesUsersControllers from "./Usecases/Users.Controllers" export { usecasesBlogControllers, diff --git a/api/src/Usecases/Blog.Controllers.ts b/api/src/Usecases/Blog.Controllers.ts index 93a7cfd0..63f5ba09 100644 --- a/api/src/Usecases/Blog.Controllers.ts +++ b/api/src/Usecases/Blog.Controllers.ts @@ -1,10 +1,10 @@ -import { matchFor } from "api/lib/matchFor.js" -import { BlogPostRepo, Events, forkOperationWithEffect, Operations, UserRepo } from "api/services.js" +import { matchFor } from "api/lib/matchFor" +import { BlogPostRepo, Events, forkOperationWithEffect, Operations, UserRepo } from "api/services" import { Duration, Effect, Schedule } from "effect" import { NonNegativeInt } from "effect-app/schema" -import { BlogPost } from "models/Blog.js" -import { BlogRsc } from "resources.js" -import { BogusEvent } from "resources/Events.js" +import { BlogPost } from "models/Blog" +import { BlogRsc } from "resources" +import { BogusEvent } from "resources/Events" const blog = matchFor(BlogRsc) diff --git a/api/src/Usecases/HelloWorld.Controllers.ts b/api/src/Usecases/HelloWorld.Controllers.ts index 5c769b4a..25f94f78 100644 --- a/api/src/Usecases/HelloWorld.Controllers.ts +++ b/api/src/Usecases/HelloWorld.Controllers.ts @@ -1,9 +1,9 @@ import { generateFromArbitrary } from "@effect-app/infra/test.arbs" -import { matchFor } from "api/lib/matchFor.js" -import { UserRepo } from "api/services.js" +import { matchFor } from "api/lib/matchFor" +import { UserRepo } from "api/services" import { Effect, S } from "effect-app" -import { User } from "models/User.js" -import { HelloWorldRsc } from "resources.js" +import { User } from "models/User" +import { HelloWorldRsc } from "resources" const helloWorld = matchFor(HelloWorldRsc) diff --git a/api/src/Usecases/Me.Controllers.ts b/api/src/Usecases/Me.Controllers.ts index 76d41eb9..2d953fd1 100644 --- a/api/src/Usecases/Me.Controllers.ts +++ b/api/src/Usecases/Me.Controllers.ts @@ -1,6 +1,6 @@ -import { matchFor } from "api/lib/matchFor.js" -import { UserRepo } from "api/services.js" -import { MeRsc } from "resources.js" +import { matchFor } from "api/lib/matchFor" +import { UserRepo } from "api/services" +import { MeRsc } from "resources" const me = matchFor(MeRsc) diff --git a/api/src/Usecases/Operations.Controllers.ts b/api/src/Usecases/Operations.Controllers.ts index 4783fa2f..60fc43e9 100644 --- a/api/src/Usecases/Operations.Controllers.ts +++ b/api/src/Usecases/Operations.Controllers.ts @@ -1,6 +1,6 @@ -import { matchFor } from "api/lib/matchFor.js" -import { Operations } from "api/services.js" -import { OperationsRsc } from "resources.js" +import { matchFor } from "api/lib/matchFor" +import { Operations } from "api/services" +import { OperationsRsc } from "resources" const operations = matchFor(OperationsRsc) diff --git a/api/src/Usecases/Users.Controllers.ts b/api/src/Usecases/Users.Controllers.ts index c007030f..c9aa0eb2 100644 --- a/api/src/Usecases/Users.Controllers.ts +++ b/api/src/Usecases/Users.Controllers.ts @@ -1,9 +1,9 @@ -import { matchFor } from "api/lib/matchFor.js" -import { UserRepo } from "api/services.js" +import { matchFor } from "api/lib/matchFor" +import { UserRepo } from "api/services" import { ReadonlyArray } from "effect" import { Order } from "effect-app" -import { UsersRsc } from "resources.js" -import type { UserView } from "resources/Views.js" +import { UsersRsc } from "resources" +import type { UserView } from "resources/Views" const users = matchFor(UsersRsc) diff --git a/api/src/_global.ext.ts b/api/src/_global.ext.ts index 602bed65..e9f2ce75 100644 --- a/api/src/_global.ext.ts +++ b/api/src/_global.ext.ts @@ -1,3 +1,3 @@ -import type {} from "./services/DBContext.js" -import type {} from "./services/Events.js" -import type {} from "./services/UserProfile.js" +import type {} from "./services/DBContext" +import type {} from "./services/Events" +import type {} from "./services/UserProfile" diff --git a/api/src/api.ts b/api/src/api.ts index 152ffe97..b9cf243f 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -6,16 +6,16 @@ import { Live as OperationsLive } from "@effect-app/infra/services/Operations/li import { RequestContextContainer } from "@effect-app/infra/services/RequestContextContainer" import { ContextMapContainer } from "@effect-app/infra/services/Store/ContextMapContainer" import { NodeContext } from "@effect/platform-node" -import { all } from "api/routes.js" +import { all } from "api/routes" import { Effect, Layer, Ref } from "effect-app" import { GenericTag } from "effect/Context" import { createServer } from "node:http" -import { MergedConfig } from "./config.js" -import { HttpClientNode, HttpMiddleware, HttpNode, HttpRouter, HttpServer } from "./lib/http.js" -import * as MW from "./middleware/index.js" -import { RequestContextMiddleware } from "./middleware/index.js" -import { BlogPostRepo, UserRepo } from "./services.js" -import { Events } from "./services/Events.js" +import { MergedConfig } from "./config" +import { HttpClientNode, HttpMiddleware, HttpNode, HttpRouter, HttpServer } from "./lib/http" +import * as MW from "./middleware/index" +import { RequestContextMiddleware } from "./middleware/index" +import { BlogPostRepo, UserRepo } from "./services" +import { Events } from "./services/Events" export const devApi = MergedConfig .andThen((cfg) => { diff --git a/api/src/config.ts b/api/src/config.ts index 3ed4f73e..372ce455 100644 --- a/api/src/config.ts +++ b/api/src/config.ts @@ -1,7 +1,7 @@ import { Config, Effect } from "effect-app" import { secretURL } from "effect-app/Config/SecretURL" import * as SecretURL from "effect-app/Config/SecretURL" -import { BaseConfig } from "./baseConfig.js" +import { BaseConfig } from "./baseConfig" const STORAGE_VERSION = "1" @@ -49,7 +49,7 @@ export interface ApiConfig extends ConfigA {} export interface ApiMainConfig extends ApiConfig, BaseConfig {} -export * from "./baseConfig.js" +export * from "./baseConfig" export const MergedConfig = ApiConfig .andThen((apiConfig) => BaseConfig.andThen((baseConfig) => ({ ...baseConfig, ...apiConfig }))) diff --git a/api/src/lib/RequestEnv.ts b/api/src/lib/RequestEnv.ts index 12b35025..a6a44ca3 100644 --- a/api/src/lib/RequestEnv.ts +++ b/api/src/lib/RequestEnv.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/ban-types */ -import { Role } from "models/User.js" +import { Role } from "models/User" import { HttpServerRequest } from "@effect-app/infra/api/http" import { JWTError, type RequestHandler } from "@effect-app/infra/api/routing" @@ -8,17 +8,17 @@ import type { RequestContext } from "@effect-app/infra/RequestContext" import { RequestContextContainer } from "@effect-app/infra/services/RequestContextContainer" import type { StructFields } from "@effect-app/schema" import { Req as Req_ } from "@effect-app/schema/REST" -import { NotLoggedInError, UnauthorizedError } from "api/errors.js" -import { Auth0Config, checkJWTI } from "api/middleware/auth.js" +import { NotLoggedInError, UnauthorizedError } from "api/errors" +import { Auth0Config, checkJWTI } from "api/middleware/auth" import { Duration, Effect, Exit, Layer, Option, Request } from "effect-app" import { makeUserProfileFromAuthorizationHeader, makeUserProfileFromUserHeader, UserProfile -} from "../services/UserProfile.js" +} from "../services/UserProfile" // Workaround for the error when using -// import type { AllowAnonymous, RequestConfig } from "resources/lib.js" +// import type { AllowAnonymous, RequestConfig } from "resources/lib" export type RequestConfig = { allowAnonymous?: true; allowedRoles?: readonly Role[] } diff --git a/api/src/lib/matchFor.ts b/api/src/lib/matchFor.ts index 3f8b44c7..0355c4ee 100644 --- a/api/src/lib/matchFor.ts +++ b/api/src/lib/matchFor.ts @@ -19,9 +19,9 @@ import { defaultErrorHandler, match } from "@effect-app/infra/api/routing" import { Effect, S } from "effect-app" import type { SupportedErrors } from "effect-app/client/errors" import { REST } from "effect-app/schema" -import { handleRequestEnv } from "./RequestEnv.js" -import type { CTX, GetContext, GetCTX, RequestEnv } from "./RequestEnv.js" -import type {} from "resources/lib.js" +import { handleRequestEnv } from "./RequestEnv" +import type { CTX, GetContext, GetCTX, RequestEnv } from "./RequestEnv" +import type {} from "resources/lib" function handle< TModule extends Record< diff --git a/api/src/main.ts b/api/src/main.ts index fbf7f4ce..f8ffb4df 100644 --- a/api/src/main.ts +++ b/api/src/main.ts @@ -1,13 +1,13 @@ import "@effect-app/fluent-extensions" -import { runMain } from "./lib/basicRuntime.js" +import { runMain } from "./lib/basicRuntime" /* eslint-disable @typescript-eslint/no-explicit-any */ import { faker } from "@faker-js/faker" -import { api, devApi } from "api/api.js" +import { api, devApi } from "api/api" import { Layer } from "effect-app" import { setFaker } from "effect-app/faker" -import { MergedConfig } from "./config.js" -import { TracingLive } from "./observability.js" +import { MergedConfig } from "./config" +import { TracingLive } from "./observability" setFaker(faker) diff --git a/api/src/middleware/Middlewares.ts b/api/src/middleware/Middlewares.ts index c8faa6e5..e2834bce 100644 --- a/api/src/middleware/Middlewares.ts +++ b/api/src/middleware/Middlewares.ts @@ -6,7 +6,7 @@ import type { NotLoggedInError } from "@effect-app/infra/errors" import type * as App from "@effect/platform/Http/App" import type { Effect } from "effect-app" -import * as internal from "./internal/middlewares.js" +import * as internal from "./internal/middlewares" /** * Add access logs for handled requests. The log runs before each request. diff --git a/api/src/middleware/RequestContextMiddleware.ts b/api/src/middleware/RequestContextMiddleware.ts index f3200bbf..0e56d082 100644 --- a/api/src/middleware/RequestContextMiddleware.ts +++ b/api/src/middleware/RequestContextMiddleware.ts @@ -1,6 +1,6 @@ import { setupRequestContext } from "@effect-app/infra/api/setupRequest" import { RequestContext } from "@effect-app/infra/RequestContext" -import { HttpMiddleware, HttpServerRequest, HttpServerResponse } from "api/lib/http.js" +import { HttpMiddleware, HttpServerRequest, HttpServerResponse } from "api/lib/http" import { Effect, S } from "effect-app" import { RequestId } from "effect-app/ids" import { NonEmptyString255 } from "effect-app/schema" diff --git a/api/src/middleware/auth.ts b/api/src/middleware/auth.ts index 0e02714d..e44b15af 100644 --- a/api/src/middleware/auth.ts +++ b/api/src/middleware/auth.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable unused-imports/no-unused-vars */ -import { HttpHeaders, HttpMiddleware, HttpServerRequest, HttpServerResponse } from "api/lib/http.js" +import { HttpHeaders, HttpMiddleware, HttpServerRequest, HttpServerResponse } from "api/lib/http" import { Config, Effect } from "effect-app" import { auth, diff --git a/api/src/middleware/events.ts b/api/src/middleware/events.ts index cce9be12..d0b34361 100644 --- a/api/src/middleware/events.ts +++ b/api/src/middleware/events.ts @@ -1,9 +1,9 @@ import { setupRequestContext } from "@effect-app/infra/api/setupRequest" import { reportError } from "@effect-app/infra/errorReporter" -import { HttpHeaders, HttpServerResponse } from "api/lib/http.js" +import { HttpHeaders, HttpServerResponse } from "api/lib/http" import { Duration, Effect, S, Schedule, Stream } from "effect-app" -import { ClientEvents } from "resources.js" -import { Events } from "../services/Events.js" +import { ClientEvents } from "resources" +import { Events } from "../services/Events" export const events = Effect .gen(function*($) { diff --git a/api/src/middleware/health.ts b/api/src/middleware/health.ts index 391d26df..8cfa7350 100644 --- a/api/src/middleware/health.ts +++ b/api/src/middleware/health.ts @@ -1,4 +1,4 @@ -import { HttpMiddleware, HttpRouter, HttpServerResponse } from "api/lib/http.js" +import { HttpMiddleware, HttpRouter, HttpServerResponse } from "api/lib/http" export function serverHealth(version: string) { return HttpRouter.get( diff --git a/api/src/middleware/index.ts b/api/src/middleware/index.ts index 36143638..06dbbd50 100644 --- a/api/src/middleware/index.ts +++ b/api/src/middleware/index.ts @@ -1,8 +1,8 @@ // codegen:start {preset: barrel, include: ./*.ts} -export * from "./auth.js" -export * from "./events.js" -export * from "./health.js" -export * from "./Middlewares.js" -export * from "./openapi.js" -export * from "./RequestContextMiddleware.js" +export * from "./auth" +export * from "./events" +export * from "./health" +export * from "./Middlewares" +export * from "./openapi" +export * from "./RequestContextMiddleware" // codegen:end diff --git a/api/src/middleware/internal/middlewares.ts b/api/src/middleware/internal/middlewares.ts index 2f6a8eb7..69140800 100644 --- a/api/src/middleware/internal/middlewares.ts +++ b/api/src/middleware/internal/middlewares.ts @@ -10,14 +10,14 @@ import { NotLoggedInError } from "@effect-app/infra/errors" import * as Middleware from "@effect/platform/Http/Middleware" import * as ServerRequest from "@effect/platform/Http/ServerRequest" import * as ServerResponse from "@effect/platform/Http/ServerResponse" -import { HttpBody, HttpHeaders, HttpServerResponse } from "api/lib/http.js" +import { HttpBody, HttpHeaders, HttpServerResponse } from "api/lib/http" import { Effect } from "effect-app" import * as Either from "effect/Either" import * as FiberRef from "effect/FiberRef" import { pipe } from "effect/Function" import * as HashMap from "effect/HashMap" import * as Metric from "effect/Metric" -import type * as Middlewares from "../Middlewares.js" +import type * as Middlewares from "../Middlewares" export const accessLog = (level: "Info" | "Warning" | "Debug" = "Info") => Middleware.make((app) => diff --git a/api/src/migrate.ts b/api/src/migrate.ts index 4193ef2e..3effd5c8 100644 --- a/api/src/migrate.ts +++ b/api/src/migrate.ts @@ -4,7 +4,7 @@ import { ContextMapContainer } from "@effect-app/infra/services/Store/ContextMap import { StoreMakerLayer } from "@effect-app/infra/services/Store/index" import * as HttpClientNode from "@effect/platform-node/NodeHttpClient" import { Layer } from "effect-app" -import { SendgridConfig, StorageConfig } from "./config.js" +import { SendgridConfig, StorageConfig } from "./config" export const RepoLive = StorageConfig .andThen(StoreMakerLayer) diff --git a/api/src/models/Blog.ts b/api/src/models/Blog.ts index f76dab69..0dc52bca 100644 --- a/api/src/models/Blog.ts +++ b/api/src/models/Blog.ts @@ -1,5 +1,5 @@ import { S } from "effect-app" -import { UserFromId } from "./User.js" +import { UserFromId } from "./User" export const BlogPostId = S.prefixedStringId()("post", "BlogPostId") export interface BlogPostIdBrand { diff --git a/api/src/models/roles.ts b/api/src/models/roles.ts index 178cbef9..bbceceaf 100644 --- a/api/src/models/roles.ts +++ b/api/src/models/roles.ts @@ -1,6 +1,6 @@ // Poor man's RBAC -import type { Role } from "./User.js" +import type { Role } from "./User" /** * Allow role access diff --git a/api/src/observability.ts b/api/src/observability.ts index 241c8013..40d7c7f4 100644 --- a/api/src/observability.ts +++ b/api/src/observability.ts @@ -21,7 +21,7 @@ import { } from "@sentry/opentelemetry" import { Effect, Layer, Secret } from "effect-app" import tcpPortUsed from "tcp-port-used" -import { BaseConfig } from "./config.js" +import { BaseConfig } from "./config" const appConfig = BaseConfig.runSync diff --git a/api/src/resources.ts b/api/src/resources.ts index b939810e..c008c57a 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -1,12 +1,12 @@ -import "./resources/lib/operations.js" +import "./resources/lib/operations" import type {} from "@effect/platform/Http/Client" -export { ClientEvents } from "./resources/Events.js" +export { ClientEvents } from "./resources/Events" // codegen:start {preset: barrel, include: ./resources/*.ts, exclude: [./resources/_global*.ts, ./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/Views.ts, ./resources/errors.ts, ./resources/Events.ts], export: { as: 'PascalCase', postfix: 'Rsc' }} -export * as BlogRsc from "./resources/Blog.js" -export * as HelloWorldRsc from "./resources/HelloWorld.js" -export * as MeRsc from "./resources/Me.js" -export * as OperationsRsc from "./resources/Operations.js" -export * as UsersRsc from "./resources/Users.js" +export * as BlogRsc from "./resources/Blog" +export * as HelloWorldRsc from "./resources/HelloWorld" +export * as MeRsc from "./resources/Me" +export * as OperationsRsc from "./resources/Operations" +export * as UsersRsc from "./resources/Users" // codegen:end diff --git a/api/src/resources/Blog.ts b/api/src/resources/Blog.ts index 8383f916..01f20ead 100644 --- a/api/src/resources/Blog.ts +++ b/api/src/resources/Blog.ts @@ -1,8 +1,8 @@ // codegen:start {preset: barrel, include: ./Blog/*.ts, export: { as: 'PascalCase' }, nodir: false } -export * as CreatePost from "./Blog/CreatePost.js" -export * as FindPost from "./Blog/FindPost.js" -export * as GetPosts from "./Blog/GetPosts.js" -export * as PublishPost from "./Blog/PublishPost.js" +export * as CreatePost from "./Blog/CreatePost" +export * as FindPost from "./Blog/FindPost" +export * as GetPosts from "./Blog/GetPosts" +export * as PublishPost from "./Blog/PublishPost" // codegen:end // codegen:start {preset: meta, sourcePrefix: src/resources/} export const meta = { moduleName: "Blog" } diff --git a/api/src/resources/Blog/CreatePost.ts b/api/src/resources/Blog/CreatePost.ts index 99df57e6..4513616f 100644 --- a/api/src/resources/Blog/CreatePost.ts +++ b/api/src/resources/Blog/CreatePost.ts @@ -1,5 +1,5 @@ -import { BlogPost, BlogPostId } from "models/Blog.js" -import { S } from "resources/lib.js" +import { BlogPost, BlogPostId } from "models/Blog" +import { S } from "resources/lib" export class CreatePostRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()( BlogPost.pick("title", "body") diff --git a/api/src/resources/Blog/FindPost.ts b/api/src/resources/Blog/FindPost.ts index 4f5a9496..a561eb72 100644 --- a/api/src/resources/Blog/FindPost.ts +++ b/api/src/resources/Blog/FindPost.ts @@ -1,6 +1,6 @@ -import { BlogPostId } from "models/Blog.js" -import { S } from "resources/lib.js" -import { BlogPostView } from "../Views.js" +import { BlogPostId } from "models/Blog" +import { S } from "resources/lib" +import { BlogPostView } from "../Views" export class FindPostRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({ id: BlogPostId diff --git a/api/src/resources/Blog/GetPosts.ts b/api/src/resources/Blog/GetPosts.ts index d82f9ccf..c0b5c52b 100644 --- a/api/src/resources/Blog/GetPosts.ts +++ b/api/src/resources/Blog/GetPosts.ts @@ -1,5 +1,5 @@ -import { S } from "resources/lib.js" -import { BlogPostView } from "../Views.js" +import { S } from "resources/lib" +import { BlogPostView } from "../Views" export class GetPostsRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({}) {} diff --git a/api/src/resources/Blog/PublishPost.ts b/api/src/resources/Blog/PublishPost.ts index 13e46a47..98b45778 100644 --- a/api/src/resources/Blog/PublishPost.ts +++ b/api/src/resources/Blog/PublishPost.ts @@ -1,6 +1,6 @@ import { OperationId } from "effect-app/Operations" -import { BlogPostId } from "models/Blog.js" -import { S } from "resources/lib.js" +import { BlogPostId } from "models/Blog" +import { S } from "resources/lib" export class PublishPostRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({ id: BlogPostId diff --git a/api/src/resources/Events.ts b/api/src/resources/Events.ts index 0b2c947e..89915f54 100644 --- a/api/src/resources/Events.ts +++ b/api/src/resources/Events.ts @@ -1,5 +1,5 @@ import type { Schema } from "effect-app/schema" -import { S } from "resources/lib.js" +import { S } from "resources/lib" export class BogusEvent extends S.ExtendedTaggedClass()("BogusEvent", { id: S.StringId.withDefault, diff --git a/api/src/resources/HelloWorld.ts b/api/src/resources/HelloWorld.ts index 02432c02..c6058820 100644 --- a/api/src/resources/HelloWorld.ts +++ b/api/src/resources/HelloWorld.ts @@ -1,5 +1,5 @@ // codegen:start {preset: barrel, include: ./HelloWorld/*.ts, export: { as: 'PascalCase' }, nodir: false } -export * as Get from "./HelloWorld/Get.js" +export * as Get from "./HelloWorld/Get" // codegen:end // codegen:start {preset: meta, sourcePrefix: src/resources/} diff --git a/api/src/resources/HelloWorld/Get.ts b/api/src/resources/HelloWorld/Get.ts index d43fae83..f6aea1b4 100644 --- a/api/src/resources/HelloWorld/Get.ts +++ b/api/src/resources/HelloWorld/Get.ts @@ -1,5 +1,5 @@ -import { S } from "resources/lib.js" -import { UserView } from "../Views.js" +import { S } from "resources/lib" +import { UserView } from "../Views" export class GetHelloWorldRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({ diff --git a/api/src/resources/Me.ts b/api/src/resources/Me.ts index b7d6f6d7..459ecfd0 100644 --- a/api/src/resources/Me.ts +++ b/api/src/resources/Me.ts @@ -1,5 +1,5 @@ // codegen:start {preset: barrel, include: ./Me/*.ts, export: { as: 'PascalCase' }, nodir: false } -export * as Get from "./Me/Get.js" +export * as Get from "./Me/Get" // codegen:end // codegen:start {preset: meta, sourcePrefix: src/resources/} diff --git a/api/src/resources/Me/Get.ts b/api/src/resources/Me/Get.ts index 7bac7095..a1b21763 100644 --- a/api/src/resources/Me/Get.ts +++ b/api/src/resources/Me/Get.ts @@ -1,5 +1,5 @@ -import { User } from "models/User.js" -import { S } from "resources/lib.js" +import { User } from "models/User" +import { S } from "resources/lib" export class GetMeRequest extends S.Req()()({}) {} diff --git a/api/src/resources/Operations.ts b/api/src/resources/Operations.ts index f6f0180b..648e4a46 100644 --- a/api/src/resources/Operations.ts +++ b/api/src/resources/Operations.ts @@ -1,5 +1,5 @@ // codegen:start {preset: barrel, include: ./Operations/*.ts, export: { as: 'PascalCase' }, nodir: false } -export * as Find from "./Operations/Find.js" +export * as Find from "./Operations/Find" // codegen:end // codegen:start {preset: meta, sourcePrefix: src/resources/} diff --git a/api/src/resources/Operations/Find.ts b/api/src/resources/Operations/Find.ts index dbb3adf8..9ca5604b 100644 --- a/api/src/resources/Operations/Find.ts +++ b/api/src/resources/Operations/Find.ts @@ -1,5 +1,5 @@ import { Operation, OperationId } from "effect-app/Operations" -import { S } from "resources/lib.js" +import { S } from "resources/lib" export class FindOperationRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({ diff --git a/api/src/resources/Users.ts b/api/src/resources/Users.ts index 826b0a72..a81a866c 100644 --- a/api/src/resources/Users.ts +++ b/api/src/resources/Users.ts @@ -1,5 +1,5 @@ // codegen:start {preset: barrel, include: ./Users/*.ts, export: { as: 'PascalCase' }, nodir: false } -export * as Index from "./Users/Index.js" +export * as Index from "./Users/Index" // codegen:end // codegen:start {preset: meta, sourcePrefix: src/resources/} diff --git a/api/src/resources/Users/Index.ts b/api/src/resources/Users/Index.ts index 0ca616d7..6c5dc35d 100644 --- a/api/src/resources/Users/Index.ts +++ b/api/src/resources/Users/Index.ts @@ -1,6 +1,6 @@ -import { UserId } from "models/User.js" -import { S } from "resources/lib.js" -import { UserView } from "../Views/UserView.js" +import { UserId } from "models/User" +import { S } from "resources/lib" +import { UserView } from "../Views/UserView" export class IndexUsersRequest extends S.Req({ allowAnonymous: true, allowRoles: ["user"] })()({ filterByIds: S.nonEmptyArray(UserId) diff --git a/api/src/resources/Views.ts b/api/src/resources/Views.ts index 8cb16080..685267a5 100644 --- a/api/src/resources/Views.ts +++ b/api/src/resources/Views.ts @@ -1,4 +1,4 @@ // codegen:start {preset: barrel, include: ./Views/*.ts} -export * from "./Views/PostView.js" -export * from "./Views/UserView.js" +export * from "./Views/PostView" +export * from "./Views/UserView" // codegen:end diff --git a/api/src/resources/Views/PostView.ts b/api/src/resources/Views/PostView.ts index e0028893..cc1df3f2 100644 --- a/api/src/resources/Views/PostView.ts +++ b/api/src/resources/Views/PostView.ts @@ -1,6 +1,6 @@ -import { BlogPost } from "models/Blog.js" -import { S } from "resources/lib.js" -import { UserViewFromId } from "../resolvers/UserResolver.js" +import { BlogPost } from "models/Blog" +import { S } from "resources/lib" +import { UserViewFromId } from "../resolvers/UserResolver" export class BlogPostView extends S.ExtendedClass()({ ...BlogPost.omit("author"), diff --git a/api/src/resources/Views/UserView.ts b/api/src/resources/Views/UserView.ts index 29853f93..642df5fe 100644 --- a/api/src/resources/Views/UserView.ts +++ b/api/src/resources/Views/UserView.ts @@ -1,5 +1,5 @@ -import { User } from "models/User.js" -import { S } from "resources/lib.js" +import { User } from "models/User" +import { S } from "resources/lib" export class UserView extends S.ExtendedClass()({ ...User.pick("id", "role"), diff --git a/api/src/resources/lib.ts b/api/src/resources/lib.ts index c970d2f2..a42918c7 100644 --- a/api/src/resources/lib.ts +++ b/api/src/resources/lib.ts @@ -1,6 +1,6 @@ // codegen:start {preset: barrel, include: ./lib/*.ts, exclude: ./lib/schema.ts} -export * from "./lib/operations.js" -export * from "./lib/req.js" +export * from "./lib/operations" +export * from "./lib/req" // codegen:end -export * as S from "./lib/schema.js" +export * as S from "./lib/schema" diff --git a/api/src/resources/lib/operations.ts b/api/src/resources/lib/operations.ts index b3c07278..49f9431e 100644 --- a/api/src/resources/lib/operations.ts +++ b/api/src/resources/lib/operations.ts @@ -1,7 +1,7 @@ import { Duration, Effect } from "effect-app" import { clientFor, type FetchResponse } from "effect-app/client" import type { Operation, OperationId } from "effect-app/Operations" -import * as OperationsRsc from "../Operations.js" +import * as OperationsRsc from "../Operations" const opsClient = clientFor(OperationsRsc) diff --git a/api/src/resources/lib/req.ts b/api/src/resources/lib/req.ts index 03fb0ca1..4bff30fc 100644 --- a/api/src/resources/lib/req.ts +++ b/api/src/resources/lib/req.ts @@ -1,4 +1,4 @@ -import type { Role } from "models/User.js" +import type { Role } from "models/User" import { Req as Req_ } from "@effect-app/schema/REST" diff --git a/api/src/resources/lib/schema.ts b/api/src/resources/lib/schema.ts index 208e4139..5fb76e08 100644 --- a/api/src/resources/lib/schema.ts +++ b/api/src/resources/lib/schema.ts @@ -1,3 +1,3 @@ -export { Req } from "./req.js" +export { Req } from "./req" export * from "effect-app/schema" diff --git a/api/src/resources/resolvers/UserResolver.ts b/api/src/resources/resolvers/UserResolver.ts index 1b1b7ea9..8e78ca1f 100644 --- a/api/src/resources/resolvers/UserResolver.ts +++ b/api/src/resources/resolvers/UserResolver.ts @@ -3,9 +3,9 @@ import { Option, S } from "effect-app" import { ApiConfig, clientFor, NotFoundError } from "effect-app/client" import { HttpClient } from "effect-app/http" import { type Schema } from "effect-app/schema" -import { UserId } from "models/User.js" -import * as UsersRsc from "../Users.js" -import { UserView } from "../Views/UserView.js" +import { UserId } from "models/User" +import * as UsersRsc from "../Users" +import { UserView } from "../Views/UserView" interface GetUserViewById extends Request.Request> { readonly _tag: "GetUserViewById" diff --git a/api/src/routes.ts b/api/src/routes.ts index 3550ceba..21af2613 100644 --- a/api/src/routes.ts +++ b/api/src/routes.ts @@ -1,5 +1,5 @@ import { Effect } from "effect-app" -import { matchAll } from "./lib/matchFor.js" -import * as Controllers from "./Usecases.js" +import { matchAll } from "./lib/matchFor" +import * as Controllers from "./Usecases" export const all = Effect.all(matchAll(Controllers)) diff --git a/api/src/services.ts b/api/src/services.ts index f89cb836..f4c3d725 100644 --- a/api/src/services.ts +++ b/api/src/services.ts @@ -1,7 +1,7 @@ // codegen:start {preset: barrel, include: services/*.ts } -export * from "./services/DBContext.js" -export * from "./services/Events.js" -export * from "./services/UserProfile.js" +export * from "./services/DBContext" +export * from "./services/Events" +export * from "./services/UserProfile" // codegen:end export * from "@effect-app/infra-adapters/memQueue" diff --git a/api/src/services/DBContext.ts b/api/src/services/DBContext.ts index f3dec88d..3e4c12d2 100644 --- a/api/src/services/DBContext.ts +++ b/api/src/services/DBContext.ts @@ -1,4 +1,4 @@ // codegen:start {preset: barrel, include: ./DBContext/* } -export * from "./DBContext/BlogPostRepo.js" -export * from "./DBContext/UserRepo.js" +export * from "./DBContext/BlogPostRepo" +export * from "./DBContext/UserRepo" // codegen:end diff --git a/api/src/services/DBContext/BlogPostRepo.ts b/api/src/services/DBContext/BlogPostRepo.ts index a6353672..c09df23c 100644 --- a/api/src/services/DBContext/BlogPostRepo.ts +++ b/api/src/services/DBContext/BlogPostRepo.ts @@ -1,9 +1,9 @@ import { RepositoryDefaultImpl } from "@effect-app/infra/services/RepositoryBase" -import { RepoLive } from "api/migrate.js" +import { RepoLive } from "api/migrate" import { Effect, Layer } from "effect" import { NonEmptyString255, NonEmptyString2k } from "effect-app/schema" -import { BlogPost } from "models/Blog.js" -import { UserRepo } from "./UserRepo.js" +import { BlogPost } from "models/Blog" +import { UserRepo } from "./UserRepo" export interface BlogPostPersistenceModel extends BlogPost.From { _etag: string | undefined diff --git a/api/src/services/DBContext/UserRepo.ts b/api/src/services/DBContext/UserRepo.ts index 835784c0..084c0e1a 100644 --- a/api/src/services/DBContext/UserRepo.ts +++ b/api/src/services/DBContext/UserRepo.ts @@ -1,15 +1,15 @@ import { NotFoundError, NotLoggedInError } from "@effect-app/infra/errors" import { RepositoryDefaultImpl } from "@effect-app/infra/services/RepositoryBase" import { generate, generateFromArbitrary } from "@effect-app/infra/test.arbs" -import { RepoConfig } from "api/config.js" -import { RepoLive } from "api/migrate.js" +import { RepoConfig } from "api/config" +import { RepoLive } from "api/migrate" import { Effect, Exit, Layer, Option, ReadonlyArray, Request, RequestResolver, S } from "effect-app" import { fakerArb } from "effect-app/faker" import { Email } from "effect-app/schema" import fc from "fast-check" -import type { UserId } from "models/User.js" -import { User } from "models/User.js" -import { UserProfile } from "../UserProfile.js" +import type { UserId } from "models/User" +import { User } from "models/User" +import { UserProfile } from "../UserProfile" export interface UserPersistenceModel extends User.From { _etag: string | undefined diff --git a/api/src/services/Events.ts b/api/src/services/Events.ts index 53bed140..44f825a7 100644 --- a/api/src/services/Events.ts +++ b/api/src/services/Events.ts @@ -2,7 +2,7 @@ import { storeId } from "@effect-app/infra/services/Store/Memory" import { Effect, FiberRef, PubSub, Stream } from "effect-app" import { TagClassMakeId } from "effect-app/service" import type { NonEmptyReadonlyArray } from "effect/ReadonlyArray" -import type { ClientEvents } from "resources.js" +import type { ClientEvents } from "resources" const makeEvents = Effect.gen(function*($) { const q = yield* $(PubSub.unbounded<{ evt: ClientEvents; namespace: string }>()) diff --git a/api/src/services/UserProfile.ts b/api/src/services/UserProfile.ts index 46c9c4ab..3459af47 100644 --- a/api/src/services/UserProfile.ts +++ b/api/src/services/UserProfile.ts @@ -2,7 +2,7 @@ import { parseJwt } from "@effect-app/infra/api/express/schema/jwt" import { S } from "effect-app" import { UserProfileId } from "effect-app/ids" import { assignTag } from "effect-app/service" -import { Role } from "models/User.js" +import { Role } from "models/User" export class UserProfile extends assignTag()( S.Class()({ diff --git a/api/tsconfig.json b/api/tsconfig.json index 317be50d..2c9583b4 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -4,11 +4,11 @@ "core/*": [ "./src/core/*" ], - "resources.js": [ - "./src/resources.js" + "resources": [ + "./src/resources" ], - "models.js": [ - "./src/models.js" + "models": [ + "./src/models" ], "resources/*": [ "./src/resources/*" diff --git a/api/tsconfig.src.json b/api/tsconfig.src.json index 61a72697..1d16c60a 100644 --- a/api/tsconfig.src.json +++ b/api/tsconfig.src.json @@ -14,11 +14,11 @@ "core/*": [ "./src/core/*" ], - "resources.js": [ - "./src/resources.js" + "resources": [ + "./src/resources" ], - "models.js": [ - "./src/models.js" + "models": [ + "./src/models" ], "resources/*": [ "./src/resources/*" diff --git a/tsconfig.base.json b/tsconfig.base.json index 1e485daf..64ee216e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,3 +1,6 @@ { - "extends": "./node_modules/effect-app/tsconfig.base.json" + "extends": "./node_modules/effect-app/tsconfig.base.json", + "compilerOptions": { + "module": "ES2022", + } } \ No newline at end of file From 3b9e0d5ff4fb991023b503e4d43b301df896a7af Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Tue, 20 Feb 2024 20:37:00 +0100 Subject: [PATCH 4/5] prep try bun --- Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 08da2e20..0a86e245 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ -FROM node:20-alpine +FROM oven/bun:1 -RUN npm i -g pnpm - -# Install CUPS/AVAHI -RUN apk update --no-cache && apk add --no-cache cups cups-filters avahi inotify-tools +RUN bun install -g pnpm WORKDIR /app From 17e6920f3e57cf14fe5d28eab82255341df3e374 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Wed, 21 Feb 2024 10:57:14 +0100 Subject: [PATCH 5/5] bunx it --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a86e245..cb8b1fc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ ENV NODE_ENV production # pnpm fetch does require only lockfile COPY patches ./patches COPY pnpm-lock.yaml .npmrc ./ -RUN pnpm fetch --prod +RUN bunx pnpm fetch --prod COPY package.json pnpm-workspace.yaml ./ @@ -17,7 +17,7 @@ COPY api/package.json ./api/ # As we're going to deploy, we want only the minimal production dependencies. # TODO -RUN pnpm install --frozen-lockfile --prod +RUN bunx pnpm install --frozen-lockfile --prod #RUN --mount=type=cache,target=/root/.pnpm pnpm_CACHE_FOLDER=/root/.pnpm pnpm install --frozen-lockfile --prod COPY api/dist ./api/dist @@ -32,4 +32,4 @@ ARG API_VERSION ENV API_VERSION=${API_VERSION:-docker_default} ENV SENTRY_RELEASE=${API_VERSION:-docker_default} -CMD ["pnpm", "start"] +CMD ["bunx", "pnpm", "start"]