@effect/platform 0.72.1 → 0.73.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 (67) hide show
  1. package/README.md +2159 -356
  2. package/Url/package.json +6 -0
  3. package/dist/cjs/HttpApi.js +22 -18
  4. package/dist/cjs/HttpApi.js.map +1 -1
  5. package/dist/cjs/HttpApiEndpoint.js.map +1 -1
  6. package/dist/cjs/HttpApiGroup.js.map +1 -1
  7. package/dist/cjs/HttpApiSchema.js +33 -4
  8. package/dist/cjs/HttpApiSchema.js.map +1 -1
  9. package/dist/cjs/HttpApiSecurity.js +2 -0
  10. package/dist/cjs/HttpApiSecurity.js.map +1 -1
  11. package/dist/cjs/OpenApi.js +132 -142
  12. package/dist/cjs/OpenApi.js.map +1 -1
  13. package/dist/cjs/OpenApiJsonSchema.js +7 -4
  14. package/dist/cjs/OpenApiJsonSchema.js.map +1 -1
  15. package/dist/cjs/Runtime.js.map +1 -1
  16. package/dist/cjs/Url.js +259 -0
  17. package/dist/cjs/Url.js.map +1 -0
  18. package/dist/cjs/index.js +3 -1
  19. package/dist/dts/HttpApi.d.ts +4 -2
  20. package/dist/dts/HttpApi.d.ts.map +1 -1
  21. package/dist/dts/HttpApiBuilder.d.ts +1 -1
  22. package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
  23. package/dist/dts/HttpApiEndpoint.d.ts +16 -8
  24. package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
  25. package/dist/dts/HttpApiGroup.d.ts +1 -2
  26. package/dist/dts/HttpApiGroup.d.ts.map +1 -1
  27. package/dist/dts/HttpApiSchema.d.ts.map +1 -1
  28. package/dist/dts/HttpApiSecurity.d.ts +2 -0
  29. package/dist/dts/HttpApiSecurity.d.ts.map +1 -1
  30. package/dist/dts/OpenApi.d.ts +102 -111
  31. package/dist/dts/OpenApi.d.ts.map +1 -1
  32. package/dist/dts/OpenApiJsonSchema.d.ts.map +1 -1
  33. package/dist/dts/Runtime.d.ts +48 -0
  34. package/dist/dts/Runtime.d.ts.map +1 -1
  35. package/dist/dts/Url.d.ts +591 -0
  36. package/dist/dts/Url.d.ts.map +1 -0
  37. package/dist/dts/index.d.ts +4 -0
  38. package/dist/dts/index.d.ts.map +1 -1
  39. package/dist/esm/HttpApi.js +22 -18
  40. package/dist/esm/HttpApi.js.map +1 -1
  41. package/dist/esm/HttpApiEndpoint.js.map +1 -1
  42. package/dist/esm/HttpApiGroup.js.map +1 -1
  43. package/dist/esm/HttpApiSchema.js +30 -3
  44. package/dist/esm/HttpApiSchema.js.map +1 -1
  45. package/dist/esm/HttpApiSecurity.js +2 -0
  46. package/dist/esm/HttpApiSecurity.js.map +1 -1
  47. package/dist/esm/OpenApi.js +132 -141
  48. package/dist/esm/OpenApi.js.map +1 -1
  49. package/dist/esm/OpenApiJsonSchema.js +4 -2
  50. package/dist/esm/OpenApiJsonSchema.js.map +1 -1
  51. package/dist/esm/Runtime.js.map +1 -1
  52. package/dist/esm/Url.js +248 -0
  53. package/dist/esm/Url.js.map +1 -0
  54. package/dist/esm/index.js +4 -0
  55. package/dist/esm/index.js.map +1 -1
  56. package/package.json +10 -2
  57. package/src/HttpApi.ts +25 -26
  58. package/src/HttpApiBuilder.ts +1 -1
  59. package/src/HttpApiEndpoint.ts +22 -13
  60. package/src/HttpApiGroup.ts +2 -3
  61. package/src/HttpApiSchema.ts +33 -8
  62. package/src/HttpApiSecurity.ts +2 -0
  63. package/src/OpenApi.ts +244 -272
  64. package/src/OpenApiJsonSchema.ts +9 -1
  65. package/src/Runtime.ts +48 -0
  66. package/src/Url.ts +632 -0
  67. package/src/index.ts +5 -0
@@ -33,6 +33,15 @@ export type TypeId = typeof TypeId
33
33
  */
34
34
  export const isHttpApiEndpoint = (u: unknown): u is HttpApiEndpoint<any, any, any> => Predicate.hasProperty(u, TypeId)
35
35
 
