effect 3.6.2 → 3.6.4

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 (40) hide show
  1. package/dist/cjs/Cache.js +6 -1
  2. package/dist/cjs/Cache.js.map +1 -1
  3. package/dist/cjs/DateTime.js +2 -2
  4. package/dist/cjs/DateTime.js.map +1 -1
  5. package/dist/cjs/Scheduler.js +7 -12
  6. package/dist/cjs/Scheduler.js.map +1 -1
  7. package/dist/cjs/internal/cache.js +14 -1
  8. package/dist/cjs/internal/cache.js.map +1 -1
  9. package/dist/cjs/internal/core-effect.js +15 -7
  10. package/dist/cjs/internal/core-effect.js.map +1 -1
  11. package/dist/cjs/internal/stream.js +2 -1
  12. package/dist/cjs/internal/stream.js.map +1 -1
  13. package/dist/cjs/internal/version.js +1 -1
  14. package/dist/dts/Cache.d.ts +24 -3
  15. package/dist/dts/Cache.d.ts.map +1 -1
  16. package/dist/dts/DateTime.d.ts +1 -1
  17. package/dist/dts/Scheduler.d.ts.map +1 -1
  18. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  19. package/dist/dts/internal/stream.d.ts.map +1 -1
  20. package/dist/esm/Cache.js +5 -0
  21. package/dist/esm/Cache.js.map +1 -1
  22. package/dist/esm/DateTime.js +2 -2
  23. package/dist/esm/DateTime.js.map +1 -1
  24. package/dist/esm/Scheduler.js +7 -12
  25. package/dist/esm/Scheduler.js.map +1 -1
  26. package/dist/esm/internal/cache.js +13 -0
  27. package/dist/esm/internal/cache.js.map +1 -1
  28. package/dist/esm/internal/core-effect.js +15 -7
  29. package/dist/esm/internal/core-effect.js.map +1 -1
  30. package/dist/esm/internal/stream.js +2 -1
  31. package/dist/esm/internal/stream.js.map +1 -1
  32. package/dist/esm/internal/version.js +1 -1
  33. package/package.json +1 -1
  34. package/src/Cache.ts +30 -3
  35. package/src/DateTime.ts +2 -2
  36. package/src/Scheduler.ts +7 -12
  37. package/src/internal/cache.ts +18 -0
  38. package/src/internal/core-effect.ts +22 -18
  39. package/src/internal/stream.ts +5 -1
  40. package/src/internal/version.ts +1 -1
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.6.2";
1
+ let moduleVersion = "3.6.4";
2
2
  export const getCurrentVersion = () => moduleVersion;
