@supabase/postgrest-js 2.87.4-canary.3 → 2.87.4-canary.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 (80) hide show
  1. package/dist/index.cjs +1237 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +1421 -0
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.mts +1421 -0
  6. package/dist/index.d.mts.map +1 -0
  7. package/dist/index.mjs +1229 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +18 -16
  10. package/src/version.ts +1 -1
  11. package/dist/cjs/PostgrestBuilder.d.ts +0 -85
  12. package/dist/cjs/PostgrestBuilder.d.ts.map +0 -1
  13. package/dist/cjs/PostgrestBuilder.js +0 -250
  14. package/dist/cjs/PostgrestBuilder.js.map +0 -1
  15. package/dist/cjs/PostgrestClient.d.ts +0 -93
  16. package/dist/cjs/PostgrestClient.d.ts.map +0 -1
  17. package/dist/cjs/PostgrestClient.js +0 -140
  18. package/dist/cjs/PostgrestClient.js.map +0 -1
  19. package/dist/cjs/PostgrestError.d.ts +0 -30
  20. package/dist/cjs/PostgrestError.d.ts.map +0 -1
  21. package/dist/cjs/PostgrestError.js +0 -31
  22. package/dist/cjs/PostgrestError.js.map +0 -1
  23. package/dist/cjs/PostgrestFilterBuilder.d.ts +0 -130
  24. package/dist/cjs/PostgrestFilterBuilder.d.ts.map +0 -1
  25. package/dist/cjs/PostgrestFilterBuilder.js +0 -436
  26. package/dist/cjs/PostgrestFilterBuilder.js.map +0 -1
  27. package/dist/cjs/PostgrestQueryBuilder.d.ts +0 -130
  28. package/dist/cjs/PostgrestQueryBuilder.d.ts.map +0 -1
  29. package/dist/cjs/PostgrestQueryBuilder.js +0 -310
  30. package/dist/cjs/PostgrestQueryBuilder.js.map +0 -1
  31. package/dist/cjs/PostgrestTransformBuilder.d.ts +0 -159
  32. package/dist/cjs/PostgrestTransformBuilder.d.ts.map +0 -1
  33. package/dist/cjs/PostgrestTransformBuilder.js +0 -224
  34. package/dist/cjs/PostgrestTransformBuilder.js.map +0 -1
  35. package/dist/cjs/constants.d.ts +0 -4
  36. package/dist/cjs/constants.d.ts.map +0 -1
  37. package/dist/cjs/constants.js +0 -6
  38. package/dist/cjs/constants.js.map +0 -1
  39. package/dist/cjs/index.d.ts +0 -20
  40. package/dist/cjs/index.d.ts.map +0 -1
  41. package/dist/cjs/index.js +0 -26
  42. package/dist/cjs/index.js.map +0 -1
  43. package/dist/cjs/select-query-parser/parser.d.ts +0 -258
  44. package/dist/cjs/select-query-parser/parser.d.ts.map +0 -1
  45. package/dist/cjs/select-query-parser/parser.js +0 -5
  46. package/dist/cjs/select-query-parser/parser.js.map +0 -1
  47. package/dist/cjs/select-query-parser/result.d.ts +0 -160
  48. package/dist/cjs/select-query-parser/result.d.ts.map +0 -1
  49. package/dist/cjs/select-query-parser/result.js +0 -3
  50. package/dist/cjs/select-query-parser/result.js.map +0 -1
  51. package/dist/cjs/select-query-parser/types.d.ts +0 -32
  52. package/dist/cjs/select-query-parser/types.d.ts.map +0 -1
  53. package/dist/cjs/select-query-parser/types.js +0 -3
  54. package/dist/cjs/select-query-parser/types.js.map +0 -1
  55. package/dist/cjs/select-query-parser/utils.d.ts +0 -283
  56. package/dist/cjs/select-query-parser/utils.d.ts.map +0 -1
  57. package/dist/cjs/select-query-parser/utils.js +0 -3
  58. package/dist/cjs/select-query-parser/utils.js.map +0 -1
  59. package/dist/cjs/types/common/common.d.ts +0 -46
  60. package/dist/cjs/types/common/common.d.ts.map +0 -1
  61. package/dist/cjs/types/common/common.js +0 -4
  62. package/dist/cjs/types/common/common.js.map +0 -1
  63. package/dist/cjs/types/common/rpc.d.ts +0 -40
  64. package/dist/cjs/types/common/rpc.d.ts.map +0 -1
  65. package/dist/cjs/types/common/rpc.js +0 -3
  66. package/dist/cjs/types/common/rpc.js.map +0 -1
  67. package/dist/cjs/types/feature-flags.d.ts +0 -7
  68. package/dist/cjs/types/feature-flags.d.ts.map +0 -1
  69. package/dist/cjs/types/feature-flags.js +0 -3
  70. package/dist/cjs/types/feature-flags.js.map +0 -1
  71. package/dist/cjs/types/types.d.ts +0 -69
  72. package/dist/cjs/types/types.d.ts.map +0 -1
  73. package/dist/cjs/types/types.js +0 -3
  74. package/dist/cjs/types/types.js.map +0 -1
  75. package/dist/cjs/version.d.ts +0 -2
  76. package/dist/cjs/version.d.ts.map +0 -1
  77. package/dist/cjs/version.js +0 -11
  78. package/dist/cjs/version.js.map +0 -1
  79. package/dist/esm/wrapper.mjs +0 -28
  80. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,1421 @@
