@telperion/reactive-storage 1.2.0 → 1.3.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 (56) hide show
  1. package/.build-manifest.json +96 -0
  2. package/fesm/reactive-storage.mjs +620 -0
  3. package/fesm/reactive-storage.mjs.map +1 -0
  4. package/index.cjs +17 -8
  5. package/index.cjs.map +1 -0
  6. package/index.d.cts +6 -0
  7. package/index.d.ts +6 -5
  8. package/index.js +5 -6
  9. package/index.js.map +1 -1
  10. package/json-parse.cjs +5 -3
  11. package/json-parse.cjs.map +1 -0
  12. package/json-parse.d.cts +8 -0
  13. package/json-parse.d.ts +3 -1
  14. package/json-parse.js +2 -1
  15. package/json-parse.js.map +1 -1
  16. package/package.json +70 -31
  17. package/reactive-cookie-storage.cjs +49 -44
  18. package/reactive-cookie-storage.cjs.map +1 -0
  19. package/reactive-cookie-storage.d.cts +77 -0
  20. package/reactive-cookie-storage.d.ts +48 -40
  21. package/reactive-cookie-storage.js +40 -35
  22. package/reactive-cookie-storage.js.map +1 -1
  23. package/reactive-storage.cjs +127 -74
  24. package/reactive-storage.cjs.map +1 -0
  25. package/reactive-storage.d.cts +144 -0
  26. package/reactive-storage.d.ts +87 -27
  27. package/reactive-storage.js +84 -31
  28. package/reactive-storage.js.map +1 -1
  29. package/reactive-web-local-storage.cjs +31 -8
  30. package/reactive-web-local-storage.cjs.map +1 -0
  31. package/reactive-web-local-storage.d.cts +38 -0
  32. package/reactive-web-local-storage.d.ts +31 -5
  33. package/reactive-web-local-storage.js +28 -5
  34. package/reactive-web-local-storage.js.map +1 -1
  35. package/reactive-web-session-storage.cjs +24 -8
  36. package/reactive-web-session-storage.cjs.map +1 -0
  37. package/reactive-web-session-storage.d.cts +31 -0
  38. package/reactive-web-session-storage.d.ts +24 -5
  39. package/reactive-web-session-storage.js +21 -5
  40. package/reactive-web-session-storage.js.map +1 -1
  41. package/reactive-web-storage.cjs +39 -23
  42. package/reactive-web-storage.cjs.map +1 -0
  43. package/reactive-web-storage.d.cts +47 -0
  44. package/reactive-web-storage.d.ts +28 -10
  45. package/reactive-web-storage.js +29 -13
  46. package/reactive-web-storage.js.map +1 -1
  47. package/regex-parser.cjs +4 -3
  48. package/regex-parser.cjs.map +1 -0
  49. package/regex-parser.d.cts +13 -0
  50. package/regex-parser.d.ts +3 -1
  51. package/regex-parser.js +2 -1
  52. package/regex-parser.js.map +1 -1
  53. package/async-iterator.polyfill.cjs +0 -87
  54. package/async-iterator.polyfill.d.ts +0 -2
  55. package/async-iterator.polyfill.js +0 -86
  56. package/async-iterator.polyfill.js.map +0 -1
@@ -1,20 +1,50 @@
1
- import { Observable } from "rxjs";
1
+ import { Observable } from 'rxjs';
2
+
2
3
  declare const GET_ALL: unique symbol;
3
4
  declare const CHANGES: unique symbol;
4
5
  declare const SET: unique symbol;
5
6
  declare const REMOVE: unique symbol;
