@0xobelisk/graphql-client 1.2.0-pre.24

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/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export {
2
+ DubheGraphqlClient,
3
+ createDubheGraphqlClient,
4
+ QueryBuilders,
5
+ } from './client';
6
+ export * from './types';
7
+ export type * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,294 @@
1
+ import { DocumentNode } from '@apollo/client';
2
+
3
+ // DubheMetadata type definition for JSON format dubhe configuration
4
+ export type DubheMetadata = {
5
+ components: Array<
6
+ Record<
7
+ string,
8
+ {
9
+ fields: Array<Record<string, any>>;
10
+ keys: string[];
11
+ }
12
+ >
13
+ >;
14
+ resources: Array<
15
+ Record<
16
+ string,
17
+ {
18
+ fields: Array<Record<string, any>>;
19
+ keys: string[];
20
+ }
21
+ >
22
+ >;
23
+ enums: any[];
24
+ };
25
+
26
+ // Basic pagination information
27
+ export interface PageInfo {
28
+ hasNextPage: boolean;
29
+ hasPreviousPage: boolean;
30
+ startCursor?: string;
31
+ endCursor?: string;
32
+ }
33
+
34
+ // Connection response common type
35
+ export interface Connection<T> {
36
+ edges: Array<{
37
+ cursor: string;
38
+ node: T;
39
+ }>;
40
+ pageInfo: PageInfo;
41
+ totalCount?: number;
42
+ }
43
+
44
+ // Basic query parameters
45
+ export interface BaseQueryParams {
46
+ first?: number;
47
+ last?: number;
48
+ after?: string;
49
+ before?: string;
50
+ }
51
+
52
+ // Sort parameters
53
+ export interface OrderBy {
54
+ field: string;
55
+ direction: 'ASC' | 'DESC';
56
+ }
57
+
58
+ // JSON path sort parameters
59
+ export interface JsonPathOrder {
60
+ path: string;
61
+ direction: 'ASC' | 'DESC';
62
+ type?: 'STRING' | 'INTEGER' | 'FLOAT' | 'BOOLEAN';
63
+ }
64
+
65
+ // Query filter base type
66
+ export interface FilterCondition {
67
+ equalTo?: any;
68
+ notEqualTo?: any;
69
+ lessThan?: any;
70
+ lessThanOrEqualTo?: any;
71
+ greaterThan?: any;
72
+ greaterThanOrEqualTo?: any;
73
+ in?: any[];
74
+ notIn?: any[];
75
+ like?: string;
76
+ notLike?: string;
77
+ isNull?: boolean;
78
+ }
79
+
80
+ // String filter
81
+ export interface StringFilter extends FilterCondition {
82
+ like?: string;
83
+ notLike?: string;
84
+ ilike?: string;
85
+ notIlike?: string;
86
+ startsWith?: string;
87
+ endsWith?: string;
88
+ includes?: string;
89
+ notIncludes?: string;
90
+ }
91
+
92
+ // Number filter
93
+ export interface NumberFilter extends FilterCondition {
94
+ lessThan?: number;
95
+ lessThanOrEqualTo?: number;
96
+ greaterThan?: number;
97
+ greaterThanOrEqualTo?: number;
98
+ }
99
+
100
+ // Date filter
101
+ export interface DateFilter extends FilterCondition {
102
+ lessThan?: string;
103
+ lessThanOrEqualTo?: string;
104
+ greaterThan?: string;
105
+ greaterThanOrEqualTo?: string;
106
+ }
107
+
108
+ // Store table base type
109
+ export interface StoreTableRow {
110
+ createdAt: string;
111
+ updatedAt: string;
112
+ [key: string]: any;
113
+ }
114
+
115
+ // Query builder type
116
+ export interface QueryBuilder<T> {
117
+ where?: Record<string, any>;
118
+ orderBy?: OrderBy[];
119
+ first?: number;
120
+ last?: number;
121
+ after?: string;
122
+ before?: string;
123
+ }
124
+
125
+ // Subscription type
126
+ export interface SubscriptionOptions {
127
+ onData?: (data: any) => void;
128
+ onError?: (error: Error) => void;
129
+ onComplete?: () => void;
130
+ }
131
+
132
+ // PostGraphile Listen subscription related types
133
+ export interface ListenPayload<T = any> {
134
+ query: T;
135
+ }
136
+
137
+ export interface ListenSubscriptionResult<T = any> {
138
+ listen: ListenPayload<T>;
139
+ }
140
+
141
+ // Advanced subscription options
142
+ export interface AdvancedSubscriptionOptions extends SubscriptionOptions {
143
+ initialEvent?: boolean;
144
+ variables?: Record<string, any>;
145
+ }
146
+
147
+ // Listen subscription configuration
148
+ export interface ListenSubscriptionConfig {
149
+ topic: string;
150
+ initialEvent?: boolean;
151
+ filter?: Record<string, any>;
152
+ orderBy?: OrderBy[];
153
+ first?: number;
154
+ fields?: string[];
155
+ }
156
+
157
+ // Query operation type
158
+ export type QueryOperation = 'query' | 'subscription';
159
+
160
+ // Typed GraphQL query
161
+ export interface TypedDocumentNode<TResult = any, TVariables = any>
162
+ extends DocumentNode {
163
+ __resultType?: TResult;
164
+ __variablesType?: TVariables;
165
+ }
166
+
167
+ // Retry configuration options
168
+ export interface RetryOptions {
169
+ max?: number;
170
+ delay?: {
171
+ initial?: number;
172
+ max?: number;
173
+ jitter?: boolean;
174
+ };
175
+ attempts?: {
176
+ max?: number;
177
+ retryIf?: (error: any, _operation: any) => boolean;
178
+ };
179
+ }
180
+
181
+ // Query cache policy
182
+ export type CachePolicy =
183
+ | 'cache-first'
184
+ | 'network-only'
185
+ | 'cache-only'
186
+ | 'no-cache'
187
+ | 'standby';
188
+
189
+ // Pagination cache strategy
190
+ export type PaginationCacheStrategy =
191
+ | 'none'
192
+ | 'filter-only'
193
+ | 'filter-orderby'
194
+ | 'table-level';
195
+
196
+ // Query options
197
+ export interface QueryOptions {
198
+ cachePolicy?: CachePolicy;
199
+ pollInterval?: number;
200
+ notifyOnNetworkStatusChange?: boolean;
201
+ }
202
+
203
+ // GraphQL error types
204
+ export interface GraphQLFormattedError {
205
+ message: string;
206
+ locations?: Array<{
207
+ line: number;
208
+ column: number;
209
+ }>;
210
+ path?: Array<string | number>;
211
+ extensions?: any;
212
+ }
213
+
214
+ // Query result
215
+ export interface QueryResult<TData = any> {
216
+ data?: TData;
217
+ loading: boolean;
218
+ error?: Error;
219
+ networkStatus: number;
220
+ refetch: () => Promise<QueryResult<TData>>;
221
+ }
222
+
223
+ // Subscription result
224
+ export interface SubscriptionResult<TData = any> {
225
+ data?: TData;
226
+ loading: boolean;
227
+ error?: Error;
228
+ }
229
+
230
+ // Multi-table subscription configuration
231
+ export interface MultiTableSubscriptionConfig {
232
+ tableName: string;
233
+ options?: SubscriptionOptions & {
234
+ fields?: string[];
235
+ filter?: Record<string, any>;
236
+ initialEvent?: boolean;
237
+ first?: number;
238
+ orderBy?: OrderBy[];
239
+ topicPrefix?: string;
240
+ };
241
+ }
242
+
243
+ // Multi-table subscription result
244
+ export interface MultiTableSubscriptionResult {
245
+ [tableName: string]: SubscriptionResult<{ listen: { query: any } }>;
246
+ }
247
+
248
+ // Multi-table subscription data result
249
+ export interface MultiTableSubscriptionData {
250
+ [tableName: string]: {
251
+ listen: {
252
+ query: any;
253
+ };
254
+ };
255
+ }
256
+
257
+ // Dubhe component field
258
+ export interface DubheComponentField {
259
+ type: string;
260
+ }
261
+
262
+ export interface DubheComponent {
263
+ fields?: Record<string, string | DubheComponentField>;
264
+ keys?: string[];
265
+ }
266
+
267
+ // Auto-parsed field information
268
+ export interface ParsedTableInfo {
269
+ tableName: string;
270
+ fields: string[];
271
+ primaryKeys: string[];
272
+ enumFields: Record<string, string[]>;
273
+ }
274
+
275
+ // Client configuration
276
+ export interface DubheClientConfig {
277
+ endpoint: string;
278
+ subscriptionEndpoint?: string;
279
+ headers?: Record<string, string>;
280
+ fetchOptions?: RequestInit;
281
+ retryOptions?: RetryOptions;
282
+ dubheMetadata?: any;
283
+ cacheConfig?: {
284
+ paginatedTables?: string[];
285
+ strategy?: PaginationCacheStrategy;
286
+ customMergeStrategies?: Record<
287
+ string,
288
+ {
289
+ keyArgs?: string[];
290
+ merge?: (existing: any, incoming: any) => any;
291
+ }
292
+ >;
293
+ };
294
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,49 @@
1
+ export const parseData = (data: unknown): unknown => {
2
+ if (typeof data !== 'object' || data === null) {
3
+ return data;
4
+ }
5
+
6
+ if (Array.isArray(data)) {
7
+ return data.map((item) => parseData(item));
8
+ }
9
+
10
+ const parsedData: Record<string, unknown> = {};
11
+ for (const key in data as object) {
12
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
13
+ const value = (data as Record<string, unknown>)[key];
14
+
15
+ if (typeof value === 'object' && value !== null) {
16
+ if ('variant' in value) {
17
+ parsedData[key] = value.variant;
18
+ } else if ('fields' in value) {
19
+ parsedData[key] = parseData(value.fields);
20
+ } else {
21
+ parsedData[key] = parseData(value);
22
+ }
23
+ } else {
24
+ parsedData[key] = value;
25
+ }
26
+ }
27
+ }
28
+ return parsedData;
29
+ };
30
+
31
+ export const parseValue = (value: unknown): unknown => {
32
+ if (typeof value !== 'object' || value === null) {
33
+ return value;
34
+ }
35
+
36
+ if (Array.isArray(value)) {
37
+ return value.map((item) => parseValue(item));
38
+ }
39
+
40
+ if ('variant' in value) {
41
+ return value.variant;
42
+ }
43
+
44
+ if ('fields' in value) {
45
+ return parseData(value.fields);
46
+ }
47
+
48
+ return parseData(value);
49
+ };