@effect/platform 0.69.14 → 0.69.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/HttpApiBuilder.js +27 -25
- package/dist/cjs/HttpApiBuilder.js.map +1 -1
- package/dist/cjs/HttpApiClient.js +18 -8
- package/dist/cjs/HttpApiClient.js.map +1 -1
- package/dist/cjs/Socket.js +47 -35
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/internal/multipart.js +50 -64
- package/dist/cjs/internal/multipart.js.map +1 -1
- package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
- package/dist/dts/HttpApiClient.d.ts.map +1 -1
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/esm/HttpApiBuilder.js +27 -25
- package/dist/esm/HttpApiBuilder.js.map +1 -1
- package/dist/esm/HttpApiClient.js +18 -8
- package/dist/esm/HttpApiClient.js.map +1 -1
- package/dist/esm/Socket.js +47 -35
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/internal/multipart.js +50 -64
- package/dist/esm/internal/multipart.js.map +1 -1
- package/package.json +2 -2
- package/src/HttpApiBuilder.ts +35 -56
- package/src/HttpApiClient.ts +34 -44
- package/src/Socket.ts +210 -205
- package/src/internal/multipart.ts +120 -150
package/src/HttpApiBuilder.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as Chunk from "effect/Chunk"
|
|
|
5
5
|
import * as Context from "effect/Context"
|
|
6
6
|
import * as Effect from "effect/Effect"
|
|
7
7
|
import * as Encoding from "effect/Encoding"
|
|
8
|
-
import * as
|
|
8
|
+
import * as Fiber from "effect/Fiber"
|
|
9
9
|
import { identity } from "effect/Function"
|
|
10
10
|
import { globalValue } from "effect/GlobalValue"
|
|
11
11
|
import * as HashMap from "effect/HashMap"
|
|
@@ -163,17 +163,13 @@ export const toWebHandler = <LA, LE>(
|
|
|
163
163
|
options?.memoMap
|
|
164
164
|
)
|
|
165
165
|
let handlerCached: ((request: Request) => Promise<Response>) | undefined
|
|
166
|
-
const handlerPromise =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
handlerCached = handler
|
|
174
|
-
}),
|
|
175
|
-
runtime.runPromise
|
|
176
|
-
)
|
|
166
|
+
const handlerPromise = Effect.gen(function*() {
|
|
167
|
+
const app = yield* httpApp
|
|
168
|
+
const rt = yield* runtime.runtimeEffect
|
|
169
|
+
const handler = HttpApp.toWebHandlerRuntime(rt)(options?.middleware ? options.middleware(app as any) as any : app)
|
|
170
|
+
handlerCached = handler
|
|
171
|
+
return handler
|
|
172
|
+
}).pipe(runtime.runPromise)
|
|
177
173
|
function handler(request: Request): Promise<Response> {
|
|
178
174
|
if (handlerCached !== undefined) {
|
|
179
175
|
return handlerCached(request)
|
|
@@ -570,52 +566,35 @@ const handlerToRoute = (
|
|
|
570
566
|
endpoint.path,
|
|
571
567
|
applyMiddleware(
|
|
572
568
|
middleware,
|
|
573
|
-
Effect.
|
|
574
|
-
const
|
|
575
|
-
const
|
|
569
|
+
Effect.gen(function*() {
|
|
570
|
+
const fiber = Option.getOrThrow(Fiber.getCurrentFiber())
|
|
571
|
+
const context = fiber.currentContext
|
|
572
|
+
const httpRequest = Context.unsafeGet(context, HttpServerRequest.HttpServerRequest)
|
|
576
573
|
const routeContext = Context.unsafeGet(context, HttpRouter.RouteContext)
|
|
577
574
|
const urlParams = Context.unsafeGet(context, HttpServerRequest.ParsedSearchParams)
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
)
|
|
583
|
-
Effect.
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const request: any = { path: input.pathParams }
|
|
602
|
-
if ("payload" in input) {
|
|
603
|
-
request.payload = input.payload
|
|
604
|
-
}
|
|
605
|
-
if ("headers" in input) {
|
|
606
|
-
request.headers = input.headers
|
|
607
|
-
}
|
|
608
|
-
if ("urlParams" in input) {
|
|
609
|
-
request.urlParams = input.urlParams
|
|
610
|
-
}
|
|
611
|
-
return handler(request)
|
|
612
|
-
}),
|
|
613
|
-
isFullResponse ?
|
|
614
|
-
identity as (_: any) => Effect.Effect<HttpServerResponse.HttpServerResponse> :
|
|
615
|
-
Effect.flatMap(encodeSuccess),
|
|
616
|
-
Effect.catchIf(ParseResult.isParseError, HttpApiDecodeError.refailParseError)
|
|
617
|
-
)
|
|
618
|
-
})
|
|
575
|
+
const request: any = {}
|
|
576
|
+
if (decodePath._tag === "Some") {
|
|
577
|
+
request.path = yield* decodePath.value(routeContext.params)
|
|
578
|
+
}
|
|
579
|
+
if (decodePayload._tag === "Some") {
|
|
580
|
+
request.payload = yield* Effect.flatMap(
|
|
581
|
+
requestPayload(httpRequest, urlParams, isMultipart),
|
|
582
|
+
decodePayload.value
|
|
583
|
+
)
|
|
584
|
+
}
|
|
585
|
+
if (decodeHeaders._tag === "Some") {
|
|
586
|
+
request.headers = yield* decodeHeaders.value(httpRequest.headers)
|
|
587
|
+
}
|
|
588
|
+
if (decodeUrlParams._tag === "Some") {
|
|
589
|
+
request.urlParams = yield* decodeUrlParams.value(urlParams)
|
|
590
|
+
}
|
|
591
|
+
const response = isFullResponse
|
|
592
|
+
? yield* handler(request)
|
|
593
|
+
: yield* Effect.flatMap(handler(request), encodeSuccess)
|
|
594
|
+
return response as HttpServerResponse.HttpServerResponse
|
|
595
|
+
}).pipe(
|
|
596
|
+
Effect.catchIf(ParseResult.isParseError, HttpApiDecodeError.refailParseError)
|
|
597
|
+
)
|
|
619
598
|
)
|
|
620
599
|
)
|
|
621
600
|
}
|
package/src/HttpApiClient.ts
CHANGED
|
@@ -152,51 +152,41 @@ export const make = <Groups extends HttpApiGroup.Any, ApiError, ApiR>(
|
|
|
152
152
|
readonly payload: any
|
|
153
153
|
readonly headers: any
|
|
154
154
|
readonly withResponse?: boolean
|
|
155
|
-
}) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
Effect.succeed(baseRequest.pipe(
|
|
160
|
-
HttpClientRequest.bodyFormData(request.payload)
|
|
161
|
-
))
|
|
162
|
-
: encodePayload._tag === "Some"
|
|
163
|
-
? encodePayload.value(request.payload).pipe(
|
|
164
|
-
Effect.flatMap((payload) =>
|
|
165
|
-
HttpMethod.hasBody(endpoint.method)
|
|
166
|
-
? HttpClientRequest.bodyJson(baseRequest, payload)
|
|
167
|
-
: Effect.succeed(HttpClientRequest.setUrlParams(baseRequest, payload as any))
|
|
168
|
-
),
|
|
169
|
-
Effect.orDie
|
|
155
|
+
}) =>
|
|
156
|
+
Effect.gen(function*() {
|
|
157
|
+
let httpRequest = HttpClientRequest.make(endpoint.method)(
|
|
158
|
+
request && request.path ? makeUrl(request.path) : endpoint.path
|
|
170
159
|
)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
199
|
-
|
|
160
|
+
if (isMultipart) {
|
|
161
|
+
httpRequest = HttpClientRequest.bodyFormData(httpRequest, request.payload)
|
|
162
|
+
} else if (encodePayload._tag === "Some") {
|
|
163
|
+
const payload = yield* encodePayload.value(request.payload)
|
|
164
|
+
httpRequest = HttpMethod.hasBody(endpoint.method)
|
|
165
|
+
? yield* Effect.orDie(HttpClientRequest.bodyJson(httpRequest, payload))
|
|
166
|
+
: HttpClientRequest.setUrlParams(httpRequest, payload as any)
|
|
167
|
+
}
|
|
168
|
+
if (encodeHeaders._tag === "Some") {
|
|
169
|
+
httpRequest = HttpClientRequest.setHeaders(
|
|
170
|
+
httpRequest,
|
|
171
|
+
(yield* encodeHeaders.value(request.headers)) as any
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
if (encodeUrlParams._tag === "Some") {
|
|
175
|
+
httpRequest = HttpClientRequest.appendUrlParams(
|
|
176
|
+
httpRequest,
|
|
177
|
+
(yield* encodeUrlParams.value(request.urlParams)) as any
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
const response = yield* httpClient.execute(httpRequest)
|
|
181
|
+
const value = yield* (options?.transformResponse === undefined
|
|
182
|
+
? decodeResponse(response)
|
|
183
|
+
: options.transformResponse(decodeResponse(response)))
|
|
184
|
+
return request?.withResponse === true ? [value, response] : value
|
|
185
|
+
}).pipe(
|
|
186
|
+
Effect.scoped,
|
|
187
|
+
Effect.catchIf(ParseResult.isParseError, Effect.die),
|
|
188
|
+
Effect.mapInputContext((input) => Context.merge(context, input))
|
|
189
|
+
)
|
|
200
190
|
}
|
|
201
191
|
})
|
|
202
192
|
return client as any
|