@ragable/sdk 0.4.2 → 0.5.1

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/dist/index.d.mts CHANGED
@@ -53,12 +53,27 @@ type TablesInsert<D extends RagableDatabase, TableName extends keyof D["public"]
53
53
  type TablesUpdate<D extends RagableDatabase, TableName extends keyof D["public"]["Tables"] & string> = [D["public"]["Tables"][TableName]] extends [never] ? Record<string, unknown> : D["public"]["Tables"][TableName] extends {
54
54
  Update: infer U;
55
55
  } ? U extends Record<string, unknown> ? U : Record<string, unknown> : Partial<Tables<D, TableName>>;
56
+ /**
57
+ * Table name union for `client.from(...)`.
58
+ * When `Tables` is empty (`DefaultRagableDatabase`), any `string` is allowed.
59
+ */
60
+ type RagableTableNames<D extends RagableDatabase> = [
61
+ keyof D["public"]["Tables"]
62
+ ] extends [never] ? string : Extract<keyof D["public"]["Tables"], string>;
63
+ /** Row type for `from(table)` when a concrete `Database` generic is set. */
64
+ type TableRow<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? Tables<D, T> : Record<string, unknown>;
65
+ /** Insert payload for typed `from(table).insert(...)`. */
66
+ type TableInsertRow<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? TablesInsert<D, T> : Record<string, unknown>;
67
+ /** Update patch for typed `from(table).update(...)`. */
68
+ type TableUpdatePatch<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? TablesUpdate<D, T> : Record<string, unknown>;
56
69
 
57
70
  /**
58
71
  * Native `fetch` must not be called as a detached reference (`const f = fetch; f(url)`),
59
72
  * or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
60
73
  */
61
74
  declare function bindFetch(custom?: typeof fetch): typeof fetch;
75
+ /** Default hosted API (`…/api`) when `baseUrl` is omitted (browser + server clients). */
76
+ declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
62
77
  interface RagableClientOptions {
63
78
  apiKey: string;
64
79
  baseUrl?: string;
@@ -242,6 +257,12 @@ interface BrowserSqlExecResult<Row extends Record<string, unknown> = Record<stri
242
257
  truncated: boolean;
243
258
  rows: Row[];
244
259
  }
260
+ type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike";
261
+ interface Filter {
262
+ op: FilterOp;
263
+ column: string;
264
+ value: unknown;
265
+ }
245
266
  type PostgrestResult<T> = {
246
267
  data: T;
247
268
  error: null;
@@ -274,61 +295,169 @@ declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Recor
274
295
  order(column: string, options?: {
275
296
  ascending?: boolean;
276
297
  }): this;
277
- /** @param includeUserLimit when false, omit `.limit()` (for `.single()` / `.maybeSingle()`). */
278
298
  private buildSelectCore;
279
299
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
280
300
  private executeMany;
281
301
  single(): Promise<PostgrestResult<Row>>;
282
302
  maybeSingle(): Promise<PostgrestResult<Row | null>>;
283
303
  }
284
- declare class PostgrestInsertBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
304
+ /** After `.insert()`: await without `.select()` `{ data: null }` (Supabase default). */
305
+ declare class PostgrestInsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
285
306
  private readonly run;
286
307
  private readonly databaseInstanceId;
287
308
  private readonly table;
288
309
  private readonly rows;
289
- private returning;
290
310
  constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[]);
291
- select(columns?: string): this;
311
+ /**
312
+ * Return inserted rows (Supabase: chain `.select()` to get data).
313
+ * @see https://supabase.com/docs/reference/javascript/insert
314
+ */
315
+ select(columns?: string): PostgrestInsertReturningBuilder<Row>;
316
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
317
+ private executeNoReturn;
318
+ }
319
+ declare class PostgrestInsertReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
320
+ private readonly run;
321
+ private readonly databaseInstanceId;
322
+ private readonly table;
323
+ private readonly rows;
324
+ private readonly returning;
325
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[], returning: string);
292
326
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
293
- private execute;
327
+ private executeMany;
328
+ single(): Promise<PostgrestResult<Row>>;
329
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
294
330
  }
295
- declare class PostgrestUpdateBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
331
+ /** Update without `.select()` `{ data: null }` on success. */
332
+ declare class PostgrestUpdateRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
296
333
  private readonly run;
297
334
  private readonly databaseInstanceId;
298
335
  private readonly table;
299
336
  private readonly patch;
