Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release queue: minor #3048

Merged
merged 14 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-berries-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

include Error.cause stack in log output
5 changes: 5 additions & 0 deletions .changeset/clever-parents-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add renderErrorCause option to Cause.pretty
5 changes: 5 additions & 0 deletions .changeset/clever-walls-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/sql-d1": minor
---

Add new cloudflare @effect/sql-d1 package
5 changes: 5 additions & 0 deletions .changeset/fast-dodos-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

set stackTraceLimit to 1 in PrettyError to address performance issues
25 changes: 25 additions & 0 deletions .changeset/five-olives-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"effect": minor
---

add RcRef module

An `RcRef` wraps a reference counted resource that can be acquired and released multiple times.

The resource is lazily acquired on the first call to `get` and released when the last reference is released.

```ts
import { Effect, RcRef } from "effect";

Effect.gen(function* () {
const ref = yield* RcRef.make({
acquire: Effect.acquireRelease(Effect.succeed("foo"), () =>
Effect.log("release foo"),
),
});

// will only acquire the resource once, and release it
// when the scope is closed
yield* RcRef.get(ref).pipe(Effect.andThen(RcRef.get(ref)), Effect.scoped);
});
```
25 changes: 25 additions & 0 deletions .changeset/hungry-drinks-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"effect": minor
---

allowing customizing Stream pubsub strategy

```ts
import { Schedule, Stream } from "effect";

// toPubSub
Stream.fromSchedule(Schedule.spaced(1000)).pipe(
Stream.toPubSub({
capacity: 16, // or "unbounded"
strategy: "dropping", // or "sliding" / "suspend"
}),
);

// also for the broadcast apis
Stream.fromSchedule(Schedule.spaced(1000)).pipe(
Stream.broadcastDynamic({
capacity: 16,
strategy: "dropping",
}),
);
```
5 changes: 5 additions & 0 deletions .changeset/little-taxis-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add Duration.isZero, for checking if a Duration is zero
5 changes: 5 additions & 0 deletions .changeset/lucky-poets-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add `Success` type util for `Config`.
15 changes: 15 additions & 0 deletions .changeset/nervous-cougars-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"effect": minor
---

add Logger.prettyLogger and Logger.pretty

`Logger.pretty` is a new logger that leverages the features of the `console` APIs to provide a more visually appealing output.

To try it out, provide it to your program:

```ts
import { Effect, Logger } from "effect"

Effect.log("Hello, World!").pipe(Effect.provide(Logger.pretty))
```
5 changes: 5 additions & 0 deletions .changeset/ninety-starfishes-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add .groupCollapsed to UnsafeConsole
5 changes: 5 additions & 0 deletions .changeset/rich-insects-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

export Random.make taking hashable values as seed
18 changes: 18 additions & 0 deletions .changeset/seven-ghosts-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"effect": minor
---

add `replay` option to PubSub constructors

This option adds a replay buffer in front of the given PubSub. The buffer will
replay the last `n` messages to any new subscriber.

```ts
Effect.gen(function*() {
const messages = [1, 2, 3, 4, 5]
const pubsub = yield* PubSub.bounded<number>({ capacity: 16, replay: 3 })
yield* PubSub.publishAll(pubsub, messages)
const sub = yield* PubSub.subscribe(pubsub)
assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5])
}))
```
31 changes: 31 additions & 0 deletions .changeset/spicy-hats-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"effect": minor
---

add RcMap module

An `RcMap` can contain multiple reference counted resources that can be indexed
by a key. The resources are lazily acquired on the first call to `get` and
released when the last reference is released.

Complex keys can extend `Equal` and `Hash` to allow lookups by value.

```ts
import { Effect, RcMap } from "effect";

Effect.gen(function* () {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(Effect.succeed(`acquired ${key}`), () =>
Effect.log(`releasing ${key}`),
),
});

// Get "foo" from the map twice, which will only acquire it once
// It will then be released once the scope closes.
yield* RcMap.get(map, "foo").pipe(
Effect.andThen(RcMap.get(map, "foo")),
Effect.scoped,
);
});
```
5 changes: 5 additions & 0 deletions .changeset/spotty-beds-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

ensure "cause" is rendered in Data.Error output
9 changes: 9 additions & 0 deletions .changeset/stream-channel-run-env-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"effect": minor
---

Ensure `Scope` is excluded from `R` in the `Channel` / `Stream` `run*` functions.

This fix ensures that `Scope` is now properly excluded from the resulting effect environment.
The affected functions include `run`, `runCollect`, `runCount`, `runDrain` and other non-scoped `run*` in both `Stream` and `Channel` modules.
This fix brings the type declaration in line with the runtime implementation.
7 changes: 7 additions & 0 deletions .changeset/stream-merge-left-right.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"effect": minor
---

refactor(Stream/mergeLeft): rename `self`/`that` argument names to `left`/`right` for clarity

refactor(Stream/mergeRight): rename `self`/`that` argument names to `left`/`right` for clarity
24 changes: 24 additions & 0 deletions .changeset/stream-race-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
"effect": minor
---

feat(Stream): implement "raceAll" operator, which returns a stream that mirrors the first source stream to emit an item.

