@keq-request/cache 5.0.0-alpha.10

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.
Files changed (117) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/LICENSE +21 -0
  3. package/dist/cache-entry/cache-entry.d.ts +17 -0
  4. package/dist/cache-entry/cache-entry.d.ts.map +1 -0
  5. package/dist/cache-entry/index.d.ts +4 -0
  6. package/dist/cache-entry/index.d.ts.map +1 -0
  7. package/dist/cache-entry/types/cache-entry-build-options.d.ts +8 -0
  8. package/dist/cache-entry/types/cache-entry-build-options.d.ts.map +1 -0
  9. package/dist/cache-entry/types/cache-entry-options.d.ts +7 -0
  10. package/dist/cache-entry/types/cache-entry-options.d.ts.map +1 -0
  11. package/dist/cache.d.ts +30 -0
  12. package/dist/cache.d.ts.map +1 -0
  13. package/dist/constants/eviction.enum.d.ts +7 -0
  14. package/dist/constants/eviction.enum.d.ts.map +1 -0
  15. package/dist/constants/strategy.enum.d.ts +7 -0
  16. package/dist/constants/strategy.enum.d.ts.map +1 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1102 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/index.mjs +1059 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/storage/index.d.ts +6 -0
  24. package/dist/storage/index.d.ts.map +1 -0
  25. package/dist/storage/indexed-db-storage/base-indexed-db-storage.d.ts +24 -0
  26. package/dist/storage/indexed-db-storage/base-indexed-db-storage.d.ts.map +1 -0
  27. package/dist/storage/indexed-db-storage/constants/default-table-name.d.ts +2 -0
  28. package/dist/storage/indexed-db-storage/constants/default-table-name.d.ts.map +1 -0
  29. package/dist/storage/indexed-db-storage/indexed-db-storage.d.ts +12 -0
  30. package/dist/storage/indexed-db-storage/indexed-db-storage.d.ts.map +1 -0
  31. package/dist/storage/indexed-db-storage/lfu-indexed-db-storage.d.ts +11 -0
  32. package/dist/storage/indexed-db-storage/lfu-indexed-db-storage.d.ts.map +1 -0
  33. package/dist/storage/indexed-db-storage/lru-indexed-db-storage.d.ts +11 -0
  34. package/dist/storage/indexed-db-storage/lru-indexed-db-storage.d.ts.map +1 -0
  35. package/dist/storage/indexed-db-storage/random-indexed-db-storage.d.ts +11 -0
  36. package/dist/storage/indexed-db-storage/random-indexed-db-storage.d.ts.map +1 -0
  37. package/dist/storage/indexed-db-storage/ttl-indexed-db-storage.d.ts +11 -0
  38. package/dist/storage/indexed-db-storage/ttl-indexed-db-storage.d.ts.map +1 -0
  39. package/dist/storage/indexed-db-storage/types/indexed-db-entry-metadata.d.ts +12 -0
  40. package/dist/storage/indexed-db-storage/types/indexed-db-entry-metadata.d.ts.map +1 -0
  41. package/dist/storage/indexed-db-storage/types/indexed-db-entry-response.d.ts +8 -0
  42. package/dist/storage/indexed-db-storage/types/indexed-db-entry-response.d.ts.map +1 -0
  43. package/dist/storage/indexed-db-storage/types/indexed-db-entry-visits.d.ts +14 -0
  44. package/dist/storage/indexed-db-storage/types/indexed-db-entry-visits.d.ts.map +1 -0
  45. package/dist/storage/indexed-db-storage/types/indexed-db-schema.d.ts +29 -0
  46. package/dist/storage/indexed-db-storage/types/indexed-db-schema.d.ts.map +1 -0
  47. package/dist/storage/indexed-db-storage/types/indexed-db-storage-options.d.ts +14 -0
  48. package/dist/storage/indexed-db-storage/types/indexed-db-storage-options.d.ts.map +1 -0
  49. package/dist/storage/indexed-db-storage/types/indexed-db-storage-size.d.ts +13 -0
  50. package/dist/storage/indexed-db-storage/types/indexed-db-storage-size.d.ts.map +1 -0
  51. package/dist/storage/internal-storage/internal-storage.d.ts +16 -0
  52. package/dist/storage/internal-storage/internal-storage.d.ts.map +1 -0
  53. package/dist/storage/internal-storage/types/events.d.ts +16 -0
  54. package/dist/storage/internal-storage/types/events.d.ts.map +1 -0
  55. package/dist/storage/internal-storage/types/storage-options.d.ts +20 -0
  56. package/dist/storage/internal-storage/types/storage-options.d.ts.map +1 -0
  57. package/dist/storage/keq-cache-storage.d.ts +20 -0
  58. package/dist/storage/keq-cache-storage.d.ts.map +1 -0
  59. package/dist/storage/memory-storage/base-memory-storage.d.ts +26 -0
  60. package/dist/storage/memory-storage/base-memory-storage.d.ts.map +1 -0
  61. package/dist/storage/memory-storage/lfu-memory-storage.d.ts +11 -0
  62. package/dist/storage/memory-storage/lfu-memory-storage.d.ts.map +1 -0
  63. package/dist/storage/memory-storage/lru-memory-storage.d.ts +11 -0
  64. package/dist/storage/memory-storage/lru-memory-storage.d.ts.map +1 -0
  65. package/dist/storage/memory-storage/memory-storage.d.ts +12 -0
  66. package/dist/storage/memory-storage/memory-storage.d.ts.map +1 -0
  67. package/dist/storage/memory-storage/random-memory-storage.d.ts +11 -0
  68. package/dist/storage/memory-storage/random-memory-storage.d.ts.map +1 -0
  69. package/dist/storage/memory-storage/ttl-memory-storage.d.ts +11 -0
  70. package/dist/storage/memory-storage/ttl-memory-storage.d.ts.map +1 -0
  71. package/dist/storage/memory-storage/types/memory-storage-options.d.ts +9 -0
  72. package/dist/storage/memory-storage/types/memory-storage-options.d.ts.map +1 -0
  73. package/dist/storage/memory-storage/types/memory-storage-size.d.ts +13 -0
  74. package/dist/storage/memory-storage/types/memory-storage-size.d.ts.map +1 -0
  75. package/dist/storage/multi-tier-storage/index.d.ts +2 -0
  76. package/dist/storage/multi-tier-storage/index.d.ts.map +1 -0
  77. package/dist/storage/multi-tier-storage/multi-tier-storage.d.ts +36 -0
  78. package/dist/storage/multi-tier-storage/multi-tier-storage.d.ts.map +1 -0
  79. package/dist/storage/multi-tier-storage/types/multi-tier-storage-options.d.ts +5 -0
  80. package/dist/storage/multi-tier-storage/types/multi-tier-storage-options.d.ts.map +1 -0
  81. package/dist/storage/tier-storage/index.d.ts +3 -0
  82. package/dist/storage/tier-storage/index.d.ts.map +1 -0
  83. package/dist/storage/tier-storage/tier-storage.d.ts +15 -0
  84. package/dist/storage/tier-storage/tier-storage.d.ts.map +1 -0
  85. package/dist/storage/tier-storage/types/tier-storage-options.d.ts +21 -0
  86. package/dist/storage/tier-storage/types/tier-storage-options.d.ts.map +1 -0
  87. package/dist/strategies/cache-first.d.ts +3 -0
  88. package/dist/strategies/cache-first.d.ts.map +1 -0
  89. package/dist/strategies/network-first.d.ts +3 -0
  90. package/dist/strategies/network-first.d.ts.map +1 -0
  91. package/dist/strategies/network-only.d.ts +3 -0
  92. package/dist/strategies/network-only.d.ts.map +1 -0
  93. package/dist/strategies/stale-while-revalidate.d.ts +3 -0
  94. package/dist/strategies/stale-while-revalidate.d.ts.map +1 -0
  95. package/dist/strategies/utils/cache-context.d.ts +5 -0
  96. package/dist/strategies/utils/cache-context.d.ts.map +1 -0
  97. package/dist/strategies/utils/index.d.ts +2 -0
  98. package/dist/strategies/utils/index.d.ts.map +1 -0
  99. package/dist/types/keq-cache-key.d.ts +3 -0
  100. package/dist/types/keq-cache-key.d.ts.map +1 -0
  101. package/dist/types/keq-cache-option.d.ts +24 -0
  102. package/dist/types/keq-cache-option.d.ts.map +1 -0
  103. package/dist/types/keq-cache-parameters.d.ts +12 -0
  104. package/dist/types/keq-cache-parameters.d.ts.map +1 -0
  105. package/dist/types/keq-cache-rule.d.ts +6 -0
  106. package/dist/types/keq-cache-rule.d.ts.map +1 -0
  107. package/dist/types/keq-cache-strategy.d.ts +6 -0
  108. package/dist/types/keq-cache-strategy.d.ts.map +1 -0
  109. package/dist/types/strategies-options.d.ts +14 -0
  110. package/dist/types/strategies-options.d.ts.map +1 -0
  111. package/dist/utils/debug.d.ts +2 -0
  112. package/dist/utils/debug.d.ts.map +1 -0
  113. package/dist/utils/get-response-bytes.d.ts +2 -0
  114. package/dist/utils/get-response-bytes.d.ts.map +1 -0
  115. package/dist/utils/random.d.ts +2 -0
  116. package/dist/utils/random.d.ts.map +1 -0
  117. package/package.json +58 -0
