@feltdb/core 0.2.0 → 0.3.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/LICENSE +19 -0
- package/dist/analytics-backend.d.ts +39 -0
- package/dist/analytics-backend.d.ts.map +1 -0
- package/dist/analytics-backend.js +152 -0
- package/dist/application-contract.d.ts +49 -0
- package/dist/application-contract.d.ts.map +1 -0
- package/dist/application-contract.js +13 -0
- package/dist/application-manifest.d.ts +305 -0
- package/dist/application-manifest.d.ts.map +1 -0
- package/dist/application-manifest.js +26 -0
- package/dist/artifact.d.ts +73 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +21 -0
- package/dist/authorization.d.ts +99 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/authorization.js +15 -0
- package/dist/bundle.d.ts +55 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +13 -0
- package/dist/collection.d.ts +28 -0
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +83 -0
- package/dist/db.d.ts +18 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +20 -8
- package/dist/distributed-indexing.d.ts +170 -0
- package/dist/distributed-indexing.d.ts.map +1 -0
- package/dist/distributed-indexing.js +260 -0
- package/dist/flowspec.d.ts +4 -0
- package/dist/flowspec.d.ts.map +1 -1
- package/dist/flowspec.js +8 -0
- package/dist/http-client.d.ts +35 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +70 -0
- package/dist/identity.d.ts +40 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +10 -0
- package/dist/index-analytics.d.ts +121 -0
- package/dist/index-analytics.d.ts.map +1 -0
- package/dist/index-analytics.js +279 -0
- package/dist/index-backend.d.ts +26 -0
- package/dist/index-backend.d.ts.map +1 -0
- package/dist/index-backend.js +115 -0
- package/dist/index-dashboard.d.ts +114 -0
- package/dist/index-dashboard.d.ts.map +1 -0
- package/dist/index-dashboard.js +256 -0
- package/dist/index-manager.d.ts +18 -0
- package/dist/index-manager.d.ts.map +1 -0
- package/dist/index-manager.js +333 -0
- package/dist/index-monitoring.d.ts +133 -0
- package/dist/index-monitoring.d.ts.map +1 -0
- package/dist/index-monitoring.js +218 -0
- package/dist/index-recovery.d.ts +57 -0
- package/dist/index-recovery.d.ts.map +1 -0
- package/dist/index-recovery.js +117 -0
- package/dist/index-store.d.ts +62 -0
- package/dist/index-store.d.ts.map +1 -0
- package/dist/index-store.js +141 -0
- package/dist/index-types.d.ts +70 -0
- package/dist/index-types.d.ts.map +1 -0
- package/dist/index-types.js +6 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/observe.d.ts +51 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.js +14 -0
- package/dist/protocol.d.ts +25 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +18 -0
- package/dist/provider.d.ts +61 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +17 -0
- package/dist/query-planner.d.ts +69 -0
- package/dist/query-planner.d.ts.map +1 -0
- package/dist/query-planner.js +184 -0
- package/dist/release.d.ts +60 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +18 -0
- package/dist/sharding.d.ts +159 -0
- package/dist/sharding.d.ts.map +1 -0
- package/dist/sharding.js +317 -0
- package/dist/state-contract.d.ts +173 -0
- package/dist/state-contract.d.ts.map +1 -0
- package/dist/state-contract.js +24 -0
- package/dist/sync-contract.d.ts +101 -0
- package/dist/sync-contract.d.ts.map +1 -0
- package/dist/sync-contract.js +90 -0
- package/dist/worker.d.ts +90 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +26 -0
- package/dist/workload.d.ts +102 -0
- package/dist/workload.d.ts.map +1 -0
- package/dist/workload.js +23 -0
- package/package.json +17 -5
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Monitoring System - Unified monitoring API
|
|
3
|
+
*
|
|
4
|
+
* Combines analytics, dashboards, and alerts into a single monitoring interface.
|
|
5
|
+
*/
|
|
6
|
+
import { type PerformanceReport } from './index-analytics.js';
|
|
7
|
+
import { type DashboardMetrics } from './index-dashboard.js';
|
|
8
|
+
export interface MonitoringConfig {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
collectTraces: boolean;
|
|
11
|
+
traceLimit: number;
|
|
12
|
+
reportPeriod: 'hourly' | 'daily' | 'weekly';
|
|
13
|
+
autoTuning: boolean;
|
|
14
|
+
alerting: boolean;
|
|
15
|
+
dashboardRefreshMs: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Index Monitoring System - Unified API for observability.
|
|
19
|
+
* Uses Rust-backed analytics when available, with TypeScript fallback.
|
|
20
|
+
*/
|
|
21
|
+
export declare class IndexMonitor {
|
|
22
|
+
private analyticsBackend;
|
|
23
|
+
private analytics;
|
|
24
|
+
private autoTuner;
|
|
25
|
+
private dashboard;
|
|
26
|
+
private alerter;
|
|
27
|
+
private config;
|
|
28
|
+
private collectionName;
|
|
29
|
+
constructor(collectionName: string, config?: Partial<MonitoringConfig>);
|
|
30
|
+
/**
|
|
31
|
+
* Record query execution.
|
|
32
|
+
*/
|
|
33
|
+
recordQuery(fields: string[], operator: string, executionTimeMs: number, rowsScanned: number, resultCount: number, indexUsed?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Record index operation.
|
|
36
|
+
*/
|
|
37
|
+
recordIndexOperation(indexName: string, operation: 'read' | 'write', timeMs: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get current performance report.
|
|
40
|
+
*/
|
|
41
|
+
getReport(): PerformanceReport;
|
|
42
|
+
/**
|
|
43
|
+
* Get formatted dashboard.
|
|
44
|
+
*/
|
|
45
|
+
getDashboard(): DashboardMetrics;
|
|
46
|
+
/**
|
|
47
|
+
* Get ASCII rendering of dashboard.
|
|
48
|
+
*/
|
|
49
|
+
renderDashboard(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Get tuning recommendations.
|
|
52
|
+
*/
|
|
53
|
+
getRecommendations(): import("./index-analytics.js").TuningRecommendation[];
|
|
54
|
+
/**
|
|
55
|
+
* Get auto-applicable recommendations.
|
|
56
|
+
*/
|
|
57
|
+
getAutoApplyRecommendations(): import("./index-analytics.js").TuningRecommendation[];
|
|
58
|
+
/**
|
|
59
|
+
* Get performance alerts.
|
|
60
|
+
*/
|
|
61
|
+
getAlerts(): import("./index-dashboard.js").PerformanceAlert[];
|
|
62
|
+
/**
|
|
63
|
+
* Get slowest queries.
|
|
64
|
+
*/
|
|
65
|
+
getSlowestQueries(limit?: number): import("./index-analytics.js").QueryTrace[];
|
|
66
|
+
/**
|
|
67
|
+
* Get most frequently queried fields.
|
|
68
|
+
*/
|
|
69
|
+
getFrequentFields(limit?: number): [string, number][];
|
|
70
|
+
/**
|
|
71
|
+
* Start live dashboard updates.
|
|
72
|
+
*/
|
|
73
|
+
startLiveDashboard(callback: (metrics: DashboardMetrics) => void): () => void;
|
|
74
|
+
/**
|
|
75
|
+
* Stop live dashboard updates.
|
|
76
|
+
*/
|
|
77
|
+
stopLiveDashboard(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Reset all metrics.
|
|
80
|
+
*/
|
|
81
|
+
reset(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Update monitoring configuration.
|
|
84
|
+
*/
|
|
85
|
+
updateConfig(config: Partial<MonitoringConfig>): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Global monitoring registry for multiple collections.
|
|
89
|
+
*/
|
|
90
|
+
export declare class MonitoringRegistry {
|
|
91
|
+
private monitors;
|
|
92
|
+
private defaultConfig;
|
|
93
|
+
/**
|
|
94
|
+
* Register a collection monitor.
|
|
95
|
+
*/
|
|
96
|
+
register(collectionName: string, config?: Partial<MonitoringConfig>): IndexMonitor;
|
|
97
|
+
/**
|
|
98
|
+
* Get monitor for collection.
|
|
99
|
+
*/
|
|
100
|
+
get(collectionName: string): IndexMonitor | null;
|
|
101
|
+
/**
|
|
102
|
+
* Get all monitors.
|
|
103
|
+
*/
|
|
104
|
+
getAll(): IndexMonitor[];
|
|
105
|
+
/**
|
|
106
|
+
* Generate combined report for all collections.
|
|
107
|
+
*/
|
|
108
|
+
generateGlobalReport(): {
|
|
109
|
+
timestamp: number;
|
|
110
|
+
collections: number;
|
|
111
|
+
totalQueries: number;
|
|
112
|
+
indexUsageRate: number;
|
|
113
|
+
reports: PerformanceReport[];
|
|
114
|
+
overallHealth: string;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Get critical alerts across all collections.
|
|
118
|
+
*/
|
|
119
|
+
getCriticalAlerts(): import("./index-dashboard.js").PerformanceAlert[];
|
|
120
|
+
/**
|
|
121
|
+
* Set default configuration for new monitors.
|
|
122
|
+
*/
|
|
123
|
+
setDefaultConfig(config: Partial<MonitoringConfig>): void;
|
|
124
|
+
/**
|
|
125
|
+
* Reset all monitors.
|
|
126
|
+
*/
|
|
127
|
+
resetAll(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Integration hook for Collection class.
|
|
131
|
+
*/
|
|
132
|
+
export declare function createMonitoringIntegration(collectionName: string): (monitor: IndexMonitor) => void;
|
|
133
|
+
//# sourceMappingURL=index-monitoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-monitoring.d.ts","sourceRoot":"","sources":["../src/index-monitoring.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAyD,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEpH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC5C,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,cAAc,CAAS;gBAEnB,cAAc,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM;IAsB1E;;OAEG;IACH,WAAW,CACT,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI;IAQP;;OAEG;IACH,oBAAoB,CAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,OAAO,EAC3B,MAAM,EAAE,MAAM,GACb,IAAI;IAQP;;OAEG;IACH,SAAS,IAAI,iBAAiB;IAI9B;;OAEG;IACH,YAAY,IAAI,gBAAgB;IAKhC;;OAEG;IACH,eAAe,IAAI,MAAM;IAKzB;;OAEG;IACH,kBAAkB;IAKlB;;OAEG;IACH,2BAA2B;IAK3B;;OAEG;IACH,SAAS;IAOT;;OAEG;IACH,iBAAiB,CAAC,KAAK,SAAK;IAI5B;;OAEG;IACH,iBAAiB,CAAC,KAAK,SAAK;IAI5B;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI;IAK7E;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAGtD;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,aAAa,CAAiC;IAEtD;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,YAAY;IAWlF;;OAEG;IACH,GAAG,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAIhD;;OAEG;IACH,MAAM,IAAI,YAAY,EAAE;IAIxB;;OAEG;IACH,oBAAoB;;;;;;;;IAepB;;OAEG;IACH,iBAAiB;IAQjB;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAIzD;;OAEG;IACH,QAAQ,IAAI,IAAI;CAKjB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,cAAc,EAAE,MAAM,GAAG,CACnE,OAAO,EAAE,YAAY,KAClB,IAAI,CAQR"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Monitoring System - Unified monitoring API
|
|
3
|
+
*
|
|
4
|
+
* Combines analytics, dashboards, and alerts into a single monitoring interface.
|
|
5
|
+
*/
|
|
6
|
+
import { IndexAnalytics, AutoTuner } from './index-analytics.js';
|
|
7
|
+
import { AnalyticsBackend } from './analytics-backend.js';
|
|
8
|
+
import { DashboardFormatter, LiveDashboard, PerformanceAlerter } from './index-dashboard.js';
|
|
9
|
+
/**
|
|
10
|
+
* Index Monitoring System - Unified API for observability.
|
|
11
|
+
* Uses Rust-backed analytics when available, with TypeScript fallback.
|
|
12
|
+
*/
|
|
13
|
+
export class IndexMonitor {
|
|
14
|
+
constructor(collectionName, config = {}) {
|
|
15
|
+
this.collectionName = collectionName;
|
|
16
|
+
this.config = {
|
|
17
|
+
enabled: true,
|
|
18
|
+
collectTraces: true,
|
|
19
|
+
traceLimit: 10000,
|
|
20
|
+
reportPeriod: 'daily',
|
|
21
|
+
autoTuning: true,
|
|
22
|
+
alerting: true,
|
|
23
|
+
dashboardRefreshMs: 10000,
|
|
24
|
+
...config,
|
|
25
|
+
};
|
|
26
|
+
// Use performance-optimized Rust backend with TypeScript fallback
|
|
27
|
+
this.analyticsBackend = new AnalyticsBackend();
|
|
28
|
+
// Keep TypeScript analytics for AutoTuner compatibility
|
|
29
|
+
this.analytics = new IndexAnalytics();
|
|
30
|
+
this.autoTuner = new AutoTuner(this.analytics);
|
|
31
|
+
this.dashboard = new LiveDashboard();
|
|
32
|
+
this.alerter = new PerformanceAlerter();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Record query execution.
|
|
36
|
+
*/
|
|
37
|
+
recordQuery(fields, operator, executionTimeMs, rowsScanned, resultCount, indexUsed) {
|
|
38
|
+
if (!this.config.enabled || !this.config.collectTraces)
|
|
39
|
+
return;
|
|
40
|
+
// Record in both backends for consistency
|
|
41
|
+
this.analyticsBackend.recordQuery(fields, operator, executionTimeMs, rowsScanned, resultCount, indexUsed);
|
|
42
|
+
this.analytics.recordQuery(fields, operator, executionTimeMs, rowsScanned, resultCount, indexUsed);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Record index operation.
|
|
46
|
+
*/
|
|
47
|
+
recordIndexOperation(indexName, operation, timeMs) {
|
|
48
|
+
if (!this.config.enabled)
|
|
49
|
+
return;
|
|
50
|
+
// Record in both backends for consistency
|
|
51
|
+
this.analyticsBackend.recordIndexUsage(indexName, operation, timeMs);
|
|
52
|
+
this.analytics.recordIndexUsage(indexName, operation, timeMs);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get current performance report.
|
|
56
|
+
*/
|
|
57
|
+
getReport() {
|
|
58
|
+
return this.analytics.generateReport(this.collectionName, this.config.reportPeriod);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get formatted dashboard.
|
|
62
|
+
*/
|
|
63
|
+
getDashboard() {
|
|
64
|
+
const report = this.getReport();
|
|
65
|
+
return DashboardFormatter.formatReport(report);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get ASCII rendering of dashboard.
|
|
69
|
+
*/
|
|
70
|
+
renderDashboard() {
|
|
71
|
+
const dashboard = this.getDashboard();
|
|
72
|
+
return DashboardFormatter.renderASCII(dashboard);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get tuning recommendations.
|
|
76
|
+
*/
|
|
77
|
+
getRecommendations() {
|
|
78
|
+
const report = this.getReport();
|
|
79
|
+
return report.recommendations;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get auto-applicable recommendations.
|
|
83
|
+
*/
|
|
84
|
+
getAutoApplyRecommendations() {
|
|
85
|
+
const report = this.getReport();
|
|
86
|
+
return this.autoTuner.getAutoApplyableRecommendations(report);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get performance alerts.
|
|
90
|
+
*/
|
|
91
|
+
getAlerts() {
|
|
92
|
+
if (!this.config.alerting)
|
|
93
|
+
return [];
|
|
94
|
+
const dashboard = this.getDashboard();
|
|
95
|
+
return this.alerter.checkThresholds(dashboard);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get slowest queries.
|
|
99
|
+
*/
|
|
100
|
+
getSlowestQueries(limit = 10) {
|
|
101
|
+
return this.analytics.getSlowestQueries(limit);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get most frequently queried fields.
|
|
105
|
+
*/
|
|
106
|
+
getFrequentFields(limit = 20) {
|
|
107
|
+
return this.analytics.getFrequentFields(limit);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Start live dashboard updates.
|
|
111
|
+
*/
|
|
112
|
+
startLiveDashboard(callback) {
|
|
113
|
+
this.dashboard.start(() => this.getDashboard(), this.config.dashboardRefreshMs);
|
|
114
|
+
return this.dashboard.subscribe(callback);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stop live dashboard updates.
|
|
118
|
+
*/
|
|
119
|
+
stopLiveDashboard() {
|
|
120
|
+
this.dashboard.stop();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Reset all metrics.
|
|
124
|
+
*/
|
|
125
|
+
reset() {
|
|
126
|
+
this.analytics.reset();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Update monitoring configuration.
|
|
130
|
+
*/
|
|
131
|
+
updateConfig(config) {
|
|
132
|
+
this.config = { ...this.config, ...config };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Global monitoring registry for multiple collections.
|
|
137
|
+
*/
|
|
138
|
+
export class MonitoringRegistry {
|
|
139
|
+
constructor() {
|
|
140
|
+
this.monitors = new Map();
|
|
141
|
+
this.defaultConfig = {};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Register a collection monitor.
|
|
145
|
+
*/
|
|
146
|
+
register(collectionName, config) {
|
|
147
|
+
if (this.monitors.has(collectionName)) {
|
|
148
|
+
return this.monitors.get(collectionName);
|
|
149
|
+
}
|
|
150
|
+
const finalConfig = { ...this.defaultConfig, ...config };
|
|
151
|
+
const monitor = new IndexMonitor(collectionName, finalConfig);
|
|
152
|
+
this.monitors.set(collectionName, monitor);
|
|
153
|
+
return monitor;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get monitor for collection.
|
|
157
|
+
*/
|
|
158
|
+
get(collectionName) {
|
|
159
|
+
return this.monitors.get(collectionName) || null;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get all monitors.
|
|
163
|
+
*/
|
|
164
|
+
getAll() {
|
|
165
|
+
return Array.from(this.monitors.values());
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Generate combined report for all collections.
|
|
169
|
+
*/
|
|
170
|
+
generateGlobalReport() {
|
|
171
|
+
const reports = Array.from(this.monitors.values()).map(m => m.getReport());
|
|
172
|
+
const totalQueries = reports.reduce((sum, r) => sum + r.totalQueries, 0);
|
|
173
|
+
const totalIndexedQueries = reports.reduce((sum, r) => sum + r.indexedQueries, 0);
|
|
174
|
+
return {
|
|
175
|
+
timestamp: Date.now(),
|
|
176
|
+
collections: reports.length,
|
|
177
|
+
totalQueries,
|
|
178
|
+
indexUsageRate: totalQueries > 0 ? totalIndexedQueries / totalQueries : 0,
|
|
179
|
+
reports,
|
|
180
|
+
overallHealth: totalIndexedQueries / Math.max(totalQueries, 1) > 0.8 ? 'healthy' : 'warning',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get critical alerts across all collections.
|
|
185
|
+
*/
|
|
186
|
+
getCriticalAlerts() {
|
|
187
|
+
const allAlerts = Array.from(this.monitors.values())
|
|
188
|
+
.flatMap(m => m.getAlerts())
|
|
189
|
+
.filter(a => a.severity === 'critical');
|
|
190
|
+
return allAlerts.sort((a, b) => b.timestamp - a.timestamp);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Set default configuration for new monitors.
|
|
194
|
+
*/
|
|
195
|
+
setDefaultConfig(config) {
|
|
196
|
+
this.defaultConfig = config;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reset all monitors.
|
|
200
|
+
*/
|
|
201
|
+
resetAll() {
|
|
202
|
+
for (const monitor of this.monitors.values()) {
|
|
203
|
+
monitor.reset();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Integration hook for Collection class.
|
|
209
|
+
*/
|
|
210
|
+
export function createMonitoringIntegration(collectionName) {
|
|
211
|
+
return function setupMonitoring(monitor) {
|
|
212
|
+
// Queries would be recorded through this integration
|
|
213
|
+
// Example usage in Collection class:
|
|
214
|
+
// const start = performance.now();
|
|
215
|
+
// const results = await index.query(...);
|
|
216
|
+
// monitor.recordQuery(fields, operator, performance.now() - start, rowsScanned, results.length, indexUsed);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Recovery and Validation
|
|
3
|
+
*
|
|
4
|
+
* Ensures indexes are valid and consistent after crashes or data corruption.
|
|
5
|
+
* Automatically rebuilds stale or missing indexes on startup.
|
|
6
|
+
*/
|
|
7
|
+
import type { Collection } from './collection.js';
|
|
8
|
+
export interface IndexRecoveryReport {
|
|
9
|
+
collectionName: string;
|
|
10
|
+
indexesChecked: number;
|
|
11
|
+
indexesRebuilt: number;
|
|
12
|
+
duration: number;
|
|
13
|
+
errors: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validate and repair indexes across a collection.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateAndRepairIndexes(collection: Collection<any>): Promise<IndexRecoveryReport>;
|
|
19
|
+
/**
|
|
20
|
+
* Batch validate multiple collections.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateMultipleCollections(collections: Collection<any>[]): Promise<IndexRecoveryReport[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Index consistency checker for detecting corruption.
|
|
25
|
+
*/
|
|
26
|
+
export declare class IndexConsistencyChecker {
|
|
27
|
+
/**
|
|
28
|
+
* Check if index entries match collection data.
|
|
29
|
+
*/
|
|
30
|
+
static checkEntryCount(collection: Collection<any>, indexName: string, expectedCount: number): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Detect orphaned index entries (entries for deleted records).
|
|
33
|
+
*/
|
|
34
|
+
static detectOrphanedEntries(collection: Collection<any>): Promise<string[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Detect missing index entries (records not in index).
|
|
37
|
+
*/
|
|
38
|
+
static detectMissingEntries(collection: Collection<any>): Promise<string[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Index repair strategies for different corruption scenarios.
|
|
42
|
+
*/
|
|
43
|
+
export declare class IndexRepairStrategy {
|
|
44
|
+
/**
|
|
45
|
+
* Full rebuild: Delete and recreate all indexes from scratch.
|
|
46
|
+
*/
|
|
47
|
+
static fullRebuild(collection: Collection<any>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Partial repair: Only rebuild stale indexes.
|
|
50
|
+
*/
|
|
51
|
+
static partialRepair(collection: Collection<any>): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Incremental repair: Fix corruption by replaying operations.
|
|
54
|
+
*/
|
|
55
|
+
static incrementalRepair(collection: Collection<any>): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-recovery.d.ts","sourceRoot":"","sources":["../src/index-recovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAoC9B;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,GAC7B,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAKhC;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAClC;;OAEG;WACU,eAAe,CAC1B,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAC3B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;IAOnB;;OAEG;WACU,qBAAqB,CAChC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC;IAMpB;;OAEG;WACU,oBAAoB,CAC/B,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC;CAKrB;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;OAEG;WACU,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE;;OAEG;WACU,aAAa,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAatE;;OAEG;WACU,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ3E"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Recovery and Validation
|
|
3
|
+
*
|
|
4
|
+
* Ensures indexes are valid and consistent after crashes or data corruption.
|
|
5
|
+
* Automatically rebuilds stale or missing indexes on startup.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validate and repair indexes across a collection.
|
|
9
|
+
*/
|
|
10
|
+
export async function validateAndRepairIndexes(collection) {
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
const report = {
|
|
13
|
+
collectionName: collection.name || 'unknown',
|
|
14
|
+
indexesChecked: 0,
|
|
15
|
+
indexesRebuilt: 0,
|
|
16
|
+
duration: 0,
|
|
17
|
+
errors: [],
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const indexes = collection.listIndexes();
|
|
21
|
+
report.indexesChecked = indexes.length;
|
|
22
|
+
if (indexes.length === 0) {
|
|
23
|
+
report.duration = Date.now() - startTime;
|
|
24
|
+
return report;
|
|
25
|
+
}
|
|
26
|
+
// Validate each index
|
|
27
|
+
const isValid = await collection.validateIndexes();
|
|
28
|
+
if (!isValid) {
|
|
29
|
+
try {
|
|
30
|
+
await collection.rebuildIndexes();
|
|
31
|
+
report.indexesRebuilt = indexes.length;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
report.errors.push(`Failed to rebuild indexes: ${String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
report.errors.push(`Validation failed: ${String(error)}`);
|
|
40
|
+
}
|
|
41
|
+
report.duration = Date.now() - startTime;
|
|
42
|
+
return report;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Batch validate multiple collections.
|
|
46
|
+
*/
|
|
47
|
+
export async function validateMultipleCollections(collections) {
|
|
48
|
+
const reports = await Promise.all(collections.map(collection => validateAndRepairIndexes(collection)));
|
|
49
|
+
return reports;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Index consistency checker for detecting corruption.
|
|
53
|
+
*/
|
|
54
|
+
export class IndexConsistencyChecker {
|
|
55
|
+
/**
|
|
56
|
+
* Check if index entries match collection data.
|
|
57
|
+
*/
|
|
58
|
+
static async checkEntryCount(collection, indexName, expectedCount) {
|
|
59
|
+
// This would query the index to get actual entry count
|
|
60
|
+
// For now, we just check that the collection size matches expectation
|
|
61
|
+
const items = await collection.all();
|
|
62
|
+
return Math.abs(items.length - expectedCount) < items.length * 0.1;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Detect orphaned index entries (entries for deleted records).
|
|
66
|
+
*/
|
|
67
|
+
static async detectOrphanedEntries(collection) {
|
|
68
|
+
// This would scan indexes and check if each entry has a corresponding record
|
|
69
|
+
// Returns list of orphaned entry IDs
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detect missing index entries (records not in index).
|
|
74
|
+
*/
|
|
75
|
+
static async detectMissingEntries(collection) {
|
|
76
|
+
// This would scan collection and check if each record is in the index
|
|
77
|
+
// Returns list of missing record IDs
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Index repair strategies for different corruption scenarios.
|
|
83
|
+
*/
|
|
84
|
+
export class IndexRepairStrategy {
|
|
85
|
+
/**
|
|
86
|
+
* Full rebuild: Delete and recreate all indexes from scratch.
|
|
87
|
+
*/
|
|
88
|
+
static async fullRebuild(collection) {
|
|
89
|
+
await collection.rebuildIndexes();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Partial repair: Only rebuild stale indexes.
|
|
93
|
+
*/
|
|
94
|
+
static async partialRepair(collection) {
|
|
95
|
+
const indexes = collection.listIndexes();
|
|
96
|
+
// Mark only corrupted indexes for rebuild
|
|
97
|
+
for (const index of indexes) {
|
|
98
|
+
// Check if this specific index is stale
|
|
99
|
+
const isStale = Math.random() < 0.1; // Placeholder
|
|
100
|
+
if (isStale) {
|
|
101
|
+
// Rebuild only this index
|
|
102
|
+
await collection.rebuildIndexes();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Incremental repair: Fix corruption by replaying operations.
|
|
108
|
+
*/
|
|
109
|
+
static async incrementalRepair(collection) {
|
|
110
|
+
// Replay recent mutations to rebuild index state
|
|
111
|
+
const items = await collection.all();
|
|
112
|
+
for (const item of items) {
|
|
113
|
+
const recordId = item?.id || JSON.stringify(item);
|
|
114
|
+
// Re-index this record
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Persistence Layer
|
|
3
|
+
*
|
|
4
|
+
* Handles serialization and storage of indexes for durability.
|
|
5
|
+
* Indexes are stored in a special collection alongside application data.
|
|
6
|
+
*/
|
|
7
|
+
import type { JsDb } from './feltdb.js';
|
|
8
|
+
import type { IndexConfig } from './index-types.js';
|
|
9
|
+
export interface StoredIndex {
|
|
10
|
+
config: IndexConfig;
|
|
11
|
+
version: number;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
lastUpdated: number;
|
|
14
|
+
entryCount: number;
|
|
15
|
+
}
|
|
16
|
+
export interface IndexSnapshot {
|
|
17
|
+
collectionName: string;
|
|
18
|
+
indexes: StoredIndex[];
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class IndexStore {
|
|
22
|
+
private db;
|
|
23
|
+
private collectionName;
|
|
24
|
+
constructor(db: JsDb, collectionName: string);
|
|
25
|
+
/**
|
|
26
|
+
* Save index metadata to storage.
|
|
27
|
+
* Stores index configuration but not the actual index data (rebuilt on demand).
|
|
28
|
+
*/
|
|
29
|
+
saveIndexConfig(config: IndexConfig, entryCount: number): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Load all index configurations for a collection.
|
|
32
|
+
*/
|
|
33
|
+
loadIndexConfigs(): Promise<IndexConfig[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Get specific index configuration.
|
|
36
|
+
*/
|
|
37
|
+
getIndexConfig(indexName: string): Promise<IndexConfig | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete index metadata from storage.
|
|
40
|
+
*/
|
|
41
|
+
deleteIndexConfig(indexName: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Update index metadata (entry count, timestamp).
|
|
44
|
+
*/
|
|
45
|
+
updateIndexStats(indexName: string, entryCount: number): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get full index snapshot (configuration + metadata).
|
|
48
|
+
*/
|
|
49
|
+
getSnapshot(): Promise<IndexSnapshot>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Index rebuilder - reconstructs indexes from collection data.
|
|
53
|
+
* Used when loading persisted indexes at startup.
|
|
54
|
+
*/
|
|
55
|
+
export declare class IndexRebuilder {
|
|
56
|
+
static rebuildIndexes(db: JsDb, collectionName: string, items: any[], indexConfigs: IndexConfig[]): Promise<Map<string, any>>;
|
|
57
|
+
/**
|
|
58
|
+
* Check if an index is stale by comparing entry count to collection size.
|
|
59
|
+
*/
|
|
60
|
+
static isStale(indexEntryCount: number, collectionSize: number): boolean;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-store.d.ts","sourceRoot":"","sources":["../src/index-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,EAAE,CAAO;IACjB,OAAO,CAAC,cAAc,CAAS;gBAEnB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM;IAK5C;;;OAGG;IACG,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB7E;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAgBhD;;OAEG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgBpE;;OAEG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAczD;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB5E;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,aAAa,CAAC;CAc5C;AAED;;;GAGG;AACH,qBAAa,cAAc;WACZ,cAAc,CACzB,EAAE,EAAE,IAAI,EACR,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,GAAG,EAAE,EACZ,YAAY,EAAE,WAAW,EAAE,GAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAgB5B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO;CAIzE"}
|