@codemastersolutions/db-utility 0.0.1

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.es +21 -0
  3. package/LICENSE.pt-BR +21 -0
  4. package/README.es.md +155 -0
  5. package/README.md +155 -0
  6. package/README.pt-BR.md +155 -0
  7. package/dist/cli/index.d.ts +3 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +314 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/config/AppConfig.d.ts +19 -0
  12. package/dist/config/AppConfig.d.ts.map +1 -0
  13. package/dist/config/AppConfig.js +142 -0
  14. package/dist/config/AppConfig.js.map +1 -0
  15. package/dist/config/ConfigInitializer.d.ts +10 -0
  16. package/dist/config/ConfigInitializer.d.ts.map +1 -0
  17. package/dist/config/ConfigInitializer.js +37 -0
  18. package/dist/config/ConfigInitializer.js.map +1 -0
  19. package/dist/config/ConfigLoader.d.ts +7 -0
  20. package/dist/config/ConfigLoader.d.ts.map +1 -0
  21. package/dist/config/ConfigLoader.js +94 -0
  22. package/dist/config/ConfigLoader.js.map +1 -0
  23. package/dist/database/ConnectionFactory.d.ts +5 -0
  24. package/dist/database/ConnectionFactory.d.ts.map +1 -0
  25. package/dist/database/ConnectionFactory.js +22 -0
  26. package/dist/database/ConnectionFactory.js.map +1 -0
  27. package/dist/database/SqlSafety.d.ts +7 -0
  28. package/dist/database/SqlSafety.d.ts.map +1 -0
  29. package/dist/database/SqlSafety.js +47 -0
  30. package/dist/database/SqlSafety.js.map +1 -0
  31. package/dist/database/connectors/MssqlConnector.d.ts +13 -0
  32. package/dist/database/connectors/MssqlConnector.d.ts.map +1 -0
  33. package/dist/database/connectors/MssqlConnector.js +72 -0
  34. package/dist/database/connectors/MssqlConnector.js.map +1 -0
  35. package/dist/database/connectors/MysqlConnector.d.ts +12 -0
  36. package/dist/database/connectors/MysqlConnector.d.ts.map +1 -0
  37. package/dist/database/connectors/MysqlConnector.js +70 -0
  38. package/dist/database/connectors/MysqlConnector.js.map +1 -0
  39. package/dist/database/connectors/PostgresConnector.d.ts +12 -0
  40. package/dist/database/connectors/PostgresConnector.d.ts.map +1 -0
  41. package/dist/database/connectors/PostgresConnector.js +65 -0
  42. package/dist/database/connectors/PostgresConnector.js.map +1 -0
  43. package/dist/errors/DbUtilityError.d.ts +7 -0
  44. package/dist/errors/DbUtilityError.d.ts.map +1 -0
  45. package/dist/errors/DbUtilityError.js +15 -0
  46. package/dist/errors/DbUtilityError.js.map +1 -0
  47. package/dist/generators/GeneratorTypes.d.ts +15 -0
  48. package/dist/generators/GeneratorTypes.d.ts.map +1 -0
  49. package/dist/generators/GeneratorTypes.js +3 -0
  50. package/dist/generators/GeneratorTypes.js.map +1 -0
  51. package/dist/generators/GeneratorWriter.d.ts +6 -0
  52. package/dist/generators/GeneratorWriter.d.ts.map +1 -0
  53. package/dist/generators/GeneratorWriter.js +25 -0
  54. package/dist/generators/GeneratorWriter.js.map +1 -0
  55. package/dist/generators/MongooseGenerator.d.ts +10 -0
  56. package/dist/generators/MongooseGenerator.d.ts.map +1 -0
  57. package/dist/generators/MongooseGenerator.js +75 -0
  58. package/dist/generators/MongooseGenerator.js.map +1 -0
  59. package/dist/generators/PrismaGenerator.d.ts +9 -0
  60. package/dist/generators/PrismaGenerator.d.ts.map +1 -0
  61. package/dist/generators/PrismaGenerator.js +87 -0
  62. package/dist/generators/PrismaGenerator.js.map +1 -0
  63. package/dist/generators/SequelizeGenerator.d.ts +12 -0
  64. package/dist/generators/SequelizeGenerator.d.ts.map +1 -0
  65. package/dist/generators/SequelizeGenerator.js +243 -0
  66. package/dist/generators/SequelizeGenerator.js.map +1 -0
  67. package/dist/generators/TypeORMGenerator.d.ts +12 -0
  68. package/dist/generators/TypeORMGenerator.d.ts.map +1 -0
  69. package/dist/generators/TypeORMGenerator.js +216 -0
  70. package/dist/generators/TypeORMGenerator.js.map +1 -0
  71. package/dist/i18n/messages.d.ts +49 -0
  72. package/dist/i18n/messages.d.ts.map +1 -0
  73. package/dist/i18n/messages.js +149 -0
  74. package/dist/i18n/messages.js.map +1 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +8 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/introspection/DataExtractor.d.ts +10 -0
  80. package/dist/introspection/DataExtractor.d.ts.map +1 -0
  81. package/dist/introspection/DataExtractor.js +52 -0
  82. package/dist/introspection/DataExtractor.js.map +1 -0
  83. package/dist/introspection/IntrospectionLogger.d.ts +7 -0
  84. package/dist/introspection/IntrospectionLogger.d.ts.map +1 -0
  85. package/dist/introspection/IntrospectionLogger.js +30 -0
  86. package/dist/introspection/IntrospectionLogger.js.map +1 -0
  87. package/dist/introspection/IntrospectionService.d.ts +10 -0
  88. package/dist/introspection/IntrospectionService.d.ts.map +1 -0
  89. package/dist/introspection/IntrospectionService.js +37 -0
  90. package/dist/introspection/IntrospectionService.js.map +1 -0
  91. package/dist/introspection/Introspector.d.ts +11 -0
  92. package/dist/introspection/Introspector.d.ts.map +1 -0
  93. package/dist/introspection/Introspector.js +11 -0
  94. package/dist/introspection/Introspector.js.map +1 -0
  95. package/dist/introspection/MssqlIntrospector.d.ts +11 -0
  96. package/dist/introspection/MssqlIntrospector.d.ts.map +1 -0
  97. package/dist/introspection/MssqlIntrospector.js +193 -0
  98. package/dist/introspection/MssqlIntrospector.js.map +1 -0
  99. package/dist/introspection/MysqlIntrospector.d.ts +10 -0
  100. package/dist/introspection/MysqlIntrospector.d.ts.map +1 -0
  101. package/dist/introspection/MysqlIntrospector.js +175 -0
  102. package/dist/introspection/MysqlIntrospector.js.map +1 -0
  103. package/dist/introspection/PostgresIntrospector.d.ts +11 -0
  104. package/dist/introspection/PostgresIntrospector.d.ts.map +1 -0
  105. package/dist/introspection/PostgresIntrospector.js +192 -0
  106. package/dist/introspection/PostgresIntrospector.js.map +1 -0
  107. package/dist/testing/ContainerManager.d.ts +7 -0
  108. package/dist/testing/ContainerManager.d.ts.map +1 -0
  109. package/dist/testing/ContainerManager.js +68 -0
  110. package/dist/testing/ContainerManager.js.map +1 -0
  111. package/dist/testing/MigrationTester.d.ts +18 -0
  112. package/dist/testing/MigrationTester.d.ts.map +1 -0
  113. package/dist/testing/MigrationTester.js +399 -0
  114. package/dist/testing/MigrationTester.js.map +1 -0
  115. package/dist/testing/runners/MigrationRunner.d.ts +5 -0
  116. package/dist/testing/runners/MigrationRunner.d.ts.map +1 -0
  117. package/dist/testing/runners/MigrationRunner.js +3 -0
  118. package/dist/testing/runners/MigrationRunner.js.map +1 -0
  119. package/dist/testing/runners/SequelizeRunner.d.ts +8 -0
  120. package/dist/testing/runners/SequelizeRunner.d.ts.map +1 -0
  121. package/dist/testing/runners/SequelizeRunner.js +71 -0
  122. package/dist/testing/runners/SequelizeRunner.js.map +1 -0
  123. package/dist/testing/runners/TypeORMRunner.d.ts +8 -0
  124. package/dist/testing/runners/TypeORMRunner.d.ts.map +1 -0
  125. package/dist/testing/runners/TypeORMRunner.js +91 -0
  126. package/dist/testing/runners/TypeORMRunner.js.map +1 -0
  127. package/dist/types/database.d.ts +22 -0
  128. package/dist/types/database.d.ts.map +1 -0
  129. package/dist/types/database.js +3 -0
  130. package/dist/types/database.js.map +1 -0
  131. package/dist/types/introspection.d.ts +43 -0
  132. package/dist/types/introspection.d.ts.map +1 -0
  133. package/dist/types/introspection.js +3 -0
  134. package/dist/types/introspection.js.map +1 -0
  135. package/dist/utils/PackageManager.d.ts +13 -0
  136. package/dist/utils/PackageManager.d.ts.map +1 -0
  137. package/dist/utils/PackageManager.js +114 -0
  138. package/dist/utils/PackageManager.js.map +1 -0
  139. package/dist/utils/topologicalSort.d.ts +3 -0
  140. package/dist/utils/topologicalSort.d.ts.map +1 -0
  141. package/dist/utils/topologicalSort.js +37 -0
  142. package/dist/utils/topologicalSort.js.map +1 -0
  143. package/package.json +98 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConfigLoader = void 0;
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const DbUtilityError_1 = require("../errors/DbUtilityError");
11
+ dotenv_1.default.config();
12
+ class ConfigLoader {
13
+ static async load(configPath, overrides) {
14
+ let config;
15
+ if (configPath) {
16
+ config = await this.loadFromFile(configPath);
17
+ }
18
+ else {
19
+ const defaultFiles = ['db-utility.config.js', 'db-utility.config.json', '.db-utilityrc'];
20
+ let found = false;
21
+ config = {};
22
+ for (const file of defaultFiles) {
23
+ const path = (0, path_1.resolve)(process.cwd(), file);
24
+ if ((0, fs_1.existsSync)(path)) {
25
+ config = await this.loadFromFile(path);
26
+ found = true;
27
+ break;
28
+ }
29
+ }
30
+ if (!found) {
31
+ try {
32
+ config = this.loadFromEnv();
33
+ }
34
+ catch (error) {
35
+ if (!overrides || Object.keys(overrides).length === 0) {
36
+ throw error;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ if (overrides) {
42
+ config = { ...config, ...overrides };
43
+ }
44
+ if (!config.type && !config.connectionString) {
45
+ throw new DbUtilityError_1.DbUtilityError('CONFIG_DB_TYPE_OR_CONNECTION_STRING_REQUIRED');
46
+ }
47
+ return config;
48
+ }
49
+ static async loadFromFile(path) {
50
+ const absolutePath = (0, path_1.resolve)(process.cwd(), path);
51
+ if (!(0, fs_1.existsSync)(absolutePath)) {
52
+ throw new DbUtilityError_1.DbUtilityError('CONFIG_FILE_NOT_FOUND', absolutePath);
53
+ }
54
+ const ext = (0, path_1.extname)(absolutePath);
55
+ if (ext === '.json' || ext === '') {
56
+ const content = (0, fs_1.readFileSync)(absolutePath, 'utf-8');
57
+ return JSON.parse(content);
58
+ }
59
+ else if (ext === '.js') {
60
+ const config = require(absolutePath);
61
+ return config.default || config;
62
+ }
63
+ throw new DbUtilityError_1.DbUtilityError('CONFIG_FILE_FORMAT_UNSUPPORTED', ext);
64
+ }
65
+ static loadFromEnv() {
66
+ const dbType = process.env.DBUTILITY_DB_TYPE || process.env.DB_TYPE;
67
+ if (!dbType) {
68
+ throw new DbUtilityError_1.DbUtilityError('CONFIG_DB_TYPE_REQUIRED');
69
+ }
70
+ const host = process.env.DBUTILITY_DB_HOST || process.env.DB_HOST;
71
+ const portStr = process.env.DBUTILITY_DB_PORT || process.env.DB_PORT;
72
+ const username = process.env.DBUTILITY_DB_USER ||
73
+ process.env.DBUTILITY_DB_USERNAME ||
74
+ process.env.DB_USER ||
75
+ process.env.DB_USERNAME;
76
+ const password = process.env.DBUTILITY_DB_PASSWORD || process.env.DB_PASSWORD;
77
+ const database = process.env.DBUTILITY_DB_NAME ||
78
+ process.env.DBUTILITY_DB_DATABASE ||
79
+ process.env.DB_NAME ||
80
+ process.env.DB_DATABASE;
81
+ const connectionString = process.env.DBUTILITY_DB_CONNECTION_STRING || process.env.DB_CONNECTION_STRING;
82
+ return {
83
+ type: dbType,
84
+ host,
85
+ port: portStr ? parseInt(portStr, 10) : undefined,
86
+ username,
87
+ password,
88
+ database,
89
+ connectionString,
90
+ };
91
+ }
92
+ }
93
+ exports.ConfigLoader = ConfigLoader;
94
+ //# sourceMappingURL=ConfigLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigLoader.js","sourceRoot":"","sources":["../../src/config/ConfigLoader.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2BAA8C;AAC9C,+BAAwC;AAExC,6DAA0D;AAE1D,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAa,YAAY;IACvB,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,UAAmB,EACnB,SAAmC;QAEnC,IAAI,MAAsB,CAAC;QAE3B,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,GAAG,MAAM,IAAI,CA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CAAC,OAAO;YACnB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAC9E,MAAM,QAAQ,GACZ,OAAO,CAAC,GAAG,CAAC,iBAAiB;YAC7B,OAAO,CAAC,GAAG,CAAC,qBAAqB;YACjC,OAAO,CAAC,GAAG,CAAC,OAAO;YACnB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAC1B,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAEjF,OAAO;YACL,IAAI,EAAE,MAAsB;YAC5B,IAAI;YACJ,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;YACjD,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF;AA5GD,oCA4GC"}
@@ -0,0 +1,5 @@
1
+ import { DatabaseConfig, IDatabaseConnector } from '../types/database';
2
+ export declare class ConnectionFactory {
3
+ static create(config: DatabaseConfig): IDatabaseConnector;
4
+ }
5
+ //# sourceMappingURL=ConnectionFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionFactory.d.ts","sourceRoot":"","sources":["../../src/database/ConnectionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAKvE,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB;CAY1D"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionFactory = void 0;
4
+ const MysqlConnector_1 = require("./connectors/MysqlConnector");
5
+ const PostgresConnector_1 = require("./connectors/PostgresConnector");
6
+ const MssqlConnector_1 = require("./connectors/MssqlConnector");
7
+ class ConnectionFactory {
8
+ static create(config) {
9
+ switch (config.type) {
10
+ case 'mysql':
11
+ return new MysqlConnector_1.MysqlConnector(config);
12
+ case 'postgres':
13
+ return new PostgresConnector_1.PostgresConnector(config);
14
+ case 'mssql':
15
+ return new MssqlConnector_1.MssqlConnector(config);
16
+ default:
17
+ throw new Error(`Tipo de banco de dados não suportado: ${config.type}`);
18
+ }
19
+ }
20
+ }
21
+ exports.ConnectionFactory = ConnectionFactory;
22
+ //# sourceMappingURL=ConnectionFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionFactory.js","sourceRoot":"","sources":["../../src/database/ConnectionFactory.ts"],"names":[],"mappings":";;;AACA,gEAA6D;AAC7D,sEAAmE;AACnE,gEAA6D;AAE7D,MAAa,iBAAiB;IAC5B,MAAM,CAAC,MAAM,CAAC,MAAsB;QAClC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,OAAO;gBACV,OAAO,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;YACpC,KAAK,UAAU;gBACb,OAAO,IAAI,qCAAiB,CAAC,MAAM,CAAC,CAAC;YACvC,KAAK,OAAO;gBACV,OAAO,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;YACpC;gBACE,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF;AAbD,8CAaC"}
@@ -0,0 +1,7 @@
1
+ export type DbUtilitySecurityErrorCode = 'UNSAFE_OPERATION' | 'UNSAFE_DATA_SELECT';
2
+ export declare class DbUtilitySecurityError extends Error {
3
+ code: DbUtilitySecurityErrorCode;
4
+ constructor(code: DbUtilitySecurityErrorCode);
5
+ }
6
+ export declare function assertSafeSql(sql: string): void;
7
+ //# sourceMappingURL=SqlSafety.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqlSafety.d.ts","sourceRoot":"","sources":["../../src/database/SqlSafety.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAEnF,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,IAAI,EAAE,0BAA0B,CAAC;gBAErB,IAAI,EAAE,0BAA0B;CAK7C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAqC/C"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DbUtilitySecurityError = void 0;
4
+ exports.assertSafeSql = assertSafeSql;
5
+ class DbUtilitySecurityError extends Error {
6
+ code;
7
+ constructor(code) {
8
+ super(code);
9
+ this.name = 'DbUtilitySecurityError';
10
+ this.code = code;
11
+ }
12
+ }
13
+ exports.DbUtilitySecurityError = DbUtilitySecurityError;
14
+ function assertSafeSql(sql) {
15
+ const normalized = sql.toLowerCase();
16
+ const forbiddenKeywords = [
17
+ 'insert',
18
+ 'update',
19
+ 'delete',
20
+ 'merge',
21
+ 'drop',
22
+ 'truncate',
23
+ 'alter',
24
+ 'create',
25
+ 'grant',
26
+ 'revoke',
27
+ 'execute',
28
+ 'exec',
29
+ 'call',
30
+ ];
31
+ for (const keyword of forbiddenKeywords) {
32
+ const pattern = new RegExp(`\\b${keyword}\\b`, 'i');
33
+ if (pattern.test(sql)) {
34
+ throw new DbUtilitySecurityError('UNSAFE_OPERATION');
35
+ }
36
+ }
37
+ if (normalized.includes('select')) {
38
+ const isMetadataSelect = normalized.includes('information_schema.') ||
39
+ normalized.includes(' from pg_catalog ') ||
40
+ normalized.includes(' from sys.') ||
41
+ /\bselect\s+1\b/.test(normalized);
42
+ if (!isMetadataSelect) {
43
+ throw new DbUtilitySecurityError('UNSAFE_DATA_SELECT');
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=Sql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AAoB,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { DatabaseConfig, IDatabaseConnector, QueryOptions } from '../../types/database';
2
+ export declare class MssqlConnector implements IDatabaseConnector {
3
+ private pool;
4
+ private config;
5
+ constructor(config: DatabaseConfig);
6
+ connect(): Promise<void>;
7
+ private connectWithUri;
8
+ disconnect(): Promise<void>;
9
+ query<T>(sql: string, params?: unknown[], options?: QueryOptions): Promise<T[]>;
10
+ isConnected(): Promise<boolean>;
11
+ getVersion(): Promise<string>;
12
+ }
13
+ //# sourceMappingURL=MssqlConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MssqlConnector.d.ts","sourceRoot":"","sources":["../../../src/database/connectors/MssqlConnector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxF,qBAAa,cAAe,YAAW,kBAAkB;IACvD,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAqBhB,cAAc;IAKtB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAqB/E,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAK/B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAMpC"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MssqlConnector = void 0;
4
+ const mssql_1 = require("mssql");
5
+ const DbUtilityError_1 = require("../../errors/DbUtilityError");
6
+ const SqlSafety_1 = require("../SqlSafety");
7
+ class MssqlConnector {
8
+ pool = null;
9
+ config;
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ async connect() {
14
+ const mssqlConfig = {
15
+ server: this.config.host || 'localhost',
16
+ port: this.config.port,
17
+ user: this.config.username,
18
+ password: this.config.password,
19
+ database: this.config.database,
20
+ options: {
21
+ encrypt: this.config.ssl !== false,
22
+ trustServerCertificate: !this.config.ssl,
23
+ },
24
+ };
25
+ if (this.config.connectionString) {
26
+ await this.connectWithUri(this.config.connectionString);
27
+ }
28
+ else {
29
+ this.pool = new mssql_1.ConnectionPool(mssqlConfig);
30
+ await this.pool.connect();
31
+ }
32
+ }
33
+ async connectWithUri(uri) {
34
+ this.pool = new mssql_1.ConnectionPool(uri);
35
+ await this.pool.connect();
36
+ }
37
+ async disconnect() {
38
+ if (this.pool) {
39
+ await this.pool.close();
40
+ this.pool = null;
41
+ }
42
+ }
43
+ async query(sql, params, options) {
44
+ if (!this.pool) {
45
+ throw new DbUtilityError_1.DbUtilityError('CONNECTION_FAILED');
46
+ }
47
+ if (!options?.bypassSafety) {
48
+ (0, SqlSafety_1.assertSafeSql)(sql);
49
+ }
50
+ const request = this.pool.request();
51
+ if (params) {
52
+ params.forEach((param, index) => {
53
+ request.input(`param${index}`, param);
54
+ });
55
+ }
56
+ const result = await request.query(sql);
57
+ return result.recordset;
58
+ }
59
+ async isConnected() {
60
+ if (!this.pool)
61
+ return false;
62
+ return this.pool.connected;
63
+ }
64
+ async getVersion() {
65
+ const result = await this.query('SELECT @@VERSION as version', [], {
66
+ bypassSafety: true,
67
+ });
68
+ return result[0]?.version || 'Unknown MSSQL Version';
69
+ }
70
+ }
71
+ exports.MssqlConnector = MssqlConnector;
72
+ //# sourceMappingURL=MssqlConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MssqlConnector.js","sourceRoot":"","sources":["../../../src/database/connectors/MssqlConnector.ts"],"names":[],"mappings":";;;AAAA,iCAA8D;AAC9D,gEAA6D;AAE7D,4CA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GAAG,IAAI,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAI,GAAW,EAAE,MAAkB,EAAE,OAAsB;QACpE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,+BAAc,CAAC,mBAAmB,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;YAC3B,IAAA,yBAAa,EAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAEpC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBAC9B,OAAO,CAAC,KAAK,CAAC,QAAQ,KAAK,EAAE,EAAE,KAAc,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,MAAM,CAAC,SAAgB,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAsB,6BAA6B,EAAE,EAAE,EAAE;YACtF,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,uBAAuB,CAAC;IACvD,CAAC;CACF;AAzED,wCAyEC"}
@@ -0,0 +1,12 @@
1
+ import { DatabaseConfig, IDatabaseConnector, QueryOptions } from '../../types/database';
2
+ export declare class MysqlConnector implements IDatabaseConnector {
3
+ private pool;
4
+ private config;
5
+ constructor(config: DatabaseConfig);
6
+ connect(): Promise<void>;
7
+ disconnect(): Promise<void>;
8
+ query<T>(sql: string, params?: unknown[], options?: QueryOptions): Promise<T[]>;
9
+ isConnected(): Promise<boolean>;
10
+ getVersion(): Promise<string>;
11
+ }
12
+ //# sourceMappingURL=MysqlConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MysqlConnector.d.ts","sourceRoot":"","sources":["../../../src/database/connectors/MysqlConnector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxF,qBAAa,cAAe,YAAW,kBAAkB;IACvD,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAa/E,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAW/B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAMpC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MysqlConnector = void 0;
4
+ const promise_1 = require("mysql2/promise");
5
+ const DbUtilityError_1 = require("../../errors/DbUtilityError");
6
+ const SqlSafety_1 = require("../SqlSafety");
7
+ class MysqlConnector {
8
+ pool = null;
9
+ config;
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ async connect() {
14
+ const poolOptions = {
15
+ host: this.config.host,
16
+ port: this.config.port,
17
+ user: this.config.username,
18
+ password: this.config.password,
19
+ database: this.config.database,
20
+ ssl: this.config.ssl ? { rejectUnauthorized: false } : undefined,
21
+ waitForConnections: true,
22
+ connectionLimit: 10,
23
+ queueLimit: 0,
24
+ };
25
+ if (this.config.connectionString) {
26
+ this.pool = (0, promise_1.createPool)(this.config.connectionString);
27
+ }
28
+ else {
29
+ this.pool = (0, promise_1.createPool)(poolOptions);
30
+ }
31
+ const connection = await this.pool.getConnection();
32
+ connection.release();
33
+ }
34
+ async disconnect() {
35
+ if (this.pool) {
36
+ await this.pool.end();
37
+ this.pool = null;
38
+ }
39
+ }
40
+ async query(sql, params, options) {
41
+ if (!this.pool) {
42
+ throw new DbUtilityError_1.DbUtilityError('CONNECTION_FAILED');
43
+ }
44
+ if (!options?.bypassSafety) {
45
+ (0, SqlSafety_1.assertSafeSql)(sql);
46
+ }
47
+ const [rows] = await this.pool.execute(sql, params);
48
+ return rows;
49
+ }
50
+ async isConnected() {
51
+ if (!this.pool)
52
+ return false;
53
+ try {
54
+ const connection = await this.pool.getConnection();
55
+ connection.release();
56
+ return true;
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ }
62
+ async getVersion() {
63
+ const result = await this.query('SELECT VERSION() as version', [], {
64
+ bypassSafety: true,
65
+ });
66
+ return result[0]?.version || 'Unknown MySQL Version';
67
+ }
68
+ }
69
+ exports.MysqlConnector = MysqlConnector;
70
+ //# sourceMappingURL=MysqlConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MysqlConnector.js","sourceRoot":"","sources":["../../../src/database/connectors/MysqlConnector.ts"],"names":[],"mappings":";;;AAAA,4CAA+D;AAC/D,gEAA6D;AAE7D,4CAA6C;AAE7C,MAAa,cAAc;IACjB,IAAI,GAAgB,IAAI,CAAC;IACzB,MAAM,CAAiB;IAE/B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,WAAW,GAAgB;YAC/B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,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M,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;QAC7D,OAAO,IAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACnD,UAAU,CAAC,OAAO,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAsB,6BAA6B,EAAE,EAAE,EAAE;YACtF,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,uBAAuB,CAAC;IACvD,CAAC;CACF;AAtED,wCAsEC"}
@@ -0,0 +1,12 @@
1
+ import { DatabaseConfig, IDatabaseConnector, QueryOptions } from '../../types/database';
2
+ export declare class PostgresConnector implements IDatabaseConnector {
3
+ private pool;
4
+ private config;
5
+ constructor(config: DatabaseConfig);
6
+ connect(): Promise<void>;
7
+ disconnect(): Promise<void>;
8
+ query<T>(sql: string, params?: unknown[], options?: QueryOptions): Promise<T[]>;
9
+ isConnected(): Promise<boolean>;
10
+ getVersion(): Promise<string>;
11
+ }
12
+ //# sourceMappingURL=PostgresConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresConnector.d.ts","sourceRoot":"","sources":["../../../src/database/connectors/PostgresConnector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxF,qBAAa,iBAAkB,YAAW,kBAAkB;IAC1D,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAa/E,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAc/B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAMpC"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostgresConnector = void 0;
4
+ const pg_1 = require("pg");
5
+ const DbUtilityError_1 = require("../../errors/DbUtilityError");
6
+ const SqlSafety_1 = require("../SqlSafety");
7
+ class PostgresConnector {
8
+ pool = null;
9
+ config;
10
+ constructor(config) {
11
+ this.config = config;
12
+ }
13
+ async connect() {
14
+ const poolConfig = {
15
+ host: this.config.host,
16
+ port: this.config.port,
17
+ user: this.config.username,
18
+ password: this.config.password,
19
+ database: this.config.database,
20
+ ssl: this.config.ssl ? { rejectUnauthorized: false } : undefined,
21
+ };
22
+ if (this.config.connectionString) {
23
+ poolConfig.connectionString = this.config.connectionString;
24
+ }
25
+ this.pool = new pg_1.Pool(poolConfig);
26
+ const client = await this.pool.connect();
27
+ client.release();
28
+ }
29
+ async disconnect() {
30
+ if (this.pool) {
31
+ await this.pool.end();
32
+ this.pool = null;
33
+ }
34
+ }
35
+ async query(sql, params, options) {
36
+ if (!this.pool) {
37
+ throw new DbUtilityError_1.DbUtilityError('CONNECTION_FAILED');
38
+ }
39
+ if (!options?.bypassSafety) {
40
+ (0, SqlSafety_1.assertSafeSql)(sql);
41
+ }
42
+ const result = await this.pool.query(sql, params);
43
+ return result.rows;
44
+ }
45
+ async isConnected() {
46
+ if (!this.pool)
47
+ return false;
48
+ try {
49
+ const client = await this.pool.connect();
50
+ client.release();
51
+ return true;
52
+ }
53
+ catch {
54
+ return false;
55
+ }
56
+ }
57
+ async getVersion() {
58
+ const result = await this.query('SELECT version()', [], {
59
+ bypassSafety: true,
60
+ });
61
+ return result[0]?.version || 'Unknown Postgres Version';
62
+ }
63
+ }
64
+ exports.PostgresConnector = PostgresConnector;
65
+ //# sourceMappingURL=PostgresConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresConnector.js","sourceRoot":"","sources":["../../../src/database/connectors/PostgresConnector.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AACtC,gEAA6D;AAE7D,4CAA6C;AAE7C,MAAa,iBAAiB;IACpB,IAAI,GAAgB,IAAI,CAAC;IACzB,MAAM,CAAiB;IAE/B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,UAAU,GAAe;YAC7B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC1B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS;SACjE,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YACjC,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,SAAI,CAAC,UAAU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OAAO,IAAI,0BAA0B,CAAC;IAC1D,CAAC;CACF;AArED,8CAqEC"}
@@ -0,0 +1,7 @@
1
+ export type DbUtilityErrorCode = 'INTROSPECTION_DB_TYPE_REQUIRED' | 'INTROSPECTION_DB_TYPE_UNSUPPORTED' | 'APP_CONFIG_FILE_NOT_FOUND' | 'APP_CONFIG_FILE_FORMAT_UNSUPPORTED' | 'CONFIG_FILE_NOT_FOUND' | 'CONFIG_FILE_FORMAT_UNSUPPORTED' | 'CONFIG_DB_TYPE_OR_CONNECTION_STRING_REQUIRED' | 'CONFIG_DB_TYPE_REQUIRED' | 'CONNECTION_FAILED';
2
+ export declare class DbUtilityError extends Error {
3
+ code: DbUtilityErrorCode;
4
+ details?: string;
5
+ constructor(code: DbUtilityErrorCode, details?: string);
6
+ }
7
+ //# sourceMappingURL=DbUtilityError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DbUtilityError.d.ts","sourceRoot":"","sources":["../../src/errors/DbUtilityError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC1B,gCAAgC,GAChC,mCAAmC,GACnC,2BAA2B,GAC3B,oCAAoC,GACpC,uBAAuB,GACvB,gCAAgC,GAChC,8CAA8C,GAC9C,yBAAyB,GACzB,mBAAmB,CAAC;AAExB,qBAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAEL,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,MAAM;CAMvD"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DbUtilityError = void 0;
4
+ class DbUtilityError extends Error {
5
+ code;
6
+ details;
7
+ constructor(code, details) {
8
+ super(code);
9
+ this.name = 'DbUtilityError';
10
+ this.code = code;
11
+ this.details = details;
12
+ }
13
+ }
14
+ exports.DbUtilityError = DbUtilityError;
15
+ //# sourceMappingURL=DbUtilityError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DbUtilityError.js","sourceRoot":"","sources":["../../src/errors/DbUtilityError.ts"],"names":[],"mappings":";;;AAWA,MAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,CAAqB;IACzB,OAAO,CAAU;IAEjB,YAAY,IAAwB,EAAE,OAAgB;QACpD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,wCAUC"}
@@ -0,0 +1,15 @@
1
+ import { DatabaseSchema, TableData } from '../types/introspection';
2
+ export interface GeneratedFile {
3
+ fileName: string;
4
+ content: string;
5
+ }
6
+ export interface SchemaGenerator {
7
+ generate(schema: DatabaseSchema): Promise<GeneratedFile[]>;
8
+ }
9
+ export interface MigrationGenerator {
10
+ generateMigrations(schema: DatabaseSchema, data?: TableData[]): Promise<GeneratedFile[]>;
11
+ }
12
+ export interface DataMigrationGenerator {
13
+ generateDataMigrations(data: TableData[]): Promise<GeneratedFile[]>;
14
+ }
15
+ //# sourceMappingURL=GeneratorTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeneratorTypes.d.ts","sourceRoot":"","sources":["../../src/generators/GeneratorTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,kBAAkB;IACjC,kBAAkB,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CAC1F;AAED,MAAM,WAAW,sBAAsB;IACrC,sBAAsB,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CACrE"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=GeneratorTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeneratorTypes.js","sourceRoot":"","sources":["../../src/generators/GeneratorTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { GeneratedFile } from './GeneratorTypes';
2
+ export declare class GeneratorWriter {
3
+ static clean(outputDir: string): void;
4
+ static write(files: GeneratedFile[], outputDir: string): void;
5
+ }
6
+ //# sourceMappingURL=GeneratorWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeneratorWriter.d.ts","sourceRoot":"","sources":["../../src/generators/GeneratorWriter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM;IAO9B,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,SAAS,EAAE,MAAM;CAWvD"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratorWriter = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ class GeneratorWriter {
7
+ static clean(outputDir) {
8
+ if ((0, fs_1.existsSync)(outputDir)) {
9
+ (0, fs_1.rmSync)(outputDir, { recursive: true, force: true });
10
+ console.log(`Cleaned output directory: ${outputDir}`);
11
+ }
12
+ }
13
+ static write(files, outputDir) {
14
+ if (!(0, fs_1.existsSync)(outputDir)) {
15
+ (0, fs_1.mkdirSync)(outputDir, { recursive: true });
16
+ }
17
+ for (const file of files) {
18
+ const path = (0, path_1.join)(outputDir, file.fileName);
19
+ (0, fs_1.writeFileSync)(path, file.content, 'utf-8');
20
+ console.log(`Created: ${path}`);
21
+ }
22
+ }
23
+ }
24
+ exports.GeneratorWriter = GeneratorWriter;
25
+ //# sourceMappingURL=GeneratorWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeneratorWriter.js","sourceRoot":"","sources":["../../src/generators/GeneratorWriter.ts"],"names":[],"mappings":";;;AAAA,2BAAkE;AAClE,+BAA4B;AAG5B,MAAa,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,SAAiB;QAC5B,IAAI,IAAA,eAAU,EAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,IAAA,WAAM,EAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAsB,EAAE,SAAiB;QACpD,IAAI,CAAC,IAAA,eAAU,EAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,IAAA,cAAS,EAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,IAAA,kBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF;AAnBD,0CAmBC"}
@@ -0,0 +1,10 @@
1
+ import { DatabaseSchema } from '../types/introspection';
2
+ import { GeneratedFile, SchemaGenerator } from './GeneratorTypes';
3
+ export declare class MongooseGenerator implements SchemaGenerator {
4
+ generate(schema: DatabaseSchema): Promise<GeneratedFile[]>;
5
+ private formatModelName;
6
+ private getTsType;
7
+ private generateFieldDefinition;
8
+ private getMongooseType;
9
+ }
10
+ //# sourceMappingURL=MongooseGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MongooseGenerator.d.ts","sourceRoot":"","sources":["../../src/generators/MongooseGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAElE,qBAAa,iBAAkB,YAAW,eAAe;IACjD,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAuChE,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,uBAAuB;IAkB/B,OAAO,CAAC,eAAe;CAOxB"}