@dynlabs/react-native-immutable-file-cache 1.0.0-alpha.1

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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +415 -0
  3. package/lib/commonjs/adapters/memoryAdapter.js +266 -0
  4. package/lib/commonjs/adapters/memoryAdapter.js.map +1 -0
  5. package/lib/commonjs/adapters/rnfsAdapter.js +259 -0
  6. package/lib/commonjs/adapters/rnfsAdapter.js.map +1 -0
  7. package/lib/commonjs/adapters/webAdapter.js +432 -0
  8. package/lib/commonjs/adapters/webAdapter.js.map +1 -0
  9. package/lib/commonjs/core/adapter.js +2 -0
  10. package/lib/commonjs/core/adapter.js.map +1 -0
  11. package/lib/commonjs/core/cacheEngine.js +578 -0
  12. package/lib/commonjs/core/cacheEngine.js.map +1 -0
  13. package/lib/commonjs/core/errors.js +83 -0
  14. package/lib/commonjs/core/errors.js.map +1 -0
  15. package/lib/commonjs/core/hash.js +83 -0
  16. package/lib/commonjs/core/hash.js.map +1 -0
  17. package/lib/commonjs/core/indexStore.js +175 -0
  18. package/lib/commonjs/core/indexStore.js.map +1 -0
  19. package/lib/commonjs/core/mutex.js +143 -0
  20. package/lib/commonjs/core/mutex.js.map +1 -0
  21. package/lib/commonjs/core/prune.js +127 -0
  22. package/lib/commonjs/core/prune.js.map +1 -0
  23. package/lib/commonjs/core/types.js +6 -0
  24. package/lib/commonjs/core/types.js.map +1 -0
  25. package/lib/commonjs/factory.js +56 -0
  26. package/lib/commonjs/factory.js.map +1 -0
  27. package/lib/commonjs/index.js +110 -0
  28. package/lib/commonjs/index.js.map +1 -0
  29. package/lib/commonjs/index.native.js +74 -0
  30. package/lib/commonjs/index.native.js.map +1 -0
  31. package/lib/commonjs/index.web.js +75 -0
  32. package/lib/commonjs/index.web.js.map +1 -0
  33. package/lib/commonjs/types/react-native-fs.d.js +2 -0
  34. package/lib/commonjs/types/react-native-fs.d.js.map +1 -0
  35. package/lib/module/adapters/memoryAdapter.js +261 -0
  36. package/lib/module/adapters/memoryAdapter.js.map +1 -0
  37. package/lib/module/adapters/rnfsAdapter.js +251 -0
  38. package/lib/module/adapters/rnfsAdapter.js.map +1 -0
  39. package/lib/module/adapters/webAdapter.js +426 -0
  40. package/lib/module/adapters/webAdapter.js.map +1 -0
  41. package/lib/module/core/adapter.js +2 -0
  42. package/lib/module/core/adapter.js.map +1 -0
  43. package/lib/module/core/cacheEngine.js +571 -0
  44. package/lib/module/core/cacheEngine.js.map +1 -0
  45. package/lib/module/core/errors.js +71 -0
  46. package/lib/module/core/errors.js.map +1 -0
  47. package/lib/module/core/hash.js +76 -0
  48. package/lib/module/core/hash.js.map +1 -0
  49. package/lib/module/core/indexStore.js +168 -0
  50. package/lib/module/core/indexStore.js.map +1 -0
  51. package/lib/module/core/mutex.js +135 -0
  52. package/lib/module/core/mutex.js.map +1 -0
  53. package/lib/module/core/prune.js +116 -0
  54. package/lib/module/core/prune.js.map +1 -0
  55. package/lib/module/core/types.js +2 -0
  56. package/lib/module/core/types.js.map +1 -0
  57. package/lib/module/factory.js +49 -0
  58. package/lib/module/factory.js.map +1 -0
  59. package/lib/module/index.js +41 -0
  60. package/lib/module/index.js.map +1 -0
  61. package/lib/module/index.native.js +54 -0
  62. package/lib/module/index.native.js.map +1 -0
  63. package/lib/module/index.web.js +55 -0
  64. package/lib/module/index.web.js.map +1 -0
  65. package/lib/module/types/react-native-fs.d.js +2 -0
  66. package/lib/module/types/react-native-fs.d.js.map +1 -0
  67. package/lib/typescript/src/adapters/memoryAdapter.d.ts +23 -0
  68. package/lib/typescript/src/adapters/memoryAdapter.d.ts.map +1 -0
  69. package/lib/typescript/src/adapters/rnfsAdapter.d.ts +18 -0
  70. package/lib/typescript/src/adapters/rnfsAdapter.d.ts.map +1 -0
  71. package/lib/typescript/src/adapters/webAdapter.d.ts +30 -0
  72. package/lib/typescript/src/adapters/webAdapter.d.ts.map +1 -0
  73. package/lib/typescript/src/core/adapter.d.ts +105 -0
  74. package/lib/typescript/src/core/adapter.d.ts.map +1 -0
  75. package/lib/typescript/src/core/cacheEngine.d.ts +99 -0
  76. package/lib/typescript/src/core/cacheEngine.d.ts.map +1 -0
  77. package/lib/typescript/src/core/errors.d.ts +54 -0
  78. package/lib/typescript/src/core/errors.d.ts.map +1 -0
  79. package/lib/typescript/src/core/hash.d.ts +20 -0
  80. package/lib/typescript/src/core/hash.d.ts.map +1 -0
  81. package/lib/typescript/src/core/indexStore.d.ts +34 -0
  82. package/lib/typescript/src/core/indexStore.d.ts.map +1 -0
  83. package/lib/typescript/src/core/mutex.d.ts +49 -0
  84. package/lib/typescript/src/core/mutex.d.ts.map +1 -0
  85. package/lib/typescript/src/core/prune.d.ts +39 -0
  86. package/lib/typescript/src/core/prune.d.ts.map +1 -0
  87. package/lib/typescript/src/core/types.d.ts +109 -0
  88. package/lib/typescript/src/core/types.d.ts.map +1 -0
  89. package/lib/typescript/src/factory.d.ts +46 -0
  90. package/lib/typescript/src/factory.d.ts.map +1 -0
  91. package/lib/typescript/src/index.d.ts +20 -0
  92. package/lib/typescript/src/index.d.ts.map +1 -0
  93. package/lib/typescript/src/index.native.d.ts +37 -0
  94. package/lib/typescript/src/index.native.d.ts.map +1 -0
  95. package/lib/typescript/src/index.web.d.ts +38 -0
  96. package/lib/typescript/src/index.web.d.ts.map +1 -0
  97. package/package.json +125 -0
  98. package/src/adapters/memoryAdapter.ts +307 -0
  99. package/src/adapters/rnfsAdapter.ts +283 -0
  100. package/src/adapters/webAdapter.ts +480 -0
  101. package/src/core/adapter.ts +128 -0
  102. package/src/core/cacheEngine.ts +634 -0
  103. package/src/core/errors.ts +82 -0
  104. package/src/core/hash.ts +78 -0
  105. package/src/core/indexStore.ts +184 -0
  106. package/src/core/mutex.ts +134 -0
  107. package/src/core/prune.ts +145 -0
  108. package/src/core/types.ts +165 -0
  109. package/src/factory.ts +60 -0
  110. package/src/index.native.ts +58 -0
  111. package/src/index.ts +82 -0
  112. package/src/index.web.ts +59 -0
  113. package/src/types/react-native-fs.d.ts +75 -0
