@effect/platform 0.85.2 → 0.87.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 (49) hide show
  1. package/dist/cjs/HttpApiBuilder.js +15 -5
  2. package/dist/cjs/HttpApiBuilder.js.map +1 -1
  3. package/dist/cjs/HttpApiClient.js +17 -8
  4. package/dist/cjs/HttpApiClient.js.map +1 -1
  5. package/dist/cjs/HttpApiSchema.js +6 -6
  6. package/dist/cjs/HttpApiSchema.js.map +1 -1
  7. package/dist/cjs/HttpIncomingMessage.js +7 -5
  8. package/dist/cjs/HttpIncomingMessage.js.map +1 -1
  9. package/dist/cjs/HttpServerRequest.js +10 -4
  10. package/dist/cjs/HttpServerRequest.js.map +1 -1
  11. package/dist/cjs/Multipart.js +400 -47
  12. package/dist/cjs/Multipart.js.map +1 -1
  13. package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
  14. package/dist/dts/HttpApiClient.d.ts +28 -15
  15. package/dist/dts/HttpApiClient.d.ts.map +1 -1
  16. package/dist/dts/HttpApiSchema.d.ts +19 -4
  17. package/dist/dts/HttpApiSchema.d.ts.map +1 -1
  18. package/dist/dts/HttpIncomingMessage.d.ts +5 -2
  19. package/dist/dts/HttpIncomingMessage.d.ts.map +1 -1
  20. package/dist/dts/HttpServerRequest.d.ts +6 -1
  21. package/dist/dts/HttpServerRequest.d.ts.map +1 -1
  22. package/dist/dts/Multipart.d.ts +167 -88
  23. package/dist/dts/Multipart.d.ts.map +1 -1
  24. package/dist/esm/HttpApiBuilder.js +15 -5
  25. package/dist/esm/HttpApiBuilder.js.map +1 -1
  26. package/dist/esm/HttpApiClient.js +14 -6
  27. package/dist/esm/HttpApiClient.js.map +1 -1
  28. package/dist/esm/HttpApiSchema.js +6 -6
  29. package/dist/esm/HttpApiSchema.js.map +1 -1
  30. package/dist/esm/HttpIncomingMessage.js +5 -4
  31. package/dist/esm/HttpIncomingMessage.js.map +1 -1
  32. package/dist/esm/HttpServerRequest.js +6 -1
  33. package/dist/esm/HttpServerRequest.js.map +1 -1
  34. package/dist/esm/Multipart.js +385 -46
  35. package/dist/esm/Multipart.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/HttpApiBuilder.ts +16 -5
  38. package/src/HttpApiClient.ts +63 -32
  39. package/src/HttpApiSchema.ts +23 -7
  40. package/src/HttpIncomingMessage.ts +5 -7
  41. package/src/HttpServerRequest.ts +6 -1
  42. package/src/Multipart.ts +632 -128
  43. package/dist/cjs/internal/multipart.js +0 -364
  44. package/dist/cjs/internal/multipart.js.map +0 -1
  45. package/dist/dts/internal/multipart.d.ts +0 -2
  46. package/dist/dts/internal/multipart.d.ts.map +0 -1
  47. package/dist/esm/internal/multipart.js +0 -347
  48. package/dist/esm/internal/multipart.js.map +0 -1
  49. package/src/internal/multipart.ts +0 -491
@@ -28,16 +28,17 @@ import * as UrlParams from "./UrlParams.js"
28
28
  * @since 1.0.0
29
29
  * @category models
30
30
  */
31
- export type Client<Groups extends HttpApiGroup.Any, ApiError> = Simplify<
31
+ export type Client<Groups extends HttpApiGroup.Any, E, R> = Simplify<
32
32
  & {
33
33
  readonly [Group in Extract<Groups, { readonly topLevel: false }> as HttpApiGroup.Name<Group>]: Client.Group<
34
34
  Group,
35
35
  Group["identifier"],
36
- ApiError
36
+ E,
37
+ R
37
38
  >
38
39
  }
