Skip to content

Commit a828366

Browse files
committed
fix(schema): pass array flags
1 parent fa3b2c9 commit a828366

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

.changeset/wild-bags-open.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@dreamkit/schema": patch
3+
---
4+
5+
Fix query types

packages/schema/src/types/ObjectType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export type QueryObjectType<
7171
? never
7272
: K]: P[K] extends MinimalObjectType<any, any>
7373
? QueryObjectType<P[K], Q>
74-
: P[K] extends MinimalArrayType
74+
: P[K] extends MinimalArrayType<any, infer ArrayFlags>
7575
? P[K]["items"] extends MinimalObjectType<any, any>
76-
? ArrayType<QueryObjectType<P[K]["items"], Q>>
76+
? ArrayType<QueryObjectType<P[K]["items"], Q>, ArrayFlags>
7777
: QueryObjectTypeResult<Q, P[K]>
7878
: QueryObjectTypeResult<Q, P[K]>;
7979
} & {},

packages/schema/test/types/ObjectType.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,58 @@ describe("object.refine", () => {
587587
});
588588
});
589589

590+
describe("object.query", () => {
591+
const groupItem = s.object({
592+
id: s.string().flags({ internal: true }),
593+
value: s.string(),
594+
});
595+
it("omit internal with nullable array", () => {
596+
const o = s.object({
597+
groups: s.array(groupItem).nullable(),
598+
});
599+
const o2 = o.query({ internal: false });
600+
const o2Flags = o2.props.groups.flagsValue;
601+
const props = o2.props.groups.items.props;
602+
type names = keyof typeof props;
603+
expectTypeOf<names>().toEqualTypeOf<"value">();
604+
expectTypeOf<typeof o2Flags>().toEqualTypeOf<{
605+
nullable: true;
606+
}>();
607+
expect(o2Flags.nullable).toBe(true);
608+
expect(Object.keys(props)).toEqual(["value"]);
609+
});
610+
it("omit internal with optional array", () => {
611+
const o = s.object({
612+
groups: s.array(groupItem).optional(),
613+
});
614+
const o2 = o.query({ internal: false });
615+
const o2Flags = o2.props.groups.flagsValue;
616+
const props = o2.props.groups.items.props;
617+
type names = keyof typeof props;
618+
expectTypeOf<names>().toEqualTypeOf<"value">();
619+
expectTypeOf<typeof o2Flags>().toEqualTypeOf<{
620+
optional: true;
621+
}>();
622+
expect(o2Flags.optional).toBe(true);
623+
expect(Object.keys(props)).toEqual(["value"]);
624+
});
625+
it("omit internal with nullable object", () => {
626+
const o = s.object({
627+
groups: groupItem.nullable(),
628+
});
629+
const o2 = o.query({ internal: false });
630+
const o2Flags = o2.props.groups.flagsValue;
631+
const props = o2.props.groups.props;
632+
type names = keyof typeof props;
633+
expectTypeOf<names>().toEqualTypeOf<"value">();
634+
expectTypeOf<typeof o2Flags>().toEqualTypeOf<{
635+
nullable: true;
636+
}>();
637+
expect(o2Flags.nullable).toBe(true);
638+
expect(Object.keys(props)).toEqual(["value"]);
639+
});
640+
});
641+
590642
describe("object.fit", () => {
591643
const o = s.object({
592644
id: s.string().flags({ pk: true, internal: true }),

0 commit comments

Comments
 (0)