@exogee/graphweaver-mikroorm 0.2.17 → 0.2.20

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.
@@ -95,7 +95,7 @@ ${file}`;
95
95
  }
96
96
  getPropertyDefinition(prop) {
97
97
  const padding = " ";
98
- if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
98
+ if ([import_core.ReferenceKind.ONE_TO_MANY, import_core.ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
99
99
  this.coreImports.add("Collection");
100
100
  this.entityImports.add(prop.type);
101
101
  return `${padding}${prop.name} = new Collection<${prop.type}>(this);
@@ -104,10 +104,10 @@ ${file}`;
104
104
  const isEnumOrNonStringDefault = prop.enum || typeof prop.default !== "string";
105
105
  const useDefault = prop.default != null && isEnumOrNonStringDefault;
106
106
  const optional = prop.nullable ? "?" : useDefault ? "" : "!";
107
- if (prop.wrappedReference) {
108
- this.coreImports.add("IdentifiedReference");
107
+ if (prop.ref) {
108
+ this.coreImports.add("Ref");
109
109
  this.entityImports.add(prop.type);
110
- return `${padding}${prop.name}${optional}: IdentifiedReference<${prop.type}>;
110
+ return `${padding}${prop.name}${optional}: Ref<${prop.type}>;
111
111
  `;
112
112
  }
113
113
  if (prop.primary) {
@@ -152,11 +152,11 @@ ${file}`;
152
152
  const options = {};
153
153
  let decorator = this.getDecoratorType(prop);
154
154
  this.coreImports.add(decorator.substring(1));
155
- if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
155
+ if (prop.kind === import_core.ReferenceKind.MANY_TO_MANY) {
156
156
  this.getManyToManyDecoratorOptions(options, prop);
157
- } else if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
157
+ } else if (prop.kind === import_core.ReferenceKind.ONE_TO_MANY) {
158
158
  this.getOneToManyDecoratorOptions(options, prop);
159
- } else if (prop.reference !== import_core.ReferenceType.SCALAR) {
159
+ } else if (prop.kind !== import_core.ReferenceKind.SCALAR) {
160
160
  this.getForeignKeyDecoratorOptions(options, prop);
161
161
  } else {
162
162
  this.getScalarPropertyDecoratorOptions(options, prop);
@@ -178,7 +178,7 @@ ${file}`;
178
178
  `;
179
179
  }
180
180
  getPropertyIndexes(prop, options) {
181
- if (prop.reference === import_core.ReferenceType.SCALAR) {
181
+ if (prop.kind === import_core.ReferenceKind.SCALAR) {
182
182
  const ret = [];
183
183
  if (prop.index) {
184
184
  this.coreImports.add("Index");
@@ -198,7 +198,7 @@ ${file}`;
198
198
  options[type] = defaultName === prop[type] ? "true" : `'${prop[type]}'`;
199
199
  const expected = {
200
200
  index: this.platform.indexForeignKeys(),
201
- unique: prop.reference === import_core.ReferenceType.ONE_TO_ONE
201
+ unique: prop.kind === import_core.ReferenceKind.ONE_TO_ONE
202
202
  };
203
203
  if (expected[type] && options[type] === "true") {
204
204
  delete options[type];
@@ -281,8 +281,8 @@ ${file}`;
281
281
  getForeignKeyDecoratorOptions(options, prop) {
282
282
  this.entityImports.add(prop.type);
283
283
  options.entity = `() => ${prop.type}`;
284
- if (prop.wrappedReference) {
285
- options.wrappedReference = true;
284
+ if (prop.ref) {
285
+ options.ref = true;
286
286
  }
287
287
  if (prop.mappedBy) {
288
288
  options.mappedBy = this.quote(prop.mappedBy);
@@ -296,16 +296,16 @@ ${file}`;
296
296
  }
297
297
  }