```ts
import { Stream, Schedule, Console, Effect } from "effect";

const stream = Stream.raceAll(
Stream.fromSchedule(Schedule.spaced("1 millis")),
Stream.fromSchedule(Schedule.spaced("2 millis")),
Stream.fromSchedule(Schedule.spaced("4 millis")),
).pipe(Stream.take(6), Stream.tap(Console.log));

Effect.runPromise(Stream.runDrain(stream));
// Output only from the first stream, the rest streams are interrupted
// 0
// 1
// 2
// 3
// 4
// 5
```
5 changes: 5 additions & 0 deletions .changeset/stream-tuple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

refactor(Stream): use new built-in `Types.TupleOf` instead of `Stream.DynamicTuple` and deprecate it
5 changes: 5 additions & 0 deletions .changeset/swift-dodos-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

support ErrorOptions in YieldableError constructor
5 changes: 5 additions & 0 deletions .changeset/tame-zoos-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

fix types of UnsafeConsole.group
19 changes: 19 additions & 0 deletions .changeset/ten-swans-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"effect": minor
---

allow customizing the output buffer for the Stream.async\* apis

```ts
import { Stream } from "effect";

Stream.async<string>(
(emit) => {
// ...
},
{
bufferSize: 16,
strategy: "dropping", // you can also use "sliding" or "suspend"
},
);
```
17 changes: 16 additions & 1 deletion packages/effect/dtslint/Config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Config from "effect/Config"
import { pipe } from "effect/Function"
import { hole, pipe } from "effect/Function"

declare const string: Config.Config<string>
declare const number: Config.Config<number>
Expand Down Expand Up @@ -45,3 +45,18 @@ Config.all(numberRecord)

// $ExpectType Config<{ [x: string]: number; }>
pipe(numberRecord, Config.all)

// -------------------------------------------------------------------------------------
// Success
// -------------------------------------------------------------------------------------

// $ExpectType string
hole<Config.Config.Success<typeof string>>()

// $ExpectType number
hole<Config.Config.Success<typeof number>>()

const object = Config.all({ a: string, b: number })

// $ExpectType { a: string; b: number; }
hole<Config.Config.Success<typeof object>>()
48 changes: 47 additions & 1 deletion packages/effect/src/Cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export const InvalidPubSubCapacityExceptionTypeId: unique symbol = core.InvalidP
*/
export type InvalidPubSubCapacityExceptionTypeId = typeof InvalidPubSubCapacityExceptionTypeId

/**
* @since 3.5.0
* @category symbols
*/
export const ExceededCapacityExceptionTypeId: unique symbol = core.ExceededCapacityExceptionTypeId

/**
* @since 3.5.0
* @category symbols
*/
export type ExceededCapacityExceptionTypeId = typeof ExceededCapacityExceptionTypeId

/**
* @since 2.0.0
* @category symbols
Expand Down Expand Up @@ -264,6 +276,18 @@ export interface InvalidPubSubCapacityException extends YieldableError {
readonly [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
}

/**
* Represents a checked exception which occurs when a resources capacity has
* been exceeded.
*
* @since 3.5.0
* @category models
*/
export interface ExceededCapacityException extends YieldableError {
readonly _tag: "ExceededCapacityException"
readonly [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
}

/**
* Represents a checked exception which occurs when a computation doesn't
* finish on schedule.
Expand Down Expand Up @@ -907,13 +931,35 @@ export const UnknownException: new(error: unknown, message?: string | undefined)
*/
export const isUnknownException: (u: unknown) => u is UnknownException = core.isUnknownException

/**
* Represents a checked exception which occurs when a resources capacity has
* been exceeded.
*
* @since 3.5.0
* @category errors
*/
export const ExceededCapacityException: new(message?: string | undefined) => ExceededCapacityException =
core.ExceededCapacityException

/**
* Returns `true` if the specified value is an `ExceededCapacityException`, `false`
* otherwise.
*
* @since 3.5.0
* @category refinements
*/
export const isExceededCapacityException: (u: unknown) => u is ExceededCapacityException =
core.isExceededCapacityException

/**
* Returns the specified `Cause` as a pretty-printed string.
*
* @since 2.0.0
* @category rendering
*/
export const pretty: <E>(cause: Cause<E>) => string = internal.pretty
export const pretty: <E>(cause: Cause<E>, options?: {
readonly renderErrorCause?: boolean | undefined
}) => string = internal.pretty

/**
* @since 3.2.0
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ export const repeated: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
*/
export const run: <OutErr, InErr, OutDone, InDone, Env>(
self: Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
) => Effect.Effect<OutDone, OutErr, Env> = channel.run
) => Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> = channel.run

/**
* Run the channel until it finishes with a done value or fails with an error
Expand All @@ -1929,7 +1929,7 @@ export const run: <OutErr, InErr, OutDone, InDone, Env>(
*/
export const runCollect: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
self: Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
) => Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Env> = channel.runCollect
) => Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Exclude<Env, Scope.Scope>> = channel.runCollect

/**
* Runs a channel until the end is received.
Expand All @@ -1939,7 +1939,7 @@ export const runCollect: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
*/
export const runDrain: <OutElem, OutErr, InErr, OutDone, InDone, Env>(
self: Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
) => Effect.Effect<OutDone, OutErr, Env> = channel.runDrain
) => Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> = channel.runDrain

/**
* Use a scoped effect to emit an output element.
Expand Down
6 changes: 6 additions & 0 deletions packages/effect/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export declare namespace Config {
}
}

/**
* @since 2.5.0
* @category models
*/
export type Success<T extends Config<any>> = [T] extends [Config<infer _A>] ? _A : never

/**
* @since 2.0.0
* @category models
Expand Down
Loading