@effect/platform 0.79.3 → 0.80.0

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.
Files changed (105) hide show
  1. package/ChannelSchema/package.json +6 -0
  2. package/MsgPack/package.json +6 -0
  3. package/Ndjson/package.json +6 -0
  4. package/SocketServer/package.json +6 -0
  5. package/dist/cjs/ChannelSchema.js +69 -0
  6. package/dist/cjs/ChannelSchema.js.map +1 -0
  7. package/dist/cjs/Headers.js +1 -1
  8. package/dist/cjs/Headers.js.map +1 -1
  9. package/dist/cjs/HttpApiClient.js +1 -1
  10. package/dist/cjs/HttpApiClient.js.map +1 -1
  11. package/dist/cjs/HttpApiEndpoint.js +11 -1
  12. package/dist/cjs/HttpApiEndpoint.js.map +1 -1
  13. package/dist/cjs/HttpBody.js.map +1 -1
  14. package/dist/cjs/HttpRouter.js.map +1 -1
  15. package/dist/cjs/MsgPack.js +148 -0
  16. package/dist/cjs/MsgPack.js.map +1 -0
  17. package/dist/cjs/Ndjson.js +152 -0
  18. package/dist/cjs/Ndjson.js.map +1 -0
  19. package/dist/cjs/SocketServer.js +43 -0
  20. package/dist/cjs/SocketServer.js.map +1 -0
  21. package/dist/cjs/Transferable.js +6 -5
  22. package/dist/cjs/Transferable.js.map +1 -1
  23. package/dist/cjs/Url.js.map +1 -1
  24. package/dist/cjs/UrlParams.js +19 -1
  25. package/dist/cjs/UrlParams.js.map +1 -1
  26. package/dist/cjs/WorkerRunner.js.map +1 -1
  27. package/dist/cjs/index.js +9 -1
  28. package/dist/cjs/internal/httpRouter.js +2 -0
  29. package/dist/cjs/internal/httpRouter.js.map +1 -1
  30. package/dist/cjs/internal/worker.js +1 -1
  31. package/dist/cjs/internal/worker.js.map +1 -1
  32. package/dist/dts/ChannelSchema.d.ts +69 -0
  33. package/dist/dts/ChannelSchema.d.ts.map +1 -0
  34. package/dist/dts/Headers.d.ts +1 -1
  35. package/dist/dts/Headers.d.ts.map +1 -1
  36. package/dist/dts/HttpApiClient.d.ts +3 -3
  37. package/dist/dts/HttpApiClient.d.ts.map +1 -1
  38. package/dist/dts/HttpApiEndpoint.d.ts +32 -0
  39. package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
  40. package/dist/dts/HttpBody.d.ts +1 -1
  41. package/dist/dts/HttpBody.d.ts.map +1 -1
  42. package/dist/dts/HttpRouter.d.ts +3 -0
  43. package/dist/dts/HttpRouter.d.ts.map +1 -1
  44. package/dist/dts/MsgPack.d.ts +103 -0
  45. package/dist/dts/MsgPack.d.ts.map +1 -0
  46. package/dist/dts/Ndjson.d.ts +169 -0
  47. package/dist/dts/Ndjson.d.ts.map +1 -0
  48. package/dist/dts/SocketServer.d.ts +70 -0
  49. package/dist/dts/SocketServer.d.ts.map +1 -0
  50. package/dist/dts/Transferable.d.ts +2 -2
  51. package/dist/dts/Transferable.d.ts.map +1 -1
  52. package/dist/dts/Url.d.ts +2 -2
  53. package/dist/dts/Url.d.ts.map +1 -1
  54. package/dist/dts/UrlParams.d.ts +8 -1
  55. package/dist/dts/UrlParams.d.ts.map +1 -1
  56. package/dist/dts/WorkerRunner.d.ts +3 -1
  57. package/dist/dts/WorkerRunner.d.ts.map +1 -1
  58. package/dist/dts/index.d.ts +16 -0
  59. package/dist/dts/index.d.ts.map +1 -1
  60. package/dist/dts/internal/httpRouter.d.ts.map +1 -1
  61. package/dist/esm/ChannelSchema.js +59 -0
  62. package/dist/esm/ChannelSchema.js.map +1 -0
  63. package/dist/esm/Headers.js +1 -1
  64. package/dist/esm/Headers.js.map +1 -1
  65. package/dist/esm/HttpApiClient.js +1 -1
  66. package/dist/esm/HttpApiClient.js.map +1 -1
  67. package/dist/esm/HttpApiEndpoint.js +10 -0
  68. package/dist/esm/HttpApiEndpoint.js.map +1 -1
  69. package/dist/esm/HttpBody.js.map +1 -1
  70. package/dist/esm/HttpRouter.js.map +1 -1
  71. package/dist/esm/MsgPack.js +137 -0
  72. package/dist/esm/MsgPack.js.map +1 -0
  73. package/dist/esm/Ndjson.js +134 -0
  74. package/dist/esm/Ndjson.js.map +1 -0
  75. package/dist/esm/SocketServer.js +32 -0
  76. package/dist/esm/SocketServer.js.map +1 -0
  77. package/dist/esm/Transferable.js +6 -5
  78. package/dist/esm/Transferable.js.map +1 -1
  79. package/dist/esm/Url.js.map +1 -1
  80. package/dist/esm/UrlParams.js +18 -0
  81. package/dist/esm/UrlParams.js.map +1 -1
  82. package/dist/esm/WorkerRunner.js.map +1 -1
  83. package/dist/esm/index.js +16 -0
  84. package/dist/esm/index.js.map +1 -1
  85. package/dist/esm/internal/httpRouter.js +2 -0
  86. package/dist/esm/internal/httpRouter.js.map +1 -1
  87. package/dist/esm/internal/worker.js +1 -1
  88. package/dist/esm/internal/worker.js.map +1 -1
  89. package/package.json +35 -2
  90. package/src/ChannelSchema.ts +267 -0
  91. package/src/Headers.ts +2 -2
  92. package/src/HttpApiClient.ts +9 -5
  93. package/src/HttpApiEndpoint.ts +36 -6
  94. package/src/HttpBody.ts +1 -1
  95. package/src/HttpRouter.ts +9 -0
  96. package/src/MsgPack.ts +372 -0
  97. package/src/Ndjson.ts +493 -0
  98. package/src/SocketServer.ts +79 -0
  99. package/src/Transferable.ts +9 -8
  100. package/src/Url.ts +5 -5
  101. package/src/UrlParams.ts +29 -2
  102. package/src/WorkerRunner.ts +3 -1
  103. package/src/index.ts +20 -0
  104. package/src/internal/httpRouter.ts +2 -0
  105. package/src/internal/worker.ts +1 -1
