eth-graph-query 2.0.1 → 2.0.20

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.
Files changed (59) hide show
  1. package/README.md +79 -90
  2. package/dist/.vite/manifest.json +8 -0
  3. package/dist/api-query.d.ts +67 -0
  4. package/dist/eth-graph-query.d.ts +41 -0
  5. package/dist/index.cjs +6 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.js +2072 -0
  8. package/dist/query-builder.d.ts +56 -0
  9. package/dist/type.d.ts +149 -0
  10. package/package.json +35 -50
  11. package/dist/cjs/eth-graph-query.d.ts +0 -35
  12. package/dist/cjs/eth-graph-query.d.ts.map +0 -1
  13. package/dist/cjs/eth-graph-query.js +0 -69
  14. package/dist/cjs/eth-graph-query.js.map +0 -1
  15. package/dist/cjs/index.d.ts +0 -4
  16. package/dist/cjs/index.d.ts.map +0 -1
  17. package/dist/cjs/index.js +0 -22
  18. package/dist/cjs/index.js.map +0 -1
  19. package/dist/cjs/normal-query.d.ts +0 -15
  20. package/dist/cjs/normal-query.d.ts.map +0 -1
  21. package/dist/cjs/normal-query.js +0 -65
  22. package/dist/cjs/normal-query.js.map +0 -1
  23. package/dist/cjs/package.json +0 -3
  24. package/dist/cjs/query-builder.d.ts +0 -52
  25. package/dist/cjs/query-builder.d.ts.map +0 -1
  26. package/dist/cjs/query-builder.js +0 -238
  27. package/dist/cjs/query-builder.js.map +0 -1
  28. package/dist/cjs/type.d.ts +0 -67
  29. package/dist/cjs/type.d.ts.map +0 -1
  30. package/dist/cjs/type.js +0 -25
  31. package/dist/cjs/type.js.map +0 -1
  32. package/dist/esm/eth-graph-query.d.ts +0 -35
  33. package/dist/esm/eth-graph-query.d.ts.map +0 -1
  34. package/dist/esm/eth-graph-query.js +0 -65
  35. package/dist/esm/eth-graph-query.js.map +0 -1
  36. package/dist/esm/index.d.ts +0 -4
  37. package/dist/esm/index.d.ts.map +0 -1
  38. package/dist/esm/index.js +0 -4
  39. package/dist/esm/index.js.map +0 -1
  40. package/dist/esm/normal-query.d.ts +0 -15
  41. package/dist/esm/normal-query.d.ts.map +0 -1
  42. package/dist/esm/normal-query.js +0 -58
  43. package/dist/esm/normal-query.js.map +0 -1
  44. package/dist/esm/package.json +0 -3
  45. package/dist/esm/query-builder.d.ts +0 -52
  46. package/dist/esm/query-builder.d.ts.map +0 -1
  47. package/dist/esm/query-builder.js +0 -234
  48. package/dist/esm/query-builder.js.map +0 -1
  49. package/dist/esm/type.d.ts +0 -67
  50. package/dist/esm/type.d.ts.map +0 -1
  51. package/dist/esm/type.js +0 -22
  52. package/dist/esm/type.js.map +0 -1
  53. package/dist/tsconfig.prod.cjs.tsbuildinfo +0 -1
  54. package/dist/tsconfig.prod.esm.tsbuildinfo +0 -1
  55. package/src/eth-graph-query.ts +0 -61
  56. package/src/index.ts +0 -3
  57. package/src/normal-query.ts +0 -46
  58. package/src/query-builder.ts +0 -216
  59. package/src/type.ts +0 -89
