api-core-lib 12.0.14 → 12.0.16
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-Cvp9QdAc.d.cts → apiModule.types-D0LSWRW8.d.cts} +27 -1
- package/dist/{apiModule.types-Cvp9QdAc.d.ts → apiModule.types-D0LSWRW8.d.ts} +27 -1
- package/dist/client.cjs +101 -129
- package/dist/client.d.cts +2 -3
- package/dist/client.d.ts +2 -3
- package/dist/client.js +102 -128
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +54 -4
- package/dist/index.d.ts +54 -4
- package/dist/index.js +6 -6
- package/dist/server.cjs +6 -82
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +6 -82
- package/dist/{cacheKey-BJQaehcQ.d.ts → useApiRecord.types-C7T0gsX_.d.ts} +2 -52
- package/dist/{cacheKey-BNQ1ii6y.d.cts → useApiRecord.types-DXv1-ly6.d.cts} +2 -52
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -187,14 +187,14 @@ var GlobalStateManager = class {
|
|
|
187
187
|
* يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
|
|
188
188
|
*/
|
|
189
189
|
setState(key, updater) {
|
|
190
|
-
const
|
|
190
|
+
const item = this.store.get(key);
|
|
191
|
+
const currentState = item.state;
|
|
191
192
|
const newState = updater(currentState);
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
} else {
|
|
195
|
-
this.store.get(key).state = newState;
|
|
193
|
+
if (Object.is(currentState, newState)) {
|
|
194
|
+
return;
|
|
196
195
|
}
|
|
197
|
-
|
|
196
|
+
item.state = newState;
|
|
197
|
+
item.listeners.forEach((listener) => listener());
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
200
|
* يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
|
|
@@ -252,82 +252,6 @@ var GlobalStateManager = class {
|
|
|
252
252
|
};
|
|
253
253
|
var globalStateManager = new GlobalStateManager();
|
|
254
254
|
|
|
255
|
-
// src/hooks/useApi.ts
|
|
256
|
-
import { useState, useEffect, useCallback, useRef, useMemo } from "react";
|
|
257
|
-
|
|
258
|
-
// src/hooks/useApiRecord/index.ts
|
|
259
|
-
import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useRef as useRef2, useMemo as useMemo2 } from "react";
|
|
260
|
-
|
|
261
|
-
// src/hooks/useDeepCompareEffect/index.ts
|
|
262
|
-
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
263
|
-
import isEqual from "fast-deep-equal";
|
|
264
|
-
|
|
265
|
-
// src/hooks/useApiModule/useApiModule.ts
|
|
266
|
-
import { createContext, useContext, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState3, useSyncExternalStore } from "react";
|
|
267
|
-
var ApiModuleContext = createContext(null);
|
|
268
|
-
var ApiModuleProvider = ApiModuleContext.Provider;
|
|
269
|
-
|
|
270
|
-
// src/core/client.ts
|
|
271
|
-
import axios3 from "axios";
|
|
272
|
-
import { v4 as uuidv4 } from "uuid";
|
|
273
|
-
|
|
274
|
-
// src/core/cache.ts
|
|
275
|
-
var CacheManager = class {
|
|
276
|
-
constructor() {
|
|
277
|
-
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
278
|
-
__publicField(this, "defaultDuration", 15 * 60 * 1e3);
|
|
279
|
-
}
|
|
280
|
-
// 15 minutes
|
|
281
|
-
set(key, data, duration) {
|
|
282
|
-
this.cache.set(key, {
|
|
283
|
-
data,
|
|
284
|
-
timestamp: Date.now(),
|
|
285
|
-
duration: duration || this.defaultDuration
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
get(key) {
|
|
289
|
-
const item = this.cache.get(key);
|
|
290
|
-
if (!item) return null;
|
|
291
|
-
const isExpired = Date.now() - item.timestamp > item.duration;
|
|
292
|
-
if (isExpired) {
|
|
293
|
-
this.cache.delete(key);
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
return item.data;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* [FIX] تم تحويلها إلى دالة عامة (generic) لتعيد النوع الصحيح.
|
|
300
|
-
* الآن بدلًا من إرجاع CacheItem<unknown>، ستُرجع CacheItem<T>.
|
|
301
|
-
*/
|
|
302
|
-
getWithMeta(key) {
|
|
303
|
-
const item = this.cache.get(key);
|
|
304
|
-
if (!item) return null;
|
|
305
|
-
const isExpired = Date.now() - item.timestamp > item.duration;
|
|
306
|
-
if (isExpired) {
|
|
307
|
-
this.cache.delete(key);
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
return item;
|
|
311
|
-
}
|
|
312
|
-
delete(key) {
|
|
313
|
-
this.cache.delete(key);
|
|
314
|
-
}
|
|
315
|
-
clear() {
|
|
316
|
-
this.cache.clear();
|
|
317
|
-
}
|
|
318
|
-
invalidateByPrefix(prefix) {
|
|
319
|
-
const keysToDelete = [];
|
|
320
|
-
for (const key of this.cache.keys()) {
|
|
321
|
-
if (key.startsWith(prefix)) {
|
|
322
|
-
keysToDelete.push(key);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
keysToDelete.forEach((key) => this.cache.delete(key));
|
|
326
|
-
console.log(`Invalidated ${keysToDelete.length} cache entries with prefix: ${prefix}`);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
var cacheManager = new CacheManager();
|
|
330
|
-
|
|
331
255
|
// src/core/cacheKey.ts
|
|
332
256
|
var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
|
|
333
257
|
const params = { path: callOptions.pathParams, body: input };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { R as RequestConfig,
|
|
2
|
+
import { R as RequestConfig, h as ApiError, S as StandardResponse, e as ActionOptions } from './apiModule.types-D0LSWRW8.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents the internal state of the `useApiRecord` hook.
|
|
@@ -87,54 +87,4 @@ interface UseApiRecordReturn<T> {
|
|
|
87
87
|
setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
private store;
|
|
92
|
-
getSnapshot<T>(key: string): ActionStateModule<T>;
|
|
93
|
-
/**
|
|
94
|
-
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
|
95
|
-
* @returns دالة لإلغاء الاشتراك.
|
|
96
|
-
*/
|
|
97
|
-
subscribe(key: string, callback: () => void): () => void;
|
|
98
|
-
/**
|
|
99
|
-
* يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
|
|
100
|
-
*/
|
|
101
|
-
setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
|
|
102
|
-
/**
|
|
103
|
-
* يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
|
|
104
|
-
*/
|
|
105
|
-
invalidate(key: string): void;
|
|
106
|
-
/**
|
|
107
|
-
* [نسخة محدثة وأكثر قوة]
|
|
108
|
-
* يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
|
|
109
|
-
* @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
|
|
110
|
-
*/
|
|
111
|
-
invalidateByPrefix(prefix: string): void;
|
|
112
|
-
/**
|
|
113
|
-
* Serializes the current state of the query store into a JSON string.
|
|
114
|
-
* This is used on the server to pass the initial state to the client.
|
|
115
|
-
* @returns A JSON string representing the dehydrated state.
|
|
116
|
-
*/
|
|
117
|
-
dehydrate(): string;
|
|
118
|
-
/**
|
|
119
|
-
* Merges a dehydrated state object into the current store.
|
|
120
|
-
* This is used on the client to hydrate the state received from the server.
|
|
121
|
-
* @param hydratedState - A JSON string from the `dehydrate` method.
|
|
122
|
-
*/
|
|
123
|
-
rehydrate(hydratedState: string): void;
|
|
124
|
-
}
|
|
125
|
-
declare const globalStateManager: GlobalStateManager;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
|
|
129
|
-
* هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
|
|
130
|
-
* @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
|
|
131
|
-
* @param actionName - اسم الإجراء (مثل 'list', 'create').
|
|
132
|
-
* @param input - بيانات الطلب (body/query params).
|
|
133
|
-
* @param callOptions - خيارات إضافية مثل `pathParams`.
|
|
134
|
-
* @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
|
|
135
|
-
*/
|
|
136
|
-
declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
|
|
137
|
-
pathParams?: Record<string, any>;
|
|
138
|
-
}) => string;
|
|
139
|
-
|
|
140
|
-
export { type UseApiRecordConfig as U, type UseApiRecordReturn as a, generateCacheKey as b, type UseApiRecordState as c, type UseApiRecordActions as d, globalStateManager as g };
|
|
90
|
+
export type { UseApiRecordConfig as U, UseApiRecordReturn as a, UseApiRecordState as b, UseApiRecordActions as c };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { R as RequestConfig,
|
|
2
|
+
import { R as RequestConfig, h as ApiError, S as StandardResponse, e as ActionOptions } from './apiModule.types-D0LSWRW8.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents the internal state of the `useApiRecord` hook.
|
|
@@ -87,54 +87,4 @@ interface UseApiRecordReturn<T> {
|
|
|
87
87
|
setState: Dispatch<SetStateAction<UseApiRecordState<T>>>;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
private store;
|
|
92
|
-
getSnapshot<T>(key: string): ActionStateModule<T>;
|
|
93
|
-
/**
|
|
94
|
-
* يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
|
|
95
|
-
* @returns دالة لإلغاء الاشتراك.
|
|
96
|
-
*/
|
|
97
|
-
subscribe(key: string, callback: () => void): () => void;
|
|
98
|
-
/**
|
|
99
|
-
* يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
|
|
100
|
-
*/
|
|
101
|
-
setState<T>(key: string, updater: (prevState: ActionStateModule<T>) => ActionStateModule<T>): void;
|
|
102
|
-
/**
|
|
103
|
-
* يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
|
|
104
|
-
*/
|
|
105
|
-
invalidate(key: string): void;
|
|
106
|
-
/**
|
|
107
|
-
* [نسخة محدثة وأكثر قوة]
|
|
108
|
-
* يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
|
|
109
|
-
* @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
|
|
110
|
-
*/
|
|
111
|
-
invalidateByPrefix(prefix: string): void;
|
|
112
|
-
/**
|
|
113
|
-
* Serializes the current state of the query store into a JSON string.
|
|
114
|
-
* This is used on the server to pass the initial state to the client.
|
|
115
|
-
* @returns A JSON string representing the dehydrated state.
|
|
116
|
-
*/
|
|
117
|
-
dehydrate(): string;
|
|
118
|
-
/**
|
|
119
|
-
* Merges a dehydrated state object into the current store.
|
|
120
|
-
* This is used on the client to hydrate the state received from the server.
|
|
121
|
-
* @param hydratedState - A JSON string from the `dehydrate` method.
|
|
122
|
-
*/
|
|
123
|
-
rehydrate(hydratedState: string): void;
|
|
124
|
-
}
|
|
125
|
-
declare const globalStateManager: GlobalStateManager;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* يقوم بإنشاء مفتاح تخزين مؤقت فريد وثابت لإجراء معين ومدخلاته.
|
|
129
|
-
* هذا يضمن أن نفس الطلب ينتج دائمًا نفس المفتاح.
|
|
130
|
-
* @param moduleName - عادةً ما يكون `baseEndpoint` للموديول.
|
|
131
|
-
* @param actionName - اسم الإجراء (مثل 'list', 'create').
|
|
132
|
-
* @param input - بيانات الطلب (body/query params).
|
|
133
|
-
* @param callOptions - خيارات إضافية مثل `pathParams`.
|
|
134
|
-
* @returns سلسلة نصية فريدة تمثل مفتاح التخزين المؤقت.
|
|
135
|
-
*/
|
|
136
|
-
declare const generateCacheKey: (moduleName: string, actionName: string, input?: unknown, callOptions?: {
|
|
137
|
-
pathParams?: Record<string, any>;
|
|
138
|
-
}) => string;
|
|
139
|
-
|
|
140
|
-
export { type UseApiRecordConfig as U, type UseApiRecordReturn as a, generateCacheKey as b, type UseApiRecordState as c, type UseApiRecordActions as d, globalStateManager as g };
|
|
90
|
+
export type { UseApiRecordConfig as U, UseApiRecordReturn as a, UseApiRecordState as b, UseApiRecordActions as c };
|