300
337
  private filters;
301
- private returning;
302
338
  constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>);
303
339
  eq(column: string, value: unknown): this;
304
- select(columns?: string): this;
340
+ neq(column: string, value: unknown): this;
341
+ gt(column: string, value: unknown): this;
342
+ gte(column: string, value: unknown): this;
343
+ lt(column: string, value: unknown): this;
344
+ lte(column: string, value: unknown): this;
345
+ like(column: string, value: unknown): this;
346
+ ilike(column: string, value: unknown): this;
347
+ /**
348
+ * Return updated rows (Supabase: `.update().eq().select()`).
349
+ * @see https://supabase.com/docs/reference/javascript/update
350
+ */
351
+ select(columns?: string): PostgrestUpdateReturningBuilder<Row>;
352
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
353
+ private executeNoReturn;
354
+ }
355
+ declare class PostgrestUpdateReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
356
+ private readonly run;
357
+ private readonly databaseInstanceId;
358
+ private readonly table;
359
+ private readonly patch;
360
+ private readonly filters;
361
+ private readonly returning;
362
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>, filters: Filter[], returning: string);
305
363
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
306
- private execute;
364
+ private executeMany;
365
+ single(): Promise<PostgrestResult<Row>>;
366
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
307
367
  }
308
- declare class PostgrestDeleteBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
368
+ /** Delete without `.select()` `{ data: null }`. */
369
+ declare class PostgrestDeleteRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
309
370
  private readonly run;
310
371
  private readonly databaseInstanceId;
311
372
  private readonly table;
312
373
  private filters;
313
- private returning;
314
374
  constructor(run: RunQuery, databaseInstanceId: string, table: string);
315
375
  eq(column: string, value: unknown): this;
316
- select(columns?: string): this;
376
+ neq(column: string, value: unknown): this;
377
+ gt(column: string, value: unknown): this;
378
+ gte(column: string, value: unknown): this;
379
+ lt(column: string, value: unknown): this;
380
+ lte(column: string, value: unknown): this;
381
+ like(column: string, value: unknown): this;
382
+ ilike(column: string, value: unknown): this;
383
+ /**
384
+ * Return deleted rows (Supabase: `.delete().eq().select()`).
385
+ * @see https://supabase.com/docs/reference/javascript/delete
386
+ */
387
+ select(columns?: string): PostgrestDeleteReturningBuilder<Row>;
388
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
389
+ private executeNoReturn;
390
+ }
391
+ declare class PostgrestDeleteReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
392
+ private readonly run;
393
+ private readonly databaseInstanceId;
394
+ private readonly table;
395
+ private readonly filters;
396
+ private readonly returning;
397
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, filters: Filter[], returning: string);
317
398
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
318
- private execute;
399
+ private executeMany;
400
+ single(): Promise<PostgrestResult<Row>>;
401
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
402
+ }
403
+ interface PostgrestUpsertOptions {
404
+ /** Column(s) for `ON CONFLICT` — single name or comma-separated, e.g. `"id"` or `"org_id,user_id"`. */
405
+ onConflict: string;
406
+ /** When true, `ON CONFLICT DO NOTHING` (no update of existing rows). */
407
+ ignoreDuplicates?: boolean;
319
408
  }
