@next-feature/client 0.1.3-0 → 0.1.3-1
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/index.js +1 -1
- package/lib/actions/with-api.d.ts +1 -0
- package/lib/client.d.ts +1 -1
- package/lib/types/index.d.ts +2 -1
- package/package.json +1 -1
- package/server.js +20 -13
package/index.js
CHANGED
|
@@ -4,4 +4,5 @@ interface WithApiOptions<T> {
|
|
|
4
4
|
successMessage?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function withApi<F extends (...args: any[]) => Promise<any>>(fn: F, options?: WithApiOptions<Awaited<ReturnType<F>>>): (...args: Parameters<F>) => Promise<ApiResponse<Awaited<ReturnType<F>>>>;
|
|
7
|
+
export declare function withForm<State>(fn: (formData: FormData) => Promise<ApiResponse<State>>): (prevState: Awaited<ApiResponse<State>>, formData: FormData) => Promise<ApiResponse<State>>;
|
|
7
8
|
export {};
|
package/lib/client.d.ts
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpStatusCode } from 'axios';
|
|
2
|
+
import { ApiError } from '../error';
|
|
2
3
|
/**
|
|
3
4
|
* [api-response]
|
|
4
5
|
* next-feature@0.0.11-beta
|
|
@@ -7,7 +8,7 @@ import { HttpStatusCode } from 'axios';
|
|
|
7
8
|
export interface ApiResponse<Response> {
|
|
8
9
|
success?: boolean;
|
|
9
10
|
message?: string;
|
|
10
|
-
error?:
|
|
11
|
+
error?: ApiError;
|
|
11
12
|
data: Response;
|
|
12
13
|
}
|
|
13
14
|
/**
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import { A as o } from "./error-DRDfrCQN.js";
|
|
2
|
-
function u(
|
|
3
|
-
const
|
|
2
|
+
function u(e, r) {
|
|
3
|
+
const a = {
|
|
4
4
|
fallbackData: {},
|
|
5
5
|
successMessage: "success",
|
|
6
|
-
...
|
|
6
|
+
...r
|
|
7
7
|
};
|
|
8
|
-
return async (...
|
|
8
|
+
return async (...s) => {
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
10
|
+
const t = await e(...s);
|
|
11
11
|
return {
|
|
12
12
|
success: !0,
|
|
13
|
-
message:
|
|
14
|
-
data:
|
|
13
|
+
message: a.successMessage,
|
|
14
|
+
data: t
|
|
15
15
|
};
|
|
16
|
-
} catch (
|
|
17
|
-
const
|
|
16
|
+
} catch (t) {
|
|
17
|
+
const c = o.of(t);
|
|
18
18
|
return {
|
|
19
|
-
data:
|
|
20
|
-
error:
|
|
21
|
-
message:
|
|
19
|
+
data: a.fallbackData,
|
|
20
|
+
error: c,
|
|
21
|
+
message: c.message,
|
|
22
22
|
success: !1
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
function i(e) {
|
|
28
|
+
return async (r, a) => {
|
|
29
|
+
const s = await e(a);
|
|
30
|
+
return s.error || !s.success ? { ...s, data: r.data } : s;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
27
33
|
export {
|
|
28
|
-
u as withApi
|
|
34
|
+
u as withApi,
|
|
35
|
+
i as withForm
|
|
29
36
|
};
|