@ragable/sdk 0.6.1 → 0.6.3
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 +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +58 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -45,7 +45,34 @@ var RagableError = class extends RagableSdkError {
|
|
|
45
45
|
details: this.details
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
/** Stable string for logs — avoids `{}` when coercing or stringifying. */
|
|
49
|
+
toString() {
|
|
50
|
+
const bits = [`${this.name}: ${this.message}`];
|
|
51
|
+
if (this.status) bits.push(`status=${this.status}`);
|
|
52
|
+
if (this.code) bits.push(`code=${this.code}`);
|
|
53
|
+
return bits.join(" \xB7 ");
|
|
54
|
+
}
|
|
48
55
|
};
|
|
56
|
+
function formatSdkError(err) {
|
|
57
|
+
if (err instanceof RagableError) {
|
|
58
|
+
return `${err.message} (HTTP ${err.status}${err.code ? `, ${err.code}` : ""})`;
|
|
59
|
+
}
|
|
60
|
+
if (err instanceof RagableSdkError) {
|
|
61
|
+
return err.message;
|
|
62
|
+
}
|
|
63
|
+
if (err instanceof Error) {
|
|
64
|
+
return err.message || err.name;
|
|
65
|
+
}
|
|
66
|
+
if (typeof err === "string") return err;
|
|
67
|
+
if (err && typeof err === "object") {
|
|
68
|
+
try {
|
|
69
|
+
const s = JSON.stringify(err);
|
|
70
|
+
if (s !== "{}") return s;
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return String(err);
|
|
75
|
+
}
|
|
49
76
|
var RagableNetworkError = class extends RagableSdkError {
|
|
50
77
|
constructor(message, cause) {
|
|
51
78
|
super(message);
|
|
@@ -1376,7 +1403,14 @@ var PostgrestTableApi = class {
|
|
|
1376
1403
|
columns
|
|
1377
1404
|
);
|
|
1378
1405
|
}
|
|
1379
|
-
insert(values) {
|
|
1406
|
+
insert(values, ...rest) {
|
|
1407
|
+
if (rest.length > 0) {
|
|
1408
|
+
throw new RagableError(
|
|
1409
|
+
".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.",
|
|
1410
|
+
400,
|
|
1411
|
+
{ code: "SDK_INSERT_EXTRA_ARGS" }
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1380
1414
|
const rows = Array.isArray(values) ? values : [values];
|
|
1381
1415
|
return new PostgrestInsertRootBuilder(
|
|
1382
1416
|
this.pgFetch,
|
|
@@ -2094,12 +2128,27 @@ var RagableBrowserAuthClient = class {
|
|
|
2094
2128
|
}
|
|
2095
2129
|
};
|
|
2096
2130
|
var RagableBrowserDatabaseClient = class {
|
|
2097
|
-
constructor(options, ragableAuth = null) {
|
|
2131
|
+
constructor(options, ragableAuth = null, postgrestFrom) {
|
|
2098
2132
|
this.options = options;
|
|
2099
2133
|
this.ragableAuth = ragableAuth;
|
|
2134
|
+
this.postgrestFrom = postgrestFrom;
|
|
2100
2135
|
__publicField(this, "fetchImpl");
|
|
2101
2136
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2102
2137
|
}
|
|
2138
|
+
/**
|
|
2139
|
+
* PostgREST fluent API — same as `client.from('table')`.
|
|
2140
|
+
* Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
|
|
2141
|
+
*/
|
|
2142
|
+
from(table, databaseInstanceId) {
|
|
2143
|
+
if (!this.postgrestFrom) {
|
|
2144
|
+
throw new RagableError(
|
|
2145
|
+
"database.from() is only available on the client from createBrowserClient().",
|
|
2146
|
+
500,
|
|
2147
|
+
{ code: "SDK_DATABASE_FROM_UNAVAILABLE" }
|
|
2148
|
+
);
|
|
2149
|
+
}
|
|
2150
|
+
return this.postgrestFrom(table, databaseInstanceId);
|
|
2151
|
+
}
|
|
2103
2152
|
toUrl(path) {
|
|
2104
2153
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2105
2154
|
}
|
|
@@ -2213,7 +2262,11 @@ var RagableBrowser = class {
|
|
|
2213
2262
|
}
|
|
2214
2263
|
this.agents = new RagableBrowserAgentsClient(options);
|
|
2215
2264
|
this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
|
|
2216
|
-
this.database = new RagableBrowserDatabaseClient(
|
|
2265
|
+
this.database = new RagableBrowserDatabaseClient(
|
|
2266
|
+
options,
|
|
2267
|
+
this._ragableAuth,
|
|
2268
|
+
(table, databaseInstanceId) => this.from(table, databaseInstanceId)
|
|
2269
|
+
);
|
|
2217
2270
|
}
|
|
2218
2271
|
from(table, databaseInstanceId) {
|
|
2219
2272
|
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
@@ -2394,6 +2447,7 @@ export {
|
|
|
2394
2447
|
detectStorage,
|
|
2395
2448
|
extractErrorMessage,
|
|
2396
2449
|
formatRetrievalContext,
|
|
2450
|
+
formatSdkError,
|
|
2397
2451
|
generateIdempotencyKey,
|
|
2398
2452
|
normalizeBrowserApiBase,
|
|
2399
2453
|
parseSseDataLine,
|