320
- declare class PostgrestTableApi<Row extends Record<string, unknown> = Record<string, unknown>> {
409
+ /** Upsert without `.select()` `{ data: null }`. */
410
+ declare class PostgrestUpsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
321
411
  private readonly run;
322
412
  private readonly databaseInstanceId;
323
413
  private readonly table;
324
- constructor(run: RunQuery, databaseInstanceId: string, table: string);
325
- select(columns?: string): PostgrestSelectBuilder<Row>;
326
- insert(values: Record<string, unknown> | Record<string, unknown>[]): PostgrestInsertBuilder<Row>;
327
- update(patch: Record<string, unknown>): PostgrestUpdateBuilder<Row>;
328
- delete(): PostgrestDeleteBuilder<Row>;
414
+ private readonly rows;
415
+ private readonly ignoreDuplicates;
416
+ private readonly conflictCols;
417
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[], onConflict: string, ignoreDuplicates: boolean);
418
+ /**
419
+ * Return upserted rows (Supabase: `.upsert().select()`).
420
+ * @see https://supabase.com/docs/reference/javascript/upsert
421
+ */
422
+ select(columns?: string): PostgrestUpsertReturningBuilder<Row>;
423
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
424
+ private executeNoReturn;
425
+ private runUpsert;
426
+ /** Used by returning builder */
427
+ runWithReturning(returning: string): Promise<BrowserSqlExecResult<Row>>;
428
+ }
429
+ declare class PostgrestUpsertReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
430
+ private readonly root;
431
+ private readonly returning;
432
+ constructor(root: PostgrestUpsertRootBuilder<Row>, returning: string);
433
+ then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
434
+ private executeMany;
435
+ single(): Promise<PostgrestResult<Row>>;
436
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
437
+ }
438
+ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagableDatabase, TableName extends RagableTableNames<Database> = RagableTableNames<Database>> {
439
+ private readonly run;
440
+ private readonly databaseInstanceId;
441
+ private readonly table;
442
+ constructor(run: RunQuery, databaseInstanceId: string, table: TableName extends string ? string : string);
443
+ select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>>;
444
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
445
+ update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>>;
446
+ delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>>;
447
+ /**
448
+ * `INSERT ... ON CONFLICT ... DO UPDATE` (or `DO NOTHING` with `ignoreDuplicates`).
449
+ * @see https://supabase.com/docs/reference/javascript/upsert
450
+ */
451
+ upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
329
452
  }
330
453
 
454
+ /**
455
+ * Ensures the browser SDK hits `/api/...` routes. Accepts either `https://host` or `https://host/api`
456
+ * (same rule as two-arg `createClient(url, opts)` from the package entry).
457
+ */
331
458
  declare function normalizeBrowserApiBase(baseUrl?: string): string;
