noormme 1.0.0 → 1.0.2
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 +89 -21
- package/README.md +195 -578
- package/dist/cjs/cli/commands/analyze.js +4 -1
- package/dist/cjs/cli/commands/generate.js +48 -8
- package/dist/cjs/cli/commands/init.js +54 -14
- package/dist/cjs/cli/commands/inspect.js +10 -3
- package/dist/cjs/cli/commands/migrate.js +38 -2
- package/dist/cjs/cli/commands/optimize.js +4 -1
- package/dist/cjs/cli/commands/status.js +41 -5
- package/dist/cjs/cli/commands/watch.js +4 -1
- package/dist/cjs/cli/index.js +4 -1
- package/dist/cjs/dialect/database-introspector.js +16 -21
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +13 -24
- package/dist/cjs/dynamic/dynamic.d.ts +20 -0
- package/dist/cjs/dynamic/dynamic.js +25 -0
- package/dist/cjs/edge-runtime/edge-config.d.ts +125 -0
- package/dist/cjs/edge-runtime/edge-config.js +323 -0
- package/dist/cjs/errors/NoormError.d.ts +27 -4
- package/dist/cjs/errors/NoormError.js +142 -21
- package/dist/cjs/logging/logger.d.ts +7 -2
- package/dist/cjs/logging/logger.js +21 -7
- package/dist/cjs/noormme.d.ts +12 -8
- package/dist/cjs/noormme.js +133 -61
- package/dist/cjs/operation-node/column-node.js +4 -0
- package/dist/cjs/operation-node/identifier-node.js +4 -0
- package/dist/cjs/operation-node/table-node.js +7 -0
- package/dist/cjs/parser/reference-parser.js +5 -0
- package/dist/cjs/parser/table-parser.js +2 -0
- package/dist/cjs/performance/index.d.ts +44 -0
- package/dist/cjs/performance/index.js +64 -0
- package/dist/cjs/performance/query-optimizer.d.ts +134 -0
- package/dist/cjs/performance/query-optimizer.js +391 -0
- package/dist/cjs/performance/services/cache-service.d.ts +177 -0
- package/dist/cjs/performance/services/cache-service.js +415 -0
- package/dist/cjs/performance/services/connection-factory.d.ts +198 -0
- package/dist/cjs/performance/services/connection-factory.js +498 -0
- package/dist/cjs/performance/services/metrics-collector.d.ts +162 -0
- package/dist/cjs/performance/services/metrics-collector.js +406 -0
- package/dist/cjs/performance/utils/query-parser.d.ts +123 -0
- package/dist/cjs/performance/utils/query-parser.js +295 -0
- package/dist/cjs/raw-builder/sql.d.ts +73 -26
- package/dist/cjs/raw-builder/sql.js +9 -0
- package/dist/cjs/repository/repository-factory.d.ts +10 -42
- package/dist/cjs/repository/repository-factory.js +276 -394
- package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +6 -4
- package/dist/cjs/schema/core/factories/discovery-factory.js +5 -5
- package/dist/cjs/schema/core/utils/name-generator.js +34 -2
- package/dist/cjs/schema/core/utils/type-mapper.d.ts +19 -14
- package/dist/cjs/schema/core/utils/type-mapper.js +4 -7
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +3 -2
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.d.ts +2 -0
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +19 -5
- package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -0
- package/dist/cjs/schema/test/error-handling.test.js +52 -33
- package/dist/cjs/schema/test/integration.test.js +51 -5
- package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +8 -4
- package/dist/cjs/sqlite-migration/index.js +35 -2
- package/dist/cjs/testing/test-utils.d.ts +5 -0
- package/dist/cjs/testing/test-utils.js +66 -6
- package/dist/cjs/types/index.d.ts +78 -13
- package/dist/cjs/types/index.js +23 -0
- package/dist/cjs/types/type-generator.d.ts +8 -0
- package/dist/cjs/types/type-generator.js +86 -17
- package/dist/cjs/util/safe-sql-helpers.d.ts +124 -0
- package/dist/cjs/util/safe-sql-helpers.js +221 -0
- package/dist/cjs/util/security-validator.d.ts +44 -0
- package/dist/cjs/util/security-validator.js +256 -0
- package/dist/cjs/util/security.d.ts +60 -0
- package/dist/cjs/util/security.js +137 -0
- package/dist/cjs/watch/schema-watcher.js +26 -7
- package/dist/esm/cli/commands/generate.js +10 -6
- package/dist/esm/cli/commands/init.js +15 -11
- package/dist/esm/cli/commands/inspect.js +6 -2
- package/dist/esm/cli/commands/status.js +3 -3
- package/dist/esm/dialect/database-introspector.js +16 -21
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +13 -24
- package/dist/esm/dynamic/dynamic.d.ts +20 -0
- package/dist/esm/dynamic/dynamic.js +25 -0
- package/dist/esm/edge-runtime/edge-config.d.ts +125 -0
- package/dist/esm/edge-runtime/edge-config.js +281 -0
- package/dist/esm/errors/NoormError.d.ts +27 -4
- package/dist/esm/errors/NoormError.js +134 -18
- package/dist/esm/logging/logger.d.ts +7 -2
- package/dist/esm/logging/logger.js +21 -7
- package/dist/esm/noormme.d.ts +12 -8
- package/dist/esm/noormme.js +130 -61
- package/dist/esm/operation-node/column-node.js +4 -0
- package/dist/esm/operation-node/identifier-node.js +4 -0
- package/dist/esm/operation-node/table-node.js +7 -0
- package/dist/esm/parser/reference-parser.js +5 -0
- package/dist/esm/parser/table-parser.js +2 -0
- package/dist/esm/performance/index.d.ts +44 -0
- package/dist/esm/performance/index.js +48 -0
- package/dist/esm/performance/query-optimizer.d.ts +134 -0
- package/dist/esm/performance/query-optimizer.js +387 -0
- package/dist/esm/performance/services/cache-service.d.ts +177 -0
- package/dist/esm/performance/services/cache-service.js +410 -0
- package/dist/esm/performance/services/connection-factory.d.ts +198 -0
- package/dist/esm/performance/services/connection-factory.js +493 -0
- package/dist/esm/performance/services/metrics-collector.d.ts +162 -0
- package/dist/esm/performance/services/metrics-collector.js +402 -0
- package/dist/esm/performance/utils/query-parser.d.ts +123 -0
- package/dist/esm/performance/utils/query-parser.js +292 -0
- package/dist/esm/raw-builder/sql.d.ts +73 -26
- package/dist/esm/raw-builder/sql.js +9 -0
- package/dist/esm/repository/repository-factory.d.ts +10 -42
- package/dist/esm/repository/repository-factory.js +277 -395
- package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +6 -4
- package/dist/esm/schema/core/factories/discovery-factory.js +5 -5
- package/dist/esm/schema/core/utils/name-generator.js +34 -2
- package/dist/esm/schema/core/utils/type-mapper.d.ts +19 -14
- package/dist/esm/schema/core/utils/type-mapper.js +4 -7
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +3 -2
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.d.ts +2 -0
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +19 -5
- package/dist/esm/schema/test/dialect-capabilities.test.js +6 -0
- package/dist/esm/schema/test/error-handling.test.js +52 -33
- package/dist/esm/schema/test/integration.test.js +18 -5
- package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +8 -4
- package/dist/esm/testing/test-utils.d.ts +5 -0
- package/dist/esm/testing/test-utils.js +66 -6
- package/dist/esm/types/index.d.ts +78 -13
- package/dist/esm/types/index.js +22 -1
- package/dist/esm/types/type-generator.d.ts +8 -0
- package/dist/esm/types/type-generator.js +86 -17
- package/dist/esm/util/safe-sql-helpers.d.ts +124 -0
- package/dist/esm/util/safe-sql-helpers.js +209 -0
- package/dist/esm/util/security-validator.d.ts +44 -0
- package/dist/esm/util/security-validator.js +246 -0
- package/dist/esm/util/security.d.ts +60 -0
- package/dist/esm/util/security.js +114 -0
- package/dist/esm/watch/schema-watcher.js +26 -7
- package/package.json +1 -1
- package/dist/cjs/performance/query-analyzer.d.ts +0 -89
- package/dist/cjs/performance/query-analyzer.js +0 -263
- package/dist/esm/performance/query-analyzer.d.ts +0 -89
- package/dist/esm/performance/query-analyzer.js +0 -260
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { NOORMConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Edge Runtime compatible configuration for NOORMME
|
|
4
|
+
*
|
|
5
|
+
* Edge Runtime has specific limitations:
|
|
6
|
+
* - No file system access (use in-memory database)
|
|
7
|
+
* - No WAL mode support
|
|
8
|
+
* - Limited memory and CPU resources
|
|
9
|
+
* - No persistent storage
|
|
10
|
+
* - Minimal logging capabilities
|
|
11
|
+
*/
|
|
12
|
+
export declare function getEdgeRuntimeConfig(): NOORMConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Check if current environment is Edge Runtime
|
|
15
|
+
*/
|
|
16
|
+
export declare function isEdgeRuntime(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get appropriate configuration based on runtime environment
|
|
19
|
+
*/
|
|
20
|
+
export declare function getRuntimeConfig(): NOORMConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Edge Runtime compatible database operations
|
|
23
|
+
*/
|
|
24
|
+
export declare class EdgeRuntimeDB {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config?: NOORMConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Create a new database instance optimized for Edge Runtime
|
|
29
|
+
*/
|
|
30
|
+
createInstance(): Promise<import("../noormme").NOORMME>;
|
|
31
|
+
/**
|
|
32
|
+
* Execute a simple query in Edge Runtime
|
|
33
|
+
*/
|
|
34
|
+
executeQuery(query: string, params?: any[]): Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Perform a read operation in Edge Runtime
|
|
37
|
+
*/
|
|
38
|
+
read(table: string, conditions?: Record<string, any>): Promise<unknown[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Perform a write operation in Edge Runtime
|
|
41
|
+
*/
|
|
42
|
+
write(table: string, data: Record<string, any>): Promise<unknown>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Edge Runtime compatible middleware
|
|
46
|
+
*/
|
|
47
|
+
export declare function createEdgeMiddleware(): {
|
|
48
|
+
/**
|
|
49
|
+
* Handle database operations in Edge Runtime
|
|
50
|
+
*/
|
|
51
|
+
handleRequest(request: Request): Promise<Response>;
|
|
52
|
+
/**
|
|
53
|
+
* Handle API requests in Edge Runtime
|
|
54
|
+
*/
|
|
55
|
+
handleAPIRequest(request: Request, edgeDB: EdgeRuntimeDB): Promise<Response>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Edge Runtime compatible error handler
|
|
59
|
+
*/
|
|
60
|
+
export declare function createEdgeErrorHandler(): {
|
|
61
|
+
/**
|
|
62
|
+
* Handle errors in Edge Runtime
|
|
63
|
+
*/
|
|
64
|
+
handleError(error: Error, context?: string): Response;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Edge Runtime performance monitoring
|
|
68
|
+
*/
|
|
69
|
+
export declare class EdgeRuntimeMonitor {
|
|
70
|
+
private metrics;
|
|
71
|
+
/**
|
|
72
|
+
* Record a performance metric
|
|
73
|
+
*/
|
|
74
|
+
recordMetric(name: string, value: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get performance metrics
|
|
77
|
+
*/
|
|
78
|
+
getMetrics(): {
|
|
79
|
+
[k: string]: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Monitor a function execution
|
|
83
|
+
*/
|
|
84
|
+
monitor<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Get performance report
|
|
87
|
+
*/
|
|
88
|
+
getReport(): {
|
|
89
|
+
totalOperations: number;
|
|
90
|
+
metrics: {
|
|
91
|
+
[k: string]: number;
|
|
92
|
+
};
|
|
93
|
+
timestamp: string;
|
|
94
|
+
runtime: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Edge Runtime utilities
|
|
99
|
+
*/
|
|
100
|
+
export declare const EdgeRuntimeUtils: {
|
|
101
|
+
/**
|
|
102
|
+
* Check if running in Edge Runtime
|
|
103
|
+
*/
|
|
104
|
+
isEdgeRuntime: typeof isEdgeRuntime;
|
|
105
|
+
/**
|
|
106
|
+
* Get Edge Runtime configuration
|
|
107
|
+
*/
|
|
108
|
+
getConfig: typeof getEdgeRuntimeConfig;
|
|
109
|
+
/**
|
|
110
|
+
* Create Edge Runtime database instance
|
|
111
|
+
*/
|
|
112
|
+
createDB: () => EdgeRuntimeDB;
|
|
113
|
+
/**
|
|
114
|
+
* Create Edge Runtime middleware
|
|
115
|
+
*/
|
|
116
|
+
createMiddleware: typeof createEdgeMiddleware;
|
|
117
|
+
/**
|
|
118
|
+
* Create Edge Runtime error handler
|
|
119
|
+
*/
|
|
120
|
+
createErrorHandler: typeof createEdgeErrorHandler;
|
|
121
|
+
/**
|
|
122
|
+
* Create Edge Runtime monitor
|
|
123
|
+
*/
|
|
124
|
+
createMonitor: () => EdgeRuntimeMonitor;
|
|
125
|
+
};
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/// <reference types="./edge-config.d.ts" />
|
|
2
|
+
/**
|
|
3
|
+
* Edge Runtime compatible configuration for NOORMME
|
|
4
|
+
*
|
|
5
|
+
* Edge Runtime has specific limitations:
|
|
6
|
+
* - No file system access (use in-memory database)
|
|
7
|
+
* - No WAL mode support
|
|
8
|
+
* - Limited memory and CPU resources
|
|
9
|
+
* - No persistent storage
|
|
10
|
+
* - Minimal logging capabilities
|
|
11
|
+
*/
|
|
12
|
+
export function getEdgeRuntimeConfig() {
|
|
13
|
+
return {
|
|
14
|
+
dialect: 'sqlite',
|
|
15
|
+
connection: {
|
|
16
|
+
database: ':memory:'
|
|
17
|
+
},
|
|
18
|
+
optimization: {
|
|
19
|
+
enableWALMode: false, // WAL mode not supported in Edge Runtime
|
|
20
|
+
enableForeignKeys: true,
|
|
21
|
+
cacheSize: -2000, // 2MB cache (smaller for Edge Runtime)
|
|
22
|
+
synchronous: 'NORMAL',
|
|
23
|
+
tempStore: 'MEMORY' // Use memory for temporary storage
|
|
24
|
+
},
|
|
25
|
+
logging: {
|
|
26
|
+
level: 'error', // Minimal logging for performance
|
|
27
|
+
enabled: false // Disable logging in Edge Runtime
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if current environment is Edge Runtime
|
|
33
|
+
*/
|
|
34
|
+
export function isEdgeRuntime() {
|
|
35
|
+
return ((typeof globalThis !== 'undefined' && 'EdgeRuntime' in globalThis) ||
|
|
36
|
+
(typeof process !== 'undefined' && process.env.NEXT_RUNTIME === 'edge'));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get appropriate configuration based on runtime environment
|
|
40
|
+
*/
|
|
41
|
+
export function getRuntimeConfig() {
|
|
42
|
+
if (isEdgeRuntime()) {
|
|
43
|
+
return getEdgeRuntimeConfig();
|
|
44
|
+
}
|
|
45
|
+
// Default configuration for Node.js runtime
|
|
46
|
+
return {
|
|
47
|
+
dialect: 'sqlite',
|
|
48
|
+
connection: {
|
|
49
|
+
database: process.env.DATABASE_URL || './app.db'
|
|
50
|
+
},
|
|
51
|
+
optimization: {
|
|
52
|
+
enableWALMode: true,
|
|
53
|
+
enableForeignKeys: true,
|
|
54
|
+
cacheSize: -64000, // 64MB cache
|
|
55
|
+
synchronous: 'NORMAL',
|
|
56
|
+
tempStore: 'DEFAULT'
|
|
57
|
+
},
|
|
58
|
+
logging: {
|
|
59
|
+
level: process.env.NODE_ENV === 'development' ? 'info' : 'error',
|
|
60
|
+
enabled: true
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Edge Runtime compatible database operations
|
|
66
|
+
*/
|
|
67
|
+
export class EdgeRuntimeDB {
|
|
68
|
+
config;
|
|
69
|
+
constructor(config) {
|
|
70
|
+
this.config = config || getEdgeRuntimeConfig();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new database instance optimized for Edge Runtime
|
|
74
|
+
*/
|
|
75
|
+
async createInstance() {
|
|
76
|
+
const { NOORMME } = await import('../noormme');
|
|
77
|
+
return new NOORMME(this.config);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute a simple query in Edge Runtime
|
|
81
|
+
*/
|
|
82
|
+
async executeQuery(query, params) {
|
|
83
|
+
const db = await this.createInstance();
|
|
84
|
+
await db.initialize();
|
|
85
|
+
try {
|
|
86
|
+
const result = await db.execute(query, params);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await db.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Perform a read operation in Edge Runtime
|
|
95
|
+
*/
|
|
96
|
+
async read(table, conditions = {}) {
|
|
97
|
+
const db = await this.createInstance();
|
|
98
|
+
await db.initialize();
|
|
99
|
+
try {
|
|
100
|
+
const repo = db.getRepository(table);
|
|
101
|
+
return await repo.findAll();
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await db.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Perform a write operation in Edge Runtime
|
|
109
|
+
*/
|
|
110
|
+
async write(table, data) {
|
|
111
|
+
const db = await this.createInstance();
|
|
112
|
+
await db.initialize();
|
|
113
|
+
try {
|
|
114
|
+
const repo = db.getRepository(table);
|
|
115
|
+
return await repo.create(data);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
await db.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Edge Runtime compatible middleware
|
|
124
|
+
*/
|
|
125
|
+
export function createEdgeMiddleware() {
|
|
126
|
+
return {
|
|
127
|
+
/**
|
|
128
|
+
* Handle database operations in Edge Runtime
|
|
129
|
+
*/
|
|
130
|
+
async handleRequest(request) {
|
|
131
|
+
const edgeDB = new EdgeRuntimeDB();
|
|
132
|
+
try {
|
|
133
|
+
const url = new URL(request.url);
|
|
134
|
+
const pathname = url.pathname;
|
|
135
|
+
if (pathname.startsWith('/api/')) {
|
|
136
|
+
return await this.handleAPIRequest(request, edgeDB);
|
|
137
|
+
}
|
|
138
|
+
return new Response('Not found', { status: 404 });
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error('Edge Runtime error:', error);
|
|
142
|
+
return new Response('Internal Server Error', { status: 500 });
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Handle API requests in Edge Runtime
|
|
147
|
+
*/
|
|
148
|
+
async handleAPIRequest(request, edgeDB) {
|
|
149
|
+
const url = new URL(request.url);
|
|
150
|
+
const method = request.method;
|
|
151
|
+
const pathname = url.pathname;
|
|
152
|
+
// Simple routing for Edge Runtime
|
|
153
|
+
if (pathname === '/api/health') {
|
|
154
|
+
return new Response(JSON.stringify({
|
|
155
|
+
status: 'healthy',
|
|
156
|
+
runtime: 'edge',
|
|
157
|
+
timestamp: new Date().toISOString()
|
|
158
|
+
}), {
|
|
159
|
+
headers: { 'Content-Type': 'application/json' }
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (pathname === '/api/users' && method === 'GET') {
|
|
163
|
+
const users = await edgeDB.read('users');
|
|
164
|
+
return new Response(JSON.stringify(users), {
|
|
165
|
+
headers: { 'Content-Type': 'application/json' }
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (pathname === '/api/users' && method === 'POST') {
|
|
169
|
+
const data = await request.json();
|
|
170
|
+
const user = await edgeDB.write('users', data);
|
|
171
|
+
return new Response(JSON.stringify(user), {
|
|
172
|
+
status: 201,
|
|
173
|
+
headers: { 'Content-Type': 'application/json' }
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return new Response('Not found', { status: 404 });
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Edge Runtime compatible error handler
|
|
182
|
+
*/
|
|
183
|
+
export function createEdgeErrorHandler() {
|
|
184
|
+
return {
|
|
185
|
+
/**
|
|
186
|
+
* Handle errors in Edge Runtime
|
|
187
|
+
*/
|
|
188
|
+
handleError(error, context) {
|
|
189
|
+
// Log error (minimal logging in Edge Runtime)
|
|
190
|
+
console.error(`Edge Runtime Error${context ? ` in ${context}` : ''}:`, error.message);
|
|
191
|
+
// Return appropriate response
|
|
192
|
+
return new Response(JSON.stringify({
|
|
193
|
+
error: 'Internal Server Error',
|
|
194
|
+
message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong',
|
|
195
|
+
timestamp: new Date().toISOString()
|
|
196
|
+
}), {
|
|
197
|
+
status: 500,
|
|
198
|
+
headers: { 'Content-Type': 'application/json' }
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Edge Runtime performance monitoring
|
|
205
|
+
*/
|
|
206
|
+
export class EdgeRuntimeMonitor {
|
|
207
|
+
metrics = new Map();
|
|
208
|
+
/**
|
|
209
|
+
* Record a performance metric
|
|
210
|
+
*/
|
|
211
|
+
recordMetric(name, value) {
|
|
212
|
+
this.metrics.set(name, value);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get performance metrics
|
|
216
|
+
*/
|
|
217
|
+
getMetrics() {
|
|
218
|
+
return Object.fromEntries(this.metrics);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Monitor a function execution
|
|
222
|
+
*/
|
|
223
|
+
async monitor(name, fn) {
|
|
224
|
+
const start = performance.now();
|
|
225
|
+
try {
|
|
226
|
+
const result = await fn();
|
|
227
|
+
const duration = performance.now() - start;
|
|
228
|
+
this.recordMetric(`${name}_duration`, duration);
|
|
229
|
+
this.recordMetric(`${name}_success`, 1);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
const duration = performance.now() - start;
|
|
234
|
+
this.recordMetric(`${name}_duration`, duration);
|
|
235
|
+
this.recordMetric(`${name}_error`, 1);
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get performance report
|
|
241
|
+
*/
|
|
242
|
+
getReport() {
|
|
243
|
+
const metrics = this.getMetrics();
|
|
244
|
+
const totalOperations = Object.keys(metrics).length;
|
|
245
|
+
return {
|
|
246
|
+
totalOperations,
|
|
247
|
+
metrics,
|
|
248
|
+
timestamp: new Date().toISOString(),
|
|
249
|
+
runtime: 'edge'
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Edge Runtime utilities
|
|
255
|
+
*/
|
|
256
|
+
export const EdgeRuntimeUtils = {
|
|
257
|
+
/**
|
|
258
|
+
* Check if running in Edge Runtime
|
|
259
|
+
*/
|
|
260
|
+
isEdgeRuntime,
|
|
261
|
+
/**
|
|
262
|
+
* Get Edge Runtime configuration
|
|
263
|
+
*/
|
|
264
|
+
getConfig: getEdgeRuntimeConfig,
|
|
265
|
+
/**
|
|
266
|
+
* Create Edge Runtime database instance
|
|
267
|
+
*/
|
|
268
|
+
createDB: () => new EdgeRuntimeDB(),
|
|
269
|
+
/**
|
|
270
|
+
* Create Edge Runtime middleware
|
|
271
|
+
*/
|
|
272
|
+
createMiddleware: createEdgeMiddleware,
|
|
273
|
+
/**
|
|
274
|
+
* Create Edge Runtime error handler
|
|
275
|
+
*/
|
|
276
|
+
createErrorHandler: createEdgeErrorHandler,
|
|
277
|
+
/**
|
|
278
|
+
* Create Edge Runtime monitor
|
|
279
|
+
*/
|
|
280
|
+
createMonitor: () => new EdgeRuntimeMonitor()
|
|
281
|
+
};
|
|
@@ -44,13 +44,36 @@ export declare class TableNotFoundError extends NoormError {
|
|
|
44
44
|
}
|
|
45
45
|
export declare class ColumnNotFoundError extends NoormError {
|
|
46
46
|
constructor(columnName: string, tableName: string, availableColumns?: string[]);
|
|
47
|
+
private static calculateSimilarity;
|
|
48
|
+
private static levenshteinDistance;
|
|
49
|
+
}
|
|
50
|
+
export declare class ConnectionError extends NoormError {
|
|
51
|
+
constructor(message: string, originalError?: Error);
|
|
52
|
+
}
|
|
53
|
+
export declare class DatabaseInitializationError extends NoormError {
|
|
54
|
+
constructor(originalError: Error, databasePath: string);
|
|
55
|
+
}
|
|
56
|
+
export declare class ValidationError extends NoormError {
|
|
57
|
+
constructor(message: string, validationIssues?: string[]);
|
|
47
58
|
}
|
|
48
59
|
export declare class RelationshipNotFoundError extends NoormError {
|
|
49
60
|
constructor(relationshipName: string, tableName: string, availableRelationships?: string[]);
|
|
50
61
|
}
|
|
51
|
-
export declare class
|
|
52
|
-
constructor(
|
|
62
|
+
export declare class QueryExecutionError extends NoormError {
|
|
63
|
+
constructor(query: string, originalError: Error, context?: {
|
|
64
|
+
table?: string;
|
|
65
|
+
operation?: string;
|
|
66
|
+
});
|
|
67
|
+
private static getQuerySuggestion;
|
|
53
68
|
}
|
|
54
|
-
export declare class
|
|
55
|
-
constructor(
|
|
69
|
+
export declare class SchemaDiscoveryError extends NoormError {
|
|
70
|
+
constructor(tableName: string, originalError: Error);
|
|
71
|
+
}
|
|
72
|
+
export declare class MigrationError extends NoormError {
|
|
73
|
+
constructor(migrationName: string, originalError: Error, context?: {
|
|
74
|
+
step?: string;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export declare class TypeGenerationError extends NoormError {
|
|
78
|
+
constructor(tableName: string, originalError: Error);
|
|
56
79
|
}
|
|
@@ -52,27 +52,98 @@ export class NoormError extends Error {
|
|
|
52
52
|
*/
|
|
53
53
|
export class TableNotFoundError extends NoormError {
|
|
54
54
|
constructor(tableName, availableTables = []) {
|
|
55
|
-
|
|
55
|
+
const message = availableTables.length > 0
|
|
56
|
+
? `Table '${tableName}' not found. Available tables: ${availableTables.join(', ')}`
|
|
57
|
+
: `Table '${tableName}' not found. Check your table name or run schema discovery.`;
|
|
58
|
+
super(message, {
|
|
56
59
|
table: tableName,
|
|
57
|
-
operation: '
|
|
60
|
+
operation: 'table_lookup',
|
|
58
61
|
suggestion: availableTables.length > 0
|
|
59
62
|
? `Available tables: ${availableTables.join(', ')}`
|
|
60
|
-
: 'Check your
|
|
63
|
+
: 'Check your table name or run schema discovery',
|
|
61
64
|
availableOptions: availableTables
|
|
62
65
|
});
|
|
66
|
+
this.name = 'TableNotFoundError';
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
export class ColumnNotFoundError extends NoormError {
|
|
66
70
|
constructor(columnName, tableName, availableColumns = []) {
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
// Find similar column names for better suggestions
|
|
72
|
+
const similarColumns = availableColumns.filter(col => col.toLowerCase().includes(columnName.toLowerCase()) ||
|
|
73
|
+
columnName.toLowerCase().includes(col.toLowerCase()) ||
|
|
74
|
+
ColumnNotFoundError.calculateSimilarity(col, columnName) > 0.6);
|
|
75
|
+
let suggestion = 'Check your column name or run schema discovery';
|
|
76
|
+
if (availableColumns.length > 0) {
|
|
77
|
+
suggestion = `Available columns: ${availableColumns.join(', ')}`;
|
|
78
|
+
if (similarColumns.length > 0) {
|
|
79
|
+
suggestion += `\n → Did you mean '${similarColumns[0]}'? (${Math.round(ColumnNotFoundError.calculateSimilarity(similarColumns[0], columnName) * 100)}% similarity)`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
super(`Column '${columnName}' not found in table '${tableName}'`, {
|
|
69
83
|
table: tableName,
|
|
70
84
|
operation: 'column_lookup',
|
|
71
|
-
suggestion:
|
|
72
|
-
? `Did you mean '${similar[0]}'?`
|
|
73
|
-
: `Available columns: ${availableColumns.join(', ')}`,
|
|
85
|
+
suggestion: suggestion,
|
|
74
86
|
availableOptions: availableColumns
|
|
75
87
|
});
|
|
88
|
+
this.name = 'ColumnNotFoundError';
|
|
89
|
+
}
|
|
90
|
+
static calculateSimilarity(str1, str2) {
|
|
91
|
+
const longer = str1.length > str2.length ? str1 : str2;
|
|
92
|
+
const shorter = str1.length > str2.length ? str2 : str1;
|
|
93
|
+
if (longer.length === 0)
|
|
94
|
+
return 1.0;
|
|
95
|
+
const editDistance = ColumnNotFoundError.levenshteinDistance(longer, shorter);
|
|
96
|
+
return (longer.length - editDistance) / longer.length;
|
|
97
|
+
}
|
|
98
|
+
static levenshteinDistance(str1, str2) {
|
|
99
|
+
const matrix = [];
|
|
100
|
+
for (let i = 0; i <= str2.length; i++) {
|
|
101
|
+
matrix[i] = [i];
|
|
102
|
+
}
|
|
103
|
+
for (let j = 0; j <= str1.length; j++) {
|
|
104
|
+
matrix[0][j] = j;
|
|
105
|
+
}
|
|
106
|
+
for (let i = 1; i <= str2.length; i++) {
|
|
107
|
+
for (let j = 1; j <= str1.length; j++) {
|
|
108
|
+
if (str2.charAt(i - 1) === str1.charAt(j - 1)) {
|
|
109
|
+
matrix[i][j] = matrix[i - 1][j - 1];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return matrix[str2.length][str1.length];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export class ConnectionError extends NoormError {
|
|
120
|
+
constructor(message, originalError) {
|
|
121
|
+
super(message, {
|
|
122
|
+
operation: 'connection',
|
|
123
|
+
suggestion: 'Check your database connection settings and ensure the database server is running',
|
|
124
|
+
originalError
|
|
125
|
+
});
|
|
126
|
+
this.name = 'ConnectionError';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export class DatabaseInitializationError extends NoormError {
|
|
130
|
+
constructor(originalError, databasePath) {
|
|
131
|
+
super(`Failed to initialize database at ${databasePath}: ${originalError.message}`, {
|
|
132
|
+
operation: 'initialization',
|
|
133
|
+
suggestion: 'Check database permissions, path validity, and connection settings',
|
|
134
|
+
originalError
|
|
135
|
+
});
|
|
136
|
+
this.name = 'DatabaseInitializationError';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export class ValidationError extends NoormError {
|
|
140
|
+
constructor(message, validationIssues = []) {
|
|
141
|
+
super(message, {
|
|
142
|
+
operation: 'validation',
|
|
143
|
+
suggestion: 'Check your input data and ensure it matches the expected schema',
|
|
144
|
+
availableOptions: validationIssues
|
|
145
|
+
});
|
|
146
|
+
this.name = 'ValidationError';
|
|
76
147
|
}
|
|
77
148
|
}
|
|
78
149
|
export class RelationshipNotFoundError extends NoormError {
|
|
@@ -85,24 +156,69 @@ export class RelationshipNotFoundError extends NoormError {
|
|
|
85
156
|
: 'No relationships defined for this table',
|
|
86
157
|
availableOptions: availableRelationships
|
|
87
158
|
});
|
|
159
|
+
this.name = 'RelationshipNotFoundError';
|
|
88
160
|
}
|
|
89
161
|
}
|
|
90
|
-
export class
|
|
91
|
-
constructor(
|
|
92
|
-
super(message
|
|
162
|
+
export class QueryExecutionError extends NoormError {
|
|
163
|
+
constructor(query, originalError, context) {
|
|
164
|
+
super(`Query execution failed: ${originalError.message}`, {
|
|
165
|
+
operation: context?.operation || 'query_execution',
|
|
166
|
+
table: context?.table,
|
|
167
|
+
suggestion: QueryExecutionError.getQuerySuggestion(query, originalError),
|
|
168
|
+
originalError
|
|
169
|
+
});
|
|
170
|
+
this.name = 'QueryExecutionError';
|
|
171
|
+
}
|
|
172
|
+
static getQuerySuggestion(query, error) {
|
|
173
|
+
const errorMsg = error.message.toLowerCase();
|
|
174
|
+
if (errorMsg.includes('syntax error')) {
|
|
175
|
+
return 'Check your SQL syntax. Common issues: missing commas, unclosed quotes, or invalid keywords.';
|
|
176
|
+
}
|
|
177
|
+
if (errorMsg.includes('no such table')) {
|
|
178
|
+
return 'Table does not exist. Check table name or run schema discovery to see available tables.';
|
|
179
|
+
}
|
|
180
|
+
if (errorMsg.includes('no such column')) {
|
|
181
|
+
return 'Column does not exist. Check column name or run schema discovery to see available columns.';
|
|
182
|
+
}
|
|
183
|
+
if (errorMsg.includes('constraint failed')) {
|
|
184
|
+
return 'Data constraint violation. Check for required fields, unique constraints, or foreign key references.';
|
|
185
|
+
}
|
|
186
|
+
if (errorMsg.includes('database is locked')) {
|
|
187
|
+
return 'Database is locked. Enable WAL mode for better concurrency: optimization: { enableWALMode: true }';
|
|
188
|
+
}
|
|
189
|
+
return 'Review your query and check the original error message for specific details.';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export class SchemaDiscoveryError extends NoormError {
|
|
193
|
+
constructor(tableName, originalError) {
|
|
194
|
+
super(`Failed to discover schema for table '${tableName}': ${originalError.message}`, {
|
|
93
195
|
table: tableName,
|
|
94
|
-
operation: '
|
|
95
|
-
suggestion:
|
|
196
|
+
operation: 'schema_discovery',
|
|
197
|
+
suggestion: 'Check table permissions, table name validity, or database connection',
|
|
198
|
+
originalError
|
|
96
199
|
});
|
|
200
|
+
this.name = 'SchemaDiscoveryError';
|
|
97
201
|
}
|
|
98
202
|
}
|
|
99
|
-
export class
|
|
100
|
-
constructor(
|
|
101
|
-
super(`
|
|
102
|
-
operation: '
|
|
103
|
-
suggestion: 'Check
|
|
203
|
+
export class MigrationError extends NoormError {
|
|
204
|
+
constructor(migrationName, originalError, context) {
|
|
205
|
+
super(`Migration '${migrationName}' failed${context?.step ? ` at step: ${context.step}` : ''}: ${originalError.message}`, {
|
|
206
|
+
operation: 'migration',
|
|
207
|
+
suggestion: 'Check migration SQL syntax, database permissions, or rollback the migration',
|
|
208
|
+
originalError
|
|
209
|
+
});
|
|
210
|
+
this.name = 'MigrationError';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export class TypeGenerationError extends NoormError {
|
|
214
|
+
constructor(tableName, originalError) {
|
|
215
|
+
super(`Failed to generate types for table '${tableName}': ${originalError.message}`, {
|
|
216
|
+
table: tableName,
|
|
217
|
+
operation: 'type_generation',
|
|
218
|
+
suggestion: 'Check table schema, column types, or custom type mappings configuration',
|
|
104
219
|
originalError
|
|
105
220
|
});
|
|
221
|
+
this.name = 'TypeGenerationError';
|
|
106
222
|
}
|
|
107
223
|
}
|
|
108
224
|
/**
|
|
@@ -10,11 +10,16 @@ interface QueryLog {
|
|
|
10
10
|
* Logger for NOORMME
|
|
11
11
|
*/
|
|
12
12
|
export declare class Logger {
|
|
13
|
-
private config;
|
|
14
13
|
private queryLogs;
|
|
15
14
|
private queryCount;
|
|
16
15
|
private totalQueryTime;
|
|
17
|
-
|
|
16
|
+
private config;
|
|
17
|
+
private namespace?;
|
|
18
|
+
constructor(configOrNamespace?: LoggingConfig | string);
|
|
19
|
+
/**
|
|
20
|
+
* Format namespace prefix
|
|
21
|
+
*/
|
|
22
|
+
private getPrefix;
|
|
18
23
|
/**
|
|
19
24
|
* Log debug message
|
|
20
25
|
*/
|