@@ -3,9 +3,29 @@ import { CollectionConfigBuilder } from "./live/collection-config-builder.js"
3
3
import type { LiveQueryCollectionConfig } from "./live/types.js"
4
4
import type { InitialQueryBuilder , QueryBuilder } from "./builder/index.js"
5
5
import type { Collection } from "../collection/index.js"
6
- import type { CollectionConfig , UtilsRecord } from "../types.js"
6
+ import type {
7
+ CollectionConfig ,
8
+ CollectionConfigSingleRowOption ,
9
+ NonSingleResult ,
10
+ SingleResult ,
11
+ UtilsRecord ,
12
+ } from "../types.js"
7
13
import type { Context , GetResult } from "./builder/types.js"
8
14
15
+ type CollectionConfigForContext <
16
+ TContext extends Context ,
17
+ TResult extends object ,
18
+ > = TContext extends SingleResult
19
+ ? CollectionConfigSingleRowOption < TResult > & SingleResult
20
+ : CollectionConfigSingleRowOption < TResult > & NonSingleResult
21
+
22
+ type CollectionForContext <
23
+ TContext extends Context ,
24
+ TResult extends object ,
25
+ > = TContext extends SingleResult
26
+ ? Collection < TResult > & SingleResult
27
+ : Collection < TResult > & NonSingleResult
28
+
9
29
/**
10
30
* Creates live query collection options for use with createCollection
11
31
*
@@ -35,12 +55,15 @@ export function liveQueryCollectionOptions<
35
55
TResult extends object = GetResult < TContext > ,
36
56
> (
37
57
config : LiveQueryCollectionConfig < TContext , TResult >
38
- ) : CollectionConfig < TResult > {
58
+ ) : CollectionConfigForContext < TContext , TResult > {
39
59
const collectionConfigBuilder = new CollectionConfigBuilder <
40
60
TContext ,
41
61
TResult
42
62
> ( config )
43
- return collectionConfigBuilder . getConfig ( )
63
+ return collectionConfigBuilder . getConfig ( ) as CollectionConfigForContext <
64
+ TContext ,
65
+ TResult
66
+ >
44
67
}
45
68
46
69
/**
@@ -83,7 +106,7 @@ export function createLiveQueryCollection<
83
106
TResult extends object = GetResult < TContext > ,
84
107
> (
85
108
query : ( q : InitialQueryBuilder ) => QueryBuilder < TContext >
86
- ) : Collection < TResult , string | number , { } >
109
+ ) : CollectionForContext < TContext , TResult >
87
110
88
111
// Overload 2: Accept full config object with optional utilities
89
112
export function createLiveQueryCollection <
@@ -92,7 +115,7 @@ export function createLiveQueryCollection<
92
115
TUtils extends UtilsRecord = { } ,
93
116
> (
94
117
config : LiveQueryCollectionConfig < TContext , TResult > & { utils ?: TUtils }
95
- ) : Collection < TResult , string | number , TUtils >
118
+ ) : CollectionForContext < TContext , TResult >
96
119
97
120
// Implementation
98
121
export function createLiveQueryCollection <
@@ -103,7 +126,7 @@ export function createLiveQueryCollection<
103
126
configOrQuery :
104
127
| ( LiveQueryCollectionConfig < TContext , TResult > & { utils ?: TUtils } )
105
128
| ( ( q : InitialQueryBuilder ) => QueryBuilder < TContext > )
106
- ) : Collection < TResult , string | number , TUtils > {
129
+ ) : CollectionForContext < TContext , TResult > {
107
130
// Determine if the argument is a function (query) or a config object
108
131
if ( typeof configOrQuery === `function` ) {
109
132
// Simple query function case
@@ -113,7 +136,10 @@ export function createLiveQueryCollection<
113
136
) => QueryBuilder < TContext > ,
114
137
}
115
138
const options = liveQueryCollectionOptions < TContext , TResult > ( config )
116
- return bridgeToCreateCollection ( options )
139
+ return bridgeToCreateCollection ( options ) as CollectionForContext <
140
+ TContext ,
141
+ TResult
142
+ >
117
143
} else {
118
144
// Config object case
119
145
const config = configOrQuery as LiveQueryCollectionConfig <
@@ -124,7 +150,7 @@ export function createLiveQueryCollection<
124
150
return bridgeToCreateCollection ( {
125
151
...options ,
126
152
utils : config . utils ,
127
- } )
153
+ } ) as CollectionForContext < TContext , TResult >
128
154
}
129
155
}
130
156
0 commit comments