@effect/platform 0.85.2 → 0.86.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 (42) hide show
  1. package/dist/cjs/HttpApiBuilder.js +15 -5
  2. package/dist/cjs/HttpApiBuilder.js.map +1 -1
  3. package/dist/cjs/HttpApiSchema.js +6 -6
  4. package/dist/cjs/HttpApiSchema.js.map +1 -1
  5. package/dist/cjs/HttpIncomingMessage.js +7 -5
  6. package/dist/cjs/HttpIncomingMessage.js.map +1 -1
  7. package/dist/cjs/HttpServerRequest.js +10 -4
  8. package/dist/cjs/HttpServerRequest.js.map +1 -1
  9. package/dist/cjs/Multipart.js +400 -47
  10. package/dist/cjs/Multipart.js.map +1 -1
  11. package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
  12. package/dist/dts/HttpApiSchema.d.ts +19 -4
  13. package/dist/dts/HttpApiSchema.d.ts.map +1 -1
  14. package/dist/dts/HttpIncomingMessage.d.ts +5 -2
  15. package/dist/dts/HttpIncomingMessage.d.ts.map +1 -1
  16. package/dist/dts/HttpServerRequest.d.ts +6 -1
  17. package/dist/dts/HttpServerRequest.d.ts.map +1 -1
  18. package/dist/dts/Multipart.d.ts +167 -88
  19. package/dist/dts/Multipart.d.ts.map +1 -1
  20. package/dist/esm/HttpApiBuilder.js +15 -5
  21. package/dist/esm/HttpApiBuilder.js.map +1 -1
  22. package/dist/esm/HttpApiSchema.js +6 -6
  23. package/dist/esm/HttpApiSchema.js.map +1 -1
  24. package/dist/esm/HttpIncomingMessage.js +5 -4
  25. package/dist/esm/HttpIncomingMessage.js.map +1 -1
  26. package/dist/esm/HttpServerRequest.js +6 -1
  27. package/dist/esm/HttpServerRequest.js.map +1 -1
  28. package/dist/esm/Multipart.js +385 -46
  29. package/dist/esm/Multipart.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/HttpApiBuilder.ts +16 -5
  32. package/src/HttpApiSchema.ts +23 -7
  33. package/src/HttpIncomingMessage.ts +5 -7
  34. package/src/HttpServerRequest.ts +6 -1
  35. package/src/Multipart.ts +632 -128
  36. package/dist/cjs/internal/multipart.js +0 -364
  37. package/dist/cjs/internal/multipart.js.map +0 -1
  38. package/dist/dts/internal/multipart.d.ts +0 -2
  39. package/dist/dts/internal/multipart.d.ts.map +0 -1
  40. package/dist/esm/internal/multipart.js +0 -347
  41. package/dist/esm/internal/multipart.js.map +0 -1
  42. package/src/internal/multipart.ts +0 -491
@@ -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
  /**