@geenius/tools 0.1.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/.changeset/config.json +11 -0
- package/.env.example +2 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +16 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +11 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +10 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/ci.yml +23 -0
- package/.github/workflows/release.yml +29 -0
- package/.node-version +1 -0
- package/.nvmrc +1 -0
- package/.prettierrc +7 -0
- package/.project/ACCOUNT.yaml +4 -0
- package/.project/IDEAS.yaml +7 -0
- package/.project/PROJECT.yaml +11 -0
- package/.project/ROADMAP.yaml +15 -0
- package/CHANGELOG.md +16 -0
- package/CODE_OF_CONDUCT.md +26 -0
- package/CONTRIBUTING.md +69 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/SECURITY.md +18 -0
- package/SUPPORT.md +14 -0
- package/package.json +75 -0
- package/packages/convex/shared/README.md +1 -0
- package/packages/convex/shared/package.json +42 -0
- package/packages/convex/shared/src/audit/index.ts +5 -0
- package/packages/convex/shared/src/audit/presets.ts +165 -0
- package/packages/convex/shared/src/audit/schema.ts +85 -0
- package/packages/convex/shared/src/audit/write.ts +102 -0
- package/packages/convex/shared/src/extract.ts +75 -0
- package/packages/convex/shared/src/index.ts +41 -0
- package/packages/convex/shared/src/messages.ts +45 -0
- package/packages/convex/shared/src/security.ts +112 -0
- package/packages/convex/shared/src/throw.ts +184 -0
- package/packages/convex/shared/src/types.ts +57 -0
- package/packages/convex/shared/src/utils.ts +58 -0
- package/packages/convex/shared/tsconfig.json +28 -0
- package/packages/convex/shared/tsup.config.ts +12 -0
- package/packages/devtools/package.json +27 -0
- package/packages/devtools/react/README.md +1 -0
- package/packages/devtools/react/package.json +53 -0
- package/packages/devtools/react/src/components/DesignPreview.tsx +59 -0
- package/packages/devtools/react/src/components/DesignSwitcherDropdown.tsx +99 -0
- package/packages/devtools/react/src/components/DevSidebar.tsx +247 -0
- package/packages/devtools/react/src/components/DevToolbar.tsx +242 -0
- package/packages/devtools/react/src/components/GitHubIssueDialog.tsx +402 -0
- package/packages/devtools/react/src/components/InspectorOverlay.tsx +312 -0
- package/packages/devtools/react/src/components/PageLoadWaterfall.tsx +144 -0
- package/packages/devtools/react/src/components/PerformancePanel.tsx +330 -0
- package/packages/devtools/react/src/context/DevModeContext.tsx +226 -0
- package/packages/devtools/react/src/context/PerformanceContext.tsx +143 -0
- package/packages/devtools/react/src/data/designs.ts +13 -0
- package/packages/devtools/react/src/hooks/useGitHubLabels.ts +47 -0
- package/packages/devtools/react/src/hooks/useVirtualList.ts +124 -0
- package/packages/devtools/react/src/index.ts +77 -0
- package/packages/devtools/react/src/panels/ConvexSpy.tsx +130 -0
- package/packages/devtools/react/src/panels/DatabaseSeeder.tsx +116 -0
- package/packages/devtools/react/src/panels/DevModePhase2.tsx +191 -0
- package/packages/devtools/react/src/panels/DevModePhase3.tsx +234 -0
- package/packages/devtools/react/src/panels/FeatureFlagsToggle.tsx +104 -0
- package/packages/devtools/react/src/panels/QuickRouteJump.tsx +152 -0
- package/packages/devtools/react/src/services/github-service.ts +247 -0
- package/packages/devtools/react/tsconfig.json +31 -0
- package/packages/devtools/react/tsup.config.ts +18 -0
- package/packages/devtools/solidjs/README.md +1 -0
- package/packages/devtools/solidjs/package.json +49 -0
- package/packages/devtools/solidjs/src/components/DesignPreview.tsx +51 -0
- package/packages/devtools/solidjs/src/components/DesignSwitcherDropdown.tsx +95 -0
- package/packages/devtools/solidjs/src/components/DevSidebar.tsx +247 -0
- package/packages/devtools/solidjs/src/components/DevToolbar.tsx +242 -0
- package/packages/devtools/solidjs/src/components/GitHubIssueDialog.tsx +400 -0
- package/packages/devtools/solidjs/src/components/InspectorOverlay.tsx +311 -0
- package/packages/devtools/solidjs/src/components/PageLoadWaterfall.tsx +144 -0
- package/packages/devtools/solidjs/src/components/PerformancePanel.tsx +330 -0
- package/packages/devtools/solidjs/src/context/DevModeContext.tsx +216 -0
- package/packages/devtools/solidjs/src/context/PerformanceContext.tsx +135 -0
- package/packages/devtools/solidjs/src/data/designs.ts +13 -0
- package/packages/devtools/solidjs/src/hooks/createGitHubLabels.ts +47 -0
- package/packages/devtools/solidjs/src/index.ts +64 -0
- package/packages/devtools/solidjs/src/services/github-service.ts +247 -0
- package/packages/devtools/solidjs/tsconfig.json +21 -0
- package/packages/devtools/src/index.ts +377 -0
- package/packages/devtools/tsup.config.ts +12 -0
- package/packages/env/package.json +30 -0
- package/packages/env/src/index.ts +264 -0
- package/packages/env/tsup.config.ts +12 -0
- package/packages/errors/package.json +27 -0
- package/packages/errors/react/README.md +1 -0
- package/packages/errors/react/package.json +72 -0
- package/packages/errors/react/src/analytics.ts +16 -0
- package/packages/errors/react/src/components/ErrorBoundary.tsx +248 -0
- package/packages/errors/react/src/components/ErrorDisplay.tsx +328 -0
- package/packages/errors/react/src/components/ValidationErrors.tsx +102 -0
- package/packages/errors/react/src/config.ts +199 -0
- package/packages/errors/react/src/constants.ts +74 -0
- package/packages/errors/react/src/hooks/useErrorBoundary.ts +92 -0
- package/packages/errors/react/src/hooks/useErrorHandler.ts +87 -0
- package/packages/errors/react/src/index.ts +96 -0
- package/packages/errors/react/src/types.ts +102 -0
- package/packages/errors/react/src/utils/errorMessages.ts +35 -0
- package/packages/errors/react/src/utils/errorPolicy.ts +139 -0
- package/packages/errors/react/src/utils/extractAppError.ts +174 -0
- package/packages/errors/react/src/utils/formatError.ts +112 -0
- package/packages/errors/react/tsconfig.json +25 -0
- package/packages/errors/react/tsup.config.ts +24 -0
- package/packages/errors/solidjs/README.md +1 -0
- package/packages/errors/solidjs/package.json +46 -0
- package/packages/errors/solidjs/src/components/ErrorDisplay.tsx +179 -0
- package/packages/errors/solidjs/src/config.ts +98 -0
- package/packages/errors/solidjs/src/hooks/createErrorHandler.ts +107 -0
- package/packages/errors/solidjs/src/index.ts +61 -0
- package/packages/errors/solidjs/src/types.ts +34 -0
- package/packages/errors/solidjs/src/utils/errorPolicy.ts +56 -0
- package/packages/errors/solidjs/src/utils/extractAppError.ts +94 -0
- package/packages/errors/solidjs/src/utils/formatError.ts +33 -0
- package/packages/errors/solidjs/tsconfig.json +26 -0
- package/packages/errors/solidjs/tsup.config.ts +21 -0
- package/packages/errors/src/index.ts +320 -0
- package/packages/errors/tsup.config.ts +12 -0
- package/packages/logger/package.json +27 -0
- package/packages/logger/react/README.md +1 -0
- package/packages/logger/react/package.json +46 -0
- package/packages/logger/react/src/index.ts +4 -0
- package/packages/logger/react/src/useMetrics.ts +42 -0
- package/packages/logger/react/src/usePerformanceLog.ts +61 -0
- package/packages/logger/react/tsconfig.json +31 -0
- package/packages/logger/react/tsup.config.ts +12 -0
- package/packages/logger/solidjs/README.md +1 -0
- package/packages/logger/solidjs/package.json +45 -0
- package/packages/logger/solidjs/src/createMetrics.ts +37 -0
- package/packages/logger/solidjs/src/createPerformanceLog.ts +58 -0
- package/packages/logger/solidjs/src/index.ts +4 -0
- package/packages/logger/solidjs/tsconfig.json +32 -0
- package/packages/logger/solidjs/tsup.config.ts +12 -0
- package/packages/logger/src/index.ts +363 -0
- package/packages/logger/tsup.config.ts +12 -0
- package/packages/perf/package.json +27 -0
- package/packages/perf/react/README.md +1 -0
- package/packages/perf/react/package.json +59 -0
- package/packages/perf/react/src/components/PerformanceDashboard.tsx +257 -0
- package/packages/perf/react/src/hooks/useMonitoredQuery.ts +89 -0
- package/packages/perf/react/src/hooks/usePerformanceMetrics.ts +78 -0
- package/packages/perf/react/src/index.ts +33 -0
- package/packages/perf/react/src/services/PerformanceMonitor.ts +313 -0
- package/packages/perf/react/src/types.ts +77 -0
- package/packages/perf/react/tsconfig.json +25 -0
- package/packages/perf/react/tsup.config.ts +19 -0
- package/packages/perf/solidjs/README.md +1 -0
- package/packages/perf/solidjs/package.json +41 -0
- package/packages/perf/solidjs/src/components/PerformanceDashboard.tsx +207 -0
- package/packages/perf/solidjs/src/hooks/createPerformanceMetrics.ts +73 -0
- package/packages/perf/solidjs/src/index.ts +31 -0
- package/packages/perf/solidjs/src/services/PerformanceMonitor.ts +134 -0
- package/packages/perf/solidjs/src/types.ts +78 -0
- package/packages/perf/solidjs/tsconfig.json +26 -0
- package/packages/perf/solidjs/tsup.config.ts +14 -0
- package/packages/perf/src/index.ts +410 -0
- package/packages/perf/tsup.config.ts +12 -0
- package/pnpm-workspace.yaml +2 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @geenius-tools/perf-solidjs — src/hooks/createPerformanceMetrics.ts
|
|
2
|
+
|
|
3
|
+
import { createSignal, createEffect, onCleanup } from 'solid-js'
|
|
4
|
+
import { PerformanceMonitor } from '../services/PerformanceMonitor'
|
|
5
|
+
import type { PerformanceMetrics } from '../types'
|
|
6
|
+
|
|
7
|
+
export interface CreatePerformanceMetricsOptions {
|
|
8
|
+
timeRange?: number
|
|
9
|
+
pollingInterval?: number
|
|
10
|
+
autoRefresh?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SolidJS signal for performance metrics
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const { metrics, isLoading, refresh, clearMetrics } = createPerformanceMetrics({
|
|
18
|
+
* timeRange: 60 * 60 * 1000,
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* return <div>Score: {metrics()?.score}</div>
|
|
22
|
+
*/
|
|
23
|
+
export function createPerformanceMetrics(
|
|
24
|
+
options: CreatePerformanceMetricsOptions = {},
|
|
25
|
+
) {
|
|
26
|
+
const {
|
|
27
|
+
timeRange = 24 * 60 * 60 * 1000,
|
|
28
|
+
pollingInterval = 5000,
|
|
29
|
+
autoRefresh = true,
|
|
30
|
+
} = options
|
|
31
|
+
|
|
32
|
+
const [metrics, setMetrics] = createSignal<PerformanceMetrics | null>(null)
|
|
33
|
+
const [isLoading, setIsLoading] = createSignal(true)
|
|
34
|
+
const [error, setError] = createSignal<Error | null>(null)
|
|
35
|
+
|
|
36
|
+
const fetchMetrics = () => {
|
|
37
|
+
try {
|
|
38
|
+
const end = Date.now()
|
|
39
|
+
const start = end - timeRange
|
|
40
|
+
setMetrics(PerformanceMonitor.getMetrics({ start, end }))
|
|
41
|
+
setError(null)
|
|
42
|
+
} catch (err) {
|
|
43
|
+
setError(err instanceof Error ? err : new Error('Failed to fetch metrics'))
|
|
44
|
+
} finally {
|
|
45
|
+
setIsLoading(false)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
createEffect(() => {
|
|
50
|
+
fetchMetrics()
|
|
51
|
+
|
|
52
|
+
if (autoRefresh) {
|
|
53
|
+
const interval = setInterval(fetchMetrics, pollingInterval)
|
|
54
|
+
onCleanup(() => clearInterval(interval))
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const clearMetrics = () => {
|
|
59
|
+
PerformanceMonitor.clear()
|
|
60
|
+
fetchMetrics()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const exportMetrics = () => PerformanceMonitor.exportMetrics()
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
metrics,
|
|
67
|
+
isLoading,
|
|
68
|
+
error,
|
|
69
|
+
refresh: fetchMetrics,
|
|
70
|
+
clearMetrics,
|
|
71
|
+
exportMetrics,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @geenius-tools/perf-solidjs — src/index.ts
|
|
2
|
+
|
|
3
|
+
// ===== Types =====
|
|
4
|
+
export type {
|
|
5
|
+
CacheMetrics,
|
|
6
|
+
QueryMetrics,
|
|
7
|
+
PageLoadMetrics,
|
|
8
|
+
ErrorMetrics,
|
|
9
|
+
PerformanceMetrics,
|
|
10
|
+
PerformanceConfig,
|
|
11
|
+
CacheHitEvent,
|
|
12
|
+
CacheMissEvent,
|
|
13
|
+
} from './types'
|
|
14
|
+
|
|
15
|
+
// ===== Service =====
|
|
16
|
+
export { PerformanceMonitor } from './services/PerformanceMonitor'
|
|
17
|
+
|
|
18
|
+
// ===== Hooks =====
|
|
19
|
+
export { createPerformanceMetrics } from './hooks/createPerformanceMetrics'
|
|
20
|
+
export type { CreatePerformanceMetricsOptions } from './hooks/createPerformanceMetrics'
|
|
21
|
+
|
|
22
|
+
// ===== Components =====
|
|
23
|
+
export { PerformanceDashboard } from './components/PerformanceDashboard'
|
|
24
|
+
export type {
|
|
25
|
+
PerformanceDashboardProps,
|
|
26
|
+
PerformanceMetricsData,
|
|
27
|
+
CacheMetrics as DashboardCacheMetrics,
|
|
28
|
+
QueryMetric,
|
|
29
|
+
ErrorMetric,
|
|
30
|
+
} from './components/PerformanceDashboard'
|
|
31
|
+
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @geenius-tools/perf-solidjs — src/services/PerformanceMonitor.ts
|
|
2
|
+
// Same PerformanceMonitor service as perf-react (framework-agnostic singleton)
|
|
3
|
+
// Re-implemented here to avoid cross-package dependency
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
PerformanceMetrics,
|
|
7
|
+
PerformanceConfig,
|
|
8
|
+
CacheMetrics,
|
|
9
|
+
QueryMetrics,
|
|
10
|
+
PageLoadMetrics,
|
|
11
|
+
ErrorMetrics,
|
|
12
|
+
CacheHitEvent,
|
|
13
|
+
CacheMissEvent,
|
|
14
|
+
} from '../types'
|
|
15
|
+
|
|
16
|
+
interface QueryEntry { key: string; duration: number; timestamp: number; error?: Error; cached: boolean }
|
|
17
|
+
interface CacheEntry { type: 'hit' | 'miss'; queryKey: string; duration: number; fetchDuration?: number; timestamp: number; cacheType: 'ssr' | 'client' | 'memory' }
|
|
18
|
+
interface ErrorEntry { type: string; message: string; stack?: string; timestamp: number; source: string }
|
|
19
|
+
interface PageLoadEntry { route: string; ttfb: number; fcp: number; lcp: number; tti: number; loadTime: number; ssr: boolean; timestamp: number }
|
|
20
|
+
|
|
21
|
+
const DEFAULT_CONFIG: PerformanceConfig = {
|
|
22
|
+
enableCacheTracking: true, enableQueryTracking: true,
|
|
23
|
+
enablePageLoadTracking: true, enableErrorTracking: true,
|
|
24
|
+
sampleRate: 1, maxMetrics: 1000,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class PerformanceMonitor {
|
|
28
|
+
private static queries: QueryEntry[] = []
|
|
29
|
+
private static cacheEntries: CacheEntry[] = []
|
|
30
|
+
private static errors: ErrorEntry[] = []
|
|
31
|
+
private static pageLoads: PageLoadEntry[] = []
|
|
32
|
+
private static config: PerformanceConfig = DEFAULT_CONFIG
|
|
33
|
+
|
|
34
|
+
static configure(config: Partial<PerformanceConfig>): void {
|
|
35
|
+
PerformanceMonitor.config = { ...PerformanceMonitor.config, ...config }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static trackQuery(queryKey: string, duration: number, error?: Error, cached = false): void {
|
|
39
|
+
if (!PerformanceMonitor.config.enableQueryTracking) return
|
|
40
|
+
if (Math.random() > (PerformanceMonitor.config.sampleRate ?? 1)) return
|
|
41
|
+
PerformanceMonitor.queries.push({ key: queryKey, duration, timestamp: Date.now(), error, cached })
|
|
42
|
+
const max = PerformanceMonitor.config.maxMetrics ?? 1000
|
|
43
|
+
if (PerformanceMonitor.queries.length > max) PerformanceMonitor.queries = PerformanceMonitor.queries.slice(-max)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static trackCacheHit(event: CacheHitEvent): void {
|
|
47
|
+
if (!PerformanceMonitor.config.enableCacheTracking) return
|
|
48
|
+
PerformanceMonitor.cacheEntries.push({ type: 'hit', ...event })
|
|
49
|
+
const max = PerformanceMonitor.config.maxMetrics ?? 1000
|
|
50
|
+
if (PerformanceMonitor.cacheEntries.length > max) PerformanceMonitor.cacheEntries = PerformanceMonitor.cacheEntries.slice(-max)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static trackCacheMiss(event: CacheMissEvent): void {
|
|
54
|
+
if (!PerformanceMonitor.config.enableCacheTracking) return
|
|
55
|
+
PerformanceMonitor.cacheEntries.push({ type: 'miss', ...event })
|
|
56
|
+
const max = PerformanceMonitor.config.maxMetrics ?? 1000
|
|
57
|
+
if (PerformanceMonitor.cacheEntries.length > max) PerformanceMonitor.cacheEntries = PerformanceMonitor.cacheEntries.slice(-max)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static trackError(error: Error, source: string): void {
|
|
61
|
+
if (!PerformanceMonitor.config.enableErrorTracking) return
|
|
62
|
+
PerformanceMonitor.errors.push({ type: error.name || 'Error', message: error.message, stack: error.stack, timestamp: Date.now(), source })
|
|
63
|
+
const max = PerformanceMonitor.config.maxMetrics ?? 1000
|
|
64
|
+
if (PerformanceMonitor.errors.length > max) PerformanceMonitor.errors = PerformanceMonitor.errors.slice(-max)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static trackPageLoad(metrics: Omit<PageLoadEntry, 'timestamp'>): void {
|
|
68
|
+
if (!PerformanceMonitor.config.enablePageLoadTracking) return
|
|
69
|
+
PerformanceMonitor.pageLoads.push({ ...metrics, timestamp: Date.now() })
|
|
70
|
+
const max = PerformanceMonitor.config.maxMetrics ?? 1000
|
|
71
|
+
if (PerformanceMonitor.pageLoads.length > max) PerformanceMonitor.pageLoads = PerformanceMonitor.pageLoads.slice(-max)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static getMetrics(timeRange: { start: number; end: number }): PerformanceMetrics {
|
|
75
|
+
const { start, end } = timeRange
|
|
76
|
+
const rq = PerformanceMonitor.queries.filter(q => q.timestamp >= start && q.timestamp <= end)
|
|
77
|
+
const rc = PerformanceMonitor.cacheEntries.filter(c => c.timestamp >= start && c.timestamp <= end)
|
|
78
|
+
const re = PerformanceMonitor.errors.filter(e => e.timestamp >= start && e.timestamp <= end)
|
|
79
|
+
const rp = PerformanceMonitor.pageLoads.filter(p => p.timestamp >= start && p.timestamp <= end)
|
|
80
|
+
|
|
81
|
+
const hits = rc.filter(c => c.type === 'hit')
|
|
82
|
+
const misses = rc.filter(c => c.type === 'miss')
|
|
83
|
+
const total = hits.length + misses.length
|
|
84
|
+
|
|
85
|
+
const cache: CacheMetrics = {
|
|
86
|
+
totalRequests: total, hits: hits.length, misses: misses.length,
|
|
87
|
+
hitRate: total > 0 ? (hits.length / total) * 100 : 0,
|
|
88
|
+
avgHitTime: hits.length > 0 ? hits.reduce((s, h) => s + h.duration, 0) / hits.length : 0,
|
|
89
|
+
avgMissTime: misses.length > 0 ? misses.reduce((s, m) => s + (m.fetchDuration ?? m.duration), 0) / misses.length : 0,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const qMap = new Map<string, QueryEntry[]>()
|
|
93
|
+
for (const q of rq) { const arr = qMap.get(q.key) || []; arr.push(q); qMap.set(q.key, arr) }
|
|
94
|
+
|
|
95
|
+
const queries: QueryMetrics[] = Array.from(qMap.entries()).map(([key, entries]) => {
|
|
96
|
+
const d = entries.map(e => e.duration)
|
|
97
|
+
return {
|
|
98
|
+
queryKey: key, executions: entries.length,
|
|
99
|
+
avgDuration: d.reduce((s, v) => s + v, 0) / d.length,
|
|
100
|
+
minDuration: Math.min(...d), maxDuration: Math.max(...d),
|
|
101
|
+
errors: entries.filter(e => e.error).length,
|
|
102
|
+
lastExecuted: Math.max(...entries.map(e => e.timestamp)),
|
|
103
|
+
cached: entries.some(e => e.cached),
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const eMap = new Map<string, ErrorEntry[]>()
|
|
108
|
+
for (const e of re) { const k = `${e.type}:${e.message}`; const a = eMap.get(k) || []; a.push(e); eMap.set(k, a) }
|
|
109
|
+
|
|
110
|
+
const errors: ErrorMetrics[] = Array.from(eMap.entries()).map(([, entries]) => ({
|
|
111
|
+
type: entries[0].type, message: entries[0].message, stack: entries[0].stack,
|
|
112
|
+
count: entries.length, firstSeen: Math.min(...entries.map(e => e.timestamp)),
|
|
113
|
+
lastSeen: Math.max(...entries.map(e => e.timestamp)), affectedUsers: 1,
|
|
114
|
+
}))
|
|
115
|
+
|
|
116
|
+
const pageLoads: PageLoadMetrics[] = rp
|
|
117
|
+
let score = 100
|
|
118
|
+
if (cache.hitRate < 80) score -= 20
|
|
119
|
+
if (queries.some(q => q.avgDuration > 1000)) score -= 15
|
|
120
|
+
if (errors.length > 0) score -= Math.min(errors.length * 5, 30)
|
|
121
|
+
if (pageLoads.some(p => p.lcp > 2500)) score -= 15
|
|
122
|
+
|
|
123
|
+
return { cache, queries, pageLoads, errors, score: Math.max(0, score), timeRange: { start, end } }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static clear(): void {
|
|
127
|
+
PerformanceMonitor.queries = []; PerformanceMonitor.cacheEntries = []; PerformanceMonitor.errors = []; PerformanceMonitor.pageLoads = []
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static exportMetrics(): string {
|
|
131
|
+
const end = Date.now()
|
|
132
|
+
return JSON.stringify(PerformanceMonitor.getMetrics({ start: end - 86400000, end }), null, 2)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @geenius-tools/perf-solidjs — src/types.ts
|
|
2
|
+
// Self-contained perf types (same as perf-react)
|
|
3
|
+
|
|
4
|
+
export interface CacheMetrics {
|
|
5
|
+
totalRequests: number
|
|
6
|
+
hits: number
|
|
7
|
+
misses: number
|
|
8
|
+
hitRate: number
|
|
9
|
+
avgHitTime: number
|
|
10
|
+
avgMissTime: number
|
|
11
|
+
cacheSize?: number
|
|
12
|
+
evictions?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface QueryMetrics {
|
|
16
|
+
queryKey: string
|
|
17
|
+
executions: number
|
|
18
|
+
avgDuration: number
|
|
19
|
+
minDuration: number
|
|
20
|
+
maxDuration: number
|
|
21
|
+
errors: number
|
|
22
|
+
lastExecuted: number
|
|
23
|
+
cached: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PageLoadMetrics {
|
|
27
|
+
route: string
|
|
28
|
+
ttfb: number
|
|
29
|
+
fcp: number
|
|
30
|
+
lcp: number
|
|
31
|
+
tti: number
|
|
32
|
+
loadTime: number
|
|
33
|
+
ssr: boolean
|
|
34
|
+
timestamp: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ErrorMetrics {
|
|
38
|
+
type: string
|
|
39
|
+
message: string
|
|
40
|
+
stack?: string
|
|
41
|
+
count: number
|
|
42
|
+
firstSeen: number
|
|
43
|
+
lastSeen: number
|
|
44
|
+
affectedUsers: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PerformanceMetrics {
|
|
48
|
+
cache: CacheMetrics
|
|
49
|
+
queries: QueryMetrics[]
|
|
50
|
+
pageLoads: PageLoadMetrics[]
|
|
51
|
+
errors: ErrorMetrics[]
|
|
52
|
+
score: number
|
|
53
|
+
timeRange: { start: number; end: number }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface PerformanceConfig {
|
|
57
|
+
enableCacheTracking?: boolean
|
|
58
|
+
enableQueryTracking?: boolean
|
|
59
|
+
enablePageLoadTracking?: boolean
|
|
60
|
+
enableErrorTracking?: boolean
|
|
61
|
+
sampleRate?: number
|
|
62
|
+
maxMetrics?: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CacheHitEvent {
|
|
66
|
+
queryKey: string
|
|
67
|
+
duration: number
|
|
68
|
+
timestamp: number
|
|
69
|
+
cacheType: 'ssr' | 'client' | 'memory'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface CacheMissEvent {
|
|
73
|
+
queryKey: string
|
|
74
|
+
duration: number
|
|
75
|
+
timestamp: number
|
|
76
|
+
cacheType: 'ssr' | 'client' | 'memory'
|
|
77
|
+
fetchDuration: number
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "preserve",
|
|
7
|
+
"jsxImportSource": "solid-js",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "./dist",
|
|
14
|
+
"outDir": "./dist",
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"exclude": [
|
|
23
|
+
"node_modules",
|
|
24
|
+
"dist"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: { index: 'src/index.ts' },
|
|
5
|
+
format: ['esm'],
|
|
6
|
+
dts: true,
|
|
7
|
+
clean: true,
|
|
8
|
+
outDir: 'dist',
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
external: ['solid-js', 'solid-js/web', 'solid-js/store'],
|
|
11
|
+
esbuildOptions(options) {
|
|
12
|
+
options.jsx = 'preserve'
|
|
13
|
+
},
|
|
14
|
+
})
|