459
+ /** How {@link RagableBrowserDatabaseClient.query} and `.from()` send `Authorization`. */
460
+ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
332
461
  interface RagableBrowserClientOptions {
333
462
  /** Organization id (UUID) — public agent chat URLs. */
334
463
  organizationId: string;
@@ -341,14 +470,27 @@ interface RagableBrowserClientOptions {
341
470
  * Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
342
471
  */
343
472
  databaseInstanceId?: string;
473
+ /**
474
+ * Database SQL auth. Default `user`: Bearer = JWT from {@link getAccessToken}.
475
+ * `publicAnon`: Bearer = public anon key (read-only SQL only). `admin`: Bearer = data admin key
476
+ * (same SQL rules as a logged-in user; **never** expose in browser bundles).
477
+ */
478
+ dataAuth?: BrowserDataAuthMode;
479
+ /**
480
+ * Static key when {@link dataAuth} is `publicAnon` or `admin` (e.g. `import.meta.env.VITE_…`).
481
+ * Ignored when {@link getDataStaticKey} returns a non-empty string.
482
+ */
483
+ dataStaticKey?: string;
484
+ /** Load anon/admin key at runtime; wins over {@link dataStaticKey} when non-empty. */
485
+ getDataStaticKey?: () => string | null | Promise<string | null>;
344
486
  /**
345
487
  * Returns the end-user access JWT (from login/register/refresh).
346
- * Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
488
+ * Required for `auth.getMe`, `auth.updateMe`, and for `database.query` when {@link dataAuth} is `user` (default).
347
489
  */
348
490
  getAccessToken?: () => string | null | Promise<string | null>;
349
491
  /**
350
492
  * API base URL including `/api`, e.g. `https://api.example.com/api`.
351
- * @default "http://localhost:8080/api"
493
+ * @default `https://ragable-341305259977.asia-southeast1.run.app/api` ({@link DEFAULT_RAGABLE_API_BASE})
352
494
  */
353
495
  baseUrl?: string;
354
496
  fetch?: typeof fetch;
@@ -521,7 +663,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
521
663
  * Supabase-style table API: `.from('items').select().eq('id', 1).single()`.
522
664
  * Pass `databaseInstanceId` here or set `databaseInstanceId` on the client options.
523
665
  */
524
- from<Row extends Record<string, unknown> = Record<string, unknown>>(table: string, databaseInstanceId?: string): PostgrestTableApi<Row>;
666
+ from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
525
667
  }
526
668
  /**
527
669
  * **Supabase-equivalent** browser client factory (no org API key).
@@ -618,4 +760,4 @@ declare function createClient<Database extends RagableDatabase = DefaultRagableD
618
760
  */
619
761
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
620
762
 
621
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteBuilder, PostgrestInsertBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
763
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
package/dist/index.d.ts CHANGED
@@ -53,12 +53,27 @@ type TablesInsert<D extends RagableDatabase, TableName extends keyof D["public"]
53
53
  type TablesUpdate<D extends RagableDatabase, TableName extends keyof D["public"]["Tables"] & string> = [D["public"]["Tables"][TableName]] extends [never] ? Record<string, unknown> : D["public"]["Tables"][TableName] extends {
54
54
  Update: infer U;
55
55
  } ? U extends Record<string, unknown> ? U : Record<string, unknown> : Partial<Tables<D, TableName>>;
56
+ /**
57
+ * Table name union for `client.from(...)`.
58
+ * When `Tables` is empty (`DefaultRagableDatabase`), any `string` is allowed.
59
+ */
60
+ type RagableTableNames<D extends RagableDatabase> = [
61
+ keyof D["public"]["Tables"]
62
+ ] extends [never] ? string : Extract<keyof D["public"]["Tables"], string>;
63
+ /** Row type for `from(table)` when a concrete `Database` generic is set. */
64
+ type TableRow<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? Tables<D, T> : Record<string, unknown>;
65
+ /** Insert payload for typed `from(table).insert(...)`. */
66
+ type TableInsertRow<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? TablesInsert<D, T> : Record<string, unknown>;
67
+ /** Update patch for typed `from(table).update(...)`. */
68
+ type TableUpdatePatch<D extends RagableDatabase, T extends RagableTableNames<D>> = [keyof D["public"]["Tables"]] extends [never] ? Record<string, unknown> : T extends keyof D["public"]["Tables"] ? TablesUpdate<D, T> : Record<string, unknown>;
56
69
 
57
70
  /**
58
71
  * Native `fetch` must not be called as a detached reference (`const f = fetch; f(url)`),
59
72
  * or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
60
73
  */
61
74
  declare function bindFetch(custom?: typeof fetch): typeof fetch;
75
+ /** Default hosted API (`…/api`) when `baseUrl` is omitted (browser + server clients). */
76
+ declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
62
77
  interface RagableClientOptions {
63
78
  apiKey: string;
64
79
  baseUrl?: string;
@@ -242,6 +257,12 @@ interface BrowserSqlExecResult<Row extends Record<string, unknown> = Record<stri
242
257
  truncated: boolean;
243
258
  rows: Row[];
244
259
  }
260
+ type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike";
261
+ interface Filter {
262
+ op: FilterOp;
263
+ column: string;
264
+ value: unknown;
265
+ }
245
266
  type PostgrestResult<T> = {
246
267
  data: T;
247
268
  error: null;
@@ -274,61 +295,169 @@ declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Recor
274
295
  order(column: string, options?: {
275
296
  ascending?: boolean;
276
297
  }): this;
277
- /** @param includeUserLimit when false, omit `.limit()` (for `.single()` / `.maybeSingle()`). */
278
298
  private buildSelectCore;
279
299
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
280
300
  private executeMany;
281
301
  single(): Promise<PostgrestResult<Row>>;
282
302
  maybeSingle(): Promise<PostgrestResult<Row | null>>;
283
303
  }
284
- declare class PostgrestInsertBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
304
+ /** After `.insert()`: await without `.select()` `{ data: null }` (Supabase default). */
305
+ declare class PostgrestInsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
285
306
  private readonly run;
286
307
  private readonly databaseInstanceId;
287
308
  private readonly table;
288
309
  private readonly rows;
289
- private returning;
290
310
  constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[]);
291
- select(columns?: string): this;
311
+ /**
312
+ * Return inserted rows (Supabase: chain `.select()` to get data).
313
+ * @see https://supabase.com/docs/reference/javascript/insert
314
+ */
315
+ select(columns?: string): PostgrestInsertReturningBuilder<Row>;
316
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
317
+ private executeNoReturn;
318
+ }
319
+ declare class PostgrestInsertReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
320
+ private readonly run;
321
+ private readonly databaseInstanceId;
322
+ private readonly table;
323
+ private readonly rows;
324
+ private readonly returning;
325
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[], returning: string);
292
326
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
293
- private execute;
327
+ private executeMany;
328
+ single(): Promise<PostgrestResult<Row>>;
329
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
294
330
  }
295
- declare class PostgrestUpdateBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
331
+ /** Update without `.select()` `{ data: null }` on success. */
332
+ declare class PostgrestUpdateRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
296
333
  private readonly run;
297
334
  private readonly databaseInstanceId;
298
335
  private readonly table;
299
336
  private readonly patch;
