11import "server-only" ;
22
33import { db } from "@cap/database" ;
4+ import { decrypt } from "@cap/database/crypto" ;
45import {
56 Database ,
67 DatabaseError ,
@@ -10,7 +11,7 @@ import {
1011 Videos ,
1112 VideosPolicy ,
1213} from "@cap/web-backend" ;
13- import { Video , type HttpAuthMiddleware } from "@cap/web-domain" ;
14+ import { type HttpAuthMiddleware , Video } from "@cap/web-domain" ;
1415import * as NodeSdk from "@effect/opentelemetry/NodeSdk" ;
1516import {
1617 type HttpApi ,
@@ -19,11 +20,10 @@ import {
1920 HttpServer ,
2021} from "@effect/platform" ;
2122import { Cause , Effect , Exit , Layer , ManagedRuntime , Option } from "effect" ;
22- import { cookies } from "next/headers" ;
2323import { isNotFoundError } from "next/dist/client/components/not-found" ;
24+ import { cookies } from "next/headers" ;
2425import { allowedOrigins } from "@/utils/cors" ;
2526import { getTracingConfig } from "./tracing" ;
26- import { decrypt } from "@cap/database/crypto" ;
2727
2828const DatabaseLive = Layer . sync ( Database , ( ) => ( {
2929 execute : ( cb ) =>
@@ -46,8 +46,7 @@ const CookiePasswordAttachmentLive = Layer.effect(
4646 ) ;
4747 return { password } ;
4848 } ) ,
49- )
50-
49+ ) ;
5150
5251export const Dependencies = Layer . mergeAll (
5352 S3Buckets . Default ,
@@ -60,8 +59,12 @@ export const Dependencies = Layer.mergeAll(
6059// purposefully not exposed
6160const EffectRuntime = ManagedRuntime . make ( Dependencies ) ;
6261
63- export const runPromise = < A , E > ( effect : Effect . Effect < A , E , Layer . Layer . Success < typeof Dependencies > > ) =>
64- EffectRuntime . runPromiseExit ( effect . pipe ( Effect . provide ( CookiePasswordAttachmentLive ) ) ) . then ( res => {
62+ export const runPromise = < A , E > (
63+ effect : Effect . Effect < A , E , Layer . Layer . Success < typeof Dependencies > > ,
64+ ) =>
65+ EffectRuntime . runPromiseExit (
66+ effect . pipe ( Effect . provide ( CookiePasswordAttachmentLive ) ) ,
67+ ) . then ( ( res ) => {
6568 if ( Exit . isFailure ( res ) ) {
6669 if ( Cause . isDieType ( res . cause ) && isNotFoundError ( res . cause . defect ) ) {
6770 throw res . cause . defect ;
@@ -70,17 +73,25 @@ export const runPromise = <A, E>(effect: Effect.Effect<A, E, Layer.Layer.Success
7073 throw res ;
7174 }
7275
73- return res . value
74- } )
76+ return res . value ;
77+ } ) ;
7578
76- export const runPromiseExit = < A , E > ( effect : Effect . Effect < A , E , Layer . Layer . Success < typeof Dependencies > > ) =>
77- EffectRuntime . runPromiseExit ( effect . pipe ( Effect . provide ( CookiePasswordAttachmentLive ) ) ) . then ( res => {
78- if ( Exit . isFailure ( res ) && Cause . isDieType ( res . cause ) && isNotFoundError ( res . cause . defect ) ) {
79+ export const runPromiseExit = < A , E > (
80+ effect : Effect . Effect < A , E , Layer . Layer . Success < typeof Dependencies > > ,
81+ ) =>
82+ EffectRuntime . runPromiseExit (
83+ effect . pipe ( Effect . provide ( CookiePasswordAttachmentLive ) ) ,
84+ ) . then ( ( res ) => {
85+ if (
86+ Exit . isFailure ( res ) &&
87+ Cause . isDieType ( res . cause ) &&
88+ isNotFoundError ( res . cause . defect )
89+ ) {
7990 throw res . cause . defect ;
8091 }
8192
82- return res
83- } )
93+ return res ;
94+ } ) ;
8495
8596const cors = HttpApiBuilder . middlewareCors ( {
8697 allowedOrigins,
@@ -102,6 +113,8 @@ export const apiToHandler = (
102113 Layer . provideMerge ( Dependencies ) ,
103114 Layer . merge ( HttpServer . layerContext ) ,
104115 Layer . provide ( cors ) ,
105- Layer . provide ( HttpApiBuilder . middleware ( Effect . provide ( CookiePasswordAttachmentLive ) ) ) ,
116+ Layer . provide (
117+ HttpApiBuilder . middleware ( Effect . provide ( CookiePasswordAttachmentLive ) ) ,
118+ ) ,
106119 HttpApiBuilder . toWebHandler ,
107120 ) ;
0 commit comments