@tmlmobilidade/utils 20260803.15.9 → 20260805.229.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/dist/http/index.d.ts +0 -1
- package/dist/http/index.js +0 -1
- package/dist/http/swr.d.ts +3 -3
- package/dist/http/swr.js +2 -2
- package/dist/validate-query-params.d.ts +6 -0
- package/dist/validate-query-params.js +11 -1
- package/package.json +1 -1
- package/dist/http/http.d.ts +0 -17
- package/dist/http/http.js +0 -18
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
package/dist/http/swr.d.ts
CHANGED
|
@@ -33,9 +33,9 @@ export declare function swrFetcher<T>(urlOrOptions: string | SwrFetcherOptions):
|
|
|
33
33
|
* Fetches data from a URL using the SWR fetcher function.
|
|
34
34
|
* @param urlOrOptions The URL to fetch from or the options object.
|
|
35
35
|
* @returns Promise resolving to the fetched data
|
|
36
|
-
* @
|
|
36
|
+
* @example
|
|
37
37
|
* ```ts
|
|
38
|
-
* const data = await
|
|
38
|
+
* const data = await unauthenticatedSwrFetcher('/api/users/123');
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export declare function unauthenticatedSwrFetcher<T>(url: string):
|
|
41
|
+
export declare function unauthenticatedSwrFetcher<T>(url: string): ReturnType<typeof swrFetcher<T>>;
|
package/dist/http/swr.js
CHANGED
|
@@ -43,9 +43,9 @@ export async function swrFetcher(urlOrOptions) {
|
|
|
43
43
|
* Fetches data from a URL using the SWR fetcher function.
|
|
44
44
|
* @param urlOrOptions The URL to fetch from or the options object.
|
|
45
45
|
* @returns Promise resolving to the fetched data
|
|
46
|
-
* @
|
|
46
|
+
* @example
|
|
47
47
|
* ```ts
|
|
48
|
-
* const data = await
|
|
48
|
+
* const data = await unauthenticatedSwrFetcher('/api/users/123');
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
export async function unauthenticatedSwrFetcher(url) {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the query params against the schema
|
|
4
|
+
* @param queryParams - The query params to validate
|
|
5
|
+
* @param schema - The schema to validate the query params against
|
|
6
|
+
* @returns The validated query params
|
|
7
|
+
*/
|
|
2
8
|
export declare function validateQueryParams<T>(queryParams: unknown, schema: z.ZodTypeAny): T;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/* * */
|
|
2
|
+
import { HTTP_STATUS, HttpException } from '@tmlmobilidade/consts';
|
|
3
|
+
/* * */
|
|
4
|
+
/**
|
|
5
|
+
* Validates the query params against the schema
|
|
6
|
+
* @param queryParams - The query params to validate
|
|
7
|
+
* @param schema - The schema to validate the query params against
|
|
8
|
+
* @returns The validated query params
|
|
9
|
+
*/
|
|
2
10
|
export function validateQueryParams(queryParams, schema) {
|
|
11
|
+
//
|
|
12
|
+
// Validate the query params
|
|
3
13
|
const result = schema.safeParse(queryParams);
|
|
4
14
|
if (!result.success) {
|
|
5
15
|
throw new HttpException(HTTP_STATUS.BAD_REQUEST, result.error.errors.map(error => error.message).join(', '));
|
package/package.json
CHANGED
package/dist/http/http.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type WithPagination<T> = T & {
|
|
2
|
-
pagination: {
|
|
3
|
-
limit: number;
|
|
4
|
-
page: number;
|
|
5
|
-
total: number;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Fetches data from a URL using the SWR fetcher function without authentication.
|
|
10
|
-
* @param url - The URL to fetch from
|
|
11
|
-
* @returns Promise resolving to the fetched data
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const data = await standardSwrFetcher('/api/users/123');
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare const standardSwrFetcher: <T>(url: string) => Promise<T>;
|
package/dist/http/http.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
import { HttpException } from '@tmlmobilidade/consts';
|
|
3
|
-
/**
|
|
4
|
-
* Fetches data from a URL using the SWR fetcher function without authentication.
|
|
5
|
-
* @param url - The URL to fetch from
|
|
6
|
-
* @returns Promise resolving to the fetched data
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const data = await standardSwrFetcher('/api/users/123');
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export const standardSwrFetcher = async (url) => {
|
|
13
|
-
const res = await fetch(url, { credentials: 'omit' });
|
|
14
|
-
if (!res.ok) {
|
|
15
|
-
throw new HttpException(res.status, res.statusText);
|
|
16
|
-
}
|
|
17
|
-
return res.json();
|
|
18
|
-
};
|