enlace 0.0.0-alpha.4 → 0.0.1-beta.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/dist/index.d.mts +82 -106
- package/dist/index.d.ts +82 -106
- package/dist/index.js +323 -91
- package/dist/index.mjs +326 -81
- package/dist/next/hook/index.d.mts +124 -0
- package/dist/next/hook/index.d.ts +124 -0
- package/dist/next/hook/index.js +443 -0
- package/dist/next/hook/index.mjs +444 -0
- package/dist/next/index.d.mts +64 -111
- package/dist/next/index.d.ts +64 -111
- package/dist/next/index.js +42 -122
- package/dist/next/index.mjs +45 -108
- package/package.json +15 -24
package/dist/index.d.mts
CHANGED
|
@@ -1,121 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type EnlaceOptions = Omit<RequestInit, "method" | "body">;
|
|
15
|
-
type FetchExecutor<TOptions = EnlaceOptions, TRequestOptions = RequestOptions<unknown>> = <TData, TError>(baseUrl: string, path: string[], method: HttpMethod, defaultOptions: TOptions, requestOptions?: TRequestOptions) => Promise<EnlaceResponse<TData, TError>>;
|
|
16
|
-
type RequestOptions<TBody = never> = {
|
|
17
|
-
body?: TBody;
|
|
18
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
19
|
-
headers?: HeadersInit;
|
|
20
|
-
cache?: RequestCache;
|
|
1
|
+
import { WildcardClient, EnlaceClient, EnlaceResponse, EnlaceOptions } from 'enlace-core';
|
|
2
|
+
export * from 'enlace-core';
|
|
3
|
+
|
|
4
|
+
/** Per-request options for React hooks */
|
|
5
|
+
type ReactRequestOptionsBase = {
|
|
6
|
+
/**
|
|
7
|
+
* Cache tags for caching (GET requests only)
|
|
8
|
+
* This will auto generate tags from the URL path if not provided and autoGenerateTags is enabled.
|
|
9
|
+
* But can be manually specified to override auto-generation.
|
|
10
|
+
* */
|
|
11
|
+
tags?: string[];
|
|
12
|
+
/** Tags to invalidate after mutation (triggers refetch in matching queries) */
|
|
13
|
+
revalidateTags?: string[];
|
|
21
14
|
};
|
|
22
|
-
type
|
|
15
|
+
type ApiClient<TSchema, TOptions = ReactRequestOptionsBase> = unknown extends TSchema ? WildcardClient<TOptions> : EnlaceClient<TSchema, TOptions>;
|
|
16
|
+
type QueryFn<TSchema, TData, TError, TOptions = ReactRequestOptionsBase> = (api: ApiClient<TSchema, TOptions>) => Promise<EnlaceResponse<TData, TError>>;
|
|
17
|
+
type SelectorFn<TSchema, TMethod, TOptions = ReactRequestOptionsBase> = (api: ApiClient<TSchema, TOptions>) => TMethod;
|
|
18
|
+
type HookState = {
|
|
19
|
+
loading: boolean;
|
|
20
|
+
fetching: boolean;
|
|
21
|
+
ok: boolean | undefined;
|
|
23
22
|
data: unknown;
|
|
24
23
|
error: unknown;
|
|
25
|
-
body?: unknown;
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type Endpoint<TData, TError, TBody = never> = [TBody] extends [never] ? {
|
|
43
|
-
data: TData;
|
|
44
|
-
error: TError;
|
|
45
|
-
} : {
|
|
25
|
+
type TrackedCall = {
|
|
26
|
+
path: string[];
|
|
27
|
+
method: string;
|
|
28
|
+
options: unknown;
|
|
29
|
+
};
|
|
30
|
+
declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete"];
|
|
31
|
+
type ExtractData<T> = T extends (...args: any[]) => Promise<EnlaceResponse<infer D, unknown>> ? D : never;
|
|
32
|
+
type ExtractError<T> = T extends (...args: any[]) => Promise<EnlaceResponse<unknown, infer E>> ? E : never;
|
|
33
|
+
/** Discriminated union for hook response state - enables type narrowing on ok check */
|
|
34
|
+
type HookResponseState<TData, TError> = {
|
|
35
|
+
ok: undefined;
|
|
36
|
+
data: undefined;
|
|
37
|
+
error: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
ok: true;
|
|
46
40
|
data: TData;
|
|
41
|
+
error: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
data: undefined;
|
|
47
45
|
error: TError;
|
|
48
|
-
body: TBody;
|
|
49
|
-
};
|
|
50
|
-
type ExtractMethodDef<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
51
|
-
[K in TMethod]: infer M;
|
|
52
|
-
} ? M extends MethodDefinition ? M : never : never;
|
|
53
|
-
type ExtractData<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
54
|
-
data: infer D;
|
|
55
|
-
} ? D : never;
|
|
56
|
-
type ExtractError<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
57
|
-
error: infer E;
|
|
58
|
-
} ? E : never;
|
|
59
|
-
type ExtractBody<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
60
|
-
body: infer B;
|
|
61
|
-
} ? B : never;
|
|
62
|
-
type HasMethod<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
63
|
-
[K in TMethod]: MethodDefinition;
|
|
64
|
-
} ? true : false;
|
|
65
|
-
type MethodFn<TSchema, TMethod extends SchemaMethod, TRequestOptionsBase = object> = HasMethod<TSchema, TMethod> extends true ? ExtractBody<TSchema, TMethod> extends never ? (options?: RequestOptions<never> & TRequestOptionsBase) => Promise<EnlaceResponse<ExtractData<TSchema, TMethod>, ExtractError<TSchema, TMethod>>> : (options: RequestOptions<ExtractBody<TSchema, TMethod>> & TRequestOptionsBase) => Promise<EnlaceResponse<ExtractData<TSchema, TMethod>, ExtractError<TSchema, TMethod>>> : never;
|
|
66
|
-
type IsSpecialKey<K> = K extends SchemaMethod | "_" ? true : false;
|
|
67
|
-
type StaticPathKeys<TSchema> = {
|
|
68
|
-
[K in keyof TSchema as IsSpecialKey<K> extends true ? never : K extends string ? K : never]: TSchema[K];
|
|
69
46
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
/** Result when hook is called with query function (auto-fetch mode) */
|
|
48
|
+
type UseEnlaceQueryResult<TData, TError> = {
|
|
49
|
+
loading: boolean;
|
|
50
|
+
fetching: boolean;
|
|
51
|
+
} & HookResponseState<TData, TError>;
|
|
52
|
+
/** Result when hook is called with method selector (trigger mode) */
|
|
53
|
+
type UseEnlaceSelectorResult<TMethod> = {
|
|
54
|
+
trigger: TMethod;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
fetching: boolean;
|
|
57
|
+
} & HookResponseState<ExtractData<TMethod>, ExtractError<TMethod>>;
|
|
58
|
+
|
|
59
|
+
type EnlaceHookOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* Auto-generate cache tags from URL path for GET requests.
|
|
62
|
+
* e.g., `/posts/1` generates tags `['posts', 'posts/1']`
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
autoGenerateTags?: boolean;
|
|
66
|
+
/** Auto-revalidate generated tags after successful mutations. @default true */
|
|
67
|
+
autoRevalidateTags?: boolean;
|
|
68
|
+
/** Time in ms before cached data is considered stale. @default 0 (always stale) */
|
|
69
|
+
staleTime?: number;
|
|
84
70
|
};
|
|
85
|
-
type
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
type EnlaceHook<TSchema> = {
|
|
72
|
+
<TMethod extends (...args: any[]) => Promise<EnlaceResponse<unknown, unknown>>>(selector: SelectorFn<TSchema, TMethod>): UseEnlaceSelectorResult<TMethod>;
|
|
73
|
+
<TData, TError>(queryFn: QueryFn<TSchema, TData, TError>): UseEnlaceQueryResult<TData, TError>;
|
|
88
74
|
};
|
|
89
|
-
type WildcardMethodFn<TRequestOptionsBase = object> = (options?: RequestOptions<unknown> & TRequestOptionsBase) => Promise<EnlaceResponse<unknown, unknown>>;
|
|
90
75
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
type WildcardClient<TRequestOptionsBase = object> = {
|
|
95
|
-
get: WildcardMethodFn<TRequestOptionsBase>;
|
|
96
|
-
post: WildcardMethodFn<TRequestOptionsBase>;
|
|
97
|
-
put: WildcardMethodFn<TRequestOptionsBase>;
|
|
98
|
-
patch: WildcardMethodFn<TRequestOptionsBase>;
|
|
99
|
-
delete: WildcardMethodFn<TRequestOptionsBase>;
|
|
100
|
-
} & {
|
|
101
|
-
[key: string]: WildcardClient<TRequestOptionsBase>;
|
|
102
|
-
[key: number]: WildcardClient<TRequestOptionsBase>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
declare function createProxyHandler<TSchema extends object, TOptions = EnlaceOptions>(baseUrl: string, defaultOptions: TOptions, path?: string[], fetchExecutor?: FetchExecutor<TOptions, RequestOptions<unknown>>): TSchema;
|
|
106
|
-
|
|
107
|
-
declare function executeFetch<TData, TError>(baseUrl: string, path: string[], method: HttpMethod, defaultOptions: EnlaceOptions, requestOptions?: RequestOptions<unknown>): Promise<EnlaceResponse<TData, TError>>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Creates an API client.
|
|
76
|
+
* Creates a React hook for making API calls.
|
|
77
|
+
* Called at module level to create a reusable hook.
|
|
111
78
|
*
|
|
112
79
|
* @example
|
|
113
|
-
*
|
|
114
|
-
* const api = createEnlace<MyApi>('https://api.example.com');
|
|
80
|
+
* const useAPI = createEnlaceHook<ApiSchema>('https://api.com');
|
|
115
81
|
*
|
|
116
|
-
* //
|
|
117
|
-
* const
|
|
82
|
+
* // Query mode - auto-fetch (auto-tracks changes, no deps array needed)
|
|
83
|
+
* const { loading, data, error } = useAPI((api) => api.posts.get({ query: { userId } }));
|
|
84
|
+
*
|
|
85
|
+
* // Selector mode - typed trigger for lazy calls
|
|
86
|
+
* const { trigger, loading, data, error } = useAPI((api) => api.posts.delete);
|
|
87
|
+
* onClick={() => trigger({ body: { id: 1 } })}
|
|
118
88
|
*/
|
|
119
|
-
declare function
|
|
89
|
+
declare function createEnlaceHook<TSchema = unknown>(baseUrl: string, defaultOptions?: EnlaceOptions, hookOptions?: EnlaceHookOptions): EnlaceHook<TSchema>;
|
|
90
|
+
|
|
91
|
+
type Listener = (tags: string[]) => void;
|
|
92
|
+
declare function invalidateTags(tags: string[]): void;
|
|
93
|
+
declare function onRevalidate(callback: Listener): () => void;
|
|
94
|
+
|
|
95
|
+
declare function clearCache(key?: string): void;
|
|
120
96
|
|
|
121
|
-
export { type
|
|
97
|
+
export { type ApiClient, type EnlaceHookOptions, HTTP_METHODS, type HookState, type QueryFn, type ReactRequestOptionsBase, type SelectorFn, type TrackedCall, type UseEnlaceQueryResult, type UseEnlaceSelectorResult, clearCache, createEnlaceHook, invalidateTags, onRevalidate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,121 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type EnlaceOptions = Omit<RequestInit, "method" | "body">;
|
|
15
|
-
type FetchExecutor<TOptions = EnlaceOptions, TRequestOptions = RequestOptions<unknown>> = <TData, TError>(baseUrl: string, path: string[], method: HttpMethod, defaultOptions: TOptions, requestOptions?: TRequestOptions) => Promise<EnlaceResponse<TData, TError>>;
|
|
16
|
-
type RequestOptions<TBody = never> = {
|
|
17
|
-
body?: TBody;
|
|
18
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
19
|
-
headers?: HeadersInit;
|
|
20
|
-
cache?: RequestCache;
|
|
1
|
+
import { WildcardClient, EnlaceClient, EnlaceResponse, EnlaceOptions } from 'enlace-core';
|
|
2
|
+
export * from 'enlace-core';
|
|
3
|
+
|
|
4
|
+
/** Per-request options for React hooks */
|
|
5
|
+
type ReactRequestOptionsBase = {
|
|
6
|
+
/**
|
|
7
|
+
* Cache tags for caching (GET requests only)
|
|
8
|
+
* This will auto generate tags from the URL path if not provided and autoGenerateTags is enabled.
|
|
9
|
+
* But can be manually specified to override auto-generation.
|
|
10
|
+
* */
|
|
11
|
+
tags?: string[];
|
|
12
|
+
/** Tags to invalidate after mutation (triggers refetch in matching queries) */
|
|
13
|
+
revalidateTags?: string[];
|
|
21
14
|
};
|
|
22
|
-
type
|
|
15
|
+
type ApiClient<TSchema, TOptions = ReactRequestOptionsBase> = unknown extends TSchema ? WildcardClient<TOptions> : EnlaceClient<TSchema, TOptions>;
|
|
16
|
+
type QueryFn<TSchema, TData, TError, TOptions = ReactRequestOptionsBase> = (api: ApiClient<TSchema, TOptions>) => Promise<EnlaceResponse<TData, TError>>;
|
|
17
|
+
type SelectorFn<TSchema, TMethod, TOptions = ReactRequestOptionsBase> = (api: ApiClient<TSchema, TOptions>) => TMethod;
|
|
18
|
+
type HookState = {
|
|
19
|
+
loading: boolean;
|
|
20
|
+
fetching: boolean;
|
|
21
|
+
ok: boolean | undefined;
|
|
23
22
|
data: unknown;
|
|
24
23
|
error: unknown;
|
|
25
|
-
body?: unknown;
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type Endpoint<TData, TError, TBody = never> = [TBody] extends [never] ? {
|
|
43
|
-
data: TData;
|
|
44
|
-
error: TError;
|
|
45
|
-
} : {
|
|
25
|
+
type TrackedCall = {
|
|
26
|
+
path: string[];
|
|
27
|
+
method: string;
|
|
28
|
+
options: unknown;
|
|
29
|
+
};
|
|
30
|
+
declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete"];
|
|
31
|
+
type ExtractData<T> = T extends (...args: any[]) => Promise<EnlaceResponse<infer D, unknown>> ? D : never;
|
|
32
|
+
type ExtractError<T> = T extends (...args: any[]) => Promise<EnlaceResponse<unknown, infer E>> ? E : never;
|
|
33
|
+
/** Discriminated union for hook response state - enables type narrowing on ok check */
|
|
34
|
+
type HookResponseState<TData, TError> = {
|
|
35
|
+
ok: undefined;
|
|
36
|
+
data: undefined;
|
|
37
|
+
error: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
ok: true;
|
|
46
40
|
data: TData;
|
|
41
|
+
error: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
data: undefined;
|
|
47
45
|
error: TError;
|
|
48
|
-
body: TBody;
|
|
49
|
-
};
|
|
50
|
-
type ExtractMethodDef<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
51
|
-
[K in TMethod]: infer M;
|
|
52
|
-
} ? M extends MethodDefinition ? M : never : never;
|
|
53
|
-
type ExtractData<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
54
|
-
data: infer D;
|
|
55
|
-
} ? D : never;
|
|
56
|
-
type ExtractError<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
57
|
-
error: infer E;
|
|
58
|
-
} ? E : never;
|
|
59
|
-
type ExtractBody<TSchema, TMethod extends SchemaMethod> = ExtractMethodDef<TSchema, TMethod> extends {
|
|
60
|
-
body: infer B;
|
|
61
|
-
} ? B : never;
|
|
62
|
-
type HasMethod<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
63
|
-
[K in TMethod]: MethodDefinition;
|
|
64
|
-
} ? true : false;
|
|
65
|
-
type MethodFn<TSchema, TMethod extends SchemaMethod, TRequestOptionsBase = object> = HasMethod<TSchema, TMethod> extends true ? ExtractBody<TSchema, TMethod> extends never ? (options?: RequestOptions<never> & TRequestOptionsBase) => Promise<EnlaceResponse<ExtractData<TSchema, TMethod>, ExtractError<TSchema, TMethod>>> : (options: RequestOptions<ExtractBody<TSchema, TMethod>> & TRequestOptionsBase) => Promise<EnlaceResponse<ExtractData<TSchema, TMethod>, ExtractError<TSchema, TMethod>>> : never;
|
|
66
|
-
type IsSpecialKey<K> = K extends SchemaMethod | "_" ? true : false;
|
|
67
|
-
type StaticPathKeys<TSchema> = {
|
|
68
|
-
[K in keyof TSchema as IsSpecialKey<K> extends true ? never : K extends string ? K : never]: TSchema[K];
|
|
69
46
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
/** Result when hook is called with query function (auto-fetch mode) */
|
|
48
|
+
type UseEnlaceQueryResult<TData, TError> = {
|
|
49
|
+
loading: boolean;
|
|
50
|
+
fetching: boolean;
|
|
51
|
+
} & HookResponseState<TData, TError>;
|
|
52
|
+
/** Result when hook is called with method selector (trigger mode) */
|
|
53
|
+
type UseEnlaceSelectorResult<TMethod> = {
|
|
54
|
+
trigger: TMethod;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
fetching: boolean;
|
|
57
|
+
} & HookResponseState<ExtractData<TMethod>, ExtractError<TMethod>>;
|
|
58
|
+
|
|
59
|
+
type EnlaceHookOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* Auto-generate cache tags from URL path for GET requests.
|
|
62
|
+
* e.g., `/posts/1` generates tags `['posts', 'posts/1']`
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
autoGenerateTags?: boolean;
|
|
66
|
+
/** Auto-revalidate generated tags after successful mutations. @default true */
|
|
67
|
+
autoRevalidateTags?: boolean;
|
|
68
|
+
/** Time in ms before cached data is considered stale. @default 0 (always stale) */
|
|
69
|
+
staleTime?: number;
|
|
84
70
|
};
|
|
85
|
-
type
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
type EnlaceHook<TSchema> = {
|
|
72
|
+
<TMethod extends (...args: any[]) => Promise<EnlaceResponse<unknown, unknown>>>(selector: SelectorFn<TSchema, TMethod>): UseEnlaceSelectorResult<TMethod>;
|
|
73
|
+
<TData, TError>(queryFn: QueryFn<TSchema, TData, TError>): UseEnlaceQueryResult<TData, TError>;
|
|
88
74
|
};
|
|
89
|
-
type WildcardMethodFn<TRequestOptionsBase = object> = (options?: RequestOptions<unknown> & TRequestOptionsBase) => Promise<EnlaceResponse<unknown, unknown>>;
|
|
90
75
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
type WildcardClient<TRequestOptionsBase = object> = {
|
|
95
|
-
get: WildcardMethodFn<TRequestOptionsBase>;
|
|
96
|
-
post: WildcardMethodFn<TRequestOptionsBase>;
|
|
97
|
-
put: WildcardMethodFn<TRequestOptionsBase>;
|
|
98
|
-
patch: WildcardMethodFn<TRequestOptionsBase>;
|
|
99
|
-
delete: WildcardMethodFn<TRequestOptionsBase>;
|
|
100
|
-
} & {
|
|
101
|
-
[key: string]: WildcardClient<TRequestOptionsBase>;
|
|
102
|
-
[key: number]: WildcardClient<TRequestOptionsBase>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
declare function createProxyHandler<TSchema extends object, TOptions = EnlaceOptions>(baseUrl: string, defaultOptions: TOptions, path?: string[], fetchExecutor?: FetchExecutor<TOptions, RequestOptions<unknown>>): TSchema;
|
|
106
|
-
|
|
107
|
-
declare function executeFetch<TData, TError>(baseUrl: string, path: string[], method: HttpMethod, defaultOptions: EnlaceOptions, requestOptions?: RequestOptions<unknown>): Promise<EnlaceResponse<TData, TError>>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Creates an API client.
|
|
76
|
+
* Creates a React hook for making API calls.
|
|
77
|
+
* Called at module level to create a reusable hook.
|
|
111
78
|
*
|
|
112
79
|
* @example
|
|
113
|
-
*
|
|
114
|
-
* const api = createEnlace<MyApi>('https://api.example.com');
|
|
80
|
+
* const useAPI = createEnlaceHook<ApiSchema>('https://api.com');
|
|
115
81
|
*
|
|
116
|
-
* //
|
|
117
|
-
* const
|
|
82
|
+
* // Query mode - auto-fetch (auto-tracks changes, no deps array needed)
|
|
83
|
+
* const { loading, data, error } = useAPI((api) => api.posts.get({ query: { userId } }));
|
|
84
|
+
*
|
|
85
|
+
* // Selector mode - typed trigger for lazy calls
|
|
86
|
+
* const { trigger, loading, data, error } = useAPI((api) => api.posts.delete);
|
|
87
|
+
* onClick={() => trigger({ body: { id: 1 } })}
|
|
118
88
|
*/
|
|
119
|
-
declare function
|
|
89
|
+
declare function createEnlaceHook<TSchema = unknown>(baseUrl: string, defaultOptions?: EnlaceOptions, hookOptions?: EnlaceHookOptions): EnlaceHook<TSchema>;
|
|
90
|
+
|
|
91
|
+
type Listener = (tags: string[]) => void;
|
|
92
|
+
declare function invalidateTags(tags: string[]): void;
|
|
93
|
+
declare function onRevalidate(callback: Listener): () => void;
|
|
94
|
+
|
|
95
|
+
declare function clearCache(key?: string): void;
|
|
120
96
|
|
|
121
|
-
export { type
|
|
97
|
+
export { type ApiClient, type EnlaceHookOptions, HTTP_METHODS, type HookState, type QueryFn, type ReactRequestOptionsBase, type SelectorFn, type TrackedCall, type UseEnlaceQueryResult, type UseEnlaceSelectorResult, clearCache, createEnlaceHook, invalidateTags, onRevalidate };
|