@supabase/postgrest-js
Advanced tools
Comparing version 0.23.0 to 0.24.0
@@ -14,4 +14,9 @@ import { PostgrestBuilder } from './types'; | ||
* @param columns The columns to retrieve, separated by commas. | ||
* @param head When set to true, select will void data. | ||
* @param count Count algorithm to use to count rows in a table. | ||
*/ | ||
select(columns?: string): PostgrestFilterBuilder<T>; | ||
select(columns?: string, { head, count, }?: { | ||
head?: boolean; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
/** | ||
@@ -25,6 +30,7 @@ * Performs an INSERT into the table. | ||
*/ | ||
insert(values: Partial<T> | Partial<T>[], { upsert, onConflict, returning, }?: { | ||
insert(values: Partial<T> | Partial<T>[], { upsert, onConflict, returning, count, }?: { | ||
upsert?: boolean; | ||
onConflict?: string; | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
@@ -37,4 +43,5 @@ /** | ||
*/ | ||
update(values: Partial<T>, { returning }?: { | ||
update(values: Partial<T>, { returning, count, }?: { | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
@@ -46,6 +53,7 @@ /** | ||
*/ | ||
delete({ returning, }?: { | ||
delete({ returning, count, }?: { | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
} | ||
//# sourceMappingURL=PostgrestQueryBuilder.d.ts.map |
@@ -20,4 +20,6 @@ "use strict"; | ||
* @param columns The columns to retrieve, separated by commas. | ||
* @param head When set to true, select will void data. | ||
* @param count Count algorithm to use to count rows in a table. | ||
*/ | ||
select(columns = '*') { | ||
select(columns = '*', { head = false, count = null, } = {}) { | ||
this.method = 'GET'; | ||
@@ -39,2 +41,8 @@ // Remove whitespaces except when quoted | ||
this.url.searchParams.set('select', cleanedColumns); | ||
if (count) { | ||
this.headers['Prefer'] = `count=${count}`; | ||
} | ||
if (head) { | ||
this.method = 'HEAD'; | ||
} | ||
return new PostgrestFilterBuilder_1.default(this); | ||
@@ -50,3 +58,3 @@ } | ||
*/ | ||
insert(values, { upsert = false, onConflict, returning = 'representation', } = {}) { | ||
insert(values, { upsert = false, onConflict, returning = 'representation', count = null, } = {}) { | ||
this.method = 'POST'; | ||
@@ -61,2 +69,6 @@ let prefersHeaders = []; | ||
this.body = values; | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder_1.default(this); | ||
@@ -70,6 +82,12 @@ } | ||
*/ | ||
update(values, { returning = 'representation' } = {}) { | ||
update(values, { returning = 'representation', count = null, } = {}) { | ||
this.method = 'PATCH'; | ||
this.headers['Prefer'] = `return=${returning}`; | ||
let prefersHeaders = []; | ||
prefersHeaders.push(`return=${returning}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
this.body = values; | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder_1.default(this); | ||
@@ -82,11 +100,23 @@ } | ||
*/ | ||
delete({ returning = 'representation', } = {}) { | ||
delete({ returning = 'representation', count = null, } = {}) { | ||
this.method = 'DELETE'; | ||
this.headers['Prefer'] = `return=${returning}`; | ||
let prefersHeaders = []; | ||
prefersHeaders.push(`return=${returning}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder_1.default(this); | ||
} | ||
/** @internal */ | ||
rpc(params) { | ||
rpc(params, { head = false, count = null, } = {}) { | ||
this.method = 'POST'; | ||
this.body = params; | ||
if (count) { | ||
this.headers['Prefer'] = `count=${count}`; | ||
} | ||
if (head) { | ||
this.method = 'HEAD'; | ||
} | ||
return new PostgrestTransformBuilder_1.default(this); | ||
@@ -93,0 +123,0 @@ } |
@@ -25,2 +25,3 @@ /** | ||
body: T[]; | ||
count: number | null; | ||
} | ||
@@ -31,2 +32,3 @@ interface PostgrestResponseFailure extends PostgrestResponseBase { | ||
body: null; | ||
count: null; | ||
} | ||
@@ -33,0 +35,0 @@ export declare type PostgrestResponse<T> = PostgrestResponseSuccess<T> | PostgrestResponseFailure; |
@@ -41,8 +41,26 @@ "use strict"; | ||
.then((res) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
let error, data; | ||
var _a, _b, _c; | ||
let error, data, count; | ||
if (res.ok) { | ||
error = null; | ||
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal'); | ||
data = isReturnMinimal ? null : yield res.json(); | ||
if (this.method !== 'HEAD') { | ||
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal'); | ||
data = isReturnMinimal ? null : yield res.json(); | ||
} | ||
else { | ||
data = null; | ||
} | ||
const countHeader = (_b = this.headers['Prefer']) === null || _b === void 0 ? void 0 : _b.match(/count=(exact|planned|estimated)/); | ||
if (countHeader) { | ||
const contentRange = (_c = res.headers.get('content-range')) === null || _c === void 0 ? void 0 : _c.split('/'); | ||
if (contentRange && contentRange.length > 1) { | ||
count = parseInt(contentRange[1]); | ||
} | ||
else { | ||
count = null; | ||
} | ||
} | ||
else { | ||
count = null; | ||
} | ||
} | ||
@@ -52,2 +70,3 @@ else { | ||
data = null; | ||
count = null; | ||
} | ||
@@ -57,2 +76,3 @@ const postgrestResponse = { | ||
data, | ||
count, | ||
status: res.status, | ||
@@ -59,0 +79,0 @@ statusText: res.statusText, |
@@ -14,4 +14,9 @@ import { PostgrestBuilder } from './types'; | ||
* @param columns The columns to retrieve, separated by commas. | ||
* @param head When set to true, select will void data. | ||
* @param count Count algorithm to use to count rows in a table. | ||
*/ | ||
select(columns?: string): PostgrestFilterBuilder<T>; | ||
select(columns?: string, { head, count, }?: { | ||
head?: boolean; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
/** | ||
@@ -25,6 +30,7 @@ * Performs an INSERT into the table. | ||
*/ | ||
insert(values: Partial<T> | Partial<T>[], { upsert, onConflict, returning, }?: { | ||
insert(values: Partial<T> | Partial<T>[], { upsert, onConflict, returning, count, }?: { | ||
upsert?: boolean; | ||
onConflict?: string; | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
@@ -37,4 +43,5 @@ /** | ||
*/ | ||
update(values: Partial<T>, { returning }?: { | ||
update(values: Partial<T>, { returning, count, }?: { | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
@@ -46,6 +53,7 @@ /** | ||
*/ | ||
delete({ returning, }?: { | ||
delete({ returning, count, }?: { | ||
returning?: 'minimal' | 'representation'; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
} | ||
//# sourceMappingURL=PostgrestQueryBuilder.d.ts.map |
@@ -15,4 +15,6 @@ import { PostgrestBuilder } from './types'; | ||
* @param columns The columns to retrieve, separated by commas. | ||
* @param head When set to true, select will void data. | ||
* @param count Count algorithm to use to count rows in a table. | ||
*/ | ||
select(columns = '*') { | ||
select(columns = '*', { head = false, count = null, } = {}) { | ||
this.method = 'GET'; | ||
@@ -34,2 +36,8 @@ // Remove whitespaces except when quoted | ||
this.url.searchParams.set('select', cleanedColumns); | ||
if (count) { | ||
this.headers['Prefer'] = `count=${count}`; | ||
} | ||
if (head) { | ||
this.method = 'HEAD'; | ||
} | ||
return new PostgrestFilterBuilder(this); | ||
@@ -45,3 +53,3 @@ } | ||
*/ | ||
insert(values, { upsert = false, onConflict, returning = 'representation', } = {}) { | ||
insert(values, { upsert = false, onConflict, returning = 'representation', count = null, } = {}) { | ||
this.method = 'POST'; | ||
@@ -56,2 +64,6 @@ let prefersHeaders = []; | ||
this.body = values; | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder(this); | ||
@@ -65,6 +77,12 @@ } | ||
*/ | ||
update(values, { returning = 'representation' } = {}) { | ||
update(values, { returning = 'representation', count = null, } = {}) { | ||
this.method = 'PATCH'; | ||
this.headers['Prefer'] = `return=${returning}`; | ||
let prefersHeaders = []; | ||
prefersHeaders.push(`return=${returning}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
this.body = values; | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder(this); | ||
@@ -77,11 +95,23 @@ } | ||
*/ | ||
delete({ returning = 'representation', } = {}) { | ||
delete({ returning = 'representation', count = null, } = {}) { | ||
this.method = 'DELETE'; | ||
this.headers['Prefer'] = `return=${returning}`; | ||
let prefersHeaders = []; | ||
prefersHeaders.push(`return=${returning}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
if (count) { | ||
prefersHeaders.push(`count=${count}`); | ||
this.headers['Prefer'] = prefersHeaders.join(','); | ||
} | ||
return new PostgrestFilterBuilder(this); | ||
} | ||
/** @internal */ | ||
rpc(params) { | ||
rpc(params, { head = false, count = null, } = {}) { | ||
this.method = 'POST'; | ||
this.body = params; | ||
if (count) { | ||
this.headers['Prefer'] = `count=${count}`; | ||
} | ||
if (head) { | ||
this.method = 'HEAD'; | ||
} | ||
return new PostgrestTransformBuilder(this); | ||
@@ -88,0 +118,0 @@ } |
@@ -25,2 +25,3 @@ /** | ||
body: T[]; | ||
count: number | null; | ||
} | ||
@@ -31,2 +32,3 @@ interface PostgrestResponseFailure extends PostgrestResponseBase { | ||
body: null; | ||
count: null; | ||
} | ||
@@ -33,0 +35,0 @@ export declare type PostgrestResponse<T> = PostgrestResponseSuccess<T> | PostgrestResponseFailure; |
@@ -35,8 +35,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
.then((res) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
let error, data; | ||
var _a, _b, _c; | ||
let error, data, count; | ||
if (res.ok) { | ||
error = null; | ||
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal'); | ||
data = isReturnMinimal ? null : yield res.json(); | ||
if (this.method !== 'HEAD') { | ||
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal'); | ||
data = isReturnMinimal ? null : yield res.json(); | ||
} | ||
else { | ||
data = null; | ||
} | ||
const countHeader = (_b = this.headers['Prefer']) === null || _b === void 0 ? void 0 : _b.match(/count=(exact|planned|estimated)/); | ||
if (countHeader) { | ||
const contentRange = (_c = res.headers.get('content-range')) === null || _c === void 0 ? void 0 : _c.split('/'); | ||
if (contentRange && contentRange.length > 1) { | ||
count = parseInt(contentRange[1]); | ||
} | ||
else { | ||
count = null; | ||
} | ||
} | ||
else { | ||
count = null; | ||
} | ||
} | ||
@@ -46,2 +64,3 @@ else { | ||
data = null; | ||
count = null; | ||
} | ||
@@ -51,2 +70,3 @@ const postgrestResponse = { | ||
data, | ||
count, | ||
status: res.status, | ||
@@ -53,0 +73,0 @@ statusText: res.statusText, |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "0.23.0", | ||
"version": "0.24.0", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130736
2171