@effect/platform 0.55.7 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/Http/ClientRequest.js +11 -1
  2. package/dist/cjs/Http/ClientRequest.js.map +1 -1
  3. package/dist/cjs/Http/Headers.js +3 -3
  4. package/dist/cjs/Http/Headers.js.map +1 -1
  5. package/dist/cjs/Http/UrlParams.js +4 -1
  6. package/dist/cjs/Http/UrlParams.js.map +1 -1
  7. package/dist/cjs/KeyValueStore.js.map +1 -1
  8. package/dist/cjs/Worker.js.map +1 -1
  9. package/dist/cjs/internal/http/client.js +1 -1
  10. package/dist/cjs/internal/http/client.js.map +1 -1
  11. package/dist/cjs/internal/http/clientRequest.js +37 -16
  12. package/dist/cjs/internal/http/clientRequest.js.map +1 -1
  13. package/dist/cjs/internal/keyValueStore.js +44 -41
  14. package/dist/cjs/internal/keyValueStore.js.map +1 -1
  15. package/dist/cjs/internal/worker.js +24 -15
  16. package/dist/cjs/internal/worker.js.map +1 -1
  17. package/dist/dts/Http/ClientRequest.d.ts +35 -7
  18. package/dist/dts/Http/ClientRequest.d.ts.map +1 -1
  19. package/dist/dts/Http/Headers.d.ts +3 -3
  20. package/dist/dts/Http/Headers.d.ts.map +1 -1
  21. package/dist/dts/Http/UrlParams.d.ts +1 -1
  22. package/dist/dts/Http/UrlParams.d.ts.map +1 -1
  23. package/dist/dts/KeyValueStore.d.ts +2 -1
  24. package/dist/dts/KeyValueStore.d.ts.map +1 -1
  25. package/dist/dts/Worker.d.ts +15 -4
  26. package/dist/dts/Worker.d.ts.map +1 -1
  27. package/dist/esm/Http/ClientRequest.js +10 -0
  28. package/dist/esm/Http/ClientRequest.js.map +1 -1
  29. package/dist/esm/Http/Headers.js +3 -3
  30. package/dist/esm/Http/Headers.js.map +1 -1
  31. package/dist/esm/Http/UrlParams.js +4 -1
  32. package/dist/esm/Http/UrlParams.js.map +1 -1
  33. package/dist/esm/KeyValueStore.js.map +1 -1
  34. package/dist/esm/Worker.js.map +1 -1
  35. package/dist/esm/internal/http/client.js +1 -1
  36. package/dist/esm/internal/http/client.js.map +1 -1
  37. package/dist/esm/internal/http/clientRequest.js +35 -15
  38. package/dist/esm/internal/http/clientRequest.js.map +1 -1
  39. package/dist/esm/internal/keyValueStore.js +44 -41
  40. package/dist/esm/internal/keyValueStore.js.map +1 -1
  41. package/dist/esm/internal/worker.js +24 -15
  42. package/dist/esm/internal/worker.js.map +1 -1
  43. package/package.json +3 -3
  44. package/src/Http/ClientRequest.ts +37 -7
  45. package/src/Http/Headers.ts +15 -7
  46. package/src/Http/UrlParams.ts +4 -2
  47. package/src/KeyValueStore.ts +4 -1
  48. package/src/Worker.ts +19 -6
  49. package/src/internal/http/client.ts +1 -1
  50. package/src/internal/http/clientRequest.ts +75 -10
  51. package/src/internal/keyValueStore.ts +6 -5
  52. package/src/internal/worker.ts +39 -23
@@ -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: url.toString(),
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
- makeInternal(
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
- url.toString(),
206
- self.urlParams,
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 + 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 | URL) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
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.toString() + self.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
  )
@@ -1,6 +1,7 @@
1
1
  import * as Schema from "@effect/schema/Schema"
2
2
  import * as Context from "effect/Context"
3
3
  import * as Effect from "effect/Effect"
4
+ import type { LazyArg } from "effect/Function"
4
5
  import { dual, pipe } from "effect/Function"
5
6
  import * as Layer from "effect/Layer"
6
7
  import * as Option from "effect/Option"
@@ -185,10 +186,10 @@ const storageError = (props: Omit<Parameters<typeof PlatformError.SystemError>[0
185
186
  })
186
187
 
187
188
  /** @internal */
188
- export const layerStorage = (storage: Storage) =>
189
- Layer.succeed(
190
- keyValueStoreTag,
191
- make({
189
+ export const layerStorage = (evaluate: LazyArg<Storage>) =>
190
+ Layer.sync(keyValueStoreTag, () => {
191
+ const storage = evaluate()
192
+ return make({
192
193
  get: (key: string) =>
193
194
  Effect.try({
194
195
  try: () => Option.fromNullable(storage.getItem(key)),
@@ -242,4 +243,4 @@ export const layerStorage = (storage: Storage) =>
242
243
  })
243
244
  })
244
245
  })
245
- )
246
+ })
@@ -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* semaphore.take(1).pipe(
241
- Effect.andThen(outbound.take),
238
+ yield* outbound.take.pipe(
242
239
  Effect.flatMap(([id, request, span]) =>
243
- pipe(
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.interruptible,
270
- Effect.forkScoped
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 = yield* Pool.make({
303
- acquire,
304
- size: options.size
305
- })
306
- const get = Effect.scoped(backing.get)
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) => Stream.unwrap(Effect.map(get, (worker) => worker.execute(message))),
315
- executeEffect: (message: I) => Effect.flatMap(get, (worker) => worker.executeEffect(message))
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.unwrap(Effect.map(get, (worker) => worker.execute(message))) as any,
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
  })