@supabase/postgrest-js 3.0.0-next.2 → 3.0.0-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -672,7 +672,7 @@ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOption
672
672
  * ```ts
673
673
  * import { createClient } from '@supabase/supabase-js'
674
674
  *
675
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
675
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
676
676
  * const { data, error } = await supabase.from('users').select('*')
677
677
  * ```
678
678
  *
@@ -684,7 +684,7 @@ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOption
684
684
  *
685
685
  * const builder = new PostgrestQueryBuilder(
686
686
  * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
687
- * { headers: new Headers({ apikey: 'publishable-or-anon-key' }) }
687
+ * { headers: new Headers({ apikey: 'your-publishable-key' }) }
688
688
  * )
689
689
  * ```
690
690
  */
@@ -1649,6 +1649,8 @@ type ResolveFilterRelationshipValue<Schema extends GenericSchema, RelationshipTa
1649
1649
  type InvalidMethodError<S extends string> = {
1650
1650
  Error: S;
1651
1651
  };
1652
+ type NonNullableColumn<T extends Record<string, unknown>, Col extends string> = Col extends keyof T ? { [K in keyof T]: K extends Col ? NonNullable<T[K]> : T[K] } : T;
1653
+ type NarrowResultColumn<T, Col extends string> = T extends (infer Item)[] ? Item extends Record<string, unknown> ? Col extends keyof Item ? { [K in keyof Item]: K extends Col ? NonNullable<Item[K]> : Item[K] }[] : T : T : T extends Record<string, unknown> ? Col extends keyof T ? { [K in keyof T]: K extends Col ? NonNullable<T[K]> : T[K] } : T : T;
1652
1654
  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> {
1653
1655
  /**
1654
1656
  * Match only rows where `column` is equal to `value`.
@@ -1862,6 +1864,7 @@ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions,
1862
1864
  }): this;
1863
1865
  match<ColumnName extends string & keyof Row>(query: Record<ColumnName, Row[ColumnName]>): this;
1864
1866
  match(query: Record<string, unknown>): this;
1867
+ not<ColumnName extends string & keyof Row>(column: ColumnName, operator: 'is', value: null): PostgrestFilterBuilder<ClientOptions, Schema, NonNullableColumn<Row, ColumnName>, NarrowResultColumn<Result$1, ColumnName>, RelationName, Relationships, Method> & this;
1865
1868
  not<ColumnName extends string & keyof Row>(column: ColumnName, operator: FilterOperator, value: Row[ColumnName]): this;
1866
1869
  not(column: string, operator: string, value: unknown): this;
1867
1870
  /**
@@ -2059,7 +2062,7 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
2059
2062
  * ```ts
2060
2063
  * import { createClient } from '@supabase/supabase-js'
2061
2064
  *
2062
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
2065
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
2063
2066
  * const { data, error } = await supabase.from('users').select('*')
2064
2067
  * ```
2065
2068
  *
@@ -2069,7 +2072,7 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
2069
2072
  *
2070
2073
  * const query = new PostgrestQueryBuilder(
2071
2074
  * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
2072
- * { headers: { apikey: 'publishable-or-anon-key' }, retry: true }
2075
+ * { headers: { apikey: 'your-publishable-key' }, retry: true }
2073
2076
  * )
2074
2077
  * ```
2075
2078
  */
@@ -2871,40 +2874,355 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
2871
2874
  */
