@motherbase/client 2.2.1 → 2.2.4

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.
Files changed (222) hide show
  1. package/COMPATIBILITY.md +157 -0
  2. package/LICENSE +21 -21
  3. package/README.md +52 -4
  4. package/dist/admin/auth-admin-client.d.ts +43 -0
  5. package/dist/admin/auth-admin-client.d.ts.map +1 -0
  6. package/dist/admin/auth-admin-client.js +62 -0
  7. package/dist/admin/auth-admin-client.js.map +1 -0
  8. package/dist/admin/auth-admin-mfa-client.d.ts +22 -0
  9. package/dist/admin/auth-admin-mfa-client.d.ts.map +1 -0
  10. package/dist/admin/auth-admin-mfa-client.js +17 -0
  11. package/dist/admin/auth-admin-mfa-client.js.map +1 -0
  12. package/dist/admin/types.d.ts +85 -0
  13. package/dist/admin/types.d.ts.map +1 -0
  14. package/dist/admin/types.js +3 -0
  15. package/dist/admin/types.js.map +1 -0
  16. package/dist/auth/constants.d.ts +21 -0
  17. package/dist/auth/constants.d.ts.map +1 -0
  18. package/dist/auth/constants.js +34 -0
  19. package/dist/auth/constants.js.map +1 -0
  20. package/dist/auth/index.d.ts +5 -0
  21. package/dist/auth/index.d.ts.map +1 -0
  22. package/dist/auth/index.js +34 -0
  23. package/dist/auth/index.js.map +1 -0
  24. package/dist/auth/motherbase-plugin.d.ts +6 -0
  25. package/dist/auth/motherbase-plugin.d.ts.map +1 -0
  26. package/dist/auth/motherbase-plugin.js +80 -0
  27. package/dist/auth/motherbase-plugin.js.map +1 -0
  28. package/dist/auth/pkce.d.ts +19 -0
  29. package/dist/auth/pkce.d.ts.map +1 -0
  30. package/dist/auth/pkce.js +89 -0
  31. package/dist/auth/pkce.js.map +1 -0
  32. package/dist/auth/session-utils.d.ts +29 -0
  33. package/dist/auth/session-utils.d.ts.map +1 -0
  34. package/dist/auth/session-utils.js +123 -0
  35. package/dist/auth/session-utils.js.map +1 -0
  36. package/dist/auth/session.d.ts +51 -0
  37. package/dist/auth/session.d.ts.map +1 -0
  38. package/dist/auth/session.js +161 -0
  39. package/dist/auth/session.js.map +1 -0
  40. package/dist/auth/types.d.ts +341 -0
  41. package/dist/auth/types.d.ts.map +1 -0
  42. package/dist/auth/types.js +2 -0
  43. package/dist/auth/types.js.map +1 -0
  44. package/dist/auth/utils.d.ts +28 -0
  45. package/dist/auth/utils.d.ts.map +1 -0
  46. package/dist/auth/utils.js +70 -0
  47. package/dist/auth/utils.js.map +1 -0
  48. package/dist/auth.d.ts +3 -2
  49. package/dist/auth.d.ts.map +1 -1
  50. package/dist/auth.js +27 -11
  51. package/dist/auth.js.map +1 -1
  52. package/dist/channel.d.ts +11 -0
  53. package/dist/channel.d.ts.map +1 -1
  54. package/dist/channel.js +26 -2
  55. package/dist/channel.js.map +1 -1
  56. package/dist/cookies/cookie-storage.d.ts +12 -0
  57. package/dist/cookies/cookie-storage.d.ts.map +1 -0
  58. package/dist/cookies/cookie-storage.js +35 -0
  59. package/dist/cookies/cookie-storage.js.map +1 -0
  60. package/dist/cookies/index.d.ts +5 -0
  61. package/dist/cookies/index.d.ts.map +1 -0
  62. package/dist/cookies/index.js +5 -0
  63. package/dist/cookies/index.js.map +1 -0
  64. package/dist/cookies/server-cookie-storage.d.ts +20 -0
  65. package/dist/cookies/server-cookie-storage.d.ts.map +1 -0
  66. package/dist/cookies/server-cookie-storage.js +60 -0
  67. package/dist/cookies/server-cookie-storage.js.map +1 -0
  68. package/dist/cookies/types.d.ts +33 -0
  69. package/dist/cookies/types.d.ts.map +1 -0
  70. package/dist/cookies/types.js +8 -0
  71. package/dist/cookies/types.js.map +1 -0
  72. package/dist/cookies/utils.d.ts +23 -0
  73. package/dist/cookies/utils.d.ts.map +1 -0
  74. package/dist/cookies/utils.js +67 -0
  75. package/dist/cookies/utils.js.map +1 -0
  76. package/dist/database/database.d.ts +197 -0
  77. package/dist/database/database.d.ts.map +1 -0
  78. package/dist/database/database.js +2 -0
  79. package/dist/database/database.js.map +1 -0
  80. package/dist/database/facade.d.ts +218 -0
  81. package/dist/database/facade.d.ts.map +1 -0
  82. package/dist/database/facade.js +198 -0
  83. package/dist/database/facade.js.map +1 -0
  84. package/dist/database/query.d.ts +97 -0
  85. package/dist/database/query.d.ts.map +1 -0
  86. package/dist/database/query.js +94 -0
  87. package/dist/database/query.js.map +1 -0
  88. package/dist/database/types.d.ts +314 -0
  89. package/dist/database/types.d.ts.map +1 -0
  90. package/dist/database/types.js +2 -0
  91. package/dist/database/types.js.map +1 -0
  92. package/dist/functions/errors.d.ts +28 -0
  93. package/dist/functions/errors.d.ts.map +1 -0
  94. package/dist/functions/errors.js +37 -0
  95. package/dist/functions/errors.js.map +1 -0
  96. package/dist/functions/index.d.ts +9 -0
  97. package/dist/functions/index.d.ts.map +1 -0
  98. package/dist/functions/index.js +40 -0
  99. package/dist/functions/index.js.map +1 -0
  100. package/dist/functions/types.d.ts +25 -0
  101. package/dist/functions/types.d.ts.map +1 -0
  102. package/dist/functions/types.js +2 -0
  103. package/dist/functions/types.js.map +1 -0
  104. package/dist/http/backend-error.d.ts +17 -0
  105. package/dist/http/backend-error.d.ts.map +1 -0
  106. package/dist/http/backend-error.js +11 -0
  107. package/dist/http/backend-error.js.map +1 -0
  108. package/dist/http/index.d.ts +59 -0
  109. package/dist/http/index.d.ts.map +1 -0
  110. package/dist/http/index.js +175 -0
  111. package/dist/http/index.js.map +1 -0
  112. package/dist/http/types.d.ts +45 -0
  113. package/dist/http/types.d.ts.map +1 -0
  114. package/dist/http/types.js +2 -0
  115. package/dist/http/types.js.map +1 -0
  116. package/dist/http/utils.d.ts +14 -0
  117. package/dist/http/utils.d.ts.map +1 -0
  118. package/dist/http/utils.js +37 -0
  119. package/dist/http/utils.js.map +1 -0
  120. package/dist/http.d.ts.map +1 -1
  121. package/dist/http.js +2 -1
  122. package/dist/http.js.map +1 -1
  123. package/dist/index.d.ts +47 -77
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +58 -73
  126. package/dist/index.js.map +1 -1
  127. package/dist/pkce.js +4 -4
  128. package/dist/postgrest/index.d.ts +4 -0
  129. package/dist/postgrest/index.d.ts.map +1 -0
  130. package/dist/postgrest/index.js +4 -0
  131. package/dist/postgrest/index.js.map +1 -0
  132. package/dist/postgrest/query-builder.d.ts +224 -0
  133. package/dist/postgrest/query-builder.d.ts.map +1 -0
  134. package/dist/postgrest/query-builder.js +544 -0
  135. package/dist/postgrest/query-builder.js.map +1 -0
  136. package/dist/postgrest/rpc.d.ts +12 -0
  137. package/dist/postgrest/rpc.d.ts.map +1 -0
  138. package/dist/postgrest/rpc.js +42 -0
  139. package/dist/postgrest/rpc.js.map +1 -0
  140. package/dist/postgrest/types.d.ts +88 -0
  141. package/dist/postgrest/types.d.ts.map +1 -0
  142. package/dist/postgrest/types.js +2 -0
  143. package/dist/postgrest/types.js.map +1 -0
  144. package/dist/postgrest/utils.d.ts +23 -0
  145. package/dist/postgrest/utils.d.ts.map +1 -0
  146. package/dist/postgrest/utils.js +87 -0
  147. package/dist/postgrest/utils.js.map +1 -0
  148. package/dist/postgrest.d.ts +5 -1
  149. package/dist/postgrest.d.ts.map +1 -1
  150. package/dist/postgrest.js +17 -10
  151. package/dist/postgrest.js.map +1 -1
  152. package/dist/realtime/channel.d.ts +83 -0
  153. package/dist/realtime/channel.d.ts.map +1 -0
  154. package/dist/realtime/channel.js +240 -0
  155. package/dist/realtime/channel.js.map +1 -0
  156. package/dist/realtime/index.d.ts +94 -0
  157. package/dist/realtime/index.d.ts.map +1 -0
  158. package/dist/realtime/index.js +455 -0
  159. package/dist/realtime/index.js.map +1 -0
  160. package/dist/realtime/types.d.ts +120 -0
  161. package/dist/realtime/types.d.ts.map +1 -0
  162. package/dist/realtime/types.js +2 -0
  163. package/dist/realtime/types.js.map +1 -0
  164. package/dist/realtime.d.ts +1 -0
  165. package/dist/realtime.d.ts.map +1 -1
  166. package/dist/realtime.js +26 -1
  167. package/dist/realtime.js.map +1 -1
  168. package/dist/runtime.d.ts +13 -0
  169. package/dist/runtime.d.ts.map +1 -0
  170. package/dist/runtime.js +15 -0
  171. package/dist/runtime.js.map +1 -0
  172. package/dist/session.d.ts +2 -0
  173. package/dist/session.d.ts.map +1 -1
  174. package/dist/session.js +11 -2
  175. package/dist/session.js.map +1 -1
  176. package/dist/storage/bucket.d.ts +166 -0
  177. package/dist/storage/bucket.d.ts.map +1 -0
  178. package/dist/storage/bucket.js +294 -0
  179. package/dist/storage/bucket.js.map +1 -0
  180. package/dist/storage/index.d.ts +45 -0
  181. package/dist/storage/index.d.ts.map +1 -0
  182. package/dist/storage/index.js +55 -0
  183. package/dist/storage/index.js.map +1 -0
  184. package/dist/storage/types.d.ts +131 -0
  185. package/dist/storage/types.d.ts.map +1 -0
  186. package/dist/storage/types.js +2 -0
  187. package/dist/storage/types.js.map +1 -0
  188. package/dist/storage/utils.d.ts +27 -0
  189. package/dist/storage/utils.d.ts.map +1 -0
  190. package/dist/storage/utils.js +43 -0
  191. package/dist/storage/utils.js.map +1 -0
  192. package/dist/test.d.ts +2 -0
  193. package/dist/test.d.ts.map +1 -0
  194. package/dist/test.js +3 -0
  195. package/dist/test.js.map +1 -0
  196. package/dist/types.d.ts +14 -249
  197. package/dist/types.d.ts.map +1 -1
  198. package/dist/utils/compat.d.ts +40 -0
  199. package/dist/utils/compat.d.ts.map +1 -0
  200. package/dist/utils/compat.js +100 -0
  201. package/dist/utils/compat.js.map +1 -0
  202. package/dist/utils/runtime.d.ts +13 -0
  203. package/dist/utils/runtime.d.ts.map +1 -0
  204. package/dist/utils/runtime.js +15 -0
  205. package/dist/utils/runtime.js.map +1 -0
  206. package/dist/utils/testing.d.ts +38 -0
  207. package/dist/utils/testing.d.ts.map +1 -0
  208. package/dist/utils/testing.js +50 -0
  209. package/dist/utils/testing.js.map +1 -0
  210. package/dist/utils/warn.d.ts +2 -0
  211. package/dist/utils/warn.d.ts.map +1 -0
  212. package/dist/utils/warn.js +23 -0
  213. package/dist/utils/warn.js.map +1 -0
  214. package/package.json +13 -11
  215. package/dist/devices.d.ts +0 -13
  216. package/dist/devices.d.ts.map +0 -1
  217. package/dist/devices.js +0 -13
  218. package/dist/devices.js.map +0 -1
  219. package/dist/profile.d.ts +0 -16
  220. package/dist/profile.d.ts.map +0 -1
  221. package/dist/profile.js +0 -26
  222. package/dist/profile.js.map +0 -1
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Type-level plumbing for `createClient<Database>(url, key)`.
3
+ *
4
+ * `Database` is the type generated by `motherbase gen types typescript`, which
5
+ * emits the exact shape supabase-js emits. Everything here reads that shape and
6
+ * nothing else, so a `database.types.ts` produced by Supabase's own generator
7
+ * works unchanged.
8
+ *
9
+ * This file is types only: it contains no runtime code. The query builder it
10
+ * describes is the existing `PostgrestQueryBuilder`; `MotherbaseClient.from()`
11
+ * hands back the same object viewed through this narrower interface.
12
+ */
13
+ import type { ExplainOptions, InsertOptions, MutateOptions, OrderOptions, PaginateOptions, PostgrestArrayOperand, PostgrestExplainBuilder, PostgrestFilterOperator, PostgrestIsValue, PostgrestResponse, PostgrestTextBuilder, ReferencedTableOption, RpcOptions, SelectOptions, TextSearchType, UpsertOptions } from '../postgrest/index.js';
14
+ export interface GenericTable {
15
+ Row: Record<string, unknown>;
16
+ Insert: Record<string, unknown>;
17
+ Update: Record<string, unknown>;
18
+ Relationships?: unknown;
19
+ }
20
+ export interface GenericView {
21
+ Row: Record<string, unknown>;
22
+ Relationships?: unknown;
23
+ }
24
+ export interface GenericFunction {
25
+ Args: Record<string, unknown>;
26
+ Returns: unknown;
27
+ }
28
+ export interface GenericSchema {
29
+ Tables: Record<string, GenericTable>;
30
+ Views: Record<string, GenericView>;
31
+ Functions: Record<string, GenericFunction>;
32
+ Enums?: Record<string, unknown>;
33
+ CompositeTypes?: Record<string, unknown>;
34
+ }
35
+ /**
36
+ * The default when no `Database` is supplied. Every relation name is accepted
37
+ * and every row is `Record<string, unknown>`, which is exactly how the SDK
38
+ * behaved before generics existed. Passing a generated `Database` is opt-in.
39
+ */
40
+ export type GenericDatabase = Record<string, GenericSchema>;
41
+ /**
42
+ * The schema a client reads by default. `public` when the database has one,
43
+ * otherwise whatever single schema was generated: `motherbase gen types
44
+ * typescript --schema shop` emits only `shop`, and requiring every call site to
45
+ * pass the name again would be pure friction.
46
+ */
47
+ export type DefaultSchemaName<Database> = 'public' extends keyof Database ? 'public' : keyof Database;
48
+ export type SchemaOf<Database, Name> = Name extends keyof Database ? Database[Name] extends GenericSchema ? Database[Name] : GenericSchema : GenericSchema;
49
+ /** Tables and views together: both are selectable through `.from()`. */
50
+ export type Relations<Schema extends GenericSchema> = Schema['Tables'] & Schema['Views'];
51
+ export type RelationName<Schema extends GenericSchema> = string & keyof Relations<Schema>;
52
+ export type RowOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Relations<Schema>[Name] extends {
53
+ Row: infer R;
54
+ } ? R : never;
55
+ export type InsertOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Name extends keyof Schema['Tables'] ? Schema['Tables'][Name] extends {
56
+ Insert: infer I;
57
+ } ? I : never : never;
58
+ export type UpdateOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Name extends keyof Schema['Tables'] ? Schema['Tables'][Name] extends {
59
+ Update: infer U;
60
+ } ? U : never : never;
61
+ export type FunctionName<Schema extends GenericSchema> = string & keyof Schema['Functions'];
62
+ export type FunctionArgs<Schema extends GenericSchema, Name extends FunctionName<Schema>> = Schema['Functions'][Name] extends {
63
+ Args: infer A;
64
+ } ? A : never;
65
+ export type FunctionReturns<Schema extends GenericSchema, Name extends FunctionName<Schema>> = Schema['Functions'][Name] extends {
66
+ Returns: infer R;
67
+ } ? R : never;
68
+ type Trim<S extends string> = S extends ` ${infer Rest}` ? Trim<Rest> : S extends `${infer Rest} ` ? Trim<Rest> : S;
69
+ /** `'id, name'` -> `'id' | 'name'`. */
70
+ type SplitColumns<S extends string> = S extends `${infer Head},${infer Tail}` ? Trim<Head> | SplitColumns<Tail> : Trim<S>;
71
+ /** `'created_at::text'` -> `'created_at'`. Casts change the wire type, not the source column. */
72
+ type StripCast<S extends string> = S extends `${infer Column}::${string}` ? Column : S;
73
+ type AliasPart<S extends string> = S extends `${infer Alias}:${string}` ? Alias : S;
74
+ type ColumnPart<S extends string> = S extends `${string}:${infer Column}` ? Column : S;
75
+ /** `'writer:author_id'` -> `'writer'` (the key the row will carry). */
76
+ type OutputName<S extends string> = AliasPart<StripCast<S>>;
77
+ /** `'writer:author_id'` -> `'author_id'` (the column the type comes from). */
78
+ type SourceName<S extends string> = ColumnPart<StripCast<S>>;
79
+ /**
80
+ * SEAM: relational embedding (`select=*,author(*)`) is not implemented on the
81
+ * server yet, so a select string containing a parenthesised relation is not
82
+ * narrowed. It resolves to the base row plus an open index signature, which
83
+ * types the columns we do know and leaves the embedded keys accessible without
84
+ * pretending we know their shape.
85
+ *
86
+ * When embedding lands, replace this with a resolver that walks
87
+ * `Relationships` to decide object vs array and recurse into the target row.
88
+ */
89
+ export type EmbeddedSelectSeam<Row> = Row & Record<string, unknown>;
90
+ type IsEmbeddedSelect<S extends string> = S extends `${string}(${string}` ? true : false;
91
+ /** Columns named in the select string that the relation does not have. */
92
+ export type UnknownSelectColumns<Row, S extends string> = Exclude<SourceName<SplitColumns<S>>, (keyof Row & string) | '*'>;
93
+ /**
94
+ * The `columns` argument type. Resolves to `unknown` (no extra constraint) when
95
+ * every named column exists, and to an error-message string literal otherwise,
96
+ * so a typo fails at the call site with the offending name in the message.
97
+ */
98
+ export type ValidateSelect<Row, S extends string> = IsEmbeddedSelect<S> extends true ? unknown : [UnknownSelectColumns<Row, S>] extends [never] ? unknown : `Unknown column in select: ${UnknownSelectColumns<Row, S> & string}`;
99
+ /** The row shape a select resolves to. */
100
+ export type SelectResult<Row, S extends string> = IsEmbeddedSelect<S> extends true ? EmbeddedSelectSeam<Row> : '*' extends SplitColumns<S> ? Row : {
101
+ [K in SplitColumns<S> as OutputName<K>]: Row[SourceName<K> & keyof Row];
102
+ };
103
+ export type FilterValue = string | number | boolean | null;
104
+ /** A write without `.select()` stays `null` through re-typing and `.single()`. */
105
+ type RowsUnlessWrite<Data, Rows> = Data extends null ? null : Rows;
106
+ /** Columns that can be filtered or ordered on. Any string when untyped. */
107
+ export type ColumnName<Row> = keyof Row & string;
108
+ /**
109
+ * The `.from()` result. Structurally the existing `PostgrestQueryBuilder`, with
110
+ * the generated row/insert/update types threaded through. `Result` tracks what
111
+ * the current `select` narrowed the row to; it starts as the full row.
112
+ *
113
+ * `Data` is what awaiting resolves to. A write is sent with `return=minimal`
114
+ * and resolves `data: null` until `.select()` asks for the rows back, as in
115
+ * supabase-js; typing it as rows let `data.id` after a bare `insert()` compile
116
+ * and fail at runtime.
117
+ */
118
+ export interface TypedQuery<Row, Insert, Update, Result = Row, Data = Result[]> extends PromiseLike<PostgrestResponse<Data>> {
119
+ /**
120
+ * Choose the columns to read, as a PostgREST select string. The result type
121
+ * narrows to those columns. After a write (`insert`, `update`, ...), asks for
122
+ * the written rows back: without it a write resolves `data: null`.
123
+ *
124
+ * @param columns Comma-separated columns, `*` for all. Supports aliases
125
+ * (`label:name`) and embedded relations (`author(name)`).
126
+ * @param options `count: 'exact' | 'planned' | 'estimated'` puts a total in
127
+ * `count`; `head: true` returns only that count, without rows.
128
+ * @example client.from('posts').select('id, title, author(name)')
129
+ */
130
+ select<S extends string = '*'>(columns?: S & ValidateSelect<Row, S>, options?: SelectOptions): TypedQuery<Row, Insert, Update, SelectResult<Row, S>>;
131
+ /**
132
+ * Insert one row or several. Resolves `data: null` unless followed by
133
+ * `.select()`.
134
+ * @example client.from('posts').insert({ title }).select().single()
135
+ */
136
+ insert(values: Insert | readonly Insert[], options?: InsertOptions): TypedQuery<Row, Insert, Update, Result, null>;
137
+ /**
138
+ * Insert, or update the row that already has the same primary key (or the
139
+ * same values in the `onConflict` columns). `ignoreDuplicates: true` skips
140
+ * that row instead of updating it.
141
+ */
142
+ upsert(values: Insert | readonly Insert[], options?: UpsertOptions): TypedQuery<Row, Insert, Update, Result, null>;
143
+ /**
144
+ * Update the rows matched by the filters that follow. A filter is required:
145
+ * the server refuses an update of the whole table.
146
+ * @example client.from('posts').update({ title }).eq('id', id)
147
+ */
148
+ update(values: Update, options?: MutateOptions): TypedQuery<Row, Insert, Update, Result, null>;
149
+ /**
150
+ * Delete the rows matched by the filters that follow. A filter is required:
151
+ * the server refuses a delete of the whole table.
152
+ * @example client.from('posts').delete().eq('id', id)
153
+ */
154
+ delete(options?: MutateOptions): TypedQuery<Row, Insert, Update, Result, null>;
155
+ /** Rows where `column` equals `value`. Test NULL with `is(column, null)`. */
156
+ eq(column: ColumnName<Row>, value: FilterValue): this;
157
+ /** Rows where `column` differs from `value`. */
158
+ neq(column: ColumnName<Row>, value: FilterValue): this;
159
+ /** Rows where `column` is greater than `value`. */
160
+ gt(column: ColumnName<Row>, value: FilterValue): this;
161
+ /** Rows where `column` is greater than or equal to `value`. */
162
+ gte(column: ColumnName<Row>, value: FilterValue): this;
163
+ /** Rows where `column` is less than `value`. */
164
+ lt(column: ColumnName<Row>, value: FilterValue): this;
165
+ /** Rows where `column` is less than or equal to `value`. */
166
+ lte(column: ColumnName<Row>, value: FilterValue): this;
167
+ /** Case-sensitive pattern match. `%` (or `*`) matches any run of characters. */
168
+ like(column: ColumnName<Row>, pattern: string): this;
169
+ /** Case-insensitive pattern match. `%` (or `*`) matches any run of characters. */
170
+ ilike(column: ColumnName<Row>, pattern: string): this;
171
+ /** Rows where `column` matches every pattern (case-sensitive). */
172
+ likeAllOf(column: ColumnName<Row>, patterns: readonly string[]): this;
173
+ /** Rows where `column` matches at least one pattern (case-sensitive). */
174
+ likeAnyOf(column: ColumnName<Row>, patterns: readonly string[]): this;
175
+ /** Rows where `column` matches every pattern (case-insensitive). */
176
+ ilikeAllOf(column: ColumnName<Row>, patterns: readonly string[]): this;
177
+ /** Rows where `column` matches at least one pattern (case-insensitive). */
178
+ ilikeAnyOf(column: ColumnName<Row>, patterns: readonly string[]): this;
179
+ /** Rows where `column` is one of `values`. */
180
+ in(column: ColumnName<Row>, values: readonly FilterValue[]): this;
181
+ /** Rows where `column` IS `null`, `true`, `false` or `unknown`: the way to test NULL. */
182
+ is(column: ColumnName<Row>, value: PostgrestIsValue): this;
183
+ /** One `eq()` per key, ANDed: `match({ status: 'live', owner_id: id })`. */
184
+ match(query: Partial<Record<ColumnName<Row>, FilterValue>>): this;
185
+ /**
186
+ * Negate a filter: `not('status', 'eq', 'draft')`. The column is a free
187
+ * string, so json paths (`data->>k`) work.
188
+ */
189
+ not(column: string, operator: PostgrestFilterOperator | (string & {}), value: FilterValue | readonly FilterValue[]): this;
190
+ /**
191
+ * Any PostgREST operator by name, for those without a dedicated method:
192
+ * `filter('price', 'isdistinct', null)`. The column is a free string, so json
193
+ * paths (`data->>k`) work.
194
+ */
195
+ filter(column: string, operator: PostgrestFilterOperator | (string & {}), value: FilterValue | readonly FilterValue[]): this;
196
+ /**
197
+ * Rows matching at least one condition, in PostgREST syntax. Nests with
198
+ * `and(...)`: `or('status.eq.live,and(price.gt.10,stock.gt.0)')`.
199
+ */
200
+ or(filters: string, options?: ReferencedTableOption): this;
201
+ /**
202
+ * Full-text search on a `tsvector` (or text) column.
203
+ * @param options `type`: `'plain'`, `'phrase'` or `'websearch'` (search-engine
204
+ * syntax); `config`: the text search language, e.g. `'english'`.
205
+ */
206
+ textSearch(column: ColumnName<Row>, query: string, options?: {
207
+ type?: TextSearchType;
208
+ config?: string;
209
+ }): this;
210
+ /** Array, range or jsonb `column` contains every element of `value` (`@>`). */
211
+ contains(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
212
+ /** Every element of array, range or jsonb `column` is in `value` (`<@`). */
213
+ containedBy(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
214
+ /** Array or range `column` shares at least one element with `value` (`&&`). */
215
+ overlaps(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
216
+ /** Range `column` is entirely after `range`. */
217
+ rangeGt(column: ColumnName<Row>, range: string): this;
218
+ /** Range `column` does not extend before `range`. */
219
+ rangeGte(column: ColumnName<Row>, range: string): this;
220
+ /** Range `column` is entirely before `range`. */
221
+ rangeLt(column: ColumnName<Row>, range: string): this;
222
+ /** Range `column` does not extend after `range`. */
223
+ rangeLte(column: ColumnName<Row>, range: string): this;
224
+ /** Range `column` touches `range` without overlapping it. */
225
+ rangeAdjacent(column: ColumnName<Row>, range: string): this;
226
+ /**
227
+ * Sort by `column`, ascending unless `ascending: false`. Call again for a
228
+ * secondary sort. `referencedTable` sorts the rows of an embedded relation.
229
+ */
230
+ order(column: ColumnName<Row>, options?: OrderOptions): this;
231
+ /** Return at most `count` rows. */
232
+ limit(count: number, options?: ReferencedTableOption): this;
233
+ /**
234
+ * Return rows `from` to `to`, zero-based and both inclusive: `range(0, 9)` is
235
+ * the first 10. The way to paginate.
236
+ */
237
+ range(from: number, to: number, options?: ReferencedTableOption): this;
238
+ /** Cancel the request when `signal` aborts. */
239
+ abortSignal(signal: AbortSignal): this;
240
+ /** Send one more header with this request only, e.g. `x-captcha-response`. */
241
+ setHeader(name: string, value: string): this;
242
+ /** Re-type the rows: for shapes the generated `Database` cannot express. */
243
+ returns<T>(): TypedQuery<Row, Insert, Update, T, RowsUnlessWrite<Data, T[]>>;
244
+ /** `returns<T>()` under supabase-js's newer name. */
245
+ overrideTypes<T>(): TypedQuery<Row, Insert, Update, T, RowsUnlessWrite<Data, T[]>>;
246
+ /** Reject instead of resolving `{ data: null, error }`, for try/catch code. */
247
+ throwOnError(): this;
248
+ /** Refuse the write if it would touch more than `count` rows: a net under a wrong filter. */
249
+ maxAffected(count: number): this;
250
+ /** Run the query, then roll the transaction back: a dry run of a write. */
251
+ rollback(): this;
252
+ /** Resolve the rows as one CSV string instead of objects. */
253
+ csv(): PostgrestTextBuilder;
254
+ /** Resolve the rows as a GeoJSON FeatureCollection, for PostGIS tables. */
255
+ geojson(): PostgrestExplainBuilder;
256
+ /** Resolve the Postgres query plan instead of the rows. Admin callers only. */
257
+ explain(options?: ExplainOptions): PostgrestExplainBuilder;
258
+ /**
259
+ * Walk every matching row instead of stopping at the server's row cap.
260
+ * Throws on error: a `for await` loop has nowhere to put an error value, and
261
+ * ending the iteration quietly looks exactly like reaching the last page.
262
+ * @example for await (const row of client.from('events').select('*').stream()) { ... }
263
+ */
264
+ stream(options?: PaginateOptions): AsyncGenerator<Result, void, undefined>;
265
+ /**
266
+ * `stream()` a page at a time, with the total in `count` when the server
267
+ * reports one. Throws on error.
268
+ */
269
+ paginate(options?: PaginateOptions): AsyncGenerator<{
270
+ rows: Result[];
271
+ from: number;
272
+ count: number | null;
273
+ }, void, undefined>;
274
+ /** Resolve one row instead of an array. Fails unless exactly one row matches. */
275
+ single(): TypedSingleQuery<RowsUnlessWrite<Data, Result>>;
276
+ /** Resolve one row, or `null` when none matches. Fails if several match. */
277
+ maybeSingle(): TypedSingleQuery<RowsUnlessWrite<Data, Result | null>>;
278
+ /** The URL path (with query string) this builder targets. Exposed for tests. */
279
+ toPath(): string;
280
+ /** The headers this builder sends (Prefer, Accept). Exposed for tests. */
281
+ toHeaders(): Record<string, string>;
282
+ }
283
+ /** A builder narrowed to one row by `.single()` / `.maybeSingle()`. */
284
+ export interface TypedSingleQuery<Result> extends PromiseLike<PostgrestResponse<Result>> {
285
+ toPath(): string;
286
+ toHeaders(): Record<string, string>;
287
+ }
288
+ /**
289
+ * What the `client.transaction()` callback is handed.
290
+ *
291
+ * Typed loosely on purpose: the relation names come from the generated
292
+ * `Database` on `client.from()`, and reproducing that overload pair here for a
293
+ * callback that returns nothing buys inference no one reads at the cost of a
294
+ * signature nobody can follow.
295
+ */
296
+ export interface TransactionContext {
297
+ from<Row extends object = Record<string, unknown>>(table: string): TypedQuery<Row, Partial<Row>, Partial<Row>>;
298
+ }
299
+ /**
300
+ * What `client.schema(name)` returns for a schema other than `public`: its
301
+ * functions, called with the profile header PostgREST reads, so
302
+ * `client.schema('pgmq_public').rpc('send', { queue_name, message })` reaches
303
+ * Supabase Queues exactly as it does on Supabase.
304
+ *
305
+ * `from()` is here only to fail with the reason: the REST layer serves tables
306
+ * from `public` alone, and a ported call should say so rather than being
307
+ * "not a function".
308
+ */
309
+ export interface SchemaClient<Schema extends GenericSchema = GenericSchema> {
310
+ rpc<Name extends FunctionName<Schema>>(fn: Name, args?: FunctionArgs<Schema, Name>, options?: RpcOptions): Promise<PostgrestResponse<FunctionReturns<Schema, Name>>>;
311
+ from(table: string): never;
312
+ }
313
+ export {};
314
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAI/B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,KAAK,EAAE,MAAM,CA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;IACjB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/C,KAAK,EAAE,MAAM,GACZ,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;CAChD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa;IACxE,GAAG,CAAC,IAAI,SAAS,YAAY,CAAC,MAAM,CAAC,EACnC,EAAE,EAAE,IAAI,EACR,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,EACjC,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,iBAAiB,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The error classes supabase-js throws from `functions.invoke`.
3
+ *
4
+ * Ported code branches on them (`if (error instanceof FunctionsHttpError)`), so
5
+ * they exist here and `invoke` puts the matching instance in `error`. It still
6
+ * resolves rather than throws: the `{ data, error }` envelope is the contract
7
+ * everywhere else in this SDK, and a method that sometimes throws and sometimes
8
+ * does not is worse than either.
9
+ */
10
+ export declare class FunctionsError extends Error {
11
+ readonly name_: string;
12
+ readonly context?: unknown | undefined;
13
+ constructor(message: string, name_?: string, context?: unknown | undefined);
14
+ }
15
+ /** The function ran and answered with a non-2xx status. */
16
+ export declare class FunctionsHttpError extends FunctionsError {
17
+ readonly status?: number;
18
+ constructor(message: string, status?: number, context?: unknown);
19
+ }
20
+ /** The function threw before producing a response. */
21
+ export declare class FunctionsRelayError extends FunctionsError {
22
+ constructor(message: string, context?: unknown);
23
+ }
24
+ /** The request never reached the function (network, abort, DNS). */
25
+ export declare class FunctionsFetchError extends FunctionsError {
26
+ constructor(message: string, context?: unknown);
27
+ }
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/functions/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACR,QAAQ,CAAC,KAAK;IAAqB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO;gBAA9E,OAAO,EAAE,MAAM,EAAW,KAAK,SAAmB,EAAW,OAAO,CAAC,EAAE,OAAO,YAAA;CAI7F;AAED,2DAA2D;AAC3D,qBAAa,kBAAmB,SAAQ,cAAc;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAIlE;AAED,sDAAsD;AACtD,qBAAa,mBAAoB,SAAQ,cAAc;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAGjD;AAED,oEAAoE;AACpE,qBAAa,mBAAoB,SAAQ,cAAc;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAGjD"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The error classes supabase-js throws from `functions.invoke`.
3
+ *
4
+ * Ported code branches on them (`if (error instanceof FunctionsHttpError)`), so
5
+ * they exist here and `invoke` puts the matching instance in `error`. It still
6
+ * resolves rather than throws: the `{ data, error }` envelope is the contract
7
+ * everywhere else in this SDK, and a method that sometimes throws and sometimes
8
+ * does not is worse than either.
9
+ */
10
+ export class FunctionsError extends Error {
11
+ constructor(message, name_ = 'FunctionsError', context) {
12
+ super(message);
13
+ this.name_ = name_;
14
+ this.context = context;
15
+ this.name = name_;
16
+ }
17
+ }
18
+ /** The function ran and answered with a non-2xx status. */
19
+ export class FunctionsHttpError extends FunctionsError {
20
+ constructor(message, status, context) {
21
+ super(message, 'FunctionsHttpError', context);
22
+ this.status = status;
23
+ }
24
+ }
25
+ /** The function threw before producing a response. */
26
+ export class FunctionsRelayError extends FunctionsError {
27
+ constructor(message, context) {
28
+ super(message, 'FunctionsRelayError', context);
29
+ }
30
+ }
31
+ /** The request never reached the function (network, abort, DNS). */
32
+ export class FunctionsFetchError extends FunctionsError {
33
+ constructor(message, context) {
34
+ super(message, 'FunctionsFetchError', context);
35
+ }
36
+ }
37
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/functions/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAW,QAAQ,gBAAgB,EAAW,OAAiB;QACtF,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,UAAK,GAAL,KAAK,CAAmB;QAAW,YAAO,GAAP,OAAO,CAAU;QAEtF,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACtB,CAAC;CACJ;AAED,2DAA2D;AAC3D,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IAElD,YAAY,OAAe,EAAE,MAAe,EAAE,OAAiB;QAC3D,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAED,sDAAsD;AACtD,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACnD,YAAY,OAAe,EAAE,OAAiB;QAC1C,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACJ;AAED,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACnD,YAAY,OAAe,EAAE,OAAiB;QAC1C,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { HttpClient } from "../http/index.js";
2
+ import { FunctionInvokeOptions, MotherbaseResponse } from "../index.js";
3
+ /** Supabase-compatible edge functions client: `client.functions.invoke(name, { body })`. */
4
+ export declare class FunctionsClient {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ invoke<Result = unknown, Body = Record<string, unknown>>(name: string, options?: FunctionInvokeOptions<Body>): Promise<MotherbaseResponse<Result>>;
8
+ }
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAgB,qBAAqB,EAA2C,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAI/H,4FAA4F;AAC5F,qBAAa,eAAe;IACZ,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAAqB,CAAC,IAAI,CAAM,GAC1C,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;CAgCzC"}
@@ -0,0 +1,40 @@
1
+ import { contractPath } from "@motherbase/contracts";
2
+ import { BackendError, FunctionsFetchError, FunctionsHttpError } from "../index.js";
3
+ import { warnIgnoredOption } from "../utils/warn.js";
4
+ import { toError } from "../http/utils.js";
5
+ /** Supabase-compatible edge functions client: `client.functions.invoke(name, { body })`. */
6
+ export class FunctionsClient {
7
+ constructor(http) {
8
+ this.http = http;
9
+ }
10
+ async invoke(name, options = {}) {
11
+ try {
12
+ if (options.region) {
13
+ warnIgnoredOption('functions.invoke', 'region', 'A self-hosted Motherbase runs every function in one place, so the call goes there regardless.');
14
+ }
15
+ const edgeToken = options.auth?.type === 'edge-token' ? options.auth.token : undefined;
16
+ const method = options.method ?? 'POST';
17
+ const data = await this.http.request(contractPath.edge(name), {
18
+ method,
19
+ // A GET or DELETE with a JSON body is refused by some proxies and means
20
+ // nothing to the function, so the body is only sent where it can be read.
21
+ body: method === 'GET' || method === 'DELETE' ? undefined : (options.body ?? {}),
22
+ anonymous: options.auth !== undefined,
23
+ headers: {
24
+ ...options.headers,
25
+ ...(edgeToken ? { 'x-motherbase-edge-token': edgeToken } : {}),
26
+ },
27
+ });
28
+ return { data, error: null };
29
+ }
30
+ catch (err) {
31
+ const base = toError(err);
32
+ const status = err instanceof BackendError ? err.httpStatus : 0;
33
+ const error = status
34
+ ? Object.assign(new FunctionsHttpError(base.message, status), base)
35
+ : Object.assign(new FunctionsFetchError(base.message), base);
36
+ return { data: null, error };
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAyB,mBAAmB,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AAC/H,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,4FAA4F;AAC5F,MAAM,OAAO,eAAe;IACxB,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAI,CAAC;IAElD,KAAK,CAAC,MAAM,CACR,IAAY,EACZ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AAkB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;gBACnE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;YACjE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACjC,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,25 @@
1
+ export type FunctionInvokeAuth = {
2
+ type: 'edge-token';
3
+ token: string;
4
+ } | {
5
+ type: 'public';
6
+ };
7
+ export interface FunctionInvokeOptions<Body = unknown> {
8
+ /** JSON body passed to the edge function. */
9
+ body?: Body;
10
+ /**
11
+ * Authentication override. By default the current session bearer is used.
12
+ * Public and dedicated Edge-token invocations must be explicitly selected.
13
+ */
14
+ auth?: FunctionInvokeAuth;
15
+ /** HTTP method the function receives. Defaults to POST, as in supabase-js. */
16
+ method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
17
+ /** Extra request headers, forwarded to the function. */
18
+ headers?: Record<string, string>;
19
+ /**
20
+ * Accepted for supabase-js signature parity and ignored: a self-hosted
21
+ * Motherbase runs its functions in one place, so there is no region to pick.
22
+ */
23
+ region?: string;
24
+ }
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GACxB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEzB,MAAM,WAAW,qBAAqB,CAAC,IAAI,GAAG,OAAO;IACjD,6CAA6C;IAC7C,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACrD,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ export declare class BackendError extends Error {
2
+ /** HTTP status code (0 if the request never completed). */
3
+ readonly httpStatus: number;
4
+ /** The API envelope's `status` field when present. */
5
+ readonly apiStatus?: number;
6
+ /** Backend error code, when present. */
7
+ readonly code?: string;
8
+ /**
9
+ * Correlation id for the failed request, from the `x-request-id` response
10
+ * header (the backend also puts it in the error body). Quote it in a bug
11
+ * report or log it next to your own error: it is what matches this call to
12
+ * the server-side stack trace in the project's logs.
13
+ */
14
+ readonly requestId?: string;
15
+ constructor(message: string, httpStatus: number, apiStatus?: number, code?: string, requestId?: string);
16
+ }
17
+ //# sourceMappingURL=backend-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-error.d.ts","sourceRoot":"","sources":["../../src/http/backend-error.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACnC,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAQzG"}
@@ -0,0 +1,11 @@
1
+ export class BackendError extends Error {
2
+ constructor(message, httpStatus, apiStatus, code, requestId) {
3
+ super(message);
4
+ this.name = 'BackendError';
5
+ this.httpStatus = httpStatus;
6
+ this.apiStatus = apiStatus;
7
+ this.code = code;
8
+ this.requestId = requestId;
9
+ }
10
+ }
11
+ //# sourceMappingURL=backend-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-error.js","sourceRoot":"","sources":["../../src/http/backend-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAenC,YAAY,OAAe,EAAE,UAAkB,EAAE,SAAkB,EAAE,IAAa,EAAE,SAAkB;QAClG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ"}
@@ -0,0 +1,59 @@
1
+ import { SessionStore } from "../auth/session.js";
2
+ import { RequestObserver, RequestOptions } from "./types.js";
3
+ export declare class HttpClient {
4
+ private readonly baseUrl;
5
+ private readonly store;
6
+ private readonly opts;
7
+ /** Performs the refresh; returns true on success. Injected to avoid a cycle. */
8
+ private readonly doRefresh;
9
+ private refreshPromise;
10
+ constructor(baseUrl: string, store: SessionStore, opts: {
11
+ autoRefresh: boolean;
12
+ fetch: typeof fetch;
13
+ headers?: Record<string, string>;
14
+ /** Called once per HTTP round trip, including the retry after a refresh. */
15
+ onRequest?: RequestObserver;
16
+ },
17
+ /** Performs the refresh; returns true on success. Injected to avoid a cycle. */
18
+ doRefresh: () => Promise<boolean>);
19
+ /**
20
+ * Install (or clear) the request observer.
21
+ *
22
+ * Set rather than constructed, so `client.on('request', ...)` can be called
23
+ * after the client exists, and cleared again when the last listener goes: the
24
+ * timing path is skipped entirely while nobody is watching.
25
+ */
26
+ setRequestObserver(observer: RequestObserver | undefined): void;
27
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
28
+ /**
29
+ * Like `request`, but keeps the response headers. PostgREST puts the row count
30
+ * in `Content-Range`, which is unreachable from the parsed body alone.
31
+ */
32
+ requestWithHeaders<T>(path: string, options?: RequestOptions): Promise<{
33
+ data: T;
34
+ headers: Headers;
35
+ status: number;
36
+ }>;
37
+ /** Like `request`, but returns the raw Response (for binary downloads). */
38
+ requestRaw(path: string, options?: RequestOptions): Promise<Response>;
39
+ private sendWithRefresh;
40
+ /** Shared single-flight refresh: concurrent callers await the same promise. */
41
+ private refreshOnce;
42
+ private send;
43
+ /**
44
+ * `fetchImpl`, reporting each round trip to the request observer. The auth
45
+ * client sends through Better Auth's own fetch, which is handed this. It
46
+ * passes a `URL`; the app's fetch gets a string, as from every other call.
47
+ */
48
+ observedFetch(fetchImpl: typeof fetch): typeof fetch;
49
+ private observe;
50
+ /** An observer that throws must not fail the request it was watching. */
51
+ private emit;
52
+ private parse;
53
+ /** Parse a plain-JSON (non-envelope) response, mapping failures to BackendError. */
54
+ private parseRaw;
55
+ /** Absolute URL for a path. Public so callers can navigate to an endpoint
56
+ * rather than fetch it (see the `signIn.social` redirect in auth.ts). */
57
+ url(path: string): string;
58
+ }
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAgB,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM3E,qBAAa,UAAU;IAIf,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;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