@katlux/providers 0.1.0-beta.80 → 0.1.1-alpha.100

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/index.d.mts CHANGED
@@ -1,5 +1,36 @@
1
- import { Ref } from 'vue';
1
+ /**
2
+ * types.ts — Framework-agnostic hydration and platform abstraction contracts.
3
+ */
4
+ interface ISSRHydrationAdapter {
5
+ /**
6
+ * Retrieve pre-hydrated SSR state for a key. Returns null if not present.
7
+ */
8
+ getSSRData<T>(key: string, context?: any): T | null;
9
+ /**
10
+ * Execute fetcher with SSR serialization/caching if in an SSR environment,
11
+ * or simply await fetcher() in standalone/client environments.
12
+ */
13
+ fetchWithSSR<T>(key: string, fetcher: () => Promise<T>, context?: any): Promise<T | null>;
14
+ /**
15
+ * Invalidate or clear SSR cache for a key (e.g. after mutations).
16
+ */
17
+ clearSSRData?(key: string, context?: any): void;
18
+ /**
19
+ * Extract SSR hydration payload dictionary (for cache initialization).
20
+ */
21
+ getSSRPayload?(context?: any): Record<string, any> | null;
22
+ }
23
+ interface IPlatformRouter {
24
+ getRoute(): {
25
+ query: Record<string, any>;
26
+ path?: string;
27
+ } | null;
28
+ getRouter(): any;
29
+ onReady?(cb: () => void): void;
30
+ }
2
31
 
