@bquery/bquery 1.3.0 → 1.4.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 (71) hide show
  1. package/README.md +527 -501
  2. package/dist/{batch-4LAvfLE7.js → batch-x7b2eZST.js} +2 -2
  3. package/dist/{batch-4LAvfLE7.js.map → batch-x7b2eZST.js.map} +1 -1
  4. package/dist/component.es.mjs +1 -1
  5. package/dist/core/collection.d.ts +19 -3
  6. package/dist/core/collection.d.ts.map +1 -1
  7. package/dist/core/element.d.ts +23 -4
  8. package/dist/core/element.d.ts.map +1 -1
  9. package/dist/core/index.d.ts +1 -0
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/utils/function.d.ts +21 -4
  12. package/dist/core/utils/function.d.ts.map +1 -1
  13. package/dist/{core-COenAZjD.js → core-BhpuvPhy.js} +62 -37
  14. package/dist/core-BhpuvPhy.js.map +1 -0
  15. package/dist/core.es.mjs +174 -131
  16. package/dist/core.es.mjs.map +1 -1
  17. package/dist/full.es.mjs +7 -7
  18. package/dist/full.iife.js +2 -2
  19. package/dist/full.iife.js.map +1 -1
  20. package/dist/full.umd.js +2 -2
  21. package/dist/full.umd.js.map +1 -1
  22. package/dist/index.es.mjs +7 -7
  23. package/dist/motion.es.mjs.map +1 -1
  24. package/dist/{persisted-Dz_ryNuC.js → persisted-DHoi3uEs.js} +4 -4
  25. package/dist/{persisted-Dz_ryNuC.js.map → persisted-DHoi3uEs.js.map} +1 -1
  26. package/dist/platform/storage.d.ts.map +1 -1
  27. package/dist/platform.es.mjs +12 -7
  28. package/dist/platform.es.mjs.map +1 -1
  29. package/dist/reactive/core.d.ts +12 -0
  30. package/dist/reactive/core.d.ts.map +1 -1
  31. package/dist/reactive/effect.d.ts.map +1 -1
  32. package/dist/reactive/internals.d.ts +6 -0
  33. package/dist/reactive/internals.d.ts.map +1 -1
  34. package/dist/reactive.es.mjs +6 -6
  35. package/dist/router.es.mjs +1 -1
  36. package/dist/{sanitize-1FBEPAFH.js → sanitize-Cxvxa-DX.js} +50 -39
  37. package/dist/sanitize-Cxvxa-DX.js.map +1 -0
  38. package/dist/security/sanitize-core.d.ts.map +1 -1
  39. package/dist/security.es.mjs +2 -2
  40. package/dist/store.es.mjs +2 -2
  41. package/dist/type-guards-BdKlYYlS.js +32 -0
  42. package/dist/type-guards-BdKlYYlS.js.map +1 -0
  43. package/dist/untrack-DNnnqdlR.js +6 -0
  44. package/dist/{untrack-BuEQKH7_.js.map → untrack-DNnnqdlR.js.map} +1 -1
  45. package/dist/view/evaluate.d.ts.map +1 -1
  46. package/dist/view.es.mjs +157 -151
  47. package/dist/view.es.mjs.map +1 -1
  48. package/dist/{watch-CXyaBC_9.js → watch-DXXv3iAI.js} +3 -3
  49. package/dist/{watch-CXyaBC_9.js.map → watch-DXXv3iAI.js.map} +1 -1
  50. package/package.json +132 -132
  51. package/src/core/collection.ts +628 -588
  52. package/src/core/element.ts +774 -746
  53. package/src/core/index.ts +48 -47
  54. package/src/core/utils/function.ts +151 -110
  55. package/src/motion/animate.ts +113 -113
  56. package/src/motion/flip.ts +176 -176
  57. package/src/motion/scroll.ts +57 -57
  58. package/src/motion/spring.ts +150 -150
  59. package/src/motion/timeline.ts +246 -246
  60. package/src/motion/transition.ts +51 -51
  61. package/src/platform/storage.ts +215 -208
  62. package/src/reactive/core.ts +114 -93
  63. package/src/reactive/effect.ts +54 -43
  64. package/src/reactive/internals.ts +122 -105
  65. package/src/security/sanitize-core.ts +364 -343
  66. package/src/view/evaluate.ts +290 -274
  67. package/dist/core-COenAZjD.js.map +0 -1
  68. package/dist/sanitize-1FBEPAFH.js.map +0 -1
  69. package/dist/type-guards-DRma3-Kc.js +0 -16
  70. package/dist/type-guards-DRma3-Kc.js.map +0 -1
  71. package/dist/untrack-BuEQKH7_.js +0 -6
