@supabase/postgrest-js 2.104.0-canary.0 → 2.104.0-canary.2

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.cjs CHANGED
@@ -103,30 +103,28 @@ var PostgrestBuilder = class {
103
103
  /**
104
104
  * Creates a builder configured for a specific PostgREST request.
105
105
  *
106
- * @example
106
+ * @example Using supabase-js (recommended)
107
107
  * ```ts
108
- * import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
108
+ * import { createClient } from '@supabase/supabase-js'
109
109
  *
110
- * const builder = new PostgrestQueryBuilder(
111
- * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
112
- * { headers: new Headers({ apikey: 'public-anon-key' }) }
113
- * )
110
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
111
+ * const { data, error } = await supabase.from('users').select('*')
114
112
  * ```
115
113
  *
116
114
  * @category Database
117
115
  *
118
- * @example Creating a Postgrest query builder
116
+ * @example Standalone import for bundle-sensitive environments
119
117
  * ```ts
120
118
  * import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
121
119
  *
122
120
  * const builder = new PostgrestQueryBuilder(
123
121
  * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
124
- * { headers: new Headers({ apikey: 'public-anon-key' }) }
122
+ * { headers: new Headers({ apikey: 'publishable-or-anon-key' }) }
125
123
  * )
126
124
  * ```
127
125
  */
128
126
  constructor(builder) {
129
- var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$urlLengthLim, _builder$retry;
127
+ var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$shouldStripN, _builder$urlLengthLim, _builder$retry;
130
128
  this.shouldThrowOnError = false;
131
129
  this.retryEnabled = true;
132
130
  this.method = builder.method;
@@ -137,6 +135,7 @@ var PostgrestBuilder = class {
137
135
  this.shouldThrowOnError = (_builder$shouldThrowO = builder.shouldThrowOnError) !== null && _builder$shouldThrowO !== void 0 ? _builder$shouldThrowO : false;
138
136
  this.signal = builder.signal;
139
137
  this.isMaybeSingle = (_builder$isMaybeSingl = builder.isMaybeSingle) !== null && _builder$isMaybeSingl !== void 0 ? _builder$isMaybeSingl : false;
138
+ this.shouldStripNulls = (_builder$shouldStripN = builder.shouldStripNulls) !== null && _builder$shouldStripN !== void 0 ? _builder$shouldStripN : false;
140
139
  this.urlLengthLimit = (_builder$urlLengthLim = builder.urlLengthLimit) !== null && _builder$urlLengthLim !== void 0 ? _builder$urlLengthLim : 8e3;
141
140
  this.retryEnabled = (_builder$retry = builder.retry) !== null && _builder$retry !== void 0 ? _builder$retry : true;
142
141
  if (builder.fetch) this.fetch = builder.fetch;
@@ -155,6 +154,60 @@ var PostgrestBuilder = class {
155
154
  return this;
156
155
  }
157
156
  /**
157
+ * Strip null values from the response data. Properties with `null` values
158
+ * will be omitted from the returned JSON objects.
159
+ *
160
+ * Requires PostgREST 11.2.0+.
161
+ *
162
+ * {@link https://docs.postgrest.org/en/stable/references/api/resource_representation.html#stripped-nulls}
163
+ *
164
+ * @category Database
165
+ *
166
+ * @example With `select()`
167
+ * ```ts
168
+ * const { data, error } = await supabase
169
+ * .from('characters')
170
+ * .select()
171
+ * .stripNulls()
172
+ * ```
173
+ *
174
+ * @exampleSql With `select()`
175
+ * ```sql
176
+ * create table
177
+ * characters (id int8 primary key, name text, bio text);
178
+ *
179
+ * insert into
180
+ * characters (id, name, bio)
181
+ * values
182
+ * (1, 'Luke', null),
183
+ * (2, 'Leia', 'Princess of Alderaan');
184
+ * ```
185
+ *
186
+ * @exampleResponse With `select()`
187
+ * ```json
188
+ * {
189
+ * "data": [
190
+ * {
191
+ * "id": 1,
192
+ * "name": "Luke"
193
+ * },
194
+ * {
195
+ * "id": 2,
196
+ * "name": "Leia",
197
+ * "bio": "Princess of Alderaan"
198
+ * }
199
+ * ],
200
+ * "status": 200,
201
+ * "statusText": "OK"
202
+ * }
203
+ * ```
204
+ */
205
+ stripNulls() {
206
+ if (this.headers.get("Accept") === "text/csv") throw new Error("stripNulls() cannot be used with csv()");
207
+ this.shouldStripNulls = true;
208
+ return this;
209
+ }
210
+ /**
158
211
  * Set an HTTP header for the request.
159
212
  *
160
213
  * @category Database
@@ -193,6 +246,11 @@ var PostgrestBuilder = class {
193
246
  if (this.schema === void 0) {} else if (["GET", "HEAD"].includes(this.method)) this.headers.set("Accept-Profile", this.schema);
194
247
  else this.headers.set("Content-Profile", this.schema);
195
248
  if (this.method !== "GET" && this.method !== "HEAD") this.headers.set("Content-Type", "application/json");
249
+ if (this.shouldStripNulls) {
250
+ const currentAccept = this.headers.get("Accept");
251
+ if (currentAccept === "application/vnd.pgrst.object+json") this.headers.set("Accept", "application/vnd.pgrst.object+json;nulls=stripped");
252
+ else if (!currentAccept || currentAccept === "application/json") this.headers.set("Accept", "application/vnd.pgrst.array+json;nulls=stripped");
253
+ }
196
254
  const _fetch = this.fetch;
197
255
  const executeWithRetry = async () => {
198
256
  let attemptCount = 0;
@@ -204,7 +262,7 @@ var PostgrestBuilder = class {
204
262
  res$1 = await _fetch(_this.url.toString(), {
205
263
  method: _this.method,
206
264
  headers: requestHeaders,
207
- body: JSON.stringify(_this.body),
265
+ body: JSON.stringify(_this.body, (_, value) => typeof value === "bigint" ? value.toString() : value),
208
266
  signal: _this.signal
209
267
  });
210
268
  } catch (fetchError) {
@@ -3028,13 +3086,21 @@ var PostgrestQueryBuilder = class {
3028
3086
  * @param options.urlLengthLimit - Maximum URL length before warning
3029
3087
  * @param options.retry - Enable automatic retries for transient errors (default: true)
3030
3088
  *
3031
- * @example Creating a Postgrest query builder
3089
+ * @example Using supabase-js (recommended)
3090
+ * ```ts
3091
+ * import { createClient } from '@supabase/supabase-js'
3092
+ *
3093
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
3094
+ * const { data, error } = await supabase.from('users').select('*')
3095
+ * ```
3096
+ *
3097
+ * @example Standalone import for bundle-sensitive environments
3032
3098
  * ```ts
3033
3099
  * import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
3034
3100
  *
3035
3101
  * const query = new PostgrestQueryBuilder(
3036
3102
  * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
3037
- * { headers: { apikey: 'public-anon-key' }, retry: true }
3103
+ * { headers: { apikey: 'publishable-or-anon-key' }, retry: true }
3038
3104
  * )
3039
3105
  * ```
3040
3106
  */
@@ -4608,15 +4674,12 @@ var PostgrestClient = class PostgrestClient {
4608
4674
  * When enabled, idempotent requests (GET, HEAD, OPTIONS) that fail with network
4609
4675
  * errors or HTTP 503/520 responses will be automatically retried up to 3 times
4610
4676
  * with exponential backoff (1s, 2s, 4s). Defaults to `true`.
4611
- * @example
4677
+ * @example Using supabase-js (recommended)
4612
4678
  * ```ts
4613
- * import { PostgrestClient } from '@supabase/postgrest-js'
4679
+ * import { createClient } from '@supabase/supabase-js'
4614
4680
  *
4615
- * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
4616
- * headers: { apikey: 'public-anon-key' },
4617
- * schema: 'public',
4618
- * timeout: 30000, // 30 second timeout
4619
- * })
4681
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
4682
+ * const { data, error } = await supabase.from('profiles').select('*')
4620
4683
  * ```
4621
4684
  *
4622
4685
  * @category Database
@@ -4625,25 +4688,14 @@ var PostgrestClient = class PostgrestClient {
4625
4688
  * - A `timeout` option (in milliseconds) can be set to automatically abort requests that take too long.
4626
4689
  * - A `urlLengthLimit` option (default: 8000) can be set to control when URL length warnings are included in error messages for aborted requests.
4627
4690
  *
4628
- * @example Creating a Postgrest client
4629
- * ```ts
4630
- * import { PostgrestClient } from '@supabase/postgrest-js'
4631
- *
4632
- * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
4633
- * headers: { apikey: 'public-anon-key' },
4634
- * schema: 'public',
4635
- * })
4636
- * ```
4637
- *
4638
- * @example With timeout
4691
+ * @example Standalone import for bundle-sensitive environments
4639
4692
  * ```ts
4640
4693
  * import { PostgrestClient } from '@supabase/postgrest-js'
4641
4694
  *
4642
4695
  * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
4643
- * headers: { apikey: 'public-anon-key' },
4696
+ * headers: { apikey: 'publishable-or-anon-key' },
4644
4697
  * schema: 'public',
4645
4698
  * timeout: 30000, // 30 second timeout
4646
- * retry: false, // Disable automatic retries
4647
4699
  * })
4648
4700
  * ```
4649
4701
  */