@exogee/graphweaver-mikroorm 2.17.2 → 2.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,9 +6,10 @@ export declare class DataEntityFile extends BaseFile {
6
6
  protected readonly namingStrategy: NamingStrategy;
7
7
  protected readonly platform: Platform;
8
8
  protected readonly databaseType: DatabaseType;
9
+ protected readonly entityLookup: Map<string, EntityMetadata<any>>;
9
10
  protected readonly coreImports: Set<string>;
10
11
  protected readonly entityImports: Set<string>;
11
- constructor(meta: EntityMetadata, namingStrategy: NamingStrategy, platform: Platform, databaseType: DatabaseType);
12
+ constructor(meta: EntityMetadata, namingStrategy: NamingStrategy, platform: Platform, databaseType: DatabaseType, entityLookup: Map<string, EntityMetadata<any>>);
12
13
  getBasePath(): string;
13
14
  getBaseName(): string;
14
15
  generate(): string;
@@ -24,13 +24,15 @@ module.exports = __toCommonJS(data_entity_file_exports);
24
24
  var import_core = require("@mikro-orm/core");
25
25
  var import_utils = require("../utils");
26
26
  var import_base_file = require("./base-file");
27
+ var import_generate = require("../generate");
27
28
  class DataEntityFile extends import_base_file.BaseFile {
28
- constructor(meta, namingStrategy, platform, databaseType) {
29
+ constructor(meta, namingStrategy, platform, databaseType, entityLookup) {
29
30
  super(meta, namingStrategy, platform);
30
31
  this.meta = meta;
31
32
  this.namingStrategy = namingStrategy;
32
33
  this.platform = platform;
33
34
  this.databaseType = databaseType;
35
+ this.entityLookup = entityLookup;
34
36
  this.coreImports = /* @__PURE__ */ new Set();
35
37
  this.entityImports = /* @__PURE__ */ new Set();
36
38
  }
@@ -44,8 +46,17 @@ class DataEntityFile extends import_base_file.BaseFile {
44
46
  generate() {
45
47
  const enumDefinitions = [];
46
48
  let classBody = "";
49
+ const generatedPropertyNames = /* @__PURE__ */ new Set();
47
50
  const props = Object.values(this.meta.properties);
48
51
  props.forEach((prop) => {
52
+ if (generatedPropertyNames.has(prop.name)) {
53
+ return;
54
+ }
55
+ const relatedEntity = this.entityLookup.get(prop.type);
56
+ if (relatedEntity && !(0, import_generate.isEntityWithSinglePrimaryKey)(relatedEntity)) {
57
+ return;
58
+ }
59
+ generatedPropertyNames.add(prop.name);
49
60
  const decorator = this.getPropertyDecorator(prop);
50
61
  const definition = this.getPropertyDefinition(prop);
51
62
  if (!classBody.endsWith("\n\n")) {
@@ -129,7 +140,7 @@ ${file}`;
129
140
  return `${padding}${file} = ${prop.runtimeType}.${(0, import_utils.identifierForEnumValue)(prop.default)};
130
141
  `;
131
142
  }
132
- return `${padding}${prop.name} = ${prop.default};
143
+ return `${padding}${prop.name} = ${JSON.stringify(prop.default)};
133
144
  `;
134
145
  }
135
146
  getEnumClassDefinition(enumClassName, enumValues) {
@@ -226,9 +237,9 @@ ${file}`;
226
237
  if ([`''`, ""].includes(prop.default)) {
227
238
  options.default = `''`;
228
239
  } else if (prop.defaultRaw === this.quote(prop.default)) {
229
- options.default = this.quote(prop.default);
240
+ options.default = JSON.stringify(this.quote(prop.default)).slice(1, -1);
230
241
  } else {
231
- options.defaultRaw = `\`${prop.default}\``;
242
+ options.defaultRaw = `\`${JSON.stringify(prop.default).slice(1, -1)}\``;
232
243
  }
233
244
  }
234
245
  getScalarPropertyDecoratorOptions(options, prop) {
@@ -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 { BigIntType, ReferenceKind, UnknownType, Utils } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\nimport { identifierForEnumValue, pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\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];\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} {`;\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 ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\n\t\t}\n\n\t\tconst columnType = prop.columnTypes?.[0]?.toLowerCase();\n\n\t\tif (['jsonb', 'json', 'any'].includes(columnType)) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\t// Mikro doesn't infer column types for some columns very well. We can augment.\n\t\tif (prop.type === 'unknown') {\n\t\t\tif (columnType?.startsWith('nvarchar(') || columnType?.startsWith('varchar(')) {\n\t\t\t\treturn 'string';\n\t\t\t}\n\t\t}\n\n\t\tif (prop.type === 'bigint') {\n\t\t\treturn 'string';\n\t\t}\n\n\t\treturn prop.runtimeType;\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\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.runtimeType}.${identifierForEnumValue(prop.default)};\\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}${identifierForEnumValue(enumValue)} = '${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.runtimeType}`;\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\t// Special case for when prop.type is BigIntType\n\t\t\tif (mappedType1 instanceof BigIntType) {\n\t\t\t\tthis.coreImports.add('BigIntType');\n\t\t\t\toptions.type = \"new BigIntType('string')\";\n\t\t\t} else {\n\t\t\t\toptions.type = this.quote(prop.type);\n\t\t\t}\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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,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;",
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 { BigIntType, ReferenceKind, UnknownType, Utils } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\nimport { identifierForEnumValue, pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\nimport { isEntityWithSinglePrimaryKey } from '../generate';\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\tprotected readonly entityLookup: Map<string, EntityMetadata<any>>\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 generatedPropertyNames = new Set<string>();\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tif (generatedPropertyNames.has(prop.name)) {\n\t\t\t\t// We just gobble this property. It's a duplicate, but the Schema Entity File will complain about it,\n\t\t\t\t// and we can leave that other file as the source of truth for moaning.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We're going to just skip any relationships to entities that don't have a single primary key.\n\t\t\t// This is a limitation of the current implementation, but we'll fix it in the future.\n\t\t\tconst relatedEntity = this.entityLookup.get(prop.type);\n\t\t\tif (relatedEntity && !isEntityWithSinglePrimaryKey(relatedEntity)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tgeneratedPropertyNames.add(prop.name);\n\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];\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} {`;\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 ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\n\t\t}\n\n\t\tconst columnType = prop.columnTypes?.[0]?.toLowerCase();\n\n\t\tif (['jsonb', 'json', 'any'].includes(columnType)) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\t// Mikro doesn't infer column types for some columns very well. We can augment.\n\t\tif (prop.type === 'unknown') {\n\t\t\tif (columnType?.startsWith('nvarchar(') || columnType?.startsWith('varchar(')) {\n\t\t\t\treturn 'string';\n\t\t\t}\n\t\t}\n\n\t\tif (prop.type === 'bigint') {\n\t\t\treturn 'string';\n\t\t}\n\n\t\treturn prop.runtimeType;\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\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.runtimeType}.${identifierForEnumValue(prop.default)};\\n`;\n\t\t}\n\n\t\t// The JSON.stringify here is for escaping things that can break JS if unescaped.\n\t\treturn `${padding}${prop.name} = ${JSON.stringify(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}${identifierForEnumValue(enumValue)} = '${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.runtimeType}`;\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 = JSON.stringify(this.quote(prop.default)).slice(1, -1);\n\t\t} else {\n\t\t\toptions.defaultRaw = `\\`${JSON.stringify(prop.default).slice(1, -1)}\\``;\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\t// Special case for when prop.type is BigIntType\n\t\t\tif (mappedType1 instanceof BigIntType) {\n\t\t\t\tthis.coreImports.add('BigIntType');\n\t\t\t\toptions.type = \"new BigIntType('string')\";\n\t\t\t} else {\n\t\t\t\toptions.type = this.quote(prop.type);\n\t\t\t}\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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,WAAW,KAAK,MAAM,KAAK,QAAQ;AAAA,EAC5C;AAAA,EAEU,8BAA8B,SAAqB,MAAsB;AAClF,SAAK,cAAc,IAAI,KAAK,IAAI;AAChC,YAAQ,SAAS,SAAS,KAAK,IAAI;AAEnC,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,CAAC,MACjB,KAAK,eAAe,kBAAkB,KAAK,MAAM,KAAK,sBAAsB,CAAC,CAAC,GAC7E;AACD,cAAQ,YAAY,KAAK,MAAM,KAAK,WAAW,CAAC,CAAC;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
  }
@@ -21,6 +21,8 @@ __export(data_entity_index_file_exports, {
21
21
  DataEntityIndexFile: () => DataEntityIndexFile
22
22
  });
23
23
  module.exports = __toCommonJS(data_entity_index_file_exports);
24
+ var import_generate = require("../generate");
25
+ var import_utils = require("../utils");
24
26
  class DataEntityIndexFile {
25
27
  constructor(metadata, databaseType) {
26
28
  this.metadata = metadata;
@@ -38,8 +40,8 @@ class DataEntityIndexFile {
38
40
  const imports = [];
39
41
  const exports2 = [];
40
42
  for (const meta of this.metadata) {
41
- if (!meta.pivotTable) {
42
- const filename = meta.className.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase();
43
+ if (!meta.pivotTable && (0, import_generate.isEntityWithSinglePrimaryKey)(meta)) {
44
+ const filename = (0, import_utils.pascalToKebabCaseString)(meta.className);
43
45
  exports2.push(`export * from './${filename}';`);
44
46
  imports.push(`import { ${meta.className} } from './${filename}';`);
45
47
  file += `${padding}${meta.className},
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/introspection/files/data-entity-index-file.ts"],
4
- "sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\n\nexport class DataEntityIndexFile {\n\tconstructor(\n\t\tprotected readonly metadata: EntityMetadata<any>[],\n\t\tprotected readonly databaseType: DatabaseType\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tlet file = 'export const entities = [\\n';\n\t\tconst padding = '\\t';\n\t\tconst imports: string[] = [];\n\t\tconst exports: string[] = [];\n\n\t\tfor (const meta of this.metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst filename = meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n\t\t\t\texports.push(`export * from './${filename}';`);\n\t\t\t\timports.push(`import { ${meta.className} } from './${filename}';`);\n\t\t\t\tfile += `${padding}${meta.className},\\n`;\n\t\t\t}\n\t\t}\n\n\t\tfile += '];\\n';\n\n\t\treturn `${imports.join('\\n')}\\n\\n${exports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,oBAAoB;AAAA,EAChC,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO,oBAAoB,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,QAAI,OAAO;AACX,UAAM,UAAU;AAChB,UAAM,UAAoB,CAAC;AAC3B,UAAMA,WAAoB,CAAC;AAE3B,eAAW,QAAQ,KAAK,UAAU;AACjC,UAAI,CAAC,KAAK,YAAY;AACrB,cAAM,WAAW,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACnF,QAAAA,SAAQ,KAAK,oBAAoB,QAAQ,IAAI;AAC7C,gBAAQ,KAAK,YAAY,KAAK,SAAS,cAAc,QAAQ,IAAI;AACjE,gBAAQ,GAAG,OAAO,GAAG,KAAK,SAAS;AAAA;AAAA,MACpC;AAAA,IACD;AAEA,YAAQ;AAER,WAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAOA,SAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAO,IAAI;AAAA,EACjE;AACD;",
4
+ "sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\nimport { isEntityWithSinglePrimaryKey } from '../generate';\nimport { pascalToKebabCaseString } from '../utils';\n\nexport class DataEntityIndexFile {\n\tconstructor(\n\t\tprotected readonly metadata: EntityMetadata<any>[],\n\t\tprotected readonly databaseType: DatabaseType\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tlet file = 'export const entities = [\\n';\n\t\tconst padding = '\\t';\n\t\tconst imports: string[] = [];\n\t\tconst exports: string[] = [];\n\n\t\tfor (const meta of this.metadata) {\n\t\t\tif (!meta.pivotTable && isEntityWithSinglePrimaryKey(meta)) {\n\t\t\t\tconst filename = pascalToKebabCaseString(meta.className);\n\t\t\t\texports.push(`export * from './${filename}';`);\n\t\t\t\timports.push(`import { ${meta.className} } from './${filename}';`);\n\t\t\t\tfile += `${padding}${meta.className},\\n`;\n\t\t\t}\n\t\t}\n\n\t\tfile += '];\\n';\n\n\t\treturn `${imports.join('\\n')}\\n\\n${exports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA6C;AAC7C,mBAAwC;AAEjC,MAAM,oBAAoB;AAAA,EAChC,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO,oBAAoB,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,QAAI,OAAO;AACX,UAAM,UAAU;AAChB,UAAM,UAAoB,CAAC;AAC3B,UAAMA,WAAoB,CAAC;AAE3B,eAAW,QAAQ,KAAK,UAAU;AACjC,UAAI,CAAC,KAAK,kBAAc,8CAA6B,IAAI,GAAG;AAC3D,cAAM,eAAW,sCAAwB,KAAK,SAAS;AACvD,QAAAA,SAAQ,KAAK,oBAAoB,QAAQ,IAAI;AAC7C,gBAAQ,KAAK,YAAY,KAAK,SAAS,cAAc,QAAQ,IAAI;AACjE,gBAAQ,GAAG,OAAO,GAAG,KAAK,SAAS;AAAA;AAAA,MACpC;AAAA,IACD;AAEA,YAAQ;AAER,WAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAOA,SAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAO,IAAI;AAAA,EACjE;AACD;",
6
6
  "names": ["exports"]
7
7
  }
@@ -11,6 +11,7 @@ export declare class SchemaEntityFile extends BaseFile {
11
11
  protected readonly scalarImports: Set<string>;
12
12
  protected readonly entityImports: Set<string>;
13
13
  protected readonly enumImports: Set<string>;
14
+ readonly errors: string[];
14
15
  constructor(meta: EntityMetadata, namingStrategy: NamingStrategy, platform: Platform, databaseType: DatabaseType, entityLookup: Map<string, EntityMetadata<any>>);
15
16
  getBasePath(): string;
16
17
  getBaseName(): string;
@@ -35,6 +35,7 @@ var import_core = require("@mikro-orm/core");
35
35
  var import_pluralize = __toESM(require("pluralize"));
36
36
  var import_utils = require("../utils");
37
37
  var import_base_file = require("./base-file");
38
+ var import_generate = require("../generate");
38
39
  const friendlyNameForDatabaseType = (type) => {
39
40
  if (type === "mssql") return "SQL Server";
40
41
  if (type === "mysql") return "MySQL";
@@ -54,6 +55,7 @@ class SchemaEntityFile extends import_base_file.BaseFile {
54
55
  this.scalarImports = /* @__PURE__ */ new Set();
55
56
  this.entityImports = /* @__PURE__ */ new Set();
56
57
  this.enumImports = /* @__PURE__ */ new Set();
58
+ this.errors = [];
57
59
  }
58
60
  getBasePath() {
59
61
  return `backend/schema/`;
@@ -65,8 +67,25 @@ class SchemaEntityFile extends import_base_file.BaseFile {
65
67
  generate() {
66
68
  const enumDefinitions = [];
67
69
  let classBody = "";
70
+ const generatedPropertyNames = /* @__PURE__ */ new Set();
68
71
  const props = Object.values(this.meta.properties);
69
72
  props.forEach((prop) => {
73
+ const relatedEntity = this.entityLookup.get(prop.type);
74
+ if (relatedEntity) {
75
+ if (!(0, import_generate.isEntityWithSinglePrimaryKey)(relatedEntity)) {
76
+ this.errors.push(
77
+ ` - Warning: Composite primary keys are not supported. ${this.meta.className} entity references ${prop.type} entity with composite primary key.`
78
+ );
79
+ return;
80
+ }
81
+ }
82
+ if (generatedPropertyNames.has(prop.name)) {
83
+ this.errors.push(
84
+ ` - Warning: Property ${prop.name} on ${this.meta.className} entity is not unique. Additional instances of this property were ignored.`
85
+ );
86
+ return;
87
+ }
88
+ generatedPropertyNames.add(prop.name);
70
89
  const decorator = this.getPropertyDecorator(prop);
71
90
  const definition = this.getPropertyDefinition(prop);
72
91
  if (classBody && !classBody.endsWith("\n\n")) {
@@ -90,9 +109,17 @@ class SchemaEntityFile extends import_base_file.BaseFile {
90
109
  }
91
110
  this.coreImports.add("Entity");
92
111
  file += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {
93
- provider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}' }),
112
+ provider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}'})`;
113
+ if (props.length === 1 && props[0].primary) {
114
+ file += `,
115
+ apiOptions: { clientGeneratedPrimaryKeys: true },
94
116
  })
95
117
  `;
118
+ } else {
119
+ file += `
120
+ })
121
+ `;
122
+ }
96
123
  file += `export class ${this.meta.className} {
97
124
  `;
98
125
  file += `${classBody}}
@@ -183,6 +210,10 @@ ${file}`;
183
210
  this.scalarImports.add("GraphQLBigInt");
184
211
  return "GraphQLBigInt";
185
212
  }
213
+ if (prop.runtimeType === "Buffer") {
214
+ this.scalarImports.add("GraphQLByte");
215
+ return "GraphQLByte";
216
+ }
186
217
  if (["jsonb", "json", "any"].includes(prop.columnTypes?.[0])) {
187
218
  this.scalarImports.add("GraphQLJSON");
188
219
  return `GraphQLJSON`;
@@ -231,6 +262,7 @@ ${file}`;
231
262
  options.nullable = true;
232
263
  }
233
264
  if (prop.primary) {
265
+ console.log("prop is primary: ", prop);
234
266
  options.primaryKeyField = true;
235
267
  }
236
268
  if (prop.name === "name") {
@@ -255,7 +287,7 @@ ${file}`;
255
287
  `Internal Error: Related entity ${prop.type} should exist but could not be found in the entity lookup.`
256
288
  );
257
289
  }
258
- if (relatedEntity.primaryKeys.length !== 1) {
290
+ if (!(0, import_generate.isEntityWithSinglePrimaryKey)(relatedEntity)) {
259
291
  throw new Error(`Composite primary keys are not supported.`);
260
292
  }
261
293
  const [primaryKey] = relatedEntity.getPrimaryProps();
@@ -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 { ReferenceKind, Utils } from '@mikro-orm/core';\n\nimport pluralize from 'pluralize';\nimport { identifierForEnumValue, pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\nimport { DatabaseType } from '../../database';\n\nconst friendlyNameForDatabaseType = (type: DatabaseType) => {\n\tif (type === 'mssql') return 'SQL Server';\n\tif (type === 'mysql') return 'MySQL';\n\tif (type === 'postgresql') return 'PostgreSQL';\n\tif (type === 'sqlite') return 'SQLite';\n\n\tthrow new Error('Unimplemented database type: ' + type);\n};\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\tprotected readonly databaseType: DatabaseType,\n\t\tprotected readonly entityLookup: Map<string, EntityMetadata<any>>\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\treturn `backend/schema/`;\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 && !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));\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('Entity');\n\t\tfile += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {\\n\\tprovider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}' }),\\n})\\n`;\n\t\tfile += `export class ${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\timports.push(`import { MikroBackendProvider } from '@exogee/graphweaver-mikroorm';`);\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\t`import { connection } from '../database';`\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 ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\n\t\t}\n\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\tif (prop.type === 'bigint') {\n\t\t\treturn 'string';\n\t\t}\n\n\t\treturn prop.runtimeType;\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\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.runtimeType}.${identifierForEnumValue(prop.default)};\\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('graphweaverMetadata');\n\t\tthis.enumImports.add(enumClassName);\n\t\treturn `graphweaverMetadata.collectEnumInformation({ target: ${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.runtimeType === '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 'DateScalar';\n\t\t}\n\n\t\tif (prop.runtimeType === 'unknown') {\n\t\t\treturn 'String';\n\t\t}\n\n\t\tif (prop.runtimeType === 'bigint') {\n\t\t\tthis.scalarImports.add('GraphQLBigInt');\n\t\t\treturn 'GraphQLBigInt';\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.runtimeType?.includes('[]')) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\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\tconst lastChanceType = prop.runtimeType ?? prop.type;\n\n\t\tif (!lastChanceType) {\n\t\t\tconsole.error(`Property is malformed, it has no type or runtimeType:`, prop);\n\t\t\tthrow new Error(`Property ${prop.name} on ${prop.entity} entity has no type or runtimeType.`);\n\t\t}\n\n\t\treturn lastChanceType.charAt(0).toUpperCase() + lastChanceType.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}: ${JSON.stringify(val).replaceAll('\"', '')}`)\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\n\t\tif (prop.primary) {\n\t\t\toptions.primaryKeyField = true;\n\t\t}\n\n\t\t// If there's a property called 'name' it should be the summary field. If not, and there's a field called 'title'\n\t\t// then it should be the summary field.\n\t\tif (prop.name === 'name') {\n\t\t\toptions.adminUIOptions = { summaryField: true };\n\t\t} else if (prop.name === 'title' && !this.meta.props.find((prop) => prop.name === 'name')) {\n\t\t\toptions.adminUIOptions = { summaryField: 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\n\t\tconst relatedEntity = this.entityLookup.get(prop.type);\n\t\tif (!relatedEntity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Internal Error: Related entity ${prop.type} should exist but could not be found in the entity lookup.`\n\t\t\t);\n\t\t}\n\t\tif (relatedEntity.primaryKeys.length !== 1) {\n\t\t\tthrow new Error(`Composite primary keys are not supported.`);\n\t\t}\n\t\tconst [primaryKey] = relatedEntity.getPrimaryProps();\n\n\t\toptions.id = `(entity) => entity.${prop.name}?.${primaryKey.name}`;\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,uBAAsB;AACtB,mBAAyF;AACzF,uBAAyB;AAGzB,MAAM,8BAA8B,CAAC,SAAuB;AAC3D,MAAI,SAAS,QAAS,QAAO;AAC7B,MAAI,SAAS,QAAS,QAAO;AAC7B,MAAI,SAAS,aAAc,QAAO;AAClC,MAAI,SAAS,SAAU,QAAO;AAE9B,QAAM,IAAI,MAAM,kCAAkC,IAAI;AACvD;AAEO,MAAM,yBAAyB,0BAA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{\n\tDictionary,\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceKind, Utils } from '@mikro-orm/core';\nimport pluralize from 'pluralize';\nimport { identifierForEnumValue, pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\nimport { DatabaseType } from '../../database';\nimport { isEntityWithSinglePrimaryKey } from '../generate';\n\nconst friendlyNameForDatabaseType = (type: DatabaseType) => {\n\tif (type === 'mssql') return 'SQL Server';\n\tif (type === 'mysql') return 'MySQL';\n\tif (type === 'postgresql') return 'PostgreSQL';\n\tif (type === 'sqlite') return 'SQLite';\n\n\tthrow new Error('Unimplemented database type: ' + type);\n};\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\tpublic readonly errors: 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\tprotected readonly entityLookup: Map<string, EntityMetadata<any>>\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\treturn `backend/schema/`;\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 generatedPropertyNames = new Set<string>();\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tconst relatedEntity = this.entityLookup.get(prop.type);\n\t\t\tif (relatedEntity) {\n\t\t\t\t// These are not supported yet, just skip them.\n\t\t\t\tif (!isEntityWithSinglePrimaryKey(relatedEntity)) {\n\t\t\t\t\tthis.errors.push(\n\t\t\t\t\t\t` - Warning: Composite primary keys are not supported. ${this.meta.className} entity references ${prop.type} entity with composite primary key.`\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (generatedPropertyNames.has(prop.name)) {\n\t\t\t\tthis.errors.push(\n\t\t\t\t\t` - Warning: Property ${prop.name} on ${this.meta.className} entity is not unique. Additional instances of this property were ignored.`\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tgeneratedPropertyNames.add(prop.name);\n\n\t\t\tconst decorator = this.getPropertyDecorator(prop);\n\t\t\tconst definition = this.getPropertyDefinition(prop);\n\n\t\t\tif (classBody && !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));\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('Entity');\n\n\t\tfile += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {\\n\\tprovider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}'})`;\n\n\t\tif (props.length === 1 && props[0].primary) {\n\t\t\t// Special case. If there's a single primary key field in this entity, right now that requires that it's a client side generated primary key.\n\t\t\t// There's no reason this has to be the case, but it's a current limitation, so we should generate a working project for them.\n\t\t\t// We should be able to remove this in the future and allow users to use it both ways.\n\t\t\tfile += `,\\n\\tapiOptions: { clientGeneratedPrimaryKeys: true },\\n})\\n`;\n\t\t} else {\n\t\t\tfile += `\\n})\\n`;\n\t\t}\n\n\t\tfile += `export class ${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\timports.push(`import { MikroBackendProvider } from '@exogee/graphweaver-mikroorm';`);\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\t`import { connection } from '../database';`\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 ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\n\t\t}\n\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\tif (prop.type === 'bigint') {\n\t\t\treturn 'string';\n\t\t}\n\n\t\treturn prop.runtimeType;\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\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.runtimeType}.${identifierForEnumValue(prop.default)};\\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('graphweaverMetadata');\n\t\tthis.enumImports.add(enumClassName);\n\t\treturn `graphweaverMetadata.collectEnumInformation({ target: ${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.runtimeType === '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 'DateScalar';\n\t\t}\n\n\t\tif (prop.runtimeType === 'unknown') {\n\t\t\treturn 'String';\n\t\t}\n\n\t\tif (prop.runtimeType === 'bigint') {\n\t\t\tthis.scalarImports.add('GraphQLBigInt');\n\t\t\treturn 'GraphQLBigInt';\n\t\t}\n\n\t\tif (prop.runtimeType === 'Buffer') {\n\t\t\tthis.scalarImports.add('GraphQLByte');\n\t\t\treturn 'GraphQLByte';\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.runtimeType?.includes('[]')) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {\n\t\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\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\tconst lastChanceType = prop.runtimeType ?? prop.type;\n\n\t\tif (!lastChanceType) {\n\t\t\tconsole.error(`Property is malformed, it has no type or runtimeType:`, prop);\n\t\t\tthrow new Error(`Property ${prop.name} on ${prop.entity} entity has no type or runtimeType.`);\n\t\t}\n\n\t\treturn lastChanceType.charAt(0).toUpperCase() + lastChanceType.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}: ${JSON.stringify(val).replaceAll('\"', '')}`)\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\n\t\tif (prop.primary) {\n\t\t\tconsole.log('prop is primary: ', prop);\n\t\t\toptions.primaryKeyField = true;\n\t\t}\n\n\t\t// If there's a property called 'name' it should be the summary field. If not, and there's a field called 'title'\n\t\t// then it should be the summary field.\n\t\tif (prop.name === 'name') {\n\t\t\toptions.adminUIOptions = { summaryField: true };\n\t\t} else if (prop.name === 'title' && !this.meta.props.find((prop) => prop.name === 'name')) {\n\t\t\toptions.adminUIOptions = { summaryField: 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\n\t\tconst relatedEntity = this.entityLookup.get(prop.type);\n\t\tif (!relatedEntity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Internal Error: Related entity ${prop.type} should exist but could not be found in the entity lookup.`\n\t\t\t);\n\t\t}\n\t\tif (!isEntityWithSinglePrimaryKey(relatedEntity)) {\n\t\t\tthrow new Error(`Composite primary keys are not supported.`);\n\t\t}\n\t\tconst [primaryKey] = relatedEntity.getPrimaryProps();\n\n\t\toptions.id = `(entity) => entity.${prop.name}?.${primaryKey.name}`;\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;AACrC,uBAAsB;AACtB,mBAAyF;AACzF,uBAAyB;AAEzB,sBAA6C;AAE7C,MAAM,8BAA8B,CAAC,SAAuB;AAC3D,MAAI,SAAS,QAAS,QAAO;AAC7B,MAAI,SAAS,QAAS,QAAO;AAC7B,MAAI,SAAS,aAAc,QAAO;AAClC,MAAI,SAAS,SAAU,QAAO;AAE9B,QAAM,IAAI,MAAM,kCAAkC,IAAI;AACvD;AAEO,MAAM,yBAAyB,0BAAS;AAAA,EAO9C,YACoB,MACA,gBACA,UACA,cACA,cAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AANjB;AACA;AACA;AACA;AACA;AAXpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,S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ACA,UAAM,CAAC,UAAU,IAAI,cAAc,gBAAgB;AAEnD,YAAQ,KAAK,sBAAsB,KAAK,IAAI,KAAK,WAAW,IAAI;AAAA,EACjE;AAAA,EAEU,iBAAiB,MAA8B;AACxD,QAAI,CAAC,0BAAc,YAAY,0BAAc,WAAW,EAAE,SAAS,KAAK,IAAI,GAAG;AAC9E,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK,KAAK,SAAS;AAAA,IACjD;AAEA,QAAI,CAAC,0BAAc,aAAa,0BAAc,YAAY,EAAE,SAAS,KAAK,IAAI,GAAG;AAChF,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK,IAAI;AAAA,IACvC;AAEA,SAAK,YAAY,IAAI,OAAO;AAC5B,WAAO;AAAA,EACR;AACD;",
6
6
  "names": ["prop", "pluralize"]
7
7
  }
@@ -21,6 +21,7 @@ __export(schema_index_file_exports, {
21
21
  SchemaIndexFile: () => SchemaIndexFile
22
22
  });
23
23
  module.exports = __toCommonJS(schema_index_file_exports);
24
+ var import_generate = require("../generate");
24
25
  class SchemaIndexFile {
25
26
  constructor(metadata) {
26
27
  this.metadata = metadata;
@@ -32,7 +33,7 @@ class SchemaIndexFile {
32
33
  return "index.ts";
33
34
  }
34
35
  generate() {
35
- return this.metadata.filter((meta) => !meta.pivotTable).map(
36
+ return this.metadata.filter((meta) => !meta.pivotTable && (0, import_generate.isEntityWithSinglePrimaryKey)(meta)).map(
36
37
  (meta) => `import './${meta.className.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase()}';`
37
38
  ).join("\n") + "\n";
38
39
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/introspection/files/schema-index-file.ts"],
4
- "sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\n\nexport class SchemaIndexFile {\n\tconstructor(protected readonly metadata: EntityMetadata<any>[]) {}\n\n\tgetBasePath() {\n\t\treturn `backend/schema`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\treturn (\n\t\t\tthis.metadata\n\t\t\t\t.filter((meta) => !meta.pivotTable)\n\t\t\t\t.map(\n\t\t\t\t\t(meta) =>\n\t\t\t\t\t\t`import './${meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase()}';`\n\t\t\t\t)\n\t\t\t\t.join('\\n') + '\\n'\n\t\t);\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,gBAAgB;AAAA,EAC5B,YAA+B,UAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEjE,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,WACC,KAAK,SACH,OAAO,CAAC,SAAS,CAAC,KAAK,UAAU,EACjC;AAAA,MACA,CAAC,SACA,aAAa,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY,CAAC;AAAA,IAClF,EACC,KAAK,IAAI,IAAI;AAAA,EAEjB;AACD;",
4
+ "sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\nimport { isEntityWithSinglePrimaryKey } from '../generate';\n\nexport class SchemaIndexFile {\n\tconstructor(protected readonly metadata: EntityMetadata<any>[]) {}\n\n\tgetBasePath() {\n\t\treturn `backend/schema`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\treturn (\n\t\t\tthis.metadata\n\t\t\t\t.filter((meta) => !meta.pivotTable && isEntityWithSinglePrimaryKey(meta))\n\t\t\t\t.map(\n\t\t\t\t\t(meta) =>\n\t\t\t\t\t\t`import './${meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase()}';`\n\t\t\t\t)\n\t\t\t\t.join('\\n') + '\\n'\n\t\t);\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6C;AAEtC,MAAM,gBAAgB;AAAA,EAC5B,YAA+B,UAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEjE,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,WACC,KAAK,SACH,OAAO,CAAC,SAAS,CAAC,KAAK,kBAAc,8CAA6B,IAAI,CAAC,EACvE;AAAA,MACA,CAAC,SACA,aAAa,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY,CAAC;AAAA,IAClF,EACC,KAAK,IAAI,IAAI;AAAA,EAEjB;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,15 @@
1
+ import { EntityMetadata } from '@mikro-orm/core';
1
2
  import { ConnectionOptions, DatabaseType } from '../database';
2
3
  export declare class IntrospectionError extends Error {
3
4
  protected title: string;
4
5
  protected type: string;
5
6
  constructor(title?: string, message?: string);
6
7
  }
8
+ export declare const isEntityWithSinglePrimaryKey: (meta?: EntityMetadata) => boolean;
7
9
  export declare const generate: (databaseType: DatabaseType, options: ConnectionOptions) => Promise<{
8
10
  path: string;
9
11
  name: string;
10
12
  contents: string;
11
13
  needOverwriteWarning: boolean;
14
+ errors: string[];
12
15
  }[]>;
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var generate_exports = {};
30
30
  __export(generate_exports, {
31
31
  IntrospectionError: () => IntrospectionError,
32
- generate: () => generate
32
+ generate: () => generate,
33
+ isEntityWithSinglePrimaryKey: () => isEntityWithSinglePrimaryKey
33
34
  });
34
35
  module.exports = __toCommonJS(generate_exports);
35
36
  var import_knex = require("@mikro-orm/knex");
@@ -96,15 +97,7 @@ const generateBidirectionalRelations = (metadata) => {
96
97
  }
97
98
  }
98
99
  }
99
- if (nonPrimaryKeyReferenceErrors.length) {
100
- throw new IntrospectionError(
101
- `Unsupported Relationship${nonPrimaryKeyReferenceErrors.length === 1 ? "" : "s"} Detected`,
102
- `
103
- ${nonPrimaryKeyReferenceErrors.join("\n")}
104
-
105
- Foreign keys in Graphweaver currently need to reference the primary key of the other table.`
106
- );
107
- }
100
+ return { errors: nonPrimaryKeyReferenceErrors };
108
101
  };
109
102
  const detectManyToManyRelations = (metadata) => {
110
103
  for (const meta of metadata) {
@@ -147,54 +140,30 @@ const generateSingularTypeReferences = (metadata) => {
147
140
  }
148
141
  }
149
142
  };
150
- const convertToCamelCasePropertyNames = (metadata) => {
143
+ const normalisePropertyNames = (metadata) => {
151
144
  for (const meta of metadata.filter((m) => !m.pivotTable)) {
152
145
  const props = Object.values(meta.properties);
153
146
  props.forEach((prop) => {
154
- prop.name = (0, import_utils.pascalToCamelCaseString)(prop.name);
147
+ prop.name = (0, import_utils.pascalToCamelCaseString)(prop.name).replace(/\W/g, "_");
155
148
  });
156
149
  }
157
150
  };
158
- const assertUniqueForeignKeys = (table) => {
159
- const uniqueForeignKeys = /* @__PURE__ */ new Set();
160
- const definedForeignKeys = Object.values(table.getForeignKeys());
161
- for (const foreignKey of definedForeignKeys) {
162
- const { localTableName, referencedTableName, columnNames, referencedColumnNames } = foreignKey;
163
- const serializedValue = JSON.stringify({
164
- localTableName,
165
- columnNames: columnNames.sort(),
166
- referencedTableName,
167
- referencedColumnNames: referencedColumnNames.sort()
168
- });
169
- if (uniqueForeignKeys.has(serializedValue)) {
170
- throw new Error(
171
- `
172
-
173
- Import Failed: Duplicate foreign keys detected on column/s (${columnNames.toString()}) in table "${table.name}".`
174
- );
175
- }
176
- uniqueForeignKeys.add(serializedValue);
177
- }
178
- };
179
151
  const convertSchemaToMetadata = async (schema, platform, namingStrategy) => {
180
152
  const helper = platform.getSchemaHelper();
181
153
  if (!helper) throw new Error("cannot connect to database");
182
- const metadata = schema.getTables().sort((a, b) => a.name.localeCompare(b.name)).map((table) => {
183
- assertUniqueForeignKeys(table);
184
- return table.getEntityDeclaration(namingStrategy, helper, "never");
185
- });
154
+ const metadata = schema.getTables().sort((a, b) => a.name.localeCompare(b.name)).map((table) => table.getEntityDeclaration(namingStrategy, helper, "never"));
186
155
  if (metadata.length === 0) {
187
156
  throw new IntrospectionError(
188
157
  `Warning: No tables found, this database is empty.`,
189
158
  `Make sure you have tables in this database and then try again.`
190
159
  );
191
160
  }
192
- convertToCamelCasePropertyNames(metadata);
161
+ normalisePropertyNames(metadata);
193
162
  detectManyToManyRelations(metadata);
194
163
  generateIdentifiedReferences(metadata);
195
- generateBidirectionalRelations(metadata);
164
+ const { errors } = generateBidirectionalRelations(metadata);
196
165
  generateSingularTypeReferences(metadata);
197
- return metadata;
166
+ return { metadata, errors };
198
167
  };
199
168
  const openConnection = async (type, options) => {
200
169
  const module2 = require(`@mikro-orm/${type}`);
@@ -216,6 +185,10 @@ const closeConnection = async () => {
216
185
  await import_database.ConnectionManager.close(CONNECTION_MANAGER_ID);
217
186
  console.log("Database connection closed.");
218
187
  };
188
+ const isEntityWithSinglePrimaryKey = (meta) => {
189
+ if (!meta) return false;
190
+ return meta.primaryKeys.length === 1;
191
+ };
219
192
  const generate = async (databaseType, options) => {
220
193
  try {
221
194
  await openConnection(databaseType, options);
@@ -233,7 +206,7 @@ const generate = async (databaseType, options) => {
233
206
  console.log("Fetching database schema...");
234
207
  const schema = await import_knex.DatabaseSchema.create(connection, platform, config);
235
208
  console.log("Building metadata...");
236
- const metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);
209
+ const { metadata, errors } = await convertSchemaToMetadata(schema, platform, namingStrategy);
237
210
  const entityLookup = /* @__PURE__ */ new Map();
238
211
  for (const meta of metadata) {
239
212
  entityLookup.set(meta.className, meta);
@@ -241,8 +214,14 @@ const generate = async (databaseType, options) => {
241
214
  const source = [];
242
215
  const summaryOfEntities = [];
243
216
  for (const meta of metadata) {
244
- if (!meta.pivotTable) {
245
- const dataEntityFile = new import_files.DataEntityFile(meta, namingStrategy, platform, databaseType);
217
+ if (!meta.pivotTable && isEntityWithSinglePrimaryKey(meta)) {
218
+ const dataEntityFile = new import_files.DataEntityFile(
219
+ meta,
220
+ namingStrategy,
221
+ platform,
222
+ databaseType,
223
+ entityLookup
224
+ );
246
225
  const schemaEntityFile = new import_files.SchemaEntityFile(
247
226
  meta,
248
227
  namingStrategy,
@@ -256,6 +235,14 @@ const generate = async (databaseType, options) => {
256
235
  entityFilePath: `${dataEntityFile.getBasePath()}${dataEntityFile.getBaseName()}`,
257
236
  schemaFilePath: `${schemaEntityFile.getBasePath()}${schemaEntityFile.getBaseName()}`
258
237
  });
238
+ } else if (meta.primaryKeys.length > 1) {
239
+ errors.push(
240
+ `Entity ${meta.className} has either more than one primary key. We have skipped it and relations to it because Graphweaver does not support entities with multiple primary keys yet.`
241
+ );
242
+ } else if (meta.primaryKeys.length === 0) {
243
+ errors.push(
244
+ `Entity ${meta.className} has no primary key. We have skipped it and relations to it because Graphweaver does not support entities with no primary key yet.`
245
+ );
259
246
  }
260
247
  }
261
248
  source.push(new import_files.DataEntityIndexFile(metadata, databaseType));
@@ -267,7 +254,8 @@ const generate = async (databaseType, options) => {
267
254
  path: file.getBasePath(),
268
255
  name: file.getBaseName(),
269
256
  contents: file.generate(),
270
- needOverwriteWarning: !![import_files.DatabaseFile, import_files.SchemaIndexFile].some((cls) => file instanceof cls)
257
+ needOverwriteWarning: !![import_files.DatabaseFile, import_files.SchemaIndexFile].some((cls) => file instanceof cls),
258
+ errors: "errors" in file ? file.errors : []
271
259
  };
272
260
  });
273
261
  await closeConnection();
@@ -278,6 +266,15 @@ const generate = async (databaseType, options) => {
278
266
  Imported ${summaryOfEntities.length} entities, creating the above files in your Graphweaver project.
279
267
  `
280
268
  );
269
+ for (const file of files) {
270
+ errors.push(...file.errors);
271
+ }
272
+ if (errors.length) {
273
+ console.log(`
274
+ Warning ${errors.length} errors detected:
275
+ `);
276
+ console.log(errors.join("\n"));
277
+ }
281
278
  return files;
282
279
  } catch (err) {
283
280
  if (err instanceof IntrospectionError) throw err;
@@ -292,6 +289,7 @@ Imported ${summaryOfEntities.length} entities, creating the above files in your
292
289
  // Annotate the CommonJS export names for ESM import in node:
293
290
  0 && (module.exports = {
294
291
  IntrospectionError,
295
- generate
292
+ generate,
293
+ isEntityWithSinglePrimaryKey
296
294
  });
297
295
  //# sourceMappingURL=generate.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/introspection/generate.ts"],
4
- "sourcesContent": ["import { DatabaseSchema, AbstractSqlPlatform, DatabaseTable } 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\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(\n\t\tprotected title = '',\n\t\tmessage = ''\n\t) {\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\tconst nonPrimaryKeyReferenceErrors: string[] = [];\n\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 referencedTablePrimaryKeys = Utils.flatten(\n\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t);\n\n\t\t\t\t// Check any props that actually have fields in the database to store keys in for references to non-primary keys.\n\t\t\t\tif (prop.fieldNames?.length) {\n\t\t\t\t\tfor (const referencedColumn of prop.referencedColumnNames) {\n\t\t\t\t\t\tif (!referencedTablePrimaryKeys.includes(referencedColumn)) {\n\t\t\t\t\t\t\tnonPrimaryKeyReferenceErrors.push(\n\t\t\t\t\t\t\t\t` - Relationship between ${meta.className}.${prop.fieldNames.join(', ')} and ${targetMeta?.className}.${referencedColumn} is not supported.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\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: referencedTablePrimaryKeys,\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\tif (nonPrimaryKeyReferenceErrors.length) {\n\t\tthrow new IntrospectionError(\n\t\t\t`Unsupported Relationship${nonPrimaryKeyReferenceErrors.length === 1 ? '' : 's'} Detected`,\n\t\t\t`\\n${nonPrimaryKeyReferenceErrors.join('\\n')}\\n\\nForeign keys in Graphweaver currently need to reference the primary key of the other table.`\n\t\t);\n\t}\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[]) => {\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 assertUniqueForeignKeys = (table: DatabaseTable): void => {\n\tconst uniqueForeignKeys = new Set();\n\tconst definedForeignKeys = Object.values(table.getForeignKeys());\n\n\tfor (const foreignKey of definedForeignKeys) {\n\t\tconst { localTableName, referencedTableName, columnNames, referencedColumnNames } = foreignKey;\n\t\tconst serializedValue = JSON.stringify({\n\t\t\tlocalTableName,\n\t\t\tcolumnNames: columnNames.sort(),\n\t\t\treferencedTableName,\n\t\t\treferencedColumnNames: referencedColumnNames.sort(),\n\t\t});\n\n\t\tif (uniqueForeignKeys.has(serializedValue)) {\n\t\t\tthrow new Error(\n\t\t\t\t`\\n\\nImport Failed: Duplicate foreign keys detected on column/s (${columnNames.toString()}) in table \"${\n\t\t\t\t\ttable.name\n\t\t\t\t}\".`\n\t\t\t);\n\t\t}\n\n\t\tuniqueForeignKeys.add(serializedValue);\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) => {\n\t\t\tassertUniqueForeignKeys(table);\n\t\t\treturn table.getEntityDeclaration(namingStrategy, helper, 'never');\n\t\t});\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);\n\tgenerateIdentifiedReferences(metadata);\n\tgenerateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn metadata;\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst module = require(`@mikro-orm/${type}`);\n\tconst PLATFORMS = {\n\t\tmssql: 'MsSqlDriver',\n\t\tmysql: 'MySqlDriver',\n\t\tpostgresql: 'PostgreSqlDriver',\n\t\tsqlite: 'SqliteDriver',\n\t};\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\tdriver: module[PLATFORMS[type]],\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| SchemaIndexFile\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\t// Build a lookup for efficient cross-referencing later.\n\t\tconst entityLookup = new Map<string, EntityMetadata<any>>();\n\t\tfor (const meta of metadata) {\n\t\t\tentityLookup.set(meta.className, meta);\n\t\t}\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(\n\t\t\t\t\tmeta,\n\t\t\t\t\tnamingStrategy,\n\t\t\t\t\tplatform,\n\t\t\t\t\tdatabaseType,\n\t\t\t\t\tentityLookup\n\t\t\t\t);\n\t\t\t\tsource.push(dataEntityFile, schemaEntityFile);\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: `${schemaEntityFile.getBasePath()}${schemaEntityFile.getBaseName()}`,\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\tconsole.error('Got error during introspection:');\n\t\tconsole.error(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,kBAAmE;AACnE,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBAOO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YACW,QAAQ,IAClB,UAAU,IACT;AACD,UAAM,OAAO;AAHH;AAIV,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAAqC;AAC5E,QAAM,+BAAyC,CAAC;AAEhD,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD,eAAW,QAAQ,KAAK,WAAW;AAClC,UAAI,CAAC,KAAK,KAAK,SAAS,SAAS,GAAG;AACnC,cAAM,aAAa,SAAS,KAAK,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI;AACjE,c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,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,MAAM;AAAA;AAAA,IACvC;AAEA,WAAO;AAAA,EACR,SAAS,KAAK;AACb,QAAI,eAAe,mBAAoB,OAAM;AAE7C,YAAQ,MAAM,iCAAiC;AAC/C,YAAQ,MAAM,GAAG;AAEjB,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\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(\n\t\tprotected title = '',\n\t\tmessage = ''\n\t) {\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[]) => {\n\tconst nonPrimaryKeyReferenceErrors: string[] = [];\n\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 referencedTablePrimaryKeys = Utils.flatten(\n\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t);\n\n\t\t\t\t// Check any props that actually have fields in the database to store keys in for references to non-primary keys.\n\t\t\t\tif (prop.fieldNames?.length) {\n\t\t\t\t\tfor (const referencedColumn of prop.referencedColumnNames) {\n\t\t\t\t\t\tif (!referencedTablePrimaryKeys.includes(referencedColumn)) {\n\t\t\t\t\t\t\tnonPrimaryKeyReferenceErrors.push(\n\t\t\t\t\t\t\t\t` - Relationship between ${meta.className}.${prop.fieldNames.join(', ')} and ${targetMeta?.className}.${referencedColumn} is not supported.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\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: referencedTablePrimaryKeys,\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\treturn { errors: nonPrimaryKeyReferenceErrors };\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[]) => {\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 normalisePropertyNames = (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).replace(/\\W/g, '_');\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\tnormalisePropertyNames(metadata);\n\tdetectManyToManyRelations(metadata);\n\tgenerateIdentifiedReferences(metadata);\n\tconst { errors } = generateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn { metadata, errors };\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst module = require(`@mikro-orm/${type}`);\n\tconst PLATFORMS = {\n\t\tmssql: 'MsSqlDriver',\n\t\tmysql: 'MySqlDriver',\n\t\tpostgresql: 'PostgreSqlDriver',\n\t\tsqlite: 'SqliteDriver',\n\t};\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\tdriver: module[PLATFORMS[type]],\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| SchemaIndexFile\n\t| DataEntityIndexFile\n\t| DataSourceIndexFile\n\t| DatabaseFile;\n\nexport const isEntityWithSinglePrimaryKey = (meta?: EntityMetadata) => {\n\tif (!meta) return false;\n\treturn meta.primaryKeys.length === 1;\n};\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, errors } = await convertSchemaToMetadata(schema, platform, namingStrategy);\n\n\t\t// Build a lookup for efficient cross-referencing later.\n\t\tconst entityLookup = new Map<string, EntityMetadata<any>>();\n\t\tfor (const meta of metadata) {\n\t\t\tentityLookup.set(meta.className, meta);\n\t\t}\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 && isEntityWithSinglePrimaryKey(meta)) {\n\t\t\t\tconst dataEntityFile = new DataEntityFile(\n\t\t\t\t\tmeta,\n\t\t\t\t\tnamingStrategy,\n\t\t\t\t\tplatform,\n\t\t\t\t\tdatabaseType,\n\t\t\t\t\tentityLookup\n\t\t\t\t);\n\t\t\t\tconst schemaEntityFile = new SchemaEntityFile(\n\t\t\t\t\tmeta,\n\t\t\t\t\tnamingStrategy,\n\t\t\t\t\tplatform,\n\t\t\t\t\tdatabaseType,\n\t\t\t\t\tentityLookup\n\t\t\t\t);\n\t\t\t\tsource.push(dataEntityFile, schemaEntityFile);\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: `${schemaEntityFile.getBasePath()}${schemaEntityFile.getBaseName()}`,\n\t\t\t\t});\n\t\t\t} else if (meta.primaryKeys.length > 1) {\n\t\t\t\terrors.push(\n\t\t\t\t\t`Entity ${meta.className} has either more than one primary key. We have skipped it and relations to it because Graphweaver does not support entities with multiple primary keys yet.`\n\t\t\t\t);\n\t\t\t} else if (meta.primaryKeys.length === 0) {\n\t\t\t\terrors.push(\n\t\t\t\t\t`Entity ${meta.className} has no primary key. We have skipped it and relations to it because Graphweaver does not support entities with no primary key yet.`\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\terrors: 'errors' in file ? file.errors : [],\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\tfor (const file of files) {\n\t\t\terrors.push(...file.errors);\n\t\t}\n\n\t\tif (errors.length) {\n\t\t\tconsole.log(`\\nWarning ${errors.length} errors detected:\\n`);\n\t\t\tconsole.log(errors.join('\\n'));\n\t\t}\n\n\t\treturn files;\n\t} catch (err) {\n\t\tif (err instanceof IntrospectionError) throw err;\n\n\t\tconsole.error('Got error during introspection:');\n\t\tconsole.error(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;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBAOO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YACW,QAAQ,IAClB,UAAU,IACT;AACD,UAAM,OAAO;AAHH;AAIV,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAA+B;AACtE,QAAM,+BAAyC,CAAC;AAEhD,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD,eAAW,QAAQ,KAAK,WAAW;AAClC,UAAI,CAAC,KAAK,KAAK,SAAS,SAAS,G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C/B,YAAQ;AAAA,MACP;AAAA,WAAc,kBAAkB,MAAM;AAAA;AAAA,IACvC;AAEA,eAAW,QAAQ,OAAO;AACzB,aAAO,KAAK,GAAG,KAAK,MAAM;AAAA,IAC3B;AAEA,QAAI,OAAO,QAAQ;AAClB,cAAQ,IAAI;AAAA,UAAa,OAAO,MAAM;AAAA,CAAqB;AAC3D,cAAQ,IAAI,OAAO,KAAK,IAAI,CAAC;AAAA,IAC9B;AAEA,WAAO;AAAA,EACR,SAAS,KAAK;AACb,QAAI,eAAe,mBAAoB,OAAM;AAE7C,YAAQ,MAAM,iCAAiC;AAC/C,YAAQ,MAAM,GAAG;AAEjB,UAAM,IAAI;AAAA,MACT;AAAA,MACA,gBAAgB,GAAG,IAAI,IAAI,UAAU;AAAA,IACtC;AAAA,EACD;AACD;",
6
6
  "names": ["pluralize", "module"]
7
7
  }
@@ -4,4 +4,5 @@ export declare const introspection: (databaseType: DatabaseType, options: Connec
4
4
  name: string;
5
5
  contents: string;
6
6
  needOverwriteWarning: boolean;
7
+ errors: string[];
7
8
  }[]>;
@@ -35,7 +35,14 @@ const pascalToCamelCaseString = (value) => {
35
35
  const restOfString = value.slice(1);
36
36
  return firstChar + restOfString;
37
37
  };
38
- const identifierForEnumValue = (value) => value.replace(/[^a-z0-9_]/gi, "_").toUpperCase();
38
+ const identifierForEnumValue = (value) => {
39
+ const identifier = value.replace(/[^a-z0-9_]/gi, "_").toUpperCase();
40
+ if (/^\d+$/.test(identifier)) {
41
+ return `_${identifier}`;
42
+ } else {
43
+ return identifier;
44
+ }
45
+ };
39
46
  // Annotate the CommonJS export names for ESM import in node:
40
47
  0 && (module.exports = {
41
48
  identifierForEnumValue,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/introspection/utils.ts"],
4
- "sourcesContent": ["export const pascalToKebabCaseString = (value: string) => {\n\treturn value.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n};\n\nexport const snakeToCamelCaseString = (value: string) => {\n\treturn value.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n};\n\nexport const pascalToCamelCaseString = (value: string) => {\n\tconst firstChar = value.charAt(0).toLowerCase();\n\tconst restOfString = value.slice(1);\n\treturn firstChar + restOfString;\n};\n\n// Anything that is not alphanumeric or an underscore is replaced with an underscore, then the value is uppercased\nexport const identifierForEnumValue = (value: string) =>\n\tvalue.replace(/[^a-z0-9_]/gi, '_').toUpperCase();\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,0BAA0B,CAAC,UAAkB;AACzD,SAAO,MAAM,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACjE;AAEO,MAAM,yBAAyB,CAAC,UAAkB;AACxD,SAAO,MAAM,QAAQ,aAAa,CAAC,GAAG,WAAW,OAAO,YAAY,CAAC;AACtE;AAEO,MAAM,0BAA0B,CAAC,UAAkB;AACzD,QAAM,YAAY,MAAM,OAAO,CAAC,EAAE,YAAY;AAC9C,QAAM,eAAe,MAAM,MAAM,CAAC;AAClC,SAAO,YAAY;AACpB;AAGO,MAAM,yBAAyB,CAAC,UACtC,MAAM,QAAQ,gBAAgB,GAAG,EAAE,YAAY;",
4
+ "sourcesContent": ["export const pascalToKebabCaseString = (value: string) => {\n\treturn value.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n};\n\nexport const snakeToCamelCaseString = (value: string) => {\n\treturn value.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n};\n\nexport const pascalToCamelCaseString = (value: string) => {\n\tconst firstChar = value.charAt(0).toLowerCase();\n\tconst restOfString = value.slice(1);\n\treturn firstChar + restOfString;\n};\n\n// Anything that is not alphanumeric or an underscore is replaced with an underscore, then the value is uppercased\nexport const identifierForEnumValue = (value: string) => {\n\tconst identifier = value.replace(/[^a-z0-9_]/gi, '_').toUpperCase();\n\n\t// Enums have to have string identifiers.\n\tif (/^\\d+$/.test(identifier)) {\n\t\treturn `_${identifier}`;\n\t} else {\n\t\treturn identifier;\n\t}\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,0BAA0B,CAAC,UAAkB;AACzD,SAAO,MAAM,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACjE;AAEO,MAAM,yBAAyB,CAAC,UAAkB;AACxD,SAAO,MAAM,QAAQ,aAAa,CAAC,GAAG,WAAW,OAAO,YAAY,CAAC;AACtE;AAEO,MAAM,0BAA0B,CAAC,UAAkB;AACzD,QAAM,YAAY,MAAM,OAAO,CAAC,EAAE,YAAY;AAC9C,QAAM,eAAe,MAAM,MAAM,CAAC;AAClC,SAAO,YAAY;AACpB;AAGO,MAAM,yBAAyB,CAAC,UAAkB;AACxD,QAAM,aAAa,MAAM,QAAQ,gBAAgB,GAAG,EAAE,YAAY;AAGlE,MAAI,QAAQ,KAAK,UAAU,GAAG;AAC7B,WAAO,IAAI,UAAU;AAAA,EACtB,OAAO;AACN,WAAO;AAAA,EACR;AACD;",
6
6
  "names": []
7
7
  }
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(assign_exports);
24
24
  var import_core = require("@mikro-orm/core");
25
25
  var import_logger = require("@exogee/logger");
26
26
  var import_database = require("../database");
27
+ var import_generate = require("../introspection/generate");
27
28
  const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set(), em = import_database.ConnectionManager.default.em) => {
28
29
  if (visited.has(entity)) return entity;
29
30
  visited.add(entity);
@@ -42,12 +43,12 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
42
43
  );
43
44
  }
44
45
  const relatedEntity = em.getMetadata().find(propertyMetadata.entity());
45
- if (relatedEntity?.primaryKeys.length !== 1) {
46
+ if (!(0, import_generate.isEntityWithSinglePrimaryKey)(relatedEntity)) {
46
47
  throw new Error(
47
48
  `Entity ${propertyMetadata.entity()} has multiple primary keys, which is not yet supported.`
48
49
  );
49
50
  }
50
- const [relatedPrimaryKeyField] = relatedEntity.primaryKeys;
51
+ const [relatedPrimaryKeyField] = relatedEntity?.primaryKeys ?? [];
51
52
  const visitedEntities = /* @__PURE__ */ new Set();
52
53
  for (const subvalue of value) {
53
54
  let entity2;
@@ -101,7 +102,7 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
101
102
  `Could not find entity ${propertyMetadata.entity()} in MikroORM metadata.`
102
103
  );
103
104
  }
104
- if (relatedEntity.primaryKeys.length !== 1) {
105
+ if (!(0, import_generate.isEntityWithSinglePrimaryKey)(relatedEntity)) {
105
106
  throw new Error(
106
107
  `Entity ${propertyMetadata.entity()} has ${relatedEntity.primaryKeys.length} primary keys, but we only support 1.`
107
108
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/provider/assign.ts"],
4
- "sourcesContent": ["import {\n\tAnyEntity,\n\tEntityData,\n\tEntityManager,\n\tEntityProperty,\n\tReference,\n\tReferenceKind,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\nimport { logger } from '@exogee/logger';\n\nimport { ConnectionManager } from '../database';\n\ninterface AssignOptions {\n\t// Whether this assign should be allowed to create new entities.\n\t// If false and a create is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tcreate?: boolean;\n\n\t// Whether this assign should be allowed update existing entities.\n\t// If false and an update is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tupdate?: boolean;\n}\n\nexport const assign = async <T extends AnyEntity<T>>(\n\tentity: T,\n\tdata: EntityData<T>,\n\toptions?: AssignOptions,\n\tvisited = new Set<AnyEntity<any>>(),\n\tem = ConnectionManager.default.em\n) => {\n\tif (visited.has(entity)) return entity;\n\tvisited.add(entity);\n\n\t// We'll need the metadata for this entity to be able to traverse the properties later.\n\tconst metadata = wrap(entity, true).__meta!;\n\n\tfor (const [property, value] of Object.entries(data)) {\n\t\tconst entityPropertyValue = entity[property as keyof T];\n\n\t\t// We're going to need the metadata for this property so we can ensure it exists and so that we can\n\t\t// navigate to related entities.\n\t\tconst propertyMetadata = (metadata.properties as any)[property] as\n\t\t\t| EntityProperty<T>\n\t\t\t| undefined;\n\n\t\tif (\n\t\t\tpropertyMetadata?.kind === ReferenceKind.MANY_TO_MANY ||\n\t\t\tpropertyMetadata?.kind === ReferenceKind.ONE_TO_MANY\n\t\t) {\n\t\t\tif (!Array.isArray(value))\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Value is not an array while trying to assign to collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\n\t\t\t// Ensure the entity has a loaded collection at the same place.\n\t\t\tif (!Utils.isCollection<T, any>(entityPropertyValue)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Tried to merge array into non-collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst relatedEntity = em.getMetadata().find(propertyMetadata.entity());\n\t\t\tif (relatedEntity?.primaryKeys.length !== 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Entity ${propertyMetadata.entity()} has multiple primary keys, which is not yet supported.`\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst [relatedPrimaryKeyField] = relatedEntity.primaryKeys;\n\n\t\t\tconst visitedEntities = new Set<T>();\n\n\t\t\tfor (const subvalue of value) {\n\t\t\t\tlet entity: T | undefined;\n\n\t\t\t\tif (subvalue[relatedPrimaryKeyField]) {\n\t\t\t\t\t// Get the current entity from the ORM if there's an ID.\n\t\t\t\t\tentity = em\n\t\t\t\t\t\t.getUnitOfWork()\n\t\t\t\t\t\t.getById(propertyMetadata.type, subvalue[relatedPrimaryKeyField]);\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\t// There are two cases here: either the user is trying to assign properties to the entity as well as changing members of a collection,\n\t\t\t\t\t\t// or they're just changing members of a collection.\n\t\t\t\t\t\t// For the former we actually need the entity from the DB, while for the latter we can let it slide and just pass an ID entity on down.\n\t\t\t\t\t\tconst subvalueKeys = Object.keys(subvalue);\n\t\t\t\t\t\tif (subvalueKeys.length === 1 && subvalueKeys[0] === relatedPrimaryKeyField) {\n\t\t\t\t\t\t\t// It's just the ID.\n\t\t\t\t\t\t\tentity = em.getReference(\n\t\t\t\t\t\t\t\tpropertyMetadata.type,\n\t\t\t\t\t\t\t\tsubvalue[relatedPrimaryKeyField]\n\t\t\t\t\t\t\t) as T;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t\t`Doing a full database fetch for ${propertyMetadata.type} with id ${subvalue[relatedPrimaryKeyField]}, this should ideally be prefetched into the Unit of Work before calling assign() for performance`\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// We should be prefetching for performance in most cases here but if we don't have it we can load it now.\n\t\t\t\t\t\t\t// From base resolver a reason this would be needed is when you're switching collection values from one entity to another, e.g.\n\t\t\t\t\t\t\t// Business unit 1 -> Business unit 2. In this scenario we prefetch the one that's currently on the entity, but the one we're changing\n\t\t\t\t\t\t\t// to is not in the unit of work.\n\t\t\t\t\t\t\tentity =\n\t\t\t\t\t\t\t\t((await em.findOne<any>(propertyMetadata.type, {\n\t\t\t\t\t\t\t\t\t[relatedPrimaryKeyField]: subvalue[relatedPrimaryKeyField],\n\t\t\t\t\t\t\t\t})) as T | null) ?? undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Attempted to assign as an update to '${propertyMetadata.name}' property of ${metadata.name} Entity, but even after a full fetch to the database ${propertyMetadata.type} with ID of ${subvalue.id} could not be found.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\tentity,\n\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\tprimaryKeyField: relatedPrimaryKeyField,\n\t\t\t\t\tdata: subvalue,\n\t\t\t\t\toptions,\n\t\t\t\t\tvisited,\n\t\t\t\t\tem,\n\t\t\t\t});\n\n\t\t\t\t// Ok, now we've got the created or updated entity, ensure it's in the collection\n\t\t\t\t// so its foreign keys are set correctly. If it's already in the collection this is a noop.\n\t\t\t\tentityPropertyValue.add(newEntity);\n\n\t\t\t\t// We need to keep track of the fact that this entity belongs here so it doesn't get removed in the cleanup step down below.\n\t\t\t\tvisitedEntities.add(newEntity);\n\t\t\t}\n\n\t\t\t// Ok, at this point we know what IDs we visited. If anything is left in the collection that has an ID and has not been visited\n\t\t\t// it needs to be removed from the collection, because this is the canonical list of everything that's in the collection now.\n\t\t\t// ------------\n\t\t\t// \u2757\uD83D\uDC3B WARNING BEAR TRAP \uD83D\uDC3B\u2757: If you're looking at this going, \"But I just want to pass in the items I want to update and for it not to\n\t\t\t// mess with the rest of the collection\", this is here because without this behaviour, there's no way to remove items from\n\t\t\t// Many to Many properties. Consider the case of tags on an entity, when we pass ['a', 'b', 'c'] as the list of tags, that\n\t\t\t// means we need to remove anything that isn't 'a', 'b', or 'c' because it's not in the array.\n\t\t\tentityPropertyValue.remove(\n\t\t\t\tentityPropertyValue.getItems().filter((entity) => !visitedEntities.has(entity))\n\t\t\t);\n\t\t} else if (\n\t\t\tpropertyMetadata?.kind == ReferenceKind.MANY_TO_ONE ||\n\t\t\tpropertyMetadata?.kind === ReferenceKind.ONE_TO_ONE\n\t\t) {\n\t\t\tif (value === null) {\n\t\t\t\t// If the value is null, unset the reference\n\t\t\t\t(entity as any)[property] = null;\n\t\t\t} else {\n\t\t\t\tconst valueKeys = Object.keys(value as any);\n\t\t\t\tconst relatedEntity = em.getMetadata().find(propertyMetadata.entity());\n\t\t\t\tif (!relatedEntity) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Could not find entity ${propertyMetadata.entity()} in MikroORM metadata.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (relatedEntity.primaryKeys.length !== 1) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Entity ${propertyMetadata.entity()} has ${relatedEntity.primaryKeys.length} primary keys, but we only support 1.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst relatedPrimaryKeyField = relatedEntity.primaryKeys[0];\n\n\t\t\t\tif (valueKeys.length === 1 && valueKeys[0] === relatedPrimaryKeyField) {\n\t\t\t\t\t// Ok, this is just the ID, set the reference and move on.\n\t\t\t\t\tentity[property as keyof T] = em.getReference(\n\t\t\t\t\t\tpropertyMetadata.type,\n\t\t\t\t\t\t(value as any)[relatedPrimaryKeyField]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (entityPropertyValue && !Reference.isReference(entityPropertyValue)) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not a reference.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Reference.isReference(entityPropertyValue) && !entityPropertyValue.isInitialized()) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not initialised.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\t\tentity: (entityPropertyValue as Reference<T>)?.unwrap(),\n\t\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\t\tprimaryKeyField: relatedPrimaryKeyField,\n\t\t\t\t\t\tdata: value as EntityData<T>,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\tvisited,\n\t\t\t\t\t\tem,\n\t\t\t\t\t});\n\n\t\t\t\t\t(relatedEntity as any)[property] = Reference.create(newEntity);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Ok, we're a simple scalar.\n\t\t\t(entity as any)[property] = value;\n\t\t}\n\t}\n\n\treturn entity;\n};\n\nconst createOrAssignEntity = <T extends AnyEntity<T>>({\n\tentity,\n\tentityType,\n\tprimaryKeyField,\n\tdata,\n\toptions,\n\tvisited,\n\tem,\n}: {\n\tentity?: T;\n\tentityType: string;\n\tprimaryKeyField: string;\n\tdata: EntityData<T>;\n\toptions?: AssignOptions;\n\tvisited: Set<AnyEntity<any>>;\n\tem: EntityManager;\n}) => {\n\tconst create = options?.create ?? true;\n\tconst update = options?.update ?? true;\n\n\tif ((data as any)[primaryKeyField]) {\n\t\tif (!update) {\n\t\t\tthrow new Error(\n\t\t\t\t`Updates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which has an ID property.`\n\t\t\t);\n\t\t}\n\n\t\tif (!entity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Tried to update with data ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} but entity could not be located to update.`\n\t\t\t);\n\t\t}\n\n\t\t// Ok, we need to recurse here.\n\t\treturn assign(entity, data, options, visited);\n\t} else {\n\t\tif (!create) {\n\t\t\tthrow new Error(\n\t\t\t\t`Creates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which does not have an ID property.`\n\t\t\t);\n\t\t}\n\n\t\t// We don't want Mikro to manage the data merging here, we'll do it in the next line.\n\t\tconst entity = em.create<T>(entityType, {} as any);\n\t\treturn assign(entity, data, options, visited);\n\t}\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBASO;AACP,oBAAuB;AAEvB,sBAAkC;AAc3B,MAAM,SAAS,OACrB,QACA,MACA,SACA,UAAU,oBAAI,IAAoB,GAClC,KAAK,kCAAkB,QAAQ,OAC3B;AACJ,MAAI,QAAQ,IAAI,MAAM,EAAG,QAAO;AAChC,UAAQ,IAAI,MAAM;AAGlB,QAAM,eAAW,kBAAK,QAAQ,IAAI,EAAE;AAEpC,aAAW,CAAC,UAAU,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AACrD,UA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,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAGA,UAAMA,UAAS,GAAG,OAAU,YAAY,CAAC,CAAQ;AACjD,WAAO,OAAOA,SAAQ,MAAM,SAAS,OAAO;AAAA,EAC7C;AACD;",
4
+ "sourcesContent": ["import {\n\tAnyEntity,\n\tEntityData,\n\tEntityManager,\n\tEntityProperty,\n\tReference,\n\tReferenceKind,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\nimport { logger } from '@exogee/logger';\n\nimport { ConnectionManager } from '../database';\nimport { isEntityWithSinglePrimaryKey } from '../introspection/generate';\n\ninterface AssignOptions {\n\t// Whether this assign should be allowed to create new entities.\n\t// If false and a create is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tcreate?: boolean;\n\n\t// Whether this assign should be allowed update existing entities.\n\t// If false and an update is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tupdate?: boolean;\n}\n\nexport const assign = async <T extends AnyEntity<T>>(\n\tentity: T,\n\tdata: EntityData<T>,\n\toptions?: AssignOptions,\n\tvisited = new Set<AnyEntity<any>>(),\n\tem = ConnectionManager.default.em\n) => {\n\tif (visited.has(entity)) return entity;\n\tvisited.add(entity);\n\n\t// We'll need the metadata for this entity to be able to traverse the properties later.\n\tconst metadata = wrap(entity, true).__meta!;\n\n\tfor (const [property, value] of Object.entries(data)) {\n\t\tconst entityPropertyValue = entity[property as keyof T];\n\n\t\t// We're going to need the metadata for this property so we can ensure it exists and so that we can\n\t\t// navigate to related entities.\n\t\tconst propertyMetadata = (metadata.properties as any)[property] as\n\t\t\t| EntityProperty<T>\n\t\t\t| undefined;\n\n\t\tif (\n\t\t\tpropertyMetadata?.kind === ReferenceKind.MANY_TO_MANY ||\n\t\t\tpropertyMetadata?.kind === ReferenceKind.ONE_TO_MANY\n\t\t) {\n\t\t\tif (!Array.isArray(value))\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Value is not an array while trying to assign to collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\n\t\t\t// Ensure the entity has a loaded collection at the same place.\n\t\t\tif (!Utils.isCollection<T, any>(entityPropertyValue)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Tried to merge array into non-collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst relatedEntity = em.getMetadata().find(propertyMetadata.entity());\n\t\t\tif (!isEntityWithSinglePrimaryKey(relatedEntity)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Entity ${propertyMetadata.entity()} has multiple primary keys, which is not yet supported.`\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst [relatedPrimaryKeyField] = relatedEntity?.primaryKeys ?? [];\n\n\t\t\tconst visitedEntities = new Set<T>();\n\n\t\t\tfor (const subvalue of value) {\n\t\t\t\tlet entity: T | undefined;\n\n\t\t\t\tif (subvalue[relatedPrimaryKeyField]) {\n\t\t\t\t\t// Get the current entity from the ORM if there's an ID.\n\t\t\t\t\tentity = em\n\t\t\t\t\t\t.getUnitOfWork()\n\t\t\t\t\t\t.getById(propertyMetadata.type, subvalue[relatedPrimaryKeyField]);\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\t// There are two cases here: either the user is trying to assign properties to the entity as well as changing members of a collection,\n\t\t\t\t\t\t// or they're just changing members of a collection.\n\t\t\t\t\t\t// For the former we actually need the entity from the DB, while for the latter we can let it slide and just pass an ID entity on down.\n\t\t\t\t\t\tconst subvalueKeys = Object.keys(subvalue);\n\t\t\t\t\t\tif (subvalueKeys.length === 1 && subvalueKeys[0] === relatedPrimaryKeyField) {\n\t\t\t\t\t\t\t// It's just the ID.\n\t\t\t\t\t\t\tentity = em.getReference(\n\t\t\t\t\t\t\t\tpropertyMetadata.type,\n\t\t\t\t\t\t\t\tsubvalue[relatedPrimaryKeyField]\n\t\t\t\t\t\t\t) as T;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t\t`Doing a full database fetch for ${propertyMetadata.type} with id ${subvalue[relatedPrimaryKeyField]}, this should ideally be prefetched into the Unit of Work before calling assign() for performance`\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// We should be prefetching for performance in most cases here but if we don't have it we can load it now.\n\t\t\t\t\t\t\t// From base resolver a reason this would be needed is when you're switching collection values from one entity to another, e.g.\n\t\t\t\t\t\t\t// Business unit 1 -> Business unit 2. In this scenario we prefetch the one that's currently on the entity, but the one we're changing\n\t\t\t\t\t\t\t// to is not in the unit of work.\n\t\t\t\t\t\t\tentity =\n\t\t\t\t\t\t\t\t((await em.findOne<any>(propertyMetadata.type, {\n\t\t\t\t\t\t\t\t\t[relatedPrimaryKeyField]: subvalue[relatedPrimaryKeyField],\n\t\t\t\t\t\t\t\t})) as T | null) ?? undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Attempted to assign as an update to '${propertyMetadata.name}' property of ${metadata.name} Entity, but even after a full fetch to the database ${propertyMetadata.type} with ID of ${subvalue.id} could not be found.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\tentity,\n\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\tprimaryKeyField: relatedPrimaryKeyField,\n\t\t\t\t\tdata: subvalue,\n\t\t\t\t\toptions,\n\t\t\t\t\tvisited,\n\t\t\t\t\tem,\n\t\t\t\t});\n\n\t\t\t\t// Ok, now we've got the created or updated entity, ensure it's in the collection\n\t\t\t\t// so its foreign keys are set correctly. If it's already in the collection this is a noop.\n\t\t\t\tentityPropertyValue.add(newEntity);\n\n\t\t\t\t// We need to keep track of the fact that this entity belongs here so it doesn't get removed in the cleanup step down below.\n\t\t\t\tvisitedEntities.add(newEntity);\n\t\t\t}\n\n\t\t\t// Ok, at this point we know what IDs we visited. If anything is left in the collection that has an ID and has not been visited\n\t\t\t// it needs to be removed from the collection, because this is the canonical list of everything that's in the collection now.\n\t\t\t// ------------\n\t\t\t// \u2757\uD83D\uDC3B WARNING BEAR TRAP \uD83D\uDC3B\u2757: If you're looking at this going, \"But I just want to pass in the items I want to update and for it not to\n\t\t\t// mess with the rest of the collection\", this is here because without this behaviour, there's no way to remove items from\n\t\t\t// Many to Many properties. Consider the case of tags on an entity, when we pass ['a', 'b', 'c'] as the list of tags, that\n\t\t\t// means we need to remove anything that isn't 'a', 'b', or 'c' because it's not in the array.\n\t\t\tentityPropertyValue.remove(\n\t\t\t\tentityPropertyValue.getItems().filter((entity) => !visitedEntities.has(entity))\n\t\t\t);\n\t\t} else if (\n\t\t\tpropertyMetadata?.kind == ReferenceKind.MANY_TO_ONE ||\n\t\t\tpropertyMetadata?.kind === ReferenceKind.ONE_TO_ONE\n\t\t) {\n\t\t\tif (value === null) {\n\t\t\t\t// If the value is null, unset the reference\n\t\t\t\t(entity as any)[property] = null;\n\t\t\t} else {\n\t\t\t\tconst valueKeys = Object.keys(value as any);\n\t\t\t\tconst relatedEntity = em.getMetadata().find(propertyMetadata.entity());\n\t\t\t\tif (!relatedEntity) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Could not find entity ${propertyMetadata.entity()} in MikroORM metadata.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!isEntityWithSinglePrimaryKey(relatedEntity)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Entity ${propertyMetadata.entity()} has ${relatedEntity.primaryKeys.length} primary keys, but we only support 1.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst relatedPrimaryKeyField = relatedEntity.primaryKeys[0];\n\n\t\t\t\tif (valueKeys.length === 1 && valueKeys[0] === relatedPrimaryKeyField) {\n\t\t\t\t\t// Ok, this is just the ID, set the reference and move on.\n\t\t\t\t\tentity[property as keyof T] = em.getReference(\n\t\t\t\t\t\tpropertyMetadata.type,\n\t\t\t\t\t\t(value as any)[relatedPrimaryKeyField]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tif (entityPropertyValue && !Reference.isReference(entityPropertyValue)) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not a reference.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Reference.isReference(entityPropertyValue) && !entityPropertyValue.isInitialized()) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not initialised.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\t\tentity: (entityPropertyValue as Reference<T>)?.unwrap(),\n\t\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\t\tprimaryKeyField: relatedPrimaryKeyField,\n\t\t\t\t\t\tdata: value as EntityData<T>,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\tvisited,\n\t\t\t\t\t\tem,\n\t\t\t\t\t});\n\n\t\t\t\t\t(relatedEntity as any)[property] = Reference.create(newEntity);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Ok, we're a simple scalar.\n\t\t\t(entity as any)[property] = value;\n\t\t}\n\t}\n\n\treturn entity;\n};\n\nconst createOrAssignEntity = <T extends AnyEntity<T>>({\n\tentity,\n\tentityType,\n\tprimaryKeyField,\n\tdata,\n\toptions,\n\tvisited,\n\tem,\n}: {\n\tentity?: T;\n\tentityType: string;\n\tprimaryKeyField: string;\n\tdata: EntityData<T>;\n\toptions?: AssignOptions;\n\tvisited: Set<AnyEntity<any>>;\n\tem: EntityManager;\n}) => {\n\tconst create = options?.create ?? true;\n\tconst update = options?.update ?? true;\n\n\tif ((data as any)[primaryKeyField]) {\n\t\tif (!update) {\n\t\t\tthrow new Error(\n\t\t\t\t`Updates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which has an ID property.`\n\t\t\t);\n\t\t}\n\n\t\tif (!entity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Tried to update with data ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} but entity could not be located to update.`\n\t\t\t);\n\t\t}\n\n\t\t// Ok, we need to recurse here.\n\t\treturn assign(entity, data, options, visited);\n\t} else {\n\t\tif (!create) {\n\t\t\tthrow new Error(\n\t\t\t\t`Creates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which does not have an ID property.`\n\t\t\t);\n\t\t}\n\n\t\t// We don't want Mikro to manage the data merging here, we'll do it in the next line.\n\t\tconst entity = em.create<T>(entityType, {} as any);\n\t\treturn assign(entity, data, options, visited);\n\t}\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBASO;AACP,oBAAuB;AAEvB,sBAAkC;AAClC,sBAA6C;AActC,MAAM,SAAS,OACrB,QACA,MACA,SACA,UAAU,oBAAI,IAAoB,GAClC,KAAK,kCAAkB,QAAQ,OAC3B;AACJ,MAAI,QAAQ,IAAI,MAAM,EAAG,QAAO;AAChC,UAAQ,IAAI,MAAM;AAGlB,QAAM,eAAW,kBAAK,QAAQ,IAAI,EAAE;AAEpC,aAAW,CAAC,UAAU,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AACrD,UAAM,sBAAsB,OAAO,QAAmB;AAItD,UAAM,mBAAoB,SAAS,WAAmB,QAAQ;AAI9D,QACC,kBAAkB,SAAS,0BAAc,gBACzC,kBAAkB,SAAS,0BAAc,aACxC;AACD,UAAI,CAAC,MAAM,QAAQ,KAAK;AACvB,cAAM,IAAI;AAAA,UACT,uEAAuE,QAAQ,cAAc,SAAS,IAAI;AAAA,QAC3G;AAGD,UAAI,CAAC,kBAAM,aAAqB,mBAAmB,GAAG;AACrD,cAAM,IAAI;AAAA,UACT,qDAAqD,QAAQ,c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B;AAAA,YAC/C,QAAS,qBAAsC,OAAO;AAAA,YACtD,YAAY,iBAAiB;AAAA,YAC7B,iBAAiB;AAAA,YACjB,MAAM;AAAA,YACN;AAAA,YACA;AAAA,YACA;AAAA,UACD,CAAC;AAED,UAAC,cAAsB,QAAQ,IAAI,sBAAU,OAAO,SAAS;AAAA,QAC9D;AAAA,MACD;AAAA,IACD,OAAO;AAEN,MAAC,OAAe,QAAQ,IAAI;AAAA,IAC7B;AAAA,EACD;AAEA,SAAO;AACR;AAEA,MAAM,uBAAuB,CAAyB;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,MAQM;AACL,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,SAAS,SAAS,UAAU;AAElC,MAAK,KAAa,eAAe,GAAG;AACnC,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,0CAA0C,KAAK;AAAA,UAC9C;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAEA,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,6BAA6B,KAAK;AAAA,UACjC;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAGA,WAAO,OAAO,QAAQ,MAAM,SAAS,OAAO;AAAA,EAC7C,OAAO;AACN,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,0CAA0C,KAAK;AAAA,UAC9C;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAGA,UAAMA,UAAS,GAAG,OAAU,YAAY,CAAC,CAAQ;AACjD,WAAO,OAAOA,SAAQ,MAAM,SAAS,OAAO;AAAA,EAC7C;AACD;",
6
6
  "names": ["entity"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exogee/graphweaver-mikroorm",
3
- "version": "2.17.2",
3
+ "version": "2.17.4",
4
4
  "description": "MikroORM backend for @exogee/graphweaver",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
@@ -19,22 +19,22 @@
19
19
  "dotenv": "16.4.7",
20
20
  "pluralize": "8.0.0",
21
21
  "reflect-metadata": "0.2.2",
22
- "@exogee/graphweaver": "2.17.2",
23
- "@exogee/graphweaver-server": "2.17.2",
24
- "@exogee/logger": "2.17.2"
22
+ "@exogee/logger": "2.17.4",
23
+ "@exogee/graphweaver-server": "2.17.4",
24
+ "@exogee/graphweaver": "2.17.4"
25
25
  },
26
26
  "peerDependencies": {
27
- "graphql": "16",
28
27
  "@mikro-orm/core": "6",
29
- "@mikro-orm/knex": "6"
28
+ "@mikro-orm/knex": "6",
29
+ "graphql": "16"
30
30
  },
31
31
  "devDependencies": {
32
- "@mikro-orm/core": "6.4.14",
33
- "@mikro-orm/knex": "6.4.14",
34
- "@mikro-orm/mssql": "6.4.14",
35
- "@mikro-orm/mysql": "6.4.14",
36
- "@mikro-orm/postgresql": "6.4.14",
37
- "@mikro-orm/sqlite": "6.4.14",
32
+ "@mikro-orm/core": "6.4.16",
33
+ "@mikro-orm/knex": "6.4.16",
34
+ "@mikro-orm/mssql": "6.4.16",
35
+ "@mikro-orm/mysql": "6.4.16",
36
+ "@mikro-orm/postgresql": "6.4.16",
37
+ "@mikro-orm/sqlite": "6.4.16",
38
38
  "@types/node": "22.13.14",
39
39
  "@types/pluralize": "0.0.33",
40
40
  "esbuild": "0.25.1",
@@ -45,11 +45,11 @@
45
45
  "vitest": "3.0.9"
46
46
  },
47
47
  "optionalDependencies": {
48
- "@mikro-orm/knex": "^6.4.14",
49
- "@mikro-orm/mssql": "^6.4.14",
50
- "@mikro-orm/mysql": "^6.4.14",
51
- "@mikro-orm/postgresql": "^6.4.14",
52
- "@mikro-orm/sqlite": "^6.4.14"
48
+ "@mikro-orm/knex": "^6.4.16",
49
+ "@mikro-orm/mssql": "^6.4.16",
50
+ "@mikro-orm/mysql": "^6.4.16",
51
+ "@mikro-orm/postgresql": "^6.4.16",
52
+ "@mikro-orm/sqlite": "^6.4.16"
53
53
  },
54
54
  "keywords": [
55
55
  "graphql",