@effect/platform 0.55.6 → 0.56.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/dist/cjs/Http/App.js +4 -2
- package/dist/cjs/Http/App.js.map +1 -1
- package/dist/cjs/Http/ClientRequest.js +11 -1
- package/dist/cjs/Http/ClientRequest.js.map +1 -1
- package/dist/cjs/Http/Headers.js +3 -3
- package/dist/cjs/Http/Headers.js.map +1 -1
- package/dist/cjs/Http/UrlParams.js +4 -1
- package/dist/cjs/Http/UrlParams.js.map +1 -1
- package/dist/cjs/Worker.js.map +1 -1
- package/dist/cjs/internal/http/client.js +1 -1
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/clientRequest.js +37 -16
- package/dist/cjs/internal/http/clientRequest.js.map +1 -1
- package/dist/cjs/internal/worker.js +24 -15
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/Http/ClientRequest.d.ts +35 -7
- package/dist/dts/Http/ClientRequest.d.ts.map +1 -1
- package/dist/dts/Http/Headers.d.ts +3 -3
- package/dist/dts/Http/Headers.d.ts.map +1 -1
- package/dist/dts/Http/UrlParams.d.ts +1 -1
- package/dist/dts/Http/UrlParams.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +15 -4
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/esm/Http/App.js +4 -2
- package/dist/esm/Http/App.js.map +1 -1
- package/dist/esm/Http/ClientRequest.js +10 -0
- package/dist/esm/Http/ClientRequest.js.map +1 -1
- package/dist/esm/Http/Headers.js +3 -3
- package/dist/esm/Http/Headers.js.map +1 -1
- package/dist/esm/Http/UrlParams.js +4 -1
- package/dist/esm/Http/UrlParams.js.map +1 -1
- package/dist/esm/Worker.js.map +1 -1
- package/dist/esm/internal/http/client.js +1 -1
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/clientRequest.js +35 -15
- package/dist/esm/internal/http/clientRequest.js.map +1 -1
- package/dist/esm/internal/worker.js +24 -15
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +3 -3
- package/src/Http/App.ts +4 -4
- package/src/Http/ClientRequest.ts +37 -7
- package/src/Http/Headers.ts +15 -7
- package/src/Http/UrlParams.ts +4 -2
- package/src/Worker.ts +19 -6
- package/src/internal/http/client.ts +1 -1
- package/src/internal/http/clientRequest.ts +75 -10
- package/src/internal/worker.ts +39 -23
|
@@ -5,6 +5,7 @@ import type { ParseOptions } from "@effect/schema/AST"
|
|
|
5
5
|
import type * as Schema from "@effect/schema/Schema"
|
|
6
6
|
import type * as Effect from "effect/Effect"
|
|
7
7
|
import type { Inspectable } from "effect/Inspectable"
|
|
8
|
+
import type * as Option from "effect/Option"
|
|
8
9
|
import type { Scope } from "effect/Scope"
|
|
9
10
|
import type * as Stream from "effect/Stream"
|
|
10
11
|
import type * as PlatformError from "../Error.js"
|
|
@@ -41,6 +42,7 @@ export interface ClientRequest
|
|
|
41
42
|
readonly method: Method
|
|
42
43
|
readonly url: string
|
|
43
44
|
readonly urlParams: UrlParams.UrlParams
|
|
45
|
+
readonly hash: Option.Option<string>
|
|
44
46
|
readonly headers: Headers.Headers
|
|
45
47
|
readonly body: Body.Body
|
|
46
48
|
}
|
|
@@ -51,8 +53,9 @@ export interface ClientRequest
|
|
|
51
53
|
*/
|
|
52
54
|
export interface Options {
|
|
53
55
|
readonly method?: Method | undefined
|
|
54
|
-
readonly url?: string | undefined
|
|
56
|
+
readonly url?: string | URL | undefined
|
|
55
57
|
readonly urlParams?: UrlParams.Input | undefined
|
|
58
|
+
readonly hash?: string | undefined
|
|
56
59
|
readonly headers?: Headers.Input | undefined
|
|
57
60
|
readonly body?: Body.Body | undefined
|
|
58
61
|
readonly accept?: string | undefined
|
|
@@ -204,7 +207,7 @@ export const acceptJson: (self: ClientRequest) => ClientRequest = internal.accep
|
|
|
204
207
|
*/
|
|
205
208
|
export const setUrl: {
|
|
206
209
|
(url: string | URL): (self: ClientRequest) => ClientRequest
|
|
207
|
-
(self: ClientRequest, url: string): ClientRequest
|
|
210
|
+
(self: ClientRequest, url: string | URL): ClientRequest
|
|
208
211
|
} = internal.setUrl
|
|
209
212
|
|
|
210
213
|
/**
|
|
@@ -212,7 +215,7 @@ export const setUrl: {
|
|
|
212
215
|
* @category combinators
|
|
213
216
|
*/
|
|
214
217
|
export const prependUrl: {
|
|
215
|
-
(path: string
|
|
218
|
+
(path: string): (self: ClientRequest) => ClientRequest
|
|
216
219
|
(self: ClientRequest, path: string): ClientRequest
|
|
217
220
|
} = internal.prependUrl
|
|
218
221
|
|
|
@@ -238,25 +241,52 @@ export const updateUrl: {
|
|
|
238
241
|
* @since 1.0.0
|
|
239
242
|
* @category combinators
|
|
240
243
|
*/
|
|
241
|
-
export const setUrlParam
|
|
244
|
+
export const setUrlParam: {
|
|
245
|
+
(key: string, value: string): (self: ClientRequest) => ClientRequest
|
|
246
|
+
(self: ClientRequest, key: string, value: string): ClientRequest
|
|
247
|
+
} = internal.setUrlParam
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @since 1.0.0
|
|
251
|
+
* @category combinators
|
|
252
|
+
*/
|
|
253
|
+
export const setUrlParams: {
|
|
254
|
+
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest
|
|
255
|
+
(self: ClientRequest, input: UrlParams.Input): ClientRequest
|
|
256
|
+
} = internal.setUrlParams
|
|
242
257
|
|
|
243
258
|
/**
|
|
244
259
|
* @since 1.0.0
|
|
245
260
|
* @category combinators
|
|
246
261
|
*/
|
|
247
|
-
export const
|
|
262
|
+
export const appendUrlParam: {
|
|
263
|
+
(key: string, value: string): (self: ClientRequest) => ClientRequest
|
|
264
|
+
(self: ClientRequest, key: string, value: string): ClientRequest
|
|
265
|
+
} = internal.appendUrlParam
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @since 1.0.0
|
|
269
|
+
* @category combinators
|
|
270
|
+
*/
|
|
271
|
+
export const appendUrlParams: {
|
|
272
|
+
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest
|
|
273
|
+
(self: ClientRequest, input: UrlParams.Input): ClientRequest
|
|
274
|
+
} = internal.appendUrlParams
|
|
248
275
|
|
|
249
276
|
/**
|
|
250
277
|
* @since 1.0.0
|
|
251
278
|
* @category combinators
|
|
252
279
|
*/
|
|
253
|
-
export const
|
|
280
|
+
export const setHash: {
|
|
281
|
+
(hash: string): (self: ClientRequest) => ClientRequest
|
|
282
|
+
(self: ClientRequest, hash: string): ClientRequest
|
|
283
|
+
} = internal.setHash
|
|
254
284
|
|
|
255
285
|
/**
|
|
256
286
|
* @since 1.0.0
|
|
257
287
|
* @category combinators
|
|
258
288
|
*/
|
|
259
|
-
export const
|
|
289
|
+
export const removeHash: (self: ClientRequest) => ClientRequest = internal.removeHash
|
|
260
290
|
|
|
261
291
|
/**
|
|
262
292
|
* @since 1.0.0
|
package/src/Http/Headers.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { globalValue } from "effect/GlobalValue"
|
|
|
8
8
|
import type * as Option from "effect/Option"
|
|
9
9
|
import * as Predicate from "effect/Predicate"
|
|
10
10
|
import * as Record from "effect/Record"
|
|
11
|
-
import * as
|
|
11
|
+
import * as Redacted from "effect/Redacted"
|
|
12
12
|
import * as String from "effect/String"
|
|
13
13
|
import type { Mutable } from "effect/Types"
|
|
14
14
|
|
|
@@ -205,22 +205,30 @@ export const remove: {
|
|
|
205
205
|
* @category combinators
|
|
206
206
|
*/
|
|
207
207
|
export const redact: {
|
|
208
|
-
(
|
|
209
|
-
|
|
208
|
+
(
|
|
209
|
+
key: string | RegExp | ReadonlyArray<string | RegExp>
|
|
210
|
+
): (self: Headers) => Record<string, string | Redacted.Redacted>
|
|
211
|
+
(
|
|
212
|
+
self: Headers,
|
|
213
|
+
key: string | RegExp | ReadonlyArray<string | RegExp>
|
|
214
|
+
): Record<string, string | Redacted.Redacted>
|
|
210
215
|
} = dual(
|
|
211
216
|
2,
|
|
212
|
-
(
|
|
213
|
-
|
|
217
|
+
(
|
|
218
|
+
self: Headers,
|
|
219
|
+
key: string | RegExp | ReadonlyArray<string | RegExp>
|
|
220
|
+
): Record<string, string | Redacted.Redacted> => {
|
|
221
|
+
const out: Record<string, string | Redacted.Redacted> = { ...self }
|
|
214
222
|
const modify = (key: string | RegExp) => {
|
|
215
223
|
if (typeof key === "string") {
|
|
216
224
|
const k = key.toLowerCase()
|
|
217
225
|
if (k in self) {
|
|
218
|
-
out[k] =
|
|
226
|
+
out[k] = Redacted.make(self[k])
|
|
219
227
|
}
|
|
220
228
|
} else {
|
|
221
229
|
for (const name in self) {
|
|
222
230
|
if (key.test(name)) {
|
|
223
|
-
out[name] =
|
|
231
|
+
out[name] = Redacted.make(self[name])
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
234
|
}
|
package/src/Http/UrlParams.ts
CHANGED
|
@@ -207,7 +207,7 @@ export const toString = (self: UrlParams): string => new URLSearchParams(self as
|
|
|
207
207
|
* @since 1.0.0
|
|
208
208
|
* @category constructors
|
|
209
209
|
*/
|
|
210
|
-
export const makeUrl = (url: string, params: UrlParams): Either.Either<URL, Error> => {
|
|
210
|
+
export const makeUrl = (url: string, params: UrlParams, hash: Option.Option<string>): Either.Either<URL, Error> => {
|
|
211
211
|
try {
|
|
212
212
|
const urlInstance = new URL(url, baseUrl())
|
|
213
213
|
for (let i = 0; i < params.length; i++) {
|
|
@@ -216,7 +216,9 @@ export const makeUrl = (url: string, params: UrlParams): Either.Either<URL, Erro
|
|
|
216
216
|
urlInstance.searchParams.append(key, value)
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
if (hash._tag === "Some") {
|
|
220
|
+
urlInstance.hash = hash.value
|
|
221
|
+
}
|
|
220
222
|
return Either.right(urlInstance)
|
|
221
223
|
} catch (e) {
|
|
222
224
|
return Either.left(e as Error)
|
package/src/Worker.ts
CHANGED
|
@@ -108,7 +108,6 @@ export declare namespace Worker {
|
|
|
108
108
|
readonly transfers?: ((message: I) => ReadonlyArray<unknown>) | undefined
|
|
109
109
|
readonly queue?: WorkerQueue<I> | undefined
|
|
110
110
|
readonly initialMessage?: LazyArg<I> | undefined
|
|
111
|
-
readonly permits?: number | undefined
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
/**
|
|
@@ -157,10 +156,21 @@ export declare namespace WorkerPool {
|
|
|
157
156
|
* @since 1.0.0
|
|
158
157
|
* @category models
|
|
159
158
|
*/
|
|
160
|
-
export
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
export type Options<I> =
|
|
160
|
+
& Worker.Options<I>
|
|
161
|
+
& ({
|
|
162
|
+
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
163
|
+
readonly size: number
|
|
164
|
+
readonly concurrency?: number | undefined
|
|
165
|
+
readonly targetUtilization?: number | undefined
|
|
166
|
+
} | {
|
|
167
|
+
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
168
|
+
readonly minSize: number
|
|
169
|
+
readonly maxSize: number
|
|
170
|
+
readonly concurrency?: number | undefined
|
|
171
|
+
readonly targetUtilization?: number | undefined
|
|
172
|
+
readonly timeToLive: Duration.DurationInput
|
|
173
|
+
})
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
/**
|
|
@@ -270,7 +280,6 @@ export declare namespace SerializedWorker {
|
|
|
270
280
|
* @category models
|
|
271
281
|
*/
|
|
272
282
|
export interface BaseOptions<I> {
|
|
273
|
-
readonly permits?: number | undefined
|
|
274
283
|
readonly queue?: WorkerQueue<I> | undefined
|
|
275
284
|
}
|
|
276
285
|
}
|
|
@@ -312,10 +321,14 @@ export declare namespace SerializedWorkerPool {
|
|
|
312
321
|
& ({
|
|
313
322
|
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
314
323
|
readonly size: number
|
|
324
|
+
readonly concurrency?: number | undefined
|
|
325
|
+
readonly targetUtilization?: number | undefined
|
|
315
326
|
} | {
|
|
316
327
|
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
317
328
|
readonly minSize: number
|
|
318
329
|
readonly maxSize: number
|
|
330
|
+
readonly concurrency?: number | undefined
|
|
331
|
+
readonly targetUtilization?: number | undefined
|
|
319
332
|
readonly timeToLive: Duration.DurationInput
|
|
320
333
|
})
|
|
321
334
|
}
|
|
@@ -126,7 +126,7 @@ export const makeDefault = (
|
|
|
126
126
|
const scope = Context.unsafeGet(fiber.getFiberRef(FiberRef.currentContext), Scope.Scope)
|
|
127
127
|
const controller = new AbortController()
|
|
128
128
|
const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort()))
|
|
129
|
-
const urlResult = UrlParams.makeUrl(request.url, request.urlParams)
|
|
129
|
+
const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash)
|
|
130
130
|
if (urlResult._tag === "Left") {
|
|
131
131
|
return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl", error: urlResult.left }))
|
|
132
132
|
}
|
|
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect"
|
|
|
5
5
|
import * as Effectable from "effect/Effectable"
|
|
6
6
|
import { dual } from "effect/Function"
|
|
7
7
|
import * as Inspectable from "effect/Inspectable"
|
|
8
|
+
import * as Option from "effect/Option"
|
|
8
9
|
import type * as Stream from "effect/Stream"
|
|
9
10
|
import type * as PlatformError from "../../Error.js"
|
|
10
11
|
import type * as FileSystem from "../../FileSystem.js"
|
|
@@ -35,6 +36,7 @@ const Proto = {
|
|
|
35
36
|
method: this.method,
|
|
36
37
|
url: this.url,
|
|
37
38
|
urlParams: this.urlParams,
|
|
39
|
+
hash: this.hash,
|
|
38
40
|
headers: this.headers,
|
|
39
41
|
body: this.body.toJSON()
|
|
40
42
|
}
|
|
@@ -45,6 +47,7 @@ function makeInternal(
|
|
|
45
47
|
method: Method,
|
|
46
48
|
url: string,
|
|
47
49
|
urlParams: UrlParams.UrlParams,
|
|
50
|
+
hash: Option.Option<string>,
|
|
48
51
|
headers: Headers.Headers,
|
|
49
52
|
body: Body.Body
|
|
50
53
|
): ClientRequest.ClientRequest {
|
|
@@ -52,6 +55,7 @@ function makeInternal(
|
|
|
52
55
|
self.method = method
|
|
53
56
|
self.url = url
|
|
54
57
|
self.urlParams = urlParams
|
|
58
|
+
self.hash = hash
|
|
55
59
|
self.headers = headers
|
|
56
60
|
self.body = body
|
|
57
61
|
return self
|
|
@@ -66,6 +70,7 @@ export const empty: ClientRequest.ClientRequest = makeInternal(
|
|
|
66
70
|
"GET",
|
|
67
71
|
"",
|
|
68
72
|
UrlParams.empty,
|
|
73
|
+
Option.none(),
|
|
69
74
|
Headers.empty,
|
|
70
75
|
internalBody.empty
|
|
71
76
|
)
|
|
@@ -78,7 +83,7 @@ export const make = <M extends Method>(method: M) =>
|
|
|
78
83
|
) =>
|
|
79
84
|
modify(empty, {
|
|
80
85
|
method,
|
|
81
|
-
url
|
|
86
|
+
url,
|
|
82
87
|
...(options ?? undefined)
|
|
83
88
|
})
|
|
84
89
|
|
|
@@ -122,6 +127,9 @@ export const modify = dual<
|
|
|
122
127
|
if (options.urlParams) {
|
|
123
128
|
result = setUrlParams(result, options.urlParams)
|
|
124
129
|
}
|
|
130
|
+
if (options.hash) {
|
|
131
|
+
result = setHash(result, options.hash)
|
|
132
|
+
}
|
|
125
133
|
if (options.body) {
|
|
126
134
|
result = setBody(result, options.body)
|
|
127
135
|
}
|
|
@@ -144,6 +152,7 @@ export const setHeader = dual<
|
|
|
144
152
|
self.method,
|
|
145
153
|
self.url,
|
|
146
154
|
self.urlParams,
|
|
155
|
+
self.hash,
|
|
147
156
|
Headers.set(self.headers, key, value),
|
|
148
157
|
self.body
|
|
149
158
|
))
|
|
@@ -157,6 +166,7 @@ export const setHeaders = dual<
|
|
|
157
166
|
self.method,
|
|
158
167
|
self.url,
|
|
159
168
|
self.urlParams,
|
|
169
|
+
self.hash,
|
|
160
170
|
Headers.setAll(self.headers, input),
|
|
161
171
|
self.body
|
|
162
172
|
))
|
|
@@ -191,6 +201,7 @@ export const setMethod = dual<
|
|
|
191
201
|
method,
|
|
192
202
|
self.url,
|
|
193
203
|
self.urlParams,
|
|
204
|
+
self.hash,
|
|
194
205
|
self.headers,
|
|
195
206
|
self.body
|
|
196
207
|
))
|
|
@@ -198,15 +209,32 @@ export const setMethod = dual<
|
|
|
198
209
|
/** @internal */
|
|
199
210
|
export const setUrl = dual<
|
|
200
211
|
(url: string | URL) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
201
|
-
(self: ClientRequest.ClientRequest, url: string) => ClientRequest.ClientRequest
|
|
202
|
-
>(2, (self, url) =>
|
|
203
|
-
|
|
212
|
+
(self: ClientRequest.ClientRequest, url: string | URL) => ClientRequest.ClientRequest
|
|
213
|
+
>(2, (self, url) => {
|
|
214
|
+
if (typeof url === "string") {
|
|
215
|
+
return makeInternal(
|
|
216
|
+
self.method,
|
|
217
|
+
url,
|
|
218
|
+
self.urlParams,
|
|
219
|
+
self.hash,
|
|
220
|
+
self.headers,
|
|
221
|
+
self.body
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
const clone = new URL(url.toString())
|
|
225
|
+
const urlParams = UrlParams.fromInput(clone.searchParams)
|
|
226
|
+
const hash = clone.hash ? Option.some(clone.hash.slice(1)) : Option.none()
|
|
227
|
+
clone.search = ""
|
|
228
|
+
clone.hash = ""
|
|
229
|
+
return makeInternal(
|
|
204
230
|
self.method,
|
|
205
|
-
|
|
206
|
-
|
|
231
|
+
clone.toString(),
|
|
232
|
+
urlParams,
|
|
233
|
+
hash,
|
|
207
234
|
self.headers,
|
|
208
235
|
self.body
|
|
209
|
-
)
|
|
236
|
+
)
|
|
237
|
+
})
|
|
210
238
|
|
|
211
239
|
/** @internal */
|
|
212
240
|
export const appendUrl = dual<
|
|
@@ -215,21 +243,27 @@ export const appendUrl = dual<
|
|
|
215
243
|
>(2, (self, url) =>
|
|
216
244
|
makeInternal(
|
|
217
245
|
self.method,
|
|
218
|
-
self.url
|
|
246
|
+
self.url.endsWith("/") && url.startsWith("/") ?
|
|
247
|
+
self.url + url.slice(1) :
|
|
248
|
+
self.url + url,
|
|
219
249
|
self.urlParams,
|
|
250
|
+
self.hash,
|
|
220
251
|
self.headers,
|
|
221
252
|
self.body
|
|
222
253
|
))
|
|
223
254
|
|
|
224
255
|
/** @internal */
|
|
225
256
|
export const prependUrl = dual<
|
|
226
|
-
(path: string
|
|
257
|
+
(path: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
227
258
|
(self: ClientRequest.ClientRequest, path: string) => ClientRequest.ClientRequest
|
|
228
259
|
>(2, (self, url) =>
|
|
229
260
|
makeInternal(
|
|
230
261
|
self.method,
|
|
231
|
-
url.
|
|
262
|
+
url.endsWith("/") && self.url.startsWith("/") ?
|
|
263
|
+
url + self.url.slice(1) :
|
|
264
|
+
url + self.url,
|
|
232
265
|
self.urlParams,
|
|
266
|
+
self.hash,
|
|
233
267
|
self.headers,
|
|
234
268
|
self.body
|
|
235
269
|
))
|
|
@@ -243,6 +277,7 @@ export const updateUrl = dual<
|
|
|
243
277
|
self.method,
|
|
244
278
|
f(self.url),
|
|
245
279
|
self.urlParams,
|
|
280
|
+
self.hash,
|
|
246
281
|
self.headers,
|
|
247
282
|
self.body
|
|
248
283
|
))
|
|
@@ -256,6 +291,7 @@ export const appendUrlParam = dual<
|
|
|
256
291
|
self.method,
|
|
257
292
|
self.url,
|
|
258
293
|
UrlParams.append(self.urlParams, key, value),
|
|
294
|
+
self.hash,
|
|
259
295
|
self.headers,
|
|
260
296
|
self.body
|
|
261
297
|
))
|
|
@@ -269,6 +305,7 @@ export const appendUrlParams = dual<
|
|
|
269
305
|
self.method,
|
|
270
306
|
self.url,
|
|
271
307
|
UrlParams.appendAll(self.urlParams, input),
|
|
308
|
+
self.hash,
|
|
272
309
|
self.headers,
|
|
273
310
|
self.body
|
|
274
311
|
))
|
|
@@ -282,6 +319,7 @@ export const setUrlParam = dual<
|
|
|
282
319
|
self.method,
|
|
283
320
|
self.url,
|
|
284
321
|
UrlParams.set(self.urlParams, key, value),
|
|
322
|
+
self.hash,
|
|
285
323
|
self.headers,
|
|
286
324
|
self.body
|
|
287
325
|
))
|
|
@@ -295,10 +333,36 @@ export const setUrlParams = dual<
|
|
|
295
333
|
self.method,
|
|
296
334
|
self.url,
|
|
297
335
|
UrlParams.setAll(self.urlParams, input),
|
|
336
|
+
self.hash,
|
|
298
337
|
self.headers,
|
|
299
338
|
self.body
|
|
300
339
|
))
|
|
301
340
|
|
|
341
|
+
/** @internal */
|
|
342
|
+
export const setHash = dual<
|
|
343
|
+
(hash: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
344
|
+
(self: ClientRequest.ClientRequest, hash: string) => ClientRequest.ClientRequest
|
|
345
|
+
>(2, (self, hash) =>
|
|
346
|
+
makeInternal(
|
|
347
|
+
self.method,
|
|
348
|
+
self.url,
|
|
349
|
+
self.urlParams,
|
|
350
|
+
Option.some(hash),
|
|
351
|
+
self.headers,
|
|
352
|
+
self.body
|
|
353
|
+
))
|
|
354
|
+
|
|
355
|
+
/** @internal */
|
|
356
|
+
export const removeHash = (self: ClientRequest.ClientRequest): ClientRequest.ClientRequest =>
|
|
357
|
+
makeInternal(
|
|
358
|
+
self.method,
|
|
359
|
+
self.url,
|
|
360
|
+
self.urlParams,
|
|
361
|
+
Option.none(),
|
|
362
|
+
self.headers,
|
|
363
|
+
self.body
|
|
364
|
+
)
|
|
365
|
+
|
|
302
366
|
/** @internal */
|
|
303
367
|
export const setBody = dual<
|
|
304
368
|
(body: Body.Body) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
@@ -322,6 +386,7 @@ export const setBody = dual<
|
|
|
322
386
|
self.method,
|
|
323
387
|
self.url,
|
|
324
388
|
self.urlParams,
|
|
389
|
+
self.hash,
|
|
325
390
|
headers,
|
|
326
391
|
body
|
|
327
392
|
)
|
package/src/internal/worker.ts
CHANGED
|
@@ -67,7 +67,6 @@ export const makeManager = Effect.gen(function*() {
|
|
|
67
67
|
spawn<I, O, E>({
|
|
68
68
|
encode,
|
|
69
69
|
initialMessage,
|
|
70
|
-
permits = 1,
|
|
71
70
|
queue,
|
|
72
71
|
transfers = (_) => []
|
|
73
72
|
}: Worker.Worker.Options<I>) {
|
|
@@ -75,7 +74,6 @@ export const makeManager = Effect.gen(function*() {
|
|
|
75
74
|
const spawn = yield* _(Spawner)
|
|
76
75
|
const id = idCounter++
|
|
77
76
|
let requestIdCounter = 0
|
|
78
|
-
const semaphore = Effect.unsafeMakeSemaphore(permits)
|
|
79
77
|
const requestMap = new Map<
|
|
80
78
|
number,
|
|
81
79
|
readonly [Queue.Queue<Exit.Exit<ReadonlyArray<O>, E | WorkerError>>, Deferred.Deferred<void>]
|
|
@@ -237,10 +235,9 @@ export const makeManager = Effect.gen(function*() {
|
|
|
237
235
|
executeRelease
|
|
238
236
|
)
|
|
239
237
|
|
|
240
|
-
yield*
|
|
241
|
-
Effect.andThen(outbound.take),
|
|
238
|
+
yield* outbound.take.pipe(
|
|
242
239
|
Effect.flatMap(([id, request, span]) =>
|
|
243
|
-
|
|
240
|
+
Effect.fork(
|
|
244
241
|
Effect.suspend(() => {
|
|
245
242
|
const result = requestMap.get(id)
|
|
246
243
|
if (!result) return Effect.void
|
|
@@ -260,14 +257,12 @@ export const makeManager = Effect.gen(function*() {
|
|
|
260
257
|
Effect.catchAllCause((cause) => Queue.offer(result[0], Exit.failCause(cause))),
|
|
261
258
|
Effect.zipRight(Deferred.await(result[1]))
|
|
262
259
|
)
|
|
263
|
-
})
|
|
264
|
-
Effect.ensuring(semaphore.release(1)),
|
|
265
|
-
Effect.fork
|
|
260
|
+
})
|
|
266
261
|
)
|
|
267
262
|
),
|
|
268
263
|
Effect.forever,
|
|
269
|
-
Effect.
|
|
270
|
-
Effect.
|
|
264
|
+
Effect.forkScoped,
|
|
265
|
+
Effect.interruptible
|
|
271
266
|
)
|
|
272
267
|
|
|
273
268
|
if (initialMessage) {
|
|
@@ -299,11 +294,21 @@ export const makePool = <I, O, E>(
|
|
|
299
294
|
Effect.tap((worker) => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))),
|
|
300
295
|
options.onCreate ? Effect.tap(options.onCreate) : identity
|
|
301
296
|
)
|
|
302
|
-
const backing =
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
const backing = "minSize" in options ?
|
|
298
|
+
yield* Pool.makeWithTTL({
|
|
299
|
+
acquire,
|
|
300
|
+
min: options.minSize,
|
|
301
|
+
max: options.maxSize,
|
|
302
|
+
concurrency: options.concurrency,
|
|
303
|
+
targetUtilization: options.targetUtilization,
|
|
304
|
+
timeToLive: options.timeToLive
|
|
305
|
+
}) :
|
|
306
|
+
yield* Pool.make({
|
|
307
|
+
acquire,
|
|
308
|
+
size: options.size,
|
|
309
|
+
concurrency: options.concurrency,
|
|
310
|
+
targetUtilization: options.targetUtilization
|
|
311
|
+
})
|
|
307
312
|
const pool: Worker.WorkerPool<I, O, E> = {
|
|
308
313
|
backing,
|
|
309
314
|
broadcast: (message: I) =>
|
|
@@ -311,12 +316,20 @@ export const makePool = <I, O, E>(
|
|
|
311
316
|
concurrency: "unbounded",
|
|
312
317
|
discard: true
|
|
313
318
|
}),
|
|
314
|
-
execute: (message: I) =>
|
|
315
|
-
|
|
319
|
+
execute: (message: I) =>
|
|
320
|
+
Stream.unwrapScoped(Effect.map(
|
|
321
|
+
backing.get,
|
|
322
|
+
(worker) => worker.execute(message)
|
|
323
|
+
)),
|
|
324
|
+
executeEffect: (message: I) =>
|
|
325
|
+
Effect.scoped(Effect.flatMap(
|
|
326
|
+
backing.get,
|
|
327
|
+
(worker) => worker.executeEffect(message)
|
|
328
|
+
))
|
|
316
329
|
}
|
|
317
330
|
|
|
318
331
|
// report any spawn errors
|
|
319
|
-
yield* get
|
|
332
|
+
yield* Effect.scoped(backing.get)
|
|
320
333
|
|
|
321
334
|
return pool
|
|
322
335
|
})
|
|
@@ -391,13 +404,16 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
|
|
|
391
404
|
acquire,
|
|
392
405
|
min: options.minSize,
|
|
393
406
|
max: options.maxSize,
|
|
407
|
+
concurrency: options.concurrency,
|
|
408
|
+
targetUtilization: options.targetUtilization,
|
|
394
409
|
timeToLive: options.timeToLive
|
|
395
410
|
}) :
|
|
396
411
|
Pool.make({
|
|
397
412
|
acquire,
|
|
398
|
-
size: options.size
|
|
413
|
+
size: options.size,
|
|
414
|
+
concurrency: options.concurrency,
|
|
415
|
+
targetUtilization: options.targetUtilization
|
|
399
416
|
})
|
|
400
|
-
const get = Effect.scoped(backing.get)
|
|
401
417
|
const pool: Worker.SerializedWorkerPool<I> = {
|
|
402
418
|
backing,
|
|
403
419
|
broadcast: <Req extends I>(message: Req) =>
|
|
@@ -406,13 +422,13 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
|
|
|
406
422
|
discard: true
|
|
407
423
|
}) as any,
|
|
408
424
|
execute: <Req extends I>(message: Req) =>
|
|
409
|
-
Stream.
|
|
425
|
+
Stream.unwrapScoped(Effect.map(backing.get, (worker) => worker.execute(message))) as any,
|
|
410
426
|
executeEffect: <Req extends I>(message: Req) =>
|
|
411
|
-
Effect.flatMap(get, (worker) => worker.executeEffect(message)) as any
|
|
427
|
+
Effect.scoped(Effect.flatMap(backing.get, (worker) => worker.executeEffect(message))) as any
|
|
412
428
|
}
|
|
413
429
|
|
|
414
430
|
// report any spawn errors
|
|
415
|
-
yield* get
|
|
431
|
+
yield* Effect.scoped(backing.get)
|
|
416
432
|
|
|
417
433
|
return pool
|
|
418
434
|
})
|