stabilize-orm 1.3.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +1097 -561
  2. package/dist/auto-migrate.d.ts +34 -0
  3. package/dist/auto-migrate.d.ts.map +1 -0
  4. package/dist/auto-migrate.js +3003 -0
  5. package/dist/auto-migrate.js.map +163 -0
  6. package/dist/cache.d.ts +90 -0
  7. package/dist/cache.d.ts.map +1 -0
  8. package/dist/cache.js +166 -0
  9. package/dist/cache.js.map +64 -0
  10. package/dist/client.d.ts +73 -0
  11. package/dist/client.d.ts.map +1 -0
  12. package/dist/client.js +2997 -0
  13. package/dist/client.js.map +162 -0
  14. package/dist/hooks.d.ts +31 -0
  15. package/dist/hooks.d.ts.map +1 -0
  16. package/dist/hooks.js +4 -0
  17. package/dist/hooks.js.map +11 -0
  18. package/dist/index.d.ts +101 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +3183 -0
  21. package/dist/index.js.map +222 -0
  22. package/dist/logger.d.ts +40 -0
  23. package/dist/logger.d.ts.map +1 -0
  24. package/dist/logger.js +8 -0
  25. package/dist/logger.js.map +11 -0
  26. package/dist/migrations.d.ts +31 -0
  27. package/dist/migrations.d.ts.map +1 -0
  28. package/dist/migrations.js +3009 -0
  29. package/dist/migrations.js.map +164 -0
  30. package/{model.ts → dist/model.d.ts} +124 -189
  31. package/dist/model.d.ts.map +1 -0
  32. package/dist/model.js +4 -0
  33. package/dist/model.js.map +10 -0
  34. package/dist/query-builder.d.ts +91 -0
  35. package/dist/query-builder.d.ts.map +1 -0
  36. package/dist/query-builder.js +14 -0
  37. package/dist/query-builder.js.map +12 -0
  38. package/dist/repository.d.ts +165 -0
  39. package/dist/repository.d.ts.map +1 -0
  40. package/dist/repository.js +176 -0
  41. package/dist/repository.js.map +69 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/types.d.ts +110 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +4 -0
  46. package/dist/types.js.map +10 -0
  47. package/dist/utils/encryption.d.ts +13 -0
  48. package/dist/utils/encryption.d.ts.map +1 -0
  49. package/dist/utils/encryption.js +4 -0
  50. package/dist/utils/encryption.js.map +10 -0
  51. package/package.json +96 -17
  52. package/.eslintrc.json +0 -10
  53. package/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE.md +0 -23
  54. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -25
  55. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  56. package/.github/workflows/ci-cd.yml +0 -22
  57. package/CHANGELOG.md +0 -75
  58. package/CODE_OF_CONDUCT.md +0 -87
  59. package/CONTRIBUTING.md +0 -48
  60. package/FUNDING.md +0 -14
  61. package/SECURITY.md +0 -35
  62. package/SUPPORT.md +0 -18
  63. package/bun.lock +0 -667
  64. package/cache.ts +0 -181
  65. package/client.ts +0 -249
  66. package/docker-compose.yml +0 -22
  67. package/hooks.ts +0 -76
  68. package/index.ts +0 -158
  69. package/logger.ts +0 -127
  70. package/migrations.ts +0 -318
  71. package/public/logo_both-transparent.png +0 -0
  72. package/public/logo_iamge-transparent.png +0 -0
  73. package/public/logo_text-transparent.png +0 -0
  74. package/query-builder.ts +0 -209
  75. package/repository.ts +0 -1096
  76. package/tests/migrations.test.ts +0 -141
  77. package/tsconfig.json +0 -32
  78. package/types.ts +0 -106
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file logger.ts
3
+ * @description Provides a flexible logger that can write to the console and/or rotating log files.
4
+ * @author ElectronSz
5
+ */
6
+ import { type LoggerConfig, type PoolMetrics } from "./types";
7
+ /**
8
+ * Defines the interface for a logger that can be used within the ORM.
9
+ */
10
+ export interface Logger {
11
+ logQuery(query: string, params: any[], executionTime?: number): void;
12
+ logError(error: Error): void;
13
+ logMetrics(metrics: PoolMetrics): void;
14
+ logInfo(message: string): void;
15
+ logWarn(message: string): void;
16
+ logDebug(message: string): void;
17
+ }
18
+ /**
19
+ * A logger implementation that writes to the console and can optionally write to rotating files.
20
+ */
21
+ export declare class StabilizeLogger implements Logger {
22
+ private readonly level;
23
+ private readonly filePath;
24
+ private readonly maxFileSize;
25
+ private readonly maxFiles;
26
+ constructor(config?: LoggerConfig);
27
+ /** @internal Checks if a message at a given level should be logged. */
28
+ private shouldLog;
29
+ /** @internal Rotates log files if the current one exceeds the max size. */
30
+ private rotateLogFile;
31
+ /** @internal Writes a formatted message to the console and/or a file. */
32
+ private log;
33
+ logQuery(query: string, params: any[], executionTime?: number): void;
34
+ logError(error: Error): void;
35
+ logMetrics(metrics: PoolMetrics): void;
36
+ logInfo(message: string): void;
37
+ logWarn(message: string): void;
38
+ logDebug(message: string): void;
39
+ }
40
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACvC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,MAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,MAAM,GAAE,YAAiB;IAOrC,uEAAuE;IACvE,OAAO,CAAC,SAAS;IAIjB,2EAA2E;YAC7D,aAAa;IA2B3B,yEAAyE;YAC3D,GAAG;IAwBV,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAKpE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAK5B,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAKtC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI9B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI9B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAGvC"}
package/dist/logger.js ADDED
@@ -0,0 +1,8 @@
1
+ // @bun
2
+ var N=Object.create;var{getPrototypeOf:O,defineProperty:M,getOwnPropertyNames:P}=Object;var Q=Object.prototype.hasOwnProperty;var _=(j,k,G)=>{G=j!=null?N(O(j)):{};let F=k||!j||!j.__esModule?M(G,"default",{value:j,enumerable:!0}):G;for(let A of P(j))if(!Q.call(F,A))M(F,A,{get:()=>j[A],enumerable:!0});return F};var $=(j,k)=>()=>(k||j((k={exports:{}}).exports,k),k.exports);var C=import.meta.require;var V;((F)=>{F.Postgres="postgres";F.MySQL="mysql";F.SQLite="sqlite"})(V||={});var J;((A)=>{A[A.Debug=0]="Debug";A[A.Info=1]="Info";A[A.Warn=2]="Warn";A[A.Error=3]="Error"})(J||={});var W;((A)=>{A[A.OneToOne=0]="OneToOne";A[A.OneToMany=1]="OneToMany";A[A.ManyToOne=2]="ManyToOne";A[A.ManyToMany=3]="ManyToMany"})(W||={});var X;((w)=>{w[w.STRING=0]="STRING";w[w.TEXT=1]="TEXT";w[w.INTEGER=2]="INTEGER";w[w.BIGINT=3]="BIGINT";w[w.FLOAT=4]="FLOAT";w[w.DOUBLE=5]="DOUBLE";w[w.DECIMAL=6]="DECIMAL";w[w.BOOLEAN=7]="BOOLEAN";w[w.DATE=8]="DATE";w[w.DATETIME=9]="DATETIME";w[w.JSON=10]="JSON";w[w.UUID=11]="UUID";w[w.BLOB=12]="BLOB"})(X||={});class I extends Error{code;originalError;constructor(j,k,G){super(j);this.code=k;this.originalError=G;this.name="StabilizeError"}}function b(j){return{sql:j}}class Y{listeners=new Map;on(j,k){if(!this.listeners.has(j))this.listeners.set(j,[]);this.listeners.get(j).push(k)}off(j,k){let G=this.listeners.get(j);if(G){let F=G.indexOf(k);if(F!==-1)G.splice(F,1)}}emit(j,...k){let G=this.listeners.get(j);if(G)for(let F of G)try{F(...k)}catch{}}}function z(){return crypto.randomUUID()}import*as H from"fs/promises";class Z{level;filePath;maxFileSize;maxFiles;constructor(j={}){this.level=j.level??1,this.filePath=j.filePath||null,this.maxFileSize=j.maxFileSize||1048576,this.maxFiles=j.maxFiles||3}shouldLog(j){return j<=this.level}async rotateLogFile(){if(!this.filePath)return;try{let j=await H.stat(this.filePath).catch(()=>null);if(!j||j.size<this.maxFileSize)return;let k=`${this.filePath}.${this.maxFiles}`;await H.unlink(k).catch(()=>{});for(let G=this.maxFiles-1;G>=1;G--){let F=`${this.filePath}.${G}`,A=`${this.filePath}.${G+1}`;if(await H.stat(F).catch(()=>null))await H.rename(F,A)}await H.rename(this.filePath,`${this.filePath}.1`)}catch(j){let k=new I("Log rotation failed","LOG_ROTATION_ERROR",j);console.error(`[LOGGER_ERROR] ${k.message}
3
+ ${k.stack}`)}}async log(j,k){if(!this.shouldLog(j))return;let F=`[${J[j].toUpperCase()}] ${new Date().toISOString()} - ${k}`;switch(j){case 3:console.error(F);break;case 2:console.warn(F);break;default:console.log(F);break}if(this.filePath)try{await this.rotateLogFile(),await H.appendFile(this.filePath,F+`
4
+ `)}catch(A){let K=new I("Failed to write to log file","LOG_WRITE_ERROR",A);console.error(`[LOGGER_ERROR] ${K.message}
5
+ ${K.stack}`)}}logQuery(j,k,G){let F=G?`${G.toFixed(2)}ms`:"N/A";this.log(0,`Query: ${j} | Params: ${JSON.stringify(k)} | Time: ${F}`)}logError(j){let k=`${j.message}${j.stack?`
6
+ ${j.stack}`:""}`;this.log(3,k)}logMetrics(j){let k=`Pool Metrics: Active=${j.activeConnections}, Idle=${j.idleConnections}, Total=${j.totalConnections}`;this.log(1,k)}logInfo(j){this.log(1,j)}logWarn(j){this.log(2,j)}logDebug(j){this.log(0,j)}}export{Z as StabilizeLogger};
7
+
8
+ //# debugId=3B1FDE863A25CE1764756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["..\\types.ts", "..\\logger.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * @file types.ts\n * @description Contains all shared type definitions and enums for the Stabilize ORM.\n * @author ElectronSz\n */\n\nexport enum DBType {\n Postgres = \"postgres\",\n MySQL = \"mysql\",\n SQLite = \"sqlite\",\n}\n\nexport enum LogLevel {\n Debug,\n Info,\n Warn,\n Error,\n}\n\nexport enum RelationType {\n OneToOne,\n OneToMany,\n ManyToOne,\n ManyToMany,\n}\n\n/**\n * An enumeration of abstract data types that are mapped to database-specific types.\n * This allows models to be defined in a database-agnostic way.\n */\nexport enum DataTypes {\n STRING, // Maps to VARCHAR or TEXT\n TEXT, // Maps to TEXT\n INTEGER, // Maps to INTEGER or INT\n BIGINT, // Maps to BIGINT\n FLOAT, // Maps to REAL or FLOAT\n DOUBLE, // Maps to DOUBLE PRECISION\n DECIMAL, // Maps to DECIMAL or NUMERIC\n BOOLEAN, // Maps to BOOLEAN or TINYINT/INTEGER\n DATE, // Maps to DATE or TEXT\n DATETIME, // Maps to TIMESTAMP, DATETIME, or TEXT\n JSON, // Maps to JSON, JSONB, or TEXT\n UUID, // Maps to UUID or VARCHAR(36)\n BLOB, // Maps to BYTEA or BLOB\n}\n\nexport interface DBConfig {\n type: DBType;\n connectionString: string;\n retryAttempts?: number;\n retryDelay?: number;\n maxJitter?: number;\n}\n\nexport interface CacheConfig {\n enabled: boolean;\n ttl: number;\n redisUrl?: string;\n cachePrefix?: string;\n strategy?: \"cache-aside\" | \"write-through\";\n}\n\n/**\n * Configuration for the logger.\n */\nexport interface LoggerConfig {\n level?: LogLevel;\n filePath?: string;\n maxFileSize?: number;\n maxFiles?: number;\n}\n\nexport interface PoolMetrics {\n activeConnections: number;\n idleConnections: number;\n totalConnections: number;\n}\n\nexport interface QueryHint {\n type: string;\n value: string;\n}\n\nexport interface CacheStats {\n hits: number;\n misses: number;\n keys: number;\n}\n\nexport interface Migration {\n name: string;\n up: string[];\n down: string[];\n}\n\nexport class StabilizeError extends Error {\n constructor(\n message: string,\n public code: string,\n public originalError?: Error,\n ) {\n super(message);\n this.name = \"StabilizeError\";\n }\n}\n\nexport interface DefaultExpression {\n sql: string;\n}\n\nexport function sqlDefault(sql: string): DefaultExpression {\n return { sql };\n}\n\nexport type TransactionIsolationLevel =\n | \"READ UNCOMMITTED\"\n | \"READ COMMITTED\"\n | \"REPEATABLE READ\"\n | \"SERIALIZABLE\";\n\nexport interface QueryLogEntry {\n query: string;\n params: any[];\n durationMs: number;\n timestamp: Date;\n source: string;\n}\n\nexport type StabilizeEvent =\n | \"query\"\n | \"error\"\n | \"migration:start\"\n | \"migration:complete\"\n | \"transaction:start\"\n | \"transaction:complete\"\n | \"transaction:error\"\n | \"connection:open\"\n | \"connection:close\";\n\nexport type StabilizeEventHandler = (...args: any[]) => void;\n\nexport class StabilizeEmitter {\n private listeners: Map<StabilizeEvent, StabilizeEventHandler[]> = new Map();\n\n on(event: StabilizeEvent, handler: StabilizeEventHandler): void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, []);\n }\n this.listeners.get(event)!.push(handler);\n }\n\n off(event: StabilizeEvent, handler: StabilizeEventHandler): void {\n const handlers = this.listeners.get(event);\n if (handlers) {\n const idx = handlers.indexOf(handler);\n if (idx !== -1) handlers.splice(idx, 1);\n }\n }\n\n emit(event: StabilizeEvent, ...args: any[]): void {\n const handlers = this.listeners.get(event);\n if (handlers) {\n for (const handler of handlers) {\n try {\n handler(...args);\n } catch {}\n }\n }\n }\n}\n\nexport function generateUUID(): string {\n return crypto.randomUUID();\n}\n",
6
+ "/**\n * @file logger.ts\n * @description Provides a flexible logger that can write to the console and/or rotating log files.\n * @author ElectronSz\n */\n\nimport * as fs from \"fs/promises\";\nimport {\n LogLevel,\n type LoggerConfig,\n type PoolMetrics,\n StabilizeError,\n} from \"./types\";\n\n/**\n * Defines the interface for a logger that can be used within the ORM.\n */\nexport interface Logger {\n logQuery(query: string, params: any[], executionTime?: number): void;\n logError(error: Error): void;\n logMetrics(metrics: PoolMetrics): void;\n logInfo(message: string): void;\n logWarn(message: string): void;\n logDebug(message: string): void;\n}\n\n/**\n * A logger implementation that writes to the console and can optionally write to rotating files.\n */\nexport class StabilizeLogger implements Logger {\n private readonly level: LogLevel;\n private readonly filePath: string | null;\n private readonly maxFileSize: number;\n private readonly maxFiles: number;\n\n constructor(config: LoggerConfig = {}) {\n this.level = config.level ?? LogLevel.Info;\n this.filePath = config.filePath || null;\n this.maxFileSize = config.maxFileSize || 1 * 1024 * 1024; // 1MB\n this.maxFiles = config.maxFiles || 3;\n }\n\n /** @internal Checks if a message at a given level should be logged. */\n private shouldLog(messageLevel: LogLevel): boolean {\n return messageLevel <= this.level;\n }\n\n /** @internal Rotates log files if the current one exceeds the max size. */\n private async rotateLogFile(): Promise<void> {\n if (!this.filePath) return;\n\n try {\n const stats = await fs.stat(this.filePath).catch(() => null);\n if (!stats || stats.size < this.maxFileSize) {\n return; // No rotation needed\n }\n\n const oldestLog = `${this.filePath}.${this.maxFiles}`;\n await fs.unlink(oldestLog).catch(() => {});\n\n for (let i = this.maxFiles - 1; i >= 1; i--) {\n const source = `${this.filePath}.${i}`;\n const destination = `${this.filePath}.${i + 1}`;\n if (await fs.stat(source).catch(() => null)) {\n await fs.rename(source, destination);\n }\n }\n await fs.rename(this.filePath, `${this.filePath}.1`);\n } catch (error) {\n // Use StabilizeError for internal logger failures\n const logError = new StabilizeError(\"Log rotation failed\", \"LOG_ROTATION_ERROR\", error as Error);\n console.error(`[LOGGER_ERROR] ${logError.message}\\n${logError.stack}`);\n }\n }\n\n /** @internal Writes a formatted message to the console and/or a file. */\n private async log(level: LogLevel, message: string): Promise<void> {\n if (!this.shouldLog(level)) return;\n\n const levelStr = LogLevel[level].toUpperCase();\n const logEntry = `[${levelStr}] ${new Date().toISOString()} - ${message}`;\n\n switch (level) {\n case LogLevel.Error: console.error(logEntry); break;\n case LogLevel.Warn: console.warn(logEntry); break;\n default: console.log(logEntry); break;\n }\n\n if (this.filePath) {\n try {\n await this.rotateLogFile();\n await fs.appendFile(this.filePath, logEntry + \"\\n\");\n } catch (error) {\n // Use StabilizeError for internal logger failures\n const logError = new StabilizeError(\"Failed to write to log file\", \"LOG_WRITE_ERROR\", error as Error);\n console.error(`[LOGGER_ERROR] ${logError.message}\\n${logError.stack}`);\n }\n }\n }\n\n public logQuery(query: string, params: any[], executionTime?: number): void {\n const time = executionTime ? `${executionTime.toFixed(2)}ms` : \"N/A\";\n this.log(LogLevel.Debug, `Query: ${query} | Params: ${JSON.stringify(params)} | Time: ${time}`);\n }\n\n public logError(error: Error): void {\n const message = `${error.message}${error.stack ? `\\n${error.stack}` : \"\"}`;\n this.log(LogLevel.Error, message);\n }\n\n public logMetrics(metrics: PoolMetrics): void {\n const message = `Pool Metrics: Active=${metrics.activeConnections}, Idle=${metrics.idleConnections}, Total=${metrics.totalConnections}`;\n this.log(LogLevel.Info, message);\n }\n\n public logInfo(message: string): void {\n this.log(LogLevel.Info, message);\n }\n \n public logWarn(message: string): void {\n this.log(LogLevel.Warn, message);\n }\n\n public logDebug(message: string): void {\n this.log(LogLevel.Debug, message);\n }\n}"
7
+ ],
8
+ "mappings": ";+YAMO,IAAK,GAAL,CAAK,IAAL,CACL,WAAW,WACX,QAAQ,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,CAAC,EAAe,EAAe,EAA8B,CAC1E,IAAM,EAAO,EAAgB,GAAG,EAAc,QAAQ,CAAC,MAAQ,MAC/D,KAAK,MAAoB,UAAU,eAAmB,KAAK,UAAU,CAAM,aAAa,GAAM,EAGzF,QAAQ,CAAC,EAAoB,CAClC,IAAM,EAAU,GAAG,EAAM,UAAU,EAAM,MAAQ;AAAA,EAAK,EAAM,QAAU,KACtE,KAAK,MAAoB,CAAO,EAG3B,UAAU,CAAC,EAA4B,CAC5C,IAAM,EAAU,wBAAwB,EAAQ,2BAA2B,EAAQ,0BAA0B,EAAQ,mBACrH,KAAK,MAAmB,CAAO,EAG1B,OAAO,CAAC,EAAuB,CACpC,KAAK,MAAmB,CAAO,EAG1B,OAAO,CAAC,EAAuB,CACpC,KAAK,MAAmB,CAAO,EAG1B,QAAQ,CAAC,EAAuB,CACrC,KAAK,MAAoB,CAAO,EAEpC",
9
+ "debugId": "3B1FDE863A25CE1764756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file migrations.ts
3
+ * @description Contains functions for generating and running database migrations based on model metadata.
4
+ * @author ElectronSz
5
+ * @date 2025-10-15 20:55:49
6
+ */
7
+ import { type DBConfig, type Migration, DBType, DataTypes } from "./types";
8
+ /**
9
+ * Maps an abstract data type to the correct SQL type string for the specified database dialect.
10
+ * @param dt The data type to map.
11
+ * @param dbType The target database dialect.
12
+ * @returns The SQL column type string.
13
+ */
14
+ declare function mapDataTypeToSql(dt: DataTypes | string, dbType: DBType): string;
15
+ /**
16
+ * Generates SQL migration scripts (`up` and `down`) based on a model's configuration.
17
+ * @param model The model class defined with `defineModel`.
18
+ * @param name A descriptive name for the migration.
19
+ * @param dbType The target database dialect.
20
+ * @returns A promise that resolves to a `Migration` object containing the `up` and `down` SQL scripts.
21
+ */
22
+ export declare function generateMigration(model: new (...args: any[]) => any, name: string, dbType: DBType): Promise<Migration>;
23
+ /**
24
+ * Connects to the database and runs all pending migrations.
25
+ * @param config The database configuration object.
26
+ * @param migrations An array of `Migration` objects to be executed.
27
+ */
28
+ export declare function runMigrations(config: DBConfig, migrations: Migration[]): Promise<void>;
29
+ export type { Migration };
30
+ export { mapDataTypeToSql };
31
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../migrations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,EAEd,MAAM,EACN,SAAS,EACV,MAAM,SAAS,CAAC;AAiBjB;;;;;GAKG;AACH,iBAAS,gBAAgB,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAyGxE;AAoBD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,CAmFpB;AA4ED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,iBA6C5E;AAED,YAAY,EAAE,SAAS,EAAE,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,CAAC"}