@@ -1,208 +1,215 @@
1
- /**
2
- * Unified storage adapters for web platform storage APIs.
3
- * Provides a consistent, promise-based interface with predictable errors.
4
- */
5
-
6
- /**
7
- * Common interface for all storage adapters.
8
- * All methods return promises for a unified async API.
9
- */
10
- export interface StorageAdapter {
11
- /**
12
- * Retrieve a value by key.
13
- * @param key - The storage key
14
- * @returns The stored value or null if not found
15
- */
16
- get<T>(key: string): Promise<T | null>;
17
-
18
- /**
19
- * Store a value by key.
20
- * @param key - The storage key
21
- * @param value - The value to store
22
- */
23
- set<T>(key: string, value: T): Promise<void>;
24
-
25
- /**
26
- * Remove a value by key.
27
- * @param key - The storage key
28
- */
29
- remove(key: string): Promise<void>;
30
-
31
- /**
32
- * Clear all stored values.
33
- */
34
- clear(): Promise<void>;
35
-
36
- /**
37
- * Get all storage keys.
38
- * @returns Array of all keys
39
- */
40
- keys(): Promise<string[]>;
41
- }
42
-
43
- /**
44
- * Abstract base class for web storage adapters (localStorage/sessionStorage).
45
- * Implements DRY principle by sharing common logic.
46
- */
47
- abstract class WebStorageAdapter implements StorageAdapter {
48
- constructor(protected readonly storage: Storage) {}
49
-
50
- async get<T>(key: string): Promise<T | null> {
51
- const raw = this.storage.getItem(key);
52
- if (raw === null) return null;
53
- try {
54
- return JSON.parse(raw) as T;
55
- } catch {
56
- return raw as unknown as T;
57
- }
58
- }
59
-
60
- async set<T>(key: string, value: T): Promise<void> {
61
- const serialized = typeof value === 'string' ? value : JSON.stringify(value);
62
- this.storage.setItem(key, serialized);
63
- }
64
-
65
- async remove(key: string): Promise<void> {
66
- this.storage.removeItem(key);
67
- }
68
-
69
- async clear(): Promise<void> {
70
- this.storage.clear();
71
- }
72
-
73
- async keys(): Promise<string[]> {
74
- return Object.keys(this.storage);
75
- }
76
- }
77
-
78
- /**
79
- * localStorage adapter with async interface.
80
- */
81
- class LocalStorageAdapter extends WebStorageAdapter {
82
- constructor() {
83
- super(localStorage);
84
- }
85
- }
86
-
87
- /**
88
- * sessionStorage adapter with async interface.
89
- */
90
- class SessionStorageAdapter extends WebStorageAdapter {
91
- constructor() {
92
- super(sessionStorage);
93
- }
94
- }
95
-
96
- /**
97
- * IndexedDB configuration options.
98
- */
99
- export interface IndexedDBOptions {
100
- /** Database name */
101
- name: string;
102
- /** Object store name */
103
- store: string;
104
- /** Database version (optional) */
105
- version?: number;
106
- }
107
-
108
- /**
109
- * IndexedDB key-value adapter.
110
- * Wraps IndexedDB with a simple key-value interface.
111
- */
112
- class IndexedDBAdapter implements StorageAdapter {
113
- private dbPromise: Promise<IDBDatabase> | null = null;
114
-
115
- constructor(private readonly options: IndexedDBOptions) {}
116
-
117
- /**
118
- * Opens or creates the IndexedDB database.
119
- */
120
- private openDB(): Promise<IDBDatabase> {
121
- if (this.dbPromise) return this.dbPromise;
122
-
123
- this.dbPromise = new Promise((resolve, reject) => {
124
- const request = indexedDB.open(this.options.name, this.options.version ?? 1);
125
-
126
- request.onupgradeneeded = () => {
127
- const db = request.result;
128
- if (!db.objectStoreNames.contains(this.options.store)) {
129
- db.createObjectStore(this.options.store);
130
- }
131
- };
132
-
133
- request.onsuccess = () => resolve(request.result);
134
- request.onerror = () => reject(request.error);
135
- });
136
-
137
- return this.dbPromise;
138
- }
139
-
140
- /**
141
- * Executes a transaction on the object store.
142
- */
143
- private async withStore<T>(
144
- mode: IDBTransactionMode,
145
- operation: (store: IDBObjectStore) => IDBRequest<T>
146
- ): Promise<T> {
147
- const db = await this.openDB();
148
- return new Promise((resolve, reject) => {
149
- const tx = db.transaction(this.options.store, mode);
150
- const store = tx.objectStore(this.options.store);
151
- const request = operation(store);
152
- request.onsuccess = () => resolve(request.result);
153
- request.onerror = () => reject(request.error);
154
- });
155
- }
156
-
157
- async get<T>(key: string): Promise<T | null> {
158
- const result = await this.withStore<T | undefined>('readonly', (store) => store.get(key));
159
- return result ?? null;
160
- }
161
-
162
- async set<T>(key: string, value: T): Promise<void> {
163
- await this.withStore('readwrite', (store) => store.put(value, key));
164
- }
165
-
166
- async remove(key: string): Promise<void> {
167
- await this.withStore('readwrite', (store) => store.delete(key));
168
- }
169
-
170
- async clear(): Promise<void> {
171
- await this.withStore('readwrite', (store) => store.clear());
172
- }
173
-
174
- async keys(): Promise<string[]> {
175
- const result = await this.withStore<IDBValidKey[]>('readonly', (store) => store.getAllKeys());
176
- return result.map((key) => String(key));
177
- }
178
- }
179
-
180
- /**
181
- * Storage factory providing access to different storage adapters.
182
- */
183
- export const storage = {
184
- /**
185
- * Create a localStorage adapter.
186
- * @returns StorageAdapter wrapping localStorage
187
- */
188
- local(): StorageAdapter {
189
- return new LocalStorageAdapter();
190
- },
191
-
192
- /**
193
- * Create a sessionStorage adapter.
194
- * @returns StorageAdapter wrapping sessionStorage
195
- */
196
- session(): StorageAdapter {
197
- return new SessionStorageAdapter();
198
- },
199
-
200
- /**
201
- * Create an IndexedDB adapter with key-value interface.
202
- * @param options - Database and store configuration
203
- * @returns StorageAdapter wrapping IndexedDB
204
- */
205
- indexedDB(options: IndexedDBOptions): StorageAdapter {
206
- return new IndexedDBAdapter(options);
207
- },
208
- };
1
+ /**
2
+ * Unified storage adapters for web platform storage APIs.
3
+ * Provides a consistent, promise-based interface with predictable errors.
4
+ */
5
+
6
+ /**
7
+ * Common interface for all storage adapters.
8
+ * All methods return promises for a unified async API.
9
+ */
10
+ export interface StorageAdapter {
11
+ /**
12
+ * Retrieve a value by key.
13
+ * @param key - The storage key
14
+ * @returns The stored value or null if not found
15
+ */
16
+ get<T>(key: string): Promise<T | null>;
17
+
18
+ /**
19
+ * Store a value by key.
20
+ * @param key - The storage key
21
+ * @param value - The value to store
22
+ */
23
+ set<T>(key: string, value: T): Promise<void>;
24
+
25
+ /**
26
+ * Remove a value by key.
27
+ * @param key - The storage key
28
+ */
29
+ remove(key: string): Promise<void>;
30
+
31
+ /**
32
+ * Clear all stored values.
33
+ */
34
+ clear(): Promise<void>;
35
+
36
+ /**
37
+ * Get all storage keys.
38
+ * @returns Array of all keys
39
+ */
40
+ keys(): Promise<string[]>;
41
+ }
42
+
43
+ /**
44
+ * Abstract base class for web storage adapters (localStorage/sessionStorage).
45
+ * Implements DRY principle by sharing common logic.
46
+ */
47
+ abstract class WebStorageAdapter implements StorageAdapter {
48
+ constructor(protected readonly storage: Storage) {}
49
+
50
+ async get<T>(key: string): Promise<T | null> {
51
+ const raw = this.storage.getItem(key);
52
+ if (raw === null) return null;
53
+ try {
54
+ return JSON.parse(raw) as T;
55
+ } catch {
56
+ return raw as unknown as T;
57
+ }
58
+ }
59
+
60
+ async set<T>(key: string, value: T): Promise<void> {
61
+ const serialized = typeof value === 'string' ? value : JSON.stringify(value);
62
+ this.storage.setItem(key, serialized);
63
+ }
64
+
65
+ async remove(key: string): Promise<void> {
66
+ this.storage.removeItem(key);
67
+ }
68
+
69
+ async clear(): Promise<void> {
70
+ this.storage.clear();
71
+ }
72
+
73
+ async keys(): Promise<string[]> {
74
+ const result: string[] = [];
75
+ for (let i = 0; i < this.storage.length; i++) {
76
+ const key = this.storage.key(i);
77
+ if (key !== null) {
78
+ result.push(key);
79
+ }
80
+ }
81
+ return result;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * localStorage adapter with async interface.
87
+ */
88
+ class LocalStorageAdapter extends WebStorageAdapter {
89
+ constructor() {
90
+ super(localStorage);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * sessionStorage adapter with async interface.
96
+ */
97
+ class SessionStorageAdapter extends WebStorageAdapter {
98
+ constructor() {
99
+ super(sessionStorage);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * IndexedDB configuration options.
105
+ */
106
+ export interface IndexedDBOptions {
107
+ /** Database name */
108
+ name: string;
109
+ /** Object store name */
110
+ store: string;
111
+ /** Database version (optional) */
112
+ version?: number;
113
+ }
114
+
115
+ /**
116
+ * IndexedDB key-value adapter.
117
+ * Wraps IndexedDB with a simple key-value interface.
118
+ */
119
+ class IndexedDBAdapter implements StorageAdapter {
120
+ private dbPromise: Promise<IDBDatabase> | null = null;
121
+
122
+ constructor(private readonly options: IndexedDBOptions) {}
123
+
124
+ /**
125
+ * Opens or creates the IndexedDB database.
126
+ */
127
+ private openDB(): Promise<IDBDatabase> {
128
+ if (this.dbPromise) return this.dbPromise;
129
+
130
+ this.dbPromise = new Promise((resolve, reject) => {
131
+ const request = indexedDB.open(this.options.name, this.options.version ?? 1);
132
+
133
+ request.onupgradeneeded = () => {
134
+ const db = request.result;
135
+ if (!db.objectStoreNames.contains(this.options.store)) {
136
+ db.createObjectStore(this.options.store);
137
+ }
138
+ };
139
+
140
+ request.onsuccess = () => resolve(request.result);
141
+ request.onerror = () => reject(request.error);
142
+ });
143
+
144
+ return this.dbPromise;
145
+ }
146
+
147
+ /**
148
+ * Executes a transaction on the object store.
149
+ */
150
+ private async withStore<T>(
151
+ mode: IDBTransactionMode,
152
+ operation: (store: IDBObjectStore) => IDBRequest<T>
153
+ ): Promise<T> {
154
+ const db = await this.openDB();
155
+ return new Promise((resolve, reject) => {
156
+ const tx = db.transaction(this.options.store, mode);
157
+ const store = tx.objectStore(this.options.store);
158
+ const request = operation(store);
159
+ request.onsuccess = () => resolve(request.result);
160
+ request.onerror = () => reject(request.error);
161
+ });
162
+ }
163
+
164
+ async get<T>(key: string): Promise<T | null> {
165
+ const result = await this.withStore<T | undefined>('readonly', (store) => store.get(key));
166
+ return result ?? null;
167
+ }
168
+
169
+ async set<T>(key: string, value: T): Promise<void> {
170
+ await this.withStore('readwrite', (store) => store.put(value, key));
171
+ }
172
+
173
+ async remove(key: string): Promise<void> {
174
+ await this.withStore('readwrite', (store) => store.delete(key));
175
+ }
176
+
177
+ async clear(): Promise<void> {
178
+ await this.withStore('readwrite', (store) => store.clear());
179
+ }
180
+
181
+ async keys(): Promise<string[]> {
182
+ const result = await this.withStore<IDBValidKey[]>('readonly', (store) => store.getAllKeys());
183
+ return result.map((key) => String(key));
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Storage factory providing access to different storage adapters.
189
+ */
190
+ export const storage = {
191
+ /**
192
+ * Create a localStorage adapter.
193
+ * @returns StorageAdapter wrapping localStorage
194
+ */
195
+ local(): StorageAdapter {
196
+ return new LocalStorageAdapter();
197
+ },
198
+
199
+ /**
200
+ * Create a sessionStorage adapter.
201
+ * @returns StorageAdapter wrapping sessionStorage
202
+ */
203
+ session(): StorageAdapter {
204
+ return new SessionStorageAdapter();
205
+ },
206
+
207
+ /**
208
+ * Create an IndexedDB adapter with key-value interface.
209
+ * @param options - Database and store configuration
210
+ * @returns StorageAdapter wrapping IndexedDB
211
+ */
212
+ indexedDB(options: IndexedDBOptions): StorageAdapter {
213
+ return new IndexedDBAdapter(options);
214
+ },
215
+ };
@@ -1,93 +1,114 @@
1
- /**
2
- * Core reactive signals.
3
- */
4
-
5
- import {
6
- getCurrentObserver,
7
- registerDependency,
8
- scheduleObserver,
9
- type ReactiveSource,
10
- } from './internals';
11
-
12
- /**
13
- * A reactive value container that notifies subscribers on change.
14
- *
15
- * Signals are the foundational primitive of the reactive system.
16
- * Reading a signal's value inside an effect or computed automatically
17
- * establishes a reactive dependency.
18
- *
19
- * @template T - The type of the stored value
20
- */
21
- export class Signal<T> implements ReactiveSource {
22
- private subscribers = new Set<() => void>();
23
-
24
- /**
25
- * Creates a new signal with an initial value.
26
- * @param _value - The initial value
27
- */
28
- constructor(private _value: T) {}
29
-
30
- /**
31
- * Gets the current value and tracks the read if inside an observer.
32
- * During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.
33
- */
34
- get value(): T {
35
- const current = getCurrentObserver();
36
- if (current) {
37
- this.subscribers.add(current);
38
- registerDependency(current, this);
39
- }
40
- return this._value;
41
- }
42
-
43
- /**
44
- * Sets a new value and notifies all subscribers if the value changed.
45
- * Uses Object.is for equality comparison.
46
- */
47
- set value(next: T) {
48
- if (Object.is(this._value, next)) return;
49
- this._value = next;
50
- // Create snapshot to avoid issues with subscribers modifying the set during iteration
51
- const subscribersSnapshot = Array.from(this.subscribers);
52
- for (const subscriber of subscribersSnapshot) {
53
- scheduleObserver(subscriber);
54
- }
55
- }
56
-
57
- /**
58
- * Reads the current value without tracking.
59
- * Useful when you need the value but don't want to create a dependency.
60
- *
61
- * @returns The current value
62
- */
63
- peek(): T {
64
- return this._value;
65
- }
66
-
67
- /**
68
- * Updates the value using a function.
69
- * Useful for updates based on the current value.
70
- *
71
- * @param updater - Function that receives current value and returns new value
72
- */
73
- update(updater: (current: T) => T): void {
74
- this.value = updater(this._value);
75
- }
76
-
77
- /**
78
- * Removes an observer from this signal's subscriber set.
79
- * @internal
80
- */
81
- unsubscribe(observer: () => void): void {
82
- this.subscribers.delete(observer);
83
- }
84
- }
85
-
86
- /**
87
- * Creates a new reactive signal.
88
- *
89
- * @template T - The type of the signal value
90
- * @param value - The initial value
91
- * @returns A new Signal instance
92
- */
93
- export const signal = <T>(value: T): Signal<T> => new Signal(value);
1
+ /**
2
+ * Core reactive signals.
3
+ */
4
+
5
+ import {
6
+ getCurrentObserver,
7
+ registerDependency,
8
+ removeDependency,
9
+ scheduleObserver,
10
+ type ReactiveSource,
11
+ } from './internals';
12
+
13
+ /**
14
+ * A reactive value container that notifies subscribers on change.
15
+ *
16
+ * Signals are the foundational primitive of the reactive system.
17
+ * Reading a signal's value inside an effect or computed automatically
18
+ * establishes a reactive dependency.
19
+ *
20
+ * @template T - The type of the stored value
21
+ */
22
+ export class Signal<T> implements ReactiveSource {
23
+ private subscribers = new Set<() => void>();
24
+
25
+ /**
26
+ * Creates a new signal with an initial value.
27
+ * @param _value - The initial value
28
+ */
29
+ constructor(private _value: T) {}
30
+
31
+ /**
32
+ * Gets the current value and tracks the read if inside an observer.
33
+ * During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.
34
+ */
35
+ get value(): T {
36
+ const current = getCurrentObserver();
37
+ if (current) {
38
+ this.subscribers.add(current);
39
+ registerDependency(current, this);
40
+ }
41
+ return this._value;
42
+ }
43
+
44
+ /**
45
+ * Sets a new value and notifies all subscribers if the value changed.
46
+ * Uses Object.is for equality comparison.
47
+ */
48
+ set value(next: T) {
49
+ if (Object.is(this._value, next)) return;
50
+ this._value = next;
51
+ // Create snapshot to avoid issues with subscribers modifying the set during iteration
52
+ const subscribersSnapshot = Array.from(this.subscribers);
53
+ for (const subscriber of subscribersSnapshot) {
54
+ scheduleObserver(subscriber);
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Reads the current value without tracking.
60
+ * Useful when you need the value but don't want to create a dependency.
61
+ *
62
+ * @returns The current value
63
+ */
64
+ peek(): T {
65
+ return this._value;
66
+ }
67
+
68
+ /**
69
+ * Updates the value using a function.
70
+ * Useful for updates based on the current value.
71
+ *
72
+ * @param updater - Function that receives current value and returns new value
73
+ */
74
+ update(updater: (current: T) => T): void {
75
+ this.value = updater(this._value);
76
+ }
77
+
78
+ /**
79
+ * Removes all subscribers from this signal.
80
+ * Use this when a signal is no longer needed to prevent memory leaks.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const count = signal(0);
85
+ * effect(() => console.log(count.value));
86
+ * count.dispose(); // All subscribers removed
87
+ * ```
88
+ */
89
+ dispose(): void {
90
+ // Remove this signal from each subscriber's dependency set
91
+ // so the observer no longer holds a strong reference to it
92
+ for (const subscriber of this.subscribers) {
93
+ removeDependency(subscriber, this);
94
+ }
95
+ this.subscribers.clear();
96
+ }
97
+
98
+ /**
99
+ * Removes an observer from this signal's subscriber set.
100
+ * @internal
101
+ */
102
+ unsubscribe(observer: () => void): void {
103
+ this.subscribers.delete(observer);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Creates a new reactive signal.
109
+ *
110
+ * @template T - The type of the signal value
111
+ * @param value - The initial value
112
+ * @returns A new Signal instance
113
+ */
114
+ export const signal = <T>(value: T): Signal<T> => new Signal(value);