@exogee/graphweaver-mikroorm 2.21.2 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/database.d.ts +1 -2
- package/lib/database.js +24 -20
- package/lib/database.js.map +2 -2
- package/lib/introspection/files/schema-entity-file.d.ts +1 -0
- package/lib/introspection/files/schema-entity-file.js +8 -1
- package/lib/introspection/files/schema-entity-file.js.map +2 -2
- package/lib/introspection/schema-entity-file.test.d.ts +1 -0
- package/lib/introspection/schema-entity-file.test.js +151 -0
- package/lib/introspection/schema-entity-file.test.js.map +7 -0
- package/lib/provider/provider.d.ts +0 -1
- package/lib/provider/provider.js +1 -9
- package/lib/provider/provider.js.map +2 -2
- package/package.json +5 -5
package/lib/database.d.ts
CHANGED
|
@@ -19,8 +19,7 @@ export declare enum IsolationLevel {
|
|
|
19
19
|
export type Database = typeof DatabaseImplementation.prototype;
|
|
20
20
|
declare class DatabaseImplementation {
|
|
21
21
|
private cachedOrm?;
|
|
22
|
-
private
|
|
23
|
-
private transactionInProgressIsolationLevel?;
|
|
22
|
+
private readonly transactionalAsyncLocal;
|
|
24
23
|
private connectionOptions?;
|
|
25
24
|
get orm(): MikroORM<IDatabaseDriver<Connection>, import("@mikro-orm/core").EntityManager<IDatabaseDriver<Connection>>>;
|
|
26
25
|
get em(): EntityManager;
|
package/lib/database.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(database_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(database_exports);
|
|
35
35
|
var import_change_tracker = require("./utils/change-tracker");
|
|
36
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
36
37
|
var import_core = require("@mikro-orm/core");
|
|
37
38
|
var import_logger = require("@exogee/logger");
|
|
38
39
|
var IsolationLevel = /* @__PURE__ */ ((IsolationLevel2) => {
|
|
@@ -50,6 +51,9 @@ const NumericIsolationLevels = {
|
|
|
50
51
|
};
|
|
51
52
|
class DatabaseImplementation {
|
|
52
53
|
constructor() {
|
|
54
|
+
// Per-async-chain transactional em. This ensures we keep transactions isolated
|
|
55
|
+
// and they don't mingle.
|
|
56
|
+
this.transactionalAsyncLocal = new import_node_async_hooks.AsyncLocalStorage();
|
|
53
57
|
this.getEnvironmentOverrides = async (secretArn) => {
|
|
54
58
|
import_logger.logger.trace("Database::getEnvironmentOverrides() - Enter");
|
|
55
59
|
const secret = secretArn ?? process.env.DATABASE_SECRET_ARN;
|
|
@@ -173,46 +177,46 @@ class DatabaseImplementation {
|
|
|
173
177
|
return this.cachedOrm;
|
|
174
178
|
}
|
|
175
179
|
get em() {
|
|
176
|
-
|
|
180
|
+
const tx = this.transactionalAsyncLocal.getStore();
|
|
181
|
+
if (tx) return tx.em;
|
|
182
|
+
return this.orm.em;
|
|
177
183
|
}
|
|
178
|
-
async transactional(callback, isolationLevel = "READ
|
|
184
|
+
async transactional(callback, isolationLevel = "REPEATABLE READ" /* REPEATABLE_READ */) {
|
|
179
185
|
import_logger.logger.trace("Database::transactional() enter");
|
|
180
|
-
|
|
186
|
+
const current = this.transactionalAsyncLocal.getStore();
|
|
187
|
+
if (current && NumericIsolationLevels[current.isolationLevel] < NumericIsolationLevels[isolationLevel]) {
|
|
181
188
|
const error = new Error(
|
|
182
|
-
`Transaction in progress is ${
|
|
189
|
+
`Transaction in progress is ${current.isolationLevel} isolation level, but ${isolationLevel} was requested, which is more restrictive. Since we can't upgrade, this is an error.`
|
|
183
190
|
);
|
|
184
191
|
import_logger.logger.error(error);
|
|
185
192
|
throw error;
|
|
186
193
|
}
|
|
187
|
-
if (
|
|
194
|
+
if (current) {
|
|
188
195
|
import_logger.logger.trace(
|
|
189
196
|
"Transaction already in progress with sufficient isolation, proceeding without new transaction."
|
|
190
197
|
);
|
|
191
198
|
return callback();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
}
|
|
200
|
+
import_logger.logger.trace("Starting transaction");
|
|
201
|
+
return this.orm.em.transactional(async (emArg) => {
|
|
202
|
+
const em = emArg;
|
|
203
|
+
const driver = em.getDriver();
|
|
204
|
+
if (driver.constructor.name === "SqliteDriver") {
|
|
205
|
+
import_logger.logger.trace("All transactions in SQLite are SERIALIZABLE");
|
|
206
|
+
} else {
|
|
207
|
+
await em.execute(`SET SESSION TRANSACTION ISOLATION LEVEL ${isolationLevel}`);
|
|
208
|
+
}
|
|
209
|
+
return this.transactionalAsyncLocal.run({ em, isolationLevel }, async () => {
|
|
203
210
|
let result;
|
|
204
211
|
try {
|
|
205
212
|
result = await callback();
|
|
206
213
|
} catch (error) {
|
|
207
214
|
(0, import_logger.safeErrorLog)(import_logger.logger, error, "Error in transaction");
|
|
208
215
|
throw error;
|
|
209
|
-
} finally {
|
|
210
|
-
delete this.transactionalEm;
|
|
211
|
-
delete this.transactionInProgressIsolationLevel;
|
|
212
216
|
}
|
|
213
217
|
return result;
|
|
214
218
|
});
|
|
215
|
-
}
|
|
219
|
+
});
|
|
216
220
|
}
|
|
217
221
|
isolatedTest(test) {
|
|
218
222
|
return async () => {
|
package/lib/database.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/database.ts"],
|
|
4
|
-
"sourcesContent": ["import './utils/change-tracker';\n\nimport {\n\tAnyEntity,\n\tConnection,\n\tEntityName,\n\tIDatabaseDriver,\n\tMikroORM,\n\tOptions,\n\tReflectMetadataProvider,\n} from '@mikro-orm/core';\nimport { logger, safeErrorLog } from '@exogee/logger';\n\nimport type { EntityManager as PgEntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';\nimport type { EntityManager as MyEntityManager, MySqlDriver } from '@mikro-orm/mysql';\nimport type { EntityManager as SqliteEntityManager, SqliteDriver } from '@mikro-orm/sqlite';\ntype EntityManager =\n\t| PgEntityManager<PostgreSqlDriver>\n\t| MyEntityManager<MySqlDriver>\n\t| SqliteEntityManager<SqliteDriver>;\n\nexport type DatabaseType = 'mssql' | 'mysql' | 'postgresql' | 'sqlite';\n\nexport interface ConnectionOptions {\n\tmikroOrmConfig?: Options | (() => Options | Promise<Options>);\n\tsecretArn?: string;\n\tconnectionManagerId?: string;\n}\n\nexport enum IsolationLevel {\n\tSERIALIZABLE = 'SERIALIZABLE',\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\tREAD_COMMITTED = 'READ COMMITTED',\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n}\n\nconst NumericIsolationLevels = {\n\t[IsolationLevel.SERIALIZABLE]: 4,\n\t[IsolationLevel.REPEATABLE_READ]: 3,\n\t[IsolationLevel.READ_COMMITTED]: 2,\n\t[IsolationLevel.READ_UNCOMMITTED]: 1,\n};\n\nexport type Database = typeof DatabaseImplementation.prototype;\n\nclass DatabaseImplementation {\n\tprivate cachedOrm?: MikroORM<IDatabaseDriver<Connection>>;\n\tprivate transactionalEm?: EntityManager;\n\tprivate transactionInProgressIsolationLevel?: IsolationLevel;\n\tprivate connectionOptions?: ConnectionOptions;\n\n\tpublic get orm() {\n\t\tif (!this.cachedOrm) {\n\t\t\tconst error = new Error('Tried to get the ORM before it was connected.');\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn this.cachedOrm;\n\t}\n\n\tpublic get em() {\n\t\treturn this.transactionalEm || (this.orm.em as EntityManager);\n\t}\n\n\tpublic async transactional<T>(\n\t\tcallback: () => Promise<T>,\n\t\tisolationLevel: IsolationLevel = IsolationLevel.READ_COMMITTED\n\t) {\n\t\tlogger.trace('Database::transactional() enter');\n\n\t\tif (\n\t\t\tthis.transactionInProgressIsolationLevel &&\n\t\t\tNumericIsolationLevels[this.transactionInProgressIsolationLevel] <\n\t\t\t\tNumericIsolationLevels[isolationLevel]\n\t\t) {\n\t\t\tconst error = new Error(\n\t\t\t\t`Transaction in progress is ${this.transactionInProgressIsolationLevel} isolation level, but ${isolationLevel} was requested, which is more restrictive. Since we can't upgrade, this is an error.`\n\t\t\t);\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (this.transactionalEm) {\n\t\t\t// Transaction is already in progress that is isolated enough. Run the callback without starting a new one.\n\t\t\tlogger.trace(\n\t\t\t\t'Transaction already in progress with sufficient isolation, proceeding without new transaction.'\n\t\t\t);\n\n\t\t\treturn callback();\n\t\t} else {\n\t\t\t// Ok, start a new one.\n\t\t\tlogger.trace('Starting transaction');\n\n\t\t\treturn this.em.transactional(async (em) => {\n\t\t\t\tthis.transactionalEm = em;\n\t\t\t\tthis.transactionInProgressIsolationLevel = isolationLevel;\n\n\t\t\t\tconst driver = this.em.getDriver();\n\t\t\t\tif (driver.constructor.name === 'SqliteDriver') {\n\t\t\t\t\tlogger.trace('All transactions in SQLite are SERIALIZABLE');\n\t\t\t\t} else {\n\t\t\t\t\tawait em.execute(`SET SESSION TRANSACTION ISOLATION LEVEL ${isolationLevel}`);\n\t\t\t\t}\n\n\t\t\t\tlet result: T;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await callback();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tsafeErrorLog(logger, error, 'Error in transaction');\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tdelete this.transactionalEm;\n\t\t\t\t\tdelete this.transactionInProgressIsolationLevel;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic isolatedTest(test: () => any) {\n\t\treturn async () => {\n\t\t\ttry {\n\t\t\t\tawait this.transactional(async () => {\n\t\t\t\t\tawait test();\n\t\t\t\t\tthrow new Error('Rollback transaction for test');\n\t\t\t\t}, IsolationLevel.SERIALIZABLE);\n\t\t\t} catch (error) {\n\t\t\t\t// Only need to care if this isn't our rollback from above.\n\t\t\t\t// Otherwise just gobble it.\n\t\t\t\tif ((error as Error).message !== 'Rollback transaction for test') {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic get rawConnection() {\n\t\treturn this.em.getDriver().getConnection();\n\t}\n\n\tprivate getEnvironmentOverrides = async (secretArn?: string): Promise<Options> => {\n\t\tlogger.trace('Database::getEnvironmentOverrides() - Enter');\n\t\tconst secret = secretArn ?? process.env.DATABASE_SECRET_ARN;\n\t\tif (secret) {\n\t\t\tconst { SecretsManagerClient, GetSecretValueCommand } = await import(\n\t\t\t\t'@aws-sdk/client-secrets-manager'\n\t\t\t);\n\n\t\t\tif (!SecretsManagerClient || !GetSecretValueCommand) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'SecretsManagerClient or GetSecretValueCommand not found but a secret ARN was provided. Is @aws-sdk/client-secrets-manager available?'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst client = new SecretsManagerClient({\n\t\t\t\tregion: process.env.AWS_REGION,\n\t\t\t});\n\t\t\tconst command = new GetSecretValueCommand({ SecretId: secret });\n\n\t\t\ttry {\n\t\t\t\tlogger.trace('Fetching secret from Secrets Manager');\n\t\t\t\tconst response = await client.send(command);\n\t\t\t\tconst secret = JSON.parse(response.SecretString as string);\n\t\t\t\tlogger.trace('Secret fetched from Secrets Manager');\n\n\t\t\t\treturn {\n\t\t\t\t\thost: secret.host,\n\t\t\t\t\tport: secret.port,\n\t\t\t\t\tuser: secret.username,\n\t\t\t\t\tpassword: secret.password,\n\t\t\t\t\tdbName: secret.dbname,\n\t\t\t\t\tdriverOptions: {\n\t\t\t\t\t\tconnection: { ssl: true },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('Error fetching secret from Secrets Manager');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tlogger.trace('No secret ARN provided, using environment variables');\n\n\t\treturn {\n\t\t\thost: process.env.DATABASE_HOST,\n\t\t\tport: process.env.DATABASE_PORT ? Number(process.env.DATABASE_PORT) : undefined,\n\t\t\tuser: process.env.DATABASE_USERNAME,\n\t\t\tpassword: process.env.DATABASE_PASSWORD,\n\t\t\tdbName: process.env.DATABASE_NAME,\n\t\t};\n\t};\n\n\tprivate getConnectionInfo = async (connectionOptions?: ConnectionOptions): Promise<Options> => {\n\t\tlogger.trace('Database::getConnectionInfo() - Enter');\n\n\t\t// We have some defaults\n\t\tconst defaults: Options = {\n\t\t\thost: 'localhost',\n\t\t\tport: 5432,\n\t\t\tdbName: 'graphweaver',\n\t\t};\n\n\t\tconst resolvedMikroOrmConfig =\n\t\t\ttypeof connectionOptions?.mikroOrmConfig === 'function'\n\t\t\t\t? await connectionOptions.mikroOrmConfig()\n\t\t\t\t: connectionOptions?.mikroOrmConfig;\n\n\t\t// And finally we can override all of this with environment variables if needed.\n\t\tconst environmentOverrides = await this.getEnvironmentOverrides(connectionOptions?.secretArn);\n\n\t\t// Create a function we can use to filter out undefined values in the object.\n\t\tconst filterUndefined = (obj?: Options) => {\n\t\t\tif (!obj) return {};\n\n\t\t\tfor (const key of Object.keys(obj) as Array<keyof Options>) {\n\t\t\t\tif (obj[key] === undefined) delete obj[key];\n\t\t\t}\n\n\t\t\treturn obj;\n\t\t};\n\n\t\t// Apply each in order so the correct value wins.\n\t\treturn {\n\t\t\t...defaults,\n\t\t\t...filterUndefined(environmentOverrides),\n\t\t\t...filterUndefined(resolvedMikroOrmConfig),\n\t\t};\n\t};\n\n\tpublic getRepository = <T extends AnyEntity<T>>(entityName: EntityName<T>) =>\n\t\tthis.em.getRepository(entityName);\n\n\tpublic connect = async (connectionOptions?: ConnectionOptions) => {\n\t\tlogger.trace('Database::connect() - Enter');\n\t\tthis.connectionOptions = connectionOptions;\n\n\t\tif (this.cachedOrm) {\n\t\t\tlogger.trace('Returning cached ORM');\n\t\t\treturn this.cachedOrm;\n\t\t}\n\n\t\tlogger.trace('Creating new ORM');\n\t\tlogger.trace('Getting connection info');\n\n\t\tconst params = await this.getConnectionInfo(connectionOptions);\n\n\t\tlogger.trace('Initialising ORM');\n\n\t\tlogger.trace(`${params.entities?.length}x entities`);\n\n\t\t// Log the params, obfuscating the password used for the connection if there is one.\n\t\tconst { password, ...rest } = params;\n\t\tlogger.info(\n\t\t\t{ connectionParams: rest },\n\t\t\t'Connecting to database using MikroORM. Note: connectionParams have password removed for security.'\n\t\t);\n\n\t\tconst orm = await MikroORM.init({\n\t\t\tvalidateRequired: false, // Since v5, new entities are validated on runtime (just before executing insert queries), based on the entity metadata\n\t\t\tcontextName: connectionOptions?.connectionManagerId ?? 'default',\n\t\t\timplicitTransactions: false,\n\t\t\tmetadataProvider: ReflectMetadataProvider,\n\t\t\tdiscovery: {\n\t\t\t\tdisableDynamicFileAccess: true,\n\t\t\t\trequireEntitiesArray: false,\n\t\t\t\twarnWhenNoEntities: false,\n\t\t\t},\n\t\t\tallowGlobalContext: true,\n\n\t\t\t// Ensure we only ever create one connection to the database.\n\t\t\tpool: {\n\t\t\t\tmin: 1,\n\t\t\t\tmax: 1,\n\t\t\t},\n\t\t\t...params,\n\t\t});\n\n\t\tlogger.trace({ dbName: params.dbName, host: params.host }, 'Creating database connection');\n\t\tawait orm.connect();\n\n\t\tlogger.trace('Caching connection');\n\t\tthis.cachedOrm = orm;\n\t\treturn orm;\n\t};\n\n\tpublic close = async () => {\n\t\tlogger.trace('Closing database connection');\n\n\t\tawait this.orm.close(true);\n\t\tdelete this.cachedOrm;\n\t};\n}\n\nclass ConnectionsManager {\n\tprivate connections = new Map<string, DatabaseImplementation>();\n\tprivate connectionPromises = new Map<string, Promise<DatabaseImplementation>>();\n\n\tgetConnections() {\n\t\treturn Array.from(this.connections.values());\n\t}\n\n\tget default(): DatabaseImplementation {\n\t\tconst [defaultConnection] = [...this.connections];\n\t\tif (!defaultConnection)\n\t\t\tthrow new Error(\n\t\t\t\t'Error: No database connections. There should be at least one database connection.'\n\t\t\t);\n\t\tconst [_, databaseConnection] = defaultConnection;\n\t\treturn databaseConnection;\n\t}\n\n\tpublic connect = (id: string, connectionOptions: ConnectionOptions) => {\n\t\tif (this.connections.has(id)) return this.connections.get(id);\n\n\t\tconst connect = new Promise<DatabaseImplementation>((resolve, reject) => {\n\t\t\tconst database = new DatabaseImplementation();\n\t\t\tdatabase\n\t\t\t\t.connect(connectionOptions)\n\t\t\t\t.then(() => {\n\t\t\t\t\tlogger.trace(`Saving database connection with id \"${id}\".`);\n\t\t\t\t\tthis.connections.set(id, database);\n\t\t\t\t\tresolve(database);\n\t\t\t\t})\n\t\t\t\t.catch(reject);\n\t\t});\n\n\t\tthis.connectionPromises.set(id, connect);\n\n\t\treturn connect;\n\t};\n\n\tpublic database(id: string) {\n\t\treturn this.connections.get(id);\n\t}\n\n\tpublic awaitableDatabase(id: string) {\n\t\treturn this.connectionPromises.get(id);\n\t}\n\n\tpublic async close(id: string) {\n\t\tconst database = this.database(id);\n\t\tawait database?.close();\n\t\treturn true;\n\t}\n}\nexport const ConnectionManager = new ConnectionsManager();\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAO;AAEP,kBAQO;AACP,oBAAqC;AAkB9B,IAAK,iBAAL,kBAAKA,oBAAL;AACN,EAAAA,gBAAA,kBAAe;AACf,EAAAA,gBAAA,qBAAkB;AAClB,EAAAA,gBAAA,oBAAiB;AACjB,EAAAA,gBAAA,sBAAmB;AAJR,SAAAA;AAAA,GAAA;AAOZ,MAAM,yBAAyB;AAAA,EAC9B,CAAC,iCAA2B,GAAG;AAAA,EAC/B,CAAC,uCAA8B,GAAG;AAAA,EAClC,CAAC,qCAA6B,GAAG;AAAA,EACjC,CAAC,yCAA+B,GAAG;AACpC;
|
|
4
|
+
"sourcesContent": ["import './utils/change-tracker';\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport {\n\tAnyEntity,\n\tConnection,\n\tEntityName,\n\tIDatabaseDriver,\n\tMikroORM,\n\tOptions,\n\tReflectMetadataProvider,\n} from '@mikro-orm/core';\nimport { logger, safeErrorLog } from '@exogee/logger';\n\nimport type { EntityManager as PgEntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';\nimport type { EntityManager as MyEntityManager, MySqlDriver } from '@mikro-orm/mysql';\nimport type { EntityManager as SqliteEntityManager, SqliteDriver } from '@mikro-orm/sqlite';\ntype EntityManager =\n\t| PgEntityManager<PostgreSqlDriver>\n\t| MyEntityManager<MySqlDriver>\n\t| SqliteEntityManager<SqliteDriver>;\n\nexport type DatabaseType = 'mssql' | 'mysql' | 'postgresql' | 'sqlite';\n\nexport interface ConnectionOptions {\n\tmikroOrmConfig?: Options | (() => Options | Promise<Options>);\n\tsecretArn?: string;\n\tconnectionManagerId?: string;\n}\n\nexport enum IsolationLevel {\n\tSERIALIZABLE = 'SERIALIZABLE',\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\tREAD_COMMITTED = 'READ COMMITTED',\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n}\n\nconst NumericIsolationLevels = {\n\t[IsolationLevel.SERIALIZABLE]: 4,\n\t[IsolationLevel.REPEATABLE_READ]: 3,\n\t[IsolationLevel.READ_COMMITTED]: 2,\n\t[IsolationLevel.READ_UNCOMMITTED]: 1,\n};\n\nexport type Database = typeof DatabaseImplementation.prototype;\n\ntype TransactionalAsyncStore = {\n\tem: EntityManager;\n\tisolationLevel: IsolationLevel;\n};\n\nclass DatabaseImplementation {\n\tprivate cachedOrm?: MikroORM<IDatabaseDriver<Connection>>;\n\t// Per-async-chain transactional em. This ensures we keep transactions isolated\n\t// and they don't mingle.\n\tprivate readonly transactionalAsyncLocal = new AsyncLocalStorage<TransactionalAsyncStore>();\n\tprivate connectionOptions?: ConnectionOptions;\n\n\tpublic get orm() {\n\t\tif (!this.cachedOrm) {\n\t\t\tconst error = new Error('Tried to get the ORM before it was connected.');\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn this.cachedOrm;\n\t}\n\n\tpublic get em() {\n\t\tconst tx = this.transactionalAsyncLocal.getStore();\n\t\tif (tx) return tx.em;\n\t\treturn this.orm.em as EntityManager;\n\t}\n\n\tpublic async transactional<T>(\n\t\tcallback: () => Promise<T>,\n\t\tisolationLevel: IsolationLevel = IsolationLevel.REPEATABLE_READ\n\t) {\n\t\tlogger.trace('Database::transactional() enter');\n\n\t\tconst current = this.transactionalAsyncLocal.getStore();\n\n\t\tif (\n\t\t\tcurrent &&\n\t\t\tNumericIsolationLevels[current.isolationLevel] < NumericIsolationLevels[isolationLevel]\n\t\t) {\n\t\t\tconst error = new Error(\n\t\t\t\t`Transaction in progress is ${current.isolationLevel} isolation level, but ${isolationLevel} was requested, which is more restrictive. Since we can't upgrade, this is an error.`\n\t\t\t);\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (current) {\n\t\t\t// Same async chain already inside em.transactional \u2014 merge (savepoint / same Knex tx).\n\t\t\tlogger.trace(\n\t\t\t\t'Transaction already in progress with sufficient isolation, proceeding without new transaction.'\n\t\t\t);\n\n\t\t\treturn callback();\n\t\t}\n\n\t\t// New outer transaction \u2014 use root EM so we do not read transactionalAsyncLocal before it exists.\n\t\tlogger.trace('Starting transaction');\n\n\t\treturn this.orm.em.transactional(async (emArg) => {\n\t\t\tconst em = emArg as EntityManager;\n\t\t\tconst driver = em.getDriver();\n\t\t\tif (driver.constructor.name === 'SqliteDriver') {\n\t\t\t\tlogger.trace('All transactions in SQLite are SERIALIZABLE');\n\t\t\t} else {\n\t\t\t\tawait em.execute(`SET SESSION TRANSACTION ISOLATION LEVEL ${isolationLevel}`);\n\t\t\t}\n\n\t\t\treturn this.transactionalAsyncLocal.run({ em, isolationLevel }, async () => {\n\t\t\t\tlet result: T;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await callback();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tsafeErrorLog(logger, error, 'Error in transaction');\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t});\n\t\t});\n\t}\n\n\tpublic isolatedTest(test: () => any) {\n\t\treturn async () => {\n\t\t\ttry {\n\t\t\t\tawait this.transactional(async () => {\n\t\t\t\t\tawait test();\n\t\t\t\t\tthrow new Error('Rollback transaction for test');\n\t\t\t\t}, IsolationLevel.SERIALIZABLE);\n\t\t\t} catch (error) {\n\t\t\t\t// Only need to care if this isn't our rollback from above.\n\t\t\t\t// Otherwise just gobble it.\n\t\t\t\tif ((error as Error).message !== 'Rollback transaction for test') {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic get rawConnection() {\n\t\treturn this.em.getDriver().getConnection();\n\t}\n\n\tprivate getEnvironmentOverrides = async (secretArn?: string): Promise<Options> => {\n\t\tlogger.trace('Database::getEnvironmentOverrides() - Enter');\n\t\tconst secret = secretArn ?? process.env.DATABASE_SECRET_ARN;\n\t\tif (secret) {\n\t\t\tconst { SecretsManagerClient, GetSecretValueCommand } = await import(\n\t\t\t\t'@aws-sdk/client-secrets-manager'\n\t\t\t);\n\n\t\t\tif (!SecretsManagerClient || !GetSecretValueCommand) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'SecretsManagerClient or GetSecretValueCommand not found but a secret ARN was provided. Is @aws-sdk/client-secrets-manager available?'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst client = new SecretsManagerClient({\n\t\t\t\tregion: process.env.AWS_REGION,\n\t\t\t});\n\t\t\tconst command = new GetSecretValueCommand({ SecretId: secret });\n\n\t\t\ttry {\n\t\t\t\tlogger.trace('Fetching secret from Secrets Manager');\n\t\t\t\tconst response = await client.send(command);\n\t\t\t\tconst secret = JSON.parse(response.SecretString as string);\n\t\t\t\tlogger.trace('Secret fetched from Secrets Manager');\n\n\t\t\t\treturn {\n\t\t\t\t\thost: secret.host,\n\t\t\t\t\tport: secret.port,\n\t\t\t\t\tuser: secret.username,\n\t\t\t\t\tpassword: secret.password,\n\t\t\t\t\tdbName: secret.dbname,\n\t\t\t\t\tdriverOptions: {\n\t\t\t\t\t\tconnection: { ssl: true },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('Error fetching secret from Secrets Manager');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tlogger.trace('No secret ARN provided, using environment variables');\n\n\t\treturn {\n\t\t\thost: process.env.DATABASE_HOST,\n\t\t\tport: process.env.DATABASE_PORT ? Number(process.env.DATABASE_PORT) : undefined,\n\t\t\tuser: process.env.DATABASE_USERNAME,\n\t\t\tpassword: process.env.DATABASE_PASSWORD,\n\t\t\tdbName: process.env.DATABASE_NAME,\n\t\t};\n\t};\n\n\tprivate getConnectionInfo = async (connectionOptions?: ConnectionOptions): Promise<Options> => {\n\t\tlogger.trace('Database::getConnectionInfo() - Enter');\n\n\t\t// We have some defaults\n\t\tconst defaults: Options = {\n\t\t\thost: 'localhost',\n\t\t\tport: 5432,\n\t\t\tdbName: 'graphweaver',\n\t\t};\n\n\t\tconst resolvedMikroOrmConfig =\n\t\t\ttypeof connectionOptions?.mikroOrmConfig === 'function'\n\t\t\t\t? await connectionOptions.mikroOrmConfig()\n\t\t\t\t: connectionOptions?.mikroOrmConfig;\n\n\t\t// And finally we can override all of this with environment variables if needed.\n\t\tconst environmentOverrides = await this.getEnvironmentOverrides(connectionOptions?.secretArn);\n\n\t\t// Create a function we can use to filter out undefined values in the object.\n\t\tconst filterUndefined = (obj?: Options) => {\n\t\t\tif (!obj) return {};\n\n\t\t\tfor (const key of Object.keys(obj) as Array<keyof Options>) {\n\t\t\t\tif (obj[key] === undefined) delete obj[key];\n\t\t\t}\n\n\t\t\treturn obj;\n\t\t};\n\n\t\t// Apply each in order so the correct value wins.\n\t\treturn {\n\t\t\t...defaults,\n\t\t\t...filterUndefined(environmentOverrides),\n\t\t\t...filterUndefined(resolvedMikroOrmConfig),\n\t\t};\n\t};\n\n\tpublic getRepository = <T extends AnyEntity<T>>(entityName: EntityName<T>) =>\n\t\tthis.em.getRepository(entityName);\n\n\tpublic connect = async (connectionOptions?: ConnectionOptions) => {\n\t\tlogger.trace('Database::connect() - Enter');\n\t\tthis.connectionOptions = connectionOptions;\n\n\t\tif (this.cachedOrm) {\n\t\t\tlogger.trace('Returning cached ORM');\n\t\t\treturn this.cachedOrm;\n\t\t}\n\n\t\tlogger.trace('Creating new ORM');\n\t\tlogger.trace('Getting connection info');\n\n\t\tconst params = await this.getConnectionInfo(connectionOptions);\n\n\t\tlogger.trace('Initialising ORM');\n\n\t\tlogger.trace(`${params.entities?.length}x entities`);\n\n\t\t// Log the params, obfuscating the password used for the connection if there is one.\n\t\tconst { password, ...rest } = params;\n\t\tlogger.info(\n\t\t\t{ connectionParams: rest },\n\t\t\t'Connecting to database using MikroORM. Note: connectionParams have password removed for security.'\n\t\t);\n\n\t\tconst orm = await MikroORM.init({\n\t\t\tvalidateRequired: false, // Since v5, new entities are validated on runtime (just before executing insert queries), based on the entity metadata\n\t\t\tcontextName: connectionOptions?.connectionManagerId ?? 'default',\n\t\t\timplicitTransactions: false,\n\t\t\tmetadataProvider: ReflectMetadataProvider,\n\t\t\tdiscovery: {\n\t\t\t\tdisableDynamicFileAccess: true,\n\t\t\t\trequireEntitiesArray: false,\n\t\t\t\twarnWhenNoEntities: false,\n\t\t\t},\n\t\t\tallowGlobalContext: true,\n\n\t\t\t// Ensure we only ever create one connection to the database.\n\t\t\tpool: {\n\t\t\t\tmin: 1,\n\t\t\t\tmax: 1,\n\t\t\t},\n\t\t\t...params,\n\t\t});\n\n\t\tlogger.trace({ dbName: params.dbName, host: params.host }, 'Creating database connection');\n\t\tawait orm.connect();\n\n\t\tlogger.trace('Caching connection');\n\t\tthis.cachedOrm = orm;\n\t\treturn orm;\n\t};\n\n\tpublic close = async () => {\n\t\tlogger.trace('Closing database connection');\n\n\t\tawait this.orm.close(true);\n\t\tdelete this.cachedOrm;\n\t};\n}\n\nclass ConnectionsManager {\n\tprivate connections = new Map<string, DatabaseImplementation>();\n\tprivate connectionPromises = new Map<string, Promise<DatabaseImplementation>>();\n\n\tgetConnections() {\n\t\treturn Array.from(this.connections.values());\n\t}\n\n\tget default(): DatabaseImplementation {\n\t\tconst [defaultConnection] = [...this.connections];\n\t\tif (!defaultConnection)\n\t\t\tthrow new Error(\n\t\t\t\t'Error: No database connections. There should be at least one database connection.'\n\t\t\t);\n\t\tconst [_, databaseConnection] = defaultConnection;\n\t\treturn databaseConnection;\n\t}\n\n\tpublic connect = (id: string, connectionOptions: ConnectionOptions) => {\n\t\tif (this.connections.has(id)) return this.connections.get(id);\n\n\t\tconst connect = new Promise<DatabaseImplementation>((resolve, reject) => {\n\t\t\tconst database = new DatabaseImplementation();\n\t\t\tdatabase\n\t\t\t\t.connect(connectionOptions)\n\t\t\t\t.then(() => {\n\t\t\t\t\tlogger.trace(`Saving database connection with id \"${id}\".`);\n\t\t\t\t\tthis.connections.set(id, database);\n\t\t\t\t\tresolve(database);\n\t\t\t\t})\n\t\t\t\t.catch(reject);\n\t\t});\n\n\t\tthis.connectionPromises.set(id, connect);\n\n\t\treturn connect;\n\t};\n\n\tpublic database(id: string) {\n\t\treturn this.connections.get(id);\n\t}\n\n\tpublic awaitableDatabase(id: string) {\n\t\treturn this.connectionPromises.get(id);\n\t}\n\n\tpublic async close(id: string) {\n\t\tconst database = this.database(id);\n\t\tawait database?.close();\n\t\treturn true;\n\t}\n}\nexport const ConnectionManager = new ConnectionsManager();\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAO;AAEP,8BAAkC;AAClC,kBAQO;AACP,oBAAqC;AAkB9B,IAAK,iBAAL,kBAAKA,oBAAL;AACN,EAAAA,gBAAA,kBAAe;AACf,EAAAA,gBAAA,qBAAkB;AAClB,EAAAA,gBAAA,oBAAiB;AACjB,EAAAA,gBAAA,sBAAmB;AAJR,SAAAA;AAAA,GAAA;AAOZ,MAAM,yBAAyB;AAAA,EA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YAAM,UAAU,IAAI,QAAgC,CAAC,SAAS,WAAW;AACxE,cAAM,WAAW,IAAI,uBAAuB;AAC5C,iBACE,QAAQ,iBAAiB,EACzB,KAAK,MAAM;AACX,+BAAO,MAAM,uCAAuC,EAAE,IAAI;AAC1D,eAAK,YAAY,IAAI,IAAI,QAAQ;AACjC,kBAAQ,QAAQ;AAAA,QACjB,CAAC,EACA,MAAM,MAAM;AAAA,MACf,CAAC;AAED,WAAK,mBAAmB,IAAI,IAAI,OAAO;AAEvC,aAAO;AAAA,IACR;AAAA;AAAA,EAhCA,iBAAiB;AAChB,WAAO,MAAM,KAAK,KAAK,YAAY,OAAO,CAAC;AAAA,EAC5C;AAAA,EAEA,IAAI,UAAkC;AACrC,UAAM,CAAC,iBAAiB,IAAI,CAAC,GAAG,KAAK,WAAW;AAChD,QAAI,CAAC;AACJ,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AACD,UAAM,CAAC,GAAG,kBAAkB,IAAI;AAChC,WAAO;AAAA,EACR;AAAA,EAsBO,SAAS,IAAY;AAC3B,WAAO,KAAK,YAAY,IAAI,EAAE;AAAA,EAC/B;AAAA,EAEO,kBAAkB,IAAY;AACpC,WAAO,KAAK,mBAAmB,IAAI,EAAE;AAAA,EACtC;AAAA,EAEA,MAAa,MAAM,IAAY;AAC9B,UAAM,WAAW,KAAK,SAAS,EAAE;AACjC,UAAM,UAAU,MAAM;AACtB,WAAO;AAAA,EACR;AACD;AACO,MAAM,oBAAoB,IAAI,mBAAmB;",
|
|
6
6
|
"names": ["IsolationLevel", "secret"]
|
|
7
7
|
}
|
|
@@ -17,6 +17,7 @@ export declare class SchemaEntityFile extends BaseFile {
|
|
|
17
17
|
getBasePath(): string;
|
|
18
18
|
getBaseName(): string;
|
|
19
19
|
generate(): string;
|
|
20
|
+
protected isAutoGeneratedProperty(prop: EntityProperty): boolean;
|
|
20
21
|
protected getTypescriptPropertyType(prop: EntityProperty): string;
|
|
21
22
|
protected getPropertyDefinition(prop: EntityProperty): string;
|
|
22
23
|
protected getEnumClassDefinition(enumClassName: string): string;
|
|
@@ -111,7 +111,9 @@ class SchemaEntityFile extends import_base_file.BaseFile {
|
|
|
111
111
|
this.coreImports.add("Entity");
|
|
112
112
|
file += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {
|
|
113
113
|
provider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}'})`;
|
|
114
|
-
|
|
114
|
+
const isSinglePrimaryKeyEntity = props.length === 1 && props[0].primary;
|
|
115
|
+
const [primaryKey] = this.meta.getPrimaryProps();
|
|
116
|
+
if (isSinglePrimaryKeyEntity || !this.isAutoGeneratedProperty(primaryKey) || this.clientGeneratedPrimaryKeys) {
|
|
115
117
|
file += `,
|
|
116
118
|
apiOptions: { clientGeneratedPrimaryKeys: true },
|
|
117
119
|
})
|
|
@@ -147,6 +149,11 @@ class SchemaEntityFile extends import_base_file.BaseFile {
|
|
|
147
149
|
${file}`;
|
|
148
150
|
return file;
|
|
149
151
|
}
|
|
152
|
+
isAutoGeneratedProperty(prop) {
|
|
153
|
+
const isSqliteIntegerPrimaryKey = this.databaseType === "sqlite" && prop.primary && prop.type === "integer";
|
|
154
|
+
const isPrimaryKeyAutoGenerated = prop.autoincrement || prop.generated || prop.defaultRaw && prop.defaultRaw !== "null" || isSqliteIntegerPrimaryKey;
|
|
155
|
+
return !!isPrimaryKeyAutoGenerated;
|
|
156
|
+
}
|
|
150
157
|
getTypescriptPropertyType(prop) {
|
|
151
158
|
if ([import_core.ReferenceKind.ONE_TO_ONE, import_core.ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
|
|
152
159
|
return prop.type.charAt(0).toUpperCase() + prop.type.slice(1);
|
|
@@ -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';\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\tprotected readonly clientGeneratedPrimaryKeys: boolean,\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) || this.clientGeneratedPrimaryKeys) {\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\tthis.scalarImports.add('DateScalar');\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\t// Owning side: use the FK's nullability\n\t\t// Non-owning side of 1:1 is always nullable because we aren't guaranteed to have a row for every single\n\t\t// entity created on the non-owning side of the relationship.\n\t\tif (\n\t\t\t(prop.nullable && !prop.mappedBy) ||\n\t\t\t(prop.mappedBy && prop.kind === ReferenceKind.ONE_TO_ONE)\n\t\t) {\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 (!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,k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AAa;AAEb,UAAI,MAAM,MAAM,SAAS,CAAC,MAAM,KAAM,cAAa;AAEnD,UAAI,KAAK,MAAM;AACd,cAAM,gBAAgB,KAAK,eAAe;AAAA,UACzC,KAAK,KAAK,aAAa,MAAM,KAAK,WAAW,CAAC;AAAA,UAC9C;AAAA,QACD;AACA,wBAAgB,KAAK,KAAK,uBAAuB,aAAa,CAAC;AAAA,MAChE;AAAA,IACD,CAAC;AAED,QAAI,OAAO;AAEX,QAAI,gBAAgB,QAAQ;AAC3B,cAAQ,gBAAgB,KAAK,IAAI;AACjC,cAAQ;AAAA,IACT;AAEA,SAAK,YAAY,IAAI,QAAQ;AAE7B,YAAQ,WAAW,KAAK,KAAK,SAAS,KAAK,KAAK,MAAM,KAAK,KAAK,SAAS,CAAC;AAAA,yCAAgD,KAAK,KAAK,SAAS,wCAAwC,4BAA4B,KAAK,YAAY,CAAC;
|
|
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';\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\tprotected readonly clientGeneratedPrimaryKeys: boolean,\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\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// 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// We should be able to remove this in the future and allow users to use it both ways.\n\t\tconst isSinglePrimaryKeyEntity = props.length === 1 && props[0].primary;\n\t\tconst [primaryKey] = this.meta.getPrimaryProps();\n\n\t\tif (isSinglePrimaryKeyEntity || !this.isAutoGeneratedProperty(primaryKey) || this.clientGeneratedPrimaryKeys) {\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 isAutoGeneratedProperty(prop: EntityProperty): boolean {\n\t\tconst isSqliteIntegerPrimaryKey = this.databaseType === 'sqlite' && prop.primary && prop.type === 'integer';\n\t\tconst isPrimaryKeyAutoGenerated = prop.autoincrement || \n\t\t\tprop.generated || \n\t\t\t(prop.defaultRaw && prop.defaultRaw !== 'null') ||\n\t\t\tisSqliteIntegerPrimaryKey;\n\n\t\treturn !!isPrimaryKeyAutoGenerated;\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\tthis.scalarImports.add('DateScalar');\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\t// Owning side: use the FK's nullability\n\t\t// Non-owning side of 1:1 is always nullable because we aren't guaranteed to have a row for every single\n\t\t// entity created on the non-owning side of the relationship.\n\t\tif (\n\t\t\t(prop.nullable && !prop.mappedBy) ||\n\t\t\t(prop.mappedBy && prop.kind === ReferenceKind.ONE_TO_ONE)\n\t\t) {\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 (!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,cACA,4BAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AAPjB;AACA;AACA;AACA;AACA;AACA;AAZpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,gB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,eAAe,KAAK,MAAM,KAAK,QAAQ;AAAA,EAChD;AAAA,EAEU,8BAA8B,SAAqB,MAAsB;AAClF,SAAK,cAAc,IAAI,KAAK,IAAI;AAEhC,UAAM,gBAAgB,KAAK,aAAa,IAAI,KAAK,IAAI;AACrD,QAAI,CAAC,eAAe;AACnB,YAAM,IAAI;AAAA,QACT,kCAAkC,KAAK,IAAI;AAAA,MAC5C;AAAA,IACD;AACA,QAAI,KAAC,8CAA6B,aAAa,GAAG;AACjD,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AACA,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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_core = require("@mikro-orm/core");
|
|
4
|
+
var import_schema_entity_file = require("./files/schema-entity-file");
|
|
5
|
+
const mockPlatform = {
|
|
6
|
+
getMappedType: () => ({
|
|
7
|
+
getColumnType: () => "mocked-type"
|
|
8
|
+
})
|
|
9
|
+
};
|
|
10
|
+
const mockNamingStrategy = {
|
|
11
|
+
propertyToColumnName: (name) => name,
|
|
12
|
+
getClassName: (name) => name
|
|
13
|
+
};
|
|
14
|
+
const makeScalarProp = (overrides) => ({
|
|
15
|
+
name: "field",
|
|
16
|
+
primary: false,
|
|
17
|
+
kind: import_core.ReferenceKind.SCALAR,
|
|
18
|
+
type: "string",
|
|
19
|
+
runtimeType: "string",
|
|
20
|
+
fieldNames: ["field"],
|
|
21
|
+
columnTypes: ["varchar"],
|
|
22
|
+
autoincrement: false,
|
|
23
|
+
nullable: false,
|
|
24
|
+
enum: false,
|
|
25
|
+
ref: false,
|
|
26
|
+
default: void 0,
|
|
27
|
+
generated: void 0,
|
|
28
|
+
...overrides
|
|
29
|
+
});
|
|
30
|
+
const makeMeta = (className, pkProp, extraProps = []) => {
|
|
31
|
+
const allProps = [pkProp, ...extraProps];
|
|
32
|
+
return {
|
|
33
|
+
className,
|
|
34
|
+
collection: `${className.toLowerCase()}s`,
|
|
35
|
+
primaryKeys: [pkProp.name],
|
|
36
|
+
pivotTable: false,
|
|
37
|
+
properties: Object.fromEntries(allProps.map((p) => [p.name, p])),
|
|
38
|
+
props: allProps,
|
|
39
|
+
getPrimaryProps: () => [pkProp]
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const nameProp = makeScalarProp({
|
|
43
|
+
name: "name",
|
|
44
|
+
fieldNames: ["name"]
|
|
45
|
+
});
|
|
46
|
+
(0, import_vitest.describe)("SchemaEntityFile - primary key client generation detection", () => {
|
|
47
|
+
(0, import_vitest.it)("should NOT emit clientGeneratedPrimaryKeys for an autoincrement PK", () => {
|
|
48
|
+
const pk = makeScalarProp({
|
|
49
|
+
name: "artistId",
|
|
50
|
+
primary: true,
|
|
51
|
+
type: "number",
|
|
52
|
+
runtimeType: "number",
|
|
53
|
+
fieldNames: ["artistId"],
|
|
54
|
+
columnTypes: ["integer"],
|
|
55
|
+
autoincrement: true
|
|
56
|
+
});
|
|
57
|
+
const file = new import_schema_entity_file.SchemaEntityFile(
|
|
58
|
+
makeMeta("Artist", pk, [nameProp]),
|
|
59
|
+
mockNamingStrategy,
|
|
60
|
+
mockPlatform,
|
|
61
|
+
"postgresql",
|
|
62
|
+
/* @__PURE__ */ new Map(),
|
|
63
|
+
false
|
|
64
|
+
);
|
|
65
|
+
(0, import_vitest.expect)(file.generate()).not.toContain("clientGeneratedPrimaryKeys: true");
|
|
66
|
+
});
|
|
67
|
+
(0, import_vitest.it)("should NOT emit clientGeneratedPrimaryKeys for a UUID PK with a DB-side default", () => {
|
|
68
|
+
const pk = makeScalarProp({
|
|
69
|
+
name: "albumId",
|
|
70
|
+
primary: true,
|
|
71
|
+
type: "string",
|
|
72
|
+
runtimeType: "string",
|
|
73
|
+
fieldNames: ["albumId"],
|
|
74
|
+
columnTypes: ["uuid"],
|
|
75
|
+
autoincrement: false,
|
|
76
|
+
default: void 0,
|
|
77
|
+
defaultRaw: "gen_random_uuid()"
|
|
78
|
+
});
|
|
79
|
+
const file = new import_schema_entity_file.SchemaEntityFile(
|
|
80
|
+
makeMeta("Album", pk, [nameProp]),
|
|
81
|
+
mockNamingStrategy,
|
|
82
|
+
mockPlatform,
|
|
83
|
+
"postgresql",
|
|
84
|
+
/* @__PURE__ */ new Map(),
|
|
85
|
+
false
|
|
86
|
+
);
|
|
87
|
+
(0, import_vitest.expect)(file.generate()).not.toContain("clientGeneratedPrimaryKeys: true");
|
|
88
|
+
});
|
|
89
|
+
(0, import_vitest.it)("should NOT emit clientGeneratedPrimaryKeys for a string PK with a generated value", () => {
|
|
90
|
+
const pk = makeScalarProp({
|
|
91
|
+
name: "albumId",
|
|
92
|
+
primary: true,
|
|
93
|
+
type: "string",
|
|
94
|
+
runtimeType: "string",
|
|
95
|
+
fieldNames: ["albumId"],
|
|
96
|
+
columnTypes: ["uuid"],
|
|
97
|
+
autoincrement: false,
|
|
98
|
+
generated: 'concat("ALB-", uuid_generate_v4())'
|
|
99
|
+
});
|
|
100
|
+
const file = new import_schema_entity_file.SchemaEntityFile(
|
|
101
|
+
makeMeta("Album", pk, [nameProp]),
|
|
102
|
+
mockNamingStrategy,
|
|
103
|
+
mockPlatform,
|
|
104
|
+
"postgresql",
|
|
105
|
+
/* @__PURE__ */ new Map(),
|
|
106
|
+
false
|
|
107
|
+
);
|
|
108
|
+
(0, import_vitest.expect)(file.generate()).not.toContain("clientGeneratedPrimaryKeys: true");
|
|
109
|
+
});
|
|
110
|
+
(0, import_vitest.it)("should emit clientGeneratedPrimaryKeys: true for an integer PK with no auto-generation", () => {
|
|
111
|
+
const pk = makeScalarProp({
|
|
112
|
+
name: "trackId",
|
|
113
|
+
primary: true,
|
|
114
|
+
type: "number",
|
|
115
|
+
runtimeType: "number",
|
|
116
|
+
fieldNames: ["trackId"],
|
|
117
|
+
columnTypes: ["integer"],
|
|
118
|
+
autoincrement: false
|
|
119
|
+
});
|
|
120
|
+
const file = new import_schema_entity_file.SchemaEntityFile(
|
|
121
|
+
makeMeta("Track", pk, [nameProp]),
|
|
122
|
+
mockNamingStrategy,
|
|
123
|
+
mockPlatform,
|
|
124
|
+
"postgresql",
|
|
125
|
+
/* @__PURE__ */ new Map(),
|
|
126
|
+
false
|
|
127
|
+
);
|
|
128
|
+
(0, import_vitest.expect)(file.generate()).toContain("apiOptions: { clientGeneratedPrimaryKeys: true }");
|
|
129
|
+
});
|
|
130
|
+
(0, import_vitest.it)("should emit clientGeneratedPrimaryKeys: true for an integer PK and no other props", () => {
|
|
131
|
+
const pk = makeScalarProp({
|
|
132
|
+
name: "trackId",
|
|
133
|
+
primary: true,
|
|
134
|
+
type: "number",
|
|
135
|
+
runtimeType: "number",
|
|
136
|
+
fieldNames: ["trackId"],
|
|
137
|
+
columnTypes: ["integer"],
|
|
138
|
+
autoincrement: false
|
|
139
|
+
});
|
|
140
|
+
const file = new import_schema_entity_file.SchemaEntityFile(
|
|
141
|
+
makeMeta("Track", pk),
|
|
142
|
+
mockNamingStrategy,
|
|
143
|
+
mockPlatform,
|
|
144
|
+
"postgresql",
|
|
145
|
+
/* @__PURE__ */ new Map(),
|
|
146
|
+
false
|
|
147
|
+
);
|
|
148
|
+
(0, import_vitest.expect)(file.generate()).toContain("apiOptions: { clientGeneratedPrimaryKeys: true }");
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=schema-entity-file.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/introspection/schema-entity-file.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, it, expect } from 'vitest';\nimport { type EntityMetadata, type EntityProperty, type NamingStrategy, type Platform, ReferenceKind } from '@mikro-orm/core';\nimport { SchemaEntityFile } from './files/schema-entity-file';\n\nconst mockPlatform = {\n\tgetMappedType: () => ({\n\t\tgetColumnType: () => 'mocked-type',\n\t}),\n} as unknown as Platform;\nconst mockNamingStrategy = {\n\tpropertyToColumnName: (name: string) => name,\n\tgetClassName: (name: string) => name,\n} as unknown as NamingStrategy;\nconst makeScalarProp = (overrides: Partial<EntityProperty>): EntityProperty =>\n\t({\n\t\tname: 'field',\n\t\tprimary: false,\n\t\tkind: ReferenceKind.SCALAR,\n\t\ttype: 'string',\n\t\truntimeType: 'string',\n\t\tfieldNames: ['field'],\n\t\tcolumnTypes: ['varchar'],\n\t\tautoincrement: false,\n\t\tnullable: false,\n\t\tenum: false,\n\t\tref: false,\n\t\tdefault: undefined,\n\t\tgenerated: undefined,\n\t\t...overrides,\n\t}) as EntityProperty;\nconst makeMeta = (className: string, pkProp: EntityProperty, extraProps: EntityProperty[] = []): EntityMetadata => {\n\tconst allProps = [pkProp, ...extraProps];\n\treturn {\n\t\tclassName,\n\t\tcollection: `${className.toLowerCase()}s`,\n\t\tprimaryKeys: [pkProp.name],\n\t\tpivotTable: false,\n\t\tproperties: Object.fromEntries(allProps.map((p) => [p.name, p])),\n\t\tprops: allProps,\n\t\tgetPrimaryProps: () => [pkProp],\n\t} as unknown as EntityMetadata;\n};\nconst nameProp = makeScalarProp({\n\tname: 'name',\n\tfieldNames: ['name'],\n});\n\ndescribe('SchemaEntityFile - primary key client generation detection', () => {\n\tit('should NOT emit clientGeneratedPrimaryKeys for an autoincrement PK', () => {\n\t\t// Auto Increment Column\n\t\tconst pk = makeScalarProp({\n\t\t\tname: 'artistId',\n\t\t\tprimary: true,\n\t\t\ttype: 'number',\n\t\t\truntimeType: 'number',\n\t\t\tfieldNames: ['artistId'],\n\t\t\tcolumnTypes: ['integer'],\n\t\t\tautoincrement: true,\n\t\t});\n\n\t\tconst file = new SchemaEntityFile(\n\t\t\tmakeMeta('Artist', pk, [nameProp]),\n\t\t\tmockNamingStrategy,\n\t\t\tmockPlatform,\n\t\t\t'postgresql',\n\t\t\tnew Map<string, EntityMetadata>(),\n\t\t\tfalse\n\t\t);\n\n\t\texpect(file.generate()).not.toContain('clientGeneratedPrimaryKeys: true');\n\t});\n\n\tit('should NOT emit clientGeneratedPrimaryKeys for a UUID PK with a DB-side default', () => {\n\t\t// UUID column with DEFAULT gen_random_uuid()\n\t\tconst pk = makeScalarProp({\n\t\t\tname: 'albumId',\n\t\t\tprimary: true,\n\t\t\ttype: 'string',\n\t\t\truntimeType: 'string',\n\t\t\tfieldNames: ['albumId'],\n\t\t\tcolumnTypes: ['uuid'],\n\t\t\tautoincrement: false,\n\t\t\tdefault: undefined,\n\t\t\tdefaultRaw: 'gen_random_uuid()',\n\t\t});\n\n\t\tconst file = new SchemaEntityFile(\n\t\t\tmakeMeta('Album', pk, [nameProp]),\n\t\t\tmockNamingStrategy,\n\t\t\tmockPlatform,\n\t\t\t'postgresql',\n\t\t\tnew Map<string, EntityMetadata>(),\n\t\t\tfalse\n\t\t);\n\n\t\texpect(file.generate()).not.toContain('clientGeneratedPrimaryKeys: true');\n\t});\n\n\tit('should NOT emit clientGeneratedPrimaryKeys for a string PK with a generated value', () => {\n\t\t// String column with concat value\n\t\tconst pk = makeScalarProp({\n\t\t\tname: 'albumId',\n\t\t\tprimary: true,\n\t\t\ttype: 'string',\n\t\t\truntimeType: 'string',\n\t\t\tfieldNames: ['albumId'],\n\t\t\tcolumnTypes: ['uuid'],\n\t\t\tautoincrement: false,\n\t\t\tgenerated: 'concat(\"ALB-\", uuid_generate_v4())',\n\t\t});\n\n\t\tconst file = new SchemaEntityFile(\n\t\t\tmakeMeta('Album', pk, [nameProp]),\n\t\t\tmockNamingStrategy,\n\t\t\tmockPlatform,\n\t\t\t'postgresql',\n\t\t\tnew Map<string, EntityMetadata>(),\n\t\t\tfalse\n\t\t);\n\n\t\texpect(file.generate()).not.toContain('clientGeneratedPrimaryKeys: true');\n\t});\n\n\tit('should emit clientGeneratedPrimaryKeys: true for an integer PK with no auto-generation', () => {\n\t\t// Integer column, client generates the Primary Key value\n\t\tconst pk = makeScalarProp({\n\t\t\tname: 'trackId',\n\t\t\tprimary: true,\n\t\t\ttype: 'number',\n\t\t\truntimeType: 'number',\n\t\t\tfieldNames: ['trackId'],\n\t\t\tcolumnTypes: ['integer'],\n\t\t\tautoincrement: false,\n\t\t});\n\n\t\tconst file = new SchemaEntityFile(\n\t\t\tmakeMeta('Track', pk, [nameProp]),\n\t\t\tmockNamingStrategy,\n\t\t\tmockPlatform,\n\t\t\t'postgresql',\n\t\t\tnew Map<string, EntityMetadata>(),\n\t\t\tfalse\n\t\t);\n\n\t\texpect(file.generate()).toContain('apiOptions: { clientGeneratedPrimaryKeys: true }');\n\t});\n\n\tit('should emit clientGeneratedPrimaryKeys: true for an integer PK and no other props', () => {\n\t\t// Integer column, client generates the Primary Key value\n\t\tconst pk = makeScalarProp({\n\t\t\tname: 'trackId',\n\t\t\tprimary: true,\n\t\t\ttype: 'number',\n\t\t\truntimeType: 'number',\n\t\t\tfieldNames: ['trackId'],\n\t\t\tcolumnTypes: ['integer'],\n\t\t\tautoincrement: false,\n\t\t});\n\n\t\tconst file = new SchemaEntityFile(\n\t\t\tmakeMeta('Track', pk),\n\t\t\tmockNamingStrategy,\n\t\t\tmockPlatform,\n\t\t\t'postgresql',\n\t\t\tnew Map<string, EntityMetadata>(),\n\t\t\tfalse\n\t\t);\n\n\t\texpect(file.generate()).toContain('apiOptions: { clientGeneratedPrimaryKeys: true }');\n\t});\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,oBAAqC;AACrC,kBAA4G;AAC5G,gCAAiC;AAEjC,MAAM,eAAe;AAAA,EACpB,eAAe,OAAO;AAAA,IACrB,eAAe,MAAM;AAAA,EACtB;AACD;AACA,MAAM,qBAAqB;AAAA,EAC1B,sBAAsB,CAAC,SAAiB;AAAA,EACxC,cAAc,CAAC,SAAiB;AACjC;AACA,MAAM,iBAAiB,CAAC,eACtB;AAAA,EACA,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,0BAAc;AAAA,EACpB,MAAM;AAAA,EACN,aAAa;AAAA,EACb,YAAY,CAAC,OAAO;AAAA,EACpB,aAAa,CAAC,SAAS;AAAA,EACvB,eAAe;AAAA,EACf,UAAU;AAAA,EACV,MAAM;AAAA,EACN,KAAK;AAAA,EACL,SAAS;AAAA,EACT,WAAW;AAAA,EACX,GAAG;AACJ;AACD,MAAM,WAAW,CAAC,WAAmB,QAAwB,aAA+B,CAAC,MAAsB;AAClH,QAAM,WAAW,CAAC,QAAQ,GAAG,UAAU;AACvC,SAAO;AAAA,IACN;AAAA,IACA,YAAY,GAAG,UAAU,YAAY,CAAC;AAAA,IACtC,aAAa,CAAC,OAAO,IAAI;AAAA,IACzB,YAAY;AAAA,IACZ,YAAY,OAAO,YAAY,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAAA,IAC/D,OAAO;AAAA,IACP,iBAAiB,MAAM,CAAC,MAAM;AAAA,EAC/B;AACD;AACA,MAAM,WAAW,eAAe;AAAA,EAC/B,MAAM;AAAA,EACN,YAAY,CAAC,MAAM;AACpB,CAAC;AAAA,IAED,wBAAS,8DAA8D,MAAM;AAC5E,wBAAG,sEAAsE,MAAM;AAE9E,UAAM,KAAK,eAAe;AAAA,MAC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MAChC;AAAA,IACD;AAEA,8BAAO,KAAK,SAAS,CAAC,EAAE,IAAI,UAAU,kCAAkC;AAAA,EACzE,CAAC;AAED,wBAAG,0FAA0F,MAAM;AAElG,UAAM,KAAK,eAAe;AAAA,MACzB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY,CAAC,SAAS;AAAA,MACtB,aAAa,CAAC,SAAS;AAAA,MACvB,eAAe;AAAA,IAChB,CAAC;AAED,UAAM,OAAO,IAAI;AAAA,MAChB,SAAS,SAAS,IAAI,CAAC,QAAQ,CAAC;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAI,IAA4B;AAAA,MAChC;AAAA,IACD;AAEA,8BAAO,KAAK,SAAS,CAAC,EAAE,UAAU,kDAAkD;AAAA,EACrF,CAAC;AAED,wBAAG,qFAAqF,MAAM;AAE7F,UAAM,KAAK,eAAe;AAAA,MACzB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY,CAAC,SAAS;AAAA,MACtB,aAAa,CAAC,SAAS;AAAA,MACvB,eAAe;AAAA,IAChB,CAAC;AAED,UAAM,OAAO,IAAI;AAAA,MAChB,SAAS,SAAS,EAAE;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA,oBAAI,IAA4B;AAAA,MAChC;AAAA,IACD;AAEA,8BAAO,KAAK,SAAS,CAAC,EAAE,UAAU,kDAAkD;AAAA,EACrF,CAAC;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -28,7 +28,6 @@ export declare class MikroBackendProvider<D> implements BackendProvider<D> {
|
|
|
28
28
|
private mapAndAssignKeys;
|
|
29
29
|
private applyExternalIdFields;
|
|
30
30
|
visitPathForPopulate: (entityName: string, updateArgBranch: any, populateBranch?: string) => Set<string>;
|
|
31
|
-
private flushOnBatchInserts;
|
|
32
31
|
find(filter: Filter<D>, pagination?: PaginationOptions, entityMetadata?: EntityMetadata, trace?: TraceOptions): Promise<D[]>;
|
|
33
32
|
findOne(filter: Filter<D>, entityMetadata?: EntityMetadata, trace?: TraceOptions): Promise<D | null>;
|
|
34
33
|
findByRelatedId(entity: any, relatedField: string, relatedFieldIds: string[], filter?: any, trace?: TraceOptions): Promise<D[]>;
|
package/lib/provider/provider.js
CHANGED
|
@@ -251,12 +251,6 @@ class MikroBackendProvider {
|
|
|
251
251
|
if (driver.startsWith("SqliteDriver")) return "sqlite";
|
|
252
252
|
throw new Error(`This driver (${driver}) is not supported!`);
|
|
253
253
|
}
|
|
254
|
-
// Some connections (ex. sqlite) require an explicit flush during batch inserts
|
|
255
|
-
// to retrieve user defined primary keys correctly.
|
|
256
|
-
flushOnBatchInserts() {
|
|
257
|
-
const driver = this.em.getDriver();
|
|
258
|
-
return driver.constructor.name === "SqliteDriver";
|
|
259
|
-
}
|
|
260
254
|
async find(filter, pagination, entityMetadata, trace) {
|
|
261
255
|
trace?.span.updateName(`Mikro-Orm - Find ${this.entityType.name}`);
|
|
262
256
|
import_logger.logger.trace(
|
|
@@ -500,9 +494,7 @@ class MikroBackendProvider {
|
|
|
500
494
|
this.database.em.persist(entity);
|
|
501
495
|
result.push(entity);
|
|
502
496
|
}
|
|
503
|
-
|
|
504
|
-
await this.database.em.flush();
|
|
505
|
-
}
|
|
497
|
+
await this.database.em.flush();
|
|
506
498
|
return result;
|
|
507
499
|
});
|
|
508
500
|
import_logger.logger.trace({ entity: this.entityType.name, entities }, "created items");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/provider/provider.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tAggregationType,\n\tBackendProvider,\n\tgraphweaverMetadata,\n\tGraphweaverPluginNextFunction,\n\tGraphweaverRequestEvent,\n\tSort,\n\ttrace as startTrace,\n\tTraceMethod,\n\ttraceSync,\n} from '@exogee/graphweaver';\nimport type {\n\tAggregationResult,\n\tBackendProviderConfig,\n\tEntityMetadata,\n\tFieldMetadata,\n\tFilter,\n\tPaginationOptions,\n\tTraceOptions,\n} from '@exogee/graphweaver';\nimport { logger, safeErrorLog } from '@exogee/logger';\nimport {\n\tAutoPath,\n\tLoadStrategy,\n\tPopulateHint,\n\tReference,\n\tRequestContext,\n\tsql,\n} from '@mikro-orm/core';\nimport { pluginManager, apolloPluginManager } from '@exogee/graphweaver-server';\n\nimport {\n\tLockMode,\n\tQueryFlag,\n\tReferenceKind,\n\tConnectionManager,\n\texternalIdFieldMap,\n\tAnyEntity,\n\tIsolationLevel,\n\tConnectionOptions,\n\tconnectToDatabase,\n\tDatabaseType,\n} from '..';\n\nimport { OptimisticLockError, sanitiseFilterForLogging } from '../utils';\nimport { assign } from './assign';\n\ntype PostgresError = {\n\tcode: string;\n\troutine: string;\n};\n\nconst objectOperations = new Set(['_and', '_or', '_not']);\nconst mikroObjectOperations = new Set(['$and', '$or', '$not']);\nconst nullBooleanOperations = new Set(['null', 'notnull']);\n\nconst appendPath = (path: string, newPath: string) =>\n\tpath.length ? `${path}.${newPath}` : newPath;\n\nexport const gqlToMikro = (filter: any, databaseType?: DatabaseType): any => {\n\tif (Array.isArray(filter)) {\n\t\treturn filter.map((element) => gqlToMikro(element, databaseType));\n\t} else if (typeof filter === 'object' && filter !== null) {\n\t\tfor (const key of Object.keys(filter)) {\n\t\t\t// A null here is a user-specified value and is valid to filter on\n\t\t\tif (filter[key] === null) continue;\n\n\t\t\tif (objectOperations.has(key)) {\n\t\t\t\t// { _not: '1' } => { $not: '1' }\n\t\t\t\tfilter[key.replace('_', '$')] = gqlToMikro(filter[key], databaseType);\n\t\t\t\tdelete filter[key];\n\t\t\t} else if (typeof filter[key] === 'object' && !Array.isArray(filter[key])) {\n\t\t\t\t// Recurse over nested filters only (arrays are an argument to a filter, not a nested filter)\n\t\t\t\tfilter[key] = gqlToMikro(filter[key], databaseType);\n\t\t\t} else if (key.indexOf('_') >= 0) {\n\t\t\t\tconst [newKey, operator] = key.split('_');\n\t\t\t\tlet newValue;\n\t\t\t\tif (nullBooleanOperations.has(operator) && typeof filter[key] === 'boolean') {\n\t\t\t\t\t// { firstName_null: true } => { firstName: { $eq: null } } or { firstName_null: false } => { firstName: { $ne: null } }\n\t\t\t\t\t// { firstName_notnull: true } => { firstName: { $ne: null } } or { firstName_notnull: false } => { firstName: { $eq: null } }\n\t\t\t\t\tnewValue =\n\t\t\t\t\t\t(filter[key] && operator === 'null') || (!filter[key] && operator === 'notnull')\n\t\t\t\t\t\t\t? { $eq: null }\n\t\t\t\t\t\t\t: { $ne: null };\n\t\t\t\t} else if (operator === 'ilike' && databaseType !== 'postgresql') {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`The $ilike operator is not supported by ${databaseType} databases. Operator coerced to $like.`\n\t\t\t\t\t);\n\t\t\t\t\tnewValue = { $like: filter[key] };\n\t\t\t\t} else {\n\t\t\t\t\t// { firstName_in: ['k', 'b'] } => { firstName: { $in: ['k', 'b'] } }\n\t\t\t\t\tnewValue = { [`$${operator}`]: gqlToMikro(filter[key], databaseType) };\n\t\t\t\t\t// They can construct multiple filters for the same key. In that case we need\n\t\t\t\t\t// to append them all into an object.\n\t\t\t\t}\n\n\t\t\t\tif (typeof filter[newKey] !== 'undefined') {\n\t\t\t\t\tif (typeof filter[newKey] !== 'object') {\n\t\t\t\t\t\tif (typeof newValue === 'object' && '$eq' in newValue) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`property ${newKey} on filter is ambiguous. There are two values for this property: ${filter[newKey]} and ${newValue.$eq}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfilter[newKey] = { ...{ $eq: filter[newKey] }, ...newValue };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (newValue && typeof newValue === 'object' && '$eq' in newValue) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`property ${newKey} on filter is ambiguous. There are two values for this property: ${JSON.stringify(\n\t\t\t\t\t\t\t\t\tfilter[newKey]\n\t\t\t\t\t\t\t\t)} and ${JSON.stringify(newValue)}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfilter[newKey] = { ...filter[newKey], ...newValue };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfilter[newKey] = newValue;\n\t\t\t\t}\n\n\t\t\t\tdelete filter[key];\n\t\t\t}\n\t\t}\n\t}\n\treturn filter;\n};\n\nexport interface AdditionalOptions {\n\ttransactionIsolationLevel?: IsolationLevel;\n\tbackendDisplayName?: string;\n}\n\nexport class MikroBackendProvider<D> implements BackendProvider<D> {\n\tprivate _backendId: string;\n\n\tprivate connection: ConnectionOptions;\n\n\tpublic entityType: new () => D;\n\tpublic connectionManagerId?: string;\n\tprivate transactionIsolationLevel!: IsolationLevel;\n\n\t// This is an optional setting that allows you to control how this provider is displayed in the Admin UI.\n\t// If you do not set a value, it will default to 'REST (hostname of baseUrl)'. Entities are grouped by\n\t// their backend's display name, so if you want to group them in a more specific way, this is the way to do it.\n\tpublic readonly backendDisplayName?: string;\n\n\tpublic readonly supportsInFilter = true;\n\n\t// Default backend provider config\n\tpublic readonly backendProviderConfig: BackendProviderConfig = {\n\t\tfilter: true,\n\t\tpagination: false,\n\t\torderBy: false,\n\t\tsupportedAggregationTypes: new Set<AggregationType>([AggregationType.COUNT]),\n\t\tsupportsPseudoCursorPagination: true,\n\t};\n\n\tget backendId() {\n\t\treturn this._backendId;\n\t}\n\n\tprivate get database() {\n\t\t// If we have a connection manager ID then use that else fallback to the Database\n\t\tif (!this.connectionManagerId) return ConnectionManager.default;\n\t\treturn ConnectionManager.database(this.connectionManagerId) || ConnectionManager.default;\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get transactional() {\n\t\treturn this.database.transactional;\n\t}\n\n\tpublic async withTransaction<T>(callback: () => Promise<T>) {\n\t\treturn this.database.transactional<T>(callback, this.transactionIsolationLevel);\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get em() {\n\t\treturn this.database.em;\n\t}\n\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\ttransactionIsolationLevel?: IsolationLevel\n\t);\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\tadditionalOptions?: AdditionalOptions\n\t);\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\toptionsOrIsolationLevel: AdditionalOptions | IsolationLevel = {\n\t\t\ttransactionIsolationLevel: IsolationLevel.REPEATABLE_READ,\n\t\t}\n\t) {\n\t\tconst options =\n\t\t\ttypeof optionsOrIsolationLevel === 'object'\n\t\t\t\t? optionsOrIsolationLevel\n\t\t\t\t: {\n\t\t\t\t\t\ttransactionIsolationLevel: optionsOrIsolationLevel,\n\t\t\t\t\t};\n\n\t\tthis.entityType = mikroType;\n\t\tthis.connectionManagerId = connection.connectionManagerId;\n\t\tthis._backendId = `mikro-orm-${connection.connectionManagerId || ''}`;\n\t\tthis.transactionIsolationLevel =\n\t\t\toptions.transactionIsolationLevel ?? IsolationLevel.REPEATABLE_READ;\n\t\tthis.backendDisplayName = options.backendDisplayName;\n\t\tthis.connection = connection;\n\t\tthis.addRequestContext();\n\t\tthis.connectToDatabase();\n\t}\n\tprivate getDbType(): DatabaseType {\n\t\tconst driver = this.em.getDriver().constructor.name;\n\t\t// This used to import the actual drivers, but since they're optional it makes more sense\n\t\t// to just use the strings. Using startsWith to handle ESBuild minification that may rename classes.\n\t\tif (driver.startsWith('MsSqlDriver')) return 'mssql';\n\t\tif (driver.startsWith('MySqlDriver')) return 'mysql';\n\t\tif (driver.startsWith('PostgreSqlDriver')) return 'postgresql';\n\t\tif (driver.startsWith('SqliteDriver')) return 'sqlite';\n\n\t\tthrow new Error(`This driver (${driver}) is not supported!`);\n\t}\n\n\tprivate connectToDatabase = async () => {\n\t\tconst connectionManagerId = this.connectionManagerId;\n\t\tif (!connectionManagerId) {\n\t\t\tthrow new Error('Expected connectionManagerId to be defined when calling addRequestContext.');\n\t\t}\n\n\t\tapolloPluginManager.addPlugin(connectionManagerId, connectToDatabase(this.connection));\n\t};\n\n\tprivate addRequestContext = () => {\n\t\tconst connectionManagerId = this.connectionManagerId;\n\t\tif (!connectionManagerId) {\n\t\t\tthrow new Error('Expected connectionManagerId to be defined when calling addRequestContext.');\n\t\t}\n\n\t\tconst connectionPlugin = {\n\t\t\tname: connectionManagerId,\n\t\t\tevent: GraphweaverRequestEvent.OnRequest,\n\t\t\tnext: async (_: GraphweaverRequestEvent, _next: GraphweaverPluginNextFunction) => {\n\t\t\t\tlogger.trace(`Graphweaver OnRequest plugin called`);\n\n\t\t\t\tconst connection = await ConnectionManager.awaitableDatabase(connectionManagerId);\n\n\t\t\t\tif (!connection) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No database connection found for connectionManagerId: ${connectionManagerId} after waiting for connection. This should not happen.`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn RequestContext.create(connection.orm.em, _next, {});\n\t\t\t},\n\t\t};\n\t\tpluginManager.addPlugin(connectionPlugin);\n\t};\n\n\tprivate mapAndAssignKeys = (result: D, entityType: new () => D, inputArgs: Partial<D>) => {\n\t\t// Clean the input and remove any GraphQL classes from the object\n\t\tconst assignmentObj = this.applyExternalIdFields(entityType, inputArgs);\n\t\treturn assign(result, assignmentObj, undefined, undefined, this.database.em);\n\t};\n\n\tprivate applyExternalIdFields = (target: AnyEntity | string, values: any) => {\n\t\tconst targetName = typeof target === 'string' ? target : target.name;\n\t\tconst map = externalIdFieldMap.get(targetName);\n\n\t\tconst mapFieldNames = (partialFilterObj: any) => {\n\t\t\tfor (const [from, to] of Object.entries(map || {})) {\n\t\t\t\tif (partialFilterObj[from]) {\n\t\t\t\t\tconst keys = Object.keys(partialFilterObj[from]);\n\t\t\t\t\tif (keys.length > 1) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected precisely 1 key in queryObj.${from} on ${target}, got ${JSON.stringify(\n\t\t\t\t\t\t\t\tpartialFilterObj[from],\n\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t4\n\t\t\t\t\t\t\t)}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tpartialFilterObj[to] = partialFilterObj[from][keys[0]];\n\t\t\t\t\tdelete partialFilterObj[from];\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Check for and/or/etc at the root level and handle correctly\n\t\tfor (const rootLevelKey of Object.keys(values)) {\n\t\t\tif (mikroObjectOperations.has(rootLevelKey)) {\n\t\t\t\tif (Array.isArray(values[rootLevelKey])) {\n\t\t\t\t\tfor (const field of values[rootLevelKey]) {\n\t\t\t\t\t\tmapFieldNames(field);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tmapFieldNames(values[rootLevelKey]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Map the rest of the field names as well\n\t\tmapFieldNames(values);\n\n\t\t// Traverse the nested entities\n\t\tconst { properties } = this.database.em.getMetadata().get(targetName);\n\t\tObject.values(properties)\n\t\t\t.filter((property) => typeof property.entity !== 'undefined' && values[property.name])\n\t\t\t.forEach((property) => {\n\t\t\t\tif (Array.isArray(values[property.name])) {\n\t\t\t\t\tvalues[property.name].forEach((value: any) =>\n\t\t\t\t\t\tthis.applyExternalIdFields(property.type, value)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvalues[property.name] = this.applyExternalIdFields(property.type, values[property.name]);\n\t\t\t\t}\n\t\t\t});\n\n\t\treturn values;\n\t};\n\n\t// Check if we have any keys that are a collection of entities\n\tpublic visitPathForPopulate = (entityName: string, updateArgBranch: any, populateBranch = '') => {\n\t\tconst { properties } = this.database.em.getMetadata().get(entityName);\n\t\tconst collectedPaths = populateBranch ? new Set<string>([populateBranch]) : new Set<string>([]);\n\n\t\tfor (const [key, value] of Object.entries(updateArgBranch ?? {})) {\n\t\t\tif (\n\t\t\t\t// If it's a relationship, go ahead and and '.' it in, recurse.\n\t\t\t\tproperties[key]?.kind === ReferenceKind.ONE_TO_ONE ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.ONE_TO_MANY ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.MANY_TO_ONE ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.MANY_TO_MANY\n\t\t\t) {\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t// In the case where the array is empty we also need to make sure we load the collection.\n\t\t\t\t\tcollectedPaths.add(appendPath(populateBranch, key));\n\n\t\t\t\t\tfor (const entry of value) {\n\t\t\t\t\t\t// Recurse\n\t\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof value === 'object') {\n\t\t\t\t\t// Recurse\n\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t);\n\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn collectedPaths;\n\t};\n\n\t// Some connections (ex. sqlite) require an explicit flush during batch inserts \n\t// to retrieve user defined primary keys correctly.\n\tprivate flushOnBatchInserts() {\n\t\tconst driver = this.em.getDriver();\n\t\treturn driver.constructor.name === 'SqliteDriver';\n\t};\n\n\t@TraceMethod()\n\tpublic async find(\n\t\tfilter: Filter<D>,\n\t\tpagination?: PaginationOptions,\n\t\tentityMetadata?: EntityMetadata,\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\t// If we have a span, update the name\n\t\ttrace?.span.updateName(`Mikro-Orm - Find ${this.entityType.name}`);\n\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running find with filter'\n\t\t);\n\n\t\t// Strip custom types out of the equation.\n\t\t// This query only works if we JSON.parse(JSON.stringify(filter)):\n\t\tconst where = traceSync((trace?: TraceOptions) => {\n\t\t\ttrace?.span.updateName('Convert filter to Mikro-Orm format');\n\t\t\treturn filter ? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType()) : undefined;\n\t\t})();\n\n\t\t// Convert from: { account: {id: '6' }}\n\t\t// to { accountId: '6' }\n\t\t// This conversion only works on root level objects\n\t\tconst whereWithAppliedExternalIdFields = where\n\t\t\t? this.applyExternalIdFields(this.entityType, where)\n\t\t\t: {};\n\n\t\t// Regions need some fancy handling with Query Builder. Process the where further\n\t\t// and return a Query Builder instance.\n\t\tconst query = this.em.createQueryBuilder(this.entityType);\n\t\tif (Object.keys(whereWithAppliedExternalIdFields).length > 0) {\n\t\t\tquery.andWhere(whereWithAppliedExternalIdFields);\n\t\t}\n\n\t\t// If we have specified a limit, offset or order then update the query\n\t\tif (pagination?.limit) query.limit(pagination.limit);\n\t\tif (pagination?.offset) query.offset(pagination.offset);\n\t\tif (pagination?.orderBy) query.orderBy({ ...pagination.orderBy });\n\n\t\t// Certain query filters can result in duplicate records once all joins are resolved\n\t\t// These duplicates can be discarded as related entities are returned to the\n\t\t// API consumer via field resolvers\n\t\tquery.setFlag(QueryFlag.DISTINCT);\n\n\t\t// 1:1 relations that aren't on the owning side need to get populated so the references get set.\n\t\t// This method is protected, but we need to use it from here, hence the `as any`.\n\t\tconst driver = this.database.em.getDriver();\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tquery.populate((driver as any).autoJoinOneToOneOwner(meta, []));\n\n\t\ttry {\n\t\t\tconst result = await startTrace(async (trace?: TraceOptions) => {\n\t\t\t\ttrace?.span.updateName('Mikro-Orm - Fetch Data');\n\t\t\t\treturn query.getResult();\n\t\t\t})();\n\n\t\t\tlogger.trace(`find ${this.entityType.name} result: ${result.length} rows`);\n\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tsafeErrorLog(logger, err, `find ${this.entityType.name} error`);\n\n\t\t\tif ((err as PostgresError)?.routine === 'InitializeSessionUserId') {\n\t\t\t\t// Throw if the user credentials are incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct user credentials for the database.'\n\t\t\t\t);\n\t\t\t} else if ((err as PostgresError)?.code === 'ECONNREFUSED') {\n\t\t\t\t// Throw if the database address or port is incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct address and port for the database.'\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t}\n\n\t@TraceMethod()\n\tpublic async findOne(\n\t\tfilter: Filter<D>,\n\t\tentityMetadata?: EntityMetadata,\n\t\ttrace?: TraceOptions\n\t): Promise<D | null> {\n\t\ttrace?.span.updateName(`Mikro-Orm - FindOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, filter: sanitiseFilterForLogging(filter) },\n\t\t\t'Running findOne with filter'\n\t\t);\n\n\t\tconst metadata = this.em.getMetadata().get(this.entityType.name);\n\t\tlet primaryKeyField = metadata.primaryKeys[0];\n\n\t\tif (!primaryKeyField && entityMetadata) {\n\t\t\t// When using virtual entities, MikroORM will have no primary keys.\n\t\t\t// In this scenario we actually know what the primary key is from\n\t\t\t// the GraphQL metadata, so we can go ahead and use it.\n\t\t\tprimaryKeyField = graphweaverMetadata.primaryKeyFieldForEntity(entityMetadata);\n\t\t}\n\n\t\tif (!primaryKeyField || metadata.primaryKeys.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Entity ${this.entityType.name} has ${metadata.primaryKeys.length} primary keys. We only support entities with a single primary key at this stage.`\n\t\t\t);\n\t\t}\n\n\t\tconst [result] = await this.find(filter, {\n\t\t\torderBy: { [primaryKeyField]: Sort.DESC },\n\t\t\toffset: 0,\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tlogger.trace({ result, entity: this.entityType.name }, 'findOne result');\n\n\t\treturn result;\n\t}\n\n\t@TraceMethod()\n\tpublic async findByRelatedId(\n\t\tentity: any,\n\t\trelatedField: string,\n\t\trelatedFieldIds: string[],\n\t\tfilter?: any,\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - findByRelatedId ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{\n\t\t\t\tentity: this.entityType.name,\n\t\t\t\trelatedField,\n\t\t\t\trelatedFieldIds,\n\t\t\t\tfilter: sanitiseFilterForLogging(filter),\n\t\t\t},\n\t\t\t'Running findByRelatedId'\n\t\t);\n\n\t\t// Any is the actual type from MikroORM, sorry folks.\n\t\tlet queryFilter: any = { [relatedField]: { $in: relatedFieldIds } };\n\n\t\tif (filter) {\n\t\t\t// JSON.parse(JSON.stringify()) is needed. See https://exogee.atlassian.net/browse/EXOGW-419\n\t\t\tconst gqlToMikroFilter = JSON.parse(JSON.stringify([gqlToMikro(filter, this.getDbType())]));\n\t\t\t// Since the user has supplied a filter, we need to and it in.\n\t\t\tqueryFilter = { $and: [queryFilter, ...gqlToMikroFilter] };\n\t\t}\n\n\t\tconst populate = [relatedField as AutoPath<typeof entity, PopulateHint>];\n\t\tconst result = await this.database.em.find(entity, queryFilter, {\n\t\t\t// We only need one result per entity.\n\t\t\tflags: [QueryFlag.DISTINCT],\n\n\t\t\t// We do want to populate the relation, however, see below.\n\t\t\tpopulate,\n\n\t\t\t// We'd love to use the default joined loading strategy, but it doesn't work with the populateWhere option.\n\t\t\tstrategy: LoadStrategy.SELECT_IN,\n\n\t\t\t// This tells MikroORM we only need to load the related entities if they match the filter specified above.\n\t\t\tpopulateWhere: PopulateHint.INFER,\n\t\t});\n\n\t\treturn result as D[];\n\t}\n\n\t@TraceMethod()\n\tpublic async updateOne(\n\t\tid: string | number,\n\t\tupdateArgs: Partial<D & { version?: number }>,\n\t\ttrace?: TraceOptions\n\t): Promise<D> {\n\t\ttrace?.span.updateName(`Mikro-Orm - updateOne ${this.entityType.name}`);\n\n\t\tlogger.trace(\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tupdateArgs: sanitiseFilterForLogging(updateArgs),\n\t\t\t\tentity: this.entityType.name,\n\t\t\t},\n\t\t\t'Running update with args'\n\t\t);\n\n\t\tconst entity = await this.database.em.findOne(this.entityType, id, {\n\t\t\t// This is an optimisation so that assign() doesn't have to go fetch everything one at a time.\n\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, updateArgs)] as `${string}.`[],\n\t\t});\n\n\t\tif (entity === null) {\n\t\t\tthrow new Error(`Unable to locate ${this.entityType.name} with ID: '${id}' for updating.`);\n\t\t}\n\n\t\tconst { version, ...updateArgsWithoutVersion } = updateArgs;\n\n\t\t// If a version has been sent, let's check it\n\t\tif (version) {\n\t\t\ttry {\n\t\t\t\tawait this.database.em.lock(entity, LockMode.OPTIMISTIC, version);\n\t\t\t} catch (err) {\n\t\t\t\tthrow new OptimisticLockError((err as Error)?.message, { entity });\n\t\t\t}\n\t\t}\n\n\t\t// For an update we also want to go ahead and remove the primary key if it's autoincremented, as\n\t\t// users should not be able to change the primary key. There are also scenarios like\n\t\t// GENERATED ALWAYS AS IDENTITY where even supplying the primary key in the update query will\n\t\t// cause an error.\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tfor (const key of meta.primaryKeys) {\n\t\t\tif (meta.properties[key].autoincrement) delete (updateArgsWithoutVersion as any)[key];\n\t\t}\n\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, updateArgsWithoutVersion as Partial<D>);\n\t\tawait this.database.em.persistAndFlush(entity);\n\n\t\tlogger.trace(`update ${this.entityType.name} entity`, entity);\n\n\t\treturn entity;\n\t}\n\n\t@TraceMethod()\n\tpublic async updateMany(\n\t\tupdateItems: Partial<D>[],\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - updateMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ updateItems: sanitiseFilterForLogging(updateItems), entity: this.entityType.name },\n\t\t\t'Running update many with args'\n\t\t);\n\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tconst primaryKeyField = meta.primaryKeys[0];\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\treturn Promise.all<D>(\n\t\t\t\tupdateItems.map(async (item) => {\n\t\t\t\t\tconst { [primaryKeyField]: primaryKey } = item as any;\n\t\t\t\t\tif (!primaryKey) throw new Error('You must pass an ID for this entity to update it.');\n\n\t\t\t\t\t// Find the entity in the database\n\t\t\t\t\tconst entity = await this.database.em.findOneOrFail(this.entityType, { [primaryKeyField]: primaryKey } as any, {\n\t\t\t\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, item)] as `${string}.`[],\n\t\t\t\t\t});\n\n\t\t\t\t\t// For an update we also want to go ahead and remove the primary key if it's autoincremented, as\n\t\t\t\t\t// users should not be able to change the primary key. There are also scenarios like\n\t\t\t\t\t// GENERATED ALWAYS AS IDENTITY where even supplying the primary key in the update query will\n\t\t\t\t\t// cause an error.\n\t\t\t\t\tfor (const key of meta.primaryKeys) {\n\t\t\t\t\t\tif (meta.properties[key].autoincrement) delete (item as any)[key];\n\t\t\t\t\t}\n\n\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace({ entity: this.entityType.name, entities }, 'updated items');\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async createOrUpdateMany(items: Partial<D>[], trace?: TraceOptions): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createOrUpdateMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ items: sanitiseFilterForLogging(items), entity: this.entityType.name },\n\t\t\t'Running create or update many with args'\n\t\t);\n\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tconst primaryKeyField = meta.primaryKeys[0];\n\t\tconst gwMetadata = graphweaverMetadata.getEntityMetadataByDataEntity(this.entityType);\n\t\tconst clientGeneratedPrimaryKeys = gwMetadata?.apiOptions?.clientGeneratedPrimaryKeys ?? false;\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\treturn Promise.all<D>(\n\t\t\t\titems.map(async (item) => {\n\t\t\t\t\tlet entity;\n\t\t\t\t\tconst { [primaryKeyField]: primaryKey } = item as any;\n\n\t\t\t\t\tif (primaryKey) {\n\t\t\t\t\t\tentity = await this.database.em.findOne(this.entityType, { [primaryKeyField]: primaryKey }, {\n\t\t\t\t\t\t\tpopulate: [\n\t\t\t\t\t\t\t\t...this.visitPathForPopulate(this.entityType.name, item),\n\t\t\t\t\t\t\t] as `${string}.`[],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (entity) {\n\t\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running update with item');\n\t\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\t} else if (clientGeneratedPrimaryKeys) {\n\t\t\t\t\t\t\tentity = new this.entityType();\n\t\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running create with client-generated key');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Entity ${this.entityType.name} with primary key '${primaryKey}' not found and clientGeneratedPrimaryKeys is not enabled.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tentity = new this.entityType();\n\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running create with item');\n\t\t\t\t\t}\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, entities: sanitiseFilterForLogging(entities) },\n\t\t\t'created or updated items'\n\t\t);\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async createOne(createArgs: Partial<D>, trace?: TraceOptions): Promise<D> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ createArgs: sanitiseFilterForLogging(createArgs), entity: this.entityType.name },\n\t\t\t'Running create with args'\n\t\t);\n\n\t\tconst entity = new this.entityType();\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, createArgs);\n\t\tawait this.database.em.persistAndFlush(entity as Partial<D>);\n\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, result: sanitiseFilterForLogging(entity) },\n\t\t\t'create result'\n\t\t);\n\n\t\treturn entity;\n\t}\n\n\t@TraceMethod()\n\tpublic async createMany(createItems: Partial<D>[], trace?: TraceOptions): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createMany ${this.entityType.name}`);\n\t\treturn this._createMany(createItems);\n\t}\n\n\tpublic async createTraces(createItems: Partial<D>[]): Promise<D[]> {\n\t\treturn this._createMany(createItems);\n\t}\n\n\tprivate async _createMany(createItems: Partial<D>[]) {\n\t\tlogger.trace(\n\t\t\t{ createItems: sanitiseFilterForLogging(createItems), entity: this.entityType.name },\n\t\t\t'Running create with args'\n\t\t);\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\tconst result: D[] = [];\n\t\t\tfor (const item of createItems) {\n\t\t\t\tconst entity = new this.entityType();\n\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\tthis.database.em.persist(entity as Partial<D>);\n\t\t\t\tresult.push(entity);\n\t\t\t}\n\n\t\t\tif (this.flushOnBatchInserts()) {\n\t\t\t\tawait this.database.em.flush();\n\t\t\t}\n\n\t\t\treturn result;\n\t\t});\n\n\t\tlogger.trace({ entity: this.entityType.name, entities }, 'created items');\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async deleteOne(filter: Filter<D>, trace?: TraceOptions): Promise<boolean> {\n\t\ttrace?.span.updateName(`Mikro-Orm - deleteOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running delete with filter.'\n\t\t);\n\t\tconst where = filter\n\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t: undefined;\n\t\tconst whereWithAppliedExternalIdFields =\n\t\t\twhere && this.applyExternalIdFields(this.entityType, where);\n\n\t\tconst deletedRows = await this.database.em.nativeDelete(\n\t\t\tthis.entityType,\n\t\t\twhereWithAppliedExternalIdFields\n\t\t);\n\n\t\tif (deletedRows > 1) {\n\t\t\tthrow new Error('Multiple deleted rows');\n\t\t}\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn deletedRows === 1;\n\t}\n\n\t@TraceMethod()\n\tpublic async deleteMany(filter: Filter<D>, trace?: TraceOptions): Promise<boolean> {\n\t\ttrace?.span.updateName(`Mikro-Orm - deleteMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running delete'\n\t\t);\n\n\t\tconst deletedRows = await this.database.transactional<number>(async () => {\n\t\t\tconst where = filter\n\t\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t\t: undefined;\n\t\t\tconst whereWithAppliedExternalIdFields =\n\t\t\t\twhere && this.applyExternalIdFields(this.entityType, where);\n\n\t\t\tconst toDelete = await this.database.em.count(\n\t\t\t\tthis.entityType,\n\t\t\t\twhereWithAppliedExternalIdFields\n\t\t\t);\n\t\t\tconst deletedCount = await this.database.em.nativeDelete(\n\t\t\t\tthis.entityType,\n\t\t\t\twhereWithAppliedExternalIdFields\n\t\t\t);\n\n\t\t\tif (deletedCount !== toDelete) {\n\t\t\t\tthrow new Error('We did not delete any rows, rolling back.');\n\t\t\t}\n\n\t\t\treturn deletedCount;\n\t\t});\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn true;\n\t}\n\n\tpublic foreignKeyForRelationshipField?(field: FieldMetadata, dataEntity: D) {\n\t\tconst value = dataEntity[field.name as keyof D];\n\n\t\tif (Reference.isReference(value)) {\n\t\t\tconst { properties } = this.database.em.getMetadata().get(this.entityType);\n\t\t\tconst property = properties[field.name];\n\t\t\tconst [primaryKey] = property.targetMeta?.primaryKeys ?? [];\n\t\t\tif (!primaryKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not determine primary key for ${field.name} on ${this.entityType.name}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst foreignKey = (value.unwrap() as any)[primaryKey];\n\t\t\tif (foreignKey === undefined || foreignKey === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not read foreign key from reference: ${value.unwrap()} with primary key name ${primaryKey}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn foreignKey;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t@TraceMethod()\n\tpublic async aggregate(\n\t\tfilter: Filter<D>,\n\t\trequestedAggregations: Set<AggregationType>,\n\t\ttrace?: TraceOptions\n\t): Promise<AggregationResult> {\n\t\ttrace?.span.updateName(`Mikro-Orm - aggregate ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running aggregate with filter'\n\t\t);\n\n\t\t// Strip custom types out of the equation.\n\t\t// This query only works if we JSON.parse(JSON.stringify(filter)):\n\t\t//\n\t\t// query {\n\t\t// drivers (filter: { region: { name: \"North Shore\" }}) {\n\t\t// id\n\t\t// }\n\t\t// }\n\t\tconst where = filter\n\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t: undefined;\n\n\t\t// Convert from: { account: {id: '6' }}\n\t\t// to { accountId: '6' }\n\t\t// This conversion only works on root level objects\n\t\tconst whereWithAppliedExternalIdFields = where\n\t\t\t? this.applyExternalIdFields(this.entityType, where)\n\t\t\t: {};\n\n\t\t// Regions need some fancy handling with Query Builder. Process the where further\n\t\t// and return a Query Builder instance.\n\t\tconst query = this.em.createQueryBuilder(this.entityType);\n\n\t\tif (Object.keys(whereWithAppliedExternalIdFields).length > 0) {\n\t\t\tquery.andWhere(whereWithAppliedExternalIdFields);\n\t\t}\n\n\t\tconst result: AggregationResult = {};\n\n\t\ttry {\n\t\t\tif (requestedAggregations.has(AggregationType.COUNT)) {\n\t\t\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\t\t\tif (meta.primaryKeys.length) {\n\t\t\t\t\t// It's a standard entity with primary keys, we can do a full distinct\n\t\t\t\t\t// on these keys.\n\t\t\t\t\tresult.count = await query.getCount(meta.primaryKeys, true);\n\t\t\t\t} else {\n\t\t\t\t\t// It's either a virtual entity, or it's an entity without primary keys.\n\t\t\t\t\t// We just need to count * as a fallback, no distinct.\n\t\t\t\t\tconst [firstRow] = await query.select(sql`count(*)`.as('count')).execute();\n\t\t\t\t\tresult.count = firstRow.count;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tsafeErrorLog(logger, err, `find ${this.entityType.name} error`);\n\n\t\t\tif ((err as PostgresError)?.routine === 'InitializeSessionUserId') {\n\t\t\t\t// Throw if the user credentials are incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct user credentials for the database.'\n\t\t\t\t);\n\t\t\t} else if ((err as PostgresError)?.code === 'ECONNREFUSED') {\n\t\t\t\t// Throw if the database address or port is incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct address and port for the database.'\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAUO;AAUP,oBAAqC;AACrC,kBAOO;AACP,gCAAmD;AAEnD,eAWO;AAEP,mBAA8D;AAC9D,oBAAuB;AAOvB,MAAM,mBAAmB,oBAAI,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;AACxD,MAAM,wBAAwB,oBAAI,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;AAC7D,MAAM,wBAAwB,oBAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AAEzD,MAAM,aAAa,CAAC,MAAc,YACjC,KAAK,SAAS,GAAG,IAAI,IAAI,OAAO,KAAK;AAE/B,MAAM,aAAa,CAAC,QAAa,iBAAqC;AAC5E,MAAI,MAAM,QAAQ,MAAM,GAAG;AAC1B,WAAO,OAAO,IAAI,CAAC,YAAY,WAAW,SAAS,YAAY,CAAC;AAAA,EACjE,WAAW,OAAO,WAAW,YAAY,WAAW,MAAM;AACzD,eAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AAEtC,UAAI,OAAO,GAAG,MAAM,KAAM;AAE1B,UAAI,iBAAiB,IAAI,GAAG,GAAG;AAE9B,eAAO,IAAI,QAAQ,KAAK,GAAG,CAAC,IAAI,WAAW,OAAO,GAAG,GAAG,YAAY;AACpE,eAAO,OAAO,GAAG;AAAA,MAClB,WAAW,OAAO,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,QAAQ,OAAO,GAAG,CAAC,GAAG;AAE1E,eA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AS;AAAA,QACzB;AAAA,MACD;AAAA,IACD,SAAS,KAAK;AACb,sCAAa,sBAAQ,KAAK,QAAQ,KAAK,WAAW,IAAI,QAAQ;AAE9D,UAAK,KAAuB,YAAY,2BAA2B;AAElE,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD,WAAY,KAAuB,SAAS,gBAAgB;AAE3D,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD,OAAO;AACN,cAAM;AAAA,MACP;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;AA9hBc;AAAA,MADZ,gCAAY;AAAA,GAhPD,qBAiPC;AAgFA;AAAA,MADZ,gCAAY;AAAA,GAhUD,qBAiUC;AAuCA;AAAA,MADZ,gCAAY;AAAA,GAvWD,qBAwWC;AA+CA;AAAA,MADZ,gCAAY;AAAA,GAtZD,qBAuZC;AAsDA;AAAA,MADZ,gCAAY;AAAA,GA5cD,qBA6cC;AA6CA;AAAA,MADZ,gCAAY;AAAA,GAzfD,qBA0fC;AAyDA;AAAA,MADZ,gCAAY;AAAA,GAljBD,qBAmjBC;AAoBA;AAAA,MADZ,gCAAY;AAAA,GAtkBD,qBAukBC;AAqCA;AAAA,MADZ,gCAAY;AAAA,GA3mBD,qBA4mBC;AA2BA;AAAA,MADZ,gCAAY;AAAA,GAtoBD,qBAuoBC;AA8DA;AAAA,MADZ,gCAAY;AAAA,GApsBD,qBAqsBC;",
|
|
4
|
+
"sourcesContent": ["import {\n\tAggregationType,\n\tBackendProvider,\n\tgraphweaverMetadata,\n\tGraphweaverPluginNextFunction,\n\tGraphweaverRequestEvent,\n\tSort,\n\ttrace as startTrace,\n\tTraceMethod,\n\ttraceSync,\n} from '@exogee/graphweaver';\nimport type {\n\tAggregationResult,\n\tBackendProviderConfig,\n\tEntityMetadata,\n\tFieldMetadata,\n\tFilter,\n\tPaginationOptions,\n\tTraceOptions,\n} from '@exogee/graphweaver';\nimport { logger, safeErrorLog } from '@exogee/logger';\nimport {\n\tAutoPath,\n\tLoadStrategy,\n\tPopulateHint,\n\tReference,\n\tRequestContext,\n\tsql,\n} from '@mikro-orm/core';\nimport { pluginManager, apolloPluginManager } from '@exogee/graphweaver-server';\n\nimport {\n\tLockMode,\n\tQueryFlag,\n\tReferenceKind,\n\tConnectionManager,\n\texternalIdFieldMap,\n\tAnyEntity,\n\tIsolationLevel,\n\tConnectionOptions,\n\tconnectToDatabase,\n\tDatabaseType,\n} from '..';\n\nimport { OptimisticLockError, sanitiseFilterForLogging } from '../utils';\nimport { assign } from './assign';\n\ntype PostgresError = {\n\tcode: string;\n\troutine: string;\n};\n\nconst objectOperations = new Set(['_and', '_or', '_not']);\nconst mikroObjectOperations = new Set(['$and', '$or', '$not']);\nconst nullBooleanOperations = new Set(['null', 'notnull']);\n\nconst appendPath = (path: string, newPath: string) =>\n\tpath.length ? `${path}.${newPath}` : newPath;\n\nexport const gqlToMikro = (filter: any, databaseType?: DatabaseType): any => {\n\tif (Array.isArray(filter)) {\n\t\treturn filter.map((element) => gqlToMikro(element, databaseType));\n\t} else if (typeof filter === 'object' && filter !== null) {\n\t\tfor (const key of Object.keys(filter)) {\n\t\t\t// A null here is a user-specified value and is valid to filter on\n\t\t\tif (filter[key] === null) continue;\n\n\t\t\tif (objectOperations.has(key)) {\n\t\t\t\t// { _not: '1' } => { $not: '1' }\n\t\t\t\tfilter[key.replace('_', '$')] = gqlToMikro(filter[key], databaseType);\n\t\t\t\tdelete filter[key];\n\t\t\t} else if (typeof filter[key] === 'object' && !Array.isArray(filter[key])) {\n\t\t\t\t// Recurse over nested filters only (arrays are an argument to a filter, not a nested filter)\n\t\t\t\tfilter[key] = gqlToMikro(filter[key], databaseType);\n\t\t\t} else if (key.indexOf('_') >= 0) {\n\t\t\t\tconst [newKey, operator] = key.split('_');\n\t\t\t\tlet newValue;\n\t\t\t\tif (nullBooleanOperations.has(operator) && typeof filter[key] === 'boolean') {\n\t\t\t\t\t// { firstName_null: true } => { firstName: { $eq: null } } or { firstName_null: false } => { firstName: { $ne: null } }\n\t\t\t\t\t// { firstName_notnull: true } => { firstName: { $ne: null } } or { firstName_notnull: false } => { firstName: { $eq: null } }\n\t\t\t\t\tnewValue =\n\t\t\t\t\t\t(filter[key] && operator === 'null') || (!filter[key] && operator === 'notnull')\n\t\t\t\t\t\t\t? { $eq: null }\n\t\t\t\t\t\t\t: { $ne: null };\n\t\t\t\t} else if (operator === 'ilike' && databaseType !== 'postgresql') {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t`The $ilike operator is not supported by ${databaseType} databases. Operator coerced to $like.`\n\t\t\t\t\t);\n\t\t\t\t\tnewValue = { $like: filter[key] };\n\t\t\t\t} else {\n\t\t\t\t\t// { firstName_in: ['k', 'b'] } => { firstName: { $in: ['k', 'b'] } }\n\t\t\t\t\tnewValue = { [`$${operator}`]: gqlToMikro(filter[key], databaseType) };\n\t\t\t\t\t// They can construct multiple filters for the same key. In that case we need\n\t\t\t\t\t// to append them all into an object.\n\t\t\t\t}\n\n\t\t\t\tif (typeof filter[newKey] !== 'undefined') {\n\t\t\t\t\tif (typeof filter[newKey] !== 'object') {\n\t\t\t\t\t\tif (typeof newValue === 'object' && '$eq' in newValue) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`property ${newKey} on filter is ambiguous. There are two values for this property: ${filter[newKey]} and ${newValue.$eq}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfilter[newKey] = { ...{ $eq: filter[newKey] }, ...newValue };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (newValue && typeof newValue === 'object' && '$eq' in newValue) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`property ${newKey} on filter is ambiguous. There are two values for this property: ${JSON.stringify(\n\t\t\t\t\t\t\t\t\tfilter[newKey]\n\t\t\t\t\t\t\t\t)} and ${JSON.stringify(newValue)}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfilter[newKey] = { ...filter[newKey], ...newValue };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfilter[newKey] = newValue;\n\t\t\t\t}\n\n\t\t\t\tdelete filter[key];\n\t\t\t}\n\t\t}\n\t}\n\treturn filter;\n};\n\nexport interface AdditionalOptions {\n\ttransactionIsolationLevel?: IsolationLevel;\n\tbackendDisplayName?: string;\n}\n\nexport class MikroBackendProvider<D> implements BackendProvider<D> {\n\tprivate _backendId: string;\n\n\tprivate connection: ConnectionOptions;\n\n\tpublic entityType: new () => D;\n\tpublic connectionManagerId?: string;\n\tprivate transactionIsolationLevel!: IsolationLevel;\n\n\t// This is an optional setting that allows you to control how this provider is displayed in the Admin UI.\n\t// If you do not set a value, it will default to 'REST (hostname of baseUrl)'. Entities are grouped by\n\t// their backend's display name, so if you want to group them in a more specific way, this is the way to do it.\n\tpublic readonly backendDisplayName?: string;\n\n\tpublic readonly supportsInFilter = true;\n\n\t// Default backend provider config\n\tpublic readonly backendProviderConfig: BackendProviderConfig = {\n\t\tfilter: true,\n\t\tpagination: false,\n\t\torderBy: false,\n\t\tsupportedAggregationTypes: new Set<AggregationType>([AggregationType.COUNT]),\n\t\tsupportsPseudoCursorPagination: true,\n\t};\n\n\tget backendId() {\n\t\treturn this._backendId;\n\t}\n\n\tprivate get database() {\n\t\t// If we have a connection manager ID then use that else fallback to the Database\n\t\tif (!this.connectionManagerId) return ConnectionManager.default;\n\t\treturn ConnectionManager.database(this.connectionManagerId) || ConnectionManager.default;\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get transactional() {\n\t\treturn this.database.transactional;\n\t}\n\n\tpublic async withTransaction<T>(callback: () => Promise<T>) {\n\t\treturn this.database.transactional<T>(callback, this.transactionIsolationLevel);\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get em() {\n\t\treturn this.database.em;\n\t}\n\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\ttransactionIsolationLevel?: IsolationLevel\n\t);\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\tadditionalOptions?: AdditionalOptions\n\t);\n\tpublic constructor(\n\t\tmikroType: new () => D,\n\t\tconnection: ConnectionOptions,\n\t\toptionsOrIsolationLevel: AdditionalOptions | IsolationLevel = {\n\t\t\ttransactionIsolationLevel: IsolationLevel.REPEATABLE_READ,\n\t\t}\n\t) {\n\t\tconst options =\n\t\t\ttypeof optionsOrIsolationLevel === 'object'\n\t\t\t\t? optionsOrIsolationLevel\n\t\t\t\t: {\n\t\t\t\t\t\ttransactionIsolationLevel: optionsOrIsolationLevel,\n\t\t\t\t\t};\n\n\t\tthis.entityType = mikroType;\n\t\tthis.connectionManagerId = connection.connectionManagerId;\n\t\tthis._backendId = `mikro-orm-${connection.connectionManagerId || ''}`;\n\t\tthis.transactionIsolationLevel =\n\t\t\toptions.transactionIsolationLevel ?? IsolationLevel.REPEATABLE_READ;\n\t\tthis.backendDisplayName = options.backendDisplayName;\n\t\tthis.connection = connection;\n\t\tthis.addRequestContext();\n\t\tthis.connectToDatabase();\n\t}\n\tprivate getDbType(): DatabaseType {\n\t\tconst driver = this.em.getDriver().constructor.name;\n\t\t// This used to import the actual drivers, but since they're optional it makes more sense\n\t\t// to just use the strings. Using startsWith to handle ESBuild minification that may rename classes.\n\t\tif (driver.startsWith('MsSqlDriver')) return 'mssql';\n\t\tif (driver.startsWith('MySqlDriver')) return 'mysql';\n\t\tif (driver.startsWith('PostgreSqlDriver')) return 'postgresql';\n\t\tif (driver.startsWith('SqliteDriver')) return 'sqlite';\n\n\t\tthrow new Error(`This driver (${driver}) is not supported!`);\n\t}\n\n\tprivate connectToDatabase = async () => {\n\t\tconst connectionManagerId = this.connectionManagerId;\n\t\tif (!connectionManagerId) {\n\t\t\tthrow new Error('Expected connectionManagerId to be defined when calling addRequestContext.');\n\t\t}\n\n\t\tapolloPluginManager.addPlugin(connectionManagerId, connectToDatabase(this.connection));\n\t};\n\n\tprivate addRequestContext = () => {\n\t\tconst connectionManagerId = this.connectionManagerId;\n\t\tif (!connectionManagerId) {\n\t\t\tthrow new Error('Expected connectionManagerId to be defined when calling addRequestContext.');\n\t\t}\n\n\t\tconst connectionPlugin = {\n\t\t\tname: connectionManagerId,\n\t\t\tevent: GraphweaverRequestEvent.OnRequest,\n\t\t\tnext: async (_: GraphweaverRequestEvent, _next: GraphweaverPluginNextFunction) => {\n\t\t\t\tlogger.trace(`Graphweaver OnRequest plugin called`);\n\n\t\t\t\tconst connection = await ConnectionManager.awaitableDatabase(connectionManagerId);\n\n\t\t\t\tif (!connection) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No database connection found for connectionManagerId: ${connectionManagerId} after waiting for connection. This should not happen.`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn RequestContext.create(connection.orm.em, _next, {});\n\t\t\t},\n\t\t};\n\t\tpluginManager.addPlugin(connectionPlugin);\n\t};\n\n\tprivate mapAndAssignKeys = (result: D, entityType: new () => D, inputArgs: Partial<D>) => {\n\t\t// Clean the input and remove any GraphQL classes from the object\n\t\tconst assignmentObj = this.applyExternalIdFields(entityType, inputArgs);\n\t\treturn assign(result, assignmentObj, undefined, undefined, this.database.em);\n\t};\n\n\tprivate applyExternalIdFields = (target: AnyEntity | string, values: any) => {\n\t\tconst targetName = typeof target === 'string' ? target : target.name;\n\t\tconst map = externalIdFieldMap.get(targetName);\n\n\t\tconst mapFieldNames = (partialFilterObj: any) => {\n\t\t\tfor (const [from, to] of Object.entries(map || {})) {\n\t\t\t\tif (partialFilterObj[from]) {\n\t\t\t\t\tconst keys = Object.keys(partialFilterObj[from]);\n\t\t\t\t\tif (keys.length > 1) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected precisely 1 key in queryObj.${from} on ${target}, got ${JSON.stringify(\n\t\t\t\t\t\t\t\tpartialFilterObj[from],\n\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t4\n\t\t\t\t\t\t\t)}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tpartialFilterObj[to] = partialFilterObj[from][keys[0]];\n\t\t\t\t\tdelete partialFilterObj[from];\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Check for and/or/etc at the root level and handle correctly\n\t\tfor (const rootLevelKey of Object.keys(values)) {\n\t\t\tif (mikroObjectOperations.has(rootLevelKey)) {\n\t\t\t\tif (Array.isArray(values[rootLevelKey])) {\n\t\t\t\t\tfor (const field of values[rootLevelKey]) {\n\t\t\t\t\t\tmapFieldNames(field);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tmapFieldNames(values[rootLevelKey]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Map the rest of the field names as well\n\t\tmapFieldNames(values);\n\n\t\t// Traverse the nested entities\n\t\tconst { properties } = this.database.em.getMetadata().get(targetName);\n\t\tObject.values(properties)\n\t\t\t.filter((property) => typeof property.entity !== 'undefined' && values[property.name])\n\t\t\t.forEach((property) => {\n\t\t\t\tif (Array.isArray(values[property.name])) {\n\t\t\t\t\tvalues[property.name].forEach((value: any) =>\n\t\t\t\t\t\tthis.applyExternalIdFields(property.type, value)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvalues[property.name] = this.applyExternalIdFields(property.type, values[property.name]);\n\t\t\t\t}\n\t\t\t});\n\n\t\treturn values;\n\t};\n\n\t// Check if we have any keys that are a collection of entities\n\tpublic visitPathForPopulate = (entityName: string, updateArgBranch: any, populateBranch = '') => {\n\t\tconst { properties } = this.database.em.getMetadata().get(entityName);\n\t\tconst collectedPaths = populateBranch ? new Set<string>([populateBranch]) : new Set<string>([]);\n\n\t\tfor (const [key, value] of Object.entries(updateArgBranch ?? {})) {\n\t\t\tif (\n\t\t\t\t// If it's a relationship, go ahead and and '.' it in, recurse.\n\t\t\t\tproperties[key]?.kind === ReferenceKind.ONE_TO_ONE ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.ONE_TO_MANY ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.MANY_TO_ONE ||\n\t\t\t\tproperties[key]?.kind === ReferenceKind.MANY_TO_MANY\n\t\t\t) {\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t// In the case where the array is empty we also need to make sure we load the collection.\n\t\t\t\t\tcollectedPaths.add(appendPath(populateBranch, key));\n\n\t\t\t\t\tfor (const entry of value) {\n\t\t\t\t\t\t// Recurse\n\t\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof value === 'object') {\n\t\t\t\t\t// Recurse\n\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t);\n\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn collectedPaths;\n\t};\n\n\t@TraceMethod()\n\tpublic async find(\n\t\tfilter: Filter<D>,\n\t\tpagination?: PaginationOptions,\n\t\tentityMetadata?: EntityMetadata,\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\t// If we have a span, update the name\n\t\ttrace?.span.updateName(`Mikro-Orm - Find ${this.entityType.name}`);\n\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running find with filter'\n\t\t);\n\n\t\t// Strip custom types out of the equation.\n\t\t// This query only works if we JSON.parse(JSON.stringify(filter)):\n\t\tconst where = traceSync((trace?: TraceOptions) => {\n\t\t\ttrace?.span.updateName('Convert filter to Mikro-Orm format');\n\t\t\treturn filter ? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType()) : undefined;\n\t\t})();\n\n\t\t// Convert from: { account: {id: '6' }}\n\t\t// to { accountId: '6' }\n\t\t// This conversion only works on root level objects\n\t\tconst whereWithAppliedExternalIdFields = where\n\t\t\t? this.applyExternalIdFields(this.entityType, where)\n\t\t\t: {};\n\n\t\t// Regions need some fancy handling with Query Builder. Process the where further\n\t\t// and return a Query Builder instance.\n\t\tconst query = this.em.createQueryBuilder(this.entityType);\n\t\tif (Object.keys(whereWithAppliedExternalIdFields).length > 0) {\n\t\t\tquery.andWhere(whereWithAppliedExternalIdFields);\n\t\t}\n\n\t\t// If we have specified a limit, offset or order then update the query\n\t\tif (pagination?.limit) query.limit(pagination.limit);\n\t\tif (pagination?.offset) query.offset(pagination.offset);\n\t\tif (pagination?.orderBy) query.orderBy({ ...pagination.orderBy });\n\n\t\t// Certain query filters can result in duplicate records once all joins are resolved\n\t\t// These duplicates can be discarded as related entities are returned to the\n\t\t// API consumer via field resolvers\n\t\tquery.setFlag(QueryFlag.DISTINCT);\n\n\t\t// 1:1 relations that aren't on the owning side need to get populated so the references get set.\n\t\t// This method is protected, but we need to use it from here, hence the `as any`.\n\t\tconst driver = this.database.em.getDriver();\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tquery.populate((driver as any).autoJoinOneToOneOwner(meta, []));\n\n\t\ttry {\n\t\t\tconst result = await startTrace(async (trace?: TraceOptions) => {\n\t\t\t\ttrace?.span.updateName('Mikro-Orm - Fetch Data');\n\t\t\t\treturn query.getResult();\n\t\t\t})();\n\n\t\t\tlogger.trace(`find ${this.entityType.name} result: ${result.length} rows`);\n\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tsafeErrorLog(logger, err, `find ${this.entityType.name} error`);\n\n\t\t\tif ((err as PostgresError)?.routine === 'InitializeSessionUserId') {\n\t\t\t\t// Throw if the user credentials are incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct user credentials for the database.'\n\t\t\t\t);\n\t\t\t} else if ((err as PostgresError)?.code === 'ECONNREFUSED') {\n\t\t\t\t// Throw if the database address or port is incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct address and port for the database.'\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t}\n\n\t@TraceMethod()\n\tpublic async findOne(\n\t\tfilter: Filter<D>,\n\t\tentityMetadata?: EntityMetadata,\n\t\ttrace?: TraceOptions\n\t): Promise<D | null> {\n\t\ttrace?.span.updateName(`Mikro-Orm - FindOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, filter: sanitiseFilterForLogging(filter) },\n\t\t\t'Running findOne with filter'\n\t\t);\n\n\t\tconst metadata = this.em.getMetadata().get(this.entityType.name);\n\t\tlet primaryKeyField = metadata.primaryKeys[0];\n\n\t\tif (!primaryKeyField && entityMetadata) {\n\t\t\t// When using virtual entities, MikroORM will have no primary keys.\n\t\t\t// In this scenario we actually know what the primary key is from\n\t\t\t// the GraphQL metadata, so we can go ahead and use it.\n\t\t\tprimaryKeyField = graphweaverMetadata.primaryKeyFieldForEntity(entityMetadata);\n\t\t}\n\n\t\tif (!primaryKeyField || metadata.primaryKeys.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Entity ${this.entityType.name} has ${metadata.primaryKeys.length} primary keys. We only support entities with a single primary key at this stage.`\n\t\t\t);\n\t\t}\n\n\t\tconst [result] = await this.find(filter, {\n\t\t\torderBy: { [primaryKeyField]: Sort.DESC },\n\t\t\toffset: 0,\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tlogger.trace({ result, entity: this.entityType.name }, 'findOne result');\n\n\t\treturn result;\n\t}\n\n\t@TraceMethod()\n\tpublic async findByRelatedId(\n\t\tentity: any,\n\t\trelatedField: string,\n\t\trelatedFieldIds: string[],\n\t\tfilter?: any,\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - findByRelatedId ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{\n\t\t\t\tentity: this.entityType.name,\n\t\t\t\trelatedField,\n\t\t\t\trelatedFieldIds,\n\t\t\t\tfilter: sanitiseFilterForLogging(filter),\n\t\t\t},\n\t\t\t'Running findByRelatedId'\n\t\t);\n\n\t\t// Any is the actual type from MikroORM, sorry folks.\n\t\tlet queryFilter: any = { [relatedField]: { $in: relatedFieldIds } };\n\n\t\tif (filter) {\n\t\t\t// JSON.parse(JSON.stringify()) is needed. See https://exogee.atlassian.net/browse/EXOGW-419\n\t\t\tconst gqlToMikroFilter = JSON.parse(JSON.stringify([gqlToMikro(filter, this.getDbType())]));\n\t\t\t// Since the user has supplied a filter, we need to and it in.\n\t\t\tqueryFilter = { $and: [queryFilter, ...gqlToMikroFilter] };\n\t\t}\n\n\t\tconst populate = [relatedField as AutoPath<typeof entity, PopulateHint>];\n\t\tconst result = await this.database.em.find(entity, queryFilter, {\n\t\t\t// We only need one result per entity.\n\t\t\tflags: [QueryFlag.DISTINCT],\n\n\t\t\t// We do want to populate the relation, however, see below.\n\t\t\tpopulate,\n\n\t\t\t// We'd love to use the default joined loading strategy, but it doesn't work with the populateWhere option.\n\t\t\tstrategy: LoadStrategy.SELECT_IN,\n\n\t\t\t// This tells MikroORM we only need to load the related entities if they match the filter specified above.\n\t\t\tpopulateWhere: PopulateHint.INFER,\n\t\t});\n\n\t\treturn result as D[];\n\t}\n\n\t@TraceMethod()\n\tpublic async updateOne(\n\t\tid: string | number,\n\t\tupdateArgs: Partial<D & { version?: number }>,\n\t\ttrace?: TraceOptions\n\t): Promise<D> {\n\t\ttrace?.span.updateName(`Mikro-Orm - updateOne ${this.entityType.name}`);\n\n\t\tlogger.trace(\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tupdateArgs: sanitiseFilterForLogging(updateArgs),\n\t\t\t\tentity: this.entityType.name,\n\t\t\t},\n\t\t\t'Running update with args'\n\t\t);\n\n\t\tconst entity = await this.database.em.findOne(this.entityType, id, {\n\t\t\t// This is an optimisation so that assign() doesn't have to go fetch everything one at a time.\n\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, updateArgs)] as `${string}.`[],\n\t\t});\n\n\t\tif (entity === null) {\n\t\t\tthrow new Error(`Unable to locate ${this.entityType.name} with ID: '${id}' for updating.`);\n\t\t}\n\n\t\tconst { version, ...updateArgsWithoutVersion } = updateArgs;\n\n\t\t// If a version has been sent, let's check it\n\t\tif (version) {\n\t\t\ttry {\n\t\t\t\tawait this.database.em.lock(entity, LockMode.OPTIMISTIC, version);\n\t\t\t} catch (err) {\n\t\t\t\tthrow new OptimisticLockError((err as Error)?.message, { entity });\n\t\t\t}\n\t\t}\n\n\t\t// For an update we also want to go ahead and remove the primary key if it's autoincremented, as\n\t\t// users should not be able to change the primary key. There are also scenarios like\n\t\t// GENERATED ALWAYS AS IDENTITY where even supplying the primary key in the update query will\n\t\t// cause an error.\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tfor (const key of meta.primaryKeys) {\n\t\t\tif (meta.properties[key].autoincrement) delete (updateArgsWithoutVersion as any)[key];\n\t\t}\n\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, updateArgsWithoutVersion as Partial<D>);\n\t\tawait this.database.em.persistAndFlush(entity);\n\n\t\tlogger.trace(`update ${this.entityType.name} entity`, entity);\n\n\t\treturn entity;\n\t}\n\n\t@TraceMethod()\n\tpublic async updateMany(\n\t\tupdateItems: Partial<D>[],\n\t\ttrace?: TraceOptions\n\t): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - updateMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ updateItems: sanitiseFilterForLogging(updateItems), entity: this.entityType.name },\n\t\t\t'Running update many with args'\n\t\t);\n\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tconst primaryKeyField = meta.primaryKeys[0];\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\treturn Promise.all<D>(\n\t\t\t\tupdateItems.map(async (item) => {\n\t\t\t\t\tconst { [primaryKeyField]: primaryKey } = item as any;\n\t\t\t\t\tif (!primaryKey) throw new Error('You must pass an ID for this entity to update it.');\n\n\t\t\t\t\t// Find the entity in the database\n\t\t\t\t\tconst entity = await this.database.em.findOneOrFail(this.entityType, { [primaryKeyField]: primaryKey } as any, {\n\t\t\t\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, item)] as `${string}.`[],\n\t\t\t\t\t});\n\n\t\t\t\t\t// For an update we also want to go ahead and remove the primary key if it's autoincremented, as\n\t\t\t\t\t// users should not be able to change the primary key. There are also scenarios like\n\t\t\t\t\t// GENERATED ALWAYS AS IDENTITY where even supplying the primary key in the update query will\n\t\t\t\t\t// cause an error.\n\t\t\t\t\tfor (const key of meta.primaryKeys) {\n\t\t\t\t\t\tif (meta.properties[key].autoincrement) delete (item as any)[key];\n\t\t\t\t\t}\n\n\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace({ entity: this.entityType.name, entities }, 'updated items');\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async createOrUpdateMany(items: Partial<D>[], trace?: TraceOptions): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createOrUpdateMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ items: sanitiseFilterForLogging(items), entity: this.entityType.name },\n\t\t\t'Running create or update many with args'\n\t\t);\n\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tconst primaryKeyField = meta.primaryKeys[0];\n\t\tconst gwMetadata = graphweaverMetadata.getEntityMetadataByDataEntity(this.entityType);\n\t\tconst clientGeneratedPrimaryKeys = gwMetadata?.apiOptions?.clientGeneratedPrimaryKeys ?? false;\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\treturn Promise.all<D>(\n\t\t\t\titems.map(async (item) => {\n\t\t\t\t\tlet entity;\n\t\t\t\t\tconst { [primaryKeyField]: primaryKey } = item as any;\n\n\t\t\t\t\tif (primaryKey) {\n\t\t\t\t\t\tentity = await this.database.em.findOne(this.entityType, { [primaryKeyField]: primaryKey }, {\n\t\t\t\t\t\t\tpopulate: [\n\t\t\t\t\t\t\t\t...this.visitPathForPopulate(this.entityType.name, item),\n\t\t\t\t\t\t\t] as `${string}.`[],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (entity) {\n\t\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running update with item');\n\t\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\t} else if (clientGeneratedPrimaryKeys) {\n\t\t\t\t\t\t\tentity = new this.entityType();\n\t\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running create with client-generated key');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Entity ${this.entityType.name} with primary key '${primaryKey}' not found and clientGeneratedPrimaryKeys is not enabled.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tentity = new this.entityType();\n\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\tlogger.trace({ item, entity: this.entityType.name }, 'Running create with item');\n\t\t\t\t\t}\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, entities: sanitiseFilterForLogging(entities) },\n\t\t\t'created or updated items'\n\t\t);\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async createOne(createArgs: Partial<D>, trace?: TraceOptions): Promise<D> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ createArgs: sanitiseFilterForLogging(createArgs), entity: this.entityType.name },\n\t\t\t'Running create with args'\n\t\t);\n\n\t\tconst entity = new this.entityType();\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, createArgs);\n\t\tawait this.database.em.persistAndFlush(entity as Partial<D>);\n\n\t\tlogger.trace(\n\t\t\t{ entity: this.entityType.name, result: sanitiseFilterForLogging(entity) },\n\t\t\t'create result'\n\t\t);\n\n\t\treturn entity;\n\t}\n\n\t@TraceMethod()\n\tpublic async createMany(createItems: Partial<D>[], trace?: TraceOptions): Promise<D[]> {\n\t\ttrace?.span.updateName(`Mikro-Orm - createMany ${this.entityType.name}`);\n\t\treturn this._createMany(createItems);\n\t}\n\n\tpublic async createTraces(createItems: Partial<D>[]): Promise<D[]> {\n\t\treturn this._createMany(createItems);\n\t}\n\n\tprivate async _createMany(createItems: Partial<D>[]) {\n\t\tlogger.trace(\n\t\t\t{ createItems: sanitiseFilterForLogging(createItems), entity: this.entityType.name },\n\t\t\t'Running create with args'\n\t\t);\n\n\t\tconst entities = await this.database.transactional<D[]>(async () => {\n\t\t\tconst result: D[] = [];\n\t\t\tfor (const item of createItems) {\n\t\t\t\tconst entity = new this.entityType();\n\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\tthis.database.em.persist(entity as Partial<D>);\n\t\t\t\tresult.push(entity);\n\t\t\t}\n\n\t\t\t// Flush so database-generated primary keys (e.g. PostgreSQL identity) are assigned\n\t\t\t// before we return entities to Graphweaver \u2014 nested createOrUpdate batching reads PKs\n\t\t\t// from these objects when wiring FK injectors.\n\t\t\tawait this.database.em.flush();\n\n\t\t\treturn result;\n\t\t});\n\n\t\tlogger.trace({ entity: this.entityType.name, entities }, 'created items');\n\n\t\treturn entities;\n\t}\n\n\t@TraceMethod()\n\tpublic async deleteOne(filter: Filter<D>, trace?: TraceOptions): Promise<boolean> {\n\t\ttrace?.span.updateName(`Mikro-Orm - deleteOne ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running delete with filter.'\n\t\t);\n\t\tconst where = filter\n\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t: undefined;\n\t\tconst whereWithAppliedExternalIdFields =\n\t\t\twhere && this.applyExternalIdFields(this.entityType, where);\n\n\t\tconst deletedRows = await this.database.em.nativeDelete(\n\t\t\tthis.entityType,\n\t\t\twhereWithAppliedExternalIdFields\n\t\t);\n\n\t\tif (deletedRows > 1) {\n\t\t\tthrow new Error('Multiple deleted rows');\n\t\t}\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn deletedRows === 1;\n\t}\n\n\t@TraceMethod()\n\tpublic async deleteMany(filter: Filter<D>, trace?: TraceOptions): Promise<boolean> {\n\t\ttrace?.span.updateName(`Mikro-Orm - deleteMany ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running delete'\n\t\t);\n\n\t\tconst deletedRows = await this.database.transactional<number>(async () => {\n\t\t\tconst where = filter\n\t\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t\t: undefined;\n\t\t\tconst whereWithAppliedExternalIdFields =\n\t\t\t\twhere && this.applyExternalIdFields(this.entityType, where);\n\n\t\t\tconst toDelete = await this.database.em.count(\n\t\t\t\tthis.entityType,\n\t\t\t\twhereWithAppliedExternalIdFields\n\t\t\t);\n\t\t\tconst deletedCount = await this.database.em.nativeDelete(\n\t\t\t\tthis.entityType,\n\t\t\t\twhereWithAppliedExternalIdFields\n\t\t\t);\n\n\t\t\tif (deletedCount !== toDelete) {\n\t\t\t\tthrow new Error('We did not delete any rows, rolling back.');\n\t\t\t}\n\n\t\t\treturn deletedCount;\n\t\t});\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn true;\n\t}\n\n\tpublic foreignKeyForRelationshipField?(field: FieldMetadata, dataEntity: D) {\n\t\tconst value = dataEntity[field.name as keyof D];\n\n\t\tif (Reference.isReference(value)) {\n\t\t\tconst { properties } = this.database.em.getMetadata().get(this.entityType);\n\t\t\tconst property = properties[field.name];\n\t\t\tconst [primaryKey] = property.targetMeta?.primaryKeys ?? [];\n\t\t\tif (!primaryKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not determine primary key for ${field.name} on ${this.entityType.name}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst foreignKey = (value.unwrap() as any)[primaryKey];\n\t\t\tif (foreignKey === undefined || foreignKey === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not read foreign key from reference: ${value.unwrap()} with primary key name ${primaryKey}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn foreignKey;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t@TraceMethod()\n\tpublic async aggregate(\n\t\tfilter: Filter<D>,\n\t\trequestedAggregations: Set<AggregationType>,\n\t\ttrace?: TraceOptions\n\t): Promise<AggregationResult> {\n\t\ttrace?.span.updateName(`Mikro-Orm - aggregate ${this.entityType.name}`);\n\t\tlogger.trace(\n\t\t\t{ filter: sanitiseFilterForLogging(filter), entity: this.entityType.name },\n\t\t\t'Running aggregate with filter'\n\t\t);\n\n\t\t// Strip custom types out of the equation.\n\t\t// This query only works if we JSON.parse(JSON.stringify(filter)):\n\t\t//\n\t\t// query {\n\t\t// drivers (filter: { region: { name: \"North Shore\" }}) {\n\t\t// id\n\t\t// }\n\t\t// }\n\t\tconst where = filter\n\t\t\t? gqlToMikro(JSON.parse(JSON.stringify(filter)), this.getDbType())\n\t\t\t: undefined;\n\n\t\t// Convert from: { account: {id: '6' }}\n\t\t// to { accountId: '6' }\n\t\t// This conversion only works on root level objects\n\t\tconst whereWithAppliedExternalIdFields = where\n\t\t\t? this.applyExternalIdFields(this.entityType, where)\n\t\t\t: {};\n\n\t\t// Regions need some fancy handling with Query Builder. Process the where further\n\t\t// and return a Query Builder instance.\n\t\tconst query = this.em.createQueryBuilder(this.entityType);\n\n\t\tif (Object.keys(whereWithAppliedExternalIdFields).length > 0) {\n\t\t\tquery.andWhere(whereWithAppliedExternalIdFields);\n\t\t}\n\n\t\tconst result: AggregationResult = {};\n\n\t\ttry {\n\t\t\tif (requestedAggregations.has(AggregationType.COUNT)) {\n\t\t\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\t\t\tif (meta.primaryKeys.length) {\n\t\t\t\t\t// It's a standard entity with primary keys, we can do a full distinct\n\t\t\t\t\t// on these keys.\n\t\t\t\t\tresult.count = await query.getCount(meta.primaryKeys, true);\n\t\t\t\t} else {\n\t\t\t\t\t// It's either a virtual entity, or it's an entity without primary keys.\n\t\t\t\t\t// We just need to count * as a fallback, no distinct.\n\t\t\t\t\tconst [firstRow] = await query.select(sql`count(*)`.as('count')).execute();\n\t\t\t\t\tresult.count = firstRow.count;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tsafeErrorLog(logger, err, `find ${this.entityType.name} error`);\n\n\t\t\tif ((err as PostgresError)?.routine === 'InitializeSessionUserId') {\n\t\t\t\t// Throw if the user credentials are incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct user credentials for the database.'\n\t\t\t\t);\n\t\t\t} else if ((err as PostgresError)?.code === 'ECONNREFUSED') {\n\t\t\t\t// Throw if the database address or port is incorrect\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Database connection failed, please check you are using the correct address and port for the database.'\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t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FA;AAAA,MADZ,gCAAY;AAAA,GAzTD,qBA0TC;AAuCA;AAAA,MADZ,gCAAY;AAAA,GAhWD,qBAiWC;AA+CA;AAAA,MADZ,gCAAY;AAAA,GA/YD,qBAgZC;AAsDA;AAAA,MADZ,gCAAY;AAAA,GArcD,qBAscC;AA6CA;AAAA,MADZ,gCAAY;AAAA,GAlfD,qBAmfC;AAyDA;AAAA,MADZ,gCAAY;AAAA,GA3iBD,qBA4iBC;AAoBA;AAAA,MADZ,gCAAY;AAAA,GA/jBD,qBAgkBC;AAsCA;AAAA,MADZ,gCAAY;AAAA,GArmBD,qBAsmBC;AA2BA;AAAA,MADZ,gCAAY;AAAA,GAhoBD,qBAioBC;AA8DA;AAAA,MADZ,gCAAY;AAAA,GA9rBD,qBA+rBC;",
|
|
6
6
|
"names": ["trace", "startTrace"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exogee/graphweaver-mikroorm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "MikroORM backend for @exogee/graphweaver",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@apollo/server": "5.4.0",
|
|
21
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
21
|
+
"@aws-sdk/client-secrets-manager": "3.995.0",
|
|
22
22
|
"dataloader": "2.2.3",
|
|
23
23
|
"decimal.js": "10.6.0",
|
|
24
24
|
"dotenv": "17.2.3",
|
|
25
25
|
"pluralize": "8.0.0",
|
|
26
26
|
"reflect-metadata": "0.2.2",
|
|
27
|
-
"@exogee/
|
|
28
|
-
"@exogee/
|
|
29
|
-
"@exogee/graphweaver-server": "2.
|
|
27
|
+
"@exogee/graphweaver": "2.22.0",
|
|
28
|
+
"@exogee/logger": "2.22.0",
|
|
29
|
+
"@exogee/graphweaver-server": "2.22.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@mikro-orm/core": "6",
|