strata-storage 1.5.0 → 2.0.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.
Files changed (82) hide show
  1. package/Readme.md +66 -20
  2. package/dist/README.md +162 -0
  3. package/dist/adapters/capacitor/FilesystemAdapter.js +4 -4
  4. package/dist/adapters/capacitor/PreferencesAdapter.js +4 -4
  5. package/dist/adapters/capacitor/SecureAdapter.js +4 -4
  6. package/dist/adapters/capacitor/SqliteAdapter.js +4 -4
  7. package/dist/adapters/capacitor/index.js +4 -4
  8. package/dist/adapters/web/CacheAdapter.js +3 -3
  9. package/dist/adapters/web/CookieAdapter.js +2 -2
  10. package/dist/adapters/web/IndexedDBAdapter.js +3 -3
  11. package/dist/adapters/web/LocalStorageAdapter.js +3 -3
  12. package/dist/adapters/web/MemoryAdapter.js +3 -3
  13. package/dist/adapters/web/SessionStorageAdapter.js +1 -1
  14. package/dist/adapters/web/index.js +6 -6
  15. package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
  16. package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
  17. package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
  18. package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
  19. package/dist/capacitor.d.ts +20 -0
  20. package/dist/capacitor.d.ts.map +1 -0
  21. package/dist/capacitor.js +48 -0
  22. package/dist/core/AdapterRegistry.js +1 -1
  23. package/dist/core/BaseAdapter.js +3 -3
  24. package/dist/core/StorageStrategy.js +1 -0
  25. package/dist/core/Strata.d.ts +28 -3
  26. package/dist/core/Strata.d.ts.map +1 -1
  27. package/dist/core/Strata.js +57 -58
  28. package/dist/features/compression/index.d.ts +2 -0
  29. package/dist/features/compression/index.d.ts.map +1 -0
  30. package/dist/features/compression/index.js +1 -0
  31. package/dist/features/compression.js +1 -1
  32. package/dist/features/encryption/index.d.ts +2 -0
  33. package/dist/features/encryption/index.d.ts.map +1 -0
  34. package/dist/features/encryption/index.js +1 -0
  35. package/dist/features/encryption.d.ts.map +1 -1
  36. package/dist/features/encryption.js +6 -5
  37. package/dist/features/observer/index.d.ts +2 -0
  38. package/dist/features/observer/index.d.ts.map +1 -0
  39. package/dist/features/observer/index.js +1 -0
  40. package/dist/features/observer.d.ts +20 -0
  41. package/dist/features/observer.d.ts.map +1 -0
  42. package/dist/features/observer.js +32 -0
  43. package/dist/features/query/index.d.ts +2 -0
  44. package/dist/features/query/index.d.ts.map +1 -0
  45. package/dist/features/query/index.js +1 -0
  46. package/dist/features/query.d.ts.map +1 -1
  47. package/dist/features/query.js +8 -1
  48. package/dist/features/sync/index.d.ts +2 -0
  49. package/dist/features/sync/index.d.ts.map +1 -0
  50. package/dist/features/sync/index.js +1 -0
  51. package/dist/features/sync.js +1 -1
  52. package/dist/features/ttl/index.d.ts +2 -0
  53. package/dist/features/ttl/index.d.ts.map +1 -0
  54. package/dist/features/ttl/index.js +1 -0
  55. package/dist/features/ttl.js +1 -1
  56. package/dist/firebase.d.ts +26 -0
  57. package/dist/firebase.d.ts.map +1 -0
  58. package/dist/firebase.js +147 -0
  59. package/dist/index.d.ts +13 -47
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +54 -58
  62. package/dist/ios/Plugin/KeychainStorage.swift +87 -0
  63. package/dist/ios/Plugin/SQLiteStorage.swift +167 -0
  64. package/dist/ios/Plugin/StrataStoragePlugin.swift +204 -0
  65. package/dist/ios/Plugin/UserDefaultsStorage.swift +44 -0
  66. package/dist/package.json +22 -4
  67. package/dist/plugin/definitions.d.ts +2 -2
  68. package/dist/plugin/definitions.d.ts.map +1 -1
  69. package/dist/plugin/index.d.ts +2 -1
  70. package/dist/plugin/index.d.ts.map +1 -1
  71. package/dist/plugin/index.js +77 -11
  72. package/dist/types/index.d.ts +190 -0
  73. package/dist/types/index.d.ts.map +1 -1
  74. package/dist/types/index.js +13 -0
  75. package/dist/utils/index.d.ts +20 -0
  76. package/dist/utils/index.d.ts.map +1 -1
  77. package/dist/utils/index.js +34 -0
  78. package/package.json +15 -24
  79. package/scripts/build.js +127 -14
  80. package/scripts/cli.js +6 -2
  81. package/scripts/configure.js +7 -3
  82. package/scripts/postinstall.js +21 -10