298
298
  getDecoratorType(prop) {
299
- if (prop.reference === import_core.ReferenceType.ONE_TO_ONE) {
299
+ if (prop.kind === import_core.ReferenceKind.ONE_TO_ONE) {
300
300
  return "@OneToOne";
301
301
  }
302
- if (prop.reference === import_core.ReferenceType.MANY_TO_ONE) {
302
+ if (prop.kind === import_core.ReferenceKind.MANY_TO_ONE) {
303
303
  return "@ManyToOne";
304
304
  }
305
- if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
305
+ if (prop.kind === import_core.ReferenceKind.ONE_TO_MANY) {
306
306
  return "@OneToMany";
307
307
  }
308
- if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
308
+ if (prop.kind === import_core.ReferenceKind.MANY_TO_MANY) {
309
309
  return "@ManyToMany";
310
310
  }
311
311
  if (prop.primary) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,mBAAa;AAEb,UAAI,MAAM,MAAM,SAAS,OAAO;AAAM,qBAAa;AAEnD,UAAI,KAAK,MAAM;AACd,cAAM,gBAAgB,KAAK,eAAe;AAAA,UACzC,KAAK,KAAK,aAAa,MAAM,KAAK,WAAW;AAAA,UAC7C;AAAA,QACD;AACA,wBAAgB,KAAK,KAAK,uBAAuB,eAAe,KAAK,KAAiB,CAAC;AAAA,MACx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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 { ReferenceKind, 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 ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {\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.ref) {\n\t\t\tthis.coreImports.add('Ref');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}${optional}: Ref<${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.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind !== ReferenceKind.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.kind === ReferenceKind.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.kind === ReferenceKind.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.ref) {\n\t\t\toptions.ref = 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.kind === ReferenceKind.ONE_TO_ONE) {\n\t\t\treturn '@OneToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_ONE) {\n\t\t\treturn '@ManyToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\treturn '@OneToMany';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.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": ";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,IAAI,KAAK,IAAI;AAChC,YAAQ,SAAS,SAAS,KAAK;AAC/B,YAAQ,WAAW,KAAK,MAAM,KAAK,QAAQ;AAAA,EAC5C;AAAA,EAEU,8BAA8B,SAAqB,MAAsB;AAClF,SAAK,cAAc,IAAI,KAAK,IAAI;AAChC,YAAQ,SAAS,SAAS,KAAK;AAE/B,QAAI,KAAK,KAAK;AACb,cAAQ,MAAM;AAAA,IACf;AAEA,QAAI,KAAK,UAAU;AAClB,cAAQ,WAAW,KAAK,MAAM,KAAK,QAAQ;AAC3C;AAAA,IACD;AAEA,QACC,KAAK,WAAW,OAChB,KAAK,eAAe,kBAAkB,KAAK,MAAM,KAAK,sBAAsB,EAAE,GAC7E;AACD,cAAQ,YAAY,KAAK,MAAM,KAAK,WAAW,EAAE;AAAA,IAClD;AAEA,QAAI,KAAK,SAAS;AACjB,cAAQ,UAAU;AAAA,IACnB;AAAA,EACD;AAAA,EAEU,iBAAiB,MAA8B;AACxD,QAAI,KAAK,SAAS,0BAAc,YAAY;AAC3C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,aAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,aAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,cAAc;AAC7C,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
6
  "names": ["t"]
7
7
  }
@@ -39,7 +39,7 @@ class DatabaseFile {
39
39
  const imports = [
40
40
  ...isPostgresql ? [`import { PostgreSqlDriver } from '@mikro-orm/postgresql';`] : [],
41
41
  ...isMySQL ? [`import { MySqlDriver } from '@mikro-orm/mysql';`] : [],
42
- ...isSQLite ? [`import { SqliteDriver } from '@mikro-orm/sqlite';`] : [],
42
+ ...isSQLite ? [`import { SqliteDriver } from 'mikro-orm-sqlite-wasm';`] : [],
43
43
  `import { entities } from './entities';`
44
44
  ];
45
45
  const exports = [`export const connections = [connection];`];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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}host: '${config.host}',`);\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;AAAA;AAAA;AAAA;AAGO,MAAM,aAAa;AAAA,EACzB,YACoB,cACA,YAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,eAAe,KAAK,iBAAiB;AAC3C,UAAM,UAAU,KAAK,iBAAiB;AACtC,UAAM,WAAW,KAAK,iBAAiB;AACvC,UAAM,UAAU;AAAA,MACf,GAAI,eAAe,CAAC,2DAA2D,IAAI,CAAC;AAAA,MACpF,GAAI,UAAU,CAAC,iDAAiD,IAAI,CAAC;AAAA,MACrE,GAAI,WAAW,CAAC,mDAAmD,IAAI,CAAC;AAAA,MACxE;AAAA,IACD;AACA,UAAM,UAAU,CAAC,0CAA0C;AAE3D,UAAM,MAAM;AAEZ,UAAM,SAAS,KAAK,WAAW;AAE/B,UAAM,aAAa,CAAC,6BAA6B;AACjD,eAAW,KAAK,GAAG,4BAA4B,KAAK,gBAAgB;AACpE,eAAW,KAAK,GAAG,sBAAsB;AACzC,eAAW,KAAK,GAAG,MAAM,wBAAwB;AACjD,eAAW;AAAA,MACV,GAAG,MAAM,cACR,eAAe,qBAAqB,UAAU,gBAAgB;AAAA,IAEhE;AACA,eAAW,KAAK,GAAG,MAAM,eAAe,OAAO,UAAU;AACzD,QAAI,CAAC,UAAU;AACd,iBAAW,KAAK,GAAG,MAAM,aAAa,OAAO,QAAQ;AACrD,iBAAW,KAAK,GAAG,MAAM,aAAa,OAAO,QAAQ;AACrD,iBAAW,KAAK,GAAG,MAAM,iBAAiB,OAAO,YAAY;AAC7D,iBAAW,KAAK,GAAG,MAAM,YAAY,OAAO,OAAO;AAAA,IACpD;AACA,eAAW,KAAK,GAAG,OAAO;AAC1B,eAAW,KAAK,IAAI;AAEpB,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ,WAAW,KAAK,IAAI;AAAA;AAAA,EAAQ,QAAQ,KAAK,IAAI;AAAA;AAAA,EACjF;AACD;",
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-wasm';`] : []),\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}host: '${config.host}',`);\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;AAAA;AAAA;AAAA;AAGO,MAAM,aAAa;AAAA,EACzB,YACoB,cACA,YAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,eAAe,KAAK,iBAAiB;AAC3C,UAAM,UAAU,KAAK,iBAAiB;AACtC,UAAM,WAAW,KAAK,iBAAiB;AACvC,UAAM,UAAU;AAAA,MACf,GAAI,eAAe,CAAC,2DAA2D,IAAI,CAAC;AAAA,MACpF,GAAI,UAAU,CAAC,iDAAiD,IAAI,CAAC;AAAA,MACrE,GAAI,WAAW,CAAC,uDAAuD,IAAI,CAAC;AAAA,MAC5E;AAAA,IACD;AACA,UAAM,UAAU,CAAC,0CAA0C;AAE3D,UAAM,MAAM;AAEZ,UAAM,SAAS,KAAK,WAAW;AAE/B,UAAM,aAAa,CAAC,6BAA6B;AACjD,eAAW,KAAK,GAAG,4BAA4B,KAAK,gBAAgB;AACpE,eAAW,KAAK,GAAG,sBAAsB;AACzC,eAAW,KAAK,GAAG,MAAM,wBAAwB;AACjD,eAAW;AAAA,MACV,GAAG,MAAM,cACR,eAAe,qBAAqB,UAAU,gBAAgB;AAAA,IAEhE;AACA,eAAW,KAAK,GAAG,MAAM,eAAe,OAAO,UAAU;AACzD,QAAI,CAAC,UAAU;AACd,iBAAW,KAAK,GAAG,MAAM,aAAa,OAAO,QAAQ;AACrD,iBAAW,KAAK,GAAG,MAAM,aAAa,OAAO,QAAQ;AACrD,iBAAW,KAAK,GAAG,MAAM,iBAAiB,OAAO,YAAY;AAC7D,iBAAW,KAAK,GAAG,MAAM,YAAY,OAAO,OAAO;AAAA,IACpD;AACA,eAAW,KAAK,GAAG,OAAO;AAC1B,eAAW,KAAK,IAAI;AAEpB,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ,WAAW,KAAK,IAAI;AAAA;AAAA,EAAQ,QAAQ,KAAK,IAAI;AAAA;AAAA,EACjF;AACD;",
6
6
  "names": []
7
7
  }
@@ -124,7 +124,7 @@ ${file}`;
124
124
  }
125
125
  getPropertyDefinition(prop) {
126
126
  const padding = " ";
127
- if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
127
+ if ([import_core.ReferenceKind.ONE_TO_MANY, import_core.ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
128
128
  this.entityImports.add(prop.type);
129
129
  return `${padding}${prop.name}!: ${prop.type}[];
130
130
  `;
@@ -174,7 +174,7 @@ ${file}`;
174
174
  if (prop.type.includes("[]")) {
175
175
  return `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace("[]", "")}]`;
176
176
  }
177
- if ([import_core.ReferenceType.MANY_TO_MANY, import_core.ReferenceType.ONE_TO_MANY].includes(prop.reference)) {
177
+ if ([import_core.ReferenceKind.MANY_TO_MANY, import_core.ReferenceKind.ONE_TO_MANY].includes(prop.kind)) {
178
178
  return `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace("[]", "")}]`;
179
179
  }
180
180
  if (prop.pivotTable) {
@@ -186,11 +186,11 @@ ${file}`;
186
186
  const padding = " ";
187
187
  const options = {};
188
188
  let decorator = this.getDecoratorType(prop);
189
- if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
189
+ if (prop.kind === import_core.ReferenceKind.MANY_TO_MANY) {
190
190
  this.getManyToManyDecoratorOptions(options, prop);
191
- } else if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
191
+ } else if (prop.kind === import_core.ReferenceKind.ONE_TO_MANY) {
192
192
  this.getOneToManyDecoratorOptions(options, prop);
193
- } else if (prop.reference !== import_core.ReferenceType.SCALAR) {
193
+ } else if (prop.kind !== import_core.ReferenceKind.SCALAR) {
194
194
  this.getForeignKeyDecoratorOptions(options, prop);
195
195
  }
196
196
  this.getCommonDecoratorOptions(options, prop);
