1 | import { QueryRunner, SelectQueryBuilder } from "..";
|
2 | import { ObjectLiteral } from "../common/ObjectLiteral";
|
3 | import { Connection } from "../connection/Connection";
|
4 | import { OrderByCondition } from "../find-options/OrderByCondition";
|
5 | import { TableMetadataArgs } from "../metadata-args/TableMetadataArgs";
|
6 | import { TreeMetadataArgs } from "../metadata-args/TreeMetadataArgs";
|
7 | import { CheckMetadata } from "./CheckMetadata";
|
8 | import { ColumnMetadata } from "./ColumnMetadata";
|
9 | import { EmbeddedMetadata } from "./EmbeddedMetadata";
|
10 | import { EntityListenerMetadata } from "./EntityListenerMetadata";
|
11 | import { ExclusionMetadata } from "./ExclusionMetadata";
|
12 | import { ForeignKeyMetadata } from "./ForeignKeyMetadata";
|
13 | import { IndexMetadata } from "./IndexMetadata";
|
14 | import { RelationCountMetadata } from "./RelationCountMetadata";
|
15 | import { RelationIdMetadata } from "./RelationIdMetadata";
|
16 | import { RelationMetadata } from "./RelationMetadata";
|
17 | import { TableType } from "./types/TableTypes";
|
18 | import { TreeType } from "./types/TreeTypes";
|
19 | import { UniqueMetadata } from "./UniqueMetadata";
|
20 |
|
21 |
|
22 |
|
23 | export declare class EntityMetadata {
|
24 | |
25 |
|
26 |
|
27 | connection: Connection;
|
28 | |
29 |
|
30 |
|
31 | tableMetadataArgs: TableMetadataArgs;
|
32 | |
33 |
|
34 |
|
35 | closureJunctionTable: EntityMetadata;
|
36 | |
37 |
|
38 |
|
39 | parentClosureEntityMetadata: EntityMetadata;
|
40 | |
41 |
|
42 |
|
43 | parentEntityMetadata: EntityMetadata;
|
44 | |
45 |
|
46 |
|
47 | childEntityMetadatas: EntityMetadata[];
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | inheritanceTree: Function[];
|
54 | |
55 |
|
56 |
|
57 | tableType: TableType;
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 | target: Function | string;
|
64 | |
65 |
|
66 |
|
67 | targetName: string;
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 | name: string;
|
74 | |
75 |
|
76 |
|
77 |
|
78 | expression?: string | ((connection: Connection) => SelectQueryBuilder<any>);
|
79 | /**
|
80 | * Original user-given table name (taken from schema or @Entity(tableName) decorator).
|
81 | * If user haven't specified a table name this property will be undefined.
|
82 | */
|
83 | givenTableName?: string;
|
84 | /**
|
85 | * Entity table name in the database.
|
86 | * This is final table name of the entity.
|
87 | * This name already passed naming strategy, and generated based on
|
88 | * multiple criteria, including user table name and global table prefix.
|
89 | */
|
90 | tableName: string;
|
91 | /**
|
92 | * Entity table path. Contains database name, schema name and table name.
|
93 | * E.g. myDB.mySchema.myTable
|
94 | */
|
95 | tablePath: string;
|
96 | /**
|
97 | * Entity schema path. Contains database name and schema name.
|
98 | * E.g. myDB.mySchema
|
99 | */
|
100 | schemaPath?: string;
|
101 | /**
|
102 | * Gets the table name without global table prefix.
|
103 | * When querying table you need a table name with prefix, but in some scenarios,
|
104 | * for example when you want to name a junction table that contains names of two other tables,
|
105 | * you may want a table name without prefix.
|
106 | */
|
107 | tableNameWithoutPrefix: string;
|
108 | /**
|
109 | * Indicates if schema will be synchronized for this entity or not.
|
110 | */
|
111 | synchronize: boolean;
|
112 | /**
|
113 | * Table's database engine type (like "InnoDB", "MyISAM", etc).
|
114 | */
|
115 | engine?: string;
|
116 | /**
|
117 | * Database name.
|
118 | */
|
119 | database?: string;
|
120 | /**
|
121 | * Schema name. Used in Postgres and Sql Server.
|
122 | */
|
123 | schema?: string;
|
124 | /**
|
125 | * Specifies a default order by used for queries from this table when no explicit order by is specified.
|
126 | */
|
127 | orderBy?: OrderByCondition;
|
128 | /**
|
129 | * If this entity metadata's table using one of the inheritance patterns,
|
130 | * then this will contain what pattern it uses.
|
131 | */
|
132 | inheritancePattern?: "STI";
|
133 | /**
|
134 | * Checks if there any non-nullable column exist in this entity.
|
135 | */
|
136 | hasNonNullableRelations: boolean;
|
137 | /**
|
138 | * Indicates if this entity metadata of a junction table, or not.
|
139 | * Junction table is a table created by many-to-many relationship.
|
140 | *
|
141 | * Its also possible to understand if entity is junction via tableType.
|
142 | */
|
143 | isJunction: boolean;
|
144 | /**
|
145 | * Indicates if this entity is a tree, what type of tree it is.
|
146 | */
|
147 | treeType?: TreeType;
|
148 | /**
|
149 | * Checks if this table is a junction table of the closure table.
|
150 | * This type is for tables that contain junction metadata of the closure tables.
|
151 | */
|
152 | isClosureJunction: boolean;
|
153 | /**
|
154 | * Checks if entity's table has multiple primary columns.
|
155 | */
|
156 | hasMultiplePrimaryKeys: boolean;
|
157 | /**
|
158 | * Indicates if this entity metadata has uuid generated columns.
|
159 | */
|
160 | hasUUIDGeneratedColumns: boolean;
|
161 | /**
|
162 | * If this entity metadata is a child table of some table, it should have a discriminator value.
|
163 | * Used to store a value in a discriminator column.
|
164 | */
|
165 | discriminatorValue?: string;
|
166 | /**
|
167 | * Entity's column metadatas defined by user.
|
168 | */
|
169 | ownColumns: ColumnMetadata[];
|
170 | /**
|
171 | * Columns of the entity, including columns that are coming from the embeddeds of this entity.
|
172 | */
|
173 | columns: ColumnMetadata[];
|
174 | /**
|
175 | * Ancestor columns used only in closure junction tables.
|
176 | */
|
177 | ancestorColumns: ColumnMetadata[];
|
178 | /**
|
179 | * Descendant columns used only in closure junction tables.
|
180 | */
|
181 | descendantColumns: ColumnMetadata[];
|
182 | /**
|
183 | * All columns except for virtual columns.
|
184 | */
|
185 | nonVirtualColumns: ColumnMetadata[];
|
186 | /**
|
187 | * In the case if this entity metadata is junction table's entity metadata,
|
188 | * this will contain all referenced columns of owner entity.
|
189 | */
|
190 | ownerColumns: ColumnMetadata[];
|
191 | /**
|
192 | * In the case if this entity metadata is junction table's entity metadata,
|
193 | * this will contain all referenced columns of inverse entity.
|
194 | */
|
195 | inverseColumns: ColumnMetadata[];
|
196 | /**
|
197 | * Gets the column with generated flag.
|
198 | */
|
199 | generatedColumns: ColumnMetadata[];
|
200 | /**
|
201 | * Gets the object id column used with mongodb database.
|
202 | */
|
203 | objectIdColumn?: ColumnMetadata;
|
204 | /**
|
205 | * Gets entity column which contains a create date value.
|
206 | */
|
207 | createDateColumn?: ColumnMetadata;
|
208 | /**
|
209 | * Gets entity column which contains an update date value.
|
210 | */
|
211 | updateDateColumn?: ColumnMetadata;
|
212 | /**
|
213 | * Gets entity column which contains an entity version.
|
214 | */
|
215 | versionColumn?: ColumnMetadata;
|
216 | /**
|
217 | * Gets the discriminator column used to store entity identificator in single-table inheritance tables.
|
218 | */
|
219 | discriminatorColumn?: ColumnMetadata;
|
220 | /**
|
221 | * Special column that stores tree level in tree entities.
|
222 | */
|
223 | treeLevelColumn?: ColumnMetadata;
|
224 | /**
|
225 | * Nested set's left value column.
|
226 | * Used only in tree entities with nested set pattern applied.
|
227 | */
|
228 | nestedSetLeftColumn?: ColumnMetadata;
|
229 | /**
|
230 | * Nested set's right value column.
|
231 | * Used only in tree entities with nested set pattern applied.
|
232 | */
|
233 | nestedSetRightColumn?: ColumnMetadata;
|
234 | /**
|
235 | * Materialized path column.
|
236 | * Used only in tree entities with materialized path pattern applied.
|
237 | */
|
238 | materializedPathColumn?: ColumnMetadata;
|
239 | /**
|
240 | * Gets the primary columns.
|
241 | */
|
242 | primaryColumns: ColumnMetadata[];
|
243 | /**
|
244 | * Entity's relation metadatas.
|
245 | */
|
246 | ownRelations: RelationMetadata[];
|
247 | /**
|
248 | * Relations of the entity, including relations that are coming from the embeddeds of this entity.
|
249 | */
|
250 | relations: RelationMetadata[];
|
251 | /**
|
252 | * List of eager relations this metadata has.
|
253 | */
|
254 | eagerRelations: RelationMetadata[];
|
255 | /**
|
256 | * List of eager relations this metadata has.
|
257 | */
|
258 | lazyRelations: RelationMetadata[];
|
259 | /**
|
260 | * Gets only one-to-one relations of the entity.
|
261 | */
|
262 | oneToOneRelations: RelationMetadata[];
|
263 | /**
|
264 | * Gets only owner one-to-one relations of the entity.
|
265 | */
|
266 | ownerOneToOneRelations: RelationMetadata[];
|
267 | /**
|
268 | * Gets only one-to-many relations of the entity.
|
269 | */
|
270 | oneToManyRelations: RelationMetadata[];
|
271 | /**
|
272 | * Gets only many-to-one relations of the entity.
|
273 | */
|
274 | manyToOneRelations: RelationMetadata[];
|
275 | /**
|
276 | * Gets only many-to-many relations of the entity.
|
277 | */
|
278 | manyToManyRelations: RelationMetadata[];
|
279 | /**
|
280 | * Gets only owner many-to-many relations of the entity.
|
281 | */
|
282 | ownerManyToManyRelations: RelationMetadata[];
|
283 | /**
|
284 | * Gets only owner one-to-one and many-to-one relations.
|
285 | */
|
286 | relationsWithJoinColumns: RelationMetadata[];
|
287 | /**
|
288 | * Tree parent relation. Used only in tree-tables.
|
289 | */
|
290 | treeParentRelation?: RelationMetadata;
|
291 | /**
|
292 | * Tree children relation. Used only in tree-tables.
|
293 | */
|
294 | treeChildrenRelation?: RelationMetadata;
|
295 | /**
|
296 | * Entity's relation id metadatas.
|
297 | */
|
298 | relationIds: RelationIdMetadata[];
|
299 | /**
|
300 | * Entity's relation id metadatas.
|
301 | */
|
302 | relationCounts: RelationCountMetadata[];
|
303 | /**
|
304 | * Entity's foreign key metadatas.
|
305 | */
|
306 | foreignKeys: ForeignKeyMetadata[];
|
307 | /**
|
308 | * Entity's embedded metadatas.
|
309 | */
|
310 | embeddeds: EmbeddedMetadata[];
|
311 | /**
|
312 | * All embeddeds - embeddeds from this entity metadata and from all child embeddeds, etc.
|
313 | */
|
314 | allEmbeddeds: EmbeddedMetadata[];
|
315 | /**
|
316 | * Entity's own indices.
|
317 | */
|
318 | ownIndices: IndexMetadata[];
|
319 | /**
|
320 | * Entity's index metadatas.
|
321 | */
|
322 | indices: IndexMetadata[];
|
323 | /**
|
324 | * Entity's unique metadatas.
|
325 | */
|
326 | uniques: UniqueMetadata[];
|
327 | /**
|
328 | * Entity's own uniques.
|
329 | */
|
330 | ownUniques: UniqueMetadata[];
|
331 | /**
|
332 | * Entity's check metadatas.
|
333 | */
|
334 | checks: CheckMetadata[];
|
335 | /**
|
336 | * Entity's exclusion metadatas.
|
337 | */
|
338 | exclusions: ExclusionMetadata[];
|
339 | /**
|
340 | * Entity's own listener metadatas.
|
341 | */
|
342 | ownListeners: EntityListenerMetadata[];
|
343 | /**
|
344 | * Entity listener metadatas.
|
345 | */
|
346 | listeners: EntityListenerMetadata[];
|
347 | /**
|
348 | * Listener metadatas with "AFTER LOAD" type.
|
349 | */
|
350 | afterLoadListeners: EntityListenerMetadata[];
|
351 | /**
|
352 | * Listener metadatas with "AFTER INSERT" type.
|
353 | */
|
354 | beforeInsertListeners: EntityListenerMetadata[];
|
355 | /**
|
356 | * Listener metadatas with "AFTER INSERT" type.
|
357 | */
|
358 | afterInsertListeners: EntityListenerMetadata[];
|
359 | /**
|
360 | * Listener metadatas with "AFTER UPDATE" type.
|
361 | */
|
362 | beforeUpdateListeners: EntityListenerMetadata[];
|
363 | /**
|
364 | * Listener metadatas with "AFTER UPDATE" type.
|
365 | */
|
366 | afterUpdateListeners: EntityListenerMetadata[];
|
367 | /**
|
368 | * Listener metadatas with "AFTER REMOVE" type.
|
369 | */
|
370 | beforeRemoveListeners: EntityListenerMetadata[];
|
371 | /**
|
372 | * Listener metadatas with "AFTER REMOVE" type.
|
373 | */
|
374 | afterRemoveListeners: EntityListenerMetadata[];
|
375 | /**
|
376 | * Map of columns and relations of the entity.
|
377 | *
|
378 | * example: Post{ id: number, name: string, counterEmbed: { count: number }, category: Category }.
|
379 | * This method will create following object:
|
380 | * { id: "id", counterEmbed: { count: "counterEmbed.count" }, category: "category" }
|
381 | */
|
382 | propertiesMap: ObjectLiteral;
|
383 | constructor(options: {
|
384 | connection: Connection;
|
385 | inheritanceTree?: Function[];
|
386 | inheritancePattern?: "STI";
|
387 | tableTree?: TreeMetadataArgs;
|
388 | parentClosureEntityMetadata?: EntityMetadata;
|
389 | args: TableMetadataArgs;
|
390 | });
|
391 | /**
|
392 | * Creates a new entity.
|
393 | */
|
394 | create(queryRunner?: QueryRunner): any;
|
395 | /**
|
396 | * Checks if given entity has an id.
|
397 | */
|
398 | hasId(entity: ObjectLiteral): boolean;
|
399 | /**
|
400 | * Checks if given entity / object contains ALL primary keys entity must have.
|
401 | * Returns true if it contains all of them, false if at least one of them is not defined.
|
402 | */
|
403 | hasAllPrimaryKeys(entity: ObjectLiteral): boolean;
|
404 | /**
|
405 | * Ensures that given object is an entity id map.
|
406 | * If given id is an object then it means its already id map.
|
407 | * If given id isn't an object then it means its a value of the id column
|
408 | * and it creates a new id map with this value and name of the primary column.
|
409 | */
|
410 | ensureEntityIdMap(id: any): ObjectLiteral;
|
411 | /**
|
412 | * Gets primary keys of the entity and returns them in a literal object.
|
413 | * For example, for Post{ id: 1, title: "hello" } where id is primary it will return { id: 1 }
|
414 | * For multiple primary keys it returns multiple keys in object.
|
415 | * For primary keys inside embeds it returns complex object literal with keys in them.
|
416 | */
|
417 | getEntityIdMap(entity: ObjectLiteral | undefined): ObjectLiteral | undefined;
|
418 | /**
|
419 | * Creates a "mixed id map".
|
420 | * If entity has multiple primary keys (ids) then it will return just regular id map, like what getEntityIdMap returns.
|
421 | * But if entity has a single primary key then it will return just value of the id column of the entity, just value.
|
422 | * This is called mixed id map.
|
423 | */
|
424 | getEntityIdMixedMap(entity: ObjectLiteral | undefined): ObjectLiteral | undefined;
|
425 | /**
|
426 | * Compares two different entities by their ids.
|
427 | * Returns true if they match, false otherwise.
|
428 | */
|
429 | compareEntities(firstEntity: ObjectLiteral, secondEntity: ObjectLiteral): boolean;
|
430 | /**
|
431 | * Finds column with a given property name.
|
432 | */
|
433 | findColumnWithPropertyName(propertyName: string): ColumnMetadata | undefined;
|
434 | /**
|
435 | * Finds column with a given database name.
|
436 | */
|
437 | findColumnWithDatabaseName(databaseName: string): ColumnMetadata | undefined;
|
438 | /**
|
439 | * Finds column with a given property path.
|
440 | */
|
441 | findColumnWithPropertyPath(propertyPath: string): ColumnMetadata | undefined;
|
442 | /**
|
443 | * Finds columns with a given property path.
|
444 | * Property path can match a relation, and relations can contain multiple columns.
|
445 | */
|
446 | findColumnsWithPropertyPath(propertyPath: string): ColumnMetadata[];
|
447 | /**
|
448 | * Finds relation with the given property path.
|
449 | */
|
450 | findRelationWithPropertyPath(propertyPath: string): RelationMetadata | undefined;
|
451 | /**
|
452 | * Checks if there is an embedded with a given property path.
|
453 | */
|
454 | hasEmbeddedWithPropertyPath(propertyPath: string): boolean;
|
455 | /**
|
456 | * Finds embedded with a given property path.
|
457 | */
|
458 | findEmbeddedWithPropertyPath(propertyPath: string): EmbeddedMetadata | undefined;
|
459 | /**
|
460 | * Iterates through entity and finds and extracts all values from relations in the entity.
|
461 | * If relation value is an array its being flattened.
|
462 | */
|
463 | extractRelationValuesFromEntity(entity: ObjectLiteral, relations: RelationMetadata[]): [RelationMetadata, any, EntityMetadata][];
|
464 | /**
|
465 | * Creates a property paths for a given entity.
|
466 | */
|
467 | static createPropertyPath(metadata: EntityMetadata, entity: ObjectLiteral, prefix?: string): string[];
|
468 | /**
|
469 | * Finds difference between two entity id maps.
|
470 | * Returns items that exist in the first array and absent in the second array.
|
471 | */
|
472 | static difference(firstIdMaps: ObjectLiteral[], secondIdMaps: ObjectLiteral[]): ObjectLiteral[];
|
473 | /**
|
474 | * Compares ids of the two entities.
|
475 | * Returns true if they match, false otherwise.
|
476 | */
|
477 | static compareIds(firstId: ObjectLiteral | undefined, secondId: ObjectLiteral | undefined): boolean;
|
478 | /**
|
479 | * Creates value map from the given values and columns.
|
480 | * Examples of usages are primary columns map and join columns map.
|
481 | */
|
482 | static getValueMap(entity: ObjectLiteral, columns: ColumnMetadata[], options?: {
|
483 | skipNulls?: boolean;
|
484 | }): ObjectLiteral | undefined;
|
485 | build(): void;
|
486 | /**
|
487 | * Registers a new column in the entity and recomputes all depend properties.
|
488 | */
|
489 | registerColumn(column: ColumnMetadata): void;
|
490 | /**
|
491 | * Creates a special object - all columns and relations of the object (plus columns and relations from embeds)
|
492 | * in a special format - { propertyName: propertyName }.
|
493 | *
|
494 | * example: Post{ id: number, name: string, counterEmbed: { count: number }, category: Category }.
|
495 | * This method will create following object:
|
496 | * { id: "id", counterEmbed: { count: "counterEmbed.count" }, category: "category" }
|
497 | */
|
498 | createPropertiesMap(): {
|
499 | [name: string]: string | any;
|
500 | };
|
501 | /**
|
502 | * Builds table path using database name, schema name and table name.
|
503 | */
|
504 | protected buildTablePath(): string;
|
505 | /**
|
506 | * Builds table path using schema name and database name.
|
507 | */
|
508 | protected buildSchemaPath(): string | undefined;
|
509 | }
|
510 |
|
\ | No newline at end of file |