@effect/platform 0.46.3 → 0.47.1
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/PlatformLogger/package.json +6 -0
- package/Socket/package.json +6 -0
- package/dist/cjs/Error.js +40 -4
- package/dist/cjs/Error.js.map +1 -1
- package/dist/cjs/Http/Body.js +8 -1
- package/dist/cjs/Http/Body.js.map +1 -1
- package/dist/cjs/Http/ClientError.js +21 -2
- package/dist/cjs/Http/ClientError.js.map +1 -1
- package/dist/cjs/Http/Headers.js +22 -1
- package/dist/cjs/Http/Headers.js.map +1 -1
- package/dist/cjs/Http/ServerError.js +30 -7
- package/dist/cjs/Http/ServerError.js.map +1 -1
- package/dist/cjs/Http/ServerRequest.js +11 -1
- package/dist/cjs/Http/ServerRequest.js.map +1 -1
- package/dist/cjs/Http/UrlParams.js +7 -2
- package/dist/cjs/Http/UrlParams.js.map +1 -1
- package/dist/cjs/PlatformLogger.js +57 -0
- package/dist/cjs/PlatformLogger.js.map +1 -0
- package/dist/cjs/Socket.js +212 -0
- package/dist/cjs/Socket.js.map +1 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/internal/http/body.js +1 -1
- package/dist/cjs/internal/http/body.js.map +1 -1
- package/dist/cjs/internal/http/client.js +5 -5
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/clientError.js +1 -36
- package/dist/cjs/internal/http/clientError.js.map +1 -1
- package/dist/cjs/internal/http/clientResponse.js +8 -8
- package/dist/cjs/internal/http/clientResponse.js.map +1 -1
- package/dist/cjs/internal/http/multiplex.js +1 -1
- package/dist/cjs/internal/http/multiplex.js.map +1 -1
- package/dist/cjs/internal/http/router.js +1 -1
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/http/serverError.js +1 -15
- package/dist/cjs/internal/http/serverError.js.map +1 -1
- package/dist/cjs/internal/http/serverRequest.js +22 -8
- package/dist/cjs/internal/http/serverRequest.js.map +1 -1
- package/dist/cjs/internal/platformLogger.js +46 -0
- package/dist/cjs/internal/platformLogger.js.map +1 -0
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/Error.d.ts +22 -0
- package/dist/dts/Error.d.ts.map +1 -1
- package/dist/dts/Http/Body.d.ts +9 -1
- package/dist/dts/Http/Body.d.ts.map +1 -1
- package/dist/dts/Http/ClientError.d.ts +21 -33
- package/dist/dts/Http/ClientError.d.ts.map +1 -1
- package/dist/dts/Http/Headers.d.ts +19 -0
- package/dist/dts/Http/Headers.d.ts.map +1 -1
- package/dist/dts/Http/ServerError.d.ts +33 -47
- package/dist/dts/Http/ServerError.d.ts.map +1 -1
- package/dist/dts/Http/ServerRequest.d.ts +14 -0
- package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
- package/dist/dts/Http/UrlParams.d.ts +5 -0
- package/dist/dts/Http/UrlParams.d.ts.map +1 -1
- package/dist/dts/PlatformLogger.d.ts +41 -0
- package/dist/dts/PlatformLogger.d.ts.map +1 -0
- package/dist/dts/Socket.d.ts +111 -0
- package/dist/dts/Socket.d.ts.map +1 -0
- package/dist/dts/index.d.ts +8 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/platformLogger.d.ts +2 -0
- package/dist/dts/internal/platformLogger.d.ts.map +1 -0
- package/dist/esm/Error.js +38 -3
- package/dist/esm/Error.js.map +1 -1
- package/dist/esm/Http/Body.js +6 -0
- package/dist/esm/Http/Body.js.map +1 -1
- package/dist/esm/Http/ClientError.js +19 -2
- package/dist/esm/Http/ClientError.js.map +1 -1
- package/dist/esm/Http/Headers.js +21 -1
- package/dist/esm/Http/Headers.js.map +1 -1
- package/dist/esm/Http/ServerError.js +26 -7
- package/dist/esm/Http/ServerError.js.map +1 -1
- package/dist/esm/Http/ServerRequest.js +10 -0
- package/dist/esm/Http/ServerRequest.js.map +1 -1
- package/dist/esm/Http/UrlParams.js +5 -0
- package/dist/esm/Http/UrlParams.js.map +1 -1
- package/dist/esm/PlatformLogger.js +26 -0
- package/dist/esm/PlatformLogger.js.map +1 -0
- package/dist/esm/Socket.js +166 -0
- package/dist/esm/Socket.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/http/body.js +1 -1
- package/dist/esm/internal/http/body.js.map +1 -1
- package/dist/esm/internal/http/client.js +5 -5
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/clientError.js +0 -10
- package/dist/esm/internal/http/clientError.js.map +1 -1
- package/dist/esm/internal/http/clientResponse.js +8 -8
- package/dist/esm/internal/http/clientResponse.js.map +1 -1
- package/dist/esm/internal/http/multiplex.js +1 -1
- package/dist/esm/internal/http/multiplex.js.map +1 -1
- package/dist/esm/internal/http/router.js +1 -1
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/http/serverError.js +0 -14
- package/dist/esm/internal/http/serverError.js.map +1 -1
- package/dist/esm/internal/http/serverRequest.js +20 -7
- package/dist/esm/internal/http/serverRequest.js.map +1 -1
- package/dist/esm/internal/platformLogger.js +15 -0
- package/dist/esm/internal/platformLogger.js.map +1 -0
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +20 -3
- package/src/Error.ts +61 -0
- package/src/Http/Body.ts +14 -1
- package/src/Http/ClientError.ts +21 -38
- package/src/Http/Headers.ts +29 -1
- package/src/Http/ServerError.ts +25 -56
- package/src/Http/ServerRequest.ts +25 -0
- package/src/Http/UrlParams.ts +10 -0
- package/src/PlatformLogger.ts +59 -0
- package/src/Socket.ts +291 -0
- package/src/index.ts +10 -0
- package/src/internal/http/body.ts +4 -2
- package/src/internal/http/client.ts +5 -6
- package/src/internal/http/clientError.ts +0 -14
- package/src/internal/http/clientResponse.ts +15 -14
- package/src/internal/http/multiplex.ts +1 -1
- package/src/internal/http/router.ts +1 -1
- package/src/internal/http/serverError.ts +0 -20
- package/src/internal/http/serverRequest.ts +31 -11
- package/src/internal/platformLogger.ts +42 -0
- package/src/internal/worker.ts +5 -1
package/src/Error.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import type * as Cause from "effect/Cause"
|
|
5
|
+
import * as Data from "effect/Data"
|
|
6
|
+
import * as Predicate from "effect/Predicate"
|
|
7
|
+
import type { Simplify } from "../../effect/src/Types.js"
|
|
4
8
|
import * as internal from "./internal/error.js"
|
|
5
9
|
|
|
6
10
|
/**
|
|
@@ -21,6 +25,63 @@ export type PlatformErrorTypeId = typeof PlatformErrorTypeId
|
|
|
21
25
|
*/
|
|
22
26
|
export type PlatformError = BadArgument | SystemError
|
|
23
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
* @category error
|
|
31
|
+
*/
|
|
32
|
+
export const TypeIdError = <const TypeId extends symbol, const Tag extends string>(
|
|
33
|
+
typeId: TypeId,
|
|
34
|
+
tag: Tag
|
|
35
|
+
): new<A extends Record<string, any>>(
|
|
36
|
+
args: Simplify<A>
|
|
37
|
+
) =>
|
|
38
|
+
& Cause.YieldableError
|
|
39
|
+
& Record<TypeId, TypeId>
|
|
40
|
+
& { readonly _tag: Tag }
|
|
41
|
+
& Readonly<A> =>
|
|
42
|
+
{
|
|
43
|
+
class Base extends Data.Error<{}> {
|
|
44
|
+
readonly _tag = tag
|
|
45
|
+
}
|
|
46
|
+
;(Base.prototype as any)[typeId] = typeId
|
|
47
|
+
;(Base.prototype as any).name = tag
|
|
48
|
+
return Base as any
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @category error
|
|
54
|
+
*/
|
|
55
|
+
export const RefailError = <const TypeId extends symbol, const Tag extends string>(
|
|
56
|
+
typeId: TypeId,
|
|
57
|
+
tag: Tag
|
|
58
|
+
): new<A extends Record<string, any>>(
|
|
59
|
+
args: Simplify<A & { readonly error: unknown }>
|
|
60
|
+
) =>
|
|
61
|
+
& Cause.YieldableError
|
|
62
|
+
& Record<TypeId, TypeId>
|
|
63
|
+
& { readonly _tag: Tag; readonly error: unknown }
|
|
64
|
+
& Readonly<A> =>
|
|
65
|
+
{
|
|
66
|
+
class Base extends Data.Error<{
|
|
67
|
+
readonly error: unknown
|
|
68
|
+
}> {
|
|
69
|
+
readonly _tag = tag
|
|
70
|
+
constructor(props: any) {
|
|
71
|
+
super(props)
|
|
72
|
+
if (Predicate.hasProperty(this.error, "stack")) {
|
|
73
|
+
;(this as any).stack = this.error.stack
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
get message() {
|
|
77
|
+
return String(Predicate.hasProperty(this.error, "message") ? this.error.message : this.error)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
;(Base.prototype as any)[typeId] = typeId
|
|
81
|
+
;(Base.prototype as any).name = tag
|
|
82
|
+
return Base as any
|
|
83
|
+
}
|
|
84
|
+
|
|
24
85
|
/**
|
|
25
86
|
* @since 1.0.0
|
|
26
87
|
*/
|
package/src/Http/Body.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
5
5
|
import type * as Schema from "@effect/schema/Schema"
|
|
6
6
|
import type * as Effect from "effect/Effect"
|
|
7
|
+
import * as Predicate from "effect/Predicate"
|
|
7
8
|
import type * as Stream_ from "effect/Stream"
|
|
8
9
|
import type * as PlatformError from "../Error.js"
|
|
9
10
|
import type * as FileSystem from "../FileSystem.js"
|
|
@@ -22,6 +23,12 @@ export const TypeId: unique symbol = internal.TypeId
|
|
|
22
23
|
*/
|
|
23
24
|
export type TypeId = typeof TypeId
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
* @category refinements
|
|
29
|
+
*/
|
|
30
|
+
export const isBody = (u: unknown): u is Body => Predicate.hasProperty(u, TypeId)
|
|
31
|
+
|
|
25
32
|
/**
|
|
26
33
|
* @since 1.0.0
|
|
27
34
|
* @category models
|
|
@@ -122,7 +129,13 @@ export interface Raw extends Body.Proto {
|
|
|
122
129
|
* @since 1.0.0
|
|
123
130
|
* @category constructors
|
|
124
131
|
*/
|
|
125
|
-
export const raw: (
|
|
132
|
+
export const raw: (
|
|
133
|
+
body: unknown,
|
|
134
|
+
options?: {
|
|
135
|
+
readonly contentType?: string | undefined
|
|
136
|
+
readonly contentLength?: number | undefined
|
|
137
|
+
} | undefined
|
|
138
|
+
) => Raw = internal.raw
|
|
126
139
|
|
|
127
140
|
/**
|
|
128
141
|
* @since 1.0.0
|
package/src/Http/ClientError.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Error from "@effect/platform/Error"
|
|
4
5
|
import * as internal from "../internal/http/clientError.js"
|
|
5
6
|
import type * as ClientRequest from "./ClientRequest.js"
|
|
6
7
|
import type * as ClientResponse from "./ClientResponse.js"
|
|
@@ -23,57 +24,39 @@ export type TypeId = typeof TypeId
|
|
|
23
24
|
*/
|
|
24
25
|
export type HttpClientError = RequestError | ResponseError
|
|
25
26
|
|
|
26
|
-
/**
|
|
27
|
-
* @since 1.0.0
|
|
28
|
-
*/
|
|
29
|
-
export declare namespace HttpError {
|
|
30
|
-
/**
|
|
31
|
-
* @since 1.0.0
|
|
32
|
-
* @category models
|
|
33
|
-
*/
|
|
34
|
-
export interface Proto {
|
|
35
|
-
readonly [TypeId]: TypeId
|
|
36
|
-
readonly _tag: string
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @since 1.0.0
|
|
41
|
-
*/
|
|
42
|
-
export type ProvidedFields = TypeId | "_tag"
|
|
43
|
-
}
|
|
44
|
-
|
|
45
27
|
/**
|
|
46
28
|
* @since 1.0.0
|
|
47
29
|
* @category error
|
|
48
30
|
*/
|
|
49
|
-
export
|
|
50
|
-
readonly _tag: "RequestError"
|
|
31
|
+
export class RequestError extends Error.RefailError(TypeId, "RequestError")<{
|
|
51
32
|
readonly request: ClientRequest.ClientRequest
|
|
52
33
|
readonly reason: "Transport" | "Encode" | "InvalidUrl"
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
}> {
|
|
35
|
+
get methodAndUrl() {
|
|
36
|
+
return `${this.request.method} ${this.request.url}`
|
|
37
|
+
}
|
|
55
38
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
get message() {
|
|
40
|
+
const errorString = super.message
|
|
41
|
+
return `${this.reason} error (${this.methodAndUrl}): ${errorString}`
|
|
42
|
+
}
|
|
43
|
+
}
|
|
61
44
|
|
|
62
45
|
/**
|
|
63
46
|
* @since 1.0.0
|
|
64
47
|
* @category error
|
|
65
48
|
*/
|
|
66
|
-
export
|
|
67
|
-
readonly _tag: "ResponseError"
|
|
49
|
+
export class ResponseError extends Error.RefailError(TypeId, "ResponseError")<{
|
|
68
50
|
readonly request: ClientRequest.ClientRequest
|
|
69
51
|
readonly response: ClientResponse.ClientResponse
|
|
70
52
|
readonly reason: "StatusCode" | "Decode" | "EmptyBody"
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
}> {
|
|
54
|
+
get methodAndUrl() {
|
|
55
|
+
return `${this.request.method} ${this.request.url}`
|
|
56
|
+
}
|
|
73
57
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
internal.responseError
|
|
58
|
+
get message() {
|
|
59
|
+
const errorString = super.message
|
|
60
|
+
return `${this.reason} error (${this.response.status} ${this.methodAndUrl}): ${errorString}`
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/Http/Headers.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import * as Schema from "@effect/schema/Schema"
|
|
5
|
+
import { dual, identity } from "effect/Function"
|
|
5
6
|
import type * as Option from "effect/Option"
|
|
6
7
|
import * as Predicate from "effect/Predicate"
|
|
7
8
|
import * as ReadonlyArray from "effect/ReadonlyArray"
|
|
8
9
|
import * as ReadonlyRecord from "effect/ReadonlyRecord"
|
|
9
10
|
import * as Secret from "effect/Secret"
|
|
11
|
+
import * as String from "effect/String"
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* @since 1.0.0
|
|
@@ -20,6 +22,12 @@ export const HeadersTypeId = Symbol.for("@effect/platform/Http/Headers")
|
|
|
20
22
|
*/
|
|
21
23
|
export type HeadersTypeId = typeof HeadersTypeId
|
|
22
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
* @category refinements
|
|
28
|
+
*/
|
|
29
|
+
export const isHeaders = (u: unknown): u is Headers => Predicate.hasProperty(u, HeadersTypeId)
|
|
30
|
+
|
|
23
31
|
/**
|
|
24
32
|
* @since 1.0.0
|
|
25
33
|
* @category models
|
|
@@ -29,6 +37,26 @@ export interface Headers {
|
|
|
29
37
|
readonly [key: string]: string
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
* @category schemas
|
|
43
|
+
*/
|
|
44
|
+
export const schemaFromSelf: Schema.Schema<Headers> = Schema.declare(isHeaders, {
|
|
45
|
+
identifier: "Headers",
|
|
46
|
+
equivalence: () => ReadonlyRecord.getEquivalence(String.Equivalence)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
* @category schemas
|
|
52
|
+
*/
|
|
53
|
+
export const schema: Schema.Schema<Headers, ReadonlyRecord.ReadonlyRecord<string, string>> = Schema.transform(
|
|
54
|
+
Schema.record(Schema.string, Schema.string),
|
|
55
|
+
schemaFromSelf,
|
|
56
|
+
(record) => fromInput(record),
|
|
57
|
+
identity
|
|
58
|
+
)
|
|
59
|
+
|
|
32
60
|
/**
|
|
33
61
|
* @since 1.0.0
|
|
34
62
|
* @category models
|
package/src/Http/ServerError.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type * as Cause from "effect/Cause"
|
|
5
5
|
import type * as FiberId from "effect/FiberId"
|
|
6
|
+
import { RefailError, TypeIdError } from "../Error.js"
|
|
6
7
|
import * as internal from "../internal/http/serverError.js"
|
|
7
8
|
import type * as ServerRequest from "./ServerRequest.js"
|
|
8
9
|
import type * as ServerResponse from "./ServerResponse.js"
|
|
@@ -25,34 +26,21 @@ export type TypeId = typeof TypeId
|
|
|
25
26
|
*/
|
|
26
27
|
export type HttpServerError = RequestError | ResponseError | RouteNotFound | ServeError
|
|
27
28
|
|
|
28
|
-
/**
|
|
29
|
-
* @since 1.0.0
|
|
30
|
-
*/
|
|
31
|
-
export declare namespace HttpError {
|
|
32
|
-
/**
|
|
33
|
-
* @since 1.0.0
|
|
34
|
-
* @category models
|
|
35
|
-
*/
|
|
36
|
-
export interface Proto {
|
|
37
|
-
readonly [TypeId]: TypeId
|
|
38
|
-
readonly _tag: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @since 1.0.0
|
|
43
|
-
*/
|
|
44
|
-
export type ProvidedFields = TypeId | "_tag"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
29
|
/**
|
|
48
30
|
* @since 1.0.0
|
|
49
31
|
* @category error
|
|
50
32
|
*/
|
|
51
|
-
export
|
|
52
|
-
readonly _tag: "RequestError"
|
|
33
|
+
export class RequestError extends RefailError(TypeId, "RequestError")<{
|
|
53
34
|
readonly request: ServerRequest.ServerRequest
|
|
54
35
|
readonly reason: "Transport" | "Decode"
|
|
55
|
-
|
|
36
|
+
}> {
|
|
37
|
+
get methodAndUrl() {
|
|
38
|
+
return `${this.request.method} ${this.request.url}`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get message() {
|
|
42
|
+
return `${this.reason} error (${this.methodAndUrl}): ${super.message}`
|
|
43
|
+
}
|
|
56
44
|
}
|
|
57
45
|
|
|
58
46
|
/**
|
|
@@ -65,57 +53,38 @@ export const isServerError: (u: unknown) => u is HttpServerError = internal.isSe
|
|
|
65
53
|
* @since 1.0.0
|
|
66
54
|
* @category error
|
|
67
55
|
*/
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
* @category error
|
|
73
|
-
*/
|
|
74
|
-
export interface RouteNotFound extends HttpError.Proto {
|
|
75
|
-
readonly _tag: "RouteNotFound"
|
|
56
|
+
export class RouteNotFound extends TypeIdError(TypeId, "RouteNotFound")<{
|
|
76
57
|
readonly request: ServerRequest.ServerRequest
|
|
58
|
+
}> {
|
|
59
|
+
get message() {
|
|
60
|
+
return `${this.request.method} ${this.request.url} not found`
|
|
61
|
+
}
|
|
77
62
|
}
|
|
78
63
|
|
|
79
64
|
/**
|
|
80
65
|
* @since 1.0.0
|
|
81
66
|
* @category error
|
|
82
67
|
*/
|
|
83
|
-
export
|
|
84
|
-
internal.routeNotFound
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @since 1.0.0
|
|
88
|
-
* @category error
|
|
89
|
-
*/
|
|
90
|
-
export interface ResponseError extends HttpError.Proto {
|
|
91
|
-
readonly _tag: "ResponseError"
|
|
68
|
+
export class ResponseError extends RefailError(TypeId, "ResponseError")<{
|
|
92
69
|
readonly request: ServerRequest.ServerRequest
|
|
93
70
|
readonly response: ServerResponse.ServerResponse
|
|
94
71
|
readonly reason: "Decode"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @since 1.0.0
|
|
100
|
-
* @category error
|
|
101
|
-
*/
|
|
102
|
-
export const ResponseError: (props: Omit<ResponseError, HttpError.ProvidedFields>) => ResponseError =
|
|
103
|
-
internal.responseError
|
|
72
|
+
}> {
|
|
73
|
+
get methodAndUrl() {
|
|
74
|
+
return `${this.request.method} ${this.request.url}`
|
|
75
|
+
}
|
|
104
76
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
export interface ServeError extends HttpError.Proto {
|
|
110
|
-
readonly _tag: "ServeError"
|
|
111
|
-
readonly error: unknown
|
|
77
|
+
get message() {
|
|
78
|
+
return `${this.reason} error (${this.response.status} ${this.methodAndUrl}): ${super.message}`
|
|
79
|
+
}
|
|
112
80
|
}
|
|
113
81
|
|
|
114
82
|
/**
|
|
115
83
|
* @since 1.0.0
|
|
116
84
|
* @category error
|
|
117
85
|
*/
|
|
118
|
-
export
|
|
86
|
+
export class ServeError extends RefailError(TypeId, "ServeError")<{}> {
|
|
87
|
+
}
|
|
119
88
|
|
|
120
89
|
/**
|
|
121
90
|
* @since 1.0.0
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
5
5
|
import type * as Schema from "@effect/schema/Schema"
|
|
6
|
+
import type { Channel } from "effect/Channel"
|
|
7
|
+
import type { Chunk } from "effect/Chunk"
|
|
6
8
|
import type * as Context from "effect/Context"
|
|
7
9
|
import type * as Effect from "effect/Effect"
|
|
8
10
|
import type * as Scope from "effect/Scope"
|
|
@@ -10,6 +12,7 @@ import type * as Stream from "effect/Stream"
|
|
|
10
12
|
import type * as FileSystem from "../FileSystem.js"
|
|
11
13
|
import * as internal from "../internal/http/serverRequest.js"
|
|
12
14
|
import type * as Path from "../Path.js"
|
|
15
|
+
import type * as Socket from "../Socket.js"
|
|
13
16
|
import type * as Headers from "./Headers.js"
|
|
14
17
|
import type * as IncomingMessage from "./IncomingMessage.js"
|
|
15
18
|
import type { Method } from "./Method.js"
|
|
@@ -54,6 +57,8 @@ export interface ServerRequest extends IncomingMessage.IncomingMessage<Error.Req
|
|
|
54
57
|
>
|
|
55
58
|
readonly multipartStream: Stream.Stream<Multipart.Part, Multipart.MultipartError>
|
|
56
59
|
|
|
60
|
+
readonly upgrade: Effect.Effect<Socket.Socket, Error.RequestError>
|
|
61
|
+
|
|
57
62
|
readonly modify: (
|
|
58
63
|
options: {
|
|
59
64
|
readonly url?: string
|
|
@@ -79,6 +84,26 @@ export const persistedMultipart: Effect.Effect<
|
|
|
79
84
|
Scope.Scope | FileSystem.FileSystem | Path.Path | ServerRequest
|
|
80
85
|
> = internal.multipartPersisted
|
|
81
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @since 1.0.0
|
|
89
|
+
* @category accessors
|
|
90
|
+
*/
|
|
91
|
+
export const upgrade: Effect.Effect<Socket.Socket, Error.RequestError, ServerRequest> = internal.upgrade
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @since 1.0.0
|
|
95
|
+
* @category accessors
|
|
96
|
+
*/
|
|
97
|
+
export const upgradeChannel: <IE = never>() => Channel<
|
|
98
|
+
Chunk<Uint8Array>,
|
|
99
|
+
Chunk<Uint8Array>,
|
|
100
|
+
Error.RequestError | IE | Socket.SocketError,
|
|
101
|
+
IE,
|
|
102
|
+
void,
|
|
103
|
+
unknown,
|
|
104
|
+
ServerRequest
|
|
105
|
+
> = internal.upgradeChannel
|
|
106
|
+
|
|
82
107
|
/**
|
|
83
108
|
* @since 1.0.0
|
|
84
109
|
* @category schema
|
package/src/Http/UrlParams.ts
CHANGED
|
@@ -31,6 +31,16 @@ export const fromInput = (input: Input): UrlParams => {
|
|
|
31
31
|
return ReadonlyArray.fromIterable(Object.entries(input))
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @category schemas
|
|
37
|
+
*/
|
|
38
|
+
export const schema: Schema.Schema<UrlParams, ReadonlyArray<readonly [string, string]>> = Schema.array(
|
|
39
|
+
Schema.tuple(Schema.string, Schema.string)
|
|
40
|
+
).pipe(
|
|
41
|
+
Schema.identifier("UrlParams")
|
|
42
|
+
)
|
|
43
|
+
|
|
34
44
|
/**
|
|
35
45
|
* @since 1.0.0
|
|
36
46
|
* @category constructors
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { DurationInput } from "effect/Duration"
|
|
5
|
+
import type { Effect } from "effect/Effect"
|
|
6
|
+
import type * as Logger from "effect/Logger"
|
|
7
|
+
import type { Scope } from "effect/Scope"
|
|
8
|
+
import type { PlatformError } from "./Error.js"
|
|
9
|
+
import type { FileSystem, OpenFileOptions } from "./FileSystem.js"
|
|
10
|
+
import * as internal from "./internal/platformLogger.js"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a Logger from another string Logger that writes to the specified file.
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
* @example
|
|
17
|
+
* import { PlatformLogger } from "@effect/platform"
|
|
18
|
+
* import { NodeFileSystem, NodeRuntime } from "@effect/platform-node"
|
|
19
|
+
* import { Effect, Layer, Logger } from "effect"
|
|
20
|
+
*
|
|
21
|
+
* const fileLogger = Logger.logfmtLogger.pipe(
|
|
22
|
+
* PlatformLogger.toFile("/tmp/log.txt")
|
|
23
|
+
* )
|
|
24
|
+
* const LoggerLive = Logger.replaceScoped(Logger.defaultLogger, fileLogger).pipe(
|
|
25
|
+
* Layer.provide(NodeFileSystem.layer)
|
|
26
|
+
* )
|
|
27
|
+
*
|
|
28
|
+
* Effect.log("a").pipe(
|
|
29
|
+
* Effect.zipRight(Effect.log("b")),
|
|
30
|
+
* Effect.zipRight(Effect.log("c")),
|
|
31
|
+
* Effect.provide(LoggerLive),
|
|
32
|
+
* NodeRuntime.runMain
|
|
33
|
+
* )
|
|
34
|
+
*/
|
|
35
|
+
export const toFile: {
|
|
36
|
+
(
|
|
37
|
+
path: string,
|
|
38
|
+
options?:
|
|
39
|
+
| (OpenFileOptions & {
|
|
40
|
+
readonly batchWindow?:
|
|
41
|
+
| DurationInput
|
|
42
|
+
| undefined
|
|
43
|
+
})
|
|
44
|
+
| undefined
|
|
45
|
+
): <Message>(
|
|
46
|
+
self: Logger.Logger<Message, string>
|
|
47
|
+
) => Effect<Logger.Logger<Message, void>, PlatformError, Scope | FileSystem>
|
|
48
|
+
<Message>(
|
|
49
|
+
self: Logger.Logger<Message, string>,
|
|
50
|
+
path: string,
|
|
51
|
+
options?:
|
|
52
|
+
| (OpenFileOptions & {
|
|
53
|
+
readonly batchWindow?:
|
|
54
|
+
| DurationInput
|
|
55
|
+
| undefined
|
|
56
|
+
})
|
|
57
|
+
| undefined
|
|
58
|
+
): Effect<Logger.Logger<Message, void>, PlatformError, Scope | FileSystem>
|
|
59
|
+
} = internal.toFile
|