@ragable/sdk 0.6.5 → 0.6.6
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 +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +179 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -359,6 +359,24 @@ declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Recor
|
|
|
359
359
|
single(): Promise<PostgrestResult<Row>>;
|
|
360
360
|
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
361
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Awaitable `{ data: null, error }` chain when `.insert()` is called with invalid extra
|
|
364
|
+
* arguments — matches Supabase-style result shapes without throwing.
|
|
365
|
+
*/
|
|
366
|
+
declare class PostgrestInsertSdkErrorRoot<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
|
|
367
|
+
private readonly error;
|
|
368
|
+
constructor(error: RagableError);
|
|
369
|
+
select(_columns?: string): PostgrestInsertSdkErrorReturning<Row>;
|
|
370
|
+
abortSignal(_signal: AbortSignal): this;
|
|
371
|
+
then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
372
|
+
}
|
|
373
|
+
declare class PostgrestInsertSdkErrorReturning<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
374
|
+
private readonly error;
|
|
375
|
+
constructor(error: RagableError);
|
|
376
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
377
|
+
single(): Promise<PostgrestResult<Row>>;
|
|
378
|
+
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
379
|
+
}
|
|
362
380
|
declare class PostgrestInsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
|
|
363
381
|
private readonly pgFetch;
|
|
364
382
|
private readonly databaseInstanceId;
|
|
@@ -882,7 +900,7 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
|
|
|
882
900
|
_setTransport(transport: Transport): void;
|
|
883
901
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
884
902
|
private toUrl;
|
|
885
|
-
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row
|
|
903
|
+
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
|
|
886
904
|
private baseHeaders;
|
|
887
905
|
}
|
|
888
906
|
declare class RagableBrowserAgentsClient {
|
|
@@ -986,4 +1004,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
986
1004
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
987
1005
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
988
1006
|
|
|
989
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1007
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
package/dist/index.d.ts
CHANGED
|
@@ -359,6 +359,24 @@ declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Recor
|
|
|
359
359
|
single(): Promise<PostgrestResult<Row>>;
|
|
360
360
|
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
361
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Awaitable `{ data: null, error }` chain when `.insert()` is called with invalid extra
|
|
364
|
+
* arguments — matches Supabase-style result shapes without throwing.
|
|
365
|
+
*/
|
|
366
|
+
declare class PostgrestInsertSdkErrorRoot<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
|
|
367
|
+
private readonly error;
|
|
368
|
+
constructor(error: RagableError);
|
|
369
|
+
select(_columns?: string): PostgrestInsertSdkErrorReturning<Row>;
|
|
370
|
+
abortSignal(_signal: AbortSignal): this;
|
|
371
|
+
then<TResult1 = PostgrestResult<null>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<null>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
372
|
+
}
|
|
373
|
+
declare class PostgrestInsertSdkErrorReturning<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
374
|
+
private readonly error;
|
|
375
|
+
constructor(error: RagableError);
|
|
376
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
377
|
+
single(): Promise<PostgrestResult<Row>>;
|
|
378
|
+
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
379
|
+
}
|
|
362
380
|
declare class PostgrestInsertRootBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<null>> {
|
|
363
381
|
private readonly pgFetch;
|
|
364
382
|
private readonly databaseInstanceId;
|
|
@@ -882,7 +900,7 @@ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = De
|
|
|
882
900
|
_setTransport(transport: Transport): void;
|
|
883
901
|
from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
|
|
884
902
|
private toUrl;
|
|
885
|
-
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row
|
|
903
|
+
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<PostgrestResult<BrowserSqlQueryResult<Row>>>;
|
|
886
904
|
private baseHeaders;
|
|
887
905
|
}
|
|
888
906
|
declare class RagableBrowserAgentsClient {
|
|
@@ -986,4 +1004,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
986
1004
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
987
1005
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
988
1006
|
|
|
989
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1007
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
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;
|
|
@@ -2241,20 +2270,20 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2241
2270
|
this._transport = transport;
|
|
2242
2271
|
}
|
|
2243
2272
|
from(table, databaseInstanceId) {
|
|
2244
|
-
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
2245
|
-
if (!id) {
|
|
2246
|
-
throw new RagableError(
|
|
2247
|
-
"database.from() requires databaseInstanceId in client options or as the second argument",
|
|
2248
|
-
400,
|
|
2249
|
-
{ code: "SDK_MISSING_DATABASE_INSTANCE_ID" }
|
|
2250
|
-
);
|
|
2251
|
-
}
|
|
2252
|
-
const gid = requireAuthGroupId(this.options);
|
|
2273
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim() || "";
|
|
2253
2274
|
const ragableAuth = this.ragableAuth;
|
|
2254
2275
|
const opts = this.options;
|
|
2255
2276
|
const transport = this._transport;
|
|
2256
2277
|
const fetchImpl = this.fetchImpl;
|
|
2257
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);
|
|
2258
2287
|
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2259
2288
|
const baseUrl = normalizeBrowserApiBase(opts.baseUrl);
|
|
2260
2289
|
const qs = params.searchParams.toString();
|
|
@@ -2293,36 +2322,43 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2293
2322
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2294
2323
|
}
|
|
2295
2324
|
async query(params) {
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
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
|
+
}
|
|
2304
2354
|
);
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
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
|
-
})
|
|
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);
|
|
2323
2359
|
}
|
|
2324
|
-
|
|
2325
|
-
|
|
2360
|
+
return payload;
|
|
2361
|
+
});
|
|
2326
2362
|
}
|
|
2327
2363
|
baseHeaders() {
|
|
2328
2364
|
return new Headers(this.options.headers);
|
|
@@ -2521,6 +2557,8 @@ function createRagableServerClient(options) {
|
|
|
2521
2557
|
PostgrestDeleteRootBuilder,
|
|
2522
2558
|
PostgrestInsertReturningBuilder,
|
|
2523
2559
|
PostgrestInsertRootBuilder,
|
|
2560
|
+
PostgrestInsertSdkErrorReturning,
|
|
2561
|
+
PostgrestInsertSdkErrorRoot,
|
|
2524
2562
|
PostgrestSelectBuilder,
|
|
2525
2563
|
PostgrestTableApi,
|
|
2526
2564
|
PostgrestUpdateReturningBuilder,
|