@ragable/sdk 0.6.19 → 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 +183 -42
- package/dist/index.d.ts +183 -42
- package/dist/index.js +123 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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 {
|
|
@@ -590,7 +610,18 @@ declare class AuthBroadcastChannel {
|
|
|
590
610
|
}
|
|
591
611
|
|
|
592
612
|
type AuthChangeEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
|
|
593
|
-
|
|
613
|
+
type AuthUserMetadata = Record<string, unknown>;
|
|
614
|
+
interface DefaultAuthUser<Metadata extends AuthUserMetadata = AuthUserMetadata> {
|
|
615
|
+
id: string;
|
|
616
|
+
email: string;
|
|
617
|
+
name: string | null;
|
|
618
|
+
status: "active" | "disabled" | (string & {});
|
|
619
|
+
metadata: Metadata;
|
|
620
|
+
createdAt?: string;
|
|
621
|
+
updatedAt?: string;
|
|
622
|
+
lastSignInAt?: string | null;
|
|
623
|
+
}
|
|
624
|
+
interface AuthSession<U extends object = DefaultAuthUser> {
|
|
594
625
|
access_token: string;
|
|
595
626
|
refresh_token: string;
|
|
596
627
|
expires_in: number;
|
|
@@ -612,12 +643,31 @@ interface RagableAuthConfig {
|
|
|
612
643
|
headers?: HeadersInit;
|
|
613
644
|
auth?: AuthOptions;
|
|
614
645
|
}
|
|
615
|
-
type
|
|
646
|
+
type AuthSignUpCredentials<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
|
|
647
|
+
email: string;
|
|
648
|
+
password: string;
|
|
649
|
+
options?: {
|
|
650
|
+
data?: Partial<Metadata> & {
|
|
651
|
+
name?: string | null;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
type AuthUpdateUserAttributes<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
|
|
656
|
+
email?: string;
|
|
657
|
+
password?: string;
|
|
658
|
+
data?: Partial<Metadata> & {
|
|
659
|
+
name?: string | null;
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
type MetadataForUser<U extends object> = U extends {
|
|
663
|
+
metadata: infer Metadata;
|
|
664
|
+
} ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata;
|
|
665
|
+
type AuthListener<U extends object> = (event: AuthChangeEvent, session: AuthSession<U> | null) => void;
|
|
616
666
|
interface Subscription {
|
|
617
667
|
id: string;
|
|
618
668
|
unsubscribe: () => void;
|
|
619
669
|
}
|
|
620
|
-
declare class RagableAuth<U extends
|
|
670
|
+
declare class RagableAuth<U extends object = DefaultAuthUser> {
|
|
621
671
|
private readonly fetchImpl;
|
|
622
672
|
private readonly baseUrl;
|
|
623
673
|
private readonly authGroupId;
|
|
@@ -638,13 +688,7 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
|
|
|
638
688
|
constructor(config: RagableAuthConfig);
|
|
639
689
|
private log;
|
|
640
690
|
initialize(): Promise<AuthSession<U> | null>;
|
|
641
|
-
signUp(credentials: {
|
|
642
|
-
email: string;
|
|
643
|
-
password: string;
|
|
644
|
-
options?: {
|
|
645
|
-
data?: Record<string, unknown>;
|
|
646
|
-
};
|
|
647
|
-
}): Promise<PostgrestResult<{
|
|
691
|
+
signUp(credentials: AuthSignUpCredentials<MetadataForUser<U>>): Promise<PostgrestResult<{
|
|
648
692
|
user: U;
|
|
649
693
|
session: AuthSession<U>;
|
|
650
694
|
}>>;
|
|
@@ -680,9 +724,9 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
|
|
|
680
724
|
updateUser(attributes: {
|
|
681
725
|
email?: string;
|
|
682
726
|
password?: string;
|
|
683
|
-
data?: {
|
|
727
|
+
data?: (Partial<MetadataForUser<U>> & {
|
|
684
728
|
name?: string | null;
|
|
685
|
-
};
|
|
729
|
+
});
|
|
686
730
|
}): Promise<PostgrestResult<{
|
|
687
731
|
user: U;
|
|
688
732
|
}>>;
|
|
@@ -692,11 +736,15 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
|
|
|
692
736
|
};
|
|
693
737
|
};
|
|
694
738
|
getAccessToken(): string | null;
|
|
739
|
+
getValidAccessToken(): Promise<string | null>;
|
|
695
740
|
getCurrentSession(): AuthSession<U> | null;
|
|
696
741
|
register(body: {
|
|
697
742
|
email: string;
|
|
698
743
|
password: string;
|
|
699
744
|
name?: string;
|
|
745
|
+
data?: Partial<MetadataForUser<U>> & {
|
|
746
|
+
name?: string | null;
|
|
747
|
+
};
|
|
700
748
|
}): Promise<{
|
|
701
749
|
user: U;
|
|
702
750
|
accessToken: string;
|
|
@@ -723,8 +771,12 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
|
|
|
723
771
|
user: U;
|
|
724
772
|
}>;
|
|
725
773
|
updateMe(body: {
|
|
774
|
+
email?: string;
|
|
726
775
|
name?: string | null;
|
|
727
776
|
password?: string;
|
|
777
|
+
data?: Partial<MetadataForUser<U>> & {
|
|
778
|
+
name?: string | null;
|
|
779
|
+
};
|
|
728
780
|
}): Promise<{
|
|
729
781
|
user: U;
|
|
730
782
|
}>;
|
|
@@ -817,7 +869,7 @@ interface RagableBrowserClientOptions {
|
|
|
817
869
|
auth?: AuthOptions;
|
|
818
870
|
transport?: Partial<TransportOptions>;
|
|
819
871
|
}
|
|
820
|
-
interface BrowserAuthSession<AuthUser extends
|
|
872
|
+
interface BrowserAuthSession<AuthUser extends object = DefaultAuthUser> {
|
|
821
873
|
user: AuthUser;
|
|
822
874
|
accessToken: string;
|
|
823
875
|
refreshToken: string;
|
|
@@ -828,7 +880,7 @@ interface BrowserAuthTokens {
|
|
|
828
880
|
refreshToken: string;
|
|
829
881
|
expiresIn: string;
|
|
830
882
|
}
|
|
831
|
-
interface SupabaseCompatSession<AuthUser extends
|
|
883
|
+
interface SupabaseCompatSession<AuthUser extends object = DefaultAuthUser> {
|
|
832
884
|
access_token: string;
|
|
833
885
|
refresh_token: string;
|
|
834
886
|
expires_in: number;
|
|
@@ -836,17 +888,13 @@ interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Recor
|
|
|
836
888
|
user: AuthUser;
|
|
837
889
|
}
|
|
838
890
|
|
|
839
|
-
declare class RagableBrowserAuthClient<AuthUser extends
|
|
891
|
+
declare class RagableBrowserAuthClient<AuthUser extends object = DefaultAuthUser> {
|
|
840
892
|
private readonly ragableAuth;
|
|
841
893
|
constructor(_options: RagableBrowserClientOptions, ragableAuth?: RagableAuth<AuthUser> | null);
|
|
842
894
|
private get auth();
|
|
843
|
-
signUp(credentials: {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
options?: {
|
|
847
|
-
data?: Record<string, unknown>;
|
|
848
|
-
};
|
|
849
|
-
}): Promise<PostgrestResult<{
|
|
895
|
+
signUp(credentials: AuthSignUpCredentials<AuthUser extends {
|
|
896
|
+
metadata: infer Metadata;
|
|
897
|
+
} ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
|
|
850
898
|
user: AuthUser;
|
|
851
899
|
session: SupabaseCompatSession<AuthUser>;
|
|
852
900
|
}>>;
|
|
@@ -864,13 +912,9 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
|
|
|
864
912
|
getUser(): Promise<PostgrestResult<{
|
|
865
913
|
user: AuthUser;
|
|
866
914
|
}>>;
|
|
867
|
-
updateUser(attributes: {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
data?: {
|
|
871
|
-
name?: string | null;
|
|
872
|
-
};
|
|
873
|
-
}): Promise<PostgrestResult<{
|
|
915
|
+
updateUser(attributes: AuthUpdateUserAttributes<AuthUser extends {
|
|
916
|
+
metadata: infer Metadata;
|
|
917
|
+
} ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
|
|
874
918
|
user: AuthUser;
|
|
875
919
|
}>>;
|
|
876
920
|
signOut(_options?: {
|
|
@@ -882,6 +926,11 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
|
|
|
882
926
|
email: string;
|
|
883
927
|
password: string;
|
|
884
928
|
name?: string;
|
|
929
|
+
data?: AuthUser extends {
|
|
930
|
+
metadata: infer Metadata;
|
|
931
|
+
} ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
|
|
932
|
+
name?: string | null;
|
|
933
|
+
} : Record<string, unknown> : Record<string, unknown>;
|
|
885
934
|
}): Promise<BrowserAuthSession<AuthUser>>;
|
|
886
935
|
login(body: {
|
|
887
936
|
email: string;
|
|
@@ -894,8 +943,14 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
|
|
|
894
943
|
user: AuthUser;
|
|
895
944
|
}>;
|
|
896
945
|
updateMe(body: {
|
|
946
|
+
email?: string;
|
|
897
947
|
name?: string | null;
|
|
898
948
|
password?: string;
|
|
949
|
+
data?: AuthUser extends {
|
|
950
|
+
metadata: infer Metadata;
|
|
951
|
+
} ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
|
|
952
|
+
name?: string | null;
|
|
953
|
+
} : Record<string, unknown> : Record<string, unknown>;
|
|
899
954
|
}): Promise<{
|
|
900
955
|
user: AuthUser;
|
|
901
956
|
}>;
|
|
@@ -956,7 +1011,34 @@ interface BrowserCollectionDefinition {
|
|
|
956
1011
|
createdAt: string;
|
|
957
1012
|
updatedAt: string;
|
|
958
1013
|
}
|
|
959
|
-
|
|
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>;
|
|
960
1042
|
type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
961
1043
|
[Field in Extract<keyof Row, string>]: {
|
|
962
1044
|
field: Field;
|
|
@@ -964,8 +1046,22 @@ type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
|
964
1046
|
value: Row[Field];
|
|
965
1047
|
};
|
|
966
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>[];
|
|
967
1063
|
type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
968
|
-
where?:
|
|
1064
|
+
where?: WhereInput<Row>;
|
|
969
1065
|
filters?: Array<{
|
|
970
1066
|
field: Extract<keyof Row, string> | (string & {});
|
|
971
1067
|
op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
|
|
@@ -973,24 +1069,69 @@ type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<st
|
|
|
973
1069
|
} | CollectionFilter<Row>>;
|
|
974
1070
|
limit?: number;
|
|
975
1071
|
offset?: number;
|
|
976
|
-
orderBy?: Extract<keyof Row, string> | (string & {});
|
|
1072
|
+
orderBy?: Extract<keyof Row, string> | "id" | "createdAt" | "updatedAt" | (string & {});
|
|
977
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;
|
|
978
1079
|
};
|
|
1080
|
+
type CollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
1081
|
+
type RowD<Row extends Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
979
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>> {
|
|
980
1083
|
private readonly database;
|
|
981
1084
|
private readonly name;
|
|
982
1085
|
private readonly databaseInstanceId?;
|
|
983
1086
|
constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
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?: {
|
|
987
1123
|
limit?: number;
|
|
988
|
-
}) => Promise<PostgrestResult<
|
|
989
|
-
|
|
1124
|
+
}) => Promise<PostgrestResult<{
|
|
1125
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
1126
|
+
meta: {
|
|
1127
|
+
count: number;
|
|
1128
|
+
};
|
|
1129
|
+
}>>;
|
|
1130
|
+
delete: (where: WhereInput<RowD<Row>>, options?: {
|
|
990
1131
|
limit?: number;
|
|
991
1132
|
}) => Promise<PostgrestResult<{
|
|
992
1133
|
deleted: number;
|
|
993
|
-
records: BrowserCollectionRecord<
|
|
1134
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
994
1135
|
}>>;
|
|
995
1136
|
}
|
|
996
1137
|
type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
|
|
@@ -1117,7 +1258,7 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
1117
1258
|
triggerSubtype?: string;
|
|
1118
1259
|
triggerNodeId?: string;
|
|
1119
1260
|
}
|
|
1120
|
-
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends
|
|
1261
|
+
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
|
|
1121
1262
|
readonly agents: RagableBrowserAgentsClient;
|
|
1122
1263
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
1123
1264
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
@@ -1129,7 +1270,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
1129
1270
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
1130
1271
|
destroy(): void;
|
|
1131
1272
|
}
|
|
1132
|
-
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends
|
|
1273
|
+
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1133
1274
|
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
1134
1275
|
|
|
1135
1276
|
/**
|
|
@@ -1204,7 +1345,7 @@ declare class Ragable {
|
|
|
1204
1345
|
constructor(options: RagableClientOptions);
|
|
1205
1346
|
}
|
|
1206
1347
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
1207
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends
|
|
1348
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1208
1349
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1209
1350
|
|
|
1210
|
-
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, 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 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();
|
|
@@ -1820,6 +1836,8 @@ var RagableAuth = class {
|
|
|
1820
1836
|
const refreshed = await this._doRefresh(session.refresh_token);
|
|
1821
1837
|
if (refreshed) {
|
|
1822
1838
|
this.currentSession = refreshed;
|
|
1839
|
+
} else {
|
|
1840
|
+
await this.storage.removeItem(this.storageKey);
|
|
1823
1841
|
}
|
|
1824
1842
|
}
|
|
1825
1843
|
}
|
|
@@ -1837,7 +1855,8 @@ var RagableAuth = class {
|
|
|
1837
1855
|
const raw = await this.fetchAuth("/register", "POST", {
|
|
1838
1856
|
email: credentials.email,
|
|
1839
1857
|
password: credentials.password,
|
|
1840
|
-
...name !== void 0 ? { name } : {}
|
|
1858
|
+
...name !== void 0 ? { name } : {},
|
|
1859
|
+
...credentials.options?.data !== void 0 ? { data: credentials.options.data } : {}
|
|
1841
1860
|
});
|
|
1842
1861
|
const session = this.rawToSession(raw);
|
|
1843
1862
|
await this.setSessionInternal(session, "SIGNED_IN");
|
|
@@ -1907,7 +1926,9 @@ var RagableAuth = class {
|
|
|
1907
1926
|
const token = this.currentSession?.access_token;
|
|
1908
1927
|
if (!token) throw new RagableError("Not authenticated", 401, null);
|
|
1909
1928
|
const result = await this.fetchAuthWithBearer("/me", "PATCH", token, {
|
|
1929
|
+
...attributes.email !== void 0 ? { email: attributes.email } : {},
|
|
1910
1930
|
...attributes.password !== void 0 ? { password: attributes.password } : {},
|
|
1931
|
+
...attributes.data !== void 0 ? { data: attributes.data } : {},
|
|
1911
1932
|
...attributes.data?.name !== void 0 ? { name: attributes.data.name } : {}
|
|
1912
1933
|
});
|
|
1913
1934
|
if (this.currentSession) {
|
|
@@ -1932,6 +1953,17 @@ var RagableAuth = class {
|
|
|
1932
1953
|
getAccessToken() {
|
|
1933
1954
|
return this.currentSession?.access_token ?? null;
|
|
1934
1955
|
}
|
|
1956
|
+
async getValidAccessToken() {
|
|
1957
|
+
if (!this.initialized) await this.initialize();
|
|
1958
|
+
const session = this.currentSession;
|
|
1959
|
+
if (!session) return null;
|
|
1960
|
+
const secondsUntilExpiry = session.expires_at - nowSeconds();
|
|
1961
|
+
if (secondsUntilExpiry <= this.refreshSkewSeconds) {
|
|
1962
|
+
const refreshed = await this.singleFlightRefresh(session.refresh_token);
|
|
1963
|
+
return refreshed?.access_token ?? null;
|
|
1964
|
+
}
|
|
1965
|
+
return session.access_token;
|
|
1966
|
+
}
|
|
1935
1967
|
getCurrentSession() {
|
|
1936
1968
|
return this.currentSession;
|
|
1937
1969
|
}
|
|
@@ -2145,7 +2177,7 @@ function requireAuthGroupId(options) {
|
|
|
2145
2177
|
}
|
|
2146
2178
|
async function requireAccessToken(options, ragableAuth) {
|
|
2147
2179
|
if (ragableAuth) {
|
|
2148
|
-
const token = ragableAuth.
|
|
2180
|
+
const token = await ragableAuth.getValidAccessToken();
|
|
2149
2181
|
if (token) return token;
|
|
2150
2182
|
}
|
|
2151
2183
|
const getter = options.getAccessToken;
|
|
@@ -2270,24 +2302,71 @@ var RagableBrowserAuthClient = class {
|
|
|
2270
2302
|
return this.auth.getSession();
|
|
2271
2303
|
}
|
|
2272
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
|
+
];
|
|
2273
2321
|
var BrowserCollectionApi = class {
|
|
2274
2322
|
constructor(database, name, databaseInstanceId) {
|
|
2275
2323
|
this.database = database;
|
|
2276
2324
|
this.name = name;
|
|
2277
2325
|
this.databaseInstanceId = databaseInstanceId;
|
|
2278
|
-
__publicField(this, "
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
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 });
|
|
2291
2370
|
});
|
|
2292
2371
|
__publicField(this, "insert", (data) => asPostgrestResponse(
|
|
2293
2372
|
() => this.database._requestCollection(
|
|
@@ -2297,6 +2376,9 @@ var BrowserCollectionApi = class {
|
|
|
2297
2376
|
this.databaseInstanceId
|
|
2298
2377
|
)
|
|
2299
2378
|
));
|
|
2379
|
+
/**
|
|
2380
|
+
* Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
|
|
2381
|
+
*/
|
|
2300
2382
|
__publicField(this, "update", (where, patch, options) => asPostgrestResponse(
|
|
2301
2383
|
() => this.database._requestCollection(
|
|
2302
2384
|
"PATCH",
|
|
@@ -2305,6 +2387,15 @@ var BrowserCollectionApi = class {
|
|
|
2305
2387
|
this.databaseInstanceId
|
|
2306
2388
|
)
|
|
2307
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
|
+
});
|
|
2308
2399
|
__publicField(this, "delete", (where, options) => asPostgrestResponse(
|
|
2309
2400
|
() => this.database._requestCollection(
|
|
2310
2401
|
"DELETE",
|
|
@@ -2314,6 +2405,15 @@ var BrowserCollectionApi = class {
|
|
|
2314
2405
|
)
|
|
2315
2406
|
));
|
|
2316
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
|
+
}
|
|
2317
2417
|
};
|
|
2318
2418
|
var RagableBrowserDatabaseClient = class {
|
|
2319
2419
|
constructor(options, ragableAuth = null) {
|
|
@@ -2764,10 +2864,7 @@ var RagableBrowser = class {
|
|
|
2764
2864
|
});
|
|
2765
2865
|
this.transport.setRefreshHandler(async () => {
|
|
2766
2866
|
if (effectiveDataAuth(options) !== "user") return null;
|
|
2767
|
-
|
|
2768
|
-
this._ragableAuth.getCurrentSession()?.refresh_token ?? ""
|
|
2769
|
-
);
|
|
2770
|
-
return session?.access_token ?? null;
|
|
2867
|
+
return this._ragableAuth.getValidAccessToken();
|
|
2771
2868
|
});
|
|
2772
2869
|
if (!options.getAccessToken && effectiveDataAuth(options) === "user") {
|
|
2773
2870
|
this._ragableAuth.initialize().catch(() => {
|
|
@@ -2910,7 +3007,10 @@ function createRagableServerClient(options) {
|
|
|
2910
3007
|
ShiftClient,
|
|
2911
3008
|
Transport,
|
|
2912
3009
|
asPostgrestResponse,
|
|
3010
|
+
assertPostgrestSuccess,
|
|
2913
3011
|
bindFetch,
|
|
3012
|
+
collectionRecordToRowWithMeta,
|
|
3013
|
+
collectionRecordsToRowWithMeta,
|
|
2914
3014
|
createBrowserClient,
|
|
2915
3015
|
createClient,
|
|
2916
3016
|
createRagPipeline,
|
|
@@ -2926,6 +3026,8 @@ function createRagableServerClient(options) {
|
|
|
2926
3026
|
normalizeBrowserApiBase,
|
|
2927
3027
|
parseSseDataLine,
|
|
2928
3028
|
parseTransportResponse,
|
|
2929
|
-
readSseStream
|
|
3029
|
+
readSseStream,
|
|
3030
|
+
toRagableResult,
|
|
3031
|
+
unwrapPostgrest
|
|
2930
3032
|
});
|
|
2931
3033
|
//# sourceMappingURL=index.js.map
|