@supabase/postgrest-js 2.103.0-canary.1 → 2.103.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
@@ -126,7 +126,7 @@ var PostgrestBuilder = class {
126
126
  * ```
127
127
  */
128
128
  constructor(builder) {
129
- var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$urlLengthLim, _builder$retry;
129
+ var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$shouldStripN, _builder$urlLengthLim, _builder$retry;
130
130
  this.shouldThrowOnError = false;
131
131
  this.retryEnabled = true;
132
132
  this.method = builder.method;
@@ -137,6 +137,7 @@ var PostgrestBuilder = class {
137
137
  this.shouldThrowOnError = (_builder$shouldThrowO = builder.shouldThrowOnError) !== null && _builder$shouldThrowO !== void 0 ? _builder$shouldThrowO : false;
138
138
  this.signal = builder.signal;
139
139
  this.isMaybeSingle = (_builder$isMaybeSingl = builder.isMaybeSingle) !== null && _builder$isMaybeSingl !== void 0 ? _builder$isMaybeSingl : false;
140
+ this.shouldStripNulls = (_builder$shouldStripN = builder.shouldStripNulls) !== null && _builder$shouldStripN !== void 0 ? _builder$shouldStripN : false;
140
141
  this.urlLengthLimit = (_builder$urlLengthLim = builder.urlLengthLimit) !== null && _builder$urlLengthLim !== void 0 ? _builder$urlLengthLim : 8e3;
141
142
  this.retryEnabled = (_builder$retry = builder.retry) !== null && _builder$retry !== void 0 ? _builder$retry : true;
142
143
  if (builder.fetch) this.fetch = builder.fetch;
@@ -155,6 +156,60 @@ var PostgrestBuilder = class {
155
156
  return this;
156
157
  }
157
158
  /**
159
+ * Strip null values from the response data. Properties with `null` values
160
+ * will be omitted from the returned JSON objects.
161
+ *
162
+ * Requires PostgREST 11.2.0+.
163
+ *
164
+ * {@link https://docs.postgrest.org/en/stable/references/api/resource_representation.html#stripped-nulls}
165
+ *
166
+ * @category Database
167
+ *
168
+ * @example With `select()`
169
+ * ```ts
170
+ * const { data, error } = await supabase
171
+ * .from('characters')
172
+ * .select()
173
+ * .stripNulls()
174
+ * ```
175
+ *
176
+ * @exampleSql With `select()`
177
+ * ```sql
178
+ * create table
179
+ * characters (id int8 primary key, name text, bio text);
180
+ *
181
+ * insert into
182
+ * characters (id, name, bio)
183
+ * values
184
+ * (1, 'Luke', null),
185
+ * (2, 'Leia', 'Princess of Alderaan');
186
+ * ```
187
+ *
188
+ * @exampleResponse With `select()`
189
+ * ```json
190
+ * {
191
+ * "data": [
192
+ * {
193
+ * "id": 1,
194
+ * "name": "Luke"
195
+ * },
196
+ * {
197
+ * "id": 2,
198
+ * "name": "Leia",
199
+ * "bio": "Princess of Alderaan"
200
+ * }
201
+ * ],
202
+ * "status": 200,
203
+ * "statusText": "OK"
204
+ * }
205
+ * ```
206
+ */
207
+ stripNulls() {
208
+ if (this.headers.get("Accept") === "text/csv") throw new Error("stripNulls() cannot be used with csv()");
209
+ this.shouldStripNulls = true;
210
+ return this;
211
+ }
212
+ /**
158
213
  * Set an HTTP header for the request.
159
214
  *
160
215
  * @category Database
@@ -193,6 +248,11 @@ var PostgrestBuilder = class {
193
248
  if (this.schema === void 0) {} else if (["GET", "HEAD"].includes(this.method)) this.headers.set("Accept-Profile", this.schema);
194
249
  else this.headers.set("Content-Profile", this.schema);
195
250
  if (this.method !== "GET" && this.method !== "HEAD") this.headers.set("Content-Type", "application/json");
251
+ if (this.shouldStripNulls) {
252
+ const currentAccept = this.headers.get("Accept");
253
+ if (currentAccept === "application/vnd.pgrst.object+json") this.headers.set("Accept", "application/vnd.pgrst.object+json;nulls=stripped");
254
+ else if (!currentAccept || currentAccept === "application/json") this.headers.set("Accept", "application/vnd.pgrst.array+json;nulls=stripped");
255
+ }
196
256
  const _fetch = this.fetch;
197
257
  const executeWithRetry = async () => {
198
258
  let attemptCount = 0;