nanodb-orm 0.0.2 → 0.0.4
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 +211 -309
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +270 -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 +11 -20
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +35 -53
- 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 +40 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +76 -31
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +79 -22
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +246 -48
- 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 +130 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -3
- package/dist/types/index.js.map +1 -1
- package/dist/utils/error-handler.d.ts +11 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +36 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -2
- 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 +222 -412
- package/dist/utils/migrations.js.map +1 -1
- package/dist/utils/schema-introspection.d.ts +30 -173
- package/dist/utils/schema-introspection.d.ts.map +1 -1
- package/dist/utils/schema-introspection.js +129 -460
- 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 +101 -185
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sync.d.ts +16 -54
- package/dist/utils/sync.d.ts.map +1 -1
- package/dist/utils/sync.js +71 -173
- package/dist/utils/sync.js.map +1 -1
- package/dist/utils/transactions.d.ts +16 -0
- package/dist/utils/transactions.d.ts.map +1 -0
- package/dist/utils/transactions.js +44 -0
- package/dist/utils/transactions.js.map +1 -0
- 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/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 -268
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,134 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* TypeScript definitions for database-related functionality
|
|
2
|
+
* Type definitions for nanodb-orm
|
|
4
3
|
*/
|
|
5
|
-
export * from './types';
|
|
6
4
|
export * from './errors';
|
|
5
|
+
/** Drizzle table type - accepts real Drizzle tables from sqliteTable() */
|
|
6
|
+
export type DrizzleTable = Record<string, any>;
|
|
7
|
+
/** Hook function signature for CRUD operations */
|
|
8
|
+
export type HookFn = (table: string, data: any, result?: any) => any;
|
|
9
|
+
/** Error hook signature */
|
|
10
|
+
export type ErrorHookFn = (error: Error, operation: string, table?: string) => void;
|
|
11
|
+
/** Lifecycle hook signature */
|
|
12
|
+
export type LifecycleHookFn = (db: any) => void;
|
|
13
|
+
/** Plugin definition for extending nanodb-orm */
|
|
14
|
+
export interface NanoPlugin {
|
|
15
|
+
/** Unique plugin name */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Modify db instance during setup */
|
|
18
|
+
install?: (db: any) => any;
|
|
19
|
+
beforeInsert?: HookFn;
|
|
20
|
+
afterInsert?: HookFn;
|
|
21
|
+
beforeUpdate?: HookFn;
|
|
22
|
+
afterUpdate?: HookFn;
|
|
23
|
+
beforeDelete?: HookFn;
|
|
24
|
+
afterDelete?: HookFn;
|
|
25
|
+
beforeQuery?: HookFn;
|
|
26
|
+
afterQuery?: HookFn;
|
|
27
|
+
onError?: ErrorHookFn;
|
|
28
|
+
onReady?: LifecycleHookFn;
|
|
29
|
+
}
|
|
30
|
+
/** Drizzle column definition */
|
|
31
|
+
export interface DrizzleColumn {
|
|
32
|
+
name?: string;
|
|
33
|
+
columnName?: string;
|
|
34
|
+
dataType?: string;
|
|
35
|
+
columnType?: string;
|
|
36
|
+
type?: string;
|
|
37
|
+
primary?: boolean;
|
|
38
|
+
autoIncrement?: boolean;
|
|
39
|
+
notNull?: boolean;
|
|
40
|
+
unique?: boolean;
|
|
41
|
+
default?: unknown;
|
|
42
|
+
references?: {
|
|
43
|
+
table?: string;
|
|
44
|
+
foreignTable?: {
|
|
45
|
+
tableName?: string;
|
|
46
|
+
};
|
|
47
|
+
column?: string;
|
|
48
|
+
columnName?: string;
|
|
49
|
+
onDelete?: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Database client interface for raw queries */
|
|
53
|
+
export interface DatabaseClient {
|
|
54
|
+
run(query: string | {
|
|
55
|
+
queryChunks: unknown[];
|
|
56
|
+
}): Promise<QueryResult>;
|
|
57
|
+
insert?(table: unknown): {
|
|
58
|
+
values(data: unknown[]): Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
$client?: {
|
|
61
|
+
sync?: () => Promise<void>;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Query result from database operations */
|
|
65
|
+
export interface QueryResult {
|
|
66
|
+
rows: Record<string, unknown>[];
|
|
67
|
+
changes?: number;
|
|
68
|
+
lastInsertRowid?: number;
|
|
69
|
+
}
|
|
70
|
+
/** Migration behavior configuration */
|
|
71
|
+
export interface MigrationConfig {
|
|
72
|
+
/** Preserve existing data during migrations (default: true) */
|
|
73
|
+
preserveData?: boolean;
|
|
74
|
+
/** Automatically handle schema changes (default: true) */
|
|
75
|
+
autoMigrate?: boolean;
|
|
76
|
+
/** Allow dropping tables (default: false) */
|
|
77
|
+
dropTables?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** Schema initialization data */
|
|
80
|
+
export interface SchemaData {
|
|
81
|
+
tables: Record<string, DrizzleTable>;
|
|
82
|
+
seedData?: Record<string, Record<string, unknown>[]>;
|
|
83
|
+
migrationConfig?: MigrationConfig;
|
|
84
|
+
}
|
|
85
|
+
/** Database connection configuration */
|
|
86
|
+
export interface DatabaseConfig {
|
|
87
|
+
connectionUrl: string;
|
|
88
|
+
authToken: string;
|
|
89
|
+
}
|
|
90
|
+
/** Schema validation result */
|
|
91
|
+
export interface SchemaValidation {
|
|
92
|
+
isValid: boolean;
|
|
93
|
+
missingTables: string[];
|
|
94
|
+
extraTables: string[];
|
|
95
|
+
errors: string[];
|
|
96
|
+
}
|
|
97
|
+
/** Database health check result */
|
|
98
|
+
export interface HealthCheck {
|
|
99
|
+
healthy: boolean;
|
|
100
|
+
tables: string[];
|
|
101
|
+
tableCounts: Record<string, number>;
|
|
102
|
+
totalRecords: number;
|
|
103
|
+
schemaValid: boolean;
|
|
104
|
+
errors: string[];
|
|
105
|
+
}
|
|
106
|
+
/** Database info summary */
|
|
107
|
+
export interface DatabaseInfo {
|
|
108
|
+
tables: string[];
|
|
109
|
+
tableCounts: Record<string, number>;
|
|
110
|
+
totalRecords: number;
|
|
111
|
+
schemaValid: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** Sync operation result */
|
|
114
|
+
export interface SyncResult {
|
|
115
|
+
success: boolean;
|
|
116
|
+
message: string;
|
|
117
|
+
tablesSynced: string[];
|
|
118
|
+
errors: string[];
|
|
119
|
+
}
|
|
120
|
+
/** Foreign key definition */
|
|
121
|
+
export interface ForeignKey {
|
|
122
|
+
column: string;
|
|
123
|
+
references: string;
|
|
124
|
+
table: string;
|
|
125
|
+
}
|
|
126
|
+
/** Table metadata */
|
|
127
|
+
export interface TableMetadata {
|
|
128
|
+
name: string;
|
|
129
|
+
columns: string[];
|
|
130
|
+
primaryKey: string[];
|
|
131
|
+
foreignKeys: ForeignKey[];
|
|
132
|
+
indexes: string[];
|
|
133
|
+
}
|
|
7
134
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,UAAU,CAAC;AAMzB,0EAA0E;AAE1E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAM/C,kDAAkD;AAElD,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;AAErE,2BAA2B;AAC3B,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpF,+BAA+B;AAE/B,MAAM,MAAM,eAAe,GAAG,CAA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AE,CAAC;IACxB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,mCAAmC;AACnC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,4BAA4B;AAC5B,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,4BAA4B;AAC5B,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,6BAA6B;AAC7B,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAqB;AACrB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
package/dist/types/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* TypeScript definitions for database-related functionality
|
|
3
|
+
* Type definitions for nanodb-orm
|
|
5
4
|
*/
|
|
6
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
6
|
if (k2 === undefined) k2 = k;
|
|
@@ -18,6 +17,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
18
|
};
|
|
20
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
20
|
+
// Re-export errors
|
|
22
21
|
__exportStar(require("./errors"), exports);
|
|
23
22
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,mBAAmB;AACnB,2CAAyB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap an async operation with standardized error handling.
|
|
3
|
+
*/
|
|
4
|
+
export declare function withErrorHandling<T>(operation: string, fn: () => Promise<T>, context?: {
|
|
5
|
+
table?: string | undefined;
|
|
6
|
+
}): Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Log an error without throwing (for non-critical operations).
|
|
9
|
+
*/
|
|
10
|
+
export declare function logError(operation: string, error: unknown, table?: string): void;
|
|
11
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../utils/error-handler.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACvC,OAAO,CAAC,CAAC,CAAC,CAcZ;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAQhF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withErrorHandling = withErrorHandling;
|
|
4
|
+
exports.logError = logError;
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const errors_1 = require("../types/errors");
|
|
7
|
+
/**
|
|
8
|
+
* Wrap an async operation with standardized error handling.
|
|
9
|
+
*/
|
|
10
|
+
async function withErrorHandling(operation, fn, context) {
|
|
11
|
+
try {
|
|
12
|
+
return await fn();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// If already a DatabaseError, just re-throw (it's already been logged)
|
|
16
|
+
if (error instanceof errors_1.DatabaseError) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
// Parse internal errors into user-friendly format
|
|
20
|
+
const dbError = (0, errors_1.parseDbError)(error, { operation, table: context?.table });
|
|
21
|
+
logger_1.logger.error(dbError.format());
|
|
22
|
+
throw dbError;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Log an error without throwing (for non-critical operations).
|
|
27
|
+
*/
|
|
28
|
+
function logError(operation, error, table) {
|
|
29
|
+
if (error instanceof errors_1.DatabaseError) {
|
|
30
|
+
logger_1.logger.warn(error.format());
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const dbError = (0, errors_1.parseDbError)(error, { operation, table });
|
|
34
|
+
logger_1.logger.warn(dbError.format());
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../utils/error-handler.ts"],"names":[],"mappings":";;AAMA,8CAkBC;AAKD,4BAQC;AArCD,qCAAkC;AAClC,4CAA8D;AAE9D;;GAEG;AACI,KAAK,UAAU,iBAAiB,CACrC,SAAiB,EACjB,EAAoB,EACpB,OAAwC;IAExC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,uEAAuE;QACvE,IAAI,KAAK,YAAY,sBAAa,EAAE,CAAC;YACnC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,kDAAkD;QAClD,MAAM,OAAO,GAAG,IAAA,qBAAY,EAAC,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/B,MAAM,OAAO,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,SAAiB,EAAE,KAAc,EAAE,KAAc;IACxE,IAAI,KAAK,YAAY,sBAAa,EAAE,CAAC;QACnC,eAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,qBAAY,EAAC,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Database utilities
|
|
3
|
-
* Helper functions and services for database operations
|
|
4
3
|
*/
|
|
5
4
|
export { DatabaseSync } from './sync';
|
|
6
5
|
export { DatabaseMigrations } from './migrations';
|
|
7
6
|
export { DatabaseSeeds } from './seeds';
|
|
8
7
|
export { SchemaIntrospection } from './schema-introspection';
|
|
8
|
+
export { transaction, recreateTable } from './transactions';
|
|
9
9
|
export { logger } from './logger';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Database utilities
|
|
4
|
-
* Helper functions and services for database operations
|
|
5
4
|
*/
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.logger = exports.SchemaIntrospection = exports.DatabaseSeeds = exports.DatabaseMigrations = exports.DatabaseSync = void 0;
|
|
6
|
+
exports.logger = exports.recreateTable = exports.transaction = exports.SchemaIntrospection = exports.DatabaseSeeds = exports.DatabaseMigrations = exports.DatabaseSync = void 0;
|
|
8
7
|
var sync_1 = require("./sync");
|
|
9
8
|
Object.defineProperty(exports, "DatabaseSync", { enumerable: true, get: function () { return sync_1.DatabaseSync; } });
|
|
10
9
|
var migrations_1 = require("./migrations");
|
|
@@ -13,6 +12,9 @@ var seeds_1 = require("./seeds");
|
|
|
13
12
|
Object.defineProperty(exports, "DatabaseSeeds", { enumerable: true, get: function () { return seeds_1.DatabaseSeeds; } });
|
|
14
13
|
var schema_introspection_1 = require("./schema-introspection");
|
|
15
14
|
Object.defineProperty(exports, "SchemaIntrospection", { enumerable: true, get: function () { return schema_introspection_1.SchemaIntrospection; } });
|
|
15
|
+
var transactions_1 = require("./transactions");
|
|
16
|
+
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return transactions_1.transaction; } });
|
|
17
|
+
Object.defineProperty(exports, "recreateTable", { enumerable: true, get: function () { return transactions_1.recreateTable; } });
|
|
16
18
|
var logger_1 = require("./logger");
|
|
17
19
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA;AAC3B,iCAAwC;AAA/B,sGAAA,aAAa,OAAA;AACtB,+DAA6D;AAApD,2HAAA,mBAAmB,OAAA;AAC5B,+CAA4D;AAAnD,2GAAA,WAAW,OAAA;AAAE,6GAAA,aAAa,OAAA;AACnC,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
|
package/dist/utils/logger.d.ts
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
WARN = 2,
|
|
8
|
-
ERROR = 3
|
|
9
|
-
}
|
|
10
|
-
export interface Logger {
|
|
11
|
-
debug(message: string, ...args: any[]): void;
|
|
12
|
-
info(message: string, ...args: any[]): void;
|
|
13
|
-
warn(message: string, ...args: any[]): void;
|
|
14
|
-
error(message: string, ...args: any[]): void;
|
|
15
|
-
}
|
|
16
|
-
declare class DatabaseLogger implements Logger {
|
|
17
|
-
private level;
|
|
18
|
-
constructor(level?: LogLevel);
|
|
19
|
-
debug(message: string, ...args: any[]): void;
|
|
20
|
-
info(message: string, ...args: any[]): void;
|
|
21
|
-
warn(message: string, ...args: any[]): void;
|
|
22
|
-
error(message: string, ...args: any[]): void;
|
|
23
|
-
}
|
|
24
|
-
export declare const logger: DatabaseLogger;
|
|
25
|
-
export {};
|
|
1
|
+
export declare const logger: {
|
|
2
|
+
debug: (msg: string, ...args: unknown[]) => void;
|
|
3
|
+
info: (msg: string, ...args: unknown[]) => void;
|
|
4
|
+
warn: (msg: string, ...args: unknown[]) => void;
|
|
5
|
+
error: (msg: string, ...args: unknown[]) => void;
|
|
6
|
+
};
|
|
26
7
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM;iBACJ,MAAM,WAAW,OAAO,EAAE;gBAG3B,MAAM,WAAW,OAAO,EAAE;gBAG1B,MAAM,WAAW,OAAO,EAAE;iBAGzB,MAAM,WAAW,OAAO,EAAE;CAGxC,CAAC"}
|
package/dist/utils/logger.js
CHANGED
|
@@ -1,41 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Simple logging abstraction for database operations
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
console.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
warn(message, ...args) {
|
|
29
|
-
if (this.level <= LogLevel.WARN) {
|
|
30
|
-
console.warn(`⚠️ [WARN] ${message}`, ...args);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
error(message, ...args) {
|
|
34
|
-
if (this.level <= LogLevel.ERROR) {
|
|
35
|
-
console.error(`❌ [ERROR] ${message}`, ...args);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Export default logger instance
|
|
40
|
-
exports.logger = new DatabaseLogger(process.env.NODE_ENV === 'development' ? LogLevel.DEBUG : LogLevel.INFO);
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const isDebug = process.env.DEBUG === 'true' || process.env.NODE_ENV === 'development';
|
|
5
|
+
const isQuiet = process.env.NODE_ENV === 'test' || process.env.QUIET === 'true';
|
|
6
|
+
exports.logger = {
|
|
7
|
+
debug: (msg, ...args) => {
|
|
8
|
+
if (isDebug && !isQuiet)
|
|
9
|
+
console.log(`[nanodb] ${msg}`, ...args);
|
|
10
|
+
},
|
|
11
|
+
info: (msg, ...args) => {
|
|
12
|
+
if (!isQuiet)
|
|
13
|
+
console.log(`[nanodb] ${msg}`, ...args);
|
|
14
|
+
},
|
|
15
|
+
warn: (msg, ...args) => {
|
|
16
|
+
if (!isQuiet)
|
|
17
|
+
console.warn(`[nanodb] ${msg}`, ...args);
|
|
18
|
+
},
|
|
19
|
+
error: (msg, ...args) => {
|
|
20
|
+
console.error(msg, ...args); // Errors always show, no prefix (for clean formatted errors)
|
|
21
|
+
},
|
|
22
|
+
};
|
|
41
23
|
//# sourceMappingURL=logger.js.map
|
package/dist/utils/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;AACvF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC;AAEnE,QAAA,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,GAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACzC,IAAI,OAAO,IAAI,CAAC,OAAO;YAAE,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,EAAE,CAAC,GAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACxC,IAAI,CAAC,OAAO;YAAE,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,EAAE,CAAC,GAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACxC,IAAI,CAAC,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,EAAE,CAAC,GAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACzC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,6DAA6D;IAC5F,CAAC;CACF,CAAC"}
|
|
@@ -1,94 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Completely Generic Database Migration Utilities
|
|
8
|
-
* Works with any table structure defined in schema.ts
|
|
9
|
-
* Uses Drizzle's auto-table creation capabilities
|
|
10
|
-
*/
|
|
11
|
-
export interface MigrationConfig {
|
|
12
|
-
preserveData?: boolean;
|
|
13
|
-
autoMigrate?: boolean;
|
|
14
|
-
dropTables?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class DatabaseMigrations {
|
|
17
|
-
private static tables;
|
|
18
|
-
private static migrationConfig;
|
|
19
|
-
/**
|
|
20
|
-
* Initialize with schema data
|
|
21
|
-
*/
|
|
22
|
-
static initialize(schemaData: {
|
|
23
|
-
tables: Record<string, any>;
|
|
1
|
+
import type { DrizzleTable, MigrationConfig, SchemaValidation } from '../types';
|
|
2
|
+
export declare const DatabaseMigrations: {
|
|
3
|
+
/** Initialize with schema data */
|
|
4
|
+
initialize(data: {
|
|
5
|
+
tables: Record<string, DrizzleTable>;
|
|
24
6
|
tableNames: string[];
|
|
25
7
|
migrationConfig?: MigrationConfig;
|
|
26
8
|
}): void;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Validate if table exists and has the correct schema
|
|
39
|
-
*/
|
|
40
|
-
private static validateTableSchema;
|
|
41
|
-
/**
|
|
42
|
-
* Get expected column names from Drizzle table definition
|
|
43
|
-
*/
|
|
44
|
-
private static getExpectedColumns;
|
|
45
|
-
/**
|
|
46
|
-
* Get actual column names from database table
|
|
47
|
-
*/
|
|
48
|
-
private static getActualColumns;
|
|
49
|
-
/**
|
|
50
|
-
* Check if table has any data
|
|
51
|
-
*/
|
|
52
|
-
private static tableHasData;
|
|
53
|
-
/**
|
|
54
|
-
* Generate basic CREATE TABLE SQL for SQLite
|
|
55
|
-
* This is a simplified approach that works for most common table structures
|
|
56
|
-
*/
|
|
57
|
-
private static generateBasicCreateSql;
|
|
58
|
-
/**
|
|
59
|
-
* Drop all tables
|
|
60
|
-
* Uses the provided schema tables
|
|
61
|
-
*/
|
|
62
|
-
static dropAllTables(): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Reset database (drop and recreate all tables)
|
|
65
|
-
* Completely generic - works with any table structure defined in schema.ts
|
|
66
|
-
*/
|
|
67
|
-
static resetDatabase(): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Check if tables exist in the database
|
|
70
|
-
* Uses the provided schema tables
|
|
71
|
-
*/
|
|
72
|
-
static checkTableExistence(): Promise<Record<string, boolean>>;
|
|
73
|
-
/**
|
|
74
|
-
* Validate that database schema matches provided schema
|
|
75
|
-
* Uses the provided schema tables
|
|
76
|
-
*/
|
|
77
|
-
static validateSchema(): Promise<{
|
|
78
|
-
isValid: boolean;
|
|
79
|
-
missingTables: string[];
|
|
80
|
-
extraTables: string[];
|
|
81
|
-
errors: string[];
|
|
82
|
-
}>;
|
|
83
|
-
/**
|
|
84
|
-
* Get migration status
|
|
85
|
-
* Uses the provided schema tables
|
|
86
|
-
*/
|
|
87
|
-
static getMigrationStatus(): Promise<{
|
|
88
|
-
tablesInSchema: string[];
|
|
89
|
-
tablesInDatabase: Record<string, boolean>;
|
|
90
|
-
missingTables: string[];
|
|
91
|
-
isValid: boolean;
|
|
92
|
-
}>;
|
|
93
|
-
}
|
|
9
|
+
/** Create all tables from schema */
|
|
10
|
+
initializeSchema(): Promise<void>;
|
|
11
|
+
/** Drop all tables and recreate */
|
|
12
|
+
resetDatabase(): Promise<void>;
|
|
13
|
+
/** Drop all tables */
|
|
14
|
+
dropAllTables(): Promise<void>;
|
|
15
|
+
/** Check which tables exist */
|
|
16
|
+
checkTableExistence(): Promise<Record<string, boolean>>;
|
|
17
|
+
/** Validate schema matches database */
|
|
18
|
+
validateSchema(): Promise<SchemaValidation>;
|
|
19
|
+
};
|
|
94
20
|
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../utils/migrations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../utils/migrations.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAiB,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiB/F,eAAO,MAAM,kBAAkB;IAC7B,kCAAkC;qBACjB;QACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACrC,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,eAAe,CAAC,EAAE,eAAe,CAAC;KACnC,GAAG,IAAI;IAKR,oCAAoC;wBACV,OAAO,CAAC,IAAI,CAAC;IAgBvC,mCAAmC;qBACZ,OAAO,CAAC,IAAI,CAAC;IAQpC,sBAAsB;qBACC,OAAO,CAAC,IAAI,CAAC;IAYpC,+BAA+B;2BACF,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAW7D,uCAAuC;sBACf,OAAO,CAAC,gBAAgB,CAAC;CAsBlD,CAAC"}
|