@svadmin/elysia 0.11.0 → 0.12.7
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 +5 -5
- package/src/data-provider.ts +9 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"description": "Elysia DataProvider for svadmin — CRUD convention + InferResourceMap type utility",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@svadmin/core": "^0.
|
|
24
|
-
"elysia": ">=1.4.
|
|
23
|
+
"@svadmin/core": "^0.50.0",
|
|
24
|
+
"elysia": ">=1.4.30",
|
|
25
25
|
"@elysiajs/eden": ">=1.4.9"
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"author": "zuohuadong",
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/
|
|
31
|
+
"url": "https://github.com/vibeunion/svadmin.git",
|
|
32
32
|
"directory": "packages/elysia"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"elysia": ">=1.4.
|
|
46
|
+
"elysia": ">=1.4.30",
|
|
47
47
|
"@elysiajs/eden": ">=1.4.9"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/data-provider.ts
CHANGED
|
@@ -263,6 +263,7 @@ async function parseResponse<T>(response: Response): Promise<T> {
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
async function request<T>(url: string, headers: Record<string, string>, init?: RequestOptions, withCredentials?: boolean): Promise<T> {
|
|
266
|
+
init?.signal?.throwIfAborted();
|
|
266
267
|
const fetchInit: RequestInit = { ...init, headers: mergeHeaders(headers, init?.headers) };
|
|
267
268
|
if (withCredentials) {
|
|
268
269
|
fetchInit.credentials = 'include';
|
|
@@ -335,7 +336,7 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
335
336
|
return {
|
|
336
337
|
getApiUrl: () => apiUrl,
|
|
337
338
|
|
|
338
|
-
async getList<TData extends BaseRecord = BaseRecord>({ resource, pagination, sorters, filters, meta }: GetListParams): Promise<GetListResult<TData>> {
|
|
339
|
+
async getList<TData extends BaseRecord = BaseRecord>({ resource, pagination, sorters, filters, meta, signal }: GetListParams): Promise<GetListResult<TData>> {
|
|
339
340
|
const { current = 1, pageSize = 10 } = pagination ?? {};
|
|
340
341
|
const context: ElysiaListContext = {
|
|
341
342
|
apiUrl,
|
|
@@ -351,7 +352,7 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
351
352
|
const query = params.toString();
|
|
352
353
|
const url = query ? `${baseUrl}?${query}` : baseUrl;
|
|
353
354
|
const headers = resolveHeaders(opts);
|
|
354
|
-
const json = await request<unknown>(url, headers,
|
|
355
|
+
const json = await request<unknown>(url, headers, { signal }, withCredentials);
|
|
355
356
|
|
|
356
357
|
if (adapter?.parseListResponse) {
|
|
357
358
|
return adapter.parseListResponse<TData>(json, context);
|
|
@@ -362,9 +363,9 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
362
363
|
return defaultParseListResponse<TData>(json);
|
|
363
364
|
},
|
|
364
365
|
|
|
365
|
-
async getOne<TData extends BaseRecord = BaseRecord>({ resource, id, meta }: GetOneParams): Promise<GetOneResult<TData>> {
|
|
366
|
+
async getOne<TData extends BaseRecord = BaseRecord>({ resource, id, meta, signal }: GetOneParams): Promise<GetOneResult<TData>> {
|
|
366
367
|
const baseUrl = resolveResourceUrl(opts, resource, meta);
|
|
367
|
-
const data = await request<TData>(`${baseUrl}/${encodeIdPathSegment(id)}`, resolveHeaders(opts),
|
|
368
|
+
const data = await request<TData>(`${baseUrl}/${encodeIdPathSegment(id)}`, resolveHeaders(opts), { signal }, withCredentials);
|
|
368
369
|
return { data };
|
|
369
370
|
},
|
|
370
371
|
|
|
@@ -394,10 +395,10 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
394
395
|
return { data: data === undefined ? { id } as unknown as TData : data };
|
|
395
396
|
},
|
|
396
397
|
|
|
397
|
-
async getMany<TData extends BaseRecord = BaseRecord>({ resource, ids, meta }: GetManyParams): Promise<GetManyResult<TData>> {
|
|
398
|
+
async getMany<TData extends BaseRecord = BaseRecord>({ resource, ids, meta, signal }: GetManyParams): Promise<GetManyResult<TData>> {
|
|
398
399
|
const baseUrl = resolveResourceUrl(opts, resource, meta);
|
|
399
400
|
const params = ids.map(id => `id=${encodeURIComponent(String(id))}`).join('&');
|
|
400
|
-
const data = await request<TData[]>(`${baseUrl}?${params}`, resolveHeaders(opts),
|
|
401
|
+
const data = await request<TData[]>(`${baseUrl}?${params}`, resolveHeaders(opts), { signal }, withCredentials);
|
|
401
402
|
return { data };
|
|
402
403
|
},
|
|
403
404
|
|
|
@@ -439,7 +440,7 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
439
440
|
return { data: results };
|
|
440
441
|
},
|
|
441
442
|
|
|
442
|
-
async custom<TData = unknown, TVariables = unknown>({ url, method, payload, query, headers, sorters, filters }: CustomParams<TVariables>): Promise<CustomResult<TData>> {
|
|
443
|
+
async custom<TData = unknown, TVariables = unknown>({ url, method, payload, query, headers, sorters, filters, signal }: CustomParams<TVariables>): Promise<CustomResult<TData>> {
|
|
443
444
|
const requestUrl = buildCustomUrl(url, apiUrl, query, sorters, filters);
|
|
444
445
|
const sameOrigin = isSameOrigin(apiUrl, requestUrl);
|
|
445
446
|
const providerHeaders = resolveHeaders(opts);
|
|
@@ -451,6 +452,7 @@ export function createElysiaDataProvider(opts: ElysiaDataProviderOptions): DataP
|
|
|
451
452
|
headers,
|
|
452
453
|
);
|
|
453
454
|
const data = await request<TData>(requestUrl, requestHeaders, {
|
|
455
|
+
signal,
|
|
454
456
|
method: method.toUpperCase(),
|
|
455
457
|
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
456
458
|
}, withCredentials && sameOrigin);
|