36
+ /**
37
+ * Represents a path segment. A path segment is a string that represents a
38
+ * segment of a URL path.
39
+ *
40
+ * @since 1.0.0
41
+ * @category models
42
+ */
43
+ export type PathSegment = `/${string}`
44
+
36
45
  /**
37
46
  * Represents an API endpoint. An API endpoint is mapped to a single route on
38
47
  * the underlying `HttpRouter`.
@@ -54,7 +63,7 @@ export interface HttpApiEndpoint<
54
63
  > extends Pipeable {
55
64
  readonly [TypeId]: TypeId
56
65
  readonly name: Name
57
- readonly path: HttpRouter.PathInput
66
+ readonly path: PathSegment
58
67
  readonly method: Method
59
68
  readonly pathSchema: Option.Option<Schema.Schema<Path, unknown, R>>
60
69
  readonly urlParamsSchema: Option.Option<Schema.Schema<UrlParams, unknown, R>>
@@ -194,7 +203,7 @@ export interface HttpApiEndpoint<
194
203
  * Add a prefix to the path of the endpoint.
195
204
  */
196
205
  prefix(
197
- prefix: HttpRouter.PathInput
206
+ prefix: PathSegment
198
207
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>
199
208
 
200
209
  /**
@@ -743,10 +752,10 @@ const Proto = {
743
752
  headersSchema: Option.some(schema)
744
753
  })
745
754
  },
746
- prefix(this: HttpApiEndpoint.AnyWithProps, prefix: HttpRouter.PathInput) {
755
+ prefix(this: HttpApiEndpoint.AnyWithProps, prefix: PathSegment) {
747
756
  return makeProto({
748
757
  ...this,
749
- path: HttpRouter.prefixPath(this.path, prefix) as HttpRouter.PathInput
758
+ path: HttpRouter.prefixPath(this.path, prefix) as PathSegment
750
759
  })
751
760
  },
752
761
  middleware(this: HttpApiEndpoint.AnyWithProps, middleware: HttpApiMiddleware.TagClassAny) {
@@ -783,7 +792,7 @@ const makeProto = <
783
792
  RE
784
793
  >(options: {
785
794
  readonly name: Name
786
- readonly path: HttpRouter.PathInput
795
+ readonly path: PathSegment
787
796
  readonly method: Method
788
797
  readonly pathSchema: Option.Option<Schema.Schema<Path, unknown, R>>
789
798
  readonly urlParamsSchema: Option.Option<Schema.Schema<UrlParams, unknown, R>>
@@ -802,9 +811,9 @@ const makeProto = <
802
811
  */
803
812
  export const make = <Method extends HttpMethod>(method: Method): {
804
813
  <const Name extends string>(name: Name): HttpApiEndpoint.Constructor<Name, Method>
805
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, Method>
814
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, Method>
806
815
  } =>
807
- ((name: string, ...args: [HttpRouter.PathInput]) => {
816
+ ((name: string, ...args: [PathSegment]) => {
808
817
  if (args.length === 1) {
809
818
  return makeProto({
810
819
  name,
@@ -821,7 +830,7 @@ export const make = <Method extends HttpMethod>(method: Method): {
821
830
  })
822
831
  }
823
832
  return (segments: TemplateStringsArray, ...schemas: ReadonlyArray<HttpApiSchema.AnyString>) => {
824
- let path = segments[0] as HttpRouter.PathInput
833
+ let path = segments[0] as PathSegment
825
834
  let pathSchema = Option.none<Schema.Schema.Any>()
826
835
  if (schemas.length > 0) {
827
836
  const obj: Record<string, Schema.Schema.Any> = {}
@@ -863,7 +872,7 @@ export const get: {
863
872
  * @since 1.0.0
864
873
  * @category constructors
865
874
  */
866
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, "GET">
875
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "GET">
867
876
  } = make("GET")
868
877
 
869
878
  /**
@@ -880,7 +889,7 @@ export const post: {
880
889
  * @since 1.0.0
881
890
  * @category constructors
882
891
  */
883
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, "POST">
892
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "POST">
884
893
  } = make("POST")
885
894
 
886
895
  /**
@@ -897,7 +906,7 @@ export const put: {
897
906
  * @since 1.0.0
898
907
  * @category constructors
899
908
  */
900
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, "PUT">
909
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "PUT">
901
910
  } = make("PUT")
902
911
 
903
912
  /**
@@ -914,7 +923,7 @@ export const patch: {
914
923
  * @since 1.0.0
915
924
  * @category constructors
916
925
  */
917
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, "PATCH">
926
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "PATCH">
918
927
  } = make(
919
928
  "PATCH"
920
929
  )
@@ -933,7 +942,7 @@ export const del: {
933
942
  * @since 1.0.0
934
943
  * @category constructors
935
944
  */
936
- <const Name extends string>(name: Name, path: HttpRouter.PathInput): HttpApiEndpoint<Name, "DELETE">
945
+ <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "DELETE">
937
946
  } = make(
938
947
  "DELETE"
939
948
  )
@@ -10,7 +10,6 @@ import type * as HttpApiEndpoint from "./HttpApiEndpoint.js"
10
10
  import type { HttpApiDecodeError } from "./HttpApiError.js"
11
11
  import type * as HttpApiMiddleware from "./HttpApiMiddleware.js"
12
12
  import * as HttpApiSchema from "./HttpApiSchema.js"
13
- import type { PathInput } from "./HttpRouter.js"
14
13
 
15
14
  /**
16
15
  * @since 1.0.0
@@ -77,7 +76,7 @@ export interface HttpApiGroup<
77
76
  * Add a path prefix to all endpoints in an `HttpApiGroup`. Note that this will only
78
77
  * add the prefix to the endpoints before this api is called.
79
78
  */
80
- prefix(prefix: PathInput): HttpApiGroup<Id, Endpoints, Error, R, TopLevel>
79
+ prefix(prefix: HttpApiEndpoint.PathSegment): HttpApiGroup<Id, Endpoints, Error, R, TopLevel>
81
80
 
82
81
  /**
83
82
  * Add an `HttpApiMiddleware` to the `HttpApiGroup`.
@@ -315,7 +314,7 @@ const Proto = {
315
314
  middlewares: this.middlewares
316
315
  })
317
316
  },
318
- prefix(this: HttpApiGroup.AnyWithProps, prefix: PathInput) {
317
+ prefix(this: HttpApiGroup.AnyWithProps, prefix: HttpApiEndpoint.PathSegment) {
319
318
  return makeProto({
320
319
  identifier: this.identifier,
321
320
  topLevel: this.topLevel,
@@ -180,6 +180,38 @@ export const getStatusErrorAST = (ast: AST.AST): number => getStatus(ast, 500)
180
180
  */
181
181
  export const getStatusError = <A extends Schema.Schema.All>(self: A): number => getStatusErrorAST(self.ast)
182
182
 
183
+ /**
184
+ * Extracts all individual types from a union type recursively.
185
+ *
186
+ * **Details**
187
+ *
188
+ * This function traverses an AST and collects all the types within a union,
189
+ * even if they are nested. It ensures that every type in a union (including
190
+ * deeply nested unions) is included in the resulting array. The returned array
191
+ * contains each type as an individual AST node, preserving the order in which
192
+ * they appear.
193
+ *
194
+ * @internal
195
+ */
196
+ export const extractUnionTypes = (ast: AST.AST): ReadonlyArray<AST.AST> => {
197
+ function process(ast: AST.AST): void {
198
+ if (AST.isUnion(ast)) {
199
+ for (const type of ast.types) {
200
+ process(type)
201
+ }
202
+ } else {
203
+ out.push(ast)
204
+ }
205
+ }
206
+ const out: Array<AST.AST> = []
207
+ process(ast)
208
+ return out
209
+ }
210
+
211
+ /** @internal */
212
+ export const UnionUnifyAST = (self: AST.AST, that: AST.AST): AST.AST =>
213
+ AST.Union.make(Array.from(new Set<AST.AST>([...extractUnionTypes(self), ...extractUnionTypes(that)])))
214
+
183
215
  /**
184
216
  * @since 1.0.0
185
217
  */
@@ -187,14 +219,7 @@ export const UnionUnify = <A extends Schema.Schema.All, B extends Schema.Schema.
187
219
  A["Type"] | B["Type"],
188
220
  A["Encoded"] | B["Encoded"],
189
221
  A["Context"] | B["Context"]
190
- > => {
191
- return Schema.make(AST.Union.make(Array.from(
192
- new Set<AST.AST>([
193
- ...(self.ast._tag === "Union" ? self.ast.types : [self.ast]),
194
- ...(that.ast._tag === "Union" ? that.ast.types : [that.ast])
195
- ])
196
- )))
197
- }
222
+ > => Schema.make(UnionUnifyAST(self.ast, that.ast))
198
223
 
199
224
  type Void$ = typeof Schema.Void
200
225
 
@@ -113,6 +113,8 @@ export const bearer: Bearer = Object.assign(Object.create(Proto), {
113
113
  * To set the correct cookie in a handler, you can use
114
114
  * `HttpApiBuilder.securitySetCookie`.
115
115
  *
116
+ * The default value for `in` is "header".
117
+ *
116
118
  * @since 1.0.0
117
119
  * @category constructors
118
120
  */