300
337
  private filters;
301
- private returning;
302
338
  constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>);
303
339
  eq(column: string, value: unknown): this;
304
- select(columns?: string): this;
340
+ neq(column: string, value: unknown): this;
341
+ gt(column: string, value: unknown): this;
342
+ gte(column: string, value: unknown): this;
343
+ lt(column: string, value: unknown): this;
344
+ lte(column: string, value: unknown): this;
345
+ like(column: string, value: unknown): this;
346
+ ilike(column: string, value: unknown): this;
347
+ /**
348
+ * Return updated rows (Supabase: `.update().eq().select()`).
349
+ * @see https://supabase.com/docs/reference/javascript/update
350
+ */
351
+ select(columns?: string): PostgrestUpdateReturningBuilder<Row>;
352
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
353
+ private executeNoReturn;
354
+ }
355
+ declare class PostgrestUpdateReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
356
+ private readonly run;
357
+ private readonly databaseInstanceId;
358
+ private readonly table;
359
+ private readonly patch;
360
+ private readonly filters;
361
+ private readonly returning;
362
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>, filters: Filter[], returning: string);
305
363
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
306
- private execute;
364
+ private executeMany;
365
+ single(): Promise<PostgrestResult<Row>>;
366
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
307
367
  }
308
- declare class PostgrestDeleteBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
368
+ /** Delete without `.select()` `{ data: null }`. */
369
+ declare class PostgrestDeleteRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
309
370
  private readonly run;
310
371
  private readonly databaseInstanceId;
311
372
  private readonly table;
312
373
  private filters;
313
- private returning;
314
374
  constructor(run: RunQuery, databaseInstanceId: string, table: string);
315
375
  eq(column: string, value: unknown): this;
316
- select(columns?: string): this;
376
+ neq(column: string, value: unknown): this;
377
+ gt(column: string, value: unknown): this;
378
+ gte(column: string, value: unknown): this;
379
+ lt(column: string, value: unknown): this;
380
+ lte(column: string, value: unknown): this;
381
+ like(column: string, value: unknown): this;
382
+ ilike(column: string, value: unknown): this;
383
+ /**
384
+ * Return deleted rows (Supabase: `.delete().eq().select()`).
385
+ * @see https://supabase.com/docs/reference/javascript/delete
386
+ */
387
+ select(columns?: string): PostgrestDeleteReturningBuilder<Row>;
388
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
389
+ private executeNoReturn;
390
+ }
391
+ declare class PostgrestDeleteReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
392
+ private readonly run;
393
+ private readonly databaseInstanceId;
394
+ private readonly table;
395
+ private readonly filters;
396
+ private readonly returning;
397
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, filters: Filter[], returning: string);
317
398
  then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
318
- private execute;
399
+ private executeMany;
400
+ single(): Promise<PostgrestResult<Row>>;
401
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
402
+ }
403
+ interface PostgrestUpsertOptions {
404
+ /** Column(s) for `ON CONFLICT` — single name or comma-separated, e.g. `"id"` or `"org_id,user_id"`. */
405
+ onConflict: string;
406
+ /** When true, `ON CONFLICT DO NOTHING` (no update of existing rows). */
407
+ ignoreDuplicates?: boolean;
319
408
  }
