mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 22:19:40 +02:00
feat: add monorepo configuration and shared packages structure
Root-level setup: - package.json with Turborepo scripts - pnpm-workspace.yaml for workspace management - turbo.json for build pipeline - Common config files (.nvmrc, .prettierrc, .editorconfig) Shared packages (packages/): - @manacore/shared-types - Common TypeScript types - @manacore/shared-supabase - Unified Supabase client - @manacore/shared-utils - Date, string, async utilities - @manacore/shared-ui - React Native UI components (placeholder) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e7f5f942f3
commit
2c58d03f63
23 changed files with 738 additions and 0 deletions
62
packages/shared-supabase/src/index.ts
Normal file
62
packages/shared-supabase/src/index.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Shared Supabase utilities for Manacore monorepo
|
||||
*
|
||||
* This package provides a unified Supabase client and common database utilities.
|
||||
*/
|
||||
|
||||
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
||||
import type { SupabaseConfig } from '@manacore/shared-types';
|
||||
|
||||
export { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
/**
|
||||
* Create a Supabase client with the given configuration
|
||||
*/
|
||||
export function createSupabaseClient(config: SupabaseConfig): SupabaseClient {
|
||||
return createClient(config.url, config.anonKey, {
|
||||
auth: {
|
||||
persistSession: true,
|
||||
autoRefreshToken: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Supabase admin client with service role key
|
||||
*/
|
||||
export function createSupabaseAdminClient(config: SupabaseConfig): SupabaseClient {
|
||||
if (!config.serviceRoleKey) {
|
||||
throw new Error('Service role key is required for admin client');
|
||||
}
|
||||
|
||||
return createClient(config.url, config.serviceRoleKey, {
|
||||
auth: {
|
||||
persistSession: false,
|
||||
autoRefreshToken: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Common database query helpers
|
||||
*/
|
||||
export const dbHelpers = {
|
||||
/**
|
||||
* Handle Supabase query result and return standardized response
|
||||
*/
|
||||
handleQueryResult<T>(result: { data: T | null; error: any }): {
|
||||
data: T | null;
|
||||
error: { message: string; code?: string } | null;
|
||||
} {
|
||||
if (result.error) {
|
||||
return {
|
||||
data: null,
|
||||
error: {
|
||||
message: result.error.message,
|
||||
code: result.error.code,
|
||||
},
|
||||
};
|
||||
}
|
||||
return { data: result.data, error: null };
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue