Skip to content

Commit

Permalink
feat(connect): add optional partialFilter to data.index
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Aug 1, 2023
1 parent 65c0a62 commit b328254
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
30 changes: 17 additions & 13 deletions packages/connect/deno/services/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ export const query = (selector: unknown, options?: QueryOptions) => (hyper: Hype
})
export const bulk = (docs: unknown[]) => (hyper: HyperRequestFunction) =>
hyper({ service, method: Method.POST, action: Action.BULK, body: docs })
export const index =
(indexName: string, fields: string[] | { [k: string]: IndexFieldOptions }[]) =>
(hyper: HyperRequestFunction) =>
hyper({
service,
method: Method.POST,
action: Action.INDEX,
body: {
fields,
name: indexName,
type: 'JSON',
},
})
export const index = (
indexName: string,
fields: string[] | { [k: string]: IndexFieldOptions }[],
partialFilter?: unknown,
) =>
(hyper: HyperRequestFunction) =>
hyper({
service,
method: Method.POST,
action: Action.INDEX,
body: {
fields,
partialFilter,
name: indexName,
type: 'JSON',
},
})

export const create = () => (hyper: HyperRequestFunction) => hyper({ service, method: Method.PUT })

Expand Down
12 changes: 11 additions & 1 deletion packages/connect/deno/tests/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,21 @@ test('data.index', async () => {
assertEquals(body.name, 'foo')
assertEquals(body.fields[0], 'type')

const withSort = await index('foo', [{ type: 'ASC' }, { bar: 'ASC' }])(mockRequest)
const withSort = await index('foo', [{ type: 'ASC' }, { bar: 'ASC' }])(
mockRequest,
)
const bodyWithSort = await withSort.json()
assertEquals(bodyWithSort.name, 'foo')
assertEquals(bodyWithSort.fields[0], { type: 'ASC' })
assertEquals(bodyWithSort.fields[1], { bar: 'ASC' })

const withPartialFilter = await index('foo', ['type'], { type: 'user' })(
mockRequest,
)
const bodyWithPartialFilter = await withPartialFilter.json()
assertEquals(bodyWithPartialFilter.name, 'foo')
assertEquals(bodyWithPartialFilter.fields[0], 'type')
assertEquals(bodyWithPartialFilter.partialFilter, { type: 'user' })
})

test('data.create', async () => {
Expand Down

0 comments on commit b328254

Please sign in to comment.