@react-pakistan/util-functions 1.24.98 → 1.25.0
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/api/stellar-solutions/bank/cache.d.ts +99 -0
- package/api/stellar-solutions/bank/cache.js +256 -0
- package/api/stellar-solutions/bank/index.d.ts +1 -1
- package/api/stellar-solutions/bank/index.js +15 -0
- package/api/stellar-solutions/branch/cache.d.ts +97 -0
- package/api/stellar-solutions/branch/cache.js +256 -0
- package/api/stellar-solutions/branch/index.d.ts +1 -1
- package/api/stellar-solutions/branch/index.js +15 -0
- package/api/stellar-solutions/company/cache.d.ts +106 -0
- package/api/stellar-solutions/company/cache.js +307 -0
- package/api/stellar-solutions/company/index.d.ts +1 -1
- package/api/stellar-solutions/company/index.js +15 -0
- package/api/stellar-solutions/constants.d.ts +21 -0
- package/api/stellar-solutions/constants.js +24 -0
- package/api/stellar-solutions/contact/cache.d.ts +108 -0
- package/api/stellar-solutions/contact/cache.js +307 -0
- package/api/stellar-solutions/contact/index.d.ts +1 -1
- package/api/stellar-solutions/contact/index.js +15 -0
- package/api/stellar-solutions/currency/cache.d.ts +99 -0
- package/api/stellar-solutions/currency/cache.js +256 -0
- package/api/stellar-solutions/currency/index.d.ts +1 -1
- package/api/stellar-solutions/currency/index.js +15 -0
- package/api/stellar-solutions/customer/cache.d.ts +108 -0
- package/api/stellar-solutions/customer/cache.js +307 -0
- package/api/stellar-solutions/customer/index.d.ts +1 -1
- package/api/stellar-solutions/customer/index.js +15 -0
- package/api/stellar-solutions/expense/cache.d.ts +106 -0
- package/api/stellar-solutions/expense/cache.js +307 -0
- package/api/stellar-solutions/expense/index.d.ts +1 -1
- package/api/stellar-solutions/expense/index.js +15 -0
- package/api/stellar-solutions/expense-category/cache.d.ts +94 -0
- package/api/stellar-solutions/expense-category/cache.js +280 -0
- package/api/stellar-solutions/expense-category/index.d.ts +1 -1
- package/api/stellar-solutions/expense-category/index.js +15 -0
- package/api/stellar-solutions/payment-mode/cache.d.ts +97 -0
- package/api/stellar-solutions/payment-mode/cache.js +256 -0
- package/api/stellar-solutions/payment-mode/index.d.ts +1 -1
- package/api/stellar-solutions/payment-mode/index.js +15 -0
- package/api/stellar-solutions/preference/cache.d.ts +85 -0
- package/api/stellar-solutions/preference/cache.js +229 -0
- package/api/stellar-solutions/preference/index.d.ts +1 -1
- package/api/stellar-solutions/preference/index.js +15 -0
- package/api/stellar-solutions/product/cache.d.ts +94 -0
- package/api/stellar-solutions/product/cache.js +280 -0
- package/api/stellar-solutions/product/index.d.ts +4 -6
- package/api/stellar-solutions/product/index.js +24 -8
- package/api/stellar-solutions/product-category/cache.d.ts +94 -0
- package/api/stellar-solutions/product-category/cache.js +280 -0
- package/api/stellar-solutions/product-category/index.d.ts +1 -1
- package/api/stellar-solutions/product-category/index.js +15 -0
- package/api/stellar-solutions/tax/cache.d.ts +97 -0
- package/api/stellar-solutions/tax/cache.js +256 -0
- package/api/stellar-solutions/tax/index.d.ts +1 -1
- package/api/stellar-solutions/tax/index.js +15 -0
- package/api/stellar-solutions/type.d.ts +15 -0
- package/api/stellar-solutions/type.js +17 -1
- package/index.d.ts +6 -5
- package/index.js +6 -6
- package/package.json +1 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.isBranchesCacheStale = exports.preloadBranches = exports.invalidateBranchesCache = exports.getCachedBranchesByName = exports.getCachedBranchById = exports.getCachedBranches = exports.getCachedBranchesSync = void 0;
|
|
40
|
+
var constants_1 = require("../constants");
|
|
41
|
+
var type_1 = require("../type");
|
|
42
|
+
var api_methods_1 = require("../../../constants/api-methods");
|
|
43
|
+
var fetch_data_1 = require("../../../general/fetch-data");
|
|
44
|
+
var get_storage_value_1 = require("../../../local-storage/get-storage-value");
|
|
45
|
+
var set_storage_value_1 = require("../../../local-storage/set-storage-value");
|
|
46
|
+
/**
|
|
47
|
+
* Synchronous utility function to get branches from cache only
|
|
48
|
+
* Returns cached data immediately if available and fresh, otherwise returns empty array
|
|
49
|
+
* Does not trigger any API calls
|
|
50
|
+
*
|
|
51
|
+
* @returns BranchBE[] - Array of cached branches or empty array wrapper ({count, items})
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const branches = getCachedBranchesSync();
|
|
55
|
+
* if (branches.items.length > 0) {
|
|
56
|
+
* console.log(branches.items[0].branchName);
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
var getCachedBranchesSync = function () {
|
|
60
|
+
try {
|
|
61
|
+
var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BRANCHES);
|
|
62
|
+
if (!cachedData) {
|
|
63
|
+
return { count: 0, items: [] };
|
|
64
|
+
}
|
|
65
|
+
var currentTime = new Date().getTime();
|
|
66
|
+
var cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
67
|
+
var ageInMs = currentTime - cachedTime;
|
|
68
|
+
// If cached data is less than 1 week old, return it
|
|
69
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
70
|
+
return {
|
|
71
|
+
count: cachedData.branches.length,
|
|
72
|
+
items: cachedData.branches,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { count: 0, items: [] };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error('Error getting cached branches:', error);
|
|
79
|
+
return { count: 0, items: [] };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.getCachedBranchesSync = getCachedBranchesSync;
|
|
83
|
+
/**
|
|
84
|
+
* Utility function to get branches from cache or fetch from API
|
|
85
|
+
*
|
|
86
|
+
* This function manages a localStorage cache of branches with the following logic:
|
|
87
|
+
* - If branches exist in cache and are less than 1 week old, return cached version
|
|
88
|
+
* - If branches exist but are older than 1 week, fetch fresh data and update cache
|
|
89
|
+
* - If branches don't exist in cache, fetch from API and cache them
|
|
90
|
+
*
|
|
91
|
+
* @returns Promise<{count:number, items: BranchBE[]}> - Paged branches
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const branches = await getCachedBranches();
|
|
95
|
+
* console.log(branches.items[0].branchName);
|
|
96
|
+
*/
|
|
97
|
+
var getCachedBranches = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
99
|
+
var _a;
|
|
100
|
+
return __generator(this, function (_b) {
|
|
101
|
+
switch (_b.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
_b.trys.push([0, 2, , 3]);
|
|
104
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BRANCHES);
|
|
105
|
+
currentTime = new Date().getTime();
|
|
106
|
+
// Check if cached data exists and is still fresh
|
|
107
|
+
if (cachedData) {
|
|
108
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
109
|
+
ageInMs = currentTime - cachedTime;
|
|
110
|
+
// If cached data is less than 1 week old, return it
|
|
111
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
112
|
+
return [2 /*return*/, {
|
|
113
|
+
count: cachedData.branches.length,
|
|
114
|
+
items: cachedData.branches,
|
|
115
|
+
}];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
119
|
+
url: constants_1.API_ROUTES.BRANCHES,
|
|
120
|
+
method: api_methods_1.API_METHODS.GET,
|
|
121
|
+
})];
|
|
122
|
+
case 1:
|
|
123
|
+
response = _b.sent();
|
|
124
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
125
|
+
updatedCache = {
|
|
126
|
+
branches: response.data.items,
|
|
127
|
+
cachedAt: new Date().toISOString(),
|
|
128
|
+
};
|
|
129
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.BRANCHES, updatedCache);
|
|
130
|
+
return [2 /*return*/, response.data];
|
|
131
|
+
}
|
|
132
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
133
|
+
case 2:
|
|
134
|
+
error_1 = _b.sent();
|
|
135
|
+
console.error('Error fetching branches:', error_1);
|
|
136
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
137
|
+
case 3: return [2 /*return*/];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}); };
|
|
141
|
+
exports.getCachedBranches = getCachedBranches;
|
|
142
|
+
/**
|
|
143
|
+
* Utility function to get a specific branch by ID from cache
|
|
144
|
+
* If not found in cache, returns null (does not trigger API call)
|
|
145
|
+
*
|
|
146
|
+
* @param branchId - The ID of the branch to retrieve
|
|
147
|
+
* @returns BranchBE | null - The branch or null if not found
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const branch = getCachedBranchById('branch-123');
|
|
151
|
+
* if (branch) {
|
|
152
|
+
* console.log(branch.branchName);
|
|
153
|
+
* }
|
|
154
|
+
*/
|
|
155
|
+
var getCachedBranchById = function (branchId) {
|
|
156
|
+
if (!branchId) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
var branches = (0, exports.getCachedBranchesSync)().items;
|
|
161
|
+
return branches.find(function (branch) { return branch.id === branchId; }) || null;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Error getting cached branch by ID:', error);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
exports.getCachedBranchById = getCachedBranchById;
|
|
169
|
+
/**
|
|
170
|
+
* Utility function to get branches by name from cache
|
|
171
|
+
* If not found in cache, returns empty array (does not trigger API call)
|
|
172
|
+
*
|
|
173
|
+
* @param branchName - The name of the branch to search for
|
|
174
|
+
* @returns BranchBE[] - Array of matching branches or empty array
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const branches = getCachedBranchesByName('Main Branch');
|
|
178
|
+
* console.log(branches.length);
|
|
179
|
+
*/
|
|
180
|
+
var getCachedBranchesByName = function (branchName) {
|
|
181
|
+
if (!branchName) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
var branches = (0, exports.getCachedBranchesSync)().items;
|
|
186
|
+
return branches.filter(function (branch) {
|
|
187
|
+
return branch.branchName.toLowerCase().includes(branchName.toLowerCase());
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error('Error getting cached branches by name:', error);
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
exports.getCachedBranchesByName = getCachedBranchesByName;
|
|
196
|
+
/**
|
|
197
|
+
* Utility function to invalidate (remove) branches from cache
|
|
198
|
+
* Useful when branches have been updated and you want to force a refresh
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* invalidateBranchesCache();
|
|
202
|
+
* const freshBranches = await getCachedBranches();
|
|
203
|
+
*/
|
|
204
|
+
var invalidateBranchesCache = function () {
|
|
205
|
+
try {
|
|
206
|
+
localStorage.removeItem(type_1.LS_KEYS.BRANCHES);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error('Error invalidating branches cache:', error);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.invalidateBranchesCache = invalidateBranchesCache;
|
|
213
|
+
/**
|
|
214
|
+
* Utility function to preload branches into cache
|
|
215
|
+
* Useful to call on app initialization or login
|
|
216
|
+
*
|
|
217
|
+
* @returns Promise<{count:number, items: BranchBE[]}> - Array of preloaded branches
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* // On app initialization
|
|
221
|
+
* await preloadBranches();
|
|
222
|
+
*/
|
|
223
|
+
var preloadBranches = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
224
|
+
return __generator(this, function (_a) {
|
|
225
|
+
return [2 /*return*/, (0, exports.getCachedBranches)()];
|
|
226
|
+
});
|
|
227
|
+
}); };
|
|
228
|
+
exports.preloadBranches = preloadBranches;
|
|
229
|
+
/**
|
|
230
|
+
* Utility function to check if branches cache is stale
|
|
231
|
+
* Returns true if cache is older than 1 week or doesn't exist
|
|
232
|
+
*
|
|
233
|
+
* @returns boolean - True if cache is stale or doesn't exist
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* if (isBranchesCacheStale()) {
|
|
237
|
+
* await getCachedBranches(); // This will fetch fresh data
|
|
238
|
+
* }
|
|
239
|
+
*/
|
|
240
|
+
var isBranchesCacheStale = function () {
|
|
241
|
+
try {
|
|
242
|
+
var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BRANCHES);
|
|
243
|
+
if (!cachedData) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
var currentTime = new Date().getTime();
|
|
247
|
+
var cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
248
|
+
var ageInMs = currentTime - cachedTime;
|
|
249
|
+
return ageInMs >= constants_1.ONE_WEEK_IN_MS;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
console.error('Error checking branches cache staleness:', error);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
exports.isBranchesCacheStale = isBranchesCacheStale;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './cache';
|
|
1
2
|
import { BranchBE } from '../type';
|
|
2
3
|
type PrismaClient = any;
|
|
3
4
|
export interface ListBranchArgs {
|
|
@@ -55,4 +56,3 @@ export declare const updateBranch: ({ branchAddress, branchName, enabled, id, is
|
|
|
55
56
|
* @throws {Error} If branch ID is not provided or branch not found
|
|
56
57
|
*/
|
|
57
58
|
export declare const deleteBranch: ({ id, prisma, }: DeleteBranchArgs) => Promise<BranchBE>;
|
|
58
|
-
export {};
|
|
@@ -10,6 +10,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
13
27
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
28
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
29
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -57,6 +71,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
57
71
|
};
|
|
58
72
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
73
|
exports.deleteBranch = exports.updateBranch = exports.unitBranchById = exports.listBranch = void 0;
|
|
74
|
+
__exportStar(require("./cache"), exports);
|
|
60
75
|
var general_1 = require("../../../general");
|
|
61
76
|
/**
|
|
62
77
|
* Retrieves all branches from the database with pagination
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CompanyBE } from '../type';
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous utility function to get companies from cache only
|
|
4
|
+
* Returns cached data immediately if available and fresh, otherwise returns empty array
|
|
5
|
+
* Does not trigger any API calls
|
|
6
|
+
*
|
|
7
|
+
* @returns CompanyBE[] - Array of cached companies or empty array wrapper ({count, items})
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const companies = getCachedCompaniesSync();
|
|
11
|
+
* if (companies.items.length > 0) {
|
|
12
|
+
* console.log(companies.items[0].name);
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export declare const getCachedCompaniesSync: () => {
|
|
16
|
+
count: number;
|
|
17
|
+
items: CompanyBE[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Utility function to get companies from cache or fetch from API
|
|
21
|
+
*
|
|
22
|
+
* This function manages a localStorage cache of companies with the following logic:
|
|
23
|
+
* - If companies exist in cache and are less than 1 day old, return cached version
|
|
24
|
+
* - If companies exist but are older than 1 day, fetch fresh data and update cache
|
|
25
|
+
* - If companies don't exist in cache, fetch from API and cache them
|
|
26
|
+
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter companies
|
|
28
|
+
* @param filters - Optional filters object to apply additional filtering (bypasses cache)
|
|
29
|
+
* @param pageLimit - Number of companies to fetch (default: 100)
|
|
30
|
+
* @returns Promise<{count:number, items: CompanyBE[]}> - Paged companies
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const companies = await getCachedCompanies();
|
|
34
|
+
* console.log(companies.items[0].name);
|
|
35
|
+
*
|
|
36
|
+
* // With search
|
|
37
|
+
* const filtered = await getCachedCompanies('Tech Corp');
|
|
38
|
+
*
|
|
39
|
+
* // With filters
|
|
40
|
+
* const filteredByCountry = await getCachedCompanies(undefined, { country: 'USA' });
|
|
41
|
+
*/
|
|
42
|
+
export declare const getCachedCompanies: (searchQuery?: string, filters?: Record<string, unknown>, pageLimit?: number) => Promise<{
|
|
43
|
+
count: number;
|
|
44
|
+
items: CompanyBE[];
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Utility function to get a specific company by ID from cache
|
|
48
|
+
* If not found in cache, returns null (does not trigger API call)
|
|
49
|
+
*
|
|
50
|
+
* @param companyId - The ID of the company to retrieve
|
|
51
|
+
* @returns CompanyBE | null - The company or null if not found
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const company = getCachedCompanyById('company-123');
|
|
55
|
+
* if (company) {
|
|
56
|
+
* console.log(company.name);
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
export declare const getCachedCompanyById: (companyId: string) => CompanyBE | null;
|
|
60
|
+
/**
|
|
61
|
+
* Utility function to get companies by name from cache
|
|
62
|
+
* If not found in cache, returns empty array (does not trigger API call)
|
|
63
|
+
*
|
|
64
|
+
* @param name - The name of the company to search for
|
|
65
|
+
* @returns CompanyBE[] - Array of matching companies or empty array
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const companies = getCachedCompaniesByName('Tech');
|
|
69
|
+
* console.log(companies.length);
|
|
70
|
+
*/
|
|
71
|
+
export declare const getCachedCompaniesByName: (name: string) => CompanyBE[];
|
|
72
|
+
/**
|
|
73
|
+
* Utility function to invalidate (remove) companies from cache
|
|
74
|
+
* Useful when companies have been updated and you want to force a refresh
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* invalidateCompaniesCache();
|
|
78
|
+
* const freshCompanies = await getCachedCompanies();
|
|
79
|
+
*/
|
|
80
|
+
export declare const invalidateCompaniesCache: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Utility function to preload companies into cache
|
|
83
|
+
* Useful to call on app initialization or login
|
|
84
|
+
*
|
|
85
|
+
* @returns Promise<{count:number, items: CompanyBE[]}> - Array of preloaded companies
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // On app initialization
|
|
89
|
+
* await preloadCompanies();
|
|
90
|
+
*/
|
|
91
|
+
export declare const preloadCompanies: () => Promise<{
|
|
92
|
+
count: number;
|
|
93
|
+
items: CompanyBE[];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Utility function to check if companies cache is stale
|
|
97
|
+
* Returns true if cache is older than 1 day or doesn't exist
|
|
98
|
+
*
|
|
99
|
+
* @returns boolean - True if cache is stale or doesn't exist
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* if (isCompaniesCacheStale()) {
|
|
103
|
+
* await getCachedCompanies(); // This will fetch fresh data
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
export declare const isCompaniesCacheStale: () => boolean;
|