From ffe4f4e95db35fff6869e360b072e3837befa0a1 Mon Sep 17 00:00:00 2001 From: Michael Arnaldi Date: Fri, 26 Apr 2024 12:39:59 +0200 Subject: [PATCH] Make sure GenKind utils are backward compatible & don't generate loops (#2625) Co-authored-by: Tim --- .changeset/clever-meals-remember.md | 5 + .changeset/many-laws-flash.md | 5 + packages/effect/src/Cause.ts | 2 +- packages/effect/src/Effect.ts | 15 +-- packages/effect/src/Either.ts | 18 +++- packages/effect/src/Option.ts | 18 +++- packages/effect/src/STM.ts | 7 +- packages/effect/src/Utils.ts | 101 +++++++++++++----- packages/effect/src/internal/core-effect.ts | 9 +- packages/effect/src/internal/core.ts | 7 +- packages/effect/src/internal/effectable.ts | 4 +- packages/effect/src/internal/stm/core.ts | 3 +- packages/effect/src/internal/stm/stm.ts | 3 +- packages/effect/test/Either.test.ts | 6 +- packages/platform/src/Http/IncomingMessage.ts | 2 +- packages/platform/src/internal/worker.ts | 10 +- packages/sql-pg/examples/resolver.ts | 4 +- packages/sql-sqlite-node/test/Client.test.ts | 8 +- 18 files changed, 158 insertions(+), 69 deletions(-) create mode 100644 .changeset/clever-meals-remember.md create mode 100644 .changeset/many-laws-flash.md diff --git a/.changeset/clever-meals-remember.md b/.changeset/clever-meals-remember.md new file mode 100644 index 0000000000..edad1a6688 --- /dev/null +++ b/.changeset/clever-meals-remember.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Avoid circularity on generators diff --git a/.changeset/many-laws-flash.md b/.changeset/many-laws-flash.md new file mode 100644 index 0000000000..45297766d5 --- /dev/null +++ b/.changeset/many-laws-flash.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Make sure GenKind utilities are backward compatible diff --git a/packages/effect/src/Cause.ts b/packages/effect/src/Cause.ts index 3cc69821bb..9e90fb0b3f 100644 --- a/packages/effect/src/Cause.ts +++ b/packages/effect/src/Cause.ts @@ -194,7 +194,7 @@ export interface YieldableError extends Pipeable, Inspectable, Readonly { readonly [Stream.StreamTypeId]: Effect.Effect.VarianceStruct readonly [Sink.SinkTypeId]: Sink.Sink.VarianceStruct readonly [Channel.ChannelTypeId]: Channel.Channel.VarianceStruct - [Symbol.iterator](): Generator, never> + [Symbol.iterator](): Effect.EffectGenerator> } /** diff --git a/packages/effect/src/Effect.ts b/packages/effect/src/Effect.ts index da4c09685a..be87c87c6e 100644 --- a/packages/effect/src/Effect.ts +++ b/packages/effect/src/Effect.ts @@ -58,6 +58,7 @@ import type * as Supervisor from "./Supervisor.js" import type * as Tracer from "./Tracer.js" import type { Concurrency, Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js" import type * as Unify from "./Unify.js" +import type { YieldWrap } from "./Utils.js" // ------------------------------------------------------------------------------------- // models @@ -103,7 +104,7 @@ export interface Effect extends Effect.Vari * @category models */ export interface EffectGenerator> { - next(...args: ReadonlyArray): IteratorResult> + next(...args: ReadonlyArray): IteratorResult, Effect.Success> } /** @@ -1130,20 +1131,20 @@ export const dieSync: (evaluate: LazyArg) => Effect = core.dieSy * @category constructors */ export const gen: { - , AEff>( + >, AEff>( f: (resume: Adapter) => Generator ): Effect< AEff, - [Eff] extends [never] ? never : [Eff] extends [Effect] ? E : never, - [Eff] extends [never] ? never : [Eff] extends [Effect] ? R : never + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? E : never, + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? R : never > - , AEff>( + >, AEff>( self: Self, f: (this: Self, resume: Adapter) => Generator ): Effect< AEff, - [Eff] extends [never] ? never : [Eff] extends [Effect] ? E : never, - [Eff] extends [never] ? never : [Eff] extends [Effect] ? R : never + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? E : never, + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? R : never > } = effect.gen diff --git a/packages/effect/src/Either.ts b/packages/effect/src/Either.ts index 79e73d0ed0..131e034697 100644 --- a/packages/effect/src/Either.ts +++ b/packages/effect/src/Either.ts @@ -4,7 +4,7 @@ import * as Equivalence from "./Equivalence.js" import type { LazyArg } from "./Function.js" -import { constNull, constUndefined, dual, identity, pipe } from "./Function.js" +import { constNull, constUndefined, dual, identity } from "./Function.js" import type { TypeLambda } from "./HKT.js" import type { Inspectable } from "./Inspectable.js" import * as either from "./internal/either.js" @@ -14,7 +14,7 @@ import type { Predicate, Refinement } from "./Predicate.js" import { isFunction } from "./Predicate.js" import type { Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js" import type * as Unify from "./Unify.js" -import type * as Gen from "./Utils.js" +import * as Gen from "./Utils.js" /** * @category models @@ -698,17 +698,24 @@ export const all: > | Record(self: Either): Either => isLeft(self) ? right(self.left) : left(self.right) +const adapter = Gen.adapter() + /** * @category generators * @since 2.0.0 */ export const gen: Gen.Gen> = (f) => { - const iterator = f(pipe) + const iterator = f(adapter) let state: IteratorYieldResult | IteratorReturnResult = iterator.next() if (state.done) { return right(state.value) as any } else { let current = state.value + if (Gen.isGenKind(current)) { + current = current.value + } else { + current = Gen.yieldWrapGet(current) + } if (isLeft(current)) { return current } @@ -716,6 +723,11 @@ export const gen: Gen.Gen> = (f) state = iterator.next(current.right as never) if (!state.done) { current = state.value + if (Gen.isGenKind(current)) { + current = current.value + } else { + current = Gen.yieldWrapGet(current) + } if (isLeft(current)) { return current } diff --git a/packages/effect/src/Option.ts b/packages/effect/src/Option.ts index 8c7c4e203f..c689d510b1 100644 --- a/packages/effect/src/Option.ts +++ b/packages/effect/src/Option.ts @@ -5,7 +5,7 @@ import type { Either } from "./Either.js" import * as Equal from "./Equal.js" import * as Equivalence from "./Equivalence.js" import type { LazyArg } from "./Function.js" -import { constNull, constUndefined, dual, identity, isFunction, pipe } from "./Function.js" +import { constNull, constUndefined, dual, identity, isFunction } from "./Function.js" import type { TypeLambda } from "./HKT.js" import type { Inspectable } from "./Inspectable.js" import * as either from "./internal/either.js" @@ -16,7 +16,7 @@ import type { Pipeable } from "./Pipeable.js" import type { Predicate, Refinement } from "./Predicate.js" import type { Covariant, NoInfer, NotFunction } from "./Types.js" import type * as Unify from "./Unify.js" -import type * as Gen from "./Utils.js" +import * as Gen from "./Utils.js" /** * @category models @@ -1261,17 +1261,24 @@ export const bind: { */ export const Do: Option<{}> = some({}) +const adapter = Gen.adapter() + /** * @category generators * @since 2.0.0 */ export const gen: Gen.Gen> = (f) => { - const iterator = f(pipe) + const iterator = f(adapter) let state: IteratorYieldResult | IteratorReturnResult = iterator.next() if (state.done) { return some(state.value) } else { let current = state.value + if (Gen.isGenKind(current)) { + current = current.value + } else { + current = Gen.yieldWrapGet(current) + } if (isNone(current)) { return current } @@ -1279,6 +1286,11 @@ export const gen: Gen.Gen> = (f) state = iterator.next(current.value as never) if (!state.done) { current = state.value + if (Gen.isGenKind(current)) { + current = current.value + } else { + current = Gen.yieldWrapGet(current) + } if (isNone(current)) { return current } diff --git a/packages/effect/src/STM.ts b/packages/effect/src/STM.ts index 6764342494..e084d960c1 100644 --- a/packages/effect/src/STM.ts +++ b/packages/effect/src/STM.ts @@ -16,6 +16,7 @@ import type { Pipeable } from "./Pipeable.js" import type { Predicate, Refinement } from "./Predicate.js" import type { Covariant, MergeRecord, NoInfer } from "./Types.js" import type * as Unify from "./Unify.js" +import type { YieldWrap } from "./Utils.js" /** * @since 2.0.0 @@ -1064,12 +1065,12 @@ export interface Adapter { * @since 2.0.0 * @category constructors */ -export const gen: , AEff>( +export const gen: >, AEff>( f: (resume: Adapter) => Generator ) => STM< AEff, - [Eff] extends [never] ? never : [Eff] extends [STM] ? E : never, - [Eff] extends [never] ? never : [Eff] extends [STM] ? R : never + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? E : never, + [Eff] extends [never] ? never : [Eff] extends [YieldWrap>] ? R : never > = stm.gen /** diff --git a/packages/effect/src/Utils.ts b/packages/effect/src/Utils.ts index 6b9800af0e..8fd97e8ab5 100644 --- a/packages/effect/src/Utils.ts +++ b/packages/effect/src/Utils.ts @@ -3,7 +3,8 @@ */ import { identity } from "./Function.js" import type { Kind, TypeLambda } from "./HKT.js" -import { isNullable } from "./Predicate.js" +import { getBugErrorMessage } from "./internal/errors.js" +import { isNullable, isObject } from "./Predicate.js" import type * as Types from "./Types.js" /* @@ -41,6 +42,12 @@ export interface GenKind extends Variance, A> } +/** + * @category predicates + * @since 3.0.6 + */ +export const isGenKind = (u: unknown): u is GenKind => isObject(u) && GenKindTypeId in u + /** * @category constructors * @since 2.0.0 @@ -173,13 +180,19 @@ export interface Variance { * @since 2.0.0 */ export interface Gen { - | Kind, A>( + | YieldWrap>, A>( body: (resume: Z) => Generator ): Kind< F, - [K] extends [Variance] ? R : [K] extends [Kind] ? R : never, - [K] extends [Variance] ? O : [K] extends [Kind] ? O : never, - [K] extends [Variance] ? E : [K] extends [Kind] ? E : never, + [K] extends [Variance] ? R + : [K] extends [YieldWrap>] ? R + : never, + [K] extends [Variance] ? O + : [K] extends [YieldWrap>] ? O + : never, + [K] extends [Variance] ? E + : [K] extends [YieldWrap>] ? E + : never, A > } @@ -191,22 +204,22 @@ export interface Gen { export interface Adapter { <_R, _O, _E, _A>( self: Kind - ): Kind - (a: A, ab: (a: A) => Kind): Kind - (a: A, ab: (a: A) => B, bc: (b: B) => Kind): Kind + ): GenKind + (a: A, ab: (a: A) => Kind): GenKind + (a: A, ab: (a: A) => B, bc: (b: B) => Kind): GenKind ( a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -214,7 +227,7 @@ export interface Adapter { cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -223,7 +236,7 @@ export interface Adapter { de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -233,7 +246,7 @@ export interface Adapter { ef: (e: E) => F, fg: (f: F) => G, gh: (g: F) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -244,7 +257,7 @@ export interface Adapter { fg: (f: F) => G, gh: (g: G) => H, hi: (g: H) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -256,7 +269,7 @@ export interface Adapter { gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -269,7 +282,7 @@ export interface Adapter { hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -283,7 +296,7 @@ export interface Adapter { ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -298,7 +311,7 @@ export interface Adapter { jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -314,7 +327,7 @@ export interface Adapter { kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -331,7 +344,7 @@ export interface Adapter { lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -349,7 +362,7 @@ export interface Adapter { mn: (m: M) => N, no: (n: N) => O, op: (o: O) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -368,7 +381,7 @@ export interface Adapter { no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -388,7 +401,7 @@ export interface Adapter { op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -409,7 +422,7 @@ export interface Adapter { pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -431,7 +444,7 @@ export interface Adapter { qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => Kind - ): Kind + ): GenKind ( a: A, ab: (a: A) => B, @@ -454,7 +467,7 @@ export interface Adapter { rs: (r: R) => S, st: (s: S) => T, tu: (s: T) => Kind - ): Kind + ): GenKind } /** @@ -466,7 +479,7 @@ export const adapter: () => Adapter = () => (function() for (let i = 1; i < arguments.length; i++) { x = arguments[i](x) } - return x + return new GenKindImpl(x) as any }) const defaultIncHi = 0x14057b7e @@ -699,3 +712,37 @@ function add64( out[0] = hi out[1] = lo } + +/** + * @since 3.0.6 + */ +export const YieldWrapTypeId = Symbol.for("effect/Utils/YieldWrap") + +/** + * @since 3.0.6 + */ +export class YieldWrap { + /** + * @since 3.0.6 + */ + readonly #value: T + constructor(value: T) { + this.#value = value + } + /** + * @since 3.0.6 + */ + [YieldWrapTypeId](): T { + return this.#value + } +} + +/** + * @since 3.0.6 + */ +export function yieldWrapGet(self: YieldWrap): T { + if (typeof self === "object" && self !== null && YieldWrapTypeId in self) { + return self[YieldWrapTypeId]() + } + throw new Error(getBugErrorMessage("yieldWrapGet")) +} diff --git a/packages/effect/src/internal/core-effect.ts b/packages/effect/src/internal/core-effect.ts index 5cfcbcbf86..6ea9064aef 100644 --- a/packages/effect/src/internal/core-effect.ts +++ b/packages/effect/src/internal/core-effect.ts @@ -26,6 +26,7 @@ import * as Ref from "../Ref.js" import type * as runtimeFlagsPatch from "../RuntimeFlagsPatch.js" import * as Tracer from "../Tracer.js" import type { MergeRecord, NoInfer } from "../Types.js" +import { yieldWrapGet } from "../Utils.js" import * as internalCause from "./cause.js" import { clockTag } from "./clock.js" import * as core from "./core.js" @@ -788,9 +789,11 @@ export const gen: typeof Effect.gen = function() { const state = iterator.next() const run = ( state: IteratorYieldResult | IteratorReturnResult - ): Effect.Effect => (state.done - ? core.succeed(state.value) - : core.flatMap(state.value, (val: any) => run(iterator.next(val)))) + ): Effect.Effect => { + return (state.done + ? core.succeed(state.value) + : core.flatMap(yieldWrapGet(state.value) as any, (val: any) => run(iterator.next(val)))) + } return run(state) }) } diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index c5a37aba4b..2d6de6c013 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -36,6 +36,7 @@ import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js" import type * as Scope from "../Scope.js" import type * as Tracer from "../Tracer.js" import type { NoInfer, NotFunction } from "../Types.js" +import { YieldWrap } from "../Utils.js" import * as _blockedRequests from "./blockedRequests.js" import * as internalCause from "./cause.js" import * as deferred from "./deferred.js" @@ -180,7 +181,7 @@ class EffectPrimitive { return this.toJSON() } [Symbol.iterator]() { - return new SingleShotGen(this) + return new SingleShotGen(new YieldWrap(this)) } } @@ -221,7 +222,7 @@ class EffectPrimitiveFailure { return this.toJSON() } [Symbol.iterator]() { - return new SingleShotGen(this) + return new SingleShotGen(new YieldWrap(this)) } } @@ -262,7 +263,7 @@ class EffectPrimitiveSuccess { return this.toJSON() } [Symbol.iterator]() { - return new SingleShotGen(this) + return new SingleShotGen(new YieldWrap(this)) } } diff --git a/packages/effect/src/internal/effectable.ts b/packages/effect/src/internal/effectable.ts index 258f19ab8a..b5c9f22c6b 100644 --- a/packages/effect/src/internal/effectable.ts +++ b/packages/effect/src/internal/effectable.ts @@ -6,8 +6,8 @@ import * as Hash from "../Hash.js" import { pipeArguments } from "../Pipeable.js" import type * as Sink from "../Sink.js" import type * as Stream from "../Stream.js" +import { SingleShotGen, YieldWrap } from "../Utils.js" import * as OpCodes from "./opCodes/effect.js" -import * as SingleShotGen from "./singleShotGen.js" import * as version from "./version.js" /** @internal */ @@ -77,7 +77,7 @@ export const EffectPrototype: Effect.Effect & Equal.Equal = { return Hash.cached(this, Hash.random(this)) }, [Symbol.iterator]() { - return new SingleShotGen.SingleShotGen(this) as any + return new SingleShotGen(new YieldWrap(this)) as any }, pipe() { return pipeArguments(this, arguments) diff --git a/packages/effect/src/internal/stm/core.ts b/packages/effect/src/internal/stm/core.ts index f632d8324b..b60bf51a93 100644 --- a/packages/effect/src/internal/stm/core.ts +++ b/packages/effect/src/internal/stm/core.ts @@ -15,6 +15,7 @@ import { hasProperty } from "../../Predicate.js" import type * as Scheduler from "../../Scheduler.js" import type * as STM from "../../STM.js" import { StreamTypeId } from "../../Stream.js" +import { YieldWrap } from "../../Utils.js" import { ChannelTypeId } from "../core-stream.js" import { withFiberRuntime } from "../core.js" import { effectVariance } from "../effectable.js" @@ -172,7 +173,7 @@ class STMPrimitive implements STM.STM { return Hash.cached(this, Hash.random(this)) } [Symbol.iterator]() { - return new SingleShotGen(this) as any + return new SingleShotGen(new YieldWrap(this)) as any } commit(this: STM.STM): Effect.Effect { return unsafeAtomically(this, constVoid, constVoid) diff --git a/packages/effect/src/internal/stm/stm.ts b/packages/effect/src/internal/stm/stm.ts index d1d306c485..e7e847b585 100644 --- a/packages/effect/src/internal/stm/stm.ts +++ b/packages/effect/src/internal/stm/stm.ts @@ -13,6 +13,7 @@ import type { Predicate, Refinement } from "../../Predicate.js" import * as predicate from "../../Predicate.js" import type * as STM from "../../STM.js" import type { MergeRecord, NoInfer } from "../../Types.js" +import { yieldWrapGet } from "../../Utils.js" import * as effectCore from "../core.js" import * as core from "./core.js" import * as Journal from "./stm/journal.js" @@ -626,7 +627,7 @@ export const gen: typeof STM.gen = (f) => ): STM.STM => state.done ? core.succeed(state.value) : - core.flatMap(state.value, (val: any) => run(iterator.next(val as never))) + core.flatMap(yieldWrapGet(state.value) as any, (val: any) => run(iterator.next(val as never))) return run(state) }) diff --git a/packages/effect/test/Either.test.ts b/packages/effect/test/Either.test.ts index 8a985518f6..eac10bf20f 100644 --- a/packages/effect/test/Either.test.ts +++ b/packages/effect/test/Either.test.ts @@ -19,11 +19,11 @@ describe("Either", () => { return 10 }) const c = Either.gen(function*() { - yield Either.right(1) - yield Either.right(2) + yield* Either.right(1) + yield* Either.right(2) }) const d = Either.gen(function*() { - yield Either.right(1) + yield* Either.right(1) return yield* Either.right(2) }) const e = Either.gen(function*() { diff --git a/packages/platform/src/Http/IncomingMessage.ts b/packages/platform/src/Http/IncomingMessage.ts index c7a33d1538..e0db9e2697 100644 --- a/packages/platform/src/Http/IncomingMessage.ts +++ b/packages/platform/src/Http/IncomingMessage.ts @@ -20,7 +20,7 @@ import type * as UrlParams from "./UrlParams.js" * @since 1.0.0 * @category type ids */ -export const TypeId = Symbol.for("@effect/platform/Http/IncomingMessage") +export const TypeId: unique symbol = Symbol.for("@effect/platform/Http/IncomingMessage") /** * @since 1.0.0 diff --git a/packages/platform/src/internal/worker.ts b/packages/platform/src/internal/worker.ts index e465fabf85..5b943e09a6 100644 --- a/packages/platform/src/internal/worker.ts +++ b/packages/platform/src/internal/worker.ts @@ -95,9 +95,9 @@ export const makeManager = Effect.gen(function*() { Effect.succeed const outbound = queue ?? (yield* defaultQueue()) - yield Effect.addFinalizer(() => outbound.shutdown) + yield* Effect.addFinalizer(() => outbound.shutdown) - yield Effect.gen(function*() { + yield* Effect.gen(function*() { const readyLatch = yield* Deferred.make() const backing = yield* platform.spawn>(spawn(id)) const send = pipe( @@ -138,7 +138,7 @@ export const makeManager = Effect.gen(function*() { Effect.forkScoped ) - yield Effect.addFinalizer(() => + yield* Effect.addFinalizer(() => Effect.zipRight( Effect.forEach(requestMap.values(), ([queue]) => Queue.offer(queue, Exit.failCause(Cause.empty)), { discard: true @@ -241,7 +241,7 @@ export const makeManager = Effect.gen(function*() { executeRelease ) - yield semaphore.take(1).pipe( + yield* semaphore.take(1).pipe( Effect.zipRight(outbound.take), Effect.flatMap(([id, request, span]) => pipe( @@ -275,7 +275,7 @@ export const makeManager = Effect.gen(function*() { ) if (initialMessage) { - yield Effect.sync(initialMessage).pipe( + yield* Effect.sync(initialMessage).pipe( Effect.flatMap(executeEffect), Effect.mapError((error) => new WorkerError({ reason: "spawn", error })) ) diff --git a/packages/sql-pg/examples/resolver.ts b/packages/sql-pg/examples/resolver.ts index 6f970c6184..321fa0c962 100644 --- a/packages/sql-pg/examples/resolver.ts +++ b/packages/sql-pg/examples/resolver.ts @@ -16,7 +16,7 @@ const InsertPersonSchema = Schema.Struct(Person.fields).pipe( const program = Effect.gen(function*() { const sql = yield* Pg.client.PgClient - yield sql`TRUNCATE TABLE people RESTART IDENTITY CASCADE` + yield* sql`TRUNCATE TABLE people RESTART IDENTITY CASCADE` const Insert = yield* Pg.resolver.ordered("InsertPerson", { Request: InsertPersonSchema, @@ -49,7 +49,7 @@ const program = Effect.gen(function*() { ) ) - yield sql`SELECT * FROM people`.pipe( + yield* sql`SELECT * FROM people`.pipe( Effect.andThen(Effect.fail("boom")), sql.withTransaction, Effect.ignore diff --git a/packages/sql-sqlite-node/test/Client.test.ts b/packages/sql-sqlite-node/test/Client.test.ts index 485acda645..ad26d5dc09 100644 --- a/packages/sql-sqlite-node/test/Client.test.ts +++ b/packages/sql-sqlite-node/test/Client.test.ts @@ -31,8 +31,8 @@ describe("Client", () => { it.scoped("withTransaction", () => Effect.gen(function*() { const sql = yield* makeClient - yield sql`CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)` - yield sql.withTransaction(sql`INSERT INTO test (name) VALUES ('hello')`) + yield* sql`CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)` + yield* sql.withTransaction(sql`INSERT INTO test (name) VALUES ('hello')`) const rows = yield* sql`SELECT * FROM test` assert.deepStrictEqual(rows, [{ id: 1, name: "hello" }]) })) @@ -40,8 +40,8 @@ describe("Client", () => { it.scoped("withTransaction rollback", () => Effect.gen(function*() { const sql = yield* makeClient - yield sql`CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)` - yield sql`INSERT INTO test (name) VALUES ('hello')`.pipe( + yield* sql`CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)` + yield* sql`INSERT INTO test (name) VALUES ('hello')`.pipe( Effect.andThen(Effect.fail("boom")), sql.withTransaction, Effect.ignore