strata-storage 1.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 (102) hide show
  1. package/Readme.md +113 -0
  2. package/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
  3. package/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
  4. package/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
  5. package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
  6. package/dist/adapters/capacitor/FilesystemAdapter.d.ts +46 -0
  7. package/dist/adapters/capacitor/FilesystemAdapter.d.ts.map +1 -0
  8. package/dist/adapters/capacitor/FilesystemAdapter.js +162 -0
  9. package/dist/adapters/capacitor/PreferencesAdapter.d.ts +46 -0
  10. package/dist/adapters/capacitor/PreferencesAdapter.d.ts.map +1 -0
  11. package/dist/adapters/capacitor/PreferencesAdapter.js +162 -0
  12. package/dist/adapters/capacitor/SecureAdapter.d.ts +69 -0
  13. package/dist/adapters/capacitor/SecureAdapter.d.ts.map +1 -0
  14. package/dist/adapters/capacitor/SecureAdapter.js +214 -0
  15. package/dist/adapters/capacitor/SqliteAdapter.d.ts +68 -0
  16. package/dist/adapters/capacitor/SqliteAdapter.d.ts.map +1 -0
  17. package/dist/adapters/capacitor/SqliteAdapter.js +277 -0
  18. package/dist/adapters/capacitor/index.d.ts +9 -0
  19. package/dist/adapters/capacitor/index.d.ts.map +1 -0
  20. package/dist/adapters/capacitor/index.js +8 -0
  21. package/dist/adapters/web/CacheAdapter.d.ts +91 -0
  22. package/dist/adapters/web/CacheAdapter.d.ts.map +1 -0
  23. package/dist/adapters/web/CacheAdapter.js +291 -0
  24. package/dist/adapters/web/CookieAdapter.d.ts +77 -0
  25. package/dist/adapters/web/CookieAdapter.d.ts.map +1 -0
  26. package/dist/adapters/web/CookieAdapter.js +260 -0
  27. package/dist/adapters/web/IndexedDBAdapter.d.ts +78 -0
  28. package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -0
  29. package/dist/adapters/web/IndexedDBAdapter.js +371 -0
  30. package/dist/adapters/web/LocalStorageAdapter.d.ts +63 -0
  31. package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -0
  32. package/dist/adapters/web/LocalStorageAdapter.js +238 -0
  33. package/dist/adapters/web/MemoryAdapter.d.ts +69 -0
  34. package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -0
  35. package/dist/adapters/web/MemoryAdapter.js +165 -0
  36. package/dist/adapters/web/SessionStorageAdapter.d.ts +53 -0
  37. package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -0
  38. package/dist/adapters/web/SessionStorageAdapter.js +180 -0
  39. package/dist/adapters/web/index.d.ts +10 -0
  40. package/dist/adapters/web/index.d.ts.map +1 -0
  41. package/dist/adapters/web/index.js +9 -0
  42. package/dist/core/AdapterRegistry.d.ts +52 -0
  43. package/dist/core/AdapterRegistry.d.ts.map +1 -0
  44. package/dist/core/AdapterRegistry.js +102 -0
  45. package/dist/core/BaseAdapter.d.ts +79 -0
  46. package/dist/core/BaseAdapter.d.ts.map +1 -0
  47. package/dist/core/BaseAdapter.js +197 -0
  48. package/dist/core/StorageStrategy.d.ts +55 -0
  49. package/dist/core/StorageStrategy.d.ts.map +1 -0
  50. package/dist/core/StorageStrategy.js +199 -0
  51. package/dist/core/Strata.d.ts +122 -0
  52. package/dist/core/Strata.d.ts.map +1 -0
  53. package/dist/core/Strata.js +568 -0
  54. package/dist/features/compression.d.ts +65 -0
  55. package/dist/features/compression.d.ts.map +1 -0
  56. package/dist/features/compression.js +205 -0
  57. package/dist/features/encryption.d.ts +68 -0
  58. package/dist/features/encryption.d.ts.map +1 -0
  59. package/dist/features/encryption.js +172 -0
  60. package/dist/features/migration.d.ts +17 -0
  61. package/dist/features/migration.d.ts.map +1 -0
  62. package/dist/features/migration.js +43 -0
  63. package/dist/features/query.d.ts +75 -0
  64. package/dist/features/query.d.ts.map +1 -0
  65. package/dist/features/query.js +305 -0
  66. package/dist/features/sync.d.ts +87 -0
  67. package/dist/features/sync.d.ts.map +1 -0
  68. package/dist/features/sync.js +233 -0
  69. package/dist/features/ttl.d.ts +124 -0
  70. package/dist/features/ttl.d.ts.map +1 -0
  71. package/dist/features/ttl.js +236 -0
  72. package/dist/index.d.ts +44 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +46 -0
  75. package/dist/package.json +60 -0
  76. package/dist/plugin/definitions.d.ts +219 -0
  77. package/dist/plugin/definitions.d.ts.map +1 -0
  78. package/dist/plugin/definitions.js +5 -0
  79. package/dist/plugin/index.d.ts +8 -0
  80. package/dist/plugin/index.d.ts.map +1 -0
  81. package/dist/plugin/index.js +27 -0
  82. package/dist/plugin/web.d.ts +24 -0
  83. package/dist/plugin/web.d.ts.map +1 -0
  84. package/dist/plugin/web.js +35 -0
  85. package/dist/types/index.d.ts +558 -0
  86. package/dist/types/index.d.ts.map +1 -0
  87. package/dist/types/index.js +14 -0
  88. package/dist/utils/errors.d.ts +92 -0
  89. package/dist/utils/errors.d.ts.map +1 -0
  90. package/dist/utils/errors.js +153 -0
  91. package/dist/utils/index.d.ts +105 -0
  92. package/dist/utils/index.d.ts.map +1 -0
  93. package/dist/utils/index.js +329 -0
  94. package/ios/Plugin/KeychainStorage.swift +87 -0
  95. package/ios/Plugin/SQLiteStorage.swift +167 -0
  96. package/ios/Plugin/StrataStoragePlugin.swift +204 -0
  97. package/ios/Plugin/UserDefaultsStorage.swift +44 -0
  98. package/package.json +126 -0
  99. package/scripts/build.js +52 -0
  100. package/scripts/cli.js +60 -0
  101. package/scripts/configure.js +444 -0
  102. package/scripts/postinstall.js +33 -0
