api-core-lib 12.12.107 → 12.12.109
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-dbmnauAt.d.cts → apiModule.types-CQ1VtcUp.d.cts} +1 -0
- package/dist/{apiModule.types-dbmnauAt.d.ts → apiModule.types-CQ1VtcUp.d.ts} +1 -0
- package/dist/{chunk-25UFVV4F.cjs → chunk-M3U3ZI6Q.cjs} +15 -7
- package/dist/{chunk-KPZ7BF52.js → chunk-MFZM7WY3.js} +15 -7
- package/dist/cli.cjs +19 -17
- package/dist/client.cjs +20 -20
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +3 -19
- package/dist/index.d.ts +3 -19
- package/dist/index.js +1 -1
- package/dist/server.cjs +6 -6
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/{useApiRecord.types-C06B5p4U.d.ts → useApiRecord.types-Bf6lnZjJ.d.ts} +1 -1
- package/dist/{useApiRecord.types-HrabvzEQ.d.cts → useApiRecord.types-CGkacfde.d.cts} +1 -1
- package/package.json +1 -1
|
@@ -171,11 +171,8 @@ function createApiServices(axiosInstance, baseEndpoint) {
|
|
|
171
171
|
const url = resolveUrl(config);
|
|
172
172
|
try {
|
|
173
173
|
const response = await axiosInstance.post(url, data, config);
|
|
174
|
-
console.log("[lib] response POST: ", response);
|
|
175
|
-
console.log("[lib] response processResponse POST: ", processResponse(response));
|
|
176
174
|
return processResponse(response);
|
|
177
175
|
} catch (error) {
|
|
178
|
-
console.log("[lib] response error POST: ", processResponse(error));
|
|
179
176
|
return processResponse(error);
|
|
180
177
|
}
|
|
181
178
|
};
|
|
@@ -235,18 +232,29 @@ function createApiServices(axiosInstance, baseEndpoint) {
|
|
|
235
232
|
return { get, getWithQuery, post, put, patch, remove, bulkDelete, upload };
|
|
236
233
|
}
|
|
237
234
|
async function callDynamicApi(axiosInstance, baseEndpoint, actionConfig, params) {
|
|
238
|
-
const { pathParams, body
|
|
235
|
+
const { pathParams, body } = params;
|
|
236
|
+
const finalConfig = { ...params.config };
|
|
239
237
|
const urlTemplate = `${baseEndpoint}${actionConfig.path}`;
|
|
240
238
|
const finalUrl = buildDynamicUrl(urlTemplate, pathParams || {});
|
|
239
|
+
const finalBody = body;
|
|
240
|
+
if (actionConfig.upload) {
|
|
241
|
+
if (!(finalBody instanceof FormData)) {
|
|
242
|
+
console.warn("Action configured with 'upload: true' but the provided body is not an instance of FormData.");
|
|
243
|
+
}
|
|
244
|
+
if (!finalConfig.headers) {
|
|
245
|
+
finalConfig.headers = {};
|
|
246
|
+
}
|
|
247
|
+
delete finalConfig.headers["Content-Type"];
|
|
248
|
+
}
|
|
241
249
|
try {
|
|
242
250
|
const { method } = actionConfig;
|
|
243
251
|
let response;
|
|
244
252
|
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
245
|
-
response = await axiosInstance[method.toLowerCase()](finalUrl,
|
|
253
|
+
response = await axiosInstance[method.toLowerCase()](finalUrl, finalBody, finalConfig);
|
|
246
254
|
} else if (method === "DELETE") {
|
|
247
|
-
response = await axiosInstance.delete(finalUrl, { data:
|
|
255
|
+
response = await axiosInstance.delete(finalUrl, { data: finalBody, ...finalConfig });
|
|
248
256
|
} else {
|
|
249
|
-
response = await axiosInstance.get(finalUrl, { params:
|
|
257
|
+
response = await axiosInstance.get(finalUrl, { params: finalBody, ...finalConfig });
|
|
250
258
|
}
|
|
251
259
|
return processResponse(response);
|
|
252
260
|
} catch (error) {
|
|
@@ -171,11 +171,8 @@ function createApiServices(axiosInstance, baseEndpoint) {
|
|
|
171
171
|
const url = resolveUrl(config);
|
|
172
172
|
try {
|
|
173
173
|
const response = await axiosInstance.post(url, data, config);
|
|
174
|
-
console.log("[lib] response POST: ", response);
|
|
175
|
-
console.log("[lib] response processResponse POST: ", processResponse(response));
|
|
176
174
|
return processResponse(response);
|
|
177
175
|
} catch (error) {
|
|
178
|
-
console.log("[lib] response error POST: ", processResponse(error));
|
|
179
176
|
return processResponse(error);
|
|
180
177
|
}
|
|
181
178
|
};
|
|
@@ -235,18 +232,29 @@ function createApiServices(axiosInstance, baseEndpoint) {
|
|
|
235
232
|
return { get, getWithQuery, post, put, patch, remove, bulkDelete, upload };
|
|
236
233
|
}
|
|
237
234
|
async function callDynamicApi(axiosInstance, baseEndpoint, actionConfig, params) {
|
|
238
|
-
const { pathParams, body
|
|
235
|
+
const { pathParams, body } = params;
|
|
236
|
+
const finalConfig = { ...params.config };
|
|
239
237
|
const urlTemplate = `${baseEndpoint}${actionConfig.path}`;
|
|
240
238
|
const finalUrl = buildDynamicUrl(urlTemplate, pathParams || {});
|
|
239
|
+
const finalBody = body;
|
|
240
|
+
if (actionConfig.upload) {
|
|
241
|
+
if (!(finalBody instanceof FormData)) {
|
|
242
|
+
console.warn("Action configured with 'upload: true' but the provided body is not an instance of FormData.");
|
|
243
|
+
}
|
|
244
|
+
if (!finalConfig.headers) {
|
|
245
|
+
finalConfig.headers = {};
|
|
246
|
+
}
|
|
247
|
+
delete finalConfig.headers["Content-Type"];
|
|
248
|
+
}
|
|
241
249
|
try {
|
|
242
250
|
const { method } = actionConfig;
|
|
243
251
|
let response;
|
|
244
252
|
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
245
|
-
response = await axiosInstance[method.toLowerCase()](finalUrl,
|
|
253
|
+
response = await axiosInstance[method.toLowerCase()](finalUrl, finalBody, finalConfig);
|
|
246
254
|
} else if (method === "DELETE") {
|
|
247
|
-
response = await axiosInstance.delete(finalUrl, { data:
|
|
255
|
+
response = await axiosInstance.delete(finalUrl, { data: finalBody, ...finalConfig });
|
|
248
256
|
} else {
|
|
249
|
-
response = await axiosInstance.get(finalUrl, { params:
|
|
257
|
+
response = await axiosInstance.get(finalUrl, { params: finalBody, ...finalConfig });
|
|
250
258
|
}
|
|
251
259
|
return processResponse(response);
|
|
252
260
|
} catch (error) {
|
package/dist/cli.cjs
CHANGED
|
@@ -158,22 +158,7 @@ ${shape}
|
|
|
158
158
|
return zodChain;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
// src/generator/
|
|
162
|
-
var DEBUG_MODE = process.env.DEBUG === "true";
|
|
163
|
-
var debugLog = (title, data) => DEBUG_MODE && console.log(import_chalk.default.yellow(`
|
|
164
|
-
[DEBUG: ${title}]`), import_util.default.inspect(data, { depth: 5, colors: true }));
|
|
165
|
-
var toCamelCase2 = (str) => str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toLowerCase());
|
|
166
|
-
var toPascalCase2 = (str) => str.replace(/(?:^|[-_\s])(\w)/g, (_, c) => c.toUpperCase());
|
|
167
|
-
var sanitizeForModuleName = (name) => toPascalCase2(name.replace(/api/gi, "").replace(/[^a-zA-Z0-9\s-]/g, ""));
|
|
168
|
-
function findCommonPath(paths) {
|
|
169
|
-
if (!paths || paths.length === 0) return "/";
|
|
170
|
-
const sortedPaths = paths.sort();
|
|
171
|
-
const first = sortedPaths[0].split("/");
|
|
172
|
-
const last = sortedPaths[sortedPaths.length - 1].split("/");
|
|
173
|
-
let i = 0;
|
|
174
|
-
while (i < first.length && first[i] === last[i]) i++;
|
|
175
|
-
return first.slice(0, i).join("/") || "/";
|
|
176
|
-
}
|
|
161
|
+
// src/generator/core/_propToMock.ts
|
|
177
162
|
function _propToMock(prop) {
|
|
178
163
|
if (prop.example) return prop.example;
|
|
179
164
|
if (prop.name.match(/image|avatar|logo|url/i)) return "https://via.placeholder.com/150";
|
|
@@ -182,7 +167,7 @@ function _propToMock(prop) {
|
|
|
182
167
|
case "string":
|
|
183
168
|
if (prop.format === "email") return "test@example.com";
|
|
184
169
|
if (prop.format === "uuid") return "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11";
|
|
185
|
-
return `Mock ${
|
|
170
|
+
return `Mock ${toPascalCase(prop.name)}`;
|
|
186
171
|
case "integer":
|
|
187
172
|
case "number":
|
|
188
173
|
return 1;
|
|
@@ -200,6 +185,23 @@ function _propToMock(prop) {
|
|
|
200
185
|
return null;
|
|
201
186
|
}
|
|
202
187
|
}
|
|
188
|
+
|
|
189
|
+
// src/generator/v1.ts
|
|
190
|
+
var DEBUG_MODE = process.env.DEBUG === "true";
|
|
191
|
+
var debugLog = (title, data) => DEBUG_MODE && console.log(import_chalk.default.yellow(`
|
|
192
|
+
[DEBUG: ${title}]`), import_util.default.inspect(data, { depth: 5, colors: true }));
|
|
193
|
+
var toCamelCase2 = (str) => str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toLowerCase());
|
|
194
|
+
var toPascalCase2 = (str) => str.replace(/(?:^|[-_\s])(\w)/g, (_, c) => c.toUpperCase());
|
|
195
|
+
var sanitizeForModuleName = (name) => toPascalCase2(name.replace(/api/gi, "").replace(/[^a-zA-Z0-9\s-]/g, ""));
|
|
196
|
+
function findCommonPath(paths) {
|
|
197
|
+
if (!paths || paths.length === 0) return "/";
|
|
198
|
+
const sortedPaths = paths.sort();
|
|
199
|
+
const first = sortedPaths[0].split("/");
|
|
200
|
+
const last = sortedPaths[sortedPaths.length - 1].split("/");
|
|
201
|
+
let i = 0;
|
|
202
|
+
while (i < first.length && first[i] === last[i]) i++;
|
|
203
|
+
return first.slice(0, i).join("/") || "/";
|
|
204
|
+
}
|
|
203
205
|
function parseSchema(name, schema, allEnums) {
|
|
204
206
|
const properties = [];
|
|
205
207
|
const enums = {};
|
package/dist/client.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkM3U3ZI6Qcjs = require('./chunk-M3U3ZI6Q.cjs');
|
|
9
9
|
|
|
10
10
|
// src/hooks/useApi.ts
|
|
11
11
|
var _react = require('react');
|
|
@@ -46,7 +46,7 @@ function useApi(axiosInstance, config) {
|
|
|
46
46
|
});
|
|
47
47
|
const [queryOptions, setQueryOptions] = _react.useState.call(void 0, initialQuery);
|
|
48
48
|
const apiServices = _react.useMemo.call(void 0,
|
|
49
|
-
() =>
|
|
49
|
+
() => _chunkM3U3ZI6Qcjs.createApiServices.call(void 0, axiosInstance, finalEndpoint),
|
|
50
50
|
[axiosInstance, finalEndpoint]
|
|
51
51
|
);
|
|
52
52
|
const savedOnSuccess = _react.useRef.call(void 0, onSuccess);
|
|
@@ -60,7 +60,7 @@ function useApi(axiosInstance, config) {
|
|
|
60
60
|
try {
|
|
61
61
|
const finalQuery = currentQueryOptions || queryOptions;
|
|
62
62
|
const hasQueryParams = Object.keys(finalQuery).length > 0;
|
|
63
|
-
const queryString =
|
|
63
|
+
const queryString = _chunkM3U3ZI6Qcjs.buildPaginateQuery.call(void 0, finalQuery);
|
|
64
64
|
const result = hasQueryParams ? await apiServices.getWithQuery(queryString, requestConfig) : await apiServices.get(void 0, requestConfig);
|
|
65
65
|
setState(result);
|
|
66
66
|
if (result.success && savedOnSuccess.current) {
|
|
@@ -175,7 +175,7 @@ function useApiRecord(axiosInstance, config) {
|
|
|
175
175
|
savedOnError.current = onError;
|
|
176
176
|
}, [onSuccess, onError]);
|
|
177
177
|
const apiServices = _react.useMemo.call(void 0,
|
|
178
|
-
() =>
|
|
178
|
+
() => _chunkM3U3ZI6Qcjs.createApiServices.call(void 0, axiosInstance, finalEndpoint),
|
|
179
179
|
[axiosInstance, finalEndpoint]
|
|
180
180
|
);
|
|
181
181
|
const fetchRecord = _react.useCallback.call(void 0, async () => {
|
|
@@ -287,10 +287,10 @@ var createInitialState = () => ({
|
|
|
287
287
|
rawResponse: null
|
|
288
288
|
});
|
|
289
289
|
function useApiActionState(actionConfig, cacheKey, execute, input, enabled) {
|
|
290
|
-
const getClientSnapshot = () =>
|
|
291
|
-
const getServerSnapshot = () =>
|
|
290
|
+
const getClientSnapshot = () => _chunkM3U3ZI6Qcjs.globalStateManager.getSnapshot(cacheKey);
|
|
291
|
+
const getServerSnapshot = () => _chunkM3U3ZI6Qcjs.globalStateManager.getSnapshot(cacheKey);
|
|
292
292
|
const state = _react.useSyncExternalStore.call(void 0,
|
|
293
|
-
(callback) =>
|
|
293
|
+
(callback) => _chunkM3U3ZI6Qcjs.globalStateManager.subscribe(cacheKey, callback),
|
|
294
294
|
getClientSnapshot,
|
|
295
295
|
getServerSnapshot
|
|
296
296
|
);
|
|
@@ -335,7 +335,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
335
335
|
}, [onSuccess, onError]);
|
|
336
336
|
_react.useMemo.call(void 0, () => {
|
|
337
337
|
if (hydratedState) {
|
|
338
|
-
|
|
338
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.rehydrate(hydratedState);
|
|
339
339
|
}
|
|
340
340
|
}, [hydratedState]);
|
|
341
341
|
_react.useEffect.call(void 0, () => {
|
|
@@ -343,7 +343,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
343
343
|
}, [onSuccess, onError]);
|
|
344
344
|
_react.useMemo.call(void 0, () => {
|
|
345
345
|
if (hydratedState) {
|
|
346
|
-
|
|
346
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.rehydrate(hydratedState);
|
|
347
347
|
}
|
|
348
348
|
}, [hydratedState]);
|
|
349
349
|
const actions = _react.useMemo.call(void 0, () => {
|
|
@@ -352,23 +352,23 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
352
352
|
const shouldCache = actionConfig.cacheResponse !== false;
|
|
353
353
|
const execute = async (input, options2 = {}) => {
|
|
354
354
|
const finalPathParams = { ...JSON.parse(pathParamsString), ...options2.pathParams };
|
|
355
|
-
const cacheKey = shouldCache ?
|
|
355
|
+
const cacheKey = shouldCache ? _chunkM3U3ZI6Qcjs.generateCacheKey.call(void 0, moduleConfig.baseEndpoint, actionName, input, { pathParams: finalPathParams }) : "";
|
|
356
356
|
let mutationContext;
|
|
357
357
|
try {
|
|
358
358
|
if (options2.onMutate && shouldCache) {
|
|
359
359
|
mutationContext = await options2.onMutate(input);
|
|
360
360
|
}
|
|
361
361
|
if (shouldCache) {
|
|
362
|
-
|
|
362
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, (prev) => ({ ...prev, loading: true, called: true, error: null, isStale: false }));
|
|
363
363
|
}
|
|
364
|
-
const result = await
|
|
364
|
+
const result = await _chunkM3U3ZI6Qcjs.callDynamicApi.call(void 0, axiosInstance, moduleConfig.baseEndpoint, actionConfig, {
|
|
365
365
|
pathParams: finalPathParams,
|
|
366
366
|
body: input,
|
|
367
367
|
config: options2.config
|
|
368
368
|
});
|
|
369
369
|
console.log("[API Result execute]", result);
|
|
370
370
|
if (shouldCache) {
|
|
371
|
-
|
|
371
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, (prev) => ({
|
|
372
372
|
...prev,
|
|
373
373
|
// احتفظ بالخصائص القديمة مثل 'called'
|
|
374
374
|
loading: false,
|
|
@@ -394,7 +394,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
394
394
|
_optionalChain([actionConfig, 'access', _11 => _11.invalidates, 'optionalAccess', _12 => _12.forEach, 'call', _13 => _13((keyToInvalidate) => {
|
|
395
395
|
const prefix = `${moduleConfig.baseEndpoint}/${keyToInvalidate}::`;
|
|
396
396
|
console.log(`[Invalidating] by prefix: ${prefix}`);
|
|
397
|
-
|
|
397
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.invalidateByPrefix(prefix);
|
|
398
398
|
})]);
|
|
399
399
|
} else {
|
|
400
400
|
_optionalChain([savedCallbacks, 'access', _14 => _14.current, 'access', _15 => _15.onError, 'optionalCall', _16 => _16(actionName, result.message || "Action failed", _nullishCoalesce(result.error, () => ( void 0)))]);
|
|
@@ -404,7 +404,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
404
404
|
} catch (error) {
|
|
405
405
|
const apiError = _optionalChain([error, 'access', _19 => _19.response, 'optionalAccess', _20 => _20.data]) || { status: 500, message: error.message };
|
|
406
406
|
if (shouldCache) {
|
|
407
|
-
|
|
407
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, (prev) => ({ ...prev, error: apiError, loading: false, success: false }));
|
|
408
408
|
}
|
|
409
409
|
_optionalChain([savedCallbacks, 'access', _21 => _21.current, 'access', _22 => _22.onError, 'optionalCall', _23 => _23(actionName, apiError.message, apiError)]);
|
|
410
410
|
_optionalChain([options2, 'access', _24 => _24.onError, 'optionalCall', _25 => _25(apiError, mutationContext)]);
|
|
@@ -418,8 +418,8 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
418
418
|
const reset = (input, options2 = {}) => {
|
|
419
419
|
if (shouldCache) {
|
|
420
420
|
const finalPathParams = { ...JSON.parse(pathParamsString), ...options2.pathParams };
|
|
421
|
-
const cacheKey =
|
|
422
|
-
|
|
421
|
+
const cacheKey = _chunkM3U3ZI6Qcjs.generateCacheKey.call(void 0, moduleConfig.baseEndpoint, actionName, input, { pathParams: finalPathParams });
|
|
422
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, () => createInitialState());
|
|
423
423
|
}
|
|
424
424
|
};
|
|
425
425
|
acc[actionName] = { execute, reset };
|
|
@@ -462,7 +462,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
462
462
|
}
|
|
463
463
|
const input = queryOptions2;
|
|
464
464
|
const pathParams = JSON.parse(pathParamsString);
|
|
465
|
-
const cacheKey =
|
|
465
|
+
const cacheKey = _chunkM3U3ZI6Qcjs.generateCacheKey.call(void 0,
|
|
466
466
|
moduleConfig.baseEndpoint,
|
|
467
467
|
actionName,
|
|
468
468
|
input,
|
|
@@ -490,7 +490,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
490
490
|
const state = states[actionName];
|
|
491
491
|
if (state && state.called && !state.loading) {
|
|
492
492
|
const prefix = `${moduleConfig.baseEndpoint}/${actionName}::`;
|
|
493
|
-
|
|
493
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.invalidateByPrefix(prefix);
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
}
|
|
@@ -506,7 +506,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
506
506
|
};
|
|
507
507
|
}, [enabled, refetchOnWindowFocus, moduleConfig, states]);
|
|
508
508
|
const dehydrate = _react.useMemo.call(void 0, () => {
|
|
509
|
-
return () =>
|
|
509
|
+
return () => _chunkM3U3ZI6Qcjs.globalStateManager.dehydrate();
|
|
510
510
|
}, []);
|
|
511
511
|
const baseApiReturn = { actions, states, queries, dehydrate };
|
|
512
512
|
const finalApiReturn = _react.useMemo.call(void 0, () => ({
|
package/dist/client.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 ModuleQueries } from './apiModule.types-
|
|
3
|
-
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-
|
|
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 ModuleQueries } from './apiModule.types-CQ1VtcUp.cjs';
|
|
3
|
+
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-CGkacfde.cjs';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 ModuleQueries } from './apiModule.types-
|
|
3
|
-
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-
|
|
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 ModuleQueries } from './apiModule.types-CQ1VtcUp.js';
|
|
3
|
+
import { U as UseApiRecordConfig, a as UseApiRecordReturn } from './useApiRecord.types-Bf6lnZjJ.js';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
package/dist/client.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkM3U3ZI6Qcjs = require('./chunk-M3U3ZI6Q.cjs');
|
|
9
9
|
|
|
10
10
|
// src/core/client.ts
|
|
11
11
|
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
@@ -214,9 +214,9 @@ function createAction(axiosInstance, method, endpoint) {
|
|
|
214
214
|
...method.toUpperCase() === "GET" ? { params: payload } : { data: payload },
|
|
215
215
|
...config
|
|
216
216
|
});
|
|
217
|
-
return
|
|
217
|
+
return _chunkM3U3ZI6Qcjs.processResponse.call(void 0, response);
|
|
218
218
|
} catch (error) {
|
|
219
|
-
return
|
|
219
|
+
return _chunkM3U3ZI6Qcjs.processResponse.call(void 0, error);
|
|
220
220
|
}
|
|
221
221
|
};
|
|
222
222
|
}
|
|
@@ -295,4 +295,4 @@ var cacheManager = new CacheManager();
|
|
|
295
295
|
|
|
296
296
|
|
|
297
297
|
|
|
298
|
-
exports.buildPaginateQuery =
|
|
298
|
+
exports.buildPaginateQuery = _chunkM3U3ZI6Qcjs.buildPaginateQuery; exports.cacheManager = cacheManager; exports.callDynamicApi = _chunkM3U3ZI6Qcjs.callDynamicApi; exports.createApiActions = createApiActions; exports.createApiClient = createApiClient; exports.createApiServices = _chunkM3U3ZI6Qcjs.createApiServices; exports.generateCacheKey = _chunkM3U3ZI6Qcjs.generateCacheKey; exports.globalStateManager = _chunkM3U3ZI6Qcjs.globalStateManager; exports.processResponse = _chunkM3U3ZI6Qcjs.processResponse;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
|
|
2
|
-
import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, i as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-
|
|
3
|
-
export { o as ActionConfig, u as ActionMethods, q as ActionState, s as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, e as ModuleQueries, 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-
|
|
4
|
-
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-
|
|
2
|
+
import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, i as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-CQ1VtcUp.cjs';
|
|
3
|
+
export { o as ActionConfig, u as ActionMethods, q as ActionState, s as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, e as ModuleQueries, 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-CQ1VtcUp.cjs';
|
|
4
|
+
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-CGkacfde.cjs';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* A factory function to create a reusable set of API services for a specific endpoint.
|
|
11
|
-
* It provides full CRUD operations plus advanced features like bulk deletion and file uploads,
|
|
12
|
-
* with intelligent, dynamic URL building.
|
|
13
|
-
*/
|
|
14
9
|
declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
|
|
15
10
|
get: (id?: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
16
11
|
getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T>>;
|
|
@@ -21,17 +16,6 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
|
|
|
21
16
|
bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
22
17
|
upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
23
18
|
};
|
|
24
|
-
/**
|
|
25
|
-
* [نسخة محدثة ومحسّنة]
|
|
26
|
-
* دالة عامة وصريحة لتنفيذ أي طلب API.
|
|
27
|
-
* تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
|
|
28
|
-
*
|
|
29
|
-
* @param axiosInstance - نسخة Axios.
|
|
30
|
-
* @param baseEndpoint - نقطة النهاية الأساسية للموديول.
|
|
31
|
-
* @param actionConfig - إعدادات الإجراء المحدد.
|
|
32
|
-
* @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
|
|
33
|
-
* @returns Promise<StandardResponse<any>>
|
|
34
|
-
*/
|
|
35
19
|
declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
|
|
36
20
|
pathParams?: Record<string, string | number>;
|
|
37
21
|
body?: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
|
|
2
|
-
import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, i as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-
|
|
3
|
-
export { o as ActionConfig, u as ActionMethods, q as ActionState, s as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, e as ModuleQueries, 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-
|
|
4
|
-
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-
|
|
2
|
+
import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, i as UseApiQuery, j as ApiError, L as LogLevel } from './apiModule.types-CQ1VtcUp.js';
|
|
3
|
+
export { o as ActionConfig, u as ActionMethods, q as ActionState, s as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, r as ExecuteOptions, I as InputOf, m as Middleware, l as MiddlewareContext, d as ModuleActions, e as ModuleQueries, 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-CQ1VtcUp.js';
|
|
4
|
+
export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-Bf6lnZjJ.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare function createApiClient(config: ApiClientConfig): AxiosInstance;
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* A factory function to create a reusable set of API services for a specific endpoint.
|
|
11
|
-
* It provides full CRUD operations plus advanced features like bulk deletion and file uploads,
|
|
12
|
-
* with intelligent, dynamic URL building.
|
|
13
|
-
*/
|
|
14
9
|
declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint: string): {
|
|
15
10
|
get: (id?: string | number, config?: ActionOptions) => Promise<StandardResponse<T>>;
|
|
16
11
|
getWithQuery: (query: string, config?: RequestConfig) => Promise<StandardResponse<T>>;
|
|
@@ -21,17 +16,6 @@ declare function createApiServices<T>(axiosInstance: AxiosInstance, baseEndpoint
|
|
|
21
16
|
bulkDelete: (ids: Array<string | number>, config?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
22
17
|
upload: (file: File, additionalData?: Record<string, any>, config?: ActionOptions) => Promise<StandardResponse<any>>;
|
|
23
18
|
};
|
|
24
|
-
/**
|
|
25
|
-
* [نسخة محدثة ومحسّنة]
|
|
26
|
-
* دالة عامة وصريحة لتنفيذ أي طلب API.
|
|
27
|
-
* تستقبل وسائط منظمة بدلاً من محاولة تخمينها.
|
|
28
|
-
*
|
|
29
|
-
* @param axiosInstance - نسخة Axios.
|
|
30
|
-
* @param baseEndpoint - نقطة النهاية الأساسية للموديول.
|
|
31
|
-
* @param actionConfig - إعدادات الإجراء المحدد.
|
|
32
|
-
* @param params - كائن يحتوي على جميع البارامترات اللازمة للطلب.
|
|
33
|
-
* @returns Promise<StandardResponse<any>>
|
|
34
|
-
*/
|
|
35
19
|
declare function callDynamicApi(axiosInstance: AxiosInstance, baseEndpoint: string, actionConfig: ActionConfigModule<any, any>, params: {
|
|
36
20
|
pathParams?: Record<string, string | number>;
|
|
37
21
|
body?: any;
|
package/dist/index.js
CHANGED
package/dist/server.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkM3U3ZI6Qcjs = require('./chunk-M3U3ZI6Q.cjs');
|
|
6
6
|
|
|
7
7
|
// src/server.ts
|
|
8
8
|
function createServerApi(apiClient, moduleConfig) {
|
|
@@ -15,13 +15,13 @@ function createServerApi(apiClient, moduleConfig) {
|
|
|
15
15
|
if (!actionConfig) {
|
|
16
16
|
throw new Error(`Action "${actionName}" not found in module.`);
|
|
17
17
|
}
|
|
18
|
-
const result = await
|
|
18
|
+
const result = await _chunkM3U3ZI6Qcjs.callDynamicApi.call(void 0, apiClient, moduleConfig.baseEndpoint, actionConfig, {
|
|
19
19
|
pathParams: options.pathParams,
|
|
20
20
|
body: input
|
|
21
21
|
});
|
|
22
|
-
const cacheKey =
|
|
22
|
+
const cacheKey = _chunkM3U3ZI6Qcjs.generateCacheKey.call(void 0, moduleConfig.baseEndpoint, actionName, input, { pathParams: options.pathParams });
|
|
23
23
|
if (result.success) {
|
|
24
|
-
|
|
24
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, () => ({
|
|
25
25
|
data: result.data,
|
|
26
26
|
error: null,
|
|
27
27
|
loading: false,
|
|
@@ -31,7 +31,7 @@ function createServerApi(apiClient, moduleConfig) {
|
|
|
31
31
|
rawResponse: result.rawResponse
|
|
32
32
|
}));
|
|
33
33
|
} else {
|
|
34
|
-
|
|
34
|
+
_chunkM3U3ZI6Qcjs.globalStateManager.setState(cacheKey, () => ({
|
|
35
35
|
data: null,
|
|
36
36
|
error: result.error,
|
|
37
37
|
loading: false,
|
|
@@ -47,7 +47,7 @@ function createServerApi(apiClient, moduleConfig) {
|
|
|
47
47
|
* Dehydrates the current state in the global manager into a JSON string.
|
|
48
48
|
*/
|
|
49
49
|
dehydrate: () => {
|
|
50
|
-
return
|
|
50
|
+
return _chunkM3U3ZI6Qcjs.globalStateManager.dehydrate();
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
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-CQ1VtcUp.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-CQ1VtcUp.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { R as RequestConfig, j as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-
|
|
2
|
+
import { R as RequestConfig, j as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-CQ1VtcUp.js';
|
|
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, j as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-
|
|
2
|
+
import { R as RequestConfig, j as ApiError, S as StandardResponse, g as ActionOptions } from './apiModule.types-CQ1VtcUp.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents the internal state of the `useApiRecord` hook.
|