32
+ type TDataProviderListener<T = any> = (provider: T) => void;
33
+ type TUnsubscribe = () => void;
3
34
  declare enum EDataFilterOperator {
4
35
  Equal = "==",
5
36
  NotEqual = "!=",
@@ -37,8 +68,45 @@ interface IRequestOptions {
37
68
  cacheKey?: string;
38
69
  query?: Record<string, any>;
39
70
  deduplicate?: boolean;
71
+ context?: any;
72
+ /** @deprecated Use `context` instead */
40
73
  nuxtApp?: any;
41
74
  disableCache?: boolean;
75
+ queue?: boolean;
76
+ queueLabel?: string;
77
+ label?: string;
78
+ tags?: string[];
79
+ signal?: AbortSignal;
80
+ }
81
+ /** Queue persistence backend with automatic fallback: IndexedDB → LocalStorage → Memory */
82
+ declare enum EQueueStorage {
83
+ Memory = "Memory",
84
+ LocalStorage = "LocalStorage",
85
+ IndexedDB = "IndexedDB"
86
+ }
87
+ /** Status of an item currently in the pending queue */
88
+ type TQueueItemStatus = 'pending' | 'flushing';
89
+ /** A single mutation operation waiting to be sent */
90
+ interface IQueuedOperation {
91
+ id: string;
92
+ url: string;
93
+ method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
94
+ options: IRequestOptions;
95
+ tags: string[];
96
+ label?: string;
97
+ createdAt: number;
98
+ flushAttempts: number;
99
+ status: TQueueItemStatus;
100
+ }
101
+ /** An operation that failed permanently and was moved to the dead-letter store */
102
+ interface IDeadLetterItem extends IQueuedOperation {
103
+ failedAt: number;
104
+ lastError: string;
105
+ httpStatus?: number;
106
+ }
107
+ /** Options for flush operations */
108
+ interface IFlushOptions {
109
+ tag?: string;
42
110
  }
43
111
  interface IKDatatableAction {
44
112
  action: Function;
@@ -68,18 +136,23 @@ type TPageDataHandler = (currentPage: number, pageSize: number, filter: IDataFil
68
136
  disableCache?: boolean;
69
137
  }) => IDataResult | Promise<IDataResult>;
70
138
  interface IDataProviderOptions {
139
+ idKey?: string;
71
140
  filter?: IDataFilter;
72
141
  sortList?: IDataSort[];
73
142
  pageSize?: number;
74
143
  currentPage?: number;
75
144
  SSR?: boolean;
145
+ initialLoad?: boolean;
76
146
  cacheStrategy?: ECacheStrategy;
77
147
  cacheLifetime?: number;
78
148
  deduplicate?: boolean;
149
+ context?: any;
150
+ /** @deprecated Use `context` instead for framework-agnostic SSR context */
79
151
  nuxtApp?: any;
80
152
  urlPageParam?: string;
81
153
  refreshOnMutation?: boolean;
82
154
  }
155
+
83
156
  interface ITreeNode {
84
157
  data: TDataRow;
85
158
  id: string | number;
@@ -94,6 +167,7 @@ interface ITreeNodeStatic {
94
167
  parentId: string | number | null;
95
168
  depth: number;
96
169
  hasChildren: boolean;
170
+ childIds?: (string | number)[];
97
171
  }
98
172
  type TreePaginationMode = 'all' | 'root';
99
173
  interface ITreeDataProviderOptions extends IDataProviderOptions {
@@ -102,6 +176,19 @@ interface ITreeDataProviderOptions extends IDataProviderOptions {
102
176
  expandedByDefault?: boolean;
103
177
  paginateBy?: TreePaginationMode;
104
178
  }
179
+ /**
180
+ * Tree-specific page data handler that includes tree parameters
181
+ * Server handles tree building, visibility, and pagination
182
+ */
183
+ type TTreePageDataHandler = (currentPage: number, pageSize: number, filter: IDataFilter, sortList: IDataSort[], treeParams: {
184
+ expandedNodes: (string | number)[] | Set<string | number>;
185
+ parentKey: string;
186
+ idKey: string;
187
+ paginateBy: TreePaginationMode;
188
+ expandedByDefault: boolean;
189
+ }, options?: {
190
+ disableCache?: boolean;
191
+ }) => IDataResult | Promise<IDataResult>;
105
192
  interface KProductItemData {
106
193
  id: string | number;
107
194
  title: string;
@@ -119,33 +206,72 @@ interface KProductRowAction {
119
206
  }
120
207
 
121
208
  declare abstract class ADataProvider {
122
- filter: Ref<IDataFilter | null>;
123
- sortList: Ref<IDataSort[]>;
124
- currentPage: Ref<number>;
125
- pageSize: Ref<number>;
126
- pageData: Ref<TDataRow[]>;
127
- rowCount: Ref<number>;
128
- loading: Ref<Boolean>;
129
- SSR: Ref<Boolean>;
130
- deduplicate: Ref<Boolean>;
131
- nuxtApp: any;
132
- urlPageParam: Ref<string>;
133
- selectedRows: Ref<any[]>;
134
- selectAll: Ref<boolean>;
209
+ idKey: string;
210
+ pageData: TDataRow[];
211
+ rowCount: number;
212
+ loading: boolean;
213
+ initialLoad: boolean;
214
+ error: any;
215
+ SSR: boolean;
216
+ deduplicate: boolean;
217
+ context: any;
218
+ get nuxtApp(): any;
219
+ set nuxtApp(val: any);
220
+ urlPageParam: string;
221
+ selectedRows: any[];
222
+ selectAll: boolean;
223
+ protected _currentPage: number;
224
+ protected _pageSize: number;
225
+ protected _filter: IDataFilter | null;
226
+ protected _sortList: IDataSort[];
227
+ get currentPage(): number;
228
+ set currentPage(page: number);
229
+ get pageSize(): number;
230
+ set pageSize(size: number);
231
+ get filter(): IDataFilter | null;
232
+ set filter(f: IDataFilter | null);
233
+ get sortList(): IDataSort[];
234
+ set sortList(s: IDataSort[]);
235
+ private _listeners;
236
+ private _debouncedFilterLoad;
135
237
  constructor(options?: IDataProviderOptions);
238
+ subscribe(listener: TDataProviderListener<this>): TUnsubscribe;
239
+ notify(): void;
240
+ getState(): {
241
+ pageData: TDataRow[];
242
+ rowCount: number;
243
+ currentPage: number;
244
+ pageSize: number;
245
+ loading: boolean;
246
+ initialLoad: boolean;
247
+ error: any;
248
+ filter: IDataFilter | null;
249
+ sortList: IDataSort[];
250
+ selectedRows: any[];
251
+ selectAll: boolean;
252
+ };
136
253
  setFilter(filter: IDataFilter | null): void;
137
254
  setSortList(sortList: IDataSort[]): void;
138
255
  setCurrentPage(currentPage: number): void;
139
256
  setPageSize(pageSize: number): void;
140
- abstract loadPageData(): void;
257
+ setSelectedRows(rows: any[]): void;
258
+ setSelectAll(val: boolean): void;
259
+ abstract loadPageData(options?: {
260
+ disableCache?: boolean;
261
+ signal?: AbortSignal;
262
+ }): void | Promise<void>;
141
263
  refresh(hardRefresh?: boolean): Promise<void>;
142
264
  }
143
265
 
144
266
  declare class CFlatClientDataProvider extends ADataProvider {
145
- allData: Ref<TDataRow[]>;
146
- filteredData: Ref<TDataRow[]>;
267
+ allData: TDataRow[];
268
+ filteredData: TDataRow[];
147
269
  constructor(options?: IDataProviderOptions);
148
270
  setData(data: TDataRow[]): void;
271
+ refreshData(options?: {
272
+ disableCache?: boolean;
273
+ }): Promise<void>;
274
+ refresh(hardRefresh?: boolean): Promise<void>;
149
275
  loadPageData(): Promise<void>;
150
276
  }
151
277
 
@@ -162,9 +288,14 @@ declare abstract class ACacheProvider {
162
288
 
163
289
  declare class RequestProvider {
164
290
  cacheProvider: ACacheProvider | null;
291
+ cacheStrategy?: ECacheStrategy;
165
292
  cacheLifetime: number | null;
166
293
  deduplicate: boolean;
167
294
  cacheKey: string;
295
+ /** Registry tags — set via useRequestProvider() or manually */
296
+ tags: string[];
297
+ /** If true, non-GET requests are enqueued instead of sent immediately */
298
+ queue: boolean;
168
299
  private static requestQueue;
169
300
  private static executing;
170
301
  private static requestsInFlight;
@@ -185,11 +316,11 @@ declare class RequestProvider {
185
316
  }
186
317
 
187
318
  declare abstract class AAPIDataProvider {
188
- apiUrl: Ref<string>;
189
- cacheStrategy: Ref<ECacheStrategy | null>;
190
- cacheLifetime: Ref<number>;
319
+ apiUrl: string;
320
+ cacheStrategy: ECacheStrategy | null;
321
+ cacheLifetime: number;
191
322
  requestProvider: RequestProvider;
192
- refreshOnMutation: Ref<boolean | undefined>;
323
+ refreshOnMutation: boolean | undefined;
193
324
  constructor(options?: IDataProviderOptions);
194
325
  abstract setAPIUrl(url: string): void;
195
326
  abstract create(item: any): Promise<void>;
@@ -198,13 +329,12 @@ declare abstract class AAPIDataProvider {
198
329
  }
199
330
 
200
331
  declare class CAPIFlatClientDataProvider extends CFlatClientDataProvider implements AAPIDataProvider {
201
- apiUrl: Ref<string>;
202
- contextKey: Ref<string>;
203
- initialLoad: Ref<boolean>;
332
+ apiUrl: string;
333
+ contextKey: string;
204
334
  requestProvider: RequestProvider;
205
- cacheStrategy: Ref<ECacheStrategy | null>;
206
- cacheLifetime: Ref<number>;
207
- refreshOnMutation: Ref<boolean | undefined>;
335
+ cacheStrategy: ECacheStrategy | null;
336
+ cacheLifetime: number;
337
+ refreshOnMutation: boolean | undefined;
208
338
  constructor(options?: IDataProviderOptions);
209
339
  setContextKey(key: string): void;
210
340
  refresh(hardRefresh?: boolean): Promise<void>;
@@ -219,24 +349,26 @@ declare class CAPIFlatClientDataProvider extends CFlatClientDataProvider impleme
219
349
  }
220
350
 
221
351
  declare class CFlatServerDataProvider extends ADataProvider {
222
- pageDataHandler: Ref<TPageDataHandler>;
223
- contextKey: Ref<string>;
224
- initialLoad: Ref<boolean>;
352
+ pageDataHandler: TPageDataHandler;
353
+ contextKey: string;
354
+ private latestRequestId;
355
+ private abortController;
225
356
  constructor(options?: IDataProviderOptions);
226
357
  setContextKey(key: string): void;
227
358
  setPageDataHandler(handler: TPageDataHandler): Promise<void>;
228
359
  loadPageData(options?: {
229
360
  disableCache?: boolean;
361
+ signal?: AbortSignal;
230
362
  }): Promise<void>;
231
363
  refresh(hardRefresh?: boolean): Promise<void>;
232
364
  }
233
365
 
234
366
  declare class CAPIFlatServerDataProvider extends CFlatServerDataProvider implements AAPIDataProvider {
235
- apiUrl: Ref<string>;
367
+ apiUrl: string;
236
368
  requestProvider: RequestProvider;
237
- cacheStrategy: Ref<ECacheStrategy | null>;
238
- cacheLifetime: Ref<number>;
239
- refreshOnMutation: Ref<boolean | undefined>;
369
+ cacheStrategy: ECacheStrategy | null;
370
+ cacheLifetime: number;
371
+ refreshOnMutation: boolean | undefined;
240
372
  constructor(options?: IDataProviderOptions);
241
373
  refresh(hardRefresh?: boolean): Promise<void>;
242
374
  refreshData(options?: {
@@ -244,6 +376,8 @@ declare class CAPIFlatServerDataProvider extends CFlatServerDataProvider impleme
244
376
  }): Promise<void>;
245
377
  setAPIUrl(url: string): Promise<void>;
246
378
  delete(items: any[]): Promise<void>;
379
+ create(item: any): Promise<void>;
380
+ update(item: any): Promise<void>;
247
381
  }
248
382
 
249
383
  declare class CTreeClientDataProvider extends CFlatClientDataProvider {
@@ -251,22 +385,31 @@ declare class CTreeClientDataProvider extends CFlatClientDataProvider {
251
385
  idKey: string;
252
386
  expandedByDefault: boolean;
253
387
  paginateBy: TreePaginationMode;
254
- expandedNodes: Ref<Set<string | number>>;
255
- private _staticNodes;
256
- private _nodeMap;
257
- private _sortedNodeIds;
388
+ expandedNodes: Set<string | number>;
389
+ private _staticNodesCache;
390
+ private _nodeMapCache;
391
+ private _sortedNodeIdsCache;
392
+ invalidateStaticCache(): void;
393
+ private get _staticNodes();
394
+ private get _nodeMap();
395
+ private get _sortedNodeIds();
258
396
  constructor(options?: ITreeDataProviderOptions);
397
+ setData(data: TDataRow[]): void;
259
398
  private buildStaticNodes;
260
399
  private computeSortedIds;
261
- private updatePageData;
262
400
  private isNodeVisible;
263
401
  private paginateNodes;
402
+ private updatePageData;
264
403
  loadPageData(): Promise<void>;
265
404
  get treeNodes(): ITreeNode[];
266
405
  get visibleRows(): ITreeNode[];
406
+ getAllNodes(): ITreeNode[];
407
+ getFlatNodes(): ITreeNode[];
267
408
  toggleNode(nodeId: string | number): void;
268
409
  expand(nodeId: string | number): void;
269
410
  collapse(nodeId: string | number): void;
411
+ expandNode(nodeId: string | number): void;
412
+ collapseNode(nodeId: string | number): void;
270
413
  expandAll(): void;
271
414
  collapseAll(): void;
272
415
  getNode(nodeId: string | number): ITreeNode | undefined;
@@ -275,13 +418,12 @@ declare class CTreeClientDataProvider extends CFlatClientDataProvider {
275
418
  }
276
419
 
277
420
  declare class CAPITreeClientDataProvider extends CTreeClientDataProvider implements AAPIDataProvider {
278
- apiUrl: Ref<string>;
279
- contextKey: Ref<string>;
280
- initialLoad: Ref<boolean>;
421
+ apiUrl: string;
422
+ contextKey: string;
281
423
  requestProvider: RequestProvider;
282
- cacheStrategy: Ref<ECacheStrategy | null>;
283
- cacheLifetime: Ref<number>;
284
- refreshOnMutation: Ref<boolean | undefined>;
424
+ cacheStrategy: ECacheStrategy | null;
425
+ cacheLifetime: number;
426
+ refreshOnMutation: boolean | undefined;
285
427
  constructor(options?: ITreeDataProviderOptions);
286
428
  setContextKey(key: string): void;
287
429
  refresh(hardRefresh?: boolean): Promise<void>;
@@ -295,19 +437,6 @@ declare class CAPITreeClientDataProvider extends CTreeClientDataProvider impleme
295
437
  delete(items: any[]): Promise<void>;
296
438
  }
297
439
 
298
- /**
299
- * Tree-specific page data handler that includes tree parameters
300
- * Server handles tree building, visibility, and pagination
301
- */
302
- type TTreePageDataHandler = (currentPage: number, pageSize: number, filter: IDataFilter, sortList: IDataSort[], treeParams: {
303
- expandedNodes: (string | number)[];
304
- parentKey: string;
305
- idKey: string;
306
- paginateBy: TreePaginationMode;
307
- expandedByDefault: boolean;
308
- }, options?: {
309
- disableCache?: boolean;
310
- }) => IDataResult | Promise<IDataResult>;
311
440
  /**
312
441
  * Server-side Tree Data Provider
313
442
  *
@@ -322,19 +451,21 @@ declare class CTreeServerDataProvider extends ADataProvider {
322
451
  idKey: string;
323
452
  expandedByDefault: boolean;
324
453
  paginateBy: TreePaginationMode;
325
- expandedNodes: Ref<Set<string | number>>;
326
- pageDataHandler: Ref<TTreePageDataHandler | null>;
327
- contextKey: Ref<string>;
328
- initialLoad: Ref<boolean>;
454
+ expandedNodes: Set<string | number>;
455
+ pageDataHandler: TTreePageDataHandler | null;
456
+ contextKey: string;
329
457
  constructor(options?: ITreeDataProviderOptions);
330
458
  setContextKey(key: string): void;
331
459
  setPageDataHandler(handler: TTreePageDataHandler): Promise<void>;
460
+ private latestRequestId;
461
+ private abortController;
332
462
  /**
333
463
  * Load page data from server
334
464
  * Server handles tree building, visibility, and pagination
335
465
  */
336
466
  loadPageData(options?: {
337
467
  disableCache?: boolean;
468
+ signal?: AbortSignal;
338
469
  }): Promise<void>;
339
470
  refresh(hardRefresh?: boolean): Promise<void>;
340
471
  toggleNode(nodeId: string | number): void;
@@ -353,11 +484,11 @@ declare class CTreeServerDataProvider extends ADataProvider {
353
484
  * - Automatic tree parameter serialization in query
354
485
  */
355
486
  declare class CAPITreeServerDataProvider extends CTreeServerDataProvider implements AAPIDataProvider {
356
- apiUrl: Ref<string>;
487
+ apiUrl: string;
357
488
  requestProvider: RequestProvider;
358
- cacheStrategy: Ref<ECacheStrategy | null>;
359
- cacheLifetime: Ref<number>;
360
- refreshOnMutation: Ref<boolean | undefined>;
489
+ cacheStrategy: ECacheStrategy | null;
490
+ cacheLifetime: number;
491
+ refreshOnMutation: boolean | undefined;
361
492
  constructor(options?: ITreeDataProviderOptions);
362
493
  refresh(hardRefresh?: boolean): Promise<void>;
363
494
  refreshData(options?: {
@@ -365,21 +496,90 @@ declare class CAPITreeServerDataProvider extends CTreeServerDataProvider impleme
365
496
  }): Promise<void>;
366
497
  setAPIUrl(url: string): Promise<void>;
367
498
  delete(items: any[]): Promise<void>;
499
+ create(item: any): Promise<void>;
500
+ update(item: any): Promise<void>;
501
+ }
502
+
503
+ /**
504
+ * KatluxIndexedDB
505
+ *
506
+ * Shared IndexedDB connection singleton for the entire @katlux/providers library.
507
+ * All IndexedDB consumers (CIndexedDBCache, RequestQueue) use this single connection,
508
+ * ensuring there is one database, one version number, and no versionchange conflicts.
509
+ *
510
+ * KatluxDB stores:
511
+ * cache — used by CIndexedDBCache
512
+ * queue — used by RequestQueue (pending operations)
513
+ * dead_letter — used by RequestQueue (permanently failed operations)
514
+ */
515
+ type TKatluxStore = 'cache' | 'queue' | 'dead_letter' | (string & {});
516
+ declare class KatluxIndexedDB {
517
+ private static db;
518
+ private static openPromise;
519
+ private static currentVersion;
520
+ private static customStores;
521
+ static readonly DB_NAME = "KatluxDB";
522
+ static get DB_VERSION(): number;
523
+ /**
524
+ * Opens (or returns the existing) shared IDBDatabase connection.
525
+ * Safe to call multiple times — always resolves to the same instance.
526
+ */
527
+ static open(): Promise<IDBDatabase>;
528
+ /**
529
+ * Dynamically ensures that an object store exists in the database.
530
+ * If not present, performs a database version bump and creates the store.
531
+ */
532
+ static ensureStore(storeName: string): Promise<IDBDatabase>;
533
+ /**
534
+ * Returns a transaction-bound object store.
535
+ * Convenience wrapper used by CIndexedDBCache, QueueStorage adapters, etc.
536
+ */
537
+ static getStore(storeName: TKatluxStore, mode: IDBTransactionMode): Promise<IDBObjectStore>;
538
+ /**
539
+ * For testing only — resets the singleton so tests can start fresh.
540
+ */
541
+ static _reset(): void;
368
542
  }
369
543
 
544
+ type CacheDriverLoader = () => Promise<{
545
+ getInstance: () => ACacheProvider;
546
+ }>;
370
547
  declare class CacheProviderFactory {
371
- static getProvider(strategy: ECacheStrategy): ACacheProvider | null;
548
+ private static instanceCache;
549
+ private static customDrivers;
550
+ private static readonly defaultLoaders;
551
+ /**
552
+ * Register a custom or pre-loaded cache provider driver
553
+ */
554
+ static registerDriver(strategy: string, loaderOrClass: CacheDriverLoader | {
555
+ getInstance: () => ACacheProvider;
556
+ }): void;
557
+ /**
558
+ * Asynchronously load and return the cache provider singleton for a strategy.
559
+ */
560
+ static getProvider(strategy: ECacheStrategy | string): Promise<ACacheProvider | null>;
561
+ /**
562
+ * Synchronously returns the cache provider if it was already loaded/instantiated,
563
+ * or undefined otherwise.
564
+ */
565
+ static getProviderSync(strategy: ECacheStrategy | string): ACacheProvider | undefined;
566
+ /**
567
+ * Clear cached singleton instances (useful for testing or cache resets)
568
+ */
569
+ static clearInstances(): void;
372
570
  }
373
571
 
374
572
  declare class CSessionCache extends ACacheProvider {
375
573
  private static instance;
376
574
  static getInstance(): CSessionCache;
377
- private static get storage();
575
+ static get storage(): Map<string, Map<string, ICacheEntry<any>>>;
378
576
  static getSnapshot(): Map<string, Map<string, ICacheEntry<any>>>;
577
+ private static cleanupTimer;
578
+ private static initCleanupTimer;
379
579
  private sessionIdCache;
380
580
  private sessionId;
381
581
  private readonly SESSION_ID_KEY;
382
- private constructor();
582
+ constructor();
383
583
  /**
384
584
  * Generate a UUID v4 sessionId
385
585
  */
@@ -401,11 +601,15 @@ declare class CCookieCache extends ACacheProvider {
401
601
  private static instance;
402
602
  static getInstance(): CCookieCache;
403
603
  type: string;
404
- private constructor();
604
+ constructor();
605
+ private getCookieKey;
606
+ private parseKeyFromCookieName;
607
+ private isClient;
405
608
  getKeyList(nuxtApp?: any): Promise<Array<string>>;
406
609
  get<T>(key: string, nuxtApp?: any): Promise<T | null>;
407
610
  set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void>;
408
611
  remove(key: string, nuxtApp?: any): Promise<void>;
612
+ removeByPrefix(prefix: string, nuxtApp?: any): Promise<void>;
409
613
  getRemainingTime(key: string, nuxtApp?: any): Promise<number | null>;
410
614
  cleanupExpired(): Promise<void>;
411
615
  }
@@ -428,14 +632,8 @@ declare class CLocalStorageCache extends ACacheProvider {
428
632
  declare class CIndexedDBCache extends ACacheProvider {
429
633
  private static instance;
430
634
  static getInstance(): CIndexedDBCache;
431
- private dbName;
432
- private storeName;
433
- private version;
434
- private dbPromise;
435
- setStore(storeName?: string): void;
436
635
  private constructor();
437
636
  private _hydrateFromPayload;
438
- private openDB;
439
637
  private getStore;
440
638
  getKeyList(nuxtApp?: any): Promise<Array<string>>;
441
639
  get<T>(key: string, nuxtApp?: any): Promise<T | null>;
@@ -478,5 +676,298 @@ declare class CApplicationCache extends ACacheProvider {
478
676
  cleanupExpired(): Promise<void>;
479
677
  }
480
678
 
481
- export { AAPIDataProvider, ADataProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CCookieCache, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CLocalStorageCache, CMemoryCache, CSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CacheProviderFactory, ECacheStrategy, EDataFilterOperator, RequestProvider };
482
- export type { ICacheEntry, IDataFilter, IDataProviderOptions, IDataResult, IDataSort, IKDatatableAction, IRequestOptions, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, KProductItemData, KProductRowAction, TDataRow, TPageDataHandler, TreePaginationMode };
679
+ interface IRegistryEntry {
680
+ provider: RequestProvider;
681
+ tags: string[];
682
+ }
683
+ /**
684
+ * RequestProviderRegistry
685
+ *
686
+ * Static singleton registry that maps RequestProvider instances to string tags.
687
+ * When a mutation completes on any tagged provider, the registry automatically
688
+ * calls refresh(true) on all GET-capable providers sharing any of those tags.
689
+ *
690
+ * Framework-agnostic — no Vue imports. Works in any JS environment.
691
+ *
692
+ * Usage:
693
+ * // Register (or use the useRequestProvider() Vue composable for auto-lifecycle)
694
+ * RequestProviderRegistry.register(myProvider, ['invoices', 'sales'])
695
+ *
696
+ * // Unregister manually (or automatically via useRequestProvider onUnmounted)
697
+ * RequestProviderRegistry.unregister(myProvider)
698
+ *
699
+ * // Manual targeted refresh
700
+ * await RequestProviderRegistry.refreshByTag('invoices', true)
701
+ *
702
+ * // Called internally by RequestProvider after a successful non-GET request
703
+ * await RequestProviderRegistry.notifyMutation(['invoices'])
704
+ */
705
+ declare class RequestProviderRegistry {
706
+ private static entries;
707
+ /**
708
+ * Register a provider with one or more tags.
709
+ * If the provider is already registered, its tags are updated.
710
+ */
711
+ static register(provider: RequestProvider, tags: string[]): void;
712
+ /**
713
+ * Unregister a provider from the registry.
714
+ * After this, the provider will no longer receive auto-refresh signals.
715
+ */
716
+ static unregister(provider: RequestProvider): void;
717
+ /**
718
+ * Manually refresh all providers matching a specific tag.
719
+ */
720
+ static refreshByTag(tag: string, hardRefresh?: boolean): Promise<void>;
721
+ /**
722
+ * Called internally by RequestProvider (after non-GET success) and by
723
+ * RequestQueue (after flush with at least one success).
724
+ *
725
+ * Finds all registered providers sharing any of the succeeded tags and
726
+ * calls refresh(true) once per unique provider (deduplication built in).
727
+ */
728
+ static notifyMutation(succeededTags: string[]): Promise<void>;
729
+ /**
730
+ * Returns a copy of all registry entries.
731
+ * Useful for debugging and testing.
732
+ */
733
+ static getEntries(): IRegistryEntry[];
734
+ /**
735
+ * Clears the entire registry.
736
+ * Use on app teardown (e.g., logout) or in tests.
737
+ */
738
+ static clear(): void;
739
+ }
740
+
741
+ /**
742
+ * RequestQueue
743
+ *
744
+ * Static class that manages the offline mutation queue and dead-letter store.
745
+ * Pure framework-agnostic TypeScript with subscription notifications.
746
+ *
747
+ * Design rules:
748
+ * - Stop-on-first-failure: flush halts when any item fails
749
+ * - No internal retry: the queue is the retry mechanism (items persist until flushed)
750
+ * - Partial refresh: registry refresh fires for succeeded tags only
751
+ * - Dead-letter is final: Katlux never auto-retries — app decides via retryOne() or discard()
752
+ *
753
+ * Usage:
754
+ * RequestQueue.setStorageBackend(EQueueStorage.IndexedDB)
755
+ * await RequestQueue.init() // call once at app startup
756
+ *
757
+ * // Hooks (set in app setup, not in components)
758
+ * RequestQueue.onDeadLetter((item, err) => toast.error(`Failed: ${item.label}`))
759
+ * RequestQueue.onFlushComplete((tags) => console.log('Synced tags:', tags))
760
+ * RequestQueue.onNetworkError((item) => toast.warn('Offline — will retry when back online'))
761
+ *
762
+ * // Flush when back online
763
+ * window.addEventListener('online', () => RequestQueue.flushAll())
764
+ */
765
+ declare class RequestQueue {
766
+ static queue: IQueuedOperation[];
767
+ static deadLetterQueue: IDeadLetterItem[];
768
+ static isFlushing: boolean;
769
+ private static _subscribers;
770
+ static subscribe(listener: () => void): () => void;
771
+ static notify(): void;
772
+ private static adapter;
773
+ private static initialized;
774
+ private static _onDeadLetter;
775
+ private static _onFlushComplete;
776
+ private static _onNetworkError;
777
+ /**
778
+ * Load persisted queue from storage into state.
779
+ * Call once at app startup, before any flush or enqueue operations.
780
+ */
781
+ static init(): Promise<void>;
782
+ /**
783
+ * Set the storage backend. Call before init().
784
+ * Defaults to IndexedDB with fallback to LocalStorage → Memory.
785
+ */
786
+ static setStorageBackend(backend: EQueueStorage): void;
787
+ static onDeadLetter(cb: (item: IDeadLetterItem, error: Error) => void): void;
788
+ static onFlushComplete(cb: (succeededTags: string[]) => void): void;
789
+ static onNetworkError(cb: (item: IQueuedOperation) => void): void;
790
+ /**
791
+ * Add an operation to the pending queue and persist it.
792
+ * Called internally by RequestProvider when queue: true.
793
+ * Returns the stable ID of the queued item.
794
+ */
795
+ static enqueue(operation: Omit<IQueuedOperation, 'id' | 'createdAt' | 'flushAttempts' | 'status'>): Promise<string>;
796
+ static getQueue(tag?: string): IQueuedOperation[];
797
+ static getDeadLetterQueue(tag?: string): IDeadLetterItem[];
798
+ /**
799
+ * Flush queued items in FIFO order.
800
+ * Stops on first failure. Refreshes registry for succeeded tags only.
801
+ */
802
+ static flushAll(options?: IFlushOptions): Promise<void>;
803
+ /**
804
+ * Flush a specific pending item by ID, independent of queue position.
805
+ * On success: triggers registry refresh for its own tags.
806
+ * On failure: moves to dead-letter independently.
807
+ */
808
+ static flushOne(id: string): Promise<void>;
809
+ /**
810
+ * Move a dead-letter item back to the FRONT of the pending queue for retry.
811
+ * App should call flushAll() afterwards.
812
+ */
813
+ static retryOne(id: string): Promise<void>;
814
+ /**
815
+ * Permanently remove an item from either the pending queue or dead-letter store.
816
+ */
817
+ static discard(id: string): Promise<void>;
818
+ /**
819
+ * Reorder the pending queue by providing an ordered array of IDs.
820
+ * Fully permissive — causal ordering is the app's responsibility.
821
+ */
822
+ static reorder(ids: string[]): void;
823
+ private static executeRequest;
824
+ private static moveToDeadLetter;
825
+ private static persistQueue;
826
+ private static persistDeadLetter;
827
+ /** For testing only */
828
+ static _reset(): void;
829
+ }
830
+
831
+ interface IQueueStorageAdapter {
832
+ loadQueue(): Promise<IQueuedOperation[]>;
833
+ saveQueue(items: IQueuedOperation[]): Promise<void>;
834
+ loadDeadLetter(): Promise<IDeadLetterItem[]>;
835
+ saveDeadLetter(items: IDeadLetterItem[]): Promise<void>;
836
+ }
837
+ declare class QueueStorageFactory {
838
+ private static indexedDBAdapter;
839
+ private static localStorageAdapter;
840
+ private static memoryAdapter;
841
+ /**
842
+ * Returns an adapter for the requested backend.
843
+ * Falls back automatically if the requested backend is unavailable:
844
+ * IndexedDB → LocalStorage → Memory
845
+ */
846
+ static getAdapter(backend: EQueueStorage): IQueueStorageAdapter;
847
+ static _reset(): void;
848
+ }
849
+
850
+ declare const compareIn: (rowValue: any, filterValue: any) => boolean;
851
+ declare const compareEqual: (rowValue: any, filterValue: any) => boolean;
852
+ declare const compareValues: (rowValue: any, filterValue: any) => number;
853
+ declare const compareAnd: (row: TDataRow, nested: any) => boolean;
854
+ declare const compareOr: (row: TDataRow, nested: any) => boolean;
855
+ declare const applyOperator: (operator: string, rowValue: any, filterValue: any) => boolean;
856
+ declare const evaluateFilter: (filter: IDataFilter, row: TDataRow) => boolean;
857
+ declare const filterTreeData: (nodes: any[], filter: IDataFilter, options: {
858
+ idKey: string;
859
+ parentKey: string;
860
+ }) => {
861
+ visibleNodes: any[];
862
+ expandedNodes: Set<string | number>;
863
+ };
864
+ declare const filterData: (data: any[], filter: IDataFilter, options?: {
865
+ treeOptions?: {
866
+ idKey: string;
867
+ parentKey: string;
868
+ };
869
+ }) => {
870
+ results: any[];
871
+ expandedNodes?: Set<string | number>;
872
+ };
873
+ declare const useFilterLogic: () => {
874
+ evaluateFilter: (filter: IDataFilter, row: TDataRow) => boolean;
875
+ filterTreeData: (nodes: any[], filter: IDataFilter, options: {
876
+ idKey: string;
877
+ parentKey: string;
878
+ }) => {
879
+ visibleNodes: any[];
880
+ expandedNodes: Set<string | number>;
881
+ };
882
+ filterData: (data: any[], filter: IDataFilter, options?: {
883
+ treeOptions?: {
884
+ idKey: string;
885
+ parentKey: string;
886
+ };
887
+ }) => {
888
+ results: any[];
889
+ expandedNodes?: Set<string | number>;
890
+ };
891
+ };
892
+
893
+ declare const sortData: (sortList: IDataSort[], rows: TDataRow[]) => TDataRow[];
894
+ declare const useSortLogic: () => {
895
+ sortData: (sortList: IDataSort[], rows: TDataRow[]) => TDataRow[];
896
+ };
897
+
898
+ /**
899
+ * Universal debounce utility
900
+ */
901
+ declare const useDebounce: <T extends (...args: any[]) => any>(callback: T, delay: number) => ((...args: Parameters<T>) => void);
902
+ declare const debounce: <T extends (...args: any[]) => any>(callback: T, delay: number) => ((...args: Parameters<T>) => void);
903
+
904
+ /**
905
+ * defaultAdapter.ts — Framework-agnostic default implementation of ISSRHydrationAdapter.
906
+ * Pure Vanilla JS / React / Node.js with zero framework dependencies.
907
+ */
908
+
909
+ declare class DefaultHydrationAdapter implements ISSRHydrationAdapter {
910
+ getSSRData<T>(key: string, context?: any): T | null;
911
+ fetchWithSSR<T>(key: string, fetcher: () => Promise<T>, context?: any): Promise<T | null>;
912
+ clearSSRData(key: string, context?: any): void;
913
+ getSSRPayload(context?: any): Record<string, any> | null;
914
+ }
915
+
916
+ /**
917
+ * nuxtAdapter.ts — Nuxt 3 implementation of ISSRHydrationAdapter.
918
+ * Bridges to Nuxt 3's useNuxtData, useAsyncData, and useNuxtApp when running in Nuxt.
919
+ */
920
+
921
+ declare class NuxtHydrationAdapter implements ISSRHydrationAdapter {
922
+ private fallback;
923
+ getSSRData<T>(key: string, context?: any): T | null;
924
+ fetchWithSSR<T>(key: string, fetcher: () => Promise<T>, context?: any): Promise<T | null>;
925
+ clearSSRData(key: string, context?: any): void;
926
+ getSSRPayload(context?: any): Record<string, any> | null;
927
+ }
928
+
929
+ /**
930
+ * index.ts — Framework-agnostic hydration and platform bridge.
931
+ * Provides unified, safe methods for SSR hydration, routing, and lifecycle hooks.
932
+ */
933
+
934
+ declare function getHydrationAdapter(): ISSRHydrationAdapter;
935
+ declare function setHydrationAdapter(adapter: ISSRHydrationAdapter): void;
936
+ /**
937
+ * Retrieve SSR state for a key. Returns null if not found.
938
+ */
939
+ declare function getSSRData<T>(key: string, context?: any): T | null;
940
+ /**
941
+ * Execute fetcher with SSR caching/serialization or fallback directly.
942
+ */
943
+ declare function fetchWithSSR<T>(key: string, fetcher: () => Promise<T>, context?: any): Promise<T | null>;
944
+ /**
945
+ * Clear SSR data for a key.
946
+ */
947
+ declare function clearSSRData(key: string, context?: any): void;
948
+ /**
949
+ * Extract SSR payload dictionary for hydration of memory/storage caches.
950
+ */
951
+ declare function getSSRPayload(context?: any): Record<string, any> | null;
952
+ /**
953
+ * Safe platform app accessor.
954
+ */
955
+ declare function getPlatformApp(): any;
956
+ /**
957
+ * Safe route accessor with browser URLSearchParams fallback for React/Vanilla.
958
+ */
959
+ declare function getAppRoute(): {
960
+ query: Record<string, any>;
961
+ path?: string;
962
+ } | null;
963
+ /**
964
+ * Safe router accessor with window.history fallback for React/Vanilla.
965
+ */
966
+ declare function getAppRouter(): any;
967
+ /**
968
+ * Register a callback when platform hydration is ready or DOMContentLoaded.
969
+ */
970
+ declare function onPlatformReady(cb: () => void): void;
971
+
972
+ export { AAPIDataProvider, ADataProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CCookieCache, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CLocalStorageCache, CMemoryCache, CSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CacheProviderFactory, DefaultHydrationAdapter, ECacheStrategy, EDataFilterOperator, EQueueStorage, KatluxIndexedDB, NuxtHydrationAdapter, QueueStorageFactory, RequestProvider, RequestProviderRegistry, RequestQueue, applyOperator, clearSSRData, compareAnd, compareEqual, compareIn, compareOr, compareValues, debounce, evaluateFilter, fetchWithSSR, filterData, filterTreeData, getAppRoute, getAppRouter, getHydrationAdapter, getPlatformApp, getSSRData, getSSRPayload, onPlatformReady, setHydrationAdapter, sortData, useDebounce, useFilterLogic, useSortLogic };
973
+ export type { CacheDriverLoader, ICacheEntry, IDataFilter, IDataProviderOptions, IDataResult, IDataSort, IDeadLetterItem, IFlushOptions, IKDatatableAction, IPlatformRouter, IQueueStorageAdapter, IQueuedOperation, IRequestOptions, ISSRHydrationAdapter, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, KProductItemData, KProductRowAction, TDataProviderListener, TDataRow, TKatluxStore, TPageDataHandler, TQueueItemStatus, TTreePageDataHandler, TUnsubscribe, TreePaginationMode };