Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@supabase/postgrest-js

Package Overview
Dependencies
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supabase/postgrest-js - npm Package Compare versions

Comparing version 0.13.0 to 0.14.0

4

lib/Builder.js

@@ -16,3 +16,3 @@ "use strict";var _Request=_interopRequireDefault(require("./Request"));Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}/**

* @param {string} url The full URL
*/var Builder=/*#__PURE__*/function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,a),this.url=b,this.queryFilters=[],this.headers=c}return _createClass(a,[{key:"request",value:function request(a){return new _Request["default"](a,this.url,this.headers)}},{key:"addFilters",value:function addFilters(a,b){0!=Object.keys(b).length&&Object.keys(b).forEach(function(c){var d=b[c];a.set(c,d)}),this.queryFilters.forEach(function(b){switch(b.filter){case"filter":a.filter(b.columnName,b.operator,b.criteria);break;case"not":a.not(b.columnName,b.operator,b.criteria);break;case"match":a.match(b.query);break;case"order":a.order(b.property,b.ascending,b.nullsFirst);break;case"range":a.range(b.from,b.to);break;case"single":a.single();break;default:}})}},{key:"filter",value:function filter(a,b,c){return this.queryFilters.push({filter:"filter",columnName:a,operator:b,criteria:c}),this}},{key:"not",value:function not(a,b,c){return this.queryFilters.push({filter:"not",columnName:a,operator:b,criteria:c}),this}},{key:"match",value:function match(a){return this.queryFilters.push({filter:"match",query:a}),this}},{key:"order",value:function order(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],c=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];return this.queryFilters.push({filter:"order",property:a,ascending:b,nullsFirst:c}),this}},{key:"range",value:function range(a,b){return this.queryFilters.push({filter:"range",from:a,to:b}),this}},{key:"single",value:function single(){return this.queryFilters.push({filter:"single"}),this}/**
*/var Builder=/*#__PURE__*/function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=2<arguments.length?arguments[2]:void 0;_classCallCheck(this,a),this.url=b,this.queryFilters=[],this.headers=c,this.schema=d}return _createClass(a,[{key:"request",value:function request(a){return this.schema&&("GET"==a?this.headers["Accept-Profile"]=this.schema:this.headers["Content-Profile"]=this.schema),new _Request["default"](a,this.url,this.headers)}},{key:"addFilters",value:function addFilters(a,b){0!=Object.keys(b).length&&Object.keys(b).forEach(function(c){var d=b[c];a.set(c,d)}),this.queryFilters.forEach(function(b){switch(b.filter){case"filter":a.filter(b.columnName,b.operator,b.criteria);break;case"not":a.not(b.columnName,b.operator,b.criteria);break;case"match":a.match(b.query);break;case"order":a.order(b.property,b.ascending,b.nullsFirst);break;case"range":a.range(b.from,b.to);break;case"single":a.single();break;default:}})}},{key:"filter",value:function filter(a,b,c){return this.queryFilters.push({filter:"filter",columnName:a,operator:b,criteria:c}),this}},{key:"not",value:function not(a,b,c){return this.queryFilters.push({filter:"not",columnName:a,operator:b,criteria:c}),this}},{key:"match",value:function match(a){return this.queryFilters.push({filter:"match",query:a}),this}},{key:"order",value:function order(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],c=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];return this.queryFilters.push({filter:"order",property:a,ascending:b,nullsFirst:c}),this}},{key:"range",value:function range(a,b){return this.queryFilters.push({filter:"range",from:a,to:b}),this}},{key:"single",value:function single(){return this.queryFilters.push({filter:"single"}),this}/**
* Start a "GET" request

@@ -25,3 +25,3 @@ */},{key:"select",value:function select(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"*",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=this.request("GET");return c.select(a),this.addFilters(c,b),c}/**

* Start a "DELETE" request
*/},{key:"delete",value:function _delete(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=this.request("DELETE");return this.addFilters(b,a),b}}]),a}(),advancedFilters=["eq","neq","gt","lt","gte","lte","like","ilike","is","in","cs","cd","ov","sl","sr","nxr","nxl","adj"];// pre-empts if any of the filters are used before select
*/},{key:"delete",value:function _delete(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=this.request("DELETE");return this.addFilters(b,a),b}}]),a}(),advancedFilters=["eq","neq","gt","lt","gte","lte","like","ilike","is","in","cs","cd","ova","ovr","sl","sr","nxr","nxl","adj"];// pre-empts if any of the filters are used before select
advancedFilters.forEach(function(a){return Builder.prototype[a]=function(b,c){return this.filter(b,a,c),this}});var _default=Builder;exports["default"]=_default;

