first build
This commit is contained in:
-221
@@ -1,221 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// @ts-ignore
|
||||
const node_fetch_1 = __importDefault(require("@supabase/node-fetch"));
|
||||
const PostgrestError_1 = __importDefault(require("./PostgrestError"));
|
||||
class PostgrestBuilder {
|
||||
constructor(builder) {
|
||||
this.shouldThrowOnError = false;
|
||||
this.method = builder.method;
|
||||
this.url = builder.url;
|
||||
this.headers = builder.headers;
|
||||
this.schema = builder.schema;
|
||||
this.body = builder.body;
|
||||
this.shouldThrowOnError = builder.shouldThrowOnError;
|
||||
this.signal = builder.signal;
|
||||
this.isMaybeSingle = builder.isMaybeSingle;
|
||||
if (builder.fetch) {
|
||||
this.fetch = builder.fetch;
|
||||
}
|
||||
else if (typeof fetch === 'undefined') {
|
||||
this.fetch = node_fetch_1.default;
|
||||
}
|
||||
else {
|
||||
this.fetch = fetch;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* If there's an error with the query, throwOnError will reject the promise by
|
||||
* throwing the error instead of returning it as part of a successful response.
|
||||
*
|
||||
* {@link https://github.com/supabase/supabase-js/issues/92}
|
||||
*/
|
||||
throwOnError() {
|
||||
this.shouldThrowOnError = true;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set an HTTP header for the request.
|
||||
*/
|
||||
setHeader(name, value) {
|
||||
this.headers = Object.assign({}, this.headers);
|
||||
this.headers[name] = value;
|
||||
return this;
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
// https://postgrest.org/en/stable/api.html#switching-schemas
|
||||
if (this.schema === undefined) {
|
||||
// skip
|
||||
}
|
||||
else if (['GET', 'HEAD'].includes(this.method)) {
|
||||
this.headers['Accept-Profile'] = this.schema;
|
||||
}
|
||||
else {
|
||||
this.headers['Content-Profile'] = this.schema;
|
||||
}
|
||||
if (this.method !== 'GET' && this.method !== 'HEAD') {
|
||||
this.headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
// NOTE: Invoke w/o `this` to avoid illegal invocation error.
|
||||
// https://github.com/supabase/postgrest-js/pull/247
|
||||
const _fetch = this.fetch;
|
||||
let res = _fetch(this.url.toString(), {
|
||||
method: this.method,
|
||||
headers: this.headers,
|
||||
body: JSON.stringify(this.body),
|
||||
signal: this.signal,
|
||||
}).then(async (res) => {
|
||||
var _a, _b, _c;
|
||||
let error = null;
|
||||
let data = null;
|
||||
let count = null;
|
||||
let status = res.status;
|
||||
let statusText = res.statusText;
|
||||
if (res.ok) {
|
||||
if (this.method !== 'HEAD') {
|
||||
const body = await res.text();
|
||||
if (body === '') {
|
||||
// Prefer: return=minimal
|
||||
}
|
||||
else if (this.headers['Accept'] === 'text/csv') {
|
||||
data = body;
|
||||
}
|
||||
else if (this.headers['Accept'] &&
|
||||
this.headers['Accept'].includes('application/vnd.pgrst.plan+text')) {
|
||||
data = body;
|
||||
}
|
||||
else {
|
||||
data = JSON.parse(body);
|
||||
}
|
||||
}
|
||||
const countHeader = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.match(/count=(exact|planned|estimated)/);
|
||||
const contentRange = (_b = res.headers.get('content-range')) === null || _b === void 0 ? void 0 : _b.split('/');
|
||||
if (countHeader && contentRange && contentRange.length > 1) {
|
||||
count = parseInt(contentRange[1]);
|
||||
}
|
||||
// Temporary partial fix for https://github.com/supabase/postgrest-js/issues/361
|
||||
// Issue persists e.g. for `.insert([...]).select().maybeSingle()`
|
||||
if (this.isMaybeSingle && this.method === 'GET' && Array.isArray(data)) {
|
||||
if (data.length > 1) {
|
||||
error = {
|
||||
// https://github.com/PostgREST/postgrest/blob/a867d79c42419af16c18c3fb019eba8df992626f/src/PostgREST/Error.hs#L553
|
||||
code: 'PGRST116',
|
||||
details: `Results contain ${data.length} rows, application/vnd.pgrst.object+json requires 1 row`,
|
||||
hint: null,
|
||||
message: 'JSON object requested, multiple (or no) rows returned',
|
||||
};
|
||||
data = null;
|
||||
count = null;
|
||||
status = 406;
|
||||
statusText = 'Not Acceptable';
|
||||
}
|
||||
else if (data.length === 1) {
|
||||
data = data[0];
|
||||
}
|
||||
else {
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const body = await res.text();
|
||||
try {
|
||||
error = JSON.parse(body);
|
||||
// Workaround for https://github.com/supabase/postgrest-js/issues/295
|
||||
if (Array.isArray(error) && res.status === 404) {
|
||||
data = [];
|
||||
error = null;
|
||||
status = 200;
|
||||
statusText = 'OK';
|
||||
}
|
||||
}
|
||||
catch (_d) {
|
||||
// Workaround for https://github.com/supabase/postgrest-js/issues/295
|
||||
if (res.status === 404 && body === '') {
|
||||
status = 204;
|
||||
statusText = 'No Content';
|
||||
}
|
||||
else {
|
||||
error = {
|
||||
message: body,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (error && this.isMaybeSingle && ((_c = error === null || error === void 0 ? void 0 : error.details) === null || _c === void 0 ? void 0 : _c.includes('0 rows'))) {
|
||||
error = null;
|
||||
status = 200;
|
||||
statusText = 'OK';
|
||||
}
|
||||
if (error && this.shouldThrowOnError) {
|
||||
throw new PostgrestError_1.default(error);
|
||||
}
|
||||
}
|
||||
const postgrestResponse = {
|
||||
error,
|
||||
data,
|
||||
count,
|
||||
status,
|
||||
statusText,
|
||||
};
|
||||
return postgrestResponse;
|
||||
});
|
||||
if (!this.shouldThrowOnError) {
|
||||
res = res.catch((fetchError) => {
|
||||
var _a, _b, _c;
|
||||
return ({
|
||||
error: {
|
||||
message: `${(_a = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _a !== void 0 ? _a : 'FetchError'}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`,
|
||||
details: `${(_b = fetchError === null || fetchError === void 0 ? void 0 : fetchError.stack) !== null && _b !== void 0 ? _b : ''}`,
|
||||
hint: '',
|
||||
code: `${(_c = fetchError === null || fetchError === void 0 ? void 0 : fetchError.code) !== null && _c !== void 0 ? _c : ''}`,
|
||||
},
|
||||
data: null,
|
||||
count: null,
|
||||
status: 0,
|
||||
statusText: '',
|
||||
});
|
||||
});
|
||||
}
|
||||
return res.then(onfulfilled, onrejected);
|
||||
}
|
||||
/**
|
||||
* Override the type of the returned `data`.
|
||||
*
|
||||
* @typeParam NewResult - The new result type to override with
|
||||
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
||||
*/
|
||||
returns() {
|
||||
/* istanbul ignore next */
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Override the type of the returned `data` field in the response.
|
||||
*
|
||||
* @typeParam NewResult - The new type to cast the response data to
|
||||
* @typeParam Options - Optional type configuration (defaults to { merge: true })
|
||||
* @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true)
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Merge with existing types (default behavior)
|
||||
* const query = supabase
|
||||
* .from('users')
|
||||
* .select()
|
||||
* .overrideTypes<{ custom_field: string }>()
|
||||
*
|
||||
* // Replace existing types completely
|
||||
* const replaceQuery = supabase
|
||||
* .from('users')
|
||||
* .select()
|
||||
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
||||
* ```
|
||||
* @returns A PostgrestBuilder instance with the new type
|
||||
*/
|
||||
overrideTypes() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestBuilder;
|
||||
//# sourceMappingURL=PostgrestBuilder.js.map
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const PostgrestQueryBuilder_1 = __importDefault(require("./PostgrestQueryBuilder"));
|
||||
const PostgrestFilterBuilder_1 = __importDefault(require("./PostgrestFilterBuilder"));
|
||||
const constants_1 = require("./constants");
|
||||
/**
|
||||
* PostgREST client.
|
||||
*
|
||||
* @typeParam Database - Types for the schema from the [type
|
||||
* generator](https://supabase.com/docs/reference/javascript/next/typescript-support)
|
||||
*
|
||||
* @typeParam SchemaName - Postgres schema to switch to. Must be a string
|
||||
* literal, the same one passed to the constructor. If the schema is not
|
||||
* `"public"`, this must be supplied manually.
|
||||
*/
|
||||
class PostgrestClient {
|
||||
// TODO: Add back shouldThrowOnError once we figure out the typings
|
||||
/**
|
||||
* Creates a PostgREST client.
|
||||
*
|
||||
* @param url - URL of the PostgREST endpoint
|
||||
* @param options - Named parameters
|
||||
* @param options.headers - Custom headers
|
||||
* @param options.schema - Postgres schema to switch to
|
||||
* @param options.fetch - Custom fetch
|
||||
*/
|
||||
constructor(url, { headers = {}, schema, fetch, } = {}) {
|
||||
this.url = url;
|
||||
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers);
|
||||
this.schemaName = schema;
|
||||
this.fetch = fetch;
|
||||
}
|
||||
/**
|
||||
* Perform a query on a table or a view.
|
||||
*
|
||||
* @param relation - The table or view name to query
|
||||
*/
|
||||
from(relation) {
|
||||
const url = new URL(`${this.url}/${relation}`);
|
||||
return new PostgrestQueryBuilder_1.default(url, {
|
||||
headers: Object.assign({}, this.headers),
|
||||
schema: this.schemaName,
|
||||
fetch: this.fetch,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Select a schema to query or perform an function (rpc) call.
|
||||
*
|
||||
* The schema needs to be on the list of exposed schemas inside Supabase.
|
||||
*
|
||||
* @param schema - The schema to query
|
||||
*/
|
||||
schema(schema) {
|
||||
return new PostgrestClient(this.url, {
|
||||
headers: this.headers,
|
||||
schema,
|
||||
fetch: this.fetch,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Perform a function call.
|
||||
*
|
||||
* @param fn - The function name to call
|
||||
* @param args - The arguments to pass to the function call
|
||||
* @param options - Named parameters
|
||||
* @param options.head - When set to `true`, `data` will not be returned.
|
||||
* Useful if you only need the count.
|
||||
* @param options.get - When set to `true`, the function will be called with
|
||||
* read-only access mode.
|
||||
* @param options.count - Count algorithm to use to count rows returned by the
|
||||
* function. Only applicable for [set-returning
|
||||
* functions](https://www.postgresql.org/docs/current/functions-srf.html).
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*/
|
||||
rpc(fn, args = {}, { head = false, get = false, count, } = {}) {
|
||||
let method;
|
||||
const url = new URL(`${this.url}/rpc/${fn}`);
|
||||
let body;
|
||||
if (head || get) {
|
||||
method = head ? 'HEAD' : 'GET';
|
||||
Object.entries(args)
|
||||
// params with undefined value needs to be filtered out, otherwise it'll
|
||||
// show up as `?param=undefined`
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
// array values need special syntax
|
||||
.map(([name, value]) => [name, Array.isArray(value) ? `{${value.join(',')}}` : `${value}`])
|
||||
.forEach(([name, value]) => {
|
||||
url.searchParams.append(name, value);
|
||||
});
|
||||
}
|
||||
else {
|
||||
method = 'POST';
|
||||
body = args;
|
||||
}
|
||||
const headers = Object.assign({}, this.headers);
|
||||
if (count) {
|
||||
headers['Prefer'] = `count=${count}`;
|
||||
}
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url,
|
||||
headers,
|
||||
schema: this.schemaName,
|
||||
body,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestClient;
|
||||
//# sourceMappingURL=PostgrestClient.js.map
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* Error format
|
||||
*
|
||||
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
|
||||
*/
|
||||
class PostgrestError extends Error {
|
||||
constructor(context) {
|
||||
super(context.message);
|
||||
this.name = 'PostgrestError';
|
||||
this.details = context.details;
|
||||
this.hint = context.hint;
|
||||
this.code = context.code;
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestError;
|
||||
//# sourceMappingURL=PostgrestError.js.map
|
||||
Generated
Vendored
-381
@@ -1,381 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const PostgrestTransformBuilder_1 = __importDefault(require("./PostgrestTransformBuilder"));
|
||||
class PostgrestFilterBuilder extends PostgrestTransformBuilder_1.default {
|
||||
/**
|
||||
* Match only rows where `column` is equal to `value`.
|
||||
*
|
||||
* To check if the value of `column` is NULL, you should use `.is()` instead.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
eq(column, value) {
|
||||
this.url.searchParams.append(column, `eq.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is not equal to `value`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
neq(column, value) {
|
||||
this.url.searchParams.append(column, `neq.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is greater than `value`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
gt(column, value) {
|
||||
this.url.searchParams.append(column, `gt.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is greater than or equal to `value`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
gte(column, value) {
|
||||
this.url.searchParams.append(column, `gte.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is less than `value`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
lt(column, value) {
|
||||
this.url.searchParams.append(column, `lt.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is less than or equal to `value`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
lte(column, value) {
|
||||
this.url.searchParams.append(column, `lte.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches `pattern` case-sensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param pattern - The pattern to match with
|
||||
*/
|
||||
like(column, pattern) {
|
||||
this.url.searchParams.append(column, `like.${pattern}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches all of `patterns` case-sensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param patterns - The patterns to match with
|
||||
*/
|
||||
likeAllOf(column, patterns) {
|
||||
this.url.searchParams.append(column, `like(all).{${patterns.join(',')}}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches any of `patterns` case-sensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param patterns - The patterns to match with
|
||||
*/
|
||||
likeAnyOf(column, patterns) {
|
||||
this.url.searchParams.append(column, `like(any).{${patterns.join(',')}}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches `pattern` case-insensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param pattern - The pattern to match with
|
||||
*/
|
||||
ilike(column, pattern) {
|
||||
this.url.searchParams.append(column, `ilike.${pattern}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches all of `patterns` case-insensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param patterns - The patterns to match with
|
||||
*/
|
||||
ilikeAllOf(column, patterns) {
|
||||
this.url.searchParams.append(column, `ilike(all).{${patterns.join(',')}}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` matches any of `patterns` case-insensitively.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param patterns - The patterns to match with
|
||||
*/
|
||||
ilikeAnyOf(column, patterns) {
|
||||
this.url.searchParams.append(column, `ilike(any).{${patterns.join(',')}}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` IS `value`.
|
||||
*
|
||||
* For non-boolean columns, this is only relevant for checking if the value of
|
||||
* `column` is NULL by setting `value` to `null`.
|
||||
*
|
||||
* For boolean columns, you can also set `value` to `true` or `false` and it
|
||||
* will behave the same way as `.eq()`.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param value - The value to filter with
|
||||
*/
|
||||
is(column, value) {
|
||||
this.url.searchParams.append(column, `is.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where `column` is included in the `values` array.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param values - The values array to filter with
|
||||
*/
|
||||
in(column, values) {
|
||||
const cleanedValues = Array.from(new Set(values))
|
||||
.map((s) => {
|
||||
// handle postgrest reserved characters
|
||||
// https://postgrest.org/en/v7.0.0/api.html#reserved-characters
|
||||
if (typeof s === 'string' && new RegExp('[,()]').test(s))
|
||||
return `"${s}"`;
|
||||
else
|
||||
return `${s}`;
|
||||
})
|
||||
.join(',');
|
||||
this.url.searchParams.append(column, `in.(${cleanedValues})`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for jsonb, array, and range columns. Match only rows where
|
||||
* `column` contains every element appearing in `value`.
|
||||
*
|
||||
* @param column - The jsonb, array, or range column to filter on
|
||||
* @param value - The jsonb, array, or range value to filter with
|
||||
*/
|
||||
contains(column, value) {
|
||||
if (typeof value === 'string') {
|
||||
// range types can be inclusive '[', ']' or exclusive '(', ')' so just
|
||||
// keep it simple and accept a string
|
||||
this.url.searchParams.append(column, `cs.${value}`);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
// array
|
||||
this.url.searchParams.append(column, `cs.{${value.join(',')}}`);
|
||||
}
|
||||
else {
|
||||
// json
|
||||
this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for jsonb, array, and range columns. Match only rows where
|
||||
* every element appearing in `column` is contained by `value`.
|
||||
*
|
||||
* @param column - The jsonb, array, or range column to filter on
|
||||
* @param value - The jsonb, array, or range value to filter with
|
||||
*/
|
||||
containedBy(column, value) {
|
||||
if (typeof value === 'string') {
|
||||
// range
|
||||
this.url.searchParams.append(column, `cd.${value}`);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
// array
|
||||
this.url.searchParams.append(column, `cd.{${value.join(',')}}`);
|
||||
}
|
||||
else {
|
||||
// json
|
||||
this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for range columns. Match only rows where every element in
|
||||
* `column` is greater than any element in `range`.
|
||||
*
|
||||
* @param column - The range column to filter on
|
||||
* @param range - The range to filter with
|
||||
*/
|
||||
rangeGt(column, range) {
|
||||
this.url.searchParams.append(column, `sr.${range}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for range columns. Match only rows where every element in
|
||||
* `column` is either contained in `range` or greater than any element in
|
||||
* `range`.
|
||||
*
|
||||
* @param column - The range column to filter on
|
||||
* @param range - The range to filter with
|
||||
*/
|
||||
rangeGte(column, range) {
|
||||
this.url.searchParams.append(column, `nxl.${range}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for range columns. Match only rows where every element in
|
||||
* `column` is less than any element in `range`.
|
||||
*
|
||||
* @param column - The range column to filter on
|
||||
* @param range - The range to filter with
|
||||
*/
|
||||
rangeLt(column, range) {
|
||||
this.url.searchParams.append(column, `sl.${range}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for range columns. Match only rows where every element in
|
||||
* `column` is either contained in `range` or less than any element in
|
||||
* `range`.
|
||||
*
|
||||
* @param column - The range column to filter on
|
||||
* @param range - The range to filter with
|
||||
*/
|
||||
rangeLte(column, range) {
|
||||
this.url.searchParams.append(column, `nxr.${range}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for range columns. Match only rows where `column` is
|
||||
* mutually exclusive to `range` and there can be no element between the two
|
||||
* ranges.
|
||||
*
|
||||
* @param column - The range column to filter on
|
||||
* @param range - The range to filter with
|
||||
*/
|
||||
rangeAdjacent(column, range) {
|
||||
this.url.searchParams.append(column, `adj.${range}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for array and range columns. Match only rows where
|
||||
* `column` and `value` have an element in common.
|
||||
*
|
||||
* @param column - The array or range column to filter on
|
||||
* @param value - The array or range value to filter with
|
||||
*/
|
||||
overlaps(column, value) {
|
||||
if (typeof value === 'string') {
|
||||
// range
|
||||
this.url.searchParams.append(column, `ov.${value}`);
|
||||
}
|
||||
else {
|
||||
// array
|
||||
this.url.searchParams.append(column, `ov.{${value.join(',')}}`);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only relevant for text and tsvector columns. Match only rows where
|
||||
* `column` matches the query string in `query`.
|
||||
*
|
||||
* @param column - The text or tsvector column to filter on
|
||||
* @param query - The query text to match with
|
||||
* @param options - Named parameters
|
||||
* @param options.config - The text search configuration to use
|
||||
* @param options.type - Change how the `query` text is interpreted
|
||||
*/
|
||||
textSearch(column, query, { config, type } = {}) {
|
||||
let typePart = '';
|
||||
if (type === 'plain') {
|
||||
typePart = 'pl';
|
||||
}
|
||||
else if (type === 'phrase') {
|
||||
typePart = 'ph';
|
||||
}
|
||||
else if (type === 'websearch') {
|
||||
typePart = 'w';
|
||||
}
|
||||
const configPart = config === undefined ? '' : `(${config})`;
|
||||
this.url.searchParams.append(column, `${typePart}fts${configPart}.${query}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows where each column in `query` keys is equal to its
|
||||
* associated value. Shorthand for multiple `.eq()`s.
|
||||
*
|
||||
* @param query - The object to filter with, with column names as keys mapped
|
||||
* to their filter values
|
||||
*/
|
||||
match(query) {
|
||||
Object.entries(query).forEach(([column, value]) => {
|
||||
this.url.searchParams.append(column, `eq.${value}`);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows which doesn't satisfy the filter.
|
||||
*
|
||||
* Unlike most filters, `opearator` and `value` are used as-is and need to
|
||||
* follow [PostgREST
|
||||
* syntax](https://postgrest.org/en/stable/api.html#operators). You also need
|
||||
* to make sure they are properly sanitized.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param operator - The operator to be negated to filter with, following
|
||||
* PostgREST syntax
|
||||
* @param value - The value to filter with, following PostgREST syntax
|
||||
*/
|
||||
not(column, operator, value) {
|
||||
this.url.searchParams.append(column, `not.${operator}.${value}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows which satisfy at least one of the filters.
|
||||
*
|
||||
* Unlike most filters, `filters` is used as-is and needs to follow [PostgREST
|
||||
* syntax](https://postgrest.org/en/stable/api.html#operators). You also need
|
||||
* to make sure it's properly sanitized.
|
||||
*
|
||||
* It's currently not possible to do an `.or()` filter across multiple tables.
|
||||
*
|
||||
* @param filters - The filters to use, following PostgREST syntax
|
||||
* @param options - Named parameters
|
||||
* @param options.referencedTable - Set this to filter on referenced tables
|
||||
* instead of the parent table
|
||||
* @param options.foreignTable - Deprecated, use `referencedTable` instead
|
||||
*/
|
||||
or(filters, { foreignTable, referencedTable = foreignTable, } = {}) {
|
||||
const key = referencedTable ? `${referencedTable}.or` : 'or';
|
||||
this.url.searchParams.append(key, `(${filters})`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Match only rows which satisfy the filter. This is an escape hatch - you
|
||||
* should use the specific filter methods wherever possible.
|
||||
*
|
||||
* Unlike most filters, `opearator` and `value` are used as-is and need to
|
||||
* follow [PostgREST
|
||||
* syntax](https://postgrest.org/en/stable/api.html#operators). You also need
|
||||
* to make sure they are properly sanitized.
|
||||
*
|
||||
* @param column - The column to filter on
|
||||
* @param operator - The operator to filter with, following PostgREST syntax
|
||||
* @param value - The value to filter with, following PostgREST syntax
|
||||
*/
|
||||
filter(column, operator, value) {
|
||||
this.url.searchParams.append(column, `${operator}.${value}`);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestFilterBuilder;
|
||||
//# sourceMappingURL=PostgrestFilterBuilder.js.map
|
||||
Generated
Vendored
-271
@@ -1,271 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const PostgrestFilterBuilder_1 = __importDefault(require("./PostgrestFilterBuilder"));
|
||||
class PostgrestQueryBuilder {
|
||||
constructor(url, { headers = {}, schema, fetch, }) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
this.schema = schema;
|
||||
this.fetch = fetch;
|
||||
}
|
||||
/**
|
||||
* Perform a SELECT query on the table or view.
|
||||
*
|
||||
* @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.head - When set to `true`, `data` will not be returned.
|
||||
* Useful if you only need the count.
|
||||
*
|
||||
* @param options.count - Count algorithm to use to count rows in the table or view.
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*/
|
||||
select(columns, { head = false, count, } = {}) {
|
||||
const method = head ? 'HEAD' : 'GET';
|
||||
// Remove whitespaces except when quoted
|
||||
let quoted = false;
|
||||
const cleanedColumns = (columns !== null && columns !== void 0 ? columns : '*')
|
||||
.split('')
|
||||
.map((c) => {
|
||||
if (/\s/.test(c) && !quoted) {
|
||||
return '';
|
||||
}
|
||||
if (c === '"') {
|
||||
quoted = !quoted;
|
||||
}
|
||||
return c;
|
||||
})
|
||||
.join('');
|
||||
this.url.searchParams.set('select', cleanedColumns);
|
||||
if (count) {
|
||||
this.headers['Prefer'] = `count=${count}`;
|
||||
}
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url: this.url,
|
||||
headers: this.headers,
|
||||
schema: this.schema,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Perform an INSERT into the table or view.
|
||||
*
|
||||
* By default, inserted rows are not returned. To return it, chain the call
|
||||
* with `.select()`.
|
||||
*
|
||||
* @param values - The values to insert. Pass an object to insert a single row
|
||||
* or an array to insert multiple rows.
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.count - Count algorithm to use to count inserted rows.
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*
|
||||
* @param options.defaultToNull - Make missing fields default to `null`.
|
||||
* Otherwise, use the default value for the column. Only applies for bulk
|
||||
* inserts.
|
||||
*/
|
||||
insert(values, { count, defaultToNull = true, } = {}) {
|
||||
const method = 'POST';
|
||||
const prefersHeaders = [];
|
||||
if (this.headers['Prefer']) {
|
||||
prefersHeaders.push(this.headers['Prefer']);
|
||||
}
|
||||
if (count) {
|
||||
prefersHeaders.push(`count=${count}`);
|
||||
}
|
||||
if (!defaultToNull) {
|
||||
prefersHeaders.push('missing=default');
|
||||
}
|
||||
this.headers['Prefer'] = prefersHeaders.join(',');
|
||||
if (Array.isArray(values)) {
|
||||
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
|
||||
if (columns.length > 0) {
|
||||
const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
|
||||
this.url.searchParams.set('columns', uniqueColumns.join(','));
|
||||
}
|
||||
}
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url: this.url,
|
||||
headers: this.headers,
|
||||
schema: this.schema,
|
||||
body: values,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Perform an UPSERT on the table or view. Depending on the column(s) passed
|
||||
* to `onConflict`, `.upsert()` allows you to perform the equivalent of
|
||||
* `.insert()` if a row with the corresponding `onConflict` columns doesn't
|
||||
* exist, or if it does exist, perform an alternative action depending on
|
||||
* `ignoreDuplicates`.
|
||||
*
|
||||
* By default, upserted rows are not returned. To return it, chain the call
|
||||
* with `.select()`.
|
||||
*
|
||||
* @param values - The values to upsert with. Pass an object to upsert a
|
||||
* single row or an array to upsert multiple rows.
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.onConflict - Comma-separated UNIQUE column(s) to specify how
|
||||
* duplicate rows are determined. Two rows are duplicates if all the
|
||||
* `onConflict` columns are equal.
|
||||
*
|
||||
* @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If
|
||||
* `false`, duplicate rows are merged with existing rows.
|
||||
*
|
||||
* @param options.count - Count algorithm to use to count upserted rows.
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*
|
||||
* @param options.defaultToNull - Make missing fields default to `null`.
|
||||
* Otherwise, use the default value for the column. This only applies when
|
||||
* inserting new rows, not when merging with existing rows under
|
||||
* `ignoreDuplicates: false`. This also only applies when doing bulk upserts.
|
||||
*/
|
||||
upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true, } = {}) {
|
||||
const method = 'POST';
|
||||
const prefersHeaders = [`resolution=${ignoreDuplicates ? 'ignore' : 'merge'}-duplicates`];
|
||||
if (onConflict !== undefined)
|
||||
this.url.searchParams.set('on_conflict', onConflict);
|
||||
if (this.headers['Prefer']) {
|
||||
prefersHeaders.push(this.headers['Prefer']);
|
||||
}
|
||||
if (count) {
|
||||
prefersHeaders.push(`count=${count}`);
|
||||
}
|
||||
if (!defaultToNull) {
|
||||
prefersHeaders.push('missing=default');
|
||||
}
|
||||
this.headers['Prefer'] = prefersHeaders.join(',');
|
||||
if (Array.isArray(values)) {
|
||||
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
|
||||
if (columns.length > 0) {
|
||||
const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
|
||||
this.url.searchParams.set('columns', uniqueColumns.join(','));
|
||||
}
|
||||
}
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url: this.url,
|
||||
headers: this.headers,
|
||||
schema: this.schema,
|
||||
body: values,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Perform an UPDATE on the table or view.
|
||||
*
|
||||
* By default, updated rows are not returned. To return it, chain the call
|
||||
* with `.select()` after filters.
|
||||
*
|
||||
* @param values - The values to update with
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.count - Count algorithm to use to count updated rows.
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*/
|
||||
update(values, { count, } = {}) {
|
||||
const method = 'PATCH';
|
||||
const prefersHeaders = [];
|
||||
if (this.headers['Prefer']) {
|
||||
prefersHeaders.push(this.headers['Prefer']);
|
||||
}
|
||||
if (count) {
|
||||
prefersHeaders.push(`count=${count}`);
|
||||
}
|
||||
this.headers['Prefer'] = prefersHeaders.join(',');
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url: this.url,
|
||||
headers: this.headers,
|
||||
schema: this.schema,
|
||||
body: values,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Perform a DELETE on the table or view.
|
||||
*
|
||||
* By default, deleted rows are not returned. To return it, chain the call
|
||||
* with `.select()` after filters.
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.count - Count algorithm to use to count deleted rows.
|
||||
*
|
||||
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
||||
* hood.
|
||||
*
|
||||
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
||||
* statistics under the hood.
|
||||
*
|
||||
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
||||
* numbers.
|
||||
*/
|
||||
delete({ count, } = {}) {
|
||||
const method = 'DELETE';
|
||||
const prefersHeaders = [];
|
||||
if (count) {
|
||||
prefersHeaders.push(`count=${count}`);
|
||||
}
|
||||
if (this.headers['Prefer']) {
|
||||
prefersHeaders.unshift(this.headers['Prefer']);
|
||||
}
|
||||
this.headers['Prefer'] = prefersHeaders.join(',');
|
||||
return new PostgrestFilterBuilder_1.default({
|
||||
method,
|
||||
url: this.url,
|
||||
headers: this.headers,
|
||||
schema: this.schema,
|
||||
fetch: this.fetch,
|
||||
allowEmpty: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestQueryBuilder;
|
||||
//# sourceMappingURL=PostgrestQueryBuilder.js.map
|
||||
Generated
Vendored
-222
@@ -1,222 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const PostgrestBuilder_1 = __importDefault(require("./PostgrestBuilder"));
|
||||
class PostgrestTransformBuilder extends PostgrestBuilder_1.default {
|
||||
/**
|
||||
* Perform a SELECT on the query result.
|
||||
*
|
||||
* By default, `.insert()`, `.update()`, `.upsert()`, and `.delete()` do not
|
||||
* return modified rows. By calling this method, modified rows are returned in
|
||||
* `data`.
|
||||
*
|
||||
* @param columns - The columns to retrieve, separated by commas
|
||||
*/
|
||||
select(columns) {
|
||||
// Remove whitespaces except when quoted
|
||||
let quoted = false;
|
||||
const cleanedColumns = (columns !== null && columns !== void 0 ? columns : '*')
|
||||
.split('')
|
||||
.map((c) => {
|
||||
if (/\s/.test(c) && !quoted) {
|
||||
return '';
|
||||
}
|
||||
if (c === '"') {
|
||||
quoted = !quoted;
|
||||
}
|
||||
return c;
|
||||
})
|
||||
.join('');
|
||||
this.url.searchParams.set('select', cleanedColumns);
|
||||
if (this.headers['Prefer']) {
|
||||
this.headers['Prefer'] += ',';
|
||||
}
|
||||
this.headers['Prefer'] += 'return=representation';
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Order the query result by `column`.
|
||||
*
|
||||
* You can call this method multiple times to order by multiple columns.
|
||||
*
|
||||
* You can order referenced tables, but it only affects the ordering of the
|
||||
* parent table if you use `!inner` in the query.
|
||||
*
|
||||
* @param column - The column to order by
|
||||
* @param options - Named parameters
|
||||
* @param options.ascending - If `true`, the result will be in ascending order
|
||||
* @param options.nullsFirst - If `true`, `null`s appear first. If `false`,
|
||||
* `null`s appear last.
|
||||
* @param options.referencedTable - Set this to order a referenced table by
|
||||
* its columns
|
||||
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
||||
* instead
|
||||
*/
|
||||
order(column, { ascending = true, nullsFirst, foreignTable, referencedTable = foreignTable, } = {}) {
|
||||
const key = referencedTable ? `${referencedTable}.order` : 'order';
|
||||
const existingOrder = this.url.searchParams.get(key);
|
||||
this.url.searchParams.set(key, `${existingOrder ? `${existingOrder},` : ''}${column}.${ascending ? 'asc' : 'desc'}${nullsFirst === undefined ? '' : nullsFirst ? '.nullsfirst' : '.nullslast'}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Limit the query result by `count`.
|
||||
*
|
||||
* @param count - The maximum number of rows to return
|
||||
* @param options - Named parameters
|
||||
* @param options.referencedTable - Set this to limit rows of referenced
|
||||
* tables instead of the parent table
|
||||
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
||||
* instead
|
||||
*/
|
||||
limit(count, { foreignTable, referencedTable = foreignTable, } = {}) {
|
||||
const key = typeof referencedTable === 'undefined' ? 'limit' : `${referencedTable}.limit`;
|
||||
this.url.searchParams.set(key, `${count}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Limit the query result by starting at an offset `from` and ending at the offset `to`.
|
||||
* Only records within this range are returned.
|
||||
* This respects the query order and if there is no order clause the range could behave unexpectedly.
|
||||
* The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
|
||||
* and fourth rows of the query.
|
||||
*
|
||||
* @param from - The starting index from which to limit the result
|
||||
* @param to - The last index to which to limit the result
|
||||
* @param options - Named parameters
|
||||
* @param options.referencedTable - Set this to limit rows of referenced
|
||||
* tables instead of the parent table
|
||||
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
||||
* instead
|
||||
*/
|
||||
range(from, to, { foreignTable, referencedTable = foreignTable, } = {}) {
|
||||
const keyOffset = typeof referencedTable === 'undefined' ? 'offset' : `${referencedTable}.offset`;
|
||||
const keyLimit = typeof referencedTable === 'undefined' ? 'limit' : `${referencedTable}.limit`;
|
||||
this.url.searchParams.set(keyOffset, `${from}`);
|
||||
// Range is inclusive, so add 1
|
||||
this.url.searchParams.set(keyLimit, `${to - from + 1}`);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the AbortSignal for the fetch request.
|
||||
*
|
||||
* @param signal - The AbortSignal to use for the fetch request
|
||||
*/
|
||||
abortSignal(signal) {
|
||||
this.signal = signal;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Return `data` as a single object instead of an array of objects.
|
||||
*
|
||||
* Query result must be one row (e.g. using `.limit(1)`), otherwise this
|
||||
* returns an error.
|
||||
*/
|
||||
single() {
|
||||
this.headers['Accept'] = 'application/vnd.pgrst.object+json';
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Return `data` as a single object instead of an array of objects.
|
||||
*
|
||||
* Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
|
||||
* this returns an error.
|
||||
*/
|
||||
maybeSingle() {
|
||||
// Temporary partial fix for https://github.com/supabase/postgrest-js/issues/361
|
||||
// Issue persists e.g. for `.insert([...]).select().maybeSingle()`
|
||||
if (this.method === 'GET') {
|
||||
this.headers['Accept'] = 'application/json';
|
||||
}
|
||||
else {
|
||||
this.headers['Accept'] = 'application/vnd.pgrst.object+json';
|
||||
}
|
||||
this.isMaybeSingle = true;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Return `data` as a string in CSV format.
|
||||
*/
|
||||
csv() {
|
||||
this.headers['Accept'] = 'text/csv';
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Return `data` as an object in [GeoJSON](https://geojson.org) format.
|
||||
*/
|
||||
geojson() {
|
||||
this.headers['Accept'] = 'application/geo+json';
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Return `data` as the EXPLAIN plan for the query.
|
||||
*
|
||||
* You need to enable the
|
||||
* [db_plan_enabled](https://supabase.com/docs/guides/database/debugging-performance#enabling-explain)
|
||||
* setting before using this method.
|
||||
*
|
||||
* @param options - Named parameters
|
||||
*
|
||||
* @param options.analyze - If `true`, the query will be executed and the
|
||||
* actual run time will be returned
|
||||
*
|
||||
* @param options.verbose - If `true`, the query identifier will be returned
|
||||
* and `data` will include the output columns of the query
|
||||
*
|
||||
* @param options.settings - If `true`, include information on configuration
|
||||
* parameters that affect query planning
|
||||
*
|
||||
* @param options.buffers - If `true`, include information on buffer usage
|
||||
*
|
||||
* @param options.wal - If `true`, include information on WAL record generation
|
||||
*
|
||||
* @param options.format - The format of the output, can be `"text"` (default)
|
||||
* or `"json"`
|
||||
*/
|
||||
explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, format = 'text', } = {}) {
|
||||
var _a;
|
||||
const options = [
|
||||
analyze ? 'analyze' : null,
|
||||
verbose ? 'verbose' : null,
|
||||
settings ? 'settings' : null,
|
||||
buffers ? 'buffers' : null,
|
||||
wal ? 'wal' : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('|');
|
||||
// An Accept header can carry multiple media types but postgrest-js always sends one
|
||||
const forMediatype = (_a = this.headers['Accept']) !== null && _a !== void 0 ? _a : 'application/json';
|
||||
this.headers['Accept'] = `application/vnd.pgrst.plan+${format}; for="${forMediatype}"; options=${options};`;
|
||||
if (format === 'json')
|
||||
return this;
|
||||
else
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Rollback the query.
|
||||
*
|
||||
* `data` will still be returned, but the query is not committed.
|
||||
*/
|
||||
rollback() {
|
||||
var _a;
|
||||
if (((_a = this.headers['Prefer']) !== null && _a !== void 0 ? _a : '').trim().length > 0) {
|
||||
this.headers['Prefer'] += ',tx=rollback';
|
||||
}
|
||||
else {
|
||||
this.headers['Prefer'] = 'tx=rollback';
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Override the type of the returned `data`.
|
||||
*
|
||||
* @typeParam NewResult - The new result type to override with
|
||||
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
||||
*/
|
||||
returns() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.default = PostgrestTransformBuilder;
|
||||
//# sourceMappingURL=PostgrestTransformBuilder.js.map
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DEFAULT_HEADERS = void 0;
|
||||
const version_1 = require("./version");
|
||||
exports.DEFAULT_HEADERS = { 'X-Client-Info': `postgrest-js/${version_1.version}` };
|
||||
//# sourceMappingURL=constants.js.map
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PostgrestError = exports.PostgrestBuilder = exports.PostgrestTransformBuilder = exports.PostgrestFilterBuilder = exports.PostgrestQueryBuilder = exports.PostgrestClient = void 0;
|
||||
// Always update wrapper.mjs when updating this file.
|
||||
const PostgrestClient_1 = __importDefault(require("./PostgrestClient"));
|
||||
exports.PostgrestClient = PostgrestClient_1.default;
|
||||
const PostgrestQueryBuilder_1 = __importDefault(require("./PostgrestQueryBuilder"));
|
||||
exports.PostgrestQueryBuilder = PostgrestQueryBuilder_1.default;
|
||||
const PostgrestFilterBuilder_1 = __importDefault(require("./PostgrestFilterBuilder"));
|
||||
exports.PostgrestFilterBuilder = PostgrestFilterBuilder_1.default;
|
||||
const PostgrestTransformBuilder_1 = __importDefault(require("./PostgrestTransformBuilder"));
|
||||
exports.PostgrestTransformBuilder = PostgrestTransformBuilder_1.default;
|
||||
const PostgrestBuilder_1 = __importDefault(require("./PostgrestBuilder"));
|
||||
exports.PostgrestBuilder = PostgrestBuilder_1.default;
|
||||
const PostgrestError_1 = __importDefault(require("./PostgrestError"));
|
||||
exports.PostgrestError = PostgrestError_1.default;
|
||||
exports.default = {
|
||||
PostgrestClient: PostgrestClient_1.default,
|
||||
PostgrestQueryBuilder: PostgrestQueryBuilder_1.default,
|
||||
PostgrestFilterBuilder: PostgrestFilterBuilder_1.default,
|
||||
PostgrestTransformBuilder: PostgrestTransformBuilder_1.default,
|
||||
PostgrestBuilder: PostgrestBuilder_1.default,
|
||||
PostgrestError: PostgrestError_1.default,
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = void 0;
|
||||
exports.version = '0.0.0-automated';
|
||||
//# sourceMappingURL=version.js.map
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
import index from '../cjs/index.js'
|
||||
const {
|
||||
PostgrestClient,
|
||||
PostgrestQueryBuilder,
|
||||
PostgrestFilterBuilder,
|
||||
PostgrestTransformBuilder,
|
||||
PostgrestBuilder,
|
||||
PostgrestError,
|
||||
} = index
|
||||
|
||||
export {
|
||||
PostgrestBuilder,
|
||||
PostgrestClient,
|
||||
PostgrestFilterBuilder,
|
||||
PostgrestQueryBuilder,
|
||||
PostgrestTransformBuilder,
|
||||
PostgrestError,
|
||||
}
|
||||
|
||||
// compatibility with CJS output
|
||||
export default {
|
||||
PostgrestClient,
|
||||
PostgrestQueryBuilder,
|
||||
PostgrestFilterBuilder,
|
||||
PostgrestTransformBuilder,
|
||||
PostgrestBuilder,
|
||||
PostgrestError,
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
{
|
||||
"name": "@supabase/postgrest-js",
|
||||
"version": "1.19.4",
|
||||
"description": "Isomorphic PostgREST client",
|
||||
"keywords": [
|
||||
"postgrest",
|
||||
"supabase"
|
||||
],
|
||||
"homepage": "https://github.com/supabase/postgrest-js",
|
||||
"bugs": "https://github.com/supabase/postgrest-js/issues",
|
||||
"license": "MIT",
|
||||
"author": "Supabase",
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/esm/wrapper.mjs",
|
||||
"exports": {
|
||||
"import": {
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"default": "./dist/esm/wrapper.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"default": "./dist/cjs/index.js"
|
||||
}
|
||||
},
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"repository": "supabase/postgrest-js",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist docs/v2",
|
||||
"format": "prettier --write \"{src,test}/**/*.ts\" wrapper.mjs",
|
||||
"format:check": "prettier --check \"{src,test}/**/*.ts\"",
|
||||
"build": "run-s clean format build:*",
|
||||
"build:cjs": "tsc -p tsconfig.json",
|
||||
"build:esm": "cpy wrapper.mjs dist/esm/",
|
||||
"docs": "typedoc src/index.ts --out docs/v2",
|
||||
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
|
||||
"test": "run-s format:check test:types db:clean db:run test:run db:clean && node test/smoke.cjs && node test/smoke.mjs",
|
||||
"test:run": "jest --runInBand --coverage",
|
||||
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean",
|
||||
"test:types": "run-s build && tsd --files 'test/**/*.test-d.ts'",
|
||||
"db:clean": "cd test/db && docker compose down --volumes",
|
||||
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000"
|
||||
},
|
||||
"dependencies": {
|
||||
"@supabase/node-fetch": "^2.6.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.5.1",
|
||||
"cpy-cli": "^5.0.0",
|
||||
"jest": "^28.1.0",
|
||||
"node-abort-controller": "^3.0.1",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.6.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
||||
"ts-expect": "^1.3.0",
|
||||
"ts-jest": "^28.0.3",
|
||||
"tsd": "^0.31.2",
|
||||
"type-fest": "^4.32.0",
|
||||
"typedoc": "^0.22.16",
|
||||
"typescript": "^4.5.5",
|
||||
"wait-for-localhost-cli": "^3.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user