@effect/platform 0.40.1 → 0.40.3
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/Http/Multiplex/package.json +6 -0
- package/dist/cjs/Http/IncomingMessage.js +3 -3
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/Http/Multiplex.js +93 -0
- package/dist/cjs/Http/Multiplex.js.map +1 -0
- package/dist/cjs/HttpServer.js +3 -1
- package/dist/cjs/HttpServer.js.map +1 -1
- package/dist/cjs/Transferable.js.map +1 -1
- package/dist/cjs/Worker.js.map +1 -1
- package/dist/cjs/internal/http/multiplex.js +85 -0
- package/dist/cjs/internal/http/multiplex.js.map +1 -0
- package/dist/cjs/internal/http/router.js +1 -3
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/worker.js +8 -5
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/cjs/internal/workerRunner.js +12 -2
- package/dist/cjs/internal/workerRunner.js.map +1 -1
- package/dist/dts/Http/Multiplex.d.ts +111 -0
- package/dist/dts/Http/Multiplex.d.ts.map +1 -0
- package/dist/dts/HttpClient.d.ts +7 -7
- package/dist/dts/HttpServer.d.ts +18 -10
- package/dist/dts/HttpServer.d.ts.map +1 -1
- package/dist/dts/Transferable.d.ts +3 -3
- package/dist/dts/Transferable.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +10 -3
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/internal/http/multiplex.d.ts +2 -0
- package/dist/dts/internal/http/multiplex.d.ts.map +1 -0
- package/dist/esm/Http/IncomingMessage.js +3 -3
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/Http/Multiplex.js +62 -0
- package/dist/esm/Http/Multiplex.js.map +1 -0
- package/dist/esm/HttpClient.js +7 -7
- package/dist/esm/HttpServer.js +18 -10
- package/dist/esm/HttpServer.js.map +1 -1
- package/dist/esm/Transferable.js.map +1 -1
- package/dist/esm/Worker.js.map +1 -1
- package/dist/esm/internal/http/multiplex.js +53 -0
- package/dist/esm/internal/http/multiplex.js.map +1 -0
- package/dist/esm/internal/http/router.js +1 -3
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/worker.js +8 -5
- package/dist/esm/internal/worker.js.map +1 -1
- package/dist/esm/internal/workerRunner.js +12 -2
- package/dist/esm/internal/workerRunner.js.map +1 -1
- package/package.json +11 -3
- package/src/Http/IncomingMessage.ts +3 -3
- package/src/Http/Multiplex.ts +174 -0
- package/src/HttpClient.ts +7 -7
- package/src/HttpServer.ts +18 -10
- package/src/Transferable.ts +6 -11
- package/src/Worker.ts +13 -3
- package/src/internal/http/multiplex.ts +222 -0
- package/src/internal/http/router.ts +7 -7
- package/src/internal/worker.ts +18 -8
- package/src/internal/workerRunner.ts +13 -2
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type * as Effect from "effect/Effect"
|
|
5
|
+
import * as internal from "../internal/http/multiplex.js"
|
|
6
|
+
import type * as App from "./App.js"
|
|
7
|
+
import type * as Error from "./ServerError.js"
|
|
8
|
+
import type * as ServerRequest from "./ServerRequest.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
* @category type ids
|
|
13
|
+
*/
|
|
14
|
+
export const TypeId: unique symbol = internal.TypeId
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
* @category type ids
|
|
19
|
+
*/
|
|
20
|
+
export type TypeId = typeof TypeId
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
* @category models
|
|
25
|
+
*/
|
|
26
|
+
export interface Multiplex<R, E> extends App.Default<R, E | Error.RouteNotFound> {
|
|
27
|
+
readonly [TypeId]: TypeId
|
|
28
|
+
readonly apps: ReadonlyArray<
|
|
29
|
+
readonly [
|
|
30
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R, E, boolean>,
|
|
31
|
+
app: App.Default<R, E>
|
|
32
|
+
]
|
|
33
|
+
>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @category constructors
|
|
39
|
+
*/
|
|
40
|
+
export const empty: Multiplex<never, never> = internal.empty
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
* @category constructors
|
|
45
|
+
*/
|
|
46
|
+
export const make: <R, E>(
|
|
47
|
+
apps: Iterable<
|
|
48
|
+
readonly [predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R, E, boolean>, app: App.Default<R, E>]
|
|
49
|
+
>
|
|
50
|
+
) => Multiplex<R, E> = internal.make
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
* @category combinators
|
|
55
|
+
*/
|
|
56
|
+
export const add: {
|
|
57
|
+
<R2, E2, R3, E3>(
|
|
58
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R2, E2, boolean>,
|
|
59
|
+
app: App.Default<R3, E3>
|
|
60
|
+
): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R3 | R, E2 | E3 | E>
|
|
61
|
+
<R, E, R2, E2, R3, E3>(
|
|
62
|
+
self: Multiplex<R, E>,
|
|
63
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R2, E2, boolean>,
|
|
64
|
+
app: App.Default<R3, E3>
|
|
65
|
+
): Multiplex<R | R2 | R3, E | E2 | E3>
|
|
66
|
+
} = internal.add
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category combinators
|
|
71
|
+
*/
|
|
72
|
+
export const headerExact: {
|
|
73
|
+
<R2, E2>(
|
|
74
|
+
header: string,
|
|
75
|
+
value: string,
|
|
76
|
+
app: App.Default<R2, E2>
|
|
77
|
+
): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
78
|
+
<R, E, R2, E2>(
|
|
79
|
+
self: Multiplex<R, E>,
|
|
80
|
+
header: string,
|
|
81
|
+
value: string,
|
|
82
|
+
app: App.Default<R2, E2>
|
|
83
|
+
): Multiplex<R | R2, E | E2>
|
|
84
|
+
} = internal.headerExact
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @since 1.0.0
|
|
88
|
+
* @category combinators
|
|
89
|
+
*/
|
|
90
|
+
export const headerRegex: {
|
|
91
|
+
<R2, E2>(
|
|
92
|
+
header: string,
|
|
93
|
+
regex: RegExp,
|
|
94
|
+
app: App.Default<R2, E2>
|
|
95
|
+
): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
96
|
+
<R, E, R2, E2>(
|
|
97
|
+
self: Multiplex<R, E>,
|
|
98
|
+
header: string,
|
|
99
|
+
regex: RegExp,
|
|
100
|
+
app: App.Default<R2, E2>
|
|
101
|
+
): Multiplex<R | R2, E | E2>
|
|
102
|
+
} = internal.headerRegex
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @since 1.0.0
|
|
106
|
+
* @category combinators
|
|
107
|
+
*/
|
|
108
|
+
export const headerStartsWith: {
|
|
109
|
+
<R2, E2>(
|
|
110
|
+
header: string,
|
|
111
|
+
prefix: string,
|
|
112
|
+
app: App.Default<R2, E2>
|
|
113
|
+
): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
114
|
+
<R, E, R2, E2>(
|
|
115
|
+
self: Multiplex<R, E>,
|
|
116
|
+
header: string,
|
|
117
|
+
prefix: string,
|
|
118
|
+
app: App.Default<R2, E2>
|
|
119
|
+
): Multiplex<R | R2, E | E2>
|
|
120
|
+
} = internal.headerStartsWith
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
* @category combinators
|
|
125
|
+
*/
|
|
126
|
+
export const headerEndsWith: {
|
|
127
|
+
<R2, E2>(
|
|
128
|
+
header: string,
|
|
129
|
+
suffix: string,
|
|
130
|
+
app: App.Default<R2, E2>
|
|
131
|
+
): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
132
|
+
<R, E, R2, E2>(
|
|
133
|
+
self: Multiplex<R, E>,
|
|
134
|
+
header: string,
|
|
135
|
+
suffix: string,
|
|
136
|
+
app: App.Default<R2, E2>
|
|
137
|
+
): Multiplex<R | R2, E | E2>
|
|
138
|
+
} = internal.headerEndsWith
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @since 1.0.0
|
|
142
|
+
* @category combinators
|
|
143
|
+
*/
|
|
144
|
+
export const hostExact: {
|
|
145
|
+
<R2, E2>(host: string, app: App.Default<R2, E2>): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
146
|
+
<R, E, R2, E2>(self: Multiplex<R, E>, host: string, app: App.Default<R2, E2>): Multiplex<R | R2, E | E2>
|
|
147
|
+
} = internal.hostExact
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @since 1.0.0
|
|
151
|
+
* @category combinators
|
|
152
|
+
*/
|
|
153
|
+
export const hostRegex: {
|
|
154
|
+
<R2, E2>(regex: RegExp, app: App.Default<R2, E2>): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
155
|
+
<R, E, R2, E2>(self: Multiplex<R, E>, regex: RegExp, app: App.Default<R2, E2>): Multiplex<R | R2, E | E2>
|
|
156
|
+
} = internal.hostRegex
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @since 1.0.0
|
|
160
|
+
* @category combinators
|
|
161
|
+
*/
|
|
162
|
+
export const hostStartsWith: {
|
|
163
|
+
<R2, E2>(prefix: string, app: App.Default<R2, E2>): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
164
|
+
<R, E, R2, E2>(self: Multiplex<R, E>, prefix: string, app: App.Default<R2, E2>): Multiplex<R | R2, E | E2>
|
|
165
|
+
} = internal.hostStartsWith
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @since 1.0.0
|
|
169
|
+
* @category combinators
|
|
170
|
+
*/
|
|
171
|
+
export const hostEndsWith: {
|
|
172
|
+
<R2, E2>(suffix: string, app: App.Default<R2, E2>): <R, E>(self: Multiplex<R, E>) => Multiplex<R2 | R, E2 | E>
|
|
173
|
+
<R, E, R2, E2>(self: Multiplex<R, E>, suffix: string, app: App.Default<R2, E2>): Multiplex<R | R2, E | E2>
|
|
174
|
+
} = internal.hostEndsWith
|
package/src/HttpClient.ts
CHANGED
|
@@ -13,49 +13,49 @@ export {
|
|
|
13
13
|
/**
|
|
14
14
|
* @since 1.0.0
|
|
15
15
|
*
|
|
16
|
-
* - Docs: [Http/Body](https://effect-ts.github.io/
|
|
16
|
+
* - Docs: [Http/Body](https://effect-ts.github.io/effect/platform/Http/Body.ts.html)
|
|
17
17
|
* - Module: `@effect/platform/Http/Body`
|
|
18
18
|
*/
|
|
19
19
|
body,
|
|
20
20
|
/**
|
|
21
21
|
* @since 1.0.0
|
|
22
22
|
*
|
|
23
|
-
* - Docs: [Http/Client](https://effect-ts.github.io/
|
|
23
|
+
* - Docs: [Http/Client](https://effect-ts.github.io/effect/platform/Http/Client.ts.html)
|
|
24
24
|
* - Module: `@effect/platform/Http/Client`
|
|
25
25
|
*/
|
|
26
26
|
client,
|
|
27
27
|
/**
|
|
28
28
|
* @since 1.0.0
|
|
29
29
|
*
|
|
30
|
-
* - Docs: [Http/ClientError](https://effect-ts.github.io/
|
|
30
|
+
* - Docs: [Http/ClientError](https://effect-ts.github.io/effect/platform/Http/ClientError.ts.html)
|
|
31
31
|
* - Module: `@effect/platform/Http/ClientError`
|
|
32
32
|
*/
|
|
33
33
|
error,
|
|
34
34
|
/**
|
|
35
35
|
* @since 1.0.0
|
|
36
36
|
*
|
|
37
|
-
* - Docs: [Http/Headers](https://effect-ts.github.io/
|
|
37
|
+
* - Docs: [Http/Headers](https://effect-ts.github.io/effect/platform/Http/Headers.ts.html)
|
|
38
38
|
* - Module: `@effect/platform/Http/Headers`
|
|
39
39
|
*/
|
|
40
40
|
headers,
|
|
41
41
|
/**
|
|
42
42
|
* @since 1.0.0
|
|
43
43
|
*
|
|
44
|
-
* - Docs: [Http/ClientRequest](https://effect-ts.github.io/
|
|
44
|
+
* - Docs: [Http/ClientRequest](https://effect-ts.github.io/effect/platform/Http/ClientRequest.ts.html)
|
|
45
45
|
* - Module: `@effect/platform/Http/ClientRequest`
|
|
46
46
|
*/
|
|
47
47
|
request,
|
|
48
48
|
/**
|
|
49
49
|
* @since 1.0.0
|
|
50
50
|
*
|
|
51
|
-
* - Docs: [Http/ClientResponse](https://effect-ts.github.io/
|
|
51
|
+
* - Docs: [Http/ClientResponse](https://effect-ts.github.io/effect/platform/Http/ClientResponse.ts.html)
|
|
52
52
|
* - Module: `@effect/platform/Http/ClientResponse`
|
|
53
53
|
*/
|
|
54
54
|
response,
|
|
55
55
|
/**
|
|
56
56
|
* @since 1.0.0
|
|
57
57
|
*
|
|
58
|
-
* - Docs: [Http/UrlParams](https://effect-ts.github.io/
|
|
58
|
+
* - Docs: [Http/UrlParams](https://effect-ts.github.io/effect/platform/Http/UrlParams.ts.html)
|
|
59
59
|
* - Module: `@effect/platform/Http/UrlParams`
|
|
60
60
|
*/
|
|
61
61
|
urlParams
|
package/src/HttpServer.ts
CHANGED
|
@@ -6,6 +6,7 @@ import * as body from "./Http/Body.js"
|
|
|
6
6
|
import * as headers from "./Http/Headers.js"
|
|
7
7
|
import * as middleware from "./Http/Middleware.js"
|
|
8
8
|
import * as multipart from "./Http/Multipart.js"
|
|
9
|
+
import * as multiplex from "./Http/Multiplex.js"
|
|
9
10
|
import * as router from "./Http/Router.js"
|
|
10
11
|
import * as error from "./Http/ServerError.js"
|
|
11
12
|
import * as request from "./Http/ServerRequest.js"
|
|
@@ -16,70 +17,77 @@ export {
|
|
|
16
17
|
/**
|
|
17
18
|
* @since 1.0.0
|
|
18
19
|
*
|
|
19
|
-
* - Docs: [Http/App](https://effect-ts.github.io/
|
|
20
|
+
* - Docs: [Http/App](https://effect-ts.github.io/effect/platform/Http/App.ts.html)
|
|
20
21
|
* - Module: `@effect/platform/Http/App`
|
|
21
22
|
*/
|
|
22
23
|
app,
|
|
23
24
|
/**
|
|
24
25
|
* @since 1.0.0
|
|
25
26
|
*
|
|
26
|
-
* - Docs: [Http/Body](https://effect-ts.github.io/
|
|
27
|
+
* - Docs: [Http/Body](https://effect-ts.github.io/effect/platform/Http/Body.ts.html)
|
|
27
28
|
* - Module: `@effect/platform/Http/Body`
|
|
28
29
|
*/
|
|
29
30
|
body,
|
|
30
31
|
/**
|
|
31
32
|
* @since 1.0.0
|
|
32
33
|
*
|
|
33
|
-
* - Docs: [Http/ServerError](https://effect-ts.github.io/
|
|
34
|
+
* - Docs: [Http/ServerError](https://effect-ts.github.io/effect/platform/Http/ServerError.ts.html)
|
|
34
35
|
* - Module: `@effect/platform/Http/ServerError`
|
|
35
36
|
*/
|
|
36
37
|
error,
|
|
37
38
|
/**
|
|
38
39
|
* @since 1.0.0
|
|
39
40
|
*
|
|
40
|
-
* - Docs: [Http/Headers](https://effect-ts.github.io/
|
|
41
|
+
* - Docs: [Http/Headers](https://effect-ts.github.io/effect/platform/Http/Headers.ts.html)
|
|
41
42
|
* - Module: `@effect/platform/Http/Headers`
|
|
42
43
|
*/
|
|
43
44
|
headers,
|
|
44
45
|
/**
|
|
45
46
|
* @since 1.0.0
|
|
46
47
|
*
|
|
47
|
-
* - Docs: [Http/Middleware](https://effect-ts.github.io/
|
|
48
|
+
* - Docs: [Http/Middleware](https://effect-ts.github.io/effect/platform/Http/Middleware.ts.html)
|
|
48
49
|
* - Module: `@effect/platform/Http/Middleware`
|
|
49
50
|
*/
|
|
50
51
|
middleware,
|
|
51
52
|
/**
|
|
52
53
|
* @since 1.0.0
|
|
53
54
|
*
|
|
54
|
-
* - Docs: [Http/Multipart](https://effect-ts.github.io/
|
|
55
|
+
* - Docs: [Http/Multipart](https://effect-ts.github.io/effect/platform/Http/Multipart.ts.html)
|
|
55
56
|
* - Module: `@effect/platform/Http/Multipart`
|
|
56
57
|
*/
|
|
57
58
|
multipart,
|
|
58
59
|
/**
|
|
59
60
|
* @since 1.0.0
|
|
60
61
|
*
|
|
61
|
-
* - Docs: [Http/
|
|
62
|
+
* - Docs: [Http/Multiplex](https://effect-ts.github.io/effect/platform/Http/Multiplex.ts.html)
|
|
63
|
+
* - Module: `@effect/platform/Http/Multiplex`
|
|
64
|
+
*/
|
|
65
|
+
multiplex,
|
|
66
|
+
/**
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*
|
|
69
|
+
* - Docs: [Http/ServerRequest](https://effect-ts.github.io/effect/platform/Http/ServerRequest.ts.html)
|
|
62
70
|
* - Module: `@effect/platform/Http/ServerRequest`
|
|
63
71
|
*/
|
|
64
72
|
request,
|
|
65
73
|
/**
|
|
66
74
|
* @since 1.0.0
|
|
67
75
|
*
|
|
68
|
-
* - Docs: [Http/ServerResponse](https://effect-ts.github.io/
|
|
76
|
+
* - Docs: [Http/ServerResponse](https://effect-ts.github.io/effect/platform/Http/ServerResponse.ts.html)
|
|
69
77
|
* - Module: `@effect/platform/Http/ServerResponse`
|
|
70
78
|
*/
|
|
71
79
|
response,
|
|
72
80
|
/**
|
|
73
81
|
* @since 1.0.0
|
|
74
82
|
*
|
|
75
|
-
* - Docs: [Http/Router](https://effect-ts.github.io/
|
|
83
|
+
* - Docs: [Http/Router](https://effect-ts.github.io/effect/platform/Http/Router.ts.html)
|
|
76
84
|
* - Module: `@effect/platform/Http/Router`
|
|
77
85
|
*/
|
|
78
86
|
router,
|
|
79
87
|
/**
|
|
80
88
|
* @since 1.0.0
|
|
81
89
|
*
|
|
82
|
-
* - Docs: [Http/UrlParams](https://effect-ts.github.io/
|
|
90
|
+
* - Docs: [Http/UrlParams](https://effect-ts.github.io/effect/platform/Http/UrlParams.ts.html)
|
|
83
91
|
* - Module: `@effect/platform/Http/UrlParams`
|
|
84
92
|
*/
|
|
85
93
|
urlParams
|
package/src/Transferable.ts
CHANGED
|
@@ -43,21 +43,16 @@ export const get = (u: unknown): ReadonlyArray<globalThis.Transferable> => {
|
|
|
43
43
|
* @category schema
|
|
44
44
|
*/
|
|
45
45
|
export const schema: {
|
|
46
|
-
<A>(
|
|
47
|
-
|
|
48
|
-
): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A & Transferable>
|
|
49
|
-
<I, A>(
|
|
50
|
-
self: Schema.Schema<I, A>,
|
|
51
|
-
f: (_: A) => ReadonlyArray<globalThis.Transferable>
|
|
52
|
-
): Schema.Schema<I, A & Transferable>
|
|
46
|
+
<A>(f: (_: A) => ReadonlyArray<globalThis.Transferable>): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A>
|
|
47
|
+
<I, A>(self: Schema.Schema<I, A>, f: (_: A) => ReadonlyArray<globalThis.Transferable>): Schema.Schema<I, A>
|
|
53
48
|
} = dual<
|
|
54
49
|
<A>(
|
|
55
50
|
f: (_: A) => ReadonlyArray<globalThis.Transferable>
|
|
56
|
-
) => <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A
|
|
51
|
+
) => <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A>,
|
|
57
52
|
<I, A>(
|
|
58
53
|
self: Schema.Schema<I, A>,
|
|
59
54
|
f: (_: A) => ReadonlyArray<globalThis.Transferable>
|
|
60
|
-
) => Schema.Schema<I, A
|
|
55
|
+
) => Schema.Schema<I, A>
|
|
61
56
|
>(2, <I, A>(
|
|
62
57
|
self: Schema.Schema<I, A>,
|
|
63
58
|
f: (_: A) => ReadonlyArray<globalThis.Transferable>
|
|
@@ -71,7 +66,7 @@ export const schema: {
|
|
|
71
66
|
[symbol]() {
|
|
72
67
|
return f(this as any)
|
|
73
68
|
}
|
|
74
|
-
}) as A
|
|
69
|
+
}) as A,
|
|
75
70
|
(output) => output as A
|
|
76
71
|
))
|
|
77
72
|
|
|
@@ -81,7 +76,7 @@ export const schema: {
|
|
|
81
76
|
*/
|
|
82
77
|
export const schemaFromSelf = <I, A>(
|
|
83
78
|
item: Schema.Schema<I, A>
|
|
84
|
-
): Schema.Schema<I
|
|
79
|
+
): Schema.Schema<I, A> => {
|
|
85
80
|
return Schema.declare(
|
|
86
81
|
[item],
|
|
87
82
|
item,
|
package/src/Worker.ts
CHANGED
|
@@ -10,10 +10,12 @@ import type * as Effect from "effect/Effect"
|
|
|
10
10
|
import type * as Fiber from "effect/Fiber"
|
|
11
11
|
import type { LazyArg } from "effect/Function"
|
|
12
12
|
import type * as Layer from "effect/Layer"
|
|
13
|
+
import type * as Option from "effect/Option"
|
|
13
14
|
import type * as Pool from "effect/Pool"
|
|
14
15
|
import type * as Queue from "effect/Queue"
|
|
15
16
|
import type * as Scope from "effect/Scope"
|
|
16
17
|
import type * as Stream from "effect/Stream"
|
|
18
|
+
import type * as Tracer from "effect/Tracer"
|
|
17
19
|
import * as internal from "./internal/worker.js"
|
|
18
20
|
import type { WorkerError } from "./WorkerError.js"
|
|
19
21
|
|
|
@@ -98,7 +100,15 @@ export declare namespace Worker {
|
|
|
98
100
|
* @since 1.0.0
|
|
99
101
|
* @category models
|
|
100
102
|
*/
|
|
101
|
-
export type Request<I = unknown> =
|
|
103
|
+
export type Request<I = unknown> =
|
|
104
|
+
| readonly [id: number, data: 0, I, trace?: Span]
|
|
105
|
+
| readonly [id: number, interrupt: 1]
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @since 1.0.0
|
|
109
|
+
* @category models
|
|
110
|
+
*/
|
|
111
|
+
export type Span = readonly [traceId: string, spanId: string, sampled: boolean]
|
|
102
112
|
|
|
103
113
|
/**
|
|
104
114
|
* @since 1.0.0
|
|
@@ -150,8 +160,8 @@ export declare namespace WorkerPool {
|
|
|
150
160
|
* @since 1.0.0
|
|
151
161
|
*/
|
|
152
162
|
export interface WorkerQueue<I> {
|
|
153
|
-
readonly offer: (id: number, item: I) => Effect.Effect<never, never, void>
|
|
154
|
-
readonly take: Effect.Effect<never, never, readonly [id: number, item: I]>
|
|
163
|
+
readonly offer: (id: number, item: I, span: Option.Option<Tracer.Span>) => Effect.Effect<never, never, void>
|
|
164
|
+
readonly take: Effect.Effect<never, never, readonly [id: number, item: I, span: Option.Option<Tracer.Span>]>
|
|
155
165
|
readonly shutdown: Effect.Effect<never, never, void>
|
|
156
166
|
}
|
|
157
167
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import * as Effectable from "effect/Effectable"
|
|
3
|
+
import { dual } from "effect/Function"
|
|
4
|
+
import * as ReadonlyArray from "effect/ReadonlyArray"
|
|
5
|
+
import type * as App from "../../Http/App.js"
|
|
6
|
+
import type * as Multiplex from "../../Http/Multiplex.js"
|
|
7
|
+
import * as Error from "../../Http/ServerError.js"
|
|
8
|
+
import * as ServerRequest from "../../Http/ServerRequest.js"
|
|
9
|
+
import type * as ServerResponse from "../../Http/ServerResponse.js"
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const TypeId: Multiplex.TypeId = Symbol.for("@effect/platform/Http/Multiplex") as Multiplex.TypeId
|
|
13
|
+
|
|
14
|
+
class MultiplexImpl<R, E>
|
|
15
|
+
extends Effectable.Class<R | ServerRequest.ServerRequest, E | Error.RouteNotFound, ServerResponse.ServerResponse>
|
|
16
|
+
implements Multiplex.Multiplex<R, E>
|
|
17
|
+
{
|
|
18
|
+
readonly [TypeId]: Multiplex.TypeId
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
readonly apps: ReadonlyArray<
|
|
22
|
+
readonly [
|
|
23
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R, E, boolean>,
|
|
24
|
+
app: App.Default<R, E>
|
|
25
|
+
]
|
|
26
|
+
>
|
|
27
|
+
) {
|
|
28
|
+
super()
|
|
29
|
+
this[TypeId] = TypeId
|
|
30
|
+
|
|
31
|
+
let execute: (request: ServerRequest.ServerRequest) => App.Default<R, E | Error.RouteNotFound> = (request) =>
|
|
32
|
+
Effect.fail(Error.RouteNotFound({ request }))
|
|
33
|
+
|
|
34
|
+
for (let i = apps.length - 1; i >= 0; i--) {
|
|
35
|
+
const [predicate, app] = apps[i]
|
|
36
|
+
const previous = execute
|
|
37
|
+
execute = (request) =>
|
|
38
|
+
Effect.flatMap(
|
|
39
|
+
predicate(request),
|
|
40
|
+
(match) => match ? app : previous(request)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.execute = Effect.flatMap(ServerRequest.ServerRequest, execute)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
execute: App.Default<R, E | Error.RouteNotFound>
|
|
48
|
+
|
|
49
|
+
commit() {
|
|
50
|
+
return this.execute
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @internal */
|
|
55
|
+
export const empty: Multiplex.Multiplex<never, never> = new MultiplexImpl([])
|
|
56
|
+
|
|
57
|
+
/** @internal */
|
|
58
|
+
export const make = <R, E>(
|
|
59
|
+
apps: Iterable<
|
|
60
|
+
readonly [predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R, E, boolean>, app: App.Default<R, E>]
|
|
61
|
+
>
|
|
62
|
+
): Multiplex.Multiplex<R, E> => new MultiplexImpl(ReadonlyArray.fromIterable(apps))
|
|
63
|
+
|
|
64
|
+
/** @internal */
|
|
65
|
+
export const add = dual<
|
|
66
|
+
<R2, E2, R3, E3>(
|
|
67
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R2, E2, boolean>,
|
|
68
|
+
app: App.Default<R3, E3>
|
|
69
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2 | R3, E | E2 | E3>,
|
|
70
|
+
<R, E, R2, E2, R3, E3>(
|
|
71
|
+
self: Multiplex.Multiplex<R, E>,
|
|
72
|
+
predicate: (request: ServerRequest.ServerRequest) => Effect.Effect<R2, E2, boolean>,
|
|
73
|
+
app: App.Default<R3, E3>
|
|
74
|
+
) => Multiplex.Multiplex<R | R2 | R3, E | E2 | E3>
|
|
75
|
+
>(
|
|
76
|
+
3,
|
|
77
|
+
(self, predicate, app) =>
|
|
78
|
+
make([
|
|
79
|
+
...self.apps,
|
|
80
|
+
[predicate, app]
|
|
81
|
+
] as any)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
/** @internal */
|
|
85
|
+
export const headerExact = dual<
|
|
86
|
+
<R2, E2>(
|
|
87
|
+
header: string,
|
|
88
|
+
value: string,
|
|
89
|
+
app: App.Default<R2, E2>
|
|
90
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
91
|
+
<R, E, R2, E2>(
|
|
92
|
+
self: Multiplex.Multiplex<R, E>,
|
|
93
|
+
header: string,
|
|
94
|
+
value: string,
|
|
95
|
+
app: App.Default<R2, E2>
|
|
96
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
97
|
+
>(
|
|
98
|
+
4,
|
|
99
|
+
(self, header, value, app) =>
|
|
100
|
+
add(self, (req) =>
|
|
101
|
+
req.headers[header] !== undefined
|
|
102
|
+
? Effect.succeed(req.headers[header] === value)
|
|
103
|
+
: Effect.succeed(false), app)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
/** @internal */
|
|
107
|
+
export const headerRegex = dual<
|
|
108
|
+
<R2, E2>(
|
|
109
|
+
header: string,
|
|
110
|
+
regex: RegExp,
|
|
111
|
+
app: App.Default<R2, E2>
|
|
112
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
113
|
+
<R, E, R2, E2>(
|
|
114
|
+
self: Multiplex.Multiplex<R, E>,
|
|
115
|
+
header: string,
|
|
116
|
+
regex: RegExp,
|
|
117
|
+
app: App.Default<R2, E2>
|
|
118
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
119
|
+
>(
|
|
120
|
+
4,
|
|
121
|
+
(self, header, regex, app) =>
|
|
122
|
+
add(self, (req) =>
|
|
123
|
+
req.headers[header] !== undefined
|
|
124
|
+
? Effect.succeed(regex.test(req.headers[header]))
|
|
125
|
+
: Effect.succeed(false), app)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
export const headerStartsWith = dual<
|
|
130
|
+
<R2, E2>(
|
|
131
|
+
header: string,
|
|
132
|
+
prefix: string,
|
|
133
|
+
app: App.Default<R2, E2>
|
|
134
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
135
|
+
<R, E, R2, E2>(
|
|
136
|
+
self: Multiplex.Multiplex<R, E>,
|
|
137
|
+
header: string,
|
|
138
|
+
prefix: string,
|
|
139
|
+
app: App.Default<R2, E2>
|
|
140
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
141
|
+
>(
|
|
142
|
+
4,
|
|
143
|
+
(self, header, prefix, app) =>
|
|
144
|
+
add(self, (req) =>
|
|
145
|
+
req.headers[header] !== undefined
|
|
146
|
+
? Effect.succeed(req.headers[header].startsWith(prefix))
|
|
147
|
+
: Effect.succeed(false), app)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
/** @internal */
|
|
151
|
+
export const headerEndsWith = dual<
|
|
152
|
+
<R2, E2>(
|
|
153
|
+
header: string,
|
|
154
|
+
suffix: string,
|
|
155
|
+
app: App.Default<R2, E2>
|
|
156
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
157
|
+
<R, E, R2, E2>(
|
|
158
|
+
self: Multiplex.Multiplex<R, E>,
|
|
159
|
+
header: string,
|
|
160
|
+
suffix: string,
|
|
161
|
+
app: App.Default<R2, E2>
|
|
162
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
163
|
+
>(
|
|
164
|
+
4,
|
|
165
|
+
(self, header, suffix, app) =>
|
|
166
|
+
add(self, (req) =>
|
|
167
|
+
req.headers[header] !== undefined
|
|
168
|
+
? Effect.succeed(req.headers[header].endsWith(suffix))
|
|
169
|
+
: Effect.succeed(false), app)
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
/** @internal */
|
|
173
|
+
export const hostRegex = dual<
|
|
174
|
+
<R2, E2>(
|
|
175
|
+
regex: RegExp,
|
|
176
|
+
app: App.Default<R2, E2>
|
|
177
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
178
|
+
<R, E, R2, E2>(
|
|
179
|
+
self: Multiplex.Multiplex<R, E>,
|
|
180
|
+
regex: RegExp,
|
|
181
|
+
app: App.Default<R2, E2>
|
|
182
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
183
|
+
>(3, (self, regex, app) => headerRegex(self, "host", regex, app))
|
|
184
|
+
|
|
185
|
+
/** @internal */
|
|
186
|
+
export const hostStartsWith = dual<
|
|
187
|
+
<R2, E2>(
|
|
188
|
+
prefix: string,
|
|
189
|
+
app: App.Default<R2, E2>
|
|
190
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
191
|
+
<R, E, R2, E2>(
|
|
192
|
+
self: Multiplex.Multiplex<R, E>,
|
|
193
|
+
prefix: string,
|
|
194
|
+
app: App.Default<R2, E2>
|
|
195
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
196
|
+
>(3, (self, prefix, app) => headerStartsWith(self, "host", prefix, app))
|
|
197
|
+
|
|
198
|
+
/** @internal */
|
|
199
|
+
export const hostEndsWith = dual<
|
|
200
|
+
<R2, E2>(
|
|
201
|
+
suffix: string,
|
|
202
|
+
app: App.Default<R2, E2>
|
|
203
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
204
|
+
<R, E, R2, E2>(
|
|
205
|
+
self: Multiplex.Multiplex<R, E>,
|
|
206
|
+
suffix: string,
|
|
207
|
+
app: App.Default<R2, E2>
|
|
208
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
209
|
+
>(3, (self, suffix, app) => headerEndsWith(self, "host", suffix, app))
|
|
210
|
+
|
|
211
|
+
/** @internal */
|
|
212
|
+
export const hostExact = dual<
|
|
213
|
+
<R2, E2>(
|
|
214
|
+
host: string,
|
|
215
|
+
app: App.Default<R2, E2>
|
|
216
|
+
) => <R, E>(self: Multiplex.Multiplex<R, E>) => Multiplex.Multiplex<R | R2, E | E2>,
|
|
217
|
+
<R, E, R2, E2>(
|
|
218
|
+
self: Multiplex.Multiplex<R, E>,
|
|
219
|
+
host: string,
|
|
220
|
+
app: App.Default<R2, E2>
|
|
221
|
+
) => Multiplex.Multiplex<R | R2, E | E2>
|
|
222
|
+
>(3, (self, host, app) => headerExact(self, "host", host, app))
|
|
@@ -65,15 +65,15 @@ class RouterImpl<R, E> extends Effectable.StructuralClass<
|
|
|
65
65
|
) {
|
|
66
66
|
super()
|
|
67
67
|
this[TypeId] = TypeId
|
|
68
|
+
this.httpApp = toHttpApp(this) as any
|
|
68
69
|
}
|
|
69
|
-
private httpApp:
|
|
70
|
-
|
|
71
|
-
|
|
|
70
|
+
private httpApp: Effect.Effect<
|
|
71
|
+
Exclude<R, Router.RouteContext>,
|
|
72
|
+
E | Error.RouteNotFound,
|
|
73
|
+
ServerResponse.ServerResponse
|
|
74
|
+
>
|
|
72
75
|
commit() {
|
|
73
|
-
|
|
74
|
-
this.httpApp = toHttpApp(this) as any
|
|
75
|
-
}
|
|
76
|
-
return this.httpApp!
|
|
76
|
+
return this.httpApp
|
|
77
77
|
}
|
|
78
78
|
toJSON() {
|
|
79
79
|
return {
|