-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
buildInlineDatasources.ts
39 lines (33 loc) · 1.08 KB
/
buildInlineDatasources.ts
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
37
38
39
import type { InternalDatasource } from '../../runtime/utils/printDatasources'
// that is all we need for the data proxy
export type InlineDatasources = {
[name in InternalDatasource['name']]: {
url: InternalDatasource['url']
}
}
/**
* Builds the important datasource information for the data proxy. Essentially,
* it saves the URL or env var name for the data proxy engine to read later.
* @param dataProxy
* @param internalDatasources
* @returns
*/
export function buildInlineDatasource(dataProxy: boolean, internalDatasources: InternalDatasource[]) {
if (dataProxy === true) {
const datasources = internalToInlineDatasources(internalDatasources)
return `
config.inlineDatasources = ${JSON.stringify(datasources, null, 2)}`
}
return ``
}
/**
* Transforms an array of datasources into an inline datasources
* @param internalDatasources
* @returns
*/
function internalToInlineDatasources(internalDatasources: InternalDatasource[]) {
return internalDatasources.reduce((acc, ds) => {
acc[ds.name] = { url: ds.url }
return acc
}, {} as InlineDatasources)
}