1
+ //#region src/PostgrestError.d.ts
2
+ /**
3
+ * Error format
4
+ *
5
+ * {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
6
+ */
7
+ declare class PostgrestError extends Error {
8
+ details: string;
9
+ hint: string;
10
+ code: string;
11
+ /**
12
+ * @example
13
+ * ```ts
14
+ * import PostgrestError from '@supabase/postgrest-js'
15
+ *
16
+ * throw new PostgrestError({
17
+ * message: 'Row level security prevented the request',
18
+ * details: 'RLS denied the insert',
19
+ * hint: 'Check your policies',
20
+ * code: 'PGRST301',
21
+ * })
22
+ * ```
23
+ */
24
+ constructor(context: {
25
+ message: string;
26
+ details: string;
27
+ hint: string;
28
+ code: string;
29
+ });
30
+ }
31
+ //#endregion
32
+ //#region src/types/common/common.d.ts
33
+ type Fetch = typeof fetch;
34
+ type GenericRelationship = {
35
+ foreignKeyName: string;
36
+ columns: string[];
37
+ isOneToOne?: boolean;
38
+ referencedRelation: string;
39
+ referencedColumns: string[];
40
+ };
41
+ type GenericTable = {
42
+ Row: Record<string, unknown>;
43
+ Insert: Record<string, unknown>;
44
+ Update: Record<string, unknown>;
45
+ Relationships: GenericRelationship[];
46
+ };
47
+ type GenericUpdatableView = {
48
+ Row: Record<string, unknown>;
49
+ Insert: Record<string, unknown>;
50
+ Update: Record<string, unknown>;
51
+ Relationships: GenericRelationship[];
52
+ };
53
+ type GenericNonUpdatableView = {
54
+ Row: Record<string, unknown>;
55
+ Relationships: GenericRelationship[];
56
+ };
57
+ type GenericView = GenericUpdatableView | GenericNonUpdatableView;
58
+ type GenericSetofOption = {
59
+ isSetofReturn?: boolean | undefined;
60
+ isOneToOne?: boolean | undefined;
61
+ isNotNullable?: boolean | undefined;
62
+ to: string;
63
+ from: string;
64
+ };
65
+ type GenericFunction = {
66
+ Args: Record<string, unknown> | never;
67
+ Returns: unknown;
68
+ SetofOptions?: GenericSetofOption;
69
+ };
70
+ type GenericSchema = {
71
+ Tables: Record<string, GenericTable>;
72
+ Views: Record<string, GenericView>;
73
+ Functions: Record<string, GenericFunction>;
74
+ };
75
+ type ClientServerOptions = {
76
+ PostgrestVersion?: string;
77
+ };
78
+ //#endregion
79
+ //#region src/select-query-parser/types.d.ts
80
+ type AggregateWithoutColumnFunctions = 'count';
81
+ type AggregateWithColumnFunctions = 'sum' | 'avg' | 'min' | 'max' | AggregateWithoutColumnFunctions;
82
+ type AggregateFunctions = AggregateWithColumnFunctions;
83
+ type Json = string | number | boolean | null | {
84
+ [key: string]: Json | undefined;
85
+ } | Json[];
86
+ type PostgresSQLNumberTypes = 'int2' | 'int4' | 'int8' | 'float4' | 'float8' | 'numeric';
87
+ type PostgresSQLStringTypes = 'bytea' | 'bpchar' | 'varchar' | 'date' | 'text' | 'citext' | 'time' | 'timetz' | 'timestamp' | 'timestamptz' | 'uuid' | 'vector';
88
+ type SingleValuePostgreSQLTypes = PostgresSQLNumberTypes | PostgresSQLStringTypes | 'bool' | 'json' | 'jsonb' | 'void' | 'record' | string;
89
+ type ArrayPostgreSQLTypes = `_${SingleValuePostgreSQLTypes}`;
90
+ type TypeScriptSingleValueTypes<T extends SingleValuePostgreSQLTypes> = T extends 'bool' ? boolean : T extends PostgresSQLNumberTypes ? number : T extends PostgresSQLStringTypes ? string : T extends 'json' | 'jsonb' ? Json : T extends 'void' ? undefined : T extends 'record' ? Record<string, unknown> : unknown;
91
+ type StripUnderscore<T extends string> = T extends `_${infer U}` ? U : T;
92
+ type PostgreSQLTypes = SingleValuePostgreSQLTypes | ArrayPostgreSQLTypes;
93
+ type TypeScriptTypes<T extends PostgreSQLTypes> = T extends ArrayPostgreSQLTypes ? TypeScriptSingleValueTypes<StripUnderscore<Extract<T, SingleValuePostgreSQLTypes>>>[] : TypeScriptSingleValueTypes<T>;
94
+ type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
95
+ type LastOf$1<T> = UnionToIntersection$1<T extends any ? () => T : never> extends (() => infer R) ? R : never;
96
+ type Push<T extends any[], V> = [...T, V];
97
+ type UnionToTuple<T, L$1 = LastOf$1<T>, N = ([T] extends [never] ? true : false)> = N extends true ? [] : Push<UnionToTuple<Exclude<T, L$1>>, L$1>;
98
+ type UnionToArray<T> = UnionToTuple<T>;
99
+ type ExtractFirstProperty<T> = T extends { [K in keyof T]: infer U } ? U : never;
100
+ type ContainsNull<T> = null extends T ? true : false;
101
+ type IsNonEmptyArray<T> = Exclude<T, undefined> extends readonly [unknown, ...unknown[]] ? true : false;
102
+ type TablesAndViews$2<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>;
103
+ //#endregion
104
+ //#region src/select-query-parser/parser.d.ts
105
+ /**
106
+ * Parses a query.
107
+ * A query is a sequence of nodes, separated by `,`, ensuring that there is
108
+ * no remaining input after all nodes have been parsed.
109
+ *
110
+ * Returns an array of parsed nodes, or an error.
111
+ */
112
+ type ParseQuery<Query extends string> = string extends Query ? GenericStringError : ParseNodes<EatWhitespace<Query>> extends [infer Nodes, `${infer Remainder}`] ? Nodes extends Ast.Node[] ? EatWhitespace<Remainder> extends '' ? SimplifyDeep<Nodes> : ParserError<`Unexpected input: ${Remainder}`> : ParserError<'Invalid nodes array structure'> : ParseNodes<EatWhitespace<Query>>;
113
+ /**
114
+ * Notes: all `Parse*` types assume that their input strings have their whitespace
115
+ * removed. They return tuples of ["Return Value", "Remainder of text"] or
116
+ * a `ParserError`.
117
+ */
118
+ /**
119
+ * Parses a sequence of nodes, separated by `,`.
120
+ *
121
+ * Returns a tuple of ["Parsed fields", "Remainder of text"] or an error.
122
+ */
123
+ type ParseNodes<Input extends string> = string extends Input ? GenericStringError : ParseNodesHelper<Input, []>;
124
+ type ParseNodesHelper<Input extends string, Nodes$1 extends Ast.Node[]> = ParseNode<Input> extends [infer Node, `${infer Remainder}`] ? Node extends Ast.Node ? EatWhitespace<Remainder> extends `,${infer Remainder}` ? ParseNodesHelper<EatWhitespace<Remainder>, [...Nodes$1, Node]> : [[...Nodes$1, Node], EatWhitespace<Remainder>] : ParserError<'Invalid node type in nodes helper'> : ParseNode<Input>;
125
+ /**
126
+ * Parses a node.
127
+ * A node is one of the following:
128
+ * - `*`
129
+ * - a field, as defined above
130
+ * - a renamed field, `renamed_field:field`
131
+ * - a spread field, `...field`
132
+ */
133
+ type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [Ast.StarNode, EatWhitespace<Remainder>] : Input extends `...${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer TargetField, `${infer Remainder}`] ? TargetField extends Ast.FieldNode ? [{
134
+ type: 'spread';
135
+ target: TargetField;
136
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid target field type in spread'> : ParserError<`Unable to parse spread resource at \`${Input}\``> : ParseIdentifier<Input> extends [infer NameOrAlias, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer _}` ? ParseField<Input> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends Ast.FieldNode ? [Omit<Field, 'alias'> & {
137
+ alias: NameOrAlias;
138
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid field type in alias parsing'> : ParserError<`Unable to parse renamed field at \`${Input}\``> : ParseField<Input> : ParserError<`Expected identifier at \`${Input}\``>;
139
+ /**
140
+ * Parses a field without preceding alias.
141
+ * A field is one of the following:
142
+ * - a top-level `count` field: https://docs.postgrest.org/en/v12/references/api/aggregate_functions.html#the-case-of-count
143
+ * - a field with an embedded resource
144
+ * - `field(nodes)`
145
+ * - `field!hint(nodes)`
146
+ * - `field!inner(nodes)`
147
+ * - `field!left(nodes)`
148
+ * - `field!hint!inner(nodes)`
149
+ * - `field!hint!left(nodes)`
150
+ * - a field without an embedded resource (see {@link ParseNonEmbeddedResourceField})
151
+ */
152
+ type ParseField<Input extends string> = Input extends '' ? ParserError<'Empty string'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? Name extends 'count' ? ParseCountField<Input> : Remainder extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Children, `${infer Remainder}`] ? Children extends Ast.Node[] ? [{
153
+ type: 'field';
154
+ name: Name;
155
+ innerJoin: true;
156
+ children: Children;
157
+ }, Remainder] : ParserError<'Invalid children array in inner join'> : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, `Expected embedded resource after "!inner" at \`${Remainder}\``> : EatWhitespace<Remainder> extends `!left${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Children, `${infer Remainder}`] ? Children extends Ast.Node[] ? [{
158
+ type: 'field';
159
+ name: Name;
160
+ children: Children;
161
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid children array in left join'> : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, `Expected embedded resource after "!left" at \`${EatWhitespace<Remainder>}\``> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Children, `${infer Remainder}`] ? Children extends Ast.Node[] ? [{
162
+ type: 'field';
163
+ name: Name;
164
+ hint: Hint;
165
+ innerJoin: true;
166
+ children: Children;
167
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid children array in hint inner join'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Children, `${infer Remainder}`] ? Children extends Ast.Node[] ? [{
168
+ type: 'field';
169
+ name: Name;
170
+ hint: Hint;
171
+ children: Children;
172
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid children array in hint'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<`Expected identifier after "!" at \`${EatWhitespace<Remainder>}\``> : EatWhitespace<Remainder> extends `(${infer _}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Children, `${infer Remainder}`] ? Children extends Ast.Node[] ? [{
173
+ type: 'field';
174
+ name: Name;
175
+ children: Children;
176
+ }, EatWhitespace<Remainder>] : ParserError<'Invalid children array in field'> : ParseEmbeddedResource<EatWhitespace<Remainder>> : ParseNonEmbeddedResourceField<Input> : ParserError<`Expected identifier at \`${Input}\``>;
177
+ type ParseCountField<Input extends string> = ParseIdentifier<Input> extends ['count', `${infer Remainder}`] ? (EatWhitespace<Remainder> extends `()${infer Remainder_}` ? EatWhitespace<Remainder_> : EatWhitespace<Remainder>) extends `${infer Remainder}` ? Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [{
178
+ type: 'field';
179
+ name: 'count';
180
+ aggregateFunction: 'count';
181
+ castType: CastType;
182
+ }, Remainder] : ParseFieldTypeCast<Remainder> : [{
183
+ type: 'field';
184
+ name: 'count';
185
+ aggregateFunction: 'count';
186
+ }, Remainder] : never : ParserError<`Expected "count" at \`${Input}\``>;
187
+ /**
188
+ * Parses an embedded resource, which is an opening `(`, followed by a sequence of
189
+ * 0 or more nodes separated by `,`, then a closing `)`.
190
+ *
191
+ * Returns a tuple of ["Parsed fields", "Remainder of text"], an error,
192
+ * or the original string input indicating that no opening `(` was found.
193
+ */
194
+ type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [[], EatWhitespace<Remainder>] : ParseNodes<EatWhitespace<Remainder>> extends [infer Nodes, `${infer Remainder}`] ? Nodes extends Ast.Node[] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [Nodes, EatWhitespace<Remainder>] : ParserError<`Expected ")" at \`${EatWhitespace<Remainder>}\``> : ParserError<'Invalid nodes array in embedded resource'> : ParseNodes<EatWhitespace<Remainder>> : ParserError<`Expected "(" at \`${Input}\``>;
195
+ /**
196
+ * Parses a field excluding embedded resources, without preceding field renaming.
197
+ * This is one of the following:
198
+ * - `field`
199
+ * - `field.aggregate()`
200
+ * - `field.aggregate()::type`
201
+ * - `field::type`
202
+ * - `field::type.aggregate()`
203
+ * - `field::type.aggregate()::type`
204
+ * - `field->json...`
205
+ * - `field->json.aggregate()`
206
+ * - `field->json.aggregate()::type`
207
+ * - `field->json::type`
208
+ * - `field->json::type.aggregate()`
209
+ * - `field->json::type.aggregate()::type`
210
+ */
211
+ type ParseNonEmbeddedResourceField<Input extends string> = ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? (Remainder extends `->${infer PathAndRest}` ? ParseJsonAccessor<Remainder> extends [infer PropertyName, infer PropertyType, `${infer Remainder}`] ? [{
212
+ type: 'field';
213
+ name: Name;
214
+ alias: PropertyName;
215
+ castType: PropertyType;
216
+ jsonPath: JsonPathToAccessor<PathAndRest extends `${infer Path},${string}` ? Path : PathAndRest>;
217
+ }, Remainder] : ParseJsonAccessor<Remainder> : [{
218
+ type: 'field';
219
+ name: Name;
220
+ }, Remainder]) extends infer Parsed ? Parsed extends [infer Field, `${infer Remainder}`] ? (Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [Omit<Field, 'castType'> & {
221
+ castType: CastType;
222
+ }, Remainder] : ParseFieldTypeCast<Remainder> : [Field, Remainder]) extends infer Parsed ? Parsed extends [infer Field, `${infer Remainder}`] ? Remainder extends `.${infer _}` ? ParseFieldAggregation<Remainder> extends [infer AggregateFunction, `${infer Remainder}`] ? Remainder extends `::${infer _}` ? ParseFieldTypeCast<Remainder> extends [infer CastType, `${infer Remainder}`] ? [Omit<Field, 'castType'> & {
223
+ aggregateFunction: AggregateFunction;
224
+ castType: CastType;
225
+ }, Remainder] : ParseFieldTypeCast<Remainder> : [Field & {
226
+ aggregateFunction: AggregateFunction;
227
+ }, Remainder] : ParseFieldAggregation<Remainder> : [Field, Remainder] : Parsed : never : Parsed : never : ParserError<`Expected identifier at \`${Input}\``>;
228
+ /**
229
+ * Parses a JSON property accessor of the shape `->a->b->c`. The last accessor in
230
+ * the series may convert to text by using the ->> operator instead of ->.
231
+ *
232
+ * Returns a tuple of ["Last property name", "Last property type", "Remainder of text"]
233
+ */
234
+ type ParseJsonAccessor<Input extends string> = Input extends `->${infer Remainder}` ? Remainder extends `>${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer Name, `${infer Remainder}`] ? [Name, 'text', EatWhitespace<Remainder>] : ParserError<'Expected property name after `->>`'> : ParseIdentifier<Remainder> extends [infer Name, `${infer Remainder}`] ? ParseJsonAccessor<Remainder> extends [infer PropertyName, infer PropertyType, `${infer Remainder}`] ? [PropertyName, PropertyType, EatWhitespace<Remainder>] : [Name, 'json', EatWhitespace<Remainder>] : ParserError<'Expected property name after `->`'> : ParserError<'Expected ->'>;
235
+ /**
236
+ * Parses a field typecast (`::type`), returning a tuple of ["Type", "Remainder of text"].
237
+ */
238
+ type ParseFieldTypeCast<Input extends string> = EatWhitespace<Input> extends `::${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [`${infer CastType}`, `${infer Remainder}`] ? [CastType, EatWhitespace<Remainder>] : ParserError<`Invalid type for \`::\` operator at \`${Remainder}\``> : ParserError<'Expected ::'>;
239
+ /**
240
+ * Parses a field aggregation (`.max()`), returning a tuple of ["Aggregate function", "Remainder of text"]
241
+ */
242
+ type ParseFieldAggregation<Input extends string> = EatWhitespace<Input> extends `.${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [`${infer FunctionName}`, `${infer Remainder}`] ? FunctionName extends Token.AggregateFunction ? EatWhitespace<Remainder> extends `()${infer Remainder}` ? [FunctionName, EatWhitespace<Remainder>] : ParserError<`Expected \`()\` after \`.\` operator \`${FunctionName}\``> : ParserError<`Invalid type for \`.\` operator \`${FunctionName}\``> : ParserError<`Invalid type for \`.\` operator at \`${Remainder}\``> : ParserError<'Expected .'>;
243
+ /**
244
+ * Parses a (possibly double-quoted) identifier.
245
+ * Identifiers are sequences of 1 or more letters.
246
+ */
247
+ type ParseIdentifier<Input extends string> = ParseLetters<Input> extends [infer Name, `${infer Remainder}`] ? [Name, EatWhitespace<Remainder>] : ParseQuotedLetters<Input> extends [infer Name, `${infer Remainder}`] ? [Name, EatWhitespace<Remainder>] : ParserError<`No (possibly double-quoted) identifier at \`${Input}\``>;
248
+ /**
249
+ * Parse a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`.
250
+ */
251
+ type ParseLetters<Input extends string> = string extends Input ? GenericStringError : ParseLettersHelper<Input, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected letter at \`${Input}\``> : [Letters, Remainder] : ParseLettersHelper<Input, ''>;
252
+ type ParseLettersHelper<Input extends string, Acc extends string> = string extends Input ? GenericStringError : Input extends `${infer L}${infer Remainder}` ? L extends Token.Letter ? ParseLettersHelper<Remainder, `${Acc}${L}`> : [Acc, Input] : [Acc, ''];
253
+ /**
254
+ * Parse a consecutive sequence of 1 or more double-quoted letters,
255
+ * where letters are `[^"]`.
256
+ */
257
+ type ParseQuotedLetters<Input extends string> = string extends Input ? GenericStringError : Input extends `"${infer Remainder}` ? ParseQuotedLettersHelper<Remainder, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected string at \`${Remainder}\``> : [Letters, Remainder] : ParseQuotedLettersHelper<Remainder, ''> : ParserError<`Not a double-quoted string at \`${Input}\``>;
258
+ type ParseQuotedLettersHelper<Input extends string, Acc extends string> = string extends Input ? GenericStringError : Input extends `${infer L}${infer Remainder}` ? L extends '"' ? [Acc, Remainder] : ParseQuotedLettersHelper<Remainder, `${Acc}${L}`> : ParserError<`Missing closing double-quote in \`"${Acc}${Input}\``>;
259
+ /**
260
+ * Trims whitespace from the left of the input.
261
+ */
262
+ type EatWhitespace<Input extends string> = string extends Input ? GenericStringError : Input extends `${Token.Whitespace}${infer Remainder}` ? EatWhitespace<Remainder> : Input;
263
+ /**
264
+ * Creates a new {@link ParserError} if the given input is not already a parser error.
265
+ */
266
+ type CreateParserErrorIfRequired<Input, Message extends string> = Input extends ParserError<string> ? Input : ParserError<Message>;
267
+ /**
268
+ * Parser errors.
269
+ */
270
+ type ParserError<Message extends string> = {
271
+ error: true;
272
+ } & Message;
273
+ type GenericStringError = ParserError<'Received a generic string'>;
274
+ declare namespace Ast {
275
+ type Node = FieldNode | StarNode | SpreadNode;
276
+ type FieldNode = {
277
+ type: 'field';
278
+ name: string;
279
+ alias?: string;
280
+ hint?: string;
281
+ innerJoin?: true;
282
+ castType?: string;
283
+ jsonPath?: string;
284
+ aggregateFunction?: Token.AggregateFunction;
285
+ children?: Node[];
286
+ };
287
+ type StarNode = {
288
+ type: 'star';
289
+ };
290
+ type SpreadNode = {
291
+ type: 'spread';
292
+ target: FieldNode & {
293
+ children: Node[];
294
+ };
295
+ };
296
+ }
297
+ declare namespace Token {
298
+ export type Whitespace = ' ' | '\n' | '\t';
299
+ type LowerAlphabet = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
300
+ type Alphabet = LowerAlphabet | Uppercase<LowerAlphabet>;
301
+ type Digit = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '0';
302
+ export type Letter = Alphabet | Digit | '_';
303
+ export type AggregateFunction = 'count' | 'sum' | 'avg' | 'min' | 'max';
304
+ export {};
305
+ }
306
+ //#endregion
307
+ //#region src/select-query-parser/utils.d.ts
308
+ type IsAny$1<T> = 0 extends 1 & T ? true : false;
309
+ type SelectQueryError<Message extends string> = {
310
+ error: true;
311
+ } & Message;
312
+ type DeduplicateRelationships<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? First extends Rest[number] ? DeduplicateRelationships<Rest extends readonly unknown[] ? Rest : []> : [First, ...DeduplicateRelationships<Rest extends readonly unknown[] ? Rest : []>] : T;
313
+ type GetFieldNodeResultName<Field$1 extends Ast.FieldNode> = Field$1['alias'] extends string ? Field$1['alias'] : Field$1['aggregateFunction'] extends AggregateFunctions ? Field$1['aggregateFunction'] : Field$1['name'];
314
+ type FilterRelationNodes<Nodes$1 extends Ast.Node[]> = UnionToArray<{ [K in keyof Nodes$1]: Nodes$1[K] extends Ast.SpreadNode ? Nodes$1[K]['target'] : Nodes$1[K] extends Ast.FieldNode ? IsNonEmptyArray<Nodes$1[K]['children']> extends true ? Nodes$1[K] : never : never }[number]>;
315
+ type ResolveRelationships<Schema extends GenericSchema, RelationName extends string, Relationships extends GenericRelationship[], Nodes$1 extends Ast.FieldNode[]> = UnionToArray<{ [K in keyof Nodes$1]: Nodes$1[K] extends Ast.FieldNode ? ResolveRelationship<Schema, Relationships, Nodes$1[K], RelationName> extends infer Relation ? Relation extends {
316
+ relation: {
317
+ referencedRelation: string;
318
+ foreignKeyName: string;
319
+ match: string;
320
+ };
321
+ from: string;
322
+ } ? {
323
+ referencedTable: Relation['relation']['referencedRelation'];
324
+ fkName: Relation['relation']['foreignKeyName'];
325
+ from: Relation['from'];
326
+ match: Relation['relation']['match'];
327
+ fieldName: GetFieldNodeResultName<Nodes$1[K]>;
328
+ } : Relation : never : never }>[0];
329
+ /**
330
+ * Checks if a relation is implicitly referenced twice, requiring disambiguation
331
+ */
332
+ type IsDoubleReference<T, U> = T extends {
333
+ referencedTable: infer RT;
334
+ fieldName: infer FN;
335
+ match: infer M;
336
+ } ? M extends 'col' | 'refrel' ? U extends {
337
+ referencedTable: RT;
338
+ fieldName: FN;
339
+ match: M;
340
+ } ? true : false : false : false;
341
+ /**
342
+ * Compares one element with all other elements in the array to find duplicates
343
+ */
344
+ type CheckDuplicates<Arr extends any[], Current> = Arr extends [infer Head, ...infer Tail] ? IsDoubleReference<Current, Head> extends true ? Head | CheckDuplicates<Tail, Current> : CheckDuplicates<Tail, Current> : never;
345
+ /**
346
+ * Iterates over the elements of the array to find duplicates
347
+ */
348
+ type FindDuplicatesWithinDeduplicated<Arr extends any[]> = Arr extends [infer Head, ...infer Tail] ? CheckDuplicates<Tail, Head> | FindDuplicatesWithinDeduplicated<Tail> : never;
349
+ type FindDuplicates<Arr extends any[]> = FindDuplicatesWithinDeduplicated<DeduplicateRelationships<Arr>>;
350
+ type CheckDuplicateEmbededReference<Schema extends GenericSchema, RelationName extends string, Relationships extends GenericRelationship[], Nodes$1 extends Ast.Node[]> = FilterRelationNodes<Nodes$1> extends infer RelationsNodes ? RelationsNodes extends Ast.FieldNode[] ? ResolveRelationships<Schema, RelationName, Relationships, RelationsNodes> extends infer ResolvedRels ? ResolvedRels extends unknown[] ? FindDuplicates<ResolvedRels> extends infer Duplicates ? Duplicates extends never ? false : Duplicates extends {
351
+ fieldName: infer FieldName;
352
+ } ? FieldName extends string ? { [K in FieldName]: SelectQueryError<`table "${RelationName}" specified more than once use hinting for desambiguation`> } : false : false : false : false : false : false : false;
353
+ /**
354
+ * Returns a boolean representing whether there is a foreign key referencing
355
+ * a given relation.
356
+ */
357
+ type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R] ? R extends {
358
+ referencedRelation: FRelName;
359
+ } ? true : false : Relationships extends [infer R, ...infer Rest] ? HasFKeyToFRel<FRelName, [R]> extends true ? true : HasFKeyToFRel<FRelName, Rest> : false;
360
+ /**
361
+ * Checks if there is more than one relation to a given foreign relation name in the Relationships.
362
+ */
363
+ type HasMultipleFKeysToFRelDeduplicated<FRelName, Relationships> = Relationships extends [infer R, ...infer Rest] ? R extends {
364
+ referencedRelation: FRelName;
365
+ } ? HasFKeyToFRel<FRelName, Rest> extends true ? true : HasMultipleFKeysToFRelDeduplicated<FRelName, Rest> : HasMultipleFKeysToFRelDeduplicated<FRelName, Rest> : false;
366
+ type HasMultipleFKeysToFRel<FRelName, Relationships extends unknown[]> = HasMultipleFKeysToFRelDeduplicated<FRelName, DeduplicateRelationships<Relationships>>;
367
+ type CheckRelationshipError<Schema extends GenericSchema, Relationships extends GenericRelationship[], CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string, FoundRelation$1> = FoundRelation$1 extends SelectQueryError<string> ? FoundRelation$1 : FoundRelation$1 extends {
368
+ relation: {
369
+ referencedRelation: infer RelatedRelationName;
370
+ name: string;
371
+ };
372
+ direction: 'reverse';
373
+ } ? RelatedRelationName extends string ? HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`> : FoundRelation$1 : never : FoundRelation$1 extends {
374
+ relation: {
375
+ referencedRelation: infer RelatedRelationName;
376
+ name: string;
377
+ };
378
+ direction: 'forward';
379
+ from: infer From;
380
+ } ? RelatedRelationName extends string ? From extends keyof TablesAndViews$2<Schema> & string ? HasMultipleFKeysToFRel<RelatedRelationName, TablesAndViews$2<Schema>[From]['Relationships']> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${From}' and '${RelatedRelationName}' you need to hint the column with ${From}!<columnName> ?`> : FoundRelation$1 : never : never : FoundRelation$1;
381
+ /**
382
+ * Resolves relationships for embedded resources and retrieves the referenced Table
383
+ */
384
+ type ResolveRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field$1 extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string> = ResolveReverseRelationship<Schema, Relationships, Field$1, CurrentTableOrView> extends infer ReverseRelationship ? ReverseRelationship extends false ? CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ResolveForwardRelationship<Schema, Field$1, CurrentTableOrView>> : CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ReverseRelationship> : never;
385
+ /**
386
+ * Resolves reverse relationships (from children to parent)
387
+ */
388
+ type ResolveReverseRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field$1 extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string> = FindFieldMatchingRelationships<Schema, Relationships, Field$1> extends infer FoundRelation ? FoundRelation extends never ? false : FoundRelation extends {
389
+ referencedRelation: infer RelatedRelationName;
390
+ } ? RelatedRelationName extends string ? RelatedRelationName extends keyof TablesAndViews$2<Schema> ? FoundRelation extends {
391
+ hint: string;
392
+ } ? {
393
+ referencedTable: TablesAndViews$2<Schema>[RelatedRelationName];
394
+ relation: FoundRelation;
395
+ direction: 'reverse';
396
+ from: CurrentTableOrView;
397
+ } : HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true ? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`> : {
398
+ referencedTable: TablesAndViews$2<Schema>[RelatedRelationName];
399
+ relation: FoundRelation;
400
+ direction: 'reverse';
401
+ from: CurrentTableOrView;
402
+ } : SelectQueryError<`Relation '${RelatedRelationName}' not found in schema.`> : false : false : false;
403
+ type FindMatchingTableRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], value extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
404
+ referencedRelation: infer ReferencedRelation;
405
+ } ? ReferencedRelation extends keyof Schema['Tables'] ? R extends {
406
+ foreignKeyName: value;
407
+ } ? R & {
408
+ match: 'fkname';
409
+ } : R extends {
410
+ referencedRelation: value;
411
+ } ? R & {
412
+ match: 'refrel';
413
+ } : R extends {
414
+ columns: [value];
415
+ } ? R & {
416
+ match: 'col';
417
+ } : FindMatchingTableRelationships<Schema, Rest, value> : FindMatchingTableRelationships<Schema, Rest, value> : false : false : false;
418
+ type FindMatchingViewRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], value extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
419
+ referencedRelation: infer ReferencedRelation;
420
+ } ? ReferencedRelation extends keyof Schema['Views'] ? R extends {
421
+ foreignKeyName: value;
422
+ } ? R & {
423
+ match: 'fkname';
424
+ } : R extends {
425
+ referencedRelation: value;
426
+ } ? R & {
427
+ match: 'refrel';
428
+ } : R extends {
429
+ columns: [value];
430
+ } ? R & {
431
+ match: 'col';
432
+ } : FindMatchingViewRelationships<Schema, Rest, value> : FindMatchingViewRelationships<Schema, Rest, value> : false : false : false;
433
+ type FindMatchingHintTableRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], hint extends string, name extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
434
+ referencedRelation: infer ReferencedRelation;
435
+ } ? ReferencedRelation extends name ? R extends {
436
+ foreignKeyName: hint;
437
+ } ? R & {
438
+ match: 'fkname';
439
+ } : R extends {
440
+ referencedRelation: hint;
441
+ } ? R & {
442
+ match: 'refrel';
443
+ } : R extends {
444
+ columns: [hint];
445
+ } ? R & {
446
+ match: 'col';
447
+ } : FindMatchingHintTableRelationships<Schema, Rest, hint, name> : FindMatchingHintTableRelationships<Schema, Rest, hint, name> : false : false : false;
448
+ type FindMatchingHintViewRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], hint extends string, name extends string> = Relationships extends [infer R, ...infer Rest] ? Rest extends GenericRelationship[] ? R extends {
449
+ referencedRelation: infer ReferencedRelation;
450
+ } ? ReferencedRelation extends name ? R extends {
451
+ foreignKeyName: hint;
452
+ } ? R & {
453
+ match: 'fkname';
454
+ } : R extends {
455
+ referencedRelation: hint;
456
+ } ? R & {
457
+ match: 'refrel';
458
+ } : R extends {
459
+ columns: [hint];
460
+ } ? R & {
461
+ match: 'col';
462
+ } : FindMatchingHintViewRelationships<Schema, Rest, hint, name> : FindMatchingHintViewRelationships<Schema, Rest, hint, name> : false : false : false;
463
+ type IsColumnsNullable<Table extends Pick<GenericTable, 'Row'>, Columns extends (keyof Table['Row'])[]> = Columns extends [infer Column, ...infer Rest] ? Column extends keyof Table['Row'] ? ContainsNull<Table['Row'][Column]> extends true ? true : IsColumnsNullable<Table, Rest extends (keyof Table['Row'])[] ? Rest : []> : false : false;
464
+ type IsRelationNullable<Table extends GenericTable, Relation$1 extends GenericRelationship> = IsColumnsNullable<Table, Relation$1['columns']>;
465
+ type TableForwardRelationships<Schema extends GenericSchema, TName> = TName extends keyof TablesAndViews$2<Schema> ? UnionToArray<RecursivelyFindRelationships<Schema, TName, keyof TablesAndViews$2<Schema>>> extends infer R ? R extends (GenericRelationship & {
466
+ from: keyof TablesAndViews$2<Schema>;
467
+ })[] ? R : [] : [] : [];
468
+ type RecursivelyFindRelationships<Schema extends GenericSchema, TName, Keys extends keyof TablesAndViews$2<Schema>> = Keys extends infer K ? K extends keyof TablesAndViews$2<Schema> ? FilterRelationships<TablesAndViews$2<Schema>[K]['Relationships'], TName, K> extends never ? RecursivelyFindRelationships<Schema, TName, Exclude<Keys, K>> : FilterRelationships<TablesAndViews$2<Schema>[K]['Relationships'], TName, K> | RecursivelyFindRelationships<Schema, TName, Exclude<Keys, K>> : false : false;
469
+ type FilterRelationships<R$1, TName, From$1> = R$1 extends readonly (infer Rel)[] ? Rel extends {
470
+ referencedRelation: TName;
471
+ } ? Rel & {
472
+ from: From$1;
473
+ } : never : never;
474
+ type ResolveForwardRelationship<Schema extends GenericSchema, Field$1 extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string> = FindFieldMatchingRelationships<Schema, TablesAndViews$2<Schema>[Field$1['name']]['Relationships'], Ast.FieldNode & {
475
+ name: CurrentTableOrView;
476
+ hint: Field$1['hint'];
477
+ }> extends infer FoundByName ? FoundByName extends GenericRelationship ? {
478
+ referencedTable: TablesAndViews$2<Schema>[Field$1['name']];
479
+ relation: FoundByName;
480
+ direction: 'forward';
481
+ from: Field$1['name'];
482
+ type: 'found-by-name';
483
+ } : FindFieldMatchingRelationships<Schema, TableForwardRelationships<Schema, CurrentTableOrView>, Field$1> extends infer FoundByMatch ? FoundByMatch extends GenericRelationship & {
484
+ from: keyof TablesAndViews$2<Schema>;
485
+ } ? {
486
+ referencedTable: TablesAndViews$2<Schema>[FoundByMatch['from']];
487
+ relation: FoundByMatch;
488
+ direction: 'forward';
489
+ from: CurrentTableOrView;
490
+ type: 'found-by-match';
491
+ } : FindJoinTableRelationship<Schema, CurrentTableOrView, Field$1['name']> extends infer FoundByJoinTable ? FoundByJoinTable extends GenericRelationship ? {
492
+ referencedTable: TablesAndViews$2<Schema>[FoundByJoinTable['referencedRelation']];
493
+ relation: FoundByJoinTable & {
494
+ match: 'refrel';
495
+ };
496
+ direction: 'forward';
497
+ from: CurrentTableOrView;
498
+ type: 'found-by-join-table';
499
+ } : ResolveEmbededFunctionJoinTableRelationship<Schema, CurrentTableOrView, Field$1['name']> extends infer FoundEmbededFunctionJoinTableRelation ? FoundEmbededFunctionJoinTableRelation extends GenericSetofOption ? {
500
+ referencedTable: TablesAndViews$2<Schema>[FoundEmbededFunctionJoinTableRelation['to']];
501
+ relation: {
502
+ foreignKeyName: `${Field$1['name']}_${CurrentTableOrView}_${FoundEmbededFunctionJoinTableRelation['to']}_forward`;
503
+ columns: [];
504
+ isOneToOne: FoundEmbededFunctionJoinTableRelation['isOneToOne'] extends true ? true : false;
505
+ referencedColumns: [];
506
+ referencedRelation: FoundEmbededFunctionJoinTableRelation['to'];
507
+ } & {
508
+ match: 'func';
509
+ isNotNullable: FoundEmbededFunctionJoinTableRelation['isNotNullable'] extends true ? true : FoundEmbededFunctionJoinTableRelation['isSetofReturn'] extends true ? false : true;
510
+ isSetofReturn: FoundEmbededFunctionJoinTableRelation['isSetofReturn'];
511
+ };
512
+ direction: 'forward';
513
+ from: CurrentTableOrView;
514
+ type: 'found-by-embeded-function';
515
+ } : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field$1['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field$1['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field$1['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field$1['name']}`> : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field$1['name']}`>;
516
+ /**
517
+ * Given a CurrentTableOrView, finds all join tables to this relation.
518
+ * For example, if products and categories are linked via product_categories table:
519
+ *
520
+ * @example
521
+ * Given:
522
+ * - CurrentTableView = 'products'
523
+ * - FieldName = "categories"
524
+ *
525
+ * It should return this relationship from product_categories:
526
+ * {
527
+ * foreignKeyName: "product_categories_category_id_fkey",
528
+ * columns: ["category_id"],
529
+ * isOneToOne: false,
530
+ * referencedRelation: "categories",
531
+ * referencedColumns: ["id"]
532
+ * }
533
+ */
534
+ type ResolveJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string, FieldName$1 extends string> = { [TableName in keyof TablesAndViews$2<Schema>]: DeduplicateRelationships<TablesAndViews$2<Schema>[TableName]['Relationships']> extends readonly (infer Rel)[] ? Rel extends {
535
+ referencedRelation: CurrentTableOrView;
536
+ } ? DeduplicateRelationships<TablesAndViews$2<Schema>[TableName]['Relationships']> extends readonly (infer OtherRel)[] ? OtherRel extends {
537
+ referencedRelation: FieldName$1;
538
+ } ? OtherRel : never : never : never : never }[keyof TablesAndViews$2<Schema>];
539
+ type ResolveEmbededFunctionJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string, FieldName$1 extends string> = FindMatchingFunctionBySetofFrom<Schema['Functions'][FieldName$1], CurrentTableOrView> extends infer Fn ? Fn extends GenericFunction ? Fn['SetofOptions'] : false : false;
540
+ type FindJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string, FieldName$1 extends string> = ResolveJoinTableRelationship<Schema, CurrentTableOrView, FieldName$1> extends infer Result ? [Result] extends [never] ? false : Result : never;
541
+ /**
542
+ * Finds a matching relationship based on the FieldNode's name and optional hint.
543
+ */
544
+ type FindFieldMatchingRelationships<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field$1 extends Ast.FieldNode> = Field$1 extends {
545
+ hint: string;
546
+ } ? FindMatchingHintTableRelationships<Schema, Relationships, Field$1['hint'], Field$1['name']> extends GenericRelationship ? FindMatchingHintTableRelationships<Schema, Relationships, Field$1['hint'], Field$1['name']> & {
547
+ branch: 'found-in-table-via-hint';
548
+ hint: Field$1['hint'];
549
+ } : FindMatchingHintViewRelationships<Schema, Relationships, Field$1['hint'], Field$1['name']> extends GenericRelationship ? FindMatchingHintViewRelationships<Schema, Relationships, Field$1['hint'], Field$1['name']> & {
550
+ branch: 'found-in-view-via-hint';
551
+ hint: Field$1['hint'];
552
+ } : SelectQueryError<'Failed to find matching relation via hint'> : FindMatchingTableRelationships<Schema, Relationships, Field$1['name']> extends GenericRelationship ? FindMatchingTableRelationships<Schema, Relationships, Field$1['name']> & {
553
+ branch: 'found-in-table-via-name';
554
+ name: Field$1['name'];
555
+ } : FindMatchingViewRelationships<Schema, Relationships, Field$1['name']> extends GenericRelationship ? FindMatchingViewRelationships<Schema, Relationships, Field$1['name']> & {
556
+ branch: 'found-in-view-via-name';
557
+ name: Field$1['name'];
558
+ } : SelectQueryError<'Failed to find matching relation via name'>;
559
+ type JsonPathToAccessor<Path extends string> = Path extends `${infer P1}->${infer P2}` ? P2 extends `>${infer Rest}` ? JsonPathToAccessor<`${P1}.${Rest}`> : P2 extends string ? JsonPathToAccessor<`${P1}.${P2}`> : Path : Path extends `>${infer Rest}` ? JsonPathToAccessor<Rest> : Path extends `${infer P1}::${infer _}` ? JsonPathToAccessor<P1> : Path extends `${infer P1}${')' | ','}${infer _}` ? P1 : Path;
560
+ type JsonPathToType<T, Path extends string> = Path extends '' ? T : ContainsNull<T> extends true ? JsonPathToType<Exclude<T, null>, Path> : Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? JsonPathToType<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
561
+ type IsStringUnion<T> = string extends T ? false : T extends string ? [T] extends [never] ? false : true : false;
562
+ type MatchingFunctionBySetofFrom<Fn$1 extends GenericFunction, TableName$1 extends string> = Fn$1['SetofOptions'] extends GenericSetofOption ? TableName$1 extends Fn$1['SetofOptions']['from'] ? Fn$1 : never : false;
563
+ type FindMatchingFunctionBySetofFrom<FnUnion, TableName$1 extends string> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionBySetofFrom<Fn, TableName$1> : false;
564
+ type ComputedField<Schema extends GenericSchema, RelationName extends keyof TablesAndViews$2<Schema>, FieldName$1 extends keyof TablesAndViews$2<Schema>[RelationName]['Row']> = FieldName$1 extends keyof Schema['Functions'] ? Schema['Functions'][FieldName$1] extends {
565
+ Args: {
566
+ '': TablesAndViews$2<Schema>[RelationName]['Row'];
567
+ };
568
+ Returns: any;
569
+ } ? FieldName$1 : never : never;
570
+ type GetComputedFields<Schema extends GenericSchema, RelationName extends keyof TablesAndViews$2<Schema>> = { [K in keyof TablesAndViews$2<Schema>[RelationName]['Row']]: ComputedField<Schema, RelationName, K> }[keyof TablesAndViews$2<Schema>[RelationName]['Row']];
571
+ //#endregion
572
+ //#region src/types/types.d.ts
573
+ /**
574
+ * Response format
575
+ *
576
+ * {@link https://github.com/supabase/supabase-js/issues/32}
577
+ */
578
+ interface PostgrestResponseBase {
579
+ status: number;
580
+ statusText: string;
581
+ }
582
+ interface PostgrestResponseSuccess<T> extends PostgrestResponseBase {
583
+ error: null;
584
+ data: T;
585
+ count: number | null;
586
+ }
587
+ interface PostgrestResponseFailure extends PostgrestResponseBase {
588
+ error: PostgrestError;
589
+ data: null;
590
+ count: null;
591
+ }
592
+ type PostgrestSingleResponse<T> = PostgrestResponseSuccess<T> | PostgrestResponseFailure;
593
+ type PostgrestMaybeSingleResponse<T> = PostgrestSingleResponse<T | null>;
594
+ type PostgrestResponse<T> = PostgrestSingleResponse<T[]>;
595
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
596
+ type SimplifyDeep<Type, ExcludeType = never> = ConditionalSimplifyDeep<Type, ExcludeType | NonRecursiveType | Set<unknown> | Map<unknown, unknown>, object>;
597
+ type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType ? Type : Type extends IncludeType ? { [TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType> } : Type;
598
+ type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
599
+ type BuiltIns = Primitive | void | Date | RegExp;
600
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
601
+ type IsValidResultOverride<Result$1, NewResult, ErrorResult, ErrorNewResult> = Result$1 extends any[] ? NewResult extends any[] ? true : ErrorResult : NewResult extends any[] ? ErrorNewResult : true;
602
+ /**
603
+ * Utility type to check if array types match between Result and NewResult.
604
+ * Returns either the valid NewResult type or an error message type.
605
+ */
606
+ type CheckMatchingArrayTypes<Result$1, NewResult> = Result$1 extends SelectQueryError<string> ? NewResult : IsValidResultOverride<Result$1, NewResult, {
607
+ Error: 'Type mismatch: Cannot cast array result to a single object. Use .overrideTypes<Array<YourType>> or .returns<Array<YourType>> (deprecated) for array results or .single() to convert the result to a single object';
608
+ }, {
609
+ Error: 'Type mismatch: Cannot cast single object to array type. Remove Array wrapper from return type or make sure you are not using .single() up in the calling chain';
610
+ }> extends infer ValidationResult ? ValidationResult extends true ? ContainsNull<Result$1> extends true ? NewResult | null : NewResult : ValidationResult : never;
611
+ type Simplify<T> = T extends object ? { [K in keyof T]: T[K] } : T;
612
+ type ExplicitKeys<T> = { [K in keyof T]: string extends K ? never : K }[keyof T];
613
+ type MergeExplicit<New, Row> = { [K in ExplicitKeys<New> | ExplicitKeys<Row>]: K extends keyof New ? K extends keyof Row ? Row[K] extends SelectQueryError<string> ? New[K] : New[K] extends any[] ? Row[K] extends any[] ? Array<Simplify<MergeDeep<NonNullable<New[K][number]>, NonNullable<Row[K][number]>>>> : New[K] : IsPlainObject<NonNullable<New[K]>> extends true ? IsPlainObject<NonNullable<Row[K]>> extends true ? ContainsNull<New[K]> extends true ?
614
+ // If the override wants to preserve optionality
615
+ Simplify<MergeDeep<NonNullable<New[K]>, NonNullable<Row[K]>>> | null : Simplify<MergeDeep<New[K], NonNullable<Row[K]>>> : New[K] : New[K] : New[K] : K extends keyof Row ? Row[K] : never };
616
+ type MergeDeep<New, Row> = Simplify<MergeExplicit<New, Row> & (string extends keyof Row ? {
617
+ [K: string]: Row[string];
618
+ } : {})>;
619
+ type IsPlainObject<T> = T extends any[] ? false : T extends object ? true : false;
620
+ type MergePartialResult<NewResult, Result$1, Options> = Options extends {
621
+ merge: true;
622
+ } ? Result$1 extends any[] ? NewResult extends any[] ? Array<Simplify<MergeDeep<NewResult[number], Result$1[number]>>> : never : Simplify<MergeDeep<NewResult, Result$1>> : NewResult;
623
+ //#endregion
624
+ //#region src/PostgrestBuilder.d.ts
625
+ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOptions, Result$1, ThrowOnError extends boolean = false> implements PromiseLike<ThrowOnError extends true ? PostgrestResponseSuccess<Result$1> : PostgrestSingleResponse<Result$1>> {
626
+ protected method: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE';
627
+ protected url: URL;
628
+ protected headers: Headers;
629
+ protected schema?: string;
630
+ protected body?: unknown;
631
+ protected shouldThrowOnError: boolean;
632
+ protected signal?: AbortSignal;
633
+ protected fetch: Fetch;
634
+ protected isMaybeSingle: boolean;
635
+ /**
636
+ * Creates a builder configured for a specific PostgREST request.
637
+ *
638
+ * @example
639
+ * ```ts
640
+ * import PostgrestQueryBuilder from '@supabase/postgrest-js'
641
+ *
642
+ * const builder = new PostgrestQueryBuilder(
643
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
644
+ * { headers: new Headers({ apikey: 'public-anon-key' }) }
645
+ * )
646
+ * ```
647
+ */
648
+ constructor(builder: {
649
+ method: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE';
650
+ url: URL;
651
+ headers: HeadersInit;
652
+ schema?: string;
653
+ body?: unknown;
654
+ shouldThrowOnError?: boolean;
655
+ signal?: AbortSignal;
656
+ fetch?: Fetch;
657
+ isMaybeSingle?: boolean;
658
+ });
659
+ /**
660
+ * If there's an error with the query, throwOnError will reject the promise by
661
+ * throwing the error instead of returning it as part of a successful response.
662
+ *
663
+ * {@link https://github.com/supabase/supabase-js/issues/92}
664
+ */
665
+ throwOnError(): this & PostgrestBuilder<ClientOptions, Result$1, true>;
666
+ /**
667
+ * Set an HTTP header for the request.
668
+ */
669
+ setHeader(name: string, value: string): this;
670
+ then<TResult1 = (ThrowOnError extends true ? PostgrestResponseSuccess<Result$1> : PostgrestSingleResponse<Result$1>), TResult2 = never>(onfulfilled?: ((value: ThrowOnError extends true ? PostgrestResponseSuccess<Result$1> : PostgrestSingleResponse<Result$1>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
671
+ /**
672
+ * Override the type of the returned `data`.
673
+ *
674
+ * @typeParam NewResult - The new result type to override with
675
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
676
+ */
677
+ returns<NewResult>(): PostgrestBuilder<ClientOptions, CheckMatchingArrayTypes<Result$1, NewResult>, ThrowOnError>;
678
+ /**
679
+ * Override the type of the returned `data` field in the response.
680
+ *
681
+ * @typeParam NewResult - The new type to cast the response data to
682
+ * @typeParam Options - Optional type configuration (defaults to { merge: true })
683
+ * @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true)
684
+ * @example
685
+ * ```typescript
686
+ * // Merge with existing types (default behavior)
687
+ * const query = supabase
688
+ * .from('users')
689
+ * .select()
690
+ * .overrideTypes<{ custom_field: string }>()
691
+ *
692
+ * // Replace existing types completely
693
+ * const replaceQuery = supabase
694
+ * .from('users')
695
+ * .select()
696
+ * .overrideTypes<{ id: number; name: string }, { merge: false }>()
697
+ * ```
698
+ * @returns A PostgrestBuilder instance with the new type
699
+ */
700
+ overrideTypes<NewResult, Options extends {
701
+ merge?: boolean;
702
+ } = {
703
+ merge: true;
704
+ }>(): PostgrestBuilder<ClientOptions, IsValidResultOverride<Result$1, NewResult, false, false> extends true ? ContainsNull<Result$1> extends true ? MergePartialResult<NewResult, NonNullable<Result$1>, Options> | null : MergePartialResult<NewResult, Result$1, Options> : CheckMatchingArrayTypes<Result$1, NewResult>, ThrowOnError>;
705
+ }
706
+ //#endregion
707
+ //#region src/types/feature-flags.d.ts
708
+ type IsPostgrest13<PostgrestVersion extends string | undefined> = PostgrestVersion extends `13${string}` ? true : false;
709
+ type IsPostgrest14<PostgrestVersion extends string | undefined> = PostgrestVersion extends `14${string}` ? true : false;
710
+ type IsPostgrestVersionGreaterThan12<PostgrestVersion extends string | undefined> = IsPostgrest13<PostgrestVersion> extends true ? true : IsPostgrest14<PostgrestVersion> extends true ? true : false;
711
+ type MaxAffectedEnabled<PostgrestVersion extends string | undefined> = IsPostgrestVersionGreaterThan12<PostgrestVersion> extends true ? true : false;
712
+ type SpreadOnManyEnabled<PostgrestVersion extends string | undefined> = IsPostgrestVersionGreaterThan12<PostgrestVersion> extends true ? true : false;
713
+ //#endregion
714
+ //#region src/select-query-parser/result.d.ts
715
+ /**
716
+ * Main entry point for constructing the result type of a PostgREST query.
717
+ *
718
+ * @param Schema - Database schema.
719
+ * @param Row - The type of a row in the current table.
720
+ * @param RelationName - The name of the current table or view.
721
+ * @param Relationships - Relationships of the current table.
722
+ * @param Query - The select query string literal to parse.
723
+ */
724
+ type GetResult<Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName, Relationships, Query extends string, ClientOptions extends ClientServerOptions> = IsAny$1<Schema> extends true ? ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RelationName extends string ? ProcessNodesWithoutSchema<ParsedQuery> : any : ParsedQuery : any : Relationships extends null ? ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RPCCallNodes<ParsedQuery, RelationName extends string ? RelationName : 'rpc_call', Row> : ParsedQuery : Row : ParseQuery<Query> extends infer ParsedQuery ? ParsedQuery extends Ast.Node[] ? RelationName extends string ? Relationships extends GenericRelationship[] ? ProcessNodes<ClientOptions, Schema, Row, RelationName, Relationships, ParsedQuery> : SelectQueryError<'Invalid Relationships cannot infer result type'> : SelectQueryError<'Invalid RelationName cannot infer result type'> : ParsedQuery : never;
725
+ type ProcessSimpleFieldWithoutSchema<Field$1 extends Ast.FieldNode> = Field$1['aggregateFunction'] extends AggregateFunctions ? { [K in GetFieldNodeResultName<Field$1>]: Field$1['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field$1['castType']> : number } : { [K in GetFieldNodeResultName<Field$1>]: Field$1['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field$1['castType']> : any };
726
+ type ProcessFieldNodeWithoutSchema<Node$1 extends Ast.FieldNode> = IsNonEmptyArray<Node$1['children']> extends true ? { [K in GetFieldNodeResultName<Node$1>]: Node$1['children'] extends Ast.Node[] ? ProcessNodesWithoutSchema<Node$1['children']>[] : ProcessSimpleFieldWithoutSchema<Node$1> } : ProcessSimpleFieldWithoutSchema<Node$1>;
727
+ /**
728
+ * Processes a single Node without schema and returns the resulting TypeScript type.
729
+ */
730
+ type ProcessNodeWithoutSchema<Node$1 extends Ast.Node> = Node$1 extends Ast.StarNode ? any : Node$1 extends Ast.SpreadNode ? Node$1['target']['children'] extends Ast.StarNode[] ? any : Node$1['target']['children'] extends Ast.FieldNode[] ? { [P in Node$1['target']['children'][number] as GetFieldNodeResultName<P>]: P['castType'] extends PostgreSQLTypes ? TypeScriptTypes<P['castType']> : any } : any : Node$1 extends Ast.FieldNode ? ProcessFieldNodeWithoutSchema<Node$1> : any;
731
+ /**
732
+ * Processes nodes when Schema is any, providing basic type inference
733
+ */
734
+ type ProcessNodesWithoutSchema<Nodes$1 extends Ast.Node[], Acc extends Record<string, unknown> = {}> = Nodes$1 extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessNodeWithoutSchema<FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? ProcessNodesWithoutSchema<RestNodes, Acc & FieldResult> : FieldResult : any : any : any : Prettify<Acc>;
735
+ /**
736
+ * Processes a single Node from a select chained after a rpc call
737
+ *
738
+ * @param Row - The type of a row in the current table.
739
+ * @param RelationName - The name of the current rpc function
740
+ * @param NodeType - The Node to process.
741
+ */
742
+ type ProcessRPCNode<Row extends Record<string, unknown>, RelationName extends string, NodeType extends Ast.Node> = NodeType['type'] extends Ast.StarNode['type'] ? Row : NodeType['type'] extends Ast.FieldNode['type'] ? ProcessSimpleField<Row, RelationName, Extract<NodeType, Ast.FieldNode>> : SelectQueryError<'RPC Unsupported node type.'>;
743
+ /**
744
+ * Process select call that can be chained after an rpc call
745
+ */
746
+ type RPCCallNodes<Nodes$1 extends Ast.Node[], RelationName extends string, Row extends Record<string, unknown>, Acc extends Record<string, unknown> = {}> = Nodes$1 extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessRPCNode<Row, RelationName, FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? RPCCallNodes<RestNodes, RelationName, Row, Acc & FieldResult> : FieldResult extends SelectQueryError<infer E> ? SelectQueryError<E> : SelectQueryError<'Could not retrieve a valid record or error value'> : SelectQueryError<'Processing node failed.'> : SelectQueryError<'Invalid rest nodes array in RPC call'> : SelectQueryError<'Invalid first node in RPC call'> : Prettify<Acc>;
747
+ /**
748
+ * Recursively processes an array of Nodes and accumulates the resulting TypeScript type.
749
+ *
750
+ * @param Schema - Database schema.
751
+ * @param Row - The type of a row in the current table.
752
+ * @param RelationName - The name of the current table or view.
753
+ * @param Relationships - Relationships of the current table.
754
+ * @param Nodes - An array of AST nodes to process.
755
+ * @param Acc - Accumulator for the constructed type.
756
+ */
757
+ type ProcessNodes<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Nodes$1 extends Ast.Node[], Acc extends Record<string, unknown> = {}> = CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes$1> extends false ? Nodes$1 extends [infer FirstNode, ...infer RestNodes] ? FirstNode extends Ast.Node ? RestNodes extends Ast.Node[] ? ProcessNode<ClientOptions, Schema, Row, RelationName, Relationships, FirstNode> extends infer FieldResult ? FieldResult extends Record<string, unknown> ? ProcessNodes<ClientOptions, Schema, Row, RelationName, Relationships, RestNodes, Acc & FieldResult> : FieldResult extends SelectQueryError<infer E> ? SelectQueryError<E> : SelectQueryError<'Could not retrieve a valid record or error value'> : SelectQueryError<'Processing node failed.'> : SelectQueryError<'Invalid rest nodes array type in ProcessNodes'> : SelectQueryError<'Invalid first node type in ProcessNodes'> : Prettify<Acc> : Prettify<CheckDuplicateEmbededReference<Schema, RelationName, Relationships, Nodes$1>>;
758
+ /**
759
+ * Processes a single Node and returns the resulting TypeScript type.
760
+ *
761
+ * @param Schema - Database schema.
762
+ * @param Row - The type of a row in the current table.
763
+ * @param RelationName - The name of the current table or view.
764
+ * @param Relationships - Relationships of the current table.
765
+ * @param NodeType - The Node to process.
766
+ */
767
+ type ProcessNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], NodeType extends Ast.Node> = NodeType['type'] extends Ast.StarNode['type'] ? GetComputedFields<Schema, RelationName> extends never ? Row : Omit<Row, GetComputedFields<Schema, RelationName>> : NodeType['type'] extends Ast.SpreadNode['type'] ? ProcessSpreadNode<ClientOptions, Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.SpreadNode>> : NodeType['type'] extends Ast.FieldNode['type'] ? ProcessFieldNode<ClientOptions, Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.FieldNode>> : SelectQueryError<'Unsupported node type.'>;
768
+ /**
769
+ * Processes a FieldNode and returns the resulting TypeScript type.
770
+ *
771
+ * @param Schema - Database schema.
772
+ * @param Row - The type of a row in the current table.
773
+ * @param RelationName - The name of the current table or view.
774
+ * @param Relationships - Relationships of the current table.
775
+ * @param Field - The FieldNode to process.
776
+ */
777
+ type ProcessFieldNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Field$1 extends Ast.FieldNode> = Field$1['children'] extends [] ? {} : IsNonEmptyArray<Field$1['children']> extends true ? ProcessEmbeddedResource<ClientOptions, Schema, Relationships, Field$1, RelationName> : ProcessSimpleField<Row, RelationName, Field$1>;
778
+ type ResolveJsonPathType<Value, Path extends string | undefined, CastType$1 extends PostgreSQLTypes> = Path extends string ? JsonPathToType<Value, Path> extends never ? TypeScriptTypes<CastType$1> : JsonPathToType<Value, Path> extends infer PathResult ? PathResult extends string ? PathResult : IsStringUnion<PathResult> extends true ? PathResult : CastType$1 extends 'json' ? PathResult : TypeScriptTypes<CastType$1> : TypeScriptTypes<CastType$1> : TypeScriptTypes<CastType$1>;
779
+ /**
780
+ * Processes a simple field (without embedded resources).
781
+ *
782
+ * @param Row - The type of a row in the current table.
783
+ * @param RelationName - The name of the current table or view.
784
+ * @param Field - The FieldNode to process.
785
+ */
786
+ type ProcessSimpleField<Row extends Record<string, unknown>, RelationName extends string, Field$1 extends Ast.FieldNode> = Field$1['name'] extends keyof Row | 'count' ? Field$1['aggregateFunction'] extends AggregateFunctions ? { [K in GetFieldNodeResultName<Field$1>]: Field$1['castType'] extends PostgreSQLTypes ? TypeScriptTypes<Field$1['castType']> : number } : { [K in GetFieldNodeResultName<Field$1>]: Field$1['castType'] extends PostgreSQLTypes ? ResolveJsonPathType<Row[Field$1['name']], Field$1['jsonPath'], Field$1['castType']> : Row[Field$1['name']] } : SelectQueryError<`column '${Field$1['name']}' does not exist on '${RelationName}'.`>;
787
+ /**
788
+ * Processes an embedded resource (relation).
789
+ *
790
+ * @param Schema - Database schema.
791
+ * @param Row - The type of a row in the current table.
792
+ * @param RelationName - The name of the current table or view.
793
+ * @param Relationships - Relationships of the current table.
794
+ * @param Field - The FieldNode to process.
795
+ */
796
+ type ProcessEmbeddedResource<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relationships extends GenericRelationship[], Field$1 extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$2<Schema> & string> = ResolveRelationship<Schema, Relationships, Field$1, CurrentTableOrView> extends infer Resolved ? Resolved extends {
797
+ referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>;
798
+ relation: GenericRelationship & {
799
+ match: 'refrel' | 'col' | 'fkname' | 'func';
800
+ };
801
+ direction: string;
802
+ } ? ProcessEmbeddedResourceResult<ClientOptions, Schema, Resolved, Field$1, CurrentTableOrView> : { [K in GetFieldNodeResultName<Field$1>]: Resolved } : { [K in GetFieldNodeResultName<Field$1>]: SelectQueryError<'Failed to resolve relationship.'> & string };
803
+ /**
804
+ * Helper type to process the result of an embedded resource.
805
+ */
806
+ type ProcessEmbeddedResourceResult<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Resolved$1 extends {
807
+ referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>;
808
+ relation: GenericRelationship & {
809
+ match: 'refrel' | 'col' | 'fkname' | 'func';
810
+ isNotNullable?: boolean;
811
+ referencedRelation: string;
812
+ isSetofReturn?: boolean;
813
+ };
814
+ direction: string;
815
+ }, Field$1 extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews$2<Schema>> = ProcessNodes<ClientOptions, Schema, Resolved$1['referencedTable']['Row'], Resolved$1['relation']['match'] extends 'func' ? Resolved$1['relation']['referencedRelation'] : Field$1['name'], Resolved$1['referencedTable']['Relationships'], Field$1['children'] extends undefined ? [] : Exclude<Field$1['children'], undefined> extends Ast.Node[] ? Exclude<Field$1['children'], undefined> : []> extends infer ProcessedChildren ? { [K in GetFieldNodeResultName<Field$1>]: Resolved$1['direction'] extends 'forward' ? Field$1 extends {
816
+ innerJoin: true;
817
+ } ? Resolved$1['relation']['isOneToOne'] extends true ? ProcessedChildren : ProcessedChildren[] : Resolved$1['relation']['isOneToOne'] extends true ? Resolved$1['relation']['match'] extends 'func' ? Resolved$1['relation']['isNotNullable'] extends true ? Resolved$1['relation']['isSetofReturn'] extends true ? ProcessedChildren : { [P in keyof ProcessedChildren]: ProcessedChildren[P] | null } : ProcessedChildren | null : ProcessedChildren | null : ProcessedChildren[] : Resolved$1['relation']['referencedRelation'] extends CurrentTableOrView ? Resolved$1['relation']['match'] extends 'col' ? IsRelationNullable<TablesAndViews$2<Schema>[CurrentTableOrView], Resolved$1['relation']> extends true ? ProcessedChildren | null : ProcessedChildren : ProcessedChildren[] : IsRelationNullable<TablesAndViews$2<Schema>[CurrentTableOrView], Resolved$1['relation']> extends true ? Field$1 extends {
818
+ innerJoin: true;
819
+ } ? ProcessedChildren : ProcessedChildren | null : ProcessedChildren } : { [K in GetFieldNodeResultName<Field$1>]: SelectQueryError<'Failed to process embedded resource nodes.'> & string };
820
+ /**
821
+ * Processes a SpreadNode by processing its target node.
822
+ *
823
+ * @param Schema - Database schema.
824
+ * @param Row - The type of a row in the current table.
825
+ * @param RelationName - The name of the current table or view.
826
+ * @param Relationships - Relationships of the current table.
827
+ * @param Spread - The SpreadNode to process.
828
+ */
829
+ type ProcessSpreadNode<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, RelationName extends string, Relationships extends GenericRelationship[], Spread extends Ast.SpreadNode> = ProcessNode<ClientOptions, Schema, Row, RelationName, Relationships, Spread['target']> extends infer Result ? Result extends SelectQueryError<infer E> ? SelectQueryError<E> : ExtractFirstProperty<Result> extends unknown[] ? SpreadOnManyEnabled<ClientOptions['PostgrestVersion']> extends true ? ProcessManyToManySpreadNodeResult<Result> : { [K in Spread['target']['name']]: SelectQueryError<`"${RelationName}" and "${Spread['target']['name']}" do not form a many-to-one or one-to-one relationship spread not possible`> } : ProcessSpreadNodeResult<Result> : never;
830
+ /**
831
+ * Helper type to process the result of a many-to-many spread node.
832
+ * Converts all fields in the spread object into arrays.
833
+ */
834
+ type ProcessManyToManySpreadNodeResult<Result$1> = Result$1 extends Record<string, SelectQueryError<string> | null> ? Result$1 : ExtractFirstProperty<Result$1> extends infer SpreadedObject ? SpreadedObject extends Array<Record<string, unknown>> ? { [K in keyof SpreadedObject[number]]: Array<SpreadedObject[number][K]> } : SelectQueryError<'An error occurred spreading the many-to-many object'> : SelectQueryError<'An error occurred spreading the many-to-many object'>;
835
+ /**
836
+ * Helper type to process the result of a spread node.
837
+ */
838
+ type ProcessSpreadNodeResult<Result$1> = Result$1 extends Record<string, SelectQueryError<string> | null> ? Result$1 : ExtractFirstProperty<Result$1> extends infer SpreadedObject ? ContainsNull<SpreadedObject> extends true ? Exclude<{ [K in keyof SpreadedObject]: SpreadedObject[K] | null }, null> : Exclude<{ [K in keyof SpreadedObject]: SpreadedObject[K] }, null> : SelectQueryError<'An error occurred spreading the object'>;
839
+ //#endregion
840
+ //#region src/PostgrestTransformBuilder.d.ts
841
+ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, Result$1, RelationName = unknown, Relationships = unknown, Method = unknown> extends PostgrestBuilder<ClientOptions, Result$1> {
842
+ /**
843
+ * Perform a SELECT on the query result.
844
+ *
845
+ * By default, `.insert()`, `.update()`, `.upsert()`, and `.delete()` do not
846
+ * return modified rows. By calling this method, modified rows are returned in
847
+ * `data`.
848
+ *
849
+ * @param columns - The columns to retrieve, separated by commas
850
+ */
851
+ select<Query extends string = '*', NewResultOne = GetResult<Schema, Row, RelationName, Relationships, Query, ClientOptions>>(columns?: Query): PostgrestFilterBuilder<ClientOptions, Schema, Row, Method extends 'RPC' ? Result$1 extends unknown[] ? NewResultOne[] : NewResultOne : NewResultOne[], RelationName, Relationships, Method>;
852
+ order<ColumnName extends string & keyof Row>(column: ColumnName, options?: {
853
+ ascending?: boolean;
854
+ nullsFirst?: boolean;
855
+ referencedTable?: undefined;
856
+ }): this;
857
+ order(column: string, options?: {
858
+ ascending?: boolean;
859
+ nullsFirst?: boolean;
860
+ referencedTable?: string;
861
+ }): this;
862
+ /**
863
+ * @deprecated Use `options.referencedTable` instead of `options.foreignTable`
864
+ */
865
+ order<ColumnName extends string & keyof Row>(column: ColumnName, options?: {
866
+ ascending?: boolean;
867
+ nullsFirst?: boolean;
868
+ foreignTable?: undefined;
869
+ }): this;
870
+ /**
871
+ * @deprecated Use `options.referencedTable` instead of `options.foreignTable`
872
+ */
873
+ order(column: string, options?: {
874
+ ascending?: boolean;
875
+ nullsFirst?: boolean;
876
+ foreignTable?: string;
877
+ }): this;
878
+ /**
879
+ * Limit the query result by `count`.
880
+ *
881
+ * @param count - The maximum number of rows to return
882
+ * @param options - Named parameters
883
+ * @param options.referencedTable - Set this to limit rows of referenced
884
+ * tables instead of the parent table
885
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
886
+ * instead
887
+ */
888
+ limit(count: number, {
889
+ foreignTable,
890
+ referencedTable
891
+ }?: {
892
+ foreignTable?: string;
893
+ referencedTable?: string;
894
+ }): this;
895
+ /**
896
+ * Limit the query result by starting at an offset `from` and ending at the offset `to`.
897
+ * Only records within this range are returned.
898
+ * This respects the query order and if there is no order clause the range could behave unexpectedly.
899
+ * The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
900
+ * and fourth rows of the query.
901
+ *
902
+ * @param from - The starting index from which to limit the result
903
+ * @param to - The last index to which to limit the result
904
+ * @param options - Named parameters
905
+ * @param options.referencedTable - Set this to limit rows of referenced
906
+ * tables instead of the parent table
907
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
908
+ * instead
909
+ */
910
+ range(from: number, to: number, {
911
+ foreignTable,
912
+ referencedTable
913
+ }?: {
914
+ foreignTable?: string;
915
+ referencedTable?: string;
916
+ }): this;
917
+ /**
918
+ * Set the AbortSignal for the fetch request.
919
+ *
920
+ * @param signal - The AbortSignal to use for the fetch request
921
+ */
922
+ abortSignal(signal: AbortSignal): this;
923
+ /**
924
+ * Return `data` as a single object instead of an array of objects.
925
+ *
926
+ * Query result must be one row (e.g. using `.limit(1)`), otherwise this
927
+ * returns an error.
928
+ */
929
+ single<ResultOne = (Result$1 extends (infer ResultOne)[] ? ResultOne : never)>(): PostgrestBuilder<ClientOptions, ResultOne>;
930
+ /**
931
+ * Return `data` as a single object instead of an array of objects.
932
+ *
933
+ * Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
934
+ * this returns an error.
935
+ */
936
+ maybeSingle<ResultOne = (Result$1 extends (infer ResultOne)[] ? ResultOne : never)>(): PostgrestBuilder<ClientOptions, ResultOne | null>;
937
+ /**
938
+ * Return `data` as a string in CSV format.
939
+ */
940
+ csv(): PostgrestBuilder<ClientOptions, string>;
941
+ /**
942
+ * Return `data` as an object in [GeoJSON](https://geojson.org) format.
943
+ */
944
+ geojson(): PostgrestBuilder<ClientOptions, Record<string, unknown>>;
945
+ /**
946
+ * Return `data` as the EXPLAIN plan for the query.
947
+ *
948
+ * You need to enable the
949
+ * [db_plan_enabled](https://supabase.com/docs/guides/database/debugging-performance#enabling-explain)
950
+ * setting before using this method.
951
+ *
952
+ * @param options - Named parameters
953
+ *
954
+ * @param options.analyze - If `true`, the query will be executed and the
955
+ * actual run time will be returned
956
+ *
957
+ * @param options.verbose - If `true`, the query identifier will be returned
958
+ * and `data` will include the output columns of the query
959
+ *
960
+ * @param options.settings - If `true`, include information on configuration
961
+ * parameters that affect query planning
962
+ *
963
+ * @param options.buffers - If `true`, include information on buffer usage
964
+ *
965
+ * @param options.wal - If `true`, include information on WAL record generation
966
+ *
967
+ * @param options.format - The format of the output, can be `"text"` (default)
968
+ * or `"json"`
969
+ */
970
+ explain({
971
+ analyze,
972
+ verbose,
973
+ settings,
974
+ buffers,
975
+ wal,
976
+ format
977
+ }?: {
978
+ analyze?: boolean;
979
+ verbose?: boolean;
980
+ settings?: boolean;
981
+ buffers?: boolean;
982
+ wal?: boolean;
983
+ format?: 'json' | 'text';
984
+ }): PostgrestBuilder<ClientOptions, Record<string, unknown>[], false> | PostgrestBuilder<ClientOptions, string, false>;
985
+ /**
986
+ * Rollback the query.
987
+ *
988
+ * `data` will still be returned, but the query is not committed.
989
+ */
990
+ rollback(): this;
991
+ /**
992
+ * Override the type of the returned `data`.
993
+ *
994
+ * @typeParam NewResult - The new result type to override with
995
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
996
+ */
997
+ returns<NewResult>(): PostgrestTransformBuilder<ClientOptions, Schema, Row, CheckMatchingArrayTypes<Result$1, NewResult>, RelationName, Relationships, Method>;
998
+ /**
999
+ * Set the maximum number of rows that can be affected by the query.
1000
+ * Only available in PostgREST v13+ and only works with PATCH and DELETE methods.
1001
+ *
1002
+ * @param value - The maximum number of rows that can be affected
1003
+ */
1004
+ maxAffected(value: number): MaxAffectedEnabled<ClientOptions['PostgrestVersion']> extends true ? Method extends 'PATCH' | 'DELETE' | 'RPC' ? this : InvalidMethodError<'maxAffected method only available on update or delete'> : InvalidMethodError<'maxAffected method only available on postgrest 13+'>;
1005
+ }
1006
+ //#endregion
1007
+ //#region src/PostgrestFilterBuilder.d.ts
1008
+ type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'isdistinct' | 'in' | 'cs' | 'cd' | 'sl' | 'sr' | 'nxl' | 'nxr' | 'adj' | 'ov' | 'fts' | 'plfts' | 'phfts' | 'wfts' | 'match' | 'imatch';
1009
+ type IsStringOperator<Path extends string> = Path extends `${string}->>${string}` ? true : false;
1010
+ type ResolveFilterValue<Schema extends GenericSchema, Row extends Record<string, unknown>, ColumnName extends string> = ColumnName extends `${infer RelationshipTable}.${infer Remainder}` ? Remainder extends `${infer _}.${infer _}` ? ResolveFilterValue<Schema, Row, Remainder> : ResolveFilterRelationshipValue<Schema, RelationshipTable, Remainder> : ColumnName extends keyof Row ? Row[ColumnName] : IsStringOperator<ColumnName> extends true ? string : JsonPathToType<Row, JsonPathToAccessor<ColumnName>> extends infer JsonPathValue ? JsonPathValue extends never ? never : JsonPathValue : never;
1011
+ type ResolveFilterRelationshipValue<Schema extends GenericSchema, RelationshipTable$1 extends string, RelationshipColumn extends string> = Schema['Tables'] & Schema['Views'] extends infer TablesAndViews ? RelationshipTable$1 extends keyof TablesAndViews ? 'Row' extends keyof TablesAndViews[RelationshipTable$1] ? RelationshipColumn extends keyof TablesAndViews[RelationshipTable$1]['Row'] ? TablesAndViews[RelationshipTable$1]['Row'][RelationshipColumn] : unknown : unknown : unknown : never;
1012
+ type InvalidMethodError<S extends string> = {
1013
+ Error: S;
1014
+ };
1015
+ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, Result$1, RelationName = unknown, Relationships = unknown, Method = unknown> extends PostgrestTransformBuilder<ClientOptions, Schema, Row, Result$1, RelationName, Relationships, Method> {
1016
+ /**
1017
+ * Match only rows where `column` is equal to `value`.
1018
+ *
1019
+ * To check if the value of `column` is NULL, you should use `.is()` instead.
1020
+ *
1021
+ * @param column - The column to filter on
1022
+ * @param value - The value to filter with
1023
+ */
1024
+ eq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? NonNullable<unknown> : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? NonNullable<ResolvedFilterValue> : never): this;
1025
+ /**
1026
+ * Match only rows where `column` is not equal to `value`.
1027
+ *
1028
+ * @param column - The column to filter on
1029
+ * @param value - The value to filter with
1030
+ */
1031
+ neq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never): this;
1032
+ gt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
1033
+ gt(column: string, value: unknown): this;
1034
+ gte<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
1035
+ gte(column: string, value: unknown): this;
1036
+ lt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
1037
+ lt(column: string, value: unknown): this;
1038
+ lte<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
1039
+ lte(column: string, value: unknown): this;
1040
+ like<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
1041
+ like(column: string, pattern: string): this;
1042
+ likeAllOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
1043
+ likeAllOf(column: string, patterns: readonly string[]): this;
1044
+ likeAnyOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
1045
+ likeAnyOf(column: string, patterns: readonly string[]): this;
1046
+ ilike<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
1047
+ ilike(column: string, pattern: string): this;
1048
+ ilikeAllOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
1049
+ ilikeAllOf(column: string, patterns: readonly string[]): this;
1050
+ ilikeAnyOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
1051
+ ilikeAnyOf(column: string, patterns: readonly string[]): this;
1052
+ regexMatch<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
1053
+ regexMatch(column: string, pattern: string): this;
1054
+ regexIMatch<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
1055
+ regexIMatch(column: string, pattern: string): this;
1056
+ is<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName] & (boolean | null)): this;
1057
+ is(column: string, value: boolean | null): this;
1058
+ /**
1059
+ * Match only rows where `column` IS DISTINCT FROM `value`.
1060
+ *
1061
+ * Unlike `.neq()`, this treats `NULL` as a comparable value. Two `NULL` values
1062
+ * are considered equal (not distinct), and comparing `NULL` with any non-NULL
1063
+ * value returns true (distinct).
1064
+ *
1065
+ * @param column - The column to filter on
1066
+ * @param value - The value to filter with
1067
+ */
1068
+ isDistinct<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never): this;
1069
+ /**
1070
+ * Match only rows where `column` is included in the `values` array.
1071
+ *
1072
+ * @param column - The column to filter on
1073
+ * @param values - The values array to filter with
1074
+ */
1075
+ in<ColumnName extends string>(column: ColumnName, values: ReadonlyArray<ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never>): this;
1076
+ /**
1077
+ * Match only rows where `column` is NOT included in the `values` array.
1078
+ *
1079
+ * @param column - The column to filter on
1080
+ * @param values - The values array to filter with
1081
+ */
1082
+ notIn<ColumnName extends string>(column: ColumnName, values: ReadonlyArray<ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never>): this;
1083
+ contains<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>): this;
1084
+ contains(column: string, value: string | readonly unknown[] | Record<string, unknown>): this;
1085
+ containedBy<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>): this;
1086
+ containedBy(column: string, value: string | readonly unknown[] | Record<string, unknown>): this;
1087
+ rangeGt<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
1088
+ rangeGt(column: string, range: string): this;
1089
+ rangeGte<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
1090
+ rangeGte(column: string, range: string): this;
1091
+ rangeLt<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
1092
+ rangeLt(column: string, range: string): this;
1093
+ rangeLte<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
1094
+ rangeLte(column: string, range: string): this;
1095
+ rangeAdjacent<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
1096
+ rangeAdjacent(column: string, range: string): this;
1097
+ overlaps<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]>): this;
1098
+ overlaps(column: string, value: string | readonly unknown[]): this;
1099
+ textSearch<ColumnName extends string & keyof Row>(column: ColumnName, query: string, options?: {
1100
+ config?: string;
1101
+ type?: 'plain' | 'phrase' | 'websearch';
1102
+ }): this;
1103
+ textSearch(column: string, query: string, options?: {
1104
+ config?: string;
1105
+ type?: 'plain' | 'phrase' | 'websearch';
1106
+ }): this;
1107
+ match<ColumnName extends string & keyof Row>(query: Record<ColumnName, Row[ColumnName]>): this;
1108
+ match(query: Record<string, unknown>): this;
1109
+ not<ColumnName extends string & keyof Row>(column: ColumnName, operator: FilterOperator, value: Row[ColumnName]): this;
1110
+ not(column: string, operator: string, value: unknown): this;
1111
+ /**
1112
+ * Match only rows which satisfy at least one of the filters.
1113
+ *
1114
+ * Unlike most filters, `filters` is used as-is and needs to follow [PostgREST
1115
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
1116
+ * to make sure it's properly sanitized.
1117
+ *
1118
+ * It's currently not possible to do an `.or()` filter across multiple tables.
1119
+ *
1120
+ * @param filters - The filters to use, following PostgREST syntax
1121
+ * @param options - Named parameters
1122
+ * @param options.referencedTable - Set this to filter on referenced tables
1123
+ * instead of the parent table
1124
+ * @param options.foreignTable - Deprecated, use `referencedTable` instead
1125
+ */
1126
+ or(filters: string, {
1127
+ foreignTable,
1128
+ referencedTable
1129
+ }?: {
1130
+ foreignTable?: string;
1131
+ referencedTable?: string;
1132
+ }): this;
1133
+ filter<ColumnName extends string & keyof Row>(column: ColumnName, operator: `${'' | 'not.'}${FilterOperator}`, value: unknown): this;
1134
+ filter(column: string, operator: string, value: unknown): this;
1135
+ }
1136
+ //#endregion
1137
+ //#region src/PostgrestQueryBuilder.d.ts
1138
+ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relation$1 extends GenericTable | GenericView, RelationName = unknown, Relationships = (Relation$1 extends {
1139
+ Relationships: infer R;
1140
+ } ? R : unknown)> {
1141
+ url: URL;
1142
+ headers: Headers;
1143
+ schema?: string;
1144
+ signal?: AbortSignal;
1145
+ fetch?: Fetch;
1146
+ /**
1147
+ * Creates a query builder scoped to a Postgres table or view.
1148
+ *
1149
+ * @example
1150
+ * ```ts
1151
+ * import PostgrestQueryBuilder from '@supabase/postgrest-js'
1152
+ *
1153
+ * const query = new PostgrestQueryBuilder(
1154
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
1155
+ * { headers: { apikey: 'public-anon-key' } }
1156
+ * )
1157
+ * ```
1158
+ */
1159
+ constructor(url: URL, {
1160
+ headers,
1161
+ schema,
1162
+ fetch
1163
+ }: {
1164
+ headers?: HeadersInit;
1165
+ schema?: string;
1166
+ fetch?: Fetch;
1167
+ });
1168
+ /**
1169
+ * Perform a SELECT query on the table or view.
1170
+ *
1171
+ * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
1172
+ *
1173
+ * @param options - Named parameters
1174
+ *
1175
+ * @param options.head - When set to `true`, `data` will not be returned.
1176
+ * Useful if you only need the count.
1177
+ *
1178
+ * @param options.count - Count algorithm to use to count rows in the table or view.
1179
+ *
1180
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1181
+ * hood.
1182
+ *
1183
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1184
+ * statistics under the hood.
1185
+ *
1186
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1187
+ * numbers.
1188
+ */
1189
+ select<Query extends string = '*', ResultOne = GetResult<Schema, Relation$1['Row'], RelationName, Relationships, Query, ClientOptions>>(columns?: Query, options?: {
1190
+ head?: boolean;
1191
+ count?: 'exact' | 'planned' | 'estimated';
1192
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], ResultOne[], RelationName, Relationships, 'GET'>;
1193
+ insert<Row extends (Relation$1 extends {
1194
+ Insert: unknown;
1195
+ } ? Relation$1['Insert'] : never)>(values: Row, options?: {
1196
+ count?: 'exact' | 'planned' | 'estimated';
1197
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
1198
+ insert<Row extends (Relation$1 extends {
1199
+ Insert: unknown;
1200
+ } ? Relation$1['Insert'] : never)>(values: Row[], options?: {
1201
+ count?: 'exact' | 'planned' | 'estimated';
1202
+ defaultToNull?: boolean;
1203
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
1204
+ upsert<Row extends (Relation$1 extends {
1205
+ Insert: unknown;
1206
+ } ? Relation$1['Insert'] : never)>(values: Row, options?: {
1207
+ onConflict?: string;
1208
+ ignoreDuplicates?: boolean;
1209
+ count?: 'exact' | 'planned' | 'estimated';
1210
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
1211
+ upsert<Row extends (Relation$1 extends {
1212
+ Insert: unknown;
1213
+ } ? Relation$1['Insert'] : never)>(values: Row[], options?: {
1214
+ onConflict?: string;
1215
+ ignoreDuplicates?: boolean;
1216
+ count?: 'exact' | 'planned' | 'estimated';
1217
+ defaultToNull?: boolean;
1218
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
1219
+ /**
1220
+ * Perform an UPDATE on the table or view.
1221
+ *
1222
+ * By default, updated rows are not returned. To return it, chain the call
1223
+ * with `.select()` after filters.
1224
+ *
1225
+ * @param values - The values to update with
1226
+ *
1227
+ * @param options - Named parameters
1228
+ *
1229
+ * @param options.count - Count algorithm to use to count updated rows.
1230
+ *
1231
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1232
+ * hood.
1233
+ *
1234
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1235
+ * statistics under the hood.
1236
+ *
1237
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1238
+ * numbers.
1239
+ */
1240
+ update<Row extends (Relation$1 extends {
1241
+ Update: unknown;
1242
+ } ? Relation$1['Update'] : never)>(values: Row, {
1243
+ count
1244
+ }?: {
1245
+ count?: 'exact' | 'planned' | 'estimated';
1246
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'PATCH'>;
1247
+ /**
1248
+ * Perform a DELETE on the table or view.
1249
+ *
1250
+ * By default, deleted rows are not returned. To return it, chain the call
1251
+ * with `.select()` after filters.
1252
+ *
1253
+ * @param options - Named parameters
1254
+ *
1255
+ * @param options.count - Count algorithm to use to count deleted rows.
1256
+ *
1257
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1258
+ * hood.
1259
+ *
1260
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1261
+ * statistics under the hood.
1262
+ *
1263
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1264
+ * numbers.
1265
+ */
1266
+ delete({
1267
+ count
1268
+ }?: {
1269
+ count?: 'exact' | 'planned' | 'estimated';
1270
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'DELETE'>;
1271
+ }
1272
+ //#endregion
1273
+ //#region src/types/common/rpc.d.ts
1274
+ type IsMatchingArgs<FnArgs extends GenericFunction['Args'], PassedArgs extends GenericFunction['Args']> = [FnArgs] extends [Record<PropertyKey, never>] ? PassedArgs extends Record<PropertyKey, never> ? true : false : keyof PassedArgs extends keyof FnArgs ? PassedArgs extends FnArgs ? true : false : false;
1275
+ type MatchingFunctionArgs<Fn$1 extends GenericFunction, Args extends GenericFunction['Args']> = Fn$1 extends {
1276
+ Args: infer A extends GenericFunction['Args'];
1277
+ } ? IsMatchingArgs<A, Args> extends true ? Fn$1 : never : false;
1278
+ type FindMatchingFunctionByArgs<FnUnion, Args extends GenericFunction['Args']> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionArgs<Fn, Args> : false;
1279
+ type TablesAndViews$1<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>;
1280
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
1281
+ type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends (() => infer R) ? R : never;
1282
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1283
+ type ExactMatch<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false;
1284
+ type ExtractExactFunction<Fns, Args> = Fns extends infer F ? F extends GenericFunction ? ExactMatch<F['Args'], Args> extends true ? F : never : never : never;
1285
+ type IsNever<T> = [T] extends [never] ? true : false;
1286
+ type RpcFunctionNotFound<FnName> = {
1287
+ Row: any;
1288
+ Result: {
1289
+ error: true;
1290
+ } & "Couldn't infer function definition matching provided arguments";
1291
+ RelationName: FnName;
1292
+ Relationships: null;
1293
+ };
1294
+ type CrossSchemaError<TableRef extends string> = {
1295
+ error: true;
1296
+ } & `Function returns SETOF from a different schema ('${TableRef}'). Use .overrideTypes<YourReturnType>() to specify the return type explicitly.`;
1297
+ type GetRpcFunctionFilterBuilderByArgs<Schema extends GenericSchema, FnName extends string & keyof Schema['Functions'], Args> = {
1298
+ 0: Schema['Functions'][FnName];
1299
+ 1: IsAny<Schema> extends true ? any : IsNever<Args> extends true ? IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true ? LastOf<Schema['Functions'][FnName]> : ExtractExactFunction<Schema['Functions'][FnName], Args> : Args extends Record<PropertyKey, never> ? LastOf<Schema['Functions'][FnName]> : Args extends GenericFunction['Args'] ? IsNever<LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>> extends true ? LastOf<Schema['Functions'][FnName]> : LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>> : ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction ? ExtractExactFunction<Schema['Functions'][FnName], Args> : any;
1300
+ }[1] extends infer Fn ? IsAny<Fn> extends true ? {
1301
+ Row: any;
1302
+ Result: any;
1303
+ RelationName: FnName;
1304
+ Relationships: null;
1305
+ } : Fn extends GenericFunction ? {
1306
+ Row: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] extends keyof TablesAndViews$1<Schema> ? TablesAndViews$1<Schema>[Fn['SetofOptions']['to']]['Row'] : Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : CrossSchemaError<Fn['SetofOptions']['to'] & string> : Fn['Returns'] extends Record<string, unknown> ? Fn['Returns'] : CrossSchemaError<Fn['SetofOptions']['to'] & string> : Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : Fn['Returns'] extends Record<string, unknown> ? Fn['Returns'] : never;
1307
+ Result: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['isSetofReturn'] extends true ? Fn['SetofOptions']['isOneToOne'] extends true ? Fn['Returns'][] : Fn['Returns'] : Fn['Returns'] : Fn['Returns'];
1308
+ RelationName: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] : FnName;
1309
+ Relationships: Fn['SetofOptions'] extends GenericSetofOption ? Fn['SetofOptions']['to'] extends keyof Schema['Tables'] ? Schema['Tables'][Fn['SetofOptions']['to']]['Relationships'] : Fn['SetofOptions']['to'] extends keyof Schema['Views'] ? Schema['Views'][Fn['SetofOptions']['to']]['Relationships'] : null : null;
1310
+ } : Fn extends false ? RpcFunctionNotFound<FnName> : RpcFunctionNotFound<FnName> : RpcFunctionNotFound<FnName>;
1311
+ //#endregion
1312
+ //#region src/PostgrestClient.d.ts
1313
+ /**
1314
+ * PostgREST client.
1315
+ *
1316
+ * @typeParam Database - Types for the schema from the [type
1317
+ * generator](https://supabase.com/docs/reference/javascript/next/typescript-support)
1318
+ *
1319
+ * @typeParam SchemaName - Postgres schema to switch to. Must be a string
1320
+ * literal, the same one passed to the constructor. If the schema is not
1321
+ * `"public"`, this must be supplied manually.
1322
+ */
1323
+ declare class PostgrestClient<Database = any, ClientOptions extends ClientServerOptions = (Database extends {
1324
+ __InternalSupabase: infer I extends ClientServerOptions;
1325
+ } ? I : {}), SchemaName extends string & keyof Omit<Database, '__InternalSupabase'> = ('public' extends keyof Omit<Database, '__InternalSupabase'> ? 'public' : string & keyof Omit<Database, '__InternalSupabase'>), Schema extends GenericSchema = (Omit<Database, '__InternalSupabase'>[SchemaName] extends GenericSchema ? Omit<Database, '__InternalSupabase'>[SchemaName] : any)> {
1326
+ url: string;
1327
+ headers: Headers;
1328
+ schemaName?: SchemaName;
1329
+ fetch?: Fetch;
1330
+ /**
1331
+ * Creates a PostgREST client.
1332
+ *
1333
+ * @param url - URL of the PostgREST endpoint
1334
+ * @param options - Named parameters
1335
+ * @param options.headers - Custom headers
1336
+ * @param options.schema - Postgres schema to switch to
1337
+ * @param options.fetch - Custom fetch
1338
+ * @example
1339
+ * ```ts
1340
+ * import PostgrestClient from '@supabase/postgrest-js'
1341
+ *
1342
+ * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
1343
+ * headers: { apikey: 'public-anon-key' },
1344
+ * schema: 'public',
1345
+ * })
1346
+ * ```
1347
+ */
1348
+ constructor(url: string, {
1349
+ headers,
1350
+ schema,
1351
+ fetch
1352
+ }?: {
1353
+ headers?: HeadersInit;
1354
+ schema?: SchemaName;
1355
+ fetch?: Fetch;
1356
+ });
1357
+ from<TableName$1 extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName$1]>(relation: TableName$1): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName$1>;
1358
+ from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>;
1359
+ /**
1360
+ * Select a schema to query or perform an function (rpc) call.
1361
+ *
1362
+ * The schema needs to be on the list of exposed schemas inside Supabase.
1363
+ *
1364
+ * @param schema - The schema to query
1365
+ */
1366
+ schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>;
1367
+ /**
1368
+ * Perform a function call.
1369
+ *
1370
+ * @param fn - The function name to call
1371
+ * @param args - The arguments to pass to the function call
1372
+ * @param options - Named parameters
1373
+ * @param options.head - When set to `true`, `data` will not be returned.
1374
+ * Useful if you only need the count.
1375
+ * @param options.get - When set to `true`, the function will be called with
1376
+ * read-only access mode.
1377
+ * @param options.count - Count algorithm to use to count rows returned by the
1378
+ * function. Only applicable for [set-returning
1379
+ * functions](https://www.postgresql.org/docs/current/functions-srf.html).
1380
+ *
1381
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1382
+ * hood.
1383
+ *
1384
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1385
+ * statistics under the hood.
1386
+ *
1387
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1388
+ * numbers.
1389
+ *
1390
+ * @example
1391
+ * ```ts
1392
+ * // For cross-schema functions where type inference fails, use overrideTypes:
1393
+ * const { data } = await supabase
1394
+ * .schema('schema_b')
1395
+ * .rpc('function_a', {})
1396
+ * .overrideTypes<{ id: string; user_id: string }[]>()
1397
+ * ```
1398
+ */
1399
+ rpc<FnName extends string & keyof Schema['Functions'], Args extends Schema['Functions'][FnName]['Args'] = never, FilterBuilder extends GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args> = GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args>>(fn: FnName, args?: Args, {
1400
+ head,
1401
+ get,
1402
+ count
1403
+ }?: {
1404
+ head?: boolean;
1405
+ get?: boolean;
1406
+ count?: 'exact' | 'planned' | 'estimated';
1407
+ }): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder['Row'], FilterBuilder['Result'], FilterBuilder['RelationName'], FilterBuilder['Relationships'], 'RPC'>;
1408
+ }
1409
+ //#endregion
1410
+ //#region src/index.d.ts
1411
+ declare const _default: {
1412
+ PostgrestClient: typeof PostgrestClient;
1413
+ PostgrestQueryBuilder: typeof PostgrestQueryBuilder;
1414
+ PostgrestFilterBuilder: typeof PostgrestFilterBuilder;
1415
+ PostgrestTransformBuilder: typeof PostgrestTransformBuilder;
1416
+ PostgrestBuilder: typeof PostgrestBuilder;
1417
+ PostgrestError: typeof PostgrestError;
1418
+ };
1419
+ //#endregion
1420
+ export { PostgrestBuilder, PostgrestClient, type ClientServerOptions as PostgrestClientOptions, PostgrestError, PostgrestFilterBuilder, type PostgrestMaybeSingleResponse, PostgrestQueryBuilder, type PostgrestResponse, type PostgrestResponseFailure, type PostgrestResponseSuccess, type PostgrestSingleResponse, PostgrestTransformBuilder, type GetResult as UnstableGetResult, _default as default };
1421
+ //# sourceMappingURL=index.d.mts.map