@svadmin/hasura 0.3.0 → 0.5.12

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,10 +1,12 @@
1
1
  {
2
2
  "name": "@svadmin/hasura",
3
- "version": "0.3.0",
3
+ "version": "0.5.12",
4
4
  "description": "Hasura GraphQL DataProvider for svadmin",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "files": ["src/**/*"],
7
+ "files": [
8
+ "src/**/*"
9
+ ],
8
10
  "main": "src/index.ts",
9
11
  "types": "src/index.ts",
10
12
  "exports": {
@@ -14,7 +16,12 @@
14
16
  }
15
17
  },
16
18
  "peerDependencies": {
17
- "@svadmin/core": "^0.3.0"
19
+ "@svadmin/core": "^0.5.0"
18
20
  },
19
- "license": "MIT"
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/zuohuadong/svadmin.git",
25
+ "directory": "packages/hasura"
26
+ }
20
27
  }
@@ -21,7 +21,7 @@ function mapOperator(operator: string): string {
21
21
  }
22
22
 
23
23
  // Minimal GraphQL Executor
24
- async function executeGraphQL(endpoint: string, query: string, variables: any = {}, headers: any = {}) {
24
+ async function executeGraphQL(endpoint: string, query: string, variables: Record<string, unknown> = {}, headers: Record<string, string> = {}): Promise<Record<string, unknown>> {
25
25
  const response = await fetch(endpoint, {
26
26
  method: 'POST',
27
27
  headers: { 'Content-Type': 'application/json', ...headers },
@@ -29,7 +29,7 @@ async function executeGraphQL(endpoint: string, query: string, variables: any =
29
29
  });
30
30
  const json = await response.json();
31
31
  if (json.errors) {
32
- throw new Error(json.errors.map((e: any) => e.message).join('\n'));
32
+ throw new Error((json.errors as Array<{ message: string }>).map((e) => e.message).join('\n'));
33
33
  }
34
34
  return json.data;
35
35
  }
@@ -44,11 +44,11 @@ export function createHasuraDataProvider(endpoint: string, defaultHeaders: Recor
44
44
  const limit = mode === 'server' ? pageSize : undefined;
45
45
 
46
46
  // Simplistic AST builder for demonstration. In production, 'graphql-request' or gql AST tools should be used.
47
- const variables: any = { limit, offset };
47
+ const variables: Record<string, unknown> = { limit, offset };
48
48
 
49
49
  let whereClause = '';
50
50
  if (filters && filters.length > 0) {
51
- const clauses = filters.filter((f: any) => 'field' in f).map((f: any, i: number) => {
51
+ const clauses = filters.filter((f): f is Filter & { field: string; operator: string; value: unknown } => 'field' in f).map((f, i: number) => {
52
52
  variables[`f${i}`] = f.operator === 'contains' ? `%${f.value}%` : f.value;
53
53
  return `${f.field}: { ${mapOperator(f.operator)}: $f${i} }`;
54
54
  });
@@ -75,9 +75,11 @@ export function createHasuraDataProvider(endpoint: string, defaultHeaders: Recor
75
75
  `;
76
76
 
77
77
  const data = await executeGraphQL(endpoint, query, variables, defaultHeaders);
78
+ const resourceData = data[resource] as T[] | undefined;
79
+ const aggregateData = data[`${resource}_aggregate`] as { aggregate?: { count?: number } } | undefined;
78
80
  return {
79
- data: data[resource] || [],
80
- total: data[`${resource}_aggregate`]?.aggregate?.count || 0,
81
+ data: resourceData || [],
82
+ total: aggregateData?.aggregate?.count || 0,
81
83
  };
82
84
  },
83
85
 
@@ -143,7 +145,7 @@ export function createHasuraDataProvider(endpoint: string, defaultHeaders: Recor
143
145
  }
144
146
  `;
145
147
  const data = await executeGraphQL(endpoint, query, { ids }, defaultHeaders);
146
- return { data: data[resource] || [] };
148
+ return { data: (data[resource] as T[]) || [] };
147
149
  },
148
150
 
149
151
  async custom<T>({ url, method, payload, headers }: CustomParams): Promise<CustomResult<T>> {