@xiboplayer/stats 0.7.0 → 0.7.2
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/package.json +2 -2
- package/src/log-reporter.js +12 -41
- package/src/stats-collector.js +12 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/stats",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Proof of play tracking, stats reporting, and CMS logging",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"./collector": "./src/stats-collector.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xiboplayer/utils": "0.7.
|
|
13
|
+
"@xiboplayer/utils": "0.7.2"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"vitest": "^2.0.0",
|
package/src/log-reporter.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @module @xiboplayer/stats/logger
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { createLogger } from '@xiboplayer/utils';
|
|
12
|
+
import { createLogger, openIDB } from '@xiboplayer/utils';
|
|
13
13
|
|
|
14
14
|
const log = createLogger('@xiboplayer/stats');
|
|
15
15
|
|
|
@@ -63,46 +63,17 @@ export class LogReporter {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
request.onerror = () => {
|
|
78
|
-
const error = new Error(`Failed to open IndexedDB: ${request.error}`);
|
|
79
|
-
log.error('Failed to open logs database:', request.error);
|
|
80
|
-
reject(error);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
request.onsuccess = () => {
|
|
84
|
-
this.db = request.result;
|
|
85
|
-
log.info('Logs database initialized');
|
|
86
|
-
resolve();
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
request.onupgradeneeded = (event) => {
|
|
90
|
-
const db = event.target.result;
|
|
91
|
-
|
|
92
|
-
// Create logs store if it doesn't exist
|
|
93
|
-
if (!db.objectStoreNames.contains(LOGS_STORE)) {
|
|
94
|
-
const store = db.createObjectStore(LOGS_STORE, {
|
|
95
|
-
keyPath: 'id',
|
|
96
|
-
autoIncrement: true
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Index on 'submitted' for fast queries
|
|
100
|
-
store.createIndex('submitted', 'submitted', { unique: false });
|
|
101
|
-
|
|
102
|
-
log.info('Logs store created');
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
});
|
|
66
|
+
try {
|
|
67
|
+
this.db = await openIDB(this._dbName, DB_VERSION, LOGS_STORE, {
|
|
68
|
+
keyPath: 'id',
|
|
69
|
+
indexName: 'submitted',
|
|
70
|
+
indexKey: 'submitted',
|
|
71
|
+
});
|
|
72
|
+
log.info('Logs database initialized');
|
|
73
|
+
} catch (err) {
|
|
74
|
+
log.error('Failed to open logs database:', err);
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
106
77
|
}
|
|
107
78
|
|
|
108
79
|
/**
|
package/src/stats-collector.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @module @xiboplayer/stats/collector
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { createLogger } from '@xiboplayer/utils';
|
|
12
|
+
import { createLogger, openIDB } from '@xiboplayer/utils';
|
|
13
13
|
|
|
14
14
|
const log = createLogger('@xiboplayer/stats');
|
|
15
15
|
|
|
@@ -64,46 +64,17 @@ export class StatsCollector {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
request.onerror = () => {
|
|
79
|
-
const error = new Error(`Failed to open IndexedDB: ${request.error}`);
|
|
80
|
-
log.error('Failed to open stats database:', request.error);
|
|
81
|
-
reject(error);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
request.onsuccess = () => {
|
|
85
|
-
this.db = request.result;
|
|
86
|
-
log.info('Stats database initialized');
|
|
87
|
-
resolve();
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
request.onupgradeneeded = (event) => {
|
|
91
|
-
const db = event.target.result;
|
|
92
|
-
|
|
93
|
-
// Create stats store if it doesn't exist
|
|
94
|
-
if (!db.objectStoreNames.contains(STATS_STORE)) {
|
|
95
|
-
const store = db.createObjectStore(STATS_STORE, {
|
|
96
|
-
keyPath: 'id',
|
|
97
|
-
autoIncrement: true
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Index on 'submitted' for fast queries
|
|
101
|
-
store.createIndex('submitted', 'submitted', { unique: false });
|
|
102
|
-
|
|
103
|
-
log.info('Stats store created');
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
});
|
|
67
|
+
try {
|
|
68
|
+
this.db = await openIDB(this._dbName, DB_VERSION, STATS_STORE, {
|
|
69
|
+
keyPath: 'id',
|
|
70
|
+
indexName: 'submitted',
|
|
71
|
+
indexKey: 'submitted',
|
|
72
|
+
});
|
|
73
|
+
log.info('Stats database initialized');
|
|
74
|
+
} catch (err) {
|
|
75
|
+
log.error('Failed to open stats database:', err);
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
107
78
|
}
|
|
108
79
|
|
|
109
80
|
/**
|