blob: ebc2547b3e2efd8327147e45fdc6194c39474dd8 (
plain) (
blame)
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
40
41
42
43
|
import type { AstroConfig, AstroIntegration } from 'astro';
import { loadEnv } from 'vite';
import type { AstroDbIntegration } from './types.js';
export type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
export function getAstroStudioEnv(envMode = ''): Record<`ASTRO_STUDIO_${string}`, string> {
const env = loadEnv(envMode, process.cwd(), 'ASTRO_STUDIO_');
return env;
}
export function getRemoteDatabaseUrl(): string {
const env = getAstroStudioEnv();
return env.ASTRO_STUDIO_REMOTE_DB_URL || 'https://db.services.astro.build';
}
export function getAstroStudioUrl(): string {
const env = getAstroStudioEnv();
return env.ASTRO_STUDIO_URL || 'https://studio.astro.build';
}
export function getDbDirectoryUrl(root: URL | string) {
return new URL('db/', root);
}
export function defineDbIntegration(integration: AstroDbIntegration): AstroIntegration {
return integration;
}
export type Result<T> = { success: true; data: T } | { success: false; data: unknown };
/**
* Map an object's values to a new set of values
* while preserving types.
*/
export function mapObject<T, U = T>(
item: Record<string, T>,
callback: (key: string, value: T) => U
): Record<string, U> {
return Object.fromEntries(
Object.entries(item).map(([key, value]) => [key, callback(key, value)])
);
}
|