@@ -220,11 +220,11 @@ ${file}`;
220
220
  options.id = `(entity) => entity.${prop.name}?.id`;
221
221
  }
222
222
  getDecoratorType(prop) {
223
- if ([import_core.ReferenceType.ONE_TO_ONE, import_core.ReferenceType.MANY_TO_ONE].includes(prop.reference)) {
223
+ if ([import_core.ReferenceKind.ONE_TO_ONE, import_core.ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
224
224
  this.coreImports.add("RelationshipField");
225
225
  return `@RelationshipField<${this.meta.className}>`;
226
226
  }
227
- if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
227
+ if ([import_core.ReferenceKind.ONE_TO_MANY, import_core.ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
228
228
  this.coreImports.add("RelationshipField");
229
229
  return `@RelationshipField<${prop.type}>`;
230
230
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/introspection/files/schema-entity-file.ts"],
4
- "sourcesContent": ["import type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceType, Utils } from '@mikro-orm/core';\n\nimport { BaseFile } from './base-file';\nimport { pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';\nimport pluralize from 'pluralize';\n\nexport class SchemaEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly scalarImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\tprotected readonly enumImports = 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) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\tconst dirName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `backend/schema/${dirName}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'entity.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '\\n';\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\t// Add a summary field if we have a name or title attribute\n\t\t\tif (['name', 'title'].includes(prop.name.toLowerCase())) {\n\t\t\t\tthis.coreImports.add('SummaryField');\n\t\t\t\tclassBody += `\\t@SummaryField()\\n`;\n\t\t\t}\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));\n\t\t\t}\n\t\t});\n\n\t\tlet file = '';\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n\\n';\n\t\t}\n\n\t\tthis.coreImports.add('ObjectType');\n\t\tfile += `@ObjectType(${this.quote(this.meta.className)})\\n`;\n\n\t\tthis.coreImports.add('GraphQLEntity');\n\t\tfile += `export class ${this.meta.className} extends GraphQLEntity<Orm${this.meta.className}> {\\n`;\n\t\tfile += `\\tpublic dataEntity!: Orm${this.meta.className};`;\n\n\t\tfile += `${classBody}}\\n`;\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@exogee/graphweaver';`,\n\t\t];\n\n\t\tif (this.scalarImports.size > 0) {\n\t\t\timports.push(\n\t\t\t\t`import { ${[...this.scalarImports]\n\t\t\t\t\t.sort()\n\t\t\t\t\t.join(', ')} } from '@exogee/graphweaver-scalars';`\n\t\t\t);\n\t\t}\n\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\timports.push(\n\t\t\t`import { ${this.enumImports.size > 0 ? [...this.enumImports].sort().join(', ') + ', ' : ''}${\n\t\t\t\tthis.meta.className\n\t\t\t} as Orm${this.meta.className} } from '../../entities';`\n\t\t);\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getTypescriptPropertyType(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\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\t//fallback to string if unknown\n\t\t\treturn 'string';\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.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}!: ${prop.type}[];\\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.primary) {\n\t\t\treturn `${padding}id!: ${this.getTypescriptPropertyType(prop)};`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getTypescriptPropertyType(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): string {\n\t\tthis.coreImports.add('registerEnumType');\n\t\tthis.enumImports.add(enumClassName);\n\t\treturn `registerEnumType(${enumClassName}, { name: ${this.quote(enumClassName)} });`;\n\t}\n\n\tprivate getGraphQLPropertyType(prop: EntityProperty): string {\n\t\tif (prop.primary) {\n\t\t\tthis.coreImports.add('ID');\n\t\t\treturn 'ID';\n\t\t}\n\n\t\tif (prop.type === 'Date') {\n\t\t\tthis.scalarImports.add('ISODateStringScalar');\n\t\t\treturn 'ISODateStringScalar';\n\t\t}\n\n\t\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\treturn 'String';\n\t\t}\n\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\tthis.scalarImports.add('GraphQLJSON');\n\t\t\treturn `GraphQLJSON`;\n\t\t}\n\n\t\tif (prop.type.includes('[]')) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif ([ReferenceType.MANY_TO_MANY, ReferenceType.ONE_TO_MANY].includes(prop.reference)) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif (prop.pivotTable) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1)}]`;\n\t\t}\n\n\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\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\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}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tdecorator = [decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)})\\n`;\n\t\t}\n\n\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)}, { ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\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\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(pluralize(pascalToCamelCaseString(this.meta.className)));\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.id = `(entity) => entity.${prop.name}?.id`;\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif ([ReferenceType.ONE_TO_ONE, ReferenceType.MANY_TO_ONE].includes(prop.reference)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${this.meta.className}>`;\n\t\t}\n\n\t\tif ([ReferenceType.ONE_TO_MANY, ReferenceType.MANY_TO_MANY].includes(prop.reference)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${prop.type}>`;\n\t\t}\n\n\t\tthis.coreImports.add('Field');\n\t\treturn '@Field';\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,kBAAqC;AAErC,uBAAyB;AACzB,mBAAiE;AACjE,uBAAsB;AAEf,MAAM,yBAAyB,0BAAS;AAAA,EAM9C,YACoB,MACA,gBACA,UAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AAJjB;AACA;AACA;AARpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,cAAc,oBAAI,IAAY;AAAA,EAQjD;AAAA,EAEA,cAAc;AACb,UAAM,cAAU,sCAAwB,KAAK,KAAK,SAAS;AAC3D,WAAO,kBAAkB;AAAA,EAC1B;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,kBAA4B,CAAC;AACnC,QAAI,YAAY;A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F,SAAK,cAAc,IAAI,KAAK,IAAI;AAChC,YAAQ,eAAe,KAAK,MAAM,KAAK,QAAQ;AAAA,EAChD;AAAA,EAEU,8BAA8B,SAAqB,MAAsB;AAClF,SAAK,cAAc,IAAI,KAAK,IAAI;AAChC,YAAQ,KAAK,sBAAsB,KAAK;AAAA,EACzC;AAAA,EAEU,iBAAiB,MAA8B;AACxD,QAAI,CAAC,0BAAc,YAAY,0BAAc,WAAW,EAAE,SAAS,KAAK,SAAS,GAAG;AACnF,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK,KAAK;AAAA,IACxC;AAEA,QAAI,CAAC,0BAAc,aAAa,0BAAc,YAAY,EAAE,SAAS,KAAK,SAAS,GAAG;AACrF,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK;AAAA,IACnC;AAEA,SAAK,YAAY,IAAI,OAAO;AAC5B,WAAO;AAAA,EACR;AACD;",
4
+ "sourcesContent": ["import type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceKind, Utils } from '@mikro-orm/core';\n\nimport { BaseFile } from './base-file';\nimport { pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';\nimport pluralize from 'pluralize';\n\nexport class SchemaEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly scalarImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\tprotected readonly enumImports = 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) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\tconst dirName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `backend/schema/${dirName}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'entity.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '\\n';\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\t// Add a summary field if we have a name or title attribute\n\t\t\tif (['name', 'title'].includes(prop.name.toLowerCase())) {\n\t\t\t\tthis.coreImports.add('SummaryField');\n\t\t\t\tclassBody += `\\t@SummaryField()\\n`;\n\t\t\t}\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));\n\t\t\t}\n\t\t});\n\n\t\tlet file = '';\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n\\n';\n\t\t}\n\n\t\tthis.coreImports.add('ObjectType');\n\t\tfile += `@ObjectType(${this.quote(this.meta.className)})\\n`;\n\n\t\tthis.coreImports.add('GraphQLEntity');\n\t\tfile += `export class ${this.meta.className} extends GraphQLEntity<Orm${this.meta.className}> {\\n`;\n\t\tfile += `\\tpublic dataEntity!: Orm${this.meta.className};`;\n\n\t\tfile += `${classBody}}\\n`;\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@exogee/graphweaver';`,\n\t\t];\n\n\t\tif (this.scalarImports.size > 0) {\n\t\t\timports.push(\n\t\t\t\t`import { ${[...this.scalarImports]\n\t\t\t\t\t.sort()\n\t\t\t\t\t.join(', ')} } from '@exogee/graphweaver-scalars';`\n\t\t\t);\n\t\t}\n\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\timports.push(\n\t\t\t`import { ${this.enumImports.size > 0 ? [...this.enumImports].sort().join(', ') + ', ' : ''}${\n\t\t\t\tthis.meta.className\n\t\t\t} as Orm${this.meta.className} } from '../../entities';`\n\t\t);\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getTypescriptPropertyType(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\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\t//fallback to string if unknown\n\t\t\treturn 'string';\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 ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}!: ${prop.type}[];\\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.primary) {\n\t\t\treturn `${padding}id!: ${this.getTypescriptPropertyType(prop)};`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getTypescriptPropertyType(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): string {\n\t\tthis.coreImports.add('registerEnumType');\n\t\tthis.enumImports.add(enumClassName);\n\t\treturn `registerEnumType(${enumClassName}, { name: ${this.quote(enumClassName)} });`;\n\t}\n\n\tprivate getGraphQLPropertyType(prop: EntityProperty): string {\n\t\tif (prop.primary) {\n\t\t\tthis.coreImports.add('ID');\n\t\t\treturn 'ID';\n\t\t}\n\n\t\tif (prop.type === 'Date') {\n\t\t\tthis.scalarImports.add('ISODateStringScalar');\n\t\t\treturn 'ISODateStringScalar';\n\t\t}\n\n\t\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\treturn 'String';\n\t\t}\n\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\tthis.scalarImports.add('GraphQLJSON');\n\t\t\treturn `GraphQLJSON`;\n\t\t}\n\n\t\tif (prop.type.includes('[]')) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif ([ReferenceKind.MANY_TO_MANY, ReferenceKind.ONE_TO_MANY].includes(prop.kind)) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif (prop.pivotTable) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1)}]`;\n\t\t}\n\n\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\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\n\t\tif (prop.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind !== ReferenceKind.SCALAR) {\n\t\t\tthis.getForeignKeyDecoratorOptions(options, prop);\n\t\t}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tdecorator = [decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)})\\n`;\n\t\t}\n\n\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)}, { ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\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\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(pluralize(pascalToCamelCaseString(this.meta.className)));\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.id = `(entity) => entity.${prop.name}?.id`;\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${this.meta.className}>`;\n\t\t}\n\n\t\tif ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${prop.type}>`;\n\t\t}\n\n\t\tthis.coreImports.add('Field');\n\t\treturn '@Field';\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,kBAAqC;AAErC,uBAAyB;AACzB,mBAAiE;AACjE,uBAAsB;AAEf,MAAM,yBAAyB,0BAAS;AAAA,EAM9C,YACoB,MACA,gBACA,UAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AAJjB;AACA;AACA;AARpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,cAAc,oBAAI,IAAY;AAAA,EAQjD;AAAA,EAEA,cAAc;AACb,UAAM,cAAU,sCAAwB,KAAK,KAAK,SAAS;AAC3D,WAAO,kBAAkB;AAAA,EAC1B;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;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;AAGA,UAAI,CAAC,QAAQ,OAAO,EAAE,SAAS,KAAK,KAAK,YAAY,CAAC,GAAG;AACxD,aAAK,YAAY,IAAI,cAAc;AACnC,qBAAa;AAAA;AAAA,MACd;AACA,mBAAa;AACb,mBAAa;AAEb,UAAI,MAAM,MAAM,SAAS,OAAO;AAAM,qBAAa;AAEnD,UAAI,KAAK,MAAM;AACd,cAAM,gB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,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK;AAAA,IACnC;AAEA,SAAK,YAAY,IAAI,OAAO;AAC5B,WAAO;AAAA,EACR;AACD;",
6
6
  "names": ["pluralize"]
7
7
  }
