@monygroupcorp/micro-web3 0.1.3 → 1.2.1
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/CLAUDE.md +6 -0
- package/dist/{micro-web3.cjs.js → micro-web3.cjs} +3 -3
- package/dist/micro-web3.cjs.map +1 -0
- package/dist/micro-web3.esm.js +2 -2
- package/dist/micro-web3.esm.js.map +1 -1
- package/dist/micro-web3.umd.js +2 -2
- package/dist/micro-web3.umd.js.map +1 -1
- package/docs/plans/2026-01-22-event-indexer.md +3642 -0
- package/package.json +2 -2
- package/rollup.config.cjs +1 -1
- package/src/components/FloatingWalletButton/FloatingWalletButton.js +53 -21
- package/src/components/SettingsModal/SettingsModal.js +371 -0
- package/src/components/SyncProgressBar/SyncProgressBar.js +238 -0
- package/src/index.js +15 -1
- package/src/indexer/EntityResolver.js +218 -0
- package/src/indexer/Patterns.js +277 -0
- package/src/indexer/QueryEngine.js +149 -0
- package/src/indexer/SyncEngine.js +494 -0
- package/src/indexer/index.js +13 -0
- package/src/services/BlockchainService.js +30 -0
- package/src/services/ContractCache.js +20 -2
- package/src/services/EventIndexer.js +399 -0
- package/src/storage/IndexedDBAdapter.js +423 -0
- package/src/storage/IndexerSettings.js +88 -0
- package/src/storage/MemoryAdapter.js +194 -0
- package/src/storage/StorageAdapter.js +129 -0
- package/src/storage/index.js +41 -0
- package/dist/micro-web3.cjs.js.map +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/storage/StorageAdapter.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Abstract storage adapter interface for EventIndexer.
|
|
5
|
+
* Implementations must handle all async operations.
|
|
6
|
+
*/
|
|
7
|
+
class StorageAdapter {
|
|
8
|
+
/**
|
|
9
|
+
* Initialize storage with configuration.
|
|
10
|
+
* @param {Object} config - Storage configuration
|
|
11
|
+
* @param {string} config.dbName - Database name
|
|
12
|
+
* @param {number} config.version - Schema version
|
|
13
|
+
* @param {Object[]} config.eventTypes - Event types from ABI with indexed params
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
16
|
+
async initialize(config) {
|
|
17
|
+
throw new Error('StorageAdapter.initialize() must be implemented');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Store multiple events atomically.
|
|
22
|
+
* @param {IndexedEvent[]} events - Events to store
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
async putEvents(events) {
|
|
26
|
+
throw new Error('StorageAdapter.putEvents() must be implemented');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get single event by type and ID.
|
|
31
|
+
* @param {string} type - Event type name
|
|
32
|
+
* @param {string} id - Event ID (txHash-logIndex)
|
|
33
|
+
* @returns {Promise<IndexedEvent|null>}
|
|
34
|
+
*/
|
|
35
|
+
async getEvent(type, id) {
|
|
36
|
+
throw new Error('StorageAdapter.getEvent() must be implemented');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Query events with filters, sorting, pagination.
|
|
41
|
+
* @param {string} type - Event type name
|
|
42
|
+
* @param {QueryOptions} options - Query options
|
|
43
|
+
* @returns {Promise<QueryResult>}
|
|
44
|
+
*/
|
|
45
|
+
async queryEvents(type, options) {
|
|
46
|
+
throw new Error('StorageAdapter.queryEvents() must be implemented');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Count events matching filter.
|
|
51
|
+
* @param {string} type - Event type name
|
|
52
|
+
* @param {Object} where - Filter conditions
|
|
53
|
+
* @returns {Promise<number>}
|
|
54
|
+
*/
|
|
55
|
+
async countEvents(type, where) {
|
|
56
|
+
throw new Error('StorageAdapter.countEvents() must be implemented');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Delete events by IDs.
|
|
61
|
+
* @param {string} type - Event type name
|
|
62
|
+
* @param {string[]} ids - Event IDs to delete
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
|
+
*/
|
|
65
|
+
async deleteEvents(type, ids) {
|
|
66
|
+
throw new Error('StorageAdapter.deleteEvents() must be implemented');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Delete all events after a block number (for reorg recovery).
|
|
71
|
+
* @param {number} blockNumber - Delete events after this block
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
async deleteEventsAfterBlock(blockNumber) {
|
|
75
|
+
throw new Error('StorageAdapter.deleteEventsAfterBlock() must be implemented');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get sync state.
|
|
80
|
+
* @returns {Promise<SyncState|null>}
|
|
81
|
+
*/
|
|
82
|
+
async getSyncState() {
|
|
83
|
+
throw new Error('StorageAdapter.getSyncState() must be implemented');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Update sync state.
|
|
88
|
+
* @param {SyncState} state - New sync state
|
|
89
|
+
* @returns {Promise<void>}
|
|
90
|
+
*/
|
|
91
|
+
async setSyncState(state) {
|
|
92
|
+
throw new Error('StorageAdapter.setSyncState() must be implemented');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get schema version.
|
|
97
|
+
* @returns {Promise<number>}
|
|
98
|
+
*/
|
|
99
|
+
async getVersion() {
|
|
100
|
+
throw new Error('StorageAdapter.getVersion() must be implemented');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Set schema version.
|
|
105
|
+
* @param {number} version - New version
|
|
106
|
+
* @returns {Promise<void>}
|
|
107
|
+
*/
|
|
108
|
+
async setVersion(version) {
|
|
109
|
+
throw new Error('StorageAdapter.setVersion() must be implemented');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Clear all data.
|
|
114
|
+
* @returns {Promise<void>}
|
|
115
|
+
*/
|
|
116
|
+
async clear() {
|
|
117
|
+
throw new Error('StorageAdapter.clear() must be implemented');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Close connection and cleanup.
|
|
122
|
+
* @returns {Promise<void>}
|
|
123
|
+
*/
|
|
124
|
+
async close() {
|
|
125
|
+
throw new Error('StorageAdapter.close() must be implemented');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export default StorageAdapter;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/storage/index.js
|
|
2
|
+
|
|
3
|
+
import StorageAdapter from './StorageAdapter.js';
|
|
4
|
+
import IndexedDBAdapter from './IndexedDBAdapter.js';
|
|
5
|
+
import MemoryAdapter from './MemoryAdapter.js';
|
|
6
|
+
import IndexerSettings from './IndexerSettings.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Select appropriate storage adapter based on config, environment, and user settings.
|
|
10
|
+
* @param {Object} config - Persistence configuration
|
|
11
|
+
* @returns {StorageAdapter}
|
|
12
|
+
*/
|
|
13
|
+
function selectAdapter(config) {
|
|
14
|
+
// Explicit memory mode in config
|
|
15
|
+
if (config?.type === 'memory') {
|
|
16
|
+
return new MemoryAdapter();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Check user preference - if storage disabled, use memory
|
|
20
|
+
if (!IndexerSettings.isStorageEnabled()) {
|
|
21
|
+
console.log('[EventIndexer] User disabled IndexedDB storage, using memory');
|
|
22
|
+
return new MemoryAdapter();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check IndexedDB availability
|
|
26
|
+
if (typeof indexedDB !== 'undefined') {
|
|
27
|
+
return new IndexedDBAdapter();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Fallback to memory
|
|
31
|
+
console.warn('[EventIndexer] IndexedDB not available, falling back to memory storage');
|
|
32
|
+
return new MemoryAdapter();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
StorageAdapter,
|
|
37
|
+
IndexedDBAdapter,
|
|
38
|
+
MemoryAdapter,
|
|
39
|
+
IndexerSettings,
|
|
40
|
+
selectAdapter
|
|
41
|
+
};
|