eth-graph-query 2.0.20 → 2.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eth-graph-query",
3
- "version": "2.0.20",
3
+ "version": "2.0.21",
4
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
6
  "main": "dist/index.cjs",
@@ -9,15 +9,16 @@
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
+ "sideEffects": false,
12
13
  "scripts": {
13
- "build": "npm run clear && tsc && vite build",
14
+ "build": "bun run clear && tsc && vite build",
14
15
  "preview": "vite preview",
15
16
  "clear": "rm -rf dist",
16
17
  "test": "vitest run",
17
- "prepare": "npm run build && husky install",
18
+ "prepare": "bun run build && husky install",
18
19
  "eslint": "eslint --config ./eslint.config.js --cache",
19
20
  "format": "prettier --write .",
20
- "prepublishOnly": "npm run clear && npm run build && npm run test"
21
+ "prepublishOnly": "bun run clear && bun run build && bun run test"
21
22
  },
22
23
  "repository": {
23
24
  "type": "git",
@@ -33,15 +34,15 @@
33
34
  "url": "https://github.com/phamhongphuc1999/eth-graph-query/issues"
34
35
  },
35
36
  "homepage": "https://github.com/phamhongphuc1999/eth-graph-query#readme",
36
- "dependencies": {
37
+ "peerDependencies": {
37
38
  "axios": "^1.13.2"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@commitlint/cli": "^19.4.0",
41
42
  "@commitlint/config-conventional": "^19.2.2",
42
43
  "@eslint/js": "^9.29.0",
43
- "@rollup/plugin-typescript": "^11.1.6",
44
44
  "@types/node": "^20.12.2",
45
+ "axios": "^1.13.2",
45
46
  "eslint": "^9.29.0",
46
47
  "eslint-import-resolver-typescript": "^4.4.4",
47
48
  "eslint-plugin-import": "^2.32.0",
@@ -50,11 +51,10 @@
50
51
  "eslint-plugin-react-refresh": "^0.4.20",
51
52
  "husky": "^9.1.6",
52
53
  "path": "^0.12.7",
53
- "rollup-plugin-typescript-paths": "^1.5.0",
54
- "tslib": "^2.6.2",
55
54
  "typescript": "5.5.3",
56
55
  "typescript-eslint": "^8.34.1",
57
56
  "vite": "^7.2.7",
57
+ "vite-plugin-dts": "^4.5.4",
58
58
  "vitest": "^4.0.15"
59
59
  },
60
60
  "contributors": [
@@ -1,67 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- export declare const defaultHeader: {
3
- Accept: string;
4
- 'Content-Type': string;
5
- };
6
- /**
7
- * Base class for handling API requests using axios.
8
- * Provides protected methods for common HTTP verbs.
9
- */
10
- export declare class ApiQuery {
11
- /** The root URL for all API requests. */
12
- root: string;
13
- /** Axios configuration used for all requests. */
14
- config: AxiosRequestConfig;
15
- /**
16
- * Initializes a new instance of the ApiQuery class.
17
- * @param rootUrl - The base URL for the API.
18
- * @param config - Optional axios configuration.
19
- */
20
- constructor(rootUrl: string, config?: AxiosRequestConfig);
21
- /**
22
- * Performs an API request.
23
- * @template T - The expected response type.
24
- * @param method - The HTTP method to use.
25
- * @param url - The relative URL for the request.
26
- * @param data - The request payload (for POST, PUT).
27
- * @param config - Optional axios configuration to override defaults.
28
- * @returns A promise that resolves to the response data.
29
- */
30
- private request;
31
- /**
32
- * Performs a GET request.
33
- * @template T - The expected response type.
34
- * @param url - The relative URL for the request.
35
- * @param config - Optional axios configuration to override defaults.
36
- * @returns A promise that resolves to the response data.
37
- */
38
- protected get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
39
- /**
40
- * Performs a POST request.
41
- * @template B - The request body type.
42
- * @template T - The expected response type.
43
- * @param url - The relative URL for the request.
44
- * @param data - The request payload.
45
- * @param config - Optional axios configuration to override defaults.
46
- * @returns A promise that resolves to the response data.
47
- */
48
- protected post<B = any, T = any>(url: string, data?: B, config?: AxiosRequestConfig): Promise<T>;
49
- /**
50
- * Performs a PUT request.
51
- * @template B - The request body type.
52
- * @template T - The expected response type.
53
- * @param url - The relative URL for the request.
54
- * @param data - The request payload.
55
- * @param config - Optional axios configuration to override defaults.
56
- * @returns A promise that resolves to the response data.
57
- */
58
- protected put<B = any, T = any>(url: string, data?: B, config?: AxiosRequestConfig): Promise<T>;
59
- /**
60
- * Performs a DELETE request.
61
- * @template T - The expected response type.
62
- * @param url - The relative URL for the request.
63
- * @param config - Optional axios configuration to override defaults.
64
- * @returns A promise that resolves to the response data.
65
- */
66
- protected del<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
67
- }
@@ -1,41 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { ApiQuery } from './api-query';
3
- import { GraphObject, Metadata } from './type';
4
- /**
5
- * Main class for performing queries against The Graph protocols.
6
- * Extends ApiQuery to handle HTTP communication.
7
- */
8
- export declare class EthGraphQuery extends ApiQuery {
9
- /** The name of the GraphQL query, used in makeFullQuery. */
10
- queryName: string;
11
- /**
12
- * Initializes a new EthGraphQuery instance.
13
- * @param rootUrl - The endpoint URL of the subgraph.
14
- * @param config - Optional axios configuration for custom headers or timeouts.
15
- */
16
- constructor(rootUrl: string, config?: AxiosRequestConfig);
17
- /**
18
- * Executes a raw GraphQL query string.
19
- * @template T - The expected return type of the data.
20
- * @param data - The raw GraphQL query string.
21
- * @returns A promise resolving to the query result.
22
- * @throws Error if the response contains any GraphQL errors.
23
- */
24
- stringQuery<T = any>(data: string): Promise<T>;
25
- /**
26
- * Executes a single collection query using a JSON configuration.
27
- * @template T - The expected return type of the data.
28
- * @param data - The configuration for the collection query.
29
- * @param metadata - Optional metadata fields to include in the query.
30
- * @returns A promise resolving to the fetched data.
31
- */
32
- query<T = any>(data: GraphObject, metadata?: Metadata): Promise<T>;
33
- /**
34
- * Executes multiple collection queries in a single request using JSON configurations.
35
- * @template T - The expected return type of the data.
36
- * @param data - An array of query configurations.
37
- * @param metadata - Optional metadata fields to include in the query.
38
- * @returns A promise resolving to the merged results of all queries.
39
- */
40
- multipleQuery<T = any>(data: Array<GraphObject>, metadata?: Metadata): Promise<T>;
41
- }
@@ -1,56 +0,0 @@
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 DELETED
@@ -1,149 +0,0 @@
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
- };