@cloudbase/wx-cloud-client-sdk 1.6.0 → 1.7.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ import "./polyfill";
2
+ import MySqlQueryBuilder from "./MySqlQueryBuilder";
3
+ import { ClientServerOptions, GetGenericDatabaseWithOptions } from "../postgrest";
4
+ import { Fetch, GenericSchema } from "../postgrest/types";
5
+ /**
6
+ * MySQL client.
7
+ */
8
+ export default class MySqlClient<Database = any, ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<Database, {}>["options"]> {
9
+ protected url: string;
10
+ protected headers: Headers;
11
+ protected fetch?: Fetch;
12
+ /**
13
+ * Creates a MySQL client.
14
+ *
15
+ * @param url - URL of the MySQL endpoint
16
+ * @param options - Named parameters
17
+ * @param options.headers - Custom headers
18
+ * @param options.fetch - Custom fetch
19
+ */
20
+ constructor(url: string, { headers, fetch, }?: {
21
+ headers?: HeadersInit;
22
+ fetch?: Fetch;
23
+ });
24
+ from<Schema extends GenericSchema, TableName extends string & keyof Schema["Tables"], Table extends Schema["Tables"][TableName]>(relation: TableName): MySqlQueryBuilder<ClientOptions, Schema, Table, TableName>;
25
+ from<Schema extends GenericSchema, ViewName extends string & keyof Schema["Views"], View extends Schema["Views"][ViewName]>(relation: ViewName): MySqlQueryBuilder<ClientOptions, Schema, View, ViewName>;
26
+ }
@@ -0,0 +1,11 @@
1
+ import { ClientServerOptions, PostgrestFilterBuilder } from "../postgrest";
2
+ import { GenericSchema } from "../postgrest/types";
3
+ declare class MySqlFilterBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown, Method extends "GET" | "POST" | "HEAD" | "PATCH" | "DELETE" = "GET"> extends PostgrestFilterBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method> {
4
+ constructor({ method, url, headers, fetch, }: {
5
+ method: Method;
6
+ url: URL;
7
+ headers?: HeadersInit;
8
+ fetch?: any;
9
+ });
10
+ }
11
+ export default MySqlFilterBuilder;
@@ -0,0 +1,11 @@
1
+ import { ClientServerOptions, PostgrestQueryBuilder } from "../postgrest";
2
+ import { GenericSchema, GenericTable, GenericView } from "../postgrest/types";
3
+ declare class MySqlQueryBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relation extends GenericTable | GenericView, RelationName = unknown, Relationships = Relation extends {
4
+ Relationships: infer R;
5
+ } ? R : unknown> extends PostgrestQueryBuilder<ClientOptions, Schema, Relation, RelationName, Relationships> {
6
+ constructor(url: URL, { headers, fetch, }: {
7
+ headers?: HeadersInit;
8
+ fetch?: any;
9
+ });
10
+ }
11
+ export default MySqlQueryBuilder;
@@ -0,0 +1,7 @@
1
+ import MySqlClient from "./MySqlClient";
2
+ export { MySqlClient };
3
+ declare const _default: {
4
+ MySqlClient: typeof MySqlClient;
5
+ };
6
+ export default _default;
7
+ export type { PostgrestResponse, PostgrestResponseFailure, PostgrestResponseSuccess, PostgrestSingleResponse, PostgrestMaybeSingleResponse, ClientServerOptions, GetGenericDatabaseWithOptions, } from "../postgrest";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Headers polyfill for environments without native Headers support
3
+ * 兼容的Headers类实现
4
+ */
5
+ declare class _Headers {
6
+ private map;
7
+ constructor(init?: HeadersInit | Record<string, string> | string[][]);
8
+ /**
9
+ * 添加头部信息,如果已存在则追加
10
+ * @param name 头部名称
11
+ * @param value 头部值
12
+ */
13
+ append(name: string, value: string): void;
14
+ /**
15
+ * 删除指定头部
16
+ * @param name 头部名称
17
+ */
18
+ delete(name: string): void;
19
+ /**
20
+ * 迭代所有头部
21
+ * @param callback 回调函数
22
+ * @param thisArg 回调函数的this指向
23
+ */
24
+ forEach(callback: (value: string, key: string, parent: Headers) => void, thisArg?: any): void;
25
+ /**
26
+ * 获取指定头部的值
27
+ * @param name 头部名称
28
+ * @returns 头部值,不存在则返回null
29
+ */
30
+ get(name: string): string | null;
31
+ /**
32
+ * 检查指定头部是否存在
33
+ * @param name 头部名称
34
+ * @returns 是否存在
35
+ */
36
+ has(name: string): boolean;
37
+ /**
38
+ * 设置头部信息,如果已存在则覆盖
39
+ * @param name 头部名称
40
+ * @param value 头部值
41
+ */
42
+ set(name: string, value: string): void;
43
+ /**
44
+ * 生成迭代器,用于for...of循环
45
+ * @returns 迭代器
46
+ */
47
+ entries(): IterableIterator<[string, string]>;
48
+ /**
49
+ * 生成键名迭代器
50
+ * @returns 键名迭代器
51
+ */
52
+ keys(): IterableIterator<string>;
53
+ /**
54
+ * 生成值迭代器
55
+ * @returns 值迭代器
56
+ */
57
+ values(): IterableIterator<string>;
58
+ /**
59
+ * 获取所有Set-Cookie头部值
60
+ * @returns Set-Cookie值的数组
61
+ */
62
+ getSetCookie(): string[];
63
+ /**
64
+ * 转换为普通对象
65
+ * @returns 包含所有头部的对象
66
+ */
67
+ toJSON(): Record<string, string>;
68
+ /**
69
+ * 迭代器接口,用于for...of循环
70
+ */
71
+ [Symbol.iterator](): IterableIterator<[string, string]>;
72
+ }
@@ -0,0 +1,70 @@
1
+ import type { Fetch, PostgrestSingleResponse, PostgrestResponseSuccess, CheckMatchingArrayTypes, MergePartialResult, IsValidResultOverride, ClientServerOptions } from "./types";
2
+ import { ContainsNull } from "./select-query-parser/types";
3
+ export default abstract class PostgrestBuilder<ClientOptions extends ClientServerOptions, Result, ThrowOnError extends boolean = false> implements PromiseLike<ThrowOnError extends true ? PostgrestResponseSuccess<Result> : PostgrestSingleResponse<Result>> {
4
+ protected method: "GET" | "HEAD" | "POST" | "PATCH" | "DELETE";
5
+ protected url: URL;
6
+ protected headers: Headers;
7
+ protected schema?: string;
8
+ protected body?: unknown;
9
+ protected shouldThrowOnError: boolean;
10
+ protected signal?: AbortSignal;
11
+ protected fetch: Fetch;
12
+ protected isMaybeSingle: boolean;
13
+ constructor(builder: {
14
+ method: "GET" | "HEAD" | "POST" | "PATCH" | "DELETE";
15
+ url: URL;
16
+ headers: HeadersInit;
17
+ schema?: string;
18
+ body?: unknown;
19
+ shouldThrowOnError?: boolean;
20
+ signal?: AbortSignal;
21
+ fetch?: Fetch;
22
+ isMaybeSingle?: boolean;
23
+ });
24
+ /**
25
+ * If there's an error with the query, throwOnError will reject the promise by
26
+ * throwing the error instead of returning it as part of a successful response.
27
+ *
28
+ * {@link https://github.com/supabase/supabase-js/issues/92}
29
+ */
30
+ throwOnError(): this & PostgrestBuilder<ClientOptions, Result, true>;
31
+ /**
32
+ * Set an HTTP header for the request.
33
+ */
34
+ setHeader(name: string, value: string): this;
35
+ then<TResult1 = ThrowOnError extends true ? PostgrestResponseSuccess<Result> : PostgrestSingleResponse<Result>, TResult2 = never>(onfulfilled?: ((value: ThrowOnError extends true ? PostgrestResponseSuccess<Result> : PostgrestSingleResponse<Result>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
36
+ /**
37
+ * Override the type of the returned `data`.
38
+ *
39
+ * @typeParam NewResult - The new result type to override with
40
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
41
+ */
42
+ returns<NewResult>(): PostgrestBuilder<ClientOptions, CheckMatchingArrayTypes<Result, NewResult>, ThrowOnError>;
43
+ /**
44
+ * Override the type of the returned `data` field in the response.
45
+ *
46
+ * @typeParam NewResult - The new type to cast the response data to
47
+ * @typeParam Options - Optional type configuration (defaults to { merge: true })
48
+ * @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true)
49
+ * @example
50
+ * ```typescript
51
+ * // Merge with existing types (default behavior)
52
+ * const query = supabase
53
+ * .from('users')
54
+ * .select()
55
+ * .overrideTypes<{ custom_field: string }>()
56
+ *
57
+ * // Replace existing types completely
58
+ * const replaceQuery = supabase
59
+ * .from('users')
60
+ * .select()
61
+ * .overrideTypes<{ id: number; name: string }, { merge: false }>()
62
+ * ```
63
+ * @returns A PostgrestBuilder instance with the new type
64
+ */
65
+ overrideTypes<NewResult, Options extends {
66
+ merge?: boolean;
67
+ } = {
68
+ merge: true;
69
+ }>(): PostgrestBuilder<ClientOptions, IsValidResultOverride<Result, NewResult, false, false> extends true ? ContainsNull<Result> extends true ? MergePartialResult<NewResult, NonNullable<Result>, Options> | null : MergePartialResult<NewResult, Result, Options> : CheckMatchingArrayTypes<Result, NewResult>, ThrowOnError>;
70
+ }
@@ -0,0 +1,73 @@
1
+ import PostgrestQueryBuilder from "./PostgrestQueryBuilder";
2
+ import PostgrestFilterBuilder from "./PostgrestFilterBuilder";
3
+ import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOptions } from "./types";
4
+ /**
5
+ * PostgREST client.
6
+ *
7
+ * @typeParam Database - Types for the schema from the [type
8
+ * generator](https://supabase.com/docs/reference/javascript/next/typescript-support)
9
+ *
10
+ * @typeParam SchemaName - Postgres schema to switch to. Must be a string
11
+ * literal, the same one passed to the constructor. If the schema is not
12
+ * `"public"`, this must be supplied manually.
13
+ */
14
+ export default class PostgrestClient<Database = any, ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<Database, {
15
+ PostgrestVersion: "12";
16
+ }>["options"], SchemaName extends string & keyof GetGenericDatabaseWithOptions<Database>["db"] = "public" extends keyof GetGenericDatabaseWithOptions<Database>["db"] ? "public" : string & keyof GetGenericDatabaseWithOptions<Database>["db"], Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>["db"][SchemaName] extends GenericSchema ? GetGenericDatabaseWithOptions<Database>["db"][SchemaName] : any> {
17
+ url: string;
18
+ headers: Headers;
19
+ schemaName?: SchemaName;
20
+ fetch?: Fetch;
21
+ /**
22
+ * Creates a PostgREST client.
23
+ *
24
+ * @param url - URL of the PostgREST endpoint
25
+ * @param options - Named parameters
26
+ * @param options.headers - Custom headers
27
+ * @param options.schema - Postgres schema to switch to
28
+ * @param options.fetch - Custom fetch
29
+ */
30
+ constructor(url: string, { headers, schema, fetch, }?: {
31
+ headers?: HeadersInit;
32
+ schema?: SchemaName;
33
+ fetch?: Fetch;
34
+ });
35
+ from<TableName extends string & keyof Schema["Tables"], Table extends Schema["Tables"][TableName]>(relation: TableName): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName>;
36
+ from<ViewName extends string & keyof Schema["Views"], View extends Schema["Views"][ViewName]>(relation: ViewName): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>;
37
+ /**
38
+ * Select a schema to query or perform an function (rpc) call.
39
+ *
40
+ * The schema needs to be on the list of exposed schemas inside Supabase.
41
+ *
42
+ * @param schema - The schema to query
43
+ */
44
+ schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>["db"]>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>;
45
+ /**
46
+ * Perform a function call.
47
+ *
48
+ * @param fn - The function name to call
49
+ * @param args - The arguments to pass to the function call
50
+ * @param options - Named parameters
51
+ * @param options.head - When set to `true`, `data` will not be returned.
52
+ * Useful if you only need the count.
53
+ * @param options.get - When set to `true`, the function will be called with
54
+ * read-only access mode.
55
+ * @param options.count - Count algorithm to use to count rows returned by the
56
+ * function. Only applicable for [set-returning
57
+ * functions](https://www.postgresql.org/docs/current/functions-srf.html).
58
+ *
59
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
60
+ * hood.
61
+ *
62
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
63
+ * statistics under the hood.
64
+ *
65
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
66
+ * numbers.
67
+ */
68
+ rpc<FnName extends string & keyof Schema["Functions"], Fn extends Schema["Functions"][FnName]>(fn: FnName, args?: Fn["Args"], { head, get, count, }?: {
69
+ head?: boolean;
70
+ get?: boolean;
71
+ count?: "exact" | "planned" | "estimated";
72
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Fn["Returns"] extends any[] ? Fn["Returns"][number] extends Record<string, unknown> ? Fn["Returns"][number] : never : never, Fn["Returns"], FnName, null, "RPC">;
73
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Error format
3
+ *
4
+ * {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
5
+ */
6
+ export default class PostgrestError extends Error {
7
+ details: string;
8
+ hint: string;
9
+ code: string;
10
+ constructor(context: {
11
+ message: string;
12
+ details: string;
13
+ hint: string;
14
+ code: string;
15
+ });
16
+ }
@@ -0,0 +1,107 @@
1
+ import PostgrestTransformBuilder from "./PostgrestTransformBuilder";
2
+ import { JsonPathToAccessor, JsonPathToType } from "./select-query-parser/utils";
3
+ import { ClientServerOptions, GenericSchema } from "./types";
4
+ type FilterOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "is" | "in" | "cs" | "cd" | "sl" | "sr" | "nxl" | "nxr" | "adj" | "ov" | "fts" | "plfts" | "phfts" | "wfts";
5
+ export type IsStringOperator<Path extends string> = Path extends `${string}->>${string}` ? true : false;
6
+ 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;
7
+ type ResolveFilterRelationshipValue<Schema extends GenericSchema, RelationshipTable extends string, RelationshipColumn extends string> = Schema["Tables"] & Schema["Views"] extends infer TablesAndViews ? RelationshipTable extends keyof TablesAndViews ? "Row" extends keyof TablesAndViews[RelationshipTable] ? RelationshipColumn extends keyof TablesAndViews[RelationshipTable]["Row"] ? TablesAndViews[RelationshipTable]["Row"][RelationshipColumn] : unknown : unknown : unknown : never;
8
+ export type InvalidMethodError<S extends string> = {
9
+ Error: S;
10
+ };
11
+ export default class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown, Method = unknown> extends PostgrestTransformBuilder<ClientOptions, Schema, Row, Result, RelationName, Relationships, Method> {
12
+ /**
13
+ * Match only rows where `column` is equal to `value`.
14
+ *
15
+ * To check if the value of `column` is NULL, you should use `.is()` instead.
16
+ *
17
+ * @param column - The column to filter on
18
+ * @param value - The value to filter with
19
+ */
20
+ 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;
21
+ /**
22
+ * Match only rows where `column` is not equal to `value`.
23
+ *
24
+ * @param column - The column to filter on
25
+ * @param value - The value to filter with
26
+ */
27
+ neq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never): this;
28
+ gt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
29
+ gt(column: string, value: unknown): this;
30
+ gte<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
31
+ gte(column: string, value: unknown): this;
32
+ lt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
33
+ lt(column: string, value: unknown): this;
34
+ lte<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
35
+ lte(column: string, value: unknown): this;
36
+ like<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
37
+ like(column: string, pattern: string): this;
38
+ likeAllOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
39
+ likeAllOf(column: string, patterns: readonly string[]): this;
40
+ likeAnyOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
41
+ likeAnyOf(column: string, patterns: readonly string[]): this;
42
+ ilike<ColumnName extends string & keyof Row>(column: ColumnName, pattern: string): this;
43
+ ilike(column: string, pattern: string): this;
44
+ ilikeAllOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
45
+ ilikeAllOf(column: string, patterns: readonly string[]): this;
46
+ ilikeAnyOf<ColumnName extends string & keyof Row>(column: ColumnName, patterns: readonly string[]): this;
47
+ ilikeAnyOf(column: string, patterns: readonly string[]): this;
48
+ is<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName] & (boolean | null)): this;
49
+ is(column: string, value: boolean | null): this;
50
+ /**
51
+ * Match only rows where `column` is included in the `values` array.
52
+ *
53
+ * @param column - The column to filter on
54
+ * @param values - The values array to filter with
55
+ */
56
+ 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;
57
+ contains<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>): this;
58
+ contains(column: string, value: string | readonly unknown[] | Record<string, unknown>): this;
59
+ containedBy<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>): this;
60
+ containedBy(column: string, value: string | readonly unknown[] | Record<string, unknown>): this;
61
+ rangeGt<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
62
+ rangeGt(column: string, range: string): this;
63
+ rangeGte<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
64
+ rangeGte(column: string, range: string): this;
65
+ rangeLt<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
66
+ rangeLt(column: string, range: string): this;
67
+ rangeLte<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
68
+ rangeLte(column: string, range: string): this;
69
+ rangeAdjacent<ColumnName extends string & keyof Row>(column: ColumnName, range: string): this;
70
+ rangeAdjacent(column: string, range: string): this;
71
+ overlaps<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]>): this;
72
+ overlaps(column: string, value: string | readonly unknown[]): this;
73
+ textSearch<ColumnName extends string & keyof Row>(column: ColumnName, query: string, options?: {
74
+ config?: string;
75
+ type?: "plain" | "phrase" | "websearch";
76
+ }): this;
77
+ textSearch(column: string, query: string, options?: {
78
+ config?: string;
79
+ type?: "plain" | "phrase" | "websearch";
80
+ }): this;
81
+ match<ColumnName extends string & keyof Row>(query: Record<ColumnName, Row[ColumnName]>): this;
82
+ match(query: Record<string, unknown>): this;
83
+ not<ColumnName extends string & keyof Row>(column: ColumnName, operator: FilterOperator, value: Row[ColumnName]): this;
84
+ not(column: string, operator: string, value: unknown): this;
85
+ /**
86
+ * Match only rows which satisfy at least one of the filters.
87
+ *
88
+ * Unlike most filters, `filters` is used as-is and needs to follow [PostgREST
89
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
90
+ * to make sure it's properly sanitized.
91
+ *
92
+ * It's currently not possible to do an `.or()` filter across multiple tables.
93
+ *
94
+ * @param filters - The filters to use, following PostgREST syntax
95
+ * @param options - Named parameters
96
+ * @param options.referencedTable - Set this to filter on referenced tables
97
+ * instead of the parent table
98
+ * @param options.foreignTable - Deprecated, use `referencedTable` instead
99
+ */
100
+ or(filters: string, { foreignTable, referencedTable, }?: {
101
+ foreignTable?: string;
102
+ referencedTable?: string;
103
+ }): this;
104
+ filter<ColumnName extends string & keyof Row>(column: ColumnName, operator: `${"" | "not."}${FilterOperator}`, value: unknown): this;
105
+ filter(column: string, operator: string, value: unknown): this;
106
+ }
107
+ export {};
@@ -0,0 +1,116 @@
1
+ import PostgrestFilterBuilder from "./PostgrestFilterBuilder";
2
+ import { GetResult } from "./select-query-parser/result";
3
+ import { ClientServerOptions, Fetch, GenericSchema, GenericTable, GenericView } from "./types";
4
+ export default class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relation extends GenericTable | GenericView, RelationName = unknown, Relationships = Relation extends {
5
+ Relationships: infer R;
6
+ } ? R : unknown> {
7
+ url: URL;
8
+ headers: Headers;
9
+ schema?: string;
10
+ signal?: AbortSignal;
11
+ fetch?: Fetch;
12
+ constructor(url: URL, { headers, schema, fetch, }: {
13
+ headers?: HeadersInit;
14
+ schema?: string;
15
+ fetch?: Fetch;
16
+ });
17
+ /**
18
+ * Perform a SELECT query on the table or view.
19
+ *
20
+ * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
21
+ *
22
+ * @param options - Named parameters
23
+ *
24
+ * @param options.head - When set to `true`, `data` will not be returned.
25
+ * Useful if you only need the count.
26
+ *
27
+ * @param options.count - Count algorithm to use to count rows in the table or view.
28
+ *
29
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
30
+ * hood.
31
+ *
32
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
33
+ * statistics under the hood.
34
+ *
35
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
36
+ * numbers.
37
+ */
38
+ select<Query extends string = "*", ResultOne = GetResult<Schema, Relation["Row"], RelationName, Relationships, Query, ClientOptions>>(columns?: Query, { head, count, }?: {
39
+ head?: boolean;
40
+ count?: "exact" | "planned" | "estimated";
41
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], ResultOne[], RelationName, Relationships, "GET">;
42
+ insert<Row extends Relation extends {
43
+ Insert: unknown;
44
+ } ? Relation["Insert"] : never>(values: Row, options?: {
45
+ count?: "exact" | "planned" | "estimated";
46
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "POST">;
47
+ insert<Row extends Relation extends {
48
+ Insert: unknown;
49
+ } ? Relation["Insert"] : never>(values: Row[], options?: {
50
+ count?: "exact" | "planned" | "estimated";
51
+ defaultToNull?: boolean;
52
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "POST">;
53
+ upsert<Row extends Relation extends {
54
+ Insert: unknown;
55
+ } ? Relation["Insert"] : never>(values: Row, options?: {
56
+ onConflict?: string;
57
+ ignoreDuplicates?: boolean;
58
+ count?: "exact" | "planned" | "estimated";
59
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "POST">;
60
+ upsert<Row extends Relation extends {
61
+ Insert: unknown;
62
+ } ? Relation["Insert"] : never>(values: Row[], options?: {
63
+ onConflict?: string;
64
+ ignoreDuplicates?: boolean;
65
+ count?: "exact" | "planned" | "estimated";
66
+ defaultToNull?: boolean;
67
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "POST">;
68
+ /**
69
+ * Perform an UPDATE on the table or view.
70
+ *
71
+ * By default, updated rows are not returned. To return it, chain the call
72
+ * with `.select()` after filters.
73
+ *
74
+ * @param values - The values to update with
75
+ *
76
+ * @param options - Named parameters
77
+ *
78
+ * @param options.count - Count algorithm to use to count updated rows.
79
+ *
80
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
81
+ * hood.
82
+ *
83
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
84
+ * statistics under the hood.
85
+ *
86
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
87
+ * numbers.
88
+ */
89
+ update<Row extends Relation extends {
90
+ Update: unknown;
91
+ } ? Relation["Update"] : never>(values: Row, { count, }?: {
92
+ count?: "exact" | "planned" | "estimated";
93
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "PATCH">;
94
+ /**
95
+ * Perform a DELETE on the table or view.
96
+ *
97
+ * By default, deleted rows are not returned. To return it, chain the call
98
+ * with `.select()` after filters.
99
+ *
100
+ * @param options - Named parameters
101
+ *
102
+ * @param options.count - Count algorithm to use to count deleted rows.
103
+ *
104
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
105
+ * hood.
106
+ *
107
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
108
+ * statistics under the hood.
109
+ *
110
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
111
+ * numbers.
112
+ */
113
+ delete({ count, }?: {
114
+ count?: "exact" | "planned" | "estimated";
115
+ }): PostgrestFilterBuilder<ClientOptions, Schema, Relation["Row"], null, RelationName, Relationships, "DELETE">;
116
+ }