api-core-lib 12.0.88 → 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 +24 -40
- 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,9 +453,6 @@ 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
|
-
const allPathParams = /* @__PURE__ */ new Set();
|
|
457
|
-
Object.values(module2.actions).forEach((action) => action.pathParams.forEach((param) => allPathParams.add(param)));
|
|
458
|
-
const pathParamsType = allPathParams.size > 0 ? `{ ${[...allPathParams].map((p) => `${p}?: string | number`).join("; ")} }` : "Record<string, never>";
|
|
459
456
|
let endpointsContent = `// This file is auto-generated. Do not edit directly.
|
|
460
457
|
|
|
461
458
|
`;
|
|
@@ -463,7 +460,7 @@ import type { ${schemasToImport.join(", ")} } from './types';
|
|
|
463
460
|
`;
|
|
464
461
|
const endpointTypesToImport = /* @__PURE__ */ new Set();
|
|
465
462
|
Object.values(module2.actions).forEach((action) => {
|
|
466
|
-
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") {
|
|
463
|
+
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions" && !BUILT_IN_TYPES.has(action.inputType)) {
|
|
467
464
|
endpointTypesToImport.add(action.inputType);
|
|
468
465
|
}
|
|
469
466
|
});
|
|
@@ -498,7 +495,7 @@ import type { ${schemasToImport.join(", ")} } from './types';
|
|
|
498
495
|
`;
|
|
499
496
|
if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") endpointsContent += ` input: body,
|
|
500
497
|
`;
|
|
501
|
-
if (action.hasQuery) endpointsContent += ` input: query,
|
|
498
|
+
else if (action.hasQuery) endpointsContent += ` input: query,
|
|
502
499
|
`;
|
|
503
500
|
endpointsContent += ` }),
|
|
504
501
|
|
|
@@ -506,38 +503,26 @@ import type { ${schemasToImport.join(", ")} } from './types';
|
|
|
506
503
|
}
|
|
507
504
|
endpointsContent += `};
|
|
508
505
|
`;
|
|
509
|
-
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.endpoints.ts`), endpointsContent);
|
|
506
|
+
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.endpoints.ts`), endpointsContent.trim());
|
|
510
507
|
console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.endpoints.ts (Type-Safe Endpoints)`));
|
|
511
|
-
const
|
|
508
|
+
const contextFileContent = `// This file is auto-generated. Do not edit directly.
|
|
509
|
+
'use client';
|
|
512
510
|
|
|
513
|
-
import
|
|
511
|
+
import React from 'react';
|
|
512
|
+
import { createApiModuleContext, useApiModule, UseApiModuleOptions } from 'api-core-lib/client';
|
|
514
513
|
import { apiClient } from '@/lib/api-core/clientApi'; // Assuming a fixed path
|
|
515
|
-
import { ${module2.moduleName} as TModuleType } from './config';
|
|
516
|
-
import { ${module2.moduleName} } from './config';
|
|
514
|
+
import { ${module2.moduleName}, ${module2.moduleName} as TModuleType } from './config';
|
|
517
515
|
|
|
518
|
-
|
|
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']>();
|
|
519
521
|
|
|
520
|
-
|
|
521
|
-
pathParams?: ModulePathParams;
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Custom hook for interacting with the ${moduleBaseName} API module.
|
|
526
|
-
*/
|
|
527
|
-
export const use${moduleBaseName}Api = (options: ${moduleBaseName}ApiOptions = {}) => {
|
|
528
|
-
return useApiModule<typeof TModuleType['actions']>(apiClient, ${module2.moduleName}, options);
|
|
529
|
-
};
|
|
530
|
-
`;
|
|
531
|
-
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `use${moduleBaseName}.ts`), hookContent);
|
|
532
|
-
console.log(import_chalk.default.gray(` \u2713 use${moduleBaseName}.ts (Custom Hook)`));
|
|
533
|
-
const providerContent = `// This file is auto-generated. Do not edit directly.
|
|
534
|
-
'use client';
|
|
535
|
-
|
|
536
|
-
import React from 'react';
|
|
537
|
-
import { ApiModuleProvider } from 'api-core-lib/client';
|
|
538
|
-
import { use${moduleBaseName}Api } from './use${moduleBaseName}';
|
|
522
|
+
export { use${moduleBaseName}Context };
|
|
539
523
|
|
|
540
|
-
|
|
524
|
+
// 2. Create a custom Provider that encapsulates the useApiModule logic
|
|
525
|
+
type Options = Parameters<typeof useApiModule>[2];
|
|
541
526
|
|
|
542
527
|
interface ${moduleBaseName}ProviderProps {
|
|
543
528
|
children: React.ReactNode;
|
|
@@ -548,13 +533,13 @@ interface ${moduleBaseName}ProviderProps {
|
|
|
548
533
|
* A dedicated React Provider that initializes and provides the ${moduleBaseName} API context.
|
|
549
534
|
*/
|
|
550
535
|
export function ${moduleBaseName}Provider({ children, options = {} }: ${moduleBaseName}ProviderProps) {
|
|
551
|
-
const api =
|
|
552
|
-
return <
|
|
536
|
+
const api = useApiModule(apiClient, ${module2.moduleName}, options);
|
|
537
|
+
return <Provider value={api}>{children}</Provider>;
|
|
553
538
|
}
|
|
554
539
|
`;
|
|
555
|
-
const
|
|
556
|
-
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath,
|
|
557
|
-
console.log(import_chalk.default.gray(` \u2713 ${
|
|
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)`));
|
|
558
543
|
const serverContent = `// This file is auto-generated. For server-side use only.
|
|
559
544
|
|
|
560
545
|
import { createServerApi } from 'api-core-lib/server';
|
|
@@ -568,14 +553,13 @@ export const create${moduleBaseName}ServerApi = () => {
|
|
|
568
553
|
return createServerApi(serverApiClient, ${module2.moduleName});
|
|
569
554
|
};
|
|
570
555
|
`;
|
|
571
|
-
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.server.ts`), serverContent);
|
|
556
|
+
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.server.ts`), serverContent.trim());
|
|
572
557
|
console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.server.ts (Server-Side Helper)`));
|
|
573
558
|
const newExports = [
|
|
574
559
|
`
|
|
575
560
|
// Generated API helpers`,
|
|
576
561
|
`export * from './${camelCaseModuleName}.endpoints';`,
|
|
577
|
-
`export * from '
|
|
578
|
-
`export * from './${moduleBaseName}.provider';`,
|
|
562
|
+
`export * from './${camelCaseModuleName}.context';`,
|
|
579
563
|
`export * from './${camelCaseModuleName}.server';`
|
|
580
564
|
].join("\n");
|
|
581
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.
|