@supabase/postgrest-js
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -1,1 +0,25 @@ | ||
"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}var Builder=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"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:"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}},{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}},{key:"insert",value:function insert(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=this.request("POST");return c.set("Prefer","return=representation"),c.send(a),this.addFilters(c,b),c}},{key:"update",value:function update(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=this.request("PATCH");return Array.isArray(a)?{body:null,status:400,statusCode:400,statusText:"Data type should be an object."}:(c.set("Prefer","return=representation"),c.send(a),this.addFilters(c,b),c)}},{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","gt","lt","gte","lte","like","ilike","is","in","not"];advancedFilters.forEach(function(a){return Builder.prototype[a]=function(b,c){return this.filter(b,a,c),this}});var _default=Builder;exports["default"]=_default; | ||
"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}/** | ||
* Allows the user to stack the filter functions before they call any of | ||
* | ||
* select() - "get" | ||
* | ||
* insert() - "post" | ||
* | ||
* update() - "patch" | ||
* | ||
* delete() - "delete" | ||
* | ||
* Once any of these are called the filters are passed down to the Request | ||
* | ||
* @class | ||
* @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"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:"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 | ||
*/},{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 "POST" request | ||
*/},{key:"insert",value:function insert(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{upsert:!1},c=this.request("POST"),d=b.upsert?"return=representation,resolution=merge-duplicates":"return=representation";return c.set("Prefer",d),c.send(a),this.addFilters(c,b),c}/** | ||
* Start a "PATCH" request | ||
*/},{key:"update",value:function update(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=this.request("PATCH");return Array.isArray(a)?{body:null,status:400,statusCode:400,statusText:"Data type should be an object."}:(c.set("Prefer","return=representation"),c.send(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","gt","lt","gte","lte","like","ilike","is","in","not"];// 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){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=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.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; |
@@ -1,1 +0,69 @@ | ||
"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){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 _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 _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 _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(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)}var contentRangeStructure=/^(\d+)-(\d+)\/(\d+)$/,Request=function(a){function b(a,c){var d,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(_classCallCheck(this,b),d=_possibleConstructorReturn(this,_getPrototypeOf(b).call(this,a,c)),d.set("Accept","application/json"),{}!=e)for(var f in e)d.set(f,e[f]);return d.get||(d.get=d.getHeader),d}return _inherits(b,a),_createClass(b,[{key:"auth",value:function auth(a,c){return"string"==typeof a&&null==c?(this.set("Authorization","Bearer ".concat(a)),this):("object"===_typeof(a)&&null==c&&(c=a.pass,a=a.user),_get(_getPrototypeOf(b.prototype),"auth",this).call(this,a,c))}},{key:"filter",value:function filter(a,b,c){var d=Filters["_".concat(b.toLowerCase())](a,c);return this.query(d)}},{key:"match",value:function match(a){var b=this;return Object.keys(a).forEach(function(c){b.query("".concat(c,"=eq.").concat(a[c]))}),this}},{key:"select",value:function select(a){return a&&this.query({select:a.replace(/\s/g,"")}),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.query("order=".concat(a,".").concat(b?"asc":"desc",".").concat(c?"nullsfirst":"nullslast")),this}},{key:"range",value:function range(a,b){var c=0==b?0:b||"";return this.set("Range-Unit","items"),this.set("Range","".concat(a||0,"-").concat(c)),this}},{key:"single",value:function single(){return this.set("Accept","application/vnd.pgrst.object+json"),this.set("Prefer","return=representation"),this}},{key:"end",value:function end(){var a=this;return new Promise(function(c,d){if(["DELETE","PATCH"].includes(a.method)&&0==a._query.length){var e="DELETE"===a.method?".delete()":".update()";return c({body:null,status:400,statusCode:400,statusText:"".concat(e," cannot be invoked without any filters.")})}_get(_getPrototypeOf(b.prototype),"end",a).call(a,function(a,b){if(a)return d(a);var e=b.body,f=b.headers,g=b.status,h=b.statusCode,i=b.statusText,j=f["content-range"];Array.isArray(e)&&j&&contentRangeStructure.test(j)&&(e.fullLength=parseInt(contentRangeStructure.exec(j)[3],10));return c({body:e,status:g,statusCode:h,statusText:i})})})}},{key:"then",value:function then(a,b){return this.end().then(a,b)}},{key:"catch",value:function _catch(a){return this.end()["catch"](a)}}]),b}(_superagent.Request),filters=["eq","gt","lt","gte","lte","like","ilike","is","in","not"];filters.forEach(function(a){return Request.prototype[a]=function(b,c){return this.filter(b,a,c)}});var _default=Request;exports["default"]=_default; | ||
"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 _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)}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)}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. | ||
return e.get||(e.get=e.getHeader),e}/** | ||
* Set auth using special formats. If only one string parameter is passed, it | ||
* is interpreted as a bearer token. If an object and nothing else is passed, | ||
* `user` and `pass` keys are extracted from it and used for basic auth. | ||
* | ||
* @param {string|object} user The user, bearer token, or user/pass object. | ||
* @param {string|void} pass The pass or undefined. | ||
* @returns {Request} The API request object. | ||
*/_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"auth",value:function auth(a,c){return"string"==typeof a&&null==c?(this.set("Authorization","Bearer ".concat(a)),this):("object"===_typeof(a)&&null==c&&(c=a.pass,a=a.user),_get(_getPrototypeOf(b.prototype),"auth",this).call(this,a,c))}/** | ||
* Generic filter method. | ||
* @param {string} columnName The name of the column. | ||
* @param {string} filter The type of filter | ||
* @param { object | array | string | integer | boolean | null } criteria The value of the column to be filtered. | ||
* @name filter | ||
* @function | ||
* @memberOf module:Filters | ||
* @returns {string} | ||
*/},{key:"filter",value:function filter(a,b,c){var d=Filters["_".concat(b.toLowerCase())](a,c);return this.query(d)}/** | ||
* Takes a query object and translates it to a PostgREST filter query string. | ||
* All values are prefixed with `eq.`. | ||
* | ||
* @param {object} query The object to match against. | ||
* @returns {Request} The API request object. | ||
*/},{key:"match",value:function match(a){var b=this;return Object.keys(a).forEach(function(c){b.query("".concat(c,"=eq.").concat(a[c]))}),this}/** | ||
* Cleans up a select string by stripping all whitespace. Then the string is | ||
* set as a query string value. Also always forces a root @id column. | ||
* | ||
* @param {string} select The unformatted select string. | ||
* @returns {Request} The API request object. | ||
*/},{key:"select",value:function select(a){return a&&this.query({select:a.replace(/\s/g,"")}),this}/** | ||
* Tells PostgREST in what order the result should be returned. | ||
* | ||
* @param {string} property The property name to order by. | ||
* @param {bool} ascending True for descending results, false by default. | ||
* @param {bool} nullsFirst True for nulls first, false by default. | ||
* @returns {Request} The API request object. | ||
*/},{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.query("order=".concat(a,".").concat(b?"asc":"desc",".").concat(c?"nullsfirst":"nullslast")),this}/** | ||
* Specify a range of items for PostgREST to return. If the second value is | ||
* not defined, the rest of the collection will be sent back. | ||
* | ||
* @param {number} from The first object to select. | ||
* @param {number|void} to The last object to select. | ||
* @returns {Request} The API request object. | ||
*/},{key:"range",value:function range(a,b){var c=0==b?0:b||"";return this.set("Range-Unit","items"),this.set("Range","".concat(a||0,"-").concat(c)),this}/** | ||
* Sets the header which signifies to PostgREST the response must be a single | ||
* object or 406 Not Acceptable. | ||
* | ||
* @returns {Request} The API request object. | ||
*/},{key:"single",value:function single(){return this.set("Accept","application/vnd.pgrst.object+json"),this.set("Prefer","return=representation"),this}/** | ||
* Sends the request and returns a promise. The super class uses the errback | ||
* pattern, but this function overrides that preference to use a promise. | ||
* | ||
* @returns {Promise} Resolves when the request has completed. | ||
*/},{key:"end",value:function end(){var a=this;return new Promise(function(c,d){// catch when .delete() is invoked without any filters | ||
if(["DELETE","PATCH"].includes(a.method)&&0==a._query.length){var e="DELETE"===a.method?".delete()":".update()";return c({body:null,status:400,statusCode:400,statusText:"".concat(e," cannot be invoked without any filters.")})}_get(_getPrototypeOf(b.prototype),"end",a).call(a,function(a,b){if(a)return d(a);var e=b.body,f=b.headers,g=b.status,h=b.statusCode,i=b.statusText,j=f["content-range"];Array.isArray(e)&&j&&contentRangeStructure.test(j)&&(e.fullLength=parseInt(contentRangeStructure.exec(j)[3],10));return c({body:e,status:g,statusCode:h,statusText:i})})})}/** | ||
* Makes the Request object then-able. Allows for usage with | ||
* `Promise.resolve` and async/await contexts. Just a proxy for `.then()` on | ||
* the promise returned from `.end()`. | ||
* | ||
* @param {function} Called when the request resolves. | ||
* @param {function} Called when the request errors. | ||
* @returns {Promise} Resolves when the resolution resolves. | ||
*/},{key:"then",value:function then(a,b){return this.end().then(a,b)}/** | ||
* Just a proxy for `.catch()` on the promise returned from `.end()`. | ||
* | ||
* @param {function} Called when the request errors. | ||
* @returns {Promise} Resolves when there is an error. | ||
*/},{key:"catch",value:function _catch(a){return this.end()["catch"](a)}}]),b}(_superagent.Request),filters=["eq","gt","lt","gte","lte","like","ilike","is","in","not"];filters.forEach(function(a){return Request.prototype[a]=function(b,c){return this.filter(b,a,c)}});var _default=Request;exports["default"]=_default; |
@@ -1,1 +0,133 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports._eq=_eq,exports._gt=_gt,exports._lt=_lt,exports._gte=_gte,exports._lte=_lte,exports._like=_like,exports._ilike=_ilike,exports._is=_is,exports._in=_in,exports._not=_not;function _eq(a,b){return"".concat(a,"=eq.").concat(b)}function _gt(a,b){return"".concat(a,"=gt.").concat(b)}function _lt(a,b){return"".concat(a,"=lt.").concat(b)}function _gte(a,b){return"".concat(a,"=gte.").concat(b)}function _lte(a,b){return"".concat(a,"=lte.").concat(b)}function _like(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=like.").concat(c)}function _ilike(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=ilike.").concat(c)}function _is(a,b){return"".concat(a,"=is.").concat(b)}function _in(a,b){return"".concat(a,"=in.(").concat(b.join(","),")")}function _not(a,b){return"".concat(a,"=neq.").concat(b)} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports._eq=_eq,exports._gt=_gt,exports._lt=_lt,exports._gte=_gte,exports._lte=_lte,exports._like=_like,exports._ilike=_ilike,exports._is=_is,exports._in=_in,exports._not=_not;/** @module Filters **/ /** | ||
* All exports are prefixed with an underscore to avoid collisions with reserved keywords (eg: "in") | ||
*/ /** | ||
* Finds all rows whose value on the stated columnName exactly matches the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name eq | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _eq('name', 'New Zealand') | ||
* //=> | ||
* 'name=eq.New Zealand' | ||
*/function _eq(a,b){return"".concat(a,"=eq.").concat(b)}/** | ||
* Finds all rows whose value on the stated columnName is greater than the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name gt | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _gt('id', 20) | ||
* //=> | ||
* 'id=gt.20' | ||
*/function _gt(a,b){return"".concat(a,"=gt.").concat(b)}/** | ||
* Finds all rows whose value on the stated columnName is less than the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name lt | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _lt('id', 20) | ||
* //=> | ||
* 'id=lt.20' | ||
*/function _lt(a,b){return"".concat(a,"=lt.").concat(b)}/** | ||
* Finds all rows whose value on the stated columnName is greater than or equal to the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name gte | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _gte('id', 20) | ||
* //=> | ||
* 'id=gte.20' | ||
*/function _gte(a,b){return"".concat(a,"=gte.").concat(b)}/** | ||
* Finds all rows whose value on the stated columnName is less than or equal to the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name lte | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _lte('id', 20) | ||
* //=> | ||
* 'id=lte.20' | ||
*/function _lte(a,b){return"".concat(a,"=lte.").concat(b)}/** | ||
* Finds all rows whose value in the stated columnName matches the supplied pattern (case sensitive). | ||
* @param {string} columnName Name of the database column | ||
* @param { string } stringPattern String pattern to compare to | ||
* @name like | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _like('name', '%United%') | ||
* //=> | ||
* 'name=like.*United*' | ||
* | ||
* @example | ||
* _like('name', '%United States%') | ||
* //=> | ||
* 'name=like.*United States*' | ||
*/function _like(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=like.").concat(c)}/** | ||
* Finds all rows whose value in the stated columnName matches the supplied pattern (case insensitive). | ||
* @param {string} columnName Name of the database column | ||
* @param { string } stringPattern String pattern to compare to | ||
* @name ilike | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _ilike('name', '%United%') | ||
* //=> | ||
* 'name=ilike.*United*' | ||
* | ||
* @example | ||
* _ilike('name', '%United states%') | ||
* //=> | ||
* 'name=ilike.*United states*' | ||
*/function _ilike(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=ilike.").concat(c)}/** | ||
* A check for exact equality (null, true, false), finds all rows whose value on the state columnName exactly match the specified filterValue. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name is | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _is('name', null) | ||
* //=> | ||
* 'name=is.null' | ||
*/function _is(a,b){return"".concat(a,"=is.").concat(b)}/** | ||
* Finds all rows whose value on the stated columnName is found on the specified filterArray. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name in | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _in('name', ['China', 'France']) | ||
* //=> | ||
* 'name=in.(China,France)' | ||
*/function _in(a,b){return"".concat(a,"=in.(").concat(b.join(","),")")}/** | ||
* Finds all rows whose value on the stated columnName is found on the specified filterArray. | ||
* @param {string} columnName Name of the database column | ||
* @param { string | integer | boolean } filterValue Value to match | ||
* @name not | ||
* @function | ||
* @returns {string} | ||
* | ||
* @example | ||
* _not('name', 'China') | ||
* //=> | ||
* 'name=neq.China' | ||
*/function _not(a,b){return"".concat(a,"=neq.").concat(b)} |
@@ -1,1 +0,5 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.objectToQueryString=objectToQueryString;function objectToQueryString(a){return Object.keys(a).map(function(b){return"".concat(b,"=").concat(a[b])}).join("&")} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.objectToQueryString=objectToQueryString;/** | ||
* @param {object} obj | ||
* @private | ||
* @returns {string} | ||
*/function objectToQueryString(a){return Object.keys(a).map(function(b){return"".concat(b,"=").concat(a[b])}).join("&")} |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "PostgREST JS client", | ||
@@ -48,3 +48,3 @@ "main": "./lib/index.js", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.19.1", | ||
"prettier": "^2.0.1", | ||
"rimraf": "^3.0.2" | ||
@@ -51,0 +51,0 @@ }, |
@@ -131,7 +131,10 @@ import Request from './Request' | ||
*/ | ||
insert(data, options = {}) { | ||
insert(data, options = { upsert: false }) { | ||
let method = 'POST' | ||
let request = this.request(method) | ||
let header = options.upsert | ||
? 'return=representation,resolution=merge-duplicates' | ||
: 'return=representation' | ||
request.set('Prefer', 'return=representation') | ||
request.set('Prefer', header) | ||
request.send(data) | ||
@@ -151,9 +154,8 @@ | ||
if(Array.isArray(data)) { | ||
if (Array.isArray(data)) { | ||
return { | ||
body:null, | ||
body: null, | ||
status: 400, | ||
statusCode: 400, | ||
statusText: 'Data type should be an object.' | ||
statusText: 'Data type should be an object.', | ||
} | ||
@@ -160,0 +162,0 @@ } |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances 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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
44336
822