@supabase/postgrest-js
Advanced tools
Comparing version
@@ -1,6 +0,7 @@ | ||
import PostgrestClient from './PostgrestClient'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import { PostgrestBuilder, PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError } from './lib/types'; | ||
export { PostgrestClient, PostgrestBuilder, PostgrestQueryBuilder, PostgrestFilterBuilder, PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError, }; | ||
export { default as PostgrestClient } from './PostgrestClient'; | ||
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder'; | ||
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder'; | ||
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder'; | ||
export { default as PostgrestBuilder } from './PostgrestBuilder'; | ||
export { PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,11 +6,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PostgrestFilterBuilder = exports.PostgrestQueryBuilder = exports.PostgrestBuilder = exports.PostgrestClient = void 0; | ||
const PostgrestClient_1 = __importDefault(require("./PostgrestClient")); | ||
exports.PostgrestClient = PostgrestClient_1.default; | ||
const PostgrestFilterBuilder_1 = __importDefault(require("./lib/PostgrestFilterBuilder")); | ||
exports.PostgrestFilterBuilder = PostgrestFilterBuilder_1.default; | ||
const PostgrestQueryBuilder_1 = __importDefault(require("./lib/PostgrestQueryBuilder")); | ||
exports.PostgrestQueryBuilder = PostgrestQueryBuilder_1.default; | ||
const types_1 = require("./lib/types"); | ||
Object.defineProperty(exports, "PostgrestBuilder", { enumerable: true, get: function () { return types_1.PostgrestBuilder; } }); | ||
exports.PostgrestBuilder = exports.PostgrestTransformBuilder = exports.PostgrestFilterBuilder = exports.PostgrestQueryBuilder = exports.PostgrestClient = void 0; | ||
var PostgrestClient_1 = require("./PostgrestClient"); | ||
Object.defineProperty(exports, "PostgrestClient", { enumerable: true, get: function () { return __importDefault(PostgrestClient_1).default; } }); | ||
var PostgrestQueryBuilder_1 = require("./PostgrestQueryBuilder"); | ||
Object.defineProperty(exports, "PostgrestQueryBuilder", { enumerable: true, get: function () { return __importDefault(PostgrestQueryBuilder_1).default; } }); | ||
var PostgrestFilterBuilder_1 = require("./PostgrestFilterBuilder"); | ||
Object.defineProperty(exports, "PostgrestFilterBuilder", { enumerable: true, get: function () { return __importDefault(PostgrestFilterBuilder_1).default; } }); | ||
var PostgrestTransformBuilder_1 = require("./PostgrestTransformBuilder"); | ||
Object.defineProperty(exports, "PostgrestTransformBuilder", { enumerable: true, get: function () { return __importDefault(PostgrestTransformBuilder_1).default; } }); | ||
var PostgrestBuilder_1 = require("./PostgrestBuilder"); | ||
Object.defineProperty(exports, "PostgrestBuilder", { enumerable: true, get: function () { return __importDefault(PostgrestBuilder_1).default; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,12 +0,10 @@ | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import { Fetch } from './lib/types'; | ||
export default class PostgrestClient { | ||
import PostgrestQueryBuilder from './PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
import { Fetch, GenericSchema } from './types'; | ||
export default class PostgrestClient<Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any> { | ||
url: string; | ||
headers: { | ||
[key: string]: string; | ||
}; | ||
schema?: string; | ||
headers: Record<string, string>; | ||
schema?: SchemaName; | ||
fetch?: Fetch; | ||
shouldThrowOnError?: boolean; | ||
shouldThrowOnError: boolean; | ||
/** | ||
@@ -20,6 +18,4 @@ * Creates a PostgREST client. | ||
constructor(url: string, { headers, schema, fetch, throwOnError, }?: { | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
schema?: string; | ||
headers?: Record<string, string>; | ||
schema?: SchemaName; | ||
fetch?: Fetch; | ||
@@ -32,2 +28,4 @@ throwOnError?: boolean; | ||
* @param token The JWT token to use. | ||
* | ||
* @deprecated Use `headers` in constructor instead. | ||
*/ | ||
@@ -40,3 +38,3 @@ auth(token: string): this; | ||
*/ | ||
from<T = any>(table: string): PostgrestQueryBuilder<T>; | ||
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): PostgrestQueryBuilder<Table>; | ||
/** | ||
@@ -46,11 +44,12 @@ * Perform a function call. | ||
* @param fn The function name to call. | ||
* @param params The parameters to pass to the function call. | ||
* @param head When set to true, no data will be returned. | ||
* @param count Count algorithm to use to count rows in a table. | ||
* @param args The parameters to pass to the function call. | ||
* @param options Named parameters. | ||
* @param options.head When set to true, no data will be returned. | ||
* @param options.count Count algorithm to use to count rows in a table. | ||
*/ | ||
rpc<T = any>(fn: string, params?: object, { head, count, }?: { | ||
rpc<FunctionName extends string & keyof Schema['Functions'], Function_ extends Schema['Functions'][FunctionName]>(fn: FunctionName, args?: Function_['Args'], { head, count, }?: { | ||
head?: boolean; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
count?: 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>; | ||
} | ||
//# sourceMappingURL=PostgrestClient.d.ts.map |
@@ -6,5 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const PostgrestQueryBuilder_1 = __importDefault(require("./lib/PostgrestQueryBuilder")); | ||
const PostgrestRpcBuilder_1 = __importDefault(require("./lib/PostgrestRpcBuilder")); | ||
const constants_1 = require("./lib/constants"); | ||
const PostgrestQueryBuilder_1 = __importDefault(require("./PostgrestQueryBuilder")); | ||
const PostgrestFilterBuilder_1 = __importDefault(require("./PostgrestFilterBuilder")); | ||
const constants_1 = require("./constants"); | ||
class PostgrestClient { | ||
@@ -18,3 +18,3 @@ /** | ||
*/ | ||
constructor(url, { headers = {}, schema, fetch, throwOnError, } = {}) { | ||
constructor(url, { headers = {}, schema, fetch, throwOnError = false, } = {}) { | ||
this.url = url; | ||
@@ -30,2 +30,4 @@ this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers); | ||
* @param token The JWT token to use. | ||
* | ||
* @deprecated Use `headers` in constructor instead. | ||
*/ | ||
@@ -42,5 +44,5 @@ auth(token) { | ||
from(table) { | ||
const url = `${this.url}/${table}`; | ||
const url = new URL(`${this.url}/${table}`); | ||
return new PostgrestQueryBuilder_1.default(url, { | ||
headers: this.headers, | ||
headers: Object.assign({}, this.headers), | ||
schema: this.schema, | ||
@@ -55,14 +57,35 @@ fetch: this.fetch, | ||
* @param fn The function name to call. | ||
* @param params The parameters to pass to the function call. | ||
* @param head When set to true, no data will be returned. | ||
* @param count Count algorithm to use to count rows in a table. | ||
* @param args The parameters to pass to the function call. | ||
* @param options Named parameters. | ||
* @param options.head When set to true, no data will be returned. | ||
* @param options.count Count algorithm to use to count rows in a table. | ||
*/ | ||
rpc(fn, params, { head = false, count = null, } = {}) { | ||
const url = `${this.url}/rpc/${fn}`; | ||
return new PostgrestRpcBuilder_1.default(url, { | ||
headers: this.headers, | ||
rpc(fn, args = {}, { head = false, count, } = {}) { | ||
let method; | ||
const url = new URL(`${this.url}/rpc/${fn}`); | ||
let body; | ||
if (head) { | ||
method = 'HEAD'; | ||
Object.entries(args).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.schema, | ||
body, | ||
fetch: this.fetch, | ||
shouldThrowOnError: this.shouldThrowOnError, | ||
}).rpc(params, { head, count }); | ||
allowEmpty: false, | ||
}); | ||
} | ||
@@ -69,0 +92,0 @@ } |
@@ -1,6 +0,7 @@ | ||
import PostgrestClient from './PostgrestClient'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import { PostgrestBuilder, PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError } from './lib/types'; | ||
export { PostgrestClient, PostgrestBuilder, PostgrestQueryBuilder, PostgrestFilterBuilder, PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError, }; | ||
export { default as PostgrestClient } from './PostgrestClient'; | ||
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder'; | ||
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder'; | ||
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder'; | ||
export { default as PostgrestBuilder } from './PostgrestBuilder'; | ||
export { PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import PostgrestClient from './PostgrestClient'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import { PostgrestBuilder, } from './lib/types'; | ||
export { PostgrestClient, PostgrestBuilder, PostgrestQueryBuilder, PostgrestFilterBuilder, }; | ||
export { default as PostgrestClient } from './PostgrestClient'; | ||
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder'; | ||
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder'; | ||
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder'; | ||
export { default as PostgrestBuilder } from './PostgrestBuilder'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,12 +0,10 @@ | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import { Fetch } from './lib/types'; | ||
export default class PostgrestClient { | ||
import PostgrestQueryBuilder from './PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
import { Fetch, GenericSchema } from './types'; | ||
export default class PostgrestClient<Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any> { | ||
url: string; | ||
headers: { | ||
[key: string]: string; | ||
}; | ||
schema?: string; | ||
headers: Record<string, string>; | ||
schema?: SchemaName; | ||
fetch?: Fetch; | ||
shouldThrowOnError?: boolean; | ||
shouldThrowOnError: boolean; | ||
/** | ||
@@ -20,6 +18,4 @@ * Creates a PostgREST client. | ||
constructor(url: string, { headers, schema, fetch, throwOnError, }?: { | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
schema?: string; | ||
headers?: Record<string, string>; | ||
schema?: SchemaName; | ||
fetch?: Fetch; | ||
@@ -32,2 +28,4 @@ throwOnError?: boolean; | ||
* @param token The JWT token to use. | ||
* | ||
* @deprecated Use `headers` in constructor instead. | ||
*/ | ||
@@ -40,3 +38,3 @@ auth(token: string): this; | ||
*/ | ||
from<T = any>(table: string): PostgrestQueryBuilder<T>; | ||
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): PostgrestQueryBuilder<Table>; | ||
/** | ||
@@ -46,11 +44,12 @@ * Perform a function call. | ||
* @param fn The function name to call. | ||
* @param params The parameters to pass to the function call. | ||
* @param head When set to true, no data will be returned. | ||
* @param count Count algorithm to use to count rows in a table. | ||
* @param args The parameters to pass to the function call. | ||
* @param options Named parameters. | ||
* @param options.head When set to true, no data will be returned. | ||
* @param options.count Count algorithm to use to count rows in a table. | ||
*/ | ||
rpc<T = any>(fn: string, params?: object, { head, count, }?: { | ||
rpc<FunctionName extends string & keyof Schema['Functions'], Function_ extends Schema['Functions'][FunctionName]>(fn: FunctionName, args?: Function_['Args'], { head, count, }?: { | ||
head?: boolean; | ||
count?: null | 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<T>; | ||
count?: 'exact' | 'planned' | 'estimated'; | ||
}): PostgrestFilterBuilder<Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>; | ||
} | ||
//# sourceMappingURL=PostgrestClient.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import PostgrestRpcBuilder from './lib/PostgrestRpcBuilder'; | ||
import { DEFAULT_HEADERS } from './lib/constants'; | ||
import PostgrestQueryBuilder from './PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
import { DEFAULT_HEADERS } from './constants'; | ||
export default class PostgrestClient { | ||
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
constructor(url, { headers = {}, schema, fetch, throwOnError, } = {}) { | ||
constructor(url, { headers = {}, schema, fetch, throwOnError = false, } = {}) { | ||
this.url = url; | ||
@@ -24,2 +24,4 @@ this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), headers); | ||
* @param token The JWT token to use. | ||
* | ||
* @deprecated Use `headers` in constructor instead. | ||
*/ | ||
@@ -36,5 +38,5 @@ auth(token) { | ||
from(table) { | ||
const url = `${this.url}/${table}`; | ||
const url = new URL(`${this.url}/${table}`); | ||
return new PostgrestQueryBuilder(url, { | ||
headers: this.headers, | ||
headers: Object.assign({}, this.headers), | ||
schema: this.schema, | ||
@@ -49,16 +51,37 @@ fetch: this.fetch, | ||
* @param fn The function name to call. | ||
* @param params The parameters to pass to the function call. | ||
* @param head When set to true, no data will be returned. | ||
* @param count Count algorithm to use to count rows in a table. | ||
* @param args The parameters to pass to the function call. | ||
* @param options Named parameters. | ||
* @param options.head When set to true, no data will be returned. | ||
* @param options.count Count algorithm to use to count rows in a table. | ||
*/ | ||
rpc(fn, params, { head = false, count = null, } = {}) { | ||
const url = `${this.url}/rpc/${fn}`; | ||
return new PostgrestRpcBuilder(url, { | ||
headers: this.headers, | ||
rpc(fn, args = {}, { head = false, count, } = {}) { | ||
let method; | ||
const url = new URL(`${this.url}/rpc/${fn}`); | ||
let body; | ||
if (head) { | ||
method = 'HEAD'; | ||
Object.entries(args).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({ | ||
method, | ||
url, | ||
headers, | ||
schema: this.schema, | ||
body, | ||
fetch: this.fetch, | ||
shouldThrowOnError: this.shouldThrowOnError, | ||
}).rpc(params, { head, count }); | ||
allowEmpty: false, | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=PostgrestClient.js.map |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "0.37.3", | ||
"version": "1.0.0-next.1", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -14,4 +14,3 @@ "keywords": [ | ||
"files": [ | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
@@ -25,10 +24,11 @@ "main": "dist/main/index.js", | ||
"format": "prettier --write \"{src,test}/**/*.ts\"", | ||
"build": "genversion src/lib/version.ts --es6 && run-s clean format build:*", | ||
"build": "run-s clean format build:*", | ||
"build:main": "tsc -p tsconfig.json", | ||
"build:module": "tsc -p tsconfig.module.json", | ||
"test": "run-s test:db && jest --runInBand", | ||
"test:clean": "cd test/db && docker-compose down", | ||
"test:db": "cd test/db && docker-compose down && docker-compose up -d && wait-for-localhost 3000", | ||
"docs": "typedoc --mode file --target ES6 --theme minimal", | ||
"docs:json": "typedoc --json docs/spec.json --mode modules --includeDeclarations --excludeExternals" | ||
"test": "run-s db:clean db:run && jest --runInBand; run-s db:clean", | ||
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot; run-s db:clean", | ||
"db:clean": "cd test/db && docker-compose down", | ||
"db:run": "cd test/db && docker-compose up --detach && wait-for-localhost 3000", | ||
"docs": "typedoc src/index.ts", | ||
"docs:json": "typedoc --json docs/spec.json src/index.ts" | ||
}, | ||
@@ -39,16 +39,15 @@ "dependencies": { | ||
"devDependencies": { | ||
"@types/jest": "^26.0.13", | ||
"@types/node-fetch": "^2.5.7", | ||
"genversion": "^3.0.1", | ||
"jest": "^26.4.1", | ||
"node-abort-controller": "^3.0.0", | ||
"@types/jest": "^27.5.1", | ||
"@types/node-fetch": "^2.6.1", | ||
"jest": "^28.1.0", | ||
"node-abort-controller": "^3.0.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.5", | ||
"prettier": "^2.6.2", | ||
"rimraf": "^3.0.2", | ||
"semantic-release-plugin-update-version-in-files": "^1.1.0", | ||
"ts-jest": "^26.3.0", | ||
"typedoc": "^0.22.15", | ||
"typescript": "^4.0.2", | ||
"wait-for-localhost-cli": "^2.0.0" | ||
"ts-jest": "^28.0.3", | ||
"typedoc": "^0.22.16", | ||
"typescript": "~4.6.4", | ||
"wait-for-localhost-cli": "^3.0.0" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12
-7.69%9
-10%190052
-11.57%83
-1.19%2633
-33.61%