@svadmin/directus 0.8.0 → 0.9.0

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": "@svadmin/directus",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Directus DataProvider for svadmin",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -2,7 +2,7 @@ import type {
2
2
  DataProvider, GetListParams, GetListResult, GetOneParams, GetOneResult,
3
3
  CreateParams, CreateResult, UpdateParams, UpdateResult, DeleteParams, DeleteResult,
4
4
  GetManyParams, GetManyResult, CustomParams, CustomResult, Sort, Filter
5
- } from '@svadmin/core';
5
+ , BaseRecord } from '@svadmin/core';
6
6
 
7
7
  function buildDirectusFilter(filters?: Filter[]): Record<string, unknown> {
8
8
  if (!filters?.length) return {};
@@ -27,7 +27,7 @@ export function createDirectusDataProvider(apiUrl: string, token?: string): Data
27
27
  return {
28
28
  getApiUrl: () => apiUrl,
29
29
 
30
- async getList<T>({ resource, pagination, sorters, filters, meta }: GetListParams): Promise<GetListResult<T>> {
30
+ async getList<T extends BaseRecord = BaseRecord>({ resource, pagination, sorters, filters, meta }: GetListParams): Promise<GetListResult<T>> {
31
31
  const { current = 1, pageSize = 10 } = pagination ?? {};
32
32
  const params = new URLSearchParams();
33
33
  params.set('limit', String(pageSize));
@@ -42,28 +42,28 @@ export function createDirectusDataProvider(apiUrl: string, token?: string): Data
42
42
  return { data: data.data ?? [], total: data.meta?.total_count ?? 0 };
43
43
  },
44
44
 
45
- async getOne<T>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
45
+ async getOne<T extends BaseRecord = BaseRecord>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
46
46
  const params = meta?.fields ? `?fields=${(meta.fields as string[]).join(',')}` : '';
47
47
  const data = await request<any>(`/items/${resource}/${id}${params}`);
48
- return { data: data.data as T };
48
+ return { data: data.data as unknown as T };
49
49
  },
50
50
 
51
- async create<T>({ resource, variables }: CreateParams): Promise<CreateResult<T>> {
51
+ async create<T extends BaseRecord = BaseRecord>({ resource, variables }: CreateParams): Promise<CreateResult<T>> {
52
52
  const data = await request<any>(`/items/${resource}`, { method: 'POST', body: JSON.stringify(variables) });
53
- return { data: data.data as T };
53
+ return { data: data.data as unknown as T };
54
54
  },
55
55
 
56
- async update<T>({ resource, id, variables }: UpdateParams): Promise<UpdateResult<T>> {
56
+ async update<T extends BaseRecord = BaseRecord>({ resource, id, variables }: UpdateParams): Promise<UpdateResult<T>> {
57
57
  const data = await request<any>(`/items/${resource}/${id}`, { method: 'PATCH', body: JSON.stringify(variables) });
58
- return { data: data.data as T };
58
+ return { data: data.data as unknown as T };
59
59
  },
60
60
 
61
- async deleteOne<T>({ resource, id }: DeleteParams): Promise<DeleteResult<T>> {
61
+ async deleteOne<T extends BaseRecord = BaseRecord>({ resource, id }: DeleteParams): Promise<DeleteResult<T>> {
62
62
  await request(`/items/${resource}/${id}`, { method: 'DELETE' });
63
- return { data: { id } as T };
63
+ return { data: { id } as unknown as T };
64
64
  },
65
65
 
66
- async getMany<T>({ resource, ids, meta }: GetManyParams): Promise<GetManyResult<T>> {
66
+ async getMany<T extends BaseRecord = BaseRecord>({ resource, ids, meta }: GetManyParams): Promise<GetManyResult<T>> {
67
67
  const params = new URLSearchParams();
68
68
  params.set('filter', JSON.stringify({ id: { _in: ids } }));
69
69
  if (meta?.fields) params.set('fields', (meta.fields as string[]).join(','));
@@ -71,10 +71,10 @@ export function createDirectusDataProvider(apiUrl: string, token?: string): Data
71
71
  return { data: data.data ?? [] };
72
72
  },
73
73
 
74
- async custom<T>({ url, method, payload, headers: h }: CustomParams): Promise<CustomResult<T>> {
74
+ async custom<T = unknown>({ url, method, payload, headers: h }: CustomParams): Promise<CustomResult<T>> {
75
75
  const res = await fetch(url, { method: method.toUpperCase(), headers: { ...headers, ...h }, body: payload ? JSON.stringify(payload) : undefined });
76
76
  if (!res.ok) throw new Error(`Custom request failed: ${res.status}`);
77
- return { data: (await res.json()) as T };
77
+ return { data: (await res.json()) as unknown as T };
78
78
  },
79
79
  };
80
80
  }