@ragable/sdk 0.6.4 → 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 +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +58 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -875,13 +875,11 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
875
875
|
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
876
876
|
private readonly options;
|
|
877
877
|
private readonly ragableAuth;
|
|
878
|
-
private readonly postgrestFrom?;
|
|
879
878
|
private readonly fetchImpl;
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
*/
|
|
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;
|
|
885
883
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
886
884
|
private toUrl;
|
|
887
885
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
@@ -903,9 +901,9 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
903
901
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
904
902
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
905
903
|
readonly transport: Transport;
|
|
906
|
-
private readonly options;
|
|
907
904
|
private readonly _ragableAuth;
|
|
908
905
|
constructor(options: RagableBrowserClientOptions);
|
|
906
|
+
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
909
907
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
910
908
|
destroy(): void;
|
|
911
909
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -875,13 +875,11 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
875
875
|
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
876
876
|
private readonly options;
|
|
877
877
|
private readonly ragableAuth;
|
|
878
|
-
private readonly postgrestFrom?;
|
|
879
878
|
private readonly fetchImpl;
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
*/
|
|
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;
|
|
885
883
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
886
884
|
private toUrl;
|
|
887
885
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
@@ -903,9 +901,9 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
903
901
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
904
902
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
905
903
|
readonly transport: Transport;
|
|
906
|
-
private readonly options;
|
|
907
904
|
private readonly _ragableAuth;
|
|
908
905
|
constructor(options: RagableBrowserClientOptions);
|
|
906
|
+
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
909
907
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
910
908
|
destroy(): void;
|
|
911
909
|
}
|
package/dist/index.js
CHANGED
|
@@ -2229,26 +2229,65 @@ var RagableBrowserAuthClient = class {
|
|
|
2229
2229
|
}
|
|
2230
2230
|
};
|
|
2231
2231
|
var RagableBrowserDatabaseClient = class {
|
|
2232
|
-
constructor(options, ragableAuth = null
|
|
2232
|
+
constructor(options, ragableAuth = null) {
|
|
2233
2233
|
this.options = options;
|
|
2234
2234
|
this.ragableAuth = ragableAuth;
|
|
2235
|
-
this.postgrestFrom = postgrestFrom;
|
|
2236
2235
|
__publicField(this, "fetchImpl");
|
|
2236
|
+
__publicField(this, "_transport", null);
|
|
2237
2237
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2238
2238
|
}
|
|
2239
|
-
/**
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2239
|
+
/** @internal Called by RagableBrowser to share the Transport instance. */
|
|
2240
|
+
_setTransport(transport) {
|
|
2241
|
+
this._transport = transport;
|
|
2242
|
+
}
|
|
2243
2243
|
from(table, databaseInstanceId) {
|
|
2244
|
-
|
|
2244
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2245
|
+
if (!id) {
|
|
2245
2246
|
throw new RagableError(
|
|
2246
|
-
"database.from()
|
|
2247
|
-
|
|
2248
|
-
{ code: "
|
|
2247
|
+
"database.from() requires databaseInstanceId in client options or as the second argument",
|
|
2248
|
+
400,
|
|
2249
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2249
2250
|
);
|
|
2250
2251
|
}
|
|
2251
|
-
|
|
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);
|
|
2252
2291
|
}
|
|
2253
2292
|
toUrl(path) {
|
|
2254
2293
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
@@ -2258,8 +2297,10 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2258
2297
|
const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
|
|
2259
2298
|
const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2260
2299
|
if (!databaseInstanceId) {
|
|
2261
|
-
throw new
|
|
2262
|
-
"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" }
|
|
2263
2304
|
);
|
|
2264
2305
|
}
|
|
2265
2306
|
const headers = this.baseHeaders();
|
|
@@ -2332,9 +2373,7 @@ var RagableBrowser = class {
|
|
|
2332
2373
|
__publicField(this, "auth");
|
|
2333
2374
|
__publicField(this, "database");
|
|
2334
2375
|
__publicField(this, "transport");
|
|
2335
|
-
__publicField(this, "options");
|
|
2336
2376
|
__publicField(this, "_ragableAuth");
|
|
2337
|
-
this.options = options;
|
|
2338
2377
|
this.transport = new Transport({
|
|
2339
2378
|
fetch: options.fetch,
|
|
2340
2379
|
headers: options.headers,
|
|
@@ -2365,49 +2404,13 @@ var RagableBrowser = class {
|
|
|
2365
2404
|
this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
|
|
2366
2405
|
this.database = new RagableBrowserDatabaseClient(
|
|
2367
2406
|
options,
|
|
2368
|
-
this._ragableAuth
|
|
2369
|
-
(table, databaseInstanceId) => this.from(table, databaseInstanceId)
|
|
2407
|
+
this._ragableAuth
|
|
2370
2408
|
);
|
|
2409
|
+
this.database._setTransport(this.transport);
|
|
2371
2410
|
}
|
|
2411
|
+
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
2372
2412
|
from(table, databaseInstanceId) {
|
|
2373
|
-
|
|
2374
|
-
if (!id) {
|
|
2375
|
-
throw new RagableError(
|
|
2376
|
-
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument",
|
|
2377
|
-
400,
|
|
2378
|
-
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2379
|
-
);
|
|
2380
|
-
}
|
|
2381
|
-
const gid = requireAuthGroupId(this.options);
|
|
2382
|
-
const ragableAuth = this._ragableAuth;
|
|
2383
|
-
const opts = this.options;
|
|
2384
|
-
const transport = this.transport;
|
|
2385
|
-
const pgFetch = async (params) => {
|
|
2386
|
-
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2387
|
-
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
2388
|
-
const qs = params.searchParams.toString();
|
|
2389
|
-
const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2390
|
-
const headers = new Headers(opts.headers);
|
|
2391
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
2392
|
-
headers.set("X-Database-Instance-Id", params.databaseInstanceId);
|
|
2393
|
-
if (params.body !== void 0) {
|
|
2394
|
-
headers.set("Content-Type", "application/json");
|
|
2395
|
-
}
|
|
2396
|
-
if (params.headers) {
|
|
2397
|
-
for (const [k, v] of Object.entries(params.headers)) {
|
|
2398
|
-
headers.set(k, v);
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
return transport.execute({
|
|
2402
|
-
url,
|
|
2403
|
-
method: params.method,
|
|
2404
|
-
headers,
|
|
2405
|
-
body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
|
|
2406
|
-
signal: params.signal,
|
|
2407
|
-
idempotencyKey: params.idempotencyKey
|
|
2408
|
-
});
|
|
2409
|
-
};
|
|
2410
|
-
return new PostgrestTableApi(pgFetch, id, table);
|
|
2413
|
+
return this.database.from(table, databaseInstanceId);
|
|
2411
2414
|
}
|
|
2412
2415
|
destroy() {
|
|
2413
2416
|
this._ragableAuth?.destroy();
|