@bakery-framework/plugin-analytics 2.4.2 → 2.5.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/plugin-analytics",
3
- "version": "2.4.2",
3
+ "version": "2.5.0-alpha.1",
4
4
  "description": "Bakery analytics plugin.",
5
5
  "keywords": [
6
6
  "bakery",
@@ -36,9 +36,9 @@
36
36
  "!src/tests"
37
37
  ],
38
38
  "dependencies": {
39
- "@bakery-framework/core": "^2.4.2"
39
+ "@bakery-framework/core": "^2.5.0-alpha.1"
40
40
  },
41
41
  "engines": {
42
- "bun": ">=1.4.0"
42
+ "bun": ">=1.4.4"
43
43
  }
44
44
  }
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
- export const HARD_CAP = 50_000
6
+ const HARD_CAP = 50_000
7
7
 
8
8
  export const history1m: AnalyticsSnapshot[] = []
9
9
  export const history1h: AnalyticsSnapshot[] = []
@@ -96,7 +96,7 @@ function prunePageHitsLog(now: number) {
96
96
  }
97
97
 
98
98
  let _pageHitsLogPruneTimer: ReturnType<typeof setInterval> | null = null
99
- export function ensurePageHitsLogPruner() {
99
+ function ensurePageHitsLogPruner() {
100
100
  if (_pageHitsLogPruneTimer !== null) return
101
101
  _pageHitsLogPruneTimer = setInterval(() => {
102
102
  try {
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
- export const ANALYTICS_TICK_MS = 1000
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
- export let analyticsLoopTimer: ReturnType<typeof setTimeout> | null = null
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
- | Response
179
- | JsonResponseData<AnalyticsStats | undefined>
178
+ Response | JsonResponseData<AnalyticsStats | undefined>
180
179
 
181
180
  export function handleAnalyticsRequest(
182
181
  req: Request,
@@ -59,7 +59,7 @@ function initDbInstance() {
59
59
  return db
60
60
  }
61
61
 
62
- export function initSqliteStorage() {
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
- export function getDb(): Database | null {
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
  *