@@ -0,0 +1,56 @@
1
+ import { ElementType, GraphObject, InlineFragmentType, Metadata, QueryJson } from './type';
2
+ export declare class QueryBuilder {
3
+ /**
4
+ * Converts a JSON query object into a GraphQL-compatible string.
5
+ * Handles nested objects and operator mapping (e.g., $gt -> _gt).
6
+ * @param query - The JSON filter object to build.
7
+ * @returns A string representing the GraphQL 'where' or 'block' filter.
8
+ */
9
+ static buildJsonQuery(query: QueryJson): string;
10
+ /**
11
+ * Builds the fields/elements part of a GraphQL query from an array of strings or objects.
12
+ * @param elements - An array of fields to query. Can include nested collections as GraphObject.
13
+ * @returns An array of strings representing the selected fields.
14
+ */
15
+ static buildElements(elements: Array<ElementType>): Array<string>;
16
+ /**
17
+ * Builds the metadata (_meta) fragment of a GraphQL query.
18
+ * @param metadata - The metadata configuration.
19
+ * @returns A string representing the _meta query fragment.
20
+ */
21
+ static buildMetadata(metadata: Metadata): string;
22
+ /**
23
+ * Builds an inline fragment (... on Collection { ... }) for a query.
24
+ * @param fragment - The inline fragment configuration.
25
+ * @returns A string representing the inline fragment.
26
+ * @private
27
+ */
28
+ private static _buildInlineFragment;
29
+ /**
30
+ * Builds multiple inline fragments from an array of fragment configurations.
31
+ * @param fragments - An array of inline fragments.
32
+ * @returns A string containing all built inline fragments.
33
+ */
34
+ static buildInlineFragments(fragments: Array<InlineFragmentType>): string;
35
+ /**
36
+ * Builds a complete GraphQL query for a single collection.
37
+ * @param data - The collection and parameters for the query.
38
+ * @param metadata - Optional metadata configuration.
39
+ * @returns A string containing the GraphQL query for the collection.
40
+ */
41
+ static buildQuery(data: GraphObject, metadata?: Metadata): string;
42
+ /**
43
+ * Builds a query that targets multiple collections simultaneously.
44
+ * @param data - An array of collection queries and their parameters.
45
+ * @param metadata - Optional metadata configuration that applies to the entire query.
46
+ * @returns A string containing the merged GraphQL query for multiple collections.
47
+ */
48
+ static buildMultipleQuery(data: Array<GraphObject>, metadata?: Metadata): string;
49
+ /**
50
+ * Wraps a query fragment into a full GraphQL 'query' block.
51
+ * @param query - The query fragment to wrap.
52
+ * @param queryName - An optional name for the GraphQL query (defaults to 'query').
53
+ * @returns The full GraphQL query string.
54
+ */
55
+ static makeFullQuery(query: string, queryName?: string): string;
56
+ }
package/dist/type.d.ts ADDED
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Base types that can be used in query filters.
3
+ */
4
+ export type BaseQueryType = string | number | boolean | Array<string | number | boolean> | null | undefined;
5
+ /**
6
+ * Valid operator suffixes for The Graph queries (e.g., _gt, _in, _contains).
7
+ */
8
+ export declare const OptionKeys: readonly ["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"];
9
+ /**
10
+ * Type representing the valid operator keys.
11
+ */
12
+ export type OptionKey = (typeof OptionKeys)[number];
13
+ /**
14
+ * Filter options for text-based fields.
15
+ */
16
+ export type TextWhereOptions = {
17
+ /** Matches values containing the substring. */
18
+ $contains?: BaseQueryType;
19
+ /** Case-insensitive contains. */
20
+ $contains_nocase?: BaseQueryType;
21
+ /** Matches values ending with the substring. */
22
+ $ends_with?: BaseQueryType;
23
+ /** Case-insensitive ends_with. */
24
+ $end_with_nocase?: BaseQueryType;
25
+ /** Matches values starting with the substring. */
26
+ $starts_with?: BaseQueryType;
27
+ /** Case-insensitive starts_with. */
28
+ $starts_with_nocase?: BaseQueryType;
29
+ /** Matches values NOT containing the substring. */
30
+ $not_contains?: BaseQueryType;
31
+ /** Case-insensitive not_contains. */
32
+ $not_contains_nocase?: BaseQueryType;
33
+ /** Matches values NOT ending with the substring. */
34
+ $not_ends_with?: BaseQueryType;
35
+ /** Case-insensitive not_ends_with. */
36
+ $not_ends_with_nocase?: BaseQueryType;
37
+ /** Matches values NOT starting with the substring. */
38
+ $not_starts_with?: BaseQueryType;
39
+ /** Case-insensitive not_starts_with. */
40
+ $not_starts_with_nocase?: BaseQueryType;
41
+ };
42
+ /**
43
+ * Common filter options for all field types.
44
+ */
45
+ export type CommonWhereOptions = {
46
+ /** Greater than. */
47
+ $gt?: BaseQueryType;
48
+ /** Greater than or equal to. */
49
+ $gte?: BaseQueryType;
50
+ /** Less than. */
51
+ $lt?: BaseQueryType;
52
+ /** Less than or equal to. */
53
+ $lte?: BaseQueryType;
54
+ /** Not equal to. */
55
+ $not?: BaseQueryType;
56
+ /** Included in the provided array. */
57
+ $in?: BaseQueryType;
58
+ /** Not included in the provided array. */
59
+ $not_in?: BaseQueryType;
60
+ };
61
+ /**
62
+ * Combined filter options for a field.
63
+ */
64
+ export type WhereOptions = TextWhereOptions & CommonWhereOptions;
65
+ /**
66
+ * JSON structure representing the 'where' filter in a query.
67
+ * Keys are field names, and values can be primitive values or WhereOptions.
68
+ */
69
+ export type QueryJson = {
70
+ [key: string]: QueryJson | WhereOptions | BaseQueryType;
71
+ };
72
+ /**
73
+ * Filter for querying data at a specific block.
74
+ */
75
+ export type BlockQuery = {
76
+ /** Filter by block hash. */
77
+ hash?: string;
78
+ /** Filter by exact block number. */
79
+ number?: number;
80
+ /** Filter by blocks with number greater than or equal to. */
81
+ number_gte?: number;
82
+ };
83
+ /**
84
+ * Metadata fields to query from the subgraph (_meta).
85
+ */
86
+ export type Metadata = {
87
+ /** Specific metadata elements to fetch. */
88
+ elements?: Array<'deployment' | 'hasIndexingErrors' | 'hash' | 'number' | 'timestamp'>;
89
+ /** Query metadata for a specific block. */
90
+ blockQuery?: BlockQuery;
91
+ };
92
+ /**
93
+ * Represents a field in a query. Can be a simple string (field name)
94
+ * or a GraphObject for nested collection queries.
95
+ */
96
+ export type ElementType = string | GraphObject;
97
+ /**
98
+ * Represents an inline fragment for polymorphic types.
99
+ */
100
+ export type InlineFragmentType = {
101
+ /** The collection name for the fragment (e.g., 'User'). */
102
+ collection: string;
103
+ /** Fields to select within the fragment. */
104
+ params?: Pick<GraphParams, 'elements'>;
105
+ };
106
+ /**
107
+ * Parameters for a collection query.
108
+ */
109
+ export interface GraphParams {
110
+ /** Fields to select from the collection. */
111
+ elements?: Array<ElementType>;
112
+ /** Inline fragments for selecting fields on specific types. */
113
+ inlineFragments?: Array<InlineFragmentType>;
114
+ /** Filter conditions for the query. */
115
+ where?: QueryJson;
116
+ /** Filter by specific entity ID (shortcut for where: { id: ... }). */
117
+ id?: string;
118
+ /** Number of items to return (max 1000). */
119
+ first?: number;
120
+ /** Field to sort the results by. */
121
+ orderBy?: string;
122
+ /** Direction of the sort (asc or desc). */
123
+ orderDirection?: 'asc' | 'desc';
124
+ /** Number of items to skip (max 5000). */
125
+ skip?: number;
126
+ /** Re-run the query even if the subgraph has indexing errors. */
127
+ subgraphError?: 'allow' | 'deny';
128
+ /** Query the collection state at a specific block. */
129
+ block?: BlockQuery;
130
+ }
131
+ /**
132
+ * Configuration for a query against a specific collection.
133
+ */
134
+ export interface GraphObject {
135
+ /** The name of the collection to query (e.g., 'users'). */
136
+ collection: string;
137
+ /** Optional parameters for filtering, sorting, and pagination. */
138
+ params?: GraphParams;
139
+ }
140
+ /**
141
+ * Error structure returned by The Graph API.
142
+ */
143
+ export type ErrorObject = {
144
+ /** List of errors encountered during query execution. */
145
+ errors: Array<{
146
+ message: string;
147
+ locations: Array<unknown>;
148
+ }>;
149
+ };
package/package.json CHANGED
@@ -1,33 +1,23 @@
1
1
  {
2
2
  "name": "eth-graph-query",
3
- "version": "2.0.1",
4
- "description": "simple package for create query command to the GraphQL in ethereum",
3
+ "version": "2.0.20",
4
+ "description": "A lightweight and flexible library for building The Graph queries using simple JSON objects. Eliminate the need for complex string concatenation and maintain type-safe queries.",
5
5
  "type": "module",
6
- "main": "dist/cjs/index.js",
7
- "module": "dist/esm/index.js",
8
- "exports": {
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
- "clean": "./scripts/clear-package.sh",
22
- "build": "./scripts/ts-build.sh",
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
- "eslint": "eslint . --ext .ts",
28
- "prepublishOnly": "npm run clean && npm run build && npm run test",
29
- "tsc": "./scripts/ts-compile.sh",
30
- "example": "node --loader ts-node/esm"
18
+ "eslint": "eslint --config ./eslint.config.js --cache",
19
+ "format": "prettier --write .",
20
+ "prepublishOnly": "npm run clear && npm run build && npm run test"
31
21
  },
32
22
  "repository": {
33
23
  "type": "git",
@@ -44,27 +34,28 @@
44
34
  },
45
35
  "homepage": "https://github.com/phamhongphuc1999/eth-graph-query#readme",
46
36
  "dependencies": {
47
- "axios": "^1.6.8"
37
+ "axios": "^1.13.2"
48
38
  },
49
39
  "devDependencies": {
50
- "@commitlint/cli": "^17.6.5",
51
- "@commitlint/config-conventional": "^17.6.5",
52
- "@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
- "eslint": "^8.40.0",
57
- "eslint-config-prettier": "^8.8.0",
58
- "eslint-import-resolver-alias": "^1.1.2",
59
- "eslint-plugin-import": "^2.26.0",
60
- "eslint-plugin-prettier": "^4.2.1",
61
- "husky": "^8.0.3",
62
- "lint-staged": "^13.2.2",
63
- "prettier": "^2.8.8",
64
- "ts-node": "10.9.1",
65
- "typescript": "4.7.4",
66
- "vitest": "1.4.0",
67
- "webdriverio": "^8.10.7"
40
+ "@commitlint/cli": "^19.4.0",
41
+ "@commitlint/config-conventional": "^19.2.2",
42
+ "@eslint/js": "^9.29.0",
43
+ "@rollup/plugin-typescript": "^11.1.6",
44
+ "@types/node": "^20.12.2",
45
+ "eslint": "^9.29.0",
46
+ "eslint-import-resolver-typescript": "^4.4.4",
47
+ "eslint-plugin-import": "^2.32.0",
48
+ "eslint-plugin-prettier": "^5.5.1",
49
+ "eslint-plugin-react-hooks": "^5.2.0",
50
+ "eslint-plugin-react-refresh": "^0.4.20",
51
+ "husky": "^9.1.6",
52
+ "path": "^0.12.7",
53
+ "rollup-plugin-typescript-paths": "^1.5.0",
54
+ "tslib": "^2.6.2",
55
+ "typescript": "5.5.3",
56
+ "typescript-eslint": "^8.34.1",
57
+ "vite": "^7.2.7",
58
+ "vitest": "^4.0.15"
68
59
  },
69
60
  "contributors": [
70
61
  {
@@ -74,18 +65,12 @@
74
65
  }
75
66
  ],
76
67
  "engines": {
77
- "node": ">=16",
78
- "npm": ">=7"
68
+ "node": ">=20",
69
+ "npm": ">=10"
79
70
  },
80
71
  "commitlint": {
81
72
  "extends": [
82
73
  "@commitlint/config-conventional"
83
74
  ]
84
- },
85
- "lint-staged": {
86
- "*.{js,jsx,ts,tsx}": "eslint --config ./.eslintrc-staged.cjs --cache --fix",
87
- "*.{json,yml,md}": [
88
- "prettier --write"
89
- ]
90
75
  }
91
76
  }
