File tree Expand file tree Collapse file tree 4 files changed +31
-25
lines changed Expand file tree Collapse file tree 4 files changed +31
-25
lines changed Original file line number Diff line number Diff line change 1
1
import type { Where , WhereField } from '../types/index.js'
2
2
3
- // Take a where query and flatten it to all top-level operators
4
- const flattenWhereToOperators = ( query : Where ) : WhereField [ ] =>
5
- Object . entries ( query ) . reduce ( ( flattenedConstraints , [ key , val ] ) => {
6
- if ( ( key === 'and' || key === 'or' ) && Array . isArray ( val ) ) {
7
- return [
8
- ...flattenedConstraints ,
9
- ...val . reduce ( ( subVals , subVal ) => {
10
- return [ ...subVals , ...flattenWhereToOperators ( subVal ) ]
11
- } , [ ] ) ,
12
- ]
13
- }
3
+ /**
4
+ * Take a where query and flatten it to all top-level operators
5
+ */
6
+ export function flattenWhereToOperators ( query : Where ) : WhereField [ ] {
7
+ const result : WhereField [ ] = [ ]
14
8
15
- return [ ...flattenedConstraints , val ]
16
- } , [ ] )
9
+ for ( const [ key , value ] of Object . entries ( query ) ) {
10
+ if ( ( key === 'and' || key === 'or' ) && Array . isArray ( value ) ) {
11
+ for ( const subQuery of value ) {
12
+ const flattenedSub = flattenWhereToOperators ( subQuery )
13
+ result . push ( ...flattenedSub )
14
+ }
15
+ } else {
16
+ result . push ( value as WhereField )
17
+ }
18
+ }
17
19
18
- export default flattenWhereToOperators
20
+ return result
21
+ }
Original file line number Diff line number Diff line change @@ -26,18 +26,21 @@ type Args = {
26
26
}
27
27
)
28
28
29
- const flattenWhere = ( query : Where ) : WhereField [ ] =>
30
- Object . entries ( query ) . reduce ( ( flattenedConstraints , [ key , val ] ) => {
29
+ const flattenWhere = ( query : Where ) : WhereField [ ] => {
30
+ const flattenedConstraints : WhereField [ ] = [ ]
31
+
32
+ for ( const [ key , val ] of Object . entries ( query ) ) {
31
33
if ( ( key === 'and' || key === 'or' ) && Array . isArray ( val ) ) {
32
- const subWhereConstraints : Where [ ] = val . reduce ( ( acc , subVal ) => {
33
- const subWhere = flattenWhere ( subVal )
34
- return [ ... acc , ... subWhere ]
35
- } , [ ] )
36
- return [ ... flattenedConstraints , ... subWhereConstraints ]
34
+ for ( const subVal of val ) {
35
+ flattenedConstraints . push ( ... flattenWhere ( subVal ) )
36
+ }
37
+ } else {
38
+ flattenedConstraints . push ( { [ key ] : val } )
37
39
}
40
+ }
38
41
39
- return [ ... flattenedConstraints , { [ key ] : val } ]
40
- } , [ ] )
42
+ return flattenedConstraints
43
+ }
41
44
42
45
export async function validateQueryPaths ( {
43
46
collectionConfig,
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ export const sanitizeJoinQuery = async ({
74
74
overrideAccess,
75
75
req,
76
76
// incoming where input, but we shouldn't validate generated from the access control.
77
- where : deepCopyObjectSimple ( joinQuery . where ) ,
77
+ where : joinQuery . where ,
78
78
} ) ,
79
79
)
80
80
Original file line number Diff line number Diff line change @@ -1038,7 +1038,7 @@ export type * from './config/types.js'
1038
1038
export { combineQueries } from './database/combineQueries.js'
1039
1039
export { createDatabaseAdapter } from './database/createDatabaseAdapter.js'
1040
1040
export { defaultBeginTransaction } from './database/defaultBeginTransaction.js'
1041
- export { default as flattenWhereToOperators } from './database/flattenWhereToOperators.js'
1041
+ export { flattenWhereToOperators } from './database/flattenWhereToOperators.js'
1042
1042
export { getLocalizedPaths } from './database/getLocalizedPaths.js'
1043
1043
export { createMigration } from './database/migrations/createMigration.js'
1044
1044
export { getMigrations } from './database/migrations/getMigrations.js'
You can’t perform that action at this time.
0 commit comments