@bakery-framework/plugin-analytics 2.4.1 → 2.5.0-alpha.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.
- package/package.json +2 -2
- package/src/core.ts +1 -1
- package/src/loop.ts +2 -2
- package/src/setup.ts +1 -2
- package/src/storage-sqlite.ts +2 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakery-framework/plugin-analytics",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-alpha.0",
|
|
4
4
|
"description": "Bakery analytics plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bakery",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"!src/tests"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@bakery-framework/core": "^2.
|
|
39
|
+
"@bakery-framework/core": "^2.5.0-alpha.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"bun": ">=1.4.0"
|
package/src/core.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AnalyticsSnapshot } from './types'
|
|
|
3
3
|
|
|
4
4
|
export const RETENTION_MS = 30 * 24 * 3600 * 1000
|
|
5
5
|
export const BOOT_MAX_ITEMS = 5000
|
|
6
|
-
|
|
6
|
+
const HARD_CAP = 50_000
|
|
7
7
|
|
|
8
8
|
export const history1m: AnalyticsSnapshot[] = []
|
|
9
9
|
export const history1h: AnalyticsSnapshot[] = []
|
package/src/loop.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { flushPageHits, saveAnalyticsData } from './storage-sqlite'
|
|
|
11
11
|
const SAVE_THROTTLE_MS = 60000
|
|
12
12
|
|
|
13
13
|
/** One sample per second is what every `history1m` window assumes. */
|
|
14
|
-
|
|
14
|
+
const ANALYTICS_TICK_MS = 1000
|
|
15
15
|
|
|
16
16
|
let lastSaveTime = 0
|
|
17
17
|
|
|
@@ -129,7 +129,7 @@ export function broadcastStats(compute = computeStats) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
let analyticsLoopTimer: ReturnType<typeof setTimeout> | null = null
|
|
133
133
|
|
|
134
134
|
/** False between `stopAnalyticsLoop()` and the next start; gates the re-arm. */
|
|
135
135
|
let loopRunning = false
|
package/src/setup.ts
CHANGED
|
@@ -175,8 +175,7 @@ const analyticsRoutes = routeTable({
|
|
|
175
175
|
* compile error rather than a silent widening.
|
|
176
176
|
*/
|
|
177
177
|
export type AnalyticsResponse =
|
|
178
|
-
|
|
|
179
|
-
| JsonResponseData<AnalyticsStats | undefined>
|
|
178
|
+
Response | JsonResponseData<AnalyticsStats | undefined>
|
|
180
179
|
|
|
181
180
|
export function handleAnalyticsRequest(
|
|
182
181
|
req: Request,
|
package/src/storage-sqlite.ts
CHANGED
|
@@ -59,7 +59,7 @@ function initDbInstance() {
|
|
|
59
59
|
return db
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
function initSqliteStorage() {
|
|
63
63
|
try {
|
|
64
64
|
return Promise.resolve(initDbInstance())
|
|
65
65
|
} catch (e) {
|
|
@@ -68,7 +68,7 @@ export function initSqliteStorage() {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
function getDb(): Database | null {
|
|
72
72
|
return db || null
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -102,11 +102,6 @@ export function __resetTestDb() {
|
|
|
102
102
|
resetStatements()
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export default {
|
|
106
|
-
initSqliteStorage,
|
|
107
|
-
getDb,
|
|
108
|
-
}
|
|
109
|
-
|
|
110
105
|
/**
|
|
111
106
|
* Write the page hits recorded since the last call, and nothing else.
|
|
112
107
|
*
|