@@ -0,0 +1,39 @@
1
+ import type { ICacheIndex, ICacheEntryMeta } from "./types";
2
+ /**
3
+ * Options for pruning operations.
4
+ */
5
+ export interface IPruneOptions {
6
+ readonly maxSizeBytes?: number;
7
+ readonly now?: number;
8
+ }
9
+ /**
10
+ * Identifies entries to remove based on TTL expiration.
11
+ * Returns entries that have expired (expiresAt < now).
12
+ */
13
+ export declare function getExpiredEntries(index: ICacheIndex, now?: number): ReadonlyArray<ICacheEntryMeta>;
14
+ /**
15
+ * Identifies entries to remove based on LRU policy to meet size limit.
16
+ * Sorts entries by lastAccessedAt (oldest first) and returns entries
17
+ * that need to be removed to get under maxSizeBytes.
18
+ */
19
+ export declare function getLruPruneTargets(index: ICacheIndex, maxSizeBytes: number): ReadonlyArray<ICacheEntryMeta>;
20
+ /**
21
+ * Creates a new index with the specified entries removed.
22
+ * Returns a new ICacheIndex without mutating the original.
23
+ */
24
+ export declare function removeEntriesFromIndex(index: ICacheIndex, keysToRemove: ReadonlyArray<string>): ICacheIndex;
25
+ /**
26
+ * Adds or updates an entry in the index.
27
+ * Returns a new ICacheIndex without mutating the original.
28
+ */
29
+ export declare function addEntryToIndex(index: ICacheIndex, entry: ICacheEntryMeta): ICacheIndex;
30
+ /**
31
+ * Updates the lastAccessedAt timestamp for an entry.
32
+ * Returns a new ICacheIndex without mutating the original.
33
+ */
34
+ export declare function touchEntry(index: ICacheIndex, key: string, accessedAt?: number): ICacheIndex;
35
+ /**
36
+ * Creates an empty cache index.
37
+ */
38
+ export declare function createEmptyIndex(): ICacheIndex;
39
+ //# sourceMappingURL=prune.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../../src/core/prune.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,GAAG,GAAE,MAAmB,GACvB,aAAa,CAAC,eAAe,CAAC,CAUhC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE,MAAM,GACnB,aAAa,CAAC,eAAe,CAAC,CAsBhC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,GAClC,WAAW,CAkBb;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,GAAG,WAAW,CAavF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,MAAmB,GAC9B,WAAW,CAiBb;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,CAO9C"}
@@ -0,0 +1,109 @@
1
+ import type { IStorageAdapter, TAdapterPath } from "./adapter";
2
+ export interface ICacheConfig {
3
+ /**
4
+ * Namespace for cache isolation. Creates separate storage area.
5
+ * @default "default"
6
+ */
7
+ readonly namespace?: string;
8
+ /**
9
+ * Custom storage adapter. If not provided, auto-selects based on platform.
10
+ */
11
+ readonly adapter?: IStorageAdapter;
12
+ /**
13
+ * Default TTL in milliseconds for new entries.
14
+ * @default undefined (no expiration)
15
+ */
16
+ readonly defaultTtlMs?: number;
17
+ /**
18
+ * Maximum cache size in bytes. Triggers LRU pruning when exceeded.
19
+ * @default undefined (no limit)
20
+ */
21
+ readonly maxSizeBytes?: number;
22
+ /**
23
+ * Whether to auto-prune expired entries on cache operations.
24
+ * @default true
25
+ */
26
+ readonly autoPruneExpired?: boolean;
27
+ /**
28
+ * Custom hash function for generating cache keys from input keys.
29
+ * @default SHA-256 hex
30
+ */
31
+ readonly hashFn?: (input: string) => string | Promise<string>;
32
+ }
33
+ export interface ICacheEntryMeta {
34
+ /** User-provided unique key. */
35
+ readonly key: string;
36
+ /** Hash of the key (used for filename). */
37
+ readonly hash: string;
38
+ /** Original file extension (e.g., ".jpg"). */
39
+ readonly ext: string;
40
+ /** Size in bytes. */
41
+ readonly sizeBytes: number;
42
+ /** MIME content type if known. */
43
+ readonly contentType?: string;
44
+ /** Timestamp when entry was created (ms since epoch). */
45
+ readonly createdAt: number;
46
+ /** Timestamp when entry was last accessed (ms since epoch). */
47
+ readonly lastAccessedAt: number;
48
+ /** Expiration timestamp (ms since epoch). undefined = never expires. */
49
+ readonly expiresAt?: number;
50
+ /** Optional user-defined metadata. */
51
+ readonly metadata?: Readonly<Record<string, unknown>>;
52
+ }
53
+ export interface ICacheEntry extends ICacheEntryMeta {
54
+ /** Adapter-relative path to the cached file. */
55
+ readonly path: TAdapterPath;
56
+ }
57
+ export interface ICacheIndex {
58
+ readonly version: 1;
59
+ readonly entries: Readonly<Record<string, ICacheEntryMeta>>;
60
+ readonly totalSizeBytes: number;
61
+ readonly lastModifiedAt: number;
62
+ }
63
+ export interface IPutOptions {
64
+ /** TTL in milliseconds. Overrides defaultTtlMs. */
65
+ readonly ttlMs?: number;
66
+ /** File extension to use (e.g., ".jpg"). Auto-detected if omitted. */
67
+ readonly ext?: string;
68
+ /** Optional user-defined metadata. */
69
+ readonly metadata?: Readonly<Record<string, unknown>>;
70
+ /** Progress callback for download/write operations. */
71
+ readonly onProgress?: (percent: number) => void;
72
+ /** Additional headers for URL fetches. */
73
+ readonly headers?: Readonly<Record<string, string>>;
74
+ }
75
+ export type TPutStatus = "created" | "exists";
76
+ export interface IPutResult {
77
+ readonly status: TPutStatus;
78
+ readonly entry: ICacheEntry;
79
+ }
80
+ export interface IGetResult {
81
+ readonly entry: ICacheEntry;
82
+ readonly uri: string;
83
+ }
84
+ export type TSortField = "createdAt" | "lastAccessedAt" | "sizeBytes" | "key";
85
+ export type TSortOrder = "asc" | "desc";
86
+ export interface IListOptions {
87
+ /** Sort field. @default "createdAt" */
88
+ readonly sortBy?: TSortField;
89
+ /** Sort order. @default "desc" */
90
+ readonly order?: TSortOrder;
91
+ /** Maximum entries to return. */
92
+ readonly limit?: number;
93
+ /** Number of entries to skip. */
94
+ readonly offset?: number;
95
+ /** Filter by metadata. */
96
+ readonly filter?: (entry: ICacheEntryMeta) => boolean;
97
+ }
98
+ export interface IPruneResult {
99
+ readonly removedCount: number;
100
+ readonly freedBytes: number;
101
+ readonly removedKeys: ReadonlyArray<string>;
102
+ }
103
+ export interface ICacheStats {
104
+ readonly entryCount: number;
105
+ readonly totalSizeBytes: number;
106
+ readonly oldestEntry?: ICacheEntryMeta;
107
+ readonly newestEntry?: ICacheEntryMeta;
108
+ }
109
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAM/D,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;C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;CAC7C;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC;CACxC"}
@@ -0,0 +1,46 @@
1
+ import type { ICacheConfig } from "./core/types";
2
+ import type { IStorageAdapter } from "./core/adapter";
3
+ import { CacheEngine } from "./core/cacheEngine";
4
+ export interface ICreateCacheOptions extends ICacheConfig {
5
+ /**
6
+ * If true, auto-initializes the cache before returning.
7
+ * @default true
8
+ */
9
+ readonly autoInit?: boolean;
10
+ }
11
+ /**
12
+ * Creates an immutable file cache instance.
13
+ *
14
+ * This is the base factory function. Platform-specific entrypoints
15
+ * (index.native.ts, index.web.ts) wrap this to auto-select the appropriate adapter.
16
+ *
17
+ * @param options - Cache configuration options
18
+ * @param adapter - Storage adapter (required in base factory)
19
+ * @returns Initialized CacheEngine instance
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { createImmutableFileCache } from "react-native-immutable-file-cache";
24
+ *
25
+ * const cache = await createImmutableFileCache({
26
+ * namespace: "images",
27
+ * defaultTtlMs: 7 * 24 * 60 * 60 * 1000, // 7 days
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function createImmutableFileCache(options: ICreateCacheOptions & {
32
+ adapter: IStorageAdapter;
33
+ }): Promise<CacheEngine>;
34
+ /**
35
+ * Creates a cache engine without auto-initialization.
36
+ * Useful when you need to control initialization timing.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const engine = createCacheEngineSync({ namespace: "images" }, adapter);
41
+ * // Later...
42
+ * await engine.init();
43
+ * ```
44
+ */
45
+ export declare function createCacheEngineSync(config: ICacheConfig, adapter: IStorageAdapter): CacheEngine;
46
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,mBAAmB,GAAG;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,GAC1D,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,WAAW,CAEjG"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @dynlabs/react-native-immutable-file-cache
3
+ *
4
+ * Cross-platform immutable file cache with pluggable storage adapters.
5
+ */
6
+ export type { IStorageAdapter, TAdapterPath, TBinarySource, IBinaryWriteResult, IBinaryWriteOptions, IFileStat, TProgressCallback, } from "./core/adapter";
7
+ export type { ICacheConfig, ICacheEntry, ICacheEntryMeta, ICacheIndex, IPutOptions, IPutResult, IGetResult, IListOptions, IPruneResult, ICacheStats, TPutStatus, TSortField, TSortOrder, } from "./core/types";
8
+ export { CacheError, UnsupportedSourceError, AdapterIOError, CorruptIndexError, ImmutableConflictError, EntryNotFoundError, } from "./core/errors";
9
+ export { CacheEngine } from "./core/cacheEngine";
10
+ export { createImmutableFileCache, createCacheEngineSync } from "./factory";
11
+ export type { ICreateCacheOptions } from "./factory";
12
+ export { createRnfsAdapter } from "./adapters/rnfsAdapter";
13
+ export type { IRnfsAdapterOptions } from "./adapters/rnfsAdapter";
14
+ export { createWebAdapter } from "./adapters/webAdapter";
15
+ export type { IWebAdapterOptions, IWebAdapterWithCleanup } from "./adapters/webAdapter";
16
+ export { createMemoryAdapter } from "./adapters/memoryAdapter";
17
+ export type { IMemoryAdapter } from "./adapters/memoryAdapter";
18
+ export { hash, hashSync } from "./core/hash";
19
+ export { Mutex, KeyedMutex } from "./core/mutex";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,YAAY,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,YAAY,EACZ,WAAW,EACX,eAAe,EACf,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,cAAc,CAAC;AAMtB,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMjD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAMrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAM/D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @dynlabs/react-native-immutable-file-cache - Native entrypoint
3
+ * Auto-selects RNFS adapter for React Native (iOS/Android).
4
+ */
5
+ export * from "./index";
6
+ import type { ICreateCacheOptions } from "./factory";
7
+ import { CacheEngine } from "./core/cacheEngine";
8
+ /**
9
+ * Creates an immutable file cache instance for React Native.
10
+ * Automatically uses the RNFS adapter.
11
+ *
12
+ * @param options - Cache configuration options
13
+ * @returns Initialized CacheEngine instance
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { createImmutableFileCache } from "@dynlabs/react-native-immutable-file-cache";
18
+ *
19
+ * const cache = await createImmutableFileCache({
20
+ * namespace: "images",
21
+ * defaultTtlMs: 7 * 24 * 60 * 60 * 1000,
22
+ * });
23
+ *
24
+ * // Cache an image
25
+ * const result = await cache.putFromUrl("avatar", "https://example.com/avatar.jpg");
26
+ *
27
+ * // Get cached image URI
28
+ * const entry = await cache.get("avatar");
29
+ * if (entry) {
30
+ * console.log("Image URI:", entry.uri);
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function createImmutableFileCache(options?: Omit<ICreateCacheOptions, "adapter"> & {
35
+ adapter?: ICreateCacheOptions["adapter"];
36
+ }): Promise<CacheEngine>;
37
+ //# sourceMappingURL=index.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../../src/index.native.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAA;CAAE,GAC5F,OAAO,CAAC,WAAW,CAAC,CAiBtB"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @dynlabs/react-native-immutable-file-cache - Web entrypoint
3
+ * Auto-selects Web adapter for browser environments.
4
+ */
5
+ export * from "./index";
6
+ import type { ICreateCacheOptions } from "./factory";
7
+ import { CacheEngine } from "./core/cacheEngine";
8
+ /**
9
+ * Creates an immutable file cache instance for web browsers.
10
+ * Automatically uses the Web adapter (Cache Storage + IndexedDB).
11
+ *
12
+ * @param options - Cache configuration options
13
+ * @returns Initialized CacheEngine instance
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { createImmutableFileCache } from "@dynlabs/react-native-immutable-file-cache/web";
18
+ *
19
+ * const cache = await createImmutableFileCache({
20
+ * namespace: "images",
21
+ * defaultTtlMs: 7 * 24 * 60 * 60 * 1000,
22
+ * });
23
+ *
24
+ * // Cache an image
25
+ * const result = await cache.putFromUrl("avatar", "https://example.com/avatar.jpg");
26
+ *
27
+ * // Get cached image URI (blob: URL)
28
+ * const entry = await cache.get("avatar");
29
+ * if (entry) {
30
+ * // Use entry.uri as image source
31
+ * // Remember to revoke blob URL when done to free memory
32
+ * }
33
+ * ```
34
+ */
35
+ export declare function createImmutableFileCache(options?: Omit<ICreateCacheOptions, "adapter"> & {
36
+ adapter?: ICreateCacheOptions["adapter"];
37
+ }): Promise<CacheEngine>;
38
+ //# sourceMappingURL=index.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../src/index.web.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAA;CAAE,GAC5F,OAAO,CAAC,WAAW,CAAC,CAiBtB"}
package/package.json ADDED
@@ -0,0 +1,125 @@
1
+ {
2
+ "name": "@dynlabs/react-native-immutable-file-cache",
3
+ "version": "1.0.0-alpha.1",
4
+ "description": "Cross-platform immutable file cache with pluggable storage adapters for React Native and Web",
5
+ "author": "dienp",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/dienp/react-native-immutable-file-cache.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/dienp/react-native-immutable-file-cache/issues"
13
+ },
14
+ "homepage": "https://github.com/dienp/react-native-immutable-file-cache#readme",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "main": "lib/commonjs/index.js",
19
+ "module": "lib/module/index.js",
20
+ "types": "lib/typescript/src/index.d.ts",
21
+ "react-native": "src/index.native.ts",
22
+ "source": "src/index.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./lib/typescript/src/index.d.ts",
26
+ "react-native": "./src/index.native.ts",
27
+ "import": "./lib/module/index.js",
28
+ "require": "./lib/commonjs/index.js"
29
+ },
30
+ "./native": {
31
+ "types": "./lib/typescript/src/index.native.d.ts",
32
+ "react-native": "./src/index.native.ts",
33
+ "import": "./lib/module/index.native.js",
34
+ "require": "./lib/commonjs/index.native.js"
35
+ },
36
+ "./web": {
37
+ "types": "./lib/typescript/src/index.web.d.ts",
38
+ "import": "./lib/module/index.web.js",
39
+ "require": "./lib/commonjs/index.web.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "files": [
44
+ "src",
45
+ "lib",
46
+ "README.md",
47
+ "!**/__tests__",
48
+ "!**/__mocks__",
49
+ "!**/*.test.ts"
50
+ ],
51
+ "sideEffects": false,
52
+ "scripts": {
53
+ "build": "bob build",
54
+ "typecheck": "tsc --noEmit",
55
+ "lint": "eslint src --ext .ts,.tsx",
56
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
57
+ "format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
58
+ "format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
59
+ "test": "jest",
60
+ "test:watch": "jest --watch",
61
+ "test:coverage": "jest --coverage",
62
+ "clean": "rimraf lib",
63
+ "prepublishOnly": "npm run build && npm run lint && npm run typecheck && npm test",
64
+ "release:patch": "npm version patch",
65
+ "release:minor": "npm version minor",
66
+ "release:major": "npm version major"
67
+ },
68
+ "keywords": [
69
+ "react-native",
70
+ "cache",
71
+ "file-cache",
72
+ "immutable",
73
+ "storage",
74
+ "offline",
75
+ "ios",
76
+ "android",
77
+ "web",
78
+ "cross-platform",
79
+ "adapter"
80
+ ],
81
+ "peerDependencies": {
82
+ "react-native": ">=0.70.0",
83
+ "react-native-fs": ">=2.20.0"
84
+ },
85
+ "peerDependenciesMeta": {
86
+ "react-native": {
87
+ "optional": true
88
+ },
89
+ "react-native-fs": {
90
+ "optional": true
91
+ }
92
+ },
93
+ "devDependencies": {
94
+ "@types/jest": "^29.5.12",
95
+ "@types/react-native": "^0.72.8",
96
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
97
+ "@typescript-eslint/parser": "^7.0.0",
98
+ "eslint": "^8.57.0",
99
+ "eslint-config-prettier": "^9.1.0",
100
+ "eslint-plugin-prettier": "^5.1.3",
101
+ "jest": "^29.7.0",
102
+ "prettier": "^3.2.5",
103
+ "react-native-builder-bob": "^0.23.2",
104
+ "rimraf": "^5.0.5",
105
+ "ts-jest": "^29.1.2",
106
+ "typescript": "^5.3.3"
107
+ },
108
+ "react-native-builder-bob": {
109
+ "source": "src",
110
+ "output": "lib",
111
+ "targets": [
112
+ "commonjs",
113
+ "module",
114
+ [
115
+ "typescript",
116
+ {
117
+ "project": "tsconfig.build.json"
118
+ }
119
+ ]
120
+ ]
121
+ },
122
+ "engines": {
123
+ "node": ">=18"
124
+ }
125
+ }