@exogee/graphweaver-mikroorm 0.2.2 → 0.2.3
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.
- package/lib/base-resolver/assign.js +1 -1
- package/lib/base-resolver/assign.js.map +2 -2
- package/lib/introspection/files/database-file.js +1 -0
- package/lib/introspection/files/database-file.js.map +2 -2
- package/lib/introspection/generate.js +22 -4
- package/lib/introspection/generate.js.map +2 -2
- package/package.json +14 -14
|
@@ -77,7 +77,7 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
|
|
|
77
77
|
visitedEntities.add(newEntity);
|
|
78
78
|
}
|
|
79
79
|
entityPropertyValue.remove(
|
|
80
|
-
|
|
80
|
+
entityPropertyValue.getItems().filter((entity2) => !visitedEntities.has(entity2))
|
|
81
81
|
);
|
|
82
82
|
} else if (propertyMetadata?.reference == import_core.ReferenceType.MANY_TO_ONE || propertyMetadata?.reference === import_core.ReferenceType.ONE_TO_ONE) {
|
|
83
83
|
if (value === null) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base-resolver/assign.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tAnyEntity,\n\tCollection,\n\tEntityData,\n\tEntityManager,\n\tEntityProperty,\n\tReference,\n\tReferenceType,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\nimport { logger } from '@exogee/logger';\n\nimport { ConnectionManager } from '../database';\n\n// This is how Mikro ORM does it within their own code, so in this file we're ok with non-null assertions.\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\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 as any)[property];\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?.reference === ReferenceType.MANY_TO_MANY ||\n\t\t\tpropertyMetadata?.reference === ReferenceType.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 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.id) {\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.getUnitOfWork().getById(propertyMetadata.type, subvalue.id);\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\tif (Object.keys(subvalue).length === 1) {\n\t\t\t\t\t\t\t// It's just the ID.\n\t\t\t\t\t\t\tentity = em.getReference(propertyMetadata.type, subvalue.id) 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.id}, 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(propertyMetadata.type, {\n\t\t\t\t\t\t\t\t\tid: subvalue.id,\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\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\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tAnyEntity,\n\tCollection,\n\tEntityData,\n\tEntityManager,\n\tEntityProperty,\n\tFilterQuery,\n\tReference,\n\tReferenceType,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\nimport { logger } from '@exogee/logger';\n\nimport { ConnectionManager } from '../database';\n\n// This is how Mikro ORM does it within their own code, so in this file we're ok with non-null assertions.\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\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 as any)[property];\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?.reference === ReferenceType.MANY_TO_MANY ||\n\t\t\tpropertyMetadata?.reference === ReferenceType.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 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.id) {\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.getUnitOfWork().getById(propertyMetadata.type, subvalue.id);\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\tif (Object.keys(subvalue).length === 1) {\n\t\t\t\t\t\t\t// It's just the ID.\n\t\t\t\t\t\t\tentity = em.getReference(propertyMetadata.type, subvalue.id) 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.id}, 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(propertyMetadata.type, {\n\t\t\t\t\t\t\t\t\tid: subvalue.id,\n\t\t\t\t\t\t\t\t} as FilterQuery<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\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?.reference == ReferenceType.MANY_TO_ONE ||\n\t\t\tpropertyMetadata?.reference === ReferenceType.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\tif (valueKeys.length === 1 && valueKeys[0] === 'id') {\n\t\t\t\t\t// Ok, this is just the ID, set the reference and move on.\n\t\t\t\t\t(entity as any)[property] = em.getReference(propertyMetadata.type, (value as any).id);\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 (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?.unwrap() as T,\n\t\t\t\t\t\tentityType: propertyMetadata.type,\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(entity 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\tdata,\n\toptions,\n\tvisited,\n\tem,\n}: {\n\tentity?: T;\n\tentityType: 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).id) {\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,kBAWO;AACP,oBAAuB;AAEvB,sBAAkC;AAiB3B,MAAM,SAAS,OACrB,QACA,MACA,SACA,UAAU,oBAAI,IAAoB,GAClC,KAAK,kCAA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AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,MAOM;AACL,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,SAAS,SAAS,UAAU;AAElC,MAAK,KAAa,IAAI;AACrB,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,0CAA0C,KAAK;AAAA,UAC9C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,6BAA6B,KAAK;AAAA,UACjC;AAAA,QACD;AAAA,MACD;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;AAAA,MACD;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
|
}
|
|
@@ -54,6 +54,7 @@ class DatabaseFile {
|
|
|
54
54
|
);
|
|
55
55
|
connection.push(`${pad}${pad}dbName: '${config.dbName}',`);
|
|
56
56
|
if (!isSQLite) {
|
|
57
|
+
connection.push(`${pad}${pad}host: '${config.host}',`);
|
|
57
58
|
connection.push(`${pad}${pad}user: '${config.user}',`);
|
|
58
59
|
connection.push(`${pad}${pad}password: '${config.password}',`);
|
|
59
60
|
connection.push(`${pad}${pad}port: ${config.port},`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/introspection/files/database-file.ts"],
|
|
4
|
-
"sourcesContent": ["import { Options } from '@mikro-orm/core';\nimport { ConnectionOptions, DatabaseType } from '../../database';\n\nexport class DatabaseFile {\n\tconstructor(\n\t\tprotected readonly databaseType: DatabaseType,\n\t\tprotected readonly connection: ConnectionOptions\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'database.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst isPostgresql = this.databaseType === 'postgresql';\n\t\tconst isMySQL = this.databaseType === 'mysql';\n\t\tconst isSQLite = this.databaseType === 'sqlite';\n\t\tconst imports = [\n\t\t\t...(isPostgresql ? [`import { PostgreSqlDriver } from '@mikro-orm/postgresql';`] : []),\n\t\t\t...(isMySQL ? [`import { MySqlDriver } from '@mikro-orm/mysql';`] : []),\n\t\t\t...(isSQLite ? [`import { SqliteDriver } from '@mikro-orm/sqlite';`] : []),\n\t\t\t`import { entities } from './entities';`,\n\t\t];\n\t\tconst exports = [`export const connections = [connection];`];\n\n\t\tconst pad = '\\t';\n\n\t\tconst config = this.connection.mikroOrmConfig as Options;\n\n\t\tconst connection = [`export const connection = {`];\n\t\tconnection.push(`${pad}connectionManagerId: '${this.databaseType}',`);\n\t\tconnection.push(`${pad}mikroOrmConfig: {`);\n\t\tconnection.push(`${pad}${pad}entities: entities,`);\n\t\tconnection.push(\n\t\t\t`${pad}${pad}driver: ${\n\t\t\t\tisPostgresql ? 'PostgreSqlDriver' : isMySQL ? 'MySqlDriver' : 'SqliteDriver'\n\t\t\t},`\n\t\t);\n\t\tconnection.push(`${pad}${pad}dbName: '${config.dbName}',`);\n\t\tif (!isSQLite) {\n\t\t\tconnection.push(`${pad}${pad}user: '${config.user}',`);\n\t\t\tconnection.push(`${pad}${pad}password: '${config.password}',`);\n\t\t\tconnection.push(`${pad}${pad}port: ${config.port},`);\n\t\t}\n\t\tconnection.push(`${pad}},`);\n\t\tconnection.push(`};`);\n\n\t\treturn `${imports.join('\\n')}\\n\\n${connection.join('\\n')}\\n\\n${exports.join('\\n')}\\n`;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAA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orm/core';\nimport { ConnectionOptions, DatabaseType } from '../../database';\n\nexport class DatabaseFile {\n\tconstructor(\n\t\tprotected readonly databaseType: DatabaseType,\n\t\tprotected readonly connection: ConnectionOptions\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'database.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst isPostgresql = this.databaseType === 'postgresql';\n\t\tconst isMySQL = this.databaseType === 'mysql';\n\t\tconst isSQLite = this.databaseType === 'sqlite';\n\t\tconst imports = [\n\t\t\t...(isPostgresql ? [`import { PostgreSqlDriver } from '@mikro-orm/postgresql';`] : []),\n\t\t\t...(isMySQL ? [`import { MySqlDriver } from '@mikro-orm/mysql';`] : []),\n\t\t\t...(isSQLite ? [`import { SqliteDriver } from '@mikro-orm/sqlite';`] : []),\n\t\t\t`import { entities } from './entities';`,\n\t\t];\n\t\tconst exports = [`export const connections = [connection];`];\n\n\t\tconst pad = '\\t';\n\n\t\tconst config = this.connection.mikroOrmConfig as Options;\n\n\t\tconst connection = [`export const connection = {`];\n\t\tconnection.push(`${pad}connectionManagerId: '${this.databaseType}',`);\n\t\tconnection.push(`${pad}mikroOrmConfig: {`);\n\t\tconnection.push(`${pad}${pad}entities: entities,`);\n\t\tconnection.push(\n\t\t\t`${pad}${pad}driver: ${\n\t\t\t\tisPostgresql ? 'PostgreSqlDriver' : isMySQL ? 'MySqlDriver' : 'SqliteDriver'\n\t\t\t},`\n\t\t);\n\t\tconnection.push(`${pad}${pad}dbName: '${config.dbName}',`);\n\t\tif (!isSQLite) {\n\t\t\tconnection.push(`${pad}${pad}host: '${config.host}',`);\n\t\t\tconnection.push(`${pad}${pad}user: '${config.user}',`);\n\t\t\tconnection.push(`${pad}${pad}password: '${config.password}',`);\n\t\t\tconnection.push(`${pad}${pad}port: ${config.port},`);\n\t\t}\n\t\tconnection.push(`${pad}},`);\n\t\tconnection.push(`};`);\n\n\t\treturn `${imports.join('\\n')}\\n\\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AK,IAAI;AAEpB,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ,WAAW,KAAK,IAAI;AAAA;AAAA,EAAQ,QAAQ,KAAK,IAAI;AAAA;AAAA,EACjF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -179,12 +179,23 @@ const generate = async (databaseType, options) => {
|
|
|
179
179
|
console.log("Building metadata...");
|
|
180
180
|
const metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);
|
|
181
181
|
const source = [];
|
|
182
|
+
const summaryOfEntities = [];
|
|
182
183
|
for (const meta of metadata) {
|
|
183
184
|
if (!meta.pivotTable) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
const dataEntityFile = new import_files.DataEntityFile(meta, namingStrategy, platform, databaseType);
|
|
186
|
+
const schemaEntityFile = new import_files.SchemaEntityFile(meta, namingStrategy, platform);
|
|
187
|
+
const schemaIndexFile = new import_files.SchemaEntityIndexFile(meta, namingStrategy, platform);
|
|
188
|
+
const schemaResolverFile = new import_files.SchemaResolverFile(meta, namingStrategy, platform);
|
|
189
|
+
source.push(dataEntityFile, schemaEntityFile, schemaIndexFile, schemaResolverFile);
|
|
190
|
+
summaryOfEntities.push({
|
|
191
|
+
name: meta.className,
|
|
192
|
+
entityFilePath: `${dataEntityFile.getBasePath()}${dataEntityFile.getBaseName()}`,
|
|
193
|
+
schemaFilePath: `${schemaIndexFile.getBasePath()}: ${[
|
|
194
|
+
schemaIndexFile.getBaseName(),
|
|
195
|
+
schemaEntityFile.getBaseName(),
|
|
196
|
+
schemaResolverFile.getBaseName()
|
|
197
|
+
].join(", ")}`
|
|
198
|
+
});
|
|
188
199
|
}
|
|
189
200
|
}
|
|
190
201
|
source.push(new import_files.DataEntityIndexFile(metadata, databaseType));
|
|
@@ -197,6 +208,13 @@ const generate = async (databaseType, options) => {
|
|
|
197
208
|
contents: file.generate()
|
|
198
209
|
}));
|
|
199
210
|
await closeConnection();
|
|
211
|
+
console.log("\nImport Summary:");
|
|
212
|
+
console.table(summaryOfEntities);
|
|
213
|
+
console.log(
|
|
214
|
+
`
|
|
215
|
+
Imported ${summaryOfEntities.length} entities, creating the above files in your Graphweaver project.
|
|
216
|
+
`
|
|
217
|
+
);
|
|
200
218
|
return files;
|
|
201
219
|
} catch (err) {
|
|
202
220
|
if (err instanceof IntrospectionError)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/introspection/generate.ts"],
|
|
4
|
-
"sourcesContent": ["import { DatabaseSchema, AbstractSqlPlatform } from '@mikro-orm/knex';\nimport {\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tReferenceType,\n\tUtils,\n} from '@mikro-orm/core';\nimport pluralize from 'pluralize';\n\nimport { ConnectionManager, ConnectionOptions, DatabaseType } from '../database';\nimport {\n\tDataEntityFile,\n\tDataEntityIndexFile,\n\tDataSourceIndexFile,\n\tSchemaEntityFile,\n\tSchemaIndexFile,\n\tSchemaResolverFile,\n\tSchemaEntityIndexFile,\n\tDatabaseFile,\n} from './files';\nimport { pascalToCamelCaseString } from './utils';\n\nconst CONNECTION_MANAGER_ID = 'generate';\n\nexport class IntrospectionError extends Error {\n\tprotected type: string;\n\tconstructor(protected title = '', message = '') {\n\t\tsuper(message);\n\t\tthis.type = 'IntrospectionError';\n\t\tthis.title = title;\n\t\tthis.message = message;\n\t}\n}\n\nconst hasErrorMessage = (error: any): error is { message: string } => error.message;\n\nconst generateBidirectionalRelations = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif (!prop.name.includes('Inverse')) {\n\t\t\t\tconst targetMeta = metadata.find((m) => m.className === prop.type);\n\t\t\t\tconst newProp = {\n\t\t\t\t\tname: prop.name + 'Inverse',\n\t\t\t\t\ttype: meta.className,\n\t\t\t\t\tjoinColumns: prop.fieldNames,\n\t\t\t\t\treferencedTableName: meta.tableName,\n\t\t\t\t\treferencedColumnNames: Utils.flatten(\n\t\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t\t),\n\t\t\t\t\tmappedBy: prop.name,\n\t\t\t\t} as EntityProperty;\n\n\t\t\t\t// Add reference to the inverse entity\n\t\t\t\tconst inverseMeta = metadata.find((m) => m.className === meta.className);\n\t\t\t\tconst inverseProp = inverseMeta?.props.find((p) => p.name === newProp.mappedBy);\n\t\t\t\tif (inverseProp) inverseProp.inversedBy = newProp.name;\n\n\t\t\t\tif (prop.reference === ReferenceType.MANY_TO_ONE) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_MANY;\n\t\t\t\t} else if (prop.reference === ReferenceType.ONE_TO_ONE && !prop.mappedBy) {\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_ONE;\n\t\t\t\t\tnewProp.nullable = true;\n\t\t\t\t} else if (prop.reference === ReferenceType.MANY_TO_MANY && !prop.mappedBy) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.MANY_TO_MANY;\n\t\t\t\t} else {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttargetMeta?.addProperty(newProp);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[], namingStrategy: NamingStrategy) => {\n\tfor (const meta of metadata) {\n\t\tif (\n\t\t\tmeta.compositePK && // needs to have composite PK\n\t\t\tmeta.primaryKeys.length === meta.relations.length && // all relations are PKs\n\t\t\tmeta.relations.length === 2 && // there are exactly two relation properties\n\t\t\tmeta.relations.length === meta.props.length && // all properties are relations\n\t\t\tmeta.relations.every((prop) => prop.reference === ReferenceType.MANY_TO_ONE) // all relations are m:1\n\t\t) {\n\t\t\tmeta.pivotTable = true;\n\t\t\tconst owner = metadata.find((m) => m.className === meta.relations[0].type);\n\t\t\tif (!owner) throw new Error('No Owner');\n\t\t\tconst name = pascalToCamelCaseString(meta.relations?.[1]?.type);\n\t\t\towner.addProperty({\n\t\t\t\tname: pluralize(name),\n\t\t\t\treference: ReferenceType.MANY_TO_MANY,\n\t\t\t\tpivotTable: meta.tableName,\n\t\t\t\ttype: meta.relations[1].type,\n\t\t\t\tjoinColumns: meta.relations[0].fieldNames,\n\t\t\t\tinverseJoinColumns: meta.relations[1].fieldNames,\n\t\t\t} as EntityProperty);\n\t\t}\n\t}\n};\n\nconst generateIdentifiedReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif ([ReferenceType.MANY_TO_ONE, ReferenceType.ONE_TO_ONE].includes(prop.reference)) {\n\t\t\t\tconst name = pascalToCamelCaseString(prop.type);\n\t\t\t\tprop.name = pluralize.singular(name);\n\t\t\t\tprop.wrappedReference = true;\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst generateSingularTypeReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tmeta.className = pluralize.singular(meta.className);\n\t\tfor (const prop of meta.relations) {\n\t\t\tprop.type = pluralize.singular(prop.type);\n\t\t}\n\t}\n};\n\n// Convert properties like FirstName to firstName\nconst convertToCamelCasePropertyNames = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tconst props = Object.values(meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tprop.name = pascalToCamelCaseString(prop.name);\n\t\t});\n\t}\n};\n\nconst convertSchemaToMetadata = async (\n\tschema: DatabaseSchema,\n\tplatform: AbstractSqlPlatform,\n\tnamingStrategy: NamingStrategy\n) => {\n\tconst helper = platform.getSchemaHelper();\n\n\tif (!helper) throw new Error('cannot connect to database');\n\n\tconst metadata = schema\n\t\t.getTables()\n\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\t.map((table) => table.getEntityDeclaration(namingStrategy, helper));\n\n\tif (metadata.length === 0) {\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: No tables found, this database is empty.`,\n\t\t\t`Make sure you have tables in this database and then try again.`\n\t\t);\n\t}\n\n\tconvertToCamelCasePropertyNames(metadata);\n\tdetectManyToManyRelations(metadata, namingStrategy);\n\tgenerateIdentifiedReferences(metadata);\n\tgenerateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn metadata;\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\ttype,\n\t\t\t...options.mikroOrmConfig,\n\t\t},\n\t});\n};\n\nconst closeConnection = async () => {\n\tconsole.log('Closing database connection...');\n\tawait ConnectionManager.close(CONNECTION_MANAGER_ID);\n\tconsole.log('Database connection closed.');\n};\n\ntype File =\n\t| DataEntityFile\n\t| SchemaEntityFile\n\t| SchemaEntityIndexFile\n\t| SchemaIndexFile\n\t| SchemaResolverFile\n\t| DataEntityIndexFile\n\t| DataSourceIndexFile\n\t| DatabaseFile;\n\nexport const generate = async (databaseType: DatabaseType, options: ConnectionOptions) => {\n\ttry {\n\t\tawait openConnection(databaseType, options);\n\n\t\tconst database = ConnectionManager.database(CONNECTION_MANAGER_ID);\n\t\tif (!database)\n\t\t\tthrow new IntrospectionError(\n\t\t\t\t`Warning: Unable to connect to database.`,\n\t\t\t\t'Please check the connection settings and try again'\n\t\t\t);\n\n\t\tconst config = database.em.config;\n\t\tconst driver = database.em.getDriver();\n\t\tconst platform = driver.getPlatform();\n\t\tconst namingStrategy = config.getNamingStrategy();\n\t\tconst connection = driver.getConnection();\n\n\t\tconsole.log('Fetching database schema...');\n\t\tconst schema = await DatabaseSchema.create(connection, platform, config);\n\t\tconsole.log('Building metadata...');\n\t\tconst metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);\n\n\t\tconst source: File[] = [];\n\n\t\tfor (const meta of metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBASO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YAAsB,QAAQ,IAAI,UAAU,IAAI;AAC/C,UAAM,OAAO;AADQ;AAErB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAAqC;AAC5E,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD,eAAW,QAAQ,KAAK,WAAW;AAClC,UAAI,CAAC,KAAK,KAAK,SAAS,SAAS,GAAG;AACnC,cAAM,aAAa,SAAS,KAAK,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI;AACjE,cAAM,UAAU;AAAA,UACf,MAAM,KAAK,OAAO;AAAA,UAClB,MAAM,KAAK;AAAA,UACX,aAAa,KAAK;AAAA,UAClB,qBAAqB,KAAK;AAAA,UAC1B,uBAAuB,kBAAM;AAAA,aAC3B,YAAY,gBAAgB,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,UAAU;AAAA,UAChE;AAAA,UACA,UAAU,KAAK;AAAA,QAChB;AAGA,cAAM,cAAc,SAAS,KAAK,CAAC,MAAM,EAAE,cAAc,KAAK,SAAS;AACvE,cAAM,cAAc,aAAa,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,QA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,\n} from '@mikro-orm/core';\nimport pluralize from 'pluralize';\n\nimport { ConnectionManager, ConnectionOptions, DatabaseType } from '../database';\nimport {\n\tDataEntityFile,\n\tDataEntityIndexFile,\n\tDataSourceIndexFile,\n\tSchemaEntityFile,\n\tSchemaIndexFile,\n\tSchemaResolverFile,\n\tSchemaEntityIndexFile,\n\tDatabaseFile,\n} from './files';\nimport { pascalToCamelCaseString } from './utils';\n\nconst CONNECTION_MANAGER_ID = 'generate';\n\nexport class IntrospectionError extends Error {\n\tprotected type: string;\n\tconstructor(protected title = '', message = '') {\n\t\tsuper(message);\n\t\tthis.type = 'IntrospectionError';\n\t\tthis.title = title;\n\t\tthis.message = message;\n\t}\n}\n\nconst hasErrorMessage = (error: any): error is { message: string } => error.message;\n\nconst generateBidirectionalRelations = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif (!prop.name.includes('Inverse')) {\n\t\t\t\tconst targetMeta = metadata.find((m) => m.className === prop.type);\n\t\t\t\tconst newProp = {\n\t\t\t\t\tname: prop.name + 'Inverse',\n\t\t\t\t\ttype: meta.className,\n\t\t\t\t\tjoinColumns: prop.fieldNames,\n\t\t\t\t\treferencedTableName: meta.tableName,\n\t\t\t\t\treferencedColumnNames: Utils.flatten(\n\t\t\t\t\t\t(targetMeta?.getPrimaryProps() ?? []).map((pk) => pk.fieldNames)\n\t\t\t\t\t),\n\t\t\t\t\tmappedBy: prop.name,\n\t\t\t\t} as EntityProperty;\n\n\t\t\t\t// Add reference to the inverse entity\n\t\t\t\tconst inverseMeta = metadata.find((m) => m.className === meta.className);\n\t\t\t\tconst inverseProp = inverseMeta?.props.find((p) => p.name === newProp.mappedBy);\n\t\t\t\tif (inverseProp) inverseProp.inversedBy = newProp.name;\n\n\t\t\t\tif (prop.reference === ReferenceType.MANY_TO_ONE) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_MANY;\n\t\t\t\t} else if (prop.reference === ReferenceType.ONE_TO_ONE && !prop.mappedBy) {\n\t\t\t\t\tnewProp.reference = ReferenceType.ONE_TO_ONE;\n\t\t\t\t\tnewProp.nullable = true;\n\t\t\t\t} else if (prop.reference === ReferenceType.MANY_TO_MANY && !prop.mappedBy) {\n\t\t\t\t\tconst name = pascalToCamelCaseString(meta.tableName);\n\t\t\t\t\tnewProp.name = pluralize(name);\n\t\t\t\t\tnewProp.reference = ReferenceType.MANY_TO_MANY;\n\t\t\t\t} else {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttargetMeta?.addProperty(newProp);\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst detectManyToManyRelations = (metadata: EntityMetadata[], namingStrategy: NamingStrategy) => {\n\tfor (const meta of metadata) {\n\t\tif (\n\t\t\tmeta.compositePK && // needs to have composite PK\n\t\t\tmeta.primaryKeys.length === meta.relations.length && // all relations are PKs\n\t\t\tmeta.relations.length === 2 && // there are exactly two relation properties\n\t\t\tmeta.relations.length === meta.props.length && // all properties are relations\n\t\t\tmeta.relations.every((prop) => prop.reference === ReferenceType.MANY_TO_ONE) // all relations are m:1\n\t\t) {\n\t\t\tmeta.pivotTable = true;\n\t\t\tconst owner = metadata.find((m) => m.className === meta.relations[0].type);\n\t\t\tif (!owner) throw new Error('No Owner');\n\t\t\tconst name = pascalToCamelCaseString(meta.relations?.[1]?.type);\n\t\t\towner.addProperty({\n\t\t\t\tname: pluralize(name),\n\t\t\t\treference: ReferenceType.MANY_TO_MANY,\n\t\t\t\tpivotTable: meta.tableName,\n\t\t\t\ttype: meta.relations[1].type,\n\t\t\t\tjoinColumns: meta.relations[0].fieldNames,\n\t\t\t\tinverseJoinColumns: meta.relations[1].fieldNames,\n\t\t\t} as EntityProperty);\n\t\t}\n\t}\n};\n\nconst generateIdentifiedReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tfor (const prop of meta.relations) {\n\t\t\tif ([ReferenceType.MANY_TO_ONE, ReferenceType.ONE_TO_ONE].includes(prop.reference)) {\n\t\t\t\tconst name = pascalToCamelCaseString(prop.type);\n\t\t\t\tprop.name = pluralize.singular(name);\n\t\t\t\tprop.wrappedReference = true;\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst generateSingularTypeReferences = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tmeta.className = pluralize.singular(meta.className);\n\t\tfor (const prop of meta.relations) {\n\t\t\tprop.type = pluralize.singular(prop.type);\n\t\t}\n\t}\n};\n\n// Convert properties like FirstName to firstName\nconst convertToCamelCasePropertyNames = (metadata: EntityMetadata[]): void => {\n\tfor (const meta of metadata.filter((m) => !m.pivotTable)) {\n\t\tconst props = Object.values(meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tprop.name = pascalToCamelCaseString(prop.name);\n\t\t});\n\t}\n};\n\nconst convertSchemaToMetadata = async (\n\tschema: DatabaseSchema,\n\tplatform: AbstractSqlPlatform,\n\tnamingStrategy: NamingStrategy\n) => {\n\tconst helper = platform.getSchemaHelper();\n\n\tif (!helper) throw new Error('cannot connect to database');\n\n\tconst metadata = schema\n\t\t.getTables()\n\t\t.sort((a, b) => a.name.localeCompare(b.name))\n\t\t.map((table) => table.getEntityDeclaration(namingStrategy, helper));\n\n\tif (metadata.length === 0) {\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: No tables found, this database is empty.`,\n\t\t\t`Make sure you have tables in this database and then try again.`\n\t\t);\n\t}\n\n\tconvertToCamelCasePropertyNames(metadata);\n\tdetectManyToManyRelations(metadata, namingStrategy);\n\tgenerateIdentifiedReferences(metadata);\n\tgenerateBidirectionalRelations(metadata);\n\tgenerateSingularTypeReferences(metadata);\n\n\treturn metadata;\n};\n\nconst openConnection = async (type: DatabaseType, options: ConnectionOptions) => {\n\tawait ConnectionManager.connect(CONNECTION_MANAGER_ID, {\n\t\tmikroOrmConfig: {\n\t\t\ttype,\n\t\t\t...options.mikroOrmConfig,\n\t\t},\n\t});\n};\n\nconst closeConnection = async () => {\n\tconsole.log('Closing database connection...');\n\tawait ConnectionManager.close(CONNECTION_MANAGER_ID);\n\tconsole.log('Database connection closed.');\n};\n\ntype File =\n\t| DataEntityFile\n\t| SchemaEntityFile\n\t| SchemaEntityIndexFile\n\t| SchemaIndexFile\n\t| SchemaResolverFile\n\t| DataEntityIndexFile\n\t| DataSourceIndexFile\n\t| DatabaseFile;\n\nexport const generate = async (databaseType: DatabaseType, options: ConnectionOptions) => {\n\ttry {\n\t\tawait openConnection(databaseType, options);\n\n\t\tconst database = ConnectionManager.database(CONNECTION_MANAGER_ID);\n\t\tif (!database)\n\t\t\tthrow new IntrospectionError(\n\t\t\t\t`Warning: Unable to connect to database.`,\n\t\t\t\t'Please check the connection settings and try again'\n\t\t\t);\n\n\t\tconst config = database.em.config;\n\t\tconst driver = database.em.getDriver();\n\t\tconst platform = driver.getPlatform();\n\t\tconst namingStrategy = config.getNamingStrategy();\n\t\tconst connection = driver.getConnection();\n\n\t\tconsole.log('Fetching database schema...');\n\t\tconst schema = await DatabaseSchema.create(connection, platform, config);\n\t\tconsole.log('Building metadata...');\n\t\tconst metadata = await convertSchemaToMetadata(schema, platform, namingStrategy);\n\n\t\tconst source: File[] = [];\n\n\t\tconst summaryOfEntities: { name: string; entityFilePath: string; schemaFilePath: string }[] =\n\t\t\t[];\n\n\t\tfor (const meta of metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst dataEntityFile = new DataEntityFile(meta, namingStrategy, platform, databaseType);\n\t\t\t\tconst schemaEntityFile = new SchemaEntityFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaIndexFile = new SchemaEntityIndexFile(meta, namingStrategy, platform);\n\t\t\t\tconst schemaResolverFile = new SchemaResolverFile(meta, namingStrategy, platform);\n\t\t\t\tsource.push(dataEntityFile, schemaEntityFile, schemaIndexFile, schemaResolverFile);\n\t\t\t\tsummaryOfEntities.push({\n\t\t\t\t\tname: meta.className,\n\t\t\t\t\tentityFilePath: `${dataEntityFile.getBasePath()}${dataEntityFile.getBaseName()}`,\n\t\t\t\t\tschemaFilePath: `${schemaIndexFile.getBasePath()}: ${[\n\t\t\t\t\t\tschemaIndexFile.getBaseName(),\n\t\t\t\t\t\tschemaEntityFile.getBaseName(),\n\t\t\t\t\t\tschemaResolverFile.getBaseName(),\n\t\t\t\t\t].join(', ')}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Export all the entities from the data source directory\n\t\tsource.push(new DataEntityIndexFile(metadata, databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new DataSourceIndexFile(databaseType));\n\t\t// Export the data source from the entities directory\n\t\tsource.push(new SchemaIndexFile(metadata));\n\t\t// Export the database connection to its own file\n\t\tsource.push(new DatabaseFile(databaseType, options));\n\n\t\tconst files = source.map((file) => ({\n\t\t\tpath: file.getBasePath(),\n\t\t\tname: file.getBaseName(),\n\t\t\tcontents: file.generate(),\n\t\t}));\n\n\t\tawait closeConnection();\n\n\t\tconsole.log('\\nImport Summary:');\n\t\tconsole.table(summaryOfEntities);\n\t\tconsole.log(\n\t\t\t`\\nImported ${summaryOfEntities.length} entities, creating the above files in your Graphweaver project. \\n`\n\t\t);\n\n\t\treturn files;\n\t} catch (err) {\n\t\tif (err instanceof IntrospectionError) throw err;\n\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: Unable to connect to database.`,\n\t\t\thasErrorMessage(err) ? err.message : 'Please check the connection settings and try again'\n\t\t);\n\t}\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBASO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,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BAAmB,YAAY;AAAA,UAChC,EAAE,KAAK,IAAI;AAAA,QACZ,CAAC;AAAA,MACF;AAAA,IACD;AAGA,WAAO,KAAK,IAAI,iCAAoB,UAAU,YAAY,CAAC;AAE3D,WAAO,KAAK,IAAI,iCAAoB,YAAY,CAAC;AAEjD,WAAO,KAAK,IAAI,6BAAgB,QAAQ,CAAC;AAEzC,WAAO,KAAK,IAAI,0BAAa,cAAc,OAAO,CAAC;AAEnD,UAAM,QAAQ,OAAO,IAAI,CAAC,UAAU;AAAA,MACnC,MAAM,KAAK,YAAY;AAAA,MACvB,MAAM,KAAK,YAAY;AAAA,MACvB,UAAU,KAAK,SAAS;AAAA,IACzB,EAAE;AAEF,UAAM,gBAAgB;AAEtB,YAAQ,IAAI,mBAAmB;AAC/B,YAAQ,MAAM,iBAAiB;AAC/B,YAAQ;AAAA,MACP;AAAA,WAAc,kBAAkB;AAAA;AAAA,IACjC;AAEA,WAAO;AAAA,EACR,SAAS,KAAP;AACD,QAAI,eAAe;AAAoB,YAAM;AAE7C,UAAM,IAAI;AAAA,MACT;AAAA,MACA,gBAAgB,GAAG,IAAI,IAAI,UAAU;AAAA,IACtC;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["pluralize"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exogee/graphweaver-mikroorm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "MikroORM backend for @exogee/graphweaver",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"graphql": "16.6.0",
|
|
20
20
|
"reflect-metadata": "0.1.13",
|
|
21
21
|
"pluralize": "8.0.0",
|
|
22
|
-
"@exogee/graphweaver": "0.2.
|
|
23
|
-
"@exogee/logger": "0.2.
|
|
22
|
+
"@exogee/graphweaver": "0.2.3",
|
|
23
|
+
"@exogee/logger": "0.2.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@mikro-orm/core": "5.
|
|
27
|
-
"@mikro-orm/mysql": "5.
|
|
28
|
-
"@mikro-orm/postgresql": "5.
|
|
29
|
-
"@mikro-orm/sqlite": "5.
|
|
30
|
-
"@mikro-orm/knex": "5.
|
|
26
|
+
"@mikro-orm/core": "5.7.14",
|
|
27
|
+
"@mikro-orm/mysql": "5.7.14",
|
|
28
|
+
"@mikro-orm/postgresql": "5.7.14",
|
|
29
|
+
"@mikro-orm/sqlite": "5.7.14",
|
|
30
|
+
"@mikro-orm/knex": "5.7.14",
|
|
31
31
|
"@types/node": "18.11.11",
|
|
32
32
|
"@types/pluralize": "0.0.29",
|
|
33
33
|
"esbuild": "0.15.5",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"typescript": "5.0.2"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@mikro-orm/mysql": "5.
|
|
39
|
-
"@mikro-orm/postgresql": "5.
|
|
40
|
-
"@mikro-orm/sqlite": "5.
|
|
41
|
-
"@mikro-orm/knex": "5.
|
|
38
|
+
"@mikro-orm/mysql": "5.7.14",
|
|
39
|
+
"@mikro-orm/postgresql": "5.7.14",
|
|
40
|
+
"@mikro-orm/sqlite": "5.7.14",
|
|
41
|
+
"@mikro-orm/knex": "5.7.14"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@mikro-orm/core": "5.
|
|
45
|
-
"@mikro-orm/knex": "5.
|
|
44
|
+
"@mikro-orm/core": "5.7.14",
|
|
45
|
+
"@mikro-orm/knex": "5.7.14"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "npm run build:js && npm run build:types",
|