@omnibase/core-js 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -0
- package/dist/auth/index.d.cts +397 -43
- package/dist/auth/index.d.ts +397 -43
- package/dist/database/index.d.cts +96 -47
- package/dist/database/index.d.ts +96 -47
- package/dist/index.d.ts +3 -10
- package/dist/tenants/index.cjs +3 -0
- package/dist/tenants/index.d.cts +584 -27
- package/dist/tenants/index.d.ts +584 -27
- package/dist/tenants/index.js +3 -0
- package/package.json +8 -3
package/dist/database/index.d.ts
CHANGED
|
@@ -1,56 +1,105 @@
|
|
|
1
|
-
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
2
1
|
import { PostgrestClient } from '@supabase/postgrest-js';
|
|
3
2
|
|
|
4
|
-
declare type GenericRelationship = {
|
|
5
|
-
foreignKeyName: string;
|
|
6
|
-
columns: string[];
|
|
7
|
-
isOneToOne?: boolean;
|
|
8
|
-
referencedRelation: string;
|
|
9
|
-
referencedColumns: string[];
|
|
10
|
-
};
|
|
11
|
-
declare type GenericTable = {
|
|
12
|
-
Row: Record<string, unknown>;
|
|
13
|
-
Insert: Record<string, unknown>;
|
|
14
|
-
Update: Record<string, unknown>;
|
|
15
|
-
Relationships: GenericRelationship[];
|
|
16
|
-
};
|
|
17
|
-
declare type GenericUpdatableView = {
|
|
18
|
-
Row: Record<string, unknown>;
|
|
19
|
-
Insert: Record<string, unknown>;
|
|
20
|
-
Update: Record<string, unknown>;
|
|
21
|
-
Relationships: GenericRelationship[];
|
|
22
|
-
};
|
|
23
|
-
declare type GenericNonUpdatableView = {
|
|
24
|
-
Row: Record<string, unknown>;
|
|
25
|
-
Relationships: GenericRelationship[];
|
|
26
|
-
};
|
|
27
|
-
declare type GenericView = GenericUpdatableView | GenericNonUpdatableView;
|
|
28
|
-
declare type GenericFunction = {
|
|
29
|
-
Args: Record<string, unknown>;
|
|
30
|
-
Returns: unknown;
|
|
31
|
-
};
|
|
32
|
-
declare type GenericSchema = {
|
|
33
|
-
Tables: Record<string, GenericTable>;
|
|
34
|
-
Views: Record<string, GenericView>;
|
|
35
|
-
Functions: Record<string, GenericFunction>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
3
|
/**
|
|
39
|
-
* PostgREST client
|
|
4
|
+
* Creates a PostgREST client for database operations
|
|
5
|
+
*
|
|
6
|
+
* This function creates a configured PostgREST client that handles authentication
|
|
7
|
+
* through JWT tokens. It supports both cookie-based authentication (for server-side
|
|
8
|
+
* usage) and fallback to anonymous keys. The client provides a type-safe interface
|
|
9
|
+
* for database operations when used with generated TypeScript types.
|
|
10
|
+
*
|
|
11
|
+
* The client automatically handles authentication headers and provides access to
|
|
12
|
+
* all PostgREST functionality including queries, mutations, and real-time subscriptions.
|
|
13
|
+
*
|
|
14
|
+
* @template T - Database schema types for type-safe operations. Should be generated
|
|
15
|
+
* from your database schema using a tool like Supabase CLI or Omnibase CLI
|
|
16
|
+
*
|
|
17
|
+
* @param url - The PostgREST API endpoint URL (e.g., 'https://api.example.com/rest/v1')
|
|
18
|
+
* @param anonKey - Anonymous/public API key used as fallback when no JWT token is available
|
|
19
|
+
* @param getCookie - Function to retrieve cookies by name, typically used to get JWT tokens
|
|
20
|
+
*
|
|
21
|
+
* @returns A configured PostgREST client instance with authentication headers set
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* Browser usage with cookie authentication:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createClient } from '@omnibase/core-js/database';
|
|
27
|
+
*
|
|
28
|
+
* interface DatabaseTypes {
|
|
29
|
+
* users: {
|
|
30
|
+
* Row: { id: string; email: string; name: string };
|
|
31
|
+
* Insert: { email: string; name: string };
|
|
32
|
+
* Update: { email?: string; name?: string };
|
|
33
|
+
* };
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const client = createClient<DatabaseTypes>(
|
|
37
|
+
* 'https://api.example.com/rest/v1',
|
|
38
|
+
* 'your-anon-key',
|
|
39
|
+
* (name) => document.cookie
|
|
40
|
+
* .split('; ')
|
|
41
|
+
* .find(row => row.startsWith(`${name}=`))
|
|
42
|
+
* ?.split('=')[1] || ''
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* // Type-safe query
|
|
46
|
+
* const { data, error } = await client
|
|
47
|
+
* .from('users')
|
|
48
|
+
* .select('id, email, name')
|
|
49
|
+
* .eq('email', 'user@example.com');
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* Node.js usage with custom JWT retrieval:
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { createClient } from '@omnibase/core-js/database';
|
|
56
|
+
*
|
|
57
|
+
* const client = createClient(
|
|
58
|
+
* process.env.POSTGREST_URL!,
|
|
59
|
+
* process.env.POSTGREST_ANON_KEY!,
|
|
60
|
+
* (name) => {
|
|
61
|
+
* // Custom logic to retrieve JWT from request headers, session, etc.
|
|
62
|
+
* return getJwtFromSession(name) || '';
|
|
63
|
+
* }
|
|
64
|
+
* );
|
|
65
|
+
*
|
|
66
|
+
* // Insert new record
|
|
67
|
+
* const { data, error } = await client
|
|
68
|
+
* .from('users')
|
|
69
|
+
* .insert({ email: 'new@example.com', name: 'New User' })
|
|
70
|
+
* .select();
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* Advanced usage with error handling:
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const client = createClient<DatabaseTypes>(
|
|
77
|
+
* 'https://api.example.com/rest/v1',
|
|
78
|
+
* 'your-anon-key',
|
|
79
|
+
* (name) => getCookieValue(name)
|
|
80
|
+
* );
|
|
81
|
+
*
|
|
82
|
+
* try {
|
|
83
|
+
* const { data, error } = await client
|
|
84
|
+
* .from('users')
|
|
85
|
+
* .select('*')
|
|
86
|
+
* .order('created_at', { ascending: false })
|
|
87
|
+
* .limit(10);
|
|
40
88
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
89
|
+
* if (error) {
|
|
90
|
+
* console.error('Database error:', error.message);
|
|
91
|
+
* return;
|
|
92
|
+
* }
|
|
43
93
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
94
|
+
* console.log('Users:', data);
|
|
95
|
+
* } catch (err) {
|
|
96
|
+
* console.error('Network error:', err);
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
46
99
|
*
|
|
47
|
-
* @
|
|
48
|
-
* @
|
|
49
|
-
* @param getCookie - Custom callback to get cookie by name
|
|
50
|
-
* @returns
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
* @public
|
|
51
102
|
*/
|
|
52
|
-
declare const createClient: <T = any>(url: string, anonKey: string, getCookie: (cookie: string) => string) => PostgrestClient<T
|
|
53
|
-
__InternalSupabase: infer I extends _supabase_postgrest_js.PostgrestClientOptions;
|
|
54
|
-
} ? I : {}, "public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">, Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] extends GenericSchema ? Omit<T, "__InternalSupabase">["public" extends Exclude<keyof T, "__InternalSupabase"> ? Exclude<keyof T, "__InternalSupabase"> & "public" : string & Exclude<keyof T, "__InternalSupabase">] : any>;
|
|
103
|
+
declare const createClient: <T = any>(url: string, anonKey: string, getCookie: (cookie: string) => string) => PostgrestClient<T>;
|
|
55
104
|
|
|
56
105
|
export { createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
type ApiResponse<T> = {
|
|
5
|
-
data?: T;
|
|
6
|
-
status: number;
|
|
7
|
-
error?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type { ApiResponse };
|
|
1
|
+
export * from "./auth/index";
|
|
2
|
+
export * from "./database/index";
|
|
3
|
+
export * from "./tenants/index";
|
package/dist/tenants/index.cjs
CHANGED