-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathutils.ts
More file actions
36 lines (32 loc) · 838 Bytes
/
utils.ts
File metadata and controls
36 lines (32 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { corsHeaders } from './cors'
import { StarbaseDBConfiguration } from './handler'
export type QueryTransactionRequest = {
transaction?: QueryRequest[]
}
export type QueryRequest = {
sql: string
params?: any[]
}
export function createResponse(
result: unknown,
error: string | undefined,
status: number
): Response {
return new Response(JSON.stringify({ result, error }), {
status,
headers: {
...corsHeaders,
'Content-Type': 'application/json',
},
})
}
export function getFeatureFromConfig(
features: StarbaseDBConfiguration['features']
) {
return function getFeature(
key: keyof NonNullable<StarbaseDBConfiguration['features']>,
defaultValue = true
): boolean {
return features?.[key] ?? !!defaultValue
}
}