3
3
  export const setCurrentVersion = version => {
4
4
  moduleVersion = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "3.6.2",
3
+ "version": "3.6.4",
4
4
  "description": "The missing standard library for TypeScript, for writing production-grade software.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Cache.ts CHANGED
@@ -22,6 +22,18 @@ export const CacheTypeId: unique symbol = internal.CacheTypeId
22
22
  */
23
23
  export type CacheTypeId = typeof CacheTypeId
24
24
 
25
+ /**
26
+ * @since 3.6.4
27
+ * @category symbols
28
+ */
29
+ export const ConsumerCacheTypeId: unique symbol = internal.ConsumerCacheTypeId
30
+
31
+ /**
32
+ * @since 3.6.4
33
+ * @category symbols
34
+ */
35
+ export type ConsumerCacheTypeId = typeof ConsumerCacheTypeId
36
+
25
37
  /**
26
38
  * A `Cache` is defined in terms of a lookup function that, given a key of
27
39
  * type `Key`, can either fail with an error of type `Error` or succeed with a
@@ -43,7 +55,9 @@ export type CacheTypeId = typeof CacheTypeId
43
55
  * @since 2.0.0
44
56
  * @category models
45
57
  */
46
- export interface Cache<in out Key, out Value, out Error = never> extends ConsumerCache<Key, Value, Error> {
58
+ export interface Cache<in out Key, in out Value, out Error = never>
59
+ extends ConsumerCache<Key, Value, Error>, Cache.Variance<Key, Value, Error>
60
+ {
47
61
  /**
48
62
  * Retrieves the value associated with the specified key if it exists.
49
63
  * Otherwise computes the value with the lookup function, puts it in the
@@ -83,7 +97,9 @@ export interface Cache<in out Key, out Value, out Error = never> extends Consume
83
97
  * @since 2.0.0
84
98
  * @category models
85
99
  */
86
- export interface ConsumerCache<in out Key, out Value, out Error = never> extends Cache.Variance<Key, Value, Error> {
100
+ export interface ConsumerCache<in out Key, out Value, out Error = never>
101
+ extends Cache.ConsumerVariance<Key, Value, Error>
102
+ {
87
103
  /**
88
104
  * Retrieves the value associated with the specified key if it exists.
89
105
  * Otherwise returns `Option.none`.
@@ -156,8 +172,19 @@ export declare namespace Cache {
156
172
  * @since 2.0.0
157
173
  * @category models
158
174
  */
159
- export interface Variance<in out Key, out Value, out Error> {
175
+ export interface Variance<in out Key, in out Value, out Error> {
160
176
  readonly [CacheTypeId]: {
177
+ readonly _Key: Types.Invariant<Key>
178
+ readonly _Error: Types.Covariant<Error>
179
+ readonly _Value: Types.Invariant<Value>
180
+ }
181
+ }
182
+ /**
183
+ * @since 3.6.4
184
+ * @category models
185
+ */
186
+ export interface ConsumerVariance<in out Key, out Value, out Error> {
187
+ readonly [ConsumerCacheTypeId]: {
161
188
  readonly _Key: Types.Invariant<Key>
162
189
  readonly _Error: Types.Covariant<Error>
163
190
  readonly _Value: Types.Covariant<Value>
package/src/DateTime.ts CHANGED
@@ -562,7 +562,7 @@ export const makeZonedFromString = (input: string): Option.Option<Zoned> => {
562
562
  const match = zonedStringRegex.exec(input)
563
563
  if (match === null) {
564
564
  const offset = parseOffset(input)
565
- return offset ? makeZoned(input, { timeZone: offset }) : Option.none()
565
+ return offset !== null ? makeZoned(input, { timeZone: offset }) : Option.none()
566
566
  }
567
567
  const [, isoString, timeZone] = match
568
568
  return makeZoned(isoString, { timeZone })
@@ -1979,7 +1979,7 @@ export const format: {
1979
1979
  /**
1980
1980
  * Format a `DateTime` as a string using the `DateTimeFormat` API.
1981
1981
  *
1982
- * It will use the system's local time zone.
1982
+ * It will use the system's local time zone & locale.
1983
1983
  *
1984
1984
  * @since 3.6.0
1985
1985
  * @category formatting
package/src/Scheduler.ts CHANGED
@@ -37,27 +37,22 @@ export class PriorityBuckets<in out T = Task> {
37
37
  * @since 2.0.0
38
38
  */
39
39
  scheduleTask(task: T, priority: number) {
40
+ const length = this.buckets.length
40
41
  let bucket: [number, Array<T>] | undefined = undefined
41
- let index: number
42
- for (index = 0; index < this.buckets.length; index++) {
42
+ let index = 0
43
+ for (; index < length; index++) {
43
44
  if (this.buckets[index][0] <= priority) {
44
45
  bucket = this.buckets[index]
45
46
  } else {
46
47
  break
47
48
  }
48
49
  }
49
- if (bucket) {
50
+ if (bucket && bucket[0] === priority) {
50
51
  bucket[1].push(task)
52
+ } else if (index === length) {
53
+ this.buckets.push([priority, [task]])
51
54
  } else {
52
- const newBuckets: Array<[number, Array<T>]> = []
53
- for (let i = 0; i < index; i++) {
54
- newBuckets.push(this.buckets[i])
55
- }
56
- newBuckets.push([priority, [task]])
57
- for (let i = index; i < this.buckets.length; i++) {
58
- newBuckets.push(this.buckets[i])
59
- }
60
- this.buckets = newBuckets
55
+ this.buckets.splice(index, 0, [priority, [task]])
61
56
  }
62
57
  }
63
58
  }
@@ -270,6 +270,23 @@ export const CacheTypeId: Cache.CacheTypeId = Symbol.for(
270
270
  ) as Cache.CacheTypeId
271
271
 
272
272
  const cacheVariance = {
273
+ /* c8 ignore next */
274
+ _Key: (_: any) => _,
275
+ /* c8 ignore next */
276
+ _Error: (_: never) => _,
277
+ /* c8 ignore next */
278
+ _Value: (_: any) => _
279
+ }
280
+
281
+ /** @internal */
282
+ const ConsumerCacheSymbolKey = "effect/ConsumerCache"
283
+
284
+ /** @internal */
285
+ export const ConsumerCacheTypeId: Cache.ConsumerCacheTypeId = Symbol.for(
286
+ ConsumerCacheSymbolKey
287
+ ) as Cache.ConsumerCacheTypeId
288
+
289
+ const consumerCacheVariance = {
273
290
  /* c8 ignore next */
274
291
  _Key: (_: any) => _,
275
292
  /* c8 ignore next */
@@ -294,6 +311,7 @@ export const makeEntryStats = (loadedMillis: number): Cache.EntryStats => ({
294
311
 
295
312
  class CacheImpl<in out Key, in out Value, in out Error> implements Cache.Cache<Key, Value, Error> {
296
313
  readonly [CacheTypeId] = cacheVariance
314
+ readonly [ConsumerCacheTypeId] = consumerCacheVariance
297
315
  readonly cacheState: CacheState<Key, Value, Error>
298
316
  constructor(
299
317
  readonly capacity: number,
@@ -1200,12 +1200,20 @@ export const patchFiberRefs = (patch: FiberRefsPatch.FiberRefsPatch): Effect.Eff
1200
1200
  export const promise = <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>): Effect.Effect<A> =>
1201
1201
  evaluate.length >= 1
1202
1202
  ? core.async((resolve, signal) => {
1203
- evaluate(signal)
1204
- .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1203
+ try {
1204
+ evaluate(signal)
1205
+ .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1206
+ } catch (e) {
1207
+ resolve(core.exitDie(e))
1208
+ }
1205
1209
  })
1206
1210
  : core.async((resolve) => {
1207
- ;(evaluate as LazyArg<PromiseLike<A>>)()
1208
- .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1211
+ try {
1212
+ ;(evaluate as LazyArg<PromiseLike<A>>)()
1213
+ .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1214
+ } catch (e) {
1215
+ resolve(core.exitDie(e))
1216
+ }
1209
1217
  })
1210
1218
 
1211
1219
  /* @internal */
@@ -1668,14 +1676,12 @@ export const tryPromise: {
1668
1676
  return core.async((resolve, signal) => {
1669
1677
  try {
1670
1678
  evaluate(signal)
1671
- .then((a) => resolve(core.exitSucceed(a)), (e) =>
1672
- resolve(core.fail(
1673
- catcher ? catcher(e) : new core.UnknownException(e)
1674
- )))
1679
+ .then(
1680
+ (a) => resolve(core.exitSucceed(a)),
1681
+ (e) => resolve(catcher ? core.failSync(() => catcher(e)) : core.fail(new core.UnknownException(e)))
1682
+ )
1675
1683
  } catch (e) {
1676
- resolve(core.fail(
1677
- catcher ? catcher(e) : new core.UnknownException(e)
1678
- ))
1684
+ resolve(catcher ? core.failSync(() => catcher(e)) : core.fail(new core.UnknownException(e)))
1679
1685
  }
1680
1686
  })
1681
1687
  }
@@ -1683,14 +1689,12 @@ export const tryPromise: {
1683
1689
  return core.async((resolve) => {
1684
1690
  try {
1685
1691
  evaluate()
1686
- .then((a) => resolve(core.exitSucceed(a)), (e) =>
1687
- resolve(core.fail(
1688
- catcher ? catcher(e) : new core.UnknownException(e)
1689
- )))
1692
+ .then(
1693
+ (a) => resolve(core.exitSucceed(a)),
1694
+ (e) => resolve(catcher ? core.failSync(() => catcher(e)) : core.fail(new core.UnknownException(e)))
1695
+ )
1690
1696
  } catch (e) {
1691
- resolve(core.fail(
1692
- catcher ? catcher(e) : new core.UnknownException(e)
1693
- ))
1697
+ resolve(catcher ? core.failSync(() => catcher(e)) : core.fail(new core.UnknownException(e)))
1694
1698
  }
1695
1699
  })
1696
1700
  }
@@ -6895,10 +6895,14 @@ export const toReadableStreamRuntime = dual<
6895
6895
  return new ReadableStream<A>({
6896
6896
  start(controller) {
6897
6897
  scope = runSync(Scope.make())
6898
- pull = pipe(
6898
+ const pullChunk: Effect.Effect<Chunk.Chunk<A>, Option.Option<E>, R> = pipe(
6899
6899
  toPull(self),
6900
6900
  Scope.extend(scope),
6901
6901
  runSync,
6902
+ Effect.flatMap((chunk) => Chunk.isEmpty(chunk) ? pullChunk : Effect.succeed(chunk))
6903
+ )
6904
+ pull = pipe(
6905
+ pullChunk,
6902
6906
  Effect.tap((chunk) =>
6903
6907
  Effect.sync(() => {
6904
6908
  Chunk.map(chunk, (a) => {
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.6.2"
1
+ let moduleVersion = "3.6.4"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4