@@ -64,17 +64,17 @@ const generateBidirectionalRelations = (metadata) => {
64
64
  const inverseProp = inverseMeta?.props.find((p) => p.name === newProp.mappedBy);
65
65
  if (inverseProp)
66
66
  inverseProp.inversedBy = newProp.name;
67
- if (prop.reference === import_core.ReferenceType.MANY_TO_ONE) {
68
- const name = (0, import_utils.pascalToCamelCaseString)(meta.tableName);
67
+ if (prop.kind === import_core.ReferenceKind.MANY_TO_ONE) {
68
+ const name = (0, import_utils.pascalToCamelCaseString)(meta.className);
69
69
  newProp.name = (0, import_pluralize.default)(name);
70
- newProp.reference = import_core.ReferenceType.ONE_TO_MANY;
71
- } else if (prop.reference === import_core.ReferenceType.ONE_TO_ONE && !prop.mappedBy) {
72
- newProp.reference = import_core.ReferenceType.ONE_TO_ONE;
70
+ newProp.kind = import_core.ReferenceKind.ONE_TO_MANY;
71
+ } else if (prop.kind === import_core.ReferenceKind.ONE_TO_ONE && !prop.mappedBy) {
72
+ newProp.kind = import_core.ReferenceKind.ONE_TO_ONE;
73
73
  newProp.nullable = true;
74
- } else if (prop.reference === import_core.ReferenceType.MANY_TO_MANY && !prop.mappedBy) {
75
- const name = (0, import_utils.pascalToCamelCaseString)(meta.tableName);
74
+ } else if (prop.kind === import_core.ReferenceKind.MANY_TO_MANY && !prop.mappedBy) {
75
+ const name = (0, import_utils.pascalToCamelCaseString)(meta.className);
76
76
  newProp.name = (0, import_pluralize.default)(name);
77
- newProp.reference = import_core.ReferenceType.MANY_TO_MANY;
77
+ newProp.kind = import_core.ReferenceKind.MANY_TO_MANY;
78
78
  } else {
79
79
  continue;
80
80
  }
@@ -85,7 +85,7 @@ const generateBidirectionalRelations = (metadata) => {
85
85
  };
86
86
  const detectManyToManyRelations = (metadata, namingStrategy) => {
87
87
  for (const meta of metadata) {
88
- if (meta.compositePK && meta.primaryKeys.length === meta.relations.length && meta.relations.length === 2 && meta.relations.length === meta.props.length && meta.relations.every((prop) => prop.reference === import_core.ReferenceType.MANY_TO_ONE)) {
88
+ if (meta.compositePK && meta.primaryKeys.length === meta.relations.length && meta.relations.length === 2 && meta.relations.length === meta.props.length && meta.relations.every((prop) => prop.kind === import_core.ReferenceKind.MANY_TO_ONE)) {
89
89
  meta.pivotTable = true;
90
90
  const owner = metadata.find((m) => m.className === meta.relations[0].type);
91
91
  if (!owner)
@@ -93,7 +93,7 @@ const detectManyToManyRelations = (metadata, namingStrategy) => {
93
93
  const name = (0, import_utils.pascalToCamelCaseString)(meta.relations?.[1]?.type);
94
94
  owner.addProperty({
95
95
  name: (0, import_pluralize.default)(name),
96
- reference: import_core.ReferenceType.MANY_TO_MANY,
96
+ kind: import_core.ReferenceKind.MANY_TO_MANY,
97
97
  pivotTable: meta.tableName,
98
98
  type: meta.relations[1].type,
99
99
  joinColumns: meta.relations[0].fieldNames,
@@ -105,10 +105,10 @@ const detectManyToManyRelations = (metadata, namingStrategy) => {
105
105
  const generateIdentifiedReferences = (metadata) => {
106
106
  for (const meta of metadata.filter((m) => !m.pivotTable)) {
107
107
  for (const prop of meta.relations) {
108
- if ([import_core.ReferenceType.MANY_TO_ONE, import_core.ReferenceType.ONE_TO_ONE].includes(prop.reference)) {
108
+ if ([import_core.ReferenceKind.MANY_TO_ONE, import_core.ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
109
109
  const name = (0, import_utils.pascalToCamelCaseString)(prop.type);
110
110
  prop.name = import_pluralize.default.singular(name);
111
- prop.wrappedReference = true;
111
+ prop.ref = true;
112
112
  }
113
113
  }
114
114
  }
@@ -133,7 +133,7 @@ const convertSchemaToMetadata = async (schema, platform, namingStrategy) => {
133
133
  const helper = platform.getSchemaHelper();
134
134
  if (!helper)
135
135
  throw new Error("cannot connect to database");
136
- const metadata = schema.getTables().sort((a, b) => a.name.localeCompare(b.name)).map((table) => table.getEntityDeclaration(namingStrategy, helper));
136
+ const metadata = schema.getTables().sort((a, b) => a.name.localeCompare(b.name)).map((table) => table.getEntityDeclaration(namingStrategy, helper, "never"));
137
137
  if (metadata.length === 0) {
138
138
  throw new IntrospectionError(
139
139
  `Warning: No tables found, this database is empty.`,
@@ -148,9 +148,14 @@ const convertSchemaToMetadata = async (schema, platform, namingStrategy) => {
148
148
  return metadata;
149
149
  };
150
150
  const openConnection = async (type, options) => {
151
+ const PLATFORMS = {
152
+ mysql: { className: "MySqlDriver", module: () => require("@mikro-orm/mysql") },
153
+ postgresql: { className: "PostgreSqlDriver", module: () => require("@mikro-orm/postgresql") },
154
+ sqlite: { className: "SqliteDriver", module: () => require("@mikro-orm/sqlite") }
155
+ };
151
156
  await import_database.ConnectionManager.connect(CONNECTION_MANAGER_ID, {
152
157
  mikroOrmConfig: {
153
- type,
158
+ driver: PLATFORMS[type].module()[PLATFORMS[type].className],
154
159
  ...options.mikroOrmConfig
155
160
  }
156
161
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/introspection/generate.ts"],
4
- "sourcesContent": ["import { DatabaseSchema, AbstractSqlPlatform } from '@mikro-orm/knex';\nimport {\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tReferenceType,\n\tUtils,\n} from '@mikro-orm/core';\nimport pluralize from 'pluralize';\n\nimport { ConnectionManager, ConnectionOptions, DatabaseType } from '../database';\nimport {\n\tDataEntityFile,\n\tDataEntityIndexFile,\n\tDataSourceIndexFile,\n\tSchemaEntityFile,\n\tSchemaIndexFile,\n\tSchemaResolverFile,\n\tSchemaEntityIndexFile,\n\tDatabaseFile,\n} from './files';\nimport { pascalToCamelCaseString } from './utils';\n\nconst CONNECTION_MANAGER_ID = 'generate';\n\nexport class IntrospectionError extends Error {\n\tprotected type: string;\n\tconstructor(protected title = '', message = '') {\n\t\tsuper(message);\n\t\tthis.type = 'IntrospectionError';\n\t\tthis.title = title;\n\t\tthis.message = message;\n\t}\n}\n\nconst hasErrorMessage = (error: any): error is { message: string } => error.message;\n\nconst generateBidirectionalRelations = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif (!prop.name.includes('Inverse')) {\n\t\t\t\tconst targetMeta = metadata.find((m) => m.className === prop.type);\n\t\t\t\tconst newProp = {\n\t\t\t\t\tname: prop.name + 'Inverse',\n\t\t\t\t\ttype: meta.className,\n\t\t\t\t\tjoinColumns: prop.fieldNames,\n\t\t\t\t\treferencedTableName: meta.tableName,\n\t\t\t\t\treferencedColumnNames: Utils.flatten(\n\t\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t\t),\n\t\t\t\t\tmappedBy: prop.name,\n\t\t\t\t} as EntityProperty;\n\n\t\t\t\t// Add reference to the inverse entity\n\t\t\t\tconst inverseMeta = metadata.find((m) => m.className === meta.className);\n\t\t\t\tconst inverseProp = inverseMeta?.props.find((p) => p.name === newProp.mappedBy);\n\t\t\t\tif (inverseProp) inverseProp.inversedBy = newProp.name;\n\n\t\t\t\tif (prop.reference === ReferenceType.MANY_TO_ONE) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_MANY;\n\t\t\t\t} else if (prop.reference === ReferenceType.ONE_TO_ONE && !prop.mappedBy) {\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_ONE;\n\t\t\t\t\tnewProp.nullable = true;\n\t\t\t\t} else if (prop.reference === ReferenceType.MANY_TO_MANY && !prop.mappedBy) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.MANY_TO_MANY;\n\t\t\t\t} else {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttargetMeta?.addProperty(newProp);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[], namingStrategy: NamingStrategy) => {\n\tfor (const meta of metadata) {\n\t\tif (\n\t\t\tmeta.compositePK && // needs to have composite PK\n\t\t\tmeta.primaryKeys.length === meta.relations.length && // all relations are PKs\n\t\t\tmeta.relations.length === 2 && // there are exactly two relation properties\n\t\t\tmeta.relations.length === meta.props.length && // all properties are relations\n\t\t\tmeta.relations.every((prop) => prop.reference === ReferenceType.MANY_TO_ONE) // all relations are m:1\n\t\t) {\n\t\t\tmeta.pivotTable = true;\n\t\t\tconst owner = metadata.find((m) => m.className === meta.relations[0].type);\n\t\t\tif (!owner) throw new Error('No Owner');\n\t\t\tconst name = pascalToCamelCaseString(meta.relations?.[1]?.type);\n\t\t\towner.addProperty({\n\t\t\t\tname: pluralize(name),\n\t\t\t\treference: ReferenceType.MANY_TO_MANY,\n\t\t\t\tpivotTable: meta.tableName,\n\t\t\t\ttype: meta.relations[1].type,\n\t\t\t\tjoinColumns: meta.relations[0].fieldNames,\n\t\t\t\tinverseJoinColumns: meta.relations[1].fieldNames,\n\t\t\t} as EntityProperty);\n\t\t}\n\t}\n};\n\nconst generateIdentifiedReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif ([ReferenceType.MANY_TO_ONE, ReferenceType.ONE_TO_ONE].includes(prop.reference)) {\n\t\t\t\tconst name = pascalToCamelCaseString(prop.type);\n\t\t\t\tprop.name = pluralize.singular(name);\n\t\t\t\tprop.wrappedReference = true;\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst generateSingularTypeReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tmeta.className = pluralize.singular(meta.className);\n\t\tfor (const prop of meta.relations) {\n\t\t\tprop.type = pluralize.singular(prop.type);\n\t\t}\n\t}\n};\n\n// Convert properties like FirstName to firstName\nconst convertToCamelCasePropertyNames = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tconst props = Object.values(meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tprop.name = pascalToCamelCaseString(prop.name);\n\t\t});\n\t}\n};\n\nconst convertSchemaToMetadata = async (\n\tschema: DatabaseSchema,\n\tplatform: AbstractSqlPlatform,\n\tnamingStrategy: NamingStrategy\n) => {\n\tconst helper = platform.getSchemaHelper();\n\n\tif (!helper) throw new Error('cannot connect to database');\n\n\tconst metadata = schema\n\t\t.getTables()\n\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\t.map((table) => table.getEntityDeclaration(namingStrategy, helper));\n\n\tif (metadata.length === 0) {\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: No tables found, this database is empty.`,\n\t\t\t`Make sure you have tables in this database and then try again.`\n\t\t);\n\t}\n\n\tconvertToCamelCasePropertyNames(metadata);\n\tdetectManyToManyRelations(metadata, namingStrategy);\n\tgenerateIdentifiedReferences(metadata);\n\tgenerateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn metadata;\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\ttype,\n\t\t\t...options.mikroOrmConfig,\n\t\t},\n\t});\n};\n\nconst closeConnection = async () => {\n\tconsole.log('Closing database connection...');\n\tawait ConnectionManager.close(CONNECTION_MANAGER_ID);\n\tconsole.log('Database connection closed.');\n};\n\ntype File =\n\t| DataEntityFile\n\t| SchemaEntityFile\n\t| SchemaEntityIndexFile\n\t| SchemaIndexFile\n\t| SchemaResolverFile\n\t| DataEntityIndexFile\n\t| DataSourceIndexFile\n\t| DatabaseFile;\n\nexport const generate = async (databaseType: DatabaseType, options: ConnectionOptions) => {\n\ttry {\n\t\tawait openConnection(databaseType, options);\n\n\t\tconst database = ConnectionManager.database(CONNECTION_MANAGER_ID);\n\t\tif (!database)\n\t\t\tthrow new IntrospectionError(\n\t\t\t\t`Warning: Unable to connect to database.`,\n\t\t\t\t'Please check the connection settings and try again'\n\t\t\t);\n\n\t\tconst config = database.em.config;\n\t\tconst driver = database.em.getDriver();\n\t\tconst platform = driver.getPlatform();\n\t\tconst namingStrategy = config.getNamingStrategy();\n\t\tconst connection = driver.getConnection();\n\n\t\tconsole.log('Fetching database schema...');\n\t\tconst schema = await DatabaseSchema.create(connection, platform, config);\n\t\tconsole.log('Building metadata...');\n\t\tconst metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);\n\n\t\tconst source: File[] = [];\n\n\t\tconst summaryOfEntities: { name: string; entityFilePath: string; schemaFilePath: string }[] =\n\t\t\t[];\n\n\t\tfor (const meta of metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst dataEntityFile = new DataEntityFile(meta, namingStrategy, platform, databaseType);\n\t\t\t\tconst schemaEntityFile = new SchemaEntityFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaIndexFile = new SchemaEntityIndexFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaResolverFile = new SchemaResolverFile(meta, namingStrategy, platform);\n\t\t\t\tsource.push(dataEntityFile, schemaEntityFile, schemaIndexFile, schemaResolverFile);\n\t\t\t\tsummaryOfEntities.push({\n\t\t\t\t\tname: meta.className,\n\t\t\t\t\tentityFilePath: `${dataEntityFile.getBasePath()}${dataEntityFile.getBaseName()}`,\n\t\t\t\t\tschemaFilePath: `${schemaIndexFile.getBasePath()}: ${[\n\t\t\t\t\t\tschemaIndexFile.getBaseName(),\n\t\t\t\t\t\tschemaEntityFile.getBaseName(),\n\t\t\t\t\t\tschemaResolverFile.getBaseName(),\n\t\t\t\t\t].join(', ')}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Export all the entities from the data source directory\n\t\tsource.push(new DataEntityIndexFile(metadata, databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new DataSourceIndexFile(databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new SchemaIndexFile(metadata));\n\t\t// Export the database connection to its own file\n\t\tsource.push(new DatabaseFile(databaseType, options));\n\n\t\tconst files = source.map((file) => {\n\t\t\treturn {\n\t\t\t\tpath: file.getBasePath(),\n\t\t\t\tname: file.getBaseName(),\n\t\t\t\tcontents: file.generate(),\n\t\t\t\tneedOverwriteWarning: !![DatabaseFile, SchemaIndexFile].some((cls) => file instanceof cls),\n\t\t\t};\n\t\t});\n\n\t\tawait closeConnection();\n\n\t\tconsole.log('\\nImport Summary:');\n\t\tconsole.table(summaryOfEntities);\n\t\tconsole.log(\n\t\t\t`\\nImported ${summaryOfEntities.length} entities, creating the above files in your Graphweaver project. \\n`\n\t\t);\n\n\t\treturn files;\n\t} catch (err) {\n\t\tif (err instanceof IntrospectionError) throw err;\n\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: Unable to connect to database.`,\n\t\t\thasErrorMessage(err) ? err.message : 'Please check the connection settings and try again'\n\t\t);\n\t}\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBASO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YAAsB,QAAQ,IAAI,UAAU,IAAI;AAC/C,UAAM,OAAO;AADQ;AAErB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAAqC;AAC5E,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD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AAC,SAAS;AAClC,aAAO;AAAA,QACN,MAAM,KAAK,YAAY;AAAA,QACvB,MAAM,KAAK,YAAY;AAAA,QACvB,UAAU,KAAK,SAAS;AAAA,QACxB,sBAAsB,CAAC,CAAC,CAAC,2BAAc,4BAAe,EAAE,KAAK,CAAC,QAAQ,gBAAgB,GAAG;AAAA,MAC1F;AAAA,IACD,CAAC;AAED,UAAM,gBAAgB;AAEtB,YAAQ,IAAI,mBAAmB;AAC/B,YAAQ,MAAM,iBAAiB;AAC/B,YAAQ;AAAA,MACP;AAAA,WAAc,kBAAkB;AAAA;AAAA,IACjC;AAEA,WAAO;AAAA,EACR,SAAS,KAAP;AACD,QAAI,eAAe;AAAoB,YAAM;AAE7C,UAAM,IAAI;AAAA,MACT;AAAA,MACA,gBAAgB,GAAG,IAAI,IAAI,UAAU;AAAA,IACtC;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import { DatabaseSchema, AbstractSqlPlatform } from '@mikro-orm/knex';\nimport {\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tReferenceKind,\n\tUtils,\n} from '@mikro-orm/core';\nimport pluralize from 'pluralize';\n\nimport { ConnectionManager, ConnectionOptions, DatabaseType } from '../database';\nimport {\n\tDataEntityFile,\n\tDataEntityIndexFile,\n\tDataSourceIndexFile,\n\tSchemaEntityFile,\n\tSchemaIndexFile,\n\tSchemaResolverFile,\n\tSchemaEntityIndexFile,\n\tDatabaseFile,\n} from './files';\nimport { pascalToCamelCaseString } from './utils';\n\nconst CONNECTION_MANAGER_ID = 'generate';\n\nexport class IntrospectionError extends Error {\n\tprotected type: string;\n\tconstructor(protected title = '', message = '') {\n\t\tsuper(message);\n\t\tthis.type = 'IntrospectionError';\n\t\tthis.title = title;\n\t\tthis.message = message;\n\t}\n}\n\nconst hasErrorMessage = (error: any): error is { message: string } => error.message;\n\nconst generateBidirectionalRelations = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif (!prop.name.includes('Inverse')) {\n\t\t\t\tconst targetMeta = metadata.find((m) => m.className === prop.type);\n\t\t\t\tconst newProp = {\n\t\t\t\t\tname: prop.name + 'Inverse',\n\t\t\t\t\ttype: meta.className,\n\t\t\t\t\tjoinColumns: prop.fieldNames,\n\t\t\t\t\treferencedTableName: meta.tableName,\n\t\t\t\t\treferencedColumnNames: Utils.flatten(\n\t\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t\t),\n\t\t\t\t\tmappedBy: prop.name,\n\t\t\t\t} as EntityProperty;\n\n\t\t\t\t// Add reference to the inverse entity\n\t\t\t\tconst inverseMeta = metadata.find((m) => m.className === meta.className);\n\t\t\t\tconst inverseProp = inverseMeta?.props.find((p) => p.name === newProp.mappedBy);\n\t\t\t\tif (inverseProp) inverseProp.inversedBy = newProp.name;\n\n\t\t\t\tif (prop.kind === ReferenceKind.MANY_TO_ONE) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.className);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.kind = ReferenceKind.ONE_TO_MANY;\n\t\t\t\t} else if (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.mappedBy) {\n\t\t\t\t\tnewProp.kind = ReferenceKind.ONE_TO_ONE;\n\t\t\t\t\tnewProp.nullable = true;\n\t\t\t\t} else if (prop.kind === ReferenceKind.MANY_TO_MANY && !prop.mappedBy) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.className);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.kind = ReferenceKind.MANY_TO_MANY;\n\t\t\t\t} else {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttargetMeta?.addProperty(newProp);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[], namingStrategy: NamingStrategy) => {\n\tfor (const meta of metadata) {\n\t\tif (\n\t\t\tmeta.compositePK && // needs to have composite PK\n\t\t\tmeta.primaryKeys.length === meta.relations.length && // all relations are PKs\n\t\t\tmeta.relations.length === 2 && // there are exactly two relation properties\n\t\t\tmeta.relations.length === meta.props.length && // all properties are relations\n\t\t\tmeta.relations.every((prop) => prop.kind === ReferenceKind.MANY_TO_ONE) // all relations are m:1\n\t\t) {\n\t\t\tmeta.pivotTable = true;\n\t\t\tconst owner = metadata.find((m) => m.className === meta.relations[0].type);\n\t\t\tif (!owner) throw new Error('No Owner');\n\t\t\tconst name = pascalToCamelCaseString(meta.relations?.[1]?.type);\n\t\t\towner.addProperty({\n\t\t\t\tname: pluralize(name),\n\t\t\t\tkind: ReferenceKind.MANY_TO_MANY,\n\t\t\t\tpivotTable: meta.tableName,\n\t\t\t\ttype: meta.relations[1].type,\n\t\t\t\tjoinColumns: meta.relations[0].fieldNames,\n\t\t\t\tinverseJoinColumns: meta.relations[1].fieldNames,\n\t\t\t} as EntityProperty);\n\t\t}\n\t}\n};\n\nconst generateIdentifiedReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {\n\t\t\t\tconst name = pascalToCamelCaseString(prop.type);\n\t\t\t\tprop.name = pluralize.singular(name);\n\t\t\t\tprop.ref = true;\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst generateSingularTypeReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tmeta.className = pluralize.singular(meta.className);\n\t\tfor (const prop of meta.relations) {\n\t\t\tprop.type = pluralize.singular(prop.type);\n\t\t}\n\t}\n};\n\n// Convert properties like FirstName to firstName\nconst convertToCamelCasePropertyNames = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tconst props = Object.values(meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tprop.name = pascalToCamelCaseString(prop.name);\n\t\t});\n\t}\n};\n\nconst convertSchemaToMetadata = async (\n\tschema: DatabaseSchema,\n\tplatform: AbstractSqlPlatform,\n\tnamingStrategy: NamingStrategy\n) => {\n\tconst helper = platform.getSchemaHelper();\n\n\tif (!helper) throw new Error('cannot connect to database');\n\n\tconst metadata = schema\n\t\t.getTables()\n\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\t.map((table) => table.getEntityDeclaration(namingStrategy, helper, 'never'));\n\n\tif (metadata.length === 0) {\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: No tables found, this database is empty.`,\n\t\t\t`Make sure you have tables in this database and then try again.`\n\t\t);\n\t}\n\n\tconvertToCamelCasePropertyNames(metadata);\n\tdetectManyToManyRelations(metadata, namingStrategy);\n\tgenerateIdentifiedReferences(metadata);\n\tgenerateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn metadata;\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\tconst PLATFORMS = {\n\t\tmysql: { className: 'MySqlDriver', module: () => require('@mikro-orm/mysql') },\n\t\tpostgresql: { className: 'PostgreSqlDriver', module: () => require('@mikro-orm/postgresql') },\n\t\tsqlite: { className: 'SqliteDriver', module: () => require('@mikro-orm/sqlite') },\n\t};\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\tdriver: PLATFORMS[type].module()[PLATFORMS[type].className],\n\t\t\t...options.mikroOrmConfig,\n\t\t},\n\t});\n};\n\nconst closeConnection = async () => {\n\tconsole.log('Closing database connection...');\n\tawait ConnectionManager.close(CONNECTION_MANAGER_ID);\n\tconsole.log('Database connection closed.');\n};\n\ntype File =\n\t| DataEntityFile\n\t| SchemaEntityFile\n\t| SchemaEntityIndexFile\n\t| SchemaIndexFile\n\t| SchemaResolverFile\n\t| DataEntityIndexFile\n\t| DataSourceIndexFile\n\t| DatabaseFile;\n\nexport const generate = async (databaseType: DatabaseType, options: ConnectionOptions) => {\n\ttry {\n\t\tawait openConnection(databaseType, options);\n\n\t\tconst database = ConnectionManager.database(CONNECTION_MANAGER_ID);\n\t\tif (!database)\n\t\t\tthrow new IntrospectionError(\n\t\t\t\t`Warning: Unable to connect to database.`,\n\t\t\t\t'Please check the connection settings and try again'\n\t\t\t);\n\n\t\tconst config = database.em.config;\n\t\tconst driver = database.em.getDriver();\n\t\tconst platform = driver.getPlatform();\n\t\tconst namingStrategy = config.getNamingStrategy();\n\t\tconst connection = driver.getConnection();\n\n\t\tconsole.log('Fetching database schema...');\n\t\tconst schema = await DatabaseSchema.create(connection, platform, config);\n\t\tconsole.log('Building metadata...');\n\t\tconst metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);\n\n\t\tconst source: File[] = [];\n\n\t\tconst summaryOfEntities: { name: string; entityFilePath: string; schemaFilePath: string }[] =\n\t\t\t[];\n\n\t\tfor (const meta of metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst dataEntityFile = new DataEntityFile(meta, namingStrategy, platform, databaseType);\n\t\t\t\tconst schemaEntityFile = new SchemaEntityFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaIndexFile = new SchemaEntityIndexFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaResolverFile = new SchemaResolverFile(meta, namingStrategy, platform);\n\t\t\t\tsource.push(dataEntityFile, schemaEntityFile, schemaIndexFile, schemaResolverFile);\n\t\t\t\tsummaryOfEntities.push({\n\t\t\t\t\tname: meta.className,\n\t\t\t\t\tentityFilePath: `${dataEntityFile.getBasePath()}${dataEntityFile.getBaseName()}`,\n\t\t\t\t\tschemaFilePath: `${schemaIndexFile.getBasePath()}: ${[\n\t\t\t\t\t\tschemaIndexFile.getBaseName(),\n\t\t\t\t\t\tschemaEntityFile.getBaseName(),\n\t\t\t\t\t\tschemaResolverFile.getBaseName(),\n\t\t\t\t\t].join(', ')}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Export all the entities from the data source directory\n\t\tsource.push(new DataEntityIndexFile(metadata, databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new DataSourceIndexFile(databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new SchemaIndexFile(metadata));\n\t\t// Export the database connection to its own file\n\t\tsource.push(new DatabaseFile(databaseType, options));\n\n\t\tconst files = source.map((file) => {\n\t\t\treturn {\n\t\t\t\tpath: file.getBasePath(),\n\t\t\t\tname: file.getBaseName(),\n\t\t\t\tcontents: file.generate(),\n\t\t\t\tneedOverwriteWarning: !![DatabaseFile, SchemaIndexFile].some((cls) => file instanceof cls),\n\t\t\t};\n\t\t});\n\n\t\tawait closeConnection();\n\n\t\tconsole.log('\\nImport Summary:');\n\t\tconsole.table(summaryOfEntities);\n\t\tconsole.log(\n\t\t\t`\\nImported ${summaryOfEntities.length} entities, creating the above files in your Graphweaver project. \\n`\n\t\t);\n\n\t\treturn files;\n\t} catch (err) {\n\t\tif (err instanceof IntrospectionError) throw err;\n\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: Unable to connect to database.`,\n\t\t\thasErrorMessage(err) ? err.message : 'Please check the connection settings and try again'\n\t\t);\n\t}\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBASO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YAAsB,QAAQ,IAAI,UAAU,IAAI;AAC/C,UAAM,OAAO;AADQ;AAErB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAAqC;AAC5E,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D,gBAAgB,YAAY;AAAA,YAC5B,iBAAiB,YAAY;AAAA,YAC7B,mBAAmB,YAAY;AAAA,UAChC,EAAE,KAAK,IAAI;AAAA,QACZ,CAAC;AAAA,MACF;AAAA,IACD;AAGA,WAAO,KAAK,IAAI,iCAAoB,UAAU,YAAY,CAAC;AAE3D,WAAO,KAAK,IAAI,iCAAoB,YAAY,CAAC;AAEjD,WAAO,KAAK,IAAI,6BAAgB,QAAQ,CAAC;AAEzC,WAAO,KAAK,IAAI,0BAAa,cAAc,OAAO,CAAC;AAEnD,UAAM,QAAQ,OAAO,IAAI,CAAC,SAAS;AAClC,aAAO;AAAA,QACN,MAAM,KAAK,YAAY;AAAA,QACvB,MAAM,KAAK,YAAY;AAAA,QACvB,UAAU,KAAK,SAAS;AAAA,QACxB,sBAAsB,CAAC,CAAC,CAAC,2BAAc,4BAAe,EAAE,KAAK,CAAC,QAAQ,gBAAgB,GAAG;AAAA,MAC1F;AAAA,IACD,CAAC;AAED,UAAM,gBAAgB;AAEtB,YAAQ,IAAI,mBAAmB;AAC/B,YAAQ,MAAM,iBAAiB;AAC/B,YAAQ;AAAA,MACP;AAAA,WAAc,kBAAkB;AAAA;AAAA,IACjC;AAEA,WAAO;AAAA,EACR,SAAS,KAAP;AACD,QAAI,eAAe;AAAoB,YAAM;AAE7C,UAAM,IAAI;AAAA,MACT;AAAA,MACA,gBAAgB,GAAG,IAAI,IAAI,UAAU;AAAA,IACtC;AAAA,EACD;AACD;",
6
6
  "names": ["pluralize"]
7
7
  }
@@ -26,17 +26,11 @@ const connectionIds = /* @__PURE__ */ new Set();
26
26
  const connectToDatabase = (options) => {
27
27
  return {
28
28
  serverWillStart: async () => {
29
- if (Array.isArray(options)) {
30
- for (const option of options) {
31
- if (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {
32
- connectionIds.add(option.connectionManagerId);
33
- await import_database.ConnectionManager.connect(option.connectionManagerId, option);
34
- }
35
- }
36
- } else {
37
- if (options.connectionManagerId && !connectionIds.has(options.connectionManagerId)) {
38
- connectionIds.add(options.connectionManagerId);
39
- await import_database.ConnectionManager.connect(options.connectionManagerId, options);
29
+ const connections = Array.isArray(options) ? options : [options];
30
+ for (const option of connections) {
31
+ if (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {
32
+ connectionIds.add(option.connectionManagerId);
33
+ await import_database.ConnectionManager.connect(option.connectionManagerId, option);
40
34
  }
41
35
  }
42
36
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/plugins/connect-to-database.ts"],
4
- "sourcesContent": ["import { ApolloServerPlugin } from '@apollo/server';\nimport { ConnectionManager, ConnectionOptions } from '../database';\n\nconst connectionIds = new Set<string>();\n\nexport const connectToDatabase = (\n\toptions: ConnectionOptions[] | ConnectionOptions\n): ApolloServerPlugin => {\n\treturn {\n\t\tserverWillStart: async () => {\n\t\t\tif (Array.isArray(options)) {\n\t\t\t\tfor (const option of options) {\n\t\t\t\t\tif (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {\n\t\t\t\t\t\tconnectionIds.add(option.connectionManagerId);\n\t\t\t\t\t\tawait ConnectionManager.connect(option.connectionManagerId, option);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (options.connectionManagerId && !connectionIds.has(options.connectionManagerId)) {\n\t\t\t\t\tconnectionIds.add(options.connectionManagerId);\n\t\t\t\t\tawait ConnectionManager.connect(options.connectionManagerId, options);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqD;AAErD,MAAM,gBAAgB,oBAAI,IAAY;AAE/B,MAAM,oBAAoB,CAChC,YACwB;AACxB,SAAO;AAAA,IACN,iBAAiB,YAAY;AAC5B,UAAI,MAAM,QAAQ,OAAO,GAAG;AAC3B,mBAAW,UAAU,SAAS;AAC7B,cAAI,OAAO,uBAAuB,CAAC,cAAc,IAAI,OAAO,mBAAmB,GAAG;AACjF,0BAAc,IAAI,OAAO,mBAAmB;AAC5C,kBAAM,kCAAkB,QAAQ,OAAO,qBAAqB,MAAM;AAAA,UACnE;AAAA,QACD;AAAA,MACD,OAAO;AACN,YAAI,QAAQ,uBAAuB,CAAC,cAAc,IAAI,QAAQ,mBAAmB,GAAG;AACnF,wBAAc,IAAI,QAAQ,mBAAmB;AAC7C,gBAAM,kCAAkB,QAAQ,QAAQ,qBAAqB,OAAO;AAAA,QACrE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import { ApolloServerPlugin } from '@apollo/server';\nimport { ConnectionManager, ConnectionOptions } from '../database';\n\nconst connectionIds = new Set<string>();\n\nexport const connectToDatabase = (\n\toptions: ConnectionOptions[] | ConnectionOptions\n): ApolloServerPlugin => {\n\treturn {\n\t\tserverWillStart: async () => {\n\t\t\tconst connections = Array.isArray(options) ? options : [options];\n\t\t\tfor (const option of connections) {\n\t\t\t\tif (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {\n\t\t\t\t\tconnectionIds.add(option.connectionManagerId);\n\t\t\t\t\tawait ConnectionManager.connect(option.connectionManagerId, option);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqD;AAErD,MAAM,gBAAgB,oBAAI,IAAY;AAE/B,MAAM,oBAAoB,CAChC,YACwB;AACxB,SAAO;AAAA,IACN,iBAAiB,YAAY;AAC5B,YAAM,cAAc,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAC/D,iBAAW,UAAU,aAAa;AACjC,YAAI,OAAO,uBAAuB,CAAC,cAAc,IAAI,OAAO,mBAAmB,GAAG;AACjF,wBAAc,IAAI,OAAO,mBAAmB;AAC5C,gBAAM,kCAAkB,QAAQ,OAAO,qBAAqB,MAAM;AAAA,QACnE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -16,15 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __decorateClass = (decorators, target, key, kind) => {
20
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
- if (decorator = decorators[i])
23
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
- if (kind && result)
25
- __defProp(target, key, result);
26
- return result;
27
- };
28
19
  var change_tracker_exports = {};
29
20
  __export(change_tracker_exports, {
30
21
  ChangeTracker: () => ChangeTracker
@@ -35,7 +26,7 @@ var import_entities = require("../entities");
35
26
  var import_authentication_context = require("./authentication-context");
36
27
  var import_tracked_entity = require("./tracked-entity");
37
28
  var import_untracked_property = require("./untracked-property");
38
- let ChangeTracker = class {
29
+ class ChangeTracker {
39
30
  async afterFlush({ uow, em }) {
40
31
  const changesets = uow.getChangeSets().filter((cs) => cs.entity instanceof import_tracked_entity.TrackedEntity);
41
32
  const trx = em.getTransactionContext();
@@ -67,10 +58,7 @@ let ChangeTracker = class {
67
58
  }
68
59
  }
69
60
  }
70
- };
71
- ChangeTracker = __decorateClass([
72
- (0, import_core.Subscriber)()
73
- ], ChangeTracker);
61
+ }
74
62
  const dataForChangeSet = (cs) => {
75
63
  if (cs.payload && cs.type !== import_core.ChangeSetType.DELETE) {
76
64
  const entries = Object.entries(cs.payload).filter(([k]) => !(0, import_untracked_property.isUntrackedProperty)(cs.entity, k)).map(([k]) => processPayloadEntry(k, cs.type, cs.entity, cs.originalEntity));