Skip to content

Commit 046ad7d

Browse files
committed
checkpoint
1 parent 6c56f1d commit 046ad7d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/db/src/query/builder/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
439439
select[key] = toExpression(value)
440440
} else if (
441441
typeof value === `object` &&
442+
value !== null &&
442443
`type` in value &&
443444
(value.type === `agg` || value.type === `func`)
444445
) {

packages/db/src/query/builder/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ type SelectValue =
176176
| undefined // Optional values
177177
| { [key: string]: SelectValue }
178178
| PrecomputeRefStructure<any>
179+
| SpreadableRefProxy<any> // For spread operations without internal properties
179180
| Array<Ref<any>>
180181

181182
/**
@@ -247,6 +248,8 @@ export type ResultTypeFromSelect<TSelectObject> = {
247248
? T
248249
: TSelectObject[K] extends RefProxyFor<infer T>
249250
? T
251+
: TSelectObject[K] extends SpreadableRefProxy<infer T>
252+
? ResultTypeFromSelect<SpreadableRefProxy<T>>
250253
: TSelectObject[K] extends string
251254
? string
252255
: TSelectObject[K] extends number
@@ -550,6 +553,24 @@ export type RefProxy<T = any> = {
550553
}
551554
: {}) // Primitive types get no additional properties
552555

556+
/**
557+
* SpreadableRefProxy - Type for spread operations that excludes internal properties
558+
*
559+
* This type represents what you get when you spread a RefProxy. It omits the internal
560+
* properties (__refProxy, __path, __type) and only includes the user-facing properties
561+
* that should be part of the spread operation.
562+
*
563+
* This enables clean spread operations like:
564+
* ```typescript
565+
* select({
566+
* id: employees.id,
567+
* name: employees.name,
568+
* ...employees.profile // Only spreads bio, skills, contact - not __refProxy etc.
569+
* })
570+
* ```
571+
*/
572+
export type SpreadableRefProxy<T> = Omit<RefProxy<T>, '__refProxy' | '__path' | '__type'>
573+
553574
/**
554575
* Ref - The user-facing ref type with clean IDE display
555576
*

0 commit comments

Comments
 (0)