@@ -0,0 +1,267 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type * as Cause from "effect/Cause"
5
+ import * as Channel from "effect/Channel"
6
+ import type * as Chunk from "effect/Chunk"
7
+ import { dual, pipe } from "effect/Function"
8
+ import type { ParseError } from "effect/ParseResult"
9
+ import * as Schema from "effect/Schema"
10
+
11
+ /**
12
+ * @since 1.0.0
13
+ * @category constructors
14
+ */
15
+ export const encode = <A, I, R>(
16
+ schema: Schema.Schema<A, I, R>
17
+ ) =>
18
+ <IE = never, Done = unknown>(): Channel.Channel<
19
+ Chunk.Chunk<I>,
20
+ Chunk.Chunk<A>,
21
+ IE | ParseError,
22
+ IE,
23
+ Done,
24
+ Done,
25
+ R
26
+ > => {
27
+ const encode = Schema.encode(Schema.ChunkFromSelf(schema))
28
+ const loop: Channel.Channel<Chunk.Chunk<I>, Chunk.Chunk<A>, IE | ParseError, IE, Done, Done, R> = Channel
29
+ .readWithCause({
30
+ onInput: (input: Chunk.Chunk<A>) =>
31
+ Channel.zipRight(
32
+ Channel.flatMap(encode(input), Channel.write),
33
+ loop
34
+ ),
35
+ onFailure: (cause: Cause.Cause<IE>) => Channel.failCause(cause),
36
+ onDone: Channel.succeed
37
+ })
38
+ return loop
39
+ }
40
+
41
+ /**
42
+ * @since 1.0.0
43
+ * @category constructors
44
+ */
45
+ export const encodeUnknown: <A, I, R>(
46
+ schema: Schema.Schema<A, I, R>
47
+ ) => <IE = never, Done = unknown>() => Channel.Channel<
48
+ Chunk.Chunk<unknown>,
49
+ Chunk.Chunk<A>,
50
+ IE | ParseError,
51
+ IE,
52
+ Done,
53
+ Done,
54
+ R
55
+ > = encode as any
56
+
57
+ /**
58
+ * @since 1.0.0
59
+ * @category constructors
60
+ */
61
+ export const decode = <A, I, R>(
62
+ schema: Schema.Schema<A, I, R>
63
+ ) =>
64
+ <IE = never, Done = unknown>(): Channel.Channel<
65
+ Chunk.Chunk<A>,
66
+ Chunk.Chunk<I>,
67
+ ParseError | IE,
68
+ IE,
69
+ Done,
70
+ Done,
71
+ R
72
+ > => {
73
+ const decode = Schema.decode(Schema.ChunkFromSelf(schema))
74
+ const loop: Channel.Channel<Chunk.Chunk<A>, Chunk.Chunk<I>, ParseError | IE, IE, Done, Done, R> = Channel
75
+ .readWithCause({
76
+ onInput(chunk: Chunk.Chunk<I>) {
77
+ return decode(chunk).pipe(
78
+ Channel.flatMap(Channel.write),
79
+ Channel.zipRight(loop)
80
+ )
81
+ },
82
+ onFailure(cause: Cause.Cause<IE>) {
83
+ return Channel.failCause(cause)
84
+ },
85
+ onDone(done: Done) {
86
+ return Channel.succeed(done)
87
+ }
88
+ })
89
+ return loop
90
+ }
91
+
92
+ /**
93
+ * @since 1.0.0
94
+ * @category constructors
95
+ */
96
+ export const decodeUnknown: <A, I, R>(
97
+ schema: Schema.Schema<A, I, R>
98
+ ) => <IE = never, Done = unknown>() => Channel.Channel<
99
+ Chunk.Chunk<A>,
100
+ Chunk.Chunk<any>,
101
+ ParseError | IE,
102
+ IE,
103
+ Done,
104
+ Done,
105
+ R
106
+ > = decode as any
107
+
108
+ /**
109
+ * @since 1.0.0
110
+ * @category combinators
111
+ */
112
+ export const duplex: {
113
+ /**
114
+ * @since 1.0.0
115
+ * @category combinators
116
+ */
117
+ <IA, II, IR, OA, OI, OR>(
118
+ options: {
119
+ readonly inputSchema: Schema.Schema<IA, II, IR>
120
+ readonly outputSchema: Schema.Schema<OA, OI, OR>
121
+ }
122
+ ): <R, InErr, OutErr, OutDone, InDone>(
123
+ self: Channel.Channel<
124
+ Chunk.Chunk<OI>,
125
+ Chunk.Chunk<II>,
126
+ OutErr,
127
+ ParseError | InErr,
128
+ OutDone,
129
+ InDone,
130
+ R
131
+ >
132
+ ) => Channel.Channel<
133
+ Chunk.Chunk<OA>,
134
+ Chunk.Chunk<IA>,
135
+ ParseError | OutErr,
136
+ InErr,
137
+ OutDone,
138
+ InDone,
139
+ R | IR | OR
140
+ >
141
+ /**
142
+ * @since 1.0.0
143
+ * @category combinators
144
+ */
145
+ <R, InErr, OutErr, OutDone, InDone, IA, II, IR, OA, OI, OR>(
146
+ self: Channel.Channel<
147
+ Chunk.Chunk<OI>,
148
+ Chunk.Chunk<II>,
149
+ OutErr,
150
+ ParseError | InErr,
151
+ OutDone,
152
+ InDone,
153
+ R
154
+ >,
155
+ options: {
156
+ readonly inputSchema: Schema.Schema<IA, II, IR>
157
+ readonly outputSchema: Schema.Schema<OA, OI, OR>
158
+ }
159
+ ): Channel.Channel<
160
+ Chunk.Chunk<OA>,
161
+ Chunk.Chunk<IA>,
162
+ ParseError | OutErr,
163
+ InErr,
164
+ OutDone,
165
+ InDone,
166
+ R | IR | OR
167
+ >
168
+ } = dual(2, <R, InErr, OutErr, OutDone, InDone, IA, II, IR, OA, OI, OR>(
169
+ self: Channel.Channel<
170
+ Chunk.Chunk<OI>,
171
+ Chunk.Chunk<II>,
172
+ OutErr,
173
+ ParseError | InErr,
174
+ OutDone,
175
+ InDone,
176
+ R
177
+ >,
178
+ options: {
179
+ readonly inputSchema: Schema.Schema<IA, II, IR>
180
+ readonly outputSchema: Schema.Schema<OA, OI, OR>
181
+ }
182
+ ): Channel.Channel<
183
+ Chunk.Chunk<OA>,
184
+ Chunk.Chunk<IA>,
185
+ ParseError | OutErr,
186
+ InErr,
187
+ OutDone,
188
+ InDone,
189
+ R | IR | OR
190
+ > => {
191
+ const decode = Schema.decode(Schema.ChunkFromSelf(options.outputSchema))
192
+ return pipe(
193
+ encode(options.inputSchema)</**
194
+ * @since 1.0.0
195
+ * @category combinators
196
+ */
197
+ InErr, /**
198
+ * @since 1.0.0
199
+ * @category combinators
200
+ */
201
+ InDone>(),
202
+ Channel.pipeTo(self),
203
+ Channel.mapOutEffect(decode)
204
+ );
205
+ })
206
+
207
+ /**
208
+ * @since 1.0.0
209
+ * @category combinators
210
+ */
211
+ export const duplexUnknown: {
212
+ /**
213
+ * @since 1.0.0
214
+ * @category combinators
215
+ */
216
+ <IA, II, IR, OA, OI, OR>(
217
+ options: {
218
+ readonly inputSchema: Schema.Schema<IA, II, IR>
219
+ readonly outputSchema: Schema.Schema<OA, OI, OR>
220
+ }
221
+ ): <R, InErr, OutErr, OutDone, InDone>(
222
+ self: Channel.Channel<
223
+ Chunk.Chunk<unknown>,
224
+ Chunk.Chunk<any>,
225
+ OutErr,
226
+ ParseError | InErr,
227
+ OutDone,
228
+ InDone,
229
+ R
230
+ >
231
+ ) => Channel.Channel<
232
+ Chunk.Chunk<OA>,
233
+ Chunk.Chunk<IA>,
234
+ ParseError | OutErr,
235
+ InErr,
236
+ OutDone,
237
+ InDone,
238
+ R | IR | OR
239
+ >
240
+ /**
241
+ * @since 1.0.0
242
+ * @category combinators
243
+ */
244
+ <R, InErr, OutErr, OutDone, InDone, IA, II, IR, OA, OI, OR>(
245
+ self: Channel.Channel<
246
+ Chunk.Chunk<unknown>,
247
+ Chunk.Chunk<any>,
248
+ OutErr,
249
+ ParseError | InErr,
250
+ OutDone,
251
+ InDone,
252
+ R
253
+ >,
254
+ options: {
255
+ readonly inputSchema: Schema.Schema<IA, II, IR>
256
+ readonly outputSchema: Schema.Schema<OA, OI, OR>
257
+ }
258
+ ): Channel.Channel<
259
+ Chunk.Chunk<OA>,
260
+ Chunk.Chunk<IA>,
261
+ ParseError | OutErr,
262
+ InErr,
263
+ OutDone,
264
+ InDone,
265
+ R | IR | OR
266
+ >
267
+ } = duplex as any
package/src/Headers.ts CHANGED
@@ -67,9 +67,9 @@ export const schemaFromSelf: Schema.Schema<Headers> = Schema.declare(isHeaders,
67
67
  * @since 1.0.0
68
68
  * @category schemas
69
69
  */
70
- export const schema: Schema.Schema<Headers, Record.ReadonlyRecord<string, string | ReadonlyArray<string>>> = Schema
70
+ export const schema: Schema.Schema<Headers, Record.ReadonlyRecord<string, string>> = Schema
71
71
  .transform(
72
- Schema.Record({ key: Schema.String, value: Schema.Union(Schema.String, Schema.Array(Schema.String)) }),
72
+ Schema.Record({ key: Schema.String, value: Schema.String }),
73
73
  schemaFromSelf,
74
74
  { strict: true, decode: (record) => fromInput(record), encode: identity }
75
75
  )
@@ -131,7 +131,7 @@ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiEr
131
131
  readonly transformResponse?:
132
132
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
133
133
  | undefined
134
- readonly baseUrl?: string | undefined
134
+ readonly baseUrl?: URL | string | undefined
135
135
  }
