noormme 1.1.0 → 1.2.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 +84 -65
- package/dist/cjs/agentic/ActionJournal.js +13 -9
- package/dist/cjs/agentic/CapabilityManager.js +35 -21
- package/dist/cjs/agentic/CognitiveRepository.js +19 -9
- package/dist/cjs/agentic/ContextBuffer.js +24 -12
- package/dist/cjs/agentic/Cortex.js +11 -4
- package/dist/cjs/agentic/EpisodicMemory.js +7 -5
- package/dist/cjs/agentic/PersonaManager.js +16 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +31 -12
- package/dist/cjs/agentic/ResourceMonitor.js +4 -4
- package/dist/cjs/agentic/SessionCompressor.js +22 -14
- package/dist/cjs/agentic/SessionManager.js +36 -18
- package/dist/cjs/agentic/VectorIndexer.js +22 -18
- package/dist/cjs/agentic/improvement/AblationEngine.js +22 -15
- package/dist/cjs/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/cjs/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/cjs/agentic/improvement/CortexJanitor.js +30 -9
- package/dist/cjs/agentic/improvement/CuriosityEngine.js +27 -23
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +4 -4
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +16 -6
- package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/cjs/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/cjs/agentic/improvement/GovernanceManager.js +19 -11
- package/dist/cjs/agentic/improvement/HiveLink.js +22 -15
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +48 -32
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +40 -17
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +28 -22
- package/dist/cjs/agentic/improvement/RuleEngine.js +22 -17
- package/dist/cjs/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/cjs/agentic/improvement/SkillSynthesizer.js +42 -27
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +120 -55
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/cjs/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +5 -2
- package/dist/cjs/cache/cache-manager.js +7 -4
- package/dist/cjs/cli/commands/analyze.js +5 -4
- package/dist/cjs/cli/commands/generate.js +81 -44
- package/dist/cjs/cli/commands/init.js +7 -3
- package/dist/cjs/cli/commands/inspect.js +139 -36
- package/dist/cjs/cli/commands/migrate.js +5 -4
- package/dist/cjs/cli/commands/optimize.js +4 -4
- package/dist/cjs/cli/commands/status.js +9 -7
- package/dist/cjs/cli/commands/watch.js +7 -6
- package/dist/cjs/cli/index.js +2 -2
- package/dist/cjs/cli/ui/spinner.d.ts +15 -0
- package/dist/cjs/cli/ui/spinner.js +76 -0
- package/dist/cjs/dialect/database-introspector.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/cjs/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/cjs/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/cjs/edge-runtime/edge-config.js +21 -19
- package/dist/cjs/errors/NoormError.js +22 -20
- package/dist/cjs/helpers/agent-schema.js +2 -0
- package/dist/cjs/helpers/postgresql.js +7 -4
- package/dist/cjs/helpers/schema-evolution.js +31 -6
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/logging/logger.js +8 -4
- package/dist/cjs/migration/data_migrator.js +12 -11
- package/dist/cjs/migration/database_migration_manager.js +17 -13
- package/dist/cjs/migration/schema_differ.js +22 -14
- package/dist/cjs/migration/schema_introspector.js +8 -8
- package/dist/cjs/migration/type_mapper.js +68 -67
- package/dist/cjs/noormme.js +52 -37
- package/dist/cjs/performance/index.js +5 -5
- package/dist/cjs/performance/query-optimizer.js +26 -21
- package/dist/cjs/performance/services/cache-service.js +26 -16
- package/dist/cjs/performance/services/connection-factory.js +28 -23
- package/dist/cjs/performance/services/metrics-collector.js +41 -36
- package/dist/cjs/performance/utils/query-parser.js +15 -16
- package/dist/cjs/relationships/relationship-engine.js +10 -8
- package/dist/cjs/repository/repository-factory.js +97 -38
- package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/cjs/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/cjs/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/cjs/schema/core/discovery/view-discovery.js +5 -4
- package/dist/cjs/schema/core/factories/discovery-factory.js +4 -4
- package/dist/cjs/schema/core/utils/name-generator.js +14 -5
- package/dist/cjs/schema/core/utils/type-mapper.js +24 -24
- package/dist/cjs/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/cjs/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/cjs/schema/test/basic-schema-test.js +11 -9
- package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/cjs/schema/test/discovery-factory.test.js +2 -2
- package/dist/cjs/schema/test/error-handling.test.js +8 -6
- package/dist/cjs/schema/test/integration.test.js +24 -18
- package/dist/cjs/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/cjs/schema/test/simple-schema-test.js +9 -9
- package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/cjs/schema/test/test-runner.js +3 -3
- package/dist/cjs/sqlite-migration/index.d.ts +2 -2
- package/dist/cjs/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/cjs/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/cjs/testing/test-utils.js +36 -34
- package/dist/cjs/types/index.d.ts +5 -2
- package/dist/cjs/types/index.js +6 -3
- package/dist/cjs/types/type-generator.js +46 -42
- package/dist/cjs/util/safe-sql-helpers.js +1 -1
- package/dist/cjs/util/security-validator.js +20 -9
- package/dist/cjs/utils/errorHelpers.js +20 -10
- package/dist/cjs/watch/schema-watcher.js +22 -23
- package/dist/esm/agentic/ActionJournal.js +13 -9
- package/dist/esm/agentic/CapabilityManager.js +35 -21
- package/dist/esm/agentic/CognitiveRepository.js +19 -9
- package/dist/esm/agentic/ContextBuffer.js +24 -12
- package/dist/esm/agentic/Cortex.js +11 -4
- package/dist/esm/agentic/EpisodicMemory.js +7 -5
- package/dist/esm/agentic/PersonaManager.js +16 -8
- package/dist/esm/agentic/PolicyEnforcer.js +31 -12
- package/dist/esm/agentic/ResourceMonitor.js +4 -4
- package/dist/esm/agentic/SessionCompressor.js +22 -14
- package/dist/esm/agentic/SessionManager.js +36 -18
- package/dist/esm/agentic/VectorIndexer.js +22 -18
- package/dist/esm/agentic/improvement/AblationEngine.js +22 -15
- package/dist/esm/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/esm/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/esm/agentic/improvement/CortexJanitor.js +30 -9
- package/dist/esm/agentic/improvement/CuriosityEngine.js +27 -23
- package/dist/esm/agentic/improvement/EvolutionRitual.js +4 -4
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +16 -6
- package/dist/esm/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/esm/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/esm/agentic/improvement/GovernanceManager.js +19 -11
- package/dist/esm/agentic/improvement/HiveLink.js +22 -15
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +48 -32
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +40 -17
- package/dist/esm/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +28 -22
- package/dist/esm/agentic/improvement/RuleEngine.js +22 -17
- package/dist/esm/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/esm/agentic/improvement/SkillSynthesizer.js +42 -27
- package/dist/esm/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/esm/agentic/improvement/StrategicPlanner.js +120 -55
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/esm/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/esm/agentic/telemetry/ResearchAlchemist.js +5 -2
- package/dist/esm/cache/cache-manager.js +7 -4
- package/dist/esm/cli/commands/analyze.js +5 -4
- package/dist/esm/cli/commands/generate.js +82 -45
- package/dist/esm/cli/commands/init.js +8 -4
- package/dist/esm/cli/commands/inspect.js +140 -37
- package/dist/esm/cli/commands/migrate.js +5 -4
- package/dist/esm/cli/commands/optimize.js +4 -4
- package/dist/esm/cli/commands/status.js +9 -7
- package/dist/esm/cli/commands/watch.js +7 -6
- package/dist/esm/cli/index.js +2 -2
- package/dist/esm/cli/ui/spinner.d.ts +15 -0
- package/dist/esm/cli/ui/spinner.js +70 -0
- package/dist/esm/dialect/database-introspector.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/esm/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/esm/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/esm/dynamic/dynamic.js +1 -1
- package/dist/esm/edge-runtime/edge-config.js +21 -19
- package/dist/esm/errors/NoormError.js +22 -20
- package/dist/esm/helpers/agent-schema.js +2 -0
- package/dist/esm/helpers/postgresql.js +7 -4
- package/dist/esm/helpers/schema-evolution.js +31 -6
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/logging/logger.js +8 -4
- package/dist/esm/migration/data_migrator.js +12 -11
- package/dist/esm/migration/database_migration_manager.js +18 -14
- package/dist/esm/migration/schema_differ.js +22 -14
- package/dist/esm/migration/schema_introspector.js +8 -8
- package/dist/esm/migration/type_mapper.js +68 -67
- package/dist/esm/noormme.js +52 -37
- package/dist/esm/performance/index.js +5 -5
- package/dist/esm/performance/query-optimizer.js +26 -21
- package/dist/esm/performance/services/cache-service.js +26 -16
- package/dist/esm/performance/services/connection-factory.js +28 -23
- package/dist/esm/performance/services/metrics-collector.js +41 -36
- package/dist/esm/performance/utils/query-parser.js +15 -16
- package/dist/esm/raw-builder/sql.js +1 -1
- package/dist/esm/relationships/relationship-engine.js +10 -8
- package/dist/esm/repository/repository-factory.js +98 -39
- package/dist/esm/schema/builders/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/builders/create-index-builder.js +2 -2
- package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/esm/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/esm/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/esm/schema/core/discovery/view-discovery.js +5 -4
- package/dist/esm/schema/core/factories/discovery-factory.js +4 -4
- package/dist/esm/schema/core/utils/name-generator.js +14 -5
- package/dist/esm/schema/core/utils/type-mapper.js +24 -24
- package/dist/esm/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/esm/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/esm/schema/test/basic-schema-test.js +11 -9
- package/dist/esm/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/esm/schema/test/discovery-factory.test.js +2 -2
- package/dist/esm/schema/test/error-handling.test.js +8 -6
- package/dist/esm/schema/test/integration.test.js +24 -18
- package/dist/esm/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/esm/schema/test/simple-schema-test.js +9 -9
- package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/esm/schema/test/test-runner.js +3 -3
- package/dist/esm/sqlite-migration/index.d.ts +2 -2
- package/dist/esm/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/esm/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/esm/testing/test-utils.js +36 -34
- package/dist/esm/types/index.d.ts +5 -2
- package/dist/esm/types/index.js +6 -3
- package/dist/esm/types/type-generator.js +46 -42
- package/dist/esm/util/safe-sql-helpers.js +1 -1
- package/dist/esm/util/security-validator.js +20 -9
- package/dist/esm/utils/errorHelpers.js +21 -11
- package/dist/esm/watch/schema-watcher.js +22 -23
- package/package.json +40 -44
|
@@ -69,7 +69,7 @@ class SqliteConnection {
|
|
|
69
69
|
executeQuery(compiledQuery) {
|
|
70
70
|
const { sql, parameters } = compiledQuery;
|
|
71
71
|
// Convert parameters to SQLite-compatible types
|
|
72
|
-
const sqliteParameters = parameters.map(param => {
|
|
72
|
+
const sqliteParameters = parameters.map((param) => {
|
|
73
73
|
if (param === undefined) {
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
@@ -102,7 +102,7 @@ class SqliteConnection {
|
|
|
102
102
|
async *streamQuery(compiledQuery, _chunkSize) {
|
|
103
103
|
const { sql, parameters, query } = compiledQuery;
|
|
104
104
|
// Convert parameters to SQLite-compatible types
|
|
105
|
-
const sqliteParameters = parameters.map(param => {
|
|
105
|
+
const sqliteParameters = parameters.map((param) => {
|
|
106
106
|
if (param === undefined) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
@@ -63,12 +63,13 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
63
63
|
name: col.name,
|
|
64
64
|
type: col.type,
|
|
65
65
|
nullable: !col.notnull,
|
|
66
|
-
isAutoIncrement: autoIncrementInfo.isAutoIncrement &&
|
|
66
|
+
isAutoIncrement: autoIncrementInfo.isAutoIncrement &&
|
|
67
|
+
col.name === autoIncrementInfo.columnName,
|
|
67
68
|
defaultValue: col.dflt_value,
|
|
68
|
-
isPrimaryKey: col.pk > 0
|
|
69
|
+
isPrimaryKey: col.pk > 0,
|
|
69
70
|
})),
|
|
70
71
|
indexes: [],
|
|
71
|
-
foreignKeys: []
|
|
72
|
+
foreignKeys: [],
|
|
72
73
|
};
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -85,7 +86,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
85
86
|
return {
|
|
86
87
|
isAutoIncrement: true,
|
|
87
88
|
columnName: autoIncrementMatch[1].replace(/["`]/g, ''),
|
|
88
|
-
type: 'autoincrement'
|
|
89
|
+
type: 'autoincrement',
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
// Method 2: Check for INTEGER PRIMARY KEY (implicit auto-increment)
|
|
@@ -94,7 +95,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
94
95
|
return {
|
|
95
96
|
isAutoIncrement: true,
|
|
96
97
|
columnName: integerPkMatch[1].replace(/["`]/g, ''),
|
|
97
|
-
type: 'rowid'
|
|
98
|
+
type: 'rowid',
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
// Method 3: Check columns for INTEGER PRIMARY KEY
|
|
@@ -105,7 +106,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
105
106
|
return {
|
|
106
107
|
isAutoIncrement: true,
|
|
107
108
|
columnName: pkCol.name,
|
|
108
|
-
type: 'rowid'
|
|
109
|
+
type: 'rowid',
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
}
|
|
@@ -115,7 +116,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
115
116
|
return {
|
|
116
117
|
isAutoIncrement: true,
|
|
117
118
|
columnName: 'rowid',
|
|
118
|
-
type: 'rowid'
|
|
119
|
+
type: 'rowid',
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
return { isAutoIncrement: false, columnName: null, type: 'none' };
|
|
@@ -134,7 +135,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
134
135
|
if (columnsMatch) {
|
|
135
136
|
const columns = columnsMatch[1]
|
|
136
137
|
.split(',')
|
|
137
|
-
.map(col => col.trim().replace(/["`]/g, ''));
|
|
138
|
+
.map((col) => col.trim().replace(/["`]/g, ''));
|
|
138
139
|
constraints.push(...columns);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
@@ -170,7 +171,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
170
171
|
nullable: !col.notnull,
|
|
171
172
|
defaultValue: col.dflt_value,
|
|
172
173
|
isPrimaryKey: !!col.pk,
|
|
173
|
-
isAutoIncrement: col.type.toLowerCase().includes('integer') && col.pk
|
|
174
|
+
isAutoIncrement: col.type.toLowerCase().includes('integer') && col.pk,
|
|
174
175
|
}));
|
|
175
176
|
}
|
|
176
177
|
catch (error) {
|
|
@@ -191,7 +192,9 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
191
192
|
indexes.push({
|
|
192
193
|
name: idx.name,
|
|
193
194
|
unique: !!idx.unique,
|
|
194
|
-
columns: info
|
|
195
|
+
columns: info
|
|
196
|
+
.sort((a, b) => a.seqno - b.seqno)
|
|
197
|
+
.map((c) => c.name),
|
|
195
198
|
});
|
|
196
199
|
}
|
|
197
200
|
catch (e) {
|
|
@@ -199,7 +202,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
199
202
|
indexes.push({
|
|
200
203
|
name: idx.name,
|
|
201
204
|
unique: !!idx.unique,
|
|
202
|
-
columns: []
|
|
205
|
+
columns: [],
|
|
203
206
|
});
|
|
204
207
|
}
|
|
205
208
|
}
|
|
@@ -219,7 +222,7 @@ class SqliteIntrospector extends database_introspector_js_1.DatabaseIntrospector
|
|
|
219
222
|
name: `fk_${tableName}_${fk.from}`,
|
|
220
223
|
column: fk.from,
|
|
221
224
|
referencedTable: fk.table,
|
|
222
|
-
referencedColumn: fk.to
|
|
225
|
+
referencedColumn: fk.to,
|
|
223
226
|
}));
|
|
224
227
|
}
|
|
225
228
|
catch (error) {
|
|
@@ -53,19 +53,19 @@ function getEdgeRuntimeConfig() {
|
|
|
53
53
|
return {
|
|
54
54
|
dialect: 'sqlite',
|
|
55
55
|
connection: {
|
|
56
|
-
database: ':memory:'
|
|
56
|
+
database: ':memory:',
|
|
57
57
|
},
|
|
58
58
|
optimization: {
|
|
59
59
|
enableWALMode: false, // WAL mode not supported in Edge Runtime
|
|
60
60
|
enableForeignKeys: true,
|
|
61
61
|
cacheSize: -2000, // 2MB cache (smaller for Edge Runtime)
|
|
62
62
|
synchronous: 'NORMAL',
|
|
63
|
-
tempStore: 'MEMORY' // Use memory for temporary storage
|
|
63
|
+
tempStore: 'MEMORY', // Use memory for temporary storage
|
|
64
64
|
},
|
|
65
65
|
logging: {
|
|
66
66
|
level: 'error', // Minimal logging for performance
|
|
67
|
-
enabled: false // Disable logging in Edge Runtime
|
|
68
|
-
}
|
|
67
|
+
enabled: false, // Disable logging in Edge Runtime
|
|
68
|
+
},
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -86,19 +86,19 @@ function getRuntimeConfig() {
|
|
|
86
86
|
return {
|
|
87
87
|
dialect: 'sqlite',
|
|
88
88
|
connection: {
|
|
89
|
-
database: process.env.DATABASE_URL || './app.db'
|
|
89
|
+
database: process.env.DATABASE_URL || './app.db',
|
|
90
90
|
},
|
|
91
91
|
optimization: {
|
|
92
92
|
enableWALMode: true,
|
|
93
93
|
enableForeignKeys: true,
|
|
94
94
|
cacheSize: -64000, // 64MB cache
|
|
95
95
|
synchronous: 'NORMAL',
|
|
96
|
-
tempStore: 'DEFAULT'
|
|
96
|
+
tempStore: 'DEFAULT',
|
|
97
97
|
},
|
|
98
98
|
logging: {
|
|
99
99
|
level: process.env.NODE_ENV === 'development' ? 'info' : 'error',
|
|
100
|
-
enabled: true
|
|
101
|
-
}
|
|
100
|
+
enabled: true,
|
|
101
|
+
},
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
@@ -192,15 +192,15 @@ function createEdgeMiddleware() {
|
|
|
192
192
|
return new Response(JSON.stringify({
|
|
193
193
|
status: 'healthy',
|
|
194
194
|
runtime: 'edge',
|
|
195
|
-
timestamp: new Date().toISOString()
|
|
195
|
+
timestamp: new Date().toISOString(),
|
|
196
196
|
}), {
|
|
197
|
-
headers: { 'Content-Type': 'application/json' }
|
|
197
|
+
headers: { 'Content-Type': 'application/json' },
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
if (pathname === '/api/users' && method === 'GET') {
|
|
201
201
|
const users = await edgeDB.read('users');
|
|
202
202
|
return new Response(JSON.stringify(users), {
|
|
203
|
-
headers: { 'Content-Type': 'application/json' }
|
|
203
|
+
headers: { 'Content-Type': 'application/json' },
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
if (pathname === '/api/users' && method === 'POST') {
|
|
@@ -208,11 +208,11 @@ function createEdgeMiddleware() {
|
|
|
208
208
|
const user = await edgeDB.write('users', data);
|
|
209
209
|
return new Response(JSON.stringify(user), {
|
|
210
210
|
status: 201,
|
|
211
|
-
headers: { 'Content-Type': 'application/json' }
|
|
211
|
+
headers: { 'Content-Type': 'application/json' },
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
return new Response('Not found', { status: 404 });
|
|
215
|
-
}
|
|
215
|
+
},
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
@@ -229,13 +229,15 @@ function createEdgeErrorHandler() {
|
|
|
229
229
|
// Return appropriate response
|
|
230
230
|
return new Response(JSON.stringify({
|
|
231
231
|
error: 'Internal Server Error',
|
|
232
|
-
message: process.env.NODE_ENV === 'development'
|
|
233
|
-
|
|
232
|
+
message: process.env.NODE_ENV === 'development'
|
|
233
|
+
? error.message
|
|
234
|
+
: 'Something went wrong',
|
|
235
|
+
timestamp: new Date().toISOString(),
|
|
234
236
|
}), {
|
|
235
237
|
status: 500,
|
|
236
|
-
headers: { 'Content-Type': 'application/json' }
|
|
238
|
+
headers: { 'Content-Type': 'application/json' },
|
|
237
239
|
});
|
|
238
|
-
}
|
|
240
|
+
},
|
|
239
241
|
};
|
|
240
242
|
}
|
|
241
243
|
/**
|
|
@@ -284,7 +286,7 @@ class EdgeRuntimeMonitor {
|
|
|
284
286
|
totalOperations,
|
|
285
287
|
metrics,
|
|
286
288
|
timestamp: new Date().toISOString(),
|
|
287
|
-
runtime: 'edge'
|
|
289
|
+
runtime: 'edge',
|
|
288
290
|
};
|
|
289
291
|
}
|
|
290
292
|
}
|
|
@@ -316,5 +318,5 @@ exports.EdgeRuntimeUtils = {
|
|
|
316
318
|
/**
|
|
317
319
|
* Create Edge Runtime monitor
|
|
318
320
|
*/
|
|
319
|
-
createMonitor: () => new EdgeRuntimeMonitor()
|
|
321
|
+
createMonitor: () => new EdgeRuntimeMonitor(),
|
|
320
322
|
};
|
|
@@ -29,7 +29,8 @@ class NoormError extends Error {
|
|
|
29
29
|
if (this.context.suggestion) {
|
|
30
30
|
formatted += `\n Suggestion: ${this.context.suggestion}`;
|
|
31
31
|
}
|
|
32
|
-
if (this.context.availableOptions &&
|
|
32
|
+
if (this.context.availableOptions &&
|
|
33
|
+
this.context.availableOptions.length > 0) {
|
|
33
34
|
formatted += `\n Available options: ${this.context.availableOptions.join(', ')}`;
|
|
34
35
|
}
|
|
35
36
|
if (this.context.originalError) {
|
|
@@ -45,7 +46,7 @@ class NoormError extends Error {
|
|
|
45
46
|
name: this.name,
|
|
46
47
|
message: this.message,
|
|
47
48
|
context: this.context,
|
|
48
|
-
stack: this.stack
|
|
49
|
+
stack: this.stack,
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -64,7 +65,7 @@ class TableNotFoundError extends NoormError {
|
|
|
64
65
|
suggestion: availableTables.length > 0
|
|
65
66
|
? `Available tables: ${availableTables.join(', ')}`
|
|
66
67
|
: 'Check your table name or run schema discovery',
|
|
67
|
-
availableOptions: availableTables
|
|
68
|
+
availableOptions: availableTables,
|
|
68
69
|
});
|
|
69
70
|
this.name = 'TableNotFoundError';
|
|
70
71
|
}
|
|
@@ -73,7 +74,7 @@ exports.TableNotFoundError = TableNotFoundError;
|
|
|
73
74
|
class ColumnNotFoundError extends NoormError {
|
|
74
75
|
constructor(columnName, tableName, availableColumns = []) {
|
|
75
76
|
// Find similar column names for better suggestions
|
|
76
|
-
const similarColumns = availableColumns.filter(col => col.toLowerCase().includes(columnName.toLowerCase()) ||
|
|
77
|
+
const similarColumns = availableColumns.filter((col) => col.toLowerCase().includes(columnName.toLowerCase()) ||
|
|
77
78
|
columnName.toLowerCase().includes(col.toLowerCase()) ||
|
|
78
79
|
ColumnNotFoundError.calculateSimilarity(col, columnName) > 0.6);
|
|
79
80
|
let suggestion = 'Check your column name or run schema discovery';
|
|
@@ -87,7 +88,7 @@ class ColumnNotFoundError extends NoormError {
|
|
|
87
88
|
table: tableName,
|
|
88
89
|
operation: 'column_lookup',
|
|
89
90
|
suggestion: suggestion,
|
|
90
|
-
availableOptions: availableColumns
|
|
91
|
+
availableOptions: availableColumns,
|
|
91
92
|
});
|
|
92
93
|
this.name = 'ColumnNotFoundError';
|
|
93
94
|
}
|
|
@@ -126,7 +127,7 @@ class ConnectionError extends NoormError {
|
|
|
126
127
|
super(message, {
|
|
127
128
|
operation: 'connection',
|
|
128
129
|
suggestion: 'Check your database connection settings and ensure the database server is running',
|
|
129
|
-
originalError
|
|
130
|
+
originalError,
|
|
130
131
|
});
|
|
131
132
|
this.name = 'ConnectionError';
|
|
132
133
|
}
|
|
@@ -137,7 +138,7 @@ class DatabaseInitializationError extends NoormError {
|
|
|
137
138
|
super(`Failed to initialize database at ${databasePath}: ${originalError.message}`, {
|
|
138
139
|
operation: 'initialization',
|
|
139
140
|
suggestion: 'Check database permissions, path validity, and connection settings',
|
|
140
|
-
originalError
|
|
141
|
+
originalError,
|
|
141
142
|
});
|
|
142
143
|
this.name = 'DatabaseInitializationError';
|
|
143
144
|
}
|
|
@@ -148,7 +149,7 @@ class ValidationError extends NoormError {
|
|
|
148
149
|
super(message, {
|
|
149
150
|
operation: 'validation',
|
|
150
151
|
suggestion: 'Check your input data and ensure it matches the expected schema',
|
|
151
|
-
availableOptions: validationIssues
|
|
152
|
+
availableOptions: validationIssues,
|
|
152
153
|
});
|
|
153
154
|
this.name = 'ValidationError';
|
|
154
155
|
}
|
|
@@ -162,7 +163,7 @@ class RelationshipNotFoundError extends NoormError {
|
|
|
162
163
|
suggestion: availableRelationships.length > 0
|
|
163
164
|
? `Available relationships: ${availableRelationships.join(', ')}`
|
|
164
165
|
: 'No relationships defined for this table',
|
|
165
|
-
availableOptions: availableRelationships
|
|
166
|
+
availableOptions: availableRelationships,
|
|
166
167
|
});
|
|
167
168
|
this.name = 'RelationshipNotFoundError';
|
|
168
169
|
}
|
|
@@ -174,7 +175,7 @@ class QueryExecutionError extends NoormError {
|
|
|
174
175
|
operation: context?.operation || 'query_execution',
|
|
175
176
|
table: context?.table,
|
|
176
177
|
suggestion: QueryExecutionError.getQuerySuggestion(query, originalError),
|
|
177
|
-
originalError
|
|
178
|
+
originalError,
|
|
178
179
|
});
|
|
179
180
|
this.name = 'QueryExecutionError';
|
|
180
181
|
}
|
|
@@ -205,7 +206,7 @@ class SchemaDiscoveryError extends NoormError {
|
|
|
205
206
|
table: tableName,
|
|
206
207
|
operation: 'schema_discovery',
|
|
207
208
|
suggestion: 'Check table permissions, table name validity, or database connection',
|
|
208
|
-
originalError
|
|
209
|
+
originalError,
|
|
209
210
|
});
|
|
210
211
|
this.name = 'SchemaDiscoveryError';
|
|
211
212
|
}
|
|
@@ -216,7 +217,7 @@ class MigrationError extends NoormError {
|
|
|
216
217
|
super(`Migration '${migrationName}' failed${context?.step ? ` at step: ${context.step}` : ''}: ${originalError.message}`, {
|
|
217
218
|
operation: 'migration',
|
|
218
219
|
suggestion: 'Check migration SQL syntax, database permissions, or rollback the migration',
|
|
219
|
-
originalError
|
|
220
|
+
originalError,
|
|
220
221
|
});
|
|
221
222
|
this.name = 'MigrationError';
|
|
222
223
|
}
|
|
@@ -228,7 +229,7 @@ class TypeGenerationError extends NoormError {
|
|
|
228
229
|
table: tableName,
|
|
229
230
|
operation: 'type_generation',
|
|
230
231
|
suggestion: 'Check table schema, column types, or custom type mappings configuration',
|
|
231
|
-
originalError
|
|
232
|
+
originalError,
|
|
232
233
|
});
|
|
233
234
|
this.name = 'TypeGenerationError';
|
|
234
235
|
}
|
|
@@ -240,24 +241,25 @@ exports.TypeGenerationError = TypeGenerationError;
|
|
|
240
241
|
function findSimilarColumns(columns, target) {
|
|
241
242
|
const lowerTarget = target.toLowerCase();
|
|
242
243
|
// First, try exact case-insensitive match
|
|
243
|
-
const exactMatch = columns.find(col => col.toLowerCase() === lowerTarget);
|
|
244
|
+
const exactMatch = columns.find((col) => col.toLowerCase() === lowerTarget);
|
|
244
245
|
if (exactMatch)
|
|
245
246
|
return [exactMatch];
|
|
246
247
|
// Then try substring matches
|
|
247
|
-
const substringMatches = columns.filter(col => col.toLowerCase().includes(lowerTarget) ||
|
|
248
|
+
const substringMatches = columns.filter((col) => col.toLowerCase().includes(lowerTarget) ||
|
|
249
|
+
lowerTarget.includes(col.toLowerCase()));
|
|
248
250
|
if (substringMatches.length > 0) {
|
|
249
251
|
return substringMatches.slice(0, 3); // Return up to 3 matches
|
|
250
252
|
}
|
|
251
253
|
// Finally, try simple Levenshtein-like similarity
|
|
252
|
-
const similarities = columns.map(col => ({
|
|
254
|
+
const similarities = columns.map((col) => ({
|
|
253
255
|
name: col,
|
|
254
|
-
score: calculateSimilarity(lowerTarget, col.toLowerCase())
|
|
256
|
+
score: calculateSimilarity(lowerTarget, col.toLowerCase()),
|
|
255
257
|
}));
|
|
256
258
|
return similarities
|
|
257
|
-
.filter(s => s.score > 0.5) // Only return if similarity > 50%
|
|
259
|
+
.filter((s) => s.score > 0.5) // Only return if similarity > 50%
|
|
258
260
|
.sort((a, b) => b.score - a.score)
|
|
259
261
|
.slice(0, 3)
|
|
260
|
-
.map(s => s.name);
|
|
262
|
+
.map((s) => s.name);
|
|
261
263
|
}
|
|
262
264
|
/**
|
|
263
265
|
* Simple similarity calculation (Dice coefficient)
|
|
@@ -267,7 +269,7 @@ function calculateSimilarity(str1, str2) {
|
|
|
267
269
|
return 1;
|
|
268
270
|
const bigrams1 = getBigrams(str1);
|
|
269
271
|
const bigrams2 = getBigrams(str2);
|
|
270
|
-
const intersection = bigrams1.filter(bigram => bigrams2.includes(bigram));
|
|
272
|
+
const intersection = bigrams1.filter((bigram) => bigrams2.includes(bigram));
|
|
271
273
|
return (2 * intersection.length) / (bigrams1.length + bigrams2.length);
|
|
272
274
|
}
|
|
273
275
|
function getBigrams(str) {
|
|
@@ -103,6 +103,7 @@ class AgentSchemaHelper {
|
|
|
103
103
|
.addColumn('fact', 'text', (col) => col.notNull())
|
|
104
104
|
.addColumn('confidence', 'real', (col) => col.notNull().defaultTo(1.0))
|
|
105
105
|
.addColumn('source_session_id', 'integer', (col) => col.references(`${sessionsTable}.id`).onDelete('set null'))
|
|
106
|
+
.addColumn('status', 'text', (col) => col.notNull().defaultTo('proposed'))
|
|
106
107
|
.addColumn('tags', 'text')
|
|
107
108
|
.addColumn('metadata', 'text')
|
|
108
109
|
.addColumn('created_at', 'timestamp', (col) => col.notNull())
|
|
@@ -227,6 +228,7 @@ class AgentSchemaHelper {
|
|
|
227
228
|
.addColumn('last_run', 'timestamp')
|
|
228
229
|
.addColumn('next_run', 'timestamp')
|
|
229
230
|
.addColumn('status', 'text', (col) => col.notNull().defaultTo('pending'))
|
|
231
|
+
.addColumn('locked_until', 'timestamp')
|
|
230
232
|
.addColumn('metadata', 'text')
|
|
231
233
|
.execute();
|
|
232
234
|
// 16. Rules Table
|
|
@@ -57,7 +57,8 @@ function createPostgresNoormme(poolConfig) {
|
|
|
57
57
|
const database = typeof poolConfig.database === 'string' ? poolConfig.database : '';
|
|
58
58
|
const user = typeof poolConfig.user === 'string' ? poolConfig.user : undefined;
|
|
59
59
|
const password = typeof poolConfig.password === 'string' ? poolConfig.password : undefined;
|
|
60
|
-
const ssl = typeof poolConfig.ssl === 'boolean' ||
|
|
60
|
+
const ssl = typeof poolConfig.ssl === 'boolean' ||
|
|
61
|
+
(poolConfig.ssl && typeof poolConfig.ssl === 'object')
|
|
61
62
|
? poolConfig.ssl
|
|
62
63
|
: undefined;
|
|
63
64
|
const config = {
|
|
@@ -72,9 +73,11 @@ function createPostgresNoormme(poolConfig) {
|
|
|
72
73
|
pool: {
|
|
73
74
|
max: typeof poolConfig.max === 'number' ? poolConfig.max : undefined,
|
|
74
75
|
min: typeof poolConfig.min === 'number' ? poolConfig.min : undefined,
|
|
75
|
-
idleTimeoutMillis: typeof poolConfig.idleTimeoutMillis === 'number'
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
idleTimeoutMillis: typeof poolConfig.idleTimeoutMillis === 'number'
|
|
77
|
+
? poolConfig.idleTimeoutMillis
|
|
78
|
+
: undefined,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
78
81
|
};
|
|
79
82
|
return new noormme_js_1.NOORMME(config);
|
|
80
83
|
}
|
|
@@ -18,7 +18,7 @@ class SchemaEvolutionHelper {
|
|
|
18
18
|
async getStructuralOverview() {
|
|
19
19
|
const introspector = this.db.introspection;
|
|
20
20
|
const tables = await introspector.getTables();
|
|
21
|
-
let overview =
|
|
21
|
+
let overview = 'Current Database Schema Overview:\n\n';
|
|
22
22
|
for (const table of tables) {
|
|
23
23
|
overview += `Table: ${table.name}\n`;
|
|
24
24
|
if (table.columns) {
|
|
@@ -26,7 +26,7 @@ class SchemaEvolutionHelper {
|
|
|
26
26
|
overview += ` - ${col.name} (${col.type}${col.nullable ? '?' : ''})\n`;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
overview +=
|
|
29
|
+
overview += '\n';
|
|
30
30
|
}
|
|
31
31
|
return overview;
|
|
32
32
|
}
|
|
@@ -63,9 +63,9 @@ class SchemaEvolutionHelper {
|
|
|
63
63
|
/^CREATE TABLE/i,
|
|
64
64
|
/^CREATE (?:UNIQUE )?INDEX/i,
|
|
65
65
|
/^ALTER TABLE/i,
|
|
66
|
-
/^DROP INDEX/i
|
|
66
|
+
/^DROP INDEX/i,
|
|
67
67
|
];
|
|
68
|
-
const isAllowed = allowedPatterns.some(pattern => pattern.test(d));
|
|
68
|
+
const isAllowed = allowedPatterns.some((pattern) => pattern.test(d));
|
|
69
69
|
if (!isAllowed) {
|
|
70
70
|
throw new Error(`DDL operation not allowed autonomously: ${ddl}`);
|
|
71
71
|
}
|
|
@@ -75,7 +75,32 @@ class SchemaEvolutionHelper {
|
|
|
75
75
|
for (const id of identifiers) {
|
|
76
76
|
const upId = id.toUpperCase();
|
|
77
77
|
// Skip keywords
|
|
78
|
-
if ([
|
|
78
|
+
if ([
|
|
79
|
+
'CREATE',
|
|
80
|
+
'TABLE',
|
|
81
|
+
'ALTER',
|
|
82
|
+
'ADD',
|
|
83
|
+
'COLUMN',
|
|
84
|
+
'INDEX',
|
|
85
|
+
'UNIQUE',
|
|
86
|
+
'ON',
|
|
87
|
+
'DROP',
|
|
88
|
+
'IF',
|
|
89
|
+
'EXISTS',
|
|
90
|
+
'NOT',
|
|
91
|
+
'NULL',
|
|
92
|
+
'PRIMARY',
|
|
93
|
+
'KEY',
|
|
94
|
+
'TIMESTAMP',
|
|
95
|
+
'TEXT',
|
|
96
|
+
'INTEGER',
|
|
97
|
+
'REAL',
|
|
98
|
+
'BOOLEAN',
|
|
99
|
+
'VARCHAR',
|
|
100
|
+
'REFERENCES',
|
|
101
|
+
'CASCADE',
|
|
102
|
+
'SET',
|
|
103
|
+
].includes(upId)) {
|
|
79
104
|
continue;
|
|
80
105
|
}
|
|
81
106
|
try {
|
|
@@ -83,7 +108,7 @@ class SchemaEvolutionHelper {
|
|
|
83
108
|
}
|
|
84
109
|
catch (e) {
|
|
85
110
|
// Ignore small errors in validation if it's a known data type or complex expression
|
|
86
|
-
if (!['VARCHAR', 'TIMESTAMP', 'INT', 'TEXT'].some(t => upId.includes(t))) {
|
|
111
|
+
if (!['VARCHAR', 'TIMESTAMP', 'INT', 'TEXT'].some((t) => upId.includes(t))) {
|
|
87
112
|
console.warn(`[SchemaEvolution] Identifier validation warning for "${id}":`, e);
|
|
88
113
|
}
|
|
89
114
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './kysely.js';
|
|
2
2
|
export * from './query-creator.js';
|
|
3
3
|
export * from './expression/expression.js';
|
|
4
|
-
export { expressionBuilder
|
|
5
|
-
export type { ExpressionBuilder
|
|
4
|
+
export { expressionBuilder } from './expression/expression-builder.js';
|
|
5
|
+
export type { ExpressionBuilder } from './expression/expression-builder.js';
|
|
6
6
|
export * from './expression/expression-wrapper.js';
|
|
7
7
|
export * from './query-builder/where-interface.js';
|
|
8
8
|
export * from './query-builder/returning-interface.js';
|
|
@@ -245,7 +245,7 @@ export * from './agentic/improvement/GovernanceManager.js';
|
|
|
245
245
|
export * from './agentic/CognitiveRepository.js';
|
|
246
246
|
export * from './helpers/agent-schema.js';
|
|
247
247
|
export * from './helpers/schema-evolution.js';
|
|
248
|
-
export { NoormError, TableNotFoundError, ColumnNotFoundError, ConnectionError, DatabaseInitializationError, ValidationError, RelationshipNotFoundError, QueryExecutionError, SchemaDiscoveryError, MigrationError, TypeGenerationError } from './errors/NoormError.js';
|
|
248
|
+
export { NoormError, TableNotFoundError, ColumnNotFoundError, ConnectionError, DatabaseInitializationError, ValidationError, RelationshipNotFoundError, QueryExecutionError, SchemaDiscoveryError, MigrationError, TypeGenerationError, } from './errors/NoormError.js';
|
|
249
249
|
export * from './cli/commands/init.js';
|
|
250
250
|
export * from './cli/commands/inspect.js';
|
|
251
251
|
export * from './cli/commands/generate.js';
|
|
@@ -105,7 +105,7 @@ class Logger {
|
|
|
105
105
|
sql,
|
|
106
106
|
parameters,
|
|
107
107
|
duration,
|
|
108
|
-
timestamp: Date.now()
|
|
108
|
+
timestamp: Date.now(),
|
|
109
109
|
};
|
|
110
110
|
this.queryLogs.push(queryLog);
|
|
111
111
|
this.queryCount++;
|
|
@@ -153,7 +153,7 @@ class Logger {
|
|
|
153
153
|
* Get slow queries
|
|
154
154
|
*/
|
|
155
155
|
getSlowQueries(threshold = 1000) {
|
|
156
|
-
return this.queryLogs.filter(log => log.duration > threshold);
|
|
156
|
+
return this.queryLogs.filter((log) => log.duration > threshold);
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
159
|
* Clear query logs
|
|
@@ -197,7 +197,11 @@ class Logger {
|
|
|
197
197
|
const prefix = this.getPrefix(level);
|
|
198
198
|
let logMessage = `[${timestamp}] ${prefix} ${message}`;
|
|
199
199
|
if (args.length > 0) {
|
|
200
|
-
logMessage +=
|
|
200
|
+
logMessage +=
|
|
201
|
+
' ' +
|
|
202
|
+
args
|
|
203
|
+
.map((arg) => typeof arg === 'object' ? JSON.stringify(arg) : String(arg))
|
|
204
|
+
.join(' ');
|
|
201
205
|
}
|
|
202
206
|
logMessage += '\n';
|
|
203
207
|
fs.appendFileSync(this.config.file, logMessage);
|
|
@@ -222,7 +226,7 @@ class Logger {
|
|
|
222
226
|
queryCount: this.queryCount,
|
|
223
227
|
averageQueryTime: this.getAverageQueryTime(),
|
|
224
228
|
totalQueryTime: this.totalQueryTime,
|
|
225
|
-
slowQueries: this.getSlowQueries().length
|
|
229
|
+
slowQueries: this.getSlowQueries().length,
|
|
226
230
|
};
|
|
227
231
|
}
|
|
228
232
|
/**
|
|
@@ -27,7 +27,9 @@ async function migrateTableData(sourceDb, targetDb, sourceTable, targetTable, so
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
// Keyset pagination optimization: find a numeric primary key
|
|
30
|
-
const pkColumn = sourceTable.columns.find(c => c.primaryKey &&
|
|
30
|
+
const pkColumn = sourceTable.columns.find((c) => c.primaryKey &&
|
|
31
|
+
(c.type.toLowerCase().includes('int') ||
|
|
32
|
+
c.type.toLowerCase().includes('serial')))?.name;
|
|
31
33
|
let lastId = null;
|
|
32
34
|
// Calculate number of batches (approximate)
|
|
33
35
|
const batchCount = Math.ceil(totalRows / options.batchSize);
|
|
@@ -108,7 +110,7 @@ function transformRows(rows, sourceTable, targetTable, sourceDialect, targetDial
|
|
|
108
110
|
// Build transformation map
|
|
109
111
|
const transformations = new Map();
|
|
110
112
|
for (const sourceColumn of sourceTable.columns) {
|
|
111
|
-
const targetColumn = targetTable.columns.find(c => c.name === sourceColumn.name);
|
|
113
|
+
const targetColumn = targetTable.columns.find((c) => c.name === sourceColumn.name);
|
|
112
114
|
if (targetColumn) {
|
|
113
115
|
const transform = (0, type_mapper_js_1.getValueTransformation)(sourceColumn.type, targetColumn.type, sourceDialect, targetDialect);
|
|
114
116
|
if (transform) {
|
|
@@ -117,7 +119,7 @@ function transformRows(rows, sourceTable, targetTable, sourceDialect, targetDial
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
// Transform rows
|
|
120
|
-
return rows.map(row => {
|
|
122
|
+
return rows.map((row) => {
|
|
121
123
|
const transformedRow = {};
|
|
122
124
|
for (const [columnName, value] of Object.entries(row)) {
|
|
123
125
|
const transform = transformations.get(columnName);
|
|
@@ -134,10 +136,7 @@ async function insertBatch(db, tableName, rows) {
|
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
138
|
// Use Kysely's batch insert
|
|
137
|
-
await db
|
|
138
|
-
.insertInto(tableName)
|
|
139
|
-
.values(rows)
|
|
140
|
-
.execute();
|
|
139
|
+
await db.insertInto(tableName).values(rows).execute();
|
|
141
140
|
}
|
|
142
141
|
/**
|
|
143
142
|
* Calculate estimated time remaining
|
|
@@ -155,16 +154,16 @@ function calculateETA(startTime, completed, total) {
|
|
|
155
154
|
* Migrate data for all tables in parallel
|
|
156
155
|
*/
|
|
157
156
|
async function migrateAllTablesData(sourceDb, targetDb, sourceTables, targetTables, sourceDialect, targetDialect, options) {
|
|
158
|
-
const targetTableMap = new Map(targetTables.map(t => [t.name, t]));
|
|
157
|
+
const targetTableMap = new Map(targetTables.map((t) => [t.name, t]));
|
|
159
158
|
const results = [];
|
|
160
159
|
// Filter tables that exist in both source and target
|
|
161
|
-
const tablesToMigrate = sourceTables.filter(st => targetTableMap.has(st.name));
|
|
160
|
+
const tablesToMigrate = sourceTables.filter((st) => targetTableMap.has(st.name));
|
|
162
161
|
if (options.parallel && options.parallelWorkers > 1) {
|
|
163
162
|
// Migrate tables in parallel batches
|
|
164
163
|
const workerCount = Math.min(options.parallelWorkers, tablesToMigrate.length);
|
|
165
164
|
const chunks = chunkArray(tablesToMigrate, workerCount);
|
|
166
165
|
for (const chunk of chunks) {
|
|
167
|
-
const chunkResults = await Promise.all(chunk.map(sourceTable => {
|
|
166
|
+
const chunkResults = await Promise.all(chunk.map((sourceTable) => {
|
|
168
167
|
const targetTable = targetTableMap.get(sourceTable.name);
|
|
169
168
|
return migrateTableData(sourceDb, targetDb, sourceTable, targetTable, sourceDialect, targetDialect, options);
|
|
170
169
|
}));
|
|
@@ -225,6 +224,8 @@ async function truncateTable(db, tableName, dialect) {
|
|
|
225
224
|
else {
|
|
226
225
|
await sql_js_1.sql.raw(`DELETE FROM "${tableName}"`).execute(db);
|
|
227
226
|
// Reset autoincrement counter in SQLite
|
|
228
|
-
await sql_js_1.sql
|
|
227
|
+
await sql_js_1.sql
|
|
228
|
+
.raw(`DELETE FROM sqlite_sequence WHERE name = '${tableName}'`)
|
|
229
|
+
.execute(db);
|
|
229
230
|
}
|
|
230
231
|
}
|