Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fun #9

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,15 +9,15 @@ 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 ./

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
Expand All @@ -35,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"]
7 changes: 4 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"start": "pnpm start:compiled",
"dev:compiled": "bun --inspect ./dist/main.js | ../scripts/humanlog.sh",
"dev:vite": "pnpm start:bun | ../scripts/humanlog.sh",
"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",
"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"
},
Expand Down
10 changes: 5 additions & 5 deletions api/src/Usecases.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 5 additions & 5 deletions api/src/Usecases/Blog.Controllers.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 4 additions & 4 deletions api/src/Usecases/HelloWorld.Controllers.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 3 additions & 3 deletions api/src/Usecases/Me.Controllers.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 3 additions & 3 deletions api/src/Usecases/Operations.Controllers.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 4 additions & 4 deletions api/src/Usecases/Users.Controllers.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 3 additions & 3 deletions api/src/_global.ext.ts
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 7 additions & 7 deletions api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions api/src/config.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -49,7 +49,7 @@ export interface ApiConfig extends ConfigA<typeof ApiConfig> {}

export interface ApiMainConfig extends ApiConfig, BaseConfig {}

export * from "./baseConfig.js"
export * from "./baseConfig"

export const MergedConfig = ApiConfig
.andThen((apiConfig) => BaseConfig.andThen((baseConfig) => ({ ...baseConfig, ...apiConfig })))
Expand Down
10 changes: 5 additions & 5 deletions api/src/lib/RequestEnv.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* 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"
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[] }

Expand Down
6 changes: 3 additions & 3 deletions api/src/lib/matchFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
8 changes: 4 additions & 4 deletions api/src/main.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion api/src/middleware/Middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/src/middleware/RequestContextMiddleware.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/src/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions api/src/middleware/events.ts
Original file line number Diff line number Diff line change
@@ -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*($) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/middleware/health.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
12 changes: 6 additions & 6 deletions api/src/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions api/src/middleware/internal/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion api/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/src/models/Blog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { S } from "effect-app"
import { UserFromId } from "./User.js"
import { UserFromId } from "./User"

export const BlogPostId = S.prefixedStringId<BlogPostId>()("post", "BlogPostId")
export interface BlogPostIdBrand {
Expand Down
2 changes: 1 addition & 1 deletion api/src/models/roles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Poor man's RBAC

import type { Role } from "./User.js"
import type { Role } from "./User"

/**
* Allow role access
Expand Down
2 changes: 1 addition & 1 deletion api/src/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions api/src/resources.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions api/src/resources/Blog.ts
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions api/src/resources/Blog/CreatePost.ts
Original file line number Diff line number Diff line change
@@ -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"] })<CreatePostRequest>()(
BlogPost.pick("title", "body")
Expand Down
Loading