6
- export interface ReactiveStorageChangeEvent<S = string> {
7
+ /**
8
+ * A change to one store, as a storage implementation reports it to {@link ReactiveStorage}.
9
+ * `value` is the store's new content, or `undefined` when the store was removed.
10
+ *
11
+ * @template S - Store name type
12
+ */
13
+ interface ReactiveStorageChangeEvent<S = string> {
7
14
  storeName: S;
8
15
  value: any;
9
16
  }
10
17
  /**
11
- * Abstract base class for reactive storage implementations.
12
- * Provides RxJS-based reactive API for storage with support for nested property access.
13
- * All write operations are queued using FIFO promises to ensure consistency.
18
+ * Abstract base class of every reactive storage: the shared `get`/`set`/`patch`/`delete`/`push`/`drop` API.
19
+ *
20
+ * Data is organised in named **stores**: one JSON value per store name (one localStorage key, one cookie).
21
+ * Read and write inside a store with a dot-separated **key path** (`'profile.name'`); an empty key
22
+ * means the whole store.
23
+ *
24
+ * - `get()` returns an Observable that emits the current value right away and again whenever it changes.
25
+ * Repeats of the same value (`===`) are skipped, so a primitive at a path emits only when it changes.
26
+ * - Emitted values are deep-frozen: copy them before changing them.
27
+ * - Writes return a Promise that resolves once subscribers have been notified. Writes from every
28
+ * storage instance run one at a time, first in first out; one that takes longer than a second
29
+ * is rejected with a `TimeoutError`.
30
+ * - Only writes made through the same instance (or, for cookies, linked instances) are observed.
31
+ *
32
+ * Example usage:
33
+ * ```ts
34
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
14
35
  *
15
- * @template S - Storage store name type (defaults to string)
36
+ * const storage = new ReactiveWebLocalStorage<'user' | 'settings'>('my-app');
37
+ *
38
+ * storage.get<string>('user', 'profile.name').subscribe((name) => console.log(name));
39
+ * // undefined
40
+ *
41
+ * await storage.set('user', 'profile.name', 'Ada');
42
+ * // Ada
43
+ * ```
44
+ *
45
+ * @template S - Store name type: a union of string literals restricts the store names you can use
16
46
  */
17
- export declare abstract class ReactiveStorage<S extends string = string> {
47
+ declare abstract class ReactiveStorage<S extends string = string> {
18
48
  #private;
19
49
  private static FifoGroup;
20
50
  private static extractData;
@@ -29,22 +59,38 @@ export declare abstract class ReactiveStorage<S extends string = string> {
29
59
  protected abstract [SET](store: S, value: any): Promise<void>;
30
60
  protected abstract [REMOVE](store: S): Promise<void>;
31
61
  /**
32
- * Get an observable that emits the current value and all future changes.
33
- * Supports dot notation for nested property access (e.g., 'user.settings.theme').
62
+ * Observable of a store, or of one value inside it, that emits the current value and then every change.
34
63
  *
35
- * @template T - Expected return type
36
- * @param storeName - Name of the storage store
37
- * @param key - Property path using dot notation (empty string for entire store)
38
- * @returns Observable that emits current value and all updates
64
+ * The value is `undefined` while the store or path does not exist. Emitted values are deep-frozen.
65
+ *
66
+ * Example usage:
67
+ * ```ts
68
+ * storage.get('user').subscribe((user) => console.log(user)); // whole store
69
+ * storage.get<string>('user', 'profile.name').subscribe(console.log); // one value
70
+ * ```
71
+ *
72
+ * @template T - Type of the value at `key`
73
+ * @param storeName - Store to read
74
+ * @param key - Dot-separated path inside the store; empty (default) for the whole store
75
+ * @returns Observable of the value, which never completes
39
76
  */
40
77
  get<T = Record<string, any>>(storeName: S, key?: string): Observable<T>;
41
78
  /**
42
- * Set a value in storage. Overwrites existing value.
43
- * Pass undefined as value to remove the property.
79
+ * Writes a value at a path, replacing what was there and creating missing parent objects.
44
80
  *
45
- * @param storeName - Name of the storage store
46
- * @param key - Property path using dot notation
47
- * @param value - Value to set (undefined removes the value)
81
+ * The value is stored as JSON, so it must be JSON-serializable. Passing `undefined` removes
82
+ * the property (or, with an empty key, the whole store).
83
+ *
84
+ * Example usage:
85
+ * ```ts
86
+ * await storage.set('user', '', { name: 'Ada' }); // whole store
87
+ * await storage.set('user', 'profile.theme', 'dark'); // { name: 'Ada', profile: { theme: 'dark' } }
88
+ * ```
89
+ *
90
+ * @param storeName - Store to write
91
+ * @param key - Dot-separated path inside the store; empty for the whole store
92
+ * @param value - New value; `undefined` removes it
93
+ * @returns Resolves once subscribers have received the new value
48
94
  */
49
95
  set(storeName: S, key: string, value: any): Promise<void>;
50
96
  /**
@@ -57,19 +103,31 @@ export declare abstract class ReactiveStorage<S extends string = string> {
57
103
  */
58
104
  patch(storeName: S, key: string, value: any): Promise<void>;
59
105
  /**
60
- * Delete a value from storage.
106
+ * Removes a value at a path, or the whole store. Same as `set(storeName, key, undefined)`.
61
107
  *
62
- * @param storeName - Name of the storage store
63
- * @param key - Property path using dot notation (empty string deletes entire store)
108
+ * Example usage:
109
+ * ```ts
110
+ * await storage.delete('user', 'profile.theme'); // one property
111
+ * await storage.delete('user'); // the whole store
112
+ * ```
113
+ *
114
+ * @param storeName - Store to change
115
+ * @param key - Dot-separated path inside the store; empty (default) removes the whole store
116
+ * @returns Resolves once subscribers have been notified
64
117
  */
65
118
  delete(storeName: S, key?: string): Promise<void>;
66
119
  /**
67
- * Add items to an array in storage.
68
- * Creates array if it doesn't exist.
120
+ * Appends values to the array at a path, creating the array when there is none.
69
121
  *
70
- * @param storeName - Name of the storage store
71
- * @param key - Path to array property using dot notation
72
- * @param values - Values to push into the array
122
+ * Example usage:
123
+ * ```ts
124
+ * await storage.push('todos', 'items', 'Buy milk', 'Walk the dog');
125
+ * ```
126
+ *
127
+ * @param storeName - Store to change
128
+ * @param key - Dot-separated path of the array inside the store
129
+ * @param values - Values to append
130
+ * @returns Resolves once subscribers have been notified
73
131
  */
74
132
  push(storeName: S, key: string, ...values: any[]): Promise<void>;
75
133
  /**
@@ -81,4 +139,6 @@ export declare abstract class ReactiveStorage<S extends string = string> {
81
139
  */
82
140
  drop(storeName: S, key: string, value: any): Promise<void>;
83
141
  }
84
- export {};
142
+
143
+ export { ReactiveStorage };
144
+ export type { ReactiveStorageChangeEvent };
@@ -1,23 +1,47 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { from, switchMap, map, startWith, distinctUntilChanged, firstValueFrom, lastValueFrom, take } from 'rxjs';
3
+ import { compact } from '@telperion/js-utils/array/compact';
4
+ import { remove } from '@telperion/js-utils/array/remove';
5
+ import { deepFreeze } from '@telperion/js-utils/object/deep-freeze';
6
+ import { shareLast } from '@telperion/rx-utils/operators/share-last';
7
+ import { FifoPromise } from '@telperion/ts-utils/fifo-promise';
8
+
1
9
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { __decorate, __metadata } from "tslib";
3
- import { distinctUntilChanged, firstValueFrom, from, lastValueFrom, map, startWith, switchMap, take } from "rxjs";
4
- import { compact } from "@thalesrc/js-utils/array/compact";
5
- import { remove } from "@thalesrc/js-utils/array/remove";
6
- import { deepFreeze } from "@thalesrc/js-utils/object/deep-freeze";
7
- import { shareLast } from "@thalesrc/rx-utils/operators/share-last";
8
- import { FifoPromise } from "@thalesrc/ts-utils/fifo-promise";
9
10
  const GET_ALL = Symbol('Reactive Storage Get All');
10
11
  const CHANGES = Symbol('Reactive Storage Changes');
11
12
  const SET = Symbol('Reactive Storage Set');
12
13
  const REMOVE = Symbol('Reactive Storage Remove');
13
14
  /**
14
- * Abstract base class for reactive storage implementations.
15
- * Provides RxJS-based reactive API for storage with support for nested property access.
16
- * All write operations are queued using FIFO promises to ensure consistency.
15
+ * Abstract base class of every reactive storage: the shared `get`/`set`/`patch`/`delete`/`push`/`drop` API.
16
+ *
17
+ * Data is organised in named **stores**: one JSON value per store name (one localStorage key, one cookie).
18
+ * Read and write inside a store with a dot-separated **key path** (`'profile.name'`); an empty key
19
+ * means the whole store.
20
+ *
21
+ * - `get()` returns an Observable that emits the current value right away and again whenever it changes.
22
+ * Repeats of the same value (`===`) are skipped, so a primitive at a path emits only when it changes.
23
+ * - Emitted values are deep-frozen: copy them before changing them.
24
+ * - Writes return a Promise that resolves once subscribers have been notified. Writes from every
25
+ * storage instance run one at a time, first in first out; one that takes longer than a second
26
+ * is rejected with a `TimeoutError`.
27
+ * - Only writes made through the same instance (or, for cookies, linked instances) are observed.
28
+ *
29
+ * Example usage:
30
+ * ```ts
31
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
32
+ *
33
+ * const storage = new ReactiveWebLocalStorage<'user' | 'settings'>('my-app');
17
34
  *
18
- * @template S - Storage store name type (defaults to string)
35
+ * storage.get<string>('user', 'profile.name').subscribe((name) => console.log(name));
36
+ * // undefined
37
+ *
38
+ * await storage.set('user', 'profile.name', 'Ada');
39
+ * // Ada
40
+ * ```
41
+ *
42
+ * @template S - Store name type: a union of string literals restricts the store names you can use
19
43
  */
20
- export class ReactiveStorage {
44
+ class ReactiveStorage {
21
45
  static FifoGroup = Symbol();
22
46
  static extractData(data, prop = null) {
23
47
  if (!prop)
@@ -55,13 +79,20 @@ export class ReactiveStorage {
55
79
  return this.#_stream$;
56
80
  }
57
81
  /**
58
- * Get an observable that emits the current value and all future changes.
59
- * Supports dot notation for nested property access (e.g., 'user.settings.theme').
82
+ * Observable of a store, or of one value inside it, that emits the current value and then every change.
60
83
  *
61
- * @template T - Expected return type
62
- * @param storeName - Name of the storage store
63
- * @param key - Property path using dot notation (empty string for entire store)
64
- * @returns Observable that emits current value and all updates
84
+ * The value is `undefined` while the store or path does not exist. Emitted values are deep-frozen.
85
+ *
86
+ * Example usage:
87
+ * ```ts
88
+ * storage.get('user').subscribe((user) => console.log(user)); // whole store
89
+ * storage.get<string>('user', 'profile.name').subscribe(console.log); // one value
90
+ * ```
91
+ *
92
+ * @template T - Type of the value at `key`
93
+ * @param storeName - Store to read
94
+ * @param key - Dot-separated path inside the store; empty (default) for the whole store
95
+ * @returns Observable of the value, which never completes
65
96
  */
66
97
  get(storeName, key = '') {
67
98
  return this.#stream$.pipe(map(allData => ReactiveStorage.extractData(allData, `${storeName}.${key}`)), distinctUntilChanged());
@@ -101,12 +132,21 @@ export class ReactiveStorage {
101
132
  return;
102
133
  }
103
134
  /**
104
- * Set a value in storage. Overwrites existing value.
105
- * Pass undefined as value to remove the property.
135
+ * Writes a value at a path, replacing what was there and creating missing parent objects.
106
136
  *
107
- * @param storeName - Name of the storage store
108
- * @param key - Property path using dot notation
109
- * @param value - Value to set (undefined removes the value)
137
+ * The value is stored as JSON, so it must be JSON-serializable. Passing `undefined` removes
138
+ * the property (or, with an empty key, the whole store).
139
+ *
140
+ * Example usage:
141
+ * ```ts
142
+ * await storage.set('user', '', { name: 'Ada' }); // whole store
143
+ * await storage.set('user', 'profile.theme', 'dark'); // { name: 'Ada', profile: { theme: 'dark' } }
144
+ * ```
145
+ *
146
+ * @param storeName - Store to write
147
+ * @param key - Dot-separated path inside the store; empty for the whole store
148
+ * @param value - New value; `undefined` removes it
149
+ * @returns Resolves once subscribers have received the new value
110
150
  */
111
151
  async set(storeName, key, value) {
112
152
  return await this.#set(storeName, key, value);
@@ -124,21 +164,33 @@ export class ReactiveStorage {
124
164
  await this.#set(storeName, key, Object.assign({}, existing, compact(value)));
125
165
  }
126
166
  /**
127
- * Delete a value from storage.
167
+ * Removes a value at a path, or the whole store. Same as `set(storeName, key, undefined)`.
128
168
  *
129
- * @param storeName - Name of the storage store
130
- * @param key - Property path using dot notation (empty string deletes entire store)
169
+ * Example usage:
170
+ * ```ts
171
+ * await storage.delete('user', 'profile.theme'); // one property
172
+ * await storage.delete('user'); // the whole store
173
+ * ```
174
+ *
175
+ * @param storeName - Store to change
176
+ * @param key - Dot-separated path inside the store; empty (default) removes the whole store
177
+ * @returns Resolves once subscribers have been notified
131
178
  */
132
179
  async delete(storeName, key = '') {
133
180
  return await this.#set(storeName, key, undefined);
134
181
  }
135
182
  /**
136
- * Add items to an array in storage.
137
- * Creates array if it doesn't exist.
183
+ * Appends values to the array at a path, creating the array when there is none.
138
184
  *
139
- * @param storeName - Name of the storage store
140
- * @param key - Path to array property using dot notation
141
- * @param values - Values to push into the array
185
+ * Example usage:
186
+ * ```ts
187
+ * await storage.push('todos', 'items', 'Buy milk', 'Walk the dog');
188
+ * ```
189
+ *
190
+ * @param storeName - Store to change
191
+ * @param key - Dot-separated path of the array inside the store
192
+ * @param values - Values to append
193
+ * @returns Resolves once subscribers have been notified
142
194
  */
143
195
  async push(storeName, key, ...values) {
144
196
  const existing = await firstValueFrom(this.get(storeName, key)) ?? [];
@@ -187,4 +239,5 @@ __decorate([
187
239
  __metadata("design:returntype", Promise)
188
240
  ], ReactiveStorage.prototype, "drop", null);
189
241
 
242
+ export { ReactiveStorage };
190
243
  //# sourceMappingURL=reactive-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/reactive-storage/src/reactive-storage.ts"],"names":[],"mappings":"AAAA,uDAAuD;;AAEvD,OAAO,EAAc,oBAAoB,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC9H,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,MAAM,OAAO,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AACnD,MAAM,OA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AW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;0CAGhE;AAWK;IADL,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;4CAKhE;AASK;IADL,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;6CAGhE;AAWK;IADL,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;2CAKhE;AAUK;IADL,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;2CAKhE","file":"reactive-storage.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { Observable, distinctUntilChanged, firstValueFrom, from, lastValueFrom, map, startWith, switchMap, take } from \"rxjs\";\nimport { compact } from \"@thalesrc/js-utils/array/compact\";\nimport { remove } from \"@thalesrc/js-utils/array/remove\";\nimport { deepFreeze } from \"@thalesrc/js-utils/object/deep-freeze\";\nimport { shareLast } from \"@thalesrc/rx-utils/operators/share-last\";\nimport { FifoPromise } from \"@thalesrc/ts-utils/fifo-promise\";\n\nconst GET_ALL = Symbol('Reactive Storage Get All');\nconst CHANGES = Symbol('Reactive Storage Changes');\nconst SET = Symbol('Reactive Storage Set');\nconst REMOVE = Symbol('Reactive Storage Remove');\n\nexport interface ReactiveStorageChangeEvent<S = string> {\n storeName: S;\n value: any;\n}\n\n/**\n * Abstract base class for reactive storage implementations.\n * Provides RxJS-based reactive API for storage with support for nested property access.\n * All write operations are queued using FIFO promises to ensure consistency.\n *\n * @template S - Storage store name type (defaults to string)\n */\nexport abstract class ReactiveStorage<S extends string = string> {\n private static FifoGroup = Symbol();\n private static extractData<T = any>(data: any, prop: string = null!): T {\n if (!prop) return data;\n\n const fragments = compact(prop.split('.'));\n let value = data;\n\n do {\n try {\n value = value[fragments[0]];\n } catch {\n return undefined!;\n }\n\n fragments.shift();\n } while (fragments.length);\n\n return value;\n }\n\n static Props = { GET_ALL, CHANGES, SET, REMOVE } as const;\n\n protected abstract [GET_ALL](): Promise<any>;\n protected abstract [CHANGES]: AsyncGenerator<ReactiveStorageChangeEvent<S>>;\n protected abstract [SET](store: S, value: any): Promise<void>;\n protected abstract [REMOVE](store: S): Promise<void>;\n\n #_stream$: Observable<Readonly<Record<S, any>>> = null!;\n\n #initializeStream() {\n this.#_stream$ = from(this[GET_ALL]()).pipe(\n switchMap(data => {\n data ??= {};\n\n return from(this[CHANGES]).pipe(\n map(({ storeName, value }) => {\n if (value === undefined) delete data[storeName];\n else data[storeName] = value;\n\n return deepFreeze({ ...data });\n }),\n startWith(deepFreeze({ ...data }))\n );\n }),\n shareLast()\n );\n }\n\n get #stream$() {\n if (!this.#_stream$) this.#initializeStream();\n\n return this.#_stream$;\n }\n\n /**\n * Get an observable that emits the current value and all future changes.\n * Supports dot notation for nested property access (e.g., 'user.settings.theme').\n *\n * @template T - Expected return type\n * @param storeName - Name of the storage store\n * @param key - Property path using dot notation (empty string for entire store)\n * @returns Observable that emits current value and all updates\n */\n get<T = Record<string, any>>(storeName: S, key = ''): Observable<T> {\n return this.#stream$.pipe(\n map(allData => ReactiveStorage.extractData(allData, `${storeName}.${key}`)),\n distinctUntilChanged()\n );\n }\n\n async #set(storeName: S, key: string, value: any): Promise<void> {\n const store = await firstValueFrom(this.get(storeName));\n const storeChangeEvent = lastValueFrom(this.get(storeName).pipe(take(2)));\n const paths = compact(key.split('.'));\n\n if (!paths.length) {\n if (value === undefined) {\n await this[REMOVE](storeName);\n } else {\n await this[SET](storeName, value);\n }\n\n await storeChangeEvent;\n\n return;\n }\n\n const newStore = JSON.parse(JSON.stringify(typeof store === 'object' ? store : {}));\n let lastPiece = newStore;\n\n while (paths.length > 1) {\n if (typeof lastPiece[paths[0]] !== 'object') lastPiece[paths[0]] = {};\n\n lastPiece = lastPiece[paths[0]];\n paths.shift();\n }\n\n if (lastPiece[paths[0]] === value) return;\n\n if (value === undefined) {\n delete lastPiece[paths[0]];\n } else {\n lastPiece[paths[0]] = value;\n }\n\n await this[SET](storeName, newStore);\n await storeChangeEvent;\n\n return;\n }\n\n /**\n * Set a value in storage. Overwrites existing value.\n * Pass undefined as value to remove the property.\n *\n * @param storeName - Name of the storage store\n * @param key - Property path using dot notation\n * @param value - Value to set (undefined removes the value)\n */\n @FifoPromise({ group: ReactiveStorage.FifoGroup, timeout: 1000 })\n async set(storeName: S, key: string, value: any): Promise<void> {\n return await this.#set(storeName, key, value);\n }\n\n /**\n * Merge a partial object into existing value.\n * Only works with object values.\n *\n * @param storeName - Name of the storage store\n * @param key - Property path using dot notation\n * @param value - Partial object to merge with existing value\n */\n @FifoPromise({ group: ReactiveStorage.FifoGroup, timeout: 1000 })\n async patch(storeName: S, key: string, value: any): Promise<void> {\n const existing = await firstValueFrom(this.get<any[]>(storeName, key));\n\n await this.#set(storeName, key, Object.assign({}, existing, compact(value)));\n }\n\n /**\n * Delete a value from storage.\n *\n * @param storeName - Name of the storage store\n * @param key - Property path using dot notation (empty string deletes entire store)\n */\n @FifoPromise({ group: ReactiveStorage.FifoGroup, timeout: 1000 })\n async delete(storeName: S, key = ''): Promise<void> {\n return await this.#set(storeName, key, undefined);\n }\n\n /**\n * Add items to an array in storage.\n * Creates array if it doesn't exist.\n *\n * @param storeName - Name of the storage store\n * @param key - Path to array property using dot notation\n * @param values - Values to push into the array\n */\n @FifoPromise({ group: ReactiveStorage.FifoGroup, timeout: 1000 })\n async push(storeName: S, key: string, ...values: any[]): Promise<void> {\n const existing = await firstValueFrom(this.get<any[]>(storeName, key)) ?? [];\n\n await this.#set(storeName, key, [...existing, ...values]);\n }\n\n /**\n * Remove a specific value from an array in storage.\n *\n * @param storeName - Name of the storage store\n * @param key - Path to array property using dot notation\n * @param value - Value to remove from the array\n */\n @FifoPromise({ group: ReactiveStorage.FifoGroup, timeout: 1000 })\n async drop(storeName: S, key: string, value: any): Promise<void> {\n const existing = await firstValueFrom(this.get<any[]>(storeName, key));\n\n await this.#set(storeName, key, remove(existing, value));\n }\n}\n"]}
1
+ {"version":3,"file":"reactive-storage.js","sources":["../../../libs/reactive-storage/src/reactive-storage.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;AAAA;AASA,MAAM,OAAO,GAAG,MAAM,CAAC,0BAA0B,CAAC;AAClD,MAAM,OAAO,GAAG,MAAM,CAAC,0BAA0B,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,sBAAsB,CAAC;AAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,yBAAyB,CAAC;AAahD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;MACmB,eAAe,CAAA;AAC3B,IAAA,OAAO,SAAS,GAAG,MAAM,EAAE;AAC3B,IAAA,OAAO,WAAW,CAAU,IAAS,EAAE,OAAe,IAAK,EAAA;AACjE,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,OAAO,IAAI;QAEtB,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAI,KAAK,GAAG,IAAI;AAEhB,QAAA,GAAG;AACD,YAAA,IAAI;gBACF,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC7B;AAAE,YAAA,MAAM;AACN,gBAAA,OAAO,SAAU;YACnB;YAEA,SAAS,CAAC,KAAK,EAAE;AACnB,QAAA,CAAC,QAAQ,SAAS,CAAC,MAAM;AAEzB,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,OAAO,KAAK,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAW;IAOzD,SAAS,GAAyC,IAAK;IAEvD,iBAAiB,GAAA;AACf,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI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M,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1D;;AArEM,UAAA,CAAA;AADL,IAAA,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;AAGhE,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,KAAA,EAAA,IAAA,CAAA;AAWK,UAAA,CAAA;AADL,IAAA,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;AAKhE,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,OAAA,EAAA,IAAA,CAAA;AAgBK,UAAA,CAAA;AADL,IAAA,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;AAGhE,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,QAAA,EAAA,IAAA,CAAA;AAgBK,UAAA,CAAA;AADL,IAAA,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;AAKhE,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,MAAA,EAAA,IAAA,CAAA;AAUK,UAAA,CAAA;AADL,IAAA,WAAW,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;;;AAKhE,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,MAAA,EAAA,IAAA,CAAA;;;;"}
@@ -1,19 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReactiveWebLocalStorage = void 0;
4
- const reactive_web_storage_1 = require("./reactive-web-storage");
1
+ 'use strict';
2
+
3
+ var reactiveWebStorage = require('./reactive-web-storage.cjs');
4
+
5
5
  /**
6
- * Reactive wrapper for browser localStorage.
7
- * Data persists across browser sessions.
6
+ * Reactive storage on `localStorage`: data stays until it is removed, across tabs and browser restarts.
8
7
  *
9
- * @template S - Storage store name type
8
+ * Each store is one localStorage key, `<appName>/<storeName>`, holding the store as JSON.
9
+ * Existing keys of the same app are read when the first value is requested. Store names must be
10
+ * word characters (`[A-Za-z0-9_]`): other names are saved but not read back after a reload.
11
+ *
12
+ * Changes made in other tabs, or by other instances, are not observed.
13
+ *
14
+ * Example usage:
15
+ * ```ts
16
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
17
+ *
18
+ * const storage = new ReactiveWebLocalStorage<'settings'>('my-app');
19
+ *
20
+ * storage.get<'light' | 'dark'>('settings', 'theme').subscribe((theme) => {
21
+ * document.documentElement.dataset.theme = theme ?? 'light';
22
+ * });
23
+ *
24
+ * await storage.set('settings', 'theme', 'dark'); // saved as my-app/settings = {"theme":"dark"}
25
+ * ```
26
+ *
27
+ * @template S - Store name type: a union of string literals restricts the store names you can use
10
28
  */
11
- class ReactiveWebLocalStorage extends reactive_web_storage_1.AbstractReactiveWebStorage {
29
+ class ReactiveWebLocalStorage extends reactiveWebStorage.AbstractReactiveWebStorage {
12
30
  appName;
13
31
  storage = window.localStorage;
32
+ /**
33
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
34
+ */
14
35
  constructor(appName = 'app') {
15
36
  super();
16
37
  this.appName = appName;
17
38
  }
18
39
  }
40
+
19
41
  exports.ReactiveWebLocalStorage = ReactiveWebLocalStorage;
42
+ //# sourceMappingURL=reactive-web-local-storage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-web-local-storage.cjs","sources":["../../../libs/reactive-storage/src/reactive-web-local-storage.ts"],"sourcesContent":[null],"names":["AbstractReactiveWebStorage"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,MAAO,uBAAmD,SAAQA,6CAA6B,CAAA;AAO/E,IAAA,OAAA;AANF,IAAA,OAAO,GAAG,MAAM,CAAC,YAAY;AAE/C;;AAEG;AACH,IAAA,WAAA,CACoB,UAAU,KAAK,EAAA;AAEjC,QAAA,KAAK,EAAE;QAFW,IAAA,CAAA,OAAO,GAAP,OAAO;IAG3B;AACD;;;;"}
@@ -0,0 +1,38 @@
1
+ import { AbstractReactiveWebStorage } from './reactive-web-storage.cjs';
2
+ import './reactive-storage.cjs';
3
+ import 'rxjs';
4
+
5
+ /**
6
+ * Reactive storage on `localStorage`: data stays until it is removed, across tabs and browser restarts.
7
+ *
8
+ * Each store is one localStorage key, `<appName>/<storeName>`, holding the store as JSON.
9
+ * Existing keys of the same app are read when the first value is requested. Store names must be
10
+ * word characters (`[A-Za-z0-9_]`): other names are saved but not read back after a reload.
11
+ *
12
+ * Changes made in other tabs, or by other instances, are not observed.
13
+ *
14
+ * Example usage:
15
+ * ```ts
16
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
17
+ *
18
+ * const storage = new ReactiveWebLocalStorage<'settings'>('my-app');
19
+ *
20
+ * storage.get<'light' | 'dark'>('settings', 'theme').subscribe((theme) => {
21
+ * document.documentElement.dataset.theme = theme ?? 'light';
22
+ * });
23
+ *
24
+ * await storage.set('settings', 'theme', 'dark'); // saved as my-app/settings = {"theme":"dark"}
25
+ * ```
26
+ *
27
+ * @template S - Store name type: a union of string literals restricts the store names you can use
28
+ */
29
+ declare class ReactiveWebLocalStorage<S extends string = string> extends AbstractReactiveWebStorage<S> {
30
+ readonly appName: string;
31
+ readonly storage: Storage;
32
+ /**
33
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
34
+ */
35
+ constructor(appName?: string);
36
+ }
37
+
38
+ export { ReactiveWebLocalStorage };
@@ -1,12 +1,38 @@
1
- import { AbstractReactiveWebStorage } from "./reactive-web-storage";
1
+ import { AbstractReactiveWebStorage } from './reactive-web-storage.js';
2
+ import './reactive-storage.js';
3
+ import 'rxjs';
4
+
2
5
  /**
3
- * Reactive wrapper for browser localStorage.
4
- * Data persists across browser sessions.
6
+ * Reactive storage on `localStorage`: data stays until it is removed, across tabs and browser restarts.
5
7
  *
6
- * @template S - Storage store name type
8
+ * Each store is one localStorage key, `<appName>/<storeName>`, holding the store as JSON.
9
+ * Existing keys of the same app are read when the first value is requested. Store names must be
10
+ * word characters (`[A-Za-z0-9_]`): other names are saved but not read back after a reload.
11
+ *
12
+ * Changes made in other tabs, or by other instances, are not observed.
13
+ *
14
+ * Example usage:
15
+ * ```ts
16
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
17
+ *
18
+ * const storage = new ReactiveWebLocalStorage<'settings'>('my-app');
19
+ *
20
+ * storage.get<'light' | 'dark'>('settings', 'theme').subscribe((theme) => {
21
+ * document.documentElement.dataset.theme = theme ?? 'light';
22
+ * });
23
+ *
24
+ * await storage.set('settings', 'theme', 'dark'); // saved as my-app/settings = {"theme":"dark"}
25
+ * ```
26
+ *
27
+ * @template S - Store name type: a union of string literals restricts the store names you can use
7
28
  */
8
- export declare class ReactiveWebLocalStorage<S extends string = string> extends AbstractReactiveWebStorage<S> {
29
+ declare class ReactiveWebLocalStorage<S extends string = string> extends AbstractReactiveWebStorage<S> {
9
30
  readonly appName: string;
10
31
  readonly storage: Storage;
32
+ /**
33
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
34
+ */
11
35
  constructor(appName?: string);
12
36
  }
37
+
38
+ export { ReactiveWebLocalStorage };
@@ -1,17 +1,40 @@
1
- import { AbstractReactiveWebStorage } from "./reactive-web-storage";
1
+ import { AbstractReactiveWebStorage } from './reactive-web-storage.js';
2
+
2
3
  /**
3
- * Reactive wrapper for browser localStorage.
4
- * Data persists across browser sessions.
4
+ * Reactive storage on `localStorage`: data stays until it is removed, across tabs and browser restarts.
5
+ *
6
+ * Each store is one localStorage key, `<appName>/<storeName>`, holding the store as JSON.
7
+ * Existing keys of the same app are read when the first value is requested. Store names must be
8
+ * word characters (`[A-Za-z0-9_]`): other names are saved but not read back after a reload.
9
+ *
10
+ * Changes made in other tabs, or by other instances, are not observed.
11
+ *
12
+ * Example usage:
13
+ * ```ts
14
+ * import { ReactiveWebLocalStorage } from '@telperion/reactive-storage/reactive-web-local-storage';
15
+ *
16
+ * const storage = new ReactiveWebLocalStorage<'settings'>('my-app');
17
+ *
18
+ * storage.get<'light' | 'dark'>('settings', 'theme').subscribe((theme) => {
19
+ * document.documentElement.dataset.theme = theme ?? 'light';
20
+ * });
21
+ *
22
+ * await storage.set('settings', 'theme', 'dark'); // saved as my-app/settings = {"theme":"dark"}
23
+ * ```
5
24
  *
6
- * @template S - Storage store name type
25
+ * @template S - Store name type: a union of string literals restricts the store names you can use
7
26
  */
8
- export class ReactiveWebLocalStorage extends AbstractReactiveWebStorage {
27
+ class ReactiveWebLocalStorage extends AbstractReactiveWebStorage {
9
28
  appName;
10
29
  storage = window.localStorage;
30
+ /**
31
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
32
+ */
11
33
  constructor(appName = 'app') {
12
34
  super();
13
35
  this.appName = appName;
14
36
  }
15
37
  }
16
38
 
39
+ export { ReactiveWebLocalStorage };
17
40
  //# sourceMappingURL=reactive-web-local-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/reactive-storage/src/reactive-web-local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,OAAO,uBAAmD,SAAQ,0BAA6B;IAI/E;IAHF,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC;IAEhD,YACoB,UAAU,KAAK;QAEjC,KAAK,EAAE,CAAC;QAFU,YAAO,GAAP,OAAO,CAAQ;IAGnC,CAAC;CACF","file":"reactive-web-local-storage.js","sourcesContent":["import { AbstractReactiveWebStorage } from \"./reactive-web-storage\";\n\n/**\n * Reactive wrapper for browser localStorage.\n * Data persists across browser sessions.\n *\n * @template S - Storage store name type\n */\nexport class ReactiveWebLocalStorage<S extends string = string> extends AbstractReactiveWebStorage<S> {\n override readonly storage = window.localStorage;\n\n constructor(\n override readonly appName = 'app'\n ) {\n super();\n }\n}\n"]}
1
+ {"version":3,"file":"reactive-web-local-storage.js","sources":["../../../libs/reactive-storage/src/reactive-web-local-storage.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,MAAO,uBAAmD,SAAQ,0BAA6B,CAAA;AAO/E,IAAA,OAAA;AANF,IAAA,OAAO,GAAG,MAAM,CAAC,YAAY;AAE/C;;AAEG;AACH,IAAA,WAAA,CACoB,UAAU,KAAK,EAAA;AAEjC,QAAA,KAAK,EAAE;QAFW,IAAA,CAAA,OAAO,GAAP,OAAO;IAG3B;AACD;;;;"}
@@ -1,19 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReactiveWebSessionStorage = void 0;
4
- const reactive_web_storage_1 = require("./reactive-web-storage");
1
+ 'use strict';
2
+
3
+ var reactiveWebStorage = require('./reactive-web-storage.cjs');
4
+
5
5
  /**
6
- * Reactive wrapper for browser sessionStorage.
7
- * Data is cleared when the browser tab is closed.
6
+ * Reactive storage on `sessionStorage`: data belongs to the tab and is cleared when the tab is closed.
8
7
  *
9
- * @template S - Storage store name type
8
+ * Works exactly like {@link ReactiveWebLocalStorage}, with the same `<appName>/<storeName>` keys
9
+ * and store name rules; only the underlying storage differs.
10
+ *
11
+ * Example usage:
12
+ * ```ts
13
+ * import { ReactiveWebSessionStorage } from '@telperion/reactive-storage/reactive-web-session-storage';
14
+ *
15
+ * const draft = new ReactiveWebSessionStorage('my-app');
16
+ *
17
+ * await draft.set('checkout', 'step', 2); // survives a reload, not a closed tab
18
+ * ```
19
+ *
20
+ * @template S - Store name type: a union of string literals restricts the store names you can use
10
21
  */
11
- class ReactiveWebSessionStorage extends reactive_web_storage_1.AbstractReactiveWebStorage {
22
+ class ReactiveWebSessionStorage extends reactiveWebStorage.AbstractReactiveWebStorage {
12
23
  appName;
13
24
  storage = window.sessionStorage;
25
+ /**
26
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
27
+ */
14
28
  constructor(appName = 'app') {
15
29
  super();
16
30
  this.appName = appName;
17
31
  }
18
32
  }
33
+
19
34
  exports.ReactiveWebSessionStorage = ReactiveWebSessionStorage;
35
+ //# sourceMappingURL=reactive-web-session-storage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-web-session-storage.cjs","sources":["../../../libs/reactive-storage/src/reactive-web-session-storage.ts"],"sourcesContent":[null],"names":["AbstractReactiveWebStorage"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;AAgBG;AACG,MAAO,yBAAqD,SAAQA,6CAA6B,CAAA;AAOjF,IAAA,OAAA;AANF,IAAA,OAAO,GAAG,MAAM,CAAC,cAAc;AAEjD;;AAEG;AACH,IAAA,WAAA,CACoB,UAAU,KAAK,EAAA;AAEjC,QAAA,KAAK,EAAE;QAFW,IAAA,CAAA,OAAO,GAAP,OAAO;IAG3B;AACD;;;;"}
@@ -0,0 +1,31 @@
1
+ import { AbstractReactiveWebStorage } from './reactive-web-storage.cjs';
2
+ import './reactive-storage.cjs';
3
+ import 'rxjs';
4
+
5
+ /**
6
+ * Reactive storage on `sessionStorage`: data belongs to the tab and is cleared when the tab is closed.
7
+ *
8
+ * Works exactly like {@link ReactiveWebLocalStorage}, with the same `<appName>/<storeName>` keys
9
+ * and store name rules; only the underlying storage differs.
10
+ *
11
+ * Example usage:
12
+ * ```ts
13
+ * import { ReactiveWebSessionStorage } from '@telperion/reactive-storage/reactive-web-session-storage';
14
+ *
15
+ * const draft = new ReactiveWebSessionStorage('my-app');
16
+ *
17
+ * await draft.set('checkout', 'step', 2); // survives a reload, not a closed tab
18
+ * ```
19
+ *
20
+ * @template S - Store name type: a union of string literals restricts the store names you can use
21
+ */
22
+ declare class ReactiveWebSessionStorage<S extends string = string> extends AbstractReactiveWebStorage<S> {
23
+ readonly appName: string;
24
+ readonly storage: Storage;
25
+ /**
26
+ * @param appName - Namespace of this app's keys: each store is saved under `<appName>/<storeName>`. Defaults to `'app'`
27
+ */
28
+ constructor(appName?: string);
29
+ }
30
+
31
+ export { ReactiveWebSessionStorage };