diff --git a/packages/connect/deno/services/data.ts b/packages/connect/deno/services/data.ts index 333b40a6..e63fcbbc 100644 --- a/packages/connect/deno/services/data.ts +++ b/packages/connect/deno/services/data.ts @@ -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 }) diff --git a/packages/connect/deno/tests/data.test.ts b/packages/connect/deno/tests/data.test.ts index 8f7db0c2..d264c565 100644 --- a/packages/connect/deno/tests/data.test.ts +++ b/packages/connect/deno/tests/data.test.ts @@ -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 () => {