Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/runtime/query/match/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export const detectProperties = (keys: string[]) => {
}

export const withoutKeys = (keys: string[] = []) => (obj: any) => {
if (keys.length === 0) {
if (keys.length === 0 || !obj) {
return obj
}
const { prefixes, properties } = detectProperties(keys)
return _pick(obj, key => !properties.includes(key) && !prefixes.includes(key[0]))
}

export const withKeys = (keys: string[] = []) => (obj: any) => {
if (keys.length === 0) {
if (keys.length === 0 || !obj) {
return obj
}
const { prefixes, properties } = detectProperties(keys)
Expand Down
24 changes: 24 additions & 0 deletions test/features/query/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ describe('Database Provider', () => {
assert(result[2] === null)
})

test('Surround and using only method', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))
const result = await createQuery(fetcher)
.only(['_path'])
.findSurround({ id: 3 }, { before: 2, after: 1 })

assert((result as Array<any>).length === 3)
assert(result[0]._path === '/a')
assert(result[1]._path === '/b')
assert(result[2] === null)
})

test('Surround and using without method', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))
const result = await createQuery(fetcher)
.without('id')
.findSurround({ id: 3 }, { before: 2, after: 1 })

assert((result as Array<any>).length === 3)
assert(result[0]._path === '/a')
assert(result[1]._path === '/b')
assert(result[2] === null)
})

test('Chain multiple where conditions', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, path: '/a' }, { id: 2, path: '/b' }, { id: 3, path: '/c' }] as any[]))
const query = createQuery(fetcher).where({ id: { $in: [1, 2] } })
Expand Down