@ragable/sdk 0.8.3 → 0.9.0
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 +7 -43
- package/dist/index.d.ts +7 -43
- package/dist/index.js +3 -178
- package/dist/index.mjs +3 -177
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -689,34 +689,6 @@ interface RecordEnvelope {
|
|
|
689
689
|
createdAt: string;
|
|
690
690
|
updatedAt: string;
|
|
691
691
|
}
|
|
692
|
-
interface CollectionSelectedEmbed {
|
|
693
|
-
/** Row key the embedded value lands under (defaults to the collection name). */
|
|
694
|
-
alias: string;
|
|
695
|
-
collection: string;
|
|
696
|
-
/** Linking field (`!hint`); when omitted the server infers it from schemas/conventions. */
|
|
697
|
-
hint?: string;
|
|
698
|
-
/** Projection of the embedded rows' fields (null = all). */
|
|
699
|
-
columns: string[] | null;
|
|
700
|
-
}
|
|
701
|
-
interface CollectionSelectedAggregate {
|
|
702
|
-
fn: "count" | "sum" | "avg" | "min" | "max";
|
|
703
|
-
field?: string;
|
|
704
|
-
alias: string;
|
|
705
|
-
}
|
|
706
|
-
interface ParsedSelectExpression {
|
|
707
|
-
/** Plain fields (group keys when aggregates are present); null = `*`. */
|
|
708
|
-
fields: string[] | null;
|
|
709
|
-
embeds: CollectionSelectedEmbed[];
|
|
710
|
-
aggregates: CollectionSelectedAggregate[];
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Parse a `select()` string into plain columns, relation embeds, and
|
|
714
|
-
* aggregates (Supabase grammar):
|
|
715
|
-
*
|
|
716
|
-
* - `"*, author:users!author_id(name,avatar_url), comments(*)"` — embeds
|
|
717
|
-
* - `"category, count(), total:amount.sum()"` — aggregation grouped by `category`
|
|
718
|
-
*/
|
|
719
|
-
declare function parseSelectExpression(columns: string | undefined): ParsedSelectExpression;
|
|
720
692
|
/**
|
|
721
693
|
* Transport bound to one collection: `path` is relative to the collection
|
|
722
694
|
* (e.g. `"/find"`, `"/records"`). Implemented by the database client.
|
|
@@ -808,12 +780,12 @@ type CollectionListResult<T> = {
|
|
|
808
780
|
error: RagableError;
|
|
809
781
|
count: null;
|
|
810
782
|
};
|
|
811
|
-
declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown
|
|
783
|
+
declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown>> extends CollectionConditionBuilder<Row> implements PromiseLike<CollectionListResult<CollectionRow<Row>>> {
|
|
812
784
|
private readonly request;
|
|
813
785
|
private _limit?;
|
|
814
786
|
private _offset?;
|
|
815
787
|
private _order;
|
|
816
|
-
private readonly
|
|
788
|
+
private readonly columns;
|
|
817
789
|
private readonly wantCount;
|
|
818
790
|
private readonly headOnly;
|
|
819
791
|
constructor(request: CollectionRequestFn, columns?: string, options?: CollectionSelectOptions);
|
|
@@ -825,17 +797,15 @@ declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Reco
|
|
|
825
797
|
offset(n: number): this;
|
|
826
798
|
/** Rows `from`..`to` inclusive (zero-based), like Supabase `.range()`. */
|
|
827
799
|
range(from: number, to: number): this;
|
|
828
|
-
then<TResult1 = CollectionListResult<
|
|
800
|
+
then<TResult1 = CollectionListResult<CollectionRow<Row>>, TResult2 = never>(onfulfilled?: ((value: CollectionListResult<CollectionRow<Row>>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
829
801
|
/**
|
|
830
802
|
* Exactly one row. 0 or >1 matching rows is an error (code PGRST116),
|
|
831
803
|
* mirroring Supabase `.single()`.
|
|
832
804
|
*/
|
|
833
|
-
single(): Promise<PostgrestResult<
|
|
805
|
+
single(): Promise<PostgrestResult<CollectionRow<Row>>>;
|
|
834
806
|
/** One row or `null` — only >1 matching rows is an error. */
|
|
835
|
-
maybeSingle(): Promise<PostgrestResult<
|
|
807
|
+
maybeSingle(): Promise<PostgrestResult<CollectionRow<Row> | null>>;
|
|
836
808
|
private buildBody;
|
|
837
|
-
/** Flatten the envelope and apply column + embedded-column projection. */
|
|
838
|
-
private shapeRow;
|
|
839
809
|
private executeRows;
|
|
840
810
|
private execute;
|
|
841
811
|
}
|
|
@@ -2134,14 +2104,8 @@ declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<
|
|
|
2134
2104
|
* .order("createdAt", { ascending: false })
|
|
2135
2105
|
* .range(0, 19);
|
|
2136
2106
|
* ```
|
|
2137
|
-
*
|
|
2138
|
-
* Relation embeds (one level): `select("*, author:users!author_id(name), comments(*)")`
|
|
2139
|
-
* — to-one embeds become an object (or null), to-many an array. Aggregations:
|
|
2140
|
-
* `select("category, count(), total:amount.sum()")` groups by the plain
|
|
2141
|
-
* columns; pass a type argument for the result shape:
|
|
2142
|
-
* `select<{ category: string; count: number }>("category, count()")`.
|
|
2143
2107
|
*/
|
|
2144
|
-
select:
|
|
2108
|
+
select: (columns?: string, options?: CollectionSelectOptions) => CollectionSelectBuilder<RowD<Row>>;
|
|
2145
2109
|
/**
|
|
2146
2110
|
* Insert-or-update matched on `onConflict` (`"id"` by default, or any data
|
|
2147
2111
|
* field, e.g. `{ onConflict: "slug" }`). Chain `.select()` for the affected
|
|
@@ -2805,4 +2769,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
|
2805
2769
|
|
|
2806
2770
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2807
2771
|
|
|
2808
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthOtpType, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, CollectionDeleteBuilder, type CollectionField, type CollectionFilterOp, CollectionInsertChain, type CollectionListResult, CollectionMutationReturning, type CollectionRecordEnvelope, type CollectionRequestFn, type CollectionReturnMode, type CollectionRow, type CollectionRowData, type CollectionRowWithMeta, CollectionSelectBuilder, type CollectionSelectOptions,
|
|
2772
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthOtpType, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, CollectionDeleteBuilder, type CollectionField, type CollectionFilterOp, CollectionInsertChain, type CollectionListResult, CollectionMutationReturning, type CollectionRecordEnvelope, type CollectionRequestFn, type CollectionReturnMode, type CollectionRow, type CollectionRowData, type CollectionRowWithMeta, CollectionSelectBuilder, type CollectionSelectOptions, CollectionUpdateBuilder, CollectionUpsertBuilder, type CollectionUpsertOptions, type CollectionUpsertSummary, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, RagableServerClient, type RagableServerClientConfig, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type ServerPrivilege, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createServerClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseOrString, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -689,34 +689,6 @@ interface RecordEnvelope {
|
|
|
689
689
|
createdAt: string;
|
|
690
690
|
updatedAt: string;
|
|
691
691
|
}
|
|
692
|
-
interface CollectionSelectedEmbed {
|
|
693
|
-
/** Row key the embedded value lands under (defaults to the collection name). */
|
|
694
|
-
alias: string;
|
|
695
|
-
collection: string;
|
|
696
|
-
/** Linking field (`!hint`); when omitted the server infers it from schemas/conventions. */
|
|
697
|
-
hint?: string;
|
|
698
|
-
/** Projection of the embedded rows' fields (null = all). */
|
|
699
|
-
columns: string[] | null;
|
|
700
|
-
}
|
|
701
|
-
interface CollectionSelectedAggregate {
|
|
702
|
-
fn: "count" | "sum" | "avg" | "min" | "max";
|
|
703
|
-
field?: string;
|
|
704
|
-
alias: string;
|
|
705
|
-
}
|
|
706
|
-
interface ParsedSelectExpression {
|
|
707
|
-
/** Plain fields (group keys when aggregates are present); null = `*`. */
|
|
708
|
-
fields: string[] | null;
|
|
709
|
-
embeds: CollectionSelectedEmbed[];
|
|
710
|
-
aggregates: CollectionSelectedAggregate[];
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Parse a `select()` string into plain columns, relation embeds, and
|
|
714
|
-
* aggregates (Supabase grammar):
|
|
715
|
-
*
|
|
716
|
-
* - `"*, author:users!author_id(name,avatar_url), comments(*)"` — embeds
|
|
717
|
-
* - `"category, count(), total:amount.sum()"` — aggregation grouped by `category`
|
|
718
|
-
*/
|
|
719
|
-
declare function parseSelectExpression(columns: string | undefined): ParsedSelectExpression;
|
|
720
692
|
/**
|
|
721
693
|
* Transport bound to one collection: `path` is relative to the collection
|
|
722
694
|
* (e.g. `"/find"`, `"/records"`). Implemented by the database client.
|
|
@@ -808,12 +780,12 @@ type CollectionListResult<T> = {
|
|
|
808
780
|
error: RagableError;
|
|
809
781
|
count: null;
|
|
810
782
|
};
|
|
811
|
-
declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown
|
|
783
|
+
declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown>> extends CollectionConditionBuilder<Row> implements PromiseLike<CollectionListResult<CollectionRow<Row>>> {
|
|
812
784
|
private readonly request;
|
|
813
785
|
private _limit?;
|
|
814
786
|
private _offset?;
|
|
815
787
|
private _order;
|
|
816
|
-
private readonly
|
|
788
|
+
private readonly columns;
|
|
817
789
|
private readonly wantCount;
|
|
818
790
|
private readonly headOnly;
|
|
819
791
|
constructor(request: CollectionRequestFn, columns?: string, options?: CollectionSelectOptions);
|
|
@@ -825,17 +797,15 @@ declare class CollectionSelectBuilder<Row extends Record<string, unknown> = Reco
|
|
|
825
797
|
offset(n: number): this;
|
|
826
798
|
/** Rows `from`..`to` inclusive (zero-based), like Supabase `.range()`. */
|
|
827
799
|
range(from: number, to: number): this;
|
|
828
|
-
then<TResult1 = CollectionListResult<
|
|
800
|
+
then<TResult1 = CollectionListResult<CollectionRow<Row>>, TResult2 = never>(onfulfilled?: ((value: CollectionListResult<CollectionRow<Row>>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
829
801
|
/**
|
|
830
802
|
* Exactly one row. 0 or >1 matching rows is an error (code PGRST116),
|
|
831
803
|
* mirroring Supabase `.single()`.
|
|
832
804
|
*/
|
|
833
|
-
single(): Promise<PostgrestResult<
|
|
805
|
+
single(): Promise<PostgrestResult<CollectionRow<Row>>>;
|
|
834
806
|
/** One row or `null` — only >1 matching rows is an error. */
|
|
835
|
-
maybeSingle(): Promise<PostgrestResult<
|
|
807
|
+
maybeSingle(): Promise<PostgrestResult<CollectionRow<Row> | null>>;
|
|
836
808
|
private buildBody;
|
|
837
|
-
/** Flatten the envelope and apply column + embedded-column projection. */
|
|
838
|
-
private shapeRow;
|
|
839
809
|
private executeRows;
|
|
840
810
|
private execute;
|
|
841
811
|
}
|
|
@@ -2134,14 +2104,8 @@ declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<
|
|
|
2134
2104
|
* .order("createdAt", { ascending: false })
|
|
2135
2105
|
* .range(0, 19);
|
|
2136
2106
|
* ```
|
|
2137
|
-
*
|
|
2138
|
-
* Relation embeds (one level): `select("*, author:users!author_id(name), comments(*)")`
|
|
2139
|
-
* — to-one embeds become an object (or null), to-many an array. Aggregations:
|
|
2140
|
-
* `select("category, count(), total:amount.sum()")` groups by the plain
|
|
2141
|
-
* columns; pass a type argument for the result shape:
|
|
2142
|
-
* `select<{ category: string; count: number }>("category, count()")`.
|
|
2143
2107
|
*/
|
|
2144
|
-
select:
|
|
2108
|
+
select: (columns?: string, options?: CollectionSelectOptions) => CollectionSelectBuilder<RowD<Row>>;
|
|
2145
2109
|
/**
|
|
2146
2110
|
* Insert-or-update matched on `onConflict` (`"id"` by default, or any data
|
|
2147
2111
|
* field, e.g. `{ onConflict: "slug" }`). Chain `.select()` for the affected
|
|
@@ -2805,4 +2769,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
|
2805
2769
|
|
|
2806
2770
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2807
2771
|
|
|
2808
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthOtpType, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, CollectionDeleteBuilder, type CollectionField, type CollectionFilterOp, CollectionInsertChain, type CollectionListResult, CollectionMutationReturning, type CollectionRecordEnvelope, type CollectionRequestFn, type CollectionReturnMode, type CollectionRow, type CollectionRowData, type CollectionRowWithMeta, CollectionSelectBuilder, type CollectionSelectOptions,
|
|
2772
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthOtpType, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, CollectionDeleteBuilder, type CollectionField, type CollectionFilterOp, CollectionInsertChain, type CollectionListResult, CollectionMutationReturning, type CollectionRecordEnvelope, type CollectionRequestFn, type CollectionReturnMode, type CollectionRow, type CollectionRowData, type CollectionRowWithMeta, CollectionSelectBuilder, type CollectionSelectOptions, CollectionUpdateBuilder, CollectionUpsertBuilder, type CollectionUpsertOptions, type CollectionUpsertSummary, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, RagableServerClient, type RagableServerClientConfig, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type ServerPrivilege, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createServerClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseOrString, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.js
CHANGED
|
@@ -91,7 +91,6 @@ __export(index_exports, {
|
|
|
91
91
|
parseAgentStreamAgentInfo: () => parseAgentStreamAgentInfo,
|
|
92
92
|
parseAgentStreamDone: () => parseAgentStreamDone,
|
|
93
93
|
parseOrString: () => parseOrString,
|
|
94
|
-
parseSelectExpression: () => parseSelectExpression,
|
|
95
94
|
parseSseDataLine: () => parseSseDataLine,
|
|
96
95
|
parseTransportResponse: () => parseTransportResponse,
|
|
97
96
|
readSseStream: () => readSseStream,
|
|
@@ -1864,102 +1863,10 @@ function flattenRecord(record) {
|
|
|
1864
1863
|
}
|
|
1865
1864
|
function parseColumns(columns) {
|
|
1866
1865
|
const trimmed = (columns ?? "*").trim();
|
|
1867
|
-
if (trimmed.includes("(")) {
|
|
1868
|
-
throw new RagableError(
|
|
1869
|
-
"Embeds and aggregates are only supported in .select() queries, not in a mutation's returning .select(). Use plain column names here.",
|
|
1870
|
-
400,
|
|
1871
|
-
{ code: "SDK_COLLECTION_SELECT_PLAIN_ONLY" }
|
|
1872
|
-
);
|
|
1873
|
-
}
|
|
1874
1866
|
if (!trimmed || trimmed === "*") return null;
|
|
1875
1867
|
const fields = trimmed.split(",").map((c) => c.trim()).filter(Boolean).filter((c) => c !== "*");
|
|
1876
1868
|
return fields.length > 0 ? fields : null;
|
|
1877
1869
|
}
|
|
1878
|
-
var IDENT = "[A-Za-z_][A-Za-z0-9_]*";
|
|
1879
|
-
var AGGREGATE_RE = new RegExp(
|
|
1880
|
-
`^(?:(${IDENT}):)?(?:(${IDENT})\\.)?(count|sum|avg|min|max)\\(\\)$`
|
|
1881
|
-
);
|
|
1882
|
-
var EMBED_RE = new RegExp(`^(?:(${IDENT}):)?(${IDENT})(?:!(${IDENT}))?\\(([^()]*)\\)$`);
|
|
1883
|
-
var FIELD_RE = new RegExp(`^${IDENT}$`);
|
|
1884
|
-
function parseSelectExpression(columns) {
|
|
1885
|
-
const trimmed = (columns ?? "*").trim();
|
|
1886
|
-
const result = { fields: null, embeds: [], aggregates: [] };
|
|
1887
|
-
if (!trimmed || trimmed === "*") return result;
|
|
1888
|
-
const fields = [];
|
|
1889
|
-
let sawStar = false;
|
|
1890
|
-
for (const segment of splitTopLevel(trimmed)) {
|
|
1891
|
-
if (segment === "*") {
|
|
1892
|
-
sawStar = true;
|
|
1893
|
-
continue;
|
|
1894
|
-
}
|
|
1895
|
-
const agg = AGGREGATE_RE.exec(segment);
|
|
1896
|
-
if (agg) {
|
|
1897
|
-
const [, alias, field, fn] = agg;
|
|
1898
|
-
if (fn !== "count" && !field) {
|
|
1899
|
-
throw new RagableError(
|
|
1900
|
-
`.select(): "${segment}" \u2014 ${fn}() needs a field, e.g. "amount.${fn}()".`,
|
|
1901
|
-
400,
|
|
1902
|
-
{ code: "SDK_COLLECTION_AGGREGATE_FIELD_REQUIRED" }
|
|
1903
|
-
);
|
|
1904
|
-
}
|
|
1905
|
-
const resolvedAlias = alias ?? (fn === "count" && !field ? "count" : fn);
|
|
1906
|
-
if (result.aggregates.some((a) => a.alias === resolvedAlias)) {
|
|
1907
|
-
throw new RagableError(
|
|
1908
|
-
`.select(): duplicate aggregate key "${resolvedAlias}" \u2014 alias each function, e.g. "total:amount.sum()".`,
|
|
1909
|
-
400,
|
|
1910
|
-
{ code: "SDK_COLLECTION_AGGREGATE_DUPLICATE_ALIAS" }
|
|
1911
|
-
);
|
|
1912
|
-
}
|
|
1913
|
-
result.aggregates.push({
|
|
1914
|
-
fn,
|
|
1915
|
-
...field ? { field } : {},
|
|
1916
|
-
alias: resolvedAlias
|
|
1917
|
-
});
|
|
1918
|
-
continue;
|
|
1919
|
-
}
|
|
1920
|
-
const embed = EMBED_RE.exec(segment);
|
|
1921
|
-
if (embed) {
|
|
1922
|
-
const [, alias, collection, hint, cols] = embed;
|
|
1923
|
-
const inner = (cols ?? "").trim();
|
|
1924
|
-
const embedColumns = !inner || inner === "*" ? null : inner.split(",").map((c) => c.trim()).filter(Boolean).filter((c) => c !== "*");
|
|
1925
|
-
result.embeds.push({
|
|
1926
|
-
alias: alias ?? collection,
|
|
1927
|
-
collection,
|
|
1928
|
-
...hint ? { hint } : {},
|
|
1929
|
-
columns: embedColumns && embedColumns.length > 0 ? embedColumns : null
|
|
1930
|
-
});
|
|
1931
|
-
continue;
|
|
1932
|
-
}
|
|
1933
|
-
if (FIELD_RE.test(segment)) {
|
|
1934
|
-
fields.push(segment);
|
|
1935
|
-
continue;
|
|
1936
|
-
}
|
|
1937
|
-
throw new RagableError(
|
|
1938
|
-
`.select(): could not parse "${segment}". Expected a column name, an embed like "author:users!author_id(name)", or an aggregate like "count()" / "total:amount.sum()".`,
|
|
1939
|
-
400,
|
|
1940
|
-
{ code: "SDK_COLLECTION_SELECT_SYNTAX" }
|
|
1941
|
-
);
|
|
1942
|
-
}
|
|
1943
|
-
if (result.aggregates.length > 0) {
|
|
1944
|
-
if (result.embeds.length > 0) {
|
|
1945
|
-
throw new RagableError(
|
|
1946
|
-
".select(): aggregates and embeds cannot be combined \u2014 run them as separate queries.",
|
|
1947
|
-
400,
|
|
1948
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_EMBED" }
|
|
1949
|
-
);
|
|
1950
|
-
}
|
|
1951
|
-
if (sawStar) {
|
|
1952
|
-
throw new RagableError(
|
|
1953
|
-
'.select(): "*" cannot be combined with aggregates \u2014 list the group-by fields explicitly, e.g. .select("category, count()").',
|
|
1954
|
-
400,
|
|
1955
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_STAR" }
|
|
1956
|
-
);
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
result.fields = sawStar || fields.length === 0 ? null : fields;
|
|
1960
|
-
if (result.aggregates.length > 0) result.fields = fields.length > 0 ? fields : null;
|
|
1961
|
-
return result;
|
|
1962
|
-
}
|
|
1963
1870
|
function projectRow(row, fields) {
|
|
1964
1871
|
if (!fields) return row;
|
|
1965
1872
|
const out = {
|
|
@@ -2231,19 +2138,12 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2231
2138
|
__publicField(this, "_limit");
|
|
2232
2139
|
__publicField(this, "_offset");
|
|
2233
2140
|
__publicField(this, "_order", []);
|
|
2234
|
-
__publicField(this, "
|
|
2141
|
+
__publicField(this, "columns");
|
|
2235
2142
|
__publicField(this, "wantCount");
|
|
2236
2143
|
__publicField(this, "headOnly");
|
|
2237
|
-
this.
|
|
2144
|
+
this.columns = parseColumns(columns);
|
|
2238
2145
|
this.wantCount = options?.count === "exact";
|
|
2239
2146
|
this.headOnly = options?.head === true;
|
|
2240
|
-
if (this.parsed.aggregates.length > 0 && (this.wantCount || this.headOnly)) {
|
|
2241
|
-
throw new RagableError(
|
|
2242
|
-
'Aggregate selects compute their own results \u2014 drop { count: "exact" } / { head: true }.',
|
|
2243
|
-
400,
|
|
2244
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_COUNT" }
|
|
2245
|
-
);
|
|
2246
|
-
}
|
|
2247
2147
|
}
|
|
2248
2148
|
/** Sort by a field. Call again to add secondary sort keys (max 4). */
|
|
2249
2149
|
order(field, options) {
|
|
@@ -2325,66 +2225,9 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2325
2225
|
}));
|
|
2326
2226
|
}
|
|
2327
2227
|
if (this.wantCount) body.count = true;
|
|
2328
|
-
if (this.parsed.embeds.length > 0) {
|
|
2329
|
-
body.embed = this.parsed.embeds.map((e) => ({
|
|
2330
|
-
alias: e.alias,
|
|
2331
|
-
collection: e.collection,
|
|
2332
|
-
...e.hint ? { hint: e.hint } : {}
|
|
2333
|
-
}));
|
|
2334
|
-
}
|
|
2335
|
-
if (this.parsed.aggregates.length > 0) {
|
|
2336
|
-
body.aggregate = {
|
|
2337
|
-
groupBy: this.parsed.fields ?? [],
|
|
2338
|
-
functions: this.parsed.aggregates.map((a) => ({
|
|
2339
|
-
fn: a.fn,
|
|
2340
|
-
...a.field ? { field: a.field } : {},
|
|
2341
|
-
alias: a.alias
|
|
2342
|
-
}))
|
|
2343
|
-
};
|
|
2344
|
-
}
|
|
2345
2228
|
return body;
|
|
2346
2229
|
}
|
|
2347
|
-
/** Flatten the envelope and apply column + embedded-column projection. */
|
|
2348
|
-
shapeRow(record) {
|
|
2349
|
-
const flat = flattenRecord(record);
|
|
2350
|
-
for (const embed of this.parsed.embeds) {
|
|
2351
|
-
if (!embed.columns) continue;
|
|
2352
|
-
const value = flat[embed.alias];
|
|
2353
|
-
if (Array.isArray(value)) {
|
|
2354
|
-
flat[embed.alias] = value.map(
|
|
2355
|
-
(v) => projectEmbeddedObject(v, embed.columns)
|
|
2356
|
-
);
|
|
2357
|
-
} else if (value && typeof value === "object") {
|
|
2358
|
-
flat[embed.alias] = projectEmbeddedObject(value, embed.columns);
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
if (!this.parsed.fields) return flat;
|
|
2362
|
-
const out = {
|
|
2363
|
-
id: flat.id,
|
|
2364
|
-
createdAt: flat.createdAt,
|
|
2365
|
-
updatedAt: flat.updatedAt
|
|
2366
|
-
};
|
|
2367
|
-
for (const field of this.parsed.fields) {
|
|
2368
|
-
if (field in flat) out[field] = flat[field];
|
|
2369
|
-
}
|
|
2370
|
-
for (const embed of this.parsed.embeds) {
|
|
2371
|
-
if (embed.alias in flat) out[embed.alias] = flat[embed.alias];
|
|
2372
|
-
}
|
|
2373
|
-
return out;
|
|
2374
|
-
}
|
|
2375
2230
|
async executeRows(limitOverride) {
|
|
2376
|
-
if (this.parsed.aggregates.length > 0) {
|
|
2377
|
-
const result2 = await asPostgrestResponse(
|
|
2378
|
-
() => this.request(
|
|
2379
|
-
"POST",
|
|
2380
|
-
"/find",
|
|
2381
|
-
this.buildBody(limitOverride),
|
|
2382
|
-
this.signal
|
|
2383
|
-
)
|
|
2384
|
-
);
|
|
2385
|
-
if (result2.error) return { error: result2.error, rows: null, total: null };
|
|
2386
|
-
return { error: null, rows: result2.data ?? [], total: null };
|
|
2387
|
-
}
|
|
2388
2231
|
const result = await asPostgrestResponse(
|
|
2389
2232
|
() => this.request(
|
|
2390
2233
|
"POST",
|
|
@@ -2397,7 +2240,7 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2397
2240
|
const payload = result.data;
|
|
2398
2241
|
const records = Array.isArray(payload) ? payload : payload?.records ?? [];
|
|
2399
2242
|
const total = Array.isArray(payload) ? null : payload?.total ?? null;
|
|
2400
|
-
const rows = records.map((r) =>
|
|
2243
|
+
const rows = records.map((r) => projectRow(flattenRecord(r), this.columns));
|
|
2401
2244
|
return { error: null, rows, total };
|
|
2402
2245
|
}
|
|
2403
2246
|
async execute() {
|
|
@@ -2410,17 +2253,6 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2410
2253
|
};
|
|
2411
2254
|
}
|
|
2412
2255
|
};
|
|
2413
|
-
function projectEmbeddedObject(value, columns) {
|
|
2414
|
-
const source = value;
|
|
2415
|
-
const out = {};
|
|
2416
|
-
for (const key of ["id", "createdAt", "updatedAt"]) {
|
|
2417
|
-
if (key in source) out[key] = source[key];
|
|
2418
|
-
}
|
|
2419
|
-
for (const column of columns) {
|
|
2420
|
-
if (column in source) out[column] = source[column];
|
|
2421
|
-
}
|
|
2422
|
-
return out;
|
|
2423
|
-
}
|
|
2424
2256
|
var CollectionMutationReturning = class {
|
|
2425
2257
|
constructor(run, columns) {
|
|
2426
2258
|
this.run = run;
|
|
@@ -4366,12 +4198,6 @@ var BrowserCollectionApi = class {
|
|
|
4366
4198
|
* .order("createdAt", { ascending: false })
|
|
4367
4199
|
* .range(0, 19);
|
|
4368
4200
|
* ```
|
|
4369
|
-
*
|
|
4370
|
-
* Relation embeds (one level): `select("*, author:users!author_id(name), comments(*)")`
|
|
4371
|
-
* — to-one embeds become an object (or null), to-many an array. Aggregations:
|
|
4372
|
-
* `select("category, count(), total:amount.sum()")` groups by the plain
|
|
4373
|
-
* columns; pass a type argument for the result shape:
|
|
4374
|
-
* `select<{ category: string; count: number }>("category, count()")`.
|
|
4375
4201
|
*/
|
|
4376
4202
|
__publicField(this, "select", (columns, options) => new CollectionSelectBuilder(this.chainRequest, columns, options));
|
|
4377
4203
|
/**
|
|
@@ -5827,7 +5653,6 @@ function createClient(options) {
|
|
|
5827
5653
|
parseAgentStreamAgentInfo,
|
|
5828
5654
|
parseAgentStreamDone,
|
|
5829
5655
|
parseOrString,
|
|
5830
|
-
parseSelectExpression,
|
|
5831
5656
|
parseSseDataLine,
|
|
5832
5657
|
parseTransportResponse,
|
|
5833
5658
|
readSseStream,
|
package/dist/index.mjs
CHANGED
|
@@ -1760,102 +1760,10 @@ function flattenRecord(record) {
|
|
|
1760
1760
|
}
|
|
1761
1761
|
function parseColumns(columns) {
|
|
1762
1762
|
const trimmed = (columns ?? "*").trim();
|
|
1763
|
-
if (trimmed.includes("(")) {
|
|
1764
|
-
throw new RagableError(
|
|
1765
|
-
"Embeds and aggregates are only supported in .select() queries, not in a mutation's returning .select(). Use plain column names here.",
|
|
1766
|
-
400,
|
|
1767
|
-
{ code: "SDK_COLLECTION_SELECT_PLAIN_ONLY" }
|
|
1768
|
-
);
|
|
1769
|
-
}
|
|
1770
1763
|
if (!trimmed || trimmed === "*") return null;
|
|
1771
1764
|
const fields = trimmed.split(",").map((c) => c.trim()).filter(Boolean).filter((c) => c !== "*");
|
|
1772
1765
|
return fields.length > 0 ? fields : null;
|
|
1773
1766
|
}
|
|
1774
|
-
var IDENT = "[A-Za-z_][A-Za-z0-9_]*";
|
|
1775
|
-
var AGGREGATE_RE = new RegExp(
|
|
1776
|
-
`^(?:(${IDENT}):)?(?:(${IDENT})\\.)?(count|sum|avg|min|max)\\(\\)$`
|
|
1777
|
-
);
|
|
1778
|
-
var EMBED_RE = new RegExp(`^(?:(${IDENT}):)?(${IDENT})(?:!(${IDENT}))?\\(([^()]*)\\)$`);
|
|
1779
|
-
var FIELD_RE = new RegExp(`^${IDENT}$`);
|
|
1780
|
-
function parseSelectExpression(columns) {
|
|
1781
|
-
const trimmed = (columns ?? "*").trim();
|
|
1782
|
-
const result = { fields: null, embeds: [], aggregates: [] };
|
|
1783
|
-
if (!trimmed || trimmed === "*") return result;
|
|
1784
|
-
const fields = [];
|
|
1785
|
-
let sawStar = false;
|
|
1786
|
-
for (const segment of splitTopLevel(trimmed)) {
|
|
1787
|
-
if (segment === "*") {
|
|
1788
|
-
sawStar = true;
|
|
1789
|
-
continue;
|
|
1790
|
-
}
|
|
1791
|
-
const agg = AGGREGATE_RE.exec(segment);
|
|
1792
|
-
if (agg) {
|
|
1793
|
-
const [, alias, field, fn] = agg;
|
|
1794
|
-
if (fn !== "count" && !field) {
|
|
1795
|
-
throw new RagableError(
|
|
1796
|
-
`.select(): "${segment}" \u2014 ${fn}() needs a field, e.g. "amount.${fn}()".`,
|
|
1797
|
-
400,
|
|
1798
|
-
{ code: "SDK_COLLECTION_AGGREGATE_FIELD_REQUIRED" }
|
|
1799
|
-
);
|
|
1800
|
-
}
|
|
1801
|
-
const resolvedAlias = alias ?? (fn === "count" && !field ? "count" : fn);
|
|
1802
|
-
if (result.aggregates.some((a) => a.alias === resolvedAlias)) {
|
|
1803
|
-
throw new RagableError(
|
|
1804
|
-
`.select(): duplicate aggregate key "${resolvedAlias}" \u2014 alias each function, e.g. "total:amount.sum()".`,
|
|
1805
|
-
400,
|
|
1806
|
-
{ code: "SDK_COLLECTION_AGGREGATE_DUPLICATE_ALIAS" }
|
|
1807
|
-
);
|
|
1808
|
-
}
|
|
1809
|
-
result.aggregates.push({
|
|
1810
|
-
fn,
|
|
1811
|
-
...field ? { field } : {},
|
|
1812
|
-
alias: resolvedAlias
|
|
1813
|
-
});
|
|
1814
|
-
continue;
|
|
1815
|
-
}
|
|
1816
|
-
const embed = EMBED_RE.exec(segment);
|
|
1817
|
-
if (embed) {
|
|
1818
|
-
const [, alias, collection, hint, cols] = embed;
|
|
1819
|
-
const inner = (cols ?? "").trim();
|
|
1820
|
-
const embedColumns = !inner || inner === "*" ? null : inner.split(",").map((c) => c.trim()).filter(Boolean).filter((c) => c !== "*");
|
|
1821
|
-
result.embeds.push({
|
|
1822
|
-
alias: alias ?? collection,
|
|
1823
|
-
collection,
|
|
1824
|
-
...hint ? { hint } : {},
|
|
1825
|
-
columns: embedColumns && embedColumns.length > 0 ? embedColumns : null
|
|
1826
|
-
});
|
|
1827
|
-
continue;
|
|
1828
|
-
}
|
|
1829
|
-
if (FIELD_RE.test(segment)) {
|
|
1830
|
-
fields.push(segment);
|
|
1831
|
-
continue;
|
|
1832
|
-
}
|
|
1833
|
-
throw new RagableError(
|
|
1834
|
-
`.select(): could not parse "${segment}". Expected a column name, an embed like "author:users!author_id(name)", or an aggregate like "count()" / "total:amount.sum()".`,
|
|
1835
|
-
400,
|
|
1836
|
-
{ code: "SDK_COLLECTION_SELECT_SYNTAX" }
|
|
1837
|
-
);
|
|
1838
|
-
}
|
|
1839
|
-
if (result.aggregates.length > 0) {
|
|
1840
|
-
if (result.embeds.length > 0) {
|
|
1841
|
-
throw new RagableError(
|
|
1842
|
-
".select(): aggregates and embeds cannot be combined \u2014 run them as separate queries.",
|
|
1843
|
-
400,
|
|
1844
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_EMBED" }
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
if (sawStar) {
|
|
1848
|
-
throw new RagableError(
|
|
1849
|
-
'.select(): "*" cannot be combined with aggregates \u2014 list the group-by fields explicitly, e.g. .select("category, count()").',
|
|
1850
|
-
400,
|
|
1851
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_STAR" }
|
|
1852
|
-
);
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
result.fields = sawStar || fields.length === 0 ? null : fields;
|
|
1856
|
-
if (result.aggregates.length > 0) result.fields = fields.length > 0 ? fields : null;
|
|
1857
|
-
return result;
|
|
1858
|
-
}
|
|
1859
1767
|
function projectRow(row, fields) {
|
|
1860
1768
|
if (!fields) return row;
|
|
1861
1769
|
const out = {
|
|
@@ -2127,19 +2035,12 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2127
2035
|
__publicField(this, "_limit");
|
|
2128
2036
|
__publicField(this, "_offset");
|
|
2129
2037
|
__publicField(this, "_order", []);
|
|
2130
|
-
__publicField(this, "
|
|
2038
|
+
__publicField(this, "columns");
|
|
2131
2039
|
__publicField(this, "wantCount");
|
|
2132
2040
|
__publicField(this, "headOnly");
|
|
2133
|
-
this.
|
|
2041
|
+
this.columns = parseColumns(columns);
|
|
2134
2042
|
this.wantCount = options?.count === "exact";
|
|
2135
2043
|
this.headOnly = options?.head === true;
|
|
2136
|
-
if (this.parsed.aggregates.length > 0 && (this.wantCount || this.headOnly)) {
|
|
2137
|
-
throw new RagableError(
|
|
2138
|
-
'Aggregate selects compute their own results \u2014 drop { count: "exact" } / { head: true }.',
|
|
2139
|
-
400,
|
|
2140
|
-
{ code: "SDK_COLLECTION_AGGREGATE_WITH_COUNT" }
|
|
2141
|
-
);
|
|
2142
|
-
}
|
|
2143
2044
|
}
|
|
2144
2045
|
/** Sort by a field. Call again to add secondary sort keys (max 4). */
|
|
2145
2046
|
order(field, options) {
|
|
@@ -2221,66 +2122,9 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2221
2122
|
}));
|
|
2222
2123
|
}
|
|
2223
2124
|
if (this.wantCount) body.count = true;
|
|
2224
|
-
if (this.parsed.embeds.length > 0) {
|
|
2225
|
-
body.embed = this.parsed.embeds.map((e) => ({
|
|
2226
|
-
alias: e.alias,
|
|
2227
|
-
collection: e.collection,
|
|
2228
|
-
...e.hint ? { hint: e.hint } : {}
|
|
2229
|
-
}));
|
|
2230
|
-
}
|
|
2231
|
-
if (this.parsed.aggregates.length > 0) {
|
|
2232
|
-
body.aggregate = {
|
|
2233
|
-
groupBy: this.parsed.fields ?? [],
|
|
2234
|
-
functions: this.parsed.aggregates.map((a) => ({
|
|
2235
|
-
fn: a.fn,
|
|
2236
|
-
...a.field ? { field: a.field } : {},
|
|
2237
|
-
alias: a.alias
|
|
2238
|
-
}))
|
|
2239
|
-
};
|
|
2240
|
-
}
|
|
2241
2125
|
return body;
|
|
2242
2126
|
}
|
|
2243
|
-
/** Flatten the envelope and apply column + embedded-column projection. */
|
|
2244
|
-
shapeRow(record) {
|
|
2245
|
-
const flat = flattenRecord(record);
|
|
2246
|
-
for (const embed of this.parsed.embeds) {
|
|
2247
|
-
if (!embed.columns) continue;
|
|
2248
|
-
const value = flat[embed.alias];
|
|
2249
|
-
if (Array.isArray(value)) {
|
|
2250
|
-
flat[embed.alias] = value.map(
|
|
2251
|
-
(v) => projectEmbeddedObject(v, embed.columns)
|
|
2252
|
-
);
|
|
2253
|
-
} else if (value && typeof value === "object") {
|
|
2254
|
-
flat[embed.alias] = projectEmbeddedObject(value, embed.columns);
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
if (!this.parsed.fields) return flat;
|
|
2258
|
-
const out = {
|
|
2259
|
-
id: flat.id,
|
|
2260
|
-
createdAt: flat.createdAt,
|
|
2261
|
-
updatedAt: flat.updatedAt
|
|
2262
|
-
};
|
|
2263
|
-
for (const field of this.parsed.fields) {
|
|
2264
|
-
if (field in flat) out[field] = flat[field];
|
|
2265
|
-
}
|
|
2266
|
-
for (const embed of this.parsed.embeds) {
|
|
2267
|
-
if (embed.alias in flat) out[embed.alias] = flat[embed.alias];
|
|
2268
|
-
}
|
|
2269
|
-
return out;
|
|
2270
|
-
}
|
|
2271
2127
|
async executeRows(limitOverride) {
|
|
2272
|
-
if (this.parsed.aggregates.length > 0) {
|
|
2273
|
-
const result2 = await asPostgrestResponse(
|
|
2274
|
-
() => this.request(
|
|
2275
|
-
"POST",
|
|
2276
|
-
"/find",
|
|
2277
|
-
this.buildBody(limitOverride),
|
|
2278
|
-
this.signal
|
|
2279
|
-
)
|
|
2280
|
-
);
|
|
2281
|
-
if (result2.error) return { error: result2.error, rows: null, total: null };
|
|
2282
|
-
return { error: null, rows: result2.data ?? [], total: null };
|
|
2283
|
-
}
|
|
2284
2128
|
const result = await asPostgrestResponse(
|
|
2285
2129
|
() => this.request(
|
|
2286
2130
|
"POST",
|
|
@@ -2293,7 +2137,7 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2293
2137
|
const payload = result.data;
|
|
2294
2138
|
const records = Array.isArray(payload) ? payload : payload?.records ?? [];
|
|
2295
2139
|
const total = Array.isArray(payload) ? null : payload?.total ?? null;
|
|
2296
|
-
const rows = records.map((r) =>
|
|
2140
|
+
const rows = records.map((r) => projectRow(flattenRecord(r), this.columns));
|
|
2297
2141
|
return { error: null, rows, total };
|
|
2298
2142
|
}
|
|
2299
2143
|
async execute() {
|
|
@@ -2306,17 +2150,6 @@ var CollectionSelectBuilder = class extends CollectionConditionBuilder {
|
|
|
2306
2150
|
};
|
|
2307
2151
|
}
|
|
2308
2152
|
};
|
|
2309
|
-
function projectEmbeddedObject(value, columns) {
|
|
2310
|
-
const source = value;
|
|
2311
|
-
const out = {};
|
|
2312
|
-
for (const key of ["id", "createdAt", "updatedAt"]) {
|
|
2313
|
-
if (key in source) out[key] = source[key];
|
|
2314
|
-
}
|
|
2315
|
-
for (const column of columns) {
|
|
2316
|
-
if (column in source) out[column] = source[column];
|
|
2317
|
-
}
|
|
2318
|
-
return out;
|
|
2319
|
-
}
|
|
2320
2153
|
var CollectionMutationReturning = class {
|
|
2321
2154
|
constructor(run, columns) {
|
|
2322
2155
|
this.run = run;
|
|
@@ -4262,12 +4095,6 @@ var BrowserCollectionApi = class {
|
|
|
4262
4095
|
* .order("createdAt", { ascending: false })
|
|
4263
4096
|
* .range(0, 19);
|
|
4264
4097
|
* ```
|
|
4265
|
-
*
|
|
4266
|
-
* Relation embeds (one level): `select("*, author:users!author_id(name), comments(*)")`
|
|
4267
|
-
* — to-one embeds become an object (or null), to-many an array. Aggregations:
|
|
4268
|
-
* `select("category, count(), total:amount.sum()")` groups by the plain
|
|
4269
|
-
* columns; pass a type argument for the result shape:
|
|
4270
|
-
* `select<{ category: string; count: number }>("category, count()")`.
|
|
4271
4098
|
*/
|
|
4272
4099
|
__publicField(this, "select", (columns, options) => new CollectionSelectBuilder(this.chainRequest, columns, options));
|
|
4273
4100
|
/**
|
|
@@ -5722,7 +5549,6 @@ export {
|
|
|
5722
5549
|
parseAgentStreamAgentInfo,
|
|
5723
5550
|
parseAgentStreamDone,
|
|
5724
5551
|
parseOrString,
|
|
5725
|
-
parseSelectExpression,
|
|
5726
5552
|
parseSseDataLine,
|
|
5727
5553
|
parseTransportResponse,
|
|
5728
5554
|
readSseStream,
|