@mikro-orm/core 7.2.2-dev.28 → 7.2.2-dev.29
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.
|
@@ -32,6 +32,13 @@ export declare class MetadataStorage {
|
|
|
32
32
|
getById<T>(id: number): EntityMetadata<T>;
|
|
33
33
|
/** Returns metadata by class name, optionally throwing if not found. */
|
|
34
34
|
getByClassName<T = any, V extends boolean = true>(className: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the first registered metadata with the given table name, in registration order (entities sharing
|
|
37
|
+
* a table, like STI children, resolve to the one registered first). The index is built on first use, as table
|
|
38
|
+
* names are only final once discovery has finished.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
getByTableName<T = any>(tableName: string): EntityMetadata<T> | undefined;
|
|
35
42
|
/** Returns metadata by unique name, optionally throwing if not found. */
|
|
36
43
|
getByUniqueName<T = any, V extends boolean = true>(uniqueName: string, validate?: V): V extends true ? EntityMetadata<T> : EntityMetadata<T> | undefined;
|
|
37
44
|
private validate;
|
|
@@ -18,6 +18,8 @@ export class MetadataStorage {
|
|
|
18
18
|
#classNameMap;
|
|
19
19
|
#uniqueNameMap;
|
|
20
20
|
#ambiguousNames = new Set();
|
|
21
|
+
/** Built on first use by `getByTableName()`, dropped whenever an entity is registered or removed. */
|
|
22
|
+
#tableNameMap;
|
|
21
23
|
constructor(metadata = {}) {
|
|
22
24
|
this.#idMap = {};
|
|
23
25
|
this.#uniqueNameMap = {};
|
|
@@ -102,6 +104,7 @@ export class MetadataStorage {
|
|
|
102
104
|
/** Registers metadata for the given entity. */
|
|
103
105
|
set(entityName, meta) {
|
|
104
106
|
this.#metadataMap.set(entityName, meta);
|
|
107
|
+
this.#tableNameMap = undefined;
|
|
105
108
|
this.#idMap[meta._id] = meta;
|
|
106
109
|
this.#uniqueNameMap[meta.uniqueName] = meta;
|
|
107
110
|
const className = Utils.className(entityName);
|
|
@@ -124,6 +127,7 @@ export class MetadataStorage {
|
|
|
124
127
|
const meta = this.find(entityName);
|
|
125
128
|
if (meta) {
|
|
126
129
|
this.#metadataMap.delete(meta.class);
|
|
130
|
+
this.#tableNameMap = undefined;
|
|
127
131
|
delete this.#idMap[meta._id];
|
|
128
132
|
delete this.#uniqueNameMap[meta.uniqueName];
|
|
129
133
|
delete this.#classNameMap[meta.className];
|
|
@@ -151,6 +155,23 @@ export class MetadataStorage {
|
|
|
151
155
|
getByClassName(className, validate = true) {
|
|
152
156
|
return this.validate(this.#classNameMap[className], className, validate);
|
|
153
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns the first registered metadata with the given table name, in registration order (entities sharing
|
|
160
|
+
* a table, like STI children, resolve to the one registered first). The index is built on first use, as table
|
|
161
|
+
* names are only final once discovery has finished.
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
getByTableName(tableName) {
|
|
165
|
+
if (!this.#tableNameMap) {
|
|
166
|
+
this.#tableNameMap = new Map();
|
|
167
|
+
for (const meta of this.#metadataMap.values()) {
|
|
168
|
+
if (!this.#tableNameMap.has(meta.tableName)) {
|
|
169
|
+
this.#tableNameMap.set(meta.tableName, meta);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return this.#tableNameMap.get(tableName);
|
|
174
|
+
}
|
|
154
175
|
/** Returns metadata by unique name, optionally throwing if not found. */
|
|
155
176
|
getByUniqueName(uniqueName, validate = true) {
|
|
156
177
|
return this.validate(this.#uniqueNameMap[uniqueName], uniqueName, validate);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.2-dev.
|
|
3
|
+
"version": "7.2.2-dev.29",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.2.2-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.2-dev.29';
|
|
157
157
|
/** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
|
|
158
158
|
static getRlsSettingName(filterName, argName) {
|
|
159
159
|
return `mikro.${filterName}.${argName}`;
|