@exogee/graphweaver-mikroorm 0.2.0 → 0.2.2
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.
|
@@ -106,7 +106,7 @@ const generateIdentifiedReferences = (metadata) => {
|
|
|
106
106
|
for (const meta of metadata.filter((m) => !m.pivotTable)) {
|
|
107
107
|
for (const prop of meta.relations) {
|
|
108
108
|
if ([import_core.ReferenceType.MANY_TO_ONE, import_core.ReferenceType.ONE_TO_ONE].includes(prop.reference)) {
|
|
109
|
-
const name = (0, import_utils.pascalToCamelCaseString)(prop.
|
|
109
|
+
const name = (0, import_utils.pascalToCamelCaseString)(prop.type);
|
|
110
110
|
prop.name = import_pluralize.default.singular(name);
|
|
111
111
|
prop.wrappedReference = true;
|
|
112
112
|
}
|
|
@@ -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.
|
|
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,S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;AAEA,oBAAY,YAAY,OAAO;AAAA,MAChC;AAAA,IACD;AAAA,EACD;AACD;AAEA,MAAM,4BAA4B,CAAC,UAA4B,mBAAmC;AACjG,aAAW,QAAQ,UAAU;AAC5B,QACC,KAAK,eACL,KAAK,YAAY,WAAW,KAAK,UAAU,UAC3C,KAAK,UAAU,WAAW,KAC1B,KAAK,UAAU,WAAW,KAAK,MAAM,UACrC,KAAK,UAAU,MAAM,CAAC,SAAS,KAAK,cAAc,0BAAc,WAAW,GAC1E;AACD,WAAK,aAAa;AAClB,YAAM,QAAQ,SAAS,KAAK,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,GAAG,IAAI;AACzE,UAAI,CAAC;AAAO,cAAM,IAAI,MAAM,UAAU;AACtC,YAAM,WAAO,sCAAwB,KAAK,YAAY,IAAI,IAAI;AAC9D,YAAM,YAAY;AAAA,QACjB,UAAM,iBAAAA,SAAU,IAAI;AAAA,QACpB,WAAW,0BAAc;AAAA,QACzB,YAAY,KAAK;AAAA,QACjB,MAAM,KAAK,UAAU,GAAG;AAAA,QACxB,aAAa,KAAK,UAAU,GAAG;AAAA,QAC/B,oBAAoB,KAAK,UAAU,GAAG;AAAA,MACvC,CAAmB;AAAA,IACpB;AAAA,EACD;AACD;AAEA,MAAM,+BAA+B,CAAC,aAAqC;AAC1E,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD,eAAW,QAAQ,KAAK,WAAW;AAClC,UAAI,CAAC,0BAAc,aAAa,0BAAc,UAAU,EAAE,SAAS,KAAK,SAAS,GAAG;AACnF,cAAM,WAAO,sCAAwB,KAAK,
|
|
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\tsource.push(new DataEntityFile(meta, namingStrategy, platform, databaseType));\n\t\t\t\tsource.push(new SchemaEntityFile(meta, namingStrategy, platform));\n\t\t\t\tsource.push(new SchemaEntityIndexFile(meta, namingStrategy, platform));\n\t\t\t\tsource.push(new SchemaResolverFile(meta, namingStrategy, platform));\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\treturn files;\n\t} catch (err) {\n\t\tif (err instanceof IntrospectionError) throw err;\n\n\t\tthrow new IntrospectionError(\n\t\t\t`Warning: Unable to connect to database.`,\n\t\t\thasErrorMessage(err) ? err.message : 'Please check the connection settings and try again'\n\t\t);\n\t}\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAMO;AACP,uBAAsB;AAEtB,sBAAmE;AACnE,mBASO;AACP,mBAAwC;AAExC,MAAM,wBAAwB;AAEvB,MAAM,2BAA2B,MAAM;AAAA,EAE7C,YAAsB,QAAQ,IAAI,UAAU,IAAI;AAC/C,UAAM,OAAO;AADQ;AAErB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;AAEA,MAAM,kBAAkB,CAAC,UAA6C,MAAM;AAE5E,MAAM,iCAAiC,CAAC,aAAqC;AAC5E,aAAW,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACzD,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;AAA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C5B,UAAI,CAAC,KAAK,YAAY;AACrB,eAAO,KAAK,IAAI,4BAAe,MAAM,gBAAgB,UAAU,YAAY,CAAC;AAC5E,eAAO,KAAK,IAAI,8BAAiB,MAAM,gBAAgB,QAAQ,CAAC;AAChE,eAAO,KAAK,IAAI,mCAAsB,MAAM,gBAAgB,QAAQ,CAAC;AACrE,eAAO,KAAK,IAAI,gCAAmB,MAAM,gBAAgB,QAAQ,CAAC;AAAA,MACnE;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,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
|
}
|
|
@@ -22,16 +22,20 @@ __export(connect_to_database_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(connect_to_database_exports);
|
|
24
24
|
var import_database = require("../database");
|
|
25
|
+
const connectionIds = /* @__PURE__ */ new Set();
|
|
25
26
|
const connectToDatabase = (options) => {
|
|
26
27
|
return {
|
|
27
28
|
serverWillStart: async () => {
|
|
28
29
|
if (Array.isArray(options)) {
|
|
29
30
|
for (const option of options) {
|
|
30
|
-
if (option.connectionManagerId)
|
|
31
|
+
if (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {
|
|
32
|
+
connectionIds.add(option.connectionManagerId);
|
|
31
33
|
await import_database.ConnectionManager.connect(option.connectionManagerId, option);
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
36
|
} else {
|
|
34
|
-
if (options.connectionManagerId) {
|
|
37
|
+
if (options.connectionManagerId && !connectionIds.has(options.connectionManagerId)) {
|
|
38
|
+
connectionIds.add(options.connectionManagerId);
|
|
35
39
|
await import_database.ConnectionManager.connect(options.connectionManagerId, options);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/plugins/connect-to-database.ts"],
|
|
4
|
-
"sourcesContent": ["import { ApolloServerPlugin } from '@apollo/server';\nimport { ConnectionManager, ConnectionOptions } from '../database';\n\nexport const connectToDatabase = (\n\toptions: ConnectionOptions[] | ConnectionOptions\n): ApolloServerPlugin => {\n\treturn {\n\t\tserverWillStart: async () => {\n\t\t\tif (Array.isArray(options)) {\n\t\t\t\tfor (const option of options) {\n\t\t\t\t\tif (option.connectionManagerId)\n\t\t\t\t\t\tawait ConnectionManager.connect(option.connectionManagerId, option);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (options.connectionManagerId) {\n\t\t\t\t\tawait ConnectionManager.connect(options.connectionManagerId, options);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqD;
|
|
4
|
+
"sourcesContent": ["import { ApolloServerPlugin } from '@apollo/server';\nimport { ConnectionManager, ConnectionOptions } from '../database';\n\nconst connectionIds = new Set<string>();\n\nexport const connectToDatabase = (\n\toptions: ConnectionOptions[] | ConnectionOptions\n): ApolloServerPlugin => {\n\treturn {\n\t\tserverWillStart: async () => {\n\t\t\tif (Array.isArray(options)) {\n\t\t\t\tfor (const option of options) {\n\t\t\t\t\tif (option.connectionManagerId && !connectionIds.has(option.connectionManagerId)) {\n\t\t\t\t\t\tconnectionIds.add(option.connectionManagerId);\n\t\t\t\t\t\tawait ConnectionManager.connect(option.connectionManagerId, option);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (options.connectionManagerId && !connectionIds.has(options.connectionManagerId)) {\n\t\t\t\t\tconnectionIds.add(options.connectionManagerId);\n\t\t\t\t\tawait ConnectionManager.connect(options.connectionManagerId, options);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqD;AAErD,MAAM,gBAAgB,oBAAI,IAAY;AAE/B,MAAM,oBAAoB,CAChC,YACwB;AACxB,SAAO;AAAA,IACN,iBAAiB,YAAY;AAC5B,UAAI,MAAM,QAAQ,OAAO,GAAG;AAC3B,mBAAW,UAAU,SAAS;AAC7B,cAAI,OAAO,uBAAuB,CAAC,cAAc,IAAI,OAAO,mBAAmB,GAAG;AACjF,0BAAc,IAAI,OAAO,mBAAmB;AAC5C,kBAAM,kCAAkB,QAAQ,OAAO,qBAAqB,MAAM;AAAA,UACnE;AAAA,QACD;AAAA,MACD,OAAO;AACN,YAAI,QAAQ,uBAAuB,CAAC,cAAc,IAAI,QAAQ,mBAAmB,GAAG;AACnF,wBAAc,IAAI,QAAQ,mBAAmB;AAC7C,gBAAM,kCAAkB,QAAQ,QAAQ,qBAAqB,OAAO;AAAA,QACrE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
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.2",
|
|
4
4
|
"description": "MikroORM backend for @exogee/graphweaver",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
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.2",
|
|
23
|
+
"@exogee/logger": "0.2.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@mikro-orm/core": "5.4.2",
|