@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.
- package/README.md +2159 -356
- package/Url/package.json +6 -0
- package/dist/cjs/HttpApi.js +22 -18
- package/dist/cjs/HttpApi.js.map +1 -1
- package/dist/cjs/HttpApiEndpoint.js.map +1 -1
- package/dist/cjs/HttpApiGroup.js.map +1 -1
- package/dist/cjs/HttpApiSchema.js +33 -4
- package/dist/cjs/HttpApiSchema.js.map +1 -1
- package/dist/cjs/HttpApiSecurity.js +2 -0
- package/dist/cjs/HttpApiSecurity.js.map +1 -1
- package/dist/cjs/OpenApi.js +132 -142
- package/dist/cjs/OpenApi.js.map +1 -1
- package/dist/cjs/OpenApiJsonSchema.js +7 -4
- package/dist/cjs/OpenApiJsonSchema.js.map +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/Url.js +259 -0
- package/dist/cjs/Url.js.map +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/dts/HttpApi.d.ts +4 -2
- package/dist/dts/HttpApi.d.ts.map +1 -1
- package/dist/dts/HttpApiBuilder.d.ts +1 -1
- package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
- package/dist/dts/HttpApiEndpoint.d.ts +16 -8
- package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/dts/HttpApiGroup.d.ts +1 -2
- package/dist/dts/HttpApiGroup.d.ts.map +1 -1
- package/dist/dts/HttpApiSchema.d.ts.map +1 -1
- package/dist/dts/HttpApiSecurity.d.ts +2 -0
- package/dist/dts/HttpApiSecurity.d.ts.map +1 -1
- package/dist/dts/OpenApi.d.ts +102 -111
- package/dist/dts/OpenApi.d.ts.map +1 -1
- package/dist/dts/OpenApiJsonSchema.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +48 -0
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/Url.d.ts +591 -0
- package/dist/dts/Url.d.ts.map +1 -0
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/HttpApi.js +22 -18
- package/dist/esm/HttpApi.js.map +1 -1
- package/dist/esm/HttpApiEndpoint.js.map +1 -1
- package/dist/esm/HttpApiGroup.js.map +1 -1
- package/dist/esm/HttpApiSchema.js +30 -3
- package/dist/esm/HttpApiSchema.js.map +1 -1
- package/dist/esm/HttpApiSecurity.js +2 -0
- package/dist/esm/HttpApiSecurity.js.map +1 -1
- package/dist/esm/OpenApi.js +132 -141
- package/dist/esm/OpenApi.js.map +1 -1
- package/dist/esm/OpenApiJsonSchema.js +4 -2
- package/dist/esm/OpenApiJsonSchema.js.map +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/Url.js +248 -0
- package/dist/esm/Url.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +10 -2
- package/src/HttpApi.ts +25 -26
- package/src/HttpApiBuilder.ts +1 -1
- package/src/HttpApiEndpoint.ts +22 -13
- package/src/HttpApiGroup.ts +2 -3
- package/src/HttpApiSchema.ts +33 -8
- package/src/HttpApiSecurity.ts +2 -0
- package/src/OpenApi.ts +244 -272
- package/src/OpenApiJsonSchema.ts +9 -1
- package/src/Runtime.ts +48 -0
- package/src/Url.ts +632 -0
- package/src/index.ts +5 -0
package/src/HttpApiEndpoint.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
755
|
+
prefix(this: HttpApiEndpoint.AnyWithProps, prefix: PathSegment) {
|
|
747
756
|
return makeProto({
|
|
748
757
|
...this,
|
|
749
|
-
path: HttpRouter.prefixPath(this.path, prefix) as
|
|
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:
|
|
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:
|
|
814
|
+
<const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, Method>
|
|
806
815
|
} =>
|
|
807
|
-
((name: string, ...args: [
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
945
|
+
<const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, "DELETE">
|
|
937
946
|
} = make(
|
|
938
947
|
"DELETE"
|
|
939
948
|
)
|
package/src/HttpApiGroup.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
317
|
+
prefix(this: HttpApiGroup.AnyWithProps, prefix: HttpApiEndpoint.PathSegment) {
|
|
319
318
|
return makeProto({
|
|
320
319
|
identifier: this.identifier,
|
|
321
320
|
topLevel: this.topLevel,
|
package/src/HttpApiSchema.ts
CHANGED
|
@@ -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
|
|
package/src/HttpApiSecurity.ts
CHANGED
|
@@ -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
|
*/
|