@ragable/sdk 0.6.2 → 0.6.4

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
@@ -100,7 +100,16 @@ declare class RagableError extends RagableSdkError {
100
100
  readonly details: string | undefined;
101
101
  constructor(message: string, status: number, body: unknown);
102
102
  toJSON(): Record<string, unknown>;
103
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
104
+ toString(): string;
103
105
  }
106
+ /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
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;
104
113
  declare class RagableNetworkError extends RagableSdkError {
105
114
  readonly __type: "RagableNetworkError";
106
115
  readonly cause: unknown;
@@ -484,7 +493,7 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
484
493
  private readonly table;
485
494
  constructor(pgFetch: PostgRESTFetch, databaseInstanceId: string, table: TableName extends string ? string : string);
486
495
  select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>, Database, TableName>;
487
- insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
496
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], ...rest: unknown[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
488
497
  update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>, Database, TableName>;
489
498
  delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>, Database, TableName>;
490
499
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
@@ -979,4 +988,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
979
988
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
980
989
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
981
990
 
982
- 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, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
991
+ 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
@@ -100,7 +100,16 @@ declare class RagableError extends RagableSdkError {
100
100
  readonly details: string | undefined;
101
101
  constructor(message: string, status: number, body: unknown);
102
102
  toJSON(): Record<string, unknown>;
103
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
104
+ toString(): string;
103
105
  }
106
+ /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
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;
104
113
  declare class RagableNetworkError extends RagableSdkError {
105
114
  readonly __type: "RagableNetworkError";
106
115
  readonly cause: unknown;
@@ -484,7 +493,7 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
484
493
  private readonly table;
485
494
  constructor(pgFetch: PostgRESTFetch, databaseInstanceId: string, table: TableName extends string ? string : string);
486
495
  select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>, Database, TableName>;
487
- insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
496
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], ...rest: unknown[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
488
497
  update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>, Database, TableName>;
489
498
  delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>, Database, TableName>;
490
499
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
@@ -979,4 +988,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
979
988
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
980
989
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
981
990
 
982
- 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, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
991
+ 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,7 +62,9 @@ __export(index_exports, {
62
62
  createRagableServerClient: () => createRagableServerClient,
63
63
  detectStorage: () => detectStorage,
64
64
  extractErrorMessage: () => extractErrorMessage,
65
+ formatPostgrestError: () => formatPostgrestError,
65
66
  formatRetrievalContext: () => formatRetrievalContext,
67
+ formatSdkError: () => formatSdkError,
66
68
  generateIdempotencyKey: () => generateIdempotencyKey,
67
69
  normalizeBrowserApiBase: () => normalizeBrowserApiBase,
68
70
  parseSseDataLine: () => parseSseDataLine,
@@ -83,6 +85,12 @@ var RagableSdkError = class extends Error {
83
85
  constructor(message) {
84
86
  super(message);
85
87
  this.name = this.constructor.name;
88
+ Object.defineProperty(this, "message", {
89
+ configurable: true,
90
+ enumerable: true,
91
+ writable: true,
92
+ value: message
93
+ });
86
94
  }
87
95
  toJSON() {
88
96
  return {
@@ -102,7 +110,7 @@ var RagableError = class extends RagableSdkError {
102
110
  __publicField(this, "details");
103
111
  this.status = status;
104
112
  this.body = body;
105
- 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;
106
114
  this.details = body && typeof body === "object" ? typeof body.details === "string" ? body.details : void 0 : void 0;
107
115
  }
108
116
  toJSON() {
@@ -114,7 +122,38 @@ var RagableError = class extends RagableSdkError {
114
122
  details: this.details
115
123
  };
116
124
  }
125
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
126
+ toString() {
127
+ const bits = [`${this.name}: ${this.message}`];
128
+ if (this.status) bits.push(`status=${this.status}`);
129
+ if (this.code) bits.push(`code=${this.code}`);
130
+ return bits.join(" \xB7 ");
131
+ }
117
132
  };
133
+ function formatSdkError(err) {
134
+ if (err instanceof RagableError) {
135
+ return `${err.message} (HTTP ${err.status}${err.code ? `, ${err.code}` : ""})`;
136
+ }
137
+ if (err instanceof RagableSdkError) {
138
+ return err.message;
139
+ }
140
+ if (err instanceof Error) {
141
+ return err.message || err.name;
142
+ }
143
+ if (typeof err === "string") return err;
144
+ if (err && typeof err === "object") {
145
+ try {
146
+ const s = JSON.stringify(err);
147
+ if (s !== "{}") return s;
148
+ return "Unknown error (empty object \u2014 avoid `{...error}` spread; use error.message or formatSdkError)";
149
+ } catch {
150
+ }
151
+ }
152
+ return String(err);
153
+ }
154
+ function formatPostgrestError(error) {
155
+ return formatSdkError(error);
156
+ }
118
157
  var RagableNetworkError = class extends RagableSdkError {
119
158
  constructor(message, cause) {
120
159
  super(message);
@@ -684,6 +723,27 @@ function encodeFilterValue(op, value) {
684
723
  }
685
724
  return `${op}.${value}`;
686
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
+ }
687
747
  async function parsePostgRESTResponse(response) {
688
748
  if (response.status === 204) return null;
689
749
  const text = await response.text();
@@ -699,9 +759,8 @@ async function parsePostgRESTResponse(response) {
699
759
  );
700
760
  }
701
761
  if (!response.ok) {
702
- const msg = typeof payload === "object" && payload !== null ? payload.message ?? payload.error ?? response.statusText : response.statusText;
703
- const code = typeof payload === "object" && payload !== null ? payload.code : void 0;
704
- 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);
705
764
  }
706
765
  return payload;
707
766
  }
@@ -1445,7 +1504,14 @@ var PostgrestTableApi = class {
1445
1504
  columns
1446
1505
  );
1447
1506
  }
1448
- insert(values) {
1507
+ insert(values, ...rest) {
1508
+ if (rest.length > 0) {
1509
+ throw new RagableError(
1510
+ ".insert() accepts only one argument: the row object or an array of rows. Do not pass readOnly, options, or a second object \u2014 those apply only to database.query({ sql, readOnly }). PostgREST inserts are writes by default.",
1511
+ 400,
1512
+ { code: "SDK_INSERT_EXTRA_ARGS" }
1513
+ );
1514
+ }
1449
1515
  const rows = Array.isArray(values) ? values : [values];
1450
1516
  return new PostgrestInsertRootBuilder(
1451
1517
  this.pgFetch,
@@ -2482,7 +2548,9 @@ function createRagableServerClient(options) {
2482
2548
  createRagableServerClient,
2483
2549
  detectStorage,
2484
2550
  extractErrorMessage,
2551
+ formatPostgrestError,
2485
2552
  formatRetrievalContext,
2553
+ formatSdkError,
2486
2554
  generateIdempotencyKey,
2487
2555
  normalizeBrowserApiBase,
2488
2556
  parseSseDataLine,