@freshguard/freshguard-core 0.13.2 → 0.15.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/CHANGELOG.md +15 -1
- package/README.md +74 -1
- package/SKILL.md +229 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +74 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/connectors/azure-sql.d.ts +121 -0
- package/dist/connectors/azure-sql.d.ts.map +1 -0
- package/dist/connectors/azure-sql.js +489 -0
- package/dist/connectors/azure-sql.js.map +1 -0
- package/dist/connectors/base-connector.d.ts +139 -0
- package/dist/connectors/base-connector.d.ts.map +1 -1
- package/dist/connectors/base-connector.js +160 -3
- package/dist/connectors/base-connector.js.map +1 -1
- package/dist/connectors/bigquery.d.ts +100 -0
- package/dist/connectors/bigquery.d.ts.map +1 -1
- package/dist/connectors/bigquery.js +143 -2
- package/dist/connectors/bigquery.js.map +1 -1
- package/dist/connectors/duckdb.d.ts +96 -0
- package/dist/connectors/duckdb.d.ts.map +1 -1
- package/dist/connectors/duckdb.js +144 -7
- package/dist/connectors/duckdb.js.map +1 -1
- package/dist/connectors/index.d.ts +28 -0
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +28 -0
- package/dist/connectors/index.js.map +1 -1
- package/dist/connectors/mssql.d.ts +119 -0
- package/dist/connectors/mssql.d.ts.map +1 -0
- package/dist/connectors/mssql.js +483 -0
- package/dist/connectors/mssql.js.map +1 -0
- package/dist/connectors/mysql.d.ts +85 -0
- package/dist/connectors/mysql.d.ts.map +1 -1
- package/dist/connectors/mysql.js +118 -3
- package/dist/connectors/mysql.js.map +1 -1
- package/dist/connectors/postgres.d.ts +85 -0
- package/dist/connectors/postgres.d.ts.map +1 -1
- package/dist/connectors/postgres.js +113 -6
- package/dist/connectors/postgres.js.map +1 -1
- package/dist/connectors/redshift.d.ts +90 -0
- package/dist/connectors/redshift.d.ts.map +1 -1
- package/dist/connectors/redshift.js +131 -7
- package/dist/connectors/redshift.js.map +1 -1
- package/dist/connectors/snowflake.d.ts +108 -0
- package/dist/connectors/snowflake.d.ts.map +1 -1
- package/dist/connectors/snowflake.js +137 -3
- package/dist/connectors/snowflake.js.map +1 -1
- package/dist/connectors/synapse.d.ts +123 -0
- package/dist/connectors/synapse.d.ts.map +1 -0
- package/dist/connectors/synapse.js +495 -0
- package/dist/connectors/synapse.js.map +1 -0
- package/dist/db/index.d.ts +25 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +23 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrate.d.ts +23 -0
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +38 -0
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/schema.d.ts +11 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +70 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/errors/debug-factory.d.ts +38 -0
- package/dist/errors/debug-factory.d.ts.map +1 -1
- package/dist/errors/debug-factory.js +40 -0
- package/dist/errors/debug-factory.js.map +1 -1
- package/dist/errors/index.d.ts +59 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +110 -7
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -1
- package/dist/index.js.map +1 -1
- package/dist/metadata/duckdb-storage.d.ts +3 -0
- package/dist/metadata/duckdb-storage.d.ts.map +1 -1
- package/dist/metadata/duckdb-storage.js +6 -0
- package/dist/metadata/duckdb-storage.js.map +1 -1
- package/dist/metadata/factory.d.ts +30 -0
- package/dist/metadata/factory.d.ts.map +1 -1
- package/dist/metadata/factory.js +31 -0
- package/dist/metadata/factory.js.map +1 -1
- package/dist/metadata/index.d.ts +26 -0
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/index.js +26 -0
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/interface.d.ts +33 -0
- package/dist/metadata/interface.d.ts.map +1 -1
- package/dist/metadata/interface.js +3 -0
- package/dist/metadata/interface.js.map +1 -1
- package/dist/metadata/postgresql-storage.d.ts +3 -0
- package/dist/metadata/postgresql-storage.d.ts.map +1 -1
- package/dist/metadata/postgresql-storage.js +12 -2
- package/dist/metadata/postgresql-storage.js.map +1 -1
- package/dist/metadata/schema-config.d.ts +53 -0
- package/dist/metadata/schema-config.d.ts.map +1 -1
- package/dist/metadata/schema-config.js +64 -0
- package/dist/metadata/schema-config.js.map +1 -1
- package/dist/metadata/types.d.ts +3 -0
- package/dist/metadata/types.d.ts.map +1 -1
- package/dist/metadata/types.js +3 -0
- package/dist/metadata/types.js.map +1 -1
- package/dist/monitor/baseline-calculator.d.ts +56 -0
- package/dist/monitor/baseline-calculator.d.ts.map +1 -1
- package/dist/monitor/baseline-calculator.js +72 -0
- package/dist/monitor/baseline-calculator.js.map +1 -1
- package/dist/monitor/baseline-config.d.ts +77 -0
- package/dist/monitor/baseline-config.d.ts.map +1 -1
- package/dist/monitor/baseline-config.js +79 -1
- package/dist/monitor/baseline-config.js.map +1 -1
- package/dist/monitor/freshness.d.ts +40 -0
- package/dist/monitor/freshness.d.ts.map +1 -1
- package/dist/monitor/freshness.js +82 -3
- package/dist/monitor/freshness.js.map +1 -1
- package/dist/monitor/index.d.ts +29 -0
- package/dist/monitor/index.d.ts.map +1 -1
- package/dist/monitor/index.js +29 -0
- package/dist/monitor/index.js.map +1 -1
- package/dist/monitor/schema-baseline.d.ts +45 -0
- package/dist/monitor/schema-baseline.d.ts.map +1 -1
- package/dist/monitor/schema-baseline.js +63 -5
- package/dist/monitor/schema-baseline.js.map +1 -1
- package/dist/monitor/schema-changes.d.ts +45 -0
- package/dist/monitor/schema-changes.d.ts.map +1 -1
- package/dist/monitor/schema-changes.js +85 -0
- package/dist/monitor/schema-changes.js.map +1 -1
- package/dist/monitor/volume.d.ts +43 -0
- package/dist/monitor/volume.d.ts.map +1 -1
- package/dist/monitor/volume.js +89 -0
- package/dist/monitor/volume.js.map +1 -1
- package/dist/observability/logger.d.ts +91 -0
- package/dist/observability/logger.d.ts.map +1 -1
- package/dist/observability/logger.js +108 -0
- package/dist/observability/logger.js.map +1 -1
- package/dist/observability/metrics.d.ts +140 -0
- package/dist/observability/metrics.d.ts.map +1 -1
- package/dist/observability/metrics.js +184 -7
- package/dist/observability/metrics.js.map +1 -1
- package/dist/resilience/circuit-breaker.d.ts +112 -2
- package/dist/resilience/circuit-breaker.d.ts.map +1 -1
- package/dist/resilience/circuit-breaker.js +140 -6
- package/dist/resilience/circuit-breaker.js.map +1 -1
- package/dist/resilience/index.d.ts +9 -0
- package/dist/resilience/index.d.ts.map +1 -1
- package/dist/resilience/index.js +13 -0
- package/dist/resilience/index.js.map +1 -1
- package/dist/resilience/retry-policy.d.ts +105 -0
- package/dist/resilience/retry-policy.d.ts.map +1 -1
- package/dist/resilience/retry-policy.js +158 -7
- package/dist/resilience/retry-policy.js.map +1 -1
- package/dist/resilience/timeout-manager.d.ts +137 -0
- package/dist/resilience/timeout-manager.d.ts.map +1 -1
- package/dist/resilience/timeout-manager.js +151 -4
- package/dist/resilience/timeout-manager.js.map +1 -1
- package/dist/security/query-analyzer.d.ts +124 -0
- package/dist/security/query-analyzer.d.ts.map +1 -1
- package/dist/security/query-analyzer.js +150 -9
- package/dist/security/query-analyzer.js.map +1 -1
- package/dist/security/schema-cache.d.ts +152 -0
- package/dist/security/schema-cache.d.ts.map +1 -1
- package/dist/security/schema-cache.js +144 -12
- package/dist/security/schema-cache.js.map +1 -1
- package/dist/types/connector.d.ts +68 -1
- package/dist/types/connector.d.ts.map +1 -1
- package/dist/types/connector.js +38 -15
- package/dist/types/connector.js.map +1 -1
- package/dist/types/driver-results.d.ts +28 -0
- package/dist/types/driver-results.d.ts.map +1 -1
- package/dist/types/driver-results.js +12 -0
- package/dist/types/driver-results.js.map +1 -1
- package/dist/types.d.ts +113 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/dist/validation/index.d.ts +8 -0
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +12 -0
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/runtime-validator.d.ts +98 -0
- package/dist/validation/runtime-validator.d.ts.map +1 -1
- package/dist/validation/runtime-validator.js +114 -1
- package/dist/validation/runtime-validator.js.map +1 -1
- package/dist/validation/sanitizers.d.ts +59 -0
- package/dist/validation/sanitizers.d.ts.map +1 -1
- package/dist/validation/sanitizers.js +104 -20
- package/dist/validation/sanitizers.js.map +1 -1
- package/dist/validation/schemas.d.ts +73 -0
- package/dist/validation/schemas.d.ts.map +1 -1
- package/dist/validation/schemas.js +132 -5
- package/dist/validation/schemas.js.map +1 -1
- package/dist/validators/index.d.ts +54 -0
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +93 -2
- package/dist/validators/index.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secure Azure Synapse Analytics connector for FreshGuard Core
|
|
3
|
+
* Extends BaseConnector with security built-in
|
|
4
|
+
* Uses mssql driver with Synapse-specific configuration
|
|
5
|
+
*
|
|
6
|
+
* @module @freshguard/freshguard-core/connectors/synapse
|
|
7
|
+
*/
|
|
8
|
+
import * as mssql from 'mssql';
|
|
9
|
+
import { BaseConnector } from './base-connector.js';
|
|
10
|
+
import { rowString } from '../types/driver-results.js';
|
|
11
|
+
import { ConnectionError, TimeoutError, QueryError, ErrorHandler } from '../errors/index.js';
|
|
12
|
+
import { validateConnectorConfig } from '../validators/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Secure Azure Synapse Analytics connector
|
|
15
|
+
*
|
|
16
|
+
* SSL is always enforced (Azure requirement). Includes Synapse-specific DMV
|
|
17
|
+
* support for `dm_pdw_exec_requests`.
|
|
18
|
+
*
|
|
19
|
+
* Features:
|
|
20
|
+
* - SQL injection prevention
|
|
21
|
+
* - Connection timeouts
|
|
22
|
+
* - SSL always enforced (Azure requirement)
|
|
23
|
+
* - Read-only query patterns
|
|
24
|
+
* - Secure error handling
|
|
25
|
+
* - Synapse-specific DMV support (dm_pdw_exec_requests)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { SynapseConnector } from '@freshguard/freshguard-core';
|
|
30
|
+
*
|
|
31
|
+
* const connector = new SynapseConnector({
|
|
32
|
+
* host: 'myworkspace.sql.azuresynapse.net', port: 1433,
|
|
33
|
+
* database: 'analytics_pool',
|
|
34
|
+
* username: 'readonly',
|
|
35
|
+
* password: process.env.SYNAPSE_PASSWORD!,
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class SynapseConnector extends BaseConnector {
|
|
40
|
+
pool = null;
|
|
41
|
+
connected = false;
|
|
42
|
+
/**
|
|
43
|
+
* @param config - Database connection settings (host, port, database, credentials)
|
|
44
|
+
* @param securityConfig - Optional overrides for query timeouts, max rows, and blocked keywords
|
|
45
|
+
*/
|
|
46
|
+
constructor(config, securityConfig) {
|
|
47
|
+
// Validate configuration before proceeding
|
|
48
|
+
validateConnectorConfig(config);
|
|
49
|
+
super(config, securityConfig);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Connect to Azure Synapse Analytics with security validation
|
|
53
|
+
*/
|
|
54
|
+
async connect() {
|
|
55
|
+
if (this.connected && this.pool) {
|
|
56
|
+
return; // Already connected
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const poolConfig = {
|
|
60
|
+
server: this.config.host,
|
|
61
|
+
port: this.config.port ?? 1433,
|
|
62
|
+
database: this.config.database,
|
|
63
|
+
user: this.config.username,
|
|
64
|
+
password: this.config.password,
|
|
65
|
+
options: {
|
|
66
|
+
// Azure Synapse always requires encryption
|
|
67
|
+
encrypt: true,
|
|
68
|
+
trustServerCertificate: false,
|
|
69
|
+
connectTimeout: this.connectionTimeout,
|
|
70
|
+
requestTimeout: this.queryTimeout,
|
|
71
|
+
appName: this.config.applicationName ?? 'freshguard-core'
|
|
72
|
+
},
|
|
73
|
+
pool: {
|
|
74
|
+
max: 1, // Single connection for monitoring
|
|
75
|
+
min: 0,
|
|
76
|
+
idleTimeoutMillis: 30000
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
this.pool = new mssql.ConnectionPool(poolConfig);
|
|
80
|
+
await this.pool.connect();
|
|
81
|
+
this.connected = true;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new ConnectionError('Failed to connect to Azure Synapse Analytics', this.config.host, this.config.port, error instanceof Error ? error : undefined);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Execute a validated SQL query with security measures
|
|
89
|
+
*/
|
|
90
|
+
async executeQuery(sql) {
|
|
91
|
+
return this.executeParameterizedQuery(sql, []);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Execute a parameterized SQL query using prepared statements
|
|
95
|
+
*/
|
|
96
|
+
async executeParameterizedQuery(sql, parameters = []) {
|
|
97
|
+
await this.connect();
|
|
98
|
+
if (!this.pool) {
|
|
99
|
+
throw new ConnectionError('Database connection not available');
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const result = await this.executeWithTimeout(async () => {
|
|
103
|
+
if (!this.pool)
|
|
104
|
+
throw new ConnectionError('Database connection not available');
|
|
105
|
+
const request = this.pool.request();
|
|
106
|
+
// Bind positional parameters as @p1, @p2, etc.
|
|
107
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
108
|
+
request.input(`p${i + 1}`, parameters[i]);
|
|
109
|
+
}
|
|
110
|
+
// Replace $N placeholders with @pN for MSSQL
|
|
111
|
+
let mssqlSql = sql;
|
|
112
|
+
for (let i = parameters.length; i >= 1; i--) {
|
|
113
|
+
mssqlSql = mssqlSql.replace(new RegExp(`\\$${i}`, 'g'), `@p${i}`);
|
|
114
|
+
}
|
|
115
|
+
// Also replace ? placeholders with @pN
|
|
116
|
+
let paramIndex = 0;
|
|
117
|
+
mssqlSql = mssqlSql.replace(/\?/g, () => `@p${++paramIndex}`);
|
|
118
|
+
const res = await request.query(mssqlSql);
|
|
119
|
+
return (res.recordset ?? []);
|
|
120
|
+
}, this.queryTimeout);
|
|
121
|
+
// Validate result size for security
|
|
122
|
+
this.validateResultSize(result);
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error instanceof TimeoutError) {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
// Sanitize and re-throw as QueryError
|
|
130
|
+
throw new QueryError(ErrorHandler.getUserMessage(error), 'query_execution', undefined, error instanceof Error ? error : undefined);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Test database connection with security validation
|
|
135
|
+
*/
|
|
136
|
+
async testConnection(debugConfig) {
|
|
137
|
+
const mergedDebugConfig = this.mergeDebugConfig(debugConfig);
|
|
138
|
+
const debugId = `synapse-test-${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 5)}`;
|
|
139
|
+
const startTime = performance.now();
|
|
140
|
+
try {
|
|
141
|
+
this.logDebugInfo(mergedDebugConfig, debugId, 'Starting connection test', {
|
|
142
|
+
host: this.config.host,
|
|
143
|
+
port: this.config.port,
|
|
144
|
+
database: this.config.database,
|
|
145
|
+
ssl: this.config.ssl
|
|
146
|
+
});
|
|
147
|
+
await this.connect();
|
|
148
|
+
if (!this.pool) {
|
|
149
|
+
this.logDebugError(mergedDebugConfig, debugId, 'Connection test', {
|
|
150
|
+
error: 'Connection not available after connect',
|
|
151
|
+
duration: performance.now() - startTime
|
|
152
|
+
});
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
// Test with a simple, safe query (skip validation for connection test)
|
|
156
|
+
const sql = 'SELECT 1 AS test';
|
|
157
|
+
await this.executeWithTimeout(async () => {
|
|
158
|
+
if (!this.pool)
|
|
159
|
+
throw new ConnectionError('Database connection not available');
|
|
160
|
+
const request = this.pool.request();
|
|
161
|
+
return request.query(sql);
|
|
162
|
+
}, this.connectionTimeout);
|
|
163
|
+
const duration = performance.now() - startTime;
|
|
164
|
+
if (mergedDebugConfig?.enabled) {
|
|
165
|
+
console.log(`[DEBUG-${debugId}] Connection test completed:`, {
|
|
166
|
+
success: true,
|
|
167
|
+
duration,
|
|
168
|
+
host: this.config.host,
|
|
169
|
+
database: this.config.database
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
const duration = performance.now() - startTime;
|
|
176
|
+
this.logDebugError(mergedDebugConfig, debugId, 'Connection test', {
|
|
177
|
+
host: this.config.host,
|
|
178
|
+
port: this.config.port,
|
|
179
|
+
database: this.config.database,
|
|
180
|
+
error: mergedDebugConfig?.exposeRawErrors && error instanceof Error ? error.message : 'Connection failed',
|
|
181
|
+
duration,
|
|
182
|
+
suggestion: this.generateConnectionSuggestion(error)
|
|
183
|
+
});
|
|
184
|
+
// Don't throw - this method should return boolean
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Helper method to merge debug configuration
|
|
190
|
+
*/
|
|
191
|
+
mergeDebugConfig(debugConfig) {
|
|
192
|
+
return {
|
|
193
|
+
enabled: debugConfig?.enabled ?? (process.env.NODE_ENV === 'development'),
|
|
194
|
+
exposeQueries: debugConfig?.exposeQueries ?? true,
|
|
195
|
+
exposeRawErrors: debugConfig?.exposeRawErrors ?? true,
|
|
196
|
+
logLevel: debugConfig?.logLevel ?? 'debug'
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Generate connection suggestions based on error (Synapse-specific)
|
|
201
|
+
*/
|
|
202
|
+
generateConnectionSuggestion(error) {
|
|
203
|
+
if (!(error instanceof Error)) {
|
|
204
|
+
return 'Check database connection configuration';
|
|
205
|
+
}
|
|
206
|
+
const message = error.message.toLowerCase();
|
|
207
|
+
if (message.includes('connect econnrefused') || message.includes('connection refused')) {
|
|
208
|
+
return `Azure Synapse at ${this.config.host}:${this.config.port} is not accepting connections. Verify the SQL pool is running and check firewall rules.`;
|
|
209
|
+
}
|
|
210
|
+
if (message.includes('timeout') || message.includes('connect timeout')) {
|
|
211
|
+
return `Connection timeout to ${this.config.host}:${this.config.port}. The SQL pool may be paused or scaling. Check pool status and firewall rules.`;
|
|
212
|
+
}
|
|
213
|
+
if (message.includes('login failed') || message.includes('authentication failed')) {
|
|
214
|
+
return `Authentication failed for database '${this.config.database}'. Verify username, password, and Azure AD configuration if using AAD auth.`;
|
|
215
|
+
}
|
|
216
|
+
if (message.includes('cannot open database') || (message.includes('database') && message.includes('not exist'))) {
|
|
217
|
+
return `Database '${this.config.database}' not found. Check database name on your Azure Synapse workspace.`;
|
|
218
|
+
}
|
|
219
|
+
if (message.includes('ssl') || message.includes('tls') || message.includes('encrypt')) {
|
|
220
|
+
return `SSL/TLS connection issue. Azure Synapse requires encryption - check SSL certificate configuration.`;
|
|
221
|
+
}
|
|
222
|
+
if (message.includes('firewall')) {
|
|
223
|
+
return `Connection blocked by firewall. Add your client IP address to the Synapse workspace firewall rules.`;
|
|
224
|
+
}
|
|
225
|
+
if (message.includes('paused') || message.includes('suspended') || message.includes('resuming')) {
|
|
226
|
+
return `SQL pool appears to be paused or resuming. Resume the dedicated SQL pool in the Azure portal and wait for it to become available.`;
|
|
227
|
+
}
|
|
228
|
+
if (message.includes('dwu') || message.includes('capacity')) {
|
|
229
|
+
return `SQL pool capacity issue. Check DWU settings and consider scaling up your dedicated SQL pool.`;
|
|
230
|
+
}
|
|
231
|
+
return `Connection failed to ${this.config.host}:${this.config.port}. Check host, port, credentials, SQL pool status, and network connectivity.`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* List all tables in the database (including external tables)
|
|
235
|
+
*/
|
|
236
|
+
async listTables() {
|
|
237
|
+
const sql = `
|
|
238
|
+
SELECT TABLE_NAME as table_name
|
|
239
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
240
|
+
WHERE TABLE_TYPE = 'BASE TABLE'
|
|
241
|
+
AND TABLE_SCHEMA = 'dbo'
|
|
242
|
+
ORDER BY TABLE_NAME
|
|
243
|
+
`;
|
|
244
|
+
await this.validateQuery(sql);
|
|
245
|
+
try {
|
|
246
|
+
const result = await this.executeQuery(sql);
|
|
247
|
+
return result
|
|
248
|
+
.slice(0, this.maxRows)
|
|
249
|
+
.map((row) => rowString(row.table_name ?? row.TABLE_NAME ?? row.tablename))
|
|
250
|
+
.filter(Boolean);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
throw new QueryError('Failed to list tables', 'table_listing', undefined, error instanceof Error ? error : undefined);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get table schema information securely
|
|
258
|
+
*/
|
|
259
|
+
async getTableSchema(table) {
|
|
260
|
+
// Validate table name (identifiers cannot be parameterized)
|
|
261
|
+
this.escapeIdentifier(table);
|
|
262
|
+
const sql = `
|
|
263
|
+
SELECT
|
|
264
|
+
COLUMN_NAME as column_name,
|
|
265
|
+
DATA_TYPE as data_type,
|
|
266
|
+
IS_NULLABLE as is_nullable
|
|
267
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
268
|
+
WHERE TABLE_SCHEMA = 'dbo'
|
|
269
|
+
AND TABLE_NAME = '${table}'
|
|
270
|
+
ORDER BY ORDINAL_POSITION
|
|
271
|
+
`;
|
|
272
|
+
await this.validateQuery(sql);
|
|
273
|
+
try {
|
|
274
|
+
const result = await this.executeQuery(sql);
|
|
275
|
+
const limited = result.slice(0, this.maxRows);
|
|
276
|
+
if (limited.length === 0) {
|
|
277
|
+
throw QueryError.tableNotFound(table);
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
table,
|
|
281
|
+
columns: limited.map(row => ({
|
|
282
|
+
name: rowString(row.column_name ?? row.COLUMN_NAME),
|
|
283
|
+
type: this.mapSynapseType(rowString(row.data_type ?? row.DATA_TYPE)),
|
|
284
|
+
nullable: (row.is_nullable ?? row.IS_NULLABLE) === 'YES'
|
|
285
|
+
}))
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
if (error instanceof QueryError) {
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
throw new QueryError('Failed to get table schema', 'schema_query', table, error instanceof Error ? error : undefined);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get last modified timestamp using Synapse-specific methods
|
|
297
|
+
*/
|
|
298
|
+
async getLastModified(table) {
|
|
299
|
+
// Try common timestamp columns
|
|
300
|
+
const timestampColumns = ['updated_at', 'modified_at', 'last_modified', 'timestamp'];
|
|
301
|
+
for (const column of timestampColumns) {
|
|
302
|
+
try {
|
|
303
|
+
const result = await this.getMaxTimestamp(table, column);
|
|
304
|
+
if (result) {
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// Column doesn't exist, try next one
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Fallback: use Synapse DMV for recent requests against this table
|
|
314
|
+
try {
|
|
315
|
+
const sql = `
|
|
316
|
+
SELECT MAX(end_time) as last_modified
|
|
317
|
+
FROM sys.dm_pdw_exec_requests
|
|
318
|
+
WHERE command LIKE '%${this.escapeIdentifier(table).replace(/\[|\]/g, '')}%'
|
|
319
|
+
AND status = 'Completed'
|
|
320
|
+
AND resource_class IS NOT NULL
|
|
321
|
+
`;
|
|
322
|
+
await this.validateQuery(sql);
|
|
323
|
+
const result = await this.executeQuery(sql);
|
|
324
|
+
if (result.length > 0 && result[0]?.last_modified) {
|
|
325
|
+
return new Date(rowString(result[0].last_modified));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
// DMV query failed, return null
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Close the database connection
|
|
335
|
+
*/
|
|
336
|
+
async close() {
|
|
337
|
+
if (this.pool) {
|
|
338
|
+
try {
|
|
339
|
+
await this.pool.close();
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
// Log error but don't throw - closing should be safe
|
|
343
|
+
console.warn('Warning: Error closing Synapse connection:', ErrorHandler.getUserMessage(error));
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
this.pool = null;
|
|
347
|
+
this.connected = false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Map Synapse data types to standard types
|
|
353
|
+
* Includes Synapse-specific types alongside standard SQL Server types
|
|
354
|
+
*/
|
|
355
|
+
mapSynapseType(synapseType) {
|
|
356
|
+
const typeMap = {
|
|
357
|
+
// Numeric types
|
|
358
|
+
'tinyint': 'integer',
|
|
359
|
+
'smallint': 'integer',
|
|
360
|
+
'int': 'integer',
|
|
361
|
+
'integer': 'integer',
|
|
362
|
+
'bigint': 'bigint',
|
|
363
|
+
'decimal': 'decimal',
|
|
364
|
+
'numeric': 'decimal',
|
|
365
|
+
'money': 'decimal',
|
|
366
|
+
'smallmoney': 'decimal',
|
|
367
|
+
'float': 'float',
|
|
368
|
+
'real': 'float',
|
|
369
|
+
'bit': 'boolean',
|
|
370
|
+
// String types
|
|
371
|
+
'char': 'text',
|
|
372
|
+
'varchar': 'text',
|
|
373
|
+
'text': 'text',
|
|
374
|
+
'nchar': 'text',
|
|
375
|
+
'nvarchar': 'text',
|
|
376
|
+
'ntext': 'text',
|
|
377
|
+
// Date/time types
|
|
378
|
+
'date': 'date',
|
|
379
|
+
'time': 'time',
|
|
380
|
+
'datetime': 'timestamp',
|
|
381
|
+
'datetime2': 'timestamp',
|
|
382
|
+
'smalldatetime': 'timestamp',
|
|
383
|
+
'datetimeoffset': 'timestamptz',
|
|
384
|
+
// Binary types
|
|
385
|
+
'binary': 'text',
|
|
386
|
+
'varbinary': 'text',
|
|
387
|
+
'image': 'text',
|
|
388
|
+
// Special types
|
|
389
|
+
'uniqueidentifier': 'text',
|
|
390
|
+
'xml': 'text',
|
|
391
|
+
'sql_variant': 'text',
|
|
392
|
+
'hierarchyid': 'text',
|
|
393
|
+
'geometry': 'text',
|
|
394
|
+
'geography': 'text',
|
|
395
|
+
'timestamp': 'text',
|
|
396
|
+
'rowversion': 'text'
|
|
397
|
+
};
|
|
398
|
+
return typeMap[synapseType.toLowerCase()] ?? 'unknown';
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Override escapeIdentifier for SQL Server bracket notation
|
|
402
|
+
*/
|
|
403
|
+
escapeIdentifier(identifier) {
|
|
404
|
+
// Only allow alphanumeric, underscore, and dot (for schema.table)
|
|
405
|
+
if (!/^[a-zA-Z0-9_.]+$/.test(identifier)) {
|
|
406
|
+
throw new Error(`Invalid identifier: ${identifier}`);
|
|
407
|
+
}
|
|
408
|
+
// Additional length check
|
|
409
|
+
if (identifier.length > 256) {
|
|
410
|
+
throw new Error('Identifier too long');
|
|
411
|
+
}
|
|
412
|
+
// Return with brackets for SQL Server
|
|
413
|
+
return `[${identifier}]`;
|
|
414
|
+
}
|
|
415
|
+
// ==============================================
|
|
416
|
+
// Legacy API compatibility methods
|
|
417
|
+
// ==============================================
|
|
418
|
+
/**
|
|
419
|
+
* Legacy connect method for backward compatibility
|
|
420
|
+
* @deprecated Use constructor with ConnectorConfig instead
|
|
421
|
+
*/
|
|
422
|
+
async connectLegacy(credentials) {
|
|
423
|
+
console.warn('Warning: connectLegacy is deprecated. Use constructor with ConnectorConfig instead.');
|
|
424
|
+
// Convert legacy credentials to new format
|
|
425
|
+
const config = {
|
|
426
|
+
host: credentials.host ?? '',
|
|
427
|
+
port: credentials.port ?? 1433,
|
|
428
|
+
database: credentials.database ?? '',
|
|
429
|
+
username: credentials.username ?? '',
|
|
430
|
+
password: credentials.password ?? '',
|
|
431
|
+
ssl: credentials.sslMode !== 'disable'
|
|
432
|
+
};
|
|
433
|
+
// Validate and reconnect
|
|
434
|
+
validateConnectorConfig(config);
|
|
435
|
+
this.config = { ...this.config, ...config };
|
|
436
|
+
await this.connect();
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Legacy test connection method for backward compatibility
|
|
440
|
+
* @deprecated Use testConnection() instead
|
|
441
|
+
*/
|
|
442
|
+
async testConnectionLegacy() {
|
|
443
|
+
console.warn('Warning: testConnectionLegacy is deprecated. Use testConnection() instead.');
|
|
444
|
+
try {
|
|
445
|
+
const success = await this.testConnection();
|
|
446
|
+
if (success) {
|
|
447
|
+
// Get table count for legacy compatibility
|
|
448
|
+
const tables = await this.listTables();
|
|
449
|
+
return {
|
|
450
|
+
success: true,
|
|
451
|
+
tableCount: tables.length
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
return {
|
|
456
|
+
success: false,
|
|
457
|
+
error: 'Connection test failed'
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
return {
|
|
463
|
+
success: false,
|
|
464
|
+
error: ErrorHandler.getUserMessage(error)
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Legacy get table metadata method for backward compatibility
|
|
470
|
+
* @deprecated Use getRowCount() and getMaxTimestamp() instead
|
|
471
|
+
*/
|
|
472
|
+
async getTableMetadata(tableName, timestampColumn = 'updated_at') {
|
|
473
|
+
console.warn('Warning: getTableMetadata is deprecated. Use getRowCount() and getMaxTimestamp() instead.');
|
|
474
|
+
try {
|
|
475
|
+
const rowCount = await this.getRowCount(tableName);
|
|
476
|
+
const lastUpdate = await this.getMaxTimestamp(tableName, timestampColumn);
|
|
477
|
+
return {
|
|
478
|
+
rowCount,
|
|
479
|
+
lastUpdate: lastUpdate ?? undefined
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
throw new QueryError('Failed to get table metadata', 'metadata_query', tableName, error instanceof Error ? error : undefined);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Legacy query method for backward compatibility
|
|
488
|
+
* @deprecated Direct SQL queries are not allowed for security reasons
|
|
489
|
+
*/
|
|
490
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- deprecated stub that always throws
|
|
491
|
+
async query(_sql) {
|
|
492
|
+
throw new Error('Direct SQL queries are not allowed for security reasons. Use specific methods like getRowCount(), getMaxTimestamp(), etc.');
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
//# sourceMappingURL=synapse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synapse.js","sourceRoot":"","sources":["../../src/connectors/synapse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAuB,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5E,OAAO,EACL,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACzC,IAAI,GAAgC,IAAI,CAAC;IACzC,SAAS,GAAG,KAAK,CAAC;IAE1B;;;OAGG;IACH,YAAY,MAAuB,EAAE,cAAwC;QAC3E,2CAA2C;QAC3C,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAChC,CAAC;IAED;;OA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AAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,wBAAwB;iBAChC,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC;aAC1C,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,gBAAgB,CACpB,SAAiB,EACjB,eAAe,GAAG,YAAY;QAE9B,OAAO,CAAC,IAAI,CAAC,2FAA2F,CAAC,CAAC;QAE1G,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YACnD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YAE1E,OAAO;gBACL,QAAQ;gBACR,UAAU,EAAE,UAAU,IAAI,SAAS;aACpC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,UAAU,CAClB,8BAA8B,EAC9B,gBAAgB,EAChB,SAAS,EACT,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,kGAAkG;IAClG,KAAK,CAAC,KAAK,CAAc,IAAY;QACnC,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAC;IACJ,CAAC;CACF"}
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection and schema exports
|
|
3
|
+
*
|
|
4
|
+
* Creates a Drizzle ORM connection to the FreshGuard metadata database
|
|
5
|
+
* (PostgreSQL). Used internally for storing check executions, alert logs,
|
|
6
|
+
* and monitoring rules.
|
|
7
|
+
*
|
|
8
|
+
* @module @freshguard/freshguard-core/db
|
|
9
|
+
*/
|
|
1
10
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
11
|
import * as schema from './schema.js';
|
|
3
12
|
export { schema };
|
|
13
|
+
/**
|
|
14
|
+
* Create a Drizzle ORM database connection to a PostgreSQL instance.
|
|
15
|
+
*
|
|
16
|
+
* @param connectionString - PostgreSQL connection string (e.g. `postgresql://user:pass@host:5432/db`)
|
|
17
|
+
* @returns Drizzle database instance with the FreshGuard schema loaded
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { createDatabase } from '@freshguard/freshguard-core';
|
|
22
|
+
*
|
|
23
|
+
* const db = createDatabase(process.env.DATABASE_URL!);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
4
26
|
export declare function createDatabase(connectionString: string): ReturnType<typeof drizzle>;
|
|
27
|
+
/**
|
|
28
|
+
* Type-safe database instance
|
|
29
|
+
*/
|
|
5
30
|
export type Database = ReturnType<typeof createDatabase>;
|
|
6
31
|
export { runMigrations, getCurrentVersion, needsMigrations, initializeDatabase, getMigrationStatus } from './migrate.js';
|
|
7
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/db/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,gBAAgB,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAGnF;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAGzD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,cAAc,CAAC"}
|
package/dist/db/index.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection and schema exports
|
|
3
|
+
*
|
|
4
|
+
* Creates a Drizzle ORM connection to the FreshGuard metadata database
|
|
5
|
+
* (PostgreSQL). Used internally for storing check executions, alert logs,
|
|
6
|
+
* and monitoring rules.
|
|
7
|
+
*
|
|
8
|
+
* @module @freshguard/freshguard-core/db
|
|
9
|
+
*/
|
|
1
10
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
11
|
import postgres from 'postgres';
|
|
3
12
|
import * as schema from './schema.js';
|
|
4
13
|
export { schema };
|
|
14
|
+
/**
|
|
15
|
+
* Create a Drizzle ORM database connection to a PostgreSQL instance.
|
|
16
|
+
*
|
|
17
|
+
* @param connectionString - PostgreSQL connection string (e.g. `postgresql://user:pass@host:5432/db`)
|
|
18
|
+
* @returns Drizzle database instance with the FreshGuard schema loaded
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createDatabase } from '@freshguard/freshguard-core';
|
|
23
|
+
*
|
|
24
|
+
* const db = createDatabase(process.env.DATABASE_URL!);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
5
27
|
export function createDatabase(connectionString) {
|
|
6
28
|
const client = postgres(connectionString);
|
|
7
29
|
return drizzle(client, { schema });
|
|
8
30
|
}
|
|
31
|
+
// Export migration utilities
|
|
9
32
|
export { runMigrations, getCurrentVersion, needsMigrations, initializeDatabase, getMigrationStatus } from './migrate.js';
|
|
10
33
|
//# sourceMappingURL=index.js.map
|
package/dist/db/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,gBAAwB;IACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC;AAOD,6BAA6B;AAC7B,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,cAAc,CAAC"}
|
package/dist/db/migrate.d.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database migration utilities for FreshGuard Core
|
|
3
|
+
* @module @freshguard/freshguard-core/db/migrate
|
|
4
|
+
*/
|
|
1
5
|
import type { Database } from './index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Run all pending migrations
|
|
8
|
+
*
|
|
9
|
+
* @param db - Database connection
|
|
10
|
+
* @param targetVersion - Optional target version to migrate to
|
|
11
|
+
*/
|
|
2
12
|
export declare function runMigrations(db: Database, targetVersion?: number): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Get current schema version
|
|
15
|
+
*/
|
|
3
16
|
export declare function getCurrentVersion(db: Database): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if database needs migrations
|
|
19
|
+
*/
|
|
4
20
|
export declare function needsMigrations(db: Database): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Initialize a fresh database
|
|
23
|
+
* This is equivalent to running all migrations
|
|
24
|
+
*/
|
|
5
25
|
export declare function initializeDatabase(db: Database): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get migration status
|
|
28
|
+
*/
|
|
6
29
|
export declare function getMigrationStatus(db: Database): Promise<{
|
|
7
30
|
current: number;
|
|
8
31
|
latest: number;
|
package/dist/db/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/db/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/db/migrate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmF3C;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,QAAQ,EACZ,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAWrE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpE;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC,CAYD"}
|