@effect/platform
Advanced tools
Comparing version 0.55.7 to 0.56.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.head = exports.get = exports.formDataBody = exports.fileWebBody = exports.fileBody = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0; | ||
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setHash = exports.setBody = exports.schemaBody = exports.removeHash = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.head = exports.get = exports.formDataBody = exports.fileWebBody = exports.fileBody = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../internal/http/clientRequest.js")); | ||
@@ -163,2 +163,12 @@ function _getRequireWildcardCache(e) { | ||
*/ | ||
const setHash = exports.setHash = internal.setHash; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
const removeHash = exports.removeHash = internal.removeHash; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
const setBody = exports.setBody = internal.setBody; | ||
@@ -165,0 +175,0 @@ /** |
@@ -13,3 +13,3 @@ "use strict"; | ||
var Record = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Record")); | ||
var Secret = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Secret")); | ||
var Redacted = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Redacted")); | ||
var String = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/String")); | ||
@@ -169,3 +169,3 @@ function _getRequireWildcardCache(e) { | ||
if (k in self) { | ||
out[k] = Secret.fromString(self[k]); | ||
out[k] = Redacted.make(self[k]); | ||
} | ||
@@ -175,3 +175,3 @@ } else { | ||
if (key.test(name)) { | ||
out[name] = Secret.fromString(self[name]); | ||
out[name] = Redacted.make(self[name]); | ||
} | ||
@@ -178,0 +178,0 @@ } |
@@ -127,3 +127,3 @@ "use strict"; | ||
exports.toString = toString; | ||
const makeUrl = (url, params) => { | ||
const makeUrl = (url, params, hash) => { | ||
try { | ||
@@ -137,2 +137,5 @@ const urlInstance = new URL(url, baseUrl()); | ||
} | ||
if (hash._tag === "Some") { | ||
urlInstance.hash = hash.value; | ||
} | ||
return Either.right(urlInstance); | ||
@@ -139,0 +142,0 @@ } catch (e) { |
@@ -92,3 +92,3 @@ "use strict"; | ||
const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort())); | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams); | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash); | ||
if (urlResult._tag === "Left") { | ||
@@ -95,0 +95,0 @@ return Effect.fail(new Error.RequestError({ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.isClientRequest = exports.head = exports.get = exports.formDataBody = exports.fileWebBody = exports.fileBody = exports.empty = exports.del = exports.clientTag = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0; | ||
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setHash = exports.setBody = exports.schemaBody = exports.removeHash = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.isClientRequest = exports.head = exports.get = exports.formDataBody = exports.fileWebBody = exports.fileBody = exports.empty = exports.del = exports.clientTag = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0; | ||
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context")); | ||
@@ -13,2 +13,3 @@ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect")); | ||
var Inspectable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Inspectable")); | ||
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option")); | ||
var Headers = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../Http/Headers.js")); | ||
@@ -59,2 +60,3 @@ var UrlParams = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../Http/UrlParams.js")); | ||
urlParams: this.urlParams, | ||
hash: this.hash, | ||
headers: this.headers, | ||
@@ -65,3 +67,3 @@ body: this.body.toJSON() | ||
}; | ||
function makeInternal(method, url, urlParams, headers, body) { | ||
function makeInternal(method, url, urlParams, hash, headers, body) { | ||
const self = Object.create(Proto); | ||
@@ -71,2 +73,3 @@ self.method = method; | ||
self.urlParams = urlParams; | ||
self.hash = hash; | ||
self.headers = headers; | ||
@@ -80,7 +83,7 @@ self.body = body; | ||
exports.isClientRequest = isClientRequest; | ||
const empty = exports.empty = /*#__PURE__*/makeInternal("GET", "", UrlParams.empty, Headers.empty, internalBody.empty); | ||
const empty = exports.empty = /*#__PURE__*/makeInternal("GET", "", UrlParams.empty, /*#__PURE__*/Option.none(), Headers.empty, internalBody.empty); | ||
/** @internal */ | ||
const make = method => (url, options) => modify(empty, { | ||
method, | ||
url: url.toString(), | ||
url, | ||
...(options ?? undefined) | ||
@@ -118,2 +121,5 @@ }); | ||
} | ||
if (options.hash) { | ||
result = setHash(result, options.hash); | ||
} | ||
if (options.body) { | ||
@@ -131,5 +137,5 @@ result = setBody(result, options.body); | ||
/** @internal */ | ||
const setHeader = exports.setHeader = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, self.urlParams, Headers.set(self.headers, key, value), self.body)); | ||
const setHeader = exports.setHeader = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, self.urlParams, self.hash, Headers.set(self.headers, key, value), self.body)); | ||
/** @internal */ | ||
const setHeaders = exports.setHeaders = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, self.urlParams, Headers.setAll(self.headers, input), self.body)); | ||
const setHeaders = exports.setHeaders = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, self.urlParams, self.hash, Headers.setAll(self.headers, input), self.body)); | ||
/** @internal */ | ||
@@ -144,20 +150,35 @@ const basicAuth = exports.basicAuth = /*#__PURE__*/(0, _Function.dual)(3, (self, username, password) => setHeader(self, "Authorization", `Basic ${btoa(`${username}:${password}`)}`)); | ||
/** @internal */ | ||
const setMethod = exports.setMethod = /*#__PURE__*/(0, _Function.dual)(2, (self, method) => makeInternal(method, self.url, self.urlParams, self.headers, self.body)); | ||
const setMethod = exports.setMethod = /*#__PURE__*/(0, _Function.dual)(2, (self, method) => makeInternal(method, self.url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const setUrl = exports.setUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => makeInternal(self.method, url.toString(), self.urlParams, self.headers, self.body)); | ||
const setUrl = exports.setUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => { | ||
if (typeof url === "string") { | ||
return makeInternal(self.method, url, self.urlParams, self.hash, self.headers, self.body); | ||
} | ||
const clone = new URL(url.toString()); | ||
const urlParams = UrlParams.fromInput(clone.searchParams); | ||
const hash = clone.hash ? Option.some(clone.hash.slice(1)) : Option.none(); | ||
clone.search = ""; | ||
clone.hash = ""; | ||
return makeInternal(self.method, clone.toString(), urlParams, hash, self.headers, self.body); | ||
}); | ||
/** @internal */ | ||
const appendUrl = exports.appendUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => makeInternal(self.method, self.url + url, self.urlParams, self.headers, self.body)); | ||
const appendUrl = exports.appendUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => makeInternal(self.method, self.url.endsWith("/") && url.startsWith("/") ? self.url + url.slice(1) : self.url + url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const prependUrl = exports.prependUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => makeInternal(self.method, url.toString() + self.url, self.urlParams, self.headers, self.body)); | ||
const prependUrl = exports.prependUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, url) => makeInternal(self.method, url.endsWith("/") && self.url.startsWith("/") ? url + self.url.slice(1) : url + self.url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const updateUrl = exports.updateUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => makeInternal(self.method, f(self.url), self.urlParams, self.headers, self.body)); | ||
const updateUrl = exports.updateUrl = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => makeInternal(self.method, f(self.url), self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const appendUrlParam = exports.appendUrlParam = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.append(self.urlParams, key, value), self.headers, self.body)); | ||
const appendUrlParam = exports.appendUrlParam = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.append(self.urlParams, key, value), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const appendUrlParams = exports.appendUrlParams = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, UrlParams.appendAll(self.urlParams, input), self.headers, self.body)); | ||
const appendUrlParams = exports.appendUrlParams = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, UrlParams.appendAll(self.urlParams, input), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const setUrlParam = exports.setUrlParam = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.set(self.urlParams, key, value), self.headers, self.body)); | ||
const setUrlParam = exports.setUrlParam = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.set(self.urlParams, key, value), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const setUrlParams = exports.setUrlParams = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, UrlParams.setAll(self.urlParams, input), self.headers, self.body)); | ||
const setUrlParams = exports.setUrlParams = /*#__PURE__*/(0, _Function.dual)(2, (self, input) => makeInternal(self.method, self.url, UrlParams.setAll(self.urlParams, input), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
const setHash = exports.setHash = /*#__PURE__*/(0, _Function.dual)(2, (self, hash) => makeInternal(self.method, self.url, self.urlParams, Option.some(hash), self.headers, self.body)); | ||
/** @internal */ | ||
const removeHash = self => makeInternal(self.method, self.url, self.urlParams, Option.none(), self.headers, self.body); | ||
/** @internal */ | ||
exports.removeHash = removeHash; | ||
const setBody = exports.setBody = /*#__PURE__*/(0, _Function.dual)(2, (self, body) => { | ||
@@ -177,3 +198,3 @@ let headers = self.headers; | ||
} | ||
return makeInternal(self.method, self.url, self.urlParams, headers, body); | ||
return makeInternal(self.method, self.url, self.urlParams, self.hash, headers, body); | ||
}); | ||
@@ -180,0 +201,0 @@ /** @internal */ |
@@ -79,3 +79,2 @@ "use strict"; | ||
initialMessage, | ||
permits = 1, | ||
queue, | ||
@@ -88,3 +87,2 @@ transfers = _ => [] | ||
let requestIdCounter = 0; | ||
const semaphore = Effect.unsafeMakeSemaphore(permits); | ||
const requestMap = new Map(); | ||
@@ -154,3 +152,3 @@ const sendQueue = yield* Effect.acquireRelease(Queue.unbounded(), Queue.shutdown); | ||
const executeEffect = request => Effect.acquireUseRelease(executeAcquire(request), ([, queue]) => Effect.flatMap(Queue.take(queue), Exit.map(Arr.unsafeGet(0))), executeRelease); | ||
yield* semaphore.take(1).pipe(Effect.andThen(outbound.take), Effect.flatMap(([id, request, span]) => (0, _Function.pipe)(Effect.suspend(() => { | ||
yield* outbound.take.pipe(Effect.flatMap(([id, request, span]) => Effect.fork(Effect.suspend(() => { | ||
const result = requestMap.get(id); | ||
@@ -161,3 +159,3 @@ if (!result) return Effect.void; | ||
return (0, _Function.pipe)(Effect.flatMap(wrappedEncode(request), payload => sendQueue.offer([[id, 0, payload, spanTuple], [...transferables, ...collector.unsafeRead()]])), Effect.catchAllCause(cause => Queue.offer(result[0], Exit.failCause(cause))), Effect.zipRight(Deferred.await(result[1]))); | ||
}), Effect.ensuring(semaphore.release(1)), Effect.fork)), Effect.forever, Effect.interruptible, Effect.forkScoped); | ||
}))), Effect.forever, Effect.forkScoped, Effect.interruptible); | ||
if (initialMessage) { | ||
@@ -185,7 +183,15 @@ yield* Effect.sync(initialMessage).pipe(Effect.flatMap(executeEffect), Effect.mapError(error => new _WorkerError.WorkerError({ | ||
const acquire = (0, _Function.pipe)(manager.spawn(options), Effect.tap(worker => Effect.sync(() => workers.add(worker))), Effect.tap(worker => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))), options.onCreate ? Effect.tap(options.onCreate) : _Function.identity); | ||
const backing = yield* Pool.make({ | ||
const backing = "minSize" in options ? yield* Pool.makeWithTTL({ | ||
acquire, | ||
size: options.size | ||
min: options.minSize, | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
}) : yield* Pool.make({ | ||
acquire, | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}); | ||
const get = Effect.scoped(backing.get); | ||
const pool = { | ||
@@ -197,7 +203,7 @@ backing, | ||
}), | ||
execute: message => Stream.unwrap(Effect.map(get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.flatMap(get, worker => worker.executeEffect(message)) | ||
execute: message => Stream.unwrapScoped(Effect.map(backing.get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.scoped(Effect.flatMap(backing.get, worker => worker.executeEffect(message))) | ||
}; | ||
// report any spawn errors | ||
yield* get; | ||
yield* Effect.scoped(backing.get); | ||
return pool; | ||
@@ -250,8 +256,11 @@ }); | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
}) : Pool.make({ | ||
acquire, | ||
size: options.size | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}); | ||
const get = Effect.scoped(backing.get); | ||
const pool = { | ||
@@ -263,7 +272,7 @@ backing, | ||
}), | ||
execute: message => Stream.unwrap(Effect.map(get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.flatMap(get, worker => worker.executeEffect(message)) | ||
execute: message => Stream.unwrapScoped(Effect.map(backing.get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.scoped(Effect.flatMap(backing.get, worker => worker.executeEffect(message))) | ||
}; | ||
// report any spawn errors | ||
yield* get; | ||
yield* Effect.scoped(backing.get); | ||
return pool; | ||
@@ -270,0 +279,0 @@ }); |
@@ -8,2 +8,3 @@ /** | ||
import type { Inspectable } from "effect/Inspectable"; | ||
import type * as Option from "effect/Option"; | ||
import type { Scope } from "effect/Scope"; | ||
@@ -39,2 +40,3 @@ import type * as Stream from "effect/Stream"; | ||
readonly urlParams: UrlParams.UrlParams; | ||
readonly hash: Option.Option<string>; | ||
readonly headers: Headers.Headers; | ||
@@ -49,4 +51,5 @@ readonly body: Body.Body; | ||
readonly method?: Method | undefined; | ||
readonly url?: string | undefined; | ||
readonly url?: string | URL | undefined; | ||
readonly urlParams?: UrlParams.Input | undefined; | ||
readonly hash?: string | undefined; | ||
readonly headers?: Headers.Input | undefined; | ||
@@ -181,3 +184,3 @@ readonly body?: Body.Body | undefined; | ||
(url: string | URL): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, url: string): ClientRequest; | ||
(self: ClientRequest, url: string | URL): ClientRequest; | ||
}; | ||
@@ -189,3 +192,3 @@ /** | ||
export declare const prependUrl: { | ||
(path: string | URL): (self: ClientRequest) => ClientRequest; | ||
(path: string): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, path: string): ClientRequest; | ||
@@ -213,3 +216,6 @@ }; | ||
*/ | ||
export declare const setUrlParam: ((key: string, value: string) => (self: ClientRequest) => ClientRequest) & ((self: ClientRequest, key: string, value: string) => ClientRequest); | ||
export declare const setUrlParam: { | ||
(key: string, value: string): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, key: string, value: string): ClientRequest; | ||
}; | ||
/** | ||
@@ -219,3 +225,6 @@ * @since 1.0.0 | ||
*/ | ||
export declare const setUrlParams: ((input: UrlParams.Input) => (self: ClientRequest) => ClientRequest) & ((self: ClientRequest, input: UrlParams.Input) => ClientRequest); | ||
export declare const setUrlParams: { | ||
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, input: UrlParams.Input): ClientRequest; | ||
}; | ||
/** | ||
@@ -225,3 +234,6 @@ * @since 1.0.0 | ||
*/ | ||
export declare const appendUrlParam: ((key: string, value: string) => (self: ClientRequest) => ClientRequest) & ((self: ClientRequest, key: string, value: string) => ClientRequest); | ||
export declare const appendUrlParam: { | ||
(key: string, value: string): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, key: string, value: string): ClientRequest; | ||
}; | ||
/** | ||
@@ -231,3 +243,6 @@ * @since 1.0.0 | ||
*/ | ||
export declare const appendUrlParams: ((input: UrlParams.Input) => (self: ClientRequest) => ClientRequest) & ((self: ClientRequest, input: UrlParams.Input) => ClientRequest); | ||
export declare const appendUrlParams: { | ||
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, input: UrlParams.Input): ClientRequest; | ||
}; | ||
/** | ||
@@ -237,2 +252,15 @@ * @since 1.0.0 | ||
*/ | ||
export declare const setHash: { | ||
(hash: string): (self: ClientRequest) => ClientRequest; | ||
(self: ClientRequest, hash: string): ClientRequest; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export declare const removeHash: (self: ClientRequest) => ClientRequest; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export declare const setBody: { | ||
@@ -239,0 +267,0 @@ (body: Body.Body): (self: ClientRequest) => ClientRequest; |
@@ -8,3 +8,3 @@ /** | ||
import * as Record from "effect/Record"; | ||
import * as Secret from "effect/Secret"; | ||
import * as Redacted from "effect/Redacted"; | ||
/** | ||
@@ -116,4 +116,4 @@ * @since 1.0.0 | ||
export declare const redact: { | ||
(key: string | RegExp | ReadonlyArray<string | RegExp>): (self: Headers) => Record<string, string | Secret.Secret>; | ||
(self: Headers, key: string | RegExp | ReadonlyArray<string | RegExp>): Record<string, string | Secret.Secret>; | ||
(key: string | RegExp | ReadonlyArray<string | RegExp>): (self: Headers) => Record<string, string | Redacted.Redacted>; | ||
(self: Headers, key: string | RegExp | ReadonlyArray<string | RegExp>): Record<string, string | Redacted.Redacted>; | ||
}; | ||
@@ -120,0 +120,0 @@ /** |
@@ -109,3 +109,3 @@ /** | ||
*/ | ||
export declare const makeUrl: (url: string, params: UrlParams) => Either.Either<URL, Error>; | ||
export declare const makeUrl: (url: string, params: UrlParams, hash: Option.Option<string>) => Either.Either<URL, Error>; | ||
/** | ||
@@ -112,0 +112,0 @@ * @since 1.0.0 |
@@ -100,3 +100,2 @@ /** | ||
readonly initialMessage?: LazyArg<I> | undefined; | ||
readonly permits?: number | undefined; | ||
} | ||
@@ -138,6 +137,15 @@ /** | ||
*/ | ||
interface Options<I> extends Worker.Options<I> { | ||
type Options<I> = Worker.Options<I> & ({ | ||
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>; | ||
readonly size: number; | ||
} | ||
readonly concurrency?: number | undefined; | ||
readonly targetUtilization?: number | undefined; | ||
} | { | ||
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>; | ||
readonly minSize: number; | ||
readonly maxSize: number; | ||
readonly concurrency?: number | undefined; | ||
readonly targetUtilization?: number | undefined; | ||
readonly timeToLive: Duration.DurationInput; | ||
}); | ||
} | ||
@@ -228,3 +236,2 @@ /** | ||
interface BaseOptions<I> { | ||
readonly permits?: number | undefined; | ||
readonly queue?: WorkerQueue<I> | undefined; | ||
@@ -255,2 +262,4 @@ } | ||
readonly size: number; | ||
readonly concurrency?: number | undefined; | ||
readonly targetUtilization?: number | undefined; | ||
} | { | ||
@@ -260,2 +269,4 @@ readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>; | ||
readonly maxSize: number; | ||
readonly concurrency?: number | undefined; | ||
readonly targetUtilization?: number | undefined; | ||
readonly timeToLive: Duration.DurationInput; | ||
@@ -262,0 +273,0 @@ }); |
@@ -131,2 +131,12 @@ import * as internal from "../internal/http/clientRequest.js"; | ||
*/ | ||
export const setHash = internal.setHash; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const removeHash = internal.removeHash; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const setBody = internal.setBody; | ||
@@ -133,0 +143,0 @@ /** |
@@ -10,3 +10,3 @@ /** | ||
import * as Record from "effect/Record"; | ||
import * as Secret from "effect/Secret"; | ||
import * as Redacted from "effect/Redacted"; | ||
import * as String from "effect/String"; | ||
@@ -134,3 +134,3 @@ /** | ||
if (k in self) { | ||
out[k] = Secret.fromString(self[k]); | ||
out[k] = Redacted.make(self[k]); | ||
} | ||
@@ -140,3 +140,3 @@ } else { | ||
if (key.test(name)) { | ||
out[name] = Secret.fromString(self[name]); | ||
out[name] = Redacted.make(self[name]); | ||
} | ||
@@ -143,0 +143,0 @@ } |
@@ -94,3 +94,3 @@ import * as Schema from "@effect/schema/Schema"; | ||
*/ | ||
export const makeUrl = (url, params) => { | ||
export const makeUrl = (url, params, hash) => { | ||
try { | ||
@@ -104,2 +104,5 @@ const urlInstance = new URL(url, baseUrl()); | ||
} | ||
if (hash._tag === "Some") { | ||
urlInstance.hash = hash.value; | ||
} | ||
return Either.right(urlInstance); | ||
@@ -106,0 +109,0 @@ } catch (e) { |
@@ -60,3 +60,3 @@ import * as Schema from "@effect/schema/Schema"; | ||
const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort())); | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams); | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash); | ||
if (urlResult._tag === "Left") { | ||
@@ -63,0 +63,0 @@ return Effect.fail(new Error.RequestError({ |
@@ -6,2 +6,3 @@ import * as Context from "effect/Context"; | ||
import * as Inspectable from "effect/Inspectable"; | ||
import * as Option from "effect/Option"; | ||
import * as Headers from "../../Http/Headers.js"; | ||
@@ -27,2 +28,3 @@ import * as UrlParams from "../../Http/UrlParams.js"; | ||
urlParams: this.urlParams, | ||
hash: this.hash, | ||
headers: this.headers, | ||
@@ -33,3 +35,3 @@ body: this.body.toJSON() | ||
}; | ||
function makeInternal(method, url, urlParams, headers, body) { | ||
function makeInternal(method, url, urlParams, hash, headers, body) { | ||
const self = Object.create(Proto); | ||
@@ -39,2 +41,3 @@ self.method = method; | ||
self.urlParams = urlParams; | ||
self.hash = hash; | ||
self.headers = headers; | ||
@@ -47,7 +50,7 @@ self.body = body; | ||
/** @internal */ | ||
export const empty = /*#__PURE__*/makeInternal("GET", "", UrlParams.empty, Headers.empty, internalBody.empty); | ||
export const empty = /*#__PURE__*/makeInternal("GET", "", UrlParams.empty, /*#__PURE__*/Option.none(), Headers.empty, internalBody.empty); | ||
/** @internal */ | ||
export const make = method => (url, options) => modify(empty, { | ||
method, | ||
url: url.toString(), | ||
url, | ||
...(options ?? undefined) | ||
@@ -84,2 +87,5 @@ }); | ||
} | ||
if (options.hash) { | ||
result = setHash(result, options.hash); | ||
} | ||
if (options.body) { | ||
@@ -97,5 +103,5 @@ result = setBody(result, options.body); | ||
/** @internal */ | ||
export const setHeader = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, self.urlParams, Headers.set(self.headers, key, value), self.body)); | ||
export const setHeader = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, self.urlParams, self.hash, Headers.set(self.headers, key, value), self.body)); | ||
/** @internal */ | ||
export const setHeaders = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, self.urlParams, Headers.setAll(self.headers, input), self.body)); | ||
export const setHeaders = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, self.urlParams, self.hash, Headers.setAll(self.headers, input), self.body)); | ||
/** @internal */ | ||
@@ -110,20 +116,34 @@ export const basicAuth = /*#__PURE__*/dual(3, (self, username, password) => setHeader(self, "Authorization", `Basic ${btoa(`${username}:${password}`)}`)); | ||
/** @internal */ | ||
export const setMethod = /*#__PURE__*/dual(2, (self, method) => makeInternal(method, self.url, self.urlParams, self.headers, self.body)); | ||
export const setMethod = /*#__PURE__*/dual(2, (self, method) => makeInternal(method, self.url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const setUrl = /*#__PURE__*/dual(2, (self, url) => makeInternal(self.method, url.toString(), self.urlParams, self.headers, self.body)); | ||
export const setUrl = /*#__PURE__*/dual(2, (self, url) => { | ||
if (typeof url === "string") { | ||
return makeInternal(self.method, url, self.urlParams, self.hash, self.headers, self.body); | ||
} | ||
const clone = new URL(url.toString()); | ||
const urlParams = UrlParams.fromInput(clone.searchParams); | ||
const hash = clone.hash ? Option.some(clone.hash.slice(1)) : Option.none(); | ||
clone.search = ""; | ||
clone.hash = ""; | ||
return makeInternal(self.method, clone.toString(), urlParams, hash, self.headers, self.body); | ||
}); | ||
/** @internal */ | ||
export const appendUrl = /*#__PURE__*/dual(2, (self, url) => makeInternal(self.method, self.url + url, self.urlParams, self.headers, self.body)); | ||
export const appendUrl = /*#__PURE__*/dual(2, (self, url) => makeInternal(self.method, self.url.endsWith("/") && url.startsWith("/") ? self.url + url.slice(1) : self.url + url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const prependUrl = /*#__PURE__*/dual(2, (self, url) => makeInternal(self.method, url.toString() + self.url, self.urlParams, self.headers, self.body)); | ||
export const prependUrl = /*#__PURE__*/dual(2, (self, url) => makeInternal(self.method, url.endsWith("/") && self.url.startsWith("/") ? url + self.url.slice(1) : url + self.url, self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const updateUrl = /*#__PURE__*/dual(2, (self, f) => makeInternal(self.method, f(self.url), self.urlParams, self.headers, self.body)); | ||
export const updateUrl = /*#__PURE__*/dual(2, (self, f) => makeInternal(self.method, f(self.url), self.urlParams, self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const appendUrlParam = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.append(self.urlParams, key, value), self.headers, self.body)); | ||
export const appendUrlParam = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.append(self.urlParams, key, value), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const appendUrlParams = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, UrlParams.appendAll(self.urlParams, input), self.headers, self.body)); | ||
export const appendUrlParams = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, UrlParams.appendAll(self.urlParams, input), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const setUrlParam = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.set(self.urlParams, key, value), self.headers, self.body)); | ||
export const setUrlParam = /*#__PURE__*/dual(3, (self, key, value) => makeInternal(self.method, self.url, UrlParams.set(self.urlParams, key, value), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const setUrlParams = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, UrlParams.setAll(self.urlParams, input), self.headers, self.body)); | ||
export const setUrlParams = /*#__PURE__*/dual(2, (self, input) => makeInternal(self.method, self.url, UrlParams.setAll(self.urlParams, input), self.hash, self.headers, self.body)); | ||
/** @internal */ | ||
export const setHash = /*#__PURE__*/dual(2, (self, hash) => makeInternal(self.method, self.url, self.urlParams, Option.some(hash), self.headers, self.body)); | ||
/** @internal */ | ||
export const removeHash = self => makeInternal(self.method, self.url, self.urlParams, Option.none(), self.headers, self.body); | ||
/** @internal */ | ||
export const setBody = /*#__PURE__*/dual(2, (self, body) => { | ||
@@ -143,3 +163,3 @@ let headers = self.headers; | ||
} | ||
return makeInternal(self.method, self.url, self.urlParams, headers, body); | ||
return makeInternal(self.method, self.url, self.urlParams, self.hash, headers, body); | ||
}); | ||
@@ -146,0 +166,0 @@ /** @internal */ |
@@ -47,3 +47,2 @@ import * as Schema from "@effect/schema/Schema"; | ||
initialMessage, | ||
permits = 1, | ||
queue, | ||
@@ -56,3 +55,2 @@ transfers = _ => [] | ||
let requestIdCounter = 0; | ||
const semaphore = Effect.unsafeMakeSemaphore(permits); | ||
const requestMap = new Map(); | ||
@@ -122,3 +120,3 @@ const sendQueue = yield* Effect.acquireRelease(Queue.unbounded(), Queue.shutdown); | ||
const executeEffect = request => Effect.acquireUseRelease(executeAcquire(request), ([, queue]) => Effect.flatMap(Queue.take(queue), Exit.map(Arr.unsafeGet(0))), executeRelease); | ||
yield* semaphore.take(1).pipe(Effect.andThen(outbound.take), Effect.flatMap(([id, request, span]) => pipe(Effect.suspend(() => { | ||
yield* outbound.take.pipe(Effect.flatMap(([id, request, span]) => Effect.fork(Effect.suspend(() => { | ||
const result = requestMap.get(id); | ||
@@ -129,3 +127,3 @@ if (!result) return Effect.void; | ||
return pipe(Effect.flatMap(wrappedEncode(request), payload => sendQueue.offer([[id, 0, payload, spanTuple], [...transferables, ...collector.unsafeRead()]])), Effect.catchAllCause(cause => Queue.offer(result[0], Exit.failCause(cause))), Effect.zipRight(Deferred.await(result[1]))); | ||
}), Effect.ensuring(semaphore.release(1)), Effect.fork)), Effect.forever, Effect.interruptible, Effect.forkScoped); | ||
}))), Effect.forever, Effect.forkScoped, Effect.interruptible); | ||
if (initialMessage) { | ||
@@ -153,7 +151,15 @@ yield* Effect.sync(initialMessage).pipe(Effect.flatMap(executeEffect), Effect.mapError(error => new WorkerError({ | ||
const acquire = pipe(manager.spawn(options), Effect.tap(worker => Effect.sync(() => workers.add(worker))), Effect.tap(worker => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))), options.onCreate ? Effect.tap(options.onCreate) : identity); | ||
const backing = yield* Pool.make({ | ||
const backing = "minSize" in options ? yield* Pool.makeWithTTL({ | ||
acquire, | ||
size: options.size | ||
min: options.minSize, | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
}) : yield* Pool.make({ | ||
acquire, | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}); | ||
const get = Effect.scoped(backing.get); | ||
const pool = { | ||
@@ -165,7 +171,7 @@ backing, | ||
}), | ||
execute: message => Stream.unwrap(Effect.map(get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.flatMap(get, worker => worker.executeEffect(message)) | ||
execute: message => Stream.unwrapScoped(Effect.map(backing.get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.scoped(Effect.flatMap(backing.get, worker => worker.executeEffect(message))) | ||
}; | ||
// report any spawn errors | ||
yield* get; | ||
yield* Effect.scoped(backing.get); | ||
return pool; | ||
@@ -215,8 +221,11 @@ }); | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
}) : Pool.make({ | ||
acquire, | ||
size: options.size | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}); | ||
const get = Effect.scoped(backing.get); | ||
const pool = { | ||
@@ -228,7 +237,7 @@ backing, | ||
}), | ||
execute: message => Stream.unwrap(Effect.map(get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.flatMap(get, worker => worker.executeEffect(message)) | ||
execute: message => Stream.unwrapScoped(Effect.map(backing.get, worker => worker.execute(message))), | ||
executeEffect: message => Effect.scoped(Effect.flatMap(backing.get, worker => worker.executeEffect(message))) | ||
}; | ||
// report any spawn errors | ||
yield* get; | ||
yield* Effect.scoped(backing.get); | ||
return pool; | ||
@@ -235,0 +244,0 @@ }); |
{ | ||
"name": "@effect/platform", | ||
"version": "0.55.7", | ||
"version": "0.56.0", | ||
"description": "Unified interfaces for common platform-specific services", | ||
@@ -18,4 +18,4 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@effect/schema": "^0.67.20", | ||
"effect": "^3.2.9" | ||
"@effect/schema": "^0.67.21", | ||
"effect": "^3.3.0" | ||
}, | ||
@@ -22,0 +22,0 @@ "publishConfig": { |
@@ -8,2 +8,3 @@ /** | ||
import type { Inspectable } from "effect/Inspectable" | ||
import type * as Option from "effect/Option" | ||
import type { Scope } from "effect/Scope" | ||
@@ -45,2 +46,3 @@ import type * as Stream from "effect/Stream" | ||
readonly urlParams: UrlParams.UrlParams | ||
readonly hash: Option.Option<string> | ||
readonly headers: Headers.Headers | ||
@@ -56,4 +58,5 @@ readonly body: Body.Body | ||
readonly method?: Method | undefined | ||
readonly url?: string | undefined | ||
readonly url?: string | URL | undefined | ||
readonly urlParams?: UrlParams.Input | undefined | ||
readonly hash?: string | undefined | ||
readonly headers?: Headers.Input | undefined | ||
@@ -210,3 +213,3 @@ readonly body?: Body.Body | undefined | ||
(url: string | URL): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, url: string): ClientRequest | ||
(self: ClientRequest, url: string | URL): ClientRequest | ||
} = internal.setUrl | ||
@@ -219,3 +222,3 @@ | ||
export const prependUrl: { | ||
(path: string | URL): (self: ClientRequest) => ClientRequest | ||
(path: string): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, path: string): ClientRequest | ||
@@ -246,3 +249,6 @@ } = internal.prependUrl | ||
*/ | ||
export const setUrlParam = internal.setUrlParam | ||
export const setUrlParam: { | ||
(key: string, value: string): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, key: string, value: string): ClientRequest | ||
} = internal.setUrlParam | ||
@@ -253,3 +259,6 @@ /** | ||
*/ | ||
export const setUrlParams = internal.setUrlParams | ||
export const setUrlParams: { | ||
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, input: UrlParams.Input): ClientRequest | ||
} = internal.setUrlParams | ||
@@ -260,3 +269,6 @@ /** | ||
*/ | ||
export const appendUrlParam = internal.appendUrlParam | ||
export const appendUrlParam: { | ||
(key: string, value: string): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, key: string, value: string): ClientRequest | ||
} = internal.appendUrlParam | ||
@@ -267,3 +279,6 @@ /** | ||
*/ | ||
export const appendUrlParams = internal.appendUrlParams | ||
export const appendUrlParams: { | ||
(input: UrlParams.Input): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, input: UrlParams.Input): ClientRequest | ||
} = internal.appendUrlParams | ||
@@ -274,2 +289,17 @@ /** | ||
*/ | ||
export const setHash: { | ||
(hash: string): (self: ClientRequest) => ClientRequest | ||
(self: ClientRequest, hash: string): ClientRequest | ||
} = internal.setHash | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const removeHash: (self: ClientRequest) => ClientRequest = internal.removeHash | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const setBody: { | ||
@@ -276,0 +306,0 @@ (body: Body.Body): (self: ClientRequest) => ClientRequest |
@@ -11,3 +11,3 @@ /** | ||
import * as Record from "effect/Record" | ||
import * as Secret from "effect/Secret" | ||
import * as Redacted from "effect/Redacted" | ||
import * as String from "effect/String" | ||
@@ -209,8 +209,16 @@ import type { Mutable } from "effect/Types" | ||
export const redact: { | ||
(key: string | RegExp | ReadonlyArray<string | RegExp>): (self: Headers) => Record<string, string | Secret.Secret> | ||
(self: Headers, key: string | RegExp | ReadonlyArray<string | RegExp>): Record<string, string | Secret.Secret> | ||
( | ||
key: string | RegExp | ReadonlyArray<string | RegExp> | ||
): (self: Headers) => Record<string, string | Redacted.Redacted> | ||
( | ||
self: Headers, | ||
key: string | RegExp | ReadonlyArray<string | RegExp> | ||
): Record<string, string | Redacted.Redacted> | ||
} = dual( | ||
2, | ||
(self: Headers, key: string | RegExp | ReadonlyArray<string | RegExp>): Record<string, string | Secret.Secret> => { | ||
const out: Record<string, string | Secret.Secret> = { ...self } | ||
( | ||
self: Headers, | ||
key: string | RegExp | ReadonlyArray<string | RegExp> | ||
): Record<string, string | Redacted.Redacted> => { | ||
const out: Record<string, string | Redacted.Redacted> = { ...self } | ||
const modify = (key: string | RegExp) => { | ||
@@ -220,3 +228,3 @@ if (typeof key === "string") { | ||
if (k in self) { | ||
out[k] = Secret.fromString(self[k]) | ||
out[k] = Redacted.make(self[k]) | ||
} | ||
@@ -226,3 +234,3 @@ } else { | ||
if (key.test(name)) { | ||
out[name] = Secret.fromString(self[name]) | ||
out[name] = Redacted.make(self[name]) | ||
} | ||
@@ -229,0 +237,0 @@ } |
@@ -210,3 +210,3 @@ /** | ||
*/ | ||
export const makeUrl = (url: string, params: UrlParams): Either.Either<URL, Error> => { | ||
export const makeUrl = (url: string, params: UrlParams, hash: Option.Option<string>): Either.Either<URL, Error> => { | ||
try { | ||
@@ -220,3 +220,5 @@ const urlInstance = new URL(url, baseUrl()) | ||
} | ||
if (hash._tag === "Some") { | ||
urlInstance.hash = hash.value | ||
} | ||
return Either.right(urlInstance) | ||
@@ -223,0 +225,0 @@ } catch (e) { |
@@ -129,3 +129,3 @@ import type { ParseOptions } from "@effect/schema/AST" | ||
const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort())) | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams) | ||
const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash) | ||
if (urlResult._tag === "Left") { | ||
@@ -132,0 +132,0 @@ return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl", error: urlResult.left })) |
@@ -8,2 +8,3 @@ import type { ParseOptions } from "@effect/schema/AST" | ||
import * as Inspectable from "effect/Inspectable" | ||
import * as Option from "effect/Option" | ||
import type * as Stream from "effect/Stream" | ||
@@ -39,2 +40,3 @@ import type * as PlatformError from "../../Error.js" | ||
urlParams: this.urlParams, | ||
hash: this.hash, | ||
headers: this.headers, | ||
@@ -50,2 +52,3 @@ body: this.body.toJSON() | ||
urlParams: UrlParams.UrlParams, | ||
hash: Option.Option<string>, | ||
headers: Headers.Headers, | ||
@@ -58,2 +61,3 @@ body: Body.Body | ||
self.urlParams = urlParams | ||
self.hash = hash | ||
self.headers = headers | ||
@@ -73,2 +77,3 @@ self.body = body | ||
UrlParams.empty, | ||
Option.none(), | ||
Headers.empty, | ||
@@ -86,3 +91,3 @@ internalBody.empty | ||
method, | ||
url: url.toString(), | ||
url, | ||
...(options ?? undefined) | ||
@@ -131,2 +136,5 @@ }) | ||
} | ||
if (options.hash) { | ||
result = setHash(result, options.hash) | ||
} | ||
if (options.body) { | ||
@@ -154,2 +162,3 @@ result = setBody(result, options.body) | ||
self.urlParams, | ||
self.hash, | ||
Headers.set(self.headers, key, value), | ||
@@ -168,2 +177,3 @@ self.body | ||
self.urlParams, | ||
self.hash, | ||
Headers.setAll(self.headers, input), | ||
@@ -203,2 +213,3 @@ self.body | ||
self.urlParams, | ||
self.hash, | ||
self.headers, | ||
@@ -211,11 +222,28 @@ self.body | ||
(url: string | URL) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest, | ||
(self: ClientRequest.ClientRequest, url: string) => ClientRequest.ClientRequest | ||
>(2, (self, url) => | ||
makeInternal( | ||
(self: ClientRequest.ClientRequest, url: string | URL) => ClientRequest.ClientRequest | ||
>(2, (self, url) => { | ||
if (typeof url === "string") { | ||
return makeInternal( | ||
self.method, | ||
url, | ||
self.urlParams, | ||
self.hash, | ||
self.headers, | ||
self.body | ||
) | ||
} | ||
const clone = new URL(url.toString()) | ||
const urlParams = UrlParams.fromInput(clone.searchParams) | ||
const hash = clone.hash ? Option.some(clone.hash.slice(1)) : Option.none() | ||
clone.search = "" | ||
clone.hash = "" | ||
return makeInternal( | ||
self.method, | ||
url.toString(), | ||
self.urlParams, | ||
clone.toString(), | ||
urlParams, | ||
hash, | ||
self.headers, | ||
self.body | ||
)) | ||
) | ||
}) | ||
@@ -229,4 +257,7 @@ /** @internal */ | ||
self.method, | ||
self.url + url, | ||
self.url.endsWith("/") && url.startsWith("/") ? | ||
self.url + url.slice(1) : | ||
self.url + url, | ||
self.urlParams, | ||
self.hash, | ||
self.headers, | ||
@@ -238,3 +269,3 @@ self.body | ||
export const prependUrl = dual< | ||
(path: string | URL) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest, | ||
(path: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest, | ||
(self: ClientRequest.ClientRequest, path: string) => ClientRequest.ClientRequest | ||
@@ -244,4 +275,7 @@ >(2, (self, url) => | ||
self.method, | ||
url.toString() + self.url, | ||
url.endsWith("/") && self.url.startsWith("/") ? | ||
url + self.url.slice(1) : | ||
url + self.url, | ||
self.urlParams, | ||
self.hash, | ||
self.headers, | ||
@@ -260,2 +294,3 @@ self.body | ||
self.urlParams, | ||
self.hash, | ||
self.headers, | ||
@@ -274,2 +309,3 @@ self.body | ||
UrlParams.append(self.urlParams, key, value), | ||
self.hash, | ||
self.headers, | ||
@@ -288,2 +324,3 @@ self.body | ||
UrlParams.appendAll(self.urlParams, input), | ||
self.hash, | ||
self.headers, | ||
@@ -302,2 +339,3 @@ self.body | ||
UrlParams.set(self.urlParams, key, value), | ||
self.hash, | ||
self.headers, | ||
@@ -316,2 +354,3 @@ self.body | ||
UrlParams.setAll(self.urlParams, input), | ||
self.hash, | ||
self.headers, | ||
@@ -322,2 +361,27 @@ self.body | ||
/** @internal */ | ||
export const setHash = dual< | ||
(hash: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest, | ||
(self: ClientRequest.ClientRequest, hash: string) => ClientRequest.ClientRequest | ||
>(2, (self, hash) => | ||
makeInternal( | ||
self.method, | ||
self.url, | ||
self.urlParams, | ||
Option.some(hash), | ||
self.headers, | ||
self.body | ||
)) | ||
/** @internal */ | ||
export const removeHash = (self: ClientRequest.ClientRequest): ClientRequest.ClientRequest => | ||
makeInternal( | ||
self.method, | ||
self.url, | ||
self.urlParams, | ||
Option.none(), | ||
self.headers, | ||
self.body | ||
) | ||
/** @internal */ | ||
export const setBody = dual< | ||
@@ -345,2 +409,3 @@ (body: Body.Body) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest, | ||
self.urlParams, | ||
self.hash, | ||
headers, | ||
@@ -347,0 +412,0 @@ body |
@@ -70,3 +70,2 @@ import * as Schema from "@effect/schema/Schema" | ||
initialMessage, | ||
permits = 1, | ||
queue, | ||
@@ -79,3 +78,2 @@ transfers = (_) => [] | ||
let requestIdCounter = 0 | ||
const semaphore = Effect.unsafeMakeSemaphore(permits) | ||
const requestMap = new Map< | ||
@@ -242,6 +240,5 @@ number, | ||
yield* semaphore.take(1).pipe( | ||
Effect.andThen(outbound.take), | ||
yield* outbound.take.pipe( | ||
Effect.flatMap(([id, request, span]) => | ||
pipe( | ||
Effect.fork( | ||
Effect.suspend(() => { | ||
@@ -266,10 +263,8 @@ const result = requestMap.get(id) | ||
) | ||
}), | ||
Effect.ensuring(semaphore.release(1)), | ||
Effect.fork | ||
}) | ||
) | ||
), | ||
Effect.forever, | ||
Effect.interruptible, | ||
Effect.forkScoped | ||
Effect.forkScoped, | ||
Effect.interruptible | ||
) | ||
@@ -306,7 +301,17 @@ | ||
) | ||
const backing = yield* Pool.make({ | ||
acquire, | ||
size: options.size | ||
}) | ||
const get = Effect.scoped(backing.get) | ||
const backing = "minSize" in options ? | ||
yield* Pool.makeWithTTL({ | ||
acquire, | ||
min: options.minSize, | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
}) : | ||
yield* Pool.make({ | ||
acquire, | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}) | ||
const pool: Worker.WorkerPool<I, O, E> = { | ||
@@ -319,8 +324,16 @@ backing, | ||
}), | ||
execute: (message: I) => Stream.unwrap(Effect.map(get, (worker) => worker.execute(message))), | ||
executeEffect: (message: I) => Effect.flatMap(get, (worker) => worker.executeEffect(message)) | ||
execute: (message: I) => | ||
Stream.unwrapScoped(Effect.map( | ||
backing.get, | ||
(worker) => worker.execute(message) | ||
)), | ||
executeEffect: (message: I) => | ||
Effect.scoped(Effect.flatMap( | ||
backing.get, | ||
(worker) => worker.executeEffect(message) | ||
)) | ||
} | ||
// report any spawn errors | ||
yield* get | ||
yield* Effect.scoped(backing.get) | ||
@@ -400,2 +413,4 @@ return pool | ||
max: options.maxSize, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization, | ||
timeToLive: options.timeToLive | ||
@@ -405,5 +420,6 @@ }) : | ||
acquire, | ||
size: options.size | ||
size: options.size, | ||
concurrency: options.concurrency, | ||
targetUtilization: options.targetUtilization | ||
}) | ||
const get = Effect.scoped(backing.get) | ||
const pool: Worker.SerializedWorkerPool<I> = { | ||
@@ -417,9 +433,9 @@ backing, | ||
execute: <Req extends I>(message: Req) => | ||
Stream.unwrap(Effect.map(get, (worker) => worker.execute(message))) as any, | ||
Stream.unwrapScoped(Effect.map(backing.get, (worker) => worker.execute(message))) as any, | ||
executeEffect: <Req extends I>(message: Req) => | ||
Effect.flatMap(get, (worker) => worker.executeEffect(message)) as any | ||
Effect.scoped(Effect.flatMap(backing.get, (worker) => worker.executeEffect(message))) as any | ||
} | ||
// report any spawn errors | ||
yield* get | ||
yield* Effect.scoped(backing.get) | ||
@@ -426,0 +442,0 @@ return pool |
@@ -111,3 +111,2 @@ /** | ||
readonly initialMessage?: LazyArg<I> | undefined | ||
readonly permits?: number | undefined | ||
} | ||
@@ -161,6 +160,17 @@ | ||
*/ | ||
export interface Options<I> extends Worker.Options<I> { | ||
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError> | ||
readonly size: number | ||
} | ||
export type Options<I> = | ||
& Worker.Options<I> | ||
& ({ | ||
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError> | ||
readonly size: number | ||
readonly concurrency?: number | undefined | ||
readonly targetUtilization?: number | undefined | ||
} | { | ||
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError> | ||
readonly minSize: number | ||
readonly maxSize: number | ||
readonly concurrency?: number | undefined | ||
readonly targetUtilization?: number | undefined | ||
readonly timeToLive: Duration.DurationInput | ||
}) | ||
} | ||
@@ -275,3 +285,2 @@ | ||
export interface BaseOptions<I> { | ||
readonly permits?: number | undefined | ||
readonly queue?: WorkerQueue<I> | undefined | ||
@@ -318,2 +327,4 @@ } | ||
readonly size: number | ||
readonly concurrency?: number | undefined | ||
readonly targetUtilization?: number | undefined | ||
} | { | ||
@@ -323,2 +334,4 @@ readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError> | ||
readonly maxSize: number | ||
readonly concurrency?: number | undefined | ||
readonly targetUtilization?: number | undefined | ||
readonly timeToLive: Duration.DurationInput | ||
@@ -325,0 +338,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2096692
36240