git.iko.soy/rowtype-yoga/purescript-yoga-bun-yoga
on main help sign in
Prepare for publish v0.2.0
3a8638fMark
spago.yaml+1−1
@@ -3,7 +3,7 @@ workspace: {}
3package:
3package:
4 name: yoga-bun-yoga
4 name: yoga-bun-yoga
5 publish:
5 publish:
6− version: 0.1.0
6+ version: 0.2.0
7 license: MIT
7 license: MIT
8 location:
8 location:
9 githubOwner: rowtype-yoga
9 githubOwner: rowtype-yoga
src/Yoga/Bun/HTTP.js+7−1
@@ -1,4 +1,10 @@
1−export const serveImpl = (options) => Bun.serve(options);
1+export const serveImpl = (options) => {
2+ const server = Bun.serve(options);
3+ return {
4+ stop: (close) => server.stop(close),
5+ upgrade: (req) => () => server.upgrade(req)
6+ };
7+};
2
8
3// String/text Response
9// String/text Response
4export const stringResponseImpl = (body, stuff) => new Response(body, stuff);
10export const stringResponseImpl = (body, stuff) => new Response(body, stuff);
src/Yoga/Bun/HTTP.purs+13−3
@@ -13,15 +13,24 @@ import Promise.Aff (toAffE, fromAff) as Promise
13import Web.Fetch.Request (Request)
13import Web.Fetch.Request (Request)
14import Web.Fetch.Response (Response)
14import Web.Fetch.Response (Response)
15
15
16−type BunServerImpl = { stop :: EffectFn1 Boolean (Promise Unit) }
16+type BunServerImpl = { stop :: EffectFn1 Boolean (Promise Unit), upgrade :: EffectFn1 Request Boolean }
17
17
18data CloseActiveConnections = WaitForOpenConnections | ForceTerminateAllOpenConnections
18data CloseActiveConnections = WaitForOpenConnections | ForceTerminateAllOpenConnections
19
19
20−type BunServer = { stop :: CloseActiveConnections -> Aff Unit }
20+type BunServer = { stop :: CloseActiveConnections -> Aff Unit, upgrade :: Request -> Effect Boolean }
21
21
22foreign import serveImpl :: forall options. EffectFn1 options BunServerImpl
22foreign import serveImpl :: forall options. EffectFn1 options BunServerImpl
23
23
24+type BunServeOptionsImpl =
24−type BunServeOptionsImpl = (fetch :: EffectFn1 Request (Promise Response), port :: Int, host :: String)
25+ ( fetch :: EffectFn1 Request (Promise Response)
26+ , port :: Int
27+ , host :: String
28+ , websocket ::
29+ { open :: EffectFn1 Foreign Unit
30+ , message :: EffectFn2 Foreign Foreign Unit
31+ , close :: EffectFn2 Foreign Foreign Unit
32+ }
33+ )
25
34
26serve :: forall opts opts_. Union opts opts_ BunServeOptionsImpl => { fetch :: EffectFn1 Request (Promise Response) | opts } -> Effect BunServer
35serve :: forall opts opts_. Union opts opts_ BunServeOptionsImpl => { fetch :: EffectFn1 Request (Promise Response) | opts } -> Effect BunServer
27serve opts = do
36serve opts = do
@@ -30,6 +39,7 @@ serve opts = do
30 { stop: \closeActiveConnections -> case closeActiveConnections of
39 { stop: \closeActiveConnections -> case closeActiveConnections of
31 WaitForOpenConnections -> runEffectFn1 serverImpl.stop true # Promise.toAffE
40 WaitForOpenConnections -> runEffectFn1 serverImpl.stop true # Promise.toAffE
32 ForceTerminateAllOpenConnections -> runEffectFn1 serverImpl.stop false # Promise.toAffE
41 ForceTerminateAllOpenConnections -> runEffectFn1 serverImpl.stop false # Promise.toAffE
42+ , upgrade: runEffectFn1 serverImpl.upgrade
33 }
43 }
34
44
35mkFetch :: (Request -> Aff Response) -> EffectFn1 Request (Promise Response)
45mkFetch :: (Request -> Aff Response) -> EffectFn1 Request (Promise Response)