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.
Files changed (87) hide show
  1. package/README.md +506 -333
  2. package/dist/cli.d.ts +96 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +348 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/constants/index.d.ts +7 -54
  7. package/dist/constants/index.d.ts.map +1 -1
  8. package/dist/constants/index.js +9 -61
  9. package/dist/constants/index.js.map +1 -1
  10. package/dist/core/config.d.ts +3 -13
  11. package/dist/core/config.d.ts.map +1 -1
  12. package/dist/core/config.js +5 -27
  13. package/dist/core/config.js.map +1 -1
  14. package/dist/core/connection.d.ts +16 -31
  15. package/dist/core/connection.d.ts.map +1 -1
  16. package/dist/core/connection.js +42 -78
  17. package/dist/core/connection.js.map +1 -1
  18. package/dist/core/index.d.ts +2 -3
  19. package/dist/core/index.d.ts.map +1 -1
  20. package/dist/core/index.js +3 -18
  21. package/dist/core/index.js.map +1 -1
  22. package/dist/index.d.ts +235 -12
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +252 -35
  25. package/dist/index.js.map +1 -1
  26. package/dist/init.d.ts +127 -18
  27. package/dist/init.d.ts.map +1 -1
  28. package/dist/init.js +280 -47
  29. package/dist/init.js.map +1 -1
  30. package/dist/jest.setup.d.ts +4 -0
  31. package/dist/jest.setup.d.ts.map +1 -0
  32. package/dist/jest.setup.js +40 -0
  33. package/dist/jest.setup.js.map +1 -0
  34. package/dist/types/errors.d.ts +30 -12
  35. package/dist/types/errors.d.ts.map +1 -1
  36. package/dist/types/errors.js +98 -23
  37. package/dist/types/errors.js.map +1 -1
  38. package/dist/types/index.d.ts +268 -4
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/index.js +5 -4
  41. package/dist/types/index.js.map +1 -1
  42. package/dist/utils/error-handler.d.ts +6 -31
  43. package/dist/utils/error-handler.d.ts.map +1 -1
  44. package/dist/utils/error-handler.js +24 -81
  45. package/dist/utils/error-handler.js.map +1 -1
  46. package/dist/utils/index.d.ts +1 -3
  47. package/dist/utils/index.d.ts.map +1 -1
  48. package/dist/utils/index.js +4 -6
  49. package/dist/utils/index.js.map +1 -1
  50. package/dist/utils/logger.d.ts +6 -25
  51. package/dist/utils/logger.d.ts.map +1 -1
  52. package/dist/utils/logger.js +20 -38
  53. package/dist/utils/logger.js.map +1 -1
  54. package/dist/utils/migrations.d.ts +16 -90
  55. package/dist/utils/migrations.d.ts.map +1 -1
  56. package/dist/utils/migrations.js +220 -422
  57. package/dist/utils/migrations.js.map +1 -1
  58. package/dist/utils/schema-introspection.d.ts +30 -169
  59. package/dist/utils/schema-introspection.d.ts.map +1 -1
  60. package/dist/utils/schema-introspection.js +125 -462
  61. package/dist/utils/schema-introspection.js.map +1 -1
  62. package/dist/utils/seeds.d.ts +15 -48
  63. package/dist/utils/seeds.d.ts.map +1 -1
  64. package/dist/utils/seeds.js +108 -186
  65. package/dist/utils/seeds.js.map +1 -1
  66. package/dist/utils/sync.d.ts +16 -41
  67. package/dist/utils/sync.d.ts.map +1 -1
  68. package/dist/utils/sync.js +78 -172
  69. package/dist/utils/sync.js.map +1 -1
  70. package/dist/utils/transactions.d.ts +61 -44
  71. package/dist/utils/transactions.d.ts.map +1 -1
  72. package/dist/utils/transactions.js +103 -137
  73. package/dist/utils/transactions.js.map +1 -1
  74. package/package.json +29 -10
  75. package/dist/example.d.ts +0 -67
  76. package/dist/example.d.ts.map +0 -1
  77. package/dist/example.js +0 -86
  78. package/dist/example.js.map +0 -1
  79. package/dist/types/database.d.ts +0 -74
  80. package/dist/types/database.d.ts.map +0 -1
  81. package/dist/types/database.js +0 -6
  82. package/dist/types/database.js.map +0 -1
  83. package/dist/types/types.d.ts +0 -30
  84. package/dist/types/types.d.ts.map +0 -1
  85. package/dist/types/types.js +0 -6
  86. package/dist/types/types.js.map +0 -1
  87. 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