@@ -0,0 +1,12 @@
1
+ import { Promisable } from 'type-fest';
2
+ import { MemoryStorageOptions } from './types/memory-storage-options.js';
3
+ import { CacheEntry } from '../../cache-entry/cache-entry.js';
4
+ import { KeqCacheStorage } from '../keq-cache-storage.js';
5
+ export declare class MemoryStorage extends KeqCacheStorage {
6
+ private storage;
7
+ constructor(options?: MemoryStorageOptions);
8
+ set(entry: CacheEntry): Promisable<void>;
9
+ get(key: string): Promisable<CacheEntry | undefined>;
10
+ remove(key: string): Promisable<void>;
11
+ }
12
+ //# sourceMappingURL=memory-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/memory-storage/memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAOtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,qBAAa,aAAc,SAAQ,eAAe;IAChD,OAAO,CAAC,OAAO,CAAiB;gBAEpB,OAAO,CAAC,EAAE,oBAAoB;IAkB1C,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC;IAIxC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,UAAU,GAAG,SAAS,CAAC;IAIpD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;CAGtC"}
@@ -0,0 +1,11 @@
1
+ import { BaseMemoryStorage } from './base-memory-storage.js';
2
+ import { MemoryStorageOptions } from './types/memory-storage-options.js';
3
+ import { CacheEntry } from '../../cache-entry/cache-entry.js';
4
+ export declare class RandomMemoryStorage extends BaseMemoryStorage {
5
+ constructor(options?: MemoryStorageOptions);
6
+ get(key: string): CacheEntry | undefined;
7
+ set(value: CacheEntry): void;
8
+ remove(key: string): void;
9
+ protected evict(expectSize: number): boolean;
10
+ }
11
+ //# sourceMappingURL=random-memory-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random-memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/memory-storage/random-memory-storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAGzD,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC5C,OAAO,CAAC,EAAE,oBAAoB;IAI1C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAMxC,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAK5B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CA0B7C"}
@@ -0,0 +1,11 @@
1
+ import { BaseMemoryStorage } from './base-memory-storage.js';
2
+ import { MemoryStorageOptions } from './types/memory-storage-options.js';
3
+ import { CacheEntry } from '../../cache-entry/cache-entry.js';
4
+ export declare class TTLMemoryStorage extends BaseMemoryStorage {
5
+ constructor(options?: MemoryStorageOptions);
6
+ get(key: string): CacheEntry | undefined;
7
+ set(value: CacheEntry): void;
8
+ remove(key: string): void;
9
+ protected evict(expectSize: number): boolean;
10
+ }
11
+ //# sourceMappingURL=ttl-memory-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttl-memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/memory-storage/ttl-memory-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAGzD,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACzC,OAAO,CAAC,EAAE,oBAAoB;IAI1C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAMxC,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAK5B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CAmC7C"}
@@ -0,0 +1,9 @@
1
+ import { Eviction } from '../../../constants/eviction.enum.js';
2
+ import { InternalStorageOptions } from '../../../storage/internal-storage/types/storage-options.js';
3
+ export interface MemoryStorageOptions extends InternalStorageOptions {
4
+ /**
5
+ * @default Eviction.LRU
6
+ */
7
+ eviction?: Eviction;
8
+ }
9
+ //# sourceMappingURL=memory-storage-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage-options.d.ts","sourceRoot":"","sources":["../../../../src/storage/memory-storage/types/memory-storage-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAE5F,MAAM,WAAW,oBAAqB,SAAQ,sBAAsB;IAClE;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB"}
@@ -0,0 +1,13 @@
1
+ export interface MemoryStorageSize {
2
+ /**
3
+ * @en The size of the used storage
4
+ * @zh 已使用的Storage大小
5
+ */
6
+ used: number;
7
+ /**
8
+ * @en The size of the free storage
9
+ * @zh 剩余的Storage大小
10
+ */
11
+ free: number;
12
+ }
13
+ //# sourceMappingURL=memory-storage-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage-size.d.ts","sourceRoot":"","sources":["../../../../src/storage/memory-storage/types/memory-storage-size.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;CACb"}
@@ -0,0 +1,2 @@
1
+ export * from './multi-tier-storage.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/multi-tier-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { CacheEntry } from '../../cache-entry/cache-entry.js';
2
+ import { KeqCacheStorage } from '../keq-cache-storage.js';
3
+ import { MultiTierStorageOptions } from './types/multi-tier-storage-options.js';
4
+ /**
5
+ * @en Multi-tier cache storage that manages multiple KeqCacheStorage instances in tiers
6
+ * @zh 多层缓存存储,管理多个分层的 KeqCacheStorage 实例
7
+ */
8
+ export declare class MultiTierStorage extends KeqCacheStorage {
9
+ private readonly storages;
10
+ /**
11
+ * @param storages Array of storage instances ordered by performance (fastest first)
12
+ * @zh 按性价比排序的存储实例数组,排在前面的成本低,排在后面的成本高
13
+ */
14
+ constructor(options: MultiTierStorageOptions);
15
+ /**
16
+ * @en Get cache entry, searching from lowest to highest tier
17
+ * @zh 获取缓存条目,从最底层到高层依次搜索
18
+ */
19
+ get(key: string): Promise<CacheEntry | undefined>;
20
+ /**
21
+ * @en Set cache entry to all tiers concurrently
22
+ * @zh 并发写入所有层的缓存
23
+ */
24
+ set(entry: CacheEntry): Promise<void>;
25
+ /**
26
+ * @en Remove cache entry from all tiers
27
+ * @zh 从所有层删除缓存条目
28
+ */
29
+ remove(key: string): Promise<void>;
30
+ /**
31
+ * @en Sync cache entry to all lower tiers (tiers with index < currentTierIndex)
32
+ * @zh 将缓存条目同步到所有低层存储(索引小于当前层的存储)
33
+ */
34
+ private syncToLowerTiers;
35
+ }
36
+ //# sourceMappingURL=multi-tier-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-tier-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/multi-tier-storage/multi-tier-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAE/E;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAE5C;;;OAGG;gBACS,OAAO,EAAE,uBAAuB;IAU5C;;;OAGG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAkBvD;;;OAGG;IACG,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxC;;;OAGG;YACW,gBAAgB;CAoB/B"}
@@ -0,0 +1,5 @@
1
+ import { KeqCacheStorage } from '../../../storage/keq-cache-storage.js';
2
+ export interface MultiTierStorageOptions {
3
+ tiers: KeqCacheStorage[];
4
+ }
5
+ //# sourceMappingURL=multi-tier-storage-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-tier-storage-options.d.ts","sourceRoot":"","sources":["../../../../src/storage/multi-tier-storage/types/multi-tier-storage-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAEhE,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,eAAe,EAAE,CAAA;CACzB"}
@@ -0,0 +1,3 @@
1
+ export { TierStorage } from './tier-storage.js';
2
+ export type { TierStorageOptions } from './types/tier-storage-options.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/tier-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { MultiTierStorage } from '../multi-tier-storage/multi-tier-storage.js';
2
+ import { TierStorageOptions } from './types/tier-storage-options.js';
3
+ /**
4
+ * @en Two-tier cache storage that combines MemoryStorage (L1) and IndexedDBStorage (L2)
5
+ * @zh 二级缓存存储,结合了MemoryStorage(一级)和IndexedDBStorage(二级)
6
+ *
7
+ * This is a convenience wrapper around MultiTierStorage that provides:
8
+ * - Fast in-memory cache (L1)
9
+ * - Persistent IndexedDB cache (L2)
10
+ * - Simplified configuration options
11
+ */
12
+ export declare class TierStorage extends MultiTierStorage {
13
+ constructor(options?: TierStorageOptions);
14
+ }
15
+ //# sourceMappingURL=tier-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tier-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/tier-storage/tier-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAEpE;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,gBAAgB;gBACnC,OAAO,CAAC,EAAE,kBAAkB;CAezC"}
@@ -0,0 +1,21 @@
1
+ import { MemoryStorageOptions } from '../../../storage/memory-storage/types/memory-storage-options.js';
2
+ import { IndexedDbStorageOptions } from '../../../storage/indexed-db-storage/types/indexed-db-storage-options.js';
3
+ import { MemoryStorage } from '../../../storage/memory-storage/memory-storage.js';
4
+ import { IndexedDBStorage } from '../../../storage/indexed-db-storage/indexed-db-storage.js';
5
+ /**
6
+ * @en Configuration options for TierStorage
7
+ * @zh TierStorage 的配置选项
8
+ */
9
+ export interface TierStorageOptions {
10
+ /**
11
+ * @en Memory storage instance or options for the memory storage (L1 cache)
12
+ * @zh 内存存储实例或配置选项(一级缓存)
13
+ */
14
+ memory?: MemoryStorage | MemoryStorageOptions;
15
+ /**
16
+ * @en IndexedDB storage instance or options for the IndexedDB storage (L2 cache)
17
+ * @zh IndexedDB 存储实例或配置选项(二级缓存)
18
+ */
19
+ indexedDB?: IndexedDBStorage | IndexedDbStorageOptions;
20
+ }
21
+ //# sourceMappingURL=tier-storage-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tier-storage-options.d.ts","sourceRoot":"","sources":["../../../../src/storage/tier-storage/types/tier-storage-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAA;AAC/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAA;AAC1G,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAA;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAA;AAErF;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,GAAG,oBAAoB,CAAA;IAE7C;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAA;CACvD"}
@@ -0,0 +1,3 @@
1
+ import { KeqCacheStrategy } from '../types/keq-cache-strategy.js';
2
+ export declare const cacheFirst: KeqCacheStrategy;
3
+ //# sourceMappingURL=cache-first.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-first.d.ts","sourceRoot":"","sources":["../../src/strategies/cache-first.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAIhE,eAAO,MAAM,UAAU,EAAE,gBA0BxB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { KeqCacheStrategy } from '../types/keq-cache-strategy.js';
2
+ export declare const networkFirst: KeqCacheStrategy;
3
+ //# sourceMappingURL=network-first.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-first.d.ts","sourceRoot":"","sources":["../../src/strategies/network-first.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAKhE,eAAO,MAAM,YAAY,EAAE,gBA4B1B,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { KeqCacheStrategy } from '../types/keq-cache-strategy.js';
2
+ export declare const networkOnly: KeqCacheStrategy;
3
+ //# sourceMappingURL=network-only.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-only.d.ts","sourceRoot":"","sources":["../../src/strategies/network-only.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAIhE,eAAO,MAAM,WAAW,EAAE,gBAIzB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { KeqCacheStrategy } from '../types/keq-cache-strategy.js';
2
+ export declare const staleWhileRevalidate: KeqCacheStrategy;
3
+ //# sourceMappingURL=stale-while-revalidate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stale-while-revalidate.d.ts","sourceRoot":"","sources":["../../src/strategies/stale-while-revalidate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAIhE,eAAO,MAAM,oBAAoB,EAAE,gBA6ClC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { KeqContext, KeqSharedContext } from 'keq';
2
+ import { CacheEntry } from '../../cache-entry';
3
+ import { StrategyOptions } from '../../types/strategies-options';
4
+ export declare function cacheContext(opts: StrategyOptions, context: KeqContext | KeqSharedContext): Promise<CacheEntry | undefined>;
5
+ //# sourceMappingURL=cache-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-context.d.ts","sourceRoot":"","sources":["../../../src/strategies/utils/cache-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,wBAAsB,YAAY,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,GAAG,gBAAgB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAejI"}
@@ -0,0 +1,2 @@
1
+ export * from './cache-context.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strategies/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { KeqContext } from 'keq';
2
+ export type KeqCacheKey = string | ((context: KeqContext) => string);
3
+ //# sourceMappingURL=keq-cache-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keq-cache-key.d.ts","sourceRoot":"","sources":["../../src/types/keq-cache-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAGhC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAC,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { KeqCacheStrategy } from './keq-cache-strategy.js';
2
+ import { KeqCacheKey } from './keq-cache-key.js';
3
+ export interface KeqCacheOption {
4
+ /**
5
+ * Cache Key
6
+ */
7
+ key?: KeqCacheKey;
8
+ /**
9
+ * @default Strategy.NETWORK_FIRST
10
+ */
11
+ strategy: KeqCacheStrategy;
12
+ /**
13
+ * @en seconds
14
+ * @zh 秒
15
+ *
16
+ * @default Infinity
17
+ */
18
+ ttl?: number;
19
+ /**
20
+ * If exclude is true, the request will not be cached.
21
+ */
22
+ exclude?: (res: Response) => (Promise<boolean> | boolean);
23
+ }
24
+ //# sourceMappingURL=keq-cache-option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keq-cache-option.d.ts","sourceRoot":"","sources":["../../src/types/keq-cache-option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,WAAW,CAAA;IAEjB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAA;IAE1B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAA;CAC1D"}
@@ -0,0 +1,12 @@
1
+ import { KeqContext } from 'keq';
2
+ import { KeqCacheRule } from './keq-cache-rule.js';
3
+ import { KeqCacheStorage } from '../storage/keq-cache-storage.js';
4
+ export interface KeqCacheParameters {
5
+ storage: KeqCacheStorage;
6
+ /**
7
+ * Cache Key Factory
8
+ */
9
+ keyFactory?: (context: KeqContext) => string;
10
+ rules?: KeqCacheRule[];
11
+ }
12
+ //# sourceMappingURL=keq-cache-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keq-cache-parameters.d.ts","sourceRoot":"","sources":["../../src/types/keq-cache-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAGhE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,eAAe,CAAA;IAExB;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAA;IAE5C,KAAK,CAAC,EAAE,YAAY,EAAE,CAAA;CACvB"}
@@ -0,0 +1,6 @@
1
+ import { KeqContext } from 'keq';
2
+ import { KeqCacheOption } from './keq-cache-option.js';
3
+ export interface KeqCacheRule extends KeqCacheOption {
4
+ pattern?: RegExp | ((ctx: KeqContext) => boolean) | true;
5
+ }
6
+ //# sourceMappingURL=keq-cache-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keq-cache-rule.d.ts","sourceRoot":"","sources":["../../src/types/keq-cache-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAGtD,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,GAAG,IAAI,CAAA;CACzD"}
@@ -0,0 +1,6 @@
1
+ import { KeqExecutionContext, KeqNext } from 'keq';
2
+ import { StrategyOptions } from './strategies-options.js';
3
+ export interface KeqCacheStrategy {
4
+ (options: StrategyOptions): (context: KeqExecutionContext, next: KeqNext) => Promise<void>;
5
+ }
6
+ //# sourceMappingURL=keq-cache-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keq-cache-strategy.d.ts","sourceRoot":"","sources":["../../src/types/keq-cache-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGzD,MAAM,WAAW,gBAAgB;IAC/B,CAAC,OAAO,EAAE,eAAe,GAAG,CAAC,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3F"}
@@ -0,0 +1,14 @@
1
+ import { KeqCacheStorage } from '../storage/keq-cache-storage.js';
2
+ export interface StrategyOptions {
3
+ key: string;
4
+ /**
5
+ * @en seconds
6
+ * @zh 秒
7
+ *
8
+ * @default Infinity
9
+ */
10
+ ttl?: number;
11
+ storage: KeqCacheStorage;
12
+ exclude?: (res: Response) => (boolean | Promise<boolean>);
13
+ }
14
+ //# sourceMappingURL=strategies-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies-options.d.ts","sourceRoot":"","sources":["../../src/types/strategies-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAGhE,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IAEX;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ,OAAO,EAAE,eAAe,CAAA;IAExB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;CAC1D"}
@@ -0,0 +1,2 @@
1
+ export declare function debug(...args: unknown[]): void;
2
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE9C"}
@@ -0,0 +1,2 @@
1
+ export declare function getResponseBytes(response: Response): Promise<number>;
2
+ //# sourceMappingURL=get-response-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-response-bytes.d.ts","sourceRoot":"","sources":["../../src/utils/get-response-bytes.ts"],"names":[],"mappings":"AAAA,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1E"}
@@ -0,0 +1,2 @@
1
+ export declare function random(min: number, max: number): number;
2
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/utils/random.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@keq-request/cache",
3
+ "version": "5.0.0-alpha.10",
4
+ "description": "Adds request caching capabilities similar to service workers",
5
+ "keywords": [
6
+ "keq",
7
+ "cache"
8
+ ],
9
+ "license": "MIT",
10
+ "author": "Val.istar.Guo <val.istar.guo@gmail.com>",
11
+ "types": "dist/index.d.ts",
12
+ "main": "dist/index.js",
13
+ "exports": {
14
+ ".": {
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "import": {
20
+ "types": "./dist/index.d.mts",
21
+ "default": "./dist/index.mjs"
22
+ }
23
+ }
24
+ },
25
+ "homepage": "https://github.com/keq-request/keq#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/keq-request/keq/issues"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/keq-request/keq.git"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.19.24",
35
+ "@types/ramda": "^0.31.1",
36
+ "fake-indexeddb": "^6.2.4",
37
+ "isomorphic-fetch": "^3.0.0",
38
+ "keq": "5.0.0-alpha.10"
39
+ },
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "peerDependencies": {
44
+ "keq": "^5.0.0-alpha.10"
45
+ },
46
+ "dependencies": {
47
+ "dayjs": "^1.11.19",
48
+ "idb": "^8.0.3",
49
+ "ramda": "^0.32.0",
50
+ "type-fest": "^5.2.0"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "dev": "tsup --watch",
55
+ "test": "jest",
56
+ "test:update": "jest --updateSnapshot"
57
+ }
58
+ }