@m1kapp/kit 0.0.2 → 0.0.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/index.d.mts +32 -8
- package/dist/index.d.ts +32 -8
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/server.d.mts +29 -10
- package/dist/server.d.ts +29 -10
- package/dist/server.js +1 -1
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -438,8 +438,14 @@ interface UseFormSubmitOptions<T> {
|
|
|
438
438
|
onSuccess?: (data: T) => void;
|
|
439
439
|
onError?: (err: Error) => void;
|
|
440
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Submit function type:
|
|
443
|
+
* - When V is `void` (fn takes no arguments) → `submit()` needs no args
|
|
444
|
+
* - Otherwise → `submit(vars: V)` requires the arg
|
|
445
|
+
*/
|
|
446
|
+
type SubmitFn<V> = V extends void ? () => Promise<void> : (vars: V) => Promise<void>;
|
|
441
447
|
interface UseFormSubmitResult<T, V> {
|
|
442
|
-
submit:
|
|
448
|
+
submit: SubmitFn<V>;
|
|
443
449
|
loading: boolean;
|
|
444
450
|
error: Error | null;
|
|
445
451
|
data: T | undefined;
|
|
@@ -450,16 +456,21 @@ interface UseFormSubmitResult<T, V> {
|
|
|
450
456
|
* Eliminates the try/catch/finally + setState boilerplate from every form.
|
|
451
457
|
*
|
|
452
458
|
* @example
|
|
459
|
+
* // With args
|
|
453
460
|
* const { submit, loading, error } = useFormSubmit(async (url: string) => {
|
|
454
461
|
* return api.post<Site>("/api/sites", { url });
|
|
455
462
|
* }, {
|
|
456
|
-
* onSuccess: () => router.push(
|
|
463
|
+
* onSuccess: (site) => router.push(`/${site.slug}`),
|
|
457
464
|
* });
|
|
465
|
+
* <button onClick={() => submit(inputValue)}>등록</button>
|
|
458
466
|
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
467
|
+
* @example
|
|
468
|
+
* // No args (fire-and-forget style)
|
|
469
|
+
* const { submit: save, loading } = useFormSubmit(
|
|
470
|
+
* () => api.put("/api/sites/settings", config),
|
|
471
|
+
* { onSuccess: () => setSaved(true) }
|
|
472
|
+
* );
|
|
473
|
+
* <button onClick={save}>저장</button>
|
|
463
474
|
*/
|
|
464
475
|
declare function useFormSubmit<T, V = void>(fn: (vars: V) => Promise<T>, options?: UseFormSubmitOptions<T>): UseFormSubmitResult<T, V>;
|
|
465
476
|
|
|
@@ -816,7 +827,9 @@ declare class ApiError extends Error {
|
|
|
816
827
|
readonly status: number;
|
|
817
828
|
readonly statusText: string;
|
|
818
829
|
readonly body: unknown;
|
|
819
|
-
|
|
830
|
+
readonly url?: string | undefined;
|
|
831
|
+
readonly method?: string | undefined;
|
|
832
|
+
constructor(status: number, statusText: string, body: unknown, url?: string | undefined, method?: string | undefined);
|
|
820
833
|
}
|
|
821
834
|
|
|
822
835
|
interface ApiClientOptions {
|
|
@@ -824,7 +837,7 @@ interface ApiClientOptions {
|
|
|
824
837
|
headers?: Record<string, string>;
|
|
825
838
|
/** Called before every request — mutate or replace the Request */
|
|
826
839
|
onRequest?: (req: Request) => Request | void;
|
|
827
|
-
/** Called on every non-2xx response */
|
|
840
|
+
/** Called on every non-2xx response — includes url and method for debugging */
|
|
828
841
|
onError?: (err: ApiError) => void;
|
|
829
842
|
}
|
|
830
843
|
type RequestOptions = {
|
|
@@ -844,6 +857,7 @@ type ApiClient = ReturnType<typeof createApiClient>;
|
|
|
844
857
|
|
|
845
858
|
/** Manually invalidate cache entries. Pass a URL to clear one, or nothing to clear all. */
|
|
846
859
|
declare function clearFetchCache(url?: string): void;
|
|
860
|
+
type FetchStatus = "idle" | "loading" | "success" | "error";
|
|
847
861
|
interface UseFetchOptions<T> {
|
|
848
862
|
/** Skip fetching when false (default: true) */
|
|
849
863
|
enabled?: boolean;
|
|
@@ -864,6 +878,14 @@ interface UseFetchResult<T> {
|
|
|
864
878
|
data: T | undefined;
|
|
865
879
|
loading: boolean;
|
|
866
880
|
error: Error | undefined;
|
|
881
|
+
/**
|
|
882
|
+
* Lifecycle status:
|
|
883
|
+
* - `"idle"` — url is null/undefined or `enabled: false`
|
|
884
|
+
* - `"loading"` — fetch in progress
|
|
885
|
+
* - `"success"` — data loaded (note: data may be null if the API returned null)
|
|
886
|
+
* - `"error"` — last fetch failed
|
|
887
|
+
*/
|
|
888
|
+
status: FetchStatus;
|
|
867
889
|
/** Manually trigger a refetch (ignores cache) */
|
|
868
890
|
refetch: () => void;
|
|
869
891
|
}
|
|
@@ -887,6 +909,8 @@ interface UsePollingResult<T> {
|
|
|
887
909
|
isRunning: boolean;
|
|
888
910
|
stop: () => void;
|
|
889
911
|
start: () => void;
|
|
912
|
+
/** Immediately trigger a fetch without waiting for the next interval */
|
|
913
|
+
refetch: () => void;
|
|
890
914
|
}
|
|
891
915
|
declare function usePolling<T>(fetcher: () => Promise<T>, options?: UsePollingOptions<T>): UsePollingResult<T>;
|
|
892
916
|
|
package/dist/index.d.ts
CHANGED
|
@@ -438,8 +438,14 @@ interface UseFormSubmitOptions<T> {
|
|
|
438
438
|
onSuccess?: (data: T) => void;
|
|
439
439
|
onError?: (err: Error) => void;
|
|
440
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Submit function type:
|
|
443
|
+
* - When V is `void` (fn takes no arguments) → `submit()` needs no args
|
|
444
|
+
* - Otherwise → `submit(vars: V)` requires the arg
|
|
445
|
+
*/
|
|
446
|
+
type SubmitFn<V> = V extends void ? () => Promise<void> : (vars: V) => Promise<void>;
|
|
441
447
|
interface UseFormSubmitResult<T, V> {
|
|
442
|
-
submit:
|
|
448
|
+
submit: SubmitFn<V>;
|
|
443
449
|
loading: boolean;
|
|
444
450
|
error: Error | null;
|
|
445
451
|
data: T | undefined;
|
|
@@ -450,16 +456,21 @@ interface UseFormSubmitResult<T, V> {
|
|
|
450
456
|
* Eliminates the try/catch/finally + setState boilerplate from every form.
|
|
451
457
|
*
|
|
452
458
|
* @example
|
|
459
|
+
* // With args
|
|
453
460
|
* const { submit, loading, error } = useFormSubmit(async (url: string) => {
|
|
454
461
|
* return api.post<Site>("/api/sites", { url });
|
|
455
462
|
* }, {
|
|
456
|
-
* onSuccess: () => router.push(
|
|
463
|
+
* onSuccess: (site) => router.push(`/${site.slug}`),
|
|
457
464
|
* });
|
|
465
|
+
* <button onClick={() => submit(inputValue)}>등록</button>
|
|
458
466
|
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
467
|
+
* @example
|
|
468
|
+
* // No args (fire-and-forget style)
|
|
469
|
+
* const { submit: save, loading } = useFormSubmit(
|
|
470
|
+
* () => api.put("/api/sites/settings", config),
|
|
471
|
+
* { onSuccess: () => setSaved(true) }
|
|
472
|
+
* );
|
|
473
|
+
* <button onClick={save}>저장</button>
|
|
463
474
|
*/
|
|
464
475
|
declare function useFormSubmit<T, V = void>(fn: (vars: V) => Promise<T>, options?: UseFormSubmitOptions<T>): UseFormSubmitResult<T, V>;
|
|
465
476
|
|
|
@@ -816,7 +827,9 @@ declare class ApiError extends Error {
|
|
|
816
827
|
readonly status: number;
|
|
817
828
|
readonly statusText: string;
|
|
818
829
|
readonly body: unknown;
|
|
819
|
-
|
|
830
|
+
readonly url?: string | undefined;
|
|
831
|
+
readonly method?: string | undefined;
|
|
832
|
+
constructor(status: number, statusText: string, body: unknown, url?: string | undefined, method?: string | undefined);
|
|
820
833
|
}
|
|
821
834
|
|
|
822
835
|
interface ApiClientOptions {
|
|
@@ -824,7 +837,7 @@ interface ApiClientOptions {
|
|
|
824
837
|
headers?: Record<string, string>;
|
|
825
838
|
/** Called before every request — mutate or replace the Request */
|
|
826
839
|
onRequest?: (req: Request) => Request | void;
|
|
827
|
-
/** Called on every non-2xx response */
|
|
840
|
+
/** Called on every non-2xx response — includes url and method for debugging */
|
|
828
841
|
onError?: (err: ApiError) => void;
|
|
829
842
|
}
|
|
830
843
|
type RequestOptions = {
|
|
@@ -844,6 +857,7 @@ type ApiClient = ReturnType<typeof createApiClient>;
|
|
|
844
857
|
|
|
845
858
|
/** Manually invalidate cache entries. Pass a URL to clear one, or nothing to clear all. */
|
|
846
859
|
declare function clearFetchCache(url?: string): void;
|
|
860
|
+
type FetchStatus = "idle" | "loading" | "success" | "error";
|
|
847
861
|
interface UseFetchOptions<T> {
|
|
848
862
|
/** Skip fetching when false (default: true) */
|
|
849
863
|
enabled?: boolean;
|
|
@@ -864,6 +878,14 @@ interface UseFetchResult<T> {
|
|
|
864
878
|
data: T | undefined;
|
|
865
879
|
loading: boolean;
|
|
866
880
|
error: Error | undefined;
|
|
881
|
+
/**
|
|
882
|
+
* Lifecycle status:
|
|
883
|
+
* - `"idle"` — url is null/undefined or `enabled: false`
|
|
884
|
+
* - `"loading"` — fetch in progress
|
|
885
|
+
* - `"success"` — data loaded (note: data may be null if the API returned null)
|
|
886
|
+
* - `"error"` — last fetch failed
|
|
887
|
+
*/
|
|
888
|
+
status: FetchStatus;
|
|
867
889
|
/** Manually trigger a refetch (ignores cache) */
|
|
868
890
|
refetch: () => void;
|
|
869
891
|
}
|
|
@@ -887,6 +909,8 @@ interface UsePollingResult<T> {
|
|
|
887
909
|
isRunning: boolean;
|
|
888
910
|
stop: () => void;
|
|
889
911
|
start: () => void;
|
|
912
|
+
/** Immediately trigger a fetch without waiting for the next interval */
|
|
913
|
+
refetch: () => void;
|
|
890
914
|
}
|
|
891
915
|
declare function usePolling<T>(fetcher: () => Promise<T>, options?: UsePollingOptions<T>): UsePollingResult<T>;
|
|
892
916
|
|