@@ -1,1 +0,1 @@

"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostgrestClient=void 0;var _Builder=_interopRequireDefault(require("./Builder")),_Request=_interopRequireDefault(require("./Request")),Helpers=_interopRequireWildcard(require("./utils/Helpers"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c["default"]=a,b&&b.set(a,c),c}function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}var PostgrestClient=/*#__PURE__*/function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,a),this.restUrl=b,this.queryString=null,this.headers={},c.headers&&(this.headers=c.headers),c.queryParams&&(this.queryString=Helpers.objectToQueryString(c.queryParams))}return _createClass(a,[{key:"from",value:function from(a){var b="".concat(this.restUrl,"/").concat(a);return this.queryString&&(b+="?".concat(this.queryString)),new _Builder["default"](b,this.headers)}},{key:"rpc",value:function rpc(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c="".concat(this.restUrl,"/rpc/").concat(a);this.queryString&&(c+="?".concat(this.queryString));var d=new _Request["default"]("post",c,this.headers);return null!=b&&d.send(b),d}}]),a}();exports.PostgrestClient=PostgrestClient;
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostgrestClient=void 0;var _Builder=_interopRequireDefault(require("./Builder")),_Request=_interopRequireDefault(require("./Request")),Helpers=_interopRequireWildcard(require("./utils/Helpers"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c["default"]=a,b&&b.set(a,c),c}function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}var PostgrestClient=/*#__PURE__*/function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,a),this.restUrl=b,this.headers={},this.queryString=null,this.schema=null,c.headers&&(this.headers=c.headers),c.queryParams&&(this.queryString=Helpers.objectToQueryString(c.queryParams)),c.schema&&(this.schema=c.schema)}return _createClass(a,[{key:"from",value:function from(a){var b="".concat(this.restUrl,"/").concat(a);return this.queryString&&(b+="?".concat(this.queryString)),new _Builder["default"](b,this.headers,this.schema)}},{key:"rpc",value:function rpc(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c="".concat(this.restUrl,"/rpc/").concat(a),d=this.headers;this.queryString&&(c+="?".concat(this.queryString)),this.schema&&(d["Content-Profile"]=this.schema,d["Accept-Profile"]=this.schema);var e=new _Request["default"]("post",c,d);return null!=b&&e.send(b),e}}]),a}();exports.PostgrestClient=PostgrestClient;

