vite-plugin-smart-prefetch 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/README.md +605 -0
- package/dist/index.cjs +1783 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +211 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.js +1746 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +798 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +175 -0
- package/dist/react/index.d.ts +175 -0
- package/dist/react/index.js +758 -0
- package/dist/react/index.js.map +1 -0
- package/dist/runtime/index.cjs +678 -0
- package/dist/runtime/index.cjs.map +1 -0
- package/dist/runtime/index.d.cts +223 -0
- package/dist/runtime/index.d.ts +223 -0
- package/dist/runtime/index.js +645 -0
- package/dist/runtime/index.js.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core type definitions for @farmart/vite-plugin-smart-prefetch
|
|
5
|
+
*/
|
|
6
|
+
interface PluginOptions {
|
|
7
|
+
/** Framework to use (currently only 'react' is supported) */
|
|
8
|
+
framework?: 'react' | 'vue' | 'svelte';
|
|
9
|
+
/** Prefetch strategy */
|
|
10
|
+
strategy?: PrefetchStrategy;
|
|
11
|
+
/** Google Analytics integration configuration */
|
|
12
|
+
analytics?: AnalyticsConfig;
|
|
13
|
+
/** Manual route prefetch rules (overrides ML predictions) */
|
|
14
|
+
manualRules?: ManualRules;
|
|
15
|
+
/** Cache configuration */
|
|
16
|
+
cache?: CacheConfig;
|
|
17
|
+
/** Advanced configuration options */
|
|
18
|
+
advanced?: AdvancedConfig;
|
|
19
|
+
}
|
|
20
|
+
type PrefetchStrategy = 'auto' | 'hover' | 'visible' | 'idle' | 'hybrid';
|
|
21
|
+
interface AnalyticsConfig {
|
|
22
|
+
/** Analytics provider - only BigQuery is supported */
|
|
23
|
+
provider: 'bigquery';
|
|
24
|
+
/** BigQuery authentication credentials */
|
|
25
|
+
credentials: BigQueryCredentials;
|
|
26
|
+
/** Data collection settings */
|
|
27
|
+
dataRange?: DataRangeConfig;
|
|
28
|
+
/** Model training configuration */
|
|
29
|
+
model: ModelConfig;
|
|
30
|
+
/** Environment identifier */
|
|
31
|
+
environment: string;
|
|
32
|
+
/** Generate analytics dashboard HTML */
|
|
33
|
+
dashboard?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface BigQueryCredentials {
|
|
36
|
+
/** Google Cloud Project ID */
|
|
37
|
+
projectId: string;
|
|
38
|
+
/** BigQuery dataset ID (usually analytics_XXXXXXXX) */
|
|
39
|
+
datasetId: string;
|
|
40
|
+
}
|
|
41
|
+
interface DataRangeConfig {
|
|
42
|
+
/** Number of days to analyze (default: 30) */
|
|
43
|
+
days?: number;
|
|
44
|
+
/** Minimum sessions required for route to be included (default: 100) */
|
|
45
|
+
minSessions?: number;
|
|
46
|
+
}
|
|
47
|
+
interface ModelConfig {
|
|
48
|
+
/** Model type */
|
|
49
|
+
type: 'probability' | 'ml' | 'hybrid';
|
|
50
|
+
/** Minimum probability threshold (0.0 - 1.0, default: 0.3) */
|
|
51
|
+
threshold: number;
|
|
52
|
+
/** Maximum routes to prefetch per page (default: 3) */
|
|
53
|
+
maxPrefetch: number;
|
|
54
|
+
/** How often to update the model */
|
|
55
|
+
updateInterval?: 'build' | 'daily' | 'weekly';
|
|
56
|
+
}
|
|
57
|
+
interface ManualRules {
|
|
58
|
+
/** Map of source route to target routes to prefetch */
|
|
59
|
+
[sourceRoute: string]: string[];
|
|
60
|
+
}
|
|
61
|
+
interface CacheConfig {
|
|
62
|
+
/** Enable caching (default: true) */
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
/** Time-to-live in milliseconds (default: 24h) */
|
|
65
|
+
ttl?: number;
|
|
66
|
+
/** Cache directory path (default: node_modules/.cache/smart-prefetch) */
|
|
67
|
+
path?: string;
|
|
68
|
+
}
|
|
69
|
+
interface AdvancedConfig {
|
|
70
|
+
/** Custom route normalization function */
|
|
71
|
+
routeNormalization?: (path: string) => string;
|
|
72
|
+
/** Custom chunk matching function */
|
|
73
|
+
chunkMatching?: (route: string, manifest: ViteManifest) => string | null;
|
|
74
|
+
/** Routes to exclude from prefetching */
|
|
75
|
+
excludeRoutes?: string[];
|
|
76
|
+
/** Enable debug logging */
|
|
77
|
+
debug?: boolean;
|
|
78
|
+
}
|
|
79
|
+
interface NavigationData {
|
|
80
|
+
/** Source route */
|
|
81
|
+
from: string;
|
|
82
|
+
/** Destination route */
|
|
83
|
+
to: string;
|
|
84
|
+
/** Number of transitions observed */
|
|
85
|
+
count: number;
|
|
86
|
+
}
|
|
87
|
+
interface PrefetchModel {
|
|
88
|
+
/** Schema version */
|
|
89
|
+
version: string;
|
|
90
|
+
/** Timestamp when model was generated */
|
|
91
|
+
generatedAt: string;
|
|
92
|
+
/** Environment this model is for */
|
|
93
|
+
environment: string;
|
|
94
|
+
/** Data source metadata */
|
|
95
|
+
dataSource?: DataSourceMetadata;
|
|
96
|
+
/** Model configuration used */
|
|
97
|
+
config?: ModelConfig;
|
|
98
|
+
/** Route predictions */
|
|
99
|
+
routes: {
|
|
100
|
+
[sourceRoute: string]: RoutePrediction;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface DataSourceMetadata {
|
|
104
|
+
/** Provider name */
|
|
105
|
+
provider: 'bigquery' | 'markov-chain' | 'manual' | string;
|
|
106
|
+
/** Date range analyzed */
|
|
107
|
+
dateRange: string;
|
|
108
|
+
/** Total sessions analyzed */
|
|
109
|
+
totalSessions: number;
|
|
110
|
+
/** Total unique routes found */
|
|
111
|
+
totalRoutes?: number;
|
|
112
|
+
}
|
|
113
|
+
interface RoutePrediction {
|
|
114
|
+
/** Routes to prefetch from this source (default/common rules) */
|
|
115
|
+
prefetch: PrefetchTarget[];
|
|
116
|
+
/** Segment-specific prefetch rules */
|
|
117
|
+
segments?: SegmentPrefetchRules;
|
|
118
|
+
/** Additional metadata about this route */
|
|
119
|
+
metadata?: RouteMetadata;
|
|
120
|
+
}
|
|
121
|
+
interface SegmentPrefetchRules {
|
|
122
|
+
/** Prefetch rules by user segment (free, premium, enterprise, etc.) */
|
|
123
|
+
[segmentName: string]: PrefetchTarget[];
|
|
124
|
+
}
|
|
125
|
+
interface PrefetchTarget {
|
|
126
|
+
/** Target route to prefetch */
|
|
127
|
+
route: string;
|
|
128
|
+
/** Probability of transition (0.0 - 1.0) */
|
|
129
|
+
probability: number;
|
|
130
|
+
/** Number of observed transitions */
|
|
131
|
+
count: number;
|
|
132
|
+
/** Chunk file to prefetch (set by config generator) */
|
|
133
|
+
chunk?: string;
|
|
134
|
+
/** Dependency chunks to prefetch (extracted from Vite manifest imports) */
|
|
135
|
+
imports?: string[];
|
|
136
|
+
/** Priority level */
|
|
137
|
+
priority: 'high' | 'medium' | 'low';
|
|
138
|
+
/** Whether this is a manual rule */
|
|
139
|
+
manual?: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface RouteMetadata {
|
|
142
|
+
/** Total transitions from this route */
|
|
143
|
+
totalTransitions: number;
|
|
144
|
+
/** Most common destination */
|
|
145
|
+
topDestination: string;
|
|
146
|
+
/** Average time spent on page (seconds) */
|
|
147
|
+
averageTimeOnPage?: number;
|
|
148
|
+
}
|
|
149
|
+
interface PrefetchConfig {
|
|
150
|
+
/** Schema version */
|
|
151
|
+
version: string;
|
|
152
|
+
/** Generation timestamp */
|
|
153
|
+
generatedAt: string;
|
|
154
|
+
/** Environment */
|
|
155
|
+
environment: string;
|
|
156
|
+
/** Data source info */
|
|
157
|
+
dataSource: DataSourceMetadata;
|
|
158
|
+
/** Model info */
|
|
159
|
+
model: {
|
|
160
|
+
type: ModelConfig['type'];
|
|
161
|
+
threshold: number;
|
|
162
|
+
maxPrefetch: number;
|
|
163
|
+
accuracy?: number;
|
|
164
|
+
};
|
|
165
|
+
/** Route predictions with chunk mappings */
|
|
166
|
+
routes: {
|
|
167
|
+
[sourceRoute: string]: {
|
|
168
|
+
/** Default/common prefetch rules (works for all users) */
|
|
169
|
+
prefetch: Array<PrefetchTarget & {
|
|
170
|
+
chunk: string;
|
|
171
|
+
}>;
|
|
172
|
+
/** Segment-specific rules (different per user segment) */
|
|
173
|
+
segments?: {
|
|
174
|
+
[segmentName: string]: Array<PrefetchTarget & {
|
|
175
|
+
chunk: string;
|
|
176
|
+
}>;
|
|
177
|
+
};
|
|
178
|
+
/** Metadata about this route */
|
|
179
|
+
metadata?: RouteMetadata;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** Quick lookup: route -> chunk file */
|
|
183
|
+
chunks: {
|
|
184
|
+
[route: string]: string;
|
|
185
|
+
};
|
|
186
|
+
/** Available segments (for client-side selection) */
|
|
187
|
+
segmentInfo?: {
|
|
188
|
+
available: string[];
|
|
189
|
+
description?: string;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
interface ViteManifest {
|
|
193
|
+
[key: string]: {
|
|
194
|
+
file: string;
|
|
195
|
+
src?: string;
|
|
196
|
+
isEntry?: boolean;
|
|
197
|
+
imports?: string[];
|
|
198
|
+
dynamicImports?: string[];
|
|
199
|
+
css?: string[];
|
|
200
|
+
assets?: string[];
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Main Vite Plugin
|
|
206
|
+
* Integrates all components and provides Vite hooks
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
declare function smartPrefetch(options?: PluginOptions): Plugin;
|
|
210
|
+
|
|
211
|
+
export { type AdvancedConfig, type AnalyticsConfig, type BigQueryCredentials, type CacheConfig, type DataRangeConfig, type ManualRules, type ModelConfig, type NavigationData, type PluginOptions, type PrefetchConfig, type PrefetchModel, type PrefetchStrategy, type PrefetchTarget, type ViteManifest, smartPrefetch };
|