nanodb-orm 0.0.3 → 0.0.5
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 +506 -333
- package/dist/cli.d.ts +96 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +348 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants/index.d.ts +7 -54
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +9 -61
- package/dist/constants/index.js.map +1 -1
- package/dist/core/config.d.ts +3 -13
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +5 -27
- package/dist/core/config.js.map +1 -1
- package/dist/core/connection.d.ts +16 -31
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +42 -78
- package/dist/core/connection.js.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -18
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +235 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +252 -35
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +127 -18
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +280 -47
- package/dist/init.js.map +1 -1
- package/dist/jest.setup.d.ts +4 -0
- package/dist/jest.setup.d.ts.map +1 -0
- package/dist/jest.setup.js +40 -0
- package/dist/jest.setup.js.map +1 -0
- package/dist/types/errors.d.ts +30 -12
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +98 -23
- package/dist/types/errors.js.map +1 -1
- package/dist/types/index.d.ts +268 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +5 -4
- package/dist/types/index.js.map +1 -1
- package/dist/utils/error-handler.d.ts +6 -31
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +24 -81
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.d.ts +6 -25
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +20 -38
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/migrations.d.ts +16 -90
- package/dist/utils/migrations.d.ts.map +1 -1
- package/dist/utils/migrations.js +220 -422
- package/dist/utils/migrations.js.map +1 -1
- package/dist/utils/schema-introspection.d.ts +30 -169
- package/dist/utils/schema-introspection.d.ts.map +1 -1
- package/dist/utils/schema-introspection.js +125 -462
- package/dist/utils/schema-introspection.js.map +1 -1
- package/dist/utils/seeds.d.ts +15 -48
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +108 -186
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sync.d.ts +16 -41
- package/dist/utils/sync.d.ts.map +1 -1
- package/dist/utils/sync.js +78 -172
- package/dist/utils/sync.js.map +1 -1
- package/dist/utils/transactions.d.ts +61 -44
- package/dist/utils/transactions.d.ts.map +1 -1
- package/dist/utils/transactions.js +103 -137
- package/dist/utils/transactions.js.map +1 -1
- package/package.json +29 -10
- package/dist/example.d.ts +0 -67
- package/dist/example.d.ts.map +0 -1
- package/dist/example.js +0 -86
- package/dist/example.js.map +0 -1
- package/dist/types/database.d.ts +0 -74
- package/dist/types/database.d.ts.map +0 -1
- package/dist/types/database.js +0 -6
- package/dist/types/database.js.map +0 -1
- package/dist/types/types.d.ts +0 -30
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js +0 -6
- package/dist/types/types.js.map +0 -1
- package/llm.txt +0 -336
package/dist/init.js
CHANGED
|
@@ -1,63 +1,296 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Database initialization utility
|
|
4
|
-
* Initializes the db package with schema data to work as an npm package
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDatabase = createDatabase;
|
|
7
4
|
exports.initializeDatabase = initializeDatabase;
|
|
8
|
-
exports.getSchemaInfo = getSchemaInfo;
|
|
9
5
|
const schema_introspection_1 = require("./utils/schema-introspection");
|
|
10
6
|
const seeds_1 = require("./utils/seeds");
|
|
11
7
|
const migrations_1 = require("./utils/migrations");
|
|
8
|
+
const sync_1 = require("./utils/sync");
|
|
9
|
+
const connection_1 = require("./core/connection");
|
|
12
10
|
const logger_1 = require("./utils/logger");
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Hook System
|
|
13
|
+
// ============================================================================
|
|
14
|
+
const HOOK_TYPES = [
|
|
15
|
+
'beforeInsert', 'afterInsert',
|
|
16
|
+
'beforeUpdate', 'afterUpdate',
|
|
17
|
+
'beforeDelete', 'afterDelete',
|
|
18
|
+
'beforeQuery', 'afterQuery',
|
|
19
|
+
];
|
|
20
|
+
/** Create hook runner from plugins (optimized - computes hook map once) */
|
|
21
|
+
function createHooks(plugins) {
|
|
22
|
+
const hookMap = new Map();
|
|
23
|
+
const errorHandlers = [];
|
|
24
|
+
const readyHandlers = [];
|
|
25
|
+
// Build hook map (O(n) - runs once at startup)
|
|
26
|
+
for (const type of HOOK_TYPES) {
|
|
27
|
+
const fns = plugins
|
|
28
|
+
.map((p) => p[type])
|
|
29
|
+
.filter((fn) => fn !== undefined);
|
|
30
|
+
if (fns.length > 0)
|
|
31
|
+
hookMap.set(type, fns);
|
|
32
|
+
}
|
|
33
|
+
// Collect lifecycle handlers
|
|
34
|
+
for (const plugin of plugins) {
|
|
35
|
+
if (plugin.onError)
|
|
36
|
+
errorHandlers.push(plugin.onError);
|
|
37
|
+
if (plugin.onReady)
|
|
38
|
+
readyHandlers.push(plugin.onReady);
|
|
39
|
+
}
|
|
40
|
+
/** Execute hooks - O(1) lookup, then O(k) for k hooks */
|
|
41
|
+
const run = (type, table, data, result) => {
|
|
42
|
+
const fns = hookMap.get(type);
|
|
43
|
+
if (!fns)
|
|
44
|
+
return data;
|
|
45
|
+
// "before" hooks can transform data, "after" hooks just execute
|
|
46
|
+
if (type.startsWith('before')) {
|
|
47
|
+
return fns.reduce((acc, fn) => fn(table, acc) ?? acc, data);
|
|
48
|
+
}
|
|
49
|
+
fns.forEach((fn) => fn(table, data, result));
|
|
50
|
+
return data;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
beforeInsert: (t, d) => run('beforeInsert', t, d),
|
|
54
|
+
afterInsert: (t, d, r) => run('afterInsert', t, d, r),
|
|
55
|
+
beforeUpdate: (t, d) => run('beforeUpdate', t, d),
|
|
56
|
+
afterUpdate: (t, d, r) => run('afterUpdate', t, d, r),
|
|
57
|
+
beforeDelete: (t, d) => run('beforeDelete', t, d),
|
|
58
|
+
afterDelete: (t, d, r) => run('afterDelete', t, d, r),
|
|
59
|
+
beforeQuery: (t, d) => run('beforeQuery', t, d),
|
|
60
|
+
afterQuery: (t, d, r) => run('afterQuery', t, d, r),
|
|
61
|
+
onError: (e, op, t) => errorHandlers.forEach((h) => h(e, op, t)),
|
|
62
|
+
onReady: (db) => readyHandlers.forEach((h) => h(db)),
|
|
63
|
+
has: (type) => hookMap.has(type),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// Database Creation
|
|
68
|
+
// ============================================================================
|
|
69
|
+
/** Extract table name from Drizzle table object */
|
|
70
|
+
function getTableName(table) {
|
|
71
|
+
// Access the internal Drizzle name symbol
|
|
72
|
+
const t = table;
|
|
73
|
+
const name = t[Symbol.for('drizzle:Name')] ?? t._?.name;
|
|
74
|
+
return typeof name === 'string' ? name : 'unknown';
|
|
75
|
+
}
|
|
13
76
|
/**
|
|
14
|
-
*
|
|
15
|
-
* This
|
|
77
|
+
* Create and initialize the database with schema, migrations, seeds, and plugins.
|
|
78
|
+
* This is the main entry point for nanodb-orm.
|
|
79
|
+
*
|
|
80
|
+
* The returned database instance is fully type-safe - all queries, inserts, and
|
|
81
|
+
* updates will have proper TypeScript types inferred from your schema.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { createDatabase, table, integer, text } from 'nanodb-orm';
|
|
86
|
+
*
|
|
87
|
+
* const users = table('users', {
|
|
88
|
+
* id: integer('id').primaryKey({ autoIncrement: true }),
|
|
89
|
+
* name: text('name').notNull(),
|
|
90
|
+
* email: text('email').notNull(),
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* const db = await createDatabase({
|
|
94
|
+
* tables: { users },
|
|
95
|
+
* seedData: { users: [{ name: 'Alice', email: 'alice@example.com' }] },
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* // Fully typed! `allUsers` is User[]
|
|
99
|
+
* const allUsers = await db.select().from(users);
|
|
100
|
+
*
|
|
101
|
+
* // Type error if you try to insert invalid data
|
|
102
|
+
* await db.insert(users).values({ name: 'Bob', email: 'bob@example.com' });
|
|
103
|
+
* ```
|
|
16
104
|
*/
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
logger_1.logger.info('Database package initialized successfully!');
|
|
45
|
-
logger_1.logger.info(`Loaded ${tableNames.length} tables: ${tableNames.join(', ')}`);
|
|
46
|
-
logger_1.logger.info(`Loaded seed data for ${Object.keys(schemaData.seedData || {}).length} tables`);
|
|
105
|
+
async function createDatabase(config) {
|
|
106
|
+
// Initialize all modules with schema
|
|
107
|
+
initializeDatabase(config);
|
|
108
|
+
// Run migrations and seed
|
|
109
|
+
await migrations_1.DatabaseMigrations.initializeSchema();
|
|
110
|
+
if (config.seedData)
|
|
111
|
+
await seeds_1.DatabaseSeeds.seed();
|
|
112
|
+
// Get Drizzle instance and setup plugins
|
|
113
|
+
const drizzle = await connection_1.DatabaseConnection.getInstance();
|
|
114
|
+
const plugins = config.plugins ?? [];
|
|
115
|
+
const hooks = createHooks(plugins);
|
|
116
|
+
// Store original methods
|
|
117
|
+
const originalInsert = drizzle.insert.bind(drizzle);
|
|
118
|
+
const originalUpdate = drizzle.update.bind(drizzle);
|
|
119
|
+
const originalDelete = drizzle.delete.bind(drizzle);
|
|
120
|
+
const originalSelect = drizzle.select.bind(drizzle);
|
|
121
|
+
// Helper to wrap promise with after hook (preserves original type)
|
|
122
|
+
function wrapWithAfterHook(promise, afterFn) {
|
|
123
|
+
const original = promise.then.bind(promise);
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
promise.then = function (onFulfilled, onRejected) {
|
|
126
|
+
return original((result) => {
|
|
127
|
+
afterFn();
|
|
128
|
+
return onFulfilled ? onFulfilled(result) : result;
|
|
129
|
+
}, onRejected);
|
|
130
|
+
};
|
|
131
|
+
return promise;
|
|
47
132
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
133
|
+
const wrappedSelect = new Proxy(originalSelect, {
|
|
134
|
+
apply(target, _thisArg, args) {
|
|
135
|
+
const builder = target(...args);
|
|
136
|
+
const originalFrom = builder.from;
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
+
builder.from = new Proxy(originalFrom, {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
apply(fromTarget, fromThis, fromArgs) {
|
|
141
|
+
const table = fromArgs[0];
|
|
142
|
+
const tableName = getTableName(table);
|
|
143
|
+
hooks.beforeQuery(tableName, args[0] ?? '*');
|
|
144
|
+
const result = fromTarget.apply(fromThis, fromArgs);
|
|
145
|
+
// Wrap then() to call afterQuery
|
|
146
|
+
const originalThen = result.then.bind(result);
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
|
+
result.then = function (onFulfilled, onRejected) {
|
|
149
|
+
return originalThen((rows) => {
|
|
150
|
+
hooks.afterQuery(tableName, args[0] ?? '*', rows);
|
|
151
|
+
return onFulfilled ? onFulfilled(rows) : rows;
|
|
152
|
+
}, onRejected);
|
|
153
|
+
};
|
|
154
|
+
return result;
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return builder;
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const wrappedInsert = ((table) => {
|
|
161
|
+
const tableName = getTableName(table);
|
|
162
|
+
const builder = originalInsert(table);
|
|
163
|
+
const originalValues = builder.values.bind(builder);
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
|
+
builder.values = (data) => {
|
|
166
|
+
try {
|
|
167
|
+
const processed = Array.isArray(data)
|
|
168
|
+
? data.map((d) => hooks.beforeInsert(tableName, d))
|
|
169
|
+
: hooks.beforeInsert(tableName, data);
|
|
170
|
+
const result = originalValues(processed);
|
|
171
|
+
return wrapWithAfterHook(result, () => hooks.afterInsert(tableName, processed, result));
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
hooks.onError(err, 'insert', tableName);
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
return builder;
|
|
179
|
+
});
|
|
180
|
+
const wrappedUpdate = ((table) => {
|
|
181
|
+
const tableName = getTableName(table);
|
|
182
|
+
const builder = originalUpdate(table);
|
|
183
|
+
const originalSet = builder.set.bind(builder);
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
+
builder.set = (data) => {
|
|
186
|
+
try {
|
|
187
|
+
const processed = hooks.beforeUpdate(tableName, data);
|
|
188
|
+
const result = originalSet(processed);
|
|
189
|
+
return wrapWithAfterHook(result, () => hooks.afterUpdate(tableName, processed, result));
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
hooks.onError(err, 'update', tableName);
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
return builder;
|
|
197
|
+
});
|
|
198
|
+
const wrappedDelete = ((table) => {
|
|
199
|
+
const tableName = getTableName(table);
|
|
200
|
+
const builder = originalDelete(table);
|
|
201
|
+
const originalWhere = builder.where.bind(builder);
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
builder.where = (condition) => {
|
|
204
|
+
try {
|
|
205
|
+
hooks.beforeDelete(tableName, condition ?? {});
|
|
206
|
+
const result = originalWhere(condition);
|
|
207
|
+
return wrapWithAfterHook(result, () => hooks.afterDelete(tableName, condition ?? {}, result));
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
hooks.onError(err, 'delete', tableName);
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return builder;
|
|
215
|
+
});
|
|
216
|
+
// Schema utilities with proper typing
|
|
217
|
+
const schemaUtils = {
|
|
218
|
+
tables: () => schema_introspection_1.SchemaIntrospection.getAllTableNames(),
|
|
219
|
+
getTable: (name) => schema_introspection_1.SchemaIntrospection.getTableInfo(String(name)),
|
|
220
|
+
getColumns: (name) => schema_introspection_1.SchemaIntrospection.getTableColumns(String(name)),
|
|
221
|
+
validate: () => schema_introspection_1.SchemaIntrospection.validateSchema(),
|
|
222
|
+
stats: () => schema_introspection_1.SchemaIntrospection.getSchemaStats(),
|
|
223
|
+
relationships: () => schema_introspection_1.SchemaIntrospection.getTableRelationships(),
|
|
224
|
+
};
|
|
225
|
+
// Build enhanced db instance with utilities
|
|
226
|
+
let db = Object.assign(drizzle, {
|
|
227
|
+
select: wrappedSelect,
|
|
228
|
+
insert: wrappedInsert,
|
|
229
|
+
update: wrappedUpdate,
|
|
230
|
+
delete: wrappedDelete,
|
|
231
|
+
// Health & sync
|
|
232
|
+
healthCheck: () => sync_1.DatabaseSync.healthCheck(),
|
|
233
|
+
isReady: () => sync_1.DatabaseSync.isReady(),
|
|
234
|
+
sync: () => sync_1.DatabaseSync.sync(),
|
|
235
|
+
reset: () => sync_1.DatabaseSync.reset(),
|
|
236
|
+
seed: () => seeds_1.DatabaseSeeds.seed(),
|
|
237
|
+
clearData: () => seeds_1.DatabaseSeeds.clearAllData(),
|
|
238
|
+
// Schema introspection
|
|
239
|
+
schema: schemaUtils,
|
|
240
|
+
// Migration utilities
|
|
241
|
+
migrations: {
|
|
242
|
+
run: () => migrations_1.DatabaseMigrations.initializeSchema(),
|
|
243
|
+
validate: () => migrations_1.DatabaseMigrations.validateSchema(),
|
|
244
|
+
checkTables: () => migrations_1.DatabaseMigrations.checkTableExistence(),
|
|
245
|
+
},
|
|
246
|
+
// Plugin info
|
|
247
|
+
plugins: { list: () => plugins.map((p) => p.name) },
|
|
248
|
+
hooks,
|
|
249
|
+
});
|
|
250
|
+
// Apply plugin installers
|
|
251
|
+
for (const plugin of plugins) {
|
|
252
|
+
if (plugin.install) {
|
|
253
|
+
const result = plugin.install(db);
|
|
254
|
+
if (result)
|
|
255
|
+
db = result;
|
|
256
|
+
}
|
|
51
257
|
}
|
|
258
|
+
// Trigger ready hooks
|
|
259
|
+
hooks.onReady(db);
|
|
260
|
+
return db;
|
|
52
261
|
}
|
|
262
|
+
// ============================================================================
|
|
263
|
+
// Module Initialization
|
|
264
|
+
// ============================================================================
|
|
265
|
+
/** Default migration settings */
|
|
266
|
+
const DEFAULT_MIGRATION_CONFIG = {
|
|
267
|
+
preserveData: true,
|
|
268
|
+
autoMigrate: true,
|
|
269
|
+
dropTables: false,
|
|
270
|
+
};
|
|
53
271
|
/**
|
|
54
|
-
*
|
|
272
|
+
* Initialize internal modules with schema data.
|
|
273
|
+
* Prefer `createDatabase()` which calls this automatically.
|
|
274
|
+
*
|
|
275
|
+
* @internal
|
|
55
276
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
277
|
+
function initializeDatabase(schemaData) {
|
|
278
|
+
const tableNames = Object.keys(schemaData.tables);
|
|
279
|
+
logger_1.logger.info(`Initializing with ${tableNames.length} tables: ${tableNames.join(', ')}`);
|
|
280
|
+
schema_introspection_1.SchemaIntrospection.initialize({
|
|
281
|
+
tables: schemaData.tables,
|
|
282
|
+
tableNames,
|
|
283
|
+
});
|
|
284
|
+
migrations_1.DatabaseMigrations.initialize({
|
|
285
|
+
tables: schemaData.tables,
|
|
286
|
+
tableNames,
|
|
287
|
+
migrationConfig: { ...DEFAULT_MIGRATION_CONFIG, ...schemaData.migrationConfig },
|
|
288
|
+
});
|
|
289
|
+
seeds_1.DatabaseSeeds.initialize({
|
|
290
|
+
tables: schemaData.tables,
|
|
291
|
+
tableNames,
|
|
292
|
+
seedData: (schemaData.seedData ?? {}),
|
|
293
|
+
});
|
|
294
|
+
logger_1.logger.info('Database initialized');
|
|
62
295
|
}
|
|
63
296
|
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../init.ts"],"names":[],"mappings":";;AAkOA,wCAuMC;AAmBD,gDAuBC;AAndD,uEAAmE;AACnE,yCAA8C;AAC9C,mDAAwD;AACxD,uCAA4C;AAC5C,kDAAuD;AACvD,2CAAwC;AAuHxC,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,UAAU,GAAG;IACjB,cAAc,EAAE,aAAa;IAC7B,cAAc,EAAE,aAAa;IAC7B,cAAc,EAAE,aAAa;IAC7B,aAAa,EAAE,YAAY;CACnB,CAAC;AAIX,2EAA2E;AAC3E,SAAS,WAAW,CAAC,OAAqB;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,MAAM,aAAa,GAAkB,EAAE,CAAC;IACxC,MAAM,aAA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1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Jest setup file to mock native dependencies
|
|
4
|
+
*/
|
|
5
|
+
// Mock @libsql/client to avoid loading native modules in tests
|
|
6
|
+
jest.mock('@libsql/client', () => {
|
|
7
|
+
const mockClient = {
|
|
8
|
+
execute: jest.fn(),
|
|
9
|
+
batch: jest.fn(),
|
|
10
|
+
transaction: jest.fn(),
|
|
11
|
+
close: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
createClient: jest.fn(() => mockClient),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
// Mock drizzle-orm/libsql to avoid native module issues
|
|
18
|
+
jest.mock('drizzle-orm/libsql', () => {
|
|
19
|
+
const mockDb = {
|
|
20
|
+
select: jest.fn(() => ({
|
|
21
|
+
from: jest.fn(() => Promise.resolve([])),
|
|
22
|
+
})),
|
|
23
|
+
insert: jest.fn(() => ({
|
|
24
|
+
values: jest.fn(() => Promise.resolve({})),
|
|
25
|
+
})),
|
|
26
|
+
update: jest.fn(() => ({
|
|
27
|
+
set: jest.fn(() => ({
|
|
28
|
+
where: jest.fn(() => Promise.resolve({})),
|
|
29
|
+
})),
|
|
30
|
+
})),
|
|
31
|
+
delete: jest.fn(() => ({
|
|
32
|
+
where: jest.fn(() => Promise.resolve({})),
|
|
33
|
+
})),
|
|
34
|
+
run: jest.fn(() => Promise.resolve({})),
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
drizzle: jest.fn(() => mockDb),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=jest.setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.setup.js","sourceRoot":"","sources":["../jest.setup.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,+DAA+D;AAC/D,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,MAAM,UAAU,GAAG;QACj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EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;KACxC,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;KAC/B,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Custom
|
|
2
|
+
* Custom error types for database operations
|
|
3
3
|
*/
|
|
4
|
+
interface ErrorOptions {
|
|
5
|
+
table?: string | undefined;
|
|
6
|
+
detail?: string | undefined;
|
|
7
|
+
cause?: Error | undefined;
|
|
8
|
+
}
|
|
4
9
|
export declare class DatabaseError extends Error {
|
|
5
10
|
readonly operation: string;
|
|
6
|
-
readonly
|
|
7
|
-
|
|
11
|
+
readonly table: string | undefined;
|
|
12
|
+
readonly detail: string | undefined;
|
|
13
|
+
readonly originalError: Error | undefined;
|
|
14
|
+
constructor(message: string, operation: string, options?: ErrorOptions);
|
|
15
|
+
/** Format error for display */
|
|
16
|
+
format(): string;
|
|
17
|
+
/** Override toString for cleaner console output */
|
|
18
|
+
toString(): string;
|
|
8
19
|
}
|
|
9
20
|
export declare class SchemaError extends DatabaseError {
|
|
10
|
-
|
|
11
|
-
constructor(message: string, tableName?: string | undefined, originalError?: Error);
|
|
12
|
-
}
|
|
13
|
-
export declare class SyncError extends DatabaseError {
|
|
14
|
-
constructor(message: string, originalError?: Error);
|
|
21
|
+
constructor(message: string, table?: string, detail?: string);
|
|
15
22
|
}
|
|
16
23
|
export declare class ConnectionError extends DatabaseError {
|
|
17
|
-
constructor(message: string,
|
|
24
|
+
constructor(message: string, detail?: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class MigrationError extends DatabaseError {
|
|
27
|
+
constructor(message: string, table?: string, detail?: string);
|
|
18
28
|
}
|
|
19
|
-
export declare class
|
|
20
|
-
|
|
21
|
-
constructor(message: string, field?: string | undefined, originalError?: Error);
|
|
29
|
+
export declare class SeedError extends DatabaseError {
|
|
30
|
+
constructor(message: string, table?: string, detail?: string);
|
|
22
31
|
}
|
|
32
|
+
interface ParseContext {
|
|
33
|
+
table?: string | undefined;
|
|
34
|
+
operation?: string | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse internal database errors into user-friendly messages
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseDbError(error: unknown, context?: ParseContext): DatabaseError;
|
|
40
|
+
export {};
|
|
23
41
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../types/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,aAAc,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../types/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,UAAU,YAAY;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC3B;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,KAAK,GAAG,SAAS,CAAC;gBAE9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAStE,+BAA+B;IAC/B,MAAM,IAAI,MAAM;IAiBhB,mDAAmD;IACnD,QAAQ,IAAI,MAAM;CAGnB;AAED,qBAAa,WAAY,SAAQ,aAAa;gBAChC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAI7D;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAI7C;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAI7D;AAED,qBAAa,SAAU,SAAQ,aAAa;gBAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAI7D;AAED,UAAU,YAAY;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AA4BD;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,aAAa,CA6ClF"}
|
package/dist/types/errors.js
CHANGED
|
@@ -1,46 +1,121 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Custom
|
|
3
|
+
* Custom error types for database operations
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.SeedError = exports.MigrationError = exports.ConnectionError = exports.SchemaError = exports.DatabaseError = void 0;
|
|
7
|
+
exports.parseDbError = parseDbError;
|
|
7
8
|
class DatabaseError extends Error {
|
|
8
|
-
constructor(message, operation,
|
|
9
|
+
constructor(message, operation, options) {
|
|
9
10
|
super(message);
|
|
10
|
-
this.operation = operation;
|
|
11
|
-
this.originalError = originalError;
|
|
12
11
|
this.name = 'DatabaseError';
|
|
12
|
+
this.operation = operation;
|
|
13
|
+
this.table = options?.table;
|
|
14
|
+
this.detail = options?.detail;
|
|
15
|
+
this.originalError = options?.cause;
|
|
16
|
+
}
|
|
17
|
+
/** Format error for display */
|
|
18
|
+
format() {
|
|
19
|
+
const lines = [
|
|
20
|
+
'',
|
|
21
|
+
`┌─ nanodb-orm error ─────────────────────────────`,
|
|
22
|
+
`│ ${this.message}`,
|
|
23
|
+
];
|
|
24
|
+
if (this.table)
|
|
25
|
+
lines.push(`│ Table: ${this.table}`);
|
|
26
|
+
if (this.operation)
|
|
27
|
+
lines.push(`│ Operation: ${this.operation}`);
|
|
28
|
+
if (this.detail)
|
|
29
|
+
lines.push(`│ Detail: ${this.detail}`);
|
|
30
|
+
lines.push(`└────────────────────────────────────────────────`);
|
|
31
|
+
lines.push('');
|
|
32
|
+
return lines.join('\n');
|
|
33
|
+
}
|
|
34
|
+
/** Override toString for cleaner console output */
|
|
35
|
+
toString() {
|
|
36
|
+
return this.format();
|
|
13
37
|
}
|
|
14
38
|
}
|
|
15
39
|
exports.DatabaseError = DatabaseError;
|
|
16
40
|
class SchemaError extends DatabaseError {
|
|
17
|
-
constructor(message,
|
|
18
|
-
super(message, 'schema',
|
|
19
|
-
this.tableName = tableName;
|
|
41
|
+
constructor(message, table, detail) {
|
|
42
|
+
super(message, 'schema', { table, detail });
|
|
20
43
|
this.name = 'SchemaError';
|
|
21
44
|
}
|
|
22
45
|
}
|
|
23
46
|
exports.SchemaError = SchemaError;
|
|
24
|
-
class SyncError extends DatabaseError {
|
|
25
|
-
constructor(message, originalError) {
|
|
26
|
-
super(message, 'sync', originalError);
|
|
27
|
-
this.name = 'SyncError';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.SyncError = SyncError;
|
|
31
47
|
class ConnectionError extends DatabaseError {
|
|
32
|
-
constructor(message,
|
|
33
|
-
super(message, 'connection',
|
|
48
|
+
constructor(message, detail) {
|
|
49
|
+
super(message, 'connection', { detail });
|
|
34
50
|
this.name = 'ConnectionError';
|
|
35
51
|
}
|
|
36
52
|
}
|
|
37
53
|
exports.ConnectionError = ConnectionError;
|
|
38
|
-
class
|
|
39
|
-
constructor(message,
|
|
40
|
-
super(message, '
|
|
41
|
-
this.
|
|
42
|
-
|
|
54
|
+
class MigrationError extends DatabaseError {
|
|
55
|
+
constructor(message, table, detail) {
|
|
56
|
+
super(message, 'migration', { table, detail });
|
|
57
|
+
this.name = 'MigrationError';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.MigrationError = MigrationError;
|
|
61
|
+
class SeedError extends DatabaseError {
|
|
62
|
+
constructor(message, table, detail) {
|
|
63
|
+
super(message, 'seed', { table, detail });
|
|
64
|
+
this.name = 'SeedError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SeedError = SeedError;
|
|
68
|
+
/**
|
|
69
|
+
* Extract the root error message, traversing the cause chain
|
|
70
|
+
*/
|
|
71
|
+
function getRootMessage(error) {
|
|
72
|
+
if (!(error instanceof Error))
|
|
73
|
+
return String(error);
|
|
74
|
+
// Check for nested cause (drizzle wraps libsql errors)
|
|
75
|
+
let current = error;
|
|
76
|
+
let deepestMessage = error.message;
|
|
77
|
+
while (current instanceof Error) {
|
|
78
|
+
deepestMessage = current.message;
|
|
79
|
+
// Check various cause patterns
|
|
80
|
+
const err = current;
|
|
81
|
+
if (err.cause) {
|
|
82
|
+
current = err.cause;
|
|
83
|
+
}
|
|
84
|
+
else if (err.originalError) {
|
|
85
|
+
current = err.originalError;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return deepestMessage;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parse internal database errors into user-friendly messages
|
|
95
|
+
*/
|
|
96
|
+
function parseDbError(error, context) {
|
|
97
|
+
const rootMsg = getRootMessage(error);
|
|
98
|
+
const op = context?.operation ?? 'query';
|
|
99
|
+
const tbl = context?.table;
|
|
100
|
+
// SQLite constraint errors
|
|
101
|
+
if (rootMsg.includes('SQLITE_CONSTRAINT_NOTNULL')) {
|
|
102
|
+
const match = rootMsg.match(/NOT NULL constraint failed: (\w+)\.(\w+)/);
|
|
103
|
+
const col = match ? match[2] : 'unknown column';
|
|
104
|
+
return new DatabaseError(`Missing required value for column "${col}"`, op, { table: tbl, detail: 'This column is NOT NULL but no value was provided' });
|
|
105
|
+
}
|
|
106
|
+
if (rootMsg.includes('SQLITE_CONSTRAINT_UNIQUE')) {
|
|
107
|
+
return new DatabaseError('Duplicate value for unique column', op, { table: tbl, detail: 'A record with this value already exists' });
|
|
108
|
+
}
|
|
109
|
+
if (rootMsg.includes('no column named')) {
|
|
110
|
+
const col = rootMsg.match(/no column named (\w+)/)?.[1] ?? 'unknown';
|
|
111
|
+
return new DatabaseError(`Column "${col}" does not exist`, op, { table: tbl, detail: 'Your seed data has a column that is not in the table schema' });
|
|
112
|
+
}
|
|
113
|
+
if (rootMsg.includes('no such table')) {
|
|
114
|
+
const tableName = rootMsg.match(/no such table: (\w+)/)?.[1] ?? tbl ?? 'unknown';
|
|
115
|
+
return new DatabaseError(`Table "${tableName}" does not exist`, op, { table: tableName, detail: 'Run DatabaseSync.setup() to create tables' });
|
|
43
116
|
}
|
|
117
|
+
// Generic fallback - first line only, clean up
|
|
118
|
+
const cleanMsg = rootMsg.split('\n')[0]?.replace(/^SQLITE_\w+:\s*/, '') ?? rootMsg;
|
|
119
|
+
return new DatabaseError(cleanMsg, op, { table: tbl });
|
|
44
120
|
}
|
|
45
|
-
exports.ValidationError = ValidationError;
|
|
46
121
|
//# sourceMappingURL=errors.js.map
|