aipexbase-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -0
- package/dist/index.esm.js +1 -0
- package/package.json +25 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class t{constructor({baseUrl:t,apiKey:e}){this.baseUrl=t,this.apiKey=e,this.token=localStorage.getItem("baas_token")||null}setToken(t){this.token=t,t?localStorage.setItem("baas_token",t):localStorage.removeItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,i={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.token?{Authorization:`Bearer ${this.token}`}:{},...e.headers||{}};return(await fetch(s,{...e,headers:i})).json()}}function e(t){return{async login({user_name:e,phone:s,email:i,password:r}={}){const n=e||s||i;if(!n)throw new Error("必须提供 user_name、phone 或 email 之一");if(!r)throw new Error("必须提供 password");const a=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:n,password:r})});return a.success&&t.setToken(a.data),a},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"}))}}class s{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new i(this.client,this.table,"list")}page(){return new i(this.client,this.table,"page")}get(){return new i(this.client,this.table,"get")}insert(){return new r(this.client,this.table,"add")}update(){return new r(this.client,this.table,"update")}delete(){return new i(this.client,this.table,"delete")}}class i{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new i(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class r extends i{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function n(t){return{from:e=>new s(t,e)}}class a{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function h(t){return{call:e=>new a(t,e)}}exports.createClient=function(s){const i=new t(s);return{setToken:t=>i.setToken(t),auth:e(i),db:n(i),api:h(i)}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class t{constructor({baseUrl:t,apiKey:e}){this.baseUrl=t,this.apiKey=e,this.token=localStorage.getItem("baas_token")||null}setToken(t){this.token=t,t?localStorage.setItem("baas_token",t):localStorage.removeItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,i={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.token?{Authorization:`Bearer ${this.token}`}:{},...e.headers||{}};return(await fetch(s,{...e,headers:i})).json()}}function e(t){return{async login({user_name:e,phone:s,email:i,password:r}={}){const n=e||s||i;if(!n)throw new Error("必须提供 user_name、phone 或 email 之一");if(!r)throw new Error("必须提供 password");const a=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:n,password:r})});return a.success&&t.setToken(a.data),a},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"}))}}class s{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new i(this.client,this.table,"list")}page(){return new i(this.client,this.table,"page")}get(){return new i(this.client,this.table,"get")}insert(){return new r(this.client,this.table,"add")}update(){return new r(this.client,this.table,"update")}delete(){return new i(this.client,this.table,"delete")}}class i{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new i(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class r extends i{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function n(t){return{from:e=>new s(t,e)}}class a{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function h(t){return{call:e=>new a(t,e)}}function o(s){const i=new t(s);return{setToken:t=>i.setToken(t),auth:e(i),db:n(i),api:h(i)}}export{o as createClient};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aipexbase-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
+
"build": "rollup -c"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
20
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
21
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
22
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
23
|
+
"rollup": "^4.52.2"
|
|
24
|
+
}
|
|
25
|
+
}
|