@@ -79,2 +79,2 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var _superagent=require("superagent"),Filters=_interopRequireWildcard(require("./utils/Filters"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c["default"]=a,b&&b.set(a,c),c}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _get(a,b,c){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(a,b,c){var d=_superPropBase(a,b);if(d){var e=Object.getOwnPropertyDescriptor(d,b);return e.get?e.get.call(c):e.value}},_get(a,b,c||a)}function _superPropBase(a,b){for(;!Object.prototype.hasOwnProperty.call(a,b)&&(a=_getPrototypeOf(a),null!==a););return a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){return function(){var b,c=_getPrototypeOf(a);if(_isNativeReflectConstruct()){var d=_getPrototypeOf(this).constructor;b=Reflect.construct(c,arguments,d)}else b=c.apply(this,arguments);return _possibleConstructorReturn(this,b)}}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}var contentRangeStructure=/^(\d+)-(\d+)\/(\d+)$/,Request=/*#__PURE__*/function(a){function b(a,d){var e,f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(_classCallCheck(this,b),e=c.call(this,a,d),e.set("Accept","application/json"),{}!=f)for(var g in f)e.set(g,f[g]);// Fix for superagent disconnect on client & server.

* @returns {Promise} Resolves when there is an error.
*/},{key:"catch",value:function _catch(a){return this.end()["catch"](a)}}]),b}(_superagent.Request),filters=["eq","neq","gt","lt","gte","lte","like","ilike","is","in","cs","cd","ov","sl","sr","nxr","nxl","adj"];filters.forEach(function(a){return Request.prototype[a]=function(b,c){return this.filter(b,a,c)}});var _default=Request;exports["default"]=_default;
*/},{key:"catch",value:function _catch(a){return this.end()["catch"](a)}}]),b}(_superagent.Request),filters=["eq","neq","gt","lt","gte","lte","like","ilike","is","in","cs","cd","ova","ovr","sl","sr","nxr","nxl","adj"];filters.forEach(function(a){return Request.prototype[a]=function(b,c){return this.filter(b,a,c)}});var _default=Request;exports["default"]=_default;
{
"name": "@supabase/postgrest-js",
"version": "0.13.0",
"version": "0.14.0",
"description": "PostgREST JS client",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -35,3 +35,26 @@ # Postgrest JS

#### PostgrestClient(postgrestURL, OPTIONS)
`postgrestURL: string`
The URL from where your postgREST queries.
`OPTIONS: object?`
```
/**
* @ param {object?} headers
* List of headers as keys and their corresponding values
*
* @ param {object?} query_params
* List of query parameters as keys and their corresponding values
*
* @ param {string} schema
* If you are using postgREST version v7.0.0 and above,
* you can use this to indicate your selected schema.
* This is provided that your schema is included in db-schema
*/
```
To know more about multi schema and swithching between schema, more information can be found [here](http://postgrest.org/en/v7.0.0/configuration.html#db-schema).
### GET
These filters also support our `PATCH` and `DELETE` actions as well. More information on our filters can be found [here](https://supabase.io/docs/library/get#filter_).

@@ -72,2 +95,14 @@ ```js

// Not (the reverse of .filter())
let { body: countries } = await client
.from('countries')
.select(`
name,
cities (
name
)
`)
.not('name', 'eq', 'New Zealand')
.not('cities.name', 'eq', 'Auckland')
// Ordering

@@ -148,5 +183,59 @@ let { body: countries } = await client

.from('countries')
.not('name', 'China')
.neq('name', 'China')
.select('*')
// Contains
let { body: countries } = await client
.from('countries')
.cs('main_exports', ['oil'])
.select('*')
// Contained in
let { body: countries } = await client
.from('countries')
.cd('main_exports', ['cars', 'food', 'machine'])
.select('*')
// Overlaps (for arrays)
let { body: countries } = await client
.from('countries')
.ova('main_exports', ['computers', 'minerals'])
.select('*')
// Overlaps (for ranges)
let { body: countries } = await client
.from('countries')
.ovr('population_range_millions', [150, 250])
.select('*')
// Strictly left
let { body: countries } = await client
.from('countries')
.sl('population_range_millions', [150, 250])
.select('*')
// Strictly right
let { body: countries } = await client
.from('countries')
.sr('population_range_millions', [150, 250])
.select('*')
// Does not extend to the left
let { body: countries } = await client
.from('countries')
.nxl('population_range_millions', [150, 250])
.select('*')
// Does not extend to the right
let { body: countries } = await client
.from('countries')
.nxr('population_range_millions', [150, 250])
.select('*')
// Adjacent
let { body: countries } = await client
.from('countries')
.adj('population_range_millions', [70, 185])
.select('*')
```

@@ -153,0 +242,0 @@

@@ -21,9 +21,14 @@ import Request from './Request'

class Builder {
constructor(url, headers = {}) {
constructor(url, headers = {}, schema) {
this.url = url
this.queryFilters = []
this.headers = headers
this.schema = schema
}
request(method) {
if(this.schema){
if(method == 'GET') this.headers['Accept-Profile'] = this.schema
else this.headers['Content-Profile'] = this.schema
}
return new Request(method, this.url, this.headers)

@@ -213,3 +218,4 @@ }

'cd',
'ov',
'ova',
'ovr',
'sl',

@@ -216,0 +222,0 @@ 'sr',

@@ -17,7 +17,9 @@ /**

this.restUrl = restUrl
this.headers = {}
this.queryString = null
this.headers = {}
this.schema = null
if (options.headers) this.headers = options.headers
if (options.queryParams) this.queryString = Helpers.objectToQueryString(options.queryParams)
if (options.schema) this.schema = options.schema
}

@@ -28,3 +30,3 @@

if (this.queryString) url += `?${this.queryString}`
return new Builder(url, this.headers)
return new Builder(url, this.headers, this.schema)
}

@@ -34,4 +36,12 @@

let url = `${this.restUrl}/rpc/${functionName}`
let headers = this.headers
if (this.queryString) url += `?${this.queryString}`
let request = new Request('post', url, this.headers)
if (this.schema) {
// although POST requests should be 'Content-Profile',
// this is only somehow working when the header set is 'Accept-Profile'
// will revisit this when postgREST updates their documentation for multischema rpc
headers['Content-Profile'] = this.schema
headers['Accept-Profile'] = this.schema
}
let request = new Request('post', url, headers)
if (functionParameters != null) request.send(functionParameters)

@@ -38,0 +48,0 @@ return request

@@ -271,3 +271,4 @@ /**

'cd',
'ov',
'ova',
'ovr',
'sl',

@@ -274,0 +275,0 @@ 'sr',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc