@ragable/sdk 0.6.3 → 0.6.5

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
@@ -105,6 +105,11 @@ declare class RagableError extends RagableSdkError {
105
105
  }
106
106
  /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
107
  declare function formatSdkError(err: unknown): string;
108
+ /**
109
+ * Human-readable line for a PostgREST `{ data, error }` error (or any thrown value).
110
+ * Use in UI instead of `JSON.stringify(error)` or template strings on unknown errors.
111
+ */
112
+ declare function formatPostgrestError(error: unknown): string;
108
113
  declare class RagableNetworkError extends RagableSdkError {
109
114
  readonly __type: "RagableNetworkError";
110
115
  readonly cause: unknown;
@@ -870,13 +875,11 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
870
875
  declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
871
876
  private readonly options;
872
877
  private readonly ragableAuth;
873
- private readonly postgrestFrom?;
874
878
  private readonly fetchImpl;
875
- constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
876
- /**
877
- * PostgREST fluent API same as `client.from('table')`.
878
- * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
879
- */
879
+ private _transport;
880
+ constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
881
+ /** @internal Called by RagableBrowser to share the Transport instance. */
882
+ _setTransport(transport: Transport): void;
880
883
  from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
881
884
  private toUrl;
882
885
  query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
@@ -898,9 +901,9 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
898
901
  readonly auth: RagableBrowserAuthClient<AuthUser>;
899
902
  readonly database: RagableBrowserDatabaseClient<Database>;
900
903
  readonly transport: Transport;
901
- private readonly options;
902
904
  private readonly _ragableAuth;
903
905
  constructor(options: RagableBrowserClientOptions);
906
+ /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
904
907
  from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
905
908
  destroy(): void;
906
909
  }
@@ -983,4 +986,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
983
986
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
984
987
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
985
988
 
986
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
989
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.d.ts CHANGED
@@ -105,6 +105,11 @@ declare class RagableError extends RagableSdkError {
105
105
  }
106
106
  /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
107
  declare function formatSdkError(err: unknown): string;
108
+ /**
109
+ * Human-readable line for a PostgREST `{ data, error }` error (or any thrown value).
110
+ * Use in UI instead of `JSON.stringify(error)` or template strings on unknown errors.
111
+ */
112
+ declare function formatPostgrestError(error: unknown): string;
108
113
  declare class RagableNetworkError extends RagableSdkError {
109
114
  readonly __type: "RagableNetworkError";
110
115
  readonly cause: unknown;
@@ -870,13 +875,11 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
870
875
  declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
871
876
  private readonly options;
872
877
  private readonly ragableAuth;
873
- private readonly postgrestFrom?;
874
878
  private readonly fetchImpl;
875
- constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
876
- /**
877
- * PostgREST fluent API same as `client.from('table')`.
878
- * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
879
- */
879
+ private _transport;
880
+ constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
881
+ /** @internal Called by RagableBrowser to share the Transport instance. */
882
+ _setTransport(transport: Transport): void;
880
883
  from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
881
884
  private toUrl;
882
885
  query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
@@ -898,9 +901,9 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
898
901
  readonly auth: RagableBrowserAuthClient<AuthUser>;
899
902
  readonly database: RagableBrowserDatabaseClient<Database>;
900
903
  readonly transport: Transport;
901
- private readonly options;
902
904
  private readonly _ragableAuth;
903
905
  constructor(options: RagableBrowserClientOptions);
906
+ /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
904
907
  from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
905
908
  destroy(): void;
906
909
  }
@@ -983,4 +986,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
983
986
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
984
987
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
985
988
 