39
40
  & {
40
- readonly [Method in Client.TopLevelMethods<Groups, ApiError> as Method[0]]: Method[1]
41
+ readonly [Method in Client.TopLevelMethods<Groups, E, R> as Method[0]]: Method[1]
41
42
  }
42
43
  >
43
44
 
@@ -50,13 +51,14 @@ export declare namespace Client {
50
51
  * @since 1.0.0
51
52
  * @category models
52
53
  */
53
- export type Group<Groups extends HttpApiGroup.Any, GroupName extends Groups["identifier"], ApiError> =
54
+ export type Group<Groups extends HttpApiGroup.Any, GroupName extends Groups["identifier"], E, R> =
54
55
  [HttpApiGroup.WithName<Groups, GroupName>] extends
55
56
  [HttpApiGroup<infer _GroupName, infer _Endpoints, infer _GroupError, infer _GroupErrorR>] ? {
56
57
  readonly [Endpoint in _Endpoints as HttpApiEndpoint.Name<Endpoint>]: Method<
57
58
  Endpoint,
58
- ApiError,
59
- _GroupError
59
+ E,
60
+ _GroupError,
61
+ R
60
62
  >
61
63
  } :
62
64
  never
@@ -65,7 +67,7 @@ export declare namespace Client {
65
67
  * @since 1.0.0
66
68
  * @category models
67
69
  */
68
- export type Method<Endpoint, ApiError, GroupError> = [Endpoint] extends [
70
+ export type Method<Endpoint, E, GroupError, R> = [Endpoint] extends [
69
71
  HttpApiEndpoint<
70
72
  infer _Name,
71
73
  infer _Method,
@@ -82,7 +84,8 @@ export declare namespace Client {
82
84
  request: Simplify<HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, WithResponse>>
83
85
  ) => Effect.Effect<
84
86
  WithResponse extends true ? [_Success, HttpClientResponse.HttpClientResponse] : _Success,
85
- _Error | GroupError | ApiError | HttpClientError.HttpClientError | ParseResult.ParseError
87
+ _Error | GroupError | E | HttpClientError.HttpClientError | ParseResult.ParseError,
88
+ R
86
89
  > :
87
90
  never
88
91
 
@@ -90,10 +93,10 @@ export declare namespace Client {
90
93
  * @since 1.0.0
91
94
  * @category models
92
95
  */
93
- export type TopLevelMethods<Groups extends HttpApiGroup.Any, ApiError> =
96
+ export type TopLevelMethods<Groups extends HttpApiGroup.Any, E, R> =
94
97
  Extract<Groups, { readonly topLevel: true }> extends
95
98
  HttpApiGroup<infer _Id, infer _Endpoints, infer _Error, infer _ErrorR, infer _TopLevel> ?
96
- _Endpoints extends infer Endpoint ? [HttpApiEndpoint.Name<Endpoint>, Method<Endpoint, ApiError, _Error>]
99
+ _Endpoints extends infer Endpoint ? [HttpApiEndpoint.Name<Endpoint>, Method<Endpoint, E, _Error, R>]
97
100
  : never :
98
101
  never
99
102
  }
@@ -101,9 +104,10 @@ export declare namespace Client {
101
104
  /**
102
105
  * @internal
103
106
  */
104
- const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiError, ApiR>(
107
+ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiError, ApiR, E, R>(
105
108
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
106
109
  options: {
110
+ readonly httpClient: HttpClient.HttpClient.With<E, R>
107
111
  readonly predicate?: Predicate.Predicate<{
108
112
  readonly endpoint: HttpApiEndpoint.AnyWithProps
109
113
  readonly group: HttpApiGroup.AnyWithProps
@@ -127,7 +131,6 @@ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiEr
127
131
  }>
128
132
  readonly endpointFn: Function
129
133
  }) => void
130
- readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
131
134
  readonly transformResponse?:
132
135
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
133
136
  | undefined
@@ -136,17 +139,16 @@ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiEr
136
139
  ): Effect.Effect<
137
140
  void,
138
141
  never,
139
- HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>> | HttpClient.HttpClient
142
+ HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>>
140
143
  > =>
141
144
  Effect.gen(function*() {
142
145
  const context = yield* Effect.context<any>()
143
- const httpClient = (yield* HttpClient.HttpClient).pipe(
146
+ const httpClient = options.httpClient.pipe(
144
147
  options?.baseUrl === undefined
145
148
  ? identity
146
149
  : HttpClient.mapRequest(
147
150
  HttpClientRequest.prependUrl(options.baseUrl.toString())
148
- ),
149
- options?.transformClient === undefined ? identity : options.transformClient
151
+ )
150
152
  )
151
153
  HttpApi.reflect(api as any, {
152
154
  predicate: options?.predicate,
@@ -255,9 +257,33 @@ export const make = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiE
255
257
  readonly baseUrl?: URL | string | undefined
256
258
  }
257
259
  ): Effect.Effect<
258
- Simplify<Client<Groups, ApiError>>,
260
+ Simplify<Client<Groups, ApiError, never>>,
259
261
  never,
260
262
  HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>> | HttpClient.HttpClient
263
+ > =>
264
+ Effect.flatMap(HttpClient.HttpClient, (httpClient) =>
265
+ makeWith(api, {
266
+ ...options,
267
+ httpClient: options?.transformClient ? options.transformClient(httpClient) : httpClient
268
+ }))
269
+
270
+ /**
271
+ * @since 1.0.0
272
+ * @category constructors
273
+ */
274
+ export const makeWith = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiError, ApiR, E, R>(
275
+ api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
276
+ options: {
277
+ readonly httpClient: HttpClient.HttpClient.With<E, R>
278
+ readonly transformResponse?:
279
+ | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
280
+ | undefined
281
+ readonly baseUrl?: URL | string | undefined
282
+ }
283
+ ): Effect.Effect<
284
+ Simplify<Client<Groups, ApiError | E, R>>,
285
+ never,
286
+ HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>>
261
287
  > => {
262
288
  const client: Record<string, Record<string, any>> = {}
263
289
  return makeClient(api, {
@@ -281,31 +307,33 @@ export const group = <
281
307
  Groups extends HttpApiGroup.Any,
282
308
  ApiError,
283
309
  ApiR,
284
- const GroupName extends Groups["identifier"]
310
+ const GroupName extends HttpApiGroup.Name<Groups>,
311
+ E,
312
+ R
285
313
  >(
286
314
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
287
- groupId: GroupName,
288
- options?: {
289
- readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
315
+ options: {
316
+ readonly group: GroupName
317
+ readonly httpClient: HttpClient.HttpClient.With<E, R>
290
318
  readonly transformResponse?:
291
319
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
292
320
  | undefined
293
321
  readonly baseUrl?: URL | string | undefined
294
322
  }
295
323
  ): Effect.Effect<
296
- Client.Group<Groups, GroupName, ApiError>,
324
+ Client.Group<Groups, GroupName, ApiError | E, R>,
297
325
  never,
298
326
  HttpApiMiddleware.HttpApiMiddleware.Without<
299
327
  | ApiR
300
328
  | HttpApiGroup.ClientContext<
301
329
  HttpApiGroup.WithName<Groups, GroupName>
302
330
  >
303
- > | HttpClient.HttpClient
331
+ >
304
332
  > => {
305
333
  const client: Record<string, any> = {}
306
334
  return makeClient(api, {
307
335
  ...options,
308
- predicate: ({ group }) => group.identifier === groupId,
336
+ predicate: ({ group }) => group.identifier === options.group,
309
337
  onEndpoint({ endpoint, endpointFn }) {
310
338
  client[endpoint.name] = endpointFn
311
339
  }
@@ -322,12 +350,15 @@ export const endpoint = <
322
350
  ApiError,
323
351
  ApiR,
324
352
  const GroupName extends HttpApiGroup.Name<Groups>,
325
- const EndpointName extends HttpApiEndpoint.Name<HttpApiGroup.EndpointsWithName<Groups, GroupName>>
353
+ const EndpointName extends HttpApiEndpoint.Name<HttpApiGroup.EndpointsWithName<Groups, GroupName>>,
354
+ E,
355
+ R
326
356
  >(
327
357
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
328
- groupName: GroupName,
329
- endpointName: EndpointName,
330
- options?: {
358
+ options: {
359
+ readonly group: GroupName
360
+ readonly endpoint: EndpointName
361
+ readonly httpClient: HttpClient.HttpClient.With<E, R>
331
362
  readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
332
363
  readonly transformResponse?:
333
364
  | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
@@ -338,21 +369,21 @@ export const endpoint = <
338
369
  Client.Method<
339
370
  HttpApiEndpoint.WithName<HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>, EndpointName>,
340
371
  HttpApiGroup.Error<HttpApiGroup.WithName<Groups, GroupName>>,
341
- ApiError
372
+ ApiError | E,
373
+ R
342
374
  >,
343
375
  never,
344
- | HttpApiMiddleware.HttpApiMiddleware.Without<
376
+ HttpApiMiddleware.HttpApiMiddleware.Without<
345
377
  | ApiR
346
378
  | HttpApiGroup.Context<HttpApiGroup.WithName<Groups, GroupName>>
347
379
  | HttpApiEndpoint.ContextWithName<HttpApiGroup.EndpointsWithName<Groups, GroupName>, EndpointName>
348
380
  | HttpApiEndpoint.ErrorContextWithName<HttpApiGroup.EndpointsWithName<Groups, GroupName>, EndpointName>
349
381
  >
350
- | HttpClient.HttpClient
351
382
  > => {
352
383
  let client: any = undefined
353
384
  return makeClient(api, {
354
385
  ...options,
355
- predicate: ({ endpoint, group }) => group.identifier === groupName && endpoint.name === endpointName,
386
+ predicate: ({ endpoint, group }) => group.identifier === options.group && endpoint.name === options.endpoint,
356
387
  onEndpoint({ endpointFn }) {
357
388
  client = endpointFn
358
389
  }
@@ -7,10 +7,13 @@ import * as Effectable from "effect/Effectable"
7
7
  import type { LazyArg } from "effect/Function"
8
8
  import { constant, constVoid, dual } from "effect/Function"
9
9
  import { globalValue } from "effect/GlobalValue"
10
+ import type * as Option from "effect/Option"
10
11
  import { hasProperty } from "effect/Predicate"
11
12
  import * as Schema from "effect/Schema"
12
13
  import * as AST from "effect/SchemaAST"
13
14
  import * as Struct from "effect/Struct"
15
+ import type * as FileSystem from "./FileSystem.js"
16
+ import type * as Multipart_ from "./Multipart.js"
14
17
 
15
18
  /**
16
19
  * @since 1.0.0
@@ -111,14 +114,15 @@ export const getEmptyDecodeable = (ast: AST.AST): boolean =>
111
114
  * @since 1.0.0
112
115
  * @category annotations
113
116
  */
114
- export const getMultipart = (ast: AST.AST): boolean => getAnnotation<boolean>(ast, AnnotationMultipart) ?? false
117
+ export const getMultipart = (ast: AST.AST): Multipart_.withLimits.Options | undefined =>
118
+ getAnnotation<Multipart_.withLimits.Options>(ast, AnnotationMultipart)
115
119
 
116
120
  /**
117
121
  * @since 1.0.0
118
122
  * @category annotations
119
123
  */
120
- export const getMultipartStream = (ast: AST.AST): boolean =>
121
- getAnnotation<boolean>(ast, AnnotationMultipartStream) ?? false
124
+ export const getMultipartStream = (ast: AST.AST): Multipart_.withLimits.Options | undefined =>
125
+ getAnnotation<Multipart_.withLimits.Options>(ast, AnnotationMultipartStream)
122
126
 
123
127
  const encodingJson: Encoding = {
124
128
  kind: "Json",
@@ -422,9 +426,15 @@ export interface Multipart<S extends Schema.Schema.Any>
422
426
  * @since 1.0.0
423
427
  * @category multipart
424
428
  */
425
- export const Multipart = <S extends Schema.Schema.Any>(self: S): Multipart<S> =>
429
+ export const Multipart = <S extends Schema.Schema.Any>(self: S, options?: {
430
+ readonly maxParts?: Option.Option<number> | undefined
431
+ readonly maxFieldSize?: FileSystem.SizeInput | undefined
432
+ readonly maxFileSize?: Option.Option<FileSystem.SizeInput> | undefined
433
+ readonly maxTotalSize?: Option.Option<FileSystem.SizeInput> | undefined
434
+ readonly fieldMimeTypes?: ReadonlyArray<string> | undefined
435
+ }): Multipart<S> =>
426
436
  self.annotations({
427
- [AnnotationMultipart]: true
437
+ [AnnotationMultipart]: options ?? {}
428
438
  }) as any
429
439
 
430
440
  /**
@@ -455,9 +465,15 @@ export interface MultipartStream<S extends Schema.Schema.Any> extends
455
465
  * @since 1.0.0
456
466
  * @category multipart
457
467
  */
458
- export const MultipartStream = <S extends Schema.Schema.Any>(self: S): MultipartStream<S> =>
468
+ export const MultipartStream = <S extends Schema.Schema.Any>(self: S, options?: {
469
+ readonly maxParts?: Option.Option<number> | undefined
470
+ readonly maxFieldSize?: FileSystem.SizeInput | undefined
471
+ readonly maxFileSize?: Option.Option<FileSystem.SizeInput> | undefined
472
+ readonly maxTotalSize?: Option.Option<FileSystem.SizeInput> | undefined
473
+ readonly fieldMimeTypes?: ReadonlyArray<string> | undefined
474
+ }): MultipartStream<S> =>
459
475
  self.annotations({
460
- [AnnotationMultipartStream]: true
476
+ [AnnotationMultipartStream]: options ?? {}
461
477
  }) as any
462
478
 
463
479
  const defaultContentType = (encoding: Encoding["kind"]) => {
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import * as Context from "effect/Context"
4
5
  import * as Effect from "effect/Effect"
5
- import * as FiberRef from "effect/FiberRef"
6
6
  import { dual } from "effect/Function"
7
- import * as Global from "effect/GlobalValue"
8
7
  import * as Inspectable from "effect/Inspectable"
9
8
  import * as Option from "effect/Option"
10
9
  import type * as ParseResult from "effect/ParseResult"
@@ -85,10 +84,9 @@ export const schemaHeaders = <A, I extends Readonly<Record<string, string | unde
85
84
  * @since 1.0.0
86
85
  * @category fiber refs
87
86
  */
88
- export const maxBodySize: FiberRef.FiberRef<Option.Option<FileSystem.Size>> = Global.globalValue(
89
- "@effect/platform/HttpIncomingMessage/maxBodySize",
90
- () => FiberRef.unsafeMake(Option.none<FileSystem.Size>())
91
- )
87
+ export class MaxBodySize extends Context.Reference<MaxBodySize>()("@effect/platform/HttpIncomingMessage/MaxBodySize", {
88
+ defaultValue: Option.none<FileSystem.Size>
89
+ }) {}
92
90
 
93
91
  /**
94
92
  * @since 1.0.0
@@ -105,7 +103,7 @@ export const withMaxBodySize = dual<
105
103
  * @category fiber refs
106
104
  */
107
105
  <A, E, R>(effect: Effect.Effect<A, E, R>, size: Option.Option<FileSystem.SizeInput>) => Effect.Effect<A, E, R>
108
- >(2, (effect, size) => Effect.locally(effect, maxBodySize, Option.map(size, FileSystem.Size)))
106
+ >(2, (effect, size) => Effect.provideService(effect, MaxBodySize, Option.map(size, FileSystem.Size)))
109
107
 
110
108
  /**
111
109
  * @since 1.0.0
@@ -27,7 +27,12 @@ export {
27
27
  * @since 1.0.0
28
28
  * @category fiber refs
29
29
  */
30
- maxBodySize
30
+ MaxBodySize,
31
+ /**
32
+ * @since 1.0.0
33
+ * @category fiber refs
34
+ */
35
+ withMaxBodySize
31
36
  } from "./HttpIncomingMessage.js"
32
37
 
33
38
  /**