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
34 changes: 15 additions & 19 deletions packages/connect/deno.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
{
"tasks": {
"cache": "deno cache --lock=deno.lock --lock-write deno/deps.deno.ts deno/dev_deps.ts",
"test": "deno lint && deno fmt && deno test -A --no-lock --unstable deno/tests",
"test:integration": "make test-integration",
"to-node": "make clean to-node",
"cache": "deno cache --lock=deno.lock --lock-write deno/deps.deno.ts deno/dev_deps.ts"
"to-node": "make clean to-node"
},
"fmt": {
"files": {
"exclude": [
"./CHANGELOG.md",
"./dist",
"./to-node",
"node_modules/",
"node/node_modules",
"node/harness/cjs/node_modules",
"node/harness/esm/node_modules",
"./yarn.lock"
]
},
"options": {
"lineWidth": 100,
"singleQuote": true,
"semiColons": false
}
"exclude": [
"./CHANGELOG.md",
"./dist",
"./to-node",
"node_modules/",
"node/node_modules",
"node/harness/cjs/node_modules",
"node/harness/esm/node_modules",
"./yarn.lock"
],
"lineWidth": 100,
"singleQuote": true,
"semiColons": false
},
"lint": {
"files": {
Expand Down
8 changes: 4 additions & 4 deletions packages/connect/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect/deno/dev_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export {
assert,
assertEquals,
assertObjectMatch,
} from 'https://deno.land/std@0.178.0/testing/asserts.ts'
} from 'https://deno.land/std@0.190.0/testing/asserts.ts'
33 changes: 21 additions & 12 deletions packages/connect/deno/services/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { toDataQuery } from '../utils/hyper-query.ts'

import { Action, HyperRequestFunction, ListOptions, Method, QueryOptions } from '../types.ts'
import {
Action,
HyperRequestFunction,
IndexFieldOptions,
ListOptions,
Method,
QueryOptions,
} from '../types.ts'
import { HYPER_LEGACY_GET_HEADER } from '../utils/hyper-request.ts'

const service = 'data' as const
Expand Down Expand Up @@ -38,17 +45,19 @@ 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[]) => (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 }[]) =>
(hyper: HyperRequestFunction) =>
hyper({
service,
method: Method.POST,
action: Action.INDEX,
body: {
fields,
name: indexName,
type: 'JSON',
},
})

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

Expand Down
6 changes: 6 additions & 0 deletions packages/connect/deno/tests/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ test('data.index', async () => {
const body = await result.json()
assertEquals(body.name, 'foo')
assertEquals(body.fields[0], 'type')

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' })
})

test('data.create', async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/deno/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const SortOptions = {
ASC: 'ASC',
} as const

export type IndexFieldOptions = SortOptions
export const IndexFieldOptions = SortOptions

export type Method = typeof Method[keyof typeof Method]
export const Method = {
GET: 'GET',
Expand Down