@ragable/sdk 0.6.5 → 0.6.7
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 +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.js +230 -188
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +228 -188
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,6 +32,8 @@ __export(index_exports, {
|
|
|
32
32
|
PostgrestDeleteRootBuilder: () => PostgrestDeleteRootBuilder,
|
|
33
33
|
PostgrestInsertReturningBuilder: () => PostgrestInsertReturningBuilder,
|
|
34
34
|
PostgrestInsertRootBuilder: () => PostgrestInsertRootBuilder,
|
|
35
|
+
PostgrestInsertSdkErrorReturning: () => PostgrestInsertSdkErrorReturning,
|
|
36
|
+
PostgrestInsertSdkErrorRoot: () => PostgrestInsertSdkErrorRoot,
|
|
35
37
|
PostgrestSelectBuilder: () => PostgrestSelectBuilder,
|
|
36
38
|
PostgrestTableApi: () => PostgrestTableApi,
|
|
37
39
|
PostgrestUpdateReturningBuilder: () => PostgrestUpdateReturningBuilder,
|
|
@@ -932,24 +934,48 @@ var PostgrestSelectBuilder = class {
|
|
|
932
934
|
});
|
|
933
935
|
}
|
|
934
936
|
async maybeSingle() {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
});
|
|
943
|
-
const rows = await parsePostgRESTResponse(response);
|
|
944
|
-
if (rows.length > 1) {
|
|
945
|
-
throw new RagableError(
|
|
937
|
+
const many = await this.executeMany();
|
|
938
|
+
if (many.error) return { data: null, error: many.error };
|
|
939
|
+
const rows = many.data ?? [];
|
|
940
|
+
if (rows.length > 1) {
|
|
941
|
+
return {
|
|
942
|
+
data: null,
|
|
943
|
+
error: new RagableError(
|
|
946
944
|
"JSON object requested, multiple (or no) rows returned",
|
|
947
945
|
406,
|
|
948
946
|
{ code: "PGRST116" }
|
|
949
|
-
)
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
}
|
|
947
|
+
)
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
return { data: rows[0] ?? null, error: null };
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
var PostgrestInsertSdkErrorRoot = class {
|
|
954
|
+
constructor(error) {
|
|
955
|
+
this.error = error;
|
|
956
|
+
}
|
|
957
|
+
select(_columns = "*") {
|
|
958
|
+
return new PostgrestInsertSdkErrorReturning(this.error);
|
|
959
|
+
}
|
|
960
|
+
abortSignal(_signal) {
|
|
961
|
+
return this;
|
|
962
|
+
}
|
|
963
|
+
then(onfulfilled, onrejected) {
|
|
964
|
+
return Promise.resolve({ data: null, error: this.error }).then(onfulfilled, onrejected);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
var PostgrestInsertSdkErrorReturning = class {
|
|
968
|
+
constructor(error) {
|
|
969
|
+
this.error = error;
|
|
970
|
+
}
|
|
971
|
+
then(onfulfilled, onrejected) {
|
|
972
|
+
return Promise.resolve({ data: null, error: this.error }).then(onfulfilled, onrejected);
|
|
973
|
+
}
|
|
974
|
+
async single() {
|
|
975
|
+
return { data: null, error: this.error };
|
|
976
|
+
}
|
|
977
|
+
async maybeSingle() {
|
|
978
|
+
return { data: null, error: this.error };
|
|
953
979
|
}
|
|
954
980
|
};
|
|
955
981
|
var PostgrestInsertRootBuilder = class {
|
|
@@ -1030,34 +1056,36 @@ var PostgrestInsertReturningBuilder = class {
|
|
|
1030
1056
|
});
|
|
1031
1057
|
}
|
|
1032
1058
|
async single() {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1059
|
+
const many = await this.executeMany();
|
|
1060
|
+
if (many.error) return { data: null, error: many.error };
|
|
1061
|
+
const rows = many.data ?? [];
|
|
1062
|
+
if (rows.length === 0 || rows.length > 1) {
|
|
1063
|
+
return {
|
|
1064
|
+
data: null,
|
|
1065
|
+
error: new RagableError(
|
|
1039
1066
|
"JSON object requested, multiple (or no) rows returned",
|
|
1040
1067
|
406,
|
|
1041
1068
|
{ code: "PGRST116" }
|
|
1042
|
-
)
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1069
|
+
)
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
return { data: rows[0], error: null };
|
|
1046
1073
|
}
|
|
1047
1074
|
async maybeSingle() {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1075
|
+
const many = await this.executeMany();
|
|
1076
|
+
if (many.error) return { data: null, error: many.error };
|
|
1077
|
+
const rows = many.data ?? [];
|
|
1078
|
+
if (rows.length > 1) {
|
|
1079
|
+
return {
|
|
1080
|
+
data: null,
|
|
1081
|
+
error: new RagableError(
|
|
1054
1082
|
"JSON object requested, multiple (or no) rows returned",
|
|
1055
1083
|
406,
|
|
1056
1084
|
{ code: "PGRST116" }
|
|
1057
|
-
)
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
}
|
|
1085
|
+
)
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
return { data: rows[0] ?? null, error: null };
|
|
1061
1089
|
}
|
|
1062
1090
|
};
|
|
1063
1091
|
var PostgrestUpdateRootBuilder = class {
|
|
@@ -1205,34 +1233,36 @@ var PostgrestUpdateReturningBuilder = class {
|
|
|
1205
1233
|
});
|
|
1206
1234
|
}
|
|
1207
1235
|
async single() {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1236
|
+
const many = await this.executeMany();
|
|
1237
|
+
if (many.error) return { data: null, error: many.error };
|
|
1238
|
+
const rows = many.data ?? [];
|
|
1239
|
+
if (rows.length === 0 || rows.length > 1) {
|
|
1240
|
+
return {
|
|
1241
|
+
data: null,
|
|
1242
|
+
error: new RagableError(
|
|
1214
1243
|
"JSON object requested, multiple (or no) rows returned",
|
|
1215
1244
|
406,
|
|
1216
1245
|
{ code: "PGRST116" }
|
|
1217
|
-
)
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
}
|
|
1246
|
+
)
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
return { data: rows[0], error: null };
|
|
1221
1250
|
}
|
|
1222
1251
|
async maybeSingle() {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1252
|
+
const many = await this.executeMany();
|
|
1253
|
+
if (many.error) return { data: null, error: many.error };
|
|
1254
|
+
const rows = many.data ?? [];
|
|
1255
|
+
if (rows.length > 1) {
|
|
1256
|
+
return {
|
|
1257
|
+
data: null,
|
|
1258
|
+
error: new RagableError(
|
|
1229
1259
|
"JSON object requested, multiple (or no) rows returned",
|
|
1230
1260
|
406,
|
|
1231
1261
|
{ code: "PGRST116" }
|
|
1232
|
-
)
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
}
|
|
1262
|
+
)
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
return { data: rows[0] ?? null, error: null };
|
|
1236
1266
|
}
|
|
1237
1267
|
};
|
|
1238
1268
|
var PostgrestDeleteRootBuilder = class {
|
|
@@ -1364,34 +1394,36 @@ var PostgrestDeleteReturningBuilder = class {
|
|
|
1364
1394
|
});
|
|
1365
1395
|
}
|
|
1366
1396
|
async single() {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1397
|
+
const many = await this.executeMany();
|
|
1398
|
+
if (many.error) return { data: null, error: many.error };
|
|
1399
|
+
const rows = many.data ?? [];
|
|
1400
|
+
if (rows.length === 0 || rows.length > 1) {
|
|
1401
|
+
return {
|
|
1402
|
+
data: null,
|
|
1403
|
+
error: new RagableError(
|
|
1373
1404
|
"JSON object requested, multiple (or no) rows returned",
|
|
1374
1405
|
406,
|
|
1375
1406
|
{ code: "PGRST116" }
|
|
1376
|
-
)
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
}
|
|
1407
|
+
)
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
return { data: rows[0], error: null };
|
|
1380
1411
|
}
|
|
1381
1412
|
async maybeSingle() {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1413
|
+
const many = await this.executeMany();
|
|
1414
|
+
if (many.error) return { data: null, error: many.error };
|
|
1415
|
+
const rows = many.data ?? [];
|
|
1416
|
+
if (rows.length > 1) {
|
|
1417
|
+
return {
|
|
1418
|
+
data: null,
|
|
1419
|
+
error: new RagableError(
|
|
1388
1420
|
"JSON object requested, multiple (or no) rows returned",
|
|
1389
1421
|
406,
|
|
1390
1422
|
{ code: "PGRST116" }
|
|
1391
|
-
)
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
}
|
|
1423
|
+
)
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
return { data: rows[0] ?? null, error: null };
|
|
1395
1427
|
}
|
|
1396
1428
|
};
|
|
1397
1429
|
var PostgrestUpsertRootBuilder = class {
|
|
@@ -1460,34 +1492,36 @@ var PostgrestUpsertReturningBuilder = class {
|
|
|
1460
1492
|
});
|
|
1461
1493
|
}
|
|
1462
1494
|
async single() {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1495
|
+
const many = await this.executeMany();
|
|
1496
|
+
if (many.error) return { data: null, error: many.error };
|
|
1497
|
+
const rows = many.data ?? [];
|
|
1498
|
+
if (rows.length === 0 || rows.length > 1) {
|
|
1499
|
+
return {
|
|
1500
|
+
data: null,
|
|
1501
|
+
error: new RagableError(
|
|
1469
1502
|
"JSON object requested, multiple (or no) rows returned",
|
|
1470
1503
|
406,
|
|
1471
1504
|
{ code: "PGRST116" }
|
|
1472
|
-
)
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
}
|
|
1505
|
+
)
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
return { data: rows[0], error: null };
|
|
1476
1509
|
}
|
|
1477
1510
|
async maybeSingle() {
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1511
|
+
const many = await this.executeMany();
|
|
1512
|
+
if (many.error) return { data: null, error: many.error };
|
|
1513
|
+
const rows = many.data ?? [];
|
|
1514
|
+
if (rows.length > 1) {
|
|
1515
|
+
return {
|
|
1516
|
+
data: null,
|
|
1517
|
+
error: new RagableError(
|
|
1484
1518
|
"JSON object requested, multiple (or no) rows returned",
|
|
1485
1519
|
406,
|
|
1486
1520
|
{ code: "PGRST116" }
|
|
1487
|
-
)
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
}
|
|
1521
|
+
)
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
return { data: rows[0] ?? null, error: null };
|
|
1491
1525
|
}
|
|
1492
1526
|
};
|
|
1493
1527
|
var PostgrestTableApi = class {
|
|
@@ -1506,11 +1540,14 @@ var PostgrestTableApi = class {
|
|
|
1506
1540
|
}
|
|
1507
1541
|
insert(values, ...rest) {
|
|
1508
1542
|
if (rest.length > 0) {
|
|
1509
|
-
|
|
1543
|
+
const err = new RagableError(
|
|
1510
1544
|
".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
1545
|
400,
|
|
1512
1546
|
{ code: "SDK_INSERT_EXTRA_ARGS" }
|
|
1513
1547
|
);
|
|
1548
|
+
return new PostgrestInsertSdkErrorRoot(
|
|
1549
|
+
err
|
|
1550
|
+
);
|
|
1514
1551
|
}
|
|
1515
1552
|
const rows = Array.isArray(values) ? values : [values];
|
|
1516
1553
|
return new PostgrestInsertRootBuilder(
|
|
@@ -2125,14 +2162,6 @@ async function resolveDatabaseAuthBearer(options, ragableAuth) {
|
|
|
2125
2162
|
}
|
|
2126
2163
|
return key;
|
|
2127
2164
|
}
|
|
2128
|
-
async function parseJsonOrThrow2(response) {
|
|
2129
|
-
const payload = await parseMaybeJsonBody(response);
|
|
2130
|
-
if (!response.ok) {
|
|
2131
|
-
const message = extractErrorMessage(payload, response.statusText);
|
|
2132
|
-
throw new RagableError(message, response.status, payload);
|
|
2133
|
-
}
|
|
2134
|
-
return payload;
|
|
2135
|
-
}
|
|
2136
2165
|
var RagableBrowserAuthClient = class {
|
|
2137
2166
|
constructor(_options, ragableAuth = null) {
|
|
2138
2167
|
this.ragableAuth = ragableAuth;
|
|
@@ -2234,96 +2263,107 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2234
2263
|
this.ragableAuth = ragableAuth;
|
|
2235
2264
|
__publicField(this, "fetchImpl");
|
|
2236
2265
|
__publicField(this, "_transport", null);
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
this
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
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);
|
|
2266
|
+
/**
|
|
2267
|
+
* PostgREST table access. Instance field so `client.database.from` is always an own,
|
|
2268
|
+
* enumerable function (avoids rare prototype/bundler issues).
|
|
2269
|
+
*/
|
|
2270
|
+
__publicField(this, "from", (table, databaseInstanceId) => {
|
|
2271
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim() || "";
|
|
2272
|
+
const ragableAuth = this.ragableAuth;
|
|
2273
|
+
const opts = this.options;
|
|
2274
|
+
const transport = this._transport;
|
|
2275
|
+
const fetchImpl = this.fetchImpl;
|
|
2276
|
+
const pgFetch = async (params) => {
|
|
2277
|
+
if (!params.databaseInstanceId?.trim()) {
|
|
2278
|
+
throw new RagableError(
|
|
2279
|
+
"database.from() requires databaseInstanceId in client options or as the second argument",
|
|
2280
|
+
400,
|
|
2281
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2282
|
+
);
|
|
2271
2283
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2284
|
+
const gid = requireAuthGroupId(opts);
|
|
2285
|
+
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2286
|
+
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
2287
|
+
const qs = params.searchParams.toString();
|
|
2288
|
+
const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2289
|
+
const headers = new Headers(opts.headers);
|
|
2290
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
2291
|
+
headers.set("X-Database-Instance-Id", params.databaseInstanceId);
|
|
2292
|
+
if (params.body !== void 0) {
|
|
2293
|
+
headers.set("Content-Type", "application/json");
|
|
2294
|
+
}
|
|
2295
|
+
if (params.headers) {
|
|
2296
|
+
for (const [k, v] of Object.entries(params.headers)) {
|
|
2297
|
+
headers.set(k, v);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
if (transport) {
|
|
2301
|
+
return transport.execute({
|
|
2302
|
+
url,
|
|
2303
|
+
method: params.method,
|
|
2304
|
+
headers,
|
|
2305
|
+
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2306
|
+
signal: params.signal,
|
|
2307
|
+
idempotencyKey: params.idempotencyKey
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
return fetchImpl(url, {
|
|
2276
2311
|
method: params.method,
|
|
2277
2312
|
headers,
|
|
2278
2313
|
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2279
|
-
signal: params.signal
|
|
2280
|
-
idempotencyKey: params.idempotencyKey
|
|
2314
|
+
signal: params.signal
|
|
2281
2315
|
});
|
|
2282
|
-
}
|
|
2283
|
-
return
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2316
|
+
};
|
|
2317
|
+
return new PostgrestTableApi(pgFetch, id, table);
|
|
2318
|
+
});
|
|
2319
|
+
__publicField(this, "query", async (params) => {
|
|
2320
|
+
return asPostgrestResponse(async () => {
|
|
2321
|
+
const gid = requireAuthGroupId(this.options);
|
|
2322
|
+
const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
|
|
2323
|
+
const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2324
|
+
if (!databaseInstanceId) {
|
|
2325
|
+
throw new RagableError(
|
|
2326
|
+
"database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
|
|
2327
|
+
400,
|
|
2328
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2329
|
+
);
|
|
2330
|
+
}
|
|
2331
|
+
const headers = this.baseHeaders();
|
|
2332
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
2333
|
+
headers.set("Content-Type", "application/json");
|
|
2334
|
+
const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
|
|
2335
|
+
const response = await this.fetchImpl(
|
|
2336
|
+
this.toUrl(`/auth-groups/${gid}/data/query`),
|
|
2337
|
+
{
|
|
2338
|
+
method: "POST",
|
|
2339
|
+
headers,
|
|
2340
|
+
body: JSON.stringify({
|
|
2341
|
+
databaseInstanceId,
|
|
2342
|
+
sql: params.sql,
|
|
2343
|
+
...params.params !== void 0 ? { params: params.params } : {},
|
|
2344
|
+
readOnly,
|
|
2345
|
+
...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
|
|
2346
|
+
...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
|
|
2347
|
+
})
|
|
2348
|
+
}
|
|
2349
|
+
);
|
|
2350
|
+
const payload = await parseMaybeJsonBody(response);
|
|
2351
|
+
if (!response.ok) {
|
|
2352
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
2353
|
+
throw new RagableError(message, response.status, payload);
|
|
2354
|
+
}
|
|
2355
|
+
return payload;
|
|
2288
2356
|
});
|
|
2289
|
-
};
|
|
2290
|
-
|
|
2357
|
+
});
|
|
2358
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
2359
|
+
}
|
|
2360
|
+
/** @internal Called by RagableBrowser to share the Transport instance. */
|
|
2361
|
+
_setTransport(transport) {
|
|
2362
|
+
this._transport = transport;
|
|
2291
2363
|
}
|
|
2292
2364
|
toUrl(path) {
|
|
2293
2365
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2294
2366
|
}
|
|
2295
|
-
async query(params) {
|
|
2296
|
-
const gid = requireAuthGroupId(this.options);
|
|
2297
|
-
const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
|
|
2298
|
-
const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2299
|
-
if (!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" }
|
|
2304
|
-
);
|
|
2305
|
-
}
|
|
2306
|
-
const headers = this.baseHeaders();
|
|
2307
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
2308
|
-
headers.set("Content-Type", "application/json");
|
|
2309
|
-
const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
|
|
2310
|
-
const response = await this.fetchImpl(
|
|
2311
|
-
this.toUrl(`/auth-groups/${gid}/data/query`),
|
|
2312
|
-
{
|
|
2313
|
-
method: "POST",
|
|
2314
|
-
headers,
|
|
2315
|
-
body: JSON.stringify({
|
|
2316
|
-
databaseInstanceId,
|
|
2317
|
-
sql: params.sql,
|
|
2318
|
-
...params.params !== void 0 ? { params: params.params } : {},
|
|
2319
|
-
readOnly,
|
|
2320
|
-
...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
|
|
2321
|
-
...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
|
|
2322
|
-
})
|
|
2323
|
-
}
|
|
2324
|
-
);
|
|
2325
|
-
return parseJsonOrThrow2(response);
|
|
2326
|
-
}
|
|
2327
2367
|
baseHeaders() {
|
|
2328
2368
|
return new Headers(this.options.headers);
|
|
2329
2369
|
}
|
|
@@ -2374,6 +2414,10 @@ var RagableBrowser = class {
|
|
|
2374
2414
|
__publicField(this, "database");
|
|
2375
2415
|
__publicField(this, "transport");
|
|
2376
2416
|
__publicField(this, "_ragableAuth");
|
|
2417
|
+
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
2418
|
+
__publicField(this, "from", (table, databaseInstanceId) => {
|
|
2419
|
+
return this.database.from(table, databaseInstanceId);
|
|
2420
|
+
});
|
|
2377
2421
|
this.transport = new Transport({
|
|
2378
2422
|
fetch: options.fetch,
|
|
2379
2423
|
headers: options.headers,
|
|
@@ -2408,10 +2452,6 @@ var RagableBrowser = class {
|
|
|
2408
2452
|
);
|
|
2409
2453
|
this.database._setTransport(this.transport);
|
|
2410
2454
|
}
|
|
2411
|
-
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
2412
|
-
from(table, databaseInstanceId) {
|
|
2413
|
-
return this.database.from(table, databaseInstanceId);
|
|
2414
|
-
}
|
|
2415
2455
|
destroy() {
|
|
2416
2456
|
this._ragableAuth?.destroy();
|
|
2417
2457
|
}
|
|
@@ -2521,6 +2561,8 @@ function createRagableServerClient(options) {
|
|
|
2521
2561
|
PostgrestDeleteRootBuilder,
|
|
2522
2562
|
PostgrestInsertReturningBuilder,
|
|
2523
2563
|
PostgrestInsertRootBuilder,
|
|
2564
|
+
PostgrestInsertSdkErrorReturning,
|
|
2565
|
+
PostgrestInsertSdkErrorRoot,
|
|
2524
2566
|
PostgrestSelectBuilder,
|
|
2525
2567
|
PostgrestTableApi,
|
|
2526
2568
|
PostgrestUpdateReturningBuilder,
|