@@ -0,0 +1,444 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Strata Storage Configuration Script
5
+ * Usage: npx strata-storage configure
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const { execSync } = require('child_process');
11
+
12
+ // Colors for terminal output
13
+ const colors = {
14
+ reset: '\x1b[0m',
15
+ bright: '\x1b[1m',
16
+ green: '\x1b[32m',
17
+ yellow: '\x1b[33m',
18
+ blue: '\x1b[34m',
19
+ red: '\x1b[31m',
20
+ cyan: '\x1b[36m'
21
+ };
22
+
23
+ const log = {
24
+ info: (msg) => console.log(`${colors.blue}ℹ${colors.reset} ${msg}`),
25
+ success: (msg) => console.log(`${colors.green}āœ“${colors.reset} ${msg}`),
26
+ warning: (msg) => console.log(`${colors.yellow}⚠${colors.reset} ${msg}`),
27
+ error: (msg) => console.log(`${colors.red}āœ–${colors.reset} ${msg}`),
28
+ title: (msg) => console.log(`\n${colors.bright}${msg}${colors.reset}\n`)
29
+ };
30
+
31
+ // Configuration options
32
+ const frameworks = ['react', 'vue', 'angular', 'none'];
33
+ const platforms = ['web', 'ios', 'android', 'all'];
34
+ const features = {
35
+ encryption: 'Enable encryption with Web Crypto API',
36
+ compression: 'Enable LZ-string compression',
37
+ sync: 'Enable cross-tab synchronization',
38
+ ttl: 'Enable TTL (Time To Live) support',
39
+ query: 'Enable advanced querying'
40
+ };
41
+
42
+ // Main configuration function
43
+ async function configure() {
44
+ log.title('šŸ—„ļø Strata Storage Configuration');
45
+
46
+ // Detect project type
47
+ const projectInfo = detectProject();
48
+
49
+ // Interactive prompts
50
+ const config = await getConfiguration(projectInfo);
51
+
52
+ // Generate configuration files
53
+ await generateFiles(config);
54
+
55
+ // Install dependencies if needed
56
+ await installDependencies(config);
57
+
58
+ // Show completion message
59
+ showCompletion(config);
60
+ }
61
+
62
+ // Detect project type and structure
63
+ function detectProject() {
64
+ const info = {
65
+ hasPackageJson: false,
66
+ hasTsConfig: false,
67
+ framework: 'none',
68
+ packageManager: 'npm',
69
+ isCapacitor: false
70
+ };
71
+
72
+ // Check for package.json
73
+ if (fs.existsSync('package.json')) {
74
+ info.hasPackageJson = true;
75
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
76
+
77
+ // Detect framework
78
+ if (pkg.dependencies?.react || pkg.devDependencies?.react) {
79
+ info.framework = 'react';
80
+ } else if (pkg.dependencies?.vue || pkg.devDependencies?.vue) {
81
+ info.framework = 'vue';
82
+ } else if (pkg.dependencies?.['@angular/core'] || pkg.devDependencies?.['@angular/core']) {
83
+ info.framework = 'angular';
84
+ }
85
+
86
+ // Detect Capacitor
87
+ if (pkg.dependencies?.['@capacitor/core']) {
88
+ info.isCapacitor = true;
89
+ }
90
+
91
+ // Detect package manager
92
+ if (fs.existsSync('yarn.lock')) {
93
+ info.packageManager = 'yarn';
94
+ } else if (fs.existsSync('pnpm-lock.yaml')) {
95
+ info.packageManager = 'pnpm';
96
+ }
97
+ }
98
+
99
+ // Check for TypeScript
100
+ if (fs.existsSync('tsconfig.json')) {
101
+ info.hasTsConfig = true;
102
+ }
103
+
104
+ return info;
105
+ }
106
+
107
+ // Get configuration through prompts
108
+ async function getConfiguration(projectInfo) {
109
+ const readline = require('readline');
110
+ const rl = readline.createInterface({
111
+ input: process.stdin,
112
+ output: process.stdout
113
+ });
114
+
115
+ const question = (prompt) => new Promise((resolve) => {
116
+ rl.question(prompt, resolve);
117
+ });
118
+
119
+ const config = {
120
+ framework: projectInfo.framework,
121
+ platforms: [],
122
+ features: {},
123
+ typescript: projectInfo.hasTsConfig,
124
+ packageManager: projectInfo.packageManager
125
+ };
126
+
127
+ log.info(`Detected: ${projectInfo.framework === 'none' ? 'Vanilla JS' : projectInfo.framework} project`);
128
+
129
+ // Framework selection (if not detected)
130
+ if (projectInfo.framework === 'none') {
131
+ console.log('\nWhich framework are you using?');
132
+ frameworks.forEach((f, i) => console.log(` ${i + 1}) ${f}`));
133
+
134
+ const frameworkChoice = await question('\nSelect framework (1-4): ');
135
+ config.framework = frameworks[parseInt(frameworkChoice) - 1] || 'none';
136
+ }
137
+
138
+ // Platform selection
139
+ console.log('\nWhich platforms will you target?');
140
+ platforms.forEach((p, i) => console.log(` ${i + 1}) ${p}`));
141
+
142
+ const platformChoice = await question('\nSelect platform (1-4): ');
143
+ const selectedPlatform = platforms[parseInt(platformChoice) - 1] || 'web';
144
+
145
+ if (selectedPlatform === 'all') {
146
+ config.platforms = ['web', 'ios', 'android'];
147
+ } else {
148
+ config.platforms = [selectedPlatform];
149
+ }
150
+
151
+ // Feature selection
152
+ console.log('\nWhich features do you want to enable?');
153
+ for (const [key, desc] of Object.entries(features)) {
154
+ const enable = await question(`${desc}? (y/N): `);
155
+ config.features[key] = enable.toLowerCase() === 'y';
156
+ }
157
+
158
+ // TypeScript
159
+ if (!projectInfo.hasTsConfig) {
160
+ const useTs = await question('\nUse TypeScript? (Y/n): ');
161
+ config.typescript = useTs.toLowerCase() !== 'n';
162
+ }
163
+
164
+ rl.close();
165
+ return config;
166
+ }
167
+
168
+ // Generate configuration files
169
+ async function generateFiles(config) {
170
+ log.title('Generating configuration files...');
171
+
172
+ // Create strata.config.js
173
+ const configContent = generateConfigFile(config);
174
+ fs.writeFileSync('strata.config.js', configContent);
175
+ log.success('Created strata.config.js');
176
+
177
+ // Create TypeScript declaration if needed
178
+ if (config.typescript) {
179
+ const dtsContent = generateTypeDeclaration();
180
+ fs.writeFileSync('strata.d.ts', dtsContent);
181
+ log.success('Created strata.d.ts');
182
+ }
183
+
184
+ // Create example file
185
+ const exampleContent = generateExampleFile(config);
186
+ const examplePath = `strata.example.${config.typescript ? 'ts' : 'js'}`;
187
+ fs.writeFileSync(examplePath, exampleContent);
188
+ log.success(`Created ${examplePath}`);
189
+
190
+ // Update .gitignore
191
+ updateGitignore();
192
+ }
193
+
194
+ // Generate config file content
195
+ function generateConfigFile(config) {
196
+ const enabledFeatures = Object.entries(config.features)
197
+ .filter(([_, enabled]) => enabled)
198
+ .map(([key]) => key);
199
+
200
+ return `/**
201
+ * Strata Storage Configuration
202
+ * Generated by: npx strata-storage configure
203
+ */
204
+
205
+ ${config.typescript ? "import type { StrataConfig } from 'strata-storage';\n" : ''}
206
+ ${config.typescript ? 'const config: StrataConfig' : 'module.exports'} = {
207
+ // Default storage types in order of preference
208
+ defaultStorages: [${config.platforms.includes('web') ? "'indexedDB', 'localStorage'" : "'preferences', 'sqlite'"}, 'memory'],
209
+
210
+ // Platform configuration
211
+ platform: '${config.platforms[0]}',
212
+
213
+ // Feature flags
214
+ ${enabledFeatures.includes('encryption') ? `encryption: {
215
+ enabled: true,
216
+ algorithm: 'AES-GCM',
217
+ keyDerivation: {
218
+ algorithm: 'PBKDF2',
219
+ iterations: 100000,
220
+ salt: 32,
221
+ hash: 'SHA-256'
222
+ }
223
+ },` : '// encryption: { enabled: false },'}
224
+
225
+ ${enabledFeatures.includes('compression') ? `compression: {
226
+ enabled: true,
227
+ threshold: 1024, // Only compress if larger than 1KB
228
+ level: 6
229
+ },` : '// compression: { enabled: false },'}
230
+
231
+ ${enabledFeatures.includes('sync') ? `sync: {
232
+ enabled: true,
233
+ debounce: 100,
234
+ broadcastChannel: 'strata-sync'
235
+ },` : '// sync: { enabled: false },'}
236
+
237
+ ${enabledFeatures.includes('ttl') ? `ttl: {
238
+ defaultTTL: 3600000, // 1 hour
239
+ cleanupInterval: 60000, // 1 minute
240
+ autoCleanup: true
241
+ },` : '// ttl: { autoCleanup: false },'}
242
+
243
+ // Adapter-specific configurations
244
+ adapters: {
245
+ indexedDB: {
246
+ database: 'strata-storage',
247
+ version: 1
248
+ },
249
+ sqlite: {
250
+ database: 'strata.db',
251
+ location: 'default'
252
+ },
253
+ filesystem: {
254
+ directory: 'strata-data',
255
+ encoding: 'utf8'
256
+ }
257
+ }
258
+ };
259
+
260
+ ${config.typescript ? 'export default config;' : ''}`;
261
+ }
262
+
263
+ // Generate TypeScript declaration
264
+ function generateTypeDeclaration() {
265
+ return `/// <reference types="strata-storage" />
266
+
267
+ declare module 'strata-storage' {
268
+ // Additional type declarations if needed
269
+ }`;
270
+ }
271
+
272
+ // Generate example file
273
+ function generateExampleFile(config) {
274
+ const imports = config.framework === 'react'
275
+ ? "import { StrataProvider, useStorage } from 'strata-storage/react';"
276
+ : config.framework === 'vue'
277
+ ? "import { useStorage } from 'strata-storage/vue';"
278
+ : config.framework === 'angular'
279
+ ? "import { StrataService } from 'strata-storage/angular';"
280
+ : "import { Strata } from 'strata-storage';";
281
+
282
+ const example = config.framework === 'react' ? `
283
+ // React Example
284
+ function App() {
285
+ return (
286
+ <StrataProvider config={config}>
287
+ <UserProfile />
288
+ </StrataProvider>
289
+ );
290
+ }
291
+
292
+ function UserProfile() {
293
+ const [user, setUser, loading] = useStorage('user', { name: 'Guest' });
294
+
295
+ if (loading) return <div>Loading...</div>;
296
+
297
+ return (
298
+ <div>
299
+ <h1>Hello, {user?.name}!</h1>
300
+ <button onClick={() => setUser({ name: 'John' })}>
301
+ Update Name
302
+ </button>
303
+ </div>
304
+ );
305
+ }` : config.framework === 'vue' ? `
306
+ // Vue Example
307
+ export default {
308
+ setup() {
309
+ const { value: user, update } = useStorage('user', { name: 'Guest' });
310
+
311
+ const updateName = () => {
312
+ update({ name: 'John' });
313
+ };
314
+
315
+ return { user, updateName };
316
+ }
317
+ }` : config.framework === 'angular' ? `
318
+ // Angular Example
319
+ @Component({
320
+ selector: 'app-user',
321
+ template: \`
322
+ <h1>Hello, {{ (user$ | async)?.name || 'Guest' }}!</h1>
323
+ <button (click)="updateName()">Update Name</button>
324
+ \`
325
+ })
326
+ export class UserComponent {
327
+ user$ = this.strata.watch<{ name: string }>('user');
328
+
329
+ constructor(private strata: StrataService) {}
330
+
331
+ updateName() {
332
+ this.strata.set('user', { name: 'John' }).subscribe();
333
+ }
334
+ }` : `
335
+ // Vanilla JS Example
336
+ const storage = new Strata(config);
337
+
338
+ // Initialize
339
+ await storage.initialize();
340
+
341
+ // Store data
342
+ await storage.set('user', { name: 'John' });
343
+
344
+ // Retrieve data
345
+ const user = await storage.get('user');
346
+ console.log(user); // { name: 'John' }
347
+
348
+ // Subscribe to changes
349
+ storage.subscribe((change) => {
350
+ console.log('Storage changed:', change);
351
+ });`;
352
+
353
+ return `/**
354
+ * Strata Storage Example
355
+ */
356
+
357
+ ${imports}
358
+ import config from './strata.config${config.typescript ? '' : '.js'}';
359
+ ${example}`;
360
+ }
361
+
362
+ // Update .gitignore
363
+ function updateGitignore() {
364
+ const gitignorePath = '.gitignore';
365
+ const entries = [
366
+ '# Strata Storage',
367
+ 'strata-data/',
368
+ '*.db',
369
+ '*.db-journal'
370
+ ];
371
+
372
+ if (fs.existsSync(gitignorePath)) {
373
+ const content = fs.readFileSync(gitignorePath, 'utf8');
374
+ const hasStrata = content.includes('# Strata Storage');
375
+
376
+ if (!hasStrata) {
377
+ fs.appendFileSync(gitignorePath, '\n' + entries.join('\n') + '\n');
378
+ log.success('Updated .gitignore');
379
+ }
380
+ } else {
381
+ fs.writeFileSync(gitignorePath, entries.join('\n') + '\n');
382
+ log.success('Created .gitignore');
383
+ }
384
+ }
385
+
386
+ // Install dependencies
387
+ async function installDependencies(config) {
388
+ log.title('Installing dependencies...');
389
+
390
+ const deps = ['strata-storage'];
391
+
392
+ // Add platform-specific dependencies
393
+ if (config.platforms.includes('ios') || config.platforms.includes('android')) {
394
+ deps.push('@capacitor/core');
395
+ }
396
+
397
+ // Install command
398
+ const command = config.packageManager === 'yarn'
399
+ ? `yarn add ${deps.join(' ')}`
400
+ : config.packageManager === 'pnpm'
401
+ ? `pnpm add ${deps.join(' ')}`
402
+ : `npm install ${deps.join(' ')}`;
403
+
404
+ try {
405
+ log.info(`Running: ${command}`);
406
+ execSync(command, { stdio: 'inherit' });
407
+ log.success('Dependencies installed');
408
+ } catch (error) {
409
+ log.error('Failed to install dependencies');
410
+ log.info(`Please run: ${command}`);
411
+ }
412
+ }
413
+
414
+ // Show completion message
415
+ function showCompletion(config) {
416
+ log.title('✨ Configuration complete!');
417
+
418
+ console.log('Next steps:\n');
419
+
420
+ if (config.framework === 'react') {
421
+ console.log('1. Import StrataProvider in your App component');
422
+ console.log('2. Wrap your app with <StrataProvider config={config}>');
423
+ console.log('3. Use hooks like useStorage() in your components');
424
+ } else if (config.framework === 'vue') {
425
+ console.log('1. Install the plugin: app.use(StrataPlugin, config)');
426
+ console.log('2. Use composables like useStorage() in your components');
427
+ } else if (config.framework === 'angular') {
428
+ console.log('1. Import StrataModule.forRoot(config) in AppModule');
429
+ console.log('2. Inject StrataService in your components');
430
+ } else {
431
+ console.log('1. Import and initialize Strata with your config');
432
+ console.log('2. Use storage.set() and storage.get() methods');
433
+ }
434
+
435
+ console.log('\nSee strata.example.* for a complete example.');
436
+ console.log('\nDocumentation: https://github.com/aoneahsan/strata-storage');
437
+ }
438
+
439
+ // Run configuration
440
+ configure().catch((error) => {
441
+ log.error('Configuration failed:');
442
+ console.error(error);
443
+ process.exit(1);
444
+ });
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ console.log('\nšŸš€ Strata Storage - Zero Dependencies, Infinite Possibilities!\n');
7
+
8
+ // Check if this is a Capacitor project
9
+ const capacitorConfigPaths = [
10
+ 'capacitor.config.json',
11
+ 'capacitor.config.ts',
12
+ 'capacitor.config.js'
13
+ ];
14
+
15
+ const isCapacitorProject = capacitorConfigPaths.some(configPath =>
16
+ fs.existsSync(path.join(process.cwd(), configPath))
17
+ );
18
+
19
+ if (isCapacitorProject) {
20
+ console.log('šŸ“± Capacitor project detected!');
21
+ 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
+ }
26
+
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');
31
+
32
+ console.log('šŸ“– Documentation: https://github.com/aoneahsan/strata-storage');
33
+ console.log('⭐ Star us on GitHub: https://github.com/aoneahsan/strata-storage\n');