Skip to content

Commit 0562462

Browse files
committed
feat: include inputMode in output
1 parent 3fdadce commit 0562462

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/bridge/lib/format.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, go.importObject)
1313
go.run(wasmInstance)
1414

1515
describe('format URL', () => {
16+
it('provides the correct input mode', () => {
17+
expect(
18+
format({
19+
input: '*',
20+
groqfmt,
21+
}).inputMode,
22+
).toBe('groq')
23+
24+
expect(
25+
format({
26+
input:
27+
'https://x.apicdn.sanity.io/vX/data/query/y?query=*&perspective=previewDrafts',
28+
groqfmt,
29+
}).inputMode,
30+
).toBe('url')
31+
})
32+
1633
// TODO
1734
it('extracts query from the URL', () => {})
1835

src/bridge/lib/format.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import getQueryDetails, { type Details } from './get-query-details'
33
import getQueryParams from './get-query-params'
44

55
/** @public */
6-
export type GroqfmtResultEnhanced = GroqfmtResult & {
7-
params?: Record<string, string>
8-
} & Partial<Details>
6+
export type GroqfmtResultEnhanced =
7+
| ({
8+
inputMode: 'groq'
9+
} & GroqfmtResult)
10+
| ({
11+
inputMode: 'url'
12+
params?: Record<string, string>
13+
} & GroqfmtResult &
14+
Partial<Details>)
915

1016
/** @public */
1117
export function format({
@@ -27,22 +33,26 @@ export function format({
2733
...groqfmt(query),
2834
...getQueryDetails(url),
2935
params: getQueryParams(url),
36+
inputMode: 'url',
3037
}
3138
}
3239

3340
return {
41+
inputMode: 'url',
3442
result,
3543
error,
3644
}
3745
} catch {}
3846

3947
return {
48+
inputMode: 'groq',
4049
result,
4150
error,
4251
}
4352
}
4453

4554
return {
55+
inputMode: 'groq',
4656
result,
4757
error,
4858
}

0 commit comments

Comments
 (0)