UNPKG

@cloudbase/js-sdk

Version:
2 lines 4.95 kB
!function(){"use strict";var e={504:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(126),t)},126:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)},a=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,c)}s((r=r.apply(e,t||[])).next())})},c=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.registerMySQL=void 0;var s=n(630);function u(e,t,n){var o=this,i=e.request.fetch.bind(e.request),u=t||{},l=u.instance,f=void 0===l?n?void 0:"default":l,d=u.database,h=void 0===d?n?void 0:e.config.env:d,p=e.getEndPointWithKey("GATEWAY"),v=p.BASE_URL,y=p.PROTOCOL,b="".concat(y).concat(v),g=function(t,n){return a(o,void 0,void 0,function(){var o,a,s,u,l,d,p,v,y;return c(this,function(c){switch(c.label){case 0:return o={},n.headers instanceof Headers?n.headers.forEach(function(e,t){o[t]=e}):o=n.headers||{},[["X-Db-Instance",f],["Accept-Profile",h],["Content-Profile",h]].forEach(function(e){var t=e[0],n=e[1];o[t]||o[t.toLocaleLowerCase()]||!n||(o[t]=n)}),a=t.toString(),s=e.getEndPointWithKey("GATEWAY"),u=s.BASE_URL,l=s.PROTOCOL,(d="".concat(l).concat(u))!==b&&a.startsWith(b)&&(a=a.replace(b,d)),[4,i(r(r({url:a},n),{headers:r({"Content-Type":"application/json"},o),shouldThrowOnError:!1}))];case 1:p=c.sent(),v={},c.label=2;case 2:return c.trys.push([2,4,,5]),[4,p.data];case 3:return v=c.sent(),[3,5];case 4:if(!(y=c.sent()).message.includes("Unexpected end of JSON input"))throw y;return[3,5];case 5:return[2,{ok:(null==p?void 0:p.statusCode)>=200&&(null==p?void 0:p.statusCode)<300,status:(null==p?void 0:p.statusCode)||200,statusText:(null==p?void 0:p.statusMessage)||"OK",json:function(){return Promise.resolve(v||{})},text:function(){return Promise.resolve("string"==typeof v?v:JSON.stringify(v||{}))},headers:null==p?void 0:p.header}]}})})},O="".concat(y).concat(v,"/rdb/rest");return n?(0,s.generatePGClient)(e,{pgBaseUrl:O,fetch:g}):(0,s.generateMySQLClient)(e,{mysqlBaseUrl:O,fetch:g})}var l={name:"mysql",entity:{mysql:function(e){return u(this,e,!1)(e)}}},f={name:"rdb",entity:{rdb:function(e){return u(this,e,!0)(e)}}};try{cloudbase.registerComponent(l),cloudbase.registerComponent(f)}catch(e){}function d(e){try{e.registerComponent(l),e.registerComponent(f)}catch(e){console.warn(e)}}t.registerMySQL=d;try{window.registerMySQL=d}catch(e){}i(n(630),t)},630:function(e){e.exports=require("@cloudbase/wx-cloud-client-sdk")}},t={},n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(504);module.exports=n}(); //# sourceMappingURL=index.js.map