136
136
  ): Effect.Effect<
137
137
  void,
@@ -141,7 +141,11 @@ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiEr
141
141
  Effect.gen(function*() {
142
142
  const context = yield* Effect.context<any>()
143
143
  const httpClient = (yield* HttpClient.HttpClient).pipe(
144
- options?.baseUrl === undefined ? identity : HttpClient.mapRequest(HttpClientRequest.prependUrl(options.baseUrl)),
144
+ options?.baseUrl === undefined
145
+ ? identity
146
+ : HttpClient.mapRequest(
147
+ HttpClientRequest.prependUrl(options.baseUrl.toString())
148
+ ),
145
149
  options?.transformClient === undefined ? identity : options.transformClient
146
150
  )
147
151
  HttpApi.reflect(api as any, {
@@ -244,7 +248,7 @@ export const make = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiE
244
248
  readonly transformResponse?:
245
249
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
246
250
  | undefined
247
- readonly baseUrl?: string | undefined
251
+ readonly baseUrl?: URL | string | undefined
248
252
  }
249
253
  ): Effect.Effect<
250
254
  Simplify<Client<Groups, ApiError>>,
@@ -282,7 +286,7 @@ export const group = <
282
286
  readonly transformResponse?:
283
287
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
284
288
  | undefined
285
- readonly baseUrl?: string | undefined
289
+ readonly baseUrl?: URL | string | undefined
286
290
  }
287
291
  ): Effect.Effect<
