Update Supabase version and improve Keystatic's configurations

This commit updates the version of Supabase in multiple packages. It also introduces specificity to environment variables in Keystatic configuration and adds a method to create a 'KeyStatic' reader based on the storage kind. Furthermore, minor adjustments have been made to keep the environment variable names consistent.
This commit is contained in:
giancarlo
2024-04-19 14:40:11 +08:00
parent d733c2e653
commit 19b8cc793e
15 changed files with 124 additions and 63 deletions

View File

@@ -0,0 +1,41 @@
import { z } from 'zod';
/**
* Create a KeyStatic reader based on the storage kind.
*/
export async function createKeystaticReader() {
switch (process.env.KEYSTATIC_STORAGE_KIND ?? 'local') {
case 'local': {
const { default: config } = await import('./keystatic.config');
const { createReader } = await import('@keystatic/core/reader');
return createReader('.', config);
}
case 'github':
case 'cloud': {
const { default: config } = await import('./keystatic.config');
const githubConfig = z
.object({
token: z.string(),
repo: z.custom<`${string}/${string}`>(),
pathPrefix: z.string().optional(),
})
.parse({
token: process.env.KEYSTATIC_GITHUB_TOKEN,
repo: process.env.KEYSTATIC_STORAGE_REPO,
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
});
const { createGitHubReader } = await import(
'@keystatic/core/reader/github'
);
return createGitHubReader(config, githubConfig);
}
default:
throw new Error(`Unknown storage kind`);
}
}