@exogee/graphweaver-mikroorm 0.1.25 → 0.2.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 (52) hide show
  1. package/lib/base-resolver/assign.d.ts +1 -1
  2. package/lib/base-resolver/provider.d.ts +5 -2
  3. package/lib/base-resolver/provider.js +27 -36
  4. package/lib/base-resolver/provider.js.map +3 -3
  5. package/lib/database.d.ts +4 -1
  6. package/lib/database.js +13 -2
  7. package/lib/database.js.map +2 -2
  8. package/lib/index.d.ts +1 -0
  9. package/lib/index.js +1 -0
  10. package/lib/index.js.map +2 -2
  11. package/lib/introspection/files/base-file.d.ts +8 -0
  12. package/lib/introspection/files/base-file.js +38 -0
  13. package/lib/introspection/files/base-file.js.map +7 -0
  14. package/lib/introspection/files/data-entity-file.d.ts +27 -0
  15. package/lib/introspection/files/data-entity-file.js +324 -0
  16. package/lib/introspection/files/data-entity-file.js.map +7 -0
  17. package/lib/introspection/files/data-entity-index-file.d.ts +10 -0
  18. package/lib/introspection/files/data-entity-index-file.js +61 -0
  19. package/lib/introspection/files/data-entity-index-file.js.map +7 -0
  20. package/lib/introspection/files/data-source-index-file.d.ts +8 -0
  21. package/lib/introspection/files/data-source-index-file.js +44 -0
  22. package/lib/introspection/files/data-source-index-file.js.map +7 -0
  23. package/lib/introspection/files/database-file.d.ts +9 -0
  24. package/lib/introspection/files/database-file.js +75 -0
  25. package/lib/introspection/files/database-file.js.map +7 -0
  26. package/lib/introspection/files/index.d.ts +8 -0
  27. package/lib/introspection/files/index.js +26 -0
  28. package/lib/introspection/files/index.js.map +7 -0
  29. package/lib/introspection/files/schema-entity-file.d.ts +25 -0
  30. package/lib/introspection/files/schema-entity-file.js +239 -0
  31. package/lib/introspection/files/schema-entity-file.js.map +7 -0
  32. package/lib/introspection/files/schema-entity-index-file.d.ts +6 -0
  33. package/lib/introspection/files/schema-entity-index-file.js +44 -0
  34. package/lib/introspection/files/schema-entity-index-file.js.map +7 -0
  35. package/lib/introspection/files/schema-index-file.d.ts +8 -0
  36. package/lib/introspection/files/schema-index-file.js +60 -0
  37. package/lib/introspection/files/schema-index-file.js.map +7 -0
  38. package/lib/introspection/files/schema-resolver-file.d.ts +6 -0
  39. package/lib/introspection/files/schema-resolver-file.js +62 -0
  40. package/lib/introspection/files/schema-resolver-file.js.map +7 -0
  41. package/lib/introspection/generate.d.ts +11 -0
  42. package/lib/introspection/generate.js +215 -0
  43. package/lib/introspection/generate.js.map +7 -0
  44. package/lib/introspection/index.d.ts +6 -0
  45. package/lib/introspection/index.js +30 -0
  46. package/lib/introspection/index.js.map +7 -0
  47. package/lib/introspection/utils.d.ts +3 -0
  48. package/lib/introspection/utils.js +43 -0
  49. package/lib/introspection/utils.js.map +7 -0
  50. package/lib/plugins/connect-to-database.js +3 -1
  51. package/lib/plugins/connect-to-database.js.map +2 -2
  52. package/package.json +12 -5
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var data_entity_file_exports = {};
20
+ __export(data_entity_file_exports, {
21
+ DataEntityFile: () => DataEntityFile
22
+ });
23
+ module.exports = __toCommonJS(data_entity_file_exports);
24
+ var import_core = require("@mikro-orm/core");
25
+ var import_base_file = require("./base-file");
26
+ var import_utils = require("../utils");
27
+ class DataEntityFile extends import_base_file.BaseFile {
28
+ constructor(meta, namingStrategy, platform, databaseType) {
29
+ super(meta, namingStrategy, platform);
30
+ this.meta = meta;
31
+ this.namingStrategy = namingStrategy;
32
+ this.platform = platform;
33
+ this.databaseType = databaseType;
34
+ this.coreImports = /* @__PURE__ */ new Set();
35
+ this.entityImports = /* @__PURE__ */ new Set();
36
+ }
37
+ getBasePath() {
38
+ return `backend/entities/${this.databaseType}/`;
39
+ }
40
+ getBaseName() {
41
+ const fileName = (0, import_utils.pascalToKebabCaseString)(this.meta.className);
42
+ return `${fileName}.ts`;
43
+ }
44
+ generate() {
45
+ const enumDefinitions = [];
46
+ let classBody = "";
47
+ const props = Object.values(this.meta.properties);
48
+ props.forEach((prop) => {
49
+ const decorator = this.getPropertyDecorator(prop);
50
+ const definition = this.getPropertyDefinition(prop);
51
+ if (!classBody.endsWith("\n\n")) {
52
+ classBody += "\n";
53
+ }
54
+ classBody += decorator;
55
+ classBody += definition;
56
+ if (props[props.length - 1] !== prop)
57
+ classBody += "\n";
58
+ if (prop.enum) {
59
+ const enumClassName = this.namingStrategy.getClassName(
60
+ this.meta.collection + "_" + prop.fieldNames[0],
61
+ "_"
62
+ );
63
+ enumDefinitions.push(this.getEnumClassDefinition(enumClassName, prop.items));
64
+ }
65
+ });
66
+ let file = ``;
67
+ this.coreImports.add("Entity");
68
+ const imports = [
69
+ `import { ${[...this.coreImports].sort().join(", ")} } from '@mikro-orm/core';`,
70
+ `import { BaseEntity } from '@exogee/graphweaver-mikroorm';`
71
+ ];
72
+ const entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);
73
+ entityImports.sort().forEach((entity) => {
74
+ imports.push(`import { ${entity} } from './${(0, import_utils.pascalToKebabCaseString)(entity)}';`);
75
+ });
76
+ if (enumDefinitions.length) {
77
+ file += enumDefinitions.join("\n");
78
+ file += "\n";
79
+ }
80
+ file += `@Entity(${this.getCollectionDecl()})
81
+ `;
82
+ file += `export class ${this.meta.className} extends BaseEntity {`;
83
+ file += `${classBody}}
84
+ `;
85
+ file = `${imports.join("\n")}
86
+
87
+ ${file}`;
88
+ return file;
89
+ }
90
+ getPropertyType(prop) {
91
+ if (["jsonb", "json", "any"].includes(prop.columnTypes?.[0])) {
92
+ return `Record<string, unknown>`;
93
+ }
94
+ return prop.type;
95
+ }
96
+ getPropertyDefinition(prop) {
97
+ const padding = " ";
98
+ if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
99
+ this.coreImports.add("Collection");
100
+ this.entityImports.add(prop.type);
101
+ return `${padding}${prop.name} = new Collection<${prop.type}>(this);
102
+ `;
103
+ }
104
+ const isEnumOrNonStringDefault = prop.enum || typeof prop.default !== "string";
105
+ const useDefault = prop.default != null && isEnumOrNonStringDefault;
106
+ const optional = prop.nullable ? "?" : useDefault ? "" : "!";
107
+ if (prop.wrappedReference) {
108
+ this.coreImports.add("IdentifiedReference");
109
+ this.entityImports.add(prop.type);
110
+ return `${padding}${prop.name}${optional}: IdentifiedReference<${prop.type}>;
111
+ `;
112
+ }
113
+ if (prop.primary) {
114
+ return `${padding}id!: ${this.getPropertyType(prop)};`;
115
+ }
116
+ const file = `${prop.name}${optional}: ${this.getPropertyType(prop)}`;
117
+ if (!useDefault) {
118
+ return `${padding + file};
119
+ `;
120
+ }
121
+ if (prop.enum && typeof prop.default === "string") {
122
+ return `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};
123
+ `;
124
+ }
125
+ return `${padding}${prop.name} = ${prop.default};
126
+ `;
127
+ }
128
+ getEnumClassDefinition(enumClassName, enumValues) {
129
+ const padding = " ";
130
+ let file = `export enum ${enumClassName} {
131
+ `;
132
+ for (const enumValue of enumValues) {
133
+ file += `${padding}${enumValue.toUpperCase()} = '${enumValue}',
134
+ `;
135
+ }
136
+ file += "}\n";
137
+ return file;
138
+ }
139
+ getCollectionDecl() {
140
+ const options = {};
141
+ options.tableName = this.quote(this.meta.collection);
142
+ if (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {
143
+ options.schema = this.quote(this.meta.schema);
144
+ }
145
+ if (!import_core.Utils.hasObjectKeys(options)) {
146
+ return "";
147
+ }
148
+ return `{ ${Object.entries(options).map(([opt, val]) => `${opt}: ${val}`).join(", ")} }`;
149
+ }
150
+ getPropertyDecorator(prop) {
151
+ const padding = " ";
152
+ const options = {};
153
+ let decorator = this.getDecoratorType(prop);
154
+ this.coreImports.add(decorator.substring(1));
155
+ if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
156
+ this.getManyToManyDecoratorOptions(options, prop);
157
+ } else if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
158
+ this.getOneToManyDecoratorOptions(options, prop);
159
+ } else if (prop.reference !== import_core.ReferenceType.SCALAR) {
160
+ this.getForeignKeyDecoratorOptions(options, prop);
161
+ } else {
162
+ this.getScalarPropertyDecoratorOptions(options, prop);
163
+ }
164
+ if (prop.enum) {
165
+ options.items = `() => ${prop.type}`;
166
+ }
167
+ if (prop.primary && prop.name !== "id" && prop.fieldNames?.[0]) {
168
+ options.fieldName = this.quote(prop.fieldNames[0]);
169
+ }
170
+ this.getCommonDecoratorOptions(options, prop);
171
+ const indexes = this.getPropertyIndexes(prop, options);
172
+ decorator = [...indexes.sort(), decorator].map((d) => padding + d).join("\n");
173
+ if (!import_core.Utils.hasObjectKeys(options)) {
174
+ return `${decorator}()
175
+ `;
176
+ }
177
+ return `${decorator}({ ${Object.entries(options).map(([opt, val]) => `${opt}: ${val}`).join(", ")} })
178
+ `;
179
+ }
180
+ getPropertyIndexes(prop, options) {
181
+ if (prop.reference === import_core.ReferenceType.SCALAR) {
182
+ const ret = [];
183
+ if (prop.index) {
184
+ this.coreImports.add("Index");
185
+ ret.push(`@Index({ name: '${prop.index}' })`);
186
+ }
187
+ if (prop.unique) {
188
+ this.coreImports.add("Unique");
189
+ ret.push(`@Unique({ name: '${prop.unique}' })`);
190
+ }
191
+ return ret;
192
+ }
193
+ const processIndex = (type) => {
194
+ if (!prop[type]) {
195
+ return;
196
+ }
197
+ const defaultName = this.platform.getIndexName(this.meta.collection, prop.fieldNames, type);
198
+ options[type] = defaultName === prop[type] ? "true" : `'${prop[type]}'`;
199
+ const expected = {
200
+ index: this.platform.indexForeignKeys(),
201
+ unique: prop.reference === import_core.ReferenceType.ONE_TO_ONE
202
+ };
203
+ if (expected[type] && options[type] === "true") {
204
+ delete options[type];
205
+ }
206
+ };
207
+ processIndex("index");
208
+ processIndex("unique");
209
+ return [];
210
+ }
211
+ getCommonDecoratorOptions(options, prop) {
212
+ if (prop.nullable && !prop.mappedBy) {
213
+ options.nullable = true;
214
+ }
215
+ if (prop.default == null) {
216
+ return;
217
+ }
218
+ if (typeof prop.default !== "string") {
219
+ options.default = prop.default;
220
+ return;
221
+ }
222
+ if ([`''`, ""].includes(prop.default)) {
223
+ options.default = `''`;
224
+ } else if (prop.defaultRaw === this.quote(prop.default)) {
225
+ options.default = this.quote(prop.default);
226
+ } else {
227
+ options.defaultRaw = `\`${prop.default}\``;
228
+ }
229
+ }
230
+ getScalarPropertyDecoratorOptions(options, prop) {
231
+ let t = prop.type.toLowerCase();
232
+ if (t === "date") {
233
+ t = "datetime";
234
+ }
235
+ if (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {
236
+ options.fieldName = `'${prop.fieldNames[0]}'`;
237
+ }
238
+ if (prop.enum) {
239
+ options.type = this.quote("string");
240
+ return;
241
+ }
242
+ const mappedType1 = this.platform.getMappedType(t);
243
+ const mappedType2 = this.platform.getMappedType(prop.columnTypes[0]);
244
+ const columnType1 = mappedType1.getColumnType({ ...prop, autoincrement: false }, this.platform);
245
+ const columnType2 = mappedType2.getColumnType({ ...prop, autoincrement: false }, this.platform);
246
+ if (columnType1 !== columnType2 || [mappedType1, mappedType2].some((t2) => t2 instanceof import_core.UnknownType)) {
247
+ options.type = this.quote(prop.columnTypes[0]);
248
+ } else {
249
+ options.type = this.quote(prop.type);
250
+ }
251
+ if (prop.length) {
252
+ options.length = prop.length;
253
+ }
254
+ }
255
+ getManyToManyDecoratorOptions(options, prop) {
256
+ this.entityImports.add(prop.type);
257
+ options.entity = `() => ${prop.type}`;
258
+ if (prop.mappedBy) {
259
+ options.mappedBy = this.quote(prop.mappedBy);
260
+ return;
261
+ }
262
+ if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)) {
263
+ options.pivotTable = this.quote(prop.pivotTable);
264
+ }
265
+ if (prop.joinColumns.length === 1) {
266
+ options.joinColumn = this.quote(prop.joinColumns[0]);
267
+ } else {
268
+ options.joinColumns = `[${prop.joinColumns.map(this.quote).join(", ")}]`;
269
+ }
270
+ if (prop.inverseJoinColumns.length === 1) {
271
+ options.inverseJoinColumn = this.quote(prop.inverseJoinColumns[0]);
272
+ } else {
273
+ options.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(", ")}]`;
274
+ }
275
+ }
276
+ getOneToManyDecoratorOptions(options, prop) {
277
+ this.entityImports.add(prop.type);
278
+ options.entity = `() => ${prop.type}`;
279
+ options.mappedBy = this.quote(prop.mappedBy);
280
+ }
281
+ getForeignKeyDecoratorOptions(options, prop) {
282
+ this.entityImports.add(prop.type);
283
+ options.entity = `() => ${prop.type}`;
284
+ if (prop.wrappedReference) {
285
+ options.wrappedReference = true;
286
+ }
287
+ if (prop.mappedBy) {
288
+ options.mappedBy = this.quote(prop.mappedBy);
289
+ return;
290
+ }
291
+ if (prop.fieldNames[0] !== this.namingStrategy.joinKeyColumnName(prop.name, prop.referencedColumnNames[0])) {
292
+ options.fieldName = this.quote(prop.fieldNames[0]);
293
+ }
294
+ if (prop.primary) {
295
+ options.primary = true;
296
+ }
297
+ }
298
+ getDecoratorType(prop) {
299
+ if (prop.reference === import_core.ReferenceType.ONE_TO_ONE) {
300
+ return "@OneToOne";
301
+ }
302
+ if (prop.reference === import_core.ReferenceType.MANY_TO_ONE) {
303
+ return "@ManyToOne";
304
+ }
305
+ if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
306
+ return "@OneToMany";
307
+ }
308
+ if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
309
+ return "@ManyToMany";
310
+ }
311
+ if (prop.primary) {
312
+ return "@PrimaryKey";
313
+ }
314
+ if (prop.enum) {
315
+ return "@Enum";
316
+ }
317
+ return "@Property";
318
+ }
319
+ }
320
+ // Annotate the CommonJS export names for ESM import in node:
321
+ 0 && (module.exports = {
322
+ DataEntityFile
323
+ });
324
+ //# sourceMappingURL=data-entity-file.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/introspection/files/data-entity-file.ts"],
4
+ "sourcesContent": ["// This file is a modified version of source from MikroORM, located here:\n// https://github.com/mikro-orm/mikro-orm/blob/6ba3d4004deef00b754a4ca2011cf64e44a4a3a3/packages/entity-generator/src/SourceFile.ts\n//\n// MIT License\n//\n// Copyright (c) 2018 Martin Ad\u00E1mek\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityOptions,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceType, UnknownType, Utils } from '@mikro-orm/core';\nimport { BaseFile } from './base-file';\nimport { DatabaseType } from '../../database';\nimport { pascalToKebabCaseString } from '../utils';\n\nexport class DataEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\n\tconstructor(\n\t\tprotected readonly meta: EntityMetadata,\n\t\tprotected readonly namingStrategy: NamingStrategy,\n\t\tprotected readonly platform: Platform,\n\t\tprotected readonly databaseType: DatabaseType\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\tconst fileName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `${fileName}.ts`;\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '';\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tconst decorator = this.getPropertyDecorator(prop);\n\t\t\tconst definition = this.getPropertyDefinition(prop);\n\n\t\t\tif (!classBody.endsWith('\\n\\n')) {\n\t\t\t\tclassBody += '\\n';\n\t\t\t}\n\n\t\t\tclassBody += decorator;\n\t\t\tclassBody += definition;\n\n\t\t\tif (props[props.length - 1] !== prop) classBody += '\\n';\n\n\t\t\tif (prop.enum) {\n\t\t\t\tconst enumClassName = this.namingStrategy.getClassName(\n\t\t\t\t\tthis.meta.collection + '_' + prop.fieldNames[0],\n\t\t\t\t\t'_'\n\t\t\t\t);\n\t\t\t\tenumDefinitions.push(this.getEnumClassDefinition(enumClassName, prop.items as string[]));\n\t\t\t}\n\t\t});\n\n\t\tlet file = ``;\n\n\t\tthis.coreImports.add('Entity');\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@mikro-orm/core';`,\n\t\t\t`import { BaseEntity } from '@exogee/graphweaver-mikroorm';`,\n\t\t];\n\t\tconst entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);\n\t\tentityImports.sort().forEach((entity) => {\n\t\t\timports.push(`import { ${entity} } from './${pascalToKebabCaseString(entity)}';`);\n\t\t});\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n';\n\t\t}\n\n\t\tfile += `@Entity(${this.getCollectionDecl()})\\n`;\n\t\tfile += `export class ${this.meta.className} extends BaseEntity {`;\n\n\t\tfile += `${classBody}}\\n`;\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getPropertyType(prop: EntityProperty): string {\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\treturn prop.type;\n\t}\n\n\tprotected getPropertyDefinition(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\n\t\tif ([ReferenceType.ONE_TO_MANY, ReferenceType.MANY_TO_MANY].includes(prop.reference)) {\n\t\t\tthis.coreImports.add('Collection');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name} = new Collection<${prop.type}>(this);\\n`;\n\t\t}\n\n\t\t// string defaults are usually things like SQL functions, but can be also enums, for that `useDefault` should be true\n\t\tconst isEnumOrNonStringDefault = prop.enum || typeof prop.default !== 'string';\n\t\tconst useDefault = prop.default != null && isEnumOrNonStringDefault;\n\t\tconst optional = prop.nullable ? '?' : useDefault ? '' : '!';\n\n\t\tif (prop.wrappedReference) {\n\t\t\tthis.coreImports.add('IdentifiedReference');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}${optional}: IdentifiedReference<${prop.type}>;\\n`;\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\treturn `${padding}id!: ${this.getPropertyType(prop)};`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getPropertyType(prop)}`;\n\n\t\tif (!useDefault) {\n\t\t\treturn `${padding + file};\\n`;\n\t\t}\n\n\t\tif (prop.enum && typeof prop.default === 'string') {\n\t\t\treturn `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};\\n`;\n\t\t}\n\n\t\treturn `${padding}${prop.name} = ${prop.default};\\n`;\n\t}\n\n\tprotected getEnumClassDefinition(enumClassName: string, enumValues: string[]): string {\n\t\tconst padding = '\\t';\n\t\tlet file = `export enum ${enumClassName} {\\n`;\n\n\t\tfor (const enumValue of enumValues) {\n\t\t\tfile += `${padding}${enumValue.toUpperCase()} = '${enumValue}',\\n`;\n\t\t}\n\n\t\tfile += '}\\n';\n\n\t\treturn file;\n\t}\n\n\tprivate getCollectionDecl() {\n\t\tconst options: EntityOptions<unknown> = {};\n\n\t\toptions.tableName = this.quote(this.meta.collection);\n\n\t\tif (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {\n\t\t\toptions.schema = this.quote(this.meta.schema);\n\t\t}\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `{ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} }`;\n\t}\n\n\tprivate getPropertyDecorator(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\t\tconst options = {} as Dictionary;\n\t\tlet decorator = this.getDecoratorType(prop);\n\t\tthis.coreImports.add(decorator.substring(1));\n\n\t\tif (prop.reference === ReferenceType.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.reference === ReferenceType.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.reference !== ReferenceType.SCALAR) {\n\t\t\tthis.getForeignKeyDecoratorOptions(options, prop);\n\t\t} else {\n\t\t\tthis.getScalarPropertyDecoratorOptions(options, prop);\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\toptions.items = `() => ${prop.type}`;\n\t\t}\n\n\t\tif (prop.primary && prop.name !== 'id' && prop.fieldNames?.[0]) {\n\t\t\toptions.fieldName = this.quote(prop.fieldNames[0]);\n\t\t}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tconst indexes = this.getPropertyIndexes(prop, options);\n\t\tdecorator = [...indexes.sort(), decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}()\\n`;\n\t\t}\n\n\t\treturn `${decorator}({ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\n\t}\n\n\tprotected getPropertyIndexes(prop: EntityProperty, options: Dictionary): string[] {\n\t\tif (prop.reference === ReferenceType.SCALAR) {\n\t\t\tconst ret: string[] = [];\n\n\t\t\tif (prop.index) {\n\t\t\t\tthis.coreImports.add('Index');\n\t\t\t\tret.push(`@Index({ name: '${prop.index}' })`);\n\t\t\t}\n\n\t\t\tif (prop.unique) {\n\t\t\t\tthis.coreImports.add('Unique');\n\t\t\t\tret.push(`@Unique({ name: '${prop.unique}' })`);\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tconst processIndex = (type: 'index' | 'unique') => {\n\t\t\tif (!prop[type]) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultName = this.platform.getIndexName(this.meta.collection, prop.fieldNames, type);\n\t\t\toptions[type] = defaultName === prop[type] ? 'true' : `'${prop[type]}'`;\n\t\t\tconst expected = {\n\t\t\t\tindex: this.platform.indexForeignKeys(),\n\t\t\t\tunique: prop.reference === ReferenceType.ONE_TO_ONE,\n\t\t\t};\n\n\t\t\tif (expected[type] && options[type] === 'true') {\n\t\t\t\tdelete options[type];\n\t\t\t}\n\t\t};\n\n\t\tprocessIndex('index');\n\t\tprocessIndex('unique');\n\n\t\treturn [];\n\t}\n\n\tprotected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tif (prop.nullable && !prop.mappedBy) {\n\t\t\toptions.nullable = true;\n\t\t}\n\n\t\tif (prop.default == null) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof prop.default !== 'string') {\n\t\t\toptions.default = prop.default;\n\t\t\treturn;\n\t\t}\n\n\t\tif ([`''`, ''].includes(prop.default)) {\n\t\t\toptions.default = `''`;\n\t\t} else if (prop.defaultRaw === this.quote(prop.default)) {\n\t\t\toptions.default = this.quote(prop.default);\n\t\t} else {\n\t\t\toptions.defaultRaw = `\\`${prop.default}\\``;\n\t\t}\n\t}\n\n\tprotected getScalarPropertyDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tlet t = prop.type.toLowerCase();\n\n\t\tif (t === 'date') {\n\t\t\tt = 'datetime';\n\t\t}\n\n\t\tif (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {\n\t\t\toptions.fieldName = `'${prop.fieldNames[0]}'`;\n\t\t}\n\n\t\t// for enum properties, we don't need a column type or the property length\n\t\t// in the decorator so return early.\n\t\tif (prop.enum) {\n\t\t\toptions.type = this.quote('string');\n\t\t\treturn;\n\t\t}\n\n\t\tconst mappedType1 = this.platform.getMappedType(t);\n\t\tconst mappedType2 = this.platform.getMappedType(prop.columnTypes[0]);\n\t\tconst columnType1 = mappedType1.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\t\tconst columnType2 = mappedType2.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\n\t\tif (\n\t\t\tcolumnType1 !== columnType2 ||\n\t\t\t[mappedType1, mappedType2].some((t) => t instanceof UnknownType)\n\t\t) {\n\t\t\toptions.type = this.quote(prop.columnTypes[0]);\n\t\t} else {\n\t\t\toptions.type = this.quote(prop.type);\n\t\t}\n\n\t\tif (prop.length) {\n\t\t\toptions.length = prop.length;\n\t\t}\n\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.pivotTable !==\n\t\t\tthis.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)\n\t\t) {\n\t\t\toptions.pivotTable = this.quote(prop.pivotTable);\n\t\t}\n\n\t\tif (prop.joinColumns.length === 1) {\n\t\t\toptions.joinColumn = this.quote(prop.joinColumns[0]);\n\t\t} else {\n\t\t\toptions.joinColumns = `[${prop.joinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\n\t\tif (prop.inverseJoinColumns.length === 1) {\n\t\t\toptions.inverseJoinColumn = this.quote(prop.inverseJoinColumns[0]);\n\t\t} else {\n\t\t\toptions.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.wrappedReference) {\n\t\t\toptions.wrappedReference = true;\n\t\t}\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.fieldNames[0] !==\n\t\t\tthis.namingStrategy.joinKeyColumnName(prop.name, prop.referencedColumnNames[0])\n\t\t) {\n\t\t\toptions.fieldName = this.quote(prop.fieldNames[0]);\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\toptions.primary = true;\n\t\t}\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif (prop.reference === ReferenceType.ONE_TO_ONE) {\n\t\t\treturn '@OneToOne';\n\t\t}\n\n\t\tif (prop.reference === ReferenceType.MANY_TO_ONE) {\n\t\t\treturn '@ManyToOne';\n\t\t}\n\n\t\tif (prop.reference === ReferenceType.ONE_TO_MANY) {\n\t\t\treturn '@OneToMany';\n\t\t}\n\n\t\tif (prop.reference === ReferenceType.MANY_TO_MANY) {\n\t\t\treturn '@ManyToMany';\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\treturn '@PrimaryKey';\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\treturn '@Enum';\n\t\t}\n\n\t\treturn '@Property';\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,kBAAkD;AAClD,uBAAyB;AAEzB,mBAAwC;AAEjC,MAAM,uBAAuB,0BAAS;AAAA,EAI5C,YACoB,MACA,gBACA,UACA,cAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AALjB;AACA;AACA;AACA;AAPpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AAAA,EASnD;AAAA,EAEA,cAAc;AACb,WAAO,oBAAoB,KAAK;AAAA,EACjC;AAAA,EAEA,cAAc;AACb,UAAM,eAAW,sCAAwB,KAAK,KAAK,SAAS;AAC5D,WAAO,GAAG;AAAA,EACX;AAAA,EAEA,WAAmB;AAClB,UAAM,kBAA4B,CAAC;AACnC,QAAI,YAAY;AAChB,UAAM,QAAQ,OAAO,OAAO,KAAK,KAAK,UAAU;AAChD,UAAM,QAAQ,CAAC,SAAS;AACvB,YAAM,YAAY,KAAK,qBAAqB,IAAI;AAChD,YAAM,aAAa,KAAK,sBAAsB,IAAI;AAElD,UAAI,CAAC,UAAU,SAAS,MAAM,GAAG;AAChC,qBAAa;AAAA,MACd;AAEA,mBAAa;AACb,mB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c,0BAAc,aAAa;AACjD,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,cAAc,0BAAc,cAAc;AAClD,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS;AACjB,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,MAAM;AACd,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AACD;",
6
+ "names": ["t"]
7
+ }
@@ -0,0 +1,10 @@
1
+ import { EntityMetadata } from '@mikro-orm/core';
2
+ import { DatabaseType } from '../../database';
3
+ export declare class DataEntityIndexFile {
4
+ protected readonly metadata: EntityMetadata<any>[];
5
+ protected readonly databaseType: DatabaseType;
6
+ constructor(metadata: EntityMetadata<any>[], databaseType: DatabaseType);
7
+ getBasePath(): string;
8
+ getBaseName(): string;
9
+ generate(): string;
10
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var data_entity_index_file_exports = {};
20
+ __export(data_entity_index_file_exports, {
21
+ DataEntityIndexFile: () => DataEntityIndexFile
22
+ });
23
+ module.exports = __toCommonJS(data_entity_index_file_exports);
24
+ class DataEntityIndexFile {
25
+ constructor(metadata, databaseType) {
26
+ this.metadata = metadata;
27
+ this.databaseType = databaseType;
28
+ }
29
+ getBasePath() {
30
+ return `backend/entities/${this.databaseType}/`;
31
+ }
32
+ getBaseName() {
33
+ return "index.ts";
34
+ }
35
+ generate() {
36
+ let file = "export const entities = [\n";
37
+ const padding = " ";
38
+ const imports = [];
39
+ const exports = [];
40
+ for (const meta of this.metadata) {
41
+ if (!meta.pivotTable) {
42
+ const filename = meta.className.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase();
43
+ exports.push(`export * from './${filename}';`);
44
+ imports.push(`import { ${meta.className} } from './${filename}';`);
45
+ file += `${padding}${meta.className},
46
+ `;
47
+ }
48
+ }
49
+ file += "];\n";
50
+ return `${imports.join("\n")}
51
+
52
+ ${exports.join("\n")}
53
+
54
+ ${file}`;
55
+ }
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ DataEntityIndexFile
60
+ });
61
+ //# sourceMappingURL=data-entity-index-file.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/introspection/files/data-entity-index-file.ts"],
4
+ "sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\n\nexport class DataEntityIndexFile {\n\tconstructor(\n\t\tprotected readonly metadata: EntityMetadata<any>[],\n\t\tprotected readonly databaseType: DatabaseType\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tlet file = 'export const entities = [\\n';\n\t\tconst padding = '\\t';\n\t\tconst imports: string[] = [];\n\t\tconst exports: string[] = [];\n\n\t\tfor (const meta of this.metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst filename = meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n\t\t\t\texports.push(`export * from './${filename}';`);\n\t\t\t\timports.push(`import { ${meta.className} } from './${filename}';`);\n\t\t\t\tfile += `${padding}${meta.className},\\n`;\n\t\t\t}\n\t\t}\n\n\t\tfile += '];\\n';\n\n\t\treturn `${imports.join('\\n')}\\n\\n${exports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,oBAAoB;AAAA,EAChC,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO,oBAAoB,KAAK;AAAA,EACjC;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,QAAI,OAAO;AACX,UAAM,UAAU;AAChB,UAAM,UAAoB,CAAC;AAC3B,UAAM,UAAoB,CAAC;AAE3B,eAAW,QAAQ,KAAK,UAAU;AACjC,UAAI,CAAC,KAAK,YAAY;AACrB,cAAM,WAAW,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACnF,gBAAQ,KAAK,oBAAoB,YAAY;AAC7C,gBAAQ,KAAK,YAAY,KAAK,uBAAuB,YAAY;AACjE,gBAAQ,GAAG,UAAU,KAAK;AAAA;AAAA,MAC3B;AAAA,IACD;AAEA,YAAQ;AAER,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ;AAAA,EAC7D;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ import { DatabaseType } from '../../database';
2
+ export declare class DataSourceIndexFile {
3
+ protected readonly databaseType: DatabaseType;
4
+ constructor(databaseType: DatabaseType);
5
+ getBasePath(): string;
6
+ getBaseName(): string;
7
+ generate(): string;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var data_source_index_file_exports = {};
20
+ __export(data_source_index_file_exports, {
21
+ DataSourceIndexFile: () => DataSourceIndexFile
22
+ });
23
+ module.exports = __toCommonJS(data_source_index_file_exports);
24
+ class DataSourceIndexFile {
25
+ constructor(databaseType) {
26
+ this.databaseType = databaseType;
27
+ }
28
+ getBasePath() {
29
+ return `backend/entities/`;
30
+ }
31
+ getBaseName() {
32
+ return "index.ts";
33
+ }
34
+ generate() {
35
+ const imports = [`export * from './${this.databaseType}';`];
36
+ return `${imports.join("\n")}
37
+ `;
38
+ }
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ DataSourceIndexFile
43
+ });
44
+ //# sourceMappingURL=data-source-index-file.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/introspection/files/data-source-index-file.ts"],
4
+ "sourcesContent": ["import { DatabaseType } from '../../database';\n\nexport class DataSourceIndexFile {\n\tconstructor(protected readonly databaseType: DatabaseType) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst imports = [`export * from './${this.databaseType}';`];\n\n\t\treturn `${imports.join('\\n')}\\n`;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAoB;AAAA,EAChC,YAA+B,cAA4B;AAA5B;AAAA,EAA6B;AAAA,EAE5D,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,UAAU,CAAC,oBAAoB,KAAK,gBAAgB;AAE1D,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAC5B;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ import { ConnectionOptions, DatabaseType } from '../../database';
2
+ export declare class DatabaseFile {
3
+ protected readonly databaseType: DatabaseType;
4
+ protected readonly connection: ConnectionOptions;
5
+ constructor(databaseType: DatabaseType, connection: ConnectionOptions);
6
+ getBasePath(): string;
7
+ getBaseName(): string;
8
+ generate(): string;
9
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var database_file_exports = {};
20
+ __export(database_file_exports, {
21
+ DatabaseFile: () => DatabaseFile
22
+ });
23
+ module.exports = __toCommonJS(database_file_exports);
24
+ class DatabaseFile {
25
+ constructor(databaseType, connection) {
26
+ this.databaseType = databaseType;
27
+ this.connection = connection;
28
+ }
29
+ getBasePath() {
30
+ return `backend/`;
31
+ }
32
+ getBaseName() {
33
+ return "database.ts";
34
+ }
35
+ generate() {
36
+ const isPostgresql = this.databaseType === "postgresql";
37
+ const isMySQL = this.databaseType === "mysql";
38
+ const isSQLite = this.databaseType === "sqlite";
39
+ const imports = [
40
+ ...isPostgresql ? [`import { PostgreSqlDriver } from '@mikro-orm/postgresql';`] : [],
41
+ ...isMySQL ? [`import { MySqlDriver } from '@mikro-orm/mysql';`] : [],
42
+ ...isSQLite ? [`import { SqliteDriver } from '@mikro-orm/sqlite';`] : [],
43
+ `import { entities } from './entities';`
44
+ ];
45
+ const exports = [`export const connections = [connection];`];
46
+ const pad = " ";
47
+ const config = this.connection.mikroOrmConfig;
48
+ const connection = [`export const connection = {`];
49
+ connection.push(`${pad}connectionManagerId: '${this.databaseType}',`);
50
+ connection.push(`${pad}mikroOrmConfig: {`);
51
+ connection.push(`${pad}${pad}entities: entities,`);
52
+ connection.push(
53
+ `${pad}${pad}driver: ${isPostgresql ? "PostgreSqlDriver" : isMySQL ? "MySqlDriver" : "SqliteDriver"},`
54
+ );
55
+ connection.push(`${pad}${pad}dbName: '${config.dbName}',`);
56
+ if (!isSQLite) {
57
+ connection.push(`${pad}${pad}user: '${config.user}',`);
58
+ connection.push(`${pad}${pad}password: '${config.password}',`);
59
+ connection.push(`${pad}${pad}port: ${config.port},`);
60
+ }
61
+ connection.push(`${pad}},`);
62
+ connection.push(`};`);
63
+ return `${imports.join("\n")}
64
+
65
+ ${connection.join("\n")}
66
+
67
+ ${exports.join("\n")}
68
+ `;
69
+ }
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ DatabaseFile
74
+ });
75
+ //# sourceMappingURL=database-file.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/introspection/files/database-file.ts"],
4
+ "sourcesContent": ["import { Options } from '@mikro-orm/core';\nimport { ConnectionOptions, DatabaseType } from '../../database';\n\nexport class DatabaseFile {\n\tconstructor(\n\t\tprotected readonly databaseType: DatabaseType,\n\t\tprotected readonly connection: ConnectionOptions\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'database.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst isPostgresql = this.databaseType === 'postgresql';\n\t\tconst isMySQL = this.databaseType === 'mysql';\n\t\tconst isSQLite = this.databaseType === 'sqlite';\n\t\tconst imports = [\n\t\t\t...(isPostgresql ? [`import { PostgreSqlDriver } from '@mikro-orm/postgresql';`] : []),\n\t\t\t...(isMySQL ? [`import { MySqlDriver } from '@mikro-orm/mysql';`] : []),\n\t\t\t...(isSQLite ? [`import { SqliteDriver } from '@mikro-orm/sqlite';`] : []),\n\t\t\t`import { entities } from './entities';`,\n\t\t];\n\t\tconst exports = [`export const connections = [connection];`];\n\n\t\tconst pad = '\\t';\n\n\t\tconst config = this.connection.mikroOrmConfig as Options;\n\n\t\tconst connection = [`export const connection = {`];\n\t\tconnection.push(`${pad}connectionManagerId: '${this.databaseType}',`);\n\t\tconnection.push(`${pad}mikroOrmConfig: {`);\n\t\tconnection.push(`${pad}${pad}entities: entities,`);\n\t\tconnection.push(\n\t\t\t`${pad}${pad}driver: ${\n\t\t\t\tisPostgresql ? 'PostgreSqlDriver' : isMySQL ? 'MySqlDriver' : 'SqliteDriver'\n\t\t\t},`\n\t\t);\n\t\tconnection.push(`${pad}${pad}dbName: '${config.dbName}',`);\n\t\tif (!isSQLite) {\n\t\t\tconnection.push(`${pad}${pad}user: '${config.user}',`);\n\t\t\tconnection.push(`${pad}${pad}password: '${config.password}',`);\n\t\t\tconnection.push(`${pad}${pad}port: ${config.port},`);\n\t\t}\n\t\tconnection.push(`${pad}},`);\n\t\tconnection.push(`};`);\n\n\t\treturn `${imports.join('\\n')}\\n\\n${connection.join('\\n')}\\n\\n${exports.join('\\n')}\\n`;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;A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
+ }
@@ -0,0 +1,8 @@
1
+ export * from './data-entity-file';
2
+ export * from './data-entity-index-file';
3
+ export * from './data-source-index-file';
4
+ export * from './schema-entity-file';
5
+ export * from './schema-entity-index-file';
6
+ export * from './schema-index-file';
7
+ export * from './schema-resolver-file';
8
+ export * from './database-file';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var files_exports = {};
17
+ module.exports = __toCommonJS(files_exports);
18
+ __reExport(files_exports, require("./data-entity-file"), module.exports);
19
+ __reExport(files_exports, require("./data-entity-index-file"), module.exports);
20
+ __reExport(files_exports, require("./data-source-index-file"), module.exports);
21
+ __reExport(files_exports, require("./schema-entity-file"), module.exports);
22
+ __reExport(files_exports, require("./schema-entity-index-file"), module.exports);
23
+ __reExport(files_exports, require("./schema-index-file"), module.exports);
24
+ __reExport(files_exports, require("./schema-resolver-file"), module.exports);
25
+ __reExport(files_exports, require("./database-file"), module.exports);
26
+ //# sourceMappingURL=index.js.map