@exogee/graphweaver-mikroorm 0.2.24 → 1.0.0-beta.1
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/config.js.map +1 -1
- package/lib/database.d.ts +3 -3
- package/lib/database.js +7 -11
- package/lib/database.js.map +2 -2
- package/lib/decorators/external-id-field.js.map +2 -2
- package/lib/decorators/index.js +4 -0
- package/lib/entities/audit-change.d.ts +1 -2
- package/lib/entities/audit-change.js +3 -6
- package/lib/entities/audit-change.js.map +2 -2
- package/lib/entities/audit-related-entity-change.d.ts +1 -2
- package/lib/entities/audit-related-entity-change.js +2 -4
- package/lib/entities/audit-related-entity-change.js.map +2 -2
- package/lib/entities/index.d.ts +0 -1
- package/lib/entities/index.js +5 -1
- package/lib/entities/index.js.map +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -2
- package/lib/index.js.map +2 -2
- package/lib/introspection/files/base-file.js.map +1 -1
- package/lib/introspection/files/data-entity-file.js +10 -12
- package/lib/introspection/files/data-entity-file.js.map +2 -2
- package/lib/introspection/files/data-entity-index-file.js +3 -3
- package/lib/introspection/files/data-entity-index-file.js.map +2 -2
- package/lib/introspection/files/data-source-index-file.js.map +1 -1
- package/lib/introspection/files/database-file.js +2 -2
- package/lib/introspection/files/database-file.js.map +2 -2
- package/lib/introspection/files/index.d.ts +0 -2
- package/lib/introspection/files/index.js +9 -2
- package/lib/introspection/files/index.js.map +2 -2
- package/lib/introspection/files/schema-entity-file.d.ts +2 -1
- package/lib/introspection/files/schema-entity-file.js +41 -25
- package/lib/introspection/files/schema-entity-file.js.map +3 -3
- package/lib/introspection/files/schema-index-file.js +3 -19
- package/lib/introspection/files/schema-index-file.js.map +2 -2
- package/lib/introspection/generate.js +22 -20
- package/lib/introspection/generate.js.map +2 -2
- package/lib/plugins/clear-database-context.js +1 -0
- package/lib/plugins/clear-database-context.js.map +1 -1
- package/lib/{base-resolver → provider}/assign.d.ts +1 -1
- package/lib/{base-resolver → provider}/assign.js +41 -13
- package/lib/provider/assign.js.map +7 -0
- package/lib/{base-resolver → provider}/index.js +7 -3
- package/lib/provider/index.js.map +7 -0
- package/lib/{base-resolver → provider}/provider.d.ts +13 -15
- package/lib/{base-resolver → provider}/provider.js +45 -43
- package/lib/provider/provider.js.map +7 -0
- package/lib/types/date-type.d.ts +5 -5
- package/lib/types/date-type.js +8 -11
- package/lib/types/date-type.js.map +2 -2
- package/lib/types/decimal-type.d.ts +5 -5
- package/lib/types/decimal-type.js +12 -20
- package/lib/types/decimal-type.js.map +2 -2
- package/lib/types/index.js +5 -0
- package/lib/types/time-type.d.ts +5 -5
- package/lib/types/time-type.js +12 -20
- package/lib/types/time-type.js.map +2 -2
- package/lib/utils/authentication-context.js.map +1 -1
- package/lib/utils/change-tracker.js +10 -9
- package/lib/utils/change-tracker.js.map +2 -2
- package/lib/utils/index.js +7 -0
- package/lib/utils/tracked-entity.d.ts +1 -2
- package/lib/utils/tracked-entity.js +2 -4
- package/lib/utils/tracked-entity.js.map +2 -2
- package/lib/utils/untracked-property.d.ts +0 -1
- package/lib/utils/untracked-property.js +0 -1
- package/lib/utils/untracked-property.js.map +2 -2
- package/package.json +20 -20
- package/lib/base-resolver/assign.js.map +0 -7
- package/lib/base-resolver/index.js.map +0 -7
- package/lib/base-resolver/provider.js.map +0 -7
- package/lib/entities/base-entity.d.ts +0 -5
- package/lib/entities/base-entity.js +0 -37
- package/lib/entities/base-entity.js.map +0 -7
- package/lib/introspection/files/schema-entity-index-file.d.ts +0 -6
- package/lib/introspection/files/schema-entity-index-file.js +0 -44
- package/lib/introspection/files/schema-entity-index-file.js.map +0 -7
- package/lib/introspection/files/schema-resolver-file.d.ts +0 -6
- package/lib/introspection/files/schema-resolver-file.js +0 -62
- package/lib/introspection/files/schema-resolver-file.js.map +0 -7
- /package/lib/{base-resolver → provider}/index.d.ts +0 -0
package/lib/config.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/config.ts"],
|
|
4
4
|
"sourcesContent": ["import { logger } from '@exogee/logger';\n\nexport const requireEnvironmentVariable = (\n\tenvStr: string,\n\twarnOnly?: boolean\n): string | undefined => {\n\tconst envVar = process.env[envStr];\n\tif (!envVar) {\n\t\tif (warnOnly) {\n\t\t\tlogger.warn(`${envStr} is required in environment.`);\n\t\t\treturn;\n\t\t}\n\t\tthrow new Error(`${envStr} required but not found.`);\n\t}\n\treturn envVar;\n};\n\nexport const config = {};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAEhB,MAAM,6BAA6B,CACzC,QACA,aACwB;AACxB,QAAM,SAAS,QAAQ,IAAI;
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAEhB,MAAM,6BAA6B,CACzC,QACA,aACwB;AACxB,QAAM,SAAS,QAAQ,IAAI,MAAM;AACjC,MAAI,CAAC,QAAQ;AACZ,QAAI,UAAU;AACb,2BAAO,KAAK,GAAG,MAAM,8BAA8B;AACnD;AAAA,IACD;AACA,UAAM,IAAI,MAAM,GAAG,MAAM,0BAA0B;AAAA,EACpD;AACA,SAAO;AACR;AAEO,MAAM,SAAS,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/database.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import './utils/change-tracker';
|
|
3
2
|
import { Connection, EntityName, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core';
|
|
4
3
|
import type { EntityManager as PgEntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
|
5
4
|
import type { EntityManager as MyEntityManager, MySqlDriver } from '@mikro-orm/mysql';
|
|
6
|
-
type EntityManager
|
|
5
|
+
import type { EntityManager as SqliteEntityManager, SqliteDriver } from '@mikro-orm/sqlite';
|
|
6
|
+
type EntityManager = PgEntityManager<PostgreSqlDriver> | MyEntityManager<MySqlDriver> | SqliteEntityManager<SqliteDriver>;
|
|
7
7
|
export type DatabaseType = 'mysql' | 'postgresql' | 'sqlite';
|
|
8
8
|
export interface ConnectionOptions {
|
|
9
9
|
mikroOrmConfig?: Options | (() => Options | Promise<Options>);
|
|
@@ -26,7 +26,7 @@ declare class DatabaseImplementation {
|
|
|
26
26
|
get em(): EntityManager;
|
|
27
27
|
transactional<T>(callback: () => Promise<T>, isolationLevel?: IsolationLevel): Promise<T>;
|
|
28
28
|
isolatedTest(test: () => any): () => Promise<void>;
|
|
29
|
-
get rawConnection(): import("@mikro-orm/postgresql").PostgreSqlConnection | import("@mikro-orm/
|
|
29
|
+
get rawConnection(): import("@mikro-orm/postgresql").PostgreSqlConnection | import("@mikro-orm/postgresql").MySqlConnection | import("@mikro-orm/sqlite").SqliteConnection;
|
|
30
30
|
private getConnectionInfo;
|
|
31
31
|
getRepository: <T extends Partial<T>>(entityName: EntityName<T>) => import("@mikro-orm/core").GetRepository<T, import("@mikro-orm/postgresql").EntityRepository<T>>;
|
|
32
32
|
connect: (connectionOptions?: ConnectionOptions) => Promise<MikroORM<IDatabaseDriver<Connection>, import("@mikro-orm/core").EntityManager<IDatabaseDriver<Connection>>>>;
|
package/lib/database.js
CHANGED
|
@@ -22,7 +22,6 @@ __export(database_exports, {
|
|
|
22
22
|
IsolationLevel: () => IsolationLevel
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(database_exports);
|
|
25
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
26
25
|
var import_change_tracker = require("./utils/change-tracker");
|
|
27
26
|
var import_core = require("@mikro-orm/core");
|
|
28
27
|
var import_logger = require("@exogee/logger");
|
|
@@ -57,11 +56,9 @@ class DatabaseImplementation {
|
|
|
57
56
|
dbName: process.env.DATABASE_NAME
|
|
58
57
|
};
|
|
59
58
|
const filterUndefined = (obj) => {
|
|
60
|
-
if (!obj)
|
|
61
|
-
return {};
|
|
59
|
+
if (!obj) return {};
|
|
62
60
|
for (const key of Object.keys(obj)) {
|
|
63
|
-
if (obj[key] === void 0)
|
|
64
|
-
delete obj[key];
|
|
61
|
+
if (obj[key] === void 0) delete obj[key];
|
|
65
62
|
}
|
|
66
63
|
return obj;
|
|
67
64
|
};
|
|
@@ -86,6 +83,7 @@ class DatabaseImplementation {
|
|
|
86
83
|
import_logger.logger.trace(`${params.entities?.length}x entities`);
|
|
87
84
|
const orm = await import_core.MikroORM.init({
|
|
88
85
|
validateRequired: false,
|
|
86
|
+
// Since v5, new entities are validated on runtime (just before executing insert queries), based on the entity metadata
|
|
89
87
|
implicitTransactions: false,
|
|
90
88
|
metadataProvider: import_core.ReflectMetadataProvider,
|
|
91
89
|
discovery: {
|
|
@@ -94,6 +92,7 @@ class DatabaseImplementation {
|
|
|
94
92
|
warnWhenNoEntities: false
|
|
95
93
|
},
|
|
96
94
|
allowGlobalContext: true,
|
|
95
|
+
// Ensure we only ever create one connection to the database.
|
|
97
96
|
pool: {
|
|
98
97
|
min: 1,
|
|
99
98
|
max: 1
|
|
@@ -180,13 +179,10 @@ class DatabaseImplementation {
|
|
|
180
179
|
class ConnectionsManager {
|
|
181
180
|
constructor() {
|
|
182
181
|
this.connect = async (id, connectionOptions) => {
|
|
183
|
-
if (!id)
|
|
184
|
-
|
|
185
|
-
if (this.connections.has(id))
|
|
186
|
-
return this.connections.get(id);
|
|
182
|
+
if (!id) throw new Error("Error: No id attached to connection.");
|
|
183
|
+
if (this.connections.has(id)) return this.connections.get(id);
|
|
187
184
|
const database = new DatabaseImplementation();
|
|
188
|
-
if (connectionOptions)
|
|
189
|
-
await database.connect(connectionOptions);
|
|
185
|
+
if (connectionOptions) await database.connect(connectionOptions);
|
|
190
186
|
import_logger.logger.trace(`Saving database connection with id "${id}".`);
|
|
191
187
|
this.connections.set(id, database);
|
|
192
188
|
};
|
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 '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
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 } 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 = '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} 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 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: Options = {\n\t\t\thost: process.env.DATABASE_HOST,\n\t\t\tport: process.env.DATABASE_PORT ? parseInt(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\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\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\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('Creating connection to %s on %s', params.dbName, params.host);\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: Map<string, DatabaseImplementation>;\n\n\tconstructor() {\n\t\tthis.connections = new Map<string, DatabaseImplementation>();\n\t}\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 = async (id?: string, connectionOptions?: ConnectionOptions) => {\n\t\tif (!id) throw new Error('Error: No id attached to connection.');\n\n\t\tif (this.connections.has(id)) return this.connections.get(id);\n\t\tconst database = new DatabaseImplementation();\n\t\tif (connectionOptions) await database.connect(connectionOptions);\n\t\tlogger.trace(`Saving database connection with id \"${id}\".`);\n\t\tthis.connections.set(id, database);\n\t};\n\n\tpublic database(id: string) {\n\t\tlogger.trace(`Finding database connection for id \"${id}\"`);\n\t\treturn this.connections.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,oBAAuB;AAkBhB,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;A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AY,IAAI,IAAI,QAAQ;AAAA,IAClC;AAzBC,SAAK,cAAc,oBAAI,IAAoC;AAAA,EAC5D;AAAA,EAEA,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,EAYO,SAAS,IAAY;AAC3B,yBAAO,MAAM,uCAAuC,EAAE,GAAG;AACzD,WAAO,KAAK,YAAY,IAAI,EAAE;AAAA,EAC/B;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"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/decorators/external-id-field.ts"],
|
|
4
|
-
"sourcesContent": ["// In some cases when linking across from
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,MAAM,qBAAqB,oBAAI,IAA8B;AAE7D,MAAM,kBACZ,CAAC,EAAE,KAAK,MACR,CAAC,QAAmB,UAAkB;AACrC,QAAM,WAAW,mBAAmB,IAAI,OAAO,YAAY,IAAI,KAAK,CAAC;AACrE,WAAS,
|
|
4
|
+
"sourcesContent": ["// In some cases when linking across from one data source to another, it's very handy\n// to flatten entities from:\n//\n// job.account = { id : 'whatever' }\n//\n// to\n//\n// job.crmAccountId = 'whatever'\n//\n// This allows us to treat them consistently from an API standpoint\n// but actually store the values where they need to go.\n\nimport { AnyEntity } from '@mikro-orm/core';\n\nexport type StringDictionary = { [key: string]: string };\n\n// A map of classes to dictionary.\nexport const externalIdFieldMap = new Map<string, StringDictionary>();\n\nexport const ExternalIdField =\n\t({ from }: { from: string }) =>\n\t(target: AnyEntity, field: string) => {\n\t\tconst existing = externalIdFieldMap.get(target.constructor.name) || {};\n\t\texisting[from] = field;\n\t\texternalIdFieldMap.set(target.constructor.name, existing);\n\t};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,MAAM,qBAAqB,oBAAI,IAA8B;AAE7D,MAAM,kBACZ,CAAC,EAAE,KAAK,MACR,CAAC,QAAmB,UAAkB;AACrC,QAAM,WAAW,mBAAmB,IAAI,OAAO,YAAY,IAAI,KAAK,CAAC;AACrE,WAAS,IAAI,IAAI;AACjB,qBAAmB,IAAI,OAAO,YAAY,MAAM,QAAQ;AACzD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/decorators/index.js
CHANGED
|
@@ -16,4 +16,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var decorators_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(decorators_exports);
|
|
18
18
|
__reExport(decorators_exports, require("./external-id-field"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./external-id-field")
|
|
22
|
+
});
|
|
19
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChangeSetType, Collection } from '@mikro-orm/core';
|
|
2
2
|
import { AuditRelatedEntityChange } from './audit-related-entity-change';
|
|
3
|
-
|
|
4
|
-
export declare class AuditChange extends BaseEntity {
|
|
3
|
+
export declare class AuditChange {
|
|
5
4
|
id: string;
|
|
6
5
|
type: ChangeSetType;
|
|
7
6
|
entityId: string;
|
|
@@ -21,8 +21,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
21
21
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
22
|
if (decorator = decorators[i])
|
|
23
23
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result)
|
|
25
|
-
__defProp(target, key, result);
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
25
|
return result;
|
|
27
26
|
};
|
|
28
27
|
var audit_change_exports = {};
|
|
@@ -32,11 +31,9 @@ __export(audit_change_exports, {
|
|
|
32
31
|
module.exports = __toCommonJS(audit_change_exports);
|
|
33
32
|
var import_core = require("@mikro-orm/core");
|
|
34
33
|
var import_audit_related_entity_change = require("./audit-related-entity-change");
|
|
35
|
-
|
|
36
|
-
let AuditChange = class extends import_base_entity.BaseEntity {
|
|
34
|
+
let AuditChange = class {
|
|
37
35
|
constructor() {
|
|
38
|
-
|
|
39
|
-
this.createdAt = new Date();
|
|
36
|
+
this.createdAt = /* @__PURE__ */ new Date();
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
39
|
__decorateClass([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/entities/audit-change.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tBigIntType,\n\tChangeSetType,\n\tCollection,\n\tEntity,\n\tEnum,\n\tIndex,\n\tOneToMany,\n\tPrimaryKey,\n\tProperty,\n} from '@mikro-orm/core';\n\nimport { AuditRelatedEntityChange } from './audit-related-entity-change';\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {\n\tBigIntType,\n\tChangeSetType,\n\tCollection,\n\tEntity,\n\tEnum,\n\tIndex,\n\tOneToMany,\n\tPrimaryKey,\n\tProperty,\n} from '@mikro-orm/core';\n\nimport { AuditRelatedEntityChange } from './audit-related-entity-change';\n\n@Entity()\n@Index({ properties: ['entityType', 'entityId'] })\nexport class AuditChange {\n\t@PrimaryKey({ type: new BigIntType('string') })\n\tid!: string;\n\n\t@Enum({ items: () => ChangeSetType, type: 'string' })\n\ttype!: ChangeSetType;\n\n\t@Property({ type: 'string' })\n\tentityId!: string;\n\n\t@Property({ type: 'string' })\n\tentityType!: string;\n\n\t@Property({ type: 'string' })\n\tcreatedBy!: string;\n\n\t@Property({ type: 'date' })\n\tcreatedAt: Date = new Date();\n\n\t@Property({ type: 'json', nullable: true })\n\tdata?: Record<string, unknown>;\n\n\t@OneToMany(() => AuditRelatedEntityChange, 'change')\n\trelatedEntityChanges?: Collection<AuditRelatedEntityChange>;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAUO;AAEP,yCAAyC;AAIlC,IAAM,cAAN,MAAkB;AAAA,EAAlB;AAiBN,qBAAkB,oBAAI,KAAK;AAAA;AAO5B;AAtBC;AAAA,MADC,wBAAW,EAAE,MAAM,IAAI,uBAAW,QAAQ,EAAE,CAAC;AAAA,GADlC,YAEZ;AAGA;AAAA,MADC,kBAAK,EAAE,OAAO,MAAM,2BAAe,MAAM,SAAS,CAAC;AAAA,GAJxC,YAKZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAPhB,YAQZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAVhB,YAWZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAbhB,YAcZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAhBd,YAiBZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAnB9B,YAoBZ;AAGA;AAAA,MADC,uBAAU,MAAM,6DAA0B,QAAQ;AAAA,GAtBvC,YAuBZ;AAvBY,cAAN;AAAA,MAFN,oBAAO;AAAA,MACP,mBAAM,EAAE,YAAY,CAAC,cAAc,UAAU,EAAE,CAAC;AAAA,GACpC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Ref } from '@mikro-orm/core';
|
|
2
2
|
import { AuditChange } from './audit-change';
|
|
3
|
-
|
|
4
|
-
export declare class AuditRelatedEntityChange extends BaseEntity {
|
|
3
|
+
export declare class AuditRelatedEntityChange {
|
|
5
4
|
id: string;
|
|
6
5
|
change: Ref<AuditChange>;
|
|
7
6
|
relatedEntityType: string;
|
|
@@ -21,8 +21,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
21
21
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
22
|
if (decorator = decorators[i])
|
|
23
23
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result)
|
|
25
|
-
__defProp(target, key, result);
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
25
|
return result;
|
|
27
26
|
};
|
|
28
27
|
var audit_related_entity_change_exports = {};
|
|
@@ -32,8 +31,7 @@ __export(audit_related_entity_change_exports, {
|
|
|
32
31
|
module.exports = __toCommonJS(audit_related_entity_change_exports);
|
|
33
32
|
var import_core = require("@mikro-orm/core");
|
|
34
33
|
var import_audit_change = require("./audit-change");
|
|
35
|
-
|
|
36
|
-
let AuditRelatedEntityChange = class extends import_base_entity.BaseEntity {
|
|
34
|
+
let AuditRelatedEntityChange = class {
|
|
37
35
|
};
|
|
38
36
|
__decorateClass([
|
|
39
37
|
(0, import_core.PrimaryKey)({ type: new import_core.BigIntType("string") })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/entities/audit-related-entity-change.ts"],
|
|
4
|
-
"sourcesContent": ["import { BigIntType, Entity, Ref, Index, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';\n\nimport { AuditChange } from './audit-change';\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { BigIntType, Entity, Ref, Index, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';\n\nimport { AuditChange } from './audit-change';\n@Entity()\n@Index({ properties: ['relatedEntityType', 'relatedEntityId'] })\nexport class AuditRelatedEntityChange {\n\t@PrimaryKey({ type: new BigIntType('string') })\n\tid!: string;\n\n\t@ManyToOne(() => AuditChange, { deleteRule: 'cascade', ref: true })\n\tchange!: Ref<AuditChange>;\n\n\t@Property({ type: 'string' })\n\trelatedEntityType!: string;\n\n\t@Property({ type: 'string' })\n\trelatedEntityId!: string;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgF;AAEhF,0BAA4B;AAGrB,IAAM,2BAAN,MAA+B;AAYtC;AAVC;AAAA,MADC,wBAAW,EAAE,MAAM,IAAI,uBAAW,QAAQ,EAAE,CAAC;AAAA,GADlC,yBAEZ;AAGA;AAAA,MADC,uBAAU,MAAM,iCAAa,EAAE,YAAY,WAAW,KAAK,KAAK,CAAC;AAAA,GAJtD,yBAKZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAPhB,yBAQZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAVhB,yBAWZ;AAXY,2BAAN;AAAA,MAFN,oBAAO;AAAA,MACP,mBAAM,EAAE,YAAY,CAAC,qBAAqB,iBAAiB,EAAE,CAAC;AAAA,GAClD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/entities/index.d.ts
CHANGED
package/lib/entities/index.js
CHANGED
|
@@ -17,5 +17,9 @@ var entities_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(entities_exports);
|
|
18
18
|
__reExport(entities_exports, require("./audit-change"), module.exports);
|
|
19
19
|
__reExport(entities_exports, require("./audit-related-entity-change"), module.exports);
|
|
20
|
-
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./audit-change"),
|
|
23
|
+
...require("./audit-related-entity-change")
|
|
24
|
+
});
|
|
21
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/entities/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './audit-change';\nexport * from './audit-related-entity-change';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,2BAAd;AACA,6BAAc,0CADd;
|
|
4
|
+
"sourcesContent": ["export * from './audit-change';\nexport * from './audit-related-entity-change';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,2BAAd;AACA,6BAAc,0CADd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -19,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
};
|
|
20
20
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
@@ -43,7 +47,7 @@ __export(src_exports, {
|
|
|
43
47
|
module.exports = __toCommonJS(src_exports);
|
|
44
48
|
var import_reflect_metadata = require("reflect-metadata");
|
|
45
49
|
var dotenv = __toESM(require("dotenv"));
|
|
46
|
-
__reExport(src_exports, require("./
|
|
50
|
+
__reExport(src_exports, require("./provider"), module.exports);
|
|
47
51
|
__reExport(src_exports, require("./entities"), module.exports);
|
|
48
52
|
__reExport(src_exports, require("./decorators"), module.exports);
|
|
49
53
|
__reExport(src_exports, require("./database"), module.exports);
|
|
@@ -70,6 +74,14 @@ dotenv.config({
|
|
|
70
74
|
ReferenceKind,
|
|
71
75
|
UniqueConstraintViolationException,
|
|
72
76
|
Utils,
|
|
73
|
-
wrap
|
|
77
|
+
wrap,
|
|
78
|
+
...require("./provider"),
|
|
79
|
+
...require("./entities"),
|
|
80
|
+
...require("./decorators"),
|
|
81
|
+
...require("./database"),
|
|
82
|
+
...require("./types"),
|
|
83
|
+
...require("./utils/authentication-context"),
|
|
84
|
+
...require("./plugins"),
|
|
85
|
+
...require("./introspection")
|
|
74
86
|
});
|
|
75
87
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import 'reflect-metadata';\n\nimport * as dotenv from 'dotenv';\ndotenv.config({\n\tpath: `.env.${(process.env.NODE_ENV || 'development').toLowerCase()}`,\n}); // TODO: The path to .env file in pnpm workspaces seems to use the workspace package.json path. Need to ensure it uses the local version (if required)\n\nexport * from './
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import 'reflect-metadata';\n\nimport * as dotenv from 'dotenv';\ndotenv.config({\n\tpath: `.env.${(process.env.NODE_ENV || 'development').toLowerCase()}`,\n}); // TODO: The path to .env file in pnpm workspaces seems to use the workspace package.json path. Need to ensure it uses the local version (if required)\n\nexport * from './provider';\nexport * from './entities';\nexport * from './decorators';\nexport * from './database';\nexport * from './types';\nexport * from './utils/authentication-context';\nexport * from './plugins';\nexport * from './introspection';\n\n// Re-export from Mikro so things that depend on database entities can access helpers such as\n// Reference.isReference().\nexport type {\n\tAnyEntity,\n\tChangeSet,\n\tEntityData,\n\tEntityName,\n\tEventArgs,\n\tEventSubscriber,\n\tFilterQuery,\n\tFlushEventArgs,\n\tLoaded,\n\tQueryOrderMap,\n} from '@mikro-orm/core';\nexport type { LoadedReference } from '@mikro-orm/core';\nexport {\n\tChangeSetType,\n\tCollection,\n\tDatabaseObjectNotFoundException,\n\tEntityManager,\n\tEntityRepository,\n\tLockMode,\n\tPrimaryKey,\n\tQueryFlag,\n\tQueryOrder,\n\tReference,\n\tReferenceKind,\n\tUniqueConstraintViolationException,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAEP,aAAwB;AAKxB,wBAAc,uBAPd;AAQA,wBAAc,uBARd;AASA,wBAAc,yBATd;AAUA,wBAAc,uBAVd;AAWA,wBAAc,oBAXd;AAYA,wBAAc,2CAZd;AAaA,wBAAc,sBAbd;AAcA,wBAAc,4BAdd;AA+BA,kBAeO;AA3CP,OAAO,OAAO;AAAA,EACb,MAAM,SAAS,QAAQ,IAAI,YAAY,eAAe,YAAY,CAAC;AACpE,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/introspection/files/base-file.ts"],
|
|
4
4
|
"sourcesContent": ["import { EntityMetadata, NamingStrategy, Platform } from '@mikro-orm/core';\n\nexport class BaseFile {\n\tconstructor(\n\t\tprotected readonly meta: EntityMetadata,\n\t\tprotected readonly namingStrategy: NamingStrategy,\n\t\tprotected readonly platform: Platform\n\t) {}\n\n\tprotected quote(val: string) {\n\t\treturn val.startsWith(`'`) ? `\\`${val}\\`` : `'${val}'`;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,SAAS;AAAA,EACrB,YACoB,MACA,gBACA,UAClB;AAHkB;AACA;AACA;AAAA,EACjB;AAAA,EAEO,MAAM,KAAa;AAC5B,WAAO,IAAI,WAAW,GAAG,IAAI,KAAK,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,SAAS;AAAA,EACrB,YACoB,MACA,gBACA,UAClB;AAHkB;AACA;AACA;AAAA,EACjB;AAAA,EAEO,MAAM,KAAa;AAC5B,WAAO,IAAI,WAAW,GAAG,IAAI,KAAK,GAAG,OAAO,IAAI,GAAG;AAAA,EACpD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -53,8 +53,7 @@ class DataEntityFile extends import_base_file.BaseFile {
|
|
|
53
53
|
}
|
|
54
54
|
classBody += decorator;
|
|
55
55
|
classBody += definition;
|
|
56
|
-
if (props[props.length - 1] !== prop)
|
|
57
|
-
classBody += "\n";
|
|
56
|
+
if (props[props.length - 1] !== prop) classBody += "\n";
|
|
58
57
|
if (prop.enum) {
|
|
59
58
|
const enumClassName = this.namingStrategy.getClassName(
|
|
60
59
|
this.meta.collection + "_" + prop.fieldNames[0],
|
|
@@ -66,8 +65,7 @@ class DataEntityFile extends import_base_file.BaseFile {
|
|
|
66
65
|
let file = ``;
|
|
67
66
|
this.coreImports.add("Entity");
|
|
68
67
|
const imports = [
|
|
69
|
-
`import { ${[...this.coreImports].sort().join(", ")} } from '@mikro-orm/core'
|
|
70
|
-
`import { BaseEntity } from '@exogee/graphweaver-mikroorm';`
|
|
68
|
+
`import { ${[...this.coreImports].sort().join(", ")} } from '@mikro-orm/core';`
|
|
71
69
|
];
|
|
72
70
|
const entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);
|
|
73
71
|
entityImports.sort().forEach((entity) => {
|
|
@@ -79,7 +77,7 @@ class DataEntityFile extends import_base_file.BaseFile {
|
|
|
79
77
|
}
|
|
80
78
|
file += `@Entity(${this.getCollectionDecl()})
|
|
81
79
|
`;
|
|
82
|
-
file += `export class ${this.meta.className}
|
|
80
|
+
file += `export class ${this.meta.className} {`;
|
|
83
81
|
file += `${classBody}}
|
|
84
82
|
`;
|
|
85
83
|
file = `${imports.join("\n")}
|
|
@@ -88,9 +86,15 @@ ${file}`;
|
|
|
88
86
|
return file;
|
|
89
87
|
}
|
|
90
88
|
getPropertyType(prop) {
|
|
91
|
-
|
|
89
|
+
const columnType = prop.columnTypes?.[0]?.toLowerCase();
|
|
90
|
+
if (["jsonb", "json", "any"].includes(columnType)) {
|
|
92
91
|
return `Record<string, unknown>`;
|
|
93
92
|
}
|
|
93
|
+
if (prop.type === "unknown") {
|
|
94
|
+
if (columnType?.startsWith("nvarchar(") || columnType?.startsWith("varchar(")) {
|
|
95
|
+
return "string";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
94
98
|
return prop.type;
|
|
95
99
|
}
|
|
96
100
|
getPropertyDefinition(prop) {
|
|
@@ -110,9 +114,6 @@ ${file}`;
|
|
|
110
114
|
return `${padding}${prop.name}${optional}: Ref<${prop.type}>;
|
|
111
115
|
`;
|
|
112
116
|
}
|
|
113
|
-
if (prop.primary) {
|
|
114
|
-
return `${padding}id!: ${this.getPropertyType(prop)};`;
|
|
115
|
-
}
|
|
116
117
|
const file = `${prop.name}${optional}: ${this.getPropertyType(prop)}`;
|
|
117
118
|
if (!useDefault) {
|
|
118
119
|
return `${padding + file};
|
|
@@ -164,9 +165,6 @@ ${file}`;
|
|
|
164
165
|
if (prop.enum) {
|
|
165
166
|
options.items = `() => ${prop.type}`;
|
|
166
167
|
}
|
|
167
|
-
if (prop.primary && prop.name !== "id" && prop.fieldNames?.[0]) {
|
|
168
|
-
options.fieldName = this.quote(prop.fieldNames[0]);
|
|
169
|
-
}
|
|
170
168
|
this.getCommonDecoratorOptions(options, prop);
|
|
171
169
|
const indexes = this.getPropertyIndexes(prop, options);
|
|
172
170
|
decorator = [...indexes.sort(), decorator].map((d) => padding + d).join("\n");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/introspection/files/data-entity-file.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is a modified version of source from MikroORM, located here:\n// https://github.com/mikro-orm/mikro-orm/blob/6ba3d4004deef00b754a4ca2011cf64e44a4a3a3/packages/entity-generator/src/SourceFile.ts\n//\n// MIT License\n//\n// Copyright (c) 2018 Martin Ad\u00E1mek\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityOptions,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceKind, UnknownType, Utils } from '@mikro-orm/core';\nimport { BaseFile } from './base-file';\nimport { DatabaseType } from '../../database';\nimport { pascalToKebabCaseString } from '../utils';\n\nexport class DataEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\n\tconstructor(\n\t\tprotected readonly meta: EntityMetadata,\n\t\tprotected readonly namingStrategy: NamingStrategy,\n\t\tprotected readonly platform: Platform,\n\t\tprotected readonly databaseType: DatabaseType\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\tconst fileName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `${fileName}.ts`;\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '';\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tconst decorator = this.getPropertyDecorator(prop);\n\t\t\tconst definition = this.getPropertyDefinition(prop);\n\n\t\t\tif (!classBody.endsWith('\\n\\n')) {\n\t\t\t\tclassBody += '\\n';\n\t\t\t}\n\n\t\t\tclassBody += decorator;\n\t\t\tclassBody += definition;\n\n\t\t\tif (props[props.length - 1] !== prop) classBody += '\\n';\n\n\t\t\tif (prop.enum) {\n\t\t\t\tconst enumClassName = this.namingStrategy.getClassName(\n\t\t\t\t\tthis.meta.collection + '_' + prop.fieldNames[0],\n\t\t\t\t\t'_'\n\t\t\t\t);\n\t\t\t\tenumDefinitions.push(this.getEnumClassDefinition(enumClassName, prop.items as string[]));\n\t\t\t}\n\t\t});\n\n\t\tlet file = ``;\n\n\t\tthis.coreImports.add('Entity');\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@mikro-orm/core';`,\n\t\t\t`import { BaseEntity } from '@exogee/graphweaver-mikroorm';`,\n\t\t];\n\t\tconst entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);\n\t\tentityImports.sort().forEach((entity) => {\n\t\t\timports.push(`import { ${entity} } from './${pascalToKebabCaseString(entity)}';`);\n\t\t});\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n';\n\t\t}\n\n\t\tfile += `@Entity(${this.getCollectionDecl()})\\n`;\n\t\tfile += `export class ${this.meta.className} extends BaseEntity {`;\n\n\t\tfile += `${classBody}}\\n`;\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getPropertyType(prop: EntityProperty): string {\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\treturn prop.type;\n\t}\n\n\tprotected getPropertyDefinition(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\n\t\tif ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {\n\t\t\tthis.coreImports.add('Collection');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name} = new Collection<${prop.type}>(this);\\n`;\n\t\t}\n\n\t\t// string defaults are usually things like SQL functions, but can be also enums, for that `useDefault` should be true\n\t\tconst isEnumOrNonStringDefault = prop.enum || typeof prop.default !== 'string';\n\t\tconst useDefault = prop.default != null && isEnumOrNonStringDefault;\n\t\tconst optional = prop.nullable ? '?' : useDefault ? '' : '!';\n\n\t\tif (prop.ref) {\n\t\t\tthis.coreImports.add('Ref');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}${optional}: Ref<${prop.type}>;\\n`;\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\treturn `${padding}id!: ${this.getPropertyType(prop)};`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getPropertyType(prop)}`;\n\n\t\tif (!useDefault) {\n\t\t\treturn `${padding + file};\\n`;\n\t\t}\n\n\t\tif (prop.enum && typeof prop.default === 'string') {\n\t\t\treturn `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};\\n`;\n\t\t}\n\n\t\treturn `${padding}${prop.name} = ${prop.default};\\n`;\n\t}\n\n\tprotected getEnumClassDefinition(enumClassName: string, enumValues: string[]): string {\n\t\tconst padding = '\\t';\n\t\tlet file = `export enum ${enumClassName} {\\n`;\n\n\t\tfor (const enumValue of enumValues) {\n\t\t\tfile += `${padding}${enumValue.toUpperCase()} = '${enumValue}',\\n`;\n\t\t}\n\n\t\tfile += '}\\n';\n\n\t\treturn file;\n\t}\n\n\tprivate getCollectionDecl() {\n\t\tconst options: EntityOptions<unknown> = {};\n\n\t\toptions.tableName = this.quote(this.meta.collection);\n\n\t\tif (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {\n\t\t\toptions.schema = this.quote(this.meta.schema);\n\t\t}\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `{ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} }`;\n\t}\n\n\tprivate getPropertyDecorator(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\t\tconst options = {} as Dictionary;\n\t\tlet decorator = this.getDecoratorType(prop);\n\t\tthis.coreImports.add(decorator.substring(1));\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind !== ReferenceKind.SCALAR) {\n\t\t\tthis.getForeignKeyDecoratorOptions(options, prop);\n\t\t} else {\n\t\t\tthis.getScalarPropertyDecoratorOptions(options, prop);\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\toptions.items = `() => ${prop.type}`;\n\t\t}\n\n\t\tif (prop.primary && prop.name !== 'id' && prop.fieldNames?.[0]) {\n\t\t\toptions.fieldName = this.quote(prop.fieldNames[0]);\n\t\t}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tconst indexes = this.getPropertyIndexes(prop, options);\n\t\tdecorator = [...indexes.sort(), decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}()\\n`;\n\t\t}\n\n\t\treturn `${decorator}({ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\n\t}\n\n\tprotected getPropertyIndexes(prop: EntityProperty, options: Dictionary): string[] {\n\t\tif (prop.kind === ReferenceKind.SCALAR) {\n\t\t\tconst ret: string[] = [];\n\n\t\t\tif (prop.index) {\n\t\t\t\tthis.coreImports.add('Index');\n\t\t\t\tret.push(`@Index({ name: '${prop.index}' })`);\n\t\t\t}\n\n\t\t\tif (prop.unique) {\n\t\t\t\tthis.coreImports.add('Unique');\n\t\t\t\tret.push(`@Unique({ name: '${prop.unique}' })`);\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tconst processIndex = (type: 'index' | 'unique') => {\n\t\t\tif (!prop[type]) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultName = this.platform.getIndexName(this.meta.collection, prop.fieldNames, type);\n\t\t\toptions[type] = defaultName === prop[type] ? 'true' : `'${prop[type]}'`;\n\t\t\tconst expected = {\n\t\t\t\tindex: this.platform.indexForeignKeys(),\n\t\t\t\tunique: prop.kind === ReferenceKind.ONE_TO_ONE,\n\t\t\t};\n\n\t\t\tif (expected[type] && options[type] === 'true') {\n\t\t\t\tdelete options[type];\n\t\t\t}\n\t\t};\n\n\t\tprocessIndex('index');\n\t\tprocessIndex('unique');\n\n\t\treturn [];\n\t}\n\n\tprotected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tif (prop.nullable && !prop.mappedBy) {\n\t\t\toptions.nullable = true;\n\t\t}\n\n\t\tif (prop.default == null) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof prop.default !== 'string') {\n\t\t\toptions.default = prop.default;\n\t\t\treturn;\n\t\t}\n\n\t\tif ([`''`, ''].includes(prop.default)) {\n\t\t\toptions.default = `''`;\n\t\t} else if (prop.defaultRaw === this.quote(prop.default)) {\n\t\t\toptions.default = this.quote(prop.default);\n\t\t} else {\n\t\t\toptions.defaultRaw = `\\`${prop.default}\\``;\n\t\t}\n\t}\n\n\tprotected getScalarPropertyDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tlet t = prop.type.toLowerCase();\n\n\t\tif (t === 'date') {\n\t\t\tt = 'datetime';\n\t\t}\n\n\t\tif (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {\n\t\t\toptions.fieldName = `'${prop.fieldNames[0]}'`;\n\t\t}\n\n\t\t// for enum properties, we don't need a column type or the property length\n\t\t// in the decorator so return early.\n\t\tif (prop.enum) {\n\t\t\toptions.type = this.quote('string');\n\t\t\treturn;\n\t\t}\n\n\t\tconst mappedType1 = this.platform.getMappedType(t);\n\t\tconst mappedType2 = this.platform.getMappedType(prop.columnTypes[0]);\n\t\tconst columnType1 = mappedType1.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\t\tconst columnType2 = mappedType2.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\n\t\tif (\n\t\t\tcolumnType1 !== columnType2 ||\n\t\t\t[mappedType1, mappedType2].some((t) => t instanceof UnknownType)\n\t\t) {\n\t\t\toptions.type = this.quote(prop.columnTypes[0]);\n\t\t} else {\n\t\t\toptions.type = this.quote(prop.type);\n\t\t}\n\n\t\tif (prop.length) {\n\t\t\toptions.length = prop.length;\n\t\t}\n\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.pivotTable !==\n\t\t\tthis.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)\n\t\t) {\n\t\t\toptions.pivotTable = this.quote(prop.pivotTable);\n\t\t}\n\n\t\tif (prop.joinColumns.length === 1) {\n\t\t\toptions.joinColumn = this.quote(prop.joinColumns[0]);\n\t\t} else {\n\t\t\toptions.joinColumns = `[${prop.joinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\n\t\tif (prop.inverseJoinColumns.length === 1) {\n\t\t\toptions.inverseJoinColumn = this.quote(prop.inverseJoinColumns[0]);\n\t\t} else {\n\t\t\toptions.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.ref) {\n\t\t\toptions.ref = true;\n\t\t}\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.fieldNames[0] !==\n\t\t\tthis.namingStrategy.joinKeyColumnName(prop.name, prop.referencedColumnNames[0])\n\t\t) {\n\t\t\toptions.fieldName = this.quote(prop.fieldNames[0]);\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\toptions.primary = true;\n\t\t}\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif (prop.kind === ReferenceKind.ONE_TO_ONE) {\n\t\t\treturn '@OneToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_ONE) {\n\t\t\treturn '@ManyToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\treturn '@OneToMany';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\treturn '@ManyToMany';\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\treturn '@PrimaryKey';\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\treturn '@Enum';\n\t\t}\n\n\t\treturn '@Property';\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,kBAAkD;AAClD,uBAAyB;AAEzB,mBAAwC;AAEjC,MAAM,uBAAuB,0BAAS;AAAA,EAI5C,YACoB,MACA,gBACA,UACA,cAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AALjB;AACA;AACA;AACA;AAPpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AAAA,EASnD;AAAA,EAEA,cAAc;AACb,WAAO,oBAAoB,KAAK;AAAA,
|
|
4
|
+
"sourcesContent": ["// This file is a modified version of source from MikroORM, located here:\n// https://github.com/mikro-orm/mikro-orm/blob/6ba3d4004deef00b754a4ca2011cf64e44a4a3a3/packages/entity-generator/src/SourceFile.ts\n//\n// MIT License\n//\n// Copyright (c) 2018 Martin Ad\u00E1mek\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityOptions,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceKind, UnknownType, Utils } from '@mikro-orm/core';\nimport { BaseFile } from './base-file';\nimport { DatabaseType } from '../../database';\nimport { pascalToKebabCaseString } from '../utils';\n\nexport class DataEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\n\tconstructor(\n\t\tprotected readonly meta: EntityMetadata,\n\t\tprotected readonly namingStrategy: NamingStrategy,\n\t\tprotected readonly platform: Platform,\n\t\tprotected readonly databaseType: DatabaseType\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\tconst fileName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `${fileName}.ts`;\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '';\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tconst decorator = this.getPropertyDecorator(prop);\n\t\t\tconst definition = this.getPropertyDefinition(prop);\n\n\t\t\tif (!classBody.endsWith('\\n\\n')) {\n\t\t\t\tclassBody += '\\n';\n\t\t\t}\n\n\t\t\tclassBody += decorator;\n\t\t\tclassBody += definition;\n\n\t\t\tif (props[props.length - 1] !== prop) classBody += '\\n';\n\n\t\t\tif (prop.enum) {\n\t\t\t\tconst enumClassName = this.namingStrategy.getClassName(\n\t\t\t\t\tthis.meta.collection + '_' + prop.fieldNames[0],\n\t\t\t\t\t'_'\n\t\t\t\t);\n\t\t\t\tenumDefinitions.push(this.getEnumClassDefinition(enumClassName, prop.items as string[]));\n\t\t\t}\n\t\t});\n\n\t\tlet file = ``;\n\n\t\tthis.coreImports.add('Entity');\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@mikro-orm/core';`,\n\t\t];\n\t\tconst entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);\n\t\tentityImports.sort().forEach((entity) => {\n\t\t\timports.push(`import { ${entity} } from './${pascalToKebabCaseString(entity)}';`);\n\t\t});\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n';\n\t\t}\n\n\t\tfile += `@Entity(${this.getCollectionDecl()})\\n`;\n\t\tfile += `export class ${this.meta.className} {`;\n\n\t\tfile += `${classBody}}\\n`;\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getPropertyType(prop: EntityProperty): string {\n\t\tconst columnType = prop.columnTypes?.[0]?.toLowerCase();\n\n\t\tif (['jsonb', 'json', 'any'].includes(columnType)) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\t// Mikro doesn't infer column types for some columns very well. We can augment.\n\t\tif (prop.type === 'unknown') {\n\t\t\tif (columnType?.startsWith('nvarchar(') || columnType?.startsWith('varchar(')) {\n\t\t\t\treturn 'string';\n\t\t\t}\n\t\t}\n\n\t\treturn prop.type;\n\t}\n\n\tprotected getPropertyDefinition(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\n\t\tif ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {\n\t\t\tthis.coreImports.add('Collection');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name} = new Collection<${prop.type}>(this);\\n`;\n\t\t}\n\n\t\t// string defaults are usually things like SQL functions, but can be also enums, for that `useDefault` should be true\n\t\tconst isEnumOrNonStringDefault = prop.enum || typeof prop.default !== 'string';\n\t\tconst useDefault = prop.default != null && isEnumOrNonStringDefault;\n\t\tconst optional = prop.nullable ? '?' : useDefault ? '' : '!';\n\n\t\tif (prop.ref) {\n\t\t\tthis.coreImports.add('Ref');\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}${optional}: Ref<${prop.type}>;\\n`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getPropertyType(prop)}`;\n\n\t\tif (!useDefault) {\n\t\t\treturn `${padding + file};\\n`;\n\t\t}\n\n\t\tif (prop.enum && typeof prop.default === 'string') {\n\t\t\treturn `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};\\n`;\n\t\t}\n\n\t\treturn `${padding}${prop.name} = ${prop.default};\\n`;\n\t}\n\n\tprotected getEnumClassDefinition(enumClassName: string, enumValues: string[]): string {\n\t\tconst padding = '\\t';\n\t\tlet file = `export enum ${enumClassName} {\\n`;\n\n\t\tfor (const enumValue of enumValues) {\n\t\t\tfile += `${padding}${enumValue.toUpperCase()} = '${enumValue}',\\n`;\n\t\t}\n\n\t\tfile += '}\\n';\n\n\t\treturn file;\n\t}\n\n\tprivate getCollectionDecl() {\n\t\tconst options: EntityOptions<unknown> = {};\n\n\t\toptions.tableName = this.quote(this.meta.collection);\n\n\t\tif (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {\n\t\t\toptions.schema = this.quote(this.meta.schema);\n\t\t}\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `{ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} }`;\n\t}\n\n\tprivate getPropertyDecorator(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\t\tconst options = {} as Dictionary;\n\t\tlet decorator = this.getDecoratorType(prop);\n\t\tthis.coreImports.add(decorator.substring(1));\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.kind !== ReferenceKind.SCALAR) {\n\t\t\tthis.getForeignKeyDecoratorOptions(options, prop);\n\t\t} else {\n\t\t\tthis.getScalarPropertyDecoratorOptions(options, prop);\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\toptions.items = `() => ${prop.type}`;\n\t\t}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tconst indexes = this.getPropertyIndexes(prop, options);\n\t\tdecorator = [...indexes.sort(), decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}()\\n`;\n\t\t}\n\n\t\treturn `${decorator}({ ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\n\t}\n\n\tprotected getPropertyIndexes(prop: EntityProperty, options: Dictionary): string[] {\n\t\tif (prop.kind === ReferenceKind.SCALAR) {\n\t\t\tconst ret: string[] = [];\n\n\t\t\tif (prop.index) {\n\t\t\t\tthis.coreImports.add('Index');\n\t\t\t\tret.push(`@Index({ name: '${prop.index}' })`);\n\t\t\t}\n\n\t\t\tif (prop.unique) {\n\t\t\t\tthis.coreImports.add('Unique');\n\t\t\t\tret.push(`@Unique({ name: '${prop.unique}' })`);\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tconst processIndex = (type: 'index' | 'unique') => {\n\t\t\tif (!prop[type]) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultName = this.platform.getIndexName(this.meta.collection, prop.fieldNames, type);\n\t\t\toptions[type] = defaultName === prop[type] ? 'true' : `'${prop[type]}'`;\n\t\t\tconst expected = {\n\t\t\t\tindex: this.platform.indexForeignKeys(),\n\t\t\t\tunique: prop.kind === ReferenceKind.ONE_TO_ONE,\n\t\t\t};\n\n\t\t\tif (expected[type] && options[type] === 'true') {\n\t\t\t\tdelete options[type];\n\t\t\t}\n\t\t};\n\n\t\tprocessIndex('index');\n\t\tprocessIndex('unique');\n\n\t\treturn [];\n\t}\n\n\tprotected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tif (prop.nullable && !prop.mappedBy) {\n\t\t\toptions.nullable = true;\n\t\t}\n\n\t\tif (prop.default == null) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof prop.default !== 'string') {\n\t\t\toptions.default = prop.default;\n\t\t\treturn;\n\t\t}\n\n\t\tif ([`''`, ''].includes(prop.default)) {\n\t\t\toptions.default = `''`;\n\t\t} else if (prop.defaultRaw === this.quote(prop.default)) {\n\t\t\toptions.default = this.quote(prop.default);\n\t\t} else {\n\t\t\toptions.defaultRaw = `\\`${prop.default}\\``;\n\t\t}\n\t}\n\n\tprotected getScalarPropertyDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tlet t = prop.type.toLowerCase();\n\n\t\tif (t === 'date') {\n\t\t\tt = 'datetime';\n\t\t}\n\n\t\tif (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {\n\t\t\toptions.fieldName = `'${prop.fieldNames[0]}'`;\n\t\t}\n\n\t\t// for enum properties, we don't need a column type or the property length\n\t\t// in the decorator so return early.\n\t\tif (prop.enum) {\n\t\t\toptions.type = this.quote('string');\n\t\t\treturn;\n\t\t}\n\n\t\tconst mappedType1 = this.platform.getMappedType(t);\n\t\tconst mappedType2 = this.platform.getMappedType(prop.columnTypes[0]);\n\t\tconst columnType1 = mappedType1.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\t\tconst columnType2 = mappedType2.getColumnType({ ...prop, autoincrement: false }, this.platform);\n\n\t\tif (\n\t\t\tcolumnType1 !== columnType2 ||\n\t\t\t[mappedType1, mappedType2].some((t) => t instanceof UnknownType)\n\t\t) {\n\t\t\toptions.type = this.quote(prop.columnTypes[0]);\n\t\t} else {\n\t\t\toptions.type = this.quote(prop.type);\n\t\t}\n\n\t\tif (prop.length) {\n\t\t\toptions.length = prop.length;\n\t\t}\n\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.pivotTable !==\n\t\t\tthis.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)\n\t\t) {\n\t\t\toptions.pivotTable = this.quote(prop.pivotTable);\n\t\t}\n\n\t\tif (prop.joinColumns.length === 1) {\n\t\t\toptions.joinColumn = this.quote(prop.joinColumns[0]);\n\t\t} else {\n\t\t\toptions.joinColumns = `[${prop.joinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\n\t\tif (prop.inverseJoinColumns.length === 1) {\n\t\t\toptions.inverseJoinColumn = this.quote(prop.inverseJoinColumns[0]);\n\t\t} else {\n\t\t\toptions.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(', ')}]`;\n\t\t}\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.entity = `() => ${prop.type}`;\n\n\t\tif (prop.ref) {\n\t\t\toptions.ref = true;\n\t\t}\n\n\t\tif (prop.mappedBy) {\n\t\t\toptions.mappedBy = this.quote(prop.mappedBy);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tprop.fieldNames[0] !==\n\t\t\tthis.namingStrategy.joinKeyColumnName(prop.name, prop.referencedColumnNames[0])\n\t\t) {\n\t\t\toptions.fieldName = this.quote(prop.fieldNames[0]);\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\toptions.primary = true;\n\t\t}\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif (prop.kind === ReferenceKind.ONE_TO_ONE) {\n\t\t\treturn '@OneToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_ONE) {\n\t\t\treturn '@ManyToOne';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.ONE_TO_MANY) {\n\t\t\treturn '@OneToMany';\n\t\t}\n\n\t\tif (prop.kind === ReferenceKind.MANY_TO_MANY) {\n\t\t\treturn '@ManyToMany';\n\t\t}\n\n\t\tif (prop.primary) {\n\t\t\treturn '@PrimaryKey';\n\t\t}\n\n\t\tif (prop.enum) {\n\t\t\treturn '@Enum';\n\t\t}\n\n\t\treturn '@Property';\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,kBAAkD;AAClD,uBAAyB;AAEzB,mBAAwC;AAEjC,MAAM,uBAAuB,0BAAS;AAAA,EAI5C,YACoB,MACA,gBACA,UACA,cAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AALjB;AACA;AACA;AACA;AAPpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AAAA,EASnD;AAAA,EAEA,cAAc;AACb,WAAO,oBAAoB,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEA,cAAc;AACb,UAAM,eAAW,sCAAwB,KAAK,KAAK,SAAS;AAC5D,WAAO,GAAG,QAAQ;AAAA,EACnB;AAAA,EAEA,WAAmB;AAClB,UAAM,kBAA4B,CAAC;AACnC,QAAI,YAAY;AAChB,UAAM,QAAQ,OAAO,OAAO,KAAK,KAAK,UAAU;A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;AACb,cAAQ,MAAM;AAAA,IACf;AAEA,QAAI,KAAK,UAAU;AAClB,cAAQ,WAAW,KAAK,MAAM,KAAK,QAAQ;AAC3C;AAAA,IACD;AAEA,QACC,KAAK,WAAW,CAAC,MACjB,KAAK,eAAe,kBAAkB,KAAK,MAAM,KAAK,sBAAsB,CAAC,CAAC,GAC7E;AACD,cAAQ,YAAY,KAAK,MAAM,KAAK,WAAW,CAAC,CAAC;AAAA,IAClD;AAEA,QAAI,KAAK,SAAS;AACjB,cAAQ,UAAU;AAAA,IACnB;AAAA,EACD;AAAA,EAEU,iBAAiB,MAA8B;AACxD,QAAI,KAAK,SAAS,0BAAc,YAAY;AAC3C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,aAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,aAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS,0BAAc,cAAc;AAC7C,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,SAAS;AACjB,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,MAAM;AACd,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": ["t"]
|
|
7
7
|
}
|
|
@@ -36,11 +36,11 @@ class DataEntityIndexFile {
|
|
|
36
36
|
let file = "export const entities = [\n";
|
|
37
37
|
const padding = " ";
|
|
38
38
|
const imports = [];
|
|
39
|
-
const
|
|
39
|
+
const exports2 = [];
|
|
40
40
|
for (const meta of this.metadata) {
|
|
41
41
|
if (!meta.pivotTable) {
|
|
42
42
|
const filename = meta.className.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
43
|
-
|
|
43
|
+
exports2.push(`export * from './${filename}';`);
|
|
44
44
|
imports.push(`import { ${meta.className} } from './${filename}';`);
|
|
45
45
|
file += `${padding}${meta.className},
|
|
46
46
|
`;
|
|
@@ -49,7 +49,7 @@ class DataEntityIndexFile {
|
|
|
49
49
|
file += "];\n";
|
|
50
50
|
return `${imports.join("\n")}
|
|
51
51
|
|
|
52
|
-
${
|
|
52
|
+
${exports2.join("\n")}
|
|
53
53
|
|
|
54
54
|
${file}`;
|
|
55
55
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/introspection/files/data-entity-index-file.ts"],
|
|
4
4
|
"sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\nimport { DatabaseType } from '../../database';\n\nexport class DataEntityIndexFile {\n\tconstructor(\n\t\tprotected readonly metadata: EntityMetadata<any>[],\n\t\tprotected readonly databaseType: DatabaseType\n\t) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/${this.databaseType}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tlet file = 'export const entities = [\\n';\n\t\tconst padding = '\\t';\n\t\tconst imports: string[] = [];\n\t\tconst exports: string[] = [];\n\n\t\tfor (const meta of this.metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst filename = meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n\t\t\t\texports.push(`export * from './${filename}';`);\n\t\t\t\timports.push(`import { ${meta.className} } from './${filename}';`);\n\t\t\t\tfile += `${padding}${meta.className},\\n`;\n\t\t\t}\n\t\t}\n\n\t\tfile += '];\\n';\n\n\t\treturn `${imports.join('\\n')}\\n\\n${exports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,oBAAoB;AAAA,EAChC,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO,oBAAoB,KAAK;AAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,oBAAoB;AAAA,EAChC,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EACjB;AAAA,EAEH,cAAc;AACb,WAAO,oBAAoB,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,QAAI,OAAO;AACX,UAAM,UAAU;AAChB,UAAM,UAAoB,CAAC;AAC3B,UAAMA,WAAoB,CAAC;AAE3B,eAAW,QAAQ,KAAK,UAAU;AACjC,UAAI,CAAC,KAAK,YAAY;AACrB,cAAM,WAAW,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACnF,QAAAA,SAAQ,KAAK,oBAAoB,QAAQ,IAAI;AAC7C,gBAAQ,KAAK,YAAY,KAAK,SAAS,cAAc,QAAQ,IAAI;AACjE,gBAAQ,GAAG,OAAO,GAAG,KAAK,SAAS;AAAA;AAAA,MACpC;AAAA,IACD;AAEA,YAAQ;AAER,WAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAOA,SAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAAO,IAAI;AAAA,EACjE;AACD;",
|
|
6
|
+
"names": ["exports"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/introspection/files/data-source-index-file.ts"],
|
|
4
4
|
"sourcesContent": ["import { DatabaseType } from '../../database';\n\nexport class DataSourceIndexFile {\n\tconstructor(protected readonly databaseType: DatabaseType) {}\n\n\tgetBasePath() {\n\t\treturn `backend/entities/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst imports = [`export * from './${this.databaseType}';`];\n\n\t\treturn `${imports.join('\\n')}\\n`;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAoB;AAAA,EAChC,YAA+B,cAA4B;AAA5B;AAAA,EAA6B;AAAA,EAE5D,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,UAAU,CAAC,oBAAoB,KAAK,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAoB;AAAA,EAChC,YAA+B,cAA4B;AAA5B;AAAA,EAA6B;AAAA,EAE5D,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,UAAU,CAAC,oBAAoB,KAAK,YAAY,IAAI;AAE1D,WAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;AAAA;AAAA,EAC7B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|