@svadmin/strapi 0.6.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 +1 -1
- package/src/data-provider.ts +9 -9
package/package.json
CHANGED
package/src/data-provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DataProvider, GetListParams, GetListResult, GetOneParams, GetOneResult,
|
|
3
3
|
CreateParams, CreateResult, UpdateParams, UpdateResult, DeleteParams, DeleteResult,
|
|
4
|
-
GetManyParams, GetManyResult, CustomParams, CustomResult, Sort, Filter
|
|
4
|
+
GetManyParams, GetManyResult, CustomParams, CustomResult, Sort, Filter, BaseRecord
|
|
5
5
|
} from '@svadmin/core';
|
|
6
6
|
|
|
7
7
|
function mapOperator(operator: string): string {
|
|
@@ -52,7 +52,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
52
52
|
return {
|
|
53
53
|
getApiUrl: () => apiUrl,
|
|
54
54
|
|
|
55
|
-
async getList<T>({ resource, pagination, sorters, filters, meta }: GetListParams): Promise<GetListResult<T>> {
|
|
55
|
+
async getList<T extends BaseRecord>({ resource, pagination, sorters, filters, meta }: GetListParams): Promise<GetListResult<T>> {
|
|
56
56
|
const url = new URL(`${apiUrl}/${resource}`);
|
|
57
57
|
url.search = generateQueryParams(pagination, sorters, filters);
|
|
58
58
|
if (meta?.populate) url.searchParams.append('populate', String(meta.populate));
|
|
@@ -72,7 +72,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
72
72
|
};
|
|
73
73
|
},
|
|
74
74
|
|
|
75
|
-
async getOne<T>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
|
|
75
|
+
async getOne<T extends BaseRecord>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<T>> {
|
|
76
76
|
const url = new URL(`${apiUrl}/${resource}/${id}`);
|
|
77
77
|
if (meta?.populate) url.searchParams.append('populate', String(meta.populate));
|
|
78
78
|
|
|
@@ -82,7 +82,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
82
82
|
return { data: data.data || data };
|
|
83
83
|
},
|
|
84
84
|
|
|
85
|
-
async create<T>({ resource, variables }: CreateParams): Promise<CreateResult<T>> {
|
|
85
|
+
async create<T extends BaseRecord>({ resource, variables }: CreateParams): Promise<CreateResult<T>> {
|
|
86
86
|
const response = await httpClient(`${apiUrl}/${resource}`, {
|
|
87
87
|
method: 'POST',
|
|
88
88
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -93,7 +93,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
93
93
|
return { data: result.data || result };
|
|
94
94
|
},
|
|
95
95
|
|
|
96
|
-
async update<T>({ resource, id, variables }: UpdateParams): Promise<UpdateResult<T>> {
|
|
96
|
+
async update<T extends BaseRecord>({ resource, id, variables }: UpdateParams): Promise<UpdateResult<T>> {
|
|
97
97
|
const response = await httpClient(`${apiUrl}/${resource}/${id}`, {
|
|
98
98
|
method: 'PUT',
|
|
99
99
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -104,14 +104,14 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
104
104
|
return { data: result.data || result };
|
|
105
105
|
},
|
|
106
106
|
|
|
107
|
-
async deleteOne<T>({ resource, id }: DeleteParams): Promise<DeleteResult<T>> {
|
|
107
|
+
async deleteOne<T extends BaseRecord>({ resource, id }: DeleteParams): Promise<DeleteResult<T>> {
|
|
108
108
|
const response = await httpClient(`${apiUrl}/${resource}/${id}`, { method: 'DELETE' });
|
|
109
109
|
if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
|
|
110
110
|
const result = await response.json();
|
|
111
111
|
return { data: result.data || result };
|
|
112
112
|
},
|
|
113
113
|
|
|
114
|
-
async getMany<T>({ resource, ids, meta }: GetManyParams): Promise<GetManyResult<T>> {
|
|
114
|
+
async getMany<T extends BaseRecord>({ resource, ids, meta }: GetManyParams): Promise<GetManyResult<T>> {
|
|
115
115
|
const url = new URL(`${apiUrl}/${resource}`);
|
|
116
116
|
ids.forEach((id: string | number, index: number) => url.searchParams.append(`filters[id][$in][${index}]`, String(id)));
|
|
117
117
|
if (meta?.populate) url.searchParams.append('populate', String(meta.populate));
|
|
@@ -122,7 +122,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
122
122
|
return { data: result.data || [] };
|
|
123
123
|
},
|
|
124
124
|
|
|
125
|
-
async custom<T>({ url, method, payload, headers, query }: CustomParams): Promise<CustomResult<T>> {
|
|
125
|
+
async custom<T = unknown>({ url, method, payload, headers, query }: CustomParams): Promise<CustomResult<T>> {
|
|
126
126
|
let requestUrl = url;
|
|
127
127
|
if (query) {
|
|
128
128
|
const params = new URLSearchParams();
|
|
@@ -138,7 +138,7 @@ export function createStrapiDataProvider(apiUrl: string, httpClient: typeof fetc
|
|
|
138
138
|
|
|
139
139
|
if (!response.ok) throw new Error(`Custom request failed: ${response.status}`);
|
|
140
140
|
const data = await response.json();
|
|
141
|
-
return { data: data as T };
|
|
141
|
+
return { data: data as unknown as T };
|
|
142
142
|
},
|
|
143
143
|
};
|
|
144
144
|
}
|