@@ -1,35 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { NormalQuery } from './normal-query.js';
3
- import { GraphObject, Metadata } from './type.js';
4
- export declare class EthGraphQuery extends NormalQuery {
5
- queryName: string;
6
- /**
7
- * The constructor for create a query instance.
8
- * @param {string} rootUrl The url leading to the graph
9
- * @param {AxiosRequestConfig | undefined} config Config for base axios
10
- */
11
- constructor(rootUrl: string, config?: AxiosRequestConfig);
12
- /**
13
- * Given query string, returns the data respective with it.
14
- * @param {string} query A query string containing all data you want to fetch
15
- * @returns The data respective with the query string
16
- */
17
- stringQuery<T = any>(data: string): Promise<T>;
18
- /**
19
- * Create a query to a particular collection, returns the data respective with the query data.
20
- * @param {GraphObject} data An data for create query, contains two elements:
21
- * 1. collection: string - collection name
22
- * 2. params: GraphParams | undefined - If it is defined, it create a query to the collection
23
- * @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
24
- * @returns The data respective with the query data
25
- */
26
- query<T = any>(data: GraphObject, metadata?: Metadata): Promise<T>;
27
- /**
28
- * Create a query to many collections, returns the data respective with the query data.
29
- * @param {Array<GraphObject>} data An array contain data to query to many collections
30
- * @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
31
- * @returns The data respective with the query data
32
- */
33
- multipleQuery<T = any>(data: Array<GraphObject>, metadata?: Metadata): Promise<T>;
34
- }
35
- //# sourceMappingURL=eth-graph-query.d.ts.map
@@ -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"}
@@ -1,4 +0,0 @@
1
- export { EthGraphQuery } from './eth-graph-query.js';
2
- export * from './query-builder.js';
3
- export * from './type.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -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,15 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- export declare const defaultHeader: {
3
- Accept: string;
4
- 'Content-Type': string;
5
- };
6
- export declare class NormalQuery {
7
- root: string;
8
- config: AxiosRequestConfig;
9
- constructor(rootUrl: string, config?: AxiosRequestConfig);
10
- protected get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
11
- protected post<B = any, T = any>(url: string, data?: B, config?: AxiosRequestConfig): Promise<T>;
12
- protected put<B = any, T = any>(url: string, data?: B, config?: AxiosRequestConfig): Promise<T>;
13
- protected del<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
14
- }
15
- //# sourceMappingURL=normal-query.d.ts.map
@@ -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"}
@@ -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,IAAI,CAAC,MAAM,0CAAE,OAAO,CAAA;gBAAE,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,mCAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAK,qBAAa,CAAE,CAAC;SAC1E;;YAAM,IAAI,CAAC,MAAM,GAAG,EAAE,OAAO,EAAE,qBAAa,EAAE,CAAC;IAClD,CAAC;IAEe,GAAG,CAAU,GAAW,EAAE,MAA2B;;YACnE,OAAO,MAAM,eAAK;iBACf,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,kCAAO,MAAM,GAAK,IAAI,CAAC,MAAM,EAAG;iBACxD,IAAI,CAAI,YAAY,CAAC,CAAC;QAC3B,CAAC;KAAA;IAEe,IAAI,CAAmB,GAAW,EAAE,IAAQ,EAAE,MAA2B;;YACvF,OAAO,MAAM,eAAK;iBACf,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,IAAI,kCAAO,MAAM,GAAK,IAAI,CAAC,MAAM,EAAG;iBAC/D,IAAI,CAAI,YAAY,CAAC,CAAC;QAC3B,CAAC;KAAA;IAEe,GAAG,CAAmB,GAAW,EAAE,IAAQ,EAAE,MAA2B;;YACtF,OAAO,MAAM,eAAK;iBACf,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,IAAI,kCAAO,MAAM,GAAK,IAAI,CAAC,MAAM,EAAG;iBAC9D,IAAI,CAAI,YAAY,CAAC,CAAC;QAC3B,CAAC;KAAA;IAEe,GAAG,CAAU,GAAW,EAAE,MAA2B;;YACnE,OAAO,MAAM,eAAK;iBACf,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,kCAAO,MAAM,GAAK,IAAI,CAAC,MAAM,EAAG;iBAC3D,IAAI,CAAI,YAAY,CAAC,CAAC;QAC3B,CAAC;KAAA;CACF;AApCD,kCAoCC"}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -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"}