- * Initialize the database package with schema data
15
- * This allows the db package to work independently without direct imports
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 initializeDatabase(schemaData) {
18
- try {
19
- logger_1.logger.info('Initializing database package with schema data...');
20
- // Derive table names from the tables object
21
- const tableNames = Object.keys(schemaData.tables);
22
- // Initialize schema introspection
23
- schema_introspection_1.SchemaIntrospection.initialize({
24
- tables: schemaData.tables,
25
- tableNames: tableNames,
26
- });
27
- // Initialize database migrations
28
- migrations_1.DatabaseMigrations.initialize({
29
- tables: schemaData.tables,
30
- tableNames: tableNames,
31
- migrationConfig: {
32
- preserveData: true, // Always preserve data by default
33
- autoMigrate: true, // Default to auto-migration
34
- dropTables: false, // Default to not dropping tables
35
- ...schemaData.migrationConfig, // Override with any provided config
36
- },
37
- });
38
- // Initialize database seeds
39
- seeds_1.DatabaseSeeds.initialize({
40
- tables: schemaData.tables,
41
- tableNames: tableNames,
42
- seedData: schemaData.seedData || {},
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
- catch (error) {
49
- logger_1.logger.error('Failed to initialize database package:', error);
50
- throw error;
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
- * Get initialized schema data (for verification)
272
+ * Initialize internal modules with schema data.
273
+ * Prefer `createDatabase()` which calls this automatically.
274
+ *
275
+ * @internal
55
276
  */
56
- function getSchemaInfo() {
57
- return {
58
- tableNames: schema_introspection_1.SchemaIntrospection.getAllTableNames(),
59
- tableCount: schema_introspection_1.SchemaIntrospection.getTableCount(),
60
- seedDataTables: Object.keys(seeds_1.DatabaseSeeds['seedData'] || {}),
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":";AAAA;;;GAGG;;AAuBH,gDAwCC;AAKD,sCAUC;AA5ED,uEAAmE;AACnE,yCAA8C;AAC9C,mDAAwD;AACxD,2CAAwC;AAcxC;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,UAAsB;IACvD,IAAI,CAAC;QACH,eAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAEjE,4CAA4C;QAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAElD,kCAAkC;QAClC,0CAAmB,CAAC,UAAU,CAAC;YAC7B,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,UAAU,EAAE,UAAU;SACvB,CAAC,CAAC;QAEH,iCAAiC;QACjC,+BAAkB,CAAC,UAAU,CAAC;YAC5B,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,UAAU,EAAE,UAAU;YACtB,eAAe,EAAE;gBACf,YAAY,EAAE,IAAI,EAAE,kCAAkC;gBACtD,WAAW,EAAE,IAAI,EAAG,4BAA4B;gBAChD,UAAU,EAAE,KAAK,EAAG,iCAAiC;gBACrD,GAAG,UAAU,CAAC,eAAe,EAAE,oCAAoC;aACpE;SACF,CAAC,CAAC;QAEH,4BAA4B;QAC5B,qBAAa,CAAC,UAAU,CAAC;YACvB,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,UAAU,EAAE,UAAU;YACtB,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;SACpC,CAAC,CAAC;QAEH,eAAM,C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,GAAG,MAAyB,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAElB,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,iCAAiC;AACjC,MAAM,wBAAwB,GAA8B;IAC1D,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAmB,UAAyB;IAC5E,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAElD,eAAM,CAAC,IAAI,CAAC,qBAAqB,UAAU,CAAC,MAAM,YAAY,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEvF,0CAAmB,CAAC,UAAU,CAAC;QAC7B,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,UAAU;KACX,CAAC,CAAC;IAEH,+BAAkB,CAAC,UAAU,CAAC;QAC5B,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,UAAU;QACV,eAAe,EAAE,EAAE,GAAG,wBAAwB,EAAE,GAAG,UAAU,CAAC,eAAe,EAAE;KAChF,CAAC,CAAC;IAEH,qBAAa,CAAC,UAAU,CAAC;QACvB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,UAAU;QACV,QAAQ,EAAE,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAA8C;KACnF,CAAC,CAAC;IAEH,eAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Jest setup file to mock native dependencies
3
+ */
4
+ //# sourceMappingURL=jest.setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../jest.setup.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +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;QACjB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;QAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;QACtB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;KACjB,CAAC;IAEF,OAAO;QACL,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC;KACxC,CAAC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ling
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 originalError?: Error | undefined;
7
- constructor(message: string, operation: string, originalError?: Error | undefined);
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
- readonly tableName?: string | undefined;
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, originalError?: Error);
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 ValidationError extends DatabaseError {
20
- readonly field?: string | undefined;
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;aACO,SAAS,EAAE,MAAM;aAAkB,aAAa,CAAC,EAAE,KAAK;gBAAzF,OAAO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,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"}
@@ -1,46 +1,121 @@
1
1
  "use strict";
2
2
  /**
3
- * Custom database error types for better error handling
3
+ * Custom error types for database operations
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ValidationError = exports.ConnectionError = exports.SyncError = exports.SchemaError = exports.DatabaseError = void 0;
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, originalError) {
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, tableName, originalError) {
18
- super(message, 'schema', originalError);
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, originalError) {
33
- super(message, 'connection', originalError);
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 ValidationError extends DatabaseError {
39
- constructor(message, field, originalError) {
40
- super(message, 'validation', originalError);
41
- this.field = field;
42
- this.name = 'ValidationError';
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