288
292
  Client.Group<Groups, GroupName, ApiError>,
@@ -324,7 +328,7 @@ export const endpoint = <
324
328
  readonly transformResponse?:
325
329
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
326
330
  | undefined
327
- readonly baseUrl?: string | undefined
331
+ readonly baseUrl?: URL | string | undefined
328
332
  }
329
333
  ): Effect.Effect<
330
334
  Client.Method<
@@ -924,9 +924,7 @@ export const patch: {
924
924
  * @category constructors
925
925
  */
926
926
  <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "PATCH">
927
- } = make(
928
- "PATCH"
929
- )
927
+ } = make("PATCH")
930
928
 
931
929
  /**
932
930
  * @since 1.0.0
@@ -943,6 +941,38 @@ export const del: {
943
941
  * @category constructors
944
942
  */
945
943
  <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "DELETE">
946
- } = make(
947
- "DELETE"
948
- )
944
+ } = make("DELETE")
945
+
946
+ /**
947
+ * @since 1.0.0
948
+ * @category constructors
949
+ */
950
+ export const head: {
951
+ /**
952
+ * @since 1.0.0
953
+ * @category constructors
954
+ */
955
+ <const Name extends string>(name: Name): HttpApiEndpoint.Constructor<Name, "HEAD">
956
+ /**
957
+ * @since 1.0.0
958
+ * @category constructors
959
+ */
960
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "HEAD">
961
+ } = make("HEAD")
962
+
963
+ /**
964
+ * @since 1.0.0
965
+ * @category constructors
966
+ */
967
+ export const options: {
968
+ /**
969
+ * @since 1.0.0
970
+ * @category constructors
971
+ */
972
+ <const Name extends string>(name: Name): HttpApiEndpoint.Constructor<Name, "OPTIONS">
973
+ /**
974
+ * @since 1.0.0
975
+ * @category constructors
976
+ */
977
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "OPTIONS">
978
+ } = make("OPTIONS")
package/src/HttpBody.ts CHANGED
@@ -153,7 +153,7 @@ export interface Uint8Array extends HttpBody.Proto {
153
153
  * @since 1.0.0
154
154
  * @category constructors
155
155
  */
156
- export const uint8Array: (body: globalThis.Uint8Array) => Uint8Array = internal.uint8Array
156
+ export const uint8Array: (body: globalThis.Uint8Array, contentType?: string) => Uint8Array = internal.uint8Array
157
157
 
158
158
  /**
159
159
  * @since 1.0.0
package/src/HttpRouter.ts CHANGED
@@ -18,7 +18,9 @@ import type * as Etag from "./Etag.js"
18
18
  import type { FileSystem } from "./FileSystem.js"
19
19
  import type * as App from "./HttpApp.js"
20
20
  import type * as Method from "./HttpMethod.js"
21
+ import type * as Middleware from "./HttpMiddleware.js"
21
22
  import type * as Platform from "./HttpPlatform.js"
23
+ import type * as HttpServer from "./HttpServer.js"
22
24
  import type * as Error from "./HttpServerError.js"
23
25
  import type * as ServerRequest from "./HttpServerRequest.js"
24
26
  import type * as Respondable from "./HttpServerRespondable.js"
@@ -144,6 +146,13 @@ export declare namespace HttpRouter {
144
146
  f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>
145
147
  ) => Layer.Layer<never, XE, Exclude<XR, Scope.Scope>>
146
148
  readonly unwrap: <XA, XE, XR>(f: (router: HttpRouter<E, R>) => Layer.Layer<XA, XE, XR>) => Layer.Layer<XA, XE, XR>
149
+ readonly serve: <E = never, R = never>(
150
+ middleware?: Middleware.HttpMiddleware.Applied<App.Default, E, R>
151
+ ) => Layer.Layer<
152
+ never,
153
+ never,
154
+ HttpServer.HttpServer | Exclude<R, ServerRequest.HttpServerRequest | Scope.Scope>
155
+ >
147
156
  }
148
157
  }
149
158