@ragable/sdk 0.6.6 → 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 CHANGED
@@ -898,9 +898,13 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
898
898
  constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
899
899
  /** @internal Called by RagableBrowser to share the Transport instance. */
900
900
  _setTransport(transport: Transport): void;
901
- from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
901
+ /**
902
+ * PostgREST table access. Instance field so `client.database.from` is always an own,
903
+ * enumerable function (avoids rare prototype/bundler issues).
904
+ */
905
+ from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
902
906
  private toUrl;
903
- query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
907
+ query: <Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams) => Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
904
908
  private baseHeaders;
905
909
  }
906
910
  declare class RagableBrowserAgentsClient {
@@ -922,7 +926,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
922
926
  private readonly _ragableAuth;
923
927
  constructor(options: RagableBrowserClientOptions);
924
928
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
925
- from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
929
+ from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
926
930
  destroy(): void;
927
931
  }
928
932
  declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
package/dist/index.d.ts CHANGED
@@ -898,9 +898,13 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
898
898
  constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
899
899
  /** @internal Called by RagableBrowser to share the Transport instance. */
900
900
  _setTransport(transport: Transport): void;
901
- from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
901
+ /**
902
+ * PostgREST table access. Instance field so `client.database.from` is always an own,
903
+ * enumerable function (avoids rare prototype/bundler issues).
904
+ */
905
+ from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
902
906
  private toUrl;
903
- query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
907
+ query: <Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams) => Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
904
908
  private baseHeaders;
905
909
  }
906
910
  declare class RagableBrowserAgentsClient {
@@ -922,7 +926,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
922
926
  private readonly _ragableAuth;
923
927
  constructor(options: RagableBrowserClientOptions);
924
928
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
925
- from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
929
+ from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
926
930
  destroy(): void;
927
931
  }
928
932
  declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
package/dist/index.js CHANGED
@@ -2263,103 +2263,107 @@ var RagableBrowserDatabaseClient = class {
2263
2263
  this.ragableAuth = ragableAuth;
2264
2264
  __publicField(this, "fetchImpl");
2265
2265
  __publicField(this, "_transport", null);
2266
- this.fetchImpl = bindFetch(options.fetch);
2267
- }
2268
- /** @internal Called by RagableBrowser to share the Transport instance. */
2269
- _setTransport(transport) {
2270
- this._transport = transport;
2271
- }
2272
- from(table, databaseInstanceId) {
2273
- const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim() || "";
2274
- const ragableAuth = this.ragableAuth;
2275
- const opts = this.options;
2276
- const transport = this._transport;
2277
- const fetchImpl = this.fetchImpl;
2278
- const pgFetch = async (params) => {
2279
- if (!params.databaseInstanceId?.trim()) {
2280
- throw new RagableError(
2281
- "database.from() requires databaseInstanceId in client options or as the second argument",
2282
- 400,
2283
- { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2284
- );
2285
- }
2286
- const gid = requireAuthGroupId(opts);
2287
- const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2288
- const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
2289
- const qs = params.searchParams.toString();
2290
- const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2291
- const headers = new Headers(opts.headers);
2292
- headers.set("Authorization", `Bearer ${token}`);
2293
- headers.set("X-Database-Instance-Id", params.databaseInstanceId);
2294
- if (params.body !== void 0) {
2295
- headers.set("Content-Type", "application/json");
2296
- }
2297
- if (params.headers) {
2298
- for (const [k, v] of Object.entries(params.headers)) {
2299
- 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
+ );
2300
2283
  }
2301
- }
2302
- if (transport) {
2303
- return transport.execute({
2304
- url,
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, {
2305
2311
  method: params.method,
2306
2312
  headers,
2307
2313
  body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2308
- signal: params.signal,
2309
- idempotencyKey: params.idempotencyKey
2314
+ signal: params.signal
2310
2315
  });
2311
- }
2312
- return fetchImpl(url, {
2313
- method: params.method,
2314
- headers,
2315
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2316
- signal: params.signal
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;
2317
2356
  });
2318
- };
2319
- return new PostgrestTableApi(pgFetch, id, table);
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;
2320
2363
  }
2321
2364
  toUrl(path) {
2322
2365
  return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
2323
2366
  }
2324
- async query(params) {
2325
- return asPostgrestResponse(async () => {
2326
- const gid = requireAuthGroupId(this.options);
2327
- const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
2328
- const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2329
- if (!databaseInstanceId) {
2330
- throw new RagableError(
2331
- "database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
2332
- 400,
2333
- { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2334
- );
2335
- }
2336
- const headers = this.baseHeaders();
2337
- headers.set("Authorization", `Bearer ${token}`);
2338
- headers.set("Content-Type", "application/json");
2339
- const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
2340
- const response = await this.fetchImpl(
2341
- this.toUrl(`/auth-groups/${gid}/data/query`),
2342
- {
2343
- method: "POST",
2344
- headers,
2345
- body: JSON.stringify({
2346
- databaseInstanceId,
2347
- sql: params.sql,
2348
- ...params.params !== void 0 ? { params: params.params } : {},
2349
- readOnly,
2350
- ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
2351
- ...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
2352
- })
2353
- }
2354
- );
2355
- const payload = await parseMaybeJsonBody(response);
2356
- if (!response.ok) {
2357
- const message = extractErrorMessage(payload, response.statusText);
2358
- throw new RagableError(message, response.status, payload);
2359
- }
2360
- return payload;
2361
- });
2362
- }
2363
2367
  baseHeaders() {
2364
2368
  return new Headers(this.options.headers);
2365
2369
  }
@@ -2410,6 +2414,10 @@ var RagableBrowser = class {
2410
2414
  __publicField(this, "database");
2411
2415
  __publicField(this, "transport");
2412
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
+ });
2413
2421
  this.transport = new Transport({
2414
2422
  fetch: options.fetch,
2415
2423
  headers: options.headers,
@@ -2444,10 +2452,6 @@ var RagableBrowser = class {
2444
2452
  );
2445
2453
  this.database._setTransport(this.transport);
2446
2454
  }
2447
- /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
2448
- from(table, databaseInstanceId) {
2449
- return this.database.from(table, databaseInstanceId);
2450
- }
2451
2455
  destroy() {
2452
2456
  this._ragableAuth?.destroy();
2453
2457
  }