@ragable/sdk 0.6.15 → 0.6.16
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 +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +97 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -927,6 +927,48 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
927
927
|
truncated: boolean;
|
|
928
928
|
rows: Row[];
|
|
929
929
|
}
|
|
930
|
+
interface BrowserCollectionRecord<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
931
|
+
id: string;
|
|
932
|
+
data: Row;
|
|
933
|
+
createdAt: string;
|
|
934
|
+
updatedAt: string;
|
|
935
|
+
}
|
|
936
|
+
interface BrowserCollectionDefinition {
|
|
937
|
+
id: string;
|
|
938
|
+
name: string;
|
|
939
|
+
schema: Record<string, unknown> | null;
|
|
940
|
+
createdAt: string;
|
|
941
|
+
updatedAt: string;
|
|
942
|
+
}
|
|
943
|
+
interface BrowserCollectionFindParams {
|
|
944
|
+
where?: Record<string, unknown>;
|
|
945
|
+
filters?: Array<{
|
|
946
|
+
field: string;
|
|
947
|
+
op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
|
|
948
|
+
value: unknown;
|
|
949
|
+
}>;
|
|
950
|
+
limit?: number;
|
|
951
|
+
offset?: number;
|
|
952
|
+
orderBy?: string;
|
|
953
|
+
orderDirection?: "asc" | "desc";
|
|
954
|
+
}
|
|
955
|
+
declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
956
|
+
private readonly database;
|
|
957
|
+
private readonly name;
|
|
958
|
+
private readonly databaseInstanceId?;
|
|
959
|
+
constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
|
|
960
|
+
find: (whereOrParams?: Record<string, unknown> | BrowserCollectionFindParams) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
|
|
961
|
+
insert: (data: Row) => Promise<PostgrestResult<BrowserCollectionRecord<Row>>>;
|
|
962
|
+
update: (where: Record<string, unknown>, patch: Partial<Row>, options?: {
|
|
963
|
+
limit?: number;
|
|
964
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
|
|
965
|
+
delete: (where: Record<string, unknown>, options?: {
|
|
966
|
+
limit?: number;
|
|
967
|
+
}) => Promise<PostgrestResult<{
|
|
968
|
+
deleted: number;
|
|
969
|
+
records: BrowserCollectionRecord<Row>[];
|
|
970
|
+
}>>;
|
|
971
|
+
}
|
|
930
972
|
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
931
973
|
private readonly options;
|
|
932
974
|
private readonly ragableAuth;
|
|
@@ -941,6 +983,10 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
|
|
|
941
983
|
*/
|
|
942
984
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
943
985
|
private toUrl;
|
|
986
|
+
collection: <Row extends Record<string, unknown> = Record<string, unknown>>(name: string, databaseInstanceId?: string) => BrowserCollectionApi<Row>;
|
|
987
|
+
defineCollection: (name: string, schema?: Record<string, unknown>, databaseInstanceId?: string) => Promise<PostgrestResult<BrowserCollectionDefinition>>;
|
|
988
|
+
listCollections: (databaseInstanceId?: string) => Promise<PostgrestResult<BrowserCollectionDefinition[]>>;
|
|
989
|
+
_requestCollection<T>(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, databaseInstanceId?: string): Promise<T>;
|
|
944
990
|
query: <Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams) => Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
|
|
945
991
|
private baseHeaders;
|
|
946
992
|
/**
|
|
@@ -1043,6 +1089,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
1043
1089
|
readonly agents: RagableBrowserAgentsClient;
|
|
1044
1090
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
1045
1091
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
1092
|
+
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
1046
1093
|
readonly transport: Transport;
|
|
1047
1094
|
private readonly _ragableAuth;
|
|
1048
1095
|
constructor(options: RagableBrowserClientOptions);
|
package/dist/index.d.ts
CHANGED
|
@@ -927,6 +927,48 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
927
927
|
truncated: boolean;
|
|
928
928
|
rows: Row[];
|
|
929
929
|
}
|
|
930
|
+
interface BrowserCollectionRecord<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
931
|
+
id: string;
|
|
932
|
+
data: Row;
|
|
933
|
+
createdAt: string;
|
|
934
|
+
updatedAt: string;
|
|
935
|
+
}
|
|
936
|
+
interface BrowserCollectionDefinition {
|
|
937
|
+
id: string;
|
|
938
|
+
name: string;
|
|
939
|
+
schema: Record<string, unknown> | null;
|
|
940
|
+
createdAt: string;
|
|
941
|
+
updatedAt: string;
|
|
942
|
+
}
|
|
943
|
+
interface BrowserCollectionFindParams {
|
|
944
|
+
where?: Record<string, unknown>;
|
|
945
|
+
filters?: Array<{
|
|
946
|
+
field: string;
|
|
947
|
+
op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
|
|
948
|
+
value: unknown;
|
|
949
|
+
}>;
|
|
950
|
+
limit?: number;
|
|
951
|
+
offset?: number;
|
|
952
|
+
orderBy?: string;
|
|
953
|
+
orderDirection?: "asc" | "desc";
|
|
954
|
+
}
|
|
955
|
+
declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
956
|
+
private readonly database;
|
|
957
|
+
private readonly name;
|
|
958
|
+
private readonly databaseInstanceId?;
|
|
959
|
+
constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
|
|
960
|
+
find: (whereOrParams?: Record<string, unknown> | BrowserCollectionFindParams) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
|
|
961
|
+
insert: (data: Row) => Promise<PostgrestResult<BrowserCollectionRecord<Row>>>;
|
|
962
|
+
update: (where: Record<string, unknown>, patch: Partial<Row>, options?: {
|
|
963
|
+
limit?: number;
|
|
964
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
|
|
965
|
+
delete: (where: Record<string, unknown>, options?: {
|
|
966
|
+
limit?: number;
|
|
967
|
+
}) => Promise<PostgrestResult<{
|
|
968
|
+
deleted: number;
|
|
969
|
+
records: BrowserCollectionRecord<Row>[];
|
|
970
|
+
}>>;
|
|
971
|
+
}
|
|
930
972
|
declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
|
|
931
973
|
private readonly options;
|
|
932
974
|
private readonly ragableAuth;
|
|
@@ -941,6 +983,10 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
|
|
|
941
983
|
*/
|
|
942
984
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
943
985
|
private toUrl;
|
|
986
|
+
collection: <Row extends Record<string, unknown> = Record<string, unknown>>(name: string, databaseInstanceId?: string) => BrowserCollectionApi<Row>;
|
|
987
|
+
defineCollection: (name: string, schema?: Record<string, unknown>, databaseInstanceId?: string) => Promise<PostgrestResult<BrowserCollectionDefinition>>;
|
|
988
|
+
listCollections: (databaseInstanceId?: string) => Promise<PostgrestResult<BrowserCollectionDefinition[]>>;
|
|
989
|
+
_requestCollection<T>(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, databaseInstanceId?: string): Promise<T>;
|
|
944
990
|
query: <Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams) => Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
|
|
945
991
|
private baseHeaders;
|
|
946
992
|
/**
|
|
@@ -1043,6 +1089,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
1043
1089
|
readonly agents: RagableBrowserAgentsClient;
|
|
1044
1090
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
1045
1091
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
1092
|
+
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
1046
1093
|
readonly transport: Transport;
|
|
1047
1094
|
private readonly _ragableAuth;
|
|
1048
1095
|
constructor(options: RagableBrowserClientOptions);
|
package/dist/index.js
CHANGED
|
@@ -2270,6 +2270,51 @@ var RagableBrowserAuthClient = class {
|
|
|
2270
2270
|
return this.auth.getSession();
|
|
2271
2271
|
}
|
|
2272
2272
|
};
|
|
2273
|
+
var BrowserCollectionApi = class {
|
|
2274
|
+
constructor(database, name, databaseInstanceId) {
|
|
2275
|
+
this.database = database;
|
|
2276
|
+
this.name = name;
|
|
2277
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
2278
|
+
__publicField(this, "find", (whereOrParams = {}) => {
|
|
2279
|
+
const hasQueryKeys = ["where", "filters", "limit", "offset", "orderBy", "orderDirection"].some(
|
|
2280
|
+
(key) => Object.prototype.hasOwnProperty.call(whereOrParams, key)
|
|
2281
|
+
);
|
|
2282
|
+
const body = hasQueryKeys ? whereOrParams : { where: whereOrParams };
|
|
2283
|
+
return asPostgrestResponse(
|
|
2284
|
+
() => this.database._requestCollection(
|
|
2285
|
+
"POST",
|
|
2286
|
+
`/${encodeURIComponent(this.name)}/find`,
|
|
2287
|
+
body,
|
|
2288
|
+
this.databaseInstanceId
|
|
2289
|
+
)
|
|
2290
|
+
);
|
|
2291
|
+
});
|
|
2292
|
+
__publicField(this, "insert", (data) => asPostgrestResponse(
|
|
2293
|
+
() => this.database._requestCollection(
|
|
2294
|
+
"POST",
|
|
2295
|
+
`/${encodeURIComponent(this.name)}/records`,
|
|
2296
|
+
{ data },
|
|
2297
|
+
this.databaseInstanceId
|
|
2298
|
+
)
|
|
2299
|
+
));
|
|
2300
|
+
__publicField(this, "update", (where, patch, options) => asPostgrestResponse(
|
|
2301
|
+
() => this.database._requestCollection(
|
|
2302
|
+
"PATCH",
|
|
2303
|
+
`/${encodeURIComponent(this.name)}/records`,
|
|
2304
|
+
{ where, patch, ...options?.limit ? { limit: options.limit } : {} },
|
|
2305
|
+
this.databaseInstanceId
|
|
2306
|
+
)
|
|
2307
|
+
));
|
|
2308
|
+
__publicField(this, "delete", (where, options) => asPostgrestResponse(
|
|
2309
|
+
() => this.database._requestCollection(
|
|
2310
|
+
"DELETE",
|
|
2311
|
+
`/${encodeURIComponent(this.name)}/records`,
|
|
2312
|
+
{ where, ...options?.limit ? { limit: options.limit } : {} },
|
|
2313
|
+
this.databaseInstanceId
|
|
2314
|
+
)
|
|
2315
|
+
));
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2273
2318
|
var RagableBrowserDatabaseClient = class {
|
|
2274
2319
|
constructor(options, ragableAuth = null) {
|
|
2275
2320
|
this.options = options;
|
|
@@ -2329,6 +2374,25 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2329
2374
|
};
|
|
2330
2375
|
return new PostgrestTableApi(pgFetch, id, table);
|
|
2331
2376
|
});
|
|
2377
|
+
__publicField(this, "collection", (name, databaseInstanceId) => {
|
|
2378
|
+
return new BrowserCollectionApi(this, name, databaseInstanceId);
|
|
2379
|
+
});
|
|
2380
|
+
__publicField(this, "defineCollection", (name, schema, databaseInstanceId) => asPostgrestResponse(
|
|
2381
|
+
() => this._requestCollection(
|
|
2382
|
+
"POST",
|
|
2383
|
+
"/",
|
|
2384
|
+
{ name, ...schema ? { schema } : {} },
|
|
2385
|
+
databaseInstanceId
|
|
2386
|
+
)
|
|
2387
|
+
));
|
|
2388
|
+
__publicField(this, "listCollections", (databaseInstanceId) => asPostgrestResponse(
|
|
2389
|
+
() => this._requestCollection(
|
|
2390
|
+
"GET",
|
|
2391
|
+
"/",
|
|
2392
|
+
void 0,
|
|
2393
|
+
databaseInstanceId
|
|
2394
|
+
)
|
|
2395
|
+
));
|
|
2332
2396
|
__publicField(this, "query", async (params) => {
|
|
2333
2397
|
return asPostgrestResponse(async () => {
|
|
2334
2398
|
const gid = requireAuthGroupId(this.options);
|
|
@@ -2403,6 +2467,36 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2403
2467
|
toUrl(path) {
|
|
2404
2468
|
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2405
2469
|
}
|
|
2470
|
+
async _requestCollection(method, path, body, databaseInstanceId) {
|
|
2471
|
+
const gid = requireAuthGroupId(this.options);
|
|
2472
|
+
const token = await resolveDatabaseAuthBearer(this.options, this.ragableAuth);
|
|
2473
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2474
|
+
if (!id) {
|
|
2475
|
+
throw new RagableError(
|
|
2476
|
+
"db.collection() requires databaseInstanceId in client options or as an argument",
|
|
2477
|
+
400,
|
|
2478
|
+
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
const headers = this.baseHeaders();
|
|
2482
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
2483
|
+
headers.set("X-Database-Instance-Id", id);
|
|
2484
|
+
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
2485
|
+
const response = await this.fetchImpl(
|
|
2486
|
+
this.toUrl(`/auth-groups/${gid}/data/collections${path}`),
|
|
2487
|
+
{
|
|
2488
|
+
method,
|
|
2489
|
+
headers,
|
|
2490
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
2491
|
+
}
|
|
2492
|
+
);
|
|
2493
|
+
const payload = await parseMaybeJsonBody(response);
|
|
2494
|
+
if (!response.ok) {
|
|
2495
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
2496
|
+
throw new RagableError(message, response.status, payload);
|
|
2497
|
+
}
|
|
2498
|
+
return payload;
|
|
2499
|
+
}
|
|
2406
2500
|
baseHeaders() {
|
|
2407
2501
|
return new Headers(this.options.headers);
|
|
2408
2502
|
}
|
|
@@ -2635,6 +2729,7 @@ var RagableBrowser = class {
|
|
|
2635
2729
|
__publicField(this, "agents");
|
|
2636
2730
|
__publicField(this, "auth");
|
|
2637
2731
|
__publicField(this, "database");
|
|
2732
|
+
__publicField(this, "db");
|
|
2638
2733
|
__publicField(this, "transport");
|
|
2639
2734
|
__publicField(this, "_ragableAuth");
|
|
2640
2735
|
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
@@ -2674,6 +2769,7 @@ var RagableBrowser = class {
|
|
|
2674
2769
|
this._ragableAuth
|
|
2675
2770
|
);
|
|
2676
2771
|
this.database._setTransport(this.transport);
|
|
2772
|
+
this.db = this.database;
|
|
2677
2773
|
}
|
|
2678
2774
|
destroy() {
|
|
2679
2775
|
this._ragableAuth?.destroy();
|
|
@@ -2747,7 +2843,7 @@ function createClient(options) {
|
|
|
2747
2843
|
if (isServerClientOptions(options)) {
|
|
2748
2844
|
if (typeof options === "object" && options !== null && "organizationId" in options && typeof options.organizationId === "string") {
|
|
2749
2845
|
console.warn(
|
|
2750
|
-
"[@ragable/sdk] createClient: `apiKey` is set, so the server client is returned. It has no `database` or `auth` \u2014 only `agents` and `shift`. For `database.from()` / `auth.*`, use the browser client without `apiKey` (e.g. createClient({ organizationId, authGroupId, databaseInstanceId, ... }))."
|
|
2846
|
+
"[@ragable/sdk] createClient: `apiKey` is set, so the server client is returned. It has no `database` or `auth` \u2014 only `agents` and `shift`. For `db.collection()` / `database.from()` / `auth.*`, use the browser client without `apiKey` (e.g. createClient({ organizationId, authGroupId, databaseInstanceId, ... }))."
|
|
2751
2847
|
);
|
|
2752
2848
|
}
|
|
2753
2849
|
return new Ragable(options);
|