eth-graph-query 2.0.1 → 2.0.15
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 +1 -1
- package/dist/.vite/manifest.json +8 -0
- package/dist/{cjs/normal-query.d.ts → api-query.d.ts} +1 -2
- package/dist/{cjs/eth-graph-query.d.ts → eth-graph-query.d.ts} +3 -4
- package/dist/index.cjs +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1697 -0
- package/dist/{esm/query-builder.d.ts → query-builder.d.ts} +1 -2
- package/dist/{cjs/type.d.ts → type.d.ts} +10 -11
- package/package.json +19 -29
- package/dist/cjs/eth-graph-query.d.ts.map +0 -1
- package/dist/cjs/eth-graph-query.js +0 -69
- package/dist/cjs/eth-graph-query.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/normal-query.d.ts.map +0 -1
- package/dist/cjs/normal-query.js +0 -65
- package/dist/cjs/normal-query.js.map +0 -1
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/query-builder.d.ts +0 -52
- package/dist/cjs/query-builder.d.ts.map +0 -1
- package/dist/cjs/query-builder.js +0 -238
- package/dist/cjs/query-builder.js.map +0 -1
- package/dist/cjs/type.d.ts.map +0 -1
- package/dist/cjs/type.js +0 -25
- package/dist/cjs/type.js.map +0 -1
- package/dist/esm/eth-graph-query.d.ts +0 -35
- package/dist/esm/eth-graph-query.d.ts.map +0 -1
- package/dist/esm/eth-graph-query.js +0 -65
- package/dist/esm/eth-graph-query.js.map +0 -1
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/normal-query.d.ts +0 -15
- package/dist/esm/normal-query.d.ts.map +0 -1
- package/dist/esm/normal-query.js +0 -58
- package/dist/esm/normal-query.js.map +0 -1
- package/dist/esm/package.json +0 -3
- package/dist/esm/query-builder.d.ts.map +0 -1
- package/dist/esm/query-builder.js +0 -234
- package/dist/esm/query-builder.js.map +0 -1
- package/dist/esm/type.d.ts +0 -67
- package/dist/esm/type.d.ts.map +0 -1
- package/dist/esm/type.js +0 -22
- package/dist/esm/type.js.map +0 -1
- package/dist/tsconfig.prod.cjs.tsbuildinfo +0 -1
- package/dist/tsconfig.prod.esm.tsbuildinfo +0 -1
- package/src/eth-graph-query.ts +0 -61
- package/src/index.ts +0 -3
- package/src/normal-query.ts +0 -46
- package/src/query-builder.ts +0 -216
- package/src/type.ts +0 -89
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementType, GraphObject, InlineFragmentType, Metadata, QueryJson } from './type
|
|
1
|
+
import { ElementType, GraphObject, InlineFragmentType, Metadata, QueryJson } from './type';
|
|
2
2
|
export declare class QueryBuilder {
|
|
3
3
|
/**
|
|
4
4
|
* Create a query string from a query with json format.
|
|
@@ -49,4 +49,3 @@ export declare class QueryBuilder {
|
|
|
49
49
|
*/
|
|
50
50
|
static makeFullQuery(query: string, queryName?: string): string;
|
|
51
51
|
}
|
|
52
|
-
//# sourceMappingURL=query-builder.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
type BaseQueryType = Array<string | number | boolean> | string | number | boolean | null | undefined;
|
|
2
2
|
export declare const OptionKeys: string[];
|
|
3
|
-
export
|
|
3
|
+
export type TextWhereOptions = {
|
|
4
4
|
$contains?: BaseQueryType;
|
|
5
5
|
$contains_nocase?: BaseQueryType;
|
|
6
6
|
$ends_with?: BaseQueryType;
|
|
@@ -14,7 +14,7 @@ export declare type TextWhereOptions = {
|
|
|
14
14
|
$not_starts_with?: BaseQueryType;
|
|
15
15
|
$not_starts_with_nocase?: BaseQueryType;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type CommonWhereOptions = {
|
|
18
18
|
$gt?: BaseQueryType;
|
|
19
19
|
$gte?: BaseQueryType;
|
|
20
20
|
$lt?: BaseQueryType;
|
|
@@ -23,21 +23,21 @@ export declare type CommonWhereOptions = {
|
|
|
23
23
|
$in?: BaseQueryType;
|
|
24
24
|
$not_in?: BaseQueryType;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
27
|
-
export
|
|
26
|
+
export type WhereOptions = TextWhereOptions & CommonWhereOptions;
|
|
27
|
+
export type QueryJson = {
|
|
28
28
|
[key: string]: QueryJson | WhereOptions | BaseQueryType;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type BlockQuery = {
|
|
31
31
|
hash?: string;
|
|
32
32
|
number?: number;
|
|
33
33
|
number_gte?: number;
|
|
34
34
|
};
|
|
35
|
-
export
|
|
35
|
+
export type Metadata = {
|
|
36
36
|
elements?: Array<'deployment' | 'hasIndexingErrors' | 'hash' | 'number' | 'timestamp'>;
|
|
37
37
|
blockQuery?: BlockQuery;
|
|
38
38
|
};
|
|
39
|
-
export
|
|
40
|
-
export
|
|
39
|
+
export type ElementType = string | GraphObject;
|
|
40
|
+
export type InlineFragmentType = {
|
|
41
41
|
collection: string;
|
|
42
42
|
params?: Pick<GraphParams, 'elements'>;
|
|
43
43
|
};
|
|
@@ -57,11 +57,10 @@ export interface GraphObject {
|
|
|
57
57
|
collection: string;
|
|
58
58
|
params?: GraphParams;
|
|
59
59
|
}
|
|
60
|
-
export
|
|
60
|
+
export type ErrorObject = {
|
|
61
61
|
errors: Array<{
|
|
62
62
|
message: string;
|
|
63
63
|
locations: Array<unknown>;
|
|
64
64
|
}>;
|
|
65
65
|
};
|
|
66
66
|
export {};
|
|
67
|
-
//# sourceMappingURL=type.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eth-graph-query",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "simple package for
|
|
3
|
+
"version": "2.0.15",
|
|
4
|
+
"description": "simple package for creating query to the GraphQL in ethereum",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/
|
|
7
|
-
"module": "dist/
|
|
8
|
-
"
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/esm/index.js",
|
|
11
|
-
"require": "./dist/cjs/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
14
9
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"src",
|
|
17
|
-
"package.json",
|
|
18
|
-
"README.md"
|
|
10
|
+
"dist"
|
|
19
11
|
],
|
|
20
12
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
13
|
+
"build": "npm run clear && tsc && vite build",
|
|
14
|
+
"preview": "vite preview",
|
|
15
|
+
"clear": "rm -rf dist",
|
|
16
|
+
"test": "vitest run",
|
|
23
17
|
"prepare": "npm run build && husky install",
|
|
24
|
-
"test:browser": "npx vitest run --config=./vitest.config.browser.ts --browser.name=chrome --browser.headless",
|
|
25
|
-
"test:node": "npx vitest run",
|
|
26
|
-
"test": "npm run test:node && npm run test:browser",
|
|
27
18
|
"eslint": "eslint . --ext .ts",
|
|
28
|
-
"prepublishOnly": "npm run
|
|
29
|
-
"tsc": "./scripts/ts-compile.sh",
|
|
30
|
-
"example": "node --loader ts-node/esm"
|
|
19
|
+
"prepublishOnly": "npm run clear && npm run build && npm run test"
|
|
31
20
|
},
|
|
32
21
|
"repository": {
|
|
33
22
|
"type": "git",
|
|
@@ -49,10 +38,9 @@
|
|
|
49
38
|
"devDependencies": {
|
|
50
39
|
"@commitlint/cli": "^17.6.5",
|
|
51
40
|
"@commitlint/config-conventional": "^17.6.5",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"@types/node": "^20.12.2",
|
|
52
43
|
"@typescript-eslint/eslint-plugin": "5.59.6",
|
|
53
|
-
"@vitest/browser": "1.4.0",
|
|
54
|
-
"@vitest/coverage-v8": "1.4.0",
|
|
55
|
-
"@vitest/ui": "1.4.0",
|
|
56
44
|
"eslint": "^8.40.0",
|
|
57
45
|
"eslint-config-prettier": "^8.8.0",
|
|
58
46
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
@@ -60,11 +48,13 @@
|
|
|
60
48
|
"eslint-plugin-prettier": "^4.2.1",
|
|
61
49
|
"husky": "^8.0.3",
|
|
62
50
|
"lint-staged": "^13.2.2",
|
|
51
|
+
"path": "^0.12.7",
|
|
63
52
|
"prettier": "^2.8.8",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
53
|
+
"rollup-plugin-typescript-paths": "^1.5.0",
|
|
54
|
+
"tslib": "^2.6.2",
|
|
55
|
+
"typescript": "^5.2.2",
|
|
56
|
+
"vite": "^5.2.0",
|
|
57
|
+
"vitest": "^1.4.0"
|
|
68
58
|
},
|
|
69
59
|
"contributors": [
|
|
70
60
|
{
|
|
@@ -1 +0,0 @@
|
|
|
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;AAE/D,qBAAa,aAAc,SAAQ,WAAW;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAKxD;;;;OAIG;IACG,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IASpD;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IASxE;;;;;OAKG;IACG,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;CAIxF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
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 {
|
|
16
|
-
/**
|
|
17
|
-
* The constructor for create a query instance.
|
|
18
|
-
* @param {string} rootUrl The url leading to the graph
|
|
19
|
-
* @param {AxiosRequestConfig | undefined} config Config for base axios
|
|
20
|
-
*/
|
|
21
|
-
constructor(rootUrl, config) {
|
|
22
|
-
super(rootUrl, config);
|
|
23
|
-
this.queryName = 'query';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Given query string, returns the data respective with it.
|
|
27
|
-
* @param {string} query A query string containing all data you want to fetch
|
|
28
|
-
* @returns The data respective with the query string
|
|
29
|
-
*/
|
|
30
|
-
stringQuery(data) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const result = yield this.post('', { query: data });
|
|
33
|
-
if (result.errors) {
|
|
34
|
-
const _error = result;
|
|
35
|
-
throw new Error(_error.errors[0].message);
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Create a query to a particular collection, returns the data respective with the query data.
|
|
42
|
-
* @param {GraphObject} data An data for create query, contains two elements:
|
|
43
|
-
* 1. collection: string - collection name
|
|
44
|
-
* 2. params: GraphParams | undefined - If it is defined, it create a query to the collection
|
|
45
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
46
|
-
* @returns The data respective with the query data
|
|
47
|
-
*/
|
|
48
|
-
query(data, metadata) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const _data = data;
|
|
51
|
-
const sQuery = query_builder_js_1.QueryBuilder.buildQuery({ collection: _data.collection, params: _data.params }, metadata);
|
|
52
|
-
return yield this.stringQuery(query_builder_js_1.QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Create a query to many collections, returns the data respective with the query data.
|
|
57
|
-
* @param {Array<GraphObject>} data An array contain data to query to many collections
|
|
58
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
59
|
-
* @returns The data respective with the query data
|
|
60
|
-
*/
|
|
61
|
-
multipleQuery(data, metadata) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const sQuery = query_builder_js_1.QueryBuilder.buildMultipleQuery(data, metadata);
|
|
64
|
-
return yield this.stringQuery(query_builder_js_1.QueryBuilder.makeFullQuery(sQuery, this.queryName));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.EthGraphQuery = EthGraphQuery;
|
|
69
|
-
//# sourceMappingURL=eth-graph-query.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eth-graph-query.js","sourceRoot":"","sources":["../../src/eth-graph-query.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,uDAAgD;AAChD,yDAAkD;AAGlD,MAAa,aAAc,SAAQ,6BAAW;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;IACG,WAAW,CAAU,IAAY;;YACrC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAqC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACxF,IAAK,MAAsB,CAAC,MAAM,EAAE;gBAClC,MAAM,MAAM,GAAG,MAAqB,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;aAC3C;YACD,OAAO,MAAW,CAAC;QACrB,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,KAAK,CAAU,IAAiB,EAAE,QAAmB;;YACzD,MAAM,KAAK,GAAG,IAAmB,CAAC;YAClC,MAAM,MAAM,GAAG,+BAAY,CAAC,UAAU,CACpC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EACtD,QAAQ,CACT,CAAC;YACF,OAAO,MAAM,IAAI,CAAC,WAAW,CAAI,+BAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;IAED;;;;;OAKG;IACG,aAAa,CAAU,IAAwB,EAAE,QAAmB;;YACxE,MAAM,MAAM,GAAG,+BAAY,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC/D,OAAO,MAAM,IAAI,CAAC,WAAW,CAAI,+BAAY,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CACF;AAtDD,sCAsDC"}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","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/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAqD;AAA5C,mHAAA,aAAa,OAAA;AACtB,qDAAmC;AACnC,4CAA0B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normal-query.d.ts","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":"AACA,OAAc,EAAE,kBAAkB,EAAiB,MAAM,OAAO,CAAC;AAEjE,eAAO,MAAM,aAAa;;;CAAqE,CAAC;AAMhG,qBAAa,WAAW;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;cASxC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;cAMrD,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB;cAMzE,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB;cAMxE,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB;CAKtE"}
|
package/dist/cjs/normal-query.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
exports.defaultHeader = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
19
|
-
function responseBody(res) {
|
|
20
|
-
return res.data;
|
|
21
|
-
}
|
|
22
|
-
class NormalQuery {
|
|
23
|
-
constructor(rootUrl, config) {
|
|
24
|
-
var _a;
|
|
25
|
-
this.root = rootUrl;
|
|
26
|
-
if (config) {
|
|
27
|
-
this.config = config;
|
|
28
|
-
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.headers))
|
|
29
|
-
this.config.headers = {};
|
|
30
|
-
this.config['headers'] = Object.assign(Object.assign({}, this.config['headers']), exports.defaultHeader);
|
|
31
|
-
}
|
|
32
|
-
else
|
|
33
|
-
this.config = { headers: exports.defaultHeader };
|
|
34
|
-
}
|
|
35
|
-
get(url, config) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return yield axios_1.default
|
|
38
|
-
.get(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config))
|
|
39
|
-
.then(responseBody);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
post(url, data, config) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
return yield axios_1.default
|
|
45
|
-
.post(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config))
|
|
46
|
-
.then(responseBody);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
put(url, data, config) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return yield axios_1.default
|
|
52
|
-
.put(`${this.root}${url}`, data, Object.assign(Object.assign({}, config), this.config))
|
|
53
|
-
.then(responseBody);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
del(url, config) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
return yield axios_1.default
|
|
59
|
-
.delete(`${this.root}${url}`, Object.assign(Object.assign({}, config), this.config))
|
|
60
|
-
.then(responseBody);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.NormalQuery = NormalQuery;
|
|
65
|
-
//# sourceMappingURL=normal-query.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normal-query.js","sourceRoot":"","sources":["../../src/normal-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,kDAAiE;AAEpD,QAAA,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,MAAa,WAAW;IAItB,YAAY,OAAe,EAAE,MAA2B;;QACtD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,CAAA,MAAA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C;KAAA;CACF;AApCD,kCAoCC"}
|
package/dist/cjs/package.json
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ElementType, GraphObject, InlineFragmentType, Metadata, QueryJson } from './type.js';
|
|
2
|
-
export declare class QueryBuilder {
|
|
3
|
-
/**
|
|
4
|
-
* Create a query string from a query with json format.
|
|
5
|
-
* @param {QueryJson} query the json format query
|
|
6
|
-
* @returns a query string respective with the json format query
|
|
7
|
-
*/
|
|
8
|
-
static buildJsonQuery(query: QueryJson): string;
|
|
9
|
-
/**
|
|
10
|
-
* Given a json format array as element input, returns the string array represent elements you want to query in the graph.
|
|
11
|
-
* @param {Array<ElementType>} elements A array with {@link ElementType} elements, each element in the array represent a element in the graph you want to query
|
|
12
|
-
* @returns {Array<string>} The string array represent the input array
|
|
13
|
-
*/
|
|
14
|
-
static buildElements(elements: Array<ElementType>): Array<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Given a instance of {@link Metadata}, returns the string represent the metadata you want to query
|
|
17
|
-
* @param {Metadata} metadata The instance represent all metadata you want to query
|
|
18
|
-
* @returns The string represent the metadata you want to query
|
|
19
|
-
*/
|
|
20
|
-
static buildMetadata(metadata: Metadata): string;
|
|
21
|
-
private static _buildInlineFragment;
|
|
22
|
-
/**
|
|
23
|
-
* Given a instance of Array<{@link InlineFragmentType}>, returns the string represent the inline fragments you want to query
|
|
24
|
-
* @param {Array<InlineFragmentType>} fragments The instance represent the inline fragments you want to query
|
|
25
|
-
* @returns The string represent the inline fragments you want to query
|
|
26
|
-
*/
|
|
27
|
-
static buildInlineFragments(fragments: Array<InlineFragmentType>): string;
|
|
28
|
-
/**
|
|
29
|
-
* Given json data, returns the string query. This function only can create a string query for a particular collection.
|
|
30
|
-
* @param {GraphObject} data An data for create query, contains two elements:
|
|
31
|
-
* 1. collection: string - collection name
|
|
32
|
-
* 2. params: GraphParams | undefined - If it is defined, it create a query to the collection
|
|
33
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
34
|
-
* @returns The string query
|
|
35
|
-
*/
|
|
36
|
-
static buildQuery(data: GraphObject, metadata?: Metadata): string;
|
|
37
|
-
/**
|
|
38
|
-
* Given a array contain many json data, return a query string represent a query to all collections that is in a array.
|
|
39
|
-
* @param {Array<GraphObject>} data An array contain data to query to many collections
|
|
40
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
41
|
-
* @returns The query string
|
|
42
|
-
*/
|
|
43
|
-
static buildMultipleQuery(data: Array<GraphObject>, metadata?: Metadata): string;
|
|
44
|
-
/**
|
|
45
|
-
* Create complete query string, you can use directly this query to query to the graph
|
|
46
|
-
* @param {string} query The query string
|
|
47
|
-
* @param {string} queryName The query name(default query)
|
|
48
|
-
* @returns The complete query string
|
|
49
|
-
*/
|
|
50
|
-
static makeFullQuery(query: string, queryName?: string): string;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=query-builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EAEX,kBAAkB,EAClB,QAAQ,EAER,SAAS,EAEV,MAAM,WAAW,CAAC;AAEnB,qBAAa,YAAY;IACvB;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAmC/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;IA+BhD,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAMnC;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,KAAK,CAAC,kBAAkB,CAAC,GAAG,MAAM;IAQzE;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAuDjE;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM;IAahF;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAU,GAAG,MAAM;CAGjE"}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryBuilder = void 0;
|
|
4
|
-
const type_js_1 = require("./type.js");
|
|
5
|
-
class QueryBuilder {
|
|
6
|
-
/**
|
|
7
|
-
* Create a query string from a query with json format.
|
|
8
|
-
* @param {QueryJson} query the json format query
|
|
9
|
-
* @returns a query string respective with the json format query
|
|
10
|
-
*/
|
|
11
|
-
static buildJsonQuery(query) {
|
|
12
|
-
const whereList = [];
|
|
13
|
-
for (const key in query) {
|
|
14
|
-
if (query[key] !== undefined) {
|
|
15
|
-
if (query[key] === null)
|
|
16
|
-
whereList.push(`${key}: null`);
|
|
17
|
-
if (Array.isArray(query[key])) {
|
|
18
|
-
const queryArray = query[key];
|
|
19
|
-
whereList.push(`${key}: [${queryArray.map((item) => `"${item}"`).join(', ')}]`);
|
|
20
|
-
}
|
|
21
|
-
else if (typeof query[key] == 'string') {
|
|
22
|
-
whereList.push(`${key}: "${query[key]}"`);
|
|
23
|
-
}
|
|
24
|
-
else if (typeof query[key] == 'object') {
|
|
25
|
-
const normalJson = {};
|
|
26
|
-
const operatorJson = {};
|
|
27
|
-
const options = query[key];
|
|
28
|
-
for (const option in options) {
|
|
29
|
-
const value = options[option];
|
|
30
|
-
if (option.length == 1)
|
|
31
|
-
normalJson[option] = value;
|
|
32
|
-
else {
|
|
33
|
-
if (option[0] == '$') {
|
|
34
|
-
const realOperator = option.slice(1);
|
|
35
|
-
if (type_js_1.OptionKeys.includes(realOperator))
|
|
36
|
-
operatorJson[`${key}_${realOperator}`] = value;
|
|
37
|
-
}
|
|
38
|
-
else
|
|
39
|
-
normalJson[option] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (Object.keys(normalJson).length > 0)
|
|
43
|
-
whereList.push(`${key}: {${this.buildJsonQuery(normalJson)}}`);
|
|
44
|
-
if (Object.keys(operatorJson).length > 0)
|
|
45
|
-
whereList.push(this.buildJsonQuery(operatorJson));
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
whereList.push(`${key}: ${query[key]}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return whereList.join(', ');
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Given a json format array as element input, returns the string array represent elements you want to query in the graph.
|
|
55
|
-
* @param {Array<ElementType>} elements A array with {@link ElementType} elements, each element in the array represent a element in the graph you want to query
|
|
56
|
-
* @returns {Array<string>} The string array represent the input array
|
|
57
|
-
*/
|
|
58
|
-
static buildElements(elements) {
|
|
59
|
-
const elementList = [];
|
|
60
|
-
for (const element of elements) {
|
|
61
|
-
if (typeof element == 'string')
|
|
62
|
-
elementList.push(element);
|
|
63
|
-
else {
|
|
64
|
-
const object = element;
|
|
65
|
-
elementList.push(this.buildQuery({ collection: object.collection, params: object.params }));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return elementList;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Given a instance of {@link Metadata}, returns the string represent the metadata you want to query
|
|
72
|
-
* @param {Metadata} metadata The instance represent all metadata you want to query
|
|
73
|
-
* @returns The string represent the metadata you want to query
|
|
74
|
-
*/
|
|
75
|
-
static buildMetadata(metadata) {
|
|
76
|
-
let result = '';
|
|
77
|
-
const blockQuery = [];
|
|
78
|
-
if (metadata.blockQuery) {
|
|
79
|
-
if (metadata.blockQuery.hash)
|
|
80
|
-
blockQuery.push(`hash: "${metadata.blockQuery.hash}"`);
|
|
81
|
-
if (metadata.blockQuery.number)
|
|
82
|
-
blockQuery.push(`number: ${metadata.blockQuery.number}`);
|
|
83
|
-
if (metadata.blockQuery.number_gte)
|
|
84
|
-
blockQuery.push(`number_gte: ${metadata.blockQuery.number_gte}`);
|
|
85
|
-
}
|
|
86
|
-
const sBlockQuery = blockQuery.join(', ');
|
|
87
|
-
if (sBlockQuery.length > 0)
|
|
88
|
-
result += `(block: {${sBlockQuery}})`;
|
|
89
|
-
const filters = [];
|
|
90
|
-
const blockFilters = [];
|
|
91
|
-
if (metadata.elements) {
|
|
92
|
-
for (const filter of metadata.elements) {
|
|
93
|
-
if (filter == 'deployment' || filter == 'hasIndexingErrors') {
|
|
94
|
-
const sFilter = filter.toString();
|
|
95
|
-
if (!filters.includes(sFilter))
|
|
96
|
-
filters.push(sFilter);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const sFilter = filter.toString();
|
|
100
|
-
if (!blockFilters.includes(sFilter))
|
|
101
|
-
blockFilters.push(sFilter);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const blockFilterQuery = blockFilters.join(' ');
|
|
105
|
-
if (blockFilterQuery.length > 0)
|
|
106
|
-
filters.push(`block{${blockFilterQuery}}`);
|
|
107
|
-
const sFiltersQuery = filters.join(' ');
|
|
108
|
-
if (sFiltersQuery.length > 0)
|
|
109
|
-
result += `{${sFiltersQuery}}`;
|
|
110
|
-
}
|
|
111
|
-
return result.length > 0 ? `_meta${result}` : '';
|
|
112
|
-
}
|
|
113
|
-
static _buildInlineFragment(fragment) {
|
|
114
|
-
var _a;
|
|
115
|
-
let elements = ['id'];
|
|
116
|
-
if ((_a = fragment.params) === null || _a === void 0 ? void 0 : _a.elements)
|
|
117
|
-
elements = this.buildElements(fragment.params.elements);
|
|
118
|
-
return `... on ${fragment.collection}{${elements.join(' ')}}`;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Given a instance of Array<{@link InlineFragmentType}>, returns the string represent the inline fragments you want to query
|
|
122
|
-
* @param {Array<InlineFragmentType>} fragments The instance represent the inline fragments you want to query
|
|
123
|
-
* @returns The string represent the inline fragments you want to query
|
|
124
|
-
*/
|
|
125
|
-
static buildInlineFragments(fragments) {
|
|
126
|
-
const result = [];
|
|
127
|
-
for (const fragment of fragments) {
|
|
128
|
-
result.push(this._buildInlineFragment(fragment));
|
|
129
|
-
}
|
|
130
|
-
return result.join(' ');
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Given json data, returns the string query. This function only can create a string query for a particular collection.
|
|
134
|
-
* @param {GraphObject} data An data for create query, contains two elements:
|
|
135
|
-
* 1. collection: string - collection name
|
|
136
|
-
* 2. params: GraphParams | undefined - If it is defined, it create a query to the collection
|
|
137
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
138
|
-
* @returns The string query
|
|
139
|
-
*/
|
|
140
|
-
static buildQuery(data, metadata) {
|
|
141
|
-
const collection = data.collection;
|
|
142
|
-
const params = data.params;
|
|
143
|
-
const filters = [];
|
|
144
|
-
// build id
|
|
145
|
-
if ((params === null || params === void 0 ? void 0 : params.id) != undefined)
|
|
146
|
-
filters.push(`id: ${params.id}`);
|
|
147
|
-
// build order
|
|
148
|
-
if (params === null || params === void 0 ? void 0 : params.orderBy)
|
|
149
|
-
filters.push(`orderBy: ${params.orderBy}`);
|
|
150
|
-
// build order direction
|
|
151
|
-
if (params === null || params === void 0 ? void 0 : params.orderDirection)
|
|
152
|
-
filters.push(`orderDirection: ${params.orderDirection}`);
|
|
153
|
-
//build first
|
|
154
|
-
if ((params === null || params === void 0 ? void 0 : params.first) != undefined) {
|
|
155
|
-
if (params.first < 0)
|
|
156
|
-
params.first = 0;
|
|
157
|
-
else if (params.first > 1000)
|
|
158
|
-
params.first = 1000;
|
|
159
|
-
filters.push(`first: ${params.first}`);
|
|
160
|
-
}
|
|
161
|
-
// build skip
|
|
162
|
-
if ((params === null || params === void 0 ? void 0 : params.skip) != undefined) {
|
|
163
|
-
if (params.skip < 0)
|
|
164
|
-
params.skip = 0;
|
|
165
|
-
else if (params.skip > 5000)
|
|
166
|
-
params.skip = 5000;
|
|
167
|
-
filters.push(`skip: ${params.skip}`);
|
|
168
|
-
}
|
|
169
|
-
// build where
|
|
170
|
-
if (params === null || params === void 0 ? void 0 : params.where) {
|
|
171
|
-
const sWhere = this.buildJsonQuery(params.where);
|
|
172
|
-
if (sWhere.length > 0)
|
|
173
|
-
filters.push(`where: {${sWhere}}`);
|
|
174
|
-
}
|
|
175
|
-
// build block
|
|
176
|
-
if (params === null || params === void 0 ? void 0 : params.block) {
|
|
177
|
-
const sBlock = this.buildJsonQuery(params.block);
|
|
178
|
-
if (sBlock.length > 0)
|
|
179
|
-
filters.push(`block: {${sBlock}}`);
|
|
180
|
-
}
|
|
181
|
-
const filterString = filters.join(', ');
|
|
182
|
-
// build elements
|
|
183
|
-
let elements = ['id'];
|
|
184
|
-
if (params === null || params === void 0 ? void 0 : params.elements)
|
|
185
|
-
if (params.elements.length > 0)
|
|
186
|
-
elements = this.buildElements(params.elements);
|
|
187
|
-
// build inline fragments
|
|
188
|
-
let inlineFragments = '';
|
|
189
|
-
if (params === null || params === void 0 ? void 0 : params.inlineFragments)
|
|
190
|
-
if (params.inlineFragments.length > 0)
|
|
191
|
-
inlineFragments = this.buildInlineFragments(params.inlineFragments);
|
|
192
|
-
let finalQuery = '';
|
|
193
|
-
const sElements = inlineFragments.length > 0 ? `${elements.join(' ')} ${inlineFragments}` : elements.join(' ');
|
|
194
|
-
if (filterString.length > 0)
|
|
195
|
-
finalQuery = `${collection}(${filterString}) {${sElements}}`;
|
|
196
|
-
else
|
|
197
|
-
finalQuery = `${collection} {${sElements}}`;
|
|
198
|
-
if (metadata) {
|
|
199
|
-
const sMetadata = this.buildMetadata(metadata);
|
|
200
|
-
if (sMetadata.length > 0)
|
|
201
|
-
return `${sMetadata} ${finalQuery}`;
|
|
202
|
-
else
|
|
203
|
-
return finalQuery;
|
|
204
|
-
}
|
|
205
|
-
return finalQuery;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Given a array contain many json data, return a query string represent a query to all collections that is in a array.
|
|
209
|
-
* @param {Array<GraphObject>} data An array contain data to query to many collections
|
|
210
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
211
|
-
* @returns The query string
|
|
212
|
-
*/
|
|
213
|
-
static buildMultipleQuery(data, metadata) {
|
|
214
|
-
const queries = [];
|
|
215
|
-
for (const item of data)
|
|
216
|
-
queries.push(this.buildQuery({ collection: item.collection, params: item.params }));
|
|
217
|
-
const finalQuery = queries.join(' ');
|
|
218
|
-
if (metadata) {
|
|
219
|
-
const sMetadata = this.buildMetadata(metadata);
|
|
220
|
-
if (sMetadata.length > 0)
|
|
221
|
-
return `${sMetadata} ${finalQuery}`;
|
|
222
|
-
else
|
|
223
|
-
return finalQuery;
|
|
224
|
-
}
|
|
225
|
-
return finalQuery;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Create complete query string, you can use directly this query to query to the graph
|
|
229
|
-
* @param {string} query The query string
|
|
230
|
-
* @param {string} queryName The query name(default query)
|
|
231
|
-
* @returns The complete query string
|
|
232
|
-
*/
|
|
233
|
-
static makeFullQuery(query, queryName = 'query') {
|
|
234
|
-
return `query ${queryName} {${query}}`;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.QueryBuilder = QueryBuilder;
|
|
238
|
-
//# sourceMappingURL=query-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":";;;AAAA,uCASmB;AAEnB,MAAa,YAAY;IACvB;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,KAAgB;QACpC,MAAM,SAAS,GAAG,EAAE,CAAC;QACrB,KAAK,MAAM,GAAG,IAAI,K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