package/scripts/build.js CHANGED
@@ -1,39 +1,148 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { execSync } from 'child_process';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
6
10
 
7
11
  const rootDir = path.join(__dirname, '..');
8
12
  const srcDir = path.join(rootDir, 'src');
9
13
  const distDir = path.join(rootDir, 'dist');
10
14
 
11
- console.log('šŸ”Ø Building Strata Storage...');
15
+ console.log('šŸ”Ø Building Strata Storage (ESM)...');
12
16
 
13
- // Ensure dist directory exists
14
- if (!fs.existsSync(distDir)) {
15
- fs.mkdirSync(distDir, { recursive: true });
17
+ // Clean dist directory
18
+ console.log('🧹 Cleaning dist directory...');
19
+ if (fs.existsSync(distDir)) {
20
+ fs.rmSync(distDir, { recursive: true, force: true });
16
21
  }
17
22
 
18
- // Compile TypeScript
19
- console.log('šŸ“¦ Compiling TypeScript...');
23
+ // Ensure dist directory exists
24
+ fs.mkdirSync(distDir, { recursive: true });
25
+
26
+ // Compile TypeScript to ESM
27
+ console.log('šŸ“¦ Building ES Modules...');
20
28
  try {
21
29
  execSync('npx tsc', { stdio: 'inherit', cwd: rootDir });
22
30
  } catch (error) {
23
- console.error('āŒ TypeScript compilation failed');
31
+ console.error('āŒ Build failed');
24
32
  process.exit(1);
25
33
  }
26
34
 
27
- // Copy package.json fields for publishing
35
+ // Fix path aliases in all built files
36
+ console.log('šŸ”§ Fixing path aliases...');
37
+ const fixPathAliases = (dir) => {
38
+ const files = fs.readdirSync(dir);
39
+
40
+ files.forEach(file => {
41
+ const filePath = path.join(dir, file);
42
+ const stat = fs.statSync(filePath);
43
+
44
+ if (stat.isDirectory()) {
45
+ fixPathAliases(filePath);
46
+ } else if (file.endsWith('.js')) {
47
+ let content = fs.readFileSync(filePath, 'utf8');
48
+
49
+ // Calculate depth from dist root
50
+ const relativeFromDist = path.relative(distDir, path.dirname(filePath));
51
+ const depth = relativeFromDist ? relativeFromDist.split(path.sep).length : 0;
52
+ const pathToRoot = depth > 0 ? '../'.repeat(depth) : './';
53
+
54
+ // Fix all @/ imports with proper aliasing
55
+ content = content
56
+ .replace(/from\s+["']@\/core\//g, `from "${pathToRoot}core/`)
57
+ .replace(/from\s+["']@\/adapters\//g, `from "${pathToRoot}adapters/`)
58
+ .replace(/from\s+["']@\/features\//g, `from "${pathToRoot}features/`)
59
+ .replace(/from\s+["']@\/utils\//g, `from "${pathToRoot}utils/`)
60
+ .replace(/from\s+["']@\/plugin\//g, `from "${pathToRoot}plugin/`)
61
+ .replace(/from\s+["']@\/types\//g, `from "${pathToRoot}types/`)
62
+ .replace(/from\s+["']@\/utils["']/g, `from "${pathToRoot}utils/index.js"`)
63
+ .replace(/from\s+["']@\/plugin["']/g, `from "${pathToRoot}plugin/index.js"`)
64
+ .replace(/import\(["']@\/core\//g, `import("${pathToRoot}core/`)
65
+ .replace(/import\(["']@\/adapters\//g, `import("${pathToRoot}adapters/`)
66
+ .replace(/import\(["']@\/features\//g, `import("${pathToRoot}features/`)
67
+ .replace(/import\(["']@\/utils\//g, `import("${pathToRoot}utils/`)
68
+ .replace(/import\(["']@\/plugin\//g, `import("${pathToRoot}plugin/`)
69
+ .replace(/import\(["']@\/types\//g, `import("${pathToRoot}types/`)
70
+ .replace(/import\(["']@\/utils["']\)/g, `import("${pathToRoot}utils/index.js")`)
71
+ .replace(/import\(["']@\/plugin["']\)/g, `import("${pathToRoot}plugin/index.js")`);
72
+
73
+ // Also fix any remaining short imports that should point to index.js
74
+ content = content
75
+ .replace(/from\s+["']\.\/utils["']/g, `from "./utils/index.js"`)
76
+ .replace(/from\s+["']\.\/plugin["']/g, `from "./plugin/index.js"`);
77
+
78
+ // Add .js extension to relative imports
79
+ content = content
80
+ .replace(/from\s+["'](\.[^"']+)["']/g, (match, path) => {
81
+ if (!path.endsWith('.js') && !path.endsWith('.json')) {
82
+ return `from "${path}.js"`;
83
+ }
84
+ return match;
85
+ })
86
+ .replace(/import\(["'](\.[^"']+)["']\)/g, (match, path) => {
87
+ if (!path.endsWith('.js') && !path.endsWith('.json')) {
88
+ return `import("${path}.js")`;
89
+ }
90
+ return match;
91
+ });
92
+
93
+ fs.writeFileSync(filePath, content);
94
+ }
95
+ });
96
+ };
97
+
98
+ fixPathAliases(distDir);
99
+
100
+ // Copy native directories if they exist
101
+ console.log('šŸ“± Copying native code...');
102
+ const nativeDirs = ['android', 'ios'];
103
+ nativeDirs.forEach(dir => {
104
+ const srcPath = path.join(rootDir, dir);
105
+ const destPath = path.join(distDir, dir);
106
+ if (fs.existsSync(srcPath)) {
107
+ fs.cpSync(srcPath, destPath, { recursive: true });
108
+ }
109
+ });
110
+
111
+ // Copy other files
112
+ console.log('šŸ“„ Copying additional files...');
113
+ const filesToCopy = ['README.md', 'LICENSE'];
114
+ filesToCopy.forEach(file => {
115
+ const srcPath = path.join(rootDir, file);
116
+ const destPath = path.join(distDir, file);
117
+ if (fs.existsSync(srcPath)) {
118
+ fs.copyFileSync(srcPath, destPath);
119
+ }
120
+ });
121
+
122
+ // Create package.json for distribution
28
123
  console.log('šŸ“‹ Preparing package metadata...');
29
124
  const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'));
30
125
  const distPackageJson = {
31
126
  name: packageJson.name,
32
127
  version: packageJson.version,
33
128
  description: packageJson.description,
34
- main: 'index.js',
35
- module: 'index.esm.js',
36
- types: 'index.d.ts',
129
+ type: 'module',
130
+ main: './index.js',
131
+ types: './index.d.ts',
132
+ exports: {
133
+ '.': {
134
+ types: './index.d.ts',
135
+ default: './index.js'
136
+ },
137
+ './capacitor': {
138
+ types: './capacitor.d.ts',
139
+ default: './capacitor.js'
140
+ },
141
+ './firebase': {
142
+ types: './firebase.d.ts',
143
+ default: './firebase.js'
144
+ }
145
+ },
37
146
  author: packageJson.author,
38
147
  license: packageJson.license,
39
148
  repository: packageJson.repository,
@@ -41,6 +150,10 @@ const distPackageJson = {
41
150
  peerDependencies: packageJson.peerDependencies,
42
151
  peerDependenciesMeta: packageJson.peerDependenciesMeta,
43
152
  capacitor: packageJson.capacitor,
153
+ sideEffects: false,
154
+ engines: {
155
+ node: '>=18.0.0'
156
+ }
44
157
  };
45
158
 
46
159
  fs.writeFileSync(
package/scripts/cli.js CHANGED
@@ -5,8 +5,12 @@
5
5
  * Main entry point for npx commands
6
6
  */
7
7
 
8
- const path = require('path');
9
- const { spawn } = require('child_process');
8
+ import path from 'path';
9
+ import { spawn } from 'child_process';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
10
14
 
11
15
  // Get command from arguments
12
16
  const command = process.argv[2];
@@ -5,9 +5,13 @@
5
5
  * Usage: npx strata-storage configure
6
6
  */
7
7
 
8
- const fs = require('fs');
9
- const path = require('path');
10
- const { execSync } = require('child_process');
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { execSync } from 'child_process';
11
+ import { fileURLToPath } from 'url';
12
+
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = path.dirname(__filename);
11
15
 
12
16
  // Colors for terminal output
13
17
  const colors = {
@@ -1,10 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
- const path = require('path');
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
5
9
 
6
10
  console.log('\nšŸš€ Strata Storage - Zero Dependencies, Infinite Possibilities!\n');
7
11
 
12
+ console.log('šŸ“š Quick Start:');
13
+ console.log(' import { Strata } from "strata-storage";');
14
+ console.log(' const storage = new Strata();');
15
+ console.log(' await storage.initialize();');
16
+ console.log(' await storage.set("key", "value");\n');
17
+
8
18
  // Check if this is a Capacitor project
9
19
  const capacitorConfigPaths = [
10
20
  'capacitor.config.json',
@@ -17,17 +27,18 @@ const isCapacitorProject = capacitorConfigPaths.some(configPath =>
17
27
  );
18
28
 
19
29
  if (isCapacitorProject) {
20
- console.log('šŸ“± Capacitor project detected!');
30
+ console.log('šŸ“± Capacitor Support Available (Optional):');
31
+ console.log(' import { registerCapacitorAdapters } from "strata-storage/capacitor";');
32
+ console.log(' await registerCapacitorAdapters(storage);');
21
33
  console.log(' Run "npx cap sync" to sync native code\n');
22
- } else {
23
- console.log('🌐 Web project detected!');
24
- console.log(' Strata works perfectly in web-only projects too!\n');
25
34
  }
26
35
 
27
- console.log('šŸ“š Quick Start:');
28
- console.log(' import { Strata } from "strata-storage";');
29
- console.log(' const storage = new Strata();');
30
- console.log(' await storage.set("key", "value");\n');
36
+ console.log('✨ Features:');
37
+ console.log(' • Works everywhere - Web, Node.js, Mobile');
38
+ console.log(' • Zero runtime dependencies');
39
+ console.log(' • Optional Capacitor integration');
40
+ console.log(' • Built-in encryption & compression');
41
+ console.log(' • Cross-tab synchronization\n');
31
42
 
32
43
  console.log('šŸ“– Documentation: https://github.com/aoneahsan/strata-storage');
33
44
  console.log('⭐ Star us on GitHub: https://github.com/aoneahsan/strata-storage\n');