Skip to content

fix: orm interfaces findX#1026

Open
yyyyaaa wants to merge 7 commits intomainfrom
fix/orm-interfaces-findx-752
Open

fix: orm interfaces findX#1026
yyyyaaa wants to merge 7 commits intomainfrom
fix/orm-interfaces-findx-752

Conversation

@yyyyaaa
Copy link
Copy Markdown
Contributor

@yyyyaaa yyyyaaa commented Apr 25, 2026

fixes https://github.com/constructive-io/constructive-planning/issues/752

ORM model interfaces (the core fix)

findFirst — single object return ✓
findFirst(
args: FindFirstArgs<S, UserFilter, UserOrderBy> & { select: S } & StrictSelect<S, UserSelect>
): QueryBuilder<{
user: InferSelectResult<UserWithRelations, S> | null; // ← singular, was array
}>
With transform callback: (data) => ({ user: data.users?.nodes?.[0] ?? null })

findOne — single object return ✓
Same { user: ... | null } shape as findFirst, using buildFindManyDocument with where: { id: { equalTo: args.id } }, first: 1.

Coverage across SDKs (constructive-sdk only — others mirror)

  • findFirst<...> declarations: 168 (auth: 9, objects: 5, admin: 34, public: 120)
  • Unique singular { xxx: InferSelectResult<XxxWithRelations, S> | null } return shapes: 120 distinct entities
  • Regression check: 0 instances of findFirst returning an array

FindFirstArgs interface (in generated select-types.ts)

export interface FindFirstArgs<TSelect, TWhere, TOrderBy = never> {
select?: TSelect;
where?: TWhere;
orderBy?: TOrderBy[]; // ← new orderBy support
}

CLI (sdk/constructive-cli)

  • Help text includes --orderBy under "Find-First Options" (verified user.ts and others)
  • handleFindFirst calls parseFindFirstArgs<FindFirstArgs<UserSelect, UserFilter, UserOrderBy>>(argv, defaultSelect)

React hooks (sdk/constructive-react)

  • useUserQuery returns UseQueryResult<{ user: InferSelectResult<UserWithRelations, S> | null }>
  • Delegates to getClient().user.findOne(...) — picks up the new singular shape transparently
  • fetchUserQuery and prefetchUserQuery mirror the same contract

migrate-client SDK

Same pattern verified on SqlAction.findFirst — returns { sqlAction: ... | null } with SqlActionOrderBy type param.

Build + typecheck (already done)

  • All 4 SDKs build clean
  • tsc --noEmit passes with zero errors on all 4 SDKs
  • 306 codegen tests pass, 119 snapshots green

@yyyyaaa yyyyaaa requested a review from pyramation April 25, 2026 06:06
@pyramation
Copy link
Copy Markdown
Contributor

nice is this ready to review?

@yyyyaaa
Copy link
Copy Markdown
Contributor Author

yyyyaaa commented Apr 28, 2026

yep, pr ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants