@ragable/sdk 0.6.20 → 0.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -313,6 +313,26 @@ type PostgrestResult<T> = {
313
313
  data: null;
314
314
  error: RagableError;
315
315
  };
316
+ /** Discriminated result for easier TypeScript narrowing than `{ data, error }` after destructuring. */
317
+ type RagableResult<T, E = RagableError> = {
318
+ ok: true;
319
+ value: T;
320
+ } | {
321
+ ok: false;
322
+ error: E;
323
+ };
324
+ declare function toRagableResult<T>(r: PostgrestResult<T>): RagableResult<T>;
325
+ /**
326
+ * Narrows a {@link PostgrestResult} after an `if (result.error)` guard.
327
+ * Prefer checking `result.error` on the result object (not destructured `{ data, error }`)
328
+ * so TypeScript narrows `data` automatically; use this when you need a throw or assertion.
329
+ */
330
+ declare function assertPostgrestSuccess<T>(r: PostgrestResult<T>): asserts r is {
331
+ data: T;
332
+ error: null;
333
+ };
334
+ /** Returns `data` or throws `RagableError` / the failure case. */
335
+ declare function unwrapPostgrest<T>(r: PostgrestResult<T>): T;
316
336
  declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
317
337
  type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "is" | "in";
318
338
  interface Filter {
@@ -991,7 +1011,34 @@ interface BrowserCollectionDefinition {
991
1011
  createdAt: string;
992
1012
  updatedAt: string;
993
1013
  }
994
- type CollectionWhere<Row extends Record<string, unknown>> = Partial<Row> & Record<string, unknown>;
1014
+ /**
1015
+ * Prisma-style operator object for a single field (server-supported ops).
1016
+ * Typed loosely so schema-specific refinements can be added in app code.
1017
+ */
1018
+ type WhereOperatorObject = {
1019
+ eq?: unknown;
1020
+ neq?: unknown;
1021
+ gt?: number;
1022
+ gte?: number;
1023
+ lt?: number;
1024
+ lte?: number;
1025
+ in?: unknown;
1026
+ contains?: unknown;
1027
+ };
1028
+ /**
1029
+ * `where` filters: equality on values, or per-field operator objects.
1030
+ * Use `id`, `createdAt`, `updatedAt` to match the record envelope (DB columns), not `data` JSON
1031
+ * (unless you also have those keys in your JSON — prefer envelope keys for `id`).
1032
+ */
1033
+ type WhereInput<Row extends Record<string, unknown>> = {
1034
+ [K in keyof Row]?: Row[K] | WhereOperatorObject | null;
1035
+ } & {
1036
+ id?: string | WhereOperatorObject;
1037
+ createdAt?: string | WhereOperatorObject;
1038
+ updatedAt?: string | WhereOperatorObject;
1039
+ };
1040
+ /** @deprecated Use {@link WhereInput} — same shape. */
1041
+ type CollectionWhere<Row extends Record<string, unknown>> = WhereInput<Row>;
995
1042
  type CollectionFilter<Row extends Record<string, unknown>> = {
996
1043
  [Field in Extract<keyof Row, string>]: {
997
1044
  field: Field;
@@ -999,8 +1046,22 @@ type CollectionFilter<Row extends Record<string, unknown>> = {
999
1046
  value: Row[Field];
1000
1047
  };
1001
1048
  }[Extract<keyof Row, string>];
1049
+ type CollectionReturnMode = "envelope" | "flat";
1050
+ /**
1051
+ * One row: JSON fields at the top level, envelope fields under `meta`
1052
+ * (when using {@link BrowserCollectionApi.findMany} with `return: "flat"`).
1053
+ */
1054
+ type CollectionRowWithMeta<Row extends Record<string, unknown> = Record<string, unknown>> = Row & {
1055
+ meta: {
1056
+ id: string;
1057
+ createdAt: string;
1058
+ updatedAt: string;
1059
+ };
1060
+ };
1061
+ declare function collectionRecordToRowWithMeta<Row extends Record<string, unknown>>(record: BrowserCollectionRecord<Row>): CollectionRowWithMeta<Row>;
1062
+ declare function collectionRecordsToRowWithMeta<Row extends Record<string, unknown>>(records: BrowserCollectionRecord<Row>[]): CollectionRowWithMeta<Row>[];
1002
1063
  type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
1003
- where?: CollectionWhere<Row>;
1064
+ where?: WhereInput<Row>;
1004
1065
  filters?: Array<{
1005
1066
  field: Extract<keyof Row, string> | (string & {});
1006
1067
  op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
@@ -1008,24 +1069,69 @@ type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<st
1008
1069
  } | CollectionFilter<Row>>;
1009
1070
  limit?: number;
1010
1071
  offset?: number;
1011
- orderBy?: Extract<keyof Row, string> | (string & {});
1072
+ orderBy?: Extract<keyof Row, string> | "id" | "createdAt" | "updatedAt" | (string & {});
1012
1073
  orderDirection?: "asc" | "desc";
1074
+ /**
1075
+ * - `envelope` (default): `Array<{ id, data, createdAt, updatedAt }>`
1076
+ * - `flat`: {@link CollectionRowWithMeta} — row fields at top level + `meta` for `id` / timestamps
1077
+ */
1078
+ return?: CollectionReturnMode;
1013
1079
  };
1080
+ type CollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = BrowserCollectionRowData<Row>;
1081
+ type RowD<Row extends Record<string, unknown>> = BrowserCollectionRowData<Row>;
1014
1082
  declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>, Insert extends Record<string, unknown> = Row, Update extends Record<string, unknown> = Partial<Row>> {
1015
1083
  private readonly database;
1016
1084
  private readonly name;
1017
1085
  private readonly databaseInstanceId?;
1018
1086
  constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
1019
- find: (whereOrParams?: CollectionWhere<BrowserCollectionRowData<Row>> | BrowserCollectionFindParams<BrowserCollectionRowData<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1020
- insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>>>;
1021
- update: (where: CollectionWhere<BrowserCollectionRowData<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1087
+ private normalizeFindArgs;
1088
+ private requestFind;
1089
+ /**
1090
+ * Query collection rows. Prefer this over the deprecated `find` alias.
1091
+ * Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
1092
+ */
1093
+ findMany: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
1094
+ /**
1095
+ * @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
1096
+ */
1097
+ find: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
1098
+ /**
1099
+ * At most one row, `data` is the record or `null` if none match (not an error).
1100
+ */
1101
+ findFirst: (whereOrParams?: WhereInput<RowD<Row>> | Omit<BrowserCollectionFindParams<RowD<Row>>, "return">) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
1102
+ /**
1103
+ * Lookup by primary key `id` (envelope). Equivalent to
1104
+ * `findFirst({ where: { id }, limit: 1 })` with a typed `where.id`.
1105
+ */
1106
+ findUnique: (args: {
1107
+ where: {
1108
+ id: string;
1109
+ } & Partial<WhereInput<RowD<Row>>>;
1110
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
1111
+ insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>>>;
1112
+ /**
1113
+ * Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
1114
+ */
1115
+ update: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1116
+ limit?: number;
1117
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[]>>;
1118
+ /**
1119
+ * Like {@link BrowserCollectionApi.update} but the success payload includes
1120
+ * `meta.count` (number of rows returned from the update, bounded by `limit`).
1121
+ */
1122
+ updateMany: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1022
1123
  limit?: number;
1023
- }) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1024
- delete: (where: CollectionWhere<BrowserCollectionRowData<Row>>, options?: {
1124
+ }) => Promise<PostgrestResult<{
1125
+ records: BrowserCollectionRecord<RowD<Row>>[];
1126
+ meta: {
1127
+ count: number;
1128
+ };
1129
+ }>>;
1130
+ delete: (where: WhereInput<RowD<Row>>, options?: {
1025
1131
  limit?: number;
1026
1132
  }) => Promise<PostgrestResult<{
1027
1133
  deleted: number;
1028
- records: BrowserCollectionRecord<BrowserCollectionRowData<Row>>[];
1134
+ records: BrowserCollectionRecord<RowD<Row>>[];
1029
1135
  }>>;
1030
1136
  }
1031
1137
  type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
@@ -1242,4 +1348,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
1242
1348
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1243
1349
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
1244
1350
 
1245
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, 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, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, 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, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
1351
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, 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, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, 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, type RagableResult, 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, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream, toRagableResult, unwrapPostgrest };
package/dist/index.d.ts CHANGED
@@ -313,6 +313,26 @@ type PostgrestResult<T> = {
313
313
  data: null;
314
314
  error: RagableError;
315
315
  };
316
+ /** Discriminated result for easier TypeScript narrowing than `{ data, error }` after destructuring. */
317
+ type RagableResult<T, E = RagableError> = {
318
+ ok: true;
319
+ value: T;
320
+ } | {
321
+ ok: false;
322
+ error: E;
323
+ };
324
+ declare function toRagableResult<T>(r: PostgrestResult<T>): RagableResult<T>;
325
+ /**
326
+ * Narrows a {@link PostgrestResult} after an `if (result.error)` guard.
327
+ * Prefer checking `result.error` on the result object (not destructured `{ data, error }`)
328
+ * so TypeScript narrows `data` automatically; use this when you need a throw or assertion.
329
+ */
330
+ declare function assertPostgrestSuccess<T>(r: PostgrestResult<T>): asserts r is {
331
+ data: T;
332
+ error: null;
333
+ };
334
+ /** Returns `data` or throws `RagableError` / the failure case. */
335
+ declare function unwrapPostgrest<T>(r: PostgrestResult<T>): T;
316
336
  declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
317
337
  type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "is" | "in";
318
338
  interface Filter {
@@ -991,7 +1011,34 @@ interface BrowserCollectionDefinition {
991
1011
  createdAt: string;
992
1012
  updatedAt: string;
993
1013
  }
994
- type CollectionWhere<Row extends Record<string, unknown>> = Partial<Row> & Record<string, unknown>;
1014
+ /**
1015
+ * Prisma-style operator object for a single field (server-supported ops).
1016
+ * Typed loosely so schema-specific refinements can be added in app code.
1017
+ */
1018
+ type WhereOperatorObject = {
1019
+ eq?: unknown;
1020
+ neq?: unknown;
1021
+ gt?: number;
1022
+ gte?: number;
1023
+ lt?: number;
1024
+ lte?: number;
1025
+ in?: unknown;
1026
+ contains?: unknown;
1027
+ };
1028
+ /**
1029
+ * `where` filters: equality on values, or per-field operator objects.
1030
+ * Use `id`, `createdAt`, `updatedAt` to match the record envelope (DB columns), not `data` JSON
1031
+ * (unless you also have those keys in your JSON — prefer envelope keys for `id`).
1032
+ */
1033
+ type WhereInput<Row extends Record<string, unknown>> = {
1034
+ [K in keyof Row]?: Row[K] | WhereOperatorObject | null;
1035
+ } & {
1036
+ id?: string | WhereOperatorObject;
1037
+ createdAt?: string | WhereOperatorObject;
1038
+ updatedAt?: string | WhereOperatorObject;
1039
+ };
1040
+ /** @deprecated Use {@link WhereInput} — same shape. */
1041
+ type CollectionWhere<Row extends Record<string, unknown>> = WhereInput<Row>;
995
1042
  type CollectionFilter<Row extends Record<string, unknown>> = {
996
1043
  [Field in Extract<keyof Row, string>]: {
997
1044
  field: Field;
@@ -999,8 +1046,22 @@ type CollectionFilter<Row extends Record<string, unknown>> = {
999
1046
  value: Row[Field];
1000
1047
  };
1001
1048
  }[Extract<keyof Row, string>];
1049
+ type CollectionReturnMode = "envelope" | "flat";
1050
+ /**
1051
+ * One row: JSON fields at the top level, envelope fields under `meta`
1052
+ * (when using {@link BrowserCollectionApi.findMany} with `return: "flat"`).
1053
+ */
1054
+ type CollectionRowWithMeta<Row extends Record<string, unknown> = Record<string, unknown>> = Row & {
1055
+ meta: {
1056
+ id: string;
1057
+ createdAt: string;
1058
+ updatedAt: string;
1059
+ };
1060
+ };
1061
+ declare function collectionRecordToRowWithMeta<Row extends Record<string, unknown>>(record: BrowserCollectionRecord<Row>): CollectionRowWithMeta<Row>;
1062
+ declare function collectionRecordsToRowWithMeta<Row extends Record<string, unknown>>(records: BrowserCollectionRecord<Row>[]): CollectionRowWithMeta<Row>[];
1002
1063
  type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
1003
- where?: CollectionWhere<Row>;
1064
+ where?: WhereInput<Row>;
1004
1065
  filters?: Array<{
1005
1066
  field: Extract<keyof Row, string> | (string & {});
1006
1067
  op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
@@ -1008,24 +1069,69 @@ type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<st
1008
1069
  } | CollectionFilter<Row>>;
1009
1070
  limit?: number;
1010
1071
  offset?: number;
1011
- orderBy?: Extract<keyof Row, string> | (string & {});
1072
+ orderBy?: Extract<keyof Row, string> | "id" | "createdAt" | "updatedAt" | (string & {});
1012
1073
  orderDirection?: "asc" | "desc";
1074
+ /**
1075
+ * - `envelope` (default): `Array<{ id, data, createdAt, updatedAt }>`
1076
+ * - `flat`: {@link CollectionRowWithMeta} — row fields at top level + `meta` for `id` / timestamps
1077
+ */
1078
+ return?: CollectionReturnMode;
1013
1079
  };
1080
+ type CollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = BrowserCollectionRowData<Row>;
1081
+ type RowD<Row extends Record<string, unknown>> = BrowserCollectionRowData<Row>;
1014
1082
  declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>, Insert extends Record<string, unknown> = Row, Update extends Record<string, unknown> = Partial<Row>> {
1015
1083
  private readonly database;
1016
1084
  private readonly name;
1017
1085
  private readonly databaseInstanceId?;
1018
1086
  constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
1019
- find: (whereOrParams?: CollectionWhere<BrowserCollectionRowData<Row>> | BrowserCollectionFindParams<BrowserCollectionRowData<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1020
- insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>>>;
1021
- update: (where: CollectionWhere<BrowserCollectionRowData<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1087
+ private normalizeFindArgs;
1088
+ private requestFind;
1089
+ /**
1090
+ * Query collection rows. Prefer this over the deprecated `find` alias.
1091
+ * Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
1092
+ */
1093
+ findMany: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
1094
+ /**
1095
+ * @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
1096
+ */
1097
+ find: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
1098
+ /**
1099
+ * At most one row, `data` is the record or `null` if none match (not an error).
1100
+ */
1101
+ findFirst: (whereOrParams?: WhereInput<RowD<Row>> | Omit<BrowserCollectionFindParams<RowD<Row>>, "return">) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
1102
+ /**
1103
+ * Lookup by primary key `id` (envelope). Equivalent to
1104
+ * `findFirst({ where: { id }, limit: 1 })` with a typed `where.id`.
1105
+ */
1106
+ findUnique: (args: {
1107
+ where: {
1108
+ id: string;
1109
+ } & Partial<WhereInput<RowD<Row>>>;
1110
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
1111
+ insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>>>;
1112
+ /**
1113
+ * Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
1114
+ */
1115
+ update: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1116
+ limit?: number;
1117
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[]>>;
1118
+ /**
1119
+ * Like {@link BrowserCollectionApi.update} but the success payload includes
1120
+ * `meta.count` (number of rows returned from the update, bounded by `limit`).
1121
+ */
1122
+ updateMany: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
1022
1123
  limit?: number;
1023
- }) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1024
- delete: (where: CollectionWhere<BrowserCollectionRowData<Row>>, options?: {
1124
+ }) => Promise<PostgrestResult<{
1125
+ records: BrowserCollectionRecord<RowD<Row>>[];
1126
+ meta: {
1127
+ count: number;
1128
+ };
1129
+ }>>;
1130
+ delete: (where: WhereInput<RowD<Row>>, options?: {
1025
1131
  limit?: number;
1026
1132
  }) => Promise<PostgrestResult<{
1027
1133
  deleted: number;
1028
- records: BrowserCollectionRecord<BrowserCollectionRowData<Row>>[];
1134
+ records: BrowserCollectionRecord<RowD<Row>>[];
1029
1135
  }>>;
1030
1136
  }
1031
1137
  type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
@@ -1242,4 +1348,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
1242
1348
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1243
1349
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
1244
1350
 
1245
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, 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, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, 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, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
1351
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, 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, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, 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, type RagableResult, 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, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream, toRagableResult, unwrapPostgrest };
package/dist/index.js CHANGED
@@ -56,7 +56,10 @@ __export(index_exports, {
56
56
  ShiftClient: () => ShiftClient,
57
57
  Transport: () => Transport,
58
58
  asPostgrestResponse: () => asPostgrestResponse,
59
+ assertPostgrestSuccess: () => assertPostgrestSuccess,
59
60
  bindFetch: () => bindFetch,
61
+ collectionRecordToRowWithMeta: () => collectionRecordToRowWithMeta,
62
+ collectionRecordsToRowWithMeta: () => collectionRecordsToRowWithMeta,
60
63
  createBrowserClient: () => createBrowserClient,
61
64
  createClient: () => createClient,
62
65
  createRagPipeline: () => createRagPipeline,
@@ -72,7 +75,9 @@ __export(index_exports, {
72
75
  normalizeBrowserApiBase: () => normalizeBrowserApiBase,
73
76
  parseSseDataLine: () => parseSseDataLine,
74
77
  parseTransportResponse: () => parseTransportResponse,
75
- readSseStream: () => readSseStream
78
+ readSseStream: () => readSseStream,
79
+ toRagableResult: () => toRagableResult,
80
+ unwrapPostgrest: () => unwrapPostgrest
76
81
  });
77
82
  module.exports = __toCommonJS(index_exports);
78
83
 
@@ -701,6 +706,17 @@ async function parseTransportResponse(response) {
701
706
  }
702
707
 
703
708
  // src/browser-postgrest.ts
709
+ function toRagableResult(r) {
710
+ if (r.error) return { ok: false, error: r.error };
711
+ return { ok: true, value: r.data };
712
+ }
713
+ function assertPostgrestSuccess(r) {
714
+ if (r.error) throw r.error;
715
+ }
716
+ function unwrapPostgrest(r) {
717
+ if (r.error) throw r.error;
718
+ return r.data;
719
+ }
704
720
  async function asPostgrestResponse(fn) {
705
721
  try {
706
722
  const data = await fn();
@@ -2286,24 +2302,71 @@ var RagableBrowserAuthClient = class {
2286
2302
  return this.auth.getSession();
2287
2303
  }
2288
2304
  };
2305
+ function collectionRecordToRowWithMeta(record) {
2306
+ const { data, id, createdAt, updatedAt } = record;
2307
+ return { ...data, meta: { id, createdAt, updatedAt } };
2308
+ }
2309
+ function collectionRecordsToRowWithMeta(records) {
2310
+ return records.map(collectionRecordToRowWithMeta);
2311
+ }
2312
+ var FIND_QUERY_KEYS = [
2313
+ "where",
2314
+ "filters",
2315
+ "limit",
2316
+ "offset",
2317
+ "orderBy",
2318
+ "orderDirection",
2319
+ "return"
2320
+ ];
2289
2321
  var BrowserCollectionApi = class {
2290
2322
  constructor(database, name, databaseInstanceId) {
2291
2323
  this.database = database;
2292
2324
  this.name = name;
2293
2325
  this.databaseInstanceId = databaseInstanceId;
2294
- __publicField(this, "find", (whereOrParams = {}) => {
2295
- const hasQueryKeys = ["where", "filters", "limit", "offset", "orderBy", "orderDirection"].some(
2296
- (key) => Object.prototype.hasOwnProperty.call(whereOrParams, key)
2297
- );
2298
- const body = hasQueryKeys ? whereOrParams : { where: whereOrParams };
2299
- return asPostgrestResponse(
2300
- () => this.database._requestCollection(
2301
- "POST",
2302
- `/${encodeURIComponent(this.name)}/find`,
2303
- body,
2304
- this.databaseInstanceId
2305
- )
2306
- );
2326
+ __publicField(this, "requestFind", (body) => asPostgrestResponse(
2327
+ () => this.database._requestCollection(
2328
+ "POST",
2329
+ `/${encodeURIComponent(this.name)}/find`,
2330
+ body,
2331
+ this.databaseInstanceId
2332
+ )
2333
+ ));
2334
+ /**
2335
+ * Query collection rows. Prefer this over the deprecated `find` alias.
2336
+ * Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
2337
+ */
2338
+ __publicField(this, "findMany", async (whereOrParams = {}) => {
2339
+ const { returnMode, body } = this.normalizeFindArgs(whereOrParams);
2340
+ const res = await this.requestFind(body);
2341
+ if (res.error) return res;
2342
+ if (returnMode === "flat") {
2343
+ return {
2344
+ data: collectionRecordsToRowWithMeta(res.data),
2345
+ error: null
2346
+ };
2347
+ }
2348
+ return res;
2349
+ });
2350
+ /**
2351
+ * @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
2352
+ */
2353
+ __publicField(this, "find", (whereOrParams = {}) => this.findMany(whereOrParams));
2354
+ /**
2355
+ * At most one row, `data` is the record or `null` if none match (not an error).
2356
+ */
2357
+ __publicField(this, "findFirst", async (whereOrParams = {}) => {
2358
+ const { body } = this.normalizeFindArgs(whereOrParams);
2359
+ const withCap = { ...body, limit: 1, offset: body["offset"] ?? 0 };
2360
+ const res = await this.requestFind(withCap);
2361
+ if (res.error) return res;
2362
+ return { data: res.data[0] ?? null, error: null };
2363
+ });
2364
+ /**
2365
+ * Lookup by primary key `id` (envelope). Equivalent to
2366
+ * `findFirst({ where: { id }, limit: 1 })` with a typed `where.id`.
2367
+ */
2368
+ __publicField(this, "findUnique", async (args) => {
2369
+ return this.findFirst({ where: args.where });
2307
2370
  });
2308
2371
  __publicField(this, "insert", (data) => asPostgrestResponse(
2309
2372
  () => this.database._requestCollection(
@@ -2313,6 +2376,9 @@ var BrowserCollectionApi = class {
2313
2376
  this.databaseInstanceId
2314
2377
  )
2315
2378
  ));
2379
+ /**
2380
+ * Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
2381
+ */
2316
2382
  __publicField(this, "update", (where, patch, options) => asPostgrestResponse(
2317
2383
  () => this.database._requestCollection(
2318
2384
  "PATCH",
@@ -2321,6 +2387,15 @@ var BrowserCollectionApi = class {
2321
2387
  this.databaseInstanceId
2322
2388
  )
2323
2389
  ));
2390
+ /**
2391
+ * Like {@link BrowserCollectionApi.update} but the success payload includes
2392
+ * `meta.count` (number of rows returned from the update, bounded by `limit`).
2393
+ */
2394
+ __publicField(this, "updateMany", async (where, patch, options) => {
2395
+ const r = await this.update(where, patch, options);
2396
+ if (r.error) return r;
2397
+ return { data: { records: r.data, meta: { count: r.data.length } }, error: null };
2398
+ });
2324
2399
  __publicField(this, "delete", (where, options) => asPostgrestResponse(
2325
2400
  () => this.database._requestCollection(
2326
2401
  "DELETE",
@@ -2330,6 +2405,15 @@ var BrowserCollectionApi = class {
2330
2405
  )
2331
2406
  ));
2332
2407
  }
2408
+ normalizeFindArgs(whereOrParams) {
2409
+ const hasQueryKeys = typeof whereOrParams === "object" && whereOrParams !== null && FIND_QUERY_KEYS.some(
2410
+ (key) => Object.prototype.hasOwnProperty.call(whereOrParams, key)
2411
+ );
2412
+ const raw = hasQueryKeys ? { ...whereOrParams } : { where: whereOrParams };
2413
+ const returnMode = raw["return"] === "flat" ? "flat" : "envelope";
2414
+ delete raw["return"];
2415
+ return { returnMode, body: raw };
2416
+ }
2333
2417
  };
2334
2418
  var RagableBrowserDatabaseClient = class {
2335
2419
  constructor(options, ragableAuth = null) {
@@ -2923,7 +3007,10 @@ function createRagableServerClient(options) {
2923
3007
  ShiftClient,
2924
3008
  Transport,
2925
3009
  asPostgrestResponse,
3010
+ assertPostgrestSuccess,
2926
3011
  bindFetch,
3012
+ collectionRecordToRowWithMeta,
3013
+ collectionRecordsToRowWithMeta,
2927
3014
  createBrowserClient,
2928
3015
  createClient,
2929
3016
  createRagPipeline,
@@ -2939,6 +3026,8 @@ function createRagableServerClient(options) {
2939
3026
  normalizeBrowserApiBase,
2940
3027
  parseSseDataLine,
2941
3028
  parseTransportResponse,
2942
- readSseStream
3029
+ readSseStream,
3030
+ toRagableResult,
3031
+ unwrapPostgrest
2943
3032
  });
2944
3033
  //# sourceMappingURL=index.js.map