api-core-lib 12.0.87 → 12.0.89
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/{apiModule.types-Bn0tJF7b.d.cts → apiModule.types-CZX-M2Ub.d.cts} +3 -3
- package/dist/{apiModule.types-Bn0tJF7b.d.ts → apiModule.types-CZX-M2Ub.d.ts} +3 -3
- package/dist/cli.cjs +102 -9
- package/dist/client.cjs +23 -1
- package/dist/client.d.cts +32 -5
- package/dist/client.d.ts +32 -5
- package/dist/client.js +22 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/{useApiRecord.types-NZtPRga3.d.cts → useApiRecord.types-Cq9AlZX2.d.cts} +1 -1
- package/dist/{useApiRecord.types-CWhwCAB6.d.ts → useApiRecord.types-Cye9a7zh.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosProgressEvent, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import
|
|
2
|
+
import react__default from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* يمثل معلومات الترقيم (Pagination) التي قد تعود من ה-API.
|
|
@@ -156,7 +156,7 @@ interface UseApiQuery {
|
|
|
156
156
|
/** The current query options state. */
|
|
157
157
|
options: QueryOptions;
|
|
158
158
|
/** A function to set the entire query options object at once. */
|
|
159
|
-
setOptions:
|
|
159
|
+
setOptions: react__default.Dispatch<react__default.SetStateAction<QueryOptions>>;
|
|
160
160
|
/** Sets the current page number. */
|
|
161
161
|
setPage: (page: number) => void;
|
|
162
162
|
/** Sets the number of items per page and resets to the first page. */
|
|
@@ -287,4 +287,4 @@ type ActionMethods<TAction extends ActionConfigModule<any, any>> = {
|
|
|
287
287
|
}) => void;
|
|
288
288
|
};
|
|
289
289
|
|
|
290
|
-
export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e,
|
|
290
|
+
export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ActionsWithQuery as f, ApiClientConfig as g, ActionOptions as h, ActionStateModule as i, ApiError as j, TokenManager as k, MiddlewareContext as l, Middleware as m, RefreshTokenConfig as n, ActionConfig as o, UseApiState as p, ActionState as q, ExecuteOptions as r, ActionMethods as s, t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosProgressEvent, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import
|
|
2
|
+
import react__default from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* يمثل معلومات الترقيم (Pagination) التي قد تعود من ה-API.
|
|
@@ -156,7 +156,7 @@ interface UseApiQuery {
|
|
|
156
156
|
/** The current query options state. */
|
|
157
157
|
options: QueryOptions;
|
|
158
158
|
/** A function to set the entire query options object at once. */
|
|
159
|
-
setOptions:
|
|
159
|
+
setOptions: react__default.Dispatch<react__default.SetStateAction<QueryOptions>>;
|
|
160
160
|
/** Sets the current page number. */
|
|
161
161
|
setPage: (page: number) => void;
|
|
162
162
|
/** Sets the number of items per page and resets to the first page. */
|
|
@@ -287,4 +287,4 @@ type ActionMethods<TAction extends ActionConfigModule<any, any>> = {
|
|
|
287
287
|
}) => void;
|
|
288
288
|
};
|
|
289
289
|
|
|
290
|
-
export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e,
|
|
290
|
+
export type { ActionConfigModule as A, ExecutableAction as E, InputOf as I, LogLevel as L, ModuleStates as M, OutputOf as O, PaginationMeta as P, QueryOptions as Q, RequestConfig as R, StandardResponse as S, Tokens as T, UseApiConfig as U, ValidationError as V, ApiModuleConfig as a, UseApiModuleOptions as b, UseApiModuleReturn as c, ModuleActions as d, UseApiQuery as e, ActionsWithQuery as f, ApiClientConfig as g, ActionOptions as h, ActionStateModule as i, ApiError as j, TokenManager as k, MiddlewareContext as l, Middleware as m, RefreshTokenConfig as n, ActionConfig as o, UseApiState as p, ActionState as q, ExecuteOptions as r, ActionMethods as s, t };
|
package/dist/cli.cjs
CHANGED
|
@@ -328,7 +328,7 @@ async function generateModuleFiles(module2, allSchemas, allEnums, outputDir) {
|
|
|
328
328
|
const createdFileExports = ["config"];
|
|
329
329
|
let configContent = `// This file is auto-generated. Do not edit directly.
|
|
330
330
|
|
|
331
|
-
import type { ApiModuleConfig, ActionConfigModule } from 'api-core-lib';
|
|
331
|
+
import type { ApiModuleConfig, ActionConfigModule, QueryOptions } from 'api-core-lib';
|
|
332
332
|
`;
|
|
333
333
|
if (schemasToImport.length > 0) configContent += `import type { ${schemasToImport.join(", ")} } from './types';
|
|
334
334
|
`;
|
|
@@ -453,20 +453,113 @@ import type { ${schemasToImport.join(", ")} } from './types';
|
|
|
453
453
|
console.log(import_chalk.default.gray(` \u2713 index.ts (Initial)`));
|
|
454
454
|
const moduleBaseName = module2.moduleName.replace(/Api$/, "");
|
|
455
455
|
const camelCaseModuleName = toCamelCase(moduleBaseName);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
let endpointsContent = `// This file is auto-generated. Do not edit directly.
|
|
457
|
+
|
|
458
|
+
`;
|
|
459
|
+
endpointsContent += `import type { QueryOptions } from 'api-core-lib';
|
|
460
|
+
`;
|
|
461
|
+
const endpointTypesToImport = /* @__PURE__ */ new Set();
|
|
462
|
+
Object.values(module2.actions).forEach((action) => {
|
|
463
|
+
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions" && !BUILT_IN_TYPES.has(action.inputType)) {
|
|
464
|
+
endpointTypesToImport.add(action.inputType);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
if (endpointTypesToImport.size > 0) {
|
|
468
|
+
endpointsContent += `import type { ${[...endpointTypesToImport].join(", ")} } from './types';
|
|
469
|
+
|
|
470
|
+
`;
|
|
471
|
+
}
|
|
472
|
+
endpointsContent += `export const ${camelCaseModuleName}Endpoints = {
|
|
473
|
+
`;
|
|
474
|
+
for (const action of Object.values(module2.actions)) {
|
|
475
|
+
const params = [];
|
|
476
|
+
if (action.pathParams.length > 0) {
|
|
477
|
+
params.push(`params: { ${action.pathParams.map((p) => `${p}: string | number`).join("; ")} }`);
|
|
478
|
+
}
|
|
479
|
+
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") {
|
|
480
|
+
params.push(`body: ${action.inputType}`);
|
|
481
|
+
}
|
|
482
|
+
if (action.hasQuery) {
|
|
483
|
+
params.push(`query?: QueryOptions`);
|
|
484
|
+
}
|
|
485
|
+
endpointsContent += ` /**
|
|
486
|
+
* ${action.method} ${module2.baseEndpoint}${action.path}
|
|
487
|
+
* ${action.description}
|
|
488
|
+
*/
|
|
489
|
+
`;
|
|
490
|
+
endpointsContent += ` ${action.name}: (${params.join(", ")}) => ({
|
|
491
|
+
`;
|
|
492
|
+
endpointsContent += ` action: '${action.name}' as const,
|
|
493
|
+
`;
|
|
494
|
+
if (action.pathParams.length > 0) endpointsContent += ` pathParams: params,
|
|
495
|
+
`;
|
|
496
|
+
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") endpointsContent += ` input: body,
|
|
497
|
+
`;
|
|
498
|
+
else if (action.hasQuery) endpointsContent += ` input: query,
|
|
499
|
+
`;
|
|
500
|
+
endpointsContent += ` }),
|
|
501
|
+
|
|
502
|
+
`;
|
|
503
|
+
}
|
|
504
|
+
endpointsContent += `};
|
|
505
|
+
`;
|
|
506
|
+
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.endpoints.ts`), endpointsContent.trim());
|
|
459
507
|
console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.endpoints.ts (Type-Safe Endpoints)`));
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
508
|
+
const contextFileContent = `// This file is auto-generated. Do not edit directly.
|
|
509
|
+
'use client';
|
|
510
|
+
|
|
511
|
+
import React from 'react';
|
|
512
|
+
import { createApiModuleContext, useApiModule, UseApiModuleOptions } from 'api-core-lib/client';
|
|
513
|
+
import { apiClient } from '@/lib/api-core/clientApi'; // Assuming a fixed path
|
|
514
|
+
import { ${module2.moduleName}, ${module2.moduleName} as TModuleType } from './config';
|
|
515
|
+
|
|
516
|
+
// 1. Create the strongly-typed context, provider, and consumer hook
|
|
517
|
+
const {
|
|
518
|
+
Provider,
|
|
519
|
+
useContext: use${moduleBaseName}Context
|
|
520
|
+
} = createApiModuleContext<typeof TModuleType['actions']>();
|
|
521
|
+
|
|
522
|
+
export { use${moduleBaseName}Context };
|
|
523
|
+
|
|
524
|
+
// 2. Create a custom Provider that encapsulates the useApiModule logic
|
|
525
|
+
type Options = Parameters<typeof useApiModule>[2];
|
|
526
|
+
|
|
527
|
+
interface ${moduleBaseName}ProviderProps {
|
|
528
|
+
children: React.ReactNode;
|
|
529
|
+
options?: Options;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* A dedicated React Provider that initializes and provides the ${moduleBaseName} API context.
|
|
534
|
+
*/
|
|
535
|
+
export function ${moduleBaseName}Provider({ children, options = {} }: ${moduleBaseName}ProviderProps) {
|
|
536
|
+
const api = useApiModule(apiClient, ${module2.moduleName}, options);
|
|
537
|
+
return <Provider value={api}>{children}</Provider>;
|
|
538
|
+
}
|
|
539
|
+
`;
|
|
540
|
+
const contextFileName = `${camelCaseModuleName}.context.tsx`;
|
|
541
|
+
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, contextFileName), contextFileContent.trim());
|
|
542
|
+
console.log(import_chalk.default.gray(` \u2713 ${contextFileName} (Strongly-Typed Context & Provider)`));
|
|
543
|
+
const serverContent = `// This file is auto-generated. For server-side use only.
|
|
544
|
+
|
|
545
|
+
import { createServerApi } from 'api-core-lib/server';
|
|
546
|
+
import { serverApiClient } from '@/lib/api-core/serverApi'; // Assuming a fixed path
|
|
547
|
+
import { ${module2.moduleName} } from './config';
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Creates a server-side instance of the ${moduleBaseName} API for pre-fetching data in RSC.
|
|
551
|
+
*/
|
|
552
|
+
export const create${moduleBaseName}ServerApi = () => {
|
|
553
|
+
return createServerApi(serverApiClient, ${module2.moduleName});
|
|
554
|
+
};
|
|
555
|
+
`;
|
|
556
|
+
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.server.ts`), serverContent.trim());
|
|
463
557
|
console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.server.ts (Server-Side Helper)`));
|
|
464
558
|
const newExports = [
|
|
465
559
|
`
|
|
466
560
|
// Generated API helpers`,
|
|
467
561
|
`export * from './${camelCaseModuleName}.endpoints';`,
|
|
468
|
-
`export * from '
|
|
469
|
-
`export * from './${moduleBaseName}.provider';`,
|
|
562
|
+
`export * from './${camelCaseModuleName}.context';`,
|
|
470
563
|
`export * from './${camelCaseModuleName}.server';`
|
|
471
564
|
].join("\n");
|
|
472
565
|
import_fs.default.appendFileSync(indexFilePath, newExports);
|
package/dist/client.cjs
CHANGED
|
@@ -523,10 +523,32 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
523
523
|
return finalApiReturn;
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
// src/hooks/useApiModule/apiModuleContext.ts
|
|
527
|
+
|
|
528
|
+
function createApiModuleContext() {
|
|
529
|
+
const Context = _react.createContext.call(void 0, null);
|
|
530
|
+
const Provider = ({ value, children }) => {
|
|
531
|
+
return _react.createElement.call(void 0, Context.Provider, { value }, children);
|
|
532
|
+
};
|
|
533
|
+
const useConsumer = () => {
|
|
534
|
+
const context = _react.useContext.call(void 0, Context);
|
|
535
|
+
if (!context) {
|
|
536
|
+
throw new Error("This component must be used within its corresponding ApiModuleProvider.");
|
|
537
|
+
}
|
|
538
|
+
return context;
|
|
539
|
+
};
|
|
540
|
+
return {
|
|
541
|
+
Context,
|
|
542
|
+
Provider,
|
|
543
|
+
useContext: useConsumer
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
|
|
526
548
|
|
|
527
549
|
|
|
528
550
|
|
|
529
551
|
|
|
530
552
|
|
|
531
553
|
|
|
532
|
-
exports.ApiModuleProvider = ApiModuleProvider; exports.useApi = useApi; exports.useApiModule = useApiModule; exports.useApiRecord = useApiRecord; exports.useDeepCompareEffect = useDeepCompareEffect; exports.useModuleContext = useModuleContext;
|
|
554
|
+
exports.ApiModuleProvider = ApiModuleProvider; exports.createApiModuleContext = createApiModuleContext; exports.useApi = useApi; exports.useApiModule = useApiModule; exports.useApiRecord = useApiRecord; exports.useDeepCompareEffect = useDeepCompareEffect; exports.useModuleContext = useModuleContext;
|
package/dist/client.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-
|
|
3
|
-
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-
|
|
4
|
-
import * as
|
|
2
|
+
import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery, f as ActionsWithQuery } from './apiModule.types-CZX-M2Ub.cjs';
|
|
3
|
+
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-Cq9AlZX2.cjs';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
5
6
|
|
|
6
7
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
|
|
7
8
|
|
|
@@ -21,7 +22,7 @@ type EffectCallback = () => (void | (() => void));
|
|
|
21
22
|
type DependencyList = readonly any[];
|
|
22
23
|
declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
|
|
23
24
|
|
|
24
|
-
declare const ApiModuleProvider:
|
|
25
|
+
declare const ApiModuleProvider: react.Provider<{
|
|
25
26
|
states: ModuleStates<any>;
|
|
26
27
|
actions: ModuleActions<any>;
|
|
27
28
|
queries: {
|
|
@@ -32,4 +33,30 @@ declare const ApiModuleProvider: React.Provider<{
|
|
|
32
33
|
declare function useModuleContext<TModule extends ApiModuleConfig<any>, TExtra = {}>(): UseApiModuleReturn<TModule['actions'], TExtra>;
|
|
33
34
|
declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>, TExtra extends object = {}>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions<TExtra>): UseApiModuleReturn<TActions, TExtra>;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Creates a strongly-typed React Context, Provider, and consumer hook for a specific API module.
|
|
38
|
+
* This pattern avoids the need for manual type assertions in consuming components.
|
|
39
|
+
*
|
|
40
|
+
* @template TActions - The shape of the actions in the API module.
|
|
41
|
+
* @returns An object containing the typed Context, Provider, and a `useContext` hook.
|
|
42
|
+
*/
|
|
43
|
+
declare function createApiModuleContext<TActions extends Record<string, any>>(): {
|
|
44
|
+
Context: react.Context<{
|
|
45
|
+
states: ModuleStates<TActions>;
|
|
46
|
+
actions: ModuleActions<TActions>;
|
|
47
|
+
queries: { [K in ActionsWithQuery<TActions>]: UseApiQuery; };
|
|
48
|
+
dehydrate: () => string;
|
|
49
|
+
} | null>;
|
|
50
|
+
Provider: ({ value, children }: {
|
|
51
|
+
value: UseApiModuleReturn<TActions>;
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}) => react.FunctionComponentElement<react.ProviderProps<{
|
|
54
|
+
states: ModuleStates<TActions>;
|
|
55
|
+
actions: ModuleActions<TActions>;
|
|
56
|
+
queries: { [K in ActionsWithQuery<TActions>]: UseApiQuery; };
|
|
57
|
+
dehydrate: () => string;
|
|
58
|
+
} | null>>;
|
|
59
|
+
useContext: () => UseApiModuleReturn<TActions>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { ApiModuleProvider, createApiModuleContext, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery } from './apiModule.types-
|
|
3
|
-
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-
|
|
4
|
-
import * as
|
|
2
|
+
import { U as UseApiConfig, A as ActionConfigModule, a as ApiModuleConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, M as ModuleStates, d as ModuleActions, e as UseApiQuery, f as ActionsWithQuery } from './apiModule.types-CZX-M2Ub.js';
|
|
3
|
+
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-Cye9a7zh.js';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
5
6
|
|
|
6
7
|
declare function useApi<T>(axiosInstance: AxiosInstance, config: UseApiConfig<T>): any;
|
|
7
8
|
|
|
@@ -21,7 +22,7 @@ type EffectCallback = () => (void | (() => void));
|
|
|
21
22
|
type DependencyList = readonly any[];
|
|
22
23
|
declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): void;
|
|
23
24
|
|
|
24
|
-
declare const ApiModuleProvider:
|
|
25
|
+
declare const ApiModuleProvider: react.Provider<{
|
|
25
26
|
states: ModuleStates<any>;
|
|
26
27
|
actions: ModuleActions<any>;
|
|
27
28
|
queries: {
|
|
@@ -32,4 +33,30 @@ declare const ApiModuleProvider: React.Provider<{
|
|
|
32
33
|
declare function useModuleContext<TModule extends ApiModuleConfig<any>, TExtra = {}>(): UseApiModuleReturn<TModule['actions'], TExtra>;
|
|
33
34
|
declare function useApiModule<TActions extends Record<string, ActionConfigModule<any, any>>, TExtra extends object = {}>(axiosInstance: AxiosInstance, moduleConfig: ApiModuleConfig<TActions>, options?: UseApiModuleOptions<TExtra>): UseApiModuleReturn<TActions, TExtra>;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Creates a strongly-typed React Context, Provider, and consumer hook for a specific API module.
|
|
38
|
+
* This pattern avoids the need for manual type assertions in consuming components.
|
|
39
|
+
*
|
|
40
|
+
* @template TActions - The shape of the actions in the API module.
|
|
41
|
+
* @returns An object containing the typed Context, Provider, and a `useContext` hook.
|
|
42
|
+
*/
|
|
43
|
+
declare function createApiModuleContext<TActions extends Record<string, any>>(): {
|
|
44
|
+
Context: react.Context<{
|
|
45
|
+
states: ModuleStates<TActions>;
|
|
46
|
+
actions: ModuleActions<TActions>;
|
|
47
|
+
queries: { [K in ActionsWithQuery<TActions>]: UseApiQuery; };
|
|
48
|
+
dehydrate: () => string;
|
|
49
|
+
} | null>;
|
|
50
|
+
Provider: ({ value, children }: {
|
|
51
|
+
value: UseApiModuleReturn<TActions>;
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}) => react.FunctionComponentElement<react.ProviderProps<{
|
|
54
|
+
states: ModuleStates<TActions>;
|
|
55
|
+
actions: ModuleActions<TActions>;
|
|
56
|
+
queries: { [K in ActionsWithQuery<TActions>]: UseApiQuery; };
|
|
57
|
+
dehydrate: () => string;
|
|
58
|
+
} | null>>;
|
|
59
|
+
useContext: () => UseApiModuleReturn<TActions>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { ApiModuleProvider, createApiModuleContext, useApi, useApiModule, useApiRecord, useDeepCompareEffect, useModuleContext };
|
package/dist/client.js
CHANGED
|
@@ -522,8 +522,30 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
522
522
|
}), [baseApiReturn, extraContextData]);
|
|
523
523
|
return finalApiReturn;
|
|
524
524
|
}
|
|
525
|
+
|
|
526
|
+
// src/hooks/useApiModule/apiModuleContext.ts
|
|
527
|
+
import { createContext as createContext2, useContext as useContext2, createElement } from "react";
|
|
528
|
+
function createApiModuleContext() {
|
|
529
|
+
const Context = createContext2(null);
|
|
530
|
+
const Provider = ({ value, children }) => {
|
|
531
|
+
return createElement(Context.Provider, { value }, children);
|
|
532
|
+
};
|
|
533
|
+
const useConsumer = () => {
|
|
534
|
+
const context = useContext2(Context);
|
|
535
|
+
if (!context) {
|
|
536
|
+
throw new Error("This component must be used within its corresponding ApiModuleProvider.");
|
|
537
|
+
}
|
|
538
|
+
return context;
|
|
539
|
+
};
|
|
540
|
+
return {
|
|
541
|
+
Context,
|
|
542
|
+
Provider,
|
|
543
|
+
useContext: useConsumer
|
|
544
|
+
};
|
|
545
|
+
}
|
|
525
546
|
export {
|
|
526
547
|
ApiModuleProvider,
|
|
548
|
+
createApiModuleContext,
|
|
527
549
|
useApi,
|
|
528
550
|
useApiModule,
|
|
529
551
|
useApiRecord,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-
|
|
2
|
+
import { g as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, h as ActionOptions, R as RequestConfig, i as ActionStateModule, Q as QueryOptions, e as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-CZX-M2Ub.cjs';
|
|
3
|
+
export { o as ActionConfig, s as ActionMethods, q as ActionState, f as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, n as RefreshTokenConfig, k as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, p as UseApiState, V as ValidationError, t } from './apiModule.types-CZX-M2Ub.cjs';
|
|
4
|
+
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-Cq9AlZX2.cjs';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-
|
|
2
|
+
import { g as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, h as ActionOptions, R as RequestConfig, i as ActionStateModule, Q as QueryOptions, e as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-CZX-M2Ub.js';
|
|
3
|
+
export { o as ActionConfig, s as ActionMethods, q as ActionState, f as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, n as RefreshTokenConfig, k as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, p as UseApiState, V as ValidationError, t } from './apiModule.types-CZX-M2Ub.js';
|
|
4
|
+
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-Cye9a7zh.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-
|
|
2
|
+
import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-CZX-M2Ub.cjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-
|
|
2
|
+
import { A as ActionConfigModule, a as ApiModuleConfig, I as InputOf } from './apiModule.types-CZX-M2Ub.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { R as RequestConfig,
|
|
2
|
+
import { R as RequestConfig, j as ApiError, S as StandardResponse, h as ActionOptions } from './apiModule.types-CZX-M2Ub.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents the internal state of the `useApiRecord` hook.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { R as RequestConfig,
|
|
2
|
+
import { R as RequestConfig, j as ApiError, S as StandardResponse, h as ActionOptions } from './apiModule.types-CZX-M2Ub.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents the internal state of the `useApiRecord` hook.
|