@jeanharo98/typed-storage 0.1.3 → 0.1.4
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/create-storage.js +11 -0
- package/package.json +1 -1
- package/src/create-storage.ts +19 -0
package/dist/create-storage.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { createStorageSignal } from './storage-signal.js';
|
|
2
2
|
import { applyMigrations } from './migrations.js';
|
|
3
|
+
function registerPrefix(prefix, sto) {
|
|
4
|
+
const registryKey = '__typed-storage__';
|
|
5
|
+
const existing = sto.getItem(registryKey);
|
|
6
|
+
const prefixes = existing ? JSON.parse(existing) : [];
|
|
7
|
+
if (prefix && !prefixes.includes(prefix)) {
|
|
8
|
+
prefixes.push(prefix);
|
|
9
|
+
sto.setItem(registryKey, JSON.stringify(prefixes));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
export function createStorage(schema, options) {
|
|
4
13
|
if (options?.version && options.migrations) {
|
|
5
14
|
const sto = options.storage === 'session' ? sessionStorage : localStorage;
|
|
6
15
|
const prefix = options.prefix ?? '';
|
|
7
16
|
applyMigrations(prefix, options.version, options.migrations, sto);
|
|
8
17
|
}
|
|
18
|
+
const sto = options?.storage === 'session' ? sessionStorage : localStorage;
|
|
19
|
+
registerPrefix(options?.prefix ?? '', sto);
|
|
9
20
|
if (options?.encrypt) {
|
|
10
21
|
console.warn(`
|
|
11
22
|
⚠️ typed-storage: la opción encrypt está activada.
|
package/package.json
CHANGED
package/src/create-storage.ts
CHANGED
|
@@ -7,10 +7,25 @@ import { createStorageSignal } from './storage-signal.js';
|
|
|
7
7
|
// Migraciones
|
|
8
8
|
import { applyMigrations } from './migrations.js';
|
|
9
9
|
|
|
10
|
+
function registerPrefix (
|
|
11
|
+
prefix: string,
|
|
12
|
+
sto: Storage
|
|
13
|
+
): void {
|
|
14
|
+
const registryKey = '__typed-storage__';
|
|
15
|
+
const existing = sto.getItem(registryKey);
|
|
16
|
+
const prefixes: string[] = existing ? JSON.parse(existing) : [];
|
|
17
|
+
|
|
18
|
+
if ( prefix && !prefixes.includes(prefix) ) {
|
|
19
|
+
prefixes.push(prefix);
|
|
20
|
+
sto.setItem(registryKey, JSON.stringify(prefixes));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
export function createStorage<T extends StorageSchema>(
|
|
11
25
|
schema: T,
|
|
12
26
|
options?: StorageSignalOptions
|
|
13
27
|
): StorageResult<T> {
|
|
28
|
+
// Migraciones
|
|
14
29
|
if ( options?.version && options.migrations ) {
|
|
15
30
|
const sto = options.storage === 'session' ? sessionStorage : localStorage;
|
|
16
31
|
const prefix = options.prefix ?? '';
|
|
@@ -23,6 +38,10 @@ export function createStorage<T extends StorageSchema>(
|
|
|
23
38
|
);
|
|
24
39
|
}
|
|
25
40
|
|
|
41
|
+
// Registramos el prefix en localStorage
|
|
42
|
+
const sto = options?.storage === 'session' ? sessionStorage : localStorage;
|
|
43
|
+
registerPrefix(options?.prefix ?? '', sto);
|
|
44
|
+
|
|
26
45
|
if ( options?.encrypt ) {
|
|
27
46
|
console.warn(`
|
|
28
47
|
⚠️ typed-storage: la opción encrypt está activada.
|