effect 4.0.0-beta.92 → 4.0.0-beta.94
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/dist/Cause.d.ts +3 -1
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Cause.js.map +1 -1
- package/dist/Config.d.ts +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js.map +1 -1
- package/dist/Effect.d.ts +130 -0
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +43 -0
- package/dist/Effect.js.map +1 -1
- package/dist/FileSystem.d.ts +7 -0
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +3 -0
- package/dist/FileSystem.js.map +1 -1
- package/dist/Layer.d.ts +1 -1
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +6 -3
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.js +1 -1
- package/dist/LayerMap.js.map +1 -1
- package/dist/LayerRef.d.ts +252 -0
- package/dist/LayerRef.d.ts.map +1 -0
- package/dist/LayerRef.js +171 -0
- package/dist/LayerRef.js.map +1 -0
- package/dist/Schema.d.ts +74 -30
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -0
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaParser.d.ts +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js.map +1 -1
- package/dist/internal/core.js +1 -1
- package/dist/internal/effect.js +10 -6
- package/dist/internal/effect.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +2 -2
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +2 -2
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +2 -2
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/Flag.d.ts +2 -2
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +2 -2
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -0
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +5 -3
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +3 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +3 -2
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceMap.js +39 -14
- package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +2 -2
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpBody.js +1 -1
- package/dist/unstable/http/HttpBody.js.map +1 -1
- package/dist/unstable/http/HttpClient.js +2 -2
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +5 -4
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +5 -4
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.d.ts +1 -1
- package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +2 -2
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +4 -4
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +8 -8
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts +2 -2
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/Url.d.ts +29 -4
- package/dist/unstable/http/Url.d.ts.map +1 -1
- package/dist/unstable/http/Url.js +44 -2
- package/dist/unstable/http/Url.js.map +1 -1
- package/dist/unstable/http/UrlParams.d.ts +2 -28
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +4 -46
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +2 -4
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +30 -15
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +7 -7
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +4 -3
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +4 -4
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/package.json +1 -1
- package/src/Cause.ts +3 -1
- package/src/Config.ts +1 -1
- package/src/Effect.ts +131 -0
- package/src/FileSystem.ts +13 -0
- package/src/Layer.ts +6 -6
- package/src/LayerMap.ts +1 -1
- package/src/LayerRef.ts +379 -0
- package/src/Schema.ts +83 -33
- package/src/SchemaParser.ts +2 -2
- package/src/internal/core.ts +1 -1
- package/src/internal/effect.ts +33 -6
- package/src/testing/TestSchema.ts +2 -2
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +3 -3
- package/src/unstable/cli/Argument.ts +14 -7
- package/src/unstable/cli/Flag.ts +6 -3
- package/src/unstable/cli/Param.ts +6 -3
- package/src/unstable/cli/Primitive.ts +2 -2
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -0
- package/src/unstable/cluster/Entity.ts +13 -14
- package/src/unstable/cluster/Sharding.ts +134 -131
- package/src/unstable/cluster/internal/entityManager.ts +11 -9
- package/src/unstable/cluster/internal/resourceMap.ts +59 -25
- package/src/unstable/encoding/Sse.ts +3 -3
- package/src/unstable/http/HttpBody.ts +2 -2
- package/src/unstable/http/HttpClient.ts +2 -2
- package/src/unstable/http/HttpClientRequest.ts +8 -7
- package/src/unstable/http/HttpClientResponse.ts +2 -3
- package/src/unstable/http/HttpIncomingMessage.ts +4 -5
- package/src/unstable/http/HttpRouter.ts +8 -10
- package/src/unstable/http/HttpServerRequest.ts +20 -19
- package/src/unstable/http/HttpServerResponse.ts +2 -2
- package/src/unstable/http/Multipart.ts +3 -3
- package/src/unstable/http/Url.ts +62 -7
- package/src/unstable/http/UrlParams.ts +5 -58
- package/src/unstable/httpapi/HttpApi.ts +2 -4
- package/src/unstable/httpapi/HttpApiBuilder.ts +33 -21
- package/src/unstable/httpapi/HttpApiClient.ts +2 -2
- package/src/unstable/httpapi/HttpApiEndpoint.ts +7 -7
- package/src/unstable/httpapi/HttpApiSchema.ts +1 -1
- package/src/unstable/observability/OtlpTracer.ts +4 -3
- package/src/unstable/reactivity/Atom.ts +10 -7
|
@@ -80,15 +80,15 @@ export const decode = <IE, Done>(): Channel.Channel<
|
|
|
80
80
|
* @since 4.0.0
|
|
81
81
|
*/
|
|
82
82
|
export interface EventCodec extends
|
|
83
|
-
Schema.
|
|
83
|
+
Schema.ConstraintCodec<
|
|
84
84
|
any,
|
|
85
85
|
{
|
|
86
86
|
readonly id?: string | undefined
|
|
87
87
|
readonly event?: string | undefined
|
|
88
88
|
readonly data: string
|
|
89
89
|
},
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
unknown,
|
|
91
|
+
unknown
|
|
92
92
|
>
|
|
93
93
|
{}
|
|
94
94
|
|
|
@@ -335,8 +335,8 @@ export const jsonSchema = <S extends Schema.Constraint>(
|
|
|
335
335
|
* @category constructors
|
|
336
336
|
* @since 4.0.0
|
|
337
337
|
*/
|
|
338
|
-
export const urlParams = (urlParams: UrlParams.
|
|
339
|
-
text(UrlParams.toString(urlParams), contentType ?? "application/x-www-form-urlencoded")
|
|
338
|
+
export const urlParams = (urlParams: UrlParams.Input, contentType?: string): Uint8Array =>
|
|
339
|
+
text(UrlParams.toString(UrlParams.fromInput(urlParams)), contentType ?? "application/x-www-form-urlencoded")
|
|
340
340
|
|
|
341
341
|
/**
|
|
342
342
|
* HTTP body variant backed by Web `FormData`.
|
|
@@ -40,7 +40,7 @@ import * as HttpClientResponse from "./HttpClientResponse.ts"
|
|
|
40
40
|
import * as HttpIncomingMessage from "./HttpIncomingMessage.ts"
|
|
41
41
|
import * as HttpMethod from "./HttpMethod.ts"
|
|
42
42
|
import * as TraceContext from "./HttpTraceContext.ts"
|
|
43
|
-
import * as
|
|
43
|
+
import * as Url from "./Url.ts"
|
|
44
44
|
|
|
45
45
|
const TypeId = "~effect/http/HttpClient"
|
|
46
46
|
|
|
@@ -790,7 +790,7 @@ export const make = (
|
|
|
790
790
|
Effect.withFiber((fiber) => {
|
|
791
791
|
const scopedController = scopedRequests.get(request)
|
|
792
792
|
const controller = scopedController ?? new AbortController()
|
|
793
|
-
const urlResult =
|
|
793
|
+
const urlResult = Url.make(request.url, request.urlParams, Option.getOrUndefined(request.hash))
|
|
794
794
|
if (Result.isFailure(urlResult)) {
|
|
795
795
|
return Effect.fail(
|
|
796
796
|
new Error.HttpClientError({
|
|
@@ -28,6 +28,7 @@ import * as Stream from "../../Stream.ts"
|
|
|
28
28
|
import * as Headers from "./Headers.ts"
|
|
29
29
|
import * as HttpBody from "./HttpBody.ts"
|
|
30
30
|
import { hasBody, type HttpMethod } from "./HttpMethod.ts"
|
|
31
|
+
import * as Url from "./Url.ts"
|
|
31
32
|
import * as UrlParams from "./UrlParams.ts"
|
|
32
33
|
|
|
33
34
|
const TypeId = "~effect/http/HttpClientRequest"
|
|
@@ -116,7 +117,7 @@ const Proto = {
|
|
|
116
117
|
export function makeWith(
|
|
117
118
|
method: HttpMethod,
|
|
118
119
|
url: string,
|
|
119
|
-
urlParams: UrlParams.
|
|
120
|
+
urlParams: UrlParams.Input,
|
|
120
121
|
hash: Option.Option<string>,
|
|
121
122
|
headers: Headers.Headers,
|
|
122
123
|
body: HttpBody.HttpBody
|
|
@@ -1180,7 +1181,7 @@ export const bodyFile: {
|
|
|
1180
1181
|
* @since 4.0.0
|
|
1181
1182
|
*/
|
|
1182
1183
|
export function toUrl(self: HttpClientRequest): Option.Option<URL> {
|
|
1183
|
-
const r =
|
|
1184
|
+
const r = Url.make(self.url, self.urlParams, Option.getOrUndefined(self.hash))
|
|
1184
1185
|
if (Result.isSuccess(r)) {
|
|
1185
1186
|
return Option.some(r.success)
|
|
1186
1187
|
}
|
|
@@ -1230,8 +1231,8 @@ const parseContentLength = (contentLength: string | null): number | undefined =>
|
|
|
1230
1231
|
export const toWebResult = (self: HttpClientRequest, options?: {
|
|
1231
1232
|
readonly signal?: AbortSignal | undefined
|
|
1232
1233
|
readonly context?: Context.Context<never> | undefined
|
|
1233
|
-
}): Result.Result<Request,
|
|
1234
|
-
const url =
|
|
1234
|
+
}): Result.Result<Request, Url.UrlError> => {
|
|
1235
|
+
const url = Url.make(self.url, self.urlParams, Option.getOrUndefined(self.hash))
|
|
1235
1236
|
if (Result.isFailure(url)) {
|
|
1236
1237
|
return Result.fail(url.failure)
|
|
1237
1238
|
}
|
|
@@ -1271,7 +1272,7 @@ export const toWebResult = (self: HttpClientRequest, options?: {
|
|
|
1271
1272
|
}
|
|
1272
1273
|
return Result.try({
|
|
1273
1274
|
try: () => new Request(url.success, requestInit),
|
|
1274
|
-
catch: (cause) => new
|
|
1275
|
+
catch: (cause) => new Url.UrlError({ cause })
|
|
1275
1276
|
})
|
|
1276
1277
|
}
|
|
1277
1278
|
|
|
@@ -1279,14 +1280,14 @@ const isReadableStream = (u: unknown): u is ReadableStream<Uint8Array> =>
|
|
|
1279
1280
|
typeof ReadableStream !== "undefined" && u instanceof ReadableStream
|
|
1280
1281
|
|
|
1281
1282
|
/**
|
|
1282
|
-
* Converts an `HttpClientRequest` to a Web `Request`, failing with `
|
|
1283
|
+
* Converts an `HttpClientRequest` to a Web `Request`, failing with `UrlError` when the request URL is invalid.
|
|
1283
1284
|
*
|
|
1284
1285
|
* @category converting
|
|
1285
1286
|
* @since 4.0.0
|
|
1286
1287
|
*/
|
|
1287
1288
|
export const toWeb = (self: HttpClientRequest, options?: {
|
|
1288
1289
|
readonly signal?: AbortSignal | undefined
|
|
1289
|
-
}): Effect.Effect<Request,
|
|
1290
|
+
}): Effect.Effect<Request, Url.UrlError> =>
|
|
1290
1291
|
Effect.contextWith((context) =>
|
|
1291
1292
|
Effect.fromResult(toWebResult(self, {
|
|
1292
1293
|
context: context,
|
|
@@ -93,10 +93,9 @@ export const schemaJson = <
|
|
|
93
93
|
readonly headers?: Readonly<Record<string, string | undefined>> | undefined
|
|
94
94
|
readonly body?: unknown
|
|
95
95
|
},
|
|
96
|
-
RD
|
|
97
|
-
RE
|
|
96
|
+
RD
|
|
98
97
|
>(
|
|
99
|
-
schema: Schema.
|
|
98
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
100
99
|
options?: ParseOptions | undefined
|
|
101
100
|
) => {
|
|
102
101
|
const decode = Schema.decodeEffect(Schema.toCodecJson(schema).annotate({ options }))
|
|
@@ -78,10 +78,9 @@ export const schemaBodyJson = <S extends Schema.Constraint>(schema: S, options?:
|
|
|
78
78
|
export const schemaBodyUrlParams = <
|
|
79
79
|
A,
|
|
80
80
|
I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
|
|
81
|
-
RD
|
|
82
|
-
RE
|
|
81
|
+
RD
|
|
83
82
|
>(
|
|
84
|
-
schema: Schema.
|
|
83
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
85
84
|
options?: ParseOptions | undefined
|
|
86
85
|
) => {
|
|
87
86
|
const decode = UrlParams.schemaRecord.pipe(
|
|
@@ -98,8 +97,8 @@ export const schemaBodyUrlParams = <
|
|
|
98
97
|
* @category schemas
|
|
99
98
|
* @since 4.0.0
|
|
100
99
|
*/
|
|
101
|
-
export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD
|
|
102
|
-
schema: Schema.
|
|
100
|
+
export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
|
|
101
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
103
102
|
options?: ParseOptions | undefined
|
|
104
103
|
) => {
|
|
105
104
|
const decode = Schema.decodeUnknownEffect(schema)
|
|
@@ -313,10 +313,9 @@ export const schemaJson = <
|
|
|
313
313
|
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
|
|
314
314
|
readonly body: any
|
|
315
315
|
}>,
|
|
316
|
-
RD
|
|
317
|
-
RE
|
|
316
|
+
RD
|
|
318
317
|
>(
|
|
319
|
-
schema: Schema.
|
|
318
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
320
319
|
options?: ParseOptions | undefined
|
|
321
320
|
): Effect.Effect<
|
|
322
321
|
A,
|
|
@@ -368,10 +367,9 @@ export const schemaNoBody = <
|
|
|
368
367
|
readonly pathParams: Readonly<Record<string, string | undefined>>
|
|
369
368
|
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
|
|
370
369
|
}>,
|
|
371
|
-
RD
|
|
372
|
-
RE
|
|
370
|
+
RD
|
|
373
371
|
>(
|
|
374
|
-
schema: Schema.
|
|
372
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
375
373
|
options?: ParseOptions | undefined
|
|
376
374
|
): Effect.Effect<
|
|
377
375
|
A,
|
|
@@ -410,8 +408,8 @@ export const schemaNoBody = <
|
|
|
410
408
|
* @category schemas
|
|
411
409
|
* @since 4.0.0
|
|
412
410
|
*/
|
|
413
|
-
export const schemaParams = <A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, RD
|
|
414
|
-
schema: Schema.
|
|
411
|
+
export const schemaParams = <A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, RD>(
|
|
412
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
415
413
|
options?: ParseOptions | undefined
|
|
416
414
|
): Effect.Effect<A, Schema.SchemaError, HttpServerRequest.ParsedSearchParams | RouteContext | RD> => {
|
|
417
415
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
@@ -429,8 +427,8 @@ export const schemaParams = <A, I extends Readonly<Record<string, string | Reado
|
|
|
429
427
|
* @category schemas
|
|
430
428
|
* @since 4.0.0
|
|
431
429
|
*/
|
|
432
|
-
export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, RD
|
|
433
|
-
schema: Schema.
|
|
430
|
+
export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
|
|
431
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
434
432
|
options?: ParseOptions | undefined
|
|
435
433
|
): Effect.Effect<A, Schema.SchemaError, RouteContext | RD> => {
|
|
436
434
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
@@ -191,8 +191,8 @@ export const upgradeChannel = <IE = never>(): Channel.Channel<
|
|
|
191
191
|
* @category schemas
|
|
192
192
|
* @since 4.0.0
|
|
193
193
|
*/
|
|
194
|
-
export const schemaCookies = <A, I extends Readonly<Record<string, string | undefined>>, RD
|
|
195
|
-
schema: Schema.
|
|
194
|
+
export const schemaCookies = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
|
|
195
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
196
196
|
options?: ParseOptions | undefined
|
|
197
197
|
): Effect.Effect<A, Schema.SchemaError, RD | HttpServerRequest> => {
|
|
198
198
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
@@ -205,8 +205,8 @@ export const schemaCookies = <A, I extends Readonly<Record<string, string | unde
|
|
|
205
205
|
* @category schemas
|
|
206
206
|
* @since 4.0.0
|
|
207
207
|
*/
|
|
208
|
-
export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD
|
|
209
|
-
schema: Schema.
|
|
208
|
+
export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
|
|
209
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
210
210
|
options?: ParseOptions | undefined
|
|
211
211
|
): Effect.Effect<A, Schema.SchemaError, HttpServerRequest | RD> => {
|
|
212
212
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
@@ -222,10 +222,9 @@ export const schemaHeaders = <A, I extends Readonly<Record<string, string | unde
|
|
|
222
222
|
export const schemaSearchParams = <
|
|
223
223
|
A,
|
|
224
224
|
I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
|
|
225
|
-
RD
|
|
226
|
-
RE
|
|
225
|
+
RD
|
|
227
226
|
>(
|
|
228
|
-
schema: Schema.
|
|
227
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
229
228
|
options?: ParseOptions | undefined
|
|
230
229
|
): Effect.Effect<A, Schema.SchemaError, ParsedSearchParams | RD> => {
|
|
231
230
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
@@ -242,8 +241,8 @@ export const schemaSearchParams = <
|
|
|
242
241
|
* @category schemas
|
|
243
242
|
* @since 4.0.0
|
|
244
243
|
*/
|
|
245
|
-
export const schemaBodyJson = <A,
|
|
246
|
-
schema: Schema.
|
|
244
|
+
export const schemaBodyJson = <A, RD>(
|
|
245
|
+
schema: Schema.ConstraintDecoder<A, RD>,
|
|
247
246
|
options?: ParseOptions | undefined
|
|
248
247
|
): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
|
|
249
248
|
const parse = HttpIncomingMessage.schemaBodyJson(schema, options)
|
|
@@ -265,12 +264,15 @@ const isMultipart = (request: HttpServerRequest) =>
|
|
|
265
264
|
* @category schemas
|
|
266
265
|
* @since 4.0.0
|
|
267
266
|
*/
|
|
268
|
-
export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD
|
|
269
|
-
schema: Schema.
|
|
267
|
+
export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD>(
|
|
268
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
270
269
|
options?: ParseOptions | undefined
|
|
271
270
|
) => {
|
|
272
271
|
const parseMultipart = Multipart.schemaPersisted(schema)
|
|
273
|
-
const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(
|
|
272
|
+
const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(
|
|
273
|
+
schema as Schema.ConstraintCodec<A, any, RD, unknown>,
|
|
274
|
+
options
|
|
275
|
+
)
|
|
274
276
|
return Effect.flatMap(HttpServerRequest, (request): Effect.Effect<
|
|
275
277
|
A,
|
|
276
278
|
Multipart.MultipartError | Schema.SchemaError | HttpServerError,
|
|
@@ -293,10 +295,9 @@ export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD, RE
|
|
|
293
295
|
export const schemaBodyUrlParams = <
|
|
294
296
|
A,
|
|
295
297
|
I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
|
|
296
|
-
RD
|
|
297
|
-
RE
|
|
298
|
+
RD
|
|
298
299
|
>(
|
|
299
|
-
schema: Schema.
|
|
300
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
300
301
|
options?: ParseOptions | undefined
|
|
301
302
|
): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
|
|
302
303
|
const parse = HttpIncomingMessage.schemaBodyUrlParams(schema, options)
|
|
@@ -315,8 +316,8 @@ export const schemaBodyUrlParams = <
|
|
|
315
316
|
* @category schemas
|
|
316
317
|
* @since 4.0.0
|
|
317
318
|
*/
|
|
318
|
-
export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, RD
|
|
319
|
-
schema: Schema.
|
|
319
|
+
export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, RD>(
|
|
320
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>,
|
|
320
321
|
options?: ParseOptions | undefined
|
|
321
322
|
): Effect.Effect<
|
|
322
323
|
A,
|
|
@@ -342,8 +343,8 @@ export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, R
|
|
|
342
343
|
* @category schemas
|
|
343
344
|
* @since 4.0.0
|
|
344
345
|
*/
|
|
345
|
-
export const schemaBodyFormJson = <A,
|
|
346
|
-
schema: Schema.
|
|
346
|
+
export const schemaBodyFormJson = <A, RD>(
|
|
347
|
+
schema: Schema.ConstraintDecoder<A, RD>,
|
|
347
348
|
options?: ParseOptions | undefined
|
|
348
349
|
) => {
|
|
349
350
|
const parseMultipart = Multipart.schemaJson(schema, options)
|
|
@@ -334,8 +334,8 @@ export const json = (
|
|
|
334
334
|
* @category constructors
|
|
335
335
|
* @since 4.0.0
|
|
336
336
|
*/
|
|
337
|
-
export const schemaJson = <A,
|
|
338
|
-
schema: Schema.
|
|
337
|
+
export const schemaJson = <A, RE>(
|
|
338
|
+
schema: Schema.ConstraintCodec<A, unknown, unknown, RE>,
|
|
339
339
|
options?: ParseOptions | undefined
|
|
340
340
|
) => {
|
|
341
341
|
const encode = Body.jsonSchema(schema, options)
|
|
@@ -333,8 +333,8 @@ export const SingleFileSchema: Schema.decodeTo<PersistedFileSchema, Schema.$Arra
|
|
|
333
333
|
* @category schemas
|
|
334
334
|
* @since 4.0.0
|
|
335
335
|
*/
|
|
336
|
-
export const schemaPersisted = <A, I extends Partial<Persisted>, RD
|
|
337
|
-
schema: Schema.
|
|
336
|
+
export const schemaPersisted = <A, I extends Partial<Persisted>, RD>(
|
|
337
|
+
schema: Schema.ConstraintCodec<A, I, RD, unknown>
|
|
338
338
|
): (input: unknown, options?: ParseOptions) => Effect.Effect<A, Schema.SchemaError, RD> =>
|
|
339
339
|
Schema.decodeUnknownEffect(schema)
|
|
340
340
|
|
|
@@ -349,7 +349,7 @@ export const schemaPersisted = <A, I extends Partial<Persisted>, RD, RE>(
|
|
|
349
349
|
* @category schemas
|
|
350
350
|
* @since 4.0.0
|
|
351
351
|
*/
|
|
352
|
-
export const schemaJson = <A,
|
|
352
|
+
export const schemaJson = <A, RD>(schema: Schema.ConstraintDecoder<A, RD>, options?: ParseOptions | undefined): {
|
|
353
353
|
(
|
|
354
354
|
field: string
|
|
355
355
|
): (persisted: Persisted) => Effect.Effect<A, Schema.SchemaError, RD>
|
package/src/unstable/http/Url.ts
CHANGED
|
@@ -9,11 +9,66 @@
|
|
|
9
9
|
* @since 4.0.0
|
|
10
10
|
*/
|
|
11
11
|
import * as Cause from "../../Cause.ts"
|
|
12
|
+
import * as Data from "../../Data.ts"
|
|
12
13
|
import { dual } from "../../Function.ts"
|
|
13
14
|
import * as Redacted from "../../Redacted.ts"
|
|
14
15
|
import * as Result from "../../Result.ts"
|
|
15
16
|
import * as UrlParams from "./UrlParams.ts"
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Error returned when constructing a `URL` fails.
|
|
20
|
+
*
|
|
21
|
+
* @category errors
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
*/
|
|
24
|
+
export class UrlError extends Data.TaggedError("UrlError")<{
|
|
25
|
+
readonly cause: unknown
|
|
26
|
+
}> {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a `URL` safely by appending `UrlParams` and an optional hash to a URL string.
|
|
30
|
+
*
|
|
31
|
+
* **Details**
|
|
32
|
+
*
|
|
33
|
+
* Returns a `Result` that fails with `UrlError` if the URL cannot be constructed.
|
|
34
|
+
*
|
|
35
|
+
* @category constructors
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
export const make = (
|
|
39
|
+
url: string,
|
|
40
|
+
params: UrlParams.UrlParams,
|
|
41
|
+
hash: string | undefined
|
|
42
|
+
): Result.Result<URL, UrlError> =>
|
|
43
|
+
Result.try({
|
|
44
|
+
try: () => {
|
|
45
|
+
const urlInstance = new URL(url, baseUrl())
|
|
46
|
+
for (let i = 0; i < params.params.length; i++) {
|
|
47
|
+
const [key, value] = params.params[i]
|
|
48
|
+
if (value !== undefined) {
|
|
49
|
+
urlInstance.searchParams.append(key, value)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (hash !== undefined) {
|
|
53
|
+
urlInstance.hash = hash
|
|
54
|
+
}
|
|
55
|
+
return urlInstance
|
|
56
|
+
},
|
|
57
|
+
catch: (cause) => new UrlError({ cause })
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const baseUrl = (): string | undefined => {
|
|
61
|
+
if (
|
|
62
|
+
"location" in globalThis &&
|
|
63
|
+
globalThis.location !== undefined &&
|
|
64
|
+
globalThis.location.origin !== undefined &&
|
|
65
|
+
globalThis.location.pathname !== undefined
|
|
66
|
+
) {
|
|
67
|
+
return location.origin + location.pathname
|
|
68
|
+
}
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
17
72
|
/**
|
|
18
73
|
* Parses a URL string safely into a `URL` object, returning a `Result` type for
|
|
19
74
|
* error handling.
|
|
@@ -502,7 +557,7 @@ export const setUrlParams: {
|
|
|
502
557
|
* @category setters
|
|
503
558
|
* @since 4.0.0
|
|
504
559
|
*/
|
|
505
|
-
(urlParams: UrlParams.
|
|
560
|
+
(urlParams: UrlParams.Input): (url: URL) => URL
|
|
506
561
|
/**
|
|
507
562
|
* Updates the query parameters of a URL.
|
|
508
563
|
*
|
|
@@ -532,10 +587,10 @@ export const setUrlParams: {
|
|
|
532
587
|
* @category setters
|
|
533
588
|
* @since 4.0.0
|
|
534
589
|
*/
|
|
535
|
-
(url: URL, urlParams: UrlParams.
|
|
536
|
-
} = dual(2, (url: URL,
|
|
590
|
+
(url: URL, urlParams: UrlParams.Input): URL
|
|
591
|
+
} = dual(2, (url: URL, urlParams: UrlParams.Input) =>
|
|
537
592
|
mutate(url, (url) => {
|
|
538
|
-
url.search = UrlParams.toString(
|
|
593
|
+
url.search = UrlParams.toString(UrlParams.fromInput(urlParams))
|
|
539
594
|
}))
|
|
540
595
|
|
|
541
596
|
/**
|
|
@@ -619,7 +674,7 @@ export const modifyUrlParams: {
|
|
|
619
674
|
* @category modifiers
|
|
620
675
|
* @since 4.0.0
|
|
621
676
|
*/
|
|
622
|
-
(f: (urlParams: UrlParams.UrlParams) => UrlParams.
|
|
677
|
+
(f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): (url: URL) => URL
|
|
623
678
|
/**
|
|
624
679
|
* Reads the query parameters of a URL, modifies them, and updates the URL.
|
|
625
680
|
*
|
|
@@ -646,8 +701,8 @@ export const modifyUrlParams: {
|
|
|
646
701
|
* @category modifiers
|
|
647
702
|
* @since 4.0.0
|
|
648
703
|
*/
|
|
649
|
-
(url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.
|
|
650
|
-
} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.
|
|
704
|
+
(url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): URL
|
|
705
|
+
} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input) =>
|
|
651
706
|
mutate(url, (url) => {
|
|
652
707
|
const params = f(UrlParams.fromInput(url.searchParams))
|
|
653
708
|
url.search = UrlParams.toString(params)
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* @since 4.0.0
|
|
10
10
|
*/
|
|
11
11
|
import * as Arr from "../../Array.ts"
|
|
12
|
-
import * as Data from "../../Data.ts"
|
|
13
12
|
import * as Effect from "../../Effect.ts"
|
|
14
13
|
import * as Equal from "../../Equal.ts"
|
|
15
14
|
import * as Equ from "../../Equivalence.ts"
|
|
@@ -21,7 +20,6 @@ import * as Option from "../../Option.ts"
|
|
|
21
20
|
import type { Pipeable } from "../../Pipeable.ts"
|
|
22
21
|
import { hasProperty } from "../../Predicate.ts"
|
|
23
22
|
import type { ReadonlyRecord } from "../../Record.ts"
|
|
24
|
-
import * as Result from "../../Result.ts"
|
|
25
23
|
import * as Schema from "../../Schema.ts"
|
|
26
24
|
import * as SchemaIssue from "../../SchemaIssue.ts"
|
|
27
25
|
import * as SchemaTransformation from "../../SchemaTransformation.ts"
|
|
@@ -65,6 +63,7 @@ export const isUrlParams = (u: unknown): u is UrlParams => hasProperty(u, TypeId
|
|
|
65
63
|
* @since 4.0.0
|
|
66
64
|
*/
|
|
67
65
|
export type Input =
|
|
66
|
+
| UrlParams
|
|
68
67
|
| CoercibleRecordInput
|
|
69
68
|
| Iterable<readonly [string, Coercible]>
|
|
70
69
|
| URLSearchParams
|
|
@@ -157,6 +156,9 @@ export const make = (params: ReadonlyArray<readonly [string, string]>): UrlParam
|
|
|
157
156
|
* @since 4.0.0
|
|
158
157
|
*/
|
|
159
158
|
export const fromInput = (input: Input): UrlParams => {
|
|
159
|
+
if (isUrlParams(input)) {
|
|
160
|
+
return input
|
|
161
|
+
}
|
|
160
162
|
const parsed = fromInputNested(input)
|
|
161
163
|
const out: Array<[string, string]> = []
|
|
162
164
|
for (let i = 0; i < parsed.length; i++) {
|
|
@@ -634,68 +636,13 @@ export const remove: {
|
|
|
634
636
|
(self: UrlParams, key: string): UrlParams
|
|
635
637
|
} = dual(2, (self: UrlParams, key: string): UrlParams => transform(self, Arr.filter(([k]) => k !== key)))
|
|
636
638
|
|
|
637
|
-
/**
|
|
638
|
-
* Error returned when constructing a `URL` from `UrlParams` fails.
|
|
639
|
-
*
|
|
640
|
-
* @category errors
|
|
641
|
-
* @since 4.0.0
|
|
642
|
-
*/
|
|
643
|
-
export class UrlParamsError extends Data.TaggedError("UrlParamsError")<{
|
|
644
|
-
cause: unknown
|
|
645
|
-
}> {}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Creates a `URL` safely by appending `UrlParams` and an optional hash to a URL string.
|
|
649
|
-
*
|
|
650
|
-
* **Details**
|
|
651
|
-
*
|
|
652
|
-
* Returns a `Result` that fails with `UrlParamsError` if the URL cannot be
|
|
653
|
-
* constructed.
|
|
654
|
-
*
|
|
655
|
-
* @category converting
|
|
656
|
-
* @since 4.0.0
|
|
657
|
-
*/
|
|
658
|
-
export const makeUrl = (
|
|
659
|
-
url: string,
|
|
660
|
-
params: UrlParams,
|
|
661
|
-
hash: string | undefined
|
|
662
|
-
): Result.Result<URL, UrlParamsError> => {
|
|
663
|
-
try {
|
|
664
|
-
const urlInstance = new URL(url, baseUrl())
|
|
665
|
-
for (let i = 0; i < params.params.length; i++) {
|
|
666
|
-
const [key, value] = params.params[i]
|
|
667
|
-
if (value !== undefined) {
|
|
668
|
-
urlInstance.searchParams.append(key, value)
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
if (hash !== undefined) {
|
|
672
|
-
urlInstance.hash = hash
|
|
673
|
-
}
|
|
674
|
-
return Result.succeed(urlInstance)
|
|
675
|
-
} catch (e) {
|
|
676
|
-
return Result.fail(new UrlParamsError({ cause: e }))
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
639
|
/**
|
|
681
640
|
* Serializes `UrlParams` to a URL query string without a leading question mark.
|
|
682
641
|
*
|
|
683
642
|
* @category converting
|
|
684
643
|
* @since 4.0.0
|
|
685
644
|
*/
|
|
686
|
-
export const toString = (
|
|
687
|
-
|
|
688
|
-
const baseUrl = (): string | undefined => {
|
|
689
|
-
if (
|
|
690
|
-
"location" in globalThis &&
|
|
691
|
-
globalThis.location !== undefined &&
|
|
692
|
-
globalThis.location.origin !== undefined &&
|
|
693
|
-
globalThis.location.pathname !== undefined
|
|
694
|
-
) {
|
|
695
|
-
return location.origin + location.pathname
|
|
696
|
-
}
|
|
697
|
-
return undefined
|
|
698
|
-
}
|
|
645
|
+
export const toString = (input: Input): string => new URLSearchParams(fromInput(input).params as any).toString()
|
|
699
646
|
|
|
700
647
|
/**
|
|
701
648
|
* Builds a `Record` containing all the key-value pairs in the given `UrlParams`
|
|
@@ -186,9 +186,7 @@ const makeProto = <Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
186
186
|
): HttpApi<Id, Groups> => {
|
|
187
187
|
function HttpApi() {}
|
|
188
188
|
Object.setPrototypeOf(HttpApi, Proto)
|
|
189
|
-
HttpApi
|
|
190
|
-
HttpApi.annotations = options.annotations
|
|
191
|
-
return HttpApi as any
|
|
189
|
+
return Object.assign(HttpApi, options) as any
|
|
192
190
|
}
|
|
193
191
|
|
|
194
192
|
/**
|
|
@@ -206,7 +204,7 @@ const makeProto = <Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
206
204
|
export const make = <const Id extends string>(identifier: Id): HttpApi<Id, never> =>
|
|
207
205
|
makeProto({
|
|
208
206
|
identifier,
|
|
209
|
-
groups:
|
|
207
|
+
groups: {},
|
|
210
208
|
annotations: Context.empty()
|
|
211
209
|
})
|
|
212
210
|
|