From 5d12fecca18baa10f91643d51513d23032b815b8 Mon Sep 17 00:00:00 2001 From: jfet97 Date: Thu, 10 Jul 2025 10:44:18 +0200 Subject: [PATCH 1/3] test: add projection test for nested arrays in union --- packages/infra/test/query.test.ts | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/infra/test/query.test.ts b/packages/infra/test/query.test.ts index 38bd6d0bd..90e47efaf 100644 --- a/packages/infra/test/query.test.ts +++ b/packages/infra/test/query.test.ts @@ -1084,3 +1084,60 @@ it("refine union with nested union", () => >() }) .pipe(Effect.provide(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)) + +it("projects on nested arrays union with nested union", () => + Effect + .gen(function*() { + class Item extends S.TaggedClass()("Item", { + id: S.String, + a: S.String, + bs: S.Array(S.Struct({ + b1: S.String, + b2: S.String + })) + }) {} + + const repo = yield* makeRepo("items", Item, { + makeInitial: Effect.sync(() => [ + new Item({ + id: "1", + a: "a1", + bs: [ + { b1: "b1-1", b2: "b2-1" }, + { b1: "b1-2", b2: "b2-2" } + ] + }) + ]) + }) + + const base = make() + + const res_query = base.pipe( + where("id", "1"), + project(S.Struct({ id: S.String, bs: S.Struct({ b1: S.String }) })) + ) + + const res = yield* repo.query( + () => res_query + ) + + expectTypeOf(res).toEqualTypeOf< + readonly { + readonly id: string + readonly bs: { + readonly b1: string + } + }[] + >() + + expect(res).toEqual([ + { + id: "1", + bs: [ + { b1: "b1-1" }, + { b1: "b1-2" } + ] + } + ]) + }) + .pipe(Effect.provide(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)) From 98d453f3e76d72f848b1e6fdca1ac66ebdbcde16 Mon Sep 17 00:00:00 2001 From: jfet97 Date: Thu, 10 Jul 2025 10:58:18 +0200 Subject: [PATCH 2/3] fix: enhance repo tests with MemoryStoreLive and request context setup --- packages/infra/test/query.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/infra/test/query.test.ts b/packages/infra/test/query.test.ts index 90e47efaf..d8bb774a8 100644 --- a/packages/infra/test/query.test.ts +++ b/packages/infra/test/query.test.ts @@ -153,7 +153,12 @@ it("works with repo", () => expect(q1).toEqual(items.slice(0, 2).toReversed().map(Struct.pick("id", "displayName"))) expect(q2).toEqual(items.slice(0, 2).toReversed().map(Struct.pick("displayName"))) }) - .pipe(Effect.provide(Layer.mergeAll(SomethingRepo.Test, SomeService.toLayer())), Effect.runPromise)) + .pipe( + Effect.provide(Layer.mergeAll(SomethingRepo.Test, SomeService.toLayer())), + Effect.provide(MemoryStoreLive), + setupRequestContextFromCurrent(), + Effect.runPromise + )) it("collect", () => Effect @@ -220,7 +225,12 @@ it("collect", () => expectTypeOf(value).toEqualTypeOf() expect(value).toEqual("hi") }) - .pipe(Effect.provide(Layer.mergeAll(SomethingRepo.Test, SomeService.toLayer())), Effect.runPromise)) + .pipe( + Effect.provide(Layer.mergeAll(SomethingRepo.Test, SomeService.toLayer())), + Effect.provide(MemoryStoreLive), + setupRequestContextFromCurrent(), + Effect.runPromise + )) class Person extends S.ExtendedTaggedClass()("person", { id: S.String, From e71e955260fa1d651db71fd31f5070794d78e351 Mon Sep 17 00:00:00 2001 From: jfet97 Date: Thu, 10 Jul 2025 11:18:17 +0200 Subject: [PATCH 3/3] fix: update project structure to support nested arrays in union --- packages/infra/test/query.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/infra/test/query.test.ts b/packages/infra/test/query.test.ts index d8bb774a8..e09073b2f 100644 --- a/packages/infra/test/query.test.ts +++ b/packages/infra/test/query.test.ts @@ -1124,7 +1124,7 @@ it("projects on nested arrays union with nested union", () => const res_query = base.pipe( where("id", "1"), - project(S.Struct({ id: S.String, bs: S.Struct({ b1: S.String }) })) + project(S.Struct({ id: S.String, bs: S.Array(S.Struct({ b1: S.String })) })) ) const res = yield* repo.query( @@ -1134,9 +1134,9 @@ it("projects on nested arrays union with nested union", () => expectTypeOf(res).toEqualTypeOf< readonly { readonly id: string - readonly bs: { + readonly bs: readonly { readonly b1: string - } + }[] }[] >()