2872
2875
  select<Query extends string = '*', ResultOne = GetResult<Schema, Relation$1['Row'], RelationName, Relationships, Query, ClientOptions>>(columns?: Query, options?: {
2873
2876
  head?: boolean;
2874
- count?: 'exact' | 'planned' | 'estimated';
2877
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
2875
2878
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], ResultOne[], RelationName, Relationships, 'GET'>;
2879
+ /**
2880
+ * Perform an INSERT into the table or view.
2881
+ *
2882
+ * By default, inserted rows are not returned. To return it, chain the call
2883
+ * with `.select()`.
2884
+ *
2885
+ * @param values - The values to insert. Pass an object to insert a single row
2886
+ * or an array to insert multiple rows.
2887
+ *
2888
+ * @param options - Named parameters
2889
+ *
2890
+ * @param options.count - Count algorithm to use to count inserted rows.
2891
+ *
2892
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
2893
+ * hood.
2894
+ *
2895
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
2896
+ * statistics under the hood.
2897
+ *
2898
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
2899
+ * numbers.
2900
+ *
2901
+ * @param options.defaultToNull - Make missing fields default to `null`.
2902
+ * Otherwise, use the default value for the column. Only applies for bulk
2903
+ * inserts.
2904
+ *
2905
+ * @category Database
2906
+ *
2907
+ * @example Create a record
2908
+ * ```ts
2909
+ * const { error } = await supabase
2910
+ * .from('countries')
2911
+ * .insert({ id: 1, name: 'Mordor' })
2912
+ * ```
2913
+ *
2914
+ * @exampleSql Create a record
2915
+ * ```sql
2916
+ * create table
2917
+ * countries (id int8 primary key, name text);
2918
+ * ```
2919
+ *
2920
+ * @exampleResponse Create a record
2921
+ * ```json
2922
+ * {
2923
+ * "status": 201,
2924
+ * "statusText": "Created"
2925
+ * }
2926
+ * ```
2927
+ *
2928
+ * @example Create a record and return it
2929
+ * ```ts
2930
+ * const { data, error } = await supabase
2931
+ * .from('countries')
2932
+ * .insert({ id: 1, name: 'Mordor' })
2933
+ * .select()
2934
+ * ```
2935
+ *
2936
+ * @exampleSql Create a record and return it
2937
+ * ```sql
2938
+ * create table
2939
+ * countries (id int8 primary key, name text);
2940
+ * ```
2941
+ *
2942
+ * @exampleResponse Create a record and return it
2943
+ * ```json
2944
+ * {
2945
+ * "data": [
2946
+ * {
2947
+ * "id": 1,
2948
+ * "name": "Mordor"
2949
+ * }
2950
+ * ],
2951
+ * "status": 201,
2952
+ * "statusText": "Created"
2953
+ * }
2954
+ * ```
2955
+ *
2956
+ * @exampleDescription Bulk create
2957
+ * A bulk create operation is handled in a single transaction.
2958
+ * If any of the inserts fail, none of the rows are inserted.
2959
+ *
2960
+ * @example Bulk create
2961
+ * ```ts
2962
+ * const { error } = await supabase
2963
+ * .from('countries')
2964
+ * .insert([
2965
+ * { id: 1, name: 'Mordor' },
2966
+ * { id: 1, name: 'The Shire' },
2967
+ * ])
2968
+ * ```
2969
+ *
2970
+ * @exampleSql Bulk create
2971
+ * ```sql
2972
+ * create table
2973
+ * countries (id int8 primary key, name text);
2974
+ * ```
2975
+ *
2976
+ * @exampleResponse Bulk create
2977
+ * ```json
2978
+ * {
2979
+ * "error": {
2980
+ * "code": "23505",
2981
+ * "details": "Key (id)=(1) already exists.",
2982
+ * "hint": null,
2983
+ * "message": "duplicate key value violates unique constraint \"countries_pkey\""
2984
+ * },
2985
+ * "status": 409,
2986
+ * "statusText": "Conflict"
2987
+ * }
2988
+ * ```
2989
+ */
2876
2990
  insert<Row extends (Relation$1 extends {
2877
2991
  Insert: unknown;
2878
2992
  } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2879
2993
  Insert: unknown;
2880
- } ? Relation$1['Insert'] : never, Row>, options?: {
2881
- count?: 'exact' | 'planned' | 'estimated';
2882
- }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
2883
- insert<Row extends (Relation$1 extends {
2884
- Insert: unknown;
2885
- } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2994
+ } ? Relation$1['Insert'] : never, Row> | RejectExcessProperties<Relation$1 extends {
2886
2995
  Insert: unknown;
2887
- } ? Relation$1['Insert'] : never, Row>[], options?: {
2888
- count?: 'exact' | 'planned' | 'estimated';
2996
+ } ? Relation$1['Insert'] : never, Row>[], {
2997
+ count,
2998
+ defaultToNull
2999
+ }?: {
3000
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
2889
3001
  defaultToNull?: boolean;
2890
3002
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
3003
+ /**
3004
+ * Perform an UPSERT on the table or view. Depending on the column(s) passed
3005
+ * to `onConflict`, `.upsert()` allows you to perform the equivalent of
3006
+ * `.insert()` if a row with the corresponding `onConflict` columns doesn't
3007
+ * exist, or if it does exist, perform an alternative action depending on
3008
+ * `ignoreDuplicates`.
3009
+ *
3010
+ * By default, upserted rows are not returned. To return it, chain the call
3011
+ * with `.select()`.
3012
+ *
3013
+ * @param values - The values to upsert with. Pass an object to upsert a
3014
+ * single row or an array to upsert multiple rows.
3015
+ *
3016
+ * @param options - Named parameters
3017
+ *
3018
+ * @param options.onConflict - Comma-separated UNIQUE column(s) to specify how
3019
+ * duplicate rows are determined. Two rows are duplicates if all the
3020
+ * `onConflict` columns are equal.
3021
+ *
3022
+ * @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If
3023
+ * `false`, duplicate rows are merged with existing rows.
3024
+ *
3025
+ * @param options.count - Count algorithm to use to count upserted rows.
3026
+ *
3027
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
3028
+ * hood.
3029
+ *
3030
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
3031
+ * statistics under the hood.
3032
+ *
3033
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
3034
+ * numbers.
3035
+ *
3036
+ * @param options.defaultToNull - Make missing fields default to `null`.
3037
+ * Otherwise, use the default value for the column. This only applies when
3038
+ * inserting new rows, not when merging with existing rows under
3039
+ * `ignoreDuplicates: false`. This also only applies when doing bulk upserts.
3040
+ *
3041
+ * @example Upsert a single row using a unique key
3042
+ * ```ts
3043
+ * // Upserting a single row, overwriting based on the 'username' unique column
3044
+ * const { data, error } = await supabase
3045
+ * .from('users')
3046
+ * .upsert({ username: 'supabot' }, { onConflict: 'username' })
3047
+ *
3048
+ * // Example response:
3049
+ * // {
3050
+ * // data: [
3051
+ * // { id: 4, message: 'bar', username: 'supabot' }
3052
+ * // ],
3053
+ * // error: null
3054
+ * // }
3055
+ * ```
3056
+ *
3057
+ * @example Upsert with conflict resolution and exact row counting
3058
+ * ```ts
3059
+ * // Upserting and returning exact count
3060
+ * const { data, error, count } = await supabase
3061
+ * .from('users')
3062
+ * .upsert(
3063
+ * {
3064
+ * id: 3,
3065
+ * message: 'foo',
3066
+ * username: 'supabot'
3067
+ * },
3068
+ * {
3069
+ * onConflict: 'username',
3070
+ * count: 'exact'
3071
+ * }
3072
+ * )
3073
+ *
3074
+ * // Example response:
3075
+ * // {
3076
+ * // data: [
3077
+ * // {
3078
+ * // id: 42,
3079
+ * // handle: "saoirse",
3080
+ * // display_name: "Saoirse"
3081
+ * // }
3082
+ * // ],
3083
+ * // count: 1,
3084
+ * // error: null
3085
+ * // }
3086
+ * ```
3087
+ *
3088
+ * @category Database
3089
+ *
3090
+ * @remarks
3091
+ * - Primary keys must be included in `values` to use upsert.
3092
+ *
3093
+ * @example Upsert your data
3094
+ * ```ts
3095
+ * const { data, error } = await supabase
3096
+ * .from('instruments')
3097
+ * .upsert({ id: 1, name: 'piano' })
3098
+ * .select()
3099
+ * ```
3100
+ *
3101
+ * @exampleSql Upsert your data
3102
+ * ```sql
3103
+ * create table
3104
+ * instruments (id int8 primary key, name text);
3105
+ *
3106
+ * insert into
3107
+ * instruments (id, name)
3108
+ * values
3109
+ * (1, 'harpsichord');
3110
+ * ```
3111
+ *
3112
+ * @exampleResponse Upsert your data
3113
+ * ```json
3114
+ * {
3115
+ * "data": [
3116
+ * {
3117
+ * "id": 1,
3118
+ * "name": "piano"
3119
+ * }
3120
+ * ],
3121
+ * "status": 201,
3122
+ * "statusText": "Created"
3123
+ * }
3124
+ * ```
3125
+ *
3126
+ * @example Bulk Upsert your data
3127
+ * ```ts
3128
+ * const { data, error } = await supabase
3129
+ * .from('instruments')
3130
+ * .upsert([
3131
+ * { id: 1, name: 'piano' },
3132
+ * { id: 2, name: 'harp' },
3133
+ * ])
3134
+ * .select()
3135
+ * ```
3136
+ *
3137
+ * @exampleSql Bulk Upsert your data
3138
+ * ```sql
3139
+ * create table
3140
+ * instruments (id int8 primary key, name text);
3141
+ *
3142
+ * insert into
3143
+ * instruments (id, name)
3144
+ * values
3145
+ * (1, 'harpsichord');
3146
+ * ```
3147
+ *
3148
+ * @exampleResponse Bulk Upsert your data
3149
+ * ```json
3150
+ * {
3151
+ * "data": [
3152
+ * {
3153
+ * "id": 1,
3154
+ * "name": "piano"
3155
+ * },
3156
+ * {
3157
+ * "id": 2,
3158
+ * "name": "harp"
3159
+ * }
3160
+ * ],
3161
+ * "status": 201,
3162
+ * "statusText": "Created"
3163
+ * }
3164
+ * ```
3165
+ *
3166
+ * @exampleDescription Upserting into tables with constraints
3167
+ * In the following query, `upsert()` implicitly uses the `id`
3168
+ * (primary key) column to determine conflicts. If there is no existing
3169
+ * row with the same `id`, `upsert()` inserts a new row, which
3170
+ * will fail in this case as there is already a row with `handle` `"saoirse"`.
3171
+ * Using the `onConflict` option, you can instruct `upsert()` to use
3172
+ * another column with a unique constraint to determine conflicts.
3173
+ *
3174
+ * @example Upserting into tables with constraints
3175
+ * ```ts
3176
+ * const { data, error } = await supabase
3177
+ * .from('users')
3178
+ * .upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' })
3179
+ * .select()
3180
+ * ```
3181
+ *
3182
+ * @exampleSql Upserting into tables with constraints
3183
+ * ```sql
3184
+ * create table
3185
+ * users (
3186
+ * id int8 generated by default as identity primary key,
3187
+ * handle text not null unique,
3188
+ * display_name text
3189
+ * );
3190
+ *
3191
+ * insert into
3192
+ * users (id, handle, display_name)
3193
+ * values
3194
+ * (1, 'saoirse', null);
3195
+ * ```
3196
+ *
3197
+ * @exampleResponse Upserting into tables with constraints
3198
+ * ```json
3199
+ * {
3200
+ * "error": {
3201
+ * "code": "23505",
3202
+ * "details": "Key (handle)=(saoirse) already exists.",
3203
+ * "hint": null,
3204
+ * "message": "duplicate key value violates unique constraint \"users_handle_key\""
3205
+ * },
3206
+ * "status": 409,
3207
+ * "statusText": "Conflict"
3208
+ * }
3209
+ * ```
3210
+ */
2891
3211
  upsert<Row extends (Relation$1 extends {
2892
3212
  Insert: unknown;
2893
3213
  } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2894
3214
  Insert: unknown;
2895
- } ? Relation$1['Insert'] : never, Row>, options?: {
2896
- onConflict?: string;
2897
- ignoreDuplicates?: boolean;
2898
- count?: 'exact' | 'planned' | 'estimated';
2899
- }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
2900
- upsert<Row extends (Relation$1 extends {
3215
+ } ? Relation$1['Insert'] : never, Row> | RejectExcessProperties<Relation$1 extends {
2901
3216
  Insert: unknown;
2902
- } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2903
- Insert: unknown;
2904
- } ? Relation$1['Insert'] : never, Row>[], options?: {
3217
+ } ? Relation$1['Insert'] : never, Row>[], {
3218
+ onConflict,
3219
+ ignoreDuplicates,
3220
+ count,
3221
+ defaultToNull
3222
+ }?: {
2905
3223
  onConflict?: string;
2906
3224
  ignoreDuplicates?: boolean;
2907
- count?: 'exact' | 'planned' | 'estimated';
3225
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
2908
3226
  defaultToNull?: boolean;
2909
3227
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
2910
3228
  /**
@@ -3053,7 +3371,7 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
3053
3371
  } ? Relation$1['Update'] : never, Row>, {
3054
3372
  count
3055
3373
  }?: {
3056
- count?: 'exact' | 'planned' | 'estimated';
3374
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
3057
3375
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'PATCH'>;
3058
3376
  /**
3059
3377
  * Perform a DELETE on the table or view.
@@ -3176,7 +3494,7 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
3176
3494
  delete({
3177
3495
  count
3178
3496
  }?: {
3179
- count?: 'exact' | 'planned' | 'estimated';
3497
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
3180
3498
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'DELETE'>;
3181
3499
  }
3182
3500
  //#endregion
@@ -3257,7 +3575,7 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
3257
3575
  * ```ts
3258
3576
  * import { createClient } from '@supabase/supabase-js'
3259
3577
  *
3260
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
3578
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
3261
3579
  * const { data, error } = await supabase.from('profiles').select('*')
3262
3580
  * ```
3263
3581
  *
@@ -3272,7 +3590,7 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
3272
3590
  * import { PostgrestClient } from '@supabase/postgrest-js'
3273
3591
  *
3274
3592
  * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
3275
- * headers: { apikey: 'publishable-or-anon-key' },
3593
+ * headers: { apikey: 'your-publishable-key' },
3276
3594
  * schema: 'public',
3277
3595
  * timeout: 30000, // 30 second timeout
3278
3596
  * })
@@ -3477,7 +3795,7 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
3477
3795
  }?: {
3478
3796
  head?: boolean;
3479
3797
  get?: boolean;
3480
- count?: 'exact' | 'planned' | 'estimated';
3798
+ count?: 'exact' | 'planned' | 'estimated' | (string & {});
3481
3799
  }): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder['Row'], FilterBuilder['Result'], FilterBuilder['RelationName'], FilterBuilder['Relationships'], 'RPC'>;
3482
3800
  }
3483
3801
  //#endregion