986
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
989
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ __export(index_exports, {
62
62
  createRagableServerClient: () => createRagableServerClient,
63
63
  detectStorage: () => detectStorage,
64
64
  extractErrorMessage: () => extractErrorMessage,
65
+ formatPostgrestError: () => formatPostgrestError,
65
66
  formatRetrievalContext: () => formatRetrievalContext,
66
67
  formatSdkError: () => formatSdkError,
67
68
  generateIdempotencyKey: () => generateIdempotencyKey,
@@ -84,6 +85,12 @@ var RagableSdkError = class extends Error {
84
85
  constructor(message) {
85
86
  super(message);
86
87
  this.name = this.constructor.name;
88
+ Object.defineProperty(this, "message", {
89
+ configurable: true,
90
+ enumerable: true,
91
+ writable: true,
92
+ value: message
93
+ });
87
94
  }
88
95
  toJSON() {
89
96
  return {
@@ -103,7 +110,7 @@ var RagableError = class extends RagableSdkError {
103
110
  __publicField(this, "details");
104
111
  this.status = status;
105
112
  this.body = body;
106
- this.code = body && typeof body === "object" ? typeof body.code === "string" ? body.code : void 0 : void 0;
113
+ this.code = body && typeof body === "object" ? typeof body.code === "string" ? body.code : typeof body.code === "number" ? String(body.code) : void 0 : void 0;
107
114
  this.details = body && typeof body === "object" ? typeof body.details === "string" ? body.details : void 0 : void 0;
108
115
  }
109
116
  toJSON() {
@@ -138,11 +145,15 @@ function formatSdkError(err) {
138
145
  try {
139
146
  const s = JSON.stringify(err);
140
147
  if (s !== "{}") return s;
148
+ return "Unknown error (empty object \u2014 avoid `{...error}` spread; use error.message or formatSdkError)";
141
149
  } catch {
142
150
  }
143
151
  }
144
152
  return String(err);
145
153
  }
154
+ function formatPostgrestError(error) {
155
+ return formatSdkError(error);
156
+ }
146
157
  var RagableNetworkError = class extends RagableSdkError {
147
158
  constructor(message, cause) {
148
159
  super(message);
@@ -712,6 +723,27 @@ function encodeFilterValue(op, value) {
712
723
  }
713
724
  return `${op}.${value}`;
714
725
  }
726
+ function extractPostgRESTErrorMessage(payload, status, statusText) {
727
+ const st = (statusText ?? "").trim();
728
+ if (typeof payload !== "object" || payload === null) {
729
+ return st || `HTTP ${status}`;
730
+ }
731
+ const p = payload;
732
+ const raw = p.message ?? p.error ?? p.hint;
733
+ let msg;
734
+ if (typeof raw === "string") {
735
+ msg = raw;
736
+ } else if (typeof raw === "number" || typeof raw === "boolean") {
737
+ msg = String(raw);
738
+ } else if (raw !== null && raw !== void 0 && typeof raw === "object") {
739
+ msg = JSON.stringify(raw);
740
+ } else {
741
+ msg = st || `HTTP ${status}`;
742
+ }
743
+ msg = msg.trim();
744
+ if (!msg) return st || `HTTP ${status}`;
745
+ return msg;
746
+ }
715
747
  async function parsePostgRESTResponse(response) {
716
748
  if (response.status === 204) return null;
717
749
  const text = await response.text();
@@ -727,9 +759,8 @@ async function parsePostgRESTResponse(response) {
727
759
  );
728
760
  }
729
761
  if (!response.ok) {
730
- const msg = typeof payload === "object" && payload !== null ? payload.message ?? payload.error ?? response.statusText : response.statusText;
731
- const code = typeof payload === "object" && payload !== null ? payload.code : void 0;
732
- throw new RagableError(String(msg), response.status, { code });
762
+ const msg = extractPostgRESTErrorMessage(payload, response.status, response.statusText);
763
+ throw new RagableError(msg, response.status, payload);
733
764
  }
734
765
  return payload;
735
766
  }
@@ -2198,26 +2229,65 @@ var RagableBrowserAuthClient = class {
2198
2229
  }
2199
2230
  };
2200
2231
  var RagableBrowserDatabaseClient = class {
2201
- constructor(options, ragableAuth = null, postgrestFrom) {
2232
+ constructor(options, ragableAuth = null) {
2202
2233
  this.options = options;
2203
2234
  this.ragableAuth = ragableAuth;
2204
- this.postgrestFrom = postgrestFrom;
2205
2235
  __publicField(this, "fetchImpl");
2236
+ __publicField(this, "_transport", null);
2206
2237
  this.fetchImpl = bindFetch(options.fetch);
2207
2238
  }
2208
- /**
2209
- * PostgREST fluent API — same as `client.from('table')`.
2210
- * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
2211
- */
2239
+ /** @internal Called by RagableBrowser to share the Transport instance. */
2240
+ _setTransport(transport) {
2241
+ this._transport = transport;
2242
+ }
2212
2243
  from(table, databaseInstanceId) {
2213
- if (!this.postgrestFrom) {
2244
+ const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2245
+ if (!id) {
2214
2246
  throw new RagableError(
2215
- "database.from() is only available on the client from createBrowserClient().",
2216
- 500,
2217
- { code: "SDK_DATABASE_FROM_UNAVAILABLE" }
2247
+ "database.from() requires databaseInstanceId in client options or as the second argument",
2248
+ 400,
2249
+ { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2218
2250
  );
2219
2251
  }
2220
- return this.postgrestFrom(table, databaseInstanceId);
2252
+ const gid = requireAuthGroupId(this.options);
2253
+ const ragableAuth = this.ragableAuth;
2254
+ const opts = this.options;
2255
+ const transport = this._transport;
2256
+ const fetchImpl = this.fetchImpl;
2257
+ const pgFetch = async (params) => {
2258
+ const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2259
+ const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
2260
+ const qs = params.searchParams.toString();
2261
+ const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2262
+ const headers = new Headers(opts.headers);
2263
+ headers.set("Authorization", `Bearer ${token}`);
2264
+ headers.set("X-Database-Instance-Id", params.databaseInstanceId);
2265
+ if (params.body !== void 0) {
2266
+ headers.set("Content-Type", "application/json");
2267
+ }
2268
+ if (params.headers) {
2269
+ for (const [k, v] of Object.entries(params.headers)) {
2270
+ headers.set(k, v);
2271
+ }
2272
+ }
2273
+ if (transport) {
2274
+ return transport.execute({
2275
+ url,
2276
+ method: params.method,
2277
+ headers,
2278
+ body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2279
+ signal: params.signal,
2280
+ idempotencyKey: params.idempotencyKey
2281
+ });
2282
+ }
2283
+ return fetchImpl(url, {
2284
+ method: params.method,
2285
+ headers,
2286
+ body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2287
+ signal: params.signal
2288
+ });
2289
+ };
2290
+ return new PostgrestTableApi(pgFetch, id, table);
2221
2291
  }
2222
2292
  toUrl(path) {
2223
2293
  return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
@@ -2227,8 +2297,10 @@ var RagableBrowserDatabaseClient = class {
2227
2297
  const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
2228
2298
  const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2229
2299
  if (!databaseInstanceId) {
2230
- throw new Error(
2231
- "database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })"
2300
+ throw new RagableError(
2301
+ "database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
2302
+ 400,
2303
+ { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2232
2304
  );
2233
2305
  }
2234
2306
  const headers = this.baseHeaders();
@@ -2301,9 +2373,7 @@ var RagableBrowser = class {
2301
2373
  __publicField(this, "auth");
2302
2374
  __publicField(this, "database");
2303
2375
  __publicField(this, "transport");
2304
- __publicField(this, "options");
2305
2376
  __publicField(this, "_ragableAuth");
2306
- this.options = options;
2307
2377
  this.transport = new Transport({
2308
2378
  fetch: options.fetch,
2309
2379
  headers: options.headers,
@@ -2334,49 +2404,13 @@ var RagableBrowser = class {
2334
2404
  this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
2335
2405
  this.database = new RagableBrowserDatabaseClient(
2336
2406
  options,
2337
- this._ragableAuth,
2338
- (table, databaseInstanceId) => this.from(table, databaseInstanceId)
2407
+ this._ragableAuth
2339
2408
  );
2409
+ this.database._setTransport(this.transport);
2340
2410
  }
2411
+ /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
2341
2412
  from(table, databaseInstanceId) {
2342
- const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2343
- if (!id) {
2344
- throw new RagableError(
2345
- "RagableBrowser.from() requires databaseInstanceId in client options or as the second argument",
2346
- 400,
2347
- { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2348
- );
2349
- }
2350
- const gid = requireAuthGroupId(this.options);
2351
- const ragableAuth = this._ragableAuth;
2352
- const opts = this.options;
2353
- const transport = this.transport;
2354
- const pgFetch = async (params) => {
2355
- const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2356
- const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
2357
- const qs = params.searchParams.toString();
2358
- const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2359
- const headers = new Headers(opts.headers);
2360
- headers.set("Authorization", `Bearer ${token}`);
2361
- headers.set("X-Database-Instance-Id", params.databaseInstanceId);
2362
- if (params.body !== void 0) {
2363
- headers.set("Content-Type", "application/json");
2364
- }
2365
- if (params.headers) {
2366
- for (const [k, v] of Object.entries(params.headers)) {
2367
- headers.set(k, v);
2368
- }
2369
- }
2370
- return transport.execute({
2371
- url,
2372
- method: params.method,
2373
- headers,
2374
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2375
- signal: params.signal,
2376
- idempotencyKey: params.idempotencyKey
2377
- });
2378
- };
2379
- return new PostgrestTableApi(pgFetch, id, table);
2413
+ return this.database.from(table, databaseInstanceId);
2380
2414
  }
2381
2415
  destroy() {
2382
2416
  this._ragableAuth?.destroy();
@@ -2517,6 +2551,7 @@ function createRagableServerClient(options) {
2517
2551
  createRagableServerClient,
2518
2552
  detectStorage,
2519
2553
  extractErrorMessage,
2554
+ formatPostgrestError,
2520
2555
  formatRetrievalContext,
2521
2556
  formatSdkError,
2522
2557
  generateIdempotencyKey,