@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.mjs CHANGED
@@ -2190,103 +2190,107 @@ var RagableBrowserDatabaseClient = class {
2190
2190
  this.ragableAuth = ragableAuth;
2191
2191
  __publicField(this, "fetchImpl");
2192
2192
  __publicField(this, "_transport", null);
2193
- this.fetchImpl = bindFetch(options.fetch);
2194
- }
2195
- /** @internal Called by RagableBrowser to share the Transport instance. */
2196
- _setTransport(transport) {
2197
- this._transport = transport;
2198
- }
2199
- from(table, databaseInstanceId) {
2200
- const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim() || "";
2201
- const ragableAuth = this.ragableAuth;
2202
- const opts = this.options;
2203
- const transport = this._transport;
2204
- const fetchImpl = this.fetchImpl;
2205
- const pgFetch = async (params) => {
2206
- if (!params.databaseInstanceId?.trim()) {
2207
- throw new RagableError(
2208
- "database.from() requires databaseInstanceId in client options or as the second argument",
2209
- 400,
2210
- { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2211
- );
2212
- }
2213
- const gid = requireAuthGroupId(opts);
2214
- const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2215
- const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
2216
- const qs = params.searchParams.toString();
2217
- const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2218
- const headers = new Headers(opts.headers);
2219
- headers.set("Authorization", `Bearer ${token}`);
2220
- headers.set("X-Database-Instance-Id", params.databaseInstanceId);
2221
- if (params.body !== void 0) {
2222
- headers.set("Content-Type", "application/json");
2223
- }
2224
- if (params.headers) {
2225
- for (const [k, v] of Object.entries(params.headers)) {
2226
- headers.set(k, v);
2193
+ /**
2194
+ * PostgREST table access. Instance field so `client.database.from` is always an own,
2195
+ * enumerable function (avoids rare prototype/bundler issues).
2196
+ */
2197
+ __publicField(this, "from", (table, databaseInstanceId) => {
2198
+ const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim() || "";
2199
+ const ragableAuth = this.ragableAuth;
2200
+ const opts = this.options;
2201
+ const transport = this._transport;
2202
+ const fetchImpl = this.fetchImpl;
2203
+ const pgFetch = async (params) => {
2204
+ if (!params.databaseInstanceId?.trim()) {
2205
+ throw new RagableError(
2206
+ "database.from() requires databaseInstanceId in client options or as the second argument",
2207
+ 400,
2208
+ { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2209
+ );
2227
2210
  }
2228
- }
2229
- if (transport) {
2230
- return transport.execute({
2231
- url,
2211
+ const gid = requireAuthGroupId(opts);
2212
+ const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2213
+ const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
2214
+ const qs = params.searchParams.toString();
2215
+ const url = `${baseUrl}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2216
+ const headers = new Headers(opts.headers);
2217
+ headers.set("Authorization", `Bearer ${token}`);
2218
+ headers.set("X-Database-Instance-Id", params.databaseInstanceId);
2219
+ if (params.body !== void 0) {
2220
+ headers.set("Content-Type", "application/json");
2221
+ }
2222
+ if (params.headers) {
2223
+ for (const [k, v] of Object.entries(params.headers)) {
2224
+ headers.set(k, v);
2225
+ }
2226
+ }
2227
+ if (transport) {
2228
+ return transport.execute({
2229
+ url,
2230
+ method: params.method,
2231
+ headers,
2232
+ body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2233
+ signal: params.signal,
2234
+ idempotencyKey: params.idempotencyKey
2235
+ });
2236
+ }
2237
+ return fetchImpl(url, {
2232
2238
  method: params.method,
2233
2239
  headers,
2234
2240
  body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2235
- signal: params.signal,
2236
- idempotencyKey: params.idempotencyKey
2241
+ signal: params.signal
2237
2242
  });
2238
- }
2239
- return fetchImpl(url, {
2240
- method: params.method,
2241
- headers,
2242
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
2243
- signal: params.signal
2243
+ };
2244
+ return new PostgrestTableApi(pgFetch, id, table);
2245
+ });
2246
+ __publicField(this, "query", async (params) => {
2247
+ return asPostgrestResponse(async () => {
2248
+ const gid = requireAuthGroupId(this.options);
2249
+ const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
2250
+ const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2251
+ if (!databaseInstanceId) {
2252
+ throw new RagableError(
2253
+ "database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
2254
+ 400,
2255
+ { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2256
+ );
2257
+ }
2258
+ const headers = this.baseHeaders();
2259
+ headers.set("Authorization", `Bearer ${token}`);
2260
+ headers.set("Content-Type", "application/json");
2261
+ const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
2262
+ const response = await this.fetchImpl(
2263
+ this.toUrl(`/auth-groups/${gid}/data/query`),
2264
+ {
2265
+ method: "POST",
2266
+ headers,
2267
+ body: JSON.stringify({
2268
+ databaseInstanceId,
2269
+ sql: params.sql,
2270
+ ...params.params !== void 0 ? { params: params.params } : {},
2271
+ readOnly,
2272
+ ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
2273
+ ...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
2274
+ })
2275
+ }
2276
+ );
2277
+ const payload = await parseMaybeJsonBody(response);
2278
+ if (!response.ok) {
2279
+ const message = extractErrorMessage(payload, response.statusText);
2280
+ throw new RagableError(message, response.status, payload);
2281
+ }
2282
+ return payload;
2244
2283
  });
2245
- };
2246
- return new PostgrestTableApi(pgFetch, id, table);
2284
+ });
2285
+ this.fetchImpl = bindFetch(options.fetch);
2286
+ }
2287
+ /** @internal Called by RagableBrowser to share the Transport instance. */
2288
+ _setTransport(transport) {
2289
+ this._transport = transport;
2247
2290
  }
2248
2291
  toUrl(path) {
2249
2292
  return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
2250
2293
  }
2251
- async query(params) {
2252
- return asPostgrestResponse(async () => {
2253
- const gid = requireAuthGroupId(this.options);
2254
- const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
2255
- const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
2256
- if (!databaseInstanceId) {
2257
- throw new RagableError(
2258
- "database.query requires databaseInstanceId in the request or on createBrowserClient({ databaseInstanceId })",
2259
- 400,
2260
- { code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
2261
- );
2262
- }
2263
- const headers = this.baseHeaders();
2264
- headers.set("Authorization", `Bearer ${token}`);
2265
- headers.set("Content-Type", "application/json");
2266
- const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
2267
- const response = await this.fetchImpl(
2268
- this.toUrl(`/auth-groups/${gid}/data/query`),
2269
- {
2270
- method: "POST",
2271
- headers,
2272
- body: JSON.stringify({
2273
- databaseInstanceId,
2274
- sql: params.sql,
2275
- ...params.params !== void 0 ? { params: params.params } : {},
2276
- readOnly,
2277
- ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
2278
- ...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
2279
- })
2280
- }
2281
- );
2282
- const payload = await parseMaybeJsonBody(response);
2283
- if (!response.ok) {
2284
- const message = extractErrorMessage(payload, response.statusText);
2285
- throw new RagableError(message, response.status, payload);
2286
- }
2287
- return payload;
2288
- });
2289
- }
2290
2294
  baseHeaders() {
2291
2295
  return new Headers(this.options.headers);
2292
2296
  }
@@ -2337,6 +2341,10 @@ var RagableBrowser = class {
2337
2341
  __publicField(this, "database");
2338
2342
  __publicField(this, "transport");
2339
2343
  __publicField(this, "_ragableAuth");
2344
+ /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
2345
+ __publicField(this, "from", (table, databaseInstanceId) => {
2346
+ return this.database.from(table, databaseInstanceId);
2347
+ });
2340
2348
  this.transport = new Transport({
2341
2349
  fetch: options.fetch,
2342
2350
  headers: options.headers,
@@ -2371,10 +2379,6 @@ var RagableBrowser = class {
2371
2379
  );
2372
2380
  this.database._setTransport(this.transport);
2373
2381
  }
2374
- /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
2375
- from(table, databaseInstanceId) {
2376
- return this.database.from(table, databaseInstanceId);
2377
- }
2378
2382
  destroy() {
2379
2383
  this._ragableAuth?.destroy();
2380
2384
  }