aurabase-js 0.1.0
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/.omc/state/hud-state.json +6 -0
- package/.omc/state/hud-stdin-cache.json +1 -0
- package/README.md +204 -0
- package/dist/index.d.mts +392 -0
- package/dist/index.d.ts +392 -0
- package/dist/index.js +769 -0
- package/dist/index.mjs +741 -0
- package/package.json +34 -0
- package/src/AuraBaseClient.ts +271 -0
- package/src/Auth.ts +329 -0
- package/src/QueryBuilder.ts +319 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +72 -0
- package/src/types.ts +79 -0
- package/tsconfig.json +20 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
interface AuraBaseClientOptions {
|
|
2
|
+
url: string;
|
|
3
|
+
anonKey: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
interface AuthSession {
|
|
7
|
+
access_token: string;
|
|
8
|
+
token_type: string;
|
|
9
|
+
user: User;
|
|
10
|
+
}
|
|
11
|
+
interface User {
|
|
12
|
+
id: number;
|
|
13
|
+
email: string;
|
|
14
|
+
username?: string;
|
|
15
|
+
role_id?: number;
|
|
16
|
+
created_at?: string;
|
|
17
|
+
}
|
|
18
|
+
interface AuthError {
|
|
19
|
+
error: string;
|
|
20
|
+
detail?: string | Array<{
|
|
21
|
+
msg: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
interface PostgrestResponse<T> {
|
|
25
|
+
data: T | T[] | null;
|
|
26
|
+
error: AuraBaseError | null;
|
|
27
|
+
status: number;
|
|
28
|
+
statusText: string;
|
|
29
|
+
}
|
|
30
|
+
interface AuraBaseError {
|
|
31
|
+
message: string;
|
|
32
|
+
code?: string;
|
|
33
|
+
details?: string;
|
|
34
|
+
}
|
|
35
|
+
interface AuthStateChangeEvent {
|
|
36
|
+
SIGNED_IN: 'SIGNED_IN';
|
|
37
|
+
SIGNED_OUT: 'SIGNED_OUT';
|
|
38
|
+
TOKEN_REFRESHED: 'TOKEN_REFRESHED';
|
|
39
|
+
USER_UPDATED: 'USER_UPDATED';
|
|
40
|
+
}
|
|
41
|
+
type AuthChangeEvent = AuthStateChangeEvent[keyof AuthStateChangeEvent];
|
|
42
|
+
interface Subscription {
|
|
43
|
+
unsubscribe: () => void;
|
|
44
|
+
}
|
|
45
|
+
interface SignInWithPasswordCredentials {
|
|
46
|
+
email: string;
|
|
47
|
+
password: string;
|
|
48
|
+
}
|
|
49
|
+
interface SignUpCredentials {
|
|
50
|
+
email: string;
|
|
51
|
+
password: string;
|
|
52
|
+
username?: string;
|
|
53
|
+
}
|
|
54
|
+
interface UpdateUserAttributes {
|
|
55
|
+
email?: string;
|
|
56
|
+
password?: string;
|
|
57
|
+
username?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare class QueryBuilder<T> {
|
|
61
|
+
private url;
|
|
62
|
+
private anonKey;
|
|
63
|
+
private accessToken;
|
|
64
|
+
private tableName;
|
|
65
|
+
private queryParams;
|
|
66
|
+
private headers;
|
|
67
|
+
private isSingle;
|
|
68
|
+
constructor(url: string, anonKey: string, accessToken: string | null, tableName: string, headers?: Record<string, string>);
|
|
69
|
+
/**
|
|
70
|
+
* Select columns
|
|
71
|
+
* @example
|
|
72
|
+
* .select('id, name, email')
|
|
73
|
+
* .select('*')
|
|
74
|
+
*/
|
|
75
|
+
select(columns?: string): this;
|
|
76
|
+
/**
|
|
77
|
+
* Filter by column equality
|
|
78
|
+
* @example
|
|
79
|
+
* .eq('id', 1)
|
|
80
|
+
* .eq('status', 'active')
|
|
81
|
+
*/
|
|
82
|
+
eq(column: string, value: unknown): this;
|
|
83
|
+
/**
|
|
84
|
+
* Filter by column inequality
|
|
85
|
+
*/
|
|
86
|
+
neq(column: string, value: unknown): this;
|
|
87
|
+
/**
|
|
88
|
+
* Filter by greater than
|
|
89
|
+
*/
|
|
90
|
+
gt(column: string, value: unknown): this;
|
|
91
|
+
/**
|
|
92
|
+
* Filter by greater than or equal
|
|
93
|
+
*/
|
|
94
|
+
gte(column: string, value: unknown): this;
|
|
95
|
+
/**
|
|
96
|
+
* Filter by less than
|
|
97
|
+
*/
|
|
98
|
+
lt(column: string, value: unknown): this;
|
|
99
|
+
/**
|
|
100
|
+
* Filter by less than or equal
|
|
101
|
+
*/
|
|
102
|
+
lte(column: string, value: unknown): this;
|
|
103
|
+
/**
|
|
104
|
+
* Filter by like pattern
|
|
105
|
+
*/
|
|
106
|
+
like(column: string, pattern: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Filter by case-insensitive like pattern
|
|
109
|
+
*/
|
|
110
|
+
ilike(column: string, pattern: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Filter by array contains
|
|
113
|
+
*/
|
|
114
|
+
contains(column: string, value: unknown[]): this;
|
|
115
|
+
/**
|
|
116
|
+
* Filter by value in array
|
|
117
|
+
*/
|
|
118
|
+
in(column: string, values: unknown[]): this;
|
|
119
|
+
/**
|
|
120
|
+
* Filter for null values
|
|
121
|
+
*/
|
|
122
|
+
isNull(column: string): this;
|
|
123
|
+
/**
|
|
124
|
+
* Filter for non-null values
|
|
125
|
+
*/
|
|
126
|
+
isNotNull(column: string): this;
|
|
127
|
+
/**
|
|
128
|
+
* Order results
|
|
129
|
+
* @example
|
|
130
|
+
* .order('created_at', { ascending: false })
|
|
131
|
+
*/
|
|
132
|
+
order(column: string, options?: {
|
|
133
|
+
ascending?: boolean;
|
|
134
|
+
nullsFirst?: boolean;
|
|
135
|
+
}): this;
|
|
136
|
+
/**
|
|
137
|
+
* Limit results
|
|
138
|
+
*/
|
|
139
|
+
limit(count: number): this;
|
|
140
|
+
/**
|
|
141
|
+
* Offset results
|
|
142
|
+
*/
|
|
143
|
+
offset(count: number): this;
|
|
144
|
+
/**
|
|
145
|
+
* Range of results (offset + limit)
|
|
146
|
+
*/
|
|
147
|
+
range(from: number, to: number): this;
|
|
148
|
+
/**
|
|
149
|
+
* Return single result
|
|
150
|
+
*/
|
|
151
|
+
single(): this;
|
|
152
|
+
/**
|
|
153
|
+
* Return single result or null
|
|
154
|
+
*/
|
|
155
|
+
maybeSingle(): this;
|
|
156
|
+
private getHeaders;
|
|
157
|
+
private request;
|
|
158
|
+
/**
|
|
159
|
+
* Execute SELECT query
|
|
160
|
+
*/
|
|
161
|
+
then<TResult = T[]>(resolve: (value: PostgrestResponse<TResult>) => void | PromiseLike<void>, reject?: (reason: unknown) => void | PromiseLike<void>): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Insert row(s)
|
|
164
|
+
*/
|
|
165
|
+
insert(row: Partial<T> | Partial<T>[]): Promise<PostgrestResponse<T>>;
|
|
166
|
+
/**
|
|
167
|
+
* Update row(s)
|
|
168
|
+
*/
|
|
169
|
+
update(data: Partial<T>): Promise<PostgrestResponse<T>>;
|
|
170
|
+
/**
|
|
171
|
+
* Upsert row(s)
|
|
172
|
+
*/
|
|
173
|
+
upsert(row: Partial<T> | Partial<T>[]): Promise<PostgrestResponse<T>>;
|
|
174
|
+
/**
|
|
175
|
+
* Delete row(s)
|
|
176
|
+
*/
|
|
177
|
+
delete(): Promise<PostgrestResponse<T>>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class AuthClient {
|
|
181
|
+
private url;
|
|
182
|
+
private anonKey;
|
|
183
|
+
private listeners;
|
|
184
|
+
private currentSession;
|
|
185
|
+
private storageKey;
|
|
186
|
+
constructor(url: string, anonKey: string);
|
|
187
|
+
private loadSession;
|
|
188
|
+
private saveSession;
|
|
189
|
+
private getHeaders;
|
|
190
|
+
private emitEvent;
|
|
191
|
+
/**
|
|
192
|
+
* Sign in with email and password
|
|
193
|
+
*/
|
|
194
|
+
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<{
|
|
195
|
+
data: {
|
|
196
|
+
user: User;
|
|
197
|
+
session: AuthSession;
|
|
198
|
+
} | null;
|
|
199
|
+
error: AuthError | null;
|
|
200
|
+
}>;
|
|
201
|
+
/**
|
|
202
|
+
* Sign up with email and password
|
|
203
|
+
*/
|
|
204
|
+
signUp(credentials: SignUpCredentials): Promise<{
|
|
205
|
+
data: {
|
|
206
|
+
user: User;
|
|
207
|
+
} | null;
|
|
208
|
+
error: AuthError | null;
|
|
209
|
+
}>;
|
|
210
|
+
/**
|
|
211
|
+
* Sign out
|
|
212
|
+
*/
|
|
213
|
+
signOut(): Promise<{
|
|
214
|
+
error: AuthError | null;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Get current session
|
|
218
|
+
*/
|
|
219
|
+
getSession(): {
|
|
220
|
+
data: {
|
|
221
|
+
session: AuthSession | null;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Get current user
|
|
226
|
+
*/
|
|
227
|
+
getUser(): Promise<{
|
|
228
|
+
data: {
|
|
229
|
+
user: User | null;
|
|
230
|
+
};
|
|
231
|
+
error: AuthError | null;
|
|
232
|
+
}>;
|
|
233
|
+
/**
|
|
234
|
+
* Update user
|
|
235
|
+
*/
|
|
236
|
+
updateUser(attributes: UpdateUserAttributes): Promise<{
|
|
237
|
+
data: {
|
|
238
|
+
user: User;
|
|
239
|
+
} | null;
|
|
240
|
+
error: AuthError | null;
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Request password reset
|
|
244
|
+
*/
|
|
245
|
+
resetPasswordForEmail(email: string): Promise<{
|
|
246
|
+
error: AuthError | null;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Subscribe to auth state changes
|
|
250
|
+
*/
|
|
251
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: AuthSession | null) => void): {
|
|
252
|
+
data: {
|
|
253
|
+
subscription: Subscription;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
declare class AuraBaseClient {
|
|
259
|
+
private url;
|
|
260
|
+
private anonKey;
|
|
261
|
+
private accessToken;
|
|
262
|
+
private customHeaders;
|
|
263
|
+
auth: AuthClient;
|
|
264
|
+
constructor(options: AuraBaseClientOptions);
|
|
265
|
+
/**
|
|
266
|
+
* Set access token for authenticated requests
|
|
267
|
+
*/
|
|
268
|
+
setAccessToken(token: string | null): void;
|
|
269
|
+
/**
|
|
270
|
+
* Get the current access token
|
|
271
|
+
*/
|
|
272
|
+
getAccessToken(): string | null;
|
|
273
|
+
/**
|
|
274
|
+
* Query a table
|
|
275
|
+
* @example
|
|
276
|
+
* const { data, error } = await client.from('todos').select('*')
|
|
277
|
+
*/
|
|
278
|
+
from<T = unknown>(tableName: string): QueryBuilder<T>;
|
|
279
|
+
/**
|
|
280
|
+
* Execute raw SQL (RPC function call)
|
|
281
|
+
* @example
|
|
282
|
+
* const { data, error } = await client.rpc('my_function', { arg1: 'value' })
|
|
283
|
+
*/
|
|
284
|
+
rpc<T = unknown>(functionName: string, params?: Record<string, unknown>): Promise<{
|
|
285
|
+
data: T | null;
|
|
286
|
+
error: {
|
|
287
|
+
message: string;
|
|
288
|
+
} | null;
|
|
289
|
+
}>;
|
|
290
|
+
/**
|
|
291
|
+
* Get storage client (if available)
|
|
292
|
+
*/
|
|
293
|
+
get storage(): {
|
|
294
|
+
from: (bucket: string) => StorageBucket;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Storage bucket operations
|
|
299
|
+
*/
|
|
300
|
+
declare class StorageBucket {
|
|
301
|
+
private url;
|
|
302
|
+
private anonKey;
|
|
303
|
+
private bucket;
|
|
304
|
+
private accessToken;
|
|
305
|
+
constructor(url: string, anonKey: string, bucket: string, accessToken: string | null);
|
|
306
|
+
private getHeaders;
|
|
307
|
+
/**
|
|
308
|
+
* Upload a file
|
|
309
|
+
*/
|
|
310
|
+
upload(path: string, file: File | Blob, options?: {
|
|
311
|
+
contentType?: string;
|
|
312
|
+
upsert?: boolean;
|
|
313
|
+
}): Promise<{
|
|
314
|
+
data: {
|
|
315
|
+
path: string;
|
|
316
|
+
} | null;
|
|
317
|
+
error: {
|
|
318
|
+
message: string;
|
|
319
|
+
} | null;
|
|
320
|
+
}>;
|
|
321
|
+
/**
|
|
322
|
+
* Download a file
|
|
323
|
+
*/
|
|
324
|
+
download(path: string): Promise<{
|
|
325
|
+
data: Blob | null;
|
|
326
|
+
error: {
|
|
327
|
+
message: string;
|
|
328
|
+
} | null;
|
|
329
|
+
}>;
|
|
330
|
+
/**
|
|
331
|
+
* Get public URL for a file
|
|
332
|
+
*/
|
|
333
|
+
getPublicUrl(path: string): string;
|
|
334
|
+
/**
|
|
335
|
+
* Delete a file
|
|
336
|
+
*/
|
|
337
|
+
remove(paths: string[]): Promise<{
|
|
338
|
+
error: {
|
|
339
|
+
message: string;
|
|
340
|
+
} | null;
|
|
341
|
+
}>;
|
|
342
|
+
/**
|
|
343
|
+
* List files in a bucket
|
|
344
|
+
*/
|
|
345
|
+
list(prefix?: string): Promise<{
|
|
346
|
+
data: Array<{
|
|
347
|
+
name: string;
|
|
348
|
+
id: string;
|
|
349
|
+
created_at: string;
|
|
350
|
+
}> | null;
|
|
351
|
+
error: {
|
|
352
|
+
message: string;
|
|
353
|
+
} | null;
|
|
354
|
+
}>;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Create an AuraBase client
|
|
359
|
+
* @param options - Client options containing url and anonKey
|
|
360
|
+
* @returns AuraBaseClient instance
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* import { createClient } from 'aurabase-js'
|
|
365
|
+
*
|
|
366
|
+
* const aurabase = createClient({
|
|
367
|
+
* url: 'http://localhost:8000',
|
|
368
|
+
* anonKey: 'your-anon-key'
|
|
369
|
+
* })
|
|
370
|
+
*
|
|
371
|
+
* // Query data
|
|
372
|
+
* const { data, error } = await aurabase
|
|
373
|
+
* .from('todos')
|
|
374
|
+
* .select('*')
|
|
375
|
+
* .order('created_at', { ascending: false })
|
|
376
|
+
* .limit(10)
|
|
377
|
+
*
|
|
378
|
+
* // Insert data
|
|
379
|
+
* const { data: newTodo, error: insertError } = await aurabase
|
|
380
|
+
* .from('todos')
|
|
381
|
+
* .insert({ title: 'My todo', completed: false })
|
|
382
|
+
*
|
|
383
|
+
* // Auth
|
|
384
|
+
* const { data, error } = await aurabase.auth.signInWithPassword({
|
|
385
|
+
* email: 'user@example.com',
|
|
386
|
+
* password: 'password'
|
|
387
|
+
* })
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
declare function createClient(options: AuraBaseClientOptions): AuraBaseClient;
|
|
391
|
+
|
|
392
|
+
export { AuraBaseClient, type AuraBaseClientOptions, type AuraBaseError, type AuthChangeEvent, type AuthError, type AuthSession, type PostgrestResponse, type SignInWithPasswordCredentials, type SignUpCredentials, type Subscription, type UpdateUserAttributes, type User, createClient, createClient as default };
|