@citruslime/vue-utils 3.0.0-beta.2 → 3.0.0-beta.3

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/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,25 @@
1
+ export declare const requestTypes: readonly ["GET", "POST", "PUT", "DELETE"];
2
+ export interface Endpoint {
3
+ url: string;
4
+ type: typeof requestTypes[number];
5
+ headers: () => HeadersInit;
6
+ hasBody: boolean;
7
+ options: RequestInit;
8
+ }
9
+ /**
10
+ * Creates an endpoint object, using the provided values.
11
+ *
12
+ * @param url The url fragment for the request.
13
+ * @param type The type of HTTP request to make.
14
+ * @param headers The headers this request will use.
15
+ * @param hasBody Determines whether or not an endpoint should have a body.
16
+ * @param options The options to pass to the useFetch composable.
17
+ * @returns The created Endpoint object.
18
+ */
19
+ export declare function createEndpoint(url: string, type: typeof requestTypes[number], headers?: (() => HeadersInit) | null, hasBody?: boolean | null, options?: RequestInit | null): Endpoint;
20
+ /**
21
+ * Gets a set of default headers.
22
+ *
23
+ * @returns A set of default headers.
24
+ */
25
+ export declare function getDefaultHeaders(): HeadersInit;
@@ -0,0 +1,20 @@
1
+ import { useFetch } from '@vueuse/core';
2
+ import { type Endpoint } from './endpoints';
3
+ export type ApiRequest<TResponseModel> = ReturnType<typeof useFetch<TResponseModel>>;
4
+ /**
5
+ * Composable that constructs an API object containing requests defined by the endpoints object.
6
+ *
7
+ * @param endpoints The endpoints provided to build with the factory.
8
+ * @param handleFetchErrorResponse The error handler for the api factory.
9
+ * @param prefix The prefix to append to the url (defaults to '/api/').
10
+ * @param handleAfterFetchResponse The optional after fetch response handler for the api factory.
11
+ * @returns An API object containing request methods.
12
+ */
13
+ export declare function useApi<TEndpoint extends Record<keyof TEndpoint, Endpoint>>(endpoints: TEndpoint, handleFetchErrorResponse: (context: {
14
+ data: unknown;
15
+ response: Response | null;
16
+ error: unknown;
17
+ }) => void, prefix?: string, handleAfterFetchResponse?: (context: {
18
+ data: unknown;
19
+ response: Response;
20
+ }, endPoint: Endpoint) => void): Record<keyof TEndpoint, <TResponseModel>(...values: unknown[]) => ApiRequest<TResponseModel>>;
@@ -0,0 +1,8 @@
1
+ import type { DeepReadonly } from 'vue';
2
+ /**
3
+ * Deep copies a provided value.
4
+ *
5
+ * @param value The value to copy.
6
+ * @returns A copy of the object.
7
+ */
8
+ export declare function copy<T>(value: T | Readonly<T> | DeepReadonly<T>): T;
@@ -0,0 +1,3 @@
1
+ export * from './api/endpoints';
2
+ export * from './api/factory';
3
+ export * from './copy';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/vue-utils",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.3",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",
@@ -36,12 +36,12 @@
36
36
  "vue-tsc": "^3.2.5"
37
37
  },
38
38
  "dependencies": {
39
- "@citruslime/utils": "3.0.0-beta.2",
39
+ "@citruslime/utils": "3.0.0-beta.3",
40
40
  "@vueuse/core": "^14.2.1",
41
41
  "vue": "^3.5.19"
42
42
  },
43
43
  "scripts": {
44
- "build": "run-p build-only build-types",
44
+ "build": "run-s build-only build-types",
45
45
  "build-only": "vite build",
46
46
  "build-types": "vue-tsc -p ./tsconfig.d.json",
47
47
  "lint": "eslint . --fix --cache"