320
- declare class PostgrestTableApi<Row extends Record<string, unknown> = Record<string, unknown>> {
409
+ /** Upsert without `.select()` `{ data: null }`. */
410
+ declare class PostgrestUpsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
321
411
  private readonly run;
322
412
  private readonly databaseInstanceId;
323
413
  private readonly table;
324
- constructor(run: RunQuery, databaseInstanceId: string, table: string);
325
- select(columns?: string): PostgrestSelectBuilder<Row>;
326
- insert(values: Record<string, unknown> | Record<string, unknown>[]): PostgrestInsertBuilder<Row>;
327
- update(patch: Record<string, unknown>): PostgrestUpdateBuilder<Row>;
328
- delete(): PostgrestDeleteBuilder<Row>;
414
+ private readonly rows;
415
+ private readonly ignoreDuplicates;
416
+ private readonly conflictCols;
417
+ constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[], onConflict: string, ignoreDuplicates: boolean);
418
+ /**
419
+ * Return upserted rows (Supabase: `.upsert().select()`).
420
+ * @see https://supabase.com/docs/reference/javascript/upsert
421
+ */
422
+ select(columns?: string): PostgrestUpsertReturningBuilder<Row>;
423
+ then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
424
+ private executeNoReturn;
425
+ private runUpsert;
426
+ /** Used by returning builder */
427
+ runWithReturning(returning: string): Promise<BrowserSqlExecResult<Row>>;
428
+ }
429
+ declare class PostgrestUpsertReturningBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
430
+ private readonly root;
431
+ private readonly returning;
432
+ constructor(root: PostgrestUpsertRootBuilder<Row>, returning: string);
433
+ then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
434
+ private executeMany;
435
+ single(): Promise<PostgrestResult<Row>>;
436
+ maybeSingle(): Promise<PostgrestResult<Row | null>>;
437
+ }
438
+ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagableDatabase, TableName extends RagableTableNames<Database> = RagableTableNames<Database>> {
439
+ private readonly run;
440
+ private readonly databaseInstanceId;
441
+ private readonly table;
442
+ constructor(run: RunQuery, databaseInstanceId: string, table: TableName extends string ? string : string);
443
+ select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>>;
444
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
445
+ update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>>;
446
+ delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>>;
447
+ /**
448
+ * `INSERT ... ON CONFLICT ... DO UPDATE` (or `DO NOTHING` with `ignoreDuplicates`).
449
+ * @see https://supabase.com/docs/reference/javascript/upsert
450
+ */
451
+ upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
329
452
  }
330
453
 
454
+ /**
455
+ * Ensures the browser SDK hits `/api/...` routes. Accepts either `https://host` or `https://host/api`
456
+ * (same rule as two-arg `createClient(url, opts)` from the package entry).
457
+ */
331
458
  declare function normalizeBrowserApiBase(baseUrl?: string): string;
459
+ /** How {@link RagableBrowserDatabaseClient.query} and `.from()` send `Authorization`. */
460
+ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
332
461
  interface RagableBrowserClientOptions {
333
462
  /** Organization id (UUID) — public agent chat URLs. */
334
463
  organizationId: string;
@@ -341,14 +470,27 @@ interface RagableBrowserClientOptions {
341
470
  * Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
342
471
  */
343
472
  databaseInstanceId?: string;
473
+ /**
474
+ * Database SQL auth. Default `user`: Bearer = JWT from {@link getAccessToken}.
475
+ * `publicAnon`: Bearer = public anon key (read-only SQL only). `admin`: Bearer = data admin key
476
+ * (same SQL rules as a logged-in user; **never** expose in browser bundles).
477
+ */
478
+ dataAuth?: BrowserDataAuthMode;
479
+ /**
480
+ * Static key when {@link dataAuth} is `publicAnon` or `admin` (e.g. `import.meta.env.VITE_…`).
481
+ * Ignored when {@link getDataStaticKey} returns a non-empty string.
482
+ */
483
+ dataStaticKey?: string;
484
+ /** Load anon/admin key at runtime; wins over {@link dataStaticKey} when non-empty. */
485
+ getDataStaticKey?: () => string | null | Promise<string | null>;
344
486
  /**
345
487
  * Returns the end-user access JWT (from login/register/refresh).
346
- * Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
488
+ * Required for `auth.getMe`, `auth.updateMe`, and for `database.query` when {@link dataAuth} is `user` (default).
347
489
  */
348
490
  getAccessToken?: () => string | null | Promise<string | null>;
349
491
  /**
350
492
  * API base URL including `/api`, e.g. `https://api.example.com/api`.
351
- * @default "http://localhost:8080/api"
493
+ * @default `https://ragable-341305259977.asia-southeast1.run.app/api` ({@link DEFAULT_RAGABLE_API_BASE})
352
494
  */
353
495
  baseUrl?: string;
354
496
  fetch?: typeof fetch;
@@ -521,7 +663,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
521
663
  * Supabase-style table API: `.from('items').select().eq('id', 1).single()`.
522
664
  * Pass `databaseInstanceId` here or set `databaseInstanceId` on the client options.
523
665
  */
524
- from<Row extends Record<string, unknown> = Record<string, unknown>>(table: string, databaseInstanceId?: string): PostgrestTableApi<Row>;
666
+ from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
525
667
  }
526
668
  /**
527
669
  * **Supabase-equivalent** browser client factory (no org API key).
@@ -618,4 +760,4 @@ declare function createClient<Database extends RagableDatabase = DefaultRagableD
618
760
  */
619
761
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
620
762
 
621
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteBuilder, PostgrestInsertBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
763
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };