eth-graph-query 1.1.1 → 1.1.2
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/README.md +2 -10
- package/dist/cjs/eth-graph-query.d.ts +1 -1
- package/dist/cjs/eth-graph-query.d.ts.map +1 -1
- package/dist/cjs/eth-graph-query.js +11 -30
- package/dist/cjs/eth-graph-query.js.map +1 -1
- package/dist/cjs/index.js +3 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/normal-query.js +12 -36
- package/dist/cjs/normal-query.js.map +1 -1
- package/dist/cjs/query-builder.d.ts +0 -1
- package/dist/cjs/query-builder.d.ts.map +1 -1
- package/dist/cjs/query-builder.js +30 -33
- package/dist/cjs/query-builder.js.map +1 -1
- package/dist/cjs/type.d.ts +19 -20
- package/dist/cjs/type.d.ts.map +1 -1
- package/dist/cjs/type.js +1 -4
- package/dist/cjs/type.js.map +1 -1
- package/dist/esm/eth-graph-query.d.ts +1 -1
- package/dist/esm/eth-graph-query.d.ts.map +1 -1
- package/dist/esm/eth-graph-query.js +8 -23
- package/dist/esm/eth-graph-query.js.map +1 -1
- package/dist/esm/normal-query.js +9 -26
- package/dist/esm/normal-query.js.map +1 -1
- package/dist/esm/query-builder.d.ts +0 -1
- package/dist/esm/query-builder.d.ts.map +1 -1
- package/dist/esm/query-builder.js +28 -27
- package/dist/esm/query-builder.js.map +1 -1
- package/dist/esm/type.d.ts +19 -20
- package/dist/esm/type.d.ts.map +1 -1
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/eth-graph-query.ts +1 -1
- package/src/query-builder.ts +19 -21
- package/src/type.ts +19 -39
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ const result1 = await query.mergeQuery([
|
|
|
56
56
|
'element21',
|
|
57
57
|
{
|
|
58
58
|
collection: 'collection3',
|
|
59
|
-
params: { elements: ['element31'], where: { id: { in: ['123'] }, element31: 'element31' }, first: 50 },
|
|
59
|
+
params: { elements: ['element31'], where: { id: { $in: ['123'] }, element31: 'element31' }, first: 50 },
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
62
|
where: { element21: '123', collection3: { element31: '123' } },
|
|
@@ -69,14 +69,6 @@ const result1 = await query.mergeQuery([
|
|
|
69
69
|
|
|
70
70
|
### API
|
|
71
71
|
|
|
72
|
-
Read the [API Docs](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/
|
|
72
|
+
Read the [API Docs](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/documents/api.md), you also read my [examples](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/examples)
|
|
73
73
|
|
|
74
74
|
---
|
|
75
|
-
|
|
76
|
-
### For develop
|
|
77
|
-
|
|
78
|
-
- To test package, you can run below command
|
|
79
|
-
|
|
80
|
-
```shell
|
|
81
|
-
npm run test
|
|
82
|
-
```
|
|
@@ -14,7 +14,7 @@ export declare class EthGraphQuery extends NormalQuery {
|
|
|
14
14
|
* @param {string} query A query string containing all data you want to fetch
|
|
15
15
|
* @returns The data respective with the query string
|
|
16
16
|
*/
|
|
17
|
-
_fetch
|
|
17
|
+
private _fetch;
|
|
18
18
|
/**
|
|
19
19
|
* Create a query to a particular collection, returns the data respective with the query data.
|
|
20
20
|
* @param {{ collection: string; params?: GraphParams }} data An data for create query, contains two elements:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-graph-query.d.ts","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,qBAAa,aAAc,SAAQ,WAAW;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAKxD;;;;OAIG;
|
|
1
|
+
{"version":3,"file":"eth-graph-query.d.ts","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,qBAAa,aAAc,SAAQ,WAAW;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAKxD;;;;OAIG;YACW,MAAM;IAIpB;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IAKzG;;;;;OAKG;IACG,UAAU,CAAC,CAAC,GAAG,GAAG,EACtB,IAAI,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC,EACzD,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,CAAC,CAAC;CAId"}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EthGraphQuery = void 0;
|
|
13
|
-
const normal_query_js_1 = require("./normal-query.js");
|
|
14
|
-
const query_builder_js_1 = require("./query-builder.js");
|
|
15
|
-
class EthGraphQuery extends normal_query_js_1.NormalQuery {
|
|
1
|
+
import { NormalQuery } from './normal-query.js';
|
|
2
|
+
import { QueryBuilder } from './query-builder.js';
|
|
3
|
+
export class EthGraphQuery extends NormalQuery {
|
|
16
4
|
/**
|
|
17
5
|
* The constructor for create a query instance.
|
|
18
6
|
* @param {string} rootUrl The url leading to the graph
|
|
@@ -27,10 +15,8 @@ class EthGraphQuery extends normal_query_js_1.NormalQuery {
|
|
|
27
15
|
* @param {string} query A query string containing all data you want to fetch
|
|
28
16
|
* @returns The data respective with the query string
|
|
29
17
|
*/
|
|
30
|
-
_fetch(query) {
|
|
31
|
-
return
|
|
32
|
-
return yield this.post('', { query: query });
|
|
33
|
-
});
|
|
18
|
+
async _fetch(query) {
|
|
19
|
+
return await this.post('', { query: query });
|
|
34
20
|
}
|
|
35
21
|
/**
|
|
36
22
|
* Create a query to a particular collection, returns the data respective with the query data.
|
|
@@ -40,11 +26,9 @@ class EthGraphQuery extends normal_query_js_1.NormalQuery {
|
|
|
40
26
|
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
41
27
|
* @returns The data respective with the query data
|
|
42
28
|
*/
|
|
43
|
-
query(data, metadata) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return yield this._fetch(query_builder_js_1.QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
47
|
-
});
|
|
29
|
+
async query(data, metadata) {
|
|
30
|
+
const sQuery = QueryBuilder.buildQuery({ collection: data.collection, params: data.params }, metadata);
|
|
31
|
+
return await this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
48
32
|
}
|
|
49
33
|
/**
|
|
50
34
|
* Create a query to many collections, returns the data respective with the query data.
|
|
@@ -52,12 +36,9 @@ class EthGraphQuery extends normal_query_js_1.NormalQuery {
|
|
|
52
36
|
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
53
37
|
* @returns The data respective with the query data
|
|
54
38
|
*/
|
|
55
|
-
mergeQuery(data, metadata) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return yield this._fetch(query_builder_js_1.QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
59
|
-
});
|
|
39
|
+
async mergeQuery(data, metadata) {
|
|
40
|
+
const sQuery = QueryBuilder.mergeQuery(data, metadata);
|
|
41
|
+
return await this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
60
42
|
}
|
|
61
43
|
}
|
|
62
|
-
exports.EthGraphQuery = EthGraphQuery;
|
|
63
44
|
//# sourceMappingURL=eth-graph-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-graph-query.js","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eth-graph-query.js","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,OAAO,aAAc,SAAQ,WAAW;IAG5C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,MAAM,CAAI,KAAa;QACnC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAuB,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,CAAU,IAAkD,EAAE,QAAmB;QAC1F,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;QACvG,OAAO,MAAM,IAAI,CAAC,MAAM,CAAI,YAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CACd,IAAyD,EACzD,QAAmB;QAEnB,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACvD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAI,YAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;CACF"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.EthGraphQuery = void 0;
|
|
18
|
-
var eth_graph_query_js_1 = require("./eth-graph-query.js");
|
|
19
|
-
Object.defineProperty(exports, "EthGraphQuery", { enumerable: true, get: function () { return eth_graph_query_js_1.EthGraphQuery; } });
|
|
20
|
-
__exportStar(require("./query-builder.js"), exports);
|
|
21
|
-
__exportStar(require("./type.js"), exports);
|
|
1
|
+
export { EthGraphQuery } from './eth-graph-query.js';
|
|
2
|
+
export * from './query-builder.js';
|
|
3
|
+
export * from './type.js';
|
|
22
4
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC"}
|
package/dist/cjs/normal-query.js
CHANGED
|
@@ -1,49 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.NormalQuery = exports.defaultHeader = void 0;
|
|
16
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
export const defaultHeader = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
19
4
|
function responseBody(res) {
|
|
20
5
|
return res.data;
|
|
21
6
|
}
|
|
22
|
-
class NormalQuery {
|
|
7
|
+
export class NormalQuery {
|
|
23
8
|
constructor(rootUrl, config) {
|
|
24
9
|
this.root = rootUrl;
|
|
25
|
-
this.config = config ?
|
|
10
|
+
this.config = config ? { ...config, ...{ headers: defaultHeader } } : { headers: defaultHeader };
|
|
26
11
|
}
|
|
27
|
-
get(url, config) {
|
|
28
|
-
return
|
|
29
|
-
return yield axios_1.default.get(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
30
|
-
});
|
|
12
|
+
async get(url, config) {
|
|
13
|
+
return await axios.get(`${this.root}${url}`, { ...config, ...this.config }).then(responseBody);
|
|
31
14
|
}
|
|
32
|
-
post(url, data, config) {
|
|
33
|
-
return
|
|
34
|
-
return yield axios_1.default.post(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
35
|
-
});
|
|
15
|
+
async post(url, data, config) {
|
|
16
|
+
return await axios.post(`${this.root}${url}`, data, { ...config, ...this.config }).then(responseBody);
|
|
36
17
|
}
|
|
37
|
-
put(url, data, config) {
|
|
38
|
-
return
|
|
39
|
-
return yield axios_1.default.put(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
40
|
-
});
|
|
18
|
+
async put(url, data, config) {
|
|
19
|
+
return await axios.put(`${this.root}${url}`, data, { ...config, ...this.config }).then(responseBody);
|
|
41
20
|
}
|
|
42
|
-
del(url, config) {
|
|
43
|
-
return
|
|
44
|
-
return yield axios_1.default.delete(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
45
|
-
});
|
|
21
|
+
async del(url, config) {
|
|
22
|
+
return await axios.delete(`${this.root}${url}`, { ...config, ...this.config }).then(responseBody);
|
|
46
23
|
}
|
|
47
24
|
}
|
|
48
|
-
exports.NormalQuery = NormalQuery;
|
|
49
25
|
//# sourceMappingURL=normal-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normal-query.js","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normal-query.js","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,KAA4C,MAAM,OAAO,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAEhG,SAAS,YAAY,CAAI,GAAqB;IAC5C,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC;AAED,MAAM,OAAO,WAAW;IAItB,YAAY,OAAe,EAAE,MAA2B;QACtD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACnG,CAAC;IAES,KAAK,CAAC,GAAG,CAAU,GAAW,EAAE,MAA2B;QACnE,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAI,YAAY,CAAC,CAAC;IACpG,CAAC;IAES,KAAK,CAAC,IAAI,CAAmB,GAAW,EAAE,IAAQ,EAAE,MAA2B;QACvF,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAI,YAAY,CAAC,CAAC;IAC3G,CAAC;IAES,KAAK,CAAC,GAAG,CAAmB,GAAW,EAAE,IAAQ,EAAE,MAA2B;QACtF,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAI,YAAY,CAAC,CAAC;IAC1G,CAAC;IAES,KAAK,CAAC,GAAG,CAAU,GAAW,EAAE,MAA2B;QACnE,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAI,YAAY,CAAC,CAAC;IACvG,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAc,SAAS,EAAgB,MAAM,WAAW,CAAC;AAEpG,qBAAa,YAAY;IACvB;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAgC/C;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAYjE;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM;IA8BhD;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAuClG;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAYzG;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAU,GAAG,MAAM;CAGjE"}
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.QueryBuilder = void 0;
|
|
4
|
-
const type_js_1 = require("./type.js");
|
|
5
|
-
class QueryBuilder {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
static isWhereOptions(data) {
|
|
8
|
-
const keys = Object.keys(data);
|
|
9
|
-
if (keys.length == 0)
|
|
10
|
-
return true;
|
|
11
|
-
for (const key of keys) {
|
|
12
|
-
if (!type_js_1.OptionKeys.includes(key))
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
1
|
+
import { OptionKeys } from './type.js';
|
|
2
|
+
export class QueryBuilder {
|
|
17
3
|
/**
|
|
18
4
|
* Create a query string from a query with json format.
|
|
19
5
|
* @param {QueryJson} query the json format query
|
|
@@ -27,20 +13,32 @@ class QueryBuilder {
|
|
|
27
13
|
const queryArray = query[key];
|
|
28
14
|
whereList.push(`${key}: [${queryArray.map((item) => `"${item}"`).join(', ')}]`);
|
|
29
15
|
}
|
|
30
|
-
else if (
|
|
31
|
-
const
|
|
16
|
+
else if (typeof query[key] == 'object') {
|
|
17
|
+
const normalJson = {};
|
|
18
|
+
const operatorJson = {};
|
|
32
19
|
const options = query[key];
|
|
33
20
|
for (const option in options) {
|
|
34
21
|
const value = options[option];
|
|
35
|
-
if (
|
|
36
|
-
|
|
22
|
+
if (option.length == 1)
|
|
23
|
+
normalJson[option] = value;
|
|
24
|
+
else {
|
|
25
|
+
if (option[0] == '$') {
|
|
26
|
+
const realOperator = option.slice(1);
|
|
27
|
+
if (OptionKeys.includes(realOperator))
|
|
28
|
+
operatorJson[`${key}_${realOperator}`] = value;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
normalJson[option] = value;
|
|
32
|
+
}
|
|
37
33
|
}
|
|
38
|
-
|
|
34
|
+
if (Object.keys(normalJson).length > 0)
|
|
35
|
+
whereList.push(`${key}: {${this.buildJsonQuery(normalJson)}}`);
|
|
36
|
+
if (Object.keys(operatorJson).length > 0)
|
|
37
|
+
whereList.push(this.buildJsonQuery(operatorJson));
|
|
39
38
|
}
|
|
40
|
-
else if (typeof query[key] == '
|
|
41
|
-
whereList.push(`${key}: {${this.buildJsonQuery(query[key])}}`);
|
|
42
|
-
else if (typeof query[key] == 'string')
|
|
39
|
+
else if (typeof query[key] == 'string') {
|
|
43
40
|
whereList.push(`${key}: "${query[key]}"`);
|
|
41
|
+
}
|
|
44
42
|
else
|
|
45
43
|
whereList.push(`${key}: ${query[key]}`);
|
|
46
44
|
}
|
|
@@ -119,39 +117,39 @@ class QueryBuilder {
|
|
|
119
117
|
const collection = data.collection;
|
|
120
118
|
const params = data.params;
|
|
121
119
|
const filters = [];
|
|
122
|
-
if (
|
|
120
|
+
if (params?.id != undefined)
|
|
123
121
|
filters.push(`id: ${params.id}`);
|
|
124
|
-
if (params
|
|
122
|
+
if (params?.orderBy)
|
|
125
123
|
filters.push(`orderBy: ${params.orderBy}`);
|
|
126
|
-
if (params
|
|
124
|
+
if (params?.orderDirection)
|
|
127
125
|
filters.push(`orderDirection: ${params.orderDirection}`);
|
|
128
|
-
if (
|
|
126
|
+
if (params?.first != undefined) {
|
|
129
127
|
if (params.first < 0)
|
|
130
128
|
params.first = 0;
|
|
131
129
|
else if (params.first > 1000)
|
|
132
130
|
params.first = 1000;
|
|
133
131
|
filters.push(`first: ${params.first}`);
|
|
134
132
|
}
|
|
135
|
-
if (
|
|
133
|
+
if (params?.skip != undefined) {
|
|
136
134
|
if (params.skip < 0)
|
|
137
135
|
params.skip = 0;
|
|
138
136
|
else if (params.skip > 5000)
|
|
139
137
|
params.skip = 5000;
|
|
140
138
|
filters.push(`skip: ${params.skip}`);
|
|
141
139
|
}
|
|
142
|
-
if (params
|
|
140
|
+
if (params?.where) {
|
|
143
141
|
const sWhere = this.buildJsonQuery(params.where);
|
|
144
142
|
if (sWhere.length > 0)
|
|
145
143
|
filters.push(`where: {${sWhere}}`);
|
|
146
144
|
}
|
|
147
|
-
if (params
|
|
145
|
+
if (params?.block) {
|
|
148
146
|
const sBlock = this.buildJsonQuery(params.block);
|
|
149
147
|
if (sBlock.length > 0)
|
|
150
148
|
filters.push(`block: {${sBlock}}`);
|
|
151
149
|
}
|
|
152
150
|
const filterString = filters.join(', ');
|
|
153
151
|
let elements = ['id'];
|
|
154
|
-
if (params
|
|
152
|
+
if (params?.elements)
|
|
155
153
|
if (params.elements.length > 0)
|
|
156
154
|
elements = this.buildElements(params.elements);
|
|
157
155
|
let finalQuery = '';
|
|
@@ -198,5 +196,4 @@ class QueryBuilder {
|
|
|
198
196
|
return `query ${queryName} {${query}}`;
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
|
-
exports.QueryBuilder = QueryBuilder;
|
|
202
199
|
//# sourceMappingURL=query-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"A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
2
2
|
export declare const OptionKeys: string[];
|
|
3
|
-
export declare type OptionsKey = 'contains' | 'contains_nocase' | 'ends_with' | 'end_with_nocase' | 'starts_with' | 'starts_with_nocase' | 'not_contains' | 'not_contains_nocase' | 'not_ends_with' | 'not_ends_with_nocase' | 'not_starts_with' | 'not_starts_with_nocase' | 'gt' | 'gte' | 'lt' | 'lte' | 'not' | 'in' | 'not_in';
|
|
4
3
|
export declare type TextWhereOptions = {
|
|
5
|
-
contains?: BaseQueryType;
|
|
6
|
-
contains_nocase?: BaseQueryType;
|
|
7
|
-
ends_with?: BaseQueryType;
|
|
8
|
-
end_with_nocase?: BaseQueryType;
|
|
9
|
-
starts_with?: BaseQueryType;
|
|
10
|
-
starts_with_nocase?: BaseQueryType;
|
|
11
|
-
not_contains?: BaseQueryType;
|
|
12
|
-
not_contains_nocase?: BaseQueryType;
|
|
13
|
-
not_ends_with?: BaseQueryType;
|
|
14
|
-
not_ends_with_nocase?: BaseQueryType;
|
|
15
|
-
not_starts_with?: BaseQueryType;
|
|
16
|
-
not_starts_with_nocase?: BaseQueryType;
|
|
4
|
+
$contains?: BaseQueryType;
|
|
5
|
+
$contains_nocase?: BaseQueryType;
|
|
6
|
+
$ends_with?: BaseQueryType;
|
|
7
|
+
$end_with_nocase?: BaseQueryType;
|
|
8
|
+
$starts_with?: BaseQueryType;
|
|
9
|
+
$starts_with_nocase?: BaseQueryType;
|
|
10
|
+
$not_contains?: BaseQueryType;
|
|
11
|
+
$not_contains_nocase?: BaseQueryType;
|
|
12
|
+
$not_ends_with?: BaseQueryType;
|
|
13
|
+
$not_ends_with_nocase?: BaseQueryType;
|
|
14
|
+
$not_starts_with?: BaseQueryType;
|
|
15
|
+
$not_starts_with_nocase?: BaseQueryType;
|
|
17
16
|
};
|
|
18
17
|
export declare type CommonWhereOptions = {
|
|
19
|
-
gt?: BaseQueryType;
|
|
20
|
-
gte?: BaseQueryType;
|
|
21
|
-
lt?: BaseQueryType;
|
|
22
|
-
lte?: BaseQueryType;
|
|
23
|
-
not?: BaseQueryType;
|
|
24
|
-
in?: BaseQueryType;
|
|
25
|
-
not_in?: BaseQueryType;
|
|
18
|
+
$gt?: BaseQueryType;
|
|
19
|
+
$gte?: BaseQueryType;
|
|
20
|
+
$lt?: BaseQueryType;
|
|
21
|
+
$lte?: BaseQueryType;
|
|
22
|
+
$not?: BaseQueryType;
|
|
23
|
+
$in?: BaseQueryType;
|
|
24
|
+
$not_in?: BaseQueryType;
|
|
26
25
|
};
|
|
27
26
|
export declare type WhereOptions = TextWhereOptions & CommonWhereOptions;
|
|
28
27
|
export declare type QueryJson = {
|
package/dist/cjs/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":"AAAA,aAAK,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3E,eAAO,MAAM,UAAU,UAoBtB,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":"AAAA,aAAK,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3E,eAAO,MAAM,UAAU,UAoBtB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,gBAAgB,CAAC,EAAE,aAAa,CAAC;IACjC,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,gBAAgB,CAAC,EAAE,aAAa,CAAC;IACjC,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,mBAAmB,CAAC,EAAE,aAAa,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,oBAAoB,CAAC,EAAE,aAAa,CAAC;IACrC,cAAc,CAAC,EAAE,aAAa,CAAC;IAC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AC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB"}
|
package/dist/cjs/type.js
CHANGED
package/dist/cjs/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,UAAU;IACV,iBAAiB;IACjB,WAAW;IACX,iBAAiB;IACjB,aAAa;IACb,oBAAoB;IACpB,cAAc;IACd,qBAAqB;IACrB,eAAe;IACf,sBAAsB;IACtB,iBAAiB;IACjB,wBAAwB;IACxB,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,QAAQ;CACT,CAAC"}
|
|
@@ -14,7 +14,7 @@ export declare class EthGraphQuery extends NormalQuery {
|
|
|
14
14
|
* @param {string} query A query string containing all data you want to fetch
|
|
15
15
|
* @returns The data respective with the query string
|
|
16
16
|
*/
|
|
17
|
-
_fetch
|
|
17
|
+
private _fetch;
|
|
18
18
|
/**
|
|
19
19
|
* Create a query to a particular collection, returns the data respective with the query data.
|
|
20
20
|
* @param {{ collection: string; params?: GraphParams }} data An data for create query, contains two elements:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-graph-query.d.ts","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,qBAAa,aAAc,SAAQ,WAAW;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAKxD;;;;OAIG;
|
|
1
|
+
{"version":3,"file":"eth-graph-query.d.ts","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,qBAAa,aAAc,SAAQ,WAAW;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAKxD;;;;OAIG;YACW,MAAM;IAIpB;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IAKzG;;;;;OAKG;IACG,UAAU,CAAC,CAAC,GAAG,GAAG,EACtB,IAAI,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC,EACzD,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,CAAC,CAAC;CAId"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { NormalQuery } from './normal-query.js';
|
|
11
2
|
import { QueryBuilder } from './query-builder.js';
|
|
12
3
|
export class EthGraphQuery extends NormalQuery {
|
|
@@ -24,10 +15,8 @@ export class EthGraphQuery extends NormalQuery {
|
|
|
24
15
|
* @param {string} query A query string containing all data you want to fetch
|
|
25
16
|
* @returns The data respective with the query string
|
|
26
17
|
*/
|
|
27
|
-
_fetch(query) {
|
|
28
|
-
return
|
|
29
|
-
return yield this.post('', { query: query });
|
|
30
|
-
});
|
|
18
|
+
async _fetch(query) {
|
|
19
|
+
return await this.post('', { query: query });
|
|
31
20
|
}
|
|
32
21
|
/**
|
|
33
22
|
* Create a query to a particular collection, returns the data respective with the query data.
|
|
@@ -37,11 +26,9 @@ export class EthGraphQuery extends NormalQuery {
|
|
|
37
26
|
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
38
27
|
* @returns The data respective with the query data
|
|
39
28
|
*/
|
|
40
|
-
query(data, metadata) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return yield this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
44
|
-
});
|
|
29
|
+
async query(data, metadata) {
|
|
30
|
+
const sQuery = QueryBuilder.buildQuery({ collection: data.collection, params: data.params }, metadata);
|
|
31
|
+
return await this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
45
32
|
}
|
|
46
33
|
/**
|
|
47
34
|
* Create a query to many collections, returns the data respective with the query data.
|
|
@@ -49,11 +36,9 @@ export class EthGraphQuery extends NormalQuery {
|
|
|
49
36
|
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
50
37
|
* @returns The data respective with the query data
|
|
51
38
|
*/
|
|
52
|
-
mergeQuery(data, metadata) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return yield this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
56
|
-
});
|
|
39
|
+
async mergeQuery(data, metadata) {
|
|
40
|
+
const sQuery = QueryBuilder.mergeQuery(data, metadata);
|
|
41
|
+
return await this._fetch(QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
57
42
|
}
|
|
58
43
|
}
|
|
59
44
|
//# sourceMappingURL=eth-graph-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-graph-query.js","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eth-graph-query.js","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,OAAO,aAAc,SAAQ,WAAW;IAG5C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,MAAM,CAAI,KAAa;QACnC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAuB,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,CAAU,IAAkD,EAAE,QAAmB;QAC1F,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;QACvG,OAAO,MAAM,IAAI,CAAC,MAAM,CAAI,YAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CACd,IAAyD,EACzD,QAAmB;QAEnB,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACvD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAI,YAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,CAAC;CACF"}
|
package/dist/esm/normal-query.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
2
|
import axios from 'axios';
|
|
12
3
|
export const defaultHeader = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
@@ -16,27 +7,19 @@ function responseBody(res) {
|
|
|
16
7
|
export class NormalQuery {
|
|
17
8
|
constructor(rootUrl, config) {
|
|
18
9
|
this.root = rootUrl;
|
|
19
|
-
this.config = config ?
|
|
10
|
+
this.config = config ? { ...config, ...{ headers: defaultHeader } } : { headers: defaultHeader };
|
|
20
11
|
}
|
|
21
|
-
get(url, config) {
|
|
22
|
-
return
|
|
23
|
-
return yield axios.get(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
24
|
-
});
|
|
12
|
+
async get(url, config) {
|
|
13
|
+
return await axios.get(`${this.root}${url}`, { ...config, ...this.config }).then(responseBody);
|
|
25
14
|
}
|
|
26
|
-
post(url, data, config) {
|
|
27
|
-
return
|
|
28
|
-
return yield axios.post(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
29
|
-
});
|
|
15
|
+
async post(url, data, config) {
|
|
16
|
+
return await axios.post(`${this.root}${url}`, data, { ...config, ...this.config }).then(responseBody);
|
|
30
17
|
}
|
|
31
|
-
put(url, data, config) {
|
|
32
|
-
return
|
|
33
|
-
return yield axios.put(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
34
|
-
});
|
|
18
|
+
async put(url, data, config) {
|
|
19
|
+
return await axios.put(`${this.root}${url}`, data, { ...config, ...this.config }).then(responseBody);
|
|
35
20
|
}
|
|
36
|
-
del(url, config) {
|
|
37
|
-
return
|
|
38
|
-
return yield axios.delete(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config)).then(responseBody);
|
|
39
|
-
});
|
|
21
|
+
async del(url, config) {
|
|
22
|
+
return await axios.delete(`${this.root}${url}`, { ...config, ...this.config }).then(responseBody);
|
|
40
23
|
}
|
|
41
24
|
}
|
|
42
25
|
//# sourceMappingURL=normal-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normal-query.js","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normal-query.js","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,KAA4C,MAAM,OAAO,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB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